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