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