@loomcycle/explorer 0.7.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 at, useContext as rt, useMemo as q, useState as f, useRef as ne, useEffect as B, useCallback as O } from "react";
3
- import { LoomcycleClient as ot } from "@loomcycle/client";
4
- import ct from "react-markdown";
5
- import it 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
19
+ ),
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
+ }
11
30
  ),
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),
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 = at(null);
176
- function st({
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 = rt(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 lt(e) {
191
- const r = e.fetch;
192
- return new ot({
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 dt(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 Ae(e) {
206
- const { dataLayer: r, client: n, connection: a } = e;
207
- return q(() => r || (n ? _e(n) : a ? _e(
208
- lt(a),
209
- dt(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 Pe({
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(st, { 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 ut({
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
- }), u = ne(null), [g, h] = f(!1);
246
- B(() => {
247
- !o || g || localStorage.setItem(o, String(Math.round(c)));
248
- }, [o, c, g]);
249
- const v = O((C) => {
250
- C.preventDefault(), h(!0), C.target.setPointerCapture(C.pointerId);
251
- }, []), m = O(
252
- (C) => {
253
- if (!g || !u.current) return;
254
- const L = u.current.getBoundingClientRect(), F = C.clientX - L.left, I = L.width - a - Se, P = Math.max(n, Math.min(F, I));
255
- s(P);
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
- ), A = O((C) => {
567
+ [d, n, r]
568
+ ), g = P((N) => {
259
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: u,
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: v,
283
- onPointerMove: m,
284
- onPointerUp: A,
285
- onPointerCancel: A
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 ht = ["image/png", "image/jpeg", "image/gif", "image/webp"];
294
- function Ue(e) {
295
- return ht.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 mt(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
- }, pt = 0.16;
347
- function ve(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 ft(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 gt(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}, ${pt})`;
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 = gt(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 yt(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 bt({
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()), u = O((h) => {
405
- s((v) => {
406
- const m = new Map(v);
407
- return m.set(h, v.get(h) === !1), m;
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 h = kt(e, r);
413
- h.length !== 0 && s((v) => {
414
- let m = !1;
415
- const A = new Map(v);
416
- for (const C of h)
417
- A.get(C) === !1 && (A.set(C, !0), m = !0);
418
- return m ? A : v;
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 ? ve(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((h) => /* @__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
764
  node: h,
426
- expanded: c,
427
- toggle: u,
428
- selectedId: r,
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
772
  h.row.id
434
773
  )) });
435
774
  }
436
- function kt(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, u = r.get(e.row.id) !== !1, g = a === e.row.id, h = i ? Ne(ft(e.row.status, i)) : void 0, v = 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: h, 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": u ? "collapse" : "expand",
457
- disabled: !s,
458
- onClick: (m) => {
459
- m.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 ? u ? "▼" : "▶" : "·"
800
+ children: l ? f ? "▼" : "▶" : "·"
462
801
  }
463
802
  ),
464
- /* @__PURE__ */ l(
803
+ /* @__PURE__ */ c(
465
804
  "button",
466
805
  {
467
806
  type: "button",
@@ -469,1491 +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
- v && /* @__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 && u && /* @__PURE__ */ t("ul", { className: "children chunk-children", children: e.children.map((m) => /* @__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: m,
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
- m.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: u } = await i.render(`lc-mmd-${vt++}`, e);
506
- o || a({ svg: u });
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 Nt({ chunk: e, scope: r, browse: n, onClose: a, onSaved: o }) {
516
- const i = ae(), [c, s] = f(e.title), [u, g] = f(e.type ?? ""), [h, v] = f(e.status ?? ""), [m, A] = 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, I] = f((e.tags ?? []).join(", ")), [P, M] = f(!1), [j, $] = f(null), [G, R] = f(!1), y = u === "mermaid", D = u === "image" || !!e.asset, [J, z] = f(m);
519
- B(() => {
520
- if (!y) return;
521
- const w = setTimeout(() => z(m), 400);
522
- return () => clearTimeout(w);
523
- }, [m, 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: m,
537
- title: c,
538
- type: u,
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,
539
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: P, children: "cancel" }),
564
- /* @__PURE__ */ t("button", { type: "submit", className: "primary", disabled: P, children: P ? "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
- j && /* @__PURE__ */ l("div", { className: "modal-err", children: [
568
- j,
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: u,
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
952
  value: h,
595
953
  placeholder: "(none)",
596
- onChange: (w) => v(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) => I(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: P,
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: m,
636
- onChange: (w) => A(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 wt(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 Ct({
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: u
1029
+ scope: s,
1030
+ browse: i,
1031
+ onClose: l,
1032
+ onSaved: f
675
1033
  }) {
676
- const g = ae(), [h, v] = f(null), [m, A] = f(!1), [C, L] = f({}), [F, I] = f(!1), [P, M] = f(null), [j, $] = 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
- v(p);
687
- const w = p.fields ?? {};
688
- A(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: m,
698
- color_scheme: C
699
- }), D = async () => {
1055
+ color_enabled: S,
1056
+ color_scheme: N
1057
+ }), _ = async () => {
700
1058
  if (h) {
701
- I(!0), $(null), M(null);
1059
+ B(!0), I(null), W(null);
702
1060
  try {
703
- await g.documentUpdateChunk(
704
- r,
1061
+ await d.documentUpdateChunk(
1062
+ t,
705
1063
  h.revision,
706
- { fields: y(h.fields) },
707
- i,
708
- c
709
- ), u(), s();
1064
+ { fields: Z(h.fields) },
1065
+ s,
1066
+ i
1067
+ ), f(), l();
710
1068
  } catch (b) {
711
- $(b instanceof Error ? b.message : String(b)), I(!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
- I(!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).`), u();
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
- I(!1);
1099
+ B(!1);
742
1100
  }
743
- }, z = 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 || !h, 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
- j && /* @__PURE__ */ t("div", { className: "modal-err", children: j }),
755
- h ? /* @__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: m,
762
- onChange: (b) => A(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
- z.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
- P && /* @__PURE__ */ t("span", { className: "scheme-status", children: P })
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 = wt(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 })
795
1153
  ] });
796
1154
  }
797
- const _t = 8, St = 20;
798
- function Et(e) {
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
+ " ↗"
1179
+ ] });
1180
+ }
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 xt({
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), [u, g] = f(!1), [h, v] = f(void 0), [m, A] = f([]), [C, L] = f([]), [F, I] = f(null), [P, M] = f([]), [j, $] = 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, _t),
816
- i.documentUnlinkedMentions(y, n, a, St)
817
- ]).then(([J, z, N]) => {
818
- if (!D) {
819
- if (A(J.status === "fulfilled" ? J.value.backlinks ?? [] : []), z.status === "fulfilled")
820
- L(z.value.related ?? []), I(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 = z.reason instanceof Error ? z.reason.message : String(z.reason);
824
- I(Et(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)), v(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 && !u && h === r) ? /* @__PURE__ */ l(Y, { children: [
847
- /* @__PURE__ */ l("div", { className: "doc-conn-group", children: [
848
- /* @__PURE__ */ t("h5", { children: "Backlinks" }),
849
- m.length === 0 ? /* @__PURE__ */ t("p", { className: "doc-conn-empty", children: "none" }) : /* @__PURE__ */ t("ul", { className: "doc-conn-list", children: m.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
- P.length === 0 ? /* @__PURE__ */ t("p", { className: "doc-conn-empty", children: "none" }) : /* @__PURE__ */ l("ul", { className: "doc-conn-list", children: [
881
- P.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
- j && /* @__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 Dt({
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 u = n ? e.filter((v) => v.from_id === n || v.to_id === n) : [], g = c ? e : e.slice(0, ye), h = Mt(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
- u.length === 0 ? /* @__PURE__ */ t("p", { className: "doc-refs-empty", children: "This chunk has no links." }) : /* @__PURE__ */ t("ul", { className: "doc-refs-list", children: u.map((v, m) => /* @__PURE__ */ t(
922
- Rt,
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: v,
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
- `${v.from_id}-${v.to_id}-${v.kind}-${m}`
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((v) => !v), 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: h }),
941
- e.length > ye && /* @__PURE__ */ t("button", { type: "button", className: "doc-graph-more", onClick: () => s((v) => !v), 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 Rt({
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, u = !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
- u ? /* @__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 Mt(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 $t(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 Lt({
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([]), [u, g] = f(!0), [h, v] = f(null), [m, A] = f("none"), [C, L] = f(null), [F, I] = f(""), [P, M] = f(!1), [j, $] = f(null), [G, R] = f(null), [y, D] = f("");
990
- B(() => {
991
- let N = !1;
992
- return g(!0), v(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 && v(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
- v(null), M(!0), L(N), A("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
- I(b.body ?? "");
1403
+ const b = await s.documentGetVersion(e, m, n, r);
1404
+ B(b.body ?? "");
1008
1405
  } catch (b) {
1009
- v(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
- }, z = async () => {
1014
- if (!(j === null || G === null)) {
1015
- v(null), M(!0), A("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, j, G, n, a);
1018
- D(N.diff ?? "");
1019
- } catch (N) {
1020
- v(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
- h && /* @__PURE__ */ t("div", { className: "modal-err", children: h }),
1035
- u ? /* @__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" + (m === "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: $t(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: j ?? "",
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
- z();
1484
+ E();
1088
1485
  },
1089
- disabled: P || j === 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: P ? /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "loading…" }) : m === "diff" ? /* @__PURE__ */ t(Tt, { text: y }) : m === "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 Tt({ 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(ct, { remarkPlugins: [it], components: At, 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 At = {
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
- ), [u, g] = f([]), [h, v] = f(void 0), [m, A] = f(null), [C, L] = f("chunks"), [F, I] = f(null), [P, M] = f(null), [j, $] = f(null), G = ne(null), [R, y] = f(null), [D, J] = f(!1), [z, 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([]), V = O(() => ee((d) => d + 1), []), he = q(() => yt(u), [u]), ie = q(() => u.find((k) => !k.parent_id)?.title || n || "document", [u, n]), te = q(
1147
- () => !!m && !m.parent_id,
1148
- [m]
1149
- ), X = q(
1150
- () => Z?.root_chunk_id ?? u.find((d) => !d.parent_id)?.id,
1151
- [Z, u]
1152
- ), We = q(
1153
- () => [...new Set(u.map((d) => d.status).filter((d) => !!d))],
1154
- [u]
1155
- ), se = !!Z?.color_enabled, Ve = q(() => {
1156
- const d = /* @__PURE__ */ new Set();
1157
- for (const k of W)
1158
- d.add(k.from_id), d.add(k.to_id);
1159
- return d;
1160
- }, [W]), ze = q(
1161
- () => se ? Ne(Ie(Z?.type, Z?.status, ve(Z?.color_scheme))) : void 0,
1162
- [se, Z?.type, Z?.status, Z?.color_scheme]
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(() => {
1560
+ const u = /* @__PURE__ */ new Set();
1561
+ for (const v of pe)
1562
+ u.add(v.from_id), u.add(v.to_id);
1563
+ return u;
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(() => {
1165
- let d = !1;
1166
- return S(!0), p(null), c.documentQueryChunks(e, r, s).then((k) => {
1167
- if (d) return;
1168
- const _ = k.chunks ?? [];
1169
- g(_), v((E) => E ?? _.find((U) => !U.parent_id)?.id);
1170
- }).catch((k) => !d && p(k instanceof Error ? k.message : String(k))).finally(() => !d && S(!1)), () => {
1171
- d = !0;
1568
+ H(() => {
1569
+ let u = !1;
1570
+ return de(!0), M(null), Ce(null), d.documentQueryChunks(e, t, h).then((v) => {
1571
+ if (u) return;
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)), () => {
1577
+ u = !0;
1172
1578
  };
1173
- }, [c, e, r, T, s]), B(() => {
1174
- let d = !1;
1175
- return c.documentGet(e, r, s).then((k) => !d && re(k)).catch(() => !d && re(null)), () => {
1176
- d = !0;
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(() => {
1587
+ let u = !1;
1588
+ return d.documentGet(e, t, h).then((v) => !u && ce(v)).catch(() => !u && ce(null)), () => {
1589
+ u = !0;
1177
1590
  };
1178
- }, [c, e, r, T, s]), B(() => {
1179
- let d = !1;
1180
- return c.documentGetEdges(e, r, s).then((k) => !d && Q(k.edges ?? [])).catch(() => !d && Q([])), () => {
1181
- d = !0;
1591
+ }, [d, e, t, ue, h]), H(() => {
1592
+ let u = !1;
1593
+ return d.documentGetEdges(e, t, h).then((v) => !u && oe(v.edges ?? [])).catch(() => !u && oe([])), () => {
1594
+ u = !0;
1182
1595
  };
1183
- }, [c, e, r, T, s]), B(() => {
1184
- v(void 0), A(null), I(null), L("chunks"), re(null), Q([]);
1185
- }, [e, r]), B(() => {
1186
- if (!h) {
1187
- A(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
- let d = !1;
1191
- return c.documentGetChunk(h, r, s).then((k) => !d && A(k)).catch((k) => !d && p(k instanceof Error ? k.message : String(k))), () => {
1192
- d = !0;
1603
+ let u = !1;
1604
+ return d.documentGetChunk(g, t, h).then((v) => !u && j(v)).catch((v) => !u && M(v instanceof Error ? v.message : String(v))), () => {
1605
+ u = !0;
1193
1606
  };
1194
- }, [c, h, r, T, s]), B(() => {
1195
- const d = m?.type === "image" || !!m?.asset;
1196
- if (!m || !d || !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 k = !1, _ = null;
1201
- return $(null), c.documentAssetObjectUrl(m.id, r, s).then((E) => {
1202
- if (k) {
1203
- URL.revokeObjectURL(E);
1613
+ let v = !1, T = null;
1614
+ return Z(null), d.documentAssetObjectUrl(y.id, t, h).then((A) => {
1615
+ if (v) {
1616
+ URL.revokeObjectURL(A);
1204
1617
  return;
1205
1618
  }
1206
- _ = E, M(E);
1207
- }).catch((E) => !k && $(E instanceof Error ? E.message : String(E))), () => {
1208
- k = !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, m, r, s]), B(() => {
1211
- if (C !== "markdown" || !h) {
1212
- I(null);
1623
+ }, [d, y, t, h]), H(() => {
1624
+ if (B !== "markdown" || !g) {
1625
+ q(null);
1213
1626
  return;
1214
1627
  }
1215
- const d = je(he, h);
1216
- if (!d) return;
1217
- let k = !1;
1218
- const _ = [], E = (U, le) => {
1219
- _.push({ node: U, depth: le }), U.children.forEach((de) => E(de, le + 1));
1628
+ const u = pt(Ne, g);
1629
+ if (!u) return;
1630
+ let v = !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(d, 0), Promise.all(_.map((U) => c.documentGetChunk(U.node.row.id, r, s))).then((U) => {
1222
- if (k) return;
1223
- const le = _.map((de, et) => {
1224
- const tt = Math.min(de.depth + 1, 6), K = U[et], fe = "#".repeat(tt) + " " + 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 nt = K.body ? " — " + K.body : "";
1229
- return fe + `
1634
+ return A(u, 0), Promise.all(T.map((J) => d.documentGetChunk(J.node.row.id, t, h))).then((J) => {
1635
+ if (v) return;
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_` + nt + `
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
- I(le);
1241
- }).catch((U) => !k && p(U instanceof Error ? U.message : String(U))), () => {
1242
- k = !0;
1653
+ q(xe);
1654
+ }).catch((J) => !v && M(J instanceof Error ? J.message : String(J))), () => {
1655
+ v = !0;
1243
1656
  };
1244
- }, [c, C, h, he, r, T, s]);
1245
- const Je = O((d) => v(d.row.id), []), Ze = O(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 d = await c.documentExportMd(e, r, !0, s), k = new Blob([d.markdown], { type: "text/markdown" }), _ = URL.createObjectURL(k), E = document.createElement("a");
1248
- E.href = _, E.download = (d.title || "document").replace(/[^\w.-]+/g, "_") + ".md", E.click(), URL.revokeObjectURL(_);
1249
- } catch (d) {
1250
- p(d instanceof Error ? d.message : String(d));
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);
1668
+ } catch (u) {
1669
+ M(u instanceof Error ? u.message : String(u));
1251
1670
  }
1252
- }, [c, e, r, s]), qe = O(async () => {
1671
+ }, [d, e, t, h]), ae = P(async () => {
1253
1672
  try {
1254
- const d = await c.documentExportCanvas(e, r, s), k = new Blob([JSON.stringify(d.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(k), E = document.createElement("a");
1257
- E.href = _, E.download = (ie || "document").replace(/[^\w.-]+/g, "_") + ".canvas", E.click(), URL.revokeObjectURL(_);
1258
- } catch (d) {
1259
- p(d instanceof Error ? d.message : String(d));
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);
1677
+ } catch (u) {
1678
+ M(u instanceof Error ? u.message : String(u));
1260
1679
  }
1261
- }, [c, e, r, s, ie]), me = !!c.documentCreateChunk && !!X, pe = O(
1262
- async (d) => {
1263
- if (!c.documentCreateChunk || !c.documentSetAsset) return;
1264
- const k = h || X;
1265
- if (k) {
1266
- p(null);
1680
+ }, [d, e, t, h, se]), le = !!d.documentCreateChunk && !!K, ye = P(
1681
+ async (u) => {
1682
+ if (!d.documentCreateChunk || !d.documentSetAsset) return;
1683
+ const v = g || K;
1684
+ if (v) {
1685
+ M(null);
1267
1686
  try {
1268
- const { mediaType: _, data: E } = await Oe(d), U = await c.documentCreateChunk(
1687
+ const { mediaType: T, data: A } = await mt(u), J = await d.documentCreateChunk(
1269
1688
  e,
1270
- k,
1271
- { title: d.name || "image", type: "image" },
1272
- r,
1273
- s
1689
+ v,
1690
+ { title: u.name || "image", type: "image" },
1691
+ t,
1692
+ h
1274
1693
  );
1275
- await c.documentSetAsset(U.id, _, E, d.name, r, s), V(), v(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, h, X, V]
1282
- ), Qe = O(async () => {
1283
- if (!c.documentCreateChunk) return;
1284
- const d = h || X;
1285
- if (d) {
1286
- p(null);
1700
+ [d, e, t, h, g, K, F]
1701
+ ), Ct = P(async () => {
1702
+ if (!d.documentCreateChunk) return;
1703
+ const u = g || K;
1704
+ if (u) {
1705
+ M(null);
1287
1706
  try {
1288
- const k = await c.documentCreateChunk(
1707
+ const v = await d.documentCreateChunk(
1289
1708
  e,
1290
- d,
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
- V(), v(k.id), y(k);
1297
- } catch (k) {
1298
- p(k instanceof Error ? k.message : String(k));
1715
+ F(), N(v.id), E(v);
1716
+ } catch (v) {
1717
+ M(v instanceof Error ? v.message : String(v));
1299
1718
  }
1300
1719
  }
1301
- }, [c, e, r, s, h, X, V]), Xe = O(async () => {
1302
- if (!c.documentCreateChunk) return;
1303
- const d = h && !te ? h : void 0, k = h || X;
1304
- if (k) {
1305
- p(null);
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;
1723
+ if (v) {
1724
+ M(null);
1306
1725
  try {
1307
- const _ = await c.documentCreateChunk(
1726
+ const T = await d.documentCreateChunk(
1308
1727
  e,
1309
- d ? "" : k,
1728
+ u ? "" : v,
1310
1729
  // after_id resolves the parent server-side
1311
1730
  { title: "Text", body: "" },
1312
- r,
1313
- s,
1314
- d
1731
+ t,
1732
+ h,
1733
+ u
1315
1734
  );
1316
- V(), v(_.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));
1319
1738
  }
1320
1739
  }
1321
- }, [c, e, r, s, h, te, X, V]), Ye = O(async () => {
1322
- if (!(!c.documentCreateChunk || !h)) {
1323
- p(null);
1740
+ }, [d, e, t, h, g, re, K, F]), St = P(async () => {
1741
+ if (!(!d.documentCreateChunk || !g)) {
1742
+ M(null);
1324
1743
  try {
1325
- const d = await c.documentCreateChunk(
1744
+ const u = await d.documentCreateChunk(
1326
1745
  e,
1327
- h,
1746
+ g,
1328
1747
  { title: "Text", body: "" },
1329
- r,
1330
- s
1748
+ t,
1749
+ h
1331
1750
  );
1332
- V(), v(d.id), y(d);
1333
- } catch (d) {
1334
- p(d instanceof Error ? d.message : String(d));
1751
+ F(), N(u.id), E(u);
1752
+ } catch (u) {
1753
+ M(u instanceof Error ? u.message : String(u));
1335
1754
  }
1336
1755
  }
1337
- }, [c, e, r, s, h, V]), we = q(() => {
1338
- if (!m || te) return { canUp: !1, canDown: !1 };
1339
- const d = m.parent_id ?? "", k = u.filter((E) => (E.parent_id ?? "") === d).sort((E, U) => E.position - U.position || E.id.localeCompare(U.id)), _ = k.findIndex((E) => E.id === m.id);
1340
- return { canUp: _ > 0, canDown: _ >= 0 && _ < k.length - 1 };
1341
- }, [u, m, te]), Ce = O(
1342
- async (d) => {
1343
- if (!(!c.documentReorderChunk || !h)) {
1344
- p(null);
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(
1761
+ async (u) => {
1762
+ if (!(!d.documentReorderChunk || !g)) {
1763
+ M(null);
1345
1764
  try {
1346
- await c.documentReorderChunk(h, d, r, s), V();
1347
- } catch (k) {
1348
- p(k instanceof Error ? k.message : String(k));
1765
+ await d.documentReorderChunk(g, u, t, h), F();
1766
+ } catch (v) {
1767
+ M(v instanceof Error ? v.message : String(v));
1349
1768
  }
1350
1769
  }
1351
1770
  },
1352
- [c, h, r, s, V]
1353
- ), Ke = O(async () => {
1354
- if (!c.documentDeleteChunk || !m) return;
1355
- p(null);
1356
- const d = m.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;
1357
1776
  try {
1358
- await c.documentDeleteChunk(m.id, r, s), N(!1), v(d || X), V();
1359
- } catch (k) {
1360
- p(k instanceof Error ? k.message : String(k)), N(!1);
1777
+ await d.documentDeleteChunk(y.id, t, h), x(!1), N(u || K), F();
1778
+ } catch (v) {
1779
+ M(v instanceof Error ? v.message : String(v)), x(!1);
1361
1780
  }
1362
- }, [c, m, r, s, X, V]);
1363
- return B(() => {
1364
- if (!me) return;
1365
- const d = (k) => {
1366
- if (R || x) return;
1367
- const _ = document.activeElement, E = _?.tagName;
1368
- if (E === "INPUT" || E === "TEXTAREA" || _?.isContentEditable) return;
1369
- const U = mt(k.clipboardData?.items);
1370
- U && (k.preventDefault(), pe(U));
1781
+ }, [d, y, t, h, K, F]);
1782
+ return H(() => {
1783
+ if (!le) return;
1784
+ const u = (v) => {
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));
1371
1790
  };
1372
- return window.addEventListener("paste", d), () => window.removeEventListener("paste", d);
1373
- }, [me, R, x, pe]), /* @__PURE__ */ l("div", { className: "doc-viewer", children: [
1374
- /* @__PURE__ */ t(
1791
+ return window.addEventListener("paste", u), () => window.removeEventListener("paste", u);
1792
+ }, [le, R, fe, ye]), /* @__PURE__ */ c("div", { className: "doc-viewer", children: [
1793
+ /* @__PURE__ */ a(
1375
1794
  "input",
1376
1795
  {
1377
- ref: G,
1796
+ ref: _,
1378
1797
  type: "file",
1379
1798
  accept: "image/png,image/jpeg,image/gif,image/webp",
1380
1799
  style: { display: "none" },
1381
- onChange: (d) => {
1382
- const k = d.target.files?.[0];
1383
- d.target.value = "", k && pe(k);
1800
+ onChange: (u) => {
1801
+ const v = u.target.files?.[0];
1802
+ u.target.value = "", v && ye(v);
1384
1803
  }
1385
1804
  }
1386
1805
  ),
1387
- /* @__PURE__ */ l("div", { className: "doc-toolbar", style: ze, children: [
1388
- /* @__PURE__ */ t("strong", { className: "doc-title", title: ie, children: ie }),
1389
- /* @__PURE__ */ l("div", { className: "doc-toolbar-actions", children: [
1390
- me && /* @__PURE__ */ l(Y, { children: [
1391
- /* @__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(
1392
1812
  "button",
1393
1813
  {
1394
1814
  type: "button",
1395
1815
  onClick: () => {
1396
- Xe();
1816
+ _t();
1397
1817
  },
1398
1818
  title: "Add a text chunk AFTER the selected chunk, at the same level",
1399
1819
  children: "+ text"
1400
1820
  }
1401
1821
  ),
1402
- /* @__PURE__ */ t(
1822
+ /* @__PURE__ */ a(
1403
1823
  "button",
1404
1824
  {
1405
1825
  type: "button",
1406
1826
  onClick: () => {
1407
- Ye();
1827
+ St();
1408
1828
  },
1409
- disabled: !h,
1410
- title: h ? "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",
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",
1411
1831
  children: "+ child"
1412
1832
  }
1413
1833
  ),
1414
- /* @__PURE__ */ t(
1834
+ /* @__PURE__ */ a(
1415
1835
  "button",
1416
1836
  {
1417
1837
  type: "button",
1418
- onClick: () => G.current?.click(),
1838
+ onClick: () => _.current?.click(),
1419
1839
  title: "Add an image chunk (upload — or paste a screenshot into the view)",
1420
1840
  children: "+ image"
1421
1841
  }
1422
1842
  ),
1423
- /* @__PURE__ */ t(
1843
+ /* @__PURE__ */ a(
1424
1844
  "button",
1425
1845
  {
1426
1846
  type: "button",
1427
1847
  onClick: () => {
1428
- Qe();
1848
+ Ct();
1429
1849
  },
1430
1850
  title: "Add a Mermaid diagram chunk",
1431
1851
  children: "+ diagram"
1432
1852
  }
1433
1853
  )
1434
1854
  ] }),
1435
- /* @__PURE__ */ t(
1855
+ /* @__PURE__ */ a(
1436
1856
  "button",
1437
1857
  {
1438
1858
  type: "button",
1439
- className: se ? "active" : "",
1440
- onClick: () => H(!0),
1441
- disabled: !X,
1859
+ className: ge ? "active" : "",
1860
+ onClick: () => Se(!0),
1861
+ disabled: !K,
1442
1862
  title: "Colors — tint chunk tiles + the Path tree by type/status",
1443
1863
  children: "colors"
1444
1864
  }
1445
1865
  ),
1446
- /* @__PURE__ */ t("button", { type: "button", onClick: () => {
1447
- Ze();
1866
+ /* @__PURE__ */ a("button", { type: "button", onClick: () => {
1867
+ G();
1448
1868
  }, title: "Download the whole document as Markdown (.md)", children: "↓ .md" }),
1449
- /* @__PURE__ */ t(
1869
+ /* @__PURE__ */ a(
1450
1870
  "button",
1451
1871
  {
1452
1872
  type: "button",
1453
1873
  onClick: () => {
1454
- qe();
1874
+ ae();
1455
1875
  },
1456
1876
  title: "Download the whole document as a node/edge canvas graph (.canvas)",
1457
1877
  children: "↓ .canvas"
1458
1878
  }
1459
1879
  ),
1460
- i && /* @__PURE__ */ t(
1880
+ s && /* @__PURE__ */ a(
1461
1881
  "button",
1462
1882
  {
1463
1883
  type: "button",
1464
- className: oe ? "active" : "",
1465
- onClick: () => ce((d) => !d),
1884
+ className: _e ? "active" : "",
1885
+ onClick: () => D((u) => !u),
1466
1886
  title: "Document Assistant — instruct an agent to restructure/import/link chunks",
1467
1887
  children: "assistant"
1468
1888
  }
1469
1889
  ),
1470
- /* @__PURE__ */ t("button", { type: "button", onClick: V, title: "Reload", children: "↻" })
1890
+ /* @__PURE__ */ a("button", { type: "button", onClick: F, title: "Reload", children: "↻" })
1471
1891
  ] })
1472
1892
  ] }),
1473
- b && /* @__PURE__ */ t("div", { className: "paths-err", children: b }),
1474
- /* @__PURE__ */ l("div", { className: "doc-split", children: [
1475
- /* @__PURE__ */ t("div", { className: "doc-chunktree", children: w && u.length === 0 ? /* @__PURE__ */ t("div", { className: "empty", children: /* @__PURE__ */ t("p", { children: "Loading…" }) }) : /* @__PURE__ */ t(
1476
- bt,
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,
1477
1897
  {
1478
- tree: he,
1479
- selectedId: h,
1480
- onSelect: Je,
1481
- colorEnabled: se,
1482
- scheme: Z?.color_scheme,
1483
- linkedIds: Ve
1898
+ tree: Ne,
1899
+ selectedId: g,
1900
+ onSelect: $,
1901
+ colorEnabled: ge,
1902
+ scheme: Y?.color_scheme,
1903
+ linkedIds: Me
1484
1904
  }
1485
1905
  ) }),
1486
- /* @__PURE__ */ t("div", { className: "doc-content", children: m ? /* @__PURE__ */ l(Y, { children: [
1487
- /* @__PURE__ */ l("div", { className: "doc-content-head", children: [
1488
- /* @__PURE__ */ t("h3", { children: m.title || "(untitled)" }),
1489
- /* @__PURE__ */ l("div", { className: "doc-content-meta", children: [
1490
- m.type && /* @__PURE__ */ t("span", { className: "chunk-badge", children: m.type }),
1491
- m.status && /* @__PURE__ */ t("span", { className: "chunk-badge chunk-status", children: m.status }),
1492
- /* @__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: [
1493
1913
  "rev ",
1494
- m.revision
1914
+ y.revision
1495
1915
  ] }),
1496
- m.tags?.map((d) => /* @__PURE__ */ t("span", { className: "chunk-tag", children: d }, d))
1916
+ y.tags?.map((u) => /* @__PURE__ */ a("span", { className: "chunk-tag", children: u }, u)),
1917
+ /* @__PURE__ */ a(Fe, { value: y.id, label: "chunk" })
1497
1918
  ] }),
1498
- /* @__PURE__ */ l("div", { className: "doc-content-controls", children: [
1499
- /* @__PURE__ */ l("div", { className: "doc-mode-toggle", children: [
1500
- /* @__PURE__ */ t(
1919
+ /* @__PURE__ */ c("div", { className: "doc-content-controls", children: [
1920
+ /* @__PURE__ */ c("div", { className: "doc-mode-toggle", children: [
1921
+ /* @__PURE__ */ a(
1501
1922
  "button",
1502
1923
  {
1503
1924
  type: "button",
1504
- className: C === "chunks" ? "active" : "",
1505
- onClick: () => L("chunks"),
1925
+ className: B === "chunks" ? "active" : "",
1926
+ onClick: () => O("chunks"),
1506
1927
  title: "This chunk's own content",
1507
1928
  children: "chunk"
1508
1929
  }
1509
1930
  ),
1510
- /* @__PURE__ */ t(
1931
+ /* @__PURE__ */ a(
1511
1932
  "button",
1512
1933
  {
1513
1934
  type: "button",
1514
- className: C === "markdown" ? "active" : "",
1515
- onClick: () => L("markdown"),
1516
- 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",
1517
1938
  children: "markdown"
1518
1939
  }
1519
1940
  )
1520
1941
  ] }),
1521
- /* @__PURE__ */ t("button", { type: "button", onClick: () => y(m), children: "edit" }),
1522
- /* @__PURE__ */ t(
1942
+ /* @__PURE__ */ a("button", { type: "button", onClick: () => E(y), children: "edit" }),
1943
+ /* @__PURE__ */ a(
1523
1944
  "button",
1524
1945
  {
1525
1946
  type: "button",
1526
- onClick: () => J(!0),
1947
+ onClick: () => b(!0),
1527
1948
  title: "View this chunk's edit history + diffs",
1528
1949
  children: "history"
1529
1950
  }
1530
1951
  ),
1531
- !te && /* @__PURE__ */ l(Y, { children: [
1532
- /* @__PURE__ */ t(
1952
+ !re && /* @__PURE__ */ c(Q, { children: [
1953
+ /* @__PURE__ */ a(
1533
1954
  "button",
1534
1955
  {
1535
1956
  type: "button",
1536
1957
  onClick: () => {
1537
- Ce("up");
1958
+ Ve("up");
1538
1959
  },
1539
- disabled: !we.canUp,
1960
+ disabled: !We.canUp,
1540
1961
  title: "Move this chunk up within its level",
1541
1962
  children: "↑"
1542
1963
  }
1543
1964
  ),
1544
- /* @__PURE__ */ t(
1965
+ /* @__PURE__ */ a(
1545
1966
  "button",
1546
1967
  {
1547
1968
  type: "button",
1548
1969
  onClick: () => {
1549
- Ce("down");
1970
+ Ve("down");
1550
1971
  },
1551
- disabled: !we.canDown,
1972
+ disabled: !We.canDown,
1552
1973
  title: "Move this chunk down within its level",
1553
1974
  children: "↓"
1554
1975
  }
1555
1976
  )
1556
1977
  ] }),
1557
- !te && /* @__PURE__ */ t(
1978
+ !re && /* @__PURE__ */ a(
1558
1979
  "button",
1559
1980
  {
1560
1981
  type: "button",
1561
1982
  className: "danger",
1562
- onClick: () => N(!0),
1983
+ onClick: () => x(!0),
1563
1984
  title: "Delete this chunk and its sub-chunks",
1564
1985
  children: "delete"
1565
1986
  }
1566
1987
  )
1567
1988
  ] })
1568
1989
  ] }),
1569
- /* @__PURE__ */ t("div", { className: "doc-content-body", children: m.type === "mermaid" ? (
1990
+ /* @__PURE__ */ a("div", { className: "doc-content-body", children: y.type === "mermaid" ? (
1570
1991
  // RFC BO — a diagram chunk: body IS the Mermaid source.
1571
- m.body ? /* @__PURE__ */ l(Y, { children: [
1572
- /* @__PURE__ */ t(ue, { code: m.body }),
1573
- C === "markdown" && /* @__PURE__ */ t("pre", { className: "md-pre doc-mermaid-source", children: /* @__PURE__ */ t("code", { children: m.body }) })
1574
- ] }) : /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "(empty diagram)" })
1575
- ) : m.type === "image" || m.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 ? (
1576
1997
  // RFC BO — an image chunk: bytes come from the auth'd asset GET.
1577
- j ? /* @__PURE__ */ l("p", { className: "doc-empty-body", children: [
1998
+ z ? /* @__PURE__ */ c("p", { className: "doc-empty-body", children: [
1578
1999
  "Image failed to load: ",
1579
- j
1580
- ] }) : P ? /* @__PURE__ */ l("figure", { className: "doc-image", children: [
1581
- /* @__PURE__ */ t("img", { src: P, alt: Pt(m) }),
1582
- m.body && /* @__PURE__ */ t("figcaption", { children: m.body })
1583
- ] }) : /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "Loading image…" })
1584
- ) : C === "markdown" ? F !== null ? /* @__PURE__ */ t(Me, { source: F }) : /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "Assembling Markdown…" }) : m.body ? /* @__PURE__ */ t(Me, { source: m.body }) : /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "(empty chunk)" }) }),
1585
- /* @__PURE__ */ t(
1586
- Dt,
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,
1587
2008
  {
1588
- edges: W,
2009
+ edges: pe,
1589
2010
  documentId: e,
1590
- selectedId: h,
1591
- onSelectChunk: v
2011
+ selectedId: g,
2012
+ onSelectChunk: N,
2013
+ onOpenDocument: l ? L : void 0
1592
2014
  }
1593
2015
  ),
1594
- /* @__PURE__ */ t(
1595
- xt,
2016
+ /* @__PURE__ */ a(
2017
+ fn,
1596
2018
  {
1597
2019
  documentId: e,
1598
- selectedId: h,
1599
- scope: r,
1600
- browse: s,
1601
- onSelectChunk: v
2020
+ selectedId: g,
2021
+ scope: t,
2022
+ browse: h,
2023
+ onSelectChunk: N,
2024
+ onOpenDocument: l ? L : void 0
1602
2025
  }
1603
2026
  )
1604
- ] }) : /* @__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." }) }) })
1605
2028
  ] }),
1606
- oe && i && /* @__PURE__ */ t("div", { className: "doc-assistant", children: i({
2029
+ _e && s && /* @__PURE__ */ a("div", { className: "doc-assistant", children: s({
1607
2030
  documentId: e,
1608
- scope: r,
2031
+ scope: t,
1609
2032
  subject: o?.subject,
1610
2033
  // Pass the viewer's own reload so the injected assistant can refresh
1611
2034
  // the tree + selected chunk after a turn mutates the document.
1612
- onChanged: V
2035
+ onChanged: F
1613
2036
  }) }),
1614
- R && /* @__PURE__ */ t(
1615
- Nt,
2037
+ R && /* @__PURE__ */ a(
2038
+ cn,
1616
2039
  {
1617
2040
  chunk: R,
1618
- scope: r,
1619
- browse: s,
1620
- onClose: () => y(null),
1621
- onSaved: V
2041
+ scope: t,
2042
+ browse: h,
2043
+ onClose: () => E(null),
2044
+ onSaved: F
1622
2045
  }
1623
2046
  ),
1624
- D && m && /* @__PURE__ */ t(
1625
- Lt,
2047
+ m && y && /* @__PURE__ */ a(
2048
+ Nn,
1626
2049
  {
1627
- chunkId: m.id,
1628
- chunkTitle: m.title,
1629
- scope: r,
1630
- browse: s,
1631
- onClose: () => J(!1)
2050
+ chunkId: y.id,
2051
+ chunkTitle: y.title,
2052
+ scope: t,
2053
+ browse: h,
2054
+ onClose: () => b(!1)
1632
2055
  }
1633
2056
  ),
1634
- x && X && /* @__PURE__ */ t(
1635
- Ct,
2057
+ fe && K && /* @__PURE__ */ a(
2058
+ dn,
1636
2059
  {
1637
2060
  documentId: e,
1638
- rootChunkId: X,
1639
- docType: Z?.type,
1640
- docStatus: Z?.status,
1641
- chunkStatuses: We,
1642
- scope: r,
1643
- browse: s,
1644
- onClose: () => H(!1),
1645
- onSaved: V
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
1646
2069
  }
1647
2070
  ),
1648
- z && m && /* @__PURE__ */ t("div", { className: "modal-overlay", onClick: () => N(!1), children: /* @__PURE__ */ l("div", { className: "modal chunk-delete-confirm", onClick: (d) => d.stopPropagation(), children: [
1649
- /* @__PURE__ */ t("h3", { children: "Delete chunk" }),
1650
- /* @__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: [
1651
2074
  "Delete “",
1652
- m.title || "(untitled)",
2075
+ y.title || "(untitled)",
1653
2076
  "” and all of its sub-chunks? This cannot be undone."
1654
2077
  ] }),
1655
- /* @__PURE__ */ l("div", { className: "modal-buttons", children: [
1656
- /* @__PURE__ */ t("button", { type: "button", onClick: () => N(!1), children: "cancel" }),
1657
- /* @__PURE__ */ t("button", { type: "button", className: "danger", onClick: () => {
1658
- Ke();
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();
1659
2082
  }, children: "delete" })
1660
2083
  ] })
1661
2084
  ] }) })
1662
2085
  ] });
1663
2086
  }
1664
- function Ut(e) {
1665
- const r = {
1666
- name: "",
1667
- fullPath: "",
1668
- kind: "directory",
1669
- explicit: !0,
1670
- children: []
1671
- }, n = /* @__PURE__ */ new Map([["", r]]), a = (i) => {
1672
- const c = n.get(i);
1673
- if (c) return c;
1674
- const s = i.lastIndexOf("/"), u = s <= 0 ? "" : i.slice(0, s), g = i.slice(s + 1), h = a(u), v = {
1675
- name: g,
1676
- fullPath: i,
1677
- kind: "directory",
1678
- explicit: !1,
1679
- 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) : []
1680
2099
  };
1681
- return h.children.push(v), n.set(i, v), v;
1682
- };
1683
- for (const i of e) {
1684
- const c = a(i.full_path);
1685
- c.kind = i.kind, c.explicit = !0, c.resourceRef = i.resource_ref;
1686
- }
1687
- const o = (i) => {
1688
- i.sort((c, s) => {
1689
- const u = c.kind === "directory", g = s.kind === "directory";
1690
- return u !== g ? u ? -1 : 1 : c.name.localeCompare(s.name);
1691
- }), i.forEach((c) => o(c.children));
1692
- };
1693
- return o(r.children), r.children;
1694
- }
1695
- function ke(e) {
1696
- const r = e.lastIndexOf("/");
1697
- return r <= 0 ? "" : e.slice(0, r);
1698
- }
1699
- function Ot(e) {
1700
- const r = [], n = (a) => {
1701
- if (a.kind === "document") {
1702
- const o = a.resourceRef;
1703
- o?.document_id && r.push(o.document_id);
1704
- }
1705
- a.children.forEach(n);
1706
- };
1707
- 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;
1708
2105
  }
1709
- const It = {
2106
+ const Sn = {
1710
2107
  directory: "📁",
1711
2108
  document: "📄",
1712
2109
  volume_mount: "💾",
1713
2110
  memory_entry: "🧠"
1714
2111
  };
1715
- function jt({ tree: e, selectedPath: r, onSelect: n, summaries: a }) {
1716
- const [o, i] = f(() => /* @__PURE__ */ new Map()), c = O((s) => {
1717
- i((u) => {
1718
- const g = new Map(u);
1719
- return g.set(s, u.get(s) === !1), g;
1720
- });
1721
- }, []);
1722
- return B(() => {
1723
- r && i((s) => {
1724
- let u = !1;
1725
- const g = new Map(s);
1726
- let h = ke(r);
1727
- for (; h !== ""; )
1728
- g.get(h) === !1 && (g.set(h, !0), u = !0), h = ke(h);
1729
- return u ? g : s;
1730
- });
1731
- }, [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(
1732
- Ge,
1733
- {
1734
- node: s,
1735
- expanded: o,
1736
- toggle: c,
1737
- selectedPath: r,
1738
- onSelect: n,
1739
- summaries: a
1740
- },
1741
- s.fullPath
1742
- )) });
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 });
1743
2151
  }
1744
- function Bt(e, r) {
1745
- if (e.kind !== "document" || !r) return;
2152
+ function xn(e, t) {
2153
+ if (e.kind !== "document" || !t) return;
1746
2154
  const n = e.resourceRef;
1747
- return n?.document_id ? r.get(n.document_id) : void 0;
2155
+ return n?.document_id ? t.get(n.document_id) : void 0;
1748
2156
  }
1749
- function Ge({ node: e, expanded: r, toggle: n, selectedPath: a, onSelect: o, summaries: i }) {
1750
- const c = e.children.length > 0, s = r.get(e.fullPath) !== !1, u = a === e.fullPath, g = Bt(e, i), h = g && g.color_enabled ? Ne(Ie(g.type, g.status, ve(g.color_scheme))) : void 0;
1751
- return /* @__PURE__ */ l("li", { className: `node path-node kind-${e.kind} ${u ? "selected" : ""}`, children: [
1752
- /* @__PURE__ */ l("div", { className: "row path-row", style: h, children: [
1753
- /* @__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(
1754
2162
  "button",
1755
2163
  {
1756
2164
  type: "button",
1757
2165
  className: "tree-caret",
1758
- "aria-label": s ? "collapse" : "expand",
1759
- disabled: !c,
1760
- onClick: (v) => {
1761
- v.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);
1762
2171
  },
1763
- children: c ? s ? "▼" : "▶" : "·"
2172
+ children: l ? f ? "▼" : "▶" : "·"
1764
2173
  }
1765
2174
  ),
1766
- /* @__PURE__ */ l(
2175
+ /* @__PURE__ */ c(
1767
2176
  "button",
1768
2177
  {
1769
2178
  type: "button",
1770
2179
  className: "path-link",
1771
- onClick: () => o(e),
1772
- title: e.fullPath,
2180
+ onClick: () => s(t),
2181
+ title: t.fullPath,
1773
2182
  children: [
1774
- /* @__PURE__ */ t("span", { className: "path-kind-icon", "aria-hidden": !0, children: It[e.kind] ?? "•" }),
1775
- /* @__PURE__ */ t("span", { className: "path-name", children: e.name }),
1776
- g?.type && /* @__PURE__ */ t("span", { className: "chunk-badge", children: g.type }),
1777
- g?.status && /* @__PURE__ */ t("span", { className: "chunk-badge chunk-status", children: g.status }),
1778
- !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 })
1779
2187
  ]
1780
2188
  }
1781
2189
  )
1782
2190
  ] }),
1783
- c && s && /* @__PURE__ */ t("ul", { className: "children path-children", children: e.children.map((v) => /* @__PURE__ */ t(
1784
- Ge,
1785
- {
1786
- node: v,
1787
- expanded: r,
1788
- toggle: n,
1789
- selectedPath: a,
1790
- onSelect: o,
1791
- summaries: i
1792
- },
1793
- v.fullPath
1794
- )) })
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
+ ] })
1795
2195
  ] });
1796
2196
  }
1797
- const $e = /^[A-Za-z0-9._-]+$/;
1798
- function Le(e, r) {
1799
- return `${e}/${r}`;
2197
+ const tt = /^[A-Za-z0-9._-]+$/;
2198
+ function nt(e, t) {
2199
+ return `${e}/${t}`;
1800
2200
  }
1801
- function He(e, r) {
2201
+ function wt(e, t) {
1802
2202
  for (const n of e) {
1803
- if (n.fullPath === r) return n;
1804
- const a = He(n.children, r);
1805
- if (a) return a;
2203
+ if (n.fullPath === t) return n;
2204
+ const r = wt(n.children, t);
2205
+ if (r) return r;
1806
2206
  }
1807
2207
  }
1808
- function Zt(e) {
1809
- const { theme: r, defaultScope: n, path: a, onPathChange: o, browse: i, principal: c, renderAssistant: s, onError: u } = e, g = Ae(e);
1810
- return /* @__PURE__ */ t(Pe, { theme: r, dataLayer: g, children: /* @__PURE__ */ t(
1811
- Ft,
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,
1812
2212
  {
1813
2213
  defaultScope: n,
1814
- path: a,
2214
+ path: r,
1815
2215
  onPathChange: o,
1816
- browse: i,
1817
- principal: c,
1818
- renderAssistant: s,
1819
- onError: u
2216
+ browse: s,
2217
+ principal: i,
2218
+ renderAssistant: l,
2219
+ onError: f
1820
2220
  }
1821
2221
  ) });
1822
2222
  }
1823
- function Ft({
2223
+ function $n({
1824
2224
  defaultScope: e,
1825
- path: r,
2225
+ path: t,
1826
2226
  onPathChange: n,
1827
- browse: a,
2227
+ browse: r,
1828
2228
  principal: o,
1829
- renderAssistant: i,
1830
- onError: c
2229
+ renderAssistant: s,
2230
+ onError: i
1831
2231
  }) {
1832
- const s = ae(), [u, g] = f(e ?? "user"), [h, v] = f([]), [m, A] = f(void 0), [C, L] = f(null), [F, I] = f(!1), [P, M] = f(null), j = r !== void 0 ? r : m, $ = ne(n);
1833
- B(() => {
1834
- $.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;
1835
2235
  }, [n]);
1836
- const G = ne(c);
1837
- B(() => {
1838
- G.current = c;
1839
- }, [c]);
1840
- const R = O((x) => {
1841
- $.current?.(x), A(x);
1842
- }, []), y = q(
1843
- () => a && (a.scopeId || a.tenant) ? { scopeId: a.scopeId, tenant: a.tenant } : void 0,
1844
- [a?.scopeId, a?.tenant]
1845
- ), D = O(async () => {
1846
- I(!0), L(null);
1847
- try {
1848
- const x = await s.pathLs("/", u, !0, y);
1849
- v(x.entries ?? []);
1850
- } catch (x) {
1851
- L(x instanceof Error ? x.message : String(x)), v([]), G.current?.(x);
1852
- } finally {
1853
- I(!1);
1854
- }
1855
- }, [s, u, y]), J = ne(!0);
1856
- B(() => {
1857
- J.current ? J.current = !1 : R(void 0), D();
1858
- }, [D, R]);
1859
- const z = q(() => Ut(h), [h]), [N, b] = f(() => /* @__PURE__ */ new Map());
1860
- B(() => {
1861
- if (u === "tenant") {
1862
- b(/* @__PURE__ */ new Map());
1863
- return;
1864
- }
1865
- const x = h.filter((W) => W.kind === "document").map((W) => W.resource_ref?.document_id).filter((W) => !!W);
1866
- if (x.length === 0) {
1867
- b(/* @__PURE__ */ new Map());
1868
- return;
1869
- }
1870
- let H = !1;
1871
- return s.documentsSummary({ documentIds: x }, u, y).then((W) => {
1872
- if (H) return;
1873
- const Q = /* @__PURE__ */ new Map();
1874
- for (const V of W.documents ?? []) Q.set(V.document_id, V);
1875
- b(Q);
1876
- }).catch(() => {
1877
- H || b(/* @__PURE__ */ new Map());
1878
- }), () => {
1879
- 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;
1880
2319
  };
1881
- }, [s, h, u, y]);
1882
- const p = q(
1883
- () => j ? He(z, j) : void 0,
1884
- [z, j]
1885
- ), w = q(() => p ? p.kind === "directory" ? p.fullPath : ke(p.fullPath) : "", [p]), S = w || "/", T = u !== "tenant", ee = O(() => {
1886
- M({
1887
- 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}`,
1888
2324
  fields: [{ key: "name", label: "Folder name", placeholder: "e.g. launches" }],
1889
2325
  submitLabel: "Create",
1890
- onSubmit: async (x) => {
1891
- const H = x.name.trim();
1892
- if (!$e.test(H)) throw new Error("name may contain only [A-Za-z0-9._-]");
1893
- const W = Le(w, H);
1894
- await s.pathMkdir(W, u, 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);
1895
2331
  }
1896
2332
  });
1897
- }, [s, w, S, u, y, D, R]), oe = O(() => {
1898
- M({
1899
- title: `New document in ${S}`,
2333
+ }, [l, m, oe, F, f, E, C, R]), Ne = P(() => {
2334
+ y({
2335
+ title: `New document in ${F}`,
1900
2336
  fields: [
1901
2337
  { key: "name", label: "Path name", placeholder: "e.g. launch-plan" },
1902
2338
  { key: "title", label: "Title", placeholder: "e.g. Launch Plan" }
1903
2339
  ],
1904
2340
  submitLabel: "Create",
1905
- onSubmit: async (x) => {
1906
- const H = x.name.trim();
1907
- if (!$e.test(H)) throw new Error("name may contain only [A-Za-z0-9._-]");
1908
- const W = x.title.trim() || H, Q = Le(w, H);
1909
- await s.documentCreate(W, Q, u, 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);
1910
2346
  }
1911
2347
  });
1912
- }, [s, w, S, u, y, D, R]), ce = O(() => {
1913
- p && M({
1914
- title: `Rename / move ${p.fullPath}`,
1915
- 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 }],
1916
2352
  submitLabel: "Move",
1917
- onSubmit: async (x) => {
1918
- const H = x.to.trim();
1919
- if (!H.startsWith("/")) throw new Error("path must start with /");
1920
- await s.pathMv(p.fullPath, H, u, 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($);
1921
2360
  }
1922
2361
  });
1923
- }, [s, p, u, y, D, R]), Z = O(() => {
1924
- if (!p) return;
1925
- if (p.kind === "document") {
1926
- const Q = p.resourceRef?.document_id;
1927
- M({
1928
- 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}`,
1929
2368
  message: "This deletes the document, all its chunks, and its path entry. This cannot be undone.",
1930
2369
  fields: [],
1931
2370
  submitLabel: "Delete",
1932
2371
  danger: !0,
1933
2372
  onSubmit: async () => {
1934
- if (!Q) throw new Error("this document dirent has no document_id");
1935
- await s.documentDelete(Q, u, 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);
1936
2375
  }
1937
2376
  });
1938
2377
  return;
1939
2378
  }
1940
- const x = u === "tenant" ? [] : Ot(p), H = p.children.length;
1941
- M({
1942
- title: `Delete branch ${p.fullPath}`,
1943
- 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.` : "."),
1944
- fields: [],
1945
- submitLabel: "Delete",
1946
- danger: !0,
1947
- onSubmit: async () => {
1948
- for (const W of x)
1949
- await s.documentDelete(W, u, y);
1950
- await s.pathRm(p.fullPath, u, !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;
1951
2387
  }
1952
- });
1953
- }, [s, p, u, y, D, R]), re = p && (p.kind === "directory" || p.kind === "document");
1954
- return /* @__PURE__ */ l(Y, { children: [
1955
- /* @__PURE__ */ l(
1956
- ut,
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,
1957
2436
  {
1958
2437
  className: "paths-view",
1959
2438
  defaultLeftWidth: 420,
@@ -1961,164 +2440,220 @@ function Ft({
1961
2440
  minRightWidth: 300,
1962
2441
  storageKey: "loomcycle.explorer.split.paths",
1963
2442
  children: [
1964
- /* @__PURE__ */ l("div", { className: "left", children: [
1965
- /* @__PURE__ */ l("div", { className: "paths-toolbar", children: [
1966
- /* @__PURE__ */ l("label", { className: "paths-scope", children: [
1967
- /* @__PURE__ */ t("span", { children: "scope" }),
1968
- /* @__PURE__ */ l("select", { value: u, onChange: (x) => g(x.target.value), children: [
1969
- /* @__PURE__ */ t("option", { value: "user", children: "user" }),
1970
- /* @__PURE__ */ t("option", { value: "agent", children: "agent" }),
1971
- /* @__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" })
1972
2451
  ] })
1973
2452
  ] }),
1974
- /* @__PURE__ */ l("div", { className: "paths-toolbar-actions", children: [
1975
- /* @__PURE__ */ t("button", { type: "button", onClick: ee, title: `New folder in ${S}`, children: "+ folder" }),
1976
- /* @__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(
1977
2456
  "button",
1978
2457
  {
1979
2458
  type: "button",
1980
- onClick: oe,
1981
- disabled: !T,
1982
- 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",
1983
2462
  children: "+ document"
1984
2463
  }
1985
2464
  ),
1986
- /* @__PURE__ */ t("button", { type: "button", onClick: () => {
1987
- D();
2465
+ /* @__PURE__ */ a("button", { type: "button", onClick: () => {
2466
+ Ce();
1988
2467
  }, title: "Reload the tree", children: "↻" })
1989
2468
  ] })
1990
2469
  ] }),
1991
- /* @__PURE__ */ l("p", { className: "paths-context", children: [
2470
+ /* @__PURE__ */ c("p", { className: "paths-context", children: [
1992
2471
  "new items → ",
1993
- /* @__PURE__ */ t("code", { children: S }),
1994
- y?.scopeId && /* @__PURE__ */ l(Y, { children: [
2472
+ /* @__PURE__ */ a("code", { children: F }),
2473
+ E?.scopeId && /* @__PURE__ */ c(Q, { children: [
1995
2474
  " · ",
1996
2475
  "subject ",
1997
- /* @__PURE__ */ t("code", { children: y.scopeId })
2476
+ /* @__PURE__ */ a("code", { children: E.scopeId })
1998
2477
  ] }),
1999
- y?.tenant && /* @__PURE__ */ l(Y, { children: [
2478
+ E?.tenant && /* @__PURE__ */ c(Q, { children: [
2000
2479
  " · ",
2001
2480
  "tenant ",
2002
- /* @__PURE__ */ t("code", { children: y.tenant })
2481
+ /* @__PURE__ */ a("code", { children: E.tenant })
2003
2482
  ] })
2004
2483
  ] }),
2005
- C && /* @__PURE__ */ t("div", { className: "paths-err", children: C }),
2006
- F && h.length === 0 ? /* @__PURE__ */ t("div", { className: "empty", children: /* @__PURE__ */ t("p", { children: "Loading…" }) }) : /* @__PURE__ */ t(
2007
- jt,
2484
+ (S || Y) && /* @__PURE__ */ a("div", { className: "paths-err", children: S || Y }),
2485
+ /* @__PURE__ */ a(
2486
+ En,
2008
2487
  {
2009
- tree: z,
2010
- selectedPath: j,
2011
- onSelect: (x) => R(x.fullPath),
2012
- 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
2013
2497
  }
2014
2498
  )
2015
2499
  ] }),
2016
- /* @__PURE__ */ t("div", { className: "right", children: p ? p.kind === "document" ? /* @__PURE__ */ l("div", { className: "paths-doc", children: [
2017
- /* @__PURE__ */ l("div", { className: "paths-doc-head", children: [
2018
- /* @__PURE__ */ t("code", { className: "paths-doc-path", children: p.fullPath }),
2019
- /* @__PURE__ */ l("div", { className: "paths-detail-actions", children: [
2020
- /* @__PURE__ */ t("button", { type: "button", onClick: ce, children: "rename / move" }),
2021
- /* @__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" })
2022
2518
  ] })
2023
2519
  ] }),
2024
- /* @__PURE__ */ t(
2025
- Fe,
2520
+ /* @__PURE__ */ a(
2521
+ bt,
2026
2522
  {
2027
- documentId: p.resourceRef?.document_id ?? "",
2028
- scope: u,
2029
- titleHint: p.name,
2030
- browse: y,
2523
+ documentId: ee.documentId,
2524
+ scope: f,
2525
+ titleHint: ee.title,
2526
+ browse: E,
2031
2527
  principal: o,
2032
- renderAssistant: i
2033
- }
2528
+ renderAssistant: s,
2529
+ initialChunkId: ee.chunkId,
2530
+ onOpenDocument: ge,
2531
+ onTitle: Re
2532
+ },
2533
+ I.length
2034
2534
  )
2035
- ] }) : /* @__PURE__ */ l("div", { className: "paths-detail", children: [
2036
- /* @__PURE__ */ l("h2", { children: [
2037
- /* @__PURE__ */ t("span", { className: "paths-detail-kind", children: p.kind }),
2038
- /* @__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 })
2039
2539
  ] }),
2040
- /* @__PURE__ */ l("dl", { className: "paths-detail-meta", children: [
2041
- /* @__PURE__ */ t("dt", { children: "scope" }),
2042
- /* @__PURE__ */ t("dd", { children: u }),
2043
- /* @__PURE__ */ t("dt", { children: "stored" }),
2044
- /* @__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
+ ] })
2045
2547
  ] }),
2046
- re ? /* @__PURE__ */ l("div", { className: "paths-detail-actions", children: [
2047
- /* @__PURE__ */ t("button", { type: "button", onClick: ce, children: "rename / move" }),
2048
- /* @__PURE__ */ t("button", { type: "button", className: "danger", onClick: Z, children: "delete" })
2049
- ] }) : /* @__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: [
2050
2552
  "Read-only — ",
2051
- p.kind,
2553
+ D.kind,
2052
2554
  " entries are managed by their own tool."
2053
2555
  ] })
2054
- ] }) : /* @__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." }) }) })
2055
2557
  ]
2056
2558
  }
2057
2559
  ),
2058
- P && /* @__PURE__ */ t(Gt, { state: P, onClose: () => M(null) })
2560
+ N && /* @__PURE__ */ a(Dn, { state: N, onClose: () => y(null) })
2059
2561
  ] });
2060
2562
  }
2061
- function Gt({ state: e, onClose: r }) {
2062
- const [n, a] = f(
2063
- () => Object.fromEntries(e.fields.map((g) => [g.key, g.value ?? ""]))
2064
- ), [o, i] = f(!1), [c, s] = f(null);
2065
- return /* @__PURE__ */ t("div", { className: "modal-overlay", onClick: r, children: /* @__PURE__ */ l("form", { className: "modal", onClick: (g) => g.stopPropagation(), onSubmit: async (g) => {
2066
- 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);
2067
2569
  try {
2068
- await e.onSubmit(n), r();
2570
+ await e.onSubmit(n), t();
2069
2571
  } catch (h) {
2070
- s(h instanceof Error ? h.message : String(h)), i(!1);
2572
+ l(h instanceof Error ? h.message : String(h)), s(!1);
2071
2573
  }
2072
2574
  }, children: [
2073
- /* @__PURE__ */ l("div", { className: "modal-header sticky-top", children: [
2074
- /* @__PURE__ */ t("h3", { children: e.title }),
2075
- /* @__PURE__ */ l("div", { className: "modal-buttons modal-buttons-top", children: [
2076
- /* @__PURE__ */ t("button", { type: "button", onClick: r, disabled: o, children: "cancel" }),
2077
- /* @__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 })
2078
2580
  ] })
2079
2581
  ] }),
2080
- e.message && /* @__PURE__ */ t("p", { className: "modal-context", children: e.message }),
2081
- e.fields.map((g, h) => /* @__PURE__ */ l("label", { className: "path-field", children: [
2082
- /* @__PURE__ */ t("span", { children: g.label }),
2083
- /* @__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(
2084
2586
  "input",
2085
2587
  {
2086
2588
  className: "path-modal-input",
2087
- value: n[g.key],
2088
- placeholder: g.placeholder,
2589
+ value: n[d.key],
2590
+ placeholder: d.placeholder,
2089
2591
  autoFocus: h === 0,
2090
- onChange: (v) => a((m) => ({ ...m, [g.key]: v.target.value }))
2592
+ onChange: (w) => r((S) => ({ ...S, [d.key]: w.target.value }))
2091
2593
  }
2092
2594
  )
2093
- ] }, g.key)),
2094
- c && /* @__PURE__ */ t("div", { className: "modal-err", children: c })
2595
+ ] }, d.key)),
2596
+ i && /* @__PURE__ */ a("div", { className: "modal-err", children: i })
2095
2597
  ] }) });
2096
2598
  }
2097
- function qt(e) {
2098
- const { documentId: r, scope: n, titleHint: a, browse: o, theme: i, principal: c, renderAssistant: s } = e, u = Ae(e);
2099
- return /* @__PURE__ */ t(Pe, { theme: i, dataLayer: u, children: /* @__PURE__ */ t(
2100
- 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,
2101
2603
  {
2102
- documentId: r,
2103
- scope: n,
2104
- titleHint: a,
2105
- browse: o,
2106
- principal: c,
2107
- renderAssistant: s
2108
- }
2604
+ ...e
2605
+ },
2606
+ `${n}:${t}:${r?.scopeId ?? ""}:${r?.tenant ?? ""}`
2109
2607
  ) });
2110
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
+ }
2111
2646
  export {
2112
- be as DEFAULT_SCHEME,
2113
- qt as DocumentViewer,
2114
- Zt as PathExplorer,
2115
- dt as assetFetchFromConnection,
2116
- ft as chunkColor,
2117
- lt as createLoomcycleClient,
2118
- _e as dataLayerFromClient,
2119
- Ie as docColor,
2120
- ve as effectiveScheme,
2121
- gt as hexToTint,
2122
- 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
2123
2658
  };
2124
2659
  //# sourceMappingURL=index.js.map