@copilotkit/web-components 1.62.2-canary.1783457132 → 1.62.3

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.
@@ -89,9 +89,9 @@ const iconDelete = html`
89
89
  <line x1="14" x2="14" y1="11" y2="17" />
90
90
  </svg>
91
91
  `;
92
- const iconLauncher = html`
92
+ const iconSidebar = html`
93
93
  <svg
94
- class="launcher-icon"
94
+ class="icon"
95
95
  viewBox="0 0 24 24"
96
96
  fill="none"
97
97
  stroke="currentColor"
@@ -102,7 +102,51 @@ const iconLauncher = html`
102
102
  >
103
103
  <rect width="18" height="18" x="3" y="3" rx="2" />
104
104
  <path d="M9 3v18" />
105
- <path d="m14 9 3 3-3 3" />
105
+ </svg>
106
+ `;
107
+ /**
108
+ * Header / control icons for the redesigned drawer chrome (ENT-1051). Inlined
109
+ * lucide glyphs (`square-plus`, `filter`, `ellipsis-vertical`) drawn with
110
+ * `currentColor` so they inherit the button's themed color — the element cannot
111
+ * depend on a React icon library.
112
+ */
113
+ const iconPlusSquare = html`
114
+ <svg
115
+ class="icon"
116
+ viewBox="0 0 24 24"
117
+ fill="none"
118
+ stroke="currentColor"
119
+ stroke-width="2"
120
+ stroke-linecap="round"
121
+ stroke-linejoin="round"
122
+ aria-hidden="true"
123
+ >
124
+ <rect width="18" height="18" x="3" y="3" rx="2" />
125
+ <path d="M8 12h8" />
126
+ <path d="M12 8v8" />
127
+ </svg>
128
+ `;
129
+ const iconFunnel = html`
130
+ <svg
131
+ class="icon"
132
+ viewBox="0 0 24 24"
133
+ fill="none"
134
+ stroke="currentColor"
135
+ stroke-width="2"
136
+ stroke-linecap="round"
137
+ stroke-linejoin="round"
138
+ aria-hidden="true"
139
+ >
140
+ <line x1="3" y1="5" x2="21" y2="5" />
141
+ <line x1="6" y1="12" x2="18" y2="12" />
142
+ <line x1="10" y1="19" x2="14" y2="19" />
143
+ </svg>
144
+ `;
145
+ const iconKebab = html`
146
+ <svg class="icon" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
147
+ <circle cx="12" cy="5" r="1.6" />
148
+ <circle cx="12" cy="12" r="1.6" />
149
+ <circle cx="12" cy="19" r="1.6" />
106
150
  </svg>
107
151
  `;
108
152
  /**
@@ -111,7 +155,7 @@ const iconLauncher = html`
111
155
  *
112
156
  * Pure VIEW: domain data (threads/loading/error/etc.) comes IN as properties and
113
157
  * user intent goes OUT as bubbling+composed DOM `CustomEvent`s. The element owns
114
- * VIEW state (open/collapsed, Active/All filter, confirm-delete dialog, per-row
158
+ * VIEW state (open, Active/All filter, confirm-delete dialog, per-row
115
159
  * animations) while the consumer owns DOMAIN state. `open` is additionally
116
160
  * externally controllable via the `open` property + `open-change` event so a
117
161
  * host can coordinate mobile open/close.
@@ -122,6 +166,7 @@ var CopilotKitThreadsDrawer = class extends LitElement {
122
166
  constructor(..._args) {
123
167
  super(..._args);
124
168
  this.label = "Threads";
169
+ this.recentLabel = "Recent Conversations";
125
170
  this.threads = [];
126
171
  this.loading = false;
127
172
  this.error = null;
@@ -131,21 +176,34 @@ var CopilotKitThreadsDrawer = class extends LitElement {
131
176
  this.hasMore = false;
132
177
  this.fetchingMore = false;
133
178
  this.fetchMoreError = null;
134
- this.open = true;
179
+ this.open = false;
135
180
  this.collapsed = false;
181
+ this.collapsible = true;
136
182
  this._filter = "active";
137
183
  this._confirmingDeleteId = null;
138
184
  this._viewportIsMobile = false;
185
+ this._hasHeader = false;
139
186
  this._hasMemories = false;
140
187
  this._hasFooter = false;
188
+ this._filterOpen = false;
189
+ this._openMenuId = null;
141
190
  this._mediaQuery = null;
142
191
  this._onMediaChange = (event) => {
143
192
  this._viewportIsMobile = event.matches;
144
193
  };
145
194
  this._onKeyDown = (event) => {
146
195
  if (event.key === "Escape") {
196
+ if (this._openMenuId !== null) {
197
+ this._openMenuId = null;
198
+ event.stopPropagation();
199
+ return;
200
+ }
201
+ if (this._filterOpen) {
202
+ this._filterOpen = false;
203
+ event.stopPropagation();
204
+ return;
205
+ }
147
206
  if (this._confirmingDeleteId !== null) {
148
- this._confirmingDeleteId = null;
149
207
  event.stopPropagation();
150
208
  return;
151
209
  }
@@ -157,8 +215,23 @@ var CopilotKitThreadsDrawer = class extends LitElement {
157
215
  }
158
216
  if (event.key === "Tab") this._trapTab(event);
159
217
  };
218
+ this._onDocumentPointerDown = (event) => {
219
+ if (!this._filterOpen && this._openMenuId === null) return;
220
+ const path = event.composedPath();
221
+ if (this._filterOpen) {
222
+ const popover = this.renderRoot.querySelector("[part=\"filters\"]");
223
+ const trigger = this.renderRoot.querySelector("[part=\"filter-toggle\"]");
224
+ if (!(popover && path.includes(popover) || trigger && path.includes(trigger))) this._filterOpen = false;
225
+ }
226
+ if (this._openMenuId !== null) {
227
+ const popover = this.renderRoot.querySelector("[part=\"row-menu-popover\"]");
228
+ const trigger = this.renderRoot.querySelector(".row.menu-open [part=\"row-menu\"]");
229
+ if (!(popover && path.includes(popover) || trigger && path.includes(trigger))) this._openMenuId = null;
230
+ }
231
+ };
160
232
  this._seenNamed = /* @__PURE__ */ new Set();
161
233
  this._justRevealed = /* @__PURE__ */ new Set();
234
+ this._repositionConfirm = () => this._positionConfirmDialog();
162
235
  this._scrollLocked = false;
163
236
  this._prevBodyOverflow = "";
164
237
  this._trapTab = (event) => {
@@ -207,6 +280,11 @@ var CopilotKitThreadsDrawer = class extends LitElement {
207
280
  type: String
208
281
  },
209
282
  label: { type: String },
283
+ recentLabel: {
284
+ attribute: "recent-label",
285
+ type: String
286
+ },
287
+ collapsible: { type: Boolean },
210
288
  open: {
211
289
  type: Boolean,
212
290
  reflect: true
@@ -218,8 +296,11 @@ var CopilotKitThreadsDrawer = class extends LitElement {
218
296
  _filter: { state: true },
219
297
  _confirmingDeleteId: { state: true },
220
298
  _viewportIsMobile: { state: true },
299
+ _hasHeader: { state: true },
221
300
  _hasMemories: { state: true },
222
- _hasFooter: { state: true }
301
+ _hasFooter: { state: true },
302
+ _filterOpen: { state: true },
303
+ _openMenuId: { state: true }
223
304
  };
224
305
  }
225
306
  connectedCallback() {
@@ -230,11 +311,18 @@ var CopilotKitThreadsDrawer = class extends LitElement {
230
311
  this._mediaQuery.addEventListener("change", this._onMediaChange);
231
312
  }
232
313
  this.addEventListener("keydown", this._onKeyDown);
314
+ if (typeof document !== "undefined") document.addEventListener("pointerdown", this._onDocumentPointerDown);
233
315
  }
234
316
  disconnectedCallback() {
235
317
  super.disconnectedCallback();
236
318
  this._mediaQuery?.removeEventListener("change", this._onMediaChange);
237
319
  this.removeEventListener("keydown", this._onKeyDown);
320
+ if (typeof document !== "undefined") document.removeEventListener("pointerdown", this._onDocumentPointerDown);
321
+ if (typeof window !== "undefined") {
322
+ window.removeEventListener("scroll", this._repositionConfirm, true);
323
+ window.removeEventListener("resize", this._repositionConfirm);
324
+ }
325
+ if (typeof document !== "undefined") document.documentElement.style.removeProperty("--cpk-drawer-reserved-width");
238
326
  this._releaseScrollLock();
239
327
  }
240
328
  willUpdate(changed) {
@@ -252,6 +340,9 @@ var CopilotKitThreadsDrawer = class extends LitElement {
252
340
  if (this._confirmingDeleteId !== null) {
253
341
  if (!this._visibleThreads().some((t) => t.id === this._confirmingDeleteId)) this._confirmingDeleteId = null;
254
342
  }
343
+ if (this._openMenuId !== null) {
344
+ if (!this._visibleThreads().some((t) => t.id === this._openMenuId)) this._openMenuId = null;
345
+ }
255
346
  }
256
347
  }
257
348
  updated(changed) {
@@ -259,22 +350,22 @@ var CopilotKitThreadsDrawer = class extends LitElement {
259
350
  this._applyScrollLock();
260
351
  this._focusFirstFocusable();
261
352
  } else this._releaseScrollLock();
353
+ if (changed.has("collapsed") || changed.has("collapsible") || changed.has("_viewportIsMobile")) this._syncReservedWidth();
354
+ const dialog = this.renderRoot.querySelector("dialog");
355
+ if (dialog) {
356
+ const id = this._confirmingDeleteId;
357
+ if (id !== null && !dialog.open) {
358
+ typeof dialog.showModal === "function" ? dialog.showModal() : dialog.setAttribute("open", "");
359
+ this._positionConfirmDialog();
360
+ window.addEventListener("scroll", this._repositionConfirm, true);
361
+ window.addEventListener("resize", this._repositionConfirm);
362
+ } else if (id === null && dialog.open) {
363
+ typeof dialog.close === "function" ? dialog.close() : dialog.removeAttribute("open");
364
+ window.removeEventListener("scroll", this._repositionConfirm, true);
365
+ window.removeEventListener("resize", this._repositionConfirm);
366
+ }
367
+ }
262
368
  if (this._justRevealed.size > 0) this._justRevealed = /* @__PURE__ */ new Set();
263
- this._syncNameClipping();
264
- }
265
- /**
266
- * Marks each row whose name text is truncated with `name-clipped`, so the CSS
267
- * shows the name tooltip ONLY when the full name isn't already visible (an
268
- * always-on bubble over every row on hover would be noise). Measured after
269
- * render because truncation depends on the laid-out width.
270
- */
271
- _syncNameClipping() {
272
- this.renderRoot.querySelectorAll(".row-name").forEach((name) => {
273
- const text = name.querySelector(".row-name-text");
274
- const clipped = !!text && text.scrollWidth > text.clientWidth;
275
- name.classList.toggle("name-clipped", clipped);
276
- name.closest(".row")?.classList.toggle("name-clipped", clipped);
277
- });
278
369
  }
279
370
  _isMobileModalOpen() {
280
371
  return this._viewportIsMobile && this.open;
@@ -284,6 +375,63 @@ var CopilotKitThreadsDrawer = class extends LitElement {
284
375
  this.open = next;
285
376
  this._emit("open-change", { open: next });
286
377
  }
378
+ _setCollapsed(next) {
379
+ if (this.collapsed === next) return;
380
+ this.collapsed = next;
381
+ this._emit("collapse-change", { collapsed: next });
382
+ }
383
+ /**
384
+ * Signal the drawer's reserved layout width to the host so a desktop collapse
385
+ * reclaims the column instead of leaving an empty gap. On desktop-collapse we
386
+ * set `--cpk-drawer-reserved-width: 0px` on the document root; a host whose
387
+ * grid reads `grid-template-columns: var(--cpk-drawer-reserved-width, 320px) …`
388
+ * inherits it and collapses the track (with its own transition). Expanded/mobile
389
+ * clears the override so the host's fallback width applies — which also means
390
+ * the default (expanded) render never sets it, so there is no hydration flicker.
391
+ *
392
+ * It is set on `document.documentElement` (not `parentElement`) BECAUSE the
393
+ * element is nested inside a framework wrapper host, so its parent is the
394
+ * wrapper — not the grid container, which is an ancestor a child's custom
395
+ * property can't reach. `:root` inheritance reaches the grid regardless of
396
+ * wrapper nesting. Best-effort + namespaced, single-drawer-per-document; a host
397
+ * with multiple drawers or a custom layout should instead react to the
398
+ * `collapse-change` event.
399
+ */
400
+ _syncReservedWidth() {
401
+ if (typeof document === "undefined") return;
402
+ const desktopCollapsed = this.collapsible && this.collapsed && !this._viewportIsMobile;
403
+ const root = document.documentElement;
404
+ if (desktopCollapsed) root.style.setProperty("--cpk-drawer-reserved-width", "0px");
405
+ else root.style.removeProperty("--cpk-drawer-reserved-width");
406
+ }
407
+ /**
408
+ * Center the confirm-delete <dialog> over the drawer PANEL's on-screen box
409
+ * (not the viewport). The dialog stays a top-layer `showModal()` element so it
410
+ * is never clipped, but we drive its center via `--confirm-cx/cy` measured
411
+ * from the visible `.root` rect — so it reads as "inside the drawer" per the
412
+ * ENT-1051 design while keeping the top-layer robustness. Falls back to
413
+ * viewport-center (the CSS default) when the panel isn't measurable
414
+ * (SSR/jsdom).
415
+ */
416
+ _positionConfirmDialog() {
417
+ const dialog = this.renderRoot.querySelector("dialog");
418
+ const root = this.renderRoot.querySelector(".root");
419
+ if (!dialog) return;
420
+ const rect = root?.getBoundingClientRect();
421
+ if (!rect || rect.width === 0 && rect.height === 0) {
422
+ dialog.style.removeProperty("--confirm-cx");
423
+ dialog.style.removeProperty("--confirm-cy");
424
+ return;
425
+ }
426
+ const vw = window.innerWidth;
427
+ const vh = window.innerHeight;
428
+ const visLeft = Math.max(rect.left, 0);
429
+ const visRight = Math.min(rect.right, vw);
430
+ const visTop = Math.max(rect.top, 0);
431
+ const visBottom = Math.min(rect.bottom, vh);
432
+ dialog.style.setProperty("--confirm-cx", `${(visLeft + visRight) / 2}px`);
433
+ dialog.style.setProperty("--confirm-cy", `${(visTop + visBottom) / 2}px`);
434
+ }
287
435
  _setFilter(next) {
288
436
  if (this._filter === next) return;
289
437
  this._filter = next;
@@ -362,22 +510,17 @@ var CopilotKitThreadsDrawer = class extends LitElement {
362
510
  });
363
511
  }
364
512
  render() {
513
+ const desktopCollapsed = this.collapsible && this.collapsed && !this._viewportIsMobile;
514
+ const mobileClosed = this._viewportIsMobile && !this.open;
515
+ const showCluster = desktopCollapsed || mobileClosed;
365
516
  const rootClasses = {
366
517
  root: true,
367
- collapsed: this.collapsed && !this._viewportIsMobile,
368
518
  mobile: this._viewportIsMobile,
369
519
  open: this.open,
370
- confirming: this._confirmingDeleteId !== null
520
+ collapsed: desktopCollapsed
371
521
  };
372
522
  return html`
373
- ${this._viewportIsMobile && !this.open ? html`<button
374
- class="launcher"
375
- part="launcher"
376
- aria-label="Open threads"
377
- @click=${() => this._setOpen(true)}
378
- >
379
- <slot name="launcher-icon">${iconLauncher}</slot>
380
- </button>` : nothing}
523
+ ${showCluster ? this._renderCluster() : nothing}
381
524
  ${this._isMobileModalOpen() ? html`<button
382
525
  class="backdrop"
383
526
  part="backdrop"
@@ -389,46 +532,153 @@ var CopilotKitThreadsDrawer = class extends LitElement {
389
532
  part="root"
390
533
  role=${this._isMobileModalOpen() ? "dialog" : "region"}
391
534
  aria-modal=${this._isMobileModalOpen() ? "true" : nothing}
535
+ aria-hidden=${desktopCollapsed ? "true" : nothing}
392
536
  aria-label=${this.label}
393
537
  >
394
- ${this._renderHeader()} ${this._renderBody()} ${this._renderMemories()}
395
- ${this._renderFooter()} ${this._renderConfirmDialog()}
538
+ ${desktopCollapsed ? nothing : html`${this._renderHeader()} ${this._renderBody()}
539
+ ${this._renderMemories()} ${this._renderFooter()}
540
+ ${this._renderConfirmDialog()}`}
396
541
  </div>
397
542
  `;
398
543
  }
399
- _renderHeader() {
544
+ /**
545
+ * Floating launcher cluster from the Figma "closed" mockup: a sidebar-glyph
546
+ * toggle + a "New Conversation" (+) icon button. Shown in TWO states — the
547
+ * mobile closed state (toggle opens the off-canvas modal) and the desktop
548
+ * collapsed state (toggle expands the sidebar). The primary toggle keeps
549
+ * `part="launcher"` for mobile-launcher theme compat; the new-thread button is
550
+ * suppressed in the locked/unlicensed view, mirroring the New Conversation row.
551
+ */
552
+ _renderCluster() {
553
+ const onToggle = this._viewportIsMobile ? () => this._setOpen(true) : () => this._setCollapsed(false);
400
554
  return html`
401
- <div class="header" part="header">
402
- <slot name="header"><span>${this.label}</span></slot>
555
+ <div class="launcher-cluster" part="launcher-cluster">
403
556
  <button
404
- class="primary"
405
- part="new-thread-button"
406
- aria-label="New thread"
407
- @click=${() => this._emit("new-thread", {})}
557
+ class="launcher"
558
+ part="launcher"
559
+ aria-label=${this._viewportIsMobile ? "Open threads" : "Expand threads"}
560
+ @click=${onToggle}
408
561
  >
409
- + New
562
+ <slot name="launcher-icon">${iconSidebar}</slot>
410
563
  </button>
564
+ ${this.licensed ? html`<button
565
+ class="launcher launcher-new-thread"
566
+ part="launcher-new-thread"
567
+ aria-label="New Conversation"
568
+ @click=${() => this._emit("new-thread", {})}
569
+ >
570
+ ${iconPlusSquare}
571
+ </button>` : nothing}
411
572
  </div>
412
- ${this.licensed && (!hasErrorMessage(this.error) || this.threads.length > 0) ? html`
413
- <div class="filters" part="filters" role="group" aria-label="Filter threads">
573
+ `;
574
+ }
575
+ _renderHeader() {
576
+ const showMobileClose = this._viewportIsMobile && this.open;
577
+ const showCollapseToggle = this.collapsible && !this._viewportIsMobile;
578
+ return html`
579
+ <div
580
+ class="header"
581
+ part="header"
582
+ ?hidden=${!this._hasHeader && !showMobileClose && !showCollapseToggle}
583
+ >
584
+ <slot
585
+ name="header"
586
+ @slotchange=${(e) => {
587
+ this._hasHeader = e.target.assignedElements().length > 0;
588
+ }}
589
+ ></slot>
590
+ ${showCollapseToggle ? html`<button
591
+ class="icon-btn"
592
+ part="collapse-toggle"
593
+ aria-label="Collapse threads"
594
+ @click=${() => this._setCollapsed(true)}
595
+ >
596
+ ${iconSidebar}
597
+ </button>` : nothing}
598
+ ${showMobileClose ? html`<button
599
+ class="icon-btn"
600
+ part="close-toggle"
601
+ aria-label="Close threads"
602
+ @click=${() => this._setOpen(false)}
603
+ >
604
+ ${iconSidebar}
605
+ </button>` : nothing}
606
+ </div>
607
+ ${this.licensed ? this._renderNewConversation() : nothing}
608
+ ${this._renderSectionHeading()}
609
+ `;
610
+ }
611
+ /**
612
+ * Dedicated full-width "New Conversation" row. Keeps `part="new-thread-button"`
613
+ * and fires the existing `new-thread` event, so wrappers/themes that hook the
614
+ * old header pill are unaffected.
615
+ */
616
+ _renderNewConversation() {
617
+ return html`
618
+ <button
619
+ class="new-conversation"
620
+ part="new-thread-button"
621
+ @click=${() => this._emit("new-thread", {})}
622
+ >
623
+ ${iconPlusSquare}
624
+ <span>New Conversation</span>
625
+ </button>
626
+ `;
627
+ }
628
+ /**
629
+ * "Recent Conversations" section heading with a funnel button that opens the
630
+ * Active/All filter popover. Only shown when the list region is shown
631
+ * (licensed, and not the full-panel error/empty-before-load) — mirrors the
632
+ * old filters gate. The popover options keep `part="filter-active"` /
633
+ * `part="filter-all"` and still emit `filter-change` via `_setFilter`.
634
+ */
635
+ _renderSectionHeading() {
636
+ if (!this.licensed || hasErrorMessage(this.error) && this.threads.length === 0) return nothing;
637
+ return html`
638
+ <div class="section-heading" part="section-heading">
639
+ <span class="section-title">${this.recentLabel}</span>
640
+ <button
641
+ class="icon-btn small"
642
+ part="filter-toggle"
643
+ aria-label="Filter threads"
644
+ aria-expanded=${this._filterOpen}
645
+ @click=${() => this._filterOpen = !this._filterOpen}
646
+ >
647
+ ${iconFunnel}
648
+ ${this._filter !== "active" ? html`
649
+ <span class="filter-dot" part="filter-indicator"></span>
650
+ ` : nothing}
651
+ </button>
652
+ ${this._filterOpen ? html`<div
653
+ class="filter-popover"
654
+ part="filters"
655
+ role="group"
656
+ aria-label="Filter threads"
657
+ >
414
658
  <button
415
- class="filter-btn"
659
+ class="filter-opt"
416
660
  part="filter-active"
417
661
  aria-pressed=${this._filter === "active"}
418
- @click=${() => this._setFilter("active")}
662
+ @click=${() => {
663
+ this._setFilter("active");
664
+ this._filterOpen = false;
665
+ }}
419
666
  >
420
667
  Active
421
668
  </button>
422
669
  <button
423
- class="filter-btn"
670
+ class="filter-opt"
424
671
  part="filter-all"
425
672
  aria-pressed=${this._filter === "all"}
426
- @click=${() => this._setFilter("all")}
673
+ @click=${() => {
674
+ this._setFilter("all");
675
+ this._filterOpen = false;
676
+ }}
427
677
  >
428
678
  All
429
679
  </button>
430
- </div>
431
- ` : nothing}
680
+ </div>` : nothing}
681
+ </div>
432
682
  `;
433
683
  }
434
684
  _renderBody() {
@@ -469,7 +719,12 @@ var CopilotKitThreadsDrawer = class extends LitElement {
469
719
  }
470
720
  _renderError() {
471
721
  return html`
472
- <div class="state error" part="error" role="alert" data-testid="drawer-error">
722
+ <div
723
+ class="state error"
724
+ part="error"
725
+ role="alert"
726
+ data-testid="drawer-error"
727
+ >
473
728
  <p>${this.error}</p>
474
729
  <button
475
730
  class="primary"
@@ -496,20 +751,30 @@ var CopilotKitThreadsDrawer = class extends LitElement {
496
751
  </div>
497
752
  `;
498
753
  return html`
499
- <ul class="list" part="list" role="listbox" aria-label=${this.label}>
500
- ${repeat(visible, (thread) => thread.id, (thread) => this._renderRow(thread))}
754
+ <ul
755
+ class=${this._openMenuId !== null ? "list menu-open" : "list"}
756
+ part="list"
757
+ role="listbox"
758
+ aria-label=${this.label}
759
+ >
760
+ ${repeat(visible, (thread) => thread.id, (thread, index) => this._renderRow(thread, index, visible.length))}
501
761
  </ul>
502
762
  ${this._renderFetchMore()}
503
763
  `;
504
764
  }
505
- _renderRow(thread) {
765
+ _renderRow(thread, index = 0, total = 1) {
506
766
  const isActive = thread.id === this.activeThreadId;
507
767
  const hasName = thread.name !== null && thread.name !== "";
768
+ const displayName = hasName ? thread.name : "New thread";
508
769
  const justRevealed = this._justRevealed.has(thread.id);
770
+ const menuOpen = this._openMenuId === thread.id;
771
+ const menuUp = menuOpen && total > 1 && index >= total / 2;
509
772
  const rowClasses = {
510
773
  row: true,
511
774
  active: isActive,
512
- archived: thread.archived
775
+ archived: thread.archived,
776
+ "menu-open": menuOpen,
777
+ "menu-up": menuUp
513
778
  };
514
779
  const nameClasses = {
515
780
  "row-name": true,
@@ -517,14 +782,8 @@ var CopilotKitThreadsDrawer = class extends LitElement {
517
782
  revealed: justRevealed
518
783
  };
519
784
  const slotName = rowSlotName(thread.id);
520
- const nameSpan = html`<span
521
- class=${classMap(nameClasses)}
522
- part="row-name"
523
- data-tooltip=${hasName ? thread.name : nothing}
524
- >
525
- <span class="row-name-text"
526
- >${hasName ? thread.name : "New thread"}</span
527
- >
785
+ const nameSpan = html`<span class=${classMap(nameClasses)} part="row-name">
786
+ <span class="row-name-text">${displayName}</span>
528
787
  </span>`;
529
788
  return html`
530
789
  <li
@@ -534,50 +793,76 @@ var CopilotKitThreadsDrawer = class extends LitElement {
534
793
  aria-selected=${isActive ? "true" : "false"}
535
794
  tabindex="0"
536
795
  data-thread-id=${thread.id}
537
- @click=${() => this._emit("thread-selected", { threadId: thread.id })}
796
+ @click=${() => {
797
+ this._openMenuId = null;
798
+ this._emit("thread-selected", { threadId: thread.id });
799
+ }}
538
800
  @keydown=${(e) => {
539
801
  if (e.key === "Enter" || e.key === " ") {
540
802
  e.preventDefault();
803
+ this._openMenuId = null;
541
804
  this._emit("thread-selected", { threadId: thread.id });
542
805
  }
543
806
  }}
544
807
  >
545
808
  ${slotName !== null ? html`<slot name=${slotName}>${nameSpan}</slot>` : nameSpan}
546
- ${thread.archived ? html`<button
547
- class="row-action"
548
- part="row-unarchive"
549
- data-tooltip="Unarchive"
550
- aria-label=${`Unarchive thread ${thread.name ?? "New thread"}`}
551
- @click=${(e) => {
809
+ <button
810
+ class="row-menu"
811
+ part="row-menu"
812
+ aria-label=${`Actions for ${displayName}`}
813
+ aria-haspopup="menu"
814
+ aria-expanded=${menuOpen}
815
+ @click=${(e) => {
552
816
  e.stopPropagation();
553
- this._emit("unarchive", { threadId: thread.id });
817
+ this._openMenuId = menuOpen ? null : thread.id;
554
818
  }}
819
+ >
820
+ ${iconKebab}
821
+ </button>
822
+ ${menuOpen ? html`<div
823
+ class="row-menu-popover"
824
+ part="row-menu-popover"
825
+ role="menu"
555
826
  >
556
- ${iconUnarchive}
557
- </button>` : html`<button
558
- class="row-action"
559
- part="row-archive"
560
- data-tooltip="Archive"
561
- aria-label=${`Archive thread ${thread.name ?? "New thread"}`}
562
- @click=${(e) => {
827
+ ${thread.archived ? html`<button
828
+ class="row-menu-item"
829
+ part="row-unarchive"
830
+ role="menuitem"
831
+ aria-label=${`Unarchive thread ${displayName}`}
832
+ @click=${(e) => {
833
+ e.stopPropagation();
834
+ this._openMenuId = null;
835
+ this._emit("unarchive", { threadId: thread.id });
836
+ }}
837
+ >
838
+ ${iconUnarchive}<span>Unarchive</span>
839
+ </button>` : html`<button
840
+ class="row-menu-item"
841
+ part="row-archive"
842
+ role="menuitem"
843
+ aria-label=${`Archive thread ${displayName}`}
844
+ @click=${(e) => {
563
845
  e.stopPropagation();
846
+ this._openMenuId = null;
564
847
  this._emit("archive", { threadId: thread.id });
565
848
  }}
566
- >
567
- ${iconArchive}
568
- </button>`}
569
- <button
570
- class="row-action danger"
571
- part="row-delete"
572
- data-tooltip="Delete"
573
- aria-label=${`Delete thread ${thread.name ?? "New thread"}`}
574
- @click=${(e) => {
849
+ >
850
+ ${iconArchive}<span>Archive</span>
851
+ </button>`}
852
+ <button
853
+ class="row-menu-item danger"
854
+ part="row-delete"
855
+ role="menuitem"
856
+ aria-label=${`Delete thread ${displayName}`}
857
+ @click=${(e) => {
575
858
  e.stopPropagation();
859
+ this._openMenuId = null;
576
860
  this._confirmingDeleteId = thread.id;
577
861
  }}
578
- >
579
- ${iconDelete}
580
- </button>
862
+ >
863
+ ${iconDelete}<span>Delete</span>
864
+ </button>
865
+ </div>` : nothing}
581
866
  </li>
582
867
  `;
583
868
  }
@@ -632,41 +917,59 @@ var CopilotKitThreadsDrawer = class extends LitElement {
632
917
  </div>
633
918
  `;
634
919
  }
920
+ /**
921
+ * Confirm-delete dialog, rendered as a native `<dialog>` that is ALWAYS
922
+ * present in the shadow DOM so `updated()` can drive `showModal()`/`close()`
923
+ * against it. Opening with `showModal()` puts it in the browser TOP LAYER, so
924
+ * it can never be painted under other UI — the previous CSS-positioned overlay
925
+ * was trapped in the drawer host's stacking context and appeared under the
926
+ * chat's welcome view (ENT-1051). The `::backdrop` pseudo-element (styled in
927
+ * styles.ts) provides the scrim natively.
928
+ *
929
+ * The actionable content (message + Cancel/Delete, bound to the captured id)
930
+ * renders only while confirming, so a closed dialog holds nothing stale.
931
+ * Native dismissal is wired via `@cancel` (Escape) and a backdrop-click check.
932
+ */
635
933
  _renderConfirmDialog() {
636
- if (this._confirmingDeleteId === null) return nothing;
637
934
  const id = this._confirmingDeleteId;
638
935
  return html`
639
- <div class="dialog-backdrop" part="dialog-backdrop">
640
- <div
641
- class="dialog"
642
- part="confirm-dialog"
643
- role="alertdialog"
644
- aria-modal="true"
645
- aria-label="Confirm delete"
646
- data-testid="drawer-confirm-delete"
647
- >
648
- <p>Delete this thread? This cannot be undone.</p>
649
- <div class="dialog-actions">
650
- <button
651
- class="row-action"
652
- part="confirm-cancel"
653
- @click=${() => this._confirmingDeleteId = null}
654
- >
655
- Cancel
656
- </button>
657
- <button
658
- class="primary"
659
- part="confirm-delete"
660
- @click=${() => {
936
+ <dialog
937
+ class="dialog"
938
+ part="confirm-dialog"
939
+ role="alertdialog"
940
+ aria-label="Confirm delete"
941
+ data-testid="drawer-confirm-delete"
942
+ @cancel=${(event) => {
943
+ event.preventDefault();
944
+ this._confirmingDeleteId = null;
945
+ }}
946
+ @click=${(event) => {
947
+ if (event.target === event.currentTarget) this._confirmingDeleteId = null;
948
+ }}
949
+ >
950
+ ${id !== null ? html`
951
+ <p>Delete this thread? This cannot be undone.</p>
952
+ <div class="dialog-actions">
953
+ <button
954
+ class="row-action"
955
+ part="confirm-cancel"
956
+ @click=${() => this._confirmingDeleteId = null}
957
+ >
958
+ Cancel
959
+ </button>
960
+ <button
961
+ class="primary"
962
+ part="confirm-delete"
963
+ @click=${() => {
661
964
  this._confirmingDeleteId = null;
662
965
  this._emit("delete", { threadId: id });
663
966
  }}
664
- >
665
- Delete
666
- </button>
667
- </div>
668
- </div>
669
- </div>
967
+ >
968
+ Delete
969
+ </button>
970
+ </div>
971
+ ` : nothing}
972
+ </dialog>
670
973
  `;
671
974
  }
672
975
  };