@api-client/ui 0.5.11 → 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.
Files changed (49) hide show
  1. package/build/src/elements/code-editor/code-editor.d.ts +13 -0
  2. package/build/src/elements/code-editor/code-editor.d.ts.map +1 -0
  3. package/build/src/elements/code-editor/code-editor.js +28 -0
  4. package/build/src/elements/code-editor/code-editor.js.map +1 -0
  5. package/build/src/elements/code-editor/internals/CodeEditor.d.ts +159 -0
  6. package/build/src/elements/code-editor/internals/CodeEditor.d.ts.map +1 -0
  7. package/build/src/elements/code-editor/internals/CodeEditor.js +643 -0
  8. package/build/src/elements/code-editor/internals/CodeEditor.js.map +1 -0
  9. package/build/src/elements/code-editor/internals/CodeEditor.styles.d.ts +3 -0
  10. package/build/src/elements/code-editor/internals/CodeEditor.styles.d.ts.map +1 -0
  11. package/build/src/elements/code-editor/internals/CodeEditor.styles.js +154 -0
  12. package/build/src/elements/code-editor/internals/CodeEditor.styles.js.map +1 -0
  13. package/build/src/elements/code-editor/internals/Linter.d.ts +5 -0
  14. package/build/src/elements/code-editor/internals/Linter.d.ts.map +1 -0
  15. package/build/src/elements/code-editor/internals/Linter.js +69 -0
  16. package/build/src/elements/code-editor/internals/Linter.js.map +1 -0
  17. package/build/src/elements/code-editor/internals/PlaceholderWidget.d.ts +20 -0
  18. package/build/src/elements/code-editor/internals/PlaceholderWidget.d.ts.map +1 -0
  19. package/build/src/elements/code-editor/internals/PlaceholderWidget.js +46 -0
  20. package/build/src/elements/code-editor/internals/PlaceholderWidget.js.map +1 -0
  21. package/build/src/elements/code-editor/internals/SuggestionMatchDecorator.d.ts +17 -0
  22. package/build/src/elements/code-editor/internals/SuggestionMatchDecorator.d.ts.map +1 -0
  23. package/build/src/elements/code-editor/internals/SuggestionMatchDecorator.js +31 -0
  24. package/build/src/elements/code-editor/internals/SuggestionMatchDecorator.js.map +1 -0
  25. package/build/src/elements/code-editor/internals/types.d.ts +51 -0
  26. package/build/src/elements/code-editor/internals/types.d.ts.map +1 -0
  27. package/build/src/elements/code-editor/internals/types.js +2 -0
  28. package/build/src/elements/code-editor/internals/types.js.map +1 -0
  29. package/build/src/index.d.ts +2 -0
  30. package/build/src/index.d.ts.map +1 -1
  31. package/build/src/index.js +2 -0
  32. package/build/src/index.js.map +1 -1
  33. package/build/src/md/chip/internals/Chip.styles.d.ts.map +1 -1
  34. package/build/src/md/chip/internals/Chip.styles.js +1 -0
  35. package/build/src/md/chip/internals/Chip.styles.js.map +1 -1
  36. package/demo/elements/code-editor/CodeEditorDemo.ts +212 -0
  37. package/demo/elements/code-editor/index.html +19 -0
  38. package/demo/elements/index.html +3 -0
  39. package/package.json +10 -2
  40. package/src/elements/code-editor/README.md +204 -0
  41. package/src/elements/code-editor/code-editor.ts +24 -0
  42. package/src/elements/code-editor/internals/CodeEditor.styles.ts +154 -0
  43. package/src/elements/code-editor/internals/CodeEditor.ts +589 -0
  44. package/src/elements/code-editor/internals/Linter.ts +85 -0
  45. package/src/elements/code-editor/internals/PlaceholderWidget.ts +50 -0
  46. package/src/elements/code-editor/internals/SuggestionMatchDecorator.ts +36 -0
  47. package/src/elements/code-editor/internals/types.ts +54 -0
  48. package/src/index.ts +10 -0
  49. package/src/md/chip/internals/Chip.styles.ts +1 -0
@@ -0,0 +1,50 @@
1
+ import { EditorView, WidgetType } from '@codemirror/view'
2
+ import type { Suggestion } from './types.js'
3
+ import '../../../md/chip/ui-chip.js'
4
+
5
+ /**
6
+ * A widget that represents a placeholder in the code editor,
7
+ * specifically for suggestions that are replaced with chips.
8
+ *
9
+ * This widget is used to create a visual representation of a suggestion
10
+ * in the code editor, allowing users to see and interact with suggestions
11
+ * as chips. When a chip is removed, the corresponding text in the editor
12
+ * is also removed.
13
+ */
14
+ export class ChipWidget extends WidgetType {
15
+ constructor(public suggestion: Suggestion) {
16
+ super()
17
+ }
18
+
19
+ override eq(other: WidgetType): boolean {
20
+ return this.suggestion.id == (other as ChipWidget).suggestion.id
21
+ }
22
+
23
+ toDOM(view: EditorView): HTMLElement {
24
+ const wrapper = document.createElement('span')
25
+ wrapper.className = 'mention-chip'
26
+ wrapper.setAttribute('data-mention-id', this.suggestion.id)
27
+
28
+ const chip = document.createElement('ui-chip')
29
+ chip.setAttribute('type', 'input')
30
+ chip.setAttribute('removable', 'true')
31
+ chip.textContent = this.suggestion.label
32
+ chip.addEventListener('remove', () => {
33
+ const pos = view.posAtDOM(wrapper)
34
+ if (pos === null) return
35
+
36
+ const originalText = `{{${this.suggestion.label}}}`
37
+ view.dispatch({
38
+ changes: { from: pos, to: pos + originalText.length, insert: '' },
39
+ })
40
+ view.focus()
41
+ })
42
+
43
+ wrapper.appendChild(chip)
44
+ return wrapper
45
+ }
46
+
47
+ override ignoreEvent(): boolean {
48
+ return false
49
+ }
50
+ }
@@ -0,0 +1,36 @@
1
+ import { MatchDecorator, Decoration } from '@codemirror/view'
2
+ import type { Suggestion } from './types.js'
3
+ import { ChipWidget } from './PlaceholderWidget.js'
4
+
5
+ /**
6
+ * A class that specializes in creating and managing decorations for suggestion matches in a code editor.
7
+ */
8
+ export class SuggestionMatchDecorator extends MatchDecorator {
9
+ /**
10
+ * Creates a new instance of SuggestionMatchDecorator.
11
+ * @param regexp - The regular expression used to match suggestions in the code.
12
+ * @param suggestions - An array of suggestions that will be used to create decorations.
13
+ * Each suggestion should have a unique `id` and a `label` that will be displayed in the editor.
14
+ */
15
+ constructor(
16
+ regexp: RegExp,
17
+ public suggestions: Suggestion[]
18
+ ) {
19
+ super({
20
+ regexp,
21
+ decoration: (match) => this.#decoration(match),
22
+ })
23
+ }
24
+
25
+ #decoration(match: RegExpExecArray): Decoration {
26
+ const label = match[1]
27
+ const suggestion = this.suggestions.find((s) => s.label === label)
28
+
29
+ // If no suggestion is found, create a default one
30
+ const suggestionData: Suggestion = suggestion || { id: label, label }
31
+
32
+ return Decoration.replace({
33
+ widget: new ChipWidget(suggestionData),
34
+ })
35
+ }
36
+ }
@@ -0,0 +1,54 @@
1
+ export interface FunctionSchema {
2
+ /** Unique identifier for the function */
3
+ id: string
4
+ /** Function name */
5
+ name: string
6
+ /** Function description */
7
+ description?: string
8
+ /** Function parameters */
9
+ parameters?: FunctionParameter[]
10
+ /** Return type description */
11
+ returns?: string
12
+ /** Additional metadata */
13
+ metadata?: Record<string, unknown>
14
+ }
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
+
29
+ export interface Suggestion {
30
+ /** Unique identifier for the suggestion */
31
+ id: string
32
+ /** Main label displayed */
33
+ label: string
34
+ /** Supporting description text */
35
+ description?: string
36
+ /** Suffix text (e.g., type, category) */
37
+ suffix?: string
38
+ /** Additional data associated with the suggestion */
39
+ data?: Record<string, unknown>
40
+ }
41
+
42
+ export interface FunctionInsertEvent {
43
+ /** The inserted function schema */
44
+ functionSchema: FunctionSchema
45
+ /** The position where the function was inserted */
46
+ position: number
47
+ }
48
+
49
+ export interface SuggestionInsertEvent {
50
+ /** The inserted suggestion */
51
+ suggestion: Suggestion
52
+ /** The position where the suggestion was inserted */
53
+ position: number
54
+ }
package/src/index.ts CHANGED
@@ -4,6 +4,16 @@ export { default as MarkedHighlightElement } from './elements/highlight/MarkedHi
4
4
  export { default as PrismHighlightElement } from './elements/highlight/PrismHighlight.js'
5
5
  export { default as HarViewerElement } from './elements/har/HarViewer.js'
6
6
 
7
+ // Code Editor
8
+ export { default as CodeEditorElement } from './elements/code-editor/code-editor.js'
9
+ export type {
10
+ FunctionSchema,
11
+ FunctionParameter,
12
+ Suggestion,
13
+ FunctionInsertEvent,
14
+ SuggestionInsertEvent,
15
+ } from './elements/code-editor/code-editor.js'
16
+
7
17
  // Menu Components
8
18
  export { default as Menu } from './md/menu/internal/Menu.js'
9
19
  export { default as MenuItem } from './md/menu/internal/MenuItem.js'
@@ -34,6 +34,7 @@ export default css`
34
34
  --_icon-size: 18px;
35
35
 
36
36
  height: 32px;
37
+ box-sizing: border-box;
37
38
  border-radius: var(--md-sys-shape-corner-small);
38
39
  box-shadow: var(--_shadow);
39
40
  border: var(--_outline-size) solid var(--_outline-color);