@carbon/ai-chat-components 1.10.0 → 1.11.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/custom-elements.json +2063 -2102
- 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
|
@@ -5,393 +5,4 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { IS_PHONE } from '../../../globals/utils/browser-utils.js';
|
|
9
|
-
import { adoptOnRoot, setVarsForSelector } from '../../shared/dynamic-css-var-sheet.js';
|
|
10
|
-
import { PROMPT_LINE_MAX_BLOCK_SIZE } from './prompt-line-constants.js';
|
|
11
|
-
import { textToDoc, getRawText } from './tiptap/json-utils.js';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @license
|
|
15
|
-
*
|
|
16
|
-
* Copyright IBM Corp. 2026
|
|
17
|
-
*
|
|
18
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
19
|
-
* LICENSE file in the root directory of this source tree.
|
|
20
|
-
*/
|
|
21
|
-
// ---------------------------------------------------------------------------
|
|
22
|
-
// Textarea styling (CSP-safe — installed on the shared dynamic stylesheet,
|
|
23
|
-
// governed by `style-src` not `style-src-attr`, matching ./tiptap/editor-styles).
|
|
24
|
-
// ---------------------------------------------------------------------------
|
|
25
|
-
const TA_GROW_CLASS = 'cds-aichat--input-textarea-grow';
|
|
26
|
-
const TA_FIELD_CLASS = 'cds-aichat--input-textarea';
|
|
27
|
-
const TA_MIRROR_CLASS = 'cds-aichat--input-textarea-mirror';
|
|
28
|
-
const TA_PHONE_CLASS = 'cds-aichat--input-textarea--phone';
|
|
29
|
-
let textareaRulesInstalled = false;
|
|
30
|
-
// Typography intentionally mirrors `.cds-aichat--input-pm-content` in
|
|
31
|
-
// ./tiptap/editor-styles.ts so the textarea and the Tiptap editor are pixel-
|
|
32
|
-
// identical and the textarea→editor swap is imperceptible.
|
|
33
|
-
function ensureTextareaStyleRules() {
|
|
34
|
-
if (textareaRulesInstalled) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
// Auto-grow wrapper: textarea and mirror occupy the same grid cell; the
|
|
38
|
-
// (content-bearing) mirror dictates the height, the textarea stretches to
|
|
39
|
-
// fill it. No per-keystroke inline `style.height` (CSP-safe auto-grow).
|
|
40
|
-
// Cap the box at the shared max and clip the (unbounded) mirror past it; the
|
|
41
|
-
// field below scrolls within that cap.
|
|
42
|
-
setVarsForSelector(`.${TA_GROW_CLASS}`, {
|
|
43
|
-
display: 'grid',
|
|
44
|
-
'inline-size': '100%',
|
|
45
|
-
'max-block-size': PROMPT_LINE_MAX_BLOCK_SIZE,
|
|
46
|
-
overflow: 'hidden',
|
|
47
|
-
});
|
|
48
|
-
setVarsForSelector(`.${TA_GROW_CLASS} > *`, {
|
|
49
|
-
'grid-area': '1 / 1 / 2 / 2',
|
|
50
|
-
});
|
|
51
|
-
// Shared typography + reset for both the field and the mirror.
|
|
52
|
-
const shared = {
|
|
53
|
-
margin: '0',
|
|
54
|
-
padding: '0',
|
|
55
|
-
border: 'none',
|
|
56
|
-
'white-space': 'pre-wrap',
|
|
57
|
-
'overflow-wrap': 'anywhere',
|
|
58
|
-
'font-family': 'inherit',
|
|
59
|
-
'font-size': 'var(--cds-body-01-font-size, 0.875rem)',
|
|
60
|
-
'font-weight': 'var(--cds-body-01-font-weight, 400)',
|
|
61
|
-
'letter-spacing': 'var(--cds-body-01-letter-spacing, 0.16px)',
|
|
62
|
-
'line-height': 'var(--cds-body-01-line-height, 1.42857)',
|
|
63
|
-
};
|
|
64
|
-
setVarsForSelector(`.${TA_FIELD_CLASS}`, {
|
|
65
|
-
...shared,
|
|
66
|
-
appearance: 'none',
|
|
67
|
-
background: 'transparent',
|
|
68
|
-
color: 'var(--cds-text-primary, #161616)',
|
|
69
|
-
outline: 'none',
|
|
70
|
-
resize: 'none',
|
|
71
|
-
// The field is its own scroll container past the cap so the browser keeps
|
|
72
|
-
// the caret in view natively (an ancestor scroller would not track it).
|
|
73
|
-
'overflow-x': 'hidden',
|
|
74
|
-
'overflow-y': 'auto',
|
|
75
|
-
'inline-size': '100%',
|
|
76
|
-
'min-block-size': '0',
|
|
77
|
-
'max-block-size': PROMPT_LINE_MAX_BLOCK_SIZE,
|
|
78
|
-
});
|
|
79
|
-
setVarsForSelector(`.${TA_FIELD_CLASS}::placeholder`, {
|
|
80
|
-
color: 'var(--cds-text-secondary, #525252)',
|
|
81
|
-
opacity: '1',
|
|
82
|
-
});
|
|
83
|
-
setVarsForSelector(`.${TA_MIRROR_CLASS}`, {
|
|
84
|
-
...shared,
|
|
85
|
-
visibility: 'hidden',
|
|
86
|
-
'pointer-events': 'none',
|
|
87
|
-
});
|
|
88
|
-
setVarsForSelector(`.${TA_PHONE_CLASS}`, {
|
|
89
|
-
'font-size': 'var(--cds-body-02-font-size, 1rem)',
|
|
90
|
-
'font-weight': 'var(--cds-body-02-font-weight, 400)',
|
|
91
|
-
'letter-spacing': 'var(--cds-body-02-letter-spacing, 0)',
|
|
92
|
-
'line-height': 'var(--cds-body-02-line-height, 1.5)',
|
|
93
|
-
});
|
|
94
|
-
textareaRulesInstalled = true;
|
|
95
|
-
}
|
|
96
|
-
const TYPING_TIMEOUT_MS = 5000;
|
|
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 {
|
|
105
|
-
constructor() {
|
|
106
|
-
this._wrap = null;
|
|
107
|
-
this._textarea = null;
|
|
108
|
-
this._mirror = null;
|
|
109
|
-
this._host = null;
|
|
110
|
-
this._focusFromMouse = false;
|
|
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-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-aichat-prompt-send-intent');
|
|
139
|
-
}
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
if (event.key === 'Escape') {
|
|
143
|
-
event.preventDefault();
|
|
144
|
-
this._textarea?.blur();
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
this._setMouseFlag = () => {
|
|
148
|
-
this._focusFromMouse = true;
|
|
149
|
-
};
|
|
150
|
-
this._onFocus = () => {
|
|
151
|
-
const wasMouseFocus = this._focusFromMouse;
|
|
152
|
-
this._focusFromMouse = false;
|
|
153
|
-
this._dispatch('cds-aichat-prompt-focus', { keyboard: !wasMouseFocus });
|
|
154
|
-
};
|
|
155
|
-
this._onBlur = () => {
|
|
156
|
-
this._dispatch('cds-aichat-prompt-blur');
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
mount(host, init) {
|
|
160
|
-
ensureTextareaStyleRules();
|
|
161
|
-
const root = host.getRootNode();
|
|
162
|
-
if (root instanceof ShadowRoot || root instanceof Document) {
|
|
163
|
-
adoptOnRoot(root);
|
|
164
|
-
}
|
|
165
|
-
const wrap = document.createElement('div');
|
|
166
|
-
wrap.className = TA_GROW_CLASS;
|
|
167
|
-
const textarea = document.createElement('textarea');
|
|
168
|
-
textarea.className = TA_FIELD_CLASS;
|
|
169
|
-
textarea.classList.toggle(TA_PHONE_CLASS, IS_PHONE);
|
|
170
|
-
textarea.setAttribute('rows', '1');
|
|
171
|
-
textarea.setAttribute('spellcheck', 'true');
|
|
172
|
-
textarea.setAttribute('tabindex', '0');
|
|
173
|
-
textarea.placeholder = init.placeholder;
|
|
174
|
-
textarea.value = init.value;
|
|
175
|
-
textarea.readOnly = init.disabled;
|
|
176
|
-
if (init.ariaLabel) {
|
|
177
|
-
textarea.setAttribute('aria-label', init.ariaLabel);
|
|
178
|
-
}
|
|
179
|
-
if (init.testId) {
|
|
180
|
-
textarea.setAttribute('data-testid', init.testId);
|
|
181
|
-
}
|
|
182
|
-
const mirror = document.createElement('div');
|
|
183
|
-
mirror.className = TA_MIRROR_CLASS;
|
|
184
|
-
mirror.classList.toggle(TA_PHONE_CLASS, IS_PHONE);
|
|
185
|
-
mirror.setAttribute('aria-hidden', 'true');
|
|
186
|
-
wrap.appendChild(textarea);
|
|
187
|
-
wrap.appendChild(mirror);
|
|
188
|
-
host.appendChild(wrap);
|
|
189
|
-
this._wrap = wrap;
|
|
190
|
-
this._textarea = textarea;
|
|
191
|
-
this._mirror = mirror;
|
|
192
|
-
this._host = host;
|
|
193
|
-
textarea.addEventListener('input', this._onInput);
|
|
194
|
-
textarea.addEventListener('keydown', this._onKeydown);
|
|
195
|
-
textarea.addEventListener('focus', this._onFocus);
|
|
196
|
-
textarea.addEventListener('blur', this._onBlur);
|
|
197
|
-
// Pointer/touch before focus marks the next focus as mouse-driven so we
|
|
198
|
-
// suppress the keyboard-focus outline.
|
|
199
|
-
host.addEventListener('pointerdown', this._setMouseFlag);
|
|
200
|
-
host.addEventListener('mousedown', this._setMouseFlag);
|
|
201
|
-
host.addEventListener('touchstart', this._setMouseFlag);
|
|
202
|
-
this._syncMirror();
|
|
203
|
-
}
|
|
204
|
-
destroy() {
|
|
205
|
-
this._clearTypingTimer();
|
|
206
|
-
const ta = this._textarea;
|
|
207
|
-
if (ta) {
|
|
208
|
-
ta.removeEventListener('input', this._onInput);
|
|
209
|
-
ta.removeEventListener('keydown', this._onKeydown);
|
|
210
|
-
ta.removeEventListener('focus', this._onFocus);
|
|
211
|
-
ta.removeEventListener('blur', this._onBlur);
|
|
212
|
-
}
|
|
213
|
-
const host = this._host;
|
|
214
|
-
if (host) {
|
|
215
|
-
host.removeEventListener('pointerdown', this._setMouseFlag);
|
|
216
|
-
host.removeEventListener('mousedown', this._setMouseFlag);
|
|
217
|
-
host.removeEventListener('touchstart', this._setMouseFlag);
|
|
218
|
-
}
|
|
219
|
-
this._wrap?.remove();
|
|
220
|
-
this._wrap = null;
|
|
221
|
-
this._textarea = null;
|
|
222
|
-
this._mirror = null;
|
|
223
|
-
}
|
|
224
|
-
getValue() {
|
|
225
|
-
return this._textarea?.value ?? '';
|
|
226
|
-
}
|
|
227
|
-
setContent(next) {
|
|
228
|
-
if (typeof next === 'function') {
|
|
229
|
-
const prev = textToDoc(this.getValue());
|
|
230
|
-
this._setValue(getRawText(next(prev)), true);
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
this._setValue(typeof next === 'string' ? next : getRawText(next), true);
|
|
234
|
-
}
|
|
235
|
-
insertContent(content, opts = {}) {
|
|
236
|
-
const ta = this._textarea;
|
|
237
|
-
if (!ta) {
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
const text = typeof content === 'string' ? content : getRawText(content);
|
|
241
|
-
const value = ta.value;
|
|
242
|
-
const at = typeof opts.at === 'number'
|
|
243
|
-
? Math.max(0, Math.min(opts.at, value.length))
|
|
244
|
-
: (ta.selectionStart ?? value.length);
|
|
245
|
-
const end = typeof opts.at === 'number' ? at : (ta.selectionEnd ?? at);
|
|
246
|
-
const nextValue = value.slice(0, at) + text + value.slice(end);
|
|
247
|
-
const caret = at + text.length;
|
|
248
|
-
this._setValue(nextValue, true);
|
|
249
|
-
ta.setSelectionRange(caret, caret);
|
|
250
|
-
}
|
|
251
|
-
clearContent() {
|
|
252
|
-
this._setValue('', true);
|
|
253
|
-
}
|
|
254
|
-
getEditor() {
|
|
255
|
-
return null;
|
|
256
|
-
}
|
|
257
|
-
focus() {
|
|
258
|
-
this._focusFromMouse = true;
|
|
259
|
-
this._textarea?.focus();
|
|
260
|
-
}
|
|
261
|
-
blur() {
|
|
262
|
-
this._textarea?.blur();
|
|
263
|
-
}
|
|
264
|
-
hasFocus() {
|
|
265
|
-
const ta = this._textarea;
|
|
266
|
-
if (!ta) {
|
|
267
|
-
return false;
|
|
268
|
-
}
|
|
269
|
-
const root = ta.getRootNode();
|
|
270
|
-
return root.activeElement === ta;
|
|
271
|
-
}
|
|
272
|
-
getSelection() {
|
|
273
|
-
const ta = this._textarea;
|
|
274
|
-
if (!ta) {
|
|
275
|
-
return { from: 0, to: 0 };
|
|
276
|
-
}
|
|
277
|
-
return { from: ta.selectionStart ?? 0, to: ta.selectionEnd ?? 0 };
|
|
278
|
-
}
|
|
279
|
-
setTextSelection(pos) {
|
|
280
|
-
const ta = this._textarea;
|
|
281
|
-
if (!ta) {
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
const len = ta.value.length;
|
|
285
|
-
if (typeof pos === 'number') {
|
|
286
|
-
const p = Math.max(0, Math.min(pos, len));
|
|
287
|
-
ta.setSelectionRange(p, p);
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
ta.setSelectionRange(Math.max(0, Math.min(pos.from, len)), Math.max(0, Math.min(pos.to, len)));
|
|
291
|
-
}
|
|
292
|
-
selectAll() {
|
|
293
|
-
this._textarea?.select();
|
|
294
|
-
}
|
|
295
|
-
setEditable(editable) {
|
|
296
|
-
if (this._textarea) {
|
|
297
|
-
this._textarea.readOnly = !editable;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
setPlaceholder(placeholder) {
|
|
301
|
-
if (this._textarea) {
|
|
302
|
-
this._textarea.placeholder = placeholder;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
setAriaLabel(ariaLabel) {
|
|
306
|
-
const ta = this._textarea;
|
|
307
|
-
if (!ta) {
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
if (ariaLabel) {
|
|
311
|
-
ta.setAttribute('aria-label', ariaLabel);
|
|
312
|
-
}
|
|
313
|
-
else {
|
|
314
|
-
ta.removeAttribute('aria-label');
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
setTestId(testId) {
|
|
318
|
-
const ta = this._textarea;
|
|
319
|
-
if (!ta) {
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
if (testId) {
|
|
323
|
-
ta.setAttribute('data-testid', testId);
|
|
324
|
-
}
|
|
325
|
-
else {
|
|
326
|
-
ta.removeAttribute('data-testid');
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
setExtensions(_extensions) {
|
|
330
|
-
// Textarea mode has no Tiptap extensions; the shell upgrades to the rich
|
|
331
|
-
// controller when host extensions appear.
|
|
332
|
-
}
|
|
333
|
-
setComposing(_composing) {
|
|
334
|
-
// Nothing to withhold: a `<textarea>` survives its own recreate, and the
|
|
335
|
-
// element gates the upgrade on composition itself.
|
|
336
|
-
}
|
|
337
|
-
undo() {
|
|
338
|
-
return false;
|
|
339
|
-
}
|
|
340
|
-
redo() {
|
|
341
|
-
return false;
|
|
342
|
-
}
|
|
343
|
-
/** Programmatic value write: updates the field, mirror, and emits change. */
|
|
344
|
-
_setValue(text, emit) {
|
|
345
|
-
const ta = this._textarea;
|
|
346
|
-
if (!ta) {
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
ta.value = text;
|
|
350
|
-
this._syncMirror();
|
|
351
|
-
if (emit) {
|
|
352
|
-
this._emitChange();
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
_emitChange() {
|
|
356
|
-
// Carry a plain-text doc as `content` so Redux / `getState().input.content`
|
|
357
|
-
// stays consistent with the rich editor (which emits `editor.getJSON()`).
|
|
358
|
-
const rawValue = this.getValue();
|
|
359
|
-
this._dispatch('cds-aichat-prompt-change', {
|
|
360
|
-
rawValue,
|
|
361
|
-
content: textToDoc(rawValue),
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
_syncMirror() {
|
|
365
|
-
if (this._mirror && this._textarea) {
|
|
366
|
-
// Trailing newline so the box grows the instant a new line starts.
|
|
367
|
-
this._mirror.textContent = `${this._textarea.value}\n`;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
_markTyping() {
|
|
371
|
-
if (!this._isTyping) {
|
|
372
|
-
this._isTyping = true;
|
|
373
|
-
this._dispatch('cds-aichat-prompt-typing', { isTyping: true });
|
|
374
|
-
}
|
|
375
|
-
this._clearTypingTimer();
|
|
376
|
-
this._typingTimer = setTimeout(() => {
|
|
377
|
-
this._isTyping = false;
|
|
378
|
-
this._dispatch('cds-aichat-prompt-typing', { isTyping: false });
|
|
379
|
-
}, TYPING_TIMEOUT_MS);
|
|
380
|
-
}
|
|
381
|
-
_clearTypingTimer() {
|
|
382
|
-
if (this._typingTimer != null) {
|
|
383
|
-
clearTimeout(this._typingTimer);
|
|
384
|
-
this._typingTimer = null;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
_dispatch(name, detail) {
|
|
388
|
-
this._textarea?.dispatchEvent(new CustomEvent(name, {
|
|
389
|
-
detail,
|
|
390
|
-
bubbles: true,
|
|
391
|
-
composed: true,
|
|
392
|
-
}));
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
export { TextareaController };
|
|
397
8
|
//# sourceMappingURL=prompt-line-controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-line-controller.js","sources":["../../../../src/components/prompt-line/src/prompt-line-controller.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 * Editing-surface controller abstraction for `<cds-aichat-prompt-line>`.\n *\n * The prompt-line shell ([./prompt-line.ts]) delegates all editing behavior to\n * a `PromptLineController`. Two implementations exist:\n *\n * - `TextareaController` (this file) — a Tiptap-free `<textarea>`. It is the\n * default and keeps the shell's static import graph free of `@tiptap/*`.\n * - The rich controller ([./prompt-line-rich-runtime.ts]) — a Tiptap `Editor`,\n * reached only through a dynamic `import()` so Tiptap lands in its own lazy\n * chunk.\n *\n * Both controllers emit the **same** `cds-aichat-prompt-*` events with the\n * same detail shapes, so the React wrapper and `@carbon/ai-chat`'s `Input`\n * handlers are identical regardless of mode. The shell can swap a\n * `TextareaController` for the rich controller in place (text, caret, and\n * focus transfer losslessly because the textarea holds plain text).\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 { PROMPT_LINE_MAX_BLOCK_SIZE } from './prompt-line-constants.js';\nimport { getRawText, textToDoc } from './tiptap/json-utils.js';\n\n/** Updater shape accepted by `setContent` for reduce-style edits. */\nexport type SetContentUpdater = (prev: JSONContent) => JSONContent;\n\n/** Initial state handed to a controller when it mounts into the host. */\nexport interface PromptLineControllerInit {\n /**\n * Plain-text seed value. Always the textarea's source of truth and the\n * lossless seed used when the rich editor mounts without richer `content`.\n */\n value: string;\n /**\n * Optional structured seed (a `content` prop carrying mentions / custom\n * nodes). Consumed by the rich controller; the textarea ignores it and\n * relies on `value`.\n */\n content?: JSONContent | string;\n placeholder: string;\n /** When `true`, the surface is non-editable (still focusable). */\n disabled: boolean;\n ariaLabel: string;\n testId: string;\n /**\n * Host-supplied Tiptap extensions. Consumed by the rich controller; ignored\n * by the textarea controller.\n */\n extensions?: Extension[];\n}\n\n/**\n * The surface the shell drives. Both the textarea and the rich editor satisfy\n * it, so the shell never branches on mode beyond construction.\n */\nexport interface PromptLineController {\n /** Mount the editing surface into the (already-slotted) light-DOM host. */\n mount(host: HTMLElement, init: PromptLineControllerInit): void;\n /** Tear down listeners / editor and remove the surface from the host. */\n destroy(): void;\n\n /** Current plain-text value (the lossless transfer + change payload). */\n getValue(): string;\n setContent(next: JSONContent | string | SetContentUpdater): void;\n insertContent(content: JSONContent | string, opts?: { at?: number }): void;\n clearContent(): void;\n\n /** Live Tiptap editor, or `null` in textarea mode. */\n getEditor(): Editor | null;\n\n focus(): void;\n blur(): void;\n hasFocus(): boolean;\n\n /** Selection as plain-text offsets (used for seamless transfer). */\n getSelection(): { from: number; to: number };\n setTextSelection(pos: number | { from: number; to: number }): void;\n selectAll(): void;\n\n setEditable(editable: boolean): void;\n setPlaceholder(placeholder: string): void;\n setAriaLabel(ariaLabel: string): void;\n setTestId(testId: string): void;\n /**\n * Apply a new extension list. Rich mode compares it by value against the set\n * last supplied: an equivalent set keeps the editor and its undo history,\n * writing any starter `items`/`isOn` through to live storage; a genuinely\n * different one recreates the editor preserving content/selection/focus,\n * deferred to the end of an IME composition. Textarea mode ignores it.\n */\n setExtensions(extensions: Extension[]): void;\n /**\n * Report whether an IME composition is in flight. The element owns the host's\n * composition listeners and pushes the state down, so there is one observer\n * and the two layers cannot disagree. Rich mode withholds an\n * extension-driven recreate for the duration — destroying the editor would\n * strand the IME's candidate — and flushes it once composition commits;\n * textarea mode ignores it.\n */\n setComposing(composing: boolean): void;\n\n undo(): boolean;\n redo(): boolean;\n}\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-aichat--input-textarea-grow';\nconst TA_FIELD_CLASS = 'cds-aichat--input-textarea';\nconst TA_MIRROR_CLASS = 'cds-aichat--input-textarea-mirror';\nconst TA_PHONE_CLASS = 'cds-aichat--input-textarea--phone';\n\nlet textareaRulesInstalled = false;\n\n// Typography intentionally mirrors `.cds-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\nconst TYPING_TIMEOUT_MS = 5000;\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 implements PromptLineController {\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 private _focusFromMouse = false;\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('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 host.addEventListener('pointerdown', this._setMouseFlag);\n host.addEventListener('mousedown', this._setMouseFlag);\n host.addEventListener('touchstart', this._setMouseFlag);\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 host.removeEventListener('pointerdown', this._setMouseFlag);\n host.removeEventListener('mousedown', this._setMouseFlag);\n host.removeEventListener('touchstart', this._setMouseFlag);\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(): void {\n this._focusFromMouse = true;\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-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-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 _setMouseFlag = (): void => {\n this._focusFromMouse = true;\n };\n\n private _onFocus = (): void => {\n const wasMouseFocus = this._focusFromMouse;\n this._focusFromMouse = false;\n this._dispatch('cds-aichat-prompt-focus', { keyboard: !wasMouseFocus });\n };\n\n private _onBlur = (): void => {\n this._dispatch('cds-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-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-aichat-prompt-typing', { isTyping: true });\n }\n this._clearTypingTimer();\n this._typingTimer = setTimeout(() => {\n this._isTyping = false;\n this._dispatch('cds-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;AAoHH;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;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IAAI,CAAC,SAAS,GAAG,IAAI;YACrB,IAAI,CAAC,SAAS,CAAC,0BAA0B,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;QAChE;QACA,IAAI,CAAC,iBAAiB,EAAE;AACxB,QAAA,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,MAAK;AAClC,YAAA,IAAI,CAAC,SAAS,GAAG,KAAK;YACtB,IAAI,CAAC,SAAS,CAAC,0BAA0B,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;QACjE,CAAC,EAAE,iBAAiB,CAAC;IACvB;IAEQ,iBAAiB,GAAA;AACvB,QAAA,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,EAAE;AAC7B,YAAA,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC;AAC/B,YAAA,IAAI,CAAC,YAAY,GAAG,IAAI;QAC1B;IACF;IAEQ,SAAS,CAAC,IAAY,EAAE,MAAgB,EAAA;QAC9C,IAAI,CAAC,SAAS,EAAE,aAAa,CAC3B,IAAI,WAAW,CAAC,IAAI,EAAE;YACpB,MAAM;AACN,YAAA,OAAO,EAAE,IAAI;AACb,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA,CAAC,CACH;IACH;AACD;;"}
|
|
1
|
+
{"version":3,"file":"prompt-line-controller.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
* Shared mouse-focus tracking used by both `TextareaController` and
|
|
11
|
+
* `RichController`. Pointer/touch events before focus mark it as mouse-driven
|
|
12
|
+
* so the keyboard-focus outline is suppressed.
|
|
13
|
+
*
|
|
14
|
+
* Subclasses should:
|
|
15
|
+
* - call `this._attachMouseFocusListeners(host)` in `mount()`
|
|
16
|
+
* - call `this._detachMouseFocusListeners(host)` in `destroy()`
|
|
17
|
+
* - call `this._consumeMouseFocus()` when the focus event fires to get the
|
|
18
|
+
* `wasMouseFocus` boolean and latch it into `_lastFocusFromMouse`
|
|
19
|
+
* - call `this._setNextFocusOrigin(keyboardFocus)` in `focus(keyboardFocus)` before delegating
|
|
20
|
+
*/
|
|
21
|
+
export declare abstract class MouseFocusController {
|
|
22
|
+
protected _focusFromMouse: boolean;
|
|
23
|
+
protected _lastFocusFromMouse: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Set by `focus(keyboardFocus)` to pin the keyboard value for the next focus
|
|
26
|
+
* event, bypassing pointer-event tracking. Takes priority over
|
|
27
|
+
* `_focusFromMouse` so a programmatic focus call cannot be clobbered by a
|
|
28
|
+
* synthetic pointer event fired during the same `.focus()` call (observed in
|
|
29
|
+
* Chromium/Firefox headless).
|
|
30
|
+
*/
|
|
31
|
+
private _nextFocusOriginKeyboard;
|
|
32
|
+
protected readonly _setMouseFlag: () => void;
|
|
33
|
+
/** Pins the keyboard value for the next focus event. Call this in
|
|
34
|
+
* `focus(keyboardFocus)` before delegating to the native `.focus()`. */
|
|
35
|
+
protected _setNextFocusOrigin(keyboard: boolean): void;
|
|
36
|
+
/**
|
|
37
|
+
* Called at the start of the focus event. Consumes `_focusFromMouse` (or the
|
|
38
|
+
* pinned origin set by `_setNextFocusOrigin()`), latches the result into
|
|
39
|
+
* `_lastFocusFromMouse`, and returns whether focus was mouse-driven.
|
|
40
|
+
*/
|
|
41
|
+
protected _consumeMouseFocus(): boolean;
|
|
42
|
+
getKeyboardFocus(): boolean;
|
|
43
|
+
protected _attachMouseFocusListeners(host: HTMLElement): void;
|
|
44
|
+
protected _detachMouseFocusListeners(host: HTMLElement): void;
|
|
45
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
/**
|
|
9
|
+
* @license
|
|
10
|
+
*
|
|
11
|
+
* Copyright IBM Corp. 2026
|
|
12
|
+
*
|
|
13
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
14
|
+
* LICENSE file in the root directory of this source tree.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Shared mouse-focus tracking used by both `TextareaController` and
|
|
18
|
+
* `RichController`. Pointer/touch events before focus mark it as mouse-driven
|
|
19
|
+
* so the keyboard-focus outline is suppressed.
|
|
20
|
+
*
|
|
21
|
+
* Subclasses should:
|
|
22
|
+
* - call `this._attachMouseFocusListeners(host)` in `mount()`
|
|
23
|
+
* - call `this._detachMouseFocusListeners(host)` in `destroy()`
|
|
24
|
+
* - call `this._consumeMouseFocus()` when the focus event fires to get the
|
|
25
|
+
* `wasMouseFocus` boolean and latch it into `_lastFocusFromMouse`
|
|
26
|
+
* - call `this._setNextFocusOrigin(keyboardFocus)` in `focus(keyboardFocus)` before delegating
|
|
27
|
+
*/
|
|
28
|
+
class MouseFocusController {
|
|
29
|
+
constructor() {
|
|
30
|
+
this._focusFromMouse = false;
|
|
31
|
+
this._lastFocusFromMouse = false;
|
|
32
|
+
/**
|
|
33
|
+
* Set by `focus(keyboardFocus)` to pin the keyboard value for the next focus
|
|
34
|
+
* event, bypassing pointer-event tracking. Takes priority over
|
|
35
|
+
* `_focusFromMouse` so a programmatic focus call cannot be clobbered by a
|
|
36
|
+
* synthetic pointer event fired during the same `.focus()` call (observed in
|
|
37
|
+
* Chromium/Firefox headless).
|
|
38
|
+
*/
|
|
39
|
+
this._nextFocusOriginKeyboard = null;
|
|
40
|
+
this._setMouseFlag = () => {
|
|
41
|
+
this._focusFromMouse = true;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** Pins the keyboard value for the next focus event. Call this in
|
|
45
|
+
* `focus(keyboardFocus)` before delegating to the native `.focus()`. */
|
|
46
|
+
_setNextFocusOrigin(keyboard) {
|
|
47
|
+
this._nextFocusOriginKeyboard = keyboard;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Called at the start of the focus event. Consumes `_focusFromMouse` (or the
|
|
51
|
+
* pinned origin set by `_setNextFocusOrigin()`), latches the result into
|
|
52
|
+
* `_lastFocusFromMouse`, and returns whether focus was mouse-driven.
|
|
53
|
+
*/
|
|
54
|
+
_consumeMouseFocus() {
|
|
55
|
+
let wasMouseFocus;
|
|
56
|
+
if (this._nextFocusOriginKeyboard !== null) {
|
|
57
|
+
wasMouseFocus = !this._nextFocusOriginKeyboard;
|
|
58
|
+
this._nextFocusOriginKeyboard = null;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
wasMouseFocus = this._focusFromMouse;
|
|
62
|
+
}
|
|
63
|
+
this._focusFromMouse = false;
|
|
64
|
+
this._lastFocusFromMouse = wasMouseFocus;
|
|
65
|
+
return wasMouseFocus;
|
|
66
|
+
}
|
|
67
|
+
getKeyboardFocus() {
|
|
68
|
+
return !this._lastFocusFromMouse;
|
|
69
|
+
}
|
|
70
|
+
_attachMouseFocusListeners(host) {
|
|
71
|
+
host.addEventListener('pointerdown', this._setMouseFlag);
|
|
72
|
+
host.addEventListener('mousedown', this._setMouseFlag);
|
|
73
|
+
host.addEventListener('touchstart', this._setMouseFlag);
|
|
74
|
+
}
|
|
75
|
+
_detachMouseFocusListeners(host) {
|
|
76
|
+
host.removeEventListener('pointerdown', this._setMouseFlag);
|
|
77
|
+
host.removeEventListener('mousedown', this._setMouseFlag);
|
|
78
|
+
host.removeEventListener('touchstart', this._setMouseFlag);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { MouseFocusController };
|
|
83
|
+
//# sourceMappingURL=prompt-line-mouse-focus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-line-mouse-focus.js","sources":["../../../../src/components/prompt-line/src/prompt-line-mouse-focus.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 * Shared mouse-focus tracking used by both `TextareaController` and\n * `RichController`. Pointer/touch events before focus mark it as mouse-driven\n * so the keyboard-focus outline is suppressed.\n *\n * Subclasses should:\n * - call `this._attachMouseFocusListeners(host)` in `mount()`\n * - call `this._detachMouseFocusListeners(host)` in `destroy()`\n * - call `this._consumeMouseFocus()` when the focus event fires to get the\n * `wasMouseFocus` boolean and latch it into `_lastFocusFromMouse`\n * - call `this._setNextFocusOrigin(keyboardFocus)` in `focus(keyboardFocus)` before delegating\n */\nexport abstract class MouseFocusController {\n protected _focusFromMouse = false;\n protected _lastFocusFromMouse = false;\n /**\n * Set by `focus(keyboardFocus)` to pin the keyboard value for the next focus\n * event, bypassing pointer-event tracking. Takes priority over\n * `_focusFromMouse` so a programmatic focus call cannot be clobbered by a\n * synthetic pointer event fired during the same `.focus()` call (observed in\n * Chromium/Firefox headless).\n */\n private _nextFocusOriginKeyboard: boolean | null = null;\n\n protected readonly _setMouseFlag = (): void => {\n this._focusFromMouse = true;\n };\n\n /** Pins the keyboard value for the next focus event. Call this in\n * `focus(keyboardFocus)` before delegating to the native `.focus()`. */\n protected _setNextFocusOrigin(keyboard: boolean): void {\n this._nextFocusOriginKeyboard = keyboard;\n }\n\n /**\n * Called at the start of the focus event. Consumes `_focusFromMouse` (or the\n * pinned origin set by `_setNextFocusOrigin()`), latches the result into\n * `_lastFocusFromMouse`, and returns whether focus was mouse-driven.\n */\n protected _consumeMouseFocus(): boolean {\n let wasMouseFocus: boolean;\n if (this._nextFocusOriginKeyboard !== null) {\n wasMouseFocus = !this._nextFocusOriginKeyboard;\n this._nextFocusOriginKeyboard = null;\n } else {\n wasMouseFocus = this._focusFromMouse;\n }\n this._focusFromMouse = false;\n this._lastFocusFromMouse = wasMouseFocus;\n return wasMouseFocus;\n }\n\n getKeyboardFocus(): boolean {\n return !this._lastFocusFromMouse;\n }\n\n protected _attachMouseFocusListeners(host: HTMLElement): void {\n host.addEventListener('pointerdown', this._setMouseFlag);\n host.addEventListener('mousedown', this._setMouseFlag);\n host.addEventListener('touchstart', this._setMouseFlag);\n }\n\n protected _detachMouseFocusListeners(host: HTMLElement): void {\n host.removeEventListener('pointerdown', this._setMouseFlag);\n host.removeEventListener('mousedown', this._setMouseFlag);\n host.removeEventListener('touchstart', this._setMouseFlag);\n }\n}\n"],"names":[],"mappings":";;;;;;;AAAA;;;;;;;AAOG;AAEH;;;;;;;;;;;AAWG;MACmB,oBAAoB,CAAA;AAA1C,IAAA,WAAA,GAAA;QACY,IAAA,CAAA,eAAe,GAAG,KAAK;QACvB,IAAA,CAAA,mBAAmB,GAAG,KAAK;AACrC;;;;;;AAMG;QACK,IAAA,CAAA,wBAAwB,GAAmB,IAAI;QAEpC,IAAA,CAAA,aAAa,GAAG,MAAW;AAC5C,YAAA,IAAI,CAAC,eAAe,GAAG,IAAI;AAC7B,QAAA,CAAC;IAyCH;AAvCE;AACwE;AAC9D,IAAA,mBAAmB,CAAC,QAAiB,EAAA;AAC7C,QAAA,IAAI,CAAC,wBAAwB,GAAG,QAAQ;IAC1C;AAEA;;;;AAIG;IACO,kBAAkB,GAAA;AAC1B,QAAA,IAAI,aAAsB;AAC1B,QAAA,IAAI,IAAI,CAAC,wBAAwB,KAAK,IAAI,EAAE;AAC1C,YAAA,aAAa,GAAG,CAAC,IAAI,CAAC,wBAAwB;AAC9C,YAAA,IAAI,CAAC,wBAAwB,GAAG,IAAI;QACtC;aAAO;AACL,YAAA,aAAa,GAAG,IAAI,CAAC,eAAe;QACtC;AACA,QAAA,IAAI,CAAC,eAAe,GAAG,KAAK;AAC5B,QAAA,IAAI,CAAC,mBAAmB,GAAG,aAAa;AACxC,QAAA,OAAO,aAAa;IACtB;IAEA,gBAAgB,GAAA;AACd,QAAA,OAAO,CAAC,IAAI,CAAC,mBAAmB;IAClC;AAEU,IAAA,0BAA0B,CAAC,IAAiB,EAAA;QACpD,IAAI,CAAC,gBAAgB,CAAC,aAAa,EAAE,IAAI,CAAC,aAAa,CAAC;QACxD,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC;QACtD,IAAI,CAAC,gBAAgB,CAAC,YAAY,EAAE,IAAI,CAAC,aAAa,CAAC;IACzD;AAEU,IAAA,0BAA0B,CAAC,IAAiB,EAAA;QACpD,IAAI,CAAC,mBAAmB,CAAC,aAAa,EAAE,IAAI,CAAC,aAAa,CAAC;QAC3D,IAAI,CAAC,mBAAmB,CAAC,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC;QACzD,IAAI,CAAC,mBAAmB,CAAC,YAAY,EAAE,IAAI,CAAC,aAAa,CAAC;IAC5D;AACD;;"}
|
|
@@ -7,8 +7,6 @@
|
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
|
8
8
|
*/
|
|
9
9
|
import type { PromptLineController } from './prompt-line-controller.js';
|
|
10
|
-
/** Exported so tests assert the ring without retyping the literal. */
|
|
11
|
-
export declare const PM_KEYBOARD_FOCUS_CLASS = "cds-aichat--input-pm-content--keyboard-focus";
|
|
12
10
|
/**
|
|
13
11
|
* Construct a Tiptap-backed prompt-line controller. Called by the shell once
|
|
14
12
|
* the lazily-imported runtime module has resolved.
|