@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,262 @@
|
|
|
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
|
+
* @fires cds-aichat-list-navigated — `{ navigated: boolean }` when the user
|
|
45
|
+
* starts or stops navigating the suggestion list with arrow keys. WC
|
|
46
|
+
* consumers should use this to disable their send control while `navigated`
|
|
47
|
+
* is `true` (the `listNavigated` getter reflects the same state).
|
|
48
|
+
*/
|
|
49
|
+
let AutocompleteControllerElement = class AutocompleteControllerElement extends LitElement {
|
|
50
|
+
constructor() {
|
|
51
|
+
super(...arguments);
|
|
52
|
+
/** When true, starter selection inserts text without firing the send event. */
|
|
53
|
+
this.isSendDisabled = false;
|
|
54
|
+
this._state = { trigger: null, items: [] };
|
|
55
|
+
/**
|
|
56
|
+
* Tracks whether the user is actively navigating inside the autocomplete
|
|
57
|
+
* list. When `true`, the send button should be disabled so that Enter
|
|
58
|
+
* confirms the highlighted item rather than submitting the prompt.
|
|
59
|
+
*/
|
|
60
|
+
this._listNavigated = false;
|
|
61
|
+
this._controller = null;
|
|
62
|
+
/**
|
|
63
|
+
* Ancestor we subscribed `cds-aichat-trigger-change` on. Scoping the
|
|
64
|
+
* listener to the enclosing `<cds-aichat-prompt-line-shell>` (rather than
|
|
65
|
+
* `window`) keeps a second shell/controller pair on the same page from
|
|
66
|
+
* receiving each other's events.
|
|
67
|
+
*/
|
|
68
|
+
this._eventSource = null;
|
|
69
|
+
this._handleMousedown = (event) => {
|
|
70
|
+
// Prevent the autocomplete list from stealing focus from the editor.
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
};
|
|
73
|
+
this._handleAutocompleteNavigated = (event) => {
|
|
74
|
+
const { navigated } = event.detail;
|
|
75
|
+
if (this._listNavigated === navigated) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
this._listNavigated = navigated;
|
|
79
|
+
// Re-fire a composed event so parent elements (e.g. a WC integration shell)
|
|
80
|
+
// can disable their send control while the user navigates the list.
|
|
81
|
+
this.dispatchEvent(new CustomEvent('cds-aichat-list-navigated', { detail: { navigated }, bubbles: true, composed: true }));
|
|
82
|
+
};
|
|
83
|
+
this._handleTriggerChange = (event) => {
|
|
84
|
+
this._controller?.handleTriggerChangeEvent(event);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Returns `true` while the user is navigating inside the autocomplete list.
|
|
89
|
+
* Consumers can use this to disable their send control.
|
|
90
|
+
*/
|
|
91
|
+
get listNavigated() {
|
|
92
|
+
return this._listNavigated;
|
|
93
|
+
}
|
|
94
|
+
// Render in light DOM so consumers' page-level CSS / portals can reach
|
|
95
|
+
// any custom list element they've slotted in via renderCustomList.
|
|
96
|
+
createRenderRoot() {
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
connectedCallback() {
|
|
100
|
+
super.connectedCallback();
|
|
101
|
+
this.addEventListener('mousedown', this._handleMousedown);
|
|
102
|
+
this.addEventListener('cds-aichat-autocomplete-navigated', this._handleAutocompleteNavigated);
|
|
103
|
+
this._controller = new AutocompleteController({
|
|
104
|
+
mention: this.mention,
|
|
105
|
+
command: this.command,
|
|
106
|
+
autocomplete: this.autocomplete,
|
|
107
|
+
starters: this.starters,
|
|
108
|
+
isSendDisabled: this.isSendDisabled,
|
|
109
|
+
onStarterSelected: (text) => {
|
|
110
|
+
this.dispatchEvent(new CustomEvent('cds-aichat-starter-selected', {
|
|
111
|
+
detail: { text },
|
|
112
|
+
bubbles: true,
|
|
113
|
+
composed: true,
|
|
114
|
+
}));
|
|
115
|
+
},
|
|
116
|
+
onChange: (next) => {
|
|
117
|
+
this._state = next;
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
// Scope to the enclosing prompt-line-shell so multiple shell/controller pairs
|
|
121
|
+
// on the same page don't cross-talk. Falls back to `this` if the
|
|
122
|
+
// controller is used outside a shell — in that case the consumer
|
|
123
|
+
// should make sure their prompt-line bubbles events into this element.
|
|
124
|
+
this._eventSource = this.closest('cds-aichat-prompt-line-shell') ?? this;
|
|
125
|
+
this._eventSource.addEventListener('cds-aichat-trigger-change', this._handleTriggerChange);
|
|
126
|
+
}
|
|
127
|
+
disconnectedCallback() {
|
|
128
|
+
this.removeEventListener('mousedown', this._handleMousedown);
|
|
129
|
+
this.removeEventListener('cds-aichat-autocomplete-navigated', this._handleAutocompleteNavigated);
|
|
130
|
+
this._eventSource?.removeEventListener('cds-aichat-trigger-change', this._handleTriggerChange);
|
|
131
|
+
this._eventSource = null;
|
|
132
|
+
this._controller?.destroy();
|
|
133
|
+
this._controller = null;
|
|
134
|
+
super.disconnectedCallback();
|
|
135
|
+
}
|
|
136
|
+
updated(changed) {
|
|
137
|
+
if (!this._controller) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (changed.has('mention') ||
|
|
141
|
+
changed.has('command') ||
|
|
142
|
+
changed.has('autocomplete') ||
|
|
143
|
+
changed.has('starters') ||
|
|
144
|
+
changed.has('isSendDisabled')) {
|
|
145
|
+
this._controller.setConfigs({
|
|
146
|
+
mention: this.mention,
|
|
147
|
+
command: this.command,
|
|
148
|
+
autocomplete: this.autocomplete,
|
|
149
|
+
starters: this.starters,
|
|
150
|
+
isSendDisabled: this.isSendDisabled,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
// Register the currently-rendered list element with the controller so
|
|
154
|
+
// arrow / Enter / Escape on the editor get forwarded into it.
|
|
155
|
+
const listEl = this.querySelector('cds-aichat-autocomplete') ??
|
|
156
|
+
(this.firstElementChild instanceof HTMLElement
|
|
157
|
+
? this.firstElementChild
|
|
158
|
+
: null);
|
|
159
|
+
this._controller.setListElement(listEl);
|
|
160
|
+
// Pass the editor DOM as anchorElement so the autocomplete's outside-click
|
|
161
|
+
// guard treats clicks on the editor as inside-clicks (not dismissals).
|
|
162
|
+
const editorDom = this._controller.getPromptLine()?.getEditor()?.view
|
|
163
|
+
.dom;
|
|
164
|
+
const autocompleteEl = this.querySelector('cds-aichat-autocomplete');
|
|
165
|
+
if (autocompleteEl) {
|
|
166
|
+
autocompleteEl.anchorElement = editorDom ?? null;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
render() {
|
|
170
|
+
const { trigger, items, renderCustomList, disableDirectSend } = this._state;
|
|
171
|
+
if (!trigger || items.length === 0) {
|
|
172
|
+
// List is gone — reset navigation state so the send button is unblocked.
|
|
173
|
+
// This covers cases where the list is removed without an autocomplete
|
|
174
|
+
// dismiss/select/send event (e.g. the user deletes the trigger character).
|
|
175
|
+
if (this._listNavigated) {
|
|
176
|
+
this._listNavigated = false;
|
|
177
|
+
this.dispatchEvent(new CustomEvent('cds-aichat-list-navigated', { detail: { navigated: false }, bubbles: true, composed: true }));
|
|
178
|
+
// Also fire the lower-level event so send-control's shell listener fires.
|
|
179
|
+
this.dispatchEvent(new CustomEvent('cds-aichat-autocomplete-navigated', { detail: { navigated: false }, bubbles: true, composed: true }));
|
|
180
|
+
}
|
|
181
|
+
return nothing;
|
|
182
|
+
}
|
|
183
|
+
if (renderCustomList) {
|
|
184
|
+
const result = renderCustomList({
|
|
185
|
+
items,
|
|
186
|
+
query: trigger.query,
|
|
187
|
+
onDismiss: () => this._controller?.dismiss(),
|
|
188
|
+
onSelect: (item) => this._selectItem(item),
|
|
189
|
+
onSend: (text) => this._sendItem(text),
|
|
190
|
+
});
|
|
191
|
+
if (result instanceof HTMLElement) {
|
|
192
|
+
return html `${result}`;
|
|
193
|
+
}
|
|
194
|
+
// Custom renderer returned something other than an HTMLElement (e.g.
|
|
195
|
+
// a React node). Surface it on a side-channel event so React adapters
|
|
196
|
+
// can portal it into place themselves.
|
|
197
|
+
this.dispatchEvent(new CustomEvent('cds-aichat-custom-list-render', {
|
|
198
|
+
detail: { reactNode: result },
|
|
199
|
+
bubbles: true,
|
|
200
|
+
composed: true,
|
|
201
|
+
}));
|
|
202
|
+
return nothing;
|
|
203
|
+
}
|
|
204
|
+
const { items: flatItems, groups } = itemsToGroups(items);
|
|
205
|
+
return html `
|
|
206
|
+
<cds-aichat-autocomplete
|
|
207
|
+
.items=${flatItems}
|
|
208
|
+
.groups=${groups}
|
|
209
|
+
.disableDirectSend=${disableDirectSend}
|
|
210
|
+
@cds-aichat-autocomplete-select=${(e) => this._selectItem(e.detail.item)}
|
|
211
|
+
@cds-aichat-autocomplete-send=${(e) => this._sendItem(e.detail.text)}
|
|
212
|
+
@cds-aichat-autocomplete-dismiss=${() => this._controller?.dismiss()}></cds-aichat-autocomplete>
|
|
213
|
+
`;
|
|
214
|
+
}
|
|
215
|
+
_selectItem(item) {
|
|
216
|
+
this._controller?.select(item);
|
|
217
|
+
this.dispatchEvent(new CustomEvent('cds-aichat-autocomplete-item-selected', {
|
|
218
|
+
detail: { item },
|
|
219
|
+
bubbles: true,
|
|
220
|
+
composed: true,
|
|
221
|
+
}));
|
|
222
|
+
}
|
|
223
|
+
_sendItem(text) {
|
|
224
|
+
if (this.isSendDisabled) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
this._controller?.dismiss(true);
|
|
228
|
+
this.dispatchEvent(new CustomEvent('cds-aichat-autocomplete-item-send', {
|
|
229
|
+
detail: { text },
|
|
230
|
+
bubbles: true,
|
|
231
|
+
composed: true,
|
|
232
|
+
}));
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
__decorate([
|
|
236
|
+
property({ attribute: false })
|
|
237
|
+
], AutocompleteControllerElement.prototype, "mention", void 0);
|
|
238
|
+
__decorate([
|
|
239
|
+
property({ attribute: false })
|
|
240
|
+
], AutocompleteControllerElement.prototype, "command", void 0);
|
|
241
|
+
__decorate([
|
|
242
|
+
property({ attribute: false })
|
|
243
|
+
], AutocompleteControllerElement.prototype, "autocomplete", void 0);
|
|
244
|
+
__decorate([
|
|
245
|
+
property({ attribute: false })
|
|
246
|
+
], AutocompleteControllerElement.prototype, "starters", void 0);
|
|
247
|
+
__decorate([
|
|
248
|
+
property({ type: Boolean, attribute: 'is-send-disabled' })
|
|
249
|
+
], AutocompleteControllerElement.prototype, "isSendDisabled", void 0);
|
|
250
|
+
__decorate([
|
|
251
|
+
state()
|
|
252
|
+
], AutocompleteControllerElement.prototype, "_state", void 0);
|
|
253
|
+
__decorate([
|
|
254
|
+
state()
|
|
255
|
+
], AutocompleteControllerElement.prototype, "_listNavigated", void 0);
|
|
256
|
+
AutocompleteControllerElement = __decorate([
|
|
257
|
+
carbonElement(`${prefix}-autocomplete-controller`)
|
|
258
|
+
], AutocompleteControllerElement);
|
|
259
|
+
var AutocompleteControllerElement_default = AutocompleteControllerElement;
|
|
260
|
+
|
|
261
|
+
export { AutocompleteControllerElement_default as default };
|
|
262
|
+
//# 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 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-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 * @fires cds-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-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.addEventListener(\n 'cds-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-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.removeEventListener(\n 'cds-aichat-autocomplete-navigated',\n this._handleAutocompleteNavigated as EventListener\n );\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 // 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-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-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-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 _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-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-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;;Y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,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;AAQnE,UAAA,CAAA;AADP,IAAA,KAAK;AACyB,CAAA,EAAA,6BAAA,CAAA,SAAA,EAAA,gBAAA,EAAA,MAAA,CAAA;AA9B3B,6BAA6B,GAAA,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-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;
|