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
@@ -0,0 +1,4980 @@
1
+ var no = Object.defineProperty;
2
+ var oo = (e, t, n) => t in e ? no(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var Kt = (e, t, n) => oo(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { u as ze, f as ee, b as ae, g as xe, h as Re, i as Ne, j as at, k as gt, l as fe, e as bt, c as ro } from "./index-B9jyyL8u.js";
5
+ import { jsx as d, jsxs as T, Fragment as Te } from "react/jsx-runtime";
6
+ import { useState as O, useEffect as oe, useCallback as h, useLayoutEffect as rt, useRef as _, useSyncExternalStore as un, Component as lo, Fragment as ao, memo as so, useMemo as je } from "react";
7
+ import { createPortal as Oe } from "react-dom";
8
+ import { l as ie, P as co, X as st, b as dn, a as V, B as Ot, u as io, a6 as Se, o as Ue, g as C, n as q, k as ke, s as Lt, E as se, H as pn, ao as fn, ap as mn, aq as hn, A as gn, ar as bn, as as yn, at as St, ac as Ee, au as kn, av as vn, ai as In, m as yt, $ as uo, j as G, af as wn, aw as po, a0 as fo, I as Tn, J as Cn, a2 as mo, a3 as ho, ax as Bn, ay as Rn, T as Nn, _ as go, ah as Dt, ak as bo, az as yo, aA as ko, aB as vo, an as Io, aC as wo, a4 as To, aD as Co, ab as Ln, aE as An, aF as Bo, aG as Ro, aH as No, r as Lo, aj as Ao, aI as Mo } from "./icons-C1_s0jKK.js";
9
+ import { m as Eo, b as Mn, j as ve, E as En, l as $o, c as U, n as xo, i as Ke, o as Ve, p as le, t as re, a as be, q as $n, u as Oo, d as xn, r as So, f as Do } from "./leafBlockFactory-A9eUhSe-.js";
10
+ import { M as Ht, b as Ho, d as Po, c as On, a as _o, e as Uo } from "./usePopoverEdgeClamp-gmFm0CnI.js";
11
+ import { a as jo } from "./CommentThreadCard-Cxf8GwHJ.js";
12
+ import { c as Fo, r as zo } from "./serialize-T9Odwx24.js";
13
+ function Sn(e) {
14
+ return e ? e.type !== "text" ? !1 : (e.value ?? "") === "" : !0;
15
+ }
16
+ function me(e, t) {
17
+ return !t || t.length === 0 ? !0 : t.every((n) => Sn(e.getRun(n)));
18
+ }
19
+ function kt(e, t) {
20
+ var r, l;
21
+ if (!t) return !1;
22
+ const n = t.contentIds.length > 0, o = (((l = (r = t.props) == null ? void 0 : r.titleRunIds) == null ? void 0 : l.length) ?? 0) > 0;
23
+ return !n && !o;
24
+ }
25
+ function Ko({
26
+ isOpen: e,
27
+ initialHref: t,
28
+ initialTarget: n,
29
+ hasExistingLink: o,
30
+ onSave: r,
31
+ onRemove: l,
32
+ onClose: a
33
+ }) {
34
+ const [s, c] = O(""), [u, p] = O("_self");
35
+ oe(() => {
36
+ e && (c(t), p(n));
37
+ }, [e]);
38
+ const i = s.trim(), f = h(
39
+ (b) => {
40
+ b.preventDefault(), i && r(i, u);
41
+ },
42
+ [i, u, r]
43
+ );
44
+ return /* @__PURE__ */ d(Ht, { isOpen: e, onClose: a, title: o ? "Edit link" : "Add link", children: /* @__PURE__ */ T("form", { onSubmit: f, children: [
45
+ /* @__PURE__ */ T("label", { className: "be-modal-field", children: [
46
+ /* @__PURE__ */ d("span", { children: "URL" }),
47
+ /* @__PURE__ */ d(
48
+ "input",
49
+ {
50
+ type: "text",
51
+ value: s,
52
+ onChange: (b) => c(b.target.value),
53
+ placeholder: "https://example.com",
54
+ autoFocus: !0
55
+ }
56
+ )
57
+ ] }),
58
+ /* @__PURE__ */ T("label", { className: "be-modal-field", children: [
59
+ /* @__PURE__ */ d("span", { children: "Open in" }),
60
+ /* @__PURE__ */ T("select", { value: u, onChange: (b) => p(b.target.value), children: [
61
+ /* @__PURE__ */ d("option", { value: "_self", children: "Same tab" }),
62
+ /* @__PURE__ */ d("option", { value: "_blank", children: "New tab" })
63
+ ] })
64
+ ] }),
65
+ /* @__PURE__ */ T("div", { className: "be-modal-actions", children: [
66
+ o && /* @__PURE__ */ d("button", { type: "button", className: "be-modal-delete", onClick: l, children: "Remove link" }),
67
+ /* @__PURE__ */ d("button", { type: "button", className: "be-modal-cancel", onClick: a, children: "Cancel" }),
68
+ /* @__PURE__ */ d("button", { type: "submit", className: "be-modal-save", disabled: !i, children: "Save" })
69
+ ] })
70
+ ] }) });
71
+ }
72
+ function vt(e, t, n, o) {
73
+ const [r, l] = O(null);
74
+ return rt(() => {
75
+ if (n == null || o == null) {
76
+ l(null);
77
+ return;
78
+ }
79
+ l({ top: n, left: o });
80
+ }, [n, o]), rt(() => {
81
+ if (!t || !e.current || !r) return;
82
+ const a = e.current.getBoundingClientRect(), s = Ho(r.left, a.width), c = Po(r.top, a.height);
83
+ (s !== r.left || c !== r.top) && l({ top: c, left: s });
84
+ }, [t, e, r]), r;
85
+ }
86
+ function Vo({ containerRef: e, store: t }) {
87
+ var m;
88
+ const [n, o] = O(null), [r, l] = O(!1), a = _(null), s = _(null), c = h(() => {
89
+ a.current && (clearTimeout(a.current), a.current = null);
90
+ }, []), u = h(() => {
91
+ c(), a.current = setTimeout(() => {
92
+ o((y) => r ? y : null);
93
+ }, 250);
94
+ }, [c, r]);
95
+ oe(() => {
96
+ const y = e.current;
97
+ if (!y) return;
98
+ const B = (D) => {
99
+ var F, w, N;
100
+ const S = (w = (F = D.target).closest) == null ? void 0 : w.call(F, "[data-run-id]");
101
+ if (!S || !y.contains(S)) return;
102
+ const $ = S.dataset.runId, A = t.getRun($);
103
+ (N = A == null ? void 0 : A.marks) != null && N.link && (c(), o(
104
+ (x) => (x == null ? void 0 : x.runId) === $ ? x : { runId: $, rect: S.getBoundingClientRect() }
105
+ ));
106
+ }, L = () => u();
107
+ return y.addEventListener("mouseover", B), y.addEventListener("mouseout", L), () => {
108
+ y.removeEventListener("mouseover", B), y.removeEventListener("mouseout", L);
109
+ };
110
+ }, [e, t, c, u]), oe(() => () => c(), [c]);
111
+ const p = h(() => l(!0), []), i = h(() => {
112
+ l(!1), o(null);
113
+ }, []), f = h(
114
+ (y, B) => {
115
+ if (!n) return;
116
+ const L = t.getRun(n.runId);
117
+ L && (t.applyOperation(
118
+ ie(n.runId, { marks: { ...L.marks, link: { href: y, target: B } } })
119
+ ), i());
120
+ },
121
+ [n, t, i]
122
+ ), b = h(() => {
123
+ if (!n) return;
124
+ const y = t.getRun(n.runId);
125
+ if (!y) return;
126
+ const B = { ...y.marks };
127
+ delete B.link, t.applyOperation(ie(n.runId, { marks: B })), i();
128
+ }, [n, t, i]), v = n && t.getRun(n.runId), g = (m = v == null ? void 0 : v.marks) == null ? void 0 : m.link, k = !!(n && g && !r), I = vt(
129
+ s,
130
+ k,
131
+ n ? n.rect.bottom + 6 : null,
132
+ n ? n.rect.left : null
133
+ );
134
+ return /* @__PURE__ */ T(Te, { children: [
135
+ k && I ? Oe(
136
+ /* @__PURE__ */ T(
137
+ "div",
138
+ {
139
+ ref: s,
140
+ className: "be-link-hover-card",
141
+ contentEditable: !1,
142
+ style: { position: "fixed", top: I.top, left: I.left },
143
+ onMouseEnter: c,
144
+ onMouseLeave: u,
145
+ children: [
146
+ /* @__PURE__ */ d(
147
+ "a",
148
+ {
149
+ className: "be-link-hover-card-url",
150
+ href: g.href,
151
+ target: g.target === "_blank" ? "_blank" : "_self",
152
+ rel: "noopener noreferrer",
153
+ children: g.href
154
+ }
155
+ ),
156
+ /* @__PURE__ */ d(
157
+ "button",
158
+ {
159
+ type: "button",
160
+ className: "be-link-hover-card-btn",
161
+ onClick: p,
162
+ "aria-label": "Edit link",
163
+ title: "Edit link",
164
+ children: /* @__PURE__ */ d(co, { size: 13 })
165
+ }
166
+ ),
167
+ /* @__PURE__ */ d(
168
+ "button",
169
+ {
170
+ type: "button",
171
+ className: "be-link-hover-card-btn",
172
+ onClick: b,
173
+ "aria-label": "Remove link",
174
+ title: "Remove link",
175
+ children: /* @__PURE__ */ d(st, { size: 13 })
176
+ }
177
+ )
178
+ ]
179
+ }
180
+ ),
181
+ document.body
182
+ ) : null,
183
+ /* @__PURE__ */ d(
184
+ Ko,
185
+ {
186
+ isOpen: r,
187
+ initialHref: (g == null ? void 0 : g.href) ?? "",
188
+ initialTarget: (g == null ? void 0 : g.target) ?? "_self",
189
+ hasExistingLink: !!g,
190
+ onSave: f,
191
+ onRemove: b,
192
+ onClose: i
193
+ }
194
+ )
195
+ ] });
196
+ }
197
+ function Go({ title: e, onClose: t }) {
198
+ return /* @__PURE__ */ T("div", { className: "be-comment-popover-header", children: [
199
+ /* @__PURE__ */ d("span", { className: "be-comment-popover-title", children: e }),
200
+ /* @__PURE__ */ d(
201
+ "button",
202
+ {
203
+ type: "button",
204
+ className: "be-comment-popover-close",
205
+ onClick: t,
206
+ "aria-label": "Close",
207
+ children: /* @__PURE__ */ d(st, { size: 14 })
208
+ }
209
+ )
210
+ ] });
211
+ }
212
+ const Wo = 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
213
+ function qo({ containerRef: e, store: t, authorId: n }) {
214
+ const [o, r] = O(null), [l, a] = O(!1), s = _(null), c = _(null), u = _(null), [, p] = dn(), i = h(() => {
215
+ s.current && (clearTimeout(s.current), s.current = null);
216
+ }, []), f = h(() => {
217
+ i(), s.current = setTimeout(() => {
218
+ r((m) => l ? m : null);
219
+ }, 250);
220
+ }, [i, l]);
221
+ oe(() => {
222
+ const m = e.current;
223
+ if (!m) return;
224
+ const y = (S) => {
225
+ var F, w, N;
226
+ const $ = (F = S == null ? void 0 : S.closest) == null ? void 0 : F.call(S, "[data-run-id]");
227
+ if (!$ || !m.contains($)) return null;
228
+ const A = (N = (w = t.getRun($.dataset.runId)) == null ? void 0 : w.marks) == null ? void 0 : N.commentIds;
229
+ return A != null && A.length ? { runEl: $, commentIds: A } : null;
230
+ }, B = (S) => {
231
+ const $ = y(S.target);
232
+ $ && (i(), r(
233
+ (A) => A && A.runEl === $.runEl ? A : {
234
+ rect: $.runEl.getBoundingClientRect(),
235
+ commentIds: $.commentIds,
236
+ runEl: $.runEl
237
+ }
238
+ ));
239
+ }, L = () => f(), D = (S) => {
240
+ const $ = y(S.target);
241
+ if (!$) {
242
+ a(!1), r(null);
243
+ return;
244
+ }
245
+ i(), a(!0), r({
246
+ rect: $.runEl.getBoundingClientRect(),
247
+ commentIds: $.commentIds,
248
+ runEl: $.runEl
249
+ });
250
+ };
251
+ return m.addEventListener("mouseover", B), m.addEventListener("mouseout", L), m.addEventListener("click", D), () => {
252
+ m.removeEventListener("mouseover", B), m.removeEventListener("mouseout", L), m.removeEventListener("click", D);
253
+ };
254
+ }, [e, t, i, f]), oe(() => {
255
+ if (!o) return;
256
+ const m = (B) => {
257
+ var L, D;
258
+ (L = c.current) != null && L.contains(B.target) || (D = e.current) != null && D.contains(B.target) || (a(!1), r(null));
259
+ }, y = (B) => {
260
+ B.key === "Escape" && (a(!1), r(null));
261
+ };
262
+ return document.addEventListener("mousedown", m), document.addEventListener("keydown", y), () => {
263
+ document.removeEventListener("mousedown", m), document.removeEventListener("keydown", y);
264
+ };
265
+ }, [o, e]), oe(() => () => i(), [i]), oe(() => {
266
+ var m;
267
+ p(((m = o == null ? void 0 : o.commentIds) == null ? void 0 : m[0]) ?? null);
268
+ }, [o, p]);
269
+ const b = h(() => {
270
+ a(!1), r(null);
271
+ }, []), v = !!o, g = vt(
272
+ c,
273
+ v,
274
+ o ? o.rect.bottom + 6 : null,
275
+ o ? o.rect.left : null
276
+ ), k = _(!1);
277
+ if (oe(() => {
278
+ var m, y;
279
+ l && c.current && !k.current ? (k.current = !0, u.current = document.activeElement, (c.current.querySelector(Wo) ?? c.current).focus()) : !l && k.current && (k.current = !1, (y = (m = u.current) == null ? void 0 : m.focus) == null || y.call(m), u.current = null);
280
+ }, [l, g]), !v || !g) return null;
281
+ const I = o.commentIds.map((m) => t.getComment(m)).filter(Boolean);
282
+ return I.length === 0 ? null : Oe(
283
+ /* @__PURE__ */ T(
284
+ "div",
285
+ {
286
+ ref: c,
287
+ className: "be-comment-popover",
288
+ contentEditable: !1,
289
+ style: { position: "fixed", top: g.top, left: g.left },
290
+ onMouseEnter: i,
291
+ onMouseLeave: f,
292
+ role: "dialog",
293
+ "aria-modal": l || void 0,
294
+ "aria-label": `Comments (${I.length})`,
295
+ tabIndex: -1,
296
+ children: [
297
+ /* @__PURE__ */ d(Go, { title: `Comments (${I.length})`, onClose: b }),
298
+ I.map((m) => /* @__PURE__ */ d(jo, { store: t, thread: m, authorId: n }, m.id))
299
+ ]
300
+ }
301
+ ),
302
+ document.body
303
+ );
304
+ }
305
+ function Vt(e, t) {
306
+ const n = e == null ? void 0 : e.parentElement;
307
+ if (!n || !n.hasAttribute("data-placeholder")) return;
308
+ t.length === 0 || t.every(Sn) ? n.setAttribute("data-empty", "") : n.removeAttribute("data-empty");
309
+ }
310
+ function Yo(e = {}) {
311
+ return {
312
+ fontWeight: e.bold ? "bold" : void 0,
313
+ fontStyle: e.italic ? "italic" : void 0,
314
+ textDecoration: [(e.underline || e.link) && "underline", e.strike && "line-through"].filter(Boolean).join(" ") || void 0,
315
+ verticalAlign: e.subscript ? "sub" : e.superscript ? "super" : void 0,
316
+ fontSize: e.subscript || e.superscript ? "smaller" : void 0,
317
+ color: e.color || (e.link ? "var(--noteloom-accent)" : void 0),
318
+ backgroundColor: e.highlight || void 0,
319
+ cursor: e.link ? "pointer" : void 0
320
+ };
321
+ }
322
+ function Xo(e, t) {
323
+ const n = e.childNodes.length === 1 ? e.firstChild : null;
324
+ n && n.nodeType === 3 ? n.nodeValue !== t && (n.nodeValue = t) : e.textContent = t;
325
+ }
326
+ function Qo({ id: e, host: t, onValueSynced: n }) {
327
+ const o = ze(e), [r] = dn();
328
+ return rt(() => {
329
+ var p, i, f, b, v;
330
+ if (!t || !o) return;
331
+ const l = o.value ?? "";
332
+ ($o(t.textContent) !== l || l === "" && t.textContent === "") && Xo(t, l === "" ? En : l);
333
+ const c = Yo(o.marks);
334
+ t.style.fontWeight = c.fontWeight ?? "", t.style.fontStyle = c.fontStyle ?? "", t.style.textDecoration = c.textDecoration ?? "", t.style.verticalAlign = c.verticalAlign ?? "", t.style.fontSize = c.fontSize ?? "", t.style.color = c.color ?? "", t.style.backgroundColor = c.backgroundColor ?? "", t.style.cursor = c.cursor ?? "", t.classList.toggle("be-comment-highlight", (((i = (p = o.marks) == null ? void 0 : p.commentIds) == null ? void 0 : i.length) ?? 0) > 0), t.classList.toggle(
335
+ "be-comment-highlight-active",
336
+ !!r && !!((b = (f = o.marks) == null ? void 0 : f.commentIds) != null && b.includes(r))
337
+ );
338
+ const u = (v = o.marks) == null ? void 0 : v.link;
339
+ t.title = u != null && u.href ? `${u.href} — Ctrl+Click to open` : "", t.onclick = u != null && u.href ? (g) => {
340
+ !g.ctrlKey && !g.metaKey || (g.preventDefault(), window.open(
341
+ u.href,
342
+ u.target === "_blank" ? "_blank" : "_self",
343
+ "noopener,noreferrer"
344
+ ));
345
+ } : null, n == null || n();
346
+ }, [t, o, n, r]), null;
347
+ }
348
+ function Gt(e, t, n, o) {
349
+ var i, f, b;
350
+ const r = (i = window.getSelection) == null ? void 0 : i.call(window);
351
+ if (!r || !r.isCollapsed || r.rangeCount === 0) return null;
352
+ const { anchorNode: l, anchorOffset: a } = r;
353
+ if (!l || !e.contains(l)) return null;
354
+ const s = (v) => {
355
+ const g = t.indexOf(v);
356
+ if (g === -1) return null;
357
+ const k = o ? t[g - 1] : t[g + 1];
358
+ if (!k) return null;
359
+ const I = n(k);
360
+ return I && I.type !== "text" ? k : null;
361
+ };
362
+ if (l === e) {
363
+ const v = o ? a - 1 : a, g = e.childNodes[v], k = (g == null ? void 0 : g.nodeType) === 1 ? (f = g.dataset) == null ? void 0 : f.runId : void 0;
364
+ if (!k || t.indexOf(k) === -1) return null;
365
+ const I = n(k);
366
+ return I && I.type !== "text" ? k : null;
367
+ }
368
+ const c = l.nodeType === 1 ? l : l.parentElement, u = (b = c == null ? void 0 : c.closest) == null ? void 0 : b.call(c, "[data-run-id]");
369
+ return !u || !e.contains(u) || !(o ? a === 0 : a === (l.textContent ?? "").length) ? null : s(u.getAttribute("data-run-id"));
370
+ }
371
+ function Wt(e, t, n) {
372
+ var c, u;
373
+ const o = (c = window.getSelection) == null ? void 0 : c.call(window);
374
+ if (!o || o.isCollapsed || o.rangeCount === 0) return null;
375
+ const r = o.getRangeAt(0);
376
+ if (r.startContainer !== r.endContainer || !e.contains(r.startContainer) || r.endOffset !== r.startOffset + 1) return null;
377
+ const l = r.startContainer.childNodes[r.startOffset], a = (l == null ? void 0 : l.nodeType) === 1 ? (u = l.dataset) == null ? void 0 : u.runId : void 0;
378
+ if (!a || t.indexOf(a) === -1) return null;
379
+ const s = n(a);
380
+ return s && s.type !== "text" ? a : null;
381
+ }
382
+ function qt(e, t, n) {
383
+ var s;
384
+ if (t === e) return { childIndex: n, charOffset: null };
385
+ const o = t.nodeType === 1 ? t : t.parentElement, r = (s = o == null ? void 0 : o.closest) == null ? void 0 : s.call(o, "[data-run-id]");
386
+ if (!r || !e.contains(r)) return null;
387
+ const l = Array.prototype.indexOf.call(e.childNodes, r), a = t === r ? n === 0 ? 0 : (r.textContent ?? "").length : n;
388
+ return { childIndex: l, charOffset: a };
389
+ }
390
+ function Jo(e, t, n, o) {
391
+ const r = qt(e, o.startContainer, o.startOffset), l = qt(e, o.endContainer, o.endOffset);
392
+ if (!r || !l) return null;
393
+ const a = Array.from(e.childNodes).filter(
394
+ (p) => {
395
+ var i;
396
+ return p.nodeType === 1 && ((i = p.dataset) == null ? void 0 : i.runId) && t.indexOf(p.dataset.runId) !== -1;
397
+ }
398
+ );
399
+ let s = !1;
400
+ const c = [];
401
+ let u = null;
402
+ return a.forEach((p, i) => {
403
+ const f = p.dataset.runId, b = n(f);
404
+ if (!b) return;
405
+ const v = i < r.childIndex, g = l.charOffset === null ? i >= l.childIndex : i > l.childIndex;
406
+ if (v || g) {
407
+ c.push(b);
408
+ return;
409
+ }
410
+ const k = r.charOffset !== null && i === r.childIndex, I = l.charOffset !== null && i === l.childIndex;
411
+ if (b.type !== "text") {
412
+ s = !0, u === null && (u = c.length);
413
+ return;
414
+ }
415
+ const m = b.value ?? "";
416
+ if (k && I) {
417
+ const y = m.slice(0, r.charOffset) + m.slice(l.charOffset);
418
+ y && c.push({ ...b, value: y }), u = c.length;
419
+ } else if (k) {
420
+ const y = m.slice(0, r.charOffset);
421
+ y && c.push({ ...b, value: y }), u === null && (u = c.length);
422
+ } else if (I) {
423
+ const y = m.slice(l.charOffset);
424
+ y && c.push({ id: C(), type: "text", value: y, marks: b.marks });
425
+ }
426
+ }), s ? { nextRuns: c, insertionIndex: u ?? c.length } : null;
427
+ }
428
+ function Zo(e) {
429
+ var l;
430
+ const t = (l = window.getSelection) == null ? void 0 : l.call(window);
431
+ if (!t || !t.isCollapsed) return !1;
432
+ const n = e.firstChild;
433
+ if (!n) return !0;
434
+ if (t.anchorNode === e) return t.anchorOffset === 0;
435
+ let o = n;
436
+ for (; o && o.firstChild; ) o = o.firstChild;
437
+ if (t.anchorNode !== o && t.anchorNode !== n) return !1;
438
+ const r = o.nodeType === 3 && o.textContent === En ? 1 : 0;
439
+ return t.anchorOffset <= r;
440
+ }
441
+ function er(e) {
442
+ var l;
443
+ const t = (l = window.getSelection) == null ? void 0 : l.call(window);
444
+ if (!t || !t.isCollapsed) return !1;
445
+ const n = e.lastChild;
446
+ if (!n) return !0;
447
+ if (t.anchorNode === e)
448
+ return t.anchorOffset >= e.childNodes.length;
449
+ let o = n;
450
+ for (; o && o.lastChild; ) o = o.lastChild;
451
+ if (t.anchorNode !== o && t.anchorNode !== n) return !1;
452
+ const r = o.nodeType === 3 ? (o.textContent ?? "").length : 0;
453
+ return t.anchorOffset >= r;
454
+ }
455
+ function Yt(e, t, n) {
456
+ const o = e.getBlock(t), r = e.getBlock(o == null ? void 0 : o.parentId);
457
+ if (!r) return null;
458
+ const l = r.contentIds.indexOf(t), a = n === "backward" ? l - 1 : l + 1;
459
+ if (a < 0 || a >= r.contentIds.length) return null;
460
+ const s = r.contentIds[a];
461
+ return kt(e, e.getBlock(s)) ? s : null;
462
+ }
463
+ function tr({ id: e, blockId: t, host: n, inlineRegistry: o, onValueSynced: r }) {
464
+ const l = ze(e);
465
+ if (!l) return null;
466
+ if (l.type === "text") return /* @__PURE__ */ d(Qo, { id: e, host: n, onValueSynced: r });
467
+ const a = o == null ? void 0 : o.get(l.type);
468
+ if (!a)
469
+ return process.env.NODE_ENV !== "production" && console.warn(`[block-editor] No inline type registered for "${l.type}" (run: ${e})`), null;
470
+ const s = a.component;
471
+ return /* @__PURE__ */ d(s, { id: e, blockId: t });
472
+ }
473
+ function nr(e, t, n) {
474
+ let o = e.get(n);
475
+ if (!o) {
476
+ o = document.createElement("span"), o.dataset.runId = n;
477
+ const r = t.getRun(n);
478
+ r && r.type !== "text" && o.setAttribute("contenteditable", "false"), e.set(n, o);
479
+ }
480
+ return o;
481
+ }
482
+ function Le({
483
+ blockId: e,
484
+ runIds: t,
485
+ dir: n = "auto",
486
+ onEnter: o,
487
+ onBackspaceAtStart: r,
488
+ onDeleteAtEnd: l,
489
+ onArrowUp: a,
490
+ onArrowDown: s,
491
+ onTab: c,
492
+ onShiftTab: u,
493
+ onAutoformat: p
494
+ }) {
495
+ const i = V(), f = Ot(), b = io(), { getSelectedBlockId: v, setSelectedBlockId: g } = Se(), k = _(null), I = _(!1), m = _(/* @__PURE__ */ new Map());
496
+ rt(() => {
497
+ const w = k.current;
498
+ if (!w) return;
499
+ const N = new Set(t);
500
+ for (const [H, E] of m.current)
501
+ N.has(H) || (E.remove(), m.current.delete(H));
502
+ let x = null;
503
+ for (const H of t) {
504
+ const E = m.current.get(H);
505
+ if (!E) continue;
506
+ const P = x ? x.nextSibling : w.firstChild;
507
+ P !== E && w.insertBefore(E, P), x = E;
508
+ }
509
+ }, [t]);
510
+ const y = h(() => {
511
+ if (I.current) return;
512
+ const w = k.current;
513
+ if (!w) return;
514
+ const N = t.map((P) => i.getRun(P)).filter(Boolean), {
515
+ runs: x,
516
+ changed: H,
517
+ onlyValueChanges: E
518
+ } = Eo(w, N);
519
+ if (H) {
520
+ if (E) {
521
+ if (x.forEach((P, Y) => {
522
+ P !== N[Y] && i.applyOperation(ie(P.id, { value: P.value }));
523
+ }), p != null && p(x)) return;
524
+ } else
525
+ i.applyOperation(
526
+ Ue(
527
+ e,
528
+ x.length ? x : [{ id: C(), type: "text", value: "", marks: {} }]
529
+ )
530
+ );
531
+ Vt(w, x);
532
+ }
533
+ }, [i, e, t, p]), B = h(() => {
534
+ Vt(k.current, t.map((w) => i.getRun(w)).filter(Boolean));
535
+ }, [i, t]), L = h(() => {
536
+ I.current = !0;
537
+ }, []), D = h(() => {
538
+ I.current = !1, y();
539
+ }, [y]), S = h(
540
+ (w) => {
541
+ const x = t.map((H) => i.getRun(H)).filter(Boolean).filter((H) => H.id !== w);
542
+ i.applyOperation(
543
+ Ue(
544
+ e,
545
+ x.length ? x : [{ id: C(), type: "text", value: "", marks: {} }]
546
+ )
547
+ );
548
+ },
549
+ [i, e, t]
550
+ ), $ = h(
551
+ (w) => {
552
+ v() === w ? (i.applyOperation(q(w)), g(null)) : g(w);
553
+ },
554
+ [i, v, g]
555
+ ), A = h(
556
+ (w) => {
557
+ var de, te, Ae, ye;
558
+ if (I.current) return;
559
+ if (w.target instanceof Node) {
560
+ const Z = w.target.nodeType === 1 ? w.target : w.target.parentElement;
561
+ if ((de = Z == null ? void 0 : Z.closest) != null && de.call(Z, '[contenteditable="false"]')) return;
562
+ }
563
+ const N = w.inputType ?? "", x = N.startsWith("delete"), H = N === "insertText" || N === "insertReplacementText";
564
+ if (!x && !H) return;
565
+ const E = k.current;
566
+ if (!E) return;
567
+ const P = (te = w.getTargetRanges) == null ? void 0 : te.call(w), Y = (Ae = window.getSelection) == null ? void 0 : Ae.call(window), X = (P == null ? void 0 : P[0]) ?? (Y != null && Y.rangeCount ? Y.getRangeAt(0) : null);
568
+ if (!X || !E.contains(X.startContainer) || !E.contains(X.endContainer))
569
+ return;
570
+ const K = Jo(
571
+ E,
572
+ t,
573
+ (Z) => i.getRun(Z),
574
+ X
575
+ );
576
+ if (!K) return;
577
+ w.preventDefault();
578
+ let { nextRuns: z, insertionIndex: Q } = K, he = null, ue = !1;
579
+ if (H && w.data) {
580
+ const Z = { id: C(), type: "text", value: w.data, marks: {} };
581
+ z = [
582
+ ...z.slice(0, Q),
583
+ Z,
584
+ ...z.slice(Q)
585
+ ], he = Z.id, ue = !1;
586
+ } else Q > 0 ? (he = (ye = z[Q - 1]) == null ? void 0 : ye.id, ue = !1) : z.length > 0 && (he = z[0].id, ue = !0);
587
+ const ce = z.length ? z : [{ id: C(), type: "text", value: "", marks: {} }];
588
+ i.applyOperation(Ue(e, ce));
589
+ const Ie = he ?? ce[0].id;
590
+ ue ? Mn(Ie) : ve(Ie);
591
+ },
592
+ [i, e, t]
593
+ );
594
+ oe(() => {
595
+ const w = k.current;
596
+ if (w)
597
+ return w.addEventListener("beforeinput", A), () => w.removeEventListener("beforeinput", A);
598
+ }, [A]);
599
+ const F = h(
600
+ (w) => {
601
+ if (!I.current) {
602
+ if (w.key === "Enter" && o) {
603
+ w.preventDefault(), o(w);
604
+ return;
605
+ }
606
+ if (w.key === "Backspace") {
607
+ const N = k.current, x = N && Wt(N, t, i.getRun.bind(i));
608
+ if (x) {
609
+ w.preventDefault(), S(x);
610
+ return;
611
+ }
612
+ const H = N && Gt(N, t, i.getRun.bind(i), !0);
613
+ if (H) {
614
+ w.preventDefault(), S(H);
615
+ return;
616
+ }
617
+ if (N && Zo(N)) {
618
+ if (!me(i, t)) {
619
+ const P = Yt(i, e, "backward");
620
+ if (P) {
621
+ w.preventDefault(), $(P);
622
+ return;
623
+ }
624
+ }
625
+ w.preventDefault(), r && r(w);
626
+ }
627
+ return;
628
+ }
629
+ if (w.key === "Delete") {
630
+ const N = k.current, x = N && Wt(N, t, i.getRun.bind(i));
631
+ if (x) {
632
+ w.preventDefault(), S(x);
633
+ return;
634
+ }
635
+ const H = N && Gt(N, t, i.getRun.bind(i), !1);
636
+ if (H) {
637
+ w.preventDefault(), S(H);
638
+ return;
639
+ }
640
+ if (N && er(N)) {
641
+ const E = Yt(i, e, "forward");
642
+ if (E) {
643
+ w.preventDefault(), $(E);
644
+ return;
645
+ }
646
+ l && l(w);
647
+ }
648
+ return;
649
+ }
650
+ if (w.key === "ArrowUp" && a) {
651
+ w.preventDefault(), a(w);
652
+ return;
653
+ }
654
+ if (w.key === "ArrowDown" && s) {
655
+ w.preventDefault(), s(w);
656
+ return;
657
+ }
658
+ w.key === "Tab" && (w.shiftKey && u ? (w.preventDefault(), u(w)) : !w.shiftKey && c && (w.preventDefault(), c(w)));
659
+ }
660
+ },
661
+ [
662
+ o,
663
+ r,
664
+ l,
665
+ a,
666
+ s,
667
+ c,
668
+ u,
669
+ S,
670
+ $,
671
+ t,
672
+ e,
673
+ i
674
+ ]
675
+ );
676
+ return /* @__PURE__ */ T(Te, { children: [
677
+ /* @__PURE__ */ d(
678
+ "span",
679
+ {
680
+ ref: k,
681
+ className: "be-editable",
682
+ dir: n,
683
+ contentEditable: !0,
684
+ suppressContentEditableWarning: !0,
685
+ onInput: y,
686
+ onCompositionStart: L,
687
+ onCompositionEnd: D,
688
+ onKeyDown: F,
689
+ children: t.map((w) => {
690
+ const N = nr(m.current, i, w);
691
+ return Oe(
692
+ /* @__PURE__ */ d(
693
+ tr,
694
+ {
695
+ id: w,
696
+ blockId: e,
697
+ host: N,
698
+ inlineRegistry: f,
699
+ onValueSynced: B
700
+ },
701
+ w
702
+ ),
703
+ N
704
+ );
705
+ })
706
+ }
707
+ ),
708
+ /* @__PURE__ */ d(Vo, { containerRef: k, store: i }),
709
+ /* @__PURE__ */ d(qo, { containerRef: k, store: i, authorId: b })
710
+ ] });
711
+ }
712
+ function Pt(e) {
713
+ const t = e.getRootId(), n = e.getBlock(t);
714
+ if (!n || n.contentIds.length > 0) return null;
715
+ const { block: o, runs: r } = U("paragraph")(t);
716
+ return e.applyOperation(ke(o, t, 0, { blocks: [o], runs: r })), o.id;
717
+ }
718
+ const or = /* @__PURE__ */ new Set(["callout"]), Xt = /* @__PURE__ */ new Set(["paragraph", "heading", "blockquote"]);
719
+ function rr(e, t) {
720
+ return e === t || Xt.has(e) && Xt.has(t);
721
+ }
722
+ function ct(e, t) {
723
+ const n = e.getBlock(t);
724
+ if (!n) return null;
725
+ const o = e.getBlock(n.parentId), r = o.contentIds.indexOf(t), l = n.contentIds.length === 0 || n.contentIds.length === 1 && lr(e, n.contentIds[0]);
726
+ if (r <= 0) {
727
+ if (!l) return null;
728
+ if (o.contentIds.length > 1)
729
+ return Pe(e, [q(t)]), e.getBlock(o.id).contentIds[0];
730
+ if (or.has(o.type))
731
+ return ar(e, o);
732
+ if (n.type === "paragraph") return null;
733
+ const { block: u, runs: p } = U("paragraph")(o.id);
734
+ return Pe(e, [
735
+ ke(u, o.id, r, { blocks: [u], runs: p }),
736
+ q(t)
737
+ ]), u.id;
738
+ }
739
+ const a = o.contentIds[r - 1], s = e.getBlock(a);
740
+ if (l)
741
+ return Pe(e, [q(t)]), a;
742
+ if (kt(e, s))
743
+ return Pe(e, [q(a)]), t;
744
+ if (!s || !rr(s.type, n.type)) return null;
745
+ const c = [...s.contentIds, ...n.contentIds];
746
+ return Pe(e, [
747
+ Lt(a, c),
748
+ Lt(t, []),
749
+ // detach moved runs before deleting the shell
750
+ q(t)
751
+ ]), a;
752
+ }
753
+ function lr(e, t) {
754
+ const n = e.getRun(t);
755
+ return !n || (n.value ?? "") === "";
756
+ }
757
+ function ar(e, t) {
758
+ const n = e.getBlock(t.parentId);
759
+ if (!n) return null;
760
+ const o = n.contentIds.indexOf(t.id), r = o > 0 ? n.contentIds[o - 1] : null, l = o !== -1 && o < n.contentIds.length - 1 ? n.contentIds[o + 1] : null;
761
+ Pe(e, [q(t.id)]);
762
+ const a = Pt(e);
763
+ return r ?? l ?? a;
764
+ }
765
+ function Pe(e, t) {
766
+ if (typeof e.performBatch == "function")
767
+ e.performBatch(t);
768
+ else
769
+ for (const n of t) e.applyOperation(n);
770
+ }
771
+ function Ge(e, t, n, o) {
772
+ if (!t || t === n) return;
773
+ const r = xo(e, t);
774
+ if (r) {
775
+ ve(r);
776
+ return;
777
+ }
778
+ o(t), requestAnimationFrame(() => {
779
+ var l;
780
+ (l = document.querySelector(`[data-block-id="${t}"]`)) == null || l.focus();
781
+ });
782
+ }
783
+ function Ce(e, t) {
784
+ var o, r;
785
+ if (!t) return "auto";
786
+ if ((o = t.props) != null && o.dir) return t.props.dir;
787
+ const n = e.getBlock(e.getRootId());
788
+ return ((r = n == null ? void 0 : n.props) == null ? void 0 : r.dir) ?? "auto";
789
+ }
790
+ function sr(e, t) {
791
+ if (typeof e.performBatch == "function") e.performBatch(t);
792
+ else for (const n of t) e.applyOperation(n);
793
+ }
794
+ const cr = [
795
+ { re: /^(#{1,3})[  ]$/, type: "heading", props: (e) => ({ level: e[1].length }) },
796
+ { re: /^[-*][  ]$/, type: "listItem", props: () => ({ ordered: !1, titleRunIds: [] }) },
797
+ { re: /^\d+\.[  ]$/, type: "listItem", props: () => ({ ordered: !0, titleRunIds: [] }) },
798
+ {
799
+ re: /^\[\][  ]$/,
800
+ type: "listItem",
801
+ props: () => ({ ordered: !1, checked: !1, titleRunIds: [] })
802
+ },
803
+ { re: /^>[  ]$/, type: "blockquote", props: () => ({}) },
804
+ { re: /^```$/, type: "code", props: () => ({ language: "plaintext" }) }
805
+ ];
806
+ function ir(e, t, n) {
807
+ if (n.length !== 1 || n[0].type !== "text") return !1;
808
+ const o = n[0].value ?? "";
809
+ for (const r of cr) {
810
+ const l = r.re.exec(o);
811
+ if (!l) continue;
812
+ const a = o.slice(l[0].length), { ops: s } = On(e, t, r.type, r.props(l), [n[0].id]);
813
+ return sr(e, [ie(n[0].id, { value: a }), ...s]), Mn(n[0].id), !0;
814
+ }
815
+ return !1;
816
+ }
817
+ const ur = /* @__PURE__ */ new Set(["callout", "toggleHeading"]);
818
+ function dr({ id: e }) {
819
+ const t = V(), n = ee(e), { setSelectedBlockId: o } = Se(), r = h(() => {
820
+ const f = t.getBlock(n == null ? void 0 : n.parentId), b = me(t, (n == null ? void 0 : n.contentIds) ?? []), v = !!f && f.contentIds[f.contentIds.length - 1] === e;
821
+ if (b && v && ur.has(f == null ? void 0 : f.type)) {
822
+ Ke(t, f.id, U("paragraph"));
823
+ return;
824
+ }
825
+ Ve(
826
+ t,
827
+ e,
828
+ (n == null ? void 0 : n.contentIds) ?? [],
829
+ U("paragraph")
830
+ );
831
+ }, [t, e, n]), l = h(() => {
832
+ var k, I;
833
+ const f = t.getBlock(n == null ? void 0 : n.parentId), b = me(t, (n == null ? void 0 : n.contentIds) ?? []), v = ((k = f == null ? void 0 : f.contentIds) == null ? void 0 : k.length) === 1 && f.contentIds[0] === e;
834
+ if (b && v && (f == null ? void 0 : f.type) === "toggleHeading") {
835
+ const m = ((I = f.props) == null ? void 0 : I.titleRunIds) ?? [], y = m[m.length - 1];
836
+ y && ve(y);
837
+ return;
838
+ }
839
+ const g = ct(t, e);
840
+ Ge(t, g, e, o);
841
+ }, [t, e, n, o]), a = h(() => le(t, e, "up"), [t, e]), s = h(() => le(t, e, "down"), [t, e]), c = h(
842
+ (f) => ir(t, e, f),
843
+ [t, e]
844
+ ), u = se("be-paragraph", n);
845
+ if (!n) return null;
846
+ const p = me(t, n.contentIds), i = Ce(t, n);
847
+ return /* @__PURE__ */ d(
848
+ "div",
849
+ {
850
+ className: u,
851
+ "data-block-id": e,
852
+ "data-empty": p ? "" : void 0,
853
+ "data-placeholder": "Type '/' for commands",
854
+ dir: i,
855
+ children: /* @__PURE__ */ d(
856
+ Le,
857
+ {
858
+ blockId: e,
859
+ runIds: n.contentIds,
860
+ dir: i,
861
+ onEnter: r,
862
+ onBackspaceAtStart: l,
863
+ onArrowUp: a,
864
+ onArrowDown: s,
865
+ onAutoformat: c
866
+ }
867
+ )
868
+ }
869
+ );
870
+ }
871
+ const pr = {
872
+ STRONG: "bold",
873
+ B: "bold",
874
+ EM: "italic",
875
+ I: "italic",
876
+ U: "underline",
877
+ S: "strike",
878
+ STRIKE: "strike",
879
+ DEL: "strike",
880
+ CODE: "code",
881
+ SUB: "subscript",
882
+ SUP: "superscript"
883
+ };
884
+ function Be(e, t, n = {}) {
885
+ const o = [], r = (l, a) => {
886
+ var u, p;
887
+ if (l.nodeType === 3) {
888
+ const i = l.textContent;
889
+ i && o.push({ id: C(), type: "text", value: i, marks: { ...a } });
890
+ return;
891
+ }
892
+ if (l.nodeType !== 1) return;
893
+ if (t != null && t.inlineRegistry)
894
+ for (const i of t.inlineRegistry.listHtmlMatchers()) {
895
+ const f = i.fromHTML(l, t);
896
+ if (f) {
897
+ o.push(f);
898
+ return;
899
+ }
900
+ }
901
+ let s = a;
902
+ const c = pr[l.tagName];
903
+ c && (s = { ...s, [c]: !0 }), l.tagName === "A" && l.getAttribute("href") && (s = {
904
+ ...s,
905
+ link: {
906
+ href: l.getAttribute("href"),
907
+ target: l.getAttribute("target") === "_blank" ? "_blank" : "_self"
908
+ }
909
+ }), (u = l.style) != null && u.color && (s = { ...s, color: l.style.color }), (p = l.style) != null && p.backgroundColor && (s = { ...s, highlight: l.style.backgroundColor });
910
+ for (const i of l.childNodes) r(i, s);
911
+ };
912
+ return r(e, n), o.length ? o : [{ id: C(), type: "text", value: "", marks: {} }];
913
+ }
914
+ function fr(e, t) {
915
+ return `<p>${e.contentIds.map((o) => t.store.getRun(o)).map((o) => Ne(o, t)).join("")}</p>`;
916
+ }
917
+ function mr(e, t) {
918
+ return e.contentIds.map((n) => Re(t.store.getRun(n), t)).join("");
919
+ }
920
+ function hr(e, t) {
921
+ return xe(
922
+ e.contentIds.map((n) => t.store.getRun(n)),
923
+ t
924
+ );
925
+ }
926
+ function gr(e, t) {
927
+ if (e.tagName !== "P") return null;
928
+ const n = Be(e, t);
929
+ return { block: {
930
+ id: C(),
931
+ type: "paragraph",
932
+ parentId: null,
933
+ contentIds: n.map((r) => r.id),
934
+ props: {}
935
+ }, runs: n };
936
+ }
937
+ const br = ae({
938
+ name: "paragraph",
939
+ component: dr,
940
+ contentModel: "runs",
941
+ defaultProps: {},
942
+ toHTML: fr,
943
+ toPlainText: mr,
944
+ toMarkdown: hr,
945
+ fromHTML: gr,
946
+ slashCommand: {
947
+ label: "Text",
948
+ icon: pn,
949
+ keywords: ["paragraph", "text", "p"],
950
+ run: (e, t) => re(e, t, U("paragraph"))
951
+ }
952
+ });
953
+ function yr({ id: e }) {
954
+ var b;
955
+ const t = V(), n = ee(e), { setSelectedBlockId: o } = Se(), r = h(() => {
956
+ Ve(
957
+ t,
958
+ e,
959
+ (n == null ? void 0 : n.contentIds) ?? [],
960
+ U("paragraph")
961
+ );
962
+ }, [t, e, n]), l = h(() => {
963
+ const v = ct(t, e);
964
+ Ge(t, v, e, o);
965
+ }, [t, e, o]), a = h(() => le(t, e, "up"), [t, e]), s = h(() => le(t, e, "down"), [t, e]), c = ((b = n == null ? void 0 : n.props) == null ? void 0 : b.level) ?? 3, u = se(`be-heading be-heading-${c}`, n);
966
+ if (!n) return null;
967
+ const p = `h${c}`, i = me(t, n.contentIds), f = Ce(t, n);
968
+ return /* @__PURE__ */ d(
969
+ p,
970
+ {
971
+ className: u,
972
+ "data-block-id": e,
973
+ "data-empty": i ? "" : void 0,
974
+ "data-placeholder": `Heading ${c}`,
975
+ dir: f,
976
+ children: /* @__PURE__ */ d(
977
+ Le,
978
+ {
979
+ blockId: e,
980
+ runIds: n.contentIds,
981
+ dir: f,
982
+ onEnter: r,
983
+ onBackspaceAtStart: l,
984
+ onArrowUp: a,
985
+ onArrowDown: s
986
+ }
987
+ )
988
+ }
989
+ );
990
+ }
991
+ const Tt = { 1: fn, 2: mn, 3: hn }, kr = { H1: 1, H2: 2, H3: 3 };
992
+ function vr(e, t) {
993
+ var r;
994
+ const n = ((r = e.props) == null ? void 0 : r.level) ?? 3, o = e.contentIds.map((l) => t.store.getRun(l));
995
+ return `<h${n}>${o.map((l) => Ne(l, t)).join("")}</h${n}>`;
996
+ }
997
+ function Ir(e, t) {
998
+ return e.contentIds.map((n) => Re(t.store.getRun(n), t)).join("");
999
+ }
1000
+ function wr(e, t) {
1001
+ var r;
1002
+ const n = ((r = e.props) == null ? void 0 : r.level) ?? 3, o = xe(
1003
+ e.contentIds.map((l) => t.store.getRun(l)),
1004
+ t
1005
+ );
1006
+ return `${"#".repeat(n)} ${o}`;
1007
+ }
1008
+ function Tr(e, t) {
1009
+ const n = kr[e.tagName];
1010
+ if (!n) return null;
1011
+ const o = Be(e, t);
1012
+ return { block: {
1013
+ id: C(),
1014
+ type: "heading",
1015
+ parentId: null,
1016
+ contentIds: o.map((l) => l.id),
1017
+ props: { level: n }
1018
+ }, runs: o };
1019
+ }
1020
+ const Cr = ae({
1021
+ name: "heading",
1022
+ contentModel: "runs",
1023
+ component: yr,
1024
+ defaultProps: { level: 3 },
1025
+ toHTML: vr,
1026
+ toPlainText: Ir,
1027
+ toMarkdown: wr,
1028
+ fromHTML: Tr,
1029
+ slashCommands: [
1030
+ {
1031
+ label: "Heading 1",
1032
+ icon: Tt[1],
1033
+ keywords: ["heading", "h1", "title"],
1034
+ run: (e, t) => re(e, t, U("heading", { level: 1 }))
1035
+ },
1036
+ {
1037
+ label: "Heading 2",
1038
+ icon: Tt[2],
1039
+ keywords: ["heading", "h2", "subtitle"],
1040
+ run: (e, t) => re(e, t, U("heading", { level: 2 }))
1041
+ },
1042
+ {
1043
+ label: "Heading 3",
1044
+ icon: Tt[3],
1045
+ keywords: ["heading", "h3", "title"],
1046
+ run: (e, t) => re(e, t, U("heading", { level: 3 }))
1047
+ }
1048
+ ]
1049
+ }), Br = [];
1050
+ function Dn(e) {
1051
+ const t = V(), n = h(
1052
+ (r) => t.subscribe(e, r),
1053
+ [t, e]
1054
+ ), o = h(() => {
1055
+ const r = t.getBlock(e);
1056
+ return r ? r.contentIds : Br;
1057
+ }, [t, e]);
1058
+ return un(n, o);
1059
+ }
1060
+ class Rr extends lo {
1061
+ constructor() {
1062
+ super(...arguments);
1063
+ Kt(this, "state", { hasError: !1, nonce: 0 });
1064
+ }
1065
+ static getDerivedStateFromError() {
1066
+ return { hasError: !0 };
1067
+ }
1068
+ componentDidCatch(n, o) {
1069
+ var r, l;
1070
+ process.env.NODE_ENV !== "production" && console.error(
1071
+ "[block-editor] a block failed to render; recovering by remounting it:",
1072
+ n,
1073
+ o
1074
+ ), (l = (r = this.props).onError) == null || l.call(r, n, o), queueMicrotask(() => this.setState((a) => ({ hasError: !1, nonce: a.nonce + 1 })));
1075
+ }
1076
+ render() {
1077
+ return this.state.hasError ? null : /* @__PURE__ */ d(ao, { children: this.props.children }, this.state.nonce);
1078
+ }
1079
+ }
1080
+ const Hn = so(function({ id: t }) {
1081
+ const n = ee(t), o = gn();
1082
+ if (!n) return null;
1083
+ const r = o.get(n.type);
1084
+ if (!r)
1085
+ return process.env.NODE_ENV !== "production" && console.warn(`[block-editor] No block type registered for "${n.type}" (id: ${t})`), null;
1086
+ const l = r.component;
1087
+ return /* @__PURE__ */ d(Rr, { children: /* @__PURE__ */ d(l, { id: t }) });
1088
+ });
1089
+ function _t(e, t, n, o) {
1090
+ const r = _(!1), l = _(!1);
1091
+ oe(() => {
1092
+ var p, i;
1093
+ if (!t) {
1094
+ l.current = !1, r.current && (r.current = !1, (i = (p = o == null ? void 0 : o.current) == null ? void 0 : p.focus) == null || i.call(p));
1095
+ return;
1096
+ }
1097
+ r.current = !0;
1098
+ const a = e.current;
1099
+ if (!a) return;
1100
+ const s = () => Array.from(a.querySelectorAll('[role="menuitem"]')), c = (f) => {
1101
+ var g;
1102
+ const b = s();
1103
+ if (b.length === 0) return;
1104
+ const v = (f % b.length + b.length) % b.length;
1105
+ (g = b[v]) == null || g.focus();
1106
+ };
1107
+ l.current || (l.current = !0, c(0));
1108
+ const u = (f) => {
1109
+ if (f.key === "Escape") {
1110
+ f.preventDefault(), n();
1111
+ return;
1112
+ }
1113
+ const b = s(), v = b.indexOf(document.activeElement);
1114
+ v !== -1 && (f.key === "ArrowDown" ? (f.preventDefault(), c(v + 1)) : f.key === "ArrowUp" ? (f.preventDefault(), c(v - 1)) : f.key === "Home" ? (f.preventDefault(), c(0)) : f.key === "End" && (f.preventDefault(), c(b.length - 1)));
1115
+ };
1116
+ return a.addEventListener("keydown", u), () => a.removeEventListener("keydown", u);
1117
+ });
1118
+ }
1119
+ const Qt = "be-live-region";
1120
+ function Nr() {
1121
+ if (typeof document > "u") return null;
1122
+ let e = document.getElementById(Qt);
1123
+ return e || (e = document.createElement("div"), e.id = Qt, e.setAttribute("role", "status"), e.setAttribute("aria-live", "polite"), e.setAttribute("aria-atomic", "true"), Object.assign(e.style, {
1124
+ position: "absolute",
1125
+ width: "1px",
1126
+ height: "1px",
1127
+ margin: "-1px",
1128
+ padding: "0",
1129
+ overflow: "hidden",
1130
+ clip: "rect(0, 0, 0, 0)",
1131
+ whiteSpace: "nowrap",
1132
+ border: "0"
1133
+ }), document.body.appendChild(e), e);
1134
+ }
1135
+ function Me(e) {
1136
+ const t = Nr();
1137
+ t && (t.textContent = "", setTimeout(() => {
1138
+ t.textContent = e;
1139
+ }, 0));
1140
+ }
1141
+ const De = "💡", Pn = "gray";
1142
+ function Lr({
1143
+ icon: e = De,
1144
+ color: t = Pn
1145
+ } = {}) {
1146
+ return function(o) {
1147
+ const r = C(), { block: l, runs: a } = U("paragraph")(r);
1148
+ return { block: {
1149
+ id: r,
1150
+ type: "callout",
1151
+ parentId: o,
1152
+ contentIds: [l.id],
1153
+ props: { icon: e, color: t }
1154
+ }, runs: a, subtreeBlocks: [l] };
1155
+ };
1156
+ }
1157
+ const _n = [
1158
+ { type: "paragraph", props: {}, label: "Text", icon: pn },
1159
+ { type: "heading", props: { level: 1 }, label: "Heading 1", icon: fn },
1160
+ { type: "heading", props: { level: 2 }, label: "Heading 2", icon: mn },
1161
+ { type: "heading", props: { level: 3 }, label: "Heading 3", icon: hn },
1162
+ {
1163
+ type: "listItem",
1164
+ props: { ordered: !1, titleRunIds: [] },
1165
+ label: "Bulleted list",
1166
+ icon: bn
1167
+ },
1168
+ {
1169
+ type: "listItem",
1170
+ props: { ordered: !0, titleRunIds: [] },
1171
+ label: "Numbered list",
1172
+ icon: yn
1173
+ },
1174
+ {
1175
+ type: "listItem",
1176
+ props: { ordered: !1, checked: !1, titleRunIds: [] },
1177
+ label: "To-do list",
1178
+ icon: St
1179
+ },
1180
+ {
1181
+ type: "listItem",
1182
+ props: { ordered: !1, collapsed: !1, titleRunIds: [] },
1183
+ label: "Toggle list",
1184
+ icon: Ee
1185
+ },
1186
+ {
1187
+ type: "toggleHeading",
1188
+ props: { level: 2, collapsed: !1, titleRunIds: [] },
1189
+ label: "Toggle heading",
1190
+ icon: Ee
1191
+ },
1192
+ { type: "blockquote", props: {}, label: "Quote", icon: kn },
1193
+ { type: "callout", props: { icon: De }, label: "Callout", icon: vn },
1194
+ { type: "code", props: { language: "plaintext" }, label: "Code", icon: In }
1195
+ ], Ar = new Set(_n.map((e) => e.type));
1196
+ function Mr(e) {
1197
+ return Ar.has(e);
1198
+ }
1199
+ function Er(e, t) {
1200
+ return e != null && e.props && "titleRunIds" in e.props ? e.props.titleRunIds : t && !t.isLeaf(e == null ? void 0 : e.type) ? [] : (e == null ? void 0 : e.contentIds) ?? [];
1201
+ }
1202
+ function $r(e, t, n, o) {
1203
+ const r = e.getBlock(n), l = Er(r, t), a = [];
1204
+ if (o.type === "code")
1205
+ for (const p of l) {
1206
+ const i = e.getRun(p);
1207
+ i != null && i.marks && Object.keys(i.marks).length > 0 && a.push(ie(p, { marks: {} }));
1208
+ }
1209
+ const s = { ...o.props }, { ops: c, newBlockId: u } = On(
1210
+ e,
1211
+ n,
1212
+ o.type,
1213
+ s,
1214
+ l,
1215
+ t
1216
+ );
1217
+ return { ops: [...a, ...c], newBlockId: u };
1218
+ }
1219
+ function xr({
1220
+ onSelect: e,
1221
+ onClose: t,
1222
+ containerRef: n,
1223
+ menuClassName: o = "be-block-gutter-menu",
1224
+ itemClassName: r = "be-block-gutter-menu-item"
1225
+ }) {
1226
+ const [l, a] = O(!1), [s, c] = O(null), u = _(null), p = _(null), i = h(
1227
+ (m) => {
1228
+ p.current = m, n && (n.current = m);
1229
+ },
1230
+ [n]
1231
+ ), f = h(() => {
1232
+ a(!1), t == null || t();
1233
+ }, [t]);
1234
+ at([u, p], l, f), _t(p, l, f, u);
1235
+ const b = vt(
1236
+ p,
1237
+ l,
1238
+ s == null ? void 0 : s.top,
1239
+ s ? s.right + 4 : null
1240
+ ), v = h(() => {
1241
+ var m;
1242
+ c(((m = u.current) == null ? void 0 : m.getBoundingClientRect()) ?? null), a(!0);
1243
+ }, []), g = h(
1244
+ (m) => {
1245
+ e(m), f();
1246
+ },
1247
+ [e, f]
1248
+ ), k = h(
1249
+ (m) => {
1250
+ m.key === "ArrowRight" && !l && (m.preventDefault(), v());
1251
+ },
1252
+ [l, v]
1253
+ ), I = h(
1254
+ (m) => {
1255
+ m.key === "ArrowLeft" && (m.preventDefault(), f());
1256
+ },
1257
+ [f]
1258
+ );
1259
+ return /* @__PURE__ */ T(Te, { children: [
1260
+ /* @__PURE__ */ T(
1261
+ "button",
1262
+ {
1263
+ ref: u,
1264
+ type: "button",
1265
+ role: "menuitem",
1266
+ className: r,
1267
+ "aria-haspopup": "menu",
1268
+ "aria-expanded": l,
1269
+ onClick: () => l ? f() : v(),
1270
+ onKeyDown: k,
1271
+ children: [
1272
+ /* @__PURE__ */ d(Ee, { size: 15 }),
1273
+ " Turn into"
1274
+ ]
1275
+ }
1276
+ ),
1277
+ l && b && Oe(
1278
+ /* @__PURE__ */ d(
1279
+ "div",
1280
+ {
1281
+ ref: i,
1282
+ role: "menu",
1283
+ "aria-label": "Turn into",
1284
+ className: o,
1285
+ style: { position: "fixed", top: b.top, left: b.left },
1286
+ onKeyDown: I,
1287
+ children: _n.map((m, y) => {
1288
+ const B = m.icon;
1289
+ return /* @__PURE__ */ T(
1290
+ "button",
1291
+ {
1292
+ type: "button",
1293
+ role: "menuitem",
1294
+ className: r,
1295
+ onClick: () => g(m),
1296
+ children: [
1297
+ /* @__PURE__ */ d(B, { size: 15 }),
1298
+ " ",
1299
+ m.label
1300
+ ]
1301
+ },
1302
+ `${m.type}-${y}`
1303
+ );
1304
+ })
1305
+ }
1306
+ ),
1307
+ document.body
1308
+ )
1309
+ ] });
1310
+ }
1311
+ function Or(e, t) {
1312
+ const n = e.getBlock(t);
1313
+ if (!n) return null;
1314
+ const o = e.getBlock(n.parentId), r = o.contentIds.indexOf(t), l = Fo(e, t), { block: a, runs: s, subtreeBlocks: c } = zo(l);
1315
+ return e.applyOperation(
1316
+ ke(a, o.id, r + 1, { blocks: [a, ...c], runs: s })
1317
+ ), be(e, a.id), a.id;
1318
+ }
1319
+ function Sr(e, t) {
1320
+ const n = e.getBlock(t), o = n && e.getBlock(n.parentId);
1321
+ if (!o) return !1;
1322
+ const r = o.contentIds.indexOf(t);
1323
+ return r <= 0 ? !1 : (e.applyOperation(yt(t, o.id, r - 1)), !0);
1324
+ }
1325
+ function Dr(e, t) {
1326
+ const n = e.getBlock(t), o = n && e.getBlock(n.parentId);
1327
+ if (!o) return !1;
1328
+ const r = o.contentIds.indexOf(t);
1329
+ return r === -1 || r >= o.contentIds.length - 1 ? !1 : (e.applyOperation(yt(t, o.id, r + 1)), !0);
1330
+ }
1331
+ function Un(e, t) {
1332
+ const n = e.getBlock(t);
1333
+ if (!n) return null;
1334
+ const o = e.getBlock(n.parentId), r = o.contentIds.indexOf(t), l = r > 0 ? o.contentIds[r - 1] : null, a = r !== -1 && r < o.contentIds.length - 1 ? o.contentIds[r + 1] : null;
1335
+ e.applyOperation(q(t));
1336
+ const s = Pt(e), c = l ?? a ?? s;
1337
+ return c && be(e, c), c ?? null;
1338
+ }
1339
+ function Hr(e, t) {
1340
+ if (typeof e.performBatch == "function") e.performBatch(t);
1341
+ else for (const n of t) e.applyOperation(n);
1342
+ }
1343
+ function Pr({ id: e }) {
1344
+ var w;
1345
+ const t = V(), n = gn(), o = ee(e), [r, l] = O(!1), [a, s] = O(null), c = _(null), u = _(null), p = _(null), i = je(() => [c, u, p], []), [f] = uo(), b = f.includes(e), v = h(() => l(!1), []);
1346
+ at(i, r, v), _t(u, r, v, c);
1347
+ const g = h(() => {
1348
+ var N;
1349
+ s(((N = c.current) == null ? void 0 : N.getBoundingClientRect()) ?? null), l(!0);
1350
+ }, []), k = vt(
1351
+ u,
1352
+ r,
1353
+ (a == null ? void 0 : a.bottom) != null ? a.bottom + 4 : null,
1354
+ a == null ? void 0 : a.left
1355
+ ), I = h(() => {
1356
+ Ke(t, e, U("paragraph"));
1357
+ }, [t, e]), m = h(() => {
1358
+ Or(t, e), Me("Block duplicated"), v();
1359
+ }, [t, e, v]), y = h(() => {
1360
+ Sr(t, e) && Me("Block moved up"), v();
1361
+ }, [t, e, v]), B = h(() => {
1362
+ Dr(t, e) && Me("Block moved down"), v();
1363
+ }, [t, e, v]), L = h(() => {
1364
+ Un(t, e), Me("Block deleted"), v();
1365
+ }, [t, e, v]), D = !!((w = o == null ? void 0 : o.props) != null && w.hidden), S = h(() => {
1366
+ t.applyOperation(G(e, { hidden: !D })), Me(D ? "Block shown in preview" : "Block hidden in preview"), v();
1367
+ }, [t, e, D, v]), $ = Ce(t, o) === "rtl", A = h(() => {
1368
+ t.applyOperation(G(e, { dir: $ ? "ltr" : "rtl" })), Me($ ? "Block set to left-to-right" : "Block set to right-to-left"), v();
1369
+ }, [t, e, $, v]), F = h(
1370
+ (N) => {
1371
+ const { ops: x } = $r(t, n, e, N);
1372
+ Hr(t, x), Me(`Turned into ${N.label}`), v();
1373
+ },
1374
+ [t, n, e, v]
1375
+ );
1376
+ return o ? /* @__PURE__ */ T(
1377
+ "div",
1378
+ {
1379
+ className: `be-block-row${D ? " be-block-row-hidden" : ""}${b ? " be-block-row-range-selected" : ""}`,
1380
+ "data-block-row-id": e,
1381
+ dir: Ce(t, o),
1382
+ children: [
1383
+ /* @__PURE__ */ T(
1384
+ "div",
1385
+ {
1386
+ className: `be-block-gutter${r ? " be-block-gutter-active" : ""}`,
1387
+ contentEditable: !1,
1388
+ children: [
1389
+ /* @__PURE__ */ d(
1390
+ "button",
1391
+ {
1392
+ type: "button",
1393
+ className: "be-block-gutter-btn",
1394
+ onClick: I,
1395
+ "aria-label": "Add block below",
1396
+ children: /* @__PURE__ */ d(wn, { size: 16 })
1397
+ }
1398
+ ),
1399
+ /* @__PURE__ */ d(
1400
+ "button",
1401
+ {
1402
+ ref: c,
1403
+ type: "button",
1404
+ className: "be-block-gutter-btn",
1405
+ "aria-label": "More options",
1406
+ "aria-haspopup": "menu",
1407
+ "aria-expanded": r,
1408
+ onClick: () => r ? v() : g(),
1409
+ children: /* @__PURE__ */ d(po, { size: 16 })
1410
+ }
1411
+ )
1412
+ ]
1413
+ }
1414
+ ),
1415
+ /* @__PURE__ */ d("div", { className: "be-block-row-content", children: /* @__PURE__ */ d(Hn, { id: e }) }),
1416
+ r && k && Oe(
1417
+ /* @__PURE__ */ T(
1418
+ "div",
1419
+ {
1420
+ ref: u,
1421
+ role: "menu",
1422
+ "aria-label": "Block options",
1423
+ className: "be-block-gutter-menu",
1424
+ style: { position: "fixed", top: k.top, left: k.left },
1425
+ children: [
1426
+ /* @__PURE__ */ T(
1427
+ "button",
1428
+ {
1429
+ type: "button",
1430
+ role: "menuitem",
1431
+ className: "be-block-gutter-menu-item",
1432
+ onClick: m,
1433
+ children: [
1434
+ /* @__PURE__ */ d(fo, { size: 15 }),
1435
+ " Duplicate"
1436
+ ]
1437
+ }
1438
+ ),
1439
+ /* @__PURE__ */ T(
1440
+ "button",
1441
+ {
1442
+ type: "button",
1443
+ role: "menuitem",
1444
+ className: "be-block-gutter-menu-item",
1445
+ onClick: y,
1446
+ children: [
1447
+ /* @__PURE__ */ d(Tn, { size: 15 }),
1448
+ " Move up"
1449
+ ]
1450
+ }
1451
+ ),
1452
+ /* @__PURE__ */ T(
1453
+ "button",
1454
+ {
1455
+ type: "button",
1456
+ role: "menuitem",
1457
+ className: "be-block-gutter-menu-item",
1458
+ onClick: B,
1459
+ children: [
1460
+ /* @__PURE__ */ d(Cn, { size: 15 }),
1461
+ " Move down"
1462
+ ]
1463
+ }
1464
+ ),
1465
+ /* @__PURE__ */ T(
1466
+ "button",
1467
+ {
1468
+ type: "button",
1469
+ role: "menuitem",
1470
+ className: "be-block-gutter-menu-item",
1471
+ onClick: S,
1472
+ children: [
1473
+ D ? /* @__PURE__ */ d(mo, { size: 15 }) : /* @__PURE__ */ d(ho, { size: 15 }),
1474
+ D ? "Show in preview" : "Hide in preview"
1475
+ ]
1476
+ }
1477
+ ),
1478
+ /* @__PURE__ */ T(
1479
+ "button",
1480
+ {
1481
+ type: "button",
1482
+ role: "menuitem",
1483
+ className: "be-block-gutter-menu-item",
1484
+ onClick: A,
1485
+ children: [
1486
+ $ ? /* @__PURE__ */ d(Bn, { size: 15 }) : /* @__PURE__ */ d(Rn, { size: 15 }),
1487
+ $ ? "Switch to left-to-right" : "Switch to right-to-left"
1488
+ ]
1489
+ }
1490
+ ),
1491
+ Mr(o.type) && /* @__PURE__ */ d(
1492
+ xr,
1493
+ {
1494
+ onSelect: F,
1495
+ onClose: () => {
1496
+ },
1497
+ containerRef: p
1498
+ }
1499
+ ),
1500
+ /* @__PURE__ */ T(
1501
+ "button",
1502
+ {
1503
+ type: "button",
1504
+ role: "menuitem",
1505
+ className: "be-block-gutter-menu-item be-block-gutter-menu-item-danger",
1506
+ onClick: L,
1507
+ children: [
1508
+ /* @__PURE__ */ d(Nn, { size: 15 }),
1509
+ " Delete"
1510
+ ]
1511
+ }
1512
+ )
1513
+ ]
1514
+ }
1515
+ ),
1516
+ document.body
1517
+ )
1518
+ ]
1519
+ }
1520
+ ) : null;
1521
+ }
1522
+ function He({ parentId: e, isTopLevel: t = !1, filterIds: n }) {
1523
+ const o = Dn(e), r = V(), [l] = go(), a = n ?? o, s = l ? a.filter((c) => {
1524
+ var u, p;
1525
+ return !((p = (u = r.getBlock(c)) == null ? void 0 : u.props) != null && p.hidden);
1526
+ }) : a;
1527
+ return t && !l ? s.map((c) => /* @__PURE__ */ d(Pr, { id: c }, c)) : s.map((c) => /* @__PURE__ */ d(Hn, { id: c }, c));
1528
+ }
1529
+ const _r = 97, Ur = [
1530
+ [1e3, "m"],
1531
+ [900, "cm"],
1532
+ [500, "d"],
1533
+ [400, "cd"],
1534
+ [100, "c"],
1535
+ [90, "xc"],
1536
+ [50, "l"],
1537
+ [40, "xl"],
1538
+ [10, "x"],
1539
+ [9, "ix"],
1540
+ [5, "v"],
1541
+ [4, "iv"],
1542
+ [1, "i"]
1543
+ ];
1544
+ function jr(e) {
1545
+ let t = "";
1546
+ for (; e > 0; )
1547
+ e -= 1, t = String.fromCharCode(_r + e % 26) + t, e = Math.floor(e / 26);
1548
+ return t;
1549
+ }
1550
+ function Fr(e) {
1551
+ let t = "", n = e;
1552
+ for (const [o, r] of Ur)
1553
+ for (; n >= o; )
1554
+ t += r, n -= o;
1555
+ return t;
1556
+ }
1557
+ function zr(e) {
1558
+ var t, n;
1559
+ return (e == null ? void 0 : e.type) === "listItem" && ((t = e.props) == null ? void 0 : t.checked) === void 0 && ((n = e.props) == null ? void 0 : n.collapsed) === void 0;
1560
+ }
1561
+ function Jt(e, t) {
1562
+ let n = 0, o = t;
1563
+ for (; o; ) {
1564
+ const r = e.getBlock(o.parentId);
1565
+ if (!r || r.type !== "listItem") break;
1566
+ n += 1, o = r;
1567
+ }
1568
+ return n;
1569
+ }
1570
+ function Kr(e, t, n) {
1571
+ const o = n.indexOf(t.id);
1572
+ let r = 1;
1573
+ for (let l = o - 1; l >= 0; l -= 1) {
1574
+ const a = e.getBlock(n[l]);
1575
+ if (!zr(a) || !a.props.ordered) break;
1576
+ r += 1;
1577
+ }
1578
+ return r;
1579
+ }
1580
+ function Vr(e, t) {
1581
+ const n = (e % 3 + 3) % 3;
1582
+ return n === 0 ? `${t}.` : n === 1 ? `${jr(t)}.` : `${Fr(t)}.`;
1583
+ }
1584
+ const Gr = ["•", "◦", "▪"];
1585
+ function Wr(e) {
1586
+ const t = (e % 3 + 3) % 3;
1587
+ return Gr[t];
1588
+ }
1589
+ function ot({ ordered: e = !1, checked: t, collapsed: n } = {}) {
1590
+ return function(r, l) {
1591
+ const a = C(), s = l != null && l.length ? l : [{ id: C(), type: "text", value: "", marks: {} }], c = { ordered: e, titleRunIds: s.map((f) => f.id) };
1592
+ t !== void 0 && (c.checked = t);
1593
+ let u = [], p = [], i = s;
1594
+ if (n !== void 0) {
1595
+ c.collapsed = n;
1596
+ const { block: f, runs: b } = U("paragraph")(a);
1597
+ u = [f.id], p = [f], i = [...s, ...b];
1598
+ }
1599
+ return {
1600
+ block: { id: a, type: "listItem", parentId: r, contentIds: u, props: c },
1601
+ runs: i,
1602
+ subtreeBlocks: p
1603
+ };
1604
+ };
1605
+ }
1606
+ function qr(e, t) {
1607
+ const n = e.getBlock(t), o = e.getBlock(n.parentId), r = o.contentIds.indexOf(t), l = r > 0 ? o.contentIds[r - 1] : null, a = l ? e.getBlock(l) : null;
1608
+ if (!a || a.type !== "listItem") {
1609
+ le(e, t, "down");
1610
+ return;
1611
+ }
1612
+ e.applyOperation(yt(t, l, a.contentIds.length)), be(e, t);
1613
+ }
1614
+ function At(e, t) {
1615
+ const n = e.getBlock(t), o = e.getBlock(n.parentId);
1616
+ if (!o || o.type !== "listItem") return;
1617
+ const r = o.parentId, a = e.getBlock(r).contentIds.indexOf(o.id);
1618
+ e.applyOperation(yt(t, r, a + 1)), be(e, t);
1619
+ }
1620
+ function et(e, t) {
1621
+ if (typeof e.performBatch == "function") e.performBatch(t);
1622
+ else for (const n of t) e.applyOperation(n);
1623
+ }
1624
+ function jn(e, t) {
1625
+ var n;
1626
+ return t.length === 0 || t.length === 1 && (((n = e.getRun(t[0])) == null ? void 0 : n.value) ?? "") === "";
1627
+ }
1628
+ function Yr(e, t) {
1629
+ const n = t.contentIds ?? [];
1630
+ if (n.length === 0) return !0;
1631
+ if (n.length > 1) return !1;
1632
+ const o = e.getBlock(n[0]);
1633
+ return !!o && o.type === "paragraph" && me(e, o.contentIds);
1634
+ }
1635
+ function Xr(e, t) {
1636
+ const n = e.getBlock(t);
1637
+ if (!n) return null;
1638
+ const o = e.getBlock(n.parentId), r = o.contentIds.indexOf(t), l = n.props.titleRunIds ?? [], s = jn(e, l) && Yr(e, n);
1639
+ if (r > 0) {
1640
+ const p = o.contentIds[r - 1], i = e.getBlock(p);
1641
+ if (s)
1642
+ return et(e, [q(t)]), { focusBlockId: p, needsRefocus: !0 };
1643
+ if (kt(e, i))
1644
+ return et(e, [q(p)]), { focusBlockId: t, needsRefocus: !1 };
1645
+ if ((i == null ? void 0 : i.type) === "listItem" && n.contentIds.length === 0) {
1646
+ const f = [...i.props.titleRunIds ?? [], ...l];
1647
+ return et(e, [
1648
+ G(p, { titleRunIds: f }),
1649
+ G(t, { titleRunIds: [] }),
1650
+ // detach before delete
1651
+ q(t)
1652
+ ]), { focusBlockId: p, needsRefocus: !0 };
1653
+ }
1654
+ return null;
1655
+ }
1656
+ if (o.type === "listItem")
1657
+ return At(e, t), { focusBlockId: t, needsRefocus: !0 };
1658
+ if (!s) return null;
1659
+ if (o.contentIds.length > 1)
1660
+ return et(e, [q(t)]), { focusBlockId: e.getBlock(o.id).contentIds[0], needsRefocus: !0 };
1661
+ const { block: c, runs: u } = U("paragraph")(o.id);
1662
+ return et(e, [
1663
+ ke(c, o.id, r, { blocks: [c], runs: u }),
1664
+ q(t)
1665
+ ]), { focusBlockId: c.id, needsRefocus: !0 };
1666
+ }
1667
+ function Qr(e, t) {
1668
+ if (typeof e.performBatch == "function") e.performBatch(t);
1669
+ else for (const n of t) e.applyOperation(n);
1670
+ }
1671
+ function Jr(e, t) {
1672
+ const o = e.getBlock(t).parentId, l = e.getBlock(o).contentIds.indexOf(t), { block: a, runs: s } = U("paragraph")(o);
1673
+ return Qr(e, [
1674
+ ke(a, o, l, { blocks: [a], runs: s }),
1675
+ G(t, { titleRunIds: [] }),
1676
+ // detach its own (empty) run before deleting
1677
+ q(t)
1678
+ ]), be(e, a.id), a.id;
1679
+ }
1680
+ function Zr(e, t) {
1681
+ if (typeof e.performBatch == "function") e.performBatch(t);
1682
+ else for (const n of t) e.applyOperation(n);
1683
+ }
1684
+ function el({ id: e }) {
1685
+ var S, $;
1686
+ const t = V(), n = ee(e), { setSelectedBlockId: o } = Se(), r = Dn(n == null ? void 0 : n.parentId), l = h(() => {
1687
+ var P, Y, X, K, z;
1688
+ const A = ((P = n == null ? void 0 : n.props) == null ? void 0 : P.titleRunIds) ?? [], F = t.getBlock(n == null ? void 0 : n.parentId), w = jn(t, A);
1689
+ if (w && (F == null ? void 0 : F.type) === "listItem") {
1690
+ At(t, e);
1691
+ return;
1692
+ }
1693
+ const N = (((Y = n == null ? void 0 : n.contentIds) == null ? void 0 : Y.length) ?? 0) > 0;
1694
+ if (w && (F == null ? void 0 : F.type) !== "listItem" && !N) {
1695
+ Jr(t, e);
1696
+ return;
1697
+ }
1698
+ const x = ((X = n == null ? void 0 : n.props) == null ? void 0 : X.checked) !== void 0, H = ((K = n == null ? void 0 : n.props) == null ? void 0 : K.collapsed) !== void 0, E = ot({
1699
+ ordered: (z = n == null ? void 0 : n.props) == null ? void 0 : z.ordered,
1700
+ checked: x ? !1 : void 0,
1701
+ collapsed: H ? !1 : void 0
1702
+ });
1703
+ N && !H ? $n(t, e, A, E) : Ve(t, e, A, E);
1704
+ }, [t, e, n]), a = h(() => qr(t, e), [t, e]), s = h(() => At(t, e), [t, e]), c = h(() => {
1705
+ const A = Xr(t, e);
1706
+ !A || !A.needsRefocus || Ge(t, A.focusBlockId, e, o);
1707
+ }, [t, e, o]), u = h(() => le(t, e, "up"), [t, e]), p = h(() => le(t, e, "down"), [t, e]), i = h(() => {
1708
+ var A;
1709
+ t.applyOperation(G(e, { checked: !((A = n == null ? void 0 : n.props) != null && A.checked) }));
1710
+ }, [t, e, (S = n == null ? void 0 : n.props) == null ? void 0 : S.checked]), f = h(() => {
1711
+ var F, w;
1712
+ if (!((((F = n == null ? void 0 : n.contentIds) == null ? void 0 : F.length) ?? 0) > 0)) {
1713
+ const { block: N, runs: x } = U("paragraph")(e);
1714
+ Zr(t, [
1715
+ ke(N, e, 0, { blocks: [N], runs: x }),
1716
+ G(e, { collapsed: !1 })
1717
+ ]), ve(N.contentIds[0]);
1718
+ return;
1719
+ }
1720
+ t.applyOperation(G(e, { collapsed: !((w = n == null ? void 0 : n.props) != null && w.collapsed) }));
1721
+ }, [t, e, n == null ? void 0 : n.contentIds, ($ = n == null ? void 0 : n.props) == null ? void 0 : $.collapsed]), b = se("be-list-item", n);
1722
+ if (!n) return null;
1723
+ const { ordered: v, checked: g, collapsed: k, titleRunIds: I = [] } = n.props, m = g !== void 0, y = !m && k !== void 0, B = n.contentIds.length > 0, L = I.map((A) => t.getRun(A)).filter((A) => (A == null ? void 0 : A.type) === "text").map((A) => A.value).join("").trim(), D = Ce(t, n);
1724
+ return /* @__PURE__ */ T("div", { className: b, "data-block-id": e, dir: D, children: [
1725
+ /* @__PURE__ */ T("div", { className: "be-list-item-row", children: [
1726
+ m ? /* @__PURE__ */ d(
1727
+ "input",
1728
+ {
1729
+ type: "checkbox",
1730
+ className: "be-list-checkbox",
1731
+ checked: !!g,
1732
+ onChange: i,
1733
+ "aria-label": L || "To-do item"
1734
+ }
1735
+ ) : y ? (
1736
+ // A real button (not decorative, unlike the plain bullet/number
1737
+ // marker below): it's the only way to reveal/hide this item's
1738
+ // children, so assistive tech needs to know it's interactive and
1739
+ // what state it's in.
1740
+ /* @__PURE__ */ d(
1741
+ "button",
1742
+ {
1743
+ type: "button",
1744
+ className: "be-list-toggle-marker",
1745
+ onClick: f,
1746
+ "aria-expanded": !k,
1747
+ "aria-label": B ? k ? "Expand toggle" : "Collapse toggle" : "Add content to toggle",
1748
+ children: k ? /* @__PURE__ */ d(Ee, {}) : /* @__PURE__ */ d(Dt, {})
1749
+ }
1750
+ )
1751
+ ) : (
1752
+ // Decorative: list structure/position is conveyed by the DOM
1753
+ // order itself, not by this glyph, so it's hidden from assistive
1754
+ // tech. The glyph itself cycles with nesting depth (1,2,3 ->
1755
+ // a,b,c -> i,ii,iii for numbered; disc -> circle -> square for
1756
+ // bulleted, repeating every 3 levels), a common list-nesting
1757
+ // convention — see listMarkers.js.
1758
+ /* @__PURE__ */ d("span", { className: "be-list-marker", "aria-hidden": "true", children: v ? Vr(
1759
+ Jt(t, n),
1760
+ Kr(t, n, r)
1761
+ ) : Wr(Jt(t, n)) })
1762
+ ),
1763
+ /* @__PURE__ */ d(
1764
+ "div",
1765
+ {
1766
+ className: "be-list-item-title",
1767
+ "data-empty": me(t, I) ? "" : void 0,
1768
+ "data-placeholder": m ? "To-do" : y ? "Toggle" : "List item",
1769
+ style: g ? { textDecoration: "line-through", opacity: 0.6 } : void 0,
1770
+ children: /* @__PURE__ */ d(
1771
+ Le,
1772
+ {
1773
+ blockId: e,
1774
+ runIds: I,
1775
+ dir: D,
1776
+ onEnter: l,
1777
+ onTab: a,
1778
+ onShiftTab: s,
1779
+ onBackspaceAtStart: c,
1780
+ onArrowUp: u,
1781
+ onArrowDown: p
1782
+ }
1783
+ )
1784
+ }
1785
+ )
1786
+ ] }),
1787
+ (!y || !k) && /* @__PURE__ */ d("div", { className: "be-list-item-children", children: /* @__PURE__ */ d(He, { parentId: e }) })
1788
+ ] });
1789
+ }
1790
+ function tl(e, t) {
1791
+ const { titleRunIds: n = [], ordered: o } = e.props, r = n.map((s) => Ne(t.store.getRun(s), t)).join(""), l = e.contentIds.map(
1792
+ (s) => t.registry.get(t.store.getBlock(s).type).toHTML(t.store.getBlock(s), t)
1793
+ ).join(""), a = l ? `<${o ? "ol" : "ul"}>${l}</${o ? "ol" : "ul"}>` : "";
1794
+ return `<li>${r}${a}</li>`;
1795
+ }
1796
+ function nl(e, t) {
1797
+ const { titleRunIds: n = [] } = e.props;
1798
+ return n.map((o) => Re(t.store.getRun(o), t)).join("");
1799
+ }
1800
+ function ol(e, t) {
1801
+ const { titleRunIds: n = [], ordered: o, checked: r } = e.props, l = r !== void 0 ? r ? "- [x] " : "- [ ] " : o ? "1. " : "- ", a = xe(
1802
+ n.map((c) => t.store.getRun(c)),
1803
+ t
1804
+ ), s = e.contentIds.map((c) => {
1805
+ const u = t.store.getBlock(c), p = t.registry.get(u.type);
1806
+ return (p.toMarkdown ?? p.toPlainText)(u, t).split(`
1807
+ `).map((f) => f && ` ${f}`).join(`
1808
+ `);
1809
+ }).join(`
1810
+ `);
1811
+ return s ? `${l}${a}
1812
+ ${s}` : `${l}${a}`;
1813
+ }
1814
+ function Fn(e, t) {
1815
+ const n = [], o = [];
1816
+ for (const i of e.childNodes)
1817
+ i.nodeType === 1 && (i.tagName === "UL" || i.tagName === "OL") ? o.push(i) : n.push(i);
1818
+ const r = e.ownerDocument.createElement("span");
1819
+ for (const i of n) r.appendChild(i.cloneNode(!0));
1820
+ const l = Be(r, t), a = C(), s = [...l], c = [], u = [];
1821
+ for (const i of o) {
1822
+ const f = i.tagName === "OL";
1823
+ for (const b of i.children) {
1824
+ if (b.tagName !== "LI") continue;
1825
+ const v = Fn(b, t);
1826
+ v.block.parentId = a, v.block.props.ordered = f, c.push(v.block, ...v.childBlocks), s.push(...v.runs), u.push(v.block.id);
1827
+ }
1828
+ }
1829
+ return { block: {
1830
+ id: a,
1831
+ type: "listItem",
1832
+ parentId: null,
1833
+ contentIds: u,
1834
+ props: { ordered: !1, titleRunIds: l.map((i) => i.id) }
1835
+ }, runs: s, childBlocks: c };
1836
+ }
1837
+ function rl(e, t) {
1838
+ if (e.tagName !== "LI") return null;
1839
+ const { block: n, runs: o, childBlocks: r } = Fn(e, t);
1840
+ return { block: n, runs: o, subtreeBlocks: r };
1841
+ }
1842
+ const ll = ae({
1843
+ name: "listItem",
1844
+ contentModel: "blocks",
1845
+ component: el,
1846
+ defaultProps: { ordered: !1, titleRunIds: [] },
1847
+ toHTML: tl,
1848
+ toPlainText: nl,
1849
+ toMarkdown: ol,
1850
+ fromHTML: rl,
1851
+ slashCommands: [
1852
+ {
1853
+ label: "Bulleted list",
1854
+ icon: bn,
1855
+ keywords: ["list", "bullet", "ul"],
1856
+ run: (e, t) => re(e, t, ot({ ordered: !1 }))
1857
+ },
1858
+ {
1859
+ label: "Numbered list",
1860
+ icon: yn,
1861
+ keywords: ["list", "number", "ordered", "ol"],
1862
+ run: (e, t) => re(e, t, ot({ ordered: !0 }))
1863
+ },
1864
+ {
1865
+ label: "To-do list",
1866
+ icon: St,
1867
+ keywords: ["todo", "checkbox", "task", "checklist"],
1868
+ run: (e, t) => re(
1869
+ e,
1870
+ t,
1871
+ ot({ ordered: !1, checked: !1 })
1872
+ )
1873
+ },
1874
+ {
1875
+ label: "Toggle list",
1876
+ icon: Ee,
1877
+ keywords: ["toggle", "collapse", "expand", "dropdown", "accordion"],
1878
+ run: (e, t) => re(
1879
+ e,
1880
+ t,
1881
+ ot({ ordered: !1, collapsed: !1 })
1882
+ )
1883
+ }
1884
+ ]
1885
+ }), al = ["text", "date", "checkbox", "select"], It = "text", Ut = 160, _e = 80;
1886
+ function sl(e) {
1887
+ return `Column ${e + 1}`;
1888
+ }
1889
+ function zn(e) {
1890
+ return Array.from({ length: e }, (t, n) => ({
1891
+ id: C(),
1892
+ label: sl(n),
1893
+ type: It,
1894
+ width: Ut
1895
+ }));
1896
+ }
1897
+ function pe(e, t) {
1898
+ var o;
1899
+ const n = (o = e.props) == null ? void 0 : o.columns;
1900
+ return !Array.isArray(n) || n.length !== t ? zn(t) : n.map((r) => {
1901
+ const l = r.type ?? It, a = r.width ?? Ut;
1902
+ return l === r.type && a === r.width ? r : { ...r, type: l, width: a };
1903
+ });
1904
+ }
1905
+ function cl(e) {
1906
+ switch (e) {
1907
+ case "date":
1908
+ return { id: C(), type: "date", value: "", marks: {}, data: { isoDate: "" } };
1909
+ case "checkbox":
1910
+ return {
1911
+ id: C(),
1912
+ type: "checkbox",
1913
+ value: "",
1914
+ marks: {},
1915
+ data: { checked: !1, label: "" }
1916
+ };
1917
+ case "select":
1918
+ return {
1919
+ id: C(),
1920
+ type: "tableSelect",
1921
+ value: "",
1922
+ marks: {},
1923
+ data: { selectedValue: "", selectedLabel: "" }
1924
+ };
1925
+ default:
1926
+ return { id: C(), type: "text", value: "", marks: {} };
1927
+ }
1928
+ }
1929
+ function jt(e, t) {
1930
+ const n = cl(t == null ? void 0 : t.type);
1931
+ return {
1932
+ block: { id: C(), type: "tableCell", parentId: e, contentIds: [n.id], props: {} },
1933
+ run: n
1934
+ };
1935
+ }
1936
+ function il(e, t, n) {
1937
+ if (e.type === t) return e;
1938
+ let o;
1939
+ if (e.type === "text")
1940
+ o = e.value ?? "";
1941
+ else {
1942
+ const r = n == null ? void 0 : n.get(e.type);
1943
+ o = r != null && r.toPlainText ? r.toPlainText(e) : "";
1944
+ }
1945
+ if (t === "date") {
1946
+ const r = o ? new Date(o) : null, l = r && !Number.isNaN(r.getTime()) ? r.toISOString().slice(0, 10) : "";
1947
+ return { id: C(), type: "date", value: "", marks: {}, data: { isoDate: l } };
1948
+ }
1949
+ return t === "checkbox" ? {
1950
+ id: C(),
1951
+ type: "checkbox",
1952
+ value: "",
1953
+ marks: {},
1954
+ data: { checked: !1, label: o }
1955
+ } : { id: C(), type: "text", value: o, marks: {} };
1956
+ }
1957
+ function lt(e, t) {
1958
+ if (!e) return "";
1959
+ if (e.type === "text") return e.value ?? "";
1960
+ const n = t == null ? void 0 : t.get(e.type);
1961
+ return n != null && n.toPlainText ? n.toPlainText(e) : "";
1962
+ }
1963
+ function ul(e, t, n) {
1964
+ var o, r, l;
1965
+ return t === "date" ? ((o = e == null ? void 0 : e.data) == null ? void 0 : o.isoDate) ?? "" : t === "checkbox" ? (r = e == null ? void 0 : e.data) != null && r.checked ? 1 : 0 : t === "select" ? (((l = e == null ? void 0 : e.data) == null ? void 0 : l.selectedLabel) ?? "").trim() : lt(e, n).trim();
1966
+ }
1967
+ function dl(e, t, n) {
1968
+ if (n === "checkbox") return e - t;
1969
+ const o = Number(e), r = Number(t);
1970
+ return e !== "" && t !== "" && !Number.isNaN(o) && !Number.isNaN(r) ? o - r : String(e).localeCompare(String(t), void 0, { sensitivity: "base" });
1971
+ }
1972
+ function pl(e, t, n, o) {
1973
+ const r = e.map(({ rowId: a, run: s }) => ({
1974
+ rowId: a,
1975
+ key: ul(s, t, o)
1976
+ })), l = (a) => a === "" || a == null;
1977
+ return r.sort((a, s) => {
1978
+ const c = l(a.key), u = l(s.key);
1979
+ if (c && u) return 0;
1980
+ if (c) return 1;
1981
+ if (u) return -1;
1982
+ const p = dl(a.key, s.key, t);
1983
+ return n === "desc" ? -p : p;
1984
+ }), r.map((a) => a.rowId);
1985
+ }
1986
+ const fl = [
1987
+ "none",
1988
+ "count",
1989
+ "count-values",
1990
+ "count-empty",
1991
+ "sum",
1992
+ "average",
1993
+ "min",
1994
+ "max"
1995
+ ], ml = {
1996
+ none: "None",
1997
+ count: "Count all",
1998
+ "count-values": "Count filled",
1999
+ "count-empty": "Count empty",
2000
+ sum: "Sum",
2001
+ average: "Average",
2002
+ min: "Min",
2003
+ max: "Max"
2004
+ }, hl = {
2005
+ count: "Count",
2006
+ "count-values": "Filled",
2007
+ "count-empty": "Empty",
2008
+ sum: "Sum",
2009
+ average: "Avg",
2010
+ min: "Min",
2011
+ max: "Max"
2012
+ };
2013
+ function gl(e, t, n, o) {
2014
+ if (!n || n === "none") return null;
2015
+ if (n === "count") return e.length;
2016
+ const r = e.map((a) => lt(a, o).trim());
2017
+ if (n === "count-values") return r.filter((a) => a !== "").length;
2018
+ if (n === "count-empty") return r.filter((a) => a === "").length;
2019
+ const l = r.map(Number).filter((a, s) => r[s] !== "" && !Number.isNaN(a));
2020
+ return l.length === 0 ? null : n === "sum" ? l.reduce((a, s) => a + s, 0) : n === "average" ? l.reduce((a, s) => a + s, 0) / l.length : n === "min" ? Math.min(...l) : n === "max" ? Math.max(...l) : null;
2021
+ }
2022
+ function bl(e) {
2023
+ return e == null ? "" : Number.isInteger(e) ? String(e) : e.toFixed(2);
2024
+ }
2025
+ function $e(e, t) {
2026
+ if (typeof e.performBatch == "function") e.performBatch(t);
2027
+ else for (const n of t) e.applyOperation(n);
2028
+ }
2029
+ function Kn(e, t) {
2030
+ const o = e.getBlock(t.parentId).contentIds.indexOf(t.id);
2031
+ $e(e, [q(t.id)]);
2032
+ const r = Pt(e);
2033
+ if (r)
2034
+ return be(e, r), null;
2035
+ const l = e.getBlock(t.parentId), a = l.contentIds[o] ?? l.contentIds[o - 1];
2036
+ return a && be(e, a), null;
2037
+ }
2038
+ function yl(e, t) {
2039
+ const n = e.getBlock(t), o = e.getBlock(n.parentId), r = o.contentIds.indexOf(t), l = pe(o, n.contentIds.length), a = C(), s = [], c = [], u = [];
2040
+ for (const i of l) {
2041
+ const f = jt(a, i);
2042
+ s.push(f.block), c.push(f.run), u.push(f.block.id);
2043
+ }
2044
+ const p = { id: a, type: "tableRow", parentId: o.id, contentIds: u, props: {} };
2045
+ return e.applyOperation(
2046
+ ke(p, o.id, r + 1, { blocks: [p, ...s], runs: c })
2047
+ ), be(e, a), a;
2048
+ }
2049
+ function kl(e, t) {
2050
+ const n = e.getBlock(t), o = e.getBlock(n.parentId);
2051
+ if (o.contentIds.length <= 1)
2052
+ return Kn(e, o);
2053
+ const r = o.contentIds.indexOf(t);
2054
+ $e(e, [q(t)]);
2055
+ const l = e.getBlock(o.id), a = Math.min(r, l.contentIds.length - 1), s = l.contentIds[a];
2056
+ return s && be(e, s), s ?? null;
2057
+ }
2058
+ function Zt(e, t, n) {
2059
+ const o = e.getBlock(t), r = pe(
2060
+ o,
2061
+ o.contentIds[0] ? e.getBlock(o.contentIds[0]).contentIds.length : 0
2062
+ ), l = {
2063
+ id: C(),
2064
+ label: "New Column",
2065
+ type: It,
2066
+ width: Ut
2067
+ }, a = [];
2068
+ let s = null;
2069
+ for (const u of o.contentIds) {
2070
+ const p = jt(u, l);
2071
+ s === null && (s = p.block.id), a.push(
2072
+ ke(p.block, u, n + 1, { blocks: [p.block], runs: [p.run] })
2073
+ );
2074
+ }
2075
+ const c = [...r];
2076
+ return c.splice(n + 1, 0, l), a.push(G(t, { columns: c })), $e(e, a), s && be(e, s), s;
2077
+ }
2078
+ function vl(e, t, n) {
2079
+ const o = e.getBlock(t), r = e.getBlock(o.contentIds[0]);
2080
+ if (!r || r.contentIds.length <= 1)
2081
+ return Kn(e, o);
2082
+ const l = pe(o, r.contentIds.length), a = o.contentIds.map((i) => {
2083
+ const f = e.getBlock(i);
2084
+ return q(f.contentIds[n]);
2085
+ }), s = l.filter((i, f) => f !== n);
2086
+ a.push(G(t, { columns: s })), $e(e, a);
2087
+ const c = e.getBlock(o.contentIds[0]), u = Math.min(n, c.contentIds.length - 1), p = c.contentIds[u];
2088
+ return p && be(e, p), p ?? null;
2089
+ }
2090
+ function en(e, t, n, o) {
2091
+ const r = e.getBlock(t), l = e.getBlock(r.contentIds[0]), a = pe(r, l ? l.contentIds.length : 0);
2092
+ if (!a[n]) return;
2093
+ const s = [...a];
2094
+ s[n] = {
2095
+ ...a[n],
2096
+ width: Math.max(_e, Math.round(o))
2097
+ }, e.applyOperation(G(t, { columns: s }));
2098
+ }
2099
+ function Il(e, t, n, o) {
2100
+ const r = e.getBlock(t), l = e.getBlock(r.contentIds[0]), s = [...pe(r, l ? l.contentIds.length : 0)];
2101
+ s[n] && (s[n] = { ...s[n], label: o }, e.applyOperation(G(t, { columns: s })));
2102
+ }
2103
+ function tn(e, t, n, o, r) {
2104
+ var p;
2105
+ const l = e.getBlock(t), a = l.contentIds.map((i) => {
2106
+ const f = e.getBlock(i), b = e.getBlock(f.contentIds[n]);
2107
+ return { rowId: i, run: b ? e.getRun(b.contentIds[0]) : null };
2108
+ }), c = ((p = pe(
2109
+ l,
2110
+ a.length ? e.getBlock(l.contentIds[0]).contentIds.length : 0
2111
+ )[n]) == null ? void 0 : p.type) ?? It, u = pl(a, c, o, r);
2112
+ e.applyOperation(Lt(t, u));
2113
+ }
2114
+ function wl(e, t, n, o) {
2115
+ const r = e.getBlock(t), l = e.getBlock(r.contentIds[0]), a = pe(r, l ? l.contentIds.length : 0);
2116
+ if (!a[n]) return;
2117
+ const s = [...a];
2118
+ s[n] = { ...a[n], aggregate: o }, e.applyOperation(G(t, { columns: s }));
2119
+ }
2120
+ function Ft(e, t, n) {
2121
+ return t.contentIds.map((o) => {
2122
+ const l = e.getBlock(o).contentIds[n], a = e.getBlock(l);
2123
+ return { cellId: l, run: e.getRun(a.contentIds[0]) };
2124
+ });
2125
+ }
2126
+ function Tl(e, t, n, o) {
2127
+ const r = Ft(e, t, n), l = [], a = /* @__PURE__ */ new Map();
2128
+ for (const { run: c } of r) {
2129
+ const u = lt(c, o).trim();
2130
+ if (!u || a.has(u)) continue;
2131
+ const p = { value: C(), label: u };
2132
+ a.set(u, p), l.push(p);
2133
+ }
2134
+ const s = r.map(({ cellId: c, run: u }) => {
2135
+ const p = lt(u, o).trim(), i = a.get(p);
2136
+ return {
2137
+ cellId: c,
2138
+ run: {
2139
+ id: C(),
2140
+ type: "tableSelect",
2141
+ value: "",
2142
+ marks: {},
2143
+ data: { selectedValue: (i == null ? void 0 : i.value) ?? "", selectedLabel: (i == null ? void 0 : i.label) ?? "" }
2144
+ }
2145
+ };
2146
+ });
2147
+ return { options: l, newRuns: s };
2148
+ }
2149
+ function Cl(e, t, n, o, r) {
2150
+ const l = e.getBlock(t), a = e.getBlock(l.contentIds[0]), s = pe(l, a ? a.contentIds.length : 0), c = s[n];
2151
+ if (!c || c.type === o) return;
2152
+ const u = [...s];
2153
+ if (o === "select") {
2154
+ const { options: i, newRuns: f } = Tl(
2155
+ e,
2156
+ l,
2157
+ n,
2158
+ r
2159
+ );
2160
+ u[n] = { ...c, type: o, options: i };
2161
+ const b = [G(t, { columns: u })];
2162
+ for (const { cellId: v, run: g } of f) b.push(Ue(v, [g]));
2163
+ $e(e, b);
2164
+ return;
2165
+ }
2166
+ u[n] = { ...c, type: o };
2167
+ const p = [G(t, { columns: u })];
2168
+ for (const { cellId: i, run: f } of Ft(e, l, n)) {
2169
+ if (!f) continue;
2170
+ const b = il(f, o, r);
2171
+ p.push(Ue(i, [b]));
2172
+ }
2173
+ $e(e, p);
2174
+ }
2175
+ function ht(e, t, n, o) {
2176
+ var i, f;
2177
+ const r = e.getBlock(t), l = e.getBlock(r.contentIds[0]), a = pe(r, l ? l.contentIds.length : 0), s = a[n];
2178
+ if (!s) return;
2179
+ const c = [...a];
2180
+ c[n] = { ...s, options: o };
2181
+ const u = [G(t, { columns: c })], p = new Map(o.map((b) => [b.value, b]));
2182
+ for (const { run: b } of Ft(e, r, n)) {
2183
+ if (!b || b.type !== "tableSelect") continue;
2184
+ const v = ((i = b.data) == null ? void 0 : i.selectedValue) ?? "", g = p.get(v), k = g ? v : "", I = g ? g.label : "";
2185
+ (k !== v || I !== (((f = b.data) == null ? void 0 : f.selectedLabel) ?? "")) && u.push(
2186
+ ie(b.id, {
2187
+ data: { selectedValue: k, selectedLabel: I }
2188
+ })
2189
+ );
2190
+ }
2191
+ $e(e, u);
2192
+ }
2193
+ const Bl = "$fieldTypes";
2194
+ function Rl() {
2195
+ const e = V(), t = h(
2196
+ (o) => e.subscribe(Bl, o),
2197
+ [e]
2198
+ ), n = h(() => e.getFieldTypes(), [e]);
2199
+ return un(t, n);
2200
+ }
2201
+ function nn() {
2202
+ if (typeof window > "u" || !window.visualViewport) return 0;
2203
+ const e = window.visualViewport, t = window.innerHeight - (e.height + e.offsetTop);
2204
+ return t > 0 ? Math.round(t) : 0;
2205
+ }
2206
+ function Nl() {
2207
+ const [e, t] = O(nn);
2208
+ return oe(() => {
2209
+ if (typeof window > "u" || !window.visualViewport) return;
2210
+ const n = window.visualViewport, o = () => t(nn());
2211
+ return o(), n.addEventListener("resize", o), n.addEventListener("scroll", o), () => {
2212
+ n.removeEventListener("resize", o), n.removeEventListener("scroll", o);
2213
+ };
2214
+ }, []), e;
2215
+ }
2216
+ const Ll = 280, on = 220, Al = 32, rn = 6;
2217
+ function Ml(e, t) {
2218
+ return t ? e.label.toLowerCase().includes(t.toLowerCase()) : !0;
2219
+ }
2220
+ function Fe({
2221
+ value: e,
2222
+ options: t,
2223
+ onChange: n,
2224
+ placeholder: o = "Select…",
2225
+ ariaLabel: r,
2226
+ className: l = "",
2227
+ variant: a = "default",
2228
+ selectedLabel: s,
2229
+ selectedColor: c,
2230
+ onManageOptions: u,
2231
+ manageOptionsLabel: p = "Manage options…",
2232
+ mention: i = !1,
2233
+ autoOpen: f = !1
2234
+ }) {
2235
+ var Ye, Xe;
2236
+ const [b, v] = O(!1), [g, k] = O(""), [I, m] = O(0), [y, B] = O(null), L = Nl(), [D, S] = O([]), [$, A] = O(!1), [F, w] = O(!1), N = _(null), x = _(null), H = _(null), E = _(null), P = _(null), Y = _(null), X = je(() => [N, H], []), K = a === "tag", z = typeof t == "function", [Q, he] = O(Al), [ue, ce] = O(0), Ie = z ? void 0 : t.find((R) => R.value === e), de = e ? Ie ?? (s ? { label: s, color: c } : void 0) : void 0, te = je(
2237
+ () => z ? D : t.filter((R) => Ml(R, g)),
2238
+ [z, D, t, g]
2239
+ ), Ae = Math.max(0, (te.length - 1) * Q), ye = Math.min(ue, Ae), Z = te.length ? Math.max(0, Math.floor(ye / Q) - rn) : 0, it = Math.ceil(on / Q) + rn * 2, We = Math.min(te.length, Z + it), ut = te.slice(Z, We), M = Z * Q, W = Math.max(0, (te.length - We) * Q);
2240
+ rt(() => {
2241
+ var ne;
2242
+ const R = (ne = Y.current) == null ? void 0 : ne.getBoundingClientRect().height;
2243
+ R && Math.abs(R - Q) > 0.5 && he(R);
2244
+ }), oe(() => {
2245
+ if (!z || !b) return;
2246
+ let R = !1;
2247
+ A(!0), w(!1);
2248
+ const ne = setTimeout(() => {
2249
+ Promise.resolve(t(g)).then((ge) => {
2250
+ R || (S(ge ?? []), A(!1));
2251
+ }).catch(() => {
2252
+ R || (S([]), A(!1), w(!0));
2253
+ });
2254
+ }, 250);
2255
+ return () => {
2256
+ R = !0, clearTimeout(ne);
2257
+ };
2258
+ }, [z, b, t, g]);
2259
+ const j = h(() => v(!1), []);
2260
+ at(X, b, j);
2261
+ const J = _o(H, b, y == null ? void 0 : y.left), we = h(() => {
2262
+ var R;
2263
+ B(((R = x.current) == null ? void 0 : R.getBoundingClientRect()) ?? null), k(""), m(0), ce(0), v(!0);
2264
+ }, []);
2265
+ oe(() => {
2266
+ f && we();
2267
+ }, []), oe(() => {
2268
+ var R;
2269
+ b && ((R = E.current) == null || R.focus());
2270
+ }, [b, J]), oe(() => {
2271
+ const R = P.current;
2272
+ if (!R) return;
2273
+ const ne = I * Q, ge = ne + Q, Qe = R.scrollTop, Je = R.clientHeight || on, wt = Qe + Je;
2274
+ let Ze = null;
2275
+ ne < Qe ? Ze = ne : ge > wt && (Ze = ge - Je), Ze !== null && (R.scrollTop = Ze, ce(Ze));
2276
+ }, [I, Q]);
2277
+ const qe = h(
2278
+ (R) => {
2279
+ var ne;
2280
+ n(R.value, R), j(), (ne = x.current) == null || ne.focus();
2281
+ },
2282
+ [n, j]
2283
+ ), dt = h(
2284
+ (R) => {
2285
+ var ne;
2286
+ R.key === "ArrowDown" ? (R.preventDefault(), m((ge) => Math.min(ge + 1, Math.max(te.length - 1, 0)))) : R.key === "ArrowUp" ? (R.preventDefault(), m((ge) => Math.max(ge - 1, 0))) : R.key === "Enter" ? (R.preventDefault(), te[I] && qe(te[I])) : R.key === "Escape" && (R.preventDefault(), j(), (ne = x.current) == null || ne.focus());
2287
+ },
2288
+ [te, I, qe, j]
2289
+ );
2290
+ return /* @__PURE__ */ T("span", { className: `be-select ${l}`.trim(), ref: N, children: [
2291
+ /* @__PURE__ */ d(
2292
+ "button",
2293
+ {
2294
+ type: "button",
2295
+ ref: x,
2296
+ className: `be-select-trigger${K ? " be-select-trigger-tag" : ""}${i ? " be-select-trigger-mention" : ""}`,
2297
+ "aria-haspopup": "listbox",
2298
+ "aria-expanded": b,
2299
+ "aria-label": r,
2300
+ onClick: () => b ? j() : we(),
2301
+ children: K ? de ? /* @__PURE__ */ d(
2302
+ "span",
2303
+ {
2304
+ className: `be-select-tag${i ? " be-select-tag-mention" : ""}`,
2305
+ style: i ? void 0 : { background: (Ye = de.color) == null ? void 0 : Ye.bg, color: (Xe = de.color) == null ? void 0 : Xe.text },
2306
+ children: i ? `@${de.label}` : de.label
2307
+ }
2308
+ ) : /* @__PURE__ */ d("span", { className: "be-select-value be-select-value-placeholder", children: o }) : /* @__PURE__ */ T(Te, { children: [
2309
+ /* @__PURE__ */ d("span", { className: "be-select-value", children: de ? de.label : o }),
2310
+ /* @__PURE__ */ d(Dt, { size: 14, className: "be-select-chevron" })
2311
+ ] })
2312
+ }
2313
+ ),
2314
+ b && y && J != null && Oe(
2315
+ /* @__PURE__ */ T(
2316
+ "div",
2317
+ {
2318
+ ref: H,
2319
+ className: "be-select-popover",
2320
+ style: {
2321
+ position: "fixed",
2322
+ left: J,
2323
+ minWidth: y.width,
2324
+ // Flips above the trigger instead of below it once there isn't
2325
+ // enough room left before the keyboard (or screen bottom) —
2326
+ // otherwise the popover can render partly/entirely hidden
2327
+ // underneath an open on-screen keyboard.
2328
+ ...y.bottom + Ll > window.innerHeight - L ? { bottom: window.innerHeight - y.top + 4 } : { top: y.bottom + 4 }
2329
+ },
2330
+ children: [
2331
+ /* @__PURE__ */ d(
2332
+ "input",
2333
+ {
2334
+ ref: E,
2335
+ type: "text",
2336
+ className: "be-select-search",
2337
+ value: g,
2338
+ onChange: (R) => {
2339
+ k(R.target.value), m(0);
2340
+ },
2341
+ onKeyDown: dt,
2342
+ placeholder: "Search…",
2343
+ "aria-label": r ? `Search ${r}` : "Search options"
2344
+ }
2345
+ ),
2346
+ /* @__PURE__ */ T(
2347
+ "div",
2348
+ {
2349
+ className: "be-select-options",
2350
+ role: "listbox",
2351
+ ref: P,
2352
+ onScroll: (R) => ce(R.currentTarget.scrollTop),
2353
+ children: [
2354
+ z && $ && /* @__PURE__ */ d("div", { className: "be-select-empty", children: "Loading…" }),
2355
+ z && !$ && F && /* @__PURE__ */ d("div", { className: "be-select-empty be-select-error", children: "Couldn't load options" }),
2356
+ !$ && !F && te.length === 0 && /* @__PURE__ */ d("div", { className: "be-select-empty", children: "No results" }),
2357
+ !$ && !F && te.length > 0 && /* @__PURE__ */ T(Te, { children: [
2358
+ M > 0 && /* @__PURE__ */ d("div", { style: { height: M }, "aria-hidden": "true" }),
2359
+ ut.map((R, ne) => {
2360
+ var Qe, Je;
2361
+ const ge = Z + ne;
2362
+ return /* @__PURE__ */ d(
2363
+ "div",
2364
+ {
2365
+ ref: ne === 0 ? Y : void 0,
2366
+ role: "option",
2367
+ "aria-selected": R.value === e,
2368
+ className: `be-select-option${ge === I ? " be-select-option-active" : ""}${R.value === e ? " be-select-option-selected" : ""}`,
2369
+ onMouseDown: (wt) => {
2370
+ wt.preventDefault(), qe(R);
2371
+ },
2372
+ onMouseEnter: () => m(ge),
2373
+ children: K ? /* @__PURE__ */ d(
2374
+ "span",
2375
+ {
2376
+ className: "be-select-tag",
2377
+ style: { background: (Qe = R.color) == null ? void 0 : Qe.bg, color: (Je = R.color) == null ? void 0 : Je.text },
2378
+ children: R.label
2379
+ }
2380
+ ) : R.label
2381
+ },
2382
+ R.value
2383
+ );
2384
+ }),
2385
+ W > 0 && /* @__PURE__ */ d("div", { style: { height: W }, "aria-hidden": "true" })
2386
+ ] })
2387
+ ]
2388
+ }
2389
+ ),
2390
+ u && /* @__PURE__ */ d(
2391
+ "button",
2392
+ {
2393
+ type: "button",
2394
+ className: "be-select-manage-options",
2395
+ onMouseDown: (R) => {
2396
+ R.preventDefault(), j(), u();
2397
+ },
2398
+ children: p
2399
+ }
2400
+ )
2401
+ ]
2402
+ }
2403
+ ),
2404
+ document.body
2405
+ )
2406
+ ] });
2407
+ }
2408
+ const pt = [
2409
+ { bg: "#e9e9e7", text: "#32302c" },
2410
+ // gray (default)
2411
+ { bg: "#eee0da", text: "#64473a" },
2412
+ // brown
2413
+ { bg: "#fadec9", text: "#8a4b23" },
2414
+ // orange
2415
+ { bg: "#fdecc8", text: "#8a6116" },
2416
+ // yellow
2417
+ { bg: "#dbeddb", text: "#256029" },
2418
+ // green
2419
+ { bg: "#d3e5ef", text: "#1a5f8a" },
2420
+ // blue
2421
+ { bg: "#e8deee", text: "#5b3a8a" },
2422
+ // purple
2423
+ { bg: "#f5e0e9", text: "#8a3a5f" },
2424
+ // pink
2425
+ { bg: "#ffe2dd", text: "#a13a2f" }
2426
+ // red
2427
+ ];
2428
+ function Mt(e) {
2429
+ return pt[(e % pt.length + pt.length) % pt.length];
2430
+ }
2431
+ const El = { text: "Text", date: "Date", checkbox: "Checkbox", select: "Select" }, $l = fl.map((e) => ({
2432
+ value: e,
2433
+ label: ml[e]
2434
+ })), xl = al.map((e) => ({ value: e, label: El[e] })), Ct = 800;
2435
+ function Ol({ tableId: e, colIndex: t }) {
2436
+ const n = V(), o = Rl(), { openCreate: r } = bo(), l = h(
2437
+ (a) => {
2438
+ const s = n.getFieldType(a);
2439
+ s && ht(n, e, t, s.options ?? []);
2440
+ },
2441
+ [n, e, t]
2442
+ );
2443
+ return /* @__PURE__ */ T("div", { className: "be-table-header-menu-field-type", children: [
2444
+ o.length > 0 && /* @__PURE__ */ d(
2445
+ Fe,
2446
+ {
2447
+ value: "",
2448
+ options: o.map((a) => ({ value: a.id, label: a.label })),
2449
+ onChange: l,
2450
+ placeholder: "Copy options from…",
2451
+ ariaLabel: "Copy options from an existing field type"
2452
+ }
2453
+ ),
2454
+ /* @__PURE__ */ d("button", { type: "button", className: "be-table-header-menu-item", onClick: r, children: "+ New field type" })
2455
+ ] });
2456
+ }
2457
+ function Sl({ tableId: e, colIndex: t, options: n }) {
2458
+ const o = V(), [r, l] = O(""), a = h(
2459
+ (u, p) => {
2460
+ ht(
2461
+ o,
2462
+ e,
2463
+ t,
2464
+ n.map((i) => i.value === u ? { ...i, label: p } : i)
2465
+ );
2466
+ },
2467
+ [o, e, t, n]
2468
+ ), s = h(
2469
+ (u) => ht(
2470
+ o,
2471
+ e,
2472
+ t,
2473
+ n.filter((p) => p.value !== u)
2474
+ ),
2475
+ [o, e, t, n]
2476
+ ), c = h(() => {
2477
+ const u = r.trim();
2478
+ l(""), u && ht(o, e, t, [
2479
+ ...n,
2480
+ { value: C(), label: u, color: Mt(n.length) }
2481
+ ]);
2482
+ }, [o, e, t, n, r]);
2483
+ return /* @__PURE__ */ T("div", { className: "be-table-header-menu-options", children: [
2484
+ /* @__PURE__ */ d("div", { className: "be-table-header-menu-options-label", children: "Options" }),
2485
+ n.map((u, p) => /* @__PURE__ */ T("div", { className: "be-table-header-menu-option-row", children: [
2486
+ /* @__PURE__ */ d(
2487
+ "span",
2488
+ {
2489
+ className: "be-table-header-menu-option-swatch",
2490
+ style: { background: (u.color ?? Mt(p)).bg },
2491
+ "aria-hidden": "true"
2492
+ }
2493
+ ),
2494
+ /* @__PURE__ */ d(
2495
+ "input",
2496
+ {
2497
+ className: "be-table-header-menu-option-input",
2498
+ value: u.label,
2499
+ onChange: (i) => a(u.value, i.target.value),
2500
+ "aria-label": `Rename option ${u.label}`
2501
+ }
2502
+ ),
2503
+ /* @__PURE__ */ d(
2504
+ "button",
2505
+ {
2506
+ type: "button",
2507
+ className: "be-table-header-menu-option-remove",
2508
+ onClick: () => s(u.value),
2509
+ "aria-label": `Remove option ${u.label}`,
2510
+ children: /* @__PURE__ */ d(st, { size: 14 })
2511
+ }
2512
+ )
2513
+ ] }, u.value)),
2514
+ /* @__PURE__ */ T("div", { className: "be-table-header-menu-option-row", children: [
2515
+ /* @__PURE__ */ d(
2516
+ "input",
2517
+ {
2518
+ className: "be-table-header-menu-option-input",
2519
+ value: r,
2520
+ onChange: (u) => l(u.target.value),
2521
+ placeholder: "New option…",
2522
+ onKeyDown: (u) => {
2523
+ u.key === "Enter" && (u.preventDefault(), c());
2524
+ }
2525
+ }
2526
+ ),
2527
+ /* @__PURE__ */ d(
2528
+ "button",
2529
+ {
2530
+ type: "button",
2531
+ className: "be-table-header-menu-option-add",
2532
+ onClick: c,
2533
+ "aria-label": "Add option",
2534
+ children: "+"
2535
+ }
2536
+ )
2537
+ ] })
2538
+ ] });
2539
+ }
2540
+ function Dl({ tableId: e, column: t, colIndex: n, colCount: o, filterValue: r, onFilterChange: l }) {
2541
+ const a = V(), s = Ot(), [c, u] = O(!1), [p, i] = O(null), [f, b] = O(null), v = _(null), g = _(null), k = _(null), I = je(() => [v, g], []), m = h(() => u(!1), []);
2542
+ at(I, c, m), _t(g, c, m, v);
2543
+ const y = Uo(g, c, p == null ? void 0 : p.right), B = h(() => {
2544
+ var E;
2545
+ i(((E = k.current) == null ? void 0 : E.getBoundingClientRect()) ?? null), u(!0);
2546
+ }, []), L = h(
2547
+ (E) => Il(a, e, n, E.target.value),
2548
+ [a, e, n]
2549
+ ), D = h(() => {
2550
+ Zt(a, e, n - 1), m();
2551
+ }, [a, e, n, m]), S = h(() => {
2552
+ Zt(a, e, n), m();
2553
+ }, [a, e, n, m]), $ = h(() => {
2554
+ vl(a, e, n), m();
2555
+ }, [a, e, n, m]), A = h(
2556
+ (E) => Cl(a, e, n, E, s),
2557
+ [a, e, n, s]
2558
+ ), F = h(() => {
2559
+ tn(a, e, n, "asc", s), m();
2560
+ }, [a, e, n, s, m]), w = h(() => {
2561
+ tn(a, e, n, "desc", s), m();
2562
+ }, [a, e, n, s, m]), N = h(
2563
+ (E) => wl(a, e, n, E),
2564
+ [a, e, n]
2565
+ ), x = h(
2566
+ (E) => {
2567
+ var ue;
2568
+ E.preventDefault();
2569
+ const P = (ue = k.current) == null ? void 0 : ue.closest("table"), Y = P == null ? void 0 : P.querySelector(`col[data-col-index="${n}"]`);
2570
+ if (!Y) return;
2571
+ const X = k.current.getBoundingClientRect().width, K = E.clientX, z = (ce) => Math.max(_e, Math.round(X + (ce.clientX - K))), Q = (ce) => {
2572
+ const Ie = z(ce);
2573
+ Y.style.width = `${Ie}px`, b(Ie);
2574
+ }, he = (ce) => {
2575
+ document.removeEventListener("mousemove", Q), document.removeEventListener("mouseup", he), en(a, e, n, z(ce)), b(null);
2576
+ };
2577
+ document.addEventListener("mousemove", Q), document.addEventListener("mouseup", he);
2578
+ },
2579
+ [a, e, n]
2580
+ ), H = h(
2581
+ (E) => {
2582
+ const P = t.width ?? _e, Y = E.shiftKey ? 1 : 16;
2583
+ let X;
2584
+ if (E.key === "ArrowLeft" || E.key === "ArrowDown")
2585
+ X = Math.max(_e, P - Y);
2586
+ else if (E.key === "ArrowRight" || E.key === "ArrowUp")
2587
+ X = Math.min(Ct, P + Y);
2588
+ else if (E.key === "Home") X = _e;
2589
+ else if (E.key === "End") X = Ct;
2590
+ else return;
2591
+ E.preventDefault(), en(a, e, n, X);
2592
+ },
2593
+ [a, e, n, t.width]
2594
+ );
2595
+ return /* @__PURE__ */ T("th", { ref: k, scope: "col", className: "be-table-header-cell", contentEditable: !1, children: [
2596
+ /* @__PURE__ */ d(
2597
+ "input",
2598
+ {
2599
+ className: "be-table-header-label",
2600
+ value: t.label,
2601
+ onChange: L,
2602
+ "aria-label": `Column ${n + 1} name`
2603
+ }
2604
+ ),
2605
+ /* @__PURE__ */ d(
2606
+ "button",
2607
+ {
2608
+ ref: v,
2609
+ type: "button",
2610
+ className: "be-table-header-menu-trigger",
2611
+ "aria-label": `Column ${n + 1} options`,
2612
+ "aria-haspopup": "menu",
2613
+ "aria-expanded": c,
2614
+ onClick: () => c ? m() : B(),
2615
+ children: "⋮"
2616
+ }
2617
+ ),
2618
+ /* @__PURE__ */ d(
2619
+ "div",
2620
+ {
2621
+ className: "be-table-col-resize-handle",
2622
+ onMouseDown: x,
2623
+ onKeyDown: H,
2624
+ role: "slider",
2625
+ tabIndex: 0,
2626
+ "aria-label": `Resize column ${n + 1}`,
2627
+ "aria-valuemin": _e,
2628
+ "aria-valuemax": Ct,
2629
+ "aria-valuenow": f ?? t.width
2630
+ }
2631
+ ),
2632
+ c && p && y != null && Oe(
2633
+ /* @__PURE__ */ T(
2634
+ "div",
2635
+ {
2636
+ ref: g,
2637
+ role: "menu",
2638
+ "aria-label": `Column ${n + 1} options`,
2639
+ className: "be-table-header-menu",
2640
+ style: {
2641
+ position: "fixed",
2642
+ top: p.bottom + 4,
2643
+ left: y,
2644
+ transform: "translateX(-100%)"
2645
+ },
2646
+ children: [
2647
+ /* @__PURE__ */ T("div", { className: "be-table-header-menu-type", children: [
2648
+ /* @__PURE__ */ d("span", { id: `be-table-col-type-${t.id}`, children: "Type" }),
2649
+ /* @__PURE__ */ d(
2650
+ Fe,
2651
+ {
2652
+ value: t.type,
2653
+ options: xl,
2654
+ onChange: A,
2655
+ ariaLabel: "Column type",
2656
+ className: ""
2657
+ }
2658
+ )
2659
+ ] }),
2660
+ t.type === "select" && /* @__PURE__ */ T(Te, { children: [
2661
+ /* @__PURE__ */ d(Ol, { tableId: e, colIndex: n }),
2662
+ /* @__PURE__ */ d(
2663
+ Sl,
2664
+ {
2665
+ tableId: e,
2666
+ colIndex: n,
2667
+ options: t.options ?? []
2668
+ }
2669
+ )
2670
+ ] }),
2671
+ /* @__PURE__ */ T("div", { className: "be-table-header-menu-sort", children: [
2672
+ /* @__PURE__ */ T(
2673
+ "button",
2674
+ {
2675
+ type: "button",
2676
+ role: "menuitem",
2677
+ className: "be-table-header-menu-item",
2678
+ onClick: F,
2679
+ children: [
2680
+ /* @__PURE__ */ d(Tn, { size: 13 }),
2681
+ " Sort ascending"
2682
+ ]
2683
+ }
2684
+ ),
2685
+ /* @__PURE__ */ T(
2686
+ "button",
2687
+ {
2688
+ type: "button",
2689
+ role: "menuitem",
2690
+ className: "be-table-header-menu-item",
2691
+ onClick: w,
2692
+ children: [
2693
+ /* @__PURE__ */ d(Cn, { size: 13 }),
2694
+ " Sort descending"
2695
+ ]
2696
+ }
2697
+ )
2698
+ ] }),
2699
+ /* @__PURE__ */ T("label", { className: "be-table-header-menu-filter", children: [
2700
+ /* @__PURE__ */ d("span", { children: "Filter" }),
2701
+ /* @__PURE__ */ d(
2702
+ "input",
2703
+ {
2704
+ type: "text",
2705
+ className: "be-table-header-menu-filter-input",
2706
+ placeholder: "Rows containing…",
2707
+ value: r ?? "",
2708
+ onChange: (E) => l(t.id, E.target.value),
2709
+ "aria-label": `Filter column ${n + 1}`
2710
+ }
2711
+ )
2712
+ ] }),
2713
+ /* @__PURE__ */ T("div", { className: "be-table-header-menu-type be-table-header-menu-aggregate", children: [
2714
+ /* @__PURE__ */ d("span", { id: `be-table-col-aggregate-${t.id}`, children: "Footer" }),
2715
+ /* @__PURE__ */ d(
2716
+ Fe,
2717
+ {
2718
+ value: t.aggregate ?? "none",
2719
+ options: $l,
2720
+ onChange: N,
2721
+ ariaLabel: "Column footer aggregate",
2722
+ className: ""
2723
+ }
2724
+ )
2725
+ ] }),
2726
+ /* @__PURE__ */ d(
2727
+ "button",
2728
+ {
2729
+ type: "button",
2730
+ role: "menuitem",
2731
+ className: "be-table-header-menu-item",
2732
+ onClick: D,
2733
+ children: "Insert column left"
2734
+ }
2735
+ ),
2736
+ /* @__PURE__ */ d(
2737
+ "button",
2738
+ {
2739
+ type: "button",
2740
+ role: "menuitem",
2741
+ className: "be-table-header-menu-item",
2742
+ onClick: S,
2743
+ children: "Insert column right"
2744
+ }
2745
+ ),
2746
+ /* @__PURE__ */ d(
2747
+ "button",
2748
+ {
2749
+ type: "button",
2750
+ role: "menuitem",
2751
+ className: "be-table-header-menu-item be-table-header-menu-item-danger",
2752
+ onClick: $,
2753
+ disabled: o <= 1,
2754
+ children: "Delete column"
2755
+ }
2756
+ )
2757
+ ]
2758
+ }
2759
+ ),
2760
+ document.body
2761
+ )
2762
+ ] });
2763
+ }
2764
+ function Hl({ tableId: e, columns: t, filters: n, onFilterChange: o }) {
2765
+ return /* @__PURE__ */ d("thead", { children: /* @__PURE__ */ T("tr", { className: "be-table-header-row", children: [
2766
+ t.map((r, l) => /* @__PURE__ */ d(
2767
+ Dl,
2768
+ {
2769
+ tableId: e,
2770
+ column: r,
2771
+ colIndex: l,
2772
+ colCount: t.length,
2773
+ filterValue: n == null ? void 0 : n[r.id],
2774
+ onFilterChange: o
2775
+ },
2776
+ r.id
2777
+ )),
2778
+ /* @__PURE__ */ d("th", { className: "be-table-header-spacer", "aria-hidden": "true" })
2779
+ ] }) });
2780
+ }
2781
+ function Pl({ id: e }) {
2782
+ var g;
2783
+ const t = V(), n = Ot(), o = ee(e), [r, l] = O({}), a = h((k, I) => {
2784
+ l(
2785
+ (m) => I ? { ...m, [k]: I } : Object.fromEntries(Object.entries(m).filter(([y]) => y !== k))
2786
+ );
2787
+ }, []), s = h(() => {
2788
+ var I;
2789
+ const k = (I = o == null ? void 0 : o.contentIds) == null ? void 0 : I[o.contentIds.length - 1];
2790
+ k && yl(t, k);
2791
+ }, [t, o]), c = se("be-table-wrapper", o), u = je(() => Object.entries(r).filter(([, k]) => k), [r]), p = h(
2792
+ (k, I) => {
2793
+ const m = t.getBlock(k), y = m && t.getBlock(m.contentIds[I]);
2794
+ return y ? t.getRun(y.contentIds[0]) : null;
2795
+ },
2796
+ [t]
2797
+ );
2798
+ if (!o) return null;
2799
+ const i = t.getBlock(o.contentIds[0]), f = pe(o, ((g = i == null ? void 0 : i.contentIds) == null ? void 0 : g.length) ?? 0), b = u.length === 0 ? o.contentIds : o.contentIds.filter(
2800
+ (k) => u.every(([I, m]) => {
2801
+ const y = f.findIndex((L) => L.id === I);
2802
+ return y === -1 ? !0 : lt(p(k, y), n).toLowerCase().includes(m.toLowerCase());
2803
+ })
2804
+ ), v = f.some((k) => k.aggregate && k.aggregate !== "none");
2805
+ return (
2806
+ // be-table-scroll is a second, OUTER scroll boundary around
2807
+ // be-table-wrapper's own overflow-x:auto: a fixed-layout table whose
2808
+ // columns sum wider than the page can otherwise force its ancestors
2809
+ // (this block's row content, .be-surface, ...) to grow to fit it
2810
+ // instead of actually scrolling inside be-table-wrapper — depending on
2811
+ // the host app's own surrounding layout, that can bubble all the way
2812
+ // up to the whole page scrolling horizontally. This wrapper's own
2813
+ // max-width:100% + overflow-x:auto is a hard stop that can't be
2814
+ // out-grown by anything inside it, regardless of what's going on
2815
+ // further up the tree.
2816
+ /* @__PURE__ */ d("div", { className: "be-table-scroll", children: /* @__PURE__ */ T("div", { className: c, "data-block-id": e, children: [
2817
+ /* @__PURE__ */ T("table", { className: "be-table", children: [
2818
+ /* @__PURE__ */ T("colgroup", { children: [
2819
+ f.map((k, I) => /* @__PURE__ */ d("col", { "data-col-index": I, style: { width: k.width } }, k.id)),
2820
+ /* @__PURE__ */ d("col", { className: "be-table-header-spacer-col" })
2821
+ ] }),
2822
+ /* @__PURE__ */ d(
2823
+ Hl,
2824
+ {
2825
+ tableId: e,
2826
+ columns: f,
2827
+ filters: r,
2828
+ onFilterChange: a
2829
+ }
2830
+ ),
2831
+ /* @__PURE__ */ d("tbody", { children: /* @__PURE__ */ d(He, { parentId: e, filterIds: b }) }),
2832
+ v && /* @__PURE__ */ d("tfoot", { children: /* @__PURE__ */ T("tr", { className: "be-table-footer-row", children: [
2833
+ f.map((k, I) => {
2834
+ const m = b.map((B) => p(B, I)), y = gl(
2835
+ m,
2836
+ k.type,
2837
+ k.aggregate,
2838
+ n
2839
+ );
2840
+ return /* @__PURE__ */ d("td", { className: "be-table-footer-cell", children: y != null && /* @__PURE__ */ T(Te, { children: [
2841
+ /* @__PURE__ */ d("span", { className: "be-table-footer-label", children: hl[k.aggregate] }),
2842
+ bl(y)
2843
+ ] }) }, k.id);
2844
+ }),
2845
+ /* @__PURE__ */ d("td", { className: "be-table-footer-spacer", "aria-hidden": "true" })
2846
+ ] }) })
2847
+ ] }),
2848
+ /* @__PURE__ */ T(
2849
+ "button",
2850
+ {
2851
+ type: "button",
2852
+ className: "be-table-add-row",
2853
+ contentEditable: !1,
2854
+ onClick: s,
2855
+ children: [
2856
+ /* @__PURE__ */ d(wn, { size: 14 }),
2857
+ " Add row"
2858
+ ]
2859
+ }
2860
+ )
2861
+ ] }) })
2862
+ );
2863
+ }
2864
+ function _l({ id: e }) {
2865
+ const t = V(), n = ee(e), o = se("be-table-row", n), r = h(() => kl(t, e), [t, e]);
2866
+ return /* @__PURE__ */ T("tr", { className: o, "data-block-id": e, children: [
2867
+ /* @__PURE__ */ d(He, { parentId: e }),
2868
+ /* @__PURE__ */ d("td", { className: "be-table-row-actions", contentEditable: !1, children: /* @__PURE__ */ d(
2869
+ "button",
2870
+ {
2871
+ type: "button",
2872
+ className: "be-table-delete-row",
2873
+ onClick: r,
2874
+ "aria-label": "Delete row",
2875
+ title: "Delete row",
2876
+ children: /* @__PURE__ */ d(st, { size: 14 })
2877
+ }
2878
+ ) })
2879
+ ] });
2880
+ }
2881
+ function Vn(e, t) {
2882
+ const n = e.getBlock(t), o = e.getBlock(n.parentId), r = e.getBlock(o.parentId);
2883
+ return {
2884
+ table: r,
2885
+ row: o,
2886
+ rowIndex: r.contentIds.indexOf(o.id),
2887
+ colIndex: o.contentIds.indexOf(t)
2888
+ };
2889
+ }
2890
+ function Ul(e, t, n) {
2891
+ const { table: o, row: r, rowIndex: l, colIndex: a } = Vn(e, t);
2892
+ if (n === "left" || n === "right") {
2893
+ const p = n === "right" ? 1 : -1, i = a + p;
2894
+ if (i >= 0 && i < r.contentIds.length)
2895
+ return r.contentIds[i];
2896
+ const f = l + p;
2897
+ if (f < 0 || f >= o.contentIds.length) return null;
2898
+ const b = e.getBlock(o.contentIds[f]), v = n === "right" ? 0 : b.contentIds.length - 1;
2899
+ return b.contentIds[v];
2900
+ }
2901
+ const c = l + (n === "down" ? 1 : -1);
2902
+ if (c < 0 || c >= o.contentIds.length) return null;
2903
+ const u = e.getBlock(o.contentIds[c]);
2904
+ return u.contentIds[a] ?? u.contentIds[u.contentIds.length - 1] ?? null;
2905
+ }
2906
+ function jl(e, t) {
2907
+ const n = Oo(e, t, "down");
2908
+ if (n) {
2909
+ ve(n);
2910
+ return;
2911
+ }
2912
+ Ke(e, t, U("paragraph"));
2913
+ }
2914
+ function tt(e, t, n) {
2915
+ var r;
2916
+ const o = Ul(e, t, n);
2917
+ if (o) {
2918
+ const l = e.getBlock(o), a = (r = l == null ? void 0 : l.contentIds) == null ? void 0 : r[0];
2919
+ a && ve(a);
2920
+ return;
2921
+ }
2922
+ if (n === "right") {
2923
+ const { table: l } = Vn(e, t);
2924
+ jl(e, l.id);
2925
+ }
2926
+ }
2927
+ function Fl({ id: e }) {
2928
+ const t = V(), n = ee(e), o = h(() => tt(t, e, "right"), [t, e]), r = h(() => tt(t, e, "left"), [t, e]), l = h(() => tt(t, e, "up"), [t, e]), a = h(() => tt(t, e, "down"), [t, e]), s = h(() => tt(t, e, "down"), [t, e]), c = se("be-table-cell", n);
2929
+ if (!n) return null;
2930
+ const u = Ce(t, n);
2931
+ return /* @__PURE__ */ d("td", { className: c, "data-block-id": e, dir: u, children: /* @__PURE__ */ d(
2932
+ Le,
2933
+ {
2934
+ blockId: e,
2935
+ runIds: n.contentIds,
2936
+ dir: u,
2937
+ onTab: o,
2938
+ onShiftTab: r,
2939
+ onArrowUp: l,
2940
+ onArrowDown: a,
2941
+ onEnter: s
2942
+ }
2943
+ ) });
2944
+ }
2945
+ function zl(e, t) {
2946
+ const n = C(), o = [], r = [], l = [];
2947
+ for (const a of t) {
2948
+ const s = jt(n, a);
2949
+ o.push(s.block), r.push(s.run), l.push(s.block.id);
2950
+ }
2951
+ return {
2952
+ block: { id: n, type: "tableRow", parentId: e, contentIds: l, props: {} },
2953
+ blocks: o,
2954
+ runs: r
2955
+ };
2956
+ }
2957
+ function Kl({ rows: e = 2, cols: t = 2 } = {}) {
2958
+ return function(o) {
2959
+ const r = C(), l = zn(t), a = [], s = [], c = [];
2960
+ for (let p = 0; p < e; p += 1) {
2961
+ const i = zl(r, l);
2962
+ a.push(i.block, ...i.blocks), s.push(...i.runs), c.push(i.block.id);
2963
+ }
2964
+ return { block: { id: r, type: "table", parentId: o, contentIds: c, props: { columns: l } }, runs: s, subtreeBlocks: a };
2965
+ };
2966
+ }
2967
+ function Vl(e, t) {
2968
+ return `<td>${e.contentIds.map((o) => t.store.getRun(o)).map((o) => Ne(o, t)).join("")}</td>`;
2969
+ }
2970
+ function Gl(e, t) {
2971
+ return e.contentIds.map((n) => Re(t.store.getRun(n), t)).join("");
2972
+ }
2973
+ function Wl(e, t) {
2974
+ return xe(
2975
+ e.contentIds.map((o) => t.store.getRun(o)),
2976
+ t
2977
+ ).replace(/\|/g, "\\|").replace(/\r?\n/g, "<br>");
2978
+ }
2979
+ function ql(e, t) {
2980
+ if (e.tagName !== "TD" && e.tagName !== "TH") return null;
2981
+ const n = Be(e, t);
2982
+ return { block: {
2983
+ id: C(),
2984
+ type: "tableCell",
2985
+ parentId: null,
2986
+ contentIds: n.map((r) => r.id),
2987
+ props: {}
2988
+ }, runs: n };
2989
+ }
2990
+ function Yl(e, t) {
2991
+ return `<tr>${e.contentIds.map((o) => {
2992
+ const r = t.store.getBlock(o);
2993
+ return t.registry.get(r.type).toHTML(r, t);
2994
+ }).join("")}</tr>`;
2995
+ }
2996
+ function Xl(e, t) {
2997
+ return e.contentIds.map((n) => {
2998
+ const o = t.store.getBlock(n);
2999
+ return t.registry.get(o.type).toPlainText(o, t);
3000
+ }).join(" ");
3001
+ }
3002
+ function Ql(e, t) {
3003
+ return `| ${e.contentIds.map((o) => {
3004
+ const r = t.store.getBlock(o);
3005
+ return t.registry.get(r.type).toMarkdown(r, t);
3006
+ }).join(" | ")} |`;
3007
+ }
3008
+ function Jl(e, t) {
3009
+ if (e.tagName !== "TR") return null;
3010
+ const n = [...e.children].filter((c) => c.tagName === "TD" || c.tagName === "TH"), o = C(), r = [], l = [], a = [];
3011
+ for (const c of n) {
3012
+ const u = t.registry.get("tableCell").fromHTML(c, t);
3013
+ u && (u.block.parentId = o, r.push(u.block), l.push(...u.runs), a.push(u.block.id));
3014
+ }
3015
+ return { block: { id: o, type: "tableRow", parentId: null, contentIds: a, props: {} }, runs: l, subtreeBlocks: r };
3016
+ }
3017
+ function Zl(e, t) {
3018
+ var a;
3019
+ const n = e.contentIds[0] && t.store.getBlock(e.contentIds[0]), o = pe(e, ((a = n == null ? void 0 : n.contentIds) == null ? void 0 : a.length) ?? 0), r = o.length ? `<thead><tr>${o.map((s) => `<th>${gt(s.label ?? "")}</th>`).join("")}</tr></thead>` : "", l = e.contentIds.map((s) => {
3020
+ const c = t.store.getBlock(s);
3021
+ return t.registry.get(c.type).toHTML(c, t);
3022
+ }).join("");
3023
+ return `<table>${r}<tbody>${l}</tbody></table>`;
3024
+ }
3025
+ function ea(e, t) {
3026
+ return e.contentIds.map((n) => {
3027
+ const o = t.store.getBlock(n);
3028
+ return t.registry.get(o.type).toPlainText(o, t);
3029
+ }).join(`
3030
+ `);
3031
+ }
3032
+ function ta(e, t) {
3033
+ var s;
3034
+ const n = e.contentIds[0] && t.store.getBlock(e.contentIds[0]), o = pe(e, ((s = n == null ? void 0 : n.contentIds) == null ? void 0 : s.length) ?? 0);
3035
+ if (o.length === 0) return "";
3036
+ const r = `| ${o.map((c) => (c.label ?? "").replace(/\|/g, "\\|")).join(" | ")} |`, l = `| ${o.map(() => "---").join(" | ")} |`, a = e.contentIds.map((c) => {
3037
+ const u = t.store.getBlock(c);
3038
+ return t.registry.get(u.type).toMarkdown(u, t);
3039
+ }).join(`
3040
+ `);
3041
+ return a ? `${r}
3042
+ ${l}
3043
+ ${a}` : `${r}
3044
+ ${l}`;
3045
+ }
3046
+ function na(e, t) {
3047
+ if (e.tagName !== "TABLE") return null;
3048
+ const n = e.querySelector("thead tr"), o = e.querySelector("tbody") ? [...e.querySelectorAll("tbody tr")] : [...e.querySelectorAll("tr")].filter((p) => p !== n), r = C(), l = [], a = [], s = [];
3049
+ for (const p of o) {
3050
+ const i = t.registry.get("tableRow").fromHTML(p, t);
3051
+ if (i) {
3052
+ i.block.parentId = r;
3053
+ for (const f of i.subtreeBlocks) f.parentId = i.block.id;
3054
+ l.push(i.block, ...i.subtreeBlocks), a.push(...i.runs), s.push(i.block.id);
3055
+ }
3056
+ }
3057
+ const c = {};
3058
+ if (n) {
3059
+ const p = [...n.children].filter(
3060
+ (i) => i.tagName === "TH" || i.tagName === "TD"
3061
+ );
3062
+ c.columns = p.map((i) => ({ id: C(), label: i.textContent ?? "" }));
3063
+ }
3064
+ return { block: { id: r, type: "table", parentId: null, contentIds: s, props: c }, runs: a, subtreeBlocks: l };
3065
+ }
3066
+ const oa = ae({
3067
+ name: "tableCell",
3068
+ contentModel: "runs",
3069
+ component: Fl,
3070
+ defaultProps: {},
3071
+ toHTML: Vl,
3072
+ toPlainText: Gl,
3073
+ toMarkdown: Wl,
3074
+ fromHTML: ql
3075
+ }), ra = ae({
3076
+ name: "tableRow",
3077
+ contentModel: "blocks",
3078
+ component: _l,
3079
+ defaultProps: {},
3080
+ toHTML: Yl,
3081
+ toPlainText: Xl,
3082
+ toMarkdown: Ql,
3083
+ fromHTML: Jl
3084
+ }), la = ae({
3085
+ name: "table",
3086
+ contentModel: "blocks",
3087
+ component: Pl,
3088
+ defaultProps: {},
3089
+ toHTML: Zl,
3090
+ toPlainText: ea,
3091
+ toMarkdown: ta,
3092
+ fromHTML: na,
3093
+ slashCommand: {
3094
+ label: "Table",
3095
+ icon: yo,
3096
+ keywords: ["table", "grid"],
3097
+ run: (e, t) => re(e, t, Kl({ rows: 2, cols: 2 }))
3098
+ }
3099
+ });
3100
+ function aa({ id: e }) {
3101
+ const t = ee(e), n = se("be-layout", t);
3102
+ return /* @__PURE__ */ d("div", { className: n, "data-block-id": e, style: { display: "flex", gap: "1em" }, children: /* @__PURE__ */ d(He, { parentId: e }) });
3103
+ }
3104
+ function sa({ id: e }) {
3105
+ const t = ee(e), n = se("be-layout-column", t);
3106
+ return /* @__PURE__ */ d("div", { className: n, "data-block-id": e, children: /* @__PURE__ */ d(He, { parentId: e }) });
3107
+ }
3108
+ function ca({ columns: e = 2 } = {}) {
3109
+ return function(n) {
3110
+ const o = C(), r = [], l = [], a = [];
3111
+ for (let c = 0; c < e; c += 1) {
3112
+ const u = C(), { block: p, runs: i } = U("paragraph")(u), f = {
3113
+ id: u,
3114
+ type: "layoutColumn",
3115
+ parentId: o,
3116
+ contentIds: [p.id],
3117
+ props: {}
3118
+ };
3119
+ r.push(f, p), l.push(...i), a.push(u);
3120
+ }
3121
+ return { block: { id: o, type: "layout", parentId: n, contentIds: a, props: {} }, runs: l, subtreeBlocks: r };
3122
+ };
3123
+ }
3124
+ function Gn(e, t) {
3125
+ return (n, o) => `${e}${n.contentIds.map((r) => {
3126
+ const l = o.store.getBlock(r);
3127
+ return o.registry.get(l.type).toHTML(l, o);
3128
+ }).join("")}${t}`;
3129
+ }
3130
+ function Wn(e, t) {
3131
+ return e.contentIds.map((n) => {
3132
+ const o = t.store.getBlock(n);
3133
+ return t.registry.get(o.type).toPlainText(o, t);
3134
+ }).join(`
3135
+ `);
3136
+ }
3137
+ function qn(e, t) {
3138
+ return e.contentIds.map((n) => {
3139
+ const o = t.store.getBlock(n), r = t.registry.get(o.type);
3140
+ return (r.toMarkdown ?? r.toPlainText)(o, t);
3141
+ }).join(`
3142
+
3143
+ `);
3144
+ }
3145
+ const ia = ae({
3146
+ name: "layoutColumn",
3147
+ contentModel: "blocks",
3148
+ component: sa,
3149
+ defaultProps: {},
3150
+ toHTML: Gn("<div>", "</div>"),
3151
+ toPlainText: Wn,
3152
+ toMarkdown: qn
3153
+ // no fromHTML: a bare column has no distinct HTML representation of its
3154
+ // own outside a parent `layout`'s markup; layout.fromHTML would construct
3155
+ // both together if/when generic multi-column HTML import is added.
3156
+ }), ua = ae({
3157
+ name: "layout",
3158
+ contentModel: "blocks",
3159
+ component: aa,
3160
+ defaultProps: {},
3161
+ toHTML: Gn('<div style="display:flex;gap:1em">', "</div>"),
3162
+ toPlainText: Wn,
3163
+ toMarkdown: qn,
3164
+ slashCommands: [2, 3, 4, 5].map((e) => ({
3165
+ label: `${e} columns`,
3166
+ icon: ko,
3167
+ keywords: ["layout", "columns", "column", String(e)],
3168
+ run: (t, n) => re(t, n, ca({ columns: e }))
3169
+ }))
3170
+ });
3171
+ function da({ id: e }) {
3172
+ const t = ee(e), n = se("be-divider", t);
3173
+ return /* @__PURE__ */ d("hr", { className: n, "data-block-id": e, contentEditable: !1, tabIndex: -1 });
3174
+ }
3175
+ function pa() {
3176
+ return function(t) {
3177
+ return {
3178
+ block: { id: C(), type: "divider", parentId: t, contentIds: [], props: {} },
3179
+ runs: []
3180
+ };
3181
+ };
3182
+ }
3183
+ function fa() {
3184
+ return "<hr />";
3185
+ }
3186
+ function ma() {
3187
+ return "---";
3188
+ }
3189
+ function ha() {
3190
+ return "---";
3191
+ }
3192
+ function ga(e) {
3193
+ return e.tagName !== "HR" ? null : {
3194
+ block: { id: C(), type: "divider", parentId: null, contentIds: [], props: {} },
3195
+ runs: []
3196
+ };
3197
+ }
3198
+ const ba = ae({
3199
+ name: "divider",
3200
+ contentModel: "void",
3201
+ component: da,
3202
+ defaultProps: {},
3203
+ toHTML: fa,
3204
+ toPlainText: ma,
3205
+ toMarkdown: ha,
3206
+ fromHTML: ga,
3207
+ slashCommand: {
3208
+ label: "Divider",
3209
+ icon: vo,
3210
+ keywords: ["divider", "hr", "separator", "line"],
3211
+ run: (e, { blockId: t, runId: n, sliceStart: o, sliceEnd: r }) => {
3212
+ const l = e.getRun(n), a = (l == null ? void 0 : l.value) ?? "";
3213
+ e.applyOperation(
3214
+ ie(n, { value: a.slice(0, o) + a.slice(r) })
3215
+ );
3216
+ const s = xn(e, t, pa());
3217
+ return Ke(e, s, U("paragraph")), s;
3218
+ }
3219
+ }
3220
+ }), ya = [
3221
+ { value: "gray", label: "Gray" },
3222
+ { value: "blue", label: "Blue" },
3223
+ { value: "green", label: "Green" },
3224
+ { value: "yellow", label: "Yellow" },
3225
+ { value: "orange", label: "Orange" },
3226
+ { value: "red", label: "Red" },
3227
+ { value: "purple", label: "Purple" },
3228
+ { value: "pink", label: "Pink" }
3229
+ ];
3230
+ function ka({ id: e }) {
3231
+ var I, m;
3232
+ const t = V(), n = ee(e), [o, r] = O(!1), [l, a] = O(!1), s = _(null), c = _(null), u = je(() => [s, c], []), p = h(() => a(!1), []);
3233
+ at(u, l, p);
3234
+ const i = ((I = n == null ? void 0 : n.props) == null ? void 0 : I.icon) ?? De, f = ((m = n == null ? void 0 : n.props) == null ? void 0 : m.color) ?? Pn, b = h(
3235
+ (y) => {
3236
+ const B = y.target.value.trim();
3237
+ B && t.applyOperation(G(e, { icon: B })), r(!1);
3238
+ },
3239
+ [t, e]
3240
+ ), v = h((y) => {
3241
+ y.key === "Enter" && y.currentTarget.blur(), y.key === "Escape" && r(!1);
3242
+ }, []), g = h(
3243
+ (y) => {
3244
+ t.applyOperation(G(e, { color: y })), a(!1);
3245
+ },
3246
+ [t, e]
3247
+ ), k = se("be-callout", n);
3248
+ return n ? /* @__PURE__ */ T("div", { className: k, "data-block-id": e, "data-color": f, children: [
3249
+ /* @__PURE__ */ d("div", { className: "be-callout-icon-wrap", children: o ? /* @__PURE__ */ d(
3250
+ "input",
3251
+ {
3252
+ type: "text",
3253
+ className: "be-callout-icon-input",
3254
+ defaultValue: i,
3255
+ autoFocus: !0,
3256
+ onBlur: b,
3257
+ onKeyDown: v,
3258
+ "aria-label": "Callout icon (paste or type an emoji)"
3259
+ }
3260
+ ) : /* @__PURE__ */ d(
3261
+ "button",
3262
+ {
3263
+ type: "button",
3264
+ className: "be-callout-icon",
3265
+ onClick: () => r(!0),
3266
+ "aria-label": "Change callout icon",
3267
+ title: "Change icon",
3268
+ children: i
3269
+ }
3270
+ ) }),
3271
+ /* @__PURE__ */ d("div", { className: "be-callout-content", children: /* @__PURE__ */ d(He, { parentId: e }) }),
3272
+ /* @__PURE__ */ T("div", { className: "be-callout-color-wrap", contentEditable: !1, children: [
3273
+ /* @__PURE__ */ d(
3274
+ "button",
3275
+ {
3276
+ ref: s,
3277
+ type: "button",
3278
+ className: "be-callout-color-trigger",
3279
+ "aria-label": "Callout color",
3280
+ "aria-haspopup": "true",
3281
+ "aria-expanded": l,
3282
+ title: "Callout color",
3283
+ onClick: () => a((y) => !y),
3284
+ children: /* @__PURE__ */ d("span", { className: `be-callout-color-dot be-callout-color-dot-${f}` })
3285
+ }
3286
+ ),
3287
+ l && /* @__PURE__ */ d(
3288
+ "div",
3289
+ {
3290
+ ref: c,
3291
+ className: "be-callout-color-picker",
3292
+ role: "menu",
3293
+ "aria-label": "Callout color",
3294
+ children: ya.map((y) => /* @__PURE__ */ d(
3295
+ "button",
3296
+ {
3297
+ type: "button",
3298
+ role: "menuitem",
3299
+ className: `be-callout-color-option be-callout-color-option-${y.value}${y.value === f ? " be-callout-color-option-active" : ""}`,
3300
+ title: y.label,
3301
+ "aria-label": y.label,
3302
+ onClick: () => g(y.value)
3303
+ },
3304
+ y.value
3305
+ ))
3306
+ }
3307
+ )
3308
+ ] })
3309
+ ] }) : null;
3310
+ }
3311
+ function va(e, t) {
3312
+ return e.contentIds.map((n) => {
3313
+ const o = t.store.getBlock(n);
3314
+ return t.registry.get(o.type).toHTML(o, t);
3315
+ }).join("");
3316
+ }
3317
+ function Ia(e, t) {
3318
+ var o;
3319
+ const n = ((o = e.props) == null ? void 0 : o.icon) ?? De;
3320
+ return `<div class="callout" data-icon="${n}"><div class="callout-icon">${n}</div><div class="callout-content">${va(e, t)}</div></div>`;
3321
+ }
3322
+ function wa(e, t) {
3323
+ var r;
3324
+ const n = ((r = e.props) == null ? void 0 : r.icon) ?? De, o = e.contentIds.map((l) => {
3325
+ const a = t.store.getBlock(l);
3326
+ return t.registry.get(a.type).toPlainText(a, t);
3327
+ }).join(`
3328
+ `);
3329
+ return `${n} ${o}`;
3330
+ }
3331
+ function Ta(e, t) {
3332
+ var r;
3333
+ const n = ((r = e.props) == null ? void 0 : r.icon) ?? De;
3334
+ return e.contentIds.map((l) => {
3335
+ const a = t.store.getBlock(l), s = t.registry.get(a.type);
3336
+ return (s.toMarkdown ?? s.toPlainText)(a, t);
3337
+ }).join(`
3338
+ `).split(`
3339
+ `).map((l, a) => `> ${a === 0 ? `${n} ` : ""}${l}`).join(`
3340
+ `);
3341
+ }
3342
+ const Ca = ae({
3343
+ name: "callout",
3344
+ contentModel: "blocks",
3345
+ component: ka,
3346
+ defaultProps: { icon: De },
3347
+ toHTML: Ia,
3348
+ toPlainText: wa,
3349
+ toMarkdown: Ta,
3350
+ // No fromHTML: same precedent as layoutColumn — there's no standard
3351
+ // external HTML shape for a "callout" box, so plain-HTML paste doesn't
3352
+ // need to reconstruct one. Same-editor copy/paste is already lossless
3353
+ // via the generic block-subtree JSON clipboard path
3354
+ // (captureSubtree in clipboard/serialize.js), which walks
3355
+ // contentIds generically and needs no per-type awareness at all.
3356
+ slashCommand: {
3357
+ label: "Callout",
3358
+ icon: vn,
3359
+ keywords: ["callout", "aside", "note", "info", "tip", "warning"],
3360
+ run: (e, t) => re(e, t, Lr())
3361
+ }
3362
+ });
3363
+ function Ba({ id: e }) {
3364
+ const t = V(), n = ee(e), { setSelectedBlockId: o } = Se(), r = h(() => {
3365
+ Ve(
3366
+ t,
3367
+ e,
3368
+ (n == null ? void 0 : n.contentIds) ?? [],
3369
+ U("paragraph")
3370
+ );
3371
+ }, [t, e, n]), l = h(() => {
3372
+ const i = ct(t, e);
3373
+ Ge(t, i, e, o);
3374
+ }, [t, e, o]), a = h(() => le(t, e, "up"), [t, e]), s = h(() => le(t, e, "down"), [t, e]), c = se("be-blockquote", n);
3375
+ if (!n) return null;
3376
+ const u = me(t, n.contentIds), p = Ce(t, n);
3377
+ return /* @__PURE__ */ d(
3378
+ "blockquote",
3379
+ {
3380
+ className: c,
3381
+ "data-block-id": e,
3382
+ "data-empty": u ? "" : void 0,
3383
+ "data-placeholder": "Empty quote",
3384
+ dir: p,
3385
+ children: /* @__PURE__ */ d(
3386
+ Le,
3387
+ {
3388
+ blockId: e,
3389
+ runIds: n.contentIds,
3390
+ dir: p,
3391
+ onEnter: r,
3392
+ onBackspaceAtStart: l,
3393
+ onArrowUp: a,
3394
+ onArrowDown: s
3395
+ }
3396
+ )
3397
+ }
3398
+ );
3399
+ }
3400
+ function Ra(e, t) {
3401
+ return `<p>${e.contentIds.map((o) => t.store.getRun(o)).map((o) => Ne(o, t)).join("")}</p>`;
3402
+ }
3403
+ function Na(e, t) {
3404
+ return e.contentIds.map((n) => Re(t.store.getRun(n), t)).join("");
3405
+ }
3406
+ function La(e, t) {
3407
+ return `> ${xe(
3408
+ e.contentIds.map((o) => t.store.getRun(o)),
3409
+ t
3410
+ )}`;
3411
+ }
3412
+ function Aa(e, t) {
3413
+ if (e.tagName !== "BLOCKQUOTE") return null;
3414
+ const n = Be(e, t);
3415
+ return { block: {
3416
+ id: C(),
3417
+ type: "blockquote",
3418
+ parentId: null,
3419
+ contentIds: n.map((r) => r.id),
3420
+ props: {}
3421
+ }, runs: n };
3422
+ }
3423
+ const Ma = ae({
3424
+ name: "blockquote",
3425
+ contentModel: "runs",
3426
+ component: Ba,
3427
+ defaultProps: {},
3428
+ toHTML: Ra,
3429
+ toPlainText: Na,
3430
+ toMarkdown: La,
3431
+ fromHTML: Aa,
3432
+ slashCommand: {
3433
+ label: "Quote",
3434
+ icon: kn,
3435
+ keywords: ["quote", "blockquote", "citation"],
3436
+ run: (e, t) => re(e, t, U("blockquote"))
3437
+ }
3438
+ }), Ea = [
3439
+ "plaintext",
3440
+ "javascript",
3441
+ "python",
3442
+ "html",
3443
+ "css",
3444
+ "json",
3445
+ "bash",
3446
+ "sql"
3447
+ ], $a = Ea.map((e) => ({ value: e, label: e }));
3448
+ function ln(e, t, n) {
3449
+ const o = So();
3450
+ if (!o || o.blockId !== t) return;
3451
+ const r = e.getRun(o.runId);
3452
+ if (!r || r.type !== "text") return;
3453
+ const l = r.value ?? "", a = l.slice(0, o.offset) + n + l.slice(o.offset);
3454
+ e.applyOperation(ie(r.id, { value: a })), Do(r.id, o.offset + n.length);
3455
+ }
3456
+ function xa({ id: e }) {
3457
+ var g, k;
3458
+ const t = V(), n = ee(e), o = Io(), r = h(() => ln(t, e, `
3459
+ `), [t, e]), l = h(() => ln(t, e, " "), [t, e]), a = h(() => {
3460
+ var B;
3461
+ const I = ct(t, e);
3462
+ if (!I || I === e) return;
3463
+ const m = t.getBlock(I), y = (B = m == null ? void 0 : m.contentIds) == null ? void 0 : B[m.contentIds.length - 1];
3464
+ y && ve(y);
3465
+ }, [t, e]), s = h(() => le(t, e, "up"), [t, e]), c = h(() => le(t, e, "down"), [t, e]), u = h(
3466
+ (I) => t.applyOperation(G(e, { language: I })),
3467
+ [t, e]
3468
+ ), p = h(() => Un(t, e), [t, e]), i = se("be-code-block", n);
3469
+ if (!n) return null;
3470
+ const f = ((g = n.props) == null ? void 0 : g.language) ?? "plaintext", b = me(t, n.contentIds), v = o ? (((k = n.contentIds.map((I) => {
3471
+ var m;
3472
+ return ((m = t.getRun(I)) == null ? void 0 : m.value) ?? "";
3473
+ }).join("").match(/\n/g)) == null ? void 0 : k.length) ?? 0) + 1 : 0;
3474
+ return /* @__PURE__ */ T("div", { className: i, "data-block-id": e, children: [
3475
+ /* @__PURE__ */ T("div", { className: "be-code-block-header", contentEditable: !1, children: [
3476
+ /* @__PURE__ */ d(
3477
+ Fe,
3478
+ {
3479
+ className: "be-code-block-language",
3480
+ value: f,
3481
+ options: $a,
3482
+ onChange: u,
3483
+ ariaLabel: "Code language"
3484
+ }
3485
+ ),
3486
+ /* @__PURE__ */ d(
3487
+ "button",
3488
+ {
3489
+ type: "button",
3490
+ className: "be-code-block-delete",
3491
+ onClick: p,
3492
+ "aria-label": "Delete code block",
3493
+ title: "Delete code block",
3494
+ children: /* @__PURE__ */ d(Nn, { size: 14 })
3495
+ }
3496
+ )
3497
+ ] }),
3498
+ /* @__PURE__ */ T("div", { className: "be-code-block-body", children: [
3499
+ o && /* @__PURE__ */ d("div", { className: "be-code-block-gutter", contentEditable: !1, "aria-hidden": "true", children: Array.from({ length: v }, (I, m) => /* @__PURE__ */ d("span", { children: m + 1 }, m)) }),
3500
+ /* @__PURE__ */ d("pre", { className: "be-code-block-pre", dir: "ltr", children: /* @__PURE__ */ d("code", { "data-empty": b ? "" : void 0, "data-placeholder": "Empty code block", children: /* @__PURE__ */ d(
3501
+ Le,
3502
+ {
3503
+ blockId: e,
3504
+ runIds: n.contentIds,
3505
+ dir: "ltr",
3506
+ onEnter: r,
3507
+ onTab: l,
3508
+ onBackspaceAtStart: a,
3509
+ onArrowUp: s,
3510
+ onArrowDown: c
3511
+ }
3512
+ ) }) })
3513
+ ] })
3514
+ ] });
3515
+ }
3516
+ function Oa(e, t) {
3517
+ var l;
3518
+ const n = e.contentIds.map((a) => t.store.getRun(a)), o = (l = e.props) == null ? void 0 : l.language;
3519
+ return `<pre><code${o && o !== "plaintext" ? ` data-language="${gt(o)}"` : ""}>${n.map((a) => Ne(a, t)).join("")}</code></pre>`;
3520
+ }
3521
+ function Sa(e, t) {
3522
+ return e.contentIds.map((n) => Re(t.store.getRun(n), t)).join("");
3523
+ }
3524
+ function Da(e, t) {
3525
+ var l;
3526
+ const n = (l = e.props) == null ? void 0 : l.language, o = n && n !== "plaintext" ? n : "", r = e.contentIds.map((a) => {
3527
+ var s;
3528
+ return ((s = t.store.getRun(a)) == null ? void 0 : s.value) ?? "";
3529
+ }).join("");
3530
+ return `\`\`\`${o}
3531
+ ${r}
3532
+ \`\`\``;
3533
+ }
3534
+ function Ha(e, t) {
3535
+ var a;
3536
+ if (e.tagName !== "PRE") return null;
3537
+ const n = e.querySelector("code") ?? e, o = (a = n.getAttribute) == null ? void 0 : a.call(n, "data-language"), r = C();
3538
+ return { block: {
3539
+ id: C(),
3540
+ type: "code",
3541
+ parentId: null,
3542
+ contentIds: [r],
3543
+ props: o ? { language: o } : {}
3544
+ }, runs: [{ id: r, type: "text", value: n.textContent ?? "", marks: {} }] };
3545
+ }
3546
+ const Pa = ae({
3547
+ name: "code",
3548
+ contentModel: "runs",
3549
+ component: xa,
3550
+ defaultProps: { language: "plaintext" },
3551
+ toHTML: Oa,
3552
+ toPlainText: Sa,
3553
+ toMarkdown: Da,
3554
+ fromHTML: Ha,
3555
+ slashCommand: {
3556
+ label: "Code",
3557
+ icon: In,
3558
+ keywords: ["code", "codeblock", "snippet", "pre"],
3559
+ run: (e, t) => re(e, t, U("code"))
3560
+ }
3561
+ });
3562
+ function _a(e, t) {
3563
+ var n;
3564
+ return t.length === 0 || t.length === 1 && (((n = e.getRun(t[0])) == null ? void 0 : n.value) ?? "") === "";
3565
+ }
3566
+ function Ua(e, t) {
3567
+ const n = t.contentIds ?? [];
3568
+ if (n.length === 0) return !0;
3569
+ if (n.length > 1) return !1;
3570
+ const o = e.getBlock(n[0]);
3571
+ return !!o && o.type === "paragraph" && me(e, o.contentIds);
3572
+ }
3573
+ function ft(e, t) {
3574
+ if (typeof e.performBatch == "function") e.performBatch(t);
3575
+ else for (const n of t) e.applyOperation(n);
3576
+ }
3577
+ function ja(e, t) {
3578
+ const n = e.getBlock(t);
3579
+ if (!n) return null;
3580
+ const o = e.getBlock(n.parentId), r = o.contentIds.indexOf(t), l = n.props.titleRunIds ?? [], a = _a(e, l) && Ua(e, n);
3581
+ if (r <= 0) {
3582
+ if (!a) return null;
3583
+ if (o.contentIds.length > 1)
3584
+ return ft(e, [q(t)]), { focusBlockId: e.getBlock(o.id).contentIds[0], needsRefocus: !0 };
3585
+ const { block: u, runs: p } = U("paragraph")(o.id);
3586
+ return ft(e, [
3587
+ ke(u, o.id, r, { blocks: [u], runs: p }),
3588
+ q(t)
3589
+ ]), { focusBlockId: u.id, needsRefocus: !0 };
3590
+ }
3591
+ const s = o.contentIds[r - 1], c = e.getBlock(s);
3592
+ return a ? (ft(e, [q(t)]), { focusBlockId: s, needsRefocus: !0 }) : kt(e, c) ? (ft(e, [q(s)]), { focusBlockId: t, needsRefocus: !1 }) : null;
3593
+ }
3594
+ function Fa(e, t) {
3595
+ if (typeof e.performBatch == "function") e.performBatch(t);
3596
+ else for (const n of t) e.applyOperation(n);
3597
+ }
3598
+ function za({ id: e }) {
3599
+ var k;
3600
+ const t = V(), n = ee(e), { setSelectedBlockId: o } = Se(), r = h(() => {
3601
+ var B, L;
3602
+ const I = ((B = n == null ? void 0 : n.props) == null ? void 0 : B.titleRunIds) ?? [], m = (((L = n == null ? void 0 : n.contentIds) == null ? void 0 : L.length) ?? 0) > 0, y = U("paragraph");
3603
+ m ? $n(t, e, I, y) : Ve(t, e, I, y);
3604
+ }, [t, e, n]), l = h(() => {
3605
+ const I = ja(t, e);
3606
+ !I || !I.needsRefocus || Ge(t, I.focusBlockId, e, o);
3607
+ }, [t, e, o]), a = h(() => le(t, e, "up"), [t, e]), s = h(() => le(t, e, "down"), [t, e]), c = h(() => {
3608
+ var m, y;
3609
+ if (!((((m = n == null ? void 0 : n.contentIds) == null ? void 0 : m.length) ?? 0) > 0)) {
3610
+ const { block: B, runs: L } = U("paragraph")(e);
3611
+ Fa(t, [
3612
+ ke(B, e, 0, { blocks: [B], runs: L }),
3613
+ G(e, { collapsed: !1 })
3614
+ ]), ve(B.contentIds[0]);
3615
+ return;
3616
+ }
3617
+ t.applyOperation(G(e, { collapsed: !((y = n == null ? void 0 : n.props) != null && y.collapsed) }));
3618
+ }, [t, e, n == null ? void 0 : n.contentIds, (k = n == null ? void 0 : n.props) == null ? void 0 : k.collapsed]), u = se("be-toggle-heading", n);
3619
+ if (!n) return null;
3620
+ const { level: p = 2, collapsed: i, titleRunIds: f = [] } = n.props, b = n.contentIds.length > 0, v = `h${p}`, g = Ce(t, n);
3621
+ return /* @__PURE__ */ T("div", { className: u, "data-block-id": e, dir: g, children: [
3622
+ /* @__PURE__ */ T("div", { className: "be-toggle-heading-row", children: [
3623
+ /* @__PURE__ */ d(
3624
+ "button",
3625
+ {
3626
+ type: "button",
3627
+ className: "be-toggle-heading-marker",
3628
+ onClick: c,
3629
+ "aria-expanded": !i,
3630
+ "aria-label": b ? i ? "Expand section" : "Collapse section" : "Add content to section",
3631
+ children: i ? /* @__PURE__ */ d(Ee, {}) : /* @__PURE__ */ d(Dt, {})
3632
+ }
3633
+ ),
3634
+ /* @__PURE__ */ d(
3635
+ v,
3636
+ {
3637
+ className: `be-heading be-heading-${p} be-toggle-heading-title`,
3638
+ "data-empty": me(t, f) ? "" : void 0,
3639
+ "data-placeholder": `Toggle heading ${p}`,
3640
+ children: /* @__PURE__ */ d(
3641
+ Le,
3642
+ {
3643
+ blockId: e,
3644
+ runIds: f,
3645
+ dir: g,
3646
+ onEnter: r,
3647
+ onBackspaceAtStart: l,
3648
+ onArrowUp: a,
3649
+ onArrowDown: s
3650
+ }
3651
+ )
3652
+ }
3653
+ )
3654
+ ] }),
3655
+ !i && /* @__PURE__ */ d("div", { className: "be-toggle-heading-children", children: /* @__PURE__ */ d(He, { parentId: e }) })
3656
+ ] });
3657
+ }
3658
+ function Ka({ level: e = 2, collapsed: t = !1 } = {}) {
3659
+ return function(o, r) {
3660
+ const l = C(), a = r != null && r.length ? r : [{ id: C(), type: "text", value: "", marks: {} }], { block: s, runs: c } = U("paragraph")(l);
3661
+ return {
3662
+ block: {
3663
+ id: l,
3664
+ type: "toggleHeading",
3665
+ parentId: o,
3666
+ contentIds: [s.id],
3667
+ props: { level: e, collapsed: t, titleRunIds: a.map((u) => u.id) }
3668
+ },
3669
+ runs: [...a, ...c],
3670
+ subtreeBlocks: [s]
3671
+ };
3672
+ };
3673
+ }
3674
+ function Va(e, t) {
3675
+ const { titleRunIds: n = [], level: o = 2, collapsed: r } = e.props, l = n.map((s) => Ne(t.store.getRun(s), t)).join(""), a = e.contentIds.map((s) => {
3676
+ const c = t.store.getBlock(s);
3677
+ return t.registry.get(c.type).toHTML(c, t);
3678
+ }).join("");
3679
+ return `<details${r ? "" : " open"}><summary><h${o}>${l}</h${o}></summary>${a}</details>`;
3680
+ }
3681
+ function Ga(e, t) {
3682
+ const { titleRunIds: n = [] } = e.props, o = n.map((l) => Re(t.store.getRun(l), t)).join(""), r = e.contentIds.map((l) => {
3683
+ const a = t.store.getBlock(l);
3684
+ return t.registry.get(a.type).toPlainText(a, t);
3685
+ }).join(`
3686
+ `);
3687
+ return r ? `${o}
3688
+ ${r}` : o;
3689
+ }
3690
+ function Wa(e, t) {
3691
+ const { titleRunIds: n = [], level: o = 2 } = e.props, r = xe(
3692
+ n.map((s) => t.store.getRun(s)),
3693
+ t
3694
+ ), l = `${"#".repeat(Math.min(6, o))} ${r}`, a = e.contentIds.map((s) => {
3695
+ const c = t.store.getBlock(s), u = t.registry.get(c.type);
3696
+ return (u.toMarkdown ?? u.toPlainText)(c, t);
3697
+ }).join(`
3698
+
3699
+ `);
3700
+ return a ? `${l}
3701
+
3702
+ ${a}` : l;
3703
+ }
3704
+ function qa(e, t) {
3705
+ if (e.tagName !== "DETAILS") return null;
3706
+ const n = [...e.children].find((i) => i.tagName === "SUMMARY"), o = n == null ? void 0 : n.querySelector("h1,h2,h3,h4,h5,h6"), r = o ? Math.min(6, Math.max(1, Number(o.tagName[1]))) : 2, l = o ? Be(o, t) : [{ id: C(), type: "text", value: "", marks: {} }], a = C(), s = [], c = [], u = [];
3707
+ for (const i of e.children) {
3708
+ if (i === n || i.tagName !== "P") continue;
3709
+ const f = Be(i, t), b = {
3710
+ id: C(),
3711
+ type: "paragraph",
3712
+ parentId: a,
3713
+ contentIds: f.map((v) => v.id),
3714
+ props: {}
3715
+ };
3716
+ s.push(b), c.push(...f), u.push(b.id);
3717
+ }
3718
+ if (u.length === 0) {
3719
+ const { block: i, runs: f } = U("paragraph")(a);
3720
+ s.push(i), c.push(...f), u.push(i.id);
3721
+ }
3722
+ return { block: {
3723
+ id: a,
3724
+ type: "toggleHeading",
3725
+ parentId: null,
3726
+ contentIds: u,
3727
+ props: {
3728
+ level: r,
3729
+ collapsed: !e.hasAttribute("open"),
3730
+ titleRunIds: l.map((i) => i.id)
3731
+ }
3732
+ }, runs: [...l, ...c], subtreeBlocks: s };
3733
+ }
3734
+ const Ya = ae({
3735
+ name: "toggleHeading",
3736
+ contentModel: "blocks",
3737
+ component: za,
3738
+ defaultProps: { level: 2, collapsed: !1, titleRunIds: [] },
3739
+ toHTML: Va,
3740
+ toPlainText: Ga,
3741
+ toMarkdown: Wa,
3742
+ fromHTML: qa,
3743
+ slashCommands: [1, 2, 3].map((e) => ({
3744
+ label: `Toggle heading ${e}`,
3745
+ icon: Ee,
3746
+ // Deliberately does NOT include "h1"/"h2"/"h3" — those short forms
3747
+ // already belong exclusively to the plain heading commands (see
3748
+ // heading/index.js); duplicating them here would make "/h3" ambiguous
3749
+ // between "Heading 3" and "Toggle heading 3".
3750
+ keywords: ["toggle", "heading", "collapse", "section"],
3751
+ run: (t, n) => re(t, n, Ka({ level: e }))
3752
+ }))
3753
+ }), Bt = [
3754
+ { label: "Blue", value: "#2b6fd6" },
3755
+ { label: "Green", value: "#2f9e44" },
3756
+ { label: "Red", value: "#e03131" },
3757
+ { label: "Purple", value: "#9c36b5" },
3758
+ { label: "Gray", value: "#495057" },
3759
+ { label: "Black", value: "#1a1a1a" }
3760
+ ];
3761
+ function Xa(e, t) {
3762
+ if (typeof e.performBatch == "function") e.performBatch(t);
3763
+ else for (const n of t) e.applyOperation(n);
3764
+ }
3765
+ function Qa({ isOpen: e, onClose: t, store: n, blockId: o }) {
3766
+ const [r, l] = O(""), [a, s] = O(""), [c, u] = O(Bt[0].value), [p, i] = O([{ key: "", value: "" }]);
3767
+ oe(() => {
3768
+ var m, y, B;
3769
+ if (!e) return;
3770
+ const g = n.getBlock(o);
3771
+ if (!g) return;
3772
+ const k = g.contentIds.map((L) => {
3773
+ var D;
3774
+ return ((D = n.getRun(L)) == null ? void 0 : D.value) ?? "";
3775
+ }).join(""), I = ((m = g.props) == null ? void 0 : m.customAttrs) ?? [];
3776
+ l(k), s(((y = g.props) == null ? void 0 : y.href) ?? ""), u(((B = g.props) == null ? void 0 : B.color) ?? Bt[0].value), i([...I, { key: "", value: "" }]);
3777
+ }, [e, o, n]);
3778
+ const f = h((g, k) => {
3779
+ i((I) => {
3780
+ const m = I.map((B, L) => L === g ? { ...B, ...k } : B), y = m[m.length - 1];
3781
+ return (y.key.trim() || y.value.trim()) && m.push({ key: "", value: "" }), m;
3782
+ });
3783
+ }, []), b = h((g) => {
3784
+ i((k) => k.filter((I, m) => m !== g));
3785
+ }, []), v = h(() => {
3786
+ const g = { id: C(), type: "text", value: r, marks: {} }, k = p.filter((I) => I.key.trim());
3787
+ Xa(n, [
3788
+ Ue(o, [g]),
3789
+ G(o, { href: a.trim(), color: c, customAttrs: k })
3790
+ ]), t();
3791
+ }, [n, o, r, a, c, p, t]);
3792
+ return /* @__PURE__ */ T(Ht, { isOpen: e, onClose: t, title: "Edit button", children: [
3793
+ /* @__PURE__ */ T("label", { className: "be-modal-field", children: [
3794
+ /* @__PURE__ */ d("span", { children: "Label" }),
3795
+ /* @__PURE__ */ d(
3796
+ "input",
3797
+ {
3798
+ type: "text",
3799
+ value: r,
3800
+ onChange: (g) => l(g.target.value),
3801
+ placeholder: "Button"
3802
+ }
3803
+ )
3804
+ ] }),
3805
+ /* @__PURE__ */ T("label", { className: "be-modal-field", children: [
3806
+ /* @__PURE__ */ d("span", { children: "Link URL" }),
3807
+ /* @__PURE__ */ d(
3808
+ "input",
3809
+ {
3810
+ type: "url",
3811
+ value: a,
3812
+ onChange: (g) => s(g.target.value),
3813
+ placeholder: "https://example.com"
3814
+ }
3815
+ )
3816
+ ] }),
3817
+ /* @__PURE__ */ T("div", { className: "be-modal-field", children: [
3818
+ /* @__PURE__ */ d("span", { children: "Color" }),
3819
+ /* @__PURE__ */ d("div", { className: "be-modal-color-row", children: Bt.map((g) => /* @__PURE__ */ d(
3820
+ "button",
3821
+ {
3822
+ type: "button",
3823
+ className: `be-modal-color-swatch${c === g.value ? " be-modal-color-swatch-active" : ""}`,
3824
+ style: { backgroundColor: g.value },
3825
+ title: g.label,
3826
+ "aria-label": g.label,
3827
+ onClick: () => u(g.value)
3828
+ },
3829
+ g.value
3830
+ )) })
3831
+ ] }),
3832
+ /* @__PURE__ */ T("div", { className: "be-modal-field", children: [
3833
+ /* @__PURE__ */ d("span", { children: "Custom attributes" }),
3834
+ p.map((g, k) => /* @__PURE__ */ T("div", { className: "be-modal-attr-row", children: [
3835
+ /* @__PURE__ */ d(
3836
+ "input",
3837
+ {
3838
+ type: "text",
3839
+ placeholder: "name",
3840
+ value: g.key,
3841
+ onChange: (I) => f(k, { key: I.target.value })
3842
+ }
3843
+ ),
3844
+ /* @__PURE__ */ d(
3845
+ "input",
3846
+ {
3847
+ type: "text",
3848
+ placeholder: "value",
3849
+ value: g.value,
3850
+ onChange: (I) => f(k, { value: I.target.value })
3851
+ }
3852
+ ),
3853
+ (g.key || g.value) && /* @__PURE__ */ d(
3854
+ "button",
3855
+ {
3856
+ type: "button",
3857
+ className: "be-modal-attr-remove",
3858
+ onClick: () => b(k),
3859
+ "aria-label": "Remove attribute",
3860
+ children: /* @__PURE__ */ d(st, { size: 14 })
3861
+ }
3862
+ )
3863
+ ] }, k))
3864
+ ] }),
3865
+ /* @__PURE__ */ T("div", { className: "be-modal-actions", children: [
3866
+ /* @__PURE__ */ d("button", { type: "button", className: "be-modal-cancel", onClick: t, children: "Cancel" }),
3867
+ /* @__PURE__ */ d("button", { type: "button", className: "be-modal-save", onClick: v, children: "Save" })
3868
+ ] })
3869
+ ] });
3870
+ }
3871
+ const Ja = "#2b6fd6";
3872
+ function Za({ id: e }) {
3873
+ var m, y, B, L;
3874
+ const t = V(), n = ee(e), { setSelectedBlockId: o } = Se(), [r, l] = O(!1), a = h(() => {
3875
+ Ve(
3876
+ t,
3877
+ e,
3878
+ (n == null ? void 0 : n.contentIds) ?? [],
3879
+ U("paragraph")
3880
+ );
3881
+ }, [t, e, n]), s = h(() => {
3882
+ const D = ct(t, e);
3883
+ Ge(t, D, e, o);
3884
+ }, [t, e, o]), c = h(() => le(t, e, "up"), [t, e]), u = h(() => le(t, e, "down"), [t, e]), p = h(() => {
3885
+ var S;
3886
+ const D = (S = n == null ? void 0 : n.props) == null ? void 0 : S.href;
3887
+ D && window.open(D, "_blank", "noopener,noreferrer");
3888
+ }, [(m = n == null ? void 0 : n.props) == null ? void 0 : m.href]), i = se("be-button-block", n);
3889
+ if (!n) return null;
3890
+ const f = ((y = n.props) == null ? void 0 : y.href) ?? "", b = ((B = n.props) == null ? void 0 : B.color) ?? Ja, v = ((L = n.props) == null ? void 0 : L.customAttrs) ?? [], g = me(t, n.contentIds), k = {};
3891
+ for (const { key: D, value: S } of v)
3892
+ D.trim() && (k[`data-${D.trim()}`] = S);
3893
+ const I = Ce(t, n);
3894
+ return /* @__PURE__ */ T("div", { className: i, "data-block-id": e, dir: I, children: [
3895
+ /* @__PURE__ */ T("div", { className: "be-button-block-pill", style: { backgroundColor: b }, ...k, children: [
3896
+ /* @__PURE__ */ d(
3897
+ "span",
3898
+ {
3899
+ className: "be-button-block-label",
3900
+ "data-empty": g ? "" : void 0,
3901
+ "data-placeholder": "Button",
3902
+ children: /* @__PURE__ */ d(
3903
+ Le,
3904
+ {
3905
+ blockId: e,
3906
+ runIds: n.contentIds,
3907
+ dir: I,
3908
+ onEnter: a,
3909
+ onBackspaceAtStart: s,
3910
+ onArrowUp: c,
3911
+ onArrowDown: u
3912
+ }
3913
+ )
3914
+ }
3915
+ ),
3916
+ /* @__PURE__ */ d(
3917
+ "button",
3918
+ {
3919
+ type: "button",
3920
+ className: "be-button-block-open",
3921
+ onClick: p,
3922
+ disabled: !f,
3923
+ title: f || "No link set",
3924
+ "aria-label": "Open link",
3925
+ children: "↗"
3926
+ }
3927
+ ),
3928
+ /* @__PURE__ */ d(
3929
+ "button",
3930
+ {
3931
+ type: "button",
3932
+ className: "be-button-block-settings",
3933
+ onClick: () => l(!0),
3934
+ "aria-label": "Edit button",
3935
+ title: "Edit label, link, color…",
3936
+ children: "⚙"
3937
+ }
3938
+ )
3939
+ ] }),
3940
+ /* @__PURE__ */ d(
3941
+ Qa,
3942
+ {
3943
+ isOpen: r,
3944
+ onClose: () => l(!1),
3945
+ store: t,
3946
+ blockId: e
3947
+ }
3948
+ )
3949
+ ] });
3950
+ }
3951
+ function es({
3952
+ href: e = "",
3953
+ label: t = "Button",
3954
+ color: n = "",
3955
+ customAttrs: o = []
3956
+ } = {}) {
3957
+ return function(l, a) {
3958
+ const s = C(), c = a != null && a.length ? a : [{ id: C(), type: "text", value: t, marks: {} }];
3959
+ return {
3960
+ block: {
3961
+ id: s,
3962
+ type: "button",
3963
+ parentId: l,
3964
+ contentIds: c.map((u) => u.id),
3965
+ props: { href: e, color: n, customAttrs: o }
3966
+ },
3967
+ runs: c
3968
+ };
3969
+ };
3970
+ }
3971
+ const Yn = "be-button-block-link";
3972
+ function ts(e, t) {
3973
+ var c, u, p;
3974
+ const n = e.contentIds.map((i) => t.store.getRun(i)), o = ((c = e.props) == null ? void 0 : c.href) ?? "", r = (u = e.props) == null ? void 0 : u.color, l = r ? ` style="background-color:${fe(r)}"` : "", s = (((p = e.props) == null ? void 0 : p.customAttrs) ?? []).filter((i) => {
3975
+ var f;
3976
+ return (f = i.key) == null ? void 0 : f.trim();
3977
+ }).map((i) => ` data-${fe(i.key.trim())}="${fe(i.value ?? "")}"`).join("");
3978
+ return `<a class="${Yn}" href="${fe(o)}"${l}${s}>${n.map((i) => Ne(i, t)).join("")}</a>`;
3979
+ }
3980
+ function ns(e, t) {
3981
+ return e.contentIds.map((n) => Re(t.store.getRun(n), t)).join("");
3982
+ }
3983
+ function os(e, t) {
3984
+ var r;
3985
+ const n = ((r = e.props) == null ? void 0 : r.href) ?? "";
3986
+ return `[${xe(
3987
+ e.contentIds.map((l) => t.store.getRun(l)),
3988
+ t
3989
+ ) || n}](${n})`;
3990
+ }
3991
+ function rs(e, t) {
3992
+ var l;
3993
+ if (e.tagName !== "A" || !e.classList.contains(Yn)) return null;
3994
+ const n = Be(e, t), o = [];
3995
+ for (const a of e.attributes)
3996
+ a.name.startsWith("data-") && o.push({ key: a.name.slice(5), value: a.value });
3997
+ return { block: {
3998
+ id: C(),
3999
+ type: "button",
4000
+ parentId: null,
4001
+ contentIds: n.map((a) => a.id),
4002
+ props: {
4003
+ href: e.getAttribute("href") ?? "",
4004
+ color: ((l = e.style) == null ? void 0 : l.backgroundColor) || void 0,
4005
+ customAttrs: o
4006
+ }
4007
+ }, runs: n };
4008
+ }
4009
+ const ls = ae({
4010
+ name: "button",
4011
+ contentModel: "runs",
4012
+ component: Za,
4013
+ defaultProps: { href: "", color: "", customAttrs: [] },
4014
+ toHTML: ts,
4015
+ toPlainText: ns,
4016
+ toMarkdown: os,
4017
+ fromHTML: rs,
4018
+ slashCommand: {
4019
+ label: "Button",
4020
+ icon: wo,
4021
+ keywords: ["button", "link", "cta", "action"],
4022
+ run: (e, t) => re(e, t, es())
4023
+ }
4024
+ });
4025
+ function as(e) {
4026
+ return new Promise((t, n) => {
4027
+ const o = new FileReader();
4028
+ o.onload = () => t(o.result), o.onerror = () => n(o.error), o.readAsDataURL(e);
4029
+ });
4030
+ }
4031
+ function an(e) {
4032
+ return e < 1024 ? `${e} B` : e < 1024 * 1024 ? `${Math.round(e / 1024)} KB` : `${(e / (1024 * 1024)).toFixed(1)} MB`;
4033
+ }
4034
+ function ss(e) {
4035
+ return e != null && e.startsWith("image/") ? "image" : e != null && e.startsWith("video/") ? "video" : e != null && e.startsWith("audio/") ? "audio" : "file";
4036
+ }
4037
+ async function Xn(e, { uploadFile: t, maxFileSize: n, kind: o }) {
4038
+ if (t) {
4039
+ const l = await t(e, { kind: o });
4040
+ return {
4041
+ src: l.src,
4042
+ name: l.name ?? e.name,
4043
+ mimeType: l.mimeType ?? e.type
4044
+ };
4045
+ }
4046
+ if (n && e.size > n)
4047
+ throw new Error(
4048
+ `This file is ${an(e.size)} — larger than the ${an(n)} limit.`
4049
+ );
4050
+ return { src: await as(e), name: e.name, mimeType: e.type };
4051
+ }
4052
+ async function sc(e, t) {
4053
+ const n = ss(e.type), { src: o, name: r, mimeType: l } = await Xn(e, { ...t, kind: n });
4054
+ return {
4055
+ block: {
4056
+ id: C(),
4057
+ type: "embed",
4058
+ parentId: null,
4059
+ contentIds: [],
4060
+ props: { kind: n, src: o, name: r, mimeType: l, align: "left", width: 100 }
4061
+ },
4062
+ runs: [],
4063
+ subtreeBlocks: []
4064
+ };
4065
+ }
4066
+ const cs = [
4067
+ {
4068
+ name: "youtube",
4069
+ test: /(?:youtube\.com\/watch\?(?:.*&)?v=|youtu\.be\/|youtube\.com\/shorts\/|youtube\.com\/embed\/)([\w-]{6,})/,
4070
+ embed: (e) => `https://www.youtube.com/embed/${e[1]}`
4071
+ },
4072
+ {
4073
+ name: "vimeo",
4074
+ test: /vimeo\.com\/(?:video\/)?(\d+)/,
4075
+ embed: (e) => `https://player.vimeo.com/video/${e[1]}`
4076
+ },
4077
+ {
4078
+ name: "loom",
4079
+ test: /loom\.com\/share\/([\w-]+)/,
4080
+ embed: (e) => `https://www.loom.com/embed/${e[1]}`
4081
+ },
4082
+ {
4083
+ name: "figma",
4084
+ test: /figma\.com\/(?:file|design|proto)\/[\w-]+/,
4085
+ embed: (e, t) => `https://www.figma.com/embed?embed_host=noteloom&url=${encodeURIComponent(t)}`
4086
+ },
4087
+ {
4088
+ name: "codepen",
4089
+ test: /codepen\.io\/([\w-]+)\/pen\/([\w-]+)/,
4090
+ embed: (e) => `https://codepen.io/${e[1]}/embed/${e[2]}?default-tab=result`
4091
+ },
4092
+ {
4093
+ name: "spotify",
4094
+ test: /open\.spotify\.com\/(track|album|playlist|episode|show)\/([\w]+)/,
4095
+ embed: (e) => `https://open.spotify.com/embed/${e[1]}/${e[2]}`
4096
+ }
4097
+ ];
4098
+ function is(e) {
4099
+ if (!e) return null;
4100
+ for (const t of cs) {
4101
+ const n = e.match(t.test);
4102
+ if (n) return { provider: t.name, embedUrl: t.embed(n, e) };
4103
+ }
4104
+ return null;
4105
+ }
4106
+ const mt = {
4107
+ image: "image",
4108
+ video: "video",
4109
+ audio: "audio",
4110
+ file: "file",
4111
+ oembed: "embed"
4112
+ }, us = { image: "image/*", video: "video/*", audio: "audio/*", file: "*/*" }, Et = 20, $t = 100, ds = [
4113
+ { value: "left", Icon: Bn, label: "Align left" },
4114
+ { value: "center", Icon: Co, label: "Align center" },
4115
+ { value: "right", Icon: Rn, label: "Align right" }
4116
+ ];
4117
+ function Rt(e) {
4118
+ return Math.min($t, Math.max(Et, Math.round(e)));
4119
+ }
4120
+ function ps({ kind: e, src: t, name: n, alt: o, provider: r }) {
4121
+ return e === "image" ? /* @__PURE__ */ d("img", { className: "be-embed-image", src: t, alt: o || "" }) : e === "video" ? /* @__PURE__ */ d("video", { className: "be-embed-video", src: t, controls: !0 }) : e === "audio" ? /* @__PURE__ */ d("audio", { className: "be-embed-audio", src: t, controls: !0 }) : e === "oembed" ? /* @__PURE__ */ d(
4122
+ "iframe",
4123
+ {
4124
+ className: "be-embed-oembed",
4125
+ src: t,
4126
+ title: r ? `${r} embed` : "embed",
4127
+ sandbox: "allow-scripts allow-same-origin allow-presentation allow-popups",
4128
+ allow: "autoplay; encrypted-media; picture-in-picture; fullscreen",
4129
+ allowFullScreen: !0,
4130
+ loading: "lazy"
4131
+ }
4132
+ ) : /* @__PURE__ */ T(
4133
+ "a",
4134
+ {
4135
+ className: "be-embed-file-link",
4136
+ href: t,
4137
+ download: n || void 0,
4138
+ target: "_blank",
4139
+ rel: "noopener noreferrer",
4140
+ children: [
4141
+ /* @__PURE__ */ d(An, { size: 14 }),
4142
+ " ",
4143
+ n || t
4144
+ ]
4145
+ }
4146
+ );
4147
+ }
4148
+ function fs({ id: e }) {
4149
+ var Z, it, We, ut;
4150
+ const t = V(), n = ee(e), { uploadFile: o, maxFileSize: r } = To(), [l, a] = O(""), [s, c] = O(!1), [u, p] = O(null), [i, f] = O(!1), [b, v] = O(""), [g, k] = O(!1), [I, m] = O(null), y = _(null), B = _(null), L = h(
4151
+ (M) => t.applyOperation(G(e, M)),
4152
+ [t, e]
4153
+ ), D = h(() => {
4154
+ var M;
4155
+ v(((M = n == null ? void 0 : n.props) == null ? void 0 : M.alt) ?? ""), f(!0);
4156
+ }, [(Z = n == null ? void 0 : n.props) == null ? void 0 : Z.alt]), S = h(() => f(!1), []), $ = h(
4157
+ (M) => {
4158
+ M.preventDefault(), L({ alt: b.trim() }), f(!1);
4159
+ },
4160
+ [b, L]
4161
+ ), A = h(
4162
+ async (M, W) => {
4163
+ m(null), k(!0);
4164
+ try {
4165
+ const { src: j, name: J, mimeType: we } = await Xn(M, {
4166
+ uploadFile: o,
4167
+ maxFileSize: r,
4168
+ kind: W
4169
+ });
4170
+ L({ src: j, name: J, mimeType: we });
4171
+ } catch (j) {
4172
+ m((j == null ? void 0 : j.message) || "Upload failed. Please try again.");
4173
+ } finally {
4174
+ k(!1);
4175
+ }
4176
+ },
4177
+ [o, r, L]
4178
+ ), F = h(
4179
+ (M) => {
4180
+ var j, J;
4181
+ const W = (j = M.target.files) == null ? void 0 : j[0];
4182
+ M.target.value = "", W && A(W, ((J = n == null ? void 0 : n.props) == null ? void 0 : J.kind) ?? "file");
4183
+ },
4184
+ [A, (it = n == null ? void 0 : n.props) == null ? void 0 : it.kind]
4185
+ ), w = h(
4186
+ (M) => {
4187
+ var j, J;
4188
+ M.preventDefault(), c(!1);
4189
+ const W = (j = M.dataTransfer.files) == null ? void 0 : j[0];
4190
+ W && A(W, ((J = n == null ? void 0 : n.props) == null ? void 0 : J.kind) ?? "file");
4191
+ },
4192
+ [A, (We = n == null ? void 0 : n.props) == null ? void 0 : We.kind]
4193
+ ), N = h((M) => {
4194
+ M.preventDefault(), c(!0);
4195
+ }, []), x = h(() => c(!1), []), H = h(() => {
4196
+ const M = l.trim();
4197
+ if (!M) return;
4198
+ const W = is(M);
4199
+ L(W ? {
4200
+ kind: "oembed",
4201
+ src: W.embedUrl,
4202
+ name: M,
4203
+ mimeType: "",
4204
+ provider: W.provider,
4205
+ originalUrl: M
4206
+ } : { src: M, name: M }), a("");
4207
+ }, [l, L]), E = h(
4208
+ () => L({ src: "", name: "", mimeType: "", provider: "", originalUrl: "" }),
4209
+ [L]
4210
+ ), P = h(
4211
+ (M) => {
4212
+ M.preventDefault();
4213
+ const W = y.current, j = B.current;
4214
+ if (!W || !j) return;
4215
+ const J = W.getBoundingClientRect().width, we = j.getBoundingClientRect().width, qe = M.clientX, dt = (R) => Rt((we + (R.clientX - qe)) / J * 100), Ye = (R) => p(dt(R)), Xe = (R) => {
4216
+ document.removeEventListener("mousemove", Ye), document.removeEventListener("mouseup", Xe), L({ width: dt(R) }), p(null);
4217
+ };
4218
+ document.addEventListener("mousemove", Ye), document.addEventListener("mouseup", Xe);
4219
+ },
4220
+ [L]
4221
+ ), Y = h(
4222
+ (M) => {
4223
+ var we;
4224
+ const W = ((we = n == null ? void 0 : n.props) == null ? void 0 : we.width) ?? 100, j = M.shiftKey ? 1 : 5;
4225
+ let J;
4226
+ if (M.key === "ArrowLeft" || M.key === "ArrowDown") J = Rt(W - j);
4227
+ else if (M.key === "ArrowRight" || M.key === "ArrowUp")
4228
+ J = Rt(W + j);
4229
+ else if (M.key === "Home") J = Et;
4230
+ else if (M.key === "End") J = $t;
4231
+ else return;
4232
+ M.preventDefault(), L({ width: J });
4233
+ },
4234
+ [(ut = n == null ? void 0 : n.props) == null ? void 0 : ut.width, L]
4235
+ ), X = se("be-embed", n);
4236
+ if (!n) return null;
4237
+ const {
4238
+ kind: K = "file",
4239
+ src: z,
4240
+ name: Q,
4241
+ alt: he = "",
4242
+ align: ue = "left",
4243
+ width: ce = 100,
4244
+ provider: Ie = "",
4245
+ originalUrl: de = ""
4246
+ } = n.props, te = K === "image" || K === "video" || K === "oembed", Ae = u ?? ce, ye = K === "oembed";
4247
+ return (
4248
+ // tabIndex={-1}: focusable via .focus() (see setSelectedBlockId in
4249
+ // EditorProvider.jsx) without joining the normal Tab order — keeps the
4250
+ // surface's keydown listener capturing subsequent Backspace/Delete
4251
+ // presses once this block becomes selected, even when whatever
4252
+ // previously had focus was just removed from the DOM entirely.
4253
+ /* @__PURE__ */ T(
4254
+ "div",
4255
+ {
4256
+ className: X,
4257
+ "data-block-id": e,
4258
+ "data-kind": K,
4259
+ contentEditable: !1,
4260
+ tabIndex: -1,
4261
+ children: [
4262
+ z ? /* @__PURE__ */ d("div", { ref: y, className: `be-embed-preview be-embed-align-${ue}`, children: /* @__PURE__ */ T(
4263
+ "div",
4264
+ {
4265
+ ref: B,
4266
+ className: "be-embed-frame",
4267
+ style: te ? { width: `${Ae}%` } : void 0,
4268
+ children: [
4269
+ /* @__PURE__ */ T("div", { className: "be-embed-toolbar", contentEditable: !1, children: [
4270
+ ds.map(({ value: M, Icon: W, label: j }) => /* @__PURE__ */ d(
4271
+ "button",
4272
+ {
4273
+ type: "button",
4274
+ className: `be-embed-toolbar-btn${ue === M ? " be-embed-toolbar-btn-active" : ""}`,
4275
+ title: j,
4276
+ "aria-label": j,
4277
+ "aria-pressed": ue === M,
4278
+ onClick: () => L({ align: M }),
4279
+ children: /* @__PURE__ */ d(W, { size: 14 })
4280
+ },
4281
+ M
4282
+ )),
4283
+ K === "image" && /* @__PURE__ */ d(
4284
+ "button",
4285
+ {
4286
+ type: "button",
4287
+ className: "be-embed-toolbar-btn be-embed-alt-text-btn",
4288
+ onClick: D,
4289
+ children: "Alt text"
4290
+ }
4291
+ ),
4292
+ ye && de && /* @__PURE__ */ d(
4293
+ "a",
4294
+ {
4295
+ className: "be-embed-toolbar-btn be-embed-open-original",
4296
+ href: de,
4297
+ target: "_blank",
4298
+ rel: "noopener noreferrer",
4299
+ title: "Open original link",
4300
+ "aria-label": "Open original link",
4301
+ children: /* @__PURE__ */ d(Ln, { size: 14 })
4302
+ }
4303
+ ),
4304
+ /* @__PURE__ */ d(
4305
+ "button",
4306
+ {
4307
+ type: "button",
4308
+ className: "be-embed-remove",
4309
+ onClick: E,
4310
+ "aria-label": `Remove ${mt[K]}`,
4311
+ children: "Remove"
4312
+ }
4313
+ )
4314
+ ] }),
4315
+ /* @__PURE__ */ d(ps, { kind: K, src: z, name: Q, alt: he, provider: Ie }),
4316
+ te && /* @__PURE__ */ d(
4317
+ "div",
4318
+ {
4319
+ className: "be-embed-resize-handle",
4320
+ onMouseDown: P,
4321
+ onKeyDown: Y,
4322
+ role: "slider",
4323
+ tabIndex: 0,
4324
+ "aria-label": `Resize ${mt[K]}`,
4325
+ "aria-valuemin": Et,
4326
+ "aria-valuemax": $t,
4327
+ "aria-valuenow": Ae
4328
+ }
4329
+ )
4330
+ ]
4331
+ }
4332
+ ) }) : /* @__PURE__ */ T(
4333
+ "div",
4334
+ {
4335
+ className: `be-embed-dropzone${s ? " be-embed-dropzone-active" : ""}`,
4336
+ onDrop: ye || g ? void 0 : w,
4337
+ onDragOver: ye || g ? void 0 : N,
4338
+ onDragLeave: x,
4339
+ children: [
4340
+ g ? /* @__PURE__ */ d("span", { className: "be-embed-uploading", children: "Uploading…" }) : /* @__PURE__ */ T(Te, { children: [
4341
+ !ye && /* @__PURE__ */ T(Te, { children: [
4342
+ /* @__PURE__ */ T("label", { className: "be-embed-upload-btn", children: [
4343
+ "Upload ",
4344
+ mt[K],
4345
+ /* @__PURE__ */ d(
4346
+ "input",
4347
+ {
4348
+ type: "file",
4349
+ accept: us[K],
4350
+ onChange: F,
4351
+ hidden: !0
4352
+ }
4353
+ )
4354
+ ] }),
4355
+ /* @__PURE__ */ d("span", { className: "be-embed-dropzone-hint", children: "or drop a file, or paste a URL below" })
4356
+ ] }),
4357
+ /* @__PURE__ */ T("div", { className: "be-embed-url-row", children: [
4358
+ /* @__PURE__ */ d(
4359
+ "input",
4360
+ {
4361
+ type: "text",
4362
+ className: "be-embed-url-input",
4363
+ placeholder: ye ? "Paste a YouTube, Vimeo, Loom, Figma, CodePen, or Spotify link" : `https://... ${mt[K]} URL`,
4364
+ value: l,
4365
+ onChange: (M) => a(M.target.value),
4366
+ onKeyDown: (M) => M.key === "Enter" && H()
4367
+ }
4368
+ ),
4369
+ /* @__PURE__ */ d("button", { type: "button", className: "be-embed-url-commit", onClick: H, children: "Embed" })
4370
+ ] })
4371
+ ] }),
4372
+ I && /* @__PURE__ */ T("div", { className: "be-embed-upload-error", role: "alert", children: [
4373
+ I,
4374
+ /* @__PURE__ */ d("button", { type: "button", onClick: () => m(null), "aria-label": "Dismiss error", children: "×" })
4375
+ ] })
4376
+ ]
4377
+ }
4378
+ ),
4379
+ /* @__PURE__ */ d(Ht, { isOpen: i, onClose: S, title: "Alt text", children: /* @__PURE__ */ T("form", { onSubmit: $, children: [
4380
+ /* @__PURE__ */ T("label", { className: "be-modal-field", children: [
4381
+ /* @__PURE__ */ d("span", { children: "Describe this image for screen readers" }),
4382
+ /* @__PURE__ */ d(
4383
+ "input",
4384
+ {
4385
+ type: "text",
4386
+ value: b,
4387
+ onChange: (M) => v(M.target.value),
4388
+ placeholder: "e.g. A hand-drawn diagram of the release process",
4389
+ autoFocus: !0
4390
+ }
4391
+ )
4392
+ ] }),
4393
+ /* @__PURE__ */ T("div", { className: "be-modal-actions", children: [
4394
+ /* @__PURE__ */ d("button", { type: "button", className: "be-modal-cancel", onClick: S, children: "Cancel" }),
4395
+ /* @__PURE__ */ d("button", { type: "submit", className: "be-modal-save", children: "Save" })
4396
+ ] })
4397
+ ] }) })
4398
+ ]
4399
+ }
4400
+ )
4401
+ );
4402
+ }
4403
+ function ms({
4404
+ kind: e = "file",
4405
+ src: t = "",
4406
+ name: n = "",
4407
+ alt: o = "",
4408
+ mimeType: r = "",
4409
+ align: l = "left",
4410
+ width: a = 100,
4411
+ provider: s = "",
4412
+ originalUrl: c = ""
4413
+ } = {}) {
4414
+ return function(p) {
4415
+ return {
4416
+ block: {
4417
+ id: C(),
4418
+ type: "embed",
4419
+ parentId: p,
4420
+ contentIds: [],
4421
+ props: { kind: e, src: t, name: n, alt: o, mimeType: r, align: l, width: a, provider: s, originalUrl: c }
4422
+ },
4423
+ runs: []
4424
+ };
4425
+ };
4426
+ }
4427
+ const sn = {
4428
+ image: No,
4429
+ video: Ro,
4430
+ audio: Bo,
4431
+ file: An,
4432
+ oembed: Ln
4433
+ }, Qn = "be-embed-file-link", Jn = "be-embed-oembed-link";
4434
+ function hs(e, t, n) {
4435
+ if (e !== "image" && e !== "video" && e !== "oembed") return "";
4436
+ const o = [];
4437
+ return n !== 100 && o.push(`width:${n}%`), t === "center" ? o.push("display:block", "margin-left:auto", "margin-right:auto") : t === "right" && o.push("display:block", "margin-left:auto"), o.length ? ` style="${o.join(";")}"` : "";
4438
+ }
4439
+ function Nt(e) {
4440
+ var r, l, a, s;
4441
+ const t = (r = e.style) == null ? void 0 : r.width, n = t && t.endsWith("%") ? parseInt(t, 10) : 100;
4442
+ let o = "left";
4443
+ return ((l = e.style) == null ? void 0 : l.marginLeft) === "auto" && ((a = e.style) == null ? void 0 : a.marginRight) === "auto" ? o = "center" : ((s = e.style) == null ? void 0 : s.marginLeft) === "auto" && (o = "right"), { align: o, width: Number.isFinite(n) ? n : 100 };
4444
+ }
4445
+ function gs(e) {
4446
+ const {
4447
+ kind: t,
4448
+ src: n,
4449
+ name: o,
4450
+ alt: r = "",
4451
+ align: l = "left",
4452
+ width: a = 100,
4453
+ provider: s = "",
4454
+ originalUrl: c = ""
4455
+ } = e.props;
4456
+ if (!n) return "<p></p>";
4457
+ const u = hs(t, l, a);
4458
+ return t === "image" ? `<img src="${fe(n)}" alt="${fe(r)}"${u}>` : t === "video" ? `<video src="${fe(n)}" controls${u}></video>` : t === "audio" ? `<audio src="${fe(n)}" controls></audio>` : t === "oembed" ? `<a class="${Jn}" href="${fe(c || n)}" data-embed-url="${fe(n)}" data-embed-provider="${fe(s)}">${gt(c || n)}</a>` : `<a class="${Qn}" href="${fe(n)}">${gt(o || n)}</a>`;
4459
+ }
4460
+ function bs(e) {
4461
+ const { kind: t, src: n, name: o, originalUrl: r = "" } = e.props;
4462
+ return n ? t === "oembed" ? `[embed: ${r || n}]` : `[${t}: ${o || n}]` : "";
4463
+ }
4464
+ function ys(e) {
4465
+ const { kind: t, src: n, name: o, alt: r = "", originalUrl: l = "" } = e.props;
4466
+ return n ? t === "image" ? `![${r}](${n})` : t === "oembed" ? `[${l || n}](${l || n})` : `[${o || n}](${n})` : "";
4467
+ }
4468
+ function ks(e) {
4469
+ return e.tagName === "IMG" ? nt("image", e.getAttribute("src") ?? "", "", {
4470
+ ...Nt(e),
4471
+ alt: e.getAttribute("alt") ?? ""
4472
+ }) : e.tagName === "VIDEO" ? nt("video", e.getAttribute("src") ?? "", "", Nt(e)) : e.tagName === "AUDIO" ? nt("audio", e.getAttribute("src") ?? "", "") : e.tagName === "A" && e.classList.contains(Jn) ? nt("oembed", e.getAttribute("data-embed-url") ?? "", "", {
4473
+ ...Nt(e),
4474
+ provider: e.getAttribute("data-embed-provider") ?? "",
4475
+ originalUrl: e.getAttribute("href") ?? ""
4476
+ }) : e.tagName === "A" && e.classList.contains(Qn) ? nt("file", e.getAttribute("href") ?? "", e.textContent ?? "") : null;
4477
+ }
4478
+ function nt(e, t, n, { align: o = "left", width: r = 100, alt: l = "", provider: a = "", originalUrl: s = "" } = {}) {
4479
+ return {
4480
+ block: {
4481
+ id: C(),
4482
+ type: "embed",
4483
+ parentId: null,
4484
+ contentIds: [],
4485
+ props: { kind: e, src: t, name: n, alt: l, align: o, width: r, provider: a, originalUrl: s }
4486
+ },
4487
+ runs: []
4488
+ };
4489
+ }
4490
+ function cn(e) {
4491
+ return (t, { blockId: n, runId: o, sliceStart: r, sliceEnd: l }) => {
4492
+ const a = t.getRun(o), s = (a == null ? void 0 : a.value) ?? "";
4493
+ t.applyOperation(
4494
+ ie(o, { value: s.slice(0, r) + s.slice(l) })
4495
+ );
4496
+ const c = xn(t, n, ms({ kind: e }));
4497
+ return Ke(t, c, U("paragraph")), c;
4498
+ };
4499
+ }
4500
+ const vs = ae({
4501
+ name: "embed",
4502
+ contentModel: "void",
4503
+ component: fs,
4504
+ defaultProps: {
4505
+ kind: "file",
4506
+ src: "",
4507
+ name: "",
4508
+ alt: "",
4509
+ mimeType: "",
4510
+ align: "left",
4511
+ width: 100,
4512
+ provider: "",
4513
+ originalUrl: ""
4514
+ },
4515
+ toHTML: gs,
4516
+ toPlainText: bs,
4517
+ toMarkdown: ys,
4518
+ fromHTML: ks,
4519
+ slashCommands: [
4520
+ ...["image", "video", "audio", "file"].map((e) => ({
4521
+ label: e.charAt(0).toUpperCase() + e.slice(1),
4522
+ icon: sn[e],
4523
+ keywords: ["embed", "upload", "insert", e],
4524
+ run: cn(e)
4525
+ })),
4526
+ {
4527
+ label: "Embed link",
4528
+ icon: sn.oembed,
4529
+ // A YouTube/Vimeo/Loom/Figma/CodePen/Spotify link pasted into an
4530
+ // image/video/file block's own URL field is also auto-detected (see
4531
+ // EmbedBlock.jsx's commitUrl) — this command just gets there in one
4532
+ // step instead of via "/video" first.
4533
+ keywords: ["embed", "link", "youtube", "vimeo", "loom", "figma", "codepen", "spotify"],
4534
+ run: cn("oembed")
4535
+ }
4536
+ ]
4537
+ }), xt = /* @__PURE__ */ new Set();
4538
+ function Is(e) {
4539
+ xt.add(e);
4540
+ }
4541
+ function ws(e) {
4542
+ return xt.has(e) ? (xt.delete(e), !0) : !1;
4543
+ }
4544
+ function Ts(e, t, n) {
4545
+ var s;
4546
+ const o = e.getBlock(t), r = ((s = o == null ? void 0 : o.props) == null ? void 0 : s.titleRunIds) ?? (o == null ? void 0 : o.contentIds) ?? [], l = r.indexOf(n), a = l >= 0 ? r[l + 1] : void 0;
4547
+ if (a) {
4548
+ ve(a);
4549
+ return;
4550
+ }
4551
+ Ke(e, t, U("paragraph"));
4552
+ }
4553
+ function Cs({ id: e, blockId: t }) {
4554
+ const n = V(), o = ze(e), r = _(null);
4555
+ r.current === null && (r.current = ws(e));
4556
+ const l = h(
4557
+ (u) => {
4558
+ n.applyOperation(ie(e, { data: { ...o == null ? void 0 : o.data, selectedValue: u } })), r.current && Ts(n, t, e);
4559
+ },
4560
+ [n, e, o == null ? void 0 : o.data, t]
4561
+ );
4562
+ if (!o) return null;
4563
+ const { options: a = [], selectedValue: s = "", placeholder: c = "Select…" } = o.data ?? {};
4564
+ return /* @__PURE__ */ d(
4565
+ "span",
4566
+ {
4567
+ className: "be-inline-select",
4568
+ onMouseDown: (u) => {
4569
+ u.preventDefault(), u.stopPropagation();
4570
+ },
4571
+ onKeyDown: (u) => u.stopPropagation(),
4572
+ children: /* @__PURE__ */ d(
4573
+ Fe,
4574
+ {
4575
+ value: s,
4576
+ options: a,
4577
+ onChange: l,
4578
+ placeholder: c,
4579
+ ariaLabel: "Select an option",
4580
+ autoOpen: r.current
4581
+ }
4582
+ )
4583
+ }
4584
+ );
4585
+ }
4586
+ function zt(e, { blockId: t, runId: n, sliceStart: o, sliceEnd: r }, l, { autoOpen: a = !1 } = {}) {
4587
+ const s = e.getRun(n), c = (s == null ? void 0 : s.value) ?? "", u = c.slice(0, o), p = c.slice(r), i = l(), f = { ...s, value: u }, b = { id: C(), type: "text", value: p, marks: { ...s == null ? void 0 : s.marks } };
4588
+ e.applyOperation(Lo(t, [n], [f, i, b])), a ? Is(i.id) : ve(b.id);
4589
+ }
4590
+ function Bs(e) {
4591
+ return String(e).replace(/&/g, "&amp;").replace(/"/g, "&quot;");
4592
+ }
4593
+ function Zn(e) {
4594
+ var o;
4595
+ const { options: t = [], selectedValue: n = "" } = e.data ?? {};
4596
+ return ((o = t.find((r) => r.value === n)) == null ? void 0 : o.label) ?? "";
4597
+ }
4598
+ function Rs(e) {
4599
+ var n, o;
4600
+ const t = Zn(e) || ((n = e.data) == null ? void 0 : n.placeholder) || "";
4601
+ return `<span data-inline-type="select" data-selected-value="${Bs(((o = e.data) == null ? void 0 : o.selectedValue) ?? "")}">${t}</span>`;
4602
+ }
4603
+ function Ns(e) {
4604
+ return Zn(e);
4605
+ }
4606
+ function Ls(e) {
4607
+ var t;
4608
+ return ((t = e.getAttribute) == null ? void 0 : t.call(e, "data-inline-type")) !== "select" ? null : {
4609
+ id: C(),
4610
+ type: "select",
4611
+ value: "",
4612
+ marks: {},
4613
+ data: {
4614
+ options: [],
4615
+ selectedValue: e.getAttribute("data-selected-value") ?? ""
4616
+ }
4617
+ };
4618
+ }
4619
+ const As = bt({
4620
+ name: "select",
4621
+ component: Cs,
4622
+ toHTML: Rs,
4623
+ toPlainText: Ns,
4624
+ fromHTML: Ls,
4625
+ slashCommand: {
4626
+ label: "Select",
4627
+ icon: Ao,
4628
+ keywords: ["select", "dropdown", "choice", "picker"],
4629
+ run: (e, { blockId: t, runId: n, sliceStart: o, sliceEnd: r }) => zt(
4630
+ e,
4631
+ { blockId: t, runId: n, sliceStart: o, sliceEnd: r },
4632
+ () => ({
4633
+ id: C(),
4634
+ type: "select",
4635
+ value: "",
4636
+ marks: {},
4637
+ data: { options: [], selectedValue: "", placeholder: "Select…" }
4638
+ }),
4639
+ { autoOpen: !0 }
4640
+ )
4641
+ }
4642
+ });
4643
+ function Ms({ id: e }) {
4644
+ const t = V(), n = ze(e), o = h(
4645
+ (l) => {
4646
+ t.applyOperation(ie(e, { data: { ...n == null ? void 0 : n.data, isoDate: l.target.value } }));
4647
+ },
4648
+ [t, e, n == null ? void 0 : n.data]
4649
+ );
4650
+ if (!n) return null;
4651
+ const { isoDate: r = "" } = n.data ?? {};
4652
+ return /* @__PURE__ */ d(
4653
+ "span",
4654
+ {
4655
+ className: "be-inline-date",
4656
+ onMouseDown: (l) => l.stopPropagation(),
4657
+ onKeyDown: (l) => l.stopPropagation(),
4658
+ children: /* @__PURE__ */ d("input", { type: "date", value: r, onChange: o })
4659
+ }
4660
+ );
4661
+ }
4662
+ function Es(e) {
4663
+ return String(e).replace(/&/g, "&amp;").replace(/"/g, "&quot;");
4664
+ }
4665
+ function eo(e) {
4666
+ if (!e) return "";
4667
+ const t = /* @__PURE__ */ new Date(`${e}T00:00:00`);
4668
+ return Number.isNaN(t.getTime()) ? e : t.toLocaleDateString(void 0, { year: "numeric", month: "short", day: "numeric" });
4669
+ }
4670
+ function $s(e) {
4671
+ var n;
4672
+ const t = ((n = e.data) == null ? void 0 : n.isoDate) ?? "";
4673
+ return `<span data-inline-type="date" data-iso-date="${Es(t)}">${eo(t)}</span>`;
4674
+ }
4675
+ function xs(e) {
4676
+ var t;
4677
+ return eo(((t = e.data) == null ? void 0 : t.isoDate) ?? "");
4678
+ }
4679
+ function Os(e) {
4680
+ var t;
4681
+ return ((t = e.getAttribute) == null ? void 0 : t.call(e, "data-inline-type")) !== "date" ? null : {
4682
+ id: C(),
4683
+ type: "date",
4684
+ value: "",
4685
+ marks: {},
4686
+ data: { isoDate: e.getAttribute("data-iso-date") ?? "" }
4687
+ };
4688
+ }
4689
+ function Ss() {
4690
+ return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
4691
+ }
4692
+ const Ds = bt({
4693
+ name: "date",
4694
+ component: Ms,
4695
+ toHTML: $s,
4696
+ toPlainText: xs,
4697
+ fromHTML: Os,
4698
+ slashCommand: {
4699
+ label: "Date",
4700
+ icon: Mo,
4701
+ keywords: ["date", "when", "schedule", "calendar"],
4702
+ run: (e, { blockId: t, runId: n, sliceStart: o, sliceEnd: r }) => zt(e, { blockId: t, runId: n, sliceStart: o, sliceEnd: r }, () => ({
4703
+ id: C(),
4704
+ type: "date",
4705
+ value: "",
4706
+ marks: {},
4707
+ data: { isoDate: Ss() }
4708
+ }))
4709
+ }
4710
+ });
4711
+ function Hs({ id: e }) {
4712
+ const t = V(), n = ze(e), o = h(
4713
+ (s) => {
4714
+ t.applyOperation(
4715
+ ie(e, { data: { ...n == null ? void 0 : n.data, checked: s.target.checked } })
4716
+ );
4717
+ },
4718
+ [t, e, n == null ? void 0 : n.data]
4719
+ ), r = h(
4720
+ (s) => {
4721
+ t.applyOperation(ie(e, { data: { ...n == null ? void 0 : n.data, label: s.target.value } }));
4722
+ },
4723
+ [t, e, n == null ? void 0 : n.data]
4724
+ );
4725
+ if (!n) return null;
4726
+ const { checked: l = !1, label: a = "" } = n.data ?? {};
4727
+ return /* @__PURE__ */ T(
4728
+ "span",
4729
+ {
4730
+ className: "be-inline-checkbox",
4731
+ onMouseDown: (s) => s.stopPropagation(),
4732
+ onKeyDown: (s) => s.stopPropagation(),
4733
+ children: [
4734
+ /* @__PURE__ */ d(
4735
+ "input",
4736
+ {
4737
+ type: "checkbox",
4738
+ className: "be-inline-checkbox-input",
4739
+ checked: l,
4740
+ onChange: o
4741
+ }
4742
+ ),
4743
+ /* @__PURE__ */ d(
4744
+ "input",
4745
+ {
4746
+ type: "text",
4747
+ className: "be-inline-checkbox-label",
4748
+ value: a,
4749
+ onChange: r,
4750
+ placeholder: "Label…"
4751
+ }
4752
+ )
4753
+ ]
4754
+ }
4755
+ );
4756
+ }
4757
+ function Ps(e) {
4758
+ return String(e).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
4759
+ }
4760
+ function _s(e) {
4761
+ const { checked: t = !1, label: n = "" } = e.data ?? {};
4762
+ return `<span data-inline-type="checkbox" data-checked="${t}">${t ? "☑" : "☐"} ${Ps(n)}</span>`;
4763
+ }
4764
+ function Us(e) {
4765
+ const { checked: t = !1, label: n = "" } = e.data ?? {};
4766
+ return `${t ? "[x]" : "[ ]"} ${n}`.trim();
4767
+ }
4768
+ function js(e) {
4769
+ var t;
4770
+ return ((t = e.getAttribute) == null ? void 0 : t.call(e, "data-inline-type")) !== "checkbox" ? null : {
4771
+ id: C(),
4772
+ type: "checkbox",
4773
+ value: "",
4774
+ marks: {},
4775
+ data: {
4776
+ checked: e.getAttribute("data-checked") === "true",
4777
+ label: (e.textContent ?? "").replace(/^[☑☐]\s*/, "")
4778
+ }
4779
+ };
4780
+ }
4781
+ const Fs = bt({
4782
+ name: "checkbox",
4783
+ component: Hs,
4784
+ toHTML: _s,
4785
+ toPlainText: Us,
4786
+ fromHTML: js,
4787
+ slashCommand: {
4788
+ label: "Checkbox",
4789
+ icon: St,
4790
+ keywords: ["checkbox", "todo", "check", "toggle"],
4791
+ run: (e, { blockId: t, runId: n, sliceStart: o, sliceEnd: r }) => zt(e, { blockId: t, runId: n, sliceStart: o, sliceEnd: r }, () => ({
4792
+ id: C(),
4793
+ type: "checkbox",
4794
+ value: "",
4795
+ marks: {},
4796
+ data: { checked: !1, label: "" }
4797
+ }))
4798
+ }
4799
+ });
4800
+ function zs({ id: e, blockId: t }) {
4801
+ var b;
4802
+ const n = V(), o = ze(e), r = t ? n.getBlock(t) : null, l = r ? n.getBlock(r.parentId) : null, a = (l == null ? void 0 : l.parentId) ?? null, s = ee(a), c = l ? l.contentIds.indexOf(t) : -1, p = (((b = (s && l ? pe(s, l.contentIds.length) : [])[c]) == null ? void 0 : b.options) ?? []).map((v, g) => ({
4803
+ ...v,
4804
+ color: v.color ?? Mt(g)
4805
+ })), i = h(
4806
+ (v, g) => {
4807
+ n.applyOperation(
4808
+ ie(e, { data: { selectedValue: v, selectedLabel: (g == null ? void 0 : g.label) ?? "" } })
4809
+ );
4810
+ },
4811
+ [n, e]
4812
+ );
4813
+ if (!o) return null;
4814
+ const { selectedValue: f = "" } = o.data ?? {};
4815
+ return /* @__PURE__ */ d(
4816
+ "span",
4817
+ {
4818
+ className: "be-inline-table-select",
4819
+ onMouseDown: (v) => {
4820
+ v.preventDefault(), v.stopPropagation();
4821
+ },
4822
+ onKeyDown: (v) => v.stopPropagation(),
4823
+ children: /* @__PURE__ */ d(
4824
+ Fe,
4825
+ {
4826
+ value: f,
4827
+ options: p,
4828
+ onChange: i,
4829
+ placeholder: "Select…",
4830
+ ariaLabel: "Select an option",
4831
+ variant: "tag"
4832
+ }
4833
+ )
4834
+ }
4835
+ );
4836
+ }
4837
+ function to(e) {
4838
+ return String(e).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
4839
+ }
4840
+ function Ks(e) {
4841
+ return to(e).replace(/"/g, "&quot;");
4842
+ }
4843
+ function Vs(e) {
4844
+ const { selectedValue: t = "", selectedLabel: n = "" } = e.data ?? {};
4845
+ return `<span data-inline-type="tableSelect" data-selected-value="${Ks(t)}">${to(n)}</span>`;
4846
+ }
4847
+ function Gs(e) {
4848
+ var t;
4849
+ return ((t = e.data) == null ? void 0 : t.selectedLabel) ?? "";
4850
+ }
4851
+ function Ws(e) {
4852
+ var t;
4853
+ return ((t = e.getAttribute) == null ? void 0 : t.call(e, "data-inline-type")) !== "tableSelect" ? null : {
4854
+ id: C(),
4855
+ type: "tableSelect",
4856
+ value: "",
4857
+ marks: {},
4858
+ data: {
4859
+ selectedValue: e.getAttribute("data-selected-value") ?? "",
4860
+ selectedLabel: e.textContent ?? ""
4861
+ }
4862
+ };
4863
+ }
4864
+ const qs = bt({
4865
+ name: "tableSelect",
4866
+ component: zs,
4867
+ toHTML: Vs,
4868
+ toPlainText: Gs,
4869
+ fromHTML: Ws
4870
+ // No slashCommand: unlike select/date/custom field types, this type is never
4871
+ // inserted ad-hoc into a paragraph — it only exists inside a table cell
4872
+ // whose column type has been set to "select" (see setColumnType).
4873
+ }), Ys = { name: "emoji", kind: "inline" }, Xs = [
4874
+ br,
4875
+ Cr,
4876
+ ll,
4877
+ la,
4878
+ ra,
4879
+ oa,
4880
+ ua,
4881
+ ia,
4882
+ ba,
4883
+ Ca,
4884
+ Ma,
4885
+ Pa,
4886
+ Ya,
4887
+ ls,
4888
+ vs,
4889
+ ro,
4890
+ As,
4891
+ Ds,
4892
+ Fs,
4893
+ qs,
4894
+ Ys
4895
+ ];
4896
+ function cc({ exclude: e = [] } = {}) {
4897
+ const t = new Set(e);
4898
+ return Xs.filter((n) => !t.has(n.name));
4899
+ }
4900
+ export {
4901
+ Rr as $,
4902
+ _t as A,
4903
+ Me as B,
4904
+ rr as C,
4905
+ sc as D,
4906
+ me as E,
4907
+ kt as F,
4908
+ Nl as G,
4909
+ Go as H,
4910
+ He as I,
4911
+ Or as J,
4912
+ Sr as K,
4913
+ Ko as L,
4914
+ Dr as M,
4915
+ Un as N,
4916
+ ya as O,
4917
+ yl as P,
4918
+ Zt as Q,
4919
+ Ea as R,
4920
+ Fe as S,
4921
+ xr as T,
4922
+ ws as U,
4923
+ Ts as V,
4924
+ zt as W,
4925
+ Rl as X,
4926
+ Mt as Y,
4927
+ ml as Z,
4928
+ fl as _,
4929
+ ua as a,
4930
+ Pr as a0,
4931
+ Hn as a1,
4932
+ al as a2,
4933
+ It as a3,
4934
+ Ut as a4,
4935
+ Le as a5,
4936
+ _e as a6,
4937
+ Hl as a7,
4938
+ cl as a8,
4939
+ gl as a9,
4940
+ il as aa,
4941
+ jt as ab,
4942
+ zn as ac,
4943
+ vl as ad,
4944
+ kl as ae,
4945
+ bl as af,
4946
+ Il as ag,
4947
+ wl as ah,
4948
+ ht as ai,
4949
+ Cl as aj,
4950
+ en as ak,
4951
+ tn as al,
4952
+ cc as am,
4953
+ Dn as an,
4954
+ ra as b,
4955
+ la as c,
4956
+ ls as d,
4957
+ vs as e,
4958
+ Ya as f,
4959
+ Pa as g,
4960
+ Ma as h,
4961
+ Ca as i,
4962
+ ba as j,
4963
+ ll as k,
4964
+ ia as l,
4965
+ Cr as m,
4966
+ qs as n,
4967
+ Ys as o,
4968
+ br as p,
4969
+ Fs as q,
4970
+ Ds as r,
4971
+ As as s,
4972
+ oa as t,
4973
+ pe as u,
4974
+ Be as v,
4975
+ Pt as w,
4976
+ Mr as x,
4977
+ $r as y,
4978
+ vt as z
4979
+ };
4980
+ //# sourceMappingURL=starter-kit-CY5wzYDf.js.map