@damiro/stylo 0.5.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/README.md +42 -19
  2. package/dist/{InPlaceView-B1GXXnoz.js → InPlaceView-Bu91_3Ig.js} +1200 -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 +5 -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 +6 -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/theme.d.ts.map +1 -1
  14. package/dist/editor/useCodeMirror.d.ts +6 -2
  15. package/dist/editor/useCodeMirror.d.ts.map +1 -1
  16. package/dist/editor/wikilink-complete.d.ts +17 -0
  17. package/dist/editor/wikilink-complete.d.ts.map +1 -0
  18. package/dist/embed-B2Dfkpd_.js +124 -0
  19. package/dist/embed-B2Dfkpd_.js.map +1 -0
  20. package/dist/embed.d.ts +14 -0
  21. package/dist/embed.d.ts.map +1 -0
  22. package/dist/frontmatter-DGUkb9z-.js +39 -0
  23. package/dist/frontmatter-DGUkb9z-.js.map +1 -0
  24. package/dist/index.d.ts +1 -1
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/inplace/InPlaceView.d.ts +13 -2
  27. package/dist/inplace/InPlaceView.d.ts.map +1 -1
  28. package/dist/inplace/config.d.ts +8 -0
  29. package/dist/inplace/config.d.ts.map +1 -1
  30. package/dist/inplace/context-menu-actions.d.ts +5 -14
  31. package/dist/inplace/context-menu-actions.d.ts.map +1 -1
  32. package/dist/inplace/context-menu-helpers.d.ts +30 -0
  33. package/dist/inplace/context-menu-helpers.d.ts.map +1 -0
  34. package/dist/inplace/context-menu-shell.d.ts +23 -0
  35. package/dist/inplace/context-menu-shell.d.ts.map +1 -0
  36. package/dist/inplace/context-menu-types.d.ts +46 -0
  37. package/dist/inplace/context-menu-types.d.ts.map +1 -0
  38. package/dist/inplace/context-menu.d.ts +2 -42
  39. package/dist/inplace/context-menu.d.ts.map +1 -1
  40. package/dist/inplace/decorate.d.ts.map +1 -1
  41. package/dist/inplace/edit-boundaries.d.ts +1 -25
  42. package/dist/inplace/edit-boundaries.d.ts.map +1 -1
  43. package/dist/inplace/edit-divider.d.ts +27 -0
  44. package/dist/inplace/edit-divider.d.ts.map +1 -0
  45. package/dist/inplace/embed-registry.d.ts +39 -0
  46. package/dist/inplace/embed-registry.d.ts.map +1 -0
  47. package/dist/inplace/embed.d.ts +8 -0
  48. package/dist/inplace/embed.d.ts.map +1 -0
  49. package/dist/inplace/extension.d.ts +6 -0
  50. package/dist/inplace/extension.d.ts.map +1 -1
  51. package/dist/inplace/inline-md.d.ts +6 -1
  52. package/dist/inplace/inline-md.d.ts.map +1 -1
  53. package/dist/inplace/link-row.d.ts +21 -0
  54. package/dist/inplace/link-row.d.ts.map +1 -0
  55. package/dist/inplace/math-edit.d.ts +36 -0
  56. package/dist/inplace/math-edit.d.ts.map +1 -0
  57. package/dist/inplace/math.d.ts +12 -0
  58. package/dist/inplace/math.d.ts.map +1 -1
  59. package/dist/inplace/menu-plugin.d.ts.map +1 -1
  60. package/dist/inplace/nodes-blocks.d.ts +14 -0
  61. package/dist/inplace/nodes-blocks.d.ts.map +1 -0
  62. package/dist/inplace/nodes-inline.d.ts +16 -0
  63. package/dist/inplace/nodes-inline.d.ts.map +1 -0
  64. package/dist/inplace/nodes.d.ts +3 -2
  65. package/dist/inplace/nodes.d.ts.map +1 -1
  66. package/dist/inplace/scan.d.ts +6 -0
  67. package/dist/inplace/scan.d.ts.map +1 -1
  68. package/dist/inplace/selection-bar-position.d.ts +31 -0
  69. package/dist/inplace/selection-bar-position.d.ts.map +1 -0
  70. package/dist/inplace/selection-bar.d.ts +0 -2
  71. package/dist/inplace/selection-bar.d.ts.map +1 -1
  72. package/dist/inplace/table-widget-caret.d.ts +11 -0
  73. package/dist/inplace/table-widget-caret.d.ts.map +1 -0
  74. package/dist/inplace/table-widget-render.d.ts +18 -0
  75. package/dist/inplace/table-widget-render.d.ts.map +1 -0
  76. package/dist/inplace/table-widget.d.ts +5 -2
  77. package/dist/inplace/table-widget.d.ts.map +1 -1
  78. package/dist/inplace/tables.d.ts.map +1 -1
  79. package/dist/inplace/theme-callout.d.ts +50 -0
  80. package/dist/inplace/theme-callout.d.ts.map +1 -0
  81. package/dist/inplace/theme-canvas.d.ts +166 -0
  82. package/dist/inplace/theme-canvas.d.ts.map +1 -0
  83. package/dist/inplace/theme-fonts.d.ts +4 -0
  84. package/dist/inplace/theme-fonts.d.ts.map +1 -0
  85. package/dist/inplace/theme-menu.d.ts +87 -0
  86. package/dist/inplace/theme-menu.d.ts.map +1 -0
  87. package/dist/inplace/theme-popups.d.ts +94 -0
  88. package/dist/inplace/theme-popups.d.ts.map +1 -0
  89. package/dist/inplace/theme-table-gizmos.d.ts +57 -0
  90. package/dist/inplace/theme-table-gizmos.d.ts.map +1 -0
  91. package/dist/inplace/theme-table.d.ts +30 -0
  92. package/dist/inplace/theme-table.d.ts.map +1 -0
  93. package/dist/inplace/theme.d.ts +5 -0
  94. package/dist/inplace/theme.d.ts.map +1 -1
  95. package/dist/inplace/wikilinks.d.ts.map +1 -1
  96. package/dist/inplace/wrap-at.d.ts +32 -0
  97. package/dist/inplace/wrap-at.d.ts.map +1 -0
  98. package/dist/{markdown-N3lRmU2n.js → markdown-BYXs9Tj8.js} +2 -2
  99. package/dist/{markdown-N3lRmU2n.js.map → markdown-BYXs9Tj8.js.map} +1 -1
  100. package/dist/render/Embed.d.ts +24 -0
  101. package/dist/render/Embed.d.ts.map +1 -0
  102. package/dist/render/Preview.d.ts +6 -2
  103. package/dist/render/Preview.d.ts.map +1 -1
  104. package/dist/render/embed-cache.d.ts +10 -0
  105. package/dist/render/embed-cache.d.ts.map +1 -0
  106. package/dist/render/remark-embed.d.ts +19 -0
  107. package/dist/render/remark-embed.d.ts.map +1 -0
  108. package/dist/styles.css +1 -1
  109. package/dist/stylo.js +75 -54
  110. package/dist/stylo.js.map +1 -1
  111. package/dist/toolbar/block.d.ts +0 -26
  112. package/dist/toolbar/block.d.ts.map +1 -1
  113. package/dist/toolbar/command-helpers.d.ts +57 -0
  114. package/dist/toolbar/command-helpers.d.ts.map +1 -0
  115. package/dist/toolbar/commands.d.ts +1 -21
  116. package/dist/toolbar/commands.d.ts.map +1 -1
  117. package/dist/toolbar/frontmatter-toggle.d.ts +13 -0
  118. package/dist/toolbar/frontmatter-toggle.d.ts.map +1 -0
  119. package/dist/toolbar/heading.d.ts +10 -0
  120. package/dist/toolbar/heading.d.ts.map +1 -0
  121. package/dist/toolbar/inline-ops.d.ts +3 -53
  122. package/dist/toolbar/inline-ops.d.ts.map +1 -1
  123. package/dist/toolbar/link-ops.d.ts +22 -0
  124. package/dist/toolbar/link-ops.d.ts.map +1 -0
  125. package/dist/toolbar/rule.d.ts +11 -0
  126. package/dist/toolbar/rule.d.ts.map +1 -0
  127. package/dist/toolbar/table-position.d.ts +32 -0
  128. package/dist/toolbar/table-position.d.ts.map +1 -0
  129. package/dist/toolbar/table.d.ts +1 -16
  130. package/dist/toolbar/table.d.ts.map +1 -1
  131. package/dist/toolbar/underline-ops.d.ts +15 -0
  132. package/dist/toolbar/underline-ops.d.ts.map +1 -0
  133. package/dist/toolbar/wikilink-ops.d.ts +22 -0
  134. package/dist/toolbar/wikilink-ops.d.ts.map +1 -0
  135. package/dist/types.d.ts +73 -0
  136. package/dist/types.d.ts.map +1 -1
  137. package/dist/{useCodeMirror-hLeJQw6e.js → useCodeMirror-DtwupFgc.js} +590 -526
  138. package/dist/useCodeMirror-DtwupFgc.js.map +1 -0
  139. package/package.json +5 -1
  140. package/dist/InPlaceView-B1GXXnoz.js.map +0 -1
  141. package/dist/Preview-Dxb9zPVv.js +0 -93
  142. package/dist/Preview-Dxb9zPVv.js.map +0 -1
  143. package/dist/callout-oLE630ZP.js +0 -37
  144. package/dist/callout-oLE630ZP.js.map +0 -1
  145. package/dist/useCodeMirror-hLeJQw6e.js.map +0 -1
  146. package/dist/wikilink-BFpTehto.js +0 -42
  147. package/dist/wikilink-BFpTehto.js.map +0 -1
@@ -1,168 +1,135 @@
1
- import { n as e, t } from "./wikilink-BFpTehto.js";
1
+ import { r as e, t } from "./frontmatter-DGUkb9z-.js";
2
2
  import { useEffect as n, useRef as r } from "react";
3
3
  import { EditorView as i, keymap as a, placeholder as o } from "@codemirror/view";
4
4
  import { Annotation as s, ChangeSet as c, Compartment as l, EditorSelection as u, EditorState as d, Facet as f, Prec as p } from "@codemirror/state";
5
- import { defaultKeymap as ee, history as m, historyKeymap as h, redo as g, undo as _ } from "@codemirror/commands";
6
- import { markdown as v, markdownLanguage as y } from "@codemirror/lang-markdown";
7
- import { openSearchPanel as b, search as x, searchKeymap as te } from "@codemirror/search";
8
- import { HighlightStyle as ne, syntaxHighlighting as re, syntaxTree as ie } from "@codemirror/language";
9
- import { tags as S } from "@lezer/highlight";
10
- //#region src/editor/save.ts
11
- var C = f.define({ combine: (e) => e[0] ?? null });
12
- function ae(e) {
13
- let t = e.state.facet(C);
14
- return t ? (t(e.state.doc.toString()), !0) : !1;
15
- }
16
- //#endregion
17
- //#region src/toolbar/block.ts
18
- function w(e) {
19
- let { from: t, to: n } = e.selection.main;
20
- return [e.doc.lineAt(t).number, e.doc.lineAt(n).number];
21
- }
22
- function oe(e, t) {
23
- let n = "#".repeat(t) + " ", r = e.state, [i, a] = w(r), o = [];
24
- for (let e = i; e <= a; e++) {
25
- let i = r.doc.line(e), a = /^(#{1,6}) +/.exec(i.text);
26
- a && a[1].length === t ? o.push({
27
- from: i.from,
28
- to: i.from + a[0].length
29
- }) : a ? o.push({
30
- from: i.from,
31
- to: i.from + a[0].length,
32
- insert: n
33
- }) : o.push({
34
- from: i.from,
35
- insert: n
36
- });
37
- }
38
- return e.dispatch({
39
- changes: o,
40
- scrollIntoView: !0
41
- }), e.focus(), !0;
42
- }
43
- function se(e) {
44
- let t = e.state, [n, r] = w(t), i = [];
45
- for (let e = n; e <= r; e++) {
46
- let n = t.doc.line(e), r = /^#{1,6} +/.exec(n.text);
47
- r && i.push({
48
- from: n.from,
49
- to: n.from + r[0].length
50
- });
5
+ import { defaultKeymap as ee, history as te, historyKeymap as m, redo as h, undo as g } from "@codemirror/commands";
6
+ import { markdown as _, markdownLanguage as v } from "@codemirror/lang-markdown";
7
+ import { openSearchPanel as y, search as b, searchKeymap as ne } from "@codemirror/search";
8
+ import { HighlightStyle as x, syntaxHighlighting as S, syntaxTree as C } from "@codemirror/language";
9
+ import { tags as w } from "@lezer/highlight";
10
+ import { autocompletion as re } from "@codemirror/autocomplete";
11
+ //#region src/toolbar/link-ops.ts
12
+ function T(e, t) {
13
+ let n = /\[([^\]]*)\]\([^)]*\)/g;
14
+ for (let r; r = n.exec(e);) {
15
+ let e = r.index, n = e + r[0].length;
16
+ if (t >= e && t <= n) return {
17
+ from: e,
18
+ to: n,
19
+ label: r[1] ?? ""
20
+ };
51
21
  }
52
- return i.length ? (e.dispatch({
53
- changes: i,
54
- scrollIntoView: !0
55
- }), e.focus(), !0) : !1;
22
+ return null;
56
23
  }
57
- function ce(e, t) {
58
- let n = e.state, [r, i] = w(n), a = r === i && !n.doc.line(r).text.trim(), o = !a;
59
- for (let e = r; e <= i && o; e++) {
60
- let r = n.doc.line(e).text;
61
- r.trim() && !t.match.test(r) && (o = !1);
62
- }
63
- let s = [], c = 0;
64
- for (let e = r; e <= i; e++) {
65
- let r = n.doc.line(e);
66
- if (!r.text.trim() && !a) continue;
67
- let i = t.match.exec(r.text);
68
- if (o) {
69
- i && s.push({
70
- from: r.from,
71
- to: r.from + i[0].length
72
- });
73
- continue;
74
- }
75
- if (i) continue;
76
- let l = typeof t.insert == "function" ? t.insert(c++) : t.insert, u = t.siblings?.exec(r.text);
77
- if (u) s.push({
78
- from: r.from + (u[1] ?? "").length,
79
- to: r.from + u[0].length,
80
- insert: l
81
- });
82
- else {
83
- let e = /^\s*/.exec(r.text)[0].length;
84
- s.push({
85
- from: r.from + e,
86
- insert: l
87
- });
24
+ function ie(e, t) {
25
+ let n = /\[([^\]]*)\]\(([^)]*)\)/g;
26
+ for (let r; r = n.exec(e);) {
27
+ let e = r.index, n = e + r[0].length;
28
+ if (t >= e && t <= n) {
29
+ let t = r[1] ?? "", i = r[2] ?? "", a = e + 1 + t.length + 2;
30
+ return {
31
+ from: e,
32
+ to: n,
33
+ label: t,
34
+ url: i,
35
+ urlFrom: a,
36
+ urlTo: a + i.length
37
+ };
88
38
  }
89
39
  }
90
- return s.length ? (e.dispatch({
91
- changes: s,
92
- scrollIntoView: !0
93
- }), e.focus(), !0) : !1;
40
+ return null;
94
41
  }
95
- function le(e, t) {
96
- return t.test(e.doc.lineAt(e.selection.main.head).text);
42
+ function ae(e, t, n) {
43
+ let r = T(e, t);
44
+ if (r) return {
45
+ text: e.slice(0, r.from) + r.label + e.slice(r.to),
46
+ from: r.from,
47
+ to: r.from + r.label.length
48
+ };
49
+ let i = e.slice(t, n) || "text", a = t + i.length + 3;
50
+ return {
51
+ text: e.slice(0, t) + `[${i}](url)` + e.slice(n),
52
+ from: a,
53
+ to: a + 3
54
+ };
97
55
  }
98
- var ue = /^ {0,3}([-*_])[ \t]*(?:\1[ \t]*){2,}$/;
99
- function de(e) {
100
- let t = e.state, n = t.doc.lineAt(t.selection.main.head);
101
- return ue.test(n.text) ? e.dispatch({
102
- changes: {
103
- from: n.from,
104
- to: Math.min(n.to + 1, t.doc.length)
105
- },
106
- scrollIntoView: !0
107
- }) : n.text.trim() === "" ? e.dispatch({
108
- changes: {
109
- from: n.from,
110
- to: n.to,
111
- insert: "---"
112
- },
113
- selection: u.cursor(n.from + 3),
114
- scrollIntoView: !0
115
- }) : e.dispatch({
116
- changes: {
117
- from: n.to,
118
- insert: "\n\n---\n"
119
- },
120
- selection: u.cursor(n.to + 6),
121
- scrollIntoView: !0
122
- }), e.focus(), !0;
56
+ //#endregion
57
+ //#region src/toolbar/wikilink-ops.ts
58
+ function E(t, n) {
59
+ for (let r of t.matchAll(e)) {
60
+ let e = r.index ?? 0, t = e + r[0].length;
61
+ if (n >= e && n <= t) return {
62
+ from: e,
63
+ to: t,
64
+ label: r[2] || r[1] || ""
65
+ };
66
+ }
67
+ return null;
123
68
  }
124
- function fe(e) {
125
- return ue.test(e.doc.lineAt(e.selection.main.head).text);
69
+ function oe(t, n) {
70
+ for (let r of t.matchAll(e)) {
71
+ let e = r.index ?? 0, t = e + r[0].length;
72
+ if (n < e || n > t) continue;
73
+ let i = r[1] ?? "", a = e + 2;
74
+ return {
75
+ from: e,
76
+ to: t,
77
+ target: i,
78
+ label: r[2] ?? "",
79
+ targetFrom: a,
80
+ targetTo: a + i.length
81
+ };
82
+ }
83
+ return null;
126
84
  }
127
- function pe(t) {
128
- let n = t.state, r = e(n.doc);
129
- if (r) {
130
- let e = n.doc.lineAt(r.from), i = n.doc.lineAt(r.to);
131
- t.dispatch({
132
- changes: [{
133
- from: e.from,
134
- to: Math.min(e.to + 1, n.doc.length)
135
- }, {
136
- from: i.from,
137
- to: Math.min(i.to + 1, n.doc.length)
138
- }],
139
- scrollIntoView: !0
140
- });
141
- } else {
142
- let e = n.doc.lineAt(n.selection.main.to).number;
143
- t.dispatch({
144
- changes: [{
145
- from: 0,
146
- insert: "---\n"
147
- }, {
148
- from: n.doc.line(e).to,
149
- insert: "\n---"
150
- }],
151
- selection: u.cursor(4),
152
- scrollIntoView: !0
153
- });
85
+ function se(e, t, n) {
86
+ let r = E(e, t);
87
+ if (r) return {
88
+ text: e.slice(0, r.from) + r.label + e.slice(r.to),
89
+ from: r.from,
90
+ to: r.from + r.label.length
91
+ };
92
+ let i = e.slice(t, n) || "target";
93
+ return {
94
+ text: e.slice(0, t) + `[[${i}]]` + e.slice(n),
95
+ from: t + 2,
96
+ to: t + 2 + i.length
97
+ };
98
+ }
99
+ //#endregion
100
+ //#region src/toolbar/underline-ops.ts
101
+ function ce(e, t) {
102
+ let n = /<u>([\s\S]*?)<\/u>/gi;
103
+ for (let r; r = n.exec(e);) {
104
+ let e = r.index, n = e + r[0].length;
105
+ if (t >= e && t <= n) return {
106
+ from: e,
107
+ to: n,
108
+ inner: r[1] ?? ""
109
+ };
154
110
  }
155
- return t.focus(), !0;
111
+ return null;
156
112
  }
157
- function me(t) {
158
- return e(t.doc) !== null;
113
+ function le(e, t, n) {
114
+ let r = ce(e, t);
115
+ if (r) return {
116
+ text: e.slice(0, r.from) + r.inner + e.slice(r.to),
117
+ from: r.from,
118
+ to: r.from + r.inner.length
119
+ };
120
+ let i = e.slice(t, n) || "text";
121
+ return {
122
+ text: e.slice(0, t) + `<u>${i}</u>` + e.slice(n),
123
+ from: t + 3,
124
+ to: t + 3 + i.length
125
+ };
159
126
  }
160
127
  //#endregion
161
128
  //#region src/toolbar/inline-ops.ts
162
- function T(e) {
129
+ function D(e) {
163
130
  return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
164
131
  }
165
- function he(e, t, n) {
132
+ function ue(e, t, n) {
166
133
  let r = t, i = t;
167
134
  if (n < 0) for (; r > 0 && "*~`$".includes(e[r - 1]);) r--;
168
135
  else for (; i < e.length && "*~`$".includes(e[i]);) i++;
@@ -171,7 +138,7 @@ function he(e, t, n) {
171
138
  from: r
172
139
  };
173
140
  }
174
- function ge(e, t) {
141
+ function de(e, t) {
175
142
  let n = [];
176
143
  for (let r = 0; r < e.length;) {
177
144
  if (e[r] !== t) {
@@ -187,15 +154,15 @@ function ge(e, t) {
187
154
  }
188
155
  return n;
189
156
  }
190
- function _e(e, t, n) {
157
+ function fe(e, t, n) {
191
158
  return e < n || t < n ? !1 : n > 1 || e % 2 == 1 && t % 2 == 1;
192
159
  }
193
- function ve(e, t, n, r) {
160
+ function pe(e, t, n, r) {
194
161
  let i = r.length, a = r[0], o = e.slice(t, n), s = 0;
195
162
  for (; o[s] === a;) s++;
196
163
  let c = 0;
197
164
  for (; o[o.length - 1 - c] === a;) c++;
198
- if (o.length >= 2 * i && o.startsWith(r) && o.endsWith(r) && _e(s, c, i)) return {
165
+ if (o.length >= 2 * i && o.startsWith(r) && o.endsWith(r) && fe(s, c, i)) return {
199
166
  changes: [{
200
167
  from: t,
201
168
  to: t + i,
@@ -208,10 +175,10 @@ function ve(e, t, n, r) {
208
175
  from: t,
209
176
  to: n - 2 * i
210
177
  };
211
- let l = he(e, t, -1), u = he(e, n, 1), d = ge(l.text, a), f = ge(u.text, a).reverse();
178
+ let l = ue(e, t, -1), u = ue(e, n, 1), d = de(l.text, a), f = de(u.text, a).reverse();
212
179
  for (let e = 0; e < Math.min(d.length, f.length); e++) {
213
180
  let r = d[e], a = f[e];
214
- if (!_e(r.len, a.len, i)) continue;
181
+ if (!fe(r.len, a.len, i)) continue;
215
182
  let o = l.from + r.start + r.len, s = n + a.start;
216
183
  return {
217
184
  changes: [{
@@ -241,26 +208,26 @@ function ve(e, t, n, r) {
241
208
  to: n + i
242
209
  };
243
210
  }
244
- function ye(e, t) {
211
+ function me(e, t) {
245
212
  let n = e;
246
213
  for (let e of [...t].sort((e, t) => t.from - e.from)) n = n.slice(0, e.from) + e.insert + n.slice(e.to);
247
214
  return n;
248
215
  }
249
- function E(e, t, n, r) {
250
- let i = ve(e, t, n, r);
216
+ function O(e, t, n, r) {
217
+ let i = pe(e, t, n, r);
251
218
  return {
252
- text: ye(e, i.changes),
219
+ text: me(e, i.changes),
253
220
  from: i.from,
254
221
  to: i.to
255
222
  };
256
223
  }
257
- function be(e, t) {
258
- let n = D(e, t);
224
+ function he(e, t) {
225
+ let n = T(e, t);
259
226
  if (n) return {
260
227
  from: n.from,
261
228
  to: n.to
262
229
  };
263
- let r = k(e, t);
230
+ let r = oe(e, t);
264
231
  if (r) return {
265
232
  from: r.from,
266
233
  to: r.to
@@ -272,7 +239,7 @@ function be(e, t) {
272
239
  "*",
273
240
  "`"
274
241
  ]) {
275
- let r = RegExp(T(n) + "(?!\\s)(?:[^]*?\\S)??" + T(n), "g");
242
+ let r = RegExp(D(n) + "(?!\\s)(?:[^]*?\\S)??" + D(n), "g");
276
243
  for (let a; a = r.exec(e);) {
277
244
  if (a[0].length <= 2 * n.length) continue;
278
245
  let e = a.index + n.length, r = a.index + a[0].length - n.length;
@@ -284,121 +251,10 @@ function be(e, t) {
284
251
  }
285
252
  return i;
286
253
  }
287
- function D(e, t) {
288
- let n = /\[([^\]]*)\]\([^)]*\)/g;
289
- for (let r; r = n.exec(e);) {
290
- let e = r.index, n = e + r[0].length;
291
- if (t >= e && t <= n) return {
292
- from: e,
293
- to: n,
294
- label: r[1] ?? ""
295
- };
296
- }
297
- return null;
298
- }
299
- function xe(e, t) {
300
- let n = /\[([^\]]*)\]\(([^)]*)\)/g;
301
- for (let r; r = n.exec(e);) {
302
- let e = r.index, n = e + r[0].length;
303
- if (t >= e && t <= n) {
304
- let t = r[1] ?? "", i = r[2] ?? "", a = e + 1 + t.length + 2;
305
- return {
306
- from: e,
307
- to: n,
308
- label: t,
309
- url: i,
310
- urlFrom: a,
311
- urlTo: a + i.length
312
- };
313
- }
314
- }
315
- return null;
316
- }
317
- function Se(e, t, n) {
318
- let r = D(e, t);
319
- if (r) return {
320
- text: e.slice(0, r.from) + r.label + e.slice(r.to),
321
- from: r.from,
322
- to: r.from + r.label.length
323
- };
324
- let i = e.slice(t, n) || "text", a = t + i.length + 3;
325
- return {
326
- text: e.slice(0, t) + `[${i}](url)` + e.slice(n),
327
- from: a,
328
- to: a + 3
329
- };
330
- }
331
- function Ce(e, t) {
332
- let n = /<u>([\s\S]*?)<\/u>/gi;
333
- for (let r; r = n.exec(e);) {
334
- let e = r.index, n = e + r[0].length;
335
- if (t >= e && t <= n) return {
336
- from: e,
337
- to: n,
338
- inner: r[1] ?? ""
339
- };
340
- }
341
- return null;
342
- }
343
- function we(e, t, n) {
344
- let r = Ce(e, t);
345
- if (r) return {
346
- text: e.slice(0, r.from) + r.inner + e.slice(r.to),
347
- from: r.from,
348
- to: r.from + r.inner.length
349
- };
350
- let i = e.slice(t, n) || "text";
351
- return {
352
- text: e.slice(0, t) + `<u>${i}</u>` + e.slice(n),
353
- from: t + 3,
354
- to: t + 3 + i.length
355
- };
356
- }
357
- function O(e, n) {
358
- for (let r of e.matchAll(t)) {
359
- let e = r.index ?? 0, t = e + r[0].length;
360
- if (n >= e && n <= t) return {
361
- from: e,
362
- to: t,
363
- label: r[2] || r[1] || ""
364
- };
365
- }
366
- return null;
367
- }
368
- function k(e, n) {
369
- for (let r of e.matchAll(t)) {
370
- let e = r.index ?? 0, t = e + r[0].length;
371
- if (n < e || n > t) continue;
372
- let i = r[1] ?? "", a = e + 2;
373
- return {
374
- from: e,
375
- to: t,
376
- target: i,
377
- label: r[2] ?? "",
378
- targetFrom: a,
379
- targetTo: a + i.length
380
- };
381
- }
382
- return null;
383
- }
384
- function Te(e, t, n) {
385
- let r = O(e, t);
386
- if (r) return {
387
- text: e.slice(0, r.from) + r.label + e.slice(r.to),
388
- from: r.from,
389
- to: r.from + r.label.length
390
- };
391
- let i = e.slice(t, n) || "target";
392
- return {
393
- text: e.slice(0, t) + `[[${i}]]` + e.slice(n),
394
- from: t + 2,
395
- to: t + 2 + i.length
396
- };
397
- }
398
254
  //#endregion
399
255
  //#region src/inplace/table-cell-dom.ts
400
- var Ee = (e) => [e.head, ...e.body].map((e) => [...e]), De = (e) => e.map((e) => e.map((e) => e.trim())), Oe = (e) => e.replace(/\\\|/g, "|");
401
- function A(e, t) {
256
+ var ge = (e) => [e.head, ...e.body].map((e) => [...e]), _e = (e) => e.map((e) => e.map((e) => e.trim())), ve = (e) => e.replace(/\\\|/g, "|");
257
+ function k(e, t) {
402
258
  let n = e.ownerDocument.createTreeWalker(e, NodeFilter.SHOW_TEXT), r = 0;
403
259
  for (let e = n.nextNode(); e; e = n.nextNode()) {
404
260
  if (e === t) return r;
@@ -406,12 +262,12 @@ function A(e, t) {
406
262
  }
407
263
  return r;
408
264
  }
409
- function ke(e) {
265
+ function ye(e) {
410
266
  let t = e.ownerDocument.getSelection(), n = t?.anchorNode;
411
- return !n || !e.contains(n) ? 0 : n.nodeType === Node.TEXT_NODE ? A(e, n) + (t?.anchorOffset ?? 0) : (t?.anchorOffset ?? 0) > 0 ? (e.textContent ?? "").length : 0;
267
+ return !n || !e.contains(n) ? 0 : n.nodeType === Node.TEXT_NODE ? k(e, n) + (t?.anchorOffset ?? 0) : (t?.anchorOffset ?? 0) > 0 ? (e.textContent ?? "").length : 0;
412
268
  }
413
- function Ae(e) {
414
- let t = e.ownerDocument.getSelection(), n = (e.textContent ?? "").length, r = (t, r) => !t || !e.contains(t) ? n : t.nodeType === Node.TEXT_NODE ? A(e, t) + r : r > 0 ? n : 0;
269
+ function be(e) {
270
+ let t = e.ownerDocument.getSelection(), n = (e.textContent ?? "").length, r = (t, r) => !t || !e.contains(t) ? n : t.nodeType === Node.TEXT_NODE ? k(e, t) + r : r > 0 ? n : 0;
415
271
  if (!t || t.rangeCount === 0) return {
416
272
  from: n,
417
273
  to: n
@@ -422,7 +278,7 @@ function Ae(e) {
422
278
  to: Math.max(i, a)
423
279
  };
424
280
  }
425
- function je(e, t, n) {
281
+ function xe(e, t, n) {
426
282
  let r = e.ownerDocument, i = null, a = 0;
427
283
  if (r.caretPositionFromPoint) {
428
284
  let e = r.caretPositionFromPoint(t, n);
@@ -431,18 +287,18 @@ function je(e, t, n) {
431
287
  let e = r.caretRangeFromPoint(t, n);
432
288
  e && ([i, a] = [e.startContainer, e.startOffset]);
433
289
  }
434
- return !i || !e.contains(i) ? 0 : A(e, i) + (i.nodeType === Node.TEXT_NODE ? a : 0);
290
+ return !i || !e.contains(i) ? 0 : k(e, i) + (i.nodeType === Node.TEXT_NODE ? a : 0);
435
291
  }
436
- var Me = /[\p{L}\p{N}_]/u;
437
- function Ne(e, t, n) {
438
- let r = e.textContent ?? "", i = je(e, t, n), a = be(r, i);
439
- if (a) return j(e, a.from, a.to), !0;
292
+ var Se = /[\p{L}\p{N}_]/u;
293
+ function Ce(e, t, n) {
294
+ let r = e.textContent ?? "", i = xe(e, t, n), a = he(r, i);
295
+ if (a) return A(e, a.from, a.to), !0;
440
296
  let o = i, s = i;
441
- for (; o > 0 && Me.test(r[o - 1]);) o--;
442
- for (; s < r.length && Me.test(r[s]);) s++;
443
- return s <= o ? !1 : (j(e, o, s), !0);
297
+ for (; o > 0 && Se.test(r[o - 1]);) o--;
298
+ for (; s < r.length && Se.test(r[s]);) s++;
299
+ return s <= o ? !1 : (A(e, o, s), !0);
444
300
  }
445
- function j(e, t, n = t) {
301
+ function A(e, t, n = t) {
446
302
  e.focus();
447
303
  let r = e.ownerDocument, i = r.createRange(), a = e.firstChild;
448
304
  if (a && a.nodeType === Node.TEXT_NODE) {
@@ -455,34 +311,81 @@ function j(e, t, n = t) {
455
311
  }
456
312
  //#endregion
457
313
  //#region src/toolbar/cell-inline.ts
458
- function Pe(e) {
314
+ function we(e) {
459
315
  let t = e.dom.ownerDocument.activeElement;
460
316
  return !(t instanceof HTMLElement) || !e.dom.contains(t) ? null : t.matches(".cm-inplace-tcell") ? t : null;
461
317
  }
462
- function Fe(e, t) {
463
- let { from: n, to: r } = Ae(e), i = t(e.textContent ?? "", n, r);
464
- e.textContent = i.text, j(e, i.from, i.to), e.dispatchEvent(new Event("input", { bubbles: !0 }));
465
- }
466
- function M(e, t) {
467
- let n = Pe(e);
468
- return n ? (Fe(n, t), !0) : !1;
469
- }
470
- var Ie = {
471
- b: (e, t, n) => E(e, t, n, "**"),
472
- i: (e, t, n) => E(e, t, n, "*"),
473
- u: we,
474
- k: Se,
475
- K: Te
318
+ function Te(e, t) {
319
+ let { from: n, to: r } = be(e), i = t(e.textContent ?? "", n, r);
320
+ e.textContent = i.text, A(e, i.from, i.to), e.dispatchEvent(new Event("input", { bubbles: !0 }));
321
+ }
322
+ function j(e, t) {
323
+ let n = we(e);
324
+ return n ? (Te(n, t), !0) : !1;
325
+ }
326
+ var Ee = {
327
+ b: (e, t, n) => O(e, t, n, "**"),
328
+ i: (e, t, n) => O(e, t, n, "*"),
329
+ u: le,
330
+ k: ae,
331
+ K: se
476
332
  };
477
- function Le(e, t) {
333
+ function De(e, t) {
478
334
  if (!(e.metaKey || e.ctrlKey) || e.altKey) return !1;
479
- let n = Ie[e.shiftKey ? e.key.toUpperCase() : e.key.toLowerCase()];
480
- return n ? (e.preventDefault(), Fe(t, n), !0) : !1;
335
+ let n = Ee[e.shiftKey ? e.key.toUpperCase() : e.key.toLowerCase()];
336
+ return n ? (e.preventDefault(), Te(t, n), !0) : !1;
337
+ }
338
+ //#endregion
339
+ //#region src/toolbar/block.ts
340
+ function M(e) {
341
+ let { from: t, to: n } = e.selection.main;
342
+ return [e.doc.lineAt(t).number, e.doc.lineAt(n).number];
343
+ }
344
+ function Oe(e, t) {
345
+ let n = e.state, [r, i] = M(n), a = r === i && !n.doc.line(r).text.trim(), o = !a;
346
+ for (let e = r; e <= i && o; e++) {
347
+ let r = n.doc.line(e).text;
348
+ r.trim() && !t.match.test(r) && (o = !1);
349
+ }
350
+ let s = [], c = 0;
351
+ for (let e = r; e <= i; e++) {
352
+ let r = n.doc.line(e);
353
+ if (!r.text.trim() && !a) continue;
354
+ let i = t.match.exec(r.text);
355
+ if (o) {
356
+ i && s.push({
357
+ from: r.from,
358
+ to: r.from + i[0].length
359
+ });
360
+ continue;
361
+ }
362
+ if (i) continue;
363
+ let l = typeof t.insert == "function" ? t.insert(c++) : t.insert, u = t.siblings?.exec(r.text);
364
+ if (u) s.push({
365
+ from: r.from + (u[1] ?? "").length,
366
+ to: r.from + u[0].length,
367
+ insert: l
368
+ });
369
+ else {
370
+ let e = /^\s*/.exec(r.text)[0].length;
371
+ s.push({
372
+ from: r.from + e,
373
+ insert: l
374
+ });
375
+ }
376
+ }
377
+ return s.length ? (e.dispatch({
378
+ changes: s,
379
+ scrollIntoView: !0
380
+ }), e.focus(), !0) : !1;
381
+ }
382
+ function ke(e, t) {
383
+ return t.test(e.doc.lineAt(e.selection.main.head).text);
481
384
  }
482
385
  //#endregion
483
386
  //#region src/toolbar/fence.ts
484
387
  function N(e, t) {
485
- for (let n = ie(e).resolveInner(t, 0); n; n = n.parent) {
388
+ for (let n = C(e).resolveInner(t, 0); n; n = n.parent) {
486
389
  if (n.name === "FencedCode") return {
487
390
  from: n.from,
488
391
  to: n.to
@@ -491,7 +394,7 @@ function N(e, t) {
491
394
  }
492
395
  return null;
493
396
  }
494
- function Re(e) {
397
+ function Ae(e) {
495
398
  let t = e.state, n = N(t, t.selection.main.head);
496
399
  if (n) {
497
400
  let r = t.doc.lineAt(n.from), i = t.doc.lineAt(n.to), a = [{
@@ -506,7 +409,7 @@ function Re(e) {
506
409
  scrollIntoView: !0
507
410
  });
508
411
  } else {
509
- let [n, r] = w(t);
412
+ let [n, r] = M(t);
510
413
  e.dispatch({
511
414
  changes: [{
512
415
  from: t.doc.line(n).from,
@@ -524,7 +427,7 @@ function Re(e) {
524
427
  function P(e) {
525
428
  return N(e, e.selection.main.head) !== null;
526
429
  }
527
- function ze(e) {
430
+ function je(e) {
528
431
  let t = N(e, e.selection.main.head);
529
432
  if (!t) return null;
530
433
  let n = e.doc.lineAt(t.from), r = /^(\s*(?:`{3,}|~{3,})[ \t]*)(.*?)[ \t]*$/.exec(n.text);
@@ -536,18 +439,18 @@ function ze(e) {
536
439
  lang: r[2]
537
440
  };
538
441
  }
539
- var Be = /^\s*\$\$\s*$/;
540
- function F(e, t) {
442
+ var Me = /^\s*\$\$\s*$/;
443
+ function Ne(e, t) {
541
444
  let n = 0, r = 0;
542
- for (let i = 1; i <= e.doc.lines; i++) if (Be.test(e.doc.line(i).text)) {
445
+ for (let i = 1; i <= e.doc.lines; i++) if (Me.test(e.doc.line(i).text)) {
543
446
  if (r++, r % 2 == 1) {
544
447
  if (n = i, i > t) return null;
545
448
  } else if (i >= t) return [n, i];
546
449
  }
547
450
  return null;
548
451
  }
549
- function Ve(e) {
550
- let t = e.state, [n, r] = w(t), i = F(t, t.doc.lineAt(t.selection.main.head).number);
452
+ function Pe(e) {
453
+ let t = e.state, [n, r] = M(t), i = Ne(t, t.doc.lineAt(t.selection.main.head).number);
551
454
  if (i) {
552
455
  let n = t.doc.line(i[0]), r = t.doc.line(i[1]);
553
456
  e.dispatch({
@@ -573,16 +476,53 @@ function Ve(e) {
573
476
  });
574
477
  return e.focus(), !0;
575
478
  }
576
- function I(e) {
577
- return F(e, e.doc.lineAt(e.selection.main.head).number) !== null;
479
+ function F(e) {
480
+ return Ne(e, e.doc.lineAt(e.selection.main.head).number) !== null;
481
+ }
482
+ //#endregion
483
+ //#region src/toolbar/heading.ts
484
+ function Fe(e, t) {
485
+ let n = "#".repeat(t) + " ", r = e.state, [i, a] = M(r), o = [];
486
+ for (let e = i; e <= a; e++) {
487
+ let i = r.doc.line(e), a = /^(#{1,6}) +/.exec(i.text);
488
+ a && a[1].length === t ? o.push({
489
+ from: i.from,
490
+ to: i.from + a[0].length
491
+ }) : a ? o.push({
492
+ from: i.from,
493
+ to: i.from + a[0].length,
494
+ insert: n
495
+ }) : o.push({
496
+ from: i.from,
497
+ insert: n
498
+ });
499
+ }
500
+ return e.dispatch({
501
+ changes: o,
502
+ scrollIntoView: !0
503
+ }), e.focus(), !0;
504
+ }
505
+ function Ie(e) {
506
+ let t = e.state, [n, r] = M(t), i = [];
507
+ for (let e = n; e <= r; e++) {
508
+ let n = t.doc.line(e), r = /^#{1,6} +/.exec(n.text);
509
+ r && i.push({
510
+ from: n.from,
511
+ to: n.from + r[0].length
512
+ });
513
+ }
514
+ return i.length ? (e.dispatch({
515
+ changes: i,
516
+ scrollIntoView: !0
517
+ }), e.focus(), !0) : !1;
578
518
  }
579
519
  //#endregion
580
520
  //#region src/toolbar/inline.ts
581
- function L(e, t) {
521
+ function I(e, t) {
582
522
  let n = e.state.doc.toString();
583
523
  return e.dispatch({
584
524
  ...e.state.changeByRange((e) => {
585
- let r = ve(n, e.from, e.to, t);
525
+ let r = pe(n, e.from, e.to, t);
586
526
  return {
587
527
  changes: r.changes,
588
528
  range: r.from === r.to ? u.cursor(r.from) : u.range(r.from, r.to)
@@ -591,8 +531,8 @@ function L(e, t) {
591
531
  scrollIntoView: !0
592
532
  }), e.focus(), !0;
593
533
  }
594
- function R(e, t) {
595
- let n = e.selection.main, r = e.doc.lineAt(n.head), i = RegExp(T(t) + "(?!\\s)(?:[^]*?\\S)??" + T(t), "g");
534
+ function L(e, t) {
535
+ let n = e.selection.main, r = e.doc.lineAt(n.head), i = RegExp(D(t) + "(?!\\s)(?:[^]*?\\S)??" + D(t), "g");
596
536
  for (let e; e = i.exec(r.text);) {
597
537
  if (e[0].length <= 2 * t.length || t === "$" && (r.text[e.index - 1] === "$" || r.text[e.index + e[0].length] === "$")) continue;
598
538
  let i = r.from + e.index;
@@ -600,16 +540,16 @@ function R(e, t) {
600
540
  }
601
541
  return !1;
602
542
  }
603
- function He(e) {
604
- let { head: t } = e.selection.main, n = e.doc.lineAt(t), r = D(n.text, t - n.from);
543
+ function Le(e) {
544
+ let { head: t } = e.selection.main, n = e.doc.lineAt(t), r = T(n.text, t - n.from);
605
545
  return r ? {
606
546
  from: n.from + r.from,
607
547
  to: n.from + r.to,
608
548
  text: r.label
609
549
  } : null;
610
550
  }
611
- function Ue(e) {
612
- let t = He(e.state);
551
+ function Re(e) {
552
+ let t = Le(e.state);
613
553
  if (t) return e.dispatch({
614
554
  changes: {
615
555
  from: t.from,
@@ -630,19 +570,19 @@ function Ue(e) {
630
570
  scrollIntoView: !0
631
571
  }), e.focus(), !0;
632
572
  }
633
- function We(e) {
634
- return He(e) !== null;
573
+ function ze(e) {
574
+ return Le(e) !== null;
635
575
  }
636
- function Ge(e) {
637
- let { head: t } = e.selection.main, n = e.doc.lineAt(t), r = O(n.text, t - n.from);
576
+ function Be(e) {
577
+ let { head: t } = e.selection.main, n = e.doc.lineAt(t), r = E(n.text, t - n.from);
638
578
  return r ? {
639
579
  from: n.from + r.from,
640
580
  to: n.from + r.to,
641
581
  text: r.label
642
582
  } : null;
643
583
  }
644
- function Ke(e) {
645
- let t = Ge(e.state);
584
+ function Ve(e) {
585
+ let t = Be(e.state);
646
586
  if (t) return e.dispatch({
647
587
  changes: {
648
588
  from: t.from,
@@ -663,19 +603,19 @@ function Ke(e) {
663
603
  scrollIntoView: !0
664
604
  }), e.focus(), !0;
665
605
  }
666
- function qe(e) {
667
- return Ge(e) !== null;
606
+ function He(e) {
607
+ return Be(e) !== null;
668
608
  }
669
- function Je(e) {
670
- let { head: t } = e.selection.main, n = e.doc.lineAt(t), r = Ce(n.text, t - n.from);
609
+ function Ue(e) {
610
+ let { head: t } = e.selection.main, n = e.doc.lineAt(t), r = ce(n.text, t - n.from);
671
611
  return r ? {
672
612
  from: n.from + r.from,
673
613
  to: n.from + r.to,
674
614
  inner: r.inner
675
615
  } : null;
676
616
  }
677
- function Ye(e) {
678
- let t = Je(e.state);
617
+ function We(e) {
618
+ let t = Ue(e.state);
679
619
  if (t) return e.dispatch({
680
620
  changes: {
681
621
  from: t.from,
@@ -696,29 +636,29 @@ function Ye(e) {
696
636
  scrollIntoView: !0
697
637
  }), e.focus(), !0;
698
638
  }
699
- function Xe(e) {
700
- return Je(e) !== null;
639
+ function Ge(e) {
640
+ return Ue(e) !== null;
701
641
  }
702
642
  //#endregion
703
643
  //#region src/toolbar/table-grid.ts
704
- function Ze(e) {
644
+ function Ke(e) {
705
645
  let t = e.trim();
706
646
  return t.includes("-") && t.includes("|") && /^[\s|:-]+$/.test(t);
707
647
  }
708
- function Qe(e) {
648
+ function qe(e) {
709
649
  let t = e.trim();
710
650
  t.startsWith("|") && (t = t.slice(1)), t.endsWith("|") && !t.endsWith("\\|") && (t = t.slice(0, -1));
711
651
  let n = [], r = "";
712
652
  for (let e = 0; e < t.length; e++) t[e] === "\\" && t[e + 1] === "|" ? (r += "\\|", e++) : t[e] === "|" ? (n.push(r.trim()), r = "") : r += t[e];
713
653
  return n.push(r.trim()), n;
714
654
  }
715
- function $e(e) {
655
+ function Je(e) {
716
656
  let t = e.trim(), n = t.startsWith(":"), r = t.endsWith(":");
717
657
  return n && r ? "center" : r ? "right" : n ? "left" : "";
718
658
  }
719
- function z(e) {
720
- if (e.length < 2 || !Ze(e[1])) return null;
721
- let t = Qe(e[1]).map($e), n = e.filter((e, t) => t !== 1).map(Qe), r = Math.max(t.length, ...n.map((e) => e.length)), i = n.map((e) => {
659
+ function R(e) {
660
+ if (e.length < 2 || !Ke(e[1])) return null;
661
+ let t = qe(e[1]).map(Je), n = e.filter((e, t) => t !== 1).map(qe), r = Math.max(t.length, ...n.map((e) => e.length)), i = n.map((e) => {
722
662
  let t = e.slice(0, r);
723
663
  for (; t.length < r;) t.push("");
724
664
  return t;
@@ -729,11 +669,11 @@ function z(e) {
729
669
  aligns: a
730
670
  };
731
671
  }
732
- function et(e) {
672
+ function Ye(e) {
733
673
  return e.replace(/\\\|/g, "|").length;
734
674
  }
735
- function tt(e, t, n) {
736
- let r = t - et(e);
675
+ function Xe(e, t, n) {
676
+ let r = t - Ye(e);
737
677
  if (r <= 0) return e;
738
678
  if (n === "right") return " ".repeat(r) + e;
739
679
  if (n === "center") {
@@ -742,23 +682,23 @@ function tt(e, t, n) {
742
682
  }
743
683
  return e + " ".repeat(r);
744
684
  }
745
- function nt(e, t) {
685
+ function Ze(e, t) {
746
686
  let n = Math.max(3, e);
747
687
  return t === "left" ? ":" + "-".repeat(n - 1) : t === "right" ? "-".repeat(n - 1) + ":" : t === "center" ? ":" + "-".repeat(n - 2) + ":" : "-".repeat(n);
748
688
  }
749
- function B(e) {
689
+ function z(e) {
750
690
  let t = e.aligns.length, n = [];
751
691
  for (let r = 0; r < t; r++) {
752
692
  let t = 3;
753
- for (let n of e.rows) t = Math.max(t, et(n[r] ?? ""));
693
+ for (let n of e.rows) t = Math.max(t, Ye(n[r] ?? ""));
754
694
  n.push(t);
755
695
  }
756
- let r = (t) => "| " + t.map((t, r) => tt(t ?? "", n[r], e.aligns[r])).join(" | ") + " |", i = [r(e.rows[0] ?? [])];
757
- i.push("| " + e.aligns.map((e, t) => nt(n[t], e)).join(" | ") + " |");
696
+ let r = (t) => "| " + t.map((t, r) => Xe(t ?? "", n[r], e.aligns[r])).join(" | ") + " |", i = [r(e.rows[0] ?? [])];
697
+ i.push("| " + e.aligns.map((e, t) => Ze(n[t], e)).join(" | ") + " |");
758
698
  for (let t = 1; t < e.rows.length; t++) i.push(r(e.rows[t]));
759
699
  return i.join("\n");
760
700
  }
761
- function rt(e) {
701
+ function Qe(e) {
762
702
  let t = [];
763
703
  for (let n = 0; n < e.length; n++) {
764
704
  if (e[n] === "\\") {
@@ -780,8 +720,8 @@ function rt(e) {
780
720
  return n;
781
721
  }
782
722
  //#endregion
783
- //#region src/toolbar/table.ts
784
- function V(e, t) {
723
+ //#region src/toolbar/table-position.ts
724
+ function B(e, t) {
785
725
  let n = e.lineAt(t);
786
726
  if (!n.text.includes("|")) return null;
787
727
  let r = n.number;
@@ -799,13 +739,13 @@ function V(e, t) {
799
739
  if (i - r < 1) return null;
800
740
  let a = [];
801
741
  for (let t = r; t <= i; t++) a.push(e.line(t).text);
802
- return z(a) ? {
742
+ return R(a) ? {
803
743
  from: e.line(r).from,
804
744
  to: e.line(i).to,
805
745
  lines: a
806
746
  } : null;
807
747
  }
808
- function it(e, t, n) {
748
+ function $e(e, t, n) {
809
749
  let r = t;
810
750
  for (let t = 0; t < e.length; t++) {
811
751
  let i = e[t];
@@ -821,7 +761,7 @@ function it(e, t, n) {
821
761
  onDelimiter: !0
822
762
  };
823
763
  }
824
- let a = rt(i), o = 0;
764
+ let a = Qe(i), o = 0;
825
765
  for (let t = 0; t < a.length && (o = t, !(e <= a[t].end)); t++);
826
766
  let s = a[o], c = s ? Math.max(0, Math.min(e, s.contentEnd) - s.contentStart) : 0;
827
767
  return {
@@ -835,22 +775,24 @@ function it(e, t, n) {
835
775
  }
836
776
  return null;
837
777
  }
838
- function H(e, t, n) {
778
+ function V(e, t, n) {
839
779
  let r = e.split("\n"), i = n.onDelimiter ? 1 : n.row === 0 ? 0 : n.row + 1, a = t;
840
780
  for (let e = 0; e < i; e++) a += r[e].length + 1;
841
- let o = rt(r[i]), s = o[Math.min(n.col, o.length - 1)];
781
+ let o = Qe(r[i]), s = o[Math.min(n.col, o.length - 1)];
842
782
  return s ? a + s.contentStart + Math.min(n.offset, s.contentEnd - s.contentStart) : a;
843
783
  }
844
- function at(e, t, n, r) {
845
- let i = V(e, t);
846
- return i ? H(i.lines.join("\n"), i.from, {
784
+ function et(e, t, n, r) {
785
+ let i = B(e, t);
786
+ return i ? V(i.lines.join("\n"), i.from, {
847
787
  row: n,
848
788
  col: r,
849
789
  offset: 0,
850
790
  onDelimiter: !1
851
791
  }) : null;
852
792
  }
853
- function ot(e, t) {
793
+ //#endregion
794
+ //#region src/toolbar/table.ts
795
+ function tt(e, t) {
854
796
  requestAnimationFrame(() => {
855
797
  let n = e.dom.querySelectorAll(".cm-inplace-table-edit");
856
798
  if (n.length === 0) return;
@@ -870,7 +812,7 @@ function ot(e, t) {
870
812
  s?.removeAllRanges(), s?.addRange(o), a.focus();
871
813
  });
872
814
  }
873
- function st(e) {
815
+ function nt(e) {
874
816
  let { from: t, to: n } = e.state.selection.main, r = e.state.doc.lineAt(t), i = r.text.slice(0, t - r.from).trim() ? "\n\n" : "", a = t + i.length + 2;
875
817
  return e.dispatch({
876
818
  changes: {
@@ -880,30 +822,30 @@ function st(e) {
880
822
  },
881
823
  selection: u.range(a, a + 8),
882
824
  scrollIntoView: !0
883
- }), e.focus(), ot(e, a), !0;
825
+ }), e.focus(), tt(e, a), !0;
884
826
  }
885
- function U(e) {
886
- return V(e.doc, e.selection.main.head) !== null;
827
+ function H(e) {
828
+ return B(e.doc, e.selection.main.head) !== null;
887
829
  }
888
- function W(e, t) {
889
- let n = V(e.state.doc, e.state.selection.main.head);
830
+ function U(e, t) {
831
+ let n = B(e.state.doc, e.state.selection.main.head);
890
832
  if (!n) return !1;
891
- let r = z(n.lines), i = it(n.lines, n.from, e.state.selection.main.head);
833
+ let r = R(n.lines), i = $e(n.lines, n.from, e.state.selection.main.head);
892
834
  if (!r || !i) return !1;
893
835
  let a = t(r, i);
894
836
  if (!a) return !1;
895
- let o = B(r);
837
+ let o = z(r);
896
838
  return e.dispatch({
897
839
  changes: {
898
840
  from: n.from,
899
841
  to: n.to,
900
842
  insert: o
901
843
  },
902
- selection: u.cursor(H(o, n.from, a)),
844
+ selection: u.cursor(V(o, n.from, a)),
903
845
  scrollIntoView: !0
904
846
  }), e.focus(), !0;
905
847
  }
906
- function ct(e, t, n) {
848
+ function rt(e, t, n) {
907
849
  let r = e.aligns.length, { row: i, col: a } = t;
908
850
  return a += n, a >= r ? (i++, a = 0) : a < 0 && (i--, a = r - 1), i < 0 ? null : (i >= e.rows.length && e.rows.push(Array(r).fill("")), {
909
851
  row: i,
@@ -912,7 +854,7 @@ function ct(e, t, n) {
912
854
  onDelimiter: !1
913
855
  });
914
856
  }
915
- function lt(e, t) {
857
+ function it(e, t) {
916
858
  let n = t.row + 1;
917
859
  return n >= e.rows.length && e.rows.push(Array(e.aligns.length).fill("")), {
918
860
  row: n,
@@ -921,58 +863,58 @@ function lt(e, t) {
921
863
  onDelimiter: !1
922
864
  };
923
865
  }
924
- var ut = a.of([
866
+ var at = a.of([
925
867
  {
926
868
  key: "Tab",
927
- run: (e) => W(e, (e, t) => ct(e, t, 1))
869
+ run: (e) => U(e, (e, t) => rt(e, t, 1))
928
870
  },
929
871
  {
930
872
  key: "Shift-Tab",
931
- run: (e) => W(e, (e, t) => ct(e, t, -1))
873
+ run: (e) => U(e, (e, t) => rt(e, t, -1))
932
874
  },
933
875
  {
934
876
  key: "Enter",
935
- run: (e) => W(e, lt)
877
+ run: (e) => U(e, it)
936
878
  }
937
- ]), dt = d.transactionFilter.of((e) => {
879
+ ]), ot = d.transactionFilter.of((e) => {
938
880
  if (!e.docChanged || !e.isUserEvent("input") && !e.isUserEvent("delete")) return e;
939
- let t = e.newSelection.main.head, n = V(e.newDoc, t);
881
+ let t = e.newSelection.main.head, n = B(e.newDoc, t);
940
882
  if (!n) return e;
941
- let r = z(n.lines);
883
+ let r = R(n.lines);
942
884
  if (!r) return e;
943
- let i = B(r);
885
+ let i = z(r);
944
886
  if (i === n.lines.join("\n")) return e;
945
- let a = it(n.lines, n.from, t), o = c.of([{
887
+ let a = $e(n.lines, n.from, t), o = c.of([{
946
888
  from: n.from,
947
889
  to: n.to,
948
890
  insert: i
949
891
  }], e.newDoc.length);
950
892
  return {
951
893
  changes: e.changes.compose(o),
952
- selection: a ? u.cursor(H(i, n.from, a)) : e.newSelection,
894
+ selection: a ? u.cursor(V(i, n.from, a)) : e.newSelection,
953
895
  effects: e.effects,
954
896
  scrollIntoView: e.scrollIntoView
955
897
  };
956
- }), G = (e) => /^\s{0,3}#{1,6}(?:\s|$)/.test(e.doc.lineAt(e.selection.main.head).text), K = (t) => {
957
- let n = e(t.doc);
958
- return n !== null && t.selection.main.head <= n.to;
959
- }, q = (e) => K(e) || P(e) || I(e), ft = (e) => (t) => e !== "`" && R(t, "`") || e !== "$" && R(t, "$"), pt = (e) => e.selection.main.empty && !e.wordAt(e.selection.main.head), J = (...e) => (t) => e.some((e) => e(t)), Y = /^(\s*)(?:[-*+] \[[ xX]\] +|\d+\. +|[-*+] +)/, mt = {
898
+ }), W = (e) => /^\s{0,3}#{1,6}(?:\s|$)/.test(e.doc.lineAt(e.selection.main.head).text), G = (e) => {
899
+ let n = t(e.doc);
900
+ return n !== null && e.selection.main.head <= n.to;
901
+ }, K = (e) => G(e) || P(e) || F(e), st = (e) => (t) => e !== "`" && L(t, "`") || e !== "$" && L(t, "$"), ct = (e) => e.selection.main.empty && !e.wordAt(e.selection.main.head), q = (...e) => (t) => e.some((e) => e(t)), J = /^(\s*)(?:[-*+] \[[ xX]\] +|\d+\. +|[-*+] +)/, lt = {
960
902
  match: /^ {0,3}> ?/,
961
903
  insert: "> "
962
- }, ht = {
904
+ }, ut = {
963
905
  match: /^(\s*)[-*+] +(?!\[[ xX]\])/,
964
906
  insert: "- ",
965
- siblings: Y
966
- }, gt = {
907
+ siblings: J
908
+ }, dt = {
967
909
  match: /^(\s*)\d+\. +/,
968
910
  insert: (e) => `${e + 1}. `,
969
- siblings: Y
970
- }, _t = {
911
+ siblings: J
912
+ }, ft = {
971
913
  match: /^(\s*)[-*+] \[[ xX]\] +/,
972
914
  insert: "- [ ] ",
973
- siblings: Y
915
+ siblings: J
974
916
  };
975
- function vt(e, t, n) {
917
+ function pt(e, t, n) {
976
918
  return {
977
919
  id: e,
978
920
  title: t,
@@ -982,228 +924,303 @@ function vt(e, t, n) {
982
924
  }
983
925
  };
984
926
  }
985
- function X(e, t, n, r) {
927
+ function Y(e, t, n, r) {
986
928
  return {
987
929
  id: e,
988
930
  title: t,
989
- run: (e) => M(e, (e, t, r) => E(e, t, r, n)) || L(e, n),
990
- isActive: (e) => R(e, n),
991
- disabled: J(q, ft(n), pt),
931
+ run: (e) => j(e, (e, t, r) => O(e, t, r, n)) || I(e, n),
932
+ isActive: (e) => L(e, n),
933
+ disabled: q(K, st(n), ct),
992
934
  keys: r
993
935
  };
994
936
  }
995
- function Z(e) {
937
+ function X(e) {
996
938
  let t = RegExp(`^#{${e}} `);
997
939
  return {
998
940
  id: `h${e}`,
999
941
  title: `Heading ${e}`,
1000
- run: (t) => oe(t, e),
942
+ run: (t) => Fe(t, e),
1001
943
  isActive: (e) => t.test(e.doc.lineAt(e.selection.main.head).text),
1002
- disabled: J(U, q),
944
+ disabled: q(H, K),
1003
945
  keys: [`Mod-Alt-${e}`]
1004
946
  };
1005
947
  }
1006
- function Q(e, t, n, ...r) {
948
+ function Z(e, t, n, ...r) {
1007
949
  return {
1008
950
  id: e,
1009
951
  title: t,
1010
- run: (e) => ce(e, n),
1011
- isActive: (e) => le(e, n.match),
1012
- disabled: J(U, q, ...r)
952
+ run: (e) => Oe(e, n),
953
+ isActive: (e) => ke(e, n.match),
954
+ disabled: q(H, K, ...r)
1013
955
  };
1014
956
  }
1015
- var yt = [
1016
- vt("undo", "Undo", _),
1017
- vt("redo", "Redo", g),
957
+ //#endregion
958
+ //#region src/toolbar/frontmatter-toggle.ts
959
+ function mt(e) {
960
+ let n = e.state, r = t(n.doc);
961
+ if (r) {
962
+ let t = n.doc.lineAt(r.from), i = n.doc.lineAt(r.to);
963
+ e.dispatch({
964
+ changes: [{
965
+ from: t.from,
966
+ to: Math.min(t.to + 1, n.doc.length)
967
+ }, {
968
+ from: i.from,
969
+ to: Math.min(i.to + 1, n.doc.length)
970
+ }],
971
+ scrollIntoView: !0
972
+ });
973
+ } else {
974
+ let t = n.doc.lineAt(n.selection.main.to).number;
975
+ e.dispatch({
976
+ changes: [{
977
+ from: 0,
978
+ insert: "---\n"
979
+ }, {
980
+ from: n.doc.line(t).to,
981
+ insert: "\n---"
982
+ }],
983
+ selection: u.cursor(4),
984
+ scrollIntoView: !0
985
+ });
986
+ }
987
+ return e.focus(), !0;
988
+ }
989
+ function ht(e) {
990
+ return t(e.doc) !== null;
991
+ }
992
+ //#endregion
993
+ //#region src/toolbar/rule.ts
994
+ var gt = /^ {0,3}([-*_])[ \t]*(?:\1[ \t]*){2,}$/;
995
+ function _t(e) {
996
+ let t = e.state, n = t.doc.lineAt(t.selection.main.head);
997
+ return gt.test(n.text) ? e.dispatch({
998
+ changes: {
999
+ from: n.from,
1000
+ to: Math.min(n.to + 1, t.doc.length)
1001
+ },
1002
+ scrollIntoView: !0
1003
+ }) : n.text.trim() === "" ? e.dispatch({
1004
+ changes: {
1005
+ from: n.from,
1006
+ to: n.to,
1007
+ insert: "---"
1008
+ },
1009
+ selection: u.cursor(n.from + 3),
1010
+ scrollIntoView: !0
1011
+ }) : e.dispatch({
1012
+ changes: {
1013
+ from: n.to,
1014
+ insert: "\n\n---\n"
1015
+ },
1016
+ selection: u.cursor(n.to + 6),
1017
+ scrollIntoView: !0
1018
+ }), e.focus(), !0;
1019
+ }
1020
+ function vt(e) {
1021
+ return gt.test(e.doc.lineAt(e.selection.main.head).text);
1022
+ }
1023
+ //#endregion
1024
+ //#region src/editor/save.ts
1025
+ var Q = f.define({ combine: (e) => e[0] ?? null });
1026
+ function yt(e) {
1027
+ let t = e.state.facet(Q);
1028
+ return t ? (t(e.state.doc.toString()), !0) : !1;
1029
+ }
1030
+ //#endregion
1031
+ //#region src/toolbar/commands.ts
1032
+ var $ = [
1033
+ pt("undo", "Undo", g),
1034
+ pt("redo", "Redo", h),
1018
1035
  {
1019
1036
  id: "save",
1020
1037
  title: "Save",
1021
1038
  run: (e) => {
1022
- let t = ae(e);
1039
+ let t = yt(e);
1023
1040
  return e.focus(), t;
1024
1041
  },
1025
- disabled: (e) => e.facet(C) == null
1042
+ disabled: (e) => e.facet(Q) == null
1026
1043
  },
1027
1044
  {
1028
1045
  id: "search",
1029
1046
  title: "Find / replace",
1030
- run: (e) => b(e),
1047
+ run: (e) => y(e),
1031
1048
  keys: ["Mod-f"]
1032
1049
  },
1033
- Z(1),
1034
- Z(2),
1035
- Z(3),
1050
+ X(1),
1051
+ X(2),
1052
+ X(3),
1036
1053
  {
1037
1054
  id: "body",
1038
1055
  title: "Body",
1039
- run: (e) => (se(e) || e.focus(), !0),
1056
+ run: (e) => (Ie(e) || e.focus(), !0),
1040
1057
  isActive: (e) => !/^#{1,6} /.test(e.doc.lineAt(e.selection.main.head).text),
1041
- disabled: J(U, q)
1058
+ disabled: q(H, K)
1042
1059
  },
1043
- X("bold", "Bold", "**", ["Mod-b"]),
1044
- X("italic", "Italic", "*", ["Mod-i"]),
1045
- X("strike", "Strikethrough", "~~"),
1060
+ Y("bold", "Bold", "**", ["Mod-b"]),
1061
+ Y("italic", "Italic", "*", ["Mod-i"]),
1062
+ Y("strike", "Strikethrough", "~~"),
1046
1063
  {
1047
1064
  id: "underline",
1048
1065
  title: "Underline",
1049
- run: (e) => M(e, we) || Ye(e),
1050
- isActive: Xe,
1051
- disabled: J(q, ft("u"), pt),
1066
+ run: (e) => j(e, le) || We(e),
1067
+ isActive: Ge,
1068
+ disabled: q(K, st("u"), ct),
1052
1069
  keys: ["Mod-u"]
1053
1070
  },
1054
- X("code", "Inline code", "`"),
1071
+ Y("code", "Inline code", "`"),
1055
1072
  {
1056
1073
  id: "codeBlock",
1057
1074
  title: "Code block",
1058
- run: (e) => M(e, (e, t, n) => E(e, t, n, "`")) || (U(e.state) ? L(e, "`") : Re(e)),
1059
- isActive: (e) => U(e) ? R(e, "`") : P(e),
1060
- disabled: J(K, I, G)
1075
+ run: (e) => j(e, (e, t, n) => O(e, t, n, "`")) || (H(e.state) ? I(e, "`") : Ae(e)),
1076
+ isActive: (e) => H(e) ? L(e, "`") : P(e),
1077
+ disabled: q(G, F, W)
1061
1078
  },
1062
1079
  {
1063
1080
  id: "link",
1064
1081
  title: "Link",
1065
- run: (e) => M(e, Se) || Ue(e),
1066
- isActive: We,
1067
- disabled: q,
1082
+ run: (e) => j(e, ae) || Re(e),
1083
+ isActive: ze,
1084
+ disabled: K,
1068
1085
  keys: ["Mod-k"]
1069
1086
  },
1070
1087
  {
1071
1088
  id: "wikilink",
1072
1089
  title: "Wikilink",
1073
- run: (e) => M(e, Te) || Ke(e),
1074
- isActive: qe,
1075
- disabled: q,
1090
+ run: (e) => j(e, se) || Ve(e),
1091
+ isActive: He,
1092
+ disabled: K,
1076
1093
  keys: ["Mod-Shift-k"]
1077
1094
  },
1078
- Q("quote", "Blockquote", mt),
1079
- Q("bulletList", "Bulleted list", ht, G),
1080
- Q("orderedList", "Numbered list", gt, G),
1081
- Q("task", "Task list", _t, G),
1095
+ Z("quote", "Blockquote", lt),
1096
+ Z("bulletList", "Bulleted list", ut, W),
1097
+ Z("orderedList", "Numbered list", dt, W),
1098
+ Z("task", "Task list", ft, W),
1082
1099
  {
1083
1100
  id: "hr",
1084
1101
  title: "Divider",
1085
- run: de,
1086
- isActive: fe,
1087
- disabled: J(U, q)
1102
+ run: _t,
1103
+ isActive: vt,
1104
+ disabled: q(H, K)
1088
1105
  },
1089
1106
  {
1090
1107
  id: "frontmatter",
1091
1108
  title: "Frontmatter",
1092
- run: pe,
1093
- isActive: me,
1094
- disabled: J(U, P, I, G)
1109
+ run: mt,
1110
+ isActive: ht,
1111
+ disabled: q(H, P, F, W)
1095
1112
  },
1096
1113
  {
1097
1114
  id: "table",
1098
1115
  title: "Table",
1099
- run: st,
1100
- isActive: U,
1101
- disabled: J(U, K, P, I, G)
1116
+ run: nt,
1117
+ isActive: H,
1118
+ disabled: q(H, G, P, F, W)
1102
1119
  },
1103
- X("math", "Inline math", "$"),
1120
+ Y("math", "Inline math", "$"),
1104
1121
  {
1105
1122
  id: "mathBlock",
1106
1123
  title: "Block math",
1107
- run: (e) => M(e, (e, t, n) => E(e, t, n, "$")) || (U(e.state) ? L(e, "$") : Ve(e)),
1108
- isActive: (e) => U(e) ? R(e, "$") : I(e),
1109
- disabled: J(K, P, G)
1124
+ run: (e) => j(e, (e, t, n) => O(e, t, n, "$")) || (H(e.state) ? I(e, "$") : Pe(e)),
1125
+ isActive: (e) => H(e) ? L(e, "$") : F(e),
1126
+ disabled: q(G, P, W)
1110
1127
  }
1111
- ], bt = Object.fromEntries(yt.map((e) => [e.id, e])), xt = p.high(a.of(yt.filter((e) => e.keys && e.keys.length > 0).flatMap((e) => e.keys.map((t) => ({
1128
+ ], bt = Object.fromEntries($.map((e) => [e.id, e])), xt = p.high(a.of($.filter((e) => e.keys && e.keys.length > 0).flatMap((e) => e.keys.map((t) => ({
1112
1129
  key: t,
1113
1130
  preventDefault: !0,
1114
1131
  run: ((t) => !e.disabled?.(t.state) && e.run(t))
1115
- }))))), St = ne.define([
1132
+ }))))), St = x.define([
1116
1133
  {
1117
1134
  tag: [
1118
- S.keyword,
1119
- S.modifier,
1120
- S.controlKeyword,
1121
- S.operatorKeyword,
1122
- S.definitionKeyword,
1123
- S.moduleKeyword
1135
+ w.keyword,
1136
+ w.modifier,
1137
+ w.controlKeyword,
1138
+ w.operatorKeyword,
1139
+ w.definitionKeyword,
1140
+ w.moduleKeyword
1124
1141
  ],
1125
1142
  color: "var(--stylo-syntax-keyword)"
1126
1143
  },
1127
1144
  {
1128
1145
  tag: [
1129
- S.string,
1130
- S.special(S.string),
1131
- S.regexp,
1132
- S.attributeValue
1146
+ w.string,
1147
+ w.special(w.string),
1148
+ w.regexp,
1149
+ w.attributeValue
1133
1150
  ],
1134
1151
  color: "var(--stylo-syntax-string)"
1135
1152
  },
1136
1153
  {
1137
- tag: [S.escape, S.character],
1154
+ tag: [w.escape, w.character],
1138
1155
  color: "var(--stylo-syntax-escape)"
1139
1156
  },
1140
1157
  {
1141
1158
  tag: [
1142
- S.comment,
1143
- S.lineComment,
1144
- S.blockComment,
1145
- S.docComment
1159
+ w.comment,
1160
+ w.lineComment,
1161
+ w.blockComment,
1162
+ w.docComment
1146
1163
  ],
1147
1164
  color: "var(--stylo-syntax-comment)",
1148
1165
  fontStyle: "italic"
1149
1166
  },
1150
1167
  {
1151
1168
  tag: [
1152
- S.number,
1153
- S.integer,
1154
- S.float
1169
+ w.number,
1170
+ w.integer,
1171
+ w.float
1155
1172
  ],
1156
1173
  color: "var(--stylo-syntax-number)"
1157
1174
  },
1158
1175
  {
1159
1176
  tag: [
1160
- S.bool,
1161
- S.null,
1162
- S.atom,
1163
- S.constant(S.name)
1177
+ w.bool,
1178
+ w.null,
1179
+ w.atom,
1180
+ w.constant(w.name)
1164
1181
  ],
1165
1182
  color: "var(--stylo-syntax-constant)"
1166
1183
  },
1167
1184
  {
1168
1185
  tag: [
1169
- S.function(S.variableName),
1170
- S.function(S.propertyName),
1171
- S.macroName
1186
+ w.function(w.variableName),
1187
+ w.function(w.propertyName),
1188
+ w.macroName
1172
1189
  ],
1173
1190
  color: "var(--stylo-syntax-function)"
1174
1191
  },
1175
1192
  {
1176
1193
  tag: [
1177
- S.typeName,
1178
- S.className,
1179
- S.namespace
1194
+ w.typeName,
1195
+ w.className,
1196
+ w.namespace
1180
1197
  ],
1181
1198
  color: "var(--stylo-syntax-type)"
1182
1199
  },
1183
1200
  {
1184
- tag: [S.propertyName, S.attributeName],
1201
+ tag: [w.propertyName, w.attributeName],
1185
1202
  color: "var(--stylo-syntax-property)"
1186
1203
  },
1187
1204
  {
1188
- tag: [S.tagName],
1205
+ tag: [w.tagName],
1189
1206
  color: "var(--stylo-syntax-tag)"
1190
1207
  },
1191
1208
  {
1192
- tag: [S.meta, S.annotation],
1209
+ tag: [w.meta, w.annotation],
1193
1210
  color: "var(--stylo-syntax-comment)"
1194
1211
  },
1195
1212
  {
1196
- tag: [S.invalid],
1213
+ tag: [w.invalid],
1197
1214
  color: "var(--stylo-syntax-invalid)"
1198
1215
  }
1199
- ]), Ct = re(St), wt = i.theme({
1216
+ ]), Ct = S(St), wt = i.theme({
1200
1217
  "&": {
1201
1218
  color: "var(--stylo-text)",
1202
1219
  backgroundColor: "var(--stylo-bg)",
1203
1220
  fontSize: "var(--stylo-font-size, 0.9375rem)"
1204
1221
  },
1205
1222
  ".cm-content": {
1206
- fontFamily: "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
1223
+ fontFamily: "var(--stylo-font-family-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace)",
1207
1224
  padding: "0.75rem 0",
1208
1225
  caretColor: "var(--stylo-text)"
1209
1226
  },
@@ -1262,76 +1279,123 @@ var yt = [
1262
1279
  backgroundColor: "color-mix(in srgb, var(--stylo-ring) 70%, transparent)",
1263
1280
  outline: "1px solid var(--stylo-ring)"
1264
1281
  }
1265
- });
1282
+ }), Tt = /\[\[([^[\]\n|]*)$/;
1283
+ function Et(e) {
1284
+ let t = e.label && e.label !== e.target ? e.label : void 0, n = t ? `${e.target}|${t}` : e.target;
1285
+ return {
1286
+ label: e.label ?? e.target,
1287
+ apply: (e, t, r, i) => {
1288
+ let a = e.state.sliceDoc(i, i + 2) === "]]";
1289
+ e.dispatch({
1290
+ changes: {
1291
+ from: r,
1292
+ to: i,
1293
+ insert: a ? n : `${n}]]`
1294
+ },
1295
+ selection: { anchor: r + n.length + 2 },
1296
+ userEvent: "input.complete"
1297
+ });
1298
+ }
1299
+ };
1300
+ }
1301
+ function Dt(e, t) {
1302
+ return async (n) => {
1303
+ let r = n.matchBefore(Tt);
1304
+ if (!r || r.from + 2 === n.pos && !n.explicit) return null;
1305
+ let i = r.text.slice(2), a;
1306
+ try {
1307
+ a = (await e(i)).map(Et);
1308
+ } catch (e) {
1309
+ return t?.(e, {
1310
+ source: "wikiLinkSource",
1311
+ input: i
1312
+ }), null;
1313
+ }
1314
+ return a.length ? {
1315
+ from: r.from + 2,
1316
+ to: n.pos,
1317
+ options: a,
1318
+ filter: !1
1319
+ } : null;
1320
+ };
1321
+ }
1322
+ function Ot(e, t) {
1323
+ return e ? [re(), v.data.of({ autocomplete: Dt(e, t) })] : [];
1324
+ }
1266
1325
  //#endregion
1267
1326
  //#region src/editor/extensions.ts
1268
- function Tt(e) {
1327
+ function kt(e, t, n) {
1269
1328
  return [
1270
- m(),
1271
- a.of([...ee, ...h]),
1272
- p.high(ut),
1329
+ te(),
1330
+ a.of([...ee, ...m]),
1331
+ p.high(at),
1273
1332
  xt,
1274
- dt,
1275
- x({ top: !0 }),
1276
- a.of(te),
1277
- v({
1278
- base: y,
1333
+ ot,
1334
+ b({ top: !0 }),
1335
+ a.of(ne),
1336
+ _({
1337
+ base: v,
1279
1338
  codeLanguages: e
1280
1339
  }),
1281
1340
  Ct,
1341
+ Ot(t, n),
1282
1342
  i.lineWrapping,
1283
1343
  wt
1284
1344
  ];
1285
1345
  }
1286
- function Et(e) {
1346
+ function At(e) {
1287
1347
  return [
1288
1348
  d.readOnly.of(e.readOnly),
1289
1349
  i.editable.of(!e.readOnly),
1290
1350
  e.placeholder ? o(e.placeholder) : [],
1291
- e.save ? C.of(e.save) : []
1351
+ e.save ? Q.of(e.save) : []
1292
1352
  ];
1293
1353
  }
1294
1354
  //#endregion
1295
1355
  //#region src/editor/useCodeMirror.ts
1296
- var $ = s.define();
1297
- function Dt({ value: e, onChange: t, readOnly: o = !1, placeholder: s, onSave: c, onViewChange: u, extensions: f, codeLanguages: ee }) {
1298
- let m = r(null), h = r(null), g = r(t);
1299
- g.current = t;
1300
- let _ = r(c);
1301
- _.current = c;
1302
- let v = r((e) => _.current?.(e)).current, y = c != null, b = r(u);
1303
- b.current = u;
1304
- let x = r(new l());
1356
+ var jt = s.define();
1357
+ function Mt({ value: e, onChange: t, readOnly: o = !1, placeholder: s, onSave: c, onViewChange: u, extensions: f, codeLanguages: ee, wikiLinkSource: te, onResolveError: m }) {
1358
+ let h = r(null), g = r(null), _ = r(t);
1359
+ _.current = t;
1360
+ let v = r(c);
1361
+ v.current = c;
1362
+ let y = r((e) => v.current?.(e)).current, b = r(m);
1363
+ b.current = m;
1364
+ let ne = r((e, t) => {
1365
+ b.current?.(e, t);
1366
+ }).current, x = c != null, S = r(u);
1367
+ S.current = u;
1368
+ let C = r(new l());
1305
1369
  return n(() => {
1306
- let t = m.current;
1370
+ let t = h.current;
1307
1371
  if (!t) return;
1308
1372
  let n = new i({
1309
1373
  parent: t,
1310
1374
  state: d.create({
1311
1375
  doc: e,
1312
1376
  extensions: [
1313
- Tt(ee),
1314
- x.current.of(Et({
1377
+ kt(ee, te, ne),
1378
+ C.current.of(At({
1315
1379
  readOnly: o,
1316
1380
  placeholder: s,
1317
- save: y ? v : void 0
1381
+ save: x ? y : void 0
1318
1382
  })),
1319
1383
  p.high(a.of([{
1320
1384
  key: "Mod-s",
1321
- run: ae
1385
+ run: yt
1322
1386
  }])),
1323
1387
  ...f ?? [],
1324
1388
  i.updateListener.of((e) => {
1325
- e.docChanged && (e.transactions.some((e) => !!e.annotation($)) || g.current(e.state.doc.toString()));
1389
+ e.docChanged && (e.transactions.some((e) => !!e.annotation(jt)) || _.current(e.state.doc.toString()));
1326
1390
  })
1327
1391
  ]
1328
1392
  })
1329
1393
  });
1330
- return h.current = n, b.current?.(n), () => {
1331
- b.current?.(null), n.destroy(), h.current = null;
1394
+ return g.current = n, S.current?.(n), () => {
1395
+ S.current?.(null), n.destroy(), g.current = null;
1332
1396
  };
1333
1397
  }, []), n(() => {
1334
- let t = h.current;
1398
+ let t = g.current;
1335
1399
  if (!t) return;
1336
1400
  let n = t.state.doc.toString();
1337
1401
  n !== e && t.dispatch({
@@ -1340,22 +1404,22 @@ function Dt({ value: e, onChange: t, readOnly: o = !1, placeholder: s, onSave: c
1340
1404
  to: n.length,
1341
1405
  insert: e
1342
1406
  },
1343
- annotations: $.of(!0)
1407
+ annotations: jt.of(!0)
1344
1408
  });
1345
1409
  }, [e]), n(() => {
1346
- h.current?.dispatch({ effects: x.current.reconfigure(Et({
1410
+ g.current?.dispatch({ effects: C.current.reconfigure(At({
1347
1411
  readOnly: o,
1348
1412
  placeholder: s,
1349
- save: y ? v : void 0
1413
+ save: x ? y : void 0
1350
1414
  })) });
1351
1415
  }, [
1352
1416
  o,
1353
1417
  s,
1354
- y,
1355
- v
1356
- ]), m;
1418
+ x,
1419
+ y
1420
+ ]), h;
1357
1421
  }
1358
1422
  //#endregion
1359
- export { Oe as _, B as a, k as b, Pe as c, je as d, j as f, De as g, Ae as h, z as i, Le as l, Ne as m, bt as n, ze as o, ke as p, at as r, P as s, Dt as t, Ee as u, xe as v, O as y };
1423
+ export { _e as _, R as a, oe as b, P as c, ge as d, xe as f, be as g, Ce as h, et as i, we as l, ye as m, bt as n, z as o, A as p, _t as r, je as s, Mt as t, De as u, ve as v, ie as x, E as y };
1360
1424
 
1361
- //# sourceMappingURL=useCodeMirror-hLeJQw6e.js.map
1425
+ //# sourceMappingURL=useCodeMirror-DtwupFgc.js.map