dsh-documents 0.0.0-stage → 1.0.1

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/client.js ADDED
@@ -0,0 +1,1353 @@
1
+ window.__ModuleLoader__.load({
2
+ id: 'dsh-documents',
3
+ factory(require) {
4
+ const React = require('react')
5
+ const h = React.createElement
6
+ const NS = 'dsh-documents'
7
+ const API = '/dsh-documents/api'
8
+
9
+ const EN = {
10
+ 'panel.label': 'Documents',
11
+ 'title': 'Document Library',
12
+ 'subtitle': 'Documents linked to DSH sessions',
13
+ 'count': 'documents',
14
+ 'sessionCount': 'sessions',
15
+ 'refresh': 'Refresh',
16
+ 'refresh.auto': 'Auto-refresh every 60s',
17
+ 'search': 'Search document, folder, or session',
18
+ 'filter.all': 'All',
19
+ 'sort.recent': 'Recently active',
20
+ 'sort.name': 'Name',
21
+ 'sort.size': 'Largest first',
22
+ 'workspace.all': 'All workspaces',
23
+ 'loading': 'Loading documents…',
24
+ 'empty.title': 'No session documents yet',
25
+ 'empty.body': 'When a DSH session writes, edits, or presents a document in a workspace, it appears here with its originating session.',
26
+ 'empty.filtered': 'No documents match this filter.',
27
+ 'error.title': 'Could not load documents',
28
+ 'retry': 'Retry',
29
+ 'viewer.back': 'Back to library',
30
+ 'viewer.zoomIn': 'Zoom in',
31
+ 'viewer.zoomOut': 'Zoom out',
32
+ 'viewer.zoomReset': 'Reset zoom',
33
+ 'viewer.detail': 'Details',
34
+ 'viewer.source': 'Source',
35
+ 'viewer.reading': 'Reading',
36
+ 'viewer.unsupported': 'This format cannot be previewed here. Open it in its desktop application.',
37
+ 'viewer.truncated': 'Preview truncated for large files.',
38
+ 'viewer.missing': 'This file no longer exists on disk.',
39
+ 'viewer.pick': 'Select a document from the list to view it here.',
40
+ 'viewer.list': 'List',
41
+ 'viewer.close': 'Close document',
42
+ 'detail.title': 'Details',
43
+ 'detail.path': 'Path',
44
+ 'detail.workspace': 'Workspace',
45
+ 'detail.type': 'Type',
46
+ 'detail.size': 'Size',
47
+ 'detail.modified': 'Modified',
48
+ 'detail.sessions': 'Sessions',
49
+ 'detail.created': 'Created by',
50
+ 'detail.edited': 'Edited by',
51
+ 'detail.jump': 'Open session',
52
+ 'detail.noSessions': 'No session recorded.',
53
+ 'detail.eventSeq': 'event',
54
+ 'detail.turn': 'turn',
55
+ 'detail.events': 'changes',
56
+ 'event.write': 'Write',
57
+ 'event.edit': 'Edit',
58
+ 'event.present': 'Delivered',
59
+ 'action.open': 'Open',
60
+ 'action.openExternal': 'Open in desktop app',
61
+ 'action.reveal': 'Show in folder',
62
+ 'action.rename': 'Rename',
63
+ 'action.trash': 'Move to trash',
64
+ 'action.copy': 'Copy path',
65
+ 'action.cancel': 'Cancel',
66
+ 'action.save': 'Rename',
67
+ 'rename.title': 'Rename document',
68
+ 'rename.label': 'New name',
69
+ 'trash.title': 'Move document to trash?',
70
+ 'trash.body': 'The file moves to your DSH trash folder; it is not deleted permanently.',
71
+ 'toast.open': 'Opened the document.',
72
+ 'toast.reveal': 'Opened the containing folder.',
73
+ 'toast.rename': 'Renamed.',
74
+ 'toast.trash': 'Moved to trash.',
75
+ 'toast.copied': 'Path copied.',
76
+ 'toast.copyFailed': 'Could not copy the path.',
77
+ 'toast.jump': 'Opened the session at the recorded event.',
78
+ 'toast.jumpFailed': 'Could not open that session.',
79
+ 'kind.word': 'Word',
80
+ 'kind.excel': 'Excel',
81
+ 'kind.slides': 'Slides',
82
+ 'kind.pdf': 'PDF',
83
+ 'kind.markdown': 'Markdown',
84
+ 'kind.text': 'Text',
85
+ }
86
+
87
+ const ZH = {
88
+ 'panel.label': '文档',
89
+ 'title': '文档库',
90
+ 'subtitle': '与 DSH 会话关联的文档',
91
+ 'count': '个文档',
92
+ 'sessionCount': '个会话',
93
+ 'refresh': '刷新',
94
+ 'refresh.auto': '每 60 秒自动刷新',
95
+ 'search': '搜索文档、文件夹或会话',
96
+ 'filter.all': '全部',
97
+ 'sort.recent': '最近活动',
98
+ 'sort.name': '名称',
99
+ 'sort.size': '从大到小',
100
+ 'workspace.all': '全部工作区',
101
+ 'loading': '正在加载文档…',
102
+ 'empty.title': '还没有会话文档',
103
+ 'empty.body': 'DSH 会话在工作区写入、编辑或交付文档后,会连同来源会话一起显示在这里。',
104
+ 'empty.filtered': '没有符合当前筛选的文档。',
105
+ 'error.title': '文档加载失败',
106
+ 'retry': '重试',
107
+ 'viewer.back': '返回文档库',
108
+ 'viewer.zoomIn': '放大',
109
+ 'viewer.zoomOut': '缩小',
110
+ 'viewer.zoomReset': '重置缩放',
111
+ 'viewer.detail': '详情',
112
+ 'viewer.source': '源码',
113
+ 'viewer.reading': '阅读',
114
+ 'viewer.unsupported': '该格式暂不支持在应用内预览,请用桌面应用打开。',
115
+ 'viewer.truncated': '文件较大,预览已截断。',
116
+ 'viewer.missing': '文件已不在磁盘上。',
117
+ 'viewer.pick': '从左侧列表选择文档开始查看。',
118
+ 'viewer.list': '列表',
119
+ 'viewer.close': '关闭文档',
120
+ 'detail.title': '详情',
121
+ 'detail.path': '路径',
122
+ 'detail.workspace': '工作区',
123
+ 'detail.type': '类型',
124
+ 'detail.size': '大小',
125
+ 'detail.modified': '修改时间',
126
+ 'detail.sessions': '会话',
127
+ 'detail.created': '创建会话',
128
+ 'detail.edited': '编辑会话',
129
+ 'detail.jump': '打开会话',
130
+ 'detail.noSessions': '没有记录到会话。',
131
+ 'detail.eventSeq': '事件',
132
+ 'detail.turn': '轮次',
133
+ 'detail.events': '次变动',
134
+ 'event.write': '写入',
135
+ 'event.edit': '修改',
136
+ 'event.present': '交付',
137
+ 'action.open': '打开',
138
+ 'action.openExternal': '用桌面应用打开',
139
+ 'action.reveal': '在文件夹中显示',
140
+ 'action.rename': '重命名',
141
+ 'action.trash': '移入回收站',
142
+ 'action.copy': '复制路径',
143
+ 'action.cancel': '取消',
144
+ 'action.save': '重命名',
145
+ 'rename.title': '重命名文档',
146
+ 'rename.label': '新名称',
147
+ 'trash.title': '将文档移入回收站?',
148
+ 'trash.body': '文件会被移动到 DSH 回收站目录,不会永久删除。',
149
+ 'toast.open': '已打开文档。',
150
+ 'toast.reveal': '已打开所在文件夹。',
151
+ 'toast.rename': '已重命名。',
152
+ 'toast.trash': '已移入回收站。',
153
+ 'toast.copied': '路径已复制。',
154
+ 'toast.copyFailed': '复制路径失败。',
155
+ 'toast.jump': '已打开会话并定位到记录的事件。',
156
+ 'toast.jumpFailed': '无法打开该会话。',
157
+ 'kind.word': 'Word',
158
+ 'kind.excel': 'Excel',
159
+ 'kind.slides': 'PPT',
160
+ 'kind.pdf': 'PDF',
161
+ 'kind.markdown': 'Markdown',
162
+ 'kind.text': '文本',
163
+ }
164
+
165
+ const KIND_ORDER = ['word', 'excel', 'slides', 'pdf', 'markdown', 'text']
166
+ const KIND_DOT = {
167
+ word: '#2b579a',
168
+ excel: '#217346',
169
+ slides: '#c2410c',
170
+ pdf: '#b42318',
171
+ markdown: '#6d5bd0',
172
+ text: '#5b6472',
173
+ }
174
+ const REFRESH_MS = 60 * 1000
175
+
176
+ const CSS = `
177
+ .dshdoc-page {
178
+ --dshdoc-border: var(--dsw-alias-border-l1);
179
+ display: flex;
180
+ flex-direction: column;
181
+ height: 100%;
182
+ min-height: 0;
183
+ background: var(--dsw-alias-bg-base);
184
+ color: var(--dsw-alias-label-primary);
185
+ font-size: 14px;
186
+ position: relative;
187
+ }
188
+ .dshdoc-page, .dshdoc-page *, .dshdoc-page *::before, .dshdoc-page *::after { box-sizing: border-box; }
189
+ .dshdoc-head { display: flex; align-items: flex-end; gap: 16px; padding: 22px 28px 14px; }
190
+ .dshdoc-head-main { flex: 1; min-width: 0; }
191
+ .dshdoc-title { display: flex; align-items: center; gap: 10px; font-size: 20px; line-height: 1.3; font-weight: 600; letter-spacing: -0.01em; }
192
+ .dshdoc-brandmark { width: 30px; height: 30px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; color: var(--dsw-alias-brand-primary); background: color-mix(in srgb, var(--dsw-alias-brand-primary) 12%, transparent); border: 1px solid color-mix(in srgb, var(--dsw-alias-brand-primary) 22%, transparent); }
193
+ .dshdoc-badge { font-size: 11px; font-weight: 500; line-height: 1; padding: 4px 8px; border-radius: 999px; color: var(--dsw-alias-label-secondary); background: color-mix(in srgb, var(--dsw-alias-label-primary) 7%, transparent); }
194
+ .dshdoc-sub { margin-top: 4px; font-size: 12.5px; color: var(--dsw-alias-label-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
195
+ .dshdoc-head-actions { display: flex; align-items: center; gap: 8px; padding-bottom: 2px; }
196
+ .dshdoc-refresh-hint { font-size: 10.5px; color: var(--dsw-alias-label-tertiary); white-space: nowrap; }
197
+ @media (max-width: 1200px) { .dshdoc-refresh-hint { display: none; } }
198
+ .dshdoc-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--dshdoc-border); background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-primary); font: inherit; font-size: 13px; cursor: pointer; white-space: nowrap; transition: background 120ms ease, border-color 120ms ease, opacity 120ms ease; }
199
+ .dshdoc-btn:hover { background: color-mix(in srgb, var(--dsw-alias-label-primary) 6%, var(--dsw-alias-bg-layer-1)); }
200
+ .dshdoc-btn:disabled { opacity: 0.55; cursor: default; }
201
+ .dshdoc-btn-brand { border-color: color-mix(in srgb, var(--dsw-alias-brand-primary) 34%, transparent); background: color-mix(in srgb, var(--dsw-alias-brand-primary) 12%, transparent); color: var(--dsw-alias-brand-primary); }
202
+ .dshdoc-btn-brand:hover { background: color-mix(in srgb, var(--dsw-alias-brand-primary) 18%, transparent); }
203
+ .dshdoc-btn-danger { border-color: color-mix(in srgb, var(--dsw-alias-state-error-primary) 30%, transparent); background: transparent; color: var(--dsw-alias-state-error-primary); }
204
+ .dshdoc-btn-danger:hover { background: color-mix(in srgb, var(--dsw-alias-state-error-primary) 10%, transparent); }
205
+ .dshdoc-iconbtn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 0; border: none; border-radius: 8px; background: transparent; color: var(--dsw-alias-label-secondary); cursor: pointer; flex: none; }
206
+ .dshdoc-iconbtn:hover { background: color-mix(in srgb, var(--dsw-alias-label-primary) 8%, transparent); color: var(--dsw-alias-label-primary); }
207
+ .dshdoc-iconbtn:disabled { opacity: 0.45; cursor: default; }
208
+ .dshdoc-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 0 20px 14px; }
209
+ .dshdoc-search { position: relative; display: flex; align-items: center; flex: 1 1 220px; min-width: 180px; max-width: 360px; height: 34px; border: 1px solid var(--dshdoc-border); border-radius: 10px; background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-secondary); padding: 0 10px; gap: 7px; }
210
+ .dshdoc-search:focus-within { border-color: color-mix(in srgb, var(--dsw-alias-brand-primary) 45%, var(--dshdoc-border)); }
211
+ .dshdoc-search input { flex: 1; min-width: 0; height: 100%; border: none; outline: none; background: transparent; color: var(--dsw-alias-label-primary); font: inherit; font-size: 13px; }
212
+ .dshdoc-search input::placeholder { color: var(--dsw-alias-label-tertiary); }
213
+ .dshdoc-chips { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; flex: 1 1 auto; }
214
+ .dshdoc-chip { height: 30px; padding: 0 11px; border-radius: 999px; border: 1px solid transparent; background: transparent; color: var(--dsw-alias-label-secondary); font: inherit; font-size: 12.5px; cursor: pointer; white-space: nowrap; }
215
+ .dshdoc-chip:hover { background: color-mix(in srgb, var(--dsw-alias-label-primary) 6%, transparent); color: var(--dsw-alias-label-primary); }
216
+ .dshdoc-chip[data-active="true"] { color: var(--dsw-alias-brand-primary); border-color: color-mix(in srgb, var(--dsw-alias-brand-primary) 30%, transparent); background: color-mix(in srgb, var(--dsw-alias-brand-primary) 10%, transparent); }
217
+ .dshdoc-chip-dot { display: inline-block; width: 7px; height: 7px; border-radius: 999px; margin-right: 5px; vertical-align: 1px; }
218
+ .dshdoc-select { height: 32px; border-radius: 9px; border: 1px solid var(--dshdoc-border); background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-primary); font: inherit; font-size: 12.5px; padding: 0 8px; cursor: pointer; max-width: 180px; }
219
+ .dshdoc-list-wrap { flex: 1; min-height: 0; overflow: auto; border-top: 1px solid var(--dshdoc-border); padding: 10px 14px 28px; }
220
+ .dshdoc-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 11px; border: 1px solid transparent; border-radius: 11px; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; outline: none; }
221
+ .dshdoc-row:hover { background: color-mix(in srgb, var(--dsw-alias-label-primary) 4.5%, transparent); }
222
+ .dshdoc-row:focus-visible { border-color: color-mix(in srgb, var(--dsw-alias-brand-primary) 55%, transparent); }
223
+ .dshdoc-tile { flex: none; width: 38px; height: 42px; border-radius: 9px; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 6px; font-size: 9.5px; font-weight: 700; letter-spacing: 0.02em; position: relative; overflow: hidden; }
224
+ .dshdoc-tile::after { content: ""; position: absolute; top: 0; right: 0; border-width: 0 9px 9px 0; border-style: solid; border-color: transparent rgba(255, 255, 255, 0.5) transparent transparent; }
225
+ .dshdoc-row-main { flex: 1; min-width: 0; }
226
+ .dshdoc-name { display: block; font-size: 14px; font-weight: 500; line-height: 1.45; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
227
+ .dshdoc-meta { display: block; margin-top: 2px; font-size: 12px; line-height: 1.5; color: var(--dsw-alias-label-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
228
+ .dshdoc-meta span + span::before { content: "·"; margin: 0 6px; color: var(--dsw-alias-label-tertiary); }
229
+ .dshdoc-row-side { flex: none; text-align: right; font-size: 11.5px; color: var(--dsw-alias-label-tertiary); display: flex; flex-direction: column; gap: 2px; align-items: flex-end; }
230
+ .dshdoc-session-dot { display: inline-block; width: 6px; height: 6px; border-radius: 999px; background: var(--dsw-alias-brand-primary); margin-right: 5px; vertical-align: 1px; }
231
+ .dshdoc-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 40px 24px 80px; text-align: center; }
232
+ .dshdoc-empty-art { color: var(--dsw-alias-label-tertiary); opacity: 0.9; margin-bottom: 4px; }
233
+ .dshdoc-empty-title { font-size: 15px; font-weight: 600; }
234
+ .dshdoc-empty-body { font-size: 12.5px; line-height: 1.65; color: var(--dsw-alias-label-secondary); max-width: 460px; }
235
+ .dshdoc-skeleton { padding: 12px 4px; }
236
+ .dshdoc-skeleton-row { display: flex; gap: 12px; align-items: center; padding: 9px 11px; }
237
+ .dshdoc-skeleton-tile { width: 38px; height: 42px; border-radius: 9px; background: color-mix(in srgb, var(--dsw-alias-label-primary) 7%, transparent); }
238
+ .dshdoc-skeleton-lines { flex: 1; display: flex; flex-direction: column; gap: 7px; }
239
+ .dshdoc-skeleton-line { height: 10px; border-radius: 5px; background: color-mix(in srgb, var(--dsw-alias-label-primary) 6%, transparent); animation: dshdoc-pulse 1.4s ease-in-out infinite; }
240
+ @keyframes dshdoc-pulse { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }
241
+ .dshdoc-toast { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); max-width: min(560px, calc(100% - 40px)); padding: 9px 14px; border-radius: 10px; border: 1px solid var(--dshdoc-border); background: var(--dsw-alias-bg-overlay); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18); font-size: 12.5px; color: var(--dsw-alias-label-primary); z-index: 40; }
242
+ .dshdoc-toast[data-error="true"] { border-color: color-mix(in srgb, var(--dsw-alias-state-error-primary) 45%, transparent); color: var(--dsw-alias-state-error-primary); }
243
+ .dshdoc-overlay { position: absolute; inset: 0; background: rgba(10, 12, 18, 0.42); display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 50; }
244
+ .dshdoc-dialog { width: min(440px, 100%); border-radius: 14px; border: 1px solid var(--dshdoc-border); background: var(--dsw-alias-bg-overlay); box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28); padding: 20px; }
245
+ .dshdoc-dialog-title { font-size: 15px; font-weight: 600; }
246
+ .dshdoc-dialog-body { margin-top: 6px; font-size: 12.5px; line-height: 1.6; color: var(--dsw-alias-label-secondary); }
247
+ .dshdoc-input { width: 100%; height: 36px; margin-top: 14px; box-sizing: border-box; border-radius: 9px; border: 1px solid var(--dshdoc-border); background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-primary); font: inherit; font-size: 13.5px; padding: 0 11px; outline: none; }
248
+ .dshdoc-input:focus { border-color: color-mix(in srgb, var(--dsw-alias-brand-primary) 55%, transparent); }
249
+ .dshdoc-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
250
+ .dshdoc-error { color: var(--dsw-alias-state-error-primary); }
251
+ .dshdoc-view-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--dshdoc-border); background: var(--dsw-alias-bg-layer-1); }
252
+ .dshdoc-view-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 16px; border-bottom: 1px solid var(--dshdoc-border); background: var(--dsw-alias-bg-layer-1); }
253
+ .dshdoc-view-spacer { flex: 1 1 auto; min-width: 8px; }
254
+ .dshdoc-view-titlebox { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
255
+ .dshdoc-view-name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
256
+ .dshdoc-view-sub { font-size: 11.5px; color: var(--dsw-alias-label-secondary); margin-top: 2px; }
257
+ .dshdoc-zoom { display: flex; align-items: center; gap: 2px; border: 1px solid var(--dshdoc-border); border-radius: 9px; background: var(--dsw-alias-bg-base); padding: 2px; }
258
+ .dshdoc-zoom-value { min-width: 44px; text-align: center; font-size: 11.5px; color: var(--dsw-alias-label-secondary); }
259
+ .dshdoc-body { flex: 1; min-height: 0; display: flex; position: relative; border-top: 1px solid var(--dshdoc-border); }
260
+ .dshdoc-side { flex: 0 0 330px; min-width: 0; display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--dshdoc-border); background: var(--dsw-alias-bg-base); position: relative; z-index: 2; overflow: hidden; }
261
+ .dshdoc-side-head { display: flex; flex-direction: column; gap: 8px; padding: 12px 12px 10px; border-bottom: 1px solid var(--dshdoc-border); background: var(--dsw-alias-bg-layer-1); }
262
+ .dshdoc-side-head .dshdoc-search { max-width: none; width: 100%; flex: none; }
263
+ .dshdoc-side-head .dshdoc-chips { gap: 4px; }
264
+ .dshdoc-side-head .dshdoc-chip { height: 26px; padding: 0 8px; font-size: 11.5px; }
265
+ .dshdoc-side-head .dshdoc-select { max-width: none; width: 100%; height: 30px; }
266
+ .dshdoc-side-filters { display: flex; gap: 8px; min-width: 0; }
267
+ .dshdoc-side-filters .dshdoc-select { flex: 1 1 0; min-width: 0; width: auto; }
268
+ .dshdoc-side-list { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; scrollbar-gutter: stable; padding: 6px 10px 24px 8px; }
269
+ .dshdoc-side .dshdoc-row { padding: 8px 9px; gap: 10px; }
270
+ .dshdoc-side .dshdoc-tile { width: 34px; height: 38px; font-size: 8.5px; }
271
+ .dshdoc-row[data-selected="true"] { background: color-mix(in srgb, var(--dsw-alias-brand-primary) 9%, transparent); border-color: color-mix(in srgb, var(--dsw-alias-brand-primary) 26%, transparent); box-shadow: inset 3px 0 0 var(--dsw-alias-brand-primary); }
272
+ .dshdoc-main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; background: var(--dsw-alias-bg-base); overflow: hidden; }
273
+ .dshdoc-main-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 40px; text-align: center; color: var(--dsw-alias-label-secondary); font-size: 13px; }
274
+ .dshdoc-list-toggle { display: none; }
275
+ .dshdoc-detail-head { display: flex; align-items: center; gap: 8px; }
276
+ .dshdoc-detail-head .dshdoc-section-title { flex: 1; }
277
+ .dshdoc-view-body { flex: 1; min-height: 0; display: flex; position: relative; overflow: hidden; }
278
+ .dshdoc-view-main { flex: 1; min-width: 0; overflow: auto; padding: 28px 32px 80px; }
279
+ .dshdoc-doc { max-width: 860px; margin: 0 auto; }
280
+ .dshdoc-doc-pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; line-height: 1.65; }
281
+ .dshdoc-md { line-height: 1.75; word-break: break-word; }
282
+ .dshdoc-md h1 { font-size: 1.7em; margin: 0.9em 0 0.5em; line-height: 1.35; }
283
+ .dshdoc-md h2 { font-size: 1.4em; margin: 1.2em 0 0.45em; line-height: 1.4; }
284
+ .dshdoc-md h3 { font-size: 1.18em; margin: 1.1em 0 0.4em; }
285
+ .dshdoc-md h4, .dshdoc-md h5, .dshdoc-md h6 { font-size: 1em; margin: 1em 0 0.35em; }
286
+ .dshdoc-md p { margin: 0.55em 0; }
287
+ .dshdoc-md ul, .dshdoc-md ol { margin: 0.5em 0; padding-left: 1.5em; }
288
+ .dshdoc-md li { margin: 0.2em 0; }
289
+ .dshdoc-md code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; background: color-mix(in srgb, var(--dsw-alias-label-primary) 7%, transparent); padding: 0.12em 0.35em; border-radius: 5px; }
290
+ .dshdoc-md pre.dshdoc-md-code { margin: 0.8em 0; padding: 12px 14px; overflow: auto; border-radius: 10px; border: 1px solid var(--dshdoc-border); background: var(--dsw-alias-bg-layer-2); }
291
+ .dshdoc-md pre.dshdoc-md-code code { background: transparent; padding: 0; font-size: 0.88em; }
292
+ .dshdoc-md blockquote { margin: 0.8em 0; padding: 2px 0 2px 14px; border-left: 3px solid color-mix(in srgb, var(--dsw-alias-brand-primary) 45%, transparent); color: var(--dsw-alias-label-secondary); }
293
+ .dshdoc-md hr { margin: 1.4em 0; border: none; border-top: 1px solid var(--dshdoc-border); }
294
+ .dshdoc-md a { color: var(--dsw-alias-brand-primary); text-decoration: none; }
295
+ .dshdoc-md a:hover { text-decoration: underline; }
296
+ .dshdoc-md table { border-collapse: collapse; margin: 0.9em 0; font-size: 0.94em; }
297
+ .dshdoc-md th, .dshdoc-md td { border: 1px solid var(--dshdoc-border); padding: 6px 10px; text-align: left; }
298
+ .dshdoc-md th { background: color-mix(in srgb, var(--dsw-alias-label-primary) 5%, transparent); }
299
+ .dshdoc-media { display: block; max-width: 100%; margin: 0 auto; border-radius: 8px; }
300
+ .dshdoc-pdf { width: 100%; height: 100%; border: none; background: #fff; }
301
+ .dshdoc-unsupported { max-width: 520px; margin: 60px auto; padding: 28px; border: 1px dashed var(--dshdoc-border); border-radius: 14px; text-align: center; color: var(--dsw-alias-label-secondary); font-size: 13px; line-height: 1.7; }
302
+ .dshdoc-detail { position: absolute; top: 0; right: 0; bottom: 0; width: min(360px, 100%); z-index: 20; border-left: 1px solid var(--dshdoc-border); background: var(--dsw-alias-bg-base); box-shadow: -12px 0 32px rgba(0, 0, 0, 0.16); overflow: auto; padding: 14px 14px 28px; display: flex; flex-direction: column; gap: 12px; }
303
+ .dshdoc-section-title { font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--dsw-alias-label-tertiary); }
304
+ .dshdoc-card { border: 1px solid var(--dshdoc-border); border-radius: 12px; background: var(--dsw-alias-bg-layer-1); padding: 11px 12px; }
305
+ .dshdoc-card-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--dsw-alias-label-tertiary); margin-bottom: 9px; }
306
+ .dshdoc-card-count { font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--dsw-alias-label-secondary); }
307
+ .dshdoc-fields { display: grid; grid-template-columns: 64px 1fr; gap: 8px 10px; font-size: 12.5px; }
308
+ .dshdoc-field-label { color: var(--dsw-alias-label-secondary); }
309
+ .dshdoc-field-value { color: var(--dsw-alias-label-primary); word-break: break-all; min-width: 0; }
310
+ .dshdoc-pathbox { margin-top: 10px; padding: 7px 9px; border-radius: 8px; background: color-mix(in srgb, var(--dsw-alias-label-primary) 5%, transparent); border: 1px solid var(--dshdoc-border); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 10.5px; line-height: 1.5; color: var(--dsw-alias-label-secondary); word-break: break-all; }
311
+ .dshdoc-session { border: 1px solid var(--dshdoc-border); border-radius: 10px; padding: 10px 11px 4px 12px; background: var(--dsw-alias-bg-base); border-left: 3px solid transparent; }
312
+ .dshdoc-session[data-role="origin"] { border-left-color: var(--dsw-alias-brand-primary); }
313
+ .dshdoc-session[data-role="editor"] { border-left-color: var(--dsw-alias-state-warn-primary); }
314
+ .dshdoc-session + .dshdoc-session { margin-top: 9px; }
315
+ .dshdoc-session-head { display: flex; align-items: center; gap: 7px; }
316
+ .dshdoc-role { font-size: 9.5px; font-weight: 700; letter-spacing: 0.02em; padding: 2px 6px; border-radius: 5px; flex: none; }
317
+ .dshdoc-role[data-role="origin"] { color: var(--dsw-alias-brand-primary); background: color-mix(in srgb, var(--dsw-alias-brand-primary) 13%, transparent); }
318
+ .dshdoc-role[data-role="editor"] { color: var(--dsw-alias-state-warn-primary); background: color-mix(in srgb, var(--dsw-alias-state-warn-primary) 14%, transparent); }
319
+ .dshdoc-session-title { flex: 1; min-width: 0; font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
320
+ .dshdoc-session-sub { margin-top: 3px; font-size: 10.5px; color: var(--dsw-alias-label-tertiary); }
321
+ .dshdoc-jump { flex: none; font-size: 11px; color: var(--dsw-alias-brand-primary); background: transparent; border: none; padding: 2px 0; cursor: pointer; font-family: inherit; }
322
+ .dshdoc-jump:hover { text-decoration: underline; }
323
+ .dshdoc-event { margin-top: 9px; padding: 8px 9px 9px; border-radius: 8px; background: color-mix(in srgb, var(--dsw-alias-label-primary) 3.5%, transparent); border-left: 3px solid color-mix(in srgb, var(--dsw-alias-label-primary) 14%, transparent); }
324
+ .dshdoc-event[data-kind="write"] { border-left-color: color-mix(in srgb, var(--dsw-alias-brand-primary) 70%, transparent); background: color-mix(in srgb, var(--dsw-alias-brand-primary) 5%, transparent); }
325
+ .dshdoc-event[data-kind="edit"] { border-left-color: color-mix(in srgb, var(--dsw-alias-state-warn-primary) 75%, transparent); background: color-mix(in srgb, var(--dsw-alias-state-warn-primary) 5%, transparent); }
326
+ .dshdoc-event[data-kind="present"] { border-left-color: color-mix(in srgb, var(--dsw-alias-state-success-primary) 70%, transparent); background: color-mix(in srgb, var(--dsw-alias-state-success-primary) 5%, transparent); }
327
+ .dshdoc-event-head { display: flex; align-items: flex-start; gap: 7px; }
328
+ .dshdoc-event-summary { flex: 1; min-width: 0; font-size: 12px; line-height: 1.5; color: var(--dsw-alias-label-primary); }
329
+ .dshdoc-kind-chip { flex: none; font-size: 9.5px; font-weight: 700; padding: 2px 6px; border-radius: 5px; color: var(--dsw-alias-label-secondary); background: color-mix(in srgb, var(--dsw-alias-label-primary) 8%, transparent); }
330
+ .dshdoc-kind-chip[data-kind="write"] { color: var(--dsw-alias-brand-primary); background: color-mix(in srgb, var(--dsw-alias-brand-primary) 14%, transparent); }
331
+ .dshdoc-kind-chip[data-kind="edit"] { color: var(--dsw-alias-state-warn-primary); background: color-mix(in srgb, var(--dsw-alias-state-warn-primary) 15%, transparent); }
332
+ .dshdoc-kind-chip[data-kind="present"] { color: var(--dsw-alias-state-success-primary); background: color-mix(in srgb, var(--dsw-alias-state-success-primary) 14%, transparent); }
333
+ .dshdoc-event-meta { margin-top: 6px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; font-size: 10px; color: var(--dsw-alias-label-tertiary); }
334
+ .dshdoc-pill { padding: 1px 6px; border-radius: 999px; background: color-mix(in srgb, var(--dsw-alias-label-primary) 6%, transparent); border: 1px solid var(--dshdoc-border); font-size: 10px; }
335
+ .dshdoc-event-meta button { border: none; background: transparent; color: var(--dsw-alias-brand-primary); font: inherit; cursor: pointer; padding: 0 0 0 2px; }
336
+ .dshdoc-event-preview { margin: 7px 0 0; padding: 7px 9px; border-radius: 7px; background: var(--dsw-alias-bg-layer-2); color: var(--dsw-alias-label-secondary); font-size: 10.5px; line-height: 1.6; max-height: 110px; overflow: hidden; white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
337
+ .dshdoc-actions { display: flex; flex-direction: column; gap: 6px; }
338
+ .dshdoc-actions .dshdoc-btn { width: 100%; justify-content: flex-start; }
339
+ .dshdoc-divider { height: 1px; margin: 4px 0; background: var(--dshdoc-border); }
340
+ .dshdoc-checkbox { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--dsw-alias-label-secondary); }
341
+ .dshdoc-scrim { display: none; }
342
+ @media (max-width: 900px) {
343
+ .dshdoc-scrim { display: block; position: absolute; inset: 0; z-index: 25; background: rgba(8, 10, 16, 0.32); }
344
+ .dshdoc-side { position: absolute; top: 0; bottom: 0; left: 0; z-index: 30; width: min(340px, 88%); box-shadow: 14px 0 34px rgba(0, 0, 0, 0.2); display: none; }
345
+ .dshdoc-side[data-open="true"] { display: flex; }
346
+ .dshdoc-list-toggle { display: inline-flex; }
347
+ }
348
+ `
349
+
350
+ function translateWith(dict) {
351
+ return (key) => dict[key] ?? EN[key] ?? key
352
+ }
353
+
354
+ function formatBytes(bytes) {
355
+ if (!Number.isFinite(bytes) || bytes < 0) return '—'
356
+ if (bytes < 1024) return `${bytes} B`
357
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`
358
+ return `${(bytes / 1024 / 1024).toFixed(1)} MB`
359
+ }
360
+
361
+ const timeFormat = new Intl.DateTimeFormat(undefined, {
362
+ year: 'numeric', month: '2-digit', day: '2-digit',
363
+ hour: '2-digit', minute: '2-digit', hour12: false,
364
+ })
365
+
366
+ function formatTime(ms) {
367
+ const date = new Date(ms)
368
+ return Number.isNaN(date.getTime()) ? '—' : timeFormat.format(date)
369
+ }
370
+
371
+ function folderOf(rel) {
372
+ const value = String(rel || '')
373
+ const index = Math.max(value.lastIndexOf('\\'), value.lastIndexOf('/'))
374
+ return index > 0 ? value.slice(0, index) : '.'
375
+ }
376
+
377
+ function tileLabel(doc) {
378
+ const ext = (doc.ext || '').toUpperCase()
379
+ if (ext === 'DOCX' || ext === 'DOC') return 'DOC'
380
+ if (ext === 'XLSX' || ext === 'XLS' || ext === 'CSV') return 'XLS'
381
+ if (ext === 'PPTX' || ext === 'PPT') return 'PPT'
382
+ if (ext === 'MD') return 'MD'
383
+ if (ext === 'PDF') return 'PDF'
384
+ return ext.slice(0, 4) || 'FILE'
385
+ }
386
+
387
+ function tileStyle(doc) {
388
+ const color = doc.color || '#5b6472'
389
+ return {
390
+ color,
391
+ background: `color-mix(in srgb, ${color} 16%, transparent)`,
392
+ border: `1px solid color-mix(in srgb, ${color} 28%, transparent)`,
393
+ }
394
+ }
395
+
396
+ async function requestJson(path, init) {
397
+ const response = await fetch(API + path, {
398
+ ...init,
399
+ cache: 'no-store',
400
+ headers: { 'x-dsh-documents': '1', ...(init && init.headers ? init.headers : {}) },
401
+ })
402
+ const data = await response.json().catch(() => null)
403
+ if (!response.ok || data === null || data.ok === false) {
404
+ throw new Error((data && data.error) || `HTTP ${response.status}`)
405
+ }
406
+ return data
407
+ }
408
+
409
+ function DocGlyph({ size = 18 }) {
410
+ return h('svg', { width: size, height: size, viewBox: '0 0 20 20', fill: 'none', 'aria-hidden': true },
411
+ h('path', { d: 'M5.2 2.6h6.1l3.5 3.4v11.4H5.2z', stroke: 'currentColor', strokeWidth: 1.4, strokeLinejoin: 'round' }),
412
+ h('path', { d: 'M11.2 2.9v3.2h3.4', stroke: 'currentColor', strokeWidth: 1.4, strokeLinejoin: 'round' }),
413
+ h('path', { d: 'M7.3 9.6h4.9M7.3 12.4h4.9', stroke: 'currentColor', strokeWidth: 1.3, strokeLinecap: 'round' }),
414
+ )
415
+ }
416
+
417
+ function SearchGlyph() {
418
+ return h('svg', { width: 15, height: 15, viewBox: '0 0 16 16', fill: 'none', 'aria-hidden': true },
419
+ h('circle', { cx: 7, cy: 7, r: 4.4, stroke: 'currentColor', strokeWidth: 1.5 }),
420
+ h('path', { d: 'M10.4 10.4 14 14', stroke: 'currentColor', strokeWidth: 1.5, strokeLinecap: 'round' }),
421
+ )
422
+ }
423
+
424
+ function ListGlyph() {
425
+ return h('svg', { width: 16, height: 16, viewBox: '0 0 16 16', fill: 'none', 'aria-hidden': true },
426
+ h('path', { d: 'M3 4.2h10M3 8h10M3 11.8h10', stroke: 'currentColor', strokeWidth: 1.5, strokeLinecap: 'round' }),
427
+ )
428
+ }
429
+
430
+ function CloseGlyph() {
431
+ return h('svg', { width: 15, height: 15, viewBox: '0 0 16 16', fill: 'none', 'aria-hidden': true },
432
+ h('path', { d: 'm4 4 8 8M12 4l-8 8', stroke: 'currentColor', strokeWidth: 1.5, strokeLinecap: 'round' }),
433
+ )
434
+ }
435
+
436
+ function PanelIcon({ size = 16 }) {
437
+ return h('svg', {
438
+ width: size, height: size, viewBox: '0 0 20 20', fill: 'none',
439
+ 'aria-hidden': true, style: { display: 'block' },
440
+ },
441
+ h('path', { d: 'M5.1 2.5h5.8l3.9 3.8v11.2H5.1z', stroke: 'currentColor', strokeWidth: 1.4, strokeLinejoin: 'round' }),
442
+ h('path', { d: 'M10.8 2.8v3.6h3.7', stroke: 'currentColor', strokeWidth: 1.4, strokeLinejoin: 'round' }),
443
+ h('path', { d: 'M7.2 9.4h4.9M7.2 12.2h4.9M7.2 15h3.1', stroke: 'currentColor', strokeWidth: 1.25, strokeLinecap: 'round' }),
444
+ )
445
+ }
446
+
447
+ function inlineNodes(text, prefix) {
448
+ const nodes = []
449
+ const pattern = /(\*\*[^*]+\*\*|`[^`]+`|\[[^\]]+\]\([^)\s]+\)|\*[^*\n]+\*)/g
450
+ let last = 0
451
+ let match
452
+ let index = 0
453
+ while ((match = pattern.exec(text)) !== null) {
454
+ if (match.index > last) nodes.push(text.slice(last, match.index))
455
+ const token = match[0]
456
+ const key = `${prefix}-${index++}`
457
+ if (token.startsWith('**')) {
458
+ nodes.push(h('strong', { key }, token.slice(2, -2)))
459
+ } else if (token.startsWith('`')) {
460
+ nodes.push(h('code', { key }, token.slice(1, -1)))
461
+ } else if (token.startsWith('[')) {
462
+ const link = /^\[([^\]]+)\]\(([^)\s]+)\)$/.exec(token)
463
+ if (link && /^https?:\/\//i.test(link[2])) {
464
+ nodes.push(h('a', { key, href: link[2], target: '_blank', rel: 'noreferrer noopener' }, link[1]))
465
+ } else {
466
+ nodes.push(token)
467
+ }
468
+ } else {
469
+ nodes.push(h('em', { key }, token.slice(1, -1)))
470
+ }
471
+ last = match.index + token.length
472
+ }
473
+ if (last < text.length) nodes.push(text.slice(last))
474
+ return nodes
475
+ }
476
+
477
+ function splitRow(line) {
478
+ return line.replace(/^\|/, '').replace(/\|$/, '').split('|').map((cell) => cell.trim())
479
+ }
480
+
481
+ function renderMarkdown(text) {
482
+ const lines = String(text || '').replace(/\r\n/g, '\n').split('\n')
483
+ const nodes = []
484
+ let index = 0
485
+ let key = 0
486
+ const nextKey = () => `md-${key++}`
487
+ while (index < lines.length) {
488
+ const line = lines[index]
489
+ if (/^\s*$/.test(line)) {
490
+ index += 1
491
+ continue
492
+ }
493
+ const fence = /^\s*```(.*)$/.exec(line)
494
+ if (fence) {
495
+ const language = fence[1].trim()
496
+ index += 1
497
+ const body = []
498
+ while (index < lines.length && !/^\s*```/.test(lines[index])) {
499
+ body.push(lines[index])
500
+ index += 1
501
+ }
502
+ index += 1
503
+ nodes.push(h('pre', { key: nextKey(), className: 'dshdoc-md-code' },
504
+ h('code', { 'data-lang': language }, body.join('\n'))))
505
+ continue
506
+ }
507
+ const heading = /^(#{1,6})\s+(.*)$/.exec(line)
508
+ if (heading) {
509
+ const level = heading[1].length
510
+ nodes.push(h(`h${level}`, { key: nextKey() }, inlineNodes(heading[2], nextKey())))
511
+ index += 1
512
+ continue
513
+ }
514
+ if (/^\s*(---+|\*\*\*+|___+)\s*$/.test(line)) {
515
+ nodes.push(h('hr', { key: nextKey() }))
516
+ index += 1
517
+ continue
518
+ }
519
+ if (/^\s*[-*+]\s+/.test(line)) {
520
+ const items = []
521
+ while (index < lines.length && /^\s*[-*+]\s+/.test(lines[index])) {
522
+ items.push(lines[index].replace(/^\s*[-*+]\s+/, ''))
523
+ index += 1
524
+ }
525
+ nodes.push(h('ul', { key: nextKey() }, items.map((item, itemIndex) => (
526
+ h('li', { key: `${nextKey()}-${itemIndex}` }, inlineNodes(item, nextKey()))
527
+ ))))
528
+ continue
529
+ }
530
+ if (/^\s*\d+\.\s+/.test(line)) {
531
+ const items = []
532
+ while (index < lines.length && /^\s*\d+\.\s+/.test(lines[index])) {
533
+ items.push(lines[index].replace(/^\s*\d+\.\s+/, ''))
534
+ index += 1
535
+ }
536
+ nodes.push(h('ol', { key: nextKey() }, items.map((item, itemIndex) => (
537
+ h('li', { key: `${nextKey()}-${itemIndex}` }, inlineNodes(item, nextKey()))
538
+ ))))
539
+ continue
540
+ }
541
+ if (/^>\s?/.test(line)) {
542
+ const body = []
543
+ while (index < lines.length && /^>\s?/.test(lines[index])) {
544
+ body.push(lines[index].replace(/^>\s?/, ''))
545
+ index += 1
546
+ }
547
+ nodes.push(h('blockquote', { key: nextKey() }, inlineNodes(body.join(' '), nextKey())))
548
+ continue
549
+ }
550
+ if (/^\s*\|/.test(line) && index + 1 < lines.length && /^\s*\|?[\s:|-]+\|?\s*$/.test(lines[index + 1])) {
551
+ const header = splitRow(lines[index])
552
+ index += 2
553
+ const rows = []
554
+ while (index < lines.length && /^\s*\|/.test(lines[index])) {
555
+ rows.push(splitRow(lines[index]))
556
+ index += 1
557
+ }
558
+ nodes.push(h('table', { key: nextKey() },
559
+ h('thead', null, h('tr', null, header.map((cell, cellIndex) => (
560
+ h('th', { key: `th-${cellIndex}` }, inlineNodes(cell, nextKey()))
561
+ )))),
562
+ h('tbody', null, rows.map((row, rowIndex) => (
563
+ h('tr', { key: `tr-${rowIndex}` }, row.map((cell, cellIndex) => (
564
+ h('td', { key: `td-${cellIndex}` }, inlineNodes(cell, nextKey()))
565
+ )))
566
+ ))),
567
+ ))
568
+ continue
569
+ }
570
+ const paragraph = []
571
+ while (
572
+ index < lines.length
573
+ && !/^\s*$/.test(lines[index])
574
+ && !/^\s*```/.test(lines[index])
575
+ && !/^(#{1,6})\s+/.test(lines[index])
576
+ && !/^\s*[-*+]\s+/.test(lines[index])
577
+ && !/^\s*\d+\.\s+/.test(lines[index])
578
+ && !/^>\s?/.test(lines[index])
579
+ && !/^\s*(---+|\*\*\*+|___+)\s*$/.test(lines[index])
580
+ && !/^\s*\|/.test(lines[index])
581
+ ) {
582
+ paragraph.push(lines[index])
583
+ index += 1
584
+ }
585
+ if (paragraph.length > 0) {
586
+ nodes.push(h('p', { key: nextKey() }, inlineNodes(paragraph.join(' '), nextKey())))
587
+ } else {
588
+ index += 1
589
+ }
590
+ }
591
+ return nodes
592
+ }
593
+
594
+ function DocumentsPage(props) {
595
+ const t = typeof props.t === 'function' ? props.t : translateWith(EN)
596
+ const jumpToSession = props.jumpToSession
597
+
598
+ const [documents, setDocuments] = React.useState([])
599
+ const [sessionCount, setSessionCount] = React.useState(0)
600
+ const [loading, setLoading] = React.useState(true)
601
+ const [error, setError] = React.useState(null)
602
+ const [truncated, setTruncated] = React.useState(false)
603
+ const [query, setQuery] = React.useState('')
604
+ const [kind, setKind] = React.useState('all')
605
+ const [workspace, setWorkspace] = React.useState('all')
606
+ const [sort, setSort] = React.useState('recent')
607
+ const [viewerPath, setViewerPath] = React.useState(null)
608
+ const [listOpen, setListOpen] = React.useState(false)
609
+ const [detailOpen, setDetailOpen] = React.useState(false)
610
+ const [zoom, setZoom] = React.useState(100)
611
+ const [sourceMode, setSourceMode] = React.useState(false)
612
+ const [preview, setPreview] = React.useState(null)
613
+ const [previewEpoch, setPreviewEpoch] = React.useState(0)
614
+ const [refreshing, setRefreshing] = React.useState(false)
615
+ const [busy, setBusy] = React.useState(false)
616
+ const [toast, setToast] = React.useState(null)
617
+ const [dialog, setDialog] = React.useState(null)
618
+ const [draftName, setDraftName] = React.useState('')
619
+
620
+ const alive = React.useRef(true)
621
+ const loadId = React.useRef(0)
622
+ const toastTimer = React.useRef(null)
623
+ const lastLoaded = React.useRef(0)
624
+ const inFlight = React.useRef(false)
625
+ const previewCache = React.useRef(new Map())
626
+ const reloadTimer = React.useRef(null)
627
+
628
+ React.useEffect(() => {
629
+ alive.current = true
630
+ return () => {
631
+ alive.current = false
632
+ if (toastTimer.current !== null) window.clearTimeout(toastTimer.current)
633
+ if (reloadTimer.current !== null) window.clearTimeout(reloadTimer.current)
634
+ }
635
+ }, [])
636
+
637
+ const showToast = React.useCallback((text, isError) => {
638
+ setToast({ text, isError: isError === true })
639
+ if (toastTimer.current !== null) window.clearTimeout(toastTimer.current)
640
+ toastTimer.current = window.setTimeout(() => {
641
+ if (alive.current) setToast(null)
642
+ }, 4200)
643
+ }, [])
644
+
645
+ const load = React.useCallback(async (options) => {
646
+ const force = options === true || (options !== undefined && options.force === true)
647
+ const silent = options !== undefined && options.silent === true
648
+ if (inFlight.current) {
649
+ if (!silent) setRefreshing(false)
650
+ return
651
+ }
652
+ const now = Date.now()
653
+ if (!force && lastLoaded.current !== 0 && now - lastLoaded.current < REFRESH_MS) return
654
+ const ticket = ++loadId.current
655
+ inFlight.current = true
656
+ if (!silent) setLoading(true)
657
+ setError(null)
658
+ try {
659
+ const data = await requestJson('/list')
660
+ if (!alive.current || ticket !== loadId.current) return
661
+ const next = Array.isArray(data.documents) ? data.documents : []
662
+ setDocuments(next)
663
+ setSessionCount(typeof data.sessionCount === 'number' ? data.sessionCount : 0)
664
+ setTruncated(data.truncated === true)
665
+ lastLoaded.current = Date.now()
666
+ setLoading(false)
667
+ setViewerPath((current) => (current !== null && next.some((doc) => doc.path === current) ? current : null))
668
+ } catch (loadError) {
669
+ if (!alive.current || ticket !== loadId.current) return
670
+ setError(String((loadError && loadError.message) || loadError))
671
+ setLoading(false)
672
+ } finally {
673
+ inFlight.current = false
674
+ if (alive.current) setRefreshing(false)
675
+ }
676
+ }, [])
677
+
678
+ const refreshNow = React.useCallback(() => {
679
+ previewCache.current.clear()
680
+ setPreviewEpoch((value) => value + 1)
681
+ setRefreshing(true)
682
+ load({ force: true })
683
+ }, [load])
684
+
685
+ const scheduleReconcile = React.useCallback(() => {
686
+ if (reloadTimer.current !== null) window.clearTimeout(reloadTimer.current)
687
+ reloadTimer.current = window.setTimeout(() => {
688
+ reloadTimer.current = null
689
+ load({ force: true, silent: true })
690
+ }, 1800)
691
+ }, [load])
692
+
693
+ React.useEffect(() => {
694
+ load({ force: true })
695
+ }, [load])
696
+
697
+ React.useEffect(() => {
698
+ const onFocus = () => {
699
+ if (dialog === null && Date.now() - lastLoaded.current > REFRESH_MS) load({ silent: true })
700
+ }
701
+ window.addEventListener('focus', onFocus)
702
+ return () => window.removeEventListener('focus', onFocus)
703
+ }, [load, dialog])
704
+
705
+ React.useEffect(() => {
706
+ const timer = window.setInterval(() => {
707
+ if (document.visibilityState === 'visible') load({ force: true, silent: true })
708
+ }, REFRESH_MS)
709
+ return () => window.clearInterval(timer)
710
+ }, [load])
711
+
712
+ const selected = React.useMemo(
713
+ () => documents.find((doc) => doc.path === viewerPath) || null,
714
+ [documents, viewerPath],
715
+ )
716
+
717
+ React.useEffect(() => {
718
+ if (selected === null) {
719
+ setPreview(null)
720
+ return undefined
721
+ }
722
+ const cached = previewCache.current.get(selected.path)
723
+ if (cached !== undefined) {
724
+ setPreview(cached)
725
+ return undefined
726
+ }
727
+ let cancelled = false
728
+ setPreview({ loading: true })
729
+ requestJson('/preview?path=' + encodeURIComponent(selected.path))
730
+ .then((data) => {
731
+ if (cancelled) return
732
+ previewCache.current.set(selected.path, data)
733
+ setPreview(data)
734
+ })
735
+ .catch((previewError) => {
736
+ if (!cancelled) setPreview({ ok: false, error: String((previewError && previewError.message) || previewError) })
737
+ })
738
+ return () => {
739
+ cancelled = true
740
+ }
741
+ }, [selected, previewEpoch])
742
+
743
+ const workspaces = React.useMemo(() => {
744
+ const names = new Set()
745
+ for (const doc of documents) if (doc.rootTitle) names.add(doc.rootTitle)
746
+ return [...names]
747
+ }, [documents])
748
+
749
+ const counts = React.useMemo(() => {
750
+ const base = workspace === 'all' ? documents : documents.filter((doc) => doc.rootTitle === workspace)
751
+ const result = { all: base.length }
752
+ for (const doc of base) result[doc.kind] = (result[doc.kind] || 0) + 1
753
+ return result
754
+ }, [documents, workspace])
755
+
756
+ const visible = React.useMemo(() => {
757
+ const needle = query.trim().toLowerCase()
758
+ let list = documents
759
+ if (workspace !== 'all') list = list.filter((doc) => doc.rootTitle === workspace)
760
+ if (kind !== 'all') list = list.filter((doc) => doc.kind === kind)
761
+ if (needle !== '') {
762
+ list = list.filter((doc) => {
763
+ const sessions = (doc.sessions || []).map((session) => session.title).join(' ')
764
+ return doc.name.toLowerCase().includes(needle)
765
+ || String(doc.rel || '').toLowerCase().includes(needle)
766
+ || sessions.toLowerCase().includes(needle)
767
+ })
768
+ }
769
+ const copy = list.slice()
770
+ if (sort === 'name') copy.sort((a, b) => a.name.localeCompare(b.name))
771
+ else if (sort === 'size') copy.sort((a, b) => b.bytes - a.bytes)
772
+ else copy.sort((a, b) => b.lastTime - a.lastTime)
773
+ return copy
774
+ }, [documents, query, kind, workspace, sort])
775
+
776
+ const runAction = React.useCallback(async (action, doc, extra) => {
777
+ setBusy(true)
778
+ try {
779
+ const data = await requestJson('/action', {
780
+ method: 'POST',
781
+ headers: { 'content-type': 'application/json' },
782
+ body: JSON.stringify({ action, path: doc.path, ...(extra || {}) }),
783
+ })
784
+ if (action === 'trash') {
785
+ setDocuments((list) => list.filter((entry) => entry.path !== doc.path))
786
+ previewCache.current.delete(doc.path)
787
+ setViewerPath(null)
788
+ showToast(t('toast.trash'))
789
+ scheduleReconcile()
790
+ } else if (action === 'rename') {
791
+ const nextPath = typeof data.path === 'string' ? data.path : doc.path
792
+ previewCache.current.delete(doc.path)
793
+ setDocuments((list) => list.map((entry) => (
794
+ entry.path === doc.path ? { ...entry, path: nextPath, name: data.name || entry.name } : entry
795
+ )))
796
+ setViewerPath(nextPath)
797
+ showToast(t('toast.rename'))
798
+ scheduleReconcile()
799
+ } else {
800
+ showToast(action === 'reveal' ? t('toast.reveal') : t('toast.open'))
801
+ }
802
+ setDialog(null)
803
+ } catch (actionError) {
804
+ showToast(String((actionError && actionError.message) || actionError), true)
805
+ } finally {
806
+ if (alive.current) setBusy(false)
807
+ }
808
+ }, [scheduleReconcile, showToast, t])
809
+
810
+ const copyPath = React.useCallback(async (doc) => {
811
+ try {
812
+ await navigator.clipboard.writeText(doc.path)
813
+ showToast(t('toast.copied'))
814
+ } catch {
815
+ showToast(t('toast.copyFailed'), true)
816
+ }
817
+ }, [showToast, t])
818
+
819
+ const openViewer = React.useCallback((doc) => {
820
+ setViewerPath(doc.path)
821
+ setZoom(100)
822
+ setSourceMode(false)
823
+ setDetailOpen(false)
824
+ setListOpen(false)
825
+ }, [])
826
+
827
+ const jump = React.useCallback((sessionId, event) => {
828
+ if (typeof jumpToSession !== 'function') {
829
+ showToast(t('toast.jumpFailed'), true)
830
+ return
831
+ }
832
+ try {
833
+ jumpToSession(sessionId, event && event.seq)
834
+ showToast(t('toast.jump'))
835
+ } catch {
836
+ showToast(t('toast.jumpFailed'), true)
837
+ }
838
+ }, [jumpToSession, showToast, t])
839
+
840
+ const openRename = React.useCallback((doc) => {
841
+ setDraftName(doc.name)
842
+ setDialog({ type: 'rename', doc })
843
+ }, [])
844
+
845
+ const openTrash = React.useCallback((doc) => {
846
+ setDialog({ type: 'trash', doc })
847
+ }, [])
848
+
849
+ React.useEffect(() => {
850
+ if (dialog === null) return undefined
851
+ const onKey = (event) => {
852
+ if (event.key === 'Escape') setDialog(null)
853
+ }
854
+ window.addEventListener('keydown', onKey)
855
+ return () => window.removeEventListener('keydown', onKey)
856
+ }, [dialog])
857
+
858
+ const kindChips = KIND_ORDER.filter((entry) => (counts[entry] || 0) > 0)
859
+
860
+ const toastNode = toast !== null && h('div', {
861
+ className: 'dshdoc-toast',
862
+ 'data-error': String(toast.isError),
863
+ role: 'status',
864
+ }, toast.text)
865
+
866
+ const dialogNode = dialog !== null && h('div', {
867
+ className: 'dshdoc-overlay',
868
+ onClick: (event) => { if (event.target === event.currentTarget) setDialog(null) },
869
+ },
870
+ h('div', {
871
+ className: 'dshdoc-dialog',
872
+ role: 'dialog',
873
+ 'aria-modal': true,
874
+ 'aria-label': dialog.type === 'rename' ? t('rename.title') : t('trash.title'),
875
+ },
876
+ h('div', { className: 'dshdoc-dialog-title' }, dialog.type === 'rename' ? t('rename.title') : t('trash.title')),
877
+ dialog.type === 'rename'
878
+ ? h('div', null,
879
+ h('div', { className: 'dshdoc-dialog-body' }, t('rename.label')),
880
+ h('input', {
881
+ className: 'dshdoc-input',
882
+ value: draftName,
883
+ autoFocus: true,
884
+ onChange: (event) => setDraftName(event.target.value),
885
+ onKeyDown: (event) => {
886
+ if (event.key === 'Enter' && draftName.trim() !== '') {
887
+ runAction('rename', dialog.doc, { name: draftName.trim() })
888
+ }
889
+ },
890
+ }),
891
+ )
892
+ : h('div', { className: 'dshdoc-dialog-body' }, t('trash.body')),
893
+ h('div', { className: 'dshdoc-dialog-actions' },
894
+ h('button', {
895
+ type: 'button',
896
+ className: 'dshdoc-btn',
897
+ disabled: busy,
898
+ onClick: () => setDialog(null),
899
+ }, t('action.cancel')),
900
+ h('button', {
901
+ type: 'button',
902
+ className: dialog.type === 'rename' ? 'dshdoc-btn dshdoc-btn-brand' : 'dshdoc-btn dshdoc-btn-danger',
903
+ disabled: busy || (dialog.type === 'rename' && draftName.trim() === ''),
904
+ onClick: () => {
905
+ if (dialog.type === 'rename') runAction('rename', dialog.doc, { name: draftName.trim() })
906
+ else runAction('trash', dialog.doc)
907
+ },
908
+ }, dialog.type === 'rename' ? t('action.save') : t('action.trash')),
909
+ ),
910
+ ),
911
+ )
912
+
913
+ let viewer = null
914
+ if (selected !== null) {
915
+ const scale = zoom / 100
916
+ const rawUrl = API + '/raw?path=' + encodeURIComponent(selected.path)
917
+ let content
918
+ if (preview === null || preview.loading === true) {
919
+ content = h('div', { className: 'dshdoc-unsupported' }, t('loading'))
920
+ } else if (preview.ok === false) {
921
+ content = h('div', { className: 'dshdoc-unsupported dshdoc-error' }, preview.error)
922
+ } else if (selected.kind === 'markdown' && preview.supported === true) {
923
+ content = sourceMode
924
+ ? h('pre', { className: 'dshdoc-doc-pre', style: { fontSize: `${13 * scale}px` } }, preview.text || '')
925
+ : h('div', { className: 'dshdoc-md', style: { fontSize: `${15 * scale}px` } }, renderMarkdown(preview.text || ''))
926
+ } else if (preview.supported === true) {
927
+ content = h('pre', { className: 'dshdoc-doc-pre', style: { fontSize: `${13 * scale}px` } }, preview.text || '')
928
+ } else if (selected.kind === 'pdf') {
929
+ content = h('iframe', { className: 'dshdoc-pdf', src: rawUrl, title: selected.name })
930
+ } else if (['png', 'jpg', 'jpeg', 'webp', 'gif'].includes(selected.ext)) {
931
+ content = h('img', {
932
+ className: 'dshdoc-media',
933
+ src: rawUrl,
934
+ alt: selected.name,
935
+ style: { width: `${Math.min(200, zoom)}%` },
936
+ })
937
+ } else {
938
+ content = h('div', { className: 'dshdoc-unsupported' },
939
+ h('div', null, t('viewer.unsupported')),
940
+ h('button', {
941
+ type: 'button',
942
+ className: 'dshdoc-btn dshdoc-btn-brand',
943
+ style: { marginTop: '14px' },
944
+ disabled: busy,
945
+ onClick: () => runAction('open', selected),
946
+ }, t('action.openExternal')),
947
+ )
948
+ }
949
+
950
+ viewer = h('div', { className: 'dshdoc-main' },
951
+ h('header', { className: 'dshdoc-view-head' },
952
+ h('button', {
953
+ type: 'button',
954
+ className: 'dshdoc-iconbtn dshdoc-list-toggle',
955
+ title: t('viewer.list'),
956
+ 'aria-label': t('viewer.list'),
957
+ onClick: () => setListOpen((value) => !value),
958
+ }, h(ListGlyph, null)),
959
+ h('span', { className: 'dshdoc-tile', style: tileStyle(selected) }, tileLabel(selected)),
960
+ h('div', { className: 'dshdoc-view-titlebox' },
961
+ h('div', { style: { minWidth: 0 } },
962
+ h('div', { className: 'dshdoc-view-name' }, selected.name),
963
+ h('div', { className: 'dshdoc-view-sub' },
964
+ `${t('kind.' + selected.kind)} · ${formatBytes(selected.bytes)} · ${selected.origin ? selected.origin.title : ''}`),
965
+ ),
966
+ ),
967
+ h('button', {
968
+ type: 'button',
969
+ className: 'dshdoc-iconbtn',
970
+ title: t('viewer.close'),
971
+ 'aria-label': t('viewer.close'),
972
+ onClick: () => setViewerPath(null),
973
+ }, h(CloseGlyph, null)),
974
+ ),
975
+ h('div', { className: 'dshdoc-view-tools' },
976
+ selected.kind === 'markdown' && h('button', {
977
+ type: 'button',
978
+ className: 'dshdoc-btn',
979
+ onClick: () => setSourceMode((value) => !value),
980
+ }, sourceMode ? t('viewer.reading') : t('viewer.source')),
981
+ h('div', { className: 'dshdoc-zoom' },
982
+ h('button', {
983
+ type: 'button',
984
+ className: 'dshdoc-iconbtn',
985
+ title: t('viewer.zoomOut'),
986
+ 'aria-label': t('viewer.zoomOut'),
987
+ disabled: zoom <= 60,
988
+ onClick: () => setZoom((value) => Math.max(60, value - 10)),
989
+ }, '−'),
990
+ h('button', {
991
+ type: 'button',
992
+ className: 'dshdoc-zoom-value',
993
+ style: { border: 'none', background: 'transparent', color: 'inherit', font: 'inherit', cursor: 'pointer' },
994
+ title: t('viewer.zoomReset'),
995
+ onClick: () => setZoom(100),
996
+ }, `${zoom}%`),
997
+ h('button', {
998
+ type: 'button',
999
+ className: 'dshdoc-iconbtn',
1000
+ title: t('viewer.zoomIn'),
1001
+ 'aria-label': t('viewer.zoomIn'),
1002
+ disabled: zoom >= 200,
1003
+ onClick: () => setZoom((value) => Math.min(200, value + 10)),
1004
+ }, '+'),
1005
+ ),
1006
+ h('span', { className: 'dshdoc-view-spacer' }),
1007
+ h('button', {
1008
+ type: 'button',
1009
+ className: 'dshdoc-btn',
1010
+ onClick: () => setDetailOpen((value) => !value),
1011
+ }, t('viewer.detail')),
1012
+ h('button', {
1013
+ type: 'button',
1014
+ className: 'dshdoc-btn dshdoc-btn-brand',
1015
+ disabled: busy,
1016
+ onClick: () => runAction('open', selected),
1017
+ }, t('action.open')),
1018
+ ),
1019
+ h('div', { className: 'dshdoc-view-body' },
1020
+ h('div', { className: 'dshdoc-view-main' }, h('div', { className: 'dshdoc-doc' }, content)),
1021
+ detailOpen && h('aside', { className: 'dshdoc-detail' },
1022
+ h('div', { className: 'dshdoc-detail-head' },
1023
+ h('div', { className: 'dshdoc-section-title' }, t('detail.title')),
1024
+ h('button', {
1025
+ type: 'button',
1026
+ className: 'dshdoc-iconbtn',
1027
+ title: t('viewer.close'),
1028
+ onClick: () => setDetailOpen(false),
1029
+ }, h(CloseGlyph, null)),
1030
+ ),
1031
+ h('div', { className: 'dshdoc-card' },
1032
+ h('div', { className: 'dshdoc-fields' },
1033
+ h('span', { className: 'dshdoc-field-label' }, t('detail.workspace')),
1034
+ h('span', { className: 'dshdoc-field-value' }, selected.rootTitle || '—'),
1035
+ h('span', { className: 'dshdoc-field-label' }, t('detail.size')),
1036
+ h('span', { className: 'dshdoc-field-value' }, formatBytes(selected.bytes)),
1037
+ h('span', { className: 'dshdoc-field-label' }, t('detail.modified')),
1038
+ h('span', { className: 'dshdoc-field-value' }, formatTime(selected.mtime)),
1039
+ ),
1040
+ h('div', { className: 'dshdoc-pathbox' }, selected.path),
1041
+ ),
1042
+ h('div', { className: 'dshdoc-card' },
1043
+ h('div', { className: 'dshdoc-card-title' },
1044
+ h('span', null, t('detail.sessions')),
1045
+ h('span', { className: 'dshdoc-card-count' }, String((selected.sessions || []).length)),
1046
+ ),
1047
+ (selected.sessions || []).map((session) => h('div', { key: session.id, className: 'dshdoc-session', 'data-role': session.role },
1048
+ h('div', { className: 'dshdoc-session-head' },
1049
+ h('span', { className: 'dshdoc-role', 'data-role': session.role }, session.role === 'origin' ? t('detail.created') : t('detail.edited')),
1050
+ h('span', { className: 'dshdoc-session-title', title: session.title }, session.title),
1051
+ session.events.length > 0 && h('button', {
1052
+ type: 'button',
1053
+ className: 'dshdoc-jump',
1054
+ onClick: () => jump(session.id, session.events[0]),
1055
+ }, t('detail.jump')),
1056
+ ),
1057
+ h('div', { className: 'dshdoc-session-sub' },
1058
+ `${session.workspace || ''}${session.workspace ? ' · ' : ''}${session.events.length} ${t('detail.events')}`),
1059
+ session.events.map((event, eventIndex) => h('div', {
1060
+ key: `${session.id}-${event.seq}-${eventIndex}`,
1061
+ className: 'dshdoc-event',
1062
+ 'data-kind': event.kind,
1063
+ },
1064
+ h('div', { className: 'dshdoc-event-head' },
1065
+ h('span', { className: 'dshdoc-kind-chip', 'data-kind': event.kind }, t('event.' + event.kind)),
1066
+ h('span', { className: 'dshdoc-event-summary' }, event.summary),
1067
+ ),
1068
+ h('div', { className: 'dshdoc-event-meta' },
1069
+ h('span', { className: 'dshdoc-pill' }, `${t('detail.turn')} ${event.turn}`),
1070
+ h('span', { className: 'dshdoc-pill' }, `#${event.seq}`),
1071
+ h('span', { className: 'dshdoc-pill' }, formatTime(event.time)),
1072
+ h('button', {
1073
+ type: 'button',
1074
+ onClick: () => jump(session.id, event),
1075
+ }, t('detail.jump')),
1076
+ ),
1077
+ event.preview !== '' && h('pre', { className: 'dshdoc-event-preview' }, event.preview),
1078
+ )),
1079
+ )),
1080
+ (selected.sessions || []).length === 0 && h('div', { className: 'dshdoc-empty-body' }, t('detail.noSessions')),
1081
+ ),
1082
+ h('div', { className: 'dshdoc-card dshdoc-actions' },
1083
+ h('button', {
1084
+ type: 'button',
1085
+ className: 'dshdoc-btn dshdoc-btn-brand',
1086
+ disabled: busy,
1087
+ onClick: () => runAction('open', selected),
1088
+ }, t('action.openExternal')),
1089
+ h('button', {
1090
+ type: 'button',
1091
+ className: 'dshdoc-btn',
1092
+ disabled: busy,
1093
+ onClick: () => runAction('reveal', selected),
1094
+ }, t('action.reveal')),
1095
+ h('button', {
1096
+ type: 'button',
1097
+ className: 'dshdoc-btn',
1098
+ disabled: busy,
1099
+ onClick: () => copyPath(selected),
1100
+ }, t('action.copy')),
1101
+ h('button', {
1102
+ type: 'button',
1103
+ className: 'dshdoc-btn',
1104
+ disabled: busy,
1105
+ onClick: () => openRename(selected),
1106
+ }, t('action.rename')),
1107
+ h('div', { className: 'dshdoc-divider' }),
1108
+ h('button', {
1109
+ type: 'button',
1110
+ className: 'dshdoc-btn dshdoc-btn-danger',
1111
+ disabled: busy,
1112
+ onClick: () => openTrash(selected),
1113
+ }, t('action.trash')),
1114
+ ),
1115
+ ),
1116
+ ),
1117
+ )
1118
+ }
1119
+
1120
+ let listContent
1121
+ if (loading && documents.length === 0) {
1122
+ listContent = h('div', { className: 'dshdoc-skeleton' },
1123
+ [0, 1, 2, 3, 4].map((index) => h('div', { key: index, className: 'dshdoc-skeleton-row' },
1124
+ h('div', { className: 'dshdoc-skeleton-tile' }),
1125
+ h('div', { className: 'dshdoc-skeleton-lines' },
1126
+ h('div', { className: 'dshdoc-skeleton-line', style: { width: `${52 + (index * 9) % 34}%` } }),
1127
+ h('div', { className: 'dshdoc-skeleton-line', style: { width: `${28 + (index * 7) % 22}%`, opacity: 0.7 } }),
1128
+ ),
1129
+ )),
1130
+ )
1131
+ } else if (error !== null) {
1132
+ listContent = h('div', { className: 'dshdoc-empty' },
1133
+ h('div', { className: 'dshdoc-empty-art' }, h(DocGlyph, { size: 40 })),
1134
+ h('div', { className: 'dshdoc-empty-title dshdoc-error' }, t('error.title')),
1135
+ h('div', { className: 'dshdoc-empty-body' }, error),
1136
+ h('button', { type: 'button', className: 'dshdoc-btn', onClick: refreshNow }, t('retry')),
1137
+ )
1138
+ } else if (visible.length === 0) {
1139
+ listContent = h('div', { className: 'dshdoc-empty' },
1140
+ h('div', { className: 'dshdoc-empty-art' }, h(DocGlyph, { size: 40 })),
1141
+ h('div', { className: 'dshdoc-empty-title' }, documents.length === 0 ? t('empty.title') : t('empty.filtered')),
1142
+ documents.length === 0 && h('div', { className: 'dshdoc-empty-body' }, t('empty.body')),
1143
+ )
1144
+ } else {
1145
+ listContent = visible.map((doc) => h('div', {
1146
+ key: doc.path,
1147
+ className: 'dshdoc-row',
1148
+ role: 'button',
1149
+ tabIndex: 0,
1150
+ 'aria-label': doc.name,
1151
+ 'data-selected': String(doc.path === viewerPath),
1152
+ onClick: () => openViewer(doc),
1153
+ onKeyDown: (event) => {
1154
+ if (event.key === 'Enter' || event.key === ' ') {
1155
+ event.preventDefault()
1156
+ openViewer(doc)
1157
+ }
1158
+ },
1159
+ },
1160
+ h('span', { className: 'dshdoc-tile', style: tileStyle(doc) }, tileLabel(doc)),
1161
+ h('span', { className: 'dshdoc-row-main' },
1162
+ h('span', { className: 'dshdoc-name' }, doc.name),
1163
+ h('span', { className: 'dshdoc-meta' },
1164
+ h('span', null, h('span', { className: 'dshdoc-session-dot' }), doc.origin ? doc.origin.title : t('detail.noSessions')),
1165
+ h('span', null, formatTime(doc.lastTime)),
1166
+ ),
1167
+ ),
1168
+ h('span', { className: 'dshdoc-row-side' },
1169
+ doc.editedByOthers && h('span', { style: { color: 'var(--dsw-alias-state-warn-primary)' } }, t('detail.edited')),
1170
+ h('span', null, t('kind.' + doc.kind)),
1171
+ ),
1172
+ ))
1173
+ if (truncated) {
1174
+ listContent = h(React.Fragment, null, listContent,
1175
+ h('div', { className: 'dshdoc-empty-body', style: { padding: '14px 12px 0' } }, t('empty.filtered')),
1176
+ )
1177
+ }
1178
+ }
1179
+
1180
+ const sidePanel = h('div', { className: 'dshdoc-side', 'data-open': String(listOpen) },
1181
+ h('div', { className: 'dshdoc-side-head' },
1182
+ h('label', { className: 'dshdoc-search' },
1183
+ h(SearchGlyph, null),
1184
+ h('input', {
1185
+ type: 'search',
1186
+ value: query,
1187
+ placeholder: t('search'),
1188
+ 'aria-label': t('search'),
1189
+ onChange: (event) => setQuery(event.target.value),
1190
+ }),
1191
+ ),
1192
+ h('div', { className: 'dshdoc-chips' },
1193
+ h('button', {
1194
+ type: 'button',
1195
+ className: 'dshdoc-chip',
1196
+ 'data-active': String(kind === 'all'),
1197
+ onClick: () => setKind('all'),
1198
+ }, `${t('filter.all')} ${counts.all}`),
1199
+ kindChips.map((entry) => h('button', {
1200
+ key: entry,
1201
+ type: 'button',
1202
+ className: 'dshdoc-chip',
1203
+ 'data-active': String(kind === entry),
1204
+ onClick: () => setKind(entry),
1205
+ },
1206
+ h('span', { className: 'dshdoc-chip-dot', style: { background: KIND_DOT[entry] || '#5b6472' } }),
1207
+ `${t('kind.' + entry)} ${counts[entry]}`)),
1208
+ ),
1209
+ h('div', { className: 'dshdoc-side-filters' },
1210
+ workspaces.length > 1 && h('select', {
1211
+ className: 'dshdoc-select',
1212
+ value: workspace,
1213
+ 'aria-label': t('workspace.all'),
1214
+ onChange: (event) => setWorkspace(event.target.value),
1215
+ },
1216
+ h('option', { value: 'all' }, t('workspace.all')),
1217
+ workspaces.map((name) => h('option', { key: name, value: name }, name)),
1218
+ ),
1219
+ h('select', {
1220
+ className: 'dshdoc-select',
1221
+ value: sort,
1222
+ 'aria-label': t('sort.recent'),
1223
+ onChange: (event) => setSort(event.target.value),
1224
+ },
1225
+ h('option', { value: 'recent' }, t('sort.recent')),
1226
+ h('option', { value: 'name' }, t('sort.name')),
1227
+ h('option', { value: 'size' }, t('sort.size')),
1228
+ ),
1229
+ ),
1230
+ ),
1231
+ h('div', { className: 'dshdoc-side-list' }, listContent),
1232
+ )
1233
+
1234
+ const emptyMain = h('div', { className: 'dshdoc-main' },
1235
+ h('div', { className: 'dshdoc-main-empty' },
1236
+ h('div', { className: 'dshdoc-empty-art' }, h(DocGlyph, { size: 44 })),
1237
+ h('div', null, t('viewer.pick')),
1238
+ ),
1239
+ )
1240
+
1241
+ return h('div', { className: 'dshdoc-page' },
1242
+ h('style', null, CSS),
1243
+ h('header', { className: 'dshdoc-head' },
1244
+ h('div', { className: 'dshdoc-head-main' },
1245
+ h('div', { className: 'dshdoc-title' },
1246
+ h('span', { className: 'dshdoc-brandmark' }, h(DocGlyph, { size: 18 })),
1247
+ h('span', null, t('title')),
1248
+ h('span', { className: 'dshdoc-badge' }, `${documents.length} ${t('count')}`),
1249
+ h('span', { className: 'dshdoc-badge' }, `${sessionCount} ${t('sessionCount')}`),
1250
+ ),
1251
+ h('div', { className: 'dshdoc-sub' }, t('subtitle')),
1252
+ ),
1253
+ h('div', { className: 'dshdoc-head-actions' },
1254
+ h('button', {
1255
+ type: 'button',
1256
+ className: 'dshdoc-btn dshdoc-list-toggle',
1257
+ onClick: () => setListOpen((value) => !value),
1258
+ }, t('viewer.list')),
1259
+ h('span', { className: 'dshdoc-refresh-hint' }, t('refresh.auto')),
1260
+ h('button', {
1261
+ type: 'button',
1262
+ className: 'dshdoc-btn',
1263
+ onClick: refreshNow,
1264
+ disabled: loading || refreshing,
1265
+ title: t('refresh'),
1266
+ }, t('refresh')),
1267
+ ),
1268
+ ),
1269
+ h('div', { className: 'dshdoc-body' },
1270
+ listOpen && h('div', { className: 'dshdoc-scrim', onClick: () => setListOpen(false) }),
1271
+ sidePanel,
1272
+ viewer !== null ? viewer : emptyMain,
1273
+ ),
1274
+ toastNode,
1275
+ dialogNode,
1276
+ )
1277
+ }
1278
+
1279
+ function apply(ctx) {
1280
+ let t = (key) => key
1281
+ try {
1282
+ t = ctx.locale.bind(NS)
1283
+ } catch {
1284
+ t = translateWith(EN)
1285
+ }
1286
+ const labelOf = (key) => {
1287
+ try {
1288
+ const value = t(key)
1289
+ if (typeof value === 'string' && value !== key && value !== '') return value
1290
+ } catch {
1291
+ // Fall through to English.
1292
+ }
1293
+ return EN[key] ?? key
1294
+ }
1295
+
1296
+ const jumpToSession = (sessionId, seq) => {
1297
+ const uiWorkspace = ctx.get('uiWorkspace')
1298
+ const sessions = ctx.get('sessions')
1299
+ let opened = false
1300
+ if (uiWorkspace && typeof uiWorkspace.openSession === 'function') {
1301
+ uiWorkspace.openSession(sessionId)
1302
+ opened = true
1303
+ }
1304
+ const focus = () => {
1305
+ try {
1306
+ const binding = sessions && typeof sessions.binding === 'function' ? sessions.binding(sessionId) : undefined
1307
+ if (binding && binding.session && typeof binding.session.loadThrough === 'function') {
1308
+ binding.session.loadThrough(seq).catch(() => {})
1309
+ }
1310
+ } catch {
1311
+ // Position focus is best-effort.
1312
+ }
1313
+ }
1314
+ focus()
1315
+ window.setTimeout(focus, 700)
1316
+ if (!opened) throw new Error('会话导航不可用')
1317
+ }
1318
+
1319
+ ctx.slots.inject('sidebar.panellist', () => {
1320
+ const disposeEntry = ctx.slots.register({
1321
+ name: 'sidebar.panellist',
1322
+ id: 'documents',
1323
+ order: 20,
1324
+ label: () => labelOf('panel.label'),
1325
+ }, PanelIcon)
1326
+ let disposeLocale = () => {}
1327
+ try {
1328
+ disposeLocale = ctx.locale.register(NS, { en: EN, zh: ZH })
1329
+ } catch {
1330
+ disposeLocale = () => {}
1331
+ }
1332
+ return () => {
1333
+ try {
1334
+ disposeLocale()
1335
+ } catch {
1336
+ // Already released.
1337
+ }
1338
+ disposeEntry()
1339
+ }
1340
+ })
1341
+
1342
+ ctx.slots.inject('main', () => ctx.slots.register({
1343
+ name: 'main',
1344
+ key: 'documents',
1345
+ locale: NS,
1346
+ label: labelOf('title'),
1347
+ inject: () => ({ jumpToSession }),
1348
+ }, DocumentsPage))
1349
+ }
1350
+
1351
+ return { inject: ['slots', 'locale'], apply }
1352
+ },
1353
+ })