@carbon/ai-chat-components 1.10.0 → 1.11.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 +736 -775
- package/es/components/audio-player/src/utils/url-detector.d.ts +0 -14
- package/es/components/audio-player/src/utils/url-detector.js +1 -19
- package/es/components/audio-player/src/utils/url-detector.js.map +1 -1
- 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/code-snippet/src/codemirror/codemirror-loader.d.ts +0 -5
- package/es/components/code-snippet/src/codemirror/codemirror-loader.js +1 -8
- package/es/components/code-snippet/src/codemirror/codemirror-loader.js.map +1 -1
- package/es/components/markdown/src/markdown-token-tree.js +1 -1
- package/es/components/markdown/src/plugins/markdown-it-attrs.d.ts +0 -1
- package/es/components/markdown/src/plugins/markdown-it-attrs.js +1 -1
- package/es/components/markdown/src/plugins/markdown-it-attrs.js.map +1 -1
- package/es/components/markdown/src/utils/plugin-fallback.js +3 -1
- package/es/components/markdown/src/utils/plugin-fallback.js.map +1 -1
- package/es/components/markdown/src/utils/table-helpers.d.ts +0 -26
- package/es/components/markdown/src/utils/table-helpers.js +1 -4
- package/es/components/markdown/src/utils/table-helpers.js.map +1 -1
- package/es/components/prompt-line/autocomplete/src/autocomplete.scss.js +1 -1
- package/es/components/prompt-line/src/prompt-line-constants.d.ts +9 -1
- package/es/components/prompt-line/src/prompt-line-constants.js +10 -2
- package/es/components/prompt-line/src/prompt-line-constants.js.map +1 -1
- package/es/components/prompt-line/src/prompt-line-controller.d.ts +25 -78
- package/es/components/prompt-line/src/prompt-line-controller.js +0 -389
- package/es/components/prompt-line/src/prompt-line-controller.js.map +1 -1
- package/es/components/prompt-line/src/prompt-line-mouse-focus.d.ts +45 -0
- package/es/components/prompt-line/src/prompt-line-mouse-focus.js +83 -0
- package/es/components/prompt-line/src/prompt-line-mouse-focus.js.map +1 -0
- package/es/components/prompt-line/src/prompt-line-rich-runtime.d.ts +0 -2
- package/es/components/prompt-line/src/prompt-line-rich-runtime.js +30 -53
- package/es/components/prompt-line/src/prompt-line-rich-runtime.js.map +1 -1
- package/es/components/prompt-line/src/prompt-line-textarea-runtime.d.ts +87 -0
- package/es/components/prompt-line/src/prompt-line-textarea-runtime.js +390 -0
- package/es/components/prompt-line/src/prompt-line-textarea-runtime.js.map +1 -0
- package/es/components/prompt-line/src/prompt-line.d.ts +1 -1
- package/es/components/prompt-line/src/prompt-line.js +6 -5
- package/es/components/prompt-line/src/prompt-line.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/extension-equivalence.d.ts +2 -1
- package/es/components/prompt-line/src/tiptap/extension-equivalence.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/typing-indicator.js +1 -1
- package/es/components/prompt-line/src/tiptap/typing-indicator.js.map +1 -1
- package/es/components/truncated-text/src/truncated-text.js +2 -2
- package/es/components/truncated-text/src/truncated-text.js.map +1 -1
- package/es/components/video-player/src/utils/url-detector.d.ts +0 -28
- package/es/components/video-player/src/utils/url-detector.js +1 -37
- package/es/components/video-player/src/utils/url-detector.js.map +1 -1
- package/es/globals/utils/browser-utils.d.ts +3 -5
- package/es/globals/utils/browser-utils.js +1 -1
- package/es/globals/utils/browser-utils.js.map +1 -1
- package/es/globals/utils/csv.d.ts +0 -1
- package/es/globals/utils/csv.js.map +1 -1
- package/es/react/truncated-text.d.ts +12 -0
- package/es/react/truncated-text.js +28 -0
- package/es/react/truncated-text.js.map +1 -0
- package/es/testing/PageObjectId.d.ts +0 -4
- package/es/testing/PageObjectId.js.map +1 -1
- package/es/testing/load-all-lazy-deps.d.ts +1 -2
- package/es/testing/load-all-lazy-deps.js +3 -3
- package/es/testing/load-all-lazy-deps.js.map +1 -1
- package/es-custom/components/audio-player/src/utils/url-detector.d.ts +0 -14
- package/es-custom/components/audio-player/src/utils/url-detector.js +1 -19
- package/es-custom/components/audio-player/src/utils/url-detector.js.map +1 -1
- 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/code-snippet/src/codemirror/codemirror-loader.d.ts +0 -5
- package/es-custom/components/code-snippet/src/codemirror/codemirror-loader.js +1 -8
- package/es-custom/components/code-snippet/src/codemirror/codemirror-loader.js.map +1 -1
- package/es-custom/components/markdown/src/markdown-token-tree.js +1 -1
- package/es-custom/components/markdown/src/plugins/markdown-it-attrs.d.ts +0 -1
- package/es-custom/components/markdown/src/plugins/markdown-it-attrs.js +1 -1
- package/es-custom/components/markdown/src/plugins/markdown-it-attrs.js.map +1 -1
- package/es-custom/components/markdown/src/utils/plugin-fallback.js +3 -1
- package/es-custom/components/markdown/src/utils/plugin-fallback.js.map +1 -1
- package/es-custom/components/markdown/src/utils/table-helpers.d.ts +0 -26
- package/es-custom/components/markdown/src/utils/table-helpers.js +1 -4
- package/es-custom/components/markdown/src/utils/table-helpers.js.map +1 -1
- package/es-custom/components/prompt-line/autocomplete/src/autocomplete.scss.js +1 -1
- package/es-custom/components/prompt-line/src/prompt-line-constants.d.ts +9 -1
- package/es-custom/components/prompt-line/src/prompt-line-constants.js +10 -2
- package/es-custom/components/prompt-line/src/prompt-line-constants.js.map +1 -1
- package/es-custom/components/prompt-line/src/prompt-line-controller.d.ts +25 -78
- package/es-custom/components/prompt-line/src/prompt-line-controller.js +0 -389
- package/es-custom/components/prompt-line/src/prompt-line-controller.js.map +1 -1
- package/es-custom/components/prompt-line/src/prompt-line-mouse-focus.d.ts +45 -0
- package/es-custom/components/prompt-line/src/prompt-line-mouse-focus.js +83 -0
- package/es-custom/components/prompt-line/src/prompt-line-mouse-focus.js.map +1 -0
- package/es-custom/components/prompt-line/src/prompt-line-rich-runtime.d.ts +0 -2
- package/es-custom/components/prompt-line/src/prompt-line-rich-runtime.js +30 -53
- package/es-custom/components/prompt-line/src/prompt-line-rich-runtime.js.map +1 -1
- package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.d.ts +87 -0
- package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.js +390 -0
- package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.js.map +1 -0
- package/es-custom/components/prompt-line/src/prompt-line.d.ts +1 -1
- package/es-custom/components/prompt-line/src/prompt-line.js +6 -5
- package/es-custom/components/prompt-line/src/prompt-line.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/extension-equivalence.d.ts +2 -1
- package/es-custom/components/prompt-line/src/tiptap/extension-equivalence.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/typing-indicator.js +1 -1
- package/es-custom/components/prompt-line/src/tiptap/typing-indicator.js.map +1 -1
- package/es-custom/components/truncated-text/src/truncated-text.js +2 -2
- package/es-custom/components/truncated-text/src/truncated-text.js.map +1 -1
- package/es-custom/components/video-player/src/utils/url-detector.d.ts +0 -28
- package/es-custom/components/video-player/src/utils/url-detector.js +1 -37
- package/es-custom/components/video-player/src/utils/url-detector.js.map +1 -1
- package/es-custom/globals/utils/browser-utils.d.ts +3 -5
- package/es-custom/globals/utils/browser-utils.js +1 -1
- package/es-custom/globals/utils/browser-utils.js.map +1 -1
- package/es-custom/globals/utils/csv.d.ts +0 -1
- package/es-custom/globals/utils/csv.js.map +1 -1
- package/es-custom/react/truncated-text.d.ts +12 -0
- package/es-custom/react/truncated-text.js +28 -0
- package/es-custom/react/truncated-text.js.map +1 -0
- package/es-custom/testing/PageObjectId.d.ts +0 -4
- package/es-custom/testing/PageObjectId.js.map +1 -1
- package/es-custom/testing/load-all-lazy-deps.d.ts +1 -2
- package/es-custom/testing/load-all-lazy-deps.js +3 -3
- package/es-custom/testing/load-all-lazy-deps.js.map +1 -1
- package/package.json +3 -4
- package/es/components/markdown/src/markdown.template.d.ts +0 -6
- package/es/components/markdown/src/markdown.template.js +0 -29
- package/es/components/markdown/src/markdown.template.js.map +0 -1
- package/es-custom/components/markdown/src/markdown.template.d.ts +0 -6
- package/es-custom/components/markdown/src/markdown.template.js +0 -29
- package/es-custom/components/markdown/src/markdown.template.js.map +0 -1
|
@@ -13,7 +13,7 @@ import Placeholder from '@tiptap/extension-placeholder';
|
|
|
13
13
|
import TextNode from '@tiptap/extension-text';
|
|
14
14
|
import { UndoRedo } from '@tiptap/extensions';
|
|
15
15
|
import { IS_PHONE } from '../../../globals/utils/browser-utils.js';
|
|
16
|
-
import {
|
|
16
|
+
import { MouseFocusController } from './prompt-line-mouse-focus.js';
|
|
17
17
|
import { applyEditorStyles } from './tiptap/editor-styles.js';
|
|
18
18
|
import { HISTORY_DEFAULTS } from './prompt-line-constants.js';
|
|
19
19
|
import { writeStarterStorage } from './tiptap/carbon-starter-trigger.js';
|
|
@@ -51,22 +51,13 @@ import { setHostOriginMeta } from './tiptap/origin-meta.js';
|
|
|
51
51
|
* `cds-aichat-prompt-*` events so the shell, React wrapper, and `Input`
|
|
52
52
|
* handlers are mode-agnostic.
|
|
53
53
|
*/
|
|
54
|
-
/** Exported so tests assert the ring without retyping the literal. */
|
|
55
|
-
const PM_KEYBOARD_FOCUS_CLASS = 'cds-aichat--input-pm-content--keyboard-focus';
|
|
56
|
-
let keyboardFocusRuleInstalled = false;
|
|
57
|
-
function ensureKeyboardFocusRule() {
|
|
58
|
-
if (keyboardFocusRuleInstalled) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
setVarsForSelector(`.${PM_KEYBOARD_FOCUS_CLASS}`, { outline: 'revert' });
|
|
62
|
-
keyboardFocusRuleInstalled = true;
|
|
63
|
-
}
|
|
64
54
|
/**
|
|
65
55
|
* Tiptap-backed prompt-line controller. Mirrors the editor lifecycle the
|
|
66
56
|
* element owned before the textarea/rich split.
|
|
67
57
|
*/
|
|
68
|
-
class RichController {
|
|
58
|
+
class RichController extends MouseFocusController {
|
|
69
59
|
constructor() {
|
|
60
|
+
super(...arguments);
|
|
70
61
|
this._editor = null;
|
|
71
62
|
this._host = null;
|
|
72
63
|
this._extensions = [];
|
|
@@ -81,40 +72,29 @@ class RichController {
|
|
|
81
72
|
* loses its undo history for nothing.
|
|
82
73
|
*/
|
|
83
74
|
this._installedExtensions = [];
|
|
75
|
+
this._ariaLabel = '';
|
|
84
76
|
this._placeholder = '';
|
|
85
77
|
this._testId = '';
|
|
86
78
|
this._disabled = false;
|
|
87
|
-
this._focusFromMouse = false;
|
|
88
79
|
this._isComposing = false;
|
|
80
|
+
this._hadFocus = false;
|
|
89
81
|
/** Set when a recreate is withheld during an IME composition. */
|
|
90
82
|
this._pendingRecreate = false;
|
|
91
83
|
this._pendingRecreateTimer = null;
|
|
92
|
-
// -------------------------------------------------------------------------
|
|
93
|
-
// Internals
|
|
94
|
-
// -------------------------------------------------------------------------
|
|
95
|
-
this._setMouseFlag = () => {
|
|
96
|
-
this._focusFromMouse = true;
|
|
97
|
-
};
|
|
98
84
|
}
|
|
99
85
|
mount(host, init) {
|
|
100
86
|
this._host = host;
|
|
101
87
|
this._extensions = init.extensions ?? [];
|
|
88
|
+
this._ariaLabel = init.ariaLabel;
|
|
102
89
|
this._placeholder = init.placeholder;
|
|
103
90
|
this._testId = init.testId;
|
|
104
91
|
this._disabled = init.disabled;
|
|
105
|
-
host.setAttribute('role', 'textbox');
|
|
106
92
|
host.setAttribute('aria-multiline', 'true');
|
|
107
93
|
host.setAttribute('spellcheck', 'true');
|
|
108
94
|
host.setAttribute('tabindex', '-1');
|
|
109
|
-
if (init.ariaLabel) {
|
|
110
|
-
host.setAttribute('aria-label', init.ariaLabel);
|
|
111
|
-
}
|
|
112
95
|
// Pointer/touch before focus marks the next focus as mouse-driven so we
|
|
113
96
|
// suppress the keyboard-focus outline.
|
|
114
|
-
|
|
115
|
-
host.addEventListener('mousedown', this._setMouseFlag);
|
|
116
|
-
host.addEventListener('touchstart', this._setMouseFlag);
|
|
117
|
-
ensureKeyboardFocusRule();
|
|
97
|
+
this._attachMouseFocusListeners(host);
|
|
118
98
|
// Prefer a structured `content` seed (mentions / custom nodes); otherwise
|
|
119
99
|
// rebuild a doc from the plain-text value (lossless from the textarea).
|
|
120
100
|
const seed = init.content ?? textToDoc(init.value);
|
|
@@ -127,15 +107,14 @@ class RichController {
|
|
|
127
107
|
destroy() {
|
|
128
108
|
const host = this._host;
|
|
129
109
|
if (host) {
|
|
130
|
-
|
|
131
|
-
host.removeEventListener('mousedown', this._setMouseFlag);
|
|
132
|
-
host.removeEventListener('touchstart', this._setMouseFlag);
|
|
110
|
+
this._detachMouseFocusListeners(host);
|
|
133
111
|
}
|
|
134
112
|
if (this._pendingRecreateTimer) {
|
|
135
113
|
clearTimeout(this._pendingRecreateTimer);
|
|
136
114
|
this._pendingRecreateTimer = null;
|
|
137
115
|
}
|
|
138
116
|
this._isComposing = false;
|
|
117
|
+
this._hadFocus = false;
|
|
139
118
|
this._pendingRecreate = false;
|
|
140
119
|
this._editor?.destroy();
|
|
141
120
|
this._editor = null;
|
|
@@ -189,8 +168,8 @@ class RichController {
|
|
|
189
168
|
getEditor() {
|
|
190
169
|
return this._editor;
|
|
191
170
|
}
|
|
192
|
-
focus() {
|
|
193
|
-
this.
|
|
171
|
+
focus(keyboardFocus) {
|
|
172
|
+
this._setNextFocusOrigin(keyboardFocus);
|
|
194
173
|
this._editor?.commands.focus();
|
|
195
174
|
}
|
|
196
175
|
blur() {
|
|
@@ -224,15 +203,7 @@ class RichController {
|
|
|
224
203
|
}
|
|
225
204
|
}
|
|
226
205
|
setAriaLabel(ariaLabel) {
|
|
227
|
-
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
if (ariaLabel) {
|
|
231
|
-
this._host.setAttribute('aria-label', ariaLabel);
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
this._host.removeAttribute('aria-label');
|
|
235
|
-
}
|
|
206
|
+
this._ariaLabel = ariaLabel;
|
|
236
207
|
}
|
|
237
208
|
setTestId(testId) {
|
|
238
209
|
this._testId = testId;
|
|
@@ -285,6 +256,9 @@ class RichController {
|
|
|
285
256
|
redo() {
|
|
286
257
|
return Boolean(this._editor?.commands.redo());
|
|
287
258
|
}
|
|
259
|
+
// -------------------------------------------------------------------------
|
|
260
|
+
// Internals
|
|
261
|
+
// -------------------------------------------------------------------------
|
|
288
262
|
_flushPendingRecreate() {
|
|
289
263
|
// A fresh composition may have started while the flush was queued; its own
|
|
290
264
|
// compositionend re-queues this. A detached host means the element's own
|
|
@@ -329,6 +303,15 @@ class RichController {
|
|
|
329
303
|
return new Editor({
|
|
330
304
|
element,
|
|
331
305
|
extensions: [...baseExtensions, ...this._extensions],
|
|
306
|
+
editorProps: {
|
|
307
|
+
attributes: () => {
|
|
308
|
+
const attrs = { role: 'textbox' };
|
|
309
|
+
if (this._ariaLabel) {
|
|
310
|
+
attrs['aria-label'] = this._ariaLabel;
|
|
311
|
+
}
|
|
312
|
+
return attrs;
|
|
313
|
+
},
|
|
314
|
+
},
|
|
332
315
|
content: content ?? undefined,
|
|
333
316
|
autofocus: false,
|
|
334
317
|
injectCSS: false,
|
|
@@ -336,15 +319,11 @@ class RichController {
|
|
|
336
319
|
}
|
|
337
320
|
_wireEditorEvents(editor) {
|
|
338
321
|
editor.on('focus', () => {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
if (!wasMouseFocus) {
|
|
342
|
-
editor.view.dom.classList.add(PM_KEYBOARD_FOCUS_CLASS);
|
|
343
|
-
}
|
|
322
|
+
this._hadFocus = true;
|
|
323
|
+
const wasMouseFocus = this._consumeMouseFocus();
|
|
344
324
|
this._dispatch('cds-aichat-prompt-focus', { keyboard: !wasMouseFocus });
|
|
345
325
|
});
|
|
346
326
|
editor.on('blur', () => {
|
|
347
|
-
editor.view.dom.classList.remove(PM_KEYBOARD_FOCUS_CLASS);
|
|
348
327
|
this._dispatch('cds-aichat-prompt-blur');
|
|
349
328
|
});
|
|
350
329
|
// Forward keydown for hosts wanting raw-key access. ValueSync /
|
|
@@ -370,9 +349,8 @@ class RichController {
|
|
|
370
349
|
to: this._editor.state.selection.to,
|
|
371
350
|
}
|
|
372
351
|
: null;
|
|
373
|
-
const wasFocused = this.
|
|
374
|
-
const wasKeyboardFocus = this.
|
|
375
|
-
false;
|
|
352
|
+
const wasFocused = this._hadFocus;
|
|
353
|
+
const wasKeyboardFocus = this.getKeyboardFocus();
|
|
376
354
|
this._editor?.destroy();
|
|
377
355
|
this._editor = this._createEditor(host, previousJson);
|
|
378
356
|
this._wireEditorEvents(this._editor);
|
|
@@ -386,8 +364,7 @@ class RichController {
|
|
|
386
364
|
this._editor.commands.setTextSelection({ from, to });
|
|
387
365
|
}
|
|
388
366
|
if (wasFocused) {
|
|
389
|
-
this.
|
|
390
|
-
this._editor.commands.focus();
|
|
367
|
+
this.focus(wasKeyboardFocus);
|
|
391
368
|
}
|
|
392
369
|
}
|
|
393
370
|
_dispatchSetContent(content) {
|
|
@@ -434,5 +411,5 @@ function createRichController() {
|
|
|
434
411
|
return new RichController();
|
|
435
412
|
}
|
|
436
413
|
|
|
437
|
-
export {
|
|
414
|
+
export { createRichController };
|
|
438
415
|
//# sourceMappingURL=prompt-line-rich-runtime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-line-rich-runtime.js","sources":["../../../../src/components/prompt-line/src/prompt-line-rich-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 * Tiptap runtime for `<cds-aichat-prompt-line>`'s rich mode. This module is the\n * **only** place the prompt-line stack imports `@tiptap/*` at runtime, and it\n * is reached exclusively through a dynamic `import()` (see\n * [./prompt-line-rich-loader.ts]). A bundler therefore splits Tiptap into its\n * own lazy chunk, keeping it out of the default bundle for chats that never\n * enable advanced input features.\n *\n * `createRichController()` returns a {@link PromptLineController} backed by a\n * Tiptap `Editor`. It installs the Carbon base bundle — schema (`Document` +\n * `Paragraph` + `Text` + `HardBreak`), undo/redo, placeholder, plain-text\n * paste, the chat keymap (`Mod-Enter`/`Escape`), Enter-to-send\n * (`carbonChatEnter`), value-sync, and the typing indicator — and emits the\n * identical\n * `cds-aichat-prompt-*` events so the shell, React wrapper, and `Input`\n * handlers are mode-agnostic.\n */\n\nimport { Editor, type Extension, type JSONContent } from '@tiptap/core';\nimport DocumentNode from '@tiptap/extension-document';\nimport HardBreakNode from '@tiptap/extension-hard-break';\nimport ParagraphNode from '@tiptap/extension-paragraph';\nimport Placeholder from '@tiptap/extension-placeholder';\nimport TextNode from '@tiptap/extension-text';\nimport { UndoRedo } from '@tiptap/extensions';\n\nimport { IS_PHONE } from '../../../globals/utils/browser-utils.js';\nimport { setVarsForSelector } from '../../shared/dynamic-css-var-sheet.js';\nimport type {\n PromptLineController,\n PromptLineControllerInit,\n SetContentUpdater,\n} from './prompt-line-controller.js';\nimport { applyEditorStyles } from './tiptap/editor-styles.js';\nimport { HISTORY_DEFAULTS } from './prompt-line-constants.js';\nimport { writeStarterStorage } from './tiptap/carbon-starter-trigger.js';\nimport {\n areExtensionSetsEquivalent,\n getExtensionSource,\n} from './tiptap/extension-equivalence.js';\nimport { carbonChatEnter } from './tiptap/chat-enter.js';\nimport { Keymap } from './tiptap/keymap.js';\nimport { PlainTextPaste } from './tiptap/plain-text-paste.js';\nimport { TypingIndicator } from './tiptap/typing-indicator.js';\nimport { ValueSync } from './tiptap/value-sync.js';\nimport type { StartersConfig } from './tiptap/types.js';\nimport { textToDoc } from './tiptap/json-utils.js';\nimport { setHostOriginMeta } from './tiptap/origin-meta.js';\n\n/** Exported so tests assert the ring without retyping the literal. */\nexport const PM_KEYBOARD_FOCUS_CLASS =\n 'cds-aichat--input-pm-content--keyboard-focus';\n\nlet keyboardFocusRuleInstalled = false;\nfunction ensureKeyboardFocusRule(): void {\n if (keyboardFocusRuleInstalled) {\n return;\n }\n setVarsForSelector(`.${PM_KEYBOARD_FOCUS_CLASS}`, { outline: 'revert' });\n keyboardFocusRuleInstalled = true;\n}\n\n/**\n * Tiptap-backed prompt-line controller. Mirrors the editor lifecycle the\n * element owned before the textarea/rich split.\n */\nclass RichController implements PromptLineController {\n private _editor: Editor | null = null;\n private _host: HTMLElement | null = null;\n private _extensions: Extension[] = [];\n /**\n * The set the live editor was built from. `_createEditor` assigns it the same\n * reference as `_extensions`, so the two are normally identical; they diverge\n * only between a `setExtensions` that adopted an equivalent set without\n * rebuilding and the next `_createEditor`. Only `_flushPendingRecreate` needs\n * the distinction: a rebuild withheld for a composition has to be judged\n * against what is installed, not against the set that was pending when the\n * composition began, or a host that changed the config and changed it back\n * loses its undo history for nothing.\n */\n private _installedExtensions: Extension[] = [];\n private _placeholder = '';\n private _testId = '';\n private _disabled = false;\n private _focusFromMouse = false;\n private _isComposing = false;\n /** Set when a recreate is withheld during an IME composition. */\n private _pendingRecreate = false;\n private _pendingRecreateTimer: ReturnType<typeof setTimeout> | null = null;\n\n mount(host: HTMLElement, init: PromptLineControllerInit): void {\n this._host = host;\n this._extensions = init.extensions ?? [];\n this._placeholder = init.placeholder;\n this._testId = init.testId;\n this._disabled = init.disabled;\n\n host.setAttribute('role', 'textbox');\n host.setAttribute('aria-multiline', 'true');\n host.setAttribute('spellcheck', 'true');\n host.setAttribute('tabindex', '-1');\n if (init.ariaLabel) {\n host.setAttribute('aria-label', init.ariaLabel);\n }\n\n // Pointer/touch before focus marks the next focus as mouse-driven so we\n // suppress the keyboard-focus outline.\n host.addEventListener('pointerdown', this._setMouseFlag);\n host.addEventListener('mousedown', this._setMouseFlag);\n host.addEventListener('touchstart', this._setMouseFlag);\n\n ensureKeyboardFocusRule();\n\n // Prefer a structured `content` seed (mentions / custom nodes); otherwise\n // rebuild a doc from the plain-text value (lossless from the textarea).\n const seed = init.content ?? textToDoc(init.value);\n this._editor = this._createEditor(host, seed);\n this._wireEditorEvents(this._editor);\n applyEditorStyles(this._editor.view.dom as HTMLElement, IS_PHONE);\n this._applyTestIdToEditorDom();\n this._editor.setEditable(!this._disabled);\n }\n\n destroy(): void {\n const host = this._host;\n if (host) {\n host.removeEventListener('pointerdown', this._setMouseFlag);\n host.removeEventListener('mousedown', this._setMouseFlag);\n host.removeEventListener('touchstart', this._setMouseFlag);\n }\n if (this._pendingRecreateTimer) {\n clearTimeout(this._pendingRecreateTimer);\n this._pendingRecreateTimer = null;\n }\n this._isComposing = false;\n this._pendingRecreate = false;\n this._editor?.destroy();\n this._editor = null;\n this._host = null;\n }\n\n getValue(): string {\n return this._editor?.getText() ?? '';\n }\n\n setContent(next: JSONContent | string | SetContentUpdater): void {\n const editor = this._editor;\n if (!editor) {\n return;\n }\n if (typeof next === 'function') {\n const prev = editor.getJSON();\n this._dispatchSetContent((next as SetContentUpdater)(prev));\n return;\n }\n this._dispatchSetContent(next);\n }\n\n insertContent(\n content: JSONContent | string,\n opts: { at?: number } = {}\n ): void {\n const editor = this._editor;\n if (!editor) {\n return;\n }\n if (typeof opts.at === 'number') {\n editor.commands.insertContentAt(opts.at, content);\n return;\n }\n editor.commands.insertContent(content);\n }\n\n clearContent(): void {\n const editor = this._editor;\n if (!editor) {\n return;\n }\n // Tag the clear as host-origin so the carbon-mention/command removal plugin\n // treats the post-send wipe as programmatic (not a user edit) and skips\n // firing `onRemove`. Otherwise a send would strip the just-captured\n // mention/command fields from the host's structured_data sidecar before\n // `doSend` merges them. Mirrors `_dispatchSetContent`.\n editor\n .chain()\n .command(({ tr }) => {\n setHostOriginMeta(tr);\n return true;\n })\n .clearContent(true)\n .run();\n }\n\n getEditor(): Editor | null {\n return this._editor;\n }\n\n focus(): void {\n this._focusFromMouse = true;\n this._editor?.commands.focus();\n }\n\n blur(): void {\n this._editor?.commands.blur();\n }\n\n hasFocus(): boolean {\n return this._editor?.isFocused ?? false;\n }\n\n getSelection(): { from: number; to: number } {\n const sel = this._editor?.state.selection;\n return sel ? { from: sel.from, to: sel.to } : { from: 0, to: 0 };\n }\n\n setTextSelection(pos: number | { from: number; to: number }): void {\n this._editor?.commands.setTextSelection(pos);\n }\n\n selectAll(): void {\n this._editor?.commands.selectAll();\n }\n\n setEditable(editable: boolean): void {\n this._disabled = !editable;\n this._editor?.setEditable(editable);\n }\n\n setPlaceholder(placeholder: string): void {\n this._placeholder = placeholder;\n // The Placeholder extension reads this back through the resolver installed\n // in `_createEditor`; the empty transaction repaints the decoration so the\n // new text shows without waiting for the next edit.\n const editor = this._editor;\n if (editor) {\n editor.view.dispatch(editor.state.tr);\n }\n }\n\n setAriaLabel(ariaLabel: string): void {\n if (!this._host) {\n return;\n }\n if (ariaLabel) {\n this._host.setAttribute('aria-label', ariaLabel);\n } else {\n this._host.removeAttribute('aria-label');\n }\n }\n\n setTestId(testId: string): void {\n this._testId = testId;\n this._applyTestIdToEditorDom();\n }\n\n setExtensions(extensions: Extension[]): void {\n const equivalent = areExtensionSetsEquivalent(this._extensions, extensions);\n // Adopt the new list either way — a later genuine change is compared\n // against what the host most recently supplied.\n this._extensions = extensions;\n if (equivalent) {\n // Starter items / isOn ride on extension storage precisely so they can be\n // swapped without a recreate.\n this._syncStarterStorage();\n return;\n }\n this._recreateEditor();\n }\n\n setComposing(composing: boolean): void {\n this._isComposing = composing;\n if (composing || !this._pendingRecreate || this._pendingRecreateTimer) {\n return;\n }\n // ProseMirror defers the last composed segment to a microtask after\n // compositionend, so recreating here would snapshot the doc without it and\n // lose the character the user just committed. A macrotask runs after that\n // flush.\n this._pendingRecreateTimer = setTimeout(() => {\n this._pendingRecreateTimer = null;\n this._flushPendingRecreate();\n });\n }\n\n /** Push the current starter config onto the live editor's storage. */\n private _syncStarterStorage(): void {\n const source = this._extensions\n .map(getExtensionSource)\n .find((descriptor) => descriptor?.kind === 'starters');\n const config = source?.config as StartersConfig | undefined;\n if (!config) {\n return;\n }\n writeStarterStorage(this._editor, {\n items: config.items,\n isOn: config.isOn !== false,\n });\n }\n\n undo(): boolean {\n return Boolean(this._editor?.commands.undo());\n }\n\n redo(): boolean {\n return Boolean(this._editor?.commands.redo());\n }\n\n // -------------------------------------------------------------------------\n // Internals\n // -------------------------------------------------------------------------\n\n private _setMouseFlag = (): void => {\n this._focusFromMouse = true;\n };\n\n private _flushPendingRecreate(): void {\n // A fresh composition may have started while the flush was queued; its own\n // compositionend re-queues this. A detached host means the element's own\n // deferred teardown is already pending, so rebuilding would raise an editor\n // only to destroy it a task later.\n if (\n !this._host?.isConnected ||\n !this._pendingRecreate ||\n this._isComposing\n ) {\n return;\n }\n // Compare against what is installed, not the set that was pending when the\n // composition began: a host that changed the config and changed it back has\n // nothing left to rebuild, and rebuilding anyway would drop undo history.\n if (\n areExtensionSetsEquivalent(this._installedExtensions, this._extensions)\n ) {\n this._pendingRecreate = false;\n this._syncStarterStorage();\n return;\n }\n this._recreateEditor();\n }\n\n private _createEditor(\n element: HTMLElement,\n content: JSONContent | string | undefined\n ): Editor {\n const baseExtensions: Extension[] = [\n DocumentNode as unknown as Extension,\n ParagraphNode as unknown as Extension,\n TextNode as unknown as Extension,\n HardBreakNode as unknown as Extension,\n UndoRedo.configure({ ...HISTORY_DEFAULTS }),\n // Resolved per decoration build rather than captured, so `setPlaceholder`\n // lands on the live editor. Tiptap snapshots an extension's options when\n // it builds plugins, so a value here could never be updated in place.\n Placeholder.configure({ placeholder: () => this._placeholder }),\n PlainTextPaste,\n Keymap,\n // Plain Enter sends (non-empty); empty Enter falls through to a newline.\n // Baked into the base bundle so the rich editor and the textarea agree on\n // Enter-to-send without the chat layer wiring it per surface.\n carbonChatEnter(),\n ValueSync,\n TypingIndicator,\n ];\n this._installedExtensions = this._extensions;\n return new Editor({\n element,\n extensions: [...baseExtensions, ...this._extensions],\n content: content ?? undefined,\n autofocus: false,\n injectCSS: false,\n });\n }\n\n private _wireEditorEvents(editor: Editor): void {\n editor.on('focus', () => {\n const wasMouseFocus = this._focusFromMouse;\n this._focusFromMouse = false;\n if (!wasMouseFocus) {\n editor.view.dom.classList.add(PM_KEYBOARD_FOCUS_CLASS);\n }\n this._dispatch('cds-aichat-prompt-focus', { keyboard: !wasMouseFocus });\n });\n editor.on('blur', () => {\n editor.view.dom.classList.remove(PM_KEYBOARD_FOCUS_CLASS);\n this._dispatch('cds-aichat-prompt-blur');\n });\n // Forward keydown for hosts wanting raw-key access. ValueSync /\n // TypingIndicator emit their own events; don't re-dispatch update here.\n editor.view.dom.addEventListener('keydown', (event) => {\n this._dispatch('cds-aichat-prompt-keydown', { originalEvent: event });\n });\n }\n\n private _recreateEditor(): void {\n const host = this._host;\n if (!host) {\n return;\n }\n if (this._isComposing) {\n this._pendingRecreate = true;\n return;\n }\n this._pendingRecreate = false;\n const previousJson = this._editor?.getJSON();\n const previousSelection = this._editor\n ? {\n from: this._editor.state.selection.from,\n to: this._editor.state.selection.to,\n }\n : null;\n const wasFocused = this._editor?.isFocused ?? false;\n const wasKeyboardFocus =\n this._editor?.view.dom.classList.contains(PM_KEYBOARD_FOCUS_CLASS) ??\n false;\n this._editor?.destroy();\n this._editor = this._createEditor(host, previousJson);\n this._wireEditorEvents(this._editor);\n applyEditorStyles(this._editor.view.dom as HTMLElement, IS_PHONE);\n this._applyTestIdToEditorDom();\n this._editor.setEditable(!this._disabled);\n if (previousSelection) {\n const { size } = this._editor.state.doc.content;\n const from = Math.min(previousSelection.from, size);\n const to = Math.min(previousSelection.to, size);\n this._editor.commands.setTextSelection({ from, to });\n }\n\n if (wasFocused) {\n this._focusFromMouse = !wasKeyboardFocus;\n this._editor.commands.focus();\n }\n }\n\n private _dispatchSetContent(content: JSONContent | string): void {\n const editor = this._editor;\n if (!editor) {\n return;\n }\n // Chain a no-op command that meta-tags the accumulator tr as host-origin,\n // then setContent on the same tr so downstream readers (typing-indicator)\n // recognize the update.\n editor\n .chain()\n .command(({ tr }) => {\n setHostOriginMeta(tr);\n return true;\n })\n .setContent(content, { emitUpdate: true })\n .run();\n }\n\n // Mirror testId onto the inner ProseMirror contenteditable (not the host\n // wrapper) so Playwright's editable-action helpers (`.fill()`, etc.) accept\n // it. `view.dom` is replaced on each recreate, so re-apply.\n private _applyTestIdToEditorDom(): void {\n const editorDom = this._editor?.view.dom as HTMLElement | undefined;\n if (!editorDom) {\n return;\n }\n if (this._testId) {\n editorDom.setAttribute('data-testid', this._testId);\n } else {\n editorDom.removeAttribute('data-testid');\n }\n }\n\n private _dispatch(name: string, detail?: unknown): void {\n this._host?.dispatchEvent(\n new CustomEvent(name, { detail, bubbles: true, composed: true })\n );\n }\n}\n\n/**\n * Construct a Tiptap-backed prompt-line controller. Called by the shell once\n * the lazily-imported runtime module has resolved.\n */\nexport function createRichController(): PromptLineController {\n return new RichController();\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;AAOG;AAEH;;;;;;;;;;;;;;;;AAgBG;AAiCH;AACO,MAAM,uBAAuB,GAClC;AAEF,IAAI,0BAA0B,GAAG,KAAK;AACtC,SAAS,uBAAuB,GAAA;IAC9B,IAAI,0BAA0B,EAAE;QAC9B;IACF;IACA,kBAAkB,CAAC,CAAA,CAAA,EAAI,uBAAuB,CAAA,CAAE,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;IACxE,0BAA0B,GAAG,IAAI;AACnC;AAEA;;;AAGG;AACH,MAAM,cAAc,CAAA;AAApB,IAAA,WAAA,GAAA;QACU,IAAA,CAAA,OAAO,GAAkB,IAAI;QAC7B,IAAA,CAAA,KAAK,GAAuB,IAAI;QAChC,IAAA,CAAA,WAAW,GAAgB,EAAE;AACrC;;;;;;;;;AASG;QACK,IAAA,CAAA,oBAAoB,GAAgB,EAAE;QACtC,IAAA,CAAA,YAAY,GAAG,EAAE;QACjB,IAAA,CAAA,OAAO,GAAG,EAAE;QACZ,IAAA,CAAA,SAAS,GAAG,KAAK;QACjB,IAAA,CAAA,eAAe,GAAG,KAAK;QACvB,IAAA,CAAA,YAAY,GAAG,KAAK;;QAEpB,IAAA,CAAA,gBAAgB,GAAG,KAAK;QACxB,IAAA,CAAA,qBAAqB,GAAyC,IAAI;;;;QA+NlE,IAAA,CAAA,aAAa,GAAG,MAAW;AACjC,YAAA,IAAI,CAAC,eAAe,GAAG,IAAI;AAC7B,QAAA,CAAC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,IAAI,EAAE;AACxC,aAAA,GAAG,EAAE;IACV;;;;IAKQ,uBAAuB,GAAA;QAC7B,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,GAA8B;QACnE,IAAI,CAAC,SAAS,EAAE;YACd;QACF;AACA,QAAA,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,SAAS,CAAC,YAAY,CAAC,aAAa,EAAE,IAAI,CAAC,OAAO,CAAC;QACrD;aAAO;AACL,YAAA,SAAS,CAAC,eAAe,CAAC,aAAa,CAAC;QAC1C;IACF;IAEQ,SAAS,CAAC,IAAY,EAAE,MAAgB,EAAA;QAC9C,IAAI,CAAC,KAAK,EAAE,aAAa,CACvB,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CACjE;IACH;AACD;AAED;;;AAGG;SACa,oBAAoB,GAAA;IAClC,OAAO,IAAI,cAAc,EAAE;AAC7B;;"}
|
|
1
|
+
{"version":3,"file":"prompt-line-rich-runtime.js","sources":["../../../../src/components/prompt-line/src/prompt-line-rich-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 * Tiptap runtime for `<cds-aichat-prompt-line>`'s rich mode. This module is the\n * **only** place the prompt-line stack imports `@tiptap/*` at runtime, and it\n * is reached exclusively through a dynamic `import()` (see\n * [./prompt-line-rich-loader.ts]). A bundler therefore splits Tiptap into its\n * own lazy chunk, keeping it out of the default bundle for chats that never\n * enable advanced input features.\n *\n * `createRichController()` returns a {@link PromptLineController} backed by a\n * Tiptap `Editor`. It installs the Carbon base bundle — schema (`Document` +\n * `Paragraph` + `Text` + `HardBreak`), undo/redo, placeholder, plain-text\n * paste, the chat keymap (`Mod-Enter`/`Escape`), Enter-to-send\n * (`carbonChatEnter`), value-sync, and the typing indicator — and emits the\n * identical\n * `cds-aichat-prompt-*` events so the shell, React wrapper, and `Input`\n * handlers are mode-agnostic.\n */\n\nimport { Editor, type Extension, type JSONContent } from '@tiptap/core';\nimport DocumentNode from '@tiptap/extension-document';\nimport HardBreakNode from '@tiptap/extension-hard-break';\nimport ParagraphNode from '@tiptap/extension-paragraph';\nimport Placeholder from '@tiptap/extension-placeholder';\nimport TextNode from '@tiptap/extension-text';\nimport { UndoRedo } from '@tiptap/extensions';\n\nimport { IS_PHONE } from '../../../globals/utils/browser-utils.js';\nimport { MouseFocusController } from './prompt-line-mouse-focus.js';\nimport type {\n PromptLineController,\n PromptLineControllerInit,\n SetContentUpdater,\n} from './prompt-line-controller.js';\nimport { applyEditorStyles } from './tiptap/editor-styles.js';\nimport { HISTORY_DEFAULTS } from './prompt-line-constants.js';\nimport { writeStarterStorage } from './tiptap/carbon-starter-trigger.js';\nimport {\n areExtensionSetsEquivalent,\n getExtensionSource,\n} from './tiptap/extension-equivalence.js';\nimport { carbonChatEnter } from './tiptap/chat-enter.js';\nimport { Keymap } from './tiptap/keymap.js';\nimport { PlainTextPaste } from './tiptap/plain-text-paste.js';\nimport { TypingIndicator } from './tiptap/typing-indicator.js';\nimport { ValueSync } from './tiptap/value-sync.js';\nimport type { StartersConfig } from './tiptap/types.js';\nimport { textToDoc } from './tiptap/json-utils.js';\nimport { setHostOriginMeta } from './tiptap/origin-meta.js';\n\n/**\n * Tiptap-backed prompt-line controller. Mirrors the editor lifecycle the\n * element owned before the textarea/rich split.\n */\nclass RichController\n extends MouseFocusController\n implements PromptLineController\n{\n private _editor: Editor | null = null;\n private _host: HTMLElement | null = null;\n private _extensions: Extension[] = [];\n /**\n * The set the live editor was built from. `_createEditor` assigns it the same\n * reference as `_extensions`, so the two are normally identical; they diverge\n * only between a `setExtensions` that adopted an equivalent set without\n * rebuilding and the next `_createEditor`. Only `_flushPendingRecreate` needs\n * the distinction: a rebuild withheld for a composition has to be judged\n * against what is installed, not against the set that was pending when the\n * composition began, or a host that changed the config and changed it back\n * loses its undo history for nothing.\n */\n private _installedExtensions: Extension[] = [];\n private _ariaLabel = '';\n private _placeholder = '';\n private _testId = '';\n private _disabled = false;\n private _isComposing = false;\n private _hadFocus = false;\n /** Set when a recreate is withheld during an IME composition. */\n private _pendingRecreate = false;\n private _pendingRecreateTimer: ReturnType<typeof setTimeout> | null = null;\n\n mount(host: HTMLElement, init: PromptLineControllerInit): void {\n this._host = host;\n this._extensions = init.extensions ?? [];\n this._ariaLabel = init.ariaLabel;\n this._placeholder = init.placeholder;\n this._testId = init.testId;\n this._disabled = init.disabled;\n\n host.setAttribute('aria-multiline', 'true');\n host.setAttribute('spellcheck', 'true');\n host.setAttribute('tabindex', '-1');\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 // Prefer a structured `content` seed (mentions / custom nodes); otherwise\n // rebuild a doc from the plain-text value (lossless from the textarea).\n const seed = init.content ?? textToDoc(init.value);\n this._editor = this._createEditor(host, seed);\n this._wireEditorEvents(this._editor);\n applyEditorStyles(this._editor.view.dom as HTMLElement, IS_PHONE);\n this._applyTestIdToEditorDom();\n this._editor.setEditable(!this._disabled);\n }\n\n destroy(): void {\n const host = this._host;\n if (host) {\n this._detachMouseFocusListeners(host);\n }\n if (this._pendingRecreateTimer) {\n clearTimeout(this._pendingRecreateTimer);\n this._pendingRecreateTimer = null;\n }\n this._isComposing = false;\n this._hadFocus = false;\n this._pendingRecreate = false;\n this._editor?.destroy();\n this._editor = null;\n this._host = null;\n }\n\n getValue(): string {\n return this._editor?.getText() ?? '';\n }\n\n setContent(next: JSONContent | string | SetContentUpdater): void {\n const editor = this._editor;\n if (!editor) {\n return;\n }\n if (typeof next === 'function') {\n const prev = editor.getJSON();\n this._dispatchSetContent((next as SetContentUpdater)(prev));\n return;\n }\n this._dispatchSetContent(next);\n }\n\n insertContent(\n content: JSONContent | string,\n opts: { at?: number } = {}\n ): void {\n const editor = this._editor;\n if (!editor) {\n return;\n }\n if (typeof opts.at === 'number') {\n editor.commands.insertContentAt(opts.at, content);\n return;\n }\n editor.commands.insertContent(content);\n }\n\n clearContent(): void {\n const editor = this._editor;\n if (!editor) {\n return;\n }\n // Tag the clear as host-origin so the carbon-mention/command removal plugin\n // treats the post-send wipe as programmatic (not a user edit) and skips\n // firing `onRemove`. Otherwise a send would strip the just-captured\n // mention/command fields from the host's structured_data sidecar before\n // `doSend` merges them. Mirrors `_dispatchSetContent`.\n editor\n .chain()\n .command(({ tr }) => {\n setHostOriginMeta(tr);\n return true;\n })\n .clearContent(true)\n .run();\n }\n\n getEditor(): Editor | null {\n return this._editor;\n }\n\n focus(keyboardFocus: boolean): void {\n this._setNextFocusOrigin(keyboardFocus);\n this._editor?.commands.focus();\n }\n\n blur(): void {\n this._editor?.commands.blur();\n }\n\n hasFocus(): boolean {\n return this._editor?.isFocused ?? false;\n }\n\n getSelection(): { from: number; to: number } {\n const sel = this._editor?.state.selection;\n return sel ? { from: sel.from, to: sel.to } : { from: 0, to: 0 };\n }\n\n setTextSelection(pos: number | { from: number; to: number }): void {\n this._editor?.commands.setTextSelection(pos);\n }\n\n selectAll(): void {\n this._editor?.commands.selectAll();\n }\n\n setEditable(editable: boolean): void {\n this._disabled = !editable;\n this._editor?.setEditable(editable);\n }\n\n setPlaceholder(placeholder: string): void {\n this._placeholder = placeholder;\n // The Placeholder extension reads this back through the resolver installed\n // in `_createEditor`; the empty transaction repaints the decoration so the\n // new text shows without waiting for the next edit.\n const editor = this._editor;\n if (editor) {\n editor.view.dispatch(editor.state.tr);\n }\n }\n\n setAriaLabel(ariaLabel: string): void {\n this._ariaLabel = ariaLabel;\n }\n\n setTestId(testId: string): void {\n this._testId = testId;\n this._applyTestIdToEditorDom();\n }\n\n setExtensions(extensions: Extension[]): void {\n const equivalent = areExtensionSetsEquivalent(this._extensions, extensions);\n // Adopt the new list either way — a later genuine change is compared\n // against what the host most recently supplied.\n this._extensions = extensions;\n if (equivalent) {\n // Starter items / isOn ride on extension storage precisely so they can be\n // swapped without a recreate.\n this._syncStarterStorage();\n return;\n }\n this._recreateEditor();\n }\n\n setComposing(composing: boolean): void {\n this._isComposing = composing;\n if (composing || !this._pendingRecreate || this._pendingRecreateTimer) {\n return;\n }\n // ProseMirror defers the last composed segment to a microtask after\n // compositionend, so recreating here would snapshot the doc without it and\n // lose the character the user just committed. A macrotask runs after that\n // flush.\n this._pendingRecreateTimer = setTimeout(() => {\n this._pendingRecreateTimer = null;\n this._flushPendingRecreate();\n });\n }\n\n /** Push the current starter config onto the live editor's storage. */\n private _syncStarterStorage(): void {\n const source = this._extensions\n .map(getExtensionSource)\n .find((descriptor) => descriptor?.kind === 'starters');\n const config = source?.config as StartersConfig | undefined;\n if (!config) {\n return;\n }\n writeStarterStorage(this._editor, {\n items: config.items,\n isOn: config.isOn !== false,\n });\n }\n\n undo(): boolean {\n return Boolean(this._editor?.commands.undo());\n }\n\n redo(): boolean {\n return Boolean(this._editor?.commands.redo());\n }\n\n // -------------------------------------------------------------------------\n // Internals\n // -------------------------------------------------------------------------\n\n private _flushPendingRecreate(): void {\n // A fresh composition may have started while the flush was queued; its own\n // compositionend re-queues this. A detached host means the element's own\n // deferred teardown is already pending, so rebuilding would raise an editor\n // only to destroy it a task later.\n if (\n !this._host?.isConnected ||\n !this._pendingRecreate ||\n this._isComposing\n ) {\n return;\n }\n // Compare against what is installed, not the set that was pending when the\n // composition began: a host that changed the config and changed it back has\n // nothing left to rebuild, and rebuilding anyway would drop undo history.\n if (\n areExtensionSetsEquivalent(this._installedExtensions, this._extensions)\n ) {\n this._pendingRecreate = false;\n this._syncStarterStorage();\n return;\n }\n this._recreateEditor();\n }\n\n private _createEditor(\n element: HTMLElement,\n content: JSONContent | string | undefined\n ): Editor {\n const baseExtensions: Extension[] = [\n DocumentNode as unknown as Extension,\n ParagraphNode as unknown as Extension,\n TextNode as unknown as Extension,\n HardBreakNode as unknown as Extension,\n UndoRedo.configure({ ...HISTORY_DEFAULTS }),\n // Resolved per decoration build rather than captured, so `setPlaceholder`\n // lands on the live editor. Tiptap snapshots an extension's options when\n // it builds plugins, so a value here could never be updated in place.\n Placeholder.configure({ placeholder: () => this._placeholder }),\n PlainTextPaste,\n Keymap,\n // Plain Enter sends (non-empty); empty Enter falls through to a newline.\n // Baked into the base bundle so the rich editor and the textarea agree on\n // Enter-to-send without the chat layer wiring it per surface.\n carbonChatEnter(),\n ValueSync,\n TypingIndicator,\n ];\n this._installedExtensions = this._extensions;\n return new Editor({\n element,\n extensions: [...baseExtensions, ...this._extensions],\n editorProps: {\n attributes: () => {\n const attrs: Record<string, string> = { role: 'textbox' };\n if (this._ariaLabel) {\n attrs['aria-label'] = this._ariaLabel;\n }\n return attrs;\n },\n },\n content: content ?? undefined,\n autofocus: false,\n injectCSS: false,\n });\n }\n\n private _wireEditorEvents(editor: Editor): void {\n editor.on('focus', () => {\n this._hadFocus = true;\n const wasMouseFocus = this._consumeMouseFocus();\n this._dispatch('cds-aichat-prompt-focus', { keyboard: !wasMouseFocus });\n });\n editor.on('blur', () => {\n this._dispatch('cds-aichat-prompt-blur');\n });\n // Forward keydown for hosts wanting raw-key access. ValueSync /\n // TypingIndicator emit their own events; don't re-dispatch update here.\n editor.view.dom.addEventListener('keydown', (event) => {\n this._dispatch('cds-aichat-prompt-keydown', { originalEvent: event });\n });\n }\n\n private _recreateEditor(): void {\n const host = this._host;\n if (!host) {\n return;\n }\n if (this._isComposing) {\n this._pendingRecreate = true;\n return;\n }\n this._pendingRecreate = false;\n const previousJson = this._editor?.getJSON();\n const previousSelection = this._editor\n ? {\n from: this._editor.state.selection.from,\n to: this._editor.state.selection.to,\n }\n : null;\n const wasFocused = this._hadFocus;\n const wasKeyboardFocus = this.getKeyboardFocus();\n this._editor?.destroy();\n this._editor = this._createEditor(host, previousJson);\n this._wireEditorEvents(this._editor);\n applyEditorStyles(this._editor.view.dom as HTMLElement, IS_PHONE);\n this._applyTestIdToEditorDom();\n this._editor.setEditable(!this._disabled);\n if (previousSelection) {\n const { size } = this._editor.state.doc.content;\n const from = Math.min(previousSelection.from, size);\n const to = Math.min(previousSelection.to, size);\n this._editor.commands.setTextSelection({ from, to });\n }\n\n if (wasFocused) {\n this.focus(wasKeyboardFocus);\n }\n }\n\n private _dispatchSetContent(content: JSONContent | string): void {\n const editor = this._editor;\n if (!editor) {\n return;\n }\n // Chain a no-op command that meta-tags the accumulator tr as host-origin,\n // then setContent on the same tr so downstream readers (typing-indicator)\n // recognize the update.\n editor\n .chain()\n .command(({ tr }) => {\n setHostOriginMeta(tr);\n return true;\n })\n .setContent(content, { emitUpdate: true })\n .run();\n }\n\n // Mirror testId onto the inner ProseMirror contenteditable (not the host\n // wrapper) so Playwright's editable-action helpers (`.fill()`, etc.) accept\n // it. `view.dom` is replaced on each recreate, so re-apply.\n private _applyTestIdToEditorDom(): void {\n const editorDom = this._editor?.view.dom as HTMLElement | undefined;\n if (!editorDom) {\n return;\n }\n if (this._testId) {\n editorDom.setAttribute('data-testid', this._testId);\n } else {\n editorDom.removeAttribute('data-testid');\n }\n }\n\n private _dispatch(name: string, detail?: unknown): void {\n this._host?.dispatchEvent(\n new CustomEvent(name, { detail, bubbles: true, composed: true })\n );\n }\n}\n\n/**\n * Construct a Tiptap-backed prompt-line controller. Called by the shell once\n * the lazily-imported runtime module has resolved.\n */\nexport function createRichController(): PromptLineController {\n return new RichController();\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;AAOG;AAEH;;;;;;;;;;;;;;;;AAgBG;AAiCH;;;AAGG;AACH,MAAM,cACJ,SAAQ,oBAAoB,CAAA;AAD9B,IAAA,WAAA,GAAA;;QAIU,IAAA,CAAA,OAAO,GAAkB,IAAI;QAC7B,IAAA,CAAA,KAAK,GAAuB,IAAI;QAChC,IAAA,CAAA,WAAW,GAAgB,EAAE;AACrC;;;;;;;;;AASG;QACK,IAAA,CAAA,oBAAoB,GAAgB,EAAE;QACtC,IAAA,CAA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,CAAC,IAAY,EAAE,MAAgB,EAAA;QAC9C,IAAI,CAAC,KAAK,EAAE,aAAa,CACvB,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CACjE;IACH;AACD;AAED;;;AAGG;SACa,oBAAoB,GAAA;IAClC,OAAO,IAAI,cAAc,EAAE;AAC7B;;"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*
|
|
4
|
+
* Copyright IBM Corp. 2026
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Textarea runtime for `<cds-aichat-prompt-line>`'s default (non-rich) mode.
|
|
11
|
+
* This module is **statically imported** by the prompt-line shell
|
|
12
|
+
* ([./prompt-line.ts]), so it is always part of the initial bundle — but it
|
|
13
|
+
* carries **no `@tiptap/*` runtime**. The only Tiptap symbols used here are
|
|
14
|
+
* type imports erased at compile time.
|
|
15
|
+
*
|
|
16
|
+
* `TextareaController` implements {@link PromptLineController} backed by a
|
|
17
|
+
* native `<textarea>`. It mirrors the typography and sizing of the Tiptap
|
|
18
|
+
* editor exactly (auto-grow via a CSS grid mirror, Carbon `body-01` tokens,
|
|
19
|
+
* the same `max-block-size` cap) so the textarea→editor swap triggered by
|
|
20
|
+
* the rich-mode loader ([./prompt-line-rich-loader.ts]) is visually
|
|
21
|
+
* imperceptible. State — plain text, caret position, and keyboard-focus
|
|
22
|
+
* tracking — transfers losslessly to the rich controller because the textarea
|
|
23
|
+
* is always the plain-text source of truth. The same `cds-aichat-prompt-*`
|
|
24
|
+
* events are emitted, keeping the React wrapper and `Input` handlers
|
|
25
|
+
* mode-agnostic.
|
|
26
|
+
*
|
|
27
|
+
* `Editor` / `JSONContent` are **type-only** imports here — erased at compile,
|
|
28
|
+
* so this module carries no Tiptap runtime.
|
|
29
|
+
*/
|
|
30
|
+
import type { Editor, Extension, JSONContent } from '@tiptap/core';
|
|
31
|
+
import { MouseFocusController } from './prompt-line-mouse-focus.js';
|
|
32
|
+
import type { PromptLineController, PromptLineControllerInit, SetContentUpdater } from './prompt-line-controller.js';
|
|
33
|
+
/**
|
|
34
|
+
* `<textarea>`-backed controller. Tiptap-free; emits the same prompt events as
|
|
35
|
+
* the rich editor. Auto-grows via a hidden mirror, capped at
|
|
36
|
+
* `PROMPT_LINE_MAX_BLOCK_SIZE` with the field scrolling past it — the same cap
|
|
37
|
+
* the rich contenteditable applies (see ./tiptap/editor-styles.ts), so the
|
|
38
|
+
* textarea→rich swap is imperceptible.
|
|
39
|
+
*/
|
|
40
|
+
export declare class TextareaController extends MouseFocusController implements PromptLineController {
|
|
41
|
+
private _wrap;
|
|
42
|
+
private _textarea;
|
|
43
|
+
private _mirror;
|
|
44
|
+
private _host;
|
|
45
|
+
private _isTyping;
|
|
46
|
+
private _typingTimer;
|
|
47
|
+
mount(host: HTMLElement, init: PromptLineControllerInit): void;
|
|
48
|
+
destroy(): void;
|
|
49
|
+
getValue(): string;
|
|
50
|
+
setContent(next: JSONContent | string | SetContentUpdater): void;
|
|
51
|
+
insertContent(content: JSONContent | string, opts?: {
|
|
52
|
+
at?: number;
|
|
53
|
+
}): void;
|
|
54
|
+
clearContent(): void;
|
|
55
|
+
getEditor(): Editor | null;
|
|
56
|
+
focus(keyboardFocus: boolean): void;
|
|
57
|
+
blur(): void;
|
|
58
|
+
hasFocus(): boolean;
|
|
59
|
+
getSelection(): {
|
|
60
|
+
from: number;
|
|
61
|
+
to: number;
|
|
62
|
+
};
|
|
63
|
+
setTextSelection(pos: number | {
|
|
64
|
+
from: number;
|
|
65
|
+
to: number;
|
|
66
|
+
}): void;
|
|
67
|
+
selectAll(): void;
|
|
68
|
+
setEditable(editable: boolean): void;
|
|
69
|
+
setPlaceholder(placeholder: string): void;
|
|
70
|
+
setAriaLabel(ariaLabel: string): void;
|
|
71
|
+
setTestId(testId: string): void;
|
|
72
|
+
setExtensions(_extensions: Extension[]): void;
|
|
73
|
+
setComposing(_composing: boolean): void;
|
|
74
|
+
undo(): boolean;
|
|
75
|
+
redo(): boolean;
|
|
76
|
+
private _onInput;
|
|
77
|
+
private _onKeydown;
|
|
78
|
+
private _onFocus;
|
|
79
|
+
private _onBlur;
|
|
80
|
+
/** Programmatic value write: updates the field, mirror, and emits change. */
|
|
81
|
+
private _setValue;
|
|
82
|
+
private _emitChange;
|
|
83
|
+
private _syncMirror;
|
|
84
|
+
private _markTyping;
|
|
85
|
+
private _clearTypingTimer;
|
|
86
|
+
private _dispatch;
|
|
87
|
+
}
|