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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) 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 +3 -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 +1099 -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-plugin.d.ts +2 -0
  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 +31 -0
  87. package/src/composed/index.ts +6 -0
  88. package/src/composed/inputrules.ts +13 -0
  89. package/src/composed/keymap.ts +20 -0
  90. package/src/composed/plugins.ts +23 -0
  91. package/src/composed/schema.ts +55 -0
  92. package/src/index.ts +6 -52
  93. package/src/mark/emphasis.ts +47 -0
  94. package/src/mark/index.ts +3 -10
  95. package/src/mark/inline-code.ts +70 -0
  96. package/src/mark/link.ts +96 -247
  97. package/src/mark/strong.ts +41 -36
  98. package/src/node/blockquote.ts +39 -33
  99. package/src/node/bullet-list.ts +62 -55
  100. package/src/node/code-block.ts +103 -0
  101. package/src/node/doc.ts +18 -22
  102. package/src/node/hardbreak.ts +68 -117
  103. package/src/node/heading.ts +175 -284
  104. package/src/node/hr.ts +57 -57
  105. package/src/node/image.ts +113 -209
  106. package/src/node/index.ts +6 -35
  107. package/src/node/list-item.ts +125 -141
  108. package/src/node/ordered-list.ts +70 -65
  109. package/src/node/paragraph.ts +54 -50
  110. package/src/node/text.ts +14 -16
  111. package/src/plugin/hardbreak-clear-mark-plugin.ts +45 -0
  112. package/src/plugin/hardbreak-filter-plugin.ts +33 -0
  113. package/src/plugin/index.ts +12 -14
  114. package/src/plugin/{inline-nodes-cursor.ts → inline-nodes-cursor-plugin.ts} +5 -8
  115. package/src/plugin/{inline-sync → inline-sync-plugin}/config.ts +18 -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} +14 -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 +16 -0
  123. package/src/plugin/remark-inline-link-plugin.ts +6 -0
  124. package/src/plugin/remark-line-break.ts +44 -0
  125. package/src/plugin/sync-heading-id-plugin.ts +55 -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 +0 -7
  138. package/lib/plugin/inline-nodes-cursor.d.ts.map +0 -1
  139. package/lib/plugin/inline-sync/config.d.ts.map +0 -1
  140. package/lib/plugin/inline-sync/context.d.ts.map +0 -1
  141. package/lib/plugin/inline-sync/index.d.ts +0 -6
  142. package/lib/plugin/inline-sync/index.d.ts.map +0 -1
  143. package/lib/plugin/inline-sync/regexp.d.ts.map +0 -1
  144. package/lib/plugin/inline-sync/replacer.d.ts.map +0 -1
  145. package/lib/plugin/inline-sync/utils.d.ts.map +0 -1
  146. package/lib/supported-keys.d.ts +0 -23
  147. package/lib/supported-keys.d.ts.map +0 -1
  148. package/src/mark/code-inline.ts +0 -66
  149. package/src/mark/em.ts +0 -42
  150. package/src/node/code-fence.ts +0 -245
  151. package/src/plugin/add-order-in-list.ts +0 -19
  152. package/src/plugin/filter-html.ts +0 -43
  153. package/src/supported-keys.ts +0 -25
  154. package/src/types.d.ts +0 -5
package/lib/index.es.js CHANGED
@@ -1,1486 +1,1199 @@
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, liftListItem as Fe, splitListItem 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((r) => ee(/^(?<hashes>#+)\s$/, T.type(), (e) => {
253
+ var s, l;
254
+ 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();
255
+ if (a.type.name === "heading") {
256
+ let c = Number(a.attrs.level) + Number(t);
257
+ return c > 6 && (c = 6), { level: c };
258
+ }
259
+ return { level: t };
260
+ })), M = u("WrapInHeading", () => (r) => (r ?? (r = 1), r < 1 ? S(L.type()) : S(T.type(), { level: r }))), ke = u("DowngradeHeading", () => () => (r, e, t) => {
261
+ const { $from: n } = r.selection, o = n.node();
262
+ if (o.type !== T.type() || !r.selection.empty || n.parentOffset !== 0)
263
+ return !1;
264
+ const a = o.attrs.level - 1;
265
+ return a ? (e == null || e(
266
+ r.tr.setNodeMarkup(r.selection.$from.before(), void 0, {
267
+ ...o.attrs,
268
+ level: a
921
269
  })
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;
270
+ ), !0) : S(L.type())(r, e, t);
271
+ }), ot = f("headingKeymap", {
272
+ TurnIntoH1: {
273
+ shortcuts: "Mod-Alt-1",
274
+ command: (r) => {
275
+ const e = r.get(m);
276
+ return () => e.call(M.key, 1);
277
+ }
278
+ },
279
+ TurnIntoH2: {
280
+ shortcuts: "Mod-Alt-2",
281
+ command: (r) => {
282
+ const e = r.get(m);
283
+ return () => e.call(M.key, 2);
284
+ }
285
+ },
286
+ TurnIntoH3: {
287
+ shortcuts: "Mod-Alt-3",
288
+ command: (r) => {
289
+ const e = r.get(m);
290
+ return () => e.call(M.key, 3);
291
+ }
292
+ },
293
+ TurnIntoH4: {
294
+ shortcuts: "Mod-Alt-4",
295
+ command: (r) => {
296
+ const e = r.get(m);
297
+ return () => e.call(M.key, 3);
298
+ }
299
+ },
300
+ TurnIntoH5: {
301
+ shortcuts: "Mod-Alt-5",
302
+ command: (r) => {
303
+ const e = r.get(m);
304
+ return () => e.call(M.key, 3);
305
+ }
306
+ },
307
+ TurnIntoH6: {
308
+ shortcuts: "Mod-Alt-6",
309
+ command: (r) => {
310
+ const e = r.get(m);
311
+ return () => e.call(M.key, 3);
312
+ }
313
+ },
314
+ DowngradeHeading: {
315
+ shortcuts: ["Delete", "Backspace"],
316
+ command: (r) => {
317
+ const e = r.get(m);
318
+ return () => e.call(ke.key);
319
+ }
320
+ }
321
+ }), ye = k("blockquote"), z = y("blockquote", (r) => ({
322
+ content: "block+",
323
+ group: "block",
324
+ defining: !0,
325
+ parseDOM: [{ tag: "blockquote" }],
326
+ toDOM: (e) => ["blockquote", r.get(ye.key)(e), 0],
327
+ parseMarkdown: {
328
+ match: ({ type: e }) => e === "blockquote",
329
+ runner: (e, t, n) => {
330
+ e.openNode(n).next(t.children).closeNode();
331
+ }
332
+ },
333
+ toMarkdown: {
334
+ match: (e) => e.type.name === "blockquote",
335
+ runner: (e, t) => {
336
+ e.openNode("blockquote").next(t.content).closeNode();
337
+ }
338
+ }
339
+ })), at = I(() => V(/^\s*>\s$/, z.type())), Me = u("WrapInBlockquote", () => () => F(z.type())), st = f("blockquoteKeymap", {
340
+ WrapInBlockquote: {
341
+ shortcuts: "Mod-Shift-b",
342
+ command: (r) => {
343
+ const e = r.get(m);
344
+ return () => e.call(Me.key);
345
+ }
346
+ }
347
+ }), Ie = k("codeBlock", () => ({
348
+ pre: {},
349
+ code: {}
350
+ })), j = y("code_block", (r) => ({
351
+ content: "text*",
352
+ group: "block",
353
+ marks: "",
354
+ defining: !0,
355
+ code: !0,
356
+ attrs: {
357
+ language: {
358
+ default: ""
359
+ }
360
+ },
361
+ parseDOM: [
362
+ {
363
+ tag: "pre",
364
+ preserveWhitespace: "full",
365
+ getAttrs: (e) => {
366
+ if (!(e instanceof HTMLElement))
367
+ throw b(e);
368
+ return { language: e.dataset.language };
929
369
  }
930
- )
370
+ }
931
371
  ],
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");
372
+ toDOM: (e) => {
373
+ const t = r.get(Ie.key)(e);
374
+ return [
375
+ "pre",
376
+ {
377
+ ...t.pre,
378
+ "data-language": e.attrs.language
947
379
  },
948
- deselectNode: () => {
949
- s.classList.remove("ProseMirror-selectednode");
950
- }
951
- };
380
+ ["code", t.code, 0]
381
+ ];
952
382
  },
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);
383
+ parseMarkdown: {
384
+ match: ({ type: e }) => e === "code",
385
+ runner: (e, t, n) => {
386
+ const o = t.lang, a = t.value;
387
+ e.openNode(n, { language: o }), a && e.addText(a), e.closeNode();
388
+ }
389
+ },
390
+ toMarkdown: {
391
+ match: (e) => e.type.name === "code_block",
392
+ runner: (e, t) => {
393
+ var n;
394
+ e.addNode("code", void 0, ((n = t.content.firstChild) == null ? void 0 : n.text) || "", {
395
+ lang: t.attrs.language
396
+ });
397
+ }
398
+ }
399
+ })), lt = I(() => ee(/^```(?<language>[a-z]*)?[\s\n]$/, j.type(), (r) => {
400
+ var e;
401
+ return {
402
+ language: ((e = r.groups) == null ? void 0 : e.language) ?? ""
1001
403
  };
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;
404
+ })), 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", {
405
+ CreateCodeBlock: {
406
+ shortcuts: "Mod-Alt-c",
407
+ command: (r) => {
408
+ const e = r.get(m);
409
+ return () => e.call(be.key);
1009
410
  }
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();
411
+ }
412
+ }), we = k("image"), $ = y("image", (r) => ({
413
+ inline: !0,
414
+ group: "inline",
415
+ selectable: !0,
416
+ draggable: !0,
417
+ marks: "",
418
+ atom: !0,
419
+ defining: !0,
420
+ isolating: !0,
421
+ attrs: {
422
+ src: { default: "" },
423
+ alt: { default: "" },
424
+ title: { default: "" }
425
+ },
426
+ parseDOM: [
427
+ {
428
+ tag: "img[src]",
429
+ getAttrs: (e) => {
430
+ if (!(e instanceof HTMLElement))
431
+ throw b(e);
432
+ return {
433
+ src: e.getAttribute("src") || "",
434
+ alt: e.getAttribute("alt") || "",
435
+ title: e.getAttribute("title") || e.getAttribute("alt") || ""
436
+ };
1071
437
  }
1072
438
  }
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
439
  ],
1080
- shortcuts: {
1081
- [y.NextListItem]: M(ie, "Enter"),
1082
- [y.SinkListItem]: M(ue, "Mod-]"),
1083
- [y.LiftListItem]: M(de, "Mod-[")
440
+ toDOM: (e) => ["img", { ...r.get(we.key)(e), ...e.attrs }],
441
+ parseMarkdown: {
442
+ match: ({ type: e }) => e === "image",
443
+ runner: (e, t, n) => {
444
+ const o = t.url, a = t.alt, s = t.title;
445
+ e.addNode(n, {
446
+ src: o,
447
+ alt: a,
448
+ title: s
449
+ });
450
+ }
1084
451
  },
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
452
+ toMarkdown: {
453
+ match: (e) => e.type.name === "image",
454
+ runner: (e, t) => {
455
+ e.addNode("image", void 0, void 0, {
456
+ title: t.attrs.title,
457
+ url: t.attrs.src,
458
+ alt: t.attrs.alt
459
+ });
460
+ }
461
+ }
462
+ })), it = u("InsertImage", () => (r = {}) => (e, t) => {
463
+ if (!t)
464
+ return !0;
465
+ const { src: n = "", alt: o = "", title: a = "" } = r, s = $.type().create({ src: n, alt: o, title: a });
466
+ return s && t(e.tr.replaceSelectionWith(s).scrollIntoView()), !0;
467
+ }), dt = u("UpdateImage", () => (r = {}) => (e, t) => {
468
+ const n = We(e.selection, $.type());
469
+ if (!n)
470
+ return !1;
471
+ const { node: o, pos: a } = n, s = { ...o.attrs }, { src: l, alt: c, title: i } = r;
472
+ 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;
473
+ }), cr = I(() => new te(
474
+ /!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/,
475
+ (r, e, t, n) => {
476
+ const [o, a, s = "", l] = e;
477
+ return o ? r.tr.replaceWith(t, n, $.type().create({ src: s, alt: a, title: l })) : null;
478
+ }
479
+ )), Ne = k("hardbreak", (r) => ({
480
+ "data-is-inline": r.attrs.isInline
481
+ })), x = y("hardbreak", (r) => ({
482
+ inline: !0,
483
+ group: "inline",
484
+ attrs: {
485
+ isInline: {
486
+ default: !1
487
+ }
488
+ },
489
+ selectable: !1,
490
+ parseDOM: [{ tag: "br" }],
491
+ toDOM: (e) => ["br", r.get(Ne.key)(e)],
492
+ parseMarkdown: {
493
+ match: ({ type: e }) => e === "break",
494
+ runner: (e, t, n) => {
495
+ var o;
496
+ e.addNode(n, { isInline: Boolean((o = t.data) == null ? void 0 : o.isInline) });
497
+ }
498
+ },
499
+ toMarkdown: {
500
+ match: (e) => e.type.name === "hardbreak",
501
+ runner: (e, t) => {
502
+ t.attrs.isInline ? e.addNode("text", void 0, `
503
+ `) : e.addNode("break");
504
+ }
505
+ }
506
+ })), Ce = u("InsertHardbreak", () => () => (r, e) => {
507
+ var o;
508
+ const { selection: t, tr: n } = r;
509
+ if (t.empty) {
510
+ const a = t.$from.node();
511
+ if (a.childCount > 0 && ((o = a.lastChild) == null ? void 0 : o.type.name) === "hardbreak")
512
+ return e == null || e(
513
+ n.replaceRangeWith(t.to - 1, t.to, r.schema.node("paragraph")).setSelection(ne.near(n.doc.resolve(t.to))).scrollIntoView()
514
+ ), !0;
515
+ }
516
+ return e == null || e(n.setMeta("hardbreak", !0).replaceSelectionWith(x.type().create()).scrollIntoView()), !0;
517
+ }), ut = f("hardbreakKeymap", {
518
+ InsertHardbreak: {
519
+ shortcuts: "Shift-Enter",
520
+ command: (r) => {
521
+ const e = r.get(m);
522
+ return () => e.call(Ce.key);
523
+ }
524
+ }
525
+ }), Ae = k("hr"), U = y("hr", (r) => ({
526
+ group: "block",
527
+ parseDOM: [{ tag: "hr" }],
528
+ toDOM: (e) => ["hr", r.get(Ae.key)(e)],
529
+ parseMarkdown: {
530
+ match: ({ type: e }) => e === "thematicBreak",
531
+ runner: (e, t, n) => {
532
+ e.addNode(n);
533
+ }
534
+ },
535
+ toMarkdown: {
536
+ match: (e) => e.type.name === "hr",
537
+ runner: (e) => {
538
+ e.addNode("thematicBreak");
539
+ }
540
+ }
541
+ })), pt = I(() => new te(
542
+ /^(?:---|___\s|\*\*\*\s)$/,
543
+ (r, e, t, n) => {
544
+ const { tr: o } = r;
545
+ return e[0] && o.replaceWith(t - 1, n, U.type().create()), o;
546
+ }
547
+ )), mt = u("InsertHr", () => () => (r, e) => {
548
+ if (!e)
549
+ return !0;
550
+ const t = L.node.type().create(), { tr: n, selection: o } = r, { from: a } = o, s = U.type().create();
551
+ if (!s)
552
+ return !0;
553
+ const l = n.replaceSelectionWith(s).insert(a, t), c = ne.findFrom(l.doc.resolve(a), 1, !0);
554
+ return c && e(l.setSelection(c).scrollIntoView()), !0;
555
+ }), ve = k("bulletList"), Y = y("bullet_list", (r) => ({
556
+ content: "listItem+",
557
+ group: "block",
558
+ attrs: {
559
+ spread: {
560
+ default: !1
561
+ }
562
+ },
563
+ parseDOM: [
564
+ {
565
+ tag: "ul",
566
+ getAttrs: (e) => {
567
+ if (!(e instanceof HTMLElement))
568
+ throw b(e);
569
+ return {
570
+ spread: e.dataset.spread
571
+ };
1097
572
  }
573
+ }
574
+ ],
575
+ toDOM: (e) => [
576
+ "ul",
577
+ {
578
+ ...r.get(ve.key)(e),
579
+ "data-spread": e.attrs.spread
1098
580
  },
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
- }
581
+ 0
582
+ ],
583
+ parseMarkdown: {
584
+ match: ({ type: e, ordered: t }) => e === "list" && !t,
585
+ runner: (e, t, n) => {
586
+ const o = t.spread != null ? `${t.spread}` : "false";
587
+ e.openNode(n, { spread: o }).next(t.children).closeNode();
588
+ }
589
+ },
590
+ toMarkdown: {
591
+ match: (e) => e.type.name === "bullet_list",
592
+ runner: (e, t) => {
593
+ e.openNode("list", void 0, { ordered: !1, spread: t.attrs.spread === "true" }).next(t.content).closeNode();
594
+ }
595
+ }
596
+ })), gt = I(() => V(/^\s*([-+*])\s$/, Y.type())), xe = u("WrapInBulletList", () => () => F(Y.type())), ft = f("bulletListKeymap", {
597
+ WrapInBulletList: {
598
+ shortcuts: "Mod-Alt-8",
599
+ command: (r) => {
600
+ const e = r.get(m);
601
+ return () => e.call(xe.key);
602
+ }
603
+ }
604
+ }), Se = k("orderedList"), E = y("ordered_list", (r) => ({
605
+ content: "listItem+",
606
+ group: "block",
607
+ attrs: {
608
+ order: {
609
+ default: 1
1127
610
  },
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();
611
+ spread: {
612
+ default: !1
613
+ }
614
+ },
615
+ parseDOM: [
616
+ {
617
+ tag: "ol",
618
+ getAttrs: (e) => {
619
+ if (!(e instanceof HTMLElement))
620
+ throw b(e);
621
+ return {
622
+ spread: e.dataset.spread,
623
+ order: e.hasAttribute("start") ? Number(e.getAttribute("start")) : 1
624
+ };
1132
625
  }
1133
626
  }
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
627
  ],
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
- }
628
+ toDOM: (e) => [
629
+ "ol",
630
+ {
631
+ ...r.get(Se.key)(e),
632
+ ...e.attrs.order === 1 ? {} : e.attrs.order,
633
+ "data-spread": e.attrs.spread
1159
634
  },
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
- }
635
+ 0
636
+ ],
637
+ parseMarkdown: {
638
+ match: ({ type: e, ordered: t }) => e === "list" && !!t,
639
+ runner: (e, t, n) => {
640
+ const o = t.spread != null ? `${t.spread}` : "true";
641
+ e.openNode(n, { spread: o }).next(t.children).closeNode();
642
+ }
643
+ },
644
+ toMarkdown: {
645
+ match: (e) => e.type.name === "ordered_list",
646
+ runner: (e, t) => {
647
+ e.openNode("list", void 0, { ordered: !0, start: 1, spread: t.attrs.spread === "true" }), e.next(t.content), e.closeNode();
1173
648
  }
1174
- }),
1175
- commands: (e) => [N(me, () => A(e))],
1176
- shortcuts: {
1177
- [y.Text]: M(me, "Mod-Alt-0")
1178
649
  }
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
- }
650
+ })), ht = I(() => V(
651
+ /^\s*(\d+)\.\s$/,
652
+ E.type(),
653
+ (r) => ({ order: Number(r[1]) }),
654
+ (r, e) => e.childCount + e.attrs.order === Number(r[1])
655
+ )), Le = u("WrapInOrderedList", () => () => F(E.type())), kt = f("orderedListKeymap", {
656
+ WrapInOrderedList: {
657
+ shortcuts: "Mod-Alt-7",
658
+ command: (r) => {
659
+ const e = r.get(m);
660
+ return () => e.call(Le.key);
1194
661
  }
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
662
  }
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
- }
663
+ }), Te = k("listItem"), D = y("list_item", (r) => ({
664
+ group: "listItem",
665
+ content: "paragraph block*",
666
+ attrs: {
667
+ label: {
668
+ default: "•"
669
+ },
670
+ listType: {
671
+ default: "bullet"
672
+ },
673
+ spread: {
674
+ default: "true"
675
+ }
676
+ },
677
+ defining: !0,
678
+ parseDOM: [
679
+ {
680
+ tag: "li",
681
+ getAttrs: (e) => {
682
+ if (!(e instanceof HTMLElement))
683
+ throw b(e);
684
+ return {
685
+ label: e.dataset.label,
686
+ listType: e.dataset["list-type"],
687
+ spread: e.dataset.spread
688
+ };
1238
689
  }
1239
- r.children = l;
1240
690
  }
1241
- return e(r, n, o);
691
+ ],
692
+ toDOM: (e) => [
693
+ "li",
694
+ {
695
+ ...r.get(Te.key)(e),
696
+ "data-label": e.attrs.label,
697
+ "data-list-type": e.attrs.listType,
698
+ "data-spread": e.attrs.spread
699
+ },
700
+ 0
701
+ ],
702
+ parseMarkdown: {
703
+ match: ({ type: e }) => e === "listItem",
704
+ runner: (e, t, n) => {
705
+ const o = t.label != null ? `${t.label}.` : "•", a = t.label != null ? "ordered" : "bullet", s = t.spread != null ? `${t.spread}` : "true";
706
+ e.openNode(n, { label: o, listType: a, spread: s }), e.next(t.children), e.closeNode();
707
+ }
708
+ },
709
+ toMarkdown: {
710
+ match: (e) => e.type.name === "list_item",
711
+ runner: (e, t) => {
712
+ e.openNode("listItem", void 0, { spread: t.attrs.spread === "true" }), e.next(t.content), e.closeNode();
713
+ }
1242
714
  }
1243
- }
1244
- const Dt = () => {
1245
- function a(e) {
1246
- Ht(e, (t) => Tt(t) ? [] : [t]);
715
+ })), De = u("SinkListItem", () => () => qe(D.type())), Oe = u("SplitListItem", () => () => Fe(D.type())), _e = u("SplitListItem", () => () => Ve(D.type())), yt = f("listItemKeymap", {
716
+ NextListItem: {
717
+ shortcuts: "Enter",
718
+ command: (r) => {
719
+ const e = r.get(m);
720
+ return () => e.call(_e.key);
721
+ }
722
+ },
723
+ SinkListItem: {
724
+ shortcuts: ["Tab", "Mod-]"],
725
+ command: (r) => {
726
+ const e = r.get(m);
727
+ return () => e.call(De.key);
728
+ }
729
+ },
730
+ LiftListItem: {
731
+ shortcuts: ["Shift-Tab", "Mod-["],
732
+ command: (r) => {
733
+ const e = r.get(m);
734
+ return () => e.call(Oe.key);
735
+ }
1247
736
  }
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
- }
737
+ }), Mt = X("text", () => ({
738
+ group: "inline",
739
+ parseMarkdown: {
740
+ match: ({ type: r }) => r === "text",
741
+ runner: (r, e) => {
742
+ r.addText(e.value);
1292
743
  }
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);
744
+ },
745
+ toMarkdown: {
746
+ match: (r) => r.type.name === "text",
747
+ runner: (r, e) => {
748
+ r.addNode("text", void 0, e.text);
749
+ }
750
+ }
751
+ })), It = [
752
+ Ze,
753
+ ge,
754
+ L,
755
+ G,
756
+ he,
757
+ T,
758
+ Ne,
759
+ x,
760
+ ye,
761
+ z,
762
+ Ie,
763
+ j,
764
+ Ae,
765
+ U,
766
+ we,
767
+ $,
768
+ ve,
769
+ Y,
770
+ Se,
771
+ E,
772
+ Te,
773
+ D,
774
+ ae,
775
+ se,
776
+ ce,
777
+ ie,
778
+ ue,
779
+ A,
780
+ me,
781
+ v,
782
+ Mt
783
+ ].flat(), bt = [
784
+ at,
785
+ gt,
786
+ ht,
787
+ lt,
788
+ pt,
789
+ nt
790
+ ].flat(), wt = [
791
+ fe,
792
+ Me,
793
+ M,
794
+ ke,
795
+ be,
796
+ Ce,
797
+ mt,
798
+ it,
799
+ dt,
800
+ Le,
801
+ xe,
802
+ De,
803
+ _e,
804
+ Oe,
805
+ le,
806
+ pe,
807
+ de,
808
+ Qe,
809
+ Xe
810
+ ], Nt = [
811
+ st,
812
+ ct,
813
+ ut,
814
+ ot,
815
+ yt,
816
+ kt,
817
+ ft,
818
+ et,
819
+ Ue,
820
+ Je,
821
+ Ye
822
+ ].flat(), B = /\[(?<span>((www|https:\/\/|http:\/\/)[^\s\]]+))]\((?<url>[^\s\]]+)\)/, Ct = (r) => new RegExp(`\\\\(?=[^\\w\\s${r}\\\\]|_)`, "g"), At = (r) => {
823
+ let e = r, t = e.match(B);
1297
824
  for (; t && t.groups; ) {
1298
- const { span: r } = t.groups;
1299
- e = e.replace(Y, r), t = e.match(Y);
825
+ const { span: n } = t.groups;
826
+ e = e.replace(B, n), t = e.match(B);
1300
827
  }
1301
828
  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)
829
+ }, vt = (r, e, t) => {
830
+ const n = r.split(""), o = n[e];
831
+ return n[e] && n[t] && (n[e] = n[t], n[t] = o), n.join("").toString();
832
+ }, xt = (r) => (e) => e.replace(Ct(r), ""), St = (r) => (e) => {
833
+ const t = e.indexOf(r.hole), n = e.charAt(t - 1), o = e.charAt(t + 1), a = /[^\w]|_/;
834
+ return o ? n && a.test(n) && a.test(o) ? r.punctuation : r.char : r.punctuation;
835
+ }, Lt = (r, e, t) => {
836
+ let n = e, o = !1;
837
+ return r.descendants((a) => {
838
+ var s;
839
+ if (o)
1313
840
  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 = {
841
+ if (a.isText) {
842
+ const l = (s = a.text) == null ? void 0 : s.indexOf(t);
843
+ if (l != null && l >= 0)
844
+ return o = !0, n += l, !1;
845
+ }
846
+ n += a.nodeSize;
847
+ }), n;
848
+ }, Tt = {
1322
849
  placeholderConfig: {
1323
- hole: "\u2205",
1324
- punctuation: "\u2042",
1325
- char: "\u2234"
850
+ hole: "",
851
+ punctuation: "",
852
+ char: ""
1326
853
  },
1327
854
  globalNodes: ["footnote_definition"],
1328
- shouldSyncNode: ({ prevNode: a, nextNode: e }) => a.inlineContent && e && a.type === e.type && !a.eq(e),
1329
- movePlaceholder: (a, e) => {
855
+ shouldSyncNode: ({ prevNode: r, nextNode: e }) => r.inlineContent && e && r.type === e.type && !r.eq(e),
856
+ movePlaceholder: (r, e) => {
1330
857
  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;
858
+ let n = e.indexOf(r);
859
+ for (; t.includes(e[n - 1] || "") && t.includes(e[n + 1] || ""); )
860
+ e = vt(e, n, n + 1), n = n + 1;
1334
861
  return e;
1335
862
  }
1336
- }, E = Ee(Bt, "inlineSyncConfig"), Rt = (a) => {
1337
- const { selection: e } = a, { $from: t } = e;
863
+ }, O = P(Tt, "inlineSyncConfig"), Dt = (r) => {
864
+ const { selection: e } = r, { $from: t } = e;
1338
865
  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(`
866
+ }, Ot = (r, e, t, n) => {
867
+ const o = r.get(Re), a = e.schema.topNodeType.create(void 0, [t, ...n]);
868
+ return o(a);
869
+ }, _t = (r, e) => {
870
+ const t = r.get(O.key), n = t.placeholderConfig.hole, [o = "", ...a] = e.split(`
1344
871
 
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(`
872
+ `), s = (d) => t.movePlaceholder(n, d);
873
+ let c = Be(xt(n), s, At)(o);
874
+ const i = St(t.placeholderConfig)(c);
875
+ return c = c.replace(n, i), c = [c, ...a].join(`
1349
876
 
1350
877
  `), [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(`
878
+ }, Ht = (r, e) => {
879
+ const n = r.get(Pe)(e);
880
+ return n ? n.firstChild : null;
881
+ }, Kt = (r, e) => {
882
+ const { globalNodes: t } = r.get(O.key), n = [];
883
+ return e.doc.descendants((o) => {
884
+ if (t.includes(o.type.name) || t.includes(o.type))
885
+ return n.push(o), !1;
886
+ }), n;
887
+ }, $t = (r) => r.split(`
1361
888
 
1362
- `)[0] || "", Oe = (a, e) => {
889
+ `)[0] || "", He = (r, e) => {
1363
890
  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, ""));
891
+ const t = Kt(r, e), n = Dt(e), o = Ot(r, e, n, t), [a, s] = _t(r, o), l = Ht(r, a);
892
+ return !l || n.type !== l.type ? null : (l.attrs = { ...n.attrs }, l.descendants((c) => {
893
+ var p;
894
+ const d = c.marks.find((g) => g.type.name === "link");
895
+ d && ((p = c.text) == null ? void 0 : p.includes(s)) && d.attrs.href.includes(s) && (d.attrs.href = d.attrs.href.replace(s, ""));
1369
896
  }), {
1370
- text: jt(o),
1371
- prevNode: r,
1372
- nextNode: s,
1373
- placeholder: l
897
+ text: $t(a),
898
+ prevNode: n,
899
+ nextNode: l,
900
+ placeholder: s
1374
901
  });
1375
902
  } catch {
1376
903
  return null;
1377
904
  }
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);
905
+ }, Et = (r, e, t, n, o) => {
906
+ const { placeholderConfig: a } = r.get(O.key), s = a.hole;
907
+ let l = t.tr.setMeta(e, !0).insertText(s, t.selection.from);
908
+ const c = t.apply(l), i = He(r, c);
1382
909
  if (!i)
1383
910
  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) => {
911
+ const { $from: d } = c.selection, p = d.before(), g = d.after(), h = Lt(i.nextNode, p, i.placeholder);
912
+ 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);
913
+ }, Bt = w((r) => {
1387
914
  let e = null;
1388
- return new T({
1389
- key: J,
915
+ const t = new N("MILKDOWN_INLINE_SYNC");
916
+ return new C({
917
+ key: t,
1390
918
  state: {
1391
919
  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))
920
+ apply: (n, o, a, s) => {
921
+ var _;
922
+ const l = r.get(R);
923
+ if (!((_ = l.hasFocus) != null && _.call(l)) || !l.editable || !n.docChanged || n.getMeta(t))
1396
924
  return null;
1397
- const i = Oe(a, l);
925
+ const i = He(r, s);
1398
926
  if (!i)
1399
927
  return null;
1400
928
  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(() => {
929
+ const { prevNode: d, nextNode: p, text: g } = i, { shouldSyncNode: h } = r.get(O.key);
930
+ return h({ prevNode: d, nextNode: p, ctx: r, tr: n, text: g }) && (e = requestAnimationFrame(() => {
1403
931
  e = null;
1404
- const { dispatch: g, state: h } = a.get(v);
1405
- zt(a, J, h, g, u.attrs);
932
+ const { dispatch: $e, state: Ee } = r.get(R);
933
+ Et(r, t, Ee, $e, d.attrs);
1406
934
  })), null;
1407
935
  }
1408
936
  }
1409
937
  });
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
- };
938
+ }), Rt = W(() => () => (r) => {
939
+ oe(r, "list", (e) => {
940
+ if (e.ordered) {
941
+ const t = e.start ?? 1;
942
+ e.children.forEach((n, o) => {
943
+ n.label = o + t;
944
+ });
945
+ }
946
+ });
947
+ }), Pt = W(() => () => (r) => {
948
+ const e = /[\t ]*(?:\r?\n|\r)/g;
949
+ oe(r, "text", (t, n, o) => {
950
+ if (!t.value || typeof t.value != "string")
951
+ return;
952
+ const a = [];
953
+ let s = 0;
954
+ e.lastIndex = 0;
955
+ let l = e.exec(t.value);
956
+ for (; l; ) {
957
+ const i = l.index;
958
+ 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);
959
+ }
960
+ if (!!(a.length > 0 && o && typeof n == "number"))
961
+ return s < t.value.length && a.push({ type: "text", value: t.value.slice(s) }), o.children.splice(n, 1, ...a), n + a.length;
962
+ });
963
+ }), Wt = W(() => je), qt = w(() => {
964
+ let r = !1;
965
+ const e = new N("MILKDOWN_INLINE_NODES_CURSOR"), t = new C({
966
+ key: e,
967
+ state: {
968
+ init() {
969
+ return !1;
970
+ },
971
+ apply(n) {
972
+ if (!n.selection.empty)
973
+ return !1;
974
+ const o = n.selection.$from, a = o.nodeBefore, s = o.nodeAfter;
975
+ return !!(a && s && a.isInline && !a.isText && s.isInline && !s.isText);
976
+ }
977
+ },
978
+ props: {
979
+ handleDOMEvents: {
980
+ compositionend: (n, o) => r ? (r = !1, requestAnimationFrame(() => {
981
+ if (t.getState(n.state)) {
982
+ const s = n.state.selection.from;
983
+ o.preventDefault(), n.dispatch(n.state.tr.insertText(o.data || "", s));
984
+ }
985
+ }), !0) : !1,
986
+ compositionstart: (n) => (t.getState(n.state) && (r = !0), !1),
987
+ beforeinput: (n, o) => {
988
+ if (t.getState(n.state) && o instanceof InputEvent && o.data && !r) {
989
+ const s = n.state.selection.from;
990
+ return o.preventDefault(), n.dispatch(n.state.tr.insertText(o.data || "", s)), !0;
991
+ }
992
+ return !1;
993
+ }
994
+ },
995
+ decorations(n) {
996
+ if (t.getState(n)) {
997
+ const s = n.selection.$from.pos, l = document.createElement("span"), c = J.widget(s, l, {
998
+ side: -1
999
+ }), i = document.createElement("span"), d = J.widget(s, i);
1000
+ return setTimeout(() => {
1001
+ l.contentEditable = "true", i.contentEditable = "true";
1002
+ }), Q.create(n.doc, [c, d]);
1003
+ }
1004
+ return Q.empty;
1005
+ }
1006
+ }
1007
+ });
1008
+ return t;
1009
+ }), Ft = w(() => new C({
1010
+ key: new N("MILKDOWN_HARDBREAK_MARKS"),
1011
+ appendTransaction: (r, e, t) => {
1012
+ if (!r.length)
1013
+ return;
1014
+ const [n] = r;
1015
+ if (!n)
1016
+ return;
1017
+ const [o] = n.steps;
1018
+ if (n.getMeta("hardbreak")) {
1019
+ if (!(o instanceof Ge))
1020
+ return;
1021
+ const { from: l } = o;
1022
+ return t.tr.setNodeMarkup(l, x.type(), void 0, []);
1023
+ }
1024
+ if (o instanceof ze) {
1025
+ let l = t.tr;
1026
+ const { from: c, to: i } = o;
1027
+ return t.doc.nodesBetween(c, i, (d, p) => {
1028
+ d.type === x.type() && (l = l.setNodeMarkup(p, x.type(), void 0, []));
1029
+ }), l;
1030
+ }
1031
+ }
1032
+ })), Ke = P(["table", "code_block"], "hardbreakFilterNodes"), Vt = w((r) => {
1033
+ const e = r.get(Ke.key);
1034
+ return new C({
1035
+ key: new N("MILKDOWN_HARDBREAK_FILTER"),
1036
+ filterTransaction: (t, n) => {
1037
+ const o = t.getMeta("hardbreak"), [a] = t.steps;
1038
+ if (o && a) {
1039
+ const { from: s } = a, l = n.doc.resolve(s);
1040
+ let c = l.depth, i = !0;
1041
+ for (; c > 0; )
1042
+ e.includes(l.node(c).type.name) && (i = !1), c--;
1043
+ return i;
1044
+ }
1045
+ return !0;
1046
+ }
1047
+ });
1048
+ }), Gt = w((r) => {
1049
+ const e = new N("MILKDOWN_HEADING_ID"), t = (n) => {
1050
+ if (n.composing || !n.editable)
1051
+ return;
1052
+ const o = r.get(G.key), a = n.state.tr.setMeta("addToHistory", !1);
1053
+ let s = !1;
1054
+ n.state.doc.descendants((l, c) => {
1055
+ if (l.type === T.type()) {
1056
+ if (l.textContent.trim().length === 0)
1057
+ return;
1058
+ const i = l.attrs, d = o(l);
1059
+ i.id !== d && (s = !0, a.setMeta(e, !0).setNodeMarkup(c, void 0, {
1060
+ ...i,
1061
+ id: d
1062
+ }));
1063
+ }
1064
+ }), s && n.dispatch(a);
1065
+ };
1066
+ return new C({
1067
+ key: e,
1068
+ view: (n) => (t(n), {
1069
+ update: (o) => {
1070
+ t(o);
1071
+ }
1072
+ })
1073
+ });
1074
+ }), zt = w(() => {
1075
+ const r = (e, t) => {
1076
+ const n = E.type(), o = D.type();
1077
+ let a = e.tr;
1078
+ e.doc.descendants((s, l, c, i) => {
1079
+ if (s.type === o && (c == null ? void 0 : c.type) === n) {
1080
+ let d = !1;
1081
+ const p = { ...s.attrs };
1082
+ s.attrs.listType !== "ordered" && (p.listType = "ordered", d = !0);
1083
+ const g = c == null ? void 0 : c.maybeChild(0);
1084
+ 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));
1085
+ }
1086
+ }), t(a);
1087
+ };
1088
+ return new C({
1089
+ key: new N("MILKDOWN_KEEP_LIST_ORDER"),
1090
+ appendTransaction: (e, t, n) => {
1091
+ let o = null;
1092
+ return e.some((a) => a.docChanged) && r(n, (a) => {
1093
+ o = a;
1094
+ }), o;
1095
+ }
1096
+ });
1097
+ }), jt = [
1098
+ O,
1099
+ Bt,
1100
+ Ft,
1101
+ Ke,
1102
+ Vt,
1103
+ qt,
1104
+ Rt,
1105
+ Wt,
1106
+ Pt,
1107
+ Gt,
1108
+ zt
1109
+ ], ir = [It, bt, wt, Nt, jt].flat();
1436
1110
  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
1111
+ ye as blockquoteAttr,
1112
+ st as blockquoteKeymap,
1113
+ z as blockquoteSchema,
1114
+ ve as bulletListAttr,
1115
+ ft as bulletListKeymap,
1116
+ Y as bulletListSchema,
1117
+ Ie as codeBlockAttr,
1118
+ ct as codeBlockKeymap,
1119
+ j as codeBlockSchema,
1120
+ wt as commands,
1121
+ ir as commonmark,
1122
+ be as createCodeBlockCommand,
1123
+ lt as createCodeBlockInputRule,
1124
+ Tt as defaultConfig,
1125
+ Ze as docSchema,
1126
+ ke as downgradeHeadingCommand,
1127
+ ae as emphasisAttr,
1128
+ Ue as emphasisKeymap,
1129
+ se as emphasisSchema,
1130
+ Ne as hardbreakAttr,
1131
+ Ft as hardbreakClearMarkPlugin,
1132
+ Ke as hardbreakFilterNodes,
1133
+ Vt as hardbreakFilterPlugin,
1134
+ ut as hardbreakKeymap,
1135
+ x as hardbreakSchema,
1136
+ he as headingAttr,
1137
+ G as headingIdGenerator,
1138
+ ot as headingKeymap,
1139
+ T as headingSchema,
1140
+ Ae as hrAttr,
1141
+ U as hrSchema,
1142
+ we as imageAttr,
1143
+ $ as imageSchema,
1144
+ ue as inlineCodeAttr,
1145
+ Je as inlineCodeKeymap,
1146
+ A as inlineCodeSchema,
1147
+ qt as inlineNodesCursorPlugin,
1148
+ O as inlineSyncConfig,
1149
+ Bt as inlineSyncPlugin,
1150
+ bt as inputrules,
1151
+ Ce as insertHardbreakCommand,
1152
+ mt as insertHrCommand,
1153
+ pt as insertHrInputRule,
1154
+ it as insertImageCommand,
1155
+ cr as insertImageInputRule,
1156
+ Nt as keymap,
1157
+ Oe as liftListItemCommand,
1158
+ me as linkAttr,
1159
+ v as linkSchema,
1160
+ Te as listItemAttr,
1161
+ yt as listItemKeymap,
1162
+ D as listItemSchema,
1163
+ Se as orderedListAttr,
1164
+ kt as orderedListKeymap,
1165
+ E as orderedListSchema,
1166
+ ge as paragraphAttr,
1167
+ et as paragraphKeymap,
1168
+ L as paragraphSchema,
1169
+ jt as plugins,
1170
+ Rt as remarkAddOrderInListPlugin,
1171
+ Wt as remarkInlineLinkPlugin,
1172
+ Pt as remarkLineBreak,
1173
+ It as schema,
1174
+ De as sinkListItemCommand,
1175
+ _e as splitListItemCommand,
1176
+ ce as strongAttr,
1177
+ Ye as strongKeymap,
1178
+ ie as strongSchema,
1179
+ Gt as syncHeadingIdPlugin,
1180
+ zt as syncListOrderPlugin,
1181
+ Mt as textSchema,
1182
+ le as toggleEmphasisCommand,
1183
+ pe as toggleInlineCodeCommand,
1184
+ Qe as toggleLinkCommand,
1185
+ de as toggleStrongCommand,
1186
+ fe as turnIntoTextCommand,
1187
+ lr as updateCodeBlockLanguageCommand,
1188
+ dt as updateImageCommand,
1189
+ Xe as updateLinkCommand,
1190
+ Me as wrapInBlockquoteCommand,
1191
+ at as wrapInBlockquoteInputRule,
1192
+ xe as wrapInBulletListCommand,
1193
+ gt as wrapInBulletListInputRule,
1194
+ M as wrapInHeadingCommand,
1195
+ nt as wrapInHeadingInputRule,
1196
+ Le as wrapInOrderedListCommand,
1197
+ ht as wrapInOrderedListInputRule
1485
1198
  };
1486
1199
  //# sourceMappingURL=index.es.js.map