@api-client/ui 0.5.12 → 0.5.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/elements/code-editor/{ui-code-editor.d.ts → code-editor.d.ts} +2 -2
- package/build/src/elements/code-editor/code-editor.d.ts.map +1 -0
- package/build/src/elements/code-editor/{ui-code-editor.js → code-editor.js} +1 -1
- package/build/src/elements/code-editor/code-editor.js.map +1 -0
- package/build/src/elements/code-editor/internals/CodeEditor.d.ts +21 -59
- package/build/src/elements/code-editor/internals/CodeEditor.d.ts.map +1 -1
- package/build/src/elements/code-editor/internals/CodeEditor.js +136 -105
- package/build/src/elements/code-editor/internals/CodeEditor.js.map +1 -1
- package/build/src/elements/code-editor/internals/CodeEditor.styles.d.ts.map +1 -1
- package/build/src/elements/code-editor/internals/CodeEditor.styles.js +4 -0
- package/build/src/elements/code-editor/internals/CodeEditor.styles.js.map +1 -1
- package/build/src/elements/code-editor/internals/Linter.d.ts +2 -2
- package/build/src/elements/code-editor/internals/Linter.d.ts.map +1 -1
- package/build/src/elements/code-editor/internals/Linter.js +32 -37
- package/build/src/elements/code-editor/internals/Linter.js.map +1 -1
- package/build/src/elements/code-editor/internals/PlaceholderWidget.d.ts +20 -0
- package/build/src/elements/code-editor/internals/PlaceholderWidget.d.ts.map +1 -0
- package/build/src/elements/code-editor/internals/PlaceholderWidget.js +46 -0
- package/build/src/elements/code-editor/internals/PlaceholderWidget.js.map +1 -0
- package/build/src/elements/code-editor/internals/SuggestionMatchDecorator.d.ts +17 -0
- package/build/src/elements/code-editor/internals/SuggestionMatchDecorator.d.ts.map +1 -0
- package/build/src/elements/code-editor/internals/SuggestionMatchDecorator.js +31 -0
- package/build/src/elements/code-editor/internals/SuggestionMatchDecorator.js.map +1 -0
- package/build/src/elements/code-editor/internals/types.d.ts +51 -0
- package/build/src/elements/code-editor/internals/types.d.ts.map +1 -0
- package/build/src/elements/code-editor/internals/types.js +2 -0
- package/build/src/elements/code-editor/internals/types.js.map +1 -0
- package/build/src/index.d.ts +2 -2
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +1 -1
- package/build/src/index.js.map +1 -1
- package/demo/elements/code-editor/CodeEditorDemo.ts +3 -3
- package/package.json +2 -2
- package/src/elements/code-editor/README.md +1 -1
- package/src/elements/code-editor/{ui-code-editor.ts → code-editor.ts} +1 -1
- package/src/elements/code-editor/internals/CodeEditor.styles.ts +4 -0
- package/src/elements/code-editor/internals/CodeEditor.ts +166 -172
- package/src/elements/code-editor/internals/Linter.ts +37 -39
- package/src/elements/code-editor/internals/PlaceholderWidget.ts +50 -0
- package/src/elements/code-editor/internals/SuggestionMatchDecorator.ts +36 -0
- package/src/elements/code-editor/internals/types.ts +54 -0
- package/src/index.ts +2 -2
- package/build/src/elements/code-editor/ui-code-editor.d.ts.map +0 -1
- package/build/src/elements/code-editor/ui-code-editor.js.map +0 -1
|
@@ -9,5 +9,5 @@ declare global {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
export default CodeEditorElement;
|
|
12
|
-
export type { FunctionSchema, FunctionParameter, Suggestion, FunctionInsertEvent, SuggestionInsertEvent, } from './internals/
|
|
13
|
-
//# sourceMappingURL=
|
|
12
|
+
export type { FunctionSchema, FunctionParameter, Suggestion, FunctionInsertEvent, SuggestionInsertEvent, } from './internals/types.js';
|
|
13
|
+
//# sourceMappingURL=code-editor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-editor.d.ts","sourceRoot":"","sources":["../../../../src/elements/code-editor/code-editor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,KAAK,CAAA;AAE5C,OAAO,OAAO,MAAM,2BAA2B,CAAA;AAG/C,qBACa,iBAAkB,SAAQ,OAAO;IAC5C,OAAgB,MAAM,EAAE,iBAAiB,EAAE,CAAW;CACvD;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,aAAa,EAAE,iBAAiB,CAAA;KACjC;CACF;AAED,eAAe,iBAAiB,CAAA;AAChC,YAAY,EACV,cAAc,EACd,iBAAiB,EACjB,UAAU,EACV,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,sBAAsB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-editor.js","sourceRoot":"","sources":["../../../../src/elements/code-editor/code-editor.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,OAAO,MAAM,2BAA2B,CAAA;AAC/C,OAAO,MAAM,MAAM,kCAAkC,CAAA;IAGxC,iBAAiB;4BAD7B,aAAa,CAAC,aAAa,CAAC;;;;sBACU,OAAO;iCAAf,SAAQ,WAAO;;;;YAA9C,6KAEC;;;;QADC,MAAM,CAAU,MAAM,GAAwB,CAAC,MAAM,CAAC,CAAA;;YAD3C,uDAAiB;;;;;SAAjB,iBAAiB;AAU9B,eAAe,iBAAiB,CAAA","sourcesContent":["import type { CSSResultOrNative } from 'lit'\nimport { customElement } from 'lit/decorators.js'\nimport Element from './internals/CodeEditor.js'\nimport styles from './internals/CodeEditor.styles.js'\n\n@customElement('code-editor')\nexport class CodeEditorElement extends Element {\n static override styles: CSSResultOrNative[] = [styles]\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'code-editor': CodeEditorElement\n }\n}\n\nexport default CodeEditorElement\nexport type {\n FunctionSchema,\n FunctionParameter,\n Suggestion,\n FunctionInsertEvent,\n SuggestionInsertEvent,\n} from './internals/types.js'\n"]}
|
|
@@ -1,54 +1,6 @@
|
|
|
1
1
|
import { LitElement, PropertyValues, TemplateResult } from 'lit';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
id: string;
|
|
5
|
-
/** Function name */
|
|
6
|
-
name: string;
|
|
7
|
-
/** Function description */
|
|
8
|
-
description?: string;
|
|
9
|
-
/** Function parameters */
|
|
10
|
-
parameters?: FunctionParameter[];
|
|
11
|
-
/** Return type description */
|
|
12
|
-
returns?: string;
|
|
13
|
-
/** Additional metadata */
|
|
14
|
-
metadata?: Record<string, unknown>;
|
|
15
|
-
}
|
|
16
|
-
export interface FunctionParameter {
|
|
17
|
-
/** Parameter name */
|
|
18
|
-
name: string;
|
|
19
|
-
/** Parameter type */
|
|
20
|
-
type: string;
|
|
21
|
-
/** Parameter description */
|
|
22
|
-
description?: string;
|
|
23
|
-
/** Whether parameter is required */
|
|
24
|
-
required?: boolean;
|
|
25
|
-
/** Default value */
|
|
26
|
-
defaultValue?: unknown;
|
|
27
|
-
}
|
|
28
|
-
export interface Suggestion {
|
|
29
|
-
/** Unique identifier for the suggestion */
|
|
30
|
-
id: string;
|
|
31
|
-
/** Main label displayed */
|
|
32
|
-
label: string;
|
|
33
|
-
/** Supporting description text */
|
|
34
|
-
description?: string;
|
|
35
|
-
/** Suffix text (e.g., type, category) */
|
|
36
|
-
suffix?: string;
|
|
37
|
-
/** Additional data associated with the suggestion */
|
|
38
|
-
data?: Record<string, unknown>;
|
|
39
|
-
}
|
|
40
|
-
export interface FunctionInsertEvent {
|
|
41
|
-
/** The inserted function schema */
|
|
42
|
-
functionSchema: FunctionSchema;
|
|
43
|
-
/** The position where the function was inserted */
|
|
44
|
-
position: number;
|
|
45
|
-
}
|
|
46
|
-
export interface SuggestionInsertEvent {
|
|
47
|
-
/** The inserted suggestion */
|
|
48
|
-
suggestion: Suggestion;
|
|
49
|
-
/** The position where the suggestion was inserted */
|
|
50
|
-
position: number;
|
|
51
|
-
}
|
|
2
|
+
import type { FunctionSchema, Suggestion } from './types.js';
|
|
3
|
+
import { SuggestionMatchDecorator } from './SuggestionMatchDecorator.js';
|
|
52
4
|
/**
|
|
53
5
|
* A CodeMirror 6 based editor component that supports function autocomplete and suggestion placeholders.
|
|
54
6
|
*
|
|
@@ -122,14 +74,15 @@ export default class CodeEditor extends LitElement {
|
|
|
122
74
|
private accessor hasContent;
|
|
123
75
|
private accessor isEditorFocus;
|
|
124
76
|
private editorView?;
|
|
125
|
-
private suggestionMap;
|
|
126
|
-
private functionMap;
|
|
127
77
|
private _previousValue;
|
|
78
|
+
/**
|
|
79
|
+
* Matcher for suggestion placeholders in the editor.
|
|
80
|
+
*/
|
|
81
|
+
placeholderMatcher?: SuggestionMatchDecorator;
|
|
128
82
|
/**
|
|
129
83
|
* Get all suggestions (placeholders) currently in the editor
|
|
130
84
|
*/
|
|
131
85
|
get activeSuggestions(): Suggestion[];
|
|
132
|
-
connectedCallback(): void;
|
|
133
86
|
disconnectedCallback(): void;
|
|
134
87
|
firstUpdated(): void;
|
|
135
88
|
willUpdate(changedProperties: PropertyValues): void;
|
|
@@ -137,22 +90,31 @@ export default class CodeEditor extends LitElement {
|
|
|
137
90
|
* Initialize CodeMirror editor with extensions
|
|
138
91
|
*/
|
|
139
92
|
private initializeCodeMirror;
|
|
93
|
+
/**
|
|
94
|
+
* Creates the ViewPlugin for rendering suggestion placeholders.
|
|
95
|
+
* This is created as a method to get access to the component's `suggestions`.
|
|
96
|
+
*/
|
|
97
|
+
private createPlaceholderPlugin;
|
|
140
98
|
/**
|
|
141
99
|
* Create completion source for functions and suggestions
|
|
142
100
|
*/
|
|
143
101
|
private createCompletionSource;
|
|
102
|
+
private createFunctionCompletion;
|
|
103
|
+
private createSuggestionCompletion;
|
|
144
104
|
/**
|
|
145
|
-
*
|
|
105
|
+
* Creates the source for the hover tooltips.
|
|
106
|
+
* This is an arrow function to automatically bind `this`.
|
|
146
107
|
*/
|
|
147
|
-
private
|
|
108
|
+
private createHoverTooltipSource;
|
|
148
109
|
/**
|
|
149
|
-
*
|
|
110
|
+
* Creates a styled HTML element to display function documentation.
|
|
111
|
+
* This is used for both hover tooltips and autocomplete info panels.
|
|
150
112
|
*/
|
|
151
|
-
private
|
|
113
|
+
private createFunctionInfoElement;
|
|
152
114
|
/**
|
|
153
|
-
*
|
|
115
|
+
* Format function call with parameters
|
|
154
116
|
*/
|
|
155
|
-
private
|
|
117
|
+
private formatFunctionCall;
|
|
156
118
|
/**
|
|
157
119
|
* Update editor content when value changes
|
|
158
120
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeEditor.d.ts","sourceRoot":"","sources":["../../../../../src/elements/code-editor/internals/CodeEditor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,cAAc,EAAE,cAAc,EAAW,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"CodeEditor.d.ts","sourceRoot":"","sources":["../../../../../src/elements/code-editor/internals/CodeEditor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,cAAc,EAAE,cAAc,EAAW,MAAM,KAAK,CAAA;AA2B/E,OAAO,KAAK,EAAuB,cAAc,EAAE,UAAU,EAAyB,MAAM,YAAY,CAAA;AACxG,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAA;AAExE;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,UAAU;IAChD;;;OAGG;IACH,OAAgB,iBAAiB,EAAE,cAAc,CAGhD;IAED;;OAEG;IAEH,QAAQ,CAAC,KAAK,SAAK;IAEnB;;OAEG;IAEH,QAAQ,CAAC,cAAc,SAAK;IAE5B;;OAEG;IAEH,QAAQ,CAAC,QAAQ,UAAQ;IAEzB;;OAEG;IAEH,QAAQ,CAAC,OAAO,UAAQ;IAExB;;OAEG;IAEH,QAAQ,CAAC,IAAI,SAAK;IAElB;;OAEG;IAEH,QAAQ,CAAC,QAAQ,UAAQ;IAEzB;;OAEG;IAEH,QAAQ,CAAC,WAAW,SAAK;IAEzB;;OAEG;IAEH,QAAQ,CAAC,KAAK,SAAK;IAEnB;;OAEG;IAEH,QAAQ,CAAC,eAAe,EAAE,cAAc,EAAE,CAAK;IAE/C;;OAEG;IAEH,QAAQ,CAAC,WAAW,EAAE,UAAU,EAAE,CAAK;IAEvC;;OAEG;IAEH,QAAQ,CAAC,SAAS,UAAQ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AUrB,MAAM,IAAI,cAAc;CAgBlC"}
|
|
@@ -2,59 +2,17 @@ import { __esDecorate, __runInitializers } from "tslib";
|
|
|
2
2
|
import { html, LitElement, nothing } from 'lit';
|
|
3
3
|
import { property, query, state } from 'lit/decorators.js';
|
|
4
4
|
import { classMap } from 'lit/directives/class-map.js';
|
|
5
|
+
import { linter } from '@codemirror/lint';
|
|
5
6
|
import { EditorState } from '@codemirror/state';
|
|
6
|
-
import { autocompletion } from '@codemirror/autocomplete';
|
|
7
|
+
import { autocompletion, } from '@codemirror/autocomplete';
|
|
7
8
|
import { javascript } from '@codemirror/lang-javascript';
|
|
8
9
|
import { syntaxHighlighting, defaultHighlightStyle } from '@codemirror/language';
|
|
9
10
|
import { oneDark } from '@codemirror/theme-one-dark';
|
|
10
11
|
import { keymap } from '@codemirror/view';
|
|
11
12
|
import { defaultKeymap } from '@codemirror/commands';
|
|
12
|
-
import { EditorView,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
constructor(placeholderText) {
|
|
16
|
-
super();
|
|
17
|
-
this.placeholderText = placeholderText;
|
|
18
|
-
}
|
|
19
|
-
eq(other) {
|
|
20
|
-
return this.placeholderText == other.placeholderText;
|
|
21
|
-
}
|
|
22
|
-
toDOM() {
|
|
23
|
-
const placeholder = document.createElement('span');
|
|
24
|
-
placeholder.className = 'cm-pill';
|
|
25
|
-
placeholder.textContent = this.placeholderText;
|
|
26
|
-
return placeholder;
|
|
27
|
-
}
|
|
28
|
-
ignoreEvent() {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
// We do variables Salesforce style, with double curly braces.
|
|
33
|
-
// This decorator replaces {{variable}} with a placeholder widget.
|
|
34
|
-
const placeholderMatcher = new MatchDecorator({
|
|
35
|
-
regexp: /\{\{(\w+)\}\}/g,
|
|
36
|
-
decoration: (match) => Decoration.replace({
|
|
37
|
-
widget: new PlaceholderWidget(match[1]),
|
|
38
|
-
}),
|
|
39
|
-
});
|
|
40
|
-
/**
|
|
41
|
-
* @see https://codemirror.net/examples/decoration/
|
|
42
|
-
*/
|
|
43
|
-
class AtomicDecorationRange {
|
|
44
|
-
placeholders;
|
|
45
|
-
constructor(view) {
|
|
46
|
-
this.placeholders = placeholderMatcher.createDeco(view);
|
|
47
|
-
}
|
|
48
|
-
update(update) {
|
|
49
|
-
this.placeholders = placeholderMatcher.updateDeco(update, this.placeholders);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
const placeholders = ViewPlugin.fromClass(AtomicDecorationRange, {
|
|
53
|
-
decorations: (instance) => instance.placeholders,
|
|
54
|
-
provide: (plugin) => EditorView.atomicRanges.of((view) => {
|
|
55
|
-
return view.plugin(plugin)?.placeholders || Decoration.none;
|
|
56
|
-
}),
|
|
57
|
-
});
|
|
13
|
+
import { EditorView, Decoration, ViewPlugin, hoverTooltip, } from '@codemirror/view';
|
|
14
|
+
import { functionLinter } from './Linter.js';
|
|
15
|
+
import { SuggestionMatchDecorator } from './SuggestionMatchDecorator.js';
|
|
58
16
|
let CodeEditor = (() => {
|
|
59
17
|
let _classSuper = LitElement;
|
|
60
18
|
let _label_decorators;
|
|
@@ -271,9 +229,11 @@ let CodeEditor = (() => {
|
|
|
271
229
|
get isEditorFocus() { return this.#isEditorFocus_accessor_storage; }
|
|
272
230
|
set isEditorFocus(value) { this.#isEditorFocus_accessor_storage = value; }
|
|
273
231
|
editorView = __runInitializers(this, _isEditorFocus_extraInitializers);
|
|
274
|
-
suggestionMap = new Map();
|
|
275
|
-
functionMap = new Map();
|
|
276
232
|
_previousValue = '';
|
|
233
|
+
/**
|
|
234
|
+
* Matcher for suggestion placeholders in the editor.
|
|
235
|
+
*/
|
|
236
|
+
placeholderMatcher;
|
|
277
237
|
/**
|
|
278
238
|
* Get all suggestions (placeholders) currently in the editor
|
|
279
239
|
*/
|
|
@@ -291,10 +251,6 @@ let CodeEditor = (() => {
|
|
|
291
251
|
}
|
|
292
252
|
return suggestions;
|
|
293
253
|
}
|
|
294
|
-
connectedCallback() {
|
|
295
|
-
super.connectedCallback();
|
|
296
|
-
this.setupSuggestionMaps();
|
|
297
|
-
}
|
|
298
254
|
disconnectedCallback() {
|
|
299
255
|
super.disconnectedCallback();
|
|
300
256
|
this.editorView?.destroy();
|
|
@@ -305,8 +261,10 @@ let CodeEditor = (() => {
|
|
|
305
261
|
}
|
|
306
262
|
willUpdate(changedProperties) {
|
|
307
263
|
super.willUpdate(changedProperties);
|
|
308
|
-
if (changedProperties.has('suggestions')
|
|
309
|
-
this.
|
|
264
|
+
if (changedProperties.has('suggestions')) {
|
|
265
|
+
if (this.placeholderMatcher) {
|
|
266
|
+
this.placeholderMatcher.suggestions = this.suggestions || [];
|
|
267
|
+
}
|
|
310
268
|
}
|
|
311
269
|
if (changedProperties.has('value') && this.editorView) {
|
|
312
270
|
this.updateEditorContent();
|
|
@@ -335,8 +293,9 @@ let CodeEditor = (() => {
|
|
|
335
293
|
this.handleFocusChange(update.view.hasFocus);
|
|
336
294
|
}
|
|
337
295
|
}),
|
|
338
|
-
|
|
339
|
-
|
|
296
|
+
this.createPlaceholderPlugin(),
|
|
297
|
+
hoverTooltip(this.createHoverTooltipSource),
|
|
298
|
+
linter((view) => functionLinter(view, this.functionSchemas, (e) => this.dispatchEvent(e))),
|
|
340
299
|
];
|
|
341
300
|
// Add language support
|
|
342
301
|
if (this.language === 'javascript') {
|
|
@@ -361,6 +320,28 @@ let CodeEditor = (() => {
|
|
|
361
320
|
parent: this.editorContainer,
|
|
362
321
|
});
|
|
363
322
|
}
|
|
323
|
+
/**
|
|
324
|
+
* Creates the ViewPlugin for rendering suggestion placeholders.
|
|
325
|
+
* This is created as a method to get access to the component's `suggestions`.
|
|
326
|
+
*/
|
|
327
|
+
createPlaceholderPlugin() {
|
|
328
|
+
const placeholderMatcher = new SuggestionMatchDecorator(/\{\{(\w+)\}\}/g, this.suggestions);
|
|
329
|
+
this.placeholderMatcher = placeholderMatcher;
|
|
330
|
+
// This class needs to be defined here to have access to the `placeholderMatcher`
|
|
331
|
+
class AtomicDecorationRange {
|
|
332
|
+
placeholders;
|
|
333
|
+
constructor(view) {
|
|
334
|
+
this.placeholders = placeholderMatcher.createDeco(view);
|
|
335
|
+
}
|
|
336
|
+
update(update) {
|
|
337
|
+
this.placeholders = placeholderMatcher.updateDeco(update, this.placeholders);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return ViewPlugin.fromClass(AtomicDecorationRange, {
|
|
341
|
+
decorations: (instance) => instance.placeholders,
|
|
342
|
+
provide: (plugin) => EditorView.atomicRanges.of((view) => view.plugin(plugin)?.placeholders || Decoration.none),
|
|
343
|
+
});
|
|
344
|
+
}
|
|
364
345
|
/**
|
|
365
346
|
* Create completion source for functions and suggestions
|
|
366
347
|
*/
|
|
@@ -375,19 +356,7 @@ let CodeEditor = (() => {
|
|
|
375
356
|
const prefix = functionMatch[1];
|
|
376
357
|
const functions = this.functionSchemas
|
|
377
358
|
.filter((fn) => fn.name.toLowerCase().startsWith(prefix.toLowerCase()))
|
|
378
|
-
.map((fn) => (
|
|
379
|
-
label: fn.name,
|
|
380
|
-
detail: fn.description || '',
|
|
381
|
-
info: this.formatFunctionInfo(fn),
|
|
382
|
-
apply: (view, completion, from, to) => {
|
|
383
|
-
const functionCall = this.formatFunctionCall(fn);
|
|
384
|
-
view.dispatch({
|
|
385
|
-
changes: { from, to, insert: functionCall },
|
|
386
|
-
selection: { anchor: from + functionCall.length },
|
|
387
|
-
});
|
|
388
|
-
this.dispatchFunctionInsert(fn, from);
|
|
389
|
-
},
|
|
390
|
-
}));
|
|
359
|
+
.map((fn) => this.createFunctionCompletion(fn));
|
|
391
360
|
if (functions.length > 0) {
|
|
392
361
|
return {
|
|
393
362
|
from: pos - prefix.length,
|
|
@@ -401,19 +370,7 @@ let CodeEditor = (() => {
|
|
|
401
370
|
const prefix = suggestionMatch[1];
|
|
402
371
|
const suggestions = this.suggestions
|
|
403
372
|
.filter((suggestion) => suggestion.label.toLowerCase().startsWith(prefix.toLowerCase()))
|
|
404
|
-
.map((suggestion) => (
|
|
405
|
-
label: suggestion.label,
|
|
406
|
-
detail: suggestion.description || '',
|
|
407
|
-
info: suggestion.suffix || '',
|
|
408
|
-
apply: (view, completion, from, to) => {
|
|
409
|
-
const placeholderText = `{{${suggestion.label}}}`;
|
|
410
|
-
view.dispatch({
|
|
411
|
-
changes: { from: from - 2, to, insert: placeholderText }, // -2 to include the {{
|
|
412
|
-
selection: { anchor: from - 2 + placeholderText.length },
|
|
413
|
-
});
|
|
414
|
-
this.dispatchSuggestionInsert(suggestion, from - 2);
|
|
415
|
-
},
|
|
416
|
-
}));
|
|
373
|
+
.map((suggestion) => this.createSuggestionCompletion(suggestion));
|
|
417
374
|
if (suggestions.length > 0) {
|
|
418
375
|
return {
|
|
419
376
|
from: pos - prefix.length,
|
|
@@ -424,25 +381,112 @@ let CodeEditor = (() => {
|
|
|
424
381
|
return null;
|
|
425
382
|
};
|
|
426
383
|
}
|
|
384
|
+
createFunctionCompletion(schema) {
|
|
385
|
+
const result = {
|
|
386
|
+
label: schema.name,
|
|
387
|
+
detail: schema.description || '',
|
|
388
|
+
info: () => this.createFunctionInfoElement(schema),
|
|
389
|
+
apply: (view, completion, from, to) => {
|
|
390
|
+
const functionCall = this.formatFunctionCall(schema);
|
|
391
|
+
view.dispatch({
|
|
392
|
+
changes: { from, to, insert: functionCall },
|
|
393
|
+
selection: { anchor: from + functionCall.length },
|
|
394
|
+
});
|
|
395
|
+
this.dispatchFunctionInsert(schema, from);
|
|
396
|
+
},
|
|
397
|
+
};
|
|
398
|
+
return result;
|
|
399
|
+
}
|
|
400
|
+
createSuggestionCompletion(suggestion) {
|
|
401
|
+
const result = {
|
|
402
|
+
label: suggestion.label,
|
|
403
|
+
detail: suggestion.description || '',
|
|
404
|
+
info: suggestion.suffix || '',
|
|
405
|
+
apply: (view, completion, from, to) => {
|
|
406
|
+
const placeholderText = `{{${suggestion.label}}}`;
|
|
407
|
+
view.dispatch({
|
|
408
|
+
changes: { from: from - 2, to, insert: placeholderText }, // -2 to include the {{
|
|
409
|
+
selection: { anchor: from - 2 + placeholderText.length },
|
|
410
|
+
});
|
|
411
|
+
this.dispatchSuggestionInsert(suggestion, from - 2);
|
|
412
|
+
},
|
|
413
|
+
};
|
|
414
|
+
return result;
|
|
415
|
+
}
|
|
427
416
|
/**
|
|
428
|
-
*
|
|
417
|
+
* Creates the source for the hover tooltips.
|
|
418
|
+
* This is an arrow function to automatically bind `this`.
|
|
429
419
|
*/
|
|
430
|
-
|
|
431
|
-
|
|
420
|
+
createHoverTooltipSource = (view, pos) => {
|
|
421
|
+
const word = view.state.wordAt(pos);
|
|
422
|
+
if (!word) {
|
|
423
|
+
return null;
|
|
424
|
+
}
|
|
425
|
+
const functionName = view.state.doc.sliceString(word.from, word.to);
|
|
426
|
+
const fnSchema = this.functionSchemas.find((schema) => schema.name === functionName);
|
|
427
|
+
if (!fnSchema) {
|
|
428
|
+
return null;
|
|
429
|
+
}
|
|
430
|
+
return {
|
|
431
|
+
pos: word.from,
|
|
432
|
+
end: word.to,
|
|
433
|
+
above: true,
|
|
434
|
+
create: () => ({ dom: this.createFunctionInfoElement(fnSchema) }),
|
|
435
|
+
};
|
|
436
|
+
};
|
|
437
|
+
/**
|
|
438
|
+
* Creates a styled HTML element to display function documentation.
|
|
439
|
+
* This is used for both hover tooltips and autocomplete info panels.
|
|
440
|
+
*/
|
|
441
|
+
createFunctionInfoElement(fn) {
|
|
442
|
+
const container = document.createElement('div');
|
|
443
|
+
container.className = 'function-info'; // for styling
|
|
444
|
+
if (fn.description) {
|
|
445
|
+
const description = document.createElement('p');
|
|
446
|
+
description.className = 'description';
|
|
447
|
+
description.textContent = fn.description;
|
|
448
|
+
container.appendChild(description);
|
|
449
|
+
}
|
|
432
450
|
if (fn.parameters && fn.parameters.length > 0) {
|
|
433
|
-
|
|
451
|
+
const paramsContainer = document.createElement('div');
|
|
452
|
+
paramsContainer.className = 'parameters';
|
|
453
|
+
const paramsHeader = document.createElement('h4');
|
|
454
|
+
paramsHeader.textContent = 'Parameters';
|
|
455
|
+
paramsContainer.appendChild(paramsHeader);
|
|
456
|
+
const paramsList = document.createElement('ul');
|
|
434
457
|
fn.parameters.forEach((param) => {
|
|
435
|
-
|
|
458
|
+
const listItem = document.createElement('li');
|
|
459
|
+
const name = document.createElement('span');
|
|
460
|
+
name.className = 'param-name';
|
|
461
|
+
name.textContent = param.name;
|
|
462
|
+
const type = document.createElement('span');
|
|
463
|
+
type.className = 'param-type';
|
|
464
|
+
type.textContent = `: ${param.type}`;
|
|
465
|
+
listItem.appendChild(name);
|
|
466
|
+
listItem.appendChild(type);
|
|
436
467
|
if (param.description) {
|
|
437
|
-
|
|
468
|
+
const paramDesc = document.createElement('p');
|
|
469
|
+
paramDesc.className = 'param-description';
|
|
470
|
+
paramDesc.textContent = param.description;
|
|
471
|
+
listItem.appendChild(paramDesc);
|
|
438
472
|
}
|
|
439
|
-
|
|
473
|
+
paramsList.appendChild(listItem);
|
|
440
474
|
});
|
|
475
|
+
paramsContainer.appendChild(paramsList);
|
|
476
|
+
container.appendChild(paramsContainer);
|
|
441
477
|
}
|
|
442
478
|
if (fn.returns) {
|
|
443
|
-
|
|
479
|
+
const returnsContainer = document.createElement('div');
|
|
480
|
+
returnsContainer.className = 'returns';
|
|
481
|
+
const returnsHeader = document.createElement('h4');
|
|
482
|
+
returnsHeader.textContent = 'Returns';
|
|
483
|
+
returnsContainer.appendChild(returnsHeader);
|
|
484
|
+
const returnsDesc = document.createElement('p');
|
|
485
|
+
returnsDesc.textContent = fn.returns;
|
|
486
|
+
returnsContainer.appendChild(returnsDesc);
|
|
487
|
+
container.appendChild(returnsContainer);
|
|
444
488
|
}
|
|
445
|
-
return
|
|
489
|
+
return container;
|
|
446
490
|
}
|
|
447
491
|
/**
|
|
448
492
|
* Format function call with parameters
|
|
@@ -461,19 +505,6 @@ let CodeEditor = (() => {
|
|
|
461
505
|
.join(', ');
|
|
462
506
|
return `${fn.name}(${params})`;
|
|
463
507
|
}
|
|
464
|
-
/**
|
|
465
|
-
* Setup suggestion and function maps for quick lookup
|
|
466
|
-
*/
|
|
467
|
-
setupSuggestionMaps() {
|
|
468
|
-
this.suggestionMap.clear();
|
|
469
|
-
this.functionMap.clear();
|
|
470
|
-
this.suggestions.forEach((suggestion) => {
|
|
471
|
-
this.suggestionMap.set(suggestion.id, suggestion);
|
|
472
|
-
});
|
|
473
|
-
this.functionSchemas.forEach((fn) => {
|
|
474
|
-
this.functionMap.set(fn.id, fn);
|
|
475
|
-
});
|
|
476
|
-
}
|
|
477
508
|
/**
|
|
478
509
|
* Update editor content when value changes
|
|
479
510
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeEditor.js","sourceRoot":"","sources":["../../../../../src/elements/code-editor/internals/CodeEditor.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAkC,OAAO,EAAE,MAAM,KAAK,CAAA;AAC/E,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AACtD,OAAO,EAAE,WAAW,EAAa,MAAM,mBAAmB,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAyD,MAAM,0BAA0B,CAAA;AAChH,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AACxD,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAChF,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EACL,UAAU,EACV,cAAc,EACd,UAAU,EAEV,UAAU,EAEV,UAAU,GACX,MAAM,kBAAkB,CAAA;AAyDzB,MAAM,iBAAkB,SAAQ,UAAU;IACrB;IA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MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAA;YACzD,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;gBACvB,OAAO,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;gBACnC,SAAS,EAAE,EAAE,MAAM,EAAE,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE;aAC1C,CAAC,CAAA;QACJ,CAAC;QAEQ,MAAM;YACb,MAAM,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAA;YAC7B,MAAM,iBAAiB,GAAG,CAAC,CAAC,IAAI,CAAC,cAAc,CAAA;YAE/C,OAAO,IAAI,CAAA;4BACa,QAAQ,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,aAAa,EAAE,SAAS,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;;YAEtF,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAA,sBAAsB,IAAI,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO;;;;;UAKnE,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAA,gCAAgC,IAAI,CAAC,cAAc,QAAQ,CAAC,CAAC,CAAC,OAAO;;KAElG,CAAA;QACH,CAAC;;;AAldH;;;;;;;;;;;;;;GAcG;AACH","sourcesContent":["import { html, LitElement, PropertyValues, TemplateResult, nothing } from 'lit'\nimport { property, query, state } from 'lit/decorators.js'\nimport { classMap } from 'lit/directives/class-map.js'\nimport { EditorState, Extension } from '@codemirror/state'\nimport { autocompletion, CompletionContext, CompletionResult, CompletionSource } from '@codemirror/autocomplete'\nimport { javascript } from '@codemirror/lang-javascript'\nimport { syntaxHighlighting, defaultHighlightStyle } from '@codemirror/language'\nimport { oneDark } from '@codemirror/theme-one-dark'\nimport { keymap } from '@codemirror/view'\nimport { defaultKeymap } from '@codemirror/commands'\nimport {\n EditorView,\n MatchDecorator,\n Decoration,\n DecorationSet,\n ViewPlugin,\n ViewUpdate,\n WidgetType,\n} from '@codemirror/view'\n\nexport interface FunctionSchema {\n /** Unique identifier for the function */\n id: string\n /** Function name */\n name: string\n /** Function description */\n description?: string\n /** Function parameters */\n parameters?: FunctionParameter[]\n /** Return type description */\n returns?: string\n /** Additional metadata */\n metadata?: Record<string, unknown>\n}\n\nexport interface FunctionParameter {\n /** Parameter name */\n name: string\n /** Parameter type */\n type: string\n /** Parameter description */\n description?: string\n /** Whether parameter is required */\n required?: boolean\n /** Default value */\n defaultValue?: unknown\n}\n\nexport interface Suggestion {\n /** Unique identifier for the suggestion */\n id: string\n /** Main label displayed */\n label: string\n /** Supporting description text */\n description?: string\n /** Suffix text (e.g., type, category) */\n suffix?: string\n /** Additional data associated with the suggestion */\n data?: Record<string, unknown>\n}\n\nexport interface FunctionInsertEvent {\n /** The inserted function schema */\n functionSchema: FunctionSchema\n /** The position where the function was inserted */\n position: number\n}\n\nexport interface SuggestionInsertEvent {\n /** The inserted suggestion */\n suggestion: Suggestion\n /** The position where the suggestion was inserted */\n position: number\n}\n\nclass PlaceholderWidget extends WidgetType {\n constructor(public placeholderText: string) {\n super()\n }\n\n override eq(other: WidgetType): boolean {\n return this.placeholderText == (other as PlaceholderWidget).placeholderText\n }\n\n toDOM(): HTMLElement {\n const placeholder = document.createElement('span')\n placeholder.className = 'cm-pill'\n placeholder.textContent = this.placeholderText\n return placeholder\n }\n\n override ignoreEvent(): boolean {\n return false\n }\n}\n\n// We do variables Salesforce style, with double curly braces.\n// This decorator replaces {{variable}} with a placeholder widget.\nconst placeholderMatcher = new MatchDecorator({\n regexp: /\\{\\{(\\w+)\\}\\}/g,\n decoration: (match) =>\n Decoration.replace({\n widget: new PlaceholderWidget(match[1]),\n }),\n})\n\n/**\n * @see https://codemirror.net/examples/decoration/\n */\nclass AtomicDecorationRange {\n placeholders: DecorationSet\n constructor(view: EditorView) {\n this.placeholders = placeholderMatcher.createDeco(view)\n }\n update(update: ViewUpdate) {\n this.placeholders = placeholderMatcher.updateDeco(update, this.placeholders)\n }\n}\n\nconst placeholders = ViewPlugin.fromClass(AtomicDecorationRange, {\n decorations: (instance) => instance.placeholders,\n provide: (plugin) =>\n EditorView.atomicRanges.of((view) => {\n return view.plugin(plugin)?.placeholders || Decoration.none\n }),\n})\n\n/**\n * A CodeMirror 6 based editor component that supports function autocomplete and suggestion placeholders.\n *\n * Features:\n * - Dynamic function schema loading\n * - Autocomplete for functions and suggestions\n * - Suggestion placeholders with double curly braces ({{suggestion}})\n * - Keyboard navigation\n * - Accessibility support\n *\n * @fires function-insert - When a function is inserted\n * @fires suggestion-insert - When a suggestion is inserted\n * @fires input - When the editor content changes\n * @fires change - When the editor loses focus and content has changed\n */\nexport default class CodeEditor extends LitElement {\n /**\n * Shadow root configuration for the component.\n * Uses 'open' mode for accessibility and delegates focus to enable proper focus management.\n */\n static override shadowRootOptions: ShadowRootInit = {\n mode: 'open',\n delegatesFocus: true,\n }\n\n /**\n * The label text displayed as placeholder/floating label\n */\n @property({ type: String })\n accessor label = ''\n\n /**\n * Supporting text displayed below the editor\n */\n @property({ type: String, attribute: 'supporting-text' })\n accessor supportingText = ''\n\n /**\n * Whether the component is disabled\n */\n @property({ type: Boolean, reflect: true })\n accessor disabled = false\n\n /**\n * Whether the component is in an invalid state\n */\n @property({ type: Boolean, reflect: true })\n accessor invalid = false\n\n /**\n * The name attribute for form integration\n */\n @property({ type: String })\n accessor name = ''\n\n /**\n * Whether the input is required\n */\n @property({ type: Boolean })\n accessor required = false\n\n /**\n * Placeholder text shown when editor is empty\n */\n @property({ type: String })\n accessor placeholder = ''\n\n /**\n * The editor content value\n */\n @property({ type: String })\n accessor value = ''\n\n /**\n * Available function schemas for autocomplete\n */\n @property({ type: Array, attribute: false })\n accessor functionSchemas: FunctionSchema[] = []\n\n /**\n * Available suggestions for autocomplete\n */\n @property({ type: Array, attribute: false })\n accessor suggestions: Suggestion[] = []\n\n /**\n * Whether to use dark theme\n */\n @property({ type: Boolean, attribute: 'dark-theme' })\n accessor darkTheme = false\n\n /**\n * Programming language for syntax highlighting\n */\n @property({ type: String })\n accessor language = 'javascript'\n\n @query('.editor-container')\n private accessor editorContainer!: HTMLDivElement\n\n @state()\n private accessor hasContent = false\n\n @state()\n private accessor isEditorFocus = false\n\n private editorView?: EditorView\n private suggestionMap = new Map<string, Suggestion>()\n private functionMap = new Map<string, FunctionSchema>()\n private _previousValue = ''\n\n /**\n * Get all suggestions (placeholders) currently in the editor\n */\n get activeSuggestions(): Suggestion[] {\n const suggestions: Suggestion[] = []\n const placeholderPattern = /\\{\\{(\\w+)\\}\\}/g\n let match: RegExpExecArray | null\n while ((match = placeholderPattern.exec(this.value)) !== null) {\n const placeholderText = match[1]\n // Find suggestion by label\n const suggestion = this.suggestions.find((s) => s.label.toLowerCase() === placeholderText.toLowerCase())\n if (suggestion) {\n suggestions.push(suggestion)\n }\n }\n return suggestions\n }\n\n override connectedCallback(): void {\n super.connectedCallback()\n this.setupSuggestionMaps()\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback()\n this.editorView?.destroy()\n }\n\n override firstUpdated(): void {\n this.initializeCodeMirror()\n this.updateEditorContent()\n }\n\n override willUpdate(changedProperties: PropertyValues): void {\n super.willUpdate(changedProperties)\n\n if (changedProperties.has('suggestions') || changedProperties.has('functionSchemas')) {\n this.setupSuggestionMaps()\n }\n\n if (changedProperties.has('value') && this.editorView) {\n this.updateEditorContent()\n }\n\n if (changedProperties.has('disabled')) {\n this.updateEditorState()\n }\n }\n\n /**\n * Initialize CodeMirror editor with extensions\n */\n private initializeCodeMirror(): void {\n const extensions: Extension[] = [\n keymap.of(defaultKeymap),\n syntaxHighlighting(defaultHighlightStyle),\n autocompletion({\n override: [this.createCompletionSource()],\n activateOnTyping: true,\n maxRenderedOptions: 10,\n }),\n EditorView.updateListener.of((update: ViewUpdate) => {\n if (update.docChanged) {\n this.handleEditorChange()\n }\n if (update.focusChanged) {\n this.handleFocusChange(update.view.hasFocus)\n }\n }),\n placeholders,\n // linter((view) => functionLinter(view as unknown as EditorView, this.functionSchemas)),\n ]\n\n // Add language support\n if (this.language === 'javascript') {\n extensions.push(javascript())\n }\n\n // Add theme\n if (this.darkTheme) {\n extensions.push(oneDark)\n }\n\n // Add placeholder\n if (this.placeholder) {\n extensions.push(\n EditorView.contentAttributes.of({\n 'aria-placeholder': this.placeholder,\n })\n )\n }\n\n const state = EditorState.create({\n doc: this.value,\n extensions,\n })\n\n this.editorView = new EditorView({\n state,\n parent: this.editorContainer,\n })\n }\n\n /**\n * Create completion source for functions and suggestions\n */\n private createCompletionSource(): CompletionSource {\n return (context: CompletionContext): CompletionResult | null => {\n const { pos } = context\n const line = context.state.doc.lineAt(pos)\n const textBefore = line.text.slice(0, pos - line.from)\n\n // Check if we're typing a function name\n const functionMatch = textBefore.match(/(\\w+)$/)\n if (functionMatch) {\n const prefix = functionMatch[1]\n const functions = this.functionSchemas\n .filter((fn) => fn.name.toLowerCase().startsWith(prefix.toLowerCase()))\n .map((fn) => ({\n label: fn.name,\n detail: fn.description || '',\n info: this.formatFunctionInfo(fn),\n apply: (view: EditorView, completion: unknown, from: number, to: number) => {\n const functionCall = this.formatFunctionCall(fn)\n view.dispatch({\n changes: { from, to, insert: functionCall },\n selection: { anchor: from + functionCall.length },\n })\n this.dispatchFunctionInsert(fn, from)\n },\n }))\n\n if (functions.length > 0) {\n return {\n from: pos - prefix.length,\n options: functions,\n }\n }\n }\n\n // Check if we're typing a suggestion trigger (e.g., {{)\n const suggestionMatch = textBefore.match(/\\{\\{(\\w*)$/)\n if (suggestionMatch) {\n const prefix = suggestionMatch[1]\n const suggestions = this.suggestions\n .filter((suggestion) => suggestion.label.toLowerCase().startsWith(prefix.toLowerCase()))\n .map((suggestion) => ({\n label: suggestion.label,\n detail: suggestion.description || '',\n info: suggestion.suffix || '',\n apply: (view: EditorView, completion: unknown, from: number, to: number) => {\n const placeholderText = `{{${suggestion.label}}}`\n view.dispatch({\n changes: { from: from - 2, to, insert: placeholderText }, // -2 to include the {{\n selection: { anchor: from - 2 + placeholderText.length },\n })\n this.dispatchSuggestionInsert(suggestion, from - 2)\n },\n }))\n\n if (suggestions.length > 0) {\n return {\n from: pos - prefix.length,\n options: suggestions,\n }\n }\n }\n\n return null\n }\n }\n\n /**\n * Format function information for autocomplete\n */\n private formatFunctionInfo(fn: FunctionSchema): string {\n let info = fn.description || ''\n if (fn.parameters && fn.parameters.length > 0) {\n info += '\\n\\nParameters:\\n'\n fn.parameters.forEach((param) => {\n info += `• ${param.name}: ${param.type}`\n if (param.description) {\n info += ` - ${param.description}`\n }\n info += '\\n'\n })\n }\n if (fn.returns) {\n info += `\\nReturns: ${fn.returns}`\n }\n return info\n }\n\n /**\n * Format function call with parameters\n */\n private formatFunctionCall(fn: FunctionSchema): string {\n if (!fn.parameters || fn.parameters.length === 0) {\n return `${fn.name}()`\n }\n\n const params = fn.parameters\n .map((param) => {\n if (param.required) {\n return param.name\n }\n return `${param.name}?`\n })\n .join(', ')\n\n return `${fn.name}(${params})`\n }\n\n /**\n * Setup suggestion and function maps for quick lookup\n */\n private setupSuggestionMaps(): void {\n this.suggestionMap.clear()\n this.functionMap.clear()\n\n this.suggestions.forEach((suggestion) => {\n this.suggestionMap.set(suggestion.id, suggestion)\n })\n\n this.functionSchemas.forEach((fn) => {\n this.functionMap.set(fn.id, fn)\n })\n }\n\n /**\n * Update editor content when value changes\n */\n private updateEditorContent(): void {\n if (!this.editorView) return\n\n const currentValue = this.editorView.state.doc.toString()\n if (currentValue !== this.value) {\n this.editorView.dispatch({\n changes: {\n from: 0,\n to: this.editorView.state.doc.length,\n insert: this.value,\n },\n })\n }\n }\n\n /**\n * Update editor state (e.g., disabled state)\n */\n private updateEditorState(): void {\n if (!this.editorView) return\n\n // For now, we'll handle disabled state differently\n // CodeMirror 6 doesn't use reconfigure for editable\n if (this.disabled) {\n this.editorView.contentDOM.setAttribute('contenteditable', 'false')\n } else {\n this.editorView.contentDOM.setAttribute('contenteditable', 'true')\n }\n }\n\n /**\n * Handle editor content change\n */\n private handleEditorChange(): void {\n if (!this.editorView) return\n\n const newValue = this.editorView.state.doc.toString()\n if (newValue !== this._previousValue) {\n this._previousValue = newValue\n this.value = newValue\n this.hasContent = newValue.length > 0\n\n this.dispatchEvent(new Event('input', { bubbles: true }))\n }\n }\n\n /**\n * Handle focus change\n */\n private handleFocusChange(hasFocus: boolean): void {\n this.isEditorFocus = hasFocus\n\n if (!hasFocus && this.value !== this._previousValue) {\n this.dispatchEvent(new Event('change', { bubbles: true }))\n }\n }\n\n /**\n * Dispatch function insert event\n */\n private dispatchFunctionInsert(functionSchema: FunctionSchema, position: number): void {\n const event = new CustomEvent<FunctionInsertEvent>('function-insert', {\n detail: { functionSchema, position },\n bubbles: true,\n })\n this.dispatchEvent(event)\n }\n\n /**\n * Dispatch suggestion insert event\n */\n private dispatchSuggestionInsert(suggestion: Suggestion, position: number): void {\n const event = new CustomEvent<SuggestionInsertEvent>('suggestion-insert', {\n detail: { suggestion, position },\n bubbles: true,\n })\n this.dispatchEvent(event)\n }\n\n /**\n * Focus the editor\n */\n override focus(): void {\n this.editorView?.focus()\n }\n\n /**\n * Get the editor's current selection\n */\n getSelection(): { from: number; to: number } | null {\n if (!this.editorView) return null\n const { from, to } = this.editorView.state.selection.main\n return { from, to }\n }\n\n /**\n * Insert text at the current cursor position\n */\n insertText(text: string): void {\n if (!this.editorView) return\n\n const { from, to } = this.editorView.state.selection.main\n this.editorView.dispatch({\n changes: { from, to, insert: text },\n selection: { anchor: from + text.length },\n })\n }\n\n override render(): TemplateResult {\n const hasLabel = !!this.label\n const hasSupportingText = !!this.supportingText\n\n return html`\n <div class=\"surface ${classMap({ 'has-focus': this.isEditorFocus, 'invalid': this.invalid })}\">\n <div class=\"content\">\n ${hasLabel ? html`<div class=\"label\">${this.label}</div>` : nothing}\n\n <div class=\"editor-container\" part=\"editor\"></div>\n </div>\n\n ${hasSupportingText ? html`<div class=\"supporting-text\">${this.supportingText}</div>` : noth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KAElG,CAAA;QACH,CAAC;;;AA7iBH;;;;;;;;;;;;;;GAcG;AACH","sourcesContent":["import { html, LitElement, PropertyValues, TemplateResult, nothing } from 'lit'\nimport { property, query, state } from 'lit/decorators.js'\nimport { classMap } from 'lit/directives/class-map.js'\nimport { linter } from '@codemirror/lint'\nimport { EditorState, Extension } from '@codemirror/state'\nimport {\n autocompletion,\n CompletionContext,\n type CompletionResult,\n type CompletionSource,\n type Completion,\n} from '@codemirror/autocomplete'\nimport { javascript } from '@codemirror/lang-javascript'\nimport { syntaxHighlighting, defaultHighlightStyle } from '@codemirror/language'\nimport { oneDark } from '@codemirror/theme-one-dark'\nimport { keymap } from '@codemirror/view'\nimport { defaultKeymap } from '@codemirror/commands'\nimport {\n EditorView,\n Decoration,\n DecorationSet,\n ViewPlugin,\n ViewUpdate,\n hoverTooltip,\n type Tooltip,\n} from '@codemirror/view'\nimport { functionLinter } from './Linter.js'\nimport type { FunctionInsertEvent, FunctionSchema, Suggestion, SuggestionInsertEvent } from './types.js'\nimport { SuggestionMatchDecorator } from './SuggestionMatchDecorator.js'\n\n/**\n * A CodeMirror 6 based editor component that supports function autocomplete and suggestion placeholders.\n *\n * Features:\n * - Dynamic function schema loading\n * - Autocomplete for functions and suggestions\n * - Suggestion placeholders with double curly braces ({{suggestion}})\n * - Keyboard navigation\n * - Accessibility support\n *\n * @fires function-insert - When a function is inserted\n * @fires suggestion-insert - When a suggestion is inserted\n * @fires input - When the editor content changes\n * @fires change - When the editor loses focus and content has changed\n */\nexport default class CodeEditor extends LitElement {\n /**\n * Shadow root configuration for the component.\n * Uses 'open' mode for accessibility and delegates focus to enable proper focus management.\n */\n static override shadowRootOptions: ShadowRootInit = {\n mode: 'open',\n delegatesFocus: true,\n }\n\n /**\n * The label text displayed as placeholder/floating label\n */\n @property({ type: String })\n accessor label = ''\n\n /**\n * Supporting text displayed below the editor\n */\n @property({ type: String, attribute: 'supporting-text' })\n accessor supportingText = ''\n\n /**\n * Whether the component is disabled\n */\n @property({ type: Boolean, reflect: true })\n accessor disabled = false\n\n /**\n * Whether the component is in an invalid state\n */\n @property({ type: Boolean, reflect: true })\n accessor invalid = false\n\n /**\n * The name attribute for form integration\n */\n @property({ type: String })\n accessor name = ''\n\n /**\n * Whether the input is required\n */\n @property({ type: Boolean })\n accessor required = false\n\n /**\n * Placeholder text shown when editor is empty\n */\n @property({ type: String })\n accessor placeholder = ''\n\n /**\n * The editor content value\n */\n @property({ type: String })\n accessor value = ''\n\n /**\n * Available function schemas for autocomplete\n */\n @property({ type: Array, attribute: false })\n accessor functionSchemas: FunctionSchema[] = []\n\n /**\n * Available suggestions for autocomplete\n */\n @property({ type: Array, attribute: false })\n accessor suggestions: Suggestion[] = []\n\n /**\n * Whether to use dark theme\n */\n @property({ type: Boolean, attribute: 'dark-theme' })\n accessor darkTheme = false\n\n /**\n * Programming language for syntax highlighting\n */\n @property({ type: String })\n accessor language = 'javascript'\n\n @query('.editor-container')\n private accessor editorContainer!: HTMLDivElement\n\n @state()\n private accessor hasContent = false\n\n @state()\n private accessor isEditorFocus = false\n\n private editorView?: EditorView\n private _previousValue = ''\n /**\n * Matcher for suggestion placeholders in the editor.\n */\n placeholderMatcher?: SuggestionMatchDecorator\n\n /**\n * Get all suggestions (placeholders) currently in the editor\n */\n get activeSuggestions(): Suggestion[] {\n const suggestions: Suggestion[] = []\n const placeholderPattern = /\\{\\{(\\w+)\\}\\}/g\n let match: RegExpExecArray | null\n while ((match = placeholderPattern.exec(this.value)) !== null) {\n const placeholderText = match[1]\n // Find suggestion by label\n const suggestion = this.suggestions.find((s) => s.label.toLowerCase() === placeholderText.toLowerCase())\n if (suggestion) {\n suggestions.push(suggestion)\n }\n }\n return suggestions\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback()\n this.editorView?.destroy()\n }\n\n override firstUpdated(): void {\n this.initializeCodeMirror()\n this.updateEditorContent()\n }\n\n override willUpdate(changedProperties: PropertyValues): void {\n super.willUpdate(changedProperties)\n\n if (changedProperties.has('suggestions')) {\n if (this.placeholderMatcher) {\n this.placeholderMatcher.suggestions = this.suggestions || []\n }\n }\n\n if (changedProperties.has('value') && this.editorView) {\n this.updateEditorContent()\n }\n\n if (changedProperties.has('disabled')) {\n this.updateEditorState()\n }\n }\n\n /**\n * Initialize CodeMirror editor with extensions\n */\n private initializeCodeMirror(): void {\n const extensions: Extension[] = [\n keymap.of(defaultKeymap),\n syntaxHighlighting(defaultHighlightStyle),\n autocompletion({\n override: [this.createCompletionSource()],\n activateOnTyping: true,\n maxRenderedOptions: 10,\n }),\n EditorView.updateListener.of((update: ViewUpdate) => {\n if (update.docChanged) {\n this.handleEditorChange()\n }\n if (update.focusChanged) {\n this.handleFocusChange(update.view.hasFocus)\n }\n }),\n this.createPlaceholderPlugin(),\n hoverTooltip(this.createHoverTooltipSource),\n linter((view) => functionLinter(view, this.functionSchemas, (e) => this.dispatchEvent(e))),\n ]\n\n // Add language support\n if (this.language === 'javascript') {\n extensions.push(javascript())\n }\n\n // Add theme\n if (this.darkTheme) {\n extensions.push(oneDark)\n }\n\n // Add placeholder\n if (this.placeholder) {\n extensions.push(\n EditorView.contentAttributes.of({\n 'aria-placeholder': this.placeholder,\n })\n )\n }\n\n const state = EditorState.create({\n doc: this.value,\n extensions,\n })\n\n this.editorView = new EditorView({\n state,\n parent: this.editorContainer,\n })\n }\n\n /**\n * Creates the ViewPlugin for rendering suggestion placeholders.\n * This is created as a method to get access to the component's `suggestions`.\n */\n private createPlaceholderPlugin(): Extension {\n const placeholderMatcher = new SuggestionMatchDecorator(/\\{\\{(\\w+)\\}\\}/g, this.suggestions)\n this.placeholderMatcher = placeholderMatcher\n // This class needs to be defined here to have access to the `placeholderMatcher`\n class AtomicDecorationRange {\n placeholders: DecorationSet\n constructor(view: EditorView) {\n this.placeholders = placeholderMatcher.createDeco(view)\n }\n update(update: ViewUpdate) {\n this.placeholders = placeholderMatcher.updateDeco(update, this.placeholders)\n }\n }\n\n return ViewPlugin.fromClass(AtomicDecorationRange, {\n decorations: (instance) => instance.placeholders,\n provide: (plugin) => EditorView.atomicRanges.of((view) => view.plugin(plugin)?.placeholders || Decoration.none),\n })\n }\n\n /**\n * Create completion source for functions and suggestions\n */\n private createCompletionSource(): CompletionSource {\n return (context: CompletionContext): CompletionResult | null => {\n const { pos } = context\n const line = context.state.doc.lineAt(pos)\n const textBefore = line.text.slice(0, pos - line.from)\n\n // Check if we're typing a function name\n const functionMatch = textBefore.match(/(\\w+)$/)\n if (functionMatch) {\n const prefix = functionMatch[1]\n const functions = this.functionSchemas\n .filter((fn) => fn.name.toLowerCase().startsWith(prefix.toLowerCase()))\n .map((fn) => this.createFunctionCompletion(fn))\n\n if (functions.length > 0) {\n return {\n from: pos - prefix.length,\n options: functions,\n }\n }\n }\n\n // Check if we're typing a suggestion trigger (e.g., {{)\n const suggestionMatch = textBefore.match(/\\{\\{(\\w*)$/)\n if (suggestionMatch) {\n const prefix = suggestionMatch[1]\n const suggestions = this.suggestions\n .filter((suggestion) => suggestion.label.toLowerCase().startsWith(prefix.toLowerCase()))\n .map((suggestion) => this.createSuggestionCompletion(suggestion))\n\n if (suggestions.length > 0) {\n return {\n from: pos - prefix.length,\n options: suggestions,\n }\n }\n }\n\n return null\n }\n }\n\n private createFunctionCompletion(schema: FunctionSchema): Completion {\n const result: Completion = {\n label: schema.name,\n detail: schema.description || '',\n info: () => this.createFunctionInfoElement(schema),\n apply: (view: EditorView, completion: unknown, from: number, to: number) => {\n const functionCall = this.formatFunctionCall(schema)\n view.dispatch({\n changes: { from, to, insert: functionCall },\n selection: { anchor: from + functionCall.length },\n })\n this.dispatchFunctionInsert(schema, from)\n },\n }\n\n return result\n }\n\n private createSuggestionCompletion(suggestion: Suggestion): Completion {\n const result: Completion = {\n label: suggestion.label,\n detail: suggestion.description || '',\n info: suggestion.suffix || '',\n apply: (view: EditorView, completion: unknown, from: number, to: number) => {\n const placeholderText = `{{${suggestion.label}}}`\n view.dispatch({\n changes: { from: from - 2, to, insert: placeholderText }, // -2 to include the {{\n selection: { anchor: from - 2 + placeholderText.length },\n })\n this.dispatchSuggestionInsert(suggestion, from - 2)\n },\n }\n\n return result\n }\n\n /**\n * Creates the source for the hover tooltips.\n * This is an arrow function to automatically bind `this`.\n */\n private createHoverTooltipSource = (view: EditorView, pos: number): Tooltip | null => {\n const word = view.state.wordAt(pos)\n if (!word) {\n return null\n }\n\n const functionName = view.state.doc.sliceString(word.from, word.to)\n const fnSchema = this.functionSchemas.find((schema) => schema.name === functionName)\n\n if (!fnSchema) {\n return null\n }\n\n return {\n pos: word.from,\n end: word.to,\n above: true,\n create: () => ({ dom: this.createFunctionInfoElement(fnSchema) }),\n }\n }\n\n /**\n * Creates a styled HTML element to display function documentation.\n * This is used for both hover tooltips and autocomplete info panels.\n */\n private createFunctionInfoElement(fn: FunctionSchema): HTMLElement {\n const container = document.createElement('div')\n container.className = 'function-info' // for styling\n\n if (fn.description) {\n const description = document.createElement('p')\n description.className = 'description'\n description.textContent = fn.description\n container.appendChild(description)\n }\n\n if (fn.parameters && fn.parameters.length > 0) {\n const paramsContainer = document.createElement('div')\n paramsContainer.className = 'parameters'\n\n const paramsHeader = document.createElement('h4')\n paramsHeader.textContent = 'Parameters'\n paramsContainer.appendChild(paramsHeader)\n\n const paramsList = document.createElement('ul')\n fn.parameters.forEach((param) => {\n const listItem = document.createElement('li')\n\n const name = document.createElement('span')\n name.className = 'param-name'\n name.textContent = param.name\n\n const type = document.createElement('span')\n type.className = 'param-type'\n type.textContent = `: ${param.type}`\n\n listItem.appendChild(name)\n listItem.appendChild(type)\n\n if (param.description) {\n const paramDesc = document.createElement('p')\n paramDesc.className = 'param-description'\n paramDesc.textContent = param.description\n listItem.appendChild(paramDesc)\n }\n paramsList.appendChild(listItem)\n })\n paramsContainer.appendChild(paramsList)\n container.appendChild(paramsContainer)\n }\n\n if (fn.returns) {\n const returnsContainer = document.createElement('div')\n returnsContainer.className = 'returns'\n\n const returnsHeader = document.createElement('h4')\n returnsHeader.textContent = 'Returns'\n returnsContainer.appendChild(returnsHeader)\n\n const returnsDesc = document.createElement('p')\n returnsDesc.textContent = fn.returns\n returnsContainer.appendChild(returnsDesc)\n container.appendChild(returnsContainer)\n }\n\n return container\n }\n\n /**\n * Format function call with parameters\n */\n private formatFunctionCall(fn: FunctionSchema): string {\n if (!fn.parameters || fn.parameters.length === 0) {\n return `${fn.name}()`\n }\n\n const params = fn.parameters\n .map((param) => {\n if (param.required) {\n return param.name\n }\n return `${param.name}?`\n })\n .join(', ')\n\n return `${fn.name}(${params})`\n }\n\n /**\n * Update editor content when value changes\n */\n private updateEditorContent(): void {\n if (!this.editorView) return\n\n const currentValue = this.editorView.state.doc.toString()\n if (currentValue !== this.value) {\n this.editorView.dispatch({\n changes: {\n from: 0,\n to: this.editorView.state.doc.length,\n insert: this.value,\n },\n })\n }\n }\n\n /**\n * Update editor state (e.g., disabled state)\n */\n private updateEditorState(): void {\n if (!this.editorView) return\n\n // For now, we'll handle disabled state differently\n // CodeMirror 6 doesn't use reconfigure for editable\n if (this.disabled) {\n this.editorView.contentDOM.setAttribute('contenteditable', 'false')\n } else {\n this.editorView.contentDOM.setAttribute('contenteditable', 'true')\n }\n }\n\n /**\n * Handle editor content change\n */\n private handleEditorChange(): void {\n if (!this.editorView) return\n\n const newValue = this.editorView.state.doc.toString()\n if (newValue !== this._previousValue) {\n this._previousValue = newValue\n this.value = newValue\n this.hasContent = newValue.length > 0\n\n this.dispatchEvent(new Event('input', { bubbles: true }))\n }\n }\n\n /**\n * Handle focus change\n */\n private handleFocusChange(hasFocus: boolean): void {\n this.isEditorFocus = hasFocus\n\n if (!hasFocus && this.value !== this._previousValue) {\n this.dispatchEvent(new Event('change', { bubbles: true }))\n }\n }\n\n /**\n * Dispatch function insert event\n */\n private dispatchFunctionInsert(functionSchema: FunctionSchema, position: number): void {\n const event = new CustomEvent<FunctionInsertEvent>('function-insert', {\n detail: { functionSchema, position },\n bubbles: true,\n })\n this.dispatchEvent(event)\n }\n\n /**\n * Dispatch suggestion insert event\n */\n private dispatchSuggestionInsert(suggestion: Suggestion, position: number): void {\n const event = new CustomEvent<SuggestionInsertEvent>('suggestion-insert', {\n detail: { suggestion, position },\n bubbles: true,\n })\n this.dispatchEvent(event)\n }\n\n /**\n * Focus the editor\n */\n override focus(): void {\n this.editorView?.focus()\n }\n\n /**\n * Get the editor's current selection\n */\n getSelection(): { from: number; to: number } | null {\n if (!this.editorView) return null\n const { from, to } = this.editorView.state.selection.main\n return { from, to }\n }\n\n /**\n * Insert text at the current cursor position\n */\n insertText(text: string): void {\n if (!this.editorView) return\n\n const { from, to } = this.editorView.state.selection.main\n this.editorView.dispatch({\n changes: { from, to, insert: text },\n selection: { anchor: from + text.length },\n })\n }\n\n override render(): TemplateResult {\n const hasLabel = !!this.label\n const hasSupportingText = !!this.supportingText\n\n return html`\n <div class=\"surface ${classMap({ 'has-focus': this.isEditorFocus, 'invalid': this.invalid })}\">\n <div class=\"content\">\n ${hasLabel ? html`<div class=\"label\">${this.label}</div>` : nothing}\n\n <div class=\"editor-container\" part=\"editor\"></div>\n </div>\n\n ${hasSupportingText ? html`<div class=\"supporting-text\">${this.supportingText}</div>` : nothing}\n </div>\n `\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeEditor.styles.d.ts","sourceRoot":"","sources":["../../../../../src/elements/code-editor/internals/CodeEditor.styles.ts"],"names":[],"mappings":";AAEA,
|
|
1
|
+
{"version":3,"file":"CodeEditor.styles.d.ts","sourceRoot":"","sources":["../../../../../src/elements/code-editor/internals/CodeEditor.styles.ts"],"names":[],"mappings":";AAEA,wBAuJC"}
|