@milkdown/preset-commonmark 6.5.4 → 7.0.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/lib/composed/commands.d.ts +3 -0
  2. package/lib/composed/commands.d.ts.map +1 -0
  3. package/lib/composed/index.d.ts +6 -0
  4. package/lib/composed/index.d.ts.map +1 -0
  5. package/lib/composed/inputrules.d.ts +3 -0
  6. package/lib/composed/inputrules.d.ts.map +1 -0
  7. package/lib/composed/keymap.d.ts +3 -0
  8. package/lib/composed/keymap.d.ts.map +1 -0
  9. package/lib/composed/plugins.d.ts +2 -0
  10. package/lib/composed/plugins.d.ts.map +1 -0
  11. package/lib/composed/schema.d.ts +3 -0
  12. package/lib/composed/schema.d.ts.map +1 -0
  13. package/lib/index.d.ts +4 -29
  14. package/lib/index.d.ts.map +1 -1
  15. package/lib/index.es.js +1101 -1386
  16. package/lib/index.es.js.map +1 -1
  17. package/lib/mark/emphasis.d.ts +5 -0
  18. package/lib/mark/emphasis.d.ts.map +1 -0
  19. package/lib/mark/index.d.ts +3 -4
  20. package/lib/mark/index.d.ts.map +1 -1
  21. package/lib/mark/inline-code.d.ts +5 -0
  22. package/lib/mark/inline-code.d.ts.map +1 -0
  23. package/lib/mark/link.d.ts +8 -10
  24. package/lib/mark/link.d.ts.map +1 -1
  25. package/lib/mark/strong.d.ts +4 -2
  26. package/lib/mark/strong.d.ts.map +1 -1
  27. package/lib/node/blockquote.d.ts +6 -2
  28. package/lib/node/blockquote.d.ts.map +1 -1
  29. package/lib/node/bullet-list.d.ts +5 -2
  30. package/lib/node/bullet-list.d.ts.map +1 -1
  31. package/lib/node/code-block.d.ts +10 -0
  32. package/lib/node/code-block.d.ts.map +1 -0
  33. package/lib/node/doc.d.ts +1 -1
  34. package/lib/node/doc.d.ts.map +1 -1
  35. package/lib/node/hardbreak.d.ts +4 -6
  36. package/lib/node/hardbreak.d.ts.map +1 -1
  37. package/lib/node/heading.d.ts +7 -12
  38. package/lib/node/heading.d.ts.map +1 -1
  39. package/lib/node/hr.d.ts +4 -2
  40. package/lib/node/hr.d.ts.map +1 -1
  41. package/lib/node/image.d.ts +10 -11
  42. package/lib/node/image.d.ts.map +1 -1
  43. package/lib/node/index.d.ts +6 -8
  44. package/lib/node/index.d.ts.map +1 -1
  45. package/lib/node/list-item.d.ts +6 -7
  46. package/lib/node/list-item.d.ts.map +1 -1
  47. package/lib/node/ordered-list.d.ts +5 -2
  48. package/lib/node/ordered-list.d.ts.map +1 -1
  49. package/lib/node/paragraph.d.ts +4 -2
  50. package/lib/node/paragraph.d.ts.map +1 -1
  51. package/lib/node/text.d.ts +1 -1
  52. package/lib/node/text.d.ts.map +1 -1
  53. package/lib/plugin/hardbreak-clear-mark-plugin.d.ts +2 -0
  54. package/lib/plugin/hardbreak-clear-mark-plugin.d.ts.map +1 -0
  55. package/lib/plugin/hardbreak-filter-plugin.d.ts +3 -0
  56. package/lib/plugin/hardbreak-filter-plugin.d.ts.map +1 -0
  57. package/lib/plugin/index.d.ts +9 -3
  58. package/lib/plugin/index.d.ts.map +1 -1
  59. package/lib/plugin/{inline-nodes-cursor.d.ts → inline-nodes-cursor-plugin.d.ts} +2 -3
  60. package/lib/plugin/inline-nodes-cursor-plugin.d.ts.map +1 -0
  61. package/lib/plugin/{inline-sync → inline-sync-plugin}/config.d.ts +2 -2
  62. package/lib/plugin/inline-sync-plugin/config.d.ts.map +1 -0
  63. package/lib/plugin/{inline-sync → inline-sync-plugin}/context.d.ts +1 -2
  64. package/lib/plugin/inline-sync-plugin/context.d.ts.map +1 -0
  65. package/lib/plugin/inline-sync-plugin/index.d.ts +3 -0
  66. package/lib/plugin/inline-sync-plugin/index.d.ts.map +1 -0
  67. package/lib/plugin/inline-sync-plugin/inline-sync-plugin.d.ts +2 -0
  68. package/lib/plugin/inline-sync-plugin/inline-sync-plugin.d.ts.map +1 -0
  69. package/lib/plugin/{inline-sync → inline-sync-plugin}/regexp.d.ts +0 -0
  70. package/lib/plugin/inline-sync-plugin/regexp.d.ts.map +1 -0
  71. package/lib/plugin/{inline-sync → inline-sync-plugin}/replacer.d.ts +1 -1
  72. package/lib/plugin/inline-sync-plugin/replacer.d.ts.map +1 -0
  73. package/lib/plugin/{inline-sync → inline-sync-plugin}/utils.d.ts +0 -0
  74. package/lib/plugin/inline-sync-plugin/utils.d.ts.map +1 -0
  75. package/lib/plugin/remark-add-order-in-list-plugin.d.ts +2 -0
  76. package/lib/plugin/remark-add-order-in-list-plugin.d.ts.map +1 -0
  77. package/lib/plugin/remark-inline-link-plugin.d.ts +2 -0
  78. package/lib/plugin/remark-inline-link-plugin.d.ts.map +1 -0
  79. package/lib/plugin/remark-line-break.d.ts +2 -0
  80. package/lib/plugin/remark-line-break.d.ts.map +1 -0
  81. package/lib/plugin/sync-heading-id-plugin.d.ts +2 -0
  82. package/lib/plugin/sync-heading-id-plugin.d.ts.map +1 -0
  83. package/lib/plugin/sync-list-order-plugin.d.ts +2 -0
  84. package/lib/plugin/sync-list-order-plugin.d.ts.map +1 -0
  85. package/package.json +9 -7
  86. package/src/composed/commands.ts +30 -0
  87. package/src/composed/index.ts +6 -0
  88. package/src/composed/inputrules.ts +12 -0
  89. package/src/composed/keymap.ts +19 -0
  90. package/src/composed/plugins.ts +21 -0
  91. package/src/composed/schema.ts +54 -0
  92. package/src/index.ts +5 -52
  93. package/src/mark/emphasis.ts +42 -0
  94. package/src/mark/index.ts +3 -10
  95. package/src/mark/inline-code.ts +64 -0
  96. package/src/mark/link.ts +87 -247
  97. package/src/mark/strong.ts +35 -36
  98. package/src/node/blockquote.ts +32 -33
  99. package/src/node/bullet-list.ts +56 -56
  100. package/src/node/code-block.ts +93 -0
  101. package/src/node/doc.ts +17 -22
  102. package/src/node/hardbreak.ts +60 -117
  103. package/src/node/heading.ts +158 -281
  104. package/src/node/hr.ts +51 -57
  105. package/src/node/image.ts +102 -209
  106. package/src/node/index.ts +6 -35
  107. package/src/node/list-item.ts +81 -142
  108. package/src/node/ordered-list.ts +64 -65
  109. package/src/node/paragraph.ts +48 -50
  110. package/src/node/text.ts +13 -16
  111. package/src/plugin/hardbreak-clear-mark-plugin.ts +44 -0
  112. package/src/plugin/hardbreak-filter-plugin.ts +31 -0
  113. package/src/plugin/index.ts +12 -14
  114. package/src/plugin/{inline-nodes-cursor.ts → inline-nodes-cursor-plugin.ts} +4 -4
  115. package/src/plugin/{inline-sync → inline-sync-plugin}/config.ts +4 -3
  116. package/src/plugin/{inline-sync → inline-sync-plugin}/context.ts +4 -6
  117. package/src/plugin/inline-sync-plugin/index.ts +4 -0
  118. package/src/plugin/{inline-sync/index.ts → inline-sync-plugin/inline-sync-plugin.ts} +9 -11
  119. package/src/plugin/{inline-sync → inline-sync-plugin}/regexp.ts +0 -0
  120. package/src/plugin/{inline-sync → inline-sync-plugin}/replacer.ts +3 -3
  121. package/src/plugin/{inline-sync → inline-sync-plugin}/utils.ts +0 -0
  122. package/src/plugin/remark-add-order-in-list-plugin.ts +15 -0
  123. package/src/plugin/remark-inline-link-plugin.ts +5 -0
  124. package/src/plugin/remark-line-break.ts +41 -0
  125. package/src/plugin/sync-heading-id-plugin.ts +53 -0
  126. package/src/plugin/sync-list-order-plugin.ts +57 -0
  127. package/lib/mark/code-inline.d.ts +0 -3
  128. package/lib/mark/code-inline.d.ts.map +0 -1
  129. package/lib/mark/em.d.ts +0 -3
  130. package/lib/mark/em.d.ts.map +0 -1
  131. package/lib/node/code-fence.d.ts +0 -7
  132. package/lib/node/code-fence.d.ts.map +0 -1
  133. package/lib/plugin/add-order-in-list.d.ts +0 -3
  134. package/lib/plugin/add-order-in-list.d.ts.map +0 -1
  135. package/lib/plugin/filter-html.d.ts +0 -3
  136. package/lib/plugin/filter-html.d.ts.map +0 -1
  137. package/lib/plugin/inline-nodes-cursor.d.ts.map +0 -1
  138. package/lib/plugin/inline-sync/config.d.ts.map +0 -1
  139. package/lib/plugin/inline-sync/context.d.ts.map +0 -1
  140. package/lib/plugin/inline-sync/index.d.ts +0 -6
  141. package/lib/plugin/inline-sync/index.d.ts.map +0 -1
  142. package/lib/plugin/inline-sync/regexp.d.ts.map +0 -1
  143. package/lib/plugin/inline-sync/replacer.d.ts.map +0 -1
  144. package/lib/plugin/inline-sync/utils.d.ts.map +0 -1
  145. package/lib/supported-keys.d.ts +0 -23
  146. package/lib/supported-keys.d.ts.map +0 -1
  147. package/src/mark/code-inline.ts +0 -66
  148. package/src/mark/em.ts +0 -42
  149. package/src/node/code-fence.ts +0 -245
  150. package/src/plugin/add-order-in-list.ts +0 -19
  151. package/src/plugin/filter-html.ts +0 -43
  152. package/src/supported-keys.ts +0 -25
  153. package/src/types.d.ts +0 -5
package/lib/index.es.js CHANGED
@@ -1,1486 +1,1201 @@
1
- import { createMark as q, createShortcut as M, createNode as C, pipe as Se, createPlugin as ve, AtomList as we } from "@milkdown/utils";
2
- import { createCmdKey as I, createCmd as N, commandsCtx as Le, editorViewCtx as v, schemaCtx as R, getPalette as Ae, createSlice as Ee, serializerCtx as _e, parserCtx as $e } from "@milkdown/core";
3
- import { toggleMark as pe, wrapIn as ge, setBlockType as A } from "@milkdown/prose/commands";
4
- import { expectDomTypeError as x, missingRootElement as Pe } from "@milkdown/exception";
5
- import { calculateTextPosition as Be, cloneTr as Re, findSelectedNodeOfType as F, getNodeFromSchema as We } from "@milkdown/prose";
6
- import { PluginKey as H, TextSelection as Q, Plugin as T, NodeSelection as qe, Selection as Ce } from "@milkdown/prose/state";
7
- import { wrappingInputRule as K, textblockTypeInputRule as X, InputRule as xe } from "@milkdown/prose/inputrules";
8
- import { Fragment as W } from "@milkdown/prose/model";
9
- import { ReplaceStep as Ke, AddMarkStep as Fe } from "@milkdown/prose/transform";
10
- import { DecorationSet as S, Decoration as Z } from "@milkdown/prose/view";
11
- import { splitListItem as je, sinkListItem as ze, liftListItem as Ue } from "@milkdown/prose/schema-list";
12
- import Ve from "remark-inline-links";
13
- import { visit as Ge } from "unist-util-visit";
14
- const y = {
15
- HardBreak: "HardBreak",
16
- Blockquote: "Blockquote",
17
- BulletList: "BulletList",
18
- OrderedList: "OrderedList",
19
- CodeFence: "CodeFence",
20
- H1: "H1",
21
- H2: "H2",
22
- H3: "H3",
23
- H4: "H4",
24
- H5: "H5",
25
- H6: "H6",
26
- DowngradeHeading: "DowngradeHeading",
27
- Text: "Text",
28
- CodeInline: "CodeInline",
29
- Em: "Em",
30
- Bold: "Bold",
31
- NextListItem: "NextListItem",
32
- SinkListItem: "SinkListItem",
33
- LiftListItem: "LiftListItem"
34
- }, ke = "code_inline", ee = I("ToggleInlineCode"), Ye = q((a) => ({
35
- id: ke,
36
- schema: () => ({
37
- priority: 100,
38
- code: !0,
39
- inclusive: !1,
40
- parseDOM: [{ tag: "code" }],
41
- toDOM: (e) => ["code", { class: a.getClassName(e.attrs, "code-inline") }],
42
- parseMarkdown: {
43
- match: (e) => e.type === "inlineCode",
44
- runner: (e, t, r) => {
45
- e.openMark(r), e.addText(t.value), e.closeMark(r);
46
- }
47
- },
48
- toMarkdown: {
49
- match: (e) => e.type.name === ke,
50
- runner: (e, t, r) => {
51
- e.withMark(t, "inlineCode", r.text || "");
52
- }
53
- }
54
- }),
55
- commands: (e) => [
56
- N(ee, () => (t, r) => {
57
- const { selection: n, tr: o } = t;
58
- if (n.empty)
59
- return !1;
60
- const { from: l, to: s } = n;
61
- return t.doc.rangeHasMark(l, s, e) ? (r == null || r(o.removeMark(l, s, e)), !0) : (Object.keys(t.schema.marks).filter((u) => u !== e.name).map((u) => t.schema.marks[u]).forEach((u) => {
62
- o.removeMark(l, s, u);
63
- }), r == null || r(o.addMark(l, s, e.create())), !0);
64
- })
1
+ import { $markAttr as H, $markSchema as K, $command as u, $useKeymap as f, $node as X, $nodeAttr as k, $nodeSchema as y, $ctx as P, $inputRule as I, pipe as Be, $prose as w, $remark as W } from "@milkdown/utils";
2
+ import { commandsCtx as m, editorViewCtx as R, serializerCtx as Re, parserCtx as Pe } from "@milkdown/core";
3
+ import { toggleMark as q, setBlockType as S, wrapIn as F } from "@milkdown/prose/commands";
4
+ import { Fragment as Z } from "@milkdown/prose/model";
5
+ import { expectDomTypeError as b } from "@milkdown/exception";
6
+ import { textblockTypeInputRule as ee, wrappingInputRule as V, InputRule as te } from "@milkdown/prose/inputrules";
7
+ import { TextSelection as re, Selection as ne, PluginKey as N, Plugin as C } from "@milkdown/prose/state";
8
+ import { findSelectedNodeOfType as We } from "@milkdown/prose";
9
+ import { sinkListItem as qe, splitListItem as Fe, liftListItem as Ve } from "@milkdown/prose/schema-list";
10
+ import { ReplaceStep as Ge, AddMarkStep as ze } from "@milkdown/prose/transform";
11
+ import { Decoration as J, DecorationSet as Q } from "@milkdown/prose/view";
12
+ import { visit as oe } from "unist-util-visit";
13
+ import je from "remark-inline-links";
14
+ const ae = H("emphasis"), se = K("emphasis", (r) => ({
15
+ inclusive: !1,
16
+ parseDOM: [
17
+ { tag: "i" },
18
+ { tag: "em" },
19
+ { style: "font-style", getAttrs: (e) => e === "italic" }
65
20
  ],
66
- shortcuts: {
67
- [y.CodeInline]: M(ee, "Mod-e")
68
- }
69
- })), j = "em", te = I("ToggleItalic"), Je = q((a) => ({
70
- id: j,
71
- schema: () => ({
72
- inclusive: !1,
73
- parseDOM: [
74
- { tag: "i" },
75
- { tag: "em" },
76
- { style: "font-style", getAttrs: (e) => e === "italic" }
77
- ],
78
- toDOM: (e) => ["em", { class: a.getClassName(e.attrs, j) }],
79
- parseMarkdown: {
80
- match: (e) => e.type === "emphasis",
81
- runner: (e, t, r) => {
82
- e.openMark(r), e.next(t.children), e.closeMark(r);
83
- }
84
- },
85
- toMarkdown: {
86
- match: (e) => e.type.name === j,
87
- runner: (e, t) => {
88
- e.withMark(t, "emphasis");
89
- }
21
+ toDOM: (e) => ["em", r.get(ae.key)(e)],
22
+ parseMarkdown: {
23
+ match: (e) => e.type === "emphasis",
24
+ runner: (e, t, n) => {
25
+ e.openMark(n), e.next(t.children), e.closeMark(n);
26
+ }
27
+ },
28
+ toMarkdown: {
29
+ match: (e) => e.type.name === "emphasis",
30
+ runner: (e, t) => {
31
+ e.withMark(t, "emphasis");
90
32
  }
91
- }),
92
- commands: (e) => [N(te, () => pe(e))],
93
- shortcuts: {
94
- [y.Em]: M(te, "Mod-i")
95
33
  }
96
- })), Qe = new H("MILKDOWN_LINK_INPUT"), Te = I("ToggleLink"), re = I("ModifyLink"), $ = "link", Xe = q((a, e) => ({
97
- id: $,
98
- schema: () => ({
99
- attrs: {
100
- href: {},
101
- title: { default: null }
102
- },
103
- parseDOM: [
104
- {
105
- tag: "a[href]",
106
- getAttrs: (t) => {
107
- if (!(t instanceof HTMLElement))
108
- throw x(t);
109
- return { href: t.getAttribute("href"), title: t.getAttribute("title") };
110
- }
111
- }
112
- ],
113
- toDOM: (t) => ["a", { ...t.attrs, class: a.getClassName(t.attrs, $) }],
114
- parseMarkdown: {
115
- match: (t) => t.type === "link",
116
- runner: (t, r, n) => {
117
- const o = r.url, l = r.title;
118
- t.openMark(n, { href: o, title: l }), t.next(r.children), t.closeMark(n);
119
- }
120
- },
121
- toMarkdown: {
122
- match: (t) => t.type.name === $,
123
- runner: (t, r) => {
124
- t.withMark(r, "link", void 0, {
125
- title: r.attrs.title,
126
- url: r.attrs.href
127
- });
128
- }
34
+ })), le = u("ToggleEmphasis", () => () => q(se.type())), Ue = f("emphasisKeymap", {
35
+ ToggleEmphasis: {
36
+ shortcuts: "Mod-i",
37
+ command: (r) => {
38
+ const e = r.get(m);
39
+ return () => e.call(le.key);
129
40
  }
130
- }),
131
- commands: (t) => [
132
- N(Te, (r = "") => pe(t, { href: r })),
133
- N(re, (r = "") => (n, o) => {
134
- var k;
135
- if (!o)
136
- return !1;
137
- const { marks: l } = n.schema;
138
- let s, c = -1;
139
- const { selection: i } = n, { from: u, to: f } = i;
140
- if (n.doc.nodesBetween(u, u === f ? f + 1 : f, (b, w) => {
141
- var L;
142
- if ((L = l.link) != null && L.isInSet(b.marks))
143
- return s = b, c = w, !1;
144
- }), !s)
145
- return !1;
146
- const d = s.marks.find(({ type: b }) => b === t);
147
- if (!d)
148
- return !1;
149
- const m = c, p = c + s.nodeSize, { tr: g } = n, h = (k = l.link) == null ? void 0 : k.create({ ...d.attrs, href: r });
150
- return h ? (o(
151
- g.removeMark(m, p, d).addMark(m, p, h).setSelection(new Q(g.selection.$anchor)).scrollIntoView()
152
- ), !0) : !1;
153
- })
41
+ }
42
+ }), ce = H("strong"), ie = K("strong", (r) => ({
43
+ inclusive: !1,
44
+ parseDOM: [
45
+ { tag: "b" },
46
+ { tag: "strong" },
47
+ { style: "font-style", getAttrs: (e) => e === "bold" }
154
48
  ],
155
- prosePlugins: (t, r) => {
156
- let n = !1;
157
- return [
158
- new T({
159
- key: Qe,
160
- view: (o) => {
161
- var u, f, d;
162
- const l = a.themeManager.get("input-chip", {
163
- placeholder: (f = (u = e == null ? void 0 : e.input) == null ? void 0 : u.placeholder) != null ? f : "Input Web Link",
164
- buttonText: (d = e == null ? void 0 : e.input) == null ? void 0 : d.buttonText,
165
- onUpdate: (m) => {
166
- r.get(Le).call(re, m);
167
- },
168
- calculatePosition: (m, p) => {
169
- Be(m, p, (g, h, k, b) => {
170
- const w = m.dom.parentElement;
171
- if (!w)
172
- throw Pe();
173
- const L = h.left - g.left;
174
- let D = g.left - b.left - (k.width - L) / 2, _ = g.bottom - b.top + 14 + w.scrollTop;
175
- n && (_ = g.top - b.top - k.height - 14 + w.scrollTop), D < 0 && (D = 0);
176
- const he = w.clientWidth - (k.width + 4);
177
- return D > he && (D = he), [_, D];
178
- });
179
- }
180
- });
181
- if (!l)
182
- return {};
183
- const s = (m) => {
184
- var b;
185
- const { selection: p, doc: g } = m.state, { from: h, to: k } = p;
186
- if (!m.hasFocus())
187
- return !1;
188
- if (p instanceof Q && k < g.content.size && h < g.content.size && g.rangeHasMark(h, h === k ? k + 1 : k, t)) {
189
- let w = p.empty;
190
- if (((b = e == null ? void 0 : e.input) == null ? void 0 : b.displayWhenSelected) && !w && g.nodesBetween(h, h === k ? k + 1 : k, (L, D) => {
191
- if (L.marks.some(
192
- (_) => _.type === t && h >= D && k <= D + L.nodeSize
193
- ))
194
- return w = !0, !1;
195
- }), w)
196
- return n = !1, !0;
197
- }
198
- if (p instanceof qe) {
199
- const { node: w } = p;
200
- if (w.type.name === "image" && w.marks.findIndex((L) => L.type.name === $) > -1)
201
- return n = !0, !0;
202
- }
203
- return !1;
204
- }, c = (m) => {
205
- const { selection: p } = m.state;
206
- let g;
207
- const { from: h, to: k } = p;
208
- if (m.state.doc.nodesBetween(h, h === k ? k + 1 : k, (L) => {
209
- if (t.isInSet(L.marks))
210
- return g = L, !1;
211
- }), !g)
212
- return;
213
- const b = g.marks.find((L) => L.type === t);
214
- return b ? b.attrs.href : void 0;
215
- }, i = (m) => {
216
- if (!m.editable)
217
- return;
218
- s(m) ? (l.show(m), l.update(c(m))) : l.hide();
219
- };
220
- return l.init(o), i(o), {
221
- update: (m, p) => {
222
- (p == null ? void 0 : p.doc.eq(m.state.doc)) && p.selection.eq(m.state.selection) || requestAnimationFrame(() => {
223
- i(m);
224
- });
225
- },
226
- destroy: () => {
227
- l.destroy();
228
- }
229
- };
230
- }
231
- })
232
- ];
49
+ toDOM: (e) => ["strong", r.get(ce.key)(e)],
50
+ parseMarkdown: {
51
+ match: (e) => e.type === "strong",
52
+ runner: (e, t, n) => {
53
+ e.openMark(n), e.next(t.children), e.closeMark(n);
54
+ }
55
+ },
56
+ toMarkdown: {
57
+ match: (e) => e.type.name === "strong",
58
+ runner: (e, t) => {
59
+ e.withMark(t, "strong");
60
+ }
233
61
  }
234
- })), z = "strong", ne = I("ToggleBold"), Ze = q((a) => ({
235
- id: z,
236
- schema: () => ({
237
- inclusive: !1,
238
- parseDOM: [
239
- { tag: "b" },
240
- { tag: "strong" },
241
- { style: "font-style", getAttrs: (e) => e === "bold" }
242
- ],
243
- toDOM: (e) => ["strong", { class: a.getClassName(e.attrs, z) }],
244
- parseMarkdown: {
245
- match: (e) => e.type === "strong",
246
- runner: (e, t, r) => {
247
- e.openMark(r), e.next(t.children), e.closeMark(r);
248
- }
249
- },
250
- toMarkdown: {
251
- match: (e) => e.type.name === z,
252
- runner: (e, t) => {
253
- e.withMark(t, "strong");
254
- }
62
+ })), de = u("ToggleStrong", () => () => q(ie.type())), Ye = f("strongKeymap", {
63
+ ToggleBold: {
64
+ shortcuts: ["Mod-b"],
65
+ command: (r) => {
66
+ const e = r.get(m);
67
+ return () => e.call(de.key);
255
68
  }
256
- }),
257
- commands: (e) => [N(ne, () => pe(e))],
258
- shortcuts: {
259
- [y.Bold]: M(ne, "Mod-b")
260
69
  }
261
- })), et = [Ye(), Je(), Ze(), Xe()], P = "blockquote", se = I("WrapInBlockquote"), tt = C((a) => ({
262
- id: P,
263
- schema: () => ({
264
- content: "block+",
265
- group: "block",
266
- defining: !0,
267
- parseDOM: [{ tag: "blockquote" }],
268
- toDOM: (e) => ["blockquote", { class: a.getClassName(e.attrs, P) }, 0],
269
- parseMarkdown: {
270
- match: ({ type: e }) => e === P,
271
- runner: (e, t, r) => {
272
- e.openNode(r).next(t.children).closeNode();
273
- }
274
- },
275
- toMarkdown: {
276
- match: (e) => e.type.name === P,
277
- runner: (e, t) => {
278
- e.openNode("blockquote").next(t.content).closeNode();
279
- }
70
+ }), ue = H("inlineCode"), A = K("inlineCode", (r) => ({
71
+ priority: 100,
72
+ code: !0,
73
+ inclusive: !1,
74
+ parseDOM: [{ tag: "code" }],
75
+ toDOM: (e) => ["code", r.get(ue.key)(e)],
76
+ parseMarkdown: {
77
+ match: (e) => e.type === "inlineCode",
78
+ runner: (e, t, n) => {
79
+ e.openMark(n), e.addText(t.value), e.closeMark(n);
80
+ }
81
+ },
82
+ toMarkdown: {
83
+ match: (e) => e.type.name === "inlineCode",
84
+ runner: (e, t, n) => {
85
+ e.withMark(t, "inlineCode", n.text || "");
280
86
  }
281
- }),
282
- inputRules: (e) => [K(/^\s*>\s$/, e)],
283
- commands: (e) => [N(se, () => ge(e))],
284
- shortcuts: {
285
- [y.Blockquote]: M(se, "Mod-Shift-b")
286
87
  }
287
- })), oe = I("WrapInBulletList"), rt = C((a) => {
288
- const e = "bullet_list";
289
- return {
290
- id: e,
291
- schema: () => ({
292
- content: "listItem+",
293
- group: "block",
294
- attrs: {
295
- spread: {
296
- default: !1
297
- }
298
- },
299
- parseDOM: [
300
- {
301
- tag: "ul",
302
- getAttrs: (t) => {
303
- if (!(t instanceof HTMLElement))
304
- throw x(t);
305
- return {
306
- spread: t.dataset.spread
307
- };
308
- }
309
- }
310
- ],
311
- toDOM: (t) => [
312
- "ul",
313
- {
314
- "data-spread": t.attrs.spread,
315
- class: a.getClassName(t.attrs, "bullet-list")
316
- },
317
- 0
318
- ],
319
- parseMarkdown: {
320
- match: ({ type: t, ordered: r }) => t === "list" && !r,
321
- runner: (t, r, n) => {
322
- const o = r.spread != null ? `${r.spread}` : "false";
323
- t.openNode(n, { spread: o }).next(r.children).closeNode();
324
- }
325
- },
326
- toMarkdown: {
327
- match: (t) => t.type.name === e,
328
- runner: (t, r) => {
329
- t.openNode("list", void 0, { ordered: !1, spread: r.attrs.spread === "true" }).next(r.content).closeNode();
330
- }
331
- }
332
- }),
333
- inputRules: (t) => [K(/^\s*([-+*])\s$/, t)],
334
- commands: (t) => [N(oe, () => ge(t))],
335
- shortcuts: {
336
- [y.BulletList]: M(oe, "Mod-Alt-8")
88
+ })), pe = u("ToggleInlineCode", () => () => (r, e) => {
89
+ const { selection: t, tr: n } = r;
90
+ if (t.empty)
91
+ return !1;
92
+ const { from: o, to: a } = t;
93
+ return r.doc.rangeHasMark(o, a, A.type()) ? (e == null || e(n.removeMark(o, a, A.type())), !0) : (Object.keys(r.schema.marks).filter((c) => c !== A.type.name).map((c) => r.schema.marks[c]).forEach((c) => {
94
+ n.removeMark(o, a, c);
95
+ }), e == null || e(n.addMark(o, a, A.type().create())), !0);
96
+ }), Je = f("inlineCodeKeymap", {
97
+ ToggleInlineCode: {
98
+ shortcuts: "Mod-e",
99
+ command: (r) => {
100
+ const e = r.get(m);
101
+ return () => e.call(pe.key);
337
102
  }
338
- };
339
- }), nt = [
340
- "",
341
- "javascript",
342
- "typescript",
343
- "bash",
344
- "sql",
345
- "json",
346
- "html",
347
- "css",
348
- "c",
349
- "cpp",
350
- "java",
351
- "ruby",
352
- "python",
353
- "go",
354
- "rust",
355
- "markdown"
356
- ], st = /^```(?<language>[a-z]*)?[\s\n]$/, ot = /^~~~(?<language>[a-z]*)?[\s\n]$/, ae = I("TurnIntoCodeFence"), U = "fence", at = C((a, e) => {
357
- const t = (e == null ? void 0 : e.languageList) || nt;
358
- return {
359
- id: U,
360
- schema: (r) => ({
361
- content: "text*",
362
- group: "block",
363
- marks: "",
364
- defining: !0,
365
- code: !0,
366
- attrs: {
367
- language: {
368
- default: ""
369
- },
370
- fold: {
371
- default: !0
372
- }
373
- },
374
- parseDOM: [
375
- {
376
- tag: "div.code-fence-container",
377
- preserveWhitespace: "full",
378
- getAttrs: (n) => {
379
- var o;
380
- if (!(n instanceof HTMLElement))
381
- throw x(n);
382
- return { language: (o = n.querySelector("pre")) == null ? void 0 : o.dataset.language };
383
- },
384
- getContent: (n, o) => {
385
- var c, i;
386
- if (!(n instanceof HTMLElement))
387
- throw x(n);
388
- const l = (i = (c = n.querySelector("pre")) == null ? void 0 : c.textContent) != null ? i : "";
389
- if (!l)
390
- return W.empty;
391
- const s = o.text(l);
392
- return W.from(s);
393
- }
394
- },
395
- {
396
- tag: "pre",
397
- preserveWhitespace: "full",
398
- getAttrs: (n) => {
399
- if (!(n instanceof HTMLElement))
400
- throw x(n);
401
- return { language: n.dataset.language };
402
- }
403
- }
404
- ],
405
- toDOM: (n) => {
406
- const o = document.createElement("select");
407
- return t.forEach((l) => {
408
- const s = document.createElement("option");
409
- s.value = l, s.innerText = l || "--", l === n.attrs.language && (s.selected = !0), o.appendChild(s);
410
- }), o.onchange = (l) => {
411
- const s = l.target;
412
- if (!(s instanceof HTMLSelectElement))
413
- return;
414
- const c = r.get(v);
415
- if (!c.editable) {
416
- s.value = n.attrs.language;
417
- return;
418
- }
419
- const { top: i, left: u } = s.getBoundingClientRect(), f = c.posAtCoords({ top: i, left: u });
420
- if (!f)
421
- return;
422
- const { tr: d } = c.state;
423
- c.dispatch(
424
- d.setNodeMarkup(f.inside, void 0, {
425
- ...n.attrs,
426
- language: s.value
427
- })
428
- );
429
- }, [
430
- "div",
431
- {
432
- class: "code-fence-container"
433
- },
434
- o,
435
- [
436
- "pre",
437
- {
438
- "data-language": n.attrs.language,
439
- class: a.getClassName(n.attrs, "code-fence")
440
- },
441
- ["code", { spellCheck: "false" }, 0]
442
- ]
443
- ];
444
- },
445
- parseMarkdown: {
446
- match: ({ type: n }) => n === "code",
447
- runner: (n, o, l) => {
448
- const s = o.lang, c = o.value;
449
- n.openNode(l, { language: s }), c && n.addText(c), n.closeNode();
450
- }
451
- },
452
- toMarkdown: {
453
- match: (n) => n.type.name === U,
454
- runner: (n, o) => {
455
- var l;
456
- n.addNode("code", void 0, ((l = o.content.firstChild) == null ? void 0 : l.text) || "", {
457
- lang: o.attrs.language
458
- });
459
- }
103
+ }
104
+ }), me = H("link"), v = K("link", (r) => ({
105
+ attrs: {
106
+ href: {},
107
+ title: { default: null }
108
+ },
109
+ parseDOM: [
110
+ {
111
+ tag: "a[href]",
112
+ getAttrs: (e) => {
113
+ if (!(e instanceof HTMLElement))
114
+ throw b(e);
115
+ return { href: e.getAttribute("href"), title: e.getAttribute("title") };
460
116
  }
461
- }),
462
- inputRules: (r) => [
463
- X(st, r, (n) => {
464
- const [o, l] = n;
465
- if (!!o)
466
- return { language: l };
467
- }),
468
- X(ot, r, (n) => {
469
- const [o, l] = n;
470
- if (!!o)
471
- return { language: l };
472
- })
473
- ],
474
- commands: (r) => [N(ae, () => A(r))],
475
- shortcuts: {
476
- [y.CodeFence]: M(ae, "Mod-Alt-c")
477
- },
478
- view: () => (r, n, o) => {
479
- let l = r;
480
- const s = (g) => {
481
- const { tr: h } = n.state;
482
- n.dispatch(
483
- h.setNodeMarkup(o(), void 0, {
484
- fold: !0,
485
- language: g
486
- })
487
- );
488
- }, c = () => {
489
- const { tr: g } = n.state;
490
- n.dispatch(
491
- g.setNodeMarkup(o(), void 0, {
492
- ...l.attrs,
493
- fold: !0
494
- })
495
- );
496
- }, i = () => {
497
- const { tr: g } = n.state;
498
- n.dispatch(
499
- g.setNodeMarkup(o(), void 0, {
500
- ...l.attrs,
501
- fold: !1
502
- })
503
- );
504
- }, u = a.themeManager.get("code-fence", {
505
- view: n,
506
- onBlur: c,
507
- onFocus: i,
508
- onSelectLanguage: s,
509
- editable: () => n.editable,
510
- languageList: t
117
+ }
118
+ ],
119
+ toDOM: (e) => ["a", { ...r.get(me.key)(e), ...e.attrs }],
120
+ parseMarkdown: {
121
+ match: (e) => e.type === "link",
122
+ runner: (e, t, n) => {
123
+ const o = t.url, a = t.title;
124
+ e.openMark(n, { href: o, title: a }), e.next(t.children), e.closeMark(n);
125
+ }
126
+ },
127
+ toMarkdown: {
128
+ match: (e) => e.type.name === "link",
129
+ runner: (e, t) => {
130
+ e.withMark(t, "link", void 0, {
131
+ title: t.attrs.title,
132
+ url: t.attrs.href
511
133
  });
512
- if (!u)
513
- return {};
514
- const { dom: f, contentDOM: d, onUpdate: m, onDestroy: p } = u;
515
- return m(l), {
516
- dom: f,
517
- contentDOM: d,
518
- update: (g) => g.type.name !== U ? !1 : (l = g, m(l), !0),
519
- destroy: p
520
- };
521
134
  }
522
- };
523
- }), lt = C(() => ({
524
- id: "doc",
525
- schema: () => ({
526
- content: "block+",
527
- parseMarkdown: {
528
- match: ({ type: a }) => a === "root",
529
- runner: (a, e, t) => {
530
- a.injectRoot(e, t);
531
- }
532
- },
533
- toMarkdown: {
534
- match: (a) => a.type.name === "doc",
535
- runner: (a, e) => {
536
- a.openNode("root"), a.next(e.content);
537
- }
135
+ }
136
+ })), Qe = u("ToggleLink", () => (r = {}) => q(v.type(), r)), Xe = u("UpdateLink", () => (r = {}) => (e, t) => {
137
+ if (!t)
138
+ return !1;
139
+ let n, o = -1;
140
+ const { selection: a } = e, { from: s, to: l } = a;
141
+ if (e.doc.nodesBetween(s, s === l ? l + 1 : l, (h, _) => {
142
+ if (v.type().isInSet(h.marks))
143
+ return n = h, o = _, !1;
144
+ }), !n)
145
+ return !1;
146
+ const c = n.marks.find(({ type: h }) => h === v.type());
147
+ if (!c)
148
+ return !1;
149
+ const i = o, d = o + n.nodeSize, { tr: p } = e, g = v.type().create({ ...c.attrs, ...r });
150
+ return g ? (t(
151
+ p.removeMark(i, d, c).addMark(i, d, g).setSelection(new re(p.selection.$anchor)).scrollIntoView()
152
+ ), !0) : !1;
153
+ }), Ze = X("doc", () => ({
154
+ content: "block+",
155
+ parseMarkdown: {
156
+ match: ({ type: r }) => r === "root",
157
+ runner: (r, e, t) => {
158
+ r.injectRoot(e, t);
538
159
  }
539
- })
540
- })), le = I("InsertHardbreak"), ct = new H("MILKDOWN_HARDBREAK_FILTER"), it = C((a, e) => {
541
- var r;
542
- const t = (r = e == null ? void 0 : e.notIn) != null ? r : ["table", "fence"];
543
- return {
544
- id: "hardbreak",
545
- schema: () => ({
546
- inline: !0,
547
- group: "inline",
548
- selectable: !1,
549
- parseDOM: [{ tag: "br" }],
550
- toDOM: (n) => ["br", { class: a.getClassName(n.attrs, "hardbreak") }],
551
- parseMarkdown: {
552
- match: ({ type: n }) => n === "break",
553
- runner: (n, o, l) => {
554
- n.addNode(l);
555
- }
556
- },
557
- toMarkdown: {
558
- match: (n) => n.type.name === "hardbreak",
559
- runner: (n) => {
560
- n.addNode("break");
561
- }
562
- }
563
- }),
564
- commands: (n) => [
565
- N(le, () => (o, l) => {
566
- var i;
567
- const { selection: s, tr: c } = o;
568
- if (s.empty) {
569
- const u = s.$from.node();
570
- if (u.childCount > 0 && ((i = u.lastChild) == null ? void 0 : i.type.name) === "hardbreak")
571
- return l == null || l(
572
- c.replaceRangeWith(s.to - 1, s.to, o.schema.node("paragraph")).setSelection(Ce.near(c.doc.resolve(s.to))).scrollIntoView()
573
- ), !0;
574
- }
575
- return l == null || l(c.setMeta("hardbreak", !0).replaceSelectionWith(n.create()).scrollIntoView()), !0;
576
- })
577
- ],
578
- shortcuts: {
579
- [y.HardBreak]: M(le, "Shift-Enter")
580
- },
581
- prosePlugins: (n) => [
582
- new T({
583
- key: ct,
584
- filterTransaction: (o, l) => {
585
- const s = o.getMeta("hardbreak"), [c] = o.steps;
586
- if (s && c) {
587
- const { from: i } = c, u = l.doc.resolve(i);
588
- let f = u.depth, d = !0;
589
- for (; f > 0; )
590
- t.includes(u.node(f).type.name) && (d = !1), f--;
591
- return d;
592
- }
593
- return !0;
594
- }
595
- }),
596
- new T({
597
- key: new H("MILKDOWN_HARDBREAK_MARKS"),
598
- appendTransaction: (o, l, s) => {
599
- if (!o.length)
600
- return;
601
- const [c] = o;
602
- if (!c)
603
- return;
604
- const [i] = c.steps;
605
- if (c.getMeta("hardbreak")) {
606
- if (!(i instanceof Ke))
607
- return;
608
- const { from: d } = i;
609
- return s.tr.setNodeMarkup(d, n, void 0, []);
610
- }
611
- if (i instanceof Fe) {
612
- let d = s.tr;
613
- const { from: m, to: p } = i;
614
- return s.doc.nodesBetween(m, p, (g, h) => {
615
- g.type === n && (d = d.setNodeMarkup(h, n, void 0, []));
616
- }), d;
617
- }
618
- }
619
- })
620
- ]
621
- };
622
- }), Me = Array(6).fill(0).map((a, e) => e + 1), O = I("TurnIntoHeading"), ye = I("DowngradeHeading"), V = new H("MILKDOWN_HEADING_ID"), ut = new H("MILKDOWN_HEADING_HASH"), dt = (a) => a.textContent.replace(/[\p{P}\p{S}]/gu, "").replace(/\s/g, "-").toLowerCase().trim(), ft = (a, e, t) => {
623
- let r = !1;
624
- const n = (o, l) => {
625
- const s = o.tr.setMeta("addToHistory", !1);
626
- let c = !1;
627
- o.doc.descendants((i, u) => {
628
- if (i.type === e && !r) {
629
- if (i.textContent.trim().length === 0)
630
- return;
631
- const f = i.attrs, d = t(i);
632
- f.id !== d && (c = !0, s.setMeta(V, !0).setNodeMarkup(u, void 0, {
633
- ...f,
634
- id: d
635
- }));
636
- }
637
- }), c && l(s);
638
- };
639
- return new T({
640
- key: V,
641
- props: {
642
- handleDOMEvents: {
643
- compositionstart: () => (r = !0, !1),
644
- compositionend: () => {
645
- r = !1;
646
- const o = a.get(v);
647
- return setTimeout(() => {
648
- n(o.state, (l) => o.dispatch(l));
649
- }, 0), !1;
650
- }
651
- }
652
- },
653
- appendTransaction: (o, l, s) => {
654
- let c = null;
655
- return o.every((i) => !i.getMeta(V)) && o.some((i) => i.docChanged) && n(s, (i) => {
656
- c = i;
657
- }), c;
658
- },
659
- view: (o) => {
660
- const l = o.state.doc;
661
- let s = o.state.tr.setMeta("addToHistory", !1);
662
- return l.descendants((c, i) => {
663
- c.type.name === "heading" && c.attrs.level && (c.attrs.id || (s = s.setNodeMarkup(i, void 0, {
664
- ...c.attrs,
665
- id: t(c)
666
- })));
667
- }), o.dispatch(s), {};
160
+ },
161
+ toMarkdown: {
162
+ match: (r) => r.type.name === "doc",
163
+ runner: (r, e) => {
164
+ r.openNode("root"), r.next(e.content);
668
165
  }
669
- });
670
- }, mt = (a, e, t) => new T({
671
- key: ut,
672
- state: {
673
- init: () => S.empty,
674
- apply: (r) => {
675
- var f;
676
- const n = a.get(v);
677
- if (!((f = n.hasFocus) != null && f.call(n)) || !n.editable)
678
- return S.empty;
679
- const { $from: o } = r.selection, l = o.node();
680
- if (l.type !== e)
681
- return S.empty;
682
- const s = l.attrs.level, c = (d) => Array(d).fill(0).map((m) => "#").join(""), i = document.createElement("span");
683
- i.textContent = c(s), i.contentEditable = "false", t.themeManager.onFlush(() => {
684
- const d = t.getStyle(({ css: m }) => {
685
- const p = Ae(t.themeManager);
686
- return m`
687
- margin-right: 4px;
688
- color: ${p("primary")};
689
- `;
690
- });
691
- d && (i.className = d);
692
- });
693
- const u = Z.widget(o.before() + 1, i, { side: -1 });
694
- return S.create(r.doc, [u]);
166
+ }
167
+ })), ge = k("paragraph"), L = y("paragraph", (r) => ({
168
+ content: "inline*",
169
+ group: "block",
170
+ parseDOM: [{ tag: "p" }],
171
+ toDOM: (e) => ["p", r.get(ge.key)(e), 0],
172
+ parseMarkdown: {
173
+ match: (e) => e.type === "paragraph",
174
+ runner: (e, t, n) => {
175
+ e.openNode(n), t.children ? e.next(t.children) : e.addText(t.value || ""), e.closeNode();
695
176
  }
696
177
  },
697
- props: {
698
- handleDOMEvents: {
699
- focus: (r) => {
700
- const n = Re(r.state.tr);
701
- return r.dispatch(n), !1;
702
- }
703
- },
704
- decorations(r) {
705
- return this.getState(r);
178
+ toMarkdown: {
179
+ match: (e) => e.type.name === "paragraph",
180
+ runner: (e, t) => {
181
+ var o;
182
+ if (e.openNode("paragraph"), t.childCount >= 1 && ((o = t.lastChild) == null ? void 0 : o.type.name) === "hardbreak") {
183
+ const a = [];
184
+ t.content.forEach((s, l, c) => {
185
+ c !== t.childCount - 1 && a.push(s);
186
+ }), e.next(Z.fromArray(a));
187
+ } else
188
+ e.next(t.content);
189
+ e.closeNode();
706
190
  }
707
191
  }
708
- }), pt = C(
709
- (a, e) => {
710
- var o, l;
711
- const t = "heading", r = (o = e == null ? void 0 : e.getId) != null ? o : dt, n = (l = e == null ? void 0 : e.displayHashtag) != null ? l : !0;
712
- return {
713
- id: t,
714
- schema: () => ({
715
- content: "inline*",
716
- group: "block",
717
- defining: !0,
718
- attrs: {
719
- id: {
720
- default: ""
721
- },
722
- level: {
723
- default: 1
724
- }
725
- },
726
- parseDOM: Me.map((s) => ({
727
- tag: `h${s}`,
728
- getAttrs: (c) => {
729
- if (!(c instanceof HTMLElement))
730
- throw x(c);
731
- return { level: s, id: c.id };
732
- }
733
- })),
734
- toDOM: (s) => [
735
- `h${s.attrs.level}`,
736
- {
737
- id: s.attrs.id || r(s),
738
- class: a.getClassName(s.attrs, `heading h${s.attrs.level}`)
739
- },
740
- 0
741
- ],
742
- parseMarkdown: {
743
- match: ({ type: s }) => s === t,
744
- runner: (s, c, i) => {
745
- const u = c.depth;
746
- s.openNode(i, { level: u }), s.next(c.children), s.closeNode();
747
- }
748
- },
749
- toMarkdown: {
750
- match: (s) => s.type.name === t,
751
- runner: (s, c) => {
752
- var u;
753
- if (s.openNode("heading", void 0, { depth: c.attrs.level }), c.childCount >= 1 && ((u = c.lastChild) == null ? void 0 : u.type.name) === "hardbreak") {
754
- const f = [];
755
- c.content.forEach((d, m, p) => {
756
- p !== c.childCount - 1 && f.push(d);
757
- }), s.next(W.fromArray(f));
758
- } else
759
- s.next(c.content);
760
- s.closeNode();
761
- }
762
- }
763
- }),
764
- inputRules: (s, c) => Me.map(
765
- (i) => X(new RegExp(`^(#{1,${i}})\\s$`), s, () => {
766
- const u = c.get(v), { $from: f } = u.state.selection, d = f.node();
767
- if (d.type.name === "heading") {
768
- let m = Number(d.attrs.level) + Number(i);
769
- return m > 6 && (m = 6), {
770
- level: m
771
- };
772
- }
773
- return {
774
- level: i
775
- };
776
- })
777
- ),
778
- commands: (s, c) => [
779
- N(O, (i = 1) => i < 1 ? A(i === 0 && c.get(R).nodes.paragraph || s) : A(i === 0 && c.get(R).nodes.paragraph || s, { level: i })),
780
- N(ye, () => (i, u, f) => {
781
- const { $from: d } = i.selection, m = d.node();
782
- if (m.type !== s || !i.selection.empty || d.parentOffset !== 0)
783
- return !1;
784
- const p = m.attrs.level - 1;
785
- return p ? (u == null || u(
786
- i.tr.setNodeMarkup(i.selection.$from.before(), void 0, {
787
- ...m.attrs,
788
- level: p
789
- })
790
- ), !0) : A(c.get(R).nodes.paragraph || s)(i, u, f);
791
- })
792
- ],
793
- shortcuts: {
794
- [y.H1]: M(O, "Mod-Alt-1", 1),
795
- [y.H2]: M(O, "Mod-Alt-2", 2),
796
- [y.H3]: M(O, "Mod-Alt-3", 3),
797
- [y.H4]: M(O, "Mod-Alt-4", 4),
798
- [y.H5]: M(O, "Mod-Alt-5", 5),
799
- [y.H6]: M(O, "Mod-Alt-6", 6),
800
- [y.DowngradeHeading]: M(ye, ["Backspace", "Delete"])
801
- },
802
- prosePlugins: (s, c) => {
803
- const i = [ft(c, s, r)];
804
- return n && i.push(mt(c, s, a)), i;
805
- }
806
- };
192
+ })), fe = u("TurnIntoText", () => () => S(L.type())), et = f("paragraphKeymap", {
193
+ TurnIntoText: {
194
+ shortcuts: "Mod-Alt-0",
195
+ command: (r) => {
196
+ const e = r.get(m);
197
+ return () => e.call(fe.key);
198
+ }
807
199
  }
808
- ), G = "hr", He = I("InsertHr"), gt = C((a) => ({
809
- id: G,
810
- schema: () => ({
200
+ }), tt = Array(6).fill(0).map((r, e) => e + 1), rt = (r) => r.textContent.replace(/[\p{P}\p{S}]/gu, "").replace(/\s/g, "-").toLowerCase().trim(), G = P(rt, "headingIdGenerator"), he = k("heading"), T = y("heading", (r) => {
201
+ const e = r.get(G.key);
202
+ return {
203
+ content: "inline*",
811
204
  group: "block",
812
- parseDOM: [{ tag: "hr" }],
813
- toDOM: (e) => ["hr", { class: a.getClassName(e.attrs, G) }],
814
- parseMarkdown: {
815
- match: ({ type: e }) => e === "thematicBreak",
816
- runner: (e, t, r) => {
817
- e.addNode(r);
818
- }
819
- },
820
- toMarkdown: {
821
- match: (e) => e.type.name === G,
822
- runner: (e) => {
823
- e.addNode("thematicBreak");
824
- }
825
- }
826
- }),
827
- inputRules: (e) => [
828
- new xe(/^(?:---|___\s|\*\*\*\s)$/, (t, r, n, o) => {
829
- const { tr: l } = t;
830
- return r[0] && l.replaceWith(n - 1, o, e.create()), l;
831
- })
832
- ],
833
- commands: (e, t) => [
834
- N(He, () => (r, n) => {
835
- if (!n)
836
- return !0;
837
- const o = t.get(R).node("paragraph"), { tr: l, selection: s } = r, { from: c } = s, i = e.create();
838
- if (!i)
839
- return !0;
840
- const u = l.replaceSelectionWith(i).insert(c, o), f = Ce.findFrom(u.doc.resolve(c), 1, !0);
841
- return f && n(u.setSelection(f).scrollIntoView()), !0;
842
- })
843
- ]
844
- })), ce = I("ModifyImage"), De = I("InsertImage"), B = "image", ht = new H("MILKDOWN_IMAGE_INPUT"), kt = C((a, e) => ({
845
- id: "image",
846
- schema: () => ({
847
- inline: !0,
848
- group: "inline",
849
- selectable: !0,
850
- draggable: !0,
851
- marks: "",
852
- atom: !0,
853
205
  defining: !0,
854
- isolating: !0,
855
206
  attrs: {
856
- src: { default: "" },
857
- alt: { default: "" },
858
- title: { default: "" }
207
+ id: {
208
+ default: ""
209
+ },
210
+ level: {
211
+ default: 1
212
+ }
859
213
  },
860
- parseDOM: [
861
- {
862
- tag: "img[src]",
863
- getAttrs: (t) => {
864
- if (!(t instanceof HTMLElement))
865
- throw x(t);
866
- return {
867
- src: t.getAttribute("src") || "",
868
- alt: t.getAttribute("alt") || "",
869
- title: t.getAttribute("title") || t.getAttribute("alt") || ""
870
- };
871
- }
214
+ parseDOM: tt.map((t) => ({
215
+ tag: `h${t}`,
216
+ getAttrs: (n) => {
217
+ if (!(n instanceof HTMLElement))
218
+ throw b(n);
219
+ return { level: t, id: n.id };
872
220
  }
873
- ],
221
+ })),
874
222
  toDOM: (t) => [
875
- "img",
223
+ `h${t.attrs.level}`,
876
224
  {
877
- ...t.attrs,
878
- class: a.getClassName(t.attrs, B)
879
- }
225
+ ...r.get(he.key)(t),
226
+ id: t.attrs.id || e(t)
227
+ },
228
+ 0
880
229
  ],
881
230
  parseMarkdown: {
882
- match: ({ type: t }) => t === B,
883
- runner: (t, r, n) => {
884
- const o = r.url, l = r.alt, s = r.title;
885
- t.addNode(n, {
886
- src: o,
887
- alt: l,
888
- title: s
889
- });
231
+ match: ({ type: t }) => t === "heading",
232
+ runner: (t, n, o) => {
233
+ const a = n.depth;
234
+ t.openNode(o, { level: a }), t.next(n.children), t.closeNode();
890
235
  }
891
236
  },
892
237
  toMarkdown: {
893
- match: (t) => t.type.name === B,
894
- runner: (t, r) => {
895
- t.addNode("image", void 0, void 0, {
896
- title: r.attrs.title,
897
- url: r.attrs.src,
898
- alt: r.attrs.alt
899
- });
238
+ match: (t) => t.type.name === "heading",
239
+ runner: (t, n) => {
240
+ var a;
241
+ if (t.openNode("heading", void 0, { depth: n.attrs.level }), n.childCount >= 1 && ((a = n.lastChild) == null ? void 0 : a.type.name) === "hardbreak") {
242
+ const s = [];
243
+ n.content.forEach((l, c, i) => {
244
+ i !== n.childCount - 1 && s.push(l);
245
+ }), t.next(Z.fromArray(s));
246
+ } else
247
+ t.next(n.content);
248
+ t.closeNode();
900
249
  }
901
250
  }
902
- }),
903
- commands: (t) => [
904
- N(De, (r = "") => (n, o) => {
905
- if (!o)
906
- return !0;
907
- const { tr: l } = n, s = t.create({ src: r });
908
- if (!s)
909
- return !0;
910
- const c = l.replaceSelectionWith(s);
911
- return o(c.scrollIntoView()), !0;
912
- }),
913
- N(ce, (r = "") => (n, o) => {
914
- const l = F(n.selection, t);
915
- if (!l)
916
- return !1;
917
- const { tr: s } = n;
918
- return o == null || o(
919
- s.setNodeMarkup(l.pos, void 0, { ...l.node.attrs, loading: !0, src: r }).scrollIntoView()
920
- ), !0;
251
+ };
252
+ }), nt = I(
253
+ (r) => ee(/^(?<hashes>#+)\s$/, T.type(), (e) => {
254
+ var s, l;
255
+ const t = ((l = (s = e.groups) == null ? void 0 : s.hashes) == null ? void 0 : l.length) || 0, n = r.get(R), { $from: o } = n.state.selection, a = o.node();
256
+ if (a.type.name === "heading") {
257
+ let c = Number(a.attrs.level) + Number(t);
258
+ return c > 6 && (c = 6), { level: c };
259
+ }
260
+ return { level: t };
261
+ })
262
+ ), M = u("WrapInHeading", () => (r) => (r ?? (r = 1), r < 1 ? S(L.type()) : S(T.type(), { level: r }))), ke = u("DowngradeHeading", () => () => (r, e, t) => {
263
+ const { $from: n } = r.selection, o = n.node();
264
+ if (o.type !== T.type() || !r.selection.empty || n.parentOffset !== 0)
265
+ return !1;
266
+ const a = o.attrs.level - 1;
267
+ return a ? (e == null || e(
268
+ r.tr.setNodeMarkup(r.selection.$from.before(), void 0, {
269
+ ...o.attrs,
270
+ level: a
921
271
  })
922
- ],
923
- inputRules: (t) => [
924
- new xe(
925
- /!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/,
926
- (r, n, o, l) => {
927
- const [s, c, i = "", u] = n, { tr: f } = r;
928
- return s && f.replaceWith(o, l, t.create({ src: i, alt: c, title: u })), f;
272
+ ), !0) : S(L.type())(r, e, t);
273
+ }), ot = f("headingKeymap", {
274
+ TurnIntoH1: {
275
+ shortcuts: "Mod-Alt-1",
276
+ command: (r) => {
277
+ const e = r.get(m);
278
+ return () => e.call(M.key, 1);
279
+ }
280
+ },
281
+ TurnIntoH2: {
282
+ shortcuts: "Mod-Alt-2",
283
+ command: (r) => {
284
+ const e = r.get(m);
285
+ return () => e.call(M.key, 2);
286
+ }
287
+ },
288
+ TurnIntoH3: {
289
+ shortcuts: "Mod-Alt-3",
290
+ command: (r) => {
291
+ const e = r.get(m);
292
+ return () => e.call(M.key, 3);
293
+ }
294
+ },
295
+ TurnIntoH4: {
296
+ shortcuts: "Mod-Alt-4",
297
+ command: (r) => {
298
+ const e = r.get(m);
299
+ return () => e.call(M.key, 3);
300
+ }
301
+ },
302
+ TurnIntoH5: {
303
+ shortcuts: "Mod-Alt-5",
304
+ command: (r) => {
305
+ const e = r.get(m);
306
+ return () => e.call(M.key, 3);
307
+ }
308
+ },
309
+ TurnIntoH6: {
310
+ shortcuts: "Mod-Alt-6",
311
+ command: (r) => {
312
+ const e = r.get(m);
313
+ return () => e.call(M.key, 3);
314
+ }
315
+ },
316
+ DowngradeHeading: {
317
+ shortcuts: ["Delete", "Backspace"],
318
+ command: (r) => {
319
+ const e = r.get(m);
320
+ return () => e.call(ke.key);
321
+ }
322
+ }
323
+ }), ye = k("blockquote"), z = y("blockquote", (r) => ({
324
+ content: "block+",
325
+ group: "block",
326
+ defining: !0,
327
+ parseDOM: [{ tag: "blockquote" }],
328
+ toDOM: (e) => ["blockquote", r.get(ye.key)(e), 0],
329
+ parseMarkdown: {
330
+ match: ({ type: e }) => e === "blockquote",
331
+ runner: (e, t, n) => {
332
+ e.openNode(n).next(t.children).closeNode();
333
+ }
334
+ },
335
+ toMarkdown: {
336
+ match: (e) => e.type.name === "blockquote",
337
+ runner: (e, t) => {
338
+ e.openNode("blockquote").next(t.content).closeNode();
339
+ }
340
+ }
341
+ })), at = I(() => V(/^\s*>\s$/, z.type())), Me = u("WrapInBlockquote", () => () => F(z.type())), st = f("blockquoteKeymap", {
342
+ WrapInBlockquote: {
343
+ shortcuts: "Mod-Shift-b",
344
+ command: (r) => {
345
+ const e = r.get(m);
346
+ return () => e.call(Me.key);
347
+ }
348
+ }
349
+ }), Ie = k("codeBlock", () => ({
350
+ pre: {},
351
+ code: {}
352
+ })), j = y("code_block", (r) => ({
353
+ content: "text*",
354
+ group: "block",
355
+ marks: "",
356
+ defining: !0,
357
+ code: !0,
358
+ attrs: {
359
+ language: {
360
+ default: ""
361
+ }
362
+ },
363
+ parseDOM: [
364
+ {
365
+ tag: "pre",
366
+ preserveWhitespace: "full",
367
+ getAttrs: (e) => {
368
+ if (!(e instanceof HTMLElement))
369
+ throw b(e);
370
+ return { language: e.dataset.language };
929
371
  }
930
- )
372
+ }
931
373
  ],
932
- view: () => (t) => {
933
- var i, u;
934
- let r = t;
935
- const n = (i = e == null ? void 0 : e.placeholder) != null ? i : "Add an Image", o = (u = e == null ? void 0 : e.isBlock) != null ? u : !1, l = a.themeManager.get("image", {
936
- placeholder: n,
937
- isBlock: o
938
- });
939
- if (!l)
940
- return {};
941
- const { dom: s, onUpdate: c } = l;
942
- return c(r), {
943
- dom: s,
944
- update: (f) => f.type.name !== B ? !1 : (r = f, c(r), !0),
945
- selectNode: () => {
946
- s.classList.add("ProseMirror-selectednode");
374
+ toDOM: (e) => {
375
+ const t = r.get(Ie.key)(e);
376
+ return [
377
+ "pre",
378
+ {
379
+ ...t.pre,
380
+ "data-language": e.attrs.language
947
381
  },
948
- deselectNode: () => {
949
- s.classList.remove("ProseMirror-selectednode");
950
- }
951
- };
382
+ ["code", t.code, 0]
383
+ ];
952
384
  },
953
- prosePlugins: (t, r) => [
954
- new T({
955
- key: ht,
956
- view: (n) => {
957
- var i, u, f;
958
- const o = a.themeManager.get("input-chip", {
959
- placeholder: (u = (i = e == null ? void 0 : e.input) == null ? void 0 : i.placeholder) != null ? u : "Input Image Link",
960
- buttonText: (f = e == null ? void 0 : e.input) == null ? void 0 : f.buttonText,
961
- onUpdate: (d) => {
962
- r.get(Le).call(ce, d);
963
- }
964
- });
965
- if (!o)
966
- return {};
967
- const l = (d) => Boolean(
968
- d.hasFocus() && t && F(d.state.selection, t)
969
- ), s = (d) => {
970
- const m = F(d.state.selection, t);
971
- return m ? m.node.attrs.src : void 0;
972
- }, c = (d) => {
973
- if (!d.editable)
974
- return;
975
- l(d) ? (o.show(d), o.update(s(d))) : o.hide();
976
- };
977
- return o.init(n), c(n), {
978
- update: (d, m) => {
979
- (m == null ? void 0 : m.doc.eq(d.state.doc)) && m.selection.eq(d.state.selection) || c(d);
980
- },
981
- destroy: () => {
982
- o.destroy();
983
- }
984
- };
985
- }
986
- })
987
- ]
988
- })), Ne = "list_item", ie = I("SplitListItem"), ue = I("SinkListItem"), de = I("LiftListItem"), Mt = new H("MILKDOWN_KEEP_LIST_ORDER"), yt = (a) => {
989
- const e = (t, r) => {
990
- const n = We("ordered_list", t.schema);
991
- let o = t.tr;
992
- t.doc.descendants((l, s, c, i) => {
993
- if (l.type === a && (c == null ? void 0 : c.type) === n) {
994
- let u = !1;
995
- const f = { ...l.attrs };
996
- l.attrs.listType !== "ordered" && (f.listType = "ordered", u = !0);
997
- const d = c == null ? void 0 : c.maybeChild(0);
998
- d && d.type === a && d.attrs.listType === "ordered" && (f.label = `${i + 1}.`, u = !0), l.attrs.label === "\u2022" && (f.label = `${i + 1}.`, u = !0), u && (o = o.setNodeMarkup(s, void 0, f));
999
- }
1000
- }), r(o);
385
+ parseMarkdown: {
386
+ match: ({ type: e }) => e === "code",
387
+ runner: (e, t, n) => {
388
+ const o = t.lang, a = t.value;
389
+ e.openNode(n, { language: o }), a && e.addText(a), e.closeNode();
390
+ }
391
+ },
392
+ toMarkdown: {
393
+ match: (e) => e.type.name === "code_block",
394
+ runner: (e, t) => {
395
+ var n;
396
+ e.addNode("code", void 0, ((n = t.content.firstChild) == null ? void 0 : n.text) || "", {
397
+ lang: t.attrs.language
398
+ });
399
+ }
400
+ }
401
+ })), lt = I(() => ee(/^```(?<language>[a-z]*)?[\s\n]$/, j.type(), (r) => {
402
+ var e;
403
+ return {
404
+ language: ((e = r.groups) == null ? void 0 : e.language) ?? ""
1001
405
  };
1002
- return new T({
1003
- key: Mt,
1004
- appendTransaction: (t, r, n) => {
1005
- let o = null;
1006
- return t.some((l) => l.docChanged) && e(n, (l) => {
1007
- o = l;
1008
- }), o;
406
+ })), be = u("CreateCodeBlock", () => (r = "") => S(j.type(), { language: r })), lr = u("UpdateCodeBlockLanguage", () => ({ pos: r, language: e } = { pos: -1, language: "" }) => (t, n) => r >= 0 ? (n == null || n(t.tr.setNodeAttribute(r, "language", e)), !0) : !1), ct = f("codeBlockKeymap", {
407
+ CreateCodeBlock: {
408
+ shortcuts: "Mod-Alt-c",
409
+ command: (r) => {
410
+ const e = r.get(m);
411
+ return () => e.call(be.key);
1009
412
  }
1010
- });
1011
- }, Nt = C((a) => ({
1012
- id: Ne,
1013
- schema: () => ({
1014
- group: "listItem",
1015
- content: "paragraph block*",
1016
- attrs: {
1017
- label: {
1018
- default: "\u2022"
1019
- },
1020
- listType: {
1021
- default: "bullet"
1022
- },
1023
- spread: {
1024
- default: "true"
1025
- }
1026
- },
1027
- defining: !0,
1028
- parseDOM: [
1029
- {
1030
- tag: "li.list-item",
1031
- getAttrs: (e) => {
1032
- if (!(e instanceof HTMLElement))
1033
- throw x(e);
1034
- return {
1035
- label: e.dataset.label,
1036
- listType: e.dataset["list-type"],
1037
- spread: e.dataset.spread
1038
- };
1039
- },
1040
- contentElement: (e) => {
1041
- if (!(e instanceof HTMLElement))
1042
- throw x(e);
1043
- const t = e.querySelector(".list-item_body");
1044
- return t || e;
1045
- }
1046
- },
1047
- { tag: "li" }
1048
- ],
1049
- toDOM: (e) => [
1050
- "li",
1051
- {
1052
- class: a.getClassName(e.attrs, "list-item"),
1053
- "data-label": e.attrs.label,
1054
- "data-list-type": e.attrs.listType,
1055
- "data-spread": e.attrs.spread
1056
- },
1057
- ["div", { class: a.getClassName(e.attrs, "list-item_label") }, e.attrs.label],
1058
- ["div", { class: a.getClassName(e.attrs, "list-item_body") }, 0]
1059
- ],
1060
- parseMarkdown: {
1061
- match: ({ type: e, checked: t }) => e === "listItem" && t === null,
1062
- runner: (e, t, r) => {
1063
- const n = t.label != null ? `${t.label}.` : "\u2022", o = t.label != null ? "ordered" : "bullet", l = t.spread != null ? `${t.spread}` : "true";
1064
- e.openNode(r, { label: n, listType: o, spread: l }), e.next(t.children), e.closeNode();
1065
- }
1066
- },
1067
- toMarkdown: {
1068
- match: (e) => e.type.name === Ne,
1069
- runner: (e, t) => {
1070
- e.openNode("listItem", void 0, { spread: t.attrs.spread === "true" }), e.next(t.content), e.closeNode();
413
+ }
414
+ }), we = k("image"), $ = y("image", (r) => ({
415
+ inline: !0,
416
+ group: "inline",
417
+ selectable: !0,
418
+ draggable: !0,
419
+ marks: "",
420
+ atom: !0,
421
+ defining: !0,
422
+ isolating: !0,
423
+ attrs: {
424
+ src: { default: "" },
425
+ alt: { default: "" },
426
+ title: { default: "" }
427
+ },
428
+ parseDOM: [
429
+ {
430
+ tag: "img[src]",
431
+ getAttrs: (e) => {
432
+ if (!(e instanceof HTMLElement))
433
+ throw b(e);
434
+ return {
435
+ src: e.getAttribute("src") || "",
436
+ alt: e.getAttribute("alt") || "",
437
+ title: e.getAttribute("title") || e.getAttribute("alt") || ""
438
+ };
1071
439
  }
1072
440
  }
1073
- }),
1074
- inputRules: (e) => [K(/^\s*([-+*])\s$/, e)],
1075
- commands: (e) => [
1076
- N(ie, () => je(e)),
1077
- N(ue, () => ze(e)),
1078
- N(de, () => Ue(e))
1079
441
  ],
1080
- shortcuts: {
1081
- [y.NextListItem]: M(ie, "Enter"),
1082
- [y.SinkListItem]: M(ue, "Mod-]"),
1083
- [y.LiftListItem]: M(de, "Mod-[")
442
+ toDOM: (e) => ["img", { ...r.get(we.key)(e), ...e.attrs }],
443
+ parseMarkdown: {
444
+ match: ({ type: e }) => e === "image",
445
+ runner: (e, t, n) => {
446
+ const o = t.url, a = t.alt, s = t.title;
447
+ e.addNode(n, {
448
+ src: o,
449
+ alt: a,
450
+ title: s
451
+ });
452
+ }
1084
453
  },
1085
- prosePlugins: (e) => [yt(e)]
1086
- })), fe = I("WrapInOrderedList"), Ie = "ordered_list", It = C((a) => ({
1087
- id: Ie,
1088
- schema: () => ({
1089
- content: "listItem+",
1090
- group: "block",
1091
- attrs: {
1092
- order: {
1093
- default: 1
1094
- },
1095
- spread: {
1096
- default: !1
454
+ toMarkdown: {
455
+ match: (e) => e.type.name === "image",
456
+ runner: (e, t) => {
457
+ e.addNode("image", void 0, void 0, {
458
+ title: t.attrs.title,
459
+ url: t.attrs.src,
460
+ alt: t.attrs.alt
461
+ });
462
+ }
463
+ }
464
+ })), it = u("InsertImage", () => (r = {}) => (e, t) => {
465
+ if (!t)
466
+ return !0;
467
+ const { src: n = "", alt: o = "", title: a = "" } = r, s = $.type().create({ src: n, alt: o, title: a });
468
+ return s && t(e.tr.replaceSelectionWith(s).scrollIntoView()), !0;
469
+ }), dt = u("UpdateImage", () => (r = {}) => (e, t) => {
470
+ const n = We(e.selection, $.type());
471
+ if (!n)
472
+ return !1;
473
+ const { node: o, pos: a } = n, s = { ...o.attrs }, { src: l, alt: c, title: i } = r;
474
+ return l !== void 0 && (s.src = l), c !== void 0 && (s.alt = c), i !== void 0 && (s.title = i), t == null || t(e.tr.setNodeMarkup(a, void 0, s).scrollIntoView()), !0;
475
+ }), cr = I(() => new te(
476
+ /!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/,
477
+ (r, e, t, n) => {
478
+ const [o, a, s = "", l] = e;
479
+ return o ? r.tr.replaceWith(t, n, $.type().create({ src: s, alt: a, title: l })) : null;
480
+ }
481
+ )), Ne = k("hardbreak", (r) => ({
482
+ "data-is-inline": r.attrs.isInline
483
+ })), x = y("hardbreak", (r) => ({
484
+ inline: !0,
485
+ group: "inline",
486
+ attrs: {
487
+ isInline: {
488
+ default: !1
489
+ }
490
+ },
491
+ selectable: !1,
492
+ parseDOM: [{ tag: "br" }],
493
+ toDOM: (e) => ["br", r.get(Ne.key)(e)],
494
+ parseMarkdown: {
495
+ match: ({ type: e }) => e === "break",
496
+ runner: (e, t, n) => {
497
+ var o;
498
+ e.addNode(n, { isInline: Boolean((o = t.data) == null ? void 0 : o.isInline) });
499
+ }
500
+ },
501
+ toMarkdown: {
502
+ match: (e) => e.type.name === "hardbreak",
503
+ runner: (e, t) => {
504
+ t.attrs.isInline ? e.addNode("text", void 0, `
505
+ `) : e.addNode("break");
506
+ }
507
+ }
508
+ })), Ce = u("InsertHardbreak", () => () => (r, e) => {
509
+ var o;
510
+ const { selection: t, tr: n } = r;
511
+ if (t.empty) {
512
+ const a = t.$from.node();
513
+ if (a.childCount > 0 && ((o = a.lastChild) == null ? void 0 : o.type.name) === "hardbreak")
514
+ return e == null || e(
515
+ n.replaceRangeWith(t.to - 1, t.to, r.schema.node("paragraph")).setSelection(ne.near(n.doc.resolve(t.to))).scrollIntoView()
516
+ ), !0;
517
+ }
518
+ return e == null || e(n.setMeta("hardbreak", !0).replaceSelectionWith(x.type().create()).scrollIntoView()), !0;
519
+ }), ut = f("hardbreakKeymap", {
520
+ InsertHardbreak: {
521
+ shortcuts: "Shift-Enter",
522
+ command: (r) => {
523
+ const e = r.get(m);
524
+ return () => e.call(Ce.key);
525
+ }
526
+ }
527
+ }), Ae = k("hr"), U = y("hr", (r) => ({
528
+ group: "block",
529
+ parseDOM: [{ tag: "hr" }],
530
+ toDOM: (e) => ["hr", r.get(Ae.key)(e)],
531
+ parseMarkdown: {
532
+ match: ({ type: e }) => e === "thematicBreak",
533
+ runner: (e, t, n) => {
534
+ e.addNode(n);
535
+ }
536
+ },
537
+ toMarkdown: {
538
+ match: (e) => e.type.name === "hr",
539
+ runner: (e) => {
540
+ e.addNode("thematicBreak");
541
+ }
542
+ }
543
+ })), pt = I(() => new te(
544
+ /^(?:---|___\s|\*\*\*\s)$/,
545
+ (r, e, t, n) => {
546
+ const { tr: o } = r;
547
+ return e[0] && o.replaceWith(t - 1, n, U.type().create()), o;
548
+ }
549
+ )), mt = u("InsertHr", () => () => (r, e) => {
550
+ if (!e)
551
+ return !0;
552
+ const t = L.node.type().create(), { tr: n, selection: o } = r, { from: a } = o, s = U.type().create();
553
+ if (!s)
554
+ return !0;
555
+ const l = n.replaceSelectionWith(s).insert(a, t), c = ne.findFrom(l.doc.resolve(a), 1, !0);
556
+ return c && e(l.setSelection(c).scrollIntoView()), !0;
557
+ }), ve = k("bulletList"), Y = y("bullet_list", (r) => ({
558
+ content: "listItem+",
559
+ group: "block",
560
+ attrs: {
561
+ spread: {
562
+ default: !1
563
+ }
564
+ },
565
+ parseDOM: [
566
+ {
567
+ tag: "ul",
568
+ getAttrs: (e) => {
569
+ if (!(e instanceof HTMLElement))
570
+ throw b(e);
571
+ return {
572
+ spread: e.dataset.spread
573
+ };
1097
574
  }
575
+ }
576
+ ],
577
+ toDOM: (e) => [
578
+ "ul",
579
+ {
580
+ ...r.get(ve.key)(e),
581
+ "data-spread": e.attrs.spread
1098
582
  },
1099
- parseDOM: [
1100
- {
1101
- tag: "ol",
1102
- getAttrs: (e) => {
1103
- if (!(e instanceof HTMLElement))
1104
- throw x(e);
1105
- return {
1106
- spread: e.dataset.spread,
1107
- order: e.hasAttribute("start") ? Number(e.getAttribute("start")) : 1
1108
- };
1109
- }
1110
- }
1111
- ],
1112
- toDOM: (e) => [
1113
- "ol",
1114
- {
1115
- ...e.attrs.order === 1 ? {} : e.attrs.order,
1116
- "data-spread": e.attrs.spread,
1117
- class: a.getClassName(e.attrs, "ordered-list")
1118
- },
1119
- 0
1120
- ],
1121
- parseMarkdown: {
1122
- match: ({ type: e, ordered: t }) => e === "list" && !!t,
1123
- runner: (e, t, r) => {
1124
- const n = t.spread != null ? `${t.spread}` : "true";
1125
- e.openNode(r, { spread: n }).next(t.children).closeNode();
1126
- }
583
+ 0
584
+ ],
585
+ parseMarkdown: {
586
+ match: ({ type: e, ordered: t }) => e === "list" && !t,
587
+ runner: (e, t, n) => {
588
+ const o = t.spread != null ? `${t.spread}` : "false";
589
+ e.openNode(n, { spread: o }).next(t.children).closeNode();
590
+ }
591
+ },
592
+ toMarkdown: {
593
+ match: (e) => e.type.name === "bullet_list",
594
+ runner: (e, t) => {
595
+ e.openNode("list", void 0, { ordered: !1, spread: t.attrs.spread === "true" }).next(t.content).closeNode();
596
+ }
597
+ }
598
+ })), gt = I(() => V(/^\s*([-+*])\s$/, Y.type())), xe = u("WrapInBulletList", () => () => F(Y.type())), ft = f("bulletListKeymap", {
599
+ WrapInBulletList: {
600
+ shortcuts: "Mod-Alt-8",
601
+ command: (r) => {
602
+ const e = r.get(m);
603
+ return () => e.call(xe.key);
604
+ }
605
+ }
606
+ }), Se = k("orderedList"), E = y("ordered_list", (r) => ({
607
+ content: "listItem+",
608
+ group: "block",
609
+ attrs: {
610
+ order: {
611
+ default: 1
1127
612
  },
1128
- toMarkdown: {
1129
- match: (e) => e.type.name === Ie,
1130
- runner: (e, t) => {
1131
- e.openNode("list", void 0, { ordered: !0, start: 1, spread: t.attrs.spread === "true" }), e.next(t.content), e.closeNode();
613
+ spread: {
614
+ default: !1
615
+ }
616
+ },
617
+ parseDOM: [
618
+ {
619
+ tag: "ol",
620
+ getAttrs: (e) => {
621
+ if (!(e instanceof HTMLElement))
622
+ throw b(e);
623
+ return {
624
+ spread: e.dataset.spread,
625
+ order: e.hasAttribute("start") ? Number(e.getAttribute("start")) : 1
626
+ };
1132
627
  }
1133
628
  }
1134
- }),
1135
- inputRules: (e) => [
1136
- K(
1137
- /^(\d+)\.\s$/,
1138
- e,
1139
- (t) => ({ order: Number(t[1]) }),
1140
- (t, r) => r.childCount + r.attrs.order === Number(t[1])
1141
- )
1142
629
  ],
1143
- commands: (e) => [N(fe, () => ge(e))],
1144
- shortcuts: {
1145
- [y.OrderedList]: M(fe, "Mod-Alt-7")
1146
- }
1147
- })), me = I("TurnIntoText"), be = "paragraph", bt = C((a) => ({
1148
- id: be,
1149
- schema: () => ({
1150
- content: "inline*",
1151
- group: "block",
1152
- parseDOM: [{ tag: "p" }],
1153
- toDOM: (e) => ["p", { class: a.getClassName(e.attrs, be) }, 0],
1154
- parseMarkdown: {
1155
- match: (e) => e.type === "paragraph",
1156
- runner: (e, t, r) => {
1157
- e.openNode(r), t.children ? e.next(t.children) : e.addText(t.value), e.closeNode();
1158
- }
630
+ toDOM: (e) => [
631
+ "ol",
632
+ {
633
+ ...r.get(Se.key)(e),
634
+ ...e.attrs.order === 1 ? {} : e.attrs.order,
635
+ "data-spread": e.attrs.spread
1159
636
  },
1160
- toMarkdown: {
1161
- match: (e) => e.type.name === "paragraph",
1162
- runner: (e, t) => {
1163
- var n;
1164
- if (e.openNode("paragraph"), t.childCount >= 1 && ((n = t.lastChild) == null ? void 0 : n.type.name) === "hardbreak") {
1165
- const o = [];
1166
- t.content.forEach((l, s, c) => {
1167
- c !== t.childCount - 1 && o.push(l);
1168
- }), e.next(W.fromArray(o));
1169
- } else
1170
- e.next(t.content);
1171
- e.closeNode();
1172
- }
637
+ 0
638
+ ],
639
+ parseMarkdown: {
640
+ match: ({ type: e, ordered: t }) => e === "list" && !!t,
641
+ runner: (e, t, n) => {
642
+ const o = t.spread != null ? `${t.spread}` : "true";
643
+ e.openNode(n, { spread: o }).next(t.children).closeNode();
644
+ }
645
+ },
646
+ toMarkdown: {
647
+ match: (e) => e.type.name === "ordered_list",
648
+ runner: (e, t) => {
649
+ e.openNode("list", void 0, { ordered: !0, start: 1, spread: t.attrs.spread === "true" }), e.next(t.content), e.closeNode();
1173
650
  }
1174
- }),
1175
- commands: (e) => [N(me, () => A(e))],
1176
- shortcuts: {
1177
- [y.Text]: M(me, "Mod-Alt-0")
1178
651
  }
1179
- })), wt = C(() => ({
1180
- id: "text",
1181
- schema: () => ({
1182
- group: "inline",
1183
- parseMarkdown: {
1184
- match: ({ type: a }) => a === "text",
1185
- runner: (a, e) => {
1186
- a.addText(e.value);
1187
- }
1188
- },
1189
- toMarkdown: {
1190
- match: (a) => a.type.name === "text",
1191
- runner: (a, e) => {
1192
- a.addNode("text", void 0, e.text);
1193
- }
652
+ })), ht = I(() => V(
653
+ /^\s*(\d+)\.\s$/,
654
+ E.type(),
655
+ (r) => ({ order: Number(r[1]) }),
656
+ (r, e) => e.childCount + e.attrs.order === Number(r[1])
657
+ )), Le = u("WrapInOrderedList", () => () => F(E.type())), kt = f("orderedListKeymap", {
658
+ WrapInOrderedList: {
659
+ shortcuts: "Mod-Alt-7",
660
+ command: (r) => {
661
+ const e = r.get(m);
662
+ return () => e.call(Le.key);
1194
663
  }
1195
- })
1196
- })), Lt = [
1197
- lt(),
1198
- bt(),
1199
- it(),
1200
- tt(),
1201
- at(),
1202
- rt(),
1203
- It(),
1204
- Nt(),
1205
- pt(),
1206
- gt(),
1207
- kt(),
1208
- wt()
1209
- ], Ct = () => {
1210
- function a(e) {
1211
- Ge(e, "list", (t) => {
1212
- var r;
1213
- if (t.ordered) {
1214
- const n = (r = t.start) != null ? r : 1;
1215
- t.children.forEach((o, l) => {
1216
- o.label = l + n;
1217
- });
1218
- }
1219
- });
1220
664
  }
1221
- return a;
1222
- }, xt = (a) => !!a.children, Tt = (a) => a.type === "html";
1223
- function Ht(a, e) {
1224
- return t(a, 0, null)[0];
1225
- function t(r, n, o) {
1226
- if (xt(r)) {
1227
- const l = [];
1228
- for (let s = 0, c = r.children.length; s < c; s++) {
1229
- const i = r.children[s];
1230
- if (i) {
1231
- const u = t(i, s, r);
1232
- if (u)
1233
- for (let f = 0, d = u.length; f < d; f++) {
1234
- const m = u[f];
1235
- m && l.push(m);
1236
- }
1237
- }
665
+ }), Te = k("listItem"), D = y("list_item", (r) => ({
666
+ group: "listItem",
667
+ content: "paragraph block*",
668
+ attrs: {
669
+ label: {
670
+ default: "•"
671
+ },
672
+ listType: {
673
+ default: "bullet"
674
+ },
675
+ spread: {
676
+ default: "true"
677
+ }
678
+ },
679
+ defining: !0,
680
+ parseDOM: [
681
+ {
682
+ tag: "li",
683
+ getAttrs: (e) => {
684
+ if (!(e instanceof HTMLElement))
685
+ throw b(e);
686
+ return {
687
+ label: e.dataset.label,
688
+ listType: e.dataset["list-type"],
689
+ spread: e.dataset.spread
690
+ };
1238
691
  }
1239
- r.children = l;
1240
692
  }
1241
- return e(r, n, o);
693
+ ],
694
+ toDOM: (e) => [
695
+ "li",
696
+ {
697
+ ...r.get(Te.key)(e),
698
+ "data-label": e.attrs.label,
699
+ "data-list-type": e.attrs.listType,
700
+ "data-spread": e.attrs.spread
701
+ },
702
+ 0
703
+ ],
704
+ parseMarkdown: {
705
+ match: ({ type: e }) => e === "listItem",
706
+ runner: (e, t, n) => {
707
+ const o = t.label != null ? `${t.label}.` : "•", a = t.label != null ? "ordered" : "bullet", s = t.spread != null ? `${t.spread}` : "true";
708
+ e.openNode(n, { label: o, listType: a, spread: s }), e.next(t.children), e.closeNode();
709
+ }
710
+ },
711
+ toMarkdown: {
712
+ match: (e) => e.type.name === "list_item",
713
+ runner: (e, t) => {
714
+ e.openNode("listItem", void 0, { spread: t.attrs.spread === "true" }), e.next(t.content), e.closeNode();
715
+ }
1242
716
  }
1243
- }
1244
- const Dt = () => {
1245
- function a(e) {
1246
- Ht(e, (t) => Tt(t) ? [] : [t]);
717
+ })), De = u("SinkListItem", () => () => qe(D.type())), Oe = u("SplitListItem", () => () => Fe(D.type())), _e = u("SplitListItem", () => () => Ve(D.type())), yt = f("listItemKeymap", {
718
+ NextListItem: {
719
+ shortcuts: "Enter",
720
+ command: (r) => {
721
+ const e = r.get(m);
722
+ return () => e.call(Oe.key);
723
+ }
724
+ },
725
+ SinkListItem: {
726
+ shortcuts: ["Tab", "Mod-]"],
727
+ command: (r) => {
728
+ const e = r.get(m);
729
+ return () => e.call(De.key);
730
+ }
731
+ },
732
+ LiftListItem: {
733
+ shortcuts: ["Shift-Tab", "Mod-["],
734
+ command: (r) => {
735
+ const e = r.get(m);
736
+ return () => e.call(_e.key);
737
+ }
1247
738
  }
1248
- return a;
1249
- }, Ot = new H("MILKDOWN_INLINE_NODES_CURSOR"), St = () => {
1250
- let a = !1;
1251
- const e = new T({
1252
- key: Ot,
1253
- state: {
1254
- init() {
1255
- return !1;
1256
- },
1257
- apply(t) {
1258
- if (!t.selection.empty)
1259
- return !1;
1260
- const r = t.selection.$from, n = r.nodeBefore, o = r.nodeAfter;
1261
- return !!(n && o && n.isInline && !n.isText && o.isInline && !o.isText);
1262
- }
1263
- },
1264
- props: {
1265
- handleDOMEvents: {
1266
- compositionend: (t, r) => a ? (a = !1, requestAnimationFrame(() => {
1267
- if (e.getState(t.state)) {
1268
- const o = t.state.selection.from;
1269
- r.preventDefault(), t.dispatch(t.state.tr.insertText(r.data || "", o));
1270
- }
1271
- }), !0) : !1,
1272
- compositionstart: (t) => (e.getState(t.state) && (a = !0), !1),
1273
- beforeinput: (t, r) => {
1274
- if (e.getState(t.state) && r instanceof InputEvent && r.data && !a) {
1275
- const o = t.state.selection.from;
1276
- return r.preventDefault(), t.dispatch(t.state.tr.insertText(r.data || "", o)), !0;
1277
- }
1278
- return !1;
1279
- }
1280
- },
1281
- decorations(t) {
1282
- if (e.getState(t)) {
1283
- const o = t.selection.$from.pos, l = document.createElement("span"), s = Z.widget(o, l, {
1284
- side: -1
1285
- }), c = document.createElement("span"), i = Z.widget(o, c);
1286
- return setTimeout(() => {
1287
- l.contentEditable = "true", c.contentEditable = "true";
1288
- }), S.create(t.doc, [s, i]);
1289
- }
1290
- return S.empty;
1291
- }
739
+ }), Mt = X("text", () => ({
740
+ group: "inline",
741
+ parseMarkdown: {
742
+ match: ({ type: r }) => r === "text",
743
+ runner: (r, e) => {
744
+ r.addText(e.value);
1292
745
  }
1293
- });
1294
- return e;
1295
- }, Y = /\[(?<span>((www|https:\/\/|http:\/\/)[^\s\]]+))]\((?<url>[^\s\]]+)\)/, vt = (a) => new RegExp(`\\\\(?=[^\\w\\s${a}\\\\]|_)`, "g"), At = (a) => {
1296
- let e = a, t = e.match(Y);
746
+ },
747
+ toMarkdown: {
748
+ match: (r) => r.type.name === "text",
749
+ runner: (r, e) => {
750
+ r.addNode("text", void 0, e.text);
751
+ }
752
+ }
753
+ })), It = [
754
+ Ze,
755
+ ge,
756
+ L,
757
+ G,
758
+ he,
759
+ T,
760
+ Ne,
761
+ x,
762
+ ye,
763
+ z,
764
+ Ie,
765
+ j,
766
+ Ae,
767
+ U,
768
+ we,
769
+ $,
770
+ ve,
771
+ Y,
772
+ Se,
773
+ E,
774
+ Te,
775
+ D,
776
+ ae,
777
+ se,
778
+ ce,
779
+ ie,
780
+ ue,
781
+ A,
782
+ me,
783
+ v,
784
+ Mt
785
+ ].flat(), bt = [
786
+ at,
787
+ gt,
788
+ ht,
789
+ lt,
790
+ pt,
791
+ nt
792
+ ].flat(), wt = [
793
+ fe,
794
+ Me,
795
+ M,
796
+ ke,
797
+ be,
798
+ Ce,
799
+ mt,
800
+ it,
801
+ dt,
802
+ Le,
803
+ xe,
804
+ De,
805
+ Oe,
806
+ _e,
807
+ le,
808
+ pe,
809
+ de,
810
+ Qe,
811
+ Xe
812
+ ], Nt = [
813
+ st,
814
+ ct,
815
+ ut,
816
+ ot,
817
+ yt,
818
+ kt,
819
+ ft,
820
+ et,
821
+ Ue,
822
+ Je,
823
+ Ye
824
+ ].flat(), B = /\[(?<span>((www|https:\/\/|http:\/\/)[^\s\]]+))]\((?<url>[^\s\]]+)\)/, Ct = (r) => new RegExp(`\\\\(?=[^\\w\\s${r}\\\\]|_)`, "g"), At = (r) => {
825
+ let e = r, t = e.match(B);
1297
826
  for (; t && t.groups; ) {
1298
- const { span: r } = t.groups;
1299
- e = e.replace(Y, r), t = e.match(Y);
827
+ const { span: n } = t.groups;
828
+ e = e.replace(B, n), t = e.match(B);
1300
829
  }
1301
830
  return e;
1302
- }, Et = (a, e, t) => {
1303
- const r = a.split(""), n = r[e];
1304
- return r[e] && r[t] && (r[e] = r[t], r[t] = n), r.join("").toString();
1305
- }, _t = (a) => (e) => e.replace(vt(a), ""), $t = (a) => (e) => {
1306
- const t = e.indexOf(a.hole), r = e.charAt(t - 1), n = e.charAt(t + 1), o = /[^\w]|_/;
1307
- return n ? r && o.test(r) && o.test(n) ? a.punctuation : a.char : a.punctuation;
1308
- }, Pt = (a, e, t) => {
1309
- let r = e, n = !1;
1310
- return a.descendants((o) => {
1311
- var l;
1312
- if (n)
831
+ }, vt = (r, e, t) => {
832
+ const n = r.split(""), o = n[e];
833
+ return n[e] && n[t] && (n[e] = n[t], n[t] = o), n.join("").toString();
834
+ }, xt = (r) => (e) => e.replace(Ct(r), ""), St = (r) => (e) => {
835
+ const t = e.indexOf(r.hole), n = e.charAt(t - 1), o = e.charAt(t + 1), a = /[^\w]|_/;
836
+ return o ? n && a.test(n) && a.test(o) ? r.punctuation : r.char : r.punctuation;
837
+ }, Lt = (r, e, t) => {
838
+ let n = e, o = !1;
839
+ return r.descendants((a) => {
840
+ var s;
841
+ if (o)
1313
842
  return !1;
1314
- if (o.isText) {
1315
- const s = (l = o.text) == null ? void 0 : l.indexOf(t);
1316
- if (s != null && s >= 0)
1317
- return n = !0, r += s, !1;
1318
- }
1319
- r += o.nodeSize;
1320
- }), r;
1321
- }, Bt = {
843
+ if (a.isText) {
844
+ const l = (s = a.text) == null ? void 0 : s.indexOf(t);
845
+ if (l != null && l >= 0)
846
+ return o = !0, n += l, !1;
847
+ }
848
+ n += a.nodeSize;
849
+ }), n;
850
+ }, Tt = {
1322
851
  placeholderConfig: {
1323
- hole: "\u2205",
1324
- punctuation: "\u2042",
1325
- char: "\u2234"
852
+ hole: "",
853
+ punctuation: "",
854
+ char: ""
1326
855
  },
1327
856
  globalNodes: ["footnote_definition"],
1328
- shouldSyncNode: ({ prevNode: a, nextNode: e }) => a.inlineContent && e && a.type === e.type && !a.eq(e),
1329
- movePlaceholder: (a, e) => {
857
+ shouldSyncNode: ({ prevNode: r, nextNode: e }) => r.inlineContent && e && r.type === e.type && !r.eq(e),
858
+ movePlaceholder: (r, e) => {
1330
859
  const t = ["*", "_"];
1331
- let r = e.indexOf(a);
1332
- for (; t.includes(e[r - 1] || "") && t.includes(e[r + 1] || ""); )
1333
- e = Et(e, r, r + 1), r = r + 1;
860
+ let n = e.indexOf(r);
861
+ for (; t.includes(e[n - 1] || "") && t.includes(e[n + 1] || ""); )
862
+ e = vt(e, n, n + 1), n = n + 1;
1334
863
  return e;
1335
864
  }
1336
- }, E = Ee(Bt, "inlineSyncConfig"), Rt = (a) => {
1337
- const { selection: e } = a, { $from: t } = e;
865
+ }, O = P(Tt, "inlineSyncConfig"), Dt = (r) => {
866
+ const { selection: e } = r, { $from: t } = e;
1338
867
  return t.node();
1339
- }, Wt = (a, e, t, r) => {
1340
- const n = a.get(_e), o = e.schema.topNodeType.create(void 0, [t, ...r]);
1341
- return n(o);
1342
- }, qt = (a, e) => {
1343
- const t = a.get(E), r = t.placeholderConfig.hole, [n = "", ...o] = e.split(`
868
+ }, Ot = (r, e, t, n) => {
869
+ const o = r.get(Re), a = e.schema.topNodeType.create(void 0, [t, ...n]);
870
+ return o(a);
871
+ }, _t = (r, e) => {
872
+ const t = r.get(O.key), n = t.placeholderConfig.hole, [o = "", ...a] = e.split(`
1344
873
 
1345
- `), l = (u) => t.movePlaceholder(r, u);
1346
- let c = Se(_t(r), l, At)(n);
1347
- const i = $t(t.placeholderConfig)(c);
1348
- return c = c.replace(r, i), c = [c, ...o].join(`
874
+ `), s = (d) => t.movePlaceholder(n, d);
875
+ let c = Be(xt(n), s, At)(o);
876
+ const i = St(t.placeholderConfig)(c);
877
+ return c = c.replace(n, i), c = [c, ...a].join(`
1349
878
 
1350
879
  `), [c, i];
1351
- }, Kt = (a, e) => {
1352
- const r = a.get($e)(e);
1353
- return r ? r.firstChild : null;
1354
- }, Ft = (a, e) => {
1355
- const { globalNodes: t } = a.get(E), r = [];
1356
- return e.doc.descendants((n) => {
1357
- if (t.includes(n.type.name) || t.includes(n.type))
1358
- return r.push(n), !1;
1359
- }), r;
1360
- }, jt = (a) => a.split(`
880
+ }, Ht = (r, e) => {
881
+ const n = r.get(Pe)(e);
882
+ return n ? n.firstChild : null;
883
+ }, Kt = (r, e) => {
884
+ const { globalNodes: t } = r.get(O.key), n = [];
885
+ return e.doc.descendants((o) => {
886
+ if (t.includes(o.type.name) || t.includes(o.type))
887
+ return n.push(o), !1;
888
+ }), n;
889
+ }, $t = (r) => r.split(`
1361
890
 
1362
- `)[0] || "", Oe = (a, e) => {
891
+ `)[0] || "", He = (r, e) => {
1363
892
  try {
1364
- const t = Ft(a, e), r = Rt(e), n = Wt(a, e, r, t), [o, l] = qt(a, n), s = Kt(a, o);
1365
- return !s || r.type !== s.type ? null : (s.attrs = { ...r.attrs }, s.descendants((c) => {
1366
- var f;
1367
- const u = c.marks.find((d) => d.type.name === "link");
1368
- u && ((f = c.text) == null ? void 0 : f.includes(l)) && u.attrs.href.includes(l) && (u.attrs.href = u.attrs.href.replace(l, ""));
893
+ const t = Kt(r, e), n = Dt(e), o = Ot(r, e, n, t), [a, s] = _t(r, o), l = Ht(r, a);
894
+ return !l || n.type !== l.type ? null : (l.attrs = { ...n.attrs }, l.descendants((c) => {
895
+ var p;
896
+ const d = c.marks.find((g) => g.type.name === "link");
897
+ d && ((p = c.text) == null ? void 0 : p.includes(s)) && d.attrs.href.includes(s) && (d.attrs.href = d.attrs.href.replace(s, ""));
1369
898
  }), {
1370
- text: jt(o),
1371
- prevNode: r,
1372
- nextNode: s,
1373
- placeholder: l
899
+ text: $t(a),
900
+ prevNode: n,
901
+ nextNode: l,
902
+ placeholder: s
1374
903
  });
1375
904
  } catch {
1376
905
  return null;
1377
906
  }
1378
- }, zt = (a, e, t, r, n) => {
1379
- const { placeholderConfig: o } = a.get(E), l = o.hole;
1380
- let s = t.tr.setMeta(e, !0).insertText(l, t.selection.from);
1381
- const c = t.apply(s), i = Oe(a, c);
907
+ }, Et = (r, e, t, n, o) => {
908
+ const { placeholderConfig: a } = r.get(O.key), s = a.hole;
909
+ let l = t.tr.setMeta(e, !0).insertText(s, t.selection.from);
910
+ const c = t.apply(l), i = He(r, c);
1382
911
  if (!i)
1383
912
  return;
1384
- const { $from: u } = c.selection, f = u.before(), d = u.after(), m = Pt(i.nextNode, f, i.placeholder);
1385
- s = s.replaceWith(f, d, i.nextNode).setNodeMarkup(f, void 0, n).delete(m + 1, m + 2), s = s.setSelection(Q.near(s.doc.resolve(m + 1))), r(s);
1386
- }, J = new H("MILKDOWN_INLINE_SYNC"), Ut = (a) => {
913
+ const { $from: d } = c.selection, p = d.before(), g = d.after(), h = Lt(i.nextNode, p, i.placeholder);
914
+ l = l.replaceWith(p, g, i.nextNode).setNodeMarkup(p, void 0, o).delete(h + 1, h + 2), l = l.setSelection(re.near(l.doc.resolve(h + 1))), n(l);
915
+ }, Bt = w((r) => {
1387
916
  let e = null;
1388
- return new T({
1389
- key: J,
917
+ const t = new N("MILKDOWN_INLINE_SYNC");
918
+ return new C({
919
+ key: t,
1390
920
  state: {
1391
921
  init: () => null,
1392
- apply: (r, n, o, l) => {
1393
- var p;
1394
- const s = a.get(v);
1395
- if (!((p = s.hasFocus) != null && p.call(s)) || !s.editable || !r.docChanged || r.getMeta(J))
922
+ apply: (n, o, a, s) => {
923
+ var _;
924
+ const l = r.get(R);
925
+ if (!((_ = l.hasFocus) != null && _.call(l)) || !l.editable || !n.docChanged || n.getMeta(t))
1396
926
  return null;
1397
- const i = Oe(a, l);
927
+ const i = He(r, s);
1398
928
  if (!i)
1399
929
  return null;
1400
930
  e && (cancelAnimationFrame(e), e = null);
1401
- const { prevNode: u, nextNode: f, text: d } = i, { shouldSyncNode: m } = a.get(E);
1402
- return m({ prevNode: u, nextNode: f, ctx: a, tr: r, text: d }) && (e = requestAnimationFrame(() => {
931
+ const { prevNode: d, nextNode: p, text: g } = i, { shouldSyncNode: h } = r.get(O.key);
932
+ return h({ prevNode: d, nextNode: p, ctx: r, tr: n, text: g }) && (e = requestAnimationFrame(() => {
1403
933
  e = null;
1404
- const { dispatch: g, state: h } = a.get(v);
1405
- zt(a, J, h, g, u.attrs);
934
+ const { dispatch: $e, state: Ee } = r.get(R);
935
+ Et(r, t, Ee, $e, d.attrs);
1406
936
  })), null;
1407
937
  }
1408
938
  }
1409
939
  });
1410
- }, Vt = [
1411
- ve(() => ({
1412
- injectSlices: [E],
1413
- prosePlugins: (a, e) => [St(), Ut(e)],
1414
- remarkPlugins: () => [Ve, Dt, Ct]
1415
- }))()
1416
- ], Gt = we.create([...Lt, ...et]), cr = we.create([...Vt, ...Gt]), ir = {
1417
- ToggleInlineCode: ee,
1418
- ToggleItalic: te,
1419
- ToggleLink: Te,
1420
- ToggleBold: ne,
1421
- ModifyLink: re,
1422
- ModifyImage: ce,
1423
- WrapInBlockquote: se,
1424
- WrapInBulletList: oe,
1425
- WrapInOrderedList: fe,
1426
- TurnIntoCodeFence: ae,
1427
- TurnIntoHeading: O,
1428
- TurnIntoText: me,
1429
- InsertHardbreak: le,
1430
- InsertHr: He,
1431
- InsertImage: De,
1432
- SplitListItem: ie,
1433
- SinkListItem: ue,
1434
- LiftListItem: de
1435
- };
940
+ }), Rt = W(() => () => (r) => {
941
+ oe(r, "list", (e) => {
942
+ if (e.ordered) {
943
+ const t = e.start ?? 1;
944
+ e.children.forEach((n, o) => {
945
+ n.label = o + t;
946
+ });
947
+ }
948
+ });
949
+ }), Pt = W(() => () => (r) => {
950
+ const e = /[\t ]*(?:\r?\n|\r)/g;
951
+ oe(r, "text", (t, n, o) => {
952
+ if (!t.value || typeof t.value != "string")
953
+ return;
954
+ const a = [];
955
+ let s = 0;
956
+ e.lastIndex = 0;
957
+ let l = e.exec(t.value);
958
+ for (; l; ) {
959
+ const i = l.index;
960
+ s !== i && a.push({ type: "text", value: t.value.slice(s, i) }), a.push({ type: "break", data: { isInline: !0 } }), s = i + l[0].length, l = e.exec(t.value);
961
+ }
962
+ if (!!(a.length > 0 && o && typeof n == "number"))
963
+ return s < t.value.length && a.push({ type: "text", value: t.value.slice(s) }), o.children.splice(n, 1, ...a), n + a.length;
964
+ });
965
+ }), Wt = W(() => je), qt = w(() => {
966
+ let r = !1;
967
+ const e = new N("MILKDOWN_INLINE_NODES_CURSOR"), t = new C({
968
+ key: e,
969
+ state: {
970
+ init() {
971
+ return !1;
972
+ },
973
+ apply(n) {
974
+ if (!n.selection.empty)
975
+ return !1;
976
+ const o = n.selection.$from, a = o.nodeBefore, s = o.nodeAfter;
977
+ return !!(a && s && a.isInline && !a.isText && s.isInline && !s.isText);
978
+ }
979
+ },
980
+ props: {
981
+ handleDOMEvents: {
982
+ compositionend: (n, o) => r ? (r = !1, requestAnimationFrame(() => {
983
+ if (t.getState(n.state)) {
984
+ const s = n.state.selection.from;
985
+ o.preventDefault(), n.dispatch(n.state.tr.insertText(o.data || "", s));
986
+ }
987
+ }), !0) : !1,
988
+ compositionstart: (n) => (t.getState(n.state) && (r = !0), !1),
989
+ beforeinput: (n, o) => {
990
+ if (t.getState(n.state) && o instanceof InputEvent && o.data && !r) {
991
+ const s = n.state.selection.from;
992
+ return o.preventDefault(), n.dispatch(n.state.tr.insertText(o.data || "", s)), !0;
993
+ }
994
+ return !1;
995
+ }
996
+ },
997
+ decorations(n) {
998
+ if (t.getState(n)) {
999
+ const s = n.selection.$from.pos, l = document.createElement("span"), c = J.widget(s, l, {
1000
+ side: -1
1001
+ }), i = document.createElement("span"), d = J.widget(s, i);
1002
+ return setTimeout(() => {
1003
+ l.contentEditable = "true", i.contentEditable = "true";
1004
+ }), Q.create(n.doc, [c, d]);
1005
+ }
1006
+ return Q.empty;
1007
+ }
1008
+ }
1009
+ });
1010
+ return t;
1011
+ }), Ft = w(() => new C({
1012
+ key: new N("MILKDOWN_HARDBREAK_MARKS"),
1013
+ appendTransaction: (r, e, t) => {
1014
+ if (!r.length)
1015
+ return;
1016
+ const [n] = r;
1017
+ if (!n)
1018
+ return;
1019
+ const [o] = n.steps;
1020
+ if (n.getMeta("hardbreak")) {
1021
+ if (!(o instanceof Ge))
1022
+ return;
1023
+ const { from: l } = o;
1024
+ return t.tr.setNodeMarkup(l, x.type(), void 0, []);
1025
+ }
1026
+ if (o instanceof ze) {
1027
+ let l = t.tr;
1028
+ const { from: c, to: i } = o;
1029
+ return t.doc.nodesBetween(c, i, (d, p) => {
1030
+ d.type === x.type() && (l = l.setNodeMarkup(p, x.type(), void 0, []));
1031
+ }), l;
1032
+ }
1033
+ }
1034
+ })), Ke = P(["table", "code_block"], "hardbreakFilterNodes"), Vt = w((r) => {
1035
+ const e = r.get(Ke.key);
1036
+ return new C({
1037
+ key: new N("MILKDOWN_HARDBREAK_FILTER"),
1038
+ filterTransaction: (t, n) => {
1039
+ const o = t.getMeta("hardbreak"), [a] = t.steps;
1040
+ if (o && a) {
1041
+ const { from: s } = a, l = n.doc.resolve(s);
1042
+ let c = l.depth, i = !0;
1043
+ for (; c > 0; )
1044
+ e.includes(l.node(c).type.name) && (i = !1), c--;
1045
+ return i;
1046
+ }
1047
+ return !0;
1048
+ }
1049
+ });
1050
+ }), Gt = w((r) => {
1051
+ const e = new N("MILKDOWN_HEADING_ID"), t = (n) => {
1052
+ if (n.composing || !n.editable)
1053
+ return;
1054
+ const o = r.get(G.key), a = n.state.tr.setMeta("addToHistory", !1);
1055
+ let s = !1;
1056
+ n.state.doc.descendants((l, c) => {
1057
+ if (l.type === T.type()) {
1058
+ if (l.textContent.trim().length === 0)
1059
+ return;
1060
+ const i = l.attrs, d = o(l);
1061
+ i.id !== d && (s = !0, a.setMeta(e, !0).setNodeMarkup(c, void 0, {
1062
+ ...i,
1063
+ id: d
1064
+ }));
1065
+ }
1066
+ }), s && n.dispatch(a);
1067
+ };
1068
+ return new C({
1069
+ key: e,
1070
+ view: (n) => (t(n), {
1071
+ update: (o) => {
1072
+ t(o);
1073
+ }
1074
+ })
1075
+ });
1076
+ }), zt = w(() => {
1077
+ const r = (e, t) => {
1078
+ const n = E.type(), o = D.type();
1079
+ let a = e.tr;
1080
+ e.doc.descendants((s, l, c, i) => {
1081
+ if (s.type === o && (c == null ? void 0 : c.type) === n) {
1082
+ let d = !1;
1083
+ const p = { ...s.attrs };
1084
+ s.attrs.listType !== "ordered" && (p.listType = "ordered", d = !0);
1085
+ const g = c == null ? void 0 : c.maybeChild(0);
1086
+ g === s ? (p.label = "1.", d = !0) : (g == null ? void 0 : g.type) === o && g.attrs.listType === "ordered" ? (p.label = `${i + 1}.`, d = !0) : s.attrs.label === "•" && (p.label = `${i + 1}.`, d = !0), d && (a = a.setNodeMarkup(l, void 0, p));
1087
+ }
1088
+ }), t(a);
1089
+ };
1090
+ return new C({
1091
+ key: new N("MILKDOWN_KEEP_LIST_ORDER"),
1092
+ appendTransaction: (e, t, n) => {
1093
+ let o = null;
1094
+ return e.some((a) => a.docChanged) && r(n, (a) => {
1095
+ o = a;
1096
+ }), o;
1097
+ }
1098
+ });
1099
+ }), jt = [
1100
+ O,
1101
+ Bt,
1102
+ Ft,
1103
+ Ke,
1104
+ Vt,
1105
+ qt,
1106
+ Rt,
1107
+ Wt,
1108
+ Pt,
1109
+ Gt,
1110
+ zt
1111
+ ], ir = [It, bt, wt, Nt, jt].flat();
1436
1112
  export {
1437
- ye as DowngradeHeading,
1438
- ct as HardbreakFilterPluginKey,
1439
- le as InsertHardbreak,
1440
- He as InsertHr,
1441
- De as InsertImage,
1442
- de as LiftListItem,
1443
- ce as ModifyImage,
1444
- re as ModifyLink,
1445
- ue as SinkListItem,
1446
- ie as SplitListItem,
1447
- y as SupportedKeys,
1448
- ne as ToggleBold,
1449
- ee as ToggleInlineCode,
1450
- te as ToggleItalic,
1451
- Te as ToggleLink,
1452
- ae as TurnIntoCodeFence,
1453
- O as TurnIntoHeading,
1454
- me as TurnIntoText,
1455
- se as WrapInBlockquote,
1456
- oe as WrapInBulletList,
1457
- fe as WrapInOrderedList,
1458
- st as backtickInputRegex,
1459
- tt as blockquote,
1460
- rt as bulletList,
1461
- at as codeFence,
1462
- Ye as codeInline,
1463
- ir as commands,
1464
- cr as commonmark,
1465
- Gt as commonmarkNodes,
1466
- Vt as commonmarkPlugins,
1467
- lt as doc,
1468
- Je as em,
1469
- it as hardbreak,
1470
- pt as heading,
1471
- ut as headingHashPluginKey,
1472
- V as headingIdPluginKey,
1473
- gt as hr,
1474
- kt as image,
1475
- E as inlineSyncConfigCtx,
1476
- Xe as link,
1477
- Nt as listItem,
1478
- et as marks,
1479
- Lt as nodes,
1480
- It as orderedList,
1481
- bt as paragraph,
1482
- Ze as strong,
1483
- wt as text,
1484
- ot as tildeInputRegex
1113
+ ye as blockquoteAttr,
1114
+ st as blockquoteKeymap,
1115
+ z as blockquoteSchema,
1116
+ ve as bulletListAttr,
1117
+ ft as bulletListKeymap,
1118
+ Y as bulletListSchema,
1119
+ Ie as codeBlockAttr,
1120
+ ct as codeBlockKeymap,
1121
+ j as codeBlockSchema,
1122
+ wt as commands,
1123
+ ir as commonmark,
1124
+ be as createCodeBlockCommand,
1125
+ lt as createCodeBlockInputRule,
1126
+ Tt as defaultConfig,
1127
+ Ze as docSchema,
1128
+ ke as downgradeHeadingCommand,
1129
+ ae as emphasisAttr,
1130
+ Ue as emphasisKeymap,
1131
+ se as emphasisSchema,
1132
+ Ne as hardbreakAttr,
1133
+ Ft as hardbreakClearMarkPlugin,
1134
+ Ke as hardbreakFilterNodes,
1135
+ Vt as hardbreakFilterPlugin,
1136
+ ut as hardbreakKeymap,
1137
+ x as hardbreakSchema,
1138
+ he as headingAttr,
1139
+ G as headingIdGenerator,
1140
+ ot as headingKeymap,
1141
+ T as headingSchema,
1142
+ Ae as hrAttr,
1143
+ U as hrSchema,
1144
+ we as imageAttr,
1145
+ $ as imageSchema,
1146
+ ue as inlineCodeAttr,
1147
+ Je as inlineCodeKeymap,
1148
+ A as inlineCodeSchema,
1149
+ qt as inlineNodesCursorPlugin,
1150
+ O as inlineSyncConfig,
1151
+ Bt as inlineSyncPlugin,
1152
+ bt as inputrules,
1153
+ Ce as insertHardbreakCommand,
1154
+ mt as insertHrCommand,
1155
+ pt as insertHrInputRule,
1156
+ it as insertImageCommand,
1157
+ cr as insertImageInputRule,
1158
+ Nt as keymap,
1159
+ _e as liftListItemCommand,
1160
+ me as linkAttr,
1161
+ v as linkSchema,
1162
+ Te as listItemAttr,
1163
+ yt as listItemKeymap,
1164
+ D as listItemSchema,
1165
+ Se as orderedListAttr,
1166
+ kt as orderedListKeymap,
1167
+ E as orderedListSchema,
1168
+ ge as paragraphAttr,
1169
+ et as paragraphKeymap,
1170
+ L as paragraphSchema,
1171
+ jt as plugins,
1172
+ Rt as remarkAddOrderInListPlugin,
1173
+ Wt as remarkInlineLinkPlugin,
1174
+ Pt as remarkLineBreak,
1175
+ It as schema,
1176
+ De as sinkListItemCommand,
1177
+ Oe as splitListItemCommand,
1178
+ ce as strongAttr,
1179
+ Ye as strongKeymap,
1180
+ ie as strongSchema,
1181
+ Gt as syncHeadingIdPlugin,
1182
+ zt as syncListOrderPlugin,
1183
+ Mt as textSchema,
1184
+ le as toggleEmphasisCommand,
1185
+ pe as toggleInlineCodeCommand,
1186
+ Qe as toggleLinkCommand,
1187
+ de as toggleStrongCommand,
1188
+ fe as turnIntoTextCommand,
1189
+ lr as updateCodeBlockLanguageCommand,
1190
+ dt as updateImageCommand,
1191
+ Xe as updateLinkCommand,
1192
+ Me as wrapInBlockquoteCommand,
1193
+ at as wrapInBlockquoteInputRule,
1194
+ xe as wrapInBulletListCommand,
1195
+ gt as wrapInBulletListInputRule,
1196
+ M as wrapInHeadingCommand,
1197
+ nt as wrapInHeadingInputRule,
1198
+ Le as wrapInOrderedListCommand,
1199
+ ht as wrapInOrderedListInputRule
1485
1200
  };
1486
1201
  //# sourceMappingURL=index.es.js.map