@jtfmumm/patchwork-standalone-frame 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,50 +1,49 @@
1
- import { delegateEvents as xe, createComponent as y, insert as d, effect as L, style as D, memo as ee, setStyleProperty as Z, template as w, use as Me, setAttribute as He, render as Ne } from "solid-js/web";
2
- import { createSignal as C, createMemo as X, createEffect as ue, onCleanup as te, Show as S, For as Re, onMount as $e } from "solid-js";
3
- import { docIdFromAutomergeUrl as Oe, uint8ArrayToHex as ye, ContactCard as Ae, Identifier as je, Access as Ie } from "@automerge/automerge-repo-keyhive";
4
- const Je = 100;
5
- function Pe(t, e) {
6
- return `${t}-doc-history-${e}`;
1
+ import { delegateEvents as xe, createComponent as m, insert as f, effect as D, style as E, memo as Z, setStyleProperty as X, template as w, use as Ee, setAttribute as He, render as Pe } from "solid-js/web";
2
+ import { createSignal as x, createEffect as ie, onCleanup as q, createMemo as we, Show as _, For as Me, onMount as $e } from "solid-js";
3
+ const Fe = 100;
4
+ function Oe(e, t) {
5
+ return `${e}-doc-history-${t}`;
7
6
  }
8
- function me(t, e) {
9
- return `${t}-standalone-${e}`;
7
+ function me(e, t) {
8
+ return `${e}-standalone-${t}`;
10
9
  }
11
- function ve(t, e) {
10
+ function ve(e, t) {
12
11
  try {
13
- const l = localStorage.getItem(Pe(t, e));
12
+ const l = localStorage.getItem(Oe(e, t));
14
13
  return l ? JSON.parse(l) : [];
15
14
  } catch {
16
15
  return [];
17
16
  }
18
17
  }
19
- function Fe(t, e, l) {
20
- localStorage.setItem(Pe(t, e), JSON.stringify(l));
18
+ function Re(e, t, l) {
19
+ localStorage.setItem(Oe(e, t), JSON.stringify(l));
21
20
  }
22
- function Te(t, e, l, f) {
23
- const h = ve(t, e), u = h.findIndex((k) => k.url === l);
24
- u !== -1 ? (h[u].title = f, h[u].lastOpened = Date.now()) : h.push({ url: l, title: f, lastOpened: Date.now() }), h.sort((k, x) => x.lastOpened - k.lastOpened);
25
- const $ = h.slice(0, Je);
26
- return Fe(t, e, $), $;
21
+ function Ie(e, t, l, g) {
22
+ const u = ve(e, t), p = u.findIndex(($) => $.url === l);
23
+ p !== -1 ? (u[p].title = g, u[p].lastOpened = Date.now()) : u.push({ url: l, title: g, lastOpened: Date.now() }), u.sort(($, v) => v.lastOpened - $.lastOpened);
24
+ const k = u.slice(0, Fe);
25
+ return Re(e, t, k), k;
27
26
  }
28
- function Ke(t, e, l) {
29
- const f = ve(t, e).filter((h) => h.url !== l);
30
- return Fe(t, e, f), f;
27
+ function Ne(e, t, l) {
28
+ const g = ve(e, t).filter((u) => u.url !== l);
29
+ return Re(e, t, g), g;
31
30
  }
32
- function We(t) {
33
- const e = "automerge:";
34
- if (t.startsWith(e)) {
35
- const l = t.slice(e.length);
36
- return e + l.slice(0, 12) + "...";
31
+ function Ve(e) {
32
+ const t = "automerge:";
33
+ if (e.startsWith(t)) {
34
+ const l = e.slice(t.length);
35
+ return t + l.slice(0, 12) + "...";
37
36
  }
38
- return t;
37
+ return e;
39
38
  }
40
- function Le() {
41
- const t = window.location.hash.slice(1);
42
- return t && t.startsWith("automerge:") ? t : null;
39
+ function Te() {
40
+ const e = window.location.hash.slice(1);
41
+ return e && e.startsWith("automerge:") ? e : null;
43
42
  }
44
- function ce(t) {
45
- window.history.replaceState(null, "", `#${t}`);
43
+ function se(e) {
44
+ window.history.replaceState(null, "", `#${e}`);
46
45
  }
47
- const ke = {
46
+ const Ce = {
48
47
  position: "fixed",
49
48
  inset: "0",
50
49
  background: "rgba(0,0,0,0.5)",
@@ -52,7 +51,7 @@ const ke = {
52
51
  "align-items": "center",
53
52
  "justify-content": "center",
54
53
  "z-index": "2000"
55
- }, Ce = {
54
+ }, Se = {
56
55
  background: "#191e24",
57
56
  color: "#edf2f7",
58
57
  "border-radius": "8px",
@@ -60,21 +59,25 @@ const ke = {
60
59
  "box-shadow": "0 8px 24px rgba(0,0,0,0.5)",
61
60
  "font-family": "system-ui, sans-serif"
62
61
  };
63
- var Be = /* @__PURE__ */ w("<span style=font-size:13px>This document is <strong>public"), Ve = /* @__PURE__ */ w("<button>Revoke Public Access"), Ye = /* @__PURE__ */ w("<button>Make Public"), ze = /* @__PURE__ */ w("<hr>"), qe = /* @__PURE__ */ w('<form><textarea placeholder="Paste ContactCard JSON..."rows=3 style="width:100%;background:#15191e;border:1px solid #2a323c;color:#edf2f7;border-radius:4px;padding:6px 8px;font-size:12px;font-family:monospace;resize:vertical;box-sizing:border-box"></textarea><div style=display:flex;justify-content:flex-end;margin-top:6px><button type=submit>'), Ge = /* @__PURE__ */ w("<p style=font-size:13px;color:#6b7280>Loading..."), Qe = /* @__PURE__ */ w("<p style=font-size:13px;color:#6b7280>No users have access yet"), Xe = /* @__PURE__ */ w("<div>"), Ze = /* @__PURE__ */ w('<div><div><div style=display:flex;justify-content:space-between;align-items:center;margin-bottom:8px><h2 style=margin:0;font-size:16px>Share this document</h2><button aria-label="Close modal"style="border:none;font-size:18px;padding:0 4px">&times;</button></div><section><h3>Public Access</h3><div style=display:flex;align-items:center;gap:12px></div></section><section><h3>Current Access'), et = /* @__PURE__ */ w('<button aria-label="Remove member"style="color:#c66;border:1px solid #944;padding:2px 8px">Revoke'), tt = /* @__PURE__ */ w('<div style="display:flex;justify-content:space-between;align-items:center;padding:4px 0;border-bottom:1px solid #15191e;font-size:13px"><div><span style=margin-right:8px></span><span style=color:#6b7280;font-size:11px>');
62
+ var je = /* @__PURE__ */ w("<span style=font-size:13px>This document is <strong>public"), Ke = /* @__PURE__ */ w("<button>Revoke Public Access"), Je = /* @__PURE__ */ w("<button>Make Public"), Le = /* @__PURE__ */ w("<hr>"), We = /* @__PURE__ */ w('<form><textarea placeholder="Paste ContactCard JSON..."rows=3 style="width:100%;background:#15191e;border:1px solid #2a323c;color:#edf2f7;border-radius:4px;padding:6px 8px;font-size:12px;font-family:monospace;resize:vertical;box-sizing:border-box"></textarea><div style=display:flex;justify-content:flex-end;margin-top:6px><button type=submit>'), Be = /* @__PURE__ */ w("<p style=font-size:13px;color:#6b7280>Loading..."), Ye = /* @__PURE__ */ w("<p style=font-size:13px;color:#6b7280>No users have access yet"), qe = /* @__PURE__ */ w("<div>"), Ge = /* @__PURE__ */ w('<div><div><div style=display:flex;justify-content:space-between;align-items:center;margin-bottom:8px><h2 style=margin:0;font-size:16px>Share this document</h2><button aria-label="Close modal"style="border:none;font-size:18px;padding:0 4px">&times;</button></div><section><h3>Public Access</h3><div style=display:flex;align-items:center;gap:12px></div></section><section><h3>Current Access'), Qe = /* @__PURE__ */ w('<button aria-label="Remove member"style="color:#c66;border:1px solid #944;padding:2px 8px">Revoke'), Xe = /* @__PURE__ */ w('<div style="display:flex;justify-content:space-between;align-items:center;padding:4px 0;border-bottom:1px solid #15191e;font-size:13px"><div><span style=margin-right:8px></span><span style=color:#6b7280;font-size:11px>');
63
+ let ke = null;
64
+ async function ye() {
65
+ return ke || (ke = await import("@automerge/automerge-repo-keyhive")), ke;
66
+ }
64
67
  const De = ["Pull", "Read", "Write", "Admin"];
65
- async function se(t, e) {
66
- const l = Oe(e), f = {};
67
- return (await t.docMemberCapabilities(l)).forEach((u) => {
68
- const $ = ye(u.who.id.toBytes());
69
- f[$] = u.can.toString();
70
- }), f;
68
+ async function de(e, t) {
69
+ const l = await ye(), g = l.docIdFromAutomergeUrl(t), u = {};
70
+ return (await e.docMemberCapabilities(g)).forEach((k) => {
71
+ const $ = l.uint8ArrayToHex(k.who.id.toBytes());
72
+ u[$] = k.can.toString();
73
+ }), u;
71
74
  }
72
- const nt = {
73
- ...Ce,
75
+ const Ze = {
76
+ ...Se,
74
77
  width: "420px",
75
78
  "max-height": "80vh",
76
79
  "overflow-y": "auto"
77
- }, de = {
80
+ }, ue = {
78
81
  background: "none",
79
82
  border: "1px solid #2a323c",
80
83
  color: "#edf2f7",
@@ -82,7 +85,7 @@ const nt = {
82
85
  "border-radius": "4px",
83
86
  cursor: "pointer",
84
87
  "font-size": "12px"
85
- }, Ee = {
88
+ }, ze = {
86
89
  "font-size": "13px",
87
90
  color: "#6b7280",
88
91
  margin: "16px 0 8px"
@@ -91,588 +94,603 @@ const nt = {
91
94
  "border-top": "1px solid #2a323c",
92
95
  margin: "12px 0"
93
96
  };
94
- function rt(t) {
95
- const [e, l] = C(""), [f, h] = C({}), [u, $] = C(!0), [k, x] = C(void 0), [O, z] = C(!1), ie = X(() => Oe(t.docUrl)), M = X(() => {
96
- const i = t.hive.active.individual.id;
97
- return i ? ye(i.toBytes()) : null;
98
- }), _ = X(() => {
99
- const i = t.hive.syncServer;
100
- if (!i) return null;
101
- const g = Ae.fromJson(i.contactCard.toJson());
102
- return g ? ye(g.individualId.bytes) : null;
103
- }), Y = X(() => {
104
- const i = je.publicId();
105
- return ye(i.toBytes());
106
- }), N = X(() => f()[Y()] || null), q = X(() => k() === "Admin");
107
- ue(() => {
108
- if (!t.isOpen) return;
109
- let i = !1;
97
+ function et(e) {
98
+ const [t, l] = x(""), [g, u] = x({}), [p, k] = x(!0), [$, v] = x(void 0), [N, z] = x(!1), [oe, H] = x(null), [A, ae] = x(null), [ee, te] = x(null), [G, be] = x("");
99
+ ie(() => {
100
+ if (!e.isOpen) return;
101
+ let a = !1;
102
+ (async () => {
103
+ const s = await ye();
104
+ if (a) return;
105
+ H(s.docIdFromAutomergeUrl(e.docUrl));
106
+ const C = e.hive.active.individual.id;
107
+ ae(C ? s.uint8ArrayToHex(C.toBytes()) : null);
108
+ const U = e.hive.syncServer;
109
+ if (U) {
110
+ const T = s.ContactCard.fromJson(U.contactCard.toJson());
111
+ T && te(s.uint8ArrayToHex(T.individualId.bytes));
112
+ }
113
+ const P = s.Identifier.publicId();
114
+ be(s.uint8ArrayToHex(P.toBytes()));
115
+ })(), q(() => {
116
+ a = !0;
117
+ });
118
+ });
119
+ const Q = we(() => {
120
+ const a = g(), s = G();
121
+ return s && a[s] || null;
122
+ }), le = we(() => $() === "Admin");
123
+ ie(() => {
124
+ if (!e.isOpen) return;
125
+ const a = oe();
126
+ if (!a) return;
127
+ let s = !1;
110
128
  (async () => {
111
- const g = t.hive.active.individual.id;
112
- if (!g) {
113
- i || x(void 0);
129
+ const C = e.hive.active.individual.id;
130
+ if (!C) {
131
+ s || v(void 0);
114
132
  return;
115
133
  }
116
134
  try {
117
- const T = await t.hive.accessForDoc(g, ie());
118
- i || x(T ? T.toString() : void 0);
119
- } catch (T) {
120
- i || (console.error("[ShareModal] Error checking access:", T), x(void 0));
135
+ const U = await e.hive.accessForDoc(C, a);
136
+ s || v(U ? U.toString() : void 0);
137
+ } catch (U) {
138
+ s || (console.error("[ShareModal] Error checking access:", U), v(void 0));
121
139
  }
122
- })(), te(() => {
123
- i = !0;
140
+ })(), q(() => {
141
+ s = !0;
124
142
  });
125
- }), ue(() => {
126
- if (!t.isOpen) return;
127
- let i = !1;
143
+ }), ie(() => {
144
+ if (!e.isOpen) return;
145
+ let a = !1;
128
146
  (async () => {
129
- i || $(!0);
147
+ a || k(!0);
130
148
  try {
131
- const g = await se(t.hive, t.docUrl);
132
- i || (h(g), $(!1));
133
- } catch (g) {
134
- i || (console.error("[ShareModal] Error loading access list:", g), h({}), $(!1));
149
+ const s = await de(e.hive, e.docUrl);
150
+ a || (u(s), k(!1));
151
+ } catch (s) {
152
+ a || (console.error("[ShareModal] Error loading access list:", s), u({}), k(!1));
135
153
  }
136
- })(), te(() => {
137
- i = !0;
154
+ })(), q(() => {
155
+ a = !0;
138
156
  });
139
- }), ue(() => {
140
- if (!t.isOpen) return;
141
- const i = (g) => {
142
- g.key === "Escape" && t.onClose();
157
+ }), ie(() => {
158
+ if (!e.isOpen) return;
159
+ const a = (s) => {
160
+ s.key === "Escape" && e.onClose();
143
161
  };
144
- document.addEventListener("keydown", i), te(() => document.removeEventListener("keydown", i));
162
+ document.addEventListener("keydown", a), q(() => document.removeEventListener("keydown", a));
145
163
  });
146
- const oe = async (i) => {
147
- i.preventDefault();
148
- const g = e().trim();
149
- if (g) {
164
+ const fe = async (a) => {
165
+ a.preventDefault();
166
+ const s = t().trim();
167
+ if (s) {
150
168
  z(!0);
151
169
  try {
152
- const T = Ae.fromJson(g);
153
- if (!T) throw new Error("Invalid ContactCard JSON");
154
- const G = Ie.tryFromString("write");
155
- if (!G) throw new Error("Invalid access level");
156
- await t.hive.addMemberToDoc(t.docUrl, T, G), l("");
157
- } catch (T) {
158
- console.error("[ShareModal]", T);
170
+ const C = await ye(), U = C.ContactCard.fromJson(s);
171
+ if (!U) throw new Error("Invalid ContactCard JSON");
172
+ const P = C.Access.tryFromString("write");
173
+ if (!P) throw new Error("Invalid access level");
174
+ await e.hive.addMemberToDoc(e.docUrl, U, P), l("");
175
+ } catch (C) {
176
+ console.error("[ShareModal]", C);
159
177
  } finally {
160
- const T = await se(t.hive, t.docUrl);
161
- h(T), z(!1);
178
+ const C = await de(e.hive, e.docUrl);
179
+ u(C), z(!1);
162
180
  }
163
181
  }
164
- }, be = async (i) => {
182
+ }, he = async (a) => {
165
183
  try {
166
- await t.hive.revokeMemberFromDoc(t.docUrl, i);
167
- } catch (g) {
168
- console.error("[ShareModal]", g);
184
+ await e.hive.revokeMemberFromDoc(e.docUrl, a);
185
+ } catch (s) {
186
+ console.error("[ShareModal]", s);
169
187
  } finally {
170
- const g = await se(t.hive, t.docUrl);
171
- h(g);
188
+ const s = await de(e.hive, e.docUrl);
189
+ u(s);
172
190
  }
173
- }, ae = async () => {
191
+ }, ge = async () => {
174
192
  try {
175
- const i = Ie.tryFromString("write");
176
- if (!i) throw new Error("Invalid access level");
177
- await t.hive.setPublicAccess(t.docUrl, i);
178
- } catch (i) {
179
- console.error("[ShareModal]", i);
193
+ const s = (await ye()).Access.tryFromString("write");
194
+ if (!s) throw new Error("Invalid access level");
195
+ await e.hive.setPublicAccess(e.docUrl, s);
196
+ } catch (a) {
197
+ console.error("[ShareModal]", a);
180
198
  } finally {
181
- const i = await se(t.hive, t.docUrl);
182
- h(i);
199
+ const a = await de(e.hive, e.docUrl);
200
+ u(a);
183
201
  }
184
- }, fe = async () => {
202
+ }, ne = async () => {
185
203
  try {
186
- await t.hive.revokeMemberFromDoc(t.docUrl, Y());
187
- } catch (i) {
188
- console.error("[ShareModal]", i);
204
+ await e.hive.revokeMemberFromDoc(e.docUrl, G());
205
+ } catch (a) {
206
+ console.error("[ShareModal]", a);
189
207
  } finally {
190
- const i = await se(t.hive, t.docUrl);
191
- h(i);
208
+ const a = await de(e.hive, e.docUrl);
209
+ u(a);
192
210
  }
193
- }, he = (i) => `0x${i.slice(0, 12)}...`, ne = X(() => Object.entries(f()).sort(([i], [g]) => i.localeCompare(g)));
194
- return y(S, {
211
+ }, pe = (a) => `0x${a.slice(0, 12)}...`, re = we(() => Object.entries(g()).sort(([a], [s]) => a.localeCompare(s)));
212
+ return m(_, {
195
213
  get when() {
196
- return t.isOpen;
214
+ return e.isOpen;
197
215
  },
198
216
  get children() {
199
- var i = Ze(), g = i.firstChild, T = g.firstChild, G = T.firstChild, j = G.nextSibling, ge = T.nextSibling, J = ge.firstChild, le = J.nextSibling, P = ge.nextSibling, R = P.firstChild;
200
- return i.$$click = (n) => {
201
- n.target === n.currentTarget && t.onClose();
202
- }, g.$$click = (n) => n.stopPropagation(), j.$$click = () => t.onClose(), d(le, y(S, {
217
+ var a = Ge(), s = a.firstChild, C = s.firstChild, U = C.firstChild, P = U.nextSibling, T = C.nextSibling, L = T.firstChild, F = L.nextSibling, j = T.nextSibling, ce = j.firstChild;
218
+ return a.$$click = (i) => {
219
+ i.target === i.currentTarget && e.onClose();
220
+ }, s.$$click = (i) => i.stopPropagation(), P.$$click = () => e.onClose(), f(F, m(_, {
203
221
  get when() {
204
- return N();
222
+ return Q();
205
223
  },
206
224
  get children() {
207
- return Be();
225
+ return je();
208
226
  }
209
- }), null), d(le, y(S, {
227
+ }), null), f(F, m(_, {
210
228
  get when() {
211
- return q();
229
+ return le();
212
230
  },
213
231
  get children() {
214
- return [y(S, {
232
+ return [m(_, {
215
233
  get when() {
216
- return N();
234
+ return Q();
217
235
  },
218
236
  get children() {
219
- var n = Ve();
220
- return n.$$click = fe, L((m) => D(n, de, m)), n;
237
+ var i = Ke();
238
+ return i.$$click = ne, D((S) => E(i, ue, S)), i;
221
239
  }
222
- }), y(S, {
240
+ }), m(_, {
223
241
  get when() {
224
- return !N();
242
+ return !Q();
225
243
  },
226
244
  get children() {
227
- var n = Ye();
228
- return n.$$click = ae, L((m) => D(n, de, m)), n;
245
+ var i = Je();
246
+ return i.$$click = ge, D((S) => E(i, ue, S)), i;
229
247
  }
230
248
  })];
231
249
  }
232
- }), null), d(g, y(S, {
250
+ }), null), f(s, m(_, {
233
251
  get when() {
234
- return q();
252
+ return le();
235
253
  },
236
254
  get children() {
237
255
  return [(() => {
238
- var n = ze();
239
- return L((m) => D(n, Ue, m)), n;
256
+ var i = Le();
257
+ return D((S) => E(i, Ue, S)), i;
240
258
  })(), (() => {
241
- var n = qe(), m = n.firstChild, F = m.nextSibling, U = F.firstChild;
242
- return n.addEventListener("submit", oe), m.$$input = (A) => l(A.currentTarget.value), d(U, () => O() ? "Adding..." : "Add Member"), L((A) => {
243
- var K = {
244
- ...de,
245
- opacity: O() || !e().trim() ? "0.5" : "1"
246
- }, Q = O() || !e().trim();
247
- return A.e = D(U, K, A.e), Q !== A.t && (U.disabled = A.t = Q), A;
259
+ var i = We(), S = i.firstChild, K = S.nextSibling, V = K.firstChild;
260
+ return i.addEventListener("submit", fe), S.$$input = (M) => l(M.currentTarget.value), f(V, () => N() ? "Adding..." : "Add Member"), D((M) => {
261
+ var n = {
262
+ ...ue,
263
+ opacity: N() || !t().trim() ? "0.5" : "1"
264
+ }, r = N() || !t().trim();
265
+ return M.e = E(V, n, M.e), r !== M.t && (V.disabled = M.t = r), M;
248
266
  }, {
249
267
  e: void 0,
250
268
  t: void 0
251
- }), L(() => m.value = e()), n;
269
+ }), D(() => S.value = t()), i;
252
270
  })(), (() => {
253
- var n = ze();
254
- return L((m) => D(n, Ue, m)), n;
271
+ var i = Le();
272
+ return D((S) => E(i, Ue, S)), i;
255
273
  })()];
256
274
  }
257
- }), P), d(P, y(S, {
275
+ }), j), f(j, m(_, {
258
276
  get when() {
259
- return u();
277
+ return p();
260
278
  },
261
279
  get children() {
262
- return Ge();
280
+ return Be();
263
281
  }
264
- }), null), d(P, y(S, {
282
+ }), null), f(j, m(_, {
265
283
  get when() {
266
- return ee(() => !u())() && ne().length === 0;
284
+ return Z(() => !p())() && re().length === 0;
267
285
  },
268
286
  get children() {
269
- return Qe();
287
+ return Ye();
270
288
  }
271
- }), null), d(P, y(S, {
289
+ }), null), f(j, m(_, {
272
290
  get when() {
273
- return ee(() => !u())() && ne().length > 0;
291
+ return Z(() => !p())() && re().length > 0;
274
292
  },
275
293
  get children() {
276
- var n = Xe();
277
- return d(n, y(Re, {
294
+ var i = qe();
295
+ return f(i, m(Me, {
278
296
  get each() {
279
- return ne();
297
+ return re();
280
298
  },
281
- children: ([m, F]) => {
282
- const U = m === M(), A = m === _(), K = m === Y(), Q = De.indexOf(k()), pe = De.indexOf(F), we = Q >= 0 && pe >= 0 && pe <= Q && !U && !A, r = () => U ? "You" : A ? "Sync Server" : K ? "Public" : he(m);
299
+ children: ([S, K]) => {
300
+ const V = S === A(), M = S === ee(), n = S === G(), r = De.indexOf($()), h = De.indexOf(K), c = r >= 0 && h >= 0 && h <= r && !V && !M, b = () => V ? "You" : M ? "Sync Server" : n ? "Public" : pe(S);
283
301
  return (() => {
284
- var o = tt(), p = o.firstChild, a = p.firstChild, b = a.nextSibling;
285
- return Z(a, "color", U ? "#7ab4f5" : K ? "#b5bd68" : "#edf2f7"), d(a, r), d(b, F), d(o, y(S, {
286
- when: we,
302
+ var y = Xe(), J = y.firstChild, R = J.firstChild, W = R.nextSibling;
303
+ return X(R, "color", V ? "#7ab4f5" : n ? "#b5bd68" : "#edf2f7"), f(R, b), f(W, K), f(y, m(_, {
304
+ when: c,
287
305
  get children() {
288
- var v = et();
289
- return v.$$click = () => be(m), L((W) => D(v, {
290
- ...de
291
- }, W)), v;
306
+ var o = Qe();
307
+ return o.$$click = () => he(S), D((d) => E(o, {
308
+ ...ue
309
+ }, d)), o;
292
310
  }
293
- }), null), o;
311
+ }), null), y;
294
312
  })();
295
313
  }
296
- })), n;
314
+ })), i;
297
315
  }
298
- }), null), L((n) => {
299
- var m = ke, F = nt, U = {
300
- ...de
301
- }, A = Ee, K = Ee;
302
- return n.e = D(i, m, n.e), n.t = D(g, F, n.t), n.a = D(j, U, n.a), n.o = D(J, A, n.o), n.i = D(R, K, n.i), n;
316
+ }), null), D((i) => {
317
+ var S = Ce, K = Ze, V = {
318
+ ...ue
319
+ }, M = ze, n = ze;
320
+ return i.e = E(a, S, i.e), i.t = E(s, K, i.t), i.a = E(P, V, i.a), i.o = E(L, M, i.o), i.i = E(ce, n, i.i), i;
303
321
  }, {
304
322
  e: void 0,
305
323
  t: void 0,
306
324
  a: void 0,
307
325
  o: void 0,
308
326
  i: void 0
309
- }), i;
327
+ }), a;
310
328
  }
311
329
  });
312
330
  }
313
331
  xe(["click", "input"]);
314
- var it = /* @__PURE__ */ w('<div><div style=min-width:300px;max-width:400px><h3 style="margin:0 0 12px;font-size:15px"></h3><p style="margin:0 0 20px;font-size:13px;color:#6b7280"></p><div style=display:flex;justify-content:flex-end;gap:8px><button style="background:none;border:1px solid #2a323c;color:#edf2f7;padding:4px 14px;border-radius:4px;cursor:pointer;font-size:12px">Cancel</button><button style="background:#944;border:1px solid #a55;color:#fff;padding:4px 14px;border-radius:4px;cursor:pointer;font-size:12px">');
315
- function ot(t) {
316
- return ue(() => {
317
- if (!t.isOpen) return;
318
- const e = (l) => {
319
- l.key === "Escape" && t.onCancel();
332
+ var tt = /* @__PURE__ */ w('<div><div style=min-width:300px;max-width:400px><h3 style="margin:0 0 12px;font-size:15px"></h3><p style="margin:0 0 20px;font-size:13px;color:#6b7280"></p><div style=display:flex;justify-content:flex-end;gap:8px><button style="background:none;border:1px solid #2a323c;color:#edf2f7;padding:4px 14px;border-radius:4px;cursor:pointer;font-size:12px">Cancel</button><button style="background:#944;border:1px solid #a55;color:#fff;padding:4px 14px;border-radius:4px;cursor:pointer;font-size:12px">');
333
+ function nt(e) {
334
+ return ie(() => {
335
+ if (!e.isOpen) return;
336
+ const t = (l) => {
337
+ l.key === "Escape" && e.onCancel();
320
338
  };
321
- document.addEventListener("keydown", e), te(() => document.removeEventListener("keydown", e));
322
- }), y(S, {
339
+ document.addEventListener("keydown", t), q(() => document.removeEventListener("keydown", t));
340
+ }), m(_, {
323
341
  get when() {
324
- return t.isOpen;
342
+ return e.isOpen;
325
343
  },
326
344
  get children() {
327
- var e = it(), l = e.firstChild, f = l.firstChild, h = f.nextSibling, u = h.nextSibling, $ = u.firstChild, k = $.nextSibling;
328
- return e.$$click = (x) => {
329
- x.target === x.currentTarget && t.onCancel();
330
- }, d(f, () => t.title), d(h, () => t.message), $.$$click = () => t.onCancel(), k.$$click = () => t.onConfirm(), d(k, () => t.confirmLabel ?? "Confirm"), L((x) => {
331
- var O = ke, z = {
332
- ...Ce
345
+ var t = tt(), l = t.firstChild, g = l.firstChild, u = g.nextSibling, p = u.nextSibling, k = p.firstChild, $ = k.nextSibling;
346
+ return t.$$click = (v) => {
347
+ v.target === v.currentTarget && e.onCancel();
348
+ }, f(g, () => e.title), f(u, () => e.message), k.$$click = () => e.onCancel(), $.$$click = () => e.onConfirm(), f($, () => e.confirmLabel ?? "Confirm"), D((v) => {
349
+ var N = Ce, z = {
350
+ ...Se
333
351
  };
334
- return x.e = D(e, O, x.e), x.t = D(l, z, x.t), x;
352
+ return v.e = E(t, N, v.e), v.t = E(l, z, v.t), v;
335
353
  }, {
336
354
  e: void 0,
337
355
  t: void 0
338
- }), e;
356
+ }), t;
339
357
  }
340
358
  });
341
359
  }
342
360
  xe(["click"]);
343
- var at = /* @__PURE__ */ w('<div><div style=min-width:300px;max-width:400px><h3 style="margin:0 0 12px;font-size:15px">New Document</h3><input type=text style="width:100%;background:#15191e;border:1px solid #2a323c;color:#edf2f7;font-size:14px;padding:8px 10px;border-radius:4px;outline:none;box-sizing:border-box;margin-bottom:16px"><div style=display:flex;justify-content:flex-end;gap:8px><button style="background:none;border:1px solid #2a323c;color:#edf2f7;padding:4px 14px;border-radius:4px;cursor:pointer;font-size:12px">Cancel</button><button style="background:#2a5a8a;border:1px solid #3a6a9a;color:#fff;padding:4px 14px;border-radius:4px;cursor:pointer;font-size:12px">Create');
344
- function lt(t) {
345
- const [e, l] = C("");
346
- let f;
347
- ue(() => {
348
- if (!t.isOpen) return;
349
- l(""), requestAnimationFrame(() => f?.focus());
350
- const u = ($) => {
351
- $.key === "Escape" && t.onCancel();
361
+ var rt = /* @__PURE__ */ w('<div><div style=min-width:300px;max-width:400px><h3 style="margin:0 0 12px;font-size:15px">New Document</h3><input type=text style="width:100%;background:#15191e;border:1px solid #2a323c;color:#edf2f7;font-size:14px;padding:8px 10px;border-radius:4px;outline:none;box-sizing:border-box;margin-bottom:16px"><div style=display:flex;justify-content:flex-end;gap:8px><button style="background:none;border:1px solid #2a323c;color:#edf2f7;padding:4px 14px;border-radius:4px;cursor:pointer;font-size:12px">Cancel</button><button style="background:#2a5a8a;border:1px solid #3a6a9a;color:#fff;padding:4px 14px;border-radius:4px;cursor:pointer;font-size:12px">Create');
362
+ function it(e) {
363
+ const [t, l] = x("");
364
+ let g;
365
+ ie(() => {
366
+ if (!e.isOpen) return;
367
+ l(""), requestAnimationFrame(() => g?.focus());
368
+ const p = (k) => {
369
+ k.key === "Escape" && e.onCancel();
352
370
  };
353
- document.addEventListener("keydown", u), te(() => document.removeEventListener("keydown", u));
371
+ document.addEventListener("keydown", p), q(() => document.removeEventListener("keydown", p));
354
372
  });
355
- function h() {
356
- const u = e().trim();
357
- t.onConfirm(u || t.defaultTitle);
373
+ function u() {
374
+ const p = t().trim();
375
+ e.onConfirm(p || e.defaultTitle);
358
376
  }
359
- return y(S, {
377
+ return m(_, {
360
378
  get when() {
361
- return t.isOpen;
379
+ return e.isOpen;
362
380
  },
363
381
  get children() {
364
- var u = at(), $ = u.firstChild, k = $.firstChild, x = k.nextSibling, O = x.nextSibling, z = O.firstChild, ie = z.nextSibling;
365
- u.$$click = (_) => {
366
- _.target === _.currentTarget && t.onCancel();
367
- }, x.$$keydown = (_) => {
368
- _.key === "Enter" && h();
369
- }, x.$$input = (_) => l(_.currentTarget.value);
370
- var M = f;
371
- return typeof M == "function" ? Me(M, x) : f = x, z.$$click = () => t.onCancel(), ie.$$click = () => h(), L((_) => {
372
- var Y = ke, N = {
373
- ...Ce
374
- }, q = t.defaultTitle;
375
- return _.e = D(u, Y, _.e), _.t = D($, N, _.t), q !== _.a && He(x, "placeholder", _.a = q), _;
382
+ var p = rt(), k = p.firstChild, $ = k.firstChild, v = $.nextSibling, N = v.nextSibling, z = N.firstChild, oe = z.nextSibling;
383
+ p.$$click = (A) => {
384
+ A.target === A.currentTarget && e.onCancel();
385
+ }, v.$$keydown = (A) => {
386
+ A.key === "Enter" && u();
387
+ }, v.$$input = (A) => l(A.currentTarget.value);
388
+ var H = g;
389
+ return typeof H == "function" ? Ee(H, v) : g = v, z.$$click = () => e.onCancel(), oe.$$click = () => u(), D((A) => {
390
+ var ae = Ce, ee = {
391
+ ...Se
392
+ }, te = e.defaultTitle;
393
+ return A.e = E(p, ae, A.e), A.t = E(k, ee, A.t), te !== A.a && He(v, "placeholder", A.a = te), A;
376
394
  }, {
377
395
  e: void 0,
378
396
  t: void 0,
379
397
  a: void 0
380
- }), L(() => x.value = e()), u;
398
+ }), D(() => v.value = t()), p;
381
399
  }
382
400
  });
383
401
  }
384
402
  xe(["click", "input", "keydown"]);
385
- const ct = {};
386
- var st = /* @__PURE__ */ w('<div style="padding:8px 10px;color:#6b7280;font-style:italic">No documents yet'), dt = /* @__PURE__ */ w('<div style="position:absolute;top:34px;left:0;background:#191e24;border:1px solid #2a323c;border-radius:4px;max-height:400px;overflow-y:auto;min-width:280px;max-width:420px;z-index:1000;box-shadow:0 4px 12px rgba(0,0,0,0.4)">'), ut = /* @__PURE__ */ w('<button style="background:none;border:1px solid #2a323c;color:#edf2f7;font-size:13px;padding:4px 10px;border-radius:4px;cursor:pointer;white-space:nowrap">Share'), ft = /* @__PURE__ */ w('<button title="Copy automerge URL"style="background:none;border:1px solid #2a323c;font-size:13px;padding:4px 10px;border-radius:4px;cursor:pointer;white-space:nowrap">'), ht = /* @__PURE__ */ w('<button style="background:none;border:1px solid #2a323c;font-size:13px;padding:4px 10px;border-radius:4px;cursor:pointer;white-space:nowrap">'), gt = /* @__PURE__ */ w('<button style="background:none;border:1px solid #944;color:#c66;font-size:13px;padding:4px 10px;border-radius:4px;cursor:pointer;white-space:nowrap">Remove Doc'), pt = /* @__PURE__ */ w('<div style=display:flex;flex-direction:column;height:100vh;background:#1d232a><div style="display:flex;align-items:center;height:52px;min-height:52px;background:#191e24;color:#edf2f7;font-size:14px;font-family:system-ui, sans-serif;padding:0 12px;border-bottom:1px solid #15191e;box-sizing:border-box"><button style="background:none;border:1px solid #2a323c;color:#edf2f7;font-size:13px;padding:4px 10px;border-radius:4px;cursor:pointer;flex-shrink:0;margin-right:12px;white-space:nowrap">+ New</button><input type=text placeholder="Paste automerge:… URL"style="background:#15191e;border:1px solid #2a323c;color:#edf2f7;font-size:13px;padding:4px 10px;border-radius:4px;width:200px;min-width:80px;flex-shrink:1;margin-right:12px;outline:none"><div data-doc-switcher style=position:relative;flex:1;min-width:120px><button style="background:none;border:none;color:#edf2f7;font-size:14px;cursor:pointer;padding:4px 8px;border-radius:4px;max-width:100%;display:flex;align-items:center;gap:4px"><span style=overflow:hidden;text-overflow:ellipsis;white-space:nowrap></span><span style=flex-shrink:0>▾</span></button></div><div style=display:flex;align-items:center;flex-shrink:0;gap:8px></div></div><div style=flex:1;min-height:0;overflow:hidden>'), mt = /* @__PURE__ */ w('<div style="padding:8px 12px;cursor:pointer;border-bottom:1px solid #15191e;overflow:hidden;text-overflow:ellipsis;white-space:nowrap"> <span style=color:#6b7280;font-size:12px>'), yt = /* @__PURE__ */ w('<div style="width:24px;height:24px;border:2px solid #2a323c;border-top-color:#6b7280;border-radius:50%;animation:spin 0.8s linear infinite">'), vt = /* @__PURE__ */ w('<div style="display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;height:100%;background:#1d232a;font-family:system-ui, sans-serif;font-size:14px">'), xt = /* @__PURE__ */ w("<div style=height:100%>");
387
- function bt(t) {
388
- const e = t.tool, [l, f] = C(null), [h, u] = C("..."), [$, k] = C([]), [x, O] = C(!1), [z, ie] = C(null), [M, _] = C(""), [Y, N] = C(!1), [q, oe] = C(!1), [be, ae] = C(!1), [fe, he] = C(!1), [ne, i] = C(!1), [g, T] = C(!1), [G, j] = C(!1), [ge, J] = C(null), [le, P] = C(!1);
389
- let R, n = null, m = 0;
390
- function F(r) {
391
- n && (n(), n = null);
392
- const o = r.doc(), p = o ? e.getTitle(o) : e.defaultTitle;
393
- u(p), k(Te(e.id, M(), r.url, p));
394
- const a = () => {
395
- const b = r.doc();
403
+ const ot = {};
404
+ var at = /* @__PURE__ */ w('<div style="padding:8px 10px;color:#6b7280;font-style:italic">No documents yet'), lt = /* @__PURE__ */ w('<div style="position:absolute;top:34px;left:0;background:#191e24;border:1px solid #2a323c;border-radius:4px;max-height:400px;overflow-y:auto;min-width:280px;max-width:420px;z-index:1000;box-shadow:0 4px 12px rgba(0,0,0,0.4)">'), ct = /* @__PURE__ */ w('<button style="background:none;border:1px solid #2a323c;color:#edf2f7;font-size:13px;padding:4px 10px;border-radius:4px;cursor:pointer;white-space:nowrap">Share'), st = /* @__PURE__ */ w('<button title="Copy automerge URL"style="background:none;border:1px solid #2a323c;font-size:13px;padding:4px 10px;border-radius:4px;cursor:pointer;white-space:nowrap">'), dt = /* @__PURE__ */ w('<button style="background:none;border:1px solid #2a323c;font-size:13px;padding:4px 10px;border-radius:4px;cursor:pointer;white-space:nowrap">'), ut = /* @__PURE__ */ w('<button style="background:none;border:1px solid #944;color:#c66;font-size:13px;padding:4px 10px;border-radius:4px;cursor:pointer;white-space:nowrap">Remove Doc'), ft = /* @__PURE__ */ w('<div style=display:flex;flex-direction:column;height:100vh;background:#1d232a><div style="display:flex;align-items:center;height:52px;min-height:52px;background:#191e24;color:#edf2f7;font-size:14px;font-family:system-ui, sans-serif;padding:0 12px;border-bottom:1px solid #15191e;box-sizing:border-box"><button style="background:none;border:1px solid #2a323c;color:#edf2f7;font-size:13px;padding:4px 10px;border-radius:4px;cursor:pointer;flex-shrink:0;margin-right:12px;white-space:nowrap">+ New</button><input type=text placeholder="Paste automerge:… URL"style="background:#15191e;border:1px solid #2a323c;color:#edf2f7;font-size:13px;padding:4px 10px;border-radius:4px;width:200px;min-width:80px;flex-shrink:1;margin-right:12px;outline:none"><div data-doc-switcher style=position:relative;flex:1;min-width:120px><button style="background:none;border:none;color:#edf2f7;font-size:14px;cursor:pointer;padding:4px 8px;border-radius:4px;max-width:100%;display:flex;align-items:center;gap:4px"><span style=overflow:hidden;text-overflow:ellipsis;white-space:nowrap></span><span style=flex-shrink:0>▾</span></button></div><div style=display:flex;align-items:center;flex-shrink:0;gap:8px></div></div><div style=flex:1;min-height:0;overflow:hidden>'), ht = /* @__PURE__ */ w('<div style="padding:8px 12px;cursor:pointer;border-bottom:1px solid #15191e;overflow:hidden;text-overflow:ellipsis;white-space:nowrap"> <span style=color:#6b7280;font-size:12px>'), gt = /* @__PURE__ */ w('<div style="width:24px;height:24px;border:2px solid #2a323c;border-top-color:#6b7280;border-radius:50%;animation:spin 0.8s linear infinite">'), pt = /* @__PURE__ */ w('<div style="display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;height:100%;background:#1d232a;font-family:system-ui, sans-serif;font-size:14px">'), mt = /* @__PURE__ */ w("<div style=height:100%>");
405
+ function yt(e) {
406
+ const t = e.tool, [l, g] = x(null), [u, p] = x("..."), [k, $] = x([]), [v, N] = x(!1), [z, oe] = x(null), [H, A] = x(""), [ae, ee] = x(!1), [te, G] = x(!1), [be, Q] = x(!1), [le, fe] = x(!1), [he, ge] = x(!1), [ne, pe] = x(!1), [re, a] = x(!1), [s, C] = x(null), [U, P] = x(!1);
407
+ let T, L = null, F = 0;
408
+ function j(n) {
409
+ L && (L(), L = null);
410
+ const r = n.doc(), h = r ? t.getTitle(r) : t.defaultTitle;
411
+ p(h), $(Ie(t.id, H(), n.url, h));
412
+ const c = () => {
413
+ const b = n.doc();
396
414
  if (b) {
397
- const v = e.getTitle(b);
398
- u(v), k(Te(e.id, M(), r.url, v));
415
+ const y = t.getTitle(b);
416
+ p(y), $(Ie(t.id, H(), n.url, y));
399
417
  }
400
418
  };
401
- r.on("change", a), n = () => r.off("change", a);
419
+ n.on("change", c), L = () => n.off("change", c);
402
420
  }
403
- async function U(r) {
404
- const o = z();
405
- if (!o) return !0;
421
+ async function ce(n) {
422
+ const r = z();
423
+ if (!r) return !0;
406
424
  try {
407
425
  const {
408
- docIdFromAutomergeUrl: p,
409
- Identifier: a
410
- } = await import("@automerge/automerge-repo-keyhive"), b = p(r), v = o.active.individual.id, W = a.publicId(), [H, re] = await Promise.all([o.accessForDoc(v, b).catch(() => null), o.accessForDoc(W, b).catch(() => null)]);
411
- return console.log(`[${e.name}] Access check for ${r.slice(0, 30)}...: my=${H}, public=${re}`), !!(H || re);
412
- } catch (p) {
413
- return console.error(`[${e.name}] Access check error for ${r}:`, p), !0;
426
+ docIdFromAutomergeUrl: h,
427
+ Identifier: c
428
+ } = await import("@automerge/automerge-repo-keyhive"), b = h(n), y = r.active.individual.id, J = c.publicId(), [R, W] = await Promise.all([r.accessForDoc(y, b).catch(() => null), r.accessForDoc(J, b).catch(() => null)]);
429
+ return console.log(`[${t.name}] Access check for ${n.slice(0, 30)}...: my=${R}, public=${W}`), !!(R || W);
430
+ } catch (h) {
431
+ return console.error(`[${t.name}] Access check error for ${n}:`, h), !0;
414
432
  }
415
433
  }
416
- async function A(r) {
417
- const o = ++m;
418
- n && (n(), n = null), f(null), j(!1), J(null), P(!0), u("Loading...");
434
+ async function i(n) {
435
+ const r = ++F;
436
+ L && (L(), L = null), g(null), a(!1), C(null), P(!0), p("Loading...");
419
437
  try {
420
- if (!await U(r)) {
421
- if (o !== m) return;
422
- console.warn(`[${e.name}] No access to doc: ${r}`), P(!1), j(!0), J(r), ce(r);
438
+ if (!await ce(n)) {
439
+ if (r !== F) return;
440
+ console.warn(`[${t.name}] No access to doc: ${n}`), P(!1), a(!0), C(n), se(n);
423
441
  return;
424
442
  }
425
- if (o !== m) return;
426
- const p = (b) => {
427
- const v = b.doc();
428
- return v ? e.isDocReady ? e.isDocReady(v) : !!v : !1;
443
+ if (r !== F) return;
444
+ const h = (b) => {
445
+ const y = b.doc();
446
+ return y ? t.isDocReady ? t.isDocReady(y) : !!y : !1;
429
447
  };
430
- let a = R.find(r);
431
- if (await a.whenReady(), o !== m) return;
432
- if (!p(a)) {
433
- console.log(`[${e.name}] Doc incomplete, forcing re-sync for: ${r.slice(0, 30)}...`);
448
+ let c = T.find(n);
449
+ if (await c.whenReady(), r !== F) return;
450
+ if (!h(c)) {
451
+ console.log(`[${t.name}] Doc incomplete, forcing re-sync for: ${n.slice(0, 30)}...`);
434
452
  try {
435
- R.delete(r);
453
+ T.delete(n);
436
454
  } catch {
437
455
  }
438
- if (await new Promise((b) => setTimeout(b, 100)), o !== m || (a = R.find(r), await a.whenReady(), o !== m)) return;
456
+ if (await new Promise((b) => setTimeout(b, 100)), r !== F || (c = T.find(n), await c.whenReady(), r !== F)) return;
439
457
  }
440
- if (!p(a) && (ce(r), await new Promise((b) => {
441
- const v = () => {
442
- if (o !== m) {
443
- a.off("change", v), b();
458
+ if (!h(c) && (se(n), await new Promise((b) => {
459
+ const y = () => {
460
+ if (r !== F) {
461
+ c.off("change", y), b();
444
462
  return;
445
463
  }
446
- p(a) && (a.off("change", v), b());
464
+ h(c) && (c.off("change", y), b());
447
465
  };
448
- a.on("change", v), setTimeout(() => {
449
- a.off("change", v), b();
466
+ c.on("change", y), setTimeout(() => {
467
+ c.off("change", y), b();
450
468
  }, 3e4);
451
- }), o !== m))
469
+ }), r !== F))
452
470
  return;
453
- P(!1), ce(r), localStorage.setItem(me(e.id, M()), r), F(a), f(a);
454
- } catch (p) {
455
- if (o !== m) return;
456
- console.error(`[${e.name}] Failed to load doc: ${r}`, p), P(!1), j(!0), J(r), ce(r);
471
+ P(!1), se(n), localStorage.setItem(me(t.id, H()), n), j(c), g(c);
472
+ } catch (h) {
473
+ if (r !== F) return;
474
+ console.error(`[${t.name}] Failed to load doc: ${n}`, h), P(!1), a(!0), C(n), se(n);
457
475
  }
458
476
  }
459
- async function K(r = e.defaultTitle) {
460
- const o = {};
461
- e.init(o, R), e.setTitle && e.setTitle(o, r), o["@patchwork"] = {
462
- type: e.id
477
+ async function S(n = t.defaultTitle) {
478
+ const r = {};
479
+ t.init(r, T), t.setTitle && t.setTitle(r, n), r["@patchwork"] = {
480
+ type: t.id
463
481
  };
464
- const p = z();
465
- let a;
466
- p ? (a = await R.create2(o), console.log(`[${e.name}] Created document (keyhive): ${a.url}`), await p.addSyncServerPullToDoc(a.url), await p.keyhiveStorage.saveKeyhiveWithHash(p.keyhive)) : (a = R.create(o), console.log(`[${e.name}] Created document (legacy): ${a.url}`)), f(a), ce(a.url), localStorage.setItem(me(e.id, M()), a.url), F(a);
482
+ const h = z();
483
+ let c;
484
+ h ? (c = await T.create2(r), console.log(`[${t.name}] Created document (keyhive): ${c.url}`), await h.addSyncServerPullToDoc(c.url), await h.keyhiveStorage.saveKeyhiveWithHash(h.keyhive)) : (c = T.create(r), console.log(`[${t.name}] Created document (legacy): ${c.url}`)), g(c), se(c.url), localStorage.setItem(me(t.id, H()), c.url), j(c);
467
485
  }
468
- function Q() {
469
- n && (n(), n = null), f(null), u("..."), j(!1), J(null), localStorage.removeItem(me(e.id, M())), window.history.replaceState(null, "", window.location.pathname);
486
+ function K() {
487
+ L && (L(), L = null), g(null), p("..."), a(!1), C(null), localStorage.removeItem(me(t.id, H())), window.history.replaceState(null, "", window.location.pathname);
470
488
  }
471
- function pe() {
472
- const r = l();
473
- if (!r) return;
474
- const o = r.url;
475
- Q(), R.delete(o), k(Ke(e.id, M(), o));
489
+ function V() {
490
+ const n = l();
491
+ if (!n) return;
492
+ const r = n.url;
493
+ K(), T.delete(r), $(Ne(t.id, H(), r));
476
494
  }
477
- async function we() {
478
- const r = z();
479
- if (r)
495
+ async function M() {
496
+ const n = z();
497
+ if (n)
480
498
  try {
481
- const o = r.active.contactCard.toJson();
482
- await navigator.clipboard.writeText(o), he(!0), setTimeout(() => he(!1), 1500);
483
- } catch (o) {
484
- console.error(`[${e.name}] Failed to copy contact card:`, o);
499
+ const r = n.active.contactCard.toJson();
500
+ await navigator.clipboard.writeText(r), fe(!0), setTimeout(() => fe(!1), 1500);
501
+ } catch (r) {
502
+ console.error(`[${t.name}] Failed to copy contact card:`, r);
485
503
  }
486
504
  }
487
505
  return $e(async () => {
488
- if (t.config?.legacyMode) {
489
- R = t.config.repo;
490
- const p = `standalone-frame-identity-${e.id}`;
491
- let a = localStorage.getItem(p);
492
- if (!a) {
506
+ if (e.config?.legacyMode) {
507
+ T = e.config.repo;
508
+ const h = `standalone-frame-identity-${t.id}`;
509
+ let c = localStorage.getItem(h);
510
+ if (!c) {
493
511
  const b = new Uint8Array(16);
494
- crypto.getRandomValues(b), a = Array.from(b).map((v) => v.toString(16).padStart(2, "0")).join(""), localStorage.setItem(p, a);
512
+ crypto.getRandomValues(b), c = Array.from(b).map((y) => y.toString(16).padStart(2, "0")).join(""), localStorage.setItem(h, c);
495
513
  }
496
- _(a), k(ve(e.id, a)), T(!0), console.log(`[${e.name}] Legacy mode initialized, identity: 0x${a.slice(0, 12)}...`);
514
+ A(c), $(ve(t.id, c)), pe(!0), console.log(`[${t.name}] Legacy mode initialized, identity: 0x${c.slice(0, 12)}...`);
497
515
  } else {
498
516
  const [{
499
- Repo: p
517
+ Repo: h
500
518
  }, {
501
- IndexedDBStorageAdapter: a
519
+ IndexedDBStorageAdapter: c
502
520
  }, {
503
521
  BrowserWebSocketClientAdapter: b
504
- }, v] = await Promise.all([import("@automerge/automerge-repo"), import("@automerge/automerge-repo-storage-indexeddb"), import("@automerge/automerge-repo-network-websocket"), import("@automerge/automerge-repo-keyhive")]);
505
- v.initKeyhiveWasm();
506
- const W = new a(`${e.id}-keyhive`), H = ct?.VITE_SYNC_URL, re = new b(H || e.syncUrl || "ws://localhost:3030"), c = `${e.id}-${Math.random().toString(36).slice(2)}`, s = await v.initializeAutomergeRepoKeyhive({
507
- storage: W,
508
- peerIdSuffix: c,
509
- networkAdapter: re,
522
+ }, y] = await Promise.all([import("@automerge/automerge-repo"), import("@automerge/automerge-repo-storage-indexeddb"), import("@automerge/automerge-repo-network-websocket"), import("@automerge/automerge-repo-keyhive")]);
523
+ y.initKeyhiveWasm();
524
+ const J = new c(`${t.id}-keyhive`), R = ot?.VITE_SYNC_URL, W = new b(R || t.syncUrl || "ws://localhost:3030"), o = `${t.id}-${Math.random().toString(36).slice(2)}`, d = await y.initializeAutomergeRepoKeyhive({
525
+ storage: J,
526
+ peerIdSuffix: o,
527
+ networkAdapter: W,
510
528
  automaticArchiveIngestion: !0,
511
529
  onlyShareWithHardcodedServerPeerId: !0,
512
530
  cacheHashes: !0
513
531
  });
514
- window.hive = s;
515
- const I = new p({
516
- storage: new a(),
517
- network: [s.networkAdapter],
518
- peerId: s.peerId,
519
- sharePolicy: async (V) => V === s.syncServer?.peerId,
520
- idFactory: s.idFactory
532
+ window.hive = d;
533
+ const I = new h({
534
+ storage: new c(),
535
+ network: [d.networkAdapter],
536
+ peerId: d.peerId,
537
+ sharePolicy: async (Y) => Y === d.syncServer?.peerId,
538
+ idFactory: d.idFactory
521
539
  });
522
- R = I, s.linkRepo(I), ie(s);
523
- const B = v.uint8ArrayToHex(s.active.individual.id.toBytes());
524
- _(B), k(ve(e.id, B)), T(!0), console.log(`[${e.name}] Keyhive initialized, identity: 0x${B.slice(0, 12)}...`), s.networkAdapter.on("ingest-remote", async () => {
525
- const V = ge();
526
- if (V) {
527
- await U(V) && (console.log(`[${e.name}] Access granted, loading: ${V}`), await A(V));
540
+ T = I, d.linkRepo(I), oe(d);
541
+ const B = y.uint8ArrayToHex(d.active.individual.id.toBytes());
542
+ A(B), $(ve(t.id, B)), pe(!0), console.log(`[${t.name}] Keyhive initialized, identity: 0x${B.slice(0, 12)}...`), d.networkAdapter.on("ingest-remote", async () => {
543
+ const Y = s();
544
+ if (Y) {
545
+ await ce(Y) && (console.log(`[${t.name}] Access granted, loading: ${Y}`), await i(Y));
528
546
  return;
529
547
  }
530
- const E = l();
531
- E && (await U(E.url) || (console.log(`[${e.name}] Access revoked for: ${E.url}`), n && (n(), n = null), f(null), u("..."), j(!0), J(E.url)));
548
+ const O = l();
549
+ O && (await ce(O.url) || (console.log(`[${t.name}] Access revoked for: ${O.url}`), L && (L(), L = null), g(null), p("..."), a(!0), C(O.url)));
532
550
  });
533
551
  }
534
- const r = Le();
535
- if (r) {
536
- console.log(`[${e.name}] Loading doc from hash: ${r}`), await A(r);
552
+ const n = Te();
553
+ if (n) {
554
+ console.log(`[${t.name}] Loading doc from hash: ${n}`), await i(n);
537
555
  return;
538
556
  }
539
- const o = localStorage.getItem(me(e.id, M()));
540
- if (o) {
541
- console.log(`[${e.name}] Found existing doc: ${o}`), await A(o);
557
+ const r = localStorage.getItem(me(t.id, H()));
558
+ if (r) {
559
+ console.log(`[${t.name}] Found existing doc: ${r}`), await i(r);
542
560
  return;
543
561
  }
544
- console.log(`[${e.name}] No doc found, starting blank`);
562
+ console.log(`[${t.name}] No doc found, starting blank`);
545
563
  }), $e(() => {
546
- const r = async () => {
547
- const o = Le();
548
- o && (console.log(`[${e.name}] Hash changed, loading: ${o}`), await A(o));
564
+ const n = async () => {
565
+ const r = Te();
566
+ r && (console.log(`[${t.name}] Hash changed, loading: ${r}`), await i(r));
549
567
  };
550
- window.addEventListener("hashchange", r), te(() => window.removeEventListener("hashchange", r));
568
+ window.addEventListener("hashchange", n), q(() => window.removeEventListener("hashchange", n));
551
569
  }), $e(() => {
552
- const r = (o) => {
553
- o.target.closest("[data-doc-switcher]") || O(!1);
570
+ const n = (r) => {
571
+ r.target.closest("[data-doc-switcher]") || N(!1);
554
572
  };
555
- document.addEventListener("mousedown", r), te(() => document.removeEventListener("mousedown", r));
573
+ document.addEventListener("mousedown", n), q(() => document.removeEventListener("mousedown", n));
556
574
  }), (() => {
557
- var r = pt(), o = r.firstChild, p = o.firstChild, a = p.nextSibling, b = a.nextSibling, v = b.firstChild, W = v.firstChild;
558
- W.nextSibling;
559
- var H = b.nextSibling, re = o.nextSibling;
560
- return p.$$click = () => ae(!0), a.$$keydown = (c) => {
561
- if (c.key === "Enter") {
562
- const s = c.currentTarget.value.trim();
563
- if (s) {
564
- const I = s.startsWith("automerge:") ? s : `automerge:${s}`;
565
- A(I), c.currentTarget.value = "";
575
+ var n = ft(), r = n.firstChild, h = r.firstChild, c = h.nextSibling, b = c.nextSibling, y = b.firstChild, J = y.firstChild;
576
+ J.nextSibling;
577
+ var R = b.nextSibling, W = r.nextSibling;
578
+ return h.$$click = () => Q(!0), c.$$keydown = (o) => {
579
+ if (o.key === "Enter") {
580
+ const d = o.currentTarget.value.trim();
581
+ if (d) {
582
+ const I = d.startsWith("automerge:") ? d : `automerge:${d}`;
583
+ i(I), o.currentTarget.value = "";
566
584
  }
567
585
  }
568
- }, v.$$click = () => O(!x()), d(W, h), d(b, y(S, {
586
+ }, y.$$click = () => N(!v()), f(J, u), f(b, m(_, {
569
587
  get when() {
570
- return x();
588
+ return v();
571
589
  },
572
590
  get children() {
573
- var c = dt();
574
- return d(c, y(Re, {
591
+ var o = lt();
592
+ return f(o, m(Me, {
575
593
  get each() {
576
- return $();
594
+ return k();
577
595
  },
578
- children: (s) => (() => {
579
- var I = mt(), B = I.firstChild, V = B.nextSibling;
580
- return I.addEventListener("mouseleave", (E) => {
581
- E.currentTarget.style.background = "transparent";
582
- }), I.addEventListener("mouseenter", (E) => {
583
- E.currentTarget.style.background = "#1d232a";
596
+ children: (d) => (() => {
597
+ var I = ht(), B = I.firstChild, Y = B.nextSibling;
598
+ return I.addEventListener("mouseleave", (O) => {
599
+ O.currentTarget.style.background = "transparent";
600
+ }), I.addEventListener("mouseenter", (O) => {
601
+ O.currentTarget.style.background = "#1d232a";
584
602
  }), I.$$click = () => {
585
- A(s.url), O(!1);
586
- }, d(I, () => s.title || "Untitled", B), d(V, () => We(s.url)), L((E) => {
587
- var Se = l()?.url === s.url ? "#7ab4f5" : "#edf2f7", _e = l()?.url === s.url ? "bold" : "normal";
588
- return Se !== E.e && Z(I, "color", E.e = Se), _e !== E.t && Z(I, "font-weight", E.t = _e), E;
603
+ i(d.url), N(!1);
604
+ }, f(I, () => d.title || "Untitled", B), f(Y, () => Ve(d.url)), D((O) => {
605
+ var _e = l()?.url === d.url ? "#7ab4f5" : "#edf2f7", Ae = l()?.url === d.url ? "bold" : "normal";
606
+ return _e !== O.e && X(I, "color", O.e = _e), Ae !== O.t && X(I, "font-weight", O.t = Ae), O;
589
607
  }, {
590
608
  e: void 0,
591
609
  t: void 0
592
610
  }), I;
593
611
  })()
594
- }), null), d(c, y(S, {
612
+ }), null), f(o, m(_, {
595
613
  get when() {
596
- return $().length === 0;
614
+ return k().length === 0;
597
615
  },
598
616
  get children() {
599
- return st();
617
+ return at();
600
618
  }
601
- }), null), c;
619
+ }), null), o;
602
620
  }
603
- }), null), d(H, y(S, {
621
+ }), null), f(R, m(_, {
604
622
  get when() {
605
- return ee(() => !!l())() && z();
623
+ return Z(() => !!l())() && z();
606
624
  },
607
625
  get children() {
608
- var c = ut();
609
- return c.$$click = () => N(!0), c;
626
+ var o = ct();
627
+ return o.$$click = () => ee(!0), o;
610
628
  }
611
- }), null), d(H, y(S, {
629
+ }), null), f(R, m(_, {
612
630
  get when() {
613
631
  return l();
614
632
  },
615
633
  get children() {
616
- var c = ft();
617
- return c.$$click = async () => {
618
- const s = l();
619
- s && (await navigator.clipboard.writeText(s.url), i(!0), setTimeout(() => i(!1), 1500));
620
- }, d(c, () => ne() ? "Copied!" : "Copy URL"), L((s) => Z(c, "color", ne() ? "#b5bd68" : "#edf2f7")), c;
634
+ var o = st();
635
+ return o.$$click = async () => {
636
+ const d = l();
637
+ d && (await navigator.clipboard.writeText(d.url), ge(!0), setTimeout(() => ge(!1), 1500));
638
+ }, f(o, () => he() ? "Copied!" : "Copy URL"), D((d) => X(o, "color", he() ? "#b5bd68" : "#edf2f7")), o;
621
639
  }
622
- }), null), d(H, y(S, {
640
+ }), null), f(R, m(_, {
623
641
  get when() {
624
642
  return z();
625
643
  },
626
644
  get children() {
627
- var c = ht();
628
- return c.$$click = () => void we(), d(c, () => fe() ? "Copied!" : "Contact Card"), L((s) => Z(c, "color", fe() ? "#b5bd68" : "#edf2f7")), c;
645
+ var o = dt();
646
+ return o.$$click = () => void M(), f(o, () => le() ? "Copied!" : "Contact Card"), D((d) => X(o, "color", le() ? "#b5bd68" : "#edf2f7")), o;
629
647
  }
630
- }), null), d(H, y(S, {
648
+ }), null), f(R, m(_, {
631
649
  get when() {
632
650
  return l();
633
651
  },
634
652
  get children() {
635
- var c = gt();
636
- return c.$$click = () => oe(!0), c;
653
+ var o = ut();
654
+ return o.$$click = () => G(!0), o;
637
655
  }
638
- }), null), d(re, y(S, {
656
+ }), null), f(W, m(_, {
639
657
  get when() {
640
658
  return l();
641
659
  },
642
660
  keyed: !0,
643
661
  get fallback() {
644
662
  return (() => {
645
- var c = vt();
646
- return d(c, y(S, {
663
+ var o = pt();
664
+ return f(o, m(_, {
647
665
  get when() {
648
- return le() || !g();
666
+ return U() || !ne();
649
667
  },
650
668
  get children() {
651
- return yt();
669
+ return gt();
652
670
  }
653
- }), null), d(c, (() => {
654
- var s = ee(() => !!G());
655
- return () => s() ? "Document unavailable: you may not have access" : ee(() => !!le())() ? "Loading document..." : ee(() => !!g())() ? "No document open" : t.config?.legacyMode ? "Initializing..." : "Initializing keyhive...";
656
- })(), null), L((s) => Z(c, "color", G() ? "#c66" : "#6b7280")), c;
671
+ }), null), f(o, (() => {
672
+ var d = Z(() => !!re());
673
+ return () => d() ? "Document unavailable: you may not have access" : Z(() => !!U())() ? "Loading document..." : Z(() => !!ne())() ? "No document open" : e.config?.legacyMode ? "Initializing..." : "Initializing keyhive...";
674
+ })(), null), D((d) => X(o, "color", re() ? "#c66" : "#6b7280")), o;
657
675
  })();
658
676
  },
659
- children: (c) => {
660
- const s = document.createElement("div");
661
- return s.repo = R, s.style.height = "100%", (() => {
662
- var I = xt();
663
- return Me((B) => {
664
- B.appendChild(s), e.render(c, s);
677
+ children: (o) => {
678
+ const d = document.createElement("div");
679
+ return d.repo = T, d.style.height = "100%", (() => {
680
+ var I = mt();
681
+ return Ee((B) => {
682
+ B.appendChild(d), t.render(o, d);
665
683
  }, I), I;
666
684
  })();
667
685
  }
668
- })), d(r, y(S, {
686
+ })), f(n, m(_, {
669
687
  get when() {
670
- return ee(() => !!z())() && l();
688
+ return Z(() => !!z())() && l();
671
689
  },
672
690
  get children() {
673
- return y(rt, {
691
+ return m(et, {
674
692
  get isOpen() {
675
- return Y();
693
+ return ae();
676
694
  },
677
695
  get docUrl() {
678
696
  return l().url;
@@ -680,70 +698,70 @@ function bt(t) {
680
698
  get hive() {
681
699
  return z();
682
700
  },
683
- onClose: () => N(!1)
701
+ onClose: () => ee(!1)
684
702
  });
685
703
  }
686
- }), null), d(r, y(lt, {
704
+ }), null), f(n, m(it, {
687
705
  get isOpen() {
688
706
  return be();
689
707
  },
690
708
  get defaultTitle() {
691
- return e.defaultTitle;
709
+ return t.defaultTitle;
692
710
  },
693
- onConfirm: (c) => {
694
- ae(!1), K(c);
711
+ onConfirm: (o) => {
712
+ Q(!1), S(o);
695
713
  },
696
- onCancel: () => ae(!1)
697
- }), null), d(r, y(ot, {
714
+ onCancel: () => Q(!1)
715
+ }), null), f(n, m(nt, {
698
716
  get isOpen() {
699
- return q();
717
+ return te();
700
718
  },
701
719
  title: "Remove Document",
702
720
  message: "Remove this document from your history? The document data will be deleted locally.",
703
721
  confirmLabel: "Remove",
704
722
  onConfirm: () => {
705
- oe(!1), pe();
723
+ G(!1), V();
706
724
  },
707
- onCancel: () => oe(!1)
708
- }), null), L((c) => {
709
- var s = !g(), I = g() ? "1" : "0.4";
710
- return s !== c.e && (p.disabled = c.e = s), I !== c.t && Z(p, "opacity", c.t = I), c;
725
+ onCancel: () => G(!1)
726
+ }), null), D((o) => {
727
+ var d = !ne(), I = ne() ? "1" : "0.4";
728
+ return d !== o.e && (h.disabled = o.e = d), I !== o.t && X(h, "opacity", o.t = I), o;
711
729
  }, {
712
730
  e: void 0,
713
731
  t: void 0
714
- }), r;
732
+ }), n;
715
733
  })();
716
734
  }
717
735
  xe(["click", "keydown"]);
718
- async function wt(t) {
719
- const e = t.find((k) => k.type === "patchwork:tool"), l = t.find((k) => k.type === "patchwork:datatype");
720
- if (!e) throw new Error("No patchwork:tool plugin found in plugins array");
736
+ async function vt(e) {
737
+ const t = e.find(($) => $.type === "patchwork:tool"), l = e.find(($) => $.type === "patchwork:datatype");
738
+ if (!t) throw new Error("No patchwork:tool plugin found in plugins array");
721
739
  if (!l) throw new Error("No patchwork:datatype plugin found in plugins array");
722
- const [f, h] = await Promise.all([e.load(), l.load()]), u = {};
723
- h.init(u, {});
724
- const $ = h.getTitle(u);
740
+ const [g, u] = await Promise.all([t.load(), l.load()]), p = {};
741
+ u.init(p, {});
742
+ const k = u.getTitle(p);
725
743
  return {
726
- id: e.id,
727
- name: e.name,
728
- defaultTitle: $,
729
- init: h.init,
730
- getTitle: h.getTitle,
731
- setTitle: h.setTitle,
732
- render: f
744
+ id: t.id,
745
+ name: t.name,
746
+ defaultTitle: k,
747
+ init: u.init,
748
+ getTitle: u.getTitle,
749
+ setTitle: u.setTitle,
750
+ render: g
733
751
  };
734
752
  }
735
- async function St(t, e, l) {
736
- let f;
737
- Array.isArray(e) ? f = await wt(e) : f = e, Ne(() => y(bt, {
738
- tool: f,
753
+ async function wt(e, t, l) {
754
+ let g;
755
+ Array.isArray(t) ? g = await vt(t) : g = t, Pe(() => m(yt, {
756
+ tool: g,
739
757
  config: l
740
- }), t);
758
+ }), e);
741
759
  }
742
760
  export {
743
- ot as ConfirmModal,
744
- lt as NewDocModal,
745
- rt as ShareModal,
746
- Ce as cardStyle,
747
- St as mountStandaloneApp,
748
- ke as overlayStyle
761
+ nt as ConfirmModal,
762
+ it as NewDocModal,
763
+ et as ShareModal,
764
+ Se as cardStyle,
765
+ wt as mountStandaloneApp,
766
+ Ce as overlayStyle
749
767
  };