@carbon/ai-chat-components 1.11.0 → 1.12.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/custom-elements.json +2358 -1973
- package/es/components/card/src/card-footer.scss.js +1 -1
- package/es/components/card/src/card-steps.scss.js +1 -1
- package/es/components/card/src/card.scss.js +1 -1
- package/es/components/chat-button/src/chat-button.scss.js +1 -1
- package/es/components/chat-history/src/history-panel-item-input.js +0 -1
- package/es/components/chat-history/src/history-panel-item-input.js.map +1 -1
- package/es/components/code-snippet/src/codemirror/language-controller.js +1 -1
- package/es/components/code-snippet/src/codemirror/language-controller.js.map +1 -1
- package/es/components/file-uploads/src/file-upload-item.d.ts +14 -1
- package/es/components/file-uploads/src/file-upload-item.js +78 -2
- package/es/components/file-uploads/src/file-upload-item.js.map +1 -1
- package/es/components/file-uploads/src/file-uploads.d.ts +29 -4
- package/es/components/file-uploads/src/file-uploads.js +69 -16
- package/es/components/file-uploads/src/file-uploads.js.map +1 -1
- package/es/components/launcher/src/launcher.scss.js +1 -1
- package/es/components/prompt-line/autocomplete/index.d.ts +1 -1
- package/es/components/prompt-line/autocomplete/src/autocomplete.d.ts +6 -0
- package/es/components/prompt-line/autocomplete/src/autocomplete.js +37 -11
- package/es/components/prompt-line/autocomplete/src/autocomplete.js.map +1 -1
- package/es/components/prompt-line/index.d.ts +3 -2
- package/es/components/prompt-line/index.js +2 -1
- package/es/components/prompt-line/index.js.map +1 -1
- package/es/components/prompt-line/src/__tests__/wait-for-rich.d.ts +20 -0
- package/es/components/prompt-line/src/autocomplete-controller-element.d.ts +84 -0
- package/es/components/prompt-line/src/autocomplete-controller-element.js +262 -0
- package/es/components/prompt-line/src/autocomplete-controller-element.js.map +1 -0
- package/es/components/prompt-line/src/autocomplete-controller.d.ts +10 -69
- package/es/components/prompt-line/src/autocomplete-controller.js +57 -251
- package/es/components/prompt-line/src/autocomplete-controller.js.map +1 -1
- package/es/components/prompt-line/src/prompt-line-rich-runtime.js +3 -0
- package/es/components/prompt-line/src/prompt-line-rich-runtime.js.map +1 -1
- package/es/components/prompt-line/src/prompt-line-shell.scss.js +1 -1
- package/es/components/prompt-line/src/prompt-line-textarea-runtime.js +0 -5
- package/es/components/prompt-line/src/prompt-line-textarea-runtime.js.map +1 -1
- package/es/components/prompt-line/src/prompt-line.js +1 -1
- package/es/components/prompt-line/src/prompt-line.js.map +1 -1
- package/es/components/prompt-line/src/send-control.d.ts +7 -0
- package/es/components/prompt-line/src/send-control.js +53 -5
- package/es/components/prompt-line/src/send-control.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/build-extensions.js +1 -1
- package/es/components/prompt-line/src/tiptap/build-extensions.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/carbon-autocomplete.d.ts +5 -6
- package/es/components/prompt-line/src/tiptap/carbon-autocomplete.js +24 -48
- package/es/components/prompt-line/src/tiptap/carbon-autocomplete.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/carbon-mention.js +14 -48
- package/es/components/prompt-line/src/tiptap/carbon-mention.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/carbon-starter-trigger.js +3 -4
- package/es/components/prompt-line/src/tiptap/carbon-starter-trigger.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/keymap.d.ts +1 -1
- package/es/components/prompt-line/src/tiptap/keymap.js +3 -4
- package/es/components/prompt-line/src/tiptap/keymap.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/render-token-chip.js +0 -1
- package/es/components/prompt-line/src/tiptap/render-token-chip.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/resolve-config-items.d.ts +18 -0
- package/es/components/prompt-line/src/tiptap/resolve-config-items.js +32 -0
- package/es/components/prompt-line/src/tiptap/resolve-config-items.js.map +1 -0
- package/es/components/prompt-line/src/tiptap/strip-presentation-fields.d.ts +18 -0
- package/es/components/prompt-line/src/tiptap/strip-presentation-fields.js +22 -0
- package/es/components/prompt-line/src/tiptap/strip-presentation-fields.js.map +1 -0
- package/es/components/prompt-line/src/tiptap/trigger-utils.d.ts +12 -8
- package/es/components/prompt-line/src/tiptap/trigger-utils.js +16 -1
- package/es/components/prompt-line/src/tiptap/trigger-utils.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/types.d.ts +11 -3
- package/es/components/toolbar/src/toolbar.d.ts +8 -0
- package/es/components/toolbar/src/toolbar.js +65 -19
- package/es/components/toolbar/src/toolbar.js.map +1 -1
- package/es/components/video-player/src/providers/vimeo-provider.js +1 -1
- package/es/components/video-player/src/providers/vimeo-provider.js.map +1 -1
- package/es/globals/decorators/carbon-element.js +2 -3
- package/es/globals/decorators/carbon-element.js.map +1 -1
- package/es/globals/utils/aria-announcer-manager.d.ts +56 -0
- package/es/globals/utils/aria-announcer-manager.js +46 -1
- package/es/globals/utils/aria-announcer-manager.js.map +1 -1
- package/es/globals/utils/focus-utils.js +1 -3
- package/es/globals/utils/focus-utils.js.map +1 -1
- package/es/globals/utils/iconTransform.d.ts +16 -2
- package/es/globals/utils/iconTransform.js +22 -1
- package/es/globals/utils/iconTransform.js.map +1 -1
- package/es/react/hooks/useChatAutocomplete.d.ts +5 -0
- package/es/react/hooks/useChatAutocomplete.js +26 -1
- package/es/react/hooks/useChatAutocomplete.js.map +1 -1
- package/es/react/markdown.js +0 -1
- package/es/react/markdown.js.map +1 -1
- package/es/typings/overflow-menu.d.ts +4 -0
- package/es-custom/components/card/src/card-footer.scss.js +1 -1
- package/es-custom/components/card/src/card-steps.scss.js +1 -1
- package/es-custom/components/card/src/card.scss.js +1 -1
- package/es-custom/components/chat-button/src/chat-button.scss.js +1 -1
- package/es-custom/components/chat-history/src/history-panel-item-input.js +0 -1
- package/es-custom/components/chat-history/src/history-panel-item-input.js.map +1 -1
- package/es-custom/components/code-snippet/src/codemirror/language-controller.js +1 -1
- package/es-custom/components/code-snippet/src/codemirror/language-controller.js.map +1 -1
- package/es-custom/components/file-uploads/src/file-upload-item.d.ts +14 -1
- package/es-custom/components/file-uploads/src/file-upload-item.js +78 -2
- package/es-custom/components/file-uploads/src/file-upload-item.js.map +1 -1
- package/es-custom/components/file-uploads/src/file-uploads.d.ts +29 -4
- package/es-custom/components/file-uploads/src/file-uploads.js +69 -16
- package/es-custom/components/file-uploads/src/file-uploads.js.map +1 -1
- package/es-custom/components/launcher/src/launcher.scss.js +1 -1
- package/es-custom/components/prompt-line/autocomplete/index.d.ts +1 -1
- package/es-custom/components/prompt-line/autocomplete/src/autocomplete.d.ts +6 -0
- package/es-custom/components/prompt-line/autocomplete/src/autocomplete.js +37 -11
- package/es-custom/components/prompt-line/autocomplete/src/autocomplete.js.map +1 -1
- package/es-custom/components/prompt-line/index.d.ts +3 -2
- package/es-custom/components/prompt-line/index.js +2 -1
- package/es-custom/components/prompt-line/index.js.map +1 -1
- package/es-custom/components/prompt-line/src/__tests__/wait-for-rich.d.ts +20 -0
- package/es-custom/components/prompt-line/src/autocomplete-controller-element.d.ts +84 -0
- package/es-custom/components/prompt-line/src/autocomplete-controller-element.js +262 -0
- package/es-custom/components/prompt-line/src/autocomplete-controller-element.js.map +1 -0
- package/es-custom/components/prompt-line/src/autocomplete-controller.d.ts +10 -69
- package/es-custom/components/prompt-line/src/autocomplete-controller.js +57 -251
- package/es-custom/components/prompt-line/src/autocomplete-controller.js.map +1 -1
- package/es-custom/components/prompt-line/src/prompt-line-rich-runtime.js +3 -0
- package/es-custom/components/prompt-line/src/prompt-line-rich-runtime.js.map +1 -1
- package/es-custom/components/prompt-line/src/prompt-line-shell.scss.js +1 -1
- package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.js +0 -5
- package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.js.map +1 -1
- package/es-custom/components/prompt-line/src/prompt-line.js +1 -1
- package/es-custom/components/prompt-line/src/prompt-line.js.map +1 -1
- package/es-custom/components/prompt-line/src/send-control.d.ts +7 -0
- package/es-custom/components/prompt-line/src/send-control.js +53 -5
- package/es-custom/components/prompt-line/src/send-control.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/build-extensions.js +1 -1
- package/es-custom/components/prompt-line/src/tiptap/build-extensions.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/carbon-autocomplete.d.ts +5 -6
- package/es-custom/components/prompt-line/src/tiptap/carbon-autocomplete.js +24 -48
- package/es-custom/components/prompt-line/src/tiptap/carbon-autocomplete.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/carbon-mention.js +14 -48
- package/es-custom/components/prompt-line/src/tiptap/carbon-mention.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/carbon-starter-trigger.js +3 -4
- package/es-custom/components/prompt-line/src/tiptap/carbon-starter-trigger.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/keymap.d.ts +1 -1
- package/es-custom/components/prompt-line/src/tiptap/keymap.js +3 -4
- package/es-custom/components/prompt-line/src/tiptap/keymap.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/render-token-chip.js +0 -1
- package/es-custom/components/prompt-line/src/tiptap/render-token-chip.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/resolve-config-items.d.ts +18 -0
- package/es-custom/components/prompt-line/src/tiptap/resolve-config-items.js +32 -0
- package/es-custom/components/prompt-line/src/tiptap/resolve-config-items.js.map +1 -0
- package/es-custom/components/prompt-line/src/tiptap/strip-presentation-fields.d.ts +18 -0
- package/es-custom/components/prompt-line/src/tiptap/strip-presentation-fields.js +22 -0
- package/es-custom/components/prompt-line/src/tiptap/strip-presentation-fields.js.map +1 -0
- package/es-custom/components/prompt-line/src/tiptap/trigger-utils.d.ts +12 -8
- package/es-custom/components/prompt-line/src/tiptap/trigger-utils.js +16 -1
- package/es-custom/components/prompt-line/src/tiptap/trigger-utils.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/types.d.ts +11 -3
- package/es-custom/components/toolbar/src/toolbar.d.ts +8 -0
- package/es-custom/components/toolbar/src/toolbar.js +65 -19
- package/es-custom/components/toolbar/src/toolbar.js.map +1 -1
- package/es-custom/components/video-player/src/providers/vimeo-provider.js +1 -1
- package/es-custom/components/video-player/src/providers/vimeo-provider.js.map +1 -1
- package/es-custom/globals/decorators/carbon-element.js +2 -3
- package/es-custom/globals/decorators/carbon-element.js.map +1 -1
- package/es-custom/globals/utils/aria-announcer-manager.d.ts +56 -0
- package/es-custom/globals/utils/aria-announcer-manager.js +46 -1
- package/es-custom/globals/utils/aria-announcer-manager.js.map +1 -1
- package/es-custom/globals/utils/focus-utils.js +1 -3
- package/es-custom/globals/utils/focus-utils.js.map +1 -1
- package/es-custom/globals/utils/iconTransform.d.ts +16 -2
- package/es-custom/globals/utils/iconTransform.js +22 -1
- package/es-custom/globals/utils/iconTransform.js.map +1 -1
- package/es-custom/react/hooks/useChatAutocomplete.d.ts +5 -0
- package/es-custom/react/hooks/useChatAutocomplete.js +26 -1
- package/es-custom/react/hooks/useChatAutocomplete.js.map +1 -1
- package/es-custom/react/markdown.js +0 -1
- package/es-custom/react/markdown.js.map +1 -1
- package/es-custom/typings/overflow-menu.d.ts +4 -0
- package/package.json +6 -6
- package/scss/_custom-properties.scss +0 -17
- package/scss/_tokens-component.scss +1 -2
|
@@ -30,7 +30,11 @@ function buildTriggerExtension(config, build) {
|
|
|
30
30
|
...parent,
|
|
31
31
|
mentionSuggestionChar: { default: config.trigger },
|
|
32
32
|
value: { default: null },
|
|
33
|
-
|
|
33
|
+
// Host custom fields, held in editor state only: they survive the JSON
|
|
34
|
+
// round-trip, undo/redo, and moves within the document, and never
|
|
35
|
+
// reach HTML. Tiptap's default attribute rendering would stringify the
|
|
36
|
+
// object into the markup as "[object Object]".
|
|
37
|
+
data: { default: null, renderHTML: () => ({}) },
|
|
34
38
|
trigger: { default: null },
|
|
35
39
|
};
|
|
36
40
|
},
|
|
@@ -80,33 +84,6 @@ function buildTriggerExtension(config, build) {
|
|
|
80
84
|
char: config.trigger,
|
|
81
85
|
pluginKey,
|
|
82
86
|
startOfLine: config.triggerPosition === 'start',
|
|
83
|
-
items: ({ query }) => resolveItems(config, query),
|
|
84
|
-
command: ({ editor, range, props }) => {
|
|
85
|
-
const item = props;
|
|
86
|
-
// Insert the mention/command node with our extended attrs.
|
|
87
|
-
editor
|
|
88
|
-
.chain()
|
|
89
|
-
.focus()
|
|
90
|
-
.insertContentAt(range, [
|
|
91
|
-
{
|
|
92
|
-
type: name,
|
|
93
|
-
attrs: {
|
|
94
|
-
id: item.id,
|
|
95
|
-
label: item.label,
|
|
96
|
-
value: item.value ?? item.label,
|
|
97
|
-
// Item overrides config overrides the command/mention
|
|
98
|
-
// default (see resolveShowTriggerInChip).
|
|
99
|
-
trigger: resolveShowTriggerInChip(item, config, build.defaultName === 'command')
|
|
100
|
-
? config.trigger
|
|
101
|
-
: null,
|
|
102
|
-
data: stripPresentationFields(item),
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
{ type: 'text', text: ' ' },
|
|
106
|
-
])
|
|
107
|
-
.run();
|
|
108
|
-
config.onSelect?.(item);
|
|
109
|
-
},
|
|
110
87
|
render: () => {
|
|
111
88
|
let lastQuery = null;
|
|
112
89
|
return {
|
|
@@ -122,7 +99,7 @@ function buildTriggerExtension(config, build) {
|
|
|
122
99
|
},
|
|
123
100
|
onExit: (props) => {
|
|
124
101
|
lastQuery = null;
|
|
125
|
-
dispatchTriggerChange(props.editor, null);
|
|
102
|
+
dispatchTriggerChange(props.editor, null, name);
|
|
126
103
|
},
|
|
127
104
|
onKeyDown: () => false,
|
|
128
105
|
};
|
|
@@ -168,7 +145,14 @@ function collectTokenAttrsById(doc, name) {
|
|
|
168
145
|
* `label`, `value`, and any custom fields stashed in `data` survive.
|
|
169
146
|
*/
|
|
170
147
|
function attrsToItem(attrs) {
|
|
171
|
-
|
|
148
|
+
// `data` holds whatever a caller put in the node's attrs, and
|
|
149
|
+
// `insertContent()` takes a raw node spec — so a host can land a string or
|
|
150
|
+
// an array here. Spreading either yields index keys ({...'abc'} → {0:'a'}),
|
|
151
|
+
// which would then reach onRemove as if the host had set them.
|
|
152
|
+
const raw = attrs.data;
|
|
153
|
+
const data = raw && typeof raw === 'object' && !Array.isArray(raw)
|
|
154
|
+
? raw
|
|
155
|
+
: {};
|
|
172
156
|
return {
|
|
173
157
|
...data,
|
|
174
158
|
id: String(attrs.id),
|
|
@@ -193,20 +177,6 @@ function diffRemovedTokens(before, after, name) {
|
|
|
193
177
|
}
|
|
194
178
|
return removed;
|
|
195
179
|
}
|
|
196
|
-
async function resolveItems(config, query) {
|
|
197
|
-
const minQueryLength = config.minQueryLength ?? 0;
|
|
198
|
-
if (query.length < minQueryLength) {
|
|
199
|
-
return [];
|
|
200
|
-
}
|
|
201
|
-
if (typeof config.items === 'function') {
|
|
202
|
-
return Promise.resolve(config.items(query));
|
|
203
|
-
}
|
|
204
|
-
if (!query) {
|
|
205
|
-
return config.items;
|
|
206
|
-
}
|
|
207
|
-
const lower = query.toLowerCase();
|
|
208
|
-
return config.items.filter((item) => item.label.toLowerCase().includes(lower));
|
|
209
|
-
}
|
|
210
180
|
/**
|
|
211
181
|
* Resolve whether a selected item's chip should be prefixed with the
|
|
212
182
|
* trigger character: the item's own {@link SuggestionItem.showTriggerInChip}
|
|
@@ -217,10 +187,6 @@ async function resolveItems(config, query) {
|
|
|
217
187
|
function resolveShowTriggerInChip(item, config, isCommand) {
|
|
218
188
|
return item.showTriggerInChip ?? config.showTriggerInChip ?? isCommand;
|
|
219
189
|
}
|
|
220
|
-
function stripPresentationFields(item) {
|
|
221
|
-
const { id: _id, label: _label, value: _value, avatar: _avatar, description: _description, disabled: _disabled, showTriggerInChip: _showTriggerInChip, ...rest } = item;
|
|
222
|
-
return rest;
|
|
223
|
-
}
|
|
224
190
|
function carbonMention(config) {
|
|
225
191
|
return buildTriggerExtension(config, {
|
|
226
192
|
defaultName: 'mention',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"carbon-mention.js","sources":["../../../../../src/components/prompt-line/src/tiptap/carbon-mention.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 * `carbonMention` and `carbonCommand` factories. Both wrap\n * `@tiptap/extension-mention` with carbon-specific:\n * - chip rendering via `CarbonTokenNodeView` (uses the light-DOM portal\n * handshake so React portal consumers render in light DOM).\n * - extra schema attrs (`value`, `data`, `trigger`) layered on top of\n * Mention's default `id` + `label`.\n * - direct `cds-custom-aichat-trigger-change` dispatch from the suggestion-render\n * lifecycle via the shared `dispatchTriggerChange` helper.\n * - an `onRemove` callback fired when a user edit deletes a token node, the\n * mirror of the suggestion `onSelect` (see the removal ProseMirror plugin).\n *\n * They share an internal builder. The two exports differ only in their\n * default schema-node name (`\"mention\"` vs `\"command\"`), the dispatched\n * trigger type, the default chip color (handled inside the NodeView), and\n * the default for whether the trigger char is stored on inserted nodes —\n * `carbonCommand` defaults to on, `carbonMention` to off, so command chips\n * default to reading as `/summarize` while mention chips stay a bare name.\n * Either default can be overridden per-config (`TriggerSuggestionConfig.\n * showTriggerInChip`) or per-item (`SuggestionItem.showTriggerInChip`, which\n * wins when set — e.g. a single `@` picker mixing people and agents).\n * Each chat supports one mention trigger and one command trigger, because\n * Tiptap resolves extensions by name.\n */\n\nimport type { Editor, Range } from '@tiptap/core';\nimport Mention from '@tiptap/extension-mention';\nimport type { Node as PMNode } from '@tiptap/pm/model';\nimport { Plugin, PluginKey } from '@tiptap/pm/state';\n\nimport { isHostOrigin } from './origin-meta.js';\nimport { CarbonTokenNodeView } from './token-node-view.js';\nimport { dispatchTriggerChange } from './trigger-utils.js';\nimport type { SuggestionItem, TriggerSuggestionConfig } from './types.js';\n\ninterface BuildOptions {\n defaultName: 'mention' | 'command';\n defaultPluginKeyName: string;\n}\n\nfunction buildTriggerExtension(\n config: TriggerSuggestionConfig,\n build: BuildOptions\n) {\n const name = build.defaultName;\n const pluginKey = new PluginKey(`${build.defaultPluginKeyName}_${name}`);\n\n return Mention.extend({\n name,\n\n addAttributes() {\n const parent = (this.parent?.() ?? {}) as Record<string, unknown>;\n return {\n ...parent,\n mentionSuggestionChar: { default: config.trigger },\n value: { default: null },\n data: { default: null },\n trigger: { default: null },\n };\n },\n\n addNodeView() {\n return ({ node, editor }) =>\n new CarbonTokenNodeView(node, editor.view, {\n renderCustomToken: config.renderCustomToken,\n });\n },\n\n addProseMirrorPlugins() {\n const parentPlugins = this.parent?.() ?? [];\n const onRemove = config.onRemove;\n if (!onRemove) {\n return parentPlugins;\n }\n\n // Fire `onRemove` once per token node of this type that leaves the doc\n // via a USER edit. `appendTransaction` records whether the batch was\n // host-origin — `some`, where typing-indicator uses `every` — and the\n // view's `update` runs the diff (after state is applied, so host\n // callbacks never re-enter `dispatch`). Host-origin batches — the\n // framework's post-send clear and any `getEditor()`/`updateContent`\n // mutation — are skipped, symmetric with `onSelect` firing only on user\n // popup selection.\n let lastBatchIsHost = false;\n\n const removalPlugin = new Plugin({\n key: new PluginKey(`${name}_removal`),\n appendTransaction(transactions) {\n lastBatchIsHost = transactions.some((tr) => isHostOrigin(tr));\n return null;\n },\n view: () => ({\n update(view, prevState) {\n if (view.state.doc === prevState.doc || lastBatchIsHost) {\n return;\n }\n const removed = diffRemovedTokens(\n prevState.doc,\n view.state.doc,\n name\n );\n for (const item of removed) {\n onRemove(item);\n }\n },\n }),\n });\n\n return [...parentPlugins, removalPlugin];\n },\n }).configure({\n HTMLAttributes: { 'data-token-type': name },\n suggestion: {\n char: config.trigger,\n pluginKey,\n startOfLine: config.triggerPosition === 'start',\n items: ({ query }) => resolveItems(config, query),\n command: ({ editor, range, props }) => {\n const item = props as SuggestionItem;\n // Insert the mention/command node with our extended attrs.\n editor\n .chain()\n .focus()\n .insertContentAt(range, [\n {\n type: name,\n attrs: {\n id: item.id,\n label: item.label,\n value: item.value ?? item.label,\n // Item overrides config overrides the command/mention\n // default (see resolveShowTriggerInChip).\n trigger: resolveShowTriggerInChip(\n item,\n config,\n build.defaultName === 'command'\n )\n ? config.trigger\n : null,\n data: stripPresentationFields(item),\n },\n },\n { type: 'text', text: ' ' },\n ])\n .run();\n config.onSelect?.(item);\n },\n render: () => {\n let lastQuery: string | null = null;\n return {\n onStart: (props) =>\n emitTrigger(props.editor, name, props.query, props.range, () => {\n lastQuery = props.query;\n }),\n onUpdate: (props) => {\n if (props.query === lastQuery) {\n return;\n }\n lastQuery = props.query;\n emitTrigger(props.editor, name, props.query, props.range);\n },\n onExit: (props) => {\n lastQuery = null;\n dispatchTriggerChange(props.editor, null);\n },\n onKeyDown: () => false,\n };\n },\n },\n });\n}\n\nfunction emitTrigger(\n editor: Editor,\n type: string,\n query: string,\n range: Range,\n postEmit?: () => void\n): void {\n dispatchTriggerChange(editor, {\n type,\n query,\n triggerOffset: range.from,\n });\n postEmit?.();\n}\n\n/**\n * Collect the attrs of every node named `name` in `doc`, grouped by id and\n * kept in document order, so a multiset diff can tell which specific node\n * instances were removed (duplicate chips with the same id are tracked by\n * count, not collapsed).\n */\nfunction collectTokenAttrsById(\n doc: PMNode,\n name: string\n): Map<string, Record<string, unknown>[]> {\n const byId = new Map<string, Record<string, unknown>[]>();\n doc.descendants((node) => {\n if (node.type.name !== name) {\n return;\n }\n const attrs = node.attrs as Record<string, unknown>;\n const id = String(attrs.id);\n const bucket = byId.get(id);\n if (bucket) {\n bucket.push(attrs);\n } else {\n byId.set(id, [attrs]);\n }\n });\n return byId;\n}\n\n/**\n * Reconstruct a {@link SuggestionItem} from a removed token node's attrs.\n * Presentation-only fields were stripped at insert time, so only `id`,\n * `label`, `value`, and any custom fields stashed in `data` survive.\n */\nfunction attrsToItem(attrs: Record<string, unknown>): SuggestionItem {\n const data = (attrs.data ?? {}) as Record<string, unknown>;\n return {\n ...data,\n id: String(attrs.id),\n label: attrs.label as string,\n value: (attrs.value ?? undefined) as string | undefined,\n };\n}\n\n/**\n * Diff token nodes named `name` between `before` and `after`, returning the\n * reconstructed items for each removed node instance (one entry per removed\n * duplicate).\n */\nfunction diffRemovedTokens(\n before: PMNode,\n after: PMNode,\n name: string\n): SuggestionItem[] {\n const beforeById = collectTokenAttrsById(before, name);\n const afterById = collectTokenAttrsById(after, name);\n const removed: SuggestionItem[] = [];\n for (const [id, beforeAttrs] of beforeById) {\n const afterCount = afterById.get(id)?.length ?? 0;\n for (let i = afterCount; i < beforeAttrs.length; i += 1) {\n removed.push(attrsToItem(beforeAttrs[i]));\n }\n }\n return removed;\n}\n\nasync function resolveItems(\n config: TriggerSuggestionConfig,\n query: string\n): Promise<SuggestionItem[]> {\n const minQueryLength = config.minQueryLength ?? 0;\n if (query.length < minQueryLength) {\n return [];\n }\n if (typeof config.items === 'function') {\n return Promise.resolve(config.items(query));\n }\n if (!query) {\n return config.items;\n }\n const lower = query.toLowerCase();\n return config.items.filter((item) =>\n item.label.toLowerCase().includes(lower)\n );\n}\n\n/**\n * Resolve whether a selected item's chip should be prefixed with the\n * trigger character: the item's own {@link SuggestionItem.showTriggerInChip}\n * wins when set, then the config's\n * {@link TriggerSuggestionConfig.showTriggerInChip}, then the\n * command/mention default.\n */\nexport function resolveShowTriggerInChip(\n item: SuggestionItem,\n config: Pick<TriggerSuggestionConfig, 'showTriggerInChip'>,\n isCommand: boolean\n): boolean {\n return item.showTriggerInChip ?? config.showTriggerInChip ?? isCommand;\n}\n\nfunction stripPresentationFields(\n item: SuggestionItem\n): Record<string, unknown> {\n const {\n id: _id,\n label: _label,\n value: _value,\n avatar: _avatar,\n description: _description,\n disabled: _disabled,\n showTriggerInChip: _showTriggerInChip,\n ...rest\n } = item;\n void _id;\n void _label;\n void _value;\n void _avatar;\n void _description;\n void _disabled;\n void _showTriggerInChip;\n return rest;\n}\n\nexport function carbonMention(config: TriggerSuggestionConfig) {\n return buildTriggerExtension(config, {\n defaultName: 'mention',\n defaultPluginKeyName: 'carbonMentionSuggestion',\n });\n}\n\nexport function carbonCommand(config: TriggerSuggestionConfig) {\n return buildTriggerExtension(config, {\n defaultName: 'command',\n defaultPluginKeyName: 'carbonCommandSuggestion',\n });\n}\n"],"names":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ACa,wBAAwB,CACtC,IAAoB,EACpB,MAA0D,EAC1D,SAAkB,EAAA;IAElB,OAAO,IAAI,CAAC,iBAAiB,IAAI,MAAM,CAAC,iBAAiB,IAAI,SAAS;AACxE;AAEA,SAAS,uBAAuB,CAC9B,IAAoB,EAAA;AAEpB,IAAA,MAAM,EACJ,EAAE,EAAE,GAAG,EACP,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,YAAY,EACzB,QAAQ,EAAE,SAAS,EACnB,iBAAiB,EAAE,kBAAkB,EACrC,GAAG,IAAI,EACR,GAAG,IAAI;AAQR,IAAA,OAAO,IAAI;AACb;AAEM,SAAU,aAAa,CAAC,MAA+B,EAAA;IAC3D,OAAO,qBAAqB,CAAC,MAAM,EAAE;AACnC,QAAA,WAAW,EAAE,SAAS;AACtB,QAAA,oBAAoB,EAAE,yBAAyB;AAChD,KAAA,CAAC;AACJ;AAEM,SAAU,aAAa,CAAC,MAA+B,EAAA;IAC3D,OAAO,qBAAqB,CAAC,MAAM,EAAE;AACnC,QAAA,WAAW,EAAE,SAAS;AACtB,QAAA,oBAAoB,EAAE,yBAAyB;AAChD,KAAA,CAAC;AACJ;;"}
|
|
1
|
+
{"version":3,"file":"carbon-mention.js","sources":["../../../../../src/components/prompt-line/src/tiptap/carbon-mention.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 * `carbonMention` and `carbonCommand` factories. Both wrap\n * `@tiptap/extension-mention` with carbon-specific:\n * - chip rendering via `CarbonTokenNodeView` (uses the light-DOM portal\n * handshake so React portal consumers render in light DOM).\n * - extra schema attrs (`value`, `data`, `trigger`) layered on top of\n * Mention's default `id` + `label`.\n * - direct `cds-custom-aichat-trigger-change` dispatch from the suggestion-render\n * lifecycle via the shared `dispatchTriggerChange` helper.\n * - an `onRemove` callback fired when a user edit deletes a token node, the\n * mirror of the suggestion `onSelect` (see the removal ProseMirror plugin).\n *\n * They share an internal builder. The two exports differ only in their\n * default schema-node name (`\"mention\"` vs `\"command\"`), the dispatched\n * trigger type, the default chip color (handled inside the NodeView), and\n * the default for whether the trigger char is stored on inserted nodes —\n * `carbonCommand` defaults to on, `carbonMention` to off, so command chips\n * default to reading as `/summarize` while mention chips stay a bare name.\n * Either default can be overridden per-config (`TriggerSuggestionConfig.\n * showTriggerInChip`) or per-item (`SuggestionItem.showTriggerInChip`, which\n * wins when set — e.g. a single `@` picker mixing people and agents).\n * Each chat supports one mention trigger and one command trigger, because\n * Tiptap resolves extensions by name.\n */\n\nimport type { Editor, Range } from '@tiptap/core';\nimport Mention from '@tiptap/extension-mention';\nimport type { Node as PMNode } from '@tiptap/pm/model';\nimport { Plugin, PluginKey } from '@tiptap/pm/state';\n\nimport { isHostOrigin } from './origin-meta.js';\nimport { CarbonTokenNodeView } from './token-node-view.js';\nimport { dispatchTriggerChange } from './trigger-utils.js';\nimport type { SuggestionItem, TriggerSuggestionConfig } from './types.js';\n\ninterface BuildOptions {\n defaultName: 'mention' | 'command';\n defaultPluginKeyName: string;\n}\n\nfunction buildTriggerExtension(\n config: TriggerSuggestionConfig,\n build: BuildOptions\n) {\n const name = build.defaultName;\n const pluginKey = new PluginKey(`${build.defaultPluginKeyName}_${name}`);\n\n return Mention.extend({\n name,\n\n addAttributes() {\n const parent = (this.parent?.() ?? {}) as Record<string, unknown>;\n return {\n ...parent,\n mentionSuggestionChar: { default: config.trigger },\n value: { default: null },\n // Host custom fields, held in editor state only: they survive the JSON\n // round-trip, undo/redo, and moves within the document, and never\n // reach HTML. Tiptap's default attribute rendering would stringify the\n // object into the markup as \"[object Object]\".\n data: { default: null, renderHTML: () => ({}) },\n trigger: { default: null },\n };\n },\n\n addNodeView() {\n return ({ node, editor }) =>\n new CarbonTokenNodeView(node, editor.view, {\n renderCustomToken: config.renderCustomToken,\n });\n },\n\n addProseMirrorPlugins() {\n const parentPlugins = this.parent?.() ?? [];\n const onRemove = config.onRemove;\n if (!onRemove) {\n return parentPlugins;\n }\n\n // Fire `onRemove` once per token node of this type that leaves the doc\n // via a USER edit. `appendTransaction` records whether the batch was\n // host-origin — `some`, where typing-indicator uses `every` — and the\n // view's `update` runs the diff (after state is applied, so host\n // callbacks never re-enter `dispatch`). Host-origin batches — the\n // framework's post-send clear and any `getEditor()`/`updateContent`\n // mutation — are skipped, symmetric with `onSelect` firing only on user\n // popup selection.\n let lastBatchIsHost = false;\n\n const removalPlugin = new Plugin({\n key: new PluginKey(`${name}_removal`),\n appendTransaction(transactions) {\n lastBatchIsHost = transactions.some((tr) => isHostOrigin(tr));\n return null;\n },\n view: () => ({\n update(view, prevState) {\n if (view.state.doc === prevState.doc || lastBatchIsHost) {\n return;\n }\n const removed = diffRemovedTokens(\n prevState.doc,\n view.state.doc,\n name\n );\n for (const item of removed) {\n onRemove(item);\n }\n },\n }),\n });\n\n return [...parentPlugins, removalPlugin];\n },\n }).configure({\n HTMLAttributes: { 'data-token-type': name },\n suggestion: {\n char: config.trigger,\n pluginKey,\n startOfLine: config.triggerPosition === 'start',\n render: () => {\n let lastQuery: string | null = null;\n return {\n onStart: (props) =>\n emitTrigger(props.editor, name, props.query, props.range, () => {\n lastQuery = props.query;\n }),\n onUpdate: (props) => {\n if (props.query === lastQuery) {\n return;\n }\n lastQuery = props.query;\n emitTrigger(props.editor, name, props.query, props.range);\n },\n onExit: (props) => {\n lastQuery = null;\n dispatchTriggerChange(props.editor, null, name);\n },\n onKeyDown: () => false,\n };\n },\n },\n });\n}\n\nfunction emitTrigger(\n editor: Editor,\n type: string,\n query: string,\n range: Range,\n postEmit?: () => void\n): void {\n dispatchTriggerChange(editor, {\n type,\n query,\n triggerOffset: range.from,\n });\n postEmit?.();\n}\n\n/**\n * Collect the attrs of every node named `name` in `doc`, grouped by id and\n * kept in document order, so a multiset diff can tell which specific node\n * instances were removed (duplicate chips with the same id are tracked by\n * count, not collapsed).\n */\nfunction collectTokenAttrsById(\n doc: PMNode,\n name: string\n): Map<string, Record<string, unknown>[]> {\n const byId = new Map<string, Record<string, unknown>[]>();\n doc.descendants((node) => {\n if (node.type.name !== name) {\n return;\n }\n const attrs = node.attrs as Record<string, unknown>;\n const id = String(attrs.id);\n const bucket = byId.get(id);\n if (bucket) {\n bucket.push(attrs);\n } else {\n byId.set(id, [attrs]);\n }\n });\n return byId;\n}\n\n/**\n * Reconstruct a {@link SuggestionItem} from a removed token node's attrs.\n * Presentation-only fields were stripped at insert time, so only `id`,\n * `label`, `value`, and any custom fields stashed in `data` survive.\n */\nfunction attrsToItem(attrs: Record<string, unknown>): SuggestionItem {\n // `data` holds whatever a caller put in the node's attrs, and\n // `insertContent()` takes a raw node spec — so a host can land a string or\n // an array here. Spreading either yields index keys ({...'abc'} → {0:'a'}),\n // which would then reach onRemove as if the host had set them.\n const raw = attrs.data;\n const data =\n raw && typeof raw === 'object' && !Array.isArray(raw)\n ? (raw as Record<string, unknown>)\n : {};\n return {\n ...data,\n id: String(attrs.id),\n label: attrs.label as string,\n value: (attrs.value ?? undefined) as string | undefined,\n };\n}\n\n/**\n * Diff token nodes named `name` between `before` and `after`, returning the\n * reconstructed items for each removed node instance (one entry per removed\n * duplicate).\n */\nfunction diffRemovedTokens(\n before: PMNode,\n after: PMNode,\n name: string\n): SuggestionItem[] {\n const beforeById = collectTokenAttrsById(before, name);\n const afterById = collectTokenAttrsById(after, name);\n const removed: SuggestionItem[] = [];\n for (const [id, beforeAttrs] of beforeById) {\n const afterCount = afterById.get(id)?.length ?? 0;\n for (let i = afterCount; i < beforeAttrs.length; i += 1) {\n removed.push(attrsToItem(beforeAttrs[i]));\n }\n }\n return removed;\n}\n\n/**\n * Resolve whether a selected item's chip should be prefixed with the\n * trigger character: the item's own {@link SuggestionItem.showTriggerInChip}\n * wins when set, then the config's\n * {@link TriggerSuggestionConfig.showTriggerInChip}, then the\n * command/mention default.\n */\nexport function resolveShowTriggerInChip(\n item: SuggestionItem,\n config: Pick<TriggerSuggestionConfig, 'showTriggerInChip'>,\n isCommand: boolean\n): boolean {\n return item.showTriggerInChip ?? config.showTriggerInChip ?? isCommand;\n}\n\nexport function carbonMention(config: TriggerSuggestionConfig) {\n return buildTriggerExtension(config, {\n defaultName: 'mention',\n defaultPluginKeyName: 'carbonMentionSuggestion',\n });\n}\n\nexport function carbonCommand(config: TriggerSuggestionConfig) {\n return buildTriggerExtension(config, {\n defaultName: 'command',\n defaultPluginKeyName: 'carbonCommandSuggestion',\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAAA;;;;;;;AAOG;AA0CH,SAAS,qBAAqB,CAC5B,MAA+B,EAC/B,KAAmB,EAAA;AAEnB,IAAA,MAAM,IAAI,GAAG,KAAK,CAAC,WAAW;AAC9B,IAAA,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,CAAA,EAAG,KAAK,CAAC,oBAAoB,CAAA,CAAA,EAAI,IAAI,CAAA,CAAE,CAAC;IAExE,OAAO,OAAO,CAAC,MAAM,CAAC;QACpB,IAAI;QAEJ,aAAa,GAAA;YACX,MAAM,MAAM,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,EAAE,CAA4B;YACjE,OAAO;AACL,gBAAA,GAAG,MAAM;AACT,gBAAA,qBAAqB,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE;AAClD,gBAAA,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;;;;;AAKxB,gBAAA,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,EAAE;AAC/C,gBAAA,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;aAC3B;QACH,CAAC;QAED,WAAW,GAAA;AACT,YAAA,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KACtB,IAAI,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE;gBACzC,iBAAiB,EAAE,M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G,CAAC,EAAE,CAAC,EAAE,MAAM,IAAI,CAAC;AACjD,QAAA,KAAK,IAAI,CAAC,GAAG,UAAU,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;YACvD,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3C;IACF;AACA,IAAA,OAAO,OAAO;AAChB;AAEA;;;;;;AAMG;SACa,wBAAwB,CACtC,IAAoB,EACpB,MAA0D,EAC1D,SAAkB,EAAA;IAElB,OAAO,IAAI,CAAC,iBAAiB,IAAI,MAAM,CAAC,iBAAiB,IAAI,SAAS;AACxE;AAEM,SAAU,aAAa,CAAC,MAA+B,EAAA;IAC3D,OAAO,qBAAqB,CAAC,MAAM,EAAE;AACnC,QAAA,WAAW,EAAE,SAAS;AACtB,QAAA,oBAAoB,EAAE,yBAAyB;AAChD,KAAA,CAAC;AACJ;AAEM,SAAU,aAAa,CAAC,MAA+B,EAAA;IAC3D,OAAO,qBAAqB,CAAC,MAAM,EAAE;AACnC,QAAA,WAAW,EAAE,SAAS;AACtB,QAAA,oBAAoB,EAAE,yBAAyB;AAChD,KAAA,CAAC;AACJ;;"}
|
|
@@ -52,13 +52,12 @@ function writeStarterStorage(editor, patch) {
|
|
|
52
52
|
function carbonStarterTrigger(initialItems, initialIsOn = true) {
|
|
53
53
|
return Extension.create({
|
|
54
54
|
name: 'carbonStarterTrigger',
|
|
55
|
+
// Each editor gets fresh storage from here. Tiptap emits `create` a
|
|
56
|
+
// macrotask later, so resetting storage there would drop a write the host
|
|
57
|
+
// made in between.
|
|
55
58
|
addStorage() {
|
|
56
59
|
return { items: initialItems, isOn: initialIsOn };
|
|
57
60
|
},
|
|
58
|
-
onCreate() {
|
|
59
|
-
this.storage.items = initialItems;
|
|
60
|
-
this.storage.isOn = initialIsOn;
|
|
61
|
-
},
|
|
62
61
|
onUpdate() {
|
|
63
62
|
maybeEmit(this.editor);
|
|
64
63
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"carbon-starter-trigger.js","sources":["../../../../../src/components/prompt-line/src/tiptap/carbon-starter-trigger.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 * `carbonStarterTrigger` factory. Watches the editor's empty + focused +\n * editable state and emits `cds-custom-aichat-trigger-change` with `type: \"starter\"`\n * via the shared `dispatchTriggerChange` helper.\n *\n * Items are stored on `extension.storage.items` so the prompt-line / shell\n * can swap the list at runtime without recreating the editor.\n */\n\nimport { Extension, type Editor } from '@tiptap/core';\n\nimport {\n dispatchTriggerChange,\n resetTriggerChangeState,\n} from './trigger-utils.js';\nimport type { SuggestionItem } from './types.js';\n\nexport interface StarterTriggerStorage {\n items: SuggestionItem[];\n isOn: boolean;\n}\n\n/** Read the starter trigger's live storage, or `undefined` if not installed. */\nexport function readStarterStorage(\n editor: Editor | null | undefined\n): StarterTriggerStorage | undefined {\n return (editor?.storage as unknown as Record<string, unknown> | undefined)\n ?.carbonStarterTrigger as StarterTriggerStorage | undefined;\n}\n\n/**\n * Apply a starter-config patch to the live editor. Starter differences never\n * justify recreating the editor — that would drop undo history — so they are\n * written in place. The empty transaction re-runs this extension's\n * `onTransaction` hook, so a toggle takes effect against the current selection\n * instead of waiting for the next keystroke. No-ops when nothing changed, so\n * callers do not have to guard.\n */\nexport function writeStarterStorage(\n editor: Editor | null | undefined,\n patch: Partial<StarterTriggerStorage>\n): void {\n const storage = readStarterStorage(editor);\n if (!editor || !storage) {\n return;\n }\n const entries = Object.entries(patch) as [\n keyof StarterTriggerStorage,\n StarterTriggerStorage[keyof StarterTriggerStorage],\n ][];\n if (entries.every(([key, value]) => storage[key] === value)) {\n return;\n }\n Object.assign(storage, patch);\n editor.view.dispatch(editor.state.tr);\n}\n\nexport function carbonStarterTrigger(\n initialItems: SuggestionItem[],\n initialIsOn = true\n): Extension {\n return Extension.create<unknown, StarterTriggerStorage>({\n name: 'carbonStarterTrigger',\n\n
|
|
1
|
+
{"version":3,"file":"carbon-starter-trigger.js","sources":["../../../../../src/components/prompt-line/src/tiptap/carbon-starter-trigger.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 * `carbonStarterTrigger` factory. Watches the editor's empty + focused +\n * editable state and emits `cds-custom-aichat-trigger-change` with `type: \"starter\"`\n * via the shared `dispatchTriggerChange` helper.\n *\n * Items are stored on `extension.storage.items` so the prompt-line / shell\n * can swap the list at runtime without recreating the editor.\n */\n\nimport { Extension, type Editor } from '@tiptap/core';\n\nimport {\n dispatchTriggerChange,\n resetTriggerChangeState,\n} from './trigger-utils.js';\nimport type { SuggestionItem } from './types.js';\n\nexport interface StarterTriggerStorage {\n items: SuggestionItem[];\n isOn: boolean;\n}\n\n/** Read the starter trigger's live storage, or `undefined` if not installed. */\nexport function readStarterStorage(\n editor: Editor | null | undefined\n): StarterTriggerStorage | undefined {\n return (editor?.storage as unknown as Record<string, unknown> | undefined)\n ?.carbonStarterTrigger as StarterTriggerStorage | undefined;\n}\n\n/**\n * Apply a starter-config patch to the live editor. Starter differences never\n * justify recreating the editor — that would drop undo history — so they are\n * written in place. The empty transaction re-runs this extension's\n * `onTransaction` hook, so a toggle takes effect against the current selection\n * instead of waiting for the next keystroke. No-ops when nothing changed, so\n * callers do not have to guard.\n */\nexport function writeStarterStorage(\n editor: Editor | null | undefined,\n patch: Partial<StarterTriggerStorage>\n): void {\n const storage = readStarterStorage(editor);\n if (!editor || !storage) {\n return;\n }\n const entries = Object.entries(patch) as [\n keyof StarterTriggerStorage,\n StarterTriggerStorage[keyof StarterTriggerStorage],\n ][];\n if (entries.every(([key, value]) => storage[key] === value)) {\n return;\n }\n Object.assign(storage, patch);\n editor.view.dispatch(editor.state.tr);\n}\n\nexport function carbonStarterTrigger(\n initialItems: SuggestionItem[],\n initialIsOn = true\n): Extension {\n return Extension.create<unknown, StarterTriggerStorage>({\n name: 'carbonStarterTrigger',\n\n // Each editor gets fresh storage from here. Tiptap emits `create` a\n // macrotask later, so resetting storage there would drop a write the host\n // made in between.\n addStorage() {\n return { items: initialItems, isOn: initialIsOn };\n },\n\n onUpdate() {\n maybeEmit(this.editor);\n },\n\n onTransaction() {\n if (this.editor.isFocused) {\n maybeEmit(this.editor);\n }\n },\n\n onFocus({ editor }) {\n maybeEmit(editor);\n },\n\n onBlur({ editor }) {\n // Clear coalescing state on blur so the next focus can re-emit the\n // starter trigger even if the detail hasn't changed (e.g. after the\n // send button was clicked, which uses keepCoalesced: true on dismiss).\n resetTriggerChangeState(editor);\n },\n });\n}\n\nfunction maybeEmit(editor: Editor): void {\n const storage = readStarterStorage(editor);\n const isActive =\n storage?.isOn !== false &&\n (storage?.items.length ?? 0) > 0 &&\n editor.isEditable &&\n editor.isFocused &&\n editor.isEmpty;\n if (!isActive) {\n dispatchTriggerChange(editor, null);\n return;\n }\n dispatchTriggerChange(editor, {\n type: 'starter',\n query: '',\n triggerOffset: 0,\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;AAAA;;;;;;;AAOG;AAEH;;;;;;;AAOG;AAeH;AACM,SAAU,kBAAkB,CAChC,MAAiC,EAAA;IAEjC,OAAQ,MAAM,EAAE;AACd,UAAE,oBAAyD;AAC/D;AAEA;;;;;;;AAOG;AACG,SAAU,mBAAmB,CACjC,MAAiC,EACjC,KAAqC,EAAA;AAErC,IAAA,MAAM,OAAO,GAAG,kBAAkB,CAAC,MAAM,CAAC;AAC1C,IAAA,IAAI,CAAC,MAAM,IAAI,CAAC,OAAO,EAAE;QACvB;IACF;IACA,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAGjC;IACH,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,OAAO,C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F;IACA,qBAAqB,CAAC,MAAM,EAAE;AAC5B,QAAA,IAAI,EAAE,SAAS;AACf,QAAA,KAAK,EAAE,EAAE;AACT,QAAA,aAAa,EAAE,CAAC;AACjB,KAAA,CAAC;AACJ;;"}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* - `Mod-Enter` → emit `cds-custom-aichat-prompt-send-intent`. The shell decides
|
|
13
13
|
* whether to honor (re-dispatch as `cds-custom-aichat-input-send`) or gate
|
|
14
14
|
* (`isSendDisabled` per PLAN.md decision 19).
|
|
15
|
-
* - `Escape` →
|
|
15
|
+
* - `Escape` → no-op (returns `false`; host `<dialog>`/`Modal` sees it).
|
|
16
16
|
* - Plain `Enter` is not bound here. `<cds-custom-aichat-prompt-line>` adds
|
|
17
17
|
* `carbonChatEnter` to its base bundle for "Enter sends, Shift-Enter
|
|
18
18
|
* newlines"; this extension stays Enter-agnostic so it can be reused on its
|
|
@@ -21,7 +21,7 @@ import { Extension } from '@tiptap/core';
|
|
|
21
21
|
* - `Mod-Enter` → emit `cds-custom-aichat-prompt-send-intent`. The shell decides
|
|
22
22
|
* whether to honor (re-dispatch as `cds-custom-aichat-input-send`) or gate
|
|
23
23
|
* (`isSendDisabled` per PLAN.md decision 19).
|
|
24
|
-
* - `Escape` →
|
|
24
|
+
* - `Escape` → no-op (returns `false`; host `<dialog>`/`Modal` sees it).
|
|
25
25
|
* - Plain `Enter` is not bound here. `<cds-custom-aichat-prompt-line>` adds
|
|
26
26
|
* `carbonChatEnter` to its base bundle for "Enter sends, Shift-Enter
|
|
27
27
|
* newlines"; this extension stays Enter-agnostic so it can be reused on its
|
|
@@ -47,9 +47,8 @@ const Keymap = Extension.create({
|
|
|
47
47
|
}));
|
|
48
48
|
return true;
|
|
49
49
|
},
|
|
50
|
-
Escape: (
|
|
51
|
-
|
|
52
|
-
return true;
|
|
50
|
+
Escape: () => {
|
|
51
|
+
return false;
|
|
53
52
|
},
|
|
54
53
|
};
|
|
55
54
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keymap.js","sources":["../../../../../src/components/prompt-line/src/tiptap/keymap.ts"],"sourcesContent":["/**\n * @license\n *\n * Copyright IBM Corp. 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n/**\n * Tiptap keymap extension for the prompt-line.\n *\n * - `Mod-Enter` → emit `cds-custom-aichat-prompt-send-intent`. The shell decides\n * whether to honor (re-dispatch as `cds-custom-aichat-input-send`) or gate\n * (`isSendDisabled` per PLAN.md decision 19).\n * - `Escape` →
|
|
1
|
+
{"version":3,"file":"keymap.js","sources":["../../../../../src/components/prompt-line/src/tiptap/keymap.ts"],"sourcesContent":["/**\n * @license\n *\n * Copyright IBM Corp. 2026\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n/**\n * Tiptap keymap extension for the prompt-line.\n *\n * - `Mod-Enter` → emit `cds-custom-aichat-prompt-send-intent`. The shell decides\n * whether to honor (re-dispatch as `cds-custom-aichat-input-send`) or gate\n * (`isSendDisabled` per PLAN.md decision 19).\n * - `Escape` → no-op (returns `false`; host `<dialog>`/`Modal` sees it).\n * - Plain `Enter` is not bound here. `<cds-custom-aichat-prompt-line>` adds\n * `carbonChatEnter` to its base bundle for \"Enter sends, Shift-Enter\n * newlines\"; this extension stays Enter-agnostic so it can be reused on its\n * own.\n *\n * Undo / redo come from the `UndoRedo` extension. ArrowUp / ArrowDown /\n * Enter / Escape forwarding to the active autocomplete list is **not** done\n * here — the `AutocompleteController` (see ../autocomplete-controller.ts)\n * installs its own capture-phase keydown listener on the editor view DOM\n * when a trigger is active and a list element is registered, and\n * re-dispatches those keys on the list. The Tiptap suggestion factories\n * (`carbonMention`, `carbonAutocomplete`) deliberately return `false` from\n * `onKeyDown` so they don't consume those keys either.\n */\n\nimport { Extension } from '@tiptap/core';\n\nexport const Keymap = Extension.create({\n name: 'carbonChatKeymap',\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Enter': ({ editor }) => {\n editor.view.dom.dispatchEvent(\n new CustomEvent('cds-custom-aichat-prompt-send-intent', {\n bubbles: true,\n composed: true,\n })\n );\n return true;\n },\n Escape: () => {\n return false;\n },\n };\n },\n});\n"],"names":[],"mappings":";;;;;;;;;AAAA;;;;;;;AAOG;AAEH;;;;;;;;;;;;;;;;;;;;AAoBG;AAII,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;AACrC,IAAA,IAAI,EAAE,kBAAkB;IAExB,oBAAoB,GAAA;QAClB,OAAO;AACL,YAAA,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,KAAI;gBAC1B,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,aAAa,CAC3B,IAAI,WAAW,CAAC,+BAA+B,EAAE;AAC/C,oBAAA,OAAO,EAAE,IAAI;AACb,oBAAA,QAAQ,EAAE,IAAI;AACf,iBAAA,CAAC,CACH;AACD,gBAAA,OAAO,IAAI;YACb,CAAC;YACD,MAAM,EAAE,MAAK;AACX,gBAAA,OAAO,KAAK;YACd,CAAC;SACF;IACH,CAAC;AACF,CAAA;;"}
|
|
@@ -48,7 +48,6 @@ function renderTokenChip(args) {
|
|
|
48
48
|
result = renderer(item);
|
|
49
49
|
}
|
|
50
50
|
catch (error) {
|
|
51
|
-
// eslint-disable-next-line no-console
|
|
52
51
|
console.error('Error in renderCustomToken, falling back to default chip:', error);
|
|
53
52
|
dom.appendChild(createDefaultChip(args.attrs));
|
|
54
53
|
return dom;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-token-chip.js","sources":["../../../../../src/components/prompt-line/src/tiptap/render-token-chip.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 chip-rendering implementation used by both the editor's\n * `CarbonTokenNodeView` and the chat-side rich user message bubble. Builds\n * the wrapping `<span class=\"cds-custom-aichat--token\">` container, honors a\n * consumer-supplied `renderCustomToken`, and delegates the light-DOM portal\n * handshake to `renderInLightDom` so React adapters can hydrate custom chip\n * content. This is a thin token-specific wrapper over `renderInLightDom`.\n */\n\nimport type { ReactNode } from 'react';\n\nimport { setVarsForSelector } from '../../../shared/dynamic-css-var-sheet.js';\nimport { renderInLightDom } from './render-in-light-dom.js';\nimport type { SuggestionItem, TriggerSuggestionConfig } from './types.js';\n\nlet tokenStyleRulesInstalled = false;\n\nfunction ensureTokenStyleRules(): void {\n if (tokenStyleRulesInstalled) {\n return;\n }\n setVarsForSelector('.cds-custom-aichat--token', { 'white-space': 'normal' });\n setVarsForSelector('.cds-custom-aichat--token[data-token-context=\"composer\"]', {\n color: 'var(--cds-tag-color-blue, #0043ce)',\n });\n setVarsForSelector(\n '.cds-custom-aichat--token[data-token-context=\"composer\"]::selection',\n { 'background-color': 'var(--cds-tag-background-blue, #d0e2ff)' }\n );\n setVarsForSelector('.cds-custom-aichat--token[data-token-context=\"historical\"]', {\n color: 'var(--cds-link-secondary, #0043ce)',\n });\n tokenStyleRulesInstalled = true;\n}\n\n/**\n * Attributes carried by a mention/command JSONContent node. Matches the\n * Tiptap mention shape (`id`, `label`) plus the carbon-specific `value`,\n * `data`, and `trigger` extensions added by `carbonMention`/`carbonCommand`.\n */\nexport interface TokenChipAttrs {\n /** Identifier of the item the chip came from. */\n id?: string;\n /** Text shown on the chip. */\n label?: string;\n /**\n * String the chip contributes to the message text. Falls back to `label`\n * when unset.\n */\n value?: string;\n /**\n * Custom fields carried over from the selected item. Everything the\n * suggestion item held beyond `id`, `label`, `value`, `avatar`,\n * `description`, `disabled`, and `showTriggerInChip` lands here, so it\n * survives a round trip through the editor's JSON.\n */\n data?: unknown;\n /**\n * Trigger character to prefix onto the default chip text (e.g.\n * `/summarize` vs `summarize`). Set at insert time by\n * `resolveShowTriggerInChip` — defaults to command nodes only, but is\n * overridable per-config or per-item via `TriggerSuggestionConfig`/\n * `SuggestionItem`'s `showTriggerInChip`.\n */\n trigger?: string | null;\n}\n\nexport interface RenderTokenChipArgs {\n /** Node attrs in mention shape. */\n attrs: TokenChipAttrs;\n /**\n * Subset of the trigger-suggestion config relevant to chip rendering. Only\n * `renderCustomToken` is read; other config fields are ignored.\n */\n config?: Pick<TriggerSuggestionConfig, 'renderCustomToken'>;\n /** Token type — usually `\"mention\"` or `\"command\"`. */\n type: 'mention' | 'command' | string;\n /**\n * Where to dispatch the light-DOM portal event when `renderCustomToken`\n * returns custom content. The NodeView passes the editor's `view.dom`\n * (already mounted under the chat wrapper) so the event reaches the portal\n * listener synchronously. When omitted, the event fires from the portal\n * container element itself with `bubbles: true, composed: true` — callers\n * that mount the chip lazily must ensure it lives under a listener subtree\n * before connection.\n */\n dispatchTarget?: EventTarget;\n /**\n * Visual variant to render. `\"composer\"` is the live, being-typed token in\n * the prompt-line editor; `\"historical\"` is a token inside an already-sent\n * message in the transcript. Drives the default chip's color/highlight —\n * see `ensureTokenStyleRules`.\n */\n context: 'composer' | 'historical';\n}\n\nexport function renderTokenChip(args: RenderTokenChipArgs): HTMLElement {\n const dom = createTokenContainer(args.attrs, args.type, args.context);\n const renderer = args.config?.renderCustomToken;\n\n if (!renderer) {\n dom.appendChild(createDefaultChip(args.attrs));\n return dom;\n }\n\n const item: SuggestionItem = {\n id: typeof args.attrs.id === 'string' ? args.attrs.id : '',\n label: typeof args.attrs.label === 'string' ? args.attrs.label : '',\n ...((args.attrs.data ?? {}) as Record<string, unknown>),\n };\n\n let result: HTMLElement | ReactNode | undefined;\n try {\n result = renderer(item);\n } catch (error) {\n
|
|
1
|
+
{"version":3,"file":"render-token-chip.js","sources":["../../../../../src/components/prompt-line/src/tiptap/render-token-chip.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 chip-rendering implementation used by both the editor's\n * `CarbonTokenNodeView` and the chat-side rich user message bubble. Builds\n * the wrapping `<span class=\"cds-custom-aichat--token\">` container, honors a\n * consumer-supplied `renderCustomToken`, and delegates the light-DOM portal\n * handshake to `renderInLightDom` so React adapters can hydrate custom chip\n * content. This is a thin token-specific wrapper over `renderInLightDom`.\n */\n\nimport type { ReactNode } from 'react';\n\nimport { setVarsForSelector } from '../../../shared/dynamic-css-var-sheet.js';\nimport { renderInLightDom } from './render-in-light-dom.js';\nimport type { SuggestionItem, TriggerSuggestionConfig } from './types.js';\n\nlet tokenStyleRulesInstalled = false;\n\nfunction ensureTokenStyleRules(): void {\n if (tokenStyleRulesInstalled) {\n return;\n }\n setVarsForSelector('.cds-custom-aichat--token', { 'white-space': 'normal' });\n setVarsForSelector('.cds-custom-aichat--token[data-token-context=\"composer\"]', {\n color: 'var(--cds-tag-color-blue, #0043ce)',\n });\n setVarsForSelector(\n '.cds-custom-aichat--token[data-token-context=\"composer\"]::selection',\n { 'background-color': 'var(--cds-tag-background-blue, #d0e2ff)' }\n );\n setVarsForSelector('.cds-custom-aichat--token[data-token-context=\"historical\"]', {\n color: 'var(--cds-link-secondary, #0043ce)',\n });\n tokenStyleRulesInstalled = true;\n}\n\n/**\n * Attributes carried by a mention/command JSONContent node. Matches the\n * Tiptap mention shape (`id`, `label`) plus the carbon-specific `value`,\n * `data`, and `trigger` extensions added by `carbonMention`/`carbonCommand`.\n */\nexport interface TokenChipAttrs {\n /** Identifier of the item the chip came from. */\n id?: string;\n /** Text shown on the chip. */\n label?: string;\n /**\n * String the chip contributes to the message text. Falls back to `label`\n * when unset.\n */\n value?: string;\n /**\n * Custom fields carried over from the selected item. Everything the\n * suggestion item held beyond `id`, `label`, `value`, `avatar`,\n * `description`, `disabled`, and `showTriggerInChip` lands here, so it\n * survives a round trip through the editor's JSON.\n */\n data?: unknown;\n /**\n * Trigger character to prefix onto the default chip text (e.g.\n * `/summarize` vs `summarize`). Set at insert time by\n * `resolveShowTriggerInChip` — defaults to command nodes only, but is\n * overridable per-config or per-item via `TriggerSuggestionConfig`/\n * `SuggestionItem`'s `showTriggerInChip`.\n */\n trigger?: string | null;\n}\n\nexport interface RenderTokenChipArgs {\n /** Node attrs in mention shape. */\n attrs: TokenChipAttrs;\n /**\n * Subset of the trigger-suggestion config relevant to chip rendering. Only\n * `renderCustomToken` is read; other config fields are ignored.\n */\n config?: Pick<TriggerSuggestionConfig, 'renderCustomToken'>;\n /** Token type — usually `\"mention\"` or `\"command\"`. */\n type: 'mention' | 'command' | string;\n /**\n * Where to dispatch the light-DOM portal event when `renderCustomToken`\n * returns custom content. The NodeView passes the editor's `view.dom`\n * (already mounted under the chat wrapper) so the event reaches the portal\n * listener synchronously. When omitted, the event fires from the portal\n * container element itself with `bubbles: true, composed: true` — callers\n * that mount the chip lazily must ensure it lives under a listener subtree\n * before connection.\n */\n dispatchTarget?: EventTarget;\n /**\n * Visual variant to render. `\"composer\"` is the live, being-typed token in\n * the prompt-line editor; `\"historical\"` is a token inside an already-sent\n * message in the transcript. Drives the default chip's color/highlight —\n * see `ensureTokenStyleRules`.\n */\n context: 'composer' | 'historical';\n}\n\nexport function renderTokenChip(args: RenderTokenChipArgs): HTMLElement {\n const dom = createTokenContainer(args.attrs, args.type, args.context);\n const renderer = args.config?.renderCustomToken;\n\n if (!renderer) {\n dom.appendChild(createDefaultChip(args.attrs));\n return dom;\n }\n\n const item: SuggestionItem = {\n id: typeof args.attrs.id === 'string' ? args.attrs.id : '',\n label: typeof args.attrs.label === 'string' ? args.attrs.label : '',\n ...((args.attrs.data ?? {}) as Record<string, unknown>),\n };\n\n let result: HTMLElement | ReactNode | undefined;\n try {\n result = renderer(item);\n } catch (error) {\n console.error(\n 'Error in renderCustomToken, falling back to default chip:',\n error\n );\n dom.appendChild(createDefaultChip(args.attrs));\n return dom;\n }\n\n if (result == null) {\n dom.appendChild(createDefaultChip(args.attrs));\n return dom;\n }\n\n // Bridge the custom chip into the page's light DOM via the shared portal\n // handshake. The default chip rides along as the `<slot>` fallback so the\n // token still shows something until the portal commits.\n const { container } = renderInLightDom({\n content: result,\n dispatchTarget: args.dispatchTarget ?? dom,\n fallback: createDefaultChip(args.attrs),\n });\n dom.appendChild(container);\n\n return dom;\n}\n\nfunction createTokenContainer(\n attrs: TokenChipAttrs,\n type: string,\n context: 'composer' | 'historical'\n): HTMLElement {\n ensureTokenStyleRules();\n const dom = document.createElement('span');\n const value = typeof attrs.value === 'string' ? attrs.value : null;\n const label = typeof attrs.label === 'string' ? attrs.label : null;\n dom.setAttribute('contenteditable', 'false');\n dom.setAttribute('data-token-type', type);\n dom.setAttribute('data-token-context', context);\n dom.setAttribute('data-raw-value', value ?? label ?? '');\n dom.className = 'cds-custom-aichat--token';\n return dom;\n}\n\nfunction createDefaultChip(attrs: TokenChipAttrs): HTMLElement {\n const chip = document.createElement('span');\n const label = typeof attrs.label === 'string' ? attrs.label : null;\n const value = typeof attrs.value === 'string' ? attrs.value : null;\n const trigger = typeof attrs.trigger === 'string' ? attrs.trigger : '';\n chip.textContent = `${trigger}${label || value || ''}`;\n return chip;\n}\n"],"names":[],"mappings":";;;;;;;;;;AAAA;;;;;;;AAOG;AAiBH,IAAI,wBAAwB,GAAG,KAAK;AAEpC,SAAS,qBAAqB,GAAA;IAC5B,IAAI,wBAAwB,EAAE;QAC5B;IACF;IACA,kBAAkB,CAAC,oBAAoB,EAAE,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC;IACrE,kBAAkB,CAAC,mDAAmD,EAAE;AACtE,QAAA,KAAK,EAAE,oCAAoC;AAC5C,KAAA,CAAC;IACF,kBAAkB,CAChB,8DAA8D,EAC9D,EAAE,kBAAkB,EAAE,yCAAyC,EAAE,CAClE;IACD,kBAAkB,CAAC,qDAAqD,EAAE;AACxE,QAAA,KAAK,EAAE,oCAAoC;AAC5C,KAAA,CAAC;IACF,wBAAwB,GAAG,IAAI;AACjC;AA+DM,SAAU,eAAe,CAAC,IAAyB,EAAA;AACvD,IAAA,MAAM,GAAG,GAAG,oBAAoB,CAAC,IAAI,CA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AAA,IAAI,CAAC,WAAW,GAAG,CAAA,EAAG,OAAO,CAAA,EAAG,KAAK,IAAI,KAAK,IAAI,EAAE,CAAA,CAAE;AACtD,IAAA,OAAO,IAAI;AACb;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 resolver for BaseSuggestionConfig items: applies minQueryLength
|
|
11
|
+
* gating, delegates to the async function or filters the static array.
|
|
12
|
+
* Used by AutocompleteController — the canonical resolution path.
|
|
13
|
+
*/
|
|
14
|
+
import type { SuggestionItem } from './types.js';
|
|
15
|
+
export declare function resolveConfigItems(config: {
|
|
16
|
+
items: SuggestionItem[] | ((query: string) => Promise<SuggestionItem[]> | SuggestionItem[]);
|
|
17
|
+
minQueryLength?: number;
|
|
18
|
+
}, query: string): Promise<SuggestionItem[]>;
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
async function resolveConfigItems(config, query) {
|
|
17
|
+
const minQueryLength = config.minQueryLength ?? 0;
|
|
18
|
+
if (query.length < minQueryLength) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
if (typeof config.items === 'function') {
|
|
22
|
+
return await Promise.resolve(config.items(query));
|
|
23
|
+
}
|
|
24
|
+
if (!query) {
|
|
25
|
+
return config.items;
|
|
26
|
+
}
|
|
27
|
+
const lower = query.toLowerCase();
|
|
28
|
+
return config.items.filter((item) => item.label.toLowerCase().includes(lower));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { resolveConfigItems };
|
|
32
|
+
//# sourceMappingURL=resolve-config-items.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-config-items.js","sources":["../../../../../src/components/prompt-line/src/tiptap/resolve-config-items.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 resolver for BaseSuggestionConfig items: applies minQueryLength\n * gating, delegates to the async function or filters the static array.\n * Used by AutocompleteController — the canonical resolution path.\n */\n\nimport type { SuggestionItem } from './types.js';\n\nexport async function resolveConfigItems(\n config: {\n items:\n | SuggestionItem[]\n | ((query: string) => Promise<SuggestionItem[]> | SuggestionItem[]);\n minQueryLength?: number;\n },\n query: string\n): Promise<SuggestionItem[]> {\n const minQueryLength = config.minQueryLength ?? 0;\n if (query.length < minQueryLength) {\n return [];\n }\n if (typeof config.items === 'function') {\n return await Promise.resolve(config.items(query));\n }\n if (!query) {\n return config.items;\n }\n const lower = query.toLowerCase();\n return config.items.filter((item) =>\n item.label.toLowerCase().includes(lower)\n );\n}\n"],"names":[],"mappings":";;;;;;;AAAA;;;;;;;AAOG;AAUI,eAAe,kBAAkB,CACtC,MAKC,EACD,KAAa,EAAA;AAEb,IAAA,MAAM,cAAc,GAAG,MAAM,CAAC,cAAc,IAAI,CAAC;AACjD,IAAA,IAAI,KAAK,CAAC,MAAM,GAAG,cAAc,EAAE;AACjC,QAAA,OAAO,EAAE;IACX;AACA,IAAA,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,UAAU,EAAE;AACtC,QAAA,OAAO,MAAM,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACnD;IACA,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,MAAM,CAAC,KAAK;IACrB;AACA,IAAA,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,EAAE;IACjC,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,KAC9B,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CACzC;AACH;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
* Drops the fields a chip renders from its own attrs: `id`, `label`, `value`,
|
|
11
|
+
* and the presentation-only `avatar`, `description`, `disabled`, and
|
|
12
|
+
* `showTriggerInChip`. Grouping metadata (`groupId`, `groupTitle`) survives,
|
|
13
|
+
* matching what `TriggerSuggestionConfig.onRemove` documents as retained.
|
|
14
|
+
* Used by AutocompleteController at insert time to fill the token node's
|
|
15
|
+
* `data` attr, so `onRemove` can hand those fields back.
|
|
16
|
+
*/
|
|
17
|
+
import type { SuggestionItem } from './types.js';
|
|
18
|
+
export declare function stripPresentationFields(item: SuggestionItem): Record<string, unknown>;
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
function stripPresentationFields(item) {
|
|
17
|
+
const { id: _id, label: _label, value: _value, avatar: _avatar, description: _description, disabled: _disabled, showTriggerInChip: _showTriggerInChip, ...rest } = item;
|
|
18
|
+
return rest;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { stripPresentationFields };
|
|
22
|
+
//# sourceMappingURL=strip-presentation-fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strip-presentation-fields.js","sources":["../../../../../src/components/prompt-line/src/tiptap/strip-presentation-fields.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 * Drops the fields a chip renders from its own attrs: `id`, `label`, `value`,\n * and the presentation-only `avatar`, `description`, `disabled`, and\n * `showTriggerInChip`. Grouping metadata (`groupId`, `groupTitle`) survives,\n * matching what `TriggerSuggestionConfig.onRemove` documents as retained.\n * Used by AutocompleteController at insert time to fill the token node's\n * `data` attr, so `onRemove` can hand those fields back.\n */\n\nimport type { SuggestionItem } from './types.js';\n\nexport function stripPresentationFields(\n item: SuggestionItem\n): Record<string, unknown> {\n const {\n id: _id,\n label: _label,\n value: _value,\n avatar: _avatar,\n description: _description,\n disabled: _disabled,\n showTriggerInChip: _showTriggerInChip,\n ...rest\n } = item;\n void _id;\n void _label;\n void _value;\n void _avatar;\n void _description;\n void _disabled;\n void _showTriggerInChip;\n return rest;\n}\n"],"names":[],"mappings":";;;;;;;AAAA;;;;;;;AAOG;AAaG,SAAU,uBAAuB,CACrC,IAAoB,EAAA;AAEpB,IAAA,MAAM,EACJ,EAAE,EAAE,GAAG,EACP,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,YAAY,EACzB,QAAQ,EAAE,SAAS,EACnB,iBAAiB,EAAE,kBAAkB,EACrC,GAAG,IAAI,EACR,GAAG,IAAI;AAQR,IAAA,OAAO,IAAI;AACb;;"}
|
|
@@ -12,13 +12,12 @@
|
|
|
12
12
|
* bridge extension (per PLAN.md decision 4) — each factory calls this helper
|
|
13
13
|
* from its own `onStart`/`onUpdate`/`onExit` callbacks.
|
|
14
14
|
*
|
|
15
|
-
* **Concurrent transitions:**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* range was actually exited.
|
|
15
|
+
* **Concurrent transitions:** when two factories transition in the same
|
|
16
|
+
* synchronous turn (e.g. autocomplete exits while mention starts), plugin
|
|
17
|
+
* view updates run in extension-registration order. The later `onExit`
|
|
18
|
+
* (dispatching `null`) must not overwrite the earlier `onStart` from a
|
|
19
|
+
* different plugin. Pass `exitingType` when calling with `null` so the helper
|
|
20
|
+
* can detect and suppress that stale exit.
|
|
22
21
|
*/
|
|
23
22
|
import type { Editor } from '@tiptap/core';
|
|
24
23
|
import type { TriggerChangeEventDetail } from './types.js';
|
|
@@ -26,8 +25,13 @@ import type { TriggerChangeEventDetail } from './types.js';
|
|
|
26
25
|
* Dispatch `cds-custom-aichat-trigger-change` on the editor's DOM if the detail has
|
|
27
26
|
* changed since the last call for the same editor. No-op transitions are
|
|
28
27
|
* coalesced.
|
|
28
|
+
*
|
|
29
|
+
* When `detail` is `null` (an `onExit` call), pass `exitingType` so the
|
|
30
|
+
* helper can suppress the exit if another plugin already claimed the trigger
|
|
31
|
+
* in the same synchronous turn — preventing a late `onExit` from overwriting
|
|
32
|
+
* an earlier `onStart` from a different extension.
|
|
29
33
|
*/
|
|
30
|
-
export declare function dispatchTriggerChange(editor: Editor, detail: TriggerChangeEventDetail | null): void;
|
|
34
|
+
export declare function dispatchTriggerChange(editor: Editor, detail: TriggerChangeEventDetail | null, exitingType?: string): void;
|
|
31
35
|
/**
|
|
32
36
|
* Reset the coalescing state for an editor. Call this when the controller
|
|
33
37
|
* dismisses a trigger externally (not via the extension) so that the next
|
|
@@ -18,9 +18,24 @@ const lastDetailByEditor = new WeakMap();
|
|
|
18
18
|
* Dispatch `cds-custom-aichat-trigger-change` on the editor's DOM if the detail has
|
|
19
19
|
* changed since the last call for the same editor. No-op transitions are
|
|
20
20
|
* coalesced.
|
|
21
|
+
*
|
|
22
|
+
* When `detail` is `null` (an `onExit` call), pass `exitingType` so the
|
|
23
|
+
* helper can suppress the exit if another plugin already claimed the trigger
|
|
24
|
+
* in the same synchronous turn — preventing a late `onExit` from overwriting
|
|
25
|
+
* an earlier `onStart` from a different extension.
|
|
21
26
|
*/
|
|
22
|
-
function dispatchTriggerChange(editor, detail) {
|
|
27
|
+
function dispatchTriggerChange(editor, detail, exitingType) {
|
|
23
28
|
const previous = lastDetailByEditor.get(editor) ?? null;
|
|
29
|
+
// Suppress a null dispatch when a different plugin already activated in this
|
|
30
|
+
// turn — its onStart updated lastDetail to a non-null value with a different
|
|
31
|
+
// type, so this onExit is stale.
|
|
32
|
+
const isStaleExit = detail === null &&
|
|
33
|
+
exitingType !== undefined &&
|
|
34
|
+
previous !== null &&
|
|
35
|
+
previous.type !== exitingType;
|
|
36
|
+
if (isStaleExit) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
24
39
|
if (areDetailsEqual(previous, detail)) {
|
|
25
40
|
return;
|
|
26
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trigger-utils.js","sources":["../../../../../src/components/prompt-line/src/tiptap/trigger-utils.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 helper for the carbon factories' suggestion-render lifecycles to\n * dispatch `cds-custom-aichat-trigger-change` events directly. There is no central\n * bridge extension (per PLAN.md decision 4) — each factory calls this helper\n * from its own `onStart`/`onUpdate`/`onExit` callbacks.\n *\n * **Concurrent transitions:**
|
|
1
|
+
{"version":3,"file":"trigger-utils.js","sources":["../../../../../src/components/prompt-line/src/tiptap/trigger-utils.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 helper for the carbon factories' suggestion-render lifecycles to\n * dispatch `cds-custom-aichat-trigger-change` events directly. There is no central\n * bridge extension (per PLAN.md decision 4) — each factory calls this helper\n * from its own `onStart`/`onUpdate`/`onExit` callbacks.\n *\n * **Concurrent transitions:** when two factories transition in the same\n * synchronous turn (e.g. autocomplete exits while mention starts), plugin\n * view updates run in extension-registration order. The later `onExit`\n * (dispatching `null`) must not overwrite the earlier `onStart` from a\n * different plugin. Pass `exitingType` when calling with `null` so the helper\n * can detect and suppress that stale exit.\n */\n\nimport type { Editor } from '@tiptap/core';\n\nimport type { TriggerChangeEventDetail } from './types.js';\n\nconst lastDetailByEditor = new WeakMap<\n Editor,\n TriggerChangeEventDetail | null\n>();\n\n/**\n * Dispatch `cds-custom-aichat-trigger-change` on the editor's DOM if the detail has\n * changed since the last call for the same editor. No-op transitions are\n * coalesced.\n *\n * When `detail` is `null` (an `onExit` call), pass `exitingType` so the\n * helper can suppress the exit if another plugin already claimed the trigger\n * in the same synchronous turn — preventing a late `onExit` from overwriting\n * an earlier `onStart` from a different extension.\n */\nexport function dispatchTriggerChange(\n editor: Editor,\n detail: TriggerChangeEventDetail | null,\n exitingType?: string\n): void {\n const previous = lastDetailByEditor.get(editor) ?? null;\n // Suppress a null dispatch when a different plugin already activated in this\n // turn — its onStart updated lastDetail to a non-null value with a different\n // type, so this onExit is stale.\n const isStaleExit =\n detail === null &&\n exitingType !== undefined &&\n previous !== null &&\n previous.type !== exitingType;\n if (isStaleExit) {\n return;\n }\n if (areDetailsEqual(previous, detail)) {\n return;\n }\n lastDetailByEditor.set(editor, detail);\n editor.view.dom.dispatchEvent(\n new CustomEvent('cds-custom-aichat-trigger-change', {\n detail,\n bubbles: true,\n composed: true,\n })\n );\n}\n\n/**\n * Reset the coalescing state for an editor. Call this when the controller\n * dismisses a trigger externally (not via the extension) so that the next\n * `dispatchTriggerChange` call for the same detail re-dispatches instead of\n * being swallowed as a no-op.\n */\nexport function resetTriggerChangeState(editor: Editor): void {\n lastDetailByEditor.delete(editor);\n}\n\nfunction areDetailsEqual(\n a: TriggerChangeEventDetail | null,\n b: TriggerChangeEventDetail | null\n): boolean {\n if (a === null || b === null) {\n return a === b;\n }\n return (\n a.type === b.type &&\n a.query === b.query &&\n a.triggerOffset === b.triggerOffset\n );\n}\n"],"names":[],"mappings":";;;;;;;AAAA;;;;;;;AAOG;AAoBH,MAAM,kBAAkB,GAAG,IAAI,OAAO,EAGnC;AAEH;;;;;;;;;AASG;SACa,qBAAqB,CACnC,MAAc,EACd,MAAuC,EACvC,WAAoB,EAAA;IAEpB,MAAM,QAAQ,GAAG,kBAAkB,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI;;;;AAIvD,IAAA,MAAM,WAAW,GACf,MAAM,KAAK,IAAI;AACf,QAAA,WAAW,KAAK,SAAS;AACzB,QAAA,QAAQ,KAAK,IAAI;AACjB,QAAA,QAAQ,CAAC,IAAI,KAAK,WAAW;IAC/B,IAAI,WAAW,EAAE;QACf;IACF;AACA,IAAA,IAAI,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE;QACrC;IACF;AACA,IAAA,kBAAkB,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IACtC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,aAAa,CAC3B,IAAI,WAAW,CAAC,2BAA2B,EAAE;QAC3C,MAAM;AACN,QAAA,OAAO,EAAE,IAAI;AACb,QAAA,QAAQ,EAAE,IAAI;AACf,KAAA,CAAC,CACH;AACH;AAEA;;;;;AAKG;AACG,SAAU,uBAAuB,CAAC,MAAc,EAAA;AACpD,IAAA,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC;AACnC;AAEA,SAAS,eAAe,CACtB,CAAkC,EAClC,CAAkC,EAAA;IAElC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI,EAAE;QAC5B,OAAO,CAAC,KAAK,CAAC;IAChB;AACA,IAAA,QACE,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI;AACjB,QAAA,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK;AACnB,QAAA,CAAC,CAAC,aAAa,KAAK,CAAC,CAAC,aAAa;AAEvC;;"}
|
|
@@ -102,12 +102,20 @@ export interface CustomListProps {
|
|
|
102
102
|
*/
|
|
103
103
|
export interface BaseSuggestionConfig {
|
|
104
104
|
/**
|
|
105
|
-
* Static item list or async function called with the current query
|
|
105
|
+
* Static item list, or an async function called with the current query
|
|
106
|
+
* string. Resolved by the autocomplete controller once per query change —
|
|
107
|
+
* the Tiptap extensions never call it.
|
|
106
108
|
*/
|
|
107
109
|
items: SuggestionItem[] | ((query: string) => Promise<SuggestionItem[]> | SuggestionItem[]);
|
|
108
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* Minimum query length before `items()` is called. Defaults to 0. Applied
|
|
112
|
+
* by the autocomplete controller, which owns resolution for every trigger.
|
|
113
|
+
*/
|
|
109
114
|
minQueryLength?: number;
|
|
110
|
-
/**
|
|
115
|
+
/**
|
|
116
|
+
* Called after the user selects an item and the controller has finished
|
|
117
|
+
* inserting it.
|
|
118
|
+
*/
|
|
111
119
|
onSelect?: (item: SuggestionItem) => void;
|
|
112
120
|
/** Replace the built-in suggestion list UI. */
|
|
113
121
|
renderCustomList?: (props: CustomListProps) => HTMLElement | unknown;
|
|
@@ -27,6 +27,13 @@ export interface Action extends BaseOverflowMenuItem {
|
|
|
27
27
|
* When overflow handling is enabled, setting fixed to true will force this action out of the overflow menu.
|
|
28
28
|
*/
|
|
29
29
|
fixed?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Renders this action as a two-state toggle and sets its current state.
|
|
32
|
+
* When `true` or `false`, the button exposes `aria-pressed` and a visible
|
|
33
|
+
* pressed treatment. Omit the field for a plain button with no toggle
|
|
34
|
+
* semantics — `undefined` is intentionally distinct from `false`.
|
|
35
|
+
*/
|
|
36
|
+
isSelected?: boolean;
|
|
30
37
|
}
|
|
31
38
|
/**
|
|
32
39
|
* Toolbar.
|
|
@@ -54,6 +61,7 @@ declare class CDSAIChatToolbar extends LitElement {
|
|
|
54
61
|
connectedCallback(): void;
|
|
55
62
|
disconnectedCallback(): void;
|
|
56
63
|
firstUpdated(): void;
|
|
64
|
+
updated(): void;
|
|
57
65
|
private sortActions;
|
|
58
66
|
private setupResizeObserver;
|
|
59
67
|
private getActions;
|