@jtfmumm/patchwork-standalone-frame 0.1.0 → 0.2.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,51 +1,48 @@
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) {
9
- return `${e}-doc-history-${t}`;
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}`;
10
7
  }
11
- function me(e, t) {
12
- return `${e}-standalone-${t}`;
8
+ function me(t, e) {
9
+ return `${t}-standalone-${e}`;
13
10
  }
14
- function we(e, t) {
11
+ function ve(t, e) {
15
12
  try {
16
- const a = localStorage.getItem(Pe(e, t));
17
- return a ? JSON.parse(a) : [];
13
+ const l = localStorage.getItem(Pe(t, e));
14
+ return l ? JSON.parse(l) : [];
18
15
  } catch {
19
16
  return [];
20
17
  }
21
18
  }
22
- function Fe(e, t, a) {
23
- localStorage.setItem(Pe(e, t), JSON.stringify(a));
19
+ function Fe(t, e, l) {
20
+ localStorage.setItem(Pe(t, e), JSON.stringify(l));
24
21
  }
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;
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, $), $;
30
27
  }
31
- function qe(e, t, a) {
32
- const y = we(e, t).filter((b) => b.url !== a);
33
- return Fe(e, t, y), y;
28
+ function Ke(t, e, l) {
29
+ const f = ve(t, e).filter((h) => h.url !== l);
30
+ return Fe(t, e, f), f;
34
31
  }
35
- function Ge(e) {
36
- const t = "automerge:";
37
- if (e.startsWith(t)) {
38
- const a = e.slice(t.length);
39
- return t + a.slice(0, 12) + "...";
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) + "...";
40
37
  }
41
- return e;
38
+ return t;
42
39
  }
43
- function Te() {
44
- const e = window.location.hash.slice(1);
45
- return e && e.startsWith("automerge:") ? e : null;
40
+ function Le() {
41
+ const t = window.location.hash.slice(1);
42
+ return t && t.startsWith("automerge:") ? t : null;
46
43
  }
47
- function le(e) {
48
- window.history.replaceState(null, "", `#${e}`);
44
+ function ce(t) {
45
+ window.history.replaceState(null, "", `#${t}`);
49
46
  }
50
47
  const ke = {
51
48
  position: "fixed",
@@ -63,21 +60,21 @@ const ke = {
63
60
  "box-shadow": "0 8px 24px rgba(0,0,0,0.5)",
64
61
  "font-family": "system-ui, sans-serif"
65
62
  };
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;
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>');
64
+ 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;
74
71
  }
75
- const at = {
72
+ const nt = {
76
73
  ...Ce,
77
74
  width: "420px",
78
75
  "max-height": "80vh",
79
76
  "overflow-y": "auto"
80
- }, ce = {
77
+ }, de = {
81
78
  background: "none",
82
79
  border: "1px solid #2a323c",
83
80
  color: "#edf2f7",
@@ -85,224 +82,224 @@ const at = {
85
82
  "border-radius": "4px",
86
83
  cursor: "pointer",
87
84
  "font-size": "12px"
88
- }, Ue = {
85
+ }, Ee = {
89
86
  "font-size": "13px",
90
87
  color: "#6b7280",
91
88
  margin: "16px 0 8px"
92
- }, Oe = {
89
+ }, Ue = {
93
90
  border: "none",
94
91
  "border-top": "1px solid #2a323c",
95
92
  margin: "12px 0"
96
93
  };
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;
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;
103
100
  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(() => {
111
- if (!e.isOpen) return;
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;
112
109
  let i = !1;
113
110
  (async () => {
114
- const d = e.hive.active.individual.id;
115
- if (!d) {
111
+ const g = t.hive.active.individual.id;
112
+ if (!g) {
116
113
  i || x(void 0);
117
114
  return;
118
115
  }
119
116
  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));
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));
124
121
  }
125
- })(), Z(() => {
122
+ })(), te(() => {
126
123
  i = !0;
127
124
  });
128
- }), se(() => {
129
- if (!e.isOpen) return;
125
+ }), ue(() => {
126
+ if (!t.isOpen) return;
130
127
  let i = !1;
131
128
  (async () => {
132
- i || C(!0);
129
+ i || $(!0);
133
130
  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));
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));
138
135
  }
139
- })(), Z(() => {
136
+ })(), te(() => {
140
137
  i = !0;
141
138
  });
142
- }), se(() => {
143
- if (!e.isOpen) return;
144
- const i = (d) => {
145
- d.key === "Escape" && e.onClose();
139
+ }), ue(() => {
140
+ if (!t.isOpen) return;
141
+ const i = (g) => {
142
+ g.key === "Escape" && t.onClose();
146
143
  };
147
- document.addEventListener("keydown", i), Z(() => document.removeEventListener("keydown", i));
144
+ document.addEventListener("keydown", i), te(() => document.removeEventListener("keydown", i));
148
145
  });
149
- const re = async (i) => {
146
+ const oe = async (i) => {
150
147
  i.preventDefault();
151
- const d = t().trim();
152
- if (d) {
153
- T(!0);
148
+ const g = e().trim();
149
+ if (g) {
150
+ z(!0);
154
151
  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);
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);
162
159
  } finally {
163
- const L = await ae(e.hive, e.docUrl);
164
- b(L), T(!1);
160
+ const T = await se(t.hive, t.docUrl);
161
+ h(T), z(!1);
165
162
  }
166
163
  }
167
- }, xe = async (i) => {
164
+ }, be = async (i) => {
168
165
  try {
169
- await e.hive.revokeMemberFromDoc(e.docUrl, i);
170
- } catch (d) {
171
- console.error("[ShareModal]", d);
166
+ await t.hive.revokeMemberFromDoc(t.docUrl, i);
167
+ } catch (g) {
168
+ console.error("[ShareModal]", g);
172
169
  } finally {
173
- const d = await ae(e.hive, e.docUrl);
174
- b(d);
170
+ const g = await se(t.hive, t.docUrl);
171
+ h(g);
175
172
  }
176
- }, ie = async () => {
173
+ }, ae = async () => {
177
174
  try {
178
- const i = De.tryFromString("write");
175
+ const i = Ie.tryFromString("write");
179
176
  if (!i) throw new Error("Invalid access level");
180
- await e.hive.setPublicAccess(e.docUrl, i);
177
+ await t.hive.setPublicAccess(t.docUrl, i);
181
178
  } catch (i) {
182
179
  console.error("[ShareModal]", i);
183
180
  } finally {
184
- const i = await ae(e.hive, e.docUrl);
185
- b(i);
181
+ const i = await se(t.hive, t.docUrl);
182
+ h(i);
186
183
  }
187
- }, ue = async () => {
184
+ }, fe = async () => {
188
185
  try {
189
- await e.hive.revokeMemberFromDoc(e.docUrl, Y());
186
+ await t.hive.revokeMemberFromDoc(t.docUrl, Y());
190
187
  } catch (i) {
191
188
  console.error("[ShareModal]", i);
192
189
  } finally {
193
- const i = await ae(e.hive, e.docUrl);
194
- b(i);
190
+ const i = await se(t.hive, t.docUrl);
191
+ h(i);
195
192
  }
196
- }, fe = (i) => `0x${i.slice(0, 12)}...`, ee = Q(() => Object.entries(y()).sort(([i], [d]) => i.localeCompare(d)));
197
- return g(k, {
193
+ }, he = (i) => `0x${i.slice(0, 12)}...`, ne = X(() => Object.entries(f()).sort(([i], [g]) => i.localeCompare(g)));
194
+ return y(S, {
198
195
  get when() {
199
- return e.isOpen;
196
+ return t.isOpen;
200
197
  },
201
198
  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;
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;
203
200
  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, {
201
+ n.target === n.currentTarget && t.onClose();
202
+ }, g.$$click = (n) => n.stopPropagation(), j.$$click = () => t.onClose(), d(le, y(S, {
206
203
  get when() {
207
204
  return N();
208
205
  },
209
206
  get children() {
210
- return Qe();
207
+ return Be();
211
208
  }
212
- }), null), s(oe, g(k, {
209
+ }), null), d(le, y(S, {
213
210
  get when() {
214
- return V();
211
+ return q();
215
212
  },
216
213
  get children() {
217
- return [g(k, {
214
+ return [y(S, {
218
215
  get when() {
219
216
  return N();
220
217
  },
221
218
  get children() {
222
- var n = Xe();
223
- return n.$$click = ue, I((u) => z(n, ce, u)), n;
219
+ var n = Ve();
220
+ return n.$$click = fe, L((m) => D(n, de, m)), n;
224
221
  }
225
- }), g(k, {
222
+ }), y(S, {
226
223
  get when() {
227
224
  return !N();
228
225
  },
229
226
  get children() {
230
- var n = Ze();
231
- return n.$$click = ie, I((u) => z(n, ce, u)), n;
227
+ var n = Ye();
228
+ return n.$$click = ae, L((m) => D(n, de, m)), n;
232
229
  }
233
230
  })];
234
231
  }
235
- }), null), s(d, g(k, {
232
+ }), null), d(g, y(S, {
236
233
  get when() {
237
- return V();
234
+ return q();
238
235
  },
239
236
  get children() {
240
237
  return [(() => {
241
238
  var n = ze();
242
- return I((u) => z(n, Oe, u)), n;
239
+ return L((m) => D(n, Ue, m)), n;
243
240
  })(), (() => {
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;
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;
251
248
  }, {
252
249
  e: void 0,
253
250
  t: void 0
254
- }), I(() => u.value = t()), n;
251
+ }), L(() => m.value = e()), n;
255
252
  })(), (() => {
256
253
  var n = ze();
257
- return I((u) => z(n, Oe, u)), n;
254
+ return L((m) => D(n, Ue, m)), n;
258
255
  })()];
259
256
  }
260
- }), H), s(H, g(k, {
257
+ }), P), d(P, y(S, {
261
258
  get when() {
262
- return f();
259
+ return u();
263
260
  },
264
261
  get children() {
265
- return tt();
262
+ return Ge();
266
263
  }
267
- }), null), s(H, g(k, {
264
+ }), null), d(P, y(S, {
268
265
  get when() {
269
- return te(() => !f())() && ee().length === 0;
266
+ return ee(() => !u())() && ne().length === 0;
270
267
  },
271
268
  get children() {
272
- return nt();
269
+ return Qe();
273
270
  }
274
- }), null), s(H, g(k, {
271
+ }), null), d(P, y(S, {
275
272
  get when() {
276
- return te(() => !f())() && ee().length > 0;
273
+ return ee(() => !u())() && ne().length > 0;
277
274
  },
278
275
  get children() {
279
- var n = rt();
280
- return s(n, g(Re, {
276
+ var n = Xe();
277
+ return d(n, y(Re, {
281
278
  get each() {
282
- return ee();
279
+ return ne();
283
280
  },
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);
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);
286
283
  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,
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,
290
287
  get children() {
291
- var m = ot();
292
- return m.$$click = () => xe(u), I((R) => z(m, {
293
- ...ce
294
- }, R)), m;
288
+ var v = et();
289
+ return v.$$click = () => be(m), L((W) => D(v, {
290
+ ...de
291
+ }, W)), v;
295
292
  }
296
293
  }), null), o;
297
294
  })();
298
295
  }
299
296
  })), n;
300
297
  }
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;
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;
306
303
  }, {
307
304
  e: void 0,
308
305
  t: void 0,
@@ -313,399 +310,440 @@ function ct(e) {
313
310
  }
314
311
  });
315
312
  }
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(() => {
320
- if (!e.isOpen) return;
321
- const t = (a) => {
322
- a.key === "Escape" && e.onCancel();
313
+ 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();
323
320
  };
324
- document.addEventListener("keydown", t), Z(() => document.removeEventListener("keydown", t));
325
- }), g(k, {
321
+ document.addEventListener("keydown", e), te(() => document.removeEventListener("keydown", e));
322
+ }), y(S, {
326
323
  get when() {
327
- return e.isOpen;
324
+ return t.isOpen;
328
325
  },
329
326
  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 = {
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 = {
335
332
  ...Ce
336
333
  };
337
- return x.e = z(t, U, x.e), x.t = z(a, T, x.t), x;
334
+ return x.e = D(e, O, x.e), x.t = D(l, z, x.t), x;
338
335
  }, {
339
336
  e: void 0,
340
337
  t: void 0
341
- }), t;
338
+ }), e;
342
339
  }
343
340
  });
344
341
  }
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(() => {
351
- if (!e.isOpen) return;
352
- a(""), requestAnimationFrame(() => y?.focus());
353
- const f = (C) => {
354
- C.key === "Escape" && e.onCancel();
342
+ 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();
355
352
  };
356
- document.addEventListener("keydown", f), Z(() => document.removeEventListener("keydown", f));
353
+ document.addEventListener("keydown", u), te(() => document.removeEventListener("keydown", u));
357
354
  });
358
- function b() {
359
- const f = t().trim();
360
- e.onConfirm(f || e.defaultTitle);
355
+ function h() {
356
+ const u = e().trim();
357
+ t.onConfirm(u || t.defaultTitle);
361
358
  }
362
- return g(k, {
359
+ return y(S, {
363
360
  get when() {
364
- return e.isOpen;
361
+ return t.isOpen;
365
362
  },
366
363
  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();
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();
370
367
  }, 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((_) => {
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((_) => {
375
372
  var Y = ke, N = {
376
373
  ...Ce
377
- }, V = e.defaultTitle;
378
- return _.e = z(f, Y, _.e), _.t = z(C, N, _.t), V !== _.a && je(x, "placeholder", _.a = V), _;
374
+ }, q = t.defaultTitle;
375
+ return _.e = D(u, Y, _.e), _.t = D($, N, _.t), q !== _.a && He(x, "placeholder", _.a = q), _;
379
376
  }, {
380
377
  e: void 0,
381
378
  t: void 0,
382
379
  a: void 0
383
- }), I(() => x.value = t()), f;
380
+ }), L(() => x.value = e()), u;
384
381
  }
385
382
  });
386
383
  }
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) {
384
+ 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) {
395
391
  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));
398
- 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));
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();
396
+ if (b) {
397
+ const v = e.getTitle(b);
398
+ u(v), k(Te(e.id, M(), r.url, v));
403
399
  }
404
400
  };
405
- r.on("change", c), n = () => r.off("change", c);
401
+ r.on("change", a), n = () => r.off("change", a);
406
402
  }
407
- async function E(r) {
408
- const o = T();
403
+ async function U(r) {
404
+ const o = z();
409
405
  if (!o) return !0;
410
406
  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);
413
- } catch (h) {
414
- return console.error(`[${t.name}] Access check error for ${r}:`, h), !0;
407
+ 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;
415
414
  }
416
415
  }
417
- async function S(r) {
418
- const o = ++u;
419
- n && (n(), n = null), y(null), j(!1), J(null), H(!0), f("Loading...");
416
+ async function A(r) {
417
+ const o = ++m;
418
+ n && (n(), n = null), f(null), j(!1), J(null), P(!0), u("Loading...");
420
419
  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);
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);
424
423
  return;
425
424
  }
426
- if (o !== u) return;
427
- const h = (p) => {
428
- const m = p.doc();
429
- return m ? t.isDocReady ? t.isDocReady(m) : !!m : !1;
425
+ if (o !== m) return;
426
+ const p = (b) => {
427
+ const v = b.doc();
428
+ return v ? e.isDocReady ? e.isDocReady(v) : !!v : !1;
430
429
  };
431
- let c = await M.find(r);
432
- if (await c.whenReady(), o !== u) return;
433
- if (!h(c)) {
434
- console.log(`[${t.name}] Doc incomplete, forcing re-sync for: ${r.slice(0, 30)}...`);
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)}...`);
435
434
  try {
436
- M.delete(r);
435
+ R.delete(r);
437
436
  } catch {
438
437
  }
439
- if (await new Promise((p) => setTimeout(p, 100)), o !== u || (c = await M.find(r), await c.whenReady(), o !== u)) return;
438
+ if (await new Promise((b) => setTimeout(b, 100)), o !== m || (a = R.find(r), await a.whenReady(), o !== m)) return;
440
439
  }
441
- if (!h(c) && (le(r), await new Promise((p) => {
442
- const m = () => {
443
- if (o !== u) {
444
- c.off("change", m), p();
440
+ if (!p(a) && (ce(r), await new Promise((b) => {
441
+ const v = () => {
442
+ if (o !== m) {
443
+ a.off("change", v), b();
445
444
  return;
446
445
  }
447
- h(c) && (c.off("change", m), p());
446
+ p(a) && (a.off("change", v), b());
448
447
  };
449
- c.on("change", m), setTimeout(() => {
450
- c.off("change", m), p();
448
+ a.on("change", v), setTimeout(() => {
449
+ a.off("change", v), b();
451
450
  }, 3e4);
452
- }), o !== u))
451
+ }), o !== m))
453
452
  return;
454
- H(!1), le(r), localStorage.setItem(me(t.id, O()), r), P(c), y(c);
455
- } 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);
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);
458
457
  }
459
458
  }
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"] = {
465
- type: t.id
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
466
463
  };
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);
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);
469
467
  }
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);
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);
472
470
  }
473
471
  function pe() {
474
- const r = a();
472
+ const r = l();
475
473
  if (!r) return;
476
474
  const o = r.url;
477
- G(), M.delete(o), A(qe(t.id, O(), o));
475
+ Q(), R.delete(o), k(Ke(e.id, M(), o));
478
476
  }
479
- async function ye() {
480
- const r = T();
477
+ async function we() {
478
+ const r = z();
481
479
  if (r)
482
480
  try {
483
481
  const o = r.active.contactCard.toJson();
484
- await navigator.clipboard.writeText(o), fe(!0), setTimeout(() => fe(!1), 1500);
482
+ await navigator.clipboard.writeText(o), he(!0), setTimeout(() => he(!1), 1500);
485
483
  } catch (o) {
486
- console.error(`[${t.name}] Failed to copy contact card:`, o);
484
+ console.error(`[${e.name}] Failed to copy contact card:`, o);
487
485
  }
488
486
  }
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;
487
+ 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) {
493
+ 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);
511
495
  }
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);
496
+ _(a), k(ve(e.id, a)), T(!0), console.log(`[${e.name}] Legacy mode initialized, identity: 0x${a.slice(0, 12)}...`);
497
+ } else {
498
+ const [{
499
+ Repo: p
500
+ }, {
501
+ IndexedDBStorageAdapter: a
502
+ }, {
503
+ 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,
510
+ automaticArchiveIngestion: !0,
511
+ onlyShareWithHardcodedServerPeerId: !0,
512
+ cacheHashes: !0
513
+ });
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
521
+ });
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));
528
+ return;
529
+ }
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)));
532
+ });
533
+ }
534
+ const r = Le();
535
+ if (r) {
536
+ console.log(`[${e.name}] Loading doc from hash: ${r}`), await A(r);
518
537
  return;
519
538
  }
520
- const K = localStorage.getItem(me(t.id, m));
521
- if (K) {
522
- console.log(`[${t.name}] Found existing doc: ${K}`), await S(K);
539
+ const o = localStorage.getItem(me(e.id, M()));
540
+ if (o) {
541
+ console.log(`[${e.name}] Found existing doc: ${o}`), await A(o);
523
542
  return;
524
543
  }
525
- console.log(`[${t.name}] No doc found, starting blank`);
526
- }), be(() => {
544
+ console.log(`[${e.name}] No doc found, starting blank`);
545
+ }), $e(() => {
527
546
  const r = async () => {
528
- const o = Te();
529
- o && (console.log(`[${t.name}] Hash changed, loading: ${o}`), await S(o));
547
+ const o = Le();
548
+ o && (console.log(`[${e.name}] Hash changed, loading: ${o}`), await A(o));
530
549
  };
531
- window.addEventListener("hashchange", r), Z(() => window.removeEventListener("hashchange", r));
532
- }), be(() => {
550
+ window.addEventListener("hashchange", r), te(() => window.removeEventListener("hashchange", r));
551
+ }), $e(() => {
533
552
  const r = (o) => {
534
- o.target.closest("[data-doc-switcher]") || U(!1);
553
+ o.target.closest("[data-doc-switcher]") || O(!1);
535
554
  };
536
- document.addEventListener("mousedown", r), Z(() => document.removeEventListener("mousedown", r));
555
+ document.addEventListener("mousedown", r), te(() => document.removeEventListener("mousedown", r));
537
556
  }), (() => {
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 = "";
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 = "";
547
566
  }
548
567
  }
549
- }, m.$$click = () => U(!x()), s(R, b), s(p, g(k, {
568
+ }, v.$$click = () => O(!x()), d(W, h), d(b, y(S, {
550
569
  get when() {
551
570
  return x();
552
571
  },
553
572
  get children() {
554
- var l = gt();
555
- return s(l, g(Re, {
573
+ var c = dt();
574
+ return d(c, y(Re, {
556
575
  get each() {
557
- return C();
576
+ return $();
558
577
  },
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;
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";
584
+ }), 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;
570
589
  }, {
571
590
  e: void 0,
572
591
  t: void 0
573
- }), D;
592
+ }), I;
574
593
  })()
575
- }), null), s(l, g(k, {
594
+ }), null), d(c, y(S, {
576
595
  get when() {
577
- return C().length === 0;
596
+ return $().length === 0;
578
597
  },
579
598
  get children() {
580
- return pt();
599
+ return st();
581
600
  }
582
- }), null), l;
601
+ }), null), c;
583
602
  }
584
- }), null), s(K, g(k, {
603
+ }), null), d(H, y(S, {
585
604
  get when() {
586
- return te(() => !!a())() && T();
605
+ return ee(() => !!l())() && z();
587
606
  },
588
607
  get children() {
589
- var l = mt();
590
- return l.$$click = () => N(!0), l;
608
+ var c = ut();
609
+ return c.$$click = () => N(!0), c;
591
610
  }
592
- }), null), s(K, g(k, {
611
+ }), null), d(H, y(S, {
593
612
  get when() {
594
- return a();
613
+ return l();
595
614
  },
596
615
  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;
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;
602
621
  }
603
- }), null), s(K, g(k, {
622
+ }), null), d(H, y(S, {
604
623
  get when() {
605
- return T();
624
+ return z();
606
625
  },
607
626
  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;
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;
610
629
  }
611
- }), null), s(K, g(k, {
630
+ }), null), d(H, y(S, {
612
631
  get when() {
613
- return a();
632
+ return l();
614
633
  },
615
634
  get children() {
616
- var l = yt();
617
- return l.$$click = () => re(!0), l;
635
+ var c = gt();
636
+ return c.$$click = () => oe(!0), c;
618
637
  }
619
- }), null), s(B, g(k, {
638
+ }), null), d(re, y(S, {
620
639
  get when() {
621
- return a();
640
+ return l();
622
641
  },
623
642
  keyed: !0,
624
643
  get fallback() {
625
644
  return (() => {
626
- var l = kt();
627
- return s(l, g(k, {
645
+ var c = vt();
646
+ return d(c, y(S, {
628
647
  get when() {
629
- return oe() || !d();
648
+ return le() || !g();
630
649
  },
631
650
  get children() {
632
- return wt();
651
+ return yt();
633
652
  }
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;
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;
638
657
  })();
639
658
  },
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;
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);
665
+ }, I), I;
647
666
  })();
648
667
  }
649
- })), s(r, g(k, {
668
+ })), d(r, y(S, {
650
669
  get when() {
651
- return te(() => !!T())() && a();
670
+ return ee(() => !!z())() && l();
652
671
  },
653
672
  get children() {
654
- return g(ct, {
673
+ return y(rt, {
655
674
  get isOpen() {
656
675
  return Y();
657
676
  },
658
677
  get docUrl() {
659
- return a().url;
678
+ return l().url;
660
679
  },
661
680
  get hive() {
662
- return T();
681
+ return z();
663
682
  },
664
683
  onClose: () => N(!1)
665
684
  });
666
685
  }
667
- }), null), s(r, g(ft, {
686
+ }), null), d(r, y(lt, {
668
687
  get isOpen() {
669
- return xe();
688
+ return be();
670
689
  },
671
690
  get defaultTitle() {
672
- return t.defaultTitle;
691
+ return e.defaultTitle;
673
692
  },
674
- onConfirm: (l) => {
675
- ie(!1), W(l);
693
+ onConfirm: (c) => {
694
+ ae(!1), K(c);
676
695
  },
677
- onCancel: () => ie(!1)
678
- }), null), s(r, g(dt, {
696
+ onCancel: () => ae(!1)
697
+ }), null), d(r, y(ot, {
679
698
  get isOpen() {
680
- return V();
699
+ return q();
681
700
  },
682
701
  title: "Remove Document",
683
702
  message: "Remove this document from your history? The document data will be deleted locally.",
684
703
  confirmLabel: "Remove",
685
704
  onConfirm: () => {
686
- re(!1), pe();
705
+ oe(!1), pe();
687
706
  },
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;
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;
692
711
  }, {
693
712
  e: void 0,
694
713
  t: void 0
695
714
  }), r;
696
715
  })();
697
716
  }
698
- ve(["click", "keydown"]);
699
- function zt(e, t) {
700
- Je(() => g(St, {
701
- tool: t
702
- }), e);
717
+ 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");
721
+ 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);
725
+ 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
733
+ };
734
+ }
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,
739
+ config: l
740
+ }), t);
703
741
  }
704
742
  export {
705
- dt as ConfirmModal,
706
- ft as NewDocModal,
707
- ct as ShareModal,
743
+ ot as ConfirmModal,
744
+ lt as NewDocModal,
745
+ rt as ShareModal,
708
746
  Ce as cardStyle,
709
- zt as mountStandaloneApp,
747
+ St as mountStandaloneApp,
710
748
  ke as overlayStyle
711
749
  };