noteloom 0.3.2 → 0.4.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 (104) hide show
  1. package/README.md +344 -53
  2. package/bin/noteloom.mjs +139 -0
  3. package/dist/canvas.cjs +2 -0
  4. package/dist/canvas.cjs.map +1 -0
  5. package/dist/canvas.d.ts +2 -0
  6. package/dist/canvas.js +5 -0
  7. package/dist/canvas.js.map +1 -0
  8. package/dist/collab.cjs +2 -0
  9. package/dist/collab.cjs.map +1 -0
  10. package/dist/collab.d.ts +19 -0
  11. package/dist/collab.js +379 -0
  12. package/dist/collab.js.map +1 -0
  13. package/dist/comments.cjs +2 -0
  14. package/dist/comments.cjs.map +1 -0
  15. package/dist/comments.d.ts +17 -0
  16. package/dist/comments.js +19 -0
  17. package/dist/comments.js.map +1 -0
  18. package/dist/index.cjs +2 -0
  19. package/dist/index.cjs.map +1 -0
  20. package/dist/index.d.ts +392 -32
  21. package/dist/index.js +3983 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/persistence.cjs +2 -0
  24. package/dist/persistence.cjs.map +1 -0
  25. package/dist/persistence.d.ts +11 -0
  26. package/dist/persistence.js +12 -0
  27. package/dist/persistence.js.map +1 -0
  28. package/dist/shared/CommentAvatar-TKqsM8vG.js +53 -0
  29. package/dist/shared/CommentAvatar-TKqsM8vG.js.map +1 -0
  30. package/dist/shared/CommentAvatar-V457IgoQ.cjs +2 -0
  31. package/dist/shared/CommentAvatar-V457IgoQ.cjs.map +1 -0
  32. package/dist/shared/CommentThreadCard-CAJ3oPdr.cjs +2 -0
  33. package/dist/shared/CommentThreadCard-CAJ3oPdr.cjs.map +1 -0
  34. package/dist/shared/CommentThreadCard-Cxf8GwHJ.js +213 -0
  35. package/dist/shared/CommentThreadCard-Cxf8GwHJ.js.map +1 -0
  36. package/dist/shared/CommentsPanel-BwVVyMOC.js +76 -0
  37. package/dist/shared/CommentsPanel-BwVVyMOC.js.map +1 -0
  38. package/dist/shared/CommentsPanel-CES4uzye.cjs +2 -0
  39. package/dist/shared/CommentsPanel-CES4uzye.cjs.map +1 -0
  40. package/dist/shared/VersionHistory-Bg6fufP5.js +1120 -0
  41. package/dist/shared/VersionHistory-Bg6fufP5.js.map +1 -0
  42. package/dist/shared/VersionHistory-DELa2Wbq.cjs +12 -0
  43. package/dist/shared/VersionHistory-DELa2Wbq.cjs.map +1 -0
  44. package/dist/shared/VoiceListeningIndicator-BOfVmLK0.js +338 -0
  45. package/dist/shared/VoiceListeningIndicator-BOfVmLK0.js.map +1 -0
  46. package/dist/shared/VoiceListeningIndicator-DNX8JlQM.cjs +2 -0
  47. package/dist/shared/VoiceListeningIndicator-DNX8JlQM.cjs.map +1 -0
  48. package/dist/shared/fieldRegistry-BoYyW3GH.cjs +2 -0
  49. package/dist/shared/fieldRegistry-BoYyW3GH.cjs.map +1 -0
  50. package/dist/shared/fieldRegistry-PjJWXFoB.js +223 -0
  51. package/dist/shared/fieldRegistry-PjJWXFoB.js.map +1 -0
  52. package/dist/shared/icons-C1_s0jKK.js +4269 -0
  53. package/dist/shared/icons-C1_s0jKK.js.map +1 -0
  54. package/dist/shared/icons-DtCsXuU6.cjs +3531 -0
  55. package/dist/shared/icons-DtCsXuU6.cjs.map +1 -0
  56. package/dist/shared/index-B9jyyL8u.js +2145 -0
  57. package/dist/shared/index-B9jyyL8u.js.map +1 -0
  58. package/dist/shared/index-D9WEXpYM.cjs +2 -0
  59. package/dist/shared/index-D9WEXpYM.cjs.map +1 -0
  60. package/dist/shared/indexedDbPersistence-BKlGPFTP.js +112 -0
  61. package/dist/shared/indexedDbPersistence-BKlGPFTP.js.map +1 -0
  62. package/dist/shared/indexedDbPersistence-BWJ1h5Vp.cjs +2 -0
  63. package/dist/shared/indexedDbPersistence-BWJ1h5Vp.cjs.map +1 -0
  64. package/dist/shared/leafBlockFactory-A9eUhSe-.js +335 -0
  65. package/dist/shared/leafBlockFactory-A9eUhSe-.js.map +1 -0
  66. package/dist/shared/leafBlockFactory-Dp382eP8.cjs +2 -0
  67. package/dist/shared/leafBlockFactory-Dp382eP8.cjs.map +1 -0
  68. package/dist/shared/serialize-DWEfk0vU.cjs +3 -0
  69. package/dist/shared/serialize-DWEfk0vU.cjs.map +1 -0
  70. package/dist/shared/serialize-T9Odwx24.js +86 -0
  71. package/dist/shared/serialize-T9Odwx24.js.map +1 -0
  72. package/dist/shared/starter-kit-CY5wzYDf.js +4980 -0
  73. package/dist/shared/starter-kit-CY5wzYDf.js.map +1 -0
  74. package/dist/shared/starter-kit-lPN-NpJ5.cjs +27 -0
  75. package/dist/shared/starter-kit-lPN-NpJ5.cjs.map +1 -0
  76. package/dist/shared/usePopoverEdgeClamp-CDG26jBM.cjs +2 -0
  77. package/dist/shared/usePopoverEdgeClamp-CDG26jBM.cjs.map +1 -0
  78. package/dist/shared/usePopoverEdgeClamp-gmFm0CnI.js +109 -0
  79. package/dist/shared/usePopoverEdgeClamp-gmFm0CnI.js.map +1 -0
  80. package/dist/shared/useServiceWorkerUpdate-BduabXv6.js +94 -0
  81. package/dist/shared/useServiceWorkerUpdate-BduabXv6.js.map +1 -0
  82. package/dist/shared/useServiceWorkerUpdate-DQboGesi.cjs +2 -0
  83. package/dist/shared/useServiceWorkerUpdate-DQboGesi.cjs.map +1 -0
  84. package/dist/starter-kit.cjs +2 -0
  85. package/dist/starter-kit.cjs.map +1 -0
  86. package/dist/starter-kit.d.ts +9 -0
  87. package/dist/starter-kit.js +10 -0
  88. package/dist/starter-kit.js.map +1 -0
  89. package/dist/style.css +3529 -3200
  90. package/dist/versions.cjs +2 -0
  91. package/dist/versions.cjs.map +1 -0
  92. package/dist/versions.d.ts +11 -0
  93. package/dist/versions.js +13 -0
  94. package/dist/versions.js.map +1 -0
  95. package/dist/voice.cjs +2 -0
  96. package/dist/voice.cjs.map +1 -0
  97. package/dist/voice.d.ts +7 -0
  98. package/dist/voice.js +8 -0
  99. package/dist/voice.js.map +1 -0
  100. package/package.json +159 -92
  101. package/dist/noteloom.cjs +0 -3209
  102. package/dist/noteloom.cjs.map +0 -1
  103. package/dist/noteloom.es.js +0 -14622
  104. package/dist/noteloom.es.js.map +0 -1
package/dist/index.js ADDED
@@ -0,0 +1,3983 @@
1
+ import { E as Gt, e as Yt, a as Xt, b as Qt, f as Zt, g as en } from "./shared/VersionHistory-Bg6fufP5.js";
2
+ import { V as Yr, h as Xr, i as Qr, c as Zr, d as ea, j as ta, r as na, u as oa } from "./shared/VersionHistory-Bg6fufP5.js";
3
+ import { g as $, p as tn, t as nn, q as on, a as K, l as V, _ as sn, n as q, m as Ze, j as Ie, A as ce, B as Z, $ as Pe, a0 as et, a1 as rn, I as _e, J as $e, a2 as tt, a3 as nt, T as ot, k as te, o as he, a4 as an, a5 as st, r as rt, a6 as ln, a7 as at, a8 as lt, a9 as it, aa as cn, ab as ct, C as un, c as dn, ac as fn, X as ut, ad as pn, ae as mn, af as hn, ag as bn, ah as gn, ai as kn, aj as yn, ak as dt, x as In, w as vn, y as wn } from "./shared/icons-C1_s0jKK.js";
4
+ import { al as ra, am as aa, E as la, u as ia, an as ca } from "./shared/icons-C1_s0jKK.js";
5
+ import { F as da, H as fa, L as pa, g as ma } from "./shared/fieldRegistry-PjJWXFoB.js";
6
+ import { CollabSession as ba, MESSAGE_TYPE as ga, PeerConnection as ka, createPeriodicTombstoneGC as ya, createWebSocketSignaling as Ia, decodeMessage as va, encodeMessage as wa } from "./collab.js";
7
+ import { g as Ue } from "./shared/indexedDbPersistence-BKlGPFTP.js";
8
+ import { b as Ba, d as Ra, h as Sa, c as Oa, l as xa, e as Ta, a as Ea, i as La, f as Na, s as Ma, j as Aa } from "./shared/indexedDbPersistence-BKlGPFTP.js";
9
+ import { c as Pa, u as _a, a as $a } from "./shared/useServiceWorkerUpdate-BduabXv6.js";
10
+ import { useState as D, useCallback as B, useEffect as _, useSyncExternalStore as ft, useMemo as de, useRef as z } from "react";
11
+ import { jsx as h, jsxs as N, Fragment as X } from "react/jsx-runtime";
12
+ import { C as Cn, r as Bn, c as Rn } from "./shared/CommentThreadCard-Cxf8GwHJ.js";
13
+ import { a as Fa, b as Ka, d as za, e as Ua, f as Va } from "./shared/CommentThreadCard-Cxf8GwHJ.js";
14
+ import { C as Sn } from "./shared/CommentsPanel-BwVVyMOC.js";
15
+ import { u as Wa } from "./shared/CommentsPanel-BwVVyMOC.js";
16
+ import { C as Ja } from "./shared/CommentAvatar-TKqsM8vG.js";
17
+ import { c as On, d as pt, r as Ce, a as xn, u as Tn } from "./shared/index-B9jyyL8u.js";
18
+ import { b as Ya, e as Xa, f as Qa } from "./shared/index-B9jyyL8u.js";
19
+ import { l as En, a as Ln, t as Nn, b as Mn, c as An, e as Dn, d as Pn, f as _n, g as $n, h as Hn, i as Fn, j as Kn, k as zn, m as Un, p as Vn, n as jn, o as Wn, q as qn, r as Jn, s as Gn, u as Yn, v as Oe, w as mt, x as ht, y as Xn, z as Qn, A as Zn, B as W, T as eo, C as to, D as no, E as oo, F as so, G as bt, H as ro, L as ao, I as lo, J as io, K as co, M as uo, N as fo, O as po, S as gt, P as mo, Q as ho, R as bo, U as go, V as ko, W as yo, X as Io, Y as Ve } from "./shared/starter-kit-CY5wzYDf.js";
20
+ import { Z as el, _ as tl, $ as nl, a0 as ol, a1 as sl, a2 as rl, a3 as al, a4 as ll, a5 as il, a6 as cl, a7 as ul, a8 as dl, a9 as fl, aa as pl, ab as ml, ac as hl, ad as bl, ae as gl, af as kl, ag as yl, ah as Il, ai as vl, aj as wl, ak as Cl, al as Bl, am as Rl, an as Sl } from "./shared/starter-kit-CY5wzYDf.js";
21
+ import { e as je, i as vo, c as He, f as ne, r as Q, g as me, h as fe, j as re, s as ae, k as Fe, l as kt } from "./shared/leafBlockFactory-A9eUhSe-.js";
22
+ import { b as xl } from "./shared/leafBlockFactory-A9eUhSe-.js";
23
+ import { createPortal as wo, flushSync as le } from "react-dom";
24
+ import { s as yt, r as Co } from "./shared/serialize-T9Odwx24.js";
25
+ import { c as El } from "./shared/serialize-T9Odwx24.js";
26
+ import { r as ke } from "./shared/VoiceListeningIndicator-BOfVmLK0.js";
27
+ import { V as Nl, a as Ml, l as Al, b as Dl, u as Pl } from "./shared/VoiceListeningIndicator-BOfVmLK0.js";
28
+ import { a as Bo, u as Ro, M as ve } from "./shared/usePopoverEdgeClamp-gmFm0CnI.js";
29
+ const So = 500;
30
+ function Oo(e, t) {
31
+ const n = e ?? "", o = t ?? "";
32
+ let s = 0;
33
+ const r = Math.min(n.length, o.length);
34
+ for (; s < r && n[s] === o[s]; ) s += 1;
35
+ let l = n.length, a = o.length;
36
+ for (; l > s && a > s && n[l - 1] === o[a - 1]; )
37
+ l -= 1, a -= 1;
38
+ return { beforeOffset: l, afterOffset: a };
39
+ }
40
+ function It(e) {
41
+ var t;
42
+ if ((e == null ? void 0 : e.type) === "updateRun" && typeof ((t = e.patch) == null ? void 0 : t.value) == "string")
43
+ return e.patch.value;
44
+ if ((e == null ? void 0 : e.type) === "editRunChars" && typeof e.previousValue == "string")
45
+ return e.previousValue;
46
+ }
47
+ function We(e) {
48
+ var a;
49
+ if (!e.ops.length || !e.inverses.length) return null;
50
+ const t = e.ops[0], n = e.ops[e.ops.length - 1];
51
+ if (t.type !== "updateRun" || n.type !== "updateRun" || t.id !== n.id || typeof ((a = n.patch) == null ? void 0 : a.value) != "string") return null;
52
+ const o = e.inverses[e.inverses.length - 1], s = It(o);
53
+ if (s === void 0) return null;
54
+ const { beforeOffset: r, afterOffset: l } = Oo(s, n.patch.value);
55
+ return { runId: t.id, beforeOffset: r, afterOffset: l };
56
+ }
57
+ function qe(e) {
58
+ const t = [], n = (o) => {
59
+ var s;
60
+ o && ((s = o.block) != null && s.id && t.push(o.block.id), o.blockId && t.push(o.blockId), o.id && t.push(o.id), o.parentId && t.push(o.parentId), o.toParentId && t.push(o.toParentId));
61
+ };
62
+ for (const o of e.ops) n(o);
63
+ for (const o of e.inverses) n(o);
64
+ return [...new Set(t)];
65
+ }
66
+ class xo {
67
+ constructor(t, { idleMs: n = So, trackChanges: o = !1, maxChangeLogSize: s = 500, defaultActorId: r = null } = {}) {
68
+ this.store = t, this.idleMs = n, this.defaultActorId = r, this.undoStack = [], this.redoStack = [], this.currentBatch = null, this.idleTimer = null, this.historyLog = [], this._listeners = /* @__PURE__ */ new Set(), this._undoRedoSnapshot = { canUndo: !1, canRedo: !1 }, this._pendingSelection = null, this._pendingAffectedBlockIds = [], this.trackChanges = o, this.maxChangeLogSize = s, this.changeLog = [];
69
+ }
70
+ /**
71
+ * Appends one entry to the opt-in change log (see `trackChanges`) and
72
+ * drops the oldest entry once over maxChangeLogSize. Only records actual
73
+ * before/after *values* for updateRun/updateBlockProps — both carry a
74
+ * small `patch` object on the op and its inverse already, so the diff is
75
+ * free to capture. Structural ops (insert/remove/move block, ...) are
76
+ * logged as the bare fact (opType/id/actorId/timestamp, before/after
77
+ * left undefined) rather than snapshotting a whole block subtree, which
78
+ * would defeat the point of keeping this lightweight.
79
+ */
80
+ _recordChange(t, n, o) {
81
+ var l;
82
+ if (!this.trackChanges) return;
83
+ const s = t.patch !== void 0 && (n == null ? void 0 : n.patch) !== void 0, r = s ? void 0 : It(n);
84
+ this.changeLog.push({
85
+ opType: t.type,
86
+ id: t.id ?? t.blockId ?? ((l = t.block) == null ? void 0 : l.id),
87
+ before: s ? n.patch : r !== void 0 ? { value: r } : void 0,
88
+ after: s || r !== void 0 ? t.patch : void 0,
89
+ actorId: o.actorId ?? null,
90
+ timestamp: o.timestamp ?? Date.now()
91
+ }), this.changeLog.length > this.maxChangeLogSize && this.changeLog.shift();
92
+ }
93
+ /**
94
+ * The opt-in change log (empty unless constructed with trackChanges:
95
+ * true) — one entry per operation as it was originally applied, each
96
+ * `{opType, id, before, after, actorId, timestamp}`. Same
97
+ * independent-of-undo/redo convention as getHistoryLog: undoing an edit
98
+ * doesn't erase or rewrite its original log entry.
99
+ */
100
+ getChangeLog() {
101
+ return [...this.changeLog];
102
+ }
103
+ /**
104
+ * Where the caret should move to after the undo/redo that was just
105
+ * performed — {runId, offset}, or null when the entry wasn't a plain
106
+ * text-run edit (structural ops) or carried no derivable caret. Read this
107
+ * right after calling undo()/redo(); it's overwritten by the next call.
108
+ */
109
+ getPendingSelection() {
110
+ return this._pendingSelection;
111
+ }
112
+ /**
113
+ * Fallback for structural entries where getPendingSelection() is null —
114
+ * ids (most-specific first) of blocks the just-undone/redone entry
115
+ * touched, so a caller can focus the first one that still exists rather
116
+ * than leaving focus wherever it happened to be (typically stale, since a
117
+ * removed/re-inserted block is a brand-new DOM node). See
118
+ * extractAffectedBlockIds for exactly what's collected.
119
+ */
120
+ getPendingAffectedBlockIds() {
121
+ return this._pendingAffectedBlockIds;
122
+ }
123
+ /**
124
+ * Cached {canUndo, canRedo} snapshot — only a new object when either value
125
+ * actually changed, so useSyncExternalStore's getSnapshot can call this
126
+ * every render without ever seeing a "changed" reference for no reason.
127
+ */
128
+ getUndoRedoSnapshot() {
129
+ const t = this.canUndo(), n = this.canRedo();
130
+ return (this._undoRedoSnapshot.canUndo !== t || this._undoRedoSnapshot.canRedo !== n) && (this._undoRedoSnapshot = { canUndo: t, canRedo: n }), this._undoRedoSnapshot;
131
+ }
132
+ // --- read surface: delegate straight through ---
133
+ getBlock(t) {
134
+ return this.store.getBlock(t);
135
+ }
136
+ getRun(t) {
137
+ return this.store.getRun(t);
138
+ }
139
+ getRootId() {
140
+ return this.store.getRootId();
141
+ }
142
+ getFieldTypes() {
143
+ return this.store.getFieldTypes();
144
+ }
145
+ getFieldType(t) {
146
+ return this.store.getFieldType(t);
147
+ }
148
+ getComments() {
149
+ return this.store.getComments();
150
+ }
151
+ getComment(t) {
152
+ return this.store.getComment(t);
153
+ }
154
+ getPeople() {
155
+ return this.store.getPeople();
156
+ }
157
+ getPerson(t) {
158
+ return this.store.getPerson(t);
159
+ }
160
+ getAllRunIds() {
161
+ return this.store.getAllRunIds();
162
+ }
163
+ subscribe(t, n) {
164
+ return this.store.subscribe(t, n);
165
+ }
166
+ subscribeAll(t) {
167
+ return this.store.subscribeAll(t);
168
+ }
169
+ /**
170
+ * Delegates straight to the store, deliberately outside perform/
171
+ * performBatch — pruning tombstones never changes the visible document
172
+ * (they were already invisible), so it isn't a user-facing edit and has
173
+ * no business on the undo stack.
174
+ */
175
+ getTombstoneCount() {
176
+ return this.store.getTombstoneCount();
177
+ }
178
+ pruneTombstones(t) {
179
+ return this.store.pruneTombstones(t);
180
+ }
181
+ toJSON() {
182
+ return this.store.toJSON();
183
+ }
184
+ // --- write surface ---
185
+ applyOperation(t, n = {}) {
186
+ return this.perform(t, n);
187
+ }
188
+ applyOperations(t, n = {}) {
189
+ return t.map((o) => this.perform(o, n));
190
+ }
191
+ /**
192
+ * Applies several operations as one atomic undo step (e.g. merging a
193
+ * block into its previous sibling is remove-empty-block + reassign-
194
+ * contentIds + delete-shell — three ops that must undo together, not one
195
+ * press per op). Flushes any in-progress typing batch first so the merge
196
+ * doesn't get folded into unrelated coalescing.
197
+ */
198
+ /** Changes the actorId future perform/performBatch calls fall back to when they don't pass their own `meta.actorId`. */
199
+ setDefaultActorId(t) {
200
+ this.defaultActorId = t;
201
+ }
202
+ performBatch(t, n = {}) {
203
+ var l;
204
+ const o = n.actorId ?? this.defaultActorId, s = n.timestamp ?? Date.now();
205
+ this._commitCurrentBatch();
206
+ const r = [];
207
+ for (const a of t) {
208
+ const u = this.store.applyOperation(a);
209
+ r.unshift(u), this.historyLog.push({
210
+ opType: a.type,
211
+ id: a.id ?? a.blockId ?? ((l = a.block) == null ? void 0 : l.id),
212
+ actorId: o,
213
+ timestamp: s
214
+ }), this._recordChange(a, u, { actorId: o, timestamp: s });
215
+ }
216
+ this.redoStack = [], this.undoStack.push({
217
+ ops: [...t],
218
+ inverses: r,
219
+ batchKey: null,
220
+ actorId: o,
221
+ timestamp: s,
222
+ lastTimestamp: s,
223
+ boundaryHit: !0
224
+ }), this._notify();
225
+ }
226
+ perform(t, n = {}) {
227
+ const o = n.actorId ?? this.defaultActorId, s = n.timestamp ?? Date.now(), r = this.store.applyOperation(t);
228
+ return this._record(t, r, { actorId: o, timestamp: s }), r;
229
+ }
230
+ _batchKeyFor(t) {
231
+ return t.type === "updateRun" ? `run:${t.id}` : null;
232
+ }
233
+ _isWordBoundary(t) {
234
+ var o;
235
+ if (t.type !== "updateRun") return !1;
236
+ const n = (o = t.patch) == null ? void 0 : o.value;
237
+ return typeof n != "string" || n.length === 0 ? !1 : /\s/.test(n[n.length - 1]);
238
+ }
239
+ _record(t, n, o) {
240
+ var a;
241
+ this.redoStack = [];
242
+ const s = this._batchKeyFor(t), r = this.currentBatch && o.timestamp - this.currentBatch.lastTimestamp <= this.idleMs;
243
+ this.currentBatch && s !== null && this.currentBatch.batchKey === s && r && !this.currentBatch.boundaryHit ? (this.currentBatch.ops.push(t), this.currentBatch.inverses.unshift(n), this.currentBatch.lastTimestamp = o.timestamp, this._isWordBoundary(t) && (this.currentBatch.boundaryHit = !0)) : (this._commitCurrentBatch(), this.currentBatch = {
244
+ ops: [t],
245
+ inverses: [n],
246
+ batchKey: s,
247
+ actorId: o.actorId,
248
+ timestamp: o.timestamp,
249
+ lastTimestamp: o.timestamp,
250
+ boundaryHit: this._isWordBoundary(t)
251
+ }), this._resetIdleTimer(), this.historyLog.push({
252
+ opType: t.type,
253
+ id: t.id ?? ((a = t.block) == null ? void 0 : a.id),
254
+ actorId: o.actorId,
255
+ timestamp: o.timestamp
256
+ }), this._recordChange(t, n, o), this._notify();
257
+ }
258
+ _resetIdleTimer() {
259
+ this.idleTimer && clearTimeout(this.idleTimer), this.idleTimer = setTimeout(() => {
260
+ this._commitCurrentBatch(), this._notify();
261
+ }, this.idleMs);
262
+ }
263
+ _commitCurrentBatch() {
264
+ this.currentBatch && (this.undoStack.push(this.currentBatch), this.currentBatch = null, this.idleTimer && (clearTimeout(this.idleTimer), this.idleTimer = null));
265
+ }
266
+ /** Force any in-progress coalescing batch to close (e.g. on blur). */
267
+ flush() {
268
+ this._commitCurrentBatch(), this._notify();
269
+ }
270
+ undo() {
271
+ this._commitCurrentBatch();
272
+ const t = this.undoStack.pop();
273
+ if (!t) return !1;
274
+ for (const o of t.inverses) this.store.applyOperation(o);
275
+ this.redoStack.push(t);
276
+ const n = We(t);
277
+ return this._pendingSelection = n ? { runId: n.runId, offset: n.beforeOffset } : null, this._pendingAffectedBlockIds = qe(t), this._notify(), !0;
278
+ }
279
+ redo() {
280
+ const t = this.redoStack.pop();
281
+ if (!t) return !1;
282
+ for (const o of t.ops) this.store.applyOperation(o);
283
+ this.undoStack.push(t);
284
+ const n = We(t);
285
+ return this._pendingSelection = n ? { runId: n.runId, offset: n.afterOffset } : null, this._pendingAffectedBlockIds = qe(t), this._notify(), !0;
286
+ }
287
+ canUndo() {
288
+ return this.undoStack.length > 0 || this.currentBatch !== null;
289
+ }
290
+ canRedo() {
291
+ return this.redoStack.length > 0;
292
+ }
293
+ /** Unbounded (never popped by undo/redo) who/when/what audit trail. */
294
+ getHistoryLog() {
295
+ return [...this.historyLog];
296
+ }
297
+ subscribeToHistory(t) {
298
+ return this._listeners.add(t), () => this._listeners.delete(t);
299
+ }
300
+ _notify() {
301
+ for (const t of this._listeners) t();
302
+ }
303
+ }
304
+ function Er({ scope: e } = {}) {
305
+ const [t, n] = D([]), [o, s] = D(!1), r = B(() => (s(!1), Ue().then((l) => {
306
+ n(e ? l.filter((a) => a.scope === e) : l), s(!0);
307
+ })), [e]);
308
+ return _(() => {
309
+ let l = !1;
310
+ return s(!1), Ue().then((a) => {
311
+ l || (n(e ? a.filter((u) => u.scope === e) : a), s(!0));
312
+ }), () => {
313
+ l = !0;
314
+ };
315
+ }, [e]), { templates: t, isLoaded: o, refresh: r };
316
+ }
317
+ function Lr({ templates: e, onSelect: t, emptyLabel: n = "No templates yet." }) {
318
+ return e.length === 0 ? /* @__PURE__ */ h("p", { className: "be-template-picker-empty", children: n }) : /* @__PURE__ */ h("ul", { className: "be-template-picker", role: "list", children: e.map((o) => /* @__PURE__ */ N("li", { className: "be-template-card", children: [
319
+ /* @__PURE__ */ N("div", { className: "be-template-card-body", children: [
320
+ /* @__PURE__ */ h("span", { className: "be-template-card-name", children: o.name }),
321
+ o.description && /* @__PURE__ */ h("span", { className: "be-template-card-description", children: o.description })
322
+ ] }),
323
+ /* @__PURE__ */ h(
324
+ "button",
325
+ {
326
+ type: "button",
327
+ className: "be-template-card-select",
328
+ onClick: () => t(o),
329
+ children: "Use"
330
+ }
331
+ )
332
+ ] }, o.id)) });
333
+ }
334
+ function Nr(e, { name: t, color: n }) {
335
+ const o = $();
336
+ return e.applyOperation(tn({ id: o, name: t, color: n })), o;
337
+ }
338
+ function Mr(e, t, n) {
339
+ e.applyOperation(on(t, n));
340
+ }
341
+ function Ar(e, t) {
342
+ e.applyOperation(nn(t));
343
+ }
344
+ const To = "$people";
345
+ function Dr() {
346
+ const e = K(), t = B(
347
+ (o) => e.subscribe(To, o),
348
+ [e]
349
+ ), n = B(() => e.getPeople(), [e]);
350
+ return ft(t, n);
351
+ }
352
+ class Eo {
353
+ constructor() {
354
+ this._types = /* @__PURE__ */ new Map();
355
+ }
356
+ register(t, n) {
357
+ this._types.set(t, n);
358
+ }
359
+ get(t) {
360
+ return this._types.get(t);
361
+ }
362
+ isLeaf(t) {
363
+ var n;
364
+ return !!((n = this._types.get(t)) != null && n.isLeaf);
365
+ }
366
+ listSlashCommands() {
367
+ const t = [];
368
+ for (const n of this._types.values())
369
+ n.slashCommand && t.push(n.slashCommand), n.slashCommands && t.push(...n.slashCommands);
370
+ return t;
371
+ }
372
+ listHtmlMatchers() {
373
+ return [...this._types.values()].filter((t) => t.fromHTML);
374
+ }
375
+ }
376
+ function Lo() {
377
+ return new Eo();
378
+ }
379
+ class No {
380
+ constructor() {
381
+ this._types = /* @__PURE__ */ new Map();
382
+ }
383
+ register(t, n) {
384
+ this._types.set(t, n);
385
+ }
386
+ /** Drops a registered type — e.g. deleting a user-created custom field type. */
387
+ unregister(t) {
388
+ this._types.delete(t);
389
+ }
390
+ get(t) {
391
+ return this._types.get(t);
392
+ }
393
+ listHtmlMatchers() {
394
+ return [...this._types.values()].filter((t) => t.fromHTML);
395
+ }
396
+ listSlashCommands() {
397
+ const t = [];
398
+ for (const n of this._types.values())
399
+ n.slashCommand && t.push(n.slashCommand), n.slashCommands && t.push(...n.slashCommands);
400
+ return t;
401
+ }
402
+ /** Same shape as listSlashCommands, sourced from atCommand/atCommands instead — see useAtMenuTrigger. */
403
+ listAtCommands() {
404
+ const t = [];
405
+ for (const n of this._types.values())
406
+ n.atCommand && t.push(n.atCommand), n.atCommands && t.push(...n.atCommands);
407
+ return t;
408
+ }
409
+ }
410
+ function Mo() {
411
+ return new No();
412
+ }
413
+ function Ao(e) {
414
+ Do(e, {
415
+ paragraph: Vn,
416
+ heading: Un,
417
+ listItem: zn,
418
+ ...Po,
419
+ ..._o,
420
+ divider: Kn,
421
+ callout: Fn,
422
+ blockquote: Hn,
423
+ code: $n,
424
+ toggleHeading: _n,
425
+ button: Pn,
426
+ embed: Dn,
427
+ canvas: On
428
+ });
429
+ }
430
+ function Do(e, t) {
431
+ for (const [n, o] of Object.entries(t))
432
+ e.register(n, o);
433
+ }
434
+ const Po = {
435
+ table: An,
436
+ tableRow: Mn,
437
+ tableCell: Nn
438
+ }, _o = {
439
+ layout: Ln,
440
+ layoutColumn: En
441
+ };
442
+ function $o(e) {
443
+ Ho(e, {
444
+ select: Gn,
445
+ date: Jn,
446
+ checkbox: qn,
447
+ ...Fo,
448
+ emoji: Wn
449
+ });
450
+ }
451
+ function Ho(e, t) {
452
+ for (const [n, o] of Object.entries(t))
453
+ e.register(n, o);
454
+ }
455
+ const Fo = { tableSelect: jn }, xe = {
456
+ '"': { open: "“", close: "”" },
457
+ "'": { open: "‘", close: "’" }
458
+ };
459
+ function Ko(e, t) {
460
+ const n = xe[e];
461
+ return t === void 0 || /[\s([{“‘]/.test(t) ? n.open : n.close;
462
+ }
463
+ function vt(e) {
464
+ return e.inputType !== "insertText" || !e.data || e.data.length !== 1 ? null : e.data;
465
+ }
466
+ function ue(e, t, n) {
467
+ var o;
468
+ return ((o = e.getBlock(t)) == null ? void 0 : o.type) === n;
469
+ }
470
+ function Pr() {
471
+ return pt({
472
+ name: "smart-quotes",
473
+ onBeforeInput(e, t) {
474
+ const n = vt(t);
475
+ if (!n || !xe[n]) return !1;
476
+ const o = xe[n], s = e.getSelection();
477
+ if (s) {
478
+ if (ue(e, s.blockId, "code")) return !1;
479
+ const i = e.getRun(s.runId);
480
+ if (!i || i.type !== "text") return !1;
481
+ const c = i.value ?? "", d = c.slice(0, s.startOffset) + o.open + c.slice(s.startOffset, s.endOffset) + o.close + c.slice(s.endOffset);
482
+ return e.applyOperation(V(i.id, { value: d })), e.setCaret(i.id, s.endOffset + 2), !0;
483
+ }
484
+ const r = e.getCaret();
485
+ if (!r || ue(e, r.blockId, "code")) return !1;
486
+ const l = e.getRun(r.runId);
487
+ if (!l || l.type !== "text") return !1;
488
+ const a = l.value ?? "", u = Ko(n, a[r.offset - 1]);
489
+ return e.applyOperation(
490
+ V(l.id, {
491
+ value: a.slice(0, r.offset) + u + a.slice(r.offset)
492
+ })
493
+ ), e.setCaret(l.id, r.offset + 1), !0;
494
+ }
495
+ });
496
+ }
497
+ const wt = { "(": ")", "[": "]", "{": "}" }, zo = new Set(Object.values(wt));
498
+ function _r() {
499
+ return pt({
500
+ name: "auto-pair-brackets",
501
+ onBeforeInput(e, t) {
502
+ const n = vt(t);
503
+ if (!n) return !1;
504
+ const o = wt[n];
505
+ if (o) {
506
+ const s = e.getSelection();
507
+ if (s) {
508
+ if (ue(e, s.blockId, "code")) return !1;
509
+ const u = e.getRun(s.runId);
510
+ if (!u || u.type !== "text") return !1;
511
+ const i = u.value ?? "", c = i.slice(0, s.startOffset) + n + i.slice(s.startOffset, s.endOffset) + o + i.slice(s.endOffset);
512
+ return e.applyOperation(V(u.id, { value: c })), e.setCaret(u.id, s.endOffset + 2), !0;
513
+ }
514
+ const r = e.getCaret();
515
+ if (!r || ue(e, r.blockId, "code")) return !1;
516
+ const l = e.getRun(r.runId);
517
+ if (!l || l.type !== "text") return !1;
518
+ const a = l.value ?? "";
519
+ return e.applyOperation(
520
+ V(l.id, {
521
+ value: a.slice(0, r.offset) + n + o + a.slice(r.offset)
522
+ })
523
+ ), e.setCaret(l.id, r.offset + 1), !0;
524
+ }
525
+ if (zo.has(n)) {
526
+ const s = e.getCaret();
527
+ if (!s || ue(e, s.blockId, "code")) return !1;
528
+ const r = e.getRun(s.runId);
529
+ if (!r || r.type !== "text") return !1;
530
+ if ((r.value ?? "")[s.offset] === n)
531
+ return e.setCaret(r.id, s.offset + 1), !0;
532
+ }
533
+ return !1;
534
+ }
535
+ });
536
+ }
537
+ const Ct = {
538
+ heading: ["level"],
539
+ listItem: ["ordered", "checked", "collapsed"],
540
+ toggleHeading: ["level", "collapsed"],
541
+ code: ["language"],
542
+ button: ["href", "color", "customAttrs"],
543
+ embed: ["kind", "src", "name", "alt", "mimeType", "align", "width"],
544
+ callout: ["icon"]
545
+ }, Bt = /* @__PURE__ */ new Set(["listItem", "toggleHeading"]), Rt = /* @__PURE__ */ new Set(["divider", "embed"]);
546
+ function St(e, t, n, o) {
547
+ var a, u, i;
548
+ const s = n.type, r = {};
549
+ for (const c of Ct[s] ?? [])
550
+ ((a = n.props) == null ? void 0 : a[c]) !== void 0 && (r[c] = n.props[c]);
551
+ if (s === "table") {
552
+ const c = n.contentIds[0] && e.getBlock(n.contentIds[0]);
553
+ return r.columns = Yn(n, ((u = c == null ? void 0 : c.contentIds) == null ? void 0 : u.length) ?? 0), r.rows = n.contentIds.map((d) => e.getBlock(d).contentIds.map((m) => {
554
+ const f = e.getBlock(m);
555
+ return Ce(
556
+ f.contentIds.map((b) => e.getRun(b)),
557
+ o
558
+ );
559
+ })), { id: n.id, type: s, data: r };
560
+ }
561
+ if (Bt.has(s)) {
562
+ const c = ((i = n.props) == null ? void 0 : i.titleRunIds) ?? [];
563
+ r.text = Ce(
564
+ c.map((d) => e.getRun(d)),
565
+ o
566
+ );
567
+ } else t.isLeaf(s) && !Rt.has(s) && (r.text = Ce(
568
+ n.contentIds.map((c) => e.getRun(c)),
569
+ o
570
+ ));
571
+ const l = { id: n.id, type: s, data: r };
572
+ return t.isLeaf(s) || (l.children = n.contentIds.map(
573
+ (c) => St(e, t, e.getBlock(c), o)
574
+ )), l;
575
+ }
576
+ function Ot(e, t, n, { pretty: o = !0 } = {}) {
577
+ const s = { store: e, registry: t, inlineRegistry: n }, l = e.getBlock(e.getRootId()).contentIds.map((a) => St(e, t, e.getBlock(a), s));
578
+ return JSON.stringify({ version: 1, blocks: l }, null, o ? 2 : 0);
579
+ }
580
+ function Te(e, t) {
581
+ const n = new DOMParser().parseFromString(`<div>${e ?? ""}</div>`, "text/html");
582
+ return Oe(n.body.firstChild, t);
583
+ }
584
+ function Uo(e, t, n, o, s) {
585
+ const { id: r = $(), data: l = {} } = e, a = (l.rows ?? []).map((i) => {
586
+ const c = $(), d = i.map((p) => {
587
+ const m = $(), f = Te(p, s);
588
+ return o.push(...f), n.push({
589
+ id: m,
590
+ type: "tableCell",
591
+ parentId: c,
592
+ contentIds: f.map((b) => b.id),
593
+ props: {}
594
+ }), m;
595
+ });
596
+ return n.push({ id: c, type: "tableRow", parentId: t, contentIds: d, props: {} }), c;
597
+ }), u = {
598
+ id: r,
599
+ type: "table",
600
+ parentId: t,
601
+ contentIds: a,
602
+ props: { columns: l.columns ?? [] }
603
+ };
604
+ return n.push(u), u;
605
+ }
606
+ function Ee(e, t, n, o, s, r) {
607
+ const { id: l = $(), type: a, data: u = {}, children: i = [] } = e;
608
+ if (a === "table") return Uo(e, t, s, r, o);
609
+ const c = {};
610
+ for (const p of Ct[a] ?? [])
611
+ u[p] !== void 0 && (c[p] = u[p]);
612
+ const d = { id: l, type: a, parentId: t, contentIds: [], props: c };
613
+ if (s.push(d), Bt.has(a)) {
614
+ const p = Te(u.text, o);
615
+ r.push(...p), d.props.titleRunIds = p.map((m) => m.id), d.contentIds = i.map(
616
+ (m) => Ee(m, l, n, o, s, r).id
617
+ );
618
+ } else if (n.isLeaf(a)) {
619
+ if (!Rt.has(a)) {
620
+ const p = Te(u.text, o);
621
+ r.push(...p), d.contentIds = p.map((m) => m.id);
622
+ }
623
+ } else
624
+ d.contentIds = i.map(
625
+ (p) => Ee(p, l, n, o, s, r).id
626
+ );
627
+ return d;
628
+ }
629
+ function Vo(e) {
630
+ return !!e && typeof e == "object" && Array.isArray(e.blocks) && e.rootId === void 0 && e.runs === void 0;
631
+ }
632
+ function jo(e, t, n) {
633
+ const o = typeof e == "string" ? JSON.parse(e) : e, s = { registry: t, inlineRegistry: n }, r = $(), l = [], a = [], u = (o.blocks ?? []).map(
634
+ (i) => Ee(i, r, t, s, l, a).id
635
+ );
636
+ return l.push({ id: r, type: "page", parentId: null, contentIds: u, props: {} }), { rootId: r, blocks: l, runs: a };
637
+ }
638
+ function Wo() {
639
+ const e = "root", t = $(), n = $();
640
+ return {
641
+ rootId: e,
642
+ blocks: [
643
+ { id: e, type: "page", parentId: null, contentIds: [t], props: {} },
644
+ { id: t, type: "paragraph", parentId: e, contentIds: [n], props: {} }
645
+ ],
646
+ runs: [{ id: n, type: "text", value: "", marks: {} }]
647
+ };
648
+ }
649
+ function $r({
650
+ doc: e,
651
+ history: t = !0,
652
+ currentUserId: n = null,
653
+ extensions: o,
654
+ registerBlocks: s,
655
+ registerInlineTypes: r
656
+ } = {}) {
657
+ return de(() => {
658
+ const l = Lo(), a = Mo();
659
+ o != null && xn(o, { registry: l, inlineRegistry: a }), s ? s(l) : o == null && Ao(l), r ? r(a) : o == null && $o(a);
660
+ const u = e == null ? Wo() : Vo(e) ? jo(e, l, a) : e, i = new Gt(u), c = t ? new xo(i, { defaultActorId: n }) : i;
661
+ return {
662
+ store: c,
663
+ registry: l,
664
+ inlineRegistry: a,
665
+ // Flattened extension list — <NoteloomEditor> feeds this to
666
+ // useExtensionBehaviors for the keymap/onBeforeInput/onPaste/setup half.
667
+ // Block/inline definitions are already registered above; they're kept in
668
+ // the list too but ignored there (no behavior fields).
669
+ extensions: o != null ? o.flat(1 / 0) : [],
670
+ // Read the live document back out. 'simple' (default) is the canonical
671
+ // interchange format; 'internal' is the normalized engine graph.
672
+ toJSON: ({ format: d = "simple" } = {}) => d === "internal" ? c.toJSON() : JSON.parse(Ot(c, l, a))
673
+ };
674
+ }, []);
675
+ }
676
+ function qo({ minHeight: e = 180, className: t = "be-trailing-space" }) {
677
+ const n = K(), [o] = sn(), s = B(() => {
678
+ var i;
679
+ if (o) return;
680
+ const r = n.getRootId(), l = n.getBlock(r), a = (i = l == null ? void 0 : l.contentIds) == null ? void 0 : i[l.contentIds.length - 1];
681
+ if (!a) {
682
+ const c = mt(n);
683
+ c && je(n, c);
684
+ return;
685
+ }
686
+ const u = n.getBlock(a);
687
+ (u == null ? void 0 : u.type) === "paragraph" ? je(n, a) : vo(n, a, He("paragraph"));
688
+ }, [n, o]);
689
+ return /* @__PURE__ */ h("div", { className: t, style: { minHeight: e }, onClick: s });
690
+ }
691
+ async function Je(e, t, n, o) {
692
+ var l, a, u;
693
+ const { html: s, text: r } = yt(e, t, o, n);
694
+ if (typeof ClipboardItem < "u" && ((l = navigator.clipboard) != null && l.write)) {
695
+ await navigator.clipboard.write([
696
+ new ClipboardItem({
697
+ "text/plain": new Blob([r], { type: "text/plain" }),
698
+ "text/html": new Blob([s], { type: "text/html" })
699
+ })
700
+ ]);
701
+ return;
702
+ }
703
+ await ((u = (a = navigator.clipboard) == null ? void 0 : a.writeText) == null ? void 0 : u.call(a, r));
704
+ }
705
+ function Ke(e, t) {
706
+ if (typeof e.performBatch == "function") e.performBatch(t);
707
+ else for (const n of t) e.applyOperation(n);
708
+ }
709
+ function be(e, t) {
710
+ t.length !== 0 && Ke(
711
+ e,
712
+ t.map((n) => q(n))
713
+ );
714
+ }
715
+ function Jo(e, t) {
716
+ if (t.length === 0) return !1;
717
+ const n = e.getBlock(t[0]);
718
+ if (!n) return !1;
719
+ const o = e.getBlock(n.parentId);
720
+ if (!o) return !1;
721
+ const s = o.contentIds.indexOf(t[0]), r = o.contentIds.indexOf(t[t.length - 1]);
722
+ if (s <= 0) return !1;
723
+ const l = o.contentIds[s - 1];
724
+ return e.applyOperation(Ze(l, n.parentId, r)), !0;
725
+ }
726
+ function Go(e, t) {
727
+ if (t.length === 0) return !1;
728
+ const n = e.getBlock(t[0]);
729
+ if (!n) return !1;
730
+ const o = e.getBlock(n.parentId);
731
+ if (!o) return !1;
732
+ const s = o.contentIds.indexOf(t[0]), r = o.contentIds.indexOf(t[t.length - 1]);
733
+ if (r === -1 || r >= o.contentIds.length - 1) return !1;
734
+ const l = o.contentIds[r + 1];
735
+ return e.applyOperation(Ze(l, n.parentId, s)), !0;
736
+ }
737
+ function Yo(e, t) {
738
+ return t.length > 0 && t.every((n) => {
739
+ var o, s;
740
+ return !!((s = (o = e.getBlock(n)) == null ? void 0 : o.props) != null && s.hidden);
741
+ });
742
+ }
743
+ function Xo(e, t, n) {
744
+ t.length !== 0 && Ke(
745
+ e,
746
+ t.map((o) => Ie(o, { hidden: n }))
747
+ );
748
+ }
749
+ function Qo(e, t, n, o) {
750
+ const s = n.filter((l) => {
751
+ var a;
752
+ return ht((a = e.getBlock(l)) == null ? void 0 : a.type);
753
+ });
754
+ if (s.length === 0) return;
755
+ const r = s.flatMap((l) => Xn(e, t, l, o).ops);
756
+ Ke(e, r);
757
+ }
758
+ function Hr(e, t) {
759
+ if (t.length === 0) return [];
760
+ const n = e.getBlock(t[0]), o = n && e.getBlock(n.parentId);
761
+ if (!o) return t;
762
+ const s = new Set(t);
763
+ return o.contentIds.filter((r) => s.has(r));
764
+ }
765
+ function Zo() {
766
+ const e = K(), t = ce(), n = Z(), [o, s] = Pe(), [r, l] = D(null), a = z(null), u = z(null), i = o.length > 0, c = Qn(
767
+ a,
768
+ i,
769
+ (r == null ? void 0 : r.bottom) != null ? r.bottom + 4 : null,
770
+ r == null ? void 0 : r.left
771
+ ), d = B(() => s([]), [s]);
772
+ Zn(a, i, d, void 0), _(() => {
773
+ if (!i) {
774
+ l(null);
775
+ return;
776
+ }
777
+ const S = () => {
778
+ const E = o[o.length - 1], x = document.querySelector(`[data-block-row-id="${E}"]`);
779
+ l((x == null ? void 0 : x.getBoundingClientRect()) ?? null);
780
+ };
781
+ return S(), window.addEventListener("scroll", S, !0), window.addEventListener("resize", S), () => {
782
+ window.removeEventListener("scroll", S, !0), window.removeEventListener("resize", S);
783
+ };
784
+ }, [i, o]), _(() => {
785
+ if (!i) return;
786
+ const S = (x) => {
787
+ var R, O, v, L;
788
+ (R = a.current) != null && R.contains(x.target) || (O = u.current) != null && O.contains(x.target) || (L = (v = x.target).closest) != null && L.call(v, ".be-block-gutter") || d();
789
+ }, E = (x) => {
790
+ x.key === "Escape" ? d() : (x.key === "Delete" || x.key === "Backspace") && (x.preventDefault(), be(e, o), d());
791
+ };
792
+ return document.addEventListener("mousedown", S), document.addEventListener("keydown", E), () => {
793
+ document.removeEventListener("mousedown", S), document.removeEventListener("keydown", E);
794
+ };
795
+ }, [i, e, o, d]);
796
+ const p = (S) => S === 1 ? "block" : "blocks", m = B(() => {
797
+ Je(e, t, n, o), W(`${o.length} ${p(o.length)} copied`), d();
798
+ }, [e, t, n, o, d]), f = B(async () => {
799
+ await Je(e, t, n, o);
800
+ const S = o.length;
801
+ be(e, o), W(`${S} ${p(S)} cut`), d();
802
+ }, [e, t, n, o, d]), b = B(() => {
803
+ const S = o.length;
804
+ be(e, o), W(`${S} ${p(S)} deleted`), d();
805
+ }, [e, o, d]), k = B(() => {
806
+ Jo(e, o) && W(`${o.length} ${p(o.length)} moved up`), d();
807
+ }, [e, o, d]), y = B(() => {
808
+ Go(e, o) && W(`${o.length} ${p(o.length)} moved down`), d();
809
+ }, [e, o, d]), g = Yo(e, o), I = B(() => {
810
+ Xo(e, o, !g), W(
811
+ g ? `${o.length} ${p(o.length)} shown in preview` : `${o.length} ${p(o.length)} hidden in preview`
812
+ ), d();
813
+ }, [e, o, g, d]), C = o.some(
814
+ (S) => {
815
+ var E;
816
+ return ht((E = e.getBlock(S)) == null ? void 0 : E.type);
817
+ }
818
+ ), w = B(
819
+ (S) => {
820
+ const E = o.length;
821
+ Qo(e, t, o, S), W(`${E} ${p(E)} turned into ${S.label}`), d();
822
+ },
823
+ [e, t, o, d]
824
+ );
825
+ return !i || !c ? null : wo(
826
+ /* @__PURE__ */ N(
827
+ "div",
828
+ {
829
+ ref: a,
830
+ role: "menu",
831
+ "aria-label": "Selected blocks options",
832
+ className: "be-block-range-menu",
833
+ style: { position: "fixed", top: c.top, left: c.left },
834
+ children: [
835
+ /* @__PURE__ */ N(
836
+ "button",
837
+ {
838
+ type: "button",
839
+ role: "menuitem",
840
+ className: "be-block-range-menu-item",
841
+ onClick: m,
842
+ children: [
843
+ /* @__PURE__ */ h(et, { size: 15 }),
844
+ " Copy"
845
+ ]
846
+ }
847
+ ),
848
+ /* @__PURE__ */ N(
849
+ "button",
850
+ {
851
+ type: "button",
852
+ role: "menuitem",
853
+ className: "be-block-range-menu-item",
854
+ onClick: f,
855
+ children: [
856
+ /* @__PURE__ */ h(rn, { size: 15 }),
857
+ " Cut"
858
+ ]
859
+ }
860
+ ),
861
+ /* @__PURE__ */ N(
862
+ "button",
863
+ {
864
+ type: "button",
865
+ role: "menuitem",
866
+ className: "be-block-range-menu-item",
867
+ onClick: k,
868
+ children: [
869
+ /* @__PURE__ */ h(_e, { size: 15 }),
870
+ " Move up"
871
+ ]
872
+ }
873
+ ),
874
+ /* @__PURE__ */ N(
875
+ "button",
876
+ {
877
+ type: "button",
878
+ role: "menuitem",
879
+ className: "be-block-range-menu-item",
880
+ onClick: y,
881
+ children: [
882
+ /* @__PURE__ */ h($e, { size: 15 }),
883
+ " Move down"
884
+ ]
885
+ }
886
+ ),
887
+ /* @__PURE__ */ N(
888
+ "button",
889
+ {
890
+ type: "button",
891
+ role: "menuitem",
892
+ className: "be-block-range-menu-item",
893
+ onClick: I,
894
+ children: [
895
+ g ? /* @__PURE__ */ h(tt, { size: 15 }) : /* @__PURE__ */ h(nt, { size: 15 }),
896
+ g ? "Show in preview" : "Hide in preview"
897
+ ]
898
+ }
899
+ ),
900
+ C && /* @__PURE__ */ h(
901
+ eo,
902
+ {
903
+ onSelect: w,
904
+ onClose: () => {
905
+ },
906
+ containerRef: u,
907
+ menuClassName: "be-block-range-menu",
908
+ itemClassName: "be-block-range-menu-item"
909
+ }
910
+ ),
911
+ /* @__PURE__ */ N(
912
+ "button",
913
+ {
914
+ type: "button",
915
+ role: "menuitem",
916
+ className: "be-block-range-menu-item be-block-range-menu-item-danger",
917
+ onClick: b,
918
+ children: [
919
+ /* @__PURE__ */ h(ot, { size: 15 }),
920
+ " Delete"
921
+ ]
922
+ }
923
+ )
924
+ ]
925
+ }
926
+ ),
927
+ document.body
928
+ );
929
+ }
930
+ const Le = "application/x-block-editor-blocks+json";
931
+ function xt(e) {
932
+ return e.split(/\r\n|\r|\n/).filter((t) => t.length > 0).map((t) => {
933
+ const n = $();
934
+ return {
935
+ block: { id: $(), type: "paragraph", parentId: null, contentIds: [n], props: {} },
936
+ runs: [{ id: n, type: "text", value: t, marks: {} }]
937
+ };
938
+ });
939
+ }
940
+ function es(e, t, n) {
941
+ const o = new DOMParser().parseFromString(e, "text/html"), s = { registry: t, inlineRegistry: n }, r = t.listHtmlMatchers(), l = [], a = (i) => {
942
+ var p;
943
+ const c = i.tagName === "OL", d = [];
944
+ for (const m of i.children) {
945
+ if (m.tagName !== "LI") continue;
946
+ const f = (p = t.get("listItem")) == null ? void 0 : p.fromHTML(m, s);
947
+ f && (f.block.props.ordered = c, d.push(f));
948
+ }
949
+ return d;
950
+ }, u = (i) => {
951
+ var d;
952
+ const c = Array.from(i.children).filter((p) => p.tagName === "P");
953
+ if (c.length === 0) {
954
+ const p = (d = t.get("blockquote")) == null ? void 0 : d.fromHTML(i, s);
955
+ return p ? [p] : [];
956
+ }
957
+ return c.map((p) => {
958
+ const m = Oe(p, s);
959
+ return {
960
+ block: {
961
+ id: $(),
962
+ type: "blockquote",
963
+ parentId: null,
964
+ contentIds: m.map((f) => f.id),
965
+ props: {}
966
+ },
967
+ runs: m
968
+ };
969
+ });
970
+ };
971
+ for (const i of o.body.childNodes) {
972
+ if (i.nodeType === 3) {
973
+ const d = i.textContent.trim();
974
+ d && l.push(...xt(d));
975
+ continue;
976
+ }
977
+ if (i.nodeType !== 1) continue;
978
+ if (i.tagName === "UL" || i.tagName === "OL") {
979
+ l.push(...a(i));
980
+ continue;
981
+ }
982
+ if (i.tagName === "BLOCKQUOTE") {
983
+ l.push(...u(i));
984
+ continue;
985
+ }
986
+ let c = null;
987
+ for (const d of r) {
988
+ const p = d.fromHTML(i, s);
989
+ if (p) {
990
+ c = p;
991
+ break;
992
+ }
993
+ }
994
+ if (c)
995
+ l.push(c);
996
+ else if (i.textContent.trim()) {
997
+ const d = Oe(i, s);
998
+ l.push({
999
+ block: {
1000
+ id: $(),
1001
+ type: "paragraph",
1002
+ parentId: null,
1003
+ contentIds: d.map((p) => p.id),
1004
+ props: {}
1005
+ },
1006
+ runs: d
1007
+ });
1008
+ }
1009
+ }
1010
+ return l;
1011
+ }
1012
+ function ts(e, t, n) {
1013
+ const o = e.types ?? [];
1014
+ if (o.includes(Le)) {
1015
+ const r = e.getData(Le);
1016
+ if (r) return ns(r);
1017
+ }
1018
+ if (o.includes("text/html")) {
1019
+ const r = e.getData("text/html");
1020
+ if (r) return es(r, t, n);
1021
+ }
1022
+ const s = e.getData("text/plain") ?? "";
1023
+ return xt(s);
1024
+ }
1025
+ function ns(e) {
1026
+ return JSON.parse(e).blocks.map((n) => Co(n));
1027
+ }
1028
+ function Ne(e, t) {
1029
+ var o;
1030
+ const n = e.getBlock(t);
1031
+ return ((o = n.props) == null ? void 0 : o.titleRunIds) ?? n.contentIds;
1032
+ }
1033
+ function ge() {
1034
+ return { id: $(), type: "text", value: "", marks: {} };
1035
+ }
1036
+ function Me(e, t) {
1037
+ if (typeof e.performBatch == "function") e.performBatch(t);
1038
+ else for (const n of t) e.applyOperation(n);
1039
+ }
1040
+ function Tt(e, t, n) {
1041
+ const { startRunId: o, startOffset: s, endRunId: r, endOffset: l } = n, a = Ne(e, t), u = a.indexOf(o), i = a.indexOf(r);
1042
+ if (u === -1 || i === -1) return null;
1043
+ const [c, d] = u <= i ? [u, i] : [i, u], p = u <= i ? s : l, m = u <= i ? l : s, f = a.slice(0, c).map((w) => e.getRun(w)), b = a.slice(d + 1).map((w) => e.getRun(w)), k = a.slice(c, d + 1).map((w) => e.getRun(w)), y = [];
1044
+ let g = null, I = 0;
1045
+ if (c === d) {
1046
+ const w = k[0];
1047
+ if (w.type === "text") {
1048
+ const S = Math.max(0, Math.min(p, m)), E = Math.min(w.value.length, Math.max(p, m)), x = { ...w, value: w.value.slice(0, S) + w.value.slice(E) };
1049
+ y.push(x), g = x.id, I = S;
1050
+ }
1051
+ } else
1052
+ k.forEach((w, S) => {
1053
+ if (w.type !== "text") return;
1054
+ const E = S === 0, x = S === k.length - 1, R = E ? w.value.slice(0, p) : "";
1055
+ if (E && R) {
1056
+ const O = { ...w, value: R };
1057
+ y.push(O), g = O.id, I = R.length;
1058
+ }
1059
+ if (x && !E) {
1060
+ const O = w.value.slice(m);
1061
+ if (O) {
1062
+ const v = { id: $(), type: "text", value: O, marks: w.marks };
1063
+ y.push(v), g === null && (g = v.id, I = 0);
1064
+ }
1065
+ }
1066
+ });
1067
+ let C = [...f, ...y, ...b];
1068
+ if (C.length === 0) {
1069
+ const w = ge();
1070
+ C = [w], g = w.id, I = 0;
1071
+ } else if (g === null) {
1072
+ const w = f[f.length - 1];
1073
+ w ? (g = w.id, I = w.type === "text" ? w.value.length : 0) : b[0] && (g = b[0].id, I = 0);
1074
+ }
1075
+ return e.applyOperation(he(t, C)), { blockId: t, runId: g, offset: I };
1076
+ }
1077
+ function Et(e, t) {
1078
+ const { blockIds: n, startBlockId: o, startRunId: s, startOffset: r, endBlockId: l, endRunId: a, endOffset: u } = t;
1079
+ if (!n || n.length === 0) return null;
1080
+ const i = n.indexOf(o), c = n.indexOf(l);
1081
+ if (i === -1 || c === -1) return null;
1082
+ const [d, p] = i <= c ? [i, c] : [c, i], m = i <= c, f = m ? s : a, b = m ? r : u, k = m ? a : s, y = m ? u : r;
1083
+ if (d === p)
1084
+ return Tt(e, n[d], {
1085
+ startRunId: f,
1086
+ startOffset: b,
1087
+ endRunId: k,
1088
+ endOffset: y
1089
+ });
1090
+ const g = n[d], I = n[p], C = e.getBlock(g), w = e.getBlock(I), S = Ne(e, g), E = S.indexOf(f), x = S.slice(0, E).map((U) => e.getRun(U)), R = e.getRun(f), O = R.type === "text" && b > 0 ? { ...R, value: R.value.slice(0, b) } : null, v = Ne(e, I), L = v.indexOf(k), M = v.slice(L + 1).map((U) => e.getRun(U)), A = e.getRun(k), H = A.type === "text" && y < A.value.length ? { id: $(), type: "text", value: A.value.slice(y), marks: A.marks } : null, F = [
1091
+ ...x,
1092
+ ...O ? [O] : []
1093
+ ], T = [...H ? [H] : [], ...M], P = [];
1094
+ for (let U = d + 1; U < p; U += 1) P.push(q(n[U]));
1095
+ const j = to(C.type, w.type), ee = e.getBlock(C.parentId), Wt = p - d - 1 + (j ? 1 : 0), qt = ee && ee.contentIds.length - Wt === 1;
1096
+ let J, G, we;
1097
+ if (j) {
1098
+ const U = [...F, ...T];
1099
+ if (U.length === 0 && qt && C.type !== "paragraph") {
1100
+ const { block: Y, runs: Jt } = He("paragraph")(ee.id);
1101
+ return P.push({
1102
+ type: "insertBlock",
1103
+ block: Y,
1104
+ parentId: ee.id,
1105
+ index: 0,
1106
+ subtree: { blocks: [Y], runs: Jt }
1107
+ }), P.push(q(g)), P.push(q(I)), Me(e, P), { blockId: Y.id, runId: Y.contentIds[0], offset: 0 };
1108
+ }
1109
+ const oe = U.length ? U : [ge()];
1110
+ if (P.push(he(g, oe)), P.push(q(I)), we = g, O)
1111
+ J = O.id, G = O.value.length;
1112
+ else if (x.length) {
1113
+ const Y = x[x.length - 1];
1114
+ J = Y.id, G = Y.type === "text" ? Y.value.length : 0;
1115
+ } else H ? (J = H.id, G = 0) : M.length ? (J = M[0].id, G = 0) : (J = oe[0].id, G = 0);
1116
+ } else {
1117
+ const U = F.length ? F : [ge()];
1118
+ if (P.push(he(g, U)), P.push(he(I, T.length ? T : [ge()])), we = g, O)
1119
+ J = O.id, G = O.value.length;
1120
+ else if (x.length) {
1121
+ const oe = x[x.length - 1];
1122
+ J = oe.id, G = oe.type === "text" ? oe.value.length : 0;
1123
+ } else
1124
+ J = U[0].id, G = 0;
1125
+ }
1126
+ return Me(e, P), { blockId: we, runId: J, offset: G };
1127
+ }
1128
+ function Ae(e, t = "") {
1129
+ var a;
1130
+ const n = e.getRootId(), o = ((a = e.getBlock(n)) == null ? void 0 : a.contentIds) ?? [];
1131
+ if (o.length === 0) return null;
1132
+ const s = o.map((u) => q(u)), { block: r, runs: l } = He("paragraph")(n);
1133
+ return t && (l[0].value = t), s.push(te(r, n, 0, { blocks: [r], runs: l })), Me(e, s), {
1134
+ blockId: r.id,
1135
+ runId: r.contentIds[0],
1136
+ offset: t.length
1137
+ };
1138
+ }
1139
+ function Be(e) {
1140
+ return (e == null ? void 0 : e.tagName) === "INPUT" || (e == null ? void 0 : e.tagName) === "TEXTAREA";
1141
+ }
1142
+ function ye(e) {
1143
+ var n;
1144
+ let t = (e == null ? void 0 : e.nodeType) === 1 ? e : e == null ? void 0 : e.parentElement;
1145
+ for (; t && typeof t.hasAttribute == "function" && !t.hasAttribute("data-block-id"); )
1146
+ t = t.parentElement;
1147
+ return ((n = t == null ? void 0 : t.getAttribute) == null ? void 0 : n.call(t, "data-block-id")) ?? null;
1148
+ }
1149
+ function os(e) {
1150
+ var d;
1151
+ const t = (d = window.getSelection) == null ? void 0 : d.call(window);
1152
+ if (!t || t.rangeCount === 0) return [];
1153
+ const n = ye(t.anchorNode), o = ye(t.focusNode);
1154
+ if (!n) return [];
1155
+ if (!o || n === o) return [n];
1156
+ const s = e.getBlock(n), r = s && e.getBlock(s.parentId);
1157
+ if (!r) return [n];
1158
+ const l = r.contentIds, a = l.indexOf(n), u = l.indexOf(o);
1159
+ if (a === -1 || u === -1) return [n];
1160
+ const [i, c] = a <= u ? [a, u] : [u, a];
1161
+ return l.slice(i, c + 1);
1162
+ }
1163
+ function Re(e) {
1164
+ const t = me();
1165
+ if (t) return Tt(e, t.blockId, t);
1166
+ const n = fe(e);
1167
+ return n ? Et(e, n) : null;
1168
+ }
1169
+ function ss(e, t, n) {
1170
+ const o = e.getRun(t.runId);
1171
+ if (!o || o.type !== "text") return null;
1172
+ const s = o.value ?? "", r = s.slice(0, t.offset) + n + s.slice(t.offset);
1173
+ return e.applyOperation(V(o.id, { value: r })), { blockId: t.blockId, runId: o.id, offset: t.offset + n.length };
1174
+ }
1175
+ function se(e, t) {
1176
+ if (typeof e.performBatch == "function") e.performBatch(t);
1177
+ else for (const n of t) e.applyOperation(n);
1178
+ }
1179
+ function rs() {
1180
+ const e = K(), t = ce(), n = Z(), { uploadFile: o, maxFileSize: s } = an(), [r, l] = st(), [a, u] = Pe(), i = B(
1181
+ (m) => {
1182
+ var g;
1183
+ if (Be(m.target)) return;
1184
+ const f = r ? ((g = e.getBlock(e.getRootId())) == null ? void 0 : g.contentIds) ?? [] : a.length > 0 ? a : os(e);
1185
+ if (f.length === 0) return;
1186
+ const { html: b, text: k, json: y } = yt(e, t, f, n);
1187
+ m.clipboardData.setData("text/plain", k), m.clipboardData.setData("text/html", b), m.clipboardData.setData(Le, y), m.preventDefault();
1188
+ },
1189
+ [e, t, n, r, a]
1190
+ ), c = B(
1191
+ (m) => {
1192
+ if (Be(m.target)) return;
1193
+ if (i(m), r) {
1194
+ const b = Ae(e);
1195
+ l(!1), b != null && b.runId && ne(b.runId, b.offset);
1196
+ return;
1197
+ }
1198
+ if (a.length > 0) {
1199
+ be(e, a), u([]);
1200
+ return;
1201
+ }
1202
+ const f = Re(e);
1203
+ f != null && f.runId && ne(f.runId, f.offset);
1204
+ },
1205
+ [
1206
+ i,
1207
+ e,
1208
+ r,
1209
+ l,
1210
+ a,
1211
+ u
1212
+ ]
1213
+ ), d = B(
1214
+ async (m) => {
1215
+ var S, E, x;
1216
+ const b = (await Promise.allSettled(
1217
+ m.map((R) => no(R, { uploadFile: o, maxFileSize: s }))
1218
+ )).filter((R) => R.status === "fulfilled").map((R) => R.value);
1219
+ if (b.length === 0) return;
1220
+ if (r) {
1221
+ const R = e.getRootId(), v = (((S = e.getBlock(R)) == null ? void 0 : S.contentIds) ?? []).map((M) => q(M));
1222
+ let L = 0;
1223
+ for (const { block: M, runs: A, subtreeBlocks: H = [] } of b)
1224
+ M.parentId = R, v.push(
1225
+ te(M, R, L, { blocks: [M, ...H], runs: A })
1226
+ ), L += 1;
1227
+ se(e, v), l(!1);
1228
+ return;
1229
+ }
1230
+ if (a.length > 0) {
1231
+ const R = e.getBlock(a[0]), O = (R == null ? void 0 : R.parentId) ?? null, v = O && e.getBlock(O);
1232
+ let L = v ? v.contentIds.indexOf(a[0]) : 0;
1233
+ const M = a.map((A) => q(A));
1234
+ for (const { block: A, runs: H, subtreeBlocks: F = [] } of b)
1235
+ A.parentId = O, M.push(
1236
+ te(A, O, L, { blocks: [A, ...F], runs: H })
1237
+ ), L += 1;
1238
+ se(e, M), u([]);
1239
+ return;
1240
+ }
1241
+ const k = Re(e), y = (k == null ? void 0 : k.blockId) ?? ye((x = (E = window.getSelection) == null ? void 0 : E.call(window)) == null ? void 0 : x.anchorNode);
1242
+ if (!y) return;
1243
+ const g = e.getBlock(y);
1244
+ if (!g) return;
1245
+ let C = e.getBlock(g.parentId).contentIds.indexOf(y) + 1;
1246
+ const w = [];
1247
+ for (const { block: R, runs: O, subtreeBlocks: v = [] } of b)
1248
+ R.parentId = g.parentId, w.push(
1249
+ te(R, g.parentId, C, { blocks: [R, ...v], runs: O })
1250
+ ), C += 1;
1251
+ se(e, w);
1252
+ },
1253
+ [
1254
+ e,
1255
+ o,
1256
+ s,
1257
+ r,
1258
+ l,
1259
+ a,
1260
+ u
1261
+ ]
1262
+ ), p = B(
1263
+ (m) => {
1264
+ var E, x, R, O;
1265
+ if (Be(m.target)) return;
1266
+ const f = Array.from(((E = m.clipboardData) == null ? void 0 : E.files) ?? []);
1267
+ if (f.length > 0) {
1268
+ m.preventDefault(), d(f);
1269
+ return;
1270
+ }
1271
+ const b = ts(m.clipboardData, t, n);
1272
+ if (b.length === 0) return;
1273
+ if (r) {
1274
+ const v = e.getRootId(), M = (((x = e.getBlock(v)) == null ? void 0 : x.contentIds) ?? []).map((H) => q(H));
1275
+ let A = 0;
1276
+ for (const { block: H, runs: F, subtreeBlocks: T = [] } of b)
1277
+ H.parentId = v, M.push(
1278
+ te(H, v, A, { blocks: [H, ...T], runs: F })
1279
+ ), A += 1;
1280
+ se(e, M), l(!1), m.preventDefault();
1281
+ return;
1282
+ }
1283
+ if (a.length > 0) {
1284
+ const v = e.getBlock(a[0]), L = (v == null ? void 0 : v.parentId) ?? null, M = L && e.getBlock(L);
1285
+ let A = M ? M.contentIds.indexOf(a[0]) : 0;
1286
+ const H = a.map((F) => q(F));
1287
+ for (const { block: F, runs: T, subtreeBlocks: P = [] } of b)
1288
+ F.parentId = L, H.push(
1289
+ te(F, L, A, { blocks: [F, ...P], runs: T })
1290
+ ), A += 1;
1291
+ se(e, H), u([]), m.preventDefault();
1292
+ return;
1293
+ }
1294
+ const k = Re(e);
1295
+ if (b.length === 1 && b[0].runs.every((v) => v.type === "text") && (b[0].subtreeBlocks ?? []).length === 0) {
1296
+ const v = k ? {
1297
+ blockId: k.blockId,
1298
+ runId: k.runId,
1299
+ offset: k.offset
1300
+ } : Q();
1301
+ if (v) {
1302
+ const L = b[0].runs.map((A) => A.value).join(""), M = ss(e, v, L);
1303
+ if (M) {
1304
+ ne(M.runId, M.offset), m.preventDefault();
1305
+ return;
1306
+ }
1307
+ }
1308
+ }
1309
+ const g = (k == null ? void 0 : k.blockId) ?? ye((O = (R = window.getSelection) == null ? void 0 : R.call(window)) == null ? void 0 : O.anchorNode);
1310
+ if (!g) return;
1311
+ const I = e.getBlock(g);
1312
+ if (!I) return;
1313
+ let w = e.getBlock(I.parentId).contentIds.indexOf(g) + 1;
1314
+ const S = [];
1315
+ for (const { block: v, runs: L, subtreeBlocks: M = [] } of b)
1316
+ v.parentId = I.parentId, S.push(
1317
+ te(v, I.parentId, w, { blocks: [v, ...M], runs: L })
1318
+ ), w += 1;
1319
+ se(e, S), m.preventDefault();
1320
+ },
1321
+ [
1322
+ e,
1323
+ t,
1324
+ n,
1325
+ r,
1326
+ l,
1327
+ a,
1328
+ u,
1329
+ d
1330
+ ]
1331
+ );
1332
+ return { onCopy: i, onCut: c, onPaste: p };
1333
+ }
1334
+ const as = [
1335
+ "bold",
1336
+ "italic",
1337
+ "underline",
1338
+ "strike",
1339
+ "subscript",
1340
+ "superscript",
1341
+ "code"
1342
+ ], ls = ["color", "highlight", "link"];
1343
+ function ie(e, t) {
1344
+ var o;
1345
+ const n = e.getBlock(t);
1346
+ return ((o = n.props) == null ? void 0 : o.titleRunIds) ?? n.contentIds;
1347
+ }
1348
+ function is(e, t) {
1349
+ return e === t ? !0 : e && t && typeof e == "object" ? JSON.stringify(e) === JSON.stringify(t) : !1;
1350
+ }
1351
+ function Lt(e) {
1352
+ var n;
1353
+ const t = {};
1354
+ if (e.length === 0) return t;
1355
+ for (const o of as)
1356
+ t[o] = e.every((s) => {
1357
+ var r;
1358
+ return (r = s.marks) == null ? void 0 : r[o];
1359
+ });
1360
+ for (const o of ls) {
1361
+ const s = ((n = e[0].marks) == null ? void 0 : n[o]) ?? null;
1362
+ t[o] = e.every((r) => {
1363
+ var l;
1364
+ return is(((l = r.marks) == null ? void 0 : l[o]) ?? null, s);
1365
+ }) ? s : null;
1366
+ }
1367
+ return t;
1368
+ }
1369
+ function Nt(e, t, n) {
1370
+ const { startRunId: o, startOffset: s, endRunId: r, endOffset: l } = n, a = ie(e, t), u = a.indexOf(o), i = a.indexOf(r);
1371
+ if (u === -1 || i === -1) return {};
1372
+ const [c, d] = u <= i ? [u, i] : [i, u], p = a.slice(c, d + 1).map((m) => e.getRun(m)).filter((m) => m && m.type === "text");
1373
+ return Lt(p);
1374
+ }
1375
+ function Mt(e, t) {
1376
+ const { blockIds: n, startBlockId: o, endBlockId: s } = t, r = n.indexOf(o), l = n.indexOf(s);
1377
+ if (r === -1 || l === -1) return {};
1378
+ const [a, u] = r <= l ? [r, l] : [l, r], i = [];
1379
+ for (let c = a; c <= u; c += 1)
1380
+ for (const d of ie(e, n[c])) {
1381
+ const p = e.getRun(d);
1382
+ p && p.type === "text" && i.push(p);
1383
+ }
1384
+ return Lt(i);
1385
+ }
1386
+ function At(e, t) {
1387
+ const n = { ...e };
1388
+ for (const [o, s] of Object.entries(t))
1389
+ s != null ? n[o] = s : delete n[o];
1390
+ return n;
1391
+ }
1392
+ function Dt(e, t, n, o, s, r) {
1393
+ const l = At(n.marks, r);
1394
+ if (o === 0 && s === n.value.length)
1395
+ return e.applyOperation({ type: "updateRun", id: n.id, patch: { marks: l } }), n.id;
1396
+ const a = n.value.slice(0, o), u = n.value.slice(o, s), i = n.value.slice(s), c = [];
1397
+ a && c.push({ id: $(), type: "text", value: a, marks: { ...n.marks } });
1398
+ const d = { id: $(), type: "text", value: u, marks: l };
1399
+ return c.push(d), i && c.push({ id: $(), type: "text", value: i, marks: { ...n.marks } }), e.applyOperation(rt(t, [n.id], c)), d.id;
1400
+ }
1401
+ function cs(e, t, n, o) {
1402
+ const { startRunId: s, startOffset: r, endRunId: l, endOffset: a } = n, u = ie(e, t), i = u.indexOf(s), c = u.indexOf(l);
1403
+ if (i === -1 || c === -1) return null;
1404
+ const [d, p] = i <= c ? [i, c] : [c, i], m = i <= c ? r : a, f = i <= c ? a : r, b = u.slice(d, p + 1), k = b.map((I) => e.getRun(I));
1405
+ if (d === p) {
1406
+ const I = k[0];
1407
+ if (I.type !== "text") return I.id;
1408
+ const C = Math.max(0, Math.min(m, f)), w = Math.min(I.value.length, Math.max(m, f));
1409
+ return C === w ? I.id : Dt(e, t, I, C, w, o);
1410
+ }
1411
+ const y = [];
1412
+ let g = null;
1413
+ return k.forEach((I, C) => {
1414
+ if (I.type !== "text") {
1415
+ y.push(I), g = I.id;
1416
+ return;
1417
+ }
1418
+ const w = C === 0, S = C === k.length - 1, E = w ? m : 0, x = S ? f : I.value.length, R = I.value.slice(0, E), O = I.value.slice(E, x), v = I.value.slice(x);
1419
+ R && y.push({ id: $(), type: "text", value: R, marks: { ...I.marks } });
1420
+ const L = {
1421
+ id: $(),
1422
+ type: "text",
1423
+ value: O,
1424
+ marks: At(I.marks, o)
1425
+ };
1426
+ y.push(L), g = L.id, v && y.push({ id: $(), type: "text", value: v, marks: { ...I.marks } });
1427
+ }), e.applyOperation(rt(t, b, y)), g;
1428
+ }
1429
+ function us(e, t, n, o) {
1430
+ var f;
1431
+ const { startRunId: s, startOffset: r, endRunId: l, endOffset: a } = n, u = ie(e, t), i = u.indexOf(s), c = u.indexOf(l);
1432
+ if (i === -1 || c === -1) return !0;
1433
+ const [d, p] = i <= c ? [i, c] : [c, i], m = u.slice(d, p + 1).map((b) => e.getRun(b)).filter((b) => b.type === "text");
1434
+ if (m.length === 0) return !0;
1435
+ if (d === p) {
1436
+ const b = Math.max(0, Math.min(r, a)), k = Math.min(m[0].value.length, Math.max(r, a));
1437
+ if (b === k) return !((f = m[0].marks) != null && f[o]);
1438
+ }
1439
+ return !m.every((b) => {
1440
+ var k;
1441
+ return (k = b.marks) == null ? void 0 : k[o];
1442
+ });
1443
+ }
1444
+ function Fr(e, t, n, o, s, r) {
1445
+ var d;
1446
+ const l = e.getRun(n), a = l.value ?? "", u = Math.max(0, Math.min(o, s)), i = Math.min(a.length, Math.max(o, s));
1447
+ if (u === i) return n;
1448
+ const c = !((d = l.marks) != null && d[r]);
1449
+ return Dt(e, t, l, u, i, {
1450
+ [r]: c ? !0 : null
1451
+ });
1452
+ }
1453
+ function pe(e, t, n, o) {
1454
+ return cs(e, t, n, o);
1455
+ }
1456
+ function Pt(e, t, n, o) {
1457
+ const s = us(e, t, n, o);
1458
+ return pe(e, t, n, {
1459
+ [o]: s ? !0 : null
1460
+ });
1461
+ }
1462
+ function _t(e, t, n) {
1463
+ return De(
1464
+ e,
1465
+ t,
1466
+ (o) => ({ [n]: o ? null : !0 }),
1467
+ n
1468
+ );
1469
+ }
1470
+ function De(e, t, n, o) {
1471
+ var S;
1472
+ const { blockIds: s, startBlockId: r, startRunId: l, startOffset: a, endBlockId: u, endRunId: i, endOffset: c } = t;
1473
+ if (!s || s.length === 0) return null;
1474
+ const d = s.indexOf(r), p = s.indexOf(u);
1475
+ if (d === -1 || p === -1) return null;
1476
+ const [m, f] = d <= p ? [d, p] : [p, d], b = d <= p, k = b ? l : i, y = b ? a : c, g = b ? i : l, I = b ? c : a;
1477
+ let C = n;
1478
+ if (typeof n == "function") {
1479
+ let E = !1, x = !0;
1480
+ for (let R = m; R <= f; R += 1) {
1481
+ const O = ie(e, s[R]).map((v) => e.getRun(v)).filter((v) => v.type === "text");
1482
+ O.length !== 0 && (E = !0, O.every((v) => {
1483
+ var L;
1484
+ return (L = v.marks) == null ? void 0 : L[o];
1485
+ }) || (x = !1));
1486
+ }
1487
+ C = n(E && x);
1488
+ }
1489
+ if (m === f)
1490
+ return pe(
1491
+ e,
1492
+ s[m],
1493
+ {
1494
+ startRunId: k,
1495
+ startOffset: y,
1496
+ endRunId: g,
1497
+ endOffset: I
1498
+ },
1499
+ C
1500
+ );
1501
+ let w = null;
1502
+ for (let E = m; E <= f; E += 1) {
1503
+ const x = s[E], R = ie(e, x), O = R[0], v = R[R.length - 1], L = e.getRun(v), M = ((S = L == null ? void 0 : L.value) == null ? void 0 : S.length) ?? 0;
1504
+ let A;
1505
+ E === m && E === f ? A = {
1506
+ startRunId: k,
1507
+ startOffset: y,
1508
+ endRunId: g,
1509
+ endOffset: I
1510
+ } : E === m ? A = {
1511
+ startRunId: k,
1512
+ startOffset: y,
1513
+ endRunId: v,
1514
+ endOffset: M
1515
+ } : E === f ? A = {
1516
+ startRunId: O,
1517
+ startOffset: 0,
1518
+ endRunId: g,
1519
+ endOffset: I
1520
+ } : A = {
1521
+ startRunId: O,
1522
+ startOffset: 0,
1523
+ endRunId: v,
1524
+ endOffset: M
1525
+ }, w = pe(e, x, A, C);
1526
+ }
1527
+ return w;
1528
+ }
1529
+ function $t(e, t) {
1530
+ var o;
1531
+ const n = e.getBlock(t);
1532
+ return ((o = n == null ? void 0 : n.props) == null ? void 0 : o.titleRunIds) ?? (n == null ? void 0 : n.contentIds) ?? [];
1533
+ }
1534
+ function ds(e) {
1535
+ const t = me();
1536
+ if (!t) return !1;
1537
+ const { blockId: n, startRunId: o, startOffset: s, endRunId: r, endOffset: l } = t, a = $t(e, n);
1538
+ if (a.length === 0) return !1;
1539
+ const u = a.indexOf(o), i = a.indexOf(r);
1540
+ if (u === -1 || i === -1) return !1;
1541
+ const [c, d] = u <= i ? [u, i] : [i, u], p = u <= i ? s : l, m = u <= i ? l : s;
1542
+ if (c !== 0 || d !== a.length - 1 || p !== 0) return !1;
1543
+ const f = e.getRun(a[a.length - 1]), b = (f == null ? void 0 : f.type) === "text" ? (f.value ?? "").length : 1;
1544
+ return m === b;
1545
+ }
1546
+ function fs(e) {
1547
+ const t = Q();
1548
+ return t ? oo(e, $t(e, t.blockId)) : !1;
1549
+ }
1550
+ function ps(e, t, n) {
1551
+ var m, f;
1552
+ const o = e.getBlock(t);
1553
+ if (!o) {
1554
+ n(null);
1555
+ return;
1556
+ }
1557
+ const s = e.getBlock(o.parentId), r = s ? s.contentIds.indexOf(t) : -1, l = r > 0 ? s.contentIds[r - 1] : null, a = r !== -1 && r < s.contentIds.length - 1 ? s.contentIds[r + 1] : null;
1558
+ e.applyOperation(q(t)), n(null);
1559
+ const u = mt(e), i = l ?? a ?? u;
1560
+ if (!i) return;
1561
+ const c = e.getBlock(i);
1562
+ if (so(e, c)) {
1563
+ n(i), requestAnimationFrame(() => {
1564
+ var b;
1565
+ return (b = document.querySelector(`[data-block-id="${i}"]`)) == null ? void 0 : b.focus();
1566
+ });
1567
+ return;
1568
+ }
1569
+ const d = (m = c == null ? void 0 : c.props) == null ? void 0 : m.titleRunIds, p = ((f = c == null ? void 0 : c.contentIds) == null ? void 0 : f[c.contentIds.length - 1]) ?? (d == null ? void 0 : d[d.length - 1]);
1570
+ p && re(p);
1571
+ }
1572
+ const Ge = { b: "bold", i: "italic", u: "underline" };
1573
+ function ms(e) {
1574
+ const t = K(), [n, o] = st(), { getSelectedBlockId: s, setSelectedBlockId: r } = ln();
1575
+ _(() => {
1576
+ const l = e.current;
1577
+ if (!l) return;
1578
+ const a = (i) => {
1579
+ var d, p;
1580
+ if (s() && (i.key === "Backspace" || i.key === "Delete") && !i.defaultPrevented) {
1581
+ i.preventDefault(), i.stopPropagation(), ps(t, s(), r);
1582
+ return;
1583
+ }
1584
+ if (s() && i.key !== "Backspace" && i.key !== "Delete" && r(null), i.metaKey || i.ctrlKey) {
1585
+ const m = i.key.toLowerCase();
1586
+ if (m === "z" && !i.shiftKey) {
1587
+ i.preventDefault(), (d = t.undo) != null && d.call(t) && ke(t);
1588
+ return;
1589
+ }
1590
+ if (m === "z" && i.shiftKey || m === "y") {
1591
+ i.preventDefault(), (p = t.redo) != null && p.call(t) && ke(t);
1592
+ return;
1593
+ }
1594
+ if (m === "a") {
1595
+ if (n) return;
1596
+ (ds(t) || fs(t)) && (i.preventDefault(), o(!0));
1597
+ return;
1598
+ }
1599
+ if (Ge[m]) {
1600
+ if (n) return;
1601
+ i.preventDefault();
1602
+ const f = Ge[m], b = me();
1603
+ if (b) {
1604
+ const y = Pt(
1605
+ t,
1606
+ b.blockId,
1607
+ b,
1608
+ f
1609
+ );
1610
+ y && re(y);
1611
+ return;
1612
+ }
1613
+ const k = fe(t);
1614
+ if (k) {
1615
+ const y = _t(t, k, f);
1616
+ y && re(y);
1617
+ }
1618
+ }
1619
+ return;
1620
+ }
1621
+ if (n) {
1622
+ if (i.key === "Backspace" || i.key === "Delete") {
1623
+ i.preventDefault(), i.stopPropagation();
1624
+ const m = Ae(t);
1625
+ o(!1), m != null && m.runId && ne(m.runId, m.offset);
1626
+ return;
1627
+ }
1628
+ if (i.key.length === 1) {
1629
+ i.preventDefault(), i.stopPropagation();
1630
+ const m = Ae(t, i.key);
1631
+ o(!1), m != null && m.runId && ne(m.runId, m.offset);
1632
+ return;
1633
+ }
1634
+ if (o(!1), i.key === "Escape") return;
1635
+ }
1636
+ if (i.key === "Backspace" || i.key === "Delete") {
1637
+ const m = fe(t);
1638
+ if (!m) return;
1639
+ i.preventDefault(), i.stopPropagation();
1640
+ const f = Et(t, m);
1641
+ f != null && f.runId && ne(f.runId, f.offset);
1642
+ }
1643
+ }, u = () => {
1644
+ n && o(!1), s() && r(null);
1645
+ };
1646
+ return l.addEventListener("keydown", a), l.addEventListener("mousedown", u), () => {
1647
+ l.removeEventListener("keydown", a), l.removeEventListener("mousedown", u);
1648
+ };
1649
+ }, [
1650
+ e,
1651
+ t,
1652
+ n,
1653
+ o,
1654
+ s,
1655
+ r
1656
+ ]);
1657
+ }
1658
+ function hs(e, t) {
1659
+ const n = K(), o = ce(), s = Z(), r = de(
1660
+ () => (e ?? []).filter(
1661
+ (a) => a && (a.keymap || a.onBeforeInput || a.onPaste || a.setup)
1662
+ ),
1663
+ [e]
1664
+ ), l = de(
1665
+ () => ({
1666
+ store: n,
1667
+ registry: o,
1668
+ inlineRegistry: s,
1669
+ get container() {
1670
+ return t.current;
1671
+ },
1672
+ getBlock: (a) => n.getBlock(a),
1673
+ getRun: (a) => n.getRun(a),
1674
+ getRootId: () => n.getRootId(),
1675
+ applyOperation: (a) => le(() => n.applyOperation(a)),
1676
+ applyOperations: (a) => le(() => {
1677
+ if (typeof n.performBatch == "function") n.performBatch(a);
1678
+ else for (const u of a) n.applyOperation(u);
1679
+ }),
1680
+ getSelection: () => Fe(),
1681
+ getCaret: () => Q(),
1682
+ setCaret: (a, u) => ae(a, u),
1683
+ subscribe: (a) => n.subscribeAll(a)
1684
+ }),
1685
+ [n, o, s, t]
1686
+ );
1687
+ _(() => {
1688
+ const a = t.current;
1689
+ if (!a || r.length === 0) return;
1690
+ const u = r.filter((f) => f.keymap), i = r.filter((f) => f.onBeforeInput), c = r.filter((f) => f.onPaste), d = (f) => {
1691
+ for (const b of u)
1692
+ for (const [k, y] of Object.entries(b.keymap))
1693
+ if (bs(f, k) && y(l, f)) {
1694
+ f.preventDefault(), f.stopImmediatePropagation();
1695
+ return;
1696
+ }
1697
+ }, p = (f) => {
1698
+ for (const b of i)
1699
+ if (b.onBeforeInput(l, f)) {
1700
+ f.preventDefault(), f.stopImmediatePropagation();
1701
+ return;
1702
+ }
1703
+ }, m = (f) => {
1704
+ for (const b of c)
1705
+ if (b.onPaste(l, f)) {
1706
+ f.preventDefault(), f.stopImmediatePropagation();
1707
+ return;
1708
+ }
1709
+ };
1710
+ return u.length && a.addEventListener("keydown", d), i.length && a.addEventListener("beforeinput", p), c.length && a.addEventListener("paste", m), () => {
1711
+ a.removeEventListener("keydown", d), a.removeEventListener("beforeinput", p), a.removeEventListener("paste", m);
1712
+ };
1713
+ }, [r, t, l]), _(() => {
1714
+ const a = r.filter((u) => u.setup).map((u) => u.setup(l)).filter((u) => typeof u == "function");
1715
+ return () => {
1716
+ for (const u of a) u();
1717
+ };
1718
+ }, [r, l]);
1719
+ }
1720
+ function bs(e, t) {
1721
+ const n = String(t).split("-"), o = n.pop().toLowerCase(), s = new Set(n.map((l) => l.toLowerCase())), r = e.metaKey || e.ctrlKey;
1722
+ return s.has("mod") !== r || s.has("shift") !== e.shiftKey || s.has("alt") !== e.altKey ? !1 : e.key.toLowerCase() === o;
1723
+ }
1724
+ const gs = 4;
1725
+ function ks(e, t, n) {
1726
+ const o = e.getBlock(t);
1727
+ if (!o) return [];
1728
+ const s = e.getBlock(o.parentId);
1729
+ if (!s) return [t];
1730
+ const r = s.contentIds, l = r.indexOf(t), a = n ? r.indexOf(n) : l;
1731
+ if (l === -1) return [t];
1732
+ const [u, i] = a === -1 ? [l, l] : [Math.min(l, a), Math.max(l, a)];
1733
+ return r.slice(u, i + 1);
1734
+ }
1735
+ function ys() {
1736
+ var e, t;
1737
+ return typeof window < "u" && ((t = (e = window.matchMedia) == null ? void 0 : e.call(window, "(pointer: coarse)")) == null ? void 0 : t.matches) === !0;
1738
+ }
1739
+ function Is(e) {
1740
+ const t = K(), [, n] = Pe(), o = z(null), s = z(!1), r = z(null), l = B(
1741
+ (c) => {
1742
+ var m, f, b, k, y;
1743
+ if (!o.current) return;
1744
+ if (!s.current) {
1745
+ const { x: g, y: I } = r.current ?? { x: c.clientX, y: c.clientY };
1746
+ if (Math.hypot(c.clientX - g, c.clientY - I) < gs) return;
1747
+ s.current = !0, document.documentElement.classList.add("be-block-range-dragging"), (f = (m = window.getSelection) == null ? void 0 : m.call(window)) == null || f.removeAllRanges();
1748
+ }
1749
+ (k = (b = window.getSelection) == null ? void 0 : b.call(window)) == null || k.removeAllRanges(), c.preventDefault();
1750
+ const d = (y = document.elementFromPoint(c.clientX, c.clientY)) == null ? void 0 : y.closest("[data-block-row-id]"), p = (d == null ? void 0 : d.getAttribute("data-block-row-id")) ?? null;
1751
+ n(ks(t, o.current, p));
1752
+ },
1753
+ [t, n]
1754
+ ), a = B(() => {
1755
+ o.current = null, s.current = !1, r.current = null, document.documentElement.classList.remove("be-block-range-dragging");
1756
+ }, []), u = B((c, d) => {
1757
+ o.current = c, s.current = !1, r.current = { x: d.clientX, y: d.clientY };
1758
+ }, []), i = B(
1759
+ (c) => {
1760
+ var b, k;
1761
+ if (c.button !== 0 || ys() || (k = (b = c.target).closest) != null && k.call(b, "button, input, textarea, select")) return;
1762
+ const d = c.target.closest("[data-block-row-id]");
1763
+ if (d) {
1764
+ if (c.target.closest(".be-block-row-content")) return;
1765
+ u(d.getAttribute("data-block-row-id"), c);
1766
+ return;
1767
+ }
1768
+ const p = e == null ? void 0 : e.current;
1769
+ if (!p) return;
1770
+ const f = [...p.querySelectorAll("[data-block-row-id]")].find((y) => {
1771
+ const g = y.getBoundingClientRect();
1772
+ return c.clientY >= g.top && c.clientY <= g.bottom;
1773
+ });
1774
+ f && u(f.getAttribute("data-block-row-id"), c);
1775
+ },
1776
+ [e, u]
1777
+ );
1778
+ _(() => (document.addEventListener("mousedown", i), document.addEventListener("mousemove", l), document.addEventListener("mouseup", a), () => {
1779
+ document.removeEventListener("mousedown", i), document.removeEventListener("mousemove", l), document.removeEventListener("mouseup", a), document.documentElement.classList.remove("be-block-range-dragging");
1780
+ }), [i, l, a]);
1781
+ }
1782
+ const vs = 340;
1783
+ function ws(e, t, n, o) {
1784
+ _(() => {
1785
+ if (!e || !t) return;
1786
+ const s = document.querySelector(`[data-run-id="${t}"]`);
1787
+ if (s)
1788
+ return s.setAttribute("aria-expanded", "true"), s.setAttribute("aria-haspopup", "listbox"), s.setAttribute("aria-controls", o), n && s.setAttribute("aria-activedescendant", n), () => {
1789
+ s.removeAttribute("aria-expanded"), s.removeAttribute("aria-haspopup"), s.removeAttribute("aria-controls"), s.removeAttribute("aria-activedescendant");
1790
+ };
1791
+ }, [e, t, n, o]);
1792
+ }
1793
+ function Se({
1794
+ isOpen: e,
1795
+ rect: t,
1796
+ commands: n,
1797
+ runId: o,
1798
+ onSelect: s,
1799
+ onClose: r,
1800
+ menuId: l = "be-slash-menu",
1801
+ ariaLabel: a = "Slash commands"
1802
+ }) {
1803
+ const [u, i] = D(0), c = z(null), d = z(null), p = bt(), m = Bo(
1804
+ d,
1805
+ e && n.length > 0 && !!t,
1806
+ t == null ? void 0 : t.left
1807
+ );
1808
+ _(() => {
1809
+ i(0);
1810
+ }, [n.length]), _(() => {
1811
+ var I, C;
1812
+ (C = (I = c.current) == null ? void 0 : I.scrollIntoView) == null || C.call(I, { block: "nearest" });
1813
+ }, [u]), _(() => {
1814
+ if (!e) return;
1815
+ const I = (C) => {
1816
+ C.key === "ArrowDown" ? (C.preventDefault(), C.stopPropagation(), i((w) => Math.min(w + 1, Math.max(n.length - 1, 0)))) : C.key === "ArrowUp" ? (C.preventDefault(), C.stopPropagation(), i((w) => Math.max(w - 1, 0))) : C.key === "Enter" ? (C.preventDefault(), C.stopPropagation(), n[u] && s(n[u])) : C.key === "Escape" && (C.preventDefault(), C.stopPropagation(), r());
1817
+ };
1818
+ return document.addEventListener("keydown", I, !0), () => document.removeEventListener("keydown", I, !0);
1819
+ }, [e, n, u, s, r]);
1820
+ const b = n[u] ? `${l}-option-${u}` : null;
1821
+ if (ws(e, o, b, l), !e || n.length === 0 || !t || m == null) return null;
1822
+ const k = window.innerHeight - p, g = t.bottom + vs > k ? { bottom: window.innerHeight - t.top + 4 } : { top: t.bottom + 4 };
1823
+ return /* @__PURE__ */ h(
1824
+ "div",
1825
+ {
1826
+ ref: d,
1827
+ id: l,
1828
+ role: "listbox",
1829
+ "aria-label": a,
1830
+ className: "be-slash-menu",
1831
+ style: { position: "fixed", left: m, zIndex: 1e3, ...g },
1832
+ children: n.map((I, C) => {
1833
+ const w = I.icon;
1834
+ return /* @__PURE__ */ N(
1835
+ "div",
1836
+ {
1837
+ ref: C === u ? c : void 0,
1838
+ id: `${l}-option-${C}`,
1839
+ role: "option",
1840
+ "aria-selected": C === u,
1841
+ className: `be-slash-menu-item${C === u ? " be-slash-menu-item-active" : ""}`,
1842
+ onMouseDown: (S) => {
1843
+ S.preventDefault(), s(I);
1844
+ },
1845
+ onMouseEnter: () => i(C),
1846
+ children: [
1847
+ w && /* @__PURE__ */ h("span", { className: "be-slash-menu-item-icon", children: /* @__PURE__ */ h(w, { size: 16 }) }),
1848
+ /* @__PURE__ */ h("span", { className: "be-slash-menu-item-label", children: I.label })
1849
+ ]
1850
+ },
1851
+ I.label
1852
+ );
1853
+ })
1854
+ }
1855
+ );
1856
+ }
1857
+ function Cs(e, t) {
1858
+ var o;
1859
+ if (!t) return !0;
1860
+ const n = t.toLowerCase();
1861
+ return e.label.toLowerCase().includes(n) || ((o = e.keywords) == null ? void 0 : o.some((s) => s.toLowerCase().includes(n)));
1862
+ }
1863
+ function Bs(e, t) {
1864
+ const n = t.anchorNode, o = t.anchorOffset;
1865
+ let s;
1866
+ if (n === e) {
1867
+ s = "";
1868
+ for (let r = 0; r < o && r < e.childNodes.length; r += 1)
1869
+ s += e.childNodes[r].textContent ?? "";
1870
+ } else n && n.parentElement === e ? s = (n.textContent ?? "").slice(0, o) : s = e.textContent ?? "";
1871
+ return kt(s).length;
1872
+ }
1873
+ function ze(e, t, n) {
1874
+ const o = K(), [s, r] = D(null);
1875
+ _(() => {
1876
+ const i = e.current;
1877
+ if (!i) return;
1878
+ const c = () => {
1879
+ var w, S, E, x;
1880
+ const p = (w = window.getSelection) == null ? void 0 : w.call(window), m = p == null ? void 0 : p.anchorNode;
1881
+ let f = (m == null ? void 0 : m.nodeType) === 1 ? m : m == null ? void 0 : m.parentElement;
1882
+ for (; f && typeof f.hasAttribute == "function" && !f.hasAttribute("data-run-id"); )
1883
+ f = f.parentElement;
1884
+ const b = (S = f == null ? void 0 : f.getAttribute) == null ? void 0 : S.call(f, "data-run-id");
1885
+ if (!b || !p) {
1886
+ r(null);
1887
+ return;
1888
+ }
1889
+ const k = Bs(f, p), y = kt(f.textContent).slice(0, k), g = t.exec(y);
1890
+ if (!g) {
1891
+ r(null);
1892
+ return;
1893
+ }
1894
+ const I = (x = (E = f.closest) == null ? void 0 : E.call(f, "[data-block-id]")) == null ? void 0 : x.getAttribute("data-block-id");
1895
+ if (!I) {
1896
+ r(null);
1897
+ return;
1898
+ }
1899
+ const C = g.index + g[1].length;
1900
+ r({
1901
+ query: g[2],
1902
+ blockId: I,
1903
+ runId: b,
1904
+ sliceStart: C,
1905
+ sliceEnd: k,
1906
+ rect: f.getBoundingClientRect()
1907
+ });
1908
+ }, d = (p) => {
1909
+ p.key === "Escape" && r(null);
1910
+ };
1911
+ return i.addEventListener("input", c), i.addEventListener("keydown", d), () => {
1912
+ i.removeEventListener("input", c), i.removeEventListener("keydown", d);
1913
+ };
1914
+ }, [e, t]);
1915
+ const l = s ? n().filter((i) => Cs(i, s.query)) : [], a = B(
1916
+ (i) => {
1917
+ s && (i.run(o, {
1918
+ blockId: s.blockId,
1919
+ runId: s.runId,
1920
+ sliceStart: s.sliceStart,
1921
+ sliceEnd: s.sliceEnd
1922
+ }), r(null));
1923
+ },
1924
+ [s, o]
1925
+ ), u = B(() => r(null), []);
1926
+ return {
1927
+ isOpen: !!s,
1928
+ query: (s == null ? void 0 : s.query) ?? "",
1929
+ rect: (s == null ? void 0 : s.rect) ?? null,
1930
+ runId: (s == null ? void 0 : s.runId) ?? null,
1931
+ commands: l,
1932
+ selectCommand: a,
1933
+ close: u
1934
+ };
1935
+ }
1936
+ const Rs = /(^|\s)\/(\w*)$/;
1937
+ function Ss(e) {
1938
+ const t = ce(), n = Z(), o = B(
1939
+ () => [...t.listSlashCommands(), ...(n == null ? void 0 : n.listSlashCommands()) ?? []],
1940
+ [t, n]
1941
+ );
1942
+ return ze(e, Rs, o);
1943
+ }
1944
+ const Os = [
1945
+ { char: "😀", name: "grinning face", keywords: ["smile", "happy"] },
1946
+ { char: "😂", name: "face with tears of joy", keywords: ["laugh", "lol"] },
1947
+ { char: "😍", name: "heart eyes", keywords: ["love", "crush"] },
1948
+ { char: "😎", name: "cool", keywords: ["sunglasses"] },
1949
+ { char: "🤔", name: "thinking face", keywords: ["hmm"] },
1950
+ { char: "😉", name: "winking face", keywords: ["wink"] },
1951
+ { char: "😢", name: "crying face", keywords: ["sad", "tear"] },
1952
+ { char: "😡", name: "angry face", keywords: ["mad", "rage"] },
1953
+ { char: "😱", name: "screaming face", keywords: ["shock", "scared"] },
1954
+ { char: "🥳", name: "party face", keywords: ["celebrate", "birthday"] },
1955
+ { char: "🙏", name: "folded hands", keywords: ["please", "pray", "thanks"] },
1956
+ { char: "👍", name: "thumbs up", keywords: ["approve", "yes", "like"] },
1957
+ { char: "👎", name: "thumbs down", keywords: ["disapprove", "no"] },
1958
+ { char: "👏", name: "clapping hands", keywords: ["applause", "congrats"] },
1959
+ { char: "🙌", name: "raised hands", keywords: ["hooray", "yay"] },
1960
+ { char: "👋", name: "waving hand", keywords: ["hello", "bye"] },
1961
+ { char: "✌️", name: "victory hand", keywords: ["peace"] },
1962
+ { char: "💪", name: "flexed biceps", keywords: ["strong", "muscle"] },
1963
+ { char: "🤝", name: "handshake", keywords: ["deal", "agree"] },
1964
+ { char: "❤️", name: "red heart", keywords: ["love"] },
1965
+ { char: "🔥", name: "fire", keywords: ["hot", "lit"] },
1966
+ { char: "⭐", name: "star", keywords: ["favorite"] },
1967
+ { char: "✨", name: "sparkles", keywords: ["shiny", "magic"] },
1968
+ { char: "🎉", name: "party popper", keywords: ["celebrate", "congrats"] },
1969
+ { char: "🎊", name: "confetti ball", keywords: ["celebrate"] },
1970
+ { char: "💡", name: "light bulb", keywords: ["idea", "tip"] },
1971
+ { char: "✅", name: "check mark", keywords: ["done", "yes", "complete"] },
1972
+ { char: "❌", name: "cross mark", keywords: ["no", "wrong", "delete"] },
1973
+ { char: "⚠️", name: "warning", keywords: ["caution", "alert"] },
1974
+ { char: "❓", name: "question mark", keywords: ["question", "help"] },
1975
+ { char: "❗", name: "exclamation mark", keywords: ["important", "alert"] },
1976
+ { char: "🚀", name: "rocket", keywords: ["launch", "fast", "ship"] },
1977
+ { char: "🐛", name: "bug", keywords: ["bug", "issue"] },
1978
+ { char: "🔧", name: "wrench", keywords: ["fix", "tool", "settings"] },
1979
+ { char: "📌", name: "pushpin", keywords: ["pin", "note"] },
1980
+ { char: "📎", name: "paperclip", keywords: ["attachment", "clip"] },
1981
+ { char: "📅", name: "calendar", keywords: ["date", "schedule"] },
1982
+ { char: "⏰", name: "alarm clock", keywords: ["time", "reminder"] },
1983
+ { char: "📈", name: "chart increasing", keywords: ["growth", "stats"] },
1984
+ { char: "📉", name: "chart decreasing", keywords: ["decline", "stats"] },
1985
+ { char: "💰", name: "money bag", keywords: ["money", "cash"] },
1986
+ { char: "💬", name: "speech balloon", keywords: ["comment", "chat"] },
1987
+ { char: "📝", name: "memo", keywords: ["note", "write"] },
1988
+ { char: "📚", name: "books", keywords: ["reading", "docs"] },
1989
+ { char: "🔗", name: "link", keywords: ["url", "chain"] },
1990
+ { char: "🔒", name: "locked", keywords: ["private", "secure"] },
1991
+ { char: "🔑", name: "key", keywords: ["password", "access"] },
1992
+ { char: "☕", name: "coffee", keywords: ["coffee", "break"] },
1993
+ { char: "🍕", name: "pizza", keywords: ["food"] },
1994
+ { char: "🎂", name: "birthday cake", keywords: ["birthday", "cake"] },
1995
+ { char: "🎁", name: "gift", keywords: ["present"] },
1996
+ { char: "🌟", name: "glowing star", keywords: ["star", "shiny"] },
1997
+ { char: "🌈", name: "rainbow", keywords: ["colorful"] },
1998
+ { char: "☀️", name: "sun", keywords: ["sunny", "weather"] },
1999
+ { char: "🌧️", name: "rain cloud", keywords: ["rainy", "weather"] },
2000
+ { char: "🐶", name: "dog face", keywords: ["dog", "pet"] },
2001
+ { char: "🐱", name: "cat face", keywords: ["cat", "pet"] },
2002
+ { char: "🌍", name: "globe", keywords: ["world", "earth"] },
2003
+ { char: "🎯", name: "direct hit", keywords: ["target", "goal"] },
2004
+ { char: "🏆", name: "trophy", keywords: ["win", "award"] },
2005
+ { char: "🕐", name: "clock", keywords: ["time"] },
2006
+ { char: "📣", name: "megaphone", keywords: ["announce", "shout"] },
2007
+ { char: "🧠", name: "brain", keywords: ["smart", "idea", "mind"] },
2008
+ { char: "👀", name: "eyes", keywords: ["look", "watching"] }
2009
+ ];
2010
+ function xs(e, { runId: t, sliceStart: n, sliceEnd: o }, s) {
2011
+ const r = e.getRun(t), l = (r == null ? void 0 : r.value) ?? "", a = l.slice(0, n) + s + l.slice(o);
2012
+ e.applyOperation(V(t, { value: a })), ne(t, n + s.length);
2013
+ }
2014
+ const Ts = Os.map(({ char: e, name: t, keywords: n }) => ({
2015
+ label: `${e} ${t}`,
2016
+ keywords: n,
2017
+ run: (o, s) => xs(o, s, e)
2018
+ })), Es = /(^|\s):(\w*)$/, Ls = () => Ts;
2019
+ function Ns(e) {
2020
+ return ze(e, Es, Ls);
2021
+ }
2022
+ const Ms = /(^|\s)@(\w*)$/;
2023
+ function As(e) {
2024
+ const t = Z(), n = B(() => (t == null ? void 0 : t.listAtCommands()) ?? [], [t]);
2025
+ return ze(e, Ms, n);
2026
+ }
2027
+ function Ht(e, t, n, o, s) {
2028
+ const [r, l] = D(!1), a = B(
2029
+ (k) => {
2030
+ const y = t === "same-block" ? pe(e, n.blockId, n, k) : De(e, o, k);
2031
+ return y && re(y), y;
2032
+ },
2033
+ [e, t, n, o]
2034
+ ), u = B(
2035
+ (k) => {
2036
+ const y = t === "same-block" ? Pt(e, n.blockId, n, k) : _t(e, o, k);
2037
+ y && re(y);
2038
+ },
2039
+ [e, t, n, o]
2040
+ ), i = B(
2041
+ (k) => {
2042
+ const y = k === "subscript" ? "superscript" : "subscript", g = !s[k];
2043
+ a({ [k]: g ? !0 : null, [y]: null });
2044
+ },
2045
+ [s, a]
2046
+ ), c = z(null), d = B(() => {
2047
+ c.current = { kind: t, selection: n, crossSelection: o }, l(!0);
2048
+ }, [t, n, o]), p = B(() => l(!1), []), m = B(
2049
+ (k) => {
2050
+ const y = c.current;
2051
+ if (!y) return;
2052
+ const g = y.kind === "same-block" ? pe(e, y.selection.blockId, y.selection, k) : De(e, y.crossSelection, k);
2053
+ g && re(g), l(!1);
2054
+ },
2055
+ [e]
2056
+ ), f = B(
2057
+ (k, y) => m({ link: { href: k, target: y } }),
2058
+ [m]
2059
+ ), b = B(() => m({ link: null }), [m]);
2060
+ return {
2061
+ applyPatch: a,
2062
+ toggleBoolean: u,
2063
+ setSubSuper: i,
2064
+ isLinkModalOpen: r,
2065
+ openLinkModal: d,
2066
+ closeLinkModal: p,
2067
+ handleSaveLink: f,
2068
+ handleRemoveLink: b
2069
+ };
2070
+ }
2071
+ const Ds = "be-touch-input";
2072
+ function Ps() {
2073
+ var e, t;
2074
+ return typeof window < "u" && ((t = (e = window.matchMedia) == null ? void 0 : e.call(window, "(pointer: coarse)")) == null ? void 0 : t.matches) === !0;
2075
+ }
2076
+ function Ft() {
2077
+ const [e, t] = D(Ps);
2078
+ return _(() => {
2079
+ if (typeof window > "u") return;
2080
+ const n = (o) => {
2081
+ t(o.pointerType === "touch" || o.pointerType === "pen");
2082
+ };
2083
+ return window.addEventListener("pointerdown", n, { passive: !0 }), () => window.removeEventListener("pointerdown", n);
2084
+ }, []), _(() => {
2085
+ var n;
2086
+ (n = document.documentElement) == null || n.classList.toggle(Ds, e);
2087
+ }, [e]), e;
2088
+ }
2089
+ const _s = [
2090
+ { markName: "bold", Icon: at, title: "Bold (Ctrl+B)" },
2091
+ { markName: "italic", Icon: lt, title: "Italic (Ctrl+I)" },
2092
+ { markName: "underline", Icon: it, title: "Underline (Ctrl+U)" },
2093
+ { markName: "strike", Icon: cn, title: "Strikethrough" }
2094
+ ], $s = [
2095
+ { label: "Default", value: null },
2096
+ { label: "Red", value: "#e03131" },
2097
+ { label: "Orange", value: "#e8590c" },
2098
+ { label: "Green", value: "#2f9e44" },
2099
+ { label: "Blue", value: "#1971c2" },
2100
+ { label: "Purple", value: "#9c36b5" }
2101
+ ], Hs = [
2102
+ { label: "None", value: null },
2103
+ { label: "Yellow", value: "#fff3bf" },
2104
+ { label: "Green", value: "#d3f9d8" },
2105
+ { label: "Blue", value: "#d0ebff" },
2106
+ { label: "Pink", value: "#ffdeeb" },
2107
+ { label: "Gray", value: "#e9ecef" }
2108
+ ];
2109
+ function Fs({
2110
+ isOpen: e,
2111
+ rect: t,
2112
+ kind: n,
2113
+ selection: o,
2114
+ crossSelection: s,
2115
+ marks: r,
2116
+ store: l,
2117
+ onComment: a,
2118
+ commentAuthorId: u
2119
+ }) {
2120
+ var H, F;
2121
+ const i = Ft(), [c, d] = D(null), [p, m] = D(null), f = z(null), {
2122
+ applyPatch: b,
2123
+ toggleBoolean: k,
2124
+ setSubSuper: y,
2125
+ isLinkModalOpen: g,
2126
+ openLinkModal: I,
2127
+ closeLinkModal: C,
2128
+ handleSaveLink: w,
2129
+ handleRemoveLink: S
2130
+ } = Ht(l, n, o, s, r), E = z(null);
2131
+ E.current = p;
2132
+ function x() {
2133
+ var T, P, j, ee;
2134
+ (P = (T = document.activeElement) == null ? void 0 : T.blur) == null || P.call(T), (ee = (j = window.getSelection) == null ? void 0 : j.call(window)) == null || ee.removeAllRanges();
2135
+ }
2136
+ function R() {
2137
+ if (!o) return;
2138
+ const T = $(), P = Rn(l, o, T);
2139
+ P && l.applyOperation(P), m({ commentId: T }), d("comment");
2140
+ }
2141
+ function O() {
2142
+ const T = E.current;
2143
+ if (T) {
2144
+ for (const P of Bn(l, T.commentId))
2145
+ l.applyOperation(P);
2146
+ m(null), x();
2147
+ }
2148
+ }
2149
+ function v(T) {
2150
+ !p || !o || (l.applyOperation(
2151
+ dn({
2152
+ id: p.commentId,
2153
+ blockId: o.blockId,
2154
+ anchorRunIds: [o.startRunId, o.endRunId],
2155
+ resolved: !1,
2156
+ messages: [{ id: $(), authorId: u, text: T, createdAt: Date.now() }]
2157
+ })
2158
+ ), m(null), d(null), x());
2159
+ }
2160
+ function L() {
2161
+ O(), d(null);
2162
+ }
2163
+ _(() => {
2164
+ if (!e || n !== "same-block" || !(a || u)) return;
2165
+ const T = (P) => {
2166
+ (P.metaKey || P.ctrlKey) && P.altKey && P.code === "KeyM" && (P.preventDefault(), a ? a(o) : R());
2167
+ };
2168
+ return document.addEventListener("keydown", T), () => document.removeEventListener("keydown", T);
2169
+ }, [e, n, a, u, o]), _(() => {
2170
+ if (!c) return;
2171
+ const T = (j) => {
2172
+ f.current && !f.current.contains(j.target) && (O(), d(null));
2173
+ }, P = (j) => {
2174
+ j.key === "Escape" && (O(), d(null));
2175
+ };
2176
+ return document.addEventListener("mousedown", T), document.addEventListener("keydown", P), () => {
2177
+ document.removeEventListener("mousedown", T), document.removeEventListener("keydown", P);
2178
+ };
2179
+ }, [c]), _(() => {
2180
+ O(), d(null);
2181
+ }, [t, n]);
2182
+ const M = Ro(
2183
+ f,
2184
+ !!(e && t),
2185
+ t ? t.left + t.width / 2 : null
2186
+ );
2187
+ if (i || (!e || !t) && !g) return null;
2188
+ const A = !a && c === "comment";
2189
+ return /* @__PURE__ */ N(X, { children: [
2190
+ e && t && M != null && A && // Composing a new comment REPLACES the whole button row (not another
2191
+ // picker floating off one of its buttons) -- same outer position as the
2192
+ // ordinary toolbar below (centered under the selection), so the
2193
+ // composer lands right under the highlighted text instead of trailing
2194
+ // off toward wherever the Comment button happened to sit in a wide row.
2195
+ /* @__PURE__ */ N(
2196
+ "div",
2197
+ {
2198
+ ref: f,
2199
+ className: "be-floating-toolbar be-floating-toolbar-comment-standalone",
2200
+ role: "dialog",
2201
+ "aria-label": "Add comment",
2202
+ style: {
2203
+ position: "fixed",
2204
+ top: t.top - 44,
2205
+ left: M,
2206
+ transform: "translateX(-50%)"
2207
+ },
2208
+ onMouseDown: (T) => {
2209
+ T.target.tagName !== "TEXTAREA" && T.preventDefault();
2210
+ },
2211
+ children: [
2212
+ /* @__PURE__ */ h(ro, { title: "Add comment", onClose: L }),
2213
+ /* @__PURE__ */ h(
2214
+ Cn,
2215
+ {
2216
+ authorId: u,
2217
+ autoFocus: !0,
2218
+ onSubmit: v,
2219
+ onCancel: L
2220
+ }
2221
+ )
2222
+ ]
2223
+ }
2224
+ ),
2225
+ e && t && M != null && !A && /* @__PURE__ */ N(
2226
+ "div",
2227
+ {
2228
+ ref: f,
2229
+ className: "be-floating-toolbar",
2230
+ role: "toolbar",
2231
+ "aria-label": "Text formatting",
2232
+ style: {
2233
+ position: "fixed",
2234
+ top: t.top - 44,
2235
+ left: M,
2236
+ transform: "translateX(-50%)"
2237
+ },
2238
+ onMouseDown: (T) => {
2239
+ T.target.tagName !== "TEXTAREA" && T.preventDefault();
2240
+ },
2241
+ children: [
2242
+ _s.map(({ markName: T, Icon: P, title: j }) => /* @__PURE__ */ h(
2243
+ "button",
2244
+ {
2245
+ type: "button",
2246
+ className: `be-floating-toolbar-btn${r[T] ? " be-floating-toolbar-btn-active" : ""}`,
2247
+ title: j,
2248
+ "aria-label": j,
2249
+ "aria-pressed": !!r[T],
2250
+ onClick: () => k(T),
2251
+ children: /* @__PURE__ */ h(P, {})
2252
+ },
2253
+ T
2254
+ )),
2255
+ /* @__PURE__ */ h(
2256
+ "button",
2257
+ {
2258
+ type: "button",
2259
+ className: `be-floating-toolbar-btn${r.subscript ? " be-floating-toolbar-btn-active" : ""}`,
2260
+ title: "Subscript",
2261
+ "aria-pressed": !!r.subscript,
2262
+ onClick: () => y("subscript"),
2263
+ children: "X₂"
2264
+ }
2265
+ ),
2266
+ /* @__PURE__ */ h(
2267
+ "button",
2268
+ {
2269
+ type: "button",
2270
+ className: `be-floating-toolbar-btn${r.superscript ? " be-floating-toolbar-btn-active" : ""}`,
2271
+ title: "Superscript",
2272
+ "aria-pressed": !!r.superscript,
2273
+ onClick: () => y("superscript"),
2274
+ children: "X²"
2275
+ }
2276
+ ),
2277
+ /* @__PURE__ */ h("span", { className: "be-floating-toolbar-divider" }),
2278
+ /* @__PURE__ */ N("div", { className: "be-floating-toolbar-picker-wrap", children: [
2279
+ /* @__PURE__ */ h(
2280
+ "button",
2281
+ {
2282
+ type: "button",
2283
+ className: "be-floating-toolbar-btn",
2284
+ title: "Text color",
2285
+ "aria-haspopup": "true",
2286
+ "aria-expanded": c === "color",
2287
+ onClick: () => d((T) => T === "color" ? null : "color"),
2288
+ children: /* @__PURE__ */ h("span", { style: { color: r.color || "inherit", fontWeight: 700 }, children: "A" })
2289
+ }
2290
+ ),
2291
+ c === "color" && /* @__PURE__ */ h("div", { className: "be-floating-toolbar-picker", role: "menu", "aria-label": "Text color", children: $s.map((T) => /* @__PURE__ */ h(
2292
+ "button",
2293
+ {
2294
+ type: "button",
2295
+ role: "menuitem",
2296
+ className: "be-floating-toolbar-swatch",
2297
+ title: T.label,
2298
+ onClick: () => {
2299
+ b({ color: T.value }), d(null);
2300
+ },
2301
+ children: /* @__PURE__ */ h("span", { style: { color: T.value || "#1a1a1a", fontWeight: 700 }, children: "A" })
2302
+ },
2303
+ T.label
2304
+ )) })
2305
+ ] }),
2306
+ /* @__PURE__ */ N("div", { className: "be-floating-toolbar-picker-wrap", children: [
2307
+ /* @__PURE__ */ h(
2308
+ "button",
2309
+ {
2310
+ type: "button",
2311
+ className: "be-floating-toolbar-btn",
2312
+ title: "Highlight",
2313
+ "aria-haspopup": "true",
2314
+ "aria-expanded": c === "highlight",
2315
+ onClick: () => d((T) => T === "highlight" ? null : "highlight"),
2316
+ children: /* @__PURE__ */ h(
2317
+ "span",
2318
+ {
2319
+ style: {
2320
+ backgroundColor: r.highlight || "transparent",
2321
+ padding: "0 2px",
2322
+ borderRadius: 2
2323
+ },
2324
+ children: "H"
2325
+ }
2326
+ )
2327
+ }
2328
+ ),
2329
+ c === "highlight" && /* @__PURE__ */ h("div", { className: "be-floating-toolbar-picker", role: "menu", "aria-label": "Highlight color", children: Hs.map((T) => /* @__PURE__ */ h(
2330
+ "button",
2331
+ {
2332
+ type: "button",
2333
+ role: "menuitem",
2334
+ className: "be-floating-toolbar-swatch",
2335
+ style: { backgroundColor: T.value || "transparent" },
2336
+ title: T.label,
2337
+ onClick: () => {
2338
+ b({ highlight: T.value }), d(null);
2339
+ }
2340
+ },
2341
+ T.label
2342
+ )) })
2343
+ ] }),
2344
+ /* @__PURE__ */ h("span", { className: "be-floating-toolbar-divider" }),
2345
+ /* @__PURE__ */ h(
2346
+ "button",
2347
+ {
2348
+ type: "button",
2349
+ className: `be-floating-toolbar-btn${r.link ? " be-floating-toolbar-btn-active" : ""}`,
2350
+ title: "Link",
2351
+ "aria-label": "Link",
2352
+ "aria-pressed": !!r.link,
2353
+ onClick: I,
2354
+ children: /* @__PURE__ */ h(ct, {})
2355
+ }
2356
+ ),
2357
+ (a || u) && n === "same-block" && /* @__PURE__ */ N(X, { children: [
2358
+ /* @__PURE__ */ h("span", { className: "be-floating-toolbar-divider" }),
2359
+ /* @__PURE__ */ h(
2360
+ "button",
2361
+ {
2362
+ type: "button",
2363
+ className: "be-floating-toolbar-btn",
2364
+ title: "Comment (Ctrl+Alt+M)",
2365
+ "aria-label": "Comment",
2366
+ onClick: () => a ? a(o) : R(),
2367
+ children: /* @__PURE__ */ h(un, {})
2368
+ }
2369
+ )
2370
+ ] })
2371
+ ]
2372
+ }
2373
+ ),
2374
+ /* @__PURE__ */ h(
2375
+ ao,
2376
+ {
2377
+ isOpen: g,
2378
+ initialHref: ((H = r.link) == null ? void 0 : H.href) ?? "",
2379
+ initialTarget: ((F = r.link) == null ? void 0 : F.target) ?? "_self",
2380
+ hasExistingLink: !!r.link,
2381
+ onSave: w,
2382
+ onRemove: S,
2383
+ onClose: C
2384
+ }
2385
+ )
2386
+ ] });
2387
+ }
2388
+ function Ks(e) {
2389
+ const t = K(), [n, o] = D(null);
2390
+ return _(() => {
2391
+ const s = e.current;
2392
+ if (!s) return;
2393
+ const r = () => {
2394
+ var c, d, p, m, f;
2395
+ if ((d = (c = document.activeElement) == null ? void 0 : c.closest) != null && d.call(c, ".be-floating-toolbar")) return;
2396
+ const l = (p = window.getSelection) == null ? void 0 : p.call(window);
2397
+ if (!l || l.rangeCount === 0 || l.isCollapsed) {
2398
+ o(null);
2399
+ return;
2400
+ }
2401
+ if (!s.contains(l.anchorNode) || !s.contains(l.focusNode)) {
2402
+ o(null);
2403
+ return;
2404
+ }
2405
+ const a = ((f = (m = l.getRangeAt(0)).getBoundingClientRect) == null ? void 0 : f.call(m)) ?? {
2406
+ top: 0,
2407
+ left: 0,
2408
+ right: 0,
2409
+ bottom: 0,
2410
+ width: 0,
2411
+ height: 0
2412
+ }, u = me();
2413
+ if (u) {
2414
+ o({
2415
+ kind: "same-block",
2416
+ rect: a,
2417
+ selection: u,
2418
+ marks: Nt(t, u.blockId, u)
2419
+ });
2420
+ return;
2421
+ }
2422
+ const i = fe(t);
2423
+ if (i) {
2424
+ o({
2425
+ kind: "cross-block",
2426
+ rect: a,
2427
+ crossSelection: i,
2428
+ marks: Mt(t, i)
2429
+ });
2430
+ return;
2431
+ }
2432
+ o(null);
2433
+ };
2434
+ return document.addEventListener("selectionchange", r), window.addEventListener("scroll", r, !0), window.addEventListener("resize", r), () => {
2435
+ document.removeEventListener("selectionchange", r), window.removeEventListener("scroll", r, !0), window.removeEventListener("resize", r);
2436
+ };
2437
+ }, [e, t]), {
2438
+ isOpen: !!n,
2439
+ rect: (n == null ? void 0 : n.rect) ?? null,
2440
+ kind: (n == null ? void 0 : n.kind) ?? null,
2441
+ selection: (n == null ? void 0 : n.selection) ?? null,
2442
+ crossSelection: (n == null ? void 0 : n.crossSelection) ?? null,
2443
+ marks: (n == null ? void 0 : n.marks) ?? {},
2444
+ close: () => o(null)
2445
+ };
2446
+ }
2447
+ function zs({
2448
+ isOpen: e,
2449
+ close: t,
2450
+ query: n,
2451
+ setQuery: o,
2452
+ caseSensitive: s,
2453
+ setCaseSensitive: r,
2454
+ wholeWord: l,
2455
+ setWholeWord: a,
2456
+ isReplaceOpen: u,
2457
+ setIsReplaceOpen: i,
2458
+ replacement: c,
2459
+ setReplacement: d,
2460
+ matches: p,
2461
+ currentIndex: m,
2462
+ next: f,
2463
+ prev: b,
2464
+ replaceCurrent: k,
2465
+ replaceAll: y,
2466
+ queryInputRef: g
2467
+ }) {
2468
+ if (!e) return null;
2469
+ const I = (w) => {
2470
+ w.key === "Enter" ? (w.preventDefault(), w.shiftKey ? b() : f()) : w.key === "Escape" && (w.preventDefault(), t());
2471
+ }, C = (w) => {
2472
+ w.key === "Enter" ? (w.preventDefault(), k()) : w.key === "Escape" && (w.preventDefault(), t());
2473
+ };
2474
+ return /* @__PURE__ */ N("div", { className: "be-find-bar", contentEditable: !1, children: [
2475
+ /* @__PURE__ */ N("div", { className: "be-find-bar-row", children: [
2476
+ /* @__PURE__ */ h(
2477
+ "button",
2478
+ {
2479
+ type: "button",
2480
+ className: `be-find-bar-replace-toggle${u ? " be-find-bar-replace-toggle-open" : ""}`,
2481
+ onClick: () => i(!u),
2482
+ "aria-expanded": u,
2483
+ "aria-label": "Toggle replace",
2484
+ children: /* @__PURE__ */ h(fn, { size: 12 })
2485
+ }
2486
+ ),
2487
+ /* @__PURE__ */ h(
2488
+ "input",
2489
+ {
2490
+ ref: g,
2491
+ type: "text",
2492
+ className: "be-find-bar-input",
2493
+ placeholder: "Find",
2494
+ value: n,
2495
+ onChange: (w) => o(w.target.value),
2496
+ onKeyDown: I,
2497
+ "aria-label": "Find in document"
2498
+ }
2499
+ ),
2500
+ /* @__PURE__ */ h("span", { className: "be-find-bar-count", children: p.length === 0 ? "0/0" : `${m + 1}/${p.length}` }),
2501
+ /* @__PURE__ */ h(
2502
+ "button",
2503
+ {
2504
+ type: "button",
2505
+ className: `be-find-bar-toggle${s ? " be-find-bar-toggle-active" : ""}`,
2506
+ onClick: () => r(!s),
2507
+ "aria-pressed": s,
2508
+ title: "Match case",
2509
+ "aria-label": "Match case",
2510
+ children: "Aa"
2511
+ }
2512
+ ),
2513
+ /* @__PURE__ */ h(
2514
+ "button",
2515
+ {
2516
+ type: "button",
2517
+ className: `be-find-bar-toggle${l ? " be-find-bar-toggle-active" : ""}`,
2518
+ onClick: () => a(!l),
2519
+ "aria-pressed": l,
2520
+ title: "Whole word",
2521
+ "aria-label": "Whole word",
2522
+ children: "[Ab]"
2523
+ }
2524
+ ),
2525
+ /* @__PURE__ */ h(
2526
+ "button",
2527
+ {
2528
+ type: "button",
2529
+ className: "be-find-bar-nav",
2530
+ onClick: b,
2531
+ disabled: p.length === 0,
2532
+ "aria-label": "Previous match",
2533
+ children: /* @__PURE__ */ h(_e, { size: 14 })
2534
+ }
2535
+ ),
2536
+ /* @__PURE__ */ h(
2537
+ "button",
2538
+ {
2539
+ type: "button",
2540
+ className: "be-find-bar-nav",
2541
+ onClick: f,
2542
+ disabled: p.length === 0,
2543
+ "aria-label": "Next match",
2544
+ children: /* @__PURE__ */ h($e, { size: 14 })
2545
+ }
2546
+ ),
2547
+ /* @__PURE__ */ h(
2548
+ "button",
2549
+ {
2550
+ type: "button",
2551
+ className: "be-find-bar-close",
2552
+ onClick: t,
2553
+ "aria-label": "Close find bar",
2554
+ children: /* @__PURE__ */ h(ut, { size: 14 })
2555
+ }
2556
+ )
2557
+ ] }),
2558
+ u && /* @__PURE__ */ N("div", { className: "be-find-bar-row be-find-bar-replace-row", children: [
2559
+ /* @__PURE__ */ h(
2560
+ "input",
2561
+ {
2562
+ type: "text",
2563
+ className: "be-find-bar-input",
2564
+ placeholder: "Replace",
2565
+ value: c,
2566
+ onChange: (w) => d(w.target.value),
2567
+ onKeyDown: C,
2568
+ "aria-label": "Replace with"
2569
+ }
2570
+ ),
2571
+ /* @__PURE__ */ h(
2572
+ "button",
2573
+ {
2574
+ type: "button",
2575
+ className: "be-find-bar-replace-btn",
2576
+ onClick: k,
2577
+ disabled: p.length === 0,
2578
+ children: "Replace"
2579
+ }
2580
+ ),
2581
+ /* @__PURE__ */ h(
2582
+ "button",
2583
+ {
2584
+ type: "button",
2585
+ className: "be-find-bar-replace-btn",
2586
+ onClick: y,
2587
+ disabled: p.length === 0,
2588
+ children: "Replace All"
2589
+ }
2590
+ )
2591
+ ] })
2592
+ ] });
2593
+ }
2594
+ function Ye(e) {
2595
+ return e != null && /[\w]/.test(e);
2596
+ }
2597
+ function Us(e, t, n) {
2598
+ const o = e[t - 1], s = e[t + n];
2599
+ return !Ye(o) && !Ye(s);
2600
+ }
2601
+ function Xe(e, t, n, o, s, r, l) {
2602
+ const a = l ?? e.getRun(n);
2603
+ if (!a || a.type !== "text" || !a.value) return;
2604
+ const u = s.caseSensitive ? a.value : a.value.toLowerCase();
2605
+ let i = 0;
2606
+ for (; ; ) {
2607
+ const c = u.indexOf(o, i);
2608
+ if (c === -1) break;
2609
+ (!s.wholeWord || Us(u, c, o.length)) && r.push({ blockId: t, runId: n, offset: c, length: o.length }), i = c + o.length;
2610
+ }
2611
+ }
2612
+ function Kt(e, t, n, o, s) {
2613
+ var l;
2614
+ const r = e.getBlock(t);
2615
+ if (r) {
2616
+ for (const a of ((l = r.props) == null ? void 0 : l.titleRunIds) ?? [])
2617
+ Xe(e, t, a, n, o, s);
2618
+ for (const a of r.contentIds) {
2619
+ const u = e.getRun(a);
2620
+ u ? Xe(e, t, a, n, o, s, u) : Kt(e, a, n, o, s);
2621
+ }
2622
+ }
2623
+ }
2624
+ function Vs(e, t, { caseSensitive: n = !1, wholeWord: o = !1 } = {}) {
2625
+ const s = [];
2626
+ if (!t) return s;
2627
+ const r = n ? t : t.toLowerCase();
2628
+ return Kt(e, e.getRootId(), r, { caseSensitive: n, wholeWord: o }, s), s;
2629
+ }
2630
+ function js(e, t, n) {
2631
+ const o = e.getRun(t.runId);
2632
+ if (!o) return;
2633
+ const s = o.value ?? "", r = s.slice(0, t.offset) + n + s.slice(t.offset + t.length);
2634
+ e.applyOperation(V(t.runId, { value: r }));
2635
+ }
2636
+ function Ws(e, t, n) {
2637
+ const o = /* @__PURE__ */ new Map();
2638
+ for (const r of t)
2639
+ o.has(r.runId) || o.set(r.runId, []), o.get(r.runId).push(r);
2640
+ const s = [];
2641
+ for (const [r, l] of o) {
2642
+ const a = e.getRun(r);
2643
+ if (!a) continue;
2644
+ let u = a.value ?? "";
2645
+ const i = [...l].sort((c, d) => d.offset - c.offset);
2646
+ for (const c of i)
2647
+ u = u.slice(0, c.offset) + n + u.slice(c.offset + c.length);
2648
+ s.push(V(r, { value: u }));
2649
+ }
2650
+ if (s.length !== 0)
2651
+ if (typeof e.performBatch == "function") e.performBatch(s);
2652
+ else for (const r of s) e.applyOperation(r);
2653
+ }
2654
+ const qs = 200;
2655
+ function Js(e) {
2656
+ const t = document.querySelector(`[data-run-id="${e.runId}"]`), n = t == null ? void 0 : t.firstChild;
2657
+ if (!n || n.nodeType !== 3) return null;
2658
+ const o = Math.min(e.offset, n.length), s = Math.min(e.offset + e.length, n.length);
2659
+ if (o >= s) return null;
2660
+ const r = document.createRange();
2661
+ return r.setStart(n, o), r.setEnd(n, s), r;
2662
+ }
2663
+ function Gs(e) {
2664
+ const t = K(), [n, o] = D(!1), [s, r] = D(""), [l, a] = D(!1), [u, i] = D(!1), [c, d] = D(!1), [p, m] = D(""), [f, b] = D([]), [k, y] = D(0), g = z(null), I = z(null), C = B(() => {
2665
+ const v = Vs(t, s, { caseSensitive: l, wholeWord: u });
2666
+ b(v), y((L) => v.length === 0 ? 0 : Math.min(L, v.length - 1));
2667
+ }, [t, s, l, u]);
2668
+ _(() => {
2669
+ n && (y(0), C());
2670
+ }, [n, s, l, u]), _(() => {
2671
+ if (!n) return;
2672
+ let v = null;
2673
+ const L = t.subscribeAll(() => {
2674
+ v && clearTimeout(v), v = setTimeout(C, qs);
2675
+ });
2676
+ return () => {
2677
+ v && clearTimeout(v), L();
2678
+ };
2679
+ }, [n, t, C]), _(() => {
2680
+ var M;
2681
+ if (!n || typeof Highlight > "u" || !CSS.highlights) return;
2682
+ const v = [];
2683
+ let L = null;
2684
+ if (f.forEach((A, H) => {
2685
+ const F = Js(A);
2686
+ F && (H === k ? L = F : v.push(F));
2687
+ }), CSS.highlights.set("be-find-match", new Highlight(...v)), L) {
2688
+ CSS.highlights.set("be-find-current", new Highlight(L));
2689
+ const A = document.querySelector(`[data-run-id="${(M = f[k]) == null ? void 0 : M.runId}"]`);
2690
+ A == null || A.scrollIntoView({ block: "center", behavior: "smooth" });
2691
+ } else
2692
+ CSS.highlights.delete("be-find-current");
2693
+ return () => {
2694
+ CSS.highlights.delete("be-find-match"), CSS.highlights.delete("be-find-current");
2695
+ };
2696
+ }, [n, f, k]);
2697
+ const w = B(() => {
2698
+ var v;
2699
+ if (n) {
2700
+ (v = I.current) == null || v.select();
2701
+ return;
2702
+ }
2703
+ g.current = document.activeElement, o(!0);
2704
+ }, [n]), S = B(() => {
2705
+ var v, L;
2706
+ o(!1), d(!1), typeof Highlight < "u" && CSS.highlights && (CSS.highlights.delete("be-find-match"), CSS.highlights.delete("be-find-current")), (L = (v = g.current) == null ? void 0 : v.focus) == null || L.call(v), g.current = null;
2707
+ }, []);
2708
+ _(() => {
2709
+ var v;
2710
+ n && ((v = I.current) == null || v.focus());
2711
+ }, [n]), _(() => {
2712
+ const v = e.current;
2713
+ if (!v) return;
2714
+ const L = (M) => {
2715
+ (M.metaKey || M.ctrlKey) && M.key.toLowerCase() === "f" && (M.preventDefault(), w());
2716
+ };
2717
+ return v.addEventListener("keydown", L), () => v.removeEventListener("keydown", L);
2718
+ }, [e, w]);
2719
+ const E = B(() => {
2720
+ f.length !== 0 && y((v) => (v + 1) % f.length);
2721
+ }, [f.length]), x = B(() => {
2722
+ f.length !== 0 && y((v) => (v - 1 + f.length) % f.length);
2723
+ }, [f.length]), R = B(() => {
2724
+ const v = f[k];
2725
+ v && js(t, v, p);
2726
+ }, [t, f, k, p]), O = B(() => {
2727
+ f.length !== 0 && Ws(t, f, p);
2728
+ }, [t, f, p]);
2729
+ return {
2730
+ isOpen: n,
2731
+ open: w,
2732
+ close: S,
2733
+ query: s,
2734
+ setQuery: r,
2735
+ caseSensitive: l,
2736
+ setCaseSensitive: a,
2737
+ wholeWord: u,
2738
+ setWholeWord: i,
2739
+ isReplaceOpen: c,
2740
+ setIsReplaceOpen: d,
2741
+ replacement: p,
2742
+ setReplacement: m,
2743
+ matches: f,
2744
+ currentIndex: k,
2745
+ next: E,
2746
+ prev: x,
2747
+ replaceCurrent: R,
2748
+ replaceAll: O,
2749
+ queryInputRef: I
2750
+ };
2751
+ }
2752
+ function Ys({ store: e, rootId: t, extensions: n, onComment: o, commentAuthorId: s }) {
2753
+ const r = z(null), { onCopy: l, onCut: a, onPaste: u } = rs(), i = Ss(r), c = Ns(r), d = As(r), p = Ks(r), m = Gs(r);
2754
+ return hs(n, r), ms(r), Is(r), /* @__PURE__ */ N(
2755
+ "div",
2756
+ {
2757
+ ref: r,
2758
+ role: "document",
2759
+ "aria-label": "Document editor",
2760
+ onCopy: l,
2761
+ onCut: a,
2762
+ onPaste: u,
2763
+ children: [
2764
+ /* @__PURE__ */ h(zs, { ...m }),
2765
+ /* @__PURE__ */ h(Zo, {}),
2766
+ /* @__PURE__ */ h(lo, { parentId: t, isTopLevel: !0 }),
2767
+ /* @__PURE__ */ h(qo, {}),
2768
+ /* @__PURE__ */ h(
2769
+ Se,
2770
+ {
2771
+ isOpen: i.isOpen,
2772
+ rect: i.rect,
2773
+ commands: i.commands,
2774
+ runId: i.runId,
2775
+ onSelect: i.selectCommand,
2776
+ onClose: i.close
2777
+ }
2778
+ ),
2779
+ /* @__PURE__ */ h(
2780
+ Se,
2781
+ {
2782
+ isOpen: c.isOpen,
2783
+ rect: c.rect,
2784
+ commands: c.commands,
2785
+ runId: c.runId,
2786
+ onSelect: c.selectCommand,
2787
+ onClose: c.close,
2788
+ menuId: "be-emoji-menu",
2789
+ ariaLabel: "Emoji"
2790
+ }
2791
+ ),
2792
+ /* @__PURE__ */ h(
2793
+ Se,
2794
+ {
2795
+ isOpen: d.isOpen,
2796
+ rect: d.rect,
2797
+ commands: d.commands,
2798
+ runId: d.runId,
2799
+ onSelect: d.selectCommand,
2800
+ onClose: d.close,
2801
+ menuId: "be-at-menu",
2802
+ ariaLabel: "Mention"
2803
+ }
2804
+ ),
2805
+ /* @__PURE__ */ h(
2806
+ Fs,
2807
+ {
2808
+ isOpen: p.isOpen,
2809
+ rect: p.rect,
2810
+ kind: p.kind,
2811
+ selection: p.selection,
2812
+ crossSelection: p.crossSelection,
2813
+ marks: p.marks,
2814
+ store: e,
2815
+ onComment: o,
2816
+ commentAuthorId: s
2817
+ }
2818
+ )
2819
+ ]
2820
+ }
2821
+ );
2822
+ }
2823
+ function Kr({
2824
+ editor: e,
2825
+ className: t,
2826
+ style: n,
2827
+ theme: o,
2828
+ getBlockClassName: s,
2829
+ onComment: r,
2830
+ commentAuthorId: l,
2831
+ showCommentsPanel: a,
2832
+ uploadFile: u,
2833
+ maxFileSize: i,
2834
+ children: c
2835
+ }) {
2836
+ const { store: d, registry: p, inlineRegistry: m, extensions: f } = e, b = d.getRootId();
2837
+ return /* @__PURE__ */ N(
2838
+ pn,
2839
+ {
2840
+ store: d,
2841
+ registry: p,
2842
+ inlineRegistry: m,
2843
+ history: d,
2844
+ className: t,
2845
+ style: n,
2846
+ theme: o,
2847
+ getBlockClassName: s,
2848
+ commentAuthorId: l,
2849
+ uploadFile: u,
2850
+ maxFileSize: i,
2851
+ children: [
2852
+ /* @__PURE__ */ h(
2853
+ Ys,
2854
+ {
2855
+ store: d,
2856
+ rootId: b,
2857
+ extensions: f,
2858
+ onComment: r,
2859
+ commentAuthorId: l
2860
+ }
2861
+ ),
2862
+ a && /* @__PURE__ */ h(Sn, { authorId: l }),
2863
+ c
2864
+ ]
2865
+ }
2866
+ );
2867
+ }
2868
+ const Xs = { canUndo: !1, canRedo: !1 };
2869
+ function Qs() {
2870
+ const { history: e } = mn(), t = B(
2871
+ (s) => e ? e.subscribeToHistory(s) : () => {
2872
+ },
2873
+ [e]
2874
+ ), n = B(
2875
+ () => e ? e.getUndoRedoSnapshot() : Xs,
2876
+ [e]
2877
+ ), o = ft(t, n);
2878
+ return e ? {
2879
+ ...o,
2880
+ undo: () => {
2881
+ const s = e.undo();
2882
+ return s && ke(e), s;
2883
+ },
2884
+ redo: () => {
2885
+ const s = e.redo();
2886
+ return s && ke(e), s;
2887
+ },
2888
+ getHistoryLog: () => e.getHistoryLog()
2889
+ } : null;
2890
+ }
2891
+ function zr(e) {
2892
+ const [t, n] = D(() => (e == null ? void 0 : e.getPresence()) ?? /* @__PURE__ */ new Map());
2893
+ return _(() => {
2894
+ if (!e) {
2895
+ n(/* @__PURE__ */ new Map());
2896
+ return;
2897
+ }
2898
+ return n(e.getPresence()), e.onPresenceChange(n);
2899
+ }, [e]), t;
2900
+ }
2901
+ const zt = {
2902
+ '"': { open: "“", close: "”" },
2903
+ "'": { open: "‘", close: "’" }
2904
+ };
2905
+ function Zs(e, t) {
2906
+ const n = zt[e];
2907
+ return t === void 0 || /[\s([{“‘]/.test(t) ? n.open : n.close;
2908
+ }
2909
+ function Ur(e, { enabled: t = !0 } = {}) {
2910
+ const n = K();
2911
+ _(() => {
2912
+ if (!t) return;
2913
+ const o = e.current;
2914
+ if (!o) return;
2915
+ function s(l) {
2916
+ var a;
2917
+ return ((a = n.getBlock(l)) == null ? void 0 : a.type) === "code";
2918
+ }
2919
+ function r(l) {
2920
+ if (l.inputType !== "insertText" || !l.data || l.data.length !== 1) return;
2921
+ const a = l.data, u = zt[a];
2922
+ if (!u) return;
2923
+ const i = Fe();
2924
+ if (i) {
2925
+ if (s(i.blockId)) return;
2926
+ const b = n.getRun(i.runId);
2927
+ if (!b || b.type !== "text") return;
2928
+ l.preventDefault();
2929
+ const k = b.value ?? "", y = k.slice(0, i.startOffset) + u.open + k.slice(i.startOffset, i.endOffset) + u.close + k.slice(i.endOffset);
2930
+ le(() => n.applyOperation(V(b.id, { value: y }))), ae(b.id, i.endOffset + 2);
2931
+ return;
2932
+ }
2933
+ const c = Q();
2934
+ if (!c || s(c.blockId)) return;
2935
+ const d = n.getRun(c.runId);
2936
+ if (!d || d.type !== "text") return;
2937
+ l.preventDefault();
2938
+ const p = d.value ?? "", m = Zs(a, p[c.offset - 1]), f = p.slice(0, c.offset) + m + p.slice(c.offset);
2939
+ le(() => n.applyOperation(V(d.id, { value: f }))), ae(d.id, c.offset + 1);
2940
+ }
2941
+ return o.addEventListener("beforeinput", r), () => o.removeEventListener("beforeinput", r);
2942
+ }, [e, n, t]);
2943
+ }
2944
+ const Ut = { "(": ")", "[": "]", "{": "}" }, er = new Set(Object.values(Ut));
2945
+ function Vr(e, { enabled: t = !0 } = {}) {
2946
+ const n = K();
2947
+ _(() => {
2948
+ if (!t) return;
2949
+ const o = e.current;
2950
+ if (!o) return;
2951
+ function s(l) {
2952
+ var a;
2953
+ return ((a = n.getBlock(l)) == null ? void 0 : a.type) === "code";
2954
+ }
2955
+ function r(l) {
2956
+ if (l.inputType !== "insertText" || !l.data || l.data.length !== 1) return;
2957
+ const a = l.data, u = Ut[a];
2958
+ if (u) {
2959
+ const i = Fe();
2960
+ if (i) {
2961
+ if (s(i.blockId)) return;
2962
+ const f = n.getRun(i.runId);
2963
+ if (!f || f.type !== "text") return;
2964
+ l.preventDefault();
2965
+ const b = f.value ?? "", k = b.slice(0, i.startOffset) + a + b.slice(i.startOffset, i.endOffset) + u + b.slice(i.endOffset);
2966
+ le(() => n.applyOperation(V(f.id, { value: k }))), ae(f.id, i.endOffset + 2);
2967
+ return;
2968
+ }
2969
+ const c = Q();
2970
+ if (!c || s(c.blockId)) return;
2971
+ const d = n.getRun(c.runId);
2972
+ if (!d || d.type !== "text") return;
2973
+ l.preventDefault();
2974
+ const p = d.value ?? "", m = p.slice(0, c.offset) + a + u + p.slice(c.offset);
2975
+ le(() => n.applyOperation(V(d.id, { value: m }))), ae(d.id, c.offset + 1);
2976
+ return;
2977
+ }
2978
+ if (er.has(a)) {
2979
+ const i = Q();
2980
+ if (!i || s(i.blockId)) return;
2981
+ const c = n.getRun(i.runId);
2982
+ if (!c || c.type !== "text") return;
2983
+ (c.value ?? "")[i.offset] === a && (l.preventDefault(), ae(c.id, i.offset + 1));
2984
+ }
2985
+ }
2986
+ return o.addEventListener("beforeinput", r), () => o.removeEventListener("beforeinput", r);
2987
+ }, [e, n, t]);
2988
+ }
2989
+ function tr({ isOpen: e, onClose: t, onSelectCommand: n }) {
2990
+ const o = ce(), s = Z(), r = de(
2991
+ () => [
2992
+ ...(o == null ? void 0 : o.listSlashCommands()) ?? [],
2993
+ ...(s == null ? void 0 : s.listSlashCommands()) ?? []
2994
+ ],
2995
+ [o, s]
2996
+ );
2997
+ return /* @__PURE__ */ h(ve, { isOpen: e, onClose: t, title: "Add a block", variant: "sheet", children: /* @__PURE__ */ h("div", { className: "be-mobile-picker-list", role: "listbox", "aria-label": "Insertable blocks", children: r.map((l) => {
2998
+ const a = l.icon;
2999
+ return /* @__PURE__ */ N(
3000
+ "button",
3001
+ {
3002
+ type: "button",
3003
+ role: "option",
3004
+ className: "be-mobile-picker-item",
3005
+ onClick: () => n(l),
3006
+ children: [
3007
+ a && /* @__PURE__ */ h("span", { className: "be-mobile-picker-item-icon", children: /* @__PURE__ */ h(a, { size: 18 }) }),
3008
+ /* @__PURE__ */ h("span", { className: "be-mobile-picker-item-label", children: l.label })
3009
+ ]
3010
+ },
3011
+ l.label
3012
+ );
3013
+ }) }) });
3014
+ }
3015
+ function nr({ isOpen: e, onClose: t, store: n, blockId: o }) {
3016
+ var a;
3017
+ const s = o ? n.getBlock(o) : null, r = !!((a = s == null ? void 0 : s.props) != null && a.hidden), l = B(
3018
+ (u) => {
3019
+ u(), t();
3020
+ },
3021
+ [t]
3022
+ );
3023
+ return /* @__PURE__ */ h(ve, { isOpen: e, onClose: t, title: "Block options", variant: "sheet", children: /* @__PURE__ */ N("div", { className: "be-mobile-picker-list", role: "menu", "aria-label": "Block options", children: [
3024
+ /* @__PURE__ */ N(
3025
+ "button",
3026
+ {
3027
+ type: "button",
3028
+ role: "menuitem",
3029
+ className: "be-mobile-picker-item",
3030
+ onClick: () => l(() => {
3031
+ io(n, o), W("Block duplicated");
3032
+ }),
3033
+ children: [
3034
+ /* @__PURE__ */ h("span", { className: "be-mobile-picker-item-icon", children: /* @__PURE__ */ h(et, { size: 18 }) }),
3035
+ /* @__PURE__ */ h("span", { className: "be-mobile-picker-item-label", children: "Duplicate" })
3036
+ ]
3037
+ }
3038
+ ),
3039
+ /* @__PURE__ */ N(
3040
+ "button",
3041
+ {
3042
+ type: "button",
3043
+ role: "menuitem",
3044
+ className: "be-mobile-picker-item",
3045
+ onClick: () => l(() => {
3046
+ co(n, o) && W("Block moved up");
3047
+ }),
3048
+ children: [
3049
+ /* @__PURE__ */ h("span", { className: "be-mobile-picker-item-icon", children: /* @__PURE__ */ h(_e, { size: 18 }) }),
3050
+ /* @__PURE__ */ h("span", { className: "be-mobile-picker-item-label", children: "Move up" })
3051
+ ]
3052
+ }
3053
+ ),
3054
+ /* @__PURE__ */ N(
3055
+ "button",
3056
+ {
3057
+ type: "button",
3058
+ role: "menuitem",
3059
+ className: "be-mobile-picker-item",
3060
+ onClick: () => l(() => {
3061
+ uo(n, o) && W("Block moved down");
3062
+ }),
3063
+ children: [
3064
+ /* @__PURE__ */ h("span", { className: "be-mobile-picker-item-icon", children: /* @__PURE__ */ h($e, { size: 18 }) }),
3065
+ /* @__PURE__ */ h("span", { className: "be-mobile-picker-item-label", children: "Move down" })
3066
+ ]
3067
+ }
3068
+ ),
3069
+ /* @__PURE__ */ N(
3070
+ "button",
3071
+ {
3072
+ type: "button",
3073
+ role: "menuitem",
3074
+ className: "be-mobile-picker-item",
3075
+ onClick: () => l(() => {
3076
+ n.applyOperation(Ie(o, { hidden: !r })), W(r ? "Block shown in preview" : "Block hidden in preview");
3077
+ }),
3078
+ children: [
3079
+ /* @__PURE__ */ h("span", { className: "be-mobile-picker-item-icon", children: r ? /* @__PURE__ */ h(tt, { size: 18 }) : /* @__PURE__ */ h(nt, { size: 18 }) }),
3080
+ /* @__PURE__ */ h("span", { className: "be-mobile-picker-item-label", children: r ? "Show in preview" : "Hide in preview" })
3081
+ ]
3082
+ }
3083
+ ),
3084
+ /* @__PURE__ */ N(
3085
+ "button",
3086
+ {
3087
+ type: "button",
3088
+ role: "menuitem",
3089
+ className: "be-mobile-picker-item be-mobile-picker-item-danger",
3090
+ onClick: () => l(() => {
3091
+ fo(n, o), W("Block deleted");
3092
+ }),
3093
+ children: [
3094
+ /* @__PURE__ */ h("span", { className: "be-mobile-picker-item-icon", children: /* @__PURE__ */ h(ot, { size: 18 }) }),
3095
+ /* @__PURE__ */ h("span", { className: "be-mobile-picker-item-label", children: "Delete" })
3096
+ ]
3097
+ }
3098
+ )
3099
+ ] }) });
3100
+ }
3101
+ const or = bo.map((e) => ({ value: e, label: e }));
3102
+ function sr(e, t) {
3103
+ const [n, o] = D(!1), [s, r] = D(null), [l, a] = D(null), [u, i] = D(null);
3104
+ return _(() => {
3105
+ const c = e.current;
3106
+ if (!c) return;
3107
+ const d = () => o(!0), p = (m) => {
3108
+ c.contains(m.relatedTarget) || o(!1);
3109
+ };
3110
+ return c.addEventListener("focusin", d), c.addEventListener("focusout", p), () => {
3111
+ c.removeEventListener("focusin", d), c.removeEventListener("focusout", p);
3112
+ };
3113
+ }, [e]), _(() => {
3114
+ if (!n) {
3115
+ r(null);
3116
+ return;
3117
+ }
3118
+ const c = () => {
3119
+ var f;
3120
+ const d = e.current, p = (f = window.getSelection) == null ? void 0 : f.call(window);
3121
+ if (!d || !p || p.rangeCount === 0) {
3122
+ r(null);
3123
+ return;
3124
+ }
3125
+ if (!p.isCollapsed) {
3126
+ if (!d.contains(p.anchorNode) || !d.contains(p.focusNode)) {
3127
+ r(null);
3128
+ return;
3129
+ }
3130
+ const b = me();
3131
+ if (b) {
3132
+ a({
3133
+ kind: "same-block",
3134
+ selection: b,
3135
+ crossSelection: null,
3136
+ marks: Nt(t, b.blockId, b)
3137
+ }), r("selection");
3138
+ return;
3139
+ }
3140
+ const k = fe(t);
3141
+ if (k) {
3142
+ a({
3143
+ kind: "cross-block",
3144
+ selection: null,
3145
+ crossSelection: k,
3146
+ marks: Mt(t, k)
3147
+ }), r("selection");
3148
+ return;
3149
+ }
3150
+ r(null);
3151
+ return;
3152
+ }
3153
+ const m = Q();
3154
+ if (!m || !d.contains(p.anchorNode)) {
3155
+ r(null);
3156
+ return;
3157
+ }
3158
+ i(m), r("caret");
3159
+ };
3160
+ return c(), document.addEventListener("selectionchange", c), () => document.removeEventListener("selectionchange", c);
3161
+ }, [n, t, e]), { isFocused: n, mode: s, selectionState: l, caretState: u };
3162
+ }
3163
+ function rr({ store: e, selectionState: t }) {
3164
+ const { kind: n, selection: o, crossSelection: s, marks: r } = t, { toggleBoolean: l, openLinkModal: a } = Ht(
3165
+ e,
3166
+ n,
3167
+ o,
3168
+ s,
3169
+ r
3170
+ );
3171
+ return /* @__PURE__ */ N(X, { children: [
3172
+ /* @__PURE__ */ h(
3173
+ "button",
3174
+ {
3175
+ type: "button",
3176
+ className: `be-mobile-bar-btn${r.bold ? " be-mobile-bar-btn-active" : ""}`,
3177
+ "aria-label": "Bold",
3178
+ onClick: () => l("bold"),
3179
+ children: /* @__PURE__ */ h(at, { size: 18 })
3180
+ }
3181
+ ),
3182
+ /* @__PURE__ */ h(
3183
+ "button",
3184
+ {
3185
+ type: "button",
3186
+ className: `be-mobile-bar-btn${r.italic ? " be-mobile-bar-btn-active" : ""}`,
3187
+ "aria-label": "Italic",
3188
+ onClick: () => l("italic"),
3189
+ children: /* @__PURE__ */ h(lt, { size: 18 })
3190
+ }
3191
+ ),
3192
+ /* @__PURE__ */ h(
3193
+ "button",
3194
+ {
3195
+ type: "button",
3196
+ className: `be-mobile-bar-btn${r.underline ? " be-mobile-bar-btn-active" : ""}`,
3197
+ "aria-label": "Underline",
3198
+ onClick: () => l("underline"),
3199
+ children: /* @__PURE__ */ h(it, { size: 18 })
3200
+ }
3201
+ ),
3202
+ /* @__PURE__ */ h(
3203
+ "button",
3204
+ {
3205
+ type: "button",
3206
+ className: `be-mobile-bar-btn${r.link ? " be-mobile-bar-btn-active" : ""}`,
3207
+ "aria-label": "Link",
3208
+ onClick: a,
3209
+ children: /* @__PURE__ */ h(ct, { size: 18 })
3210
+ }
3211
+ )
3212
+ ] });
3213
+ }
3214
+ function ar({ store: e, blockId: t }) {
3215
+ const n = B(() => {
3216
+ const s = e.getBlock(t), r = s && e.getBlock(s.parentId);
3217
+ r && mo(e, r.id);
3218
+ }, [e, t]), o = B(() => {
3219
+ const s = e.getBlock(t), r = s && e.getBlock(s.parentId), l = r && e.getBlock(r.parentId);
3220
+ if (!l || !r) return;
3221
+ const a = r.contentIds.indexOf(t);
3222
+ a !== -1 && ho(e, l.id, a);
3223
+ }, [e, t]);
3224
+ return /* @__PURE__ */ N(X, { children: [
3225
+ /* @__PURE__ */ h(
3226
+ "button",
3227
+ {
3228
+ type: "button",
3229
+ className: "be-mobile-bar-btn",
3230
+ "aria-label": "Insert row below",
3231
+ onClick: n,
3232
+ children: "+ Row"
3233
+ }
3234
+ ),
3235
+ /* @__PURE__ */ h(
3236
+ "button",
3237
+ {
3238
+ type: "button",
3239
+ className: "be-mobile-bar-btn",
3240
+ "aria-label": "Insert column right",
3241
+ onClick: o,
3242
+ children: "+ Column"
3243
+ }
3244
+ )
3245
+ ] });
3246
+ }
3247
+ function lr({ store: e, blockId: t }) {
3248
+ var s;
3249
+ const n = e.getBlock(t), o = B(
3250
+ (r) => e.applyOperation(Ie(t, { language: r })),
3251
+ [e, t]
3252
+ );
3253
+ return /* @__PURE__ */ h(
3254
+ gt,
3255
+ {
3256
+ className: "be-mobile-bar-select",
3257
+ value: ((s = n == null ? void 0 : n.props) == null ? void 0 : s.language) ?? "plaintext",
3258
+ options: or,
3259
+ onChange: o,
3260
+ ariaLabel: "Code language"
3261
+ }
3262
+ );
3263
+ }
3264
+ function ir({ store: e, blockId: t }) {
3265
+ var s;
3266
+ const n = e.getBlock(t), o = (s = n == null ? void 0 : n.props) == null ? void 0 : s.color;
3267
+ return /* @__PURE__ */ h("div", { className: "be-mobile-bar-swatches", children: po.map((r) => /* @__PURE__ */ h(
3268
+ "button",
3269
+ {
3270
+ type: "button",
3271
+ className: `be-callout-color-option be-callout-color-option-${r.value}${r.value === o ? " be-callout-color-option-active" : ""}`,
3272
+ "aria-label": r.label,
3273
+ title: r.label,
3274
+ onClick: () => e.applyOperation(Ie(t, { color: r.value }))
3275
+ },
3276
+ r.value
3277
+ )) });
3278
+ }
3279
+ const Vt = {
3280
+ tableCell: ar,
3281
+ code: lr,
3282
+ callout: ir
3283
+ };
3284
+ function cr(e, t) {
3285
+ let n = e.getBlock(t);
3286
+ for (; n; ) {
3287
+ if (Vt[n.type]) return n;
3288
+ n = n.parentId ? e.getBlock(n.parentId) : null;
3289
+ }
3290
+ return null;
3291
+ }
3292
+ function ur(e, t) {
3293
+ const n = e.getRootId();
3294
+ let o = e.getBlock(t);
3295
+ for (; o && o.parentId !== n; )
3296
+ o = e.getBlock(o.parentId);
3297
+ return o;
3298
+ }
3299
+ function jr({ containerRef: e }) {
3300
+ var E, x;
3301
+ const t = K(), n = Qs(), o = Ft(), s = bt(), { isFocused: r, mode: l, selectionState: a, caretState: u } = sr(e, t), [i, c] = D(!1), [d, p] = D(!1), m = B(() => c(!0), []), f = B(() => c(!1), []), b = B(() => p(!0), []), k = B(() => p(!1), []), y = B(
3302
+ (R) => {
3303
+ const O = Q() ?? u;
3304
+ O && (R.run(t, {
3305
+ blockId: O.blockId,
3306
+ runId: O.runId,
3307
+ sliceStart: O.offset,
3308
+ sliceEnd: O.offset
3309
+ }), f());
3310
+ },
3311
+ [t, u, f]
3312
+ ), g = B(() => {
3313
+ var R, O;
3314
+ (O = (R = document.activeElement) == null ? void 0 : R.blur) == null || O.call(R);
3315
+ }, []);
3316
+ if (!o || !r) return null;
3317
+ const I = l === "caret" && u ? cr(t, u.blockId) : null, C = I ? Vt[I.type] : null, w = l === "caret" && u ? u.blockId : ((E = a == null ? void 0 : a.selection) == null ? void 0 : E.blockId) ?? ((x = a == null ? void 0 : a.crossSelection) == null ? void 0 : x.startBlockId) ?? null, S = w ? ur(t, w) : null;
3318
+ return /* @__PURE__ */ N(X, { children: [
3319
+ /* @__PURE__ */ N(
3320
+ "div",
3321
+ {
3322
+ className: "be-mobile-action-bar",
3323
+ role: "toolbar",
3324
+ "aria-label": "Editor actions",
3325
+ style: { bottom: s },
3326
+ onMouseDown: (R) => R.preventDefault(),
3327
+ children: [
3328
+ l === "selection" && a && /* @__PURE__ */ h(rr, { store: t, selectionState: a }),
3329
+ l !== "selection" && /* @__PURE__ */ N(X, { children: [
3330
+ /* @__PURE__ */ h(
3331
+ "button",
3332
+ {
3333
+ type: "button",
3334
+ className: "be-mobile-bar-btn",
3335
+ "aria-label": "Add block",
3336
+ onClick: m,
3337
+ children: /* @__PURE__ */ h(hn, { size: 18 })
3338
+ }
3339
+ ),
3340
+ C && I && /* @__PURE__ */ h(C, { store: t, blockId: I.id }),
3341
+ n && /* @__PURE__ */ N(X, { children: [
3342
+ /* @__PURE__ */ h(
3343
+ "button",
3344
+ {
3345
+ type: "button",
3346
+ className: "be-mobile-bar-btn",
3347
+ "aria-label": "Undo",
3348
+ disabled: !n.canUndo,
3349
+ onClick: n.undo,
3350
+ children: "↶"
3351
+ }
3352
+ ),
3353
+ /* @__PURE__ */ h(
3354
+ "button",
3355
+ {
3356
+ type: "button",
3357
+ className: "be-mobile-bar-btn",
3358
+ "aria-label": "Redo",
3359
+ disabled: !n.canRedo,
3360
+ onClick: n.redo,
3361
+ children: "↷"
3362
+ }
3363
+ )
3364
+ ] })
3365
+ ] }),
3366
+ /* @__PURE__ */ h("span", { className: "be-mobile-bar-spacer" }),
3367
+ S && /* @__PURE__ */ h(
3368
+ "button",
3369
+ {
3370
+ type: "button",
3371
+ className: "be-mobile-bar-btn",
3372
+ "aria-label": "Block options",
3373
+ onClick: b,
3374
+ children: /* @__PURE__ */ h(bn, { size: 18 })
3375
+ }
3376
+ ),
3377
+ /* @__PURE__ */ h(
3378
+ "button",
3379
+ {
3380
+ type: "button",
3381
+ className: "be-mobile-bar-btn",
3382
+ "aria-label": "Dismiss keyboard",
3383
+ onClick: g,
3384
+ children: /* @__PURE__ */ h(gn, { size: 18 })
3385
+ }
3386
+ )
3387
+ ]
3388
+ }
3389
+ ),
3390
+ /* @__PURE__ */ h(
3391
+ tr,
3392
+ {
3393
+ isOpen: i,
3394
+ onClose: f,
3395
+ onSelectCommand: y
3396
+ }
3397
+ ),
3398
+ /* @__PURE__ */ h(
3399
+ nr,
3400
+ {
3401
+ isOpen: d,
3402
+ onClose: k,
3403
+ store: t,
3404
+ blockId: S == null ? void 0 : S.id
3405
+ }
3406
+ )
3407
+ ] });
3408
+ }
3409
+ const dr = [
3410
+ { value: "json", label: "JSON" },
3411
+ { value: "simpleJson", label: "Simple JSON" },
3412
+ { value: "html", label: "HTML" },
3413
+ { value: "markdown", label: "Markdown" },
3414
+ { value: "text", label: "Text" }
3415
+ ];
3416
+ function Wr({ label: e = "View source", className: t = "" }) {
3417
+ const n = K(), o = ce(), s = Z(), [r, l] = D(!1), [a, u] = D("json"), [i, c] = D(!1), d = B(() => {
3418
+ c(!1), l(!0);
3419
+ }, []), p = B(() => l(!1), []), m = de(() => r ? a === "json" ? Yt(n) : a === "simpleJson" ? Ot(n, o, s) : a === "html" ? Xt(n, o, s) : a === "markdown" ? Qt(n, o, s) : Zt(n, o, s) : "", [r, a, n, o, s]), f = B(async () => {
3420
+ try {
3421
+ await navigator.clipboard.writeText(m), c(!0), setTimeout(() => c(!1), 1500);
3422
+ } catch {
3423
+ }
3424
+ }, [m]), b = B(() => {
3425
+ const y = en(n, o, s), g = document.createElement("a");
3426
+ g.href = `data:application/msword;charset=utf-8,${encodeURIComponent(y)}`, g.download = "document.doc", document.body.appendChild(g), g.click(), document.body.removeChild(g);
3427
+ }, [n, o, s]), k = B(() => {
3428
+ window.print();
3429
+ }, []);
3430
+ return /* @__PURE__ */ N(X, { children: [
3431
+ /* @__PURE__ */ N("button", { type: "button", className: `be-export-trigger ${t}`.trim(), onClick: d, children: [
3432
+ /* @__PURE__ */ h(kn, { size: 14 }),
3433
+ " ",
3434
+ e
3435
+ ] }),
3436
+ /* @__PURE__ */ N(ve, { isOpen: r, onClose: p, title: "Document source", size: "large", children: [
3437
+ /* @__PURE__ */ h("div", { className: "be-export-tabs", role: "tablist", children: dr.map((y) => /* @__PURE__ */ h(
3438
+ "button",
3439
+ {
3440
+ type: "button",
3441
+ role: "tab",
3442
+ "aria-selected": a === y.value,
3443
+ className: `be-export-tab${a === y.value ? " be-export-tab-active" : ""}`,
3444
+ onClick: () => u(y.value),
3445
+ children: y.label
3446
+ },
3447
+ y.value
3448
+ )) }),
3449
+ /* @__PURE__ */ h("pre", { className: "be-export-pre", children: /* @__PURE__ */ h("code", { children: m }) }),
3450
+ /* @__PURE__ */ N("div", { className: "be-modal-actions", children: [
3451
+ /* @__PURE__ */ h("button", { type: "button", className: "be-modal-cancel", onClick: p, children: "Close" }),
3452
+ /* @__PURE__ */ h("button", { type: "button", className: "be-export-download", onClick: k, children: "Print / Save as PDF" }),
3453
+ /* @__PURE__ */ h("button", { type: "button", className: "be-export-download", onClick: b, children: "Download Word (.doc)" }),
3454
+ /* @__PURE__ */ h("button", { type: "button", className: "be-modal-save", onClick: f, children: i ? "Copied!" : "Copy" })
3455
+ ] })
3456
+ ] })
3457
+ ] });
3458
+ }
3459
+ function fr({
3460
+ id: e,
3461
+ blockId: t,
3462
+ label: n,
3463
+ placeholder: o,
3464
+ variant: s,
3465
+ options: r,
3466
+ onManage: l,
3467
+ mention: a = !1
3468
+ }) {
3469
+ const u = K(), i = Tn(e), c = z(null);
3470
+ c.current === null && (c.current = go(e));
3471
+ const d = B(
3472
+ (b, k) => {
3473
+ u.applyOperation(
3474
+ V(e, {
3475
+ data: { selectedValue: b, selectedLabel: (k == null ? void 0 : k.label) ?? "", selectedColor: k == null ? void 0 : k.color }
3476
+ })
3477
+ ), c.current && ko(u, t, e);
3478
+ },
3479
+ [u, e, t]
3480
+ );
3481
+ if (!i) return null;
3482
+ const { selectedValue: p = "", selectedLabel: m = "", selectedColor: f } = i.data ?? {};
3483
+ return /* @__PURE__ */ h(
3484
+ "span",
3485
+ {
3486
+ className: "be-inline-select",
3487
+ onMouseDown: (b) => {
3488
+ b.preventDefault(), b.stopPropagation();
3489
+ },
3490
+ onKeyDown: (b) => b.stopPropagation(),
3491
+ children: /* @__PURE__ */ h(
3492
+ gt,
3493
+ {
3494
+ value: p,
3495
+ selectedLabel: m,
3496
+ selectedColor: f,
3497
+ options: r,
3498
+ onChange: d,
3499
+ placeholder: o,
3500
+ variant: s,
3501
+ ariaLabel: n,
3502
+ onManageOptions: l,
3503
+ mention: a,
3504
+ autoOpen: c.current
3505
+ }
3506
+ )
3507
+ }
3508
+ );
3509
+ }
3510
+ function jt(e) {
3511
+ return String(e).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
3512
+ }
3513
+ function Qe(e) {
3514
+ return jt(e).replace(/"/g, "&quot;");
3515
+ }
3516
+ function pr({
3517
+ type: e,
3518
+ label: t,
3519
+ placeholder: n = "Select…",
3520
+ variant: o = "default",
3521
+ icon: s,
3522
+ options: r,
3523
+ onManage: l,
3524
+ triggers: a = ["slash"],
3525
+ // Defaults to true for an @-reachable type (Assignee, Reviewer, ...): a
3526
+ // picked chip renders as "@Name" in a fixed accent color rather than each
3527
+ // option's own tag color, matching how @mentions read everywhere else —
3528
+ // a consistent mention style, not a per-person palette. Pass
3529
+ // `mention: false` to opt an @-triggered type out of this
3530
+ // (e.g. it's reachable via "@" but isn't really a "who" mention).
3531
+ mention: u = a.includes("at")
3532
+ }) {
3533
+ function i(f) {
3534
+ var y, g;
3535
+ const b = ((y = f.data) == null ? void 0 : y.selectedLabel) || "", k = u && b ? `@${b}` : b;
3536
+ return `<span data-inline-type="${Qe(e)}" data-selected-value="${Qe(((g = f.data) == null ? void 0 : g.selectedValue) ?? "")}">${jt(k)}</span>`;
3537
+ }
3538
+ function c(f) {
3539
+ var k;
3540
+ const b = ((k = f.data) == null ? void 0 : k.selectedLabel) ?? "";
3541
+ return u && b ? `@${b}` : b;
3542
+ }
3543
+ function d(f) {
3544
+ var y;
3545
+ if (((y = f.getAttribute) == null ? void 0 : y.call(f, "data-inline-type")) !== e) return null;
3546
+ const b = f.textContent ?? "", k = u && b.startsWith("@") ? b.slice(1) : b;
3547
+ return {
3548
+ id: $(),
3549
+ type: e,
3550
+ value: "",
3551
+ marks: {},
3552
+ data: {
3553
+ selectedValue: f.getAttribute("data-selected-value") ?? "",
3554
+ selectedLabel: k
3555
+ }
3556
+ };
3557
+ }
3558
+ function p({ id: f, blockId: b }) {
3559
+ return /* @__PURE__ */ h(
3560
+ fr,
3561
+ {
3562
+ id: f,
3563
+ blockId: b,
3564
+ label: t,
3565
+ placeholder: n,
3566
+ variant: o,
3567
+ options: r,
3568
+ onManage: l,
3569
+ mention: u
3570
+ }
3571
+ );
3572
+ }
3573
+ const m = {
3574
+ label: t,
3575
+ // Falls back to the same icon the built-in generic `select` inline
3576
+ // type's own slash command uses (see inlineTypes/select/index.js) —
3577
+ // every custom field type (host-defined or created in-editor via
3578
+ // FieldTypeEditorModal, which has no way to let a user pick an icon at
3579
+ // all) gets a consistent, non-blank glyph in the "/"/"@" menu instead
3580
+ // of silently rendering with no icon at all next to every other entry
3581
+ // that has one. A host can still override it by passing its own
3582
+ // `icon` in the config, same as before.
3583
+ icon: s ?? yn,
3584
+ keywords: [t.toLowerCase(), "select", "field"],
3585
+ run: (f, { blockId: b, runId: k, sliceStart: y, sliceEnd: g }) => yo(
3586
+ f,
3587
+ { blockId: b, runId: k, sliceStart: y, sliceEnd: g },
3588
+ () => ({
3589
+ id: $(),
3590
+ type: e,
3591
+ value: "",
3592
+ marks: {},
3593
+ data: { selectedValue: "", selectedLabel: "", selectedColor: void 0 }
3594
+ }),
3595
+ { autoOpen: !0 }
3596
+ )
3597
+ };
3598
+ return {
3599
+ component: p,
3600
+ isAtomic: !0,
3601
+ toHTML: i,
3602
+ toPlainText: c,
3603
+ fromHTML: d,
3604
+ slashCommand: a.includes("slash") ? m : void 0,
3605
+ atCommand: a.includes("at") ? m : void 0
3606
+ };
3607
+ }
3608
+ function mr(e, t, { onManage: n } = {}) {
3609
+ for (const o of e.getFieldTypes())
3610
+ t.register(
3611
+ o.id,
3612
+ pr({
3613
+ type: o.id,
3614
+ label: o.label,
3615
+ placeholder: o.placeholder,
3616
+ variant: o.variant,
3617
+ options: o.options ?? [],
3618
+ triggers: o.mentionable ? ["slash", "at"] : ["slash"],
3619
+ onManage: n ? () => n(o.id) : void 0
3620
+ })
3621
+ );
3622
+ }
3623
+ function hr() {
3624
+ const e = K(), t = Z(), n = Io(), { openEdit: o } = dt(), s = z([]);
3625
+ _(() => {
3626
+ if (!t) return;
3627
+ const r = new Set(n.map((l) => l.id));
3628
+ for (const l of s.current)
3629
+ r.has(l) || t.unregister(l);
3630
+ mr(e, t, { onManage: o }), s.current = [...r];
3631
+ }, [e, t, n, o]);
3632
+ }
3633
+ function qr() {
3634
+ hr();
3635
+ const e = K(), { target: t, close: n } = dt(), o = t !== null, s = o && t !== "new", [r, l] = D(""), [a, u] = D([]), [i, c] = D(""), [d, p] = D(!1);
3636
+ _(() => {
3637
+ if (o) {
3638
+ if (s) {
3639
+ const g = e.getFieldType(t);
3640
+ l((g == null ? void 0 : g.label) ?? ""), u((g == null ? void 0 : g.options) ?? []), p(!!(g != null && g.mentionable));
3641
+ } else
3642
+ l(""), u([]), p(!1);
3643
+ c("");
3644
+ }
3645
+ }, [o, s, t, e]);
3646
+ const m = B((g, I) => {
3647
+ u((C) => C.map((w) => w.value === g ? { ...w, label: I } : w));
3648
+ }, []), f = B((g) => {
3649
+ u((I) => I.filter((C) => C.value !== g));
3650
+ }, []), b = B(() => {
3651
+ const g = i.trim();
3652
+ c(""), g && u((I) => [...I, { value: $(), label: g, color: Ve(I.length) }]);
3653
+ }, [i]), k = B(() => {
3654
+ const g = r.trim();
3655
+ g && (s ? e.applyOperation(In(t, { label: g, options: a, mentionable: d })) : e.applyOperation(
3656
+ vn({
3657
+ id: $(),
3658
+ label: g,
3659
+ placeholder: "Select…",
3660
+ variant: "tag",
3661
+ options: a,
3662
+ mentionable: d
3663
+ })
3664
+ ), n());
3665
+ }, [e, s, t, r, a, d, n]), y = B(() => {
3666
+ s && e.applyOperation(wn(t)), n();
3667
+ }, [e, s, t, n]);
3668
+ return /* @__PURE__ */ N(ve, { isOpen: o, onClose: n, title: s ? "Edit field type" : "New field type", children: [
3669
+ /* @__PURE__ */ N("label", { className: "be-modal-field", children: [
3670
+ /* @__PURE__ */ h("span", { children: "Name" }),
3671
+ /* @__PURE__ */ h(
3672
+ "input",
3673
+ {
3674
+ type: "text",
3675
+ value: r,
3676
+ onChange: (g) => l(g.target.value),
3677
+ placeholder: "e.g. Priority, Status…",
3678
+ autoFocus: !0
3679
+ }
3680
+ )
3681
+ ] }),
3682
+ /* @__PURE__ */ N("div", { className: "be-modal-field", children: [
3683
+ /* @__PURE__ */ h("span", { children: "Options" }),
3684
+ a.map((g, I) => /* @__PURE__ */ N("div", { className: "be-table-header-menu-option-row", children: [
3685
+ /* @__PURE__ */ h(
3686
+ "span",
3687
+ {
3688
+ className: "be-table-header-menu-option-swatch",
3689
+ style: { background: (g.color ?? Ve(I)).bg },
3690
+ "aria-hidden": "true"
3691
+ }
3692
+ ),
3693
+ /* @__PURE__ */ h(
3694
+ "input",
3695
+ {
3696
+ className: "be-table-header-menu-option-input",
3697
+ value: g.label,
3698
+ onChange: (C) => m(g.value, C.target.value),
3699
+ "aria-label": `Rename option ${g.label}`
3700
+ }
3701
+ ),
3702
+ /* @__PURE__ */ h(
3703
+ "button",
3704
+ {
3705
+ type: "button",
3706
+ className: "be-table-header-menu-option-remove",
3707
+ onClick: () => f(g.value),
3708
+ "aria-label": `Remove option ${g.label}`,
3709
+ children: /* @__PURE__ */ h(ut, { size: 14 })
3710
+ }
3711
+ )
3712
+ ] }, g.value)),
3713
+ /* @__PURE__ */ N("div", { className: "be-table-header-menu-option-row", children: [
3714
+ /* @__PURE__ */ h(
3715
+ "input",
3716
+ {
3717
+ className: "be-table-header-menu-option-input",
3718
+ value: i,
3719
+ onChange: (g) => c(g.target.value),
3720
+ placeholder: "New option…",
3721
+ onKeyDown: (g) => {
3722
+ g.key === "Enter" && (g.preventDefault(), b());
3723
+ }
3724
+ }
3725
+ ),
3726
+ /* @__PURE__ */ h(
3727
+ "button",
3728
+ {
3729
+ type: "button",
3730
+ className: "be-table-header-menu-option-add",
3731
+ onClick: b,
3732
+ "aria-label": "Add option",
3733
+ children: "+"
3734
+ }
3735
+ )
3736
+ ] })
3737
+ ] }),
3738
+ /* @__PURE__ */ N("label", { className: "be-modal-field be-modal-field-checkbox", children: [
3739
+ /* @__PURE__ */ h(
3740
+ "input",
3741
+ {
3742
+ type: "checkbox",
3743
+ checked: d,
3744
+ onChange: (g) => p(g.target.checked)
3745
+ }
3746
+ ),
3747
+ /* @__PURE__ */ h("span", { children: "Also show in @ mentions" })
3748
+ ] }),
3749
+ /* @__PURE__ */ N("div", { className: "be-modal-actions", children: [
3750
+ s && /* @__PURE__ */ h("button", { type: "button", className: "be-modal-delete", onClick: y, children: "Delete field type" }),
3751
+ /* @__PURE__ */ h("button", { type: "button", className: "be-modal-cancel", onClick: n, children: "Cancel" }),
3752
+ /* @__PURE__ */ h("button", { type: "button", className: "be-modal-save", onClick: k, children: "Save" })
3753
+ ] })
3754
+ ] });
3755
+ }
3756
+ export {
3757
+ el as AGGREGATE_LABELS,
3758
+ tl as AGGREGATE_TYPES,
3759
+ Le as APP_MIME,
3760
+ lo as BlockChildren,
3761
+ nl as BlockErrorBoundary,
3762
+ ol as BlockGutterRow,
3763
+ Zo as BlockRangeActionMenu,
3764
+ Eo as BlockRegistry,
3765
+ sl as BlockRenderer,
3766
+ rl as COLUMN_TYPES,
3767
+ ba as CollabSession,
3768
+ Ja as CommentAvatar,
3769
+ Cn as CommentComposer,
3770
+ Fa as CommentThreadCard,
3771
+ Sn as CommentsPanel,
3772
+ al as DEFAULT_COLUMN_TYPE,
3773
+ ll as DEFAULT_COLUMN_WIDTH,
3774
+ Wr as DocumentExportButton,
3775
+ il as EditableBlockContent,
3776
+ pn as EditorProvider,
3777
+ Gt as EditorStore,
3778
+ qo as EditorTrailingSpace,
3779
+ da as FieldClockRegistry,
3780
+ qr as FieldTypeEditorModal,
3781
+ zs as FindBar,
3782
+ Fs as FloatingToolbar,
3783
+ fa as HLC,
3784
+ xo as History,
3785
+ No as InlineRegistry,
3786
+ _o as LAYOUT_BLOCKS,
3787
+ pa as ListCrdtState,
3788
+ ga as MESSAGE_TYPE,
3789
+ cl as MIN_COLUMN_WIDTH,
3790
+ jr as MobileActionBar,
3791
+ nr as MobileBlockOptionsSheet,
3792
+ tr as MobileBlockPickerSheet,
3793
+ ve as Modal,
3794
+ Kr as NoteloomEditor,
3795
+ ka as PeerConnection,
3796
+ gt as Select,
3797
+ Se as SlashMenu,
3798
+ Po as TABLE_BLOCKS,
3799
+ Fo as TABLE_SELECT_INLINE_TYPES,
3800
+ ul as TableHeaderRow,
3801
+ Lr as TemplatePicker,
3802
+ Yr as VersionHistory,
3803
+ Nl as VoiceListeningIndicator,
3804
+ Ml as VoicePermissionModal,
3805
+ Ka as addComment,
3806
+ Rn as addCommentMarkOverRange,
3807
+ Nr as addPerson,
3808
+ Xr as applyDocumentTemplate,
3809
+ _r as autoPairBrackets,
3810
+ dl as blankRunForType,
3811
+ Hn as blockquoteBlockType,
3812
+ Pn as buttonBlockType,
3813
+ Fn as calloutBlockType,
3814
+ On as canvasBlockType,
3815
+ Qr as captureBlockTemplate,
3816
+ El as captureSubtree,
3817
+ qn as checkboxInlineType,
3818
+ $n as codeBlockType,
3819
+ fl as computeColumnAggregate,
3820
+ pl as convertRunToType,
3821
+ Je as copyBlockRangeToClipboard,
3822
+ Pa as createAutoPersistence,
3823
+ Zr as createAutoVersionHistory,
3824
+ Lo as createBlockRegistry,
3825
+ ml as createCellForColumn,
3826
+ hl as createDefaultColumns,
3827
+ Mo as createInlineRegistry,
3828
+ ya as createPeriodicTombstoneGC,
3829
+ pr as createSelectFieldType,
3830
+ Ia as createWebSocketSignaling,
3831
+ Jn as dateInlineType,
3832
+ va as decodeMessage,
3833
+ Ya as defineBlock,
3834
+ pt as defineExtension,
3835
+ Xa as defineInline,
3836
+ fo as deleteBlockAndFocusSibling,
3837
+ be as deleteBlockRange,
3838
+ bl as deleteColumn,
3839
+ za as deleteComment,
3840
+ Ba as deleteDocumentVersion,
3841
+ Ae as deleteEntireDocument,
3842
+ Et as deleteOverBlockRange,
3843
+ Ra as deletePersistedDocument,
3844
+ gl as deleteRow,
3845
+ Tt as deleteRunRangeInBlock,
3846
+ Sa as deleteTemplate,
3847
+ ts as deserializeClipboard,
3848
+ ea as diffDocumentsHTML,
3849
+ Kn as dividerBlockType,
3850
+ io as duplicateBlock,
3851
+ Dn as embedBlockType,
3852
+ Wn as emojiInlineType,
3853
+ wa as encodeMessage,
3854
+ mt as ensureRootNonEmpty,
3855
+ Xt as exportDocumentHTML,
3856
+ Yt as exportDocumentJSON,
3857
+ Qt as exportDocumentMarkdown,
3858
+ Ot as exportDocumentSimpleJSON,
3859
+ Zt as exportDocumentText,
3860
+ en as exportDocumentWordHTML,
3861
+ Vs as findMatches,
3862
+ ne as focusRunAtOffset,
3863
+ re as focusRunEnd,
3864
+ xl as focusRunStart,
3865
+ kl as formatAggregateValue,
3866
+ ma as genPeerId,
3867
+ Mt as getMarksSummaryOverBlockRange,
3868
+ Nt as getMarksSummaryOverSelection,
3869
+ Un as headingBlockType,
3870
+ jo as importDocumentSimpleJSON,
3871
+ ra as injectDefaultStyles,
3872
+ ta as insertBlockTemplate,
3873
+ ho as insertColumnAfter,
3874
+ mo as insertRowAfter,
3875
+ Yo as isEntireBlockRangeHidden,
3876
+ ds as isEntireBlockSelected,
3877
+ Vo as isSimpleDocument,
3878
+ Ln as layoutBlockType,
3879
+ En as layoutColumnBlockType,
3880
+ Oa as listDocumentVersions,
3881
+ zn as listItemBlockType,
3882
+ xa as listPersistedDocumentIds,
3883
+ Ue as listTemplates,
3884
+ Al as listVoiceCommands,
3885
+ Ta as loadDocumentVersion,
3886
+ Ea as loadPersistedDocument,
3887
+ La as loadTemplate,
3888
+ uo as moveBlockDown,
3889
+ Go as moveBlockRangeDown,
3890
+ Jo as moveBlockRangeUp,
3891
+ co as moveBlockUp,
3892
+ aa as operations,
3893
+ Vn as paragraphBlockType,
3894
+ na as registerBlockTemplates,
3895
+ Do as registerBlocks,
3896
+ Ao as registerBuiltInBlocks,
3897
+ $o as registerBuiltInInlineTypes,
3898
+ xn as registerExtensions,
3899
+ Ho as registerInlineTypes,
3900
+ mr as registerStoredFieldTypes,
3901
+ Co as remapSubtreeIds,
3902
+ Bn as removeCommentMarkEverywhere,
3903
+ Ar as removePerson,
3904
+ yl as renameColumn,
3905
+ Hr as reorderBlockRangeFromStore,
3906
+ Ws as replaceAllMatches,
3907
+ js as replaceMatch,
3908
+ Ua as replyToComment,
3909
+ Q as resolveCollapsedCaret,
3910
+ Yn as resolveColumns,
3911
+ Va as resolveComment,
3912
+ fe as resolveCrossBlockSelection,
3913
+ me as resolveMultiRunSelection,
3914
+ Fe as resolveRunSelection,
3915
+ Na as saveDocumentVersion,
3916
+ Ma as savePersistedDocument,
3917
+ Aa as saveTemplate,
3918
+ Gn as selectInlineType,
3919
+ yt as serializeBlockRange,
3920
+ Xo as setBlockRangeHidden,
3921
+ Il as setColumnAggregate,
3922
+ vl as setColumnOptions,
3923
+ wl as setColumnType,
3924
+ Cl as setColumnWidth,
3925
+ De as setMarksOverBlockRange,
3926
+ pe as setMarksOverSelection,
3927
+ Pr as smartQuotes,
3928
+ Bl as sortTableByColumn,
3929
+ Rl as starterKit,
3930
+ An as tableBlockType,
3931
+ Nn as tableCellBlockType,
3932
+ Mn as tableRowBlockType,
3933
+ jn as tableSelectInlineType,
3934
+ xt as textToParagraphs,
3935
+ _n as toggleHeadingBlockType,
3936
+ Fr as toggleMarkOnRunRange,
3937
+ _t as toggleMarkOverBlockRange,
3938
+ Pt as toggleMarkOverSelection,
3939
+ Mr as updatePerson,
3940
+ As as useAtMenuTrigger,
3941
+ Vr as useAutoPairBrackets,
3942
+ Qa as useBlock,
3943
+ Sl as useBlockChildren,
3944
+ la as useBlockClassName,
3945
+ Is as useBlockRangeDrag,
3946
+ Pe as useBlockRangeSelection,
3947
+ ce as useBlockRegistry,
3948
+ Dl as useCaretRect,
3949
+ rs as useClipboardHandlers,
3950
+ Ft as useCoarsePointer,
3951
+ ia as useCommentAuthorId,
3952
+ Wa as useComments,
3953
+ oa as useDocumentVersions,
3954
+ $r as useEditor,
3955
+ ms as useEditorKeyboardShortcuts,
3956
+ K as useEditorStore,
3957
+ Ns as useEmojiMenuTrigger,
3958
+ dt as useFieldTypeEditor,
3959
+ Io as useFieldTypes,
3960
+ an as useFileUpload,
3961
+ Gs as useFindInDocument,
3962
+ Ks as useFloatingToolbarTrigger,
3963
+ Qs as useHistory,
3964
+ Z as useInlineRegistry,
3965
+ Dr as usePeople,
3966
+ _a as usePersistedDocument,
3967
+ zr as usePresence,
3968
+ sn as usePreviewMode,
3969
+ hr as useRegisterFieldTypes,
3970
+ Tn as useRun,
3971
+ ln as useSelectedBlock,
3972
+ $a as useServiceWorkerUpdate,
3973
+ ca as useShowLineNumbers,
3974
+ Ss as useSlashMenuTrigger,
3975
+ Ur as useSmartQuotes,
3976
+ Er as useTemplates,
3977
+ Ht as useTextFormattingActions,
3978
+ bt as useVirtualKeyboardInset,
3979
+ Pl as useVoiceTyping,
3980
+ st as useWholeDocumentSelection,
3981
+ es as walkDomToBlocks
3982
+ };
3983
+ //# sourceMappingURL=index.js.map