@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.
Files changed (126) hide show
  1. package/custom-elements.json +736 -775
  2. package/es/components/audio-player/src/utils/url-detector.d.ts +0 -14
  3. package/es/components/audio-player/src/utils/url-detector.js +1 -19
  4. package/es/components/audio-player/src/utils/url-detector.js.map +1 -1
  5. package/es/components/card/src/card-footer.scss.js +1 -1
  6. package/es/components/card/src/card-steps.scss.js +1 -1
  7. package/es/components/card/src/card.scss.js +1 -1
  8. package/es/components/code-snippet/src/codemirror/codemirror-loader.d.ts +0 -5
  9. package/es/components/code-snippet/src/codemirror/codemirror-loader.js +1 -8
  10. package/es/components/code-snippet/src/codemirror/codemirror-loader.js.map +1 -1
  11. package/es/components/markdown/src/markdown-token-tree.js +1 -1
  12. package/es/components/markdown/src/plugins/markdown-it-attrs.d.ts +0 -1
  13. package/es/components/markdown/src/plugins/markdown-it-attrs.js +1 -1
  14. package/es/components/markdown/src/plugins/markdown-it-attrs.js.map +1 -1
  15. package/es/components/markdown/src/utils/plugin-fallback.js +3 -1
  16. package/es/components/markdown/src/utils/plugin-fallback.js.map +1 -1
  17. package/es/components/markdown/src/utils/table-helpers.d.ts +0 -26
  18. package/es/components/markdown/src/utils/table-helpers.js +1 -4
  19. package/es/components/markdown/src/utils/table-helpers.js.map +1 -1
  20. package/es/components/prompt-line/autocomplete/src/autocomplete.scss.js +1 -1
  21. package/es/components/prompt-line/src/prompt-line-constants.d.ts +9 -1
  22. package/es/components/prompt-line/src/prompt-line-constants.js +10 -2
  23. package/es/components/prompt-line/src/prompt-line-constants.js.map +1 -1
  24. package/es/components/prompt-line/src/prompt-line-controller.d.ts +25 -78
  25. package/es/components/prompt-line/src/prompt-line-controller.js +0 -389
  26. package/es/components/prompt-line/src/prompt-line-controller.js.map +1 -1
  27. package/es/components/prompt-line/src/prompt-line-mouse-focus.d.ts +45 -0
  28. package/es/components/prompt-line/src/prompt-line-mouse-focus.js +83 -0
  29. package/es/components/prompt-line/src/prompt-line-mouse-focus.js.map +1 -0
  30. package/es/components/prompt-line/src/prompt-line-rich-runtime.d.ts +0 -2
  31. package/es/components/prompt-line/src/prompt-line-rich-runtime.js +30 -53
  32. package/es/components/prompt-line/src/prompt-line-rich-runtime.js.map +1 -1
  33. package/es/components/prompt-line/src/prompt-line-textarea-runtime.d.ts +87 -0
  34. package/es/components/prompt-line/src/prompt-line-textarea-runtime.js +390 -0
  35. package/es/components/prompt-line/src/prompt-line-textarea-runtime.js.map +1 -0
  36. package/es/components/prompt-line/src/prompt-line.d.ts +1 -1
  37. package/es/components/prompt-line/src/prompt-line.js +6 -5
  38. package/es/components/prompt-line/src/prompt-line.js.map +1 -1
  39. package/es/components/prompt-line/src/tiptap/extension-equivalence.d.ts +2 -1
  40. package/es/components/prompt-line/src/tiptap/extension-equivalence.js.map +1 -1
  41. package/es/components/prompt-line/src/tiptap/typing-indicator.js +1 -1
  42. package/es/components/prompt-line/src/tiptap/typing-indicator.js.map +1 -1
  43. package/es/components/truncated-text/src/truncated-text.js +2 -2
  44. package/es/components/truncated-text/src/truncated-text.js.map +1 -1
  45. package/es/components/video-player/src/utils/url-detector.d.ts +0 -28
  46. package/es/components/video-player/src/utils/url-detector.js +1 -37
  47. package/es/components/video-player/src/utils/url-detector.js.map +1 -1
  48. package/es/globals/utils/browser-utils.d.ts +3 -5
  49. package/es/globals/utils/browser-utils.js +1 -1
  50. package/es/globals/utils/browser-utils.js.map +1 -1
  51. package/es/globals/utils/csv.d.ts +0 -1
  52. package/es/globals/utils/csv.js.map +1 -1
  53. package/es/react/truncated-text.d.ts +12 -0
  54. package/es/react/truncated-text.js +28 -0
  55. package/es/react/truncated-text.js.map +1 -0
  56. package/es/testing/PageObjectId.d.ts +0 -4
  57. package/es/testing/PageObjectId.js.map +1 -1
  58. package/es/testing/load-all-lazy-deps.d.ts +1 -2
  59. package/es/testing/load-all-lazy-deps.js +3 -3
  60. package/es/testing/load-all-lazy-deps.js.map +1 -1
  61. package/es-custom/components/audio-player/src/utils/url-detector.d.ts +0 -14
  62. package/es-custom/components/audio-player/src/utils/url-detector.js +1 -19
  63. package/es-custom/components/audio-player/src/utils/url-detector.js.map +1 -1
  64. package/es-custom/components/card/src/card-footer.scss.js +1 -1
  65. package/es-custom/components/card/src/card-steps.scss.js +1 -1
  66. package/es-custom/components/card/src/card.scss.js +1 -1
  67. package/es-custom/components/code-snippet/src/codemirror/codemirror-loader.d.ts +0 -5
  68. package/es-custom/components/code-snippet/src/codemirror/codemirror-loader.js +1 -8
  69. package/es-custom/components/code-snippet/src/codemirror/codemirror-loader.js.map +1 -1
  70. package/es-custom/components/markdown/src/markdown-token-tree.js +1 -1
  71. package/es-custom/components/markdown/src/plugins/markdown-it-attrs.d.ts +0 -1
  72. package/es-custom/components/markdown/src/plugins/markdown-it-attrs.js +1 -1
  73. package/es-custom/components/markdown/src/plugins/markdown-it-attrs.js.map +1 -1
  74. package/es-custom/components/markdown/src/utils/plugin-fallback.js +3 -1
  75. package/es-custom/components/markdown/src/utils/plugin-fallback.js.map +1 -1
  76. package/es-custom/components/markdown/src/utils/table-helpers.d.ts +0 -26
  77. package/es-custom/components/markdown/src/utils/table-helpers.js +1 -4
  78. package/es-custom/components/markdown/src/utils/table-helpers.js.map +1 -1
  79. package/es-custom/components/prompt-line/autocomplete/src/autocomplete.scss.js +1 -1
  80. package/es-custom/components/prompt-line/src/prompt-line-constants.d.ts +9 -1
  81. package/es-custom/components/prompt-line/src/prompt-line-constants.js +10 -2
  82. package/es-custom/components/prompt-line/src/prompt-line-constants.js.map +1 -1
  83. package/es-custom/components/prompt-line/src/prompt-line-controller.d.ts +25 -78
  84. package/es-custom/components/prompt-line/src/prompt-line-controller.js +0 -389
  85. package/es-custom/components/prompt-line/src/prompt-line-controller.js.map +1 -1
  86. package/es-custom/components/prompt-line/src/prompt-line-mouse-focus.d.ts +45 -0
  87. package/es-custom/components/prompt-line/src/prompt-line-mouse-focus.js +83 -0
  88. package/es-custom/components/prompt-line/src/prompt-line-mouse-focus.js.map +1 -0
  89. package/es-custom/components/prompt-line/src/prompt-line-rich-runtime.d.ts +0 -2
  90. package/es-custom/components/prompt-line/src/prompt-line-rich-runtime.js +30 -53
  91. package/es-custom/components/prompt-line/src/prompt-line-rich-runtime.js.map +1 -1
  92. package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.d.ts +87 -0
  93. package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.js +390 -0
  94. package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.js.map +1 -0
  95. package/es-custom/components/prompt-line/src/prompt-line.d.ts +1 -1
  96. package/es-custom/components/prompt-line/src/prompt-line.js +6 -5
  97. package/es-custom/components/prompt-line/src/prompt-line.js.map +1 -1
  98. package/es-custom/components/prompt-line/src/tiptap/extension-equivalence.d.ts +2 -1
  99. package/es-custom/components/prompt-line/src/tiptap/extension-equivalence.js.map +1 -1
  100. package/es-custom/components/prompt-line/src/tiptap/typing-indicator.js +1 -1
  101. package/es-custom/components/prompt-line/src/tiptap/typing-indicator.js.map +1 -1
  102. package/es-custom/components/truncated-text/src/truncated-text.js +2 -2
  103. package/es-custom/components/truncated-text/src/truncated-text.js.map +1 -1
  104. package/es-custom/components/video-player/src/utils/url-detector.d.ts +0 -28
  105. package/es-custom/components/video-player/src/utils/url-detector.js +1 -37
  106. package/es-custom/components/video-player/src/utils/url-detector.js.map +1 -1
  107. package/es-custom/globals/utils/browser-utils.d.ts +3 -5
  108. package/es-custom/globals/utils/browser-utils.js +1 -1
  109. package/es-custom/globals/utils/browser-utils.js.map +1 -1
  110. package/es-custom/globals/utils/csv.d.ts +0 -1
  111. package/es-custom/globals/utils/csv.js.map +1 -1
  112. package/es-custom/react/truncated-text.d.ts +12 -0
  113. package/es-custom/react/truncated-text.js +28 -0
  114. package/es-custom/react/truncated-text.js.map +1 -0
  115. package/es-custom/testing/PageObjectId.d.ts +0 -4
  116. package/es-custom/testing/PageObjectId.js.map +1 -1
  117. package/es-custom/testing/load-all-lazy-deps.d.ts +1 -2
  118. package/es-custom/testing/load-all-lazy-deps.js +3 -3
  119. package/es-custom/testing/load-all-lazy-deps.js.map +1 -1
  120. package/package.json +3 -4
  121. package/es/components/markdown/src/markdown.template.d.ts +0 -6
  122. package/es/components/markdown/src/markdown.template.js +0 -29
  123. package/es/components/markdown/src/markdown.template.js.map +0 -1
  124. package/es-custom/components/markdown/src/markdown.template.d.ts +0 -6
  125. package/es-custom/components/markdown/src/markdown.template.js +0 -29
  126. package/es-custom/components/markdown/src/markdown.template.js.map +0 -1
@@ -0,0 +1,390 @@
1
+ /**
2
+ * Copyright IBM Corp. 2025
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import { IS_PHONE } from '../../../globals/utils/browser-utils.js';
9
+ import { adoptOnRoot, setVarsForSelector } from '../../shared/dynamic-css-var-sheet.js';
10
+ import { TYPING_TIMEOUT_MS, PROMPT_LINE_MAX_BLOCK_SIZE } from './prompt-line-constants.js';
11
+ import { MouseFocusController } from './prompt-line-mouse-focus.js';
12
+ import { textToDoc, getRawText } from './tiptap/json-utils.js';
13
+
14
+ /**
15
+ * @license
16
+ *
17
+ * Copyright IBM Corp. 2026
18
+ *
19
+ * This source code is licensed under the Apache-2.0 license found in the
20
+ * LICENSE file in the root directory of this source tree.
21
+ */
22
+ // ---------------------------------------------------------------------------
23
+ // Textarea styling (CSP-safe — installed on the shared dynamic stylesheet,
24
+ // governed by `style-src` not `style-src-attr`, matching ./tiptap/editor-styles).
25
+ // ---------------------------------------------------------------------------
26
+ const TA_GROW_CLASS = 'cds-custom-aichat--input-textarea-grow';
27
+ const TA_FIELD_CLASS = 'cds-custom-aichat--input-textarea';
28
+ const TA_MIRROR_CLASS = 'cds-custom-aichat--input-textarea-mirror';
29
+ const TA_PHONE_CLASS = 'cds-custom-aichat--input-textarea--phone';
30
+ let textareaRulesInstalled = false;
31
+ // Typography intentionally mirrors `.cds-custom-aichat--input-pm-content` in
32
+ // ./tiptap/editor-styles.ts so the textarea and the Tiptap editor are pixel-
33
+ // identical and the textarea→editor swap is imperceptible.
34
+ function ensureTextareaStyleRules() {
35
+ if (textareaRulesInstalled) {
36
+ return;
37
+ }
38
+ // Auto-grow wrapper: textarea and mirror occupy the same grid cell; the
39
+ // (content-bearing) mirror dictates the height, the textarea stretches to
40
+ // fill it. No per-keystroke inline `style.height` (CSP-safe auto-grow).
41
+ // Cap the box at the shared max and clip the (unbounded) mirror past it; the
42
+ // field below scrolls within that cap.
43
+ setVarsForSelector(`.${TA_GROW_CLASS}`, {
44
+ display: 'grid',
45
+ 'inline-size': '100%',
46
+ 'max-block-size': PROMPT_LINE_MAX_BLOCK_SIZE,
47
+ overflow: 'hidden',
48
+ });
49
+ setVarsForSelector(`.${TA_GROW_CLASS} > *`, {
50
+ 'grid-area': '1 / 1 / 2 / 2',
51
+ });
52
+ // Shared typography + reset for both the field and the mirror.
53
+ const shared = {
54
+ margin: '0',
55
+ padding: '0',
56
+ border: 'none',
57
+ 'white-space': 'pre-wrap',
58
+ 'overflow-wrap': 'anywhere',
59
+ 'font-family': 'inherit',
60
+ 'font-size': 'var(--cds-body-01-font-size, 0.875rem)',
61
+ 'font-weight': 'var(--cds-body-01-font-weight, 400)',
62
+ 'letter-spacing': 'var(--cds-body-01-letter-spacing, 0.16px)',
63
+ 'line-height': 'var(--cds-body-01-line-height, 1.42857)',
64
+ };
65
+ setVarsForSelector(`.${TA_FIELD_CLASS}`, {
66
+ ...shared,
67
+ appearance: 'none',
68
+ background: 'transparent',
69
+ color: 'var(--cds-text-primary, #161616)',
70
+ outline: 'none',
71
+ resize: 'none',
72
+ // The field is its own scroll container past the cap so the browser keeps
73
+ // the caret in view natively (an ancestor scroller would not track it).
74
+ 'overflow-x': 'hidden',
75
+ 'overflow-y': 'auto',
76
+ 'inline-size': '100%',
77
+ 'min-block-size': '0',
78
+ 'max-block-size': PROMPT_LINE_MAX_BLOCK_SIZE,
79
+ });
80
+ setVarsForSelector(`.${TA_FIELD_CLASS}::placeholder`, {
81
+ color: 'var(--cds-text-secondary, #525252)',
82
+ opacity: '1',
83
+ });
84
+ setVarsForSelector(`.${TA_MIRROR_CLASS}`, {
85
+ ...shared,
86
+ visibility: 'hidden',
87
+ 'pointer-events': 'none',
88
+ });
89
+ setVarsForSelector(`.${TA_PHONE_CLASS}`, {
90
+ 'font-size': 'var(--cds-body-02-font-size, 1rem)',
91
+ 'font-weight': 'var(--cds-body-02-font-weight, 400)',
92
+ 'letter-spacing': 'var(--cds-body-02-letter-spacing, 0)',
93
+ 'line-height': 'var(--cds-body-02-line-height, 1.5)',
94
+ });
95
+ textareaRulesInstalled = true;
96
+ }
97
+ /**
98
+ * `<textarea>`-backed controller. Tiptap-free; emits the same prompt events as
99
+ * the rich editor. Auto-grows via a hidden mirror, capped at
100
+ * `PROMPT_LINE_MAX_BLOCK_SIZE` with the field scrolling past it — the same cap
101
+ * the rich contenteditable applies (see ./tiptap/editor-styles.ts), so the
102
+ * textarea→rich swap is imperceptible.
103
+ */
104
+ class TextareaController extends MouseFocusController {
105
+ constructor() {
106
+ super(...arguments);
107
+ this._wrap = null;
108
+ this._textarea = null;
109
+ this._mirror = null;
110
+ this._host = null;
111
+ this._isTyping = false;
112
+ this._typingTimer = null;
113
+ // -------------------------------------------------------------------------
114
+ // Internals
115
+ // -------------------------------------------------------------------------
116
+ this._onInput = () => {
117
+ this._syncMirror();
118
+ this._markTyping();
119
+ this._emitChange();
120
+ };
121
+ // Enter-to-send mirrors the rich editor's base bundle (`Keymap` +
122
+ // `carbonChatEnter`): plain Enter sends when non-empty, Mod-Enter sends,
123
+ // Shift-Enter inserts a newline, and Enter on an empty field falls through to
124
+ // the native newline (matching `carbonChatEnter`'s empty guard).
125
+ this._onKeydown = (event) => {
126
+ this._dispatch('cds-custom-aichat-prompt-keydown', { originalEvent: event });
127
+ // While an IME composition is active, Enter commits the candidate — let the
128
+ // IME own it. ProseMirror suppresses its keymap the same way, so the rich
129
+ // editor and the textarea agree. Without this, confirming a CJK candidate
130
+ // would send the half-composed text.
131
+ if (event.isComposing) {
132
+ return;
133
+ }
134
+ if (event.key === 'Enter' && !event.shiftKey) {
135
+ const isModEnter = event.metaKey || event.ctrlKey;
136
+ if (isModEnter || this.getValue() !== '') {
137
+ event.preventDefault();
138
+ this._dispatch('cds-custom-aichat-prompt-send-intent');
139
+ }
140
+ return;
141
+ }
142
+ if (event.key === 'Escape') {
143
+ event.preventDefault();
144
+ this._textarea?.blur();
145
+ }
146
+ };
147
+ this._onFocus = () => {
148
+ const wasMouseFocus = this._consumeMouseFocus();
149
+ this._dispatch('cds-custom-aichat-prompt-focus', { keyboard: !wasMouseFocus });
150
+ };
151
+ this._onBlur = () => {
152
+ this._dispatch('cds-custom-aichat-prompt-blur');
153
+ };
154
+ }
155
+ mount(host, init) {
156
+ ensureTextareaStyleRules();
157
+ const root = host.getRootNode();
158
+ if (root instanceof ShadowRoot || root instanceof Document) {
159
+ adoptOnRoot(root);
160
+ }
161
+ const wrap = document.createElement('div');
162
+ wrap.className = TA_GROW_CLASS;
163
+ const textarea = document.createElement('textarea');
164
+ textarea.className = TA_FIELD_CLASS;
165
+ textarea.classList.toggle(TA_PHONE_CLASS, IS_PHONE);
166
+ textarea.setAttribute('rows', '1');
167
+ textarea.setAttribute('name', 'message');
168
+ textarea.setAttribute('spellcheck', 'true');
169
+ textarea.setAttribute('tabindex', '0');
170
+ textarea.placeholder = init.placeholder;
171
+ textarea.value = init.value;
172
+ textarea.readOnly = init.disabled;
173
+ if (init.ariaLabel) {
174
+ textarea.setAttribute('aria-label', init.ariaLabel);
175
+ }
176
+ if (init.testId) {
177
+ textarea.setAttribute('data-testid', init.testId);
178
+ }
179
+ const mirror = document.createElement('div');
180
+ mirror.className = TA_MIRROR_CLASS;
181
+ mirror.classList.toggle(TA_PHONE_CLASS, IS_PHONE);
182
+ mirror.setAttribute('aria-hidden', 'true');
183
+ wrap.appendChild(textarea);
184
+ wrap.appendChild(mirror);
185
+ host.appendChild(wrap);
186
+ this._wrap = wrap;
187
+ this._textarea = textarea;
188
+ this._mirror = mirror;
189
+ this._host = host;
190
+ textarea.addEventListener('input', this._onInput);
191
+ textarea.addEventListener('keydown', this._onKeydown);
192
+ textarea.addEventListener('focus', this._onFocus);
193
+ textarea.addEventListener('blur', this._onBlur);
194
+ // Pointer/touch before focus marks the next focus as mouse-driven so we
195
+ // suppress the keyboard-focus outline.
196
+ this._attachMouseFocusListeners(host);
197
+ this._syncMirror();
198
+ }
199
+ destroy() {
200
+ this._clearTypingTimer();
201
+ const ta = this._textarea;
202
+ if (ta) {
203
+ ta.removeEventListener('input', this._onInput);
204
+ ta.removeEventListener('keydown', this._onKeydown);
205
+ ta.removeEventListener('focus', this._onFocus);
206
+ ta.removeEventListener('blur', this._onBlur);
207
+ }
208
+ const host = this._host;
209
+ if (host) {
210
+ this._detachMouseFocusListeners(host);
211
+ }
212
+ this._wrap?.remove();
213
+ this._wrap = null;
214
+ this._textarea = null;
215
+ this._mirror = null;
216
+ }
217
+ getValue() {
218
+ return this._textarea?.value ?? '';
219
+ }
220
+ setContent(next) {
221
+ if (typeof next === 'function') {
222
+ const prev = textToDoc(this.getValue());
223
+ this._setValue(getRawText(next(prev)), true);
224
+ return;
225
+ }
226
+ this._setValue(typeof next === 'string' ? next : getRawText(next), true);
227
+ }
228
+ insertContent(content, opts = {}) {
229
+ const ta = this._textarea;
230
+ if (!ta) {
231
+ return;
232
+ }
233
+ const text = typeof content === 'string' ? content : getRawText(content);
234
+ const value = ta.value;
235
+ const at = typeof opts.at === 'number'
236
+ ? Math.max(0, Math.min(opts.at, value.length))
237
+ : (ta.selectionStart ?? value.length);
238
+ const end = typeof opts.at === 'number' ? at : (ta.selectionEnd ?? at);
239
+ const nextValue = value.slice(0, at) + text + value.slice(end);
240
+ const caret = at + text.length;
241
+ this._setValue(nextValue, true);
242
+ ta.setSelectionRange(caret, caret);
243
+ }
244
+ clearContent() {
245
+ this._setValue('', true);
246
+ }
247
+ getEditor() {
248
+ return null;
249
+ }
250
+ focus(keyboardFocus) {
251
+ this._setNextFocusOrigin(keyboardFocus);
252
+ this._textarea?.focus();
253
+ }
254
+ blur() {
255
+ this._textarea?.blur();
256
+ }
257
+ hasFocus() {
258
+ const ta = this._textarea;
259
+ if (!ta) {
260
+ return false;
261
+ }
262
+ const root = ta.getRootNode();
263
+ return root.activeElement === ta;
264
+ }
265
+ getSelection() {
266
+ const ta = this._textarea;
267
+ if (!ta) {
268
+ return { from: 0, to: 0 };
269
+ }
270
+ return { from: ta.selectionStart ?? 0, to: ta.selectionEnd ?? 0 };
271
+ }
272
+ setTextSelection(pos) {
273
+ const ta = this._textarea;
274
+ if (!ta) {
275
+ return;
276
+ }
277
+ const len = ta.value.length;
278
+ if (typeof pos === 'number') {
279
+ const p = Math.max(0, Math.min(pos, len));
280
+ ta.setSelectionRange(p, p);
281
+ return;
282
+ }
283
+ ta.setSelectionRange(Math.max(0, Math.min(pos.from, len)), Math.max(0, Math.min(pos.to, len)));
284
+ }
285
+ selectAll() {
286
+ this._textarea?.select();
287
+ }
288
+ setEditable(editable) {
289
+ if (this._textarea) {
290
+ this._textarea.readOnly = !editable;
291
+ }
292
+ }
293
+ setPlaceholder(placeholder) {
294
+ if (this._textarea) {
295
+ this._textarea.placeholder = placeholder;
296
+ }
297
+ }
298
+ setAriaLabel(ariaLabel) {
299
+ const ta = this._textarea;
300
+ if (!ta) {
301
+ return;
302
+ }
303
+ if (ariaLabel) {
304
+ ta.setAttribute('aria-label', ariaLabel);
305
+ }
306
+ else {
307
+ ta.removeAttribute('aria-label');
308
+ }
309
+ }
310
+ setTestId(testId) {
311
+ const ta = this._textarea;
312
+ if (!ta) {
313
+ return;
314
+ }
315
+ if (testId) {
316
+ ta.setAttribute('data-testid', testId);
317
+ }
318
+ else {
319
+ ta.removeAttribute('data-testid');
320
+ }
321
+ }
322
+ setExtensions(_extensions) {
323
+ // Textarea mode has no Tiptap extensions; the shell upgrades to the rich
324
+ // controller when host extensions appear.
325
+ }
326
+ setComposing(_composing) {
327
+ // Nothing to withhold: a `<textarea>` survives its own recreate, and the
328
+ // element gates the upgrade on composition itself.
329
+ }
330
+ undo() {
331
+ return false;
332
+ }
333
+ redo() {
334
+ return false;
335
+ }
336
+ /** Programmatic value write: updates the field, mirror, and emits change. */
337
+ _setValue(text, emit) {
338
+ const ta = this._textarea;
339
+ if (!ta) {
340
+ return;
341
+ }
342
+ ta.value = text;
343
+ this._syncMirror();
344
+ if (emit) {
345
+ this._emitChange();
346
+ }
347
+ }
348
+ _emitChange() {
349
+ // Carry a plain-text doc as `content` so Redux / `getState().input.content`
350
+ // stays consistent with the rich editor (which emits `editor.getJSON()`).
351
+ const rawValue = this.getValue();
352
+ this._dispatch('cds-custom-aichat-prompt-change', {
353
+ rawValue,
354
+ content: textToDoc(rawValue),
355
+ });
356
+ }
357
+ _syncMirror() {
358
+ if (this._mirror && this._textarea) {
359
+ // Trailing newline so the box grows the instant a new line starts.
360
+ this._mirror.textContent = `${this._textarea.value}\n`;
361
+ }
362
+ }
363
+ _markTyping() {
364
+ if (!this._isTyping) {
365
+ this._isTyping = true;
366
+ this._dispatch('cds-custom-aichat-prompt-typing', { isTyping: true });
367
+ }
368
+ this._clearTypingTimer();
369
+ this._typingTimer = setTimeout(() => {
370
+ this._isTyping = false;
371
+ this._dispatch('cds-custom-aichat-prompt-typing', { isTyping: false });
372
+ }, TYPING_TIMEOUT_MS);
373
+ }
374
+ _clearTypingTimer() {
375
+ if (this._typingTimer != null) {
376
+ clearTimeout(this._typingTimer);
377
+ this._typingTimer = null;
378
+ }
379
+ }
380
+ _dispatch(name, detail) {
381
+ this._textarea?.dispatchEvent(new CustomEvent(name, {
382
+ detail,
383
+ bubbles: true,
384
+ composed: true,
385
+ }));
386
+ }
387
+ }
388
+
389
+ export { TextareaController };
390
+ //# sourceMappingURL=prompt-line-textarea-runtime.js.map
@@ -0,0 +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,GAA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AW,CAAC,IAAI,EAAE;YACpB,MAAM;AACN,YAAA,OAAO,EAAE,IAAI;AACb,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA,CAAC,CACH;IACH;AACD;;"}
@@ -37,7 +37,7 @@
37
37
  */
38
38
  import type { Editor, Extension, JSONContent } from '@tiptap/core';
39
39
  import { LitElement } from 'lit';
40
- import { type SetContentUpdater } from './prompt-line-controller.js';
40
+ import type { SetContentUpdater } from './prompt-line-controller.js';
41
41
  declare class PromptLineElement extends LitElement {
42
42
  static styles: import("lit").CSSResult;
43
43
  /**
@@ -11,7 +11,7 @@ import { property } from 'lit/decorators.js';
11
11
  import { carbonElement } from '../../../globals/decorators/carbon-element.js';
12
12
  import prefix from '../../../globals/settings.js';
13
13
  import { adoptOnRoot } from '../../shared/dynamic-css-var-sheet.js';
14
- import { TextareaController } from './prompt-line-controller.js';
14
+ import { TextareaController } from './prompt-line-textarea-runtime.js';
15
15
  import { getRichRuntimeIfLoaded, loadRichRuntime } from './prompt-line-rich-loader.js';
16
16
  import { getRawText, textOffsetToDocPos } from './tiptap/json-utils.js';
17
17
  import styles from './prompt-line.scss.js';
@@ -55,7 +55,7 @@ let PromptLineElement = class PromptLineElement extends LitElement {
55
55
  /** Placeholder text shown when the surface is empty. */
56
56
  this.placeholder = '';
57
57
  /** Accessible label for the editing surface. */
58
- this.ariaLabel = '';
58
+ this.ariaLabel = 'Message';
59
59
  /** Test id, applied to the inner editable element. */
60
60
  this.testId = '';
61
61
  /** Focus the surface on mount. */
@@ -233,7 +233,7 @@ let PromptLineElement = class PromptLineElement extends LitElement {
233
233
  }
234
234
  if (this.autofocus) {
235
235
  // Defer so consumer listeners are attached first.
236
- Promise.resolve().then(() => this._controller?.focus());
236
+ Promise.resolve().then(() => this._controller?.focus(false));
237
237
  }
238
238
  }
239
239
  render() {
@@ -287,7 +287,7 @@ let PromptLineElement = class PromptLineElement extends LitElement {
287
287
  return this._controller?.getValue() ?? '';
288
288
  }
289
289
  focus() {
290
- this._controller?.focus();
290
+ this._controller?.focus(false);
291
291
  }
292
292
  blur() {
293
293
  this._controller?.blur();
@@ -430,6 +430,7 @@ let PromptLineElement = class PromptLineElement extends LitElement {
430
430
  const value = previous.getValue();
431
431
  const selection = previous.getSelection();
432
432
  const hadFocus = previous.hasFocus();
433
+ const hadKeyboardFocus = previous.getKeyboardFocus();
433
434
  previous.destroy();
434
435
  this._controller = rich;
435
436
  this._mode = 'rich';
@@ -443,7 +444,7 @@ let PromptLineElement = class PromptLineElement extends LitElement {
443
444
  to: textOffsetToDocPos(value, selection.to),
444
445
  });
445
446
  if (hadFocus) {
446
- rich.focus();
447
+ rich.focus(hadKeyboardFocus);
447
448
  }
448
449
  this._settleRichReady();
449
450
  }