@loomcycle/explorer 0.12.0 → 0.14.0

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/index.js CHANGED
@@ -37,11 +37,59 @@ function y(e, t) {
37
37
  return n === "" || e.some((e) => e.toLowerCase() === n.toLowerCase()) ? e : [n, ...e];
38
38
  }
39
39
  //#endregion
40
+ //#region src/lib/transfer.ts
41
+ function b(e) {
42
+ let t = {
43
+ op: e.op === "copy" ? "copy_documents" : "move_documents",
44
+ scope: e.scope,
45
+ to_scope: e.toScope,
46
+ dry_run: e.dryRun
47
+ };
48
+ e.documentId && (t.document_ids = [e.documentId]), e.underPath && (t.under_path = e.underPath);
49
+ let n = w(e.from), r = w(e.to);
50
+ return n && r && n !== r && (t.path_map = { [n]: r }), e.op === "move" && (e.dropDangling && (t.dangling = "drop"), e.dryRun || (t.expect_count = e.expectCount ?? 0)), t;
51
+ }
52
+ function x(e) {
53
+ let t = e.to.trim();
54
+ return t.startsWith("/") ? e.op === "move" && e.toScope === e.scope ? "a move goes to another scope; to rename within this one, use rename / move" : e.op === "copy" && e.toScope === e.scope && w(t) === w(e.from) ? "a copy into the same scope needs a new path" : null : "the new path must start with /";
55
+ }
56
+ function S(e, t) {
57
+ let n = t.counts ?? {}, r = n.documents ?? 0, i = e === "copy" ? "copied" : "moved", a = [], o = `${n.chunks ?? 0} parts, ${n.revisions ?? 0} revisions, ${n.statements ?? 0} relations, ${n.assets ?? 0} images`;
58
+ if (t.dry_run) a.push(`${r} ${T(r, "document")} would be ${i}: ${o}.`), t.to_finish?.length && a.push(`${t.to_finish.length} ${T(t.to_finish.length, "document")} left by an earlier interrupted move will be finished.`);
59
+ else if (e === "move") {
60
+ let e = t.moved?.length ?? 0;
61
+ a.push(`${e} ${T(e, "document")} moved: ${o}.`);
62
+ } else a.push(`${r} ${T(r, "document")} copied: ${o}.`);
63
+ let s = t.refused_count ?? t.refused?.length ?? 0;
64
+ if (s > 0) {
65
+ a.push(`${s} ${T(s, "document")} refused:`);
66
+ for (let e of t.refused ?? []) a.push(` ${e.document_id}: ${e.code}${e.detail ? ` — ${e.detail}` : ""}`);
67
+ }
68
+ if (t.dangling_count > 0) {
69
+ e === "copy" ? a.push(`${t.dangling_count} ${T(t.dangling_count, "relation")} to documents outside the set stay behind.`) : t.dropped === void 0 ? t.blocked_by === "dangling_relations" ? a.push(`${t.dangling_count} ${T(t.dangling_count, "relation")} join these documents to ones outside the set. A relation cannot span two scopes: include the other documents, or drop these relations.`) : a.push(`${t.dangling_count} ${T(t.dangling_count, "relation")} to documents outside the set will be dropped.`) : a.push(`${t.dropped} ${T(t.dropped, "relation")} to documents outside the set were dropped.`);
70
+ for (let e of t.dangling ?? []) a.push(` ${e.kind}: ${e.from} → ${e.to} (outside: ${e.outside})`);
71
+ }
72
+ for (let e of t.unfinished ?? []) a.push(`not finished: ${e.document_id}: ${e.code}${e.detail ? ` — ${e.detail}` : ""}. Run the move again.`);
73
+ for (let e of t.name_failures ?? []) a.push(`no name ${e.path} for ${e.document_id}: ${e.error}`);
74
+ return t.body_failures && a.push(`${t.body_failures} ${T(t.body_failures, "body", "bodies")} could not be written.`), t.statements_failed && a.push(`${t.statements_failed} ${T(t.statements_failed, "relation")} could not be written${t.statement_error ? `: ${t.statement_error}` : ""}.`), a;
75
+ }
76
+ function C(e, t, n) {
77
+ return e === "move" && t.dangling_count > 0 && !n || (t.counts?.documents ?? 0) === 0 && !(t.to_finish?.length ?? 0);
78
+ }
79
+ function w(e) {
80
+ let t = e.trim(), n = t.length;
81
+ for (; n > 1 && t[n - 1] === "/";) n--;
82
+ return t.slice(0, n);
83
+ }
84
+ function T(e, t, n = t + "s") {
85
+ return e === 1 ? t : n;
86
+ }
87
+ //#endregion
40
88
  //#region src/lib/dataLayer.tsx
41
- var b = 4, x = 5e3;
42
- function S(e, t, n) {
89
+ var E = 4, D = 5e3;
90
+ function O(e, t, n) {
43
91
  return {
44
- ...C(e, n),
92
+ ...k(e, n),
45
93
  pathLs: (t, n, r, i, a) => e.path({
46
94
  op: "ls",
47
95
  path: t,
@@ -60,14 +108,14 @@ function S(e, t, n) {
60
108
  }),
61
109
  documentPath: async (t, n, r) => {
62
110
  let i;
63
- for (let a = 0; a < b; a++) {
111
+ for (let a = 0; a < E; a++) {
64
112
  let a = await e.path({
65
113
  op: "ls",
66
114
  path: "/",
67
115
  scope: n,
68
116
  recursive: !0,
69
117
  kind_filter: "document",
70
- limit: x,
118
+ limit: D,
71
119
  ...i ? { cursor: i } : {}
72
120
  }, r), o = (a.entries ?? []).find((e) => e.resource_ref?.document_id === t);
73
121
  if (o) return o.full_path;
@@ -102,6 +150,7 @@ function S(e, t, n) {
102
150
  id: t,
103
151
  scope: n
104
152
  }, r),
153
+ documentsTransfer: (t, n) => e.document(b(t), n),
105
154
  documentGet: (t, n, r) => e.document({
106
155
  op: "get_document",
107
156
  id: t,
@@ -261,7 +310,7 @@ function S(e, t, n) {
261
310
  } } : {}
262
311
  };
263
312
  }
264
- function C(e, t) {
313
+ function k(e, t) {
265
314
  let n = e, r = (e) => e?.tenant ? `?tenant=${encodeURIComponent(e.tenant)}` : "", i = {};
266
315
  typeof n.ruleStatements == "function" ? i.documentRuleStatements = (e, t) => n.ruleStatements(e.action, e.ids ? { ids: e.ids } : { filter: e.filter }, {
267
316
  reason: e.reason,
@@ -286,35 +335,35 @@ function C(e, t) {
286
335
  });
287
336
  }), i;
288
337
  }
289
- var w = e(null);
290
- function T({ value: e, children: t }) {
291
- return /* @__PURE__ */ l(w.Provider, {
338
+ var A = e(null);
339
+ function j({ value: e, children: t }) {
340
+ return /* @__PURE__ */ l(A.Provider, {
292
341
  value: e,
293
342
  children: t
294
343
  });
295
344
  }
296
- function ee() {
297
- let e = n(w);
345
+ function M() {
346
+ let e = n(A);
298
347
  if (!e) throw Error("useExplorerData must be used within <PathExplorer> or <DocumentViewer> (no ExplorerDataLayer in context)");
299
348
  return e;
300
349
  }
301
- var E = 5e3;
302
- function D(e) {
350
+ var N = 5e3;
351
+ function P(e) {
303
352
  return e === "" ? "/" : e;
304
353
  }
305
- function O(e) {
354
+ function F(e) {
306
355
  let t = e.lastIndexOf("/");
307
356
  return t <= 0 ? "" : e.slice(0, t);
308
357
  }
309
- function k(e) {
358
+ function ee(e) {
310
359
  let t = [""], n = e.split("/").filter(Boolean), r = "";
311
360
  for (let e = 0; e < n.length - 1; e++) r = `${r}/${n[e]}`, t.push(r);
312
361
  return t;
313
362
  }
314
- function A(e) {
363
+ function te(e) {
315
364
  return e instanceof Error ? e.message : String(e);
316
365
  }
317
- function j(e, t) {
366
+ function ne(e, t) {
318
367
  return {
319
368
  entries: [...t, ...e.entries ?? []],
320
369
  nextCursor: e.next_cursor || void 0,
@@ -322,7 +371,7 @@ function j(e, t) {
322
371
  loading: !1
323
372
  };
324
373
  }
325
- var te = class {
374
+ var re = class {
326
375
  data;
327
376
  scope;
328
377
  browse;
@@ -356,7 +405,7 @@ var te = class {
356
405
  }
357
406
  reload(e) {
358
407
  let t = this.dirs.get(e), n = t?.entries.length ?? 0, r = t?.loaded && !t.nextCursor ? n + this.pageLimit : n;
359
- return this.fetchFirst(e, Math.min(E, Math.max(this.pageLimit, r)));
408
+ return this.fetchFirst(e, Math.min(N, Math.max(this.pageLimit, r)));
360
409
  }
361
410
  fetchFirst(e, t) {
362
411
  let n = (this.epoch.get(e) ?? 0) + 1;
@@ -368,15 +417,15 @@ var te = class {
368
417
  loaded: r?.loaded ?? !1,
369
418
  loading: !0
370
419
  });
371
- let i = this.data.pathLs(D(e), this.scope, !1, this.browse, { limit: t }).then((t) => {
372
- this.epoch.get(e) === n && this.set(e, j(t, []));
420
+ let i = this.data.pathLs(P(e), this.scope, !1, this.browse, { limit: t }).then((t) => {
421
+ this.epoch.get(e) === n && this.set(e, ne(t, []));
373
422
  }, (t) => {
374
423
  throw this.epoch.get(e) === n && this.set(e, {
375
424
  entries: r?.entries ?? [],
376
425
  nextCursor: r?.nextCursor,
377
426
  loaded: r?.loaded ?? !1,
378
427
  loading: !1,
379
- error: A(t)
428
+ error: te(t)
380
429
  }), t;
381
430
  });
382
431
  return this.track(e, i);
@@ -392,16 +441,16 @@ var te = class {
392
441
  loading: !0,
393
442
  error: void 0
394
443
  });
395
- let i = this.data.pathLs(D(e), this.scope, !1, this.browse, {
444
+ let i = this.data.pathLs(P(e), this.scope, !1, this.browse, {
396
445
  limit: this.pageLimit,
397
446
  cursor: n.nextCursor
398
447
  }).then((t) => {
399
- this.epoch.get(e) === r && this.set(e, j(t, n.entries));
448
+ this.epoch.get(e) === r && this.set(e, ne(t, n.entries));
400
449
  }, (t) => {
401
450
  throw this.epoch.get(e) === r && this.set(e, {
402
451
  ...n,
403
452
  loading: !1,
404
- error: A(t)
453
+ error: te(t)
405
454
  }), t;
406
455
  });
407
456
  return this.track(e, i);
@@ -427,7 +476,7 @@ var te = class {
427
476
  for (let t of [...this.dirs.keys()]) (t === e || t.startsWith(`${e}/`)) && (this.dirs.delete(t), this.epoch.set(t, (this.epoch.get(t) ?? 0) + 1), this.inflight.delete(t));
428
477
  this.publish();
429
478
  }
430
- let n = k(e).filter((e) => this.dirs.has(e));
479
+ let n = ee(e).filter((e) => this.dirs.has(e));
431
480
  await Promise.all(n.map((e) => this.reload(e)));
432
481
  }
433
482
  async refresh(e) {
@@ -439,11 +488,11 @@ var te = class {
439
488
  await Promise.all(n.map((e) => this.reload(e)));
440
489
  }
441
490
  };
442
- async function ne(e, t, n, r) {
491
+ async function ie(e, t, n, r) {
443
492
  let i = [], a;
444
493
  for (;;) {
445
- let o = await e.pathLs(D(t), n, !0, r, {
446
- limit: E,
494
+ let o = await e.pathLs(P(t), n, !0, r, {
495
+ limit: N,
447
496
  cursor: a
448
497
  });
449
498
  i.push(...o.entries ?? []);
@@ -452,7 +501,7 @@ async function ne(e, t, n, r) {
452
501
  a = s;
453
502
  }
454
503
  }
455
- function re(e) {
504
+ function ae(e) {
456
505
  let t = [];
457
506
  for (let n of e) {
458
507
  if (n.kind !== "document") continue;
@@ -463,7 +512,7 @@ function re(e) {
463
512
  }
464
513
  //#endregion
465
514
  //#region src/lib/createClient.ts
466
- function ie(e) {
515
+ function I(e) {
467
516
  let t = e.fetch;
468
517
  return new d({
469
518
  baseUrl: e.baseUrl,
@@ -471,21 +520,21 @@ function ie(e) {
471
520
  fetch: (e, n) => t ? t(e, n) : fetch(e, n)
472
521
  });
473
522
  }
474
- function M(e) {
523
+ function L(e) {
475
524
  let t = e.fetch, n = (e, n) => t ? t(e, n) : fetch(e, n);
476
525
  return (t) => {
477
526
  let r = {};
478
527
  return e.token && (r.Authorization = `Bearer ${e.token}`), n(e.baseUrl + t, { headers: r });
479
528
  };
480
529
  }
481
- var ae = class extends Error {
530
+ var oe = class extends Error {
482
531
  status;
483
532
  code;
484
533
  constructor(e, t, n) {
485
534
  super(e), this.name = "RequestError", this.status = t, this.code = n;
486
535
  }
487
536
  };
488
- function oe(e) {
537
+ function se(e) {
489
538
  let t = e.fetch, n = (e, n) => t ? t(e, n) : fetch(e, n);
490
539
  return async (t, r) => {
491
540
  let i = {
@@ -503,16 +552,16 @@ function oe(e) {
503
552
  } catch {}
504
553
  if (!a.ok) {
505
554
  let e = s && typeof s == "object" ? s : {};
506
- throw new ae(typeof e.error == "string" && e.error ? e.error : `${a.status} ${a.statusText}`.trim(), a.status, typeof e.code == "string" ? e.code : void 0);
555
+ throw new oe(typeof e.error == "string" && e.error ? e.error : `${a.status} ${a.statusText}`.trim(), a.status, typeof e.code == "string" ? e.code : void 0);
507
556
  }
508
557
  return s;
509
558
  };
510
559
  }
511
560
  //#endregion
512
561
  //#region src/components/ExplorerRoot.tsx
513
- function N(e) {
562
+ function R(e) {
514
563
  let { dataLayer: t, client: n, connection: r } = e;
515
- return i(() => t || (n ? S(n) : r ? S(ie(r), M(r), oe(r)) : null), [
564
+ return i(() => t || (n ? O(n) : r ? O(I(r), L(r), se(r)) : null), [
516
565
  t,
517
566
  n,
518
567
  r?.baseUrl,
@@ -520,12 +569,12 @@ function N(e) {
520
569
  r?.fetch
521
570
  ]);
522
571
  }
523
- function P({ theme: e, dataLayer: t, children: n }) {
572
+ function z({ theme: e, dataLayer: t, children: n }) {
524
573
  let r = e ? { "data-theme": e } : {};
525
574
  return t ? /* @__PURE__ */ l("div", {
526
575
  className: "loomcycle-explorer",
527
576
  ...r,
528
- children: /* @__PURE__ */ l(T, {
577
+ children: /* @__PURE__ */ l(j, {
529
578
  value: t,
530
579
  children: n
531
580
  })
@@ -549,32 +598,32 @@ function P({ theme: e, dataLayer: t, children: n }) {
549
598
  }
550
599
  //#endregion
551
600
  //#region src/lib/docTrail.ts
552
- function se(e, t, n) {
601
+ function ce(e, t, n) {
553
602
  let r = e[e.length - 1];
554
603
  return [...r && r.documentId === t.documentId ? [...e.slice(0, -1), {
555
604
  ...r,
556
- ...F(t)
605
+ ...B(t)
557
606
  }] : [...e, t], n];
558
607
  }
559
- function ce(e, t) {
608
+ function le(e, t) {
560
609
  return t < 0 || t >= e.length - 1 ? e : e.slice(0, t + 1);
561
610
  }
562
- function le(e, t, n) {
611
+ function ue(e, t, n) {
563
612
  let r = e[e.length - 1];
564
613
  if (!r || r.documentId !== t) return e;
565
614
  let i = {
566
615
  ...r,
567
- ...F(n)
616
+ ...B(n)
568
617
  };
569
618
  return i.title === r.title && i.path === r.path ? e : [...e.slice(0, -1), i];
570
619
  }
571
- function F(e) {
620
+ function B(e) {
572
621
  return Object.fromEntries(Object.entries(e).filter(([, e]) => e !== void 0));
573
622
  }
574
- function ue(e) {
623
+ function de(e) {
575
624
  return e.title ? e.title : e.path ? e.path.slice(e.path.lastIndexOf("/") + 1) || e.path : e.documentId.slice(0, 8);
576
625
  }
577
- function I(e, t = 4) {
626
+ function V(e, t = 4) {
578
627
  let n = Array.from({ length: e }, (e, t) => ({
579
628
  kind: "crumb",
580
629
  index: t
@@ -590,24 +639,24 @@ function I(e, t = 4) {
590
639
  ...n.slice(e - r)
591
640
  ];
592
641
  }
593
- function de(e, t) {
642
+ function fe(e, t) {
594
643
  for (let n of e.values()) {
595
- let e = n.entries.find((e) => L(e) === t);
644
+ let e = n.entries.find((e) => H(e) === t);
596
645
  if (e) return e.full_path;
597
646
  }
598
647
  }
599
- function L(e) {
648
+ function H(e) {
600
649
  if (e.kind === "document") return e.resource_ref?.document_id || void 0;
601
650
  }
602
- function R(e, t) {
651
+ function U(e, t) {
603
652
  return t && e.some((e) => e.id === t) ? t : e.find((e) => !e.parent_id)?.id;
604
653
  }
605
654
  //#endregion
606
655
  //#region src/components/DocTrail.tsx
607
- function fe({ trail: e, onJump: t }) {
656
+ function pe({ trail: e, onJump: t }) {
608
657
  let [n, r] = o(!1);
609
658
  if (e.length < 2) return null;
610
- let i = e.length - 1, a = e[i - 1], s = I(e.length, n ? e.length : void 0);
659
+ let i = e.length - 1, a = e[i - 1], s = V(e.length, n ? e.length : void 0);
611
660
  return /* @__PURE__ */ u("nav", {
612
661
  className: "doc-trail",
613
662
  "aria-label": "Documents you came through",
@@ -615,7 +664,7 @@ function fe({ trail: e, onJump: t }) {
615
664
  type: "button",
616
665
  className: "doc-trail-back",
617
666
  onClick: () => t(i - 1),
618
- title: `Back to ${ue(a)}`,
667
+ title: `Back to ${de(a)}`,
619
668
  children: "← Back"
620
669
  }), /* @__PURE__ */ l("ol", {
621
670
  className: "doc-trail-list",
@@ -625,7 +674,7 @@ function fe({ trail: e, onJump: t }) {
625
674
  type: "button",
626
675
  className: "doc-trail-gap",
627
676
  onClick: () => r(!0),
628
- title: `Show ${n.hidden.length} more: ${n.hidden.map((t) => ue(e[t])).join(" › ")}`,
677
+ title: `Show ${n.hidden.length} more: ${n.hidden.map((t) => de(e[t])).join(" › ")}`,
629
678
  "aria-label": `Show ${n.hidden.length} hidden documents`,
630
679
  children: "…"
631
680
  })
@@ -634,8 +683,8 @@ function fe({ trail: e, onJump: t }) {
634
683
  children: /* @__PURE__ */ l("span", {
635
684
  className: "doc-trail-current",
636
685
  "aria-current": "page",
637
- title: ue(e[i]),
638
- children: ue(e[i])
686
+ title: de(e[i]),
687
+ children: de(e[i])
639
688
  })
640
689
  }, n.index) : /* @__PURE__ */ l("li", {
641
690
  className: "doc-trail-item",
@@ -643,17 +692,175 @@ function fe({ trail: e, onJump: t }) {
643
692
  type: "button",
644
693
  className: "doc-trail-crumb",
645
694
  onClick: () => t(n.index),
646
- title: ue(e[n.index]),
647
- children: ue(e[n.index])
695
+ title: de(e[n.index]),
696
+ children: de(e[n.index])
648
697
  })
649
698
  }, n.index))
650
699
  })]
651
700
  });
652
701
  }
653
702
  //#endregion
703
+ //#region src/components/TransferModal.tsx
704
+ function me({ data: e, scope: t, browse: n, documentId: r, underPath: a, fromPath: s, onClose: c, onDone: d }) {
705
+ let [f, p] = o("copy"), [m, h] = o(t === "tenant" ? "user" : "tenant"), [g, _] = o(s), [v, y] = o(!1), [w, T] = o(null), [E, D] = o(null), [O, k] = o(!1), [A, j] = o(null), M = i(() => ({
706
+ op: f,
707
+ scope: t,
708
+ toScope: m,
709
+ documentId: r,
710
+ underPath: a,
711
+ from: s,
712
+ to: g,
713
+ dropDangling: v,
714
+ dryRun: !0
715
+ }), [
716
+ f,
717
+ t,
718
+ m,
719
+ r,
720
+ a,
721
+ s,
722
+ g,
723
+ v
724
+ ]), N = JSON.stringify(b(M)), P = x(M), F = w && w.key === N ? w.res : null, ee = F ? C(f, F, v) : !1, te = F ? f === "move" ? (F.counts?.documents ?? 0) + (F.to_finish?.length ?? 0) : F.counts?.documents ?? 0 : 0, ne = async (t) => {
725
+ if (t.preventDefault(), E) c();
726
+ else if (!P && e.documentsTransfer) {
727
+ k(!0), j(null);
728
+ try {
729
+ if (!F) T({
730
+ key: N,
731
+ res: await e.documentsTransfer(M, n)
732
+ });
733
+ else {
734
+ let t = {
735
+ ...M,
736
+ dryRun: !1,
737
+ expectCount: F.counts?.documents ?? 0
738
+ }, r = await e.documentsTransfer(t, n);
739
+ D(r), d(t, r);
740
+ }
741
+ } catch (e) {
742
+ j(e instanceof Error ? e.message : String(e));
743
+ } finally {
744
+ k(!1);
745
+ }
746
+ }
747
+ }, re = E ? "close" : O ? "working…" : F ? `${f} ${te} document${te === 1 ? "" : "s"}` : "check", ie = E ?? F;
748
+ return /* @__PURE__ */ l("div", {
749
+ className: "modal-overlay",
750
+ onClick: O ? void 0 : c,
751
+ children: /* @__PURE__ */ u("form", {
752
+ className: "modal",
753
+ onClick: (e) => e.stopPropagation(),
754
+ onSubmit: ne,
755
+ children: [
756
+ /* @__PURE__ */ u("div", {
757
+ className: "modal-header sticky-top",
758
+ children: [/* @__PURE__ */ u("h3", { children: [
759
+ "Copy or move the ",
760
+ r ? "document" : "documents under",
761
+ " ",
762
+ s
763
+ ] }), /* @__PURE__ */ u("div", {
764
+ className: "modal-buttons modal-buttons-top",
765
+ children: [!E && /* @__PURE__ */ l("button", {
766
+ type: "button",
767
+ onClick: c,
768
+ disabled: O,
769
+ children: "cancel"
770
+ }), /* @__PURE__ */ l("button", {
771
+ type: "submit",
772
+ className: F && f === "move" && !E ? "danger" : "primary",
773
+ disabled: O || !E && (!!P || ee),
774
+ children: re
775
+ })]
776
+ })]
777
+ }),
778
+ /* @__PURE__ */ u("p", {
779
+ className: "modal-context",
780
+ children: [
781
+ "A copy gets new ids and leaves the source as it is. A move keeps every id and removes the documents from ",
782
+ /* @__PURE__ */ l("code", { children: t }),
783
+ ". Relations between the documents go with them."
784
+ ]
785
+ }),
786
+ /* @__PURE__ */ l("div", {
787
+ className: "paths-nav-switch",
788
+ role: "group",
789
+ "aria-label": "Copy or move",
790
+ children: ["copy", "move"].map((e) => /* @__PURE__ */ l("button", {
791
+ type: "button",
792
+ "aria-pressed": f === e,
793
+ className: f === e ? "active" : void 0,
794
+ disabled: O || !!E,
795
+ onClick: () => p(e),
796
+ children: e
797
+ }, e))
798
+ }),
799
+ /* @__PURE__ */ u("label", {
800
+ className: "path-field",
801
+ children: [/* @__PURE__ */ l("span", { children: "To scope" }), /* @__PURE__ */ u("select", {
802
+ value: m,
803
+ disabled: O || !!E,
804
+ onChange: (e) => h(e.target.value),
805
+ children: [
806
+ /* @__PURE__ */ l("option", {
807
+ value: "user",
808
+ children: "user"
809
+ }),
810
+ /* @__PURE__ */ l("option", {
811
+ value: "agent",
812
+ children: "agent"
813
+ }),
814
+ /* @__PURE__ */ l("option", {
815
+ value: "tenant",
816
+ children: "tenant"
817
+ })
818
+ ]
819
+ })]
820
+ }),
821
+ /* @__PURE__ */ u("label", {
822
+ className: "path-field",
823
+ children: [/* @__PURE__ */ l("span", { children: "New path" }), /* @__PURE__ */ l("input", {
824
+ className: "path-modal-input",
825
+ value: g,
826
+ disabled: O || !!E,
827
+ onChange: (e) => _(e.target.value)
828
+ })]
829
+ }),
830
+ f === "move" && /* @__PURE__ */ l("label", {
831
+ className: "path-field",
832
+ children: /* @__PURE__ */ u("span", { children: [
833
+ /* @__PURE__ */ l("input", {
834
+ type: "checkbox",
835
+ checked: v,
836
+ disabled: O || !!E,
837
+ onChange: (e) => y(e.target.checked)
838
+ }),
839
+ " ",
840
+ "Drop relations to documents outside the set"
841
+ ] })
842
+ }),
843
+ P && /* @__PURE__ */ l("div", {
844
+ className: "modal-err",
845
+ children: P
846
+ }),
847
+ ie && /* @__PURE__ */ l("div", {
848
+ className: "modal-context",
849
+ "aria-live": "polite",
850
+ children: S(f, ie).map((e, t) => e.startsWith(" ") ? /* @__PURE__ */ l("div", { children: /* @__PURE__ */ l("code", { children: e.trim() }) }, t) : /* @__PURE__ */ l("div", { children: e }, t))
851
+ }),
852
+ A && /* @__PURE__ */ l("div", {
853
+ className: "modal-err",
854
+ children: A
855
+ })
856
+ ]
857
+ })
858
+ });
859
+ }
860
+ //#endregion
654
861
  //#region src/components/Splitter.tsx
655
- var z = 6;
656
- function pe({ children: e, defaultLeftWidth: n = 380, minLeftWidth: i = 180, minRightWidth: s = 240, storageKey: c, className: d, hideRight: f = !1 }) {
862
+ var W = 6;
863
+ function he({ children: e, defaultLeftWidth: n = 380, minLeftWidth: i = 180, minRightWidth: s = 240, storageKey: c, className: d, hideRight: f = !1 }) {
657
864
  let p = () => {
658
865
  if (c) {
659
866
  let e = localStorage.getItem(c), t = e ? parseInt(e, 10) : NaN;
@@ -675,7 +882,7 @@ function pe({ children: e, defaultLeftWidth: n = 380, minLeftWidth: i = 180, min
675
882
  e.preventDefault(), b(!0), e.target.setPointerCapture(e.pointerId);
676
883
  }, []), S = t((e) => {
677
884
  if (!y || !v.current) return;
678
- let t = v.current.getBoundingClientRect(), n = e.clientX - t.left, r = t.width - s - z;
885
+ let t = v.current.getBoundingClientRect(), n = e.clientX - t.left, r = t.width - s - W;
679
886
  h(Math.max(i, Math.min(n, r)));
680
887
  }, [
681
888
  y,
@@ -690,7 +897,7 @@ function pe({ children: e, defaultLeftWidth: n = 380, minLeftWidth: i = 180, min
690
897
  return /* @__PURE__ */ u("div", {
691
898
  ref: v,
692
899
  className: `splitter ${d ?? ""} ${y ? "dragging" : ""}`,
693
- style: { gridTemplateColumns: f ? "1fr 0 0" : `min(${m}px, calc(100% - ${s + z}px)) ${z}px 1fr` },
900
+ style: { gridTemplateColumns: f ? "1fr 0 0" : `min(${m}px, calc(100% - ${s + W}px)) ${W}px 1fr` },
694
901
  children: [
695
902
  /* @__PURE__ */ l("div", {
696
903
  className: "splitter-pane splitter-left",
@@ -717,18 +924,18 @@ function pe({ children: e, defaultLeftWidth: n = 380, minLeftWidth: i = 180, min
717
924
  }
718
925
  //#endregion
719
926
  //#region src/lib/imageUpload.ts
720
- var B = [
927
+ var ge = [
721
928
  "image/png",
722
929
  "image/jpeg",
723
930
  "image/gif",
724
931
  "image/webp"
725
932
  ];
726
- function V(e) {
727
- return B.includes(e);
933
+ function G(e) {
934
+ return ge.includes(e);
728
935
  }
729
- function H(e) {
936
+ function _e(e) {
730
937
  return new Promise((t, n) => {
731
- if (!V(e.type)) {
938
+ if (!G(e.type)) {
732
939
  n(/* @__PURE__ */ Error(`unsupported image type "${e.type || "unknown"}" (png, jpeg, gif, webp only)`));
733
940
  return;
734
941
  }
@@ -742,11 +949,11 @@ function H(e) {
742
949
  }, r.readAsDataURL(e);
743
950
  });
744
951
  }
745
- function me(e) {
952
+ function ve(e) {
746
953
  if (!e) return null;
747
954
  for (let t = 0; t < e.length; t++) {
748
955
  let n = e[t];
749
- if (n.kind === "file" && V(n.type)) {
956
+ if (n.kind === "file" && G(n.type)) {
750
957
  let e = n.getAsFile();
751
958
  if (e) return e;
752
959
  }
@@ -755,8 +962,8 @@ function me(e) {
755
962
  }
756
963
  //#endregion
757
964
  //#region src/lib/edgePages.ts
758
- var he = 20;
759
- async function U(e, t, n, r, i = 20) {
965
+ var ye = 20;
966
+ async function be(e, t, n, r, i = 20) {
760
967
  let a = [], o;
761
968
  for (let s = 0; s < i; s++) {
762
969
  let i = await e.documentGetEdges(t, n, r, o ? { after: o } : void 0);
@@ -781,7 +988,7 @@ async function U(e, t, n, r, i = 20) {
781
988
  }
782
989
  //#endregion
783
990
  //#region src/lib/chunkAncestry.ts
784
- function ge(e, t) {
991
+ function xe(e, t) {
785
992
  if (!t) return [];
786
993
  let n = new Map(e.map((e) => [e.id, e])), r = /* @__PURE__ */ new Set([t]), i = [], a = n.get(t)?.parent_id;
787
994
  for (; a && !r.has(a);) {
@@ -793,48 +1000,48 @@ function ge(e, t) {
793
1000
  }
794
1001
  //#endregion
795
1002
  //#region src/lib/statement.ts
796
- var _e = /* @__PURE__ */ new Set(["manual", "wikilink"]), ve = 280;
797
- function ye(e) {
1003
+ var K = /* @__PURE__ */ new Set(["manual", "wikilink"]), Se = 280;
1004
+ function Ce(e) {
798
1005
  return e.status && e.status !== "asserted" ? e.status : void 0;
799
1006
  }
800
- function W(e) {
801
- return e.method && !_e.has(e.method) ? e.method : void 0;
1007
+ function we(e) {
1008
+ return e.method && !K.has(e.method) ? e.method : void 0;
802
1009
  }
803
- function G(e) {
1010
+ function q(e) {
804
1011
  return e.status === "proposed" && !!e.id;
805
1012
  }
806
- function be(e) {
1013
+ function Te(e) {
807
1014
  return new Date(Math.floor(e / 1e6)).toISOString().slice(0, 10);
808
1015
  }
809
- function xe(e) {
810
- let t = e.valid_at == null ? void 0 : be(e.valid_at), n = e.invalid_at == null ? void 0 : be(e.invalid_at);
1016
+ function Ee(e) {
1017
+ let t = e.valid_at == null ? void 0 : Te(e.valid_at), n = e.invalid_at == null ? void 0 : Te(e.invalid_at);
811
1018
  if (t && n) return `valid ${t} → ${n}`;
812
1019
  if (t) return `valid from ${t}`;
813
1020
  if (n) return `valid until ${n}`;
814
1021
  }
815
- function Se(e) {
1022
+ function De(e) {
816
1023
  if (e.judged_at == null) return;
817
- let t = `judged by ${e.judged_by || "a judge"} on ${be(e.judged_at)}`;
1024
+ let t = `judged by ${e.judged_by || "a judge"} on ${Te(e.judged_at)}`;
818
1025
  return e.judge_reason ? `${t}: ${e.judge_reason}` : t;
819
1026
  }
820
- function K(e, t = 3) {
1027
+ function Oe(e, t = 3) {
821
1028
  let n = (e.evidence ?? []).slice(0, t), r = Math.max(e.evidence_count ?? 0, e.evidence?.length ?? 0);
822
1029
  return {
823
1030
  rows: n,
824
1031
  more: Math.max(0, r - n.length)
825
1032
  };
826
1033
  }
827
- function Ce(e, t = ve) {
1034
+ function ke(e, t = Se) {
828
1035
  let n = e.replace(/\s+/g, " ").trim();
829
1036
  return n.length > t ? n.slice(0, t - 1) + "…" : n;
830
1037
  }
831
1038
  //#endregion
832
1039
  //#region src/lib/ruling.ts
833
- var we = 1e3, Te = 3, Ee = 1e3;
834
- function De(e) {
1040
+ var J = 1e3, Ae = 3, je = 1e3;
1041
+ function Me(e) {
835
1042
  return !!e && typeof e == "object" && e.code === "queue_changed";
836
1043
  }
837
- async function Oe(e, t, n = {}) {
1044
+ async function Ne(e, t, n = {}) {
838
1045
  let r = {
839
1046
  action: t.action,
840
1047
  ...t.ids ? { ids: t.ids } : { filter: t.filter ?? {} },
@@ -863,7 +1070,7 @@ async function Oe(e, t, n = {}) {
863
1070
  }
864
1071
  if (s.matched === 0 || !await o(s, "first")) return i;
865
1072
  let c = 0;
866
- for (let t = 0; t < Ee && s.to_rule !== 0; t++) {
1073
+ for (let t = 0; t < je && s.to_rule !== 0; t++) {
867
1074
  let t;
868
1075
  try {
869
1076
  t = await e.rule({
@@ -872,7 +1079,7 @@ async function Oe(e, t, n = {}) {
872
1079
  expect_count: s.matched
873
1080
  });
874
1081
  } catch (e) {
875
- if (!De(e) || c >= 3) return i.error = e, i;
1082
+ if (!Me(e) || c >= 3) return i.error = e, i;
876
1083
  c++;
877
1084
  try {
878
1085
  s = await a();
@@ -900,7 +1107,7 @@ async function Oe(e, t, n = {}) {
900
1107
  }
901
1108
  return i;
902
1109
  }
903
- async function ke(e, t) {
1110
+ async function Y(e, t) {
904
1111
  let n = {
905
1112
  reverted: 0,
906
1113
  changed: 0,
@@ -914,21 +1121,21 @@ async function ke(e, t) {
914
1121
  }
915
1122
  return n;
916
1123
  }
917
- function Ae(e) {
918
- return Math.max(1, Math.ceil(e / we));
1124
+ function Pe(e) {
1125
+ return Math.max(1, Math.ceil(e / J));
919
1126
  }
920
1127
  //#endregion
921
1128
  //#region src/lib/bulkReview.ts
922
- function q(e) {
1129
+ function X(e) {
923
1130
  return e === "tenant" || e === "user" ? e : void 0;
924
1131
  }
925
- function je(e, t) {
926
- return e.documentRuleStatements ? q(t) : void 0;
1132
+ function Fe(e, t) {
1133
+ return e.documentRuleStatements ? X(t) : void 0;
927
1134
  }
928
- function Me(e, t) {
929
- return e.filter((e) => G(e) && !!e.id && e.from_document_id === t);
1135
+ function Ie(e, t) {
1136
+ return e.filter((e) => q(e) && !!e.id && e.from_document_id === t);
930
1137
  }
931
- function Ne(e, t, n, r) {
1138
+ function Le(e, t, n, r) {
932
1139
  return e ? {
933
1140
  proposals: t,
934
1141
  scope: e,
@@ -936,8 +1143,8 @@ function Ne(e, t, n, r) {
936
1143
  onChanged: r
937
1144
  } : void 0;
938
1145
  }
939
- function J(e, t, n) {
940
- return e.documentRuleStatements ? Oe({ rule: (n) => e.documentRuleStatements(n, t.browse) }, {
1146
+ function Re(e, t, n) {
1147
+ return e.documentRuleStatements ? Ne({ rule: (n) => e.documentRuleStatements(n, t.browse) }, {
941
1148
  action: t.action,
942
1149
  ...t.ids && t.ids.length > 0 ? { ids: t.ids } : { filter: { from_document_id: t.documentId } },
943
1150
  ...t.reason ? { reason: t.reason } : {},
@@ -945,13 +1152,13 @@ function J(e, t, n) {
945
1152
  ...t.scope === "user" && t.browse?.scopeId ? { scopeId: t.browse.scopeId } : {}
946
1153
  }, n) : Promise.reject(/* @__PURE__ */ Error("this data layer cannot rule in bulk"));
947
1154
  }
948
- function Pe(e, t) {
1155
+ function ze(e, t) {
949
1156
  let n = (e) => e.toLocaleString("en-US"), r = [`${e === "accept" ? "Accepted" : "Rejected"} ${n(t.ruled)} statement${t.ruled === 1 ? "" : "s"}`];
950
1157
  return t.failed > 0 && r.push(`${n(t.failed)} did not take the ruling`), t.skipped > 0 && r.push(`${n(t.skipped)} skipped: not yours to rule`), r.join("; ") + ".";
951
1158
  }
952
1159
  //#endregion
953
1160
  //#region src/lib/colorScheme.ts
954
- var Y = {
1161
+ var Z = {
955
1162
  "doc.rfc.draft": "#c99a3a",
956
1163
  "doc.rfc.review": "#6a7bd6",
957
1164
  "doc.rfc.confirmed": "#3a9ad6",
@@ -970,36 +1177,49 @@ var Y = {
970
1177
  "chunk.backlog": "#8a8f98",
971
1178
  "chunk.implementation": "#d1863a",
972
1179
  "chunk.merged": "#3aa06a"
973
- }, Fe = .16;
974
- function Ie(e) {
975
- return e && Object.keys(e).length > 0 ? e : Y;
1180
+ }, Q = .16;
1181
+ function Be(e) {
1182
+ return e && Object.keys(e).length > 0 ? e : Z;
976
1183
  }
977
- function Le(e, t, n) {
1184
+ function Ve(e, t, n) {
978
1185
  let r = e ?? "", i = t ?? "";
979
1186
  if (r && i && n[`doc.${r}.${i}`]) return n[`doc.${r}.${i}`];
980
1187
  if (r && n[`doc.${r}`]) return n[`doc.${r}`];
981
1188
  }
982
- function X(e, t) {
1189
+ function He(e, t) {
983
1190
  let n = e ?? "";
984
1191
  return n ? t[`chunk.${n}`] : void 0;
985
1192
  }
986
- function Z(e) {
987
- let t = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());
988
- if (!t) return;
989
- let n = t[1];
990
- return n.length === 3 && (n = n[0] + n[0] + n[1] + n[1] + n[2] + n[2]), `rgba(${parseInt(n.slice(0, 2), 16)}, ${parseInt(n.slice(2, 4), 16)}, ${parseInt(n.slice(4, 6), 16)}, ${Fe})`;
1193
+ function Ue(e) {
1194
+ let t = String(e["chunk.inherit"] ?? "").trim().toLowerCase();
1195
+ return t !== "false" && t !== "none" && t !== "off" && t !== "0";
1196
+ }
1197
+ function We(e, t = Q) {
1198
+ let n = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());
1199
+ if (!n) return;
1200
+ let r = n[1];
1201
+ return r.length === 3 && (r = r[0] + r[0] + r[1] + r[1] + r[2] + r[2]), `rgba(${parseInt(r.slice(0, 2), 16)}, ${parseInt(r.slice(2, 4), 16)}, ${parseInt(r.slice(4, 6), 16)}, ${t})`;
991
1202
  }
992
- function Re(e) {
1203
+ function Ge(e) {
993
1204
  if (!e) return;
994
- let t = Z(e);
1205
+ let t = We(e);
995
1206
  if (t) return {
996
1207
  background: t,
997
1208
  borderLeft: `3px solid ${e}`
998
1209
  };
999
1210
  }
1211
+ function Ke(e) {
1212
+ if (!e) return;
1213
+ let t = We(e, Q / 2);
1214
+ return t ? { background: t } : void 0;
1215
+ }
1216
+ function qe(e) {
1217
+ let { status: t, isRoot: n, documentColor: r, scheme: i } = e;
1218
+ if (i) return n ? Ge(r) ?? Ge(He(t, i)) : Ge(He(t, i)) ?? (Ue(i) ? Ke(r) : void 0);
1219
+ }
1000
1220
  //#endregion
1001
1221
  //#region src/lib/clipboard.ts
1002
- async function Q(e) {
1222
+ async function Je(e) {
1003
1223
  try {
1004
1224
  return typeof navigator > "u" || !navigator.clipboard ? !1 : (await navigator.clipboard.writeText(e), !0);
1005
1225
  } catch {
@@ -1008,10 +1228,10 @@ async function Q(e) {
1008
1228
  }
1009
1229
  //#endregion
1010
1230
  //#region src/components/IdCopy.tsx
1011
- function ze({ value: e, label: t, compact: n, title: r }) {
1231
+ function $({ value: e, label: t, compact: n, title: r }) {
1012
1232
  let [i, a] = o("idle"), s = async (t) => {
1013
1233
  t.stopPropagation(), t.preventDefault();
1014
- let n = await Q(e);
1234
+ let n = await Je(e);
1015
1235
  a(n ? "copied" : "error"), window.setTimeout(() => a("idle"), n ? 1200 : 1500);
1016
1236
  }, c = i === "copied" ? "✓" : i === "error" ? "✗" : "⎘", d = r ?? `Copy ${t ?? "id"}: ${e}`, f = /* @__PURE__ */ l("button", {
1017
1237
  type: "button",
@@ -1039,7 +1259,7 @@ function ze({ value: e, label: t, compact: n, title: r }) {
1039
1259
  }
1040
1260
  //#endregion
1041
1261
  //#region src/components/DocumentChunkTree.tsx
1042
- function Be(e) {
1262
+ function Ye(e) {
1043
1263
  let t = /* @__PURE__ */ new Map();
1044
1264
  e.forEach((e) => t.set(e.id, {
1045
1265
  row: e,
@@ -1055,50 +1275,52 @@ function Be(e) {
1055
1275
  };
1056
1276
  return r(n), n;
1057
1277
  }
1058
- function Ve(e) {
1278
+ function Xe(e) {
1059
1279
  return e === "image" ? "🖼" : e === "mermaid" ? "📊" : "";
1060
1280
  }
1061
- function He(e, t) {
1281
+ function Ze(e, t) {
1062
1282
  for (let n of e) {
1063
1283
  if (n.row.id === t) return n;
1064
- let e = He(n.children, t);
1284
+ let e = Ze(n.children, t);
1065
1285
  if (e) return e;
1066
1286
  }
1067
1287
  }
1068
- function $({ tree: e, selectedId: n, onSelect: i, colorEnabled: a, scheme: s, linkedIds: c }) {
1069
- let [u, d] = o(() => /* @__PURE__ */ new Map()), f = t((e) => {
1070
- d((t) => {
1288
+ function Qe({ tree: e, selectedId: n, onSelect: i, colorEnabled: a, scheme: s, documentColor: c, linkedIds: u }) {
1289
+ let [d, f] = o(() => /* @__PURE__ */ new Map()), p = t((e) => {
1290
+ f((t) => {
1071
1291
  let n = new Map(t);
1072
1292
  return n.set(e, t.get(e) === !1), n;
1073
1293
  });
1074
1294
  }, []);
1075
1295
  r(() => {
1076
1296
  if (!n) return;
1077
- let t = Ue(e, n);
1078
- t.length !== 0 && d((e) => {
1297
+ let t = $e(e, n);
1298
+ t.length !== 0 && f((e) => {
1079
1299
  let n = !1, r = new Map(e);
1080
1300
  for (let e of t) r.get(e) === !1 && (r.set(e, !0), n = !0);
1081
1301
  return n ? r : e;
1082
1302
  });
1083
1303
  }, [e, n]);
1084
- let p = a ? Ie(s) : null;
1304
+ let m = a ? Be(s) : null;
1085
1305
  return e.length === 0 ? /* @__PURE__ */ l("div", {
1086
1306
  className: "empty",
1087
1307
  children: /* @__PURE__ */ l("p", { children: "No chunks." })
1088
1308
  }) : /* @__PURE__ */ l("ul", {
1089
1309
  className: "tree chunk-tree",
1090
- children: e.map((e) => /* @__PURE__ */ l(We, {
1310
+ children: e.map((e) => /* @__PURE__ */ l(et, {
1091
1311
  node: e,
1092
- expanded: u,
1093
- toggle: f,
1312
+ expanded: d,
1313
+ toggle: p,
1094
1314
  selectedId: n,
1095
1315
  onSelect: i,
1096
- tintScheme: p,
1097
- linkedIds: c
1316
+ tintScheme: m,
1317
+ documentColor: c,
1318
+ isRoot: !0,
1319
+ linkedIds: u
1098
1320
  }, e.row.id))
1099
1321
  });
1100
1322
  }
1101
- function Ue(e, t) {
1323
+ function $e(e, t) {
1102
1324
  let n = [], r = (e, i) => {
1103
1325
  for (let a of e) {
1104
1326
  if (a.row.id === t) return n.push(...i), !0;
@@ -1108,23 +1330,28 @@ function Ue(e, t) {
1108
1330
  };
1109
1331
  return r(e, []), n;
1110
1332
  }
1111
- function We({ node: e, expanded: t, toggle: n, selectedId: r, onSelect: i, tintScheme: a, linkedIds: o }) {
1112
- let s = e.children.length > 0, c = t.get(e.row.id) !== !1, d = r === e.row.id, f = a ? Re(X(e.row.status, a)) : void 0, p = o?.has(e.row.id);
1333
+ function et({ node: e, expanded: t, toggle: n, selectedId: r, onSelect: i, tintScheme: a, documentColor: o, isRoot: s = !1, linkedIds: c }) {
1334
+ let d = e.children.length > 0, f = t.get(e.row.id) !== !1, p = r === e.row.id, m = qe({
1335
+ status: e.row.status,
1336
+ isRoot: s,
1337
+ documentColor: o,
1338
+ scheme: a
1339
+ }), h = c?.has(e.row.id);
1113
1340
  return /* @__PURE__ */ u("li", {
1114
- className: `node chunk-node ${d ? "selected" : ""}`,
1341
+ className: `node chunk-node ${p ? "selected" : ""}`,
1115
1342
  children: [/* @__PURE__ */ u("div", {
1116
1343
  className: "row chunk-row",
1117
- style: f,
1344
+ style: m,
1118
1345
  children: [
1119
1346
  /* @__PURE__ */ l("button", {
1120
1347
  type: "button",
1121
1348
  className: "tree-caret",
1122
- "aria-label": c ? "collapse" : "expand",
1123
- disabled: !s,
1349
+ "aria-label": f ? "collapse" : "expand",
1350
+ disabled: !d,
1124
1351
  onClick: (t) => {
1125
- t.stopPropagation(), s && n(e.row.id);
1352
+ t.stopPropagation(), d && n(e.row.id);
1126
1353
  },
1127
- children: s ? c ? "▼" : "▶" : "·"
1354
+ children: d ? f ? "▼" : "▶" : "·"
1128
1355
  }),
1129
1356
  /* @__PURE__ */ u("button", {
1130
1357
  type: "button",
@@ -1132,10 +1359,10 @@ function We({ node: e, expanded: t, toggle: n, selectedId: r, onSelect: i, tintS
1132
1359
  onClick: () => i(e),
1133
1360
  title: e.row.title,
1134
1361
  children: [
1135
- Ve(e.row.type) && /* @__PURE__ */ l("span", {
1362
+ Xe(e.row.type) && /* @__PURE__ */ l("span", {
1136
1363
  className: "chunk-type-icon",
1137
1364
  "aria-hidden": !0,
1138
- children: Ve(e.row.type)
1365
+ children: Xe(e.row.type)
1139
1366
  }),
1140
1367
  /* @__PURE__ */ l("span", {
1141
1368
  className: "chunk-title",
@@ -1149,7 +1376,7 @@ function We({ node: e, expanded: t, toggle: n, selectedId: r, onSelect: i, tintS
1149
1376
  className: "chunk-badge chunk-status",
1150
1377
  children: e.row.status
1151
1378
  }),
1152
- p && /* @__PURE__ */ l("span", {
1379
+ h && /* @__PURE__ */ l("span", {
1153
1380
  className: "chunk-link-badge",
1154
1381
  title: "Has cross-reference links",
1155
1382
  "aria-label": "linked",
@@ -1157,34 +1384,35 @@ function We({ node: e, expanded: t, toggle: n, selectedId: r, onSelect: i, tintS
1157
1384
  })
1158
1385
  ]
1159
1386
  }),
1160
- /* @__PURE__ */ l(ze, {
1387
+ /* @__PURE__ */ l($, {
1161
1388
  value: e.row.id,
1162
1389
  compact: !0,
1163
1390
  title: `Copy chunk id: ${e.row.id}`
1164
1391
  })
1165
1392
  ]
1166
- }), s && c && /* @__PURE__ */ l("ul", {
1393
+ }), d && f && /* @__PURE__ */ l("ul", {
1167
1394
  className: "children chunk-children",
1168
- children: e.children.map((e) => /* @__PURE__ */ l(We, {
1395
+ children: e.children.map((e) => /* @__PURE__ */ l(et, {
1169
1396
  node: e,
1170
1397
  expanded: t,
1171
1398
  toggle: n,
1172
1399
  selectedId: r,
1173
1400
  onSelect: i,
1174
1401
  tintScheme: a,
1175
- linkedIds: o
1402
+ documentColor: o,
1403
+ linkedIds: c
1176
1404
  }, e.row.id))
1177
1405
  })]
1178
1406
  });
1179
1407
  }
1180
1408
  //#endregion
1181
1409
  //#region src/components/Mermaid.tsx
1182
- var Ge = 0;
1183
- function Ke(e) {
1410
+ var tt = 0;
1411
+ function nt(e) {
1184
1412
  let t = e?.closest("g.node");
1185
1413
  return t ? /flowchart-(.+)-\d+$/.exec(t.id)?.[1] : void 0;
1186
1414
  }
1187
- function qe({ code: e, onNodeClick: t }) {
1415
+ function rt({ code: e, onNodeClick: t }) {
1188
1416
  let n = a(null), [i, s] = o({});
1189
1417
  return r(() => {
1190
1418
  let t = !1;
@@ -1196,7 +1424,7 @@ function qe({ code: e, onNodeClick: t }) {
1196
1424
  theme: a ? "dark" : "default",
1197
1425
  securityLevel: "strict"
1198
1426
  });
1199
- let { svg: o } = await r.render(`lc-mmd-${Ge++}`, e);
1427
+ let { svg: o } = await r.render(`lc-mmd-${tt++}`, e);
1200
1428
  t || s({ svg: o });
1201
1429
  } catch {
1202
1430
  t || s({ err: !0 });
@@ -1212,7 +1440,7 @@ function qe({ code: e, onNodeClick: t }) {
1212
1440
  ref: n,
1213
1441
  className: t ? "md-mermaid md-mermaid-nav" : "md-mermaid",
1214
1442
  onClick: t && ((e) => {
1215
- let n = Ke(e.target);
1443
+ let n = nt(e.target);
1216
1444
  n && t(n);
1217
1445
  }),
1218
1446
  dangerouslySetInnerHTML: { __html: i.svg }
@@ -1224,17 +1452,17 @@ function qe({ code: e, onNodeClick: t }) {
1224
1452
  }
1225
1453
  //#endregion
1226
1454
  //#region src/components/ChunkEditorModal.tsx
1227
- function Je({ chunk: e, scope: t, browse: n, onClose: i, onSaved: a }) {
1228
- let s = ee(), [c, d] = o(e.title), [f, p] = o(e.type ?? ""), [m, h] = o(e.status ?? ""), [g, _] = o(e.body ?? ""), [v, y] = o(e.fields ? JSON.stringify(e.fields, null, 2) : ""), [b, x] = o((e.tags ?? []).join(", ")), [S, C] = o(!1), [w, T] = o(null), [E, D] = o(!1), O = f === "mermaid", k = f === "image" || !!e.asset, [A, j] = o(g);
1455
+ function it({ chunk: e, scope: t, browse: n, onClose: i, onSaved: a }) {
1456
+ let s = M(), [c, d] = o(e.title), [f, p] = o(e.type ?? ""), [m, h] = o(e.status ?? ""), [g, _] = o(e.body ?? ""), [v, y] = o(e.fields ? JSON.stringify(e.fields, null, 2) : ""), [b, x] = o((e.tags ?? []).join(", ")), [S, C] = o(!1), [w, T] = o(null), [E, D] = o(!1), O = f === "mermaid", k = f === "image" || !!e.asset, [A, j] = o(g);
1229
1457
  r(() => {
1230
1458
  if (!O) return;
1231
1459
  let e = setTimeout(() => j(g), 400);
1232
1460
  return () => clearTimeout(e);
1233
1461
  }, [g, O]);
1234
- let te = async (r) => {
1462
+ let N = async (r) => {
1235
1463
  T(null), C(!0);
1236
1464
  try {
1237
- let { mediaType: o, data: c } = await H(r);
1465
+ let { mediaType: o, data: c } = await _e(r);
1238
1466
  a(await s.documentSetAsset(e.id, o, c, r.name, t, n)), i();
1239
1467
  } catch (e) {
1240
1468
  T(e instanceof Error ? e.message : String(e)), C(!1);
@@ -1336,7 +1564,7 @@ function Je({ chunk: e, scope: t, browse: n, onClose: i, onSaved: a }) {
1336
1564
  disabled: S,
1337
1565
  onChange: (e) => {
1338
1566
  let t = e.target.files?.[0];
1339
- t && te(t);
1567
+ t && N(t);
1340
1568
  }
1341
1569
  })]
1342
1570
  }),
@@ -1353,7 +1581,7 @@ function Je({ chunk: e, scope: t, browse: n, onClose: i, onSaved: a }) {
1353
1581
  className: "path-field",
1354
1582
  children: [/* @__PURE__ */ l("span", { children: "Preview" }), /* @__PURE__ */ l("div", {
1355
1583
  className: "chunk-mermaid-preview",
1356
- children: A.trim() ? /* @__PURE__ */ l(qe, { code: A }) : /* @__PURE__ */ l("p", {
1584
+ children: A.trim() ? /* @__PURE__ */ l(rt, { code: A }) : /* @__PURE__ */ l("p", {
1357
1585
  className: "doc-empty-body",
1358
1586
  children: "(enter Mermaid source above)"
1359
1587
  })
@@ -1375,8 +1603,8 @@ function Je({ chunk: e, scope: t, browse: n, onClose: i, onSaved: a }) {
1375
1603
  }
1376
1604
  //#endregion
1377
1605
  //#region src/components/SubjectTypeModal.tsx
1378
- function Ye({ chunk: e, scope: t, browse: n, onClose: i, onSaved: a }) {
1379
- let s = ee(), [c, d] = o(null), [f, p] = o(e.type ?? ""), [m, h] = o(!1), [g, _] = o(null), [v, b] = o(null);
1606
+ function at({ chunk: e, scope: t, browse: n, onClose: i, onSaved: a }) {
1607
+ let s = M(), [c, d] = o(null), [f, p] = o(e.type ?? ""), [m, h] = o(!1), [g, _] = o(null), [v, b] = o(null);
1380
1608
  r(() => {
1381
1609
  let e = !1;
1382
1610
  return s.documentEntityTypes?.(t, n).then((t) => {
@@ -1468,18 +1696,18 @@ function Ye({ chunk: e, scope: t, browse: n, onClose: i, onSaved: a }) {
1468
1696
  }
1469
1697
  //#endregion
1470
1698
  //#region src/lib/classify.ts
1471
- function Xe(e) {
1699
+ function ot(e) {
1472
1700
  return Array.isArray(e) && e.every((e) => typeof e == "string");
1473
1701
  }
1474
- function Ze(e) {
1702
+ function st(e) {
1475
1703
  if (!e || typeof e != "object") return;
1476
1704
  let t = e.classification;
1477
1705
  if (!t || typeof t != "object" || Array.isArray(t)) return;
1478
1706
  let n = t, r = {};
1479
- return typeof n.by == "string" && (r.by = n.by), typeof n.at == "number" && (r.at = n.at), typeof n.applied_type == "string" && n.applied_type && (r.applied_type = n.applied_type), typeof n.proposed_type == "string" && n.proposed_type && (r.proposed_type = n.proposed_type), n.proposed_fields && typeof n.proposed_fields == "object" && !Array.isArray(n.proposed_fields) && (r.proposed_fields = n.proposed_fields), Xe(n.proposed_tags) && (r.proposed_tags = n.proposed_tags), Xe(n.statements) && (r.statements = n.statements), r;
1707
+ return typeof n.by == "string" && (r.by = n.by), typeof n.at == "number" && (r.at = n.at), typeof n.applied_type == "string" && n.applied_type && (r.applied_type = n.applied_type), typeof n.proposed_type == "string" && n.proposed_type && (r.proposed_type = n.proposed_type), n.proposed_fields && typeof n.proposed_fields == "object" && !Array.isArray(n.proposed_fields) && (r.proposed_fields = n.proposed_fields), ot(n.proposed_tags) && (r.proposed_tags = n.proposed_tags), ot(n.statements) && (r.statements = n.statements), r;
1480
1708
  }
1481
- function Qe(e) {
1482
- let t = Ze(e);
1709
+ function ct(e) {
1710
+ let t = st(e);
1483
1711
  if (!t) return;
1484
1712
  let n = t.proposed_tags ?? [], r = t.statements?.length ?? 0;
1485
1713
  if (t.proposed_type || n.length !== 0 || r !== 0) return {
@@ -1488,7 +1716,7 @@ function Qe(e) {
1488
1716
  statementCount: r
1489
1717
  };
1490
1718
  }
1491
- function $e(e) {
1719
+ function lt(e) {
1492
1720
  let t = e.write === "report";
1493
1721
  switch (e.result) {
1494
1722
  case "classified": return t ? "would be classified" : "classified";
@@ -1498,46 +1726,46 @@ function $e(e) {
1498
1726
  default: return String(e.result);
1499
1727
  }
1500
1728
  }
1501
- function et(e) {
1729
+ function ut(e) {
1502
1730
  if (!e.class) return;
1503
1731
  if (e.result === "kept") return "not applied";
1504
1732
  let t = e.write === "report";
1505
1733
  return e.live ? t ? "would be applied" : "applied" : t ? "would be proposed" : "proposed";
1506
1734
  }
1507
- function tt(e) {
1735
+ function dt(e) {
1508
1736
  return e.write === "report" ? e.result === "classified" || e.result === "proposed" || (e.concepts?.length ?? 0) > 0 || (e.issued_by?.length ?? 0) > 0 : !1;
1509
1737
  }
1510
- function nt(e) {
1738
+ function ft(e) {
1511
1739
  return e == null || !Number.isFinite(e) ? "" : `${Math.round(e * 100)}%`;
1512
1740
  }
1513
- var rt = {
1741
+ var pt = {
1514
1742
  rules: "Rules",
1515
1743
  vote: "Neighbourhood vote",
1516
1744
  model: "Model"
1517
1745
  };
1518
- function it(e) {
1519
- return rt[e] ?? e;
1746
+ function mt(e) {
1747
+ return pt[e] ?? e;
1520
1748
  }
1521
- function at(e) {
1749
+ function ht(e) {
1522
1750
  let t = [];
1523
1751
  e.quote && t.push(e.from ? `“${e.quote}” (${e.from})` : `“${e.quote}”`), e.votes != null && t.push(`${e.votes} vote${e.votes === 1 ? "" : "s"}`);
1524
- let n = nt(e.share);
1752
+ let n = ft(e.share);
1525
1753
  return n && t.push(n), t.join(" · ");
1526
1754
  }
1527
- function ot(e) {
1755
+ function gt(e) {
1528
1756
  return {
1529
- label: it(e.step),
1757
+ label: mt(e.step),
1530
1758
  ...e.chosen ? { chosen: e.chosen } : {},
1531
1759
  ...e.method ? { method: e.method } : {},
1532
1760
  ...e.neighbours ? { neighbours: e.neighbours } : {},
1533
1761
  ...e.reason ? { reason: e.reason } : {},
1534
1762
  candidates: (e.candidates ?? []).map((e) => ({
1535
1763
  class: e.class,
1536
- detail: at(e)
1764
+ detail: ht(e)
1537
1765
  }))
1538
1766
  };
1539
1767
  }
1540
- function st(e) {
1768
+ function _t(e) {
1541
1769
  let t = [];
1542
1770
  e.type && t.push(`type ${e.type}`);
1543
1771
  let n = e.accepted_statements?.length ?? 0;
@@ -1550,18 +1778,18 @@ function st(e) {
1550
1778
  notices: r
1551
1779
  };
1552
1780
  }
1553
- function ct(e) {
1781
+ function vt(e) {
1554
1782
  let t = e instanceof Error ? e.message : String(e);
1555
1783
  return t.includes("nothing_pending") ? "Nothing is pending for this document — it may already have been accepted." : t;
1556
1784
  }
1557
1785
  //#endregion
1558
1786
  //#region src/components/Classification.tsx
1559
- function lt({ documentId: e, scope: t, browse: n, rootFields: a, requestKey: s, onClose: c, onChanged: d }) {
1560
- let f = ee(), [p, m] = o(null), [h, g] = o(!1), [_, v] = o(null), [y, b] = o(!1), [x, S] = o(null), [C, w] = o(null), T = i(() => f.documentAcceptClassification ? Qe(a) : void 0, [f, a]);
1787
+ function yt({ documentId: e, scope: t, browse: n, rootFields: a, requestKey: s, onClose: c, onChanged: d }) {
1788
+ let f = M(), [p, m] = o(null), [h, g] = o(!1), [_, v] = o(null), [y, b] = o(!1), [x, S] = o(null), [C, w] = o(null), T = i(() => f.documentAcceptClassification ? ct(a) : void 0, [f, a]);
1561
1789
  r(() => {
1562
1790
  if (s === 0 || !f.documentClassify) return;
1563
1791
  let r = !1;
1564
- return g(!0), v(null), m(null), f.documentClassify(e, "report", t, n).then((e) => !r && m(e)).catch((e) => !r && v(ct(e))).finally(() => !r && g(!1)), () => {
1792
+ return g(!0), v(null), m(null), f.documentClassify(e, "report", t, n).then((e) => !r && m(e)).catch((e) => !r && v(vt(e))).finally(() => !r && g(!1)), () => {
1565
1793
  r = !0;
1566
1794
  };
1567
1795
  }, [
@@ -1577,7 +1805,7 @@ function lt({ documentId: e, scope: t, browse: n, rootFields: a, requestKey: s,
1577
1805
  try {
1578
1806
  m(await f.documentClassify(e, "propose", t, n)), d();
1579
1807
  } catch (e) {
1580
- v(ct(e));
1808
+ v(vt(e));
1581
1809
  } finally {
1582
1810
  g(!1);
1583
1811
  }
@@ -1588,14 +1816,14 @@ function lt({ documentId: e, scope: t, browse: n, rootFields: a, requestKey: s,
1588
1816
  try {
1589
1817
  w(await f.documentAcceptClassification(e, t, n)), d();
1590
1818
  } catch (e) {
1591
- S(ct(e));
1819
+ S(vt(e));
1592
1820
  } finally {
1593
1821
  b(!1);
1594
1822
  }
1595
1823
  }
1596
1824
  }, O = s > 0;
1597
1825
  if (!O && !T && !C && !x) return null;
1598
- let k = C ? st(C) : void 0;
1826
+ let k = C ? _t(C) : void 0;
1599
1827
  return /* @__PURE__ */ u("div", {
1600
1828
  className: "doc-classify",
1601
1829
  children: [
@@ -1666,7 +1894,7 @@ function lt({ documentId: e, scope: t, browse: n, rootFields: a, requestKey: s,
1666
1894
  /* @__PURE__ */ l("h4", { children: "Classify" }),
1667
1895
  p && /* @__PURE__ */ l("span", {
1668
1896
  className: `doc-classify-result ${p.result}`,
1669
- children: $e(p)
1897
+ children: lt(p)
1670
1898
  }),
1671
1899
  p?.write === "report" && /* @__PURE__ */ l("span", {
1672
1900
  className: "doc-classify-hint",
@@ -1690,8 +1918,8 @@ function lt({ documentId: e, scope: t, browse: n, rootFields: a, requestKey: s,
1690
1918
  role: "alert",
1691
1919
  children: _
1692
1920
  }),
1693
- p && /* @__PURE__ */ l(ut, { answer: p }),
1694
- p && tt(p) && /* @__PURE__ */ l("div", {
1921
+ p && /* @__PURE__ */ l(bt, { answer: p }),
1922
+ p && dt(p) && /* @__PURE__ */ l("div", {
1695
1923
  className: "doc-classify-actions",
1696
1924
  children: /* @__PURE__ */ l("button", {
1697
1925
  type: "button",
@@ -1706,8 +1934,8 @@ function lt({ documentId: e, scope: t, browse: n, rootFields: a, requestKey: s,
1706
1934
  ]
1707
1935
  });
1708
1936
  }
1709
- function ut({ answer: e }) {
1710
- let t = et(e), n = Object.entries(e.fields ?? {}), r = e.issued_by ?? [], i = e.concepts ?? [], a = (e.steps ?? []).map(ot), o = e.statements?.length ?? 0;
1937
+ function bt({ answer: e }) {
1938
+ let t = ut(e), n = Object.entries(e.fields ?? {}), r = e.issued_by ?? [], i = e.concepts ?? [], a = (e.steps ?? []).map(gt), o = e.statements?.length ?? 0;
1711
1939
  return /* @__PURE__ */ u(c, { children: [
1712
1940
  /* @__PURE__ */ u("dl", {
1713
1941
  className: "doc-classify-rows",
@@ -1745,7 +1973,7 @@ function ut({ answer: e }) {
1745
1973
  title: e.tag,
1746
1974
  children: [e.concept, /* @__PURE__ */ u("span", {
1747
1975
  className: "doc-classify-hint",
1748
- children: [" ", nt(e.share)]
1976
+ children: [" ", ft(e.share)]
1749
1977
  })]
1750
1978
  }, e.tag)) })] }),
1751
1979
  o > 0 && /* @__PURE__ */ u(c, { children: [/* @__PURE__ */ l("dt", { children: "statements" }), /* @__PURE__ */ u("dd", { children: [
@@ -1813,15 +2041,15 @@ function ut({ answer: e }) {
1813
2041
  }
1814
2042
  //#endregion
1815
2043
  //#region src/components/ColorSchemeEditor.tsx
1816
- function dt(e) {
2044
+ function xt(e) {
1817
2045
  let t = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec((e ?? "").trim());
1818
2046
  if (!t) return "#888888";
1819
2047
  let n = t[1];
1820
2048
  return n.length === 3 && (n = n[0] + n[0] + n[1] + n[1] + n[2] + n[2]), "#" + n.toLowerCase();
1821
2049
  }
1822
- function ft({ documentId: e, rootChunkId: t, docType: n, docStatus: a, chunkStatuses: s, scope: d, browse: f, onClose: p, onSaved: m }) {
1823
- let h = ee(), [g, _] = o(null), [v, y] = o(!1), [b, x] = o({}), [S, C] = o(!1), [w, T] = o(null), [E, D] = o(null), O = i(() => {
1824
- let e = new Set(Object.keys(Y));
2050
+ function St({ documentId: e, rootChunkId: t, docType: n, docStatus: a, chunkStatuses: s, scope: d, browse: f, onClose: p, onSaved: m }) {
2051
+ let h = M(), [g, _] = o(null), [v, y] = o(!1), [b, x] = o({}), [S, C] = o(!1), [w, T] = o(null), [E, D] = o(null), O = i(() => {
2052
+ let e = new Set(Object.keys(Z));
1825
2053
  n && e.add(`doc.${n}.${a || "draft"}`);
1826
2054
  for (let t of s) t && e.add(`chunk.${t}`);
1827
2055
  return [...e].sort();
@@ -1839,7 +2067,7 @@ function ft({ documentId: e, rootChunkId: t, docType: n, docStatus: a, chunkStat
1839
2067
  y(n.color_enabled === !0);
1840
2068
  let r = n.color_scheme ?? {};
1841
2069
  x({
1842
- ...Y,
2070
+ ...Z,
1843
2071
  ...r
1844
2072
  });
1845
2073
  }).catch((t) => !e && D(t instanceof Error ? t.message : String(t))), () => {
@@ -1867,7 +2095,7 @@ function ft({ documentId: e, rootChunkId: t, docType: n, docStatus: a, chunkStat
1867
2095
  D(e instanceof Error ? e.message : String(e)), C(!1);
1868
2096
  }
1869
2097
  }
1870
- }, te = async () => {
2098
+ }, N = async () => {
1871
2099
  if (!n) D("this document has no type to match");
1872
2100
  else {
1873
2101
  C(!0), D(null), T(null);
@@ -1884,7 +2112,7 @@ function ft({ documentId: e, rootChunkId: t, docType: n, docStatus: a, chunkStat
1884
2112
  C(!1);
1885
2113
  }
1886
2114
  }
1887
- }, ne = O.filter((e) => e.startsWith("doc.")), re = O.filter((e) => e.startsWith("chunk."));
2115
+ }, P = O.filter((e) => e.startsWith("doc.")), F = O.filter((e) => e.startsWith("chunk."));
1888
2116
  return /* @__PURE__ */ l("div", {
1889
2117
  className: "modal-overlay",
1890
2118
  onClick: p,
@@ -1929,7 +2157,7 @@ function ft({ documentId: e, rootChunkId: t, docType: n, docStatus: a, chunkStat
1929
2157
  }),
1930
2158
  /* @__PURE__ */ u("div", {
1931
2159
  className: "scheme-group",
1932
- children: [/* @__PURE__ */ l("h4", { children: "Document (type · status)" }), ne.map((e) => /* @__PURE__ */ l(pt, {
2160
+ children: [/* @__PURE__ */ l("h4", { children: "Document (type · status)" }), P.map((e) => /* @__PURE__ */ l(Ct, {
1933
2161
  label: e.slice(4),
1934
2162
  value: b[e],
1935
2163
  onChange: (t) => k(e, t)
@@ -1937,7 +2165,7 @@ function ft({ documentId: e, rootChunkId: t, docType: n, docStatus: a, chunkStat
1937
2165
  }),
1938
2166
  /* @__PURE__ */ u("div", {
1939
2167
  className: "scheme-group",
1940
- children: [/* @__PURE__ */ l("h4", { children: "Chunks (status)" }), re.map((e) => /* @__PURE__ */ l(pt, {
2168
+ children: [/* @__PURE__ */ l("h4", { children: "Chunks (status)" }), F.map((e) => /* @__PURE__ */ l(Ct, {
1941
2169
  label: e.slice(6),
1942
2170
  value: b[e],
1943
2171
  onChange: (t) => k(e, t)
@@ -1947,7 +2175,7 @@ function ft({ documentId: e, rootChunkId: t, docType: n, docStatus: a, chunkStat
1947
2175
  className: "scheme-editor-foot",
1948
2176
  children: [/* @__PURE__ */ u("button", {
1949
2177
  type: "button",
1950
- onClick: () => void te(),
2178
+ onClick: () => void N(),
1951
2179
  disabled: S || !n,
1952
2180
  title: n ? `Apply this palette to every other ${n} document` : "This document has no type",
1953
2181
  children: [
@@ -1968,8 +2196,8 @@ function ft({ documentId: e, rootChunkId: t, docType: n, docStatus: a, chunkStat
1968
2196
  })
1969
2197
  });
1970
2198
  }
1971
- function pt({ label: e, value: t, onChange: n }) {
1972
- let r = dt(t);
2199
+ function Ct({ label: e, value: t, onChange: n }) {
2200
+ let r = xt(t);
1973
2201
  return /* @__PURE__ */ u("label", {
1974
2202
  className: "scheme-row",
1975
2203
  children: [
@@ -1991,7 +2219,7 @@ function pt({ label: e, value: t, onChange: n }) {
1991
2219
  }
1992
2220
  //#endregion
1993
2221
  //#region src/components/ChunkTarget.tsx
1994
- function mt({ id: e, title: t, targetDocumentId: n, documentId: r, onSelectChunk: i, onOpenDocument: a }) {
2222
+ function wt({ id: e, title: t, targetDocumentId: n, documentId: r, onSelectChunk: i, onOpenDocument: a }) {
1995
2223
  let o = t || e.slice(0, 8);
1996
2224
  return !n || n === r ? /* @__PURE__ */ l("button", {
1997
2225
  type: "button",
@@ -2012,8 +2240,8 @@ function mt({ id: e, title: t, targetDocumentId: n, documentId: r, onSelectChunk
2012
2240
  }
2013
2241
  //#endregion
2014
2242
  //#region src/components/Statement.tsx
2015
- function ht({ statement: e }) {
2016
- let t = ye(e), n = W(e), r = Se(e), i = xe(e), { rows: a, more: o } = K(e);
2243
+ function Tt({ statement: e }) {
2244
+ let t = Ce(e), n = we(e), r = De(e), i = Ee(e), { rows: a, more: o } = Oe(e);
2017
2245
  return /* @__PURE__ */ u(c, { children: [
2018
2246
  t && /* @__PURE__ */ l("span", {
2019
2247
  className: `doc-stmt-status ${t}`,
@@ -2039,7 +2267,7 @@ function ht({ statement: e }) {
2039
2267
  title: e.quote,
2040
2268
  children: [
2041
2269
  "“",
2042
- Ce(e.quote),
2270
+ ke(e.quote),
2043
2271
  "”",
2044
2272
  e.stale && /* @__PURE__ */ l("span", {
2045
2273
  className: "doc-stmt-stale",
@@ -2057,7 +2285,7 @@ function ht({ statement: e }) {
2057
2285
  })
2058
2286
  ] });
2059
2287
  }
2060
- function gt({ id: e, onRule: t }) {
2288
+ function Et({ id: e, onRule: t }) {
2061
2289
  let [n, r] = o(!1), [i, a] = o(""), [s, d] = o(!1), [f, p] = o(null), m = async (n) => {
2062
2290
  d(!0), p(null);
2063
2291
  try {
@@ -2115,9 +2343,9 @@ function gt({ id: e, onRule: t }) {
2115
2343
  }
2116
2344
  //#endregion
2117
2345
  //#region src/components/ProposalReview.tsx
2118
- var _t = 3;
2119
- function vt({ documentId: e, proposals: t, incomplete: n, scope: r, browse: i, onChanged: s, onSelectChunk: c, onOpenDocument: d }) {
2120
- let f = ee(), [p, m] = o(/* @__PURE__ */ new Set()), [h, g] = o({ kind: "idle" }), [_, v] = o(""), [y, b] = o(null), [x, S] = o(null), C = a(null), w = new Set(t.map((e) => e.id)), T = [...p].filter((e) => w.has(e)), E = h.kind !== "idle" && h.kind !== "reason", D = (e, t) => {
2346
+ var Dt = 3;
2347
+ function Ot({ documentId: e, proposals: t, incomplete: n, scope: r, browse: i, onChanged: s, onSelectChunk: c, onOpenDocument: d }) {
2348
+ let f = M(), [p, m] = o(/* @__PURE__ */ new Set()), [h, g] = o({ kind: "idle" }), [_, v] = o(""), [y, b] = o(null), [x, S] = o(null), C = a(null), w = new Set(t.map((e) => e.id)), T = [...p].filter((e) => w.has(e)), E = h.kind !== "idle" && h.kind !== "reason", D = (e, t) => {
2121
2349
  b(null), S(null), e === "reject" ? g({
2122
2350
  kind: "reason",
2123
2351
  action: e,
@@ -2131,7 +2359,7 @@ function vt({ documentId: e, proposals: t, incomplete: n, scope: r, browse: i, o
2131
2359
  });
2132
2360
  let o;
2133
2361
  try {
2134
- o = await J(f, {
2362
+ o = await Re(f, {
2135
2363
  documentId: e,
2136
2364
  action: t,
2137
2365
  ids: n ? void 0 : T,
@@ -2168,7 +2396,7 @@ function vt({ documentId: e, proposals: t, incomplete: n, scope: r, browse: i, o
2168
2396
  };
2169
2397
  }
2170
2398
  C.current = null, g({ kind: "idle" }), v(""), o.rulingIds.length > 0 ? (m(/* @__PURE__ */ new Set()), S({
2171
- text: Pe(t, o),
2399
+ text: ze(t, o),
2172
2400
  rulingIds: o.rulingIds
2173
2401
  }), s()) : o.error === void 0 && !o.cancelled && S({
2174
2402
  text: "Nothing to rule: no proposals match.",
@@ -2181,7 +2409,7 @@ function vt({ documentId: e, proposals: t, incomplete: n, scope: r, browse: i, o
2181
2409
  }), C.current?.(e);
2182
2410
  }, A = async () => {
2183
2411
  if (!x || !f.documentRevertRuling) return;
2184
- let e = x, t = await ke((e) => f.documentRevertRuling(e, r, i), e.rulingIds), n = [`${t.reverted} came back to review`];
2412
+ let e = x, t = await Y((e) => f.documentRevertRuling(e, r, i), e.rulingIds), n = [`${t.reverted} came back to review`];
2185
2413
  t.changed > 0 && n.push(`${t.changed} changed since and left as ruled`), t.errors.length > 0 && n.push(`not undone: ${t.errors.join("; ")}`), S({
2186
2414
  ...e,
2187
2415
  undone: !0,
@@ -2190,7 +2418,7 @@ function vt({ documentId: e, proposals: t, incomplete: n, scope: r, browse: i, o
2190
2418
  }, j = (e) => m((t) => {
2191
2419
  let n = new Set(t);
2192
2420
  return n.has(e) ? n.delete(e) : n.add(e), n;
2193
- }), te = t.length > 0 && T.length === t.length, ne = t.length === 0 && !n;
2421
+ }), N = t.length > 0 && T.length === t.length, P = t.length === 0 && !n;
2194
2422
  return /* @__PURE__ */ u("div", {
2195
2423
  className: "doc-conn-group doc-bulk",
2196
2424
  children: [
@@ -2206,9 +2434,9 @@ function vt({ documentId: e, proposals: t, incomplete: n, scope: r, browse: i, o
2206
2434
  /* @__PURE__ */ l("input", {
2207
2435
  type: "checkbox",
2208
2436
  "aria-label": "select every proposal shown",
2209
- checked: te,
2437
+ checked: N,
2210
2438
  disabled: E || t.length === 0,
2211
- onChange: () => m(te ? /* @__PURE__ */ new Set() : new Set(w))
2439
+ onChange: () => m(N ? /* @__PURE__ */ new Set() : new Set(w))
2212
2440
  }),
2213
2441
  " ",
2214
2442
  "all shown"
@@ -2232,14 +2460,14 @@ function vt({ documentId: e, proposals: t, incomplete: n, scope: r, browse: i, o
2232
2460
  }),
2233
2461
  /* @__PURE__ */ l("button", {
2234
2462
  type: "button",
2235
- disabled: E || ne,
2463
+ disabled: E || P,
2236
2464
  onClick: () => D("accept", !0),
2237
2465
  children: "Accept all from this document"
2238
2466
  }),
2239
2467
  /* @__PURE__ */ l("button", {
2240
2468
  type: "button",
2241
2469
  className: "danger",
2242
- disabled: E || ne,
2470
+ disabled: E || P,
2243
2471
  onClick: () => D("reject", !0),
2244
2472
  children: "Reject all…"
2245
2473
  })
@@ -2276,7 +2504,7 @@ function vt({ documentId: e, proposals: t, incomplete: n, scope: r, browse: i, o
2276
2504
  className: "doc-conn-empty",
2277
2505
  children: "counting…"
2278
2506
  }),
2279
- h.kind === "confirm" && /* @__PURE__ */ l(yt, {
2507
+ h.kind === "confirm" && /* @__PURE__ */ l(kt, {
2280
2508
  step: h,
2281
2509
  onAnswer: k
2282
2510
  }),
@@ -2313,7 +2541,7 @@ function vt({ documentId: e, proposals: t, incomplete: n, scope: r, browse: i, o
2313
2541
  disabled: E,
2314
2542
  onChange: () => j(t.id)
2315
2543
  }),
2316
- /* @__PURE__ */ l(mt, {
2544
+ /* @__PURE__ */ l(wt, {
2317
2545
  id: t.from_id,
2318
2546
  title: t.from_title,
2319
2547
  targetDocumentId: t.from_document_id,
@@ -2325,7 +2553,7 @@ function vt({ documentId: e, proposals: t, incomplete: n, scope: r, browse: i, o
2325
2553
  className: "doc-ref-kind",
2326
2554
  children: t.kind
2327
2555
  }),
2328
- /* @__PURE__ */ l(mt, {
2556
+ /* @__PURE__ */ l(wt, {
2329
2557
  id: t.to_id,
2330
2558
  title: t.to_title,
2331
2559
  targetDocumentId: t.to_document_id,
@@ -2333,15 +2561,15 @@ function vt({ documentId: e, proposals: t, incomplete: n, scope: r, browse: i, o
2333
2561
  onSelectChunk: c,
2334
2562
  onOpenDocument: d
2335
2563
  }),
2336
- /* @__PURE__ */ l(ht, { statement: t })
2564
+ /* @__PURE__ */ l(Tt, { statement: t })
2337
2565
  ]
2338
2566
  }, t.id))
2339
2567
  })
2340
2568
  ]
2341
2569
  });
2342
2570
  }
2343
- function yt({ step: e, onAnswer: t }) {
2344
- let { dry: n } = e, r = e.action === "accept" ? "Accept" : "Reject", i = Ae(n.matched);
2571
+ function kt({ step: e, onAnswer: t }) {
2572
+ let { dry: n } = e, r = e.action === "accept" ? "Accept" : "Reject", i = Pe(n.matched);
2345
2573
  return /* @__PURE__ */ u("div", {
2346
2574
  className: "doc-bulk-step doc-bulk-confirm",
2347
2575
  children: [
@@ -2362,7 +2590,7 @@ function yt({ step: e, onAnswer: t }) {
2362
2590
  ] }),
2363
2591
  (n.sample ?? []).length > 0 && /* @__PURE__ */ l("ul", {
2364
2592
  className: "doc-bulk-sample",
2365
- children: (n.sample ?? []).slice(0, _t).map((e) => /* @__PURE__ */ u("li", { children: [
2593
+ children: (n.sample ?? []).slice(0, Dt).map((e) => /* @__PURE__ */ u("li", { children: [
2366
2594
  e.from_title || e.from_id,
2367
2595
  " ",
2368
2596
  /* @__PURE__ */ l("span", {
@@ -2393,26 +2621,26 @@ function yt({ step: e, onAnswer: t }) {
2393
2621
  }
2394
2622
  //#endregion
2395
2623
  //#region src/components/Connections.tsx
2396
- var bt = 8, xt = 20;
2397
- function St(e) {
2624
+ var At = 8, jt = 20;
2625
+ function Mt(e) {
2398
2626
  return /embedder|embedding|vector|semantic|not configured/i.test(e);
2399
2627
  }
2400
- function Ct({ documentId: e, selectedId: t, scope: n, browse: i, onSelectChunk: a, onOpenDocument: s, refreshKey: d, review: f }) {
2401
- let p = ee(), [m, h] = o(!1), [g, _] = o(!1), [v, y] = o(void 0), [b, x] = o([]), [S, C] = o([]), [w, T] = o(null), [E, D] = o([]), [O, k] = o(!1);
2628
+ function Nt({ documentId: e, selectedId: t, scope: n, browse: i, onSelectChunk: a, onOpenDocument: s, refreshKey: d, review: f }) {
2629
+ let p = M(), [m, h] = o(!1), [g, _] = o(!1), [v, y] = o(void 0), [b, x] = o([]), [S, C] = o([]), [w, T] = o(null), [E, D] = o([]), [O, k] = o(!1);
2402
2630
  r(() => {
2403
2631
  if (!m || !t) return;
2404
2632
  let e = t, r = !1;
2405
2633
  return _(!0), Promise.allSettled([
2406
2634
  p.documentBacklinks(e, n, i),
2407
- p.documentRelated(e, n, i, bt),
2408
- p.documentUnlinkedMentions(e, n, i, xt)
2635
+ p.documentRelated(e, n, i, At),
2636
+ p.documentUnlinkedMentions(e, n, i, jt)
2409
2637
  ]).then(([t, n, i]) => {
2410
2638
  if (!r) {
2411
2639
  if (x(t.status === "fulfilled" ? t.value.backlinks ?? [] : []), n.status === "fulfilled") C(n.value.related ?? []), T(null);
2412
2640
  else {
2413
2641
  C([]);
2414
2642
  let e = n.reason instanceof Error ? n.reason.message : String(n.reason);
2415
- T(St(e) ? "semantic search not configured" : e);
2643
+ T(Mt(e) ? "semantic search not configured" : e);
2416
2644
  }
2417
2645
  i.status === "fulfilled" ? (D(i.value.unlinked_mentions ?? []), k(!!i.value.truncated)) : (D([]), k(!1)), y(e), _(!1);
2418
2646
  }
@@ -2427,7 +2655,7 @@ function Ct({ documentId: e, selectedId: t, scope: n, browse: i, onSelectChunk:
2427
2655
  i,
2428
2656
  d
2429
2657
  ]);
2430
- let A = (t, n, r) => /* @__PURE__ */ l(mt, {
2658
+ let A = (t, n, r) => /* @__PURE__ */ l(wt, {
2431
2659
  id: t,
2432
2660
  title: n,
2433
2661
  targetDocumentId: r,
@@ -2444,7 +2672,7 @@ function Ct({ documentId: e, selectedId: t, scope: n, browse: i, onSelectChunk:
2444
2672
  children: [m ? "▼" : "▶", " Connections"]
2445
2673
  }), m && /* @__PURE__ */ u("div", {
2446
2674
  className: "doc-conn-body",
2447
- children: [f && /* @__PURE__ */ l(vt, {
2675
+ children: [f && /* @__PURE__ */ l(Ot, {
2448
2676
  documentId: e,
2449
2677
  proposals: f.proposals,
2450
2678
  incomplete: f.incomplete,
@@ -2474,7 +2702,7 @@ function Ct({ documentId: e, selectedId: t, scope: n, browse: i, onSelectChunk:
2474
2702
  title: "Auto-linked from a [[wikilink]]",
2475
2703
  children: "auto"
2476
2704
  }),
2477
- /* @__PURE__ */ l(ht, { statement: e })
2705
+ /* @__PURE__ */ l(Tt, { statement: e })
2478
2706
  ]
2479
2707
  }, `${e.from_id}-${e.kind}-${t}`))
2480
2708
  })]
@@ -2528,11 +2756,11 @@ function Ct({ documentId: e, selectedId: t, scope: n, browse: i, onSelectChunk:
2528
2756
  }
2529
2757
  //#endregion
2530
2758
  //#region src/components/CrossReferences.tsx
2531
- var wt = 24;
2532
- function Tt({ edges: e, documentId: t, selectedId: n, onSelectChunk: r, onOpenDocument: i, onRuleStatement: a, incomplete: s }) {
2759
+ var Pt = 24;
2760
+ function Ft({ edges: e, documentId: t, selectedId: n, onSelectChunk: r, onOpenDocument: i, onRuleStatement: a, incomplete: s }) {
2533
2761
  let [d, f] = o(!1), [p, m] = o(!1);
2534
2762
  if (e.length === 0) return null;
2535
- let h = n ? e.filter((e) => e.from_id === n || e.to_id === n) : [], g = p ? e : e.slice(0, wt), _ = Dt(g);
2763
+ let h = n ? e.filter((e) => e.from_id === n || e.to_id === n) : [], g = p ? e : e.slice(0, Pt), _ = Lt(g);
2536
2764
  return /* @__PURE__ */ u("div", {
2537
2765
  className: "doc-refs",
2538
2766
  children: [
@@ -2551,7 +2779,7 @@ function Tt({ edges: e, documentId: t, selectedId: n, onSelectChunk: r, onOpenDo
2551
2779
  children: "This chunk has no links."
2552
2780
  }) : /* @__PURE__ */ l("ul", {
2553
2781
  className: "doc-refs-list",
2554
- children: h.map((e, o) => /* @__PURE__ */ l(Et, {
2782
+ children: h.map((e, o) => /* @__PURE__ */ l(It, {
2555
2783
  edge: e,
2556
2784
  selectedId: n,
2557
2785
  documentId: t,
@@ -2573,23 +2801,23 @@ function Tt({ edges: e, documentId: t, selectedId: n, onSelectChunk: r, onOpenDo
2573
2801
  e.length,
2574
2802
  ")"
2575
2803
  ]
2576
- }), d && /* @__PURE__ */ u(c, { children: [/* @__PURE__ */ l(qe, {
2804
+ }), d && /* @__PURE__ */ u(c, { children: [/* @__PURE__ */ l(rt, {
2577
2805
  code: _,
2578
2806
  onNodeClick: (e) => {
2579
- let n = Ot(g, e);
2807
+ let n = Rt(g, e);
2580
2808
  n && (!n.documentId || n.documentId === t ? r(n.id) : i?.(n.documentId, n.id, n.title));
2581
2809
  }
2582
- }), e.length > wt && /* @__PURE__ */ l("button", {
2810
+ }), e.length > Pt && /* @__PURE__ */ l("button", {
2583
2811
  type: "button",
2584
2812
  className: "doc-graph-more",
2585
2813
  onClick: () => m((e) => !e),
2586
- children: p ? `show top ${wt}` : `show all ${e.length}`
2814
+ children: p ? `show top ${Pt}` : `show all ${e.length}`
2587
2815
  })] })]
2588
2816
  })
2589
2817
  ]
2590
2818
  });
2591
2819
  }
2592
- function Et({ edge: e, selectedId: t, documentId: n, onSelectChunk: r, onOpenDocument: i, onRuleStatement: a }) {
2820
+ function It({ edge: e, selectedId: t, documentId: n, onSelectChunk: r, onOpenDocument: i, onRuleStatement: a }) {
2593
2821
  let o = e.from_id === t, s = o ? e.to_id : e.from_id, c = o ? e.to_title : e.from_title, d = o ? e.to_document_id : e.from_document_id;
2594
2822
  return /* @__PURE__ */ u("li", {
2595
2823
  className: "doc-ref",
@@ -2603,7 +2831,7 @@ function Et({ edge: e, selectedId: t, documentId: n, onSelectChunk: r, onOpenDoc
2603
2831
  "aria-hidden": !0,
2604
2832
  children: o ? "→" : "←"
2605
2833
  }),
2606
- /* @__PURE__ */ l(mt, {
2834
+ /* @__PURE__ */ l(wt, {
2607
2835
  id: s,
2608
2836
  title: c,
2609
2837
  targetDocumentId: d,
@@ -2611,46 +2839,46 @@ function Et({ edge: e, selectedId: t, documentId: n, onSelectChunk: r, onOpenDoc
2611
2839
  onSelectChunk: r,
2612
2840
  onOpenDocument: i
2613
2841
  }),
2614
- /* @__PURE__ */ l(ht, { statement: e }),
2615
- a && G(e) && /* @__PURE__ */ l(gt, {
2842
+ /* @__PURE__ */ l(Tt, { statement: e }),
2843
+ a && q(e) && /* @__PURE__ */ l(Et, {
2616
2844
  id: e.id,
2617
2845
  onRule: a
2618
2846
  })
2619
2847
  ]
2620
2848
  });
2621
2849
  }
2622
- function Dt(e) {
2850
+ function Lt(e) {
2623
2851
  let t = ["graph LR"];
2624
2852
  for (let n of e) {
2625
- let e = `${kt(n.from_id)}["${At(n.from_title, n.from_id)}"]`, r = `${kt(n.to_id)}["${At(n.to_title, n.to_id)}"]`, i = (n.kind || "link").replace(/[|"]/g, " "), a = n.status === "proposed" ? "-.->" : "-->";
2853
+ let e = `${zt(n.from_id)}["${Bt(n.from_title, n.from_id)}"]`, r = `${zt(n.to_id)}["${Bt(n.to_title, n.to_id)}"]`, i = (n.kind || "link").replace(/[|"]/g, " "), a = n.status === "proposed" ? "-.->" : "-->";
2626
2854
  t.push(` ${e} ${a}|${i}| ${r}`);
2627
2855
  }
2628
2856
  return t.join("\n");
2629
2857
  }
2630
- function Ot(e, t) {
2858
+ function Rt(e, t) {
2631
2859
  for (let n of e) {
2632
- if (kt(n.from_id) === t) return {
2860
+ if (zt(n.from_id) === t) return {
2633
2861
  id: n.from_id,
2634
2862
  documentId: n.from_document_id,
2635
2863
  title: n.from_title
2636
2864
  };
2637
- if (kt(n.to_id) === t) return {
2865
+ if (zt(n.to_id) === t) return {
2638
2866
  id: n.to_id,
2639
2867
  documentId: n.to_document_id,
2640
2868
  title: n.to_title
2641
2869
  };
2642
2870
  }
2643
2871
  }
2644
- function kt(e) {
2872
+ function zt(e) {
2645
2873
  return "n" + e.replace(/[^a-zA-Z0-9]/g, "");
2646
2874
  }
2647
- function At(e, t) {
2875
+ function Bt(e, t) {
2648
2876
  let n = (e ?? "").replace(/["[\]{}|<>]/g, " ").replace(/\s+/g, " ").trim() || t.slice(0, 6);
2649
2877
  return n.length > 30 ? n.slice(0, 29) + "…" : n;
2650
2878
  }
2651
2879
  //#endregion
2652
2880
  //#region src/components/DocUnavailable.tsx
2653
- function jt({ documentId: e, scope: t, detail: n }) {
2881
+ function Vt({ documentId: e, scope: t, detail: n }) {
2654
2882
  return /* @__PURE__ */ u("div", {
2655
2883
  className: "doc-unavailable",
2656
2884
  role: "alert",
@@ -2673,12 +2901,12 @@ function jt({ documentId: e, scope: t, detail: n }) {
2673
2901
  }
2674
2902
  //#endregion
2675
2903
  //#region src/components/HistoryModal.tsx
2676
- function Mt(e) {
2904
+ function Ht(e) {
2677
2905
  let t = typeof e == "number" ? e / 1e6 : Date.parse(String(e));
2678
2906
  return !Number.isFinite(t) || t <= 0 ? String(e ?? "") : new Date(t).toLocaleString();
2679
2907
  }
2680
- function Nt({ chunkId: e, chunkTitle: t, scope: n, browse: i, onClose: a }) {
2681
- let s = ee(), [d, f] = o([]), [p, m] = o(!0), [h, g] = o(null), [_, v] = o("none"), [y, b] = o(null), [x, S] = o(""), [C, w] = o(!1), [T, E] = o(null), [D, O] = o(null), [k, A] = o("");
2908
+ function Ut({ chunkId: e, chunkTitle: t, scope: n, browse: i, onClose: a }) {
2909
+ let s = M(), [d, f] = o([]), [p, m] = o(!0), [h, g] = o(null), [_, v] = o("none"), [y, b] = o(null), [x, S] = o(""), [C, w] = o(!1), [T, E] = o(null), [D, O] = o(null), [k, A] = o("");
2682
2910
  r(() => {
2683
2911
  let t = !1;
2684
2912
  return m(!0), g(null), s.documentHistory(e, n, i).then((e) => {
@@ -2707,7 +2935,7 @@ function Nt({ chunkId: e, chunkTitle: t, scope: n, browse: i, onClose: a }) {
2707
2935
  } finally {
2708
2936
  w(!1);
2709
2937
  }
2710
- }, te = async () => {
2938
+ }, N = async () => {
2711
2939
  if (T !== null && D !== null) {
2712
2940
  g(null), w(!0), v("diff");
2713
2941
  try {
@@ -2762,7 +2990,7 @@ function Nt({ chunkId: e, chunkTitle: t, scope: n, browse: i, onClose: a }) {
2762
2990
  }),
2763
2991
  /* @__PURE__ */ l("span", {
2764
2992
  className: "doc-hist-rev-time",
2765
- children: Mt(e.created_at)
2993
+ children: Ht(e.created_at)
2766
2994
  }),
2767
2995
  /* @__PURE__ */ l("span", {
2768
2996
  className: "doc-hist-rev-actor",
@@ -2799,7 +3027,7 @@ function Nt({ chunkId: e, chunkTitle: t, scope: n, browse: i, onClose: a }) {
2799
3027
  }),
2800
3028
  /* @__PURE__ */ l("button", {
2801
3029
  type: "button",
2802
- onClick: () => void te(),
3030
+ onClick: () => void N(),
2803
3031
  disabled: C || T === null || D === null,
2804
3032
  children: "diff"
2805
3033
  })
@@ -2810,7 +3038,7 @@ function Nt({ chunkId: e, chunkTitle: t, scope: n, browse: i, onClose: a }) {
2810
3038
  children: C ? /* @__PURE__ */ l("p", {
2811
3039
  className: "doc-empty-body",
2812
3040
  children: "loading…"
2813
- }) : _ === "diff" ? /* @__PURE__ */ l(Pt, { text: k }) : _ === "version" ? /* @__PURE__ */ l("pre", {
3041
+ }) : _ === "diff" ? /* @__PURE__ */ l(Wt, { text: k }) : _ === "version" ? /* @__PURE__ */ l("pre", {
2814
3042
  className: "md-pre doc-hist-version",
2815
3043
  children: /* @__PURE__ */ l("code", { children: x || "(empty)" })
2816
3044
  }) : /* @__PURE__ */ l("p", {
@@ -2823,7 +3051,7 @@ function Nt({ chunkId: e, chunkTitle: t, scope: n, browse: i, onClose: a }) {
2823
3051
  })
2824
3052
  });
2825
3053
  }
2826
- function Pt({ text: e }) {
3054
+ function Wt({ text: e }) {
2827
3055
  if (!e.trim()) return /* @__PURE__ */ l("p", {
2828
3056
  className: "doc-empty-body",
2829
3057
  children: "(no differences)"
@@ -2842,17 +3070,17 @@ function Pt({ text: e }) {
2842
3070
  }
2843
3071
  //#endregion
2844
3072
  //#region src/components/Markdown.tsx
2845
- function Ft({ source: e }) {
3073
+ function Gt({ source: e }) {
2846
3074
  return /* @__PURE__ */ l("div", {
2847
3075
  className: "md",
2848
3076
  children: /* @__PURE__ */ l(f, {
2849
3077
  remarkPlugins: [p],
2850
- components: It,
3078
+ components: Kt,
2851
3079
  children: e
2852
3080
  })
2853
3081
  });
2854
3082
  }
2855
- var It = {
3083
+ var Kt = {
2856
3084
  a({ href: e, children: t }) {
2857
3085
  let n = e ?? "", r = /^https?:\/\//i.test(n);
2858
3086
  return /* @__PURE__ */ l("a", {
@@ -2867,7 +3095,7 @@ var It = {
2867
3095
  },
2868
3096
  code({ className: e, children: t }) {
2869
3097
  let n = /language-(\w+)/.exec(e ?? "")?.[1], r = String(t ?? "");
2870
- return n === "mermaid" ? /* @__PURE__ */ l(qe, { code: r.replace(/\n$/, "") }) : n || r.includes("\n") ? /* @__PURE__ */ l("pre", {
3098
+ return n === "mermaid" ? /* @__PURE__ */ l(rt, { code: r.replace(/\n$/, "") }) : n || r.includes("\n") ? /* @__PURE__ */ l("pre", {
2871
3099
  className: "md-pre",
2872
3100
  children: /* @__PURE__ */ l("code", {
2873
3101
  className: e,
@@ -2878,70 +3106,70 @@ var It = {
2878
3106
  };
2879
3107
  //#endregion
2880
3108
  //#region src/components/DocumentViewerBody.tsx
2881
- function Lt(e) {
3109
+ function qt(e) {
2882
3110
  let t = e.fields ?? {};
2883
3111
  return typeof t.alt == "string" && t.alt.trim() !== "" ? t.alt : e.title || "image";
2884
3112
  }
2885
- function Rt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, renderAssistant: p, initialChunkId: m, onOpenDocument: h, onTitle: g, onChunkSelect: v, focusChunk: y }) {
2886
- let b = ee(), x = i(() => d && (d.scopeId || d.tenant) ? {
3113
+ function Jt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, renderAssistant: p, initialChunkId: m, onOpenDocument: h, onTitle: g, onChunkSelect: v, focusChunk: y }) {
3114
+ let b = M(), x = i(() => d && (d.scopeId || d.tenant) ? {
2887
3115
  scopeId: d.scopeId,
2888
3116
  tenant: d.tenant
2889
- } : void 0, [d?.scopeId, d?.tenant]), [S, C] = o([]), [w, T] = o(void 0), [E, D] = o(null), [O, k] = o("chunks"), [A, j] = o(null), [te, ne] = o(null), [re, ie] = o(null), M = a(null), [ae, oe] = o(null), [N, P] = o(null), [se, ce] = o(!1), [le, F] = o(!1), [ue, I] = o(null), [de, L] = o(!1), [fe, z] = o(void 0), [B, V] = o(null), [he, _e] = o(0), [ve, ye] = o(!1), [W, G] = o(null), [be, xe] = o(!1), [Se, K] = o([]), [Ce, we] = o(!1), [Te, Ee] = o(0), [De, Oe] = o(0), [ke, Ae] = o(void 0), q = t(() => _e((e) => e + 1), []), J = a(m);
2890
- J.current = m;
2891
- let Pe = a(g);
2892
- Pe.current = g;
2893
- let Y = i(() => Be(S), [S]), Fe = i(() => S.find((e) => !e.parent_id)?.title || s || "document", [S, s]), X = i(() => !!E && !E.parent_id, [E]), Z = i(() => ge(S, E?.id), [S, E]), Q = i(() => W?.root_chunk_id ?? S.find((e) => !e.parent_id)?.id, [W, S]), Ve = a(v);
2894
- Ve.current = v, r(() => {
2895
- w && Ve.current?.(w === Q ? void 0 : w);
2896
- }, [w, Q]);
2897
- let Ue = i(() => [...new Set(S.map((e) => e.status).filter((e) => !!e))], [S]), We = !!W?.color_enabled, Ge = i(() => {
3117
+ } : void 0, [d?.scopeId, d?.tenant]), [S, C] = o([]), [w, T] = o(void 0), [E, D] = o(null), [O, k] = o("chunks"), [A, j] = o(null), [N, P] = o(null), [F, ee] = o(null), te = a(null), [ne, re] = o(null), [ie, ae] = o(null), [I, L] = o(!1), [oe, se] = o(!1), [R, z] = o(null), [ce, le] = o(!1), [ue, B] = o(void 0), [de, V] = o(null), [fe, H] = o(0), [pe, me] = o(!1), [W, ge] = o(null), [G, ye] = o(!1), [K, Se] = o([]), [Ce, we] = o(!1), [q, Te] = o(0), [Ee, De] = o(0), [Oe, ke] = o(void 0), J = t(() => H((e) => e + 1), []), Ae = a(m);
3118
+ Ae.current = m;
3119
+ let je = a(g);
3120
+ je.current = g;
3121
+ let Me = i(() => Ye(S), [S]), Ne = i(() => S.find((e) => !e.parent_id)?.title || s || "document", [S, s]), Y = i(() => !!E && !E.parent_id, [E]), Pe = i(() => xe(S, E?.id), [S, E]), X = i(() => W?.root_chunk_id ?? S.find((e) => !e.parent_id)?.id, [W, S]), Re = a(v);
3122
+ Re.current = v, r(() => {
3123
+ w && Re.current?.(w === X ? void 0 : w);
3124
+ }, [w, X]);
3125
+ let ze = i(() => [...new Set(S.map((e) => e.status).filter((e) => !!e))], [S]), Z = !!W?.color_enabled, Q = i(() => {
2898
3126
  let e = /* @__PURE__ */ new Set();
2899
- for (let t of Se) e.add(t.from_id), e.add(t.to_id);
3127
+ for (let t of K) e.add(t.from_id), e.add(t.to_id);
2900
3128
  return e;
2901
- }, [Se]), Ke = i(() => We ? Re(Le(W?.type, W?.status, Ie(W?.color_scheme))) : void 0, [
2902
- We,
3129
+ }, [K]), He = i(() => Z ? Ve(W?.type, W?.status, Be(W?.color_scheme)) : void 0, [
3130
+ Z,
2903
3131
  W?.type,
2904
3132
  W?.status,
2905
3133
  W?.color_scheme
2906
- ]);
3134
+ ]), Ue = i(() => Ge(He), [He]);
2907
3135
  r(() => {
2908
3136
  let t = !1;
2909
- return L(!0), I(null), V(null), b.documentQueryChunks(e, n, x).then((r) => {
3137
+ return le(!0), z(null), V(null), b.documentQueryChunks(e, n, x).then((r) => {
2910
3138
  if (t) return;
2911
3139
  let i = r.chunks ?? [];
2912
- C(i), z(`${n}:${e}`), T((e) => e ?? R(i, J.current));
3140
+ C(i), B(`${n}:${e}`), T((e) => e ?? U(i, Ae.current));
2913
3141
  }).catch((e) => {
2914
3142
  t || (C([]), V(e instanceof Error ? e.message : String(e)));
2915
- }).finally(() => !t && L(!1)), () => {
3143
+ }).finally(() => !t && le(!1)), () => {
2916
3144
  t = !0;
2917
3145
  };
2918
3146
  }, [
2919
3147
  b,
2920
3148
  e,
2921
3149
  n,
2922
- he,
3150
+ fe,
2923
3151
  x
2924
3152
  ]);
2925
- let Xe = !de && (B !== null || fe === `${n}:${e}` && S.length === 0), Ze = i(() => S.find((t) => !t.parent_id && t.document_id === e)?.title, [S, e]);
3153
+ let We = !ce && (de !== null || ue === `${n}:${e}` && S.length === 0), Ke = i(() => S.find((t) => !t.parent_id && t.document_id === e)?.title, [S, e]);
2926
3154
  r(() => {
2927
- Ze && Pe.current?.(e, Ze);
2928
- }, [e, Ze]), r(() => {
3155
+ Ke && je.current?.(e, Ke);
3156
+ }, [e, Ke]), r(() => {
2929
3157
  let t = !1;
2930
- return b.documentGet(e, n, x).then((e) => !t && G(e)).catch(() => !t && G(null)), () => {
3158
+ return b.documentGet(e, n, x).then((e) => !t && ge(e)).catch(() => !t && ge(null)), () => {
2931
3159
  t = !0;
2932
3160
  };
2933
3161
  }, [
2934
3162
  b,
2935
3163
  e,
2936
3164
  n,
2937
- he,
3165
+ fe,
2938
3166
  x
2939
3167
  ]), r(() => {
2940
3168
  let t = !1;
2941
- return U(b, e, n, x).then((e) => {
2942
- t || (K(e.edges), we(e.incomplete));
3169
+ return be(b, e, n, x).then((e) => {
3170
+ t || (Se(e.edges), we(e.incomplete));
2943
3171
  }).catch(() => {
2944
- t || (K([]), we(!1));
3172
+ t || (Se([]), we(!1));
2945
3173
  }), () => {
2946
3174
  t = !0;
2947
3175
  };
@@ -2949,73 +3177,73 @@ function Rt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, re
2949
3177
  b,
2950
3178
  e,
2951
3179
  n,
2952
- he,
3180
+ fe,
2953
3181
  x,
2954
- Te
3182
+ q
2955
3183
  ]), r(() => {
2956
- if (!Q || !b.documentAcceptClassification) {
2957
- Ae(void 0);
3184
+ if (!X || !b.documentAcceptClassification) {
3185
+ ke(void 0);
2958
3186
  return;
2959
3187
  }
2960
3188
  let t = !1;
2961
- return b.documentGetChunk(Q, n, x).then((n) => !t && Ae(n.document_id === e ? n.fields : void 0)).catch(() => !t && Ae(void 0)), () => {
3189
+ return b.documentGetChunk(X, n, x).then((n) => !t && ke(n.document_id === e ? n.fields : void 0)).catch(() => !t && ke(void 0)), () => {
2962
3190
  t = !0;
2963
3191
  };
2964
3192
  }, [
2965
3193
  b,
2966
3194
  e,
2967
- Q,
3195
+ X,
2968
3196
  n,
2969
- he,
3197
+ fe,
2970
3198
  x
2971
3199
  ]);
2972
- let Qe = i(() => {
3200
+ let qe = i(() => {
2973
3201
  if (b.documentAcceptStatement && b.documentRejectStatement) return async (e, t, r) => {
2974
- t ? await b.documentAcceptStatement(e, n, x, r) : await b.documentRejectStatement(e, r ?? "", n, x), Ee((e) => e + 1);
3202
+ t ? await b.documentAcceptStatement(e, n, x, r) : await b.documentRejectStatement(e, r ?? "", n, x), Te((e) => e + 1);
2975
3203
  };
2976
3204
  }, [
2977
3205
  b,
2978
3206
  n,
2979
3207
  x
2980
- ]), $e = i(() => je(b, n), [b, n]), et = i(() => Me(Se, e), [Se, e]), tt = t(() => Ee((e) => e + 1), []), nt = i(() => Ne($e, et, Ce, tt), [
2981
- $e,
2982
- et,
3208
+ ]), Je = i(() => Fe(b, n), [b, n]), Xe = i(() => Ie(K, e), [K, e]), $e = t(() => Te((e) => e + 1), []), et = i(() => Le(Je, Xe, Ce, $e), [
3209
+ Je,
3210
+ Xe,
2983
3211
  Ce,
2984
- tt
2985
- ]), rt = y?.seq, it = a(y);
2986
- it.current = y;
2987
- let at = a(Q);
2988
- at.current = Q, r(() => {
2989
- if (rt === void 0) return;
2990
- let e = it.current?.chunkId ?? at.current;
3212
+ $e
3213
+ ]), tt = y?.seq, nt = a(y);
3214
+ nt.current = y;
3215
+ let ot = a(X);
3216
+ ot.current = X, r(() => {
3217
+ if (tt === void 0) return;
3218
+ let e = nt.current?.chunkId ?? ot.current;
2991
3219
  e && T(e);
2992
- }, [rt]), r(() => {
2993
- T(void 0), D(null), j(null), k("chunks"), G(null), K([]), we(!1), Oe(0), Ae(void 0);
3220
+ }, [tt]), r(() => {
3221
+ T(void 0), D(null), j(null), k("chunks"), ge(null), Se([]), we(!1), De(0), ke(void 0);
2994
3222
  }, [e, n]), r(() => {
2995
3223
  if (!w) {
2996
3224
  D(null);
2997
3225
  return;
2998
3226
  }
2999
3227
  let e = !1;
3000
- return b.documentGetChunk(w, n, x).then((t) => !e && D(t)).catch((t) => !e && I(t instanceof Error ? t.message : String(t))), () => {
3228
+ return b.documentGetChunk(w, n, x).then((t) => !e && D(t)).catch((t) => !e && z(t instanceof Error ? t.message : String(t))), () => {
3001
3229
  e = !0;
3002
3230
  };
3003
3231
  }, [
3004
3232
  b,
3005
3233
  w,
3006
3234
  n,
3007
- he,
3235
+ fe,
3008
3236
  x
3009
3237
  ]), r(() => {
3010
3238
  let e = E?.type === "image" || !!E?.asset;
3011
3239
  if (!E || !e || !b.documentAssetObjectUrl) {
3012
- ne(null), ie(null);
3240
+ P(null), ee(null);
3013
3241
  return;
3014
3242
  }
3015
3243
  let t = !1, r = null;
3016
- return ie(null), b.documentAssetObjectUrl(E.id, n, x).then((e) => {
3017
- t ? URL.revokeObjectURL(e) : (r = e, ne(e));
3018
- }).catch((e) => !t && ie(e instanceof Error ? e.message : String(e))), () => {
3244
+ return ee(null), b.documentAssetObjectUrl(E.id, n, x).then((e) => {
3245
+ t ? URL.revokeObjectURL(e) : (r = e, P(e));
3246
+ }).catch((e) => !t && ee(e instanceof Error ? e.message : String(e))), () => {
3019
3247
  t = !0, r && URL.revokeObjectURL(r);
3020
3248
  };
3021
3249
  }, [
@@ -3028,7 +3256,7 @@ function Rt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, re
3028
3256
  j(null);
3029
3257
  return;
3030
3258
  }
3031
- let e = He(Y, w);
3259
+ let e = Ze(Me, w);
3032
3260
  if (!e) return;
3033
3261
  let t = !1, r = [], i = (e, t) => {
3034
3262
  r.push({
@@ -3048,37 +3276,37 @@ function Rt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, re
3048
3276
  return a + (i.body ? "\n\n" + i.body : "") + "\n";
3049
3277
  }).join("\n");
3050
3278
  j(n);
3051
- }).catch((e) => !t && I(e instanceof Error ? e.message : String(e))), () => {
3279
+ }).catch((e) => !t && z(e instanceof Error ? e.message : String(e))), () => {
3052
3280
  t = !0;
3053
3281
  };
3054
3282
  }, [
3055
3283
  b,
3056
3284
  O,
3057
3285
  w,
3058
- Y,
3286
+ Me,
3059
3287
  n,
3060
- he,
3288
+ fe,
3061
3289
  x
3062
3290
  ]);
3063
- let ot = t((e) => T(e.row.id), []), st = t((t, n, r) => h?.({
3291
+ let st = t((e) => T(e.row.id), []), ct = t((t, n, r) => h?.({
3064
3292
  documentId: t,
3065
3293
  chunkId: n,
3066
3294
  title: r
3067
3295
  }, {
3068
3296
  documentId: e,
3069
3297
  chunkId: w,
3070
- title: Fe
3298
+ title: Ne
3071
3299
  }), [
3072
3300
  h,
3073
3301
  e,
3074
3302
  w,
3075
- Fe
3076
- ]), ct = t(async () => {
3303
+ Ne
3304
+ ]), lt = t(async () => {
3077
3305
  try {
3078
3306
  let t = await b.documentExportMd(e, n, !0, x), r = new Blob([t.markdown], { type: "text/markdown" }), i = URL.createObjectURL(r), a = document.createElement("a");
3079
3307
  a.href = i, a.download = (t.title || "document").replace(/[^\w.-]+/g, "_") + ".md", a.click(), URL.revokeObjectURL(i);
3080
3308
  } catch (e) {
3081
- I(e instanceof Error ? e.message : String(e));
3309
+ z(e instanceof Error ? e.message : String(e));
3082
3310
  }
3083
3311
  }, [
3084
3312
  b,
@@ -3088,29 +3316,29 @@ function Rt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, re
3088
3316
  ]), ut = t(async () => {
3089
3317
  try {
3090
3318
  let t = await b.documentExportCanvas(e, n, x), r = new Blob([JSON.stringify(t.canvas, null, 2)], { type: "application/json" }), i = URL.createObjectURL(r), a = document.createElement("a");
3091
- a.href = i, a.download = (Fe || "document").replace(/[^\w.-]+/g, "_") + ".canvas", a.click(), URL.revokeObjectURL(i);
3319
+ a.href = i, a.download = (Ne || "document").replace(/[^\w.-]+/g, "_") + ".canvas", a.click(), URL.revokeObjectURL(i);
3092
3320
  } catch (e) {
3093
- I(e instanceof Error ? e.message : String(e));
3321
+ z(e instanceof Error ? e.message : String(e));
3094
3322
  }
3095
3323
  }, [
3096
3324
  b,
3097
3325
  e,
3098
3326
  n,
3099
3327
  x,
3100
- Fe
3101
- ]), dt = !!b.documentCreateChunk && !!Q, pt = t(async (t) => {
3328
+ Ne
3329
+ ]), dt = !!b.documentCreateChunk && !!X, ft = t(async (t) => {
3102
3330
  if (!b.documentCreateChunk || !b.documentSetAsset) return;
3103
- let r = w || Q;
3331
+ let r = w || X;
3104
3332
  if (r) {
3105
- I(null);
3333
+ z(null);
3106
3334
  try {
3107
- let { mediaType: i, data: a } = await H(t), o = await b.documentCreateChunk(e, r, {
3335
+ let { mediaType: i, data: a } = await _e(t), o = await b.documentCreateChunk(e, r, {
3108
3336
  title: t.name || "image",
3109
3337
  type: "image"
3110
3338
  }, n, x);
3111
- await b.documentSetAsset(o.id, i, a, t.name, n, x), q(), T(o.id);
3339
+ await b.documentSetAsset(o.id, i, a, t.name, n, x), J(), T(o.id);
3112
3340
  } catch (e) {
3113
- I(e instanceof Error ? e.message : String(e));
3341
+ z(e instanceof Error ? e.message : String(e));
3114
3342
  }
3115
3343
  }
3116
3344
  }, [
@@ -3119,22 +3347,22 @@ function Rt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, re
3119
3347
  n,
3120
3348
  x,
3121
3349
  w,
3122
- Q,
3123
- q
3124
- ]), mt = t(async () => {
3350
+ X,
3351
+ J
3352
+ ]), pt = t(async () => {
3125
3353
  if (!b.documentCreateChunk) return;
3126
- let t = w || Q;
3354
+ let t = w || X;
3127
3355
  if (t) {
3128
- I(null);
3356
+ z(null);
3129
3357
  try {
3130
3358
  let r = await b.documentCreateChunk(e, t, {
3131
3359
  title: "Diagram",
3132
3360
  type: "mermaid",
3133
3361
  body: "graph TD\n A[Start] --> B[End]"
3134
3362
  }, n, x);
3135
- q(), T(r.id), oe(r);
3363
+ J(), T(r.id), re(r);
3136
3364
  } catch (e) {
3137
- I(e instanceof Error ? e.message : String(e));
3365
+ z(e instanceof Error ? e.message : String(e));
3138
3366
  }
3139
3367
  }
3140
3368
  }, [
@@ -3143,21 +3371,21 @@ function Rt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, re
3143
3371
  n,
3144
3372
  x,
3145
3373
  w,
3146
- Q,
3147
- q
3148
- ]), ht = t(async () => {
3374
+ X,
3375
+ J
3376
+ ]), mt = t(async () => {
3149
3377
  if (!b.documentCreateChunk) return;
3150
- let t = w && !X ? w : void 0, r = w || Q;
3378
+ let t = w && !Y ? w : void 0, r = w || X;
3151
3379
  if (r) {
3152
- I(null);
3380
+ z(null);
3153
3381
  try {
3154
3382
  let i = await b.documentCreateChunk(e, t ? "" : r, {
3155
3383
  title: "Text",
3156
3384
  body: ""
3157
3385
  }, n, x, t);
3158
- q(), T(i.id), oe(i);
3386
+ J(), T(i.id), re(i);
3159
3387
  } catch (e) {
3160
- I(e instanceof Error ? e.message : String(e));
3388
+ z(e instanceof Error ? e.message : String(e));
3161
3389
  }
3162
3390
  }
3163
3391
  }, [
@@ -3166,20 +3394,20 @@ function Rt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, re
3166
3394
  n,
3167
3395
  x,
3168
3396
  w,
3397
+ Y,
3169
3398
  X,
3170
- Q,
3171
- q
3172
- ]), gt = t(async () => {
3399
+ J
3400
+ ]), ht = t(async () => {
3173
3401
  if (b.documentCreateChunk && w) {
3174
- I(null);
3402
+ z(null);
3175
3403
  try {
3176
3404
  let t = await b.documentCreateChunk(e, w, {
3177
3405
  title: "Text",
3178
3406
  body: ""
3179
3407
  }, n, x);
3180
- q(), T(t.id), oe(t);
3408
+ J(), T(t.id), re(t);
3181
3409
  } catch (e) {
3182
- I(e instanceof Error ? e.message : String(e));
3410
+ z(e instanceof Error ? e.message : String(e));
3183
3411
  }
3184
3412
  }
3185
3413
  }, [
@@ -3188,9 +3416,9 @@ function Rt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, re
3188
3416
  n,
3189
3417
  x,
3190
3418
  w,
3191
- q
3192
- ]), _t = i(() => {
3193
- if (!E || X) return {
3419
+ J
3420
+ ]), gt = i(() => {
3421
+ if (!E || Y) return {
3194
3422
  canUp: !1,
3195
3423
  canDown: !1
3196
3424
  };
@@ -3202,14 +3430,14 @@ function Rt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, re
3202
3430
  }, [
3203
3431
  S,
3204
3432
  E,
3205
- X
3206
- ]), vt = t(async (e) => {
3433
+ Y
3434
+ ]), _t = t(async (e) => {
3207
3435
  if (b.documentReorderChunk && w) {
3208
- I(null);
3436
+ z(null);
3209
3437
  try {
3210
- await b.documentReorderChunk(w, e, n, x), q();
3438
+ await b.documentReorderChunk(w, e, n, x), J();
3211
3439
  } catch (e) {
3212
- I(e instanceof Error ? e.message : String(e));
3440
+ z(e instanceof Error ? e.message : String(e));
3213
3441
  }
3214
3442
  }
3215
3443
  }, [
@@ -3217,62 +3445,62 @@ function Rt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, re
3217
3445
  w,
3218
3446
  n,
3219
3447
  x,
3220
- q
3221
- ]), yt = t(async () => {
3448
+ J
3449
+ ]), vt = t(async () => {
3222
3450
  if (!b.documentDeleteChunk || !E) return;
3223
- I(null);
3451
+ z(null);
3224
3452
  let e = E.parent_id;
3225
3453
  try {
3226
- await b.documentDeleteChunk(E.id, n, x), F(!1), T(e || Q), q();
3454
+ await b.documentDeleteChunk(E.id, n, x), se(!1), T(e || X), J();
3227
3455
  } catch (e) {
3228
- I(e instanceof Error ? e.message : String(e)), F(!1);
3456
+ z(e instanceof Error ? e.message : String(e)), se(!1);
3229
3457
  }
3230
3458
  }, [
3231
3459
  b,
3232
3460
  E,
3233
3461
  n,
3234
3462
  x,
3235
- Q,
3236
- q
3463
+ X,
3464
+ J
3237
3465
  ]);
3238
3466
  return r(() => {
3239
3467
  if (!dt) return;
3240
3468
  let e = (e) => {
3241
- if (ae || be) return;
3469
+ if (ne || G) return;
3242
3470
  let t = document.activeElement, n = t?.tagName;
3243
3471
  if (n === "INPUT" || n === "TEXTAREA" || t?.isContentEditable) return;
3244
- let r = me(e.clipboardData?.items);
3245
- r && (e.preventDefault(), pt(r));
3472
+ let r = ve(e.clipboardData?.items);
3473
+ r && (e.preventDefault(), ft(r));
3246
3474
  };
3247
3475
  return window.addEventListener("paste", e), () => window.removeEventListener("paste", e);
3248
3476
  }, [
3249
3477
  dt,
3250
- ae,
3251
- be,
3252
- pt
3478
+ ne,
3479
+ G,
3480
+ ft
3253
3481
  ]), /* @__PURE__ */ u("div", {
3254
3482
  className: "doc-viewer",
3255
3483
  children: [
3256
3484
  /* @__PURE__ */ l("input", {
3257
- ref: M,
3485
+ ref: te,
3258
3486
  type: "file",
3259
3487
  accept: "image/png,image/jpeg,image/gif,image/webp",
3260
3488
  style: { display: "none" },
3261
3489
  onChange: (e) => {
3262
3490
  let t = e.target.files?.[0];
3263
- e.target.value = "", t && pt(t);
3491
+ e.target.value = "", t && ft(t);
3264
3492
  }
3265
3493
  }),
3266
3494
  /* @__PURE__ */ u("div", {
3267
3495
  className: "doc-toolbar",
3268
- style: Ke,
3496
+ style: Ue,
3269
3497
  children: [
3270
3498
  /* @__PURE__ */ l("strong", {
3271
3499
  className: "doc-title",
3272
- title: Fe,
3273
- children: Fe
3500
+ title: Ne,
3501
+ children: Ne
3274
3502
  }),
3275
- /* @__PURE__ */ l(ze, {
3503
+ /* @__PURE__ */ l($, {
3276
3504
  value: e,
3277
3505
  label: "doc"
3278
3506
  }),
@@ -3282,48 +3510,48 @@ function Rt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, re
3282
3510
  dt && /* @__PURE__ */ u(c, { children: [
3283
3511
  /* @__PURE__ */ l("button", {
3284
3512
  type: "button",
3285
- onClick: () => void ht(),
3513
+ onClick: () => void mt(),
3286
3514
  title: "Add a text chunk AFTER the selected chunk, at the same level",
3287
3515
  children: "+ text"
3288
3516
  }),
3289
3517
  /* @__PURE__ */ l("button", {
3290
3518
  type: "button",
3291
- onClick: () => void gt(),
3519
+ onClick: () => void ht(),
3292
3520
  disabled: !w,
3293
3521
  title: w ? "Add a chunk NESTED UNDER the selected chunk (in the ontology, a child is a subclass)" : "Select a chunk first — this nests a new chunk under it",
3294
3522
  children: "+ child"
3295
3523
  }),
3296
3524
  /* @__PURE__ */ l("button", {
3297
3525
  type: "button",
3298
- onClick: () => M.current?.click(),
3526
+ onClick: () => te.current?.click(),
3299
3527
  title: "Add an image chunk (upload — or paste a screenshot into the view)",
3300
3528
  children: "+ image"
3301
3529
  }),
3302
3530
  /* @__PURE__ */ l("button", {
3303
3531
  type: "button",
3304
- onClick: () => void mt(),
3532
+ onClick: () => void pt(),
3305
3533
  title: "Add a Mermaid diagram chunk",
3306
3534
  children: "+ diagram"
3307
3535
  })
3308
3536
  ] }),
3309
3537
  /* @__PURE__ */ l("button", {
3310
3538
  type: "button",
3311
- className: We ? "active" : "",
3312
- onClick: () => xe(!0),
3313
- disabled: !Q,
3539
+ className: Z ? "active" : "",
3540
+ onClick: () => ye(!0),
3541
+ disabled: !X,
3314
3542
  title: "Colors — tint chunk tiles + the Path tree by type/status",
3315
3543
  children: "colors"
3316
3544
  }),
3317
3545
  b.documentClassify && /* @__PURE__ */ l("button", {
3318
3546
  type: "button",
3319
- className: De > 0 ? "active" : "",
3320
- onClick: () => Oe((e) => e > 0 ? 0 : 1),
3547
+ className: Ee > 0 ? "active" : "",
3548
+ onClick: () => De((e) => e > 0 ? 0 : 1),
3321
3549
  title: "Classify — what this document is, by the confirmed ontology (a report first; nothing is written until Apply)",
3322
3550
  children: "classify"
3323
3551
  }),
3324
3552
  /* @__PURE__ */ l("button", {
3325
3553
  type: "button",
3326
- onClick: () => void ct(),
3554
+ onClick: () => void lt(),
3327
3555
  title: "Download the whole document as Markdown (.md)",
3328
3556
  children: "↓ .md"
3329
3557
  }),
@@ -3335,14 +3563,14 @@ function Rt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, re
3335
3563
  }),
3336
3564
  p && /* @__PURE__ */ l("button", {
3337
3565
  type: "button",
3338
- className: ve ? "active" : "",
3339
- onClick: () => ye((e) => !e),
3566
+ className: pe ? "active" : "",
3567
+ onClick: () => me((e) => !e),
3340
3568
  title: "Document Assistant — instruct an agent to restructure/import/link chunks",
3341
3569
  children: "assistant"
3342
3570
  }),
3343
3571
  /* @__PURE__ */ l("button", {
3344
3572
  type: "button",
3345
- onClick: q,
3573
+ onClick: J,
3346
3574
  title: "Reload",
3347
3575
  children: "↻"
3348
3576
  })
@@ -3350,24 +3578,24 @@ function Rt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, re
3350
3578
  })
3351
3579
  ]
3352
3580
  }),
3353
- ue && /* @__PURE__ */ l("div", {
3581
+ R && /* @__PURE__ */ l("div", {
3354
3582
  className: "paths-err",
3355
- children: ue
3583
+ children: R
3356
3584
  }),
3357
- !Xe && /* @__PURE__ */ l(lt, {
3585
+ !We && /* @__PURE__ */ l(yt, {
3358
3586
  documentId: e,
3359
3587
  scope: n,
3360
3588
  browse: x,
3361
- rootFields: ke,
3362
- requestKey: De,
3363
- onClose: () => Oe(0),
3364
- onChanged: q
3589
+ rootFields: Oe,
3590
+ requestKey: Ee,
3591
+ onClose: () => De(0),
3592
+ onChanged: J
3365
3593
  }, `${n}:${e}`),
3366
- Xe ? /* @__PURE__ */ l(jt, {
3594
+ We ? /* @__PURE__ */ l(Vt, {
3367
3595
  documentId: e,
3368
3596
  scope: n,
3369
- detail: B ?? void 0
3370
- }) : /* @__PURE__ */ u(pe, {
3597
+ detail: de ?? void 0
3598
+ }) : /* @__PURE__ */ u(he, {
3371
3599
  className: "doc-split",
3372
3600
  defaultLeftWidth: 320,
3373
3601
  minLeftWidth: 160,
@@ -3375,16 +3603,17 @@ function Rt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, re
3375
3603
  storageKey: "loomcycle.explorer.split.doc",
3376
3604
  children: [/* @__PURE__ */ l("div", {
3377
3605
  className: "doc-chunktree",
3378
- children: de && S.length === 0 ? /* @__PURE__ */ l("div", {
3606
+ children: ce && S.length === 0 ? /* @__PURE__ */ l("div", {
3379
3607
  className: "empty",
3380
3608
  children: /* @__PURE__ */ l("p", { children: "Loading…" })
3381
- }) : /* @__PURE__ */ l($, {
3382
- tree: Y,
3609
+ }) : /* @__PURE__ */ l(Qe, {
3610
+ tree: Me,
3383
3611
  selectedId: w,
3384
- onSelect: ot,
3385
- colorEnabled: We,
3612
+ onSelect: st,
3613
+ colorEnabled: Z,
3386
3614
  scheme: W?.color_scheme,
3387
- linkedIds: Ge
3615
+ documentColor: He,
3616
+ linkedIds: Q
3388
3617
  })
3389
3618
  }), /* @__PURE__ */ l("div", {
3390
3619
  className: "doc-content",
@@ -3392,18 +3621,18 @@ function Rt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, re
3392
3621
  /* @__PURE__ */ u("div", {
3393
3622
  className: "doc-content-head",
3394
3623
  children: [
3395
- Z.length > 0 && /* @__PURE__ */ u("nav", {
3624
+ Pe.length > 0 && /* @__PURE__ */ u("nav", {
3396
3625
  className: "chunk-ancestry",
3397
3626
  "aria-label": "Chunks above this one",
3398
3627
  children: [/* @__PURE__ */ l("button", {
3399
3628
  type: "button",
3400
3629
  className: "chunk-ancestry-up",
3401
- onClick: () => T(Z[Z.length - 1].id),
3402
- title: `Up to ${Z[Z.length - 1].title || "(untitled)"}`,
3630
+ onClick: () => T(Pe[Pe.length - 1].id),
3631
+ title: `Up to ${Pe[Pe.length - 1].title || "(untitled)"}`,
3403
3632
  children: "↰ Up"
3404
3633
  }), /* @__PURE__ */ u("ol", {
3405
3634
  className: "doc-trail-list",
3406
- children: [Z.map((e) => /* @__PURE__ */ l("li", {
3635
+ children: [Pe.map((e) => /* @__PURE__ */ l("li", {
3407
3636
  className: "doc-trail-item",
3408
3637
  children: /* @__PURE__ */ l("button", {
3409
3638
  type: "button",
@@ -3443,7 +3672,7 @@ function Rt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, re
3443
3672
  className: "chunk-tag",
3444
3673
  children: e
3445
3674
  }, e)),
3446
- /* @__PURE__ */ l(ze, {
3675
+ /* @__PURE__ */ l($, {
3447
3676
  value: E.id,
3448
3677
  label: "chunk"
3449
3678
  })
@@ -3464,45 +3693,45 @@ function Rt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, re
3464
3693
  type: "button",
3465
3694
  className: O === "markdown" ? "active" : "",
3466
3695
  onClick: () => k("markdown"),
3467
- title: X ? "Whole document as Markdown" : "This chunk + its sub-chunks as Markdown",
3696
+ title: Y ? "Whole document as Markdown" : "This chunk + its sub-chunks as Markdown",
3468
3697
  children: "markdown"
3469
3698
  })]
3470
3699
  }),
3471
3700
  /* @__PURE__ */ l("button", {
3472
3701
  type: "button",
3473
3702
  className: "chunk-edit",
3474
- onClick: () => oe(E),
3703
+ onClick: () => re(E),
3475
3704
  children: "edit"
3476
3705
  }),
3477
3706
  b.documentEntityTypes && _(E) && /* @__PURE__ */ l("button", {
3478
3707
  type: "button",
3479
- onClick: () => P(E),
3708
+ onClick: () => ae(E),
3480
3709
  title: "Change this subject's type to another type in force",
3481
3710
  children: "change type"
3482
3711
  }),
3483
3712
  /* @__PURE__ */ l("button", {
3484
3713
  type: "button",
3485
- onClick: () => ce(!0),
3714
+ onClick: () => L(!0),
3486
3715
  title: "View this chunk's edit history + diffs",
3487
3716
  children: "history"
3488
3717
  }),
3489
- !X && /* @__PURE__ */ u(c, { children: [/* @__PURE__ */ l("button", {
3718
+ !Y && /* @__PURE__ */ u(c, { children: [/* @__PURE__ */ l("button", {
3490
3719
  type: "button",
3491
- onClick: () => void vt("up"),
3492
- disabled: !_t.canUp,
3720
+ onClick: () => void _t("up"),
3721
+ disabled: !gt.canUp,
3493
3722
  title: "Move this chunk up within its level",
3494
3723
  children: "↑"
3495
3724
  }), /* @__PURE__ */ l("button", {
3496
3725
  type: "button",
3497
- onClick: () => void vt("down"),
3498
- disabled: !_t.canDown,
3726
+ onClick: () => void _t("down"),
3727
+ disabled: !gt.canDown,
3499
3728
  title: "Move this chunk down within its level",
3500
3729
  children: "↓"
3501
3730
  })] }),
3502
- !X && /* @__PURE__ */ l("button", {
3731
+ !Y && /* @__PURE__ */ l("button", {
3503
3732
  type: "button",
3504
3733
  className: "danger",
3505
- onClick: () => F(!0),
3734
+ onClick: () => se(!0),
3506
3735
  title: "Delete this chunk and its sub-chunks",
3507
3736
  children: "delete"
3508
3737
  })
@@ -3512,20 +3741,20 @@ function Rt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, re
3512
3741
  }),
3513
3742
  /* @__PURE__ */ l("div", {
3514
3743
  className: "doc-content-body",
3515
- children: E.type === "mermaid" ? E.body ? /* @__PURE__ */ u(c, { children: [/* @__PURE__ */ l(qe, { code: E.body }), O === "markdown" && /* @__PURE__ */ l("pre", {
3744
+ children: E.type === "mermaid" ? E.body ? /* @__PURE__ */ u(c, { children: [/* @__PURE__ */ l(rt, { code: E.body }), O === "markdown" && /* @__PURE__ */ l("pre", {
3516
3745
  className: "md-pre doc-mermaid-source",
3517
3746
  children: /* @__PURE__ */ l("code", { children: E.body })
3518
3747
  })] }) : /* @__PURE__ */ l("p", {
3519
3748
  className: "doc-empty-body",
3520
3749
  children: "(empty diagram)"
3521
- }) : E.type === "image" || E.asset ? re ? /* @__PURE__ */ u("p", {
3750
+ }) : E.type === "image" || E.asset ? F ? /* @__PURE__ */ u("p", {
3522
3751
  className: "doc-empty-body",
3523
- children: ["Image failed to load: ", re]
3524
- }) : te ? /* @__PURE__ */ u("figure", {
3752
+ children: ["Image failed to load: ", F]
3753
+ }) : N ? /* @__PURE__ */ u("figure", {
3525
3754
  className: "doc-image",
3526
3755
  children: [/* @__PURE__ */ l("img", {
3527
- src: te,
3528
- alt: Lt(E)
3756
+ src: N,
3757
+ alt: qt(E)
3529
3758
  }), E.body && /* @__PURE__ */ l("figcaption", { children: E.body })]
3530
3759
  }) : /* @__PURE__ */ l("p", {
3531
3760
  className: "doc-empty-body",
@@ -3533,29 +3762,29 @@ function Rt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, re
3533
3762
  }) : O === "markdown" ? A === null ? /* @__PURE__ */ l("p", {
3534
3763
  className: "doc-empty-body",
3535
3764
  children: "Assembling Markdown…"
3536
- }) : /* @__PURE__ */ l(Ft, { source: A }) : E.body ? /* @__PURE__ */ l(Ft, { source: E.body }) : /* @__PURE__ */ l("p", {
3765
+ }) : /* @__PURE__ */ l(Gt, { source: A }) : E.body ? /* @__PURE__ */ l(Gt, { source: E.body }) : /* @__PURE__ */ l("p", {
3537
3766
  className: "doc-empty-body",
3538
3767
  children: "(empty chunk)"
3539
3768
  })
3540
3769
  }),
3541
- /* @__PURE__ */ l(Tt, {
3542
- edges: Se,
3770
+ /* @__PURE__ */ l(Ft, {
3771
+ edges: K,
3543
3772
  incomplete: Ce,
3544
3773
  documentId: e,
3545
3774
  selectedId: w,
3546
3775
  onSelectChunk: T,
3547
- onOpenDocument: h ? st : void 0,
3548
- onRuleStatement: Qe
3776
+ onOpenDocument: h ? ct : void 0,
3777
+ onRuleStatement: qe
3549
3778
  }),
3550
- /* @__PURE__ */ l(Ct, {
3779
+ /* @__PURE__ */ l(Nt, {
3551
3780
  documentId: e,
3552
3781
  selectedId: w,
3553
3782
  scope: n,
3554
3783
  browse: x,
3555
3784
  onSelectChunk: T,
3556
- onOpenDocument: h ? st : void 0,
3557
- refreshKey: Te,
3558
- review: nt
3785
+ onOpenDocument: h ? ct : void 0,
3786
+ refreshKey: q,
3787
+ review: et
3559
3788
  })
3560
3789
  ] }) : /* @__PURE__ */ l("div", {
3561
3790
  className: "empty",
@@ -3563,50 +3792,50 @@ function Rt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, re
3563
3792
  })
3564
3793
  })]
3565
3794
  }),
3566
- ve && p && /* @__PURE__ */ l("div", {
3795
+ pe && p && /* @__PURE__ */ l("div", {
3567
3796
  className: "doc-assistant",
3568
3797
  children: p({
3569
3798
  documentId: e,
3570
3799
  scope: n,
3571
3800
  subject: f?.subject,
3572
- onChanged: q
3801
+ onChanged: J
3573
3802
  })
3574
3803
  }),
3575
- ae && /* @__PURE__ */ l(Je, {
3576
- chunk: ae,
3804
+ ne && /* @__PURE__ */ l(it, {
3805
+ chunk: ne,
3577
3806
  scope: n,
3578
3807
  browse: x,
3579
- onClose: () => oe(null),
3580
- onSaved: q
3808
+ onClose: () => re(null),
3809
+ onSaved: J
3581
3810
  }),
3582
- N && /* @__PURE__ */ l(Ye, {
3583
- chunk: N,
3811
+ ie && /* @__PURE__ */ l(at, {
3812
+ chunk: ie,
3584
3813
  scope: n,
3585
3814
  browse: x,
3586
- onClose: () => P(null),
3587
- onSaved: q
3815
+ onClose: () => ae(null),
3816
+ onSaved: J
3588
3817
  }),
3589
- se && E && /* @__PURE__ */ l(Nt, {
3818
+ I && E && /* @__PURE__ */ l(Ut, {
3590
3819
  chunkId: E.id,
3591
3820
  chunkTitle: E.title,
3592
3821
  scope: n,
3593
3822
  browse: x,
3594
- onClose: () => ce(!1)
3823
+ onClose: () => L(!1)
3595
3824
  }),
3596
- be && Q && /* @__PURE__ */ l(ft, {
3825
+ G && X && /* @__PURE__ */ l(St, {
3597
3826
  documentId: e,
3598
- rootChunkId: Q,
3827
+ rootChunkId: X,
3599
3828
  docType: W?.type,
3600
3829
  docStatus: W?.status,
3601
- chunkStatuses: Ue,
3830
+ chunkStatuses: ze,
3602
3831
  scope: n,
3603
3832
  browse: x,
3604
- onClose: () => xe(!1),
3605
- onSaved: q
3833
+ onClose: () => ye(!1),
3834
+ onSaved: J
3606
3835
  }),
3607
- le && E && /* @__PURE__ */ l("div", {
3836
+ oe && E && /* @__PURE__ */ l("div", {
3608
3837
  className: "modal-overlay",
3609
- onClick: () => F(!1),
3838
+ onClick: () => se(!1),
3610
3839
  children: /* @__PURE__ */ u("div", {
3611
3840
  className: "modal chunk-delete-confirm",
3612
3841
  onClick: (e) => e.stopPropagation(),
@@ -3624,12 +3853,12 @@ function Rt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, re
3624
3853
  className: "modal-buttons",
3625
3854
  children: [/* @__PURE__ */ l("button", {
3626
3855
  type: "button",
3627
- onClick: () => F(!1),
3856
+ onClick: () => se(!1),
3628
3857
  children: "cancel"
3629
3858
  }), /* @__PURE__ */ l("button", {
3630
3859
  type: "button",
3631
3860
  className: "danger",
3632
- onClick: () => void yt(),
3861
+ onClick: () => void vt(),
3633
3862
  children: "delete"
3634
3863
  })]
3635
3864
  })
@@ -3641,7 +3870,7 @@ function Rt({ documentId: e, scope: n, titleHint: s, browse: d, principal: f, re
3641
3870
  }
3642
3871
  //#endregion
3643
3872
  //#region src/components/PathTree.tsx
3644
- function zt(e, t = "") {
3873
+ function Yt(e, t = "") {
3645
3874
  let n = e.get(t);
3646
3875
  if (!n) return [];
3647
3876
  let r = n.entries.map((n) => {
@@ -3652,7 +3881,7 @@ function zt(e, t = "") {
3652
3881
  kind: n.kind,
3653
3882
  resourceRef: n.resource_ref,
3654
3883
  listing: r ? e.get(n.full_path) : void 0,
3655
- children: r ? zt(e, n.full_path) : []
3884
+ children: r ? Yt(e, n.full_path) : []
3656
3885
  };
3657
3886
  });
3658
3887
  return r.sort((e, t) => {
@@ -3660,13 +3889,13 @@ function zt(e, t = "") {
3660
3889
  return n === (t.kind === "directory") ? e.name.localeCompare(t.name) : n ? -1 : 1;
3661
3890
  }), r;
3662
3891
  }
3663
- var Bt = {
3892
+ var Xt = {
3664
3893
  directory: "📁",
3665
3894
  document: "📄",
3666
3895
  volume_mount: "💾",
3667
3896
  memory_entry: "🧠"
3668
3897
  };
3669
- function Vt(e) {
3898
+ function Zt(e) {
3670
3899
  let { tree: t, root: n } = e;
3671
3900
  return !n || !n.loaded && n.loading ? /* @__PURE__ */ l("div", {
3672
3901
  className: "empty",
@@ -3676,17 +3905,17 @@ function Vt(e) {
3676
3905
  children: /* @__PURE__ */ l("p", { children: "This tree is empty. Create a folder or document to begin." })
3677
3906
  }) : /* @__PURE__ */ u("ul", {
3678
3907
  className: "tree path-tree",
3679
- children: [t.map((t) => /* @__PURE__ */ l(Wt, {
3908
+ children: [t.map((t) => /* @__PURE__ */ l(en, {
3680
3909
  node: t,
3681
3910
  ...e
3682
- }, t.fullPath)), /* @__PURE__ */ l(Ht, {
3911
+ }, t.fullPath)), /* @__PURE__ */ l(Qt, {
3683
3912
  dir: "",
3684
3913
  listing: n,
3685
3914
  ...e
3686
3915
  })]
3687
3916
  });
3688
3917
  }
3689
- function Ht({ dir: e, listing: t, onLoadMore: n, onRetry: r }) {
3918
+ function Qt({ dir: e, listing: t, onLoadMore: n, onRetry: r }) {
3690
3919
  let i = [];
3691
3920
  return !t || t.loading && t.entries.length === 0 ? i.push(/* @__PURE__ */ l("li", {
3692
3921
  className: "node path-status",
@@ -3726,13 +3955,13 @@ function Ht({ dir: e, listing: t, onLoadMore: n, onRetry: r }) {
3726
3955
  })
3727
3956
  }, "more")), /* @__PURE__ */ l(c, { children: i });
3728
3957
  }
3729
- function Ut(e, t) {
3958
+ function $t(e, t) {
3730
3959
  if (e.kind !== "document" || !t) return;
3731
3960
  let n = e.resourceRef;
3732
3961
  return n?.document_id ? t.get(n.document_id) : void 0;
3733
3962
  }
3734
- function Wt(e) {
3735
- let { node: t, expanded: n, onToggle: r, selectedPath: i, onSelect: a, summaries: o } = e, s = t.kind === "directory", c = s && n.has(t.fullPath), d = i === t.fullPath, f = Ut(t, o), p = f && f.color_enabled ? Re(Le(f.type, f.status, Ie(f.color_scheme))) : void 0;
3963
+ function en(e) {
3964
+ let { node: t, expanded: n, onToggle: r, selectedPath: i, onSelect: a, summaries: o } = e, s = t.kind === "directory", c = s && n.has(t.fullPath), d = i === t.fullPath, f = $t(t, o), p = f && f.color_enabled ? Ge(Ve(f.type, f.status, Be(f.color_scheme))) : void 0;
3736
3965
  return /* @__PURE__ */ u("li", {
3737
3966
  className: `node path-node kind-${t.kind} ${d ? "selected" : ""}`,
3738
3967
  children: [/* @__PURE__ */ u("div", {
@@ -3757,7 +3986,7 @@ function Wt(e) {
3757
3986
  /* @__PURE__ */ l("span", {
3758
3987
  className: "path-kind-icon",
3759
3988
  "aria-hidden": !0,
3760
- children: Bt[t.kind] ?? "•"
3989
+ children: Xt[t.kind] ?? "•"
3761
3990
  }),
3762
3991
  /* @__PURE__ */ l("span", {
3763
3992
  className: "path-name",
@@ -3775,10 +4004,10 @@ function Wt(e) {
3775
4004
  })]
3776
4005
  }), c && /* @__PURE__ */ u("ul", {
3777
4006
  className: "children path-children",
3778
- children: [t.children.map((t) => /* @__PURE__ */ l(Wt, {
4007
+ children: [t.children.map((t) => /* @__PURE__ */ l(en, {
3779
4008
  ...e,
3780
4009
  node: t
3781
- }, t.fullPath)), /* @__PURE__ */ l(Ht, {
4010
+ }, t.fullPath)), /* @__PURE__ */ l(Qt, {
3782
4011
  ...e,
3783
4012
  dir: t.fullPath,
3784
4013
  listing: t.listing
@@ -3788,23 +4017,23 @@ function Wt(e) {
3788
4017
  }
3789
4018
  //#endregion
3790
4019
  //#region src/PathExplorer.tsx
3791
- var Gt = /^[A-Za-z0-9._-]+$/;
3792
- function Kt(e, t) {
4020
+ var tn = /^[A-Za-z0-9._-]+$/;
4021
+ function nn(e, t) {
3793
4022
  return `${e}/${t}`;
3794
4023
  }
3795
- function qt(e, t) {
4024
+ function rn(e, t) {
3796
4025
  for (let n of e) {
3797
4026
  if (n.fullPath === t) return n;
3798
- let e = qt(n.children, t);
4027
+ let e = rn(n.children, t);
3799
4028
  if (e) return e;
3800
4029
  }
3801
4030
  }
3802
- function Jt(e) {
3803
- let { theme: t, defaultScope: n, path: r, onPathChange: i, browse: a, principal: o, renderAssistant: s, renderNavigator: c, navigator: u, onError: d } = e, f = N(e);
3804
- return /* @__PURE__ */ l(P, {
4031
+ function an(e) {
4032
+ let { theme: t, defaultScope: n, path: r, onPathChange: i, browse: a, principal: o, renderAssistant: s, renderNavigator: c, navigator: u, onError: d } = e, f = R(e);
4033
+ return /* @__PURE__ */ l(z, {
3805
4034
  theme: t,
3806
4035
  dataLayer: f,
3807
- children: /* @__PURE__ */ l(Yt, {
4036
+ children: /* @__PURE__ */ l(on, {
3808
4037
  defaultScope: n,
3809
4038
  path: r,
3810
4039
  onPathChange: i,
@@ -3817,77 +4046,77 @@ function Jt(e) {
3817
4046
  })
3818
4047
  });
3819
4048
  }
3820
- function Yt({ defaultScope: e, path: n, onPathChange: d, browse: f, principal: p, renderAssistant: m, renderNavigator: _, navigator: v, onError: y }) {
3821
- let b = ee(), [x, S] = o(e ?? "user"), [C, w] = o(void 0), [T, E] = o(null), [D, A] = o(null), [j, ie] = o(() => /* @__PURE__ */ new Set()), M = n === void 0 ? C : n, ae = a(d);
4049
+ function on({ defaultScope: e, path: n, onPathChange: d, browse: f, principal: p, renderAssistant: m, renderNavigator: _, navigator: v, onError: y }) {
4050
+ let b = M(), [x, S] = o(e ?? "user"), [C, w] = o(void 0), [T, E] = o(null), [D, O] = o(null), [k, A] = o(null), [j, N] = o(() => /* @__PURE__ */ new Set()), P = n === void 0 ? C : n, te = a(d);
3822
4051
  r(() => {
3823
- ae.current = d;
4052
+ te.current = d;
3824
4053
  }, [d]);
3825
- let oe = a(y);
4054
+ let ne = a(y);
3826
4055
  r(() => {
3827
- oe.current = y;
4056
+ ne.current = y;
3828
4057
  }, [y]);
3829
- let [N, P] = o([]), F = a(0), I = a(void 0), L = t((e) => {
3830
- I.current = e, ae.current?.(e), w(e);
3831
- }, []), R = t((e) => {
3832
- F.current++, P((e) => e.length > 0 ? [] : e), L(e);
3833
- }, [L]);
4058
+ let [I, L] = o([]), oe = a(0), se = a(void 0), R = t((e) => {
4059
+ se.current = e, te.current?.(e), w(e);
4060
+ }, []), z = t((e) => {
4061
+ oe.current++, L((e) => e.length > 0 ? [] : e), R(e);
4062
+ }, [R]);
3834
4063
  r(() => {
3835
- n !== void 0 && n !== I.current && (F.current++, P((e) => e.length > 0 ? [] : e));
4064
+ n !== void 0 && n !== se.current && (oe.current++, L((e) => e.length > 0 ? [] : e));
3836
4065
  }, [n]);
3837
- let z = i(() => f && (f.scopeId || f.tenant) ? {
4066
+ let B = i(() => f && (f.scopeId || f.tenant) ? {
3838
4067
  scopeId: f.scopeId,
3839
4068
  tenant: f.tenant
3840
- } : void 0, [f?.scopeId, f?.tenant]), B = i(() => new te(b, x, z), [
4069
+ } : void 0, [f?.scopeId, f?.tenant]), V = i(() => new re(b, x, B), [
3841
4070
  b,
3842
4071
  x,
3843
- z
3844
- ]), V = s(B.subscribe, B.getSnapshot), H = t((e) => {
3845
- oe.current?.(e);
3846
- }, []), [me, he] = o(() => _ ? h(globalThis.localStorage) : "tree"), U = !!_ && me === "stars", ge = t((e) => {
3847
- he(e), g(globalThis.localStorage, e), e === "tree" && ve(!1);
3848
- }, []), [_e, ve] = o(!1), [ye, W] = o(0);
4072
+ B
4073
+ ]), H = s(V.subscribe, V.getSnapshot), U = t((e) => {
4074
+ ne.current?.(e);
4075
+ }, []), [W, ge] = o(() => _ ? h(globalThis.localStorage) : "tree"), G = !!_ && W === "stars", _e = t((e) => {
4076
+ ge(e), g(globalThis.localStorage, e), e === "tree" && ye(!1);
4077
+ }, []), [ve, ye] = o(!1), [be, xe] = o(0);
3849
4078
  r(() => {
3850
- _ && v && ge(v);
4079
+ _ && v && _e(v);
3851
4080
  }, [v]);
3852
- let [G, be] = o(), [xe, Se] = o(), K = t((e, t) => (W((e) => e + 1), B.invalidate(e, t)), [B]), [Ce, we] = o(() => /* @__PURE__ */ new Map()), Te = a(/* @__PURE__ */ new Set()), Ee = a(0), De = t(() => {
3853
- Ee.current++, Te.current = /* @__PURE__ */ new Set(), we(/* @__PURE__ */ new Map());
3854
- }, []), Oe = a(!0);
4081
+ let [K, Se] = o(), [Ce, we] = o(), q = t((e, t) => (xe((e) => e + 1), V.invalidate(e, t)), [V]), [Te, Ee] = o(() => /* @__PURE__ */ new Map()), De = a(/* @__PURE__ */ new Set()), Oe = a(0), ke = t(() => {
4082
+ Oe.current++, De.current = /* @__PURE__ */ new Set(), Ee(/* @__PURE__ */ new Map());
4083
+ }, []), J = a(!0);
3855
4084
  r(() => {
3856
- Oe.current ? Oe.current = !1 : (R(void 0), E(null), ie(/* @__PURE__ */ new Set()), De()), B.loadDir("").catch(H);
4085
+ J.current ? J.current = !1 : (z(void 0), E(null), N(/* @__PURE__ */ new Set()), ke()), V.loadDir("").catch(U);
3857
4086
  }, [
3858
- B,
3859
- R,
3860
- De,
3861
- H
4087
+ V,
4088
+ z,
4089
+ ke,
4090
+ U
3862
4091
  ]), r(() => {
3863
- for (let e of j) V.has(e) || B.loadDir(e).catch(H);
4092
+ for (let e of j) H.has(e) || V.loadDir(e).catch(U);
3864
4093
  }, [
3865
- B,
3866
- j,
3867
4094
  V,
3868
- H
4095
+ j,
4096
+ H,
4097
+ U
3869
4098
  ]);
3870
- let ke = a(null);
4099
+ let Ae = a(null);
3871
4100
  r(() => {
3872
- let e = ke.current !== null && ke.current !== B;
3873
- if (ke.current = B, !M || e) return;
3874
- let t = k(M).filter((e) => e !== "");
3875
- ie((e) => {
4101
+ let e = Ae.current !== null && Ae.current !== V;
4102
+ if (Ae.current = V, !P || e) return;
4103
+ let t = ee(P).filter((e) => e !== "");
4104
+ N((e) => {
3876
4105
  if (t.every((t) => e.has(t))) return e;
3877
4106
  let n = new Set(e);
3878
4107
  return t.forEach((e) => n.add(e)), n;
3879
- }), B.reveal(M).catch(H);
4108
+ }), V.reveal(P).catch(U);
3880
4109
  }, [
3881
- B,
3882
- M,
3883
- H
4110
+ V,
4111
+ P,
4112
+ U
3884
4113
  ]), r(() => {
3885
4114
  if (x === "tenant") return;
3886
4115
  let e = [];
3887
- for (let t of V.values()) for (let n of re(t.entries)) Te.current.has(n) || (Te.current.add(n), e.push(n));
3888
- let t = Ee.current;
3889
- for (let n = 0; n < e.length; n += 500) b.documentsSummary({ documentIds: e.slice(n, n + 500) }, x, z).then((e) => {
3890
- Ee.current === t && we((t) => {
4116
+ for (let t of H.values()) for (let n of ae(t.entries)) De.current.has(n) || (De.current.add(n), e.push(n));
4117
+ let t = Oe.current;
4118
+ for (let n = 0; n < e.length; n += 500) b.documentsSummary({ documentIds: e.slice(n, n + 500) }, x, B).then((e) => {
4119
+ Oe.current === t && Ee((t) => {
3891
4120
  let n = new Map(t);
3892
4121
  for (let t of e.documents ?? []) n.set(t.document_id, t);
3893
4122
  return n;
@@ -3895,32 +4124,32 @@ function Yt({ defaultScope: e, path: n, onPathChange: d, browse: f, principal: p
3895
4124
  }).catch(() => {});
3896
4125
  }, [
3897
4126
  b,
3898
- V,
4127
+ H,
3899
4128
  x,
3900
- z
4129
+ B
3901
4130
  ]);
3902
- let Ae = i(() => zt(V), [V]), q = t(async () => {
3903
- E(null), De(), W((e) => e + 1), await B.refresh(j).catch(H), M && await B.reveal(M).catch(H);
4131
+ let je = i(() => Yt(H), [H]), Me = t(async () => {
4132
+ E(null), ke(), xe((e) => e + 1), await V.refresh(j).catch(U), P && await V.reveal(P).catch(U);
3904
4133
  }, [
3905
- B,
4134
+ V,
3906
4135
  j,
3907
- M,
3908
- De,
3909
- H
3910
- ]), je = t((e) => {
3911
- ie((t) => {
4136
+ P,
4137
+ ke,
4138
+ U
4139
+ ]), Ne = t((e) => {
4140
+ N((t) => {
3912
4141
  let n = new Set(t);
3913
4142
  return n.has(e) ? n.delete(e) : n.add(e), n;
3914
4143
  });
3915
- }, []), Me = t((e) => B.loadMore(e).catch(H), [B, H]), Ne = t((e) => {
3916
- (B.getSnapshot().get(e)?.loaded ? B.loadMore(e) : B.loadDir(e)).catch(H);
3917
- }, [B, H]), J = i(() => M ? qt(Ae, M) : void 0, [Ae, M]), Pe = V.get("")?.error, Y = J?.kind === "directory" ? J.fullPath : void 0, [Fe, Ie] = o(null);
4144
+ }, []), Y = t((e) => V.loadMore(e).catch(U), [V, U]), Pe = t((e) => {
4145
+ (V.getSnapshot().get(e)?.loaded ? V.loadMore(e) : V.loadDir(e)).catch(U);
4146
+ }, [V, U]), X = i(() => P ? rn(je, P) : void 0, [je, P]), Fe = H.get("")?.error, Ie = X?.kind === "directory" ? X.fullPath : void 0, [Le, Re] = o(null);
3918
4147
  r(() => {
3919
- if (!Y || !b.pathIsStored) return;
4148
+ if (!Ie || !b.pathIsStored) return;
3920
4149
  let e = !1;
3921
- return b.pathIsStored(Y, x, z).then((t) => {
3922
- e || Ie({
3923
- path: Y,
4150
+ return b.pathIsStored(Ie, x, B).then((t) => {
4151
+ e || Re({
4152
+ path: Ie,
3924
4153
  explicit: t
3925
4154
  });
3926
4155
  }, () => {}), () => {
@@ -3928,13 +4157,13 @@ function Yt({ defaultScope: e, path: n, onPathChange: d, browse: f, principal: p
3928
4157
  };
3929
4158
  }, [
3930
4159
  b,
3931
- Y,
4160
+ Ie,
3932
4161
  x,
3933
- z
4162
+ B
3934
4163
  ]);
3935
- let Le = J ? J.kind === "directory" ? Fe?.path === J.fullPath ? Fe.explicit ? "yes" : "implicit (no entry)" : void 0 : "yes" : void 0, X = i(() => J ? J.kind === "directory" ? J.fullPath : O(J.fullPath) : "", [J]), Z = X || "/", Re = x !== "tenant", Q = t(() => {
3936
- A({
3937
- title: `New folder in ${Z}`,
4164
+ let ze = X ? X.kind === "directory" ? Le?.path === X.fullPath ? Le.explicit ? "yes" : "implicit (no entry)" : void 0 : "yes" : void 0, Z = i(() => X ? X.kind === "directory" ? X.fullPath : F(X.fullPath) : "", [X]), Q = Z || "/", Be = x !== "tenant", Ve = t(() => {
4165
+ O({
4166
+ title: `New folder in ${Q}`,
3938
4167
  fields: [{
3939
4168
  key: "name",
3940
4169
  label: "Folder name",
@@ -3943,23 +4172,23 @@ function Yt({ defaultScope: e, path: n, onPathChange: d, browse: f, principal: p
3943
4172
  submitLabel: "Create",
3944
4173
  onSubmit: async (e) => {
3945
4174
  let t = e.name.trim();
3946
- if (!Gt.test(t)) throw Error("name may contain only [A-Za-z0-9._-]");
3947
- let n = Kt(X, t);
3948
- await b.pathMkdir(n, x, z), await K(n).catch(H), R(n);
4175
+ if (!tn.test(t)) throw Error("name may contain only [A-Za-z0-9._-]");
4176
+ let n = nn(Z, t);
4177
+ await b.pathMkdir(n, x, B), await q(n).catch(U), z(n);
3949
4178
  }
3950
4179
  });
3951
4180
  }, [
3952
4181
  b,
3953
- B,
3954
- X,
4182
+ V,
3955
4183
  Z,
4184
+ Q,
3956
4185
  x,
3957
- z,
3958
- H,
3959
- R
3960
- ]), ze = t(() => {
3961
- A({
3962
- title: `New document in ${Z}`,
4186
+ B,
4187
+ U,
4188
+ z
4189
+ ]), He = t(() => {
4190
+ O({
4191
+ title: `New document in ${Q}`,
3963
4192
  fields: [{
3964
4193
  key: "name",
3965
4194
  label: "Path name",
@@ -3972,368 +4201,423 @@ function Yt({ defaultScope: e, path: n, onPathChange: d, browse: f, principal: p
3972
4201
  submitLabel: "Create",
3973
4202
  onSubmit: async (e) => {
3974
4203
  let t = e.name.trim();
3975
- if (!Gt.test(t)) throw Error("name may contain only [A-Za-z0-9._-]");
3976
- let n = e.title.trim() || t, r = Kt(X, t);
3977
- await b.documentCreate(n, r, x, z), await K(r).catch(H), R(r);
4204
+ if (!tn.test(t)) throw Error("name may contain only [A-Za-z0-9._-]");
4205
+ let n = e.title.trim() || t, r = nn(Z, t);
4206
+ await b.documentCreate(n, r, x, B), await q(r).catch(U), z(r);
3978
4207
  }
3979
4208
  });
3980
4209
  }, [
3981
4210
  b,
3982
- B,
3983
- X,
4211
+ V,
3984
4212
  Z,
4213
+ Q,
3985
4214
  x,
3986
- z,
3987
- H,
3988
- R
3989
- ]), Be = t(() => {
3990
- J && A({
3991
- title: `Rename / move ${J.fullPath}`,
4215
+ B,
4216
+ U,
4217
+ z
4218
+ ]), Ue = t(() => {
4219
+ X && O({
4220
+ title: `Rename / move ${X.fullPath}`,
3992
4221
  fields: [{
3993
4222
  key: "to",
3994
4223
  label: "New path",
3995
- value: J.fullPath
4224
+ value: X.fullPath
3996
4225
  }],
3997
4226
  submitLabel: "Move",
3998
4227
  onSubmit: async (e) => {
3999
4228
  let t = e.to.trim();
4000
4229
  if (!t.startsWith("/")) throw Error("path must start with /");
4001
- await b.pathMv(J.fullPath, t, x, z), await Promise.all([K(J.fullPath, { dropSubtree: !0 }), K(t)]).catch(H), R(t);
4230
+ await b.pathMv(X.fullPath, t, x, B), await Promise.all([q(X.fullPath, { dropSubtree: !0 }), q(t)]).catch(U), z(t);
4002
4231
  }
4003
4232
  });
4004
4233
  }, [
4005
4234
  b,
4006
- B,
4007
- J,
4235
+ V,
4236
+ X,
4008
4237
  x,
4009
- z,
4010
- H,
4011
- R
4012
- ]), Ve = t(() => {
4013
- if (!J) return;
4014
- if (J.kind === "document") {
4015
- let e = J.resourceRef?.document_id;
4016
- A({
4017
- title: `Delete document ${J.fullPath}`,
4238
+ B,
4239
+ U,
4240
+ z
4241
+ ]), We = t(() => {
4242
+ if (!X) return;
4243
+ if (X.kind === "document") {
4244
+ let e = X.resourceRef?.document_id;
4245
+ O({
4246
+ title: `Delete document ${X.fullPath}`,
4018
4247
  message: "This deletes the document, all its chunks, and its path entry. This cannot be undone.",
4019
4248
  fields: [],
4020
4249
  submitLabel: "Delete",
4021
4250
  danger: !0,
4022
4251
  onSubmit: async () => {
4023
4252
  if (!e) throw Error("this document dirent has no document_id");
4024
- await b.documentDelete(e, x, z), await K(J.fullPath).catch(H), R(void 0);
4253
+ await b.documentDelete(e, x, B), await q(X.fullPath).catch(U), z(void 0);
4025
4254
  }
4026
4255
  });
4027
4256
  return;
4028
4257
  }
4029
- let e = J;
4258
+ let e = X;
4030
4259
  E(null), (async () => {
4031
4260
  let t;
4032
4261
  try {
4033
- t = await ne(b, e.fullPath, x, z);
4262
+ t = await ie(b, e.fullPath, x, B);
4034
4263
  } catch (t) {
4035
4264
  E(`could not list ${e.fullPath} for delete: ${t instanceof Error ? t.message : String(t)}`);
4036
4265
  return;
4037
4266
  }
4038
- let n = x === "tenant" ? [] : re(t);
4039
- A({
4267
+ let n = x === "tenant" ? [] : ae(t);
4268
+ O({
4040
4269
  title: `Delete branch ${e.fullPath}`,
4041
4270
  message: t.length === 0 ? "This removes the (empty) folder." : "This removes the folder and everything under it" + (n.length > 0 ? ` — including ${n.length} document(s), whose chunks are deleted.` : "."),
4042
4271
  fields: [],
4043
4272
  submitLabel: "Delete",
4044
4273
  danger: !0,
4045
4274
  onSubmit: async () => {
4046
- for (let e of n) await b.documentDelete(e, x, z);
4047
- await b.pathRm(e.fullPath, x, !0, z), await K(e.fullPath, { dropSubtree: !0 }).catch(H), R(void 0);
4275
+ for (let e of n) await b.documentDelete(e, x, B);
4276
+ await b.pathRm(e.fullPath, x, !0, B), await q(e.fullPath, { dropSubtree: !0 }).catch(U), z(void 0);
4048
4277
  }
4049
4278
  });
4050
4279
  })();
4051
4280
  }, [
4052
4281
  b,
4282
+ V,
4283
+ X,
4284
+ x,
4053
4285
  B,
4054
- J,
4286
+ U,
4287
+ z
4288
+ ]), Ge = X && (X.kind === "directory" || X.kind === "document"), Ke = !!b.documentsTransfer && !!Ge, qe = t(() => {
4289
+ if (X) {
4290
+ if (X.kind === "document") {
4291
+ let e = X.resourceRef?.document_id;
4292
+ if (!e) {
4293
+ E("this document entry has no document_id");
4294
+ return;
4295
+ }
4296
+ A({
4297
+ documentId: e,
4298
+ fromPath: X.fullPath
4299
+ });
4300
+ } else A({
4301
+ underPath: X.fullPath,
4302
+ fromPath: X.fullPath
4303
+ });
4304
+ }
4305
+ }, [X]), Je = t((e) => {
4306
+ e.op === "move" ? (q(e.from, { dropSubtree: !0 }).catch(U), L([]), z(void 0)) : e.toScope === x && q(e.to).catch(U);
4307
+ }, [
4308
+ q,
4309
+ U,
4055
4310
  x,
4056
- z,
4057
- H,
4058
- R
4059
- ]), He = J && (J.kind === "directory" || J.kind === "document"), $ = i(() => {
4060
- if (N.length > 0) return N[N.length - 1];
4061
- if (J?.kind === "document") return {
4062
- documentId: J.resourceRef?.document_id ?? "",
4063
- path: J.fullPath,
4064
- title: J.name
4311
+ z
4312
+ ]), $ = i(() => {
4313
+ if (I.length > 0) return I[I.length - 1];
4314
+ if (X?.kind === "document") return {
4315
+ documentId: X.resourceRef?.document_id ?? "",
4316
+ path: X.fullPath,
4317
+ title: X.name
4065
4318
  };
4066
- }, [N, J]), Ue = t((e, t) => {
4067
- let n = ++F.current, r = de(B.getSnapshot(), e.documentId);
4068
- P(se(N, {
4319
+ }, [I, X]), Ye = t((e, t) => {
4320
+ let n = ++oe.current, r = fe(V.getSnapshot(), e.documentId);
4321
+ L(ce(I, {
4069
4322
  ...t,
4070
4323
  path: $?.path
4071
4324
  }, {
4072
4325
  ...e,
4073
4326
  path: r
4074
- })), L(r), !r && b.documentPath && b.documentPath(e.documentId, x, z).then((t) => {
4075
- t && F.current === n && (P((n) => le(n, e.documentId, { path: t })), L(t));
4327
+ })), R(r), !r && b.documentPath && b.documentPath(e.documentId, x, B).then((t) => {
4328
+ t && oe.current === n && (L((n) => ue(n, e.documentId, { path: t })), R(t));
4076
4329
  }, () => {});
4077
4330
  }, [
4078
4331
  b,
4079
- B,
4080
- N,
4332
+ V,
4333
+ I,
4081
4334
  $?.path,
4082
4335
  x,
4083
- z,
4084
- L
4085
- ]), We = t((e) => {
4086
- let t = ce(N, e);
4087
- t !== N && (F.current++, P(t), L(t[t.length - 1].path));
4088
- }, [N, L]), Ge = t((e, t) => P((n) => le(n, e, { title: t })), []), Ke = t((e) => {
4089
- Se((t) => ({
4336
+ B,
4337
+ R
4338
+ ]), Xe = t((e) => {
4339
+ let t = le(I, e);
4340
+ t !== I && (oe.current++, L(t), R(t[t.length - 1].path));
4341
+ }, [I, R]), Ze = t((e, t) => L((n) => ue(n, e, { title: t })), []), Qe = t((e) => {
4342
+ we((t) => ({
4090
4343
  documentId: e.documentId,
4091
4344
  chunkId: e.chunkId,
4092
4345
  seq: (t?.seq ?? 0) + 1
4093
- })), $?.documentId !== e.documentId && (e.path ? R(e.path) : (F.current++, P([{
4346
+ })), $?.documentId !== e.documentId && (e.path ? z(e.path) : (oe.current++, L([{
4094
4347
  documentId: e.documentId,
4095
4348
  chunkId: e.chunkId
4096
- }]), L(void 0)));
4349
+ }]), R(void 0)));
4097
4350
  }, [
4098
4351
  $?.documentId,
4099
- R,
4100
- L
4101
- ]), qe = i(() => ({
4352
+ z,
4353
+ R
4354
+ ]), $e = i(() => ({
4102
4355
  scope: x,
4103
- browse: z,
4356
+ browse: B,
4104
4357
  selection: {
4105
4358
  documentId: $?.documentId,
4106
- chunkId: G && G.documentId === $?.documentId ? G.chunkId : void 0,
4359
+ chunkId: K && K.documentId === $?.documentId ? K.chunkId : void 0,
4107
4360
  path: $?.path
4108
4361
  },
4109
- onSelect: Ke,
4110
- reloadToken: ye,
4111
- maximized: _e,
4112
- onToggleMaximize: () => ve((e) => !e),
4362
+ onSelect: Qe,
4363
+ reloadToken: be,
4364
+ maximized: ve,
4365
+ onToggleMaximize: () => ye((e) => !e),
4113
4366
  subject: p?.subject
4114
4367
  }), [
4115
4368
  x,
4116
- z,
4369
+ B,
4117
4370
  $?.documentId,
4118
4371
  $?.path,
4119
- G,
4120
- Ke,
4121
- ye,
4122
- _e,
4372
+ K,
4373
+ Qe,
4374
+ be,
4375
+ ve,
4123
4376
  p?.subject
4124
- ]), Je = xe && $ && xe.documentId === $.documentId ? xe : void 0, Ye = !!$?.path && J?.kind === "document" && J.fullPath === $.path;
4125
- return /* @__PURE__ */ u(c, { children: [/* @__PURE__ */ u(pe, {
4126
- className: U ? "paths-view paths-view--stars" : "paths-view",
4127
- defaultLeftWidth: U ? 720 : 420,
4128
- minLeftWidth: 280,
4129
- minRightWidth: 300,
4130
- storageKey: U ? "loomcycle.explorer.split.stars" : "loomcycle.explorer.split.paths",
4131
- hideRight: U && _e,
4132
- children: [/* @__PURE__ */ u("div", {
4133
- className: "left",
4134
- children: [
4135
- /* @__PURE__ */ u("div", {
4136
- className: "paths-toolbar",
4377
+ ]), et = Ce && $ && Ce.documentId === $.documentId ? Ce : void 0, tt = !!$?.path && X?.kind === "document" && X.fullPath === $.path;
4378
+ return /* @__PURE__ */ u(c, { children: [
4379
+ /* @__PURE__ */ u(he, {
4380
+ className: G ? "paths-view paths-view--stars" : "paths-view",
4381
+ defaultLeftWidth: G ? 720 : 420,
4382
+ minLeftWidth: 280,
4383
+ minRightWidth: 300,
4384
+ storageKey: G ? "loomcycle.explorer.split.stars" : "loomcycle.explorer.split.paths",
4385
+ hideRight: G && ve,
4386
+ children: [/* @__PURE__ */ u("div", {
4387
+ className: "left",
4388
+ children: [
4389
+ /* @__PURE__ */ u("div", {
4390
+ className: "paths-toolbar",
4391
+ children: [
4392
+ /* @__PURE__ */ u("label", {
4393
+ className: "paths-scope",
4394
+ children: [/* @__PURE__ */ l("span", { children: "scope" }), /* @__PURE__ */ u("select", {
4395
+ value: x,
4396
+ onChange: (e) => S(e.target.value),
4397
+ children: [
4398
+ /* @__PURE__ */ l("option", {
4399
+ value: "user",
4400
+ children: "user"
4401
+ }),
4402
+ /* @__PURE__ */ l("option", {
4403
+ value: "agent",
4404
+ children: "agent"
4405
+ }),
4406
+ /* @__PURE__ */ l("option", {
4407
+ value: "tenant",
4408
+ children: "tenant"
4409
+ })
4410
+ ]
4411
+ })]
4412
+ }),
4413
+ _ && /* @__PURE__ */ u("div", {
4414
+ className: "paths-nav-switch",
4415
+ role: "group",
4416
+ "aria-label": "Navigator",
4417
+ children: [/* @__PURE__ */ l("button", {
4418
+ type: "button",
4419
+ "aria-pressed": !G,
4420
+ className: G ? void 0 : "active",
4421
+ onClick: () => _e("tree"),
4422
+ title: "Browse the Path tree",
4423
+ children: "tree"
4424
+ }), /* @__PURE__ */ l("button", {
4425
+ type: "button",
4426
+ "aria-pressed": G,
4427
+ className: G ? "active" : void 0,
4428
+ onClick: () => _e("stars"),
4429
+ title: "Browse the scope as a 3D star map",
4430
+ children: "stars"
4431
+ })]
4432
+ }),
4433
+ /* @__PURE__ */ u("div", {
4434
+ className: "paths-toolbar-actions",
4435
+ children: [!G && /* @__PURE__ */ u(c, { children: [/* @__PURE__ */ l("button", {
4436
+ type: "button",
4437
+ onClick: Ve,
4438
+ title: `New folder in ${Q}`,
4439
+ children: "+ folder"
4440
+ }), /* @__PURE__ */ l("button", {
4441
+ type: "button",
4442
+ onClick: He,
4443
+ disabled: !Be,
4444
+ title: Be ? `New document in ${Q}` : "Documents are agent/user scope only",
4445
+ children: "+ document"
4446
+ })] }), /* @__PURE__ */ l("button", {
4447
+ type: "button",
4448
+ onClick: () => void Me(),
4449
+ title: "Reload the tree",
4450
+ children: "↻"
4451
+ })]
4452
+ })
4453
+ ]
4454
+ }),
4455
+ !G && /* @__PURE__ */ u("p", {
4456
+ className: "paths-context",
4457
+ children: [
4458
+ "new items → ",
4459
+ /* @__PURE__ */ l("code", { children: Q }),
4460
+ B?.scopeId && /* @__PURE__ */ u(c, { children: [
4461
+ " · ",
4462
+ "subject ",
4463
+ /* @__PURE__ */ l("code", { children: B.scopeId })
4464
+ ] }),
4465
+ B?.tenant && /* @__PURE__ */ u(c, { children: [
4466
+ " · ",
4467
+ "tenant ",
4468
+ /* @__PURE__ */ l("code", { children: B.tenant })
4469
+ ] })
4470
+ ]
4471
+ }),
4472
+ (T || Fe) && /* @__PURE__ */ l("div", {
4473
+ className: "paths-err",
4474
+ children: T || Fe
4475
+ }),
4476
+ G && _ ? /* @__PURE__ */ l("div", {
4477
+ className: "paths-navigator",
4478
+ children: _($e)
4479
+ }) : /* @__PURE__ */ l(Zt, {
4480
+ tree: je,
4481
+ root: H.get(""),
4482
+ expanded: j,
4483
+ onToggle: Ne,
4484
+ onLoadMore: Y,
4485
+ onRetry: Pe,
4486
+ selectedPath: P,
4487
+ onSelect: (e) => z(e.fullPath),
4488
+ summaries: Te
4489
+ })
4490
+ ]
4491
+ }), /* @__PURE__ */ l("div", {
4492
+ className: "right",
4493
+ children: $ ? /* @__PURE__ */ u("div", {
4494
+ className: "paths-doc",
4137
4495
  children: [
4138
- /* @__PURE__ */ u("label", {
4139
- className: "paths-scope",
4140
- children: [/* @__PURE__ */ l("span", { children: "scope" }), /* @__PURE__ */ u("select", {
4141
- value: x,
4142
- onChange: (e) => S(e.target.value),
4496
+ /* @__PURE__ */ l(pe, {
4497
+ trail: I,
4498
+ onJump: Xe
4499
+ }),
4500
+ /* @__PURE__ */ u("div", {
4501
+ className: "paths-doc-head",
4502
+ children: [$.path ? /* @__PURE__ */ l("code", {
4503
+ className: "paths-doc-path",
4504
+ children: $.path
4505
+ }) : /* @__PURE__ */ u("span", {
4506
+ className: "paths-doc-path paths-doc-unfiled",
4507
+ title: "Opened by id — no entry for this document was found in the Path tree",
4143
4508
  children: [
4144
- /* @__PURE__ */ l("option", {
4145
- value: "user",
4146
- children: "user"
4509
+ de($),
4510
+ " ",
4511
+ /* @__PURE__ */ l("em", { children: "· opened by id, not in the tree" })
4512
+ ]
4513
+ }), tt && /* @__PURE__ */ u("div", {
4514
+ className: "paths-detail-actions",
4515
+ children: [
4516
+ /* @__PURE__ */ l("button", {
4517
+ type: "button",
4518
+ onClick: Ue,
4519
+ children: "rename / move"
4147
4520
  }),
4148
- /* @__PURE__ */ l("option", {
4149
- value: "agent",
4150
- children: "agent"
4521
+ Ke && /* @__PURE__ */ l("button", {
4522
+ type: "button",
4523
+ onClick: qe,
4524
+ title: "Copy or move to another scope",
4525
+ children: "copy / move to…"
4151
4526
  }),
4152
- /* @__PURE__ */ l("option", {
4153
- value: "tenant",
4154
- children: "tenant"
4527
+ /* @__PURE__ */ l("button", {
4528
+ type: "button",
4529
+ className: "danger",
4530
+ onClick: We,
4531
+ children: "delete"
4155
4532
  })
4156
4533
  ]
4157
4534
  })]
4158
4535
  }),
4159
- _ && /* @__PURE__ */ u("div", {
4160
- className: "paths-nav-switch",
4161
- role: "group",
4162
- "aria-label": "Navigator",
4163
- children: [/* @__PURE__ */ l("button", {
4164
- type: "button",
4165
- "aria-pressed": !U,
4166
- className: U ? void 0 : "active",
4167
- onClick: () => ge("tree"),
4168
- title: "Browse the Path tree",
4169
- children: "tree"
4170
- }), /* @__PURE__ */ l("button", {
4171
- type: "button",
4172
- "aria-pressed": U,
4173
- className: U ? "active" : void 0,
4174
- onClick: () => ge("stars"),
4175
- title: "Browse the scope as a 3D star map",
4176
- children: "stars"
4177
- })]
4178
- }),
4179
- /* @__PURE__ */ u("div", {
4180
- className: "paths-toolbar-actions",
4181
- children: [!U && /* @__PURE__ */ u(c, { children: [/* @__PURE__ */ l("button", {
4182
- type: "button",
4183
- onClick: Q,
4184
- title: `New folder in ${Z}`,
4185
- children: "+ folder"
4186
- }), /* @__PURE__ */ l("button", {
4187
- type: "button",
4188
- onClick: ze,
4189
- disabled: !Re,
4190
- title: Re ? `New document in ${Z}` : "Documents are agent/user scope only",
4191
- children: "+ document"
4192
- })] }), /* @__PURE__ */ l("button", {
4193
- type: "button",
4194
- onClick: () => void q(),
4195
- title: "Reload the tree",
4196
- children: "↻"
4197
- })]
4198
- })
4536
+ /* @__PURE__ */ l(Jt, {
4537
+ documentId: $.documentId,
4538
+ scope: x,
4539
+ titleHint: $.title,
4540
+ browse: B,
4541
+ principal: p,
4542
+ renderAssistant: m,
4543
+ initialChunkId: $.chunkId ?? et?.chunkId,
4544
+ onOpenDocument: Ye,
4545
+ onTitle: Ze,
4546
+ onChunkSelect: (e) => Se({
4547
+ documentId: $.documentId,
4548
+ chunkId: e
4549
+ }),
4550
+ focusChunk: et
4551
+ }, I.length)
4199
4552
  ]
4200
- }),
4201
- !U && /* @__PURE__ */ u("p", {
4202
- className: "paths-context",
4553
+ }) : X ? /* @__PURE__ */ u("div", {
4554
+ className: "paths-detail",
4203
4555
  children: [
4204
- "new items → ",
4205
- /* @__PURE__ */ l("code", { children: Z }),
4206
- z?.scopeId && /* @__PURE__ */ u(c, { children: [
4207
- " · ",
4208
- "subject ",
4209
- /* @__PURE__ */ l("code", { children: z.scopeId })
4210
- ] }),
4211
- z?.tenant && /* @__PURE__ */ u(c, { children: [
4212
- " · ",
4213
- "tenant ",
4214
- /* @__PURE__ */ l("code", { children: z.tenant })
4215
- ] })
4216
- ]
4217
- }),
4218
- (T || Pe) && /* @__PURE__ */ l("div", {
4219
- className: "paths-err",
4220
- children: T || Pe
4221
- }),
4222
- U && _ ? /* @__PURE__ */ l("div", {
4223
- className: "paths-navigator",
4224
- children: _(qe)
4225
- }) : /* @__PURE__ */ l(Vt, {
4226
- tree: Ae,
4227
- root: V.get(""),
4228
- expanded: j,
4229
- onToggle: je,
4230
- onLoadMore: Me,
4231
- onRetry: Ne,
4232
- selectedPath: M,
4233
- onSelect: (e) => R(e.fullPath),
4234
- summaries: Ce
4235
- })
4236
- ]
4237
- }), /* @__PURE__ */ l("div", {
4238
- className: "right",
4239
- children: $ ? /* @__PURE__ */ u("div", {
4240
- className: "paths-doc",
4241
- children: [
4242
- /* @__PURE__ */ l(fe, {
4243
- trail: N,
4244
- onJump: We
4245
- }),
4246
- /* @__PURE__ */ u("div", {
4247
- className: "paths-doc-head",
4248
- children: [$.path ? /* @__PURE__ */ l("code", {
4249
- className: "paths-doc-path",
4250
- children: $.path
4251
- }) : /* @__PURE__ */ u("span", {
4252
- className: "paths-doc-path paths-doc-unfiled",
4253
- title: "Opened by id — no entry for this document was found in the Path tree",
4556
+ /* @__PURE__ */ u("h2", { children: [/* @__PURE__ */ l("span", {
4557
+ className: "paths-detail-kind",
4558
+ children: X.kind
4559
+ }), /* @__PURE__ */ l("code", { children: X.fullPath })] }),
4560
+ /* @__PURE__ */ u("dl", {
4561
+ className: "paths-detail-meta",
4254
4562
  children: [
4255
- ue($),
4256
- " ",
4257
- /* @__PURE__ */ l("em", { children: "· opened by id, not in the tree" })
4563
+ /* @__PURE__ */ l("dt", { children: "scope" }),
4564
+ /* @__PURE__ */ l("dd", { children: x }),
4565
+ ze && /* @__PURE__ */ u(c, { children: [/* @__PURE__ */ l("dt", { children: "stored" }), /* @__PURE__ */ l("dd", { children: ze })] })
4258
4566
  ]
4259
- }), Ye && /* @__PURE__ */ u("div", {
4260
- className: "paths-detail-actions",
4261
- children: [/* @__PURE__ */ l("button", {
4262
- type: "button",
4263
- onClick: Be,
4264
- children: "rename / move"
4265
- }), /* @__PURE__ */ l("button", {
4266
- type: "button",
4267
- className: "danger",
4268
- onClick: Ve,
4269
- children: "delete"
4270
- })]
4271
- })]
4272
- }),
4273
- /* @__PURE__ */ l(Rt, {
4274
- documentId: $.documentId,
4275
- scope: x,
4276
- titleHint: $.title,
4277
- browse: z,
4278
- principal: p,
4279
- renderAssistant: m,
4280
- initialChunkId: $.chunkId ?? Je?.chunkId,
4281
- onOpenDocument: Ue,
4282
- onTitle: Ge,
4283
- onChunkSelect: (e) => be({
4284
- documentId: $.documentId,
4285
- chunkId: e
4286
4567
  }),
4287
- focusChunk: Je
4288
- }, N.length)
4289
- ]
4290
- }) : J ? /* @__PURE__ */ u("div", {
4291
- className: "paths-detail",
4292
- children: [
4293
- /* @__PURE__ */ u("h2", { children: [/* @__PURE__ */ l("span", {
4294
- className: "paths-detail-kind",
4295
- children: J.kind
4296
- }), /* @__PURE__ */ l("code", { children: J.fullPath })] }),
4297
- /* @__PURE__ */ u("dl", {
4298
- className: "paths-detail-meta",
4299
- children: [
4300
- /* @__PURE__ */ l("dt", { children: "scope" }),
4301
- /* @__PURE__ */ l("dd", { children: x }),
4302
- Le && /* @__PURE__ */ u(c, { children: [/* @__PURE__ */ l("dt", { children: "stored" }), /* @__PURE__ */ l("dd", { children: Le })] })
4303
- ]
4304
- }),
4305
- He ? /* @__PURE__ */ u("div", {
4306
- className: "paths-detail-actions",
4307
- children: [/* @__PURE__ */ l("button", {
4308
- type: "button",
4309
- onClick: Be,
4310
- children: "rename / move"
4311
- }), /* @__PURE__ */ l("button", {
4312
- type: "button",
4313
- className: "danger",
4314
- onClick: Ve,
4315
- children: "delete"
4316
- })]
4317
- }) : /* @__PURE__ */ u("p", {
4318
- className: "paths-readonly",
4319
- children: [
4320
- "Read-only — ",
4321
- J.kind,
4322
- " entries are managed by their own tool."
4323
- ]
4324
- })
4325
- ]
4326
- }) : /* @__PURE__ */ l("div", {
4327
- className: "empty",
4328
- children: /* @__PURE__ */ l("p", { children: "Select a path on the left, or create a folder / document." })
4329
- })
4330
- })]
4331
- }), D && /* @__PURE__ */ l(Xt, {
4332
- state: D,
4333
- onClose: () => A(null)
4334
- })] });
4568
+ Ge ? /* @__PURE__ */ u("div", {
4569
+ className: "paths-detail-actions",
4570
+ children: [
4571
+ /* @__PURE__ */ l("button", {
4572
+ type: "button",
4573
+ onClick: Ue,
4574
+ children: "rename / move"
4575
+ }),
4576
+ Ke && /* @__PURE__ */ l("button", {
4577
+ type: "button",
4578
+ onClick: qe,
4579
+ title: "Copy or move to another scope",
4580
+ children: "copy / move to…"
4581
+ }),
4582
+ /* @__PURE__ */ l("button", {
4583
+ type: "button",
4584
+ className: "danger",
4585
+ onClick: We,
4586
+ children: "delete"
4587
+ })
4588
+ ]
4589
+ }) : /* @__PURE__ */ u("p", {
4590
+ className: "paths-readonly",
4591
+ children: [
4592
+ "Read-only — ",
4593
+ X.kind,
4594
+ " entries are managed by their own tool."
4595
+ ]
4596
+ })
4597
+ ]
4598
+ }) : /* @__PURE__ */ l("div", {
4599
+ className: "empty",
4600
+ children: /* @__PURE__ */ l("p", { children: "Select a path on the left, or create a folder / document." })
4601
+ })
4602
+ })]
4603
+ }),
4604
+ D && /* @__PURE__ */ l(sn, {
4605
+ state: D,
4606
+ onClose: () => O(null)
4607
+ }),
4608
+ k && /* @__PURE__ */ l(me, {
4609
+ data: b,
4610
+ scope: x,
4611
+ browse: B,
4612
+ documentId: k.documentId,
4613
+ underPath: k.underPath,
4614
+ fromPath: k.fromPath,
4615
+ onClose: () => A(null),
4616
+ onDone: Je
4617
+ })
4618
+ ] });
4335
4619
  }
4336
- function Xt({ state: e, onClose: t }) {
4620
+ function sn({ state: e, onClose: t }) {
4337
4621
  let [n, r] = o(() => Object.fromEntries(e.fields.map((e) => [e.key, e.value ?? ""]))), [i, a] = o(!1), [s, c] = o(null);
4338
4622
  return /* @__PURE__ */ l("div", {
4339
4623
  className: "modal-overlay",
@@ -4394,22 +4678,22 @@ function Xt({ state: e, onClose: t }) {
4394
4678
  }
4395
4679
  //#endregion
4396
4680
  //#region src/DocumentViewer.tsx
4397
- function Zt(e) {
4398
- let { documentId: t, scope: n, browse: r, theme: i } = e, a = N(e);
4399
- return /* @__PURE__ */ l(P, {
4681
+ function cn(e) {
4682
+ let { documentId: t, scope: n, browse: r, theme: i } = e, a = R(e);
4683
+ return /* @__PURE__ */ l(z, {
4400
4684
  theme: i,
4401
4685
  dataLayer: a,
4402
- children: /* @__PURE__ */ l(Qt, { ...e }, `${n}:${t}:${r?.scopeId ?? ""}:${r?.tenant ?? ""}`)
4686
+ children: /* @__PURE__ */ l(ln, { ...e }, `${n}:${t}:${r?.scopeId ?? ""}:${r?.tenant ?? ""}`)
4403
4687
  });
4404
4688
  }
4405
- function Qt({ documentId: e, scope: n, titleHint: r, browse: i, principal: a, renderAssistant: s, onOpenDocument: d }) {
4689
+ function ln({ documentId: e, scope: n, titleHint: r, browse: i, principal: a, renderAssistant: s, onOpenDocument: d }) {
4406
4690
  let [f, p] = o([]), m = f[f.length - 1], h = t((e, t) => {
4407
- d ? d(e, t) : p((n) => se(n, t, e));
4408
- }, [d]), g = t((e) => p((t) => ce(t, e)), []), _ = t((e, t) => p((n) => le(n, e, { title: t })), []);
4409
- return /* @__PURE__ */ u(c, { children: [/* @__PURE__ */ l(fe, {
4691
+ d ? d(e, t) : p((n) => ce(n, t, e));
4692
+ }, [d]), g = t((e) => p((t) => le(t, e)), []), _ = t((e, t) => p((n) => ue(n, e, { title: t })), []);
4693
+ return /* @__PURE__ */ u(c, { children: [/* @__PURE__ */ l(pe, {
4410
4694
  trail: f,
4411
4695
  onJump: g
4412
- }), /* @__PURE__ */ l(Rt, {
4696
+ }), /* @__PURE__ */ l(Jt, {
4413
4697
  documentId: m?.documentId ?? e,
4414
4698
  scope: n,
4415
4699
  titleHint: m ? m.title : r,
@@ -4422,6 +4706,6 @@ function Qt({ documentId: e, scope: n, titleHint: r, browse: i, principal: a, re
4422
4706
  }, f.length)] });
4423
4707
  }
4424
4708
  //#endregion
4425
- export { Y as DEFAULT_SCHEME, Zt as DocumentViewer, he as EDGE_PAGE_CAP, Jt as PathExplorer, Te as QUEUE_CHANGED_RETRIES, we as RULING_CHUNK, ae as RequestError, M as assetFetchFromConnection, X as chunkColor, Ae as chunkCount, ie as createLoomcycleClient, S as dataLayerFromClient, Le as docColor, Ie as effectiveScheme, Z as hexToTint, De as isQueueChanged, oe as jsonPostFromConnection, U as loadDocumentEdges, Oe as runRuling, Re as tintStyle, ke as undoRulings };
4709
+ export { Z as DEFAULT_SCHEME, cn as DocumentViewer, ye as EDGE_PAGE_CAP, an as PathExplorer, Ae as QUEUE_CHANGED_RETRIES, J as RULING_CHUNK, oe as RequestError, L as assetFetchFromConnection, He as chunkColor, Pe as chunkCount, Ue as chunkInheritsDocColor, qe as chunkRowStyle, I as createLoomcycleClient, O as dataLayerFromClient, Ve as docColor, Be as effectiveScheme, We as hexToTint, Me as isQueueChanged, se as jsonPostFromConnection, be as loadDocumentEdges, Ne as runRuling, Ge as tintStyle, b as transferInput, Y as undoRulings, Ke as washStyle };
4426
4710
 
4427
4711
  //# sourceMappingURL=index.js.map