@loomcycle/explorer 0.2.0 → 0.3.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,104 +1,153 @@
1
1
  import { jsx as n, jsxs as d, Fragment as q } from "react/jsx-runtime";
2
- import { createContext as Pe, useContext as Te, useMemo as A, useState as b, useRef as ee, useEffect as I, useCallback as G } from "react";
3
- import { LoomcycleClient as Oe } from "@loomcycle/client";
4
- import Ie from "react-markdown";
5
- import Ae from "remark-gfm";
6
- function he(e) {
2
+ import { createContext as Je, useContext as Ve, useMemo as H, useState as y, useRef as K, useEffect as I, useCallback as G } from "react";
3
+ import { LoomcycleClient as Ze } from "@loomcycle/client";
4
+ import qe from "react-markdown";
5
+ import Qe from "remark-gfm";
6
+ function ye(e, r) {
7
7
  return {
8
- pathLs: (a, t, r, c) => e.path(
9
- { op: "ls", path: a, scope: t, recursive: r },
10
- c
8
+ pathLs: (t, a, c, s) => e.path(
9
+ { op: "ls", path: t, scope: a, recursive: c },
10
+ s
11
11
  ),
12
- pathMkdir: (a, t, r) => e.path({ op: "mkdir", path: a, scope: t }, r),
13
- pathMv: (a, t, r, c) => e.path({ op: "mv", path: a, to: t, scope: r }, c),
14
- pathRm: (a, t, r, c) => e.path({ op: "rm", path: a, scope: t, recursive: r }, c),
15
- documentCreate: (a, t, r, c) => e.document(
16
- { op: "create_document", title: a, path: t, scope: r },
17
- c
12
+ pathMkdir: (t, a, c) => e.path({ op: "mkdir", path: t, scope: a }, c),
13
+ pathMv: (t, a, c, s) => e.path({ op: "mv", path: t, to: a, scope: c }, s),
14
+ pathRm: (t, a, c, s) => e.path({ op: "rm", path: t, scope: a, recursive: c }, s),
15
+ documentCreate: (t, a, c, s) => e.document(
16
+ { op: "create_document", title: t, path: a, scope: c },
17
+ s
18
18
  ),
19
- documentDelete: (a, t, r) => e.document({ op: "delete_document", id: a, scope: t }, r),
20
- documentGet: (a, t, r) => e.document({ op: "get_document", id: a, scope: t }, r),
21
- documentsSummary: (a, t, r) => e.document(
19
+ documentDelete: (t, a, c) => e.document({ op: "delete_document", id: t, scope: a }, c),
20
+ documentGet: (t, a, c) => e.document({ op: "get_document", id: t, scope: a }, c),
21
+ documentsSummary: (t, a, c) => e.document(
22
22
  // documents_summary + document_ids are RFC BN wire additions the pinned
23
23
  // SDK type doesn't enumerate; the /v1/_document passthrough accepts them
24
24
  // verbatim, so cast past DocumentToolInput (same pattern as update_chunk).
25
25
  {
26
26
  op: "documents_summary",
27
- scope: t,
28
- ...a.documentIds ? { document_ids: a.documentIds } : {},
29
- ...a.underPath ? { under_path: a.underPath } : {}
27
+ scope: a,
28
+ ...t.documentIds ? { document_ids: t.documentIds } : {},
29
+ ...t.underPath ? { under_path: t.underPath } : {}
30
+ },
31
+ c
32
+ ),
33
+ documentQueryChunks: (t, a, c) => e.document(
34
+ { op: "query_chunks", document_id: t, scope: a, limit: 1e3 },
35
+ c
36
+ ),
37
+ documentGetChunk: (t, a, c) => e.document({ op: "get_chunk", id: t, scope: a }, c),
38
+ documentCreateChunk: (t, a, c, s, o) => e.document(
39
+ {
40
+ op: "create_chunk",
41
+ document_id: t,
42
+ parent_id: a,
43
+ scope: s,
44
+ ...c
30
45
  },
31
- r
46
+ o
32
47
  ),
33
- documentQueryChunks: (a, t, r) => e.document(
34
- { op: "query_chunks", document_id: a, scope: t, limit: 1e3 },
35
- r
48
+ documentSetAsset: (t, a, c, s, o, i) => e.document(
49
+ // set_asset is an RFC BO wire op the pinned SDK type doesn't enumerate;
50
+ // the /v1/_document passthrough accepts it verbatim.
51
+ {
52
+ op: "set_asset",
53
+ id: t,
54
+ media_type: a,
55
+ data: c,
56
+ ...s ? { filename: s } : {},
57
+ scope: o
58
+ },
59
+ i
36
60
  ),
37
- documentGetChunk: (a, t, r) => e.document({ op: "get_chunk", id: a, scope: t }, r),
38
- documentGetEdges: (a, t, r) => e.document(
61
+ documentGetEdges: (t, a, c) => e.document(
39
62
  // get_edges is an RFC BN P4 wire op the pinned SDK type doesn't
40
63
  // enumerate; the /v1/_document passthrough accepts it verbatim.
41
- { op: "get_edges", document_id: a, scope: t },
42
- r
64
+ { op: "get_edges", document_id: t, scope: a },
65
+ c
43
66
  ),
44
- documentUpdateChunk: (a, t, r, c, l) => e.document(
67
+ documentUpdateChunk: (t, a, c, s, o) => e.document(
45
68
  // `patch.fields` is unknown but DocumentToolInput.fields is a typed
46
69
  // Record; the cast reconciles the spread (the server accepts arbitrary
47
70
  // JSON there). Op order + arg names mirror the wire contract exactly.
48
71
  {
49
72
  op: "update_chunk",
50
- id: a,
51
- revision: t,
52
- scope: c,
53
- ...r
73
+ id: t,
74
+ revision: a,
75
+ scope: s,
76
+ ...c
54
77
  },
55
- l
78
+ o
56
79
  ),
57
- documentExportMd: (a, t, r, c) => e.document(
80
+ documentExportMd: (t, a, c, s) => e.document(
58
81
  {
59
82
  op: "export_md",
60
- document_id: a,
61
- scope: t,
62
- include_metadata: r
83
+ document_id: t,
84
+ scope: a,
85
+ include_metadata: c
63
86
  },
64
- c
65
- )
87
+ s
88
+ ),
89
+ // Present only when an AssetFetch was supplied (the connection path); a bare
90
+ // client can't do the raw binary GET, so the op is omitted and the viewer
91
+ // shows a placeholder.
92
+ ...r ? {
93
+ documentAssetObjectUrl: async (t, a, c) => {
94
+ const s = new URLSearchParams({ scope: a });
95
+ c?.scopeId && s.set("scope_id", c.scopeId), c?.tenant && s.set("tenant", c.tenant);
96
+ const o = await r(
97
+ `/v1/_document/asset/${encodeURIComponent(t)}?${s.toString()}`
98
+ );
99
+ if (!o.ok) throw new Error(`asset fetch failed: ${o.status}`);
100
+ const i = await o.blob();
101
+ return URL.createObjectURL(i);
102
+ }
103
+ } : {}
66
104
  };
67
105
  }
68
- const ve = Pe(null);
69
- function Ge({
106
+ const Se = Je(null);
107
+ function Xe({
70
108
  value: e,
71
- children: a
109
+ children: r
72
110
  }) {
73
- return /* @__PURE__ */ n(ve.Provider, { value: e, children: a });
111
+ return /* @__PURE__ */ n(Se.Provider, { value: e, children: r });
74
112
  }
75
- function ce() {
76
- const e = Te(ve);
113
+ function se() {
114
+ const e = Ve(Se);
77
115
  if (!e)
78
116
  throw new Error(
79
117
  "useExplorerData must be used within <PathExplorer> or <DocumentViewer> (no ExplorerDataLayer in context)"
80
118
  );
81
119
  return e;
82
120
  }
83
- function je(e) {
84
- const a = e.fetch;
85
- return new Oe({
121
+ function Ye(e) {
122
+ const r = e.fetch;
123
+ return new Ze({
86
124
  baseUrl: e.baseUrl,
87
125
  authToken: e.token || void 0,
88
- fetch: (t, r) => a ? a(t, r) : fetch(t, r)
126
+ fetch: (t, a) => r ? r(t, a) : fetch(t, a)
89
127
  });
90
128
  }
91
- function Ne(e) {
92
- const { dataLayer: a, client: t, connection: r } = e;
93
- return A(() => a || (t ? he(t) : r ? he(je(r)) : null), [a, t, r?.baseUrl, r?.token, r?.fetch]);
129
+ function Ke(e) {
130
+ const r = e.fetch, t = (a, c) => r ? r(a, c) : fetch(a, c);
131
+ return (a) => {
132
+ const c = {};
133
+ return e.token && (c.Authorization = `Bearer ${e.token}`), t(e.baseUrl + a, { headers: c });
134
+ };
94
135
  }
95
- function we({
136
+ function xe(e) {
137
+ const { dataLayer: r, client: t, connection: a } = e;
138
+ return H(() => r || (t ? ye(t) : a ? ye(
139
+ Ye(a),
140
+ Ke(a)
141
+ // RFC BO — binary image-asset GET
142
+ ) : null), [r, t, a?.baseUrl, a?.token, a?.fetch]);
143
+ }
144
+ function $e({
96
145
  theme: e,
97
- dataLayer: a,
146
+ dataLayer: r,
98
147
  children: t
99
148
  }) {
100
- const r = e ? { "data-theme": e } : {};
101
- return a ? /* @__PURE__ */ n("div", { className: "loomcycle-explorer", ...r, children: /* @__PURE__ */ n(Ge, { value: a, children: t }) }) : /* @__PURE__ */ n("div", { className: "loomcycle-explorer", ...r, children: /* @__PURE__ */ d("div", { className: "error-banner", children: [
149
+ const a = e ? { "data-theme": e } : {};
150
+ return r ? /* @__PURE__ */ n("div", { className: "loomcycle-explorer", ...a, children: /* @__PURE__ */ n(Xe, { value: r, children: t }) }) : /* @__PURE__ */ n("div", { className: "loomcycle-explorer", ...a, children: /* @__PURE__ */ d("div", { className: "error-banner", children: [
102
151
  "@loomcycle/explorer: provide a ",
103
152
  /* @__PURE__ */ n("code", { children: "connection" }),
104
153
  ", ",
@@ -109,48 +158,48 @@ function we({
109
158
  " prop."
110
159
  ] }) });
111
160
  }
112
- const me = 6;
113
- function Ue({
161
+ const be = 6;
162
+ function et({
114
163
  children: e,
115
- defaultLeftWidth: a = 380,
164
+ defaultLeftWidth: r = 380,
116
165
  minLeftWidth: t = 180,
117
- minRightWidth: r = 240,
166
+ minRightWidth: a = 240,
118
167
  storageKey: c,
119
- className: l
168
+ className: s
120
169
  }) {
121
- const [s, o] = b(() => {
170
+ const [o, i] = y(() => {
122
171
  if (c) {
123
- const v = localStorage.getItem(c), E = v ? parseInt(v, 10) : NaN;
124
- if (Number.isFinite(E) && E >= t) return E;
172
+ const N = localStorage.getItem(c), D = N ? parseInt(N, 10) : NaN;
173
+ if (Number.isFinite(D) && D >= t) return D;
125
174
  }
126
- return a;
127
- }), i = ee(null), [u, h] = b(!1);
175
+ return r;
176
+ }), l = K(null), [m, p] = y(!1);
128
177
  I(() => {
129
- !c || u || localStorage.setItem(c, String(Math.round(s)));
130
- }, [c, s, u]);
131
- const f = G((v) => {
132
- v.preventDefault(), h(!0), v.target.setPointerCapture(v.pointerId);
178
+ !c || m || localStorage.setItem(c, String(Math.round(o)));
179
+ }, [c, o, m]);
180
+ const b = G((N) => {
181
+ N.preventDefault(), p(!0), N.target.setPointerCapture(N.pointerId);
133
182
  }, []), g = G(
134
- (v) => {
135
- if (!u || !i.current) return;
136
- const E = i.current.getBoundingClientRect(), O = v.clientX - E.left, R = E.width - r - me, j = Math.max(t, Math.min(O, R));
137
- o(j);
183
+ (N) => {
184
+ if (!m || !l.current) return;
185
+ const D = l.current.getBoundingClientRect(), U = N.clientX - D.left, R = D.width - a - be, W = Math.max(t, Math.min(U, R));
186
+ i(W);
138
187
  },
139
- [u, t, r]
140
- ), M = G((v) => {
141
- h(!1);
188
+ [m, t, a]
189
+ ), O = G((N) => {
190
+ p(!1);
142
191
  try {
143
- v.target.releasePointerCapture(v.pointerId);
192
+ N.target.releasePointerCapture(N.pointerId);
144
193
  } catch {
145
194
  }
146
195
  }, []);
147
196
  return /* @__PURE__ */ d(
148
197
  "div",
149
198
  {
150
- ref: i,
151
- className: `splitter ${l ?? ""} ${u ? "dragging" : ""}`,
199
+ ref: l,
200
+ className: `splitter ${s ?? ""} ${m ? "dragging" : ""}`,
152
201
  style: {
153
- gridTemplateColumns: `${s}px ${me}px 1fr`
202
+ gridTemplateColumns: `${o}px ${be}px 1fr`
154
203
  },
155
204
  children: [
156
205
  /* @__PURE__ */ n("div", { className: "splitter-pane splitter-left", children: e[0] }),
@@ -160,11 +209,11 @@ function Ue({
160
209
  className: "splitter-handle",
161
210
  role: "separator",
162
211
  "aria-orientation": "vertical",
163
- "aria-valuenow": Math.round(s),
164
- onPointerDown: f,
212
+ "aria-valuenow": Math.round(o),
213
+ onPointerDown: b,
165
214
  onPointerMove: g,
166
- onPointerUp: M,
167
- onPointerCancel: M
215
+ onPointerUp: O,
216
+ onPointerCancel: O
168
217
  }
169
218
  ),
170
219
  /* @__PURE__ */ n("div", { className: "splitter-pane splitter-right", children: e[1] })
@@ -172,7 +221,39 @@ function Ue({
172
221
  }
173
222
  );
174
223
  }
175
- const se = {
224
+ const tt = ["image/png", "image/jpeg", "image/gif", "image/webp"];
225
+ function Me(e) {
226
+ return tt.includes(e);
227
+ }
228
+ function Le(e) {
229
+ return new Promise((r, t) => {
230
+ if (!Me(e.type)) {
231
+ t(new Error(`unsupported image type "${e.type || "unknown"}" (png, jpeg, gif, webp only)`));
232
+ return;
233
+ }
234
+ const a = new FileReader();
235
+ a.onerror = () => t(a.error ?? new Error("failed to read file")), a.onload = () => {
236
+ const c = String(a.result ?? ""), s = c.indexOf(",");
237
+ if (s < 0) {
238
+ t(new Error("could not decode image data"));
239
+ return;
240
+ }
241
+ r({ mediaType: e.type, data: c.slice(s + 1) });
242
+ }, a.readAsDataURL(e);
243
+ });
244
+ }
245
+ function nt(e) {
246
+ if (!e) return null;
247
+ for (let r = 0; r < e.length; r++) {
248
+ const t = e[r];
249
+ if (t.kind === "file" && Me(t.type)) {
250
+ const a = t.getAsFile();
251
+ if (a) return a;
252
+ }
253
+ }
254
+ return null;
255
+ }
256
+ const me = {
176
257
  "doc.rfc.draft": "#c99a3a",
177
258
  "doc.rfc.review": "#6a7bd6",
178
259
  "doc.rfc.confirmed": "#3a9ad6",
@@ -184,119 +265,122 @@ const se = {
184
265
  "chunk.review": "#6a7bd6",
185
266
  "chunk.confirmed": "#3a9ad6",
186
267
  "chunk.done": "#3aa06a"
187
- }, Be = 0.16;
188
- function ie(e) {
189
- return e && Object.keys(e).length > 0 ? e : se;
268
+ }, at = 0.16;
269
+ function fe(e) {
270
+ return e && Object.keys(e).length > 0 ? e : me;
190
271
  }
191
- function Ce(e, a, t) {
192
- const r = e ?? "", c = a ?? "";
193
- if (r && c && t[`doc.${r}.${c}`]) return t[`doc.${r}.${c}`];
194
- if (r && t[`doc.${r}`]) return t[`doc.${r}`];
272
+ function De(e, r, t) {
273
+ const a = e ?? "", c = r ?? "";
274
+ if (a && c && t[`doc.${a}.${c}`]) return t[`doc.${a}.${c}`];
275
+ if (a && t[`doc.${a}`]) return t[`doc.${a}`];
195
276
  }
196
- function Fe(e, a) {
277
+ function rt(e, r) {
197
278
  const t = e ?? "";
198
- return t ? a[`chunk.${t}`] : void 0;
279
+ return t ? r[`chunk.${t}`] : void 0;
199
280
  }
200
- function He(e) {
201
- const a = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());
202
- if (!a) return;
203
- let t = a[1];
281
+ function ct(e) {
282
+ const r = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());
283
+ if (!r) return;
284
+ let t = r[1];
204
285
  t.length === 3 && (t = t[0] + t[0] + t[1] + t[1] + t[2] + t[2]);
205
- const r = parseInt(t.slice(0, 2), 16), c = parseInt(t.slice(2, 4), 16), l = parseInt(t.slice(4, 6), 16);
206
- return `rgba(${r}, ${c}, ${l}, ${Be})`;
286
+ const a = parseInt(t.slice(0, 2), 16), c = parseInt(t.slice(2, 4), 16), s = parseInt(t.slice(4, 6), 16);
287
+ return `rgba(${a}, ${c}, ${s}, ${at})`;
207
288
  }
208
- function de(e) {
289
+ function ge(e) {
209
290
  if (!e) return;
210
- const a = He(e);
211
- if (a)
212
- return { background: a, borderLeft: `3px solid ${e}` };
291
+ const r = ct(e);
292
+ if (r)
293
+ return { background: r, borderLeft: `3px solid ${e}` };
213
294
  }
214
- function We(e) {
215
- const a = /* @__PURE__ */ new Map();
216
- e.forEach((c) => a.set(c.id, { row: c, children: [] }));
295
+ function ot(e) {
296
+ const r = /* @__PURE__ */ new Map();
297
+ e.forEach((c) => r.set(c.id, { row: c, children: [] }));
217
298
  const t = [];
218
299
  e.forEach((c) => {
219
- const l = a.get(c.id);
220
- c.parent_id && a.has(c.parent_id) ? a.get(c.parent_id).children.push(l) : t.push(l);
300
+ const s = r.get(c.id);
301
+ c.parent_id && r.has(c.parent_id) ? r.get(c.parent_id).children.push(s) : t.push(s);
221
302
  });
222
- const r = (c) => {
223
- c.sort((l, s) => l.row.position - s.row.position), c.forEach((l) => r(l.children));
303
+ const a = (c) => {
304
+ c.sort((s, o) => s.row.position - o.row.position), c.forEach((s) => a(s.children));
224
305
  };
225
- return r(t), t;
306
+ return a(t), t;
226
307
  }
227
- function _e(e, a) {
308
+ function ke(e) {
309
+ return e === "image" ? "🖼" : e === "mermaid" ? "📊" : "";
310
+ }
311
+ function Re(e, r) {
228
312
  for (const t of e) {
229
- if (t.row.id === a) return t;
230
- const r = _e(t.children, a);
231
- if (r) return r;
313
+ if (t.row.id === r) return t;
314
+ const a = Re(t.children, r);
315
+ if (a) return a;
232
316
  }
233
317
  }
234
- function ze({
318
+ function st({
235
319
  tree: e,
236
- selectedId: a,
320
+ selectedId: r,
237
321
  onSelect: t,
238
- colorEnabled: r,
322
+ colorEnabled: a,
239
323
  scheme: c,
240
- linkedIds: l
324
+ linkedIds: s
241
325
  }) {
242
- const [s, o] = b(() => /* @__PURE__ */ new Map()), i = G((h) => {
243
- o((f) => {
244
- const g = new Map(f);
245
- return g.set(h, f.get(h) === !1), g;
326
+ const [o, i] = y(() => /* @__PURE__ */ new Map()), l = G((p) => {
327
+ i((b) => {
328
+ const g = new Map(b);
329
+ return g.set(p, b.get(p) === !1), g;
246
330
  });
247
331
  }, []);
248
332
  I(() => {
249
- if (!a) return;
250
- const h = Je(e, a);
251
- h.length !== 0 && o((f) => {
333
+ if (!r) return;
334
+ const p = it(e, r);
335
+ p.length !== 0 && i((b) => {
252
336
  let g = !1;
253
- const M = new Map(f);
254
- for (const v of h)
255
- M.get(v) === !1 && (M.set(v, !0), g = !0);
256
- return g ? M : f;
337
+ const O = new Map(b);
338
+ for (const N of p)
339
+ O.get(N) === !1 && (O.set(N, !0), g = !0);
340
+ return g ? O : b;
257
341
  });
258
- }, [e, a]);
259
- const u = r ? ie(c) : null;
260
- return e.length === 0 ? /* @__PURE__ */ n("div", { className: "empty", children: /* @__PURE__ */ n("p", { children: "No chunks." }) }) : /* @__PURE__ */ n("ul", { className: "tree chunk-tree", children: e.map((h) => /* @__PURE__ */ n(
261
- xe,
342
+ }, [e, r]);
343
+ const m = a ? fe(c) : null;
344
+ return e.length === 0 ? /* @__PURE__ */ n("div", { className: "empty", children: /* @__PURE__ */ n("p", { children: "No chunks." }) }) : /* @__PURE__ */ n("ul", { className: "tree chunk-tree", children: e.map((p) => /* @__PURE__ */ n(
345
+ Ae,
262
346
  {
263
- node: h,
264
- expanded: s,
265
- toggle: i,
266
- selectedId: a,
347
+ node: p,
348
+ expanded: o,
349
+ toggle: l,
350
+ selectedId: r,
267
351
  onSelect: t,
268
- tintScheme: u,
269
- linkedIds: l
352
+ tintScheme: m,
353
+ linkedIds: s
270
354
  },
271
- h.row.id
355
+ p.row.id
272
356
  )) });
273
357
  }
274
- function Je(e, a) {
275
- const t = [], r = (c, l) => {
276
- for (const s of c) {
277
- if (s.row.id === a)
278
- return t.push(...l), !0;
279
- if (r(s.children, [...l, s.row.id])) return !0;
358
+ function it(e, r) {
359
+ const t = [], a = (c, s) => {
360
+ for (const o of c) {
361
+ if (o.row.id === r)
362
+ return t.push(...s), !0;
363
+ if (a(o.children, [...s, o.row.id])) return !0;
280
364
  }
281
365
  return !1;
282
366
  };
283
- return r(e, []), t;
367
+ return a(e, []), t;
284
368
  }
285
- function xe({ node: e, expanded: a, toggle: t, selectedId: r, onSelect: c, tintScheme: l, linkedIds: s }) {
286
- const o = e.children.length > 0, i = a.get(e.row.id) !== !1, u = r === e.row.id, h = l ? de(Fe(e.row.status, l)) : void 0, f = s?.has(e.row.id);
287
- return /* @__PURE__ */ d("li", { className: `node chunk-node ${u ? "selected" : ""}`, children: [
288
- /* @__PURE__ */ d("div", { className: "row chunk-row", style: h, children: [
369
+ function Ae({ node: e, expanded: r, toggle: t, selectedId: a, onSelect: c, tintScheme: s, linkedIds: o }) {
370
+ const i = e.children.length > 0, l = r.get(e.row.id) !== !1, m = a === e.row.id, p = s ? ge(rt(e.row.status, s)) : void 0, b = o?.has(e.row.id);
371
+ return /* @__PURE__ */ d("li", { className: `node chunk-node ${m ? "selected" : ""}`, children: [
372
+ /* @__PURE__ */ d("div", { className: "row chunk-row", style: p, children: [
289
373
  /* @__PURE__ */ n(
290
374
  "button",
291
375
  {
292
376
  type: "button",
293
377
  className: "tree-caret",
294
- "aria-label": i ? "collapse" : "expand",
295
- disabled: !o,
378
+ "aria-label": l ? "collapse" : "expand",
379
+ disabled: !i,
296
380
  onClick: (g) => {
297
- g.stopPropagation(), o && t(e.row.id);
381
+ g.stopPropagation(), i && t(e.row.id);
298
382
  },
299
- children: o ? i ? "▼" : "▶" : "·"
383
+ children: i ? l ? "▼" : "▶" : "·"
300
384
  }
301
385
  ),
302
386
  /* @__PURE__ */ d(
@@ -307,71 +391,105 @@ function xe({ node: e, expanded: a, toggle: t, selectedId: r, onSelect: c, tintS
307
391
  onClick: () => c(e),
308
392
  title: e.row.title,
309
393
  children: [
394
+ ke(e.row.type) && /* @__PURE__ */ n("span", { className: "chunk-type-icon", "aria-hidden": !0, children: ke(e.row.type) }),
310
395
  /* @__PURE__ */ n("span", { className: "chunk-title", children: e.row.title || "(untitled)" }),
311
396
  e.row.type && /* @__PURE__ */ n("span", { className: "chunk-badge", children: e.row.type }),
312
397
  e.row.status && /* @__PURE__ */ n("span", { className: "chunk-badge chunk-status", children: e.row.status }),
313
- f && /* @__PURE__ */ n("span", { className: "chunk-link-badge", title: "Has cross-reference links", "aria-label": "linked", children: "🔗" })
398
+ b && /* @__PURE__ */ n("span", { className: "chunk-link-badge", title: "Has cross-reference links", "aria-label": "linked", children: "🔗" })
314
399
  ]
315
400
  }
316
401
  )
317
402
  ] }),
318
- o && i && /* @__PURE__ */ n("ul", { className: "children chunk-children", children: e.children.map((g) => /* @__PURE__ */ n(
319
- xe,
403
+ i && l && /* @__PURE__ */ n("ul", { className: "children chunk-children", children: e.children.map((g) => /* @__PURE__ */ n(
404
+ Ae,
320
405
  {
321
406
  node: g,
322
- expanded: a,
407
+ expanded: r,
323
408
  toggle: t,
324
- selectedId: r,
409
+ selectedId: a,
325
410
  onSelect: c,
326
- tintScheme: l,
327
- linkedIds: s
411
+ tintScheme: s,
412
+ linkedIds: o
328
413
  },
329
414
  g.row.id
330
415
  )) })
331
416
  ] });
332
417
  }
333
- function Ve({ chunk: e, scope: a, browse: t, onClose: r, onSaved: c }) {
334
- const l = ce(), [s, o] = b(e.title), [i, u] = b(e.type ?? ""), [h, f] = b(e.status ?? ""), [g, M] = b(e.body ?? ""), [v, E] = b(
418
+ let lt = 0;
419
+ function ie({ code: e }) {
420
+ const r = K(null), [t, a] = y({});
421
+ return I(() => {
422
+ let c = !1;
423
+ return (async () => {
424
+ try {
425
+ const s = (await import("mermaid")).default, o = r.current?.closest("[data-theme]")?.getAttribute("data-theme"), i = o ? o === "dark" : !0;
426
+ s.initialize({ startOnLoad: !1, theme: i ? "dark" : "default", securityLevel: "strict" });
427
+ const { svg: l } = await s.render(`lc-mmd-${lt++}`, e);
428
+ c || a({ svg: l });
429
+ } catch {
430
+ c || a({ err: !0 });
431
+ }
432
+ })(), () => {
433
+ c = !0;
434
+ };
435
+ }, [e]), t.err ? /* @__PURE__ */ n("pre", { className: "md-pre md-mermaid-error", title: "diagram failed to render", children: /* @__PURE__ */ n("code", { children: e }) }) : t.svg ? /* @__PURE__ */ n("div", { ref: r, className: "md-mermaid", dangerouslySetInnerHTML: { __html: t.svg } }) : /* @__PURE__ */ n("div", { ref: r, className: "md-mermaid md-mermaid-loading", children: "rendering diagram…" });
436
+ }
437
+ function dt({ chunk: e, scope: r, browse: t, onClose: a, onSaved: c }) {
438
+ const s = se(), [o, i] = y(e.title), [l, m] = y(e.type ?? ""), [p, b] = y(e.status ?? ""), [g, O] = y(e.body ?? ""), [N, D] = y(
335
439
  e.fields ? JSON.stringify(e.fields, null, 2) : ""
336
- ), [O, R] = b(!1), [j, D] = b(null), [U, $] = b(!1);
337
- return /* @__PURE__ */ n("div", { className: "modal-overlay", onClick: r, children: /* @__PURE__ */ d("form", { className: "modal chunk-editor", onClick: (k) => k.stopPropagation(), onSubmit: async (k) => {
338
- k.preventDefault(), D(null), $(!1);
339
- const N = {
440
+ ), [U, R] = y(!1), [W, M] = y(null), [z, j] = y(!1), B = l === "mermaid", _ = l === "image" || !!e.asset, [w, L] = y(g);
441
+ I(() => {
442
+ if (!B) return;
443
+ const u = setTimeout(() => L(g), 400);
444
+ return () => clearTimeout(u);
445
+ }, [g, B]);
446
+ const F = async (u) => {
447
+ M(null), R(!0);
448
+ try {
449
+ const { mediaType: h, data: C } = await Le(u), E = await s.documentSetAsset(e.id, h, C, u.name, r, t);
450
+ c(E), a();
451
+ } catch (h) {
452
+ M(h instanceof Error ? h.message : String(h)), R(!1);
453
+ }
454
+ };
455
+ return /* @__PURE__ */ n("div", { className: "modal-overlay", onClick: a, children: /* @__PURE__ */ d("form", { className: "modal chunk-editor", onClick: (u) => u.stopPropagation(), onSubmit: async (u) => {
456
+ u.preventDefault(), M(null), j(!1);
457
+ const h = {
340
458
  body: g,
341
- title: s,
342
- type: i,
343
- status: h
459
+ title: o,
460
+ type: l,
461
+ status: p
344
462
  };
345
- if (v.trim() !== "")
463
+ if (N.trim() !== "")
346
464
  try {
347
- N.fields = JSON.parse(v);
465
+ h.fields = JSON.parse(N);
348
466
  } catch {
349
- D("fields must be valid JSON");
467
+ M("fields must be valid JSON");
350
468
  return;
351
469
  }
352
470
  R(!0);
353
471
  try {
354
- const _ = await l.documentUpdateChunk(e.id, e.revision, N, a, t);
355
- c(_), r();
356
- } catch (_) {
357
- const F = _ instanceof Error ? _.message : String(_);
358
- D(F), $(/revision conflict/i.test(F)), R(!1);
472
+ const C = await s.documentUpdateChunk(e.id, e.revision, h, r, t);
473
+ c(C), a();
474
+ } catch (C) {
475
+ const E = C instanceof Error ? C.message : String(C);
476
+ M(E), j(/revision conflict/i.test(E)), R(!1);
359
477
  }
360
478
  }, children: [
361
479
  /* @__PURE__ */ d("div", { className: "modal-header sticky-top", children: [
362
480
  /* @__PURE__ */ n("h3", { children: "Edit chunk" }),
363
481
  /* @__PURE__ */ d("div", { className: "modal-buttons modal-buttons-top", children: [
364
- /* @__PURE__ */ n("button", { type: "button", onClick: r, disabled: O, children: "cancel" }),
365
- /* @__PURE__ */ n("button", { type: "submit", className: "primary", disabled: O, children: O ? "saving…" : "save" })
482
+ /* @__PURE__ */ n("button", { type: "button", onClick: a, disabled: U, children: "cancel" }),
483
+ /* @__PURE__ */ n("button", { type: "submit", className: "primary", disabled: U, children: U ? "saving…" : "save" })
366
484
  ] })
367
485
  ] }),
368
- j && /* @__PURE__ */ d("div", { className: "modal-err", children: [
369
- j,
370
- U && " — reopen the chunk to load the latest, then reapply your edit."
486
+ W && /* @__PURE__ */ d("div", { className: "modal-err", children: [
487
+ W,
488
+ z && " — reopen the chunk to load the latest, then reapply your edit."
371
489
  ] }),
372
490
  /* @__PURE__ */ d("label", { className: "path-field", children: [
373
491
  /* @__PURE__ */ n("span", { children: "Title" }),
374
- /* @__PURE__ */ n("input", { className: "path-modal-input", value: s, onChange: (k) => o(k.target.value) })
492
+ /* @__PURE__ */ n("input", { className: "path-modal-input", value: o, onChange: (u) => i(u.target.value) })
375
493
  ] }),
376
494
  /* @__PURE__ */ d("div", { className: "chunk-editor-row", children: [
377
495
  /* @__PURE__ */ d("label", { className: "path-field", children: [
@@ -380,9 +498,9 @@ function Ve({ chunk: e, scope: a, browse: t, onClose: r, onSaved: c }) {
380
498
  "input",
381
499
  {
382
500
  className: "path-modal-input",
383
- value: i,
501
+ value: l,
384
502
  placeholder: "(none)",
385
- onChange: (k) => u(k.target.value)
503
+ onChange: (u) => m(u.target.value)
386
504
  }
387
505
  )
388
506
  ] }),
@@ -392,25 +510,44 @@ function Ve({ chunk: e, scope: a, browse: t, onClose: r, onSaved: c }) {
392
510
  "input",
393
511
  {
394
512
  className: "path-modal-input",
395
- value: h,
513
+ value: p,
396
514
  placeholder: "(none)",
397
- onChange: (k) => f(k.target.value)
515
+ onChange: (u) => b(u.target.value)
398
516
  }
399
517
  )
400
518
  ] })
401
519
  ] }),
520
+ _ && /* @__PURE__ */ d("label", { className: "path-field", children: [
521
+ /* @__PURE__ */ n("span", { children: "Replace image" }),
522
+ /* @__PURE__ */ n(
523
+ "input",
524
+ {
525
+ type: "file",
526
+ accept: "image/png,image/jpeg,image/gif,image/webp",
527
+ disabled: U,
528
+ onChange: (u) => {
529
+ const h = u.target.files?.[0];
530
+ h && F(h);
531
+ }
532
+ }
533
+ )
534
+ ] }),
402
535
  /* @__PURE__ */ d("label", { className: "path-field", children: [
403
- /* @__PURE__ */ n("span", { children: "Body (Markdown)" }),
536
+ /* @__PURE__ */ n("span", { children: B ? "Mermaid source" : _ ? "Caption (optional)" : "Body (Markdown)" }),
404
537
  /* @__PURE__ */ n(
405
538
  "textarea",
406
539
  {
407
540
  className: "modal-textarea chunk-body-input",
408
- rows: 12,
541
+ rows: B ? 8 : 12,
409
542
  value: g,
410
- onChange: (k) => M(k.target.value)
543
+ onChange: (u) => O(u.target.value)
411
544
  }
412
545
  )
413
546
  ] }),
547
+ B && /* @__PURE__ */ d("div", { className: "path-field", children: [
548
+ /* @__PURE__ */ n("span", { children: "Preview" }),
549
+ /* @__PURE__ */ n("div", { className: "chunk-mermaid-preview", children: w.trim() ? /* @__PURE__ */ n(ie, { code: w }) : /* @__PURE__ */ n("p", { className: "doc-empty-body", children: "(enter Mermaid source above)" }) })
550
+ ] }),
414
551
  /* @__PURE__ */ d("label", { className: "path-field", children: [
415
552
  /* @__PURE__ */ n("span", { children: "Fields (JSON, optional)" }),
416
553
  /* @__PURE__ */ n(
@@ -418,118 +555,118 @@ function Ve({ chunk: e, scope: a, browse: t, onClose: r, onSaved: c }) {
418
555
  {
419
556
  className: "modal-textarea chunk-fields-input",
420
557
  rows: 4,
421
- value: v,
558
+ value: N,
422
559
  placeholder: "{}",
423
- onChange: (k) => E(k.target.value)
560
+ onChange: (u) => D(u.target.value)
424
561
  }
425
562
  )
426
563
  ] })
427
564
  ] }) });
428
565
  }
429
- function Ze(e) {
430
- const a = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec((e ?? "").trim());
431
- if (!a) return "#888888";
432
- let t = a[1];
566
+ function ut(e) {
567
+ const r = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec((e ?? "").trim());
568
+ if (!r) return "#888888";
569
+ let t = r[1];
433
570
  return t.length === 3 && (t = t[0] + t[0] + t[1] + t[1] + t[2] + t[2]), "#" + t.toLowerCase();
434
571
  }
435
- function qe({
572
+ function ht({
436
573
  documentId: e,
437
- rootChunkId: a,
574
+ rootChunkId: r,
438
575
  docType: t,
439
- docStatus: r,
576
+ docStatus: a,
440
577
  chunkStatuses: c,
441
- scope: l,
442
- browse: s,
443
- onClose: o,
444
- onSaved: i
578
+ scope: s,
579
+ browse: o,
580
+ onClose: i,
581
+ onSaved: l
445
582
  }) {
446
- const u = ce(), [h, f] = b(null), [g, M] = b(!1), [v, E] = b({}), [O, R] = b(!1), [j, D] = b(null), [U, $] = b(null), J = A(() => {
447
- const p = new Set(Object.keys(se));
448
- t && p.add(`doc.${t}.${r || "draft"}`);
449
- for (const m of c) m && p.add(`chunk.${m}`);
450
- return [...p].sort();
451
- }, [t, r, c]);
583
+ const m = se(), [p, b] = y(null), [g, O] = y(!1), [N, D] = y({}), [U, R] = y(!1), [W, M] = y(null), [z, j] = y(null), B = H(() => {
584
+ const u = new Set(Object.keys(me));
585
+ t && u.add(`doc.${t}.${a || "draft"}`);
586
+ for (const h of c) h && u.add(`chunk.${h}`);
587
+ return [...u].sort();
588
+ }, [t, a, c]);
452
589
  I(() => {
453
- let p = !1;
454
- return u.documentGetChunk(a, l, s).then((m) => {
455
- if (p) return;
456
- f(m);
457
- const T = m.fields ?? {};
458
- M(T.color_enabled === !0);
459
- const S = T.color_scheme ?? {};
460
- E({ ...se, ...S });
461
- }).catch((m) => !p && $(m instanceof Error ? m.message : String(m))), () => {
462
- p = !0;
590
+ let u = !1;
591
+ return m.documentGetChunk(r, s, o).then((h) => {
592
+ if (u) return;
593
+ b(h);
594
+ const C = h.fields ?? {};
595
+ O(C.color_enabled === !0);
596
+ const E = C.color_scheme ?? {};
597
+ D({ ...me, ...E });
598
+ }).catch((h) => !u && j(h instanceof Error ? h.message : String(h))), () => {
599
+ u = !0;
463
600
  };
464
- }, [u, a, l, s]);
465
- const k = (p, m) => E((T) => ({ ...T, [p]: m })), N = (p) => ({
466
- ...p ?? {},
601
+ }, [m, r, s, o]);
602
+ const _ = (u, h) => D((C) => ({ ...C, [u]: h })), w = (u) => ({
603
+ ...u ?? {},
467
604
  color_enabled: g,
468
- color_scheme: v
469
- }), _ = async () => {
470
- if (h) {
471
- R(!0), $(null), D(null);
605
+ color_scheme: N
606
+ }), L = async () => {
607
+ if (p) {
608
+ R(!0), j(null), M(null);
472
609
  try {
473
- await u.documentUpdateChunk(
474
- a,
475
- h.revision,
476
- { fields: N(h.fields) },
477
- l,
478
- s
479
- ), i(), o();
480
- } catch (p) {
481
- $(p instanceof Error ? p.message : String(p)), R(!1);
610
+ await m.documentUpdateChunk(
611
+ r,
612
+ p.revision,
613
+ { fields: w(p.fields) },
614
+ s,
615
+ o
616
+ ), l(), i();
617
+ } catch (u) {
618
+ j(u instanceof Error ? u.message : String(u)), R(!1);
482
619
  }
483
620
  }
484
621
  }, F = async () => {
485
622
  if (!t) {
486
- $("this document has no type to match");
623
+ j("this document has no type to match");
487
624
  return;
488
625
  }
489
- R(!0), $(null), D(null);
626
+ R(!0), j(null), M(null);
490
627
  try {
491
- const { documents: p } = await u.documentsSummary({ underPath: "/" }, l, s), m = (p ?? []).filter(
492
- (S) => S.type === t && S.document_id !== e && S.root_chunk_id
628
+ const { documents: u } = await m.documentsSummary({ underPath: "/" }, s, o), h = (u ?? []).filter(
629
+ (E) => E.type === t && E.document_id !== e && E.root_chunk_id
493
630
  );
494
- let T = 0;
495
- for (const S of m)
631
+ let C = 0;
632
+ for (const E of h)
496
633
  try {
497
- const W = await u.documentGetChunk(S.root_chunk_id, l, s);
498
- await u.documentUpdateChunk(
499
- S.root_chunk_id,
500
- W.revision,
501
- { fields: N(W.fields) },
502
- l,
503
- s
504
- ), T++;
634
+ const A = await m.documentGetChunk(E.root_chunk_id, s, o);
635
+ await m.documentUpdateChunk(
636
+ E.root_chunk_id,
637
+ A.revision,
638
+ { fields: w(A.fields) },
639
+ s,
640
+ o
641
+ ), C++;
505
642
  } catch {
506
643
  }
507
- D(`Applied to ${T} other ${t} document(s).`), i();
508
- } catch (p) {
509
- $(p instanceof Error ? p.message : String(p));
644
+ M(`Applied to ${C} other ${t} document(s).`), l();
645
+ } catch (u) {
646
+ j(u instanceof Error ? u.message : String(u));
510
647
  } finally {
511
648
  R(!1);
512
649
  }
513
- }, Z = J.filter((p) => p.startsWith("doc.")), P = J.filter((p) => p.startsWith("chunk."));
514
- return /* @__PURE__ */ n("div", { className: "modal-overlay", onClick: o, children: /* @__PURE__ */ d("div", { className: "modal scheme-editor", onClick: (p) => p.stopPropagation(), children: [
650
+ }, Q = B.filter((u) => u.startsWith("doc.")), X = B.filter((u) => u.startsWith("chunk."));
651
+ return /* @__PURE__ */ n("div", { className: "modal-overlay", onClick: i, children: /* @__PURE__ */ d("div", { className: "modal scheme-editor", onClick: (u) => u.stopPropagation(), children: [
515
652
  /* @__PURE__ */ d("div", { className: "scheme-editor-head", children: [
516
653
  /* @__PURE__ */ n("h3", { children: "Document colors" }),
517
654
  /* @__PURE__ */ d("div", { className: "scheme-editor-actions", children: [
518
- /* @__PURE__ */ n("button", { type: "button", onClick: o, disabled: O, children: "cancel" }),
655
+ /* @__PURE__ */ n("button", { type: "button", onClick: i, disabled: U, children: "cancel" }),
519
656
  /* @__PURE__ */ n("button", { type: "button", className: "primary", onClick: () => {
520
- _();
521
- }, disabled: O || !h, children: O ? "saving…" : "save" })
657
+ L();
658
+ }, disabled: U || !p, children: U ? "saving…" : "save" })
522
659
  ] })
523
660
  ] }),
524
- U && /* @__PURE__ */ n("div", { className: "modal-err", children: U }),
525
- h ? /* @__PURE__ */ d(q, { children: [
661
+ z && /* @__PURE__ */ n("div", { className: "modal-err", children: z }),
662
+ p ? /* @__PURE__ */ d(q, { children: [
526
663
  /* @__PURE__ */ d("label", { className: "scheme-toggle", children: [
527
664
  /* @__PURE__ */ n(
528
665
  "input",
529
666
  {
530
667
  type: "checkbox",
531
668
  checked: g,
532
- onChange: (p) => M(p.target.checked)
669
+ onChange: (u) => O(u.target.checked)
533
670
  }
534
671
  ),
535
672
  /* @__PURE__ */ n("span", { children: "Enable coloring for this document" })
@@ -537,277 +674,372 @@ function qe({
537
674
  /* @__PURE__ */ n("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." }),
538
675
  /* @__PURE__ */ d("div", { className: "scheme-group", children: [
539
676
  /* @__PURE__ */ n("h4", { children: "Document (type · status)" }),
540
- Z.map((p) => /* @__PURE__ */ n(pe, { label: p.slice(4), value: v[p], onChange: (m) => k(p, m) }, p))
677
+ Q.map((u) => /* @__PURE__ */ n(ve, { label: u.slice(4), value: N[u], onChange: (h) => _(u, h) }, u))
541
678
  ] }),
542
679
  /* @__PURE__ */ d("div", { className: "scheme-group", children: [
543
680
  /* @__PURE__ */ n("h4", { children: "Chunks (status)" }),
544
- P.map((p) => /* @__PURE__ */ n(pe, { label: p.slice(6), value: v[p], onChange: (m) => k(p, m) }, p))
681
+ X.map((u) => /* @__PURE__ */ n(ve, { label: u.slice(6), value: N[u], onChange: (h) => _(u, h) }, u))
545
682
  ] }),
546
683
  /* @__PURE__ */ d("div", { className: "scheme-editor-foot", children: [
547
684
  /* @__PURE__ */ d("button", { type: "button", onClick: () => {
548
685
  F();
549
- }, disabled: O || !t, title: t ? `Apply this palette to every other ${t} document` : "This document has no type", children: [
686
+ }, disabled: U || !t, title: t ? `Apply this palette to every other ${t} document` : "This document has no type", children: [
550
687
  "copy to all ",
551
688
  t || "same-type",
552
689
  " documents"
553
690
  ] }),
554
- j && /* @__PURE__ */ n("span", { className: "scheme-status", children: j })
691
+ W && /* @__PURE__ */ n("span", { className: "scheme-status", children: W })
555
692
  ] })
556
693
  ] }) : /* @__PURE__ */ n("p", { className: "modal-context", children: "Loading…" })
557
694
  ] }) });
558
695
  }
559
- function pe({ label: e, value: a, onChange: t }) {
560
- const r = Ze(a);
696
+ function ve({ label: e, value: r, onChange: t }) {
697
+ const a = ut(r);
561
698
  return /* @__PURE__ */ d("label", { className: "scheme-row", children: [
562
- /* @__PURE__ */ n("input", { type: "color", value: r, onChange: (c) => t(c.target.value) }),
699
+ /* @__PURE__ */ n("input", { type: "color", value: a, onChange: (c) => t(c.target.value) }),
563
700
  /* @__PURE__ */ n("span", { className: "scheme-key", children: e }),
564
- /* @__PURE__ */ n("code", { className: "scheme-hex", children: r })
701
+ /* @__PURE__ */ n("code", { className: "scheme-hex", children: a })
565
702
  ] });
566
703
  }
567
- let Qe = 0;
568
- function Se({ code: e }) {
569
- const a = ee(null), [t, r] = b({});
570
- return I(() => {
571
- let c = !1;
572
- return (async () => {
573
- try {
574
- const l = (await import("mermaid")).default, s = a.current?.closest("[data-theme]")?.getAttribute("data-theme"), o = s ? s === "dark" : !0;
575
- l.initialize({ startOnLoad: !1, theme: o ? "dark" : "default", securityLevel: "strict" });
576
- const { svg: i } = await l.render(`lc-mmd-${Qe++}`, e);
577
- c || r({ svg: i });
578
- } catch {
579
- c || r({ err: !0 });
580
- }
581
- })(), () => {
582
- c = !0;
583
- };
584
- }, [e]), t.err ? /* @__PURE__ */ n("pre", { className: "md-pre md-mermaid-error", title: "diagram failed to render", children: /* @__PURE__ */ n("code", { children: e }) }) : t.svg ? /* @__PURE__ */ n("div", { ref: a, className: "md-mermaid", dangerouslySetInnerHTML: { __html: t.svg } }) : /* @__PURE__ */ n("div", { ref: a, className: "md-mermaid md-mermaid-loading", children: "rendering diagram…" });
585
- }
586
- const oe = 24;
587
- function Xe({
704
+ const he = 24;
705
+ function mt({
588
706
  edges: e,
589
- documentId: a,
707
+ documentId: r,
590
708
  selectedId: t,
591
- onSelectChunk: r
709
+ onSelectChunk: a
592
710
  }) {
593
- const [c, l] = b(!1), [s, o] = b(!1);
711
+ const [c, s] = y(!1), [o, i] = y(!1);
594
712
  if (e.length === 0) return null;
595
- const i = t ? e.filter((f) => f.from_id === t || f.to_id === t) : [], u = s ? e : e.slice(0, oe), h = Ye(u);
713
+ const l = t ? e.filter((b) => b.from_id === t || b.to_id === t) : [], m = o ? e : e.slice(0, he), p = ft(m);
596
714
  return /* @__PURE__ */ d("div", { className: "doc-refs", children: [
597
715
  t && /* @__PURE__ */ d("div", { className: "doc-refs-list-wrap", children: [
598
716
  /* @__PURE__ */ n("h4", { children: "References" }),
599
- i.length === 0 ? /* @__PURE__ */ n("p", { className: "doc-refs-empty", children: "This chunk has no links." }) : /* @__PURE__ */ n("ul", { className: "doc-refs-list", children: i.map((f, g) => /* @__PURE__ */ n(
600
- Ke,
717
+ l.length === 0 ? /* @__PURE__ */ n("p", { className: "doc-refs-empty", children: "This chunk has no links." }) : /* @__PURE__ */ n("ul", { className: "doc-refs-list", children: l.map((b, g) => /* @__PURE__ */ n(
718
+ pt,
601
719
  {
602
- edge: f,
720
+ edge: b,
603
721
  selectedId: t,
604
- documentId: a,
605
- onSelectChunk: r
722
+ documentId: r,
723
+ onSelectChunk: a
606
724
  },
607
- `${f.from_id}-${f.to_id}-${f.kind}-${g}`
725
+ `${b.from_id}-${b.to_id}-${b.kind}-${g}`
608
726
  )) })
609
727
  ] }),
610
728
  /* @__PURE__ */ d("div", { className: "doc-graph", children: [
611
- /* @__PURE__ */ d("button", { type: "button", className: "doc-graph-toggle", onClick: () => l((f) => !f), children: [
729
+ /* @__PURE__ */ d("button", { type: "button", className: "doc-graph-toggle", onClick: () => s((b) => !b), children: [
612
730
  c ? "▼" : "▶",
613
731
  " relationship graph (",
614
732
  e.length,
615
733
  ")"
616
734
  ] }),
617
735
  c && /* @__PURE__ */ d(q, { children: [
618
- /* @__PURE__ */ n(Se, { code: h }),
619
- e.length > oe && /* @__PURE__ */ n("button", { type: "button", className: "doc-graph-more", onClick: () => o((f) => !f), children: s ? `show top ${oe}` : `show all ${e.length}` })
736
+ /* @__PURE__ */ n(ie, { code: p }),
737
+ e.length > he && /* @__PURE__ */ n("button", { type: "button", className: "doc-graph-more", onClick: () => i((b) => !b), children: o ? `show top ${he}` : `show all ${e.length}` })
620
738
  ] })
621
739
  ] })
622
740
  ] });
623
741
  }
624
- function Ke({
742
+ function pt({
625
743
  edge: e,
626
- selectedId: a,
744
+ selectedId: r,
627
745
  documentId: t,
628
- onSelectChunk: r
746
+ onSelectChunk: a
629
747
  }) {
630
- const c = e.from_id === a, l = c ? e.to_id : e.from_id, s = (c ? e.to_title : e.from_title) || l.slice(0, 8), o = c ? e.to_document_id : e.from_document_id, i = !o || o === t;
748
+ const c = e.from_id === r, s = c ? e.to_id : e.from_id, o = (c ? e.to_title : e.from_title) || s.slice(0, 8), i = c ? e.to_document_id : e.from_document_id, l = !i || i === t;
631
749
  return /* @__PURE__ */ d("li", { className: "doc-ref", children: [
632
750
  /* @__PURE__ */ n("span", { className: "doc-ref-kind", children: e.kind }),
633
751
  /* @__PURE__ */ n("span", { className: "doc-ref-arrow", "aria-hidden": !0, children: c ? "→" : "←" }),
634
- i ? /* @__PURE__ */ n("button", { type: "button", className: "doc-ref-target", onClick: () => r(l), children: s }) : /* @__PURE__ */ d("span", { className: "doc-ref-target external", title: "In another document", children: [
635
- s,
752
+ l ? /* @__PURE__ */ n("button", { type: "button", className: "doc-ref-target", onClick: () => a(s), children: o }) : /* @__PURE__ */ d("span", { className: "doc-ref-target external", title: "In another document", children: [
753
+ o,
636
754
  " ↗"
637
755
  ] })
638
756
  ] });
639
757
  }
640
- function Ye(e) {
641
- const a = ["graph LR"];
758
+ function ft(e) {
759
+ const r = ["graph LR"];
642
760
  for (const t of e) {
643
- const r = `${fe(t.from_id)}["${be(t.from_title, t.from_id)}"]`, c = `${fe(t.to_id)}["${be(t.to_title, t.to_id)}"]`, l = (t.kind || "link").replace(/[|"]/g, " ");
644
- a.push(` ${r} -->|${l}| ${c}`);
761
+ const a = `${Ne(t.from_id)}["${we(t.from_title, t.from_id)}"]`, c = `${Ne(t.to_id)}["${we(t.to_title, t.to_id)}"]`, s = (t.kind || "link").replace(/[|"]/g, " ");
762
+ r.push(` ${a} -->|${s}| ${c}`);
645
763
  }
646
- return a.join(`
764
+ return r.join(`
647
765
  `);
648
766
  }
649
- function fe(e) {
767
+ function Ne(e) {
650
768
  return "n" + e.replace(/[^a-zA-Z0-9]/g, "");
651
769
  }
652
- function be(e, a) {
653
- const r = (e ?? "").replace(/["[\]{}|<>]/g, " ").replace(/\s+/g, " ").trim() || a.slice(0, 6);
654
- return r.length > 30 ? r.slice(0, 29) + "…" : r;
770
+ function we(e, r) {
771
+ const a = (e ?? "").replace(/["[\]{}|<>]/g, " ").replace(/\s+/g, " ").trim() || r.slice(0, 6);
772
+ return a.length > 30 ? a.slice(0, 29) + "…" : a;
655
773
  }
656
- function ye({ source: e }) {
657
- return /* @__PURE__ */ n("div", { className: "md", children: /* @__PURE__ */ n(Ie, { remarkPlugins: [Ae], components: et, children: e }) });
774
+ function Ce({ source: e }) {
775
+ return /* @__PURE__ */ n("div", { className: "md", children: /* @__PURE__ */ n(qe, { remarkPlugins: [Qe], components: gt, children: e }) });
658
776
  }
659
- const et = {
777
+ const gt = {
660
778
  // react-markdown already sanitized the href; add target/rel for external links.
661
- a({ href: e, children: a }) {
662
- const t = e ?? "", r = /^https?:\/\//i.test(t);
663
- return /* @__PURE__ */ n("a", { href: t, target: r ? "_blank" : void 0, rel: r ? "noopener noreferrer" : void 0, children: a });
779
+ a({ href: e, children: r }) {
780
+ const t = e ?? "", a = /^https?:\/\//i.test(t);
781
+ return /* @__PURE__ */ n("a", { href: t, target: a ? "_blank" : void 0, rel: a ? "noopener noreferrer" : void 0, children: r });
664
782
  },
665
783
  // Let the code renderer own the block wrapper so a mermaid fence isn't wrapped
666
784
  // in a <pre> (and a normal code block gets exactly one <pre>).
667
785
  pre({ children: e }) {
668
786
  return /* @__PURE__ */ n(q, { children: e });
669
787
  },
670
- code({ className: e, children: a }) {
671
- const t = /language-(\w+)/.exec(e ?? "")?.[1], r = String(a ?? "");
672
- return t === "mermaid" ? /* @__PURE__ */ n(Se, { code: r.replace(/\n$/, "") }) : t || r.includes(`
673
- `) ? /* @__PURE__ */ n("pre", { className: "md-pre", children: /* @__PURE__ */ n("code", { className: e, children: a }) }) : /* @__PURE__ */ n("code", { children: a });
788
+ code({ className: e, children: r }) {
789
+ const t = /language-(\w+)/.exec(e ?? "")?.[1], a = String(r ?? "");
790
+ return t === "mermaid" ? /* @__PURE__ */ n(ie, { code: a.replace(/\n$/, "") }) : t || a.includes(`
791
+ `) ? /* @__PURE__ */ n("pre", { className: "md-pre", children: /* @__PURE__ */ n("code", { className: e, children: r }) }) : /* @__PURE__ */ n("code", { children: r });
674
792
  }
675
793
  };
676
- function Ee({
794
+ function yt(e) {
795
+ const r = e.fields ?? {};
796
+ return typeof r.alt == "string" && r.alt.trim() !== "" ? r.alt : e.title || "image";
797
+ }
798
+ function Pe({
677
799
  documentId: e,
678
- scope: a,
800
+ scope: r,
679
801
  titleHint: t,
680
- browse: r,
802
+ browse: a,
681
803
  principal: c,
682
- renderAssistant: l
804
+ renderAssistant: s
683
805
  }) {
684
- const s = ce(), o = A(
685
- () => r && (r.scopeId || r.tenant) ? { scopeId: r.scopeId, tenant: r.tenant } : void 0,
686
- [r?.scopeId, r?.tenant]
687
- ), [i, u] = b([]), [h, f] = b(void 0), [g, M] = b(null), [v, E] = b("chunks"), [O, R] = b(null), [j, D] = b(null), [U, $] = b(null), [J, k] = b(!1), [N, _] = b(0), [F, Z] = b(!1), [P, p] = b(null), [m, T] = b(!1), [S, W] = b([]), Q = G(() => _((y) => y + 1), []), X = A(() => We(i), [i]), K = A(() => i.find((C) => !C.parent_id)?.title || t || "document", [i, t]), te = A(
806
+ const o = se(), i = H(
807
+ () => a && (a.scopeId || a.tenant) ? { scopeId: a.scopeId, tenant: a.tenant } : void 0,
808
+ [a?.scopeId, a?.tenant]
809
+ ), [l, m] = y([]), [p, b] = y(void 0), [g, O] = y(null), [N, D] = y("chunks"), [U, R] = y(null), [W, M] = y(null), [z, j] = y(null), B = K(null), [_, w] = y(null), [L, F] = y(null), [Q, X] = y(!1), [u, h] = y(0), [C, E] = y(!1), [A, ee] = y(null), [te, ne] = y(!1), [Y, ae] = y([]), v = G(() => h((f) => f + 1), []), $ = H(() => ot(l), [l]), P = H(() => l.find((k) => !k.parent_id)?.title || t || "document", [l, t]), V = H(
688
810
  () => !!g && !g.parent_id,
689
811
  [g]
690
- ), Y = A(
691
- () => P?.root_chunk_id ?? i.find((y) => !y.parent_id)?.id,
692
- [P, i]
693
- ), w = A(
694
- () => [...new Set(i.map((y) => y.status).filter((y) => !!y))],
695
- [i]
696
- ), x = !!P?.color_enabled, L = A(() => {
697
- const y = /* @__PURE__ */ new Set();
698
- for (const C of S)
699
- y.add(C.from_id), y.add(C.to_id);
700
- return y;
701
- }, [S]), H = A(
702
- () => x ? de(Ce(P?.type, P?.status, ie(P?.color_scheme))) : void 0,
703
- [x, P?.type, P?.status, P?.color_scheme]
812
+ ), J = H(
813
+ () => A?.root_chunk_id ?? l.find((f) => !f.parent_id)?.id,
814
+ [A, l]
815
+ ), Oe = H(
816
+ () => [...new Set(l.map((f) => f.status).filter((f) => !!f))],
817
+ [l]
818
+ ), re = !!A?.color_enabled, Ue = H(() => {
819
+ const f = /* @__PURE__ */ new Set();
820
+ for (const k of Y)
821
+ f.add(k.from_id), f.add(k.to_id);
822
+ return f;
823
+ }, [Y]), je = H(
824
+ () => re ? ge(De(A?.type, A?.status, fe(A?.color_scheme))) : void 0,
825
+ [re, A?.type, A?.status, A?.color_scheme]
704
826
  );
705
827
  I(() => {
706
- let y = !1;
707
- return k(!0), $(null), s.documentQueryChunks(e, a, o).then((C) => {
708
- if (y) return;
709
- const z = C.chunks ?? [];
710
- u(z), f((V) => V ?? z.find((B) => !B.parent_id)?.id);
711
- }).catch((C) => !y && $(C instanceof Error ? C.message : String(C))).finally(() => !y && k(!1)), () => {
712
- y = !0;
828
+ let f = !1;
829
+ return X(!0), F(null), o.documentQueryChunks(e, r, i).then((k) => {
830
+ if (f) return;
831
+ const S = k.chunks ?? [];
832
+ m(S), b((x) => x ?? S.find((T) => !T.parent_id)?.id);
833
+ }).catch((k) => !f && F(k instanceof Error ? k.message : String(k))).finally(() => !f && X(!1)), () => {
834
+ f = !0;
713
835
  };
714
- }, [s, e, a, N, o]), I(() => {
715
- let y = !1;
716
- return s.documentGet(e, a, o).then((C) => !y && p(C)).catch(() => !y && p(null)), () => {
717
- y = !0;
836
+ }, [o, e, r, u, i]), I(() => {
837
+ let f = !1;
838
+ return o.documentGet(e, r, i).then((k) => !f && ee(k)).catch(() => !f && ee(null)), () => {
839
+ f = !0;
718
840
  };
719
- }, [s, e, a, N, o]), I(() => {
720
- let y = !1;
721
- return s.documentGetEdges(e, a, o).then((C) => !y && W(C.edges ?? [])).catch(() => !y && W([])), () => {
722
- y = !0;
841
+ }, [o, e, r, u, i]), I(() => {
842
+ let f = !1;
843
+ return o.documentGetEdges(e, r, i).then((k) => !f && ae(k.edges ?? [])).catch(() => !f && ae([])), () => {
844
+ f = !0;
723
845
  };
724
- }, [s, e, a, N, o]), I(() => {
725
- f(void 0), M(null), R(null), E("chunks"), p(null), W([]);
726
- }, [e, a]), I(() => {
727
- if (!h) {
728
- M(null);
846
+ }, [o, e, r, u, i]), I(() => {
847
+ b(void 0), O(null), R(null), D("chunks"), ee(null), ae([]);
848
+ }, [e, r]), I(() => {
849
+ if (!p) {
850
+ O(null);
729
851
  return;
730
852
  }
731
- let y = !1;
732
- return s.documentGetChunk(h, a, o).then((C) => !y && M(C)).catch((C) => !y && $(C instanceof Error ? C.message : String(C))), () => {
733
- y = !0;
853
+ let f = !1;
854
+ return o.documentGetChunk(p, r, i).then((k) => !f && O(k)).catch((k) => !f && F(k instanceof Error ? k.message : String(k))), () => {
855
+ f = !0;
734
856
  };
735
- }, [s, h, a, N, o]), I(() => {
736
- if (v !== "markdown" || !h) {
857
+ }, [o, p, r, u, i]), I(() => {
858
+ const f = g?.type === "image" || !!g?.asset;
859
+ if (!g || !f || !o.documentAssetObjectUrl) {
860
+ M(null), j(null);
861
+ return;
862
+ }
863
+ let k = !1, S = null;
864
+ return j(null), o.documentAssetObjectUrl(g.id, r, i).then((x) => {
865
+ if (k) {
866
+ URL.revokeObjectURL(x);
867
+ return;
868
+ }
869
+ S = x, M(x);
870
+ }).catch((x) => !k && j(x instanceof Error ? x.message : String(x))), () => {
871
+ k = !0, S && URL.revokeObjectURL(S);
872
+ };
873
+ }, [o, g, r, i]), I(() => {
874
+ if (N !== "markdown" || !p) {
737
875
  R(null);
738
876
  return;
739
877
  }
740
- const y = _e(X, h);
741
- if (!y) return;
742
- let C = !1;
743
- const z = [], V = (B, ae) => {
744
- z.push({ node: B, depth: ae }), B.children.forEach((re) => V(re, ae + 1));
878
+ const f = Re($, p);
879
+ if (!f) return;
880
+ let k = !1;
881
+ const S = [], x = (T, ce) => {
882
+ S.push({ node: T, depth: ce }), T.children.forEach((oe) => x(oe, ce + 1));
745
883
  };
746
- return V(y, 0), Promise.all(z.map((B) => s.documentGetChunk(B.node.row.id, a, o))).then((B) => {
747
- if (C) return;
748
- const ae = z.map((re, Le) => {
749
- const Re = Math.min(re.depth + 1, 6), ue = B[Le];
750
- return "#".repeat(Re) + " " + re.node.row.title + (ue.body ? `
884
+ return x(f, 0), Promise.all(S.map((T) => o.documentGetChunk(T.node.row.id, r, i))).then((T) => {
885
+ if (k) return;
886
+ const ce = S.map((oe, He) => {
887
+ const We = Math.min(oe.depth + 1, 6), Z = T[He], ue = "#".repeat(We) + " " + oe.node.row.title;
888
+ if (Z.type === "mermaid" && Z.body)
889
+ return ue + "\n\n```mermaid\n" + Z.body + "\n```\n";
890
+ if (Z.type === "image" || Z.asset) {
891
+ const ze = Z.body ? " — " + Z.body : "";
892
+ return ue + `
893
+
894
+ _🖼 image chunk_` + ze + `
895
+ `;
896
+ }
897
+ return ue + (Z.body ? `
751
898
 
752
- ` + ue.body : "") + `
899
+ ` + Z.body : "") + `
753
900
  `;
754
901
  }).join(`
755
902
  `);
756
- R(ae);
757
- }).catch((B) => !C && $(B instanceof Error ? B.message : String(B))), () => {
758
- C = !0;
903
+ R(ce);
904
+ }).catch((T) => !k && F(T instanceof Error ? T.message : String(T))), () => {
905
+ k = !0;
759
906
  };
760
- }, [s, v, h, X, a, N, o]);
761
- const ne = G((y) => f(y.row.id), []), De = G(async () => {
907
+ }, [o, N, p, $, r, u, i]);
908
+ const Fe = G((f) => b(f.row.id), []), Ge = G(async () => {
762
909
  try {
763
- const y = await s.documentExportMd(e, a, !0, o), C = new Blob([y.markdown], { type: "text/markdown" }), z = URL.createObjectURL(C), V = document.createElement("a");
764
- V.href = z, V.download = (y.title || "document").replace(/[^\w.-]+/g, "_") + ".md", V.click(), URL.revokeObjectURL(z);
765
- } catch (y) {
766
- $(y instanceof Error ? y.message : String(y));
910
+ const f = await o.documentExportMd(e, r, !0, i), k = new Blob([f.markdown], { type: "text/markdown" }), S = URL.createObjectURL(k), x = document.createElement("a");
911
+ x.href = S, x.download = (f.title || "document").replace(/[^\w.-]+/g, "_") + ".md", x.click(), URL.revokeObjectURL(S);
912
+ } catch (f) {
913
+ F(f instanceof Error ? f.message : String(f));
767
914
  }
768
- }, [s, e, a, o]);
769
- return /* @__PURE__ */ d("div", { className: "doc-viewer", children: [
770
- /* @__PURE__ */ d("div", { className: "doc-toolbar", style: H, children: [
771
- /* @__PURE__ */ n("strong", { className: "doc-title", title: K, children: K }),
915
+ }, [o, e, r, i]), le = !!o.documentCreateChunk && !!J, de = G(
916
+ async (f) => {
917
+ if (!o.documentCreateChunk || !o.documentSetAsset) return;
918
+ const k = p || J;
919
+ if (k) {
920
+ F(null);
921
+ try {
922
+ const { mediaType: S, data: x } = await Le(f), T = await o.documentCreateChunk(
923
+ e,
924
+ k,
925
+ { title: f.name || "image", type: "image" },
926
+ r,
927
+ i
928
+ );
929
+ await o.documentSetAsset(T.id, S, x, f.name, r, i), v(), b(T.id);
930
+ } catch (S) {
931
+ F(S instanceof Error ? S.message : String(S));
932
+ }
933
+ }
934
+ },
935
+ [o, e, r, i, p, J, v]
936
+ ), Be = G(async () => {
937
+ if (!o.documentCreateChunk) return;
938
+ const f = p || J;
939
+ if (f) {
940
+ F(null);
941
+ try {
942
+ const k = await o.documentCreateChunk(
943
+ e,
944
+ f,
945
+ { title: "Diagram", type: "mermaid", body: `graph TD
946
+ A[Start] --> B[End]` },
947
+ r,
948
+ i
949
+ );
950
+ v(), b(k.id), w(k);
951
+ } catch (k) {
952
+ F(k instanceof Error ? k.message : String(k));
953
+ }
954
+ }
955
+ }, [o, e, r, i, p, J, v]);
956
+ return I(() => {
957
+ if (!le) return;
958
+ const f = (k) => {
959
+ if (_ || te) return;
960
+ const S = document.activeElement, x = S?.tagName;
961
+ if (x === "INPUT" || x === "TEXTAREA" || S?.isContentEditable) return;
962
+ const T = nt(k.clipboardData?.items);
963
+ T && (k.preventDefault(), de(T));
964
+ };
965
+ return window.addEventListener("paste", f), () => window.removeEventListener("paste", f);
966
+ }, [le, _, te, de]), /* @__PURE__ */ d("div", { className: "doc-viewer", children: [
967
+ /* @__PURE__ */ n(
968
+ "input",
969
+ {
970
+ ref: B,
971
+ type: "file",
972
+ accept: "image/png,image/jpeg,image/gif,image/webp",
973
+ style: { display: "none" },
974
+ onChange: (f) => {
975
+ const k = f.target.files?.[0];
976
+ f.target.value = "", k && de(k);
977
+ }
978
+ }
979
+ ),
980
+ /* @__PURE__ */ d("div", { className: "doc-toolbar", style: je, children: [
981
+ /* @__PURE__ */ n("strong", { className: "doc-title", title: P, children: P }),
772
982
  /* @__PURE__ */ d("div", { className: "doc-toolbar-actions", children: [
983
+ le && /* @__PURE__ */ d(q, { children: [
984
+ /* @__PURE__ */ n(
985
+ "button",
986
+ {
987
+ type: "button",
988
+ onClick: () => B.current?.click(),
989
+ title: "Add an image chunk (upload — or paste a screenshot into the view)",
990
+ children: "+ image"
991
+ }
992
+ ),
993
+ /* @__PURE__ */ n(
994
+ "button",
995
+ {
996
+ type: "button",
997
+ onClick: () => {
998
+ Be();
999
+ },
1000
+ title: "Add a Mermaid diagram chunk",
1001
+ children: "+ diagram"
1002
+ }
1003
+ )
1004
+ ] }),
773
1005
  /* @__PURE__ */ n(
774
1006
  "button",
775
1007
  {
776
1008
  type: "button",
777
- className: x ? "active" : "",
778
- onClick: () => T(!0),
779
- disabled: !Y,
1009
+ className: re ? "active" : "",
1010
+ onClick: () => ne(!0),
1011
+ disabled: !J,
780
1012
  title: "Colors — tint chunk tiles + the Path tree by type/status",
781
1013
  children: "colors"
782
1014
  }
783
1015
  ),
784
1016
  /* @__PURE__ */ n("button", { type: "button", onClick: () => {
785
- De();
1017
+ Ge();
786
1018
  }, title: "Download the whole document as Markdown (.md)", children: "↓ .md" }),
787
- l && /* @__PURE__ */ n(
1019
+ s && /* @__PURE__ */ n(
788
1020
  "button",
789
1021
  {
790
1022
  type: "button",
791
- className: F ? "active" : "",
792
- onClick: () => Z((y) => !y),
1023
+ className: C ? "active" : "",
1024
+ onClick: () => E((f) => !f),
793
1025
  title: "Document Assistant — instruct an agent to restructure/import/link chunks",
794
1026
  children: "assistant"
795
1027
  }
796
1028
  ),
797
- /* @__PURE__ */ n("button", { type: "button", onClick: Q, title: "Reload", children: "↻" })
1029
+ /* @__PURE__ */ n("button", { type: "button", onClick: v, title: "Reload", children: "↻" })
798
1030
  ] })
799
1031
  ] }),
800
- U && /* @__PURE__ */ n("div", { className: "paths-err", children: U }),
1032
+ L && /* @__PURE__ */ n("div", { className: "paths-err", children: L }),
801
1033
  /* @__PURE__ */ d("div", { className: "doc-split", children: [
802
- /* @__PURE__ */ n("div", { className: "doc-chunktree", children: J && i.length === 0 ? /* @__PURE__ */ n("div", { className: "empty", children: /* @__PURE__ */ n("p", { children: "Loading…" }) }) : /* @__PURE__ */ n(
803
- ze,
1034
+ /* @__PURE__ */ n("div", { className: "doc-chunktree", children: Q && l.length === 0 ? /* @__PURE__ */ n("div", { className: "empty", children: /* @__PURE__ */ n("p", { children: "Loading…" }) }) : /* @__PURE__ */ n(
1035
+ st,
804
1036
  {
805
- tree: X,
806
- selectedId: h,
807
- onSelect: ne,
808
- colorEnabled: x,
809
- scheme: P?.color_scheme,
810
- linkedIds: L
1037
+ tree: $,
1038
+ selectedId: p,
1039
+ onSelect: Fe,
1040
+ colorEnabled: re,
1041
+ scheme: A?.color_scheme,
1042
+ linkedIds: Ue
811
1043
  }
812
1044
  ) }),
813
1045
  /* @__PURE__ */ n("div", { className: "doc-content", children: g ? /* @__PURE__ */ d(q, { children: [
@@ -827,8 +1059,8 @@ function Ee({
827
1059
  "button",
828
1060
  {
829
1061
  type: "button",
830
- className: v === "chunks" ? "active" : "",
831
- onClick: () => E("chunks"),
1062
+ className: N === "chunks" ? "active" : "",
1063
+ onClick: () => D("chunks"),
832
1064
  title: "This chunk's own content",
833
1065
  children: "chunk"
834
1066
  }
@@ -837,162 +1069,177 @@ function Ee({
837
1069
  "button",
838
1070
  {
839
1071
  type: "button",
840
- className: v === "markdown" ? "active" : "",
841
- onClick: () => E("markdown"),
842
- title: te ? "Whole document as Markdown" : "This chunk + its sub-chunks as Markdown",
1072
+ className: N === "markdown" ? "active" : "",
1073
+ onClick: () => D("markdown"),
1074
+ title: V ? "Whole document as Markdown" : "This chunk + its sub-chunks as Markdown",
843
1075
  children: "markdown"
844
1076
  }
845
1077
  )
846
1078
  ] }),
847
- /* @__PURE__ */ n("button", { type: "button", onClick: () => D(g), children: "edit" })
1079
+ /* @__PURE__ */ n("button", { type: "button", onClick: () => w(g), children: "edit" })
848
1080
  ] })
849
1081
  ] }),
850
- /* @__PURE__ */ n("div", { className: "doc-content-body", children: v === "markdown" ? O !== null ? /* @__PURE__ */ n(ye, { source: O }) : /* @__PURE__ */ n("p", { className: "doc-empty-body", children: "Assembling Markdown…" }) : g.body ? /* @__PURE__ */ n(ye, { source: g.body }) : /* @__PURE__ */ n("p", { className: "doc-empty-body", children: "(empty chunk)" }) }),
1082
+ /* @__PURE__ */ n("div", { className: "doc-content-body", children: g.type === "mermaid" ? (
1083
+ // RFC BO — a diagram chunk: body IS the Mermaid source.
1084
+ g.body ? /* @__PURE__ */ d(q, { children: [
1085
+ /* @__PURE__ */ n(ie, { code: g.body }),
1086
+ N === "markdown" && /* @__PURE__ */ n("pre", { className: "md-pre doc-mermaid-source", children: /* @__PURE__ */ n("code", { children: g.body }) })
1087
+ ] }) : /* @__PURE__ */ n("p", { className: "doc-empty-body", children: "(empty diagram)" })
1088
+ ) : g.type === "image" || g.asset ? (
1089
+ // RFC BO — an image chunk: bytes come from the auth'd asset GET.
1090
+ z ? /* @__PURE__ */ d("p", { className: "doc-empty-body", children: [
1091
+ "Image failed to load: ",
1092
+ z
1093
+ ] }) : W ? /* @__PURE__ */ d("figure", { className: "doc-image", children: [
1094
+ /* @__PURE__ */ n("img", { src: W, alt: yt(g) }),
1095
+ g.body && /* @__PURE__ */ n("figcaption", { children: g.body })
1096
+ ] }) : /* @__PURE__ */ n("p", { className: "doc-empty-body", children: "Loading image…" })
1097
+ ) : N === "markdown" ? U !== null ? /* @__PURE__ */ n(Ce, { source: U }) : /* @__PURE__ */ n("p", { className: "doc-empty-body", children: "Assembling Markdown…" }) : g.body ? /* @__PURE__ */ n(Ce, { source: g.body }) : /* @__PURE__ */ n("p", { className: "doc-empty-body", children: "(empty chunk)" }) }),
851
1098
  /* @__PURE__ */ n(
852
- Xe,
1099
+ mt,
853
1100
  {
854
- edges: S,
1101
+ edges: Y,
855
1102
  documentId: e,
856
- selectedId: h,
857
- onSelectChunk: f
1103
+ selectedId: p,
1104
+ onSelectChunk: b
858
1105
  }
859
1106
  )
860
1107
  ] }) : /* @__PURE__ */ n("div", { className: "empty", children: /* @__PURE__ */ n("p", { children: "Select a chunk on the left." }) }) })
861
1108
  ] }),
862
- F && l && /* @__PURE__ */ n("div", { className: "doc-assistant", children: l({
1109
+ C && s && /* @__PURE__ */ n("div", { className: "doc-assistant", children: s({
863
1110
  documentId: e,
864
- scope: a,
1111
+ scope: r,
865
1112
  subject: c?.subject,
866
1113
  // Pass the viewer's own reload so the injected assistant can refresh
867
1114
  // the tree + selected chunk after a turn mutates the document.
868
- onChanged: Q
1115
+ onChanged: v
869
1116
  }) }),
870
- j && /* @__PURE__ */ n(
871
- Ve,
1117
+ _ && /* @__PURE__ */ n(
1118
+ dt,
872
1119
  {
873
- chunk: j,
874
- scope: a,
875
- browse: o,
876
- onClose: () => D(null),
877
- onSaved: Q
1120
+ chunk: _,
1121
+ scope: r,
1122
+ browse: i,
1123
+ onClose: () => w(null),
1124
+ onSaved: v
878
1125
  }
879
1126
  ),
880
- m && Y && /* @__PURE__ */ n(
881
- qe,
1127
+ te && J && /* @__PURE__ */ n(
1128
+ ht,
882
1129
  {
883
1130
  documentId: e,
884
- rootChunkId: Y,
885
- docType: P?.type,
886
- docStatus: P?.status,
887
- chunkStatuses: w,
888
- scope: a,
889
- browse: o,
890
- onClose: () => T(!1),
891
- onSaved: Q
1131
+ rootChunkId: J,
1132
+ docType: A?.type,
1133
+ docStatus: A?.status,
1134
+ chunkStatuses: Oe,
1135
+ scope: r,
1136
+ browse: i,
1137
+ onClose: () => ne(!1),
1138
+ onSaved: v
892
1139
  }
893
1140
  )
894
1141
  ] });
895
1142
  }
896
- function tt(e) {
897
- const a = {
1143
+ function bt(e) {
1144
+ const r = {
898
1145
  name: "",
899
1146
  fullPath: "",
900
1147
  kind: "directory",
901
1148
  explicit: !0,
902
1149
  children: []
903
- }, t = /* @__PURE__ */ new Map([["", a]]), r = (l) => {
904
- const s = t.get(l);
905
- if (s) return s;
906
- const o = l.lastIndexOf("/"), i = o <= 0 ? "" : l.slice(0, o), u = l.slice(o + 1), h = r(i), f = {
907
- name: u,
908
- fullPath: l,
1150
+ }, t = /* @__PURE__ */ new Map([["", r]]), a = (s) => {
1151
+ const o = t.get(s);
1152
+ if (o) return o;
1153
+ const i = s.lastIndexOf("/"), l = i <= 0 ? "" : s.slice(0, i), m = s.slice(i + 1), p = a(l), b = {
1154
+ name: m,
1155
+ fullPath: s,
909
1156
  kind: "directory",
910
1157
  explicit: !1,
911
1158
  children: []
912
1159
  };
913
- return h.children.push(f), t.set(l, f), f;
1160
+ return p.children.push(b), t.set(s, b), b;
914
1161
  };
915
- for (const l of e) {
916
- const s = r(l.full_path);
917
- s.kind = l.kind, s.explicit = !0, s.resourceRef = l.resource_ref;
1162
+ for (const s of e) {
1163
+ const o = a(s.full_path);
1164
+ o.kind = s.kind, o.explicit = !0, o.resourceRef = s.resource_ref;
918
1165
  }
919
- const c = (l) => {
920
- l.sort((s, o) => {
921
- const i = s.kind === "directory", u = o.kind === "directory";
922
- return i !== u ? i ? -1 : 1 : s.name.localeCompare(o.name);
923
- }), l.forEach((s) => c(s.children));
1166
+ const c = (s) => {
1167
+ s.sort((o, i) => {
1168
+ const l = o.kind === "directory", m = i.kind === "directory";
1169
+ return l !== m ? l ? -1 : 1 : o.name.localeCompare(i.name);
1170
+ }), s.forEach((o) => c(o.children));
924
1171
  };
925
- return c(a.children), a.children;
1172
+ return c(r.children), r.children;
926
1173
  }
927
- function le(e) {
928
- const a = e.lastIndexOf("/");
929
- return a <= 0 ? "" : e.slice(0, a);
1174
+ function pe(e) {
1175
+ const r = e.lastIndexOf("/");
1176
+ return r <= 0 ? "" : e.slice(0, r);
930
1177
  }
931
- function nt(e) {
932
- const a = [], t = (r) => {
933
- if (r.kind === "document") {
934
- const c = r.resourceRef;
935
- c?.document_id && a.push(c.document_id);
1178
+ function kt(e) {
1179
+ const r = [], t = (a) => {
1180
+ if (a.kind === "document") {
1181
+ const c = a.resourceRef;
1182
+ c?.document_id && r.push(c.document_id);
936
1183
  }
937
- r.children.forEach(t);
1184
+ a.children.forEach(t);
938
1185
  };
939
- return t(e), a;
1186
+ return t(e), r;
940
1187
  }
941
- const at = {
1188
+ const vt = {
942
1189
  directory: "📁",
943
1190
  document: "📄",
944
1191
  volume_mount: "💾",
945
1192
  memory_entry: "🧠"
946
1193
  };
947
- function rt({ tree: e, selectedPath: a, onSelect: t, summaries: r }) {
948
- const [c, l] = b(() => /* @__PURE__ */ new Map()), s = G((o) => {
949
- l((i) => {
950
- const u = new Map(i);
951
- return u.set(o, i.get(o) === !1), u;
1194
+ function Nt({ tree: e, selectedPath: r, onSelect: t, summaries: a }) {
1195
+ const [c, s] = y(() => /* @__PURE__ */ new Map()), o = G((i) => {
1196
+ s((l) => {
1197
+ const m = new Map(l);
1198
+ return m.set(i, l.get(i) === !1), m;
952
1199
  });
953
1200
  }, []);
954
1201
  return I(() => {
955
- a && l((o) => {
956
- let i = !1;
957
- const u = new Map(o);
958
- let h = le(a);
959
- for (; h !== ""; )
960
- u.get(h) === !1 && (u.set(h, !0), i = !0), h = le(h);
961
- return i ? u : o;
1202
+ r && s((i) => {
1203
+ let l = !1;
1204
+ const m = new Map(i);
1205
+ let p = pe(r);
1206
+ for (; p !== ""; )
1207
+ m.get(p) === !1 && (m.set(p, !0), l = !0), p = pe(p);
1208
+ return l ? m : i;
962
1209
  });
963
- }, [a]), e.length === 0 ? /* @__PURE__ */ n("div", { className: "empty", children: /* @__PURE__ */ n("p", { children: "This tree is empty. Create a folder or document to begin." }) }) : /* @__PURE__ */ n("ul", { className: "tree path-tree", children: e.map((o) => /* @__PURE__ */ n(
964
- $e,
1210
+ }, [r]), e.length === 0 ? /* @__PURE__ */ n("div", { className: "empty", children: /* @__PURE__ */ n("p", { children: "This tree is empty. Create a folder or document to begin." }) }) : /* @__PURE__ */ n("ul", { className: "tree path-tree", children: e.map((i) => /* @__PURE__ */ n(
1211
+ Te,
965
1212
  {
966
- node: o,
1213
+ node: i,
967
1214
  expanded: c,
968
- toggle: s,
969
- selectedPath: a,
1215
+ toggle: o,
1216
+ selectedPath: r,
970
1217
  onSelect: t,
971
- summaries: r
1218
+ summaries: a
972
1219
  },
973
- o.fullPath
1220
+ i.fullPath
974
1221
  )) });
975
1222
  }
976
- function ct(e, a) {
977
- if (e.kind !== "document" || !a) return;
1223
+ function wt(e, r) {
1224
+ if (e.kind !== "document" || !r) return;
978
1225
  const t = e.resourceRef;
979
- return t?.document_id ? a.get(t.document_id) : void 0;
1226
+ return t?.document_id ? r.get(t.document_id) : void 0;
980
1227
  }
981
- function $e({ node: e, expanded: a, toggle: t, selectedPath: r, onSelect: c, summaries: l }) {
982
- const s = e.children.length > 0, o = a.get(e.fullPath) !== !1, i = r === e.fullPath, u = ct(e, l), h = u && u.color_enabled ? de(Ce(u.type, u.status, ie(u.color_scheme))) : void 0;
983
- return /* @__PURE__ */ d("li", { className: `node path-node kind-${e.kind} ${i ? "selected" : ""}`, children: [
984
- /* @__PURE__ */ d("div", { className: "row path-row", style: h, children: [
1228
+ function Te({ node: e, expanded: r, toggle: t, selectedPath: a, onSelect: c, summaries: s }) {
1229
+ const o = e.children.length > 0, i = r.get(e.fullPath) !== !1, l = a === e.fullPath, m = wt(e, s), p = m && m.color_enabled ? ge(De(m.type, m.status, fe(m.color_scheme))) : void 0;
1230
+ return /* @__PURE__ */ d("li", { className: `node path-node kind-${e.kind} ${l ? "selected" : ""}`, children: [
1231
+ /* @__PURE__ */ d("div", { className: "row path-row", style: p, children: [
985
1232
  /* @__PURE__ */ n(
986
1233
  "button",
987
1234
  {
988
1235
  type: "button",
989
1236
  className: "tree-caret",
990
- "aria-label": o ? "collapse" : "expand",
991
- disabled: !s,
992
- onClick: (f) => {
993
- f.stopPropagation(), s && t(e.fullPath);
1237
+ "aria-label": i ? "collapse" : "expand",
1238
+ disabled: !o,
1239
+ onClick: (b) => {
1240
+ b.stopPropagation(), o && t(e.fullPath);
994
1241
  },
995
- children: s ? o ? "▼" : "▶" : "·"
1242
+ children: o ? i ? "▼" : "▶" : "·"
996
1243
  }
997
1244
  ),
998
1245
  /* @__PURE__ */ d(
@@ -1003,189 +1250,189 @@ function $e({ node: e, expanded: a, toggle: t, selectedPath: r, onSelect: c, sum
1003
1250
  onClick: () => c(e),
1004
1251
  title: e.fullPath,
1005
1252
  children: [
1006
- /* @__PURE__ */ n("span", { className: "path-kind-icon", "aria-hidden": !0, children: at[e.kind] ?? "•" }),
1253
+ /* @__PURE__ */ n("span", { className: "path-kind-icon", "aria-hidden": !0, children: vt[e.kind] ?? "•" }),
1007
1254
  /* @__PURE__ */ n("span", { className: "path-name", children: e.name }),
1008
- u?.type && /* @__PURE__ */ n("span", { className: "chunk-badge", children: u.type }),
1009
- u?.status && /* @__PURE__ */ n("span", { className: "chunk-badge chunk-status", children: u.status }),
1255
+ m?.type && /* @__PURE__ */ n("span", { className: "chunk-badge", children: m.type }),
1256
+ m?.status && /* @__PURE__ */ n("span", { className: "chunk-badge chunk-status", children: m.status }),
1010
1257
  !e.explicit && /* @__PURE__ */ n("span", { className: "path-implicit", title: "Implicit directory (no stored entry)", children: "implicit" })
1011
1258
  ]
1012
1259
  }
1013
1260
  )
1014
1261
  ] }),
1015
- s && o && /* @__PURE__ */ n("ul", { className: "children path-children", children: e.children.map((f) => /* @__PURE__ */ n(
1016
- $e,
1262
+ o && i && /* @__PURE__ */ n("ul", { className: "children path-children", children: e.children.map((b) => /* @__PURE__ */ n(
1263
+ Te,
1017
1264
  {
1018
- node: f,
1019
- expanded: a,
1265
+ node: b,
1266
+ expanded: r,
1020
1267
  toggle: t,
1021
- selectedPath: r,
1268
+ selectedPath: a,
1022
1269
  onSelect: c,
1023
- summaries: l
1270
+ summaries: s
1024
1271
  },
1025
- f.fullPath
1272
+ b.fullPath
1026
1273
  )) })
1027
1274
  ] });
1028
1275
  }
1029
- const ge = /^[A-Za-z0-9._-]+$/;
1030
- function ke(e, a) {
1031
- return `${e}/${a}`;
1276
+ const _e = /^[A-Za-z0-9._-]+$/;
1277
+ function Ee(e, r) {
1278
+ return `${e}/${r}`;
1032
1279
  }
1033
- function Me(e, a) {
1280
+ function Ie(e, r) {
1034
1281
  for (const t of e) {
1035
- if (t.fullPath === a) return t;
1036
- const r = Me(t.children, a);
1037
- if (r) return r;
1282
+ if (t.fullPath === r) return t;
1283
+ const a = Ie(t.children, r);
1284
+ if (a) return a;
1038
1285
  }
1039
1286
  }
1040
- function mt(e) {
1041
- const { theme: a, defaultScope: t, path: r, onPathChange: c, browse: l, principal: s, renderAssistant: o, onError: i } = e, u = Ne(e);
1042
- return /* @__PURE__ */ n(we, { theme: a, dataLayer: u, children: /* @__PURE__ */ n(
1043
- ot,
1287
+ function Lt(e) {
1288
+ const { theme: r, defaultScope: t, path: a, onPathChange: c, browse: s, principal: o, renderAssistant: i, onError: l } = e, m = xe(e);
1289
+ return /* @__PURE__ */ n($e, { theme: r, dataLayer: m, children: /* @__PURE__ */ n(
1290
+ Ct,
1044
1291
  {
1045
1292
  defaultScope: t,
1046
- path: r,
1293
+ path: a,
1047
1294
  onPathChange: c,
1048
- browse: l,
1049
- principal: s,
1050
- renderAssistant: o,
1051
- onError: i
1295
+ browse: s,
1296
+ principal: o,
1297
+ renderAssistant: i,
1298
+ onError: l
1052
1299
  }
1053
1300
  ) });
1054
1301
  }
1055
- function ot({
1302
+ function Ct({
1056
1303
  defaultScope: e,
1057
- path: a,
1304
+ path: r,
1058
1305
  onPathChange: t,
1059
- browse: r,
1306
+ browse: a,
1060
1307
  principal: c,
1061
- renderAssistant: l,
1062
- onError: s
1308
+ renderAssistant: s,
1309
+ onError: o
1063
1310
  }) {
1064
- const o = ce(), [i, u] = b(e ?? "user"), [h, f] = b([]), [g, M] = b(void 0), [v, E] = b(null), [O, R] = b(!1), [j, D] = b(null), U = a !== void 0 ? a : g, $ = ee(t);
1311
+ const i = se(), [l, m] = y(e ?? "user"), [p, b] = y([]), [g, O] = y(void 0), [N, D] = y(null), [U, R] = y(!1), [W, M] = y(null), z = r !== void 0 ? r : g, j = K(t);
1065
1312
  I(() => {
1066
- $.current = t;
1313
+ j.current = t;
1067
1314
  }, [t]);
1068
- const J = ee(s);
1315
+ const B = K(o);
1069
1316
  I(() => {
1070
- J.current = s;
1071
- }, [s]);
1072
- const k = G((w) => {
1073
- $.current?.(w), M(w);
1074
- }, []), N = A(
1075
- () => r && (r.scopeId || r.tenant) ? { scopeId: r.scopeId, tenant: r.tenant } : void 0,
1076
- [r?.scopeId, r?.tenant]
1077
- ), _ = G(async () => {
1078
- R(!0), E(null);
1317
+ B.current = o;
1318
+ }, [o]);
1319
+ const _ = G((v) => {
1320
+ j.current?.(v), O(v);
1321
+ }, []), w = H(
1322
+ () => a && (a.scopeId || a.tenant) ? { scopeId: a.scopeId, tenant: a.tenant } : void 0,
1323
+ [a?.scopeId, a?.tenant]
1324
+ ), L = G(async () => {
1325
+ R(!0), D(null);
1079
1326
  try {
1080
- const w = await o.pathLs("/", i, !0, N);
1081
- f(w.entries ?? []);
1082
- } catch (w) {
1083
- E(w instanceof Error ? w.message : String(w)), f([]), J.current?.(w);
1327
+ const v = await i.pathLs("/", l, !0, w);
1328
+ b(v.entries ?? []);
1329
+ } catch (v) {
1330
+ D(v instanceof Error ? v.message : String(v)), b([]), B.current?.(v);
1084
1331
  } finally {
1085
1332
  R(!1);
1086
1333
  }
1087
- }, [o, i, N]), F = ee(!0);
1334
+ }, [i, l, w]), F = K(!0);
1088
1335
  I(() => {
1089
- F.current ? F.current = !1 : k(void 0), _();
1090
- }, [_, k]);
1091
- const Z = A(() => tt(h), [h]), [P, p] = b(() => /* @__PURE__ */ new Map());
1336
+ F.current ? F.current = !1 : _(void 0), L();
1337
+ }, [L, _]);
1338
+ const Q = H(() => bt(p), [p]), [X, u] = y(() => /* @__PURE__ */ new Map());
1092
1339
  I(() => {
1093
- if (i === "tenant") {
1094
- p(/* @__PURE__ */ new Map());
1340
+ if (l === "tenant") {
1341
+ u(/* @__PURE__ */ new Map());
1095
1342
  return;
1096
1343
  }
1097
- const w = h.filter((L) => L.kind === "document").map((L) => L.resource_ref?.document_id).filter((L) => !!L);
1098
- if (w.length === 0) {
1099
- p(/* @__PURE__ */ new Map());
1344
+ const v = p.filter((P) => P.kind === "document").map((P) => P.resource_ref?.document_id).filter((P) => !!P);
1345
+ if (v.length === 0) {
1346
+ u(/* @__PURE__ */ new Map());
1100
1347
  return;
1101
1348
  }
1102
- let x = !1;
1103
- return o.documentsSummary({ documentIds: w }, i, N).then((L) => {
1104
- if (x) return;
1105
- const H = /* @__PURE__ */ new Map();
1106
- for (const ne of L.documents ?? []) H.set(ne.document_id, ne);
1107
- p(H);
1349
+ let $ = !1;
1350
+ return i.documentsSummary({ documentIds: v }, l, w).then((P) => {
1351
+ if ($) return;
1352
+ const V = /* @__PURE__ */ new Map();
1353
+ for (const J of P.documents ?? []) V.set(J.document_id, J);
1354
+ u(V);
1108
1355
  }).catch(() => {
1109
- x || p(/* @__PURE__ */ new Map());
1356
+ $ || u(/* @__PURE__ */ new Map());
1110
1357
  }), () => {
1111
- x = !0;
1358
+ $ = !0;
1112
1359
  };
1113
- }, [o, h, i, N]);
1114
- const m = A(
1115
- () => U ? Me(Z, U) : void 0,
1116
- [Z, U]
1117
- ), T = A(() => m ? m.kind === "directory" ? m.fullPath : le(m.fullPath) : "", [m]), S = T || "/", W = i !== "tenant", Q = G(() => {
1118
- D({
1119
- title: `New folder in ${S}`,
1360
+ }, [i, p, l, w]);
1361
+ const h = H(
1362
+ () => z ? Ie(Q, z) : void 0,
1363
+ [Q, z]
1364
+ ), C = H(() => h ? h.kind === "directory" ? h.fullPath : pe(h.fullPath) : "", [h]), E = C || "/", A = l !== "tenant", ee = G(() => {
1365
+ M({
1366
+ title: `New folder in ${E}`,
1120
1367
  fields: [{ key: "name", label: "Folder name", placeholder: "e.g. launches" }],
1121
1368
  submitLabel: "Create",
1122
- onSubmit: async (w) => {
1123
- const x = w.name.trim();
1124
- if (!ge.test(x)) throw new Error("name may contain only [A-Za-z0-9._-]");
1125
- const L = ke(T, x);
1126
- await o.pathMkdir(L, i, N), await _(), k(L);
1369
+ onSubmit: async (v) => {
1370
+ const $ = v.name.trim();
1371
+ if (!_e.test($)) throw new Error("name may contain only [A-Za-z0-9._-]");
1372
+ const P = Ee(C, $);
1373
+ await i.pathMkdir(P, l, w), await L(), _(P);
1127
1374
  }
1128
1375
  });
1129
- }, [o, T, S, i, N, _, k]), X = G(() => {
1130
- D({
1131
- title: `New document in ${S}`,
1376
+ }, [i, C, E, l, w, L, _]), te = G(() => {
1377
+ M({
1378
+ title: `New document in ${E}`,
1132
1379
  fields: [
1133
1380
  { key: "name", label: "Path name", placeholder: "e.g. launch-plan" },
1134
1381
  { key: "title", label: "Title", placeholder: "e.g. Launch Plan" }
1135
1382
  ],
1136
1383
  submitLabel: "Create",
1137
- onSubmit: async (w) => {
1138
- const x = w.name.trim();
1139
- if (!ge.test(x)) throw new Error("name may contain only [A-Za-z0-9._-]");
1140
- const L = w.title.trim() || x, H = ke(T, x);
1141
- await o.documentCreate(L, H, i, N), await _(), k(H);
1384
+ onSubmit: async (v) => {
1385
+ const $ = v.name.trim();
1386
+ if (!_e.test($)) throw new Error("name may contain only [A-Za-z0-9._-]");
1387
+ const P = v.title.trim() || $, V = Ee(C, $);
1388
+ await i.documentCreate(P, V, l, w), await L(), _(V);
1142
1389
  }
1143
1390
  });
1144
- }, [o, T, S, i, N, _, k]), K = G(() => {
1145
- m && D({
1146
- title: `Rename / move ${m.fullPath}`,
1147
- fields: [{ key: "to", label: "New path", value: m.fullPath }],
1391
+ }, [i, C, E, l, w, L, _]), ne = G(() => {
1392
+ h && M({
1393
+ title: `Rename / move ${h.fullPath}`,
1394
+ fields: [{ key: "to", label: "New path", value: h.fullPath }],
1148
1395
  submitLabel: "Move",
1149
- onSubmit: async (w) => {
1150
- const x = w.to.trim();
1151
- if (!x.startsWith("/")) throw new Error("path must start with /");
1152
- await o.pathMv(m.fullPath, x, i, N), await _(), k(x);
1396
+ onSubmit: async (v) => {
1397
+ const $ = v.to.trim();
1398
+ if (!$.startsWith("/")) throw new Error("path must start with /");
1399
+ await i.pathMv(h.fullPath, $, l, w), await L(), _($);
1153
1400
  }
1154
1401
  });
1155
- }, [o, m, i, N, _, k]), te = G(() => {
1156
- if (!m) return;
1157
- if (m.kind === "document") {
1158
- const H = m.resourceRef?.document_id;
1159
- D({
1160
- title: `Delete document ${m.fullPath}`,
1402
+ }, [i, h, l, w, L, _]), Y = G(() => {
1403
+ if (!h) return;
1404
+ if (h.kind === "document") {
1405
+ const V = h.resourceRef?.document_id;
1406
+ M({
1407
+ title: `Delete document ${h.fullPath}`,
1161
1408
  message: "This deletes the document, all its chunks, and its path entry. This cannot be undone.",
1162
1409
  fields: [],
1163
1410
  submitLabel: "Delete",
1164
1411
  danger: !0,
1165
1412
  onSubmit: async () => {
1166
- if (!H) throw new Error("this document dirent has no document_id");
1167
- await o.documentDelete(H, i, N), await _(), k(void 0);
1413
+ if (!V) throw new Error("this document dirent has no document_id");
1414
+ await i.documentDelete(V, l, w), await L(), _(void 0);
1168
1415
  }
1169
1416
  });
1170
1417
  return;
1171
1418
  }
1172
- const w = i === "tenant" ? [] : nt(m), x = m.children.length;
1173
- D({
1174
- title: `Delete branch ${m.fullPath}`,
1175
- message: x === 0 ? "This removes the (empty) folder." : "This removes the folder and everything under it" + (w.length > 0 ? ` — including ${w.length} document(s), whose chunks are deleted.` : "."),
1419
+ const v = l === "tenant" ? [] : kt(h), $ = h.children.length;
1420
+ M({
1421
+ title: `Delete branch ${h.fullPath}`,
1422
+ message: $ === 0 ? "This removes the (empty) folder." : "This removes the folder and everything under it" + (v.length > 0 ? ` — including ${v.length} document(s), whose chunks are deleted.` : "."),
1176
1423
  fields: [],
1177
1424
  submitLabel: "Delete",
1178
1425
  danger: !0,
1179
1426
  onSubmit: async () => {
1180
- for (const L of w)
1181
- await o.documentDelete(L, i, N);
1182
- await o.pathRm(m.fullPath, i, !0, N), await _(), k(void 0);
1427
+ for (const P of v)
1428
+ await i.documentDelete(P, l, w);
1429
+ await i.pathRm(h.fullPath, l, !0, w), await L(), _(void 0);
1183
1430
  }
1184
1431
  });
1185
- }, [o, m, i, N, _, k]), Y = m && (m.kind === "directory" || m.kind === "document");
1432
+ }, [i, h, l, w, L, _]), ae = h && (h.kind === "directory" || h.kind === "document");
1186
1433
  return /* @__PURE__ */ d(q, { children: [
1187
1434
  /* @__PURE__ */ d(
1188
- Ue,
1435
+ et,
1189
1436
  {
1190
1437
  className: "paths-view",
1191
1438
  defaultLeftWidth: 420,
@@ -1197,159 +1444,160 @@ function ot({
1197
1444
  /* @__PURE__ */ d("div", { className: "paths-toolbar", children: [
1198
1445
  /* @__PURE__ */ d("label", { className: "paths-scope", children: [
1199
1446
  /* @__PURE__ */ n("span", { children: "scope" }),
1200
- /* @__PURE__ */ d("select", { value: i, onChange: (w) => u(w.target.value), children: [
1447
+ /* @__PURE__ */ d("select", { value: l, onChange: (v) => m(v.target.value), children: [
1201
1448
  /* @__PURE__ */ n("option", { value: "user", children: "user" }),
1202
1449
  /* @__PURE__ */ n("option", { value: "agent", children: "agent" }),
1203
1450
  /* @__PURE__ */ n("option", { value: "tenant", children: "tenant" })
1204
1451
  ] })
1205
1452
  ] }),
1206
1453
  /* @__PURE__ */ d("div", { className: "paths-toolbar-actions", children: [
1207
- /* @__PURE__ */ n("button", { type: "button", onClick: Q, title: `New folder in ${S}`, children: "+ folder" }),
1454
+ /* @__PURE__ */ n("button", { type: "button", onClick: ee, title: `New folder in ${E}`, children: "+ folder" }),
1208
1455
  /* @__PURE__ */ n(
1209
1456
  "button",
1210
1457
  {
1211
1458
  type: "button",
1212
- onClick: X,
1213
- disabled: !W,
1214
- title: W ? `New document in ${S}` : "Documents are agent/user scope only",
1459
+ onClick: te,
1460
+ disabled: !A,
1461
+ title: A ? `New document in ${E}` : "Documents are agent/user scope only",
1215
1462
  children: "+ document"
1216
1463
  }
1217
1464
  ),
1218
1465
  /* @__PURE__ */ n("button", { type: "button", onClick: () => {
1219
- _();
1466
+ L();
1220
1467
  }, title: "Reload the tree", children: "↻" })
1221
1468
  ] })
1222
1469
  ] }),
1223
1470
  /* @__PURE__ */ d("p", { className: "paths-context", children: [
1224
1471
  "new items → ",
1225
- /* @__PURE__ */ n("code", { children: S }),
1226
- N?.scopeId && /* @__PURE__ */ d(q, { children: [
1472
+ /* @__PURE__ */ n("code", { children: E }),
1473
+ w?.scopeId && /* @__PURE__ */ d(q, { children: [
1227
1474
  " · ",
1228
1475
  "subject ",
1229
- /* @__PURE__ */ n("code", { children: N.scopeId })
1476
+ /* @__PURE__ */ n("code", { children: w.scopeId })
1230
1477
  ] }),
1231
- N?.tenant && /* @__PURE__ */ d(q, { children: [
1478
+ w?.tenant && /* @__PURE__ */ d(q, { children: [
1232
1479
  " · ",
1233
1480
  "tenant ",
1234
- /* @__PURE__ */ n("code", { children: N.tenant })
1481
+ /* @__PURE__ */ n("code", { children: w.tenant })
1235
1482
  ] })
1236
1483
  ] }),
1237
- v && /* @__PURE__ */ n("div", { className: "paths-err", children: v }),
1238
- O && h.length === 0 ? /* @__PURE__ */ n("div", { className: "empty", children: /* @__PURE__ */ n("p", { children: "Loading…" }) }) : /* @__PURE__ */ n(
1239
- rt,
1484
+ N && /* @__PURE__ */ n("div", { className: "paths-err", children: N }),
1485
+ U && p.length === 0 ? /* @__PURE__ */ n("div", { className: "empty", children: /* @__PURE__ */ n("p", { children: "Loading…" }) }) : /* @__PURE__ */ n(
1486
+ Nt,
1240
1487
  {
1241
- tree: Z,
1242
- selectedPath: U,
1243
- onSelect: (w) => k(w.fullPath),
1244
- summaries: P
1488
+ tree: Q,
1489
+ selectedPath: z,
1490
+ onSelect: (v) => _(v.fullPath),
1491
+ summaries: X
1245
1492
  }
1246
1493
  )
1247
1494
  ] }),
1248
- /* @__PURE__ */ n("div", { className: "right", children: m ? m.kind === "document" ? /* @__PURE__ */ d("div", { className: "paths-doc", children: [
1495
+ /* @__PURE__ */ n("div", { className: "right", children: h ? h.kind === "document" ? /* @__PURE__ */ d("div", { className: "paths-doc", children: [
1249
1496
  /* @__PURE__ */ d("div", { className: "paths-doc-head", children: [
1250
- /* @__PURE__ */ n("code", { className: "paths-doc-path", children: m.fullPath }),
1497
+ /* @__PURE__ */ n("code", { className: "paths-doc-path", children: h.fullPath }),
1251
1498
  /* @__PURE__ */ d("div", { className: "paths-detail-actions", children: [
1252
- /* @__PURE__ */ n("button", { type: "button", onClick: K, children: "rename / move" }),
1253
- /* @__PURE__ */ n("button", { type: "button", className: "danger", onClick: te, children: "delete" })
1499
+ /* @__PURE__ */ n("button", { type: "button", onClick: ne, children: "rename / move" }),
1500
+ /* @__PURE__ */ n("button", { type: "button", className: "danger", onClick: Y, children: "delete" })
1254
1501
  ] })
1255
1502
  ] }),
1256
1503
  /* @__PURE__ */ n(
1257
- Ee,
1504
+ Pe,
1258
1505
  {
1259
- documentId: m.resourceRef?.document_id ?? "",
1260
- scope: i === "agent" ? "agent" : "user",
1261
- titleHint: m.name,
1262
- browse: N,
1506
+ documentId: h.resourceRef?.document_id ?? "",
1507
+ scope: l === "agent" ? "agent" : "user",
1508
+ titleHint: h.name,
1509
+ browse: w,
1263
1510
  principal: c,
1264
- renderAssistant: l
1511
+ renderAssistant: s
1265
1512
  }
1266
1513
  )
1267
1514
  ] }) : /* @__PURE__ */ d("div", { className: "paths-detail", children: [
1268
1515
  /* @__PURE__ */ d("h2", { children: [
1269
- /* @__PURE__ */ n("span", { className: "paths-detail-kind", children: m.kind }),
1270
- /* @__PURE__ */ n("code", { children: m.fullPath })
1516
+ /* @__PURE__ */ n("span", { className: "paths-detail-kind", children: h.kind }),
1517
+ /* @__PURE__ */ n("code", { children: h.fullPath })
1271
1518
  ] }),
1272
1519
  /* @__PURE__ */ d("dl", { className: "paths-detail-meta", children: [
1273
1520
  /* @__PURE__ */ n("dt", { children: "scope" }),
1274
- /* @__PURE__ */ n("dd", { children: i }),
1521
+ /* @__PURE__ */ n("dd", { children: l }),
1275
1522
  /* @__PURE__ */ n("dt", { children: "stored" }),
1276
- /* @__PURE__ */ n("dd", { children: m.explicit ? "yes" : "implicit (no entry)" })
1523
+ /* @__PURE__ */ n("dd", { children: h.explicit ? "yes" : "implicit (no entry)" })
1277
1524
  ] }),
1278
- Y ? /* @__PURE__ */ d("div", { className: "paths-detail-actions", children: [
1279
- /* @__PURE__ */ n("button", { type: "button", onClick: K, children: "rename / move" }),
1280
- /* @__PURE__ */ n("button", { type: "button", className: "danger", onClick: te, children: "delete" })
1525
+ ae ? /* @__PURE__ */ d("div", { className: "paths-detail-actions", children: [
1526
+ /* @__PURE__ */ n("button", { type: "button", onClick: ne, children: "rename / move" }),
1527
+ /* @__PURE__ */ n("button", { type: "button", className: "danger", onClick: Y, children: "delete" })
1281
1528
  ] }) : /* @__PURE__ */ d("p", { className: "paths-readonly", children: [
1282
1529
  "Read-only — ",
1283
- m.kind,
1530
+ h.kind,
1284
1531
  " entries are managed by their own tool."
1285
1532
  ] })
1286
1533
  ] }) : /* @__PURE__ */ n("div", { className: "empty", children: /* @__PURE__ */ n("p", { children: "Select a path on the left, or create a folder / document." }) }) })
1287
1534
  ]
1288
1535
  }
1289
1536
  ),
1290
- j && /* @__PURE__ */ n(st, { state: j, onClose: () => D(null) })
1537
+ W && /* @__PURE__ */ n(_t, { state: W, onClose: () => M(null) })
1291
1538
  ] });
1292
1539
  }
1293
- function st({ state: e, onClose: a }) {
1294
- const [t, r] = b(
1295
- () => Object.fromEntries(e.fields.map((u) => [u.key, u.value ?? ""]))
1296
- ), [c, l] = b(!1), [s, o] = b(null);
1297
- return /* @__PURE__ */ n("div", { className: "modal-overlay", onClick: a, children: /* @__PURE__ */ d("form", { className: "modal", onClick: (u) => u.stopPropagation(), onSubmit: async (u) => {
1298
- u.preventDefault(), l(!0), o(null);
1540
+ function _t({ state: e, onClose: r }) {
1541
+ const [t, a] = y(
1542
+ () => Object.fromEntries(e.fields.map((m) => [m.key, m.value ?? ""]))
1543
+ ), [c, s] = y(!1), [o, i] = y(null);
1544
+ return /* @__PURE__ */ n("div", { className: "modal-overlay", onClick: r, children: /* @__PURE__ */ d("form", { className: "modal", onClick: (m) => m.stopPropagation(), onSubmit: async (m) => {
1545
+ m.preventDefault(), s(!0), i(null);
1299
1546
  try {
1300
- await e.onSubmit(t), a();
1301
- } catch (h) {
1302
- o(h instanceof Error ? h.message : String(h)), l(!1);
1547
+ await e.onSubmit(t), r();
1548
+ } catch (p) {
1549
+ i(p instanceof Error ? p.message : String(p)), s(!1);
1303
1550
  }
1304
1551
  }, children: [
1305
1552
  /* @__PURE__ */ d("div", { className: "modal-header sticky-top", children: [
1306
1553
  /* @__PURE__ */ n("h3", { children: e.title }),
1307
1554
  /* @__PURE__ */ d("div", { className: "modal-buttons modal-buttons-top", children: [
1308
- /* @__PURE__ */ n("button", { type: "button", onClick: a, disabled: c, children: "cancel" }),
1555
+ /* @__PURE__ */ n("button", { type: "button", onClick: r, disabled: c, children: "cancel" }),
1309
1556
  /* @__PURE__ */ n("button", { type: "submit", className: e.danger ? "danger" : "primary", disabled: c, children: c ? "working…" : e.submitLabel })
1310
1557
  ] })
1311
1558
  ] }),
1312
1559
  e.message && /* @__PURE__ */ n("p", { className: "modal-context", children: e.message }),
1313
- e.fields.map((u, h) => /* @__PURE__ */ d("label", { className: "path-field", children: [
1314
- /* @__PURE__ */ n("span", { children: u.label }),
1560
+ e.fields.map((m, p) => /* @__PURE__ */ d("label", { className: "path-field", children: [
1561
+ /* @__PURE__ */ n("span", { children: m.label }),
1315
1562
  /* @__PURE__ */ n(
1316
1563
  "input",
1317
1564
  {
1318
1565
  className: "path-modal-input",
1319
- value: t[u.key],
1320
- placeholder: u.placeholder,
1321
- autoFocus: h === 0,
1322
- onChange: (f) => r((g) => ({ ...g, [u.key]: f.target.value }))
1566
+ value: t[m.key],
1567
+ placeholder: m.placeholder,
1568
+ autoFocus: p === 0,
1569
+ onChange: (b) => a((g) => ({ ...g, [m.key]: b.target.value }))
1323
1570
  }
1324
1571
  )
1325
- ] }, u.key)),
1326
- s && /* @__PURE__ */ n("div", { className: "modal-err", children: s })
1572
+ ] }, m.key)),
1573
+ o && /* @__PURE__ */ n("div", { className: "modal-err", children: o })
1327
1574
  ] }) });
1328
1575
  }
1329
- function pt(e) {
1330
- const { documentId: a, scope: t, titleHint: r, browse: c, theme: l, principal: s, renderAssistant: o } = e, i = Ne(e);
1331
- return /* @__PURE__ */ n(we, { theme: l, dataLayer: i, children: /* @__PURE__ */ n(
1332
- Ee,
1576
+ function Dt(e) {
1577
+ const { documentId: r, scope: t, titleHint: a, browse: c, theme: s, principal: o, renderAssistant: i } = e, l = xe(e);
1578
+ return /* @__PURE__ */ n($e, { theme: s, dataLayer: l, children: /* @__PURE__ */ n(
1579
+ Pe,
1333
1580
  {
1334
- documentId: a,
1581
+ documentId: r,
1335
1582
  scope: t,
1336
- titleHint: r,
1583
+ titleHint: a,
1337
1584
  browse: c,
1338
- principal: s,
1339
- renderAssistant: o
1585
+ principal: o,
1586
+ renderAssistant: i
1340
1587
  }
1341
1588
  ) });
1342
1589
  }
1343
1590
  export {
1344
- se as DEFAULT_SCHEME,
1345
- pt as DocumentViewer,
1346
- mt as PathExplorer,
1347
- Fe as chunkColor,
1348
- je as createLoomcycleClient,
1349
- he as dataLayerFromClient,
1350
- Ce as docColor,
1351
- ie as effectiveScheme,
1352
- He as hexToTint,
1353
- de as tintStyle
1591
+ me as DEFAULT_SCHEME,
1592
+ Dt as DocumentViewer,
1593
+ Lt as PathExplorer,
1594
+ Ke as assetFetchFromConnection,
1595
+ rt as chunkColor,
1596
+ Ye as createLoomcycleClient,
1597
+ ye as dataLayerFromClient,
1598
+ De as docColor,
1599
+ fe as effectiveScheme,
1600
+ ct as hexToTint,
1601
+ ge as tintStyle
1354
1602
  };
1355
1603
  //# sourceMappingURL=index.js.map