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