@loomcycle/explorer 0.6.0 → 0.9.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
@@ -1,17 +1,59 @@
1
- import { jsx as t, jsxs as l, Fragment as Y } from "react/jsx-runtime";
2
- import { createContext as nt, useContext as at, useMemo as q, useState as f, useRef as ne, useEffect as B, useCallback as j } from "react";
3
- import { LoomcycleClient as rt } from "@loomcycle/client";
4
- import ot from "react-markdown";
5
- import ct from "remark-gfm";
6
- function _e(e, r) {
1
+ import { jsx as a, jsxs as c, Fragment as Q } from "react/jsx-runtime";
2
+ import { createContext as Tt, useContext as Lt, useMemo as X, useState as p, useRef as te, useEffect as H, useCallback as P, useSyncExternalStore as Mt } from "react";
3
+ import { LoomcycleClient as Rt } from "@loomcycle/client";
4
+ import Pt from "react-markdown";
5
+ import It from "remark-gfm";
6
+ const At = 4, Ot = 5e3;
7
+ function ze(e, t) {
7
8
  return {
8
- pathLs: (n, a, o, i) => e.path(
9
- { op: "ls", path: n, scope: a, recursive: o },
10
- i
9
+ pathLs: (n, r, o, s, i) => e.path(
10
+ {
11
+ op: "ls",
12
+ path: n,
13
+ scope: r,
14
+ recursive: o,
15
+ ...i?.limit ? { limit: i.limit } : {},
16
+ ...i?.cursor ? { cursor: i.cursor } : {}
17
+ },
18
+ s
11
19
  ),
12
- pathMkdir: (n, a, o) => e.path({ op: "mkdir", path: n, scope: a }, o),
13
- pathMv: (n, a, o, i) => e.path({ op: "mv", path: n, to: a, scope: o }, i),
14
- pathRm: (n, a, o, i) => e.path({ op: "rm", path: n, scope: a, recursive: o }, i),
20
+ // stat refuses a path with no dirent; that refusal IS the answer "implicit"
21
+ // here (the path came from a listing, so it exists). Any other failure —
22
+ // network, auth — is not an answer and propagates. Matched by name, not
23
+ // instanceof: the host's client may be a different copy of the package.
24
+ pathIsStored: (n, r, o) => e.path({ op: "stat", path: n, scope: r }, o).then(
25
+ () => !0,
26
+ (s) => {
27
+ if (s?.name === "SubstrateToolRefusedError") return !1;
28
+ throw s;
29
+ }
30
+ ),
31
+ // One recursive listing of document dirents, followed page by page until the
32
+ // document turns up.
33
+ documentPath: async (n, r, o) => {
34
+ let s;
35
+ for (let i = 0; i < At; i++) {
36
+ const l = await e.path(
37
+ {
38
+ op: "ls",
39
+ path: "/",
40
+ scope: r,
41
+ recursive: !0,
42
+ kind_filter: "document",
43
+ limit: Ot,
44
+ ...s ? { cursor: s } : {}
45
+ },
46
+ o
47
+ ), f = (l.entries ?? []).find(
48
+ (d) => d.resource_ref?.document_id === n
49
+ );
50
+ if (f) return f.full_path;
51
+ if (s = l.next_cursor || void 0, !s) return;
52
+ }
53
+ },
54
+ pathMkdir: (n, r, o) => e.path({ op: "mkdir", path: n, scope: r }, o),
55
+ pathMv: (n, r, o, s) => e.path({ op: "mv", path: n, to: r, scope: o }, s),
56
+ pathRm: (n, r, o, s) => e.path({ op: "rm", path: n, scope: r, recursive: o }, s),
15
57
  // The `as unknown as DocumentToolInput` casts below are the same pinned-SDK
16
58
  // workaround documentReorderChunk already uses, for a different reason: the
17
59
  // published @loomcycle/client still types `scope` as "agent" | "user", from
@@ -19,310 +61,578 @@ function _e(e, r) {
19
61
  // v1.41.0 and adapters/ts is fixed at source, so these casts come out on the
20
62
  // next client publish — they are not papering over a wire mismatch, they are
21
63
  // waiting for a version bump.
22
- documentCreate: (n, a, o, i) => e.document(
23
- { op: "create_document", title: n, path: a, scope: o },
24
- i
64
+ documentCreate: (n, r, o, s) => e.document(
65
+ { op: "create_document", title: n, path: r, scope: o },
66
+ s
25
67
  ),
26
- documentDelete: (n, a, o) => e.document({ op: "delete_document", id: n, scope: a }, o),
27
- documentGet: (n, a, o) => e.document({ op: "get_document", id: n, scope: a }, o),
28
- documentsSummary: (n, a, o) => e.document(
68
+ documentDelete: (n, r, o) => e.document({ op: "delete_document", id: n, scope: r }, o),
69
+ documentGet: (n, r, o) => e.document({ op: "get_document", id: n, scope: r }, o),
70
+ documentsSummary: (n, r, o) => e.document(
29
71
  // documents_summary + document_ids are RFC BN wire additions the pinned
30
72
  // SDK type doesn't enumerate; the /v1/_document passthrough accepts them
31
73
  // verbatim, so cast past DocumentToolInput (same pattern as update_chunk).
32
74
  {
33
75
  op: "documents_summary",
34
- scope: a,
76
+ scope: r,
35
77
  ...n.documentIds ? { document_ids: n.documentIds } : {},
36
78
  ...n.underPath ? { under_path: n.underPath } : {}
37
79
  },
38
80
  o
39
81
  ),
40
- documentQueryChunks: (n, a, o) => e.document(
41
- { op: "query_chunks", document_id: n, scope: a, limit: 1e3 },
82
+ documentQueryChunks: (n, r, o) => e.document(
83
+ { op: "query_chunks", document_id: n, scope: r, limit: 1e3 },
42
84
  o
43
85
  ),
44
- documentGetChunk: (n, a, o) => e.document({ op: "get_chunk", id: n, scope: a }, o),
45
- documentCreateChunk: (n, a, o, i, c, s) => e.document(
86
+ documentGetChunk: (n, r, o) => e.document({ op: "get_chunk", id: n, scope: r }, o),
87
+ documentCreateChunk: (n, r, o, s, i, l) => e.document(
46
88
  {
47
89
  op: "create_chunk",
48
90
  document_id: n,
49
- parent_id: a,
50
- scope: i,
51
- ...s ? { after_id: s } : {},
91
+ parent_id: r,
92
+ scope: s,
93
+ ...l ? { after_id: l } : {},
52
94
  ...o
53
95
  },
54
- c
96
+ i
55
97
  ),
56
- documentReorderChunk: (n, a, o, i) => e.document(
98
+ documentReorderChunk: (n, r, o, s) => e.document(
57
99
  // reorder_chunk is an RFC BP wire op the pinned SDK type doesn't
58
100
  // enumerate; the /v1/_document passthrough accepts it verbatim.
59
- { op: "reorder_chunk", id: n, direction: a, scope: o },
60
- i
101
+ { op: "reorder_chunk", id: n, direction: r, scope: o },
102
+ s
61
103
  ),
62
- documentDeleteChunk: (n, a, o) => e.document({ op: "delete_chunk", id: n, scope: a }, o),
63
- documentSetAsset: (n, a, o, i, c, s) => e.document(
104
+ documentDeleteChunk: (n, r, o) => e.document({ op: "delete_chunk", id: n, scope: r }, o),
105
+ documentSetAsset: (n, r, o, s, i, l) => e.document(
64
106
  // set_asset is an RFC BO wire op the pinned SDK type doesn't enumerate;
65
107
  // the /v1/_document passthrough accepts it verbatim.
66
108
  {
67
109
  op: "set_asset",
68
110
  id: n,
69
- media_type: a,
111
+ media_type: r,
70
112
  data: o,
71
- ...i ? { filename: i } : {},
72
- scope: c
113
+ ...s ? { filename: s } : {},
114
+ scope: i
73
115
  },
74
- s
116
+ l
75
117
  ),
76
- documentGetEdges: (n, a, o) => e.document(
118
+ documentGetEdges: (n, r, o) => e.document(
77
119
  // get_edges is an RFC BN P4 wire op the pinned SDK type doesn't
78
120
  // enumerate; the /v1/_document passthrough accepts it verbatim.
79
- { op: "get_edges", document_id: n, scope: a },
121
+ { op: "get_edges", document_id: n, scope: r },
80
122
  o
81
123
  ),
82
- documentUpdateChunk: (n, a, o, i, c) => e.document(
124
+ documentUpdateChunk: (n, r, o, s, i) => e.document(
83
125
  // `patch.fields` is unknown but DocumentToolInput.fields is a typed
84
126
  // Record; the cast reconciles the spread (the server accepts arbitrary
85
127
  // JSON there). Op order + arg names mirror the wire contract exactly.
86
128
  {
87
129
  op: "update_chunk",
88
130
  id: n,
89
- revision: a,
90
- scope: i,
131
+ revision: r,
132
+ scope: s,
91
133
  ...o
92
134
  },
93
- c
135
+ i
94
136
  ),
95
- documentExportMd: (n, a, o, i) => e.document(
137
+ documentExportMd: (n, r, o, s) => e.document(
96
138
  {
97
139
  op: "export_md",
98
140
  document_id: n,
99
- scope: a,
141
+ scope: r,
100
142
  include_metadata: o
101
143
  },
102
- i
144
+ s
103
145
  ),
104
146
  // RFC BS document-connections + history + canvas ops. Same `as unknown as
105
147
  // DocumentToolInput` passthrough as documentGetEdges — new wire ops the pinned
106
148
  // SDK type doesn't enumerate; the /v1/_document passthrough accepts them
107
149
  // verbatim (adapters/ts is fixed at source, so the casts come out on the next
108
150
  // client publish).
109
- documentBacklinks: (n, a, o) => e.document(
110
- { op: "backlinks", id: n, scope: a },
151
+ documentBacklinks: (n, r, o) => e.document(
152
+ { op: "backlinks", id: n, scope: r },
111
153
  o
112
154
  ),
113
- documentRelated: (n, a, o, i) => e.document(
155
+ documentRelated: (n, r, o, s) => e.document(
114
156
  {
115
157
  op: "related",
116
158
  id: n,
117
- scope: a,
118
- ...i ? { limit: i } : {}
159
+ scope: r,
160
+ ...s ? { limit: s } : {}
119
161
  },
120
162
  o
121
163
  ),
122
- documentUnlinkedMentions: (n, a, o, i) => e.document(
164
+ documentUnlinkedMentions: (n, r, o, s) => e.document(
123
165
  {
124
166
  op: "unlinked_mentions",
125
167
  id: n,
126
- scope: a,
127
- ...i ? { limit: i } : {}
168
+ scope: r,
169
+ ...s ? { limit: s } : {}
128
170
  },
129
171
  o
130
172
  ),
131
- documentHistory: (n, a, o, i) => e.document(
173
+ documentHistory: (n, r, o, s) => e.document(
132
174
  {
133
175
  op: "history",
134
176
  id: n,
135
- scope: a,
136
- ...i ? { limit: i } : {}
177
+ scope: r,
178
+ ...s ? { limit: s } : {}
137
179
  },
138
180
  o
139
181
  ),
140
- documentGetVersion: (n, a, o, i) => e.document(
141
- { op: "get_version", id: n, revision: a, scope: o },
142
- i
182
+ documentGetVersion: (n, r, o, s) => e.document(
183
+ { op: "get_version", id: n, revision: r, scope: o },
184
+ s
143
185
  ),
144
- documentDiff: (n, a, o, i, c) => e.document(
186
+ documentDiff: (n, r, o, s, i) => e.document(
145
187
  {
146
188
  op: "diff",
147
189
  id: n,
148
- from_revision: a,
190
+ from_revision: r,
149
191
  to_revision: o,
150
- scope: i
192
+ scope: s
151
193
  },
152
- c
194
+ i
153
195
  ),
154
- documentExportCanvas: (n, a, o) => e.document(
155
- { op: "export_canvas", document_id: n, scope: a },
196
+ documentExportCanvas: (n, r, o) => e.document(
197
+ { op: "export_canvas", document_id: n, scope: r },
156
198
  o
157
199
  ),
158
200
  // Present only when an AssetFetch was supplied (the connection path); a bare
159
201
  // client can't do the raw binary GET, so the op is omitted and the viewer
160
202
  // shows a placeholder.
161
- ...r ? {
162
- documentAssetObjectUrl: async (n, a, o) => {
163
- const i = new URLSearchParams({ scope: a });
164
- o?.scopeId && i.set("scope_id", o.scopeId), o?.tenant && i.set("tenant", o.tenant);
165
- const c = await r(
166
- `/v1/_document/asset/${encodeURIComponent(n)}?${i.toString()}`
203
+ ...t ? {
204
+ documentAssetObjectUrl: async (n, r, o) => {
205
+ const s = new URLSearchParams({ scope: r });
206
+ o?.scopeId && s.set("scope_id", o.scopeId), o?.tenant && s.set("tenant", o.tenant);
207
+ const i = await t(
208
+ `/v1/_document/asset/${encodeURIComponent(n)}?${s.toString()}`
167
209
  );
168
- if (!c.ok) throw new Error(`asset fetch failed: ${c.status}`);
169
- const s = await c.blob();
170
- return URL.createObjectURL(s);
210
+ if (!i.ok) throw new Error(`asset fetch failed: ${i.status}`);
211
+ const l = await i.blob();
212
+ return URL.createObjectURL(l);
171
213
  }
172
214
  } : {}
173
215
  };
174
216
  }
175
- const Te = nt(null);
176
- function it({
217
+ const at = Tt(null);
218
+ function Ut({
177
219
  value: e,
178
- children: r
220
+ children: t
179
221
  }) {
180
- return /* @__PURE__ */ t(Te.Provider, { value: e, children: r });
222
+ return /* @__PURE__ */ a(at.Provider, { value: e, children: t });
181
223
  }
182
- function ae() {
183
- const e = at(Te);
224
+ function be() {
225
+ const e = Lt(at);
184
226
  if (!e)
185
227
  throw new Error(
186
228
  "useExplorerData must be used within <PathExplorer> or <DocumentViewer> (no ExplorerDataLayer in context)"
187
229
  );
188
230
  return e;
189
231
  }
190
- function st(e) {
191
- const r = e.fetch;
192
- return new rt({
232
+ const Oe = 500, rt = 5e3;
233
+ function Ue(e) {
234
+ return e === "" ? "/" : e;
235
+ }
236
+ function jt(e) {
237
+ const t = e.lastIndexOf("/");
238
+ return t <= 0 ? "" : e.slice(0, t);
239
+ }
240
+ function ot(e) {
241
+ const t = [""], n = e.split("/").filter(Boolean);
242
+ let r = "";
243
+ for (let o = 0; o < n.length - 1; o++)
244
+ r = `${r}/${n[o]}`, t.push(r);
245
+ return t;
246
+ }
247
+ function qe(e) {
248
+ return e instanceof Error ? e.message : String(e);
249
+ }
250
+ function Je(e, t) {
251
+ return {
252
+ entries: [...t, ...e.entries ?? []],
253
+ nextCursor: e.next_cursor || void 0,
254
+ loaded: !0,
255
+ loading: !1
256
+ };
257
+ }
258
+ class Bt {
259
+ constructor(t, n, r, o = Oe) {
260
+ this.data = t, this.scope = n, this.browse = r, this.pageLimit = o;
261
+ }
262
+ data;
263
+ scope;
264
+ browse;
265
+ pageLimit;
266
+ dirs = /* @__PURE__ */ new Map();
267
+ snapshot = /* @__PURE__ */ new Map();
268
+ listeners = /* @__PURE__ */ new Set();
269
+ inflight = /* @__PURE__ */ new Map();
270
+ // epoch bumps whenever a directory is re-listed from its first page or
271
+ // dropped, so a page that was in flight across that point is discarded
272
+ // instead of being appended to a listing it no longer continues.
273
+ epoch = /* @__PURE__ */ new Map();
274
+ getSnapshot = () => this.snapshot;
275
+ subscribe = (t) => (this.listeners.add(t), () => {
276
+ this.listeners.delete(t);
277
+ });
278
+ publish() {
279
+ this.snapshot = new Map(this.dirs), this.listeners.forEach((t) => t());
280
+ }
281
+ set(t, n) {
282
+ this.dirs.set(t, n), this.publish();
283
+ }
284
+ track(t, n) {
285
+ const r = n.finally(() => {
286
+ this.inflight.get(t) === r && this.inflight.delete(t);
287
+ });
288
+ return this.inflight.set(t, r), r;
289
+ }
290
+ // loadDir lists a directory's first page unless it is already listed. A
291
+ // request already in flight for it is joined rather than repeated.
292
+ loadDir(t) {
293
+ const n = this.inflight.get(t);
294
+ return n || (this.dirs.get(t)?.loaded ? Promise.resolve() : this.fetchFirst(t, this.pageLimit));
295
+ }
296
+ // reload re-lists a directory from its first page, asking for as many entries
297
+ // as it already showed so a refresh does not fold away pages the operator
298
+ // loaded (up to the runtime's ceiling; past it the "load more" row returns).
299
+ // A directory that was shown in full gets a page of headroom on top, so the
300
+ // entry just created in it does not split it back into "load more".
301
+ reload(t) {
302
+ const n = this.dirs.get(t), r = n?.entries.length ?? 0, o = n?.loaded && !n.nextCursor ? r + this.pageLimit : r;
303
+ return this.fetchFirst(t, Math.min(rt, Math.max(this.pageLimit, o)));
304
+ }
305
+ fetchFirst(t, n) {
306
+ const r = (this.epoch.get(t) ?? 0) + 1;
307
+ this.epoch.set(t, r);
308
+ const o = this.dirs.get(t);
309
+ this.set(t, {
310
+ entries: o?.entries ?? [],
311
+ nextCursor: o?.nextCursor,
312
+ loaded: o?.loaded ?? !1,
313
+ loading: !0
314
+ });
315
+ const s = this.data.pathLs(Ue(t), this.scope, !1, this.browse, { limit: n }).then(
316
+ (i) => {
317
+ this.epoch.get(t) === r && this.set(t, Je(i, []));
318
+ },
319
+ (i) => {
320
+ throw this.epoch.get(t) === r && this.set(t, {
321
+ entries: o?.entries ?? [],
322
+ nextCursor: o?.nextCursor,
323
+ loaded: o?.loaded ?? !1,
324
+ loading: !1,
325
+ error: qe(i)
326
+ }), i;
327
+ }
328
+ );
329
+ return this.track(t, s);
330
+ }
331
+ // loadMore appends a directory's next page. A no-op when it has none.
332
+ loadMore(t) {
333
+ const n = this.inflight.get(t);
334
+ if (n) return n;
335
+ const r = this.dirs.get(t);
336
+ if (!r?.nextCursor) return Promise.resolve();
337
+ const o = this.epoch.get(t) ?? 0;
338
+ this.set(t, { ...r, loading: !0, error: void 0 });
339
+ const s = this.data.pathLs(Ue(t), this.scope, !1, this.browse, {
340
+ limit: this.pageLimit,
341
+ cursor: r.nextCursor
342
+ }).then(
343
+ (i) => {
344
+ this.epoch.get(t) === o && this.set(t, Je(i, r.entries));
345
+ },
346
+ (i) => {
347
+ throw this.epoch.get(t) === o && this.set(t, { ...r, loading: !1, error: qe(i) }), i;
348
+ }
349
+ );
350
+ return this.track(t, s);
351
+ }
352
+ // reveal lists every ancestor of `path`, paging each one until the next path
353
+ // segment appears, so a deep link to an entry on a later page still resolves.
354
+ // Resolves false when the path is not there. Because a page is ordered by
355
+ // name, paging stops as soon as a page ends past the wanted name.
356
+ async reveal(t) {
357
+ const n = t.split("/").filter(Boolean);
358
+ let r = "";
359
+ for (const o of n) {
360
+ for (await this.loadDir(r); ; ) {
361
+ const s = this.dirs.get(r);
362
+ if (!s) return !1;
363
+ if (s.entries.some((f) => f.name === o)) break;
364
+ const i = s.entries[s.entries.length - 1];
365
+ if (!s.nextCursor || i && i.name > o) return !1;
366
+ const l = s.nextCursor;
367
+ if (await this.loadMore(r), this.dirs.get(r)?.nextCursor === l) return !1;
368
+ }
369
+ r = `${r}/${o}`;
370
+ }
371
+ return !0;
372
+ }
373
+ // invalidate re-lists what a change at `path` can alter: every ancestor that
374
+ // is already listed — not just the parent, because an implicit directory
375
+ // appears with its first descendant and vanishes with its last. dropSubtree
376
+ // also forgets the listings at/under `path` (a moved or removed directory's
377
+ // old children must not linger under its old name).
378
+ async invalidate(t, n) {
379
+ if (n?.dropSubtree) {
380
+ for (const o of [...this.dirs.keys()])
381
+ (o === t || o.startsWith(`${t}/`)) && (this.dirs.delete(o), this.epoch.set(o, (this.epoch.get(o) ?? 0) + 1), this.inflight.delete(o));
382
+ this.publish();
383
+ }
384
+ const r = ot(t).filter((o) => this.dirs.has(o));
385
+ await Promise.all(r.map((o) => this.reload(o)));
386
+ }
387
+ // refresh re-lists the root and every directory in `keep` that is listed, and
388
+ // forgets the rest (a collapsed directory re-lists when it is next opened).
389
+ async refresh(t) {
390
+ const n = new Set(t);
391
+ n.add("");
392
+ for (const o of [...this.dirs.keys()])
393
+ n.has(o) || (this.dirs.delete(o), this.epoch.set(o, (this.epoch.get(o) ?? 0) + 1), this.inflight.delete(o));
394
+ this.publish();
395
+ const r = [...n].filter((o) => o === "" || this.dirs.has(o));
396
+ await Promise.all(r.map((o) => this.reload(o)));
397
+ }
398
+ }
399
+ async function Ft(e, t, n, r) {
400
+ const o = [];
401
+ let s;
402
+ for (; ; ) {
403
+ const i = await e.pathLs(Ue(t), n, !0, r, {
404
+ limit: rt,
405
+ cursor: s
406
+ });
407
+ o.push(...i.entries ?? []);
408
+ const l = i.next_cursor || void 0;
409
+ if (!l || l === s) return o;
410
+ s = l;
411
+ }
412
+ }
413
+ function Ze(e) {
414
+ const t = [];
415
+ for (const n of e) {
416
+ if (n.kind !== "document") continue;
417
+ const r = n.resource_ref?.document_id;
418
+ r && t.push(r);
419
+ }
420
+ return t;
421
+ }
422
+ function Gt(e) {
423
+ const t = e.fetch;
424
+ return new Rt({
193
425
  baseUrl: e.baseUrl,
194
426
  authToken: e.token || void 0,
195
- fetch: (n, a) => r ? r(n, a) : fetch(n, a)
427
+ fetch: (n, r) => t ? t(n, r) : fetch(n, r)
196
428
  });
197
429
  }
198
- function lt(e) {
199
- const r = e.fetch, n = (a, o) => r ? r(a, o) : fetch(a, o);
200
- return (a) => {
430
+ function Ht(e) {
431
+ const t = e.fetch, n = (r, o) => t ? t(r, o) : fetch(r, o);
432
+ return (r) => {
201
433
  const o = {};
202
- return e.token && (o.Authorization = `Bearer ${e.token}`), n(e.baseUrl + a, { headers: o });
434
+ return e.token && (o.Authorization = `Bearer ${e.token}`), n(e.baseUrl + r, { headers: o });
203
435
  };
204
436
  }
205
- function Pe(e) {
206
- const { dataLayer: r, client: n, connection: a } = e;
207
- return q(() => r || (n ? _e(n) : a ? _e(
208
- st(a),
209
- lt(a)
437
+ function st(e) {
438
+ const { dataLayer: t, client: n, connection: r } = e;
439
+ return X(() => t || (n ? ze(n) : r ? ze(
440
+ Gt(r),
441
+ Ht(r)
210
442
  // RFC BO — binary image-asset GET
211
- ) : null), [r, n, a?.baseUrl, a?.token, a?.fetch]);
443
+ ) : null), [t, n, r?.baseUrl, r?.token, r?.fetch]);
212
444
  }
213
- function Ae({
445
+ function it({
214
446
  theme: e,
215
- dataLayer: r,
447
+ dataLayer: t,
216
448
  children: n
217
449
  }) {
218
- const a = e ? { "data-theme": e } : {};
219
- return r ? /* @__PURE__ */ t("div", { className: "loomcycle-explorer", ...a, children: /* @__PURE__ */ t(it, { value: r, children: n }) }) : /* @__PURE__ */ t("div", { className: "loomcycle-explorer", ...a, children: /* @__PURE__ */ l("div", { className: "error-banner", children: [
450
+ const r = e ? { "data-theme": e } : {};
451
+ return t ? /* @__PURE__ */ a("div", { className: "loomcycle-explorer", ...r, children: /* @__PURE__ */ a(Ut, { value: t, children: n }) }) : /* @__PURE__ */ a("div", { className: "loomcycle-explorer", ...r, children: /* @__PURE__ */ c("div", { className: "error-banner", children: [
220
452
  "@loomcycle/explorer: provide a ",
221
- /* @__PURE__ */ t("code", { children: "connection" }),
453
+ /* @__PURE__ */ a("code", { children: "connection" }),
222
454
  ", ",
223
- /* @__PURE__ */ t("code", { children: "client" }),
455
+ /* @__PURE__ */ a("code", { children: "client" }),
224
456
  ", or",
225
457
  " ",
226
- /* @__PURE__ */ t("code", { children: "dataLayer" }),
458
+ /* @__PURE__ */ a("code", { children: "dataLayer" }),
227
459
  " prop."
228
460
  ] }) });
229
461
  }
230
- const Se = 6;
231
- function dt({
462
+ function ct(e, t, n) {
463
+ const r = e[e.length - 1];
464
+ return [...r && r.documentId === t.documentId ? [...e.slice(0, -1), { ...r, ...dt(t) }] : [...e, t], n];
465
+ }
466
+ function lt(e, t) {
467
+ return t < 0 || t >= e.length - 1 ? e : e.slice(0, t + 1);
468
+ }
469
+ function je(e, t, n) {
470
+ const r = e[e.length - 1];
471
+ if (!r || r.documentId !== t) return e;
472
+ const o = { ...r, ...dt(n) };
473
+ return o.title === r.title && o.path === r.path ? e : [...e.slice(0, -1), o];
474
+ }
475
+ function dt(e) {
476
+ return Object.fromEntries(Object.entries(e).filter(([, t]) => t !== void 0));
477
+ }
478
+ function he(e) {
479
+ return e.title ? e.title : e.path ? e.path.slice(e.path.lastIndexOf("/") + 1) || e.path : e.documentId.slice(0, 8);
480
+ }
481
+ const Wt = 4;
482
+ function Vt(e, t = Wt) {
483
+ const n = Array.from({ length: e }, (s, i) => ({ kind: "crumb", index: i }));
484
+ if (e <= t || t < 3) return n;
485
+ const r = t - 1, o = Array.from({ length: e - 1 - r }, (s, i) => i + 1);
486
+ return [n[0], { kind: "gap", hidden: o }, ...n.slice(e - r)];
487
+ }
488
+ function zt(e, t) {
489
+ for (const n of e.values()) {
490
+ const r = n.entries.find((o) => qt(o) === t);
491
+ if (r) return r.full_path;
492
+ }
493
+ }
494
+ function qt(e) {
495
+ if (e.kind === "document")
496
+ return e.resource_ref?.document_id || void 0;
497
+ }
498
+ function Jt(e, t) {
499
+ return t && e.some((n) => n.id === t) ? t : e.find((n) => !n.parent_id)?.id;
500
+ }
501
+ function ut({ trail: e, onJump: t }) {
502
+ const [n, r] = p(!1);
503
+ if (e.length < 2) return null;
504
+ const o = e.length - 1, s = e[o - 1], i = Vt(e.length, n ? e.length : void 0);
505
+ return /* @__PURE__ */ c("nav", { className: "doc-trail", "aria-label": "Documents you came through", children: [
506
+ /* @__PURE__ */ a(
507
+ "button",
508
+ {
509
+ type: "button",
510
+ className: "doc-trail-back",
511
+ onClick: () => t(o - 1),
512
+ title: `Back to ${he(s)}`,
513
+ children: "← Back"
514
+ }
515
+ ),
516
+ /* @__PURE__ */ a("ol", { className: "doc-trail-list", children: i.map(
517
+ (l) => l.kind === "gap" ? /* @__PURE__ */ a("li", { className: "doc-trail-item", children: /* @__PURE__ */ a(
518
+ "button",
519
+ {
520
+ type: "button",
521
+ className: "doc-trail-gap",
522
+ onClick: () => r(!0),
523
+ title: `Show ${l.hidden.length} more: ${l.hidden.map((f) => he(e[f])).join(" › ")}`,
524
+ "aria-label": `Show ${l.hidden.length} hidden documents`,
525
+ children: "…"
526
+ }
527
+ ) }, "gap") : l.index === o ? /* @__PURE__ */ a("li", { className: "doc-trail-item", children: /* @__PURE__ */ a("span", { className: "doc-trail-current", "aria-current": "page", title: he(e[o]), children: he(e[o]) }) }, l.index) : /* @__PURE__ */ a("li", { className: "doc-trail-item", children: /* @__PURE__ */ a(
528
+ "button",
529
+ {
530
+ type: "button",
531
+ className: "doc-trail-crumb",
532
+ onClick: () => t(l.index),
533
+ title: he(e[l.index]),
534
+ children: he(e[l.index])
535
+ }
536
+ ) }, l.index)
537
+ ) })
538
+ ] });
539
+ }
540
+ const Xe = 6;
541
+ function Zt({
232
542
  children: e,
233
- defaultLeftWidth: r = 380,
543
+ defaultLeftWidth: t = 380,
234
544
  minLeftWidth: n = 180,
235
- minRightWidth: a = 240,
545
+ minRightWidth: r = 240,
236
546
  storageKey: o,
237
- className: i
547
+ className: s
238
548
  }) {
239
- const [c, s] = f(() => {
549
+ const [i, l] = p(() => {
240
550
  if (o) {
241
- const C = localStorage.getItem(o), L = C ? parseInt(C, 10) : NaN;
242
- if (Number.isFinite(L) && L >= n) return L;
551
+ const N = localStorage.getItem(o), y = N ? parseInt(N, 10) : NaN;
552
+ if (Number.isFinite(y) && y >= n) return y;
243
553
  }
244
- return r;
245
- }), d = ne(null), [g, m] = f(!1);
246
- B(() => {
247
- !o || g || localStorage.setItem(o, String(Math.round(c)));
248
- }, [o, c, g]);
249
- const k = j((C) => {
250
- C.preventDefault(), m(!0), C.target.setPointerCapture(C.pointerId);
251
- }, []), h = j(
252
- (C) => {
253
- if (!g || !d.current) return;
254
- const L = d.current.getBoundingClientRect(), F = C.clientX - L.left, O = L.width - a - Se, A = Math.max(n, Math.min(F, O));
255
- s(A);
554
+ return t;
555
+ }), f = te(null), [d, h] = p(!1);
556
+ H(() => {
557
+ !o || d || localStorage.setItem(o, String(Math.round(i)));
558
+ }, [o, i, d]);
559
+ const w = P((N) => {
560
+ N.preventDefault(), h(!0), N.target.setPointerCapture(N.pointerId);
561
+ }, []), S = P(
562
+ (N) => {
563
+ if (!d || !f.current) return;
564
+ const y = f.current.getBoundingClientRect(), j = N.clientX - y.left, B = y.width - r - Xe, O = Math.max(n, Math.min(j, B));
565
+ l(O);
256
566
  },
257
- [g, n, a]
258
- ), P = j((C) => {
259
- m(!1);
567
+ [d, n, r]
568
+ ), g = P((N) => {
569
+ h(!1);
260
570
  try {
261
- C.target.releasePointerCapture(C.pointerId);
571
+ N.target.releasePointerCapture(N.pointerId);
262
572
  } catch {
263
573
  }
264
574
  }, []);
265
- return /* @__PURE__ */ l(
575
+ return /* @__PURE__ */ c(
266
576
  "div",
267
577
  {
268
- ref: d,
269
- className: `splitter ${i ?? ""} ${g ? "dragging" : ""}`,
578
+ ref: f,
579
+ className: `splitter ${s ?? ""} ${d ? "dragging" : ""}`,
270
580
  style: {
271
- gridTemplateColumns: `${c}px ${Se}px 1fr`
581
+ gridTemplateColumns: `${i}px ${Xe}px 1fr`
272
582
  },
273
583
  children: [
274
- /* @__PURE__ */ t("div", { className: "splitter-pane splitter-left", children: e[0] }),
275
- /* @__PURE__ */ t(
584
+ /* @__PURE__ */ a("div", { className: "splitter-pane splitter-left", children: e[0] }),
585
+ /* @__PURE__ */ a(
276
586
  "div",
277
587
  {
278
588
  className: "splitter-handle",
279
589
  role: "separator",
280
590
  "aria-orientation": "vertical",
281
- "aria-valuenow": Math.round(c),
282
- onPointerDown: k,
283
- onPointerMove: h,
284
- onPointerUp: P,
285
- onPointerCancel: P
591
+ "aria-valuenow": Math.round(i),
592
+ onPointerDown: w,
593
+ onPointerMove: S,
594
+ onPointerUp: g,
595
+ onPointerCancel: g
286
596
  }
287
597
  ),
288
- /* @__PURE__ */ t("div", { className: "splitter-pane splitter-right", children: e[1] })
598
+ /* @__PURE__ */ a("div", { className: "splitter-pane splitter-right", children: e[1] })
289
599
  ]
290
600
  }
291
601
  );
292
602
  }
293
- const ut = ["image/png", "image/jpeg", "image/gif", "image/webp"];
294
- function Ue(e) {
295
- return ut.includes(e);
603
+ const Xt = ["image/png", "image/jpeg", "image/gif", "image/webp"];
604
+ function ht(e) {
605
+ return Xt.includes(e);
296
606
  }
297
- function Oe(e) {
298
- return new Promise((r, n) => {
299
- if (!Ue(e.type)) {
607
+ function mt(e) {
608
+ return new Promise((t, n) => {
609
+ if (!ht(e.type)) {
300
610
  n(new Error(`unsupported image type "${e.type || "unknown"}" (png, jpeg, gif, webp only)`));
301
611
  return;
302
612
  }
303
- const a = new FileReader();
304
- a.onerror = () => n(a.error ?? new Error("failed to read file")), a.onload = () => {
305
- const o = String(a.result ?? ""), i = o.indexOf(",");
306
- if (i < 0) {
613
+ const r = new FileReader();
614
+ r.onerror = () => n(r.error ?? new Error("failed to read file")), r.onload = () => {
615
+ const o = String(r.result ?? ""), s = o.indexOf(",");
616
+ if (s < 0) {
307
617
  n(new Error("could not decode image data"));
308
618
  return;
309
619
  }
310
- r({ mediaType: e.type, data: o.slice(i + 1) });
311
- }, a.readAsDataURL(e);
620
+ t({ mediaType: e.type, data: o.slice(s + 1) });
621
+ }, r.readAsDataURL(e);
312
622
  });
313
623
  }
314
- function ht(e) {
624
+ function Qt(e) {
315
625
  if (!e) return null;
316
- for (let r = 0; r < e.length; r++) {
317
- const n = e[r];
318
- if (n.kind === "file" && Ue(n.type)) {
319
- const a = n.getAsFile();
320
- if (a) return a;
626
+ for (let t = 0; t < e.length; t++) {
627
+ const n = e[t];
628
+ if (n.kind === "file" && ht(n.type)) {
629
+ const r = n.getAsFile();
630
+ if (r) return r;
321
631
  }
322
632
  }
323
633
  return null;
324
634
  }
325
- const be = {
635
+ const Be = {
326
636
  "doc.rfc.draft": "#c99a3a",
327
637
  "doc.rfc.review": "#6a7bd6",
328
638
  "doc.rfc.confirmed": "#3a9ad6",
@@ -343,125 +653,154 @@ const be = {
343
653
  "chunk.backlog": "#8a8f98",
344
654
  "chunk.implementation": "#d1863a",
345
655
  "chunk.merged": "#3aa06a"
346
- }, mt = 0.16;
347
- function ke(e) {
348
- return e && Object.keys(e).length > 0 ? e : be;
656
+ }, Yt = 0.16;
657
+ function Ge(e) {
658
+ return e && Object.keys(e).length > 0 ? e : Be;
349
659
  }
350
- function Ie(e, r, n) {
351
- const a = e ?? "", o = r ?? "";
352
- if (a && o && n[`doc.${a}.${o}`]) return n[`doc.${a}.${o}`];
353
- if (a && n[`doc.${a}`]) return n[`doc.${a}`];
660
+ function ft(e, t, n) {
661
+ const r = e ?? "", o = t ?? "";
662
+ if (r && o && n[`doc.${r}.${o}`]) return n[`doc.${r}.${o}`];
663
+ if (r && n[`doc.${r}`]) return n[`doc.${r}`];
354
664
  }
355
- function pt(e, r) {
665
+ function Kt(e, t) {
356
666
  const n = e ?? "";
357
- return n ? r[`chunk.${n}`] : void 0;
667
+ return n ? t[`chunk.${n}`] : void 0;
358
668
  }
359
- function ft(e) {
360
- const r = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());
361
- if (!r) return;
362
- let n = r[1];
669
+ function en(e) {
670
+ const t = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());
671
+ if (!t) return;
672
+ let n = t[1];
363
673
  n.length === 3 && (n = n[0] + n[0] + n[1] + n[1] + n[2] + n[2]);
364
- const a = parseInt(n.slice(0, 2), 16), o = parseInt(n.slice(2, 4), 16), i = parseInt(n.slice(4, 6), 16);
365
- return `rgba(${a}, ${o}, ${i}, ${mt})`;
674
+ const r = parseInt(n.slice(0, 2), 16), o = parseInt(n.slice(2, 4), 16), s = parseInt(n.slice(4, 6), 16);
675
+ return `rgba(${r}, ${o}, ${s}, ${Yt})`;
366
676
  }
367
- function Ne(e) {
677
+ function He(e) {
368
678
  if (!e) return;
369
- const r = ft(e);
370
- if (r)
371
- return { background: r, borderLeft: `3px solid ${e}` };
679
+ const t = en(e);
680
+ if (t)
681
+ return { background: t, borderLeft: `3px solid ${e}` };
682
+ }
683
+ async function tn(e) {
684
+ try {
685
+ return typeof navigator > "u" || !navigator.clipboard ? !1 : (await navigator.clipboard.writeText(e), !0);
686
+ } catch {
687
+ return !1;
688
+ }
372
689
  }
373
- function gt(e) {
374
- const r = /* @__PURE__ */ new Map();
375
- e.forEach((o) => r.set(o.id, { row: o, children: [] }));
690
+ function Fe({ value: e, label: t, compact: n, title: r }) {
691
+ const [o, s] = p("idle"), i = async (h) => {
692
+ h.stopPropagation(), h.preventDefault();
693
+ const w = await tn(e);
694
+ s(w ? "copied" : "error"), window.setTimeout(() => s("idle"), w ? 1200 : 1500);
695
+ }, l = o === "copied" ? "✓" : o === "error" ? "✗" : "⎘", f = r ?? `Copy ${t ?? "id"}: ${e}`, d = /* @__PURE__ */ a(
696
+ "button",
697
+ {
698
+ type: "button",
699
+ className: `id-copy-btn id-copy-${o}`,
700
+ onClick: i,
701
+ title: f,
702
+ "aria-label": f,
703
+ children: l
704
+ }
705
+ );
706
+ return n ? d : /* @__PURE__ */ c("span", { className: "id-copy", children: [
707
+ t && /* @__PURE__ */ a("span", { className: "id-copy-label", children: t }),
708
+ /* @__PURE__ */ a("code", { className: "id-copy-value", title: e, children: e }),
709
+ d
710
+ ] });
711
+ }
712
+ function nn(e) {
713
+ const t = /* @__PURE__ */ new Map();
714
+ e.forEach((o) => t.set(o.id, { row: o, children: [] }));
376
715
  const n = [];
377
716
  e.forEach((o) => {
378
- const i = r.get(o.id);
379
- o.parent_id && r.has(o.parent_id) ? r.get(o.parent_id).children.push(i) : n.push(i);
717
+ const s = t.get(o.id);
718
+ o.parent_id && t.has(o.parent_id) ? t.get(o.parent_id).children.push(s) : n.push(s);
380
719
  });
381
- const a = (o) => {
382
- o.sort((i, c) => i.row.position - c.row.position), o.forEach((i) => a(i.children));
720
+ const r = (o) => {
721
+ o.sort((s, i) => s.row.position - i.row.position), o.forEach((s) => r(s.children));
383
722
  };
384
- return a(n), n;
723
+ return r(n), n;
385
724
  }
386
- function Ee(e) {
725
+ function Qe(e) {
387
726
  return e === "image" ? "🖼" : e === "mermaid" ? "📊" : "";
388
727
  }
389
- function je(e, r) {
728
+ function pt(e, t) {
390
729
  for (const n of e) {
391
- if (n.row.id === r) return n;
392
- const a = je(n.children, r);
393
- if (a) return a;
730
+ if (n.row.id === t) return n;
731
+ const r = pt(n.children, t);
732
+ if (r) return r;
394
733
  }
395
734
  }
396
- function yt({
735
+ function an({
397
736
  tree: e,
398
- selectedId: r,
737
+ selectedId: t,
399
738
  onSelect: n,
400
- colorEnabled: a,
739
+ colorEnabled: r,
401
740
  scheme: o,
402
- linkedIds: i
741
+ linkedIds: s
403
742
  }) {
404
- const [c, s] = f(() => /* @__PURE__ */ new Map()), d = j((m) => {
405
- s((k) => {
406
- const h = new Map(k);
407
- return h.set(m, k.get(m) === !1), h;
743
+ const [i, l] = p(() => /* @__PURE__ */ new Map()), f = P((h) => {
744
+ l((w) => {
745
+ const S = new Map(w);
746
+ return S.set(h, w.get(h) === !1), S;
408
747
  });
409
748
  }, []);
410
- B(() => {
411
- if (!r) return;
412
- const m = bt(e, r);
413
- m.length !== 0 && s((k) => {
414
- let h = !1;
415
- const P = new Map(k);
416
- for (const C of m)
417
- P.get(C) === !1 && (P.set(C, !0), h = !0);
418
- return h ? P : k;
749
+ H(() => {
750
+ if (!t) return;
751
+ const h = rn(e, t);
752
+ h.length !== 0 && l((w) => {
753
+ let S = !1;
754
+ const g = new Map(w);
755
+ for (const N of h)
756
+ g.get(N) === !1 && (g.set(N, !0), S = !0);
757
+ return S ? g : w;
419
758
  });
420
- }, [e, r]);
421
- const g = a ? ke(o) : null;
422
- return e.length === 0 ? /* @__PURE__ */ t("div", { className: "empty", children: /* @__PURE__ */ t("p", { children: "No chunks." }) }) : /* @__PURE__ */ t("ul", { className: "tree chunk-tree", children: e.map((m) => /* @__PURE__ */ t(
423
- Be,
759
+ }, [e, t]);
760
+ const d = r ? Ge(o) : null;
761
+ return e.length === 0 ? /* @__PURE__ */ a("div", { className: "empty", children: /* @__PURE__ */ a("p", { children: "No chunks." }) }) : /* @__PURE__ */ a("ul", { className: "tree chunk-tree", children: e.map((h) => /* @__PURE__ */ a(
762
+ gt,
424
763
  {
425
- node: m,
426
- expanded: c,
427
- toggle: d,
428
- selectedId: r,
764
+ node: h,
765
+ expanded: i,
766
+ toggle: f,
767
+ selectedId: t,
429
768
  onSelect: n,
430
- tintScheme: g,
431
- linkedIds: i
769
+ tintScheme: d,
770
+ linkedIds: s
432
771
  },
433
- m.row.id
772
+ h.row.id
434
773
  )) });
435
774
  }
436
- function bt(e, r) {
437
- const n = [], a = (o, i) => {
438
- for (const c of o) {
439
- if (c.row.id === r)
440
- return n.push(...i), !0;
441
- if (a(c.children, [...i, c.row.id])) return !0;
775
+ function rn(e, t) {
776
+ const n = [], r = (o, s) => {
777
+ for (const i of o) {
778
+ if (i.row.id === t)
779
+ return n.push(...s), !0;
780
+ if (r(i.children, [...s, i.row.id])) return !0;
442
781
  }
443
782
  return !1;
444
783
  };
445
- return a(e, []), n;
784
+ return r(e, []), n;
446
785
  }
447
- function Be({ node: e, expanded: r, toggle: n, selectedId: a, onSelect: o, tintScheme: i, linkedIds: c }) {
448
- const s = e.children.length > 0, d = r.get(e.row.id) !== !1, g = a === e.row.id, m = i ? Ne(pt(e.row.status, i)) : void 0, k = c?.has(e.row.id);
449
- return /* @__PURE__ */ l("li", { className: `node chunk-node ${g ? "selected" : ""}`, children: [
450
- /* @__PURE__ */ l("div", { className: "row chunk-row", style: m, children: [
451
- /* @__PURE__ */ t(
786
+ function gt({ node: e, expanded: t, toggle: n, selectedId: r, onSelect: o, tintScheme: s, linkedIds: i }) {
787
+ const l = e.children.length > 0, f = t.get(e.row.id) !== !1, d = r === e.row.id, h = s ? He(Kt(e.row.status, s)) : void 0, w = i?.has(e.row.id);
788
+ return /* @__PURE__ */ c("li", { className: `node chunk-node ${d ? "selected" : ""}`, children: [
789
+ /* @__PURE__ */ c("div", { className: "row chunk-row", style: h, children: [
790
+ /* @__PURE__ */ a(
452
791
  "button",
453
792
  {
454
793
  type: "button",
455
794
  className: "tree-caret",
456
- "aria-label": d ? "collapse" : "expand",
457
- disabled: !s,
458
- onClick: (h) => {
459
- h.stopPropagation(), s && n(e.row.id);
795
+ "aria-label": f ? "collapse" : "expand",
796
+ disabled: !l,
797
+ onClick: (S) => {
798
+ S.stopPropagation(), l && n(e.row.id);
460
799
  },
461
- children: s ? d ? "▼" : "▶" : "·"
800
+ children: l ? f ? "▼" : "▶" : "·"
462
801
  }
463
802
  ),
464
- /* @__PURE__ */ l(
803
+ /* @__PURE__ */ c(
465
804
  "button",
466
805
  {
467
806
  type: "button",
@@ -469,1463 +808,1631 @@ function Be({ node: e, expanded: r, toggle: n, selectedId: a, onSelect: o, tintS
469
808
  onClick: () => o(e),
470
809
  title: e.row.title,
471
810
  children: [
472
- Ee(e.row.type) && /* @__PURE__ */ t("span", { className: "chunk-type-icon", "aria-hidden": !0, children: Ee(e.row.type) }),
473
- /* @__PURE__ */ t("span", { className: "chunk-title", children: e.row.title || "(untitled)" }),
474
- e.row.type && /* @__PURE__ */ t("span", { className: "chunk-badge", children: e.row.type }),
475
- e.row.status && /* @__PURE__ */ t("span", { className: "chunk-badge chunk-status", children: e.row.status }),
476
- k && /* @__PURE__ */ t("span", { className: "chunk-link-badge", title: "Has cross-reference links", "aria-label": "linked", children: "🔗" })
811
+ Qe(e.row.type) && /* @__PURE__ */ a("span", { className: "chunk-type-icon", "aria-hidden": !0, children: Qe(e.row.type) }),
812
+ /* @__PURE__ */ a("span", { className: "chunk-title", children: e.row.title || "(untitled)" }),
813
+ e.row.type && /* @__PURE__ */ a("span", { className: "chunk-badge", children: e.row.type }),
814
+ e.row.status && /* @__PURE__ */ a("span", { className: "chunk-badge chunk-status", children: e.row.status }),
815
+ w && /* @__PURE__ */ a("span", { className: "chunk-link-badge", title: "Has cross-reference links", "aria-label": "linked", children: "🔗" })
477
816
  ]
478
817
  }
479
- )
818
+ ),
819
+ /* @__PURE__ */ a(Fe, { value: e.row.id, compact: !0, title: `Copy chunk id: ${e.row.id}` })
480
820
  ] }),
481
- s && d && /* @__PURE__ */ t("ul", { className: "children chunk-children", children: e.children.map((h) => /* @__PURE__ */ t(
482
- Be,
821
+ l && f && /* @__PURE__ */ a("ul", { className: "children chunk-children", children: e.children.map((S) => /* @__PURE__ */ a(
822
+ gt,
483
823
  {
484
- node: h,
485
- expanded: r,
824
+ node: S,
825
+ expanded: t,
486
826
  toggle: n,
487
- selectedId: a,
827
+ selectedId: r,
488
828
  onSelect: o,
489
- tintScheme: i,
490
- linkedIds: c
829
+ tintScheme: s,
830
+ linkedIds: i
491
831
  },
492
- h.row.id
832
+ S.row.id
493
833
  )) })
494
834
  ] });
495
835
  }
496
- let vt = 0;
497
- function ue({ code: e }) {
498
- const r = ne(null), [n, a] = f({});
499
- return B(() => {
500
- let o = !1;
836
+ let on = 0;
837
+ function sn(e) {
838
+ const t = e?.closest("g.node");
839
+ return t ? /flowchart-(.+)-\d+$/.exec(t.id)?.[1] : void 0;
840
+ }
841
+ function Te({
842
+ code: e,
843
+ onNodeClick: t
844
+ }) {
845
+ const n = te(null), [r, o] = p({});
846
+ return H(() => {
847
+ let s = !1;
501
848
  return (async () => {
502
849
  try {
503
- const i = (await import("mermaid")).default, c = r.current?.closest("[data-theme]")?.getAttribute("data-theme"), s = c ? c === "dark" : !0;
504
- i.initialize({ startOnLoad: !1, theme: s ? "dark" : "default", securityLevel: "strict" });
505
- const { svg: d } = await i.render(`lc-mmd-${vt++}`, e);
506
- o || a({ svg: d });
850
+ const i = (await import("mermaid")).default, l = n.current?.closest("[data-theme]")?.getAttribute("data-theme"), f = l ? l === "dark" : !0;
851
+ i.initialize({ startOnLoad: !1, theme: f ? "dark" : "default", securityLevel: "strict" });
852
+ const { svg: d } = await i.render(`lc-mmd-${on++}`, e);
853
+ s || o({ svg: d });
507
854
  } catch {
508
- o || a({ err: !0 });
855
+ s || o({ err: !0 });
509
856
  }
510
857
  })(), () => {
511
- o = !0;
858
+ s = !0;
512
859
  };
513
- }, [e]), n.err ? /* @__PURE__ */ t("pre", { className: "md-pre md-mermaid-error", title: "diagram failed to render", children: /* @__PURE__ */ t("code", { children: e }) }) : n.svg ? /* @__PURE__ */ t("div", { ref: r, className: "md-mermaid", dangerouslySetInnerHTML: { __html: n.svg } }) : /* @__PURE__ */ t("div", { ref: r, className: "md-mermaid md-mermaid-loading", children: "rendering diagram…" });
860
+ }, [e]), r.err ? /* @__PURE__ */ a("pre", { className: "md-pre md-mermaid-error", title: "diagram failed to render", children: /* @__PURE__ */ a("code", { children: e }) }) : r.svg ? /* @__PURE__ */ a(
861
+ "div",
862
+ {
863
+ ref: n,
864
+ className: t ? "md-mermaid md-mermaid-nav" : "md-mermaid",
865
+ onClick: t && ((s) => {
866
+ const i = sn(s.target);
867
+ i && t(i);
868
+ }),
869
+ dangerouslySetInnerHTML: { __html: r.svg }
870
+ }
871
+ ) : /* @__PURE__ */ a("div", { ref: n, className: "md-mermaid md-mermaid-loading", children: "rendering diagram…" });
514
872
  }
515
- function kt({ chunk: e, scope: r, browse: n, onClose: a, onSaved: o }) {
516
- const i = ae(), [c, s] = f(e.title), [d, g] = f(e.type ?? ""), [m, k] = f(e.status ?? ""), [h, P] = f(e.body ?? ""), [C, L] = f(
873
+ function cn({ chunk: e, scope: t, browse: n, onClose: r, onSaved: o }) {
874
+ const s = be(), [i, l] = p(e.title), [f, d] = p(e.type ?? ""), [h, w] = p(e.status ?? ""), [S, g] = p(e.body ?? ""), [N, y] = p(
517
875
  e.fields ? JSON.stringify(e.fields, null, 2) : ""
518
- ), [F, O] = f((e.tags ?? []).join(", ")), [A, M] = f(!1), [I, $] = f(null), [G, R] = f(!1), y = d === "mermaid", D = d === "image" || !!e.asset, [J, V] = f(h);
519
- B(() => {
520
- if (!y) return;
521
- const w = setTimeout(() => V(h), 400);
522
- return () => clearTimeout(w);
523
- }, [h, y]);
524
- const N = async (w) => {
525
- $(null), M(!0);
876
+ ), [j, B] = p((e.tags ?? []).join(", ")), [O, W] = p(!1), [q, I] = p(null), [V, z] = p(!1), Z = f === "mermaid", _ = f === "image" || !!e.asset, [R, E] = p(S);
877
+ H(() => {
878
+ if (!Z) return;
879
+ const x = setTimeout(() => E(S), 400);
880
+ return () => clearTimeout(x);
881
+ }, [S, Z]);
882
+ const m = async (x) => {
883
+ I(null), W(!0);
526
884
  try {
527
- const { mediaType: S, data: T } = await Oe(w), ee = await i.documentSetAsset(e.id, S, T, w.name, r, n);
528
- o(ee), a();
529
- } catch (S) {
530
- $(S instanceof Error ? S.message : String(S)), M(!1);
885
+ const { mediaType: U, data: M } = await mt(x), ne = await s.documentSetAsset(e.id, U, M, x.name, t, n);
886
+ o(ne), r();
887
+ } catch (U) {
888
+ I(U instanceof Error ? U.message : String(U)), W(!1);
531
889
  }
532
890
  };
533
- return /* @__PURE__ */ t("div", { className: "modal-overlay", onClick: a, children: /* @__PURE__ */ l("form", { className: "modal chunk-editor", onClick: (w) => w.stopPropagation(), onSubmit: async (w) => {
534
- w.preventDefault(), $(null), R(!1);
535
- const S = {
536
- body: h,
537
- title: c,
538
- type: d,
539
- status: m,
891
+ return /* @__PURE__ */ a("div", { className: "modal-overlay", onClick: r, children: /* @__PURE__ */ c("form", { className: "modal chunk-editor", onClick: (x) => x.stopPropagation(), onSubmit: async (x) => {
892
+ x.preventDefault(), I(null), z(!1);
893
+ const U = {
894
+ body: S,
895
+ title: i,
896
+ type: f,
897
+ status: h,
540
898
  // Parse the comma-separated list; replace-set is intentional (the box shows
541
899
  // the chunk's tags, so saving makes it exactly what's in the box).
542
- tags: F.split(",").map((T) => T.trim()).filter((T) => T !== "")
900
+ tags: j.split(",").map((M) => M.trim()).filter((M) => M !== "")
543
901
  };
544
- if (C.trim() !== "")
902
+ if (N.trim() !== "")
545
903
  try {
546
- S.fields = JSON.parse(C);
904
+ U.fields = JSON.parse(N);
547
905
  } catch {
548
- $("fields must be valid JSON");
906
+ I("fields must be valid JSON");
549
907
  return;
550
908
  }
551
- M(!0);
909
+ W(!0);
552
910
  try {
553
- const T = await i.documentUpdateChunk(e.id, e.revision, S, r, n);
554
- o(T), a();
555
- } catch (T) {
556
- const ee = T instanceof Error ? T.message : String(T);
557
- $(ee), R(/revision conflict/i.test(ee)), M(!1);
911
+ const M = await s.documentUpdateChunk(e.id, e.revision, U, t, n);
912
+ o(M), r();
913
+ } catch (M) {
914
+ const ne = M instanceof Error ? M.message : String(M);
915
+ I(ne), z(/revision conflict/i.test(ne)), W(!1);
558
916
  }
559
917
  }, children: [
560
- /* @__PURE__ */ l("div", { className: "modal-header sticky-top", children: [
561
- /* @__PURE__ */ t("h3", { children: "Edit chunk" }),
562
- /* @__PURE__ */ l("div", { className: "modal-buttons modal-buttons-top", children: [
563
- /* @__PURE__ */ t("button", { type: "button", onClick: a, disabled: A, children: "cancel" }),
564
- /* @__PURE__ */ t("button", { type: "submit", className: "primary", disabled: A, children: A ? "saving…" : "save" })
918
+ /* @__PURE__ */ c("div", { className: "modal-header sticky-top", children: [
919
+ /* @__PURE__ */ a("h3", { children: "Edit chunk" }),
920
+ /* @__PURE__ */ c("div", { className: "modal-buttons modal-buttons-top", children: [
921
+ /* @__PURE__ */ a("button", { type: "button", onClick: r, disabled: O, children: "cancel" }),
922
+ /* @__PURE__ */ a("button", { type: "submit", className: "primary", disabled: O, children: O ? "saving…" : "save" })
565
923
  ] })
566
924
  ] }),
567
- I && /* @__PURE__ */ l("div", { className: "modal-err", children: [
568
- I,
569
- G && " — reopen the chunk to load the latest, then reapply your edit."
925
+ q && /* @__PURE__ */ c("div", { className: "modal-err", children: [
926
+ q,
927
+ V && " — reopen the chunk to load the latest, then reapply your edit."
570
928
  ] }),
571
- /* @__PURE__ */ l("label", { className: "path-field", children: [
572
- /* @__PURE__ */ t("span", { children: "Title" }),
573
- /* @__PURE__ */ t("input", { className: "path-modal-input", value: c, onChange: (w) => s(w.target.value) })
929
+ /* @__PURE__ */ c("label", { className: "path-field", children: [
930
+ /* @__PURE__ */ a("span", { children: "Title" }),
931
+ /* @__PURE__ */ a("input", { className: "path-modal-input", value: i, onChange: (x) => l(x.target.value) })
574
932
  ] }),
575
- /* @__PURE__ */ l("div", { className: "chunk-editor-row", children: [
576
- /* @__PURE__ */ l("label", { className: "path-field", children: [
577
- /* @__PURE__ */ t("span", { children: "Type" }),
578
- /* @__PURE__ */ t(
933
+ /* @__PURE__ */ c("div", { className: "chunk-editor-row", children: [
934
+ /* @__PURE__ */ c("label", { className: "path-field", children: [
935
+ /* @__PURE__ */ a("span", { children: "Type" }),
936
+ /* @__PURE__ */ a(
579
937
  "input",
580
938
  {
581
939
  className: "path-modal-input",
582
- value: d,
940
+ value: f,
583
941
  placeholder: "(none)",
584
- onChange: (w) => g(w.target.value)
942
+ onChange: (x) => d(x.target.value)
585
943
  }
586
944
  )
587
945
  ] }),
588
- /* @__PURE__ */ l("label", { className: "path-field", children: [
589
- /* @__PURE__ */ t("span", { children: "Status" }),
590
- /* @__PURE__ */ t(
946
+ /* @__PURE__ */ c("label", { className: "path-field", children: [
947
+ /* @__PURE__ */ a("span", { children: "Status" }),
948
+ /* @__PURE__ */ a(
591
949
  "input",
592
950
  {
593
951
  className: "path-modal-input",
594
- value: m,
952
+ value: h,
595
953
  placeholder: "(none)",
596
- onChange: (w) => k(w.target.value)
954
+ onChange: (x) => w(x.target.value)
597
955
  }
598
956
  )
599
957
  ] })
600
958
  ] }),
601
- /* @__PURE__ */ l("label", { className: "path-field", children: [
602
- /* @__PURE__ */ t("span", { children: "Tags" }),
603
- /* @__PURE__ */ t(
959
+ /* @__PURE__ */ c("label", { className: "path-field", children: [
960
+ /* @__PURE__ */ a("span", { children: "Tags" }),
961
+ /* @__PURE__ */ a(
604
962
  "input",
605
963
  {
606
964
  className: "path-modal-input",
607
- value: F,
965
+ value: j,
608
966
  placeholder: "comma-separated, nest with a slash: area/sub, priority/high",
609
- onChange: (w) => O(w.target.value)
967
+ onChange: (x) => B(x.target.value)
610
968
  }
611
969
  )
612
970
  ] }),
613
- D && /* @__PURE__ */ l("label", { className: "path-field", children: [
614
- /* @__PURE__ */ t("span", { children: "Replace image" }),
615
- /* @__PURE__ */ t(
971
+ _ && /* @__PURE__ */ c("label", { className: "path-field", children: [
972
+ /* @__PURE__ */ a("span", { children: "Replace image" }),
973
+ /* @__PURE__ */ a(
616
974
  "input",
617
975
  {
618
976
  type: "file",
619
977
  accept: "image/png,image/jpeg,image/gif,image/webp",
620
- disabled: A,
621
- onChange: (w) => {
622
- const S = w.target.files?.[0];
623
- S && N(S);
978
+ disabled: O,
979
+ onChange: (x) => {
980
+ const U = x.target.files?.[0];
981
+ U && m(U);
624
982
  }
625
983
  }
626
984
  )
627
985
  ] }),
628
- /* @__PURE__ */ l("label", { className: "path-field", children: [
629
- /* @__PURE__ */ t("span", { children: y ? "Mermaid source" : D ? "Caption (optional)" : "Body (Markdown)" }),
630
- /* @__PURE__ */ t(
986
+ /* @__PURE__ */ c("label", { className: "path-field", children: [
987
+ /* @__PURE__ */ a("span", { children: Z ? "Mermaid source" : _ ? "Caption (optional)" : "Body (Markdown)" }),
988
+ /* @__PURE__ */ a(
631
989
  "textarea",
632
990
  {
633
991
  className: "modal-textarea chunk-body-input",
634
- rows: y ? 8 : 12,
635
- value: h,
636
- onChange: (w) => P(w.target.value)
992
+ rows: Z ? 8 : 12,
993
+ value: S,
994
+ onChange: (x) => g(x.target.value)
637
995
  }
638
996
  )
639
997
  ] }),
640
- y && /* @__PURE__ */ l("div", { className: "path-field", children: [
641
- /* @__PURE__ */ t("span", { children: "Preview" }),
642
- /* @__PURE__ */ t("div", { className: "chunk-mermaid-preview", children: J.trim() ? /* @__PURE__ */ t(ue, { code: J }) : /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "(enter Mermaid source above)" }) })
998
+ Z && /* @__PURE__ */ c("div", { className: "path-field", children: [
999
+ /* @__PURE__ */ a("span", { children: "Preview" }),
1000
+ /* @__PURE__ */ a("div", { className: "chunk-mermaid-preview", children: R.trim() ? /* @__PURE__ */ a(Te, { code: R }) : /* @__PURE__ */ a("p", { className: "doc-empty-body", children: "(enter Mermaid source above)" }) })
643
1001
  ] }),
644
- /* @__PURE__ */ l("label", { className: "path-field", children: [
645
- /* @__PURE__ */ t("span", { children: "Fields (JSON, optional)" }),
646
- /* @__PURE__ */ t(
1002
+ /* @__PURE__ */ c("label", { className: "path-field", children: [
1003
+ /* @__PURE__ */ a("span", { children: "Fields (JSON, optional)" }),
1004
+ /* @__PURE__ */ a(
647
1005
  "textarea",
648
1006
  {
649
1007
  className: "modal-textarea chunk-fields-input",
650
1008
  rows: 4,
651
- value: C,
1009
+ value: N,
652
1010
  placeholder: "{}",
653
- onChange: (w) => L(w.target.value)
1011
+ onChange: (x) => y(x.target.value)
654
1012
  }
655
1013
  )
656
1014
  ] })
657
1015
  ] }) });
658
1016
  }
659
- function Nt(e) {
660
- const r = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec((e ?? "").trim());
661
- if (!r) return "#888888";
662
- let n = r[1];
1017
+ function ln(e) {
1018
+ const t = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec((e ?? "").trim());
1019
+ if (!t) return "#888888";
1020
+ let n = t[1];
663
1021
  return n.length === 3 && (n = n[0] + n[0] + n[1] + n[1] + n[2] + n[2]), "#" + n.toLowerCase();
664
1022
  }
665
- function wt({
1023
+ function dn({
666
1024
  documentId: e,
667
- rootChunkId: r,
1025
+ rootChunkId: t,
668
1026
  docType: n,
669
- docStatus: a,
1027
+ docStatus: r,
670
1028
  chunkStatuses: o,
671
- scope: i,
672
- browse: c,
673
- onClose: s,
674
- onSaved: d
1029
+ scope: s,
1030
+ browse: i,
1031
+ onClose: l,
1032
+ onSaved: f
675
1033
  }) {
676
- const g = ae(), [m, k] = f(null), [h, P] = f(!1), [C, L] = f({}), [F, O] = f(!1), [A, M] = f(null), [I, $] = f(null), G = q(() => {
677
- const b = new Set(Object.keys(be));
678
- n && b.add(`doc.${n}.${a || "draft"}`);
679
- for (const p of o) p && b.add(`chunk.${p}`);
1034
+ const d = be(), [h, w] = p(null), [S, g] = p(!1), [N, y] = p({}), [j, B] = p(!1), [O, W] = p(null), [q, I] = p(null), V = X(() => {
1035
+ const b = new Set(Object.keys(Be));
1036
+ n && b.add(`doc.${n}.${r || "draft"}`);
1037
+ for (const C of o) C && b.add(`chunk.${C}`);
680
1038
  return [...b].sort();
681
- }, [n, a, o]);
682
- B(() => {
1039
+ }, [n, r, o]);
1040
+ H(() => {
683
1041
  let b = !1;
684
- return g.documentGetChunk(r, i, c).then((p) => {
1042
+ return d.documentGetChunk(t, s, i).then((C) => {
685
1043
  if (b) return;
686
- k(p);
687
- const w = p.fields ?? {};
688
- P(w.color_enabled === !0);
689
- const S = w.color_scheme ?? {};
690
- L({ ...be, ...S });
691
- }).catch((p) => !b && $(p instanceof Error ? p.message : String(p))), () => {
1044
+ w(C);
1045
+ const x = C.fields ?? {};
1046
+ g(x.color_enabled === !0);
1047
+ const U = x.color_scheme ?? {};
1048
+ y({ ...Be, ...U });
1049
+ }).catch((C) => !b && I(C instanceof Error ? C.message : String(C))), () => {
692
1050
  b = !0;
693
1051
  };
694
- }, [g, r, i, c]);
695
- const R = (b, p) => L((w) => ({ ...w, [b]: p })), y = (b) => ({
1052
+ }, [d, t, s, i]);
1053
+ const z = (b, C) => y((x) => ({ ...x, [b]: C })), Z = (b) => ({
696
1054
  ...b ?? {},
697
- color_enabled: h,
698
- color_scheme: C
699
- }), D = async () => {
700
- if (m) {
701
- O(!0), $(null), M(null);
1055
+ color_enabled: S,
1056
+ color_scheme: N
1057
+ }), _ = async () => {
1058
+ if (h) {
1059
+ B(!0), I(null), W(null);
702
1060
  try {
703
- await g.documentUpdateChunk(
704
- r,
705
- m.revision,
706
- { fields: y(m.fields) },
707
- i,
708
- c
709
- ), d(), s();
1061
+ await d.documentUpdateChunk(
1062
+ t,
1063
+ h.revision,
1064
+ { fields: Z(h.fields) },
1065
+ s,
1066
+ i
1067
+ ), f(), l();
710
1068
  } catch (b) {
711
- $(b instanceof Error ? b.message : String(b)), O(!1);
1069
+ I(b instanceof Error ? b.message : String(b)), B(!1);
712
1070
  }
713
1071
  }
714
- }, J = async () => {
1072
+ }, R = async () => {
715
1073
  if (!n) {
716
- $("this document has no type to match");
1074
+ I("this document has no type to match");
717
1075
  return;
718
1076
  }
719
- O(!0), $(null), M(null);
1077
+ B(!0), I(null), W(null);
720
1078
  try {
721
- const { documents: b } = await g.documentsSummary({ underPath: "/" }, i, c), p = (b ?? []).filter(
722
- (S) => S.type === n && S.document_id !== e && S.root_chunk_id
1079
+ const { documents: b } = await d.documentsSummary({ underPath: "/" }, s, i), C = (b ?? []).filter(
1080
+ (U) => U.type === n && U.document_id !== e && U.root_chunk_id
723
1081
  );
724
- let w = 0;
725
- for (const S of p)
1082
+ let x = 0;
1083
+ for (const U of C)
726
1084
  try {
727
- const T = await g.documentGetChunk(S.root_chunk_id, i, c);
728
- await g.documentUpdateChunk(
729
- S.root_chunk_id,
730
- T.revision,
731
- { fields: y(T.fields) },
732
- i,
733
- c
734
- ), w++;
1085
+ const M = await d.documentGetChunk(U.root_chunk_id, s, i);
1086
+ await d.documentUpdateChunk(
1087
+ U.root_chunk_id,
1088
+ M.revision,
1089
+ { fields: Z(M.fields) },
1090
+ s,
1091
+ i
1092
+ ), x++;
735
1093
  } catch {
736
1094
  }
737
- M(`Applied to ${w} other ${n} document(s).`), d();
1095
+ W(`Applied to ${x} other ${n} document(s).`), f();
738
1096
  } catch (b) {
739
- $(b instanceof Error ? b.message : String(b));
1097
+ I(b instanceof Error ? b.message : String(b));
740
1098
  } finally {
741
- O(!1);
1099
+ B(!1);
742
1100
  }
743
- }, V = G.filter((b) => b.startsWith("doc.")), N = G.filter((b) => b.startsWith("chunk."));
744
- return /* @__PURE__ */ t("div", { className: "modal-overlay", onClick: s, children: /* @__PURE__ */ l("div", { className: "modal scheme-editor", onClick: (b) => b.stopPropagation(), children: [
745
- /* @__PURE__ */ l("div", { className: "scheme-editor-head", children: [
746
- /* @__PURE__ */ t("h3", { children: "Document colors" }),
747
- /* @__PURE__ */ l("div", { className: "scheme-editor-actions", children: [
748
- /* @__PURE__ */ t("button", { type: "button", onClick: s, disabled: F, children: "cancel" }),
749
- /* @__PURE__ */ t("button", { type: "button", className: "primary", onClick: () => {
750
- D();
751
- }, disabled: F || !m, children: F ? "saving…" : "save" })
1101
+ }, E = V.filter((b) => b.startsWith("doc.")), m = V.filter((b) => b.startsWith("chunk."));
1102
+ return /* @__PURE__ */ a("div", { className: "modal-overlay", onClick: l, children: /* @__PURE__ */ c("div", { className: "modal scheme-editor", onClick: (b) => b.stopPropagation(), children: [
1103
+ /* @__PURE__ */ c("div", { className: "scheme-editor-head", children: [
1104
+ /* @__PURE__ */ a("h3", { children: "Document colors" }),
1105
+ /* @__PURE__ */ c("div", { className: "scheme-editor-actions", children: [
1106
+ /* @__PURE__ */ a("button", { type: "button", onClick: l, disabled: j, children: "cancel" }),
1107
+ /* @__PURE__ */ a("button", { type: "button", className: "primary", onClick: () => {
1108
+ _();
1109
+ }, disabled: j || !h, children: j ? "saving…" : "save" })
752
1110
  ] })
753
1111
  ] }),
754
- I && /* @__PURE__ */ t("div", { className: "modal-err", children: I }),
755
- m ? /* @__PURE__ */ l(Y, { children: [
756
- /* @__PURE__ */ l("label", { className: "scheme-toggle", children: [
757
- /* @__PURE__ */ t(
1112
+ q && /* @__PURE__ */ a("div", { className: "modal-err", children: q }),
1113
+ h ? /* @__PURE__ */ c(Q, { children: [
1114
+ /* @__PURE__ */ c("label", { className: "scheme-toggle", children: [
1115
+ /* @__PURE__ */ a(
758
1116
  "input",
759
1117
  {
760
1118
  type: "checkbox",
761
- checked: h,
762
- onChange: (b) => P(b.target.checked)
1119
+ checked: S,
1120
+ onChange: (b) => g(b.target.checked)
763
1121
  }
764
1122
  ),
765
- /* @__PURE__ */ t("span", { children: "Enable coloring for this document" })
1123
+ /* @__PURE__ */ a("span", { children: "Enable coloring for this document" })
766
1124
  ] }),
767
- /* @__PURE__ */ t("p", { className: "modal-context", children: "Document rows are tinted by type + status; chunk tiles by status. Colors apply as a semi-transparent wash so text stays readable." }),
768
- /* @__PURE__ */ l("div", { className: "scheme-group", children: [
769
- /* @__PURE__ */ t("h4", { children: "Document (type · status)" }),
770
- V.map((b) => /* @__PURE__ */ t(xe, { label: b.slice(4), value: C[b], onChange: (p) => R(b, p) }, b))
1125
+ /* @__PURE__ */ a("p", { className: "modal-context", children: "Document rows are tinted by type + status; chunk tiles by status. Colors apply as a semi-transparent wash so text stays readable." }),
1126
+ /* @__PURE__ */ c("div", { className: "scheme-group", children: [
1127
+ /* @__PURE__ */ a("h4", { children: "Document (type · status)" }),
1128
+ E.map((b) => /* @__PURE__ */ a(Ye, { label: b.slice(4), value: N[b], onChange: (C) => z(b, C) }, b))
771
1129
  ] }),
772
- /* @__PURE__ */ l("div", { className: "scheme-group", children: [
773
- /* @__PURE__ */ t("h4", { children: "Chunks (status)" }),
774
- N.map((b) => /* @__PURE__ */ t(xe, { label: b.slice(6), value: C[b], onChange: (p) => R(b, p) }, b))
1130
+ /* @__PURE__ */ c("div", { className: "scheme-group", children: [
1131
+ /* @__PURE__ */ a("h4", { children: "Chunks (status)" }),
1132
+ m.map((b) => /* @__PURE__ */ a(Ye, { label: b.slice(6), value: N[b], onChange: (C) => z(b, C) }, b))
775
1133
  ] }),
776
- /* @__PURE__ */ l("div", { className: "scheme-editor-foot", children: [
777
- /* @__PURE__ */ l("button", { type: "button", onClick: () => {
778
- J();
779
- }, disabled: F || !n, title: n ? `Apply this palette to every other ${n} document` : "This document has no type", children: [
1134
+ /* @__PURE__ */ c("div", { className: "scheme-editor-foot", children: [
1135
+ /* @__PURE__ */ c("button", { type: "button", onClick: () => {
1136
+ R();
1137
+ }, disabled: j || !n, title: n ? `Apply this palette to every other ${n} document` : "This document has no type", children: [
780
1138
  "copy to all ",
781
1139
  n || "same-type",
782
1140
  " documents"
783
1141
  ] }),
784
- A && /* @__PURE__ */ t("span", { className: "scheme-status", children: A })
1142
+ O && /* @__PURE__ */ a("span", { className: "scheme-status", children: O })
785
1143
  ] })
786
- ] }) : /* @__PURE__ */ t("p", { className: "modal-context", children: "Loading…" })
1144
+ ] }) : /* @__PURE__ */ a("p", { className: "modal-context", children: "Loading…" })
787
1145
  ] }) });
788
1146
  }
789
- function xe({ label: e, value: r, onChange: n }) {
790
- const a = Nt(r);
791
- return /* @__PURE__ */ l("label", { className: "scheme-row", children: [
792
- /* @__PURE__ */ t("input", { type: "color", value: a, onChange: (o) => n(o.target.value) }),
793
- /* @__PURE__ */ t("span", { className: "scheme-key", children: e }),
794
- /* @__PURE__ */ t("code", { className: "scheme-hex", children: a })
1147
+ function Ye({ label: e, value: t, onChange: n }) {
1148
+ const r = ln(t);
1149
+ return /* @__PURE__ */ c("label", { className: "scheme-row", children: [
1150
+ /* @__PURE__ */ a("input", { type: "color", value: r, onChange: (o) => n(o.target.value) }),
1151
+ /* @__PURE__ */ a("span", { className: "scheme-key", children: e }),
1152
+ /* @__PURE__ */ a("code", { className: "scheme-hex", children: r })
1153
+ ] });
1154
+ }
1155
+ function yt({
1156
+ id: e,
1157
+ title: t,
1158
+ targetDocumentId: n,
1159
+ documentId: r,
1160
+ onSelectChunk: o,
1161
+ onOpenDocument: s
1162
+ }) {
1163
+ const i = t || e.slice(0, 8);
1164
+ return !n || n === r ? /* @__PURE__ */ a("button", { type: "button", className: "doc-ref-target", onClick: () => o(e), children: i }) : s ? /* @__PURE__ */ c(
1165
+ "button",
1166
+ {
1167
+ type: "button",
1168
+ className: "doc-ref-target external",
1169
+ title: "In another document — opens it at this chunk",
1170
+ onClick: () => s(n, e, t),
1171
+ children: [
1172
+ i,
1173
+ " ↗"
1174
+ ]
1175
+ }
1176
+ ) : /* @__PURE__ */ c("span", { className: "doc-ref-target external", title: "In another document", children: [
1177
+ i,
1178
+ " ↗"
795
1179
  ] });
796
1180
  }
797
- const Ct = 8, _t = 20;
798
- function St(e) {
1181
+ const un = 8, hn = 20;
1182
+ function mn(e) {
799
1183
  return /embedder|embedding|vector|semantic|not configured/i.test(e);
800
1184
  }
801
- function Et({
1185
+ function fn({
802
1186
  documentId: e,
803
- selectedId: r,
1187
+ selectedId: t,
804
1188
  scope: n,
805
- browse: a,
806
- onSelectChunk: o
1189
+ browse: r,
1190
+ onSelectChunk: o,
1191
+ onOpenDocument: s
807
1192
  }) {
808
- const i = ae(), [c, s] = f(!1), [d, g] = f(!1), [m, k] = f(void 0), [h, P] = f([]), [C, L] = f([]), [F, O] = f(null), [A, M] = f([]), [I, $] = f(!1);
809
- B(() => {
810
- if (!c || !r) return;
811
- const y = r;
812
- let D = !1;
813
- return g(!0), Promise.allSettled([
814
- i.documentBacklinks(y, n, a),
815
- i.documentRelated(y, n, a, Ct),
816
- i.documentUnlinkedMentions(y, n, a, _t)
817
- ]).then(([J, V, N]) => {
818
- if (!D) {
819
- if (P(J.status === "fulfilled" ? J.value.backlinks ?? [] : []), V.status === "fulfilled")
820
- L(V.value.related ?? []), O(null);
1193
+ const i = be(), [l, f] = p(!1), [d, h] = p(!1), [w, S] = p(void 0), [g, N] = p([]), [y, j] = p([]), [B, O] = p(null), [W, q] = p([]), [I, V] = p(!1);
1194
+ H(() => {
1195
+ if (!l || !t) return;
1196
+ const _ = t;
1197
+ let R = !1;
1198
+ return h(!0), Promise.allSettled([
1199
+ i.documentBacklinks(_, n, r),
1200
+ i.documentRelated(_, n, r, un),
1201
+ i.documentUnlinkedMentions(_, n, r, hn)
1202
+ ]).then(([E, m, b]) => {
1203
+ if (!R) {
1204
+ if (N(E.status === "fulfilled" ? E.value.backlinks ?? [] : []), m.status === "fulfilled")
1205
+ j(m.value.related ?? []), O(null);
821
1206
  else {
822
- L([]);
823
- const b = V.reason instanceof Error ? V.reason.message : String(V.reason);
824
- O(St(b) ? "semantic search not configured" : b);
1207
+ j([]);
1208
+ const C = m.reason instanceof Error ? m.reason.message : String(m.reason);
1209
+ O(mn(C) ? "semantic search not configured" : C);
825
1210
  }
826
- N.status === "fulfilled" ? (M(N.value.unlinked_mentions ?? []), $(!!N.value.truncated)) : (M([]), $(!1)), k(y), g(!1);
1211
+ b.status === "fulfilled" ? (q(b.value.unlinked_mentions ?? []), V(!!b.value.truncated)) : (q([]), V(!1)), S(_), h(!1);
827
1212
  }
828
1213
  }), () => {
829
- D = !0;
1214
+ R = !0;
830
1215
  };
831
- }, [i, c, r, n, a]);
832
- const G = (y) => !!y && y !== e;
833
- return /* @__PURE__ */ l("div", { className: "doc-conn", children: [
834
- /* @__PURE__ */ l(
1216
+ }, [i, l, t, n, r]);
1217
+ const z = (_, R, E) => /* @__PURE__ */ a(
1218
+ yt,
1219
+ {
1220
+ id: _,
1221
+ title: R,
1222
+ targetDocumentId: E,
1223
+ documentId: e,
1224
+ onSelectChunk: o,
1225
+ onOpenDocument: s
1226
+ }
1227
+ );
1228
+ return /* @__PURE__ */ c("div", { className: "doc-conn", children: [
1229
+ /* @__PURE__ */ c(
835
1230
  "button",
836
1231
  {
837
1232
  type: "button",
838
1233
  className: "doc-conn-toggle",
839
- onClick: () => s((y) => !y),
1234
+ onClick: () => f((_) => !_),
840
1235
  children: [
841
- c ? "▼" : "▶",
1236
+ l ? "▼" : "▶",
842
1237
  " Connections"
843
1238
  ]
844
1239
  }
845
1240
  ),
846
- c && /* @__PURE__ */ t("div", { className: "doc-conn-body", children: r ? !!(c && r && !d && m === r) ? /* @__PURE__ */ l(Y, { children: [
847
- /* @__PURE__ */ l("div", { className: "doc-conn-group", children: [
848
- /* @__PURE__ */ t("h5", { children: "Backlinks" }),
849
- h.length === 0 ? /* @__PURE__ */ t("p", { className: "doc-conn-empty", children: "none" }) : /* @__PURE__ */ t("ul", { className: "doc-conn-list", children: h.map((y, D) => /* @__PURE__ */ l("li", { className: "doc-conn-row", children: [
850
- /* @__PURE__ */ t(
851
- ge,
852
- {
853
- id: y.from_id,
854
- title: y.from_title,
855
- crossDoc: G(y.from_document_id),
856
- onSelect: o
857
- }
858
- ),
859
- /* @__PURE__ */ t("span", { className: "doc-ref-kind", children: y.kind }),
860
- y.auto && /* @__PURE__ */ t("span", { className: "doc-conn-auto", title: "Auto-linked from a [[wikilink]]", children: "auto" })
861
- ] }, `${y.from_id}-${y.kind}-${D}`)) })
1241
+ l && /* @__PURE__ */ a("div", { className: "doc-conn-body", children: t ? !!(l && t && !d && w === t) ? /* @__PURE__ */ c(Q, { children: [
1242
+ /* @__PURE__ */ c("div", { className: "doc-conn-group", children: [
1243
+ /* @__PURE__ */ a("h5", { children: "Backlinks" }),
1244
+ g.length === 0 ? /* @__PURE__ */ a("p", { className: "doc-conn-empty", children: "none" }) : /* @__PURE__ */ a("ul", { className: "doc-conn-list", children: g.map((_, R) => /* @__PURE__ */ c("li", { className: "doc-conn-row", children: [
1245
+ z(_.from_id, _.from_title, _.from_document_id),
1246
+ /* @__PURE__ */ a("span", { className: "doc-ref-kind", children: _.kind }),
1247
+ _.auto && /* @__PURE__ */ a("span", { className: "doc-conn-auto", title: "Auto-linked from a [[wikilink]]", children: "auto" })
1248
+ ] }, `${_.from_id}-${_.kind}-${R}`)) })
862
1249
  ] }),
863
- /* @__PURE__ */ l("div", { className: "doc-conn-group", children: [
864
- /* @__PURE__ */ t("h5", { children: "Related" }),
865
- F ? /* @__PURE__ */ t("p", { className: "doc-conn-empty", children: F }) : C.length === 0 ? /* @__PURE__ */ t("p", { className: "doc-conn-empty", children: "none" }) : /* @__PURE__ */ t("ul", { className: "doc-conn-list", children: C.map((y, D) => /* @__PURE__ */ l("li", { className: "doc-conn-row", children: [
866
- /* @__PURE__ */ t(
867
- ge,
868
- {
869
- id: y.chunk_id,
870
- title: y.title,
871
- crossDoc: G(y.document_id),
872
- onSelect: o
873
- }
874
- ),
875
- /* @__PURE__ */ t("span", { className: "doc-conn-score", title: "similarity score", children: y.score.toFixed(2) })
876
- ] }, `${y.chunk_id}-${D}`)) })
1250
+ /* @__PURE__ */ c("div", { className: "doc-conn-group", children: [
1251
+ /* @__PURE__ */ a("h5", { children: "Related" }),
1252
+ B ? /* @__PURE__ */ a("p", { className: "doc-conn-empty", children: B }) : y.length === 0 ? /* @__PURE__ */ a("p", { className: "doc-conn-empty", children: "none" }) : /* @__PURE__ */ a("ul", { className: "doc-conn-list", children: y.map((_, R) => /* @__PURE__ */ c("li", { className: "doc-conn-row", children: [
1253
+ z(_.chunk_id, _.title, _.document_id),
1254
+ /* @__PURE__ */ a("span", { className: "doc-conn-score", title: "similarity score", children: _.score.toFixed(2) })
1255
+ ] }, `${_.chunk_id}-${R}`)) })
877
1256
  ] }),
878
- /* @__PURE__ */ l("div", { className: "doc-conn-group", children: [
879
- /* @__PURE__ */ t("h5", { children: "Unlinked mentions" }),
880
- A.length === 0 ? /* @__PURE__ */ t("p", { className: "doc-conn-empty", children: "none" }) : /* @__PURE__ */ l("ul", { className: "doc-conn-list", children: [
881
- A.map((y, D) => /* @__PURE__ */ t("li", { className: "doc-conn-row", children: /* @__PURE__ */ t(
882
- ge,
883
- {
884
- id: y.chunk_id,
885
- title: y.title,
886
- crossDoc: G(y.document_id),
887
- onSelect: o
888
- }
889
- ) }, `${y.chunk_id}-${D}`)),
890
- I && /* @__PURE__ */ t("li", { className: "doc-conn-more", "aria-hidden": !0, children: "(more…)" })
1257
+ /* @__PURE__ */ c("div", { className: "doc-conn-group", children: [
1258
+ /* @__PURE__ */ a("h5", { children: "Unlinked mentions" }),
1259
+ W.length === 0 ? /* @__PURE__ */ a("p", { className: "doc-conn-empty", children: "none" }) : /* @__PURE__ */ c("ul", { className: "doc-conn-list", children: [
1260
+ W.map((_, R) => /* @__PURE__ */ a("li", { className: "doc-conn-row", children: z(_.chunk_id, _.title, _.document_id) }, `${_.chunk_id}-${R}`)),
1261
+ I && /* @__PURE__ */ a("li", { className: "doc-conn-more", "aria-hidden": !0, children: "(more…)" })
891
1262
  ] })
892
1263
  ] })
893
- ] }) : /* @__PURE__ */ t("p", { className: "doc-conn-empty", children: "loading…" }) : /* @__PURE__ */ t("p", { className: "doc-conn-empty", children: "Select a chunk." }) })
1264
+ ] }) : /* @__PURE__ */ a("p", { className: "doc-conn-empty", children: "loading…" }) : /* @__PURE__ */ a("p", { className: "doc-conn-empty", children: "Select a chunk." }) })
894
1265
  ] });
895
1266
  }
896
- function ge({
897
- id: e,
898
- title: r,
899
- crossDoc: n,
900
- onSelect: a
901
- }) {
902
- const o = r || e.slice(0, 8);
903
- return n ? /* @__PURE__ */ l("span", { className: "doc-ref-target external", title: "In another document", children: [
904
- o,
905
- " ↗"
906
- ] }) : /* @__PURE__ */ t("button", { type: "button", className: "doc-ref-target", onClick: () => a(e), children: o });
907
- }
908
- const ye = 24;
909
- function xt({
1267
+ const Ae = 24;
1268
+ function pn({
910
1269
  edges: e,
911
- documentId: r,
1270
+ documentId: t,
912
1271
  selectedId: n,
913
- onSelectChunk: a
1272
+ onSelectChunk: r,
1273
+ onOpenDocument: o
914
1274
  }) {
915
- const [o, i] = f(!1), [c, s] = f(!1);
1275
+ const [s, i] = p(!1), [l, f] = p(!1);
916
1276
  if (e.length === 0) return null;
917
- const d = n ? e.filter((k) => k.from_id === n || k.to_id === n) : [], g = c ? e : e.slice(0, ye), m = Rt(g);
918
- return /* @__PURE__ */ l("div", { className: "doc-refs", children: [
919
- n && /* @__PURE__ */ l("div", { className: "doc-refs-list-wrap", children: [
920
- /* @__PURE__ */ t("h4", { children: "References" }),
921
- d.length === 0 ? /* @__PURE__ */ t("p", { className: "doc-refs-empty", children: "This chunk has no links." }) : /* @__PURE__ */ t("ul", { className: "doc-refs-list", children: d.map((k, h) => /* @__PURE__ */ t(
922
- Dt,
1277
+ const d = n ? e.filter((g) => g.from_id === n || g.to_id === n) : [], h = l ? e : e.slice(0, Ae), w = yn(h), S = (g) => {
1278
+ const N = bn(h, g);
1279
+ N && (!N.documentId || N.documentId === t ? r(N.id) : o?.(N.documentId, N.id, N.title));
1280
+ };
1281
+ return /* @__PURE__ */ c("div", { className: "doc-refs", children: [
1282
+ n && /* @__PURE__ */ c("div", { className: "doc-refs-list-wrap", children: [
1283
+ /* @__PURE__ */ a("h4", { children: "References" }),
1284
+ d.length === 0 ? /* @__PURE__ */ a("p", { className: "doc-refs-empty", children: "This chunk has no links." }) : /* @__PURE__ */ a("ul", { className: "doc-refs-list", children: d.map((g, N) => /* @__PURE__ */ a(
1285
+ gn,
923
1286
  {
924
- edge: k,
1287
+ edge: g,
925
1288
  selectedId: n,
926
- documentId: r,
927
- onSelectChunk: a
1289
+ documentId: t,
1290
+ onSelectChunk: r,
1291
+ onOpenDocument: o
928
1292
  },
929
- `${k.from_id}-${k.to_id}-${k.kind}-${h}`
1293
+ `${g.from_id}-${g.to_id}-${g.kind}-${N}`
930
1294
  )) })
931
1295
  ] }),
932
- /* @__PURE__ */ l("div", { className: "doc-graph", children: [
933
- /* @__PURE__ */ l("button", { type: "button", className: "doc-graph-toggle", onClick: () => i((k) => !k), children: [
934
- o ? "▼" : "▶",
1296
+ /* @__PURE__ */ c("div", { className: "doc-graph", children: [
1297
+ /* @__PURE__ */ c("button", { type: "button", className: "doc-graph-toggle", onClick: () => i((g) => !g), children: [
1298
+ s ? "▼" : "▶",
935
1299
  " relationship graph (",
936
1300
  e.length,
937
1301
  ")"
938
1302
  ] }),
939
- o && /* @__PURE__ */ l(Y, { children: [
940
- /* @__PURE__ */ t(ue, { code: m }),
941
- e.length > ye && /* @__PURE__ */ t("button", { type: "button", className: "doc-graph-more", onClick: () => s((k) => !k), children: c ? `show top ${ye}` : `show all ${e.length}` })
1303
+ s && /* @__PURE__ */ c(Q, { children: [
1304
+ /* @__PURE__ */ a(Te, { code: w, onNodeClick: S }),
1305
+ e.length > Ae && /* @__PURE__ */ a("button", { type: "button", className: "doc-graph-more", onClick: () => f((g) => !g), children: l ? `show top ${Ae}` : `show all ${e.length}` })
942
1306
  ] })
943
1307
  ] })
944
1308
  ] });
945
1309
  }
946
- function Dt({
1310
+ function gn({
947
1311
  edge: e,
948
- selectedId: r,
1312
+ selectedId: t,
949
1313
  documentId: n,
950
- onSelectChunk: a
1314
+ onSelectChunk: r,
1315
+ onOpenDocument: o
951
1316
  }) {
952
- const o = e.from_id === r, i = o ? e.to_id : e.from_id, c = (o ? e.to_title : e.from_title) || i.slice(0, 8), s = o ? e.to_document_id : e.from_document_id, d = !s || s === n;
953
- return /* @__PURE__ */ l("li", { className: "doc-ref", children: [
954
- /* @__PURE__ */ t("span", { className: "doc-ref-kind", children: e.kind }),
955
- /* @__PURE__ */ t("span", { className: "doc-ref-arrow", "aria-hidden": !0, children: o ? "→" : "←" }),
956
- d ? /* @__PURE__ */ t("button", { type: "button", className: "doc-ref-target", onClick: () => a(i), children: c }) : /* @__PURE__ */ l("span", { className: "doc-ref-target external", title: "In another document", children: [
957
- c,
958
- " ↗"
959
- ] })
1317
+ const s = e.from_id === t, i = s ? e.to_id : e.from_id, l = s ? e.to_title : e.from_title, f = s ? e.to_document_id : e.from_document_id;
1318
+ return /* @__PURE__ */ c("li", { className: "doc-ref", children: [
1319
+ /* @__PURE__ */ a("span", { className: "doc-ref-kind", children: e.kind }),
1320
+ /* @__PURE__ */ a("span", { className: "doc-ref-arrow", "aria-hidden": !0, children: s ? "→" : "←" }),
1321
+ /* @__PURE__ */ a(
1322
+ yt,
1323
+ {
1324
+ id: i,
1325
+ title: l,
1326
+ targetDocumentId: f,
1327
+ documentId: n,
1328
+ onSelectChunk: r,
1329
+ onOpenDocument: o
1330
+ }
1331
+ )
960
1332
  ] });
961
1333
  }
962
- function Rt(e) {
963
- const r = ["graph LR"];
1334
+ function yn(e) {
1335
+ const t = ["graph LR"];
964
1336
  for (const n of e) {
965
- const a = `${De(n.from_id)}["${Re(n.from_title, n.from_id)}"]`, o = `${De(n.to_id)}["${Re(n.to_title, n.to_id)}"]`, i = (n.kind || "link").replace(/[|"]/g, " ");
966
- r.push(` ${a} -->|${i}| ${o}`);
1337
+ const r = `${De(n.from_id)}["${Ke(n.from_title, n.from_id)}"]`, o = `${De(n.to_id)}["${Ke(n.to_title, n.to_id)}"]`, s = (n.kind || "link").replace(/[|"]/g, " ");
1338
+ t.push(` ${r} -->|${s}| ${o}`);
967
1339
  }
968
- return r.join(`
1340
+ return t.join(`
969
1341
  `);
970
1342
  }
1343
+ function bn(e, t) {
1344
+ for (const n of e) {
1345
+ if (De(n.from_id) === t)
1346
+ return { id: n.from_id, documentId: n.from_document_id, title: n.from_title };
1347
+ if (De(n.to_id) === t)
1348
+ return { id: n.to_id, documentId: n.to_document_id, title: n.to_title };
1349
+ }
1350
+ }
971
1351
  function De(e) {
972
1352
  return "n" + e.replace(/[^a-zA-Z0-9]/g, "");
973
1353
  }
974
- function Re(e, r) {
975
- const a = (e ?? "").replace(/["[\]{}|<>]/g, " ").replace(/\s+/g, " ").trim() || r.slice(0, 6);
976
- return a.length > 30 ? a.slice(0, 29) + "…" : a;
1354
+ function Ke(e, t) {
1355
+ const r = (e ?? "").replace(/["[\]{}|<>]/g, " ").replace(/\s+/g, " ").trim() || t.slice(0, 6);
1356
+ return r.length > 30 ? r.slice(0, 29) + "…" : r;
1357
+ }
1358
+ function vn({ documentId: e, scope: t, detail: n }) {
1359
+ return /* @__PURE__ */ c("div", { className: "doc-unavailable", role: "alert", children: [
1360
+ /* @__PURE__ */ a("p", { className: "doc-unavailable-lead", children: "This document can’t be opened." }),
1361
+ /* @__PURE__ */ c("p", { children: [
1362
+ "It may have been deleted, live in a scope other than ",
1363
+ /* @__PURE__ */ a("code", { children: t }),
1364
+ ", or not be yours to read."
1365
+ ] }),
1366
+ /* @__PURE__ */ c("p", { className: "doc-unavailable-detail", children: [
1367
+ /* @__PURE__ */ a("code", { children: e }),
1368
+ n && /* @__PURE__ */ c(Q, { children: [
1369
+ " — ",
1370
+ n
1371
+ ] })
1372
+ ] })
1373
+ ] });
977
1374
  }
978
- function Mt(e) {
979
- const r = typeof e == "number" ? e / 1e6 : Date.parse(String(e));
980
- return !Number.isFinite(r) || r <= 0 ? String(e ?? "") : new Date(r).toLocaleString();
1375
+ function kn(e) {
1376
+ const t = typeof e == "number" ? e / 1e6 : Date.parse(String(e));
1377
+ return !Number.isFinite(t) || t <= 0 ? String(e ?? "") : new Date(t).toLocaleString();
981
1378
  }
982
- function $t({
1379
+ function Nn({
983
1380
  chunkId: e,
984
- chunkTitle: r,
1381
+ chunkTitle: t,
985
1382
  scope: n,
986
- browse: a,
1383
+ browse: r,
987
1384
  onClose: o
988
1385
  }) {
989
- const i = ae(), [c, s] = f([]), [d, g] = f(!0), [m, k] = f(null), [h, P] = f("none"), [C, L] = f(null), [F, O] = f(""), [A, M] = f(!1), [I, $] = f(null), [G, R] = f(null), [y, D] = f("");
990
- B(() => {
991
- let N = !1;
992
- return g(!0), k(null), i.documentHistory(e, n, a).then((b) => {
993
- if (N) return;
994
- const p = b.revisions ?? [];
995
- if (s(p), p.length >= 2) {
996
- const w = p.map((S) => S.revision);
997
- $(Math.min(...w)), R(Math.max(...w));
1386
+ const s = be(), [i, l] = p([]), [f, d] = p(!0), [h, w] = p(null), [S, g] = p("none"), [N, y] = p(null), [j, B] = p(""), [O, W] = p(!1), [q, I] = p(null), [V, z] = p(null), [Z, _] = p("");
1387
+ H(() => {
1388
+ let m = !1;
1389
+ return d(!0), w(null), s.documentHistory(e, n, r).then((b) => {
1390
+ if (m) return;
1391
+ const C = b.revisions ?? [];
1392
+ if (l(C), C.length >= 2) {
1393
+ const x = C.map((U) => U.revision);
1394
+ I(Math.min(...x)), z(Math.max(...x));
998
1395
  }
999
- }).catch((b) => !N && k(b instanceof Error ? b.message : String(b))).finally(() => !N && g(!1)), () => {
1000
- N = !0;
1396
+ }).catch((b) => !m && w(b instanceof Error ? b.message : String(b))).finally(() => !m && d(!1)), () => {
1397
+ m = !0;
1001
1398
  };
1002
- }, [i, e, n, a]);
1003
- const J = async (N) => {
1004
- k(null), M(!0), L(N), P("version");
1399
+ }, [s, e, n, r]);
1400
+ const R = async (m) => {
1401
+ w(null), W(!0), y(m), g("version");
1005
1402
  try {
1006
- const b = await i.documentGetVersion(e, N, n, a);
1007
- O(b.body ?? "");
1403
+ const b = await s.documentGetVersion(e, m, n, r);
1404
+ B(b.body ?? "");
1008
1405
  } catch (b) {
1009
- k(b instanceof Error ? b.message : String(b));
1406
+ w(b instanceof Error ? b.message : String(b));
1010
1407
  } finally {
1011
- M(!1);
1408
+ W(!1);
1012
1409
  }
1013
- }, V = async () => {
1014
- if (!(I === null || G === null)) {
1015
- k(null), M(!0), P("diff");
1410
+ }, E = async () => {
1411
+ if (!(q === null || V === null)) {
1412
+ w(null), W(!0), g("diff");
1016
1413
  try {
1017
- const N = await i.documentDiff(e, I, G, n, a);
1018
- D(N.diff ?? "");
1019
- } catch (N) {
1020
- k(N instanceof Error ? N.message : String(N));
1414
+ const m = await s.documentDiff(e, q, V, n, r);
1415
+ _(m.diff ?? "");
1416
+ } catch (m) {
1417
+ w(m instanceof Error ? m.message : String(m));
1021
1418
  } finally {
1022
- M(!1);
1419
+ W(!1);
1023
1420
  }
1024
1421
  }
1025
1422
  };
1026
- return /* @__PURE__ */ t("div", { className: "modal-overlay", onClick: o, children: /* @__PURE__ */ l("div", { className: "modal history-modal", onClick: (N) => N.stopPropagation(), children: [
1027
- /* @__PURE__ */ l("div", { className: "modal-header sticky-top", children: [
1028
- /* @__PURE__ */ l("h3", { children: [
1423
+ return /* @__PURE__ */ a("div", { className: "modal-overlay", onClick: o, children: /* @__PURE__ */ c("div", { className: "modal history-modal", onClick: (m) => m.stopPropagation(), children: [
1424
+ /* @__PURE__ */ c("div", { className: "modal-header sticky-top", children: [
1425
+ /* @__PURE__ */ c("h3", { children: [
1029
1426
  "History",
1030
- r ? ` — ${r}` : ""
1427
+ t ? ` — ${t}` : ""
1031
1428
  ] }),
1032
- /* @__PURE__ */ t("div", { className: "modal-buttons modal-buttons-top", children: /* @__PURE__ */ t("button", { type: "button", onClick: o, children: "close" }) })
1429
+ /* @__PURE__ */ a("div", { className: "modal-buttons modal-buttons-top", children: /* @__PURE__ */ a("button", { type: "button", onClick: o, children: "close" }) })
1033
1430
  ] }),
1034
- m && /* @__PURE__ */ t("div", { className: "modal-err", children: m }),
1035
- d ? /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "loading…" }) : c.length === 0 ? /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "No history recorded for this chunk." }) : /* @__PURE__ */ l(Y, { children: [
1036
- /* @__PURE__ */ t("div", { className: "doc-hist-revs", children: c.map((N) => /* @__PURE__ */ l(
1431
+ h && /* @__PURE__ */ a("div", { className: "modal-err", children: h }),
1432
+ f ? /* @__PURE__ */ a("p", { className: "doc-empty-body", children: "loading…" }) : i.length === 0 ? /* @__PURE__ */ a("p", { className: "doc-empty-body", children: "No history recorded for this chunk." }) : /* @__PURE__ */ c(Q, { children: [
1433
+ /* @__PURE__ */ a("div", { className: "doc-hist-revs", children: i.map((m) => /* @__PURE__ */ c(
1037
1434
  "button",
1038
1435
  {
1039
1436
  type: "button",
1040
- className: "doc-hist-rev" + (h === "version" && C === N.revision ? " active" : ""),
1437
+ className: "doc-hist-rev" + (S === "version" && N === m.revision ? " active" : ""),
1041
1438
  onClick: () => {
1042
- J(N.revision);
1439
+ R(m.revision);
1043
1440
  },
1044
1441
  children: [
1045
- /* @__PURE__ */ l("span", { className: "doc-hist-rev-num", children: [
1442
+ /* @__PURE__ */ c("span", { className: "doc-hist-rev-num", children: [
1046
1443
  "rev ",
1047
- N.revision
1444
+ m.revision
1048
1445
  ] }),
1049
- /* @__PURE__ */ t("span", { className: "doc-hist-rev-time", children: Mt(N.created_at) }),
1050
- /* @__PURE__ */ t("span", { className: "doc-hist-rev-actor", children: N.actor || "unknown" })
1446
+ /* @__PURE__ */ a("span", { className: "doc-hist-rev-time", children: kn(m.created_at) }),
1447
+ /* @__PURE__ */ a("span", { className: "doc-hist-rev-actor", children: m.actor || "unknown" })
1051
1448
  ]
1052
1449
  },
1053
- N.revision
1450
+ m.revision
1054
1451
  )) }),
1055
- c.length >= 2 && /* @__PURE__ */ l("div", { className: "doc-hist-diffbar", children: [
1056
- /* @__PURE__ */ t("span", { children: "Compare" }),
1057
- /* @__PURE__ */ t(
1452
+ i.length >= 2 && /* @__PURE__ */ c("div", { className: "doc-hist-diffbar", children: [
1453
+ /* @__PURE__ */ a("span", { children: "Compare" }),
1454
+ /* @__PURE__ */ a(
1058
1455
  "select",
1059
1456
  {
1060
- value: I ?? "",
1061
- onChange: (N) => $(N.target.value === "" ? null : Number(N.target.value)),
1457
+ value: q ?? "",
1458
+ onChange: (m) => I(m.target.value === "" ? null : Number(m.target.value)),
1062
1459
  "aria-label": "diff from revision",
1063
- children: c.map((N) => /* @__PURE__ */ l("option", { value: N.revision, children: [
1460
+ children: i.map((m) => /* @__PURE__ */ c("option", { value: m.revision, children: [
1064
1461
  "rev ",
1065
- N.revision
1066
- ] }, N.revision))
1462
+ m.revision
1463
+ ] }, m.revision))
1067
1464
  }
1068
1465
  ),
1069
- /* @__PURE__ */ t("span", { "aria-hidden": !0, children: "→" }),
1070
- /* @__PURE__ */ t(
1466
+ /* @__PURE__ */ a("span", { "aria-hidden": !0, children: "→" }),
1467
+ /* @__PURE__ */ a(
1071
1468
  "select",
1072
1469
  {
1073
- value: G ?? "",
1074
- onChange: (N) => R(N.target.value === "" ? null : Number(N.target.value)),
1470
+ value: V ?? "",
1471
+ onChange: (m) => z(m.target.value === "" ? null : Number(m.target.value)),
1075
1472
  "aria-label": "diff to revision",
1076
- children: c.map((N) => /* @__PURE__ */ l("option", { value: N.revision, children: [
1473
+ children: i.map((m) => /* @__PURE__ */ c("option", { value: m.revision, children: [
1077
1474
  "rev ",
1078
- N.revision
1079
- ] }, N.revision))
1475
+ m.revision
1476
+ ] }, m.revision))
1080
1477
  }
1081
1478
  ),
1082
- /* @__PURE__ */ t(
1479
+ /* @__PURE__ */ a(
1083
1480
  "button",
1084
1481
  {
1085
1482
  type: "button",
1086
1483
  onClick: () => {
1087
- V();
1484
+ E();
1088
1485
  },
1089
- disabled: A || I === null || G === null,
1486
+ disabled: O || q === null || V === null,
1090
1487
  children: "diff"
1091
1488
  }
1092
1489
  )
1093
1490
  ] }),
1094
- /* @__PURE__ */ t("div", { className: "doc-hist-output", children: A ? /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "loading…" }) : h === "diff" ? /* @__PURE__ */ t(Lt, { text: y }) : h === "version" ? /* @__PURE__ */ t("pre", { className: "md-pre doc-hist-version", children: /* @__PURE__ */ t("code", { children: F || "(empty)" }) }) : /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "Select a revision to view it, or compare two." }) })
1491
+ /* @__PURE__ */ a("div", { className: "doc-hist-output", children: O ? /* @__PURE__ */ a("p", { className: "doc-empty-body", children: "loading…" }) : S === "diff" ? /* @__PURE__ */ a(wn, { text: Z }) : S === "version" ? /* @__PURE__ */ a("pre", { className: "md-pre doc-hist-version", children: /* @__PURE__ */ a("code", { children: j || "(empty)" }) }) : /* @__PURE__ */ a("p", { className: "doc-empty-body", children: "Select a revision to view it, or compare two." }) })
1095
1492
  ] })
1096
1493
  ] }) });
1097
1494
  }
1098
- function Lt({ text: e }) {
1099
- if (!e.trim()) return /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "(no differences)" });
1100
- const r = e.split(`
1495
+ function wn({ text: e }) {
1496
+ if (!e.trim()) return /* @__PURE__ */ a("p", { className: "doc-empty-body", children: "(no differences)" });
1497
+ const t = e.split(`
1101
1498
  `);
1102
- return /* @__PURE__ */ t("pre", { className: "md-pre doc-hist-diff", children: r.map((n, a) => {
1499
+ return /* @__PURE__ */ a("pre", { className: "md-pre doc-hist-diff", children: t.map((n, r) => {
1103
1500
  const o = n.startsWith("+") && !n.startsWith("+++") ? "diff-add" : n.startsWith("-") && !n.startsWith("---") ? "diff-del" : n.startsWith("@@") ? "diff-hunk" : "";
1104
- return /* @__PURE__ */ l("span", { className: o, children: [
1501
+ return /* @__PURE__ */ c("span", { className: o, children: [
1105
1502
  n,
1106
1503
  `
1107
1504
  `
1108
- ] }, a);
1505
+ ] }, r);
1109
1506
  }) });
1110
1507
  }
1111
- function Me({ source: e }) {
1112
- return /* @__PURE__ */ t("div", { className: "md", children: /* @__PURE__ */ t(ot, { remarkPlugins: [ct], components: Tt, children: e }) });
1508
+ function et({ source: e }) {
1509
+ return /* @__PURE__ */ a("div", { className: "md", children: /* @__PURE__ */ a(Pt, { remarkPlugins: [It], components: Cn, children: e }) });
1113
1510
  }
1114
- const Tt = {
1511
+ const Cn = {
1115
1512
  // react-markdown already sanitized the href; add target/rel for external links.
1116
- a({ href: e, children: r }) {
1117
- const n = e ?? "", a = /^https?:\/\//i.test(n);
1118
- return /* @__PURE__ */ t("a", { href: n, target: a ? "_blank" : void 0, rel: a ? "noopener noreferrer" : void 0, children: r });
1513
+ a({ href: e, children: t }) {
1514
+ const n = e ?? "", r = /^https?:\/\//i.test(n);
1515
+ return /* @__PURE__ */ a("a", { href: n, target: r ? "_blank" : void 0, rel: r ? "noopener noreferrer" : void 0, children: t });
1119
1516
  },
1120
1517
  // Let the code renderer own the block wrapper so a mermaid fence isn't wrapped
1121
1518
  // in a <pre> (and a normal code block gets exactly one <pre>).
1122
1519
  pre({ children: e }) {
1123
- return /* @__PURE__ */ t(Y, { children: e });
1520
+ return /* @__PURE__ */ a(Q, { children: e });
1124
1521
  },
1125
- code({ className: e, children: r }) {
1126
- const n = /language-(\w+)/.exec(e ?? "")?.[1], a = String(r ?? "");
1127
- return n === "mermaid" ? /* @__PURE__ */ t(ue, { code: a.replace(/\n$/, "") }) : n || a.includes(`
1128
- `) ? /* @__PURE__ */ t("pre", { className: "md-pre", children: /* @__PURE__ */ t("code", { className: e, children: r }) }) : /* @__PURE__ */ t("code", { children: r });
1522
+ code({ className: e, children: t }) {
1523
+ const n = /language-(\w+)/.exec(e ?? "")?.[1], r = String(t ?? "");
1524
+ return n === "mermaid" ? /* @__PURE__ */ a(Te, { code: r.replace(/\n$/, "") }) : n || r.includes(`
1525
+ `) ? /* @__PURE__ */ a("pre", { className: "md-pre", children: /* @__PURE__ */ a("code", { className: e, children: t }) }) : /* @__PURE__ */ a("code", { children: t });
1129
1526
  }
1130
1527
  };
1131
- function Pt(e) {
1132
- const r = e.fields ?? {};
1133
- return typeof r.alt == "string" && r.alt.trim() !== "" ? r.alt : e.title || "image";
1528
+ function _n(e) {
1529
+ const t = e.fields ?? {};
1530
+ return typeof t.alt == "string" && t.alt.trim() !== "" ? t.alt : e.title || "image";
1134
1531
  }
1135
- function Fe({
1532
+ function bt({
1136
1533
  documentId: e,
1137
- scope: r,
1534
+ scope: t,
1138
1535
  titleHint: n,
1139
- browse: a,
1536
+ browse: r,
1140
1537
  principal: o,
1141
- renderAssistant: i
1538
+ renderAssistant: s,
1539
+ initialChunkId: i,
1540
+ onOpenDocument: l,
1541
+ onTitle: f
1142
1542
  }) {
1143
- const c = ae(), s = q(
1144
- () => a && (a.scopeId || a.tenant) ? { scopeId: a.scopeId, tenant: a.tenant } : void 0,
1145
- [a?.scopeId, a?.tenant]
1146
- ), [d, g] = f([]), [m, k] = f(void 0), [h, P] = f(null), [C, L] = f("chunks"), [F, O] = f(null), [A, M] = f(null), [I, $] = f(null), G = ne(null), [R, y] = f(null), [D, J] = f(!1), [V, N] = f(!1), [b, p] = f(null), [w, S] = f(!1), [T, ee] = f(0), [oe, ce] = f(!1), [Z, re] = f(null), [x, H] = f(!1), [W, Q] = f([]), z = j(() => ee((u) => u + 1), []), he = q(() => gt(d), [d]), ie = q(() => d.find((v) => !v.parent_id)?.title || n || "document", [d, n]), te = q(
1147
- () => !!h && !h.parent_id,
1148
- [h]
1149
- ), X = q(
1150
- () => Z?.root_chunk_id ?? d.find((u) => !u.parent_id)?.id,
1151
- [Z, d]
1152
- ), We = q(
1153
- () => [...new Set(d.map((u) => u.status).filter((u) => !!u))],
1154
- [d]
1155
- ), se = !!Z?.color_enabled, Ve = q(() => {
1543
+ const d = be(), h = X(
1544
+ () => r && (r.scopeId || r.tenant) ? { scopeId: r.scopeId, tenant: r.tenant } : void 0,
1545
+ [r?.scopeId, r?.tenant]
1546
+ ), [w, S] = p([]), [g, N] = p(void 0), [y, j] = p(null), [B, O] = p("chunks"), [W, q] = p(null), [I, V] = p(null), [z, Z] = p(null), _ = te(null), [R, E] = p(null), [m, b] = p(!1), [C, x] = p(!1), [U, M] = p(null), [ne, de] = p(!1), [we, ve] = p(void 0), [me, Ce] = p(null), [ue, Le] = p(0), [_e, D] = p(!1), [Y, ce] = p(null), [fe, Se] = p(!1), [pe, oe] = p([]), F = P(() => Le((u) => u + 1), []), ke = te(i);
1547
+ ke.current = i;
1548
+ const Ee = te(f);
1549
+ Ee.current = f;
1550
+ const Ne = X(() => nn(w), [w]), se = X(() => w.find((v) => !v.parent_id)?.title || n || "document", [w, n]), re = X(
1551
+ () => !!y && !y.parent_id,
1552
+ [y]
1553
+ ), K = X(
1554
+ () => Y?.root_chunk_id ?? w.find((u) => !u.parent_id)?.id,
1555
+ [Y, w]
1556
+ ), ee = X(
1557
+ () => [...new Set(w.map((u) => u.status).filter((u) => !!u))],
1558
+ [w]
1559
+ ), ge = !!Y?.color_enabled, Me = X(() => {
1156
1560
  const u = /* @__PURE__ */ new Set();
1157
- for (const v of W)
1561
+ for (const v of pe)
1158
1562
  u.add(v.from_id), u.add(v.to_id);
1159
1563
  return u;
1160
- }, [W]), ze = q(
1161
- () => se ? Ne(Ie(Z?.type, Z?.status, ke(Z?.color_scheme))) : void 0,
1162
- [se, Z?.type, Z?.status, Z?.color_scheme]
1564
+ }, [pe]), Re = X(
1565
+ () => ge ? He(ft(Y?.type, Y?.status, Ge(Y?.color_scheme))) : void 0,
1566
+ [ge, Y?.type, Y?.status, Y?.color_scheme]
1163
1567
  );
1164
- B(() => {
1568
+ H(() => {
1165
1569
  let u = !1;
1166
- return S(!0), p(null), c.documentQueryChunks(e, r, s).then((v) => {
1570
+ return de(!0), M(null), Ce(null), d.documentQueryChunks(e, t, h).then((v) => {
1167
1571
  if (u) return;
1168
- const _ = v.chunks ?? [];
1169
- g(_), k((E) => E ?? _.find((U) => !U.parent_id)?.id);
1170
- }).catch((v) => !u && p(v instanceof Error ? v.message : String(v))).finally(() => !u && S(!1)), () => {
1572
+ const T = v.chunks ?? [];
1573
+ S(T), ve(`${t}:${e}`), N((A) => A ?? Jt(T, ke.current));
1574
+ }).catch((v) => {
1575
+ u || (S([]), Ce(v instanceof Error ? v.message : String(v)));
1576
+ }).finally(() => !u && de(!1)), () => {
1171
1577
  u = !0;
1172
1578
  };
1173
- }, [c, e, r, T, s]), B(() => {
1579
+ }, [d, e, t, ue, h]);
1580
+ const Pe = !ne && (me !== null || we === `${t}:${e}` && w.length === 0), k = X(
1581
+ () => w.find((u) => !u.parent_id && u.document_id === e)?.title,
1582
+ [w, e]
1583
+ );
1584
+ H(() => {
1585
+ k && Ee.current?.(e, k);
1586
+ }, [e, k]), H(() => {
1174
1587
  let u = !1;
1175
- return c.documentGet(e, r, s).then((v) => !u && re(v)).catch(() => !u && re(null)), () => {
1588
+ return d.documentGet(e, t, h).then((v) => !u && ce(v)).catch(() => !u && ce(null)), () => {
1176
1589
  u = !0;
1177
1590
  };
1178
- }, [c, e, r, T, s]), B(() => {
1591
+ }, [d, e, t, ue, h]), H(() => {
1179
1592
  let u = !1;
1180
- return c.documentGetEdges(e, r, s).then((v) => !u && Q(v.edges ?? [])).catch(() => !u && Q([])), () => {
1593
+ return d.documentGetEdges(e, t, h).then((v) => !u && oe(v.edges ?? [])).catch(() => !u && oe([])), () => {
1181
1594
  u = !0;
1182
1595
  };
1183
- }, [c, e, r, T, s]), B(() => {
1184
- k(void 0), P(null), O(null), L("chunks"), re(null), Q([]);
1185
- }, [e, r]), B(() => {
1186
- if (!m) {
1187
- P(null);
1596
+ }, [d, e, t, ue, h]), H(() => {
1597
+ N(void 0), j(null), q(null), O("chunks"), ce(null), oe([]);
1598
+ }, [e, t]), H(() => {
1599
+ if (!g) {
1600
+ j(null);
1188
1601
  return;
1189
1602
  }
1190
1603
  let u = !1;
1191
- return c.documentGetChunk(m, r, s).then((v) => !u && P(v)).catch((v) => !u && p(v instanceof Error ? v.message : String(v))), () => {
1604
+ return d.documentGetChunk(g, t, h).then((v) => !u && j(v)).catch((v) => !u && M(v instanceof Error ? v.message : String(v))), () => {
1192
1605
  u = !0;
1193
1606
  };
1194
- }, [c, m, r, T, s]), B(() => {
1195
- const u = h?.type === "image" || !!h?.asset;
1196
- if (!h || !u || !c.documentAssetObjectUrl) {
1197
- M(null), $(null);
1607
+ }, [d, g, t, ue, h]), H(() => {
1608
+ const u = y?.type === "image" || !!y?.asset;
1609
+ if (!y || !u || !d.documentAssetObjectUrl) {
1610
+ V(null), Z(null);
1198
1611
  return;
1199
1612
  }
1200
- let v = !1, _ = null;
1201
- return $(null), c.documentAssetObjectUrl(h.id, r, s).then((E) => {
1613
+ let v = !1, T = null;
1614
+ return Z(null), d.documentAssetObjectUrl(y.id, t, h).then((A) => {
1202
1615
  if (v) {
1203
- URL.revokeObjectURL(E);
1616
+ URL.revokeObjectURL(A);
1204
1617
  return;
1205
1618
  }
1206
- _ = E, M(E);
1207
- }).catch((E) => !v && $(E instanceof Error ? E.message : String(E))), () => {
1208
- v = !0, _ && URL.revokeObjectURL(_);
1619
+ T = A, V(A);
1620
+ }).catch((A) => !v && Z(A instanceof Error ? A.message : String(A))), () => {
1621
+ v = !0, T && URL.revokeObjectURL(T);
1209
1622
  };
1210
- }, [c, h, r, s]), B(() => {
1211
- if (C !== "markdown" || !m) {
1212
- O(null);
1623
+ }, [d, y, t, h]), H(() => {
1624
+ if (B !== "markdown" || !g) {
1625
+ q(null);
1213
1626
  return;
1214
1627
  }
1215
- const u = je(he, m);
1628
+ const u = pt(Ne, g);
1216
1629
  if (!u) return;
1217
1630
  let v = !1;
1218
- const _ = [], E = (U, le) => {
1219
- _.push({ node: U, depth: le }), U.children.forEach((de) => E(de, le + 1));
1631
+ const T = [], A = (J, xe) => {
1632
+ T.push({ node: J, depth: xe }), J.children.forEach(($e) => A($e, xe + 1));
1220
1633
  };
1221
- return E(u, 0), Promise.all(_.map((U) => c.documentGetChunk(U.node.row.id, r, s))).then((U) => {
1634
+ return A(u, 0), Promise.all(T.map((J) => d.documentGetChunk(J.node.row.id, t, h))).then((J) => {
1222
1635
  if (v) return;
1223
- const le = _.map((de, Ke) => {
1224
- const et = Math.min(de.depth + 1, 6), K = U[Ke], fe = "#".repeat(et) + " " + de.node.row.title;
1225
- if (K.type === "mermaid" && K.body)
1226
- return fe + "\n\n```mermaid\n" + K.body + "\n```\n";
1227
- if (K.type === "image" || K.asset) {
1228
- const tt = K.body ? " — " + K.body : "";
1229
- return fe + `
1636
+ const xe = T.map(($e, xt) => {
1637
+ const $t = Math.min($e.depth + 1, 6), ie = J[xt], Ie = "#".repeat($t) + " " + $e.node.row.title;
1638
+ if (ie.type === "mermaid" && ie.body)
1639
+ return Ie + "\n\n```mermaid\n" + ie.body + "\n```\n";
1640
+ if (ie.type === "image" || ie.asset) {
1641
+ const Dt = ie.body ? " — " + ie.body : "";
1642
+ return Ie + `
1230
1643
 
1231
- _🖼 image chunk_` + tt + `
1644
+ _🖼 image chunk_` + Dt + `
1232
1645
  `;
1233
1646
  }
1234
- return fe + (K.body ? `
1647
+ return Ie + (ie.body ? `
1235
1648
 
1236
- ` + K.body : "") + `
1649
+ ` + ie.body : "") + `
1237
1650
  `;
1238
1651
  }).join(`
1239
1652
  `);
1240
- O(le);
1241
- }).catch((U) => !v && p(U instanceof Error ? U.message : String(U))), () => {
1653
+ q(xe);
1654
+ }).catch((J) => !v && M(J instanceof Error ? J.message : String(J))), () => {
1242
1655
  v = !0;
1243
1656
  };
1244
- }, [c, C, m, he, r, T, s]);
1245
- const Je = j((u) => k(u.row.id), []), Ze = j(async () => {
1657
+ }, [d, B, g, Ne, t, ue, h]);
1658
+ const $ = P((u) => N(u.row.id), []), L = P(
1659
+ (u, v, T) => l?.(
1660
+ { documentId: u, chunkId: v, title: T },
1661
+ { documentId: e, chunkId: g, title: se }
1662
+ ),
1663
+ [l, e, g, se]
1664
+ ), G = P(async () => {
1246
1665
  try {
1247
- const u = await c.documentExportMd(e, r, !0, s), v = new Blob([u.markdown], { type: "text/markdown" }), _ = URL.createObjectURL(v), E = document.createElement("a");
1248
- E.href = _, E.download = (u.title || "document").replace(/[^\w.-]+/g, "_") + ".md", E.click(), URL.revokeObjectURL(_);
1666
+ const u = await d.documentExportMd(e, t, !0, h), v = new Blob([u.markdown], { type: "text/markdown" }), T = URL.createObjectURL(v), A = document.createElement("a");
1667
+ A.href = T, A.download = (u.title || "document").replace(/[^\w.-]+/g, "_") + ".md", A.click(), URL.revokeObjectURL(T);
1249
1668
  } catch (u) {
1250
- p(u instanceof Error ? u.message : String(u));
1669
+ M(u instanceof Error ? u.message : String(u));
1251
1670
  }
1252
- }, [c, e, r, s]), qe = j(async () => {
1671
+ }, [d, e, t, h]), ae = P(async () => {
1253
1672
  try {
1254
- const u = await c.documentExportCanvas(e, r, s), v = new Blob([JSON.stringify(u.canvas, null, 2)], {
1673
+ const u = await d.documentExportCanvas(e, t, h), v = new Blob([JSON.stringify(u.canvas, null, 2)], {
1255
1674
  type: "application/json"
1256
- }), _ = URL.createObjectURL(v), E = document.createElement("a");
1257
- E.href = _, E.download = (ie || "document").replace(/[^\w.-]+/g, "_") + ".canvas", E.click(), URL.revokeObjectURL(_);
1675
+ }), T = URL.createObjectURL(v), A = document.createElement("a");
1676
+ A.href = T, A.download = (se || "document").replace(/[^\w.-]+/g, "_") + ".canvas", A.click(), URL.revokeObjectURL(T);
1258
1677
  } catch (u) {
1259
- p(u instanceof Error ? u.message : String(u));
1678
+ M(u instanceof Error ? u.message : String(u));
1260
1679
  }
1261
- }, [c, e, r, s, ie]), me = !!c.documentCreateChunk && !!X, pe = j(
1680
+ }, [d, e, t, h, se]), le = !!d.documentCreateChunk && !!K, ye = P(
1262
1681
  async (u) => {
1263
- if (!c.documentCreateChunk || !c.documentSetAsset) return;
1264
- const v = m || X;
1682
+ if (!d.documentCreateChunk || !d.documentSetAsset) return;
1683
+ const v = g || K;
1265
1684
  if (v) {
1266
- p(null);
1685
+ M(null);
1267
1686
  try {
1268
- const { mediaType: _, data: E } = await Oe(u), U = await c.documentCreateChunk(
1687
+ const { mediaType: T, data: A } = await mt(u), J = await d.documentCreateChunk(
1269
1688
  e,
1270
1689
  v,
1271
1690
  { title: u.name || "image", type: "image" },
1272
- r,
1273
- s
1691
+ t,
1692
+ h
1274
1693
  );
1275
- await c.documentSetAsset(U.id, _, E, u.name, r, s), z(), k(U.id);
1276
- } catch (_) {
1277
- p(_ instanceof Error ? _.message : String(_));
1694
+ await d.documentSetAsset(J.id, T, A, u.name, t, h), F(), N(J.id);
1695
+ } catch (T) {
1696
+ M(T instanceof Error ? T.message : String(T));
1278
1697
  }
1279
1698
  }
1280
1699
  },
1281
- [c, e, r, s, m, X, z]
1282
- ), Qe = j(async () => {
1283
- if (!c.documentCreateChunk) return;
1284
- const u = m || X;
1700
+ [d, e, t, h, g, K, F]
1701
+ ), Ct = P(async () => {
1702
+ if (!d.documentCreateChunk) return;
1703
+ const u = g || K;
1285
1704
  if (u) {
1286
- p(null);
1705
+ M(null);
1287
1706
  try {
1288
- const v = await c.documentCreateChunk(
1707
+ const v = await d.documentCreateChunk(
1289
1708
  e,
1290
1709
  u,
1291
1710
  { title: "Diagram", type: "mermaid", body: `graph TD
1292
1711
  A[Start] --> B[End]` },
1293
- r,
1294
- s
1712
+ t,
1713
+ h
1295
1714
  );
1296
- z(), k(v.id), y(v);
1715
+ F(), N(v.id), E(v);
1297
1716
  } catch (v) {
1298
- p(v instanceof Error ? v.message : String(v));
1717
+ M(v instanceof Error ? v.message : String(v));
1299
1718
  }
1300
1719
  }
1301
- }, [c, e, r, s, m, X, z]), Xe = j(async () => {
1302
- if (!c.documentCreateChunk) return;
1303
- const u = m && !te ? m : void 0, v = m || X;
1720
+ }, [d, e, t, h, g, K, F]), _t = P(async () => {
1721
+ if (!d.documentCreateChunk) return;
1722
+ const u = g && !re ? g : void 0, v = g || K;
1304
1723
  if (v) {
1305
- p(null);
1724
+ M(null);
1306
1725
  try {
1307
- const _ = await c.documentCreateChunk(
1726
+ const T = await d.documentCreateChunk(
1308
1727
  e,
1309
1728
  u ? "" : v,
1310
1729
  // after_id resolves the parent server-side
1311
1730
  { title: "Text", body: "" },
1312
- r,
1313
- s,
1731
+ t,
1732
+ h,
1314
1733
  u
1315
1734
  );
1316
- z(), k(_.id), y(_);
1317
- } catch (_) {
1318
- p(_ instanceof Error ? _.message : String(_));
1735
+ F(), N(T.id), E(T);
1736
+ } catch (T) {
1737
+ M(T instanceof Error ? T.message : String(T));
1738
+ }
1739
+ }
1740
+ }, [d, e, t, h, g, re, K, F]), St = P(async () => {
1741
+ if (!(!d.documentCreateChunk || !g)) {
1742
+ M(null);
1743
+ try {
1744
+ const u = await d.documentCreateChunk(
1745
+ e,
1746
+ g,
1747
+ { title: "Text", body: "" },
1748
+ t,
1749
+ h
1750
+ );
1751
+ F(), N(u.id), E(u);
1752
+ } catch (u) {
1753
+ M(u instanceof Error ? u.message : String(u));
1319
1754
  }
1320
1755
  }
1321
- }, [c, e, r, s, m, te, X, z]), we = q(() => {
1322
- if (!h || te) return { canUp: !1, canDown: !1 };
1323
- const u = h.parent_id ?? "", v = d.filter((E) => (E.parent_id ?? "") === u).sort((E, U) => E.position - U.position || E.id.localeCompare(U.id)), _ = v.findIndex((E) => E.id === h.id);
1324
- return { canUp: _ > 0, canDown: _ >= 0 && _ < v.length - 1 };
1325
- }, [d, h, te]), Ce = j(
1756
+ }, [d, e, t, h, g, F]), We = X(() => {
1757
+ if (!y || re) return { canUp: !1, canDown: !1 };
1758
+ const u = y.parent_id ?? "", v = w.filter((A) => (A.parent_id ?? "") === u).sort((A, J) => A.position - J.position || A.id.localeCompare(J.id)), T = v.findIndex((A) => A.id === y.id);
1759
+ return { canUp: T > 0, canDown: T >= 0 && T < v.length - 1 };
1760
+ }, [w, y, re]), Ve = P(
1326
1761
  async (u) => {
1327
- if (!(!c.documentReorderChunk || !m)) {
1328
- p(null);
1762
+ if (!(!d.documentReorderChunk || !g)) {
1763
+ M(null);
1329
1764
  try {
1330
- await c.documentReorderChunk(m, u, r, s), z();
1765
+ await d.documentReorderChunk(g, u, t, h), F();
1331
1766
  } catch (v) {
1332
- p(v instanceof Error ? v.message : String(v));
1767
+ M(v instanceof Error ? v.message : String(v));
1333
1768
  }
1334
1769
  }
1335
1770
  },
1336
- [c, m, r, s, z]
1337
- ), Ye = j(async () => {
1338
- if (!c.documentDeleteChunk || !h) return;
1339
- p(null);
1340
- const u = h.parent_id;
1771
+ [d, g, t, h, F]
1772
+ ), Et = P(async () => {
1773
+ if (!d.documentDeleteChunk || !y) return;
1774
+ M(null);
1775
+ const u = y.parent_id;
1341
1776
  try {
1342
- await c.documentDeleteChunk(h.id, r, s), N(!1), k(u || X), z();
1777
+ await d.documentDeleteChunk(y.id, t, h), x(!1), N(u || K), F();
1343
1778
  } catch (v) {
1344
- p(v instanceof Error ? v.message : String(v)), N(!1);
1779
+ M(v instanceof Error ? v.message : String(v)), x(!1);
1345
1780
  }
1346
- }, [c, h, r, s, X, z]);
1347
- return B(() => {
1348
- if (!me) return;
1781
+ }, [d, y, t, h, K, F]);
1782
+ return H(() => {
1783
+ if (!le) return;
1349
1784
  const u = (v) => {
1350
- if (R || x) return;
1351
- const _ = document.activeElement, E = _?.tagName;
1352
- if (E === "INPUT" || E === "TEXTAREA" || _?.isContentEditable) return;
1353
- const U = ht(v.clipboardData?.items);
1354
- U && (v.preventDefault(), pe(U));
1785
+ if (R || fe) return;
1786
+ const T = document.activeElement, A = T?.tagName;
1787
+ if (A === "INPUT" || A === "TEXTAREA" || T?.isContentEditable) return;
1788
+ const J = Qt(v.clipboardData?.items);
1789
+ J && (v.preventDefault(), ye(J));
1355
1790
  };
1356
1791
  return window.addEventListener("paste", u), () => window.removeEventListener("paste", u);
1357
- }, [me, R, x, pe]), /* @__PURE__ */ l("div", { className: "doc-viewer", children: [
1358
- /* @__PURE__ */ t(
1792
+ }, [le, R, fe, ye]), /* @__PURE__ */ c("div", { className: "doc-viewer", children: [
1793
+ /* @__PURE__ */ a(
1359
1794
  "input",
1360
1795
  {
1361
- ref: G,
1796
+ ref: _,
1362
1797
  type: "file",
1363
1798
  accept: "image/png,image/jpeg,image/gif,image/webp",
1364
1799
  style: { display: "none" },
1365
1800
  onChange: (u) => {
1366
1801
  const v = u.target.files?.[0];
1367
- u.target.value = "", v && pe(v);
1802
+ u.target.value = "", v && ye(v);
1368
1803
  }
1369
1804
  }
1370
1805
  ),
1371
- /* @__PURE__ */ l("div", { className: "doc-toolbar", style: ze, children: [
1372
- /* @__PURE__ */ t("strong", { className: "doc-title", title: ie, children: ie }),
1373
- /* @__PURE__ */ l("div", { className: "doc-toolbar-actions", children: [
1374
- me && /* @__PURE__ */ l(Y, { children: [
1375
- /* @__PURE__ */ t(
1806
+ /* @__PURE__ */ c("div", { className: "doc-toolbar", style: Re, children: [
1807
+ /* @__PURE__ */ a("strong", { className: "doc-title", title: se, children: se }),
1808
+ /* @__PURE__ */ a(Fe, { value: e, label: "doc" }),
1809
+ /* @__PURE__ */ c("div", { className: "doc-toolbar-actions", children: [
1810
+ le && /* @__PURE__ */ c(Q, { children: [
1811
+ /* @__PURE__ */ a(
1376
1812
  "button",
1377
1813
  {
1378
1814
  type: "button",
1379
1815
  onClick: () => {
1380
- Xe();
1816
+ _t();
1381
1817
  },
1382
- title: "Add a text chunk after the selected chunk",
1818
+ title: "Add a text chunk AFTER the selected chunk, at the same level",
1383
1819
  children: "+ text"
1384
1820
  }
1385
1821
  ),
1386
- /* @__PURE__ */ t(
1822
+ /* @__PURE__ */ a(
1823
+ "button",
1824
+ {
1825
+ type: "button",
1826
+ onClick: () => {
1827
+ St();
1828
+ },
1829
+ disabled: !g,
1830
+ title: g ? "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",
1831
+ children: "+ child"
1832
+ }
1833
+ ),
1834
+ /* @__PURE__ */ a(
1387
1835
  "button",
1388
1836
  {
1389
1837
  type: "button",
1390
- onClick: () => G.current?.click(),
1838
+ onClick: () => _.current?.click(),
1391
1839
  title: "Add an image chunk (upload — or paste a screenshot into the view)",
1392
1840
  children: "+ image"
1393
1841
  }
1394
1842
  ),
1395
- /* @__PURE__ */ t(
1843
+ /* @__PURE__ */ a(
1396
1844
  "button",
1397
1845
  {
1398
1846
  type: "button",
1399
1847
  onClick: () => {
1400
- Qe();
1848
+ Ct();
1401
1849
  },
1402
1850
  title: "Add a Mermaid diagram chunk",
1403
1851
  children: "+ diagram"
1404
1852
  }
1405
1853
  )
1406
1854
  ] }),
1407
- /* @__PURE__ */ t(
1855
+ /* @__PURE__ */ a(
1408
1856
  "button",
1409
1857
  {
1410
1858
  type: "button",
1411
- className: se ? "active" : "",
1412
- onClick: () => H(!0),
1413
- disabled: !X,
1859
+ className: ge ? "active" : "",
1860
+ onClick: () => Se(!0),
1861
+ disabled: !K,
1414
1862
  title: "Colors — tint chunk tiles + the Path tree by type/status",
1415
1863
  children: "colors"
1416
1864
  }
1417
1865
  ),
1418
- /* @__PURE__ */ t("button", { type: "button", onClick: () => {
1419
- Ze();
1866
+ /* @__PURE__ */ a("button", { type: "button", onClick: () => {
1867
+ G();
1420
1868
  }, title: "Download the whole document as Markdown (.md)", children: "↓ .md" }),
1421
- /* @__PURE__ */ t(
1869
+ /* @__PURE__ */ a(
1422
1870
  "button",
1423
1871
  {
1424
1872
  type: "button",
1425
1873
  onClick: () => {
1426
- qe();
1874
+ ae();
1427
1875
  },
1428
1876
  title: "Download the whole document as a node/edge canvas graph (.canvas)",
1429
1877
  children: "↓ .canvas"
1430
1878
  }
1431
1879
  ),
1432
- i && /* @__PURE__ */ t(
1880
+ s && /* @__PURE__ */ a(
1433
1881
  "button",
1434
1882
  {
1435
1883
  type: "button",
1436
- className: oe ? "active" : "",
1437
- onClick: () => ce((u) => !u),
1884
+ className: _e ? "active" : "",
1885
+ onClick: () => D((u) => !u),
1438
1886
  title: "Document Assistant — instruct an agent to restructure/import/link chunks",
1439
1887
  children: "assistant"
1440
1888
  }
1441
1889
  ),
1442
- /* @__PURE__ */ t("button", { type: "button", onClick: z, title: "Reload", children: "↻" })
1890
+ /* @__PURE__ */ a("button", { type: "button", onClick: F, title: "Reload", children: "↻" })
1443
1891
  ] })
1444
1892
  ] }),
1445
- b && /* @__PURE__ */ t("div", { className: "paths-err", children: b }),
1446
- /* @__PURE__ */ l("div", { className: "doc-split", children: [
1447
- /* @__PURE__ */ t("div", { className: "doc-chunktree", children: w && d.length === 0 ? /* @__PURE__ */ t("div", { className: "empty", children: /* @__PURE__ */ t("p", { children: "Loading…" }) }) : /* @__PURE__ */ t(
1448
- yt,
1893
+ U && /* @__PURE__ */ a("div", { className: "paths-err", children: U }),
1894
+ Pe ? /* @__PURE__ */ a(vn, { documentId: e, scope: t, detail: me ?? void 0 }) : /* @__PURE__ */ c("div", { className: "doc-split", children: [
1895
+ /* @__PURE__ */ a("div", { className: "doc-chunktree", children: ne && w.length === 0 ? /* @__PURE__ */ a("div", { className: "empty", children: /* @__PURE__ */ a("p", { children: "Loading…" }) }) : /* @__PURE__ */ a(
1896
+ an,
1449
1897
  {
1450
- tree: he,
1451
- selectedId: m,
1452
- onSelect: Je,
1453
- colorEnabled: se,
1454
- scheme: Z?.color_scheme,
1455
- linkedIds: Ve
1898
+ tree: Ne,
1899
+ selectedId: g,
1900
+ onSelect: $,
1901
+ colorEnabled: ge,
1902
+ scheme: Y?.color_scheme,
1903
+ linkedIds: Me
1456
1904
  }
1457
1905
  ) }),
1458
- /* @__PURE__ */ t("div", { className: "doc-content", children: h ? /* @__PURE__ */ l(Y, { children: [
1459
- /* @__PURE__ */ l("div", { className: "doc-content-head", children: [
1460
- /* @__PURE__ */ t("h3", { children: h.title || "(untitled)" }),
1461
- /* @__PURE__ */ l("div", { className: "doc-content-meta", children: [
1462
- h.type && /* @__PURE__ */ t("span", { className: "chunk-badge", children: h.type }),
1463
- h.status && /* @__PURE__ */ t("span", { className: "chunk-badge chunk-status", children: h.status }),
1464
- /* @__PURE__ */ l("span", { className: "chunk-rev", children: [
1906
+ /* @__PURE__ */ a("div", { className: "doc-content", children: y ? /* @__PURE__ */ c(Q, { children: [
1907
+ /* @__PURE__ */ c("div", { className: "doc-content-head", children: [
1908
+ /* @__PURE__ */ a("h3", { children: y.title || "(untitled)" }),
1909
+ /* @__PURE__ */ c("div", { className: "doc-content-meta", children: [
1910
+ y.type && /* @__PURE__ */ a("span", { className: "chunk-badge", children: y.type }),
1911
+ y.status && /* @__PURE__ */ a("span", { className: "chunk-badge chunk-status", children: y.status }),
1912
+ /* @__PURE__ */ c("span", { className: "chunk-rev", children: [
1465
1913
  "rev ",
1466
- h.revision
1914
+ y.revision
1467
1915
  ] }),
1468
- h.tags?.map((u) => /* @__PURE__ */ t("span", { className: "chunk-tag", children: u }, u))
1916
+ y.tags?.map((u) => /* @__PURE__ */ a("span", { className: "chunk-tag", children: u }, u)),
1917
+ /* @__PURE__ */ a(Fe, { value: y.id, label: "chunk" })
1469
1918
  ] }),
1470
- /* @__PURE__ */ l("div", { className: "doc-content-controls", children: [
1471
- /* @__PURE__ */ l("div", { className: "doc-mode-toggle", children: [
1472
- /* @__PURE__ */ t(
1919
+ /* @__PURE__ */ c("div", { className: "doc-content-controls", children: [
1920
+ /* @__PURE__ */ c("div", { className: "doc-mode-toggle", children: [
1921
+ /* @__PURE__ */ a(
1473
1922
  "button",
1474
1923
  {
1475
1924
  type: "button",
1476
- className: C === "chunks" ? "active" : "",
1477
- onClick: () => L("chunks"),
1925
+ className: B === "chunks" ? "active" : "",
1926
+ onClick: () => O("chunks"),
1478
1927
  title: "This chunk's own content",
1479
1928
  children: "chunk"
1480
1929
  }
1481
1930
  ),
1482
- /* @__PURE__ */ t(
1931
+ /* @__PURE__ */ a(
1483
1932
  "button",
1484
1933
  {
1485
1934
  type: "button",
1486
- className: C === "markdown" ? "active" : "",
1487
- onClick: () => L("markdown"),
1488
- title: te ? "Whole document as Markdown" : "This chunk + its sub-chunks as Markdown",
1935
+ className: B === "markdown" ? "active" : "",
1936
+ onClick: () => O("markdown"),
1937
+ title: re ? "Whole document as Markdown" : "This chunk + its sub-chunks as Markdown",
1489
1938
  children: "markdown"
1490
1939
  }
1491
1940
  )
1492
1941
  ] }),
1493
- /* @__PURE__ */ t("button", { type: "button", onClick: () => y(h), children: "edit" }),
1494
- /* @__PURE__ */ t(
1942
+ /* @__PURE__ */ a("button", { type: "button", onClick: () => E(y), children: "edit" }),
1943
+ /* @__PURE__ */ a(
1495
1944
  "button",
1496
1945
  {
1497
1946
  type: "button",
1498
- onClick: () => J(!0),
1947
+ onClick: () => b(!0),
1499
1948
  title: "View this chunk's edit history + diffs",
1500
1949
  children: "history"
1501
1950
  }
1502
1951
  ),
1503
- !te && /* @__PURE__ */ l(Y, { children: [
1504
- /* @__PURE__ */ t(
1952
+ !re && /* @__PURE__ */ c(Q, { children: [
1953
+ /* @__PURE__ */ a(
1505
1954
  "button",
1506
1955
  {
1507
1956
  type: "button",
1508
1957
  onClick: () => {
1509
- Ce("up");
1958
+ Ve("up");
1510
1959
  },
1511
- disabled: !we.canUp,
1960
+ disabled: !We.canUp,
1512
1961
  title: "Move this chunk up within its level",
1513
1962
  children: "↑"
1514
1963
  }
1515
1964
  ),
1516
- /* @__PURE__ */ t(
1965
+ /* @__PURE__ */ a(
1517
1966
  "button",
1518
1967
  {
1519
1968
  type: "button",
1520
1969
  onClick: () => {
1521
- Ce("down");
1970
+ Ve("down");
1522
1971
  },
1523
- disabled: !we.canDown,
1972
+ disabled: !We.canDown,
1524
1973
  title: "Move this chunk down within its level",
1525
1974
  children: "↓"
1526
1975
  }
1527
1976
  )
1528
1977
  ] }),
1529
- !te && /* @__PURE__ */ t(
1978
+ !re && /* @__PURE__ */ a(
1530
1979
  "button",
1531
1980
  {
1532
1981
  type: "button",
1533
1982
  className: "danger",
1534
- onClick: () => N(!0),
1983
+ onClick: () => x(!0),
1535
1984
  title: "Delete this chunk and its sub-chunks",
1536
1985
  children: "delete"
1537
1986
  }
1538
1987
  )
1539
1988
  ] })
1540
1989
  ] }),
1541
- /* @__PURE__ */ t("div", { className: "doc-content-body", children: h.type === "mermaid" ? (
1990
+ /* @__PURE__ */ a("div", { className: "doc-content-body", children: y.type === "mermaid" ? (
1542
1991
  // RFC BO — a diagram chunk: body IS the Mermaid source.
1543
- h.body ? /* @__PURE__ */ l(Y, { children: [
1544
- /* @__PURE__ */ t(ue, { code: h.body }),
1545
- C === "markdown" && /* @__PURE__ */ t("pre", { className: "md-pre doc-mermaid-source", children: /* @__PURE__ */ t("code", { children: h.body }) })
1546
- ] }) : /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "(empty diagram)" })
1547
- ) : h.type === "image" || h.asset ? (
1992
+ y.body ? /* @__PURE__ */ c(Q, { children: [
1993
+ /* @__PURE__ */ a(Te, { code: y.body }),
1994
+ B === "markdown" && /* @__PURE__ */ a("pre", { className: "md-pre doc-mermaid-source", children: /* @__PURE__ */ a("code", { children: y.body }) })
1995
+ ] }) : /* @__PURE__ */ a("p", { className: "doc-empty-body", children: "(empty diagram)" })
1996
+ ) : y.type === "image" || y.asset ? (
1548
1997
  // RFC BO — an image chunk: bytes come from the auth'd asset GET.
1549
- I ? /* @__PURE__ */ l("p", { className: "doc-empty-body", children: [
1998
+ z ? /* @__PURE__ */ c("p", { className: "doc-empty-body", children: [
1550
1999
  "Image failed to load: ",
1551
- I
1552
- ] }) : A ? /* @__PURE__ */ l("figure", { className: "doc-image", children: [
1553
- /* @__PURE__ */ t("img", { src: A, alt: Pt(h) }),
1554
- h.body && /* @__PURE__ */ t("figcaption", { children: h.body })
1555
- ] }) : /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "Loading image…" })
1556
- ) : C === "markdown" ? F !== null ? /* @__PURE__ */ t(Me, { source: F }) : /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "Assembling Markdown…" }) : h.body ? /* @__PURE__ */ t(Me, { source: h.body }) : /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "(empty chunk)" }) }),
1557
- /* @__PURE__ */ t(
1558
- xt,
2000
+ z
2001
+ ] }) : I ? /* @__PURE__ */ c("figure", { className: "doc-image", children: [
2002
+ /* @__PURE__ */ a("img", { src: I, alt: _n(y) }),
2003
+ y.body && /* @__PURE__ */ a("figcaption", { children: y.body })
2004
+ ] }) : /* @__PURE__ */ a("p", { className: "doc-empty-body", children: "Loading image…" })
2005
+ ) : B === "markdown" ? W !== null ? /* @__PURE__ */ a(et, { source: W }) : /* @__PURE__ */ a("p", { className: "doc-empty-body", children: "Assembling Markdown…" }) : y.body ? /* @__PURE__ */ a(et, { source: y.body }) : /* @__PURE__ */ a("p", { className: "doc-empty-body", children: "(empty chunk)" }) }),
2006
+ /* @__PURE__ */ a(
2007
+ pn,
1559
2008
  {
1560
- edges: W,
2009
+ edges: pe,
1561
2010
  documentId: e,
1562
- selectedId: m,
1563
- onSelectChunk: k
2011
+ selectedId: g,
2012
+ onSelectChunk: N,
2013
+ onOpenDocument: l ? L : void 0
1564
2014
  }
1565
2015
  ),
1566
- /* @__PURE__ */ t(
1567
- Et,
2016
+ /* @__PURE__ */ a(
2017
+ fn,
1568
2018
  {
1569
2019
  documentId: e,
1570
- selectedId: m,
1571
- scope: r,
1572
- browse: s,
1573
- onSelectChunk: k
2020
+ selectedId: g,
2021
+ scope: t,
2022
+ browse: h,
2023
+ onSelectChunk: N,
2024
+ onOpenDocument: l ? L : void 0
1574
2025
  }
1575
2026
  )
1576
- ] }) : /* @__PURE__ */ t("div", { className: "empty", children: /* @__PURE__ */ t("p", { children: "Select a chunk on the left." }) }) })
2027
+ ] }) : /* @__PURE__ */ a("div", { className: "empty", children: /* @__PURE__ */ a("p", { children: "Select a chunk on the left." }) }) })
1577
2028
  ] }),
1578
- oe && i && /* @__PURE__ */ t("div", { className: "doc-assistant", children: i({
2029
+ _e && s && /* @__PURE__ */ a("div", { className: "doc-assistant", children: s({
1579
2030
  documentId: e,
1580
- scope: r,
2031
+ scope: t,
1581
2032
  subject: o?.subject,
1582
2033
  // Pass the viewer's own reload so the injected assistant can refresh
1583
2034
  // the tree + selected chunk after a turn mutates the document.
1584
- onChanged: z
2035
+ onChanged: F
1585
2036
  }) }),
1586
- R && /* @__PURE__ */ t(
1587
- kt,
2037
+ R && /* @__PURE__ */ a(
2038
+ cn,
1588
2039
  {
1589
2040
  chunk: R,
1590
- scope: r,
1591
- browse: s,
1592
- onClose: () => y(null),
1593
- onSaved: z
2041
+ scope: t,
2042
+ browse: h,
2043
+ onClose: () => E(null),
2044
+ onSaved: F
1594
2045
  }
1595
2046
  ),
1596
- D && h && /* @__PURE__ */ t(
1597
- $t,
2047
+ m && y && /* @__PURE__ */ a(
2048
+ Nn,
1598
2049
  {
1599
- chunkId: h.id,
1600
- chunkTitle: h.title,
1601
- scope: r,
1602
- browse: s,
1603
- onClose: () => J(!1)
2050
+ chunkId: y.id,
2051
+ chunkTitle: y.title,
2052
+ scope: t,
2053
+ browse: h,
2054
+ onClose: () => b(!1)
1604
2055
  }
1605
2056
  ),
1606
- x && X && /* @__PURE__ */ t(
1607
- wt,
2057
+ fe && K && /* @__PURE__ */ a(
2058
+ dn,
1608
2059
  {
1609
2060
  documentId: e,
1610
- rootChunkId: X,
1611
- docType: Z?.type,
1612
- docStatus: Z?.status,
1613
- chunkStatuses: We,
1614
- scope: r,
1615
- browse: s,
1616
- onClose: () => H(!1),
1617
- onSaved: z
2061
+ rootChunkId: K,
2062
+ docType: Y?.type,
2063
+ docStatus: Y?.status,
2064
+ chunkStatuses: ee,
2065
+ scope: t,
2066
+ browse: h,
2067
+ onClose: () => Se(!1),
2068
+ onSaved: F
1618
2069
  }
1619
2070
  ),
1620
- V && h && /* @__PURE__ */ t("div", { className: "modal-overlay", onClick: () => N(!1), children: /* @__PURE__ */ l("div", { className: "modal chunk-delete-confirm", onClick: (u) => u.stopPropagation(), children: [
1621
- /* @__PURE__ */ t("h3", { children: "Delete chunk" }),
1622
- /* @__PURE__ */ l("p", { className: "modal-context", children: [
2071
+ C && y && /* @__PURE__ */ a("div", { className: "modal-overlay", onClick: () => x(!1), children: /* @__PURE__ */ c("div", { className: "modal chunk-delete-confirm", onClick: (u) => u.stopPropagation(), children: [
2072
+ /* @__PURE__ */ a("h3", { children: "Delete chunk" }),
2073
+ /* @__PURE__ */ c("p", { className: "modal-context", children: [
1623
2074
  "Delete “",
1624
- h.title || "(untitled)",
2075
+ y.title || "(untitled)",
1625
2076
  "” and all of its sub-chunks? This cannot be undone."
1626
2077
  ] }),
1627
- /* @__PURE__ */ l("div", { className: "modal-buttons", children: [
1628
- /* @__PURE__ */ t("button", { type: "button", onClick: () => N(!1), children: "cancel" }),
1629
- /* @__PURE__ */ t("button", { type: "button", className: "danger", onClick: () => {
1630
- Ye();
2078
+ /* @__PURE__ */ c("div", { className: "modal-buttons", children: [
2079
+ /* @__PURE__ */ a("button", { type: "button", onClick: () => x(!1), children: "cancel" }),
2080
+ /* @__PURE__ */ a("button", { type: "button", className: "danger", onClick: () => {
2081
+ Et();
1631
2082
  }, children: "delete" })
1632
2083
  ] })
1633
2084
  ] }) })
1634
2085
  ] });
1635
2086
  }
1636
- function At(e) {
1637
- const r = {
1638
- name: "",
1639
- fullPath: "",
1640
- kind: "directory",
1641
- explicit: !0,
1642
- children: []
1643
- }, n = /* @__PURE__ */ new Map([["", r]]), a = (i) => {
1644
- const c = n.get(i);
1645
- if (c) return c;
1646
- const s = i.lastIndexOf("/"), d = s <= 0 ? "" : i.slice(0, s), g = i.slice(s + 1), m = a(d), k = {
1647
- name: g,
1648
- fullPath: i,
1649
- kind: "directory",
1650
- explicit: !1,
1651
- children: []
2087
+ function vt(e, t = "") {
2088
+ const n = e.get(t);
2089
+ if (!n) return [];
2090
+ const r = n.entries.map((o) => {
2091
+ const s = o.kind === "directory" && o.full_path.startsWith(`${t}/`);
2092
+ return {
2093
+ name: o.name,
2094
+ fullPath: o.full_path,
2095
+ kind: o.kind,
2096
+ resourceRef: o.resource_ref,
2097
+ listing: s ? e.get(o.full_path) : void 0,
2098
+ children: s ? vt(e, o.full_path) : []
1652
2099
  };
1653
- return m.children.push(k), n.set(i, k), k;
1654
- };
1655
- for (const i of e) {
1656
- const c = a(i.full_path);
1657
- c.kind = i.kind, c.explicit = !0, c.resourceRef = i.resource_ref;
1658
- }
1659
- const o = (i) => {
1660
- i.sort((c, s) => {
1661
- const d = c.kind === "directory", g = s.kind === "directory";
1662
- return d !== g ? d ? -1 : 1 : c.name.localeCompare(s.name);
1663
- }), i.forEach((c) => o(c.children));
1664
- };
1665
- return o(r.children), r.children;
1666
- }
1667
- function ve(e) {
1668
- const r = e.lastIndexOf("/");
1669
- return r <= 0 ? "" : e.slice(0, r);
1670
- }
1671
- function Ut(e) {
1672
- const r = [], n = (a) => {
1673
- if (a.kind === "document") {
1674
- const o = a.resourceRef;
1675
- o?.document_id && r.push(o.document_id);
1676
- }
1677
- a.children.forEach(n);
1678
- };
1679
- return n(e), r;
2100
+ });
2101
+ return r.sort((o, s) => {
2102
+ const i = o.kind === "directory", l = s.kind === "directory";
2103
+ return i !== l ? i ? -1 : 1 : o.name.localeCompare(s.name);
2104
+ }), r;
1680
2105
  }
1681
- const Ot = {
2106
+ const Sn = {
1682
2107
  directory: "📁",
1683
2108
  document: "📄",
1684
2109
  volume_mount: "💾",
1685
2110
  memory_entry: "🧠"
1686
2111
  };
1687
- function It({ tree: e, selectedPath: r, onSelect: n, summaries: a }) {
1688
- const [o, i] = f(() => /* @__PURE__ */ new Map()), c = j((s) => {
1689
- i((d) => {
1690
- const g = new Map(d);
1691
- return g.set(s, d.get(s) === !1), g;
1692
- });
1693
- }, []);
1694
- return B(() => {
1695
- r && i((s) => {
1696
- let d = !1;
1697
- const g = new Map(s);
1698
- let m = ve(r);
1699
- for (; m !== ""; )
1700
- g.get(m) === !1 && (g.set(m, !0), d = !0), m = ve(m);
1701
- return d ? g : s;
1702
- });
1703
- }, [r]), e.length === 0 ? /* @__PURE__ */ t("div", { className: "empty", children: /* @__PURE__ */ t("p", { children: "This tree is empty. Create a folder or document to begin." }) }) : /* @__PURE__ */ t("ul", { className: "tree path-tree", children: e.map((s) => /* @__PURE__ */ t(
1704
- Ge,
1705
- {
1706
- node: s,
1707
- expanded: o,
1708
- toggle: c,
1709
- selectedPath: r,
1710
- onSelect: n,
1711
- summaries: a
1712
- },
1713
- s.fullPath
1714
- )) });
2112
+ function En(e) {
2113
+ const { tree: t, root: n } = e;
2114
+ return !n || !n.loaded && n.loading ? /* @__PURE__ */ a("div", { className: "empty", children: /* @__PURE__ */ a("p", { children: "Loading…" }) }) : n.loaded && t.length === 0 && !n.nextCursor ? /* @__PURE__ */ a("div", { className: "empty", children: /* @__PURE__ */ a("p", { children: "This tree is empty. Create a folder or document to begin." }) }) : /* @__PURE__ */ c("ul", { className: "tree path-tree", children: [
2115
+ t.map((r) => /* @__PURE__ */ a(Nt, { node: r, ...e }, r.fullPath)),
2116
+ /* @__PURE__ */ a(kt, { dir: "", listing: n, ...e })
2117
+ ] });
2118
+ }
2119
+ function kt({
2120
+ dir: e,
2121
+ listing: t,
2122
+ onLoadMore: n,
2123
+ onRetry: r
2124
+ }) {
2125
+ const o = [];
2126
+ return !t || t.loading && t.entries.length === 0 ? o.push(
2127
+ /* @__PURE__ */ a("li", { className: "node path-status", children: /* @__PURE__ */ a("span", { className: "path-implicit", children: "loading…" }) }, "status")
2128
+ ) : t.error ? o.push(
2129
+ /* @__PURE__ */ c("li", { className: "node path-status", children: [
2130
+ e !== "" && /* @__PURE__ */ c("span", { className: "path-err", children: [
2131
+ "failed to load: ",
2132
+ t.error
2133
+ ] }),
2134
+ " ",
2135
+ /* @__PURE__ */ a("button", { type: "button", className: "path-more", onClick: () => r(e), children: "retry" })
2136
+ ] }, "status")
2137
+ ) : t.loaded && t.entries.length === 0 && e !== "" && o.push(
2138
+ /* @__PURE__ */ a("li", { className: "node path-status", children: /* @__PURE__ */ a("span", { className: "path-implicit", children: "empty" }) }, "status")
2139
+ ), t?.nextCursor && !t.error && o.push(
2140
+ /* @__PURE__ */ a("li", { className: "node path-status", children: /* @__PURE__ */ a(
2141
+ "button",
2142
+ {
2143
+ type: "button",
2144
+ className: "path-more",
2145
+ disabled: t.loading,
2146
+ onClick: () => n(e),
2147
+ children: t.loading ? "loading…" : `Load more (${t.entries.length} shown)`
2148
+ }
2149
+ ) }, "more")
2150
+ ), /* @__PURE__ */ a(Q, { children: o });
1715
2151
  }
1716
- function jt(e, r) {
1717
- if (e.kind !== "document" || !r) return;
2152
+ function xn(e, t) {
2153
+ if (e.kind !== "document" || !t) return;
1718
2154
  const n = e.resourceRef;
1719
- return n?.document_id ? r.get(n.document_id) : void 0;
2155
+ return n?.document_id ? t.get(n.document_id) : void 0;
1720
2156
  }
1721
- function Ge({ node: e, expanded: r, toggle: n, selectedPath: a, onSelect: o, summaries: i }) {
1722
- const c = e.children.length > 0, s = r.get(e.fullPath) !== !1, d = a === e.fullPath, g = jt(e, i), m = g && g.color_enabled ? Ne(Ie(g.type, g.status, ke(g.color_scheme))) : void 0;
1723
- return /* @__PURE__ */ l("li", { className: `node path-node kind-${e.kind} ${d ? "selected" : ""}`, children: [
1724
- /* @__PURE__ */ l("div", { className: "row path-row", style: m, children: [
1725
- /* @__PURE__ */ t(
2157
+ function Nt(e) {
2158
+ const { node: t, expanded: n, onToggle: r, selectedPath: o, onSelect: s, summaries: i } = e, l = t.kind === "directory", f = l && n.has(t.fullPath), d = o === t.fullPath, h = xn(t, i), w = h && h.color_enabled ? He(ft(h.type, h.status, Ge(h.color_scheme))) : void 0;
2159
+ return /* @__PURE__ */ c("li", { className: `node path-node kind-${t.kind} ${d ? "selected" : ""}`, children: [
2160
+ /* @__PURE__ */ c("div", { className: "row path-row", style: w, children: [
2161
+ /* @__PURE__ */ a(
1726
2162
  "button",
1727
2163
  {
1728
2164
  type: "button",
1729
2165
  className: "tree-caret",
1730
- "aria-label": s ? "collapse" : "expand",
1731
- disabled: !c,
1732
- onClick: (k) => {
1733
- k.stopPropagation(), c && n(e.fullPath);
2166
+ "aria-label": f ? "collapse" : "expand",
2167
+ "aria-expanded": l ? f : void 0,
2168
+ disabled: !l,
2169
+ onClick: (S) => {
2170
+ S.stopPropagation(), l && r(t.fullPath);
1734
2171
  },
1735
- children: c ? s ? "▼" : "▶" : "·"
2172
+ children: l ? f ? "▼" : "▶" : "·"
1736
2173
  }
1737
2174
  ),
1738
- /* @__PURE__ */ l(
2175
+ /* @__PURE__ */ c(
1739
2176
  "button",
1740
2177
  {
1741
2178
  type: "button",
1742
2179
  className: "path-link",
1743
- onClick: () => o(e),
1744
- title: e.fullPath,
2180
+ onClick: () => s(t),
2181
+ title: t.fullPath,
1745
2182
  children: [
1746
- /* @__PURE__ */ t("span", { className: "path-kind-icon", "aria-hidden": !0, children: Ot[e.kind] ?? "•" }),
1747
- /* @__PURE__ */ t("span", { className: "path-name", children: e.name }),
1748
- g?.type && /* @__PURE__ */ t("span", { className: "chunk-badge", children: g.type }),
1749
- g?.status && /* @__PURE__ */ t("span", { className: "chunk-badge chunk-status", children: g.status }),
1750
- !e.explicit && /* @__PURE__ */ t("span", { className: "path-implicit", title: "Implicit directory (no stored entry)", children: "implicit" })
2183
+ /* @__PURE__ */ a("span", { className: "path-kind-icon", "aria-hidden": !0, children: Sn[t.kind] ?? "•" }),
2184
+ /* @__PURE__ */ a("span", { className: "path-name", children: t.name }),
2185
+ h?.type && /* @__PURE__ */ a("span", { className: "chunk-badge", children: h.type }),
2186
+ h?.status && /* @__PURE__ */ a("span", { className: "chunk-badge chunk-status", children: h.status })
1751
2187
  ]
1752
2188
  }
1753
2189
  )
1754
2190
  ] }),
1755
- c && s && /* @__PURE__ */ t("ul", { className: "children path-children", children: e.children.map((k) => /* @__PURE__ */ t(
1756
- Ge,
1757
- {
1758
- node: k,
1759
- expanded: r,
1760
- toggle: n,
1761
- selectedPath: a,
1762
- onSelect: o,
1763
- summaries: i
1764
- },
1765
- k.fullPath
1766
- )) })
2191
+ f && /* @__PURE__ */ c("ul", { className: "children path-children", children: [
2192
+ t.children.map((S) => /* @__PURE__ */ a(Nt, { ...e, node: S }, S.fullPath)),
2193
+ /* @__PURE__ */ a(kt, { ...e, dir: t.fullPath, listing: t.listing })
2194
+ ] })
1767
2195
  ] });
1768
2196
  }
1769
- const $e = /^[A-Za-z0-9._-]+$/;
1770
- function Le(e, r) {
1771
- return `${e}/${r}`;
2197
+ const tt = /^[A-Za-z0-9._-]+$/;
2198
+ function nt(e, t) {
2199
+ return `${e}/${t}`;
1772
2200
  }
1773
- function He(e, r) {
2201
+ function wt(e, t) {
1774
2202
  for (const n of e) {
1775
- if (n.fullPath === r) return n;
1776
- const a = He(n.children, r);
1777
- if (a) return a;
2203
+ if (n.fullPath === t) return n;
2204
+ const r = wt(n.children, t);
2205
+ if (r) return r;
1778
2206
  }
1779
2207
  }
1780
- function Jt(e) {
1781
- const { theme: r, defaultScope: n, path: a, onPathChange: o, browse: i, principal: c, renderAssistant: s, onError: d } = e, g = Pe(e);
1782
- return /* @__PURE__ */ t(Ae, { theme: r, dataLayer: g, children: /* @__PURE__ */ t(
1783
- Bt,
2208
+ function An(e) {
2209
+ const { theme: t, defaultScope: n, path: r, onPathChange: o, browse: s, principal: i, renderAssistant: l, onError: f } = e, d = st(e);
2210
+ return /* @__PURE__ */ a(it, { theme: t, dataLayer: d, children: /* @__PURE__ */ a(
2211
+ $n,
1784
2212
  {
1785
2213
  defaultScope: n,
1786
- path: a,
2214
+ path: r,
1787
2215
  onPathChange: o,
1788
- browse: i,
1789
- principal: c,
1790
- renderAssistant: s,
1791
- onError: d
2216
+ browse: s,
2217
+ principal: i,
2218
+ renderAssistant: l,
2219
+ onError: f
1792
2220
  }
1793
2221
  ) });
1794
2222
  }
1795
- function Bt({
2223
+ function $n({
1796
2224
  defaultScope: e,
1797
- path: r,
2225
+ path: t,
1798
2226
  onPathChange: n,
1799
- browse: a,
2227
+ browse: r,
1800
2228
  principal: o,
1801
- renderAssistant: i,
1802
- onError: c
2229
+ renderAssistant: s,
2230
+ onError: i
1803
2231
  }) {
1804
- const s = ae(), [d, g] = f(e ?? "user"), [m, k] = f([]), [h, P] = f(void 0), [C, L] = f(null), [F, O] = f(!1), [A, M] = f(null), I = r !== void 0 ? r : h, $ = ne(n);
1805
- B(() => {
1806
- $.current = n;
2232
+ const l = be(), [f, d] = p(e ?? "user"), [h, w] = p(void 0), [S, g] = p(null), [N, y] = p(null), [j, B] = p(() => /* @__PURE__ */ new Set()), O = t !== void 0 ? t : h, W = te(n);
2233
+ H(() => {
2234
+ W.current = n;
1807
2235
  }, [n]);
1808
- const G = ne(c);
1809
- B(() => {
1810
- G.current = c;
1811
- }, [c]);
1812
- const R = j((x) => {
1813
- $.current?.(x), P(x);
1814
- }, []), y = q(
1815
- () => a && (a.scopeId || a.tenant) ? { scopeId: a.scopeId, tenant: a.tenant } : void 0,
1816
- [a?.scopeId, a?.tenant]
1817
- ), D = j(async () => {
1818
- O(!0), L(null);
1819
- try {
1820
- const x = await s.pathLs("/", d, !0, y);
1821
- k(x.entries ?? []);
1822
- } catch (x) {
1823
- L(x instanceof Error ? x.message : String(x)), k([]), G.current?.(x);
1824
- } finally {
1825
- O(!1);
1826
- }
1827
- }, [s, d, y]), J = ne(!0);
1828
- B(() => {
1829
- J.current ? J.current = !1 : R(void 0), D();
1830
- }, [D, R]);
1831
- const V = q(() => At(m), [m]), [N, b] = f(() => /* @__PURE__ */ new Map());
1832
- B(() => {
1833
- if (d === "tenant") {
1834
- b(/* @__PURE__ */ new Map());
1835
- return;
1836
- }
1837
- const x = m.filter((W) => W.kind === "document").map((W) => W.resource_ref?.document_id).filter((W) => !!W);
1838
- if (x.length === 0) {
1839
- b(/* @__PURE__ */ new Map());
1840
- return;
1841
- }
1842
- let H = !1;
1843
- return s.documentsSummary({ documentIds: x }, d, y).then((W) => {
1844
- if (H) return;
1845
- const Q = /* @__PURE__ */ new Map();
1846
- for (const z of W.documents ?? []) Q.set(z.document_id, z);
1847
- b(Q);
1848
- }).catch(() => {
1849
- H || b(/* @__PURE__ */ new Map());
1850
- }), () => {
1851
- H = !0;
2236
+ const q = te(i);
2237
+ H(() => {
2238
+ q.current = i;
2239
+ }, [i]);
2240
+ const [I, V] = p([]), z = te(0), Z = te(void 0), _ = P((k) => {
2241
+ Z.current = k, W.current?.(k), w(k);
2242
+ }, []), R = P(
2243
+ (k) => {
2244
+ z.current++, V(($) => $.length > 0 ? [] : $), _(k);
2245
+ },
2246
+ [_]
2247
+ );
2248
+ H(() => {
2249
+ t === void 0 || t === Z.current || (z.current++, V((k) => k.length > 0 ? [] : k));
2250
+ }, [t]);
2251
+ const E = X(
2252
+ () => r && (r.scopeId || r.tenant) ? { scopeId: r.scopeId, tenant: r.tenant } : void 0,
2253
+ [r?.scopeId, r?.tenant]
2254
+ ), m = X(() => new Bt(l, f, E), [l, f, E]), b = Mt(m.subscribe, m.getSnapshot), C = P((k) => {
2255
+ q.current?.(k);
2256
+ }, []), [x, U] = p(() => /* @__PURE__ */ new Map()), M = te(/* @__PURE__ */ new Set()), ne = te(0), de = P(() => {
2257
+ ne.current++, M.current = /* @__PURE__ */ new Set(), U(/* @__PURE__ */ new Map());
2258
+ }, []), we = te(!0);
2259
+ H(() => {
2260
+ we.current ? we.current = !1 : (R(void 0), g(null), B(/* @__PURE__ */ new Set()), de()), m.loadDir("").catch(C);
2261
+ }, [m, R, de, C]), H(() => {
2262
+ for (const k of j)
2263
+ b.has(k) || m.loadDir(k).catch(C);
2264
+ }, [m, j, b, C]);
2265
+ const ve = te(null);
2266
+ H(() => {
2267
+ const k = ve.current !== null && ve.current !== m;
2268
+ if (ve.current = m, !O || k) return;
2269
+ const $ = ot(O).filter((L) => L !== "");
2270
+ B((L) => {
2271
+ if ($.every((ae) => L.has(ae))) return L;
2272
+ const G = new Set(L);
2273
+ return $.forEach((ae) => G.add(ae)), G;
2274
+ }), m.reveal(O).catch(C);
2275
+ }, [m, O, C]), H(() => {
2276
+ if (f === "tenant") return;
2277
+ const k = [];
2278
+ for (const L of b.values())
2279
+ for (const G of Ze(L.entries))
2280
+ M.current.has(G) || (M.current.add(G), k.push(G));
2281
+ const $ = ne.current;
2282
+ for (let L = 0; L < k.length; L += Oe)
2283
+ l.documentsSummary({ documentIds: k.slice(L, L + Oe) }, f, E).then((G) => {
2284
+ ne.current === $ && U((ae) => {
2285
+ const le = new Map(ae);
2286
+ for (const ye of G.documents ?? []) le.set(ye.document_id, ye);
2287
+ return le;
2288
+ });
2289
+ }).catch(() => {
2290
+ });
2291
+ }, [l, b, f, E]);
2292
+ const me = X(() => vt(b), [b]), Ce = P(async () => {
2293
+ g(null), de(), await m.refresh(j).catch(C), O && await m.reveal(O).catch(C);
2294
+ }, [m, j, O, de, C]), ue = P((k) => {
2295
+ B(($) => {
2296
+ const L = new Set($);
2297
+ return L.has(k) ? L.delete(k) : L.add(k), L;
2298
+ });
2299
+ }, []), Le = P((k) => m.loadMore(k).catch(C), [m, C]), _e = P(
2300
+ (k) => {
2301
+ (m.getSnapshot().get(k)?.loaded ? m.loadMore(k) : m.loadDir(k)).catch(C);
2302
+ },
2303
+ [m, C]
2304
+ ), D = X(
2305
+ () => O ? wt(me, O) : void 0,
2306
+ [me, O]
2307
+ ), Y = b.get("")?.error, ce = D?.kind === "directory" ? D.fullPath : void 0, [fe, Se] = p(null);
2308
+ H(() => {
2309
+ if (!ce || !l.pathIsStored) return;
2310
+ let k = !1;
2311
+ return l.pathIsStored(ce, f, E).then(
2312
+ ($) => {
2313
+ k || Se({ path: ce, explicit: $ });
2314
+ },
2315
+ () => {
2316
+ }
2317
+ ), () => {
2318
+ k = !0;
1852
2319
  };
1853
- }, [s, m, d, y]);
1854
- const p = q(
1855
- () => I ? He(V, I) : void 0,
1856
- [V, I]
1857
- ), w = q(() => p ? p.kind === "directory" ? p.fullPath : ve(p.fullPath) : "", [p]), S = w || "/", T = d !== "tenant", ee = j(() => {
1858
- M({
1859
- title: `New folder in ${S}`,
2320
+ }, [l, ce, f, E]);
2321
+ const pe = D ? D.kind !== "directory" ? "yes" : fe?.path === D.fullPath ? fe.explicit ? "yes" : "implicit (no entry)" : void 0 : void 0, oe = X(() => D ? D.kind === "directory" ? D.fullPath : jt(D.fullPath) : "", [D]), F = oe || "/", ke = f !== "tenant", Ee = P(() => {
2322
+ y({
2323
+ title: `New folder in ${F}`,
1860
2324
  fields: [{ key: "name", label: "Folder name", placeholder: "e.g. launches" }],
1861
2325
  submitLabel: "Create",
1862
- onSubmit: async (x) => {
1863
- const H = x.name.trim();
1864
- if (!$e.test(H)) throw new Error("name may contain only [A-Za-z0-9._-]");
1865
- const W = Le(w, H);
1866
- await s.pathMkdir(W, d, y), await D(), R(W);
2326
+ onSubmit: async (k) => {
2327
+ const $ = k.name.trim();
2328
+ if (!tt.test($)) throw new Error("name may contain only [A-Za-z0-9._-]");
2329
+ const L = nt(oe, $);
2330
+ await l.pathMkdir(L, f, E), await m.invalidate(L).catch(C), R(L);
1867
2331
  }
1868
2332
  });
1869
- }, [s, w, S, d, y, D, R]), oe = j(() => {
1870
- M({
1871
- title: `New document in ${S}`,
2333
+ }, [l, m, oe, F, f, E, C, R]), Ne = P(() => {
2334
+ y({
2335
+ title: `New document in ${F}`,
1872
2336
  fields: [
1873
2337
  { key: "name", label: "Path name", placeholder: "e.g. launch-plan" },
1874
2338
  { key: "title", label: "Title", placeholder: "e.g. Launch Plan" }
1875
2339
  ],
1876
2340
  submitLabel: "Create",
1877
- onSubmit: async (x) => {
1878
- const H = x.name.trim();
1879
- if (!$e.test(H)) throw new Error("name may contain only [A-Za-z0-9._-]");
1880
- const W = x.title.trim() || H, Q = Le(w, H);
1881
- await s.documentCreate(W, Q, d, y), await D(), R(Q);
2341
+ onSubmit: async (k) => {
2342
+ const $ = k.name.trim();
2343
+ if (!tt.test($)) throw new Error("name may contain only [A-Za-z0-9._-]");
2344
+ const L = k.title.trim() || $, G = nt(oe, $);
2345
+ await l.documentCreate(L, G, f, E), await m.invalidate(G).catch(C), R(G);
1882
2346
  }
1883
2347
  });
1884
- }, [s, w, S, d, y, D, R]), ce = j(() => {
1885
- p && M({
1886
- title: `Rename / move ${p.fullPath}`,
1887
- fields: [{ key: "to", label: "New path", value: p.fullPath }],
2348
+ }, [l, m, oe, F, f, E, C, R]), se = P(() => {
2349
+ D && y({
2350
+ title: `Rename / move ${D.fullPath}`,
2351
+ fields: [{ key: "to", label: "New path", value: D.fullPath }],
1888
2352
  submitLabel: "Move",
1889
- onSubmit: async (x) => {
1890
- const H = x.to.trim();
1891
- if (!H.startsWith("/")) throw new Error("path must start with /");
1892
- await s.pathMv(p.fullPath, H, d, y), await D(), R(H);
2353
+ onSubmit: async (k) => {
2354
+ const $ = k.to.trim();
2355
+ if (!$.startsWith("/")) throw new Error("path must start with /");
2356
+ await l.pathMv(D.fullPath, $, f, E), await Promise.all([
2357
+ m.invalidate(D.fullPath, { dropSubtree: !0 }),
2358
+ m.invalidate($)
2359
+ ]).catch(C), R($);
1893
2360
  }
1894
2361
  });
1895
- }, [s, p, d, y, D, R]), Z = j(() => {
1896
- if (!p) return;
1897
- if (p.kind === "document") {
1898
- const Q = p.resourceRef?.document_id;
1899
- M({
1900
- title: `Delete document ${p.fullPath}`,
2362
+ }, [l, m, D, f, E, C, R]), re = P(() => {
2363
+ if (!D) return;
2364
+ if (D.kind === "document") {
2365
+ const L = D.resourceRef?.document_id;
2366
+ y({
2367
+ title: `Delete document ${D.fullPath}`,
1901
2368
  message: "This deletes the document, all its chunks, and its path entry. This cannot be undone.",
1902
2369
  fields: [],
1903
2370
  submitLabel: "Delete",
1904
2371
  danger: !0,
1905
2372
  onSubmit: async () => {
1906
- if (!Q) throw new Error("this document dirent has no document_id");
1907
- await s.documentDelete(Q, d, y), await D(), R(void 0);
2373
+ if (!L) throw new Error("this document dirent has no document_id");
2374
+ await l.documentDelete(L, f, E), await m.invalidate(D.fullPath).catch(C), R(void 0);
1908
2375
  }
1909
2376
  });
1910
2377
  return;
1911
2378
  }
1912
- const x = d === "tenant" ? [] : Ut(p), H = p.children.length;
1913
- M({
1914
- title: `Delete branch ${p.fullPath}`,
1915
- message: H === 0 ? "This removes the (empty) folder." : "This removes the folder and everything under it" + (x.length > 0 ? ` — including ${x.length} document(s), whose chunks are deleted.` : "."),
1916
- fields: [],
1917
- submitLabel: "Delete",
1918
- danger: !0,
1919
- onSubmit: async () => {
1920
- for (const W of x)
1921
- await s.documentDelete(W, d, y);
1922
- await s.pathRm(p.fullPath, d, !0, y), await D(), R(void 0);
2379
+ const k = D;
2380
+ g(null), (async () => {
2381
+ let $;
2382
+ try {
2383
+ $ = await Ft(l, k.fullPath, f, E);
2384
+ } catch (G) {
2385
+ g(`could not list ${k.fullPath} for delete: ${G instanceof Error ? G.message : String(G)}`);
2386
+ return;
1923
2387
  }
1924
- });
1925
- }, [s, p, d, y, D, R]), re = p && (p.kind === "directory" || p.kind === "document");
1926
- return /* @__PURE__ */ l(Y, { children: [
1927
- /* @__PURE__ */ l(
1928
- dt,
2388
+ const L = f === "tenant" ? [] : Ze($);
2389
+ y({
2390
+ title: `Delete branch ${k.fullPath}`,
2391
+ message: $.length === 0 ? "This removes the (empty) folder." : "This removes the folder and everything under it" + (L.length > 0 ? ` — including ${L.length} document(s), whose chunks are deleted.` : "."),
2392
+ fields: [],
2393
+ submitLabel: "Delete",
2394
+ danger: !0,
2395
+ onSubmit: async () => {
2396
+ for (const G of L)
2397
+ await l.documentDelete(G, f, E);
2398
+ await l.pathRm(k.fullPath, f, !0, E), await m.invalidate(k.fullPath, { dropSubtree: !0 }).catch(C), R(void 0);
2399
+ }
2400
+ });
2401
+ })();
2402
+ }, [l, m, D, f, E, C, R]), K = D && (D.kind === "directory" || D.kind === "document"), ee = X(() => {
2403
+ if (I.length > 0) return I[I.length - 1];
2404
+ if (D?.kind === "document")
2405
+ return {
2406
+ documentId: D.resourceRef?.document_id ?? "",
2407
+ path: D.fullPath,
2408
+ title: D.name
2409
+ };
2410
+ }, [I, D]), ge = P(
2411
+ (k, $) => {
2412
+ const L = ++z.current, G = zt(m.getSnapshot(), k.documentId);
2413
+ V(ct(I, { ...$, path: ee?.path }, { ...k, path: G })), _(G), !(G || !l.documentPath) && l.documentPath(k.documentId, f, E).then(
2414
+ (ae) => {
2415
+ !ae || z.current !== L || (V((le) => je(le, k.documentId, { path: ae })), _(ae));
2416
+ },
2417
+ () => {
2418
+ }
2419
+ // best-effort: the document is already open by id
2420
+ );
2421
+ },
2422
+ [l, m, I, ee?.path, f, E, _]
2423
+ ), Me = P(
2424
+ (k) => {
2425
+ const $ = lt(I, k);
2426
+ $ !== I && (z.current++, V($), _($[$.length - 1].path));
2427
+ },
2428
+ [I, _]
2429
+ ), Re = P(
2430
+ (k, $) => V((L) => je(L, k, { title: $ })),
2431
+ []
2432
+ ), Pe = !!ee?.path && D?.kind === "document" && D.fullPath === ee.path;
2433
+ return /* @__PURE__ */ c(Q, { children: [
2434
+ /* @__PURE__ */ c(
2435
+ Zt,
1929
2436
  {
1930
2437
  className: "paths-view",
1931
2438
  defaultLeftWidth: 420,
@@ -1933,164 +2440,220 @@ function Bt({
1933
2440
  minRightWidth: 300,
1934
2441
  storageKey: "loomcycle.explorer.split.paths",
1935
2442
  children: [
1936
- /* @__PURE__ */ l("div", { className: "left", children: [
1937
- /* @__PURE__ */ l("div", { className: "paths-toolbar", children: [
1938
- /* @__PURE__ */ l("label", { className: "paths-scope", children: [
1939
- /* @__PURE__ */ t("span", { children: "scope" }),
1940
- /* @__PURE__ */ l("select", { value: d, onChange: (x) => g(x.target.value), children: [
1941
- /* @__PURE__ */ t("option", { value: "user", children: "user" }),
1942
- /* @__PURE__ */ t("option", { value: "agent", children: "agent" }),
1943
- /* @__PURE__ */ t("option", { value: "tenant", children: "tenant" })
2443
+ /* @__PURE__ */ c("div", { className: "left", children: [
2444
+ /* @__PURE__ */ c("div", { className: "paths-toolbar", children: [
2445
+ /* @__PURE__ */ c("label", { className: "paths-scope", children: [
2446
+ /* @__PURE__ */ a("span", { children: "scope" }),
2447
+ /* @__PURE__ */ c("select", { value: f, onChange: (k) => d(k.target.value), children: [
2448
+ /* @__PURE__ */ a("option", { value: "user", children: "user" }),
2449
+ /* @__PURE__ */ a("option", { value: "agent", children: "agent" }),
2450
+ /* @__PURE__ */ a("option", { value: "tenant", children: "tenant" })
1944
2451
  ] })
1945
2452
  ] }),
1946
- /* @__PURE__ */ l("div", { className: "paths-toolbar-actions", children: [
1947
- /* @__PURE__ */ t("button", { type: "button", onClick: ee, title: `New folder in ${S}`, children: "+ folder" }),
1948
- /* @__PURE__ */ t(
2453
+ /* @__PURE__ */ c("div", { className: "paths-toolbar-actions", children: [
2454
+ /* @__PURE__ */ a("button", { type: "button", onClick: Ee, title: `New folder in ${F}`, children: "+ folder" }),
2455
+ /* @__PURE__ */ a(
1949
2456
  "button",
1950
2457
  {
1951
2458
  type: "button",
1952
- onClick: oe,
1953
- disabled: !T,
1954
- title: T ? `New document in ${S}` : "Documents are agent/user scope only",
2459
+ onClick: Ne,
2460
+ disabled: !ke,
2461
+ title: ke ? `New document in ${F}` : "Documents are agent/user scope only",
1955
2462
  children: "+ document"
1956
2463
  }
1957
2464
  ),
1958
- /* @__PURE__ */ t("button", { type: "button", onClick: () => {
1959
- D();
2465
+ /* @__PURE__ */ a("button", { type: "button", onClick: () => {
2466
+ Ce();
1960
2467
  }, title: "Reload the tree", children: "↻" })
1961
2468
  ] })
1962
2469
  ] }),
1963
- /* @__PURE__ */ l("p", { className: "paths-context", children: [
2470
+ /* @__PURE__ */ c("p", { className: "paths-context", children: [
1964
2471
  "new items → ",
1965
- /* @__PURE__ */ t("code", { children: S }),
1966
- y?.scopeId && /* @__PURE__ */ l(Y, { children: [
2472
+ /* @__PURE__ */ a("code", { children: F }),
2473
+ E?.scopeId && /* @__PURE__ */ c(Q, { children: [
1967
2474
  " · ",
1968
2475
  "subject ",
1969
- /* @__PURE__ */ t("code", { children: y.scopeId })
2476
+ /* @__PURE__ */ a("code", { children: E.scopeId })
1970
2477
  ] }),
1971
- y?.tenant && /* @__PURE__ */ l(Y, { children: [
2478
+ E?.tenant && /* @__PURE__ */ c(Q, { children: [
1972
2479
  " · ",
1973
2480
  "tenant ",
1974
- /* @__PURE__ */ t("code", { children: y.tenant })
2481
+ /* @__PURE__ */ a("code", { children: E.tenant })
1975
2482
  ] })
1976
2483
  ] }),
1977
- C && /* @__PURE__ */ t("div", { className: "paths-err", children: C }),
1978
- F && m.length === 0 ? /* @__PURE__ */ t("div", { className: "empty", children: /* @__PURE__ */ t("p", { children: "Loading…" }) }) : /* @__PURE__ */ t(
1979
- It,
2484
+ (S || Y) && /* @__PURE__ */ a("div", { className: "paths-err", children: S || Y }),
2485
+ /* @__PURE__ */ a(
2486
+ En,
1980
2487
  {
1981
- tree: V,
1982
- selectedPath: I,
1983
- onSelect: (x) => R(x.fullPath),
1984
- summaries: N
2488
+ tree: me,
2489
+ root: b.get(""),
2490
+ expanded: j,
2491
+ onToggle: ue,
2492
+ onLoadMore: Le,
2493
+ onRetry: _e,
2494
+ selectedPath: O,
2495
+ onSelect: (k) => R(k.fullPath),
2496
+ summaries: x
1985
2497
  }
1986
2498
  )
1987
2499
  ] }),
1988
- /* @__PURE__ */ t("div", { className: "right", children: p ? p.kind === "document" ? /* @__PURE__ */ l("div", { className: "paths-doc", children: [
1989
- /* @__PURE__ */ l("div", { className: "paths-doc-head", children: [
1990
- /* @__PURE__ */ t("code", { className: "paths-doc-path", children: p.fullPath }),
1991
- /* @__PURE__ */ l("div", { className: "paths-detail-actions", children: [
1992
- /* @__PURE__ */ t("button", { type: "button", onClick: ce, children: "rename / move" }),
1993
- /* @__PURE__ */ t("button", { type: "button", className: "danger", onClick: Z, children: "delete" })
2500
+ /* @__PURE__ */ a("div", { className: "right", children: ee ? /* @__PURE__ */ c("div", { className: "paths-doc", children: [
2501
+ /* @__PURE__ */ a(ut, { trail: I, onJump: Me }),
2502
+ /* @__PURE__ */ c("div", { className: "paths-doc-head", children: [
2503
+ ee.path ? /* @__PURE__ */ a("code", { className: "paths-doc-path", children: ee.path }) : /* @__PURE__ */ c(
2504
+ "span",
2505
+ {
2506
+ className: "paths-doc-path paths-doc-unfiled",
2507
+ title: "Opened by id — no entry for this document was found in the Path tree",
2508
+ children: [
2509
+ he(ee),
2510
+ " ",
2511
+ /* @__PURE__ */ a("em", { children: "· opened by id, not in the tree" })
2512
+ ]
2513
+ }
2514
+ ),
2515
+ Pe && /* @__PURE__ */ c("div", { className: "paths-detail-actions", children: [
2516
+ /* @__PURE__ */ a("button", { type: "button", onClick: se, children: "rename / move" }),
2517
+ /* @__PURE__ */ a("button", { type: "button", className: "danger", onClick: re, children: "delete" })
1994
2518
  ] })
1995
2519
  ] }),
1996
- /* @__PURE__ */ t(
1997
- Fe,
2520
+ /* @__PURE__ */ a(
2521
+ bt,
1998
2522
  {
1999
- documentId: p.resourceRef?.document_id ?? "",
2000
- scope: d,
2001
- titleHint: p.name,
2002
- browse: y,
2523
+ documentId: ee.documentId,
2524
+ scope: f,
2525
+ titleHint: ee.title,
2526
+ browse: E,
2003
2527
  principal: o,
2004
- renderAssistant: i
2005
- }
2528
+ renderAssistant: s,
2529
+ initialChunkId: ee.chunkId,
2530
+ onOpenDocument: ge,
2531
+ onTitle: Re
2532
+ },
2533
+ I.length
2006
2534
  )
2007
- ] }) : /* @__PURE__ */ l("div", { className: "paths-detail", children: [
2008
- /* @__PURE__ */ l("h2", { children: [
2009
- /* @__PURE__ */ t("span", { className: "paths-detail-kind", children: p.kind }),
2010
- /* @__PURE__ */ t("code", { children: p.fullPath })
2535
+ ] }) : D ? /* @__PURE__ */ c("div", { className: "paths-detail", children: [
2536
+ /* @__PURE__ */ c("h2", { children: [
2537
+ /* @__PURE__ */ a("span", { className: "paths-detail-kind", children: D.kind }),
2538
+ /* @__PURE__ */ a("code", { children: D.fullPath })
2011
2539
  ] }),
2012
- /* @__PURE__ */ l("dl", { className: "paths-detail-meta", children: [
2013
- /* @__PURE__ */ t("dt", { children: "scope" }),
2014
- /* @__PURE__ */ t("dd", { children: d }),
2015
- /* @__PURE__ */ t("dt", { children: "stored" }),
2016
- /* @__PURE__ */ t("dd", { children: p.explicit ? "yes" : "implicit (no entry)" })
2540
+ /* @__PURE__ */ c("dl", { className: "paths-detail-meta", children: [
2541
+ /* @__PURE__ */ a("dt", { children: "scope" }),
2542
+ /* @__PURE__ */ a("dd", { children: f }),
2543
+ pe && /* @__PURE__ */ c(Q, { children: [
2544
+ /* @__PURE__ */ a("dt", { children: "stored" }),
2545
+ /* @__PURE__ */ a("dd", { children: pe })
2546
+ ] })
2017
2547
  ] }),
2018
- re ? /* @__PURE__ */ l("div", { className: "paths-detail-actions", children: [
2019
- /* @__PURE__ */ t("button", { type: "button", onClick: ce, children: "rename / move" }),
2020
- /* @__PURE__ */ t("button", { type: "button", className: "danger", onClick: Z, children: "delete" })
2021
- ] }) : /* @__PURE__ */ l("p", { className: "paths-readonly", children: [
2548
+ K ? /* @__PURE__ */ c("div", { className: "paths-detail-actions", children: [
2549
+ /* @__PURE__ */ a("button", { type: "button", onClick: se, children: "rename / move" }),
2550
+ /* @__PURE__ */ a("button", { type: "button", className: "danger", onClick: re, children: "delete" })
2551
+ ] }) : /* @__PURE__ */ c("p", { className: "paths-readonly", children: [
2022
2552
  "Read-only — ",
2023
- p.kind,
2553
+ D.kind,
2024
2554
  " entries are managed by their own tool."
2025
2555
  ] })
2026
- ] }) : /* @__PURE__ */ t("div", { className: "empty", children: /* @__PURE__ */ t("p", { children: "Select a path on the left, or create a folder / document." }) }) })
2556
+ ] }) : /* @__PURE__ */ a("div", { className: "empty", children: /* @__PURE__ */ a("p", { children: "Select a path on the left, or create a folder / document." }) }) })
2027
2557
  ]
2028
2558
  }
2029
2559
  ),
2030
- A && /* @__PURE__ */ t(Ft, { state: A, onClose: () => M(null) })
2560
+ N && /* @__PURE__ */ a(Dn, { state: N, onClose: () => y(null) })
2031
2561
  ] });
2032
2562
  }
2033
- function Ft({ state: e, onClose: r }) {
2034
- const [n, a] = f(
2035
- () => Object.fromEntries(e.fields.map((g) => [g.key, g.value ?? ""]))
2036
- ), [o, i] = f(!1), [c, s] = f(null);
2037
- return /* @__PURE__ */ t("div", { className: "modal-overlay", onClick: r, children: /* @__PURE__ */ l("form", { className: "modal", onClick: (g) => g.stopPropagation(), onSubmit: async (g) => {
2038
- g.preventDefault(), i(!0), s(null);
2563
+ function Dn({ state: e, onClose: t }) {
2564
+ const [n, r] = p(
2565
+ () => Object.fromEntries(e.fields.map((d) => [d.key, d.value ?? ""]))
2566
+ ), [o, s] = p(!1), [i, l] = p(null);
2567
+ return /* @__PURE__ */ a("div", { className: "modal-overlay", onClick: t, children: /* @__PURE__ */ c("form", { className: "modal", onClick: (d) => d.stopPropagation(), onSubmit: async (d) => {
2568
+ d.preventDefault(), s(!0), l(null);
2039
2569
  try {
2040
- await e.onSubmit(n), r();
2041
- } catch (m) {
2042
- s(m instanceof Error ? m.message : String(m)), i(!1);
2570
+ await e.onSubmit(n), t();
2571
+ } catch (h) {
2572
+ l(h instanceof Error ? h.message : String(h)), s(!1);
2043
2573
  }
2044
2574
  }, children: [
2045
- /* @__PURE__ */ l("div", { className: "modal-header sticky-top", children: [
2046
- /* @__PURE__ */ t("h3", { children: e.title }),
2047
- /* @__PURE__ */ l("div", { className: "modal-buttons modal-buttons-top", children: [
2048
- /* @__PURE__ */ t("button", { type: "button", onClick: r, disabled: o, children: "cancel" }),
2049
- /* @__PURE__ */ t("button", { type: "submit", className: e.danger ? "danger" : "primary", disabled: o, children: o ? "working…" : e.submitLabel })
2575
+ /* @__PURE__ */ c("div", { className: "modal-header sticky-top", children: [
2576
+ /* @__PURE__ */ a("h3", { children: e.title }),
2577
+ /* @__PURE__ */ c("div", { className: "modal-buttons modal-buttons-top", children: [
2578
+ /* @__PURE__ */ a("button", { type: "button", onClick: t, disabled: o, children: "cancel" }),
2579
+ /* @__PURE__ */ a("button", { type: "submit", className: e.danger ? "danger" : "primary", disabled: o, children: o ? "working…" : e.submitLabel })
2050
2580
  ] })
2051
2581
  ] }),
2052
- e.message && /* @__PURE__ */ t("p", { className: "modal-context", children: e.message }),
2053
- e.fields.map((g, m) => /* @__PURE__ */ l("label", { className: "path-field", children: [
2054
- /* @__PURE__ */ t("span", { children: g.label }),
2055
- /* @__PURE__ */ t(
2582
+ e.message && /* @__PURE__ */ a("p", { className: "modal-context", children: e.message }),
2583
+ e.fields.map((d, h) => /* @__PURE__ */ c("label", { className: "path-field", children: [
2584
+ /* @__PURE__ */ a("span", { children: d.label }),
2585
+ /* @__PURE__ */ a(
2056
2586
  "input",
2057
2587
  {
2058
2588
  className: "path-modal-input",
2059
- value: n[g.key],
2060
- placeholder: g.placeholder,
2061
- autoFocus: m === 0,
2062
- onChange: (k) => a((h) => ({ ...h, [g.key]: k.target.value }))
2589
+ value: n[d.key],
2590
+ placeholder: d.placeholder,
2591
+ autoFocus: h === 0,
2592
+ onChange: (w) => r((S) => ({ ...S, [d.key]: w.target.value }))
2063
2593
  }
2064
2594
  )
2065
- ] }, g.key)),
2066
- c && /* @__PURE__ */ t("div", { className: "modal-err", children: c })
2595
+ ] }, d.key)),
2596
+ i && /* @__PURE__ */ a("div", { className: "modal-err", children: i })
2067
2597
  ] }) });
2068
2598
  }
2069
- function Zt(e) {
2070
- const { documentId: r, scope: n, titleHint: a, browse: o, theme: i, principal: c, renderAssistant: s } = e, d = Pe(e);
2071
- return /* @__PURE__ */ t(Ae, { theme: i, dataLayer: d, children: /* @__PURE__ */ t(
2072
- Fe,
2599
+ function On(e) {
2600
+ const { documentId: t, scope: n, browse: r, theme: o } = e, s = st(e);
2601
+ return /* @__PURE__ */ a(it, { theme: o, dataLayer: s, children: /* @__PURE__ */ a(
2602
+ Tn,
2073
2603
  {
2074
- documentId: r,
2075
- scope: n,
2076
- titleHint: a,
2077
- browse: o,
2078
- principal: c,
2079
- renderAssistant: s
2080
- }
2604
+ ...e
2605
+ },
2606
+ `${n}:${t}:${r?.scopeId ?? ""}:${r?.tenant ?? ""}`
2081
2607
  ) });
2082
2608
  }
2609
+ function Tn({
2610
+ documentId: e,
2611
+ scope: t,
2612
+ titleHint: n,
2613
+ browse: r,
2614
+ principal: o,
2615
+ renderAssistant: s,
2616
+ onOpenDocument: i
2617
+ }) {
2618
+ const [l, f] = p([]), d = l[l.length - 1], h = P(
2619
+ (g, N) => {
2620
+ i ? i(g, N) : f((y) => ct(y, N, g));
2621
+ },
2622
+ [i]
2623
+ ), w = P((g) => f((N) => lt(N, g)), []), S = P(
2624
+ (g, N) => f((y) => je(y, g, { title: N })),
2625
+ []
2626
+ );
2627
+ return /* @__PURE__ */ c(Q, { children: [
2628
+ /* @__PURE__ */ a(ut, { trail: l, onJump: w }),
2629
+ /* @__PURE__ */ a(
2630
+ bt,
2631
+ {
2632
+ documentId: d?.documentId ?? e,
2633
+ scope: t,
2634
+ titleHint: d ? d.title : n,
2635
+ browse: r,
2636
+ principal: o,
2637
+ renderAssistant: s,
2638
+ initialChunkId: d?.chunkId,
2639
+ onOpenDocument: h,
2640
+ onTitle: S
2641
+ },
2642
+ l.length
2643
+ )
2644
+ ] });
2645
+ }
2083
2646
  export {
2084
- be as DEFAULT_SCHEME,
2085
- Zt as DocumentViewer,
2086
- Jt as PathExplorer,
2087
- lt as assetFetchFromConnection,
2088
- pt as chunkColor,
2089
- st as createLoomcycleClient,
2090
- _e as dataLayerFromClient,
2091
- Ie as docColor,
2092
- ke as effectiveScheme,
2093
- ft as hexToTint,
2094
- Ne as tintStyle
2647
+ Be as DEFAULT_SCHEME,
2648
+ On as DocumentViewer,
2649
+ An as PathExplorer,
2650
+ Ht as assetFetchFromConnection,
2651
+ Kt as chunkColor,
2652
+ Gt as createLoomcycleClient,
2653
+ ze as dataLayerFromClient,
2654
+ ft as docColor,
2655
+ Ge as effectiveScheme,
2656
+ en as hexToTint,
2657
+ He as tintStyle
2095
2658
  };
2096
2659
  //# sourceMappingURL=index.js.map