@carbon/ai-chat-components 1.14.0 → 1.15.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 +8737 -8823
- package/es/components/audio-player/src/transcript.js +1 -1
- package/es/components/carousel/src/carousel.d.ts +1 -1
- package/es/components/carousel/src/carousel.js +1 -1
- package/es/components/carousel/src/carousel.js.map +1 -1
- package/es/components/chat-history/src/history-panel-item.d.ts +8 -0
- package/es/components/chat-history/src/history-panel-item.js +44 -1
- package/es/components/chat-history/src/history-panel-item.js.map +1 -1
- package/es/components/code-snippet/src/code-snippet.d.ts +4 -0
- package/es/components/code-snippet/src/code-snippet.js +12 -0
- package/es/components/code-snippet/src/code-snippet.js.map +1 -1
- package/es/components/feedback/src/feedback.js +1 -1
- package/es/components/file-uploads/src/file-upload-item.d.ts +16 -17
- package/es/components/file-uploads/src/file-upload-item.js +98 -58
- package/es/components/file-uploads/src/file-upload-item.js.map +1 -1
- package/es/components/file-uploads/src/file-upload-item.scss.js +1 -1
- package/es/components/file-uploads/src/file-uploads.d.ts +20 -0
- package/es/components/file-uploads/src/file-uploads.js +55 -1
- package/es/components/file-uploads/src/file-uploads.js.map +1 -1
- package/es/components/file-uploads/src/file-uploads.scss.js +1 -1
- package/es/components/markdown/index.js +1 -2
- package/es/components/markdown/index.js.map +1 -1
- package/es/components/markdown/src/inline-markdown.d.ts +2 -2
- package/es/components/markdown/src/inline-markdown.js +8 -2
- package/es/components/markdown/src/inline-markdown.js.map +1 -1
- package/es/components/markdown/src/inline-markdown.scss.js +2 -2
- package/es/components/markdown/src/markdown-renderer-types.d.ts +2 -0
- package/es/components/markdown/src/markdown-renderer.js +3 -1
- package/es/components/markdown/src/markdown-renderer.js.map +1 -1
- package/es/components/markdown/src/markdown.d.ts +4 -0
- package/es/components/markdown/src/markdown.js +14 -0
- package/es/components/markdown/src/markdown.js.map +1 -1
- package/es/components/markdown/src/utils/inline-run-projection.js +3 -17
- package/es/components/markdown/src/utils/inline-run-projection.js.map +1 -1
- package/es/components/message-item-shell/index.d.ts +11 -0
- package/es/components/message-item-shell/index.js +9 -0
- package/es/components/message-item-shell/index.js.map +1 -0
- package/es/components/message-item-shell/src/message-item-shell.d.ts +48 -0
- package/es/components/message-item-shell/src/message-item-shell.js +91 -0
- package/es/components/message-item-shell/src/message-item-shell.js.map +1 -0
- package/es/components/message-item-shell/src/message-item-shell.scss.js +13 -0
- package/es/components/message-item-shell/src/message-item-shell.scss.js.map +1 -0
- package/es/components/prompt-line/src/prompt-line-controller.d.ts +1 -1
- package/es/components/prompt-line/src/prompt-line-rich-runtime.js +19 -2
- 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 +9 -4
- package/es/components/prompt-line/src/prompt-line-textarea-runtime.js.map +1 -1
- package/es/components/prompt-line/src/prompt-line.d.ts +17 -7
- package/es/components/prompt-line/src/prompt-line.js +39 -0
- package/es/components/prompt-line/src/prompt-line.js.map +1 -1
- package/es/components/prompt-line/src/prompt-line.scss.js +1 -1
- package/es/components/prompt-line/src/tiptap/chat-enter.d.ts +2 -2
- package/es/components/prompt-line/src/tiptap/chat-enter.js +2 -2
- package/es/components/prompt-line/src/tiptap/chat-enter.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/editor-styles.js +1 -1
- package/es/components/prompt-line/src/tiptap/editor-styles.js.map +1 -1
- package/es/components/prompt-line/src/tiptap/types.d.ts +3 -4
- package/es/components/shared/root-styles.d.ts +30 -0
- package/es/components/shared/root-styles.js +72 -0
- package/es/components/shared/root-styles.js.map +1 -0
- package/es/components/toolbar/src/toolbar.d.ts +14 -4
- package/es/components/toolbar/src/toolbar.js +29 -6
- package/es/components/toolbar/src/toolbar.js.map +1 -1
- package/es/components/user-avatar/index.d.ts +10 -0
- package/es/components/user-avatar/index.js +9 -0
- package/es/components/user-avatar/index.js.map +1 -0
- package/es/components/user-avatar/src/user-avatar.d.ts +46 -0
- package/es/components/user-avatar/src/user-avatar.js +153 -0
- package/es/components/user-avatar/src/user-avatar.js.map +1 -0
- package/es/components/user-avatar/src/user-avatar.scss.js +13 -0
- package/es/components/user-avatar/src/user-avatar.scss.js.map +1 -0
- package/es/globals/utils/iconTransform.js +1 -0
- package/es/globals/utils/iconTransform.js.map +1 -1
- package/es/react/chat-header.js +4 -2
- package/es/react/chat-header.js.map +1 -1
- package/es/react/code-snippet.d.ts +4 -1
- package/es/react/code-snippet.js +3 -1
- package/es/react/code-snippet.js.map +1 -1
- package/es/react/message-item-shell.d.ts +3 -0
- package/es/react/message-item-shell.js +30 -0
- package/es/react/message-item-shell.js.map +1 -0
- package/es/react/toolbar.d.ts +1 -1
- package/es/react/toolbar.js +3 -1
- package/es/react/toolbar.js.map +1 -1
- package/es/react/user-avatar.d.ts +3 -0
- package/es/react/user-avatar.js +29 -0
- package/es/react/user-avatar.js.map +1 -0
- package/es-custom/components/audio-player/src/transcript.js +1 -1
- package/es-custom/components/carousel/src/carousel.d.ts +1 -1
- package/es-custom/components/carousel/src/carousel.js +1 -1
- package/es-custom/components/carousel/src/carousel.js.map +1 -1
- package/es-custom/components/chat-history/src/history-panel-item.d.ts +8 -0
- package/es-custom/components/chat-history/src/history-panel-item.js +44 -1
- package/es-custom/components/chat-history/src/history-panel-item.js.map +1 -1
- package/es-custom/components/code-snippet/src/code-snippet.d.ts +4 -0
- package/es-custom/components/code-snippet/src/code-snippet.js +12 -0
- package/es-custom/components/code-snippet/src/code-snippet.js.map +1 -1
- package/es-custom/components/feedback/src/feedback.js +1 -1
- package/es-custom/components/file-uploads/src/file-upload-item.d.ts +16 -17
- package/es-custom/components/file-uploads/src/file-upload-item.js +98 -58
- package/es-custom/components/file-uploads/src/file-upload-item.js.map +1 -1
- package/es-custom/components/file-uploads/src/file-upload-item.scss.js +1 -1
- package/es-custom/components/file-uploads/src/file-uploads.d.ts +20 -0
- package/es-custom/components/file-uploads/src/file-uploads.js +55 -1
- package/es-custom/components/file-uploads/src/file-uploads.js.map +1 -1
- package/es-custom/components/file-uploads/src/file-uploads.scss.js +1 -1
- package/es-custom/components/markdown/index.js +1 -2
- package/es-custom/components/markdown/index.js.map +1 -1
- package/es-custom/components/markdown/src/inline-markdown.d.ts +2 -2
- package/es-custom/components/markdown/src/inline-markdown.js +8 -2
- package/es-custom/components/markdown/src/inline-markdown.js.map +1 -1
- package/es-custom/components/markdown/src/inline-markdown.scss.js +2 -2
- package/es-custom/components/markdown/src/markdown-renderer-types.d.ts +2 -0
- package/es-custom/components/markdown/src/markdown-renderer.js +3 -1
- package/es-custom/components/markdown/src/markdown-renderer.js.map +1 -1
- package/es-custom/components/markdown/src/markdown.d.ts +4 -0
- package/es-custom/components/markdown/src/markdown.js +14 -0
- package/es-custom/components/markdown/src/markdown.js.map +1 -1
- package/es-custom/components/markdown/src/utils/inline-run-projection.js +3 -17
- package/es-custom/components/markdown/src/utils/inline-run-projection.js.map +1 -1
- package/es-custom/components/message-item-shell/index.d.ts +11 -0
- package/es-custom/components/message-item-shell/index.js +9 -0
- package/es-custom/components/message-item-shell/index.js.map +1 -0
- package/es-custom/components/message-item-shell/src/message-item-shell.d.ts +48 -0
- package/es-custom/components/message-item-shell/src/message-item-shell.js +91 -0
- package/es-custom/components/message-item-shell/src/message-item-shell.js.map +1 -0
- package/es-custom/components/message-item-shell/src/message-item-shell.scss.js +13 -0
- package/es-custom/components/message-item-shell/src/message-item-shell.scss.js.map +1 -0
- package/es-custom/components/prompt-line/src/prompt-line-controller.d.ts +1 -1
- package/es-custom/components/prompt-line/src/prompt-line-rich-runtime.js +19 -2
- 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 +9 -4
- package/es-custom/components/prompt-line/src/prompt-line-textarea-runtime.js.map +1 -1
- package/es-custom/components/prompt-line/src/prompt-line.d.ts +17 -7
- package/es-custom/components/prompt-line/src/prompt-line.js +39 -0
- package/es-custom/components/prompt-line/src/prompt-line.js.map +1 -1
- package/es-custom/components/prompt-line/src/prompt-line.scss.js +1 -1
- package/es-custom/components/prompt-line/src/tiptap/chat-enter.d.ts +2 -2
- package/es-custom/components/prompt-line/src/tiptap/chat-enter.js +2 -2
- package/es-custom/components/prompt-line/src/tiptap/chat-enter.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/editor-styles.js +1 -1
- package/es-custom/components/prompt-line/src/tiptap/editor-styles.js.map +1 -1
- package/es-custom/components/prompt-line/src/tiptap/types.d.ts +3 -4
- package/es-custom/components/shared/root-styles.d.ts +30 -0
- package/es-custom/components/shared/root-styles.js +72 -0
- package/es-custom/components/shared/root-styles.js.map +1 -0
- package/es-custom/components/toolbar/src/toolbar.d.ts +14 -4
- package/es-custom/components/toolbar/src/toolbar.js +29 -6
- package/es-custom/components/toolbar/src/toolbar.js.map +1 -1
- package/es-custom/components/user-avatar/index.d.ts +10 -0
- package/es-custom/components/user-avatar/index.js +9 -0
- package/es-custom/components/user-avatar/index.js.map +1 -0
- package/es-custom/components/user-avatar/src/user-avatar.d.ts +46 -0
- package/es-custom/components/user-avatar/src/user-avatar.js +153 -0
- package/es-custom/components/user-avatar/src/user-avatar.js.map +1 -0
- package/es-custom/components/user-avatar/src/user-avatar.scss.js +13 -0
- package/es-custom/components/user-avatar/src/user-avatar.scss.js.map +1 -0
- package/es-custom/globals/utils/iconTransform.js +1 -0
- package/es-custom/globals/utils/iconTransform.js.map +1 -1
- package/es-custom/react/chat-header.js +4 -2
- package/es-custom/react/chat-header.js.map +1 -1
- package/es-custom/react/code-snippet.d.ts +4 -1
- package/es-custom/react/code-snippet.js +3 -1
- package/es-custom/react/code-snippet.js.map +1 -1
- package/es-custom/react/message-item-shell.d.ts +3 -0
- package/es-custom/react/message-item-shell.js +30 -0
- package/es-custom/react/message-item-shell.js.map +1 -0
- package/es-custom/react/toolbar.d.ts +1 -1
- package/es-custom/react/toolbar.js +3 -1
- package/es-custom/react/toolbar.js.map +1 -1
- package/es-custom/react/user-avatar.d.ts +3 -0
- package/es-custom/react/user-avatar.js +29 -0
- package/es-custom/react/user-avatar.js.map +1 -0
- package/package.json +8 -6
- package/telemetry.yml +16 -0
|
@@ -11,9 +11,12 @@ import { property, state } from 'lit/decorators.js';
|
|
|
11
11
|
import { carbonElement } from '../../../globals/decorators/carbon-element.js';
|
|
12
12
|
import { isBrowser } from '../../../globals/utils/browser-utils.js';
|
|
13
13
|
import prefix from '../../../globals/settings.js';
|
|
14
|
+
import { attachRootStyles } from '../../shared/root-styles.js';
|
|
14
15
|
import '@carbon/web-components/es/components/file-uploader/index.js';
|
|
15
16
|
import { iconLoader } from '@carbon/web-components/es/globals/internal/icon-loader.js';
|
|
17
|
+
import { carbonIconToSVG } from '@carbon/web-components/es/globals/internal/icon-loader-utils.js';
|
|
16
18
|
import PlayFilledAlt16 from '@carbon/icons/es/play--filled--alt/16.js';
|
|
19
|
+
import ErrorFilled16 from '@carbon/icons/es/error--filled/16.js';
|
|
17
20
|
import { pickFileTypeIcon } from './file-type-icon.js';
|
|
18
21
|
import styles from './file-upload-item.scss.js';
|
|
19
22
|
|
|
@@ -25,11 +28,6 @@ import styles from './file-upload-item.scss.js';
|
|
|
25
28
|
* This source code is licensed under the Apache-2.0 license found in the
|
|
26
29
|
* LICENSE file in the root directory of this source tree.
|
|
27
30
|
*/
|
|
28
|
-
/**
|
|
29
|
-
* Ids are scoped to their shadow root and each `cds-file-uploader-item` has its
|
|
30
|
-
* own, so a constant collides with nothing.
|
|
31
|
-
*/
|
|
32
|
-
const ERROR_MESSAGE_ID = 'cds-aichat-file-upload-item-error';
|
|
33
31
|
/** Sets `attribute` to `value`, or removes it when there is no value. */
|
|
34
32
|
function syncAttribute({ element, attribute, value }) {
|
|
35
33
|
if (value) {
|
|
@@ -84,8 +82,6 @@ let FileUploadItemElement = class FileUploadItemElement extends LitElement {
|
|
|
84
82
|
/** The File instance the current object URL was created for. */
|
|
85
83
|
this._objectURLFile = null;
|
|
86
84
|
this._syncedErrorState = false;
|
|
87
|
-
/** The `<style>` patched into Carbon's shadow root. See `_syncInjectedStyles`. */
|
|
88
|
-
this._injectedStyle = null;
|
|
89
85
|
}
|
|
90
86
|
/**
|
|
91
87
|
* The chip's content, resolved from whichever shape `upload` holds. Stated name
|
|
@@ -164,29 +160,19 @@ let FileUploadItemElement = class FileUploadItemElement extends LitElement {
|
|
|
164
160
|
_canPreviewURL(url) {
|
|
165
161
|
return Boolean(url) && url !== this._failedPreviewURL;
|
|
166
162
|
}
|
|
167
|
-
/**
|
|
168
|
-
* Only the state the patched rules read can change what they say. The
|
|
169
|
-
* `_injectedStyle` check keeps the first cycle covered — and retries on the next
|
|
170
|
-
* one if Carbon's shadow root wasn't there to patch yet.
|
|
171
|
-
*/
|
|
172
163
|
updated(changedProperties) {
|
|
173
|
-
|
|
174
|
-
changedProperties.has('readOnly') ||
|
|
175
|
-
changedProperties.has('upload') ||
|
|
176
|
-
changedProperties.has('_failedPreviewURL')) {
|
|
177
|
-
this._syncInjectedStyles();
|
|
178
|
-
}
|
|
164
|
+
this._syncInjectedStyles();
|
|
179
165
|
if (changedProperties.has('readOnly') ||
|
|
180
166
|
changedProperties.has('upload') ||
|
|
167
|
+
changedProperties.has('errorDescription') ||
|
|
181
168
|
!this._syncedErrorState) {
|
|
182
169
|
this._syncErrorState();
|
|
183
170
|
}
|
|
184
171
|
}
|
|
185
172
|
/**
|
|
186
|
-
* Carbon
|
|
187
|
-
* the
|
|
188
|
-
*
|
|
189
|
-
* `aria-describedby` is wired there: an id reference cannot cross the boundary.
|
|
173
|
+
* Carbon hides the invalid icon and leaves its failure message unreferenced, so
|
|
174
|
+
* the chip states the failure itself, in its name, for a screen reader to read
|
|
175
|
+
* when the chip takes focus.
|
|
190
176
|
*/
|
|
191
177
|
async _syncErrorState() {
|
|
192
178
|
const { isError, message } = this._uploadError;
|
|
@@ -194,13 +180,26 @@ let FileUploadItemElement = class FileUploadItemElement extends LitElement {
|
|
|
194
180
|
// `aria-invalid` on a role-less host is dropped, so an input-area chip states
|
|
195
181
|
// a role and names itself. A read-only chip is already a list item in the
|
|
196
182
|
// message list.
|
|
197
|
-
const
|
|
183
|
+
const name = this.readOnly ? undefined : this._resolved?.name;
|
|
184
|
+
// The failure text is folded into the name because an id reference from the
|
|
185
|
+
// host cannot reach into this shadow root, and a group's contents are not read
|
|
186
|
+
// when it takes focus. Focusing the chip then announces the whole failure.
|
|
187
|
+
const failure = this.errorDescription || message;
|
|
188
|
+
const hasFailureToAnnounce = Boolean(invalid && failure && name);
|
|
189
|
+
const label = hasFailureToAnnounce ? `${name}. ${failure}` : name;
|
|
198
190
|
syncAttribute({
|
|
199
191
|
element: this,
|
|
200
192
|
attribute: 'role',
|
|
201
193
|
value: this.readOnly ? undefined : 'group',
|
|
202
194
|
});
|
|
203
195
|
syncAttribute({ element: this, attribute: 'aria-label', value: label });
|
|
196
|
+
// Focusable so keyboard and screen reader users can land on the chip itself,
|
|
197
|
+
// and hear its state.
|
|
198
|
+
syncAttribute({
|
|
199
|
+
element: this,
|
|
200
|
+
attribute: 'tabindex',
|
|
201
|
+
value: this.readOnly ? undefined : '0',
|
|
202
|
+
});
|
|
204
203
|
syncAttribute({
|
|
205
204
|
element: this,
|
|
206
205
|
attribute: 'aria-invalid',
|
|
@@ -210,41 +209,39 @@ let FileUploadItemElement = class FileUploadItemElement extends LitElement {
|
|
|
210
209
|
if (!inner) {
|
|
211
210
|
return;
|
|
212
211
|
}
|
|
213
|
-
//
|
|
214
|
-
//
|
|
212
|
+
// Carbon draws the invalid icon in its own update, after ours; a failed upload
|
|
213
|
+
// usually also moves `state` from "uploading" to "edit", which swaps the whole
|
|
214
|
+
// status area. Wait for that render before looking for the icon.
|
|
215
215
|
await inner.updateComplete;
|
|
216
216
|
const innerRoot = inner.shadowRoot;
|
|
217
217
|
if (!innerRoot) {
|
|
218
218
|
return;
|
|
219
219
|
}
|
|
220
220
|
this._syncedErrorState = true;
|
|
221
|
-
// Carbon
|
|
222
|
-
|
|
223
|
-
const
|
|
224
|
-
if (
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
element: removeButton,
|
|
231
|
-
attribute: 'aria-describedby',
|
|
232
|
-
value: describedBy,
|
|
221
|
+
// Carbon hardcodes its WarningFilled icon for the invalid state. Swap in
|
|
222
|
+
// ErrorFilled; the marker keeps repeat syncs from replacing it again.
|
|
223
|
+
const warningIcon = innerRoot.querySelector('.cds--file__state-container .cds--file-invalid:not([data-error-icon])');
|
|
224
|
+
if (invalid && warningIcon) {
|
|
225
|
+
const template = document.createElement('template');
|
|
226
|
+
template.innerHTML = carbonIconToSVG(ErrorFilled16, {
|
|
227
|
+
class: 'cds--file-invalid',
|
|
228
|
+
'aria-hidden': 'true',
|
|
229
|
+
'data-error-icon': '',
|
|
233
230
|
});
|
|
231
|
+
warningIcon.replaceWith(template.content);
|
|
234
232
|
}
|
|
235
233
|
}
|
|
236
234
|
/**
|
|
237
|
-
* Carbon's `cds-file-uploader-item`
|
|
238
|
-
*
|
|
235
|
+
* Overrides Carbon's `cds-file-uploader-item` styles from inside its shadow
|
|
236
|
+
* root, since it exposes no `part=` for the affected elements.
|
|
239
237
|
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
* `padding-inline-end: .75rem`, so in read-only mode — where there is no status
|
|
243
|
-
* to show — it would leave 36px of dead space on the chip's trailing edge.
|
|
238
|
+
* Keep the existing selector specificity for both constructed sheets and the
|
|
239
|
+
* legacy `<style>` fallback.
|
|
244
240
|
*/
|
|
245
241
|
_syncInjectedStyles() {
|
|
246
242
|
const innerRoot = this.shadowRoot?.querySelector('cds-file-uploader-item')?.shadowRoot;
|
|
247
243
|
if (!innerRoot) {
|
|
244
|
+
this._injectedStyles = undefined;
|
|
248
245
|
return;
|
|
249
246
|
}
|
|
250
247
|
const rules = [];
|
|
@@ -258,15 +255,45 @@ let FileUploadItemElement = class FileUploadItemElement extends LitElement {
|
|
|
258
255
|
// Restate it on the name to even the two sides up.
|
|
259
256
|
rules.push('.cds--file-filename { margin-inline-end: 1rem; }');
|
|
260
257
|
}
|
|
261
|
-
|
|
262
|
-
|
|
258
|
+
if (!this.readOnly) {
|
|
259
|
+
// Column gap between the name and the status area.
|
|
260
|
+
rules.push(':host(cds-file-uploader-item[size][size=md]) { gap: 0 var(--cds-spacing-05, 1rem); }');
|
|
261
|
+
// Column gap between the status area's children (error icon, remove button).
|
|
262
|
+
rules.push(':host([size]) .cds--file__state-container { gap: var(--cds-spacing-02, 0.25rem); }');
|
|
263
|
+
}
|
|
264
|
+
if (!this.readOnly && this._uploadError.isError) {
|
|
265
|
+
// Override core component's invalid-state styles: remove its padding and outline, hide
|
|
266
|
+
// inline error text, and redraw the outline so it paints above the content.
|
|
267
|
+
rules.push(':host([invalid][size]) { padding: 0; outline: none; }');
|
|
268
|
+
rules.push(':host([invalid][size]) .cds--form-requirement { display: none; }');
|
|
269
|
+
rules.push(':host([invalid][size])::after { content: ""; position: absolute; inset: 0; border-radius: 0.5rem; outline: 2px solid var(--cds-support-error, #da1e28); outline-offset: -2px; pointer-events: none; }');
|
|
270
|
+
rules.push('@media screen and (prefers-contrast) { :host([invalid][size])::after { outline-style: dotted; } }');
|
|
271
|
+
}
|
|
272
|
+
this._applyInjectedStyles(innerRoot, rules.join('\n'));
|
|
273
|
+
}
|
|
274
|
+
_applyInjectedStyles(innerRoot, nextText) {
|
|
275
|
+
const ownerDocument = innerRoot.ownerDocument;
|
|
276
|
+
const previous = this._injectedStyles;
|
|
277
|
+
if (previous?.root === innerRoot &&
|
|
278
|
+
previous.ownerDocument === ownerDocument) {
|
|
279
|
+
previous.styles.update(nextText);
|
|
263
280
|
return;
|
|
264
281
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
282
|
+
// A sheet built for the old document can't stay adopted after the root
|
|
283
|
+
// moves documents. A replaced root takes its old styles with it.
|
|
284
|
+
if (previous?.root === innerRoot) {
|
|
285
|
+
previous.styles.detach();
|
|
268
286
|
}
|
|
269
|
-
this.
|
|
287
|
+
this._injectedStyles = {
|
|
288
|
+
root: innerRoot,
|
|
289
|
+
ownerDocument,
|
|
290
|
+
styles: attachRootStyles(innerRoot, nextText),
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
connectedCallback() {
|
|
294
|
+
super.connectedCallback();
|
|
295
|
+
// Recheck the document after adoption, even if no public property changed.
|
|
296
|
+
this.requestUpdate();
|
|
270
297
|
}
|
|
271
298
|
disconnectedCallback() {
|
|
272
299
|
super.disconnectedCallback();
|
|
@@ -290,15 +317,20 @@ let FileUploadItemElement = class FileUploadItemElement extends LitElement {
|
|
|
290
317
|
if (!objectURL) {
|
|
291
318
|
return nothing;
|
|
292
319
|
}
|
|
293
|
-
return html `<
|
|
294
|
-
|
|
320
|
+
return html `<a
|
|
321
|
+
class="${prefix}-file-upload-item__preview-wrapper"
|
|
322
|
+
href="${objectURL}"
|
|
323
|
+
target="_blank"
|
|
324
|
+
rel="noopener noreferrer"
|
|
325
|
+
aria-label="Open image">
|
|
326
|
+
<img
|
|
295
327
|
class="${prefix}-file-upload-item__preview"
|
|
296
328
|
src="${objectURL}"
|
|
297
329
|
width="36"
|
|
298
330
|
height="36"
|
|
299
331
|
alt=""
|
|
300
|
-
aria-hidden="true"
|
|
301
|
-
|
|
332
|
+
aria-hidden="true" />
|
|
333
|
+
</a>`;
|
|
302
334
|
}
|
|
303
335
|
// Video preview
|
|
304
336
|
if (file && type.startsWith('video/')) {
|
|
@@ -325,7 +357,7 @@ let FileUploadItemElement = class FileUploadItemElement extends LitElement {
|
|
|
325
357
|
newWindow.document.body.appendChild(video);
|
|
326
358
|
};
|
|
327
359
|
return html `<button
|
|
328
|
-
class="${prefix}-file-upload-item__preview-wrapper
|
|
360
|
+
class="${prefix}-file-upload-item__preview-wrapper"
|
|
329
361
|
type="button"
|
|
330
362
|
aria-label="Play video"
|
|
331
363
|
@click="${openVideo}">
|
|
@@ -351,8 +383,13 @@ let FileUploadItemElement = class FileUploadItemElement extends LitElement {
|
|
|
351
383
|
// rather than in the page. No video equivalent: playback would stream the file
|
|
352
384
|
// back, which a chip on a sent message has no business doing.
|
|
353
385
|
if (this._canPreviewURL(url) && type.startsWith('image/')) {
|
|
354
|
-
return html `<
|
|
355
|
-
|
|
386
|
+
return html `<a
|
|
387
|
+
class="${prefix}-file-upload-item__preview-wrapper"
|
|
388
|
+
href="${url}"
|
|
389
|
+
target="_blank"
|
|
390
|
+
rel="noopener noreferrer"
|
|
391
|
+
aria-label="Open image">
|
|
392
|
+
<img
|
|
356
393
|
class="${prefix}-file-upload-item__preview"
|
|
357
394
|
src="${url}"
|
|
358
395
|
width="36"
|
|
@@ -361,8 +398,8 @@ let FileUploadItemElement = class FileUploadItemElement extends LitElement {
|
|
|
361
398
|
aria-hidden="true"
|
|
362
399
|
@error="${() => {
|
|
363
400
|
this._failedPreviewURL = url;
|
|
364
|
-
}}"
|
|
365
|
-
|
|
401
|
+
}}" />
|
|
402
|
+
</a>`;
|
|
366
403
|
}
|
|
367
404
|
// File type icon (for supported icons)
|
|
368
405
|
const icon = pickFileTypeIcon(name, type);
|
|
@@ -427,6 +464,9 @@ __decorate([
|
|
|
427
464
|
__decorate([
|
|
428
465
|
property({ type: String, attribute: 'uploading-file-label' })
|
|
429
466
|
], FileUploadItemElement.prototype, "uploadingFileLabel", void 0);
|
|
467
|
+
__decorate([
|
|
468
|
+
property({ type: String, attribute: 'error-description' })
|
|
469
|
+
], FileUploadItemElement.prototype, "errorDescription", void 0);
|
|
430
470
|
__decorate([
|
|
431
471
|
property({ type: String, attribute: 'fallback-label' })
|
|
432
472
|
], FileUploadItemElement.prototype, "fallbackLabel", void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-upload-item.js","sources":["../../../../src/components/file-uploads/src/file-upload-item.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 { carbonElement } from '../../../globals/decorators/carbon-element.js';\nimport { isBrowser } from '../../../globals/utils/browser-utils.js';\nimport prefix from '../../../globals/settings.js';\n\nimport '@carbon/web-components/es/components/file-uploader/index.js';\n\nimport { iconLoader } from '@carbon/web-components/es/globals/internal/icon-loader.js';\nimport PlayFilledAlt16 from '@carbon/icons/es/play--filled--alt/16.js';\n\nimport { pickFileTypeIcon } from './file-type-icon.js';\n\nimport type {\n FileUpload,\n FileRemoveEventDetail,\n} from '../../prompt-line/src/types.js';\nimport type { FileAttachment } from './types.js';\n\nimport styles from './file-upload-item.scss?lit';\n\n/**\n * Ids are scoped to their shadow root and each `cds-file-uploader-item` has its\n * own, so a constant collides with nothing.\n */\nconst ERROR_MESSAGE_ID = 'cds-aichat-file-upload-item-error';\n\ninterface SyncAttributeOptions {\n /** The element to set the attribute on. */\n element: Element;\n\n /** The qualified attribute name. */\n attribute: string;\n\n /** The value to set, or nothing to remove the attribute. */\n value?: string;\n}\n\n/** Sets `attribute` to `value`, or removes it when there is no value. */\nfunction syncAttribute({ element, attribute, value }: SyncAttributeOptions) {\n if (value) {\n element.setAttribute(attribute, value);\n } else {\n element.removeAttribute(attribute);\n }\n}\n\n/**\n * The name, type, and (when available) `File` behind the chip, resolved from\n * whichever input was supplied.\n */\ninterface ResolvedFile {\n name?: string;\n mimeType?: string;\n file?: File;\n url?: string;\n}\n\n/**\n * Renders a single file chip with an optional media preview or file-type icon.\n *\n * Serves both places a file appears. In the input area it is driven by `upload`,\n * which carries the live `File`, and shows upload status plus a remove button. In a\n * sent message it is driven by either input with `read-only` set: no status, no\n * remove affordance. `attachment` exists for the read-only case where there is no\n * `File` at all — a message restored from conversation history — since a `File`\n * cannot be serialized.\n *\n * @element cds-aichat-file-upload-item\n * @fires {CustomEvent<FileRemoveEventDetail>} cds-aichat-file-remove - Fired when the remove button is clicked\n */\n@carbonElement(`${prefix}-file-upload-item`)\nclass FileUploadItemElement extends LitElement {\n static styles = css`\n ${unsafeCSS(styles)}\n `;\n\n /**\n * The file to render. A {@link FileUpload} when the live `File` is to hand, as in\n * the input area; a {@link FileAttachment} when only metadata survives, as on a\n * message restored from conversation history.\n */\n @property({ type: Object, attribute: false })\n upload: FileUpload | FileAttachment | null = null;\n\n /**\n * Renders the chip without status or a remove button, for a file on a message\n * that has already been sent.\n */\n @property({ type: Boolean, attribute: 'read-only', reflect: true })\n readOnly = false;\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 * Accessible name for the remove button, with the file name already\n * interpolated by the caller. Falls back to {@link removeFileLabel}.\n */\n @property({ type: String, attribute: 'remove-file-named-label' })\n removeFileNamedLabel?: string;\n\n /** Label for the uploading status. */\n @property({ type: String, attribute: 'uploading-file-label' })\n uploadingFileLabel = 'Uploading';\n\n /** Text shown when the file's name is not known. */\n @property({ type: String, attribute: 'fallback-label' })\n fallbackLabel = 'Attachment';\n\n /**\n * A preview URL that failed to load, so the chip can fall back to a file-type\n * icon. Holds the URL rather than a flag, so a new one is tried afresh: a stated\n * URL can go dead between the send and the render — a signed link expires, or an\n * object URL outlives the page that minted it.\n */\n @state()\n private _failedPreviewURL: string | null = null;\n\n /** Object URL created for image/video previews. Revoked on disconnect or when the file changes. */\n private _objectURL: string | null = null;\n\n /** The File instance the current object URL was created for. */\n private _objectURLFile: File | null = null;\n\n /**\n * The chip's content, resolved from whichever shape `upload` holds. Stated name\n * and type win where they exist; a `File` supplies them otherwise. Both shapes may\n * carry a `File`, so this branches on the `File` rather than on the shape.\n */\n private get _resolved(): ResolvedFile | null {\n const value = this.upload;\n if (!value) {\n return null;\n }\n\n const attachment = value as FileAttachment;\n const file =\n (value as FileUpload).file instanceof File\n ? (value as FileUpload).file\n : undefined;\n\n if (file) {\n return {\n name: attachment.name ?? file.name,\n mimeType: attachment.mimeType ?? file.type,\n file,\n };\n }\n\n return {\n name: attachment.name,\n mimeType: attachment.mimeType,\n url: attachment.url,\n };\n }\n\n /**\n * Whether `upload` is a staged upload rather than a sent attachment. Keyed on\n * `status`, which only an upload has — an attachment may carry a `File` too, so\n * the `File` no longer tells the two apart.\n */\n private _isUpload(value: FileUpload | FileAttachment): value is FileUpload {\n return typeof (value as FileUpload).status === 'string';\n }\n\n /** Upload status, which only a staged file has. */\n private get _uploadStatus(): string {\n return this.upload && this._isUpload(this.upload) ? this.upload.status : '';\n }\n\n /** Error state, which only a staged file has. */\n private get _uploadError(): { isError: boolean; message: string } {\n if (!this.upload || !this._isUpload(this.upload)) {\n return { isError: false, message: '' };\n }\n return {\n isError: Boolean(this.upload.isError),\n message: this.upload.errorMessage || '',\n };\n }\n\n private _getOrCreateObjectURL(file: File): string | null {\n if (this._objectURLFile !== file) {\n if (this._objectURL) {\n URL.revokeObjectURL(this._objectURL);\n }\n this._objectURL = URL.createObjectURL(file);\n this._objectURLFile = file;\n }\n return this._objectURL;\n }\n\n private _hasMediaPreview(): boolean {\n const resolved = this._resolved;\n if (!resolved) {\n return false;\n }\n\n const type = resolved.mimeType ?? '';\n if (resolved.file) {\n return type.startsWith('image/') || type.startsWith('video/');\n }\n\n // With no `File` to build an object URL from, only a stated URL can stand in,\n // and only for an image that loads. Everything else falls back to a file-type\n // icon.\n return this._canPreviewURL(resolved.url) && type.startsWith('image/');\n }\n\n /** Whether a stated URL is usable as a preview source. */\n private _canPreviewURL(url: string | undefined): url is string {\n return Boolean(url) && url !== this._failedPreviewURL;\n }\n\n /**\n * Only the state the patched rules read can change what they say. The\n * `_injectedStyle` check keeps the first cycle covered — and retries on the next\n * one if Carbon's shadow root wasn't there to patch yet.\n */\n updated(changedProperties: PropertyValues) {\n if (\n !this._injectedStyle ||\n changedProperties.has('readOnly') ||\n changedProperties.has('upload') ||\n changedProperties.has('_failedPreviewURL')\n ) {\n this._syncInjectedStyles();\n }\n\n if (\n changedProperties.has('readOnly') ||\n changedProperties.has('upload') ||\n !this._syncedErrorState\n ) {\n this._syncErrorState();\n }\n }\n\n private _syncedErrorState = false;\n\n /**\n * Carbon leaves the failure message unreferenced and hides the invalid icon, so\n * the remove button — the chip's only focusable node — states no reason. The\n * message and the button are siblings in Carbon's shadow root, so the\n * `aria-describedby` is wired there: an id reference cannot cross the boundary.\n */\n private async _syncErrorState() {\n const { isError, message } = this._uploadError;\n const invalid = !this.readOnly && isError;\n\n // `aria-invalid` on a role-less host is dropped, so an input-area chip states\n // a role and names itself. A read-only chip is already a list item in the\n // message list.\n const label = this.readOnly ? undefined : this._resolved?.name;\n syncAttribute({\n element: this,\n attribute: 'role',\n value: this.readOnly ? undefined : 'group',\n });\n syncAttribute({ element: this, attribute: 'aria-label', value: label });\n syncAttribute({\n element: this,\n attribute: 'aria-invalid',\n value: invalid ? 'true' : undefined,\n });\n\n const inner = this.shadowRoot?.querySelector(\n 'cds-file-uploader-item'\n ) as LitElement | null;\n if (!inner) {\n return;\n }\n\n // A failure also flips `state`, and Carbon re-renders that subtree — replacing\n // the button being described. Wait for the new one.\n await inner.updateComplete;\n\n const innerRoot = inner.shadowRoot;\n if (!innerRoot) {\n return;\n }\n this._syncedErrorState = true;\n\n // Carbon renders the requirement node even when it holds no message.\n const describedBy = invalid && message ? ERROR_MESSAGE_ID : undefined;\n\n const title = innerRoot.querySelector('.cds--form-requirement__title');\n if (title) {\n syncAttribute({ element: title, attribute: 'id', value: describedBy });\n }\n\n const removeButton = innerRoot.querySelector('button.cds--file-close');\n if (removeButton) {\n syncAttribute({\n element: removeButton,\n attribute: 'aria-describedby',\n value: describedBy,\n });\n }\n }\n\n /**\n * Carbon's `cds-file-uploader-item` needs two things patched from inside its own\n * shadow root, because it exposes no `part=` for either.\n *\n * The filename margin is too wide when a media preview sits beside it. And the\n * status container is rendered unconditionally at `min-inline-size: 1.5rem` plus\n * `padding-inline-end: .75rem`, so in read-only mode — where there is no status\n * to show — it would leave 36px of dead space on the chip's trailing edge.\n */\n private _syncInjectedStyles() {\n const innerRoot = this.shadowRoot?.querySelector(\n 'cds-file-uploader-item'\n )?.shadowRoot;\n if (!innerRoot) {\n return;\n }\n\n const rules: string[] = [];\n if (this._hasMediaPreview()) {\n rules.push(\n ':host(cds-file-uploader-item) p.cds--file-filename { margin-inline-start: 2px; }'\n );\n }\n if (this.readOnly) {\n rules.push(':host .cds--file__state-container { display: none; }');\n // Carbon hangs the chip's trailing padding off the status container, so\n // hiding it leaves the name flush to the edge against a 1rem leading margin.\n // Restate it on the name to even the two sides up.\n rules.push('.cds--file-filename { margin-inline-end: 1rem; }');\n }\n\n const nextText = rules.join('\\n');\n if (this._injectedStyle?.textContent === nextText) {\n return;\n }\n\n if (!this._injectedStyle) {\n this._injectedStyle = document.createElement('style');\n innerRoot.appendChild(this._injectedStyle);\n }\n this._injectedStyle.textContent = nextText;\n }\n\n /** The `<style>` patched into Carbon's shadow root. See `_syncInjectedStyles`. */\n private _injectedStyle: HTMLStyleElement | null = null;\n\n disconnectedCallback() {\n super.disconnectedCallback();\n if (this._objectURL) {\n URL.revokeObjectURL(this._objectURL);\n this._objectURL = null;\n this._objectURLFile = null;\n }\n }\n\n private _renderPreview() {\n const resolved = this._resolved;\n if (!resolved) {\n return nothing;\n }\n\n const { file, name, url } = resolved;\n const type = resolved.mimeType ?? '';\n\n // Image preview from the live File. An attachment without one falls through to\n // the URL branch below, and failing that to a file-type icon.\n if (file && type.startsWith('image/')) {\n const objectURL = this._getOrCreateObjectURL(file);\n if (!objectURL) {\n return nothing;\n }\n\n return html`<span class=\"${prefix}-file-upload-item__preview-wrapper\"\n ><img\n class=\"${prefix}-file-upload-item__preview\"\n src=\"${objectURL}\"\n width=\"36\"\n height=\"36\"\n alt=\"\"\n aria-hidden=\"true\"\n /></span>`;\n }\n\n // Video preview\n if (file && type.startsWith('video/')) {\n const objectURL = this._getOrCreateObjectURL(file);\n if (!objectURL) {\n return nothing;\n }\n\n const openVideo = () => {\n const newWindow = isBrowser()\n ? window.open('', '_blank', 'width=800,height=600')\n : null;\n\n if (!newWindow) {\n return;\n }\n\n const style = newWindow.document.createElement('style');\n style.textContent =\n '* { margin: 0; padding: 0; background: #000 } video { display: block; width: 100%; height: 100vh; object-fit: contain }';\n const video = newWindow.document.createElement('video');\n video.src = objectURL;\n video.controls = true;\n video.autoplay = true;\n newWindow.document.title = name ?? '';\n newWindow.document.head.appendChild(style);\n newWindow.document.body.appendChild(video);\n };\n\n return html`<button\n class=\"${prefix}-file-upload-item__preview-wrapper ${prefix}-file-upload-item__video-preview-wrapper\"\n type=\"button\"\n aria-label=\"Play video\"\n @click=\"${openVideo}\">\n <video\n class=\"${prefix}-file-upload-item__preview\"\n src=\"${objectURL}\"\n width=\"36\"\n height=\"36\"\n preload=\"metadata\"\n muted\n playsinline\n tabindex=\"-1\"\n aria-hidden=\"true\"\n @loadedmetadata=\"${(e: Event) => {\n (e.target as HTMLVideoElement).currentTime = 0.1;\n }}\"></video\n ><span class=\"${prefix}-file-upload-item__play-badge\" aria-hidden=\"true\"\n >${iconLoader(PlayFilledAlt16)}</span\n >\n </button>`;\n }\n\n // Image preview from a stated URL — an attachment whose file lives on a server\n // rather than in the page. No video equivalent: playback would stream the file\n // back, which a chip on a sent message has no business doing.\n if (this._canPreviewURL(url) && type.startsWith('image/')) {\n return html`<span class=\"${prefix}-file-upload-item__preview-wrapper\"\n ><img\n class=\"${prefix}-file-upload-item__preview\"\n src=\"${url}\"\n width=\"36\"\n height=\"36\"\n alt=\"\"\n aria-hidden=\"true\"\n @error=\"${() => {\n this._failedPreviewURL = url;\n }}\"\n /></span>`;\n }\n\n // File type icon (for supported icons)\n const icon = pickFileTypeIcon(name, type);\n if (icon) {\n return html`<span\n class=\"${prefix}-file-upload-item__icon\"\n aria-hidden=\"true\"\n >${iconLoader(icon)}</span\n >`;\n }\n\n return nothing;\n }\n\n private _handleRemove() {\n if (!this.upload) {\n return;\n }\n\n this.dispatchEvent(\n new CustomEvent<FileRemoveEventDetail>('cds-aichat-file-remove', {\n detail: { fileId: this.upload.id },\n bubbles: true,\n composed: true,\n })\n );\n }\n\n render() {\n const resolved = this._resolved;\n if (!resolved) {\n return nothing;\n }\n\n // An empty state falls through Carbon's status switch, rendering no\n // affordance. `_syncInjectedStyles` collapses the container it still reserves.\n const state = this.readOnly ? '' : this._uploadStatus;\n const error = this._uploadError;\n\n return html`\n <cds-file-uploader-item\n size=\"md\"\n .state=\"${state}\"\n .iconDescription=\"${\n state === 'uploading'\n ? this.uploadingFileLabel\n : this.removeFileNamedLabel || this.removeFileLabel\n }\"\n .errorSubject=\"${error.message}\"\n ?invalid=\"${!this.readOnly && error.isError}\"\n @cds-file-uploader-item-deleted=\"${this._handleRemove}\">\n ${this._renderPreview()} ${resolved.name || this.fallbackLabel}\n </cds-file-uploader-item>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'cds-aichat-file-upload-item': FileUploadItemElement;\n }\n}\n\nexport default FileUploadItemElement;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;AAOG;AA+BH;;;AAGG;AACH,MAAM,gBAAgB,GAAG,mCAAmC;AAa5D;AACA,SAAS,aAAa,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAwB,EAAA;IACxE,IAAI,KAAK,EAAE;AACT,QAAA,OAAO,CAAC,YAAY,CAAC,SAAS,EAAE,KAAK,CAAC;IACxC;SAAO;AACL,QAAA,OAAO,CAAC,eAAe,CAAC,SAAS,CAAC;IACpC;AACF;AAaA;;;;;;;;;;;;AAYG;AAEH,IAAM,qBAAqB,GAA3B,MAAM,qBAAsB,SAAQ,UAAU,CAAA;AAA9C,IAAA,WAAA,GAAA;;AAKE;;;;AAIG;QAEH,IAAA,CAAA,MAAM,GAAuC,IAAI;AAEjD;;;AAGG;QAEH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A,CAAA,SAAA,EAAA,oBAAA,EAAA,MAAA,CAAA;AAIjC,UAAA,CAAA;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE;AAC1B,CAAA,EAAA,qBAAA,CAAA,SAAA,EAAA,eAAA,EAAA,MAAA,CAAA;AASrB,UAAA,CAAA;AADP,IAAA,KAAK;AAC0C,CAAA,EAAA,qBAAA,CAAA,SAAA,EAAA,mBAAA,EAAA,MAAA,CAAA;AA9C5C,qBAAqB,GAAA,UAAA,CAAA;AAD1B,IAAA,aAAa,CAAC,CAAA,EAAG,MAAM,CAAA,iBAAA,CAAmB;AACrC,CAAA,EAAA,qBAAqB,CAsb1B;AAQD,8BAAe,qBAAqB;;"}
|
|
1
|
+
{"version":3,"file":"file-upload-item.js","sources":["../../../../src/components/file-uploads/src/file-upload-item.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 { carbonElement } from '../../../globals/decorators/carbon-element.js';\nimport { isBrowser } from '../../../globals/utils/browser-utils.js';\nimport prefix from '../../../globals/settings.js';\nimport { attachRootStyles, type RootStyles } from '../../shared/root-styles.js';\n\nimport '@carbon/web-components/es/components/file-uploader/index.js';\n\nimport { iconLoader } from '@carbon/web-components/es/globals/internal/icon-loader.js';\nimport { carbonIconToSVG } from '@carbon/web-components/es/globals/internal/icon-loader-utils.js';\nimport PlayFilledAlt16 from '@carbon/icons/es/play--filled--alt/16.js';\nimport ErrorFilled16 from '@carbon/icons/es/error--filled/16.js';\nimport { pickFileTypeIcon } from './file-type-icon.js';\n\nimport type {\n FileUpload,\n FileRemoveEventDetail,\n} from '../../prompt-line/src/types.js';\nimport type { FileAttachment } from './types.js';\n\nimport styles from './file-upload-item.scss?lit';\n\ninterface SyncAttributeOptions {\n /** The element to set the attribute on. */\n element: Element;\n\n /** The qualified attribute name. */\n attribute: string;\n\n /** The value to set, or nothing to remove the attribute. */\n value?: string;\n}\n\n/** Sets `attribute` to `value`, or removes it when there is no value. */\nfunction syncAttribute({ element, attribute, value }: SyncAttributeOptions) {\n if (value) {\n element.setAttribute(attribute, value);\n } else {\n element.removeAttribute(attribute);\n }\n}\n\n/**\n * The name, type, and (when available) `File` behind the chip, resolved from\n * whichever input was supplied.\n */\ninterface ResolvedFile {\n name?: string;\n mimeType?: string;\n file?: File;\n url?: string;\n}\n\n/**\n * Renders a single file chip with an optional media preview or file-type icon.\n *\n * Serves both places a file appears. In the input area it is driven by `upload`,\n * which carries the live `File`, and shows upload status plus a remove button. In a\n * sent message it is driven by either input with `read-only` set: no status, no\n * remove affordance. `attachment` exists for the read-only case where there is no\n * `File` at all — a message restored from conversation history — since a `File`\n * cannot be serialized.\n *\n * @element cds-aichat-file-upload-item\n * @fires {CustomEvent<FileRemoveEventDetail>} cds-aichat-file-remove - Fired when the remove button is clicked\n */\n@carbonElement(`${prefix}-file-upload-item`)\nclass FileUploadItemElement extends LitElement {\n static styles = css`\n ${unsafeCSS(styles)}\n `;\n\n /**\n * The file to render. A {@link FileUpload} when the live `File` is to hand, as in\n * the input area; a {@link FileAttachment} when only metadata survives, as on a\n * message restored from conversation history.\n */\n @property({ type: Object, attribute: false })\n upload: FileUpload | FileAttachment | null = null;\n\n /**\n * Renders the chip without status or a remove button, for a file on a message\n * that has already been sent.\n */\n @property({ type: Boolean, attribute: 'read-only', reflect: true })\n readOnly = false;\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 * Accessible name for the remove button, with the file name already\n * interpolated by the caller. Falls back to {@link removeFileLabel}.\n */\n @property({ type: String, attribute: 'remove-file-named-label' })\n removeFileNamedLabel?: string;\n\n /** Label for the uploading status. */\n @property({ type: String, attribute: 'uploading-file-label' })\n uploadingFileLabel = 'Uploading';\n\n /**\n * Full failure text for a failed upload, announced after the file name when the\n * chip takes focus. Falls back to the upload's own error message.\n */\n @property({ type: String, attribute: 'error-description' })\n errorDescription?: string;\n\n /** Text shown when the file's name is not known. */\n @property({ type: String, attribute: 'fallback-label' })\n fallbackLabel = 'Attachment';\n\n /**\n * A preview URL that failed to load, so the chip can fall back to a file-type\n * icon. Holds the URL rather than a flag, so a new one is tried afresh: a stated\n * URL can go dead between the send and the render — a signed link expires, or an\n * object URL outlives the page that minted it.\n */\n @state()\n private _failedPreviewURL: string | null = null;\n\n /** Object URL created for image/video previews. Revoked on disconnect or when the file changes. */\n private _objectURL: string | null = null;\n\n /** The File instance the current object URL was created for. */\n private _objectURLFile: File | null = null;\n\n /**\n * The chip's content, resolved from whichever shape `upload` holds. Stated name\n * and type win where they exist; a `File` supplies them otherwise. Both shapes may\n * carry a `File`, so this branches on the `File` rather than on the shape.\n */\n private get _resolved(): ResolvedFile | null {\n const value = this.upload;\n if (!value) {\n return null;\n }\n\n const attachment = value as FileAttachment;\n const file =\n (value as FileUpload).file instanceof File\n ? (value as FileUpload).file\n : undefined;\n\n if (file) {\n return {\n name: attachment.name ?? file.name,\n mimeType: attachment.mimeType ?? file.type,\n file,\n };\n }\n\n return {\n name: attachment.name,\n mimeType: attachment.mimeType,\n url: attachment.url,\n };\n }\n\n /**\n * Whether `upload` is a staged upload rather than a sent attachment. Keyed on\n * `status`, which only an upload has — an attachment may carry a `File` too, so\n * the `File` no longer tells the two apart.\n */\n private _isUpload(value: FileUpload | FileAttachment): value is FileUpload {\n return typeof (value as FileUpload).status === 'string';\n }\n\n /** Upload status, which only a staged file has. */\n private get _uploadStatus(): string {\n return this.upload && this._isUpload(this.upload) ? this.upload.status : '';\n }\n\n /** Error state, which only a staged file has. */\n private get _uploadError(): { isError: boolean; message: string } {\n if (!this.upload || !this._isUpload(this.upload)) {\n return { isError: false, message: '' };\n }\n return {\n isError: Boolean(this.upload.isError),\n message: this.upload.errorMessage || '',\n };\n }\n\n private _getOrCreateObjectURL(file: File): string | null {\n if (this._objectURLFile !== file) {\n if (this._objectURL) {\n URL.revokeObjectURL(this._objectURL);\n }\n this._objectURL = URL.createObjectURL(file);\n this._objectURLFile = file;\n }\n return this._objectURL;\n }\n\n private _hasMediaPreview(): boolean {\n const resolved = this._resolved;\n if (!resolved) {\n return false;\n }\n\n const type = resolved.mimeType ?? '';\n if (resolved.file) {\n return type.startsWith('image/') || type.startsWith('video/');\n }\n\n // With no `File` to build an object URL from, only a stated URL can stand in,\n // and only for an image that loads. Everything else falls back to a file-type\n // icon.\n return this._canPreviewURL(resolved.url) && type.startsWith('image/');\n }\n\n /** Whether a stated URL is usable as a preview source. */\n private _canPreviewURL(url: string | undefined): url is string {\n return Boolean(url) && url !== this._failedPreviewURL;\n }\n\n updated(changedProperties: PropertyValues) {\n this._syncInjectedStyles();\n\n if (\n changedProperties.has('readOnly') ||\n changedProperties.has('upload') ||\n changedProperties.has('errorDescription') ||\n !this._syncedErrorState\n ) {\n this._syncErrorState();\n }\n }\n\n private _syncedErrorState = false;\n\n /**\n * Carbon hides the invalid icon and leaves its failure message unreferenced, so\n * the chip states the failure itself, in its name, for a screen reader to read\n * when the chip takes focus.\n */\n private async _syncErrorState(): Promise<void> {\n const { isError, message } = this._uploadError;\n const invalid = !this.readOnly && isError;\n\n // `aria-invalid` on a role-less host is dropped, so an input-area chip states\n // a role and names itself. A read-only chip is already a list item in the\n // message list.\n const name = this.readOnly ? undefined : this._resolved?.name;\n // The failure text is folded into the name because an id reference from the\n // host cannot reach into this shadow root, and a group's contents are not read\n // when it takes focus. Focusing the chip then announces the whole failure.\n const failure = this.errorDescription || message;\n const hasFailureToAnnounce = Boolean(invalid && failure && name);\n const label = hasFailureToAnnounce ? `${name}. ${failure}` : name;\n syncAttribute({\n element: this,\n attribute: 'role',\n value: this.readOnly ? undefined : 'group',\n });\n syncAttribute({ element: this, attribute: 'aria-label', value: label });\n // Focusable so keyboard and screen reader users can land on the chip itself,\n // and hear its state.\n syncAttribute({\n element: this,\n attribute: 'tabindex',\n value: this.readOnly ? undefined : '0',\n });\n syncAttribute({\n element: this,\n attribute: 'aria-invalid',\n value: invalid ? 'true' : undefined,\n });\n\n const inner = this.shadowRoot?.querySelector(\n 'cds-file-uploader-item'\n ) as LitElement | null;\n if (!inner) {\n return;\n }\n\n // Carbon draws the invalid icon in its own update, after ours; a failed upload\n // usually also moves `state` from \"uploading\" to \"edit\", which swaps the whole\n // status area. Wait for that render before looking for the icon.\n await inner.updateComplete;\n\n const innerRoot = inner.shadowRoot;\n if (!innerRoot) {\n return;\n }\n this._syncedErrorState = true;\n\n // Carbon hardcodes its WarningFilled icon for the invalid state. Swap in\n // ErrorFilled; the marker keeps repeat syncs from replacing it again.\n const warningIcon = innerRoot.querySelector(\n '.cds--file__state-container .cds--file-invalid:not([data-error-icon])'\n );\n if (invalid && warningIcon) {\n const template = document.createElement('template');\n template.innerHTML = carbonIconToSVG(ErrorFilled16, {\n class: 'cds--file-invalid',\n 'aria-hidden': 'true',\n 'data-error-icon': '',\n });\n warningIcon.replaceWith(template.content);\n }\n }\n\n /**\n * Overrides Carbon's `cds-file-uploader-item` styles from inside its shadow\n * root, since it exposes no `part=` for the affected elements.\n *\n * Keep the existing selector specificity for both constructed sheets and the\n * legacy `<style>` fallback.\n */\n private _syncInjectedStyles() {\n const innerRoot = this.shadowRoot?.querySelector(\n 'cds-file-uploader-item'\n )?.shadowRoot;\n if (!innerRoot) {\n this._injectedStyles = undefined;\n return;\n }\n\n const rules: string[] = [];\n if (this._hasMediaPreview()) {\n rules.push(\n ':host(cds-file-uploader-item) p.cds--file-filename { margin-inline-start: 2px; }'\n );\n }\n if (this.readOnly) {\n rules.push(':host .cds--file__state-container { display: none; }');\n // Carbon hangs the chip's trailing padding off the status container, so\n // hiding it leaves the name flush to the edge against a 1rem leading margin.\n // Restate it on the name to even the two sides up.\n rules.push('.cds--file-filename { margin-inline-end: 1rem; }');\n }\n if (!this.readOnly) {\n // Column gap between the name and the status area.\n rules.push(\n ':host(cds-file-uploader-item[size][size=md]) { gap: 0 var(--cds-spacing-05, 1rem); }'\n );\n // Column gap between the status area's children (error icon, remove button).\n rules.push(\n ':host([size]) .cds--file__state-container { gap: var(--cds-spacing-02, 0.25rem); }'\n );\n }\n if (!this.readOnly && this._uploadError.isError) {\n // Override core component's invalid-state styles: remove its padding and outline, hide\n // inline error text, and redraw the outline so it paints above the content.\n rules.push(':host([invalid][size]) { padding: 0; outline: none; }');\n rules.push(\n ':host([invalid][size]) .cds--form-requirement { display: none; }'\n );\n rules.push(\n ':host([invalid][size])::after { content: \"\"; position: absolute; inset: 0; border-radius: 0.5rem; outline: 2px solid var(--cds-support-error, #da1e28); outline-offset: -2px; pointer-events: none; }'\n );\n rules.push(\n '@media screen and (prefers-contrast) { :host([invalid][size])::after { outline-style: dotted; } }'\n );\n }\n\n this._applyInjectedStyles(innerRoot, rules.join('\\n'));\n }\n\n private _applyInjectedStyles(innerRoot: ShadowRoot, nextText: string) {\n const ownerDocument = innerRoot.ownerDocument;\n const previous = this._injectedStyles;\n if (\n previous?.root === innerRoot &&\n previous.ownerDocument === ownerDocument\n ) {\n previous.styles.update(nextText);\n return;\n }\n // A sheet built for the old document can't stay adopted after the root\n // moves documents. A replaced root takes its old styles with it.\n if (previous?.root === innerRoot) {\n previous.styles.detach();\n }\n this._injectedStyles = {\n root: innerRoot,\n ownerDocument,\n styles: attachRootStyles(innerRoot, nextText),\n };\n }\n\n /** Local to the inner root, so detaching a chip needs no stylesheet mutation. */\n private _injectedStyles?: {\n root: ShadowRoot;\n ownerDocument: Document;\n styles: RootStyles;\n };\n\n connectedCallback() {\n super.connectedCallback();\n // Recheck the document after adoption, even if no public property changed.\n this.requestUpdate();\n }\n\n disconnectedCallback() {\n super.disconnectedCallback();\n if (this._objectURL) {\n URL.revokeObjectURL(this._objectURL);\n this._objectURL = null;\n this._objectURLFile = null;\n }\n }\n\n private _renderPreview() {\n const resolved = this._resolved;\n if (!resolved) {\n return nothing;\n }\n\n const { file, name, url } = resolved;\n const type = resolved.mimeType ?? '';\n\n // Image preview from the live File. An attachment without one falls through to\n // the URL branch below, and failing that to a file-type icon.\n if (file && type.startsWith('image/')) {\n const objectURL = this._getOrCreateObjectURL(file);\n if (!objectURL) {\n return nothing;\n }\n\n return html`<a\n class=\"${prefix}-file-upload-item__preview-wrapper\"\n href=\"${objectURL}\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n aria-label=\"Open image\">\n <img\n class=\"${prefix}-file-upload-item__preview\"\n src=\"${objectURL}\"\n width=\"36\"\n height=\"36\"\n alt=\"\"\n aria-hidden=\"true\" />\n </a>`;\n }\n\n // Video preview\n if (file && type.startsWith('video/')) {\n const objectURL = this._getOrCreateObjectURL(file);\n if (!objectURL) {\n return nothing;\n }\n\n const openVideo = () => {\n const newWindow = isBrowser()\n ? window.open('', '_blank', 'width=800,height=600')\n : null;\n\n if (!newWindow) {\n return;\n }\n\n const style = newWindow.document.createElement('style');\n style.textContent =\n '* { margin: 0; padding: 0; background: #000 } video { display: block; width: 100%; height: 100vh; object-fit: contain }';\n const video = newWindow.document.createElement('video');\n video.src = objectURL;\n video.controls = true;\n video.autoplay = true;\n newWindow.document.title = name ?? '';\n newWindow.document.head.appendChild(style);\n newWindow.document.body.appendChild(video);\n };\n\n return html`<button\n class=\"${prefix}-file-upload-item__preview-wrapper\"\n type=\"button\"\n aria-label=\"Play video\"\n @click=\"${openVideo}\">\n <video\n class=\"${prefix}-file-upload-item__preview\"\n src=\"${objectURL}\"\n width=\"36\"\n height=\"36\"\n preload=\"metadata\"\n muted\n playsinline\n tabindex=\"-1\"\n aria-hidden=\"true\"\n @loadedmetadata=\"${(e: Event) => {\n (e.target as HTMLVideoElement).currentTime = 0.1;\n }}\"></video\n ><span class=\"${prefix}-file-upload-item__play-badge\" aria-hidden=\"true\"\n >${iconLoader(PlayFilledAlt16)}</span\n >\n </button>`;\n }\n\n // Image preview from a stated URL — an attachment whose file lives on a server\n // rather than in the page. No video equivalent: playback would stream the file\n // back, which a chip on a sent message has no business doing.\n if (this._canPreviewURL(url) && type.startsWith('image/')) {\n return html`<a\n class=\"${prefix}-file-upload-item__preview-wrapper\"\n href=\"${url}\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n aria-label=\"Open image\">\n <img\n class=\"${prefix}-file-upload-item__preview\"\n src=\"${url}\"\n width=\"36\"\n height=\"36\"\n alt=\"\"\n aria-hidden=\"true\"\n @error=\"${() => {\n this._failedPreviewURL = url;\n }}\" />\n </a>`;\n }\n\n // File type icon (for supported icons)\n const icon = pickFileTypeIcon(name, type);\n if (icon) {\n return html`<span\n class=\"${prefix}-file-upload-item__icon\"\n aria-hidden=\"true\"\n >${iconLoader(icon)}</span\n >`;\n }\n\n return nothing;\n }\n\n private _handleRemove() {\n if (!this.upload) {\n return;\n }\n\n this.dispatchEvent(\n new CustomEvent<FileRemoveEventDetail>('cds-aichat-file-remove', {\n detail: { fileId: this.upload.id },\n bubbles: true,\n composed: true,\n })\n );\n }\n\n render() {\n const resolved = this._resolved;\n if (!resolved) {\n return nothing;\n }\n\n // An empty state falls through Carbon's status switch, rendering no\n // affordance. `_syncInjectedStyles` collapses the container it still reserves.\n const state = this.readOnly ? '' : this._uploadStatus;\n const error = this._uploadError;\n\n return html`\n <cds-file-uploader-item\n size=\"md\"\n .state=\"${state}\"\n .iconDescription=\"${\n state === 'uploading'\n ? this.uploadingFileLabel\n : this.removeFileNamedLabel || this.removeFileLabel\n }\"\n .errorSubject=\"${error.message}\"\n ?invalid=\"${!this.readOnly && error.isError}\"\n @cds-file-uploader-item-deleted=\"${this._handleRemove}\">\n ${this._renderPreview()} ${resolved.name || this.fallbackLabel}\n </cds-file-uploader-item>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'cds-aichat-file-upload-item': FileUploadItemElement;\n }\n}\n\nexport default FileUploadItemElement;\n"],"names":[],"mappings":";;;;;;;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SAAS,EAAE,yBAAyB,EAAE;AAClC,CAAA,EAAA,qBAAA,CAAA,SAAA,EAAA,sBAAA,EAAA,MAAA,CAAA;AAI9B,UAAA,CAAA;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,sBAAsB,EAAE;AAC5B,CAAA,EAAA,qBAAA,CAAA,SAAA,EAAA,oBAAA,EAAA,MAAA,CAAA;AAOjC,UAAA,CAAA;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,mBAAmB,EAAE;AAChC,CAAA,EAAA,qBAAA,CAAA,SAAA,EAAA,kBAAA,EAAA,MAAA,CAAA;AAI1B,UAAA,CAAA;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE;AAC1B,CAAA,EAAA,qBAAA,CAAA,SAAA,EAAA,eAAA,EAAA,MAAA,CAAA;AASrB,UAAA,CAAA;AADP,IAAA,KAAK;AAC0C,CAAA,EAAA,qBAAA,CAAA,SAAA,EAAA,mBAAA,EAAA,MAAA,CAAA;AArD5C,qBAAqB,GAAA,UAAA,CAAA;AAD1B,IAAA,aAAa,CAAC,CAAA,EAAG,MAAM,CAAA,iBAAA,CAAmB;AACrC,CAAA,EAAA,qBAAqB,CAqf1B;AAQD,8BAAe,qBAAqB;;"}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import { css } from 'lit';
|
|
9
9
|
|
|
10
|
-
var styles = css([":host{display:block;margin-inline-end:.5rem}cds-file-uploader-item{border-radius:.5rem;font-size:var(--cds-body-compact-01-font-size,.875rem);font-weight:var(--cds-body-compact-01-font-weight,400);letter-spacing:var(--cds-body-compact-01-letter-spacing,.16px);line-height:var(--cds-body-compact-01-line-height,1.28572)}.cds-aichat-file-upload-item__preview-wrapper{block-size:36px;border-radius:6px;display:inline-block;inline-size:36px;margin-inline-end:1rem;overflow:hidden;position:relative;vertical-align:middle}.cds-aichat-file-upload-
|
|
10
|
+
var styles = css([":host{display:inline-block;margin-inline-end:.5rem}:host(:focus){outline:none}cds-file-uploader-item{border-radius:.5rem;font-size:var(--cds-body-compact-01-font-size,.875rem);font-weight:var(--cds-body-compact-01-font-weight,400);inline-size:-moz-max-content;inline-size:max-content;letter-spacing:var(--cds-body-compact-01-letter-spacing,.16px);line-height:var(--cds-body-compact-01-line-height,1.28572);position:relative}:host(:focus-visible) cds-file-uploader-item:after{border-radius:.5rem;content:\"\";inset:0;outline:2px solid var(--cds-focus,#0f62fe);outline-offset:-2px;pointer-events:none;position:absolute}.cds-aichat-file-upload-item__preview-wrapper{background:none;block-size:36px;border:0;border-radius:6px;color:inherit;cursor:pointer;display:inline-block;inline-size:36px;margin-inline-end:1rem;overflow:hidden;padding:0;position:relative;text-decoration:none;vertical-align:middle}.cds-aichat-file-upload-item__preview-wrapper:focus{outline:none}.cds-aichat-file-upload-item__preview-wrapper:focus-visible{outline:2px solid var(--cds-focus,#0f62fe);outline-offset:-2px}.cds-aichat-file-upload-item__play-badge{align-items:center;background:rgba(0,0,0,.6);block-size:.75rem;border-radius:6px;display:flex;inline-size:1rem;inset-block-end:.125rem;inset-inline-end:0;inset-inline-start:.25rem;justify-content:center;pointer-events:none;position:absolute}.cds-aichat-file-upload-item__play-badge svg{block-size:.5rem;fill:#fff;inline-size:.5rem}.cds-aichat-file-upload-item__preview{block-size:100%;display:block;inline-size:100%;-o-object-fit:cover;object-fit:cover}.cds-aichat-file-upload-item__icon{align-items:center;display:inline-flex;margin-inline-end:.5rem;vertical-align:middle}"]);
|
|
11
11
|
|
|
12
12
|
export { styles as default };
|
|
13
13
|
//# sourceMappingURL=file-upload-item.scss.js.map
|
|
@@ -26,6 +26,13 @@ declare class FileUploadsElement extends LitElement {
|
|
|
26
26
|
static styles: import("lit").CSSResult;
|
|
27
27
|
/** Array of file uploads to display. */
|
|
28
28
|
uploads: FileUpload[];
|
|
29
|
+
/**
|
|
30
|
+
* Returns the sorted order of uploads for display. When errors are present,
|
|
31
|
+
* errored uploads appear first (alphabetical by name), followed by healthy
|
|
32
|
+
* uploads (alphabetical by name). When no errors are present, all uploads
|
|
33
|
+
* are sorted alphabetically by name.
|
|
34
|
+
*/
|
|
35
|
+
private get _sortedUploads();
|
|
29
36
|
/** Label for the remove file button, used when no file name is available. */
|
|
30
37
|
removeFileLabel: string;
|
|
31
38
|
/**
|
|
@@ -79,9 +86,22 @@ declare class FileUploadsElement extends LitElement {
|
|
|
79
86
|
private _announcer;
|
|
80
87
|
/** Previous-frame snapshot keyed by upload id, used to detect transitions. */
|
|
81
88
|
private _snapshots;
|
|
89
|
+
/**
|
|
90
|
+
* The element holding focus before a re-render. Reordering chips moves their
|
|
91
|
+
* DOM nodes, and moving a focused node drops focus, so it is put back once
|
|
92
|
+
* the move is done.
|
|
93
|
+
*/
|
|
94
|
+
private _focusedBeforeUpdate;
|
|
82
95
|
private _resizeObserver;
|
|
83
96
|
private _checkOverflow;
|
|
84
97
|
protected firstUpdated(): void;
|
|
98
|
+
/**
|
|
99
|
+
* Returns the element that holds focus inside this list. Focus can sit on a
|
|
100
|
+
* chip or on the Remove button nested in Carbon's shadow root, so the depth
|
|
101
|
+
* varies; walk down rather than assume it.
|
|
102
|
+
*/
|
|
103
|
+
private _deepActiveElement;
|
|
104
|
+
protected willUpdate(changedProperties: PropertyValues): void;
|
|
85
105
|
disconnectedCallback(): void;
|
|
86
106
|
protected updated(changedProperties: PropertyValues): void;
|
|
87
107
|
private _snapshotOf;
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { __decorate } from 'tslib';
|
|
9
9
|
import { unsafeCSS, css, LitElement, nothing, html } from 'lit';
|
|
10
10
|
import { property, state } from 'lit/decorators.js';
|
|
11
|
+
import { repeat } from 'lit/directives/repeat.js';
|
|
11
12
|
import { AriaAnnouncerManager } from '../../../globals/utils/aria-announcer-manager.js';
|
|
12
13
|
import { carbonElement } from '../../../globals/decorators/carbon-element.js';
|
|
13
14
|
import prefix from '../../../globals/settings.js';
|
|
@@ -85,10 +86,33 @@ let FileUploadsElement = class FileUploadsElement extends LitElement {
|
|
|
85
86
|
this._announcer = new AriaAnnouncerManager();
|
|
86
87
|
/** Previous-frame snapshot keyed by upload id, used to detect transitions. */
|
|
87
88
|
this._snapshots = new Map();
|
|
89
|
+
/**
|
|
90
|
+
* The element holding focus before a re-render. Reordering chips moves their
|
|
91
|
+
* DOM nodes, and moving a focused node drops focus, so it is put back once
|
|
92
|
+
* the move is done.
|
|
93
|
+
*/
|
|
94
|
+
this._focusedBeforeUpdate = null;
|
|
88
95
|
this._resizeObserver = new ResizeObserver(() => {
|
|
89
96
|
this._checkOverflow();
|
|
90
97
|
});
|
|
91
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Returns the sorted order of uploads for display. When errors are present,
|
|
101
|
+
* errored uploads appear first (alphabetical by name), followed by healthy
|
|
102
|
+
* uploads (alphabetical by name). When no errors are present, all uploads
|
|
103
|
+
* are sorted alphabetically by name.
|
|
104
|
+
*/
|
|
105
|
+
get _sortedUploads() {
|
|
106
|
+
const errored = this.uploads.filter((u) => u.isError);
|
|
107
|
+
const healthy = this.uploads.filter((u) => !u.isError);
|
|
108
|
+
const byName = (a, b) => (a.file?.name ?? '').localeCompare(b.file?.name ?? '', undefined, {
|
|
109
|
+
sensitivity: 'base',
|
|
110
|
+
});
|
|
111
|
+
if (errored.length > 0) {
|
|
112
|
+
return [...errored.sort(byName), ...healthy.sort(byName)];
|
|
113
|
+
}
|
|
114
|
+
return [...this.uploads].sort(byName);
|
|
115
|
+
}
|
|
92
116
|
_checkOverflow() {
|
|
93
117
|
const container = this.renderRoot.querySelector(`.${prefix}--file-uploads-container`);
|
|
94
118
|
this._hasOverflow =
|
|
@@ -104,12 +128,34 @@ let FileUploadsElement = class FileUploadsElement extends LitElement {
|
|
|
104
128
|
// input is hidden and re-shown, and a blocking failure must not be swallowed.
|
|
105
129
|
this._snapshots = this._snapshotOf(this.uploads.filter((upload) => !upload.isError));
|
|
106
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Returns the element that holds focus inside this list. Focus can sit on a
|
|
133
|
+
* chip or on the Remove button nested in Carbon's shadow root, so the depth
|
|
134
|
+
* varies; walk down rather than assume it.
|
|
135
|
+
*/
|
|
136
|
+
_deepActiveElement() {
|
|
137
|
+
let active = this.shadowRoot?.activeElement ?? null;
|
|
138
|
+
while (active?.shadowRoot?.activeElement) {
|
|
139
|
+
active = active.shadowRoot.activeElement;
|
|
140
|
+
}
|
|
141
|
+
return active;
|
|
142
|
+
}
|
|
143
|
+
willUpdate(changedProperties) {
|
|
144
|
+
this._focusedBeforeUpdate = changedProperties.has('uploads')
|
|
145
|
+
? this._deepActiveElement()
|
|
146
|
+
: null;
|
|
147
|
+
}
|
|
107
148
|
disconnectedCallback() {
|
|
108
149
|
this._resizeObserver.disconnect();
|
|
109
150
|
this._announcer.disconnect();
|
|
110
151
|
super.disconnectedCallback();
|
|
111
152
|
}
|
|
112
153
|
updated(changedProperties) {
|
|
154
|
+
const focused = this._focusedBeforeUpdate;
|
|
155
|
+
this._focusedBeforeUpdate = null;
|
|
156
|
+
if (focused?.isConnected && this._deepActiveElement() !== focused) {
|
|
157
|
+
focused.focus();
|
|
158
|
+
}
|
|
113
159
|
if (changedProperties.has('uploads')) {
|
|
114
160
|
this.toggleAttribute('has-uploads', this.uploads.length > 0);
|
|
115
161
|
this._announceTransitions();
|
|
@@ -215,6 +261,7 @@ let FileUploadsElement = class FileUploadsElement extends LitElement {
|
|
|
215
261
|
// continue to bubble to the consumer. No need to re-dispatch.
|
|
216
262
|
}
|
|
217
263
|
render() {
|
|
264
|
+
const sorted = this._sortedUploads;
|
|
218
265
|
return html `
|
|
219
266
|
<div class="${prefix}--file-uploads-live-region" aria-live="polite"></div>
|
|
220
267
|
<div class="${prefix}--file-uploads-live-region" aria-live="polite"></div>
|
|
@@ -229,7 +276,7 @@ let FileUploadsElement = class FileUploadsElement extends LitElement {
|
|
|
229
276
|
<div
|
|
230
277
|
class="${prefix}--file-uploads-gradient-wrapper${this._hasOverflow ? ` ${prefix}--file-uploads-gradient-wrapper--overflow` : ''}">
|
|
231
278
|
<div class="${prefix}--file-uploads-container">
|
|
232
|
-
${
|
|
279
|
+
${repeat(sorted, (upload) => upload.id, (upload) => html `
|
|
233
280
|
<cds-aichat-file-upload-item
|
|
234
281
|
.upload="${upload}"
|
|
235
282
|
remove-file-label="${this.removeFileLabel}"
|
|
@@ -237,6 +284,13 @@ let FileUploadsElement = class FileUploadsElement extends LitElement {
|
|
|
237
284
|
name: upload.file?.name,
|
|
238
285
|
})}"
|
|
239
286
|
uploading-file-label="${this.uploadingFileLabel}"
|
|
287
|
+
error-description="${upload.isError
|
|
288
|
+
? this.getFileUploadFailureText({
|
|
289
|
+
messages: upload.errorMessage
|
|
290
|
+
? [upload.errorMessage]
|
|
291
|
+
: [],
|
|
292
|
+
})
|
|
293
|
+
: ''}"
|
|
240
294
|
@cds-aichat-file-remove="${this._handleFileRemove}"></cds-aichat-file-upload-item>
|
|
241
295
|
`)}
|
|
242
296
|
</div>
|