@vespercms/admin 0.0.0-stage → 0.1.0-next.1

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 (207) hide show
  1. package/README.md +119 -2
  2. package/dist/BodyEditor-_mkh0BSQ.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-4fVeej3c.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 +35 -0
  79. package/dist/screens/EntryEditor.d.ts +13 -0
  80. package/dist/screens/EntryList.d.ts +16 -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/screens/status.d.ts +36 -0
  89. package/dist/shortcuts-CarKeDqp.js +4666 -0
  90. package/dist/studio.css +3 -0
  91. package/dist/studio.js +6449 -0
  92. package/dist/types.d.ts +76 -0
  93. package/dist/widgets/basic.d.ts +25 -0
  94. package/dist/widgets/blank-date.d.ts +8 -0
  95. package/dist/widgets/crops.d.ts +43 -0
  96. package/dist/widgets/focal-point.d.ts +15 -0
  97. package/dist/widgets/geo-map.d.ts +10 -0
  98. package/dist/widgets/geo.d.ts +16 -0
  99. package/dist/widgets/group.d.ts +41 -0
  100. package/dist/widgets/icon.d.ts +9 -0
  101. package/dist/widgets/image.d.ts +16 -0
  102. package/dist/widgets/markdown-lazy.d.ts +2 -0
  103. package/dist/widgets/markdown.d.ts +2 -0
  104. package/dist/widgets/reference.d.ts +12 -0
  105. package/dist/widgets/registry.d.ts +32 -0
  106. package/dist/widgets/special.d.ts +20 -0
  107. package/dist/widgets/union.d.ts +36 -0
  108. package/package.json +63 -4
  109. package/src/a11y/FieldNotes.tsx +56 -0
  110. package/src/a11y/NotesDrawer.tsx +81 -0
  111. package/src/a11y/pdf.ts +45 -0
  112. package/src/a11y/run.ts +12 -0
  113. package/src/a11y/useNotes.ts +139 -0
  114. package/src/app/App.tsx +156 -0
  115. package/src/app/Screen.tsx +416 -0
  116. package/src/app/UserMenu.tsx +95 -0
  117. package/src/app/api.ts +176 -0
  118. package/src/app/appearance.ts +54 -0
  119. package/src/app/browser-api.ts +173 -0
  120. package/src/app/collection-icon.ts +15 -0
  121. package/src/app/context.tsx +32 -0
  122. package/src/app/entries-changed.ts +48 -0
  123. package/src/app/file-url.tsx +44 -0
  124. package/src/app/format.ts +39 -0
  125. package/src/app/idb.ts +82 -0
  126. package/src/app/load.ts +40 -0
  127. package/src/app/media.ts +20 -0
  128. package/src/app/navigation.ts +4 -0
  129. package/src/app/pane-context.ts +25 -0
  130. package/src/app/panes.tsx +513 -0
  131. package/src/app/router.ts +158 -0
  132. package/src/body/BodyEditor.tsx +1139 -0
  133. package/src/body/TableView.tsx +700 -0
  134. package/src/body/catalog.ts +198 -0
  135. package/src/body/checks.ts +83 -0
  136. package/src/body/chips.ts +150 -0
  137. package/src/body/commands.ts +191 -0
  138. package/src/body/document.ts +388 -0
  139. package/src/body/insert.tsx +301 -0
  140. package/src/body/nodes.ts +287 -0
  141. package/src/body/reveal.ts +93 -0
  142. package/src/body/scroll.ts +53 -0
  143. package/src/body/settings.tsx +510 -0
  144. package/src/body/shortcuts.ts +31 -0
  145. package/src/body/table.ts +192 -0
  146. package/src/body/ui.ts +77 -0
  147. package/src/body/views.tsx +268 -0
  148. package/src/build.ts +6 -0
  149. package/src/cloud/CloudGate.tsx +245 -0
  150. package/src/cloud/access.ts +52 -0
  151. package/src/cloud/changes.tsx +474 -0
  152. package/src/cloud/connection.ts +281 -0
  153. package/src/cloud/editor.tsx +250 -0
  154. package/src/cloud/session.ts +289 -0
  155. package/src/cloud/storage.ts +212 -0
  156. package/src/editor/Field.tsx +182 -0
  157. package/src/editor/PagePicker.tsx +102 -0
  158. package/src/editor/arrange.ts +98 -0
  159. package/src/editor/context.tsx +31 -0
  160. package/src/editor/copy.ts +30 -0
  161. package/src/editor/reveal.ts +38 -0
  162. package/src/editor/target.ts +104 -0
  163. package/src/editor/values.ts +71 -0
  164. package/src/github/GitHubGate.tsx +298 -0
  165. package/src/github/api.ts +81 -0
  166. package/src/github/cache.ts +64 -0
  167. package/src/github/session.ts +146 -0
  168. package/src/index.ts +10 -0
  169. package/src/media/MediaPicker.tsx +302 -0
  170. package/src/media/file-icon.ts +17 -0
  171. package/src/media/formats.ts +262 -0
  172. package/src/media/hygiene.ts +220 -0
  173. package/src/media/upload.ts +47 -0
  174. package/src/mount.tsx +20 -0
  175. package/src/schedule/ScheduleDialog.tsx +303 -0
  176. package/src/schedule/ScheduleSummary.tsx +59 -0
  177. package/src/schedule/ScheduledView.tsx +294 -0
  178. package/src/schedule/cloud.ts +66 -0
  179. package/src/schedule/now.ts +18 -0
  180. package/src/schedule/times.ts +122 -0
  181. package/src/screens/EntryEditor.tsx +1817 -0
  182. package/src/screens/EntryList.tsx +272 -0
  183. package/src/screens/Home.tsx +131 -0
  184. package/src/screens/ListPane.tsx +477 -0
  185. package/src/screens/MediaBrowser.tsx +253 -0
  186. package/src/screens/NotFound.tsx +19 -0
  187. package/src/screens/PageTree.tsx +738 -0
  188. package/src/screens/Redirects.tsx +522 -0
  189. package/src/screens/Unavailable.tsx +27 -0
  190. package/src/screens/status.tsx +104 -0
  191. package/src/studio.css +168 -0
  192. package/src/types.ts +82 -0
  193. package/src/widgets/basic.tsx +315 -0
  194. package/src/widgets/blank-date.ts +32 -0
  195. package/src/widgets/crops.tsx +399 -0
  196. package/src/widgets/focal-point.tsx +240 -0
  197. package/src/widgets/geo-map.tsx +160 -0
  198. package/src/widgets/geo.tsx +170 -0
  199. package/src/widgets/group.tsx +827 -0
  200. package/src/widgets/icon.tsx +47 -0
  201. package/src/widgets/image.tsx +407 -0
  202. package/src/widgets/markdown-lazy.tsx +22 -0
  203. package/src/widgets/markdown.tsx +267 -0
  204. package/src/widgets/reference.tsx +196 -0
  205. package/src/widgets/registry.ts +104 -0
  206. package/src/widgets/special.tsx +290 -0
  207. 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, A as n, B as r, C as i, H as a, I as o, V as s, X as c, b as l, c as u, ct as d, et as f, ft as p, ht as m, it as h, k as g, lt as _, m as v, mt as ee, n as y, nt as b, o as x, ot as S, r as C, s as te, st as w, t as T, tt as E, w as D, x as O, z as k } from "./shortcuts-CarKeDqp.js";
3
+ import { Fragment as ne, createContext as A, useContext as j, useEffect as M, useId as N, useMemo as P, useRef as F, useState as I } from "react";
4
+ import { Fragment as L, jsx as R, jsxs as z } from "react/jsx-runtime";
5
+ import { assembleBody as B, deepEqual as V, editJsxTag as re, editMarkdocTag as H, editTable as ie, escapePipes as U, humanize as ae, jsxClosing as oe, jsxOpening as se, jsxTagLayout as ce, markdocClosing as le, markdocOpening as ue, markdocTagLayout as de, markdocTags as fe, mediaReference as pe, parseBody as me, tableValue as he, unescapePipes as ge } from "@vespercms/core";
6
+ import { Extension as W, Node as G } from "@tiptap/core";
7
+ import _e from "@tiptap/extension-image";
8
+ import { Markdown as ve } from "@tiptap/markdown";
9
+ import { NodeSelection as K, Plugin as ye, PluginKey as be, Selection as xe, TextSelection as Se } from "@tiptap/pm/state";
10
+ import { EditorContent as Ce, NodeViewContent as we, NodeViewWrapper as q, ReactNodeViewRenderer as J, useEditor as Te, useEditorState as Y } from "@tiptap/react";
11
+ import Ee from "@tiptap/starter-kit";
12
+ import { Fragment as De } from "@tiptap/pm/model";
13
+ import { closeHistory as Oe } from "@tiptap/pm/history";
14
+ //#region src/body/catalog.ts
15
+ var ke = {
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 Ae(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: [ke],
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 je = {
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 Me(e) {
111
+ return [...[...e.kinds.values()].filter((e) => e.builtin !== "if" && e.builtin !== "else"), je];
112
+ }
113
+ function Ne(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 = ue(e.name, i, a), o = a ? "" : le(e.name);
117
+ return {
118
+ open: t,
119
+ close: o,
120
+ whole: n === "inline" ? t + r + o : t
121
+ };
122
+ }
123
+ let o = se(e.name, i, a), s = a ? "" : oe(e.name);
124
+ return {
125
+ open: o,
126
+ close: s,
127
+ whole: n === "inline" ? o + r + s : o
128
+ };
129
+ }
130
+ function X(e, t) {
131
+ return e === "mdx" ? t : ae(t);
132
+ }
133
+ //#endregion
134
+ //#region src/body/chips.ts
135
+ var Pe = "", Fe = "", Ie = /([0-9a-f]*)/g, Le = new TextEncoder(), Re = new TextDecoder();
136
+ function ze(e) {
137
+ let t = "";
138
+ for (let n of Le.encode(e)) t += n.toString(16).padStart(2, "0");
139
+ return `${Pe}${t}${Fe}`;
140
+ }
141
+ function Be(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 Re.decode(t);
145
+ }
146
+ function Ve(e) {
147
+ return e.replace(Ie, (e, t) => Be(t));
148
+ }
149
+ function He(e, t) {
150
+ let n = "", r = 0;
151
+ for (let i of t) n += e.slice(r, i.start) + ze(e.slice(i.start, i.end)), r = i.end;
152
+ return n + e.slice(r);
153
+ }
154
+ function Ue(e) {
155
+ return e.includes(Pe) || e.includes(Fe);
156
+ }
157
+ function We(e, t) {
158
+ let n = {}, r = {};
159
+ if (e === "markdoc") {
160
+ let [e] = fe(t);
161
+ for (let t of e?.attributes ?? []) t.type === "attribute" && t.name !== "primary" && (Ge(t.value) ? r[t.name] = Ke(t.value) : n[t.name] = t.value);
162
+ return {
163
+ values: n,
164
+ code: r
165
+ };
166
+ }
167
+ let i = ce(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 Ge(e) {
175
+ return typeof e != "object" || !e ? !1 : "$$mdtype" in e || Object.values(e).some(Ge);
176
+ }
177
+ function Ke(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 qe(e) {
182
+ if (e.startsWith("{%")) {
183
+ let t = fe(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 = ce(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 Je = /* @__PURE__ */ new Set([
235
+ "text",
236
+ "image",
237
+ "vesperInline"
238
+ ]), Ye = /&(?!(?:lt|gt|quot|amp);)[A-Za-z][A-Za-z0-9]*;/;
239
+ function Xe(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 Ze(e, t) {
244
+ try {
245
+ let n = e.parse(Xe(ge(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) => Je.has(e.type ?? "")) ? i : null;
251
+ } catch {
252
+ return null;
253
+ }
254
+ }
255
+ function Qe(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 U(e.serialize(n).trim());
265
+ }
266
+ function $e(e, t) {
267
+ let n = Ze(e, t);
268
+ if (!n || n.some((e) => e.type === "text" && Ye.test(e.text ?? ""))) return null;
269
+ let r = Ze(e, Qe(e, n));
270
+ return JSON.stringify(r) === JSON.stringify(n) ? n : null;
271
+ }
272
+ function et(e, t) {
273
+ let n = he(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 He(e, (i?.chips ?? []).map((e) => ({
281
+ start: e.start - a,
282
+ end: e.end - a
283
+ })));
284
+ })
285
+ }))
286
+ };
287
+ }
288
+ function tt(e) {
289
+ return {
290
+ ...e,
291
+ rows: e.rows.map((e) => ({
292
+ ...e,
293
+ cells: e.cells.map(Ve)
294
+ }))
295
+ };
296
+ }
297
+ function nt() {
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 rt(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 it(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 at(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 ot(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 st(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 ct(e, t) {
369
+ return t < 1 ? e : {
370
+ ...e,
371
+ rows: e.rows.filter((e, n) => n !== t)
372
+ };
373
+ }
374
+ function lt(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 ut(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 dt(e, t) {
395
+ return e === "vesperCard" || e === "vesperInline" || e === "vesperTable" || e === "sourceBlock" || t.kindOf(e) !== void 0;
396
+ }
397
+ function ft(e, t) {
398
+ let { selection: n } = e.state;
399
+ return n instanceof K && dt(n.node.type.name, t) ? {
400
+ pos: n.from,
401
+ type: n.node.type.name
402
+ } : null;
403
+ }
404
+ function pt(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 mt(e, t) {
410
+ let n = e.state.tr.setSelection(K.create(e.state.doc, t));
411
+ e.view.dispatch(n.scrollIntoView()), e.view.focus();
412
+ }
413
+ function ht(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(K.create(l.doc, u)).scrollIntoView(), e.view.dispatch(l), e.view.focus(), u;
428
+ }
429
+ function gt(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(Se.near(r.doc.resolve(i))), e.view.dispatch(r.scrollIntoView()), e.view.focus();
434
+ }
435
+ function _t(e, t, n, r = {}, i = "") {
436
+ if (e.builtin === "table") return {
437
+ type: "vesperTable",
438
+ attrs: { value: nt() }
439
+ };
440
+ let a = Ne(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 vt(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(_t(t, i, n)), c = r.node(o), l = r.index(o);
472
+ return a ? c.canReplace(l, l + 1, De.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 yt(e, t, n, r, i, a = {}) {
478
+ let o = _t(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 bt = /* @__PURE__ */ new Set([
488
+ "paragraph",
489
+ "heading",
490
+ "bulletList",
491
+ "orderedList",
492
+ "blockquote",
493
+ "codeBlock",
494
+ "horizontalRule"
495
+ ]), xt = {
496
+ default: null,
497
+ keepOnSplit: !1,
498
+ rendered: !1
499
+ }, St = W.create({
500
+ name: "vesperBlockIndex",
501
+ addGlobalAttributes() {
502
+ return [{
503
+ types: [...bt],
504
+ attributes: { vesperBlock: xt }
505
+ }];
506
+ }
507
+ }), Ct = G.create({
508
+ name: "sourceBlock",
509
+ group: "block",
510
+ atom: !0,
511
+ selectable: !0,
512
+ draggable: !1,
513
+ addAttributes() {
514
+ return {
515
+ vesperBlock: xt,
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
+ }), wt = G.create({
543
+ name: "vesperCard",
544
+ group: "block vesperTag",
545
+ atom: !0,
546
+ selectable: !0,
547
+ draggable: !1,
548
+ addAttributes() {
549
+ return {
550
+ vesperBlock: xt,
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
+ }), Tt = G.create({
584
+ name: "vesperTable",
585
+ group: "block",
586
+ atom: !0,
587
+ selectable: !0,
588
+ draggable: !1,
589
+ addAttributes() {
590
+ return {
591
+ vesperBlock: xt,
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
+ }), Et = G.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: Be(String(e.hex ?? "")) }),
655
+ renderMarkdown: (e) => ze(String(e.attrs?.source ?? ""))
656
+ }), Dt = {
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 Ot(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) => Dt[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(kt(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 kt(e, t, n) {
689
+ return G.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: xt,
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 At(e, t) {
743
+ let n = me(e, t.format, t.markdoc ? { markdoc: t.markdoc } : {}), r = Mt(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 jt = (e, t) => e === null ? String(t) : `${e}.${String(t)}`;
753
+ function Mt(e, t, n, r, i, a) {
754
+ return t.map((t, o) => {
755
+ let s = jt(n, o), c = Pt(e, t, s, r, i);
756
+ return a && !a(c.type ?? "") ? Nt(e, t, s) : c;
757
+ });
758
+ }
759
+ function Nt(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 Pt(e, t, n, r, i) {
770
+ let a = e.slice(t.start, t.end);
771
+ if (t.kind === "markdown" && !Ue(a)) {
772
+ let o = Ft(He(a, (t.chips ?? []).map((e) => ({
773
+ start: e.start - t.start,
774
+ end: e.end - t.start
775
+ }))), r), s = o === null ? null : It(i.markdown, o);
776
+ return s ? {
777
+ ...s,
778
+ attrs: {
779
+ ...s.attrs,
780
+ vesperBlock: n
781
+ }
782
+ } : Nt(e, t, n);
783
+ }
784
+ if (t.kind === "table" && t.table) {
785
+ let r = et(e, t.table);
786
+ return r.rows.every((e) => e.cells.every((e) => !Ue(Ve(e)) && $e(i.markdown, e))) ? {
787
+ type: "vesperTable",
788
+ attrs: {
789
+ vesperBlock: n,
790
+ value: r
791
+ }
792
+ } : Nt(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 Nt(e, t, n);
796
+ let c = i.containers.typeOf(s);
797
+ if (c && o.children && o.closeStart !== void 0) {
798
+ let r = Mt(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 Ft(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 It(e, t) {
831
+ try {
832
+ let n = e.parse(t).content ?? [], [r] = n;
833
+ if (n.length !== 1 || !r?.type || !bt.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 Lt = (e, t) => e.type !== void 0 && t.kindOf(e.type) !== void 0;
844
+ function Rt(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, Lt(i, t) ? JSON.stringify({ open: i.attrs?.open }) : JSON.stringify(i)), Lt(i, t) && r(i.content);
849
+ }
850
+ };
851
+ return r(e.content), n;
852
+ }
853
+ function zt(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 Bt(e, t, n) {
859
+ return Wt(e.content, null, t, n);
860
+ }
861
+ function Vt(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 Ht(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 Ut(e, t, n, r) {
892
+ let i = n.get(t), a = r ? Vt(r, t) : null;
893
+ if (!i || !r || !a?.block.chips) return null;
894
+ let o = Ht(JSON.parse(i)), s = Ht(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 Ft(l, a.indent);
904
+ }
905
+ function Wt(e, t, n, r) {
906
+ let i = [];
907
+ for (let a of e ?? []) {
908
+ let e = a.attrs?.vesperBlock, o = zt(e, t);
909
+ if (Lt(a, r.containers)) {
910
+ let t = String(a.attrs?.open ?? "");
911
+ if (o !== null && typeof e == "string") {
912
+ let s = n.get(e), c = Wt(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: Wt(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 = Gt(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" ? Ut(a, e, n, r.parsed) : null) ?? Kt(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 Gt(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 ? Vt(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 ie(o, tt(t), r);
957
+ }
958
+ function Kt(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 Ve(t.serialize({
963
+ type: "doc",
964
+ content: [{
965
+ ...e,
966
+ attrs: r
967
+ }]
968
+ }).replace(/\s+$/, ""));
969
+ }
970
+ function qt(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 Z = new be("vesperSlash");
988
+ function Jt(e, t, n) {
989
+ return Me(t).flatMap((t) => {
990
+ let r = vt(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 Yt(e) {
998
+ let t = Z.getState(e);
999
+ return t?.active ? e.doc.textBetween(t.from + 1, e.selection.from, "\n") : null;
1000
+ }
1001
+ function Xt(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 Zt(e) {
1006
+ return W.create({
1007
+ name: "vesperSlash",
1008
+ priority: 1e3,
1009
+ addProseMirrorPlugins() {
1010
+ return [new ye({
1011
+ key: Z,
1012
+ state: {
1013
+ init: () => ({ active: !1 }),
1014
+ apply(e, t, n, r) {
1015
+ let i = e.getMeta(Z), 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(Z, {
1034
+ active: !0,
1035
+ from: n,
1036
+ index: 0
1037
+ })), !0);
1038
+ },
1039
+ handleKeyDown(t, n) {
1040
+ let r = Z.getState(t.state);
1041
+ if (!r?.active) return !1;
1042
+ let i = Yt(t.state) ?? "", a = Xt(e.choices(t.state), i);
1043
+ if (n.key === "Escape") return t.dispatch(t.state.tr.setMeta(Z, { 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(Z, { 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(Z, { active: !1 })), e.choose(n, i), !0;
1057
+ }
1058
+ return !1;
1059
+ }
1060
+ }
1061
+ })];
1062
+ }
1063
+ });
1064
+ }
1065
+ function Qt(e, t) {
1066
+ let n = Z.getState(e);
1067
+ if (!n?.active) return {
1068
+ role: "textbox",
1069
+ "aria-multiline": "true"
1070
+ };
1071
+ let r = t.count(Yt(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 $t({ editor: e, listboxId: t, optionId: n, choices: r, onChoose: i }) {
1081
+ let a = Y({
1082
+ editor: e,
1083
+ selector: ({ editor: e }) => {
1084
+ let t = Z.getState(e.state);
1085
+ return t?.active ? {
1086
+ from: t.from,
1087
+ to: e.state.selection.from,
1088
+ index: t.index,
1089
+ query: Yt(e.state) ?? "",
1090
+ place: en(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 = Xt(r(e.state), a.query), c = Math.min(a.index, Math.max(0, s.length - 1));
1097
+ return /* @__PURE__ */ R("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: m("fixed z-40 max-h-64 min-w-56 overflow-y-auto", S),
1106
+ children: s.length === 0 ? /* @__PURE__ */ R("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__ */ z("div", {
1114
+ id: n(t),
1115
+ role: "option",
1116
+ tabIndex: -1,
1117
+ "aria-selected": t === c,
1118
+ className: m("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__ */ R("span", {
1126
+ className: "text-content-muted",
1127
+ children: " (in this line)"
1128
+ })]
1129
+ }, e.kind.key))
1130
+ });
1131
+ }
1132
+ function en(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 tn({ editor: e, choices: t, onChoose: n, disabled: r }) {
1144
+ let i = Y({
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__ */ R(h, {
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 nn() {
1163
+ let e = N().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 rn(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 an(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 on(e, t, n, r) {
1198
+ let i = me(t, r.format, r.markdoc ? { markdoc: r.markdoc } : {}), a = an(e.state.doc, rn(i.blocks, n));
1199
+ if (e.view.focus(), !a) return;
1200
+ let { doc: o } = e.state, s;
1201
+ s = a.node.isTextblock ? Se.create(o, a.pos + 1) : dt(a.node.type.name, r.containers) ? K.create(o, a.pos) : Se.near(o.resolve(a.pos + 1)), e.view.dispatch(e.state.tr.setSelection(s).scrollIntoView());
1202
+ }
1203
+ function sn(e, t, n) {
1204
+ e.setSelectionRange(t, n), e.blur(), e.focus();
1205
+ }
1206
+ //#endregion
1207
+ //#region src/body/scroll.ts
1208
+ var cn = "sticky top-[var(--sticky-top,0px)] z-1 rounded-t-md border-b border-border bg-surface-raised p-1", ln = 4;
1209
+ function un(e, t) {
1210
+ if (!t) return !1;
1211
+ let { selection: n } = e.state, r;
1212
+ try {
1213
+ r = e.coordsAtPos(n instanceof K ? n.from : n.head).top;
1214
+ } catch {
1215
+ return !1;
1216
+ }
1217
+ let i = t.getBoundingClientRect().bottom + ln;
1218
+ return r >= i || r < e.dom.getBoundingClientRect().top || dn(e.dom).scrollBy(0, r - i), !1;
1219
+ }
1220
+ function dn(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 fn = A(null);
1230
+ function Q() {
1231
+ let e = j(fn);
1232
+ if (!e) throw Error("useBodyUi() must be used inside the body editor.");
1233
+ return e;
1234
+ }
1235
+ function pn(e) {
1236
+ let { checks: t } = Q(), n = P(() => t.validateSync(e), [t, e]), [r, i] = I([]);
1237
+ return M(() => {
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 mn(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 $ = (e) => typeof e == "string" ? e : "";
1263
+ function hn({ editor: e, pos: t, onClose: n }) {
1264
+ let r = Q(), i = Y({
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 ? _n(i, r) : null;
1278
+ return /* @__PURE__ */ R(b, {
1279
+ title: a?.title ?? "Settings",
1280
+ isOpen: t !== null && i !== null,
1281
+ onOpenChange: (e) => {
1282
+ e || n();
1283
+ },
1284
+ children: i && a && /* @__PURE__ */ z(gn, {
1285
+ className: "flex flex-col gap-6",
1286
+ children: [
1287
+ a.mode === "tag" && a.kind && /* @__PURE__ */ R(xn, {
1288
+ editor: e,
1289
+ target: i,
1290
+ kind: a.kind
1291
+ }),
1292
+ a.mode === "condition" && /* @__PURE__ */ R(En, {
1293
+ editor: e,
1294
+ target: i
1295
+ }),
1296
+ a.mode === "raw" && /* @__PURE__ */ R(Dn, {
1297
+ editor: e,
1298
+ target: i,
1299
+ label: a.label
1300
+ }),
1301
+ /* @__PURE__ */ R(On, {
1302
+ editor: e,
1303
+ target: i,
1304
+ onClose: n
1305
+ })
1306
+ ]
1307
+ })
1308
+ });
1309
+ }
1310
+ function gn({ className: e, children: t }) {
1311
+ let n = F(null);
1312
+ return M(() => {
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__ */ R("div", {
1321
+ ref: n,
1322
+ className: e,
1323
+ children: t
1324
+ });
1325
+ }
1326
+ function _n(e, t) {
1327
+ if (e.type === "sourceBlock") {
1328
+ let t = qt($(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 = $(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 ?? X(n, r);
1361
+ return {
1362
+ mode: "raw",
1363
+ title: `Edit ${a} as text`,
1364
+ label: a
1365
+ };
1366
+ }
1367
+ let r = qe($(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 ? X(r.syntax, r.name) : "Tag";
1375
+ return {
1376
+ mode: "raw",
1377
+ title: `Edit ${a.toLowerCase()} as text`,
1378
+ label: a
1379
+ };
1380
+ }
1381
+ function vn(e) {
1382
+ if (e.type === "vesperInline") {
1383
+ let t = $(e.attrs.source), n = qe(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 = $(e.attrs.source), r = t === "markdoc" ? fe(n)[0]?.end ?? n.length : ce(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: $(e.attrs.open),
1404
+ rest: ""
1405
+ };
1406
+ }
1407
+ function yn(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 = vn(t);
1416
+ t.type === "vesperInline" || t.type === "vesperCard" ? yn(e, t, { source: n + r.rest }) : yn(e, t, { open: n });
1417
+ }
1418
+ function xn({ editor: e, target: t, kind: r }) {
1419
+ let a = Q(), o = D(), s = vn(t), { values: c, code: l } = We(s.syntax, s.open), [u, f] = I(null), p = pn(t.type === "vesperInline" || t.type === "vesperCard" ? $(t.attrs.source) : s.syntax === "mdx" ? `${s.open}\n\n${$(t.attrs.close)}` : `${s.open}\n${$(t.attrs.close)}`), m = P(() => {
1420
+ let e = {};
1421
+ for (let t of r.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
+ }, [r.fields, c]), h = P(() => {
1427
+ let e = /* @__PURE__ */ new Map();
1428
+ for (let t of p) {
1429
+ if (!t.attribute || t.level !== "error") continue;
1430
+ let n = g([t.attribute]), r = t.message.replace(/^[^:]+: /, "");
1431
+ e.set(n, [...e.get(n) ?? [], r]);
1432
+ }
1433
+ return e;
1434
+ }, [p]), _ = r.builtin === "partial" ? r.fields.filter((e) => e.path[0] !== "file") : r.fields, v = {
1435
+ ...o,
1436
+ values: m,
1437
+ issues: h,
1438
+ disabled: a.disabled,
1439
+ idPrefix: `block${String(t.pos)}`,
1440
+ setValue: (i, a) => {
1441
+ let o = String(i[0]), c = i.length > 1 ? n(m, i, a)[o] ?? null : a, l = r.fields.find((e) => e.path[0] === o), u = l?.default !== void 0 && V(c, l.default) ? void 0 : c, d = (s.syntax === "markdoc" ? H : re)(s.open, [[o, u]], r.order);
1442
+ d === null ? f("This tag is written in a way the form can’t change. Edit it as Markdoc instead.") : (f(null), bn(e, t, d));
1443
+ }
1444
+ };
1445
+ return /* @__PURE__ */ z(i.Provider, {
1446
+ value: v,
1447
+ children: [
1448
+ r.description && /* @__PURE__ */ R("p", {
1449
+ className: "text-small text-content-muted",
1450
+ children: r.description
1451
+ }),
1452
+ u && /* @__PURE__ */ R("p", {
1453
+ role: "alert",
1454
+ className: "text-small text-danger",
1455
+ children: u
1456
+ }),
1457
+ r.builtin === "partial" && /* @__PURE__ */ R(Sn, {
1458
+ value: typeof c.file == "string" ? c.file : "",
1459
+ message: p.find((e) => e.code === "partial-missing")?.message,
1460
+ onChange: (n) => {
1461
+ let i = H(s.open, [["file", n]], r.order);
1462
+ i && bn(e, t, i);
1463
+ }
1464
+ }),
1465
+ _.map((e) => /* @__PURE__ */ R(C, {
1466
+ field: e,
1467
+ path: e.path
1468
+ }, e.path.join("."))),
1469
+ t.type === "vesperInline" && s.close !== "" && /* @__PURE__ */ R(d, {
1470
+ label: "Text",
1471
+ description: "What the reader sees.",
1472
+ value: s.inner ?? "",
1473
+ isDisabled: a.disabled,
1474
+ onChange: (n) => {
1475
+ yn(e, t, { source: s.open + n + (s.close ?? "") });
1476
+ }
1477
+ }),
1478
+ Object.keys(l).length > 0 && /* @__PURE__ */ z("div", {
1479
+ className: "text-small text-content-muted",
1480
+ children: [/* @__PURE__ */ R("p", { children: "Set in the page’s code, so kept as written:" }), /* @__PURE__ */ R("ul", {
1481
+ className: "list-disc pl-6",
1482
+ children: Object.entries(l).map(([e, t]) => /* @__PURE__ */ z("li", { children: [
1483
+ /* @__PURE__ */ R("code", {
1484
+ className: "font-mono",
1485
+ children: e
1486
+ }),
1487
+ ": ",
1488
+ /* @__PURE__ */ R("code", {
1489
+ className: "font-mono",
1490
+ children: t
1491
+ })
1492
+ ] }, e))
1493
+ })]
1494
+ })
1495
+ ]
1496
+ });
1497
+ }
1498
+ function Sn({ value: e, message: n, onChange: r }) {
1499
+ let i = Q(), a = Cn(i.partials ?? [], i.entryPath, e);
1500
+ return /* @__PURE__ */ R(t, {
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: a,
1504
+ value: e === "" ? null : e,
1505
+ onChange: (e) => {
1506
+ e !== null && r(e);
1507
+ },
1508
+ isInvalid: n !== void 0,
1509
+ errorMessage: n?.replace(/^[^:]+: /, ""),
1510
+ isRequired: !0,
1511
+ isDisabled: i.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 = Q(), r = $(t.attrs.open), i = de(r), a = i?.attributes.find((e) => e.kind === "primary"), [o, s] = I(a ? r.slice(a.valueStart, a.valueEnd) : ""), [c, l] = I(!1);
1535
+ return !i || !a ? /* @__PURE__ */ R(Dn, {
1536
+ editor: e,
1537
+ target: t,
1538
+ label: "Condition",
1539
+ field: "open"
1540
+ }) : /* @__PURE__ */ R(d, {
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() !== "" && de(i)?.attributes.some((e) => e.kind === "primary");
1551
+ l(!o), o && yn(e, t, { open: i });
1552
+ }
1553
+ });
1554
+ }
1555
+ function Dn({ editor: e, target: t, label: n, field: r }) {
1556
+ let i = Q(), a = r ?? (t.type === "sourceBlock" ? "text" : "source"), o = $(t.attrs[a]);
1557
+ return /* @__PURE__ */ R(w, {
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
+ yn(e, t, { [a]: n });
1566
+ }
1567
+ });
1568
+ }
1569
+ function On({ editor: e, target: t, onClose: n }) {
1570
+ let r = Q(), i = e.state.doc.resolve(t.pos), a = i.index(), o = i.parent.childCount;
1571
+ return /* @__PURE__ */ z("div", {
1572
+ className: "flex flex-wrap items-center justify-between gap-3 border-t border-border pt-4",
1573
+ children: [/* @__PURE__ */ z("div", {
1574
+ className: "flex flex-wrap gap-2",
1575
+ children: [!t.inline && /* @__PURE__ */ z(L, { children: [/* @__PURE__ */ R(_, {
1576
+ isDisabled: r.disabled || a === 0,
1577
+ onPress: () => {
1578
+ r.move(t.pos, -1);
1579
+ },
1580
+ children: "Move up"
1581
+ }), /* @__PURE__ */ R(_, {
1582
+ isDisabled: r.disabled || a >= o - 1,
1583
+ onPress: () => {
1584
+ r.move(t.pos, 1);
1585
+ },
1586
+ children: "Move down"
1587
+ })] }), /* @__PURE__ */ R(_, {
1588
+ variant: "quiet",
1589
+ isDisabled: r.disabled,
1590
+ onPress: () => {
1591
+ n(), r.remove(t.pos);
1592
+ },
1593
+ children: "Remove"
1594
+ })]
1595
+ }), /* @__PURE__ */ R(_, {
1596
+ variant: "primary",
1597
+ onPress: n,
1598
+ children: "Done"
1599
+ })]
1600
+ });
1601
+ }
1602
+ //#endregion
1603
+ //#region src/body/TableView.tsx
1604
+ var kn = m("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 = qe(t), r = (n.name ? e.catalog.find(n.syntax, n.name) : void 0)?.label ?? (n.name && (n.kind === "tag" || n.kind === "component") ? X(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 = Q();
1641
+ return e.map((e, n) => {
1642
+ if (e.type === "image") {
1643
+ let t = String(e.attrs?.alt ?? "");
1644
+ return /* @__PURE__ */ R("span", {
1645
+ className: "text-content-muted",
1646
+ children: t ? `Image: ${t}` : "Image"
1647
+ }, n);
1648
+ }
1649
+ if (e.type === "vesperInline") return /* @__PURE__ */ R("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__ */ R("strong", {
1655
+ className: "font-semibold",
1656
+ children: r
1657
+ }) : t.type === "italic" ? r = /* @__PURE__ */ R("em", { children: r }) : t.type === "strike" ? r = /* @__PURE__ */ R("s", { children: r }) : t.type === "code" ? r = /* @__PURE__ */ R("code", {
1658
+ className: "font-mono text-small",
1659
+ children: r
1660
+ }) : t.type === "link" && (r = /* @__PURE__ */ R("span", {
1661
+ className: "text-accent underline",
1662
+ children: r
1663
+ }));
1664
+ return /* @__PURE__ */ R(ne, { 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 = G.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] = I(!1), [s] = I(() => new Fn());
1686
+ M(() => {
1687
+ s.update({
1688
+ onFinish: i,
1689
+ linkOpen: a,
1690
+ openLink: () => {
1691
+ o(!0);
1692
+ }
1693
+ });
1694
+ });
1695
+ let [c] = I(() => [
1696
+ In,
1697
+ Ee.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
+ _e.configure({ inline: !0 }),
1717
+ Et.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
+ ve,
1724
+ W.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
+ W.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 = Te({
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 M(() => {
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__ */ z(L, { children: [/* @__PURE__ */ R(Ce, { editor: l }), /* @__PURE__ */ R(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 = Q(), a = e.attrs.value, o = e.attrs.vesperBlock ?? null, s = r.markdown, c = a.rows.length, l = a.columns.length, u = N(), d = N(), f = N(), [g, _] = I({
1790
+ row: 0,
1791
+ col: 0
1792
+ }), [v, ee] = I(null), [b, x] = I(null), [S, C] = I(!1), [te, w] = I(null), E = F(/* @__PURE__ */ new Map()), D = {
1793
+ row: Math.min(g.row, c - 1),
1794
+ col: Math.min(g.col, l - 1)
1795
+ }, O = F({
1796
+ at: D,
1797
+ editing: v
1798
+ });
1799
+ M(() => {
1800
+ O.current = {
1801
+ at: D,
1802
+ editing: v
1803
+ };
1804
+ });
1805
+ let k = P(() => a.rows.map((e) => e.cells.map((e) => Ze(s, e) ?? [])), [a, s]), ne = (k[0] ?? []).map((e, t) => Nn(i, e) || `column ${String(t + 1)}`), A = (e) => ne[e] ?? `column ${String(e + 1)}`, j = () => {
1806
+ setTimeout(() => {
1807
+ let { at: e, editing: t } = O.current;
1808
+ t || E.current.get(`${String(e.row)}:${String(e.col)}`)?.focus();
1809
+ }, 0);
1810
+ }, L = (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
+ O.current = {
1816
+ ...O.current,
1817
+ at: r
1818
+ }, _(r), j();
1819
+ }, B = (e) => {
1820
+ O.current = {
1821
+ at: e ?? O.current.at,
1822
+ editing: e
1823
+ }, e && _(e), ee(e);
1824
+ };
1825
+ M(() => {
1826
+ i.takeNewTable() && B({
1827
+ row: 0,
1828
+ col: 0
1829
+ });
1830
+ }, []);
1831
+ let V = (e, n) => {
1832
+ let a = i.checkTable(o, e);
1833
+ if (!a.ok) return w(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 : (w(null), r.view.dispatch(Oe(r.state.tr.setNodeMarkup(s, void 0, {
1836
+ ...c.attrs,
1837
+ value: e
1838
+ }))), n && i.announce(n), !0);
1839
+ }, re = () => {
1840
+ let e = t();
1841
+ typeof e == "number" && mt(r, e);
1842
+ }, H = (e) => e === 0 ? "the header row" : `row ${String(e + 1)}`, ie = (e, { row: t, col: n }) => {
1843
+ let r = A(n), i = String(t + 1);
1844
+ return e === "row-above" && t > 0 ? [
1845
+ it(a, t),
1846
+ `Row added above ${H(t)}.`,
1847
+ {
1848
+ row: t,
1849
+ col: n
1850
+ }
1851
+ ] : e === "row-below" ? [
1852
+ it(a, t + 1),
1853
+ `Row added below ${H(t)}.`,
1854
+ {
1855
+ row: t + 1,
1856
+ col: n
1857
+ }
1858
+ ] : e === "column-left" ? [
1859
+ at(a, n),
1860
+ `Column added left of ${r}.`,
1861
+ {
1862
+ row: t,
1863
+ col: n
1864
+ }
1865
+ ] : e === "column-right" ? [
1866
+ at(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
+ ot(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
+ ot(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
+ st(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
+ st(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
+ ct(a, t),
1902
+ `Row ${i} deleted.`,
1903
+ {
1904
+ row: t,
1905
+ col: n
1906
+ }
1907
+ ] : e === "column-delete" && l > 1 ? [
1908
+ lt(a, n),
1909
+ `Column ${r} deleted.`,
1910
+ {
1911
+ row: t,
1912
+ col: n
1913
+ }
1914
+ ] : null;
1915
+ }, U = (e) => {
1916
+ let t = ie(e, D);
1917
+ t && V(t[0], t[1]) ? L(t[2].row, t[2].col, t[0]) : L(D.row, D.col);
1918
+ }, ae = (e) => {
1919
+ let t = An.find((t) => t.id === e), { col: n } = D;
1920
+ if (!t || a.align[n] === t.align) return;
1921
+ let r = t.align === null ? "as written" : t.id === "center" ? "centre" : t.id;
1922
+ V(ut(a, n, t.align), `Column ${A(n)} aligned ${r}.`);
1923
+ }, oe = (e) => (t, n) => {
1924
+ B(null);
1925
+ let r = a, o;
1926
+ if (t) {
1927
+ let n = Qe(s, t), o = Ze(s, n);
1928
+ if (!o || Qe(s, o) !== n) {
1929
+ let t = "That can’t be written in a table cell, so the cell wasn’t changed.";
1930
+ w(t), i.announce(t), L(e.row, e.col);
1931
+ return;
1932
+ }
1933
+ n !== a.rows[e.row]?.cells[e.col] && (r = rt(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 = it(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 && !V(r, o) ? L(e.row, e.col) : n !== "leave" && (d ? B(d) : L(e.row, e.col));
1952
+ }, se = (e) => {
1953
+ if (v) return;
1954
+ let { row: t, col: n } = D, a = T ? e.metaKey : e.ctrlKey, o = e.key, s = !i.disabled;
1955
+ if (e.altKey && s && o === "ArrowUp") U("row-up");
1956
+ else if (e.altKey && s && o === "ArrowDown") U("row-down");
1957
+ else if (e.altKey && s && o === "ArrowLeft") U("column-move-left");
1958
+ else if (e.altKey && s && o === "ArrowRight") U("column-move-right");
1959
+ else if (o === "ArrowUp") L(t - 1, n);
1960
+ else if (o === "ArrowDown") L(t + 1, n);
1961
+ else if (o === "ArrowLeft") L(t, n - 1);
1962
+ else if (o === "ArrowRight") L(t, n + 1);
1963
+ else if (o === "Home") L(e.ctrlKey || e.metaKey ? 0 : t, 0);
1964
+ else if (o === "End") L(e.ctrlKey || e.metaKey ? c - 1 : t, l - 1);
1965
+ else if ((o === "Enter" || o === "F2") && s) B({
1966
+ row: t,
1967
+ col: n
1968
+ });
1969
+ else if (o === "Escape") re();
1970
+ else if ((o === "F10" && e.shiftKey || o === "ContextMenu") && s) x("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
+ }, ce = [
1976
+ {
1977
+ id: "row-above",
1978
+ label: "Insert row above",
1979
+ isDisabled: D.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: D.row <= 1
1997
+ },
1998
+ {
1999
+ id: "row-down",
2000
+ label: "Move row down",
2001
+ isDisabled: D.row === 0 || D.row === c - 1
2002
+ },
2003
+ {
2004
+ id: "column-move-left",
2005
+ label: "Move column left",
2006
+ isDisabled: D.col === 0
2007
+ },
2008
+ {
2009
+ id: "column-move-right",
2010
+ label: "Move column right",
2011
+ isDisabled: D.col === l - 1
2012
+ },
2013
+ {
2014
+ id: "row-delete",
2015
+ label: "Delete row",
2016
+ isDanger: !0,
2017
+ isDisabled: D.row === 0
2018
+ },
2019
+ {
2020
+ id: "column-delete",
2021
+ label: "Delete column",
2022
+ isDanger: !0,
2023
+ isDisabled: l <= 1
2024
+ }
2025
+ ], le = An.find((e) => e.align === (a.align[D.col] ?? null)) ?? An[3], ue = l === 1 ? "column" : "columns";
2026
+ return /* @__PURE__ */ z(q, {
2027
+ as: "div",
2028
+ role: "group",
2029
+ "aria-labelledby": u,
2030
+ "aria-describedby": te ? d : void 0,
2031
+ onFocus: () => {
2032
+ C(!0);
2033
+ },
2034
+ onBlur: (e) => {
2035
+ e.currentTarget.contains(e.relatedTarget) || C(!1);
2036
+ },
2037
+ className: m("my-3", n && kn),
2038
+ children: [
2039
+ /* @__PURE__ */ z("div", {
2040
+ "data-vesper-table-ui": "",
2041
+ className: "mb-1 flex items-center justify-between gap-2",
2042
+ children: [/* @__PURE__ */ z("p", {
2043
+ id: u,
2044
+ className: "text-label text-content-muted",
2045
+ children: [
2046
+ "Table · ",
2047
+ l,
2048
+ " ",
2049
+ ue
2050
+ ]
2051
+ }), !i.disabled && /* @__PURE__ */ R(h, {
2052
+ label: "Table actions",
2053
+ trigger: /* @__PURE__ */ R(p, {
2054
+ icon: "more",
2055
+ label: "Table actions",
2056
+ excludeFromTabOrder: !S,
2057
+ className: "size-8"
2058
+ }),
2059
+ items: ce,
2060
+ onAction: U,
2061
+ choice: {
2062
+ title: "Align column",
2063
+ options: An.map((e) => ({
2064
+ id: e.id,
2065
+ label: e.label
2066
+ })),
2067
+ selected: le?.id ?? "none",
2068
+ onChange: ae
2069
+ },
2070
+ isOpen: b !== null,
2071
+ onOpenChange: (e) => {
2072
+ let t = b;
2073
+ x(e ? t ?? "button" : null), !e && t === "cell" && j();
2074
+ }
2075
+ })]
2076
+ }),
2077
+ /* @__PURE__ */ R("div", {
2078
+ "data-vesper-table-ui": "",
2079
+ className: "overflow-x-auto rounded-md border border-border bg-surface-raised",
2080
+ children: /* @__PURE__ */ R("table", {
2081
+ role: "grid",
2082
+ "aria-label": `Table: ${ne.join(", ")}`,
2083
+ "aria-rowcount": c,
2084
+ "aria-colcount": l,
2085
+ "aria-describedby": f,
2086
+ onKeyDown: se,
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__ */ R("tr", {
2092
+ "aria-rowindex": r + 1,
2093
+ children: e.cells.map((e, t) => {
2094
+ let n = D.row === r && D.col === t, o = v?.row === r && v.col === t;
2095
+ return /* @__PURE__ */ R(r === 0 ? "th" : "td", {
2096
+ ref: (e) => {
2097
+ let n = `${String(r)}:${String(t)}`;
2098
+ e ? E.current.set(n, e) : E.current.delete(n);
2099
+ },
2100
+ role: r === 0 ? "columnheader" : "gridcell",
2101
+ "aria-colindex": t + 1,
2102
+ tabIndex: n && S && !o ? 0 : -1,
2103
+ "data-vesper-active": n ? "" : void 0,
2104
+ onFocus: (e) => {
2105
+ if (o) return;
2106
+ _({
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 || B({
2115
+ row: r,
2116
+ col: t
2117
+ });
2118
+ },
2119
+ className: m("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__ */ R(Ln, {
2121
+ inline: k[r]?.[t] ?? [],
2122
+ label: `${A(t)}, ${H(r)}`,
2123
+ describedBy: f,
2124
+ chipName: (e) => Mn(i, e),
2125
+ onFinish: oe({
2126
+ row: r,
2127
+ col: t
2128
+ })
2129
+ }) : /* @__PURE__ */ R(Pn, { inline: k[r]?.[t] ?? [] })
2130
+ }, t);
2131
+ })
2132
+ }, r);
2133
+ });
2134
+ return t === 0 ? /* @__PURE__ */ R("thead", { children: n }, "head") : /* @__PURE__ */ R("tbody", { children: n }, "body");
2135
+ })
2136
+ })
2137
+ }),
2138
+ /* @__PURE__ */ R("p", {
2139
+ id: f,
2140
+ className: "sr-only",
2141
+ children: v ? `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
+ te && /* @__PURE__ */ R("p", {
2144
+ id: d,
2145
+ className: "mt-2 text-small text-danger",
2146
+ children: te
2147
+ })
2148
+ ]
2149
+ });
2150
+ }
2151
+ //#endregion
2152
+ //#region src/body/views.tsx
2153
+ var zn = m("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__ */ R("ul", {
2156
+ id: e,
2157
+ className: "mt-2 flex flex-col gap-1 text-small",
2158
+ children: t.map((e) => /* @__PURE__ */ R("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 = Q(), a = N(), o = N(), 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 ?? X(s, c), p = d?.builtin === "if" ? `shown when ${Gn(l)}` : mn(d, We(s, l).values), h = pn(s === "mdx" ? `${l}\n\n${u}` : `${l}\n${u}`), g = Y({
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__ */ z(q, {
2178
+ as: "div",
2179
+ role: "group",
2180
+ "aria-labelledby": a,
2181
+ "aria-describedby": h.length > 0 ? o : void 0,
2182
+ className: m("my-3 rounded-md border border-border p-3", h.some((e) => e.level === "error") && "border-danger", n && zn),
2183
+ children: [
2184
+ /* @__PURE__ */ z("div", {
2185
+ contentEditable: !1,
2186
+ className: "mb-2 flex items-center justify-between gap-2",
2187
+ children: [/* @__PURE__ */ R("p", {
2188
+ id: a,
2189
+ className: "text-label text-content-muted",
2190
+ children: Vn(f, p)
2191
+ }), /* @__PURE__ */ R(Un, {
2192
+ label: f,
2193
+ getPos: t,
2194
+ inTabOrder: g
2195
+ })]
2196
+ }),
2197
+ /* @__PURE__ */ R(we, { className: "vesper-container-content" }),
2198
+ /* @__PURE__ */ R("div", {
2199
+ contentEditable: !1,
2200
+ children: /* @__PURE__ */ R(Bn, {
2201
+ id: o,
2202
+ issues: h
2203
+ })
2204
+ })
2205
+ ]
2206
+ });
2207
+ }
2208
+ function Un({ label: e, getPos: t, inTabOrder: n }) {
2209
+ let r = Q();
2210
+ return /* @__PURE__ */ R(_, {
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 = Q(), i = N(), a = N(), o = e.attrs.syntax, s = String(e.attrs.name), c = String(e.attrs.source), l = r.catalog.find(o, s), u = l?.label ?? X(o, s), d = l?.builtin === "else" ? Gn(c) : l?.builtin === "if" ? "" : mn(l, We(o, c).values), f = pn(c);
2225
+ return /* @__PURE__ */ z(q, {
2226
+ as: "div",
2227
+ contentEditable: !1,
2228
+ role: "group",
2229
+ "aria-labelledby": i,
2230
+ "aria-describedby": f.length > 0 ? a : void 0,
2231
+ className: m("my-3 rounded-md border border-border bg-surface p-3", f.some((e) => e.level === "error") && "border-danger", n && zn),
2232
+ children: [/* @__PURE__ */ z("div", {
2233
+ className: "flex items-center justify-between gap-2",
2234
+ children: [/* @__PURE__ */ R("p", {
2235
+ id: i,
2236
+ className: "text-label text-content",
2237
+ children: Vn(u, d)
2238
+ }), /* @__PURE__ */ R(Un, {
2239
+ label: u,
2240
+ getPos: t,
2241
+ inTabOrder: !1
2242
+ })]
2243
+ }), /* @__PURE__ */ R(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 = Q(), r = String(e.attrs.source), i = qe(r), a = i.name ? n.catalog.find(i.syntax, i.name) : void 0, o = i.kind === "tag" || i.kind === "component", s = pn(o ? r : "").filter((e) => e.level === "error"), c = a && o, l = c ? Vn(a.label, qn(i.inner) || mn(a, We(i.syntax, i.open ?? "").values)) : r.length > 80 ? `${r.slice(0, 77)}…` : r;
2254
+ return /* @__PURE__ */ z(q, {
2255
+ as: "span",
2256
+ className: m("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__ */ z("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 = Q(), i = String(e.attrs.text ?? "").split("\n"), a = qt(String(e.attrs.blockType ?? ""));
2272
+ return /* @__PURE__ */ z(q, {
2273
+ as: "div",
2274
+ contentEditable: !1,
2275
+ className: m("my-3 rounded-md border border-dashed border-border-strong bg-surface-sunken p-3", n && zn),
2276
+ children: [/* @__PURE__ */ z("div", {
2277
+ className: "mb-1 flex items-center justify-between gap-2",
2278
+ children: [/* @__PURE__ */ z("p", {
2279
+ className: "text-label text-content-muted",
2280
+ children: [a, ", kept as written."]
2281
+ }), /* @__PURE__ */ R(_, {
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__ */ z("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] = I("writing"), [r, i] = I(0), a = Yn[e.format], o = (e.issues ?? []).filter((e) => e.level === "error"), s = e.notes ?? [], c = F(null), l = F(t);
2308
+ M(() => {
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 ? sn(t, e.target.start, e.target.end) : c.current?.(e.target.start);
2315
+ }, d = F(u);
2316
+ M(() => {
2317
+ d.current = u;
2318
+ });
2319
+ let { apiRef: f } = e;
2320
+ return M(() => {
2321
+ if (f) return f.current = { reveal: (e) => {
2322
+ d.current(e);
2323
+ } }, () => {
2324
+ f.current = null;
2325
+ };
2326
+ }, [f]), /* @__PURE__ */ z("section", {
2327
+ "aria-labelledby": "entry-body-label",
2328
+ className: "flex flex-col gap-2",
2329
+ children: [
2330
+ /* @__PURE__ */ z("div", {
2331
+ className: "flex flex-wrap items-center justify-between gap-2",
2332
+ children: [/* @__PURE__ */ R("span", {
2333
+ id: "entry-body-label",
2334
+ className: "text-label text-content",
2335
+ children: "Body"
2336
+ }), /* @__PURE__ */ R(_, {
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__ */ R(cr, {
2345
+ ...e,
2346
+ revealRef: c
2347
+ }, r) : /* @__PURE__ */ z(L, { children: [
2348
+ /* @__PURE__ */ R("textarea", {
2349
+ id: "entry-body",
2350
+ "aria-labelledby": "entry-body-label",
2351
+ "aria-describedby": m("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: m(O, "resize-y font-mono text-small leading-relaxed")
2361
+ }),
2362
+ /* @__PURE__ */ z("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__ */ R("ul", {
2372
+ id: "entry-body-issues",
2373
+ className: "flex flex-col gap-1 text-small text-danger",
2374
+ children: o.map((e) => /* @__PURE__ */ z("li", { children: [
2375
+ "Line ",
2376
+ e.line,
2377
+ ": ",
2378
+ e.message
2379
+ ] }, `${String(e.line)}${e.message}`))
2380
+ })
2381
+ ] }),
2382
+ /* @__PURE__ */ R(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__ */ z("div", {
2392
+ className: "flex flex-col gap-2",
2393
+ children: [/* @__PURE__ */ R("p", {
2394
+ id: "entry-body-a11y-label",
2395
+ className: "text-label text-content",
2396
+ children: "Accessibility notes in the body"
2397
+ }), /* @__PURE__ */ R("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__ */ z("li", {
2403
+ className: "flex flex-wrap items-start justify-between gap-2 text-small text-content",
2404
+ children: [/* @__PURE__ */ z("p", {
2405
+ id: i,
2406
+ className: "m-0 flex min-w-0 flex-1 gap-2",
2407
+ children: [/* @__PURE__ */ R(ee, {
2408
+ name: "warning",
2409
+ size: 16,
2410
+ className: "mt-0.5 text-warning"
2411
+ }), /* @__PURE__ */ z("span", { children: [t && e.target.kind === "body" ? `Line ${String(e.target.line)}. ` : "", /* @__PURE__ */ R(v, { note: e })] })]
2412
+ }), /* @__PURE__ */ R(_, {
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 = Ct.extend({ addNodeView() {
2426
+ return J(Jn);
2427
+ } }), $n = wt.extend({ addNodeView() {
2428
+ return J(Wn);
2429
+ } }), er = Et.extend({ addNodeView() {
2430
+ return J(Kn, { as: "span" });
2431
+ } }), tr = Tt.extend({ addNodeView() {
2432
+ return J(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 = ft(e, t), a = i && i.type !== "vesperInline" ? i.pos : pt(e, t);
2447
+ return a !== null && (ht(e, a, r), !0);
2448
+ };
2449
+ return W.create({
2450
+ name: "vesperShortcuts",
2451
+ addKeyboardShortcuts() {
2452
+ let i = this.editor;
2453
+ return {
2454
+ "Mod-k": () => (e.onLink(), !0),
2455
+ Escape: () => {
2456
+ if (!ft(i, t)) {
2457
+ let e = pt(i, t);
2458
+ if (e !== null) return mt(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 = ft(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
+ [T ? "Mod-ArrowUp" : "Mod-Home"]: () => ir(i, "start"),
2469
+ [T ? "Mod-ArrowDown" : "Mod-End"]: () => ir(i, "end")
2470
+ };
2471
+ },
2472
+ addProseMirrorPlugins() {
2473
+ return [new ye({ 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" ? xe.atStart(n) : xe.atEnd(n);
2479
+ return e.view.dispatch(e.state.tr.setSelection(r).scrollIntoView()), !0;
2480
+ }
2481
+ function ar(e, t) {
2482
+ if (!T || !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 Se)) 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 = ft(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 = qt(String(r.attrs.blockType ?? ""));
2503
+ else if (r.type.name === "vesperInline") {
2504
+ let e = qe(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 ?? X(e, n);
2509
+ }
2510
+ return `${i} selected. Press Enter for its settings.`;
2511
+ }
2512
+ function cr({ value: t, onChange: n, format: r, disabled: i, entryPath: a, imageFolder: s, partials: c = null, headingStart: d = 2, revealRef: f }) {
2513
+ let { manifest: p, loadMdxProps: h } = o(), g = F(null), _ = F(n);
2514
+ M(() => {
2515
+ _.current = n;
2516
+ });
2517
+ let [v, ee] = I(!1), y = F(null), [b, x] = I(!1), [S, C] = I(null), te = l(S), [w, T] = I(null), E = nn(), [D, O] = I(""), k = F(!1), [ne] = I(() => {
2518
+ let e = Ae(p, r);
2519
+ return {
2520
+ catalog: e,
2521
+ containers: Ot(e)
2522
+ };
2523
+ }), { catalog: A, containers: j } = ne, [N] = I(() => new nr()), [L] = I(() => {
2524
+ let e = (e) => Jt(e, A, j);
2525
+ return [
2526
+ Ee.configure({
2527
+ underline: !1,
2528
+ trailingNode: !1,
2529
+ link: {
2530
+ openOnClick: !1,
2531
+ autolink: !0,
2532
+ defaultProtocol: "https"
2533
+ }
2534
+ }),
2535
+ _e.configure({ inline: !0 }),
2536
+ ve,
2537
+ St,
2538
+ Qn,
2539
+ $n,
2540
+ er,
2541
+ tr,
2542
+ ...j.extensions.map((e) => e.extend({ addNodeView() {
2543
+ return J(Hn);
2544
+ } })),
2545
+ Zt({
2546
+ ...E,
2547
+ choices: e,
2548
+ choose: (e, t) => {
2549
+ N.actions.insert(e, t);
2550
+ },
2551
+ disabled: () => N.actions.disabled
2552
+ }),
2553
+ rr({
2554
+ containers: j,
2555
+ actions: () => N.actions,
2556
+ onLink: () => {
2557
+ ee(!0);
2558
+ }
2559
+ })
2560
+ ];
2561
+ }), V = Te({
2562
+ immediatelyRender: !0,
2563
+ shouldRerenderOnTransaction: !1,
2564
+ editable: !i,
2565
+ extensions: L,
2566
+ editorProps: {
2567
+ handleScrollToSelection: (e) => un(e, y.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
+ ...Qt(e, {
2574
+ ...E,
2575
+ count: (t) => Xt(Jt(e, A, j), t).length
2576
+ })
2577
+ })
2578
+ },
2579
+ onCreate: ({ editor: e }) => {
2580
+ let n = At(t, {
2581
+ format: r,
2582
+ markdown: e.markdown,
2583
+ catalog: A,
2584
+ containers: j,
2585
+ ...p.markdoc ? { markdoc: p.markdoc.options } : {}
2586
+ });
2587
+ e.commands.setContent(n.doc, { emitUpdate: !1 });
2588
+ let i = xe.findFrom(e.state.doc.resolve(0), 1, !0);
2589
+ i && e.view.dispatch(e.state.tr.setSelection(i)), g.current = {
2590
+ built: n,
2591
+ initial: Rt(e.getJSON(), j)
2592
+ };
2593
+ },
2594
+ onUpdate: ({ editor: e }) => {
2595
+ if (!g.current) return;
2596
+ let t = Bt(e.getJSON(), g.current.initial, {
2597
+ markdown: e.markdown,
2598
+ containers: j,
2599
+ parsed: g.current.built.parsed,
2600
+ format: r,
2601
+ ...p.markdoc ? { markdoc: p.markdoc.options } : {}
2602
+ });
2603
+ _.current(B(g.current.built.parsed, t));
2604
+ }
2605
+ });
2606
+ function re(e, t) {
2607
+ k.current = e.kind.builtin === "table";
2608
+ let n = yt(V, e.kind, e.shape, j, t, H(e));
2609
+ n !== null && (e.kind.fields.length > 0 || e.shape === "inline") && T(n);
2610
+ }
2611
+ function H(e) {
2612
+ if (e.kind.builtin !== "partial") return {};
2613
+ let [t] = wn(c ?? [], a);
2614
+ return t ? { file: Tn(a, t) } : {};
2615
+ }
2616
+ M(() => {
2617
+ N.update({
2618
+ open: (e) => {
2619
+ if (V.state.doc.nodeAt(e)?.type.name === "vesperTable") {
2620
+ let t = V.view.nodeDOM(e);
2621
+ t instanceof HTMLElement && or(t);
2622
+ } else T(e);
2623
+ },
2624
+ insert: re,
2625
+ disabled: i
2626
+ });
2627
+ });
2628
+ let ie = P(() => e({
2629
+ manifest: p,
2630
+ format: r,
2631
+ loadMdxProps: h,
2632
+ partials: c,
2633
+ entryPath: a
2634
+ }), [
2635
+ p,
2636
+ r,
2637
+ h,
2638
+ c,
2639
+ a
2640
+ ]), U = P(() => ({
2641
+ catalog: A,
2642
+ containers: j,
2643
+ disabled: i,
2644
+ checks: ie,
2645
+ partials: c,
2646
+ entryPath: a,
2647
+ openSettings: (e) => {
2648
+ T(e);
2649
+ },
2650
+ move: (e, t) => {
2651
+ let n = ht(V, e, t);
2652
+ n !== null && T((e) => e === null ? null : n);
2653
+ },
2654
+ remove: (e) => {
2655
+ gt(V, e);
2656
+ },
2657
+ announce: (e) => {
2658
+ O((t) => t === e ? `${e}\u00a0` : e);
2659
+ },
2660
+ checkTable: (e, t) => Gt(e, t, {
2661
+ markdown: V.markdown,
2662
+ containers: j,
2663
+ format: r,
2664
+ ...g.current ? { parsed: g.current.built.parsed } : {},
2665
+ ...p.markdoc ? { markdoc: p.markdoc.options } : {}
2666
+ }),
2667
+ takeNewTable: () => {
2668
+ let e = k.current;
2669
+ return k.current = !1, e;
2670
+ }
2671
+ }), [
2672
+ A,
2673
+ j,
2674
+ i,
2675
+ ie,
2676
+ c,
2677
+ a,
2678
+ V,
2679
+ r,
2680
+ p.markdoc
2681
+ ]), ae = F(t);
2682
+ M(() => {
2683
+ ae.current = t;
2684
+ }), M(() => (f.current = (e) => {
2685
+ on(V, ae.current, e, {
2686
+ format: r,
2687
+ containers: j,
2688
+ ...p.markdoc ? { markdoc: p.markdoc.options } : {}
2689
+ });
2690
+ }, () => {
2691
+ f.current = null;
2692
+ }), [
2693
+ V,
2694
+ r,
2695
+ j,
2696
+ p.markdoc,
2697
+ f
2698
+ ]);
2699
+ let oe = Y({
2700
+ editor: V,
2701
+ selector: ({ editor: e }) => sr(e, {
2702
+ catalog: A,
2703
+ containers: j
2704
+ })
2705
+ }), se = A.kinds.size > 0;
2706
+ return /* @__PURE__ */ R(fn.Provider, {
2707
+ value: U,
2708
+ children: /* @__PURE__ */ z("div", {
2709
+ "data-vesper-body": "",
2710
+ className: "flex flex-col gap-2",
2711
+ children: [
2712
+ /* @__PURE__ */ z("div", {
2713
+ className: m("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__ */ R("div", {
2715
+ ref: y,
2716
+ className: cn,
2717
+ children: /* @__PURE__ */ R(lr, {
2718
+ editor: V,
2719
+ disabled: i,
2720
+ headingStart: d,
2721
+ onLink: () => {
2722
+ ee(!0);
2723
+ },
2724
+ onImage: () => {
2725
+ x(!0);
2726
+ },
2727
+ insert: /* @__PURE__ */ R(tn, {
2728
+ editor: V,
2729
+ choices: (e) => Jt(e, A, j),
2730
+ onChoose: (e) => {
2731
+ re(e);
2732
+ },
2733
+ disabled: i
2734
+ })
2735
+ })
2736
+ }), /* @__PURE__ */ R(Ce, { editor: V })]
2737
+ }),
2738
+ /* @__PURE__ */ R($t, {
2739
+ editor: V,
2740
+ ...E,
2741
+ choices: (e) => Jt(e, A, j),
2742
+ onChoose: (e, t) => {
2743
+ re(e, t);
2744
+ }
2745
+ }),
2746
+ /* @__PURE__ */ R("p", {
2747
+ className: "sr-only",
2748
+ role: "status",
2749
+ children: oe
2750
+ }),
2751
+ /* @__PURE__ */ R("div", {
2752
+ className: "sr-only",
2753
+ role: "status",
2754
+ children: D
2755
+ }),
2756
+ /* @__PURE__ */ z("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
+ se ? " 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__ */ R(hn, {
2767
+ editor: V,
2768
+ pos: w,
2769
+ onClose: () => {
2770
+ let e = w;
2771
+ T(null);
2772
+ let t = V.view.dom, n = !1, r = () => {
2773
+ if (n || V.isDestroyed) return;
2774
+ n = !0, t.removeEventListener("focusin", i), V.view.focus();
2775
+ let r = e === null ? null : V.state.doc.nodeAt(e);
2776
+ e !== null && r && dt(r.type.name, j) && V.view.dispatch(V.state.tr.setSelection(K.create(V.state.doc, e)));
2777
+ }, i = () => setTimeout(r, 0);
2778
+ t.addEventListener("focusin", i), setTimeout(r, 500);
2779
+ }
2780
+ }),
2781
+ /* @__PURE__ */ R(dr, {
2782
+ editor: V,
2783
+ isOpen: v,
2784
+ onOpenChange: ee
2785
+ }),
2786
+ /* @__PURE__ */ R(u, {
2787
+ isOpen: b,
2788
+ onOpenChange: x,
2789
+ kind: "image",
2790
+ folder: s,
2791
+ onChoose: (e) => {
2792
+ C(e);
2793
+ }
2794
+ }),
2795
+ /* @__PURE__ */ R(pr, {
2796
+ path: S,
2797
+ previewUrl: te,
2798
+ onCancel: () => {
2799
+ C(null), V.commands.focus();
2800
+ },
2801
+ onInsert: (e) => {
2802
+ S && (V.chain().focus().setImage({
2803
+ src: pe(S, a),
2804
+ alt: e
2805
+ }).run(), C(null));
2806
+ }
2807
+ })
2808
+ ]
2809
+ })
2810
+ });
2811
+ }
2812
+ function lr({ editor: e, disabled: t, headingStart: n, onLink: i, onImage: o, insert: c }) {
2813
+ let l = Y({
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
+ }), u = () => e.chain().focus();
2826
+ return /* @__PURE__ */ z(s, {
2827
+ label: "Formatting",
2828
+ children: [
2829
+ /* @__PURE__ */ R(k, {
2830
+ icon: "bold",
2831
+ label: "Bold",
2832
+ shortcut: y("Mod", "B"),
2833
+ isDisabled: t,
2834
+ isSelected: l.bold,
2835
+ onChange: () => u().toggleBold().run()
2836
+ }),
2837
+ /* @__PURE__ */ R(k, {
2838
+ icon: "italic",
2839
+ label: "Italic",
2840
+ shortcut: y("Mod", "I"),
2841
+ isDisabled: t,
2842
+ isSelected: l.italic,
2843
+ onChange: () => u().toggleItalic().run()
2844
+ }),
2845
+ /* @__PURE__ */ R(a, {}),
2846
+ /* @__PURE__ */ R(ur, {
2847
+ editor: e,
2848
+ level: l.level,
2849
+ start: n,
2850
+ disabled: t
2851
+ }),
2852
+ /* @__PURE__ */ R(a, {}),
2853
+ /* @__PURE__ */ R(k, {
2854
+ icon: "bullets",
2855
+ label: "Bullets",
2856
+ shortcut: y("Mod", "Shift", "8"),
2857
+ isDisabled: t,
2858
+ isSelected: l.bullets,
2859
+ onChange: () => u().toggleBulletList().run()
2860
+ }),
2861
+ /* @__PURE__ */ R(k, {
2862
+ icon: "numbers",
2863
+ label: "Numbers",
2864
+ shortcut: y("Mod", "Shift", "7"),
2865
+ isDisabled: t,
2866
+ isSelected: l.numbers,
2867
+ onChange: () => u().toggleOrderedList().run()
2868
+ }),
2869
+ /* @__PURE__ */ R(k, {
2870
+ icon: "quote",
2871
+ label: "Quote",
2872
+ shortcut: y("Mod", "Shift", "B"),
2873
+ isDisabled: t,
2874
+ isSelected: l.quote,
2875
+ onChange: () => u().toggleBlockquote().run()
2876
+ }),
2877
+ /* @__PURE__ */ R(k, {
2878
+ icon: "code",
2879
+ label: "Code",
2880
+ shortcut: y("Mod", "E"),
2881
+ isDisabled: t,
2882
+ isSelected: l.code,
2883
+ onChange: () => u().toggleCode().run()
2884
+ }),
2885
+ /* @__PURE__ */ R(a, {}),
2886
+ /* @__PURE__ */ R(r, {
2887
+ icon: "link",
2888
+ label: l.link ? "Edit link" : "Link",
2889
+ shortcut: y("Mod", "K"),
2890
+ isDisabled: t,
2891
+ onPress: i
2892
+ }),
2893
+ /* @__PURE__ */ R(r, {
2894
+ icon: "image",
2895
+ label: "Image",
2896
+ isDisabled: t,
2897
+ onPress: o
2898
+ }),
2899
+ c
2900
+ ]
2901
+ });
2902
+ }
2903
+ function ur({ editor: e, level: t, start: n, disabled: i }) {
2904
+ let a = t === 0 ? "Paragraph" : `Heading ${String(t)}`, 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(n, 6)).map((e) => ({
2915
+ id: String(e),
2916
+ label: `Heading ${String(e)}`
2917
+ }))];
2918
+ return /* @__PURE__ */ R(h, {
2919
+ label: "Text style",
2920
+ items: [],
2921
+ onAction: () => void 0,
2922
+ trigger: /* @__PURE__ */ z(r, {
2923
+ "aria-label": `Text style: ${a}`,
2924
+ isDisabled: i,
2925
+ className: "w-28 gap-1",
2926
+ children: [/* @__PURE__ */ R("span", {
2927
+ className: "min-w-0 flex-1 truncate text-left",
2928
+ children: a
2929
+ }), /* @__PURE__ */ R(E, {})]
2930
+ }),
2931
+ choice: {
2932
+ title: "Text style",
2933
+ options: o,
2934
+ selected: String(t),
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__ */ R(b, {
2950
+ title: r ? "Edit link" : "Add a link",
2951
+ isOpen: t,
2952
+ onOpenChange: (e) => {
2953
+ e ? n(!0) : i();
2954
+ },
2955
+ children: t && /* @__PURE__ */ R(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] = I(t ?? ""), a = te(), o = P(() => x(a), [a]);
2964
+ return /* @__PURE__ */ z("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__ */ R(f, {
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__ */ z("div", {
2979
+ className: "flex flex-wrap justify-end gap-3",
2980
+ children: [t && /* @__PURE__ */ R(_, {
2981
+ variant: "quiet",
2982
+ onPress: () => {
2983
+ e.chain().focus().extendMarkRange("link").unsetLink().run(), n();
2984
+ },
2985
+ children: "Remove link"
2986
+ }), /* @__PURE__ */ R(_, {
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, a] = I(""), [o, s] = I(!1), [l, u] = I(!1);
2996
+ return /* @__PURE__ */ R(b, {
2997
+ title: "Describe the image",
2998
+ isOpen: e !== null,
2999
+ onOpenChange: (e) => {
3000
+ e || n();
3001
+ },
3002
+ children: /* @__PURE__ */ z("form", {
3003
+ className: "flex flex-col gap-4",
3004
+ onSubmit: (e) => {
3005
+ e.preventDefault(), !o && i.trim() === "" ? u(!0) : (r(o ? "" : i.trim()), a(""), s(!1), u(!1));
3006
+ },
3007
+ children: [
3008
+ t && /* @__PURE__ */ R("img", {
3009
+ src: t,
3010
+ alt: "",
3011
+ className: "max-h-40 self-start rounded-md object-contain"
3012
+ }),
3013
+ e && /* @__PURE__ */ R("p", {
3014
+ className: "text-small text-content-muted",
3015
+ children: e.slice(e.lastIndexOf("/") + 1)
3016
+ }),
3017
+ !o && /* @__PURE__ */ R(w, {
3018
+ label: "Alt text",
3019
+ isRequired: !0,
3020
+ description: "Describe what this image communicates here.",
3021
+ value: i,
3022
+ onChange: (e) => {
3023
+ a(e), u(!1);
3024
+ },
3025
+ isInvalid: l,
3026
+ errorMessage: "Describe the image, or mark it decorative.",
3027
+ rows: 2
3028
+ }),
3029
+ /* @__PURE__ */ R(c, {
3030
+ isSelected: o,
3031
+ onChange: s,
3032
+ children: "Decorative image (it adds nothing a reader needs)"
3033
+ }),
3034
+ /* @__PURE__ */ R("div", {
3035
+ className: "flex justify-end",
3036
+ children: /* @__PURE__ */ R(_, {
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, cn as n, un as t };