Skip to content

Commit

Permalink
Merge branch 'develop-v4' into develop-v5
Browse files Browse the repository at this point in the history
# Conflicts:
#	composer.json
  • Loading branch information
khalwat committed Jan 16, 2024
2 parents 7615525 + ccabb2f commit 50872b1
Show file tree
Hide file tree
Showing 9 changed files with 2,989 additions and 1,600 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-and-deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ jobs:
strategy:
fail-fast: true
matrix:
node-version: [ 14.x ]
node-version: [ 20.x ]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file.

## 4.0.12 - UNRELEASED
### Changed
* Updated docs to use node 20 & a new sitemap plugin

## 4.0.11 - 2023.10.09
### Changed
* Ensure that the code field is rendered as formatted (but read-only) code when viewing a revision ([#12](https://github.com/nystudio107/craft-code-field/issues/12))

## 4.0.10 - 2023.08.06
### Changed
* Clean up `IEditorOptionsSchema.json` to handle `<Record>` types and refactor `GoToLocationValues` to `$def`
Expand Down
4 changes: 2 additions & 2 deletions docs/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG TAG=14-alpine
ARG TAG=20-alpine
FROM node:$TAG

USER node
RUN npm install -g npm@^10.0.0

WORKDIR /app/

Expand Down
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MAJOR_VERSION?=4
TAG?=14-alpine
TAG?=20-alpine
CONTAINER?=$(shell basename $(dir $(CURDIR)))-v${MAJOR_VERSION}-docs
DOCS_DEV_PORT?=400${MAJOR_VERSION}
DOCS_DEST?=../../../sites/nystudio107/web/docs/code-field
Expand Down
1 change: 0 additions & 1 deletion docs/docs/@types/sitemap-plugin.d.ts

This file was deleted.

18 changes: 9 additions & 9 deletions docs/docs/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import {defineConfig} from 'vite'
import SitemapPlugin from 'rollup-plugin-sitemap'
import { sitemap, Url as SitemapUrl } from '@aminnairi/rollup-plugin-sitemap'
import VitePressConfig from './.vitepress/config'
import {DefaultTheme} from "vitepress/types/default-theme";

const docsSiteBaseUrl = 'https://nystudio107.com'
const docsBaseUrl = new URL(VitePressConfig.base!, docsSiteBaseUrl).href.replace(/\/$/, '') + '/'
const siteMapRoutes = [{
path: '',
name: VitePressConfig.title
}]
const docsBaseUrl = new URL(VitePressConfig.base!, docsSiteBaseUrl).href.replace(/\/$/, '') + '/';
let siteMapUrls: SitemapUrl[] = [{
location: '',
lastModified: new Date(),
}];

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
SitemapPlugin({
sitemap({
baseUrl: docsBaseUrl,
contentBase: './docs/.vitepress/dist',
routes: siteMapRoutes,
urls: siteMapUrls,
})
],
server: {
Expand Down
4,447 changes: 2,897 additions & 1,550 deletions docs/package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"type": "module",
"scripts": {
"docs:build": "npm run docs:fix && npm run docs:lint && vitepress build docs",
"docs:dev": "vitepress dev docs",
Expand All @@ -7,8 +8,8 @@
},
"devDependencies": {
"@textlint-rule/textlint-rule-no-unmatched-pair": "^1.0.8",
"@types/node": "^18.0.0",
"rollup-plugin-sitemap": "^1.0.3",
"@types/node": "^20.0.0",
"@aminnairi/rollup-plugin-sitemap": "^0.1.0",
"textlint": "^13.0.0",
"textlint-filter-rule-comments": "^1.2.2",
"textlint-rule-apostrophe": "^1.0.0",
Expand Down
98 changes: 66 additions & 32 deletions src/fields/Code.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public static function displayName(): string
// Public Methods
// =========================================================================


/**
* @inheritdoc
*/
Expand Down Expand Up @@ -198,41 +197,24 @@ public function getSettingsHtml(): ?string
*/
public function getInputHtml($value, ElementInterface $element = null): string
{
// Get our id and namespace
$id = Html::id($this->handle);
$namespacedId = Craft::$app->getView()->namespaceInputId($id);
$twigVariables = $this->getFieldRenderVariables($value, $element, true);
// Render the input template
return Craft::$app->getView()->renderTemplate(
'codefield/_components/fields/Code_input',
$twigVariables
);
}

// Extract just the languages that have been selected for display
$displayLanguages = [];
if ($this->showLanguageDropdown) {
$monacoLanguages = require(__DIR__ . '/MonacoLanguages.php');
$decomposedLanguages = array_column($monacoLanguages, 'label', 'value');
$displayLanguages = array_intersect_key($decomposedLanguages, array_flip($this->availableLanguages));
// Handle "all" checkbox
if ($this->availableLanguages[0] === '*') {
$displayLanguages = $decomposedLanguages;
}
$displayLanguages = array_map(static function ($k, $v) {
return ['value' => $k, 'label' => $v];
}, array_keys($displayLanguages), array_values($displayLanguages));
}
$monacoOptionsOverride = Json::decodeIfJson($this->monacoEditorOptions);
if ($monacoOptionsOverride === null || is_string($monacoOptionsOverride)) {
$monacoOptionsOverride = [];
}
/**
* @inheritdoc
*/
public function getStaticHtml(mixed $value, ElementInterface $element): string
{
$twigVariables = $this->getFieldRenderVariables($value, $element, false);
// Render the input template
return Craft::$app->getView()->renderTemplate(
'codefield/_components/fields/Code_input',
[
'name' => $this->handle,
'value' => $value,
'field' => $this,
'orientation' => $this->getOrientation($element),
'id' => $id,
'namespacedId' => $namespacedId,
'displayLanguages' => $displayLanguages,
'monacoOptionsOverride' => $monacoOptionsOverride,
]
$twigVariables
);
}

Expand Down Expand Up @@ -282,4 +264,56 @@ public function getContentColumnType(): string

return Schema::TYPE_TEXT;
}

// Protected Methods
// =========================================================================

/**
* Return the Twig variables for rendering the field
*
* @param $value
* @param ElementInterface $element
* @param bool $enabled Whether the field is enabled or not
* @return array[]
*/
protected function getFieldRenderVariables($value, ElementInterface $element, bool $enabled): array
{
// Get our id and namespace
$id = Html::id($this->handle);
$namespacedId = Craft::$app->getView()->namespaceInputId($id);

// Extract just the languages that have been selected for display
$displayLanguages = [];
if ($this->showLanguageDropdown) {
$monacoLanguages = require(__DIR__ . '/MonacoLanguages.php');
$decomposedLanguages = array_column($monacoLanguages, 'label', 'value');
$displayLanguages = array_intersect_key($decomposedLanguages, array_flip($this->availableLanguages));
// Handle "all" checkbox
if ($this->availableLanguages[0] === '*') {
$displayLanguages = $decomposedLanguages;
}
$displayLanguages = array_map(static function ($k, $v) {
return ['value' => $k, 'label' => $v];
}, array_keys($displayLanguages), array_values($displayLanguages));
}
$monacoOptionsOverride = Json::decodeIfJson($this->monacoEditorOptions);
if ($monacoOptionsOverride === null || is_string($monacoOptionsOverride)) {
$monacoOptionsOverride = [];
}
// Disable the Monaco editor
if (!$enabled) {
$monacoOptionsOverride['domReadOnly'] = true;
$monacoOptionsOverride['readOnly'] = true;
}
return [
'name' => $this->handle,
'value' => $value,
'field' => $this,
'orientation' => $this->getOrientation($element),
'id' => $id,
'namespacedId' => $namespacedId,
'displayLanguages' => $displayLanguages,
'monacoOptionsOverride' => $monacoOptionsOverride,
];
}
}

0 comments on commit 50872b1

Please sign in to comment.