@carbon/ai-chat-components 1.11.0 → 1.12.0-rc.0
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 +2414 -2161
- 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/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 +68 -0
- package/es/components/prompt-line/src/autocomplete-controller-element.js +221 -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 +44 -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/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 +4 -28
- package/es/components/prompt-line/src/tiptap/carbon-autocomplete.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/carbon-mention.js +13 -47
- 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/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.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/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 +68 -0
- package/es-custom/components/prompt-line/src/autocomplete-controller-element.js +221 -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 +44 -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/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 +4 -28
- 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 +13 -47
- 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/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.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
|
@@ -10,8 +10,9 @@ export { default as PromptLineElement } from './src/prompt-line.js';
|
|
|
10
10
|
export { default as ErrorMessage } from './src/error-message.js';
|
|
11
11
|
export { default as InputSendControlElement } from './src/send-control.js';
|
|
12
12
|
export { default as StopStreamingButton } from './src/stop-streaming-button.js';
|
|
13
|
-
export {
|
|
13
|
+
export { default as AutocompleteControllerElement } from './src/autocomplete-controller-element.js';
|
|
14
14
|
export { preloadPromptLineRich } from './src/prompt-line-rich-loader.js';
|
|
15
|
+
export { AutocompleteController } from './src/autocomplete-controller.js';
|
|
15
16
|
export { carbonCommand, carbonMention } from './src/tiptap/carbon-mention.js';
|
|
16
17
|
export { carbonAutocomplete } from './src/tiptap/carbon-autocomplete.js';
|
|
17
18
|
export { carbonStarterTrigger } from './src/tiptap/carbon-starter-trigger.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*
|
|
4
|
+
* Copyright IBM Corp. 2026
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
import type PromptLineElement from '../prompt-line.js';
|
|
10
|
+
/**
|
|
11
|
+
* Poll until the rich editor has finished loading + mounting. Tiptap is loaded
|
|
12
|
+
* via a lazy `import()` (see #1578), so the first upgrade in a test file pays a
|
|
13
|
+
* cold-load cost that can approach a couple seconds on Chromium — poll long
|
|
14
|
+
* enough to cover it (the runner's Mocha timeout is raised to match in
|
|
15
|
+
* web-test-runner.config.js).
|
|
16
|
+
*
|
|
17
|
+
* Pass an optional `context` callback to augment the timeout error message with
|
|
18
|
+
* file-local diagnostics (see `describeUpgrade` in prompt-line.test.ts).
|
|
19
|
+
*/
|
|
20
|
+
export declare function waitForRich(el: PromptLineElement, context?: (el: PromptLineElement) => Promise<string>): Promise<void>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*
|
|
4
|
+
* Copyright IBM Corp. 2026
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
import { LitElement, nothing } from 'lit';
|
|
10
|
+
import '../autocomplete/src/autocomplete.js';
|
|
11
|
+
import type { AutocompleteConfig, StartersConfig, TriggerSuggestionConfig } from './tiptap/types.js';
|
|
12
|
+
/**
|
|
13
|
+
* `<cds-aichat-autocomplete-controller>` — drops the autocomplete overlay
|
|
14
|
+
* lifecycle into a `<cds-aichat-prompt-line-shell>`'s `autocomplete-content` slot.
|
|
15
|
+
*
|
|
16
|
+
* Listens for `cds-aichat-trigger-change` events bubbling up from the
|
|
17
|
+
* enclosing prompt-line-shell (the events are `composed: true, bubbles: true`, so
|
|
18
|
+
* they reach here from inside the prompt-line's shadow root). Scoping the
|
|
19
|
+
* listener to the shell — rather than `window` — keeps multiple
|
|
20
|
+
* shell/controller pairs on the same page from cross-talking. Renders the
|
|
21
|
+
* built-in `<cds-aichat-autocomplete>` or the active config's
|
|
22
|
+
* `renderCustomList` output. Selection routes back into the originating
|
|
23
|
+
* prompt-line.
|
|
24
|
+
*
|
|
25
|
+
* @element cds-aichat-autocomplete-controller
|
|
26
|
+
* @fires cds-aichat-starter-selected — `{ text: string }` after a starter is
|
|
27
|
+
* inserted into the editor; consumer triggers send.
|
|
28
|
+
* @fires cds-aichat-autocomplete-item-selected — `{ item: SuggestionItem }`
|
|
29
|
+
* after a suggestion item is selected. Fired in addition to type-specific callbacks.
|
|
30
|
+
* @fires cds-aichat-autocomplete-item-send — `{ text: string }` when the
|
|
31
|
+
* per-item send button is clicked inside the suggestion list.
|
|
32
|
+
*/
|
|
33
|
+
declare class AutocompleteControllerElement extends LitElement {
|
|
34
|
+
/** `@`-style mention trigger config. */
|
|
35
|
+
mention?: TriggerSuggestionConfig;
|
|
36
|
+
/** `/`-style command trigger config. */
|
|
37
|
+
command?: TriggerSuggestionConfig;
|
|
38
|
+
/** Live-typeahead autocomplete config (no trigger character). */
|
|
39
|
+
autocomplete?: AutocompleteConfig;
|
|
40
|
+
/** Starter prompts shown when the editor is empty + focused + editable. */
|
|
41
|
+
starters?: StartersConfig;
|
|
42
|
+
/** When true, starter selection inserts text without firing the send event. */
|
|
43
|
+
isSendDisabled: boolean;
|
|
44
|
+
private _state;
|
|
45
|
+
private _controller;
|
|
46
|
+
/**
|
|
47
|
+
* Ancestor we subscribed `cds-aichat-trigger-change` on. Scoping the
|
|
48
|
+
* listener to the enclosing `<cds-aichat-prompt-line-shell>` (rather than
|
|
49
|
+
* `window`) keeps a second shell/controller pair on the same page from
|
|
50
|
+
* receiving each other's events.
|
|
51
|
+
*/
|
|
52
|
+
private _eventSource;
|
|
53
|
+
protected createRenderRoot(): this;
|
|
54
|
+
connectedCallback(): void;
|
|
55
|
+
disconnectedCallback(): void;
|
|
56
|
+
updated(changed: Map<string, unknown>): void;
|
|
57
|
+
render(): import("lit-html").TemplateResult<1> | typeof nothing;
|
|
58
|
+
private _selectItem;
|
|
59
|
+
private _sendItem;
|
|
60
|
+
private _handleMousedown;
|
|
61
|
+
private _handleTriggerChange;
|
|
62
|
+
}
|
|
63
|
+
declare global {
|
|
64
|
+
interface HTMLElementTagNameMap {
|
|
65
|
+
'cds-aichat-autocomplete-controller': AutocompleteControllerElement;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export default AutocompleteControllerElement;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2025
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
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
|
+
import { AutocompleteController, itemsToGroups } from './autocomplete-controller.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @license
|
|
18
|
+
*
|
|
19
|
+
* Copyright IBM Corp. 2026
|
|
20
|
+
*
|
|
21
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
22
|
+
* LICENSE file in the root directory of this source tree.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* `<cds-aichat-autocomplete-controller>` — drops the autocomplete overlay
|
|
26
|
+
* lifecycle into a `<cds-aichat-prompt-line-shell>`'s `autocomplete-content` slot.
|
|
27
|
+
*
|
|
28
|
+
* Listens for `cds-aichat-trigger-change` events bubbling up from the
|
|
29
|
+
* enclosing prompt-line-shell (the events are `composed: true, bubbles: true`, so
|
|
30
|
+
* they reach here from inside the prompt-line's shadow root). Scoping the
|
|
31
|
+
* listener to the shell — rather than `window` — keeps multiple
|
|
32
|
+
* shell/controller pairs on the same page from cross-talking. Renders the
|
|
33
|
+
* built-in `<cds-aichat-autocomplete>` or the active config's
|
|
34
|
+
* `renderCustomList` output. Selection routes back into the originating
|
|
35
|
+
* prompt-line.
|
|
36
|
+
*
|
|
37
|
+
* @element cds-aichat-autocomplete-controller
|
|
38
|
+
* @fires cds-aichat-starter-selected — `{ text: string }` after a starter is
|
|
39
|
+
* inserted into the editor; consumer triggers send.
|
|
40
|
+
* @fires cds-aichat-autocomplete-item-selected — `{ item: SuggestionItem }`
|
|
41
|
+
* after a suggestion item is selected. Fired in addition to type-specific callbacks.
|
|
42
|
+
* @fires cds-aichat-autocomplete-item-send — `{ text: string }` when the
|
|
43
|
+
* per-item send button is clicked inside the suggestion list.
|
|
44
|
+
*/
|
|
45
|
+
let AutocompleteControllerElement = class AutocompleteControllerElement extends LitElement {
|
|
46
|
+
constructor() {
|
|
47
|
+
super(...arguments);
|
|
48
|
+
/** When true, starter selection inserts text without firing the send event. */
|
|
49
|
+
this.isSendDisabled = false;
|
|
50
|
+
this._state = { trigger: null, items: [] };
|
|
51
|
+
this._controller = null;
|
|
52
|
+
/**
|
|
53
|
+
* Ancestor we subscribed `cds-aichat-trigger-change` on. Scoping the
|
|
54
|
+
* listener to the enclosing `<cds-aichat-prompt-line-shell>` (rather than
|
|
55
|
+
* `window`) keeps a second shell/controller pair on the same page from
|
|
56
|
+
* receiving each other's events.
|
|
57
|
+
*/
|
|
58
|
+
this._eventSource = null;
|
|
59
|
+
this._handleMousedown = (event) => {
|
|
60
|
+
// Prevent the autocomplete list from stealing focus from the editor.
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
};
|
|
63
|
+
this._handleTriggerChange = (event) => {
|
|
64
|
+
this._controller?.handleTriggerChangeEvent(event);
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
// Render in light DOM so consumers' page-level CSS / portals can reach
|
|
68
|
+
// any custom list element they've slotted in via renderCustomList.
|
|
69
|
+
createRenderRoot() {
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
connectedCallback() {
|
|
73
|
+
super.connectedCallback();
|
|
74
|
+
this.addEventListener('mousedown', this._handleMousedown);
|
|
75
|
+
this._controller = new AutocompleteController({
|
|
76
|
+
mention: this.mention,
|
|
77
|
+
command: this.command,
|
|
78
|
+
autocomplete: this.autocomplete,
|
|
79
|
+
starters: this.starters,
|
|
80
|
+
isSendDisabled: this.isSendDisabled,
|
|
81
|
+
onStarterSelected: (text) => {
|
|
82
|
+
this.dispatchEvent(new CustomEvent('cds-aichat-starter-selected', {
|
|
83
|
+
detail: { text },
|
|
84
|
+
bubbles: true,
|
|
85
|
+
composed: true,
|
|
86
|
+
}));
|
|
87
|
+
},
|
|
88
|
+
onChange: (next) => {
|
|
89
|
+
this._state = next;
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
// Scope to the enclosing prompt-line-shell so multiple shell/controller pairs
|
|
93
|
+
// on the same page don't cross-talk. Falls back to `this` if the
|
|
94
|
+
// controller is used outside a shell — in that case the consumer
|
|
95
|
+
// should make sure their prompt-line bubbles events into this element.
|
|
96
|
+
this._eventSource = this.closest('cds-aichat-prompt-line-shell') ?? this;
|
|
97
|
+
this._eventSource.addEventListener('cds-aichat-trigger-change', this._handleTriggerChange);
|
|
98
|
+
}
|
|
99
|
+
disconnectedCallback() {
|
|
100
|
+
this.removeEventListener('mousedown', this._handleMousedown);
|
|
101
|
+
this._eventSource?.removeEventListener('cds-aichat-trigger-change', this._handleTriggerChange);
|
|
102
|
+
this._eventSource = null;
|
|
103
|
+
this._controller?.destroy();
|
|
104
|
+
this._controller = null;
|
|
105
|
+
super.disconnectedCallback();
|
|
106
|
+
}
|
|
107
|
+
updated(changed) {
|
|
108
|
+
if (!this._controller) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (changed.has('mention') ||
|
|
112
|
+
changed.has('command') ||
|
|
113
|
+
changed.has('autocomplete') ||
|
|
114
|
+
changed.has('starters') ||
|
|
115
|
+
changed.has('isSendDisabled')) {
|
|
116
|
+
this._controller.setConfigs({
|
|
117
|
+
mention: this.mention,
|
|
118
|
+
command: this.command,
|
|
119
|
+
autocomplete: this.autocomplete,
|
|
120
|
+
starters: this.starters,
|
|
121
|
+
isSendDisabled: this.isSendDisabled,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
// Register the currently-rendered list element with the controller so
|
|
125
|
+
// arrow / Enter / Escape on the editor get forwarded into it.
|
|
126
|
+
const listEl = this.querySelector('cds-aichat-autocomplete') ??
|
|
127
|
+
(this.firstElementChild instanceof HTMLElement
|
|
128
|
+
? this.firstElementChild
|
|
129
|
+
: null);
|
|
130
|
+
this._controller.setListElement(listEl);
|
|
131
|
+
// Pass the editor DOM as anchorElement so the autocomplete's outside-click
|
|
132
|
+
// guard treats clicks on the editor as inside-clicks (not dismissals).
|
|
133
|
+
const editorDom = this._controller.getPromptLine()?.getEditor()?.view
|
|
134
|
+
.dom;
|
|
135
|
+
const autocompleteEl = this.querySelector('cds-aichat-autocomplete');
|
|
136
|
+
if (autocompleteEl) {
|
|
137
|
+
autocompleteEl.anchorElement = editorDom ?? null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
render() {
|
|
141
|
+
const { trigger, items, renderCustomList, disableDirectSend } = this._state;
|
|
142
|
+
if (!trigger || items.length === 0) {
|
|
143
|
+
return nothing;
|
|
144
|
+
}
|
|
145
|
+
if (renderCustomList) {
|
|
146
|
+
const result = renderCustomList({
|
|
147
|
+
items,
|
|
148
|
+
query: trigger.query,
|
|
149
|
+
onDismiss: () => this._controller?.dismiss(),
|
|
150
|
+
onSelect: (item) => this._selectItem(item),
|
|
151
|
+
onSend: (text) => this._sendItem(text),
|
|
152
|
+
});
|
|
153
|
+
if (result instanceof HTMLElement) {
|
|
154
|
+
return html `${result}`;
|
|
155
|
+
}
|
|
156
|
+
// Custom renderer returned something other than an HTMLElement (e.g.
|
|
157
|
+
// a React node). Surface it on a side-channel event so React adapters
|
|
158
|
+
// can portal it into place themselves.
|
|
159
|
+
this.dispatchEvent(new CustomEvent('cds-aichat-custom-list-render', {
|
|
160
|
+
detail: { reactNode: result },
|
|
161
|
+
bubbles: true,
|
|
162
|
+
composed: true,
|
|
163
|
+
}));
|
|
164
|
+
return nothing;
|
|
165
|
+
}
|
|
166
|
+
const { items: flatItems, groups } = itemsToGroups(items);
|
|
167
|
+
return html `
|
|
168
|
+
<cds-aichat-autocomplete
|
|
169
|
+
.items=${flatItems}
|
|
170
|
+
.groups=${groups}
|
|
171
|
+
.disableDirectSend=${disableDirectSend}
|
|
172
|
+
@cds-aichat-autocomplete-select=${(e) => this._selectItem(e.detail.item)}
|
|
173
|
+
@cds-aichat-autocomplete-send=${(e) => this._sendItem(e.detail.text)}
|
|
174
|
+
@cds-aichat-autocomplete-dismiss=${() => this._controller?.dismiss()}></cds-aichat-autocomplete>
|
|
175
|
+
`;
|
|
176
|
+
}
|
|
177
|
+
_selectItem(item) {
|
|
178
|
+
this._controller?.select(item);
|
|
179
|
+
this.dispatchEvent(new CustomEvent('cds-aichat-autocomplete-item-selected', {
|
|
180
|
+
detail: { item },
|
|
181
|
+
bubbles: true,
|
|
182
|
+
composed: true,
|
|
183
|
+
}));
|
|
184
|
+
}
|
|
185
|
+
_sendItem(text) {
|
|
186
|
+
if (this.isSendDisabled) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
this._controller?.dismiss(true);
|
|
190
|
+
this.dispatchEvent(new CustomEvent('cds-aichat-autocomplete-item-send', {
|
|
191
|
+
detail: { text },
|
|
192
|
+
bubbles: true,
|
|
193
|
+
composed: true,
|
|
194
|
+
}));
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
__decorate([
|
|
198
|
+
property({ attribute: false })
|
|
199
|
+
], AutocompleteControllerElement.prototype, "mention", void 0);
|
|
200
|
+
__decorate([
|
|
201
|
+
property({ attribute: false })
|
|
202
|
+
], AutocompleteControllerElement.prototype, "command", void 0);
|
|
203
|
+
__decorate([
|
|
204
|
+
property({ attribute: false })
|
|
205
|
+
], AutocompleteControllerElement.prototype, "autocomplete", void 0);
|
|
206
|
+
__decorate([
|
|
207
|
+
property({ attribute: false })
|
|
208
|
+
], AutocompleteControllerElement.prototype, "starters", void 0);
|
|
209
|
+
__decorate([
|
|
210
|
+
property({ type: Boolean, attribute: 'is-send-disabled' })
|
|
211
|
+
], AutocompleteControllerElement.prototype, "isSendDisabled", void 0);
|
|
212
|
+
__decorate([
|
|
213
|
+
state()
|
|
214
|
+
], AutocompleteControllerElement.prototype, "_state", void 0);
|
|
215
|
+
AutocompleteControllerElement = __decorate([
|
|
216
|
+
carbonElement(`${prefix}-autocomplete-controller`)
|
|
217
|
+
], AutocompleteControllerElement);
|
|
218
|
+
var AutocompleteControllerElement_default = AutocompleteControllerElement;
|
|
219
|
+
|
|
220
|
+
export { AutocompleteControllerElement_default as default };
|
|
221
|
+
//# sourceMappingURL=autocomplete-controller-element.js.map
|
|
@@ -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 {\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-aichat-autocomplete-controller>` — drops the autocomplete overlay\n * lifecycle into a `<cds-aichat-prompt-line-shell>`'s `autocomplete-content` slot.\n *\n * Listens for `cds-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-aichat-autocomplete>` or the active config's\n * `renderCustomList` output. Selection routes back into the originating\n * prompt-line.\n *\n * @element cds-aichat-autocomplete-controller\n * @fires cds-aichat-starter-selected — `{ text: string }` after a starter is\n * inserted into the editor; consumer triggers send.\n * @fires cds-aichat-autocomplete-item-selected — `{ item: SuggestionItem }`\n * after a suggestion item is selected. Fired in addition to type-specific callbacks.\n * @fires cds-aichat-autocomplete-item-send — `{ text: string }` when the\n * per-item send button is clicked inside the suggestion list.\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 private _controller: AutocompleteController | null = null;\n /**\n * Ancestor we subscribed `cds-aichat-trigger-change` on. Scoping the\n * listener to the enclosing `<cds-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._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-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-aichat-prompt-line-shell') ?? this;\n this._eventSource.addEventListener(\n 'cds-aichat-trigger-change',\n this._handleTriggerChange as EventListener\n );\n }\n\n override disconnectedCallback(): void {\n this.removeEventListener('mousedown', this._handleMousedown);\n this._eventSource?.removeEventListener(\n 'cds-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-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-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 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-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-aichat-autocomplete\n .items=${flatItems}\n .groups=${groups}\n .disableDirectSend=${disableDirectSend}\n @cds-aichat-autocomplete-select=${(\n e: CustomEvent<{ item: SuggestionItem }>\n ) => this._selectItem(e.detail.item)}\n @cds-aichat-autocomplete-send=${(e: CustomEvent<{ text: string }>) =>\n this._sendItem(e.detail.text)}\n @cds-aichat-autocomplete-dismiss=${() => this._controller?.dismiss()}></cds-aichat-autocomplete>\n `;\n }\n\n private _selectItem(item: SuggestionItem): void {\n this._controller?.select(item);\n this.dispatchEvent(\n new CustomEvent('cds-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-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 _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-aichat-autocomplete-controller': AutocompleteControllerElement;\n }\n}\n\nexport default AutocompleteControllerElement;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;AAOG;AAqBH;;;;;;;;;;;;;;;;;;;;AAoBG;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;QAElE,IAAA,CAAA,WAAW,GAAkC,IAAI;AACzD;;;;;AAKG;QACK,IAAA,CAAA,YAAY,GAAuB,IAAI;AAiKvC,QAAA,IAAA,CAAA,gBAAgB,GAAG,CAAC,KAAiB,KAAU;;YAErD,KAAK,CAAC,cAAc,EAAE;AACxB,QAAA,CAAC;AAEO,QAAA,IAAA,CAAA,oBAAoB,GAAG,CAAC,K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AQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE;AACJ,CAAA,EAAA,6BAAA,CAAA,SAAA,EAAA,UAAA,EAAA,MAAA,CAAA;AAI1B,UAAA,CAAA;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE;AACnC,CAAA,EAAA,6BAAA,CAAA,SAAA,EAAA,gBAAA,EAAA,MAAA,CAAA;AAGf,UAAA,CAAA;AADP,IAAA,KAAK;AACqE,CAAA,EAAA,6BAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;AAtBvE,6BAA6B,GAAA,UAAA,CAAA;AADlC,IAAA,aAAa,CAAC,CAAA,EAAG,MAAM,CAAA,wBAAA,CAA0B;AAC5C,CAAA,EAAA,6BAA6B,CA4MlC;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-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-aichat-autocomplete-controller>` — drops the autocomplete overlay
|
|
153
|
-
* lifecycle into a `<cds-aichat-prompt-line-shell>`'s `autocomplete-content` slot.
|
|
154
|
-
*
|
|
155
|
-
* Listens for `cds-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-aichat-autocomplete>` or the active config's
|
|
161
|
-
* `renderCustomList` output. Selection routes back into the originating
|
|
162
|
-
* prompt-line.
|
|
163
|
-
*
|
|
164
|
-
* @element cds-aichat-autocomplete-controller
|
|
165
|
-
* @fires cds-aichat-starter-selected — `{ text: string }` after a starter is
|
|
166
|
-
* inserted into the editor; consumer triggers send.
|
|
167
|
-
* @fires cds-aichat-autocomplete-item-selected — `{ item: SuggestionItem }`
|
|
168
|
-
* after a suggestion item is selected. Fired in addition to type-specific callbacks.
|
|
169
|
-
* @fires cds-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-aichat-trigger-change` on. Scoping the
|
|
187
|
-
* listener to the enclosing `<cds-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-aichat-autocomplete-controller': AutocompleteControllerElement;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
export default AutocompleteControllerElement;
|