@dsh-sparrow/dsh-file-manage 0.1.0-alpha.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/lib/client.js ADDED
@@ -0,0 +1,705 @@
1
+ window.__ModuleLoader__.load({ id: "@dsh-sparrow/dsh-file-manage", factory: (require) => {
2
+ var module = { exports: {} };
3
+ "use strict";
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/client/index.ts
23
+ var index_exports = {};
24
+ __export(index_exports, {
25
+ FileManageDock: () => FileManageDock,
26
+ apply: () => apply,
27
+ countApi: () => countApi,
28
+ deleteApi: () => deleteApi,
29
+ ensureFileManageStyles: () => ensureFileManageStyles,
30
+ inject: () => inject,
31
+ listApi: () => listApi
32
+ });
33
+ module.exports = __toCommonJS(index_exports);
34
+
35
+ // src/client/api.ts
36
+ var REQUEST_TIMEOUT_MS = 15e3;
37
+ var COUNT_TIMEOUT_MS = 6e4;
38
+ async function listApi(after) {
39
+ const params = new URLSearchParams();
40
+ if (after !== void 0) params.set("after", after);
41
+ const response = await fetch(`/api/file-manage/list?${params.toString()}`, {
42
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
43
+ });
44
+ const payload = await response.json();
45
+ if (!response.ok) {
46
+ throw new Error(payload.error?.message ?? `\u8BF7\u6C42\u5931\u8D25\uFF08HTTP ${response.status}\uFF09`);
47
+ }
48
+ return {
49
+ rows: payload.items ?? [],
50
+ hasMore: payload.hasMore ?? false,
51
+ ...payload.lastId === void 0 ? {} : { lastId: payload.lastId }
52
+ };
53
+ }
54
+ async function countApi() {
55
+ const response = await fetch("/api/file-manage/count", { signal: AbortSignal.timeout(COUNT_TIMEOUT_MS) });
56
+ const payload = await response.json();
57
+ if (!response.ok) {
58
+ throw new Error(payload.error?.message ?? `\u8BF7\u6C42\u5931\u8D25\uFF08HTTP ${response.status}\uFF09`);
59
+ }
60
+ return {
61
+ count: payload.count ?? 0,
62
+ totalBytes: payload.totalBytes ?? 0,
63
+ totalBytesLabel: payload.totalBytesLabel ?? "0 B",
64
+ quotaBytes: payload.quotaBytes ?? 0,
65
+ quotaBytesLabel: payload.quotaBytesLabel ?? "0 B",
66
+ quotaCount: payload.quotaCount ?? 0
67
+ };
68
+ }
69
+ async function deleteApi(id) {
70
+ const params = new URLSearchParams({ id });
71
+ const response = await fetch(`/api/file-manage/files?${params.toString()}`, {
72
+ method: "DELETE",
73
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
74
+ });
75
+ const payload = await response.json();
76
+ if (!response.ok) {
77
+ throw new Error(payload.error?.message ?? `\u8BF7\u6C42\u5931\u8D25\uFF08HTTP ${response.status}\uFF09`);
78
+ }
79
+ }
80
+
81
+ // src/client/FileManageDock.tsx
82
+ var import_react = require("react");
83
+ var import_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
84
+
85
+ // src/client/quota.ts
86
+ function storageUsageRatio(usedBytes, quotaBytes) {
87
+ if (!Number.isFinite(usedBytes) || usedBytes <= 0) return 0;
88
+ if (!Number.isFinite(quotaBytes) || quotaBytes <= 0) return 0;
89
+ return Math.min(1, Math.max(0, usedBytes / quotaBytes));
90
+ }
91
+ function formatUsagePercent(ratio) {
92
+ const percent = Math.min(1, Math.max(0, ratio)) * 100;
93
+ if (percent >= 10) return `${Math.round(percent)}%`;
94
+ if (percent >= 1) return `${percent.toFixed(1)}%`;
95
+ if (percent >= 0.1) return `${percent.toFixed(2)}%`;
96
+ if (percent >= 0.01) return `${percent.toFixed(3)}%`;
97
+ return `${percent.toFixed(4)}%`;
98
+ }
99
+
100
+ // src/client/styles.ts
101
+ function ensureFileManageStyles() {
102
+ if (document.querySelector("style[data-dsh-file-manage]") !== null) return;
103
+ const style = document.createElement("style");
104
+ style.dataset.dshFileManage = "";
105
+ style.textContent = `/* \u5B98\u65B9 .footerActions \u662F\u6A2A\u5411 flex \u884C\uFF0Cslot \u5305\u88F9\u5C42\u4E3A\u884C\u5185 display:contents\uFF1A
106
+ * \u591A\u63D2\u4EF6\u5404\u81EA\u7684\u5168\u5BBD\u6309\u94AE\u4F1A\u5E76\u6392\u6324\u5230\u53F3\u7F18\u5916\uFF08\u53EA\u5269\u4E00\u6761\u8FB9\uFF09\u3002\u8FD9\u91CC\u628A\u5305\u88F9\u5C42\u6539\u56DE\u771F\u5B9E\u76D2\u5B50\u7EB5\u6392\uFF0C
107
+ * Archive / \u4E91\u7AEF\u6587\u4EF6\u4E24\u4E2A\u6309\u94AE\u4E0A\u4E0B\u5806\u53E0\u3001\u5404\u81EA\u5360\u6EE1\u4E00\u884C\uFF08!important \u538B\u8FC7\u884C\u5185 contents\uFF09\u3002 */
108
+ [data-slot='sidebar.footer.action'] {
109
+ display: flex !important;
110
+ flex-direction: column;
111
+ /* \u5305\u88F9\u5C42\u662F .footerActions \u884C\u5BB9\u5668\u91CC\u7684 flex item\uFF0C\u9700\u663E\u5F0F\u6491\u6EE1\uFF0C\u5426\u5219\u4E24\u4E2A\u5168\u5BBD\u6309\u94AE\u6309\u5185\u5BB9\u5BBD\u5EA6\u6536\u7F29\u3002 */
112
+ width: 100%;
113
+ }
114
+ .dsh-file-manage-trigger {
115
+ flex: none;
116
+ display: flex;
117
+ align-items: center;
118
+ gap: 8px;
119
+ width: calc(100% + 4px);
120
+ height: 42px;
121
+ margin: 4px -2px;
122
+ padding: 0 10px 0 8px;
123
+ box-sizing: border-box;
124
+ border: none;
125
+ border-radius: 12px;
126
+ background: transparent;
127
+ cursor: pointer;
128
+ overflow: hidden;
129
+ color: var(--dsw-alias-label-primary);
130
+ font-family: inherit;
131
+ font-size: 14px;
132
+ line-height: 22px;
133
+ }
134
+ .dsh-file-manage-trigger:hover {
135
+ background: var(--dsw-alias-interactive-bg-hover);
136
+ }
137
+ .dsh-file-manage-trigger-rail {
138
+ width: 36px;
139
+ height: 36px;
140
+ margin: 8px 0 10px;
141
+ justify-content: center;
142
+ gap: 0;
143
+ padding: 0;
144
+ border-radius: 50%;
145
+ }
146
+ .dsh-file-manage-trigger-icon {
147
+ flex: none;
148
+ }
149
+ .dsh-file-manage-trigger-label {
150
+ overflow: hidden;
151
+ text-overflow: ellipsis;
152
+ white-space: nowrap;
153
+ }
154
+ /* \u9762\u677F\u6EDA\u52A8\u533A\uFF1A\u5B98\u65B9 settings \u540C\u6B3E\u2014\u2014elevated surface \u91CD\u7ED1 l2 \u6EDA\u52A8\u6761 token\uFF08base \u9ED8\u8BA4 l1\uFF0C\u6D6E\u5C42\u4E0A\u5BF9\u6BD4\u5EA6\u4E0D\u5BF9\uFF09\u3002 */
155
+ .dsh-file-manage-body {
156
+ --dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l2);
157
+ --dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l2);
158
+ }
159
+ /* \u9762\u677F\u5934\uFF1A\u5B98\u65B9 settings \u9762\u677F\u540C\u6B3E\uFF0854px \u9AD8\u3001\u6807\u9898\u8D77\u70B9 24px\uFF09\u3002 */
160
+ .dsh-file-manage-panel-header {
161
+ flex: none;
162
+ display: flex;
163
+ align-items: flex-start;
164
+ justify-content: space-between;
165
+ gap: 8px;
166
+ height: 54px;
167
+ padding: 20px 14px 8px 24px;
168
+ box-sizing: border-box;
169
+ }
170
+ .dsh-file-manage-panel-title {
171
+ font-size: 16px;
172
+ font-weight: 500;
173
+ line-height: 24px;
174
+ color: var(--dsw-alias-label-primary);
175
+ }
176
+ .dsh-file-manage-close {
177
+ display: inline-flex;
178
+ align-items: center;
179
+ justify-content: center;
180
+ width: 28px;
181
+ height: 28px;
182
+ padding: 0;
183
+ border: none;
184
+ border-radius: 28px;
185
+ outline: none;
186
+ background: transparent;
187
+ cursor: pointer;
188
+ color: var(--dsw-alias-label-primary);
189
+ }
190
+ .dsh-file-manage-close:hover {
191
+ background: var(--dsw-alias-interactive-bg-hover);
192
+ }
193
+ .dsh-file-manage-badge {
194
+ flex: none;
195
+ padding: 1px 6px;
196
+ border: 1px solid var(--dsw-alias-border-l2, #e2e5ea);
197
+ border-radius: 999px;
198
+ color: var(--dsw-alias-label-caption, #8a919f);
199
+ font-size: 11px;
200
+ line-height: 16px;
201
+ }
202
+ .dsh-file-manage-btn {
203
+ height: 28px;
204
+ padding: 0 12px;
205
+ border: 1px solid var(--dsw-alias-border-l1, #d4d8e0);
206
+ border-radius: 999px;
207
+ outline: none;
208
+ background: transparent;
209
+ color: var(--dsw-alias-label-primary, #1f2329);
210
+ font-size: 13px;
211
+ line-height: 20px;
212
+ white-space: nowrap;
213
+ cursor: pointer;
214
+ }
215
+ .dsh-file-manage-btn:hover:not(:disabled) {
216
+ background: var(--dsw-alias-interactive-bg-hover);
217
+ }
218
+ .dsh-file-manage-btn:disabled {
219
+ opacity: 0.5;
220
+ cursor: default;
221
+ }
222
+ .dsh-file-manage-btn-danger {
223
+ color: var(--dsw-alias-state-error-primary, #c62828);
224
+ }
225
+ /* \u5220\u9664\u786E\u8BA4\u6846\uFF1A\u5B98\u65B9 web \u786E\u8BA4\u6846\u540C\u6B3E\uFF08mask + \u6BDB\u73BB\u7483 + 480 \u5361\u7247\uFF09\u3002 */
226
+ .dsh-file-manage-confirm-overlay {
227
+ position: fixed;
228
+ inset: 0;
229
+ z-index: 1100;
230
+ display: flex;
231
+ align-items: center;
232
+ justify-content: center;
233
+ background: var(--dsw-alias-bg-mask-1, rgba(0, 0, 0, 0.28));
234
+ backdrop-filter: var(--dsw-mask-blur);
235
+ }
236
+ .dsh-file-manage-confirm-card {
237
+ display: flex;
238
+ flex-direction: column;
239
+ gap: 12px;
240
+ width: min(480px, calc(100vw - 48px));
241
+ padding: 20px;
242
+ border-radius: 16px;
243
+ background: var(--dsw-alias-bg-layer-2, #f6f7f9);
244
+ color: var(--dsw-alias-label-primary, #1f2329);
245
+ box-shadow: var(--dsw-shadow-lv3, 0 12px 40px rgba(0,0,0,0.22));
246
+ }
247
+ .dsh-file-manage-confirm-title {
248
+ margin: 0;
249
+ font-size: 16px;
250
+ font-weight: 500;
251
+ line-height: 24px;
252
+ }
253
+ .dsh-file-manage-confirm-desc {
254
+ margin: 0;
255
+ font-size: 14px;
256
+ line-height: 22px;
257
+ color: var(--dsw-alias-label-secondary, #6b7280);
258
+ white-space: pre-line;
259
+ }
260
+ .dsh-file-manage-confirm-actions {
261
+ display: flex;
262
+ justify-content: flex-end;
263
+ gap: 8px;
264
+ }
265
+ /* \u7528\u91CF/\u8FDB\u5EA6\u6761\u56FA\u5B9A\u533A\uFF1A\u9762\u677F\u5934\u4E0B\u65B9\u3001\u4E0D\u968F\u5217\u8868\u6EDA\u52A8\uFF1B\u5DE6\u4FA7 24px \u4E0E\u533A\u5757\u5361\u7EBF\u6846\u9F50\u5E73\uFF0C
266
+ \u53F3\u4FA7\u989D\u5916\u8BA9\u51FA\u6EDA\u52A8\u6761\u5BBD\u5EA6\uFF08\u5217\u8868\u533A scrollbar-gutter: stable \u56FA\u5B9A\u5360\u4F4D 8px\uFF09\u3002 */
267
+ .dsh-file-manage-summary {
268
+ flex: none;
269
+ padding: 12px calc(24px + var(--dsh-scrollbar-width, 8px)) 8px 24px;
270
+ }
271
+ .dsh-file-manage-count {
272
+ margin: 6px 0 0;
273
+ font-size: 12px;
274
+ line-height: 18px;
275
+ color: var(--dsw-alias-label-secondary, #6b7280);
276
+ }
277
+ /* \u5217\u8868\u533A\u5757\u5361\uFF1A\u5B58\u6863\u9875\u5F52\u6863\u533A/\u5907\u4EFD\u533A\u540C\u6B3E token\uFF08border-l2 + r12\uFF09\u3002 */
278
+ .dsh-file-manage-card {
279
+ box-sizing: border-box;
280
+ display: flex;
281
+ flex-direction: column;
282
+ margin: 0 0 12px;
283
+ padding: 8px 12px 12px;
284
+ border: 1px solid var(--dsw-alias-border-l2, #e2e5ea);
285
+ border-radius: 12px;
286
+ }
287
+ /* \u914D\u989D\u5BB9\u91CF\u6761\uFF1A\u52A0\u539A + \u672A\u4F7F\u7528\u533A\u659C\u7EB9\uFF08repeating-linear-gradient\uFF09\uFF0C\u4E0E\u5206\u5272\u7EBF\u533A\u5206\uFF1B\u586B\u5145\u76D6\u4F4F\u659C\u7EB9\u3002
288
+ \u5BB9\u91CF\u6587\u5B57\u7EDD\u5BF9\u5B9A\u4F4D\u5C45\u4E2D\u53E0\u52A0\u5728\u6761\u4E0A\u3002 */
289
+ .dsh-file-manage-quota-track {
290
+ position: relative;
291
+ height: 16px;
292
+ border-radius: 8px;
293
+ background-color: var(--dsw-alias-interactive-bg-hover);
294
+ background-image: repeating-linear-gradient(
295
+ 45deg,
296
+ transparent 0px,
297
+ transparent 5px,
298
+ var(--dsw-alias-border-l1, #d4d8e0) 5px,
299
+ var(--dsw-alias-border-l1, #d4d8e0) 7px
300
+ );
301
+ overflow: hidden;
302
+ }
303
+ .dsh-file-manage-quota-text {
304
+ position: absolute;
305
+ inset: 0;
306
+ z-index: 1;
307
+ display: flex;
308
+ align-items: center;
309
+ justify-content: center;
310
+ font-size: 11px;
311
+ line-height: 16px;
312
+ white-space: nowrap;
313
+ color: var(--dsw-alias-label-primary, #1f2329);
314
+ /* \u9AD8\u7528\u91CF\u65F6\u84DD\u586B\u5145\u57AB\u5E95\uFF0C\u52A0\u4E00\u5708\u5E95\u8272\u5149\u6655\u4FDD\u8BC1\u53EF\u8BFB\u3002 */
315
+ text-shadow: 0 0 4px var(--dsw-alias-bg-layer-2, #f6f7f9);
316
+ pointer-events: none;
317
+ }
318
+ .dsh-file-manage-quota-fill {
319
+ height: 100%;
320
+ /* \u7528\u91CF\u6781\u5C0F\u65F6\uFF080.01% \u91CF\u7EA7\uFF09\u5BBD\u5EA6\u8D8B\u8FD1 0\uFF0C\u515C\u5E95 4px \u94F6\u6761\u8BA9\u300C\u6709\u4F7F\u7528\u300D\u53EF\u89C1\uFF08\u7F51\u76D8\u540C\u6B3E\uFF09\u3002
321
+ \u4E0D\u52A0\u81EA\u8EAB\u5706\u89D2\uFF1A\u6700\u5C0F\u5BBD\u5EA6\u4E0B\u5706\u89D2\u4F1A\u957F\u6210\u5706\u70B9\u3001\u89C6\u89C9\u9F13\u51FA\u8F68\u9053\u5DE6\u7AEF\uFF0C\u6539\u7531\u8F68\u9053 overflow:hidden + \u5706\u89D2\u88C1\u5207\u4E24\u7AEF\u3002 */
322
+ min-width: 4px;
323
+ background: var(--dsw-alias-state-business-primary);
324
+ transition: width 220ms ease-out;
325
+ }
326
+ `;
327
+ document.head.appendChild(style);
328
+ }
329
+ var styles = {
330
+ overlay: {
331
+ position: "fixed",
332
+ inset: 0,
333
+ zIndex: 1e3,
334
+ display: "flex",
335
+ alignItems: "center",
336
+ justifyContent: "center",
337
+ background: "var(--dsw-alias-bg-mask-1, rgba(0, 0, 0, 0.28))",
338
+ backdropFilter: "var(--dsw-mask-blur)"
339
+ },
340
+ panel: {
341
+ position: "relative",
342
+ display: "flex",
343
+ flexDirection: "column",
344
+ width: "min(800px, calc(100vw - 48px))",
345
+ // 高度随内容自适应、上限钳到视口(官方 settings 同款上限)。
346
+ maxHeight: "min(800px, calc(100vh - 48px))",
347
+ borderRadius: 24,
348
+ overflow: "hidden",
349
+ padding: 0,
350
+ background: "var(--dsw-alias-bg-layer-2, #f6f7f9)",
351
+ color: "var(--dsw-alias-label-primary, #1f2329)",
352
+ boxShadow: "var(--dsw-shadow-lv3, 0 12px 40px rgba(0,0,0,0.22))"
353
+ },
354
+ body: {
355
+ flex: 1,
356
+ minHeight: 0,
357
+ overflow: "auto",
358
+ // 滚动条固定占位:卡片右缘不因滚动条出现/消失而左右漂移(与顶部进度条对齐)。
359
+ scrollbarGutter: "stable",
360
+ padding: "0 24px 24px"
361
+ },
362
+ row: {
363
+ display: "flex",
364
+ justifyContent: "space-between",
365
+ gap: 8,
366
+ alignItems: "center",
367
+ padding: "8px 0",
368
+ borderBottom: "1px solid var(--dsw-alias-border-l1, #e2e5ea)"
369
+ },
370
+ actions: {
371
+ display: "flex",
372
+ gap: 6,
373
+ alignItems: "center"
374
+ },
375
+ title: {
376
+ overflow: "hidden",
377
+ textOverflow: "ellipsis",
378
+ whiteSpace: "nowrap"
379
+ },
380
+ secondarySmall: {
381
+ color: "var(--dsw-alias-label-secondary, #6b7280)",
382
+ fontSize: 12,
383
+ lineHeight: "18px"
384
+ },
385
+ footerBar: {
386
+ flex: "none",
387
+ display: "flex",
388
+ justifyContent: "center",
389
+ // 列表已包区块卡,不再加顶部分隔线(避免与卡片叠加显乱)。
390
+ padding: "10px 24px 14px"
391
+ }
392
+ };
393
+
394
+ // src/client/FileManageDock.tsx
395
+ var import_jsx_runtime = require("react/jsx-runtime");
396
+ function FileManageDock({ wide, listFiles, deleteFile, countFiles, t }) {
397
+ const [open, setOpen] = (0, import_react.useState)(false);
398
+ const [rows, setRows] = (0, import_react.useState)([]);
399
+ const [hasMore, setHasMore] = (0, import_react.useState)(false);
400
+ const [lastId, setLastId] = (0, import_react.useState)(void 0);
401
+ const [loading, setLoading] = (0, import_react.useState)(false);
402
+ const [loadingMore, setLoadingMore] = (0, import_react.useState)(false);
403
+ const [error, setError] = (0, import_react.useState)(null);
404
+ const [confirming, setConfirming] = (0, import_react.useState)(null);
405
+ const [busyDelete, setBusyDelete] = (0, import_react.useState)(false);
406
+ const [copied, setCopied] = (0, import_react.useState)(null);
407
+ const [summary, setSummary] = (0, import_react.useState)(null);
408
+ const closeButtonRef = (0, import_react.useRef)(null);
409
+ const refreshSeqRef = (0, import_react.useRef)(0);
410
+ const copiedTimerRef = (0, import_react.useRef)(null);
411
+ const loadFirst = (0, import_react.useCallback)(() => {
412
+ const seq = ++refreshSeqRef.current;
413
+ setLoading(true);
414
+ setError(null);
415
+ listFiles().then((page) => {
416
+ if (seq !== refreshSeqRef.current) return;
417
+ setRows(page.rows);
418
+ setHasMore(page.hasMore);
419
+ setLastId(page.lastId);
420
+ }).catch((reason) => {
421
+ if (seq !== refreshSeqRef.current) return;
422
+ setError(reason instanceof Error ? reason.message : String(reason));
423
+ }).finally(() => {
424
+ if (seq === refreshSeqRef.current) setLoading(false);
425
+ });
426
+ }, [listFiles]);
427
+ (0, import_react.useEffect)(() => {
428
+ if (!open) return;
429
+ closeButtonRef.current?.focus();
430
+ const onKeyDown = (event) => {
431
+ if (event.key === "Escape") setOpen(false);
432
+ };
433
+ document.addEventListener("keydown", onKeyDown);
434
+ return () => {
435
+ document.removeEventListener("keydown", onKeyDown);
436
+ };
437
+ }, [open]);
438
+ (0, import_react.useEffect)(() => {
439
+ if (!open) return;
440
+ setConfirming(null);
441
+ setSummary(null);
442
+ loadFirst();
443
+ const seq = refreshSeqRef.current;
444
+ void countFiles().then((next) => {
445
+ if (seq === refreshSeqRef.current) setSummary(next);
446
+ }).catch(() => {
447
+ });
448
+ }, [open, loadFirst, countFiles]);
449
+ (0, import_react.useEffect)(() => () => {
450
+ if (copiedTimerRef.current !== null) window.clearTimeout(copiedTimerRef.current);
451
+ }, []);
452
+ const loadMore = (0, import_react.useCallback)(() => {
453
+ if (lastId === void 0 || loadingMore) return;
454
+ setLoadingMore(true);
455
+ listFiles(lastId).then((page) => {
456
+ setRows((current) => [...current, ...page.rows]);
457
+ setHasMore(page.hasMore);
458
+ setLastId(page.lastId);
459
+ }).catch((reason) => {
460
+ setError(reason instanceof Error ? reason.message : String(reason));
461
+ }).finally(() => {
462
+ setLoadingMore(false);
463
+ });
464
+ }, [lastId, loadingMore, listFiles]);
465
+ const copyId = (0, import_react.useCallback)(async (row) => {
466
+ try {
467
+ await navigator.clipboard.writeText(row.id);
468
+ setCopied(row.id);
469
+ if (copiedTimerRef.current !== null) window.clearTimeout(copiedTimerRef.current);
470
+ copiedTimerRef.current = window.setTimeout(() => {
471
+ setCopied(null);
472
+ }, 2e3);
473
+ } catch {
474
+ setCopied(null);
475
+ setError(t("copyFailed"));
476
+ }
477
+ }, [t]);
478
+ const quotaRatio = summary === null ? 0 : storageUsageRatio(summary.totalBytes, summary.quotaBytes);
479
+ const submitDelete = (0, import_react.useCallback)(() => {
480
+ if (confirming === null || busyDelete) return;
481
+ setBusyDelete(true);
482
+ deleteFile(confirming.id).then(() => {
483
+ setRows((current) => current.filter((row) => row.id !== confirming.id));
484
+ setConfirming(null);
485
+ void countFiles().then(setSummary).catch(() => {
486
+ });
487
+ }).catch((reason) => {
488
+ setError(reason instanceof Error ? reason.message : String(reason));
489
+ setConfirming(null);
490
+ }).finally(() => {
491
+ setBusyDelete(false);
492
+ });
493
+ }, [busyDelete, confirming, deleteFile, countFiles]);
494
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
495
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
496
+ "button",
497
+ {
498
+ type: "button",
499
+ className: wide ? "dsh-file-manage-trigger" : "dsh-file-manage-trigger dsh-file-manage-trigger-rail",
500
+ title: t("dialog.title"),
501
+ "aria-haspopup": "dialog",
502
+ "aria-expanded": open,
503
+ onClick: () => {
504
+ setOpen((value) => !value);
505
+ },
506
+ children: [
507
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.IconFolderOpenOutline16, { className: "dsh-file-manage-trigger-icon", size: wide ? 16 : 18 }),
508
+ wide ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dsh-file-manage-trigger-label", children: t("button.label") }) : null
509
+ ]
510
+ }
511
+ ),
512
+ open ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: styles.overlay, role: "presentation", onMouseDown: (event) => {
513
+ if (event.target === event.currentTarget) setOpen(false);
514
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: styles.panel, role: "dialog", "aria-modal": "true", "aria-label": t("dialog.title"), children: [
515
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-file-manage-panel-header", children: [
516
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: "dsh-file-manage-panel-title", style: { margin: 0 }, children: t("dialog.title") }),
517
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { ref: closeButtonRef, type: "button", className: "dsh-file-manage-close", "aria-label": t("dialog.close"), onClick: () => {
518
+ setOpen(false);
519
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.IconCloseOutline16, { size: 14 }) })
520
+ ] }),
521
+ summary !== null ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-file-manage-summary", children: [
522
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-file-manage-quota-track", children: [
523
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dsh-file-manage-quota-text", children: `${summary.totalBytesLabel} / ${summary.quotaBytesLabel} \xB7 ${t("quota.used", { percent: formatUsagePercent(quotaRatio) })}` }),
524
+ quotaRatio > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dsh-file-manage-quota-fill", style: { width: `${Math.round(quotaRatio * 100)}%` } }) : null
525
+ ] }),
526
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dsh-file-manage-count", children: rows.length < summary.count ? t("summary.loaded", { loaded: rows.length, count: summary.count }) : t("summary.count", { count: summary.count }) })
527
+ ] }) : null,
528
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { ...styles.body, padding: summary !== null ? "0 24px 24px" : "12px 24px 24px" }, className: "dsh-file-manage-body", children: [
529
+ error !== null ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { role: "alert", style: { ...styles.secondarySmall, margin: "0 0 12px", color: "var(--dsw-alias-state-error-primary, #c62828)" }, children: [
530
+ error,
531
+ " ",
532
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "dsh-file-manage-btn", onClick: loadFirst, children: t("retry") })
533
+ ] }) : null,
534
+ loading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { style: styles.secondarySmall, children: t("loading") }) : null,
535
+ !loading && error === null && rows.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { style: styles.secondarySmall, children: t("empty") }) : null,
536
+ rows.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dsh-file-manage-card", children: rows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: styles.row, children: [
537
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { minWidth: 0 }, children: [
538
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: 6, minWidth: 0 }, children: [
539
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: styles.title, title: row.filename, children: row.filename }),
540
+ row.dshOwned ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dsh-file-manage-badge", children: t("dshBadge") }) : null
541
+ ] }),
542
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: styles.secondarySmall, children: [
543
+ row.sizeLabel,
544
+ " \xB7 ",
545
+ row.createdAtLabel,
546
+ row.expiresAtLabel !== void 0 ? ` \xB7 ${t("expires", { time: row.expiresAtLabel })}` : ""
547
+ ] })
548
+ ] }),
549
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: styles.actions, children: [
550
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
551
+ "button",
552
+ {
553
+ type: "button",
554
+ className: "dsh-file-manage-btn",
555
+ onClick: () => {
556
+ void copyId(row);
557
+ },
558
+ children: copied === row.id ? t("copied") : t("copy")
559
+ }
560
+ ),
561
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
562
+ "button",
563
+ {
564
+ type: "button",
565
+ className: "dsh-file-manage-btn dsh-file-manage-btn-danger",
566
+ onClick: () => {
567
+ setConfirming(row);
568
+ },
569
+ children: t("delete")
570
+ }
571
+ )
572
+ ] })
573
+ ] }, row.id)) }) : null
574
+ ] }),
575
+ hasMore && !loading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: styles.footerBar, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
576
+ "button",
577
+ {
578
+ type: "button",
579
+ className: "dsh-file-manage-btn",
580
+ disabled: loadingMore,
581
+ onClick: () => {
582
+ void loadMore();
583
+ },
584
+ children: loadingMore ? t("loading") : t("loadMore")
585
+ }
586
+ ) }) : null
587
+ ] }) }) : null,
588
+ confirming !== null ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dsh-file-manage-confirm-overlay", role: "presentation", onMouseDown: (event) => {
589
+ if (event.target === event.currentTarget && !busyDelete) setConfirming(null);
590
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
591
+ "div",
592
+ {
593
+ className: "dsh-file-manage-confirm-card",
594
+ role: "alertdialog",
595
+ "aria-modal": "true",
596
+ "aria-label": t("delete"),
597
+ onKeyDown: (event) => {
598
+ if (event.key === "Escape" && !busyDelete) {
599
+ event.stopPropagation();
600
+ setConfirming(null);
601
+ }
602
+ },
603
+ children: [
604
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { className: "dsh-file-manage-confirm-title", children: t("delete") }),
605
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dsh-file-manage-confirm-desc", children: confirming.dshOwned ? t("confirm.deleteDsh", { name: confirming.filename }) : t("confirm.delete", { name: confirming.filename }) }),
606
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-file-manage-confirm-actions", children: [
607
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
608
+ "button",
609
+ {
610
+ type: "button",
611
+ className: "dsh-file-manage-btn",
612
+ disabled: busyDelete,
613
+ onClick: () => {
614
+ setConfirming(null);
615
+ },
616
+ children: t("confirm.cancel")
617
+ }
618
+ ),
619
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
620
+ "button",
621
+ {
622
+ type: "button",
623
+ className: "dsh-file-manage-btn dsh-file-manage-btn-danger",
624
+ disabled: busyDelete,
625
+ onClick: () => {
626
+ void submitDelete();
627
+ },
628
+ children: busyDelete ? t("confirm.deleting") : t("confirm.confirm")
629
+ }
630
+ )
631
+ ] })
632
+ ]
633
+ }
634
+ ) }) : null
635
+ ] });
636
+ }
637
+
638
+ // src/client/index.ts
639
+ var inject = ["slots", "locale"];
640
+ var LOCALE_DICTS = {
641
+ zh: {
642
+ "button.label": "\u4E91\u7AEF\u6587\u4EF6",
643
+ "dialog.title": "\u4E91\u7AEF\u6587\u4EF6\uFF08DeepSeek Files API\uFF09",
644
+ "dialog.close": "\u5173\u95ED",
645
+ "loading": "\u52A0\u8F7D\u4E2D\u2026",
646
+ "loadMore": "\u52A0\u8F7D\u66F4\u591A",
647
+ "summary.count": "\u5171 {count} \u4E2A\u6587\u4EF6",
648
+ "summary.loaded": "\u5DF2\u52A0\u8F7D {loaded} / \u5171 {count} \u4E2A\u6587\u4EF6",
649
+ "quota.used": "\u5DF2\u7528 {percent}",
650
+ "empty": "\u6682\u65E0\u4E91\u7AEF\u6587\u4EF6",
651
+ "dshBadge": "DSH \u81EA\u52A8\u4E0A\u4F20",
652
+ "expires": "\u5230\u671F {time}",
653
+ "copy": "\u590D\u5236 file_id",
654
+ "copied": "\u5DF2\u590D\u5236",
655
+ "copyFailed": "\u590D\u5236\u5931\u8D25\uFF08\u6D4F\u89C8\u5668\u53EF\u80FD\u672A\u6388\u6743\u526A\u8D34\u677F\uFF09",
656
+ "delete": "\u5220\u9664",
657
+ "retry": "\u91CD\u8BD5",
658
+ "confirm.confirm": "\u786E\u8BA4\u5220\u9664",
659
+ "confirm.cancel": "\u53D6\u6D88",
660
+ "confirm.deleting": "\u6B63\u5728\u5220\u9664\u2026",
661
+ "confirm.delete": "\u5220\u9664\u300C{name}\u300D\uFF1F\n\n\u5220\u9664\u540E\uFF0C\u5F15\u7528\u5B83\u7684\u4F1A\u8BDD\u518D\u6B21\u4F7F\u7528\u65F6\u5B98\u65B9\u4F1A\u81EA\u52A8\u91CD\u65B0\u4E0A\u4F20\uFF08\u53EF\u80FD\u7A0D\u6162\uFF09\u3002",
662
+ "confirm.deleteDsh": "\u6B64\u6587\u4EF6\u7531 DSH \u81EA\u52A8\u4E0A\u4F20\uFF0C\u53EF\u80FD\u4ECD\u88AB\u4F1A\u8BDD\u5F15\u7528\u3002\n\n\u5220\u9664\u300C{name}\u300D\uFF1F\u5220\u9664\u540E\u518D\u6B21\u5F15\u7528\u65F6\u5B98\u65B9\u4F1A\u81EA\u52A8\u91CD\u65B0\u4E0A\u4F20\u3002"
663
+ },
664
+ en: {
665
+ "button.label": "Cloud Files",
666
+ "dialog.title": "Cloud Files (DeepSeek Files API)",
667
+ "dialog.close": "Close",
668
+ "loading": "Loading\u2026",
669
+ "loadMore": "Load more",
670
+ "summary.count": "{count} files",
671
+ "summary.loaded": "{loaded} / {count} files",
672
+ "quota.used": "{percent} used",
673
+ "empty": "No cloud files",
674
+ "dshBadge": "DSH auto-uploaded",
675
+ "expires": "expires {time}",
676
+ "copy": "Copy file_id",
677
+ "copied": "Copied",
678
+ "copyFailed": "Copy failed (clipboard may be blocked by the browser)",
679
+ "delete": "Delete",
680
+ "retry": "Retry",
681
+ "confirm.confirm": "Delete",
682
+ "confirm.cancel": "Cancel",
683
+ "confirm.deleting": "Deleting\u2026",
684
+ "confirm.delete": 'Delete "{name}"?\n\nSessions that reference it will transparently re-upload on next use (may be slower).',
685
+ "confirm.deleteDsh": 'This file was auto-uploaded by DSH and may still be referenced by sessions.\n\nDelete "{name}"? It will transparently re-upload on next use.'
686
+ }
687
+ };
688
+ function apply(ctx) {
689
+ ensureFileManageStyles();
690
+ const disposeDictionaries = ctx.locale.register("file-manage", { zh: LOCALE_DICTS.zh, en: LOCALE_DICTS.en });
691
+ ctx.effect(() => disposeDictionaries, "dsh-file-manage: locale dictionaries");
692
+ ctx.slots.inject("sidebar.footer.action", () => ctx.slots.register({
693
+ name: "sidebar.footer.action",
694
+ locale: "file-manage",
695
+ id: "file-manage",
696
+ order: 21,
697
+ inject: () => ({
698
+ listFiles: listApi,
699
+ deleteFile: deleteApi,
700
+ countFiles: countApi
701
+ })
702
+ }, FileManageDock));
703
+ }
704
+ return module.exports; } });
705
+ //# sourceMappingURL=client.js.map