@carbon/ai-chat-components 1.11.0 → 1.12.0-rc.1
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/custom-elements.json +2358 -1973
- package/es/components/card/src/card-footer.scss.js +1 -1
- package/es/components/card/src/card-steps.scss.js +1 -1
- package/es/components/card/src/card.scss.js +1 -1
- package/es/components/chat-button/src/chat-button.scss.js +1 -1
- package/es/components/chat-history/src/history-panel-item-input.js +0 -1
- package/es/components/chat-history/src/history-panel-item-input.js.map +1 -1
- package/es/components/code-snippet/src/codemirror/language-controller.js +1 -1
- package/es/components/code-snippet/src/codemirror/language-controller.js.map +1 -1
- package/es/components/file-uploads/src/file-upload-item.d.ts +14 -1
- package/es/components/file-uploads/src/file-upload-item.js +78 -2
- package/es/components/file-uploads/src/file-upload-item.js.map +1 -1
- package/es/components/file-uploads/src/file-uploads.d.ts +29 -4
- package/es/components/file-uploads/src/file-uploads.js +69 -16
- package/es/components/file-uploads/src/file-uploads.js.map +1 -1
- package/es/components/launcher/src/launcher.scss.js +1 -1
- package/es/components/prompt-line/autocomplete/index.d.ts +1 -1
- package/es/components/prompt-line/autocomplete/src/autocomplete.d.ts +6 -0
- package/es/components/prompt-line/autocomplete/src/autocomplete.js +37 -11
- package/es/components/prompt-line/autocomplete/src/autocomplete.js.map +1 -1
- package/es/components/prompt-line/index.d.ts +3 -2
- package/es/components/prompt-line/index.js +2 -1
- package/es/components/prompt-line/index.js.map +1 -1
- package/es/components/prompt-line/src/__tests__/wait-for-rich.d.ts +20 -0
- package/es/components/prompt-line/src/autocomplete-controller-element.d.ts +84 -0
- package/es/components/prompt-line/src/autocomplete-controller-element.js +262 -0
- package/es/components/prompt-line/src/autocomplete-controller-element.js.map +1 -0
- package/es/components/prompt-line/src/autocomplete-controller.d.ts +10 -69
- package/es/components/prompt-line/src/autocomplete-controller.js +57 -251
- package/es/components/prompt-line/src/autocomplete-controller.js.map +1 -1
- package/es/components/prompt-line/src/prompt-line-rich-runtime.js +3 -0
- package/es/components/prompt-line/src/prompt-line-rich-runtime.js.map +1 -1
- package/es/components/prompt-line/src/prompt-line-shell.scss.js +1 -1
- package/es/components/prompt-line/src/prompt-line-textarea-runtime.js +0 -5
- package/es/components/prompt-line/src/prompt-line-textarea-runtime.js.map +1 -1
- package/es/components/prompt-line/src/prompt-line.js +1 -1
- package/es/components/prompt-line/src/prompt-line.js.map +1 -1
- package/es/components/prompt-line/src/send-control.d.ts +7 -0
- package/es/components/prompt-line/src/send-control.js +53 -5
- package/es/components/prompt-line/src/send-control.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/build-extensions.js +1 -1
- package/es/components/prompt-line/src/tiptap/build-extensions.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/carbon-autocomplete.d.ts +5 -6
- package/es/components/prompt-line/src/tiptap/carbon-autocomplete.js +24 -48
- package/es/components/prompt-line/src/tiptap/carbon-autocomplete.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/carbon-mention.js +14 -48
- package/es/components/prompt-line/src/tiptap/carbon-mention.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/carbon-starter-trigger.js +3 -4
- package/es/components/prompt-line/src/tiptap/carbon-starter-trigger.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/keymap.d.ts +1 -1
- package/es/components/prompt-line/src/tiptap/keymap.js +3 -4
- package/es/components/prompt-line/src/tiptap/keymap.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/render-token-chip.js +0 -1
- package/es/components/prompt-line/src/tiptap/render-token-chip.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/resolve-config-items.d.ts +18 -0
- package/es/components/prompt-line/src/tiptap/resolve-config-items.js +32 -0
- package/es/components/prompt-line/src/tiptap/resolve-config-items.js.map +1 -0
- package/es/components/prompt-line/src/tiptap/strip-presentation-fields.d.ts +18 -0
- package/es/components/prompt-line/src/tiptap/strip-presentation-fields.js +22 -0
- package/es/components/prompt-line/src/tiptap/strip-presentation-fields.js.map +1 -0
- package/es/components/prompt-line/src/tiptap/trigger-utils.d.ts +12 -8
- package/es/components/prompt-line/src/tiptap/trigger-utils.js +16 -1
- package/es/components/prompt-line/src/tiptap/trigger-utils.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/types.d.ts +11 -3
- package/es/components/toolbar/src/toolbar.d.ts +8 -0
- package/es/components/toolbar/src/toolbar.js +65 -19
- package/es/components/toolbar/src/toolbar.js.map +1 -1
- package/es/components/video-player/src/providers/vimeo-provider.js +1 -1
- package/es/components/video-player/src/providers/vimeo-provider.js.map +1 -1
- package/es/globals/decorators/carbon-element.js +2 -3
- package/es/globals/decorators/carbon-element.js.map +1 -1
- package/es/globals/utils/aria-announcer-manager.d.ts +56 -0
- package/es/globals/utils/aria-announcer-manager.js +46 -1
- package/es/globals/utils/aria-announcer-manager.js.map +1 -1
- package/es/globals/utils/focus-utils.js +1 -3
- package/es/globals/utils/focus-utils.js.map +1 -1
- package/es/globals/utils/iconTransform.d.ts +16 -2
- package/es/globals/utils/iconTransform.js +22 -1
- package/es/globals/utils/iconTransform.js.map +1 -1
- package/es/react/hooks/useChatAutocomplete.d.ts +5 -0
- package/es/react/hooks/useChatAutocomplete.js +26 -1
- package/es/react/hooks/useChatAutocomplete.js.map +1 -1
- package/es/react/markdown.js +0 -1
- package/es/react/markdown.js.map +1 -1
- package/es/typings/overflow-menu.d.ts +4 -0
- package/es-custom/components/card/src/card-footer.scss.js +1 -1
- package/es-custom/components/card/src/card-steps.scss.js +1 -1
- package/es-custom/components/card/src/card.scss.js +1 -1
- package/es-custom/components/chat-button/src/chat-button.scss.js +1 -1
- package/es-custom/components/chat-history/src/history-panel-item-input.js +0 -1
- package/es-custom/components/chat-history/src/history-panel-item-input.js.map +1 -1
- package/es-custom/components/code-snippet/src/codemirror/language-controller.js +1 -1
- package/es-custom/components/code-snippet/src/codemirror/language-controller.js.map +1 -1
- package/es-custom/components/file-uploads/src/file-upload-item.d.ts +14 -1
- package/es-custom/components/file-uploads/src/file-upload-item.js +78 -2
- package/es-custom/components/file-uploads/src/file-upload-item.js.map +1 -1
- package/es-custom/components/file-uploads/src/file-uploads.d.ts +29 -4
- package/es-custom/components/file-uploads/src/file-uploads.js +69 -16
- package/es-custom/components/file-uploads/src/file-uploads.js.map +1 -1
- package/es-custom/components/launcher/src/launcher.scss.js +1 -1
- package/es-custom/components/prompt-line/autocomplete/index.d.ts +1 -1
- package/es-custom/components/prompt-line/autocomplete/src/autocomplete.d.ts +6 -0
- package/es-custom/components/prompt-line/autocomplete/src/autocomplete.js +37 -11
- package/es-custom/components/prompt-line/autocomplete/src/autocomplete.js.map +1 -1
- package/es-custom/components/prompt-line/index.d.ts +3 -2
- package/es-custom/components/prompt-line/index.js +2 -1
- package/es-custom/components/prompt-line/index.js.map +1 -1
- package/es-custom/components/prompt-line/src/__tests__/wait-for-rich.d.ts +20 -0
- package/es-custom/components/prompt-line/src/autocomplete-controller-element.d.ts +84 -0
- package/es-custom/components/prompt-line/src/autocomplete-controller-element.js +262 -0
- package/es-custom/components/prompt-line/src/autocomplete-controller-element.js.map +1 -0
- package/es-custom/components/prompt-line/src/autocomplete-controller.d.ts +10 -69
- package/es-custom/components/prompt-line/src/autocomplete-controller.js +57 -251
- package/es-custom/components/prompt-line/src/autocomplete-controller.js.map +1 -1
- package/es-custom/components/prompt-line/src/prompt-line-rich-runtime.js +3 -0
- package/es-custom/components/prompt-line/src/prompt-line-rich-runtime.js.map +1 -1
- package/es-custom/components/prompt-line/src/prompt-line-shell.scss.js +1 -1
- package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.js +0 -5
- package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.js.map +1 -1
- package/es-custom/components/prompt-line/src/prompt-line.js +1 -1
- package/es-custom/components/prompt-line/src/prompt-line.js.map +1 -1
- package/es-custom/components/prompt-line/src/send-control.d.ts +7 -0
- package/es-custom/components/prompt-line/src/send-control.js +53 -5
- package/es-custom/components/prompt-line/src/send-control.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/build-extensions.js +1 -1
- package/es-custom/components/prompt-line/src/tiptap/build-extensions.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/carbon-autocomplete.d.ts +5 -6
- package/es-custom/components/prompt-line/src/tiptap/carbon-autocomplete.js +24 -48
- package/es-custom/components/prompt-line/src/tiptap/carbon-autocomplete.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/carbon-mention.js +14 -48
- package/es-custom/components/prompt-line/src/tiptap/carbon-mention.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/carbon-starter-trigger.js +3 -4
- package/es-custom/components/prompt-line/src/tiptap/carbon-starter-trigger.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/keymap.d.ts +1 -1
- package/es-custom/components/prompt-line/src/tiptap/keymap.js +3 -4
- package/es-custom/components/prompt-line/src/tiptap/keymap.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/render-token-chip.js +0 -1
- package/es-custom/components/prompt-line/src/tiptap/render-token-chip.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/resolve-config-items.d.ts +18 -0
- package/es-custom/components/prompt-line/src/tiptap/resolve-config-items.js +32 -0
- package/es-custom/components/prompt-line/src/tiptap/resolve-config-items.js.map +1 -0
- package/es-custom/components/prompt-line/src/tiptap/strip-presentation-fields.d.ts +18 -0
- package/es-custom/components/prompt-line/src/tiptap/strip-presentation-fields.js +22 -0
- package/es-custom/components/prompt-line/src/tiptap/strip-presentation-fields.js.map +1 -0
- package/es-custom/components/prompt-line/src/tiptap/trigger-utils.d.ts +12 -8
- package/es-custom/components/prompt-line/src/tiptap/trigger-utils.js +16 -1
- package/es-custom/components/prompt-line/src/tiptap/trigger-utils.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/types.d.ts +11 -3
- package/es-custom/components/toolbar/src/toolbar.d.ts +8 -0
- package/es-custom/components/toolbar/src/toolbar.js +65 -19
- package/es-custom/components/toolbar/src/toolbar.js.map +1 -1
- package/es-custom/components/video-player/src/providers/vimeo-provider.js +1 -1
- package/es-custom/components/video-player/src/providers/vimeo-provider.js.map +1 -1
- package/es-custom/globals/decorators/carbon-element.js +2 -3
- package/es-custom/globals/decorators/carbon-element.js.map +1 -1
- package/es-custom/globals/utils/aria-announcer-manager.d.ts +56 -0
- package/es-custom/globals/utils/aria-announcer-manager.js +46 -1
- package/es-custom/globals/utils/aria-announcer-manager.js.map +1 -1
- package/es-custom/globals/utils/focus-utils.js +1 -3
- package/es-custom/globals/utils/focus-utils.js.map +1 -1
- package/es-custom/globals/utils/iconTransform.d.ts +16 -2
- package/es-custom/globals/utils/iconTransform.js +22 -1
- package/es-custom/globals/utils/iconTransform.js.map +1 -1
- package/es-custom/react/hooks/useChatAutocomplete.d.ts +5 -0
- package/es-custom/react/hooks/useChatAutocomplete.js +26 -1
- package/es-custom/react/hooks/useChatAutocomplete.js.map +1 -1
- package/es-custom/react/markdown.js +0 -1
- package/es-custom/react/markdown.js.map +1 -1
- package/es-custom/typings/overflow-menu.d.ts +4 -0
- package/package.json +6 -6
- package/scss/_custom-properties.scss +0 -17
- package/scss/_tokens-component.scss +1 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autocomplete-controller-element.js","sources":["../../../../src/components/prompt-line/src/autocomplete-controller-element.ts"],"sourcesContent":["/**\n * @license\n *\n * Copyright IBM Corp. 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport { html, LitElement, nothing } from 'lit';\nimport { property, state } from 'lit/decorators.js';\n\nimport { carbonElement } from '../../../globals/decorators/carbon-element.js';\nimport prefix from '../../../globals/settings.js';\n\nimport '../autocomplete/src/autocomplete.js';\nimport type { AutocompleteNavigatedEventDetail } from '../autocomplete/src/autocomplete.js';\nimport {\n AutocompleteController,\n itemsToGroups,\n type AutocompleteControllerState,\n} from './autocomplete-controller.js';\nimport type {\n AutocompleteConfig,\n StartersConfig,\n SuggestionItem,\n TriggerSuggestionConfig,\n} from './tiptap/types.js';\n\n/**\n * `<cds-custom-aichat-autocomplete-controller>` — drops the autocomplete overlay\n * lifecycle into a `<cds-custom-aichat-prompt-line-shell>`'s `autocomplete-content` slot.\n *\n * Listens for `cds-custom-aichat-trigger-change` events bubbling up from the\n * enclosing prompt-line-shell (the events are `composed: true, bubbles: true`, so\n * they reach here from inside the prompt-line's shadow root). Scoping the\n * listener to the shell — rather than `window` — keeps multiple\n * shell/controller pairs on the same page from cross-talking. Renders the\n * built-in `<cds-custom-aichat-autocomplete>` or the active config's\n * `renderCustomList` output. Selection routes back into the originating\n * prompt-line.\n *\n * @element cds-custom-aichat-autocomplete-controller\n * @fires cds-custom-aichat-starter-selected — `{ text: string }` after a starter is\n * inserted into the editor; consumer triggers send.\n * @fires cds-custom-aichat-autocomplete-item-selected — `{ item: SuggestionItem }`\n * after a suggestion item is selected. Fired in addition to type-specific callbacks.\n * @fires cds-custom-aichat-autocomplete-item-send — `{ text: string }` when the\n * per-item send button is clicked inside the suggestion list.\n * @fires cds-custom-aichat-list-navigated — `{ navigated: boolean }` when the user\n * starts or stops navigating the suggestion list with arrow keys. WC\n * consumers should use this to disable their send control while `navigated`\n * is `true` (the `listNavigated` getter reflects the same state).\n */\n@carbonElement(`${prefix}-autocomplete-controller`)\nclass AutocompleteControllerElement extends LitElement {\n /** `@`-style mention trigger config. */\n @property({ attribute: false })\n mention?: TriggerSuggestionConfig;\n\n /** `/`-style command trigger config. */\n @property({ attribute: false })\n command?: TriggerSuggestionConfig;\n\n /** Live-typeahead autocomplete config (no trigger character). */\n @property({ attribute: false })\n autocomplete?: AutocompleteConfig;\n\n /** Starter prompts shown when the editor is empty + focused + editable. */\n @property({ attribute: false })\n starters?: StartersConfig;\n\n /** When true, starter selection inserts text without firing the send event. */\n @property({ type: Boolean, attribute: 'is-send-disabled' })\n isSendDisabled = false;\n\n @state()\n private _state: AutocompleteControllerState = { trigger: null, items: [] };\n\n /**\n * Tracks whether the user is actively navigating inside the autocomplete\n * list. When `true`, the send button should be disabled so that Enter\n * confirms the highlighted item rather than submitting the prompt.\n */\n @state()\n private _listNavigated = false;\n\n /**\n * Returns `true` while the user is navigating inside the autocomplete list.\n * Consumers can use this to disable their send control.\n */\n get listNavigated(): boolean {\n return this._listNavigated;\n }\n\n private _controller: AutocompleteController | null = null;\n /**\n * Ancestor we subscribed `cds-custom-aichat-trigger-change` on. Scoping the\n * listener to the enclosing `<cds-custom-aichat-prompt-line-shell>` (rather than\n * `window`) keeps a second shell/controller pair on the same page from\n * receiving each other's events.\n */\n private _eventSource: EventTarget | null = null;\n\n // Render in light DOM so consumers' page-level CSS / portals can reach\n // any custom list element they've slotted in via renderCustomList.\n protected override createRenderRoot(): this {\n return this;\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.addEventListener('mousedown', this._handleMousedown);\n this.addEventListener(\n 'cds-custom-aichat-autocomplete-navigated',\n this._handleAutocompleteNavigated as EventListener\n );\n this._controller = new AutocompleteController({\n mention: this.mention,\n command: this.command,\n autocomplete: this.autocomplete,\n starters: this.starters,\n isSendDisabled: this.isSendDisabled,\n onStarterSelected: (text) => {\n this.dispatchEvent(\n new CustomEvent('cds-custom-aichat-starter-selected', {\n detail: { text },\n bubbles: true,\n composed: true,\n })\n );\n },\n onChange: (next) => {\n this._state = next;\n },\n });\n // Scope to the enclosing prompt-line-shell so multiple shell/controller pairs\n // on the same page don't cross-talk. Falls back to `this` if the\n // controller is used outside a shell — in that case the consumer\n // should make sure their prompt-line bubbles events into this element.\n this._eventSource = this.closest('cds-custom-aichat-prompt-line-shell') ?? this;\n this._eventSource.addEventListener(\n 'cds-custom-aichat-trigger-change',\n this._handleTriggerChange as EventListener\n );\n }\n\n override disconnectedCallback(): void {\n this.removeEventListener('mousedown', this._handleMousedown);\n this.removeEventListener(\n 'cds-custom-aichat-autocomplete-navigated',\n this._handleAutocompleteNavigated as EventListener\n );\n this._eventSource?.removeEventListener(\n 'cds-custom-aichat-trigger-change',\n this._handleTriggerChange as EventListener\n );\n this._eventSource = null;\n this._controller?.destroy();\n this._controller = null;\n super.disconnectedCallback();\n }\n\n override updated(changed: Map<string, unknown>): void {\n if (!this._controller) {\n return;\n }\n if (\n changed.has('mention') ||\n changed.has('command') ||\n changed.has('autocomplete') ||\n changed.has('starters') ||\n changed.has('isSendDisabled')\n ) {\n this._controller.setConfigs({\n mention: this.mention,\n command: this.command,\n autocomplete: this.autocomplete,\n starters: this.starters,\n isSendDisabled: this.isSendDisabled,\n });\n }\n // Register the currently-rendered list element with the controller so\n // arrow / Enter / Escape on the editor get forwarded into it.\n const listEl =\n this.querySelector<HTMLElement>('cds-custom-aichat-autocomplete') ??\n (this.firstElementChild instanceof HTMLElement\n ? this.firstElementChild\n : null);\n this._controller.setListElement(listEl);\n\n // Pass the editor DOM as anchorElement so the autocomplete's outside-click\n // guard treats clicks on the editor as inside-clicks (not dismissals).\n const editorDom = this._controller.getPromptLine()?.getEditor()?.view\n .dom as Element | undefined;\n const autocompleteEl = this.querySelector<\n HTMLElement & { anchorElement?: Element | null }\n >('cds-custom-aichat-autocomplete');\n if (autocompleteEl) {\n autocompleteEl.anchorElement = editorDom ?? null;\n }\n }\n\n override render() {\n const { trigger, items, renderCustomList, disableDirectSend } = this._state;\n if (!trigger || items.length === 0) {\n // List is gone — reset navigation state so the send button is unblocked.\n // This covers cases where the list is removed without an autocomplete\n // dismiss/select/send event (e.g. the user deletes the trigger character).\n if (this._listNavigated) {\n this._listNavigated = false;\n this.dispatchEvent(\n new CustomEvent<AutocompleteNavigatedEventDetail>(\n 'cds-custom-aichat-list-navigated',\n { detail: { navigated: false }, bubbles: true, composed: true }\n )\n );\n // Also fire the lower-level event so send-control's shell listener fires.\n this.dispatchEvent(\n new CustomEvent<AutocompleteNavigatedEventDetail>(\n 'cds-custom-aichat-autocomplete-navigated',\n { detail: { navigated: false }, bubbles: true, composed: true }\n )\n );\n }\n return nothing;\n }\n if (renderCustomList) {\n const result = renderCustomList({\n items,\n query: trigger.query,\n onDismiss: () => this._controller?.dismiss(),\n onSelect: (item) => this._selectItem(item),\n onSend: (text) => this._sendItem(text),\n });\n if (result instanceof HTMLElement) {\n return html`${result}`;\n }\n // Custom renderer returned something other than an HTMLElement (e.g.\n // a React node). Surface it on a side-channel event so React adapters\n // can portal it into place themselves.\n this.dispatchEvent(\n new CustomEvent('cds-custom-aichat-custom-list-render', {\n detail: { reactNode: result },\n bubbles: true,\n composed: true,\n })\n );\n return nothing;\n }\n const { items: flatItems, groups } = itemsToGroups(items);\n return html`\n <cds-custom-aichat-autocomplete\n .items=${flatItems}\n .groups=${groups}\n .disableDirectSend=${disableDirectSend}\n @cds-custom-aichat-autocomplete-select=${(\n e: CustomEvent<{ item: SuggestionItem }>\n ) => this._selectItem(e.detail.item)}\n @cds-custom-aichat-autocomplete-send=${(e: CustomEvent<{ text: string }>) =>\n this._sendItem(e.detail.text)}\n @cds-custom-aichat-autocomplete-dismiss=${() => this._controller?.dismiss()}></cds-custom-aichat-autocomplete>\n `;\n }\n\n private _selectItem(item: SuggestionItem): void {\n this._controller?.select(item);\n this.dispatchEvent(\n new CustomEvent('cds-custom-aichat-autocomplete-item-selected', {\n detail: { item },\n bubbles: true,\n composed: true,\n })\n );\n }\n\n private _sendItem(text: string): void {\n if (this.isSendDisabled) {\n return;\n }\n this._controller?.dismiss(true);\n this.dispatchEvent(\n new CustomEvent('cds-custom-aichat-autocomplete-item-send', {\n detail: { text },\n bubbles: true,\n composed: true,\n })\n );\n }\n\n private _handleMousedown = (event: MouseEvent): void => {\n // Prevent the autocomplete list from stealing focus from the editor.\n event.preventDefault();\n };\n\n private _handleAutocompleteNavigated = (event: Event): void => {\n const { navigated } = (\n event as CustomEvent<AutocompleteNavigatedEventDetail>\n ).detail;\n if (this._listNavigated === navigated) {\n return;\n }\n this._listNavigated = navigated;\n // Re-fire a composed event so parent elements (e.g. a WC integration shell)\n // can disable their send control while the user navigates the list.\n this.dispatchEvent(\n new CustomEvent<AutocompleteNavigatedEventDetail>(\n 'cds-custom-aichat-list-navigated',\n { detail: { navigated }, bubbles: true, composed: true }\n )\n );\n };\n\n private _handleTriggerChange = (event: Event): void => {\n this._controller?.handleTriggerChangeEvent(\n event as CustomEvent<\n Parameters<AutocompleteController['handleTriggerChange']>[0]\n >\n );\n };\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'cds-custom-aichat-autocomplete-controller': AutocompleteControllerElement;\n }\n}\n\nexport default AutocompleteControllerElement;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;AAOG;AAsBH;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;AAEH,IAAM,6BAA6B,GAAnC,MAAM,6BAA8B,SAAQ,UAAU,CAAA;AAAtD,IAAA,WAAA,GAAA;;;QAmBE,IAAA,CAAA,cAAc,GAAG,KAAK;QAGd,IAAA,CAAA,MAAM,GAAgC,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE;AAE1E;;;;AAIG;QAEK,IAAA,CAAA,cAAc,GAAG,KAAK;QAUtB,IAAA,CAAA,WAAW,GAAkC,IAAI;AACzD;;;;;AAKG;QACK,IAAA,CAAA,YAAY,GAAuB,IAAI;AA4LvC,QAAA,IAAA,CAAA,gBAAgB,GAAG,CAAC,KAAiB,KAAU;;YAErD,KAAK,CAAC,cAAc,EAAE;AACxB,QAAA,CAAC;AAEO,QAAA,IAAA,CAAA,4BAA4B,GAAG,CAAC,KAAY,KAAU;AAC5D,YAAA,MAAM,EAAE,SAAS,EAAE,GACjB,KACD,CAAC,MAAM;AACR,YAAA,IAAI,IAAI,CAAC,cAAc,KAAK,SAAS,EAAE;gBACrC;YACF;AACA,YAAA,IAAI,CAAC,cAAc,GAAG,SAAS;;;YAG/B,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CACb,2BAA2B,EAC3B,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CACzD,CACF;A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AA,UAAA,CAAA;AADlC,IAAA,aAAa,CAAC,CAAA,EAAG,MAAM,CAAA,wBAAA,CAA0B;AAC5C,CAAA,EAAA,6BAA6B,CAyQlC;AAQD,4CAAe,6BAA6B;;"}
|
|
@@ -6,20 +6,8 @@
|
|
|
6
6
|
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
|
8
8
|
*/
|
|
9
|
-
import { LitElement, nothing } from 'lit';
|
|
10
|
-
import '../autocomplete/src/autocomplete.js';
|
|
11
9
|
import type PromptLineElement from './prompt-line.js';
|
|
12
10
|
import type { AutocompleteConfig, CustomListProps, StartersConfig, SuggestionItem, SuggestionItemGroup, TriggerChangeEventDetail, TriggerSuggestionConfig } from './tiptap/types.js';
|
|
13
|
-
/**
|
|
14
|
-
* Framework-agnostic controller for the chat-input autocomplete overlay:
|
|
15
|
-
* trigger-state tracking, async item resolution with stale-result protection,
|
|
16
|
-
* dismissal, and selection routing back through the editor (mention/command
|
|
17
|
-
* chip insertion, plain-text autocomplete, starter insert-and-send).
|
|
18
|
-
*
|
|
19
|
-
* Wrapped by [../../../react/hooks/useChatAutocomplete.tsx] (React hook) and
|
|
20
|
-
* by the `<cds-custom-aichat-autocomplete-controller>` element below — same logic,
|
|
21
|
-
* two surfaces.
|
|
22
|
-
*/
|
|
23
11
|
export interface AutocompleteControllerOptions {
|
|
24
12
|
mention?: TriggerSuggestionConfig;
|
|
25
13
|
command?: TriggerSuggestionConfig;
|
|
@@ -132,6 +120,16 @@ export declare class AutocompleteController {
|
|
|
132
120
|
private _handleEditorKeyDown;
|
|
133
121
|
private _handleEditorFocusOut;
|
|
134
122
|
private _kickoffResolve;
|
|
123
|
+
/**
|
|
124
|
+
* The config backing a trigger type, or `undefined` for a type no config
|
|
125
|
+
* covers. Single lookup for the class: a new trigger type is one case here,
|
|
126
|
+
* not a hunt through every method that names the types.
|
|
127
|
+
*
|
|
128
|
+
* Callers reach the fields every config shares. The `mention`/`command`
|
|
129
|
+
* overload returns the narrower type, which is what `select()` needs to read
|
|
130
|
+
* `trigger` — a field `BaseSuggestionConfig` does not carry.
|
|
131
|
+
*/
|
|
132
|
+
private _configForTrigger;
|
|
135
133
|
private _resolveItems;
|
|
136
134
|
private _resolveRenderCustomList;
|
|
137
135
|
private _resolveDisableDirectSend;
|
|
@@ -148,60 +146,3 @@ export declare function itemsToGroups(flat: SuggestionItem[]): {
|
|
|
148
146
|
items: SuggestionItem[];
|
|
149
147
|
groups: SuggestionItemGroup[];
|
|
150
148
|
};
|
|
151
|
-
/**
|
|
152
|
-
* `<cds-custom-aichat-autocomplete-controller>` — drops the autocomplete overlay
|
|
153
|
-
* lifecycle into a `<cds-custom-aichat-prompt-line-shell>`'s `autocomplete-content` slot.
|
|
154
|
-
*
|
|
155
|
-
* Listens for `cds-custom-aichat-trigger-change` events bubbling up from the
|
|
156
|
-
* enclosing prompt-line-shell (the events are `composed: true, bubbles: true`, so
|
|
157
|
-
* they reach here from inside the prompt-line's shadow root). Scoping the
|
|
158
|
-
* listener to the shell — rather than `window` — keeps multiple
|
|
159
|
-
* shell/controller pairs on the same page from cross-talking. Renders the
|
|
160
|
-
* built-in `<cds-custom-aichat-autocomplete>` or the active config's
|
|
161
|
-
* `renderCustomList` output. Selection routes back into the originating
|
|
162
|
-
* prompt-line.
|
|
163
|
-
*
|
|
164
|
-
* @element cds-custom-aichat-autocomplete-controller
|
|
165
|
-
* @fires cds-custom-aichat-starter-selected — `{ text: string }` after a starter is
|
|
166
|
-
* inserted into the editor; consumer triggers send.
|
|
167
|
-
* @fires cds-custom-aichat-autocomplete-item-selected — `{ item: SuggestionItem }`
|
|
168
|
-
* after a suggestion item is selected. Fired in addition to type-specific callbacks.
|
|
169
|
-
* @fires cds-custom-aichat-autocomplete-item-send — `{ text: string }` when the
|
|
170
|
-
* per-item send button is clicked inside the suggestion list.
|
|
171
|
-
*/
|
|
172
|
-
declare class AutocompleteControllerElement extends LitElement {
|
|
173
|
-
/** `@`-style mention trigger config. */
|
|
174
|
-
mention?: TriggerSuggestionConfig;
|
|
175
|
-
/** `/`-style command trigger config. */
|
|
176
|
-
command?: TriggerSuggestionConfig;
|
|
177
|
-
/** Live-typeahead autocomplete config (no trigger character). */
|
|
178
|
-
autocomplete?: AutocompleteConfig;
|
|
179
|
-
/** Starter prompts shown when the editor is empty + focused + editable. */
|
|
180
|
-
starters?: StartersConfig;
|
|
181
|
-
/** When true, starter selection inserts text without firing the send event. */
|
|
182
|
-
isSendDisabled: boolean;
|
|
183
|
-
private _state;
|
|
184
|
-
private _controller;
|
|
185
|
-
/**
|
|
186
|
-
* Ancestor we subscribed `cds-custom-aichat-trigger-change` on. Scoping the
|
|
187
|
-
* listener to the enclosing `<cds-custom-aichat-prompt-line-shell>` (rather than
|
|
188
|
-
* `window`) keeps a second shell/controller pair on the same page from
|
|
189
|
-
* receiving each other's events.
|
|
190
|
-
*/
|
|
191
|
-
private _eventSource;
|
|
192
|
-
protected createRenderRoot(): this;
|
|
193
|
-
connectedCallback(): void;
|
|
194
|
-
disconnectedCallback(): void;
|
|
195
|
-
updated(changed: Map<string, unknown>): void;
|
|
196
|
-
render(): import("lit-html").TemplateResult<1> | typeof nothing;
|
|
197
|
-
private _selectItem;
|
|
198
|
-
private _sendItem;
|
|
199
|
-
private _handleMousedown;
|
|
200
|
-
private _handleTriggerChange;
|
|
201
|
-
}
|
|
202
|
-
declare global {
|
|
203
|
-
interface HTMLElementTagNameMap {
|
|
204
|
-
'cds-custom-aichat-autocomplete-controller': AutocompleteControllerElement;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
export default AutocompleteControllerElement;
|
|
@@ -5,14 +5,10 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { __decorate } from 'tslib';
|
|
9
|
-
import { LitElement, nothing, html } from 'lit';
|
|
10
|
-
import { property, state } from 'lit/decorators.js';
|
|
11
|
-
import { carbonElement } from '../../../globals/decorators/carbon-element.js';
|
|
12
|
-
import prefix from '../../../globals/settings.js';
|
|
13
|
-
import '../autocomplete/src/autocomplete.js';
|
|
14
8
|
import { writeStarterStorage } from './tiptap/carbon-starter-trigger.js';
|
|
15
9
|
import { resolveShowTriggerInChip } from './tiptap/carbon-mention.js';
|
|
10
|
+
import { stripPresentationFields } from './tiptap/strip-presentation-fields.js';
|
|
11
|
+
import { resolveConfigItems } from './tiptap/resolve-config-items.js';
|
|
16
12
|
import { projectRawValue } from './tiptap/json-utils.js';
|
|
17
13
|
import { resetTriggerChangeState } from './tiptap/trigger-utils.js';
|
|
18
14
|
|
|
@@ -24,6 +20,25 @@ import { resetTriggerChangeState } from './tiptap/trigger-utils.js';
|
|
|
24
20
|
* This source code is licensed under the Apache-2.0 license found in the
|
|
25
21
|
* LICENSE file in the root directory of this source tree.
|
|
26
22
|
*/
|
|
23
|
+
/**
|
|
24
|
+
* Framework-agnostic controller for the chat-input autocomplete overlay:
|
|
25
|
+
* trigger-state tracking, async item resolution with stale-result protection,
|
|
26
|
+
* dismissal, and selection routing back through the editor (mention/command
|
|
27
|
+
* chip insertion, plain-text autocomplete, starter insert-and-send).
|
|
28
|
+
*
|
|
29
|
+
* Wrapped by [../../../react/hooks/useChatAutocomplete.tsx] (React hook) and
|
|
30
|
+
* by the `<cds-custom-aichat-autocomplete-controller>` element in
|
|
31
|
+
* [./autocomplete-controller-element.ts] — same logic, two surfaces.
|
|
32
|
+
*
|
|
33
|
+
* This module stays free of `lit` and of custom-element registration. The
|
|
34
|
+
* React hook imports the controller directly, so a Lit import here would hand
|
|
35
|
+
* every React consumer a runtime and an element it never renders. A static
|
|
36
|
+
* import check in [../../../react/__tests__/autocomplete-controller-imports.test.ts]
|
|
37
|
+
* fails if either comes back.
|
|
38
|
+
*/
|
|
39
|
+
function isNavigableListElement(el) {
|
|
40
|
+
return typeof el.hasNavigated === 'function';
|
|
41
|
+
}
|
|
27
42
|
class AutocompleteController {
|
|
28
43
|
constructor(options) {
|
|
29
44
|
this._trigger = null;
|
|
@@ -57,6 +72,7 @@ class AutocompleteController {
|
|
|
57
72
|
this._handleEditorKeyDown = (event) => {
|
|
58
73
|
if (event.key !== 'ArrowUp' &&
|
|
59
74
|
event.key !== 'ArrowDown' &&
|
|
75
|
+
event.key !== 'Tab' &&
|
|
60
76
|
event.key !== 'Enter' &&
|
|
61
77
|
event.key !== 'Escape') {
|
|
62
78
|
return;
|
|
@@ -65,6 +81,15 @@ class AutocompleteController {
|
|
|
65
81
|
if (!listEl || !this._trigger) {
|
|
66
82
|
return;
|
|
67
83
|
}
|
|
84
|
+
if (event.key === 'Enter') {
|
|
85
|
+
const navigated = isNavigableListElement(listEl)
|
|
86
|
+
? listEl.hasNavigated()
|
|
87
|
+
: true;
|
|
88
|
+
if (!navigated) {
|
|
89
|
+
this.dismiss();
|
|
90
|
+
return; // let carbonChatEnter send the typed text
|
|
91
|
+
}
|
|
92
|
+
}
|
|
68
93
|
// Stop Tiptap and the editor from acting on the same key. `capture: true`
|
|
69
94
|
// (when listening) plus stopPropagation here gets us in ahead of
|
|
70
95
|
// ProseMirror's own keydown handler.
|
|
@@ -256,7 +281,7 @@ class AutocompleteController {
|
|
|
256
281
|
return;
|
|
257
282
|
}
|
|
258
283
|
if (trigger.type === 'mention' || trigger.type === 'command') {
|
|
259
|
-
const config = trigger.type
|
|
284
|
+
const config = this._configForTrigger(trigger.type);
|
|
260
285
|
const nodeName = trigger.type;
|
|
261
286
|
const range = {
|
|
262
287
|
from: trigger.triggerOffset,
|
|
@@ -275,6 +300,7 @@ class AutocompleteController {
|
|
|
275
300
|
trigger: resolveShowTriggerInChip(item, config ?? {}, trigger.type === 'command')
|
|
276
301
|
? config?.trigger
|
|
277
302
|
: null,
|
|
303
|
+
data: stripPresentationFields(item),
|
|
278
304
|
},
|
|
279
305
|
},
|
|
280
306
|
{ type: 'text', text: ' ' },
|
|
@@ -357,17 +383,27 @@ class AutocompleteController {
|
|
|
357
383
|
this._emit();
|
|
358
384
|
})();
|
|
359
385
|
}
|
|
386
|
+
_configForTrigger(type) {
|
|
387
|
+
switch (type) {
|
|
388
|
+
case 'starter':
|
|
389
|
+
return this._starters;
|
|
390
|
+
case 'mention':
|
|
391
|
+
return this._mention;
|
|
392
|
+
case 'command':
|
|
393
|
+
return this._command;
|
|
394
|
+
case 'autocomplete':
|
|
395
|
+
return this._autocomplete;
|
|
396
|
+
default:
|
|
397
|
+
return undefined;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
360
400
|
async _resolveItems(trigger) {
|
|
401
|
+
// Starters are a fixed list shown on an empty editor, so they skip the
|
|
402
|
+
// query gating and filtering every other trigger runs through.
|
|
361
403
|
if (trigger.type === 'starter') {
|
|
362
404
|
return this._starters?.items ?? [];
|
|
363
405
|
}
|
|
364
|
-
const config = trigger.type
|
|
365
|
-
? this._mention
|
|
366
|
-
: trigger.type === 'command'
|
|
367
|
-
? this._command
|
|
368
|
-
: trigger.type === 'autocomplete'
|
|
369
|
-
? this._autocomplete
|
|
370
|
-
: undefined;
|
|
406
|
+
const config = this._configForTrigger(trigger.type);
|
|
371
407
|
if (!config) {
|
|
372
408
|
return [];
|
|
373
409
|
}
|
|
@@ -378,33 +414,19 @@ class AutocompleteController {
|
|
|
378
414
|
if (!trigger) {
|
|
379
415
|
return undefined;
|
|
380
416
|
}
|
|
381
|
-
|
|
382
|
-
return this._starters?.renderCustomList;
|
|
383
|
-
}
|
|
384
|
-
const config = trigger.type === 'mention'
|
|
385
|
-
? this._mention
|
|
386
|
-
: trigger.type === 'command'
|
|
387
|
-
? this._command
|
|
388
|
-
: trigger.type === 'autocomplete'
|
|
389
|
-
? this._autocomplete
|
|
390
|
-
: undefined;
|
|
391
|
-
return config?.renderCustomList;
|
|
417
|
+
return this._configForTrigger(trigger.type)?.renderCustomList;
|
|
392
418
|
}
|
|
393
419
|
_resolveDisableDirectSend() {
|
|
394
420
|
const trigger = this._trigger;
|
|
395
421
|
if (!trigger) {
|
|
396
422
|
return undefined;
|
|
397
423
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
return true;
|
|
403
|
-
case 'command':
|
|
404
|
-
return true;
|
|
405
|
-
default:
|
|
406
|
-
return this._autocomplete?.disableDirectSend;
|
|
424
|
+
// Mention and command always insert a chip rather than send, which is why
|
|
425
|
+
// TriggerSuggestionConfig omits the field rather than defaulting it.
|
|
426
|
+
if (trigger.type === 'mention' || trigger.type === 'command') {
|
|
427
|
+
return true;
|
|
407
428
|
}
|
|
429
|
+
return this._configForTrigger(trigger.type)?.disableDirectSend;
|
|
408
430
|
}
|
|
409
431
|
_emit() {
|
|
410
432
|
this._onChange({
|
|
@@ -428,24 +450,6 @@ function findPromptLineFromTarget(path) {
|
|
|
428
450
|
}
|
|
429
451
|
return null;
|
|
430
452
|
}
|
|
431
|
-
/**
|
|
432
|
-
* Resolve a `BaseSuggestionConfig`'s `items` field (array or async resolver)
|
|
433
|
-
* to a flat list, applying `minQueryLength` filtering.
|
|
434
|
-
*/
|
|
435
|
-
async function resolveConfigItems(config, query) {
|
|
436
|
-
const minQueryLength = config.minQueryLength ?? 0;
|
|
437
|
-
if (query.length < minQueryLength) {
|
|
438
|
-
return [];
|
|
439
|
-
}
|
|
440
|
-
if (typeof config.items === 'function') {
|
|
441
|
-
return await Promise.resolve(config.items(query));
|
|
442
|
-
}
|
|
443
|
-
if (!query) {
|
|
444
|
-
return config.items;
|
|
445
|
-
}
|
|
446
|
-
const lower = query.toLowerCase();
|
|
447
|
-
return config.items.filter((item) => item.label.toLowerCase().includes(lower));
|
|
448
|
-
}
|
|
449
453
|
/**
|
|
450
454
|
* Partition a flat `SuggestionItem[]` into ungrouped items and derived
|
|
451
455
|
* `SuggestionItemGroup[]` for the `<cds-custom-aichat-autocomplete>` element.
|
|
@@ -481,204 +485,6 @@ function itemsToGroups(flat) {
|
|
|
481
485
|
.filter((g) => g !== undefined),
|
|
482
486
|
};
|
|
483
487
|
}
|
|
484
|
-
// ---------------------------------------------------------------------------
|
|
485
|
-
// <cds-custom-aichat-autocomplete-controller> — Lit element wrapping the class
|
|
486
|
-
// ---------------------------------------------------------------------------
|
|
487
|
-
/**
|
|
488
|
-
* `<cds-custom-aichat-autocomplete-controller>` — drops the autocomplete overlay
|
|
489
|
-
* lifecycle into a `<cds-custom-aichat-prompt-line-shell>`'s `autocomplete-content` slot.
|
|
490
|
-
*
|
|
491
|
-
* Listens for `cds-custom-aichat-trigger-change` events bubbling up from the
|
|
492
|
-
* enclosing prompt-line-shell (the events are `composed: true, bubbles: true`, so
|
|
493
|
-
* they reach here from inside the prompt-line's shadow root). Scoping the
|
|
494
|
-
* listener to the shell — rather than `window` — keeps multiple
|
|
495
|
-
* shell/controller pairs on the same page from cross-talking. Renders the
|
|
496
|
-
* built-in `<cds-custom-aichat-autocomplete>` or the active config's
|
|
497
|
-
* `renderCustomList` output. Selection routes back into the originating
|
|
498
|
-
* prompt-line.
|
|
499
|
-
*
|
|
500
|
-
* @element cds-custom-aichat-autocomplete-controller
|
|
501
|
-
* @fires cds-custom-aichat-starter-selected — `{ text: string }` after a starter is
|
|
502
|
-
* inserted into the editor; consumer triggers send.
|
|
503
|
-
* @fires cds-custom-aichat-autocomplete-item-selected — `{ item: SuggestionItem }`
|
|
504
|
-
* after a suggestion item is selected. Fired in addition to type-specific callbacks.
|
|
505
|
-
* @fires cds-custom-aichat-autocomplete-item-send — `{ text: string }` when the
|
|
506
|
-
* per-item send button is clicked inside the suggestion list.
|
|
507
|
-
*/
|
|
508
|
-
let AutocompleteControllerElement = class AutocompleteControllerElement extends LitElement {
|
|
509
|
-
constructor() {
|
|
510
|
-
super(...arguments);
|
|
511
|
-
/** When true, starter selection inserts text without firing the send event. */
|
|
512
|
-
this.isSendDisabled = false;
|
|
513
|
-
this._state = { trigger: null, items: [] };
|
|
514
|
-
this._controller = null;
|
|
515
|
-
/**
|
|
516
|
-
* Ancestor we subscribed `cds-custom-aichat-trigger-change` on. Scoping the
|
|
517
|
-
* listener to the enclosing `<cds-custom-aichat-prompt-line-shell>` (rather than
|
|
518
|
-
* `window`) keeps a second shell/controller pair on the same page from
|
|
519
|
-
* receiving each other's events.
|
|
520
|
-
*/
|
|
521
|
-
this._eventSource = null;
|
|
522
|
-
this._handleMousedown = (event) => {
|
|
523
|
-
// Prevent the autocomplete list from stealing focus from the editor.
|
|
524
|
-
event.preventDefault();
|
|
525
|
-
};
|
|
526
|
-
this._handleTriggerChange = (event) => {
|
|
527
|
-
this._controller?.handleTriggerChangeEvent(event);
|
|
528
|
-
};
|
|
529
|
-
}
|
|
530
|
-
// Render in light DOM so consumers' page-level CSS / portals can reach
|
|
531
|
-
// any custom list element they've slotted in via renderCustomList.
|
|
532
|
-
createRenderRoot() {
|
|
533
|
-
return this;
|
|
534
|
-
}
|
|
535
|
-
connectedCallback() {
|
|
536
|
-
super.connectedCallback();
|
|
537
|
-
this.addEventListener('mousedown', this._handleMousedown);
|
|
538
|
-
this._controller = new AutocompleteController({
|
|
539
|
-
mention: this.mention,
|
|
540
|
-
command: this.command,
|
|
541
|
-
autocomplete: this.autocomplete,
|
|
542
|
-
starters: this.starters,
|
|
543
|
-
isSendDisabled: this.isSendDisabled,
|
|
544
|
-
onStarterSelected: (text) => {
|
|
545
|
-
this.dispatchEvent(new CustomEvent('cds-custom-aichat-starter-selected', {
|
|
546
|
-
detail: { text },
|
|
547
|
-
bubbles: true,
|
|
548
|
-
composed: true,
|
|
549
|
-
}));
|
|
550
|
-
},
|
|
551
|
-
onChange: (next) => {
|
|
552
|
-
this._state = next;
|
|
553
|
-
},
|
|
554
|
-
});
|
|
555
|
-
// Scope to the enclosing prompt-line-shell so multiple shell/controller pairs
|
|
556
|
-
// on the same page don't cross-talk. Falls back to `this` if the
|
|
557
|
-
// controller is used outside a shell — in that case the consumer
|
|
558
|
-
// should make sure their prompt-line bubbles events into this element.
|
|
559
|
-
this._eventSource = this.closest('cds-custom-aichat-prompt-line-shell') ?? this;
|
|
560
|
-
this._eventSource.addEventListener('cds-custom-aichat-trigger-change', this._handleTriggerChange);
|
|
561
|
-
}
|
|
562
|
-
disconnectedCallback() {
|
|
563
|
-
this.removeEventListener('mousedown', this._handleMousedown);
|
|
564
|
-
this._eventSource?.removeEventListener('cds-custom-aichat-trigger-change', this._handleTriggerChange);
|
|
565
|
-
this._eventSource = null;
|
|
566
|
-
this._controller?.destroy();
|
|
567
|
-
this._controller = null;
|
|
568
|
-
super.disconnectedCallback();
|
|
569
|
-
}
|
|
570
|
-
updated(changed) {
|
|
571
|
-
if (!this._controller) {
|
|
572
|
-
return;
|
|
573
|
-
}
|
|
574
|
-
if (changed.has('mention') ||
|
|
575
|
-
changed.has('command') ||
|
|
576
|
-
changed.has('autocomplete') ||
|
|
577
|
-
changed.has('starters') ||
|
|
578
|
-
changed.has('isSendDisabled')) {
|
|
579
|
-
this._controller.setConfigs({
|
|
580
|
-
mention: this.mention,
|
|
581
|
-
command: this.command,
|
|
582
|
-
autocomplete: this.autocomplete,
|
|
583
|
-
starters: this.starters,
|
|
584
|
-
isSendDisabled: this.isSendDisabled,
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
|
-
// Register the currently-rendered list element with the controller so
|
|
588
|
-
// arrow / Enter / Escape on the editor get forwarded into it.
|
|
589
|
-
const listEl = this.querySelector('cds-custom-aichat-autocomplete') ??
|
|
590
|
-
(this.firstElementChild instanceof HTMLElement
|
|
591
|
-
? this.firstElementChild
|
|
592
|
-
: null);
|
|
593
|
-
this._controller.setListElement(listEl);
|
|
594
|
-
// Pass the editor DOM as anchorElement so the autocomplete's outside-click
|
|
595
|
-
// guard treats clicks on the editor as inside-clicks (not dismissals).
|
|
596
|
-
const editorDom = this._controller.getPromptLine()?.getEditor()?.view
|
|
597
|
-
.dom;
|
|
598
|
-
const autocompleteEl = this.querySelector('cds-custom-aichat-autocomplete');
|
|
599
|
-
if (autocompleteEl) {
|
|
600
|
-
autocompleteEl.anchorElement = editorDom ?? null;
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
render() {
|
|
604
|
-
const { trigger, items, renderCustomList, disableDirectSend } = this._state;
|
|
605
|
-
if (!trigger || items.length === 0) {
|
|
606
|
-
return nothing;
|
|
607
|
-
}
|
|
608
|
-
if (renderCustomList) {
|
|
609
|
-
const result = renderCustomList({
|
|
610
|
-
items,
|
|
611
|
-
query: trigger.query,
|
|
612
|
-
onDismiss: () => this._controller?.dismiss(),
|
|
613
|
-
onSelect: (item) => this._selectItem(item),
|
|
614
|
-
onSend: (text) => this._sendItem(text),
|
|
615
|
-
});
|
|
616
|
-
if (result instanceof HTMLElement) {
|
|
617
|
-
return html `${result}`;
|
|
618
|
-
}
|
|
619
|
-
// Custom renderer returned something other than an HTMLElement (e.g.
|
|
620
|
-
// a React node). Surface it on a side-channel event so React adapters
|
|
621
|
-
// can portal it into place themselves.
|
|
622
|
-
this.dispatchEvent(new CustomEvent('cds-custom-aichat-custom-list-render', {
|
|
623
|
-
detail: { reactNode: result },
|
|
624
|
-
bubbles: true,
|
|
625
|
-
composed: true,
|
|
626
|
-
}));
|
|
627
|
-
return nothing;
|
|
628
|
-
}
|
|
629
|
-
const { items: flatItems, groups } = itemsToGroups(items);
|
|
630
|
-
return html `
|
|
631
|
-
<cds-custom-aichat-autocomplete
|
|
632
|
-
.items=${flatItems}
|
|
633
|
-
.groups=${groups}
|
|
634
|
-
.disableDirectSend=${disableDirectSend}
|
|
635
|
-
@cds-custom-aichat-autocomplete-select=${(e) => this._selectItem(e.detail.item)}
|
|
636
|
-
@cds-custom-aichat-autocomplete-send=${(e) => this._sendItem(e.detail.text)}
|
|
637
|
-
@cds-custom-aichat-autocomplete-dismiss=${() => this._controller?.dismiss()}></cds-custom-aichat-autocomplete>
|
|
638
|
-
`;
|
|
639
|
-
}
|
|
640
|
-
_selectItem(item) {
|
|
641
|
-
this._controller?.select(item);
|
|
642
|
-
this.dispatchEvent(new CustomEvent('cds-custom-aichat-autocomplete-item-selected', {
|
|
643
|
-
detail: { item },
|
|
644
|
-
bubbles: true,
|
|
645
|
-
composed: true,
|
|
646
|
-
}));
|
|
647
|
-
}
|
|
648
|
-
_sendItem(text) {
|
|
649
|
-
if (this.isSendDisabled) {
|
|
650
|
-
return;
|
|
651
|
-
}
|
|
652
|
-
this._controller?.dismiss(true);
|
|
653
|
-
this.dispatchEvent(new CustomEvent('cds-custom-aichat-autocomplete-item-send', {
|
|
654
|
-
detail: { text },
|
|
655
|
-
bubbles: true,
|
|
656
|
-
composed: true,
|
|
657
|
-
}));
|
|
658
|
-
}
|
|
659
|
-
};
|
|
660
|
-
__decorate([
|
|
661
|
-
property({ attribute: false })
|
|
662
|
-
], AutocompleteControllerElement.prototype, "mention", void 0);
|
|
663
|
-
__decorate([
|
|
664
|
-
property({ attribute: false })
|
|
665
|
-
], AutocompleteControllerElement.prototype, "command", void 0);
|
|
666
|
-
__decorate([
|
|
667
|
-
property({ attribute: false })
|
|
668
|
-
], AutocompleteControllerElement.prototype, "autocomplete", void 0);
|
|
669
|
-
__decorate([
|
|
670
|
-
property({ attribute: false })
|
|
671
|
-
], AutocompleteControllerElement.prototype, "starters", void 0);
|
|
672
|
-
__decorate([
|
|
673
|
-
property({ type: Boolean, attribute: 'is-send-disabled' })
|
|
674
|
-
], AutocompleteControllerElement.prototype, "isSendDisabled", void 0);
|
|
675
|
-
__decorate([
|
|
676
|
-
state()
|
|
677
|
-
], AutocompleteControllerElement.prototype, "_state", void 0);
|
|
678
|
-
AutocompleteControllerElement = __decorate([
|
|
679
|
-
carbonElement(`${prefix}-autocomplete-controller`)
|
|
680
|
-
], AutocompleteControllerElement);
|
|
681
|
-
var AutocompleteControllerElement_default = AutocompleteControllerElement;
|
|
682
488
|
|
|
683
|
-
export { AutocompleteController,
|
|
489
|
+
export { AutocompleteController, itemsToGroups };
|
|
684
490
|
//# sourceMappingURL=autocomplete-controller.js.map
|