@chatcode/cco-better-sidebar 0.18.0-alpha.4 → 0.18.0-rc.12
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/README.md +30 -9
- package/README_EN.md +30 -9
- package/cordis.patch.yml +6 -5
- package/lib/client-editor.js +10954 -395
- package/lib/client-mermaid.js +10835 -300
- package/lib/client-registry.js +4035 -2215
- package/lib/client-terminal.js +435 -292
- package/lib/client.js +4035 -2215
- package/lib/index.js +282 -47
- package/lib/types/client/LogoutConfirmDialog.d.ts +5 -0
- package/lib/types/client/PluginMarketSettingsSection.d.ts +7 -0
- package/lib/types/client/PluginMarketView.d.ts +7 -0
- package/lib/types/client/PluginProjectPicker.d.ts +13 -0
- package/lib/types/client/api.d.ts +21 -0
- package/lib/types/client/builtins/tabs.d.ts +13 -1
- package/lib/types/client/icons.d.ts +26 -8
- package/lib/types/client/locales-ja.d.ts +25 -0
- package/lib/types/client/locales.d.ts +39 -0
- package/lib/types/client/plugin-market-catalog.d.ts +25 -0
- package/lib/types/client/service.d.ts +1 -1
- package/lib/types/client/ui-tweaks/archive.d.ts +9 -28
- package/lib/types/client/ui-tweaks/branding.d.ts +1 -1
- package/lib/types/client/ui-tweaks/dom-text.d.ts +2 -0
- package/lib/types/client/ui-tweaks/index.d.ts +9 -1
- package/lib/types/client/ui-tweaks/sidebar-header.d.ts +6 -0
- package/lib/types/client/ui-tweaks/typography.d.ts +9 -0
- package/lib/types/config.d.ts +4 -3
- package/lib/types/context-types.d.ts +12 -14
- package/lib/types/login-page-script.d.ts +2 -0
- package/lib/types/login-route.d.ts +2 -0
- package/lib/types/plugin-market-api.d.ts +5 -0
- package/lib/types/plugin-market-shared.d.ts +59 -0
- package/lib/types/prefs-shared.d.ts +1 -1
- package/lib/types/pty-deps.d.ts +1 -1
- package/lib/types/ui-tweaks/config.d.ts +6 -7
- package/lib/types/ui-tweaks/index.d.ts +2 -3
- package/package.json +2 -2
- package/src/client/AccountMenu.tsx +12 -2
- package/src/client/BrowserView.tsx +1 -1
- package/src/client/DiffTab.tsx +1 -1
- package/src/client/EditorHost.tsx +1 -1
- package/src/client/FileTree.tsx +10 -5
- package/src/client/FreeWindow.tsx +2 -1
- package/src/client/GitView.tsx +7 -3
- package/src/client/LogoutConfirmDialog.tsx +39 -0
- package/src/client/PluginMarketSettingsSection.tsx +55 -0
- package/src/client/PluginMarketView.module.css +50 -0
- package/src/client/PluginMarketView.tsx +243 -0
- package/src/client/PluginProjectPicker.tsx +73 -0
- package/src/client/SideCardSection.tsx +2 -23
- package/src/client/Sidebar.tsx +2 -2
- package/src/client/TabBar.tsx +2 -4
- package/src/client/TextEditor.tsx +2 -1
- package/src/client/TreePanel.tsx +1 -2
- package/src/client/UsageHeatmapSection.tsx +1 -1
- package/src/client/api.ts +12 -0
- package/src/client/builtins/tabs.tsx +25 -5
- package/src/client/builtins/viewers.tsx +2 -1
- package/src/client/icons.tsx +57 -4
- package/src/client/index.tsx +10 -1
- package/src/client/intercept.tsx +1 -1
- package/src/client/locales-ja.ts +65 -0
- package/src/client/locales.ts +118 -1
- package/src/client/md-toc.tsx +1 -1
- package/src/client/mermaid.tsx +2 -1
- package/src/client/open-with-settings.tsx +1 -1
- package/src/client/plugin-market-catalog.ts +90 -0
- package/src/client/service.ts +1 -1
- package/src/client/sidebar.module.css +81 -19
- package/src/client/ui-tweaks/archive.tsx +118 -140
- package/src/client/ui-tweaks/branding.tsx +117 -49
- package/src/client/ui-tweaks/cachehit.tsx +24 -14
- package/src/client/ui-tweaks/dom-text.ts +12 -0
- package/src/client/ui-tweaks/index.tsx +75 -103
- package/src/client/ui-tweaks/sidebar-header.ts +73 -0
- package/src/client/ui-tweaks/typography.ts +38 -0
- package/src/config.ts +22 -2
- package/src/context-types.ts +5 -15
- package/src/index.ts +28 -21
- package/src/login-page-script.ts +107 -0
- package/src/login-route.ts +7 -4
- package/src/plugin-market-api.ts +88 -0
- package/src/plugin-market-shared.ts +30 -0
- package/src/prefs-shared.ts +1 -1
- package/src/pty-deps.ts +2 -2
- package/src/ui-tweaks/config.ts +12 -12
- package/src/ui-tweaks/index.ts +7 -13
|
@@ -442,13 +442,11 @@
|
|
|
442
442
|
box-sizing: border-box;
|
|
443
443
|
gap: 8px;
|
|
444
444
|
width: 100%;
|
|
445
|
-
min-height:
|
|
446
|
-
padding:
|
|
445
|
+
min-height: 44px;
|
|
446
|
+
padding: 8px 12px max(8px, env(safe-area-inset-bottom));
|
|
447
447
|
border-radius: 0;
|
|
448
448
|
background: var(--dsw-alias-bg-layer-1);
|
|
449
|
-
font
|
|
450
|
-
font-size: var(--dsw-font-size-body-sm);
|
|
451
|
-
line-height: var(--dsw-font-line-height-body-sm);
|
|
449
|
+
font: var(--dsw-font-xs-13);
|
|
452
450
|
transition: background var(--ds-transition-duration-slow) var(--ds-ease-in-out);
|
|
453
451
|
}
|
|
454
452
|
|
|
@@ -466,18 +464,21 @@
|
|
|
466
464
|
.accountAvatar {
|
|
467
465
|
position: relative;
|
|
468
466
|
display: grid;
|
|
469
|
-
|
|
470
|
-
|
|
467
|
+
box-sizing: border-box;
|
|
468
|
+
width: 24px;
|
|
469
|
+
height: 24px;
|
|
471
470
|
flex: none;
|
|
472
471
|
place-items: center;
|
|
473
472
|
border-radius: 50%;
|
|
474
473
|
background: var(--dsw-alias-bg-layer-3);
|
|
475
474
|
border: 1px solid var(--dsw-alias-border-l2);
|
|
476
475
|
color: var(--dsw-alias-fg-accent);
|
|
476
|
+
font: var(--dsw-font-xxs-12);
|
|
477
477
|
font-weight: 600;
|
|
478
478
|
}
|
|
479
479
|
|
|
480
480
|
.accountName {
|
|
481
|
+
min-width: 0;
|
|
481
482
|
overflow: hidden;
|
|
482
483
|
text-overflow: ellipsis;
|
|
483
484
|
white-space: nowrap;
|
|
@@ -490,10 +491,10 @@
|
|
|
490
491
|
left: 8px;
|
|
491
492
|
display: grid;
|
|
492
493
|
box-sizing: border-box;
|
|
493
|
-
width: min(
|
|
494
|
-
padding:
|
|
494
|
+
width: min(224px, calc(100% - 16px));
|
|
495
|
+
padding: 8px 6px 6px;
|
|
495
496
|
border: 1px solid var(--dsw-alias-border-l2);
|
|
496
|
-
border-radius:
|
|
497
|
+
border-radius: 10px;
|
|
497
498
|
background: var(--dsw-alias-bg-layer-2);
|
|
498
499
|
z-index: 1;
|
|
499
500
|
}
|
|
@@ -502,16 +503,15 @@
|
|
|
502
503
|
display: flex;
|
|
503
504
|
align-items: center;
|
|
504
505
|
gap: 8px;
|
|
505
|
-
min-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
font
|
|
509
|
-
line-height: var(--dsw-font-line-height-body-sm);
|
|
506
|
+
min-width: 0;
|
|
507
|
+
min-height: 28px;
|
|
508
|
+
padding: 0 6px 6px;
|
|
509
|
+
font: var(--dsw-font-xs-13);
|
|
510
510
|
}
|
|
511
511
|
|
|
512
512
|
.accountMenuDivider {
|
|
513
513
|
height: 1px;
|
|
514
|
-
margin: 0 4px
|
|
514
|
+
margin: 0 4px 4px;
|
|
515
515
|
background: var(--dsw-alias-border-l2);
|
|
516
516
|
}
|
|
517
517
|
|
|
@@ -519,12 +519,12 @@
|
|
|
519
519
|
display: flex;
|
|
520
520
|
align-items: center;
|
|
521
521
|
gap: 8px;
|
|
522
|
-
min-height:
|
|
523
|
-
padding: 0
|
|
522
|
+
min-height: 30px;
|
|
523
|
+
padding: 0 8px;
|
|
524
524
|
border-radius: 7px;
|
|
525
525
|
background: transparent;
|
|
526
526
|
text-align: left;
|
|
527
|
-
font: var(--dsw-font-
|
|
527
|
+
font: var(--dsw-font-xs-13);
|
|
528
528
|
}
|
|
529
529
|
|
|
530
530
|
.accountItem:hover {
|
|
@@ -546,6 +546,68 @@
|
|
|
546
546
|
border-color: var(--dsw-alias-bg-layer-1);
|
|
547
547
|
}
|
|
548
548
|
|
|
549
|
+
/* The native top layer is viewport-centered even though the account rail is positioned. */
|
|
550
|
+
.accountLogoutDialog {
|
|
551
|
+
box-sizing: border-box;
|
|
552
|
+
width: min(400px, calc(100vw - 32px));
|
|
553
|
+
max-width: calc(100vw - 32px);
|
|
554
|
+
max-height: calc(100dvh - 32px);
|
|
555
|
+
margin: auto;
|
|
556
|
+
padding: 24px;
|
|
557
|
+
overflow: auto;
|
|
558
|
+
border: 1px solid var(--dsw-alias-border-l2);
|
|
559
|
+
border-radius: 16px;
|
|
560
|
+
background: var(--dsw-alias-bg-layer-2);
|
|
561
|
+
color: var(--dsw-alias-fg-base);
|
|
562
|
+
font: var(--dsw-font-s-14);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
.accountLogoutDialog::backdrop {
|
|
566
|
+
background: var(--dsw-alias-bg-mask-1);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
.accountLogoutTitle {
|
|
570
|
+
margin: 0;
|
|
571
|
+
font: var(--dsw-font-base-strong-16);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
.accountLogoutDescription {
|
|
575
|
+
margin: 12px 0 24px;
|
|
576
|
+
color: var(--dsw-alias-label-secondary);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
.accountLogoutActions {
|
|
580
|
+
display: flex;
|
|
581
|
+
flex-wrap: wrap;
|
|
582
|
+
justify-content: flex-end;
|
|
583
|
+
gap: 8px;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
.accountLogoutActions button {
|
|
587
|
+
min-height: 34px;
|
|
588
|
+
padding: 6px 14px;
|
|
589
|
+
border: 1px solid var(--dsw-alias-border-l2);
|
|
590
|
+
border-radius: 8px;
|
|
591
|
+
background: var(--dsw-alias-bg-layer-2);
|
|
592
|
+
color: var(--dsw-alias-fg-base);
|
|
593
|
+
font: var(--dsw-font-xs-13);
|
|
594
|
+
cursor: pointer;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
.accountLogoutActions button:hover {
|
|
598
|
+
background: var(--dsw-alias-bg-hover);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
.accountLogoutActions button:focus-visible {
|
|
602
|
+
outline: 2px solid var(--dsw-alias-border-accent);
|
|
603
|
+
outline-offset: 2px;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
.accountLogoutActions .accountLogoutConfirm {
|
|
607
|
+
border-color: var(--dsw-alias-state-error-primary);
|
|
608
|
+
color: var(--dsw-alias-state-error-primary);
|
|
609
|
+
}
|
|
610
|
+
|
|
549
611
|
/* The compatibility action cluster used when the host exposes no native
|
|
550
612
|
right-sidebar affordance. It stays pinned to the viewport corner, sitting
|
|
551
613
|
flush in the 34px tab strip (28px buttons at top: 3) whose right end it
|
|
@@ -1,84 +1,21 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* when the `archiveManagerEnabled` toggle in 界面调整 is on — otherwise it
|
|
6
|
-
* shows an invite card with a one-click enable). The section lists every
|
|
7
|
-
* archived session — enriched from the framework `useSessions` /
|
|
8
|
-
* `useWorkspaces` feeds — with per-row actions and batch actions that go
|
|
9
|
-
* through the same-origin archive route (`/_dsh/ui-tweaks/archive`):
|
|
10
|
-
*
|
|
11
|
-
* - **恢复** (Restore): remove the session from the archive set — its log and
|
|
12
|
-
* workspace slot are kept, so the conversation reappears in the normal
|
|
13
|
-
* sidebar list.
|
|
14
|
-
* - **删除** (Delete): PERMANENTLY delete the session — the server removes its
|
|
15
|
-
* durable log, workspace accounting, archive-set entry and caches; the list
|
|
16
|
-
* then refreshes so the row (and the session itself) disappear.
|
|
17
|
-
* - **全部恢复 / 全部删除**: the same actions for every archived session.
|
|
18
|
-
*
|
|
19
|
-
* Live (open/running) sessions are refused by the server; the client maps the
|
|
20
|
-
* `session-live` error code to localized copy.
|
|
21
|
-
* @module dsh-ui-tweaks/client/archive
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
import { useEffect, useMemo, useState, useSyncExternalStore } from 'react'
|
|
25
|
-
import type { ISessions, SessionListState, SessionSummary } from '@deepseek-ai/dsh-api-session-controller/client'
|
|
1
|
+
/** Archived sessions use the shared Host operations for restore and confirmed deletion. */
|
|
2
|
+
import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react'
|
|
3
|
+
import { Button, Modal } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
4
|
+
import type { SessionListState, SessionSummary } from '@deepseek-ai/dsh-api-session-controller/client'
|
|
26
5
|
import type { WorkspaceSnapshot } from '@deepseek-ai/dsh-api-workspace-controller/client'
|
|
27
6
|
import type { SnapshotSelectorHook } from '@deepseek-ai/dsh-client-ui-slots'
|
|
28
7
|
import type { SettingsClient } from './index.tsx'
|
|
29
8
|
|
|
30
|
-
/**
|
|
31
|
-
const ARCHIVE_ROUTE = '/_dsh/ui-tweaks/archive'
|
|
32
|
-
|
|
33
|
-
/** Locale keys the Archive manager reads off the `ui-tweaks` dictionary. */
|
|
9
|
+
/** Locale keys read by archive management. */
|
|
34
10
|
type ArchiveLabelKey =
|
|
35
|
-
| '
|
|
36
|
-
| 'archiveDelete' | 'archiveDeleteAll' | 'archiveRestoreAll'
|
|
37
|
-
| '
|
|
38
|
-
| '
|
|
39
|
-
|
|
11
|
+
| 'archiveTitle' | 'archiveEmpty' | 'archiveRestore' | 'archiveRestoring'
|
|
12
|
+
| 'archiveDelete' | 'archiveDeleteAll' | 'archiveRestoreAll' | 'archiveCount'
|
|
13
|
+
| 'archiveDisabledHint' | 'archiveEnable' | 'unavailable'
|
|
14
|
+
| 'archiveConfirmTitle' | 'archiveConfirmDescription' | 'archiveCancel'
|
|
15
|
+
| 'archiveSelectAll' | 'archiveSelectedCount' | 'archiveClearSelection'
|
|
16
|
+
| 'archiveDeleteSelected' | 'archiveDeleteFailed'
|
|
40
17
|
type Translate = (key: ArchiveLabelKey) => string
|
|
41
18
|
|
|
42
|
-
interface ApiSuccess<T> { ok: true; value: T }
|
|
43
|
-
interface ApiFailure { ok: false; error: { code: string; message: string } }
|
|
44
|
-
|
|
45
|
-
interface ArchiveSnapshot {
|
|
46
|
-
archivedSessionIds: string[]
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** Fetch one archive route call, attaching the server error code when present. */
|
|
50
|
-
async function archiveRequest<T>(init?: RequestInit): Promise<T> {
|
|
51
|
-
const response = await fetch(ARCHIVE_ROUTE, { credentials: 'same-origin', ...init })
|
|
52
|
-
let body: ApiSuccess<T> | ApiFailure | undefined
|
|
53
|
-
try {
|
|
54
|
-
body = await response.json() as ApiSuccess<T> | ApiFailure
|
|
55
|
-
} catch {
|
|
56
|
-
// Non-JSON response (e.g. the route is not mounted yet) — fall through to
|
|
57
|
-
// a clean error instead of a JSON-parse exception.
|
|
58
|
-
body = undefined
|
|
59
|
-
}
|
|
60
|
-
if (!response.ok || body === undefined || !body.ok) {
|
|
61
|
-
const failure = body as ApiFailure | undefined
|
|
62
|
-
const error = new Error(failure?.error?.message ?? `UI Tweaks archive request failed with HTTP ${response.status}`) as Error & { code: string | undefined }
|
|
63
|
-
error.code = failure?.error?.code
|
|
64
|
-
throw error
|
|
65
|
-
}
|
|
66
|
-
return body.value
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** Map a thrown archive error to user-facing copy. */
|
|
70
|
-
function errorMessage(error: unknown, t: Translate): string {
|
|
71
|
-
const code = (error as { code?: string } | null)?.code
|
|
72
|
-
if (code === 'session-live') return t('archiveLiveError')
|
|
73
|
-
return error instanceof Error ? error.message : String(error)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** Re-pull the host session list after a permanent delete (the outward
|
|
77
|
-
* ISessions face omits refresh; the concrete runtime provides it). */
|
|
78
|
-
function refreshSessions(sessionsService: ISessions): void {
|
|
79
|
-
void (sessionsService as unknown as { refresh(): Promise<void> }).refresh()
|
|
80
|
-
}
|
|
81
|
-
|
|
82
19
|
/** Workspace display title: the path's last non-empty segment. */
|
|
83
20
|
function basenameOf(path: string | undefined): string {
|
|
84
21
|
if (path === undefined || path === '') return ''
|
|
@@ -99,8 +36,8 @@ function relativeTime(ms: number, now: number, formatter: Intl.RelativeTimeForma
|
|
|
99
36
|
}
|
|
100
37
|
|
|
101
38
|
export const ARCHIVE_CSS = `
|
|
102
|
-
.dut-arc{display:grid;gap:12px;max-width:680px;padding:6px 2px 36px}
|
|
103
|
-
.dut-arc-head{display:flex;align-items:center;gap:10px;padding:14px 16px 0}
|
|
39
|
+
.dut-arc{display:grid;grid-template-columns:minmax(0,1fr);gap:12px;max-width:680px;padding:6px 2px 36px}
|
|
40
|
+
.dut-arc-head{display:flex;align-items:center;flex-wrap:wrap;gap:10px;padding:14px 16px 0}
|
|
104
41
|
.dut-arc-head h2{margin:0;font-size:15px;font-weight:600;letter-spacing:-.01em;color:var(--dsw-alias-label-primary)}
|
|
105
42
|
.dut-arc-count{font-size:11.5px;color:var(--dsw-alias-label-secondary);padding:2px 8px;border-radius:999px;background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l1)}
|
|
106
43
|
.dut-arc-spacer{flex:1}
|
|
@@ -109,14 +46,19 @@ export const ARCHIVE_CSS = `
|
|
|
109
46
|
.dut-arc-btn:disabled{opacity:.5;cursor:default}
|
|
110
47
|
.dut-arc-btn.dut-arc-del:hover{border-color:color-mix(in srgb,var(--dsw-alias-state-error-primary) 55%,transparent);color:var(--dsw-alias-state-error-primary);background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 10%,transparent)}
|
|
111
48
|
.dut-arc-btn.dut-arc-confirm{border-color:color-mix(in srgb,var(--dsw-alias-state-error-primary) 55%,transparent);color:var(--dsw-alias-state-error-primary);font-weight:600}
|
|
112
|
-
.dut-arc-body{display:grid;gap:2px;margin-top:4px}
|
|
49
|
+
.dut-arc-body{display:grid;grid-template-columns:minmax(0,1fr);gap:2px;margin-top:4px}
|
|
50
|
+
.dut-arc-toolbar{display:flex;align-items:center;flex-wrap:wrap;gap:10px;padding:12px 16px 0;font-size:12px;color:var(--dsw-alias-label-secondary)}
|
|
51
|
+
.dut-arc-select{display:flex;align-items:center;gap:10px;cursor:pointer}
|
|
52
|
+
.dut-arc-select input{flex-shrink:0;width:14px;height:14px;margin:0;accent-color:var(--dsw-alias-label-primary);cursor:inherit}
|
|
53
|
+
.dut-arc-session{flex:1;min-width:0}
|
|
113
54
|
.dut-arc-row{display:flex;align-items:center;gap:8px;padding:10px 16px;border-radius:12px}
|
|
114
55
|
.dut-arc-row:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
115
|
-
.dut-arc-main{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px;text-align:left;background:transparent;border:none;padding:0;
|
|
56
|
+
.dut-arc-main{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px;text-align:left;background:transparent;border:none;padding:0;color:var(--dsw-alias-label-primary);font:inherit}
|
|
116
57
|
.dut-arc-title{font-size:13.5px;font-weight:600;white-space:nowrap;text-overflow:ellipsis;overflow:hidden}
|
|
117
58
|
.dut-arc-sub{font-size:11.5px;color:var(--dsw-alias-label-secondary);white-space:nowrap;text-overflow:ellipsis;overflow:hidden}
|
|
118
59
|
.dut-arc-empty{padding:32px 16px;text-align:center;font-size:12.5px;color:var(--dsw-alias-label-secondary)}
|
|
119
|
-
.dut-arc-alert{margin:8px 16px 0;padding:8px 12px;border-radius:10px;font-size:12px;line-height:1.5;background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 10%,transparent);color:var(--dsw-alias-state-error-primary)}
|
|
60
|
+
.dut-arc-alert{margin:8px 16px 0;padding:8px 12px;border-radius:10px;font-size:12px;line-height:1.5;white-space:pre-line;background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 10%,transparent);color:var(--dsw-alias-state-error-primary)}
|
|
61
|
+
.dut-arc-targets{max-height:240px;overflow:auto;padding-inline-start:20px;overflow-wrap:anywhere}
|
|
120
62
|
.dut-arc-off{padding:20px 16px;display:grid;gap:12px}
|
|
121
63
|
.dut-arc-off p{margin:0;font-size:12.5px;line-height:1.6;color:var(--dsw-alias-label-secondary)}
|
|
122
64
|
`
|
|
@@ -143,35 +85,28 @@ interface ArchiveRow {
|
|
|
143
85
|
export interface ArchiveSectionProps {
|
|
144
86
|
controller: SettingsClient
|
|
145
87
|
t: Translate
|
|
146
|
-
|
|
88
|
+
restoreSession: (id: string) => Promise<void>
|
|
89
|
+
previewDeletion: (id: string) => Promise<readonly string[]>
|
|
90
|
+
deleteSession: (id: string, scope: readonly string[]) => Promise<void>
|
|
147
91
|
/** Framework standard feeds: session list + workspace archive set. */
|
|
148
92
|
useSessions: SnapshotSelectorHook<SessionListState>
|
|
149
93
|
useWorkspaces: SnapshotSelectorHook<WorkspaceSnapshot>
|
|
150
94
|
}
|
|
151
95
|
|
|
152
|
-
|
|
96
|
+
/** Select archived sessions for confirmed deletion, retaining failed targets for retry. */
|
|
97
|
+
export function ArchiveSection({ controller, t, restoreSession, previewDeletion, deleteSession, useSessions, useWorkspaces }: ArchiveSectionProps) {
|
|
153
98
|
const settingsState = useSyncExternalStore(controller.subscribe, controller.getSnapshot, controller.getSnapshot)
|
|
154
99
|
const enabled = settingsState.value?.archiveManagerEnabled === true
|
|
155
100
|
const sessions = useSessions(state => state)
|
|
156
101
|
const workspaces = useWorkspaces(state => state)
|
|
157
|
-
const [confirmId, setConfirmId] = useState<string | null>(null)
|
|
158
|
-
const [confirmAll, setConfirmAll] = useState(false)
|
|
159
102
|
const [busy, setBusy] = useState<string | null>(null)
|
|
103
|
+
const busyRef = useRef(false)
|
|
104
|
+
const [selected, setSelected] = useState<readonly string[]>([])
|
|
105
|
+
const [deletion, setDeletion] = useState<readonly { id: string; title: string; scope: readonly string[] }[] | null>(null)
|
|
160
106
|
const [error, setError] = useState<string | null>(null)
|
|
161
107
|
const timeFormatter = useMemo(() => new Intl.RelativeTimeFormat(navigator.language, { numeric: 'auto' }), [])
|
|
162
108
|
const now = Date.now()
|
|
163
109
|
|
|
164
|
-
useEffect(() => {
|
|
165
|
-
if (confirmId === null) return
|
|
166
|
-
const timer = window.setTimeout(() => { setConfirmId(current => (current === confirmId ? null : current)) }, 3000)
|
|
167
|
-
return () => { window.clearTimeout(timer) }
|
|
168
|
-
}, [confirmId])
|
|
169
|
-
useEffect(() => {
|
|
170
|
-
if (!confirmAll) return
|
|
171
|
-
const timer = window.setTimeout(() => { setConfirmAll(false) }, 3000)
|
|
172
|
-
return () => { window.clearTimeout(timer) }
|
|
173
|
-
}, [confirmAll])
|
|
174
|
-
|
|
175
110
|
const rows: ArchiveRow[] = useMemo(() => {
|
|
176
111
|
const byId = sessions.byId
|
|
177
112
|
return workspaces.archivedSessionIds.map(id => ({ id, summary: byId[id] })).sort((a, b) => {
|
|
@@ -180,44 +115,62 @@ export function ArchiveSection({ controller, t, sessionsService, useSessions, us
|
|
|
180
115
|
return tb - ta
|
|
181
116
|
})
|
|
182
117
|
}, [workspaces.archivedSessionIds, sessions.byId])
|
|
118
|
+
const selectedSet = useMemo(() => new Set(selected), [selected])
|
|
119
|
+
const selectedIds = rows.filter(row => selectedSet.has(row.id)).map(row => row.id)
|
|
120
|
+
const allSelected = rows.length > 0 && selectedIds.length === rows.length
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
const available = new Set(rows.map(row => row.id))
|
|
123
|
+
setSelected(previous => previous.every(id => available.has(id)) ? previous : previous.filter(id => available.has(id)))
|
|
124
|
+
}, [rows])
|
|
183
125
|
|
|
184
|
-
const run = (key: string,
|
|
126
|
+
const run = async (key: string, operation: () => Promise<void>): Promise<void> => {
|
|
127
|
+
if (busyRef.current) return
|
|
128
|
+
busyRef.current = true
|
|
185
129
|
setBusy(key)
|
|
186
130
|
setError(null)
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
body: JSON.stringify(body),
|
|
191
|
-
}).then(() => { after?.() }).catch((reason: unknown) => {
|
|
192
|
-
setError(errorMessage(reason, t))
|
|
193
|
-
}).finally(() => { setBusy(current => (current === key ? null : current)) })
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const restore = (id: string): void => {
|
|
197
|
-
run(`restore:${id}`, { action: 'restore', sessionId: id })
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const remove = (id: string): void => {
|
|
201
|
-
if (confirmId !== id) {
|
|
202
|
-
setConfirmId(id)
|
|
203
|
-
return
|
|
204
|
-
}
|
|
205
|
-
setConfirmId(null)
|
|
206
|
-
run(`delete:${id}`, { action: 'delete', sessionId: id }, () => { refreshSessions(sessionsService) })
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const restoreAll = (): void => {
|
|
210
|
-
run('restore-all', { action: 'restore-all' })
|
|
131
|
+
try { await operation() }
|
|
132
|
+
catch (reason) { setError(reason instanceof Error ? reason.message : String(reason)) }
|
|
133
|
+
finally { busyRef.current = false; setBusy(null) }
|
|
211
134
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
135
|
+
const restore = (id: string): void => { void run(`restore:${id}`, async () => {
|
|
136
|
+
await restoreSession(id)
|
|
137
|
+
setSelected(previous => previous.filter(value => value !== id))
|
|
138
|
+
}) }
|
|
139
|
+
const restoreAll = (): void => { void run('restore-all', async () => {
|
|
140
|
+
for (const row of rows) {
|
|
141
|
+
await restoreSession(row.id)
|
|
142
|
+
setSelected(previous => previous.filter(id => id !== row.id))
|
|
217
143
|
}
|
|
218
|
-
|
|
219
|
-
|
|
144
|
+
}) }
|
|
145
|
+
const requestDelete = (ids: readonly string[]): void => { void run('preview-delete', async () => {
|
|
146
|
+
const targets = []
|
|
147
|
+
const titles = new Map(rows.map(row => [row.id, row.summary?.displayTitle ?? row.id]))
|
|
148
|
+
for (const id of ids) targets.push({ id, title: titles.get(id) ?? id, scope: await previewDeletion(id) })
|
|
149
|
+
if (targets.length > 0) setDeletion(targets)
|
|
150
|
+
}) }
|
|
151
|
+
const confirmDelete = (): void => {
|
|
152
|
+
if (deletion === null) return
|
|
153
|
+
void run('delete', async () => {
|
|
154
|
+
const failed = []
|
|
155
|
+
const failures: string[] = []
|
|
156
|
+
for (const target of deletion) {
|
|
157
|
+
try { await deleteSession(target.id, target.scope) }
|
|
158
|
+
catch (reason) {
|
|
159
|
+
failed.push(target)
|
|
160
|
+
const message = reason instanceof Error ? reason.message : String(reason)
|
|
161
|
+
failures.push(deletion.length > 1
|
|
162
|
+
? t('archiveDeleteFailed').replace('{title}', () => target.title).replace('{error}', () => message)
|
|
163
|
+
: message)
|
|
164
|
+
continue
|
|
165
|
+
}
|
|
166
|
+
const removed = new Set([target.id, ...target.scope])
|
|
167
|
+
setSelected(previous => previous.filter(id => !removed.has(id)))
|
|
168
|
+
}
|
|
169
|
+
setDeletion(failed.length > 0 ? failed : null)
|
|
170
|
+
if (failures.length > 0) setError(failures.join('\n'))
|
|
171
|
+
})
|
|
220
172
|
}
|
|
173
|
+
const dismissDeletion = (): void => { if (!busyRef.current) { setDeletion(null); setError(null) } }
|
|
221
174
|
|
|
222
175
|
if (!enabled) {
|
|
223
176
|
return (
|
|
@@ -244,11 +197,25 @@ export function ArchiveSection({ controller, t, sessionsService, useSessions, us
|
|
|
244
197
|
{rows.length > 1 ? (
|
|
245
198
|
<>
|
|
246
199
|
<button type="button" className="dut-arc-btn" disabled={busy !== null} onClick={restoreAll}>{busy === 'restore-all' ? t('archiveRestoring') : t('archiveRestoreAll')}</button>
|
|
247
|
-
<button type="button" className=
|
|
200
|
+
<button type="button" className="dut-arc-btn dut-arc-del" disabled={busy !== null} onClick={() => requestDelete(rows.map(row => row.id))}>{t('archiveDeleteAll')}</button>
|
|
248
201
|
</>
|
|
249
202
|
) : null}
|
|
250
203
|
</div>
|
|
251
|
-
{
|
|
204
|
+
{rows.length > 0 && <div className="dut-arc-toolbar">
|
|
205
|
+
<label className="dut-arc-select">
|
|
206
|
+
<input type="checkbox" checked={allSelected} disabled={busy !== null}
|
|
207
|
+
ref={input => { if (input !== null) input.indeterminate = selectedIds.length > 0 && !allSelected }}
|
|
208
|
+
onChange={event => { setSelected(event.target.checked ? rows.map(row => row.id) : []) }} />
|
|
209
|
+
<span>{t('archiveSelectAll')}</span>
|
|
210
|
+
</label>
|
|
211
|
+
<span role="status">{t('archiveSelectedCount').replace('{count}', String(selectedIds.length))}</span>
|
|
212
|
+
<span className="dut-arc-spacer" />
|
|
213
|
+
<button type="button" className="dut-arc-btn" disabled={busy !== null || selectedIds.length === 0}
|
|
214
|
+
onClick={() => { setSelected([]) }}>{t('archiveClearSelection')}</button>
|
|
215
|
+
<button type="button" className="dut-arc-btn dut-arc-del" disabled={busy !== null || selectedIds.length === 0}
|
|
216
|
+
onClick={() => requestDelete(selectedIds)}>{t('archiveDeleteSelected').replace('{count}', String(selectedIds.length))}</button>
|
|
217
|
+
</div>}
|
|
218
|
+
{error !== null && deletion === null ? <div role="alert" className="dut-arc-alert">{error}</div> : null}
|
|
252
219
|
<div className="dut-arc-body">
|
|
253
220
|
{rows.length === 0 ? (
|
|
254
221
|
<div className="dut-arc-empty">{t('archiveEmpty')}</div>
|
|
@@ -258,24 +225,35 @@ export function ArchiveSection({ controller, t, sessionsService, useSessions, us
|
|
|
258
225
|
const sub = [basenameOf(summary?.cwd), summary !== undefined ? relativeTime(summary.updatedAt, now, timeFormatter) : ''].filter(Boolean).join(' · ')
|
|
259
226
|
return (
|
|
260
227
|
<div className="dut-arc-row" key={row.id}>
|
|
261
|
-
<
|
|
262
|
-
<
|
|
263
|
-
|
|
264
|
-
|
|
228
|
+
<label className="dut-arc-select dut-arc-session" title={title}>
|
|
229
|
+
<input type="checkbox" aria-label={title} checked={selectedSet.has(row.id)} disabled={busy !== null}
|
|
230
|
+
onChange={event => {
|
|
231
|
+
const checked = event.target.checked
|
|
232
|
+
setSelected(previous => checked ? [...previous, row.id] : previous.filter(id => id !== row.id))
|
|
233
|
+
}} />
|
|
234
|
+
<span className="dut-arc-main">
|
|
235
|
+
<span className="dut-arc-title">{title}</span>
|
|
236
|
+
{sub !== '' ? <span className="dut-arc-sub">{sub}</span> : null}
|
|
237
|
+
</span>
|
|
238
|
+
</label>
|
|
265
239
|
<button type="button" className="dut-arc-btn" disabled={busy !== null} onClick={() => { restore(row.id) }}>{busy === `restore:${row.id}` ? t('archiveRestoring') : t('archiveRestore')}</button>
|
|
266
|
-
<button
|
|
267
|
-
type="button"
|
|
268
|
-
className={'dut-arc-btn dut-arc-del' + (confirmId === row.id ? ' dut-arc-confirm' : '')}
|
|
269
|
-
disabled={busy !== null}
|
|
270
|
-
onClick={() => { remove(row.id) }}
|
|
271
|
-
>
|
|
272
|
-
{busy === `delete:${row.id}` ? t('archiveDelete') + '…' : confirmId === row.id ? t('archiveDelete') + '?' : t('archiveDelete')}
|
|
273
|
-
</button>
|
|
240
|
+
<button type="button" className="dut-arc-btn dut-arc-del" disabled={busy !== null} onClick={() => requestDelete([row.id])}>{t('archiveDelete')}</button>
|
|
274
241
|
</div>
|
|
275
242
|
)
|
|
276
243
|
})}
|
|
277
244
|
</div>
|
|
278
245
|
</div>
|
|
246
|
+
<Modal open={deletion !== null} title={t('archiveConfirmTitle')} closeLabel={t('archiveCancel')} onClose={dismissDeletion}
|
|
247
|
+
description={t('archiveConfirmDescription').replace('{count}', String(new Set(deletion?.flatMap(target => [...target.scope]) ?? []).size))}
|
|
248
|
+
footer={<>
|
|
249
|
+
<Button data-modal-autofocus autoFocus disabled={busy === 'delete'} onClick={dismissDeletion}>{t('archiveCancel')}</Button>
|
|
250
|
+
<Button disabled={busy !== null} onClick={confirmDelete}>{t('archiveDelete')}</Button>
|
|
251
|
+
</>}>
|
|
252
|
+
{deletion !== null && deletion.length > 1 && <ul className="dut-arc-targets">
|
|
253
|
+
{deletion.map(target => <li key={target.id}>{target.title}</li>)}
|
|
254
|
+
</ul>}
|
|
255
|
+
{error !== null && <p role="alert" style={{ whiteSpace: 'pre-line' }}>{error}</p>}
|
|
256
|
+
</Modal>
|
|
279
257
|
</div>
|
|
280
258
|
)
|
|
281
259
|
}
|