@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.
Files changed (172) hide show
  1. package/custom-elements.json +2358 -1973
  2. package/es/components/card/src/card-footer.scss.js +1 -1
  3. package/es/components/card/src/card-steps.scss.js +1 -1
  4. package/es/components/card/src/card.scss.js +1 -1
  5. package/es/components/chat-button/src/chat-button.scss.js +1 -1
  6. package/es/components/chat-history/src/history-panel-item-input.js +0 -1
  7. package/es/components/chat-history/src/history-panel-item-input.js.map +1 -1
  8. package/es/components/code-snippet/src/codemirror/language-controller.js +1 -1
  9. package/es/components/code-snippet/src/codemirror/language-controller.js.map +1 -1
  10. package/es/components/file-uploads/src/file-upload-item.d.ts +14 -1
  11. package/es/components/file-uploads/src/file-upload-item.js +78 -2
  12. package/es/components/file-uploads/src/file-upload-item.js.map +1 -1
  13. package/es/components/file-uploads/src/file-uploads.d.ts +29 -4
  14. package/es/components/file-uploads/src/file-uploads.js +69 -16
  15. package/es/components/file-uploads/src/file-uploads.js.map +1 -1
  16. package/es/components/launcher/src/launcher.scss.js +1 -1
  17. package/es/components/prompt-line/autocomplete/index.d.ts +1 -1
  18. package/es/components/prompt-line/autocomplete/src/autocomplete.d.ts +6 -0
  19. package/es/components/prompt-line/autocomplete/src/autocomplete.js +37 -11
  20. package/es/components/prompt-line/autocomplete/src/autocomplete.js.map +1 -1
  21. package/es/components/prompt-line/index.d.ts +3 -2
  22. package/es/components/prompt-line/index.js +2 -1
  23. package/es/components/prompt-line/index.js.map +1 -1
  24. package/es/components/prompt-line/src/__tests__/wait-for-rich.d.ts +20 -0
  25. package/es/components/prompt-line/src/autocomplete-controller-element.d.ts +84 -0
  26. package/es/components/prompt-line/src/autocomplete-controller-element.js +262 -0
  27. package/es/components/prompt-line/src/autocomplete-controller-element.js.map +1 -0
  28. package/es/components/prompt-line/src/autocomplete-controller.d.ts +10 -69
  29. package/es/components/prompt-line/src/autocomplete-controller.js +57 -251
  30. package/es/components/prompt-line/src/autocomplete-controller.js.map +1 -1
  31. package/es/components/prompt-line/src/prompt-line-rich-runtime.js +3 -0
  32. package/es/components/prompt-line/src/prompt-line-rich-runtime.js.map +1 -1
  33. package/es/components/prompt-line/src/prompt-line-shell.scss.js +1 -1
  34. package/es/components/prompt-line/src/prompt-line-textarea-runtime.js +0 -5
  35. package/es/components/prompt-line/src/prompt-line-textarea-runtime.js.map +1 -1
  36. package/es/components/prompt-line/src/prompt-line.js +1 -1
  37. package/es/components/prompt-line/src/prompt-line.js.map +1 -1
  38. package/es/components/prompt-line/src/send-control.d.ts +7 -0
  39. package/es/components/prompt-line/src/send-control.js +53 -5
  40. package/es/components/prompt-line/src/send-control.js.map +1 -1
  41. package/es/components/prompt-line/src/tiptap/build-extensions.js +1 -1
  42. package/es/components/prompt-line/src/tiptap/build-extensions.js.map +1 -1
  43. package/es/components/prompt-line/src/tiptap/carbon-autocomplete.d.ts +5 -6
  44. package/es/components/prompt-line/src/tiptap/carbon-autocomplete.js +24 -48
  45. package/es/components/prompt-line/src/tiptap/carbon-autocomplete.js.map +1 -1
  46. package/es/components/prompt-line/src/tiptap/carbon-mention.js +14 -48
  47. package/es/components/prompt-line/src/tiptap/carbon-mention.js.map +1 -1
  48. package/es/components/prompt-line/src/tiptap/carbon-starter-trigger.js +3 -4
  49. package/es/components/prompt-line/src/tiptap/carbon-starter-trigger.js.map +1 -1
  50. package/es/components/prompt-line/src/tiptap/keymap.d.ts +1 -1
  51. package/es/components/prompt-line/src/tiptap/keymap.js +3 -4
  52. package/es/components/prompt-line/src/tiptap/keymap.js.map +1 -1
  53. package/es/components/prompt-line/src/tiptap/render-token-chip.js +0 -1
  54. package/es/components/prompt-line/src/tiptap/render-token-chip.js.map +1 -1
  55. package/es/components/prompt-line/src/tiptap/resolve-config-items.d.ts +18 -0
  56. package/es/components/prompt-line/src/tiptap/resolve-config-items.js +32 -0
  57. package/es/components/prompt-line/src/tiptap/resolve-config-items.js.map +1 -0
  58. package/es/components/prompt-line/src/tiptap/strip-presentation-fields.d.ts +18 -0
  59. package/es/components/prompt-line/src/tiptap/strip-presentation-fields.js +22 -0
  60. package/es/components/prompt-line/src/tiptap/strip-presentation-fields.js.map +1 -0
  61. package/es/components/prompt-line/src/tiptap/trigger-utils.d.ts +12 -8
  62. package/es/components/prompt-line/src/tiptap/trigger-utils.js +16 -1
  63. package/es/components/prompt-line/src/tiptap/trigger-utils.js.map +1 -1
  64. package/es/components/prompt-line/src/tiptap/types.d.ts +11 -3
  65. package/es/components/toolbar/src/toolbar.d.ts +8 -0
  66. package/es/components/toolbar/src/toolbar.js +65 -19
  67. package/es/components/toolbar/src/toolbar.js.map +1 -1
  68. package/es/components/video-player/src/providers/vimeo-provider.js +1 -1
  69. package/es/components/video-player/src/providers/vimeo-provider.js.map +1 -1
  70. package/es/globals/decorators/carbon-element.js +2 -3
  71. package/es/globals/decorators/carbon-element.js.map +1 -1
  72. package/es/globals/utils/aria-announcer-manager.d.ts +56 -0
  73. package/es/globals/utils/aria-announcer-manager.js +46 -1
  74. package/es/globals/utils/aria-announcer-manager.js.map +1 -1
  75. package/es/globals/utils/focus-utils.js +1 -3
  76. package/es/globals/utils/focus-utils.js.map +1 -1
  77. package/es/globals/utils/iconTransform.d.ts +16 -2
  78. package/es/globals/utils/iconTransform.js +22 -1
  79. package/es/globals/utils/iconTransform.js.map +1 -1
  80. package/es/react/hooks/useChatAutocomplete.d.ts +5 -0
  81. package/es/react/hooks/useChatAutocomplete.js +26 -1
  82. package/es/react/hooks/useChatAutocomplete.js.map +1 -1
  83. package/es/react/markdown.js +0 -1
  84. package/es/react/markdown.js.map +1 -1
  85. package/es/typings/overflow-menu.d.ts +4 -0
  86. package/es-custom/components/card/src/card-footer.scss.js +1 -1
  87. package/es-custom/components/card/src/card-steps.scss.js +1 -1
  88. package/es-custom/components/card/src/card.scss.js +1 -1
  89. package/es-custom/components/chat-button/src/chat-button.scss.js +1 -1
  90. package/es-custom/components/chat-history/src/history-panel-item-input.js +0 -1
  91. package/es-custom/components/chat-history/src/history-panel-item-input.js.map +1 -1
  92. package/es-custom/components/code-snippet/src/codemirror/language-controller.js +1 -1
  93. package/es-custom/components/code-snippet/src/codemirror/language-controller.js.map +1 -1
  94. package/es-custom/components/file-uploads/src/file-upload-item.d.ts +14 -1
  95. package/es-custom/components/file-uploads/src/file-upload-item.js +78 -2
  96. package/es-custom/components/file-uploads/src/file-upload-item.js.map +1 -1
  97. package/es-custom/components/file-uploads/src/file-uploads.d.ts +29 -4
  98. package/es-custom/components/file-uploads/src/file-uploads.js +69 -16
  99. package/es-custom/components/file-uploads/src/file-uploads.js.map +1 -1
  100. package/es-custom/components/launcher/src/launcher.scss.js +1 -1
  101. package/es-custom/components/prompt-line/autocomplete/index.d.ts +1 -1
  102. package/es-custom/components/prompt-line/autocomplete/src/autocomplete.d.ts +6 -0
  103. package/es-custom/components/prompt-line/autocomplete/src/autocomplete.js +37 -11
  104. package/es-custom/components/prompt-line/autocomplete/src/autocomplete.js.map +1 -1
  105. package/es-custom/components/prompt-line/index.d.ts +3 -2
  106. package/es-custom/components/prompt-line/index.js +2 -1
  107. package/es-custom/components/prompt-line/index.js.map +1 -1
  108. package/es-custom/components/prompt-line/src/__tests__/wait-for-rich.d.ts +20 -0
  109. package/es-custom/components/prompt-line/src/autocomplete-controller-element.d.ts +84 -0
  110. package/es-custom/components/prompt-line/src/autocomplete-controller-element.js +262 -0
  111. package/es-custom/components/prompt-line/src/autocomplete-controller-element.js.map +1 -0
  112. package/es-custom/components/prompt-line/src/autocomplete-controller.d.ts +10 -69
  113. package/es-custom/components/prompt-line/src/autocomplete-controller.js +57 -251
  114. package/es-custom/components/prompt-line/src/autocomplete-controller.js.map +1 -1
  115. package/es-custom/components/prompt-line/src/prompt-line-rich-runtime.js +3 -0
  116. package/es-custom/components/prompt-line/src/prompt-line-rich-runtime.js.map +1 -1
  117. package/es-custom/components/prompt-line/src/prompt-line-shell.scss.js +1 -1
  118. package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.js +0 -5
  119. package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.js.map +1 -1
  120. package/es-custom/components/prompt-line/src/prompt-line.js +1 -1
  121. package/es-custom/components/prompt-line/src/prompt-line.js.map +1 -1
  122. package/es-custom/components/prompt-line/src/send-control.d.ts +7 -0
  123. package/es-custom/components/prompt-line/src/send-control.js +53 -5
  124. package/es-custom/components/prompt-line/src/send-control.js.map +1 -1
  125. package/es-custom/components/prompt-line/src/tiptap/build-extensions.js +1 -1
  126. package/es-custom/components/prompt-line/src/tiptap/build-extensions.js.map +1 -1
  127. package/es-custom/components/prompt-line/src/tiptap/carbon-autocomplete.d.ts +5 -6
  128. package/es-custom/components/prompt-line/src/tiptap/carbon-autocomplete.js +24 -48
  129. package/es-custom/components/prompt-line/src/tiptap/carbon-autocomplete.js.map +1 -1
  130. package/es-custom/components/prompt-line/src/tiptap/carbon-mention.js +14 -48
  131. package/es-custom/components/prompt-line/src/tiptap/carbon-mention.js.map +1 -1
  132. package/es-custom/components/prompt-line/src/tiptap/carbon-starter-trigger.js +3 -4
  133. package/es-custom/components/prompt-line/src/tiptap/carbon-starter-trigger.js.map +1 -1
  134. package/es-custom/components/prompt-line/src/tiptap/keymap.d.ts +1 -1
  135. package/es-custom/components/prompt-line/src/tiptap/keymap.js +3 -4
  136. package/es-custom/components/prompt-line/src/tiptap/keymap.js.map +1 -1
  137. package/es-custom/components/prompt-line/src/tiptap/render-token-chip.js +0 -1
  138. package/es-custom/components/prompt-line/src/tiptap/render-token-chip.js.map +1 -1
  139. package/es-custom/components/prompt-line/src/tiptap/resolve-config-items.d.ts +18 -0
  140. package/es-custom/components/prompt-line/src/tiptap/resolve-config-items.js +32 -0
  141. package/es-custom/components/prompt-line/src/tiptap/resolve-config-items.js.map +1 -0
  142. package/es-custom/components/prompt-line/src/tiptap/strip-presentation-fields.d.ts +18 -0
  143. package/es-custom/components/prompt-line/src/tiptap/strip-presentation-fields.js +22 -0
  144. package/es-custom/components/prompt-line/src/tiptap/strip-presentation-fields.js.map +1 -0
  145. package/es-custom/components/prompt-line/src/tiptap/trigger-utils.d.ts +12 -8
  146. package/es-custom/components/prompt-line/src/tiptap/trigger-utils.js +16 -1
  147. package/es-custom/components/prompt-line/src/tiptap/trigger-utils.js.map +1 -1
  148. package/es-custom/components/prompt-line/src/tiptap/types.d.ts +11 -3
  149. package/es-custom/components/toolbar/src/toolbar.d.ts +8 -0
  150. package/es-custom/components/toolbar/src/toolbar.js +65 -19
  151. package/es-custom/components/toolbar/src/toolbar.js.map +1 -1
  152. package/es-custom/components/video-player/src/providers/vimeo-provider.js +1 -1
  153. package/es-custom/components/video-player/src/providers/vimeo-provider.js.map +1 -1
  154. package/es-custom/globals/decorators/carbon-element.js +2 -3
  155. package/es-custom/globals/decorators/carbon-element.js.map +1 -1
  156. package/es-custom/globals/utils/aria-announcer-manager.d.ts +56 -0
  157. package/es-custom/globals/utils/aria-announcer-manager.js +46 -1
  158. package/es-custom/globals/utils/aria-announcer-manager.js.map +1 -1
  159. package/es-custom/globals/utils/focus-utils.js +1 -3
  160. package/es-custom/globals/utils/focus-utils.js.map +1 -1
  161. package/es-custom/globals/utils/iconTransform.d.ts +16 -2
  162. package/es-custom/globals/utils/iconTransform.js +22 -1
  163. package/es-custom/globals/utils/iconTransform.js.map +1 -1
  164. package/es-custom/react/hooks/useChatAutocomplete.d.ts +5 -0
  165. package/es-custom/react/hooks/useChatAutocomplete.js +26 -1
  166. package/es-custom/react/hooks/useChatAutocomplete.js.map +1 -1
  167. package/es-custom/react/markdown.js +0 -1
  168. package/es-custom/react/markdown.js.map +1 -1
  169. package/es-custom/typings/overflow-menu.d.ts +4 -0
  170. package/package.json +6 -6
  171. package/scss/_custom-properties.scss +0 -17
  172. package/scss/_tokens-component.scss +1 -2
@@ -1 +1 @@
1
- {"version":3,"file":"prompt-line.js","sources":["../../../../src/components/prompt-line/src/prompt-line.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\n/**\n * `<cds-custom-aichat-prompt-line>` — the editing-surface layer of the chat input\n * stack.\n *\n * It renders a lightweight `<textarea>` by default and **never statically\n * imports `@tiptap/*`**, so chats that don't use advanced input features ship\n * no Tiptap. When the `rich` property is set, or `ensureEditor()` is called,\n * the element dynamically imports a Tiptap runtime and upgrades the surface in\n * place — text, caret, and focus carry over because the textarea holds plain\n * text. Host `extensions` alone do not trigger it; they are staged for whichever\n * surface mounts. The upgrade is **sticky**: once rich, the element stays rich\n * for the rest of its life.\n *\n * Both modes expose the same imperative API (`getEditor`, `setContent`,\n * `insertContent`, …) and emit the same events, so the React wrapper and\n * `@carbon/ai-chat`'s `Input` are mode-agnostic. `getEditor()` returns `null`\n * in textarea mode (it's a probe — it never triggers a load); call\n * `ensureEditor()` to force the upgrade and resolve with the live editor.\n *\n * The Carbon Tiptap bundle the rich editor installs — schema, value-sync,\n * typing-indicator, plain-text paste, keymap (`Mod-Enter`/`Enter` →\n * `cds-custom-aichat-prompt-send-intent`), placeholder, undo/redo — lives in\n * [./prompt-line-rich-runtime.ts]. Non-chat hosts wanting Tiptap inside Lit\n * should compose their own element against `@tiptap/core` directly.\n *\n * @element cds-custom-aichat-prompt-line\n *\n * @experimental\n */\n\nimport type { Editor, Extension, JSONContent } from '@tiptap/core';\nimport { css, html, LitElement, unsafeCSS } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport { carbonElement } from '../../../globals/decorators/carbon-element.js';\nimport prefix from '../../../globals/settings.js';\nimport { adoptOnRoot } from '../../shared/dynamic-css-var-sheet.js';\nimport type {\n PromptLineController,\n PromptLineControllerInit,\n SetContentUpdater,\n} from './prompt-line-controller.js';\nimport { TextareaController } from './prompt-line-textarea-runtime.js';\nimport {\n getRichRuntimeIfLoaded,\n loadRichRuntime,\n} from './prompt-line-rich-loader.js';\nimport { getRawText, textOffsetToDocPos } from './tiptap/json-utils.js';\n\nimport styles from './prompt-line.scss?lit';\n\n@carbonElement(`${prefix}-prompt-line`)\nclass PromptLineElement extends LitElement {\n static styles = css`\n ${unsafeCSS(styles)}\n `;\n\n /**\n * Host-supplied Tiptap extensions, appended to the carbon bundle when the\n * rich editor mounts. These are *staged*, not a rich-mode trigger: setting\n * them while in textarea mode does not load Tiptap. Select rich explicitly\n * with `rich` or call `ensureEditor()`; the upgrade mounts with these\n * already installed.\n *\n * A new array is compared by value against the set last supplied, so a config\n * update that rebuilds an equivalent one leaves the live editor and its undo\n * history in place, writing any starter `items`/`isOn` through to storage.\n * Only a genuinely different set recreates the editor, preserving content,\n * selection, and focus but resetting history.\n * Extensions built by `buildCarbonExtensions` compare by their source\n * config; anything you supply directly compares by reference, so memoize\n * those (a fresh instance each render reads as a real change).\n */\n @property({ type: Array, attribute: false })\n extensions: Extension[] = [];\n\n /**\n * Initial / current content. Accepts Tiptap-native JSONContent or a plain\n * string. In textarea mode JSONContent is flattened to plain text.\n */\n @property({ type: Object, attribute: false })\n content?: JSONContent | string;\n\n /**\n * Selects the rich Tiptap editor. The element lazy-loads Tiptap and upgrades\n * the textarea in place; the upgrade is sticky (clearing `rich` later keeps\n * the editor). Defaults to the textarea.\n */\n @property({ type: Boolean, reflect: true })\n rich = false;\n\n /** Disables editing. The surface stays mounted but non-editable. */\n @property({ type: Boolean, reflect: true })\n disabled = false;\n\n /** Placeholder text shown when the surface is empty. */\n @property({ type: String })\n placeholder = '';\n\n /** Accessible label for the editing surface. */\n @property({ type: String, attribute: 'aria-label', reflect: true })\n override ariaLabel = 'Message';\n\n /** Test id, applied to the inner editable element. */\n @property({ type: String, attribute: 'test-id' })\n testId = '';\n\n /** Focus the surface on mount. */\n @property({ type: Boolean })\n override autofocus = false;\n\n private _controller: PromptLineController | null = null;\n private _mode: 'textarea' | 'rich' = 'textarea';\n private _editorHost: HTMLElement | null = null;\n private _lastExtensionsRef: Extension[] | null = null;\n /**\n * The `content` value the current surface was seeded with, and whether that\n * seed is still unconsumed. Both are needed: the value catches the echo, and\n * the latch releases after one `updated()` so a later change back to the same\n * value still lands. Comparing on the value alone suppressed it for the life\n * of the surface, dropping `a` in an `a` -> `b` -> `a` sequence.\n */\n private _seededContent?: JSONContent | string;\n private _seedPending = false;\n /** Pending deferred teardown, cancelled if the element is reattached. */\n private _pendingTeardownTimer: ReturnType<typeof setTimeout> | null = null;\n /** Sticky latch — once rich is wanted it never reverts. */\n private _richLatched = false;\n private _upgrading = false;\n /**\n * The element owns the host's composition listeners for both layers — it\n * gates its own textarea→rich upgrade on this, and pushes the state to the\n * active controller via `setComposing` so rich mode can withhold a recreate.\n * One observer, so the two layers cannot disagree.\n */\n private _isComposing = false;\n private _pendingUpgrade = false;\n /**\n * Shared promise for in-flight `ensureEditor()` callers. Created lazily on the\n * first `ensureEditor()` call that needs an upgrade, settled once the rich\n * editor is mounted (`_swapToRich`) or the upgrade can't complete.\n */\n private _richReady: Promise<Editor> | null = null;\n private _resolveRichReady: ((editor: Editor) => void) | null = null;\n private _rejectRichReady: ((reason: Error) => void) | null = null;\n\n // ---------------------------------------------------------------------------\n // Lifecycle\n // ---------------------------------------------------------------------------\n\n override firstUpdated(): void {\n this._initializeSurface();\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n if (this._pendingTeardownTimer !== null) {\n // Reattached before the deferred teardown ran — a move, not an unmount.\n // The controller and its editor host travelled with the element, so the\n // Tiptap instance (and its undo history) survives untouched.\n //\n // Unlike `_teardownSurface`, this deliberately leaves `_isComposing` /\n // `_pendingUpgrade` alone: the host div and its composition listeners are\n // still attached, so a later `compositionend` reaches them and releases\n // whatever was parked. Teardown has to reset eagerly only because it\n // discards the listeners that would otherwise do it.\n clearTimeout(this._pendingTeardownTimer);\n this._pendingTeardownTimer = null;\n const root = this._editorHost?.getRootNode();\n if (root instanceof ShadowRoot || root instanceof Document) {\n adoptOnRoot(root);\n }\n return;\n }\n // Reattached after a real teardown. `firstUpdated` is a one-shot, so\n // without this the element would come back permanently inert.\n if (this._isTornDown()) {\n this._initializeSurface();\n }\n }\n\n override updated(changed: Map<string | number | symbol, unknown>): void {\n if (!this._controller) {\n return;\n }\n if (\n (changed.has('rich') || changed.has('extensions')) &&\n this._wantsRich()\n ) {\n this._richLatched = true;\n if (this._mode === 'textarea') {\n void this._upgradeToRich();\n }\n }\n if (\n changed.has('extensions') &&\n this.extensions !== this._lastExtensionsRef\n ) {\n this._lastExtensionsRef = this.extensions;\n if (this._mode === 'rich') {\n this._controller.setExtensions(this.extensions);\n }\n }\n if (changed.has('disabled')) {\n this._controller.setEditable(!this.disabled);\n }\n // The seed echo is skipped once — re-applying it would emit a spurious\n // host-origin change event. Every later update lands, including one that\n // returns to the seed value, and including one alongside an extensions\n // change (which may no-op or recreate; either way the seed is the previous\n // doc).\n if (changed.has('content')) {\n const echoesSeed =\n this._seedPending && this.content === this._seededContent;\n this._seedPending = false;\n if (!echoesSeed) {\n this._controller.setContent(this.content ?? '');\n }\n }\n if (changed.has('placeholder')) {\n this._controller.setPlaceholder(this.placeholder);\n }\n if (changed.has('testId')) {\n this._controller.setTestId(this.testId);\n }\n if (changed.has('ariaLabel')) {\n this._controller.setAriaLabel(this.ariaLabel);\n }\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n if (!this._controller || this._pendingTeardownTimer !== null) {\n return;\n }\n // Deferred by a task so a reparent — remove and re-append in the same\n // frame — keeps the live editor instead of destroying and rebuilding it.\n // A macrotask rather than a microtask because the reconnect can be\n // scheduled separately from the removal, and rather than a frame callback\n // because those never fire in a background tab, which would leak the\n // editor of a chat that really was unmounted.\n this._pendingTeardownTimer = setTimeout(() => {\n this._pendingTeardownTimer = null;\n this._teardownSurface();\n }, 0);\n }\n\n /** Destroy the editing surface. Deferred from `disconnectedCallback`. */\n private _teardownSurface(): void {\n this._failRichReady(new Error('Input is not currently rendered'));\n this._controller?.destroy();\n this._controller = null;\n this._editorHost?.remove();\n this._editorHost = null;\n this._lastExtensionsRef = null;\n // Back to the default surface. `_richLatched` is the sticky flag, so a late\n // reconnect still comes back rich; leaving `_mode` on 'rich' with no\n // controller would just be a field outliving what it describes.\n this._mode = 'textarea';\n // The host div (and its composition listeners) is gone, so a composition\n // that was in flight can never fire its `compositionend`. Left set, these\n // would park the first upgrade after a reattach forever.\n this._isComposing = false;\n this._pendingUpgrade = false;\n }\n\n /** Mount the editing surface. Runs on first render and on a late reconnect. */\n private _initializeSurface(): void {\n const host = this._mountEditorHost();\n this._lastExtensionsRef = this.extensions;\n this._seededContent = this.content;\n this._seedPending = true;\n this._richLatched = this._wantsRich();\n\n const warmRuntime = this._richLatched ? getRichRuntimeIfLoaded() : null;\n if (warmRuntime) {\n // Runtime already loaded (e.g. preloaded at boot) — mount rich directly,\n // no textarea flash.\n this._mode = 'rich';\n this._controller = warmRuntime.createRichController();\n this._controller.mount(host, this._makeInit());\n } else {\n this._mode = 'textarea';\n this._controller = new TextareaController();\n this._controller.mount(host, this._makeInit());\n if (this._richLatched) {\n void this._upgradeToRich();\n }\n }\n\n if (this.autofocus) {\n // Defer so consumer listeners are attached first.\n Promise.resolve().then(() => this._controller?.focus(false));\n }\n }\n\n override render() {\n return html`\n <div class=\"frame\">\n <slot name=\"editor\"></slot>\n </div>\n `;\n }\n\n // ---------------------------------------------------------------------------\n // Public methods (delegate to the active controller)\n // ---------------------------------------------------------------------------\n\n /** Returns the live Tiptap editor, or `null` in textarea mode. */\n getEditor(): Editor | null {\n return this._controller?.getEditor() ?? null;\n }\n\n /**\n * Lazily load Tiptap (if not already loaded), upgrade the textarea to the\n * rich editor in place, and resolve with the live editor. Resolves\n * immediately when already rich. Rejects when the surface isn't mounted or\n * the runtime can't load (SSR). Concurrent callers share one in-flight\n * upgrade.\n */\n ensureEditor(): Promise<Editor> {\n if (this._mode === 'rich') {\n const editor = this._controller?.getEditor();\n if (editor) {\n return Promise.resolve(editor);\n }\n }\n // Connected but not yet rendered, or already torn down — nothing to upgrade.\n if (!this._editorHost || !this._controller) {\n return Promise.reject(new Error('Input is not currently rendered'));\n }\n this._richLatched = true;\n if (!this._richReady) {\n this._richReady = new Promise<Editor>((resolve, reject) => {\n this._resolveRichReady = resolve;\n this._rejectRichReady = reject;\n });\n }\n void this._upgradeToRich();\n return this._richReady;\n }\n\n /**\n * Current plain-text value. Works in both modes (in rich mode this mirrors\n * `getEditor()?.getText()`), so callers don't need to branch on `getEditor()`\n * being `null`.\n */\n getValue(): string {\n return this._controller?.getValue() ?? '';\n }\n\n override focus(): void {\n this._controller?.focus(false);\n }\n\n override blur(): void {\n this._controller?.blur();\n }\n\n /** Returns `true` if the editing surface currently holds focus. */\n hasFocus(): boolean {\n return this._controller?.hasFocus() ?? false;\n }\n\n clearContent(): void {\n this._controller?.clearContent();\n }\n\n setContent(next: JSONContent | string | SetContentUpdater): void {\n this._controller?.setContent(next);\n }\n\n insertContent(\n content: JSONContent | string,\n opts: { at?: number } = {}\n ): void {\n this._controller?.insertContent(content, opts);\n }\n\n setTextSelection(pos: number | { from: number; to: number }): void {\n this._controller?.setTextSelection(pos);\n }\n\n selectAll(): void {\n this._controller?.selectAll();\n }\n\n undo(): boolean {\n return this._controller?.undo() ?? false;\n }\n\n redo(): boolean {\n return this._controller?.redo() ?? false;\n }\n\n // ---------------------------------------------------------------------------\n // Internals\n // ---------------------------------------------------------------------------\n\n private _wantsRich(): boolean {\n return this._richLatched || this.rich;\n }\n\n /**\n * Rendered once and then torn down — the element is inert until something\n * re-runs the mount path. Distinct from \"not yet rendered\", where Lit's own\n * `firstUpdated` still has it.\n */\n private _isTornDown(): boolean {\n return this.hasUpdated && !this._controller;\n }\n\n private _mountEditorHost(): HTMLElement {\n const host = document.createElement('div');\n host.setAttribute('slot', 'editor');\n host.dataset.aichatEditorHost = '';\n this.appendChild(host);\n this._editorHost = host;\n\n // Defer an upgrade requested mid-IME-composition so we don't tear the\n // field out from under the user.\n host.addEventListener('compositionstart', this._onCompositionStart);\n host.addEventListener('compositionend', this._onCompositionEnd);\n\n const root = host.getRootNode();\n if (root instanceof ShadowRoot || root instanceof Document) {\n adoptOnRoot(root);\n }\n return host;\n }\n\n private _onCompositionStart = (): void => {\n this._isComposing = true;\n this._controller?.setComposing(true);\n };\n\n private _onCompositionEnd = (): void => {\n this._isComposing = false;\n this._controller?.setComposing(false);\n if (this._pendingUpgrade) {\n this._pendingUpgrade = false;\n void this._upgradeToRich();\n }\n };\n\n /** Build the controller init from current props (rich seed by default). */\n private _makeInit(valueOverride?: string): PromptLineControllerInit {\n const value =\n valueOverride ??\n (typeof this.content === 'string'\n ? this.content\n : this.content\n ? getRawText(this.content)\n : '');\n return {\n value,\n // On an upgrade we seed losslessly from the textarea's plain text, so\n // the structured `content` prop is only used for the initial mount.\n content: valueOverride === undefined ? this.content : undefined,\n placeholder: this.placeholder,\n disabled: this.disabled,\n ariaLabel: this.ariaLabel,\n testId: this.testId,\n extensions: this.extensions,\n };\n }\n\n /** Resolve any pending `ensureEditor()` callers with the live editor. */\n private _settleRichReady(): void {\n const editor = this._controller?.getEditor();\n if (editor && this._resolveRichReady) {\n this._resolveRichReady(editor);\n this._resolveRichReady = null;\n this._rejectRichReady = null;\n }\n }\n\n /**\n * Reject any pending `ensureEditor()` callers and clear the shared promise so\n * a later call can retry.\n */\n private _failRichReady(reason: Error): void {\n if (this._rejectRichReady) {\n this._rejectRichReady(reason);\n }\n this._resolveRichReady = null;\n this._rejectRichReady = null;\n this._richReady = null;\n }\n\n /** Lazily load Tiptap and swap the textarea for the rich editor in place. */\n private async _upgradeToRich(): Promise<void> {\n if (this._mode === 'rich' || this._upgrading) {\n return;\n }\n this._upgrading = true;\n try {\n const module = getRichRuntimeIfLoaded() ?? (await loadRichRuntime());\n // Bail if disconnected or runtime unavailable (SSR). The `_upgrading`\n // latch already prevents a concurrent upgrade.\n if (!module || !this._editorHost || !this._controller) {\n this._failRichReady(\n new Error(\n module\n ? 'Input is not currently rendered'\n : 'Input editor runtime is unavailable'\n )\n );\n return;\n }\n if (this._isComposing) {\n // Defer until composition ends; `_richReady` stays pending and settles\n // when `_onCompositionEnd` re-runs the upgrade.\n this._pendingUpgrade = true;\n return;\n }\n this._swapToRich(module.createRichController());\n } catch (error) {\n // A failed runtime load or mount must reject pending `ensureEditor()`\n // callers rather than leave them hanging.\n this._failRichReady(\n error instanceof Error ? error : new Error(String(error))\n );\n } finally {\n this._upgrading = false;\n }\n }\n\n private _swapToRich(rich: PromptLineController): void {\n const previous = this._controller;\n const host = this._editorHost;\n if (!previous || !host) {\n return;\n }\n const value = previous.getValue();\n const selection = previous.getSelection();\n const hadFocus = previous.hasFocus();\n const hadKeyboardFocus = previous.getKeyboardFocus();\n\n previous.destroy();\n this._controller = rich;\n this._mode = 'rich';\n // Seeded losslessly from the textarea's text, which already reflects\n // `content`, so an in-flight identical `content` update stays a no-op.\n this._seededContent = this.content;\n this._seedPending = true;\n rich.mount(host, this._makeInit(value));\n\n rich.setTextSelection({\n from: textOffsetToDocPos(value, selection.from),\n to: textOffsetToDocPos(value, selection.to),\n });\n if (hadFocus) {\n rich.focus(hadKeyboardFocus);\n }\n this._settleRichReady();\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'cds-custom-aichat-prompt-line': PromptLineElement;\n }\n}\n\nexport default PromptLineElement;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;AAOG;AAsDH,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,UAAU,CAAA;AAA1C,IAAA,WAAA,GAAA;;AAKE;;;;;;;;;;;;;;;AAeG;QAEH,IAAA,CAAA,UAAU,GAAgB,EAAE;AAS5B;;;;AAIG;QAEH,IAAA,CAAA,IAAI,GAAG,KAAK;;QAIZ,IAAA,CAAA,QAAQ,GAAG,KAAK;;QAIhB,IAAA,CAAA,WAAW,GAAG,EAAE;;QAIP,IAAA,CAAA,SAAS,GAAG,SAAS;;QAI9B,IAAA,CAAA,MAAM,GAAG,EAAE;;QAIF,IAAA,CAAA,SAAS,GAAG,KAAK;QAElB,IAA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AAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE;AAC7B,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AAIb,UAAA,CAAA;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE;AACzB,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,UAAA,EAAA,MAAA,CAAA;AAIjB,UAAA,CAAA;AADC,IAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;AACT,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,aAAA,EAAA,MAAA,CAAA;AAIR,UAAA,CAAA;AADR,IAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE;AACnC,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,WAAA,EAAA,MAAA,CAAA;AAI/B,UAAA,CAAA;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE;AACpC,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;AAIH,UAAA,CAAA;AADR,IAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE;AACA,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,WAAA,EAAA,MAAA,CAAA;AAzDvB,iBAAiB,GAAA,UAAA,CAAA;AADtB,IAAA,aAAa,CAAC,CAAA,EAAG,MAAM,CAAA,YAAA,CAAc;AAChC,CAAA,EAAA,iBAAiB,CAyftB;AAQD,0BAAe,iBAAiB;;"}
1
+ {"version":3,"file":"prompt-line.js","sources":["../../../../src/components/prompt-line/src/prompt-line.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\n/**\n * `<cds-custom-aichat-prompt-line>` — the editing-surface layer of the chat input\n * stack.\n *\n * It renders a lightweight `<textarea>` by default and **never statically\n * imports `@tiptap/*`**, so chats that don't use advanced input features ship\n * no Tiptap. When the `rich` property is set, or `ensureEditor()` is called,\n * the element dynamically imports a Tiptap runtime and upgrades the surface in\n * place — text, caret, and focus carry over because the textarea holds plain\n * text. Host `extensions` alone do not trigger it; they are staged for whichever\n * surface mounts. The upgrade is **sticky**: once rich, the element stays rich\n * for the rest of its life.\n *\n * Both modes expose the same imperative API (`getEditor`, `setContent`,\n * `insertContent`, …) and emit the same events, so the React wrapper and\n * `@carbon/ai-chat`'s `Input` are mode-agnostic. `getEditor()` returns `null`\n * in textarea mode (it's a probe — it never triggers a load); call\n * `ensureEditor()` to force the upgrade and resolve with the live editor.\n *\n * The Carbon Tiptap bundle the rich editor installs — schema, value-sync,\n * typing-indicator, plain-text paste, keymap (`Mod-Enter`/`Enter` →\n * `cds-custom-aichat-prompt-send-intent`), placeholder, undo/redo — lives in\n * [./prompt-line-rich-runtime.ts]. Non-chat hosts wanting Tiptap inside Lit\n * should compose their own element against `@tiptap/core` directly.\n *\n * @element cds-custom-aichat-prompt-line\n *\n * @experimental\n */\n\nimport type { Editor, Extension, JSONContent } from '@tiptap/core';\nimport { css, html, LitElement, unsafeCSS } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport { carbonElement } from '../../../globals/decorators/carbon-element.js';\nimport prefix from '../../../globals/settings.js';\nimport { adoptOnRoot } from '../../shared/dynamic-css-var-sheet.js';\nimport type {\n PromptLineController,\n PromptLineControllerInit,\n SetContentUpdater,\n} from './prompt-line-controller.js';\nimport { TextareaController } from './prompt-line-textarea-runtime.js';\nimport {\n getRichRuntimeIfLoaded,\n loadRichRuntime,\n} from './prompt-line-rich-loader.js';\nimport { getRawText, textOffsetToDocPos } from './tiptap/json-utils.js';\n\nimport styles from './prompt-line.scss?lit';\n\n@carbonElement(`${prefix}-prompt-line`)\nclass PromptLineElement extends LitElement {\n static styles = css`\n ${unsafeCSS(styles)}\n `;\n\n /**\n * Host-supplied Tiptap extensions, appended to the carbon bundle when the\n * rich editor mounts. These are *staged*, not a rich-mode trigger: setting\n * them while in textarea mode does not load Tiptap. Select rich explicitly\n * with `rich` or call `ensureEditor()`; the upgrade mounts with these\n * already installed.\n *\n * A new array is compared by value against the set last supplied, so a config\n * update that rebuilds an equivalent one leaves the live editor and its undo\n * history in place, writing any starter `items`/`isOn` through to storage.\n * Only a genuinely different set recreates the editor, preserving content,\n * selection, and focus but resetting history.\n * Extensions built by `buildCarbonExtensions` compare by their source\n * config; anything you supply directly compares by reference, so memoize\n * those (a fresh instance each render reads as a real change).\n */\n @property({ type: Array, attribute: false })\n extensions: Extension[] = [];\n\n /**\n * Initial / current content. Accepts Tiptap-native JSONContent or a plain\n * string. In textarea mode JSONContent is flattened to plain text.\n */\n @property({ type: Object, attribute: false })\n content?: JSONContent | string;\n\n /**\n * Selects the rich Tiptap editor. The element lazy-loads Tiptap and upgrades\n * the textarea in place; the upgrade is sticky (clearing `rich` later keeps\n * the editor). Defaults to the textarea.\n */\n @property({ type: Boolean, reflect: true })\n rich = false;\n\n /** Disables editing. The surface stays mounted but non-editable. */\n @property({ type: Boolean, reflect: true })\n disabled = false;\n\n /** Placeholder text shown when the surface is empty. */\n @property({ type: String })\n placeholder = '';\n\n /** Accessible label for the editing surface. */\n @property({ type: String, attribute: 'aria-label', reflect: true })\n override ariaLabel = 'Message';\n\n /** Test id, applied to the inner editable element. */\n @property({ type: String, attribute: 'test-id' })\n testId = '';\n\n /** Focus the surface on mount. */\n @property({ type: Boolean })\n override autofocus = false;\n\n private _controller: PromptLineController | null = null;\n private _mode: 'textarea' | 'rich' = 'textarea';\n private _editorHost: HTMLElement | null = null;\n private _lastExtensionsRef: Extension[] | null = null;\n /**\n * The `content` value the current surface was seeded with, and whether that\n * seed is still unconsumed. Both are needed: the value catches the echo, and\n * the latch releases after one `updated()` so a later change back to the same\n * value still lands. Comparing on the value alone suppressed it for the life\n * of the surface, dropping `a` in an `a` -> `b` -> `a` sequence.\n */\n private _seededContent?: JSONContent | string;\n private _seedPending = false;\n /** Pending deferred teardown, cancelled if the element is reattached. */\n private _pendingTeardownTimer: ReturnType<typeof setTimeout> | null = null;\n /** Sticky latch — once rich is wanted it never reverts. */\n private _richLatched = false;\n private _upgrading = false;\n /**\n * The element owns the host's composition listeners for both layers — it\n * gates its own textarea→rich upgrade on this, and pushes the state to the\n * active controller via `setComposing` so rich mode can withhold a recreate.\n * One observer, so the two layers cannot disagree.\n */\n private _isComposing = false;\n private _pendingUpgrade = false;\n /**\n * Shared promise for in-flight `ensureEditor()` callers. Created lazily on the\n * first `ensureEditor()` call that needs an upgrade, settled once the rich\n * editor is mounted (`_swapToRich`) or the upgrade can't complete.\n */\n private _richReady: Promise<Editor> | null = null;\n private _resolveRichReady: ((editor: Editor) => void) | null = null;\n private _rejectRichReady: ((reason: Error) => void) | null = null;\n\n // ---------------------------------------------------------------------------\n // Lifecycle\n // ---------------------------------------------------------------------------\n\n override firstUpdated(): void {\n this._initializeSurface();\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n if (this._pendingTeardownTimer !== null) {\n // Reattached before the deferred teardown ran — a move, not an unmount.\n // The controller and its editor host traveled with the element, so the\n // Tiptap instance (and its undo history) survives untouched.\n //\n // Unlike `_teardownSurface`, this deliberately leaves `_isComposing` /\n // `_pendingUpgrade` alone: the host div and its composition listeners are\n // still attached, so a later `compositionend` reaches them and releases\n // whatever was parked. Teardown has to reset eagerly only because it\n // discards the listeners that would otherwise do it.\n clearTimeout(this._pendingTeardownTimer);\n this._pendingTeardownTimer = null;\n const root = this._editorHost?.getRootNode();\n if (root instanceof ShadowRoot || root instanceof Document) {\n adoptOnRoot(root);\n }\n return;\n }\n // Reattached after a real teardown. `firstUpdated` is a one-shot, so\n // without this the element would come back permanently inert.\n if (this._isTornDown()) {\n this._initializeSurface();\n }\n }\n\n override updated(changed: Map<string | number | symbol, unknown>): void {\n if (!this._controller) {\n return;\n }\n if (\n (changed.has('rich') || changed.has('extensions')) &&\n this._wantsRich()\n ) {\n this._richLatched = true;\n if (this._mode === 'textarea') {\n void this._upgradeToRich();\n }\n }\n if (\n changed.has('extensions') &&\n this.extensions !== this._lastExtensionsRef\n ) {\n this._lastExtensionsRef = this.extensions;\n if (this._mode === 'rich') {\n this._controller.setExtensions(this.extensions);\n }\n }\n if (changed.has('disabled')) {\n this._controller.setEditable(!this.disabled);\n }\n // The seed echo is skipped once — re-applying it would emit a spurious\n // host-origin change event. Every later update lands, including one that\n // returns to the seed value, and including one alongside an extensions\n // change (which may no-op or recreate; either way the seed is the previous\n // doc).\n if (changed.has('content')) {\n const echoesSeed =\n this._seedPending && this.content === this._seededContent;\n this._seedPending = false;\n if (!echoesSeed) {\n this._controller.setContent(this.content ?? '');\n }\n }\n if (changed.has('placeholder')) {\n this._controller.setPlaceholder(this.placeholder);\n }\n if (changed.has('testId')) {\n this._controller.setTestId(this.testId);\n }\n if (changed.has('ariaLabel')) {\n this._controller.setAriaLabel(this.ariaLabel);\n }\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n if (!this._controller || this._pendingTeardownTimer !== null) {\n return;\n }\n // Deferred by a task so a reparent — remove and re-append in the same\n // frame — keeps the live editor instead of destroying and rebuilding it.\n // A macrotask rather than a microtask because the reconnect can be\n // scheduled separately from the removal, and rather than a frame callback\n // because those never fire in a background tab, which would leak the\n // editor of a chat that really was unmounted.\n this._pendingTeardownTimer = setTimeout(() => {\n this._pendingTeardownTimer = null;\n this._teardownSurface();\n }, 0);\n }\n\n /** Destroy the editing surface. Deferred from `disconnectedCallback`. */\n private _teardownSurface(): void {\n this._failRichReady(new Error('Input is not currently rendered'));\n this._controller?.destroy();\n this._controller = null;\n this._editorHost?.remove();\n this._editorHost = null;\n this._lastExtensionsRef = null;\n // Back to the default surface. `_richLatched` is the sticky flag, so a late\n // reconnect still comes back rich; leaving `_mode` on 'rich' with no\n // controller would just be a field outliving what it describes.\n this._mode = 'textarea';\n // The host div (and its composition listeners) is gone, so a composition\n // that was in flight can never fire its `compositionend`. Left set, these\n // would park the first upgrade after a reattach forever.\n this._isComposing = false;\n this._pendingUpgrade = false;\n }\n\n /** Mount the editing surface. Runs on first render and on a late reconnect. */\n private _initializeSurface(): void {\n const host = this._mountEditorHost();\n this._lastExtensionsRef = this.extensions;\n this._seededContent = this.content;\n this._seedPending = true;\n this._richLatched = this._wantsRich();\n\n const warmRuntime = this._richLatched ? getRichRuntimeIfLoaded() : null;\n if (warmRuntime) {\n // Runtime already loaded (e.g. preloaded at boot) — mount rich directly,\n // no textarea flash.\n this._mode = 'rich';\n this._controller = warmRuntime.createRichController();\n this._controller.mount(host, this._makeInit());\n } else {\n this._mode = 'textarea';\n this._controller = new TextareaController();\n this._controller.mount(host, this._makeInit());\n if (this._richLatched) {\n void this._upgradeToRich();\n }\n }\n\n if (this.autofocus) {\n // Defer so consumer listeners are attached first.\n Promise.resolve().then(() => this._controller?.focus(false));\n }\n }\n\n override render() {\n return html`\n <div class=\"frame\">\n <slot name=\"editor\"></slot>\n </div>\n `;\n }\n\n // ---------------------------------------------------------------------------\n // Public methods (delegate to the active controller)\n // ---------------------------------------------------------------------------\n\n /** Returns the live Tiptap editor, or `null` in textarea mode. */\n getEditor(): Editor | null {\n return this._controller?.getEditor() ?? null;\n }\n\n /**\n * Lazily load Tiptap (if not already loaded), upgrade the textarea to the\n * rich editor in place, and resolve with the live editor. Resolves\n * immediately when already rich. Rejects when the surface isn't mounted or\n * the runtime can't load (SSR). Concurrent callers share one in-flight\n * upgrade.\n */\n ensureEditor(): Promise<Editor> {\n if (this._mode === 'rich') {\n const editor = this._controller?.getEditor();\n if (editor) {\n return Promise.resolve(editor);\n }\n }\n // Connected but not yet rendered, or already torn down — nothing to upgrade.\n if (!this._editorHost || !this._controller) {\n return Promise.reject(new Error('Input is not currently rendered'));\n }\n this._richLatched = true;\n if (!this._richReady) {\n this._richReady = new Promise<Editor>((resolve, reject) => {\n this._resolveRichReady = resolve;\n this._rejectRichReady = reject;\n });\n }\n void this._upgradeToRich();\n return this._richReady;\n }\n\n /**\n * Current plain-text value. Works in both modes (in rich mode this mirrors\n * `getEditor()?.getText()`), so callers don't need to branch on `getEditor()`\n * being `null`.\n */\n getValue(): string {\n return this._controller?.getValue() ?? '';\n }\n\n override focus(): void {\n this._controller?.focus(false);\n }\n\n override blur(): void {\n this._controller?.blur();\n }\n\n /** Returns `true` if the editing surface currently holds focus. */\n hasFocus(): boolean {\n return this._controller?.hasFocus() ?? false;\n }\n\n clearContent(): void {\n this._controller?.clearContent();\n }\n\n setContent(next: JSONContent | string | SetContentUpdater): void {\n this._controller?.setContent(next);\n }\n\n insertContent(\n content: JSONContent | string,\n opts: { at?: number } = {}\n ): void {\n this._controller?.insertContent(content, opts);\n }\n\n setTextSelection(pos: number | { from: number; to: number }): void {\n this._controller?.setTextSelection(pos);\n }\n\n selectAll(): void {\n this._controller?.selectAll();\n }\n\n undo(): boolean {\n return this._controller?.undo() ?? false;\n }\n\n redo(): boolean {\n return this._controller?.redo() ?? false;\n }\n\n // ---------------------------------------------------------------------------\n // Internals\n // ---------------------------------------------------------------------------\n\n private _wantsRich(): boolean {\n return this._richLatched || this.rich;\n }\n\n /**\n * Rendered once and then torn down — the element is inert until something\n * re-runs the mount path. Distinct from \"not yet rendered\", where Lit's own\n * `firstUpdated` still has it.\n */\n private _isTornDown(): boolean {\n return this.hasUpdated && !this._controller;\n }\n\n private _mountEditorHost(): HTMLElement {\n const host = document.createElement('div');\n host.setAttribute('slot', 'editor');\n host.dataset.aichatEditorHost = '';\n this.appendChild(host);\n this._editorHost = host;\n\n // Defer an upgrade requested mid-IME-composition so we don't tear the\n // field out from under the user.\n host.addEventListener('compositionstart', this._onCompositionStart);\n host.addEventListener('compositionend', this._onCompositionEnd);\n\n const root = host.getRootNode();\n if (root instanceof ShadowRoot || root instanceof Document) {\n adoptOnRoot(root);\n }\n return host;\n }\n\n private _onCompositionStart = (): void => {\n this._isComposing = true;\n this._controller?.setComposing(true);\n };\n\n private _onCompositionEnd = (): void => {\n this._isComposing = false;\n this._controller?.setComposing(false);\n if (this._pendingUpgrade) {\n this._pendingUpgrade = false;\n void this._upgradeToRich();\n }\n };\n\n /** Build the controller init from current props (rich seed by default). */\n private _makeInit(valueOverride?: string): PromptLineControllerInit {\n const value =\n valueOverride ??\n (typeof this.content === 'string'\n ? this.content\n : this.content\n ? getRawText(this.content)\n : '');\n return {\n value,\n // On an upgrade we seed losslessly from the textarea's plain text, so\n // the structured `content` prop is only used for the initial mount.\n content: valueOverride === undefined ? this.content : undefined,\n placeholder: this.placeholder,\n disabled: this.disabled,\n ariaLabel: this.ariaLabel,\n testId: this.testId,\n extensions: this.extensions,\n };\n }\n\n /** Resolve any pending `ensureEditor()` callers with the live editor. */\n private _settleRichReady(): void {\n const editor = this._controller?.getEditor();\n if (editor && this._resolveRichReady) {\n this._resolveRichReady(editor);\n this._resolveRichReady = null;\n this._rejectRichReady = null;\n }\n }\n\n /**\n * Reject any pending `ensureEditor()` callers and clear the shared promise so\n * a later call can retry.\n */\n private _failRichReady(reason: Error): void {\n if (this._rejectRichReady) {\n this._rejectRichReady(reason);\n }\n this._resolveRichReady = null;\n this._rejectRichReady = null;\n this._richReady = null;\n }\n\n /** Lazily load Tiptap and swap the textarea for the rich editor in place. */\n private async _upgradeToRich(): Promise<void> {\n if (this._mode === 'rich' || this._upgrading) {\n return;\n }\n this._upgrading = true;\n try {\n const module = getRichRuntimeIfLoaded() ?? (await loadRichRuntime());\n // Bail if disconnected or runtime unavailable (SSR). The `_upgrading`\n // latch already prevents a concurrent upgrade.\n if (!module || !this._editorHost || !this._controller) {\n this._failRichReady(\n new Error(\n module\n ? 'Input is not currently rendered'\n : 'Input editor runtime is unavailable'\n )\n );\n return;\n }\n if (this._isComposing) {\n // Defer until composition ends; `_richReady` stays pending and settles\n // when `_onCompositionEnd` re-runs the upgrade.\n this._pendingUpgrade = true;\n return;\n }\n this._swapToRich(module.createRichController());\n } catch (error) {\n // A failed runtime load or mount must reject pending `ensureEditor()`\n // callers rather than leave them hanging.\n this._failRichReady(\n error instanceof Error ? error : new Error(String(error))\n );\n } finally {\n this._upgrading = false;\n }\n }\n\n private _swapToRich(rich: PromptLineController): void {\n const previous = this._controller;\n const host = this._editorHost;\n if (!previous || !host) {\n return;\n }\n const value = previous.getValue();\n const selection = previous.getSelection();\n const hadFocus = previous.hasFocus();\n const hadKeyboardFocus = previous.getKeyboardFocus();\n\n previous.destroy();\n this._controller = rich;\n this._mode = 'rich';\n // Seeded losslessly from the textarea's text, which already reflects\n // `content`, so an in-flight identical `content` update stays a no-op.\n this._seededContent = this.content;\n this._seedPending = true;\n rich.mount(host, this._makeInit(value));\n\n rich.setTextSelection({\n from: textOffsetToDocPos(value, selection.from),\n to: textOffsetToDocPos(value, selection.to),\n });\n if (hadFocus) {\n rich.focus(hadKeyboardFocus);\n }\n this._settleRichReady();\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'cds-custom-aichat-prompt-line': PromptLineElement;\n }\n}\n\nexport default PromptLineElement;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;AAOG;AAsDH,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,UAAU,CAAA;AAA1C,IAAA,WAAA,GAAA;;AAKE;;;;;;;;;;;;;;;AAeG;QAEH,IAAA,CAAA,UAAU,GAAgB,EAAE;AAS5B;;;;AAIG;QAEH,IAAA,CAAA,IAAI,GAAG,KAAK;;QAIZ,IAAA,CAAA,QAAQ,GAAG,KAAK;;QAIhB,IAAA,CAAA,WAAW,GAAG,EAAE;;QAIP,IAAA,CAAA,SAAS,GAAG,SAAS;;QAI9B,IAAA,CAAA,MAAM,GAAG,EAAE;;QAIF,IAAA,CAAA,SAAS,GAAG,KAAK;QAElB,IAAA,CAAA,WAAW,GAAgC,IAAI;QAC/C,IAAA,CAAA,KAAK,GAAwB,UAAU;QACvC,IAAA,CAAA,WAAW,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,EAAA,MAAA,EAAA,MAAA,CAAA;AAIb,UAAA,CAAA;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE;AACzB,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,UAAA,EAAA,MAAA,CAAA;AAIjB,UAAA,CAAA;AADC,IAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;AACT,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,aAAA,EAAA,MAAA,CAAA;AAIR,UAAA,CAAA;AADR,IAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE;AACnC,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,WAAA,EAAA,MAAA,CAAA;AAI/B,UAAA,CAAA;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE;AACpC,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;AAIH,UAAA,CAAA;AADR,IAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE;AACA,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,WAAA,EAAA,MAAA,CAAA;AAzDvB,iBAAiB,GAAA,UAAA,CAAA;AADtB,IAAA,aAAa,CAAC,CAAA,EAAG,MAAM,CAAA,YAAA,CAAc;AAChC,CAAA,EAAA,iBAAiB,CAyftB;AAQD,0BAAe,iBAAiB;;"}
@@ -34,6 +34,13 @@ declare class InputSendControlElement extends LitElement {
34
34
  stopResponseLabel: string;
35
35
  /** Test identifier. */
36
36
  testId?: string;
37
+ private _autocompleteListNavigated;
38
+ private _navigatedAtPointerdown;
39
+ private _autocompleteEventSource;
40
+ connectedCallback(): void;
41
+ disconnectedCallback(): void;
42
+ private _handleAutocompleteNavigated;
43
+ private _handleDocumentPointerdown;
37
44
  private _handleSendClick;
38
45
  private _handleStopStreamingClick;
39
46
  render(): import("lit-html").TemplateResult<1>;
@@ -7,7 +7,7 @@
7
7
 
8
8
  import { __decorate } from 'tslib';
9
9
  import { unsafeCSS, css, LitElement, html } from 'lit';
10
- import { property } from 'lit/decorators.js';
10
+ import { property, state } from 'lit/decorators.js';
11
11
  import { ifDefined } from 'lit/directives/if-defined.js';
12
12
  import { carbonElement } from '../../../globals/decorators/carbon-element.js';
13
13
  import prefix from '../../../globals/settings.js';
@@ -51,8 +51,34 @@ let InputSendControlElement = class InputSendControlElement extends LitElement {
51
51
  this.buttonLabel = 'Send';
52
52
  /** Label for the stop streaming button tooltip. */
53
53
  this.stopResponseLabel = 'Stop response';
54
- this._handleSendClick = () => {
55
- if (this.disabled || this.disableSend || !this.hasValidInput) {
54
+ this._autocompleteListNavigated = false;
55
+ // Latches navigated state at gesture start; focusout can clear the live flag
56
+ // before click fires, so this preserves the blocked state through click.
57
+ this._navigatedAtPointerdown = false;
58
+ // Autocomplete is a sibling; listen on the shared shell ancestor.
59
+ this._autocompleteEventSource = null;
60
+ this._handleAutocompleteNavigated = (event) => {
61
+ this._autocompleteListNavigated = event.detail.navigated;
62
+ };
63
+ this._handleDocumentPointerdown = (event) => {
64
+ if (!event.composedPath().includes(this)) {
65
+ return;
66
+ }
67
+ const navigated = this._autocompleteListNavigated;
68
+ // Sync on every gesture so a cancelled gesture doesn't leave a stale latch.
69
+ this._navigatedAtPointerdown = navigated;
70
+ if (navigated) {
71
+ // Suppress focus-activation so the editor stays focused and the live flag
72
+ // remains true through the subsequent click.
73
+ event.preventDefault();
74
+ }
75
+ };
76
+ this._handleSendClick = (event) => {
77
+ // detail === 0 for keyboard/assistive clicks — don't block those.
78
+ const blocked = (event.detail > 0 && this._navigatedAtPointerdown) ||
79
+ this._autocompleteListNavigated;
80
+ this._navigatedAtPointerdown = false;
81
+ if (this.disabled || this.disableSend || blocked || !this.hasValidInput) {
56
82
  return;
57
83
  }
58
84
  this.dispatchEvent(new CustomEvent('cds-custom-aichat-input-send', {
@@ -67,10 +93,29 @@ let InputSendControlElement = class InputSendControlElement extends LitElement {
67
93
  }));
68
94
  };
69
95
  }
96
+ connectedCallback() {
97
+ super.connectedCallback();
98
+ this._autocompleteEventSource =
99
+ this.closest(`${prefix}-prompt-line-shell`) ?? this.parentElement;
100
+ this._autocompleteEventSource?.addEventListener('cds-custom-aichat-autocomplete-navigated', this._handleAutocompleteNavigated);
101
+ // Capture phase: fires before focus-activation and before pointer-events:none
102
+ // on the disabled button suppresses the event.
103
+ document.addEventListener('pointerdown', this._handleDocumentPointerdown, {
104
+ capture: true,
105
+ });
106
+ }
107
+ disconnectedCallback() {
108
+ super.disconnectedCallback();
109
+ this._autocompleteEventSource?.removeEventListener('cds-custom-aichat-autocomplete-navigated', this._handleAutocompleteNavigated);
110
+ this._autocompleteEventSource = null;
111
+ document.removeEventListener('pointerdown', this._handleDocumentPointerdown, { capture: true });
112
+ }
70
113
  render() {
71
- // Check if RTL direction is set
72
114
  const isRTL = document.dir === 'rtl' || document.documentElement.dir === 'rtl';
73
- const showDisabledSend = !this.hasValidInput || this.disabled || this.disableSend;
115
+ const showDisabledSend = !this.hasValidInput ||
116
+ this.disabled ||
117
+ this.disableSend ||
118
+ this._autocompleteListNavigated;
74
119
  if (this.isStopStreamingButtonVisible) {
75
120
  return html `
76
121
  <cds-custom-aichat-stop-streaming-button
@@ -127,6 +172,9 @@ __decorate([
127
172
  __decorate([
128
173
  property({ type: String, attribute: 'test-id' })
129
174
  ], InputSendControlElement.prototype, "testId", void 0);
175
+ __decorate([
176
+ state()
177
+ ], InputSendControlElement.prototype, "_autocompleteListNavigated", void 0);
130
178
  InputSendControlElement = __decorate([
131
179
  carbonElement(`${prefix}-input-send-control`)
132
180
  ], InputSendControlElement);
@@ -1 +1 @@
1
- {"version":3,"file":"send-control.js","sources":["../../../../src/components/prompt-line/src/send-control.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 } from 'lit/decorators.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\n\nimport { carbonElement } from '../../../globals/decorators/carbon-element.js';\nimport prefix from '../../../globals/settings.js';\n\nimport '@carbon/web-components/es-custom/components/button/index.js';\n\nimport { iconLoader } from '@carbon/web-components/es-custom/globals/internal/icon-loader.js';\nimport Send16 from '@carbon/icons/es/send/16.js';\nimport SendFilled16 from '@carbon/icons/es/send--filled/16.js';\n\nimport {\n BUTTON_KIND,\n BUTTON_SIZE,\n BUTTON_TYPE,\n BUTTON_TOOLTIP_ALIGNMENT,\n BUTTON_TOOLTIP_POSITION,\n} from '@carbon/web-components/es-custom/components/button/defs.js';\n\nimport './stop-streaming-button.js';\n\nimport styles from './send-control.scss?lit';\n\n/**\n * Send control component — renders the send button or stop streaming button.\n *\n * @element cds-custom-aichat-input-send-control\n * @fires {CustomEvent} cds-custom-aichat-input-send - Fired when the send button is clicked\n * @fires {CustomEvent} cds-custom-aichat-input-stop-streaming - Fired when the stop streaming button is clicked\n */\n@carbonElement(`${prefix}-input-send-control`)\nclass InputSendControlElement extends LitElement {\n static styles = css`\n ${unsafeCSS(styles)}\n `;\n\n /** Whether the input has valid content that can be sent. */\n @property({ type: Boolean, attribute: 'has-valid-input' })\n hasValidInput = false;\n\n /** Whether the entire input is disabled. */\n @property({ type: Boolean, attribute: 'disabled' })\n disabled = false;\n\n /** Whether sending is disabled (separate from overall disabled state). */\n @property({ type: Boolean, attribute: 'disable-send' })\n disableSend = false;\n\n /** Show the stop streaming button instead of the send button. */\n @property({ type: Boolean, attribute: 'show-stop-streaming' })\n isStopStreamingButtonVisible = false;\n\n /** Whether the stop streaming button is disabled. */\n @property({ type: Boolean, attribute: 'disable-stop-streaming' })\n isStopStreamingButtonDisabled = false;\n\n /** Label for the send button tooltip. */\n @property({ type: String, attribute: 'button-label' })\n buttonLabel = 'Send';\n\n /** Label for the stop streaming button tooltip. */\n @property({ type: String, attribute: 'stop-response-label' })\n stopResponseLabel = 'Stop response';\n\n /** Test identifier. */\n @property({ type: String, attribute: 'test-id' })\n testId?: string;\n\n private _handleSendClick = () => {\n if (this.disabled || this.disableSend || !this.hasValidInput) {\n return;\n }\n\n this.dispatchEvent(\n new CustomEvent('cds-custom-aichat-input-send', {\n bubbles: true,\n composed: true,\n })\n );\n };\n\n private _handleStopStreamingClick = () => {\n this.dispatchEvent(\n new CustomEvent('cds-custom-aichat-input-stop-streaming', {\n bubbles: true,\n composed: true,\n })\n );\n };\n\n render() {\n // Check if RTL direction is set\n const isRTL =\n document.dir === 'rtl' || document.documentElement.dir === 'rtl';\n\n const showDisabledSend =\n !this.hasValidInput || this.disabled || this.disableSend;\n\n if (this.isStopStreamingButtonVisible) {\n return html`\n <cds-custom-aichat-stop-streaming-button\n label=\"${this.stopResponseLabel}\"\n ?disabled=\"${this.isStopStreamingButtonDisabled}\"\n tooltip-alignment=\"${isRTL ? 'top-left' : 'top-right'}\"\n @click=\"${this._handleStopStreamingClick}\"></cds-custom-aichat-stop-streaming-button>\n `;\n }\n\n return html`\n <cds-custom-button\n class=\"${prefix}--input-send-button\"\n kind=\"${BUTTON_KIND.GHOST}\"\n size=\"${BUTTON_SIZE.SMALL}\"\n type=\"${BUTTON_TYPE.BUTTON}\"\n ?disabled=\"${showDisabledSend}\"\n tooltip-text=\"${this.buttonLabel}\"\n tooltip-alignment=\"${\n isRTL ? BUTTON_TOOLTIP_ALIGNMENT.START : BUTTON_TOOLTIP_ALIGNMENT.END\n }\"\n tooltip-position=\"${BUTTON_TOOLTIP_POSITION.TOP}\"\n @click=\"${this._handleSendClick}\"\n aria-label=\"${this.buttonLabel}\"\n data-testid=\"${ifDefined(this.testId)}\">\n ${\n this.hasValidInput\n ? iconLoader(SendFilled16, { slot: 'icon' })\n : iconLoader(Send16, { slot: 'icon' })\n }\n </cds-custom-button>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'cds-custom-aichat-input-send-control': InputSendControlElement;\n }\n}\n\nexport default InputSendControlElement;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;AAOG;AA2BH;;;;;;AAMG;AAEH,IAAM,uBAAuB,GAA7B,MAAM,uBAAwB,SAAQ,UAAU,CAAA;AAAhD,IAAA,WAAA,GAAA;;;QAOE,IAAA,CAAA,aAAa,GAAG,KAAK;;QAIrB,IAAA,CAAA,QAAQ,GAAG,KAAK;;QAIhB,IAAA,CAAA,WAAW,GAAG,KAAK;;QAInB,IAAA,CAAA,4BAA4B,GAAG,KAAK;;QAIpC,IAAA,CAAA,6BAA6B,GAAG,KAAK;;QAIrC,IAAA,CAAA,WAAW,GAAG,MAAM;;QAIpB,IAAA,CAAA,iBAAiB,GAAG,eAAe;QAM3B,IAAA,CAAA,gBAAgB,GAAG,MAAK;AAC9B,YAAA,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;gBAC5D;YACF;AAEA,YAAA,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,uBAAuB,EAAE;AACvC,gBAAA,OAAO,EAAE,IAAI;AACb,gBAAA,QAAQ,EAAE,IAAI;AACf,aAAA,CAAC,CACH;AACH,QAAA,CAAC;QAEO,IAAA,CAAA,yBAAyB,GAAG,MAAK;AACvC,YAAA,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,iCAAiC,EAAE;AACjD,gBAAA,OAAO,EAAE,IAAI;AACb,gBAAA,QAAQ,EAAE,IAAI;AACf,aAAA,CAAC,CACH;AACH,QAAA,CAAC;IA2CH;IAzCE,MAAM,GAAA;;AAEJ,QAAA,MAAM,KAAK,GACT,QAAQ,CAAC,GAAG,KAAK,KAAK,IAAI,QAAQ,CAAC,eAAe,CAAC,GAAG,KAAK,KAAK;AAElE,QAAA,MAAM,gBAAgB,GACpB,CAAC,IA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EAAG,MAAM,CAAA,mBAAA,CAAqB;AACvC,CAAA,EAAA,uBAAuB,CAoG5B;AAQD,gCAAe,uBAAuB;;"}
1
+ {"version":3,"file":"send-control.js","sources":["../../../../src/components/prompt-line/src/send-control.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';\nimport { ifDefined } from 'lit/directives/if-defined.js';\n\nimport { carbonElement } from '../../../globals/decorators/carbon-element.js';\nimport prefix from '../../../globals/settings.js';\n\nimport '@carbon/web-components/es-custom/components/button/index.js';\n\nimport { iconLoader } from '@carbon/web-components/es-custom/globals/internal/icon-loader.js';\nimport Send16 from '@carbon/icons/es/send/16.js';\nimport SendFilled16 from '@carbon/icons/es/send--filled/16.js';\n\nimport {\n BUTTON_KIND,\n BUTTON_SIZE,\n BUTTON_TYPE,\n BUTTON_TOOLTIP_ALIGNMENT,\n BUTTON_TOOLTIP_POSITION,\n} from '@carbon/web-components/es-custom/components/button/defs.js';\n\nimport './stop-streaming-button.js';\n\nimport styles from './send-control.scss?lit';\n\n/**\n * Send control component — renders the send button or stop streaming button.\n *\n * @element cds-custom-aichat-input-send-control\n * @fires {CustomEvent} cds-custom-aichat-input-send - Fired when the send button is clicked\n * @fires {CustomEvent} cds-custom-aichat-input-stop-streaming - Fired when the stop streaming button is clicked\n */\n@carbonElement(`${prefix}-input-send-control`)\nclass InputSendControlElement extends LitElement {\n static styles = css`\n ${unsafeCSS(styles)}\n `;\n\n /** Whether the input has valid content that can be sent. */\n @property({ type: Boolean, attribute: 'has-valid-input' })\n hasValidInput = false;\n\n /** Whether the entire input is disabled. */\n @property({ type: Boolean, attribute: 'disabled' })\n disabled = false;\n\n /** Whether sending is disabled (separate from overall disabled state). */\n @property({ type: Boolean, attribute: 'disable-send' })\n disableSend = false;\n\n /** Show the stop streaming button instead of the send button. */\n @property({ type: Boolean, attribute: 'show-stop-streaming' })\n isStopStreamingButtonVisible = false;\n\n /** Whether the stop streaming button is disabled. */\n @property({ type: Boolean, attribute: 'disable-stop-streaming' })\n isStopStreamingButtonDisabled = false;\n\n /** Label for the send button tooltip. */\n @property({ type: String, attribute: 'button-label' })\n buttonLabel = 'Send';\n\n /** Label for the stop streaming button tooltip. */\n @property({ type: String, attribute: 'stop-response-label' })\n stopResponseLabel = 'Stop response';\n\n /** Test identifier. */\n @property({ type: String, attribute: 'test-id' })\n testId?: string;\n\n @state()\n private _autocompleteListNavigated = false;\n\n // Latches navigated state at gesture start; focusout can clear the live flag\n // before click fires, so this preserves the blocked state through click.\n private _navigatedAtPointerdown = false;\n\n // Autocomplete is a sibling; listen on the shared shell ancestor.\n private _autocompleteEventSource: EventTarget | null = null;\n\n override connectedCallback(): void {\n super.connectedCallback();\n this._autocompleteEventSource =\n this.closest(`${prefix}-prompt-line-shell`) ?? this.parentElement;\n this._autocompleteEventSource?.addEventListener(\n 'cds-custom-aichat-autocomplete-navigated',\n this._handleAutocompleteNavigated as EventListener\n );\n // Capture phase: fires before focus-activation and before pointer-events:none\n // on the disabled button suppresses the event.\n document.addEventListener('pointerdown', this._handleDocumentPointerdown, {\n capture: true,\n });\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n this._autocompleteEventSource?.removeEventListener(\n 'cds-custom-aichat-autocomplete-navigated',\n this._handleAutocompleteNavigated as EventListener\n );\n this._autocompleteEventSource = null;\n document.removeEventListener(\n 'pointerdown',\n this._handleDocumentPointerdown,\n { capture: true }\n );\n }\n\n private _handleAutocompleteNavigated = (event: Event): void => {\n this._autocompleteListNavigated = (\n event as CustomEvent<{ navigated: boolean }>\n ).detail.navigated;\n };\n\n private _handleDocumentPointerdown = (event: PointerEvent): void => {\n if (!event.composedPath().includes(this)) {\n return;\n }\n const navigated = this._autocompleteListNavigated;\n // Sync on every gesture so a cancelled gesture doesn't leave a stale latch.\n this._navigatedAtPointerdown = navigated;\n if (navigated) {\n // Suppress focus-activation so the editor stays focused and the live flag\n // remains true through the subsequent click.\n event.preventDefault();\n }\n };\n\n private _handleSendClick = (event: MouseEvent) => {\n // detail === 0 for keyboard/assistive clicks — don't block those.\n const blocked =\n (event.detail > 0 && this._navigatedAtPointerdown) ||\n this._autocompleteListNavigated;\n this._navigatedAtPointerdown = false;\n if (this.disabled || this.disableSend || blocked || !this.hasValidInput) {\n return;\n }\n this.dispatchEvent(\n new CustomEvent('cds-custom-aichat-input-send', {\n bubbles: true,\n composed: true,\n })\n );\n };\n\n private _handleStopStreamingClick = () => {\n this.dispatchEvent(\n new CustomEvent('cds-custom-aichat-input-stop-streaming', {\n bubbles: true,\n composed: true,\n })\n );\n };\n\n render() {\n const isRTL =\n document.dir === 'rtl' || document.documentElement.dir === 'rtl';\n\n const showDisabledSend =\n !this.hasValidInput ||\n this.disabled ||\n this.disableSend ||\n this._autocompleteListNavigated;\n\n if (this.isStopStreamingButtonVisible) {\n return html`\n <cds-custom-aichat-stop-streaming-button\n label=\"${this.stopResponseLabel}\"\n ?disabled=\"${this.isStopStreamingButtonDisabled}\"\n tooltip-alignment=\"${isRTL ? 'top-left' : 'top-right'}\"\n @click=\"${this._handleStopStreamingClick}\"></cds-custom-aichat-stop-streaming-button>\n `;\n }\n\n return html`\n <cds-custom-button\n class=\"${prefix}--input-send-button\"\n kind=\"${BUTTON_KIND.GHOST}\"\n size=\"${BUTTON_SIZE.SMALL}\"\n type=\"${BUTTON_TYPE.BUTTON}\"\n ?disabled=\"${showDisabledSend}\"\n tooltip-text=\"${this.buttonLabel}\"\n tooltip-alignment=\"${\n isRTL ? BUTTON_TOOLTIP_ALIGNMENT.START : BUTTON_TOOLTIP_ALIGNMENT.END\n }\"\n tooltip-position=\"${BUTTON_TOOLTIP_POSITION.TOP}\"\n @click=\"${this._handleSendClick}\"\n aria-label=\"${this.buttonLabel}\"\n data-testid=\"${ifDefined(this.testId)}\">\n ${\n this.hasValidInput\n ? iconLoader(SendFilled16, { slot: 'icon' })\n : iconLoader(Send16, { slot: 'icon' })\n }\n </cds-custom-button>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'cds-custom-aichat-input-send-control': InputSendControlElement;\n }\n}\n\nexport default InputSendControlElement;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;AAOG;AA2BH;;;;;;AAMG;AAEH,IAAM,uBAAuB,GAA7B,MAAM,uBAAwB,SAAQ,UAAU,CAAA;AAAhD,IAAA,WAAA,GAAA;;;QAOE,IAAA,CAAA,aAAa,GAAG,KAAK;;QAIrB,IAAA,CAAA,QAAQ,GAAG,KAAK;;QAIhB,IAAA,CAAA,WAAW,GAAG,KAAK;;QAInB,IAAA,CAAA,4BAA4B,GAAG,KAAK;;QAIpC,IAAA,CAAA,6BAA6B,GAAG,KAAK;;QAIrC,IAAA,CAAA,WAAW,GAAG,MAAM;;QAIpB,IAAA,CAAA,iBAAiB,GAAG,eAAe;QAO3B,IAAA,CAAA,0BAA0B,GAAG,KAAK;;;QAIlC,IAAA,CAAA,uBAAuB,GAAG,KAAK;;QAG/B,IAAA,CAAA,wBAAwB,GAAuB,IAAI;AA+BnD,QAAA,IAAA,CAAA,4BAA4B,GAAG,CAAC,KAAY,KAAU;YAC5D,IAAI,CAAC,0BAA0B,GAC7B,KACD,CAAC,MAAM,CAAC,SAAS;AACpB,QAAA,CAAC;AAEO,QAAA,IAAA,CAAA,0BAA0B,GAAG,CAAC,KAAmB,KAAU;YACjE,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;gBACxC;YACF;AACA,YAAA,MAAM,SAAS,GAAG,IAAI,CAAC,0BAA0B;;AAEjD,YAAA,IAAI,CAAC,uBAAuB,GAAG,SAAS;YACxC,IAAI,SAAS,EAAE;;;gBAGb,KAAK,CAAC,cAAc,EAAE;YACxB;AACF,QAAA,CAAC;AAEO,QAAA,IAA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AA,CAAA;AAIrB,UAAA,CAAA;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,qBAAqB,EAAE;AACxB,CAAA,EAAA,uBAAA,CAAA,SAAA,EAAA,mBAAA,EAAA,MAAA,CAAA;AAIpC,UAAA,CAAA;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE;AAChC,CAAA,EAAA,uBAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;AAGR,UAAA,CAAA;AADP,IAAA,KAAK;AACqC,CAAA,EAAA,uBAAA,CAAA,SAAA,EAAA,4BAAA,EAAA,MAAA,CAAA;AAtCvC,uBAAuB,GAAA,UAAA,CAAA;AAD5B,IAAA,aAAa,CAAC,CAAA,EAAG,MAAM,CAAA,mBAAA,CAAqB;AACvC,CAAA,EAAA,uBAAuB,CAqK5B;AAQD,gCAAe,uBAAuB;;"}
@@ -49,7 +49,7 @@ function buildCarbonExtensions(configs) {
49
49
  position: configs.command.triggerPosition === 'start' ? 'start' : 'anywhere',
50
50
  });
51
51
  }
52
- out.push(tagExtensionSource(carbonAutocomplete(configs.autocomplete, excludeTriggers), {
52
+ out.push(tagExtensionSource(carbonAutocomplete(excludeTriggers), {
53
53
  kind: 'autocomplete',
54
54
  config: configs.autocomplete,
55
55
  }));
@@ -1 +1 @@
1
- {"version":3,"file":"build-extensions.js","sources":["../../../../../src/components/prompt-line/src/tiptap/build-extensions.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\n/**\n * Pure helper: translate the chat-domain configs surfaced on\n * `<cds-custom-aichat-prompt-line-shell>` (and `InputConfig`) into a curated Tiptap\n * extension list. Used by the shell's render logic and exposed publicly so\n * direct `<cds-custom-aichat-prompt-line>` consumers can call the same builder\n * without bringing the chrome along.\n *\n * Filters out `undefined` / empty configs so the returned list contains\n * exactly the extensions whose backing config was supplied. Enter-to-send is\n * **not** included here — `<cds-custom-aichat-prompt-line>` bakes `carbonChatEnter`\n * into its own base bundle, so both the textarea and rich surfaces send on\n * Enter without this builder.\n */\n\nimport type { Extension } from '@tiptap/core';\n\nimport {\n carbonAutocomplete,\n type ExcludedTrigger,\n} from './carbon-autocomplete.js';\nimport { carbonCommand, carbonMention } from './carbon-mention.js';\nimport { carbonStarterTrigger } from './carbon-starter-trigger.js';\nimport { tagExtensionSource } from './extension-equivalence.js';\nimport type {\n AutocompleteConfig,\n StartersConfig,\n TriggerSuggestionConfig,\n} from './types.js';\n\n/**\n * The input configs {@link buildCarbonExtensions} turns into Tiptap\n * extensions.\n * Leave a field out to leave its extension out.\n */\nexport interface BuildCarbonExtensionsConfig {\n /** Config for the `@`-style mention picker. Builds {@link carbonMention}. */\n mention?: TriggerSuggestionConfig;\n /** Config for the `/`-style command picker. Builds {@link carbonCommand}. */\n command?: TriggerSuggestionConfig;\n /**\n * Config for live autocomplete. Builds {@link carbonAutocomplete}, set to\n * stand down for whichever mention and command triggers you also pass.\n */\n autocomplete?: AutocompleteConfig;\n /**\n * Config for the starter prompts shown while the editor is empty and\n * focused. Builds {@link carbonStarterTrigger}. An empty `items` list still\n * installs the extension, so you can fill the list later without\n * recreating the editor.\n */\n starters?: StartersConfig;\n}\n\nexport function buildCarbonExtensions(\n configs: BuildCarbonExtensionsConfig\n): Extension[] {\n // Each entry is tagged with the config it was built from so the rich runtime\n // can tell a genuinely different extension set from a rebuilt-but-identical\n // one without recreating the editor. See ./extension-equivalence.ts.\n const out: Extension[] = [];\n if (configs.mention) {\n out.push(\n tagExtensionSource(\n carbonMention(configs.mention) as unknown as Extension,\n {\n kind: 'mention',\n config: configs.mention,\n }\n )\n );\n }\n if (configs.command) {\n out.push(\n tagExtensionSource(\n carbonCommand(configs.command) as unknown as Extension,\n {\n kind: 'command',\n config: configs.command,\n }\n )\n );\n }\n if (configs.autocomplete) {\n const excludeTriggers: ExcludedTrigger[] = [];\n if (configs.mention) {\n excludeTriggers.push({\n char: configs.mention.trigger,\n position:\n configs.mention.triggerPosition === 'start' ? 'start' : 'anywhere',\n });\n }\n if (configs.command) {\n excludeTriggers.push({\n char: configs.command.trigger,\n position:\n configs.command.triggerPosition === 'start' ? 'start' : 'anywhere',\n });\n }\n out.push(\n tagExtensionSource(\n carbonAutocomplete(configs.autocomplete, excludeTriggers),\n {\n kind: 'autocomplete',\n config: configs.autocomplete,\n }\n )\n );\n }\n // Installed whenever `starters` is configured, empty list included: it is how\n // `items`/`isOn` reach the live editor, and omitting it for an empty list\n // shortens the set, which the equivalence check rejects — recreating the\n // editor and dropping its undo history. `maybeEmit` stays silent when empty.\n if (configs.starters) {\n out.push(\n tagExtensionSource(\n carbonStarterTrigger(configs.starters.items, configs.starters.isOn),\n { kind: 'starters', config: configs.starters }\n )\n );\n }\n return out;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;AAOG;AAuDG,SAAU,qBAAqB,CACnC,OAAoC,EAAA;;;;IAKpC,MAAM,GAAG,GAAgB,EAAE;AAC3B,IAAA,IAAI,OAAO,CAAC,OAAO,EAAE;QACnB,GAAG,CAAC,IAAI,CACN,kBAAkB,CAChB,aAAa,CAAC,OAAO,CAAC,OAAO,CAAyB,EACtD;AACE,YAAA,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,OAAO,CAAC,OAAO;AACxB,SAAA,CACF,CACF;IACH;AACA,IAAA,IAAI,OAAO,CAAC,OAAO,EAAE;QACnB,GAAG,CAAC,IAAI,CACN,kBAAkB,CAChB,aAAa,CAAC,OAAO,CAAC,OAAO,CAAyB,EACtD;AACE,YAAA,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,OAAO,CAAC,OAAO;AACxB,SAAA,CACF,CACF;IACH;AACA,IAAA,IAAI,OAAO,CAAC,YAAY,EAAE;QACxB,MAAM,eAAe,GAAsB,EAAE;AAC7C,QAAA,IAAI,OAAO,CAAC,OAAO,EAAE;YACnB,eAAe,CAAC,IAAI,CAAC;AACnB,gBAAA,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO;AAC7B,gBAAA,QAAQ,EACN,OAAO,CAAC,OAAO,CAAC,eAAe,KAAK,OAAO,GAAG,OAAO,GAAG,UAAU;AACrE,aAAA,CAAC;QACJ;AACA,QAAA,IAAI,OAAO,CAAC,OAAO,EAAE;YACnB,eAAe,CAAC,IAAI,CAAC;AACnB,gBAAA,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO;AAC7B,gBAAA,QAAQ,EACN,OAAO,CAAC,OAAO,CAAC,eAAe,KAAK,OAAO,GAAG,OAAO,GAAG,UAAU;AACrE,aAAA,CAAC;QACJ;AACA,QAAA,GAAG,CAAC,IAAI,CACN,kBAAkB,CAChB,kBAAkB,CAAC,OAAO,CAAC,YAAY,EAAE,eAAe,CAAC,EACzD;AACE,YAAA,IAAI,EAAE,cAAc;YACpB,MAAM,EAAE,OAAO,CAAC,YAAY;AAC7B,SAAA,CACF,CACF;IACH;;;;;AAKA,IAAA,IAAI,OAAO,CAAC,QAAQ,EAAE;AACpB,QAAA,GAAG,CAAC,IAAI,CACN,kBAAkB,CAChB,oBAAoB,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EACnE,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,QAAQ,EAAE,CAC/C,CACF;IACH;AACA,IAAA,OAAO,GAAG;AACZ;;"}
1
+ {"version":3,"file":"build-extensions.js","sources":["../../../../../src/components/prompt-line/src/tiptap/build-extensions.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\n/**\n * Pure helper: translate the chat-domain configs surfaced on\n * `<cds-custom-aichat-prompt-line-shell>` (and `InputConfig`) into a curated Tiptap\n * extension list. Used by the shell's render logic and exposed publicly so\n * direct `<cds-custom-aichat-prompt-line>` consumers can call the same builder\n * without bringing the chrome along.\n *\n * Filters out `undefined` / empty configs so the returned list contains\n * exactly the extensions whose backing config was supplied. Enter-to-send is\n * **not** included here — `<cds-custom-aichat-prompt-line>` bakes `carbonChatEnter`\n * into its own base bundle, so both the textarea and rich surfaces send on\n * Enter without this builder.\n */\n\nimport type { Extension } from '@tiptap/core';\n\nimport {\n carbonAutocomplete,\n type ExcludedTrigger,\n} from './carbon-autocomplete.js';\nimport { carbonCommand, carbonMention } from './carbon-mention.js';\nimport { carbonStarterTrigger } from './carbon-starter-trigger.js';\nimport { tagExtensionSource } from './extension-equivalence.js';\nimport type {\n AutocompleteConfig,\n StartersConfig,\n TriggerSuggestionConfig,\n} from './types.js';\n\n/**\n * The input configs {@link buildCarbonExtensions} turns into Tiptap\n * extensions.\n * Leave a field out to leave its extension out.\n */\nexport interface BuildCarbonExtensionsConfig {\n /** Config for the `@`-style mention picker. Builds {@link carbonMention}. */\n mention?: TriggerSuggestionConfig;\n /** Config for the `/`-style command picker. Builds {@link carbonCommand}. */\n command?: TriggerSuggestionConfig;\n /**\n * Config for live autocomplete. Builds {@link carbonAutocomplete}, set to\n * stand down for whichever mention and command triggers you also pass.\n */\n autocomplete?: AutocompleteConfig;\n /**\n * Config for the starter prompts shown while the editor is empty and\n * focused. Builds {@link carbonStarterTrigger}. An empty `items` list still\n * installs the extension, so you can fill the list later without\n * recreating the editor.\n */\n starters?: StartersConfig;\n}\n\nexport function buildCarbonExtensions(\n configs: BuildCarbonExtensionsConfig\n): Extension[] {\n // Each entry is tagged with the config it was built from so the rich runtime\n // can tell a genuinely different extension set from a rebuilt-but-identical\n // one without recreating the editor. See ./extension-equivalence.ts.\n const out: Extension[] = [];\n if (configs.mention) {\n out.push(\n tagExtensionSource(\n carbonMention(configs.mention) as unknown as Extension,\n {\n kind: 'mention',\n config: configs.mention,\n }\n )\n );\n }\n if (configs.command) {\n out.push(\n tagExtensionSource(\n carbonCommand(configs.command) as unknown as Extension,\n {\n kind: 'command',\n config: configs.command,\n }\n )\n );\n }\n if (configs.autocomplete) {\n const excludeTriggers: ExcludedTrigger[] = [];\n if (configs.mention) {\n excludeTriggers.push({\n char: configs.mention.trigger,\n position:\n configs.mention.triggerPosition === 'start' ? 'start' : 'anywhere',\n });\n }\n if (configs.command) {\n excludeTriggers.push({\n char: configs.command.trigger,\n position:\n configs.command.triggerPosition === 'start' ? 'start' : 'anywhere',\n });\n }\n out.push(\n tagExtensionSource(carbonAutocomplete(excludeTriggers), {\n kind: 'autocomplete',\n config: configs.autocomplete,\n })\n );\n }\n // Installed whenever `starters` is configured, empty list included: it is how\n // `items`/`isOn` reach the live editor, and omitting it for an empty list\n // shortens the set, which the equivalence check rejects — recreating the\n // editor and dropping its undo history. `maybeEmit` stays silent when empty.\n if (configs.starters) {\n out.push(\n tagExtensionSource(\n carbonStarterTrigger(configs.starters.items, configs.starters.isOn),\n { kind: 'starters', config: configs.starters }\n )\n );\n }\n return out;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;AAOG;AAuDG,SAAU,qBAAqB,CACnC,OAAoC,EAAA;;;;IAKpC,MAAM,GAAG,GAAgB,EAAE;AAC3B,IAAA,IAAI,OAAO,CAAC,OAAO,EAAE;QACnB,GAAG,CAAC,IAAI,CACN,kBAAkB,CAChB,aAAa,CAAC,OAAO,CAAC,OAAO,CAAyB,EACtD;AACE,YAAA,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,OAAO,CAAC,OAAO;AACxB,SAAA,CACF,CACF;IACH;AACA,IAAA,IAAI,OAAO,CAAC,OAAO,EAAE;QACnB,GAAG,CAAC,IAAI,CACN,kBAAkB,CAChB,aAAa,CAAC,OAAO,CAAC,OAAO,CAAyB,EACtD;AACE,YAAA,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,OAAO,CAAC,OAAO;AACxB,SAAA,CACF,CACF;IACH;AACA,IAAA,IAAI,OAAO,CAAC,YAAY,EAAE;QACxB,MAAM,eAAe,GAAsB,EAAE;AAC7C,QAAA,IAAI,OAAO,CAAC,OAAO,EAAE;YACnB,eAAe,CAAC,IAAI,CAAC;AACnB,gBAAA,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO;AAC7B,gBAAA,QAAQ,EACN,OAAO,CAAC,OAAO,CAAC,eAAe,KAAK,OAAO,GAAG,OAAO,GAAG,UAAU;AACrE,aAAA,CAAC;QACJ;AACA,QAAA,IAAI,OAAO,CAAC,OAAO,EAAE;YACnB,eAAe,CAAC,IAAI,CAAC;AACnB,gBAAA,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO;AAC7B,gBAAA,QAAQ,EACN,OAAO,CAAC,OAAO,CAAC,eAAe,KAAK,OAAO,GAAG,OAAO,GAAG,UAAU;AACrE,aAAA,CAAC;QACJ;QACA,GAAG,CAAC,IAAI,CACN,kBAAkB,CAAC,kBAAkB,CAAC,eAAe,CAAC,EAAE;AACtD,YAAA,IAAI,EAAE,cAAc;YACpB,MAAM,EAAE,OAAO,CAAC,YAAY;AAC7B,SAAA,CAAC,CACH;IACH;;;;;AAKA,IAAA,IAAI,OAAO,CAAC,QAAQ,EAAE;AACpB,QAAA,GAAG,CAAC,IAAI,CACN,kBAAkB,CAChB,oBAAoB,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EACnE,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,QAAQ,EAAE,CAC/C,CACF;IACH;AACA,IAAA,OAAO,GAAG;AACZ;;"}
@@ -8,20 +8,19 @@
8
8
  */
9
9
  /**
10
10
  * `carbonAutocomplete` factory. Wraps `@tiptap/suggestion` directly (no
11
- * Mention node) — the `command` callback inserts plain text rather than a
12
- * schema node. Activates whenever the input has any non-empty text (the
11
+ * Mention node). Activates whenever the input has any non-empty text (the
13
12
  * legacy autocomplete contract).
14
13
  *
15
14
  * Dispatches `cds-custom-aichat-trigger-change` with `type: "autocomplete"` from
16
15
  * the suggestion-render lifecycle via the shared `dispatchTriggerChange`
17
- * helper.
16
+ * helper. Selection is routed through `AutocompleteController.select()` —
17
+ * the `@tiptap/suggestion` `command` hook is intentionally unused.
18
18
  */
19
19
  import { Extension } from '@tiptap/core';
20
- import type { AutocompleteConfig } from './types.js';
21
20
  /**
22
21
  * A trigger character that autocomplete stands down for, so a co-installed
23
22
  * mention or command picker wins while its trigger is active. Pass a list of
24
- * these as the second argument to {@link carbonAutocomplete}.
23
+ * these as the only argument to {@link carbonAutocomplete}.
25
24
  */
26
25
  export interface ExcludedTrigger {
27
26
  /** The character to stand down for, such as `"@"` or `"/"`. */
@@ -34,4 +33,4 @@ export interface ExcludedTrigger {
34
33
  */
35
34
  position: 'anywhere' | 'start';
36
35
  }
37
- export declare function carbonAutocomplete(config: AutocompleteConfig, excludeTriggers?: ExcludedTrigger[]): Extension;
36
+ export declare function carbonAutocomplete(excludeTriggers?: ExcludedTrigger[]): Extension;
@@ -20,15 +20,15 @@ import { dispatchTriggerChange } from './trigger-utils.js';
20
20
  */
21
21
  /**
22
22
  * `carbonAutocomplete` factory. Wraps `@tiptap/suggestion` directly (no
23
- * Mention node) — the `command` callback inserts plain text rather than a
24
- * schema node. Activates whenever the input has any non-empty text (the
23
+ * Mention node). Activates whenever the input has any non-empty text (the
25
24
  * legacy autocomplete contract).
26
25
  *
27
26
  * Dispatches `cds-custom-aichat-trigger-change` with `type: "autocomplete"` from
28
27
  * the suggestion-render lifecycle via the shared `dispatchTriggerChange`
29
- * helper.
28
+ * helper. Selection is routed through `AutocompleteController.select()` —
29
+ * the `@tiptap/suggestion` `command` hook is intentionally unused.
30
30
  */
31
- function carbonAutocomplete(config, excludeTriggers = []) {
31
+ function carbonAutocomplete(excludeTriggers = []) {
32
32
  const pluginKey = new PluginKey('carbonAutocompleteSuggestion');
33
33
  return Extension.create({
34
34
  name: 'carbonAutocomplete',
@@ -47,45 +47,35 @@ function carbonAutocomplete(config, excludeTriggers = []) {
47
47
  if (!text || text.length === 0) {
48
48
  return null;
49
49
  }
50
- // Restrict the query to the trailing word (split on whitespace).
51
- const trailing = /\S+$/.exec(text);
52
- if (!trailing) {
53
- return null;
54
- }
55
- const query = trailing[0];
56
50
  // Yield to co-installed mention/command extensions so they win
57
- // when their trigger char is active.
58
- for (const excluded of excludeTriggers) {
59
- if (!query.startsWith(excluded.char)) {
60
- continue;
61
- }
62
- if (excluded.position === 'anywhere') {
63
- return null;
64
- }
65
- if (text === query) {
66
- return null;
51
+ // when their trigger char is the active (trailing) word.
52
+ const trailing = /\S+$/.exec(text);
53
+ if (trailing) {
54
+ const trailingWord = trailing[0];
55
+ for (const excluded of excludeTriggers) {
56
+ if (!trailingWord.startsWith(excluded.char)) {
57
+ continue;
58
+ }
59
+ if (excluded.position === 'anywhere') {
60
+ return null;
61
+ }
62
+ // text matches an excluded trigger
63
+ if (text === trailingWord) {
64
+ return null;
65
+ }
67
66
  }
68
67
  }
69
- const matchStart = $position.start() + $position.parentOffset - query.length;
68
+ // Use the full paragraph text as the query so spaces are included.
69
+ const matchStart = $position.start();
70
70
  return {
71
71
  range: {
72
72
  from: matchStart,
73
73
  to: $position.start() + $position.parentOffset,
74
74
  },
75
- query,
76
- text: query,
75
+ query: text,
76
+ text,
77
77
  };
78
78
  },
79
- items: ({ query }) => resolveItems(config, query),
80
- command: ({ editor: ed, range, props }) => {
81
- const item = props;
82
- const insertText = item.value ?? item.label;
83
- ed.chain()
84
- .focus()
85
- .insertContentAt(range, [{ type: 'text', text: insertText }])
86
- .run();
87
- config.onSelect?.(item);
88
- },
89
79
  render: () => ({
90
80
  onStart: (props) => {
91
81
  lastQuery = props.query;
@@ -108,7 +98,7 @@ function carbonAutocomplete(config, excludeTriggers = []) {
108
98
  },
109
99
  onExit: (props) => {
110
100
  lastQuery = null;
111
- dispatchTriggerChange(props.editor, null);
101
+ dispatchTriggerChange(props.editor, null, 'autocomplete');
112
102
  },
113
103
  onKeyDown: () => false,
114
104
  }),
@@ -117,20 +107,6 @@ function carbonAutocomplete(config, excludeTriggers = []) {
117
107
  },
118
108
  });
119
109
  }
120
- async function resolveItems(config, query) {
121
- const minQueryLength = config.minQueryLength ?? 0;
122
- if (query.length < minQueryLength) {
123
- return [];
124
- }
125
- if (typeof config.items === 'function') {
126
- return Promise.resolve(config.items(query));
127
- }
128
- if (!query) {
129
- return config.items;
130
- }
131
- const lower = query.toLowerCase();
132
- return config.items.filter((item) => item.label.toLowerCase().includes(lower));
133
- }
134
110
 
135
111
  export { carbonAutocomplete };
136
112
  //# sourceMappingURL=carbon-autocomplete.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"carbon-autocomplete.js","sources":["../../../../../src/components/prompt-line/src/tiptap/carbon-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\n/**\n * `carbonAutocomplete` factory. Wraps `@tiptap/suggestion` directly (no\n * Mention node) — the `command` callback inserts plain text rather than a\n * schema node. Activates whenever the input has any non-empty text (the\n * legacy autocomplete contract).\n *\n * Dispatches `cds-custom-aichat-trigger-change` with `type: \"autocomplete\"` from\n * the suggestion-render lifecycle via the shared `dispatchTriggerChange`\n * helper.\n */\n\nimport { Extension } from '@tiptap/core';\nimport { PluginKey } from '@tiptap/pm/state';\nimport Suggestion from '@tiptap/suggestion';\n\nimport { dispatchTriggerChange } from './trigger-utils.js';\nimport type { AutocompleteConfig, SuggestionItem } from './types.js';\n\n/**\n * A trigger character that autocomplete stands down for, so a co-installed\n * mention or command picker wins while its trigger is active. Pass a list of\n * these as the second argument to {@link carbonAutocomplete}.\n */\nexport interface ExcludedTrigger {\n /** The character to stand down for, such as `\"@\"` or `\"/\"`. */\n char: string;\n /**\n * Where that character has to sit. `\"anywhere\"` stands down for any word\n * starting with it; `\"start\"` stands down only when that word starts the\n * line. Mirrors the picker's own\n * {@link TriggerSuggestionConfig.triggerPosition}.\n */\n position: 'anywhere' | 'start';\n}\n\nexport function carbonAutocomplete(\n config: AutocompleteConfig,\n excludeTriggers: ExcludedTrigger[] = []\n): Extension {\n const pluginKey = new PluginKey('carbonAutocompleteSuggestion');\n\n return Extension.create({\n name: 'carbonAutocomplete',\n\n addProseMirrorPlugins() {\n const editor = this.editor;\n let lastQuery: string | null = null;\n\n return [\n Suggestion<SuggestionItem>({\n editor,\n char: '',\n pluginKey,\n // Match any non-empty text as the autocomplete query.\n allowedPrefixes: null,\n findSuggestionMatch: ({ $position }) => {\n const text = $position.parent.textBetween(\n 0,\n $position.parentOffset,\n '\\n',\n '\\0'\n );\n if (!text || text.length === 0) {\n return null;\n }\n // Restrict the query to the trailing word (split on whitespace).\n const trailing = /\\S+$/.exec(text);\n if (!trailing) {\n return null;\n }\n const query = trailing[0];\n // Yield to co-installed mention/command extensions so they win\n // when their trigger char is active.\n for (const excluded of excludeTriggers) {\n if (!query.startsWith(excluded.char)) {\n continue;\n }\n if (excluded.position === 'anywhere') {\n return null;\n }\n if (text === query) {\n return null;\n }\n }\n const matchStart =\n $position.start() + $position.parentOffset - query.length;\n return {\n range: {\n from: matchStart,\n to: $position.start() + $position.parentOffset,\n },\n query,\n text: query,\n };\n },\n items: ({ query }) => resolveItems(config, query),\n command: ({ editor: ed, range, props }) => {\n const item = props as SuggestionItem;\n const insertText = item.value ?? item.label;\n ed.chain()\n .focus()\n .insertContentAt(range, [{ type: 'text', text: insertText }])\n .run();\n config.onSelect?.(item);\n },\n render: () => ({\n onStart: (props) => {\n lastQuery = props.query;\n dispatchTriggerChange(props.editor, {\n type: 'autocomplete',\n query: props.query,\n triggerOffset: props.range.from,\n });\n },\n onUpdate: (props) => {\n if (props.query === lastQuery) {\n return;\n }\n lastQuery = props.query;\n dispatchTriggerChange(props.editor, {\n type: 'autocomplete',\n query: props.query,\n triggerOffset: props.range.from,\n });\n },\n onExit: (props) => {\n lastQuery = null;\n dispatchTriggerChange(props.editor, null);\n },\n onKeyDown: () => false,\n }),\n }),\n ];\n },\n });\n}\n\nasync function resolveItems(\n config: AutocompleteConfig,\n query: string\n): Promise<SuggestionItem[]> {\n const minQueryLength = config.minQueryLength ?? 0;\n if (query.length < minQueryLength) {\n return [];\n }\n if (typeof config.items === 'function') {\n return Promise.resolve(config.items(query));\n }\n if (!query) {\n return config.items;\n }\n const lower = query.toLowerCase();\n return config.items.filter((item) =>\n item.label.toLowerCase().includes(lower)\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;AAOG;AAEH;;;;;;;;;AASG;SA0Ba,kBAAkB,CAChC,MAA0B,EAC1B,kBAAqC,EAAE,EAAA;AAEvC,IAAA,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,8BAA8B,CAAC;IAE/D,OAAO,SAAS,CAAC,MAAM,CAAC;AACtB,QAAA,IAAI,EAAE,oBAAoB;QAE1B,qBAAqB,GAAA;AACnB,YAAA,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM;YAC1B,IAAI,SAAS,GAAkB,IAAI;YAEnC,OAAO;AACL,gBAAA,UAAU,CAAiB;oBACzB,MAAM;AACN,oBAAA,IAAI,EAAE,EAAE;oBACR,SAAS;;AAET,oBAAA,eAAe,EAAE,IAAI;AACrB,oBAAA,mBAAmB,EAAE,CAAC,EAAE,SAAS,EAAE,KAAI;AACrC,wBAAA,MAAM,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,WAAW,CACvC,CAAC,EACD,SAAS,CAAC,YAAY,EACtB,IAAI,EACJ,IAAI,CACL;wBACD,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;AAC9B,4BAAA,OAAO,IAAI;wBACb;;wBAEA,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;wBAClC,IAAI,CAAC,QAAQ,EAAE;AACb,4BAAA,OAAO,IAAI;wBACb;AACA,wBAAA,MAAM,KAAK,GAAG,QAAQ,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AO,MAAM,CAAC,KAAK;IACrB;AACA,IAAA,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,EAAE;IACjC,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,KAC9B,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CACzC;AACH;;"}
1
+ {"version":3,"file":"carbon-autocomplete.js","sources":["../../../../../src/components/prompt-line/src/tiptap/carbon-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\n/**\n * `carbonAutocomplete` factory. Wraps `@tiptap/suggestion` directly (no\n * Mention node). Activates whenever the input has any non-empty text (the\n * legacy autocomplete contract).\n *\n * Dispatches `cds-custom-aichat-trigger-change` with `type: \"autocomplete\"` from\n * the suggestion-render lifecycle via the shared `dispatchTriggerChange`\n * helper. Selection is routed through `AutocompleteController.select()` —\n * the `@tiptap/suggestion` `command` hook is intentionally unused.\n */\n\nimport { Extension } from '@tiptap/core';\nimport { PluginKey } from '@tiptap/pm/state';\nimport Suggestion from '@tiptap/suggestion';\n\nimport { dispatchTriggerChange } from './trigger-utils.js';\nimport type { SuggestionItem } from './types.js';\n\n/**\n * A trigger character that autocomplete stands down for, so a co-installed\n * mention or command picker wins while its trigger is active. Pass a list of\n * these as the only argument to {@link carbonAutocomplete}.\n */\nexport interface ExcludedTrigger {\n /** The character to stand down for, such as `\"@\"` or `\"/\"`. */\n char: string;\n /**\n * Where that character has to sit. `\"anywhere\"` stands down for any word\n * starting with it; `\"start\"` stands down only when that word starts the\n * line. Mirrors the picker's own\n * {@link TriggerSuggestionConfig.triggerPosition}.\n */\n position: 'anywhere' | 'start';\n}\n\nexport function carbonAutocomplete(\n excludeTriggers: ExcludedTrigger[] = []\n): Extension {\n const pluginKey = new PluginKey('carbonAutocompleteSuggestion');\n\n return Extension.create({\n name: 'carbonAutocomplete',\n\n addProseMirrorPlugins() {\n const editor = this.editor;\n let lastQuery: string | null = null;\n\n return [\n Suggestion<SuggestionItem>({\n editor,\n char: '',\n pluginKey,\n // Match any non-empty text as the autocomplete query.\n allowedPrefixes: null,\n findSuggestionMatch: ({ $position }) => {\n const text = $position.parent.textBetween(\n 0,\n $position.parentOffset,\n '\\n',\n '\\0'\n );\n if (!text || text.length === 0) {\n return null;\n }\n // Yield to co-installed mention/command extensions so they win\n // when their trigger char is the active (trailing) word.\n const trailing = /\\S+$/.exec(text);\n if (trailing) {\n const trailingWord = trailing[0];\n for (const excluded of excludeTriggers) {\n if (!trailingWord.startsWith(excluded.char)) {\n continue;\n }\n if (excluded.position === 'anywhere') {\n return null;\n }\n // text matches an excluded trigger\n if (text === trailingWord) {\n return null;\n }\n }\n }\n // Use the full paragraph text as the query so spaces are included.\n const matchStart = $position.start();\n return {\n range: {\n from: matchStart,\n to: $position.start() + $position.parentOffset,\n },\n query: text,\n text,\n };\n },\n render: () => ({\n onStart: (props) => {\n lastQuery = props.query;\n dispatchTriggerChange(props.editor, {\n type: 'autocomplete',\n query: props.query,\n triggerOffset: props.range.from,\n });\n },\n onUpdate: (props) => {\n if (props.query === lastQuery) {\n return;\n }\n lastQuery = props.query;\n dispatchTriggerChange(props.editor, {\n type: 'autocomplete',\n query: props.query,\n triggerOffset: props.range.from,\n });\n },\n onExit: (props) => {\n lastQuery = null;\n dispatchTriggerChange(props.editor, null, 'autocomplete');\n },\n onKeyDown: () => false,\n }),\n }),\n ];\n },\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;AAOG;AAEH;;;;;;;;;AASG;AA0BG,SAAU,kBAAkB,CAChC,eAAA,GAAqC,EAAE,EAAA;AAEvC,IAAA,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,8BAA8B,CAAC;IAE/D,OAAO,SAAS,CAAC,MAAM,CAAC;AACtB,QAAA,IAAI,EAAE,oBAAoB;QAE1B,qBAAqB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