@api-client/ui 0.5.12 → 0.5.14

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.
Files changed (44) hide show
  1. package/build/src/elements/code-editor/{ui-code-editor.d.ts → code-editor.d.ts} +3 -2
  2. package/build/src/elements/code-editor/code-editor.d.ts.map +1 -0
  3. package/build/src/elements/code-editor/{ui-code-editor.js → code-editor.js} +1 -1
  4. package/build/src/elements/code-editor/code-editor.js.map +1 -0
  5. package/build/src/elements/code-editor/internals/CodeEditor.d.ts +22 -59
  6. package/build/src/elements/code-editor/internals/CodeEditor.d.ts.map +1 -1
  7. package/build/src/elements/code-editor/internals/CodeEditor.js +139 -106
  8. package/build/src/elements/code-editor/internals/CodeEditor.js.map +1 -1
  9. package/build/src/elements/code-editor/internals/CodeEditor.styles.d.ts.map +1 -1
  10. package/build/src/elements/code-editor/internals/CodeEditor.styles.js +4 -0
  11. package/build/src/elements/code-editor/internals/CodeEditor.styles.js.map +1 -1
  12. package/build/src/elements/code-editor/internals/Linter.d.ts +2 -2
  13. package/build/src/elements/code-editor/internals/Linter.d.ts.map +1 -1
  14. package/build/src/elements/code-editor/internals/Linter.js +33 -37
  15. package/build/src/elements/code-editor/internals/Linter.js.map +1 -1
  16. package/build/src/elements/code-editor/internals/PlaceholderWidget.d.ts +20 -0
  17. package/build/src/elements/code-editor/internals/PlaceholderWidget.d.ts.map +1 -0
  18. package/build/src/elements/code-editor/internals/PlaceholderWidget.js +46 -0
  19. package/build/src/elements/code-editor/internals/PlaceholderWidget.js.map +1 -0
  20. package/build/src/elements/code-editor/internals/SuggestionMatchDecorator.d.ts +17 -0
  21. package/build/src/elements/code-editor/internals/SuggestionMatchDecorator.d.ts.map +1 -0
  22. package/build/src/elements/code-editor/internals/SuggestionMatchDecorator.js +31 -0
  23. package/build/src/elements/code-editor/internals/SuggestionMatchDecorator.js.map +1 -0
  24. package/build/src/elements/code-editor/internals/types.d.ts +26 -0
  25. package/build/src/elements/code-editor/internals/types.d.ts.map +1 -0
  26. package/build/src/elements/code-editor/internals/types.js +2 -0
  27. package/build/src/elements/code-editor/internals/types.js.map +1 -0
  28. package/build/src/index.d.ts +2 -2
  29. package/build/src/index.d.ts.map +1 -1
  30. package/build/src/index.js +1 -1
  31. package/build/src/index.js.map +1 -1
  32. package/demo/elements/code-editor/CodeEditorDemo.ts +19 -22
  33. package/package.json +3 -2
  34. package/src/elements/code-editor/README.md +1 -1
  35. package/src/elements/code-editor/{ui-code-editor.ts → code-editor.ts} +2 -7
  36. package/src/elements/code-editor/internals/CodeEditor.styles.ts +4 -0
  37. package/src/elements/code-editor/internals/CodeEditor.ts +170 -173
  38. package/src/elements/code-editor/internals/Linter.ts +38 -39
  39. package/src/elements/code-editor/internals/PlaceholderWidget.ts +50 -0
  40. package/src/elements/code-editor/internals/SuggestionMatchDecorator.ts +36 -0
  41. package/src/elements/code-editor/internals/types.ts +28 -0
  42. package/src/index.ts +2 -8
  43. package/build/src/elements/code-editor/ui-code-editor.d.ts.map +0 -1
  44. package/build/src/elements/code-editor/ui-code-editor.js.map +0 -1
@@ -9,5 +9,6 @@ declare global {
9
9
  }
10
10
  }
11
11
  export default CodeEditorElement;
12
- export type { FunctionSchema, FunctionParameter, Suggestion, FunctionInsertEvent, SuggestionInsertEvent, } from './internals/CodeEditor.js';
13
- //# sourceMappingURL=ui-code-editor.d.ts.map
12
+ export type { Suggestion, FunctionInsertEvent, SuggestionInsertEvent } from './internals/types.js';
13
+ export type { FunctionSchema, FunctionParameter } from '@pawel-up/jexl/schemas/types.js';
14
+ //# 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,EAAE,UAAU,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAClG,YAAY,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA"}
@@ -25,4 +25,4 @@ let CodeEditorElement = (() => {
25
25
  })();
26
26
  export { CodeEditorElement };
27
27
  export default CodeEditorElement;
28
- //# sourceMappingURL=ui-code-editor.js.map
28
+ //# sourceMappingURL=code-editor.js.map
@@ -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 { Suggestion, FunctionInsertEvent, SuggestionInsertEvent } from './internals/types.js'\nexport type { FunctionSchema, FunctionParameter } from '@pawel-up/jexl/schemas/types.js'\n"]}
@@ -1,54 +1,7 @@
1
1
  import { LitElement, PropertyValues, TemplateResult } from 'lit';
2
- export interface FunctionSchema {
3
- /** Unique identifier for the function */
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 } from '@pawel-up/jexl/schemas/types.js';
3
+ import type { Suggestion } from './types.js';
4
+ import { SuggestionMatchDecorator } from './SuggestionMatchDecorator.js';
52
5
  /**
53
6
  * A CodeMirror 6 based editor component that supports function autocomplete and suggestion placeholders.
54
7
  *
@@ -122,14 +75,15 @@ export default class CodeEditor extends LitElement {
122
75
  private accessor hasContent;
123
76
  private accessor isEditorFocus;
124
77
  private editorView?;
125
- private suggestionMap;
126
- private functionMap;
127
78
  private _previousValue;
79
+ /**
80
+ * Matcher for suggestion placeholders in the editor.
81
+ */
82
+ placeholderMatcher?: SuggestionMatchDecorator;
128
83
  /**
129
84
  * Get all suggestions (placeholders) currently in the editor
130
85
  */
131
86
  get activeSuggestions(): Suggestion[];
132
- connectedCallback(): void;
133
87
  disconnectedCallback(): void;
134
88
  firstUpdated(): void;
135
89
  willUpdate(changedProperties: PropertyValues): void;
@@ -137,22 +91,31 @@ export default class CodeEditor extends LitElement {
137
91
  * Initialize CodeMirror editor with extensions
138
92
  */
139
93
  private initializeCodeMirror;
94
+ /**
95
+ * Creates the ViewPlugin for rendering suggestion placeholders.
96
+ * This is created as a method to get access to the component's `suggestions`.
97
+ */
98
+ private createPlaceholderPlugin;
140
99
  /**
141
100
  * Create completion source for functions and suggestions
142
101
  */
143
102
  private createCompletionSource;
103
+ private createFunctionCompletion;
104
+ private createSuggestionCompletion;
144
105
  /**
145
- * Format function information for autocomplete
106
+ * Creates the source for the hover tooltips.
107
+ * This is an arrow function to automatically bind `this`.
146
108
  */
147
- private formatFunctionInfo;
109
+ private createHoverTooltipSource;
148
110
  /**
149
- * Format function call with parameters
111
+ * Creates a styled HTML element to display function documentation.
112
+ * This is used for both hover tooltips and autocomplete info panels.
150
113
  */
151
- private formatFunctionCall;
114
+ private createFunctionInfoElement;
152
115
  /**
153
- * Setup suggestion and function maps for quick lookup
116
+ * Format function call with parameters
154
117
  */
155
- private setupSuggestionMaps;
118
+ private formatFunctionCall;
156
119
  /**
157
120
  * Update editor content when value changes
158
121
  */
@@ -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;AAoB/E,MAAM,WAAW,cAAc;IAC7B,yCAAyC;IACzC,EAAE,EAAE,MAAM,CAAA;IACV,oBAAoB;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,2BAA2B;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,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,KAAK,IAAI,IAAI;IAItB;;OAEG;IACH,YAAY,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAMnD;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAUrB,MAAM,IAAI,cAAc;CAgBlC"}
@@ -2,59 +2,18 @@ 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, MatchDecorator, Decoration, ViewPlugin, WidgetType, } from '@codemirror/view';
13
- class PlaceholderWidget extends WidgetType {
14
- placeholderText;
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 { getTypeStringFromSchema } from '@pawel-up/jexl/schemas/utils.js';
15
+ import { functionLinter } from './Linter.js';
16
+ import { SuggestionMatchDecorator } from './SuggestionMatchDecorator.js';
58
17
  let CodeEditor = (() => {
59
18
  let _classSuper = LitElement;
60
19
  let _label_decorators;
@@ -271,9 +230,11 @@ let CodeEditor = (() => {
271
230
  get isEditorFocus() { return this.#isEditorFocus_accessor_storage; }
272
231
  set isEditorFocus(value) { this.#isEditorFocus_accessor_storage = value; }
273
232
  editorView = __runInitializers(this, _isEditorFocus_extraInitializers);
274
- suggestionMap = new Map();
275
- functionMap = new Map();
276
233
  _previousValue = '';
234
+ /**
235
+ * Matcher for suggestion placeholders in the editor.
236
+ */
237
+ placeholderMatcher;
277
238
  /**
278
239
  * Get all suggestions (placeholders) currently in the editor
279
240
  */
@@ -291,10 +252,6 @@ let CodeEditor = (() => {
291
252
  }
292
253
  return suggestions;
293
254
  }
294
- connectedCallback() {
295
- super.connectedCallback();
296
- this.setupSuggestionMaps();
297
- }
298
255
  disconnectedCallback() {
299
256
  super.disconnectedCallback();
300
257
  this.editorView?.destroy();
@@ -305,8 +262,10 @@ let CodeEditor = (() => {
305
262
  }
306
263
  willUpdate(changedProperties) {
307
264
  super.willUpdate(changedProperties);
308
- if (changedProperties.has('suggestions') || changedProperties.has('functionSchemas')) {
309
- this.setupSuggestionMaps();
265
+ if (changedProperties.has('suggestions')) {
266
+ if (this.placeholderMatcher) {
267
+ this.placeholderMatcher.suggestions = this.suggestions || [];
268
+ }
310
269
  }
311
270
  if (changedProperties.has('value') && this.editorView) {
312
271
  this.updateEditorContent();
@@ -335,8 +294,9 @@ let CodeEditor = (() => {
335
294
  this.handleFocusChange(update.view.hasFocus);
336
295
  }
337
296
  }),
338
- placeholders,
339
- // linter((view) => functionLinter(view as unknown as EditorView, this.functionSchemas)),
297
+ this.createPlaceholderPlugin(),
298
+ hoverTooltip(this.createHoverTooltipSource),
299
+ linter((view) => functionLinter(view, this.functionSchemas, (e) => this.dispatchEvent(e))),
340
300
  ];
341
301
  // Add language support
342
302
  if (this.language === 'javascript') {
@@ -361,6 +321,28 @@ let CodeEditor = (() => {
361
321
  parent: this.editorContainer,
362
322
  });
363
323
  }
324
+ /**
325
+ * Creates the ViewPlugin for rendering suggestion placeholders.
326
+ * This is created as a method to get access to the component's `suggestions`.
327
+ */
328
+ createPlaceholderPlugin() {
329
+ const placeholderMatcher = new SuggestionMatchDecorator(/\{\{(\w+)\}\}/g, this.suggestions);
330
+ this.placeholderMatcher = placeholderMatcher;
331
+ // This class needs to be defined here to have access to the `placeholderMatcher`
332
+ class AtomicDecorationRange {
333
+ placeholders;
334
+ constructor(view) {
335
+ this.placeholders = placeholderMatcher.createDeco(view);
336
+ }
337
+ update(update) {
338
+ this.placeholders = placeholderMatcher.updateDeco(update, this.placeholders);
339
+ }
340
+ }
341
+ return ViewPlugin.fromClass(AtomicDecorationRange, {
342
+ decorations: (instance) => instance.placeholders,
343
+ provide: (plugin) => EditorView.atomicRanges.of((view) => view.plugin(plugin)?.placeholders || Decoration.none),
344
+ });
345
+ }
364
346
  /**
365
347
  * Create completion source for functions and suggestions
366
348
  */
@@ -375,19 +357,7 @@ let CodeEditor = (() => {
375
357
  const prefix = functionMatch[1];
376
358
  const functions = this.functionSchemas
377
359
  .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
- }));
360
+ .map((fn) => this.createFunctionCompletion(fn));
391
361
  if (functions.length > 0) {
392
362
  return {
393
363
  from: pos - prefix.length,
@@ -401,19 +371,7 @@ let CodeEditor = (() => {
401
371
  const prefix = suggestionMatch[1];
402
372
  const suggestions = this.suggestions
403
373
  .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
- }));
374
+ .map((suggestion) => this.createSuggestionCompletion(suggestion));
417
375
  if (suggestions.length > 0) {
418
376
  return {
419
377
  from: pos - prefix.length,
@@ -424,25 +382,113 @@ let CodeEditor = (() => {
424
382
  return null;
425
383
  };
426
384
  }
385
+ createFunctionCompletion(schema) {
386
+ const result = {
387
+ label: schema.name,
388
+ detail: schema.description || '',
389
+ info: () => this.createFunctionInfoElement(schema),
390
+ apply: (view, completion, from, to) => {
391
+ const functionCall = this.formatFunctionCall(schema);
392
+ view.dispatch({
393
+ changes: { from, to, insert: functionCall },
394
+ selection: { anchor: from + functionCall.length },
395
+ });
396
+ this.dispatchFunctionInsert(schema, from);
397
+ },
398
+ };
399
+ return result;
400
+ }
401
+ createSuggestionCompletion(suggestion) {
402
+ const result = {
403
+ label: suggestion.label,
404
+ detail: suggestion.description || '',
405
+ info: suggestion.suffix || '',
406
+ apply: (view, completion, from, to) => {
407
+ const placeholderText = `{{${suggestion.label}}}`;
408
+ view.dispatch({
409
+ changes: { from: from - 2, to, insert: placeholderText }, // -2 to include the {{
410
+ selection: { anchor: from - 2 + placeholderText.length },
411
+ });
412
+ this.dispatchSuggestionInsert(suggestion, from - 2);
413
+ },
414
+ };
415
+ return result;
416
+ }
427
417
  /**
428
- * Format function information for autocomplete
418
+ * Creates the source for the hover tooltips.
419
+ * This is an arrow function to automatically bind `this`.
429
420
  */
430
- formatFunctionInfo(fn) {
431
- let info = fn.description || '';
421
+ createHoverTooltipSource = (view, pos) => {
422
+ const word = view.state.wordAt(pos);
423
+ if (!word) {
424
+ return null;
425
+ }
426
+ const functionName = view.state.doc.sliceString(word.from, word.to);
427
+ const fnSchema = this.functionSchemas.find((schema) => schema.name === functionName);
428
+ if (!fnSchema) {
429
+ return null;
430
+ }
431
+ return {
432
+ pos: word.from,
433
+ end: word.to,
434
+ above: true,
435
+ create: () => ({ dom: this.createFunctionInfoElement(fnSchema) }),
436
+ };
437
+ };
438
+ /**
439
+ * Creates a styled HTML element to display function documentation.
440
+ * This is used for both hover tooltips and autocomplete info panels.
441
+ */
442
+ createFunctionInfoElement(fn) {
443
+ const container = document.createElement('div');
444
+ container.className = 'function-info'; // for styling
445
+ if (fn.description) {
446
+ const description = document.createElement('p');
447
+ description.className = 'description';
448
+ description.textContent = fn.description;
449
+ container.appendChild(description);
450
+ }
432
451
  if (fn.parameters && fn.parameters.length > 0) {
433
- info += '\n\nParameters:\n';
452
+ const paramsContainer = document.createElement('div');
453
+ paramsContainer.className = 'parameters';
454
+ const paramsHeader = document.createElement('h4');
455
+ paramsHeader.textContent = 'Parameters';
456
+ paramsContainer.appendChild(paramsHeader);
457
+ const paramsList = document.createElement('ul');
434
458
  fn.parameters.forEach((param) => {
435
- info += `• ${param.name}: ${param.type}`;
436
- if (param.description) {
437
- info += ` - ${param.description}`;
459
+ const listItem = document.createElement('li');
460
+ const name = document.createElement('span');
461
+ name.className = 'param-name';
462
+ name.textContent = param.name;
463
+ const type = document.createElement('span');
464
+ type.className = 'param-type';
465
+ type.textContent = `: ${getTypeStringFromSchema(param.schema)}`;
466
+ listItem.appendChild(name);
467
+ listItem.appendChild(type);
468
+ if (param.schema.description) {
469
+ const paramDesc = document.createElement('p');
470
+ paramDesc.className = 'param-description';
471
+ paramDesc.textContent = param.schema.description;
472
+ listItem.appendChild(paramDesc);
438
473
  }
439
- info += '\n';
474
+ paramsList.appendChild(listItem);
440
475
  });
476
+ paramsContainer.appendChild(paramsList);
477
+ container.appendChild(paramsContainer);
441
478
  }
442
479
  if (fn.returns) {
443
- info += `\nReturns: ${fn.returns}`;
480
+ const returnsContainer = document.createElement('div');
481
+ returnsContainer.className = 'returns';
482
+ const returnsHeader = document.createElement('h4');
483
+ returnsHeader.textContent = 'Returns';
484
+ returnsContainer.appendChild(returnsHeader);
485
+ const returnsDesc = document.createElement('p');
486
+ const returnType = getTypeStringFromSchema(fn.returns);
487
+ returnsDesc.textContent = fn.returns.description ? `${returnType}: ${fn.returns.description}` : returnType;
488
+ returnsContainer.appendChild(returnsDesc);
489
+ container.appendChild(returnsContainer);
444
490
  }
445
- return info;
491
+ return container;
446
492
  }
447
493
  /**
448
494
  * Format function call with parameters
@@ -461,19 +507,6 @@ let CodeEditor = (() => {
461
507
  .join(', ');
462
508
  return `${fn.name}(${params})`;
463
509
  }
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
510
  /**
478
511
  * Update editor content when value changes
479
512
  */
@@ -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,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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>` : nothing}\n </div>\n `\n }\n}\n"]}
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,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,WAAW,EAAa,MAAM,mBAAmB,CAAA;AAC1D,OAAO,EACL,cAAc,GAKf,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AACxD,OAAO,EAAE,kBAAkB,EAA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D,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAA;QACrB,CAAC;QAED;;WAEG;QACH,UAAU,CAAC,IAAY;YACrB,IAAI,CAAC,IAAI,CAAC,UAAU;gBAAE,OAAM;YAE5B,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;;;AA9iBH;;;;;;;;;;;;;;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 type { FunctionSchema } from '@pawel-up/jexl/schemas/types.js'\nimport { getTypeStringFromSchema } from '@pawel-up/jexl/schemas/utils.js'\nimport { functionLinter } from './Linter.js'\nimport type { FunctionInsertEvent, 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 = `: ${getTypeStringFromSchema(param.schema)}`\n\n listItem.appendChild(name)\n listItem.appendChild(type)\n\n if (param.schema.description) {\n const paramDesc = document.createElement('p')\n paramDesc.className = 'param-description'\n paramDesc.textContent = param.schema.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 const returnType = getTypeStringFromSchema(fn.returns)\n returnsDesc.textContent = fn.returns.description ? `${returnType}: ${fn.returns.description}` : returnType\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"]}