dsh-delete-session 0.2.3 → 0.2.5

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/src/client.js CHANGED
@@ -61,6 +61,9 @@ window.__ModuleLoader__.load({
61
61
  pageAsk: '删除时询问',
62
62
  pageRecycle: '删除至回收站',
63
63
  pageSyncChildren: '同时删除子会话',
64
+ dropHint: '拖到这里删除',
65
+ dropRelease: '松手删除「{name}」',
66
+ dropFallback: '这个对话',
64
67
  starAsk: '⭐ 顺手留颗 Star,作者能高兴一整天',
65
68
  starCta: '行,给你一颗 Star',
66
69
  pageSyncChildrenOn: '删除对话时,把它派生的子代理会话一起删掉。',
@@ -98,6 +101,7 @@ window.__ModuleLoader__.load({
98
101
  rootOpened: '已在文件管理器中打开',
99
102
  rootOpenFailed: '打开失败:',
100
103
  pickerOpening: '已打开系统文件夹对话框,请在弹出的窗口里选择',
104
+ pickerFailed: '选择文件夹失败:',
101
105
  pageRootReset: '用默认',
102
106
  pageRootDefaultHint: (path) => `当前使用默认路径:${path}`,
103
107
  pageRootCustomHint: '隔离夹会建在这个目录下,每次删除生成一个带时间戳的子目录',
@@ -109,6 +113,12 @@ window.__ModuleLoader__.load({
109
113
  pickerDefault: (path) => `默认路径:${path}`,
110
114
  rootSet: '保存位置已更新',
111
115
  artifactSection: '本对话产出的文件',
116
+ artifactOpenFolder: '打开所在文件夹',
117
+ artifactDeleteFile: '删除这个文件',
118
+ fileDeleted: '文件已删除',
119
+ fileRecycled: '文件已移入回收站',
120
+ fileDeleteFailed: '删除文件失败:',
121
+ revealFailed: '打开文件夹失败:',
112
122
  artifactLoading: '正在扫描…',
113
123
  artifactFailed: '扫描失败:',
114
124
  artifactNone: '没有需要处理的文件。',
@@ -155,6 +165,9 @@ window.__ModuleLoader__.load({
155
165
  pageAsk: 'Ask before deleting',
156
166
  pageRecycle: 'Delete to the Recycle Bin',
157
167
  pageSyncChildren: 'Delete child sessions too',
168
+ dropHint: 'Drop here to delete',
169
+ dropRelease: 'Release to delete \'{name}\'',
170
+ dropFallback: 'this conversation',
158
171
  starAsk: '⭐ A star would make the author\'s day',
159
172
  starCta: 'Fine — have one',
160
173
  pageSyncChildrenOn: 'A delete also removes the subagent sessions it spawned.',
@@ -190,6 +203,7 @@ window.__ModuleLoader__.load({
190
203
  rootOpened: 'Opened in the file manager',
191
204
  rootOpenFailed: 'Could not open: ',
192
205
  pickerOpening: 'The system folder dialog is open; pick a folder in that window',
206
+ pickerFailed: 'Could not open the folder picker: ',
193
207
  pageRootReset: 'Use default',
194
208
  pageRootDefaultHint: (path) => `Using the default path: ${path}`,
195
209
  pageRootCustomHint: 'The quarantine folder is created here, one timestamped subfolder per delete',
@@ -201,6 +215,12 @@ window.__ModuleLoader__.load({
201
215
  pickerDefault: (path) => `Default path: ${path}`,
202
216
  rootSet: 'Location updated',
203
217
  artifactSection: 'Files this conversation produced',
218
+ artifactOpenFolder: 'Open containing folder',
219
+ artifactDeleteFile: 'Delete this file',
220
+ fileDeleted: 'File deleted',
221
+ fileRecycled: 'File moved to the recycle bin',
222
+ fileDeleteFailed: 'Could not delete the file: ',
223
+ revealFailed: 'Could not open the folder: ',
204
224
  artifactLoading: 'Scanning...',
205
225
  artifactFailed: 'Scan failed: ',
206
226
  artifactNone: 'Nothing to handle.',
@@ -309,6 +329,11 @@ window.__ModuleLoader__.load({
309
329
  picker: null,
310
330
  /** The host's default quarantine root, fetched once so the card can name it. */
311
331
  defaultRoot: null,
332
+ /**
333
+ * The session being dragged over the footer, or null. `over` arms the drop:
334
+ * the bar only says "松手删除" once the pointer is actually on it.
335
+ */
336
+ drag: null,
312
337
  }
313
338
 
314
339
  const listeners = new Set()
@@ -322,6 +347,7 @@ window.__ModuleLoader__.load({
322
347
  batch: state.batch,
323
348
  picker: state.picker,
324
349
  defaultRoot: state.defaultRoot,
350
+ drag: state.drag,
325
351
  selectedCount: state.selected.size,
326
352
  }
327
353
  }
@@ -492,11 +518,13 @@ window.__ModuleLoader__.load({
492
518
  * a conversation of its own, so it is offered rather than swept up.
493
519
  */
494
520
  function syncChildren() {
495
- return readPref(SYNC_CHILDREN_KEY, '0') === '1'
521
+ return readPref(SYNC_CHILDREN_KEY, '1') !== '0'
496
522
  }
497
523
 
498
524
  function setSyncChildren(on) {
499
- writePref(SYNC_CHILDREN_KEY, on ? '1' : null)
525
+ // "Off" is written as '0' rather than cleared: the default is now on, so a
526
+ // removed key would read back as on again.
527
+ writePref(SYNC_CHILDREN_KEY, on ? '1' : '0')
500
528
  }
501
529
 
502
530
  /** The chosen quarantine root, or '' for "use the host default". */
@@ -577,6 +605,65 @@ window.__ModuleLoader__.load({
577
605
  })
578
606
  }
579
607
 
608
+ /** Drop one row from the dialog after its file left the disk. */
609
+ function forgetFile(sessionId, target) {
610
+ const dialog = state.dialog
611
+ if (dialog === null || dialog.sessionId !== sessionId) return
612
+ const artifacts = dialog.artifacts
613
+ if (artifacts === null || artifacts.plan === null) return
614
+ artifacts.selected.delete(target)
615
+ const keep = (row) => row.path !== target
616
+ artifacts.plan = {
617
+ ...artifacts.plan,
618
+ created: (artifacts.plan.created || []).filter(keep),
619
+ modified: (artifacts.plan.modified || []).filter(keep),
620
+ }
621
+ publish()
622
+ }
623
+
624
+ /** Delete one produced file, then drop its row. */
625
+ function deleteOneFile(sessionId, target) {
626
+ const recycle = recycleSession()
627
+ postDeleteFile(sessionId, target, recycle).then((data) => {
628
+ forgetFile(sessionId, target)
629
+ toast(t(data && data.recycled === true ? 'fileRecycled' : 'fileDeleted'))
630
+ }).catch((reason) => {
631
+ toast(t('fileDeleteFailed') + String((reason && reason.message) || reason), true)
632
+ })
633
+ }
634
+
635
+ /**
636
+ * Delete one produced file. The recycle choice is the same preference that
637
+ * governs a conversation delete, so the two never disagree.
638
+ */
639
+ function postDeleteFile(sessionId, target, recycle) {
640
+ return fetch('/dsh-delete-session/delete-file', {
641
+ method: 'POST',
642
+ headers: { 'content-type': 'application/json' },
643
+ body: JSON.stringify({ sessionId, path: target, recycle }),
644
+ }).then(async (res) => {
645
+ let data = {}
646
+ try { data = await res.json() } catch { /* keep {} */ }
647
+ if (!res.ok || !data.ok) throw new Error((data && data.error) || `HTTP ${res.status}`)
648
+ return data
649
+ })
650
+ }
651
+
652
+ /**
653
+ * Show one produced file's folder. The host validates that the path is a
654
+ * directory; the browser has no path module, so the parent is taken with a
655
+ * plain last-separator split — Windows separators included.
656
+ */
657
+ function revealParent(filePath) {
658
+ const text = String(filePath === null || filePath === undefined ? '' : filePath).replace(/[\\/]+$/, '')
659
+ const cut = Math.max(text.lastIndexOf('/'), text.lastIndexOf('\\'))
660
+ const parent = cut > 0 ? text.slice(0, cut) : text
661
+ if (parent === '') return
662
+ postReveal(parent).catch((reason) => {
663
+ toast(t('revealFailed') + String((reason && reason.message) || reason), true)
664
+ })
665
+ }
666
+
580
667
  /** Show the quarantine folder the current settings would write to. */
581
668
  function openQuarantineRoot(target) {
582
669
  if (typeof target !== 'string' || target === '') return
@@ -670,7 +757,9 @@ window.__ModuleLoader__.load({
670
757
  // host's `Modal`, so it brings no backdrop CSS of its own.
671
758
 
672
759
  const CSS = [
673
- '.dsdel-toast{position:fixed;bottom:20px;left:50%;transform:translateX(-50%);z-index:2147483601;background:Canvas;color:CanvasText;border:1px solid color-mix(in srgb,CanvasText 25%,transparent);padding:9px 16px;border-radius:999px;font-size:12px;box-shadow:0 8px 24px rgba(0,0,0,.25);max-width:min(92vw,460px);cursor:pointer}',
760
+ '.dsdel-toast{position:fixed;bottom:20px;left:50%;transform:translateX(-50%);z-index:2147483601;background:var(--dsw-alias-bg-overlay,var(--dsw-alias-bg-layer-1,#2b2b2b));color:var(--dsw-alias-label-primary,#fff);border:1px solid var(--dsw-alias-border-l1,rgba(127,127,127,.3));padding:9px 16px;border-radius:10px;font-size:12.5px;line-height:18px;box-shadow:0 10px 28px rgba(0,0,0,.24);max-width:min(92vw,460px);cursor:pointer;animation:dsdel-toast-in .16s cubic-bezier(.2,.8,.3,1)}',
761
+ '@keyframes dsdel-toast-in{from{opacity:0;transform:translate(-50%,6px)}to{opacity:1;transform:translate(-50%,0)}}',
762
+ '@media (prefers-reduced-motion:reduce){.dsdel-toast{animation:none}.dsdel-field{transition:none}}',
674
763
  '.dsdel-check{display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;border-radius:50%;border:1.5px solid var(--dsw-alias-border-l3,rgba(128,128,128,.5));background:transparent;flex:none;margin-right:8px;box-sizing:border-box;cursor:pointer}',
675
764
  '.dsdel-check-on{background:var(--dsw-alias-state-business-primary,#4c6ef5);border-color:var(--dsw-alias-state-business-primary,#4c6ef5)}',
676
765
  '.dsdel-check-on::after{content:"";width:9px;height:5px;border-left:2px solid #fff;border-bottom:2px solid #fff;transform:rotate(-45deg) translateY(-1px)}',
@@ -687,12 +776,38 @@ window.__ModuleLoader__.load({
687
776
  // exclusion rule silently hid the bar together with its Cancel button.
688
777
  'body.dsdel-selecting [data-slot="sidebar.footer.action"] > [data-dsh-plugin]{display:none}',
689
778
  'body.dsdel-selecting [data-slot="sidebar.footer.action"] > [class*="_entryRow"]{display:none}',
779
+ '.dsdel-drop{border:1px dashed var(--dsw-alias-border-l2,rgba(128,128,128,.4));border-radius:8px;color:var(--dsw-alias-label-secondary,inherit)}',
780
+ '.dsdel-drop-over{border-color:var(--dsw-alias-state-error-primary,#e5484d);border-style:solid;background:rgba(229,72,77,.10);color:var(--dsw-alias-state-error-primary,#e5484d)}',
781
+ '.dsdel-drop-icon{display:inline-flex;flex:0 0 auto;align-items:center}',
782
+ '.dsdel-drop-text{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
690
783
  '.dsdel-bar-count{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color:var(--dsw-alias-label-secondary,inherit)}',
691
784
  '.dsdel-bar-btn{flex:0 0 auto;white-space:nowrap;appearance:none;min-height:30px;padding:0 12px;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.4));background:var(--dsw-alias-fill-elevated,rgba(128,128,128,.08));color:var(--dsw-alias-label-primary,inherit);border-radius:8px;font-size:13px;cursor:pointer}',
785
+ '.dsdel-bar-btn:focus-visible{outline:2px solid var(--dsdel-ring);outline-offset:1px}',
692
786
  '.dsdel-bar-btn:disabled{opacity:.5;cursor:default}',
693
787
  '.dsdel-bar-danger{border-color:var(--dsw-alias-state-error-primary,#e5484d);background:var(--dsw-alias-state-error-primary,#e5484d);color:#fff}',
788
+ // One token layer for every surface this plugin draws. Everything below
789
+ // reads these rather than repeating a fallback per rule: the host theme then
790
+ // reaches the whole plugin through one block, which is the point of exposing
791
+ // tokens at all.
792
+ '.dsdel-page,.dsdel-modal,.dsdel-bar{--dsdel-bg:var(--dsw-alias-fill-elevated,rgba(127,127,127,.06));--dsdel-bg-hover:var(--dsw-alias-fill-hover,rgba(127,127,127,.10));--dsdel-border:var(--dsw-alias-border-l2,rgba(127,127,127,.28));--dsdel-label:var(--dsw-alias-label-primary,inherit);--dsdel-label-dim:var(--dsw-alias-label-secondary,#666);--dsdel-label-faint:var(--dsw-alias-label-tertiary,#888);--dsdel-danger:var(--dsw-alias-state-error-primary,#e5484d);--dsdel-radius:10px;--dsdel-radius-sm:8px;--dsdel-ring:color-mix(in srgb,var(--dsw-alias-brand-primary,#4c8dff) 45%,transparent);--dsdel-shadow:0 1px 2px rgba(0,0,0,.04)}',
694
793
  '.dsdel-page{display:flex;flex-direction:column;gap:8px}',
695
- '.dsdel-page-hint{margin:0;color:var(--dsw-alias-label-tertiary,#888);font-size:13px;line-height:20px}',
794
+ // Each switch and its explanation read as one block, so a card with eight
795
+ // controls stops looking like one long column of tick boxes.
796
+ '.dsdel-field{display:flex;flex-direction:column;gap:2px;padding:10px 12px;border:1px solid var(--dsdel-border);border-radius:var(--dsdel-radius);background:var(--dsdel-bg);box-shadow:var(--dsdel-shadow);transition:background .12s ease,border-color .12s ease}',
797
+ '.dsdel-field:hover{background:var(--dsdel-bg-hover)}',
798
+ '.dsdel-field:focus-within{outline:2px solid var(--dsdel-ring);outline-offset:1px}',
799
+ '.dsdel-page-hint{margin:0;color:var(--dsdel-label-faint);font-size:12.5px;line-height:19px;letter-spacing:.01em}',
800
+ // One produced file per row: tick on the left, path in the middle, a folder
801
+ // button on the right. The button sits outside the label so a click opens
802
+ // the folder instead of toggling the tick.
803
+ '.dsdel-file-row{display:flex;align-items:center;gap:8px;padding:4px 6px;border-radius:var(--dsdel-radius-sm);transition:background .12s ease}',
804
+ '.dsdel-file-row:hover{background:var(--dsdel-bg-hover)}',
805
+ '.dsdel-file-label{display:flex;align-items:center;gap:8px;flex:1;min-width:0;cursor:pointer}',
806
+ '.dsdel-file-path{flex:1;min-width:0;word-break:break-all;font-size:13px;line-height:20px;color:var(--dsdel-label)}',
807
+ '.dsdel-file-open{display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;width:26px;height:26px;padding:0;border:1px solid transparent;border-radius:var(--dsdel-radius-sm);background:transparent;color:var(--dsdel-label-dim);cursor:pointer;transition:background .12s ease,color .12s ease,border-color .12s ease}',
808
+ '.dsdel-file-open:hover{background:var(--dsdel-bg);border-color:var(--dsdel-border);color:var(--dsdel-label)}',
809
+ '.dsdel-file-open:focus-visible{outline:2px solid var(--dsdel-ring);outline-offset:1px}',
810
+ '.dsdel-file-remove:hover{background:color-mix(in srgb,var(--dsdel-danger) 12%,transparent);border-color:color-mix(in srgb,var(--dsdel-danger) 40%,transparent);color:var(--dsdel-danger)}',
696
811
  '.dsdel-star{display:flex;align-items:center;justify-content:flex-end;gap:8px;flex-wrap:wrap;font-size:12px;color:var(--dsw-alias-label-tertiary,#8b93a1);padding:2px 2px 0;}',
697
812
  '.dsdel-star-link{color:var(--dsw-alias-brand-primary,#4d76e6);text-decoration:underline;}',
698
813
  '.dsdel-root-input{flex:1 1 220px;min-width:160px;min-height:30px;padding:0 10px;border:1px solid var(--dsw-alias-border-secondary,#d0d0d0);border-radius:6px;background:transparent;color:inherit;font:inherit;font-size:13px}',
@@ -700,8 +815,11 @@ window.__ModuleLoader__.load({
700
815
  // A wider confirmation dialog: the class reaches it when `Modal` forwards
701
816
  // `className`, and the `:has()` rule catches the host-owned container when
702
817
  // it does not. Both are harmless if the other one is the one that applies.
703
- '.dsdel-dialog-wide{width:min(94vw,980px)!important;max-width:min(94vw,980px)!important}',
704
- '[role="dialog"]:has(.dsdel-modal-meta),[aria-modal="true"]:has(.dsdel-modal-meta){width:min(94vw,980px);max-width:min(94vw,980px)}',
818
+ '.dsdel-dialog-wide{width:min(46vw,860px)!important;max-width:min(46vw,860px)!important;min-height:min(240px,88vh)!important;max-height:88vh!important;display:flex;flex-direction:column;overflow:hidden}',
819
+ '.dsdel-dialog-wide > :first-child{flex:1 1 auto;min-height:0;overflow:auto}',
820
+ '.dsdel-dialog-wide > :last-child{flex:0 0 auto;margin-top:auto}',
821
+ '.dsdel-artifacts{overflow:auto;overscroll-behavior:contain;padding-right:2px}',
822
+ '[role="dialog"]:has(.dsdel-file-row),[aria-modal="true"]:has(.dsdel-file-row){width:min(46vw,860px);max-width:min(46vw,860px);min-height:min(240px,88vh);max-height:88vh}',
705
823
  '.dsdel-picker-list{display:flex;flex-direction:column;gap:2px;max-height:280px;overflow:auto;margin:0 0 8px}',
706
824
  '.dsdel-picker-row{appearance:none;text-align:left;padding:6px 8px;border:0;border-radius:6px;background:transparent;color:inherit;font:inherit;font-size:13px;cursor:pointer}',
707
825
  '.dsdel-picker-row:hover{background:var(--dsw-alias-fill-secondary,rgba(127,127,127,0.12))}',
@@ -774,6 +892,56 @@ window.__ModuleLoader__.load({
774
892
  return id === '' ? null : id
775
893
  }
776
894
 
895
+ // --- drag a session onto the footer to delete it ---------------------------
896
+ //
897
+ // The id comes from the host's own `data-row-key`, never from `dataTransfer`:
898
+ // the official drag only reorders, and a dragover payload is unreadable anyway.
899
+ // The gesture ends in the same place as the menu row - the confirmation dialog
900
+ // unless the user turned asking off - so there is exactly one delete policy.
901
+
902
+ /** The row under the pointer, with the title the drop target can name. */
903
+ function draggedSession(event) {
904
+ const target = event === null || event === undefined ? null : event.target
905
+ const row = target && typeof target.closest === 'function'
906
+ ? target.closest('[role="treeitem"]')
907
+ : null
908
+ const sessionId = sessionIdFromRow(row)
909
+ if (sessionId === null) return null
910
+ const text = row !== null && typeof row.textContent === 'string' ? row.textContent.trim() : ''
911
+ const title = text === '' ? null : text.slice(0, 40)
912
+ return { sessionId, title }
913
+ }
914
+
915
+ function onDragStartCapture(event) {
916
+ // Inside multi-select a drag is the host reordering rows; deleting on drop
917
+ // would make the mode quietly destructive.
918
+ if (state.selecting) return
919
+ const info = draggedSession(event)
920
+ if (info === null) return
921
+ state.drag = { sessionId: info.sessionId, title: info.title, over: false }
922
+ syncFooterMode()
923
+ publish()
924
+ }
925
+
926
+ function onDragEndCapture() {
927
+ if (state.drag === null) return
928
+ state.drag = null
929
+ syncFooterMode()
930
+ publish()
931
+ }
932
+
933
+ /** Drop on the bar: same policy as the menu row. */
934
+ function dropToDelete() {
935
+ const drag = state.drag
936
+ if (drag === null) return
937
+ state.drag = null
938
+ syncFooterMode()
939
+ publish()
940
+ const needsDialog = !artifactsOff() && !artifactsAuto()
941
+ if (skipConfirm() && !needsDialog) deleteNow({ sessionId: drag.sessionId })
942
+ else openDeleteDialog(drag.sessionId, drag.title)
943
+ }
944
+
777
945
  function decorateRows() {
778
946
  if (typeof document === 'undefined') return
779
947
  const rows = document.querySelectorAll('[role="treeitem"]')
@@ -782,14 +950,22 @@ window.__ModuleLoader__.load({
782
950
  if (!id) return
783
951
  // Checkboxes belong to multi-select only: a single delete (or any other
784
952
  // decorate pass outside the mode) must not plant them on every row.
953
+ // The checkbox is always the row's first element child, so it is read
954
+ // through the pointer. `querySelector` here ran twice per row per frame,
955
+ // which is the pass's dominant cost once the list is long.
956
+ const first = row.firstElementChild
957
+ const existing = first !== null && first !== undefined
958
+ && first.classList
959
+ && first.classList.contains(DEL_CHECK)
960
+ ? first
961
+ : null
785
962
  if (!state.selecting) {
786
- const stray = row.querySelector(':scope > .dsdel-check')
787
- if (stray) stray.remove()
963
+ if (existing !== null) existing.remove()
788
964
  } else {
789
- let check = row.querySelector(':scope > .dsdel-check')
965
+ let check = existing
790
966
  if (!check) {
791
967
  check = document.createElement('span')
792
- check.className = 'dsdel-check'
968
+ check.className = DEL_CHECK
793
969
  check.setAttribute('data-dsh-delete-session', 'check')
794
970
  row.insertBefore(check, row.firstChild)
795
971
  }
@@ -801,6 +977,24 @@ window.__ModuleLoader__.load({
801
977
  document.querySelectorAll('.dsdel-check').forEach((el) => el.remove())
802
978
  }
803
979
  }
980
+ /**
981
+ * A mutation batch only matters when a node came or went. Text streaming
982
+ * inside the transcript produces characterData records forever; scheduling a
983
+ * full row scan for those would burn a frame's budget on every token.
984
+ */
985
+ function onRowMutations(records) {
986
+ if (records === undefined || records === null) return scheduleDecorate()
987
+ for (const record of records) {
988
+ const added = record === null || record === undefined ? null : record.addedNodes
989
+ const removed = record === null || record === undefined ? null : record.removedNodes
990
+ if ((added !== null && added !== undefined && added.length > 0)
991
+ || (removed !== null && removed !== undefined && removed.length > 0)) {
992
+ scheduleDecorate()
993
+ return
994
+ }
995
+ }
996
+ }
997
+
804
998
  function scheduleDecorate() {
805
999
  if (typeof requestAnimationFrame !== 'function') return
806
1000
  if (decorateRaf !== null) return
@@ -834,6 +1028,42 @@ window.__ModuleLoader__.load({
834
1028
  function BulkBar({ t: injected }) {
835
1029
  const translate = localizedTranslator(injected)
836
1030
  const view = useSnapshot()
1031
+ // A session dragged over the sidebar turns the footer into a drop target.
1032
+ if (view.drag !== null && view.drag !== undefined) {
1033
+ const armed = view.drag.over === true
1034
+ const name = view.drag.title === null || view.drag.title === undefined
1035
+ ? translate('dropFallback')
1036
+ : view.drag.title
1037
+ return h('div', {
1038
+ className: armed ? 'dsdel-bar dsdel-drop dsdel-drop-over' : 'dsdel-bar dsdel-drop',
1039
+ role: 'toolbar',
1040
+ onDragOver: (event) => {
1041
+ if (event && typeof event.preventDefault === 'function') event.preventDefault()
1042
+ if (event && event.dataTransfer) {
1043
+ try { event.dataTransfer.dropEffect = 'move' } catch { /* read-only */ }
1044
+ }
1045
+ if (state.drag !== null && state.drag.over !== true) {
1046
+ state.drag.over = true
1047
+ publish()
1048
+ }
1049
+ },
1050
+ onDragLeave: () => {
1051
+ if (state.drag !== null && state.drag.over !== false) {
1052
+ state.drag.over = false
1053
+ publish()
1054
+ }
1055
+ },
1056
+ onDrop: (event) => {
1057
+ if (event && typeof event.preventDefault === 'function') event.preventDefault()
1058
+ if (event && typeof event.stopPropagation === 'function') event.stopPropagation()
1059
+ dropToDelete()
1060
+ },
1061
+ },
1062
+ h('span', { key: 'icon', className: 'dsdel-drop-icon' }, glyph(TRASH_PATHS)),
1063
+ h('span', { key: 'text', className: 'dsdel-drop-text' },
1064
+ armed ? translate('dropRelease', name) : translate('dropHint', name)),
1065
+ )
1066
+ }
837
1067
  // Outside selection mode the footer keeps its normal face.
838
1068
  if (!view.selecting) return null
839
1069
  const busy = view.batch !== null
@@ -918,17 +1148,30 @@ window.__ModuleLoader__.load({
918
1148
  else classes.remove('dsdel-selecting')
919
1149
  }
920
1150
 
1151
+ /** The footer is ours while selecting or while a session is dragged over it. */
1152
+ function syncFooterMode() {
1153
+ markSelecting(state.selecting || state.drag !== null)
1154
+ }
1155
+
921
1156
  function enterSelection() {
922
1157
  if (state.selecting) return
923
1158
  state.selecting = true
924
1159
  state.selected.clear()
925
1160
  ensureStyle()
926
- markSelecting(true)
1161
+ syncFooterMode()
927
1162
  document.addEventListener('click', onSelectClickCapture, true)
928
1163
  document.addEventListener('keydown', onSelectKeydown, true)
929
1164
  if (typeof MutationObserver === 'function') {
930
- rowObserver = new MutationObserver(scheduleDecorate)
931
- rowObserver.observe(document.body, { childList: true, subtree: true })
1165
+ rowObserver = new MutationObserver(onRowMutations)
1166
+ // Observation root is the list, not the document: the transcript below
1167
+ // streams tokens continuously and would otherwise wake this on every one.
1168
+ const list = typeof document.querySelector === 'function'
1169
+ ? document.querySelector(LIST_SELECTOR)
1170
+ : null
1171
+ rowObserver.observe(list !== null && list !== undefined ? list : document.body, {
1172
+ childList: true,
1173
+ subtree: true,
1174
+ })
932
1175
  }
933
1176
  publish()
934
1177
  }
@@ -943,7 +1186,7 @@ window.__ModuleLoader__.load({
943
1186
  state.pending.clear()
944
1187
  document.querySelectorAll('.dsdel-row-pending').forEach((el) => el.classList.remove('dsdel-row-pending'))
945
1188
  }
946
- markSelecting(false)
1189
+ syncFooterMode()
947
1190
  document.removeEventListener('click', onSelectClickCapture, true)
948
1191
  document.removeEventListener('keydown', onSelectKeydown, true)
949
1192
  if (rowObserver) { rowObserver.disconnect(); rowObserver = null }
@@ -1293,11 +1536,16 @@ window.__ModuleLoader__.load({
1293
1536
  toast(t('rootSet'))
1294
1537
  })
1295
1538
  .catch((reason) => {
1296
- if (reason && reason.code === 'unsupported') {
1539
+ // Two host answers mean "use the page picker instead": `unsupported`
1540
+ // (no directoryPicker service at all) and `browse` (the service exists
1541
+ // but serves listings, which is what a remote client gets). Neither is
1542
+ // a failure, so neither may surface as a toast.
1543
+ if (reason && (reason.code === 'unsupported' || reason.code === 'browse')) {
1297
1544
  openPicker()
1298
1545
  return
1299
1546
  }
1300
- toast(t('failed') + String((reason && reason.message) || reason), true)
1547
+ // Nothing was deleted here, so the delete wording would mislead.
1548
+ toast(t('pickerFailed') + String((reason && reason.message) || reason), true)
1301
1549
  })
1302
1550
  .finally(() => {
1303
1551
  folderDialogOpen = false
@@ -1371,8 +1619,15 @@ window.__ModuleLoader__.load({
1371
1619
 
1372
1620
  // --- menu rows (slot: sidebar.workspaces.session.menu.item) ----------------
1373
1621
 
1622
+ /** The sidebar list container; hashed class name, matched by its suffix. */
1623
+ const LIST_SELECTOR = '[class*="_regionArea"]'
1624
+ /** Marks a row checkbox this plugin planted. */
1625
+ const DEL_CHECK = 'dsdel-check'
1626
+
1374
1627
  /** Inline glyphs for the two rows; the host exposes no matching pair. */
1375
1628
  const TRASH_PATHS = ['M4 7h16', 'M10 11v6', 'M14 11v6', 'M6 7l1 13a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1l1-13', 'M9 7V4h6v3']
1629
+ /** A folder, for "show this file where it lives". */
1630
+ const FOLDER_PATHS = ['M3 6a1 1 0 0 1 1-1h4l2 2h8a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1z']
1376
1631
  const SELECT_PATHS = ['M5 7m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0', 'M5 17m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0', 'M11 7h9', 'M11 17h9']
1377
1632
 
1378
1633
  function glyph(paths) {
@@ -1506,21 +1761,55 @@ window.__ModuleLoader__.load({
1506
1761
  elements.push(h('p', { key: 'selected', className: 'dsdel-modal-meta' },
1507
1762
  translate('artifactSelected', artifacts.selected.size)))
1508
1763
  for (const row of rows.slice(0, ARTIFACT_ROWS_SHOWN)) {
1509
- elements.push(h('label', {
1764
+ elements.push(h('div', {
1510
1765
  key: `row:${row.path}`,
1511
- className: 'dsdel-modal-text',
1512
- style: { display: 'flex', alignItems: 'center', gap: '8px', padding: '2px 0', cursor: 'pointer' },
1766
+ 'data-file-row': row.path,
1767
+ className: 'dsdel-file-row',
1513
1768
  },
1514
- h('input', {
1515
- type: 'checkbox',
1516
- checked: artifacts.selected.has(row.path),
1517
- onChange: (e) => {
1518
- if (e && e.target && e.target.checked) artifacts.selected.add(row.path)
1519
- else artifacts.selected.delete(row.path)
1520
- publish()
1769
+ h('label', {
1770
+ key: 'label',
1771
+ className: 'dsdel-file-label',
1772
+ },
1773
+ h('input', {
1774
+ type: 'checkbox',
1775
+ checked: artifacts.selected.has(row.path),
1776
+ onChange: (e) => {
1777
+ if (e && e.target && e.target.checked) artifacts.selected.add(row.path)
1778
+ else artifacts.selected.delete(row.path)
1779
+ publish()
1780
+ },
1781
+ }),
1782
+ h('span', { key: 'path', className: 'dsdel-file-path' }, row.displayPath || row.path),
1783
+ ),
1784
+ // Delete just this file. Same destination rule as the conversation
1785
+ // switch: the system trash when recycling is on, gone when it is not.
1786
+ h('button', {
1787
+ key: 'remove',
1788
+ type: 'button',
1789
+ className: 'dsdel-file-open dsdel-file-remove',
1790
+ title: translate('artifactDeleteFile'),
1791
+ 'aria-label': translate('artifactDeleteFile'),
1792
+ onClick: (event) => {
1793
+ if (event && typeof event.preventDefault === 'function') event.preventDefault()
1794
+ if (event && typeof event.stopPropagation === 'function') event.stopPropagation()
1795
+ deleteOneFile(state.dialog === null ? '' : state.dialog.sessionId, row.path)
1521
1796
  },
1522
- }),
1523
- h('span', { style: { wordBreak: 'break-all' } }, row.displayPath || row.path),
1797
+ }, glyph(TRASH_PATHS)),
1798
+ // One folder per row. What moves is the file, so the thing worth
1799
+ // looking at before deciding is where it lives. The button is a
1800
+ // SIBLING of the label: inside it, a click would toggle the tick box.
1801
+ h('button', {
1802
+ key: 'open',
1803
+ type: 'button',
1804
+ className: 'dsdel-file-open',
1805
+ title: translate('artifactOpenFolder'),
1806
+ 'aria-label': translate('artifactOpenFolder'),
1807
+ onClick: (event) => {
1808
+ if (event && typeof event.preventDefault === 'function') event.preventDefault()
1809
+ if (event && typeof event.stopPropagation === 'function') event.stopPropagation()
1810
+ revealParent(row.path)
1811
+ },
1812
+ }, glyph(FOLDER_PATHS)),
1524
1813
  ))
1525
1814
  }
1526
1815
  if (rows.length > ARTIFACT_ROWS_SHOWN) {
@@ -1536,7 +1825,7 @@ window.__ModuleLoader__.load({
1536
1825
  if (plan.truncated) {
1537
1826
  elements.push(h('p', { key: 'truncated', className: 'dsdel-modal-meta' }, translate('artifactTruncated')))
1538
1827
  }
1539
- return h('div', { key: 'artifacts' }, elements)
1828
+ return h('div', { key: 'artifacts', className: 'dsdel-artifacts' }, elements)
1540
1829
  }
1541
1830
 
1542
1831
  /** Folder picker overlay: walk directories, then commit one. */
@@ -1620,6 +1909,17 @@ window.__ModuleLoader__.load({
1620
1909
  const dialog = view.dialog
1621
1910
  if (dialog === null) return null
1622
1911
 
1912
+ // The file list sizes its own frame: a short list gets a short dialog, a
1913
+ // long one grows until the viewport cap and then scrolls. A forced ratio
1914
+ // cannot do that — it pins the height, so the empty band under two lines
1915
+ // of text simply moves around.
1916
+ const plan = dialog.artifacts !== null && dialog.artifacts !== undefined
1917
+ ? dialog.artifacts.plan
1918
+ : null
1919
+ const listed = plan === null || plan === undefined
1920
+ ? 0
1921
+ : (plan.created || []).length + (plan.modified || []).length
1922
+ const needsFrame = listed > 0 && dialog.artifacts.auto !== true
1623
1923
  const footer = h(
1624
1924
  Fragment,
1625
1925
  null,
@@ -1640,12 +1940,20 @@ window.__ModuleLoader__.load({
1640
1940
 
1641
1941
  return h(primitives.Modal, {
1642
1942
  open: true,
1643
- // The produced-file list needs more room than the default dialog gives.
1644
- // `Modal` does not document a width prop, so the class, the inline style
1645
- // and the `:has()` rule in the stylesheet all try, and whichever the host
1646
- // honours wins.
1647
- className: 'dsdel-dialog-wide',
1648
- style: { width: 'min(94vw, 980px)', maxWidth: 'min(94vw, 980px)' },
1943
+ // `Modal` documents no width prop, so the class, the inline style and the
1944
+ // `:has()` rule in the stylesheet all try; whichever the host honours wins.
1945
+ // 9:16: the file list reads as a column, so the shell is a phone-shaped
1946
+ // card. Width is derived from the height budget (94vh tall at most), which
1947
+ // keeps the ratio on every window size; the list scrolls inside it.
1948
+ ...(needsFrame ? { className: 'dsdel-dialog-wide' } : {}),
1949
+ ...(needsFrame ? {
1950
+ style: {
1951
+ width: 'min(46vw, 860px)',
1952
+ maxWidth: 'min(46vw, 860px)',
1953
+ minHeight: 'min(240px, 88vh)',
1954
+ maxHeight: '88vh',
1955
+ },
1956
+ } : {}),
1649
1957
  onClose: () => closeDeleteDialog(),
1650
1958
  closeLabel: translate('cancel'),
1651
1959
  title: translate('title'),
@@ -1886,7 +2194,36 @@ window.__ModuleLoader__.load({
1886
2194
  rel: 'noreferrer',
1887
2195
  }, translate('starCta'))))
1888
2196
 
1889
- return h('div', { className: 'dsdel-page' }, children)
2197
+ // Each control owns the nodes that explain it. Grouping them here keeps the
2198
+ // markup above flat (a switch and its hint are still two pushes) while the
2199
+ // page draws them as one block.
2200
+ const FIELD_KEYS = new Set(['ask', 'recycle', 'syncChildren', 'off', 'auto', 'scope', 'skipGit', 'root'])
2201
+ function groupFields(nodes) {
2202
+ const groups = []
2203
+ let current = null
2204
+ for (const node of nodes) {
2205
+ const key = node !== null && node !== undefined && node.props ? node.props.key : undefined
2206
+ if (FIELD_KEYS.has(key)) {
2207
+ current = { control: key, nodes: [node] }
2208
+ groups.push(current)
2209
+ continue
2210
+ }
2211
+ // The hint of a control is keyed `<control>Hint`; the root row keeps its
2212
+ // input, buttons and hint under the same prefix.
2213
+ if (current !== null && typeof key === 'string' && key !== 'star' && key !== 'cta'
2214
+ && key.startsWith(current.control)) {
2215
+ current.nodes.push(node)
2216
+ continue
2217
+ }
2218
+ current = null
2219
+ groups.push({ control: null, nodes: [node] })
2220
+ }
2221
+ return groups.map((group, index) => (group.control === null
2222
+ ? group.nodes[0]
2223
+ : h('div', { key: `field:${group.control}`, className: 'dsdel-field' }, ...group.nodes)))
2224
+ }
2225
+
2226
+ return h('div', { className: 'dsdel-page' }, groupFields(children))
1890
2227
  }
1891
2228
 
1892
2229
  // --- plugin ------------------------------------------------------------------
@@ -1936,6 +2273,12 @@ window.__ModuleLoader__.load({
1936
2273
  }
1937
2274
 
1938
2275
  const install = (slots) => {
2276
+ // The drag gesture is document-wide (the row is not ours), so these are
2277
+ // plain capture listeners rather than slot handlers.
2278
+ if (typeof document !== 'undefined' && typeof document.addEventListener === 'function') {
2279
+ document.addEventListener('dragstart', onDragStartCapture, true)
2280
+ document.addEventListener('dragend', onDragEndCapture, true)
2281
+ }
1939
2282
  // Session menu rows. A package-namespaced id keeps them beside the
1940
2283
  // shipped pin(100)/rename(200)/fork(300)/archive(400)/session-id(450).
1941
2284
  slots.inject('sidebar.workspaces.session.menu.item', () => slots.register(
@@ -1957,7 +2300,17 @@ window.__ModuleLoader__.load({
1957
2300
  { name: 'shell.overlay', id: `${NS}-picker`, order: 1, locale: NS },
1958
2301
  QuarantinePicker,
1959
2302
  ))
1960
- // The plugin page card.
2303
+ // The plugin page card, on BOTH seats the manager offers.
2304
+ //
2305
+ // `plugins.bundle.config` renders on the package page, whose address is
2306
+ // `#/panel/plugins/<package>`. `plugins.row.config` renders on the row's
2307
+ // own page, `#/panel/plugins/<package>/<rowId>` — and this bundle's row id
2308
+ // is the package name, so that address repeated itself. The row seat keeps
2309
+ // only its `summary` face, which is the one line the rows list shows.
2310
+ slots.inject('plugins.bundle.config', () => slots.register(
2311
+ { name: 'plugins.bundle.config', key: NS },
2312
+ AskBeforeDeleteOption,
2313
+ ))
1961
2314
  slots.inject('plugins.row.config', () => slots.register(
1962
2315
  { name: 'plugins.row.config', key: `${NS}#${NS}` },
1963
2316
  AskBeforeDeleteOption,
@@ -1971,6 +2324,12 @@ window.__ModuleLoader__.load({
1971
2324
 
1972
2325
  // Leaving the mode disconnects the row observer and strips the checkboxes.
1973
2326
  return () => {
2327
+ if (typeof document !== 'undefined' && typeof document.removeEventListener === 'function') {
2328
+ document.removeEventListener('dragstart', onDragStartCapture, true)
2329
+ document.removeEventListener('dragend', onDragEndCapture, true)
2330
+ }
2331
+ state.drag = null
2332
+ syncFooterMode()
1974
2333
  exitSelection()
1975
2334
  }
1976
2335
  }