@carbon/ai-chat-components 1.12.0-rc.0 → 1.12.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 +7789 -7657
- 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/src/autocomplete-controller-element.d.ts +16 -0
- package/es/components/prompt-line/src/autocomplete-controller-element.js +41 -0
- package/es/components/prompt-line/src/autocomplete-controller-element.js.map +1 -1
- package/es/components/prompt-line/src/autocomplete-controller.js +13 -0
- package/es/components/prompt-line/src/autocomplete-controller.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/carbon-autocomplete.js +20 -20
- package/es/components/prompt-line/src/tiptap/carbon-autocomplete.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/carbon-mention.js +1 -1
- package/es/components/prompt-line/src/tiptap/carbon-mention.js.map +1 -1
- 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/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-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/src/autocomplete-controller-element.d.ts +16 -0
- package/es-custom/components/prompt-line/src/autocomplete-controller-element.js +41 -0
- package/es-custom/components/prompt-line/src/autocomplete-controller-element.js.map +1 -1
- package/es-custom/components/prompt-line/src/autocomplete-controller.js +13 -0
- package/es-custom/components/prompt-line/src/autocomplete-controller.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/carbon-autocomplete.js +20 -20
- 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 +1 -1
- package/es-custom/components/prompt-line/src/tiptap/carbon-mention.js.map +1 -1
- 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/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/package.json +2 -2
- package/telemetry.yml +3 -0
|
@@ -17,6 +17,7 @@ function useChatAutocomplete(options) {
|
|
|
17
17
|
trigger: null,
|
|
18
18
|
items: [],
|
|
19
19
|
});
|
|
20
|
+
const [isListNavigated, setIsListNavigated] = React.useState(false);
|
|
20
21
|
// Keep the controller stable for the hook's lifetime — set in a layout
|
|
21
22
|
// effect so it's wired before any event handler can fire.
|
|
22
23
|
const controllerRef = React.useRef(null);
|
|
@@ -84,7 +85,13 @@ function useChatAutocomplete(options) {
|
|
|
84
85
|
// Register / unregister the rendered list element with the controller so
|
|
85
86
|
// arrow / Enter / Escape on the editor DOM get forwarded to it.
|
|
86
87
|
// Also set the max-height CSS variable if provided.
|
|
88
|
+
const navigatedListenerRef = React.useRef(null);
|
|
87
89
|
const setListElement = React.useCallback((el) => {
|
|
90
|
+
// Remove the previous navigation listener before swapping elements.
|
|
91
|
+
if (navigatedListenerRef.current) {
|
|
92
|
+
navigatedListenerRef.current.el.removeEventListener('cds-aichat-autocomplete-navigated', navigatedListenerRef.current.handler);
|
|
93
|
+
navigatedListenerRef.current = null;
|
|
94
|
+
}
|
|
88
95
|
controllerRef.current?.setListElement(el);
|
|
89
96
|
// Pass the editor DOM as anchorElement so outside-click detection on the
|
|
90
97
|
// autocomplete element doesn't dismiss the list when the user clicks the
|
|
@@ -96,6 +103,24 @@ function useChatAutocomplete(options) {
|
|
|
96
103
|
if (el && maxHeight) {
|
|
97
104
|
el.style.setProperty('--cds-aichat-autocomplete-max-height', maxHeight);
|
|
98
105
|
}
|
|
106
|
+
if (el) {
|
|
107
|
+
const handler = (e) => {
|
|
108
|
+
setIsListNavigated(e.detail
|
|
109
|
+
.navigated);
|
|
110
|
+
};
|
|
111
|
+
el.addEventListener('cds-aichat-autocomplete-navigated', handler);
|
|
112
|
+
navigatedListenerRef.current = { el, handler };
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
setIsListNavigated(false);
|
|
116
|
+
// Fire a synthetic clear event on the prompt-line's shell ancestor so
|
|
117
|
+
// the send-control's internal guard (`_autocompleteListNavigated`) also
|
|
118
|
+
// resets. This covers cases where the list is removed from the DOM
|
|
119
|
+
// without the autocomplete element dispatching its own clear event
|
|
120
|
+
// (e.g. the user deletes the trigger character).
|
|
121
|
+
const shell = promptLineRef.current?.closest('cds-aichat-prompt-line-shell');
|
|
122
|
+
shell?.dispatchEvent(new CustomEvent('cds-aichat-autocomplete-navigated', { detail: { navigated: false }, bubbles: false, composed: false }));
|
|
123
|
+
}
|
|
99
124
|
}, [maxHeight, promptLineRef]);
|
|
100
125
|
// Prevent mousedown on the autocomplete container from stealing focus from
|
|
101
126
|
// the editor.
|
|
@@ -133,7 +158,7 @@ function useChatAutocomplete(options) {
|
|
|
133
158
|
attached,
|
|
134
159
|
handleContainerMousedown,
|
|
135
160
|
]);
|
|
136
|
-
return { onTriggerChange, autocompleteContent };
|
|
161
|
+
return { onTriggerChange, autocompleteContent, isListNavigated };
|
|
137
162
|
}
|
|
138
163
|
/** Mounts a host-provided HTMLElement into the React tree at `slot`. */
|
|
139
164
|
function CustomElementHost({ slot, element, onMount, onMousedown, }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useChatAutocomplete.js","sources":["../../../src/react/hooks/useChatAutocomplete.tsx"],"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\n/**\n * React hook for the chat-input autocomplete overlay. Thin wrapper around\n * the framework-agnostic `AutocompleteController` in\n * [../../components/prompt-line/src/autocomplete-controller.ts]. That module\n * holds no Lit and registers no custom element, so reaching the controller\n * costs this hook neither. It still loads `<cds-aichat-autocomplete>` — it\n * renders that list itself — but never\n * `<cds-aichat-autocomplete-controller>`, the other surface on the same\n * class. The controller owns\n * trigger handling, async resolution, and selection routing; this hook\n * adapts those callbacks into React state and returns a JSX node to slot\n * into `<PromptLineShell>`.\n */\n\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport type { JSX, ReactNode, RefObject } from 'react';\n\nimport Autocomplete from '../autocomplete.js';\nimport type PromptLineElement from '../../components/prompt-line/src/prompt-line.js';\nimport {\n AutocompleteController,\n itemsToGroups,\n type AutocompleteControllerState,\n} from '../../components/prompt-line/src/autocomplete-controller.js';\nimport type {\n AutocompleteConfig,\n StartersConfig,\n SuggestionItem,\n TriggerChangeEventDetail,\n TriggerSuggestionConfig,\n} from '../../components/prompt-line/src/tiptap/types.js';\n\nexport interface UseChatAutocompleteOptions {\n mention?: TriggerSuggestionConfig;\n command?: TriggerSuggestionConfig;\n autocomplete?: AutocompleteConfig;\n starters?: StartersConfig;\n /** Ref to the slotted `<cds-aichat-prompt-line>`. */\n promptLineRef: RefObject<PromptLineElement | null>;\n /** When true, starter selection inserts the text but does not auto-send. */\n isSendDisabled?: boolean;\n /** Fired after a starter is selected and inserted (used to trigger send). */\n onStarterSelected?: (text: string) => void;\n /**\n * Fired when an autocomplete suggestion item is selected.\n * Called after the controller has already inserted the item.\n */\n onSelectItem?: (item: SuggestionItem) => void;\n /**\n * Fired when the send button inside an autocomplete suggestion item is clicked.\n */\n onSendItem?: (text: string) => void;\n /** Whether the autocomplete is attached to the input (affects corner rounding). */\n attached?: boolean;\n /** Maximum height for the autocomplete popover */\n maxHeight?: string;\n}\n\nexport interface UseChatAutocompleteResult {\n /** Attach to `<PromptLine onTriggerChange={...} />`. */\n onTriggerChange: (\n event: CustomEvent<TriggerChangeEventDetail | null>\n ) => void;\n /**\n * JSX to render with `slot=\"autocomplete-content\"` inside `<PromptLineShell>`.\n * `null` while no trigger is active.\n */\n autocompleteContent: ReactNode;\n}\n\nexport function useChatAutocomplete(\n options: UseChatAutocompleteOptions\n): UseChatAutocompleteResult {\n const {\n mention,\n command,\n autocomplete,\n starters,\n promptLineRef,\n isSendDisabled,\n onStarterSelected,\n onSelectItem,\n onSendItem,\n attached = true,\n maxHeight,\n } = options;\n\n const [state, setState] = React.useState<AutocompleteControllerState>({\n trigger: null,\n items: [],\n });\n\n // Keep the controller stable for the hook's lifetime — set in a layout\n // effect so it's wired before any event handler can fire.\n const controllerRef = React.useRef<AutocompleteController | null>(null);\n // Latest config / callback values; the controller stores its own copies\n // but reading them out of refs avoids re-instantiation churn.\n const onStarterRef = React.useRef(onStarterSelected);\n onStarterRef.current = onStarterSelected;\n const onSelectItemRef = React.useRef(onSelectItem);\n onSelectItemRef.current = onSelectItem;\n const onSendItemRef = React.useRef(onSendItem);\n onSendItemRef.current = onSendItem;\n\n if (!controllerRef.current) {\n controllerRef.current = new AutocompleteController({\n mention,\n command,\n autocomplete,\n starters,\n isSendDisabled,\n onStarterSelected: (text) => onStarterRef.current?.(text),\n onChange: setState,\n });\n }\n\n // Push prop changes into the controller without recreating it.\n React.useEffect(() => {\n controllerRef.current?.setConfigs({\n mention,\n command,\n autocomplete,\n starters,\n isSendDisabled,\n });\n }, [mention, command, autocomplete, starters, isSendDisabled]);\n\n // Keep the controller pointed at the live prompt-line element.\n React.useEffect(() => {\n controllerRef.current?.setPromptLine(promptLineRef.current);\n });\n\n React.useEffect(() => {\n return () => {\n controllerRef.current?.destroy();\n controllerRef.current = null;\n };\n }, []);\n\n const onTriggerChange = React.useCallback(\n (event: CustomEvent<TriggerChangeEventDetail | null>) => {\n // Pin the controller to the current prompt-line ref before handing\n // off the detail — the React caller's ref is authoritative.\n controllerRef.current?.setPromptLine(promptLineRef.current);\n controllerRef.current?.handleTriggerChange(event.detail ?? null);\n },\n [promptLineRef]\n );\n\n const handleSelect = React.useCallback((item: SuggestionItem) => {\n controllerRef.current?.select(item);\n onSelectItemRef.current?.(item);\n }, []);\n\n const isSendDisabledRef = React.useRef(isSendDisabled);\n isSendDisabledRef.current = isSendDisabled;\n\n const handleSend = React.useCallback((text: string) => {\n if (!text || isSendDisabledRef.current) {\n return;\n }\n controllerRef.current?.dismiss(true);\n onSendItemRef.current?.(text);\n }, []);\n\n const dismiss = React.useCallback(() => {\n controllerRef.current?.dismiss();\n }, []);\n\n // Register / unregister the rendered list element with the controller so\n // arrow / Enter / Escape on the editor DOM get forwarded to it.\n // Also set the max-height CSS variable if provided.\n const setListElement = React.useCallback(\n (el: HTMLElement | null) => {\n controllerRef.current?.setListElement(el);\n // Pass the editor DOM as anchorElement so outside-click detection on the\n // autocomplete element doesn't dismiss the list when the user clicks the\n // editor (the editor is not inside the autocomplete element).\n if (el && 'anchorElement' in el) {\n (el as HTMLElement & { anchorElement: Element | null }).anchorElement =\n promptLineRef.current?.getEditor?.()?.view.dom ?? null;\n }\n if (el && maxHeight) {\n el.style.setProperty('--cds-aichat-autocomplete-max-height', maxHeight);\n }\n },\n [maxHeight, promptLineRef]\n );\n\n // Prevent mousedown on the autocomplete container from stealing focus from\n // the editor.\n const handleContainerMousedown = React.useCallback(\n (e: Event | React.MouseEvent) => {\n e.preventDefault();\n },\n []\n );\n\n const autocompleteContent = React.useMemo<ReactNode>(() => {\n if (!state.trigger || state.items.length === 0) {\n return null;\n }\n const { items: flatItems, groups } = itemsToGroups(state.items);\n if (state.renderCustomList) {\n const result = state.renderCustomList({\n items: state.items,\n query: state.trigger.query,\n onDismiss: dismiss,\n onSelect: handleSelect,\n onSend: handleSend,\n });\n if (result == null) {\n return null;\n }\n if (result instanceof HTMLElement) {\n return (\n <CustomElementHost\n slot=\"autocomplete-content\"\n element={result}\n onMount={setListElement}\n onMousedown={handleContainerMousedown}\n />\n );\n }\n return (\n <CustomReactNodePortal\n slot=\"autocomplete-content\"\n node={result as ReactNode}\n onMount={setListElement}\n onMousedown={handleContainerMousedown}\n />\n );\n }\n return (\n <Autocomplete\n ref={setListElement}\n slot=\"autocomplete-content\"\n items={flatItems}\n groups={groups}\n attached={attached}\n disableDirectSend={state.disableDirectSend}\n onDismiss={dismiss}\n onSelect={(e: CustomEvent<{ item: SuggestionItem }>) =>\n handleSelect(e.detail.item)\n }\n onSend={(e: CustomEvent<{ text: string }>) =>\n handleSend(e.detail?.text)\n }\n />\n );\n }, [\n state,\n handleSelect,\n handleSend,\n dismiss,\n setListElement,\n attached,\n handleContainerMousedown,\n ]);\n\n return { onTriggerChange, autocompleteContent };\n}\n\ninterface CustomElementHostProps {\n slot: string;\n element: HTMLElement;\n /** Notify the parent which element is the key-forwarding target. */\n onMount?: (el: HTMLElement | null) => void;\n onMousedown?: (e: React.MouseEvent) => void;\n}\n\n/** Mounts a host-provided HTMLElement into the React tree at `slot`. */\nfunction CustomElementHost({\n slot,\n element,\n onMount,\n onMousedown,\n}: CustomElementHostProps): JSX.Element {\n const containerRef = React.useRef<HTMLDivElement | null>(null);\n React.useEffect(() => {\n const container = containerRef.current;\n if (!container) {\n return undefined;\n }\n container.appendChild(element);\n onMount?.(element);\n return () => {\n onMount?.(null);\n if (element.parentNode === container) {\n container.removeChild(element);\n }\n };\n }, [element, onMount]);\n return (\n <div\n ref={containerRef}\n role=\"presentation\"\n slot={slot}\n onMouseDown={onMousedown}\n />\n );\n}\n\ninterface CustomReactNodePortalProps {\n slot: string;\n node: ReactNode;\n onMount?: (el: HTMLElement | null) => void;\n onMousedown?: (e: MouseEvent) => void;\n}\n\nlet autocompletePortalCounter = 0;\n\n/**\n * Projects a consumer-supplied React node into the page's light DOM via a\n * two-level slot/host pair so external `<style>` tags reach it. The rendered\n * `<div>` is a slot-projected anchor in the shell's `autocomplete-content`\n * slot; a sibling `<div slot=\"…\">` is appended to the chatWrapper (the host\n * of the surrounding shadow root) and receives the React node via\n * `createPortal`. Without this hop the node would mount inside the chat's\n * shadow root, hidden from page CSS.\n */\nfunction CustomReactNodePortal({\n slot,\n node,\n onMount,\n onMousedown,\n}: CustomReactNodePortalProps): JSX.Element {\n const containerRef = React.useRef<HTMLDivElement | null>(null);\n const [hostElement, setHostElement] = React.useState<HTMLElement | null>(\n null\n );\n\n React.useEffect(() => {\n const container = containerRef.current;\n if (!container) {\n return undefined;\n }\n const rootNode = container.getRootNode();\n const chatWrapper =\n rootNode instanceof ShadowRoot ? (rootNode.host as HTMLElement) : null;\n if (!chatWrapper) {\n return undefined;\n }\n\n const slotName = `cds-aichat-autocomplete-${++autocompletePortalCounter}`;\n const slotEl = document.createElement('slot');\n slotEl.setAttribute('name', slotName);\n container.appendChild(slotEl);\n\n const hostEl = document.createElement('div');\n hostEl.setAttribute('slot', slotName);\n if (onMousedown) {\n hostEl.addEventListener('mousedown', onMousedown);\n }\n chatWrapper.appendChild(hostEl);\n\n setHostElement(hostEl);\n return () => {\n onMount?.(null);\n if (onMousedown) {\n hostEl.removeEventListener('mousedown', onMousedown);\n }\n slotEl.remove();\n hostEl.remove();\n setHostElement(null);\n };\n // Empty deps: the slot/host pair is owned by this mount cycle and should\n // not churn as `node` updates — React's portal reconciliation handles\n // those updates in place.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // After the portal content is committed into hostElement, hand the first\n // child element to the controller. This is typically a custom element (e.g.\n // <cds-aichat-autocomplete>) whose properties (anchorElement, keydown\n // forwarding) only work on the element itself — not on the plain <div>\n // wrapper that createPortal renders into. Custom elements are defined\n // synchronously at module load, so by the time useEffect fires (post-paint)\n // the element is fully upgraded and its properties are available.\n React.useEffect(() => {\n if (!hostElement) {\n return;\n }\n const child = hostElement.firstElementChild as HTMLElement | null;\n onMount?.(child ?? hostElement);\n }, [hostElement, onMount]);\n\n return (\n <div slot={slot} ref={containerRef}>\n {hostElement ? ReactDOM.createPortal(node, hostElement) : null}\n </div>\n );\n}\n"],"names":["_jsx","Autocomplete"],"mappings":";;;;;;;;;;;;;AAgFM,SAAU,mBAAmB,CACjC,OAAmC,EAAA;IAEnC,MAAM,EACJ,OAAO,EACP,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,UAAU,EACV,QAAQ,GAAG,IAAI,EACf,SAAS,GACV,GAAG,OAAO;IAEX,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,CAA8B;AACpE,QAAA,OAAO,EAAE,IAAI;AACb,QAAA,KAAK,EAAE,EAAE;AACV,KAAA,CAAC;;;IAIF,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAgC,IAAI,CAAC;;;IAGvE,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAC,iBAAiB,CAAC;AACpD,IAAA,YAAY,CAAC,OAAO,GAAG,iBAAiB;IACxC,MAAM,eAAe,GAAG,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC;AAClD,IAAA,eAAe,CAAC,OAAO,GAAG,YAAY;IACtC,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC;AAC9C,IAAA,aAAa,CAAC,OAAO,GAAG,UAAU;AAElC,IAAA,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE;AAC1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WAAW,EAAE,WAAW,CAAC;YACtD;YACA,MAAM,CAAC,MAAM,EAAE;YACf,MAAM,CAAC,MAAM,EAAE;YACf,cAAc,CAAC,IAAI,CAAC;AACtB,QAAA,CAAC;;;;;IAKH,CAAC,EAAE,EAAE,CAAC;;;;;;;;AASN,IAAA,KAAK,CAAC,SAAS,CAAC,MAAK;QACnB,IAAI,CAAC,WAAW,EAAE;YAChB;QACF;AACA,QAAA,MAAM,KAAK,GAAG,WAAW,CAAC,iBAAuC;AACjE,QAAA,OAAO,GAAG,KAAK,IAAI,WAAW,CAAC;AACjC,IAAA,CAAC,EAAE,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAE1B,IAAA,QACEA,GAAA,CAAA,KAAA,EAAA,EAAK,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAA,QAAA,EAC/B,WAAW,GAAG,QAAQ,CAAC,YAAY,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG,IAAI,EAAA,CAC1D;AAEV;;"}
|
|
1
|
+
{"version":3,"file":"useChatAutocomplete.js","sources":["../../../src/react/hooks/useChatAutocomplete.tsx"],"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\n/**\n * React hook for the chat-input autocomplete overlay. Thin wrapper around\n * the framework-agnostic `AutocompleteController` in\n * [../../components/prompt-line/src/autocomplete-controller.ts]. That module\n * holds no Lit and registers no custom element, so reaching the controller\n * costs this hook neither. It still loads `<cds-aichat-autocomplete>` — it\n * renders that list itself — but never\n * `<cds-aichat-autocomplete-controller>`, the other surface on the same\n * class. The controller owns\n * trigger handling, async resolution, and selection routing; this hook\n * adapts those callbacks into React state and returns a JSX node to slot\n * into `<PromptLineShell>`.\n */\n\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport type { JSX, ReactNode, RefObject } from 'react';\n\nimport Autocomplete from '../autocomplete.js';\nimport type PromptLineElement from '../../components/prompt-line/src/prompt-line.js';\nimport {\n AutocompleteController,\n itemsToGroups,\n type AutocompleteControllerState,\n} from '../../components/prompt-line/src/autocomplete-controller.js';\nimport type { AutocompleteNavigatedEventDetail } from '../../components/prompt-line/autocomplete/src/autocomplete.js';\nimport type {\n AutocompleteConfig,\n StartersConfig,\n SuggestionItem,\n TriggerChangeEventDetail,\n TriggerSuggestionConfig,\n} from '../../components/prompt-line/src/tiptap/types.js';\n\nexport interface UseChatAutocompleteOptions {\n mention?: TriggerSuggestionConfig;\n command?: TriggerSuggestionConfig;\n autocomplete?: AutocompleteConfig;\n starters?: StartersConfig;\n /** Ref to the slotted `<cds-aichat-prompt-line>`. */\n promptLineRef: RefObject<PromptLineElement | null>;\n /** When true, starter selection inserts the text but does not auto-send. */\n isSendDisabled?: boolean;\n /** Fired after a starter is selected and inserted (used to trigger send). */\n onStarterSelected?: (text: string) => void;\n /**\n * Fired when an autocomplete suggestion item is selected.\n * Called after the controller has already inserted the item.\n */\n onSelectItem?: (item: SuggestionItem) => void;\n /**\n * Fired when the send button inside an autocomplete suggestion item is clicked.\n */\n onSendItem?: (text: string) => void;\n /** Whether the autocomplete is attached to the input (affects corner rounding). */\n attached?: boolean;\n /** Maximum height for the autocomplete popover */\n maxHeight?: string;\n}\n\nexport interface UseChatAutocompleteResult {\n /** Attach to `<PromptLine onTriggerChange={...} />`. */\n onTriggerChange: (\n event: CustomEvent<TriggerChangeEventDetail | null>\n ) => void;\n /**\n * JSX to render with `slot=\"autocomplete-content\"` inside `<PromptLineShell>`.\n * `null` while no trigger is active.\n */\n autocompleteContent: ReactNode;\n /**\n * `true` while the user has navigated into the autocomplete list with arrow\n * keys. Use to disable the prompt send button while a list item is active.\n */\n isListNavigated: boolean;\n}\n\nexport function useChatAutocomplete(\n options: UseChatAutocompleteOptions\n): UseChatAutocompleteResult {\n const {\n mention,\n command,\n autocomplete,\n starters,\n promptLineRef,\n isSendDisabled,\n onStarterSelected,\n onSelectItem,\n onSendItem,\n attached = true,\n maxHeight,\n } = options;\n\n const [state, setState] = React.useState<AutocompleteControllerState>({\n trigger: null,\n items: [],\n });\n\n const [isListNavigated, setIsListNavigated] = React.useState(false);\n\n // Keep the controller stable for the hook's lifetime — set in a layout\n // effect so it's wired before any event handler can fire.\n const controllerRef = React.useRef<AutocompleteController | null>(null);\n // Latest config / callback values; the controller stores its own copies\n // but reading them out of refs avoids re-instantiation churn.\n const onStarterRef = React.useRef(onStarterSelected);\n onStarterRef.current = onStarterSelected;\n const onSelectItemRef = React.useRef(onSelectItem);\n onSelectItemRef.current = onSelectItem;\n const onSendItemRef = React.useRef(onSendItem);\n onSendItemRef.current = onSendItem;\n\n if (!controllerRef.current) {\n controllerRef.current = new AutocompleteController({\n mention,\n command,\n autocomplete,\n starters,\n isSendDisabled,\n onStarterSelected: (text) => onStarterRef.current?.(text),\n onChange: setState,\n });\n }\n\n // Push prop changes into the controller without recreating it.\n React.useEffect(() => {\n controllerRef.current?.setConfigs({\n mention,\n command,\n autocomplete,\n starters,\n isSendDisabled,\n });\n }, [mention, command, autocomplete, starters, isSendDisabled]);\n\n // Keep the controller pointed at the live prompt-line element.\n React.useEffect(() => {\n controllerRef.current?.setPromptLine(promptLineRef.current);\n });\n\n React.useEffect(() => {\n return () => {\n controllerRef.current?.destroy();\n controllerRef.current = null;\n };\n }, []);\n\n const onTriggerChange = React.useCallback(\n (event: CustomEvent<TriggerChangeEventDetail | null>) => {\n // Pin the controller to the current prompt-line ref before handing\n // off the detail — the React caller's ref is authoritative.\n controllerRef.current?.setPromptLine(promptLineRef.current);\n controllerRef.current?.handleTriggerChange(event.detail ?? null);\n },\n [promptLineRef]\n );\n\n const handleSelect = React.useCallback((item: SuggestionItem) => {\n controllerRef.current?.select(item);\n onSelectItemRef.current?.(item);\n }, []);\n\n const isSendDisabledRef = React.useRef(isSendDisabled);\n isSendDisabledRef.current = isSendDisabled;\n\n const handleSend = React.useCallback((text: string) => {\n if (!text || isSendDisabledRef.current) {\n return;\n }\n controllerRef.current?.dismiss(true);\n onSendItemRef.current?.(text);\n }, []);\n\n const dismiss = React.useCallback(() => {\n controllerRef.current?.dismiss();\n }, []);\n\n // Register / unregister the rendered list element with the controller so\n // arrow / Enter / Escape on the editor DOM get forwarded to it.\n // Also set the max-height CSS variable if provided.\n const navigatedListenerRef = React.useRef<{\n el: HTMLElement;\n handler: (e: Event) => void;\n } | null>(null);\n\n const setListElement = React.useCallback(\n (el: HTMLElement | null) => {\n // Remove the previous navigation listener before swapping elements.\n if (navigatedListenerRef.current) {\n navigatedListenerRef.current.el.removeEventListener(\n 'cds-aichat-autocomplete-navigated',\n navigatedListenerRef.current.handler\n );\n navigatedListenerRef.current = null;\n }\n\n controllerRef.current?.setListElement(el);\n // Pass the editor DOM as anchorElement so outside-click detection on the\n // autocomplete element doesn't dismiss the list when the user clicks the\n // editor (the editor is not inside the autocomplete element).\n if (el && 'anchorElement' in el) {\n (el as HTMLElement & { anchorElement: Element | null }).anchorElement =\n promptLineRef.current?.getEditor?.()?.view.dom ?? null;\n }\n if (el && maxHeight) {\n el.style.setProperty('--cds-aichat-autocomplete-max-height', maxHeight);\n }\n if (el) {\n const handler = (e: Event) => {\n setIsListNavigated(\n (e as CustomEvent<AutocompleteNavigatedEventDetail>).detail\n .navigated\n );\n };\n el.addEventListener('cds-aichat-autocomplete-navigated', handler);\n navigatedListenerRef.current = { el, handler };\n } else {\n setIsListNavigated(false);\n // Fire a synthetic clear event on the prompt-line's shell ancestor so\n // the send-control's internal guard (`_autocompleteListNavigated`) also\n // resets. This covers cases where the list is removed from the DOM\n // without the autocomplete element dispatching its own clear event\n // (e.g. the user deletes the trigger character).\n const shell = promptLineRef.current?.closest(\n 'cds-aichat-prompt-line-shell'\n );\n shell?.dispatchEvent(\n new CustomEvent<AutocompleteNavigatedEventDetail>(\n 'cds-aichat-autocomplete-navigated',\n { detail: { navigated: false }, bubbles: false, composed: false }\n )\n );\n }\n },\n [maxHeight, promptLineRef]\n );\n\n // Prevent mousedown on the autocomplete container from stealing focus from\n // the editor.\n const handleContainerMousedown = React.useCallback(\n (e: Event | React.MouseEvent) => {\n e.preventDefault();\n },\n []\n );\n\n const autocompleteContent = React.useMemo<ReactNode>(() => {\n if (!state.trigger || state.items.length === 0) {\n return null;\n }\n const { items: flatItems, groups } = itemsToGroups(state.items);\n if (state.renderCustomList) {\n const result = state.renderCustomList({\n items: state.items,\n query: state.trigger.query,\n onDismiss: dismiss,\n onSelect: handleSelect,\n onSend: handleSend,\n });\n if (result == null) {\n return null;\n }\n if (result instanceof HTMLElement) {\n return (\n <CustomElementHost\n slot=\"autocomplete-content\"\n element={result}\n onMount={setListElement}\n onMousedown={handleContainerMousedown}\n />\n );\n }\n return (\n <CustomReactNodePortal\n slot=\"autocomplete-content\"\n node={result as ReactNode}\n onMount={setListElement}\n onMousedown={handleContainerMousedown}\n />\n );\n }\n return (\n <Autocomplete\n ref={setListElement}\n slot=\"autocomplete-content\"\n items={flatItems}\n groups={groups}\n attached={attached}\n disableDirectSend={state.disableDirectSend}\n onDismiss={dismiss}\n onSelect={(e: CustomEvent<{ item: SuggestionItem }>) =>\n handleSelect(e.detail.item)\n }\n onSend={(e: CustomEvent<{ text: string }>) =>\n handleSend(e.detail?.text)\n }\n />\n );\n }, [\n state,\n handleSelect,\n handleSend,\n dismiss,\n setListElement,\n attached,\n handleContainerMousedown,\n ]);\n\n return { onTriggerChange, autocompleteContent, isListNavigated };\n}\n\ninterface CustomElementHostProps {\n slot: string;\n element: HTMLElement;\n /** Notify the parent which element is the key-forwarding target. */\n onMount?: (el: HTMLElement | null) => void;\n onMousedown?: (e: React.MouseEvent) => void;\n}\n\n/** Mounts a host-provided HTMLElement into the React tree at `slot`. */\nfunction CustomElementHost({\n slot,\n element,\n onMount,\n onMousedown,\n}: CustomElementHostProps): JSX.Element {\n const containerRef = React.useRef<HTMLDivElement | null>(null);\n React.useEffect(() => {\n const container = containerRef.current;\n if (!container) {\n return undefined;\n }\n container.appendChild(element);\n onMount?.(element);\n return () => {\n onMount?.(null);\n if (element.parentNode === container) {\n container.removeChild(element);\n }\n };\n }, [element, onMount]);\n return (\n <div\n ref={containerRef}\n role=\"presentation\"\n slot={slot}\n onMouseDown={onMousedown}\n />\n );\n}\n\ninterface CustomReactNodePortalProps {\n slot: string;\n node: ReactNode;\n onMount?: (el: HTMLElement | null) => void;\n onMousedown?: (e: MouseEvent) => void;\n}\n\nlet autocompletePortalCounter = 0;\n\n/**\n * Projects a consumer-supplied React node into the page's light DOM via a\n * two-level slot/host pair so external `<style>` tags reach it. The rendered\n * `<div>` is a slot-projected anchor in the shell's `autocomplete-content`\n * slot; a sibling `<div slot=\"…\">` is appended to the chatWrapper (the host\n * of the surrounding shadow root) and receives the React node via\n * `createPortal`. Without this hop the node would mount inside the chat's\n * shadow root, hidden from page CSS.\n */\nfunction CustomReactNodePortal({\n slot,\n node,\n onMount,\n onMousedown,\n}: CustomReactNodePortalProps): JSX.Element {\n const containerRef = React.useRef<HTMLDivElement | null>(null);\n const [hostElement, setHostElement] = React.useState<HTMLElement | null>(\n null\n );\n\n React.useEffect(() => {\n const container = containerRef.current;\n if (!container) {\n return undefined;\n }\n const rootNode = container.getRootNode();\n const chatWrapper =\n rootNode instanceof ShadowRoot ? (rootNode.host as HTMLElement) : null;\n if (!chatWrapper) {\n return undefined;\n }\n\n const slotName = `cds-aichat-autocomplete-${++autocompletePortalCounter}`;\n const slotEl = document.createElement('slot');\n slotEl.setAttribute('name', slotName);\n container.appendChild(slotEl);\n\n const hostEl = document.createElement('div');\n hostEl.setAttribute('slot', slotName);\n if (onMousedown) {\n hostEl.addEventListener('mousedown', onMousedown);\n }\n chatWrapper.appendChild(hostEl);\n\n setHostElement(hostEl);\n return () => {\n onMount?.(null);\n if (onMousedown) {\n hostEl.removeEventListener('mousedown', onMousedown);\n }\n slotEl.remove();\n hostEl.remove();\n setHostElement(null);\n };\n // Empty deps: the slot/host pair is owned by this mount cycle and should\n // not churn as `node` updates — React's portal reconciliation handles\n // those updates in place.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // After the portal content is committed into hostElement, hand the first\n // child element to the controller. This is typically a custom element (e.g.\n // <cds-aichat-autocomplete>) whose properties (anchorElement, keydown\n // forwarding) only work on the element itself — not on the plain <div>\n // wrapper that createPortal renders into. Custom elements are defined\n // synchronously at module load, so by the time useEffect fires (post-paint)\n // the element is fully upgraded and its properties are available.\n React.useEffect(() => {\n if (!hostElement) {\n return;\n }\n const child = hostElement.firstElementChild as HTMLElement | null;\n onMount?.(child ?? hostElement);\n }, [hostElement, onMount]);\n\n return (\n <div slot={slot} ref={containerRef}>\n {hostElement ? ReactDOM.createPortal(node, hostElement) : null}\n </div>\n );\n}\n"],"names":["_jsx","Autocomplete"],"mappings":";;;;;;;;;;;;;AAsFM,SAAU,mBAAmB,CACjC,OAAmC,EAAA;IAEnC,MAAM,EACJ,OAAO,EACP,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,UAAU,EACV,QAAQ,GAAG,IAAI,EACf,SAAS,GACV,GAAG,OAAO;IAEX,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,CAA8B;AACpE,QAAA,OAAO,EAAE,IAAI;AACb,QAAA,KAAK,EAAE,EAAE;AACV,KAAA,CAAC;AAEF,IAAA,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;;;IAInE,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAgC,IAAI,CAAC;;;IAGvE,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAC,iBAAiB,CAAC;AACpD,IAAA,YAAY,CAAC,OAAO,GAAG,iBAAiB;IACxC,MAAM,eAAe,GAAG,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC;AAClD,IAAA,eAAe,CAAC,OAAO,GAAG,YAAY;IACtC,MAAM,aAAa,GAAG,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,CAAC,WAAW,EAAE;YAChB;QACF;AACA,QAAA,MAAM,KAAK,GAAG,WAAW,CAAC,iBAAuC;AACjE,QAAA,OAAO,GAAG,KAAK,IAAI,WAAW,CAAC;AACjC,IAAA,CAAC,EAAE,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAE1B,IAAA,QACEA,GAAA,CAAA,KAAA,EAAA,EAAK,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAA,QAAA,EAC/B,WAAW,GAAG,QAAQ,CAAC,YAAY,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG,IAAI,EAAA,CAC1D;AAEV;;"}
|
|
@@ -9,4 +9,4 @@
|
|
|
9
9
|
import './src/autocomplete.js';
|
|
10
10
|
export { default as AutocompleteElement } from './src/autocomplete.js';
|
|
11
11
|
export { defaultAutocompleteI18n } from './src/autocomplete.js';
|
|
12
|
-
export type { HeaderConfig, AutocompleteI18n, AutocompleteSelectEventDetail, AutocompleteSendEventDetail, SuggestionItem, SuggestionItemGroup, } from './src/autocomplete.js';
|
|
12
|
+
export type { HeaderConfig, AutocompleteI18n, AutocompleteSelectEventDetail, AutocompleteSendEventDetail, AutocompleteNavigatedEventDetail, SuggestionItem, SuggestionItemGroup, } from './src/autocomplete.js';
|
|
@@ -76,6 +76,9 @@ export interface AutocompleteSelectEventDetail {
|
|
|
76
76
|
export interface AutocompleteSendEventDetail {
|
|
77
77
|
text: string;
|
|
78
78
|
}
|
|
79
|
+
export interface AutocompleteNavigatedEventDetail {
|
|
80
|
+
navigated: boolean;
|
|
81
|
+
}
|
|
79
82
|
/**
|
|
80
83
|
* Autocomplete component for AI Chat input suggestions.
|
|
81
84
|
*
|
|
@@ -125,6 +128,8 @@ declare class AutocompleteElement extends LitElement {
|
|
|
125
128
|
* anchor element are treated as inside-clicks and do not dismiss the list.
|
|
126
129
|
*/
|
|
127
130
|
anchorElement: Element | null;
|
|
131
|
+
private _userHasNavigated;
|
|
132
|
+
private _setUserHasNavigated;
|
|
128
133
|
private _announcer;
|
|
129
134
|
private _listboxEl;
|
|
130
135
|
/**
|
|
@@ -136,6 +141,7 @@ declare class AutocompleteElement extends LitElement {
|
|
|
136
141
|
private _openAnnounced;
|
|
137
142
|
connectedCallback(): void;
|
|
138
143
|
disconnectedCallback(): void;
|
|
144
|
+
hasNavigated(): boolean;
|
|
139
145
|
firstUpdated(): void;
|
|
140
146
|
updated(changedProperties: Map<string, any>): void;
|
|
141
147
|
/**
|
|
@@ -88,7 +88,8 @@ let AutocompleteElement = class AutocompleteElement extends LitElement {
|
|
|
88
88
|
* Currently active item index
|
|
89
89
|
* @internal
|
|
90
90
|
*/
|
|
91
|
-
this._focusedIndex =
|
|
91
|
+
this._focusedIndex = -1;
|
|
92
|
+
this._userHasNavigated = false;
|
|
92
93
|
this._announcer = new AriaAnnouncerManager();
|
|
93
94
|
this._listboxEl = null;
|
|
94
95
|
/**
|
|
@@ -107,12 +108,14 @@ let AutocompleteElement = class AutocompleteElement extends LitElement {
|
|
|
107
108
|
case 'ArrowDown':
|
|
108
109
|
event.preventDefault();
|
|
109
110
|
this._focusedIndex = this._navigateTo(this._focusedIndex, 1);
|
|
111
|
+
this._setUserHasNavigated(true);
|
|
110
112
|
this._scheduleMoveAnnouncement(this._focusedIndex, totalItems);
|
|
111
113
|
this._scrollActiveItemIntoView();
|
|
112
114
|
break;
|
|
113
115
|
case 'ArrowUp':
|
|
114
116
|
event.preventDefault();
|
|
115
117
|
this._focusedIndex = this._navigateTo(this._focusedIndex, -1);
|
|
118
|
+
this._setUserHasNavigated(true);
|
|
116
119
|
this._scheduleMoveAnnouncement(this._focusedIndex, totalItems);
|
|
117
120
|
this._scrollActiveItemIntoView();
|
|
118
121
|
break;
|
|
@@ -124,6 +127,7 @@ let AutocompleteElement = class AutocompleteElement extends LitElement {
|
|
|
124
127
|
first++;
|
|
125
128
|
}
|
|
126
129
|
this._focusedIndex = first < totalItems ? first : this._focusedIndex;
|
|
130
|
+
this._setUserHasNavigated(true);
|
|
127
131
|
this._scheduleMoveAnnouncement(this._focusedIndex, totalItems);
|
|
128
132
|
this._scrollActiveItemIntoView();
|
|
129
133
|
break;
|
|
@@ -136,15 +140,26 @@ let AutocompleteElement = class AutocompleteElement extends LitElement {
|
|
|
136
140
|
last--;
|
|
137
141
|
}
|
|
138
142
|
this._focusedIndex = last >= 0 ? last : this._focusedIndex;
|
|
143
|
+
this._setUserHasNavigated(true);
|
|
139
144
|
this._scheduleMoveAnnouncement(this._focusedIndex, totalItems);
|
|
140
145
|
this._scrollActiveItemIntoView();
|
|
141
146
|
break;
|
|
142
147
|
}
|
|
148
|
+
case 'Tab':
|
|
149
|
+
event.preventDefault();
|
|
150
|
+
this._focusedIndex = this._navigateTo(this._focusedIndex, 1);
|
|
151
|
+
this._setUserHasNavigated(true);
|
|
152
|
+
this._scheduleMoveAnnouncement(this._focusedIndex, totalItems);
|
|
153
|
+
this._scrollActiveItemIntoView();
|
|
154
|
+
break;
|
|
143
155
|
case 'Escape':
|
|
144
156
|
event.preventDefault();
|
|
145
157
|
this._dismiss();
|
|
146
158
|
break;
|
|
147
159
|
case 'Enter':
|
|
160
|
+
if (!this._userHasNavigated) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
148
163
|
event.preventDefault();
|
|
149
164
|
this._handleItemClick(this._focusedIndex);
|
|
150
165
|
break;
|
|
@@ -170,6 +185,13 @@ let AutocompleteElement = class AutocompleteElement extends LitElement {
|
|
|
170
185
|
this._dismiss();
|
|
171
186
|
};
|
|
172
187
|
}
|
|
188
|
+
_setUserHasNavigated(value) {
|
|
189
|
+
if (this._userHasNavigated === value) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
this._userHasNavigated = value;
|
|
193
|
+
this.dispatchEvent(new CustomEvent('cds-custom-aichat-autocomplete-navigated', { detail: { navigated: value }, bubbles: true, composed: true }));
|
|
194
|
+
}
|
|
173
195
|
connectedCallback() {
|
|
174
196
|
super.connectedCallback();
|
|
175
197
|
this.addEventListener('keydown', this._handleKeydown);
|
|
@@ -186,6 +208,9 @@ let AutocompleteElement = class AutocompleteElement extends LitElement {
|
|
|
186
208
|
this._moveAnnouncePending = null;
|
|
187
209
|
}
|
|
188
210
|
}
|
|
211
|
+
hasNavigated() {
|
|
212
|
+
return this._userHasNavigated;
|
|
213
|
+
}
|
|
189
214
|
firstUpdated() {
|
|
190
215
|
const regions = this.renderRoot.querySelectorAll(`.${blockClass}__live-region`);
|
|
191
216
|
this._announcer.connect(Array.from(regions));
|
|
@@ -202,13 +227,8 @@ let AutocompleteElement = class AutocompleteElement extends LitElement {
|
|
|
202
227
|
this._openAnnounced = false;
|
|
203
228
|
return;
|
|
204
229
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
while (firstEnabled < totalItems &&
|
|
208
|
-
this._getItemAtIndex(firstEnabled)?.disabled) {
|
|
209
|
-
firstEnabled++;
|
|
210
|
-
}
|
|
211
|
-
this._focusedIndex = firstEnabled < totalItems ? firstEnabled : 0;
|
|
230
|
+
this._focusedIndex = -1;
|
|
231
|
+
this._setUserHasNavigated(false);
|
|
212
232
|
if (!this._openAnnounced) {
|
|
213
233
|
this._openAnnounced = true;
|
|
214
234
|
this._announcer.announce(this.i18n.suggestionsAvailable(totalItems));
|
|
@@ -247,14 +267,16 @@ let AutocompleteElement = class AutocompleteElement extends LitElement {
|
|
|
247
267
|
*/
|
|
248
268
|
_navigateTo(from, direction) {
|
|
249
269
|
const totalItems = this._getTotalItemCount();
|
|
250
|
-
|
|
270
|
+
// When no item is selected yet (-1), ArrowUp wraps to the last item.
|
|
271
|
+
const start = from === -1 && direction === -1 ? totalItems : from;
|
|
272
|
+
let next = start + direction;
|
|
251
273
|
while (next >= 0 && next < totalItems) {
|
|
252
274
|
if (!this._getItemAtIndex(next)?.disabled) {
|
|
253
275
|
return next;
|
|
254
276
|
}
|
|
255
277
|
next += direction;
|
|
256
278
|
}
|
|
257
|
-
// No enabled item found in that direction — stay put.
|
|
279
|
+
// No enabled item found in that direction — stay put (keep -1 if unnavigated).
|
|
258
280
|
return from;
|
|
259
281
|
}
|
|
260
282
|
/**
|
|
@@ -316,6 +338,7 @@ let AutocompleteElement = class AutocompleteElement extends LitElement {
|
|
|
316
338
|
}
|
|
317
339
|
_dismiss() {
|
|
318
340
|
this._openAnnounced = false;
|
|
341
|
+
this._setUserHasNavigated(false);
|
|
319
342
|
this._announcer.announce(this.i18n.suggestionsClosed);
|
|
320
343
|
this.dispatchEvent(new CustomEvent('cds-custom-aichat-autocomplete-dismiss', {
|
|
321
344
|
bubbles: true,
|
|
@@ -335,6 +358,9 @@ let AutocompleteElement = class AutocompleteElement extends LitElement {
|
|
|
335
358
|
this._selectItem(item);
|
|
336
359
|
}
|
|
337
360
|
_getActiveOptionId() {
|
|
361
|
+
if (!this._userHasNavigated) {
|
|
362
|
+
return undefined;
|
|
363
|
+
}
|
|
338
364
|
const item = this._getItemAtIndex(this._focusedIndex);
|
|
339
365
|
return item ? `${item.id}--option` : undefined;
|
|
340
366
|
}
|
|
@@ -391,7 +417,7 @@ let AutocompleteElement = class AutocompleteElement extends LitElement {
|
|
|
391
417
|
*/
|
|
392
418
|
_renderItem(item, index, opts = {}) {
|
|
393
419
|
const { typed, remainder } = this._getLabelParts(item);
|
|
394
|
-
const isActive = index === this._focusedIndex;
|
|
420
|
+
const isActive = this._userHasNavigated && index === this._focusedIndex;
|
|
395
421
|
const isDisabled = !!item.disabled;
|
|
396
422
|
const id = `${item.id}--option`;
|
|
397
423
|
return html `
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autocomplete.js","sources":["../../../../../src/components/prompt-line/autocomplete/src/autocomplete.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 { css, html, LitElement, unsafeCSS } from 'lit';\nimport { property, state } from 'lit/decorators.js';\n\nimport { carbonElement } from '../../../../globals/decorators/carbon-element.js';\nimport prefix from '../../../../globals/settings.js';\nimport { AriaAnnouncerManager } from '../../../../globals/utils/aria-announcer-manager.js';\n\nimport styles from './autocomplete.scss?lit';\nimport { iconLoader } from '@carbon/web-components/es-custom/globals/internal/icon-loader.js';\nimport SendFilled16 from '@carbon/icons/es/send--filled/16.js';\n\nimport type {\n SuggestionItem,\n SuggestionItemGroup,\n} from '../../src/tiptap/types.js';\nimport { classMap } from 'lit/directives/class-map.js';\n\nconst blockClass = `${prefix}-autocomplete`;\nconst itemClass = `${blockClass}-item`;\nconst groupClass = `${itemClass}-group`;\n\n/**\n * Configuration for the autocomplete header\n */\nexport interface HeaderConfig {\n /** Whether to show the header */\n showHeader: boolean;\n /** Title text to display in the header */\n title: string;\n}\n\n/**\n * Localized / consumer-supplied strings for the autocomplete component.\n * All fields are required so callers explicitly provide every user-visible string.\n */\nexport interface AutocompleteI18n {\n /** Announced when the suggestions list is empty. */\n noSuggestions: string;\n /**\n * Announced when the suggestions list first opens.\n * Receives the item count so the caller can form the full phrase.\n *\n * @example (count) => `${count} suggestion${count === 1 ? \"\" : \"s\"}. Use up and down arrows to move, Enter to pick, Escape to close.`\n */\n suggestionsAvailable: (count: number) => string;\n /**\n * Announced when the user moves focus to an item via arrow keys.\n * Receives the item label, optional description, optional group label, and position info.\n *\n * @example (label, description, groupLabel, position) => `${label}${description ? `, ${description}` : \"\"}${groupLabel ? `, ${groupLabel}` : \"\"}, ${position}`\n */\n itemNavigation: (\n label: string,\n description: string | undefined,\n groupLabel: string | undefined,\n position: string\n ) => string;\n /**\n * Announced when an item is selected/inserted.\n * Receives the item label.\n *\n * @example (label) => `${label} inserted.`\n */\n itemInserted: (label: string) => string;\n /**\n * Announced when an item is sent to the chat.\n * Receives the item label.\n *\n * @example (label) => `${label} sent.`\n */\n itemSent: (label: string) => string;\n /** Announced when the suggestions list is closed/dismissed. */\n suggestionsClosed: string;\n /** Accessible label for the listbox element. */\n listboxLabel: string;\n /**\n * Accessible label for the implicit group that wraps flat (non-grouped) items\n * when the listbox element also contains grouped items.\n */\n nonGroupedItemsLabel: string;\n}\n\n/** Default English strings — used as the fallback value for `i18n`. */\nexport const defaultAutocompleteI18n: AutocompleteI18n = {\n noSuggestions: 'No suggestions.',\n suggestionsAvailable: (count) =>\n `${count} suggestion${count === 1 ? '' : 's'}. Use up and down arrows to move, Enter to pick, Escape to close.`,\n itemNavigation: (label, description, groupLabel, position) =>\n `${label}${description ? `, ${description}` : ''}${groupLabel ? `, ${groupLabel}` : ''}, ${position}`,\n itemInserted: (label) => `${label} inserted.`,\n itemSent: (label) => `${label} sent.`,\n suggestionsClosed: 'Suggestions closed.',\n listboxLabel: 'Autocomplete options',\n nonGroupedItemsLabel: 'Non-grouped options',\n};\n\n/**\n * Custom event detail for autocomplete select events\n */\nexport interface AutocompleteSelectEventDetail {\n item: SuggestionItem;\n}\n\n/**\n * Custom event detail for autocomplete send events\n */\nexport interface AutocompleteSendEventDetail {\n text: string;\n}\n\n/**\n * Autocomplete component for AI Chat input suggestions.\n *\n * @element cds-custom-aichat-autocomplete\n * @fires {CustomEvent<AutocompleteSelectEventDetail>} cds-custom-aichat-autocomplete-select - Fired when an item is clicked/activated and `disableDirectSend` is true (insert-into-editor path)\n * @fires {CustomEvent<AutocompleteSendEventDetail>} cds-custom-aichat-autocomplete-send - Fired when an item is clicked/activated and `disableDirectSend` is false (default: sends directly to chat)\n * @fires {CustomEvent} cds-custom-aichat-autocomplete-dismiss - Fired when the autocomplete is dismissed\n */\n@carbonElement(`${prefix}-autocomplete`)\nclass AutocompleteElement extends LitElement {\n static styles = css`\n ${unsafeCSS(styles)}\n `;\n\n /**\n * Array of suggestion items to display\n */\n @property({ type: Array, attribute: false })\n items: SuggestionItem[] = [];\n\n /**\n * Array of grouped suggestion items to display. These will be displayed after any provided `items`.\n */\n @property({ type: Array, attribute: false })\n groups: SuggestionItemGroup[] = [];\n\n /**\n * Optional header configuration\n */\n @property({ type: Object, attribute: false })\n headerConfig?: HeaderConfig;\n\n /**\n * Localized strings for announcements and labels.\n * Defaults to English via `defaultAutocompleteI18n`.\n */\n @property({ type: Object, attribute: false })\n i18n: AutocompleteI18n = defaultAutocompleteI18n;\n\n /**\n * The current text in the input (used to apply styling to indicate what user has already typed)\n */\n @property({ type: String, attribute: 'input-text', reflect: true })\n inputText = '';\n\n /**\n * When `false` (default), clicking an item fires `cds-custom-aichat-autocomplete-send` and\n * the item sends directly to chat.\n *\n * When `true`, clicking an item fires `cds-custom-aichat-autocomplete-select` instead\n * and inserts it into the editor rather than send immediately.\n */\n @property({ type: Boolean, reflect: true, attribute: 'disable-direct-send' })\n disableDirectSend = false;\n\n /**\n * Whether the autocomplete is attached to another element (e.g., an input field).\n * When true, the bottom corners will not be rounded.\n */\n @property({ type: Boolean, reflect: true })\n attached = true;\n\n /**\n * Optional element that \"owns\" this list (e.g. the editor). Clicks on the\n * anchor element are treated as inside-clicks and do not dismiss the list.\n */\n @property({ type: Object, attribute: false })\n anchorElement: Element | null = null;\n\n /**\n * Currently active item index\n * @internal\n */\n @state()\n private _focusedIndex = 0;\n\n private _announcer = new AriaAnnouncerManager();\n private _listboxEl: HTMLElement | null = null;\n\n /**\n * Pending arrow-move announcement timer. Held-key rapid fires are collapsed:\n * only the last pending label is spoken.\n */\n private _moveAnnouncePending: number | null = null;\n\n /** Whether the open announcement has already fired for this show. */\n private _openAnnounced = false;\n\n connectedCallback() {\n super.connectedCallback();\n this.addEventListener('keydown', this._handleKeydown);\n document.addEventListener('click', this._handleClickOutside);\n }\n\n disconnectedCallback() {\n super.disconnectedCallback();\n this.removeEventListener('keydown', this._handleKeydown);\n this._listboxEl?.removeEventListener('mousedown', this._handleMousedown);\n document.removeEventListener('click', this._handleClickOutside);\n this._announcer.disconnect();\n if (this._moveAnnouncePending !== null) {\n clearTimeout(this._moveAnnouncePending);\n this._moveAnnouncePending = null;\n }\n }\n\n firstUpdated() {\n const regions = this.renderRoot.querySelectorAll<HTMLDivElement>(\n `.${blockClass}__live-region`\n );\n this._announcer.connect(Array.from(regions));\n this._listboxEl = this.renderRoot.querySelector<HTMLElement>(\n `.${blockClass}__items`\n );\n this._listboxEl?.addEventListener('mousedown', this._handleMousedown);\n }\n\n updated(changedProperties: Map<string, any>) {\n super.updated(changedProperties);\n\n const itemsChanged =\n changedProperties.has('items') || changedProperties.has('groups');\n\n if (itemsChanged) {\n const totalItems = this._getTotalItemCount();\n if (totalItems === 0) {\n this._announcer.announce(this.i18n.noSuggestions);\n this._openAnnounced = false;\n return;\n }\n // Reset to first enabled item and announce list opened (once per show).\n let firstEnabled = 0;\n while (\n firstEnabled < totalItems &&\n this._getItemAtIndex(firstEnabled)?.disabled\n ) {\n firstEnabled++;\n }\n this._focusedIndex = firstEnabled < totalItems ? firstEnabled : 0;\n if (!this._openAnnounced) {\n this._openAnnounced = true;\n this._announcer.announce(this.i18n.suggestionsAvailable(totalItems));\n }\n }\n }\n\n /**\n * Get the total count of all items (flat items + items in groups)\n */\n private _getTotalItemCount(): number {\n const flatCount = this.items.length;\n const groupedCount = this.groups.reduce(\n (sum, group) => sum + group.items.length,\n 0\n );\n return flatCount + groupedCount;\n }\n\n /**\n * Get the item at a specific index (accounting for both flat items and groups)\n */\n private _getItemAtIndex(index: number): SuggestionItem | null {\n if (index < this.items.length) {\n return this.items[index];\n }\n\n let currentIndex = this.items.length;\n for (const group of this.groups) {\n if (index < currentIndex + group.items.length) {\n return group.items[index - currentIndex];\n }\n currentIndex += group.items.length;\n }\n\n return null;\n }\n\n /**\n * Move focus to the next enabled item in the given direction (+1 / -1),\n * skipping over any disabled items. Mirrors the Carbon Dropdown `_navigate`\n * pattern. Returns the resolved index, or the current index if no enabled\n * item exists in that direction.\n */\n private _navigateTo(from: number, direction: 1 | -1): number {\n const totalItems = this._getTotalItemCount();\n let next = from + direction;\n while (next >= 0 && next < totalItems) {\n if (!this._getItemAtIndex(next)?.disabled) {\n return next;\n }\n next += direction;\n }\n // No enabled item found in that direction — stay put.\n return from;\n }\n\n private _handleKeydown = (event: KeyboardEvent) => {\n const totalItems = this._getTotalItemCount();\n if (totalItems === 0) {\n return;\n }\n\n switch (event.key) {\n case 'ArrowDown':\n event.preventDefault();\n this._focusedIndex = this._navigateTo(this._focusedIndex, 1);\n this._scheduleMoveAnnouncement(this._focusedIndex, totalItems);\n this._scrollActiveItemIntoView();\n break;\n\n case 'ArrowUp':\n event.preventDefault();\n this._focusedIndex = this._navigateTo(this._focusedIndex, -1);\n this._scheduleMoveAnnouncement(this._focusedIndex, totalItems);\n this._scrollActiveItemIntoView();\n break;\n\n case 'Home': {\n event.preventDefault();\n // Find first enabled item from the top.\n let first = 0;\n while (first < totalItems && this._getItemAtIndex(first)?.disabled) {\n first++;\n }\n this._focusedIndex = first < totalItems ? first : this._focusedIndex;\n this._scheduleMoveAnnouncement(this._focusedIndex, totalItems);\n this._scrollActiveItemIntoView();\n break;\n }\n\n case 'End': {\n event.preventDefault();\n // Find last enabled item from the bottom.\n let last = totalItems - 1;\n while (last >= 0 && this._getItemAtIndex(last)?.disabled) {\n last--;\n }\n this._focusedIndex = last >= 0 ? last : this._focusedIndex;\n this._scheduleMoveAnnouncement(this._focusedIndex, totalItems);\n this._scrollActiveItemIntoView();\n break;\n }\n\n case 'Escape':\n event.preventDefault();\n this._dismiss();\n break;\n\n case 'Enter':\n event.preventDefault();\n this._handleItemClick(this._focusedIndex);\n break;\n }\n };\n\n /**\n * Schedule a move announcement, replacing any pending one so rapid arrow\n * holds only speak the final position.\n */\n private _scheduleMoveAnnouncement(index: number, total: number): void {\n if (this._moveAnnouncePending !== null) {\n clearTimeout(this._moveAnnouncePending);\n }\n this._moveAnnouncePending = window.setTimeout(() => {\n this._moveAnnouncePending = null;\n const item = this._getItemAtIndex(index);\n if (!item) {\n return;\n }\n const position = `${index + 1} of ${total}`;\n this._announcer.announce(\n this.i18n.itemNavigation(\n item.label,\n item.description,\n this._getGroupTitleAtIndex(index),\n position\n )\n );\n }, 50);\n }\n\n private _handleSend(index: number) {\n const item = this._getItemAtIndex(index);\n if (!item) {\n return;\n }\n this._focusedIndex = index;\n this._announcer.announce(this.i18n.itemSent(item.label));\n this.dispatchEvent(\n new CustomEvent<AutocompleteSendEventDetail>(\n 'cds-custom-aichat-autocomplete-send',\n {\n detail: { text: item.value ?? item.label },\n bubbles: true,\n composed: true,\n }\n )\n );\n }\n\n private _handleMousedown = (event: MouseEvent) => {\n // Prevent the editor from losing focus when the user clicks one of the list\n // items. Without this, mousedown transfers focus away from the editor,\n // carbonStarterTrigger.onTransaction fires, sees editor.isFocused === false,\n // and dismisses the list before the click event can trigger onSelect.\n event.preventDefault();\n };\n\n private _handleItemMouseEnter(index: number): void {\n if (this._getItemAtIndex(index)?.disabled) {\n return;\n }\n this._focusedIndex = index;\n }\n\n private _handleClickOutside = (event: MouseEvent) => {\n // Use composedPath() instead of event.target so clicks originating inside\n // a shadow root are visible.\n const path = event.composedPath();\n\n if (path.includes(this)) {\n return;\n }\n if (this.anchorElement && path.includes(this.anchorElement)) {\n return;\n }\n this._dismiss();\n };\n\n private _scrollActiveItemIntoView(): void {\n this.updateComplete.then(() => {\n const itemsContainer = this.shadowRoot?.querySelector(\n `.${blockClass}__items`\n );\n const options = Array.from(\n itemsContainer?.querySelectorAll('li[role=\"option\"]') ?? []\n );\n (options[this._focusedIndex] as HTMLElement | undefined)?.scrollIntoView({\n block: 'nearest',\n });\n });\n }\n\n private _selectItem(item: SuggestionItem) {\n if (item.disabled) {\n return;\n }\n this._announcer.announce(this.i18n.itemInserted(item.label));\n this.dispatchEvent(\n new CustomEvent<AutocompleteSelectEventDetail>(\n 'cds-custom-aichat-autocomplete-select',\n {\n detail: { item },\n bubbles: true,\n composed: true,\n }\n )\n );\n }\n\n private _dismiss() {\n this._openAnnounced = false;\n this._announcer.announce(this.i18n.suggestionsClosed);\n this.dispatchEvent(\n new CustomEvent('cds-custom-aichat-autocomplete-dismiss', {\n bubbles: true,\n composed: true,\n })\n );\n }\n\n private _handleItemClick(index: number) {\n const item = this._getItemAtIndex(index);\n if (!item || item.disabled) {\n return;\n }\n\n if (!this.disableDirectSend) {\n this._handleSend(index);\n return;\n }\n this._focusedIndex = index;\n this._selectItem(item);\n }\n\n private _getActiveOptionId(): string | undefined {\n const item = this._getItemAtIndex(this._focusedIndex);\n return item ? `${item.id}--option` : undefined;\n }\n\n private _getGroupTitleAtIndex(index: number): string | undefined {\n if (index < this.items.length) {\n return this.groups.length > 0\n ? this.i18n.nonGroupedItemsLabel\n : undefined;\n }\n\n let currentIndex = this.items.length;\n for (const group of this.groups) {\n const groupEndIndex = currentIndex + group.items.length;\n if (index < groupEndIndex) {\n return group.title;\n }\n currentIndex = groupEndIndex;\n }\n\n return undefined;\n }\n\n private _getLabelParts(item: SuggestionItem): {\n typed: string;\n remainder: string;\n } {\n const label = item.label;\n const input = this.inputText.toLowerCase();\n\n if (input && label.toLowerCase().startsWith(input)) {\n return {\n typed: label.substring(0, input.length),\n remainder: label.substring(input.length),\n };\n }\n\n return { typed: '', remainder: label };\n }\n\n /**\n * Render the avatar if provided\n */\n private _renderAvatar(item: SuggestionItem) {\n const { avatar } = item;\n if (!avatar) {\n return null;\n }\n if (typeof avatar === 'string') {\n return html`<div class=\"${itemClass}__avatar\">\n <img src=\"${avatar}\" alt=\"\" />\n </div>`;\n }\n // CarbonIcon descriptor (object, not a function)\n if (typeof avatar !== 'function') {\n return html`<div class=\"${itemClass}__avatar\">\n ${iconLoader(avatar)}\n </div>`;\n }\n return null;\n }\n\n /**\n * Render a single `<li role=\"option\">` for both flat and grouped contexts.\n */\n private _renderItem(\n item: SuggestionItem,\n index: number,\n opts: { firstItem?: boolean; lastItem?: boolean } = {}\n ) {\n const { typed, remainder } = this._getLabelParts(item);\n const isActive = index === this._focusedIndex;\n const isDisabled = !!item.disabled;\n const id = `${item.id}--option`;\n\n return html`\n <li\n @click=\"${() => this._handleItemClick(index)}\"\n @keydown=\"${(e: KeyboardEvent) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n this._handleItemClick(index);\n }\n }}\"\n @mouseenter=\"${() => this._handleItemMouseEnter(index)}\"\n aria-selected=\"false\"\n aria-disabled=\"${isDisabled ? 'true' : 'false'}\"\n class=${classMap({\n [itemClass]: true,\n [`${itemClass}--active`]: isActive,\n [`${itemClass}--disabled`]: isDisabled,\n })}\n id=\"${id}\"\n role=\"option\"\n tabindex=\"-1\"\n ?first-item=\"${opts.firstItem}\"\n ?last-item=\"${opts.lastItem}\">\n <div class=\"${itemClass}__content\">\n ${this._renderAvatar(item)}\n <div class=\"${itemClass}__text\">\n <div class=\"${itemClass}__label\">\n ${\n typed\n ? html`<span class=\"${itemClass}__label-typed\"\n >${typed}</span\n >`\n : ''\n }${\n remainder\n ? html`<span class=\"${itemClass}__label-remainder\"\n >${remainder}</span\n >`\n : ''\n }\n </div>\n ${\n item.description\n ? html`<div class=\"${itemClass}__description\">\n ${item.description}\n </div>`\n : null\n }\n </div>\n </div>\n ${\n !this.disableDirectSend\n ? html`<span aria-hidden=\"true\" class=\"${itemClass}__send-icon\">\n ${iconLoader(SendFilled16)}\n </span>`\n : null\n }\n </li>\n `;\n }\n\n render() {\n const totalItems = this._getTotalItemCount();\n\n // Always render the live regions so the last announcement is not lost\n // when the list empties (e.g. \"No suggestions.\" or \"Suggestions closed.\").\n const liveRegions = html`\n <div\n class=\"${blockClass}__live-region\"\n aria-live=\"polite\"\n aria-atomic=\"false\"></div>\n <div\n class=\"${blockClass}__live-region\"\n aria-live=\"polite\"\n aria-atomic=\"false\"></div>\n `;\n\n if (totalItems === 0) {\n return liveRegions;\n }\n\n let currentIndex = 0;\n const hasGroups = this.groups.length > 0;\n\n return html`\n ${liveRegions}\n <div class=\"${blockClass}\">\n ${\n this.headerConfig?.showHeader\n ? html`\n <div class=\"${blockClass}__header\">\n <span class=\"${blockClass}__title\">\n ${this.headerConfig.title}\n </span>\n </div>\n `\n : ''\n }\n ${\n hasGroups\n ? html`\n <div\n aria-activedescendant=\"${this._getActiveOptionId()}\"\n aria-label=\"${this.i18n.listboxLabel}\"\n class=\"${blockClass}__items\"\n id=\"${blockClass}-listbox\"\n role=\"listbox\">\n <!-- Flat items wrapped in their own implicit group -->\n ${\n this.items.length > 0\n ? html`\n <ul\n role=\"group\"\n aria-label=\"${this.i18n.nonGroupedItemsLabel}\"\n class=\"${groupClass}__items\">\n ${this.items.map((item, index) => {\n const itemIndex = currentIndex++;\n return this._renderItem(item, itemIndex, {\n firstItem:\n !this.headerConfig?.showHeader && index === 0,\n });\n })}\n </ul>\n `\n : ''\n }\n\n <!-- Grouped items -->\n ${this.groups.map((group, groupIndex) => {\n const groupStartIndex = currentIndex;\n currentIndex += group.items.length;\n const isLastGroup = groupIndex === this.groups.length - 1;\n return html`\n <ul\n role=\"group\"\n aria-labelledby=\"group-label-${groupIndex}\"\n class=\"${groupClass}__items\">\n <li\n role=\"presentation\"\n id=\"group-label-${groupIndex}\"\n class=\"${groupClass}__title\">\n ${group.title}\n </li>\n ${group.items.map((item, itemIndex) =>\n this._renderItem(item, groupStartIndex + itemIndex, {\n lastItem:\n isLastGroup &&\n itemIndex === group.items.length - 1,\n })\n )}\n </ul>\n `;\n })}\n </div>\n `\n : html`\n <!-- Flat items only -->\n <ul\n aria-activedescendant=\"${this._getActiveOptionId()}\"\n aria-label=\"${this.i18n.listboxLabel}\"\n class=\"${blockClass}__items\"\n id=\"${blockClass}-listbox\"\n role=\"listbox\">\n ${this.items.map((item, index) => {\n const itemIndex = currentIndex++;\n return this._renderItem(item, itemIndex, {\n firstItem: !this.headerConfig?.showHeader && index === 0,\n lastItem: index === this.items.length - 1,\n });\n })}\n </ul>\n `\n }\n </div>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'cds-custom-aichat-autocomplete': AutocompleteElement;\n }\n}\n\nexport default AutocompleteElement;\nexport type {\n SuggestionItem,\n SuggestionItemGroup,\n} from '../../src/tiptap/types.js';\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;AAOG;AAmBH,MAAM,UAAU,GAAG,CAAA,EAAG,MAAM,eAA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MAAA,CAAA;AAO7B,UAAA,CAAA;AADP,IAAA,KAAK;AACoB,CAAA,EAAA,mBAAA,CAAA,SAAA,EAAA,eAAA,EAAA,MAAA,CAAA;AAjEtB,mBAAmB,GAAA,UAAA,CAAA;AADxB,IAAA,aAAa,CAAC,CAAA,EAAG,MAAM,CAAA,aAAA,CAAe;AACjC,CAAA,EAAA,mBAAmB,CAmnBxB;AAQD,4BAAe,mBAAmB;;"}
|
|
1
|
+
{"version":3,"file":"autocomplete.js","sources":["../../../../../src/components/prompt-line/autocomplete/src/autocomplete.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 { css, html, LitElement, unsafeCSS } from 'lit';\nimport { property, state } from 'lit/decorators.js';\n\nimport { carbonElement } from '../../../../globals/decorators/carbon-element.js';\nimport prefix from '../../../../globals/settings.js';\nimport { AriaAnnouncerManager } from '../../../../globals/utils/aria-announcer-manager.js';\n\nimport styles from './autocomplete.scss?lit';\nimport { iconLoader } from '@carbon/web-components/es-custom/globals/internal/icon-loader.js';\nimport SendFilled16 from '@carbon/icons/es/send--filled/16.js';\n\nimport type {\n SuggestionItem,\n SuggestionItemGroup,\n} from '../../src/tiptap/types.js';\nimport { classMap } from 'lit/directives/class-map.js';\n\nconst blockClass = `${prefix}-autocomplete`;\nconst itemClass = `${blockClass}-item`;\nconst groupClass = `${itemClass}-group`;\n\n/**\n * Configuration for the autocomplete header\n */\nexport interface HeaderConfig {\n /** Whether to show the header */\n showHeader: boolean;\n /** Title text to display in the header */\n title: string;\n}\n\n/**\n * Localized / consumer-supplied strings for the autocomplete component.\n * All fields are required so callers explicitly provide every user-visible string.\n */\nexport interface AutocompleteI18n {\n /** Announced when the suggestions list is empty. */\n noSuggestions: string;\n /**\n * Announced when the suggestions list first opens.\n * Receives the item count so the caller can form the full phrase.\n *\n * @example (count) => `${count} suggestion${count === 1 ? \"\" : \"s\"}. Use up and down arrows to move, Enter to pick, Escape to close.`\n */\n suggestionsAvailable: (count: number) => string;\n /**\n * Announced when the user moves focus to an item via arrow keys.\n * Receives the item label, optional description, optional group label, and position info.\n *\n * @example (label, description, groupLabel, position) => `${label}${description ? `, ${description}` : \"\"}${groupLabel ? `, ${groupLabel}` : \"\"}, ${position}`\n */\n itemNavigation: (\n label: string,\n description: string | undefined,\n groupLabel: string | undefined,\n position: string\n ) => string;\n /**\n * Announced when an item is selected/inserted.\n * Receives the item label.\n *\n * @example (label) => `${label} inserted.`\n */\n itemInserted: (label: string) => string;\n /**\n * Announced when an item is sent to the chat.\n * Receives the item label.\n *\n * @example (label) => `${label} sent.`\n */\n itemSent: (label: string) => string;\n /** Announced when the suggestions list is closed/dismissed. */\n suggestionsClosed: string;\n /** Accessible label for the listbox element. */\n listboxLabel: string;\n /**\n * Accessible label for the implicit group that wraps flat (non-grouped) items\n * when the listbox element also contains grouped items.\n */\n nonGroupedItemsLabel: string;\n}\n\n/** Default English strings — used as the fallback value for `i18n`. */\nexport const defaultAutocompleteI18n: AutocompleteI18n = {\n noSuggestions: 'No suggestions.',\n suggestionsAvailable: (count) =>\n `${count} suggestion${count === 1 ? '' : 's'}. Use up and down arrows to move, Enter to pick, Escape to close.`,\n itemNavigation: (label, description, groupLabel, position) =>\n `${label}${description ? `, ${description}` : ''}${groupLabel ? `, ${groupLabel}` : ''}, ${position}`,\n itemInserted: (label) => `${label} inserted.`,\n itemSent: (label) => `${label} sent.`,\n suggestionsClosed: 'Suggestions closed.',\n listboxLabel: 'Autocomplete options',\n nonGroupedItemsLabel: 'Non-grouped options',\n};\n\n/**\n * Custom event detail for autocomplete select events\n */\nexport interface AutocompleteSelectEventDetail {\n item: SuggestionItem;\n}\n\n/**\n * Custom event detail for autocomplete send events\n */\nexport interface AutocompleteSendEventDetail {\n text: string;\n}\n\nexport interface AutocompleteNavigatedEventDetail {\n navigated: boolean;\n}\n\n/**\n * Autocomplete component for AI Chat input suggestions.\n *\n * @element cds-custom-aichat-autocomplete\n * @fires {CustomEvent<AutocompleteSelectEventDetail>} cds-custom-aichat-autocomplete-select - Fired when an item is clicked/activated and `disableDirectSend` is true (insert-into-editor path)\n * @fires {CustomEvent<AutocompleteSendEventDetail>} cds-custom-aichat-autocomplete-send - Fired when an item is clicked/activated and `disableDirectSend` is false (default: sends directly to chat)\n * @fires {CustomEvent} cds-custom-aichat-autocomplete-dismiss - Fired when the autocomplete is dismissed\n */\n@carbonElement(`${prefix}-autocomplete`)\nclass AutocompleteElement extends LitElement {\n static styles = css`\n ${unsafeCSS(styles)}\n `;\n\n /**\n * Array of suggestion items to display\n */\n @property({ type: Array, attribute: false })\n items: SuggestionItem[] = [];\n\n /**\n * Array of grouped suggestion items to display. These will be displayed after any provided `items`.\n */\n @property({ type: Array, attribute: false })\n groups: SuggestionItemGroup[] = [];\n\n /**\n * Optional header configuration\n */\n @property({ type: Object, attribute: false })\n headerConfig?: HeaderConfig;\n\n /**\n * Localized strings for announcements and labels.\n * Defaults to English via `defaultAutocompleteI18n`.\n */\n @property({ type: Object, attribute: false })\n i18n: AutocompleteI18n = defaultAutocompleteI18n;\n\n /**\n * The current text in the input (used to apply styling to indicate what user has already typed)\n */\n @property({ type: String, attribute: 'input-text', reflect: true })\n inputText = '';\n\n /**\n * When `false` (default), clicking an item fires `cds-custom-aichat-autocomplete-send` and\n * the item sends directly to chat.\n *\n * When `true`, clicking an item fires `cds-custom-aichat-autocomplete-select` instead\n * and inserts it into the editor rather than send immediately.\n */\n @property({ type: Boolean, reflect: true, attribute: 'disable-direct-send' })\n disableDirectSend = false;\n\n /**\n * Whether the autocomplete is attached to another element (e.g., an input field).\n * When true, the bottom corners will not be rounded.\n */\n @property({ type: Boolean, reflect: true })\n attached = true;\n\n /**\n * Optional element that \"owns\" this list (e.g. the editor). Clicks on the\n * anchor element are treated as inside-clicks and do not dismiss the list.\n */\n @property({ type: Object, attribute: false })\n anchorElement: Element | null = null;\n\n /**\n * Currently active item index\n * @internal\n */\n @state()\n private _focusedIndex = -1;\n\n private _userHasNavigated = false;\n\n private _setUserHasNavigated(value: boolean): void {\n if (this._userHasNavigated === value) {\n return;\n }\n this._userHasNavigated = value;\n this.dispatchEvent(\n new CustomEvent<AutocompleteNavigatedEventDetail>(\n 'cds-custom-aichat-autocomplete-navigated',\n { detail: { navigated: value }, bubbles: true, composed: true }\n )\n );\n }\n\n private _announcer = new AriaAnnouncerManager();\n private _listboxEl: HTMLElement | null = null;\n\n /**\n * Pending arrow-move announcement timer. Held-key rapid fires are collapsed:\n * only the last pending label is spoken.\n */\n private _moveAnnouncePending: number | null = null;\n\n /** Whether the open announcement has already fired for this show. */\n private _openAnnounced = false;\n\n connectedCallback() {\n super.connectedCallback();\n this.addEventListener('keydown', this._handleKeydown);\n document.addEventListener('click', this._handleClickOutside);\n }\n\n disconnectedCallback() {\n super.disconnectedCallback();\n this.removeEventListener('keydown', this._handleKeydown);\n this._listboxEl?.removeEventListener('mousedown', this._handleMousedown);\n document.removeEventListener('click', this._handleClickOutside);\n this._announcer.disconnect();\n if (this._moveAnnouncePending !== null) {\n clearTimeout(this._moveAnnouncePending);\n this._moveAnnouncePending = null;\n }\n }\n\n public hasNavigated(): boolean {\n return this._userHasNavigated;\n }\n\n firstUpdated() {\n const regions = this.renderRoot.querySelectorAll<HTMLDivElement>(\n `.${blockClass}__live-region`\n );\n this._announcer.connect(Array.from(regions));\n this._listboxEl = this.renderRoot.querySelector<HTMLElement>(\n `.${blockClass}__items`\n );\n this._listboxEl?.addEventListener('mousedown', this._handleMousedown);\n }\n\n updated(changedProperties: Map<string, any>) {\n super.updated(changedProperties);\n\n const itemsChanged =\n changedProperties.has('items') || changedProperties.has('groups');\n\n if (itemsChanged) {\n const totalItems = this._getTotalItemCount();\n if (totalItems === 0) {\n this._announcer.announce(this.i18n.noSuggestions);\n this._openAnnounced = false;\n return;\n }\n this._focusedIndex = -1;\n this._setUserHasNavigated(false);\n if (!this._openAnnounced) {\n this._openAnnounced = true;\n this._announcer.announce(this.i18n.suggestionsAvailable(totalItems));\n }\n }\n }\n\n /**\n * Get the total count of all items (flat items + items in groups)\n */\n private _getTotalItemCount(): number {\n const flatCount = this.items.length;\n const groupedCount = this.groups.reduce(\n (sum, group) => sum + group.items.length,\n 0\n );\n return flatCount + groupedCount;\n }\n\n /**\n * Get the item at a specific index (accounting for both flat items and groups)\n */\n private _getItemAtIndex(index: number): SuggestionItem | null {\n if (index < this.items.length) {\n return this.items[index];\n }\n\n let currentIndex = this.items.length;\n for (const group of this.groups) {\n if (index < currentIndex + group.items.length) {\n return group.items[index - currentIndex];\n }\n currentIndex += group.items.length;\n }\n\n return null;\n }\n\n /**\n * Move focus to the next enabled item in the given direction (+1 / -1),\n * skipping over any disabled items. Mirrors the Carbon Dropdown `_navigate`\n * pattern. Returns the resolved index, or the current index if no enabled\n * item exists in that direction.\n */\n private _navigateTo(from: number, direction: 1 | -1): number {\n const totalItems = this._getTotalItemCount();\n // When no item is selected yet (-1), ArrowUp wraps to the last item.\n const start = from === -1 && direction === -1 ? totalItems : from;\n let next = start + direction;\n while (next >= 0 && next < totalItems) {\n if (!this._getItemAtIndex(next)?.disabled) {\n return next;\n }\n next += direction;\n }\n // No enabled item found in that direction — stay put (keep -1 if unnavigated).\n return from;\n }\n\n private _handleKeydown = (event: KeyboardEvent) => {\n const totalItems = this._getTotalItemCount();\n if (totalItems === 0) {\n return;\n }\n\n switch (event.key) {\n case 'ArrowDown':\n event.preventDefault();\n this._focusedIndex = this._navigateTo(this._focusedIndex, 1);\n this._setUserHasNavigated(true);\n this._scheduleMoveAnnouncement(this._focusedIndex, totalItems);\n this._scrollActiveItemIntoView();\n break;\n\n case 'ArrowUp':\n event.preventDefault();\n this._focusedIndex = this._navigateTo(this._focusedIndex, -1);\n this._setUserHasNavigated(true);\n this._scheduleMoveAnnouncement(this._focusedIndex, totalItems);\n this._scrollActiveItemIntoView();\n break;\n\n case 'Home': {\n event.preventDefault();\n // Find first enabled item from the top.\n let first = 0;\n while (first < totalItems && this._getItemAtIndex(first)?.disabled) {\n first++;\n }\n this._focusedIndex = first < totalItems ? first : this._focusedIndex;\n this._setUserHasNavigated(true);\n this._scheduleMoveAnnouncement(this._focusedIndex, totalItems);\n this._scrollActiveItemIntoView();\n break;\n }\n case 'End': {\n event.preventDefault();\n // Find last enabled item from the bottom.\n let last = totalItems - 1;\n while (last >= 0 && this._getItemAtIndex(last)?.disabled) {\n last--;\n }\n this._focusedIndex = last >= 0 ? last : this._focusedIndex;\n this._setUserHasNavigated(true);\n this._scheduleMoveAnnouncement(this._focusedIndex, totalItems);\n this._scrollActiveItemIntoView();\n break;\n }\n\n case 'Tab':\n event.preventDefault();\n this._focusedIndex = this._navigateTo(this._focusedIndex, 1);\n this._setUserHasNavigated(true);\n this._scheduleMoveAnnouncement(this._focusedIndex, totalItems);\n this._scrollActiveItemIntoView();\n break;\n\n case 'Escape':\n event.preventDefault();\n this._dismiss();\n break;\n\n case 'Enter':\n if (!this._userHasNavigated) {\n return;\n }\n event.preventDefault();\n this._handleItemClick(this._focusedIndex);\n break;\n }\n };\n\n /**\n * Schedule a move announcement, replacing any pending one so rapid arrow\n * holds only speak the final position.\n */\n private _scheduleMoveAnnouncement(index: number, total: number): void {\n if (this._moveAnnouncePending !== null) {\n clearTimeout(this._moveAnnouncePending);\n }\n this._moveAnnouncePending = window.setTimeout(() => {\n this._moveAnnouncePending = null;\n const item = this._getItemAtIndex(index);\n if (!item) {\n return;\n }\n const position = `${index + 1} of ${total}`;\n this._announcer.announce(\n this.i18n.itemNavigation(\n item.label,\n item.description,\n this._getGroupTitleAtIndex(index),\n position\n )\n );\n }, 50);\n }\n\n private _handleSend(index: number) {\n const item = this._getItemAtIndex(index);\n if (!item) {\n return;\n }\n this._focusedIndex = index;\n this._announcer.announce(this.i18n.itemSent(item.label));\n this.dispatchEvent(\n new CustomEvent<AutocompleteSendEventDetail>(\n 'cds-custom-aichat-autocomplete-send',\n {\n detail: { text: item.value ?? item.label },\n bubbles: true,\n composed: true,\n }\n )\n );\n }\n\n private _handleMousedown = (event: MouseEvent) => {\n // Prevent the editor from losing focus when the user clicks one of the list\n // items. Without this, mousedown transfers focus away from the editor,\n // carbonStarterTrigger.onTransaction fires, sees editor.isFocused === false,\n // and dismisses the list before the click event can trigger onSelect.\n event.preventDefault();\n };\n\n private _handleItemMouseEnter(index: number): void {\n if (this._getItemAtIndex(index)?.disabled) {\n return;\n }\n this._focusedIndex = index;\n }\n\n private _handleClickOutside = (event: MouseEvent) => {\n // Use composedPath() instead of event.target so clicks originating inside\n // a shadow root are visible.\n const path = event.composedPath();\n\n if (path.includes(this)) {\n return;\n }\n if (this.anchorElement && path.includes(this.anchorElement)) {\n return;\n }\n this._dismiss();\n };\n\n private _scrollActiveItemIntoView(): void {\n this.updateComplete.then(() => {\n const itemsContainer = this.shadowRoot?.querySelector(\n `.${blockClass}__items`\n );\n const options = Array.from(\n itemsContainer?.querySelectorAll('li[role=\"option\"]') ?? []\n );\n (options[this._focusedIndex] as HTMLElement | undefined)?.scrollIntoView({\n block: 'nearest',\n });\n });\n }\n\n private _selectItem(item: SuggestionItem) {\n if (item.disabled) {\n return;\n }\n this._announcer.announce(this.i18n.itemInserted(item.label));\n this.dispatchEvent(\n new CustomEvent<AutocompleteSelectEventDetail>(\n 'cds-custom-aichat-autocomplete-select',\n {\n detail: { item },\n bubbles: true,\n composed: true,\n }\n )\n );\n }\n\n private _dismiss() {\n this._openAnnounced = false;\n this._setUserHasNavigated(false);\n this._announcer.announce(this.i18n.suggestionsClosed);\n this.dispatchEvent(\n new CustomEvent('cds-custom-aichat-autocomplete-dismiss', {\n bubbles: true,\n composed: true,\n })\n );\n }\n\n private _handleItemClick(index: number) {\n const item = this._getItemAtIndex(index);\n if (!item || item.disabled) {\n return;\n }\n\n if (!this.disableDirectSend) {\n this._handleSend(index);\n return;\n }\n this._focusedIndex = index;\n this._selectItem(item);\n }\n\n private _getActiveOptionId(): string | undefined {\n if (!this._userHasNavigated) {\n return undefined;\n }\n const item = this._getItemAtIndex(this._focusedIndex);\n return item ? `${item.id}--option` : undefined;\n }\n\n private _getGroupTitleAtIndex(index: number): string | undefined {\n if (index < this.items.length) {\n return this.groups.length > 0\n ? this.i18n.nonGroupedItemsLabel\n : undefined;\n }\n\n let currentIndex = this.items.length;\n for (const group of this.groups) {\n const groupEndIndex = currentIndex + group.items.length;\n if (index < groupEndIndex) {\n return group.title;\n }\n currentIndex = groupEndIndex;\n }\n\n return undefined;\n }\n\n private _getLabelParts(item: SuggestionItem): {\n typed: string;\n remainder: string;\n } {\n const label = item.label;\n const input = this.inputText.toLowerCase();\n\n if (input && label.toLowerCase().startsWith(input)) {\n return {\n typed: label.substring(0, input.length),\n remainder: label.substring(input.length),\n };\n }\n\n return { typed: '', remainder: label };\n }\n\n /**\n * Render the avatar if provided\n */\n private _renderAvatar(item: SuggestionItem) {\n const { avatar } = item;\n if (!avatar) {\n return null;\n }\n if (typeof avatar === 'string') {\n return html`<div class=\"${itemClass}__avatar\">\n <img src=\"${avatar}\" alt=\"\" />\n </div>`;\n }\n // CarbonIcon descriptor (object, not a function)\n if (typeof avatar !== 'function') {\n return html`<div class=\"${itemClass}__avatar\">\n ${iconLoader(avatar)}\n </div>`;\n }\n return null;\n }\n\n /**\n * Render a single `<li role=\"option\">` for both flat and grouped contexts.\n */\n private _renderItem(\n item: SuggestionItem,\n index: number,\n opts: { firstItem?: boolean; lastItem?: boolean } = {}\n ) {\n const { typed, remainder } = this._getLabelParts(item);\n const isActive = this._userHasNavigated && index === this._focusedIndex;\n const isDisabled = !!item.disabled;\n const id = `${item.id}--option`;\n\n return html`\n <li\n @click=\"${() => this._handleItemClick(index)}\"\n @keydown=\"${(e: KeyboardEvent) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n this._handleItemClick(index);\n }\n }}\"\n @mouseenter=\"${() => this._handleItemMouseEnter(index)}\"\n aria-selected=\"false\"\n aria-disabled=\"${isDisabled ? 'true' : 'false'}\"\n class=${classMap({\n [itemClass]: true,\n [`${itemClass}--active`]: isActive,\n [`${itemClass}--disabled`]: isDisabled,\n })}\n id=\"${id}\"\n role=\"option\"\n tabindex=\"-1\"\n ?first-item=\"${opts.firstItem}\"\n ?last-item=\"${opts.lastItem}\">\n <div class=\"${itemClass}__content\">\n ${this._renderAvatar(item)}\n <div class=\"${itemClass}__text\">\n <div class=\"${itemClass}__label\">\n ${\n typed\n ? html`<span class=\"${itemClass}__label-typed\"\n >${typed}</span\n >`\n : ''\n }${\n remainder\n ? html`<span class=\"${itemClass}__label-remainder\"\n >${remainder}</span\n >`\n : ''\n }\n </div>\n ${\n item.description\n ? html`<div class=\"${itemClass}__description\">\n ${item.description}\n </div>`\n : null\n }\n </div>\n </div>\n ${\n !this.disableDirectSend\n ? html`<span aria-hidden=\"true\" class=\"${itemClass}__send-icon\">\n ${iconLoader(SendFilled16)}\n </span>`\n : null\n }\n </li>\n `;\n }\n\n render() {\n const totalItems = this._getTotalItemCount();\n\n // Always render the live regions so the last announcement is not lost\n // when the list empties (e.g. \"No suggestions.\" or \"Suggestions closed.\").\n const liveRegions = html`\n <div\n class=\"${blockClass}__live-region\"\n aria-live=\"polite\"\n aria-atomic=\"false\"></div>\n <div\n class=\"${blockClass}__live-region\"\n aria-live=\"polite\"\n aria-atomic=\"false\"></div>\n `;\n\n if (totalItems === 0) {\n return liveRegions;\n }\n\n let currentIndex = 0;\n const hasGroups = this.groups.length > 0;\n\n return html`\n ${liveRegions}\n <div class=\"${blockClass}\">\n ${\n this.headerConfig?.showHeader\n ? html`\n <div class=\"${blockClass}__header\">\n <span class=\"${blockClass}__title\">\n ${this.headerConfig.title}\n </span>\n </div>\n `\n : ''\n }\n ${\n hasGroups\n ? html`\n <div\n aria-activedescendant=\"${this._getActiveOptionId()}\"\n aria-label=\"${this.i18n.listboxLabel}\"\n class=\"${blockClass}__items\"\n id=\"${blockClass}-listbox\"\n role=\"listbox\">\n <!-- Flat items wrapped in their own implicit group -->\n ${\n this.items.length > 0\n ? html`\n <ul\n role=\"group\"\n aria-label=\"${this.i18n.nonGroupedItemsLabel}\"\n class=\"${groupClass}__items\">\n ${this.items.map((item, index) => {\n const itemIndex = currentIndex++;\n return this._renderItem(item, itemIndex, {\n firstItem:\n !this.headerConfig?.showHeader && index === 0,\n });\n })}\n </ul>\n `\n : ''\n }\n\n <!-- Grouped items -->\n ${this.groups.map((group, groupIndex) => {\n const groupStartIndex = currentIndex;\n currentIndex += group.items.length;\n const isLastGroup = groupIndex === this.groups.length - 1;\n return html`\n <ul\n role=\"group\"\n aria-labelledby=\"group-label-${groupIndex}\"\n class=\"${groupClass}__items\">\n <li\n role=\"presentation\"\n id=\"group-label-${groupIndex}\"\n class=\"${groupClass}__title\">\n ${group.title}\n </li>\n ${group.items.map((item, itemIndex) =>\n this._renderItem(item, groupStartIndex + itemIndex, {\n lastItem:\n isLastGroup &&\n itemIndex === group.items.length - 1,\n })\n )}\n </ul>\n `;\n })}\n </div>\n `\n : html`\n <!-- Flat items only -->\n <ul\n aria-activedescendant=\"${this._getActiveOptionId()}\"\n aria-label=\"${this.i18n.listboxLabel}\"\n class=\"${blockClass}__items\"\n id=\"${blockClass}-listbox\"\n role=\"listbox\">\n ${this.items.map((item, index) => {\n const itemIndex = currentIndex++;\n return this._renderItem(item, itemIndex, {\n firstItem: !this.headerConfig?.showHeader && index === 0,\n lastItem: index === this.items.length - 1,\n });\n })}\n </ul>\n `\n }\n </div>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'cds-custom-aichat-autocomplete': AutocompleteElement;\n }\n}\n\nexport default AutocompleteElement;\nexport type {\n SuggestionItem,\n SuggestionItemGroup,\n} from '../../src/tiptap/types.js';\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;AAOG;AAmBH,MAAM,UAAU,GAAG,CAAA,EAAG,MAAM,eAAe;AAC3C,MAAM,SAAS,GAAG,CAAA,EAAG,UAAU,OAAO;AACtC,MAAM,UAAU,GAAG,CAAA,EAAG,SAAS,QAAQ;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,CAAe;AACjC,CAAA,EAAA,mBAAmB,CAmpBxB;AAQD,4BAAe,mBAAmB;;"}
|
|
@@ -29,6 +29,10 @@ import type { AutocompleteConfig, StartersConfig, TriggerSuggestionConfig } from
|
|
|
29
29
|
* after a suggestion item is selected. Fired in addition to type-specific callbacks.
|
|
30
30
|
* @fires cds-custom-aichat-autocomplete-item-send — `{ text: string }` when the
|
|
31
31
|
* per-item send button is clicked inside the suggestion list.
|
|
32
|
+
* @fires cds-custom-aichat-list-navigated — `{ navigated: boolean }` when the user
|
|
33
|
+
* starts or stops navigating the suggestion list with arrow keys. WC
|
|
34
|
+
* consumers should use this to disable their send control while `navigated`
|
|
35
|
+
* is `true` (the `listNavigated` getter reflects the same state).
|
|
32
36
|
*/
|
|
33
37
|
declare class AutocompleteControllerElement extends LitElement {
|
|
34
38
|
/** `@`-style mention trigger config. */
|
|
@@ -42,6 +46,17 @@ declare class AutocompleteControllerElement extends LitElement {
|
|
|
42
46
|
/** When true, starter selection inserts text without firing the send event. */
|
|
43
47
|
isSendDisabled: boolean;
|
|
44
48
|
private _state;
|
|
49
|
+
/**
|
|
50
|
+
* Tracks whether the user is actively navigating inside the autocomplete
|
|
51
|
+
* list. When `true`, the send button should be disabled so that Enter
|
|
52
|
+
* confirms the highlighted item rather than submitting the prompt.
|
|
53
|
+
*/
|
|
54
|
+
private _listNavigated;
|
|
55
|
+
/**
|
|
56
|
+
* Returns `true` while the user is navigating inside the autocomplete list.
|
|
57
|
+
* Consumers can use this to disable their send control.
|
|
58
|
+
*/
|
|
59
|
+
get listNavigated(): boolean;
|
|
45
60
|
private _controller;
|
|
46
61
|
/**
|
|
47
62
|
* Ancestor we subscribed `cds-custom-aichat-trigger-change` on. Scoping the
|
|
@@ -58,6 +73,7 @@ declare class AutocompleteControllerElement extends LitElement {
|
|
|
58
73
|
private _selectItem;
|
|
59
74
|
private _sendItem;
|
|
60
75
|
private _handleMousedown;
|
|
76
|
+
private _handleAutocompleteNavigated;
|
|
61
77
|
private _handleTriggerChange;
|
|
62
78
|
}
|
|
63
79
|
declare global {
|