@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
|
@@ -40,15 +40,23 @@ let FileUploadsElement = class FileUploadsElement extends LitElement {
|
|
|
40
40
|
super(...arguments);
|
|
41
41
|
/** Array of file uploads to display. */
|
|
42
42
|
this.uploads = [];
|
|
43
|
-
/** Label for the remove file button. */
|
|
43
|
+
/** Label for the remove file button, used when no file name is available. */
|
|
44
44
|
this.removeFileLabel = 'Remove file';
|
|
45
|
+
/**
|
|
46
|
+
* Returns the accessible name for one file's remove button. Receives the file
|
|
47
|
+
* name so the consumer can interpolate it, giving each button a distinct name.
|
|
48
|
+
* The default English formatter is for standalone use; `@carbon/ai-chat`
|
|
49
|
+
* supplies an `intl`-backed one. A file with no name falls back to
|
|
50
|
+
* {@link removeFileLabel}.
|
|
51
|
+
*/
|
|
52
|
+
this.getRemoveFileLabel = ({ name }) => name ? `Remove ${name}` : this.removeFileLabel;
|
|
45
53
|
/** Label announced and shown while a file is uploading. */
|
|
46
54
|
this.uploadingFileLabel = 'Uploading file';
|
|
47
55
|
/** Announced when a file is removed from the upload list. */
|
|
48
56
|
this.fileRemovedLabel = 'File removed.';
|
|
49
57
|
/** Announced when a file finishes uploading successfully. */
|
|
50
58
|
this.uploadSuccessLabel = 'The file was uploaded successfully.';
|
|
51
|
-
/** Announced when a file fails to upload. */
|
|
59
|
+
/** Announced when a file fails to upload, ahead of the host's own reason. */
|
|
52
60
|
this.uploadFailureLabel = 'There was an error uploading the file.';
|
|
53
61
|
/**
|
|
54
62
|
* Returns the announcement made when one or more files are added in the same
|
|
@@ -64,6 +72,14 @@ let FileUploadsElement = class FileUploadsElement extends LitElement {
|
|
|
64
72
|
* default English formatter is for standalone use.
|
|
65
73
|
*/
|
|
66
74
|
this.getFilesUploadingText = ({ count }) => count === 1 ? 'Uploading file.' : `Uploading ${count} files.`;
|
|
75
|
+
/**
|
|
76
|
+
* Returns the announcement made when uploads fail, receiving one reason per
|
|
77
|
+
* failed file so every reason is carried without repeating a shared title. The
|
|
78
|
+
* default builds on {@link uploadFailureLabel} and is for standalone use;
|
|
79
|
+
* `@carbon/ai-chat` supplies one composed from its language pack. Failures
|
|
80
|
+
* with no stated reason announce the label alone.
|
|
81
|
+
*/
|
|
82
|
+
this.getFileUploadFailureText = ({ messages, }) => [this.uploadFailureLabel, ...messages].filter(Boolean).join(' ');
|
|
67
83
|
/** Whether scrolling is required to view the entire width of all file upload items. */
|
|
68
84
|
this._hasOverflow = false;
|
|
69
85
|
this._announcer = new AriaAnnouncerManager();
|
|
@@ -79,11 +95,14 @@ let FileUploadsElement = class FileUploadsElement extends LitElement {
|
|
|
79
95
|
!!container && container.scrollWidth > container.clientWidth;
|
|
80
96
|
}
|
|
81
97
|
firstUpdated() {
|
|
82
|
-
const
|
|
83
|
-
this.
|
|
98
|
+
const politeRegions = this.renderRoot.querySelectorAll(`.${prefix}--file-uploads-live-region[aria-live="polite"]`);
|
|
99
|
+
const assertiveRegions = this.renderRoot.querySelectorAll(`.${prefix}--file-uploads-live-region[aria-live="assertive"]`);
|
|
100
|
+
this._announcer.connect([...politeRegions], [...assertiveRegions]);
|
|
84
101
|
// Seed from the initial uploads so the already-rendered set does not
|
|
85
|
-
// produce a burst of "added" announcements on first paint.
|
|
86
|
-
|
|
102
|
+
// produce a burst of "added" announcements on first paint. Failures are left
|
|
103
|
+
// unseeded so the first diff still reports them: the element remounts when the
|
|
104
|
+
// input is hidden and re-shown, and a blocking failure must not be swallowed.
|
|
105
|
+
this._snapshots = this._snapshotOf(this.uploads.filter((upload) => !upload.isError));
|
|
87
106
|
}
|
|
88
107
|
disconnectedCallback() {
|
|
89
108
|
this._resizeObserver.disconnect();
|
|
@@ -108,7 +127,11 @@ let FileUploadsElement = class FileUploadsElement extends LitElement {
|
|
|
108
127
|
_snapshotOf(uploads) {
|
|
109
128
|
return new Map(uploads.map((upload) => [
|
|
110
129
|
upload.id,
|
|
111
|
-
{
|
|
130
|
+
{
|
|
131
|
+
status: upload.status,
|
|
132
|
+
isError: Boolean(upload.isError),
|
|
133
|
+
errorMessage: upload.errorMessage,
|
|
134
|
+
},
|
|
112
135
|
]));
|
|
113
136
|
}
|
|
114
137
|
/**
|
|
@@ -122,8 +145,13 @@ let FileUploadsElement = class FileUploadsElement extends LitElement {
|
|
|
122
145
|
* Added and uploading transitions are coalesced: when several files are added
|
|
123
146
|
* or start uploading in the same frame, a single counted announcement is made
|
|
124
147
|
* (via {@link getFilesAddedText} / {@link getFilesUploadingText}) rather than
|
|
125
|
-
* one per file. Success
|
|
126
|
-
*
|
|
148
|
+
* one per file. Success settles per file in its own frame, so it is announced
|
|
149
|
+
* inline.
|
|
150
|
+
*
|
|
151
|
+
* Failures are diffed as a whole set rather than per edge: uploads resolve one
|
|
152
|
+
* at a time, so a per-edge diff repeats the title and recovery sentence for
|
|
153
|
+
* each failing file, and says nothing when removing one of two failed files
|
|
154
|
+
* leaves the other's reason on screen.
|
|
127
155
|
*/
|
|
128
156
|
_announceTransitions() {
|
|
129
157
|
const previous = this._snapshots;
|
|
@@ -137,16 +165,10 @@ let FileUploadsElement = class FileUploadsElement extends LitElement {
|
|
|
137
165
|
if (upload.status === 'uploading') {
|
|
138
166
|
uploadingCount += 1;
|
|
139
167
|
}
|
|
140
|
-
else if (isError) {
|
|
141
|
-
this._announcer.announce(this.uploadFailureLabel);
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
168
|
+
else if (!isError) {
|
|
144
169
|
addedCount += 1;
|
|
145
170
|
}
|
|
146
171
|
}
|
|
147
|
-
else if (!before.isError && isError) {
|
|
148
|
-
this._announcer.announce(this.uploadFailureLabel);
|
|
149
|
-
}
|
|
150
172
|
else if (before.status === 'uploading' &&
|
|
151
173
|
upload.status !== 'uploading' &&
|
|
152
174
|
!isError) {
|
|
@@ -161,6 +183,22 @@ let FileUploadsElement = class FileUploadsElement extends LitElement {
|
|
|
161
183
|
uploadingCount += 1;
|
|
162
184
|
}
|
|
163
185
|
}
|
|
186
|
+
// Keyed by id as well as reason so a failure with no reason still announces.
|
|
187
|
+
const failed = this.uploads.filter((upload) => upload.isError);
|
|
188
|
+
const signature = failed
|
|
189
|
+
.map((upload) => `${upload.id}:${upload.errorMessage ?? ''}`)
|
|
190
|
+
.join('\n');
|
|
191
|
+
const previousSignature = [...previous.entries()]
|
|
192
|
+
.filter(([, snapshot]) => snapshot.isError)
|
|
193
|
+
.map(([id, snapshot]) => `${id}:${snapshot.errorMessage ?? ''}`)
|
|
194
|
+
.join('\n');
|
|
195
|
+
if (failed.length > 0 && signature !== previousSignature) {
|
|
196
|
+
this._announcer.announce(this.getFileUploadFailureText({
|
|
197
|
+
messages: failed
|
|
198
|
+
.map((upload) => upload.errorMessage ?? '')
|
|
199
|
+
.filter(Boolean),
|
|
200
|
+
}), 'assertive');
|
|
201
|
+
}
|
|
164
202
|
if (addedCount > 0) {
|
|
165
203
|
this._announcer.announce(this.getFilesAddedText({ count: addedCount }));
|
|
166
204
|
}
|
|
@@ -180,6 +218,12 @@ let FileUploadsElement = class FileUploadsElement extends LitElement {
|
|
|
180
218
|
return html `
|
|
181
219
|
<div class="${prefix}--file-uploads-live-region" aria-live="polite"></div>
|
|
182
220
|
<div class="${prefix}--file-uploads-live-region" aria-live="polite"></div>
|
|
221
|
+
<div
|
|
222
|
+
class="${prefix}--file-uploads-live-region"
|
|
223
|
+
aria-live="assertive"></div>
|
|
224
|
+
<div
|
|
225
|
+
class="${prefix}--file-uploads-live-region"
|
|
226
|
+
aria-live="assertive"></div>
|
|
183
227
|
${this.uploads && this.uploads.length > 0
|
|
184
228
|
? html `
|
|
185
229
|
<div
|
|
@@ -189,6 +233,9 @@ let FileUploadsElement = class FileUploadsElement extends LitElement {
|
|
|
189
233
|
<cds-custom-aichat-file-upload-item
|
|
190
234
|
.upload="${upload}"
|
|
191
235
|
remove-file-label="${this.removeFileLabel}"
|
|
236
|
+
remove-file-named-label="${this.getRemoveFileLabel({
|
|
237
|
+
name: upload.file?.name,
|
|
238
|
+
})}"
|
|
192
239
|
uploading-file-label="${this.uploadingFileLabel}"
|
|
193
240
|
@cds-custom-aichat-file-remove="${this._handleFileRemove}"></cds-custom-aichat-file-upload-item>
|
|
194
241
|
`)}
|
|
@@ -208,6 +255,9 @@ __decorate([
|
|
|
208
255
|
__decorate([
|
|
209
256
|
property({ type: String, attribute: 'remove-file-label' })
|
|
210
257
|
], FileUploadsElement.prototype, "removeFileLabel", void 0);
|
|
258
|
+
__decorate([
|
|
259
|
+
property({ type: Object, attribute: false })
|
|
260
|
+
], FileUploadsElement.prototype, "getRemoveFileLabel", void 0);
|
|
211
261
|
__decorate([
|
|
212
262
|
property({ type: String, attribute: 'uploading-file-label' })
|
|
213
263
|
], FileUploadsElement.prototype, "uploadingFileLabel", void 0);
|
|
@@ -226,6 +276,9 @@ __decorate([
|
|
|
226
276
|
__decorate([
|
|
227
277
|
property({ type: Object, attribute: false })
|
|
228
278
|
], FileUploadsElement.prototype, "getFilesUploadingText", void 0);
|
|
279
|
+
__decorate([
|
|
280
|
+
property({ type: Object, attribute: false })
|
|
281
|
+
], FileUploadsElement.prototype, "getFileUploadFailureText", void 0);
|
|
229
282
|
__decorate([
|
|
230
283
|
state()
|
|
231
284
|
], FileUploadsElement.prototype, "_hasOverflow", void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-uploads.js","sources":["../../../../src/components/file-uploads/src/file-uploads.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\nimport {\n css,\n html,\n LitElement,\n nothing,\n type PropertyValues,\n unsafeCSS,\n} from 'lit';\nimport { property, state } from 'lit/decorators.js';\n\nimport { AriaAnnouncerManager } from '../../../globals/utils/aria-announcer-manager.js';\nimport { carbonElement } from '../../../globals/decorators/carbon-element.js';\nimport prefix from '../../../globals/settings.js';\nimport type {\n FileUpload,\n FileRemoveEventDetail,\n} from '../../prompt-line/src/types.js';\n\nimport './file-upload-item.js';\nimport styles from './file-uploads.scss?lit';\n\n/** Minimal per-file state captured between renders to diff status transitions. */\ninterface UploadSnapshot {\n status: FileUpload['status'];\n isError: boolean;\n}\n\n/**\n * Displays a list of file uploads with status indicators, and announces upload\n * state changes (added / uploading / success / failure / removed) to screen\n * readers via the shared {@link AriaAnnouncerManager}.\n *\n * The element stays mounted whenever uploading is available (even with no\n * pending files) so its live regions survive removal of the last file; the host\n * reflects a `has-uploads` attribute so the surrounding layout can collapse its\n * spacing when empty.\n *\n * @element cds-custom-aichat-file-uploads\n * @fires {CustomEvent<FileRemoveEventDetail>} cds-custom-aichat-file-remove - Fired when a file is removed\n */\n@carbonElement(`${prefix}-file-uploads`)\nclass FileUploadsElement extends LitElement {\n static styles = css`\n ${unsafeCSS(styles)}\n `;\n\n /** Array of file uploads to display. */\n @property({ type: Array, attribute: false })\n uploads: FileUpload[] = [];\n\n /** Label for the remove file button. */\n @property({ type: String, attribute: 'remove-file-label' })\n removeFileLabel = 'Remove file';\n\n /** Label announced and shown while a file is uploading. */\n @property({ type: String, attribute: 'uploading-file-label' })\n uploadingFileLabel = 'Uploading file';\n\n /** Announced when a file is removed from the upload list. */\n @property({ type: String, attribute: 'file-removed-label' })\n fileRemovedLabel = 'File removed.';\n\n /** Announced when a file finishes uploading successfully. */\n @property({ type: String, attribute: 'upload-success-label' })\n uploadSuccessLabel = 'The file was uploaded successfully.';\n\n /** Announced when a file fails to upload. */\n @property({ type: String, attribute: 'upload-failure-label' })\n uploadFailureLabel = 'There was an error uploading the file.';\n\n /**\n * Returns the announcement made when one or more files are added in the same\n * frame. Receives the batch count so the consumer can localize and pluralize\n * (correct plural rules are locale-specific). The default English formatter is\n * for standalone use; `@carbon/ai-chat` supplies an `intl`-backed one. Files\n * added together are announced once, not once per file.\n */\n @property({ type: Object, attribute: false })\n getFilesAddedText: (args: { count: number }) => string = ({ count }) =>\n count === 1 ? 'File added.' : `${count} files added.`;\n\n /**\n * Returns the announcement made when one or more files begin uploading in the\n * same frame. Receives the batch count for localization/pluralization; the\n * default English formatter is for standalone use.\n */\n @property({ type: Object, attribute: false })\n getFilesUploadingText: (args: { count: number }) => string = ({ count }) =>\n count === 1 ? 'Uploading file.' : `Uploading ${count} files.`;\n\n /** Whether scrolling is required to view the entire width of all file upload items. */\n @state() private _hasOverflow = false;\n\n private _announcer = new AriaAnnouncerManager();\n\n /** Previous-frame snapshot keyed by upload id, used to detect transitions. */\n private _snapshots = new Map<string, UploadSnapshot>();\n\n private _resizeObserver = new ResizeObserver(() => {\n this._checkOverflow();\n });\n\n private _checkOverflow() {\n const container = this.renderRoot.querySelector<HTMLElement>(\n `.${prefix}--file-uploads-container`\n );\n this._hasOverflow =\n !!container && container.scrollWidth > container.clientWidth;\n }\n\n protected firstUpdated() {\n const regions = this.renderRoot.querySelectorAll<HTMLDivElement>(\n `.${prefix}--file-uploads-live-region`\n );\n this._announcer.connect(Array.from(regions));\n // Seed from the initial uploads so the already-rendered set does not\n // produce a burst of \"added\" announcements on first paint.\n this._snapshots = this._snapshotOf(this.uploads);\n }\n\n disconnectedCallback() {\n this._resizeObserver.disconnect();\n this._announcer.disconnect();\n super.disconnectedCallback();\n }\n\n protected updated(changedProperties: PropertyValues) {\n if (changedProperties.has('uploads')) {\n this.toggleAttribute('has-uploads', this.uploads.length > 0);\n this._announceTransitions();\n\n this._resizeObserver.disconnect();\n const container = this.renderRoot.querySelector<HTMLElement>(\n `.${prefix}--file-uploads-container`\n );\n if (container) {\n this._resizeObserver.observe(container);\n this._checkOverflow();\n } else {\n this._hasOverflow = false;\n }\n }\n }\n\n private _snapshotOf(uploads: FileUpload[]): Map<string, UploadSnapshot> {\n return new Map(\n uploads.map((upload) => [\n upload.id,\n { status: upload.status, isError: Boolean(upload.isError) },\n ])\n );\n }\n\n /**\n * Announce per-file status transitions by diffing the current uploads against\n * the previous frame. The input list never carries a positive \"complete\"\n * status (a finished assistant upload settles back to \"edit\"), so success is\n * inferred from the `uploading → not-uploading` transition. Removals are\n * announced from {@link _handleFileRemove} instead — diffing would also fire\n * when uploads clear on send.\n *\n * Added and uploading transitions are coalesced: when several files are added\n * or start uploading in the same frame, a single counted announcement is made\n * (via {@link getFilesAddedText} / {@link getFilesUploadingText}) rather than\n * one per file. Success and failure settle per file in their own frames, so\n * they are announced inline.\n */\n private _announceTransitions() {\n const previous = this._snapshots;\n\n let addedCount = 0;\n let uploadingCount = 0;\n\n for (const upload of this.uploads) {\n const before = previous.get(upload.id);\n const isError = Boolean(upload.isError);\n\n if (!before) {\n // New item this frame.\n if (upload.status === 'uploading') {\n uploadingCount += 1;\n } else if (isError) {\n this._announcer.announce(this.uploadFailureLabel);\n } else {\n addedCount += 1;\n }\n } else if (!before.isError && isError) {\n this._announcer.announce(this.uploadFailureLabel);\n } else if (\n before.status === 'uploading' &&\n upload.status !== 'uploading' &&\n !isError\n ) {\n this._announcer.announce(this.uploadSuccessLabel);\n } else if (\n before.status !== 'uploading' &&\n upload.status === 'uploading'\n ) {\n // A staged file that begins uploading. Files staged in the input area\n // start in the \"edit\" state and flip to \"uploading\" once their upload\n // begins, so this transition fires for staged-then-uploaded files (the\n // \"added\" announcement already fired when they were staged).\n uploadingCount += 1;\n }\n }\n\n if (addedCount > 0) {\n this._announcer.announce(this.getFilesAddedText({ count: addedCount }));\n }\n if (uploadingCount > 0) {\n this._announcer.announce(\n this.getFilesUploadingText({ count: uploadingCount })\n );\n }\n\n this._snapshots = this._snapshotOf(this.uploads);\n }\n\n private _handleFileRemove(_e: CustomEvent<FileRemoveEventDetail>) {\n // Announce here rather than in the diff so we only speak on a user-initiated\n // removal, not when uploads clear on send.\n this._announcer.announce(this.fileRemovedLabel);\n // Event was dispatched composed+bubbling from file-upload-item — it will\n // continue to bubble to the consumer. No need to re-dispatch.\n }\n\n render() {\n return html`\n <div class=\"${prefix}--file-uploads-live-region\" aria-live=\"polite\"></div>\n <div class=\"${prefix}--file-uploads-live-region\" aria-live=\"polite\"></div>\n ${\n this.uploads && this.uploads.length > 0\n ? html`\n <div\n class=\"${prefix}--file-uploads-gradient-wrapper${this._hasOverflow ? ` ${prefix}--file-uploads-gradient-wrapper--overflow` : ''}\">\n <div class=\"${prefix}--file-uploads-container\">\n ${this.uploads.map(\n (upload) => html`\n <cds-custom-aichat-file-upload-item\n .upload=\"${upload}\"\n remove-file-label=\"${this.removeFileLabel}\"\n uploading-file-label=\"${this.uploadingFileLabel}\"\n @cds-custom-aichat-file-remove=\"${this._handleFileRemove}\"></cds-custom-aichat-file-upload-item>\n `\n )}\n </div>\n </div>\n `\n : nothing\n }\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'cds-custom-aichat-file-uploads': FileUploadsElement;\n }\n}\n\nexport default FileUploadsElement;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;AAOG;AA6BH;;;;;;;;;;;;AAYG;AAEH,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,UAAU,CAAA;AAA3C,IAAA,WAAA,GAAA;;;QAOE,IAAA,CAAA,OAAO,GAAiB,EAAE;;QAI1B,IAAA,CAAA,eAAe,GAAG,aAAa;;QAI/B,IAAA,CAAA,kBAAkB,GAAG,gBAAgB;;QAIrC,IAAA,CAAA,gBAAgB,GAAG,eAAe;;QAIlC,IAAA,CAAA,kBAAkB,GAAG,qCAAqC;;QAI1D,IAAA,CAAA,kBAAkB,GAAG,wCAAwC;AAE7D;;;;;;AAMG;QAEH,IAAA,CAAA,iBAAiB,GAAwC,CAAC,EAAE,KAAK,EAAE,KACjE,KAAK,KAAK,CAAC,GAAG,aAAa,GAAG,CAAA,EAAG,KAAK,CAAA,aAAA,CAAe;AAEvD;;;;AAIG;QAEH,IAAA,CAAA,qBAAqB,GAAwC,CAAC,EAAE,KAAK,EAAE,KACrE,KAAK,KAAK,CAAC,GAAG,iBAAiB,GAAG,CAAA,UAAA,EAAa,KAAK,CAAA,OAAA,CAAS;;QAG9C,IAAA,CAAA,YAAY,GAAG,KAAK;AAE7B,QAAA,IAAA,CAAA,UAAU,GAAG,IAAI,oBAAoB,EAAE;;AAGvC,QAAA,IAAA,CAAA,UAAU,GAAG,IAAI,GAAG,EAA0B;AAE9C,QAAA,IAAA,CAAA,eAAe,GAAG,IAAI,cAAc,CAAC,MAAK;YAChD,IAAI,CAAC,cAAc,EAAE;AACvB,QAAA,CAAC,CAAC;IAwJJ;IAtJU,cAAc,GAAA;AACpB,QAAA,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa,CAC7C,CAAA,CA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D,UAAA,CAAA;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE;AAEoB,CAAA,EAAA,kBAAA,CAAA,SAAA,EAAA,uBAAA,EAAA,MAAA,CAAA;AAG/C,UAAA,CAAA;AAAhB,IAAA,KAAK;AAAgC,CAAA,EAAA,kBAAA,CAAA,SAAA,EAAA,cAAA,EAAA,MAAA,CAAA;AAlDlC,kBAAkB,GAAA,UAAA,CAAA;AADvB,IAAA,aAAa,CAAC,CAAA,EAAG,MAAM,CAAA,aAAA,CAAe;AACjC,CAAA,EAAA,kBAAkB,CAmNvB;AAQD,2BAAe,kBAAkB;;"}
|
|
1
|
+
{"version":3,"file":"file-uploads.js","sources":["../../../../src/components/file-uploads/src/file-uploads.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\nimport {\n css,\n html,\n LitElement,\n nothing,\n type PropertyValues,\n unsafeCSS,\n} from 'lit';\nimport { property, state } from 'lit/decorators.js';\n\nimport { AriaAnnouncerManager } from '../../../globals/utils/aria-announcer-manager.js';\nimport { carbonElement } from '../../../globals/decorators/carbon-element.js';\nimport prefix from '../../../globals/settings.js';\nimport type {\n FileUpload,\n FileRemoveEventDetail,\n} from '../../prompt-line/src/types.js';\n\nimport './file-upload-item.js';\nimport styles from './file-uploads.scss?lit';\n\n/** Minimal per-file state captured between renders to diff status transitions. */\ninterface UploadSnapshot {\n status: FileUpload['status'];\n isError: boolean;\n errorMessage?: string;\n}\n\n/**\n * Displays a list of file uploads with status indicators, and announces upload\n * state changes (added / uploading / success / failure / removed) to screen\n * readers via the shared {@link AriaAnnouncerManager}.\n *\n * The element stays mounted whenever uploading is available (even with no\n * pending files) so its live regions survive removal of the last file; the host\n * reflects a `has-uploads` attribute so the surrounding layout can collapse its\n * spacing when empty.\n *\n * @element cds-custom-aichat-file-uploads\n * @fires {CustomEvent<FileRemoveEventDetail>} cds-custom-aichat-file-remove - Fired when a file is removed\n */\n@carbonElement(`${prefix}-file-uploads`)\nclass FileUploadsElement extends LitElement {\n static styles = css`\n ${unsafeCSS(styles)}\n `;\n\n /** Array of file uploads to display. */\n @property({ type: Array, attribute: false })\n uploads: FileUpload[] = [];\n\n /** Label for the remove file button, used when no file name is available. */\n @property({ type: String, attribute: 'remove-file-label' })\n removeFileLabel = 'Remove file';\n\n /**\n * Returns the accessible name for one file's remove button. Receives the file\n * name so the consumer can interpolate it, giving each button a distinct name.\n * The default English formatter is for standalone use; `@carbon/ai-chat`\n * supplies an `intl`-backed one. A file with no name falls back to\n * {@link removeFileLabel}.\n */\n @property({ type: Object, attribute: false })\n getRemoveFileLabel: (args: { name?: string }) => string = ({ name }) =>\n name ? `Remove ${name}` : this.removeFileLabel;\n\n /** Label announced and shown while a file is uploading. */\n @property({ type: String, attribute: 'uploading-file-label' })\n uploadingFileLabel = 'Uploading file';\n\n /** Announced when a file is removed from the upload list. */\n @property({ type: String, attribute: 'file-removed-label' })\n fileRemovedLabel = 'File removed.';\n\n /** Announced when a file finishes uploading successfully. */\n @property({ type: String, attribute: 'upload-success-label' })\n uploadSuccessLabel = 'The file was uploaded successfully.';\n\n /** Announced when a file fails to upload, ahead of the host's own reason. */\n @property({ type: String, attribute: 'upload-failure-label' })\n uploadFailureLabel = 'There was an error uploading the file.';\n\n /**\n * Returns the announcement made when one or more files are added in the same\n * frame. Receives the batch count so the consumer can localize and pluralize\n * (correct plural rules are locale-specific). The default English formatter is\n * for standalone use; `@carbon/ai-chat` supplies an `intl`-backed one. Files\n * added together are announced once, not once per file.\n */\n @property({ type: Object, attribute: false })\n getFilesAddedText: (args: { count: number }) => string = ({ count }) =>\n count === 1 ? 'File added.' : `${count} files added.`;\n\n /**\n * Returns the announcement made when one or more files begin uploading in the\n * same frame. Receives the batch count for localization/pluralization; the\n * default English formatter is for standalone use.\n */\n @property({ type: Object, attribute: false })\n getFilesUploadingText: (args: { count: number }) => string = ({ count }) =>\n count === 1 ? 'Uploading file.' : `Uploading ${count} files.`;\n\n /**\n * Returns the announcement made when uploads fail, receiving one reason per\n * failed file so every reason is carried without repeating a shared title. The\n * default builds on {@link uploadFailureLabel} and is for standalone use;\n * `@carbon/ai-chat` supplies one composed from its language pack. Failures\n * with no stated reason announce the label alone.\n */\n @property({ type: Object, attribute: false })\n getFileUploadFailureText: (args: { messages: string[] }) => string = ({\n messages,\n }) => [this.uploadFailureLabel, ...messages].filter(Boolean).join(' ');\n\n /** Whether scrolling is required to view the entire width of all file upload items. */\n @state()\n private _hasOverflow = false;\n\n private _announcer = new AriaAnnouncerManager();\n\n /** Previous-frame snapshot keyed by upload id, used to detect transitions. */\n private _snapshots = new Map<string, UploadSnapshot>();\n\n private _resizeObserver = new ResizeObserver(() => {\n this._checkOverflow();\n });\n\n private _checkOverflow() {\n const container = this.renderRoot.querySelector<HTMLElement>(\n `.${prefix}--file-uploads-container`\n );\n this._hasOverflow =\n !!container && container.scrollWidth > container.clientWidth;\n }\n\n protected firstUpdated() {\n const politeRegions = this.renderRoot.querySelectorAll<HTMLDivElement>(\n `.${prefix}--file-uploads-live-region[aria-live=\"polite\"]`\n );\n const assertiveRegions = this.renderRoot.querySelectorAll<HTMLDivElement>(\n `.${prefix}--file-uploads-live-region[aria-live=\"assertive\"]`\n );\n\n this._announcer.connect([...politeRegions], [...assertiveRegions]);\n // Seed from the initial uploads so the already-rendered set does not\n // produce a burst of \"added\" announcements on first paint. Failures are left\n // unseeded so the first diff still reports them: the element remounts when the\n // input is hidden and re-shown, and a blocking failure must not be swallowed.\n this._snapshots = this._snapshotOf(\n this.uploads.filter((upload) => !upload.isError)\n );\n }\n\n disconnectedCallback() {\n this._resizeObserver.disconnect();\n this._announcer.disconnect();\n super.disconnectedCallback();\n }\n\n protected updated(changedProperties: PropertyValues) {\n if (changedProperties.has('uploads')) {\n this.toggleAttribute('has-uploads', this.uploads.length > 0);\n this._announceTransitions();\n\n this._resizeObserver.disconnect();\n const container = this.renderRoot.querySelector<HTMLElement>(\n `.${prefix}--file-uploads-container`\n );\n if (container) {\n this._resizeObserver.observe(container);\n this._checkOverflow();\n } else {\n this._hasOverflow = false;\n }\n }\n }\n\n private _snapshotOf(uploads: FileUpload[]): Map<string, UploadSnapshot> {\n return new Map(\n uploads.map((upload) => [\n upload.id,\n {\n status: upload.status,\n isError: Boolean(upload.isError),\n errorMessage: upload.errorMessage,\n },\n ])\n );\n }\n\n /**\n * Announce per-file status transitions by diffing the current uploads against\n * the previous frame. The input list never carries a positive \"complete\"\n * status (a finished assistant upload settles back to \"edit\"), so success is\n * inferred from the `uploading → not-uploading` transition. Removals are\n * announced from {@link _handleFileRemove} instead — diffing would also fire\n * when uploads clear on send.\n *\n * Added and uploading transitions are coalesced: when several files are added\n * or start uploading in the same frame, a single counted announcement is made\n * (via {@link getFilesAddedText} / {@link getFilesUploadingText}) rather than\n * one per file. Success settles per file in its own frame, so it is announced\n * inline.\n *\n * Failures are diffed as a whole set rather than per edge: uploads resolve one\n * at a time, so a per-edge diff repeats the title and recovery sentence for\n * each failing file, and says nothing when removing one of two failed files\n * leaves the other's reason on screen.\n */\n private _announceTransitions() {\n const previous = this._snapshots;\n\n let addedCount = 0;\n let uploadingCount = 0;\n\n for (const upload of this.uploads) {\n const before = previous.get(upload.id);\n const isError = Boolean(upload.isError);\n\n if (!before) {\n // New item this frame.\n if (upload.status === 'uploading') {\n uploadingCount += 1;\n } else if (!isError) {\n addedCount += 1;\n }\n } else if (\n before.status === 'uploading' &&\n upload.status !== 'uploading' &&\n !isError\n ) {\n this._announcer.announce(this.uploadSuccessLabel);\n } else if (\n before.status !== 'uploading' &&\n upload.status === 'uploading'\n ) {\n // A staged file that begins uploading. Files staged in the input area\n // start in the \"edit\" state and flip to \"uploading\" once their upload\n // begins, so this transition fires for staged-then-uploaded files (the\n // \"added\" announcement already fired when they were staged).\n uploadingCount += 1;\n }\n }\n\n // Keyed by id as well as reason so a failure with no reason still announces.\n const failed = this.uploads.filter((upload) => upload.isError);\n const signature = failed\n .map((upload) => `${upload.id}:${upload.errorMessage ?? ''}`)\n .join('\\n');\n const previousSignature = [...previous.entries()]\n .filter(([, snapshot]) => snapshot.isError)\n .map(([id, snapshot]) => `${id}:${snapshot.errorMessage ?? ''}`)\n .join('\\n');\n\n if (failed.length > 0 && signature !== previousSignature) {\n this._announcer.announce(\n this.getFileUploadFailureText({\n messages: failed\n .map((upload) => upload.errorMessage ?? '')\n .filter(Boolean),\n }),\n 'assertive'\n );\n }\n if (addedCount > 0) {\n this._announcer.announce(this.getFilesAddedText({ count: addedCount }));\n }\n if (uploadingCount > 0) {\n this._announcer.announce(\n this.getFilesUploadingText({ count: uploadingCount })\n );\n }\n\n this._snapshots = this._snapshotOf(this.uploads);\n }\n\n private _handleFileRemove(_e: CustomEvent<FileRemoveEventDetail>) {\n // Announce here rather than in the diff so we only speak on a user-initiated\n // removal, not when uploads clear on send.\n this._announcer.announce(this.fileRemovedLabel);\n // Event was dispatched composed+bubbling from file-upload-item — it will\n // continue to bubble to the consumer. No need to re-dispatch.\n }\n\n render() {\n return html`\n <div class=\"${prefix}--file-uploads-live-region\" aria-live=\"polite\"></div>\n <div class=\"${prefix}--file-uploads-live-region\" aria-live=\"polite\"></div>\n <div\n class=\"${prefix}--file-uploads-live-region\"\n aria-live=\"assertive\"></div>\n <div\n class=\"${prefix}--file-uploads-live-region\"\n aria-live=\"assertive\"></div>\n ${\n this.uploads && this.uploads.length > 0\n ? html`\n <div\n class=\"${prefix}--file-uploads-gradient-wrapper${this._hasOverflow ? ` ${prefix}--file-uploads-gradient-wrapper--overflow` : ''}\">\n <div class=\"${prefix}--file-uploads-container\">\n ${this.uploads.map(\n (upload) => html`\n <cds-custom-aichat-file-upload-item\n .upload=\"${upload}\"\n remove-file-label=\"${this.removeFileLabel}\"\n remove-file-named-label=\"${this.getRemoveFileLabel({\n name: upload.file?.name,\n })}\"\n uploading-file-label=\"${this.uploadingFileLabel}\"\n @cds-custom-aichat-file-remove=\"${this._handleFileRemove}\"></cds-custom-aichat-file-upload-item>\n `\n )}\n </div>\n </div>\n `\n : nothing\n }\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'cds-custom-aichat-file-uploads': FileUploadsElement;\n }\n}\n\nexport default FileUploadsElement;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;AAOG;AA8BH;;;;;;;;;;;;AAYG;AAEH,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,UAAU,CAAA;AAA3C,IAAA,WAAA,GAAA;;;QAOE,IAAA,CAAA,OAAO,GAAiB,EAAE;;QAI1B,IAAA,CAAA,eAAe,GAAG,aAAa;AAE/B;;;;;;AAMG;QAEH,IAAA,CAAA,kBAAkB,GAAwC,CAAC,EAAE,IAAI,EAAE,KACjE,IAAI,GAAG,CAAA,OAAA,EAAU,IAAI,CAAA,CAAE,GAAG,IAAI,CAAC,eAAe;;QAIhD,IAAA,CAAA,kBAAkB,GAAG,gBAAgB;;QAIrC,IAAA,CAAA,gBAAgB,GAAG,eAAe;;QAIlC,IAAA,CAAA,kBAAkB,GAAG,qCAAqC;;QAI1D,IAAA,CAAA,kBAAkB,GAAG,wCAAwC;AAE7D;;;;;;AAMG;QAEH,IAAA,CAAA,iBAAiB,GAAwC,CAAC,EAAE,KAAK,EAAE,KACjE,KAAK,KAAK,CAAC,GAAG,aAAa,GAAG,CAAA,EAAG,KAAK,CAAA,aAAA,CAAe;AAEvD;;;;AAIG;QAEH,IAAA,CAAA,qBAAqB,GAAwC,CAAC,EAAE,KAAK,EAAE,KACrE,KAAK,KAAK,CAAC,GAAG,iBAAiB,GAAG,CAAA,UAAA,EAAa,KAAK,CAAA,OAAA,CAAS;AAE/D;;;;;;AAMG;QAEH,IAAA,CAAA,wBAAwB,GAA6C,CAAC,EACpE,QAAQ,GACT,KAAK,CAAC,IAAI,CAAC,kBAAkB,EAAE,GAAG,QAAQ,CAAC,CAAC,MAAM,CA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