@damiro/stylo 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +144 -0
  3. package/dist/InPlaceView-Ba7JCZ2Y.js +2346 -0
  4. package/dist/InPlaceView-Ba7JCZ2Y.js.map +1 -0
  5. package/dist/Preview-Dxb9zPVv.js +93 -0
  6. package/dist/Preview-Dxb9zPVv.js.map +1 -0
  7. package/dist/SplitView.d.ts +23 -0
  8. package/dist/SplitView.d.ts.map +1 -0
  9. package/dist/Stylo.d.ts +15 -0
  10. package/dist/Stylo.d.ts.map +1 -0
  11. package/dist/callout-oLE630ZP.js +37 -0
  12. package/dist/callout-oLE630ZP.js.map +1 -0
  13. package/dist/callout.d.ts +18 -0
  14. package/dist/callout.d.ts.map +1 -0
  15. package/dist/config-DTBxVhtH.js +101 -0
  16. package/dist/config-DTBxVhtH.js.map +1 -0
  17. package/dist/editor/SourceView.d.ts +17 -0
  18. package/dist/editor/SourceView.d.ts.map +1 -0
  19. package/dist/editor/extensions.d.ts +20 -0
  20. package/dist/editor/extensions.d.ts.map +1 -0
  21. package/dist/editor/highlight.d.ts +19 -0
  22. package/dist/editor/highlight.d.ts.map +1 -0
  23. package/dist/editor/save.d.ts +12 -0
  24. package/dist/editor/save.d.ts.map +1 -0
  25. package/dist/editor/theme.d.ts +3 -0
  26. package/dist/editor/theme.d.ts.map +1 -0
  27. package/dist/editor/useCodeMirror.d.ts +26 -0
  28. package/dist/editor/useCodeMirror.d.ts.map +1 -0
  29. package/dist/frontmatter.d.ts +21 -0
  30. package/dist/frontmatter.d.ts.map +1 -0
  31. package/dist/index.d.ts +4 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/inplace/InPlaceView.d.ts +30 -0
  34. package/dist/inplace/InPlaceView.d.ts.map +1 -0
  35. package/dist/inplace/autoformat.d.ts +23 -0
  36. package/dist/inplace/autoformat.d.ts.map +1 -0
  37. package/dist/inplace/config.d.ts +57 -0
  38. package/dist/inplace/config.d.ts.map +1 -0
  39. package/dist/inplace/context-menu-actions.d.ts +53 -0
  40. package/dist/inplace/context-menu-actions.d.ts.map +1 -0
  41. package/dist/inplace/context-menu.d.ts +50 -0
  42. package/dist/inplace/context-menu.d.ts.map +1 -0
  43. package/dist/inplace/decorate.d.ts +17 -0
  44. package/dist/inplace/decorate.d.ts.map +1 -0
  45. package/dist/inplace/edit-boundaries.d.ts +59 -0
  46. package/dist/inplace/edit-boundaries.d.ts.map +1 -0
  47. package/dist/inplace/edit-insert-assoc.d.ts +17 -0
  48. package/dist/inplace/edit-insert-assoc.d.ts.map +1 -0
  49. package/dist/inplace/edit-line-prefix.d.ts +23 -0
  50. package/dist/inplace/edit-line-prefix.d.ts.map +1 -0
  51. package/dist/inplace/extension.d.ts +21 -0
  52. package/dist/inplace/extension.d.ts.map +1 -0
  53. package/dist/inplace/frontmatter.d.ts +13 -0
  54. package/dist/inplace/frontmatter.d.ts.map +1 -0
  55. package/dist/inplace/inline-md.d.ts +13 -0
  56. package/dist/inplace/inline-md.d.ts.map +1 -0
  57. package/dist/inplace/lazyInPlace.d.ts +7 -0
  58. package/dist/inplace/lazyInPlace.d.ts.map +1 -0
  59. package/dist/inplace/link-click.d.ts +24 -0
  60. package/dist/inplace/link-click.d.ts.map +1 -0
  61. package/dist/inplace/link-hover.d.ts +11 -0
  62. package/dist/inplace/link-hover.d.ts.map +1 -0
  63. package/dist/inplace/list-guides.d.ts +16 -0
  64. package/dist/inplace/list-guides.d.ts.map +1 -0
  65. package/dist/inplace/long-press.d.ts +39 -0
  66. package/dist/inplace/long-press.d.ts.map +1 -0
  67. package/dist/inplace/math.d.ts +16 -0
  68. package/dist/inplace/math.d.ts.map +1 -0
  69. package/dist/inplace/menu-plugin.d.ts +30 -0
  70. package/dist/inplace/menu-plugin.d.ts.map +1 -0
  71. package/dist/inplace/nodes.d.ts +24 -0
  72. package/dist/inplace/nodes.d.ts.map +1 -0
  73. package/dist/inplace/plugin.d.ts +21 -0
  74. package/dist/inplace/plugin.d.ts.map +1 -0
  75. package/dist/inplace/reveal.d.ts +8 -0
  76. package/dist/inplace/reveal.d.ts.map +1 -0
  77. package/dist/inplace/scan.d.ts +11 -0
  78. package/dist/inplace/scan.d.ts.map +1 -0
  79. package/dist/inplace/selection-bar.d.ts +38 -0
  80. package/dist/inplace/selection-bar.d.ts.map +1 -0
  81. package/dist/inplace/table-cell-dom.d.ts +30 -0
  82. package/dist/inplace/table-cell-dom.d.ts.map +1 -0
  83. package/dist/inplace/table-enter.d.ts +22 -0
  84. package/dist/inplace/table-enter.d.ts.map +1 -0
  85. package/dist/inplace/table-gizmos.d.ts +55 -0
  86. package/dist/inplace/table-gizmos.d.ts.map +1 -0
  87. package/dist/inplace/table-structure.d.ts +23 -0
  88. package/dist/inplace/table-structure.d.ts.map +1 -0
  89. package/dist/inplace/table-widget.d.ts +81 -0
  90. package/dist/inplace/table-widget.d.ts.map +1 -0
  91. package/dist/inplace/tables.d.ts +8 -0
  92. package/dist/inplace/tables.d.ts.map +1 -0
  93. package/dist/inplace/theme.d.ts +14 -0
  94. package/dist/inplace/theme.d.ts.map +1 -0
  95. package/dist/inplace/widgets.d.ts +25 -0
  96. package/dist/inplace/widgets.d.ts.map +1 -0
  97. package/dist/inplace/wikilinks.d.ts +10 -0
  98. package/dist/inplace/wikilinks.d.ts.map +1 -0
  99. package/dist/katex-BfiLlqfN.js +21979 -0
  100. package/dist/katex-BfiLlqfN.js.map +1 -0
  101. package/dist/katex.css +3 -0
  102. package/dist/markdown-N3lRmU2n.js +8524 -0
  103. package/dist/markdown-N3lRmU2n.js.map +1 -0
  104. package/dist/render/Preview.d.ts +10 -0
  105. package/dist/render/Preview.d.ts.map +1 -0
  106. package/dist/render/lazyPreview.d.ts +8 -0
  107. package/dist/render/lazyPreview.d.ts.map +1 -0
  108. package/dist/render/remark-callout.d.ts +10 -0
  109. package/dist/render/remark-callout.d.ts.map +1 -0
  110. package/dist/render/remark-wikilink.d.ts +8 -0
  111. package/dist/render/remark-wikilink.d.ts.map +1 -0
  112. package/dist/styles.css +2 -0
  113. package/dist/stylo.js +293 -0
  114. package/dist/stylo.js.map +1 -0
  115. package/dist/toolbar/Toolbar.d.ts +28 -0
  116. package/dist/toolbar/Toolbar.d.ts.map +1 -0
  117. package/dist/toolbar/block.d.ts +56 -0
  118. package/dist/toolbar/block.d.ts.map +1 -0
  119. package/dist/toolbar/cell-inline.d.ts +16 -0
  120. package/dist/toolbar/cell-inline.d.ts.map +1 -0
  121. package/dist/toolbar/commands.d.ts +25 -0
  122. package/dist/toolbar/commands.d.ts.map +1 -0
  123. package/dist/toolbar/config.d.ts +21 -0
  124. package/dist/toolbar/config.d.ts.map +1 -0
  125. package/dist/toolbar/fence.d.ts +28 -0
  126. package/dist/toolbar/fence.d.ts.map +1 -0
  127. package/dist/toolbar/floating-watchdog.d.ts +18 -0
  128. package/dist/toolbar/floating-watchdog.d.ts.map +1 -0
  129. package/dist/toolbar/icon-paths.d.ts +10 -0
  130. package/dist/toolbar/icon-paths.d.ts.map +1 -0
  131. package/dist/toolbar/icons.d.ts +10 -0
  132. package/dist/toolbar/icons.d.ts.map +1 -0
  133. package/dist/toolbar/inline-ops.d.ts +101 -0
  134. package/dist/toolbar/inline-ops.d.ts.map +1 -0
  135. package/dist/toolbar/inline.d.ts +38 -0
  136. package/dist/toolbar/inline.d.ts.map +1 -0
  137. package/dist/toolbar/keyboard-inset.d.ts +10 -0
  138. package/dist/toolbar/keyboard-inset.d.ts.map +1 -0
  139. package/dist/toolbar/keymap.d.ts +8 -0
  140. package/dist/toolbar/keymap.d.ts.map +1 -0
  141. package/dist/toolbar/labels.d.ts +16 -0
  142. package/dist/toolbar/labels.d.ts.map +1 -0
  143. package/dist/toolbar/table-grid.d.ts +23 -0
  144. package/dist/toolbar/table-grid.d.ts.map +1 -0
  145. package/dist/toolbar/table.d.ts +35 -0
  146. package/dist/toolbar/table.d.ts.map +1 -0
  147. package/dist/toolbar-settings/SortableRow.d.ts +15 -0
  148. package/dist/toolbar-settings/SortableRow.d.ts.map +1 -0
  149. package/dist/toolbar-settings/StyloToolbarSettings.d.ts +29 -0
  150. package/dist/toolbar-settings/StyloToolbarSettings.d.ts.map +1 -0
  151. package/dist/toolbar-settings/index.d.ts +3 -0
  152. package/dist/toolbar-settings/index.d.ts.map +1 -0
  153. package/dist/toolbar-settings/items.d.ts +24 -0
  154. package/dist/toolbar-settings/items.d.ts.map +1 -0
  155. package/dist/toolbar-settings.js +269 -0
  156. package/dist/toolbar-settings.js.map +1 -0
  157. package/dist/types.d.ts +264 -0
  158. package/dist/types.d.ts.map +1 -0
  159. package/dist/useCodeMirror-YnIFkvKn.js +1361 -0
  160. package/dist/useCodeMirror-YnIFkvKn.js.map +1 -0
  161. package/dist/wikilink-BFpTehto.js +42 -0
  162. package/dist/wikilink-BFpTehto.js.map +1 -0
  163. package/dist/wikilink.d.ts +11 -0
  164. package/dist/wikilink.d.ts.map +1 -0
  165. package/package.json +122 -0
@@ -0,0 +1,2346 @@
1
+ import { i as e, n as t, t as n } from "./wikilink-BFpTehto.js";
2
+ import { _ as r, a as i, b as a, c as o, d as s, f as c, g as l, h as u, i as d, l as f, m as p, n as m, o as ee, p as h, r as te, s as ne, t as re, u as ie, v as ae, y as oe } from "./useCodeMirror-YnIFkvKn.js";
3
+ import { a as se, i as g } from "./config-DTBxVhtH.js";
4
+ import { t as ce } from "./katex-BfiLlqfN.js";
5
+ import { r as le, t as _ } from "./callout-oLE630ZP.js";
6
+ import { useRef as ue, useState as de } from "react";
7
+ import { Decoration as v, EditorView as y, ViewPlugin as b, WidgetType as x, hoverTooltip as fe, keymap as pe } from "@codemirror/view";
8
+ import { Annotation as me, EditorSelection as he, EditorState as ge, Facet as S, Prec as C, StateField as w } from "@codemirror/state";
9
+ import { syntaxTree as T } from "@codemirror/language";
10
+ import { jsx as _e } from "react/jsx-runtime";
11
+ //#region src/inplace/config.ts
12
+ var ve = {
13
+ headings: !0,
14
+ emphasis: !0,
15
+ links: !0,
16
+ wikilinks: !0,
17
+ math: !0,
18
+ lists: !0,
19
+ tasks: !0,
20
+ blockquote: !0,
21
+ horizontalRule: !0,
22
+ code: !0,
23
+ frontmatter: !0,
24
+ tables: !0
25
+ };
26
+ function ye(e) {
27
+ return {
28
+ ...ve,
29
+ ...e?.decorations
30
+ };
31
+ }
32
+ var E = S.define({ combine: (e) => e[0] ?? ve }), D = S.define({ combine: (e) => e[0] ?? "source" }), O = S.define({ combine: (e) => e[0] ?? "caret" }), be = S.define({ combine: (e) => e[0] ?? null }), k = S.define({ combine: (e) => e[0] ?? !0 }), A = [
33
+ "link",
34
+ "format",
35
+ "paragraph",
36
+ "insert",
37
+ "clipboard"
38
+ ], j = [
39
+ "bold",
40
+ "italic",
41
+ "strike",
42
+ "code",
43
+ "link",
44
+ "wikilink",
45
+ "math"
46
+ ];
47
+ function xe(e) {
48
+ return e === !1 ? {
49
+ enabled: !1,
50
+ groups: []
51
+ } : e == null || e === !0 ? {
52
+ enabled: !0,
53
+ groups: A
54
+ } : {
55
+ enabled: !0,
56
+ groups: e.groups?.length ? e.groups : A
57
+ };
58
+ }
59
+ var M = S.define({ combine: (e) => e[0] ?? A });
60
+ function Se(e) {
61
+ if (!e?.length) return j;
62
+ let t = e.filter((e) => j.includes(e));
63
+ return t.length ? t : j;
64
+ }
65
+ var Ce = S.define({ combine: (e) => e[0] ?? j }), N = S.define({ combine: (e) => e[0] ?? "menu" });
66
+ //#endregion
67
+ //#region src/inplace/frontmatter.ts
68
+ function we(e) {
69
+ if (!e.facet(E).frontmatter) return v.none;
70
+ let n = t(e.doc);
71
+ if (!n) return v.none;
72
+ let r = e.doc.lineAt(n.from).number, i = e.doc.lineAt(n.to).number, a = e.selection.ranges.some((t) => {
73
+ let n = e.doc.lineAt(t.from).number;
74
+ return n >= r && n <= i;
75
+ }), o = [];
76
+ for (let t = r; t <= i; t++) {
77
+ let n = e.doc.line(t), s = t === r ? "cm-inplace-fm cm-inplace-fm-first" : "cm-inplace-fm";
78
+ o.push(v.line({ class: s }).range(n.from)), (t === r || t === i) && !a && n.to > n.from && o.push(v.replace({}).range(n.from, n.to));
79
+ }
80
+ return v.set(o, !0);
81
+ }
82
+ var Te = w.define({
83
+ create: we,
84
+ update: (e, t) => t.docChanged || t.selection ? we(t.state) : e,
85
+ provide: (e) => y.decorations.from(e)
86
+ });
87
+ //#endregion
88
+ //#region src/inplace/list-guides.ts
89
+ function Ee(e) {
90
+ let t = 1;
91
+ for (let n = e.node.parent; n; n = n.parent) n.name === "ListItem" && t++;
92
+ return t;
93
+ }
94
+ function De(e, t, n, r, i, a) {
95
+ if (!i.lists) return;
96
+ let o = /* @__PURE__ */ new Set();
97
+ n.iterate({
98
+ from: e,
99
+ to: t,
100
+ enter: (e) => {
101
+ if (e.name !== "ListItem") return;
102
+ let t = Ee(e) - 1;
103
+ if (t < 1) return;
104
+ let n = r.lineAt(e.from).number, i = e.node.getChild("BulletList") ?? e.node.getChild("OrderedList"), s = r.lineAt(i ? i.from - 1 : Math.min(e.to, r.length)).number;
105
+ for (let e = n; e <= s; e++) o.has(e) || (o.add(e), a.push(v.line({
106
+ class: "cm-inplace-li",
107
+ attributes: { style: `--sl-li-depth:${t}` }
108
+ }).range(r.line(e).from)));
109
+ }
110
+ });
111
+ }
112
+ //#endregion
113
+ //#region src/inplace/reveal.ts
114
+ function P(e) {
115
+ let t = /* @__PURE__ */ new Set();
116
+ for (let n of e.selection.ranges) {
117
+ let r = e.doc.lineAt(n.from).number, i = e.doc.lineAt(n.to).number;
118
+ for (let e = r; e <= i; e++) t.add(e);
119
+ }
120
+ return t;
121
+ }
122
+ //#endregion
123
+ //#region src/inplace/scan.ts
124
+ var Oe = /* @__PURE__ */ new Set([
125
+ "InlineCode",
126
+ "FencedCode",
127
+ "CodeBlock",
128
+ "CodeText"
129
+ ]);
130
+ function F(e, t) {
131
+ let n = e.resolveInner(t, 1);
132
+ for (;;) {
133
+ if (Oe.has(n.name)) return !0;
134
+ let e = n.parent;
135
+ if (!e) return !1;
136
+ n = e;
137
+ }
138
+ }
139
+ function I(e, t, n, r) {
140
+ let i = t.lineAt(n).number, a = t.lineAt(r).number;
141
+ for (let t = i; t <= a; t++) if (e.has(t)) return !0;
142
+ return !1;
143
+ }
144
+ //#endregion
145
+ //#region src/inplace/math.ts
146
+ var ke = /(?<![\w$])\$(?!\s)([^\n$]+?)(?<!\s)\$(?![\w$])/g, Ae = /(?<![\w$])\$\$([^\n$]+?)\$\$(?![\w$])/g, je = /(?<![\w$])\$\$([^]+?)\$\$/g, L = class extends x {
147
+ src;
148
+ block;
149
+ constructor(e, t) {
150
+ super(), this.src = e, this.block = t;
151
+ }
152
+ eq(e) {
153
+ return e.src === this.src && e.block === this.block;
154
+ }
155
+ toDOM() {
156
+ let e = document.createElement(this.block ? "div" : "span");
157
+ e.className = this.block ? "cm-inplace-math cm-inplace-math-block" : "cm-inplace-math";
158
+ try {
159
+ ce.render(this.src, e, {
160
+ displayMode: this.block,
161
+ throwOnError: !1
162
+ });
163
+ } catch {
164
+ e.textContent = this.block ? `$$${this.src}$$` : `$${this.src}$`;
165
+ }
166
+ return e;
167
+ }
168
+ ignoreEvent() {
169
+ return !1;
170
+ }
171
+ };
172
+ function Me(e, t, n, r, i, a) {
173
+ let o = e.state.doc.sliceString(t, n);
174
+ if (!o.includes("$")) return;
175
+ let { doc: s } = e.state, c = [];
176
+ for (let e of o.matchAll(Ae)) {
177
+ let n = (e[1] ?? "").trim(), o = t + (e.index ?? 0), l = o + (e[0] ?? "").length;
178
+ !n || F(i, o + 2) || (c.push([o, l]), !I(r, s, o, l) && a.push(v.replace({ widget: new L(n, !0) }).range(o, l)));
179
+ }
180
+ for (let e of o.matchAll(ke)) {
181
+ let n = (e[1] ?? "").trim(), o = t + (e.index ?? 0), l = o + (e[0] ?? "").length;
182
+ !n || F(i, o + 1) || c.some(([e, t]) => o >= e && l <= t) || I(r, s, o, l) || a.push(v.replace({ widget: new L(n, !1) }).range(o, l));
183
+ }
184
+ }
185
+ var Ne = w.define({
186
+ create: Pe,
187
+ update(e, t) {
188
+ return t.docChanged || t.selection ? Pe(t.state) : e;
189
+ },
190
+ provide: (e) => [y.decorations.from(e), y.atomicRanges.of((t) => t.state.field(e))]
191
+ });
192
+ function Pe(e) {
193
+ if (!e.facet(E).math) return v.none;
194
+ let t = e.doc.toString();
195
+ if (!t.includes("$$")) return v.none;
196
+ let n = [], r = P(e), i = T(e);
197
+ for (let a of t.matchAll(je)) {
198
+ let t = a[0] ?? "", o = (a[1] ?? "").trim();
199
+ if (!o || !t.includes("\n")) continue;
200
+ let s = a.index ?? 0, c = s + t.length, l = e.doc.lineAt(s), u = e.doc.lineAt(c), d = e.doc.sliceString(l.from, s).trim(), f = e.doc.sliceString(c, u.to).trim();
201
+ d === "" && f === "" && (F(i, s + 2) || I(r, e.doc, s, c) || n.push(v.replace({
202
+ widget: new L(o, !0),
203
+ block: !0
204
+ }).range(s, c)));
205
+ }
206
+ return v.set(n, !0);
207
+ }
208
+ //#endregion
209
+ //#region src/inplace/widgets.ts
210
+ var Fe = class extends x {
211
+ eq() {
212
+ return !0;
213
+ }
214
+ toDOM() {
215
+ let e = document.createElement("hr");
216
+ return e.className = "cm-inplace-hr", e;
217
+ }
218
+ ignoreEvent() {
219
+ return !1;
220
+ }
221
+ }, Ie = class extends x {
222
+ eq() {
223
+ return !0;
224
+ }
225
+ toDOM() {
226
+ let e = document.createElement("span");
227
+ return e.className = "cm-inplace-bullet", e.textContent = "•", e;
228
+ }
229
+ ignoreEvent() {
230
+ return !1;
231
+ }
232
+ }, Le = class extends x {
233
+ checked;
234
+ constructor(e) {
235
+ super(), this.checked = e;
236
+ }
237
+ eq(e) {
238
+ return e.checked === this.checked;
239
+ }
240
+ toDOM(e) {
241
+ let t = document.createElement("input");
242
+ return t.type = "checkbox", t.checked = this.checked, t.className = "cm-inplace-checkbox", t.addEventListener("mousedown", (e) => e.stopPropagation()), t.addEventListener("change", () => {
243
+ let n = e.posAtDOM(t) + 1;
244
+ e.dispatch({ changes: {
245
+ from: n,
246
+ to: n + 1,
247
+ insert: this.checked ? " " : "x"
248
+ } });
249
+ }), t;
250
+ }
251
+ ignoreEvent() {
252
+ return !0;
253
+ }
254
+ }, Re = /^ATXHeading([1-6])$/, ze = /^SetextHeading([12])$/, Be = /^[-*+]$/, Ve = {
255
+ StrongEmphasis: {
256
+ mark: "EmphasisMark",
257
+ className: "cm-inplace-strong",
258
+ toggle: "emphasis"
259
+ },
260
+ Emphasis: {
261
+ mark: "EmphasisMark",
262
+ className: "cm-inplace-em",
263
+ toggle: "emphasis"
264
+ },
265
+ Strikethrough: {
266
+ mark: "StrikethroughMark",
267
+ className: "cm-inplace-strike",
268
+ toggle: "emphasis"
269
+ },
270
+ InlineCode: {
271
+ mark: "CodeMark",
272
+ className: "cm-inplace-code",
273
+ toggle: "code"
274
+ }
275
+ };
276
+ function He(e, t) {
277
+ let { doc: n, revealed: r, caretRevealed: i, out: a, toggles: o, fmEnd: s, quoteRevealed: c } = t;
278
+ if (e.to <= s) return !1;
279
+ let l = Re.exec(e.name);
280
+ if (l) {
281
+ if (o.headings) {
282
+ let t = n.lineAt(e.from);
283
+ if (a.push(v.line({
284
+ class: `cm-inplace-heading cm-inplace-h${l[1]}`,
285
+ attributes: {
286
+ role: "heading",
287
+ "aria-level": l[1]
288
+ }
289
+ }).range(t.from)), !r.has(t.number)) {
290
+ let n = e.node.firstChild;
291
+ n?.name === "HeaderMark" && a.push(v.replace({}).range(n.from, Math.min(n.to + 1, t.to)));
292
+ }
293
+ }
294
+ return;
295
+ }
296
+ let u = ze.exec(e.name);
297
+ if (u) {
298
+ if (o.headings) {
299
+ let t = n.lineAt(e.from);
300
+ a.push(v.line({
301
+ class: `cm-inplace-heading cm-inplace-h${u[1]}`,
302
+ attributes: {
303
+ role: "heading",
304
+ "aria-level": u[1]
305
+ }
306
+ }).range(t.from));
307
+ let r = e.node.getChild("HeaderMark");
308
+ if (r) {
309
+ let e = n.lineAt(r.from);
310
+ !i.has(t.number) && !i.has(e.number) && (a.push(v.line({ class: "cm-inplace-setext-rule" }).range(e.from)), a.push(v.replace({}).range(r.from, r.to)));
311
+ }
312
+ }
313
+ return;
314
+ }
315
+ let d = Ve[e.name];
316
+ if (d) {
317
+ if (!o[d.toggle]) return;
318
+ let t = e.node.getChildren(d.mark), i = t[0], s = t[t.length - 1], c = i && s && i !== s, l = c ? i.to : e.from, u = c ? s.from : e.to;
319
+ u > l && a.push(v.mark({ class: d.className }).range(l, u)), c && !r.has(n.lineAt(e.from).number) && (a.push(v.replace({}).range(i.from, i.to)), a.push(v.replace({}).range(s.from, s.to)));
320
+ return;
321
+ }
322
+ if (e.name === "Link") {
323
+ let t = n.sliceString(Math.max(0, e.from - 1), e.from), i = n.sliceString(e.to, e.to + 1);
324
+ if (t === "[" && i === "]" || !o.links) return !1;
325
+ let s = n.lineAt(e.from), c = _.exec(s.text);
326
+ if (c && e.from - s.from < c[1].length + c[2].length) return !1;
327
+ let l = e.node.getChildren("LinkMark");
328
+ if (l.length >= 2) {
329
+ let t = l[0], i = l[1];
330
+ i.from > t.to && a.push(v.mark({ class: "cm-inplace-link" }).range(t.to, i.from)), r.has(n.lineAt(e.from).number) || (a.push(v.replace({}).range(e.from, t.to)), a.push(v.replace({}).range(i.from, e.to)));
331
+ }
332
+ return;
333
+ }
334
+ if (e.name === "HorizontalRule") {
335
+ if (!o.horizontalRule) return !1;
336
+ let t = n.lineAt(e.from);
337
+ return i.has(t.number) || (a.push(v.line({ class: "cm-inplace-hr-line" }).range(t.from)), a.push(v.replace({ widget: new Fe() }).range(t.from, t.to))), !1;
338
+ }
339
+ if (e.name === "Blockquote") {
340
+ if (o.blockquote) {
341
+ let t = n.lineAt(e.from).number, o = n.lineAt(Math.min(e.to, n.length)).number, s = n.line(t), l = _.exec(s.text), u = l ? le(l[3]) : null, d = !1;
342
+ for (let e = t; e <= o; e++) i.has(e) && (d = !0);
343
+ if (d) for (let e = t; e <= o; e++) c.add(e);
344
+ for (let e = t; e <= o; e++) {
345
+ let r = u ? `cm-inplace-callout cm-inplace-callout-${u}` : "cm-inplace-quote";
346
+ u && e === t && (r += " cm-inplace-callout-head"), u && e === o && (r += " cm-inplace-callout-foot");
347
+ let i = {};
348
+ u && (i["data-callout"] = l[3].toLowerCase()), u && d && (i["data-revealed"] = ""), a.push(v.line({
349
+ class: r,
350
+ attributes: i
351
+ }).range(n.line(e).from));
352
+ }
353
+ if (u && !d && !r.has(t)) {
354
+ let e = s.from + l[1].length;
355
+ a.push(v.replace({}).range(e, e + l[2].length));
356
+ }
357
+ }
358
+ return;
359
+ }
360
+ if (e.name === "QuoteMark") {
361
+ if (!o.blockquote) return !1;
362
+ let t = n.lineAt(e.from);
363
+ if (!r.has(t.number) && !c.has(t.number)) {
364
+ let n = Math.min(e.to + 1, t.to), r = _.exec(t.text), i = r ? t.text.slice(r[1].length + r[2].length) : t.text.slice(n - t.from);
365
+ a.push(v.replace({}).range(e.from, i.trim() === "" ? e.to : n));
366
+ }
367
+ return !1;
368
+ }
369
+ if (e.name === "ListMark") {
370
+ let t = n.sliceString(e.from, e.to), i = n.lineAt(e.from), s = e.node.parent, c = !!(s?.getChild("Task") ?? s?.getChild("TaskMarker"));
371
+ return r.has(i.number) || (c ? o.tasks && a.push(v.replace({}).range(e.from, Math.min(e.to + 1, i.to))) : o.lists && Be.test(t) && a.push(v.replace({ widget: new Ie() }).range(e.from, e.to))), !1;
372
+ }
373
+ if (e.name === "TaskMarker") {
374
+ if (!o.tasks) return !1;
375
+ if (!r.has(n.lineAt(e.from).number)) {
376
+ let t = n.sliceString(e.from + 1, e.to - 1).toLowerCase() === "x";
377
+ a.push(v.replace({ widget: new Le(t) }).range(e.from, e.to));
378
+ }
379
+ return !1;
380
+ }
381
+ if (e.name === "FencedCode" || e.name === "CodeBlock") {
382
+ if (!o.code) return !1;
383
+ let t = e.name === "FencedCode", r = n.lineAt(e.from).number, s = n.lineAt(e.to > e.from ? e.to - 1 : e.to).number, c = !1;
384
+ for (let e = r; e <= s && !c; e++) i.has(e) && (c = !0);
385
+ let l = t && s > r && !c;
386
+ for (let e = r; e <= s; e++) {
387
+ let i = t && (e === r || e === s), o = "cm-inplace-mono";
388
+ e === r && (o += " cm-inplace-code-top"), e === s && (o += " cm-inplace-code-bottom"), i && (o += l ? " cm-inplace-code-pad" : " cm-inplace-fence");
389
+ let c = n.line(e);
390
+ a.push(v.line({ class: o }).range(c.from)), i && l && c.to > c.from && a.push(v.replace({}).range(c.from, c.to));
391
+ }
392
+ return !1;
393
+ }
394
+ }
395
+ //#endregion
396
+ //#region src/inplace/wikilinks.ts
397
+ function Ue(e, t, r, i, a, o) {
398
+ let s = e.state.doc.sliceString(t, r);
399
+ if (s.includes("[[")) for (let r of s.matchAll(n)) {
400
+ let [n = "", s = "", c] = r, l = s.trim(), u = t + (r.index ?? 0);
401
+ if (!l || F(a, u + 1)) continue;
402
+ let d = u + n.length, f = c == null ? u + 2 : u + 2 + s.length + 1, p = d - 2;
403
+ o.push(v.mark({
404
+ class: "cm-inplace-link cm-inplace-wikilink",
405
+ attributes: { "data-stylo-wikilink": l }
406
+ }).range(f, p)), i.has(e.state.doc.lineAt(u).number) || (o.push(v.replace({}).range(u, f)), o.push(v.replace({}).range(p, d)));
407
+ }
408
+ }
409
+ //#endregion
410
+ //#region src/inplace/decorate.ts
411
+ var We = /* @__PURE__ */ new Set(), Ge = v.replace({});
412
+ function Ke(e) {
413
+ let n = [], r = P(e.state), i = e.state.facet(O) === "never" ? We : r, a = T(e.state), { doc: o } = e.state, s = e.state.facet(E), c = {
414
+ doc: o,
415
+ revealed: i,
416
+ caretRevealed: r,
417
+ out: n,
418
+ toggles: s,
419
+ fmEnd: t(o)?.to ?? -1,
420
+ quoteRevealed: /* @__PURE__ */ new Set()
421
+ };
422
+ for (let t of e.visibleRanges) a.iterate({
423
+ from: t.from,
424
+ to: t.to,
425
+ enter: (e) => He(e, c)
426
+ }), s.wikilinks && Ue(e, t.from, t.to, i, a, n), s.math && Me(e, t.from, t.to, r, a, n), De(t.from, t.to, a, o, s, n);
427
+ let l = n.filter((e) => e.from < e.to && !e.value.spec.class).sort((e, t) => e.from - t.from || e.to - t.to), u = [];
428
+ for (let e of l) {
429
+ if (!e.value.spec.widget) {
430
+ let t = o.lineAt(e.from);
431
+ if (e.from === t.from && e.to === t.to) continue;
432
+ }
433
+ let t = u[u.length - 1];
434
+ t && e.from <= t.to ? e.to > t.to && (u[u.length - 1] = Ge.range(t.from, e.to)) : u.push(Ge.range(e.from, e.to));
435
+ }
436
+ return {
437
+ decorations: v.set(n, !0),
438
+ atomic: v.set(u, !0)
439
+ };
440
+ }
441
+ //#endregion
442
+ //#region src/inplace/plugin.ts
443
+ var R = b.fromClass(class {
444
+ decorations;
445
+ atomic;
446
+ constructor(e) {
447
+ let t = Ke(e);
448
+ this.decorations = t.decorations, this.atomic = t.atomic;
449
+ }
450
+ update(e) {
451
+ if (e.docChanged || e.viewportChanged || e.selectionSet) {
452
+ let t = Ke(e.view);
453
+ this.decorations = t.decorations, this.atomic = t.atomic;
454
+ }
455
+ }
456
+ }, {
457
+ decorations: (e) => e.decorations,
458
+ provide: (e) => y.atomicRanges.of((t) => t.plugin(e)?.atomic ?? v.none)
459
+ });
460
+ function qe() {
461
+ return R;
462
+ }
463
+ //#endregion
464
+ //#region src/inplace/edit-boundaries.ts
465
+ var Je = {
466
+ StrongEmphasis: {
467
+ markType: "EmphasisMark",
468
+ toggle: "emphasis"
469
+ },
470
+ Emphasis: {
471
+ markType: "EmphasisMark",
472
+ toggle: "emphasis"
473
+ },
474
+ Strikethrough: {
475
+ markType: "StrikethroughMark",
476
+ toggle: "emphasis"
477
+ },
478
+ InlineCode: {
479
+ markType: "CodeMark",
480
+ toggle: "code"
481
+ }
482
+ };
483
+ function z(e, t) {
484
+ return e.facet(O) === "never" || !P(e).has(t);
485
+ }
486
+ function Ye(e, t, n) {
487
+ let r = e.plugin(R)?.decorations;
488
+ if (!r) return t;
489
+ let i = n < 0 ? 0 : e.state.doc.length, a = t;
490
+ for (let e = !0; e;) e = !1, r.between(Math.min(a, i), Math.max(a, i), (t, r, i) => {
491
+ t >= r || i.spec.widget || i.spec.class || (n < 0 ? r === a : t === a) && (a = n < 0 ? t : r, e = !0);
492
+ });
493
+ return a;
494
+ }
495
+ function B(e, t, r = !1, i = !1) {
496
+ let a = e.doc.lineAt(t);
497
+ if (!i && !z(e, a.number)) return null;
498
+ let o = e.facet(E), s = T(e);
499
+ for (let n of [-1, 1]) for (let i = s.resolveInner(t, n); i; i = i.parent) {
500
+ let t = Je[i.name];
501
+ if (t) {
502
+ if (!o[t.toggle]) break;
503
+ let e = i.getChildren(t.markType), n = e[0], r = e[e.length - 1];
504
+ if (!n || !r || n === r) break;
505
+ return {
506
+ from: i.from,
507
+ to: i.to,
508
+ contentFrom: n.to,
509
+ contentTo: r.from,
510
+ kind: "mark"
511
+ };
512
+ }
513
+ if (i.name === "Link") {
514
+ if (r || e.doc.sliceString(Math.max(0, i.from - 1), i.from) === "[" || !o.links) break;
515
+ let t = i.getChildren("LinkMark");
516
+ if (t.length < 2) break;
517
+ return {
518
+ from: i.from,
519
+ to: i.to,
520
+ contentFrom: t[0].to,
521
+ contentTo: t[1].from,
522
+ kind: "link"
523
+ };
524
+ }
525
+ }
526
+ if (o.wikilinks && !r) for (let e of a.text.matchAll(n)) {
527
+ let n = a.from + (e.index ?? 0), r = n + e[0].length;
528
+ if (t < n || t > r) continue;
529
+ let i = e[1] ?? "", o = e[2] != null;
530
+ return {
531
+ from: n,
532
+ to: r,
533
+ contentFrom: n + 2 + (o ? i.length + 1 : 0),
534
+ contentTo: r - 2,
535
+ kind: "link"
536
+ };
537
+ }
538
+ return null;
539
+ }
540
+ var Xe = (e) => (t) => {
541
+ if (o(t)) return !1;
542
+ let n = t.state.selection.main;
543
+ if (!n.empty) return !1;
544
+ let { state: r } = t;
545
+ if (!z(r, r.doc.lineAt(n.head).number)) return !1;
546
+ let i = Ye(t, n.head, e);
547
+ if (i === n.head) return !1;
548
+ let a = r.doc;
549
+ if (e < 0 ? i <= 0 : i >= a.length) return !0;
550
+ let s = e < 0 ? i - 1 : i, c = e < 0 ? i : i + 1;
551
+ for (let e = B(r, s); e && s <= e.contentFrom && c >= e.contentTo && e.contentTo > e.contentFrom && !(e.from >= s && e.to <= c); e = B(r, s)) s = Math.min(s, e.from), c = Math.max(c, e.to);
552
+ return t.dispatch({
553
+ changes: {
554
+ from: s,
555
+ to: c,
556
+ insert: ""
557
+ },
558
+ selection: { anchor: s },
559
+ userEvent: e < 0 ? "delete.backward" : "delete.forward",
560
+ scrollIntoView: !0
561
+ }), !0;
562
+ }, Ze = Xe(-1), Qe = Xe(1);
563
+ function $e(e, t, n) {
564
+ if (n <= t) return !1;
565
+ let r = e.plugin(R)?.decorations;
566
+ if (!r) return !1;
567
+ let i = t;
568
+ return r.between(t, n, (e, t, n) => {
569
+ n.spec.widget || n.spec.class || t <= e || e <= i && (i = Math.max(i, t));
570
+ }), i >= n;
571
+ }
572
+ var V = (e, t) => (n) => {
573
+ if (o(n)) return !1;
574
+ let r = n.state.selection.main;
575
+ if (!t && !r.empty || !z(n.state, n.state.doc.lineAt(r.head).number)) return !1;
576
+ let i = n.moveByChar(r, e);
577
+ if ($e(n, Math.min(r.head, i.head), Math.max(r.head, i.head)) && (i = n.moveByChar(i, e)), i.head === r.head) return !1;
578
+ let a = t ? he.range(r.anchor, i.head) : he.cursor(i.head);
579
+ return n.dispatch({
580
+ selection: a,
581
+ userEvent: "select"
582
+ }), !0;
583
+ }, et = V(!1, !1), tt = V(!0, !1), nt = V(!1, !0), rt = V(!0, !0), it = C.high(pe.of([
584
+ {
585
+ key: "Backspace",
586
+ run: Ze
587
+ },
588
+ {
589
+ key: "Delete",
590
+ run: Qe
591
+ },
592
+ {
593
+ key: "ArrowLeft",
594
+ run: et
595
+ },
596
+ {
597
+ key: "ArrowRight",
598
+ run: tt
599
+ },
600
+ {
601
+ key: "Shift-ArrowLeft",
602
+ run: nt
603
+ },
604
+ {
605
+ key: "Shift-ArrowRight",
606
+ run: rt
607
+ }
608
+ ])), at = (e) => e === "h1" || e === "h2" || e === "h3" ? g.heading : g[e], ot = [
609
+ "bold",
610
+ "italic",
611
+ "strike"
612
+ ], st = ["code", "math"], ct = [
613
+ "bulletList",
614
+ "orderedList",
615
+ "task"
616
+ ], lt = [
617
+ "h1",
618
+ "h2",
619
+ "h3"
620
+ ], ut = ["table", "hr"], dt = [
621
+ "codeBlock",
622
+ "mathBlock",
623
+ "frontmatter"
624
+ ];
625
+ function H(e) {
626
+ let t = o(e);
627
+ if (!t) return !1;
628
+ let { from: n, to: r } = u(t);
629
+ return r > n;
630
+ }
631
+ var ft = (e, t, n = !1) => {
632
+ let r = m[t];
633
+ return r ? {
634
+ label: r.title,
635
+ icon: at(t),
636
+ active: !n && !!r.isActive?.(e.state),
637
+ disabled: !n && !!r.disabled?.(e.state),
638
+ onSelect: () => {
639
+ r.run(e), e.focus();
640
+ }
641
+ } : null;
642
+ }, U = (e, t, n = !1, r = !1) => {
643
+ let i = [];
644
+ for (let a of t) {
645
+ let t = ft(e, a, r);
646
+ t && !(n && t.disabled) && i.push(t);
647
+ }
648
+ return i;
649
+ }, W = (e) => {
650
+ let t = e.contentDOM.ownerDocument, n = (n) => () => {
651
+ e.focus();
652
+ try {
653
+ t.execCommand(n);
654
+ } catch {}
655
+ }, r = e.dom.ownerDocument.defaultView?.navigator?.clipboard, i = typeof r?.readText == "function";
656
+ return [
657
+ {
658
+ label: "Cut",
659
+ icon: g.cut,
660
+ onSelect: n("cut")
661
+ },
662
+ {
663
+ label: "Copy",
664
+ icon: g.copy,
665
+ onSelect: n("copy")
666
+ },
667
+ i ? {
668
+ label: "Paste",
669
+ icon: g.paste,
670
+ onSelect: () => {
671
+ let n = o(e);
672
+ n || e.focus(), r?.readText().then((r) => {
673
+ r && (n ? t.execCommand("insertText", !1, r) : e.dispatch(e.state.replaceSelection(r)));
674
+ }).catch(() => {});
675
+ }
676
+ } : {
677
+ label: "Paste",
678
+ icon: g.paste,
679
+ disabled: !0,
680
+ title: "Paste with the keyboard shortcut",
681
+ onSelect: () => {}
682
+ }
683
+ ];
684
+ }, pt = (e) => {
685
+ let t = e.trim().replace(/^<([^]*)>$/, "$1");
686
+ return /[\s()]/.test(t) ? `<${t.replace(/[<>]/g, "")}>` : t;
687
+ }, mt = (e) => e.replace(/^<([^]*)>$/, "$1");
688
+ function ht(e, t) {
689
+ let n = e.doc.lineAt(t.from);
690
+ if (e.doc.lineAt(t.to).number !== n.number) return null;
691
+ let r = t.from - n.from, i = t.to - n.from, a = ae(n.text, r) ?? ae(n.text, i);
692
+ if (a) return {
693
+ from: n.from + a.from,
694
+ to: n.from + a.to,
695
+ text: a.label
696
+ };
697
+ let o = oe(n.text, r) ?? oe(n.text, i);
698
+ return o ? {
699
+ from: n.from + o.from,
700
+ to: n.from + o.to,
701
+ text: o.label
702
+ } : null;
703
+ }
704
+ function G(e) {
705
+ let { state: t } = e, n = t.selection.main, r = t.doc.lineAt(n.head), i = ae(r.text, n.head - r.from);
706
+ if (i) {
707
+ let n = r.from + i.from, a = r.from + i.to, o = r.from + i.urlFrom, s = r.from + i.urlTo, c = t.facet(be), l = [];
708
+ return c && i.url && l.push({
709
+ label: "Open link",
710
+ icon: g.link,
711
+ onSelect: () => c(i.url)
712
+ }), l.push({
713
+ label: "Remove link",
714
+ onSelect: () => {
715
+ e.dispatch({
716
+ changes: {
717
+ from: n,
718
+ to: a,
719
+ insert: i.label
720
+ },
721
+ selection: {
722
+ anchor: n,
723
+ head: n + i.label.length
724
+ }
725
+ }), e.focus();
726
+ }
727
+ }), {
728
+ field: !0,
729
+ label: "Edit external link",
730
+ icon: g.link,
731
+ value: mt(i.url),
732
+ placeholder: "https://…",
733
+ onSubmit: (t) => {
734
+ e.dispatch({ changes: {
735
+ from: o,
736
+ to: s,
737
+ insert: pt(t)
738
+ } }), e.focus();
739
+ },
740
+ actions: l
741
+ };
742
+ }
743
+ let a = ht(t, n), o = a ? a.from : n.from, s = a ? a.to : n.to, c = (a ? a.text : t.sliceDoc(n.from, n.to)) || "link";
744
+ return {
745
+ field: !0,
746
+ label: "Add external link",
747
+ icon: g.link,
748
+ value: "",
749
+ placeholder: "https://…",
750
+ onSubmit: (t) => {
751
+ e.dispatch({
752
+ changes: {
753
+ from: o,
754
+ to: s,
755
+ insert: `[${c}](${pt(t)})`
756
+ },
757
+ selection: {
758
+ anchor: o + 1,
759
+ head: o + 1 + c.length
760
+ }
761
+ }), e.focus();
762
+ }
763
+ };
764
+ }
765
+ function gt(e) {
766
+ let { state: t } = e, n = t.selection.main, r = t.doc.lineAt(n.head), i = a(r.text, n.head - r.from);
767
+ if (i) {
768
+ let t = r.from + i.from, n = r.from + i.to, a = r.from + i.targetFrom, o = r.from + i.targetTo, s = i.label || i.target;
769
+ return {
770
+ field: !0,
771
+ label: "Edit link",
772
+ icon: g.wikilink,
773
+ value: i.target,
774
+ placeholder: "note or path",
775
+ onSubmit: (t) => {
776
+ t && e.dispatch({ changes: {
777
+ from: a,
778
+ to: o,
779
+ insert: t
780
+ } }), e.focus();
781
+ },
782
+ actions: [{
783
+ label: "Remove link",
784
+ onSelect: () => {
785
+ e.dispatch({
786
+ changes: {
787
+ from: t,
788
+ to: n,
789
+ insert: s
790
+ },
791
+ selection: {
792
+ anchor: t,
793
+ head: t + s.length
794
+ }
795
+ }), e.focus();
796
+ }
797
+ }]
798
+ };
799
+ }
800
+ let o = ht(t, n), s = o ? o.from : n.from, c = o ? o.to : n.to, l = o ? o.text : t.sliceDoc(n.from, n.to);
801
+ return {
802
+ field: !0,
803
+ label: "Add link",
804
+ icon: g.wikilink,
805
+ value: "",
806
+ placeholder: "note or path",
807
+ onSubmit: (t) => {
808
+ let n = t || l || "target", r = !t || t === l ? `[[${n}]]` : `[[${t}|${l}]]`;
809
+ e.dispatch({
810
+ changes: {
811
+ from: s,
812
+ to: c,
813
+ insert: r
814
+ },
815
+ selection: {
816
+ anchor: s + 2,
817
+ head: s + 2 + (t || n).length
818
+ }
819
+ }), e.focus();
820
+ }
821
+ };
822
+ }
823
+ var K = (e, t, n, r = !1) => ({
824
+ label: e,
825
+ icon: t,
826
+ rows: n,
827
+ disabled: r
828
+ });
829
+ function _t(e) {
830
+ let t = ee(e.state);
831
+ return {
832
+ field: !0,
833
+ label: "Language",
834
+ icon: g.codeBlock,
835
+ value: t?.lang ?? "",
836
+ placeholder: "ts, python, …",
837
+ onSubmit: (n) => {
838
+ t && e.dispatch({ changes: {
839
+ from: t.from,
840
+ to: t.to,
841
+ insert: n.trim()
842
+ } }), e.focus();
843
+ },
844
+ actions: [{
845
+ label: "Remove code block",
846
+ onSelect: () => {
847
+ m.codeBlock?.run(e), e.focus();
848
+ }
849
+ }]
850
+ };
851
+ }
852
+ var vt = (e, t = !1) => [
853
+ ...U(e, ot, !1, t),
854
+ "separator",
855
+ ...U(e, st, !1, t)
856
+ ];
857
+ function yt(e) {
858
+ let t = e.state.facet(M), n = [];
859
+ return t.includes("format") && q(n, [K("Format", g.format, vt(e, !0))]), t.includes("clipboard") && q(n, W(e)), n;
860
+ }
861
+ var bt = (e) => [
862
+ ...U(e, ct),
863
+ "separator",
864
+ ...U(e, [...lt, "body"]),
865
+ "separator",
866
+ ...U(e, ["quote"])
867
+ ], xt = (e) => [
868
+ ...U(e, ut),
869
+ "separator",
870
+ ...U(e, dt)
871
+ ];
872
+ function q(e, t) {
873
+ t.length && (e.length && e.push("separator"), e.push(...t));
874
+ }
875
+ function St(e) {
876
+ let { state: t } = e, n = t.facet(M), r = (e) => n.includes(e);
877
+ if (H(e)) return yt(e);
878
+ if (ne(t)) {
879
+ let t = [_t(e)];
880
+ return r("clipboard") && q(t, W(e)), t;
881
+ }
882
+ let i = t.selection.main, a = t.doc.lineAt(i.head).text.trim() === "", o = !i.empty || !!t.wordAt(i.head), s = t.facet(N) === "menu", c = [];
883
+ for (let t of n) t === "link" && s ? q(c, [gt(e), G(e)]) : t === "format" && s ? q(c, [K("Format", g.format, vt(e), !o)]) : t === "paragraph" ? q(c, [K("Paragraph", g.paragraph, bt(e))]) : t === "insert" ? q(c, [K("Insert", g.insert, xt(e), !a)]) : t === "clipboard" && q(c, W(e));
884
+ return c;
885
+ }
886
+ //#endregion
887
+ //#region src/inplace/inline-md.ts
888
+ function Ct(e) {
889
+ let t = document.createDocumentFragment();
890
+ return Tt(t, e), t;
891
+ }
892
+ var wt = [
893
+ {
894
+ re: /`([^`\n]+)`/,
895
+ build: (e) => J("code", "cm-inplace-code", document.createTextNode(e[1]))
896
+ },
897
+ {
898
+ re: /(?<![\d$])\$(?!\s)([^$\n]+?)(?<!\s)\$(?![\d$])/,
899
+ build: (e) => {
900
+ let t = J("span", "cm-inplace-math");
901
+ return ce.render(e[1], t, { throwOnError: !1 }), t;
902
+ }
903
+ },
904
+ {
905
+ re: new RegExp(n.source),
906
+ build: (e) => {
907
+ let t = J("span", "cm-inplace-wikilink", document.createTextNode(e[2] || e[1] || ""));
908
+ return t.dataset.styloWikilink = e[1] ?? "", t;
909
+ }
910
+ },
911
+ {
912
+ re: /\[([^\]\n]*)\]\(([^)\n]*)\)/,
913
+ build: (e) => {
914
+ let t = J("a", "cm-inplace-link");
915
+ return t.href = e[2] ?? "", t.append(Y(e[1] ?? "")), t;
916
+ }
917
+ },
918
+ {
919
+ re: /\*\*\*([^*\n]+?)\*\*\*/,
920
+ build: (e) => J("strong", "cm-inplace-strong", J("em", "cm-inplace-em", Y(e[1])))
921
+ },
922
+ {
923
+ re: /\*\*([^\n]+?)\*\*/,
924
+ build: (e) => J("strong", "cm-inplace-strong", Y(e[1]))
925
+ },
926
+ {
927
+ re: /~~([^\n]+?)~~/,
928
+ build: (e) => J("span", "cm-inplace-strike", Y(e[1]))
929
+ },
930
+ {
931
+ re: /(?<!\*)\*(?!\*|\s)([^\n]+?)(?<!\s)\*(?!\*)/,
932
+ build: (e) => J("em", "cm-inplace-em", Y(e[1]))
933
+ }
934
+ ];
935
+ function J(e, t, ...n) {
936
+ let r = document.createElement(e);
937
+ return r.className = t, r.append(...n), r;
938
+ }
939
+ function Y(e) {
940
+ let t = document.createDocumentFragment();
941
+ return Tt(t, e), t;
942
+ }
943
+ function Tt(e, t) {
944
+ for (; t;) {
945
+ let n = -1, r = null;
946
+ for (let e of wt) {
947
+ let i = e.re.exec(t);
948
+ i && (n < 0 || i.index < n) && (n = i.index, r = {
949
+ rule: e,
950
+ m: i
951
+ });
952
+ }
953
+ if (!r) {
954
+ e.appendChild(document.createTextNode(t));
955
+ return;
956
+ }
957
+ n > 0 && e.appendChild(document.createTextNode(t.slice(0, n))), e.appendChild(r.rule.build(r.m)), t = t.slice(n + r.m[0].length);
958
+ }
959
+ }
960
+ //#endregion
961
+ //#region src/inplace/long-press.ts
962
+ function Et(e, t) {
963
+ let n = t.delay ?? 450, r = t.slop ?? 20, i = null, a = 0, o = 0, s = () => {
964
+ i != null && (clearTimeout(i), i = null);
965
+ }, c = (e) => {
966
+ if (e.pointerType === "mouse") return;
967
+ s(), a = e.clientX, o = e.clientY;
968
+ let r = e.target;
969
+ i = setTimeout(() => {
970
+ i = null, t.onLongPress(a, o, r);
971
+ }, n);
972
+ }, l = (e) => {
973
+ i != null && (Math.abs(e.clientX - a) > r || Math.abs(e.clientY - o) > r) && s();
974
+ };
975
+ return e.addEventListener("pointerdown", c), e.addEventListener("pointermove", l), e.addEventListener("pointerup", s), e.addEventListener("pointercancel", s), {
976
+ cancel: s,
977
+ dispose: () => {
978
+ s(), e.removeEventListener("pointerdown", c), e.removeEventListener("pointermove", l), e.removeEventListener("pointerup", s), e.removeEventListener("pointercancel", s);
979
+ }
980
+ };
981
+ }
982
+ //#endregion
983
+ //#region src/inplace/context-menu.ts
984
+ var Dt = (e) => typeof e != "string" && "rows" in e, Ot = (e) => typeof e != "string" && "field" in e;
985
+ function X(e, t = "cm-inplace-menu") {
986
+ let n = e.defaultView, r = e.createElement("div");
987
+ r.className = t, r.setAttribute("contenteditable", "false"), r.hidden = !0;
988
+ let i = null, a = null, o = () => {
989
+ i?.remove(), i = null;
990
+ }, s = () => {
991
+ r.hidden || (o(), r.hidden = !0, r.replaceChildren(), a?.(), a = null);
992
+ }, c = (e) => e.addEventListener("mousedown", (e) => {
993
+ e.preventDefault(), e.stopPropagation();
994
+ }), l = (t, n, r) => {
995
+ r && t.appendChild(se(e, r));
996
+ let i = e.createElement("span");
997
+ i.textContent = n, t.appendChild(i);
998
+ }, u = (n) => {
999
+ let r = e.createElement("button");
1000
+ return r.type = "button", r.className = `${t}-item`, l(r, n.label, n.icon), n.title && (r.title = n.title), n.active && (r.dataset.active = ""), n.disabled ? r.disabled = !0 : (c(r), r.addEventListener("pointerenter", () => {
1001
+ r.closest(`.${t}-panel[data-for]`) || o();
1002
+ }), r.addEventListener("click", (e) => {
1003
+ e.stopPropagation(), s(), n.onSelect();
1004
+ })), r;
1005
+ }, d = (n, a, s, u = !1) => {
1006
+ let d = e.createElement("button");
1007
+ if (d.type = "button", d.className = `${t}-item ${t}-parent`, l(d, n, a), u) return d.disabled = !0, d;
1008
+ c(d);
1009
+ let f = () => {
1010
+ if (i?.dataset.for === n) return;
1011
+ o();
1012
+ let e = s();
1013
+ e.dataset.for = n, r.appendChild(e), ee(e, d.getBoundingClientRect()), i = e, e.querySelector("input")?.focus({ preventScroll: !0 });
1014
+ };
1015
+ return d.addEventListener("pointerenter", f), d.addEventListener("click", (e) => {
1016
+ e.stopPropagation(), f();
1017
+ }), d;
1018
+ }, f = (n) => {
1019
+ let r = e.createElement("div");
1020
+ r.className = `${t}-panel`;
1021
+ let i = e.createElement("input");
1022
+ i.type = "text", i.className = `${t}-input`, i.value = n.value, n.placeholder && (i.placeholder = n.placeholder), i.addEventListener("keydown", (e) => {
1023
+ if (e.key !== "Enter") return;
1024
+ e.preventDefault();
1025
+ let t = i.value.trim();
1026
+ s(), n.onSubmit(t);
1027
+ }), r.appendChild(i);
1028
+ for (let e of n.actions ?? []) r.appendChild(u(e));
1029
+ return r;
1030
+ }, p = (n) => {
1031
+ let r = e.createElement("div");
1032
+ r.className = `${t}-panel`;
1033
+ for (let i of n) if (i === "separator") {
1034
+ let n = e.createElement("div");
1035
+ n.className = `${t}-sep`, r.appendChild(n);
1036
+ } else Dt(i) ? r.appendChild(d(i.label, i.icon, () => p(i.rows), i.disabled)) : Ot(i) ? r.appendChild(d(i.label, i.icon, () => f(i))) : r.appendChild(u(i));
1037
+ return r;
1038
+ }, m = (e, t, r) => {
1039
+ let i = n?.innerWidth ?? 0, a = n?.innerHeight ?? 0;
1040
+ e.style.left = "0", e.style.top = "0";
1041
+ let { width: o, height: s } = e.getBoundingClientRect();
1042
+ e.style.left = `${Math.max(4, Math.min(t, i - o - 4))}px`, e.style.top = `${Math.max(4, Math.min(r, a - s - 4))}px`;
1043
+ }, ee = (e, t) => {
1044
+ let r = n?.innerWidth ?? 0, i = n?.innerHeight ?? 0;
1045
+ e.style.left = "0", e.style.top = "0";
1046
+ let { width: a, height: o } = e.getBoundingClientRect(), s = t.right - 4, c = s + a > r - 4 ? t.left - a + 4 : s;
1047
+ e.style.left = `${Math.max(4, c)}px`, e.style.top = `${Math.max(4, Math.min(t.top - 4, i - o - 4))}px`;
1048
+ }, h = () => {
1049
+ let t = Date.now(), n = (e) => !r.contains(e.target), i = (e) => {
1050
+ n(e) && s();
1051
+ }, o = (e) => {
1052
+ e.key === "Escape" && s();
1053
+ }, c = (e) => {
1054
+ Date.now() - t < 350 || n(e) && s();
1055
+ };
1056
+ e.addEventListener("pointerdown", i, !0), e.addEventListener("mousedown", i, !0), e.addEventListener("keydown", o, !0), e.addEventListener("scroll", c, !0), a = () => {
1057
+ e.removeEventListener("pointerdown", i, !0), e.removeEventListener("mousedown", i, !0), e.removeEventListener("keydown", o, !0), e.removeEventListener("scroll", c, !0);
1058
+ };
1059
+ };
1060
+ return {
1061
+ el: r,
1062
+ get isOpen() {
1063
+ return !r.hidden;
1064
+ },
1065
+ show: (e, t, n) => {
1066
+ s();
1067
+ let i = p(e);
1068
+ r.appendChild(i), r.hidden = !1, m(i, t, n), h();
1069
+ },
1070
+ showField: (e, t, n) => {
1071
+ s();
1072
+ let i = f(e);
1073
+ r.appendChild(i), r.hidden = !1, m(i, t, n), i.querySelector("input")?.focus({ preventScroll: !0 }), h();
1074
+ },
1075
+ hide: s,
1076
+ destroy: () => {
1077
+ s(), r.remove();
1078
+ }
1079
+ };
1080
+ }
1081
+ //#endregion
1082
+ //#region src/inplace/table-gizmos.ts
1083
+ function kt(e, t) {
1084
+ let n = e.createElement("div");
1085
+ n.className = "cm-inplace-table-gizmos", n.setAttribute("contenteditable", "false");
1086
+ let r = X(e), i = (t, n, r) => {
1087
+ let i = e.createElement("button");
1088
+ return i.type = "button", i.className = t, i.setAttribute("aria-label", n), i.addEventListener("mousedown", (e) => {
1089
+ e.preventDefault(), e.stopPropagation();
1090
+ }), i.addEventListener("click", (e) => {
1091
+ e.stopPropagation(), r();
1092
+ }), i;
1093
+ }, a = (t, n, r) => {
1094
+ let a = i(`cm-inplace-tg-edge cm-inplace-tg-add${t}`, n, r), o = e.createElement("span");
1095
+ return o.className = "cm-inplace-tg-plus", a.appendChild(o), a;
1096
+ }, o = a("col", "Add column", () => t.run({
1097
+ kind: "insertColumn",
1098
+ at: t.dims().cols,
1099
+ focus: [1, t.dims().cols]
1100
+ })), s = a("row", "Add row", () => t.run({
1101
+ kind: "insertRow",
1102
+ at: t.dims().rows,
1103
+ focus: [t.dims().rows, 0]
1104
+ }));
1105
+ n.append(o, s, r.el);
1106
+ let c = (e, n, r = []) => {
1107
+ let { cols: i, rows: a, alignAt: o } = t.dims(), s = (e, n, r = !1) => ({
1108
+ label: e,
1109
+ active: r,
1110
+ onSelect: () => t.run(n)
1111
+ }), c = [
1112
+ s("Insert row above", {
1113
+ kind: "insertRow",
1114
+ at: e,
1115
+ focus: [e, n]
1116
+ }),
1117
+ s("Insert row below", {
1118
+ kind: "insertRow",
1119
+ at: e + 1,
1120
+ focus: [e + 1, n]
1121
+ }),
1122
+ s("Insert column left", {
1123
+ kind: "insertColumn",
1124
+ at: n,
1125
+ focus: [e, n]
1126
+ }),
1127
+ s("Insert column right", {
1128
+ kind: "insertColumn",
1129
+ at: n + 1,
1130
+ focus: [e, n + 1]
1131
+ })
1132
+ ];
1133
+ e > 0 && a > 2 && c.push(s("Delete row", {
1134
+ kind: "deleteRow",
1135
+ at: e,
1136
+ focus: [e, n]
1137
+ })), i > 1 && c.push(s("Delete column", {
1138
+ kind: "deleteColumn",
1139
+ at: n,
1140
+ focus: [e, n - 1]
1141
+ })), c.push("separator");
1142
+ for (let e of [
1143
+ "left",
1144
+ "center",
1145
+ "right"
1146
+ ]) c.push(s(`Align ${e}`, {
1147
+ kind: "align",
1148
+ at: n,
1149
+ value: e
1150
+ }, o(n) === e));
1151
+ return r.length && c.push("separator", ...r), c;
1152
+ };
1153
+ return {
1154
+ el: n,
1155
+ layout: (e) => {
1156
+ let t = [...e.rows];
1157
+ if (!t.length) return;
1158
+ let r = n.getBoundingClientRect(), i = t[0].getBoundingClientRect().top - r.top, a = t[t.length - 1].getBoundingClientRect().bottom - r.top, c = e.getBoundingClientRect(), l = c.left - r.left, u = c.right - r.left;
1159
+ o.style.left = `${u + 3}px`, o.style.top = `${i}px`, o.style.height = `${a - i}px`, s.style.left = `${l}px`, s.style.top = `${a + 3}px`, s.style.width = `${u - l}px`;
1160
+ },
1161
+ openFor: (e, t, n, i) => {
1162
+ r.show(c(Number(e.dataset.r), Number(e.dataset.c), i), t, n);
1163
+ },
1164
+ destroy: () => r.destroy()
1165
+ };
1166
+ }
1167
+ //#endregion
1168
+ //#region src/inplace/table-structure.ts
1169
+ var Z = (e) => e.aligns.length;
1170
+ function At(e, t) {
1171
+ let n = Math.max(0, Math.min(t, Z(e)));
1172
+ for (let t of e.rows) t.splice(n, 0, "");
1173
+ e.aligns.splice(n, 0, "");
1174
+ }
1175
+ function jt(e, t) {
1176
+ if (!(Z(e) <= 1 || t < 0 || t >= Z(e))) {
1177
+ for (let n of e.rows) n.splice(t, 1);
1178
+ e.aligns.splice(t, 1);
1179
+ }
1180
+ }
1181
+ function Mt(e, t) {
1182
+ let n = Math.max(1, Math.min(t, e.rows.length));
1183
+ e.rows.splice(n, 0, Array(Z(e)).fill(""));
1184
+ }
1185
+ function Nt(e, t) {
1186
+ t <= 0 || t >= e.rows.length || e.rows.length <= 2 || e.rows.splice(t, 1);
1187
+ }
1188
+ function Pt(e, t, n) {
1189
+ t >= 0 && t < Z(e) && (e.aligns[t] = n);
1190
+ }
1191
+ //#endregion
1192
+ //#region src/inplace/table-widget.ts
1193
+ var Q = me.define(), Ft = class extends x {
1194
+ data;
1195
+ table = null;
1196
+ rows;
1197
+ editing = null;
1198
+ syncing = !1;
1199
+ pendingOffset = null;
1200
+ current;
1201
+ gizmos = null;
1202
+ longPress = null;
1203
+ longPressAt = 0;
1204
+ constructor(e) {
1205
+ super(), this.data = e, this.rows = ie(e), this.current = l(this.rows);
1206
+ }
1207
+ eq(e) {
1208
+ return !this.table && JSON.stringify(this.current) === JSON.stringify(e.current);
1209
+ }
1210
+ ignoreEvent() {
1211
+ return !0;
1212
+ }
1213
+ cols() {
1214
+ return this.data.aligns.length;
1215
+ }
1216
+ bounds(e) {
1217
+ let t = e.state.doc, n = (e) => {
1218
+ let n = t.line(e).text;
1219
+ return n.trim() !== "" && n.includes("|");
1220
+ }, r = t.lineAt(e.posAtDOM(this.table)).number, i = r;
1221
+ for (; r > 1 && n(r - 1);) r--;
1222
+ for (; i < t.lines && n(i + 1);) i++;
1223
+ return {
1224
+ from: t.line(r).from,
1225
+ to: t.line(i).to
1226
+ };
1227
+ }
1228
+ cellAt(e, t) {
1229
+ return this.table ? (e === 0 ? this.table.tHead.rows[0] : this.table.tBodies[0].rows[e - 1])?.cells[t] ?? null : null;
1230
+ }
1231
+ coords(e) {
1232
+ return {
1233
+ r: Number(e.dataset.r),
1234
+ c: Number(e.dataset.c)
1235
+ };
1236
+ }
1237
+ paint(e, t) {
1238
+ let { r: n, c: i } = this.coords(e), a = this.rows[n]?.[i] ?? "";
1239
+ e.replaceChildren(t ? e.ownerDocument.createTextNode(a) : Ct(r(a)));
1240
+ }
1241
+ mkCell(e, t, n) {
1242
+ let r = document.createElement(n ? "th" : "td");
1243
+ r.className = "cm-inplace-tcell", r.setAttribute("contenteditable", "true"), r.dataset.r = String(e), r.dataset.c = String(t);
1244
+ let i = this.data.aligns[t];
1245
+ return i && (r.style.textAlign = i), this.paint(r, !1), r;
1246
+ }
1247
+ renderCells() {
1248
+ let e = this.table;
1249
+ e.replaceChildren();
1250
+ let t = e.createTHead().insertRow();
1251
+ for (let e = 0; e < this.cols(); e++) t.appendChild(this.mkCell(0, e, !0));
1252
+ let n = e.createTBody();
1253
+ for (let e = 1; e < this.rows.length; e++) {
1254
+ let t = n.insertRow();
1255
+ for (let n = 0; n < this.cols(); n++) t.appendChild(this.mkCell(e, n, !1));
1256
+ }
1257
+ }
1258
+ appendRow() {
1259
+ Mt(this.model(), this.rows.length), this.renderCells(), this.gizmos?.layout(this.table);
1260
+ }
1261
+ model() {
1262
+ return {
1263
+ rows: this.rows,
1264
+ aligns: this.data.aligns
1265
+ };
1266
+ }
1267
+ runOp(e, t) {
1268
+ if (!this.table) return;
1269
+ let n = this.model();
1270
+ if (t.kind === "insertColumn" ? At(n, t.at) : t.kind === "deleteColumn" ? jt(n, t.at) : t.kind === "insertRow" ? Mt(n, t.at) : t.kind === "deleteRow" ? Nt(n, t.at) : Pt(n, t.at, n.aligns[t.at] === t.value ? "" : t.value), this.editing = null, this.sync(e), this.renderCells(), this.gizmos?.layout(this.table), t.kind !== "align") {
1271
+ let e = Math.max(0, Math.min(t.focus[0], this.rows.length - 1)), n = Math.max(0, Math.min(t.focus[1], this.cols() - 1));
1272
+ this.cellAt(e, n)?.focus();
1273
+ }
1274
+ }
1275
+ finish(e, t) {
1276
+ let { r: n, c: r } = this.coords(e);
1277
+ this.rows[n] && (this.rows[n][r] = (e.textContent ?? "").replace(/\r?\n/g, " ")), t || this.paint(e, !1);
1278
+ }
1279
+ onFocusIn(e) {
1280
+ let t = e.target.closest("td, th");
1281
+ if (!t || t === this.editing) return;
1282
+ let n = this.pendingOffset ?? h(t);
1283
+ this.pendingOffset = null, this.editing && this.finish(this.editing, !1), this.editing = t, this.paint(t, !0), c(t, n);
1284
+ }
1285
+ onFocusOut(e) {
1286
+ if (this.syncing || !this.editing) return;
1287
+ let t = e.relatedTarget;
1288
+ t && this.table?.contains(t) || (this.finish(this.editing, !1), this.editing = null);
1289
+ }
1290
+ readCaret() {
1291
+ if (!this.editing) return null;
1292
+ let { r: e, c: t } = this.coords(this.editing), n = this.editing.ownerDocument.getSelection(), r = this.editing.firstChild, i = (this.editing.textContent ?? "").length, a = n?.anchorNode === r ? n?.anchorOffset ?? 0 : i;
1293
+ return {
1294
+ r: e,
1295
+ c: t,
1296
+ offset: a,
1297
+ head: n?.focusNode === r ? n?.focusOffset ?? a : a
1298
+ };
1299
+ }
1300
+ writeCaret(e) {
1301
+ let t = this.cellAt(e.r, e.c);
1302
+ t && c(t, e.offset, e.head);
1303
+ }
1304
+ sync(e) {
1305
+ if (!this.table) return;
1306
+ let t = this.readCaret(), n = i({
1307
+ rows: this.rows,
1308
+ aligns: this.data.aligns
1309
+ });
1310
+ this.current = l(this.rows);
1311
+ let { from: r, to: a } = this.bounds(e);
1312
+ e.state.sliceDoc(r, a) !== n && (this.syncing = !0, e.dispatch({
1313
+ changes: {
1314
+ from: r,
1315
+ to: a,
1316
+ insert: n
1317
+ },
1318
+ annotations: Q.of(!0),
1319
+ userEvent: "input"
1320
+ }), this.syncing = !1, t && (this.writeCaret(t), requestAnimationFrame(() => {
1321
+ this.table && t && this.writeCaret(t);
1322
+ })));
1323
+ }
1324
+ onKey(e, t) {
1325
+ let n = e.target.closest("td, th");
1326
+ if (!n || !this.table) return;
1327
+ if (f(e, n)) {
1328
+ e.stopPropagation();
1329
+ return;
1330
+ }
1331
+ let { r, c: i } = this.coords(n), a = this.rows.length - 1;
1332
+ if (e.key === "Tab") {
1333
+ e.preventDefault(), e.stopPropagation();
1334
+ let n = r * this.cols() + i + (e.shiftKey ? -1 : 1);
1335
+ if (n < 0) return;
1336
+ if (n >= this.rows.length * this.cols()) {
1337
+ if (e.shiftKey) return;
1338
+ this.appendRow(), this.cellAt(a + 1, 0)?.focus(), this.sync(t);
1339
+ return;
1340
+ }
1341
+ this.cellAt(Math.floor(n / this.cols()), n % this.cols())?.focus();
1342
+ return;
1343
+ }
1344
+ if (e.key === "Enter") {
1345
+ if (e.preventDefault(), e.stopPropagation(), r < a) return this.cellAt(r + 1, i)?.focus();
1346
+ this.appendRow(), this.cellAt(a + 1, i)?.focus(), this.sync(t);
1347
+ return;
1348
+ }
1349
+ let o = this.cols(), s = () => {
1350
+ let { to: e } = this.bounds(t);
1351
+ t.focus(), t.dispatch({ selection: { anchor: Math.min(e + 1, t.state.doc.length) } });
1352
+ }, c = () => {
1353
+ let { from: e } = this.bounds(t);
1354
+ t.focus(), t.dispatch({ selection: { anchor: Math.max(e - 1, 0) } });
1355
+ }, l = (e, t) => {
1356
+ let n = this.cellAt(Math.floor(e / o), e % o);
1357
+ n && (this.pendingOffset = t, n.focus());
1358
+ };
1359
+ if (e.key === "ArrowDown") {
1360
+ e.preventDefault(), e.stopPropagation(), r === a ? s() : l((r + 1) * o + i, this.readCaret()?.offset ?? 0);
1361
+ return;
1362
+ }
1363
+ if (e.key === "ArrowUp") {
1364
+ e.preventDefault(), e.stopPropagation(), r === 0 ? c() : l((r - 1) * o + i, this.readCaret()?.offset ?? 0);
1365
+ return;
1366
+ }
1367
+ if (e.key === "ArrowRight" || e.key === "ArrowLeft") {
1368
+ let t = e.key === "ArrowLeft", a = this.readCaret();
1369
+ if (!a || a.offset !== a.head || (t ? a.offset > 0 : a.offset < (n.textContent ?? "").length)) return;
1370
+ e.preventDefault(), e.stopPropagation();
1371
+ let u = r * o + i + (t ? -1 : 1);
1372
+ if (u < 0) return c();
1373
+ if (u >= this.rows.length * o) return s();
1374
+ l(u, t ? (this.rows[Math.floor(u / o)]?.[u % o] ?? "").length : 0);
1375
+ return;
1376
+ }
1377
+ }
1378
+ focusEdge(e) {
1379
+ if (!this.table) return !1;
1380
+ let t = e === "first" ? 0 : this.rows.length - 1, n = e === "first" ? 0 : this.cols() - 1, r = this.cellAt(t, n);
1381
+ return r ? (this.pendingOffset = e === "first" ? 0 : (this.rows[t]?.[n] ?? "").length, r.focus(), !0) : !1;
1382
+ }
1383
+ openCellMenuAt(e, t, n, r) {
1384
+ let i = r?.closest("td, th");
1385
+ if (!i) return;
1386
+ this.editing === i && !H(e) && p(i, t, n);
1387
+ let a = H(e) ? yt(e) : void 0;
1388
+ this.gizmos?.openFor(i, t, n, a);
1389
+ }
1390
+ toDOM(e) {
1391
+ let t = document.createElement("div");
1392
+ t.className = "cm-inplace-table-wrap";
1393
+ let n = document.createElement("table");
1394
+ this.table = n, this.editing = null, n.className = "cm-inplace-table cm-inplace-table-edit", this.renderCells(), n.addEventListener("mousedown", (e) => {
1395
+ e.stopPropagation();
1396
+ let t = e.target.closest("td, th");
1397
+ this.pendingOffset = t && t !== this.editing ? s(t, e.clientX, e.clientY) : null;
1398
+ }), n.addEventListener("focusin", (e) => this.onFocusIn(e)), n.addEventListener("focusout", (e) => this.onFocusOut(e));
1399
+ let r = (t) => {
1400
+ t && (this.editing = t, this.finish(t, !0), this.sync(e));
1401
+ };
1402
+ return n.addEventListener("input", (e) => {
1403
+ e.isComposing || r(e.target.closest("td, th"));
1404
+ }), n.addEventListener("compositionend", (e) => r(e.target.closest("td, th"))), n.addEventListener("keydown", (t) => this.onKey(t, e)), n.addEventListener("paste", (e) => {
1405
+ e.preventDefault();
1406
+ let t = (e.clipboardData?.getData("text/plain") ?? "").replace(/\r?\n/g, " ");
1407
+ document.execCommand("insertText", !1, t);
1408
+ }), n.addEventListener("contextmenu", (t) => {
1409
+ t.target.closest("td, th") && (t.preventDefault(), t.stopPropagation(), this.longPress?.cancel(), !(Date.now() - this.longPressAt < 700) && this.openCellMenuAt(e, t.clientX, t.clientY, t.target));
1410
+ }), this.longPress = Et(n, { onLongPress: (t, n, r) => {
1411
+ this.longPressAt = Date.now(), this.openCellMenuAt(e, t, n, r);
1412
+ } }), this.gizmos = kt(document, {
1413
+ dims: () => ({
1414
+ cols: this.cols(),
1415
+ rows: this.rows.length,
1416
+ alignAt: (e) => this.data.aligns[e] ?? ""
1417
+ }),
1418
+ run: (t) => this.runOp(e, t)
1419
+ }), t.append(n, this.gizmos.el), t.addEventListener("mouseenter", () => this.gizmos?.layout(n)), requestAnimationFrame(() => this.gizmos?.layout(n)), t;
1420
+ }
1421
+ destroy() {
1422
+ this.longPress?.dispose(), this.longPress = null, this.gizmos?.destroy(), this.gizmos = null, this.table = null, this.editing = null;
1423
+ }
1424
+ }, It = /* @__PURE__ */ new Set([
1425
+ "-",
1426
+ "*",
1427
+ "_"
1428
+ ]), Lt = ge.transactionFilter.of((e) => {
1429
+ if (!e.docChanged || e.isUserEvent("undo") || e.isUserEvent("redo") || e.annotation(Q) || !e.startState.selection.main.empty) return e;
1430
+ let t = e.startState.selection.main.head, n = "", r = 0;
1431
+ if (e.changes.iterChanges((e, i, a, o, s) => {
1432
+ r += 1, e === i && e === t && (n = s.toString());
1433
+ }), r !== 1 || n.length !== 1) return e;
1434
+ let i = e.newDoc, a = e.newSelection.main.head, o = i.lineAt(a);
1435
+ if (a !== o.to) return e;
1436
+ let s = o.text, c = null;
1437
+ if (n === " " && /^\[ ?\] $/.test(s)) c = {
1438
+ changes: {
1439
+ from: o.from,
1440
+ to: o.to,
1441
+ insert: "- [ ] "
1442
+ },
1443
+ anchor: o.from + 6
1444
+ };
1445
+ else if (n === "`" && s === "```") c = {
1446
+ changes: {
1447
+ from: a,
1448
+ insert: "\n\n```"
1449
+ },
1450
+ anchor: a + 1
1451
+ };
1452
+ else if (n === "$" && s === "$$") c = {
1453
+ changes: {
1454
+ from: a,
1455
+ insert: "\n\n$$"
1456
+ },
1457
+ anchor: a + 1
1458
+ };
1459
+ else if (It.has(n) && RegExp(`^\\${n}{3,}$`).test(s)) {
1460
+ let e = o.number === 1 || i.line(o.number - 1).text.trim() === "", t = n === "-" && !e, r = o.number === i.lines;
1461
+ if (t || r) {
1462
+ let e = [];
1463
+ t && e.push({
1464
+ from: o.from,
1465
+ insert: "\n"
1466
+ }), r && e.push({
1467
+ from: o.to,
1468
+ insert: "\n"
1469
+ }), c = {
1470
+ changes: e,
1471
+ anchor: o.to + +!!t + +!!r
1472
+ };
1473
+ }
1474
+ }
1475
+ return c ? [e, {
1476
+ changes: c.changes,
1477
+ selection: { anchor: c.anchor },
1478
+ sequential: !0,
1479
+ scrollIntoView: !0,
1480
+ userEvent: "input.autoformat"
1481
+ }] : e;
1482
+ }), Rt = /* @__PURE__ */ new Set([
1483
+ "EmphasisMark",
1484
+ "CodeMark",
1485
+ "StrikethroughMark"
1486
+ ]);
1487
+ function zt(e, t, n) {
1488
+ let r = t;
1489
+ for (;;) {
1490
+ let t = e.resolveInner(r, n);
1491
+ if (!Rt.has(t.name) || t.from >= t.to) return r;
1492
+ let i = n < 0 ? t.from : t.to;
1493
+ if (i === r) return r;
1494
+ r = i;
1495
+ }
1496
+ }
1497
+ function Bt(e, t) {
1498
+ let n = B(e, t, !0);
1499
+ if (!n) return t;
1500
+ let r = T(e);
1501
+ return t === n.contentTo ? zt(r, t, 1) : t === n.contentFrom ? zt(r, t, -1) : t;
1502
+ }
1503
+ var Vt = ge.transactionFilter.of((e) => {
1504
+ if (!e.docChanged || e.isUserEvent("undo") || e.isUserEvent("redo") || e.annotation(Q)) return e;
1505
+ let t = e.startState, n = t.selection.main;
1506
+ if (!n.empty || !z(t, t.doc.lineAt(n.head).number)) return e;
1507
+ let r = [], i = 0;
1508
+ e.changes.iterChanges((e, t, a, o, s) => {
1509
+ i++, e === t && e === n.head && s.length > 0 && r.push(s.toString());
1510
+ });
1511
+ let a = r[0];
1512
+ if (i !== 1 || a === void 0) return e;
1513
+ let o = Bt(t, n.head);
1514
+ return o === n.head ? e : {
1515
+ changes: {
1516
+ from: o,
1517
+ insert: a
1518
+ },
1519
+ selection: { anchor: o + a.length },
1520
+ scrollIntoView: !0,
1521
+ userEvent: "input.type"
1522
+ };
1523
+ });
1524
+ //#endregion
1525
+ //#region src/inplace/edit-line-prefix.ts
1526
+ function Ht(e) {
1527
+ let t = /^#{1,6} /.exec(e);
1528
+ if (t) return {
1529
+ prefixLen: t[0].length,
1530
+ drop: [0, t[0].length]
1531
+ };
1532
+ let n = /^(?:> ?)+/.exec(e);
1533
+ if (n) {
1534
+ let t = /^> ?/.exec(e)[0].length;
1535
+ return {
1536
+ prefixLen: n[0].length,
1537
+ drop: [0, t]
1538
+ };
1539
+ }
1540
+ let r = /^(\s*)[-*+] \[[ xX]\] /.exec(e);
1541
+ if (r) return {
1542
+ prefixLen: r[0].length,
1543
+ drop: [0, r[0].length]
1544
+ };
1545
+ let i = /^(\s*)([-*+] |\d+[.)] )/.exec(e);
1546
+ if (i) {
1547
+ let e = i[1];
1548
+ if (e) {
1549
+ let t = e.startsWith(" ") ? 1 : Math.min(2, e.length);
1550
+ return {
1551
+ prefixLen: i[0].length,
1552
+ drop: [0, t]
1553
+ };
1554
+ }
1555
+ return {
1556
+ prefixLen: i[2].length,
1557
+ drop: [0, i[2].length]
1558
+ };
1559
+ }
1560
+ return null;
1561
+ }
1562
+ var Ut = C.high(pe.of([{
1563
+ key: "Backspace",
1564
+ run: (e) => {
1565
+ if (o(e)) return !1;
1566
+ let { state: t } = e, n = t.selection.main;
1567
+ if (!n.empty) return !1;
1568
+ let r = t.doc.lineAt(n.head);
1569
+ if (!z(t, r.number)) return !1;
1570
+ let i = Ht(r.text);
1571
+ if (!i || n.head < r.from || n.head > r.from + i.prefixLen) return !1;
1572
+ let [a, s] = i.drop;
1573
+ return e.dispatch({
1574
+ changes: {
1575
+ from: r.from + a,
1576
+ to: r.from + s,
1577
+ insert: ""
1578
+ },
1579
+ selection: { anchor: r.from + a },
1580
+ userEvent: "delete.backward",
1581
+ scrollIntoView: !0
1582
+ }), !0;
1583
+ }
1584
+ }])), Wt = class {
1585
+ menu;
1586
+ contentDOM;
1587
+ onClick;
1588
+ constructor(e) {
1589
+ this.menu = X(e.dom.ownerDocument), e.dom.appendChild(this.menu.el), this.contentDOM = e.contentDOM, this.onClick = (t) => {
1590
+ if (e.state.facet(O) !== "never" || !e.state.facet(E).links) return;
1591
+ let n = t.target?.closest(".cm-inplace-link");
1592
+ if (!n || n.classList.contains("cm-inplace-wikilink")) return;
1593
+ let r = e.posAtDOM(n);
1594
+ if (r < 0) {
1595
+ let n = e.posAtCoords({
1596
+ x: t.clientX,
1597
+ y: t.clientY
1598
+ });
1599
+ if (n == null) return;
1600
+ r = n;
1601
+ }
1602
+ e.dispatch({ selection: { anchor: r } }), this.menu.showField(G(e), t.clientX, t.clientY);
1603
+ }, this.contentDOM.addEventListener("click", this.onClick);
1604
+ }
1605
+ destroy() {
1606
+ this.contentDOM.removeEventListener("click", this.onClick), this.menu.destroy();
1607
+ }
1608
+ }, Gt = b.fromClass(Wt), Kt = (e) => e.replace(/^<([^]*)>$/, "$1").trim(), qt = (e, t, n) => n ? {
1609
+ pos: e,
1610
+ end: t,
1611
+ above: !0,
1612
+ create() {
1613
+ let e = document.createElement("div");
1614
+ return e.className = "cm-inplace-href-tip", e.textContent = n, { dom: e };
1615
+ }
1616
+ } : null;
1617
+ function Jt(e, t) {
1618
+ for (let n = T(e.state).resolveInner(t, -1); n; n = n.parent) {
1619
+ if (n.name !== "Link") continue;
1620
+ if (e.state.doc.sliceString(Math.max(0, n.from - 1), n.from) === "[") break;
1621
+ let t = n.getChild("URL"), r = t ? e.state.sliceDoc(t.from, t.to) : e.state.sliceDoc(n.from, n.to);
1622
+ return qt(n.from, n.to, Kt(r));
1623
+ }
1624
+ return null;
1625
+ }
1626
+ function Yt(e, t) {
1627
+ let r = e.state.doc.lineAt(t);
1628
+ for (let e of r.text.matchAll(n)) {
1629
+ let n = r.from + (e.index ?? 0), i = n + e[0].length;
1630
+ if (!(t < n || t > i)) return qt(n, i, (e[1] ?? "").trim());
1631
+ }
1632
+ return null;
1633
+ }
1634
+ var Xt = fe((e, t) => {
1635
+ let n = e.state.facet(E);
1636
+ return (n.links ? Jt(e, t) : null) ?? (n.wikilinks ? Yt(e, t) : null);
1637
+ }), Zt = class {
1638
+ view;
1639
+ menu;
1640
+ onContextMenu;
1641
+ onPointerDown;
1642
+ longPress;
1643
+ contentDOM;
1644
+ stashed = null;
1645
+ longPressAt = 0;
1646
+ constructor(e) {
1647
+ this.view = e, this.menu = X(e.dom.ownerDocument), e.dom.appendChild(this.menu.el), this.contentDOM = e.contentDOM, this.onPointerDown = () => {
1648
+ let t = e.state.selection.main;
1649
+ this.stashed = t.empty ? null : {
1650
+ anchor: t.anchor,
1651
+ head: t.head
1652
+ };
1653
+ }, this.contentDOM.addEventListener("pointerdown", this.onPointerDown, !0), this.onContextMenu = (t) => {
1654
+ let n = t.target;
1655
+ e.state.facet(k) && (n?.closest(".cm-inplace-table-edit") || (t.preventDefault(), this.longPress.cancel(), !(Date.now() - this.longPressAt < 700) && this.openMenuAt(t.clientX, t.clientY, n)));
1656
+ }, this.contentDOM.addEventListener("contextmenu", this.onContextMenu), this.longPress = Et(this.contentDOM, { onLongPress: (e, t, n) => {
1657
+ this.longPressAt = Date.now(), this.openMenuAt(e, t, n);
1658
+ } });
1659
+ }
1660
+ openMenuAt(e, t, n) {
1661
+ let r = this.view;
1662
+ if (r.state.facet(k) && !n?.closest(".cm-inplace-table-edit")) {
1663
+ if (this.stashed && r.state.selection.main.empty) r.dispatch({ selection: this.stashed });
1664
+ else if (r.state.selection.main.empty) {
1665
+ let n = r.posAtCoords({
1666
+ x: e,
1667
+ y: t
1668
+ });
1669
+ if (n != null) {
1670
+ let e = B(r.state, n, !1, !0), t = r.state.wordAt(n) ?? { anchor: n };
1671
+ e?.kind === "link" ? t = {
1672
+ anchor: e.from,
1673
+ head: e.to
1674
+ } : e && e.contentTo > e.contentFrom && (t = {
1675
+ anchor: e.contentFrom,
1676
+ head: e.contentTo
1677
+ }), r.dispatch({ selection: t });
1678
+ }
1679
+ }
1680
+ this.menu.show(St(r), e, t);
1681
+ }
1682
+ }
1683
+ destroy() {
1684
+ this.contentDOM.removeEventListener("pointerdown", this.onPointerDown, !0), this.contentDOM.removeEventListener("contextmenu", this.onContextMenu), this.longPress.dispose(), this.menu.destroy();
1685
+ }
1686
+ }, Qt = b.fromClass(Zt), $t = class {
1687
+ view;
1688
+ bar;
1689
+ ids;
1690
+ buttons = /* @__PURE__ */ new Map();
1691
+ linkMenu;
1692
+ onScroll = () => {
1693
+ this.bar.hidden = !0;
1694
+ };
1695
+ onSelectionChange = () => {
1696
+ o(this.view) && this.schedule();
1697
+ };
1698
+ constructor(e) {
1699
+ this.view = e;
1700
+ let t = e.dom.ownerDocument;
1701
+ this.ids = e.state.facet(Ce), this.linkMenu = X(t), e.dom.appendChild(this.linkMenu.el), this.bar = t.createElement("div"), this.bar.className = "cm-inplace-selbar", this.bar.setAttribute("contenteditable", "false"), this.bar.hidden = !0;
1702
+ for (let n of this.ids) {
1703
+ let r = m[n], i = t.createElement("button");
1704
+ i.type = "button", i.className = "cm-inplace-selbar-btn", i.title = r.title, i.setAttribute("aria-label", r.title), i.appendChild(se(t, g[n] ?? "")), i.addEventListener("mousedown", (e) => e.preventDefault()), i.addEventListener("click", (t) => {
1705
+ t.preventDefault();
1706
+ let a = !!o(e), s = !a && n === "link" ? G(e) : !a && n === "wikilink" ? gt(e) : null;
1707
+ if (s) {
1708
+ let e = i.getBoundingClientRect();
1709
+ this.linkMenu.showField(s, e.left, e.bottom + 6);
1710
+ return;
1711
+ }
1712
+ r.run(e), a || e.focus(), this.schedule();
1713
+ }), this.buttons.set(n, i), this.bar.appendChild(i);
1714
+ }
1715
+ e.dom.appendChild(this.bar), t.addEventListener("scroll", this.onScroll, !0), t.addEventListener("selectionchange", this.onSelectionChange);
1716
+ }
1717
+ update(e) {
1718
+ (e.selectionSet || e.docChanged || e.focusChanged) && this.schedule();
1719
+ }
1720
+ schedule() {
1721
+ this.view.requestMeasure({
1722
+ key: this,
1723
+ read: () => this.measure(),
1724
+ write: (e) => this.apply(e)
1725
+ });
1726
+ }
1727
+ selectionBox() {
1728
+ let { view: e } = this, t = e.state.selection.main;
1729
+ if (!t.empty) {
1730
+ let n = e.coordsAtPos(t.from), r = e.coordsAtPos(t.to);
1731
+ return !n || !r ? null : {
1732
+ inCell: !1,
1733
+ box: {
1734
+ left: Math.min(n.left, r.left),
1735
+ right: Math.max(n.right, r.right),
1736
+ top: Math.min(n.top, r.top),
1737
+ bottom: Math.max(n.bottom, r.bottom)
1738
+ }
1739
+ };
1740
+ }
1741
+ if (!H(e)) return null;
1742
+ let n = e.dom.ownerDocument.getSelection();
1743
+ if (!n || n.rangeCount === 0) return null;
1744
+ let r = n.getRangeAt(0).getBoundingClientRect();
1745
+ return {
1746
+ inCell: !0,
1747
+ box: {
1748
+ left: r.left,
1749
+ right: r.right,
1750
+ top: r.top,
1751
+ bottom: r.bottom
1752
+ }
1753
+ };
1754
+ }
1755
+ measure() {
1756
+ let { view: e } = this;
1757
+ if (e.state.facet(N) !== "bar") return null;
1758
+ let t = this.selectionBox();
1759
+ if (!t) return null;
1760
+ let { box: n, inCell: r } = t;
1761
+ if (!r && !e.hasFocus) return null;
1762
+ let i = this.bar.getBoundingClientRect(), a = e.dom.ownerDocument.defaultView?.innerWidth ?? 0, o = (n.left + n.right) / 2, s = e.dom.getBoundingClientRect().top, c = n.top - i.height - 6, l = n.bottom + 6, u = {}, d = {};
1763
+ for (let t of this.ids) {
1764
+ let n = m[t], i = !r && !!n.disabled?.(e.state);
1765
+ u[t] = i, d[t] = !i && !r && !!n.isActive?.(e.state);
1766
+ }
1767
+ return this.ids.every((e) => u[e]) ? null : {
1768
+ left: Math.max(4, Math.min(o - i.width / 2, a - i.width - 4)),
1769
+ top: c < s + 2 ? l : c,
1770
+ disabled: u,
1771
+ active: d
1772
+ };
1773
+ }
1774
+ apply(e) {
1775
+ if (!e) {
1776
+ this.bar.hidden = !0;
1777
+ return;
1778
+ }
1779
+ this.bar.hidden = !1, this.bar.style.left = `${e.left}px`, this.bar.style.top = `${e.top}px`;
1780
+ for (let [t, n] of this.buttons) n.disabled = e.disabled[t], n.toggleAttribute("data-active", e.active[t]);
1781
+ }
1782
+ destroy() {
1783
+ let e = this.view.dom.ownerDocument;
1784
+ e.removeEventListener("scroll", this.onScroll, !0), e.removeEventListener("selectionchange", this.onSelectionChange), this.linkMenu.destroy(), this.bar.remove();
1785
+ }
1786
+ }, en = b.fromClass($t), tn = class extends x {
1787
+ table;
1788
+ constructor(e) {
1789
+ super(), this.table = e;
1790
+ }
1791
+ eq(e) {
1792
+ return JSON.stringify(this.table) === JSON.stringify(e.table);
1793
+ }
1794
+ toDOM() {
1795
+ let { head: e, body: t, aligns: n } = this.table, r = document.createElement("table");
1796
+ r.className = "cm-inplace-table";
1797
+ let i = (e) => Ct(e.replace(/\\\|/g, "|")), a = r.createTHead().insertRow();
1798
+ e.forEach((e, t) => {
1799
+ let r = document.createElement("th");
1800
+ r.appendChild(i(e)), r.dataset.styloRow = "0", r.dataset.styloCol = String(t), nn(r, n[t]), a.appendChild(r);
1801
+ });
1802
+ let o = r.createTBody();
1803
+ return t.forEach((t, r) => {
1804
+ let a = o.insertRow();
1805
+ for (let o = 0; o < e.length; o++) {
1806
+ let e = a.insertCell();
1807
+ e.appendChild(i(t[o] ?? "")), e.dataset.styloRow = String(r + 1), e.dataset.styloCol = String(o), nn(e, n[o]);
1808
+ }
1809
+ }), r;
1810
+ }
1811
+ ignoreEvent() {
1812
+ return !1;
1813
+ }
1814
+ };
1815
+ function nn(e, t) {
1816
+ t && (e.style.textAlign = t);
1817
+ }
1818
+ function rn(e, t) {
1819
+ let n = t.lineAt(e.from).number, r = t.lineAt(e.to).number, i = [];
1820
+ for (let e = n; e <= r; e++) i.push(t.line(e).text);
1821
+ let a = d(i);
1822
+ return !a || a.rows.length === 0 ? null : {
1823
+ head: a.rows[0],
1824
+ body: a.rows.slice(1),
1825
+ aligns: a.aligns
1826
+ };
1827
+ }
1828
+ function an(e) {
1829
+ if (!e.facet(E).tables) return v.none;
1830
+ let n = e.facet(D) === "cells", r = T(e), i = t(e.doc), a = n ? null : P(e), o = [];
1831
+ return r.iterate({ enter: (t) => {
1832
+ if (t.name !== "Table") return;
1833
+ if (i && t.from < i.to) return !1;
1834
+ if (a) {
1835
+ let n = e.doc.lineAt(t.from).number, r = e.doc.lineAt(t.to).number;
1836
+ for (let e = n; e <= r; e++) if (a.has(e)) return !1;
1837
+ }
1838
+ let r = rn(t.node, e.doc);
1839
+ if (r) {
1840
+ let e = n ? new Ft(r) : new tn(r);
1841
+ o.push(v.replace({
1842
+ widget: e,
1843
+ block: !0
1844
+ }).range(t.from, t.to));
1845
+ }
1846
+ return !1;
1847
+ } }), v.set(o, !0);
1848
+ }
1849
+ var on = w.define({
1850
+ create: an,
1851
+ update: (e, t) => t.annotation(Q) ? e.map(t.changes) : t.state.facet(D) === "cells" ? t.docChanged ? an(t.state) : e.map(t.changes) : t.docChanged || t.selection ? an(t.state) : e,
1852
+ provide: (e) => [y.decorations.from(e), y.atomicRanges.of((t) => t.state.field(e))]
1853
+ }), sn = (e) => (t) => {
1854
+ if (o(t)) return !1;
1855
+ let n = t.state.selection.main;
1856
+ if (!n.empty) return !1;
1857
+ let { doc: r } = t.state, i = r.lineAt(n.head), a = e ? i.number + 1 : i.number - 1;
1858
+ if (a < 1 || a > r.lines) return !1;
1859
+ let s = r.line(a), c = -1, l = -1, u;
1860
+ if (t.state.field(on).between(s.from, s.to, (t, n, r) => {
1861
+ if (e ? t === s.from : n === s.to) return c = t, l = n, u = r.spec.widget, !1;
1862
+ }), c < 0) return !1;
1863
+ if (t.state.facet(D) === "cells") return u instanceof Ft && u.focusEdge(e ? "first" : "last");
1864
+ let d = e ? r.lineAt(c).from : r.lineAt(l).to;
1865
+ return t.dispatch({
1866
+ selection: { anchor: d },
1867
+ userEvent: "select",
1868
+ scrollIntoView: !0
1869
+ }), !0;
1870
+ }, cn = sn(!0), ln = sn(!1), un = C.high(pe.of([{
1871
+ key: "ArrowDown",
1872
+ run: cn
1873
+ }, {
1874
+ key: "ArrowUp",
1875
+ run: ln
1876
+ }])), $ = "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace", dn = y.theme({
1877
+ "& .cm-content": {
1878
+ fontFamily: "-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif",
1879
+ lineHeight: "1.75",
1880
+ padding: "0.75rem",
1881
+ WebkitTouchCallout: "none"
1882
+ },
1883
+ "& .cm-line": {
1884
+ paddingLeft: "0",
1885
+ paddingRight: "0"
1886
+ },
1887
+ ".cm-inplace-heading": { fontWeight: "600" },
1888
+ ".cm-inplace-h1": {
1889
+ fontSize: "2.25em",
1890
+ lineHeight: "1.1111111",
1891
+ paddingTop: "0.35em"
1892
+ },
1893
+ ".cm-inplace-h2": {
1894
+ fontSize: "1.5em",
1895
+ lineHeight: "1.3333333",
1896
+ paddingTop: "0.7em"
1897
+ },
1898
+ ".cm-inplace-h3": {
1899
+ fontSize: "1.25em",
1900
+ lineHeight: "1.6",
1901
+ paddingTop: "0.6em"
1902
+ },
1903
+ ".cm-inplace-h4": {
1904
+ fontSize: "1em",
1905
+ lineHeight: "1.5",
1906
+ paddingTop: "0.5em"
1907
+ },
1908
+ ".cm-inplace-h5": { fontSize: "0.9em" },
1909
+ ".cm-inplace-h6": {
1910
+ fontSize: "0.9em",
1911
+ color: "var(--stylo-text-muted)"
1912
+ },
1913
+ ".cm-inplace-strong": { fontWeight: "700" },
1914
+ ".cm-inplace-em": { fontStyle: "italic" },
1915
+ ".cm-inplace-strike": { textDecoration: "line-through" },
1916
+ ".cm-inplace-code": {
1917
+ fontFamily: $,
1918
+ fontSize: "0.9em",
1919
+ padding: "0.1em 0.35em",
1920
+ borderRadius: "3px",
1921
+ background: "color-mix(in srgb, var(--stylo-border) 45%, transparent)"
1922
+ },
1923
+ ".cm-inplace-mono": {
1924
+ fontFamily: $,
1925
+ fontSize: "0.9em",
1926
+ background: "color-mix(in srgb, var(--stylo-border) 35%, transparent)",
1927
+ padding: "0 0.9rem"
1928
+ },
1929
+ ".cm-inplace-code-top": {
1930
+ paddingTop: "0.7rem",
1931
+ borderTopLeftRadius: "var(--stylo-radius)",
1932
+ borderTopRightRadius: "var(--stylo-radius)"
1933
+ },
1934
+ ".cm-inplace-code-bottom": {
1935
+ paddingBottom: "0.7rem",
1936
+ borderBottomLeftRadius: "var(--stylo-radius)",
1937
+ borderBottomRightRadius: "var(--stylo-radius)"
1938
+ },
1939
+ ".cm-inplace-fence": { color: "var(--stylo-text-muted)" },
1940
+ ".cm-inplace-code-pad": {
1941
+ fontSize: "0",
1942
+ lineHeight: "0"
1943
+ },
1944
+ ".cm-inplace-link": {
1945
+ color: "var(--stylo-link)",
1946
+ textDecoration: "none",
1947
+ cursor: "pointer"
1948
+ },
1949
+ ".cm-inplace-wikilink": { color: "var(--stylo-link)" },
1950
+ ".cm-inplace-math-block": {
1951
+ display: "block",
1952
+ padding: "0.9em 0",
1953
+ textAlign: "center"
1954
+ },
1955
+ ".cm-inplace-math-block .katex-display": { margin: "0" },
1956
+ ".cm-inplace-hr-line": {
1957
+ fontSize: "0",
1958
+ lineHeight: "0"
1959
+ },
1960
+ ".cm-inplace-setext-rule": {
1961
+ fontSize: "0",
1962
+ lineHeight: "0"
1963
+ },
1964
+ ".cm-inplace-hr": {
1965
+ display: "block",
1966
+ height: "1.6rem",
1967
+ margin: "0",
1968
+ border: "none",
1969
+ background: "linear-gradient(var(--stylo-border), var(--stylo-border)) left center / 100% 1px no-repeat"
1970
+ },
1971
+ ".cm-inplace-quote": {
1972
+ borderLeft: "0.25rem solid var(--stylo-border)",
1973
+ paddingLeft: "1rem",
1974
+ color: "var(--stylo-text-muted)"
1975
+ },
1976
+ ".cm-inplace-callout": {
1977
+ borderLeft: "0.25rem solid var(--stylo-callout-accent, var(--stylo-border))",
1978
+ padding: "0 1rem",
1979
+ background: "color-mix(in srgb, var(--stylo-callout-accent, var(--stylo-border)) 10%, transparent)",
1980
+ color: "var(--stylo-text)"
1981
+ },
1982
+ ".cm-inplace-callout-head": {
1983
+ paddingTop: "0.7em",
1984
+ borderTopRightRadius: "var(--stylo-radius)"
1985
+ },
1986
+ ".cm-inplace-callout-foot": {
1987
+ paddingBottom: "0.7em",
1988
+ borderBottomRightRadius: "var(--stylo-radius)"
1989
+ },
1990
+ ".cm-inplace-callout-note": { "--stylo-callout-accent": "var(--stylo-callout-note, #3b82f6)" },
1991
+ ".cm-inplace-callout-tip": { "--stylo-callout-accent": "var(--stylo-callout-tip, #22c55e)" },
1992
+ ".cm-inplace-callout-warn": { "--stylo-callout-accent": "var(--stylo-callout-warn, #f59e0b)" },
1993
+ ".cm-inplace-callout-danger": { "--stylo-callout-accent": "var(--stylo-callout-danger, #ef4444)" },
1994
+ ".cm-inplace-callout-example": { "--stylo-callout-accent": "var(--stylo-callout-example, #a855f7)" },
1995
+ ".cm-inplace-callout-head::before": {
1996
+ content: "attr(data-callout)",
1997
+ display: "block",
1998
+ marginBottom: "0.2em",
1999
+ fontSize: "0.8em",
2000
+ fontWeight: "700",
2001
+ textTransform: "uppercase",
2002
+ letterSpacing: "0.04em",
2003
+ color: "var(--stylo-callout-accent, var(--stylo-text-muted))"
2004
+ },
2005
+ ".cm-inplace-callout-head[data-revealed]::before": {
2006
+ content: "\"\"",
2007
+ display: "none"
2008
+ },
2009
+ ".cm-inplace-bullet": { color: "var(--stylo-text-muted)" },
2010
+ ".cm-inplace-li": {
2011
+ backgroundImage: "repeating-linear-gradient(to right, var(--stylo-guide) 0 1px, transparent 1px 1.5em)",
2012
+ backgroundRepeat: "no-repeat",
2013
+ backgroundPosition: "0.35em 0",
2014
+ backgroundSize: "calc(var(--sl-li-depth, 0) * 1.5em) 100%"
2015
+ },
2016
+ ".cm-inplace-checkbox": {
2017
+ margin: "0 0.4em 0 0",
2018
+ verticalAlign: "middle",
2019
+ cursor: "pointer"
2020
+ },
2021
+ ".cm-inplace-fm": {
2022
+ fontFamily: $,
2023
+ fontSize: "0.85em",
2024
+ color: "var(--stylo-text-muted)"
2025
+ },
2026
+ ".cm-inplace-fm-first::before": {
2027
+ content: "\"Frontmatter\"",
2028
+ marginRight: "0.6em",
2029
+ fontFamily: "-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif",
2030
+ fontSize: "0.8rem",
2031
+ fontWeight: "600",
2032
+ textTransform: "uppercase",
2033
+ letterSpacing: "0.04em",
2034
+ color: "var(--stylo-text-muted)"
2035
+ },
2036
+ ".cm-inplace-table": {
2037
+ borderCollapse: "collapse",
2038
+ padding: "1em 0 1.4em",
2039
+ fontSize: "0.95em"
2040
+ },
2041
+ ".cm-inplace-table th": {
2042
+ padding: "0.35em 0.6em",
2043
+ border: "1px solid var(--stylo-table-border)",
2044
+ background: "var(--stylo-table-header-bg)",
2045
+ fontWeight: "600"
2046
+ },
2047
+ ".cm-inplace-table td": {
2048
+ padding: "0.35em 0.6em",
2049
+ border: "1px solid var(--stylo-table-border)"
2050
+ },
2051
+ ".cm-inplace-table tbody tr:nth-child(even) td": { background: "var(--stylo-table-stripe-bg)" },
2052
+ ".cm-inplace-table-edit .cm-inplace-tcell": {
2053
+ minWidth: "3em",
2054
+ cursor: "text",
2055
+ outline: "none"
2056
+ },
2057
+ ".cm-inplace-table-edit .cm-inplace-tcell:focus": { boxShadow: "inset 0 0 0 2px var(--stylo-ring)" },
2058
+ ".cm-inplace-table-wrap": {
2059
+ position: "relative",
2060
+ display: "inline-block",
2061
+ maxWidth: "100%",
2062
+ padding: "0 calc(1.15em + 4px) calc(1.15em + 4px) 0"
2063
+ },
2064
+ ".cm-inplace-table-gizmos": {
2065
+ position: "absolute",
2066
+ inset: "0",
2067
+ pointerEvents: "none"
2068
+ },
2069
+ ".cm-inplace-tg-edge": {
2070
+ position: "absolute",
2071
+ display: "flex",
2072
+ alignItems: "center",
2073
+ justifyContent: "center",
2074
+ pointerEvents: "auto",
2075
+ padding: "0",
2076
+ font: "inherit",
2077
+ border: "none",
2078
+ background: "transparent",
2079
+ cursor: "pointer",
2080
+ opacity: "0",
2081
+ transition: "opacity 0.1s ease"
2082
+ },
2083
+ ".cm-inplace-tg-edge:hover": {
2084
+ opacity: "1",
2085
+ background: "color-mix(in srgb, var(--stylo-border) 30%, transparent)"
2086
+ },
2087
+ ".cm-inplace-tg-addcol": { width: "1.15em" },
2088
+ ".cm-inplace-tg-addrow": { height: "1.15em" },
2089
+ ".cm-inplace-tg-plus": {
2090
+ width: "0.7em",
2091
+ height: "0.7em",
2092
+ color: "var(--stylo-text-muted)",
2093
+ background: "linear-gradient(currentColor, currentColor) center / 100% 2px no-repeat,linear-gradient(currentColor, currentColor) center / 2px 100% no-repeat",
2094
+ pointerEvents: "none"
2095
+ },
2096
+ ".cm-inplace-tg-edge:hover .cm-inplace-tg-plus": { color: "var(--stylo-text)" },
2097
+ "@media (hover: none)": { ".cm-inplace-tg-edge": { opacity: "0.5" } },
2098
+ ".cm-inplace-menu": {
2099
+ position: "fixed",
2100
+ inset: "0",
2101
+ zIndex: "20",
2102
+ pointerEvents: "none"
2103
+ },
2104
+ ".cm-inplace-menu-panel": {
2105
+ position: "fixed",
2106
+ minWidth: "12em",
2107
+ padding: "0.25em",
2108
+ display: "flex",
2109
+ flexDirection: "column",
2110
+ pointerEvents: "auto",
2111
+ background: "var(--stylo-surface-floating, #fff)",
2112
+ border: "1px solid var(--stylo-border)",
2113
+ borderRadius: "6px",
2114
+ boxShadow: "0 4px 16px rgba(0, 0, 0, 0.12)",
2115
+ font: "inherit"
2116
+ },
2117
+ ".cm-inplace-menu-sep": {
2118
+ height: "1px",
2119
+ margin: "0.25em 0.3em",
2120
+ background: "var(--stylo-border)"
2121
+ },
2122
+ ".cm-inplace-menu-item": {
2123
+ all: "unset",
2124
+ display: "flex",
2125
+ alignItems: "center",
2126
+ gap: "0.55em",
2127
+ padding: "0.35em 0.6em",
2128
+ borderRadius: "4px",
2129
+ fontSize: "0.9em",
2130
+ cursor: "pointer",
2131
+ whiteSpace: "nowrap"
2132
+ },
2133
+ ".cm-inplace-menu-item svg": {
2134
+ width: "1em",
2135
+ height: "1em",
2136
+ flex: "0 0 auto",
2137
+ color: "var(--stylo-text-muted)"
2138
+ },
2139
+ ".cm-inplace-menu-item:hover:not(:disabled)": { background: "color-mix(in srgb, var(--stylo-border) 40%, transparent)" },
2140
+ ".cm-inplace-menu-item:disabled": {
2141
+ opacity: "0.4",
2142
+ cursor: "default"
2143
+ },
2144
+ ".cm-inplace-menu-item[data-active]": {
2145
+ color: "var(--stylo-accent)",
2146
+ fontWeight: "600"
2147
+ },
2148
+ ".cm-inplace-menu-item[data-active] svg": { color: "var(--stylo-accent)" },
2149
+ ".cm-inplace-menu-parent::after": {
2150
+ content: "\"\\203A\"",
2151
+ marginLeft: "auto",
2152
+ paddingLeft: "1.5em"
2153
+ },
2154
+ ".cm-inplace-menu-input": {
2155
+ display: "block",
2156
+ boxSizing: "border-box",
2157
+ width: "18em",
2158
+ maxWidth: "70vw",
2159
+ margin: "0.15em",
2160
+ padding: "0.45em 0.6em",
2161
+ border: "1px solid var(--stylo-text-muted)",
2162
+ borderRadius: "4px",
2163
+ fontSize: "0.9em",
2164
+ fontFamily: "inherit",
2165
+ lineHeight: "1.4",
2166
+ color: "var(--stylo-text)",
2167
+ background: "var(--stylo-surface-floating, #fff)",
2168
+ outline: "none"
2169
+ },
2170
+ ".cm-inplace-menu-input:focus": { borderColor: "var(--stylo-ring)" },
2171
+ ".cm-inplace-selbar": {
2172
+ position: "fixed",
2173
+ zIndex: "20",
2174
+ display: "flex",
2175
+ gap: "0.1em",
2176
+ padding: "0.2em",
2177
+ background: "var(--stylo-surface-floating, #fff)",
2178
+ border: "1px solid var(--stylo-border)",
2179
+ borderRadius: "6px",
2180
+ boxShadow: "0 4px 16px rgba(0, 0, 0, 0.12)"
2181
+ },
2182
+ ".cm-inplace-selbar[hidden]": {
2183
+ visibility: "hidden",
2184
+ pointerEvents: "none"
2185
+ },
2186
+ ".cm-inplace-selbar-btn": {
2187
+ all: "unset",
2188
+ display: "flex",
2189
+ padding: "0.3em",
2190
+ borderRadius: "4px",
2191
+ cursor: "pointer",
2192
+ color: "var(--stylo-text-muted)"
2193
+ },
2194
+ ".cm-inplace-selbar-btn svg": {
2195
+ width: "1.05em",
2196
+ height: "1.05em",
2197
+ display: "block"
2198
+ },
2199
+ ".cm-inplace-selbar-btn:hover": {
2200
+ background: "color-mix(in srgb, var(--stylo-border) 40%, transparent)",
2201
+ color: "var(--stylo-text)"
2202
+ },
2203
+ ".cm-inplace-selbar-btn[data-active]": {
2204
+ color: "var(--stylo-text)",
2205
+ background: "color-mix(in srgb, var(--stylo-border) 55%, transparent)"
2206
+ },
2207
+ "@media (pointer: coarse)": {
2208
+ ".cm-inplace-menu-panel": {
2209
+ minWidth: "14em",
2210
+ padding: "0.25em"
2211
+ },
2212
+ ".cm-inplace-menu-item": {
2213
+ padding: "9px 0.75em",
2214
+ fontSize: "1em"
2215
+ },
2216
+ ".cm-inplace-menu-item svg": {
2217
+ width: "1.15em",
2218
+ height: "1.15em"
2219
+ },
2220
+ ".cm-inplace-menu-sep": { margin: "0.2em 0.3em" },
2221
+ ".cm-inplace-menu-input": {
2222
+ padding: "9px 0.75em",
2223
+ fontSize: "1em"
2224
+ },
2225
+ ".cm-inplace-selbar": {
2226
+ gap: "0.15em",
2227
+ padding: "0.25em"
2228
+ },
2229
+ ".cm-inplace-selbar-btn": {
2230
+ padding: "0.55em",
2231
+ minWidth: "44px",
2232
+ justifyContent: "center"
2233
+ },
2234
+ ".cm-inplace-selbar-btn svg": {
2235
+ width: "1.25em",
2236
+ height: "1.25em"
2237
+ }
2238
+ },
2239
+ ".cm-tooltip.cm-tooltip-hover:has(.cm-inplace-href-tip)": {
2240
+ border: "none",
2241
+ background: "transparent"
2242
+ },
2243
+ ".cm-inplace-href-tip": {
2244
+ maxWidth: "min(28em, 70vw)",
2245
+ padding: "0.3em 0.55em",
2246
+ borderRadius: "5px",
2247
+ background: "var(--stylo-surface-floating, #fff)",
2248
+ border: "1px solid var(--stylo-border)",
2249
+ boxShadow: "0 4px 16px rgba(0, 0, 0, 0.12)",
2250
+ color: "var(--stylo-text-muted)",
2251
+ fontSize: "0.82em",
2252
+ lineHeight: "1.4",
2253
+ wordBreak: "break-all"
2254
+ }
2255
+ }), fn = ".cm-inplace-math, .cm-inplace-hr, .cm-inplace-table";
2256
+ function pn(e, t, n) {
2257
+ let r = e.firstChild, i = e.textContent?.length ?? 0;
2258
+ if (!r || r.nodeType !== Node.TEXT_NODE || i === 0) return 0;
2259
+ let a = e.ownerDocument, o = null, s = 0;
2260
+ if (a.caretPositionFromPoint) {
2261
+ let e = a.caretPositionFromPoint(t, n);
2262
+ e && ([o, s] = [e.offsetNode, e.offset]);
2263
+ } else if (a.caretRangeFromPoint) {
2264
+ let e = a.caretRangeFromPoint(t, n);
2265
+ e && ([o, s] = [e.startContainer, e.startOffset]);
2266
+ }
2267
+ return o === r ? Math.min(s, i) : o === e && s > 0 ? i : 0;
2268
+ }
2269
+ function mn(e = {}) {
2270
+ let t = xe(e.inPlace?.contextMenu);
2271
+ return [
2272
+ E.of(ye(e.inPlace)),
2273
+ D.of(e.inPlace?.table ?? "source"),
2274
+ O.of(e.inPlace?.reveal ?? "caret"),
2275
+ be.of(e.onLinkClick ?? null),
2276
+ k.of(t.enabled),
2277
+ M.of(t.groups),
2278
+ N.of(e.inPlace?.selectionUI ?? "menu"),
2279
+ Ce.of(Se(e.inPlace?.selectionBarItems)),
2280
+ qe(),
2281
+ Ut,
2282
+ it,
2283
+ un,
2284
+ Vt,
2285
+ Lt,
2286
+ Ne,
2287
+ Te,
2288
+ on,
2289
+ Qt,
2290
+ en,
2291
+ Gt,
2292
+ Xt,
2293
+ C.high(dn),
2294
+ y.domEventHandlers({
2295
+ mousedown(e, t) {
2296
+ let n = e.target;
2297
+ if (n?.closest(".cm-inplace-table-edit")) return !1;
2298
+ let r = n?.closest(fn);
2299
+ if (!r) return !1;
2300
+ let i = t.posAtDOM(r);
2301
+ if (i < 0) return !1;
2302
+ let a = n?.closest("[data-stylo-row]");
2303
+ if (a && r.contains(a)) {
2304
+ let n = te(t.state.doc, i, Number(a.dataset.styloRow), Number(a.dataset.styloCol));
2305
+ n != null && (i = n + pn(a, e.clientX, e.clientY));
2306
+ }
2307
+ return t.focus(), t.dispatch({ selection: { anchor: i } }), !0;
2308
+ },
2309
+ click(t) {
2310
+ if (!e.onWikiLinkClick) return !1;
2311
+ let n = t.target?.closest("[data-stylo-wikilink]");
2312
+ return n && e.onWikiLinkClick(n.getAttribute("data-stylo-wikilink") ?? ""), !1;
2313
+ }
2314
+ })
2315
+ ];
2316
+ }
2317
+ //#endregion
2318
+ //#region src/inplace/InPlaceView.tsx
2319
+ function hn({ value: t, onChange: n, readOnly: r, placeholder: i, onWikiLinkClick: a, onLinkClick: o, inPlace: s, codeLanguages: c, onSave: l, onViewChange: u }) {
2320
+ let d = ue(a);
2321
+ d.current = a;
2322
+ let f = ue(o);
2323
+ f.current = o;
2324
+ let [p] = de(() => [mn({
2325
+ onWikiLinkClick: (e) => d.current?.(e),
2326
+ onLinkClick: (e) => f.current?.(e),
2327
+ inPlace: s
2328
+ })]), m = re({
2329
+ value: t,
2330
+ onChange: n,
2331
+ readOnly: r,
2332
+ placeholder: i,
2333
+ extensions: p,
2334
+ codeLanguages: c,
2335
+ onSave: l,
2336
+ onViewChange: u
2337
+ });
2338
+ return /* @__PURE__ */ _e("div", {
2339
+ className: e.inplace,
2340
+ ref: m
2341
+ });
2342
+ }
2343
+ //#endregion
2344
+ export { hn as InPlaceView };
2345
+
2346
+ //# sourceMappingURL=InPlaceView-Ba7JCZ2Y.js.map