noteloom 0.5.0 → 0.7.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/README.md +1 -1
- package/dist/canvas.cjs +1 -1
- package/dist/canvas.js +1 -1
- package/dist/collab.cjs +1 -1
- package/dist/collab.cjs.map +1 -1
- package/dist/collab.js +157 -102
- package/dist/collab.js.map +1 -1
- package/dist/comments.cjs +1 -1
- package/dist/comments.js +3 -3
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +33 -0
- package/dist/index.js +1691 -1592
- package/dist/index.js.map +1 -1
- package/dist/shared/{CommentThreadCard-YziIa8My.cjs → CommentThreadCard-CIB6nZEA.cjs} +2 -2
- package/dist/shared/{CommentThreadCard-YziIa8My.cjs.map → CommentThreadCard-CIB6nZEA.cjs.map} +1 -1
- package/dist/shared/{CommentThreadCard-CwKd6fp3.js → CommentThreadCard-lW_lbI74.js} +2 -2
- package/dist/shared/{CommentThreadCard-CwKd6fp3.js.map → CommentThreadCard-lW_lbI74.js.map} +1 -1
- package/dist/shared/{CommentsPanel-DezejDdE.cjs → CommentsPanel-CRxb3RWi.cjs} +2 -2
- package/dist/shared/{CommentsPanel-DezejDdE.cjs.map → CommentsPanel-CRxb3RWi.cjs.map} +1 -1
- package/dist/shared/{CommentsPanel-dx7IaoqS.js → CommentsPanel-Dg0k_XNU.js} +3 -3
- package/dist/shared/{CommentsPanel-dx7IaoqS.js.map → CommentsPanel-Dg0k_XNU.js.map} +1 -1
- package/dist/shared/VersionHistory-BsSwOq_k.cjs +12 -0
- package/dist/shared/VersionHistory-BsSwOq_k.cjs.map +1 -0
- package/dist/shared/{VersionHistory-DhYb8C2e.js → VersionHistory-BzMnJpbc.js} +221 -206
- package/dist/shared/VersionHistory-BzMnJpbc.js.map +1 -0
- package/dist/shared/VoiceListeningIndicator-B_7-6Mq4.cjs +2 -0
- package/dist/shared/VoiceListeningIndicator-B_7-6Mq4.cjs.map +1 -0
- package/dist/shared/VoiceListeningIndicator-DeA3hb33.js +342 -0
- package/dist/shared/VoiceListeningIndicator-DeA3hb33.js.map +1 -0
- package/dist/shared/{icons-D5Ctow8R.js → icons-CmfXmn13.js} +350 -282
- package/dist/shared/icons-CmfXmn13.js.map +1 -0
- package/dist/shared/{icons-BCseh2pt.cjs → icons-DQ7j_-ZK.cjs} +44 -3
- package/dist/shared/icons-DQ7j_-ZK.cjs.map +1 -0
- package/dist/shared/{index-D_8hJpI7.js → index-DUigqWQn.js} +52 -52
- package/dist/shared/{index-D_8hJpI7.js.map → index-DUigqWQn.js.map} +1 -1
- package/dist/shared/{index-CbIBsFmI.cjs → index-vWtS1iyt.cjs} +2 -2
- package/dist/shared/{index-CbIBsFmI.cjs.map → index-vWtS1iyt.cjs.map} +1 -1
- package/dist/shared/{leafBlockFactory-CaLWUcfa.cjs → leafBlockFactory-6GFBveaC.cjs} +2 -2
- package/dist/shared/{leafBlockFactory-CaLWUcfa.cjs.map → leafBlockFactory-6GFBveaC.cjs.map} +1 -1
- package/dist/shared/{leafBlockFactory-DSa1XCox.js → leafBlockFactory-Dm6cd2NY.js} +5 -5
- package/dist/shared/{leafBlockFactory-DSa1XCox.js.map → leafBlockFactory-Dm6cd2NY.js.map} +1 -1
- package/dist/shared/{serialize-BqKU9EZy.js → serialize-R4V4gmHs.js} +2 -2
- package/dist/shared/{serialize-BqKU9EZy.js.map → serialize-R4V4gmHs.js.map} +1 -1
- package/dist/shared/{serialize-CqwX55uK.cjs → serialize-vLXz0cze.cjs} +2 -2
- package/dist/shared/{serialize-CqwX55uK.cjs.map → serialize-vLXz0cze.cjs.map} +1 -1
- package/dist/shared/starter-kit-BQUaaql0.cjs +29 -0
- package/dist/shared/starter-kit-BQUaaql0.cjs.map +1 -0
- package/dist/shared/{starter-kit-mfeNxqFn.js → starter-kit-Bp30PiE4.js} +1545 -1477
- package/dist/shared/starter-kit-Bp30PiE4.js.map +1 -0
- package/dist/shared/{usePopoverEdgeClamp-CPRWQtZV.cjs → usePopoverEdgeClamp-BJLbbANB.cjs} +2 -2
- package/dist/shared/{usePopoverEdgeClamp-CPRWQtZV.cjs.map → usePopoverEdgeClamp-BJLbbANB.cjs.map} +1 -1
- package/dist/shared/{usePopoverEdgeClamp-D_hB5t60.js → usePopoverEdgeClamp-DSpz-6xR.js} +2 -2
- package/dist/shared/{usePopoverEdgeClamp-D_hB5t60.js.map → usePopoverEdgeClamp-DSpz-6xR.js.map} +1 -1
- package/dist/starter-kit.cjs +1 -1
- package/dist/starter-kit.js +2 -2
- package/dist/style.css +41 -0
- package/dist/versions.cjs +1 -1
- package/dist/versions.js +1 -1
- package/dist/voice.cjs +1 -1
- package/dist/voice.js +1 -1
- package/package.json +2 -2
- package/dist/shared/VersionHistory-DhYb8C2e.js.map +0 -1
- package/dist/shared/VersionHistory-DuSxis_7.cjs +0 -12
- package/dist/shared/VersionHistory-DuSxis_7.cjs.map +0 -1
- package/dist/shared/VoiceListeningIndicator-BXByLZwO.cjs +0 -2
- package/dist/shared/VoiceListeningIndicator-BXByLZwO.cjs.map +0 -1
- package/dist/shared/VoiceListeningIndicator-bv285FSY.js +0 -338
- package/dist/shared/VoiceListeningIndicator-bv285FSY.js.map +0 -1
- package/dist/shared/icons-BCseh2pt.cjs.map +0 -1
- package/dist/shared/icons-D5Ctow8R.js.map +0 -1
- package/dist/shared/starter-kit-DyX1U84W.cjs +0 -27
- package/dist/shared/starter-kit-DyX1U84W.cjs.map +0 -1
- package/dist/shared/starter-kit-mfeNxqFn.js.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { jsxs as b, Fragment as
|
|
2
|
-
import { useState as v, useCallback as
|
|
3
|
-
import { createPortal as
|
|
4
|
-
import { g as
|
|
5
|
-
import { f as
|
|
6
|
-
import { c as
|
|
7
|
-
import { g as
|
|
8
|
-
import { C as
|
|
9
|
-
function
|
|
10
|
-
const i = Array.from(
|
|
1
|
+
import { jsxs as b, Fragment as L, jsx as k } from "react/jsx-runtime";
|
|
2
|
+
import { useState as v, useCallback as tt, useEffect as M, useRef as F, useMemo as H } from "react";
|
|
3
|
+
import { createPortal as et } from "react-dom";
|
|
4
|
+
import { g as st, O as m, q as nt, t as it, v as rt, w as ot, f as ct, e as lt, x as dt, c as at, d as ht, y as ut, z as mt, A as ft, o as kt, r as bt, s as yt, m as pt, n as It, i as _t, j as gt, B as z, l as q, k as wt, a as Tt, D as Rt, E as Et, F as St, X as Ct, R as Ot } from "./icons-CmfXmn13.js";
|
|
5
|
+
import { f as vt, c as V, b as xt } from "./indexedDbPersistence-BKlGPFTP.js";
|
|
6
|
+
import { c as J, r as Pt, s as X } from "./serialize-R4V4gmHs.js";
|
|
7
|
+
import { g as At, H as Mt, F as Nt, L as D } from "./fieldRegistry-PjJWXFoB.js";
|
|
8
|
+
import { C as W, f as Lt } from "./CommentAvatar-TKqsM8vG.js";
|
|
9
|
+
function Dt(d, t) {
|
|
10
|
+
const i = Array.from(d ?? ""), e = Array.from(t ?? "");
|
|
11
11
|
let s = 0;
|
|
12
12
|
const n = Math.min(i.length, e.length);
|
|
13
13
|
for (; s < n && i[s] === e[s]; ) s += 1;
|
|
@@ -16,17 +16,17 @@ function Nt(a, t) {
|
|
|
16
16
|
r -= 1, o -= 1;
|
|
17
17
|
return { start: s, oldEnd: r, newEnd: o, oldChars: i, newChars: e };
|
|
18
18
|
}
|
|
19
|
-
const B = "$fieldTypes", R = "$comments", O = "$people";
|
|
20
|
-
class
|
|
19
|
+
const B = "$fieldTypes", R = "$comments", O = "$people", j = "$title";
|
|
20
|
+
class $ {
|
|
21
21
|
constructor(t) {
|
|
22
|
-
this.blocks = new Map(((t == null ? void 0 : t.blocks) ?? []).map((i) => [i.id, i])), this.runs = new Map(((t == null ? void 0 : t.runs) ?? []).map((i) => [i.id, i])), this.rootId = (t == null ? void 0 : t.rootId) ?? null, this.fieldTypes = new Map(((t == null ? void 0 : t.fieldTypes) ?? []).map((i) => [i.id, i])), this._fieldTypesSnapshot = null, this.comments = new Map(((t == null ? void 0 : t.comments) ?? []).map((i) => [i.id, i])), this._commentsSnapshot = null, this.people = new Map(((t == null ? void 0 : t.people) ?? []).map((i) => [i.id, i])), this._peopleSnapshot = null, this._listeners = /* @__PURE__ */ new Map(), this._globalListeners = /* @__PURE__ */ new Set(), this._peerId =
|
|
22
|
+
this.blocks = new Map(((t == null ? void 0 : t.blocks) ?? []).map((i) => [i.id, i])), this.runs = new Map(((t == null ? void 0 : t.runs) ?? []).map((i) => [i.id, i])), this.rootId = (t == null ? void 0 : t.rootId) ?? null, this.fieldTypes = new Map(((t == null ? void 0 : t.fieldTypes) ?? []).map((i) => [i.id, i])), this._fieldTypesSnapshot = null, this.comments = new Map(((t == null ? void 0 : t.comments) ?? []).map((i) => [i.id, i])), this._commentsSnapshot = null, this.people = new Map(((t == null ? void 0 : t.people) ?? []).map((i) => [i.id, i])), this._peopleSnapshot = null, this.title = (t == null ? void 0 : t.title) ?? "", this._listeners = /* @__PURE__ */ new Map(), this._globalListeners = /* @__PURE__ */ new Set(), this._peerId = At(), this._clock = new Mt(this._peerId), this._fieldClocks = new Nt(), this._orders = /* @__PURE__ */ new Map(), this._runOrders = /* @__PURE__ */ new Map(), this._runChars = /* @__PURE__ */ new Map(), this._runValueSnapshots = /* @__PURE__ */ new Map();
|
|
23
23
|
}
|
|
24
24
|
/** Lazily seeds a block's ordering CRDT state from its current (plain-array) contentIds the first time it's touched. */
|
|
25
25
|
_getOrder(t) {
|
|
26
26
|
let i = this._orders.get(t);
|
|
27
27
|
if (!i) {
|
|
28
28
|
const e = this.blocks.get(t);
|
|
29
|
-
i =
|
|
29
|
+
i = D.fromArray((e == null ? void 0 : e.contentIds) ?? [], { peerId: "legacy" }), this._orders.set(t, i);
|
|
30
30
|
}
|
|
31
31
|
return i;
|
|
32
32
|
}
|
|
@@ -55,7 +55,7 @@ class F {
|
|
|
55
55
|
let i = this._runOrders.get(t);
|
|
56
56
|
if (!i) {
|
|
57
57
|
const e = this.runs.get(t), s = /* @__PURE__ */ new Map();
|
|
58
|
-
i = new
|
|
58
|
+
i = new D();
|
|
59
59
|
let n = null, r = 0;
|
|
60
60
|
for (const o of Array.from((e == null ? void 0 : e.value) ?? "")) {
|
|
61
61
|
const c = `${t}:legacyChar:${r}`;
|
|
@@ -84,16 +84,16 @@ class F {
|
|
|
84
84
|
* other regardless of how many ticks they'd otherwise get.
|
|
85
85
|
*/
|
|
86
86
|
_editRunText(t, i) {
|
|
87
|
-
const e = this._materializeRunValue(t), { start: s, oldEnd: n, newEnd: r, newChars: o } =
|
|
87
|
+
const e = this._materializeRunValue(t), { start: s, oldEnd: n, newEnd: r, newChars: o } = Dt(e, i), c = this._getRunOrder(t), l = this._runChars.get(t), a = c.toArray(), h = this._clock.tick(), u = [];
|
|
88
88
|
for (let w = s; w < n; w += 1) {
|
|
89
|
-
const g =
|
|
89
|
+
const g = a[w];
|
|
90
90
|
c.delete(g, h), u.push({ id: g, clock: h });
|
|
91
91
|
}
|
|
92
92
|
const f = [];
|
|
93
|
-
let T = s > 0 ?
|
|
93
|
+
let T = s > 0 ? a[s - 1] : null;
|
|
94
94
|
for (let w = s; w < r; w += 1) {
|
|
95
|
-
const g =
|
|
96
|
-
|
|
95
|
+
const g = st(), _ = o[w];
|
|
96
|
+
l.set(g, _), c.insert(g, T, h, this._peerId), f.push({ id: g, char: _, afterId: T, clock: h }), T = g;
|
|
97
97
|
}
|
|
98
98
|
return this._runValueSnapshots.delete(t), { oldValue: e, insertedChars: f, deletedCharIds: u, clock: h };
|
|
99
99
|
}
|
|
@@ -161,6 +161,16 @@ class F {
|
|
|
161
161
|
getPerson(t) {
|
|
162
162
|
return this.people.get(t);
|
|
163
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* The document's own title — real, collaboration-aware document data
|
|
166
|
+
* (see `docTitle` in applyOperation/applyRemoteOperation below), not a
|
|
167
|
+
* device-local/storage-layer concern. A host app that wants title edits
|
|
168
|
+
* on one collaborator's device to show up on another's reads this
|
|
169
|
+
* (via `useTitle`) instead of keeping its own separate title state.
|
|
170
|
+
*/
|
|
171
|
+
getTitle() {
|
|
172
|
+
return this.title;
|
|
173
|
+
}
|
|
164
174
|
/**
|
|
165
175
|
* Every run id in the whole document, regardless of reachability from
|
|
166
176
|
* the root — used by removeCommentMarkEverywhere (see
|
|
@@ -248,11 +258,11 @@ class F {
|
|
|
248
258
|
if (o)
|
|
249
259
|
this._replayRunTextEdit(t.id, o);
|
|
250
260
|
else {
|
|
251
|
-
const { oldValue:
|
|
261
|
+
const { oldValue: l, insertedChars: a, deletedCharIds: h, clock: u } = this._editRunText(
|
|
252
262
|
t.id,
|
|
253
263
|
t.patch.value
|
|
254
264
|
);
|
|
255
|
-
o = { oldValue:
|
|
265
|
+
o = { oldValue: l, insertedChars: a, deletedCharIds: h, clock: u }, t._charEdit = o;
|
|
256
266
|
}
|
|
257
267
|
const c = this._materializeRunValue(t.id);
|
|
258
268
|
return this.runs.set(t.id, { ...e, value: c }), this._lastEnvelope = {
|
|
@@ -263,9 +273,9 @@ class F {
|
|
|
263
273
|
clock: o.clock
|
|
264
274
|
}, this._notify([t.id]), z(
|
|
265
275
|
t.id,
|
|
266
|
-
o.insertedChars.map((
|
|
276
|
+
o.insertedChars.map((l) => l.id),
|
|
267
277
|
// undo: tombstone what was just inserted...
|
|
268
|
-
o.deletedCharIds.map((
|
|
278
|
+
o.deletedCharIds.map((l) => l.id),
|
|
269
279
|
// ...and restore what was just deleted
|
|
270
280
|
o.oldValue
|
|
271
281
|
// cosmetic-only, for History's caret restoration/change log -- see editRunChars's own doc comment
|
|
@@ -280,7 +290,7 @@ class F {
|
|
|
280
290
|
id: t.id,
|
|
281
291
|
patch: t.patch,
|
|
282
292
|
clocks: r
|
|
283
|
-
}, this._notify([t.id]),
|
|
293
|
+
}, this._notify([t.id]), q(t.id, n);
|
|
284
294
|
}
|
|
285
295
|
case m.EDIT_RUN_CHARS: {
|
|
286
296
|
const e = this._getRunOrder(t.id), s = this._clock.tick();
|
|
@@ -306,7 +316,7 @@ class F {
|
|
|
306
316
|
id: t.id,
|
|
307
317
|
patch: t.patch,
|
|
308
318
|
clocks: n
|
|
309
|
-
}, this._notify([t.id]),
|
|
319
|
+
}, this._notify([t.id]), gt(t.id, s);
|
|
310
320
|
}
|
|
311
321
|
case m.CHANGE_BLOCK_TYPE: {
|
|
312
322
|
const e = this.blocks.get(t.id), s = e.type, n = e.props, r = this._clock.tick();
|
|
@@ -317,7 +327,7 @@ class F {
|
|
|
317
327
|
blockType: t.blockType,
|
|
318
328
|
props: t.props,
|
|
319
329
|
clock: r
|
|
320
|
-
}, this._notify([t.id]),
|
|
330
|
+
}, this._notify([t.id]), _t(t.id, s, n);
|
|
321
331
|
}
|
|
322
332
|
case m.INSERT_BLOCK: {
|
|
323
333
|
if (t.subtree) {
|
|
@@ -338,13 +348,13 @@ class F {
|
|
|
338
348
|
blockId: t.block.id,
|
|
339
349
|
slot: s.getSlot(t.block.id),
|
|
340
350
|
subtree: t.subtree ?? { blocks: [t.block], runs: [] }
|
|
341
|
-
}, this._notify([t.block.id, t.parentId]),
|
|
351
|
+
}, this._notify([t.block.id, t.parentId]), It(t.block.id);
|
|
342
352
|
}
|
|
343
353
|
case m.REMOVE_BLOCK: {
|
|
344
354
|
const e = this.blocks.get(t.id), s = e.parentId, n = this.blocks.get(s), r = this._getOrder(s), o = r.toArray().indexOf(t.id), c = this._captureSubtree(t.id);
|
|
345
355
|
this._deleteSubtree(t.id);
|
|
346
|
-
const
|
|
347
|
-
return r.delete(t.id,
|
|
356
|
+
const l = this._clock.tick();
|
|
357
|
+
return r.delete(t.id, l), this.blocks.set(s, { ...n, contentIds: r.toArray() }), this._lastEnvelope = { kind: "deleteSlot", parentId: s, blockId: t.id, clock: l }, this._notify([s]), { type: m.INSERT_BLOCK, block: e, parentId: s, index: o, subtree: c };
|
|
348
358
|
}
|
|
349
359
|
case m.MOVE_BLOCK: {
|
|
350
360
|
const s = this.blocks.get(t.id).parentId, n = this._getOrder(s), r = n.toArray().indexOf(t.id);
|
|
@@ -352,8 +362,8 @@ class F {
|
|
|
352
362
|
...this.blocks.get(s),
|
|
353
363
|
contentIds: n.toArray()
|
|
354
364
|
});
|
|
355
|
-
const o = this._getOrder(t.toParentId), c = o.toArray(),
|
|
356
|
-
o.has(t.id) ? o.move(t.id,
|
|
365
|
+
const o = this._getOrder(t.toParentId), c = o.toArray(), l = t.toIndex ?? c.length, a = l > 0 ? c[l - 1] : null, h = this._clock.tick();
|
|
366
|
+
o.has(t.id) ? o.move(t.id, a, h, this._peerId) : o.insert(t.id, a, h, this._peerId), this.blocks.set(t.toParentId, {
|
|
357
367
|
...this.blocks.get(t.toParentId),
|
|
358
368
|
contentIds: o.toArray()
|
|
359
369
|
}), this.blocks.set(t.id, { ...this.blocks.get(t.id), parentId: t.toParentId }), this._lastEnvelope = {
|
|
@@ -364,23 +374,23 @@ class F {
|
|
|
364
374
|
slot: o.getSlot(t.id)
|
|
365
375
|
};
|
|
366
376
|
const u = /* @__PURE__ */ new Set([t.id, s, t.toParentId]);
|
|
367
|
-
return this._notify(u),
|
|
377
|
+
return this._notify(u), pt(t.id, s, r);
|
|
368
378
|
}
|
|
369
379
|
case m.SET_BLOCK_CONTENT_IDS: {
|
|
370
380
|
const e = this.blocks.get(t.blockId), s = e.contentIds;
|
|
371
|
-
return this.blocks.set(t.blockId, { ...e, contentIds: t.contentIds }), this._orders.set(t.blockId,
|
|
381
|
+
return this.blocks.set(t.blockId, { ...e, contentIds: t.contentIds }), this._orders.set(t.blockId, D.fromArray(t.contentIds, { peerId: "legacy" })), this._lastEnvelope = null, this._notify([t.blockId]), yt(t.blockId, s);
|
|
372
382
|
}
|
|
373
383
|
case m.REPLACE_RUN_SPAN: {
|
|
374
|
-
const e = this.blocks.get(t.blockId), s = e.contentIds.indexOf(t.oldRunIds[0]) !== -1, n = s ? e.contentIds : ((i = e.props) == null ? void 0 : i.titleRunIds) ?? [], r = n.indexOf(t.oldRunIds[0]), o = t.oldRunIds.map((
|
|
375
|
-
for (const
|
|
376
|
-
for (const
|
|
384
|
+
const e = this.blocks.get(t.blockId), s = e.contentIds.indexOf(t.oldRunIds[0]) !== -1, n = s ? e.contentIds : ((i = e.props) == null ? void 0 : i.titleRunIds) ?? [], r = n.indexOf(t.oldRunIds[0]), o = t.oldRunIds.map((l) => this.runs.get(l));
|
|
385
|
+
for (const l of t.oldRunIds) this.runs.delete(l);
|
|
386
|
+
for (const l of t.newRuns) this.runs.set(l.id, l);
|
|
377
387
|
const c = [...n];
|
|
378
|
-
return c.splice(r, t.oldRunIds.length, ...t.newRuns.map((
|
|
388
|
+
return c.splice(r, t.oldRunIds.length, ...t.newRuns.map((l) => l.id)), s ? this.blocks.set(t.blockId, { ...e, contentIds: c }) : this.blocks.set(t.blockId, {
|
|
379
389
|
...e,
|
|
380
390
|
props: { ...e.props, titleRunIds: c }
|
|
381
|
-
}), this._lastEnvelope = null, this._notify([t.blockId, ...t.oldRunIds, ...t.newRuns.map((
|
|
391
|
+
}), this._lastEnvelope = null, this._notify([t.blockId, ...t.oldRunIds, ...t.newRuns.map((l) => l.id)]), bt(
|
|
382
392
|
t.blockId,
|
|
383
|
-
t.newRuns.map((
|
|
393
|
+
t.newRuns.map((l) => l.id),
|
|
384
394
|
o
|
|
385
395
|
);
|
|
386
396
|
}
|
|
@@ -392,24 +402,24 @@ class F {
|
|
|
392
402
|
return s ? this.blocks.set(t.blockId, {
|
|
393
403
|
...e,
|
|
394
404
|
props: { ...e.props, titleRunIds: o }
|
|
395
|
-
}) : this.blocks.set(t.blockId, { ...e, contentIds: o }), this._lastEnvelope = null, this._notify([t.blockId, ...n, ...o]),
|
|
405
|
+
}) : this.blocks.set(t.blockId, { ...e, contentIds: o }), this._lastEnvelope = null, this._notify([t.blockId, ...n, ...o]), kt(t.blockId, r);
|
|
396
406
|
}
|
|
397
407
|
case m.ADD_FIELD_TYPE:
|
|
398
|
-
return this.fieldTypes.set(t.fieldType.id, t.fieldType), this._fieldTypesSnapshot = null, this._notify([B]),
|
|
408
|
+
return this.fieldTypes.set(t.fieldType.id, t.fieldType), this._fieldTypesSnapshot = null, this._notify([B]), ft(t.fieldType.id);
|
|
399
409
|
case m.UPDATE_FIELD_TYPE: {
|
|
400
410
|
const e = this.fieldTypes.get(t.id), s = {};
|
|
401
411
|
for (const n of Object.keys(t.patch)) s[n] = e[n];
|
|
402
|
-
return this.fieldTypes.set(t.id, { ...e, ...t.patch }), this._fieldTypesSnapshot = null, this._notify([B]),
|
|
412
|
+
return this.fieldTypes.set(t.id, { ...e, ...t.patch }), this._fieldTypesSnapshot = null, this._notify([B]), mt(t.id, s);
|
|
403
413
|
}
|
|
404
414
|
case m.REMOVE_FIELD_TYPE: {
|
|
405
415
|
const e = this.fieldTypes.get(t.id);
|
|
406
|
-
return this.fieldTypes.delete(t.id), this._fieldTypesSnapshot = null, this._notify([B]),
|
|
416
|
+
return this.fieldTypes.delete(t.id), this._fieldTypesSnapshot = null, this._notify([B]), ut(e);
|
|
407
417
|
}
|
|
408
418
|
case m.ADD_COMMENT_THREAD:
|
|
409
|
-
return this.comments.set(t.thread.id, t.thread), this._commentsSnapshot = null, this._lastEnvelope = { kind: "commentWrite", op: "addThread", thread: t.thread }, this._notify([R]),
|
|
419
|
+
return this.comments.set(t.thread.id, t.thread), this._commentsSnapshot = null, this._lastEnvelope = { kind: "commentWrite", op: "addThread", thread: t.thread }, this._notify([R]), ht(t.thread.id);
|
|
410
420
|
case m.REMOVE_COMMENT_THREAD: {
|
|
411
421
|
const e = this.comments.get(t.commentId);
|
|
412
|
-
return this.comments.delete(t.commentId), this._commentsSnapshot = null, this._lastEnvelope = { kind: "commentWrite", op: "removeThread", commentId: t.commentId }, this._notify([R]),
|
|
422
|
+
return this.comments.delete(t.commentId), this._commentsSnapshot = null, this._lastEnvelope = { kind: "commentWrite", op: "removeThread", commentId: t.commentId }, this._notify([R]), at(e);
|
|
413
423
|
}
|
|
414
424
|
case m.ADD_COMMENT_REPLY: {
|
|
415
425
|
const e = this.comments.get(t.commentId);
|
|
@@ -418,7 +428,7 @@ class F {
|
|
|
418
428
|
op: "addReply",
|
|
419
429
|
commentId: t.commentId,
|
|
420
430
|
message: t.message
|
|
421
|
-
}, this._notify([R]),
|
|
431
|
+
}, this._notify([R]), dt(t.commentId, t.message.id);
|
|
422
432
|
}
|
|
423
433
|
case m.REMOVE_COMMENT_REPLY: {
|
|
424
434
|
const e = this.comments.get(t.commentId), s = e.messages.find((n) => n.id === t.messageId);
|
|
@@ -430,7 +440,7 @@ class F {
|
|
|
430
440
|
op: "removeReply",
|
|
431
441
|
commentId: t.commentId,
|
|
432
442
|
messageId: t.messageId
|
|
433
|
-
}, this._notify([R]),
|
|
443
|
+
}, this._notify([R]), lt(t.commentId, s);
|
|
434
444
|
}
|
|
435
445
|
case m.RESOLVE_COMMENT: {
|
|
436
446
|
const e = this.comments.get(t.commentId), s = e.resolved;
|
|
@@ -439,18 +449,22 @@ class F {
|
|
|
439
449
|
op: "resolve",
|
|
440
450
|
commentId: t.commentId,
|
|
441
451
|
resolved: t.resolved
|
|
442
|
-
}, this._notify([R]),
|
|
452
|
+
}, this._notify([R]), ct(t.commentId, s);
|
|
443
453
|
}
|
|
444
454
|
case m.ADD_PERSON:
|
|
445
|
-
return this.people.set(t.person.id, t.person), this._peopleSnapshot = null, this._lastEnvelope = { kind: "peopleWrite", op: "add", person: t.person }, this._notify([O]),
|
|
455
|
+
return this.people.set(t.person.id, t.person), this._peopleSnapshot = null, this._lastEnvelope = { kind: "peopleWrite", op: "add", person: t.person }, this._notify([O]), ot(t.person.id);
|
|
446
456
|
case m.UPDATE_PERSON: {
|
|
447
457
|
const e = this.people.get(t.id), s = {};
|
|
448
458
|
for (const n of Object.keys(t.patch)) s[n] = e[n];
|
|
449
|
-
return this.people.set(t.id, { ...e, ...t.patch }), this._peopleSnapshot = null, this._lastEnvelope = { kind: "peopleWrite", op: "update", id: t.id, patch: t.patch }, this._notify([O]),
|
|
459
|
+
return this.people.set(t.id, { ...e, ...t.patch }), this._peopleSnapshot = null, this._lastEnvelope = { kind: "peopleWrite", op: "update", id: t.id, patch: t.patch }, this._notify([O]), rt(t.id, s);
|
|
450
460
|
}
|
|
451
461
|
case m.REMOVE_PERSON: {
|
|
452
462
|
const e = this.people.get(t.id);
|
|
453
|
-
return this.people.delete(t.id), this._peopleSnapshot = null, this._lastEnvelope = { kind: "peopleWrite", op: "remove", id: t.id }, this._notify([O]),
|
|
463
|
+
return this.people.delete(t.id), this._peopleSnapshot = null, this._lastEnvelope = { kind: "peopleWrite", op: "remove", id: t.id }, this._notify([O]), it(e);
|
|
464
|
+
}
|
|
465
|
+
case m.SET_TITLE: {
|
|
466
|
+
const e = this.title, s = this._clock.tick();
|
|
467
|
+
return this._fieldClocks.recordLocal("$doc", "title", s), this.title = t.title, this._lastEnvelope = { kind: "fieldWrite", target: "docTitle", title: t.title, clock: s }, this._notify([j]), nt(e);
|
|
454
468
|
}
|
|
455
469
|
default:
|
|
456
470
|
throw new Error(`Unknown operation type: ${t.type}`);
|
|
@@ -548,7 +562,7 @@ class F {
|
|
|
548
562
|
type: t.blockType,
|
|
549
563
|
props: t.props
|
|
550
564
|
}), this._notify([t.id]));
|
|
551
|
-
}
|
|
565
|
+
} else t.target === "docTitle" && this._fieldClocks.shouldApplyRemote("$doc", "title", t.clock) && (this._fieldClocks.recordRemote("$doc", "title", t.clock), this.title = t.title, this._notify([j]));
|
|
552
566
|
for (const s of Object.values(t.clocks ?? {})) this._clock.receive(s);
|
|
553
567
|
t.clock && this._clock.receive(t.clock);
|
|
554
568
|
return;
|
|
@@ -646,31 +660,32 @@ class F {
|
|
|
646
660
|
rootId: this.rootId,
|
|
647
661
|
fieldTypes: [...this.fieldTypes.values()],
|
|
648
662
|
comments: [...this.comments.values()],
|
|
649
|
-
people: [...this.people.values()]
|
|
663
|
+
people: [...this.people.values()],
|
|
664
|
+
title: this.title
|
|
650
665
|
};
|
|
651
666
|
}
|
|
652
667
|
static fromJSON(t) {
|
|
653
|
-
return new
|
|
668
|
+
return new $(t);
|
|
654
669
|
}
|
|
655
670
|
}
|
|
656
|
-
function
|
|
657
|
-
if (typeof
|
|
658
|
-
else for (const i of t)
|
|
671
|
+
function Bt(d, t) {
|
|
672
|
+
if (typeof d.performBatch == "function") d.performBatch(t);
|
|
673
|
+
else for (const i of t) d.applyOperation(i);
|
|
659
674
|
}
|
|
660
|
-
function
|
|
661
|
-
return { roots: t.map((i) =>
|
|
675
|
+
function re(d, t) {
|
|
676
|
+
return { roots: t.map((i) => J(d, i)) };
|
|
662
677
|
}
|
|
663
|
-
function
|
|
678
|
+
function Vt(d, t, { parentId: i, index: e }) {
|
|
664
679
|
const s = [];
|
|
665
680
|
let n = e;
|
|
666
681
|
for (const r of t.roots) {
|
|
667
|
-
const { block: o, runs: c, subtreeBlocks:
|
|
668
|
-
o.parentId = i, s.push(
|
|
682
|
+
const { block: o, runs: c, subtreeBlocks: l } = Pt(r);
|
|
683
|
+
o.parentId = i, s.push(wt(o, i, n, { blocks: [o, ...l], runs: c })), n += 1;
|
|
669
684
|
}
|
|
670
|
-
|
|
685
|
+
Bt(d, s);
|
|
671
686
|
}
|
|
672
|
-
function
|
|
673
|
-
const i =
|
|
687
|
+
function $t(d, t) {
|
|
688
|
+
const i = d.store ?? d;
|
|
674
689
|
i.blocks = new Map((t.blocks ?? []).map((e) => [e.id, e])), i.runs = new Map((t.runs ?? []).map((e) => [e.id, e])), i.rootId = t.rootId ?? null, i.fieldTypes = new Map((t.fieldTypes ?? []).map((e) => [e.id, e])), i._fieldTypesSnapshot = null, i.comments = new Map((t.comments ?? []).map((e) => [e.id, e])), i._commentsSnapshot = null, i._orders = /* @__PURE__ */ new Map(), i._notify([
|
|
675
690
|
...i.blocks.keys(),
|
|
676
691
|
...i.runs.keys(),
|
|
@@ -678,9 +693,9 @@ function Bt(a, t) {
|
|
|
678
693
|
"$comments"
|
|
679
694
|
]);
|
|
680
695
|
}
|
|
681
|
-
function
|
|
696
|
+
function oe(d, t) {
|
|
682
697
|
for (const i of t)
|
|
683
|
-
|
|
698
|
+
d.register(`__blockTemplate:${i.id}`, {
|
|
684
699
|
component: () => null,
|
|
685
700
|
isLeaf: !0,
|
|
686
701
|
slashCommand: {
|
|
@@ -688,77 +703,77 @@ function ie(a, t) {
|
|
|
688
703
|
icon: i.icon,
|
|
689
704
|
keywords: i.keywords ?? [i.label],
|
|
690
705
|
run(e, { blockId: s, runId: n, sliceStart: r, sliceEnd: o }) {
|
|
691
|
-
const c = e.getRun(n),
|
|
706
|
+
const c = e.getRun(n), l = (c == null ? void 0 : c.value) ?? "";
|
|
692
707
|
e.applyOperation(
|
|
693
|
-
|
|
708
|
+
q(n, { value: l.slice(0, r) + l.slice(o) })
|
|
694
709
|
);
|
|
695
|
-
const
|
|
696
|
-
|
|
710
|
+
const a = e.getBlock(s), u = e.getBlock(a.parentId).contentIds.indexOf(s) + 1;
|
|
711
|
+
Vt(e, i, { parentId: a.parentId, index: u });
|
|
697
712
|
}
|
|
698
713
|
}
|
|
699
714
|
});
|
|
700
715
|
}
|
|
701
|
-
function
|
|
702
|
-
const i =
|
|
716
|
+
function Ft(d, { pretty: t = !0 } = {}) {
|
|
717
|
+
const i = d.getRootId(), { blocks: e, runs: s } = J(d, i);
|
|
703
718
|
return JSON.stringify({ version: 1, rootId: i, blocks: e, runs: s }, null, t ? 2 : 0);
|
|
704
719
|
}
|
|
705
|
-
function
|
|
706
|
-
const e =
|
|
707
|
-
return e ?
|
|
720
|
+
function G(d, t, i) {
|
|
721
|
+
const e = d.getBlock(d.getRootId());
|
|
722
|
+
return e ? X(d, t, e.contentIds, i).html : "";
|
|
708
723
|
}
|
|
709
|
-
function
|
|
710
|
-
const e =
|
|
711
|
-
return e ?
|
|
724
|
+
function ce(d, t, i) {
|
|
725
|
+
const e = d.getBlock(d.getRootId());
|
|
726
|
+
return e ? X(d, t, e.contentIds, i).text : "";
|
|
712
727
|
}
|
|
713
|
-
function
|
|
728
|
+
function le(d, t, i) {
|
|
714
729
|
return `<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">
|
|
715
730
|
<head>
|
|
716
731
|
<meta charset="utf-8">
|
|
717
732
|
<title>Document</title>
|
|
718
733
|
<!--[if gte mso 9]><xml><w:WordDocument><w:View>Print</w:View><w:DoNotOptimizeForBrowser/></w:WordDocument></xml><![endif]-->
|
|
719
734
|
</head>
|
|
720
|
-
<body>${
|
|
735
|
+
<body>${G(d, t, i)}</body>
|
|
721
736
|
</html>`;
|
|
722
737
|
}
|
|
723
|
-
function
|
|
724
|
-
const e =
|
|
738
|
+
function de(d, t, i) {
|
|
739
|
+
const e = d.getBlock(d.getRootId());
|
|
725
740
|
if (!e) return "";
|
|
726
|
-
const s = { store:
|
|
741
|
+
const s = { store: d, registry: t, inlineRegistry: i }, n = e.contentIds;
|
|
727
742
|
let r = "", o = null;
|
|
728
743
|
for (const c of n) {
|
|
729
|
-
const
|
|
744
|
+
const l = d.getBlock(c), a = t.get(l.type), h = (a.toMarkdown ?? a.toPlainText)(l, s);
|
|
730
745
|
if (o) {
|
|
731
|
-
const u =
|
|
746
|
+
const u = l.type === "listItem" && o.type === "listItem" && !!l.props.ordered == !!o.props.ordered, f = l.type === "blockquote" && o.type === "blockquote";
|
|
732
747
|
r += u || f ? `
|
|
733
748
|
` : `
|
|
734
749
|
|
|
735
750
|
`;
|
|
736
751
|
}
|
|
737
|
-
r += h, o =
|
|
752
|
+
r += h, o = l;
|
|
738
753
|
}
|
|
739
754
|
return r;
|
|
740
755
|
}
|
|
741
|
-
const
|
|
742
|
-
function
|
|
743
|
-
store:
|
|
756
|
+
const Ht = 5 * 60 * 1e3, zt = 200;
|
|
757
|
+
function Wt({
|
|
758
|
+
store: d,
|
|
744
759
|
docId: t,
|
|
745
|
-
idleMs: i =
|
|
746
|
-
maxVersions: e =
|
|
760
|
+
idleMs: i = Ht,
|
|
761
|
+
maxVersions: e = zt,
|
|
747
762
|
onSnapshot: s,
|
|
748
763
|
onError: n
|
|
749
764
|
}) {
|
|
750
|
-
let r = null, o =
|
|
751
|
-
function
|
|
765
|
+
let r = null, o = d.getHistoryLog().length, c = !1;
|
|
766
|
+
function l() {
|
|
752
767
|
r && (clearTimeout(r), r = null);
|
|
753
768
|
}
|
|
754
|
-
async function
|
|
755
|
-
if (
|
|
769
|
+
async function a() {
|
|
770
|
+
if (l(), !c) return;
|
|
756
771
|
c = !1;
|
|
757
|
-
const u =
|
|
772
|
+
const u = d.getHistoryLog(), f = u.slice(o);
|
|
758
773
|
if (o = u.length, f.length === 0) return;
|
|
759
774
|
const T = new Set(f.map((_) => _.id).filter(Boolean)), w = [...new Set(f.map((_) => _.actorId).filter(Boolean))], g = f[f.length - 1].actorId ?? null;
|
|
760
775
|
try {
|
|
761
|
-
const _ = JSON.parse(
|
|
776
|
+
const _ = JSON.parse(Ft(d)), S = {
|
|
762
777
|
id: crypto.randomUUID(),
|
|
763
778
|
docId: t,
|
|
764
779
|
timestamp: Date.now(),
|
|
@@ -767,30 +782,30 @@ function $t({
|
|
|
767
782
|
summary: `${T.size} block${T.size === 1 ? "" : "s"} changed`,
|
|
768
783
|
doc: _
|
|
769
784
|
};
|
|
770
|
-
await
|
|
771
|
-
const
|
|
772
|
-
if (
|
|
773
|
-
const C =
|
|
774
|
-
await Promise.all(C.map((N) =>
|
|
785
|
+
await vt(S), s == null || s(S);
|
|
786
|
+
const p = await V(t);
|
|
787
|
+
if (p.length > e) {
|
|
788
|
+
const C = p.slice(e);
|
|
789
|
+
await Promise.all(C.map((N) => xt(N.id)));
|
|
775
790
|
}
|
|
776
791
|
} catch (_) {
|
|
777
792
|
n == null || n(_);
|
|
778
793
|
}
|
|
779
794
|
}
|
|
780
|
-
const h =
|
|
781
|
-
c = !0,
|
|
795
|
+
const h = d.subscribeToHistory(() => {
|
|
796
|
+
c = !0, l(), r = setTimeout(a, i);
|
|
782
797
|
});
|
|
783
798
|
return {
|
|
784
799
|
/** Stops listening. Does NOT flush a final in-progress window -- call `flush()` first if you want that (e.g. right before navigating away). */
|
|
785
800
|
stop() {
|
|
786
|
-
|
|
801
|
+
l(), h();
|
|
787
802
|
},
|
|
788
803
|
/** Closes and saves the current window immediately, without waiting for `idleMs` of inactivity. A no-op if nothing's happened since the last save. */
|
|
789
|
-
flush:
|
|
804
|
+
flush: a
|
|
790
805
|
};
|
|
791
806
|
}
|
|
792
|
-
function
|
|
793
|
-
const i =
|
|
807
|
+
function jt(d, t) {
|
|
808
|
+
const i = U(d), e = U(t), s = i.length, n = e.length, r = Array.from({ length: s + 1 }, () => new Uint32Array(n + 1));
|
|
794
809
|
for (let h = s - 1; h >= 0; h -= 1)
|
|
795
810
|
for (let u = n - 1; u >= 0; u -= 1)
|
|
796
811
|
r[h][u] = i[h] === e[u] ? r[h + 1][u + 1] + 1 : Math.max(r[h + 1][u], r[h][u + 1]);
|
|
@@ -798,44 +813,44 @@ function zt(a, t) {
|
|
|
798
813
|
const f = o[o.length - 1];
|
|
799
814
|
f && f.type === h ? f.text += u : o.push({ type: h, text: u });
|
|
800
815
|
};
|
|
801
|
-
let
|
|
802
|
-
for (;
|
|
803
|
-
i[
|
|
804
|
-
for (;
|
|
805
|
-
c("removed", i[
|
|
806
|
-
for (;
|
|
807
|
-
c("added", e[
|
|
816
|
+
let l = 0, a = 0;
|
|
817
|
+
for (; l < s && a < n; )
|
|
818
|
+
i[l] === e[a] ? (c("equal", i[l]), l += 1, a += 1) : r[l + 1][a] >= r[l][a + 1] ? (c("removed", i[l]), l += 1) : (c("added", e[a]), a += 1);
|
|
819
|
+
for (; l < s; )
|
|
820
|
+
c("removed", i[l]), l += 1;
|
|
821
|
+
for (; a < n; )
|
|
822
|
+
c("added", e[a]), a += 1;
|
|
808
823
|
return o;
|
|
809
824
|
}
|
|
810
|
-
function
|
|
811
|
-
return (
|
|
825
|
+
function U(d) {
|
|
826
|
+
return (d ?? "").match(/\s+|[^\s]+/g) ?? [];
|
|
812
827
|
}
|
|
813
|
-
const
|
|
814
|
-
function A(
|
|
815
|
-
return
|
|
828
|
+
const Ut = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" };
|
|
829
|
+
function A(d) {
|
|
830
|
+
return d.replace(/[&<>"']/g, (t) => Ut[t]);
|
|
816
831
|
}
|
|
817
|
-
function
|
|
818
|
-
const t = new Map(
|
|
832
|
+
function Y(d) {
|
|
833
|
+
const t = new Map(d.blocks.map((r) => [r.id, r])), i = new Map(d.runs.map((r) => [r.id, r])), e = [], s = (r) => r.map((o) => {
|
|
819
834
|
var c;
|
|
820
835
|
return ((c = i.get(o)) == null ? void 0 : c.value) ?? "";
|
|
821
836
|
}).join(""), n = (r) => {
|
|
822
|
-
var
|
|
837
|
+
var l;
|
|
823
838
|
const o = t.get(r);
|
|
824
839
|
if (!o) return;
|
|
825
|
-
const c = (
|
|
826
|
-
Array.isArray(c) && c.length > 0 ? e.push({ id: r, text: s(c) }) : o.contentIds.length > 0 && o.contentIds.every((
|
|
827
|
-
for (const
|
|
828
|
-
i.has(
|
|
840
|
+
const c = (l = o.props) == null ? void 0 : l.titleRunIds;
|
|
841
|
+
Array.isArray(c) && c.length > 0 ? e.push({ id: r, text: s(c) }) : o.contentIds.length > 0 && o.contentIds.every((a) => i.has(a)) && e.push({ id: r, text: s(o.contentIds) });
|
|
842
|
+
for (const a of o.contentIds)
|
|
843
|
+
i.has(a) || n(a);
|
|
829
844
|
};
|
|
830
|
-
return n(
|
|
845
|
+
return n(d.rootId), e;
|
|
831
846
|
}
|
|
832
|
-
const
|
|
847
|
+
const K = {
|
|
833
848
|
rootId: "root",
|
|
834
849
|
blocks: [{ id: "root", type: "page", parentId: null, contentIds: [], props: {} }],
|
|
835
850
|
runs: []
|
|
836
851
|
};
|
|
837
|
-
function
|
|
838
|
-
const i =
|
|
852
|
+
function Yt(d, t) {
|
|
853
|
+
const i = Y(d ?? K), e = Y(t ?? K), s = new Map(i.map((o) => [o.id, o])), n = new Set(e.map((o) => o.id)), r = [];
|
|
839
854
|
for (const o of e) {
|
|
840
855
|
const c = s.get(o.id);
|
|
841
856
|
if (!c) {
|
|
@@ -849,11 +864,11 @@ function Wt(a, t) {
|
|
|
849
864
|
r.push(`<p class="be-version-diff-block">${A(o.text) || " "}</p>`);
|
|
850
865
|
continue;
|
|
851
866
|
}
|
|
852
|
-
const
|
|
867
|
+
const a = jt(c.text, o.text).map((h) => {
|
|
853
868
|
const u = A(h.text);
|
|
854
869
|
return h.type === "added" ? `<span class="be-version-diff-added">${u}</span>` : h.type === "removed" ? `<span class="be-version-diff-removed">${u}</span>` : u;
|
|
855
870
|
}).join("");
|
|
856
|
-
r.push(`<p class="be-version-diff-block">${
|
|
871
|
+
r.push(`<p class="be-version-diff-block">${a}</p>`);
|
|
857
872
|
}
|
|
858
873
|
for (const o of i)
|
|
859
874
|
if (!n.has(o.id)) {
|
|
@@ -864,94 +879,94 @@ function Wt(a, t) {
|
|
|
864
879
|
}
|
|
865
880
|
return r.length === 0 ? '<p class="be-version-diff-empty">No text changes.</p>' : r.join("");
|
|
866
881
|
}
|
|
867
|
-
function
|
|
868
|
-
const [t, i] = v([]), [e, s] = v(!1), n =
|
|
882
|
+
function Kt(d) {
|
|
883
|
+
const [t, i] = v([]), [e, s] = v(!1), n = tt(() => d ? (s(!1), V(d).then((r) => {
|
|
869
884
|
i(r), s(!0);
|
|
870
|
-
})) : Promise.resolve(), [
|
|
885
|
+
})) : Promise.resolve(), [d]);
|
|
871
886
|
return M(() => {
|
|
872
|
-
if (!
|
|
887
|
+
if (!d) {
|
|
873
888
|
i([]), s(!0);
|
|
874
889
|
return;
|
|
875
890
|
}
|
|
876
891
|
let r = !1;
|
|
877
|
-
return s(!1), V(
|
|
892
|
+
return s(!1), V(d).then((o) => {
|
|
878
893
|
r || (i(o), s(!0));
|
|
879
894
|
}), () => {
|
|
880
895
|
r = !0;
|
|
881
896
|
};
|
|
882
|
-
}, [
|
|
897
|
+
}, [d]), { versions: t, isLoaded: e, refresh: n };
|
|
883
898
|
}
|
|
884
|
-
const
|
|
885
|
-
function
|
|
886
|
-
const t = new Date(
|
|
899
|
+
const qt = 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
|
|
900
|
+
function Jt(d) {
|
|
901
|
+
const t = new Date(d), i = /* @__PURE__ */ new Date(), e = (n) => new Date(n.getFullYear(), n.getMonth(), n.getDate()).getTime(), s = Math.round((e(i) - e(t)) / (24 * 60 * 60 * 1e3));
|
|
887
902
|
return s === 0 ? "Today" : s === 1 ? "Yesterday" : t.toLocaleDateString(void 0, {
|
|
888
903
|
month: "long",
|
|
889
904
|
day: "numeric",
|
|
890
905
|
year: t.getFullYear() !== i.getFullYear() ? "numeric" : void 0
|
|
891
906
|
});
|
|
892
907
|
}
|
|
893
|
-
function
|
|
894
|
-
const e =
|
|
908
|
+
function ae({ docId: d, idleMs: t, maxVersions: i }) {
|
|
909
|
+
const e = Tt(), s = Rt(), n = Et(), { versions: r, isLoaded: o, refresh: c } = Kt(d), [l, a] = v(!1), [h, u] = v(null), [f, T] = v("changes"), w = F(null), g = F(null);
|
|
895
910
|
M(() => {
|
|
896
911
|
if (typeof e.getHistoryLog != "function") return;
|
|
897
|
-
const
|
|
912
|
+
const y = Wt({
|
|
898
913
|
store: e,
|
|
899
|
-
docId:
|
|
914
|
+
docId: d,
|
|
900
915
|
idleMs: t,
|
|
901
916
|
maxVersions: i,
|
|
902
917
|
onSnapshot: c
|
|
903
918
|
});
|
|
904
|
-
return () =>
|
|
905
|
-
}, [e,
|
|
919
|
+
return () => y.stop();
|
|
920
|
+
}, [e, d]);
|
|
906
921
|
function _() {
|
|
907
|
-
|
|
922
|
+
a(!1), u(null), T("changes");
|
|
908
923
|
}
|
|
909
924
|
M(() => {
|
|
910
|
-
if (!
|
|
911
|
-
const
|
|
925
|
+
if (!l) return;
|
|
926
|
+
const y = (I) => {
|
|
912
927
|
I.key === "Escape" && _();
|
|
913
928
|
};
|
|
914
|
-
return document.addEventListener("keydown",
|
|
915
|
-
}, [
|
|
916
|
-
var
|
|
917
|
-
if (
|
|
929
|
+
return document.addEventListener("keydown", y), () => document.removeEventListener("keydown", y);
|
|
930
|
+
}, [l]), M(() => {
|
|
931
|
+
var y, I, E;
|
|
932
|
+
if (l) {
|
|
918
933
|
g.current = document.activeElement;
|
|
919
934
|
const P = w.current;
|
|
920
|
-
(
|
|
935
|
+
(y = (P == null ? void 0 : P.querySelector(qt)) ?? P) == null || y.focus();
|
|
921
936
|
return;
|
|
922
937
|
}
|
|
923
938
|
(E = (I = g.current) == null ? void 0 : I.focus) == null || E.call(I), g.current = null;
|
|
924
|
-
}, [
|
|
925
|
-
const S = r.findIndex((
|
|
926
|
-
if (!
|
|
927
|
-
const
|
|
928
|
-
return
|
|
929
|
-
}, [
|
|
930
|
-
function
|
|
931
|
-
|
|
939
|
+
}, [l]);
|
|
940
|
+
const S = r.findIndex((y) => y.id === h), p = S >= 0 ? r[S] : null, C = S >= 0 ? r[S + 1] ?? null : null, N = H(() => {
|
|
941
|
+
if (!p) return "";
|
|
942
|
+
const y = new $(p.doc);
|
|
943
|
+
return G(y, s, n);
|
|
944
|
+
}, [p, s, n]), Q = H(() => p ? Yt((C == null ? void 0 : C.doc) ?? null, p.doc) : "", [p, C]);
|
|
945
|
+
function Z() {
|
|
946
|
+
p && window.confirm("Restore this version? This replaces the current document.") && ($t(e, p.doc), _());
|
|
932
947
|
}
|
|
933
948
|
const x = [];
|
|
934
|
-
for (const
|
|
935
|
-
const I =
|
|
949
|
+
for (const y of r) {
|
|
950
|
+
const I = Jt(y.timestamp);
|
|
936
951
|
let E = x[x.length - 1];
|
|
937
|
-
(!E || E.label !== I) && (E = { label: I, versions: [] }, x.push(E)), E.versions.push(
|
|
952
|
+
(!E || E.label !== I) && (E = { label: I, versions: [] }, x.push(E)), E.versions.push(y);
|
|
938
953
|
}
|
|
939
|
-
return /* @__PURE__ */ b(
|
|
954
|
+
return /* @__PURE__ */ b(L, { children: [
|
|
940
955
|
/* @__PURE__ */ b(
|
|
941
956
|
"button",
|
|
942
957
|
{
|
|
943
958
|
type: "button",
|
|
944
959
|
className: "be-version-history-trigger",
|
|
945
|
-
onClick: () =>
|
|
960
|
+
onClick: () => a(!0),
|
|
946
961
|
title: "Version history",
|
|
947
962
|
children: [
|
|
948
|
-
/* @__PURE__ */ k(
|
|
963
|
+
/* @__PURE__ */ k(St, { size: 15 }),
|
|
949
964
|
"Version history"
|
|
950
965
|
]
|
|
951
966
|
}
|
|
952
967
|
),
|
|
953
|
-
|
|
954
|
-
/* @__PURE__ */ b(
|
|
968
|
+
l && et(
|
|
969
|
+
/* @__PURE__ */ b(L, { children: [
|
|
955
970
|
/* @__PURE__ */ k("div", { className: "be-version-history-backdrop", onClick: _ }),
|
|
956
971
|
/* @__PURE__ */ b(
|
|
957
972
|
"div",
|
|
@@ -964,7 +979,7 @@ function de({ docId: a, idleMs: t, maxVersions: i }) {
|
|
|
964
979
|
tabIndex: -1,
|
|
965
980
|
children: [
|
|
966
981
|
/* @__PURE__ */ b("div", { className: "be-version-history-header", children: [
|
|
967
|
-
/* @__PURE__ */ k("span", { children:
|
|
982
|
+
/* @__PURE__ */ k("span", { children: p ? "Preview" : "Version history" }),
|
|
968
983
|
/* @__PURE__ */ k(
|
|
969
984
|
"button",
|
|
970
985
|
{
|
|
@@ -972,19 +987,19 @@ function de({ docId: a, idleMs: t, maxVersions: i }) {
|
|
|
972
987
|
className: "be-version-history-close",
|
|
973
988
|
onClick: _,
|
|
974
989
|
"aria-label": "Close",
|
|
975
|
-
children: /* @__PURE__ */ k(
|
|
990
|
+
children: /* @__PURE__ */ k(Ct, { size: 14 })
|
|
976
991
|
}
|
|
977
992
|
)
|
|
978
993
|
] }),
|
|
979
|
-
|
|
994
|
+
p ? /* @__PURE__ */ b("div", { className: "be-version-history-preview", children: [
|
|
980
995
|
/* @__PURE__ */ b("div", { className: "be-version-history-preview-meta", children: [
|
|
981
|
-
/* @__PURE__ */ k(
|
|
996
|
+
/* @__PURE__ */ k(W, { authorId: p.authorId, size: 24 }),
|
|
982
997
|
/* @__PURE__ */ b("div", { children: [
|
|
983
|
-
/* @__PURE__ */ k("div", { className: "be-version-history-preview-author", children:
|
|
998
|
+
/* @__PURE__ */ k("div", { className: "be-version-history-preview-author", children: p.authorId ?? "Unknown" }),
|
|
984
999
|
/* @__PURE__ */ b("div", { className: "be-version-history-preview-time", children: [
|
|
985
|
-
new Date(
|
|
1000
|
+
new Date(p.timestamp).toLocaleString(),
|
|
986
1001
|
" · ",
|
|
987
|
-
|
|
1002
|
+
p.summary
|
|
988
1003
|
] })
|
|
989
1004
|
] })
|
|
990
1005
|
] }),
|
|
@@ -1020,7 +1035,7 @@ function de({ docId: a, idleMs: t, maxVersions: i }) {
|
|
|
1020
1035
|
]
|
|
1021
1036
|
}
|
|
1022
1037
|
),
|
|
1023
|
-
f === "changes" && /* @__PURE__ */ b(
|
|
1038
|
+
f === "changes" && /* @__PURE__ */ b(L, { children: [
|
|
1024
1039
|
/* @__PURE__ */ b("div", { className: "be-version-history-diff-legend", children: [
|
|
1025
1040
|
/* @__PURE__ */ k("span", { className: "be-version-diff-added", children: "Added" }),
|
|
1026
1041
|
/* @__PURE__ */ k("span", { className: "be-version-diff-removed", children: "Removed" }),
|
|
@@ -1030,7 +1045,7 @@ function de({ docId: a, idleMs: t, maxVersions: i }) {
|
|
|
1030
1045
|
"div",
|
|
1031
1046
|
{
|
|
1032
1047
|
className: "be-version-history-preview-body be-version-history-diff-body",
|
|
1033
|
-
dangerouslySetInnerHTML: { __html:
|
|
1048
|
+
dangerouslySetInnerHTML: { __html: Q }
|
|
1034
1049
|
}
|
|
1035
1050
|
)
|
|
1036
1051
|
] }),
|
|
@@ -1058,9 +1073,9 @@ function de({ docId: a, idleMs: t, maxVersions: i }) {
|
|
|
1058
1073
|
{
|
|
1059
1074
|
type: "button",
|
|
1060
1075
|
className: "be-version-history-restore",
|
|
1061
|
-
onClick:
|
|
1076
|
+
onClick: Z,
|
|
1062
1077
|
children: [
|
|
1063
|
-
/* @__PURE__ */ k(
|
|
1078
|
+
/* @__PURE__ */ k(Ot, { size: 13 }),
|
|
1064
1079
|
"Restore this version"
|
|
1065
1080
|
]
|
|
1066
1081
|
}
|
|
@@ -1069,20 +1084,20 @@ function de({ docId: a, idleMs: t, maxVersions: i }) {
|
|
|
1069
1084
|
] }) : /* @__PURE__ */ b("div", { className: "be-version-history-list", children: [
|
|
1070
1085
|
!o && /* @__PURE__ */ k("p", { className: "be-version-history-empty", children: "Loading…" }),
|
|
1071
1086
|
o && r.length === 0 && /* @__PURE__ */ k("p", { className: "be-version-history-empty", children: "No versions yet — one is saved automatically after you make some edits and pause." }),
|
|
1072
|
-
x.map((
|
|
1073
|
-
/* @__PURE__ */ k("div", { className: "be-version-history-group-label", children:
|
|
1074
|
-
|
|
1087
|
+
x.map((y) => /* @__PURE__ */ b("div", { className: "be-version-history-group", children: [
|
|
1088
|
+
/* @__PURE__ */ k("div", { className: "be-version-history-group-label", children: y.label }),
|
|
1089
|
+
y.versions.map((I) => /* @__PURE__ */ b(
|
|
1075
1090
|
"button",
|
|
1076
1091
|
{
|
|
1077
1092
|
type: "button",
|
|
1078
1093
|
className: "be-version-history-item",
|
|
1079
1094
|
onClick: () => u(I.id),
|
|
1080
1095
|
children: [
|
|
1081
|
-
/* @__PURE__ */ k(
|
|
1096
|
+
/* @__PURE__ */ k(W, { authorId: I.authorId, size: 24 }),
|
|
1082
1097
|
/* @__PURE__ */ b("div", { className: "be-version-history-item-body", children: [
|
|
1083
1098
|
/* @__PURE__ */ k("div", { className: "be-version-history-item-author", children: I.authorId ?? "Unknown" }),
|
|
1084
1099
|
/* @__PURE__ */ b("div", { className: "be-version-history-item-meta", children: [
|
|
1085
|
-
|
|
1100
|
+
Lt(I.timestamp),
|
|
1086
1101
|
" · ",
|
|
1087
1102
|
I.summary
|
|
1088
1103
|
] })
|
|
@@ -1091,7 +1106,7 @@ function de({ docId: a, idleMs: t, maxVersions: i }) {
|
|
|
1091
1106
|
},
|
|
1092
1107
|
I.id
|
|
1093
1108
|
))
|
|
1094
|
-
] },
|
|
1109
|
+
] }, y.label))
|
|
1095
1110
|
] })
|
|
1096
1111
|
]
|
|
1097
1112
|
}
|
|
@@ -1102,19 +1117,19 @@ function de({ docId: a, idleMs: t, maxVersions: i }) {
|
|
|
1102
1117
|
] });
|
|
1103
1118
|
}
|
|
1104
1119
|
export {
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1120
|
+
$ as E,
|
|
1121
|
+
ae as V,
|
|
1122
|
+
G as a,
|
|
1123
|
+
de as b,
|
|
1124
|
+
Wt as c,
|
|
1125
|
+
Yt as d,
|
|
1126
|
+
Ft as e,
|
|
1127
|
+
ce as f,
|
|
1128
|
+
le as g,
|
|
1129
|
+
$t as h,
|
|
1130
|
+
re as i,
|
|
1131
|
+
Vt as j,
|
|
1132
|
+
oe as r,
|
|
1133
|
+
Kt as u
|
|
1119
1134
|
};
|
|
1120
|
-
//# sourceMappingURL=VersionHistory-
|
|
1135
|
+
//# sourceMappingURL=VersionHistory-BzMnJpbc.js.map
|