@fileverse-dev/ddoc 6.0.0-drop-in.3 → 6.0.1-dist-slim.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.
Files changed (51) hide show
  1. package/README.md +18 -89
  2. package/dist/data-BCRDUrcS.mjs +59842 -0
  3. package/dist/ddoc-persistence-DLdSviUr.mjs +371 -0
  4. package/dist/headless-editor-utils.es.js +1 -1
  5. package/dist/index--ObnXdbg.mjs +14053 -0
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.es.js +10734 -21551
  8. package/dist/markdown-source-pane-BJbpMXo2.mjs +143 -0
  9. package/dist/package/components/editor-toolbar.d.ts +1 -2
  10. package/dist/package/components/fullscreen-toolbar.d.ts +2 -2
  11. package/dist/package/components/mobile-toolbar.d.ts +1 -2
  12. package/dist/package/components/tabs/document-mobile-tab-panel.d.ts +1 -3
  13. package/dist/package/components/tabs/document-tabs-sidebar.d.ts +1 -2
  14. package/dist/package/components/toc/document-outline.d.ts +1 -1
  15. package/dist/package/components/toc/toc.d.ts +1 -1
  16. package/dist/package/components/toc/types.d.ts +0 -7
  17. package/dist/package/extensions/emoji/components/emoji-utils.d.ts +2 -2
  18. package/dist/package/hooks/use-export-headless-editor-content.d.ts +6 -2
  19. package/dist/package/hooks/use-focus-mode.d.ts +3 -1
  20. package/dist/package/hooks/use-headless-editor.d.ts +12 -4
  21. package/dist/package/hooks/use-tab-editor.d.ts +1 -4
  22. package/dist/package/hooks/use-tab-manager.d.ts +3 -1
  23. package/dist/package/hooks/use-yjs-setup.d.ts +7 -1
  24. package/dist/package/persistence/compaction.d.ts +27 -0
  25. package/dist/package/persistence/content-fingerprint.d.ts +27 -0
  26. package/dist/package/persistence/ddoc-persistence.d.ts +96 -0
  27. package/dist/package/persistence/index.d.ts +2 -0
  28. package/dist/package/persistence/provider-lifecycle.d.ts +37 -0
  29. package/dist/package/sync-local/SyncManager.d.ts +8 -1
  30. package/dist/package/sync-local/types/index.d.ts +2 -0
  31. package/dist/package/types.d.ts +25 -43
  32. package/dist/package/use-ddoc-editor.d.ts +1 -3
  33. package/dist/package/utils/responsive.d.ts +1 -3
  34. package/dist/persistence.d.ts +1 -0
  35. package/dist/persistence.es.js +10 -0
  36. package/dist/{split-view-toolbar-NTimkQK1.mjs → split-view-toolbar-6aBSjsO2.mjs} +47 -46
  37. package/dist/style.css +1 -1
  38. package/dist/tab-utils-BNFvrUAj.mjs +284 -0
  39. package/dist/use-headless-editor-fZCM6BjV.mjs +43828 -0
  40. package/package.json +11 -4
  41. package/tailwind.preset.cjs +0 -42
  42. package/dist/index-eP_xxZsk.mjs +0 -13126
  43. package/dist/markdown-source-pane-D-8OmL1r.mjs +0 -6069
  44. package/dist/package/components/editor-navbar.d.ts +0 -12
  45. package/dist/package/hooks/use-canvas-metrics.d.ts +0 -16
  46. package/dist/package/hooks/use-controllable-state.d.ts +0 -3
  47. package/dist/package/hooks/use-editor-media-query.d.ts +0 -4
  48. package/dist/package/utils/container-query-support.d.ts +0 -1
  49. package/dist/package/utils/editor-width-store.d.ts +0 -6
  50. package/dist/package/utils/stats-publisher.d.ts +0 -8
  51. package/dist/use-headless-editor-KdKS6vWp.mjs +0 -162186
@@ -0,0 +1,371 @@
1
+ import { fromUint8Array as _, toUint8Array as C } from "js-base64";
2
+ import * as m from "yjs";
3
+ import { S as I, A as $ } from "./tab-utils-BNFvrUAj.mjs";
4
+ const U = (e) => {
5
+ const r = [];
6
+ for (const [n, f] of e) {
7
+ const o = r[r.length - 1];
8
+ o && o[1] === n ? o[1] = f : r.push([n, f]);
9
+ }
10
+ return r;
11
+ }, j = (e) => e.map(([r, n]) => `${r}-${n}`).join(","), N = (e) => {
12
+ const r = e.share.get(I), n = (t) => r !== void 0 && t instanceof m.Item && t.parent === r && t.parentSub === $, f = Array.from(e.store.clients.keys()).sort((t, s) => t - s), o = [];
13
+ for (const t of f) {
14
+ const s = [], u = [];
15
+ for (const a of e.store.clients.get(t) ?? []) {
16
+ if (n(a)) continue;
17
+ const i = [
18
+ a.id.clock,
19
+ a.id.clock + a.length
20
+ ];
21
+ s.push(i), a.deleted && u.push([...i]);
22
+ }
23
+ s.length !== 0 && o.push(
24
+ `${t}:${j(U(s))}|${j(
25
+ U(u)
26
+ )}`
27
+ );
28
+ }
29
+ return o.join(";");
30
+ }, Y = async (e) => {
31
+ const r = await crypto.subtle.digest(
32
+ "SHA-256",
33
+ new TextEncoder().encode(N(e))
34
+ );
35
+ return _(new Uint8Array(r));
36
+ }, T = 8e3, W = "DdocStoreRepaired", h = "updates", P = "custom", B = (e) => e instanceof Error ? e : new Error(String(e)), E = (e, r, n) => ({
37
+ ddocId: e,
38
+ status: r,
39
+ encodedState: null,
40
+ ...n ? { error: B(n) } : {}
41
+ }), O = (e, r) => {
42
+ const n = m.encodeStateAsUpdate(r);
43
+ return {
44
+ ddocId: e,
45
+ status: n.length <= 2 ? "empty" : "available",
46
+ encodedState: _(n)
47
+ };
48
+ }, R = (e) => e.objectStoreNames.contains(h), M = (e) => Object.prototype.toString.call(e) === "[object Uint8Array]", k = (e, r) => {
49
+ for (const n of r ?? []) {
50
+ if (!M(n))
51
+ throw new Error("dDoc IndexedDB contains a non-Yjs update");
52
+ m.applyUpdate(e, n);
53
+ }
54
+ }, F = (e, r) => new Promise((n) => {
55
+ const f = new m.Doc();
56
+ let o = null, t = null, s = !1, u = !1;
57
+ const a = (c) => {
58
+ s || (s = !0, clearTimeout(p), o == null || o.close(), f.destroy(), n(c));
59
+ }, i = (c, l) => a(E(e, c, l)), p = setTimeout(() => {
60
+ try {
61
+ t == null || t.abort();
62
+ } catch {
63
+ }
64
+ i("timed-out", new Error("dDoc IndexedDB read timed out"));
65
+ }, r);
66
+ let b;
67
+ try {
68
+ b = indexedDB.open(e);
69
+ } catch (c) {
70
+ i("unavailable", c);
71
+ return;
72
+ }
73
+ b.onupgradeneeded = () => {
74
+ var c;
75
+ u = !0, (c = b.transaction) == null || c.abort();
76
+ }, b.onerror = () => {
77
+ u ? a(E(e, "missing")) : i("unavailable", b.error);
78
+ }, b.onsuccess = () => {
79
+ if (o = b.result, s) {
80
+ o.close();
81
+ return;
82
+ }
83
+ if (!R(o)) {
84
+ i("corrupt", new Error("dDoc IndexedDB has no updates store"));
85
+ return;
86
+ }
87
+ try {
88
+ t = o.transaction(h, "readonly");
89
+ const c = t.objectStore(h).getAll();
90
+ c.onerror = () => i("unavailable", c.error), c.onsuccess = () => {
91
+ try {
92
+ k(f, c.result);
93
+ } catch (l) {
94
+ i("corrupt", l);
95
+ }
96
+ }, t.oncomplete = () => a(O(e, f)), t.onabort = () => {
97
+ s || i("unavailable", t == null ? void 0 : t.error);
98
+ }, t.onerror = () => {
99
+ s || i("unavailable", t == null ? void 0 : t.error);
100
+ };
101
+ } catch (c) {
102
+ i("unavailable", c);
103
+ }
104
+ };
105
+ }), q = async (e, r) => {
106
+ const n = indexedDB;
107
+ if (!n.databases) return null;
108
+ let f;
109
+ try {
110
+ const o = await Promise.race([
111
+ n.databases(),
112
+ new Promise((t) => {
113
+ f = setTimeout(() => t(null), r);
114
+ })
115
+ ]);
116
+ return o ? o.some((t) => t.name === e) : null;
117
+ } catch {
118
+ return null;
119
+ } finally {
120
+ clearTimeout(f);
121
+ }
122
+ }, K = async (e, r) => typeof indexedDB > "u" ? E(
123
+ e,
124
+ "unavailable",
125
+ new Error("IndexedDB is unavailable")
126
+ ) : await q(e, r) === !1 ? E(e, "missing") : F(e, r), z = (e, r = {}) => K(
127
+ e,
128
+ r.timeoutMs ?? T
129
+ ), G = (e, r, n = {}) => {
130
+ const f = n.timeoutMs ?? T, o = (s, u) => ({
131
+ ...E(e, s, u),
132
+ changed: !1,
133
+ created: !1
134
+ }), t = new m.Doc();
135
+ try {
136
+ m.applyUpdate(t, C(r));
137
+ } catch (s) {
138
+ return t.destroy(), Promise.resolve(o("corrupt", s));
139
+ }
140
+ return typeof indexedDB > "u" ? (t.destroy(), Promise.resolve(
141
+ o("unavailable", new Error("IndexedDB is unavailable"))
142
+ )) : new Promise((s) => {
143
+ const u = new m.Doc();
144
+ let a = null, i = null, p = !1, b = !1, c = !1, l = null;
145
+ const y = (d) => {
146
+ p || (p = !0, clearTimeout(A), a == null || a.close(), u.destroy(), t.destroy(), s(d));
147
+ }, A = setTimeout(() => {
148
+ try {
149
+ i == null || i.abort();
150
+ } catch {
151
+ }
152
+ y(
153
+ o("timed-out", new Error("dDoc IndexedDB merge timed out"))
154
+ );
155
+ }, f);
156
+ let D;
157
+ try {
158
+ D = indexedDB.open(e);
159
+ } catch (d) {
160
+ y(o("unavailable", d));
161
+ return;
162
+ }
163
+ D.onupgradeneeded = () => {
164
+ var g;
165
+ if (p) {
166
+ (g = D.transaction) == null || g.abort();
167
+ return;
168
+ }
169
+ c = !0;
170
+ const d = D.result;
171
+ d.objectStoreNames.contains(h) || d.createObjectStore(h, { autoIncrement: !0 }), d.objectStoreNames.contains(P) || d.createObjectStore(P);
172
+ }, D.onerror = () => y(o("unavailable", D.error)), D.onsuccess = () => {
173
+ if (a = D.result, p) {
174
+ a.close();
175
+ return;
176
+ }
177
+ if (!R(a)) {
178
+ y(
179
+ o(
180
+ "corrupt",
181
+ new Error("dDoc IndexedDB has no updates store")
182
+ )
183
+ );
184
+ return;
185
+ }
186
+ try {
187
+ const d = a.transaction(h, "readwrite");
188
+ i = d;
189
+ const g = d.objectStore(h), v = (w, x) => {
190
+ l ?? (l = { status: w, error: x });
191
+ try {
192
+ d.abort();
193
+ } catch {
194
+ }
195
+ }, S = g.getAll();
196
+ S.onsuccess = () => {
197
+ try {
198
+ k(u, S.result);
199
+ } catch (w) {
200
+ v("corrupt", w);
201
+ return;
202
+ }
203
+ try {
204
+ const w = m.encodeStateAsUpdate(
205
+ t,
206
+ m.encodeStateVector(u)
207
+ ), x = () => {
208
+ b = !0;
209
+ };
210
+ u.on("update", x);
211
+ try {
212
+ m.applyUpdate(u, w);
213
+ } finally {
214
+ u.off("update", x);
215
+ }
216
+ b && g.add(w);
217
+ } catch (w) {
218
+ v("unavailable", w);
219
+ }
220
+ }, d.oncomplete = () => y({ ...O(e, u), changed: b, created: c }), d.onabort = () => y(
221
+ o(
222
+ (l == null ? void 0 : l.status) ?? "unavailable",
223
+ (l == null ? void 0 : l.error) ?? d.error ?? new Error("dDoc IndexedDB merge aborted")
224
+ )
225
+ );
226
+ } catch (d) {
227
+ y(o("unavailable", d));
228
+ }
229
+ };
230
+ });
231
+ }, V = (e) => {
232
+ if (!M(e)) return !1;
233
+ const r = new m.Doc();
234
+ try {
235
+ return m.applyUpdate(r, e), !0;
236
+ } catch {
237
+ return !1;
238
+ } finally {
239
+ r.destroy();
240
+ }
241
+ }, J = async (e, r = {}) => {
242
+ const n = (o, t = 0, s) => ({
243
+ ddocId: e,
244
+ status: o,
245
+ droppedRows: t,
246
+ ...s ? { error: B(s) } : {}
247
+ });
248
+ if (typeof indexedDB > "u")
249
+ return n("unavailable", 0, new Error("IndexedDB is unavailable"));
250
+ const f = r.timeoutMs ?? T;
251
+ return await q(e, f) === !1 ? n("missing") : new Promise((o) => {
252
+ let t = null, s = null, u = !1, a = !1, i = 0;
253
+ const p = (l) => {
254
+ u || (u = !0, clearTimeout(b), t == null || t.close(), o(l));
255
+ }, b = setTimeout(() => {
256
+ try {
257
+ s == null || s.abort();
258
+ } catch {
259
+ }
260
+ p(
261
+ n("timed-out", 0, new Error("dDoc IndexedDB repair timed out"))
262
+ );
263
+ }, f);
264
+ let c;
265
+ try {
266
+ c = indexedDB.open(e);
267
+ } catch (l) {
268
+ p(n("unavailable", 0, l));
269
+ return;
270
+ }
271
+ c.onupgradeneeded = () => {
272
+ var l;
273
+ a = !0, (l = c.transaction) == null || l.abort();
274
+ }, c.onerror = () => p(
275
+ a ? n("missing") : n("unavailable", 0, c.error)
276
+ ), c.onsuccess = () => {
277
+ if (t = c.result, u) {
278
+ t.close();
279
+ return;
280
+ }
281
+ if (!R(t)) {
282
+ p(
283
+ n(
284
+ "corrupt",
285
+ 0,
286
+ new Error("dDoc IndexedDB has no updates store")
287
+ )
288
+ );
289
+ return;
290
+ }
291
+ try {
292
+ const l = t.transaction(h, "readwrite");
293
+ s = l;
294
+ const y = l.objectStore(h), A = y.getAllKeys(), D = y.getAll();
295
+ D.onsuccess = () => {
296
+ const d = A.result ?? [];
297
+ (D.result ?? []).forEach((v, S) => {
298
+ V(v) || (y.delete(d[S]), i += 1);
299
+ });
300
+ }, l.oncomplete = () => p(i > 0 ? n("repaired", i) : n("healthy")), l.onabort = () => p(
301
+ n(
302
+ "unavailable",
303
+ 0,
304
+ l.error ?? new Error("dDoc IndexedDB repair aborted")
305
+ )
306
+ );
307
+ } catch (l) {
308
+ p(n("unavailable", 0, l));
309
+ }
310
+ };
311
+ });
312
+ }, Q = (e, r = {}) => {
313
+ if (typeof indexedDB > "u")
314
+ return Promise.resolve({
315
+ ddocId: e,
316
+ status: "unavailable",
317
+ error: new Error("IndexedDB is unavailable")
318
+ });
319
+ const n = r.timeoutMs ?? T;
320
+ return new Promise((f) => {
321
+ let o = !1, t = !1;
322
+ const s = (i) => {
323
+ o || (o = !0, clearTimeout(u), f(i));
324
+ }, u = setTimeout(
325
+ () => s(
326
+ t ? {
327
+ ddocId: e,
328
+ status: "blocked",
329
+ error: new Error(
330
+ "dDoc IndexedDB delete is blocked by an open connection"
331
+ )
332
+ } : {
333
+ ddocId: e,
334
+ status: "unavailable",
335
+ error: new Error("dDoc IndexedDB delete timed out")
336
+ }
337
+ ),
338
+ n
339
+ );
340
+ let a;
341
+ try {
342
+ a = indexedDB.deleteDatabase(e);
343
+ } catch (i) {
344
+ s({ ddocId: e, status: "unavailable", error: B(i) });
345
+ return;
346
+ }
347
+ a.onblocked = () => {
348
+ t = !0;
349
+ }, a.onsuccess = () => s({ ddocId: e, status: "deleted" }), a.onerror = () => s({
350
+ ddocId: e,
351
+ status: "unavailable",
352
+ error: B(a.error ?? "dDoc IndexedDB delete failed")
353
+ });
354
+ });
355
+ }, X = async (e) => {
356
+ const r = new m.Doc();
357
+ try {
358
+ return m.applyUpdate(r, C(e)), await Y(r);
359
+ } finally {
360
+ r.destroy();
361
+ }
362
+ };
363
+ export {
364
+ W as D,
365
+ T as a,
366
+ J as b,
367
+ Q as d,
368
+ X as g,
369
+ G as m,
370
+ z as r
371
+ };
@@ -1,4 +1,4 @@
1
- import { ch as s } from "./use-headless-editor-KdKS6vWp.mjs";
1
+ import { c as s } from "./use-headless-editor-fZCM6BjV.mjs";
2
2
  const n = (e) => {
3
3
  const { getYjsConvertor: t, mergeYjsUpdates: r } = s(e);
4
4
  return { getYjsConvertor: t, mergeYjsUpdates: r };