Skip to content

Commit 871acea

Browse files
committed
fix(user-message): register and classify attachments
1 parent 30b7836 commit 871acea

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

2nd-gen/packages/swc/patterns/conversational-ai/user-message/UserMessage.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export class UserMessage extends SpectrumElement {
101101
attributes: true,
102102
attributeFilter: ['type'],
103103
childList: true,
104+
subtree: true,
104105
},
105106
callback: () => {
106107
this._routeAttachments();
@@ -137,13 +138,19 @@ export class UserMessage extends SpectrumElement {
137138
(element): element is UserMessageAttachment =>
138139
this._isAttachmentElement(element)
139140
);
140-
const mediaAttachments = attachments.filter((el) => el.type !== 'card');
141-
const cardAttachments = attachments.filter((el) => el.type === 'card');
141+
const mediaAttachments = attachments.filter(
142+
(el) => el.getAttribute('type') !== 'card'
143+
);
144+
const cardAttachments = attachments.filter(
145+
(el) => el.getAttribute('type') === 'card'
146+
);
142147
const hasOverflow = mediaAttachments.length > VISIBLE_MEDIA_COUNT;
143148

144149
for (const el of attachments) {
145150
const targetSlot =
146-
el.type === 'card' ? 'attachment-card' : 'attachment-media';
151+
el.getAttribute('type') === 'card'
152+
? 'attachment-card'
153+
: 'attachment-media';
147154
if (el.getAttribute('slot') !== targetSlot) {
148155
el.setAttribute('slot', targetSlot);
149156
}
@@ -179,7 +186,8 @@ export class UserMessage extends SpectrumElement {
179186
hasOverflow: boolean
180187
): void {
181188
const visible = mediaAttachments.filter(
182-
(_el, index) => !(hasOverflow && !this.open && index >= VISIBLE_MEDIA_COUNT)
189+
(_el, index) =>
190+
!(hasOverflow && !this.open && index >= VISIBLE_MEDIA_COUNT)
183191
);
184192
const total = visible.length;
185193
const columnCount = Math.max(1, Math.min(total, VISIBLE_MEDIA_COUNT));

2nd-gen/packages/swc/patterns/conversational-ai/user-message/swc-user-message.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
*/
1212
import { defineElement } from '@adobe/spectrum-wc-core/element/index.js';
1313

14+
import './user-message-attachment/index.js';
15+
1416
import { UserMessage } from './UserMessage.js';
1517

1618
declare global {

2nd-gen/packages/swc/patterns/conversational-ai/user-message/user-message-attachment/UserMessageAttachment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export class UserMessageAttachment extends SpectrumElement {
162162
protected override render(): TemplateResult {
163163
return html`
164164
<div class="swc-UserMessageAttachment">
165-
${this.type === 'card'
165+
${this.getAttribute('type') === 'card'
166166
? this._renderCardSurface()
167167
: this._renderMediaSurface()}
168168
</div>

0 commit comments

Comments
 (0)