@vespercms/admin 0.0.0-stage → 0.1.0-next.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 (203) hide show
  1. package/README.md +119 -2
  2. package/dist/BodyEditor-CAGNfofv.js +3047 -0
  3. package/dist/a11y/FieldNotes.d.ts +23 -0
  4. package/dist/a11y/NotesDrawer.d.ts +23 -0
  5. package/dist/a11y/pdf.d.ts +3 -0
  6. package/dist/a11y/run.d.ts +3 -0
  7. package/dist/a11y/useNotes.d.ts +28 -0
  8. package/dist/app/App.d.ts +2 -0
  9. package/dist/app/Screen.d.ts +88 -0
  10. package/dist/app/UserMenu.d.ts +7 -0
  11. package/dist/app/api.d.ts +75 -0
  12. package/dist/app/appearance.d.ts +10 -0
  13. package/dist/app/browser-api.d.ts +17 -0
  14. package/dist/app/collection-icon.d.ts +12 -0
  15. package/dist/app/context.d.ts +23 -0
  16. package/dist/app/entries-changed.d.ts +11 -0
  17. package/dist/app/file-url.d.ts +13 -0
  18. package/dist/app/format.d.ts +4 -0
  19. package/dist/app/idb.d.ts +7 -0
  20. package/dist/app/load.d.ts +16 -0
  21. package/dist/app/media.d.ts +5 -0
  22. package/dist/app/navigation.d.ts +4 -0
  23. package/dist/app/pane-context.d.ts +19 -0
  24. package/dist/app/panes.d.ts +14 -0
  25. package/dist/app/router.d.ts +62 -0
  26. package/dist/body/BodyEditor.d.ts +42 -0
  27. package/dist/body/TableView.d.ts +2 -0
  28. package/dist/body/catalog.d.ts +47 -0
  29. package/dist/body/checks.d.ts +15 -0
  30. package/dist/body/chips.d.ts +31 -0
  31. package/dist/body/commands.d.ts +31 -0
  32. package/dist/body/document.d.ts +42 -0
  33. package/dist/body/insert.d.ts +69 -0
  34. package/dist/body/nodes.d.ts +38 -0
  35. package/dist/body/reveal.d.ts +13 -0
  36. package/dist/body/scroll.d.ts +16 -0
  37. package/dist/body/settings.d.ts +19 -0
  38. package/dist/body/shortcuts.d.ts +13 -0
  39. package/dist/body/table.d.ts +31 -0
  40. package/dist/body/ui.d.ts +30 -0
  41. package/dist/body/views.d.ts +9 -0
  42. package/dist/checks-C-0xDu-I.js +57 -0
  43. package/dist/cloud/CloudGate.d.ts +14 -0
  44. package/dist/cloud/access.d.ts +14 -0
  45. package/dist/cloud/changes.d.ts +26 -0
  46. package/dist/cloud/connection.d.ts +100 -0
  47. package/dist/cloud/editor.d.ts +44 -0
  48. package/dist/cloud/session.d.ts +62 -0
  49. package/dist/cloud/storage.d.ts +45 -0
  50. package/dist/editor/Field.d.ts +24 -0
  51. package/dist/editor/PagePicker.d.ts +20 -0
  52. package/dist/editor/arrange.d.ts +13 -0
  53. package/dist/editor/context.d.ts +23 -0
  54. package/dist/editor/copy.d.ts +9 -0
  55. package/dist/editor/reveal.d.ts +7 -0
  56. package/dist/editor/target.d.ts +21 -0
  57. package/dist/editor/values.d.ts +18 -0
  58. package/dist/geo-map-CT3OGD7O.js +110 -0
  59. package/dist/github/GitHubGate.d.ts +15 -0
  60. package/dist/github/api.d.ts +20 -0
  61. package/dist/github/cache.d.ts +2 -0
  62. package/dist/github/session.d.ts +35 -0
  63. package/dist/index.d.ts +3 -0
  64. package/dist/markdown-KUkv11EB.js +211 -0
  65. package/dist/media/MediaPicker.d.ts +28 -0
  66. package/dist/media/file-icon.d.ts +3 -0
  67. package/dist/media/formats.d.ts +23 -0
  68. package/dist/media/hygiene.d.ts +37 -0
  69. package/dist/media/upload.d.ts +31 -0
  70. package/dist/mount.d.ts +3 -0
  71. package/dist/pdf-m5s_uXJ3.js +24 -0
  72. package/dist/run-y4XRkg17.js +7 -0
  73. package/dist/schedule/ScheduleDialog.d.ts +28 -0
  74. package/dist/schedule/ScheduleSummary.d.ts +12 -0
  75. package/dist/schedule/ScheduledView.d.ts +8 -0
  76. package/dist/schedule/cloud.d.ts +21 -0
  77. package/dist/schedule/now.d.ts +5 -0
  78. package/dist/schedule/times.d.ts +37 -0
  79. package/dist/screens/EntryEditor.d.ts +13 -0
  80. package/dist/screens/EntryList.d.ts +18 -0
  81. package/dist/screens/Home.d.ts +6 -0
  82. package/dist/screens/ListPane.d.ts +6 -0
  83. package/dist/screens/MediaBrowser.d.ts +7 -0
  84. package/dist/screens/NotFound.d.ts +3 -0
  85. package/dist/screens/PageTree.d.ts +10 -0
  86. package/dist/screens/Redirects.d.ts +1 -0
  87. package/dist/screens/Unavailable.d.ts +8 -0
  88. package/dist/shortcuts-B_JMAvF9.js +4630 -0
  89. package/dist/studio.css +3 -0
  90. package/dist/studio.js +6312 -0
  91. package/dist/types.d.ts +76 -0
  92. package/dist/widgets/basic.d.ts +25 -0
  93. package/dist/widgets/crops.d.ts +43 -0
  94. package/dist/widgets/focal-point.d.ts +15 -0
  95. package/dist/widgets/geo-map.d.ts +10 -0
  96. package/dist/widgets/geo.d.ts +16 -0
  97. package/dist/widgets/group.d.ts +41 -0
  98. package/dist/widgets/icon.d.ts +9 -0
  99. package/dist/widgets/image.d.ts +16 -0
  100. package/dist/widgets/markdown-lazy.d.ts +2 -0
  101. package/dist/widgets/markdown.d.ts +2 -0
  102. package/dist/widgets/reference.d.ts +12 -0
  103. package/dist/widgets/registry.d.ts +32 -0
  104. package/dist/widgets/special.d.ts +20 -0
  105. package/dist/widgets/union.d.ts +36 -0
  106. package/package.json +63 -4
  107. package/src/a11y/FieldNotes.tsx +56 -0
  108. package/src/a11y/NotesDrawer.tsx +81 -0
  109. package/src/a11y/pdf.ts +45 -0
  110. package/src/a11y/run.ts +12 -0
  111. package/src/a11y/useNotes.ts +139 -0
  112. package/src/app/App.tsx +156 -0
  113. package/src/app/Screen.tsx +416 -0
  114. package/src/app/UserMenu.tsx +95 -0
  115. package/src/app/api.ts +176 -0
  116. package/src/app/appearance.ts +54 -0
  117. package/src/app/browser-api.ts +173 -0
  118. package/src/app/collection-icon.ts +15 -0
  119. package/src/app/context.tsx +32 -0
  120. package/src/app/entries-changed.ts +48 -0
  121. package/src/app/file-url.tsx +44 -0
  122. package/src/app/format.ts +39 -0
  123. package/src/app/idb.ts +82 -0
  124. package/src/app/load.ts +40 -0
  125. package/src/app/media.ts +20 -0
  126. package/src/app/navigation.ts +4 -0
  127. package/src/app/pane-context.ts +25 -0
  128. package/src/app/panes.tsx +513 -0
  129. package/src/app/router.ts +158 -0
  130. package/src/body/BodyEditor.tsx +1139 -0
  131. package/src/body/TableView.tsx +700 -0
  132. package/src/body/catalog.ts +198 -0
  133. package/src/body/checks.ts +83 -0
  134. package/src/body/chips.ts +150 -0
  135. package/src/body/commands.ts +191 -0
  136. package/src/body/document.ts +388 -0
  137. package/src/body/insert.tsx +301 -0
  138. package/src/body/nodes.ts +287 -0
  139. package/src/body/reveal.ts +93 -0
  140. package/src/body/scroll.ts +53 -0
  141. package/src/body/settings.tsx +510 -0
  142. package/src/body/shortcuts.ts +31 -0
  143. package/src/body/table.ts +192 -0
  144. package/src/body/ui.ts +77 -0
  145. package/src/body/views.tsx +268 -0
  146. package/src/build.ts +6 -0
  147. package/src/cloud/CloudGate.tsx +245 -0
  148. package/src/cloud/access.ts +52 -0
  149. package/src/cloud/changes.tsx +474 -0
  150. package/src/cloud/connection.ts +281 -0
  151. package/src/cloud/editor.tsx +250 -0
  152. package/src/cloud/session.ts +289 -0
  153. package/src/cloud/storage.ts +212 -0
  154. package/src/editor/Field.tsx +182 -0
  155. package/src/editor/PagePicker.tsx +102 -0
  156. package/src/editor/arrange.ts +98 -0
  157. package/src/editor/context.tsx +31 -0
  158. package/src/editor/copy.ts +30 -0
  159. package/src/editor/reveal.ts +38 -0
  160. package/src/editor/target.ts +104 -0
  161. package/src/editor/values.ts +71 -0
  162. package/src/github/GitHubGate.tsx +261 -0
  163. package/src/github/api.ts +81 -0
  164. package/src/github/cache.ts +64 -0
  165. package/src/github/session.ts +146 -0
  166. package/src/index.ts +10 -0
  167. package/src/media/MediaPicker.tsx +302 -0
  168. package/src/media/file-icon.ts +17 -0
  169. package/src/media/formats.ts +262 -0
  170. package/src/media/hygiene.ts +220 -0
  171. package/src/media/upload.ts +47 -0
  172. package/src/mount.tsx +20 -0
  173. package/src/schedule/ScheduleDialog.tsx +300 -0
  174. package/src/schedule/ScheduleSummary.tsx +59 -0
  175. package/src/schedule/ScheduledView.tsx +294 -0
  176. package/src/schedule/cloud.ts +66 -0
  177. package/src/schedule/now.ts +18 -0
  178. package/src/schedule/times.ts +133 -0
  179. package/src/screens/EntryEditor.tsx +1803 -0
  180. package/src/screens/EntryList.tsx +274 -0
  181. package/src/screens/Home.tsx +131 -0
  182. package/src/screens/ListPane.tsx +459 -0
  183. package/src/screens/MediaBrowser.tsx +253 -0
  184. package/src/screens/NotFound.tsx +19 -0
  185. package/src/screens/PageTree.tsx +718 -0
  186. package/src/screens/Redirects.tsx +522 -0
  187. package/src/screens/Unavailable.tsx +27 -0
  188. package/src/studio.css +163 -0
  189. package/src/types.ts +82 -0
  190. package/src/widgets/basic.tsx +311 -0
  191. package/src/widgets/crops.tsx +399 -0
  192. package/src/widgets/focal-point.tsx +240 -0
  193. package/src/widgets/geo-map.tsx +160 -0
  194. package/src/widgets/geo.tsx +170 -0
  195. package/src/widgets/group.tsx +827 -0
  196. package/src/widgets/icon.tsx +47 -0
  197. package/src/widgets/image.tsx +407 -0
  198. package/src/widgets/markdown-lazy.tsx +22 -0
  199. package/src/widgets/markdown.tsx +267 -0
  200. package/src/widgets/reference.tsx +196 -0
  201. package/src/widgets/registry.ts +104 -0
  202. package/src/widgets/special.tsx +286 -0
  203. package/src/widgets/union.tsx +233 -0
@@ -0,0 +1,3047 @@
1
+ import { t as e } from "./checks-C-0xDu-I.js";
2
+ import { $ as t, B as n, C as r, F as i, J as a, O as o, Q as s, R as c, S as l, V as u, Z as d, at as f, b as p, c as m, et as h, ft as ee, it as g, k as _, m as v, n as y, nt as te, o as b, ot as x, pt as S, r as C, s as w, st as T, t as E, ut as ne, x as D, z as O } from "./shortcuts-B_JMAvF9.js";
3
+ import { Fragment as re, createContext as k, useContext as A, useEffect as j, useId as M, useMemo as N, useRef as P, useState as F } from "react";
4
+ import { Fragment as I, jsx as L, jsxs as R } from "react/jsx-runtime";
5
+ import { assembleBody as z, deepEqual as B, editJsxTag as ie, editMarkdocTag as V, editTable as ae, escapePipes as H, humanize as oe, jsxClosing as se, jsxOpening as ce, jsxTagLayout as le, markdocClosing as ue, markdocOpening as de, markdocTagLayout as fe, markdocTags as pe, mediaReference as me, parseBody as he, tableValue as ge, unescapePipes as _e } from "@vespercms/core";
6
+ import { Extension as U, Node as W } from "@tiptap/core";
7
+ import ve from "@tiptap/extension-image";
8
+ import { Markdown as ye } from "@tiptap/markdown";
9
+ import { NodeSelection as G, Plugin as be, PluginKey as xe, Selection as Se, TextSelection as Ce } from "@tiptap/pm/state";
10
+ import { EditorContent as we, NodeViewContent as Te, NodeViewWrapper as K, ReactNodeViewRenderer as q, useEditor as Ee, useEditorState as J } from "@tiptap/react";
11
+ import De from "@tiptap/starter-kit";
12
+ import { Fragment as Oe } from "@tiptap/pm/model";
13
+ import { closeHistory as ke } from "@tiptap/pm/history";
14
+ //#region src/body/catalog.ts
15
+ var Ae = {
16
+ path: ["file"],
17
+ kind: "string",
18
+ required: !0,
19
+ label: "File",
20
+ description: "The partial’s file, shown here as part of this page."
21
+ };
22
+ function je(e, t) {
23
+ let n = /* @__PURE__ */ new Map();
24
+ if (t === "mdoc") {
25
+ for (let t of e.markdoc?.tags ?? []) {
26
+ let e = t.inline === !0 ? null : t.selfClosing ? "card" : "container", r = t.inline === !0 || t.inline === void 0 && !t.selfClosing && !t.children;
27
+ n.set(`markdoc:${t.name}`, {
28
+ key: `markdoc:${t.name}`,
29
+ syntax: "markdoc",
30
+ name: t.name,
31
+ label: t.label,
32
+ ...t.summary ? { summary: t.summary } : {},
33
+ ...t.description ? { description: t.description } : {},
34
+ block: e,
35
+ inline: r,
36
+ selfClosing: t.selfClosing,
37
+ ...t.children ? { children: t.children } : {},
38
+ fields: t.fields,
39
+ order: t.attributes.map((e) => e.name)
40
+ });
41
+ }
42
+ n.has("markdoc:partial") || n.set("markdoc:partial", {
43
+ key: "markdoc:partial",
44
+ syntax: "markdoc",
45
+ name: "partial",
46
+ label: "Partial",
47
+ summary: "file",
48
+ description: "Text kept in its own file and shown here.",
49
+ block: "card",
50
+ inline: !1,
51
+ selfClosing: !0,
52
+ fields: [Ae],
53
+ order: ["file", "variables"],
54
+ builtin: "partial"
55
+ }), n.set("markdoc:if", {
56
+ key: "markdoc:if",
57
+ syntax: "markdoc",
58
+ name: "if",
59
+ label: "Conditional content",
60
+ block: "container",
61
+ inline: !1,
62
+ selfClosing: !1,
63
+ fields: [],
64
+ order: [],
65
+ builtin: "if"
66
+ }), n.set("markdoc:else", {
67
+ key: "markdoc:else",
68
+ syntax: "markdoc",
69
+ name: "else",
70
+ label: "Otherwise",
71
+ block: "card",
72
+ inline: !1,
73
+ selfClosing: !0,
74
+ fields: [],
75
+ order: [],
76
+ builtin: "else"
77
+ });
78
+ }
79
+ if (t === "mdx") for (let t of e.mdx?.components ?? []) n.set(`mdx:${t.name}`, {
80
+ key: `mdx:${t.name}`,
81
+ syntax: "mdx",
82
+ name: t.name,
83
+ label: t.label,
84
+ ...t.summary ? { summary: t.summary } : {},
85
+ ...t.description ? { description: t.description } : {},
86
+ block: t.inline ? null : t.children ? "container" : "card",
87
+ inline: t.inline,
88
+ selfClosing: !t.children,
89
+ fields: t.fields ?? [],
90
+ order: (t.fields ?? []).map((e) => e.path[0] ?? "")
91
+ });
92
+ return {
93
+ format: t,
94
+ kinds: n,
95
+ find: (e, t) => n.get(`${e}:${t}`)
96
+ };
97
+ }
98
+ var Me = {
99
+ key: "table",
100
+ syntax: "markdoc",
101
+ name: "table",
102
+ label: "Table",
103
+ block: "card",
104
+ inline: !1,
105
+ selfClosing: !0,
106
+ fields: [],
107
+ order: [],
108
+ builtin: "table"
109
+ };
110
+ function Ne(e) {
111
+ return [...[...e.kinds.values()].filter((e) => e.builtin !== "if" && e.builtin !== "else"), Me];
112
+ }
113
+ function Pe(e, t, n, r = "") {
114
+ let i = e.order.map((e) => [e, t[e]]), a = n === "card" || n === "inline" && e.selfClosing;
115
+ if (e.syntax === "markdoc") {
116
+ let t = de(e.name, i, a), o = a ? "" : ue(e.name);
117
+ return {
118
+ open: t,
119
+ close: o,
120
+ whole: n === "inline" ? t + r + o : t
121
+ };
122
+ }
123
+ let o = ce(e.name, i, a), s = a ? "" : se(e.name);
124
+ return {
125
+ open: o,
126
+ close: s,
127
+ whole: n === "inline" ? o + r + s : o
128
+ };
129
+ }
130
+ function Y(e, t) {
131
+ return e === "mdx" ? t : oe(t);
132
+ }
133
+ //#endregion
134
+ //#region src/body/chips.ts
135
+ var Fe = "", Ie = "", Le = /([0-9a-f]*)/g, Re = new TextEncoder(), ze = new TextDecoder();
136
+ function Be(e) {
137
+ let t = "";
138
+ for (let n of Re.encode(e)) t += n.toString(16).padStart(2, "0");
139
+ return `${Fe}${t}${Ie}`;
140
+ }
141
+ function Ve(e) {
142
+ let t = new Uint8Array(e.length / 2);
143
+ for (let n = 0; n < t.length; n++) t[n] = parseInt(e.slice(n * 2, n * 2 + 2), 16);
144
+ return ze.decode(t);
145
+ }
146
+ function He(e) {
147
+ return e.replace(Le, (e, t) => Ve(t));
148
+ }
149
+ function Ue(e, t) {
150
+ let n = "", r = 0;
151
+ for (let i of t) n += e.slice(r, i.start) + Be(e.slice(i.start, i.end)), r = i.end;
152
+ return n + e.slice(r);
153
+ }
154
+ function We(e) {
155
+ return e.includes(Fe) || e.includes(Ie);
156
+ }
157
+ function Ge(e, t) {
158
+ let n = {}, r = {};
159
+ if (e === "markdoc") {
160
+ let [e] = pe(t);
161
+ for (let t of e?.attributes ?? []) t.type === "attribute" && t.name !== "primary" && (Ke(t.value) ? r[t.name] = qe(t.value) : n[t.name] = t.value);
162
+ return {
163
+ values: n,
164
+ code: r
165
+ };
166
+ }
167
+ let i = le(t);
168
+ for (let e of i?.attributes ?? []) e.name && (e.readable ? n[e.name] = e.value : r[e.name] = t.slice(e.start, e.end));
169
+ return {
170
+ values: n,
171
+ code: r
172
+ };
173
+ }
174
+ function Ke(e) {
175
+ return typeof e != "object" || !e ? !1 : "$$mdtype" in e || Object.values(e).some(Ke);
176
+ }
177
+ function qe(e) {
178
+ let t = e;
179
+ return t.$$mdtype === "Variable" && Array.isArray(t.path) ? `$${t.path.join(".")}` : t.$$mdtype === "Function" && t.name ? `${t.name}(…)` : "a value set by code";
180
+ }
181
+ function Je(e) {
182
+ if (e.startsWith("{%")) {
183
+ let t = pe(e), n = t[0], r = t.at(-1);
184
+ if (!n || n.kind === "variable") return {
185
+ syntax: "markdoc",
186
+ kind: "variable"
187
+ };
188
+ if (n.kind === "annotation") return {
189
+ syntax: "markdoc",
190
+ kind: "annotation"
191
+ };
192
+ let i = n.name;
193
+ if (n.kind === "tag") return {
194
+ syntax: "markdoc",
195
+ kind: "tag",
196
+ ...i ? { name: i } : {},
197
+ open: e,
198
+ inner: "",
199
+ close: ""
200
+ };
201
+ let a = r && r.kind === "tag_close" && r.end === e.length ? r.start : e.length;
202
+ return {
203
+ syntax: "markdoc",
204
+ kind: "tag",
205
+ ...i ? { name: i } : {},
206
+ open: e.slice(0, n.end),
207
+ inner: e.slice(n.end, a),
208
+ close: e.slice(a)
209
+ };
210
+ }
211
+ if (e.startsWith("<")) {
212
+ let t = le(e);
213
+ if (!t) return {
214
+ syntax: "mdx",
215
+ kind: "component"
216
+ };
217
+ let n = t.selfClosing ? "" : /<\/[^>]*>$/.exec(e)?.[0] ?? "";
218
+ return {
219
+ syntax: "mdx",
220
+ kind: "component",
221
+ name: t.name,
222
+ open: e.slice(0, t.openEnd),
223
+ inner: e.slice(t.openEnd, e.length - n.length),
224
+ close: n
225
+ };
226
+ }
227
+ return {
228
+ syntax: "mdx",
229
+ kind: "expression"
230
+ };
231
+ }
232
+ //#endregion
233
+ //#region src/body/table.ts
234
+ var Ye = /* @__PURE__ */ new Set([
235
+ "text",
236
+ "image",
237
+ "vesperInline"
238
+ ]), Xe = /&(?!(?:lt|gt|quot|amp);)[A-Za-z][A-Za-z0-9]*;/;
239
+ function Ze(e) {
240
+ let t = /^(\d{1,9})[.)](\s|$)/.exec(e);
241
+ return t?.[1] ? `${t[1]}\\${e.slice(t[1].length)}` : /^(#{1,6}(\s|$)|[-+*](\s|$)|>|([-*_][ \t]*){3,}$|`{3}|~{3})/.test(e) ? `\\${e}` : e;
242
+ }
243
+ function Qe(e, t) {
244
+ try {
245
+ let n = e.parse(Ze(_e(t))).content ?? [];
246
+ if (n.length === 0) return [];
247
+ let [r] = n;
248
+ if (n.length !== 1 || r?.type !== "paragraph") return null;
249
+ let i = r.content ?? [];
250
+ return i.every((e) => Ye.has(e.type ?? "")) ? i : null;
251
+ } catch {
252
+ return null;
253
+ }
254
+ }
255
+ function $e(e, t) {
256
+ if (t.length === 0) return "";
257
+ let n = {
258
+ type: "doc",
259
+ content: [{
260
+ type: "paragraph",
261
+ content: [...t]
262
+ }]
263
+ };
264
+ return H(e.serialize(n).trim());
265
+ }
266
+ function et(e, t) {
267
+ let n = Qe(e, t);
268
+ if (!n || n.some((e) => e.type === "text" && Xe.test(e.text ?? ""))) return null;
269
+ let r = Qe(e, $e(e, n));
270
+ return JSON.stringify(r) === JSON.stringify(n) ? n : null;
271
+ }
272
+ function tt(e, t) {
273
+ let n = ge(e, t), r = [t.header, ...t.rows];
274
+ return {
275
+ ...n,
276
+ rows: n.rows.map((e, t) => ({
277
+ ...e,
278
+ cells: e.cells.map((e, n) => {
279
+ let i = r[t]?.cells[n], a = i?.contentStart ?? 0;
280
+ return Ue(e, (i?.chips ?? []).map((e) => ({
281
+ start: e.start - a,
282
+ end: e.end - a
283
+ })));
284
+ })
285
+ }))
286
+ };
287
+ }
288
+ function nt(e) {
289
+ return {
290
+ ...e,
291
+ rows: e.rows.map((e) => ({
292
+ ...e,
293
+ cells: e.cells.map(He)
294
+ }))
295
+ };
296
+ }
297
+ function rt() {
298
+ return {
299
+ align: [null, null],
300
+ columns: [null, null],
301
+ rows: [{
302
+ from: null,
303
+ cells: ["", ""]
304
+ }, {
305
+ from: null,
306
+ cells: ["", ""]
307
+ }]
308
+ };
309
+ }
310
+ function it(e, t, n, r) {
311
+ return {
312
+ ...e,
313
+ rows: e.rows.map((e, i) => i === t ? {
314
+ ...e,
315
+ cells: e.cells.map((e, t) => t === n ? r : e)
316
+ } : e)
317
+ };
318
+ }
319
+ function at(e, t) {
320
+ let n = [...e.rows];
321
+ return n.splice(Math.max(1, t), 0, {
322
+ from: null,
323
+ cells: e.columns.map(() => "")
324
+ }), {
325
+ ...e,
326
+ rows: n
327
+ };
328
+ }
329
+ function ot(e, t) {
330
+ let n = (e, n) => [
331
+ ...e.slice(0, t),
332
+ n,
333
+ ...e.slice(t)
334
+ ];
335
+ return {
336
+ align: n(e.align, null),
337
+ columns: n(e.columns, null),
338
+ rows: e.rows.map((e) => ({
339
+ ...e,
340
+ cells: n(e.cells, "")
341
+ }))
342
+ };
343
+ }
344
+ function st(e, t, n) {
345
+ if (t < 1 || n < 1 || n >= e.rows.length || t >= e.rows.length) return e;
346
+ let r = [...e.rows], [i] = r.splice(t, 1);
347
+ return i && r.splice(n, 0, i), {
348
+ ...e,
349
+ rows: r
350
+ };
351
+ }
352
+ function ct(e, t, n) {
353
+ let r = e.columns.length;
354
+ if (t < 0 || n < 0 || t >= r || n >= r) return e;
355
+ let i = (e) => {
356
+ let r = [...e], [i] = r.splice(t, 1);
357
+ return i !== void 0 && r.splice(n, 0, i), r;
358
+ };
359
+ return {
360
+ align: i(e.align),
361
+ columns: i(e.columns),
362
+ rows: e.rows.map((e) => ({
363
+ ...e,
364
+ cells: i(e.cells)
365
+ }))
366
+ };
367
+ }
368
+ function lt(e, t) {
369
+ return t < 1 ? e : {
370
+ ...e,
371
+ rows: e.rows.filter((e, n) => n !== t)
372
+ };
373
+ }
374
+ function ut(e, t) {
375
+ if (e.columns.length <= 1) return e;
376
+ let n = (e) => e.filter((e, n) => n !== t);
377
+ return {
378
+ align: n(e.align),
379
+ columns: n(e.columns),
380
+ rows: e.rows.map((e) => ({
381
+ ...e,
382
+ cells: n(e.cells)
383
+ }))
384
+ };
385
+ }
386
+ function dt(e, t, n) {
387
+ return {
388
+ ...e,
389
+ align: e.align.map((e, r) => r === t ? n : e)
390
+ };
391
+ }
392
+ //#endregion
393
+ //#region src/body/commands.ts
394
+ function ft(e, t) {
395
+ return e === "vesperCard" || e === "vesperInline" || e === "vesperTable" || e === "sourceBlock" || t.kindOf(e) !== void 0;
396
+ }
397
+ function pt(e, t) {
398
+ let { selection: n } = e.state;
399
+ return n instanceof G && ft(n.node.type.name, t) ? {
400
+ pos: n.from,
401
+ type: n.node.type.name
402
+ } : null;
403
+ }
404
+ function mt(e, t) {
405
+ let { $from: n } = e.state.selection;
406
+ for (let e = n.depth; e > 0; e--) if (t.kindOf(n.node(e).type.name)) return n.before(e);
407
+ return null;
408
+ }
409
+ function ht(e, t) {
410
+ let n = e.state.tr.setSelection(G.create(e.state.doc, t));
411
+ e.view.dispatch(n.scrollIntoView()), e.view.focus();
412
+ }
413
+ function gt(e, t, n) {
414
+ let { state: r } = e, i = r.doc.resolve(t), a = r.doc.nodeAt(t);
415
+ if (!a || a.isInline) return null;
416
+ let o = i.parent, s = i.index() + n;
417
+ if (s < 0 || s >= o.childCount) return null;
418
+ let c = o.child(s), l = r.tr, u;
419
+ if (n === -1) {
420
+ let e = t - c.nodeSize;
421
+ l.delete(t, t + a.nodeSize).insert(e, a), u = e;
422
+ } else {
423
+ l.delete(t, t + a.nodeSize);
424
+ let e = t + c.nodeSize;
425
+ l.insert(e, a), u = e;
426
+ }
427
+ return l.setSelection(G.create(l.doc, u)).scrollIntoView(), e.view.dispatch(l), e.view.focus(), u;
428
+ }
429
+ function _t(e, t) {
430
+ let n = e.state.doc.nodeAt(t);
431
+ if (!n) return;
432
+ let r = e.state.tr.delete(t, t + n.nodeSize), i = Math.min(t, r.doc.content.size);
433
+ r.setSelection(Ce.near(r.doc.resolve(i))), e.view.dispatch(r.scrollIntoView()), e.view.focus();
434
+ }
435
+ function vt(e, t, n, r = {}, i = "") {
436
+ if (e.builtin === "table") return {
437
+ type: "vesperTable",
438
+ attrs: { value: rt() }
439
+ };
440
+ let a = Pe(e, r, t, i);
441
+ if (t === "inline") return {
442
+ type: "vesperInline",
443
+ attrs: { source: a.whole }
444
+ };
445
+ let o = t === "container" ? n.typeOf(e) : void 0;
446
+ return o ? {
447
+ type: o,
448
+ attrs: {
449
+ syntax: e.syntax,
450
+ name: e.name,
451
+ open: a.open,
452
+ close: a.close
453
+ },
454
+ content: [{ type: "paragraph" }]
455
+ } : {
456
+ type: "vesperCard",
457
+ attrs: {
458
+ syntax: e.syntax,
459
+ name: e.name,
460
+ source: a.whole
461
+ }
462
+ };
463
+ }
464
+ function yt(e, t, n) {
465
+ let { $from: r } = e.selection, i = r.parent;
466
+ if (!i.isTextblock) return null;
467
+ let a = i.type.name === "paragraph" && /^\/?[^\s]*$/.test(i.textContent);
468
+ if (t.block && (a || !t.inline) && ((i) => {
469
+ let o = r.depth - 1;
470
+ if (o < 0) return !1;
471
+ let s = e.schema.nodeFromJSON(vt(t, i, n)), c = r.node(o), l = r.index(o);
472
+ return a ? c.canReplace(l, l + 1, Oe.from(s)) : c.canReplaceWith(l + 1, l + 1, s.type);
473
+ })(t.block)) return t.block;
474
+ let o = e.schema.nodes.vesperInline;
475
+ return t.inline && o && i.canReplaceWith(r.index(), r.index(), o) ? "inline" : null;
476
+ }
477
+ function bt(e, t, n, r, i, a = {}) {
478
+ let o = vt(t, n, r, a), s = e.chain().focus();
479
+ i && (s = s.deleteRange(i));
480
+ let c = i ? i.from : e.state.selection.from;
481
+ if (!s.insertContent(o).run()) return null;
482
+ let l = { pos: null };
483
+ return e.state.doc.nodesBetween(Math.max(0, c - 2), e.state.doc.content.size, (e, t) => l.pos === null ? e.type.name === o.type && JSON.stringify(e.attrs.source ?? e.attrs.open) === JSON.stringify(o.attrs?.source ?? o.attrs?.open) ? (l.pos = t, !1) : !0 : !1), l.pos !== null && n === "container" && e.commands.setTextSelection(l.pos + 2), l.pos;
484
+ }
485
+ //#endregion
486
+ //#region src/body/nodes.ts
487
+ var xt = /* @__PURE__ */ new Set([
488
+ "paragraph",
489
+ "heading",
490
+ "bulletList",
491
+ "orderedList",
492
+ "blockquote",
493
+ "codeBlock",
494
+ "horizontalRule"
495
+ ]), St = {
496
+ default: null,
497
+ keepOnSplit: !1,
498
+ rendered: !1
499
+ }, Ct = U.create({
500
+ name: "vesperBlockIndex",
501
+ addGlobalAttributes() {
502
+ return [{
503
+ types: [...xt],
504
+ attributes: { vesperBlock: St }
505
+ }];
506
+ }
507
+ }), wt = W.create({
508
+ name: "sourceBlock",
509
+ group: "block",
510
+ atom: !0,
511
+ selectable: !0,
512
+ draggable: !1,
513
+ addAttributes() {
514
+ return {
515
+ vesperBlock: St,
516
+ text: {
517
+ default: "",
518
+ rendered: !1
519
+ },
520
+ blockType: {
521
+ default: "",
522
+ rendered: !1
523
+ }
524
+ };
525
+ },
526
+ parseHTML() {
527
+ return [{
528
+ tag: "div[data-vesper-source]",
529
+ getAttrs: (e) => ({
530
+ text: e.getAttribute("data-text") ?? "",
531
+ blockType: e.getAttribute("data-block-type") ?? ""
532
+ })
533
+ }];
534
+ },
535
+ renderHTML({ node: e }) {
536
+ return ["div", {
537
+ "data-vesper-source": "",
538
+ "data-text": String(e.attrs.text ?? ""),
539
+ "data-block-type": String(e.attrs.blockType ?? "")
540
+ }];
541
+ }
542
+ }), Tt = W.create({
543
+ name: "vesperCard",
544
+ group: "block vesperTag",
545
+ atom: !0,
546
+ selectable: !0,
547
+ draggable: !1,
548
+ addAttributes() {
549
+ return {
550
+ vesperBlock: St,
551
+ syntax: {
552
+ default: "markdoc",
553
+ rendered: !1
554
+ },
555
+ name: {
556
+ default: "",
557
+ rendered: !1
558
+ },
559
+ source: {
560
+ default: "",
561
+ rendered: !1
562
+ }
563
+ };
564
+ },
565
+ parseHTML() {
566
+ return [{
567
+ tag: "div[data-vesper-card]",
568
+ getAttrs: (e) => ({
569
+ syntax: e.getAttribute("data-syntax") ?? "markdoc",
570
+ name: e.getAttribute("data-name") ?? "",
571
+ source: e.getAttribute("data-source") ?? ""
572
+ })
573
+ }];
574
+ },
575
+ renderHTML({ node: e }) {
576
+ return ["div", {
577
+ "data-vesper-card": "",
578
+ "data-syntax": String(e.attrs.syntax),
579
+ "data-name": String(e.attrs.name),
580
+ "data-source": String(e.attrs.source)
581
+ }];
582
+ }
583
+ }), Et = W.create({
584
+ name: "vesperTable",
585
+ group: "block",
586
+ atom: !0,
587
+ selectable: !0,
588
+ draggable: !1,
589
+ addAttributes() {
590
+ return {
591
+ vesperBlock: St,
592
+ value: {
593
+ default: null,
594
+ rendered: !1
595
+ }
596
+ };
597
+ },
598
+ parseHTML() {
599
+ return [{
600
+ tag: "div[data-vesper-table]",
601
+ getAttrs: (e) => {
602
+ try {
603
+ return { value: JSON.parse(e.getAttribute("data-value") ?? "null") };
604
+ } catch {
605
+ return !1;
606
+ }
607
+ }
608
+ }];
609
+ },
610
+ renderHTML({ node: e }) {
611
+ return ["div", {
612
+ "data-vesper-table": "",
613
+ "data-value": JSON.stringify(e.attrs.value)
614
+ }];
615
+ }
616
+ }), Dt = W.create({
617
+ name: "vesperInline",
618
+ group: "inline",
619
+ inline: !0,
620
+ atom: !0,
621
+ selectable: !0,
622
+ draggable: !1,
623
+ addAttributes() {
624
+ return { source: {
625
+ default: "",
626
+ rendered: !1
627
+ } };
628
+ },
629
+ parseHTML() {
630
+ return [{
631
+ tag: "span[data-vesper-chip]",
632
+ getAttrs: (e) => ({ source: e.getAttribute("data-source") ?? "" })
633
+ }];
634
+ },
635
+ renderHTML({ node: e }) {
636
+ return ["span", {
637
+ "data-vesper-chip": "",
638
+ "data-source": String(e.attrs.source)
639
+ }];
640
+ },
641
+ markdownTokenizer: {
642
+ name: "vesperInline",
643
+ level: "inline",
644
+ start: (e) => e.indexOf(""),
645
+ tokenize: (e) => {
646
+ let t = /^([0-9a-f]*)/.exec(e);
647
+ return t ? {
648
+ type: "vesperInline",
649
+ raw: t[0],
650
+ hex: t[1]
651
+ } : void 0;
652
+ }
653
+ },
654
+ parseMarkdown: (e, t) => t.createNode("vesperInline", { source: Ve(String(e.hex ?? "")) }),
655
+ renderMarkdown: (e) => Be(String(e.attrs?.source ?? ""))
656
+ }), Ot = {
657
+ paragraph: ["paragraph"],
658
+ list: ["bulletList", "orderedList"],
659
+ heading: ["heading"],
660
+ blockquote: ["blockquote"],
661
+ fence: ["codeBlock"],
662
+ hr: ["horizontalRule"],
663
+ image: ["paragraph"],
664
+ table: ["vesperTable"],
665
+ tag: ["vesperTag"]
666
+ };
667
+ function kt(e) {
668
+ let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = [], a = 0;
669
+ for (let o of e.kinds.values()) {
670
+ if (o.block !== "container") continue;
671
+ let e = `vesperTag${String(a++)}_${o.name.replace(/[^A-Za-z0-9]/g, "")}`;
672
+ t.set(e, o), n.set(o.key, e);
673
+ let s = o.children?.flatMap((e) => Ot[e] ?? []), c = s ? /* @__PURE__ */ new Set([...s, "sourceBlock"]) : null;
674
+ r.set(o.key, c);
675
+ let l = c ? `(${[...c].join(" | ")})+` : "block+";
676
+ i.push(At(e, l, o));
677
+ }
678
+ return {
679
+ extensions: i,
680
+ typeOf: (e) => n.get(e.key),
681
+ kindOf: (e) => t.get(e),
682
+ allows: (e, n) => {
683
+ let i = r.get(e.key);
684
+ return i == null || i.has(n) ? !0 : i.has("vesperTag") && (n === "vesperCard" || t.has(n));
685
+ }
686
+ };
687
+ }
688
+ function At(e, t, n) {
689
+ return W.create({
690
+ name: e,
691
+ group: "block vesperTag",
692
+ content: t,
693
+ defining: !0,
694
+ isolating: !0,
695
+ draggable: !1,
696
+ selectable: !0,
697
+ addAttributes() {
698
+ return {
699
+ vesperBlock: St,
700
+ syntax: {
701
+ default: n.syntax,
702
+ rendered: !1
703
+ },
704
+ name: {
705
+ default: n.name,
706
+ rendered: !1
707
+ },
708
+ open: {
709
+ default: "",
710
+ rendered: !1
711
+ },
712
+ close: {
713
+ default: "",
714
+ rendered: !1
715
+ }
716
+ };
717
+ },
718
+ parseHTML() {
719
+ return [{
720
+ tag: `div[data-vesper-container="${e}"]`,
721
+ getAttrs: (e) => ({
722
+ open: e.getAttribute("data-open") ?? "",
723
+ close: e.getAttribute("data-close") ?? ""
724
+ })
725
+ }];
726
+ },
727
+ renderHTML({ node: t }) {
728
+ return [
729
+ "div",
730
+ {
731
+ "data-vesper-container": e,
732
+ "data-open": String(t.attrs.open),
733
+ "data-close": String(t.attrs.close)
734
+ },
735
+ 0
736
+ ];
737
+ }
738
+ });
739
+ }
740
+ //#endregion
741
+ //#region src/body/document.ts
742
+ function jt(e, t) {
743
+ let n = he(e, t.format, t.markdoc ? { markdoc: t.markdoc } : {}), r = Nt(n.text, n.blocks, null, "", t, null);
744
+ return {
745
+ parsed: n,
746
+ doc: {
747
+ type: "doc",
748
+ content: r.length > 0 ? r : [{ type: "paragraph" }]
749
+ }
750
+ };
751
+ }
752
+ var Mt = (e, t) => e === null ? String(t) : `${e}.${String(t)}`;
753
+ function Nt(e, t, n, r, i, a) {
754
+ return t.map((t, o) => {
755
+ let s = Mt(n, o), c = Ft(e, t, s, r, i);
756
+ return a && !a(c.type ?? "") ? Pt(e, t, s) : c;
757
+ });
758
+ }
759
+ function Pt(e, t, n) {
760
+ return {
761
+ type: "sourceBlock",
762
+ attrs: {
763
+ vesperBlock: n,
764
+ text: e.slice(t.start, t.end),
765
+ blockType: t.type
766
+ }
767
+ };
768
+ }
769
+ function Ft(e, t, n, r, i) {
770
+ let a = e.slice(t.start, t.end);
771
+ if (t.kind === "markdown" && !We(a)) {
772
+ let o = It(Ue(a, (t.chips ?? []).map((e) => ({
773
+ start: e.start - t.start,
774
+ end: e.end - t.start
775
+ }))), r), s = o === null ? null : Lt(i.markdown, o);
776
+ return s ? {
777
+ ...s,
778
+ attrs: {
779
+ ...s.attrs,
780
+ vesperBlock: n
781
+ }
782
+ } : Pt(e, t, n);
783
+ }
784
+ if (t.kind === "table" && t.table) {
785
+ let r = tt(e, t.table);
786
+ return r.rows.every((e) => e.cells.every((e) => !We(He(e)) && et(i.markdown, e))) ? {
787
+ type: "vesperTable",
788
+ attrs: {
789
+ vesperBlock: n,
790
+ value: r
791
+ }
792
+ } : Pt(e, t, n);
793
+ }
794
+ let o = t.tag, s = t.kind === "tag" && o ? i.catalog.find(o.syntax, o.name) : void 0;
795
+ if (!o || !s) return Pt(e, t, n);
796
+ let c = i.containers.typeOf(s);
797
+ if (c && o.children && o.closeStart !== void 0) {
798
+ let r = Nt(e, o.children, n, o.indent ?? "", i, (e) => i.containers.allows(s, e));
799
+ return {
800
+ type: c,
801
+ attrs: {
802
+ vesperBlock: n,
803
+ syntax: o.syntax,
804
+ name: o.name,
805
+ open: e.slice(t.start, o.openEnd),
806
+ close: e.slice(o.closeStart, t.end)
807
+ },
808
+ content: r.length > 0 ? r : [{ type: "paragraph" }]
809
+ };
810
+ }
811
+ return {
812
+ type: "vesperCard",
813
+ attrs: {
814
+ vesperBlock: n,
815
+ syntax: o.syntax,
816
+ name: o.name,
817
+ source: a
818
+ }
819
+ };
820
+ }
821
+ function It(e, t) {
822
+ if (t === "") return e;
823
+ let n = e.split("\n"), r = [];
824
+ for (let [e, i] of n.entries()) if (e === 0) r.push(i);
825
+ else if (i.trim() === "") r.push(i.trim());
826
+ else if (i.startsWith(t)) r.push(i.slice(t.length));
827
+ else return null;
828
+ return r.join("\n");
829
+ }
830
+ function Lt(e, t) {
831
+ try {
832
+ let n = e.parse(t).content ?? [], [r] = n;
833
+ if (n.length !== 1 || !r?.type || !xt.has(r.type)) return null;
834
+ let i = e.parse(e.serialize({
835
+ type: "doc",
836
+ content: [r]
837
+ })).content ?? [];
838
+ return i.length === 1 && JSON.stringify(i[0]) === JSON.stringify(r) ? r : null;
839
+ } catch {
840
+ return null;
841
+ }
842
+ }
843
+ var Rt = (e, t) => e.type !== void 0 && t.kindOf(e.type) !== void 0;
844
+ function zt(e, t) {
845
+ let n = /* @__PURE__ */ new Map(), r = (e) => {
846
+ for (let i of e ?? []) {
847
+ let e = i.attrs?.vesperBlock;
848
+ typeof e == "string" && !n.has(e) && n.set(e, Rt(i, t) ? JSON.stringify({ open: i.attrs?.open }) : JSON.stringify(i)), Rt(i, t) && r(i.content);
849
+ }
850
+ };
851
+ return r(e.content), n;
852
+ }
853
+ function Bt(e, t) {
854
+ if (typeof e != "string") return null;
855
+ let n = e.lastIndexOf(".");
856
+ return (n === -1 ? null : e.slice(0, n)) === t ? Number(e.slice(n + 1)) : null;
857
+ }
858
+ function Vt(e, t, n) {
859
+ return Gt(e.content, null, t, n);
860
+ }
861
+ function Ht(e, t) {
862
+ let n = e.blocks, r = "", i = t.split(".");
863
+ for (let [e, t] of i.entries()) {
864
+ let a = n[Number(t)];
865
+ if (!a) return null;
866
+ if (e === i.length - 1) return {
867
+ block: a,
868
+ indent: r
869
+ };
870
+ if (!a.tag?.children) return null;
871
+ n = a.tag.children, r = a.tag.indent ?? "";
872
+ }
873
+ return null;
874
+ }
875
+ function Ut(e) {
876
+ let t = [], n = (e) => e.type === "vesperInline" ? (t.push(String(e.attrs?.source ?? "")), {
877
+ ...e,
878
+ attrs: {
879
+ ...e.attrs,
880
+ source: ""
881
+ }
882
+ }) : e.content ? {
883
+ ...e,
884
+ content: e.content.map(n)
885
+ } : e;
886
+ return {
887
+ sources: t,
888
+ shape: JSON.stringify(n(e))
889
+ };
890
+ }
891
+ function Wt(e, t, n, r) {
892
+ let i = n.get(t), a = r ? Ht(r, t) : null;
893
+ if (!i || !r || !a?.block.chips) return null;
894
+ let o = Ut(JSON.parse(i)), s = Ut(e), c = a.block.chips;
895
+ if (o.shape !== s.shape || s.sources.length !== c.length) return null;
896
+ let l = r.text.slice(a.block.start, a.block.end);
897
+ for (let e = c.length - 1; e >= 0; e--) {
898
+ let t = c[e];
899
+ if (!t) return null;
900
+ let n = t.start - a.block.start, r = t.end - a.block.start;
901
+ l = l.slice(0, n) + (s.sources[e] ?? "") + l.slice(r);
902
+ }
903
+ return It(l, a.indent);
904
+ }
905
+ function Gt(e, t, n, r) {
906
+ let i = [];
907
+ for (let a of e ?? []) {
908
+ let e = a.attrs?.vesperBlock, o = Bt(e, t);
909
+ if (Rt(a, r.containers)) {
910
+ let t = String(a.attrs?.open ?? "");
911
+ if (o !== null && typeof e == "string") {
912
+ let s = n.get(e), c = Gt(a.content, e, n, r);
913
+ i.push({
914
+ replaces: o,
915
+ ...s === JSON.stringify({ open: t }) ? {} : { open: t },
916
+ children: c
917
+ });
918
+ } else i.push({
919
+ open: t,
920
+ close: String(a.attrs?.close ?? ""),
921
+ children: Gt(a.content, null, n, r)
922
+ });
923
+ continue;
924
+ }
925
+ if (o !== null && typeof e == "string" && n.get(e) === JSON.stringify(a)) {
926
+ i.push({ keep: o });
927
+ continue;
928
+ }
929
+ if (a.type === "vesperTable") {
930
+ let t = Kt(typeof e == "string" ? e : null, a.attrs?.value, r);
931
+ if (!t.ok) throw Error(t.reason);
932
+ i.push(o === null ? { text: t.text } : {
933
+ text: t.text,
934
+ replaces: o
935
+ });
936
+ continue;
937
+ }
938
+ let s = (o !== null && typeof e == "string" ? Wt(a, e, n, r.parsed) : null) ?? qt(a, r.markdown);
939
+ (s !== "" || o !== null) && i.push(o === null ? { text: s } : {
940
+ text: s,
941
+ replaces: o
942
+ });
943
+ }
944
+ return i;
945
+ }
946
+ function Kt(e, t, n) {
947
+ if (!n.format) throw Error("Saving a table needs the body’s format.");
948
+ let r = {
949
+ format: n.format,
950
+ ...n.markdoc ? { markdoc: n.markdoc } : {}
951
+ }, i = e !== null && n.parsed ? Ht(n.parsed, e) : null, a = i?.block.table, o = i && a && n.parsed ? {
952
+ text: n.parsed.text,
953
+ table: a,
954
+ indent: i.indent
955
+ } : null;
956
+ return ae(o, nt(t), r);
957
+ }
958
+ function qt(e, t) {
959
+ if (e.type === "sourceBlock") return String(e.attrs?.text ?? "");
960
+ if (e.type === "vesperCard") return String(e.attrs?.source ?? "");
961
+ let { vesperBlock: n, ...r } = e.attrs ?? {};
962
+ return He(t.serialize({
963
+ type: "doc",
964
+ content: [{
965
+ ...e,
966
+ attrs: r
967
+ }]
968
+ }).replace(/\s+$/, ""));
969
+ }
970
+ function Jt(e) {
971
+ return {
972
+ mdxjsEsm: "Import",
973
+ mdxJsxFlowElement: "Component",
974
+ mdxFlowExpression: "Expression",
975
+ html: "HTML",
976
+ html_block: "HTML",
977
+ comment: "Comment",
978
+ definition: "Link reference",
979
+ footnoteDefinition: "Footnote",
980
+ table: "Table",
981
+ tag: "Markdoc tag",
982
+ unparsed: "Body that couldn’t be read"
983
+ }[e] ?? "Formatted text";
984
+ }
985
+ //#endregion
986
+ //#region src/body/insert.tsx
987
+ var X = new xe("vesperSlash");
988
+ function Yt(e, t, n) {
989
+ return Ne(t).flatMap((t) => {
990
+ let r = yt(e, t, n);
991
+ return r ? [{
992
+ kind: t,
993
+ shape: r
994
+ }] : [];
995
+ }).sort((e, t) => e.kind.label.localeCompare(t.kind.label));
996
+ }
997
+ function Xt(e) {
998
+ let t = X.getState(e);
999
+ return t?.active ? e.doc.textBetween(t.from + 1, e.selection.from, "\n") : null;
1000
+ }
1001
+ function Zt(e, t) {
1002
+ let n = t.toLowerCase();
1003
+ return e.filter((e) => e.kind.label.toLowerCase().includes(n) || e.kind.name.toLowerCase().includes(n));
1004
+ }
1005
+ function Qt(e) {
1006
+ return U.create({
1007
+ name: "vesperSlash",
1008
+ priority: 1e3,
1009
+ addProseMirrorPlugins() {
1010
+ return [new be({
1011
+ key: X,
1012
+ state: {
1013
+ init: () => ({ active: !1 }),
1014
+ apply(e, t, n, r) {
1015
+ let i = e.getMeta(X), a = t, o = i !== void 0 && "active" in i;
1016
+ if (o ? a = i : i && a.active && (a = {
1017
+ ...a,
1018
+ index: i.index
1019
+ }), !a.active) return a;
1020
+ let s = o ? a.from : e.mapping.map(a.from, -1), { selection: c } = r, l = r.doc.textBetween(s, Math.max(s, c.from), "\n");
1021
+ return c.empty && c.from > s && r.doc.resolve(s).parent === c.$from.parent && l.startsWith("/") && !/\s/.test(l) ? {
1022
+ ...a,
1023
+ from: s
1024
+ } : { active: !1 };
1025
+ }
1026
+ },
1027
+ props: {
1028
+ handleTextInput(t, n, r, i) {
1029
+ if (i !== "/" || e.disabled()) return !1;
1030
+ let a = t.state.doc.resolve(n);
1031
+ if (a.parent.type.name !== "paragraph") return !1;
1032
+ let o = a.parent.textBetween(0, a.parentOffset, "\n");
1033
+ return o !== "" && !/\s$/.test(o) ? !1 : (t.dispatch(t.state.tr.insertText("/", n, r).setMeta(X, {
1034
+ active: !0,
1035
+ from: n,
1036
+ index: 0
1037
+ })), !0);
1038
+ },
1039
+ handleKeyDown(t, n) {
1040
+ let r = X.getState(t.state);
1041
+ if (!r?.active) return !1;
1042
+ let i = Xt(t.state) ?? "", a = Zt(e.choices(t.state), i);
1043
+ if (n.key === "Escape") return t.dispatch(t.state.tr.setMeta(X, { active: !1 })), !0;
1044
+ if (a.length === 0) return !1;
1045
+ if (n.key === "ArrowDown" || n.key === "ArrowUp") {
1046
+ let e = n.key === "ArrowDown" ? 1 : -1, i = (r.index + e + a.length) % a.length;
1047
+ return t.dispatch(t.state.tr.setMeta(X, { index: i })), !0;
1048
+ }
1049
+ if (n.key === "Enter" || n.key === "Tab") {
1050
+ let n = a[Math.min(r.index, a.length - 1)];
1051
+ if (!n) return !1;
1052
+ let i = {
1053
+ from: r.from,
1054
+ to: t.state.selection.from
1055
+ };
1056
+ return t.dispatch(t.state.tr.setMeta(X, { active: !1 })), e.choose(n, i), !0;
1057
+ }
1058
+ return !1;
1059
+ }
1060
+ }
1061
+ })];
1062
+ }
1063
+ });
1064
+ }
1065
+ function $t(e, t) {
1066
+ let n = X.getState(e);
1067
+ if (!n?.active) return {
1068
+ role: "textbox",
1069
+ "aria-multiline": "true"
1070
+ };
1071
+ let r = t.count(Xt(e) ?? "");
1072
+ return {
1073
+ role: "combobox",
1074
+ "aria-expanded": "true",
1075
+ "aria-controls": t.listboxId,
1076
+ "aria-autocomplete": "list",
1077
+ ...r > 0 ? { "aria-activedescendant": t.optionId(Math.min(n.index, r - 1)) } : {}
1078
+ };
1079
+ }
1080
+ function en({ editor: e, listboxId: t, optionId: n, choices: r, onChoose: i }) {
1081
+ let a = J({
1082
+ editor: e,
1083
+ selector: ({ editor: e }) => {
1084
+ let t = X.getState(e.state);
1085
+ return t?.active ? {
1086
+ from: t.from,
1087
+ to: e.state.selection.from,
1088
+ index: t.index,
1089
+ query: Xt(e.state) ?? "",
1090
+ place: tn(e, t.from)
1091
+ } : null;
1092
+ },
1093
+ equalityFn: (e, t) => JSON.stringify(e) === JSON.stringify(t)
1094
+ });
1095
+ if (!a) return null;
1096
+ let { place: o } = a, s = Zt(r(e.state), a.query), c = Math.min(a.index, Math.max(0, s.length - 1));
1097
+ return /* @__PURE__ */ L("div", {
1098
+ id: t,
1099
+ role: "listbox",
1100
+ "aria-label": "Insert a block",
1101
+ style: o ? {
1102
+ top: o.top,
1103
+ left: o.left
1104
+ } : void 0,
1105
+ className: S("fixed z-40 max-h-64 min-w-56 overflow-y-auto", g),
1106
+ children: s.length === 0 ? /* @__PURE__ */ L("div", {
1107
+ role: "option",
1108
+ tabIndex: -1,
1109
+ "aria-selected": "false",
1110
+ "aria-disabled": "true",
1111
+ className: "px-3 py-2 text-small text-content-muted",
1112
+ children: "Nothing fits here"
1113
+ }) : s.map((e, t) => /* @__PURE__ */ R("div", {
1114
+ id: n(t),
1115
+ role: "option",
1116
+ tabIndex: -1,
1117
+ "aria-selected": t === c,
1118
+ className: S("flex min-h-9 cursor-default items-center rounded-md px-3 text-body text-content", t === c && "bg-accent-subtle"),
1119
+ onMouseDown: (t) => {
1120
+ t.preventDefault(), i(e, {
1121
+ from: a.from,
1122
+ to: a.to
1123
+ });
1124
+ },
1125
+ children: [e.kind.label, e.shape === "inline" && /* @__PURE__ */ L("span", {
1126
+ className: "text-content-muted",
1127
+ children: " (in this line)"
1128
+ })]
1129
+ }, e.kind.key))
1130
+ });
1131
+ }
1132
+ function tn(e, t) {
1133
+ try {
1134
+ let n = e.view.coordsAtPos(t);
1135
+ return {
1136
+ top: n.bottom + 4,
1137
+ left: n.left
1138
+ };
1139
+ } catch {
1140
+ return null;
1141
+ }
1142
+ }
1143
+ function nn({ editor: e, choices: t, onChoose: n, disabled: r }) {
1144
+ let i = J({
1145
+ editor: e,
1146
+ selector: ({ editor: e }) => t(e.state).map((e) => `${e.kind.key}|${e.shape}`).join(",")
1147
+ }), a = t(e.state);
1148
+ return r || i === "" || a.length === 0 ? null : /* @__PURE__ */ L(te, {
1149
+ label: "Insert a block",
1150
+ triggerText: "Insert",
1151
+ triggerIcon: "add",
1152
+ items: a.map((e) => ({
1153
+ id: `${e.kind.key}|${e.shape}`,
1154
+ label: e.shape === "inline" ? `${e.kind.label} (in this line)` : e.kind.label
1155
+ })),
1156
+ onAction: (e) => {
1157
+ let t = a.find((t) => `${t.kind.key}|${t.shape}` === e);
1158
+ t && n(t);
1159
+ }
1160
+ });
1161
+ }
1162
+ function rn() {
1163
+ let e = M().replace(/:/g, "");
1164
+ return {
1165
+ listboxId: `${e}-insert`,
1166
+ optionId: (t) => `${e}-insert-${String(t)}`
1167
+ };
1168
+ }
1169
+ //#endregion
1170
+ //#region src/body/reveal.ts
1171
+ function an(e, t) {
1172
+ let n = [], r = e;
1173
+ for (; r.length > 0;) {
1174
+ let e = r.findIndex((e) => t >= e.start && t <= e.end);
1175
+ e === -1 && (e = Math.max(0, r.findLastIndex((e) => e.start <= t))), n.push(e);
1176
+ let i = r[e]?.tag?.children ?? [];
1177
+ if (!i.some((e) => t >= e.start && t <= e.end)) break;
1178
+ r = i;
1179
+ }
1180
+ return n;
1181
+ }
1182
+ function on(e, t) {
1183
+ let n = e, r = 0, i = null;
1184
+ for (let e of t) {
1185
+ if (n.childCount === 0) break;
1186
+ let t = Math.min(e, n.childCount - 1), a = r;
1187
+ for (let e = 0; e < t; e++) a += n.child(e).nodeSize;
1188
+ let o = n.child(t);
1189
+ if (i = {
1190
+ node: o,
1191
+ pos: a
1192
+ }, o.isTextblock || o.isAtom) break;
1193
+ n = o, r = a + 1;
1194
+ }
1195
+ return i;
1196
+ }
1197
+ function sn(e, t, n, r) {
1198
+ let i = he(t, r.format, r.markdoc ? { markdoc: r.markdoc } : {}), a = on(e.state.doc, an(i.blocks, n));
1199
+ if (e.view.focus(), !a) return;
1200
+ let { doc: o } = e.state, s;
1201
+ s = a.node.isTextblock ? Ce.create(o, a.pos + 1) : ft(a.node.type.name, r.containers) ? G.create(o, a.pos) : Ce.near(o.resolve(a.pos + 1)), e.view.dispatch(e.state.tr.setSelection(s).scrollIntoView());
1202
+ }
1203
+ function cn(e, t, n) {
1204
+ e.setSelectionRange(t, n), e.blur(), e.focus();
1205
+ }
1206
+ //#endregion
1207
+ //#region src/body/scroll.ts
1208
+ var ln = "sticky top-[var(--sticky-top,0px)] z-1 rounded-t-md border-b border-border bg-surface-raised p-1", un = 4;
1209
+ function dn(e, t) {
1210
+ if (!t) return !1;
1211
+ let { selection: n } = e.state, r;
1212
+ try {
1213
+ r = e.coordsAtPos(n instanceof G ? n.from : n.head).top;
1214
+ } catch {
1215
+ return !1;
1216
+ }
1217
+ let i = t.getBoundingClientRect().bottom + un;
1218
+ return r >= i || r < e.dom.getBoundingClientRect().top || fn(e.dom).scrollBy(0, r - i), !1;
1219
+ }
1220
+ function fn(e) {
1221
+ for (let t = e.parentElement; t; t = t.parentElement) {
1222
+ let { overflowY: e } = getComputedStyle(t);
1223
+ if ((e === "auto" || e === "scroll") && t.scrollHeight > t.clientHeight) return t;
1224
+ }
1225
+ return window;
1226
+ }
1227
+ //#endregion
1228
+ //#region src/body/ui.ts
1229
+ var pn = k(null);
1230
+ function Z() {
1231
+ let e = A(pn);
1232
+ if (!e) throw Error("useBodyUi() must be used inside the body editor.");
1233
+ return e;
1234
+ }
1235
+ function mn(e) {
1236
+ let { checks: t } = Z(), n = N(() => t.validateSync(e), [t, e]), [r, i] = F([]);
1237
+ return j(() => {
1238
+ if (n !== null) return;
1239
+ let r = !0;
1240
+ return t.validate(e).then((e) => {
1241
+ r && i(e);
1242
+ }), () => {
1243
+ r = !1;
1244
+ };
1245
+ }, [
1246
+ t,
1247
+ e,
1248
+ n
1249
+ ]), n ?? r;
1250
+ }
1251
+ function hn(e, t) {
1252
+ if (!e) return "";
1253
+ let n = e.summary ?? (e.builtin === "partial" ? "file" : void 0);
1254
+ if (!n) return "";
1255
+ let r = t[n], i = e.fields.find((e) => e.path[0] === n), a = r === void 0 ? i?.default : r;
1256
+ if (a == null || a === "") return "";
1257
+ let o = i?.constraints?.options?.find((e) => e.value === a)?.label ?? (typeof a == "string" ? a : JSON.stringify(a));
1258
+ return o.length > 60 ? `${o.slice(0, 57)}…` : o;
1259
+ }
1260
+ //#endregion
1261
+ //#region src/body/settings.tsx
1262
+ var Q = (e) => typeof e == "string" ? e : "";
1263
+ function gn({ editor: e, pos: t, onClose: n }) {
1264
+ let r = Z(), i = J({
1265
+ editor: e,
1266
+ selector: ({ editor: e }) => {
1267
+ if (t === null) return null;
1268
+ let n = e.state.doc.nodeAt(t);
1269
+ return n ? {
1270
+ pos: t,
1271
+ type: n.type.name,
1272
+ attrs: n.attrs,
1273
+ inline: n.isInline
1274
+ } : null;
1275
+ },
1276
+ equalityFn: (e, t) => JSON.stringify(e) === JSON.stringify(t)
1277
+ }), a = i ? vn(i, r) : null;
1278
+ return /* @__PURE__ */ L(h, {
1279
+ title: a?.title ?? "Settings",
1280
+ isOpen: t !== null && i !== null,
1281
+ onOpenChange: (e) => {
1282
+ e || n();
1283
+ },
1284
+ children: i && a && /* @__PURE__ */ R(_n, {
1285
+ className: "flex flex-col gap-6",
1286
+ children: [
1287
+ a.mode === "tag" && a.kind && /* @__PURE__ */ L(xn, {
1288
+ editor: e,
1289
+ target: i,
1290
+ kind: a.kind
1291
+ }),
1292
+ a.mode === "condition" && /* @__PURE__ */ L(En, {
1293
+ editor: e,
1294
+ target: i
1295
+ }),
1296
+ a.mode === "raw" && /* @__PURE__ */ L(Dn, {
1297
+ editor: e,
1298
+ target: i,
1299
+ label: a.label
1300
+ }),
1301
+ /* @__PURE__ */ L(On, {
1302
+ editor: e,
1303
+ target: i,
1304
+ onClose: n
1305
+ })
1306
+ ]
1307
+ })
1308
+ });
1309
+ }
1310
+ function _n({ className: e, children: t }) {
1311
+ let n = P(null);
1312
+ return j(() => {
1313
+ let e = setTimeout(() => {
1314
+ let e = n.current?.querySelector("input:not([type=hidden]):not([disabled]), textarea:not([disabled]), button:not([disabled])");
1315
+ ((e?.type === "radio" ? n.current?.querySelector(`input[type=radio][name="${CSS.escape(e.name)}"]:checked`) : null) ?? e)?.focus();
1316
+ }, 0);
1317
+ return () => {
1318
+ clearTimeout(e);
1319
+ };
1320
+ }, []), /* @__PURE__ */ L("div", {
1321
+ ref: n,
1322
+ className: e,
1323
+ children: t
1324
+ });
1325
+ }
1326
+ function vn(e, t) {
1327
+ if (e.type === "sourceBlock") {
1328
+ let t = Jt(Q(e.attrs.blockType));
1329
+ return {
1330
+ mode: "raw",
1331
+ title: `Edit ${t.toLowerCase()} as text`,
1332
+ label: t
1333
+ };
1334
+ }
1335
+ let n = t.containers.kindOf(e.type);
1336
+ if (n) return n.builtin === "if" ? {
1337
+ mode: "condition",
1338
+ title: "Conditional content",
1339
+ label: n.label
1340
+ } : {
1341
+ mode: "tag",
1342
+ title: `${n.label} settings`,
1343
+ label: n.label,
1344
+ kind: n
1345
+ };
1346
+ if (e.type === "vesperCard") {
1347
+ let n = e.attrs.syntax, r = Q(e.attrs.name), i = t.catalog.find(n, r);
1348
+ if (i && !i.builtin) return {
1349
+ mode: "tag",
1350
+ title: `${i.label} settings`,
1351
+ label: i.label,
1352
+ kind: i
1353
+ };
1354
+ if (i?.builtin === "partial") return {
1355
+ mode: "tag",
1356
+ title: "Partial settings",
1357
+ label: i.label,
1358
+ kind: i
1359
+ };
1360
+ let a = i?.label ?? Y(n, r);
1361
+ return {
1362
+ mode: "raw",
1363
+ title: `Edit ${a} as text`,
1364
+ label: a
1365
+ };
1366
+ }
1367
+ let r = Je(Q(e.attrs.source)), i = r.name ? t.catalog.find(r.syntax, r.name) : void 0;
1368
+ if (i && !i.builtin && (r.kind === "tag" || r.kind === "component")) return {
1369
+ mode: "tag",
1370
+ title: `${i.label} settings`,
1371
+ label: i.label,
1372
+ kind: i
1373
+ };
1374
+ let a = r.kind === "variable" ? "Variable" : r.kind === "annotation" ? "Annotation" : r.kind === "expression" ? "Expression" : r.name ? Y(r.syntax, r.name) : "Tag";
1375
+ return {
1376
+ mode: "raw",
1377
+ title: `Edit ${a.toLowerCase()} as text`,
1378
+ label: a
1379
+ };
1380
+ }
1381
+ function yn(e) {
1382
+ if (e.type === "vesperInline") {
1383
+ let t = Q(e.attrs.source), n = Je(t);
1384
+ return {
1385
+ syntax: n.syntax,
1386
+ open: n.open ?? t,
1387
+ rest: t.slice((n.open ?? t).length),
1388
+ inner: n.inner ?? "",
1389
+ close: n.close ?? ""
1390
+ };
1391
+ }
1392
+ let t = e.attrs.syntax;
1393
+ if (e.type === "vesperCard") {
1394
+ let n = Q(e.attrs.source), r = t === "markdoc" ? pe(n)[0]?.end ?? n.length : le(n)?.openEnd ?? n.length;
1395
+ return {
1396
+ syntax: t,
1397
+ open: n.slice(0, r),
1398
+ rest: n.slice(r)
1399
+ };
1400
+ }
1401
+ return {
1402
+ syntax: t,
1403
+ open: Q(e.attrs.open),
1404
+ rest: ""
1405
+ };
1406
+ }
1407
+ function $(e, t, n) {
1408
+ let r = e.state.tr.setNodeMarkup(t.pos, void 0, {
1409
+ ...t.attrs,
1410
+ ...n
1411
+ });
1412
+ e.view.dispatch(r);
1413
+ }
1414
+ function bn(e, t, n) {
1415
+ let r = yn(t);
1416
+ t.type === "vesperInline" || t.type === "vesperCard" ? $(e, t, { source: n + r.rest }) : $(e, t, { open: n });
1417
+ }
1418
+ function xn({ editor: e, target: t, kind: n }) {
1419
+ let i = Z(), a = r(), s = yn(t), { values: c, code: u } = Ge(s.syntax, s.open), [d, f] = F(null), p = mn(t.type === "vesperInline" || t.type === "vesperCard" ? Q(t.attrs.source) : s.syntax === "mdx" ? `${s.open}\n\n${Q(t.attrs.close)}` : `${s.open}\n${Q(t.attrs.close)}`), m = N(() => {
1420
+ let e = {};
1421
+ for (let t of n.fields) {
1422
+ let n = t.path[0] ?? "", r = n in c ? c[n] : t.default;
1423
+ r !== void 0 && (e[n] = r);
1424
+ }
1425
+ return e;
1426
+ }, [n.fields, c]), h = N(() => {
1427
+ let e = /* @__PURE__ */ new Map();
1428
+ for (let t of p) {
1429
+ if (!t.attribute || t.level !== "error") continue;
1430
+ let n = o([t.attribute]), r = t.message.replace(/^[^:]+: /, "");
1431
+ e.set(n, [...e.get(n) ?? [], r]);
1432
+ }
1433
+ return e;
1434
+ }, [p]), ee = n.builtin === "partial" ? n.fields.filter((e) => e.path[0] !== "file") : n.fields, g = {
1435
+ ...a,
1436
+ values: m,
1437
+ issues: h,
1438
+ disabled: i.disabled,
1439
+ idPrefix: `block${String(t.pos)}`,
1440
+ setValue: (r, i) => {
1441
+ let a = String(r[0]), o = r.length > 1 ? _(m, r, i)[a] ?? null : i, c = n.fields.find((e) => e.path[0] === a), l = c?.default !== void 0 && B(o, c.default) ? void 0 : o, u = (s.syntax === "markdoc" ? V : ie)(s.open, [[a, l]], n.order);
1442
+ u === null ? f("This tag is written in a way the form can’t change. Edit it as Markdoc instead.") : (f(null), bn(e, t, u));
1443
+ }
1444
+ };
1445
+ return /* @__PURE__ */ R(l.Provider, {
1446
+ value: g,
1447
+ children: [
1448
+ n.description && /* @__PURE__ */ L("p", {
1449
+ className: "text-small text-content-muted",
1450
+ children: n.description
1451
+ }),
1452
+ d && /* @__PURE__ */ L("p", {
1453
+ role: "alert",
1454
+ className: "text-small text-danger",
1455
+ children: d
1456
+ }),
1457
+ n.builtin === "partial" && /* @__PURE__ */ L(Sn, {
1458
+ value: typeof c.file == "string" ? c.file : "",
1459
+ message: p.find((e) => e.code === "partial-missing")?.message,
1460
+ onChange: (r) => {
1461
+ let i = V(s.open, [["file", r]], n.order);
1462
+ i && bn(e, t, i);
1463
+ }
1464
+ }),
1465
+ ee.map((e) => /* @__PURE__ */ L(C, {
1466
+ field: e,
1467
+ path: e.path
1468
+ }, e.path.join("."))),
1469
+ t.type === "vesperInline" && s.close !== "" && /* @__PURE__ */ L(x, {
1470
+ label: "Text",
1471
+ description: "What the reader sees.",
1472
+ value: s.inner ?? "",
1473
+ isDisabled: i.disabled,
1474
+ onChange: (n) => {
1475
+ $(e, t, { source: s.open + n + (s.close ?? "") });
1476
+ }
1477
+ }),
1478
+ Object.keys(u).length > 0 && /* @__PURE__ */ R("div", {
1479
+ className: "text-small text-content-muted",
1480
+ children: [/* @__PURE__ */ L("p", { children: "Set in the page’s code, so kept as written:" }), /* @__PURE__ */ L("ul", {
1481
+ className: "list-disc pl-6",
1482
+ children: Object.entries(u).map(([e, t]) => /* @__PURE__ */ R("li", { children: [
1483
+ /* @__PURE__ */ L("code", {
1484
+ className: "font-mono",
1485
+ children: e
1486
+ }),
1487
+ ": ",
1488
+ /* @__PURE__ */ L("code", {
1489
+ className: "font-mono",
1490
+ children: t
1491
+ })
1492
+ ] }, e))
1493
+ })]
1494
+ })
1495
+ ]
1496
+ });
1497
+ }
1498
+ function Sn({ value: e, message: t, onChange: n }) {
1499
+ let r = Z(), i = Cn(r.partials ?? [], r.entryPath, e);
1500
+ return /* @__PURE__ */ L(d, {
1501
+ label: "File",
1502
+ description: "Text kept in its own file and shown here. Files whose names start with an underscore, or that sit in a partials folder, are listed.",
1503
+ options: i,
1504
+ value: e === "" ? null : e,
1505
+ onChange: (e) => {
1506
+ e !== null && n(e);
1507
+ },
1508
+ isInvalid: t !== void 0,
1509
+ errorMessage: t?.replace(/^[^:]+: /, ""),
1510
+ isRequired: !0,
1511
+ isDisabled: r.disabled
1512
+ });
1513
+ }
1514
+ function Cn(e, t, n) {
1515
+ let r = wn(e, t).map((e) => ({
1516
+ value: Tn(t, e),
1517
+ label: e
1518
+ }));
1519
+ return n !== "" && !r.some((e) => e.value === n) && r.unshift({
1520
+ value: n,
1521
+ label: `${n} (as written)`
1522
+ }), r;
1523
+ }
1524
+ function wn(e, t) {
1525
+ let n = (e) => Tn(t, e).split("/").length - 1;
1526
+ return e.filter((e) => e !== t && e.endsWith(".mdoc")).filter((e) => /(^|\/)_[^/]+$/.test(e) || /(^|\/)_?partials\//.test(e)).sort((e, t) => n(e) - n(t) || e.localeCompare(t));
1527
+ }
1528
+ function Tn(e, t) {
1529
+ let n = e.split("/").slice(0, -1), r = t.split("/"), i = 0;
1530
+ for (; i < n.length && i < r.length - 1 && n[i] === r[i];) i++;
1531
+ return [...Array(n.length - i).fill(".."), ...r.slice(i)].join("/");
1532
+ }
1533
+ function En({ editor: e, target: t }) {
1534
+ let n = Z(), r = Q(t.attrs.open), i = fe(r), a = i?.attributes.find((e) => e.kind === "primary"), [o, s] = F(a ? r.slice(a.valueStart, a.valueEnd) : ""), [c, l] = F(!1);
1535
+ return !i || !a ? /* @__PURE__ */ L(Dn, {
1536
+ editor: e,
1537
+ target: t,
1538
+ label: "Condition",
1539
+ field: "open"
1540
+ }) : /* @__PURE__ */ L(x, {
1541
+ label: "Shown when",
1542
+ description: "A Markdoc condition, such as $product.beta or equals($tier, \"free\"). The content inside is shown only when it’s true.",
1543
+ value: o,
1544
+ isDisabled: n.disabled,
1545
+ isInvalid: c,
1546
+ errorMessage: "That isn’t a condition Markdoc can read, so it wasn’t changed.",
1547
+ inputClassName: "font-mono",
1548
+ onChange: (n) => {
1549
+ s(n);
1550
+ let i = r.slice(0, a.valueStart) + n + r.slice(a.valueEnd), o = n.trim() !== "" && fe(i)?.attributes.some((e) => e.kind === "primary");
1551
+ l(!o), o && $(e, t, { open: i });
1552
+ }
1553
+ });
1554
+ }
1555
+ function Dn({ editor: e, target: t, label: n, field: r }) {
1556
+ let i = Z(), a = r ?? (t.type === "sourceBlock" ? "text" : "source"), o = Q(t.attrs[a]);
1557
+ return /* @__PURE__ */ L(f, {
1558
+ label: n,
1559
+ description: "Kept exactly as written: Vesper never reformats it. Change it with care; the site reads it as code.",
1560
+ value: o,
1561
+ rows: Math.min(12, o.split("\n").length + 1),
1562
+ isDisabled: i.disabled,
1563
+ inputClassName: "font-mono text-small",
1564
+ onChange: (n) => {
1565
+ $(e, t, { [a]: n });
1566
+ }
1567
+ });
1568
+ }
1569
+ function On({ editor: e, target: t, onClose: n }) {
1570
+ let r = Z(), i = e.state.doc.resolve(t.pos), a = i.index(), o = i.parent.childCount;
1571
+ return /* @__PURE__ */ R("div", {
1572
+ className: "flex flex-wrap items-center justify-between gap-3 border-t border-border pt-4",
1573
+ children: [/* @__PURE__ */ R("div", {
1574
+ className: "flex flex-wrap gap-2",
1575
+ children: [!t.inline && /* @__PURE__ */ R(I, { children: [/* @__PURE__ */ L(T, {
1576
+ isDisabled: r.disabled || a === 0,
1577
+ onPress: () => {
1578
+ r.move(t.pos, -1);
1579
+ },
1580
+ children: "Move up"
1581
+ }), /* @__PURE__ */ L(T, {
1582
+ isDisabled: r.disabled || a >= o - 1,
1583
+ onPress: () => {
1584
+ r.move(t.pos, 1);
1585
+ },
1586
+ children: "Move down"
1587
+ })] }), /* @__PURE__ */ L(T, {
1588
+ variant: "quiet",
1589
+ isDisabled: r.disabled,
1590
+ onPress: () => {
1591
+ n(), r.remove(t.pos);
1592
+ },
1593
+ children: "Remove"
1594
+ })]
1595
+ }), /* @__PURE__ */ L(T, {
1596
+ variant: "primary",
1597
+ onPress: n,
1598
+ children: "Done"
1599
+ })]
1600
+ });
1601
+ }
1602
+ //#endregion
1603
+ //#region src/body/TableView.tsx
1604
+ var kn = S("in-[.ProseMirror-focused]:outline-2 in-[.ProseMirror-focused]:outline-solid in-[.ProseMirror-focused]:outline-offset-2 in-[.ProseMirror-focused]:outline-focus", "in-[.ProseMirror-focused]:ring-6 in-[.ProseMirror-focused]:ring-(color:--glow-focus)"), An = [
1605
+ {
1606
+ id: "left",
1607
+ label: "Left",
1608
+ align: "left"
1609
+ },
1610
+ {
1611
+ id: "center",
1612
+ label: "Centre",
1613
+ align: "center"
1614
+ },
1615
+ {
1616
+ id: "right",
1617
+ label: "Right",
1618
+ align: "right"
1619
+ },
1620
+ {
1621
+ id: "none",
1622
+ label: "As written",
1623
+ align: null
1624
+ }
1625
+ ], jn = {
1626
+ left: "text-left",
1627
+ center: "text-center",
1628
+ right: "text-right"
1629
+ };
1630
+ function Mn(e, t) {
1631
+ let n = Je(t), r = (n.name ? e.catalog.find(n.syntax, n.name) : void 0)?.label ?? (n.name && (n.kind === "tag" || n.kind === "component") ? Y(n.syntax, n.name) : null);
1632
+ if (r === null) return t.length > 40 ? `${t.slice(0, 37)}…` : t;
1633
+ let i = n.inner ?? "";
1634
+ return i && !/[{<*_`[\]\\]/.test(i) ? `${r} · ${i}` : r;
1635
+ }
1636
+ function Nn(e, t) {
1637
+ return t.map((t) => t.type === "text" ? t.text ?? "" : t.type === "image" ? String(t.attrs?.alt ?? "") : t.type === "vesperInline" ? Mn(e, String(t.attrs?.source ?? "")) : "").join("").trim();
1638
+ }
1639
+ function Pn({ inline: e }) {
1640
+ let t = Z();
1641
+ return e.map((e, n) => {
1642
+ if (e.type === "image") {
1643
+ let t = String(e.attrs?.alt ?? "");
1644
+ return /* @__PURE__ */ L("span", {
1645
+ className: "text-content-muted",
1646
+ children: t ? `Image: ${t}` : "Image"
1647
+ }, n);
1648
+ }
1649
+ if (e.type === "vesperInline") return /* @__PURE__ */ L("span", {
1650
+ className: "mx-0.5 rounded-sm border border-border-strong bg-surface-sunken px-1 py-0.5 text-small",
1651
+ children: Mn(t, String(e.attrs?.source ?? ""))
1652
+ }, n);
1653
+ let r = e.text ?? "";
1654
+ for (let t of e.marks ?? []) t.type === "bold" ? r = /* @__PURE__ */ L("strong", {
1655
+ className: "font-semibold",
1656
+ children: r
1657
+ }) : t.type === "italic" ? r = /* @__PURE__ */ L("em", { children: r }) : t.type === "strike" ? r = /* @__PURE__ */ L("s", { children: r }) : t.type === "code" ? r = /* @__PURE__ */ L("code", {
1658
+ className: "font-mono text-small",
1659
+ children: r
1660
+ }) : t.type === "link" && (r = /* @__PURE__ */ L("span", {
1661
+ className: "text-accent underline",
1662
+ children: r
1663
+ }));
1664
+ return /* @__PURE__ */ L(re, { children: r }, n);
1665
+ });
1666
+ }
1667
+ var Fn = class {
1668
+ done = !1;
1669
+ changed = !1;
1670
+ linkOpen = !1;
1671
+ onFinish = () => void 0;
1672
+ openLink = () => void 0;
1673
+ update(e) {
1674
+ this.onFinish = e.onFinish, this.linkOpen = e.linkOpen, this.openLink = e.openLink;
1675
+ }
1676
+ finish(e, t) {
1677
+ return this.done || (this.done = !0, this.onFinish(this.changed ? e.getJSON().content[0]?.content ?? [] : null, t)), !0;
1678
+ }
1679
+ }, In = W.create({
1680
+ name: "doc",
1681
+ topNode: !0,
1682
+ content: "paragraph"
1683
+ });
1684
+ function Ln({ inline: e, label: t, describedBy: n, chipName: r, onFinish: i }) {
1685
+ let [a, o] = F(!1), [s] = F(() => new Fn());
1686
+ j(() => {
1687
+ s.update({
1688
+ onFinish: i,
1689
+ linkOpen: a,
1690
+ openLink: () => {
1691
+ o(!0);
1692
+ }
1693
+ });
1694
+ });
1695
+ let [c] = F(() => [
1696
+ In,
1697
+ De.configure({
1698
+ document: !1,
1699
+ heading: !1,
1700
+ blockquote: !1,
1701
+ codeBlock: !1,
1702
+ horizontalRule: !1,
1703
+ bulletList: !1,
1704
+ orderedList: !1,
1705
+ listItem: !1,
1706
+ listKeymap: !1,
1707
+ hardBreak: !1,
1708
+ underline: !1,
1709
+ trailingNode: !1,
1710
+ link: {
1711
+ openOnClick: !1,
1712
+ autolink: !0,
1713
+ defaultProtocol: "https"
1714
+ }
1715
+ }),
1716
+ ve.configure({ inline: !0 }),
1717
+ Dt.extend({ addNodeView() {
1718
+ return ({ node: e }) => {
1719
+ let t = document.createElement("span");
1720
+ return t.className = "mx-0.5 rounded-sm border border-border-strong bg-surface-sunken px-1 py-0.5 text-small", t.textContent = r(String(e.attrs.source)), { dom: t };
1721
+ };
1722
+ } }),
1723
+ ye,
1724
+ U.create({
1725
+ name: "vesperCellKeys",
1726
+ addKeyboardShortcuts() {
1727
+ let e = this.editor;
1728
+ return {
1729
+ Enter: () => s.finish(e, "stay"),
1730
+ "Shift-Enter": () => !0,
1731
+ Escape: () => s.finish(e, "stay"),
1732
+ Tab: () => s.finish(e, "next"),
1733
+ "Shift-Tab": () => s.finish(e, "previous"),
1734
+ "Mod-k": () => (s.openLink(), !0)
1735
+ };
1736
+ }
1737
+ }),
1738
+ U.create({
1739
+ name: "vesperCellBlur",
1740
+ onUpdate() {
1741
+ s.changed = !0;
1742
+ },
1743
+ onBlur() {
1744
+ let e = this.editor;
1745
+ setTimeout(() => {
1746
+ e.isDestroyed || e.view.hasFocus() || s.linkOpen || s.finish(e, "leave");
1747
+ }, 0);
1748
+ }
1749
+ })
1750
+ ]), l = Ee({
1751
+ immediatelyRender: !0,
1752
+ shouldRerenderOnTransaction: !1,
1753
+ extensions: c,
1754
+ content: {
1755
+ type: "doc",
1756
+ content: [{
1757
+ type: "paragraph",
1758
+ content: [...e]
1759
+ }]
1760
+ },
1761
+ editorProps: { attributes: {
1762
+ role: "textbox",
1763
+ "aria-multiline": "false",
1764
+ "aria-label": t,
1765
+ "aria-describedby": n,
1766
+ class: "vesper-body min-h-6 w-full min-w-24 text-body text-content outline-none"
1767
+ } }
1768
+ });
1769
+ return j(() => {
1770
+ let e = () => {
1771
+ l.commands.setTextSelection(l.state.doc.content.size - 1), l.view.focus();
1772
+ };
1773
+ e();
1774
+ let t = requestAnimationFrame(() => {
1775
+ !l.isDestroyed && !s.done && !l.view.hasFocus() && e();
1776
+ });
1777
+ return () => {
1778
+ cancelAnimationFrame(t);
1779
+ };
1780
+ }, [l, s]), /* @__PURE__ */ R(I, { children: [/* @__PURE__ */ L(we, { editor: l }), /* @__PURE__ */ L(dr, {
1781
+ editor: l,
1782
+ isOpen: a,
1783
+ onOpenChange: (e) => {
1784
+ o(e);
1785
+ }
1786
+ })] });
1787
+ }
1788
+ function Rn({ node: e, getPos: t, selected: n, editor: r }) {
1789
+ let i = Z(), a = e.attrs.value, o = e.attrs.vesperBlock ?? null, s = r.markdown, c = a.rows.length, l = a.columns.length, u = M(), d = M(), f = M(), [p, m] = F({
1790
+ row: 0,
1791
+ col: 0
1792
+ }), [h, ee] = F(null), [g, _] = F(null), [v, b] = F(!1), [x, C] = F(null), w = P(/* @__PURE__ */ new Map()), T = {
1793
+ row: Math.min(p.row, c - 1),
1794
+ col: Math.min(p.col, l - 1)
1795
+ }, D = P({
1796
+ at: T,
1797
+ editing: h
1798
+ });
1799
+ j(() => {
1800
+ D.current = {
1801
+ at: T,
1802
+ editing: h
1803
+ };
1804
+ });
1805
+ let O = N(() => a.rows.map((e) => e.cells.map((e) => Qe(s, e) ?? [])), [a, s]), re = (O[0] ?? []).map((e, t) => Nn(i, e) || `column ${String(t + 1)}`), k = (e) => re[e] ?? `column ${String(e + 1)}`, A = () => {
1806
+ setTimeout(() => {
1807
+ let { at: e, editing: t } = D.current;
1808
+ t || w.current.get(`${String(e.row)}:${String(e.col)}`)?.focus();
1809
+ }, 0);
1810
+ }, I = (e, t, n = a) => {
1811
+ let r = {
1812
+ row: Math.max(0, Math.min(n.rows.length - 1, e)),
1813
+ col: Math.max(0, Math.min(n.columns.length - 1, t))
1814
+ };
1815
+ D.current = {
1816
+ ...D.current,
1817
+ at: r
1818
+ }, m(r), A();
1819
+ }, z = (e) => {
1820
+ D.current = {
1821
+ at: e ?? D.current.at,
1822
+ editing: e
1823
+ }, e && m(e), ee(e);
1824
+ };
1825
+ j(() => {
1826
+ i.takeNewTable() && z({
1827
+ row: 0,
1828
+ col: 0
1829
+ });
1830
+ }, []);
1831
+ let B = (e, n) => {
1832
+ let a = i.checkTable(o, e);
1833
+ if (!a.ok) return C(a.reason), i.announce(a.reason), !1;
1834
+ let s = t(), c = typeof s == "number" ? r.state.doc.nodeAt(s) : null;
1835
+ return typeof s != "number" || c?.type.name !== "vesperTable" ? !1 : (C(null), r.view.dispatch(ke(r.state.tr.setNodeMarkup(s, void 0, {
1836
+ ...c.attrs,
1837
+ value: e
1838
+ }))), n && i.announce(n), !0);
1839
+ }, ie = () => {
1840
+ let e = t();
1841
+ typeof e == "number" && ht(r, e);
1842
+ }, V = (e) => e === 0 ? "the header row" : `row ${String(e + 1)}`, ae = (e, { row: t, col: n }) => {
1843
+ let r = k(n), i = String(t + 1);
1844
+ return e === "row-above" && t > 0 ? [
1845
+ at(a, t),
1846
+ `Row added above ${V(t)}.`,
1847
+ {
1848
+ row: t,
1849
+ col: n
1850
+ }
1851
+ ] : e === "row-below" ? [
1852
+ at(a, t + 1),
1853
+ `Row added below ${V(t)}.`,
1854
+ {
1855
+ row: t + 1,
1856
+ col: n
1857
+ }
1858
+ ] : e === "column-left" ? [
1859
+ ot(a, n),
1860
+ `Column added left of ${r}.`,
1861
+ {
1862
+ row: t,
1863
+ col: n
1864
+ }
1865
+ ] : e === "column-right" ? [
1866
+ ot(a, n + 1),
1867
+ `Column added right of ${r}.`,
1868
+ {
1869
+ row: t,
1870
+ col: n + 1
1871
+ }
1872
+ ] : e === "row-up" && t > 1 ? [
1873
+ st(a, t, t - 1),
1874
+ `Row ${i} moved up.`,
1875
+ {
1876
+ row: t - 1,
1877
+ col: n
1878
+ }
1879
+ ] : e === "row-down" && t > 0 && t < c - 1 ? [
1880
+ st(a, t, t + 1),
1881
+ `Row ${i} moved down.`,
1882
+ {
1883
+ row: t + 1,
1884
+ col: n
1885
+ }
1886
+ ] : e === "column-move-left" && n > 0 ? [
1887
+ ct(a, n, n - 1),
1888
+ `Column ${r} moved left.`,
1889
+ {
1890
+ row: t,
1891
+ col: n - 1
1892
+ }
1893
+ ] : e === "column-move-right" && n < l - 1 ? [
1894
+ ct(a, n, n + 1),
1895
+ `Column ${r} moved right.`,
1896
+ {
1897
+ row: t,
1898
+ col: n + 1
1899
+ }
1900
+ ] : e === "row-delete" && t > 0 ? [
1901
+ lt(a, t),
1902
+ `Row ${i} deleted.`,
1903
+ {
1904
+ row: t,
1905
+ col: n
1906
+ }
1907
+ ] : e === "column-delete" && l > 1 ? [
1908
+ ut(a, n),
1909
+ `Column ${r} deleted.`,
1910
+ {
1911
+ row: t,
1912
+ col: n
1913
+ }
1914
+ ] : null;
1915
+ }, H = (e) => {
1916
+ let t = ae(e, T);
1917
+ t && B(t[0], t[1]) ? I(t[2].row, t[2].col, t[0]) : I(T.row, T.col);
1918
+ }, oe = (e) => {
1919
+ let t = An.find((t) => t.id === e), { col: n } = T;
1920
+ if (!t || a.align[n] === t.align) return;
1921
+ let r = t.align === null ? "as written" : t.id === "center" ? "centre" : t.id;
1922
+ B(dt(a, n, t.align), `Column ${k(n)} aligned ${r}.`);
1923
+ }, se = (e) => (t, n) => {
1924
+ z(null);
1925
+ let r = a, o;
1926
+ if (t) {
1927
+ let n = $e(s, t), o = Qe(s, n);
1928
+ if (!o || $e(s, o) !== n) {
1929
+ let t = "That can’t be written in a table cell, so the cell wasn’t changed.";
1930
+ C(t), i.announce(t), I(e.row, e.col);
1931
+ return;
1932
+ }
1933
+ n !== a.rows[e.row]?.cells[e.col] && (r = it(r, e.row, e.col, n));
1934
+ }
1935
+ let u = e.row === c - 1 && e.col === l - 1, d = null;
1936
+ n === "next" && u ? (r = at(r, c), o = "Row added.", d = {
1937
+ row: c,
1938
+ col: 0
1939
+ }) : n === "next" ? d = e.col < l - 1 ? {
1940
+ row: e.row,
1941
+ col: e.col + 1
1942
+ } : {
1943
+ row: e.row + 1,
1944
+ col: 0
1945
+ } : n === "previous" && (d = e.col > 0 ? {
1946
+ row: e.row,
1947
+ col: e.col - 1
1948
+ } : e.row > 0 ? {
1949
+ row: e.row - 1,
1950
+ col: l - 1
1951
+ } : null), r !== a && !B(r, o) ? I(e.row, e.col) : n !== "leave" && (d ? z(d) : I(e.row, e.col));
1952
+ }, ce = (e) => {
1953
+ if (h) return;
1954
+ let { row: t, col: n } = T, a = E ? e.metaKey : e.ctrlKey, o = e.key, s = !i.disabled;
1955
+ if (e.altKey && s && o === "ArrowUp") H("row-up");
1956
+ else if (e.altKey && s && o === "ArrowDown") H("row-down");
1957
+ else if (e.altKey && s && o === "ArrowLeft") H("column-move-left");
1958
+ else if (e.altKey && s && o === "ArrowRight") H("column-move-right");
1959
+ else if (o === "ArrowUp") I(t - 1, n);
1960
+ else if (o === "ArrowDown") I(t + 1, n);
1961
+ else if (o === "ArrowLeft") I(t, n - 1);
1962
+ else if (o === "ArrowRight") I(t, n + 1);
1963
+ else if (o === "Home") I(e.ctrlKey || e.metaKey ? 0 : t, 0);
1964
+ else if (o === "End") I(e.ctrlKey || e.metaKey ? c - 1 : t, l - 1);
1965
+ else if ((o === "Enter" || o === "F2") && s) z({
1966
+ row: t,
1967
+ col: n
1968
+ });
1969
+ else if (o === "Escape") ie();
1970
+ else if ((o === "F10" && e.shiftKey || o === "ContextMenu") && s) _("cell");
1971
+ else if (a && o.toLowerCase() === "z") e.shiftKey ? r.commands.redo() : r.commands.undo();
1972
+ else if (a && o.toLowerCase() === "y") r.commands.redo();
1973
+ else return;
1974
+ e.preventDefault(), e.stopPropagation();
1975
+ }, le = [
1976
+ {
1977
+ id: "row-above",
1978
+ label: "Insert row above",
1979
+ isDisabled: T.row === 0
1980
+ },
1981
+ {
1982
+ id: "row-below",
1983
+ label: "Insert row below"
1984
+ },
1985
+ {
1986
+ id: "column-left",
1987
+ label: "Insert column left"
1988
+ },
1989
+ {
1990
+ id: "column-right",
1991
+ label: "Insert column right"
1992
+ },
1993
+ {
1994
+ id: "row-up",
1995
+ label: "Move row up",
1996
+ isDisabled: T.row <= 1
1997
+ },
1998
+ {
1999
+ id: "row-down",
2000
+ label: "Move row down",
2001
+ isDisabled: T.row === 0 || T.row === c - 1
2002
+ },
2003
+ {
2004
+ id: "column-move-left",
2005
+ label: "Move column left",
2006
+ isDisabled: T.col === 0
2007
+ },
2008
+ {
2009
+ id: "column-move-right",
2010
+ label: "Move column right",
2011
+ isDisabled: T.col === l - 1
2012
+ },
2013
+ {
2014
+ id: "row-delete",
2015
+ label: "Delete row",
2016
+ isDanger: !0,
2017
+ isDisabled: T.row === 0
2018
+ },
2019
+ {
2020
+ id: "column-delete",
2021
+ label: "Delete column",
2022
+ isDanger: !0,
2023
+ isDisabled: l <= 1
2024
+ }
2025
+ ], ue = An.find((e) => e.align === (a.align[T.col] ?? null)) ?? An[3], de = l === 1 ? "column" : "columns";
2026
+ return /* @__PURE__ */ R(K, {
2027
+ as: "div",
2028
+ role: "group",
2029
+ "aria-labelledby": u,
2030
+ "aria-describedby": x ? d : void 0,
2031
+ onFocus: () => {
2032
+ b(!0);
2033
+ },
2034
+ onBlur: (e) => {
2035
+ e.currentTarget.contains(e.relatedTarget) || b(!1);
2036
+ },
2037
+ className: S("my-3", n && kn),
2038
+ children: [
2039
+ /* @__PURE__ */ R("div", {
2040
+ "data-vesper-table-ui": "",
2041
+ className: "mb-1 flex items-center justify-between gap-2",
2042
+ children: [/* @__PURE__ */ R("p", {
2043
+ id: u,
2044
+ className: "text-label text-content-muted",
2045
+ children: [
2046
+ "Table · ",
2047
+ l,
2048
+ " ",
2049
+ de
2050
+ ]
2051
+ }), !i.disabled && /* @__PURE__ */ L(te, {
2052
+ label: "Table actions",
2053
+ trigger: /* @__PURE__ */ L(ne, {
2054
+ icon: "more",
2055
+ label: "Table actions",
2056
+ excludeFromTabOrder: !v,
2057
+ className: "size-8"
2058
+ }),
2059
+ items: le,
2060
+ onAction: H,
2061
+ choice: {
2062
+ title: "Align column",
2063
+ options: An.map((e) => ({
2064
+ id: e.id,
2065
+ label: e.label
2066
+ })),
2067
+ selected: ue?.id ?? "none",
2068
+ onChange: oe
2069
+ },
2070
+ isOpen: g !== null,
2071
+ onOpenChange: (e) => {
2072
+ let t = g;
2073
+ _(e ? t ?? "button" : null), !e && t === "cell" && A();
2074
+ }
2075
+ })]
2076
+ }),
2077
+ /* @__PURE__ */ L("div", {
2078
+ "data-vesper-table-ui": "",
2079
+ className: "overflow-x-auto rounded-md border border-border bg-surface-raised",
2080
+ children: /* @__PURE__ */ L("table", {
2081
+ role: "grid",
2082
+ "aria-label": `Table: ${re.join(", ")}`,
2083
+ "aria-rowcount": c,
2084
+ "aria-colcount": l,
2085
+ "aria-describedby": f,
2086
+ onKeyDown: ce,
2087
+ className: "w-full border-collapse text-body",
2088
+ children: [a.rows.slice(0, 1), a.rows.slice(1)].map((e, t) => {
2089
+ let n = e.map((e, n) => {
2090
+ let r = t === 0 ? n : n + 1;
2091
+ return /* @__PURE__ */ L("tr", {
2092
+ "aria-rowindex": r + 1,
2093
+ children: e.cells.map((e, t) => {
2094
+ let n = T.row === r && T.col === t, o = h?.row === r && h.col === t;
2095
+ return /* @__PURE__ */ L(r === 0 ? "th" : "td", {
2096
+ ref: (e) => {
2097
+ let n = `${String(r)}:${String(t)}`;
2098
+ e ? w.current.set(n, e) : w.current.delete(n);
2099
+ },
2100
+ role: r === 0 ? "columnheader" : "gridcell",
2101
+ "aria-colindex": t + 1,
2102
+ tabIndex: n && v && !o ? 0 : -1,
2103
+ "data-vesper-active": n ? "" : void 0,
2104
+ onFocus: (e) => {
2105
+ if (o) return;
2106
+ m({
2107
+ row: r,
2108
+ col: t
2109
+ });
2110
+ let n = window.getSelection();
2111
+ n?.anchorNode && !e.currentTarget.contains(n.anchorNode) && n.removeAllRanges();
2112
+ },
2113
+ onDoubleClick: () => {
2114
+ i.disabled || z({
2115
+ row: r,
2116
+ col: t
2117
+ });
2118
+ },
2119
+ className: S("border border-border px-3 py-2 align-top outline-none", r === 0 ? "bg-surface-sunken text-label text-content" : "text-content", jn[a.align[t] ?? ""] ?? "text-left", "focus-visible:outline-2 focus-visible:outline-solid focus-visible:-outline-offset-2 focus-visible:outline-focus", o && "outline-2 outline-solid -outline-offset-2 outline-focus"),
2120
+ children: o ? /* @__PURE__ */ L(Ln, {
2121
+ inline: O[r]?.[t] ?? [],
2122
+ label: `${k(t)}, ${V(r)}`,
2123
+ describedBy: f,
2124
+ chipName: (e) => Mn(i, e),
2125
+ onFinish: se({
2126
+ row: r,
2127
+ col: t
2128
+ })
2129
+ }) : /* @__PURE__ */ L(Pn, { inline: O[r]?.[t] ?? [] })
2130
+ }, t);
2131
+ })
2132
+ }, r);
2133
+ });
2134
+ return t === 0 ? /* @__PURE__ */ L("thead", { children: n }, "head") : /* @__PURE__ */ L("tbody", { children: n }, "body");
2135
+ })
2136
+ })
2137
+ }),
2138
+ /* @__PURE__ */ L("p", {
2139
+ id: f,
2140
+ className: "sr-only",
2141
+ children: h ? `Enter or Escape keeps the cell, Tab goes to the next. ${y("Mod", "B").text} bold, ${y("Mod", "I").text} italic, ${y("Mod", "E").text} code, ${y("Mod", "K").text} link.` : "Enter edits the cell. Shift+F10 for row and column actions. Escape returns to the text."
2142
+ }),
2143
+ x && /* @__PURE__ */ L("p", {
2144
+ id: d,
2145
+ className: "mt-2 text-small text-danger",
2146
+ children: x
2147
+ })
2148
+ ]
2149
+ });
2150
+ }
2151
+ //#endregion
2152
+ //#region src/body/views.tsx
2153
+ var zn = S("in-[.ProseMirror-focused]:outline-2 in-[.ProseMirror-focused]:outline-solid in-[.ProseMirror-focused]:outline-offset-2 in-[.ProseMirror-focused]:outline-focus", "in-[.ProseMirror-focused]:ring-6 in-[.ProseMirror-focused]:ring-(color:--glow-focus)");
2154
+ function Bn({ id: e, issues: t }) {
2155
+ return t.length === 0 ? null : /* @__PURE__ */ L("ul", {
2156
+ id: e,
2157
+ className: "mt-2 flex flex-col gap-1 text-small",
2158
+ children: t.map((e) => /* @__PURE__ */ L("li", {
2159
+ className: e.level === "error" ? "text-danger" : "text-content-muted",
2160
+ children: e.level === "error" ? e.message : `Note: ${e.message}`
2161
+ }, `${String(e.line)}${e.message}`))
2162
+ });
2163
+ }
2164
+ function Vn(e, t) {
2165
+ return t ? `${e} · ${t}` : e;
2166
+ }
2167
+ function Hn({ node: e, getPos: t, selected: n, editor: r }) {
2168
+ let i = Z(), a = M(), o = M(), s = e.attrs.syntax, c = String(e.attrs.name), l = String(e.attrs.open), u = String(e.attrs.close), d = i.catalog.find(s, c), f = d?.label ?? Y(s, c), p = d?.builtin === "if" ? `shown when ${Gn(l)}` : hn(d, Ge(s, l).values), m = mn(s === "mdx" ? `${l}\n\n${u}` : `${l}\n${u}`), h = J({
2169
+ editor: r,
2170
+ selector: ({ editor: n }) => {
2171
+ let r = t();
2172
+ if (typeof r != "number") return !1;
2173
+ let { from: i, to: a } = n.state.selection;
2174
+ return i > r && a < r + e.nodeSize;
2175
+ }
2176
+ });
2177
+ return /* @__PURE__ */ R(K, {
2178
+ as: "div",
2179
+ role: "group",
2180
+ "aria-labelledby": a,
2181
+ "aria-describedby": m.length > 0 ? o : void 0,
2182
+ className: S("my-3 rounded-md border border-border p-3", m.some((e) => e.level === "error") && "border-danger", n && zn),
2183
+ children: [
2184
+ /* @__PURE__ */ R("div", {
2185
+ contentEditable: !1,
2186
+ className: "mb-2 flex items-center justify-between gap-2",
2187
+ children: [/* @__PURE__ */ L("p", {
2188
+ id: a,
2189
+ className: "text-label text-content-muted",
2190
+ children: Vn(f, p)
2191
+ }), /* @__PURE__ */ L(Un, {
2192
+ label: f,
2193
+ getPos: t,
2194
+ inTabOrder: h
2195
+ })]
2196
+ }),
2197
+ /* @__PURE__ */ L(Te, { className: "vesper-container-content" }),
2198
+ /* @__PURE__ */ L("div", {
2199
+ contentEditable: !1,
2200
+ children: /* @__PURE__ */ L(Bn, {
2201
+ id: o,
2202
+ issues: m
2203
+ })
2204
+ })
2205
+ ]
2206
+ });
2207
+ }
2208
+ function Un({ label: e, getPos: t, inTabOrder: n }) {
2209
+ let r = Z();
2210
+ return /* @__PURE__ */ L(T, {
2211
+ variant: "quiet",
2212
+ excludeFromTabOrder: !n,
2213
+ "aria-label": `Settings for ${e}`,
2214
+ isDisabled: r.disabled,
2215
+ onPress: () => {
2216
+ let e = t();
2217
+ typeof e == "number" && r.openSettings(e);
2218
+ },
2219
+ className: "min-h-8 px-2 text-small",
2220
+ children: "Settings"
2221
+ });
2222
+ }
2223
+ function Wn({ node: e, getPos: t, selected: n }) {
2224
+ let r = Z(), i = M(), a = M(), o = e.attrs.syntax, s = String(e.attrs.name), c = String(e.attrs.source), l = r.catalog.find(o, s), u = l?.label ?? Y(o, s), d = l?.builtin === "else" ? Gn(c) : l?.builtin === "if" ? "" : hn(l, Ge(o, c).values), f = mn(c);
2225
+ return /* @__PURE__ */ R(K, {
2226
+ as: "div",
2227
+ contentEditable: !1,
2228
+ role: "group",
2229
+ "aria-labelledby": i,
2230
+ "aria-describedby": f.length > 0 ? a : void 0,
2231
+ className: S("my-3 rounded-md border border-border bg-surface p-3", f.some((e) => e.level === "error") && "border-danger", n && zn),
2232
+ children: [/* @__PURE__ */ R("div", {
2233
+ className: "flex items-center justify-between gap-2",
2234
+ children: [/* @__PURE__ */ L("p", {
2235
+ id: i,
2236
+ className: "text-label text-content",
2237
+ children: Vn(u, d)
2238
+ }), /* @__PURE__ */ L(Un, {
2239
+ label: u,
2240
+ getPos: t,
2241
+ inTabOrder: !1
2242
+ })]
2243
+ }), /* @__PURE__ */ L(Bn, {
2244
+ id: a,
2245
+ issues: f
2246
+ })]
2247
+ });
2248
+ }
2249
+ function Gn(e) {
2250
+ return e.replace(/^\{%\s*(if|else)\b/, "").replace(/\/?%\}$/, "").trim();
2251
+ }
2252
+ function Kn({ node: e, selected: t }) {
2253
+ let n = Z(), r = String(e.attrs.source), i = Je(r), a = i.name ? n.catalog.find(i.syntax, i.name) : void 0, o = i.kind === "tag" || i.kind === "component", s = mn(o ? r : "").filter((e) => e.level === "error"), c = a && o, l = c ? Vn(a.label, qn(i.inner) || hn(a, Ge(i.syntax, i.open ?? "").values)) : r.length > 80 ? `${r.slice(0, 77)}…` : r;
2254
+ return /* @__PURE__ */ R(K, {
2255
+ as: "span",
2256
+ className: S("mx-0.5 rounded-sm border border-border-strong bg-surface-sunken px-1 py-0.5 text-small", !c && "font-mono", s.length > 0 && "border-danger", t && zn),
2257
+ children: [l, s.length > 0 && /* @__PURE__ */ R("span", {
2258
+ className: "text-danger",
2259
+ children: [
2260
+ " (",
2261
+ s.map((e) => e.message).join(" "),
2262
+ ")"
2263
+ ]
2264
+ })]
2265
+ });
2266
+ }
2267
+ function qn(e) {
2268
+ return !e || /[{<*_`[\]\\]/.test(e) ? "" : e;
2269
+ }
2270
+ function Jn({ node: e, getPos: t, selected: n }) {
2271
+ let r = Z(), i = String(e.attrs.text ?? "").split("\n"), a = Jt(String(e.attrs.blockType ?? ""));
2272
+ return /* @__PURE__ */ R(K, {
2273
+ as: "div",
2274
+ contentEditable: !1,
2275
+ className: S("my-3 rounded-md border border-dashed border-border-strong bg-surface-sunken p-3", n && zn),
2276
+ children: [/* @__PURE__ */ R("div", {
2277
+ className: "mb-1 flex items-center justify-between gap-2",
2278
+ children: [/* @__PURE__ */ R("p", {
2279
+ className: "text-label text-content-muted",
2280
+ children: [a, ", kept as written."]
2281
+ }), /* @__PURE__ */ L(T, {
2282
+ variant: "quiet",
2283
+ excludeFromTabOrder: !0,
2284
+ "aria-label": `Edit as text: ${a}`,
2285
+ isDisabled: r.disabled,
2286
+ onPress: () => {
2287
+ let e = t();
2288
+ typeof e == "number" && r.openSettings(e);
2289
+ },
2290
+ className: "min-h-8 px-2 text-small",
2291
+ children: "Edit as text"
2292
+ })]
2293
+ }), /* @__PURE__ */ R("pre", {
2294
+ className: "overflow-x-auto font-mono text-small whitespace-pre-wrap text-content",
2295
+ children: [i.slice(0, 6).join("\n"), i.length > 6 ? `\n… ${String(i.length - 6)} more lines` : ""]
2296
+ })]
2297
+ });
2298
+ }
2299
+ //#endregion
2300
+ //#region src/body/BodyEditor.tsx
2301
+ var Yn = {
2302
+ md: "Markdown",
2303
+ mdx: "MDX",
2304
+ mdoc: "Markdoc"
2305
+ };
2306
+ function Xn(e) {
2307
+ let [t, n] = F("writing"), [r, i] = F(0), a = Yn[e.format], o = (e.issues ?? []).filter((e) => e.level === "error"), s = e.notes ?? [], c = P(null), l = P(t);
2308
+ j(() => {
2309
+ l.current = t;
2310
+ }, [t]);
2311
+ let u = (e) => {
2312
+ if (e.target.kind !== "body") return;
2313
+ let t = document.getElementById("entry-body");
2314
+ l.current === "source" && t instanceof HTMLTextAreaElement ? cn(t, e.target.start, e.target.end) : c.current?.(e.target.start);
2315
+ }, d = P(u);
2316
+ j(() => {
2317
+ d.current = u;
2318
+ });
2319
+ let { apiRef: f } = e;
2320
+ return j(() => {
2321
+ if (f) return f.current = { reveal: (e) => {
2322
+ d.current(e);
2323
+ } }, () => {
2324
+ f.current = null;
2325
+ };
2326
+ }, [f]), /* @__PURE__ */ R("section", {
2327
+ "aria-labelledby": "entry-body-label",
2328
+ className: "flex flex-col gap-2",
2329
+ children: [
2330
+ /* @__PURE__ */ R("div", {
2331
+ className: "flex flex-wrap items-center justify-between gap-2",
2332
+ children: [/* @__PURE__ */ L("span", {
2333
+ id: "entry-body-label",
2334
+ className: "text-label text-content",
2335
+ children: "Body"
2336
+ }), /* @__PURE__ */ L(T, {
2337
+ variant: "quiet",
2338
+ onPress: () => {
2339
+ t === "source" && i((e) => e + 1), n(t === "writing" ? "source" : "writing");
2340
+ },
2341
+ children: t === "writing" ? `Edit as ${a}` : "Back to the writing view"
2342
+ })]
2343
+ }),
2344
+ t === "writing" ? /* @__PURE__ */ L(cr, {
2345
+ ...e,
2346
+ revealRef: c
2347
+ }, r) : /* @__PURE__ */ R(I, { children: [
2348
+ /* @__PURE__ */ L("textarea", {
2349
+ id: "entry-body",
2350
+ "aria-labelledby": "entry-body-label",
2351
+ "aria-describedby": S("entry-body-source-help", o.length > 0 && "entry-body-issues"),
2352
+ "aria-invalid": o.length > 0 || void 0,
2353
+ value: e.value,
2354
+ onChange: (t) => {
2355
+ e.onChange(t.target.value);
2356
+ },
2357
+ rows: 20,
2358
+ spellCheck: !1,
2359
+ disabled: e.disabled,
2360
+ className: S(D, "resize-y font-mono text-small leading-relaxed")
2361
+ }),
2362
+ /* @__PURE__ */ R("p", {
2363
+ id: "entry-body-source-help",
2364
+ className: "text-small text-content-muted",
2365
+ children: [
2366
+ "The whole body as ",
2367
+ a,
2368
+ ", exactly as it’s saved."
2369
+ ]
2370
+ }),
2371
+ o.length > 0 && /* @__PURE__ */ L("ul", {
2372
+ id: "entry-body-issues",
2373
+ className: "flex flex-col gap-1 text-small text-danger",
2374
+ children: o.map((e) => /* @__PURE__ */ R("li", { children: [
2375
+ "Line ",
2376
+ e.line,
2377
+ ": ",
2378
+ e.message
2379
+ ] }, `${String(e.line)}${e.message}`))
2380
+ })
2381
+ ] }),
2382
+ /* @__PURE__ */ L(Zn, {
2383
+ notes: s,
2384
+ lines: t === "source",
2385
+ onShow: u
2386
+ })
2387
+ ]
2388
+ });
2389
+ }
2390
+ function Zn({ notes: e, lines: t, onShow: n }) {
2391
+ return e.length === 0 ? null : /* @__PURE__ */ R("div", {
2392
+ className: "flex flex-col gap-2",
2393
+ children: [/* @__PURE__ */ L("p", {
2394
+ id: "entry-body-a11y-label",
2395
+ className: "text-label text-content",
2396
+ children: "Accessibility notes in the body"
2397
+ }), /* @__PURE__ */ L("ul", {
2398
+ "aria-labelledby": "entry-body-a11y-label",
2399
+ className: "m-0 flex list-none flex-col gap-2 p-0",
2400
+ children: e.map((e, r) => {
2401
+ let i = `entry-body-a11y-${String(r)}`;
2402
+ return /* @__PURE__ */ R("li", {
2403
+ className: "flex flex-wrap items-start justify-between gap-2 text-small text-content",
2404
+ children: [/* @__PURE__ */ R("p", {
2405
+ id: i,
2406
+ className: "m-0 flex min-w-0 flex-1 gap-2",
2407
+ children: [/* @__PURE__ */ L(ee, {
2408
+ name: "warning",
2409
+ size: 16,
2410
+ className: "mt-0.5 text-warning"
2411
+ }), /* @__PURE__ */ R("span", { children: [t && e.target.kind === "body" ? `Line ${String(e.target.line)}. ` : "", /* @__PURE__ */ L(v, { note: e })] })]
2412
+ }), /* @__PURE__ */ L(T, {
2413
+ variant: "quiet",
2414
+ "aria-describedby": i,
2415
+ onPress: () => {
2416
+ n(e);
2417
+ },
2418
+ children: "Show"
2419
+ })]
2420
+ }, i);
2421
+ })
2422
+ })]
2423
+ });
2424
+ }
2425
+ var Qn = wt.extend({ addNodeView() {
2426
+ return q(Jn);
2427
+ } }), $n = Tt.extend({ addNodeView() {
2428
+ return q(Wn);
2429
+ } }), er = Dt.extend({ addNodeView() {
2430
+ return q(Kn, { as: "span" });
2431
+ } }), tr = Et.extend({ addNodeView() {
2432
+ return q(Rn, { stopEvent: ({ event: e }) => e.target instanceof Element && e.target.closest("[data-vesper-table-ui]") !== null });
2433
+ } }), nr = class {
2434
+ actions = {
2435
+ open: () => void 0,
2436
+ insert: () => void 0,
2437
+ disabled: !0
2438
+ };
2439
+ update(e) {
2440
+ this.actions = e;
2441
+ }
2442
+ };
2443
+ function rr(e) {
2444
+ let { containers: t, actions: n } = e, r = (e, r) => {
2445
+ if (n().disabled) return !1;
2446
+ let i = pt(e, t), a = i && i.type !== "vesperInline" ? i.pos : mt(e, t);
2447
+ return a !== null && (gt(e, a, r), !0);
2448
+ };
2449
+ return U.create({
2450
+ name: "vesperShortcuts",
2451
+ addKeyboardShortcuts() {
2452
+ let i = this.editor;
2453
+ return {
2454
+ "Mod-k": () => (e.onLink(), !0),
2455
+ Escape: () => {
2456
+ if (!pt(i, t)) {
2457
+ let e = mt(i, t);
2458
+ if (e !== null) return ht(i, e), !0;
2459
+ }
2460
+ return i.view.dom.closest("[data-vesper-body]")?.querySelector("[role=\"toolbar\"] button")?.focus(), !0;
2461
+ },
2462
+ Enter: () => {
2463
+ let e = pt(i, t);
2464
+ return !e || n().disabled ? !1 : (n().open(e.pos), !0);
2465
+ },
2466
+ "Alt-ArrowUp": () => r(i, -1),
2467
+ "Alt-ArrowDown": () => r(i, 1),
2468
+ [E ? "Mod-ArrowUp" : "Mod-Home"]: () => ir(i, "start"),
2469
+ [E ? "Mod-ArrowDown" : "Mod-End"]: () => ir(i, "end")
2470
+ };
2471
+ },
2472
+ addProseMirrorPlugins() {
2473
+ return [new be({ props: { handleDOMEvents: { keydown: (e, t) => ar(e, t) } } })];
2474
+ }
2475
+ });
2476
+ }
2477
+ function ir(e, t) {
2478
+ let { doc: n } = e.state, r = t === "start" ? Se.atStart(n) : Se.atEnd(n);
2479
+ return e.view.dispatch(e.state.tr.setSelection(r).scrollIntoView()), !0;
2480
+ }
2481
+ function ar(e, t) {
2482
+ if (!E || !t.shiftKey || !t.metaKey || t.altKey || t.ctrlKey || t.key !== "ArrowLeft" && t.key !== "ArrowRight") return !1;
2483
+ let { selection: n } = e.state;
2484
+ if (!(n instanceof Ce)) return !1;
2485
+ let r = t.key === "ArrowLeft" == (getComputedStyle(e.dom).direction === "rtl") ? n.$head.nodeAfter : n.$head.nodeBefore;
2486
+ return r !== null && !r.isText && r.isLeaf;
2487
+ }
2488
+ function or(e) {
2489
+ (e.querySelector("[data-vesper-active]") ?? e.querySelector("[role=\"grid\"] [aria-colindex]"))?.focus();
2490
+ }
2491
+ function sr(e, t) {
2492
+ if (!e.isFocused) return "";
2493
+ let n = pt(e, t.containers);
2494
+ if (!n) return "";
2495
+ let r = e.state.doc.nodeAt(n.pos);
2496
+ if (!r) return "";
2497
+ if (r.type.name === "vesperTable") {
2498
+ let e = r.attrs.value, t = e.columns.length, n = e.rows.length;
2499
+ return `Table, ${String(t)} ${t === 1 ? "column" : "columns"} and ${String(n)} ${n === 1 ? "row" : "rows"}, selected. Press Enter to edit its cells.`;
2500
+ }
2501
+ let i;
2502
+ if (r.type.name === "sourceBlock") i = Jt(String(r.attrs.blockType ?? ""));
2503
+ else if (r.type.name === "vesperInline") {
2504
+ let e = Je(String(r.attrs.source));
2505
+ i = (e.name ? t.catalog.find(e.syntax, e.name) : void 0)?.label ?? (e.kind === "variable" ? "Variable" : e.kind === "annotation" ? "Annotation" : "Tag");
2506
+ } else {
2507
+ let e = r.attrs.syntax, n = String(r.attrs.name);
2508
+ i = t.catalog.find(e, n)?.label ?? Y(e, n);
2509
+ }
2510
+ return `${i} selected. Press Enter for its settings.`;
2511
+ }
2512
+ function cr({ value: t, onChange: n, format: r, disabled: a, entryPath: o, imageFolder: s, partials: c = null, headingStart: l = 2, revealRef: u }) {
2513
+ let { manifest: d, loadMdxProps: f } = i(), h = P(null), ee = P(n);
2514
+ j(() => {
2515
+ ee.current = n;
2516
+ });
2517
+ let [g, _] = F(!1), v = P(null), [y, te] = F(!1), [b, x] = F(null), C = p(b), [w, T] = F(null), E = rn(), [ne, D] = F(""), O = P(!1), [re] = F(() => {
2518
+ let e = je(d, r);
2519
+ return {
2520
+ catalog: e,
2521
+ containers: kt(e)
2522
+ };
2523
+ }), { catalog: k, containers: A } = re, [M] = F(() => new nr()), [I] = F(() => {
2524
+ let e = (e) => Yt(e, k, A);
2525
+ return [
2526
+ De.configure({
2527
+ underline: !1,
2528
+ trailingNode: !1,
2529
+ link: {
2530
+ openOnClick: !1,
2531
+ autolink: !0,
2532
+ defaultProtocol: "https"
2533
+ }
2534
+ }),
2535
+ ve.configure({ inline: !0 }),
2536
+ ye,
2537
+ Ct,
2538
+ Qn,
2539
+ $n,
2540
+ er,
2541
+ tr,
2542
+ ...A.extensions.map((e) => e.extend({ addNodeView() {
2543
+ return q(Hn);
2544
+ } })),
2545
+ Qt({
2546
+ ...E,
2547
+ choices: e,
2548
+ choose: (e, t) => {
2549
+ M.actions.insert(e, t);
2550
+ },
2551
+ disabled: () => M.actions.disabled
2552
+ }),
2553
+ rr({
2554
+ containers: A,
2555
+ actions: () => M.actions,
2556
+ onLink: () => {
2557
+ _(!0);
2558
+ }
2559
+ })
2560
+ ];
2561
+ }), B = Ee({
2562
+ immediatelyRender: !0,
2563
+ shouldRerenderOnTransaction: !1,
2564
+ editable: !a,
2565
+ extensions: I,
2566
+ editorProps: {
2567
+ handleScrollToSelection: (e) => dn(e, v.current),
2568
+ attributes: (e) => ({
2569
+ id: "entry-body",
2570
+ "aria-labelledby": "entry-body-label",
2571
+ "aria-describedby": "entry-body-help",
2572
+ class: "vesper-body min-h-72 resize-y overflow-y-auto px-4 py-3 text-body outline-none",
2573
+ ...$t(e, {
2574
+ ...E,
2575
+ count: (t) => Zt(Yt(e, k, A), t).length
2576
+ })
2577
+ })
2578
+ },
2579
+ onCreate: ({ editor: e }) => {
2580
+ let n = jt(t, {
2581
+ format: r,
2582
+ markdown: e.markdown,
2583
+ catalog: k,
2584
+ containers: A,
2585
+ ...d.markdoc ? { markdoc: d.markdoc.options } : {}
2586
+ });
2587
+ e.commands.setContent(n.doc, { emitUpdate: !1 });
2588
+ let i = Se.findFrom(e.state.doc.resolve(0), 1, !0);
2589
+ i && e.view.dispatch(e.state.tr.setSelection(i)), h.current = {
2590
+ built: n,
2591
+ initial: zt(e.getJSON(), A)
2592
+ };
2593
+ },
2594
+ onUpdate: ({ editor: e }) => {
2595
+ if (!h.current) return;
2596
+ let t = Vt(e.getJSON(), h.current.initial, {
2597
+ markdown: e.markdown,
2598
+ containers: A,
2599
+ parsed: h.current.built.parsed,
2600
+ format: r,
2601
+ ...d.markdoc ? { markdoc: d.markdoc.options } : {}
2602
+ });
2603
+ ee.current(z(h.current.built.parsed, t));
2604
+ }
2605
+ });
2606
+ function ie(e, t) {
2607
+ O.current = e.kind.builtin === "table";
2608
+ let n = bt(B, e.kind, e.shape, A, t, V(e));
2609
+ n !== null && (e.kind.fields.length > 0 || e.shape === "inline") && T(n);
2610
+ }
2611
+ function V(e) {
2612
+ if (e.kind.builtin !== "partial") return {};
2613
+ let [t] = wn(c ?? [], o);
2614
+ return t ? { file: Tn(o, t) } : {};
2615
+ }
2616
+ j(() => {
2617
+ M.update({
2618
+ open: (e) => {
2619
+ if (B.state.doc.nodeAt(e)?.type.name === "vesperTable") {
2620
+ let t = B.view.nodeDOM(e);
2621
+ t instanceof HTMLElement && or(t);
2622
+ } else T(e);
2623
+ },
2624
+ insert: ie,
2625
+ disabled: a
2626
+ });
2627
+ });
2628
+ let ae = N(() => e({
2629
+ manifest: d,
2630
+ format: r,
2631
+ loadMdxProps: f,
2632
+ partials: c,
2633
+ entryPath: o
2634
+ }), [
2635
+ d,
2636
+ r,
2637
+ f,
2638
+ c,
2639
+ o
2640
+ ]), H = N(() => ({
2641
+ catalog: k,
2642
+ containers: A,
2643
+ disabled: a,
2644
+ checks: ae,
2645
+ partials: c,
2646
+ entryPath: o,
2647
+ openSettings: (e) => {
2648
+ T(e);
2649
+ },
2650
+ move: (e, t) => {
2651
+ let n = gt(B, e, t);
2652
+ n !== null && T((e) => e === null ? null : n);
2653
+ },
2654
+ remove: (e) => {
2655
+ _t(B, e);
2656
+ },
2657
+ announce: (e) => {
2658
+ D((t) => t === e ? `${e}\u00a0` : e);
2659
+ },
2660
+ checkTable: (e, t) => Kt(e, t, {
2661
+ markdown: B.markdown,
2662
+ containers: A,
2663
+ format: r,
2664
+ ...h.current ? { parsed: h.current.built.parsed } : {},
2665
+ ...d.markdoc ? { markdoc: d.markdoc.options } : {}
2666
+ }),
2667
+ takeNewTable: () => {
2668
+ let e = O.current;
2669
+ return O.current = !1, e;
2670
+ }
2671
+ }), [
2672
+ k,
2673
+ A,
2674
+ a,
2675
+ ae,
2676
+ c,
2677
+ o,
2678
+ B,
2679
+ r,
2680
+ d.markdoc
2681
+ ]), oe = P(t);
2682
+ j(() => {
2683
+ oe.current = t;
2684
+ }), j(() => (u.current = (e) => {
2685
+ sn(B, oe.current, e, {
2686
+ format: r,
2687
+ containers: A,
2688
+ ...d.markdoc ? { markdoc: d.markdoc.options } : {}
2689
+ });
2690
+ }, () => {
2691
+ u.current = null;
2692
+ }), [
2693
+ B,
2694
+ r,
2695
+ A,
2696
+ d.markdoc,
2697
+ u
2698
+ ]);
2699
+ let se = J({
2700
+ editor: B,
2701
+ selector: ({ editor: e }) => sr(e, {
2702
+ catalog: k,
2703
+ containers: A
2704
+ })
2705
+ }), ce = k.kinds.size > 0;
2706
+ return /* @__PURE__ */ L(pn.Provider, {
2707
+ value: H,
2708
+ children: /* @__PURE__ */ R("div", {
2709
+ "data-vesper-body": "",
2710
+ className: "flex flex-col gap-2",
2711
+ children: [
2712
+ /* @__PURE__ */ R("div", {
2713
+ className: S("rounded-md border border-border-strong bg-surface-raised", "has-[#entry-body:focus-visible]:outline-2 has-[#entry-body:focus-visible]:outline-solid has-[#entry-body:focus-visible]:outline-offset-2 has-[#entry-body:focus-visible]:outline-focus", "has-[#entry-body:focus-visible]:ring-6 has-[#entry-body:focus-visible]:ring-(color:--glow-focus)"),
2714
+ children: [/* @__PURE__ */ L("div", {
2715
+ ref: v,
2716
+ className: ln,
2717
+ children: /* @__PURE__ */ L(lr, {
2718
+ editor: B,
2719
+ disabled: a,
2720
+ headingStart: l,
2721
+ onLink: () => {
2722
+ _(!0);
2723
+ },
2724
+ onImage: () => {
2725
+ te(!0);
2726
+ },
2727
+ insert: /* @__PURE__ */ L(nn, {
2728
+ editor: B,
2729
+ choices: (e) => Yt(e, k, A),
2730
+ onChoose: (e) => {
2731
+ ie(e);
2732
+ },
2733
+ disabled: a
2734
+ })
2735
+ })
2736
+ }), /* @__PURE__ */ L(we, { editor: B })]
2737
+ }),
2738
+ /* @__PURE__ */ L(en, {
2739
+ editor: B,
2740
+ ...E,
2741
+ choices: (e) => Yt(e, k, A),
2742
+ onChoose: (e, t) => {
2743
+ ie(e, t);
2744
+ }
2745
+ }),
2746
+ /* @__PURE__ */ L("p", {
2747
+ className: "sr-only",
2748
+ role: "status",
2749
+ children: se
2750
+ }),
2751
+ /* @__PURE__ */ L("div", {
2752
+ className: "sr-only",
2753
+ role: "status",
2754
+ children: ne
2755
+ }),
2756
+ /* @__PURE__ */ R("p", {
2757
+ id: "entry-body-help",
2758
+ className: "text-small text-content-muted",
2759
+ children: [
2760
+ "Ctrl+B bold, Ctrl+I italic, Ctrl+K link.",
2761
+ ce ? " Type / to insert a block or a table. Arrow onto a block and press Enter for its settings, or onto a table for its cells; Alt+↑ and Alt+↓ move it." : " Type / to insert a table. Arrow onto a table and press Enter for its cells; Alt+↑ and Alt+↓ move it.",
2762
+ " ",
2763
+ "Escape leaves a block, then the text. Dashed boxes are kept exactly as written."
2764
+ ]
2765
+ }),
2766
+ /* @__PURE__ */ L(gn, {
2767
+ editor: B,
2768
+ pos: w,
2769
+ onClose: () => {
2770
+ let e = w;
2771
+ T(null);
2772
+ let t = B.view.dom, n = !1, r = () => {
2773
+ if (n || B.isDestroyed) return;
2774
+ n = !0, t.removeEventListener("focusin", i), B.view.focus();
2775
+ let r = e === null ? null : B.state.doc.nodeAt(e);
2776
+ e !== null && r && ft(r.type.name, A) && B.view.dispatch(B.state.tr.setSelection(G.create(B.state.doc, e)));
2777
+ }, i = () => setTimeout(r, 0);
2778
+ t.addEventListener("focusin", i), setTimeout(r, 500);
2779
+ }
2780
+ }),
2781
+ /* @__PURE__ */ L(dr, {
2782
+ editor: B,
2783
+ isOpen: g,
2784
+ onOpenChange: _
2785
+ }),
2786
+ /* @__PURE__ */ L(m, {
2787
+ isOpen: y,
2788
+ onOpenChange: te,
2789
+ kind: "image",
2790
+ folder: s,
2791
+ onChoose: (e) => {
2792
+ x(e);
2793
+ }
2794
+ }),
2795
+ /* @__PURE__ */ L(pr, {
2796
+ path: b,
2797
+ previewUrl: C,
2798
+ onCancel: () => {
2799
+ x(null), B.commands.focus();
2800
+ },
2801
+ onInsert: (e) => {
2802
+ b && (B.chain().focus().setImage({
2803
+ src: me(b, o),
2804
+ alt: e
2805
+ }).run(), x(null));
2806
+ }
2807
+ })
2808
+ ]
2809
+ })
2810
+ });
2811
+ }
2812
+ function lr({ editor: e, disabled: t, headingStart: r, onLink: i, onImage: a, insert: o }) {
2813
+ let s = J({
2814
+ editor: e,
2815
+ selector: ({ editor: e }) => ({
2816
+ bold: e.isActive("bold"),
2817
+ italic: e.isActive("italic"),
2818
+ code: e.isActive("code"),
2819
+ level: e.isActive("heading") ? Number(e.getAttributes("heading").level) : 0,
2820
+ bullets: e.isActive("bulletList"),
2821
+ numbers: e.isActive("orderedList"),
2822
+ quote: e.isActive("blockquote"),
2823
+ link: e.isActive("link")
2824
+ })
2825
+ }), l = () => e.chain().focus();
2826
+ return /* @__PURE__ */ R(n, {
2827
+ label: "Formatting",
2828
+ children: [
2829
+ /* @__PURE__ */ L(c, {
2830
+ icon: "bold",
2831
+ label: "Bold",
2832
+ shortcut: y("Mod", "B"),
2833
+ isDisabled: t,
2834
+ isSelected: s.bold,
2835
+ onChange: () => l().toggleBold().run()
2836
+ }),
2837
+ /* @__PURE__ */ L(c, {
2838
+ icon: "italic",
2839
+ label: "Italic",
2840
+ shortcut: y("Mod", "I"),
2841
+ isDisabled: t,
2842
+ isSelected: s.italic,
2843
+ onChange: () => l().toggleItalic().run()
2844
+ }),
2845
+ /* @__PURE__ */ L(u, {}),
2846
+ /* @__PURE__ */ L(ur, {
2847
+ editor: e,
2848
+ level: s.level,
2849
+ start: r,
2850
+ disabled: t
2851
+ }),
2852
+ /* @__PURE__ */ L(u, {}),
2853
+ /* @__PURE__ */ L(c, {
2854
+ icon: "bullets",
2855
+ label: "Bullets",
2856
+ shortcut: y("Mod", "Shift", "8"),
2857
+ isDisabled: t,
2858
+ isSelected: s.bullets,
2859
+ onChange: () => l().toggleBulletList().run()
2860
+ }),
2861
+ /* @__PURE__ */ L(c, {
2862
+ icon: "numbers",
2863
+ label: "Numbers",
2864
+ shortcut: y("Mod", "Shift", "7"),
2865
+ isDisabled: t,
2866
+ isSelected: s.numbers,
2867
+ onChange: () => l().toggleOrderedList().run()
2868
+ }),
2869
+ /* @__PURE__ */ L(c, {
2870
+ icon: "quote",
2871
+ label: "Quote",
2872
+ shortcut: y("Mod", "Shift", "B"),
2873
+ isDisabled: t,
2874
+ isSelected: s.quote,
2875
+ onChange: () => l().toggleBlockquote().run()
2876
+ }),
2877
+ /* @__PURE__ */ L(c, {
2878
+ icon: "code",
2879
+ label: "Code",
2880
+ shortcut: y("Mod", "E"),
2881
+ isDisabled: t,
2882
+ isSelected: s.code,
2883
+ onChange: () => l().toggleCode().run()
2884
+ }),
2885
+ /* @__PURE__ */ L(u, {}),
2886
+ /* @__PURE__ */ L(O, {
2887
+ icon: "link",
2888
+ label: s.link ? "Edit link" : "Link",
2889
+ shortcut: y("Mod", "K"),
2890
+ isDisabled: t,
2891
+ onPress: i
2892
+ }),
2893
+ /* @__PURE__ */ L(O, {
2894
+ icon: "image",
2895
+ label: "Image",
2896
+ isDisabled: t,
2897
+ onPress: a
2898
+ }),
2899
+ o
2900
+ ]
2901
+ });
2902
+ }
2903
+ function ur({ editor: e, level: n, start: r, disabled: i }) {
2904
+ let a = n === 0 ? "Paragraph" : `Heading ${String(n)}`, o = [{
2905
+ id: "0",
2906
+ label: "Paragraph"
2907
+ }, ...[
2908
+ 1,
2909
+ 2,
2910
+ 3,
2911
+ 4,
2912
+ 5,
2913
+ 6
2914
+ ].filter((e) => e >= Math.min(r, 6)).map((e) => ({
2915
+ id: String(e),
2916
+ label: `Heading ${String(e)}`
2917
+ }))];
2918
+ return /* @__PURE__ */ L(te, {
2919
+ label: "Text style",
2920
+ items: [],
2921
+ onAction: () => void 0,
2922
+ trigger: /* @__PURE__ */ R(O, {
2923
+ "aria-label": `Text style: ${a}`,
2924
+ isDisabled: i,
2925
+ className: "w-28 gap-1",
2926
+ children: [/* @__PURE__ */ L("span", {
2927
+ className: "min-w-0 flex-1 truncate text-left",
2928
+ children: a
2929
+ }), /* @__PURE__ */ L(t, {})]
2930
+ }),
2931
+ choice: {
2932
+ title: "Text style",
2933
+ options: o,
2934
+ selected: String(n),
2935
+ onChange: (t) => {
2936
+ let n = Number(t);
2937
+ n === 0 ? e.chain().setParagraph().run() : e.chain().setHeading({ level: n }).run();
2938
+ },
2939
+ onClosed: () => {
2940
+ e.commands.focus();
2941
+ }
2942
+ }
2943
+ });
2944
+ }
2945
+ function dr({ editor: e, isOpen: t, onOpenChange: n }) {
2946
+ let r = e.getAttributes("link").href, i = () => {
2947
+ n(!1), e.commands.focus();
2948
+ };
2949
+ return /* @__PURE__ */ L(h, {
2950
+ title: r ? "Edit link" : "Add a link",
2951
+ isOpen: t,
2952
+ onOpenChange: (e) => {
2953
+ e ? n(!0) : i();
2954
+ },
2955
+ children: t && /* @__PURE__ */ L(fr, {
2956
+ editor: e,
2957
+ current: r,
2958
+ onDone: i
2959
+ })
2960
+ });
2961
+ }
2962
+ function fr({ editor: e, current: t, onDone: n }) {
2963
+ let [r, i] = F(t ?? ""), a = w(), o = N(() => b(a), [a]);
2964
+ return /* @__PURE__ */ R("form", {
2965
+ className: "flex flex-col gap-4",
2966
+ onSubmit: (t) => {
2967
+ t.preventDefault();
2968
+ let i = r.trim();
2969
+ i === "" ? e.chain().focus().extendMarkRange("link").unsetLink().run() : e.chain().focus().extendMarkRange("link").setLink({ href: i }).run(), n();
2970
+ },
2971
+ children: [/* @__PURE__ */ L(s, {
2972
+ label: "Page or web address",
2973
+ description: "Search pages by title, or type an address such as https://example.com.",
2974
+ value: r,
2975
+ onChange: i,
2976
+ suggestions: o,
2977
+ inputMode: "url"
2978
+ }), /* @__PURE__ */ R("div", {
2979
+ className: "flex flex-wrap justify-end gap-3",
2980
+ children: [t && /* @__PURE__ */ L(T, {
2981
+ variant: "quiet",
2982
+ onPress: () => {
2983
+ e.chain().focus().extendMarkRange("link").unsetLink().run(), n();
2984
+ },
2985
+ children: "Remove link"
2986
+ }), /* @__PURE__ */ L(T, {
2987
+ type: "submit",
2988
+ variant: "primary",
2989
+ children: t ? "Update link" : "Add link"
2990
+ })]
2991
+ })]
2992
+ });
2993
+ }
2994
+ function pr({ path: e, previewUrl: t, onCancel: n, onInsert: r }) {
2995
+ let [i, o] = F(""), [s, c] = F(!1), [l, u] = F(!1);
2996
+ return /* @__PURE__ */ L(h, {
2997
+ title: "Describe the image",
2998
+ isOpen: e !== null,
2999
+ onOpenChange: (e) => {
3000
+ e || n();
3001
+ },
3002
+ children: /* @__PURE__ */ R("form", {
3003
+ className: "flex flex-col gap-4",
3004
+ onSubmit: (e) => {
3005
+ e.preventDefault(), !s && i.trim() === "" ? u(!0) : (r(s ? "" : i.trim()), o(""), c(!1), u(!1));
3006
+ },
3007
+ children: [
3008
+ t && /* @__PURE__ */ L("img", {
3009
+ src: t,
3010
+ alt: "",
3011
+ className: "max-h-40 self-start rounded-md object-contain"
3012
+ }),
3013
+ e && /* @__PURE__ */ L("p", {
3014
+ className: "text-small text-content-muted",
3015
+ children: e.slice(e.lastIndexOf("/") + 1)
3016
+ }),
3017
+ !s && /* @__PURE__ */ L(f, {
3018
+ label: "Alt text",
3019
+ isRequired: !0,
3020
+ description: "Describe what this image communicates here.",
3021
+ value: i,
3022
+ onChange: (e) => {
3023
+ o(e), u(!1);
3024
+ },
3025
+ isInvalid: l,
3026
+ errorMessage: "Describe the image, or mark it decorative.",
3027
+ rows: 2
3028
+ }),
3029
+ /* @__PURE__ */ L(a, {
3030
+ isSelected: s,
3031
+ onChange: c,
3032
+ children: "Decorative image (it adds nothing a reader needs)"
3033
+ }),
3034
+ /* @__PURE__ */ L("div", {
3035
+ className: "flex justify-end",
3036
+ children: /* @__PURE__ */ L(T, {
3037
+ type: "submit",
3038
+ variant: "primary",
3039
+ children: "Insert image"
3040
+ })
3041
+ })
3042
+ ]
3043
+ })
3044
+ });
3045
+ }
3046
+ //#endregion
3047
+ export { Xn as BodyEditor, dr as LinkDialog, ln as n, dn as t };