dsh-bill-ilife 0.3.3 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.js CHANGED
@@ -152,6 +152,678 @@ window.__ModuleLoader__.load({
152
152
  /** 宿主目录选择命名空间的服务名(#736;出处与禁令见 cookbook §13)。 */
153
153
  const REMOTE_DIRECTORY_PICKER = "remote.directoryPicker";
154
154
  //#endregion
155
+ //#region ../plugin-manager/dist/directory-browser-contract.js
156
+ /** 目录浏览器的纯逻辑半(**不认识宿主**:只认两格原语)。
157
+ *
158
+ * 为什么在这里:六个单品插件的设置页各有一批「值是一个目录」的行,它们要的界面是同一个东西。
159
+ * 界面的**取数**来自宿主给的两个原语(`list`/`createDirectory`),而这两个原语的形状是**调用方喂进来的**
160
+ * ——本件不 import 宿主的任何实现,也不认识 `remote.directoryPicker` 这个名字(那两件住在各家的
161
+ * `dsh-ctx.ts` 镜像里)。于是本件在 Windows 桌面、远程浏览器、SSH 三种部署下是同一份代码。
162
+ *
163
+ * 装什么:本次要浏览的那一层怎么走(进子目录/回上一级/跳面包屑)、路径怎么切出「目录部分」与
164
+ * 「筛选词」、回执怎么认。**不装**任何 IO、不装任何持久化——`list`/`createDirectory` 由调用方执行。
165
+ *
166
+ * 与平台自带浏览器件的关系:`@deepseek-ai/dsh-client-ui-directory-picker-browse` 的 `DirectoryBrowser`
167
+ * 是包内私有件(只经 `ui-workspace` 的流程空位暴露),插件侧取不到,所以这里是一份独立实现,
168
+ * 只对齐它的**交互结果**(进/选/新建),不对齐它的 DOM。
169
+ */
170
+ /** 认一认某个值是不是可用的目录取数面(软依赖守卫用:认不出就当没有,绝不把页面带下来)。 */
171
+ function isBrowseFace(raw) {
172
+ if (typeof raw !== "object" || raw === null) return false;
173
+ const face = raw;
174
+ return typeof face.list === "function" && typeof face.createDirectory === "function";
175
+ }
176
+ /** 认一认某个值有没有 `pick`(对应宿主 composition 里的 `native` 能力)。 */
177
+ function hasPickFn(raw) {
178
+ if (typeof raw !== "object" || raw === null) return false;
179
+ return typeof raw.pick === "function";
180
+ }
181
+ /** 三态判定:先 native(有 pick),再 browse(有两格原语),都没有=`none`。 */
182
+ function pickerModeOf$1(raw) {
183
+ if (hasPickFn(raw)) return "native";
184
+ return isBrowseFace(raw) ? "browse" : "none";
185
+ }
186
+ /** 平台回执 → 三态(**永不抛**):成功回的是信封里的 `value` 不是路径;`ok:false` 是「供不了」不是「取消」。
187
+ *
188
+ * 出处:`@deepseek-ai/dsh-api-gateway/lib/client.js` 的 `invoke()`(失败不抛、成功也不回裸值),
189
+ * 第一方消费方 `@deepseek-ai/dsh-client-ui-workspace/lib/client.js:99-103` 就照这个信封拆。
190
+ * 裸串照收(老形状兜底),认不出的形状当「供不了」报出来,不当取消吞掉(#743 的教训)。 */
191
+ function readPickAnswer$1(raw) {
192
+ if (typeof raw === "string") return raw.trim() === "" ? { kind: "cancelled" } : {
193
+ kind: "picked",
194
+ path: raw
195
+ };
196
+ const answer = typeof raw === "object" && raw !== null ? raw : {};
197
+ if (answer.ok === true) {
198
+ const value = answer.value;
199
+ return typeof value === "string" && value.trim() !== "" ? {
200
+ kind: "picked",
201
+ path: value
202
+ } : { kind: "cancelled" };
203
+ }
204
+ const detail = answer.error?.message?.trim() ?? "";
205
+ return {
206
+ kind: "unavailable",
207
+ message: "打不开系统文件夹对话框" + (detail === "" ? "" : "(" + detail + ")") + ":请直接在框里填绝对路径。"
208
+ };
209
+ }
210
+ /** 一段路径里最后那个分隔符的位置(Windows 上 `\` 与 `/` 都算;POSIX 上 `\` 是合法文件名字符,不算)。 */
211
+ function lastSeparator(path) {
212
+ const back = path.lastIndexOf("\\");
213
+ const slash = path.lastIndexOf("/");
214
+ return back > slash ? back : slash;
215
+ }
216
+ /** 上一层:`'C:\\a\\b\\'` → `'C:\\a'`;已经是根则回自身;相对名(没有任何分隔符)也回自身。
217
+ *
218
+ * 尾分隔符先吃掉再切——否则「回上一级」会在原地打转。**盘根单独认**:`C:\` 掐掉尾分隔符会剩成
219
+ * `C:`,而 `C:` 是「当前盘」不是「上一层」,回它就会多跑一趟、还可能跨到别的盘上去。
220
+ * UNC(`\\server\share`)不特殊处理:切到头就是共享名本身,浏览停在共享根。 */
221
+ function parentOf(path) {
222
+ const trimmed = path.replace(/[\\/]+$/, "");
223
+ if (trimmed === "") return path;
224
+ const sep = path.includes("\\") ? "\\" : "/";
225
+ if (/^[A-Za-z]:$/.test(trimmed)) return trimmed + sep;
226
+ const cut = lastSeparator(trimmed);
227
+ if (cut === -1) return trimmed;
228
+ if (cut === 0) return path.slice(0, 1);
229
+ if (cut === 2 && /^[A-Za-z]:/.test(trimmed)) return trimmed.slice(0, 2) + sep;
230
+ return trimmed.slice(0, cut);
231
+ }
232
+ /** 一层列举里,哪些行可进:隐藏目录按开关过滤,其余照宿主给的顺序。 */
233
+ function visibleEntries(listing, showHidden) {
234
+ return showHidden ? listing.entries : listing.entries.filter((entry) => !entry.hidden);
235
+ }
236
+ /** 这一层有多少个被藏起来的目录(用来决定「显示隐藏目录」那个开关要不要出现在图上)。 */
237
+ function hiddenCount(listing) {
238
+ return listing.entries.filter((entry) => entry.hidden).length;
239
+ }
240
+ /** 拿一段文本按「最后一个分隔符」切成「目录部分 + 筛选词」。
241
+ *
242
+ * 没打过任何分隔符时目录部分=null(那段文字还不指任何目录,只当筛选词用)。
243
+ * Windows 上 `/` 也当分隔符(宿主那边两种都收),POSIX 上不。 */
244
+ function splitDraft(draft) {
245
+ const cut = lastSeparator(draft);
246
+ if (cut === -1) return {
247
+ directory: null,
248
+ filter: draft
249
+ };
250
+ return {
251
+ directory: draft.slice(0, cut + 1),
252
+ filter: draft.slice(cut + 1)
253
+ };
254
+ }
255
+ /** 按筛选词过一层目录(大小写不敏感;空筛选词=全留)。 */
256
+ function filterEntries(entries, filter) {
257
+ const needle = filter.trim().toLowerCase();
258
+ if (needle === "") return entries;
259
+ return entries.filter((entry) => entry.name.toLowerCase().includes(needle));
260
+ }
261
+ /** 给界面用的一句话位置说明:优先显示相对 home 的说法,省得整条绝对路径占满一行。 */
262
+ function locationLabel(listing) {
263
+ const home = listing.home.replace(/[\\/]+$/, "");
264
+ if (home !== "" && listing.path !== home && listing.path.startsWith(home)) {
265
+ const tail = listing.path.slice(home.length).replace(/^[\\/]+/, "");
266
+ if (tail !== "") return "~" + (listing.path.includes("\\") ? "\\" : "/") + tail;
267
+ }
268
+ return listing.path;
269
+ }
270
+ /** 新建文件夹的名字合不合法(单个路径段:不许分隔符、不许空、不许 `.`/`..`)。
271
+ *
272
+ * 与宿主 browse 后端的校验同口径——这里先拦一道,是为了在图上给得出人话,不是替代宿主校验。 */
273
+ function validateFolderName(name) {
274
+ const trimmed = name.trim();
275
+ if (trimmed === "") return {
276
+ ok: false,
277
+ reason: "文件夹名不能为空。"
278
+ };
279
+ if (/[\\/]/.test(trimmed)) return {
280
+ ok: false,
281
+ reason: "文件夹名里不能带路径分隔符。"
282
+ };
283
+ if (trimmed === "." || trimmed === "..") return {
284
+ ok: false,
285
+ reason: "「.」与「..」不是文件夹名。"
286
+ };
287
+ return { ok: true };
288
+ }
289
+ //#endregion
290
+ //#region ../plugin-manager/dist/directory-browser-state.js
291
+ /** 文件浏览器的操作半:把「进哪一层、这一层显示什么、选到了什么」算成状态,**IO 全部由调用方注入**。
292
+ *
293
+ * 分两层的原因:本件(操作)在 Node 里就能直测——喂一个假的取数面,就能把「进目录/回上一级/
294
+ * 跳面包屑/筛选/新建文件夹/失败出人话」全跑一遍;视图那半(`directory-browser-ui.ts`)
295
+ * 只负责把这份状态画成 DOM。两边都不认识宿主。
296
+ *
297
+ * 数据来源只有两格:`list(path?)` 与 `createDirectory(path, name)`(调用方注入的 `DirectoryBrowseFace`)。
298
+ */
299
+ /** 建一个浏览器控制器。取数、回调、初值全部由调用方给。 */
300
+ function createBrowseController(deps) {
301
+ const label = deps.failureLabel ?? "浏览失败";
302
+ const listeners = /* @__PURE__ */ new Set();
303
+ let state = {
304
+ phase: "idle",
305
+ listing: null,
306
+ failure: null,
307
+ selected: null,
308
+ showHidden: false,
309
+ draft: deps.initialPath,
310
+ filter: "",
311
+ creating: null,
312
+ notice: null
313
+ };
314
+ /** 每次列举带一个序号:晚回来的旧回执直接丢掉,不许覆盖新一层。 */
315
+ let generation = 0;
316
+ const emit = (next) => {
317
+ state = {
318
+ ...state,
319
+ ...next
320
+ };
321
+ for (const listener of [...listeners]) listener(state);
322
+ };
323
+ const humanize = (cause) => {
324
+ const raw = typeof cause === "object" && cause !== null ? cause : {};
325
+ const message = typeof raw.message === "string" && raw.message.trim() !== "" ? raw.message.trim() : String(cause);
326
+ return {
327
+ code: typeof raw.code === "string" && raw.code !== "" ? raw.code : "browse-failed",
328
+ message: `${label}:${message}`
329
+ };
330
+ };
331
+ const load = async (path) => {
332
+ const mine = ++generation;
333
+ emit({
334
+ phase: "loading",
335
+ failure: null,
336
+ notice: null
337
+ });
338
+ try {
339
+ const listing = path === null ? await deps.face.list() : await deps.face.list(path);
340
+ if (mine !== generation) return;
341
+ emit({
342
+ phase: "ready",
343
+ listing,
344
+ failure: null,
345
+ selected: null,
346
+ draft: listing.path,
347
+ filter: ""
348
+ });
349
+ } catch (cause) {
350
+ if (mine !== generation) return;
351
+ emit({
352
+ phase: "failed",
353
+ listing: null,
354
+ failure: humanize(cause),
355
+ selected: null
356
+ });
357
+ }
358
+ };
359
+ /** 草稿指到的那一层已经列举过时,按末段筛当前这一层的行;否则不过滤。
360
+ *
361
+ * 两边都先掐掉尾分隔符再比:草稿那边切开后天然带尾分隔符(`C:\a\` + `b`),
362
+ * 而这一层的 `path` 由宿主给、不带尾分隔符。 */
363
+ const applyDraft = (draft) => {
364
+ const { directory, filter } = splitDraft(draft);
365
+ const listing = state.listing;
366
+ const sameLevel = listing !== null && directory !== null && normalize(directory) === normalize(listing.path);
367
+ emit({
368
+ draft,
369
+ filter: sameLevel ? filter : ""
370
+ });
371
+ };
372
+ const normalize = (path) => path.replace(/[\\/]+$/, "");
373
+ return {
374
+ getState: () => state,
375
+ subscribe(listener) {
376
+ listeners.add(listener);
377
+ return () => listeners.delete(listener);
378
+ },
379
+ open: () => load(null),
380
+ enter: (path) => load(path),
381
+ async up() {
382
+ const listing = state.listing;
383
+ if (listing === null) return;
384
+ const parent = parentOf(listing.path);
385
+ if (parent === listing.path) return;
386
+ await load(parent);
387
+ },
388
+ pick() {
389
+ const target = state.selected ?? state.listing?.path ?? null;
390
+ if (target === null) return;
391
+ deps.onPicked(target);
392
+ },
393
+ cancel() {
394
+ deps.onClose();
395
+ },
396
+ close() {
397
+ deps.onClose();
398
+ },
399
+ select(path) {
400
+ emit({
401
+ selected: state.selected === path ? null : path,
402
+ notice: null
403
+ });
404
+ },
405
+ toggleHidden() {
406
+ emit({ showHidden: !state.showHidden });
407
+ },
408
+ setDraft(draft) {
409
+ applyDraft(draft);
410
+ },
411
+ async commitDraft() {
412
+ const trimmed = state.draft.trim();
413
+ if (trimmed === "") return;
414
+ await load(trimmed);
415
+ },
416
+ setCreating(name) {
417
+ emit({
418
+ creating: name,
419
+ notice: null
420
+ });
421
+ },
422
+ async createFolder(name) {
423
+ const checked = validateFolderName(name);
424
+ if (!checked.ok) {
425
+ emit({ notice: checked.reason });
426
+ return;
427
+ }
428
+ const base = state.selected ?? state.listing?.path ?? null;
429
+ if (base === null) {
430
+ emit({ notice: "还没有打开任何目录,无法新建文件夹。" });
431
+ return;
432
+ }
433
+ try {
434
+ const created = await deps.face.createDirectory(base, name.trim());
435
+ emit({
436
+ creating: null,
437
+ notice: null
438
+ });
439
+ await load(created);
440
+ emit({ selected: created });
441
+ } catch (cause) {
442
+ const failure = humanize(cause);
443
+ emit({
444
+ notice: failure.message,
445
+ creating: null
446
+ });
447
+ }
448
+ }
449
+ };
450
+ }
451
+ /** 图上这一层要画的行(按隐藏开关与草稿末段过滤之后的)。 */
452
+ function rowsOf(state) {
453
+ if (state.listing === null) return [];
454
+ return filterEntries(visibleEntries(state.listing, state.showHidden), state.filter);
455
+ }
456
+ /** 「打开」这颗按钮的目标:选中行优先,没选中就是当前层。 */
457
+ function targetOf(state) {
458
+ return state.selected ?? state.listing?.path ?? null;
459
+ }
460
+ /** 一段路径拼成可读的一句话(给用例与调试用;图上不直接显示)。 */
461
+ function describe(state) {
462
+ if (state.phase === "failed") return `${state.failure?.code ?? "browse-failed"} @ ${state.draft}`;
463
+ if (state.listing === null) return `${state.phase}`;
464
+ return `${state.listing.path}(${rowsOf(state).length} 行)`;
465
+ }
466
+ /** 建一份「目录行接线」:给一个取数面与初值,回一组动作。
467
+ *
468
+ * 只做接线:把控制器算出来的状态与回调打包好,不取数、不画图、不认宿主。 */
469
+ function createDirectoryRowBrowser(deps) {
470
+ const controller = createBrowseController({
471
+ face: deps.face,
472
+ initialPath: deps.initialPath,
473
+ onPicked: deps.onPicked,
474
+ onClose: () => deps.onClosed?.(),
475
+ ...deps.failureLabel === void 0 ? {} : { failureLabel: deps.failureLabel }
476
+ });
477
+ return {
478
+ open: () => controller.open(),
479
+ state: () => controller.getState(),
480
+ summary: () => describe(controller.getState()),
481
+ actions: {
482
+ onPick: () => controller.pick(),
483
+ onClose: () => controller.cancel(),
484
+ onEnter: (path) => void controller.enter(path),
485
+ onUp: () => void controller.up(),
486
+ onSelect: (path) => controller.select(path),
487
+ onToggleHidden: () => controller.toggleHidden(),
488
+ onDraft: (draft) => controller.setDraft(draft),
489
+ onCommitDraft: () => void controller.commitDraft(),
490
+ onCreate: (name) => void controller.createFolder(name),
491
+ onCreatingChange: (name) => controller.setCreating(name)
492
+ }
493
+ };
494
+ }
495
+ //#endregion
496
+ //#region ../plugin-manager/dist/directory-browser-ui.js
497
+ /** 文件浏览器的视图半:把 `BrowseState` 画成一张对话框。**不认识宿主**,也不自己做 IO。
498
+ *
499
+ * 手写 `React.createElement`(本包 client 束禁 JSX,见 `tsdown.config.ts` 的既成口径)。
500
+ * 只读状态、只回调;进哪一层、选到什么由操作半(`directory-browser-state.ts`)算。
501
+ */
502
+ const EMPTY_LISTING = {
503
+ path: "",
504
+ home: "",
505
+ crumbs: [],
506
+ entries: [],
507
+ truncated: false
508
+ };
509
+ const S$1 = {
510
+ scrim: {
511
+ position: "fixed",
512
+ inset: 0,
513
+ background: "rgba(0,0,0,0.35)",
514
+ display: "flex",
515
+ alignItems: "center",
516
+ justifyContent: "center",
517
+ zIndex: 9999
518
+ },
519
+ dialog: {
520
+ width: 680,
521
+ maxWidth: "92vw",
522
+ height: 500,
523
+ maxHeight: "86vh",
524
+ display: "flex",
525
+ flexDirection: "column",
526
+ background: "var(--dsw-alias-bg-layer-1, #1f1f23)",
527
+ color: "var(--dsw-alias-label-primary, inherit)",
528
+ border: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.35))",
529
+ borderRadius: 10,
530
+ boxShadow: "0 12px 32px rgba(0,0,0,0.35)",
531
+ overflow: "hidden"
532
+ },
533
+ head: {
534
+ display: "flex",
535
+ alignItems: "center",
536
+ gap: 8,
537
+ padding: "10px 12px",
538
+ borderBottom: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.25))"
539
+ },
540
+ title: {
541
+ fontSize: 14,
542
+ fontWeight: 700
543
+ },
544
+ headTail: {
545
+ marginLeft: "auto",
546
+ fontSize: 12,
547
+ opacity: .72,
548
+ overflow: "hidden",
549
+ textOverflow: "ellipsis",
550
+ whiteSpace: "nowrap"
551
+ },
552
+ crumbs: {
553
+ display: "flex",
554
+ flexWrap: "wrap",
555
+ alignItems: "center",
556
+ gap: 2,
557
+ padding: "8px 12px 0",
558
+ fontSize: 12
559
+ },
560
+ chromeButton: {
561
+ background: "transparent",
562
+ border: "none",
563
+ color: "var(--dsw-alias-label-primary, inherit)",
564
+ cursor: "pointer",
565
+ padding: "2px 4px",
566
+ fontSize: 12,
567
+ opacity: .85
568
+ },
569
+ crumbSep: {
570
+ opacity: .45,
571
+ fontSize: 12
572
+ },
573
+ pathRow: {
574
+ display: "flex",
575
+ gap: 6,
576
+ padding: "8px 12px"
577
+ },
578
+ input: {
579
+ flex: 1,
580
+ minWidth: 0,
581
+ fontSize: 12,
582
+ padding: "5px 8px",
583
+ background: "var(--dsw-alias-bg-layer-2, rgba(128,128,128,0.12))",
584
+ color: "inherit",
585
+ border: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.35))",
586
+ borderRadius: 6
587
+ },
588
+ button: {
589
+ fontSize: 12,
590
+ padding: "5px 10px",
591
+ cursor: "pointer",
592
+ background: "var(--dsw-alias-bg-layer-2, rgba(128,128,128,0.12))",
593
+ color: "inherit",
594
+ border: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.35))",
595
+ borderRadius: 6
596
+ },
597
+ buttonOff: {
598
+ opacity: .45,
599
+ cursor: "default"
600
+ },
601
+ list: {
602
+ flex: 1,
603
+ minHeight: 0,
604
+ overflowY: "auto",
605
+ margin: "0 12px",
606
+ border: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.25))",
607
+ borderRadius: 6
608
+ },
609
+ row: {
610
+ display: "flex",
611
+ alignItems: "center",
612
+ gap: 8,
613
+ width: "100%",
614
+ padding: "6px 10px",
615
+ textAlign: "left",
616
+ background: "transparent",
617
+ color: "inherit",
618
+ border: "none",
619
+ borderBottom: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.12))",
620
+ cursor: "pointer",
621
+ fontSize: 13
622
+ },
623
+ rowSelected: { background: "var(--dsw-alias-bg-layer-2, rgba(128,128,128,0.18))" },
624
+ empty: {
625
+ padding: "14px 12px",
626
+ fontSize: 12,
627
+ opacity: .7
628
+ },
629
+ footNote: {
630
+ padding: "6px 12px 0",
631
+ fontSize: 12,
632
+ minHeight: 20
633
+ },
634
+ foot: {
635
+ display: "flex",
636
+ alignItems: "center",
637
+ gap: 8,
638
+ padding: "10px 12px",
639
+ borderTop: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.25))"
640
+ },
641
+ target: {
642
+ marginRight: "auto",
643
+ fontSize: 12,
644
+ opacity: .8,
645
+ overflow: "hidden",
646
+ textOverflow: "ellipsis",
647
+ whiteSpace: "nowrap"
648
+ },
649
+ error: { color: "var(--dsw-alias-label-error, #e66)" }
650
+ };
651
+ function crumbRow(state, labels, onEnter) {
652
+ const listing = state.listing;
653
+ if (listing === null || listing.crumbs.length === 0) return null;
654
+ const parts = [];
655
+ listing.crumbs.forEach((crumb, index) => {
656
+ if (index > 0) parts.push(react.createElement("span", {
657
+ key: "sep-" + crumb.path,
658
+ style: S$1.crumbSep
659
+ }, "›"));
660
+ const isCurrent = crumb.path === listing.path;
661
+ parts.push(react.createElement("button", {
662
+ key: crumb.path,
663
+ type: "button",
664
+ style: {
665
+ ...S$1.chromeButton,
666
+ fontWeight: isCurrent ? 700 : 400
667
+ },
668
+ title: crumb.path,
669
+ onClick: () => onEnter(crumb.path)
670
+ }, index === 0 ? labels.up : crumb.name));
671
+ });
672
+ return react.createElement("div", { style: S$1.crumbs }, parts);
673
+ }
674
+ function entryRow(entry, selected, labels, onToggleSelect, onEnter) {
675
+ return react.createElement("div", {
676
+ key: entry.path,
677
+ style: {
678
+ ...S$1.row,
679
+ padding: 0,
680
+ ...selected ? S$1.rowSelected : {}
681
+ }
682
+ }, react.createElement("button", {
683
+ type: "button",
684
+ style: {
685
+ ...S$1.row,
686
+ flex: 1,
687
+ border: "none"
688
+ },
689
+ onClick: () => onEnter(entry.path)
690
+ }, "📁 " + entry.name), react.createElement("button", {
691
+ type: "button",
692
+ style: {
693
+ ...S$1.button,
694
+ marginRight: 8,
695
+ padding: "2px 8px"
696
+ },
697
+ "aria-pressed": selected,
698
+ title: selected ? labels.selected : labels.select,
699
+ onClick: () => onToggleSelect(entry.path)
700
+ }, selected ? "✓" : labels.select));
701
+ }
702
+ function createRow(labels, onName, onCancel, onCreate, creatingName) {
703
+ if (creatingName === null) return null;
704
+ return react.createElement("div", { style: {
705
+ ...S$1.pathRow,
706
+ borderTop: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.25))"
707
+ } }, react.createElement("input", {
708
+ style: S$1.input,
709
+ value: creatingName,
710
+ placeholder: labels.newFolder,
711
+ "aria-label": labels.newFolder,
712
+ onChange: (event) => onName(event.currentTarget.value),
713
+ onKeyDown: (event) => {
714
+ if (event.key === "Enter") onCreate(creatingName);
715
+ if (event.key === "Escape") onCancel();
716
+ }
717
+ }), react.createElement("button", {
718
+ type: "button",
719
+ style: S$1.button,
720
+ onClick: () => onCreate(creatingName)
721
+ }, labels.createConfirm), react.createElement("button", {
722
+ type: "button",
723
+ style: S$1.button,
724
+ onClick: onCancel
725
+ }, labels.createCancel));
726
+ }
727
+ /** 画一张文件浏览器对话框。`open=false` 时返回 null(本件不挂 portal,由调用方决定挂在哪)。 */
728
+ function DirectoryBrowser(props) {
729
+ const { open, state, labels } = props;
730
+ if (!open) return null;
731
+ const rows = rowsOf(state);
732
+ const target = targetOf(state);
733
+ const listing = state.listing ?? EMPTY_LISTING;
734
+ const hidden = hiddenCount(listing);
735
+ const body = [];
736
+ body.push(crumbRow(state, labels, props.onEnter));
737
+ body.push(react.createElement("div", { style: S$1.pathRow }, react.createElement("input", {
738
+ style: S$1.input,
739
+ value: state.draft,
740
+ placeholder: labels.pathPlaceholder,
741
+ "aria-label": labels.pathPlaceholder,
742
+ onChange: (event) => props.onDraft(event.currentTarget.value),
743
+ onKeyDown: (event) => {
744
+ if (event.key === "Enter") props.onCommitDraft();
745
+ }
746
+ }), react.createElement("button", {
747
+ type: "button",
748
+ style: S$1.button,
749
+ onClick: props.onUp
750
+ }, labels.up), react.createElement("button", {
751
+ type: "button",
752
+ style: S$1.button,
753
+ onClick: props.onCommitDraft
754
+ }, labels.go)));
755
+ body.push(react.createElement("div", {
756
+ style: S$1.list,
757
+ role: "listbox",
758
+ "aria-label": labels.title
759
+ }, rows.length === 0 ? react.createElement("div", { style: S$1.empty }, state.phase === "loading" ? labels.loading : labels.empty) : rows.map((entry) => entryRow(entry, state.selected === entry.path, labels, props.onSelect, props.onEnter))));
760
+ body.push(createRow(labels, props.onDraft, () => props.onCreatingChange(null), props.onCreate, state.creating));
761
+ body.push(react.createElement("div", { style: S$1.footNote }, hidden > 0 ? react.createElement("label", { style: {
762
+ fontSize: 12,
763
+ cursor: "pointer",
764
+ marginRight: 10
765
+ } }, react.createElement("input", {
766
+ type: "checkbox",
767
+ checked: state.showHidden,
768
+ onChange: props.onToggleHidden
769
+ }), " " + labels.showHidden(hidden)) : null, state.creating === null ? react.createElement("button", {
770
+ type: "button",
771
+ style: {
772
+ ...S$1.chromeButton,
773
+ textDecoration: "underline"
774
+ },
775
+ onClick: () => props.onCreatingChange("")
776
+ }, labels.newFolder) : null, state.notice !== null ? react.createElement("div", { style: S$1.error }, state.notice) : null, state.phase === "failed" && state.failure !== null ? react.createElement("div", { style: S$1.error }, state.failure.message) : null));
777
+ body.push(react.createElement("div", { style: S$1.foot }, react.createElement("span", {
778
+ style: S$1.target,
779
+ title: target ?? ""
780
+ }, target === null ? "" : labels.willPick + target), react.createElement("button", {
781
+ type: "button",
782
+ style: {
783
+ ...S$1.button,
784
+ ...target === null ? S$1.buttonOff : {}
785
+ },
786
+ onClick: props.onPick
787
+ }, labels.open), react.createElement("button", {
788
+ type: "button",
789
+ style: S$1.button,
790
+ onClick: props.onClose
791
+ }, labels.cancel)));
792
+ return react.createElement("div", {
793
+ style: S$1.scrim,
794
+ role: "presentation",
795
+ onMouseDown: (event) => {
796
+ if (event.target === event.currentTarget) props.onClose();
797
+ }
798
+ }, react.createElement("div", {
799
+ style: S$1.dialog,
800
+ role: "dialog",
801
+ "aria-modal": true,
802
+ "aria-label": labels.title
803
+ }, react.createElement("div", { style: S$1.head }, react.createElement("span", { style: S$1.title }, labels.title), react.createElement("span", {
804
+ style: S$1.headTail,
805
+ title: listing.path
806
+ }, state.listing === null ? "" : locationLabel(listing)), react.createElement("button", {
807
+ type: "button",
808
+ style: S$1.button,
809
+ "aria-label": labels.close,
810
+ title: labels.close,
811
+ onClick: props.onClose
812
+ }, "✕")), body));
813
+ }
814
+ /** 目录行接线的 React 半边:把操作半那组动作直接喂给组件。
815
+ *
816
+ * 操作半(`directory-browser-state.ts` 的 `createDirectoryRowBrowser`)不碰 React,
817
+ * 这里只把它的 `actions` 摊进 props —— 于是「进哪一层」那套在 Node 里可测,这里只做接线。 */
818
+ function DirectoryBrowserFromRow(props) {
819
+ return DirectoryBrowser({
820
+ open: props.open,
821
+ state: props.row.state(),
822
+ labels: props.labels,
823
+ ...props.row.actions
824
+ });
825
+ }
826
+ //#endregion
155
827
  //#region src/client.ts
156
828
  /** dsh-bill-ilife client 适配器(六边形:port=contract,adapter=本文件)。
157
829
  *
@@ -171,7 +843,10 @@ window.__ModuleLoader__.load({
171
843
  /** client 短名声明:只有这两个(#736 的目录选择走**可选查找**,不写进来——
172
844
  * 写进来=硬依赖,提供方缺席时整包被停靠,设置页会跟着装不上;见 cookbook §13)。 */
173
845
  const inject = ["slots", "connection"];
174
- /** 面板视觉(内联 style;颜色走 DSH 主题别名,深浅主题自适应,写死值只做回退)。 */
846
+ /** 面板视觉(内联 style;颜色走 DSH 主题别名,深浅主题自适应,写死值只做回退)。
847
+ *
848
+ * **六家逐项同形**(备忘·卡路里·记账·作息·居家·大厨):同一项在这六份里逐字相同,
849
+ * 改任一条要六家一起改,锁见 `test/panel-copy-743.test.mjs` 第 ⑤ 条。 */
175
850
  const S = {
176
851
  card: {
177
852
  padding: "12px 14px",
@@ -191,11 +866,13 @@ window.__ModuleLoader__.load({
191
866
  fontSize: "0.92em"
192
867
  },
193
868
  error: {
194
- color: "var(--dsw-alias-state-error-primary, #ff6b6b)",
869
+ marginTop: 8,
870
+ color: "var(--dsw-alias-label-error, #b3261e)",
195
871
  fontSize: "1em",
196
872
  whiteSpace: "pre-wrap"
197
873
  },
198
874
  okText: {
875
+ marginTop: 8,
199
876
  color: "var(--dsw-alias-state-success-primary, #12805c)",
200
877
  fontSize: "0.96em"
201
878
  },
@@ -205,16 +882,16 @@ window.__ModuleLoader__.load({
205
882
  paddingTop: 8
206
883
  },
207
884
  info: {
208
- fontSize: "0.92em",
209
885
  color: "var(--dsw-alias-label-secondary, #9a9a9a)",
886
+ fontSize: "0.92em",
210
887
  overflowWrap: "anywhere"
211
888
  },
212
- row: { marginTop: 10 },
889
+ row: { marginBottom: 10 },
213
890
  label: { fontWeight: 600 },
214
891
  hint: {
215
- color: "var(--dsw-alias-label-tertiary, #8a8a8a)",
892
+ color: "var(--dsw-alias-label-secondary, #9a9a9a)",
216
893
  fontSize: "0.92em",
217
- margin: "1px 0 4px"
894
+ marginBottom: 4
218
895
  },
219
896
  input: {
220
897
  width: "100%",
@@ -241,34 +918,29 @@ window.__ModuleLoader__.load({
241
918
  cursor: "pointer"
242
919
  },
243
920
  bar: {
244
- marginTop: 14,
245
921
  display: "flex",
246
922
  gap: 8,
247
- alignItems: "center",
923
+ marginTop: 12,
248
924
  flexWrap: "wrap"
249
925
  },
250
926
  btn: {
251
- padding: "5px 14px",
252
- borderRadius: 7,
927
+ padding: "4px 12px",
928
+ borderRadius: 6,
253
929
  border: "1px solid var(--dsw-alias-border, rgba(128,128,128,.45))",
254
930
  background: "var(--dsw-alias-bg-base, transparent)",
255
931
  color: "var(--dsw-alias-label-primary, inherit)",
256
932
  cursor: "pointer"
257
933
  },
258
934
  btnPrimary: {
259
- padding: "5px 14px",
260
- borderRadius: 7,
935
+ padding: "4px 12px",
936
+ borderRadius: 6,
261
937
  border: "1px solid var(--dsw-alias-brand-primary, #2f6fed)",
262
938
  background: "var(--dsw-alias-brand-primary, #2f6fed)",
263
939
  color: "#fff",
264
940
  cursor: "pointer"
265
941
  },
266
- adv: {
267
- marginTop: 12,
268
- paddingTop: 8,
269
- borderTop: "1px solid var(--dsw-alias-border, rgba(128,128,128,.25))"
270
- },
271
- advSummary: {
942
+ advanced: { marginTop: 12 },
943
+ summary: {
272
944
  cursor: "pointer",
273
945
  fontWeight: 600
274
946
  }
@@ -403,29 +1075,9 @@ window.__ModuleLoader__.load({
403
1075
  return null;
404
1076
  }
405
1077
  }
406
- /** 平台回执 → 三种结果(**永不抛**)。回执是信封 `{ok, value|error}`(见 dsh-ctx.ts 的
407
- * `DirectoryPickerAnswer`):成功回的是 `value` 不是路径本身,被拒回的是 `ok:false` 不是抛——
408
- * 照裸值解会把两种情况都误判成「用户取消」(#743 真机现象:点「选择文件夹」什么都没发生)。
409
- * 裸串照收(老形状兜底),认不出的形状当「供不了」报出来,不当取消吞掉。 */
410
- function readPickAnswer(raw) {
411
- if (typeof raw === "string") return raw.trim() === "" ? { kind: "cancelled" } : {
412
- kind: "picked",
413
- path: raw
414
- };
415
- const answer = typeof raw === "object" && raw !== null ? raw : {};
416
- if (answer.ok === true) {
417
- const value = answer.value;
418
- return typeof value === "string" && value.trim() !== "" ? {
419
- kind: "picked",
420
- path: value
421
- } : { kind: "cancelled" };
422
- }
423
- const detail = answer.error?.message?.trim() ?? "";
424
- return {
425
- kind: "unavailable",
426
- message: "打不开系统文件夹对话框" + (detail === "" ? "" : "(" + detail + ")") + ":请直接在框里填绝对路径。"
427
- };
428
- }
1078
+ /** 平台回执/入口三态:**已经收进共用件**(票 #744),这里只同名转出。 */
1079
+ const readPickAnswer = readPickAnswer$1;
1080
+ const pickerModeOf = pickerModeOf$1;
429
1081
  /** 唤起一次系统文件夹选择器并归一结果(**永不抛**)。 */
430
1082
  async function pickDirectory(picker) {
431
1083
  try {
@@ -437,6 +1089,29 @@ window.__ModuleLoader__.load({
437
1089
  };
438
1090
  }
439
1091
  }
1092
+ /** 入口三态:有系统对话框(`pick`)/只有应用内浏览(`list` + `createDirectory`)/都没有。
1093
+ *
1094
+ * 判定取自共用件(一处定义)。本函数只读那个命名空间,不做 IO。 */
1095
+ function directoryEntryMode(picker) {
1096
+ return picker === null ? "none" : pickerModeOf(picker);
1097
+ }
1098
+ /** 开一行的应用内浏览器;返回 undefined=这条路供不了(调用方据此不画入口)。
1099
+ *
1100
+ * **状态由调用方持有**(`setBrowseRow`):本函数只造浏览器、开图,不碰 React 状态。 */
1101
+ function openRowBrowser(input) {
1102
+ if (input.picker === null || pickerModeOf(input.picker) !== "browse") return void 0;
1103
+ const row = createDirectoryRowBrowser({
1104
+ face: input.picker,
1105
+ initialPath: input.path,
1106
+ onPicked: (picked) => {
1107
+ input.onChange(input.key, picked);
1108
+ input.setBrowseRow(null);
1109
+ },
1110
+ onClosed: () => input.setBrowseRow(null)
1111
+ });
1112
+ input.setBrowseRow(row);
1113
+ return row.open();
1114
+ }
440
1115
  /** 「选择文件夹」按钮的真装配函数(目录行渲染出来的按钮,onClick 就是它)。
441
1116
  *
442
1117
  * 回 Promise 是为了本地可判(用例直接 await);接进 React 时调用方 `void` 掉。 */
@@ -467,12 +1142,14 @@ window.__ModuleLoader__.load({
467
1142
  spellCheck: false,
468
1143
  onChange
469
1144
  });
470
- const browse = item.control === "directory" && props.onBrowse !== void 0 ? react.createElement("button", {
1145
+ /** 三态入口:供不了(`none`/缺席)就不画,不摆一个点了没反应的死按钮。 */
1146
+ const entry = props.browser ?? null;
1147
+ const browse = item.control === "directory" && entry !== null && entry.mode !== "none" ? react.createElement("button", {
471
1148
  style: S.btnPick,
472
1149
  type: "button",
473
1150
  disabled: props.disabled,
474
- onClick: () => props.onBrowse?.(item.key)
475
- }, "选择文件夹…") : null;
1151
+ onClick: () => entry.onOpen(item.key)
1152
+ }, entry.mode === "native" ? "选择文件夹…" : "浏览…") : null;
476
1153
  return react.createElement("div", { style: S.row }, react.createElement("div", { style: S.label }, item.title), react.createElement("div", { style: S.hint }, item.hint), browse === null ? control : react.createElement("div", { style: S.pickRow }, control, browse));
477
1154
  }
478
1155
  /** 技能设置页:承载饼干记账自己的全部可配置项(只配置,不干活)。
@@ -526,24 +1203,46 @@ window.__ModuleLoader__.load({
526
1203
  setNotice(null);
527
1204
  setError(null);
528
1205
  }, []);
529
- /** 目录选择:拿不到命名空间就没有入口;被拒一次即收起入口(不留死按钮)。 */
530
- const picker = pickerGone ? null : props.getPicker();
531
- const onBrowse = react.useMemo(() => {
532
- if (picker === null) return void 0;
533
- const browse = createBrowseHandler({
534
- picker,
535
- onChange,
536
- onUnavailable: (message) => {
537
- setError(message);
1206
+ /** 目录行入口:三态(系统对话框/应用内浏览/都没有)。
1207
+ *
1208
+ * **软依赖**:拿不到命名空间就没有入口(留文本框),被拒一次即收起入口,不留死按钮。
1209
+ * 状态全部住在组件自己(hook 顺序与旧版同形):浏览器那一份只存「当前开着的那条」。 */
1210
+ const picker = pickerGone ? null : props.pickerSource();
1211
+ const [browseRow, setBrowseRow] = react.useState(null);
1212
+ /** 目录行的入口动作:三态各一条路;都供不了就不给入口(`undefined` ⇒ Row 不画按钮)。 */
1213
+ const onOpenRow = react.useCallback(async (key) => {
1214
+ if (pickerModeOf(picker) === "native") {
1215
+ setPicking(true);
1216
+ setError(null);
1217
+ const outcome = await pickDirectory(picker);
1218
+ setPicking(false);
1219
+ if (outcome.kind === "picked") onChange(key, outcome.path);
1220
+ else if (outcome.kind === "unavailable") {
1221
+ setError(outcome.message);
538
1222
  setPickerGone(true);
539
1223
  }
1224
+ return;
1225
+ }
1226
+ const opened = openRowBrowser({
1227
+ picker,
1228
+ key,
1229
+ path: draft[key] ?? "",
1230
+ onChange,
1231
+ setBrowseRow
540
1232
  });
541
- return (key) => {
542
- setPicking(true);
543
- setError(null);
544
- browse(key).finally(() => setPicking(false));
545
- };
546
- }, [picker, onChange]);
1233
+ if (opened === void 0) return;
1234
+ setError(null);
1235
+ await opened;
1236
+ }, [
1237
+ picker,
1238
+ onChange,
1239
+ draft
1240
+ ]);
1241
+ /** 给 Row 的三态入口:`none` 时给 null(不画按钮,文本框照旧)。 */
1242
+ const rowEntry = pickerModeOf(picker) === "none" ? null : {
1243
+ mode: pickerModeOf(picker),
1244
+ onOpen: onOpenRow
1245
+ };
547
1246
  const surface = state.kind === "ready" ? state.surface : null;
548
1247
  const dirty = surface !== null && CONFIG_ITEMS.some((i) => (draft[i.key] ?? "") !== (toDraft(surface.values, surface)[i.key] ?? ""));
549
1248
  /** 写完(保存/重置)之后重新读一份整面:写回执是 `{path, values}`、重置回执是 `{path, backupPath}`,
@@ -605,9 +1304,9 @@ window.__ModuleLoader__.load({
605
1304
  value: draft[item.key] ?? "",
606
1305
  disabled: busy,
607
1306
  onChange,
608
- onBrowse
1307
+ browser: rowEntry
609
1308
  });
610
- return react.createElement("div", { style: S.card }, head, react.createElement("div", { style: S.rows }, common.map(renderRow)), react.createElement("details", { style: S.adv }, react.createElement("summary", { style: S.advSummary }, ADVANCED_GROUP_TITLE), react.createElement("div", { style: S.muted }, ADVANCED_GROUP_NOTE), advanced.map(renderRow)), react.createElement("div", { style: S.bar }, react.createElement("button", {
1309
+ return react.createElement("div", { style: S.card }, head, react.createElement("div", { style: S.rows }, common.map(renderRow)), react.createElement("details", { style: S.advanced }, react.createElement("summary", { style: S.summary }, ADVANCED_GROUP_TITLE), react.createElement("div", { style: S.muted }, ADVANCED_GROUP_NOTE), advanced.map(renderRow)), react.createElement("div", { style: S.bar }, react.createElement("button", {
611
1310
  style: dirty ? S.btnPrimary : S.btn,
612
1311
  type: "button",
613
1312
  disabled: busy || !dirty,
@@ -622,7 +1321,28 @@ window.__ModuleLoader__.load({
622
1321
  type: "button",
623
1322
  disabled: busy,
624
1323
  onClick: () => void load()
625
- }, "重新读取")), picking ? react.createElement("div", { style: S.muted }, "已唤起系统文件夹对话框:选中后自动填上,取消则不动。") : null, notice !== null ? react.createElement("div", { style: S.okText }, notice) : null, error !== null ? react.createElement("div", { style: S.error }, error) : null);
1324
+ }, "重新读取")), picking ? react.createElement("div", { style: S.muted }, "已唤起系统文件夹对话框:选中后自动填上,取消则不动。") : null, browseRow !== null ? react.createElement(DirectoryBrowserFromRow, {
1325
+ open: true,
1326
+ row: browseRow,
1327
+ labels: {
1328
+ title: "选择文件夹",
1329
+ close: "关闭",
1330
+ up: "上一级",
1331
+ pathPlaceholder: "直接填绝对路径,回车即进入",
1332
+ go: "转到",
1333
+ showHidden: (n) => "显示隐藏目录(" + n + ")",
1334
+ empty: "这个目录里没有子目录。",
1335
+ loading: "正在读取…",
1336
+ newFolder: "新建文件夹",
1337
+ createConfirm: "创建",
1338
+ createCancel: "取消",
1339
+ select: "选",
1340
+ selected: "已选",
1341
+ open: "选定这个目录",
1342
+ cancel: "取消",
1343
+ willPick: "将选定:"
1344
+ }
1345
+ }) : null, notice !== null ? react.createElement("div", { style: S.okText }, notice) : null, error !== null ? react.createElement("div", { style: S.error }, error) : null);
626
1346
  }
627
1347
  function apply(ctx) {
628
1348
  const getCall = () => ctx.connection?.rpc?.call ?? null;
@@ -635,19 +1355,22 @@ window.__ModuleLoader__.load({
635
1355
  channel: RPC_CHANNEL
636
1356
  }, () => react.createElement(BillConfig, {
637
1357
  getCall,
638
- getPicker
1358
+ pickerSource: getPicker
639
1359
  })));
640
1360
  }
641
1361
  //#endregion
642
1362
  exports.Row = Row;
643
1363
  exports.apply = apply;
644
1364
  exports.createBrowseHandler = createBrowseHandler;
1365
+ exports.directoryEntryMode = directoryEntryMode;
645
1366
  exports.fetchConfigSurface = fetchConfigSurface;
646
1367
  exports.fromDraft = fromDraft;
647
1368
  exports.humanizeConfigFailure = humanizeConfigFailure;
648
1369
  exports.inject = inject;
649
1370
  exports.isDirectoryPicker = isDirectoryPicker;
1371
+ exports.openRowBrowser = openRowBrowser;
650
1372
  exports.pickDirectory = pickDirectory;
1373
+ exports.pickerModeOf = pickerModeOf;
651
1374
  exports.readPickAnswer = readPickAnswer;
652
1375
  exports.resetConfigSurface = resetConfigSurface;
653
1376
  exports.resolveDirectoryPicker = resolveDirectoryPicker;