@carbon/ai-chat-components 1.11.0 → 1.12.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/custom-elements.json +2414 -2161
- package/es/components/card/src/card-footer.scss.js +1 -1
- package/es/components/card/src/card-steps.scss.js +1 -1
- package/es/components/card/src/card.scss.js +1 -1
- package/es/components/chat-button/src/chat-button.scss.js +1 -1
- package/es/components/chat-history/src/history-panel-item-input.js +0 -1
- package/es/components/chat-history/src/history-panel-item-input.js.map +1 -1
- package/es/components/code-snippet/src/codemirror/language-controller.js +1 -1
- package/es/components/code-snippet/src/codemirror/language-controller.js.map +1 -1
- package/es/components/file-uploads/src/file-upload-item.d.ts +14 -1
- package/es/components/file-uploads/src/file-upload-item.js +78 -2
- package/es/components/file-uploads/src/file-upload-item.js.map +1 -1
- package/es/components/file-uploads/src/file-uploads.d.ts +29 -4
- package/es/components/file-uploads/src/file-uploads.js +69 -16
- package/es/components/file-uploads/src/file-uploads.js.map +1 -1
- package/es/components/launcher/src/launcher.scss.js +1 -1
- package/es/components/prompt-line/index.d.ts +3 -2
- package/es/components/prompt-line/index.js +2 -1
- package/es/components/prompt-line/index.js.map +1 -1
- package/es/components/prompt-line/src/__tests__/wait-for-rich.d.ts +20 -0
- package/es/components/prompt-line/src/autocomplete-controller-element.d.ts +68 -0
- package/es/components/prompt-line/src/autocomplete-controller-element.js +221 -0
- package/es/components/prompt-line/src/autocomplete-controller-element.js.map +1 -0
- package/es/components/prompt-line/src/autocomplete-controller.d.ts +10 -69
- package/es/components/prompt-line/src/autocomplete-controller.js +44 -251
- package/es/components/prompt-line/src/autocomplete-controller.js.map +1 -1
- package/es/components/prompt-line/src/prompt-line-rich-runtime.js +3 -0
- package/es/components/prompt-line/src/prompt-line-rich-runtime.js.map +1 -1
- package/es/components/prompt-line/src/prompt-line-shell.scss.js +1 -1
- package/es/components/prompt-line/src/prompt-line-textarea-runtime.js +0 -5
- package/es/components/prompt-line/src/prompt-line-textarea-runtime.js.map +1 -1
- package/es/components/prompt-line/src/prompt-line.js +1 -1
- package/es/components/prompt-line/src/prompt-line.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/build-extensions.js +1 -1
- package/es/components/prompt-line/src/tiptap/build-extensions.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/carbon-autocomplete.d.ts +5 -6
- package/es/components/prompt-line/src/tiptap/carbon-autocomplete.js +4 -28
- package/es/components/prompt-line/src/tiptap/carbon-autocomplete.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/carbon-mention.js +13 -47
- package/es/components/prompt-line/src/tiptap/carbon-mention.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/carbon-starter-trigger.js +3 -4
- package/es/components/prompt-line/src/tiptap/carbon-starter-trigger.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/keymap.d.ts +1 -1
- package/es/components/prompt-line/src/tiptap/keymap.js +3 -4
- package/es/components/prompt-line/src/tiptap/keymap.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/render-token-chip.js +0 -1
- package/es/components/prompt-line/src/tiptap/render-token-chip.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/resolve-config-items.d.ts +18 -0
- package/es/components/prompt-line/src/tiptap/resolve-config-items.js +32 -0
- package/es/components/prompt-line/src/tiptap/resolve-config-items.js.map +1 -0
- package/es/components/prompt-line/src/tiptap/strip-presentation-fields.d.ts +18 -0
- package/es/components/prompt-line/src/tiptap/strip-presentation-fields.js +22 -0
- package/es/components/prompt-line/src/tiptap/strip-presentation-fields.js.map +1 -0
- package/es/components/prompt-line/src/tiptap/types.d.ts +11 -3
- package/es/components/toolbar/src/toolbar.d.ts +8 -0
- package/es/components/toolbar/src/toolbar.js +65 -19
- package/es/components/toolbar/src/toolbar.js.map +1 -1
- package/es/components/video-player/src/providers/vimeo-provider.js +1 -1
- package/es/components/video-player/src/providers/vimeo-provider.js.map +1 -1
- package/es/globals/decorators/carbon-element.js +2 -3
- package/es/globals/decorators/carbon-element.js.map +1 -1
- package/es/globals/utils/aria-announcer-manager.d.ts +56 -0
- package/es/globals/utils/aria-announcer-manager.js +46 -1
- package/es/globals/utils/aria-announcer-manager.js.map +1 -1
- package/es/globals/utils/focus-utils.js +1 -3
- package/es/globals/utils/focus-utils.js.map +1 -1
- package/es/globals/utils/iconTransform.d.ts +16 -2
- package/es/globals/utils/iconTransform.js +22 -1
- package/es/globals/utils/iconTransform.js.map +1 -1
- package/es/react/hooks/useChatAutocomplete.js.map +1 -1
- package/es/react/markdown.js +0 -1
- package/es/react/markdown.js.map +1 -1
- package/es/typings/overflow-menu.d.ts +4 -0
- package/es-custom/components/card/src/card-footer.scss.js +1 -1
- package/es-custom/components/card/src/card-steps.scss.js +1 -1
- package/es-custom/components/card/src/card.scss.js +1 -1
- package/es-custom/components/chat-button/src/chat-button.scss.js +1 -1
- package/es-custom/components/chat-history/src/history-panel-item-input.js +0 -1
- package/es-custom/components/chat-history/src/history-panel-item-input.js.map +1 -1
- package/es-custom/components/code-snippet/src/codemirror/language-controller.js +1 -1
- package/es-custom/components/code-snippet/src/codemirror/language-controller.js.map +1 -1
- package/es-custom/components/file-uploads/src/file-upload-item.d.ts +14 -1
- package/es-custom/components/file-uploads/src/file-upload-item.js +78 -2
- package/es-custom/components/file-uploads/src/file-upload-item.js.map +1 -1
- package/es-custom/components/file-uploads/src/file-uploads.d.ts +29 -4
- package/es-custom/components/file-uploads/src/file-uploads.js +69 -16
- package/es-custom/components/file-uploads/src/file-uploads.js.map +1 -1
- package/es-custom/components/launcher/src/launcher.scss.js +1 -1
- package/es-custom/components/prompt-line/index.d.ts +3 -2
- package/es-custom/components/prompt-line/index.js +2 -1
- package/es-custom/components/prompt-line/index.js.map +1 -1
- package/es-custom/components/prompt-line/src/__tests__/wait-for-rich.d.ts +20 -0
- package/es-custom/components/prompt-line/src/autocomplete-controller-element.d.ts +68 -0
- package/es-custom/components/prompt-line/src/autocomplete-controller-element.js +221 -0
- package/es-custom/components/prompt-line/src/autocomplete-controller-element.js.map +1 -0
- package/es-custom/components/prompt-line/src/autocomplete-controller.d.ts +10 -69
- package/es-custom/components/prompt-line/src/autocomplete-controller.js +44 -251
- package/es-custom/components/prompt-line/src/autocomplete-controller.js.map +1 -1
- package/es-custom/components/prompt-line/src/prompt-line-rich-runtime.js +3 -0
- package/es-custom/components/prompt-line/src/prompt-line-rich-runtime.js.map +1 -1
- package/es-custom/components/prompt-line/src/prompt-line-shell.scss.js +1 -1
- package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.js +0 -5
- package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.js.map +1 -1
- package/es-custom/components/prompt-line/src/prompt-line.js +1 -1
- package/es-custom/components/prompt-line/src/prompt-line.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/build-extensions.js +1 -1
- package/es-custom/components/prompt-line/src/tiptap/build-extensions.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/carbon-autocomplete.d.ts +5 -6
- package/es-custom/components/prompt-line/src/tiptap/carbon-autocomplete.js +4 -28
- package/es-custom/components/prompt-line/src/tiptap/carbon-autocomplete.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/carbon-mention.js +13 -47
- package/es-custom/components/prompt-line/src/tiptap/carbon-mention.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/carbon-starter-trigger.js +3 -4
- package/es-custom/components/prompt-line/src/tiptap/carbon-starter-trigger.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/keymap.d.ts +1 -1
- package/es-custom/components/prompt-line/src/tiptap/keymap.js +3 -4
- package/es-custom/components/prompt-line/src/tiptap/keymap.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/render-token-chip.js +0 -1
- package/es-custom/components/prompt-line/src/tiptap/render-token-chip.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/resolve-config-items.d.ts +18 -0
- package/es-custom/components/prompt-line/src/tiptap/resolve-config-items.js +32 -0
- package/es-custom/components/prompt-line/src/tiptap/resolve-config-items.js.map +1 -0
- package/es-custom/components/prompt-line/src/tiptap/strip-presentation-fields.d.ts +18 -0
- package/es-custom/components/prompt-line/src/tiptap/strip-presentation-fields.js +22 -0
- package/es-custom/components/prompt-line/src/tiptap/strip-presentation-fields.js.map +1 -0
- package/es-custom/components/prompt-line/src/tiptap/types.d.ts +11 -3
- package/es-custom/components/toolbar/src/toolbar.d.ts +8 -0
- package/es-custom/components/toolbar/src/toolbar.js +65 -19
- package/es-custom/components/toolbar/src/toolbar.js.map +1 -1
- package/es-custom/components/video-player/src/providers/vimeo-provider.js +1 -1
- package/es-custom/components/video-player/src/providers/vimeo-provider.js.map +1 -1
- package/es-custom/globals/decorators/carbon-element.js +2 -3
- package/es-custom/globals/decorators/carbon-element.js.map +1 -1
- package/es-custom/globals/utils/aria-announcer-manager.d.ts +56 -0
- package/es-custom/globals/utils/aria-announcer-manager.js +46 -1
- package/es-custom/globals/utils/aria-announcer-manager.js.map +1 -1
- package/es-custom/globals/utils/focus-utils.js +1 -3
- package/es-custom/globals/utils/focus-utils.js.map +1 -1
- package/es-custom/globals/utils/iconTransform.d.ts +16 -2
- package/es-custom/globals/utils/iconTransform.js +22 -1
- package/es-custom/globals/utils/iconTransform.js.map +1 -1
- package/es-custom/react/hooks/useChatAutocomplete.js.map +1 -1
- package/es-custom/react/markdown.js +0 -1
- package/es-custom/react/markdown.js.map +1 -1
- package/es-custom/typings/overflow-menu.d.ts +4 -0
- package/package.json +6 -6
- package/scss/_custom-properties.scss +0 -17
- package/scss/_tokens-component.scss +1 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-line-textarea-runtime.js","sources":["../../../../src/components/prompt-line/src/prompt-line-textarea-runtime.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 * Textarea runtime for `<cds-custom-aichat-prompt-line>`'s default (non-rich) mode.\n * This module is **statically imported** by the prompt-line shell\n * ([./prompt-line.ts]), so it is always part of the initial bundle — but it\n * carries **no `@tiptap/*` runtime**. The only Tiptap symbols used here are\n * type imports erased at compile time.\n *\n * `TextareaController` implements {@link PromptLineController} backed by a\n * native `<textarea>`. It mirrors the typography and sizing of the Tiptap\n * editor exactly (auto-grow via a CSS grid mirror, Carbon `body-01` tokens,\n * the same `max-block-size` cap) so the textarea→editor swap triggered by\n * the rich-mode loader ([./prompt-line-rich-loader.ts]) is visually\n * imperceptible. State — plain text, caret position, and keyboard-focus\n * tracking — transfers losslessly to the rich controller because the textarea\n * is always the plain-text source of truth. The same `cds-custom-aichat-prompt-*`\n * events are emitted, keeping the React wrapper and `Input` handlers\n * mode-agnostic.\n *\n * `Editor` / `JSONContent` are **type-only** imports here — erased at compile,\n * so this module carries no Tiptap runtime.\n */\n\nimport type { Editor, Extension, JSONContent } from '@tiptap/core';\n\nimport { IS_PHONE } from '../../../globals/utils/browser-utils.js';\nimport {\n adoptOnRoot,\n setVarsForSelector,\n} from '../../shared/dynamic-css-var-sheet.js';\nimport {\n PROMPT_LINE_MAX_BLOCK_SIZE,\n TYPING_TIMEOUT_MS,\n} from './prompt-line-constants.js';\nimport { MouseFocusController } from './prompt-line-mouse-focus.js';\nimport type {\n PromptLineController,\n PromptLineControllerInit,\n SetContentUpdater,\n} from './prompt-line-controller.js';\nimport { getRawText, textToDoc } from './tiptap/json-utils.js';\n\n// ---------------------------------------------------------------------------\n// Textarea styling (CSP-safe — installed on the shared dynamic stylesheet,\n// governed by `style-src` not `style-src-attr`, matching ./tiptap/editor-styles).\n// ---------------------------------------------------------------------------\n\nconst TA_GROW_CLASS = 'cds-custom-aichat--input-textarea-grow';\nconst TA_FIELD_CLASS = 'cds-custom-aichat--input-textarea';\nconst TA_MIRROR_CLASS = 'cds-custom-aichat--input-textarea-mirror';\nconst TA_PHONE_CLASS = 'cds-custom-aichat--input-textarea--phone';\n\nlet textareaRulesInstalled = false;\n\n// Typography intentionally mirrors `.cds-custom-aichat--input-pm-content` in\n// ./tiptap/editor-styles.ts so the textarea and the Tiptap editor are pixel-\n// identical and the textarea→editor swap is imperceptible.\nfunction ensureTextareaStyleRules(): void {\n if (textareaRulesInstalled) {\n return;\n }\n // Auto-grow wrapper: textarea and mirror occupy the same grid cell; the\n // (content-bearing) mirror dictates the height, the textarea stretches to\n // fill it. No per-keystroke inline `style.height` (CSP-safe auto-grow).\n // Cap the box at the shared max and clip the (unbounded) mirror past it; the\n // field below scrolls within that cap.\n setVarsForSelector(`.${TA_GROW_CLASS}`, {\n display: 'grid',\n 'inline-size': '100%',\n 'max-block-size': PROMPT_LINE_MAX_BLOCK_SIZE,\n overflow: 'hidden',\n });\n setVarsForSelector(`.${TA_GROW_CLASS} > *`, {\n 'grid-area': '1 / 1 / 2 / 2',\n });\n // Shared typography + reset for both the field and the mirror.\n const shared: Record<string, string> = {\n margin: '0',\n padding: '0',\n border: 'none',\n 'white-space': 'pre-wrap',\n 'overflow-wrap': 'anywhere',\n 'font-family': 'inherit',\n 'font-size': 'var(--cds-body-01-font-size, 0.875rem)',\n 'font-weight': 'var(--cds-body-01-font-weight, 400)',\n 'letter-spacing': 'var(--cds-body-01-letter-spacing, 0.16px)',\n 'line-height': 'var(--cds-body-01-line-height, 1.42857)',\n };\n setVarsForSelector(`.${TA_FIELD_CLASS}`, {\n ...shared,\n appearance: 'none',\n background: 'transparent',\n color: 'var(--cds-text-primary, #161616)',\n outline: 'none',\n resize: 'none',\n // The field is its own scroll container past the cap so the browser keeps\n // the caret in view natively (an ancestor scroller would not track it).\n 'overflow-x': 'hidden',\n 'overflow-y': 'auto',\n 'inline-size': '100%',\n 'min-block-size': '0',\n 'max-block-size': PROMPT_LINE_MAX_BLOCK_SIZE,\n });\n setVarsForSelector(`.${TA_FIELD_CLASS}::placeholder`, {\n color: 'var(--cds-text-secondary, #525252)',\n opacity: '1',\n });\n setVarsForSelector(`.${TA_MIRROR_CLASS}`, {\n ...shared,\n visibility: 'hidden',\n 'pointer-events': 'none',\n });\n setVarsForSelector(`.${TA_PHONE_CLASS}`, {\n 'font-size': 'var(--cds-body-02-font-size, 1rem)',\n 'font-weight': 'var(--cds-body-02-font-weight, 400)',\n 'letter-spacing': 'var(--cds-body-02-letter-spacing, 0)',\n 'line-height': 'var(--cds-body-02-line-height, 1.5)',\n });\n textareaRulesInstalled = true;\n}\n\n/**\n * `<textarea>`-backed controller. Tiptap-free; emits the same prompt events as\n * the rich editor. Auto-grows via a hidden mirror, capped at\n * `PROMPT_LINE_MAX_BLOCK_SIZE` with the field scrolling past it — the same cap\n * the rich contenteditable applies (see ./tiptap/editor-styles.ts), so the\n * textarea→rich swap is imperceptible.\n */\nexport class TextareaController\n extends MouseFocusController\n implements PromptLineController\n{\n private _wrap: HTMLDivElement | null = null;\n private _textarea: HTMLTextAreaElement | null = null;\n private _mirror: HTMLDivElement | null = null;\n private _host: HTMLElement | null = null;\n\n private _isTyping = false;\n private _typingTimer: ReturnType<typeof setTimeout> | null = null;\n\n mount(host: HTMLElement, init: PromptLineControllerInit): void {\n ensureTextareaStyleRules();\n const root = host.getRootNode();\n if (root instanceof ShadowRoot || root instanceof Document) {\n adoptOnRoot(root);\n }\n\n const wrap = document.createElement('div');\n wrap.className = TA_GROW_CLASS;\n\n const textarea = document.createElement('textarea');\n textarea.className = TA_FIELD_CLASS;\n textarea.classList.toggle(TA_PHONE_CLASS, IS_PHONE);\n textarea.setAttribute('rows', '1');\n textarea.setAttribute('name', 'message');\n textarea.setAttribute('spellcheck', 'true');\n textarea.setAttribute('tabindex', '0');\n textarea.placeholder = init.placeholder;\n textarea.value = init.value;\n textarea.readOnly = init.disabled;\n if (init.ariaLabel) {\n textarea.setAttribute('aria-label', init.ariaLabel);\n }\n if (init.testId) {\n textarea.setAttribute('data-testid', init.testId);\n }\n\n const mirror = document.createElement('div');\n mirror.className = TA_MIRROR_CLASS;\n mirror.classList.toggle(TA_PHONE_CLASS, IS_PHONE);\n mirror.setAttribute('aria-hidden', 'true');\n\n wrap.appendChild(textarea);\n wrap.appendChild(mirror);\n host.appendChild(wrap);\n\n this._wrap = wrap;\n this._textarea = textarea;\n this._mirror = mirror;\n this._host = host;\n\n textarea.addEventListener('input', this._onInput);\n textarea.addEventListener('keydown', this._onKeydown);\n textarea.addEventListener('focus', this._onFocus);\n textarea.addEventListener('blur', this._onBlur);\n\n // Pointer/touch before focus marks the next focus as mouse-driven so we\n // suppress the keyboard-focus outline.\n this._attachMouseFocusListeners(host);\n\n this._syncMirror();\n }\n\n destroy(): void {\n this._clearTypingTimer();\n const ta = this._textarea;\n if (ta) {\n ta.removeEventListener('input', this._onInput);\n ta.removeEventListener('keydown', this._onKeydown);\n ta.removeEventListener('focus', this._onFocus);\n ta.removeEventListener('blur', this._onBlur);\n }\n const host = this._host;\n if (host) {\n this._detachMouseFocusListeners(host);\n }\n this._wrap?.remove();\n this._wrap = null;\n this._textarea = null;\n this._mirror = null;\n }\n\n getValue(): string {\n return this._textarea?.value ?? '';\n }\n\n setContent(next: JSONContent | string | SetContentUpdater): void {\n if (typeof next === 'function') {\n const prev = textToDoc(this.getValue());\n this._setValue(getRawText((next as SetContentUpdater)(prev)), true);\n return;\n }\n this._setValue(typeof next === 'string' ? next : getRawText(next), true);\n }\n\n insertContent(\n content: JSONContent | string,\n opts: { at?: number } = {}\n ): void {\n const ta = this._textarea;\n if (!ta) {\n return;\n }\n const text = typeof content === 'string' ? content : getRawText(content);\n const value = ta.value;\n const at =\n typeof opts.at === 'number'\n ? Math.max(0, Math.min(opts.at, value.length))\n : (ta.selectionStart ?? value.length);\n const end = typeof opts.at === 'number' ? at : (ta.selectionEnd ?? at);\n const nextValue = value.slice(0, at) + text + value.slice(end);\n const caret = at + text.length;\n this._setValue(nextValue, true);\n ta.setSelectionRange(caret, caret);\n }\n\n clearContent(): void {\n this._setValue('', true);\n }\n\n getEditor(): Editor | null {\n return null;\n }\n\n focus(keyboardFocus: boolean): void {\n this._setNextFocusOrigin(keyboardFocus);\n this._textarea?.focus();\n }\n\n blur(): void {\n this._textarea?.blur();\n }\n\n hasFocus(): boolean {\n const ta = this._textarea;\n if (!ta) {\n return false;\n }\n const root = ta.getRootNode() as Document | ShadowRoot;\n return root.activeElement === ta;\n }\n\n getSelection(): { from: number; to: number } {\n const ta = this._textarea;\n if (!ta) {\n return { from: 0, to: 0 };\n }\n return { from: ta.selectionStart ?? 0, to: ta.selectionEnd ?? 0 };\n }\n\n setTextSelection(pos: number | { from: number; to: number }): void {\n const ta = this._textarea;\n if (!ta) {\n return;\n }\n const len = ta.value.length;\n if (typeof pos === 'number') {\n const p = Math.max(0, Math.min(pos, len));\n ta.setSelectionRange(p, p);\n return;\n }\n ta.setSelectionRange(\n Math.max(0, Math.min(pos.from, len)),\n Math.max(0, Math.min(pos.to, len))\n );\n }\n\n selectAll(): void {\n this._textarea?.select();\n }\n\n setEditable(editable: boolean): void {\n if (this._textarea) {\n this._textarea.readOnly = !editable;\n }\n }\n\n setPlaceholder(placeholder: string): void {\n if (this._textarea) {\n this._textarea.placeholder = placeholder;\n }\n }\n\n setAriaLabel(ariaLabel: string): void {\n const ta = this._textarea;\n if (!ta) {\n return;\n }\n if (ariaLabel) {\n ta.setAttribute('aria-label', ariaLabel);\n } else {\n ta.removeAttribute('aria-label');\n }\n }\n\n setTestId(testId: string): void {\n const ta = this._textarea;\n if (!ta) {\n return;\n }\n if (testId) {\n ta.setAttribute('data-testid', testId);\n } else {\n ta.removeAttribute('data-testid');\n }\n }\n\n setExtensions(_extensions: Extension[]): void {\n // Textarea mode has no Tiptap extensions; the shell upgrades to the rich\n // controller when host extensions appear.\n }\n\n setComposing(_composing: boolean): void {\n // Nothing to withhold: a `<textarea>` survives its own recreate, and the\n // element gates the upgrade on composition itself.\n }\n\n undo(): boolean {\n return false;\n }\n\n redo(): boolean {\n return false;\n }\n\n // -------------------------------------------------------------------------\n // Internals\n // -------------------------------------------------------------------------\n\n private _onInput = (): void => {\n this._syncMirror();\n this._markTyping();\n this._emitChange();\n };\n\n // Enter-to-send mirrors the rich editor's base bundle (`Keymap` +\n // `carbonChatEnter`): plain Enter sends when non-empty, Mod-Enter sends,\n // Shift-Enter inserts a newline, and Enter on an empty field falls through to\n // the native newline (matching `carbonChatEnter`'s empty guard).\n private _onKeydown = (event: KeyboardEvent): void => {\n this._dispatch('cds-custom-aichat-prompt-keydown', { originalEvent: event });\n // While an IME composition is active, Enter commits the candidate — let the\n // IME own it. ProseMirror suppresses its keymap the same way, so the rich\n // editor and the textarea agree. Without this, confirming a CJK candidate\n // would send the half-composed text.\n if (event.isComposing) {\n return;\n }\n if (event.key === 'Enter' && !event.shiftKey) {\n const isModEnter = event.metaKey || event.ctrlKey;\n if (isModEnter || this.getValue() !== '') {\n event.preventDefault();\n this._dispatch('cds-custom-aichat-prompt-send-intent');\n }\n return;\n }\n if (event.key === 'Escape') {\n event.preventDefault();\n this._textarea?.blur();\n }\n };\n\n private _onFocus = (): void => {\n const wasMouseFocus = this._consumeMouseFocus();\n this._dispatch('cds-custom-aichat-prompt-focus', { keyboard: !wasMouseFocus });\n };\n\n private _onBlur = (): void => {\n this._dispatch('cds-custom-aichat-prompt-blur');\n };\n\n /** Programmatic value write: updates the field, mirror, and emits change. */\n private _setValue(text: string, emit: boolean): void {\n const ta = this._textarea;\n if (!ta) {\n return;\n }\n ta.value = text;\n this._syncMirror();\n if (emit) {\n this._emitChange();\n }\n }\n\n private _emitChange(): void {\n // Carry a plain-text doc as `content` so Redux / `getState().input.content`\n // stays consistent with the rich editor (which emits `editor.getJSON()`).\n const rawValue = this.getValue();\n this._dispatch('cds-custom-aichat-prompt-change', {\n rawValue,\n content: textToDoc(rawValue),\n });\n }\n\n private _syncMirror(): void {\n if (this._mirror && this._textarea) {\n // Trailing newline so the box grows the instant a new line starts.\n this._mirror.textContent = `${this._textarea.value}\\n`;\n }\n }\n\n private _markTyping(): void {\n if (!this._isTyping) {\n this._isTyping = true;\n this._dispatch('cds-custom-aichat-prompt-typing', { isTyping: true });\n }\n this._clearTypingTimer();\n this._typingTimer = setTimeout(() => {\n this._isTyping = false;\n this._dispatch('cds-custom-aichat-prompt-typing', { isTyping: false });\n }, TYPING_TIMEOUT_MS);\n }\n\n private _clearTypingTimer(): void {\n if (this._typingTimer != null) {\n clearTimeout(this._typingTimer);\n this._typingTimer = null;\n }\n }\n\n private _dispatch(name: string, detail?: unknown): void {\n this._textarea?.dispatchEvent(\n new CustomEvent(name, {\n detail,\n bubbles: true,\n composed: true,\n })\n );\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAAA;;;;;;;AAOG;AA2CH;AACA;AACA;AACA;AAEA,MAAM,aAAa,GAAG,iCAAiC;AACvD,MAAM,cAAc,GAAG,4BAA4B;AACnD,MAAM,eAAe,GAAG,mCAAmC;AAC3D,MAAM,cAAc,GAAG,mCAAmC;AAE1D,IAAI,sBAAsB,GAAG,KAAK;AAElC;AACA;AACA;AACA,SAAS,wBAAwB,GAAA;IAC/B,IAAI,sBAAsB,EAAE;QAC1B;IACF;;;;;;AAMA,IAAA,kBAAkB,CAAC,CAAA,CAAA,EAAI,aAAa,CAAA,CAAE,EAAE;AACtC,QAAA,OAAO,EAAE,MAAM;AACf,QAAA,aAAa,EAAE,MAAM;AACrB,QAAA,gBAAgB,EAAE,0BAA0B;AAC5C,QAAA,QAAQ,EAAE,QAAQ;AACnB,KAAA,CAAC;AACF,IAAA,kBAAkB,CAAC,CAAA,CAAA,EAAI,aAAa,CAAA,IAAA,CAAM,EAAE;AAC1C,QAAA,WAAW,EAAE,eAAe;AAC7B,KAAA,CAAC;;AAEF,IAAA,MAAM,MAAM,GAA2B;AACrC,QAAA,MAAM,EAAE,GAAG;AACX,QAAA,OAAO,EAAE,GAAG;AACZ,QAAA,MAAM,EAAE,MAAM;AACd,QAAA,aAAa,EAAE,UAAU;AACzB,QAAA,eAAe,EAAE,UAAU;AAC3B,QAAA,aAAa,EAAE,SAAS;AACxB,QAAA,WAAW,EAAE,wCAAwC;AACrD,QAAA,aAAa,EAAE,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,YAAA,OAAO,EAAE,SAAS,CAAC,QAAQ,CAAC;AAC7B,SAAA,CAAC;IACJ;IAEQ,WAAW,GAAA;QACjB,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,SAAS,EAAE;;AAElC,YAAA,IAAI,CAAC,OAAO,CAAC,WAAW,GAAG,CAAA,EAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAA,EAAA,CAAI;QACxD;IACF;IAEQ,WAAW,GAAA;AACjB,QAAA,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;AACnB,YAAA,IAAI,CAAC,SAAS,GAAG,IAAI;YACrB,IAAI,CAAC,SAAS,CAAC,0BAA0B,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;QAChE;QACA,IAAI,CAAC,iBAAiB,EAAE;AACxB,QAAA,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,MAAK;AAClC,YAAA,IAAI,CAAC,SAAS,GAAG,KAAK;YACtB,IAAI,CAAC,SAAS,CAAC,0BAA0B,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;QACjE,CAAC,EAAE,iBAAiB,CAAC;IACvB;IAEQ,iBAAiB,GAAA;AACvB,QAAA,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,EAAE;AAC7B,YAAA,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC;AAC/B,YAAA,IAAI,CAAC,YAAY,GAAG,IAAI;QAC1B;IACF;IAEQ,SAAS,CAAC,IAAY,EAAE,MAAgB,EAAA;QAC9C,IAAI,CAAC,SAAS,EAAE,aAAa,CAC3B,IAAI,WAAW,CAAC,IAAI,EAAE;YACpB,MAAM;AACN,YAAA,OAAO,EAAE,IAAI;AACb,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA,CAAC,CACH;IACH;AACD;;"}
|
|
1
|
+
{"version":3,"file":"prompt-line-textarea-runtime.js","sources":["../../../../src/components/prompt-line/src/prompt-line-textarea-runtime.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 * Textarea runtime for `<cds-custom-aichat-prompt-line>`'s default (non-rich) mode.\n * This module is **statically imported** by the prompt-line shell\n * ([./prompt-line.ts]), so it is always part of the initial bundle — but it\n * carries **no `@tiptap/*` runtime**. The only Tiptap symbols used here are\n * type imports erased at compile time.\n *\n * `TextareaController` implements {@link PromptLineController} backed by a\n * native `<textarea>`. It mirrors the typography and sizing of the Tiptap\n * editor exactly (auto-grow via a CSS grid mirror, Carbon `body-01` tokens,\n * the same `max-block-size` cap) so the textarea→editor swap triggered by\n * the rich-mode loader ([./prompt-line-rich-loader.ts]) is visually\n * imperceptible. State — plain text, caret position, and keyboard-focus\n * tracking — transfers losslessly to the rich controller because the textarea\n * is always the plain-text source of truth. The same `cds-custom-aichat-prompt-*`\n * events are emitted, keeping the React wrapper and `Input` handlers\n * mode-agnostic.\n *\n * `Editor` / `JSONContent` are **type-only** imports here — erased at compile,\n * so this module carries no Tiptap runtime.\n */\n\nimport type { Editor, Extension, JSONContent } from '@tiptap/core';\n\nimport { IS_PHONE } from '../../../globals/utils/browser-utils.js';\nimport {\n adoptOnRoot,\n setVarsForSelector,\n} from '../../shared/dynamic-css-var-sheet.js';\nimport {\n PROMPT_LINE_MAX_BLOCK_SIZE,\n TYPING_TIMEOUT_MS,\n} from './prompt-line-constants.js';\nimport { MouseFocusController } from './prompt-line-mouse-focus.js';\nimport type {\n PromptLineController,\n PromptLineControllerInit,\n SetContentUpdater,\n} from './prompt-line-controller.js';\nimport { getRawText, textToDoc } from './tiptap/json-utils.js';\n\n// ---------------------------------------------------------------------------\n// Textarea styling (CSP-safe — installed on the shared dynamic stylesheet,\n// governed by `style-src` not `style-src-attr`, matching ./tiptap/editor-styles).\n// ---------------------------------------------------------------------------\n\nconst TA_GROW_CLASS = 'cds-custom-aichat--input-textarea-grow';\nconst TA_FIELD_CLASS = 'cds-custom-aichat--input-textarea';\nconst TA_MIRROR_CLASS = 'cds-custom-aichat--input-textarea-mirror';\nconst TA_PHONE_CLASS = 'cds-custom-aichat--input-textarea--phone';\n\nlet textareaRulesInstalled = false;\n\n// Typography intentionally mirrors `.cds-custom-aichat--input-pm-content` in\n// ./tiptap/editor-styles.ts so the textarea and the Tiptap editor are pixel-\n// identical and the textarea→editor swap is imperceptible.\nfunction ensureTextareaStyleRules(): void {\n if (textareaRulesInstalled) {\n return;\n }\n // Auto-grow wrapper: textarea and mirror occupy the same grid cell; the\n // (content-bearing) mirror dictates the height, the textarea stretches to\n // fill it. No per-keystroke inline `style.height` (CSP-safe auto-grow).\n // Cap the box at the shared max and clip the (unbounded) mirror past it; the\n // field below scrolls within that cap.\n setVarsForSelector(`.${TA_GROW_CLASS}`, {\n display: 'grid',\n 'inline-size': '100%',\n 'max-block-size': PROMPT_LINE_MAX_BLOCK_SIZE,\n overflow: 'hidden',\n });\n setVarsForSelector(`.${TA_GROW_CLASS} > *`, {\n 'grid-area': '1 / 1 / 2 / 2',\n });\n // Shared typography + reset for both the field and the mirror.\n const shared: Record<string, string> = {\n margin: '0',\n padding: '0',\n border: 'none',\n 'white-space': 'pre-wrap',\n 'overflow-wrap': 'anywhere',\n 'font-family': 'inherit',\n 'font-size': 'var(--cds-body-01-font-size, 0.875rem)',\n 'font-weight': 'var(--cds-body-01-font-weight, 400)',\n 'letter-spacing': 'var(--cds-body-01-letter-spacing, 0.16px)',\n 'line-height': 'var(--cds-body-01-line-height, 1.42857)',\n };\n setVarsForSelector(`.${TA_FIELD_CLASS}`, {\n ...shared,\n appearance: 'none',\n background: 'transparent',\n color: 'var(--cds-text-primary, #161616)',\n outline: 'none',\n resize: 'none',\n // The field is its own scroll container past the cap so the browser keeps\n // the caret in view natively (an ancestor scroller would not track it).\n 'overflow-x': 'hidden',\n 'overflow-y': 'auto',\n 'inline-size': '100%',\n 'min-block-size': '0',\n 'max-block-size': PROMPT_LINE_MAX_BLOCK_SIZE,\n });\n setVarsForSelector(`.${TA_FIELD_CLASS}::placeholder`, {\n color: 'var(--cds-text-secondary, #525252)',\n opacity: '1',\n });\n setVarsForSelector(`.${TA_MIRROR_CLASS}`, {\n ...shared,\n visibility: 'hidden',\n 'pointer-events': 'none',\n });\n setVarsForSelector(`.${TA_PHONE_CLASS}`, {\n 'font-size': 'var(--cds-body-02-font-size, 1rem)',\n 'font-weight': 'var(--cds-body-02-font-weight, 400)',\n 'letter-spacing': 'var(--cds-body-02-letter-spacing, 0)',\n 'line-height': 'var(--cds-body-02-line-height, 1.5)',\n });\n textareaRulesInstalled = true;\n}\n\n/**\n * `<textarea>`-backed controller. Tiptap-free; emits the same prompt events as\n * the rich editor. Auto-grows via a hidden mirror, capped at\n * `PROMPT_LINE_MAX_BLOCK_SIZE` with the field scrolling past it — the same cap\n * the rich contenteditable applies (see ./tiptap/editor-styles.ts), so the\n * textarea→rich swap is imperceptible.\n */\nexport class TextareaController\n extends MouseFocusController\n implements PromptLineController\n{\n private _wrap: HTMLDivElement | null = null;\n private _textarea: HTMLTextAreaElement | null = null;\n private _mirror: HTMLDivElement | null = null;\n private _host: HTMLElement | null = null;\n\n private _isTyping = false;\n private _typingTimer: ReturnType<typeof setTimeout> | null = null;\n\n mount(host: HTMLElement, init: PromptLineControllerInit): void {\n ensureTextareaStyleRules();\n const root = host.getRootNode();\n if (root instanceof ShadowRoot || root instanceof Document) {\n adoptOnRoot(root);\n }\n\n const wrap = document.createElement('div');\n wrap.className = TA_GROW_CLASS;\n\n const textarea = document.createElement('textarea');\n textarea.className = TA_FIELD_CLASS;\n textarea.classList.toggle(TA_PHONE_CLASS, IS_PHONE);\n textarea.setAttribute('rows', '1');\n textarea.setAttribute('name', 'message');\n textarea.setAttribute('spellcheck', 'true');\n textarea.setAttribute('tabindex', '0');\n textarea.placeholder = init.placeholder;\n textarea.value = init.value;\n textarea.readOnly = init.disabled;\n if (init.ariaLabel) {\n textarea.setAttribute('aria-label', init.ariaLabel);\n }\n if (init.testId) {\n textarea.setAttribute('data-testid', init.testId);\n }\n\n const mirror = document.createElement('div');\n mirror.className = TA_MIRROR_CLASS;\n mirror.classList.toggle(TA_PHONE_CLASS, IS_PHONE);\n mirror.setAttribute('aria-hidden', 'true');\n\n wrap.appendChild(textarea);\n wrap.appendChild(mirror);\n host.appendChild(wrap);\n\n this._wrap = wrap;\n this._textarea = textarea;\n this._mirror = mirror;\n this._host = host;\n\n textarea.addEventListener('input', this._onInput);\n textarea.addEventListener('keydown', this._onKeydown);\n textarea.addEventListener('focus', this._onFocus);\n textarea.addEventListener('blur', this._onBlur);\n\n // Pointer/touch before focus marks the next focus as mouse-driven so we\n // suppress the keyboard-focus outline.\n this._attachMouseFocusListeners(host);\n\n this._syncMirror();\n }\n\n destroy(): void {\n this._clearTypingTimer();\n const ta = this._textarea;\n if (ta) {\n ta.removeEventListener('input', this._onInput);\n ta.removeEventListener('keydown', this._onKeydown);\n ta.removeEventListener('focus', this._onFocus);\n ta.removeEventListener('blur', this._onBlur);\n }\n const host = this._host;\n if (host) {\n this._detachMouseFocusListeners(host);\n }\n this._wrap?.remove();\n this._wrap = null;\n this._textarea = null;\n this._mirror = null;\n }\n\n getValue(): string {\n return this._textarea?.value ?? '';\n }\n\n setContent(next: JSONContent | string | SetContentUpdater): void {\n if (typeof next === 'function') {\n const prev = textToDoc(this.getValue());\n this._setValue(getRawText((next as SetContentUpdater)(prev)), true);\n return;\n }\n this._setValue(typeof next === 'string' ? next : getRawText(next), true);\n }\n\n insertContent(\n content: JSONContent | string,\n opts: { at?: number } = {}\n ): void {\n const ta = this._textarea;\n if (!ta) {\n return;\n }\n const text = typeof content === 'string' ? content : getRawText(content);\n const value = ta.value;\n const at =\n typeof opts.at === 'number'\n ? Math.max(0, Math.min(opts.at, value.length))\n : (ta.selectionStart ?? value.length);\n const end = typeof opts.at === 'number' ? at : (ta.selectionEnd ?? at);\n const nextValue = value.slice(0, at) + text + value.slice(end);\n const caret = at + text.length;\n this._setValue(nextValue, true);\n ta.setSelectionRange(caret, caret);\n }\n\n clearContent(): void {\n this._setValue('', true);\n }\n\n getEditor(): Editor | null {\n return null;\n }\n\n focus(keyboardFocus: boolean): void {\n this._setNextFocusOrigin(keyboardFocus);\n this._textarea?.focus();\n }\n\n blur(): void {\n this._textarea?.blur();\n }\n\n hasFocus(): boolean {\n const ta = this._textarea;\n if (!ta) {\n return false;\n }\n const root = ta.getRootNode() as Document | ShadowRoot;\n return root.activeElement === ta;\n }\n\n getSelection(): { from: number; to: number } {\n const ta = this._textarea;\n if (!ta) {\n return { from: 0, to: 0 };\n }\n return { from: ta.selectionStart ?? 0, to: ta.selectionEnd ?? 0 };\n }\n\n setTextSelection(pos: number | { from: number; to: number }): void {\n const ta = this._textarea;\n if (!ta) {\n return;\n }\n const len = ta.value.length;\n if (typeof pos === 'number') {\n const p = Math.max(0, Math.min(pos, len));\n ta.setSelectionRange(p, p);\n return;\n }\n ta.setSelectionRange(\n Math.max(0, Math.min(pos.from, len)),\n Math.max(0, Math.min(pos.to, len))\n );\n }\n\n selectAll(): void {\n this._textarea?.select();\n }\n\n setEditable(editable: boolean): void {\n if (this._textarea) {\n this._textarea.readOnly = !editable;\n }\n }\n\n setPlaceholder(placeholder: string): void {\n if (this._textarea) {\n this._textarea.placeholder = placeholder;\n }\n }\n\n setAriaLabel(ariaLabel: string): void {\n const ta = this._textarea;\n if (!ta) {\n return;\n }\n if (ariaLabel) {\n ta.setAttribute('aria-label', ariaLabel);\n } else {\n ta.removeAttribute('aria-label');\n }\n }\n\n setTestId(testId: string): void {\n const ta = this._textarea;\n if (!ta) {\n return;\n }\n if (testId) {\n ta.setAttribute('data-testid', testId);\n } else {\n ta.removeAttribute('data-testid');\n }\n }\n\n setExtensions(_extensions: Extension[]): void {\n // Textarea mode has no Tiptap extensions; the shell upgrades to the rich\n // controller when host extensions appear.\n }\n\n setComposing(_composing: boolean): void {\n // Nothing to withhold: a `<textarea>` survives its own recreate, and the\n // element gates the upgrade on composition itself.\n }\n\n undo(): boolean {\n return false;\n }\n\n redo(): boolean {\n return false;\n }\n\n // -------------------------------------------------------------------------\n // Internals\n // -------------------------------------------------------------------------\n\n private _onInput = (): void => {\n this._syncMirror();\n this._markTyping();\n this._emitChange();\n };\n\n // Enter-to-send mirrors the rich editor's base bundle (`Keymap` +\n // `carbonChatEnter`): plain Enter sends when non-empty, Mod-Enter sends,\n // Shift-Enter inserts a newline, and Enter on an empty field falls through to\n // the native newline (matching `carbonChatEnter`'s empty guard).\n private _onKeydown = (event: KeyboardEvent): void => {\n this._dispatch('cds-custom-aichat-prompt-keydown', { originalEvent: event });\n // While an IME composition is active, Enter commits the candidate — let the\n // IME own it. ProseMirror suppresses its keymap the same way, so the rich\n // editor and the textarea agree. Without this, confirming a CJK candidate\n // would send the half-composed text.\n if (event.isComposing) {\n return;\n }\n if (event.key === 'Enter' && !event.shiftKey) {\n const isModEnter = event.metaKey || event.ctrlKey;\n if (isModEnter || this.getValue() !== '') {\n event.preventDefault();\n this._dispatch('cds-custom-aichat-prompt-send-intent');\n }\n }\n };\n\n private _onFocus = (): void => {\n const wasMouseFocus = this._consumeMouseFocus();\n this._dispatch('cds-custom-aichat-prompt-focus', { keyboard: !wasMouseFocus });\n };\n\n private _onBlur = (): void => {\n this._dispatch('cds-custom-aichat-prompt-blur');\n };\n\n /** Programmatic value write: updates the field, mirror, and emits change. */\n private _setValue(text: string, emit: boolean): void {\n const ta = this._textarea;\n if (!ta) {\n return;\n }\n ta.value = text;\n this._syncMirror();\n if (emit) {\n this._emitChange();\n }\n }\n\n private _emitChange(): void {\n // Carry a plain-text doc as `content` so Redux / `getState().input.content`\n // stays consistent with the rich editor (which emits `editor.getJSON()`).\n const rawValue = this.getValue();\n this._dispatch('cds-custom-aichat-prompt-change', {\n rawValue,\n content: textToDoc(rawValue),\n });\n }\n\n private _syncMirror(): void {\n if (this._mirror && this._textarea) {\n // Trailing newline so the box grows the instant a new line starts.\n this._mirror.textContent = `${this._textarea.value}\\n`;\n }\n }\n\n private _markTyping(): void {\n if (!this._isTyping) {\n this._isTyping = true;\n this._dispatch('cds-custom-aichat-prompt-typing', { isTyping: true });\n }\n this._clearTypingTimer();\n this._typingTimer = setTimeout(() => {\n this._isTyping = false;\n this._dispatch('cds-custom-aichat-prompt-typing', { isTyping: false });\n }, TYPING_TIMEOUT_MS);\n }\n\n private _clearTypingTimer(): void {\n if (this._typingTimer != null) {\n clearTimeout(this._typingTimer);\n this._typingTimer = null;\n }\n }\n\n private _dispatch(name: string, detail?: unknown): void {\n this._textarea?.dispatchEvent(\n new CustomEvent(name, {\n detail,\n bubbles: true,\n composed: true,\n })\n );\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAAA;;;;;;;AAOG;AA2CH;AACA;AACA;AACA;AAEA,MAAM,aAAa,GAAG,iCAAiC;AACvD,MAAM,cAAc,GAAG,4BAA4B;AACnD,MAAM,eAAe,GAAG,mCAAmC;AAC3D,MAAM,cAAc,GAAG,mCAAmC;AAE1D,IAAI,sBAAsB,GAAG,KAAK;AAElC;AACA;AACA;AACA,SAAS,wBAAwB,GAAA;IAC/B,IAAI,sBAAsB,EAAE;QAC1B;IACF;;;;;;AAMA,IAAA,kBAAkB,CAAC,CAAA,CAAA,EAAI,aAAa,CAAA,CAAE,EAAE;AACtC,QAAA,OAAO,EAAE,MAAM;AACf,QAAA,aAAa,EAAE,MAAM;AACrB,QAAA,gBAAgB,EAAE,0BAA0B;AAC5C,QAAA,QAAQ,EAAE,QAAQ;AACnB,KAAA,CAAC;AACF,IAAA,kBAAkB,CAAC,CAAA,CAAA,EAAI,aAAa,CAAA,IAAA,CAAM,EAAE;AAC1C,QAAA,WAAW,EAAE,eAAe;AAC7B,KAAA,CAAC;;AAEF,IAAA,MAAM,MAAM,GAA2B;AACrC,QAAA,MAAM,EAAE,GAAG;AACX,QAAA,OAAO,EAAE,GAAG;AACZ,QAAA,MAAM,EAAE,MAAM;AACd,QAAA,aAAa,EAAE,UAAU;AACzB,QAAA,eAAe,EAAE,UAAU;AAC3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ACJ;IAEQ,WAAW,GAAA;QACjB,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,SAAS,EAAE;;AAElC,YAAA,IAAI,CAAC,OAAO,CAAC,WAAW,GAAG,CAAA,EAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAA,EAAA,CAAI;QACxD;IACF;IAEQ,WAAW,GAAA;AACjB,QAAA,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;AACnB,YAAA,IAAI,CAAC,SAAS,GAAG,IAAI;YACrB,IAAI,CAAC,SAAS,CAAC,0BAA0B,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;QAChE;QACA,IAAI,CAAC,iBAAiB,EAAE;AACxB,QAAA,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,MAAK;AAClC,YAAA,IAAI,CAAC,SAAS,GAAG,KAAK;YACtB,IAAI,CAAC,SAAS,CAAC,0BAA0B,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;QACjE,CAAC,EAAE,iBAAiB,CAAC;IACvB;IAEQ,iBAAiB,GAAA;AACvB,QAAA,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,EAAE;AAC7B,YAAA,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC;AAC/B,YAAA,IAAI,CAAC,YAAY,GAAG,IAAI;QAC1B;IACF;IAEQ,SAAS,CAAC,IAAY,EAAE,MAAgB,EAAA;QAC9C,IAAI,CAAC,SAAS,EAAE,aAAa,CAC3B,IAAI,WAAW,CAAC,IAAI,EAAE;YACpB,MAAM;AACN,YAAA,OAAO,EAAE,IAAI;AACb,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA,CAAC,CACH;IACH;AACD;;"}
|
|
@@ -109,7 +109,7 @@ let PromptLineElement = class PromptLineElement extends LitElement {
|
|
|
109
109
|
super.connectedCallback();
|
|
110
110
|
if (this._pendingTeardownTimer !== null) {
|
|
111
111
|
// Reattached before the deferred teardown ran — a move, not an unmount.
|
|
112
|
-
// The controller and its editor host
|
|
112
|
+
// The controller and its editor host traveled with the element, so the
|
|
113
113
|
// Tiptap instance (and its undo history) survives untouched.
|
|
114
114
|
//
|
|
115
115
|
// Unlike `_teardownSurface`, this deliberately leaves `_isComposing` /
|
|
@@ -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,E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,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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}
|
|
@@ -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(
|
|
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(
|
|
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)
|
|
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
|
|
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(
|
|
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)
|
|
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(
|
|
31
|
+
function carbonAutocomplete(excludeTriggers = []) {
|
|
32
32
|
const pluginKey = new PluginKey('carbonAutocompleteSuggestion');
|
|
33
33
|
return Extension.create({
|
|
34
34
|
name: 'carbonAutocomplete',
|
|
@@ -76,16 +76,6 @@ function carbonAutocomplete(config, excludeTriggers = []) {
|
|
|
76
76
|
text: query,
|
|
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;
|
|
@@ -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)
|
|
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 // 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 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"],"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,GAAA;AACnB,YAAA,MAAM,MAAM,GAAG,IAAI,CAAC,MA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;oBACH,CAAC;AACD,oBAAA,MAAM,EAAE,OAAO;AACb,wBAAA,OAAO,EAAE,CAAC,KAAK,KAAI;AACjB,4BAAA,SAAS,GAAG,KAAK,CAAC,KAAK;AACvB,4BAAA,qBAAqB,CAAC,KAAK,CAAC,MAAM,EAAE;AAClC,gCAAA,IAAI,EAAE,cAAc;gCACpB,KAAK,EAAE,KAAK,CAAC,KAAK;AAClB,gCAAA,aAAa,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI;AAChC,6BAAA,CAAC;wBACJ,CAAC;AACD,wBAAA,QAAQ,EAAE,CAAC,KAAK,KAAI;AAClB,4BAAA,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,EAAE;gCAC7B;4BACF;AACA,4BAAA,SAAS,GAAG,KAAK,CAAC,KAAK;AACvB,4BAAA,qBAAqB,CAAC,KAAK,CAAC,MAAM,EAAE;AAClC,gCAAA,IAAI,EAAE,cAAc;gCACpB,KAAK,EAAE,KAAK,CAAC,KAAK;AAClB,gCAAA,aAAa,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI;AAChC,6BAAA,CAAC;wBACJ,CAAC;AACD,wBAAA,MAAM,EAAE,CAAC,KAAK,KAAI;4BAChB,SAAS,GAAG,IAAI;AAChB,4BAAA,qBAAqB,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC;wBAC3C,CAAC;AACD,wBAAA,SAAS,EAAE,MAAM,KAAK;qBACvB,CAAC;iBACH,CAAC;aACH;QACH,CAAC;AACF,KAAA,CAAC;AACJ;;"}
|
|
@@ -30,7 +30,11 @@ function buildTriggerExtension(config, build) {
|
|
|
30
30
|
...parent,
|
|
31
31
|
mentionSuggestionChar: { default: config.trigger },
|
|
32
32
|
value: { default: null },
|
|
33
|
-
|
|
33
|
+
// Host custom fields, held in editor state only: they survive the JSON
|
|
34
|
+
// round-trip, undo/redo, and moves within the document, and never
|
|
35
|
+
// reach HTML. Tiptap's default attribute rendering would stringify the
|
|
36
|
+
// object into the markup as "[object Object]".
|
|
37
|
+
data: { default: null, renderHTML: () => ({}) },
|
|
34
38
|
trigger: { default: null },
|
|
35
39
|
};
|
|
36
40
|
},
|
|
@@ -80,33 +84,6 @@ function buildTriggerExtension(config, build) {
|
|
|
80
84
|
char: config.trigger,
|
|
81
85
|
pluginKey,
|
|
82
86
|
startOfLine: config.triggerPosition === 'start',
|
|
83
|
-
items: ({ query }) => resolveItems(config, query),
|
|
84
|
-
command: ({ editor, range, props }) => {
|
|
85
|
-
const item = props;
|
|
86
|
-
// Insert the mention/command node with our extended attrs.
|
|
87
|
-
editor
|
|
88
|
-
.chain()
|
|
89
|
-
.focus()
|
|
90
|
-
.insertContentAt(range, [
|
|
91
|
-
{
|
|
92
|
-
type: name,
|
|
93
|
-
attrs: {
|
|
94
|
-
id: item.id,
|
|
95
|
-
label: item.label,
|
|
96
|
-
value: item.value ?? item.label,
|
|
97
|
-
// Item overrides config overrides the command/mention
|
|
98
|
-
// default (see resolveShowTriggerInChip).
|
|
99
|
-
trigger: resolveShowTriggerInChip(item, config, build.defaultName === 'command')
|
|
100
|
-
? config.trigger
|
|
101
|
-
: null,
|
|
102
|
-
data: stripPresentationFields(item),
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
{ type: 'text', text: ' ' },
|
|
106
|
-
])
|
|
107
|
-
.run();
|
|
108
|
-
config.onSelect?.(item);
|
|
109
|
-
},
|
|
110
87
|
render: () => {
|
|
111
88
|
let lastQuery = null;
|
|
112
89
|
return {
|
|
@@ -168,7 +145,14 @@ function collectTokenAttrsById(doc, name) {
|
|
|
168
145
|
* `label`, `value`, and any custom fields stashed in `data` survive.
|
|
169
146
|
*/
|
|
170
147
|
function attrsToItem(attrs) {
|
|
171
|
-
|
|
148
|
+
// `data` holds whatever a caller put in the node's attrs, and
|
|
149
|
+
// `insertContent()` takes a raw node spec — so a host can land a string or
|
|
150
|
+
// an array here. Spreading either yields index keys ({...'abc'} → {0:'a'}),
|
|
151
|
+
// which would then reach onRemove as if the host had set them.
|
|
152
|
+
const raw = attrs.data;
|
|
153
|
+
const data = raw && typeof raw === 'object' && !Array.isArray(raw)
|
|
154
|
+
? raw
|
|
155
|
+
: {};
|
|
172
156
|
return {
|
|
173
157
|
...data,
|
|
174
158
|
id: String(attrs.id),
|
|
@@ -193,20 +177,6 @@ function diffRemovedTokens(before, after, name) {
|
|
|
193
177
|
}
|
|
194
178
|
return removed;
|
|
195
179
|
}
|
|
196
|
-
async function resolveItems(config, query) {
|
|
197
|
-
const minQueryLength = config.minQueryLength ?? 0;
|
|
198
|
-
if (query.length < minQueryLength) {
|
|
199
|
-
return [];
|
|
200
|
-
}
|
|
201
|
-
if (typeof config.items === 'function') {
|
|
202
|
-
return Promise.resolve(config.items(query));
|
|
203
|
-
}
|
|
204
|
-
if (!query) {
|
|
205
|
-
return config.items;
|
|
206
|
-
}
|
|
207
|
-
const lower = query.toLowerCase();
|
|
208
|
-
return config.items.filter((item) => item.label.toLowerCase().includes(lower));
|
|
209
|
-
}
|
|
210
180
|
/**
|
|
211
181
|
* Resolve whether a selected item's chip should be prefixed with the
|
|
212
182
|
* trigger character: the item's own {@link SuggestionItem.showTriggerInChip}
|
|
@@ -217,10 +187,6 @@ async function resolveItems(config, query) {
|
|
|
217
187
|
function resolveShowTriggerInChip(item, config, isCommand) {
|
|
218
188
|
return item.showTriggerInChip ?? config.showTriggerInChip ?? isCommand;
|
|
219
189
|
}
|
|
220
|
-
function stripPresentationFields(item) {
|
|
221
|
-
const { id: _id, label: _label, value: _value, avatar: _avatar, description: _description, disabled: _disabled, showTriggerInChip: _showTriggerInChip, ...rest } = item;
|
|
222
|
-
return rest;
|
|
223
|
-
}
|
|
224
190
|
function carbonMention(config) {
|
|
225
191
|
return buildTriggerExtension(config, {
|
|
226
192
|
defaultName: 'mention',
|