@carbon/ai-chat-components 1.11.0 → 1.12.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/custom-elements.json +2414 -2161
- package/es/components/card/src/card-footer.scss.js +1 -1
- package/es/components/card/src/card-steps.scss.js +1 -1
- package/es/components/card/src/card.scss.js +1 -1
- package/es/components/chat-button/src/chat-button.scss.js +1 -1
- package/es/components/chat-history/src/history-panel-item-input.js +0 -1
- package/es/components/chat-history/src/history-panel-item-input.js.map +1 -1
- package/es/components/code-snippet/src/codemirror/language-controller.js +1 -1
- package/es/components/code-snippet/src/codemirror/language-controller.js.map +1 -1
- package/es/components/file-uploads/src/file-upload-item.d.ts +14 -1
- package/es/components/file-uploads/src/file-upload-item.js +78 -2
- package/es/components/file-uploads/src/file-upload-item.js.map +1 -1
- package/es/components/file-uploads/src/file-uploads.d.ts +29 -4
- package/es/components/file-uploads/src/file-uploads.js +69 -16
- package/es/components/file-uploads/src/file-uploads.js.map +1 -1
- package/es/components/launcher/src/launcher.scss.js +1 -1
- package/es/components/prompt-line/index.d.ts +3 -2
- package/es/components/prompt-line/index.js +2 -1
- package/es/components/prompt-line/index.js.map +1 -1
- package/es/components/prompt-line/src/__tests__/wait-for-rich.d.ts +20 -0
- package/es/components/prompt-line/src/autocomplete-controller-element.d.ts +68 -0
- package/es/components/prompt-line/src/autocomplete-controller-element.js +221 -0
- package/es/components/prompt-line/src/autocomplete-controller-element.js.map +1 -0
- package/es/components/prompt-line/src/autocomplete-controller.d.ts +10 -69
- package/es/components/prompt-line/src/autocomplete-controller.js +44 -251
- package/es/components/prompt-line/src/autocomplete-controller.js.map +1 -1
- package/es/components/prompt-line/src/prompt-line-rich-runtime.js +3 -0
- package/es/components/prompt-line/src/prompt-line-rich-runtime.js.map +1 -1
- package/es/components/prompt-line/src/prompt-line-shell.scss.js +1 -1
- package/es/components/prompt-line/src/prompt-line-textarea-runtime.js +0 -5
- package/es/components/prompt-line/src/prompt-line-textarea-runtime.js.map +1 -1
- package/es/components/prompt-line/src/prompt-line.js +1 -1
- package/es/components/prompt-line/src/prompt-line.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/build-extensions.js +1 -1
- package/es/components/prompt-line/src/tiptap/build-extensions.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/carbon-autocomplete.d.ts +5 -6
- package/es/components/prompt-line/src/tiptap/carbon-autocomplete.js +4 -28
- package/es/components/prompt-line/src/tiptap/carbon-autocomplete.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/carbon-mention.js +13 -47
- package/es/components/prompt-line/src/tiptap/carbon-mention.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/carbon-starter-trigger.js +3 -4
- package/es/components/prompt-line/src/tiptap/carbon-starter-trigger.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/keymap.d.ts +1 -1
- package/es/components/prompt-line/src/tiptap/keymap.js +3 -4
- package/es/components/prompt-line/src/tiptap/keymap.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/render-token-chip.js +0 -1
- package/es/components/prompt-line/src/tiptap/render-token-chip.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/resolve-config-items.d.ts +18 -0
- package/es/components/prompt-line/src/tiptap/resolve-config-items.js +32 -0
- package/es/components/prompt-line/src/tiptap/resolve-config-items.js.map +1 -0
- package/es/components/prompt-line/src/tiptap/strip-presentation-fields.d.ts +18 -0
- package/es/components/prompt-line/src/tiptap/strip-presentation-fields.js +22 -0
- package/es/components/prompt-line/src/tiptap/strip-presentation-fields.js.map +1 -0
- package/es/components/prompt-line/src/tiptap/types.d.ts +11 -3
- package/es/components/toolbar/src/toolbar.d.ts +8 -0
- package/es/components/toolbar/src/toolbar.js +65 -19
- package/es/components/toolbar/src/toolbar.js.map +1 -1
- package/es/components/video-player/src/providers/vimeo-provider.js +1 -1
- package/es/components/video-player/src/providers/vimeo-provider.js.map +1 -1
- package/es/globals/decorators/carbon-element.js +2 -3
- package/es/globals/decorators/carbon-element.js.map +1 -1
- package/es/globals/utils/aria-announcer-manager.d.ts +56 -0
- package/es/globals/utils/aria-announcer-manager.js +46 -1
- package/es/globals/utils/aria-announcer-manager.js.map +1 -1
- package/es/globals/utils/focus-utils.js +1 -3
- package/es/globals/utils/focus-utils.js.map +1 -1
- package/es/globals/utils/iconTransform.d.ts +16 -2
- package/es/globals/utils/iconTransform.js +22 -1
- package/es/globals/utils/iconTransform.js.map +1 -1
- package/es/react/hooks/useChatAutocomplete.js.map +1 -1
- package/es/react/markdown.js +0 -1
- package/es/react/markdown.js.map +1 -1
- package/es/typings/overflow-menu.d.ts +4 -0
- package/es-custom/components/card/src/card-footer.scss.js +1 -1
- package/es-custom/components/card/src/card-steps.scss.js +1 -1
- package/es-custom/components/card/src/card.scss.js +1 -1
- package/es-custom/components/chat-button/src/chat-button.scss.js +1 -1
- package/es-custom/components/chat-history/src/history-panel-item-input.js +0 -1
- package/es-custom/components/chat-history/src/history-panel-item-input.js.map +1 -1
- package/es-custom/components/code-snippet/src/codemirror/language-controller.js +1 -1
- package/es-custom/components/code-snippet/src/codemirror/language-controller.js.map +1 -1
- package/es-custom/components/file-uploads/src/file-upload-item.d.ts +14 -1
- package/es-custom/components/file-uploads/src/file-upload-item.js +78 -2
- package/es-custom/components/file-uploads/src/file-upload-item.js.map +1 -1
- package/es-custom/components/file-uploads/src/file-uploads.d.ts +29 -4
- package/es-custom/components/file-uploads/src/file-uploads.js +69 -16
- package/es-custom/components/file-uploads/src/file-uploads.js.map +1 -1
- package/es-custom/components/launcher/src/launcher.scss.js +1 -1
- package/es-custom/components/prompt-line/index.d.ts +3 -2
- package/es-custom/components/prompt-line/index.js +2 -1
- package/es-custom/components/prompt-line/index.js.map +1 -1
- package/es-custom/components/prompt-line/src/__tests__/wait-for-rich.d.ts +20 -0
- package/es-custom/components/prompt-line/src/autocomplete-controller-element.d.ts +68 -0
- package/es-custom/components/prompt-line/src/autocomplete-controller-element.js +221 -0
- package/es-custom/components/prompt-line/src/autocomplete-controller-element.js.map +1 -0
- package/es-custom/components/prompt-line/src/autocomplete-controller.d.ts +10 -69
- package/es-custom/components/prompt-line/src/autocomplete-controller.js +44 -251
- package/es-custom/components/prompt-line/src/autocomplete-controller.js.map +1 -1
- package/es-custom/components/prompt-line/src/prompt-line-rich-runtime.js +3 -0
- package/es-custom/components/prompt-line/src/prompt-line-rich-runtime.js.map +1 -1
- package/es-custom/components/prompt-line/src/prompt-line-shell.scss.js +1 -1
- package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.js +0 -5
- package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.js.map +1 -1
- package/es-custom/components/prompt-line/src/prompt-line.js +1 -1
- package/es-custom/components/prompt-line/src/prompt-line.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/build-extensions.js +1 -1
- package/es-custom/components/prompt-line/src/tiptap/build-extensions.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/carbon-autocomplete.d.ts +5 -6
- package/es-custom/components/prompt-line/src/tiptap/carbon-autocomplete.js +4 -28
- package/es-custom/components/prompt-line/src/tiptap/carbon-autocomplete.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/carbon-mention.js +13 -47
- package/es-custom/components/prompt-line/src/tiptap/carbon-mention.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/carbon-starter-trigger.js +3 -4
- package/es-custom/components/prompt-line/src/tiptap/carbon-starter-trigger.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/keymap.d.ts +1 -1
- package/es-custom/components/prompt-line/src/tiptap/keymap.js +3 -4
- package/es-custom/components/prompt-line/src/tiptap/keymap.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/render-token-chip.js +0 -1
- package/es-custom/components/prompt-line/src/tiptap/render-token-chip.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/resolve-config-items.d.ts +18 -0
- package/es-custom/components/prompt-line/src/tiptap/resolve-config-items.js +32 -0
- package/es-custom/components/prompt-line/src/tiptap/resolve-config-items.js.map +1 -0
- package/es-custom/components/prompt-line/src/tiptap/strip-presentation-fields.d.ts +18 -0
- package/es-custom/components/prompt-line/src/tiptap/strip-presentation-fields.js +22 -0
- package/es-custom/components/prompt-line/src/tiptap/strip-presentation-fields.js.map +1 -0
- package/es-custom/components/prompt-line/src/tiptap/types.d.ts +11 -3
- package/es-custom/components/toolbar/src/toolbar.d.ts +8 -0
- package/es-custom/components/toolbar/src/toolbar.js +65 -19
- package/es-custom/components/toolbar/src/toolbar.js.map +1 -1
- package/es-custom/components/video-player/src/providers/vimeo-provider.js +1 -1
- package/es-custom/components/video-player/src/providers/vimeo-provider.js.map +1 -1
- package/es-custom/globals/decorators/carbon-element.js +2 -3
- package/es-custom/globals/decorators/carbon-element.js.map +1 -1
- package/es-custom/globals/utils/aria-announcer-manager.d.ts +56 -0
- package/es-custom/globals/utils/aria-announcer-manager.js +46 -1
- package/es-custom/globals/utils/aria-announcer-manager.js.map +1 -1
- package/es-custom/globals/utils/focus-utils.js +1 -3
- package/es-custom/globals/utils/focus-utils.js.map +1 -1
- package/es-custom/globals/utils/iconTransform.d.ts +16 -2
- package/es-custom/globals/utils/iconTransform.js +22 -1
- package/es-custom/globals/utils/iconTransform.js.map +1 -1
- package/es-custom/react/hooks/useChatAutocomplete.js.map +1 -1
- package/es-custom/react/markdown.js +0 -1
- package/es-custom/react/markdown.js.map +1 -1
- package/es-custom/typings/overflow-menu.d.ts +4 -0
- package/package.json +6 -6
- package/scss/_custom-properties.scss +0 -17
- package/scss/_tokens-component.scss +1 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"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-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":[],"mappings":";;;;;;;;;;;;;AAAA;;;;;;;AAOG;AA0CH,SAAS,qBAAqB,CAC5B,MAA+B,EAC/B,KAAmB,EAAA;AAEnB,IAAA,MAAM,IAAI,GAAG,KAAK,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AEA,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-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);\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,MAAM,CAAC,iBAAiB;AAC5C,aAAA,CAAC;QACN,CAAC;QAED,qBAAqB,GAAA;YACnB,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,EAAE;AAC3C,YAAA,M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AAE;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-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-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,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,EAAE;QAC3D;IACF;AACA,IAAA,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC;IAC7B,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC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
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* - `Mod-Enter` → emit `cds-aichat-prompt-send-intent`. The shell decides
|
|
13
13
|
* whether to honor (re-dispatch as `cds-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-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-aichat-prompt-send-intent`. The shell decides
|
|
22
22
|
* whether to honor (re-dispatch as `cds-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-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-aichat-prompt-send-intent`. The shell decides\n * whether to honor (re-dispatch as `cds-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-aichat-prompt-send-intent`. The shell decides\n * whether to honor (re-dispatch as `cds-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-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-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-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-aichat--token', { 'white-space': 'normal' });\n setVarsForSelector('.cds-aichat--token[data-token-context=\"composer\"]', {\n color: 'var(--cds-tag-color-blue, #0043ce)',\n });\n setVarsForSelector(\n '.cds-aichat--token[data-token-context=\"composer\"]::selection',\n { 'background-color': 'var(--cds-tag-background-blue, #d0e2ff)' }\n );\n setVarsForSelector('.cds-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-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-aichat--token', { 'white-space': 'normal' });\n setVarsForSelector('.cds-aichat--token[data-token-context=\"composer\"]', {\n color: 'var(--cds-tag-color-blue, #0043ce)',\n });\n setVarsForSelector(\n '.cds-aichat--token[data-token-context=\"composer\"]::selection',\n { 'background-color': 'var(--cds-tag-background-blue, #d0e2ff)' }\n );\n setVarsForSelector('.cds-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-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,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC;AACrE,IAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,EAAE,iBAAiB;IAE/C,IAAI,CAAC,QAAQ,EAAE;QACb,GAAG,CAAC,WAAW,CAAC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC9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
|
|
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;;"}
|
|
@@ -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;
|
|
@@ -86,19 +86,23 @@ let CDSAIChatToolbar = CDSAIChatToolbar_1 = class CDSAIChatToolbar extends LitEl
|
|
|
86
86
|
*/
|
|
87
87
|
this.renderIconButton = (action) => {
|
|
88
88
|
const tooltipAlign = this.isRTL ? 'bottom-start' : 'bottom-end';
|
|
89
|
+
const { isSelected } = action;
|
|
89
90
|
return html `
|
|
90
91
|
<cds-icon-button
|
|
92
|
+
align=${tooltipAlign}
|
|
93
|
+
@click=${action.onClick}
|
|
91
94
|
?data-fixed=${action.fixed}
|
|
95
|
+
data-pressed=${isSelected !== undefined ? String(isSelected) : nothing}
|
|
96
|
+
?data-selected=${isSelected === true}
|
|
92
97
|
data-testid=${action.testId || nothing}
|
|
93
|
-
|
|
98
|
+
?disabled=${action.disabled}
|
|
99
|
+
enter-delay-ms="0"
|
|
94
100
|
href=${action.href || nothing}
|
|
95
|
-
|
|
96
|
-
size=${action.size || BUTTON_SIZE.MEDIUM}
|
|
97
|
-
align=${tooltipAlign}
|
|
101
|
+
?isSelected=${isSelected === true}
|
|
98
102
|
kind="ghost"
|
|
99
|
-
enter-delay-ms="0"
|
|
100
103
|
leave-delay-ms="0"
|
|
101
|
-
|
|
104
|
+
size=${action.size || BUTTON_SIZE.MEDIUM}
|
|
105
|
+
target=${action.href ? action.target || '_self' : nothing}>
|
|
102
106
|
${iconLoader(action.icon, {
|
|
103
107
|
slot: 'icon',
|
|
104
108
|
})}
|
|
@@ -122,6 +126,39 @@ let CDSAIChatToolbar = CDSAIChatToolbar_1 = class CDSAIChatToolbar extends LitEl
|
|
|
122
126
|
this.setupResizeObserver();
|
|
123
127
|
}
|
|
124
128
|
}
|
|
129
|
+
updated() {
|
|
130
|
+
// Carbon's delegatesFocus moves focus to the inner shadow <button>, so
|
|
131
|
+
// ARIA attributes on the host are invisible to assistive tech. Mirror
|
|
132
|
+
// them onto the inner button after each element's update cycle completes.
|
|
133
|
+
void this._patchShadowButtonAttrs('cds-icon-button[data-pressed]', {
|
|
134
|
+
'aria-pressed': 'data-pressed',
|
|
135
|
+
});
|
|
136
|
+
void this._patchShadowButtonAttrs('cds-overflow-menu-item[role="menuitemcheckbox"]', { role: 'role', 'aria-checked': 'aria-checked' });
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Copies attributes from each host element matching `selector` onto its
|
|
140
|
+
* inner shadow `<button>`, after the element's own update cycle completes.
|
|
141
|
+
*
|
|
142
|
+
* @param selector - CSS selector scoped to this shadow root.
|
|
143
|
+
* @param attrMap - `{ targetAttr: sourceAttr }` pairs to copy.
|
|
144
|
+
* @internal
|
|
145
|
+
*/
|
|
146
|
+
async _patchShadowButtonAttrs(selector, attrMap) {
|
|
147
|
+
await Promise.all(Array.from(this.shadowRoot?.querySelectorAll(selector) ??
|
|
148
|
+
[]).map(async (el) => {
|
|
149
|
+
await el.updateComplete;
|
|
150
|
+
const btn = el.shadowRoot?.querySelector('button');
|
|
151
|
+
if (!btn) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
for (const [target, source] of Object.entries(attrMap)) {
|
|
155
|
+
const value = el.getAttribute(source);
|
|
156
|
+
if (value !== null) {
|
|
157
|
+
btn.setAttribute(target, value);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
125
162
|
sortActions() {
|
|
126
163
|
return [...this.actions].sort((a, b) => {
|
|
127
164
|
if (a.fixed && !b.fixed) {
|
|
@@ -273,19 +310,28 @@ let CDSAIChatToolbar = CDSAIChatToolbar_1 = class CDSAIChatToolbar extends LitEl
|
|
|
273
310
|
>${CDSAIChatToolbar_1.OVERFLOW_MENU_LABEL}</span
|
|
274
311
|
>
|
|
275
312
|
<cds-overflow-menu-body ?flipped=${!this.isRTL}>
|
|
276
|
-
${repeat(hiddenActions, (item) => item.text, (item) =>
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
313
|
+
${repeat(hiddenActions, (item) => item.text, (item) => {
|
|
314
|
+
return html `
|
|
315
|
+
<cds-overflow-menu-item
|
|
316
|
+
@click=${item.onClick}
|
|
317
|
+
href=${item.href || nothing}
|
|
318
|
+
target=${item.href ? item.target || '_self' : nothing}
|
|
319
|
+
?disabled=${item.disabled}
|
|
320
|
+
?danger=${item.danger}
|
|
321
|
+
danger-description=${item.dangerDescription || nothing}
|
|
322
|
+
?divider=${item.divider}
|
|
323
|
+
?data-selected=${item.isSelected === true}
|
|
324
|
+
role=${item.isSelected !== undefined
|
|
325
|
+
? 'menuitemcheckbox'
|
|
326
|
+
: nothing}
|
|
327
|
+
aria-checked=${item.isSelected !== undefined
|
|
328
|
+
? String(item.isSelected)
|
|
329
|
+
: nothing}
|
|
330
|
+
data-testid=${item.testId || nothing}>
|
|
331
|
+
${item.text}
|
|
332
|
+
</cds-overflow-menu-item>
|
|
333
|
+
`;
|
|
334
|
+
})}
|
|
289
335
|
</cds-overflow-menu-body>
|
|
290
336
|
</cds-overflow-menu>
|
|
291
337
|
`
|