Skip to content

Commit 538c61c

Browse files
authored
Merge pull request #1227 from bjarnef/feature/code-editor
Feature: Code Editor
2 parents d134b0b + a4fa97c commit 538c61c

34 files changed

+691
-282
lines changed

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"./block-rte": "./dist-cms/packages/block/block-rte/index.js",
2323
"./block-type": "./dist-cms/packages/block/block-type/index.js",
2424
"./block": "./dist-cms/packages/block/block/index.js",
25-
"./code-editor": "./dist-cms/packages/templating/code-editor/index.js",
25+
"./code-editor": "./dist-cms/packages/code-editor/index.js",
2626
"./collection": "./dist-cms/packages/core/collection/index.js",
2727
"./components": "./dist-cms/packages/core/components/index.js",
2828
"./content-type": "./dist-cms/packages/core/content-type/index.js",
@@ -130,6 +130,7 @@
130130
},
131131
"workspaces": [
132132
"./src/packages/block",
133+
"./src/packages/code-editor",
133134
"./src/packages/core",
134135
"./src/packages/data-type",
135136
"./src/packages/dictionary",

src/apps/backoffice/backoffice.element.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import './components/index.js';
1313

1414
const CORE_PACKAGES = [
1515
import('../../packages/block/umbraco-package.js'),
16+
import('../../packages/code-editor/umbraco-package.js'),
1617
import('../../packages/data-type/umbraco-package.js'),
1718
import('../../packages/dictionary/umbraco-package.js'),
1819
import('../../packages/documents/umbraco-package.js'),

src/assets/lang/da-dk.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,4 +2532,18 @@ export default {
25322532
routeNotFoundTitle: 'Ikke fundet',
25332533
routeNotFoundDescription: 'Den side du leder efter kunne ikke findes. Kontroller adressen og prøv igen.',
25342534
},
2535+
codeEditor: {
2536+
label: 'Code editor',
2537+
languageConfigLabel: 'Sprog',
2538+
languageConfigDescription: 'Vælg sprog til syntax highlighting og IntelliSense.',
2539+
heightConfigLabel: 'Højde',
2540+
heightConfigDescription: 'Indstil højden på editorvinduet i pixels.',
2541+
lineNumbersConfigLabel: 'Linjenumre',
2542+
lineNumbersConfigDescription: 'Vis linjenumre i editorvinduet.',
2543+
minimapConfigLabel: 'Minimap',
2544+
minimapConfigDescription: 'Vis en minimap i editorvinduet.',
2545+
wordWrapConfigLabel: 'Ordbrydning',
2546+
wordWrapConfigDescription:
2547+
'Slå ordbrydning til eller fra, så tekst automatisk brydes ved vinduets kant i stedet for at skabe en horisontal scrollbar.',
2548+
},
25352549
} as UmbLocalizationDictionary;

src/assets/lang/en-us.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,4 +2533,17 @@ export default {
25332533
routeNotFoundTitle: 'Not found',
25342534
routeNotFoundDescription: 'The requested route could not be found. Please check the URL and try again.',
25352535
},
2536+
codeEditor: {
2537+
label: 'Code editor',
2538+
languageConfigLabel: 'Language',
2539+
languageConfigDescription: 'Select the language for syntax highlighting and IntelliSense.',
2540+
heightConfigLabel: 'Height',
2541+
heightConfigDescription: 'Set the height of the code editor in pixels.',
2542+
lineNumbersConfigLabel: 'Line numbers',
2543+
lineNumbersConfigDescription: 'Show line numbers in the code editor.',
2544+
minimapConfigLabel: 'Minimap',
2545+
minimapConfigDescription: 'Show a minimap in the code editor.',
2546+
wordWrapConfigLabel: 'Word wrap',
2547+
wordWrapConfigDescription: 'Enable word wrapping in the code editor.',
2548+
},
25362549
} as UmbLocalizationDictionary;

src/assets/lang/en.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2604,4 +2604,17 @@ export default {
26042604
routeNotFoundTitle: 'Not found',
26052605
routeNotFoundDescription: 'The requested route could not be found. Please check the URL and try again.',
26062606
},
2607+
codeEditor: {
2608+
label: 'Code editor',
2609+
languageConfigLabel: 'Language',
2610+
languageConfigDescription: 'Select the language for syntax highlighting and IntelliSense.',
2611+
heightConfigLabel: 'Height',
2612+
heightConfigDescription: 'Set the height of the code editor in pixels.',
2613+
lineNumbersConfigLabel: 'Line numbers',
2614+
lineNumbersConfigDescription: 'Show line numbers in the code editor.',
2615+
minimapConfigLabel: 'Minimap',
2616+
minimapConfigDescription: 'Show a minimap in the code editor.',
2617+
wordWrapConfigLabel: 'Word wrap',
2618+
wordWrapConfigDescription: 'Enable word wrapping in the code editor.',
2619+
},
26072620
} as UmbLocalizationDictionary;

src/mocks/data/data-type/data-type.data.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,23 @@ export const data: Array<UmbMockDataTypeModel> = [
493493
},
494494
],
495495
},
496+
{
497+
name: 'Code Editor',
498+
id: 'dt-codeEditor',
499+
parent: null,
500+
editorAlias: 'Umbraco.Plain.String',
501+
editorUiAlias: 'Umb.PropertyEditorUi.CodeEditor',
502+
hasChildren: false,
503+
isFolder: false,
504+
canIgnoreStartNodes: false,
505+
isDeletable: true,
506+
values: [
507+
{
508+
alias: 'language',
509+
value: 'html',
510+
},
511+
],
512+
},
496513
{
497514
name: 'Markdown Editor',
498515
id: 'dt-markdownEditor',

src/mocks/data/document-type/document-type.data.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,30 @@ export const data: Array<UmbMockDocumentTypeModel> = [
713713
labelOnTop: false,
714714
},
715715
},
716+
{
717+
id: '34',
718+
container: {
719+
id: 'all-properties-group-key',
720+
},
721+
alias: 'codeEditor',
722+
name: 'Code Editor',
723+
description: 'umb-code-editor configured with the `html` language.',
724+
dataType: {
725+
id: 'dt-codeEditor',
726+
},
727+
variesByCulture: false,
728+
variesBySegment: false,
729+
sortOrder: 0,
730+
validation: {
731+
mandatory: true,
732+
mandatoryMessage: null,
733+
regEx: null,
734+
regExMessage: null,
735+
},
736+
appearance: {
737+
labelOnTop: false,
738+
},
739+
},
716740
],
717741
containers: [
718742
{

src/mocks/data/document/document.data.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,36 @@ export const data: Array<UmbMockDocumentModel> = [
8282
`,
8383
},
8484
},
85+
{
86+
alias: 'codeEditor',
87+
culture: null,
88+
segment: null,
89+
value: `<h1>Lorem ipsum dolor sit amet consectetuer adipiscing elit</h1>
90+
<ul>
91+
<li>Lorem ipsum dolor sit amet consectetuer.</li>
92+
<li>Aenean commodo ligula eget dolor.</li>
93+
<li>Aenean massa cum sociis natoque penatibus.</li>
94+
</ul>
95+
<p>
96+
Lorem ipsum dolor sit amet, consectetuer adipiscing
97+
elit. Aenean commodo ligula eget dolor.
98+
</p>
99+
<p>
100+
<blockquote>
101+
Lorem ipsum dolor sit amet, consectetuer
102+
adipiscing elit. Aenean commodo ligula eget dolor.
103+
Aenean massa <strong>strong</strong>. Cum sociis
104+
natoque penatibus et magnis dis parturient montes,
105+
nascetur ridiculus mus. Donec quam felis, ultricies
106+
nec, pellentesque eu, pretium quis, sem. Nulla consequat
107+
massa quis enim. Donec pede justo, fringilla vel,
108+
aliquet nec, vulputate eget, arcu. In <em>em</em>
109+
enim justo, rhoncus ut, imperdiet a, venenatis vitae,
110+
justo. Nullam <a class="external ext" href="#">link</a>
111+
dictum felis eu pede mollis pretium.
112+
</blockquote>
113+
</p>`,
114+
},
85115
{
86116
alias: 'email',
87117
culture: null,

src/packages/templating/code-editor/code-editor.controller.ts renamed to src/packages/code-editor/code-editor.controller.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import type {
88
UmbCodeEditorHost,
99
UmbCodeEditorRange,
1010
UmbCodeEditorSelection,
11-
} from './code-editor.model.js';
11+
} from './models/code-editor.model.js';
1212
import { themes } from './themes/index.js';
1313
import { monaco } from '@umbraco-cms/backoffice/external/monaco-editor';
1414
import { UmbChangeEvent, UmbInputEvent } from '@umbraco-cms/backoffice/event';
15+
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
1516

1617
//TODO - consider firing change event on blur
1718

@@ -27,9 +28,11 @@ import { UmbChangeEvent, UmbInputEvent } from '@umbraco-cms/backoffice/event';
2728
* @export
2829
* @class UmbCodeEditor
2930
*/
30-
export class UmbCodeEditorController {
31+
export class UmbCodeEditorController extends UmbControllerBase {
3132
#host: UmbCodeEditorHost;
33+
3234
#editor?: monaco.editor.IStandaloneCodeEditor;
35+
3336
/**
3437
* The monaco editor object. This is the actual monaco editor object. It is exposed for advanced usage, but mind the fact that editor might be swapped in the future for a different library, so use on your own responsibility. For more information see [monaco editor API](https://microsoft.github.io/monaco-editor/docs.html#interfaces/editor.IStandaloneCodeEditor.html).
3538
*
@@ -41,6 +44,7 @@ export class UmbCodeEditorController {
4144
}
4245

4346
#options: CodeEditorConstructorOptions = {};
47+
4448
/**
4549
* The options used to create the editor.
4650
*
@@ -63,6 +67,7 @@ export class UmbCodeEditorController {
6367
};
6468

6569
#position: UmbCodeEditorCursorPosition | null = null;
70+
6671
/**
6772
* Provides the current position of the cursor.
6873
*
@@ -72,7 +77,9 @@ export class UmbCodeEditorController {
7277
get position() {
7378
return this.#position;
7479
}
80+
7581
#secondaryPositions: UmbCodeEditorCursorPosition[] = [];
82+
7683
/**
7784
* Provides positions of all the secondary cursors.
7885
*
@@ -102,6 +109,7 @@ export class UmbCodeEditorController {
102109
this.#editor.setValue(newValue ?? '');
103110
}
104111
}
112+
105113
/**
106114
* Provides the current model of the editor. For advanced usage. Bare in mind that in case of the monaco library being swapped in the future, this might not be available. For more information see [monaco editor model API](https://microsoft.github.io/monaco-editor/docs.html#interfaces/editor.ITextModel.html).
107115
*
@@ -112,13 +120,15 @@ export class UmbCodeEditorController {
112120
if (!this.#editor) return null;
113121
return this.#editor.getModel();
114122
}
123+
115124
/**
116125
* Creates an instance of UmbCodeEditor. You should instantiate this class through the `UmbCodeEditorHost` interface and that should happen when inside DOM nodes of the host container are available, otherwise the editor will not be able to initialize, for example in lit `firstUpdated` lifecycle hook. It will make host emit change and input events when the value of the editor changes.
117126
* @param {UmbCodeEditorHost} host
118127
* @param {CodeEditorConstructorOptions} [options]
119128
* @memberof UmbCodeEditor
120129
*/
121130
constructor(host: UmbCodeEditorHost, options?: CodeEditorConstructorOptions) {
131+
super(host);
122132
this.#options = { ...options };
123133
this.#host = host;
124134
this.#registerThemes();
@@ -185,14 +195,7 @@ export class UmbCodeEditorController {
185195

186196
const mergedOptions = { ...this.#defaultMonacoOptions, ...this.#mapOptions(options) };
187197

188-
this.#editor = monaco.editor.create(this.#host.container, {
189-
...mergedOptions,
190-
value: this.#host.code ?? '',
191-
language: this.#host.language,
192-
theme: this.#host.theme,
193-
readOnly: this.#host.readonly,
194-
ariaLabel: this.#host.label,
195-
});
198+
this.#editor = monaco.editor.create(this.#host.container, mergedOptions);
196199

197200
this.#initiateEvents();
198201
}
@@ -378,5 +381,3 @@ export class UmbCodeEditorController {
378381
});
379382
}
380383
}
381-
382-
export default UmbCodeEditorController;

0 commit comments

Comments
 (0)