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