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