@milkdown/preset-commonmark 6.1.5 → 6.3.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 (58) hide show
  1. package/lib/index.d.ts +2 -6
  2. package/lib/index.d.ts.map +1 -1
  3. package/lib/index.es.js +1013 -1047
  4. package/lib/index.es.js.map +1 -1
  5. package/lib/mark/code-inline.d.ts +1 -5
  6. package/lib/mark/code-inline.d.ts.map +1 -1
  7. package/lib/mark/em.d.ts +1 -5
  8. package/lib/mark/em.d.ts.map +1 -1
  9. package/lib/mark/link.d.ts +1 -5
  10. package/lib/mark/link.d.ts.map +1 -1
  11. package/lib/mark/strong.d.ts +1 -5
  12. package/lib/mark/strong.d.ts.map +1 -1
  13. package/lib/node/blockquote.d.ts +1 -5
  14. package/lib/node/blockquote.d.ts.map +1 -1
  15. package/lib/node/bullet-list.d.ts +1 -5
  16. package/lib/node/bullet-list.d.ts.map +1 -1
  17. package/lib/node/code-fence.d.ts +1 -5
  18. package/lib/node/code-fence.d.ts.map +1 -1
  19. package/lib/node/doc.d.ts +1 -5
  20. package/lib/node/doc.d.ts.map +1 -1
  21. package/lib/node/hardbreak.d.ts +4 -4
  22. package/lib/node/hardbreak.d.ts.map +1 -1
  23. package/lib/node/heading.d.ts +8 -6
  24. package/lib/node/heading.d.ts.map +1 -1
  25. package/lib/node/hr.d.ts +1 -5
  26. package/lib/node/hr.d.ts.map +1 -1
  27. package/lib/node/image.d.ts +1 -5
  28. package/lib/node/image.d.ts.map +1 -1
  29. package/lib/node/index.d.ts +2 -3
  30. package/lib/node/index.d.ts.map +1 -1
  31. package/lib/node/list-item.d.ts +1 -5
  32. package/lib/node/list-item.d.ts.map +1 -1
  33. package/lib/node/ordered-list.d.ts +1 -5
  34. package/lib/node/ordered-list.d.ts.map +1 -1
  35. package/lib/node/paragraph.d.ts +1 -5
  36. package/lib/node/paragraph.d.ts.map +1 -1
  37. package/lib/node/text.d.ts +1 -5
  38. package/lib/node/text.d.ts.map +1 -1
  39. package/lib/plugin/add-order-in-list.d.ts +3 -0
  40. package/lib/plugin/add-order-in-list.d.ts.map +1 -0
  41. package/lib/plugin/index.d.ts.map +1 -1
  42. package/lib/supported-keys.d.ts +1 -0
  43. package/lib/supported-keys.d.ts.map +1 -1
  44. package/package.json +7 -5
  45. package/src/mark/link.ts +55 -9
  46. package/src/node/code-fence.ts +7 -6
  47. package/src/node/hardbreak.ts +46 -3
  48. package/src/node/heading.ts +264 -117
  49. package/src/node/hr.ts +4 -2
  50. package/src/node/image.ts +4 -3
  51. package/src/node/index.ts +3 -1
  52. package/src/node/list-item.ts +93 -3
  53. package/src/node/ordered-list.ts +2 -1
  54. package/src/node/paragraph.ts +12 -2
  55. package/src/plugin/add-order-in-list.ts +19 -0
  56. package/src/plugin/index.ts +2 -1
  57. package/src/plugin/inline-nodes-cursor.ts +1 -1
  58. package/src/supported-keys.ts +1 -0
package/lib/index.es.js CHANGED
@@ -1,34 +1,17 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- import { createMark, createShortcut, createNode, createPlugin, AtomList } from "@milkdown/utils";
21
- import { createCmdKey, createCmd, schemaCtx, commandsCtx, editorViewCtx } from "@milkdown/core";
22
- import { markRule, findSelectedNodeOfType } from "@milkdown/prose";
23
- import { toggleMark, wrapIn, setBlockType } from "@milkdown/prose/commands";
24
- import { InputRule, wrappingInputRule, textblockTypeInputRule } from "@milkdown/prose/inputrules";
25
- import { PluginKey, TextSelection, Plugin, Selection } from "@milkdown/prose/state";
26
- import { Fragment } from "@milkdown/prose/model";
27
- import { ReplaceStep, AddMarkStep } from "@milkdown/prose/transform";
28
- import { splitListItem, sinkListItem, liftListItem } from "@milkdown/prose/schema-list";
29
- import links from "remark-inline-links";
30
- import { Decoration, DecorationSet } from "@milkdown/prose/view";
31
- const SupportedKeys = {
1
+ import { createMark as R, createShortcut as h, createNode as w, createPlugin as He, AtomList as Ne } from "@milkdown/utils";
2
+ import { createCmdKey as I, createCmd as M, schemaCtx as A, commandsCtx as we, editorViewCtx as B, getPalette as Te } from "@milkdown/core";
3
+ import { markRule as _, calculateTextPosition as Oe, cloneTr as Ae, findSelectedNodeOfType as K, getNodeFromSchema as Ee } from "@milkdown/prose";
4
+ import { toggleMark as P, wrapIn as de, setBlockType as E } from "@milkdown/prose/commands";
5
+ import { expectDomTypeError as D, missingRootElement as _e } from "@milkdown/exception";
6
+ import { InputRule as me, wrappingInputRule as W, textblockTypeInputRule as G } from "@milkdown/prose/inputrules";
7
+ import { PluginKey as T, TextSelection as pe, Plugin as H, NodeSelection as ve, Selection as Le } from "@milkdown/prose/state";
8
+ import { Fragment as ge } from "@milkdown/prose/model";
9
+ import { ReplaceStep as $e, AddMarkStep as Se } from "@milkdown/prose/transform";
10
+ import { DecorationSet as O, Decoration as J } from "@milkdown/prose/view";
11
+ import { splitListItem as Re, sinkListItem as Be, liftListItem as Pe } from "@milkdown/prose/schema-list";
12
+ import We from "remark-inline-links";
13
+ import { visit as qe } from "unist-util-visit";
14
+ const k = {
32
15
  HardBreak: "HardBreak",
33
16
  Blockquote: "Blockquote",
34
17
  BulletList: "BulletList",
@@ -40,6 +23,7 @@ const SupportedKeys = {
40
23
  H4: "H4",
41
24
  H5: "H5",
42
25
  H6: "H6",
26
+ DowngradeHeading: "DowngradeHeading",
43
27
  Text: "Text",
44
28
  CodeInline: "CodeInline",
45
29
  Em: "Em",
@@ -47,333 +31,283 @@ const SupportedKeys = {
47
31
  NextListItem: "NextListItem",
48
32
  SinkListItem: "SinkListItem",
49
33
  LiftListItem: "LiftListItem"
50
- };
51
- const id$a = "code_inline";
52
- const ToggleInlineCode = createCmdKey("ToggleInlineCode");
53
- const codeInline = createMark((utils) => {
54
- return {
55
- id: id$a,
56
- schema: () => ({
57
- priority: 100,
58
- code: true,
59
- inclusive: false,
60
- parseDOM: [{ tag: "code" }],
61
- toDOM: (mark) => ["code", { class: utils.getClassName(mark.attrs, "code-inline") }],
62
- parseMarkdown: {
63
- match: (node) => node.type === "inlineCode",
64
- runner: (state, node, markType) => {
65
- state.openMark(markType);
66
- state.addText(node["value"]);
67
- state.closeMark(markType);
68
- }
69
- },
70
- toMarkdown: {
71
- match: (mark) => mark.type.name === id$a,
72
- runner: (state, mark, node) => {
73
- state.withMark(mark, "inlineCode", node.text || "");
74
- }
34
+ }, he = "code_inline", Q = I("ToggleInlineCode"), Ke = R((c) => ({
35
+ id: he,
36
+ schema: () => ({
37
+ priority: 100,
38
+ code: !0,
39
+ inclusive: !1,
40
+ parseDOM: [{ tag: "code" }],
41
+ toDOM: (e) => ["code", { class: c.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 === he,
50
+ runner: (e, t, r) => {
51
+ e.withMark(t, "inlineCode", r.text || "");
75
52
  }
76
- }),
77
- inputRules: (markType) => [markRule(/(?:^|[^`])(`([^`]+)`)$/, markType)],
78
- commands: (markType) => [createCmd(ToggleInlineCode, () => toggleMark(markType))],
79
- shortcuts: {
80
- [SupportedKeys.CodeInline]: createShortcut(ToggleInlineCode, "Mod-e")
81
53
  }
82
- };
83
- });
84
- const id$9 = "em";
85
- const ToggleItalic = createCmdKey("ToggleItalic");
86
- const em = createMark((utils) => ({
87
- id: id$9,
54
+ }),
55
+ inputRules: (e) => [_(/(?:^|[^`])(`([^`]+)`)$/, e)],
56
+ commands: (e) => [M(Q, () => P(e))],
57
+ shortcuts: {
58
+ [k.CodeInline]: h(Q, "Mod-e")
59
+ }
60
+ })), F = "em", X = I("ToggleItalic"), Fe = R((c) => ({
61
+ id: F,
88
62
  schema: () => ({
89
63
  parseDOM: [
90
64
  { tag: "i" },
91
65
  { tag: "em" },
92
- { style: "font-style", getAttrs: (value) => value === "italic" }
66
+ { style: "font-style", getAttrs: (e) => e === "italic" }
93
67
  ],
94
- toDOM: (mark) => ["em", { class: utils.getClassName(mark.attrs, id$9) }],
68
+ toDOM: (e) => ["em", { class: c.getClassName(e.attrs, F) }],
95
69
  parseMarkdown: {
96
- match: (node) => node.type === "emphasis",
97
- runner: (state, node, markType) => {
98
- state.openMark(markType);
99
- state.next(node.children);
100
- state.closeMark(markType);
70
+ match: (e) => e.type === "emphasis",
71
+ runner: (e, t, r) => {
72
+ e.openMark(r), e.next(t.children), e.closeMark(r);
101
73
  }
102
74
  },
103
75
  toMarkdown: {
104
- match: (mark) => mark.type.name === id$9,
105
- runner: (state, mark) => {
106
- state.withMark(mark, "emphasis");
76
+ match: (e) => e.type.name === F,
77
+ runner: (e, t) => {
78
+ e.withMark(t, "emphasis");
107
79
  }
108
80
  }
109
81
  }),
110
- inputRules: (markType) => [
111
- markRule(/(?:^|[^_])(_([^_]+)_)$/, markType),
112
- markRule(/(?:^|[^*])(\*([^*]+)\*)$/, markType)
82
+ inputRules: (e) => [
83
+ _(/(?:^|[^_])(_([^_]+)_)$/, e),
84
+ _(/(?:^|[^*])(\*([^*]+)\*)$/, e)
113
85
  ],
114
- commands: (markType) => [createCmd(ToggleItalic, () => toggleMark(markType))],
86
+ commands: (e) => [M(X, () => P(e))],
115
87
  shortcuts: {
116
- [SupportedKeys.Em]: createShortcut(ToggleItalic, "Mod-i")
88
+ [k.Em]: h(X, "Mod-i")
117
89
  }
118
- }));
119
- const key$1 = new PluginKey("MILKDOWN_LINK_INPUT");
120
- const ToggleLink = createCmdKey("ToggleLink");
121
- const ModifyLink = createCmdKey("ModifyLink");
122
- const id$8 = "link";
123
- const link = createMark((utils, options) => {
124
- return {
125
- id: id$8,
126
- schema: () => ({
127
- attrs: {
128
- href: {},
129
- title: { default: null }
130
- },
131
- inclusive: false,
132
- parseDOM: [
133
- {
134
- tag: "a[href]",
135
- getAttrs: (dom) => {
136
- if (!(dom instanceof HTMLElement)) {
137
- throw new Error();
138
- }
139
- return { href: dom.getAttribute("href"), title: dom.getAttribute("title") };
140
- }
141
- }
142
- ],
143
- toDOM: (mark) => ["a", __spreadProps(__spreadValues({}, mark.attrs), { class: utils.getClassName(mark.attrs, id$8) })],
144
- parseMarkdown: {
145
- match: (node) => node.type === "link",
146
- runner: (state, node, markType) => {
147
- const url = node["url"];
148
- const title = node["title"];
149
- state.openMark(markType, { href: url, title });
150
- state.next(node.children);
151
- state.closeMark(markType);
152
- }
153
- },
154
- toMarkdown: {
155
- match: (mark) => mark.type.name === id$8,
156
- runner: (state, mark) => {
157
- state.withMark(mark, "link", void 0, {
158
- title: mark.attrs["title"],
159
- url: mark.attrs["href"]
160
- });
90
+ })), Ue = new T("MILKDOWN_LINK_INPUT"), xe = I("ToggleLink"), Y = I("ModifyLink"), v = "link", Ve = R((c, e) => ({
91
+ id: v,
92
+ schema: () => ({
93
+ attrs: {
94
+ href: {},
95
+ title: { default: null }
96
+ },
97
+ inclusive: !1,
98
+ parseDOM: [
99
+ {
100
+ tag: "a[href]",
101
+ getAttrs: (t) => {
102
+ if (!(t instanceof HTMLElement))
103
+ throw D(t);
104
+ return { href: t.getAttribute("href"), title: t.getAttribute("title") };
161
105
  }
162
106
  }
163
- }),
164
- commands: (markType) => [
165
- createCmd(ToggleLink, (href = "") => toggleMark(markType, { href })),
166
- createCmd(ModifyLink, (href = "") => (state, dispatch) => {
167
- if (!dispatch)
168
- return false;
169
- const { marks: marks2 } = state.schema;
170
- let node;
171
- let pos = -1;
172
- const { selection } = state;
173
- state.doc.nodesBetween(selection.from, selection.to, (n, p) => {
174
- if (marks2.link.isInSet(n.marks)) {
175
- node = n;
176
- pos = p;
177
- return false;
178
- }
179
- return;
180
- });
181
- if (!node)
182
- return false;
183
- const mark = node.marks.find(({ type }) => type === markType);
184
- if (!mark)
185
- return false;
186
- const start = pos;
187
- const end = pos + node.nodeSize;
188
- const { tr } = state;
189
- const linkMark = marks2.link.create(__spreadProps(__spreadValues({}, mark.attrs), { href }));
190
- dispatch(tr.removeMark(start, end, mark).addMark(start, end, linkMark).setSelection(new TextSelection(tr.selection.$anchor)).scrollIntoView());
191
- return true;
192
- })
193
107
  ],
194
- inputRules: (markType, ctx) => [
195
- new InputRule(/\[(?<text>.*?)]\((?<href>.*?)(?=“|\))"?(?<title>[^"]+)?"?\)/, (state, match, start, end) => {
196
- const [okay, text2 = "", href, title] = match;
197
- const { tr } = state;
198
- if (okay) {
199
- const content = text2 || "link";
200
- tr.replaceWith(start, end, ctx.get(schemaCtx).text(content)).addMark(start, content.length + start, markType.create({ title, href }));
108
+ toDOM: (t) => ["a", { ...t.attrs, class: c.getClassName(t.attrs, v) }],
109
+ parseMarkdown: {
110
+ match: (t) => t.type === "link",
111
+ runner: (t, r, n) => {
112
+ const o = r.url, a = r.title;
113
+ t.openMark(n, { href: o, title: a }), t.next(r.children), t.closeMark(n);
114
+ }
115
+ },
116
+ toMarkdown: {
117
+ match: (t) => t.type.name === v,
118
+ runner: (t, r) => {
119
+ t.withMark(r, "link", void 0, {
120
+ title: r.attrs.title,
121
+ url: r.attrs.href
122
+ });
123
+ }
124
+ }
125
+ }),
126
+ commands: (t) => [
127
+ M(xe, (r = "") => P(t, { href: r })),
128
+ M(Y, (r = "") => (n, o) => {
129
+ var y;
130
+ if (!o)
131
+ return !1;
132
+ const { marks: a } = n.schema;
133
+ let s, l = -1;
134
+ const { selection: i } = n, { from: u, to: g } = i;
135
+ if (n.doc.nodesBetween(u, u === g ? g + 1 : g, (N, x) => {
136
+ var L;
137
+ if ((L = a.link) != null && L.isInSet(N.marks))
138
+ return s = N, l = x, !1;
139
+ }), !s)
140
+ return !1;
141
+ const d = s.marks.find(({ type: N }) => N === t);
142
+ if (!d)
143
+ return !1;
144
+ const m = l, f = l + s.nodeSize, { tr: p } = n, b = (y = a.link) == null ? void 0 : y.create({ ...d.attrs, href: r });
145
+ return b ? (o(p.removeMark(m, f, d).addMark(m, f, b).setSelection(new pe(p.selection.$anchor)).scrollIntoView()), !0) : !1;
146
+ })
147
+ ],
148
+ inputRules: (t, r) => [
149
+ new me(/\[(?<text>.*?)]\((?<href>.*?)(?=“|\))"?(?<title>[^"]+)?"?\)/, (n, o, a, s) => {
150
+ const [l, i = "", u, g] = o, { tr: d } = n;
151
+ if (l) {
152
+ const m = i || "link";
153
+ d.replaceWith(a, s, r.get(A).text(m)).addMark(a, m.length + a, t.create({ title: g, href: u }));
154
+ }
155
+ return d;
156
+ })
157
+ ],
158
+ prosePlugins: (t, r) => {
159
+ let n = !1;
160
+ return [
161
+ new H({
162
+ key: Ue,
163
+ view: (o) => {
164
+ var u, g, d;
165
+ const a = c.themeManager.get("input-chip", {
166
+ placeholder: (g = (u = e == null ? void 0 : e.input) == null ? void 0 : u.placeholder) != null ? g : "Input Web Link",
167
+ buttonText: (d = e == null ? void 0 : e.input) == null ? void 0 : d.buttonText,
168
+ onUpdate: (m) => {
169
+ r.get(we).call(Y, m);
170
+ },
171
+ calculatePosition: (m, f) => {
172
+ Oe(m, f, (p, b, y, N) => {
173
+ const x = m.dom.parentElement;
174
+ if (!x)
175
+ throw _e();
176
+ const L = b.left - p.left;
177
+ let q = p.left - N.left - (y.width - L) / 2, fe = p.bottom - N.top + 14 + x.scrollTop;
178
+ return n && (fe = p.top - N.top - y.height - 14 + x.scrollTop), q < 0 && (q = 0), [fe, q];
179
+ });
180
+ }
181
+ });
182
+ if (!a)
183
+ return {};
184
+ const s = (m) => {
185
+ const { selection: f, doc: p } = m.state, { from: b, to: y } = f;
186
+ if (!m.hasFocus())
187
+ return !1;
188
+ if (f.empty && f instanceof pe && y < p.content.size && b < p.content.size && p.rangeHasMark(b, b === y ? y + 1 : y, t))
189
+ return n = !1, !0;
190
+ if (f instanceof ve) {
191
+ const { node: N } = f;
192
+ if (N.type.name === "image" && N.marks.findIndex((x) => x.type.name === v) > -1)
193
+ return n = !0, !0;
194
+ }
195
+ return !1;
196
+ }, l = (m) => {
197
+ const { selection: f } = m.state;
198
+ let p;
199
+ const { from: b, to: y } = f;
200
+ if (m.state.doc.nodesBetween(b, b === y ? y + 1 : y, (L) => {
201
+ if (t.isInSet(L.marks))
202
+ return p = L, !1;
203
+ }), !p)
204
+ return;
205
+ const N = p.marks.find((L) => L.type === t);
206
+ return N ? N.attrs.href : void 0;
207
+ }, i = (m) => {
208
+ if (!m.editable)
209
+ return;
210
+ s(m) ? (a.show(m), a.update(l(m))) : a.hide();
211
+ };
212
+ return a.init(o), i(o), {
213
+ update: (m, f) => {
214
+ (f == null ? void 0 : f.doc.eq(m.state.doc)) && f.selection.eq(m.state.selection) || requestAnimationFrame(() => {
215
+ i(m);
216
+ });
217
+ },
218
+ destroy: () => {
219
+ a.destroy();
220
+ }
221
+ };
201
222
  }
202
- return tr;
203
223
  })
224
+ ];
225
+ }
226
+ })), U = "strong", Z = I("ToggleBold"), je = R((c) => ({
227
+ id: U,
228
+ schema: () => ({
229
+ parseDOM: [
230
+ { tag: "b" },
231
+ { tag: "strong" },
232
+ { style: "font-style", getAttrs: (e) => e === "bold" }
204
233
  ],
205
- prosePlugins: (type, ctx) => {
206
- return [
207
- new Plugin({
208
- key: key$1,
209
- view: (editorView) => {
210
- var _a, _b, _c;
211
- const inputChipRenderer = utils.themeManager.get("input-chip", {
212
- placeholder: (_b = (_a = options == null ? void 0 : options.input) == null ? void 0 : _a.placeholder) != null ? _b : "Input Web Link",
213
- buttonText: (_c = options == null ? void 0 : options.input) == null ? void 0 : _c.buttonText,
214
- onUpdate: (value) => {
215
- ctx.get(commandsCtx).call(ModifyLink, value);
216
- }
217
- });
218
- if (!inputChipRenderer)
219
- return {};
220
- const shouldDisplay = (view) => {
221
- const { selection, doc: doc2 } = view.state;
222
- const { from, to } = selection;
223
- return view.hasFocus() && selection.empty && selection instanceof TextSelection && to < doc2.content.size && from < doc2.content.size && doc2.rangeHasMark(from, from === to ? to + 1 : to, type);
224
- };
225
- const getCurrentLink = (view) => {
226
- const { selection } = view.state;
227
- let node;
228
- const { from, to } = selection;
229
- view.state.doc.nodesBetween(from, from === to ? to + 1 : to, (n) => {
230
- if (type.isInSet(n.marks)) {
231
- node = n;
232
- return false;
233
- }
234
- return;
235
- });
236
- if (!node)
237
- return;
238
- const mark = node.marks.find((m) => m.type === type);
239
- if (!mark)
240
- return;
241
- const value = mark.attrs["href"];
242
- return value;
243
- };
244
- const renderByView = (view) => {
245
- if (!view.editable) {
246
- return;
247
- }
248
- const display = shouldDisplay(view);
249
- if (display) {
250
- inputChipRenderer.show(view);
251
- inputChipRenderer.update(getCurrentLink(view));
252
- } else {
253
- inputChipRenderer.hide();
254
- }
255
- };
256
- inputChipRenderer.init(editorView);
257
- renderByView(editorView);
258
- return {
259
- update: (view, prevState) => {
260
- const isEqualSelection = (prevState == null ? void 0 : prevState.doc.eq(view.state.doc)) && prevState.selection.eq(view.state.selection);
261
- if (isEqualSelection)
262
- return;
263
- renderByView(view);
264
- },
265
- destroy: () => {
266
- inputChipRenderer.destroy();
267
- }
268
- };
269
- }
270
- })
271
- ];
272
- }
273
- };
274
- });
275
- const id$7 = "strong";
276
- const ToggleBold = createCmdKey("ToggleBold");
277
- const strong = createMark((utils) => {
278
- return {
279
- id: id$7,
280
- schema: () => ({
281
- parseDOM: [
282
- { tag: "b" },
283
- { tag: "strong" },
284
- { style: "font-style", getAttrs: (value) => value === "bold" }
285
- ],
286
- toDOM: (mark) => ["strong", { class: utils.getClassName(mark.attrs, id$7) }],
287
- parseMarkdown: {
288
- match: (node) => node.type === "strong",
289
- runner: (state, node, markType) => {
290
- state.openMark(markType);
291
- state.next(node.children);
292
- state.closeMark(markType);
293
- }
294
- },
295
- toMarkdown: {
296
- match: (mark) => mark.type.name === id$7,
297
- runner: (state, mark) => {
298
- state.withMark(mark, "strong");
299
- }
234
+ toDOM: (e) => ["strong", { class: c.getClassName(e.attrs, U) }],
235
+ parseMarkdown: {
236
+ match: (e) => e.type === "strong",
237
+ runner: (e, t, r) => {
238
+ e.openMark(r), e.next(t.children), e.closeMark(r);
239
+ }
240
+ },
241
+ toMarkdown: {
242
+ match: (e) => e.type.name === U,
243
+ runner: (e, t) => {
244
+ e.withMark(t, "strong");
300
245
  }
301
- }),
302
- inputRules: (markType) => [
303
- markRule(/(?:__)([^_]+)(?:__)$/, markType),
304
- markRule(/(?:\*\*)([^*]+)(?:\*\*)$/, markType)
305
- ],
306
- commands: (markType) => [createCmd(ToggleBold, () => toggleMark(markType))],
307
- shortcuts: {
308
- [SupportedKeys.Bold]: createShortcut(ToggleBold, "Mod-b")
309
246
  }
310
- };
311
- });
312
- const marks = [codeInline(), em(), strong(), link()];
313
- const id$6 = "blockquote";
314
- const WrapInBlockquote = createCmdKey("WrapInBlockquote");
315
- const blockquote = createNode((utils) => {
316
- return {
317
- id: id$6,
318
- schema: () => ({
319
- content: "block+",
320
- group: "block",
321
- defining: true,
322
- parseDOM: [{ tag: "blockquote" }],
323
- toDOM: (node) => ["blockquote", { class: utils.getClassName(node.attrs, id$6) }, 0],
324
- parseMarkdown: {
325
- match: ({ type }) => type === id$6,
326
- runner: (state, node, type) => {
327
- state.openNode(type).next(node.children).closeNode();
328
- }
329
- },
330
- toMarkdown: {
331
- match: (node) => node.type.name === id$6,
332
- runner: (state, node) => {
333
- state.openNode("blockquote").next(node.content).closeNode();
334
- }
247
+ }),
248
+ inputRules: (e) => [
249
+ _(/(?:__)([^_]+)(?:__)$/, e),
250
+ _(/(?:\*\*)([^*]+)(?:\*\*)$/, e)
251
+ ],
252
+ commands: (e) => [M(Z, () => P(e))],
253
+ shortcuts: {
254
+ [k.Bold]: h(Z, "Mod-b")
255
+ }
256
+ })), ze = [Ke(), Fe(), je(), Ve()], $ = "blockquote", ee = I("WrapInBlockquote"), Ge = w((c) => ({
257
+ id: $,
258
+ schema: () => ({
259
+ content: "block+",
260
+ group: "block",
261
+ defining: !0,
262
+ parseDOM: [{ tag: "blockquote" }],
263
+ toDOM: (e) => ["blockquote", { class: c.getClassName(e.attrs, $) }, 0],
264
+ parseMarkdown: {
265
+ match: ({ type: e }) => e === $,
266
+ runner: (e, t, r) => {
267
+ e.openNode(r).next(t.children).closeNode();
268
+ }
269
+ },
270
+ toMarkdown: {
271
+ match: (e) => e.type.name === $,
272
+ runner: (e, t) => {
273
+ e.openNode("blockquote").next(t.content).closeNode();
335
274
  }
336
- }),
337
- inputRules: (nodeType) => [wrappingInputRule(/^\s*>\s$/, nodeType)],
338
- commands: (nodeType) => [createCmd(WrapInBlockquote, () => wrapIn(nodeType))],
339
- shortcuts: {
340
- [SupportedKeys.Blockquote]: createShortcut(WrapInBlockquote, "Mod-Shift-b")
341
275
  }
342
- };
343
- });
344
- const WrapInBulletList = createCmdKey("WrapInBulletList");
345
- const bulletList = createNode((utils) => {
346
- const id2 = "bullet_list";
276
+ }),
277
+ inputRules: (e) => [W(/^\s*>\s$/, e)],
278
+ commands: (e) => [M(ee, () => de(e))],
279
+ shortcuts: {
280
+ [k.Blockquote]: h(ee, "Mod-Shift-b")
281
+ }
282
+ })), te = I("WrapInBulletList"), Je = w((c) => {
283
+ const e = "bullet_list";
347
284
  return {
348
- id: id2,
285
+ id: e,
349
286
  schema: () => ({
350
287
  content: "listItem+",
351
288
  group: "block",
352
289
  parseDOM: [{ tag: "ul" }],
353
- toDOM: (node) => {
354
- return ["ul", { class: utils.getClassName(node.attrs, "bullet-list") }, 0];
355
- },
290
+ toDOM: (t) => ["ul", { class: c.getClassName(t.attrs, "bullet-list") }, 0],
356
291
  parseMarkdown: {
357
- match: ({ type, ordered }) => type === "list" && !ordered,
358
- runner: (state, node, type) => {
359
- state.openNode(type).next(node.children).closeNode();
292
+ match: ({ type: t, ordered: r }) => t === "list" && !r,
293
+ runner: (t, r, n) => {
294
+ t.openNode(n).next(r.children).closeNode();
360
295
  }
361
296
  },
362
297
  toMarkdown: {
363
- match: (node) => node.type.name === id2,
364
- runner: (state, node) => {
365
- state.openNode("list", void 0, { ordered: false }).next(node.content).closeNode();
298
+ match: (t) => t.type.name === e,
299
+ runner: (t, r) => {
300
+ t.openNode("list", void 0, { ordered: !1 }).next(r.content).closeNode();
366
301
  }
367
302
  }
368
303
  }),
369
- inputRules: (nodeType) => [wrappingInputRule(/^\s*([-+*])\s$/, nodeType)],
370
- commands: (nodeType) => [createCmd(WrapInBulletList, () => wrapIn(nodeType))],
304
+ inputRules: (t) => [W(/^\s*([-+*])\s$/, t)],
305
+ commands: (t) => [M(te, () => de(t))],
371
306
  shortcuts: {
372
- [SupportedKeys.BulletList]: createShortcut(WrapInBulletList, "Mod-Alt-8")
307
+ [k.BulletList]: h(te, "Mod-Alt-8")
373
308
  }
374
309
  };
375
- });
376
- const languageOptions = [
310
+ }), Qe = [
377
311
  "",
378
312
  "javascript",
379
313
  "typescript",
@@ -390,293 +324,351 @@ const languageOptions = [
390
324
  "go",
391
325
  "rust",
392
326
  "markdown"
393
- ];
394
- const backtickInputRegex = /^```(?<language>[a-z]*)?[\s\n]$/;
395
- const tildeInputRegex = /^~~~(?<language>[a-z]*)?[\s\n]$/;
396
- const TurnIntoCodeFence = createCmdKey("TurnIntoCodeFence");
397
- const id$5 = "fence";
398
- const codeFence = createNode((utils, options) => {
399
- const languageList = (options == null ? void 0 : options.languageList) || languageOptions;
327
+ ], Xe = /^```(?<language>[a-z]*)?[\s\n]$/, Ye = /^~~~(?<language>[a-z]*)?[\s\n]$/, re = I("TurnIntoCodeFence"), V = "fence", Ze = w((c, e) => {
328
+ const t = (e == null ? void 0 : e.languageList) || Qe;
400
329
  return {
401
- id: id$5,
402
- schema: (ctx) => ({
330
+ id: V,
331
+ schema: (r) => ({
403
332
  content: "text*",
404
333
  group: "block",
405
334
  marks: "",
406
- defining: true,
407
- code: true,
335
+ defining: !0,
336
+ code: !0,
408
337
  attrs: {
409
338
  language: {
410
339
  default: ""
411
340
  },
412
341
  fold: {
413
- default: true
342
+ default: !0
414
343
  }
415
344
  },
416
345
  parseDOM: [
417
346
  {
418
347
  tag: "div.code-fence-container",
419
348
  preserveWhitespace: "full",
420
- getAttrs: (dom) => {
421
- var _a;
422
- if (!(dom instanceof HTMLElement)) {
423
- throw new Error("Parse DOM error.");
424
- }
425
- return { language: (_a = dom.querySelector("pre")) == null ? void 0 : _a.dataset["language"] };
349
+ getAttrs: (n) => {
350
+ var o;
351
+ if (!(n instanceof HTMLElement))
352
+ throw D(n);
353
+ return { language: (o = n.querySelector("pre")) == null ? void 0 : o.dataset.language };
426
354
  },
427
- getContent: (dom, schema) => {
428
- var _a, _b;
429
- if (!(dom instanceof HTMLElement)) {
430
- throw new Error("Parse DOM error.");
431
- }
432
- const textNode = schema.text((_b = (_a = dom.querySelector("pre")) == null ? void 0 : _a.textContent) != null ? _b : "");
433
- return Fragment.from(textNode);
355
+ getContent: (n, o) => {
356
+ var s, l;
357
+ if (!(n instanceof HTMLElement))
358
+ throw D(n);
359
+ const a = o.text((l = (s = n.querySelector("pre")) == null ? void 0 : s.textContent) != null ? l : "");
360
+ return ge.from(a);
434
361
  }
435
362
  },
436
363
  {
437
364
  tag: "pre",
438
365
  preserveWhitespace: "full",
439
- getAttrs: (dom) => {
440
- if (!(dom instanceof HTMLElement)) {
441
- throw new Error("Parse DOM error.");
442
- }
443
- return { language: dom.dataset["language"] };
366
+ getAttrs: (n) => {
367
+ if (!(n instanceof HTMLElement))
368
+ throw D(n);
369
+ return { language: n.dataset.language };
444
370
  }
445
371
  }
446
372
  ],
447
- toDOM: (node) => {
448
- const select = document.createElement("select");
449
- languageList.forEach((lang) => {
450
- const option = document.createElement("option");
451
- option.value = lang;
452
- option.innerText = !lang ? "--" : lang;
453
- if (lang === node.attrs["language"]) {
454
- option.selected = true;
455
- }
456
- select.appendChild(option);
457
- });
458
- select.onchange = (e) => {
459
- const target = e.target;
460
- if (!(target instanceof HTMLSelectElement)) {
373
+ toDOM: (n) => {
374
+ const o = document.createElement("select");
375
+ return t.forEach((a) => {
376
+ const s = document.createElement("option");
377
+ s.value = a, s.innerText = a || "--", a === n.attrs.language && (s.selected = !0), o.appendChild(s);
378
+ }), o.onchange = (a) => {
379
+ const s = a.target;
380
+ if (!(s instanceof HTMLSelectElement))
461
381
  return;
462
- }
463
- const view = ctx.get(editorViewCtx);
464
- if (!view.editable) {
465
- target.value = node.attrs["language"];
382
+ const l = r.get(B);
383
+ if (!l.editable) {
384
+ s.value = n.attrs.language;
466
385
  return;
467
386
  }
468
- const { top, left } = target.getBoundingClientRect();
469
- const result = view.posAtCoords({ top, left });
470
- if (!result)
387
+ const { top: i, left: u } = s.getBoundingClientRect(), g = l.posAtCoords({ top: i, left: u });
388
+ if (!g)
471
389
  return;
472
- const { tr } = view.state;
473
- view.dispatch(tr.setNodeMarkup(result.inside, void 0, __spreadProps(__spreadValues({}, node.attrs), {
474
- language: target.value
475
- })));
476
- };
477
- return [
390
+ const { tr: d } = l.state;
391
+ l.dispatch(d.setNodeMarkup(g.inside, void 0, {
392
+ ...n.attrs,
393
+ language: s.value
394
+ }));
395
+ }, [
478
396
  "div",
479
397
  {
480
398
  class: "code-fence-container"
481
399
  },
482
- select,
400
+ o,
483
401
  [
484
402
  "pre",
485
403
  {
486
- "data-language": node.attrs["language"],
487
- class: utils.getClassName(node.attrs, "code-fence")
404
+ "data-language": n.attrs.language,
405
+ class: c.getClassName(n.attrs, "code-fence")
488
406
  },
489
407
  ["code", { spellCheck: "false" }, 0]
490
408
  ]
491
409
  ];
492
410
  },
493
411
  parseMarkdown: {
494
- match: ({ type }) => type === "code",
495
- runner: (state, node, type) => {
496
- const language = node["lang"];
497
- const value = node["value"];
498
- state.openNode(type, { language });
499
- if (value) {
500
- state.addText(value);
501
- }
502
- state.closeNode();
412
+ match: ({ type: n }) => n === "code",
413
+ runner: (n, o, a) => {
414
+ const s = o.lang, l = o.value;
415
+ n.openNode(a, { language: s }), l && n.addText(l), n.closeNode();
503
416
  }
504
417
  },
505
418
  toMarkdown: {
506
- match: (node) => node.type.name === id$5,
507
- runner: (state, node) => {
508
- var _a;
509
- state.addNode("code", void 0, ((_a = node.content.firstChild) == null ? void 0 : _a.text) || "", {
510
- lang: node.attrs["language"]
419
+ match: (n) => n.type.name === V,
420
+ runner: (n, o) => {
421
+ var a;
422
+ n.addNode("code", void 0, ((a = o.content.firstChild) == null ? void 0 : a.text) || "", {
423
+ lang: o.attrs.language
511
424
  });
512
425
  }
513
426
  }
514
427
  }),
515
- inputRules: (nodeType) => [
516
- textblockTypeInputRule(backtickInputRegex, nodeType, (match) => {
517
- const [ok, language] = match;
518
- if (!ok)
519
- return;
520
- return { language };
428
+ inputRules: (r) => [
429
+ G(Xe, r, (n) => {
430
+ const [o, a] = n;
431
+ if (!!o)
432
+ return { language: a };
521
433
  }),
522
- textblockTypeInputRule(tildeInputRegex, nodeType, (match) => {
523
- const [ok, language] = match;
524
- if (!ok)
525
- return;
526
- return { language };
434
+ G(Ye, r, (n) => {
435
+ const [o, a] = n;
436
+ if (!!o)
437
+ return { language: a };
527
438
  })
528
439
  ],
529
- commands: (nodeType) => [createCmd(TurnIntoCodeFence, () => setBlockType(nodeType))],
440
+ commands: (r) => [M(re, () => E(r))],
530
441
  shortcuts: {
531
- [SupportedKeys.CodeFence]: createShortcut(TurnIntoCodeFence, "Mod-Alt-c")
442
+ [k.CodeFence]: h(re, "Mod-Alt-c")
532
443
  },
533
- view: () => (node, view, getPos) => {
534
- let currNode = node;
535
- const onSelectLanguage = (language) => {
536
- const { tr } = view.state;
537
- view.dispatch(tr.setNodeMarkup(getPos(), void 0, {
538
- fold: true,
539
- language
444
+ view: () => (r, n, o) => {
445
+ let a = r;
446
+ const s = (p) => {
447
+ const { tr: b } = n.state;
448
+ n.dispatch(b.setNodeMarkup(o(), void 0, {
449
+ fold: !0,
450
+ language: p
540
451
  }));
541
- };
542
- const onBlur = () => {
543
- const { tr } = view.state;
544
- view.dispatch(tr.setNodeMarkup(getPos(), void 0, __spreadProps(__spreadValues({}, currNode.attrs), {
545
- fold: true
546
- })));
547
- };
548
- const onFocus = () => {
549
- const { tr } = view.state;
550
- view.dispatch(tr.setNodeMarkup(getPos(), void 0, __spreadProps(__spreadValues({}, currNode.attrs), {
551
- fold: false
552
- })));
553
- };
554
- const renderer = utils.themeManager.get("code-fence", {
555
- onBlur,
556
- onFocus,
557
- onSelectLanguage,
558
- editable: () => view.editable,
559
- languageList
452
+ }, l = () => {
453
+ const { tr: p } = n.state;
454
+ n.dispatch(p.setNodeMarkup(o(), void 0, {
455
+ ...a.attrs,
456
+ fold: !0
457
+ }));
458
+ }, i = () => {
459
+ const { tr: p } = n.state;
460
+ n.dispatch(p.setNodeMarkup(o(), void 0, {
461
+ ...a.attrs,
462
+ fold: !1
463
+ }));
464
+ }, u = c.themeManager.get("code-fence", {
465
+ onBlur: l,
466
+ onFocus: i,
467
+ onSelectLanguage: s,
468
+ editable: () => n.editable,
469
+ languageList: t
560
470
  });
561
- if (!renderer)
471
+ if (!u)
562
472
  return {};
563
- const { dom, contentDOM, onUpdate, onDestroy } = renderer;
564
- onUpdate(currNode);
565
- return {
566
- dom,
567
- contentDOM,
568
- update: (updatedNode) => {
569
- if (updatedNode.type.name !== id$5)
570
- return false;
571
- currNode = updatedNode;
572
- onUpdate(currNode);
573
- return true;
574
- },
575
- destroy: onDestroy
473
+ const { dom: g, contentDOM: d, onUpdate: m, onDestroy: f } = u;
474
+ return m(a), {
475
+ dom: g,
476
+ contentDOM: d,
477
+ update: (p) => p.type.name !== V ? !1 : (a = p, m(a), !0),
478
+ destroy: f
576
479
  };
577
480
  }
578
481
  };
579
- });
580
- const doc = createNode(() => {
581
- return {
582
- id: "doc",
583
- schema: () => ({
584
- content: "block+",
585
- parseMarkdown: {
586
- match: ({ type }) => type === "root",
587
- runner: (state, node, type) => {
588
- state.injectRoot(node, type);
589
- }
590
- },
591
- toMarkdown: {
592
- match: (node) => node.type.name === "doc",
593
- runner: (state, node) => {
594
- state.openNode("root");
595
- state.next(node.content);
596
- }
482
+ }), et = w(() => ({
483
+ id: "doc",
484
+ schema: () => ({
485
+ content: "block+",
486
+ parseMarkdown: {
487
+ match: ({ type: c }) => c === "root",
488
+ runner: (c, e, t) => {
489
+ c.injectRoot(e, t);
597
490
  }
598
- })
599
- };
600
- });
601
- const InsertHardbreak = createCmdKey("InsertHardbreak");
602
- const hardbreak = createNode((utils) => {
491
+ },
492
+ toMarkdown: {
493
+ match: (c) => c.type.name === "doc",
494
+ runner: (c, e) => {
495
+ c.openNode("root"), c.next(e.content);
496
+ }
497
+ }
498
+ })
499
+ })), ne = I("InsertHardbreak"), tt = new T("MILKDOWN_HARDBREAK_FILTER"), rt = w((c, e) => {
500
+ var r;
501
+ const t = (r = e == null ? void 0 : e.notIn) != null ? r : ["table", "fence"];
603
502
  return {
604
503
  id: "hardbreak",
605
504
  schema: () => ({
606
- inline: true,
505
+ inline: !0,
607
506
  group: "inline",
608
- selectable: false,
507
+ selectable: !1,
609
508
  parseDOM: [{ tag: "br" }],
610
- toDOM: (node) => ["br", { class: utils.getClassName(node.attrs, "hardbreak") }],
509
+ toDOM: (n) => ["br", { class: c.getClassName(n.attrs, "hardbreak") }],
611
510
  parseMarkdown: {
612
- match: ({ type }) => type === "break",
613
- runner: (state, _, type) => {
614
- state.addNode(type);
511
+ match: ({ type: n }) => n === "break",
512
+ runner: (n, o, a) => {
513
+ n.addNode(a);
615
514
  }
616
515
  },
617
516
  toMarkdown: {
618
- match: (node) => node.type.name === "hardbreak",
619
- runner: (state) => {
620
- state.addNode("break");
517
+ match: (n) => n.type.name === "hardbreak",
518
+ runner: (n) => {
519
+ n.addNode("break");
621
520
  }
622
521
  }
623
522
  }),
624
- commands: (type) => [
625
- createCmd(InsertHardbreak, () => (state, dispatch) => {
626
- dispatch == null ? void 0 : dispatch(state.tr.setMeta("hardbreak", true).replaceSelectionWith(type.create()).scrollIntoView());
627
- return true;
523
+ commands: (n) => [
524
+ M(ne, () => (o, a) => {
525
+ var i;
526
+ const { selection: s, tr: l } = o;
527
+ if (s.empty) {
528
+ const u = s.$from.node();
529
+ if (u.childCount > 0 && ((i = u.lastChild) == null ? void 0 : i.type.name) === "hardbreak")
530
+ return a == null || a(l.replaceRangeWith(s.to - 1, s.to, o.schema.node("paragraph")).setSelection(Le.near(l.doc.resolve(s.to))).scrollIntoView()), !0;
531
+ }
532
+ return a == null || a(l.setMeta("hardbreak", !0).replaceSelectionWith(n.create()).scrollIntoView()), !0;
628
533
  })
629
534
  ],
630
535
  shortcuts: {
631
- [SupportedKeys.HardBreak]: createShortcut(InsertHardbreak, "Shift-Enter")
536
+ [k.HardBreak]: h(ne, "Shift-Enter")
632
537
  },
633
- prosePlugins: (type) => [
634
- new Plugin({
635
- key: new PluginKey("MILKDOWN_HARDBREAK_MARKS"),
636
- appendTransaction: (trs, _oldState, newState) => {
637
- if (!trs.length)
538
+ prosePlugins: (n) => [
539
+ new H({
540
+ key: tt,
541
+ filterTransaction: (o, a) => {
542
+ const s = o.getMeta("hardbreak"), [l] = o.steps;
543
+ if (s && l) {
544
+ const { from: i } = l, u = a.doc.resolve(i);
545
+ let g = u.depth, d = !0;
546
+ for (; g > 0; )
547
+ t.includes(u.node(g).type.name) && (d = !1), g--;
548
+ return d;
549
+ }
550
+ return !0;
551
+ }
552
+ }),
553
+ new H({
554
+ key: new T("MILKDOWN_HARDBREAK_MARKS"),
555
+ appendTransaction: (o, a, s) => {
556
+ if (!o.length)
638
557
  return;
639
- const [tr] = trs;
640
- if (!tr)
558
+ const [l] = o;
559
+ if (!l)
641
560
  return;
642
- const [step] = tr.steps;
643
- const isInsertHr = tr.getMeta("hardbreak");
644
- if (isInsertHr) {
645
- if (!(step instanceof ReplaceStep)) {
561
+ const [i] = l.steps;
562
+ if (l.getMeta("hardbreak")) {
563
+ if (!(i instanceof $e))
646
564
  return;
647
- }
648
- const { from } = step;
649
- return newState.tr.setNodeMarkup(from, type, void 0, []);
565
+ const { from: d } = i;
566
+ return s.tr.setNodeMarkup(d, n, void 0, []);
650
567
  }
651
- const isAddMarkStep = step instanceof AddMarkStep;
652
- if (isAddMarkStep) {
653
- let _tr = newState.tr;
654
- const { from, to } = step;
655
- newState.doc.nodesBetween(from, to, (node, pos) => {
656
- if (node.type === type) {
657
- _tr = _tr.setNodeMarkup(pos, type, void 0, []);
658
- }
659
- });
660
- return _tr;
568
+ if (i instanceof Se) {
569
+ let d = s.tr;
570
+ const { from: m, to: f } = i;
571
+ return s.doc.nodesBetween(m, f, (p, b) => {
572
+ p.type === n && (d = d.setNodeMarkup(b, n, void 0, []));
573
+ }), d;
661
574
  }
662
- return;
663
575
  }
664
576
  })
665
577
  ]
666
578
  };
667
- });
668
- const headingIndex = Array(6).fill(0).map((_, i) => i + 1);
669
- const TurnIntoHeading = createCmdKey("TurnIntoHeading");
670
- const headingPluginKey = new PluginKey("MILKDOWN_ID");
671
- const createId = (node) => node.textContent.replace(/[\p{P}\p{S}]/gu, "").replace(/\s/g, "-").toLowerCase().trim();
672
- const heading = createNode((utils) => {
673
- const id2 = "heading";
579
+ }), ke = Array(6).fill(0).map((c, e) => e + 1), C = I("TurnIntoHeading"), Me = I("DowngradeHeading"), j = new T("MILKDOWN_HEADING_ID"), nt = new T("MILKDOWN_HEADING_HASH"), st = (c) => c.textContent.replace(/[\p{P}\p{S}]/gu, "").replace(/\s/g, "-").toLowerCase().trim(), ot = (c, e, t) => {
580
+ let r = !1;
581
+ const n = (o, a) => {
582
+ const s = o.tr;
583
+ o.doc.descendants((l, i) => {
584
+ if (l.type === e && !r) {
585
+ if (l.textContent.trim().length === 0)
586
+ return;
587
+ const u = l.attrs, g = t(l);
588
+ u.id !== g && s.setMeta(j, !0).setNodeMarkup(i, void 0, {
589
+ ...u,
590
+ id: g
591
+ });
592
+ }
593
+ }), a(s);
594
+ };
595
+ return new H({
596
+ key: j,
597
+ props: {
598
+ handleDOMEvents: {
599
+ compositionstart: () => (r = !0, !1),
600
+ compositionend: () => {
601
+ r = !1;
602
+ const o = c.get(B);
603
+ return setTimeout(() => {
604
+ n(o.state, (a) => o.dispatch(a));
605
+ }, 0), !1;
606
+ }
607
+ }
608
+ },
609
+ appendTransaction: (o, a, s) => {
610
+ let l = null;
611
+ return o.every((i) => !i.getMeta(j)) && o.some((i) => i.docChanged) && n(s, (i) => {
612
+ l = i;
613
+ }), l;
614
+ },
615
+ view: (o) => {
616
+ const a = o.state.doc;
617
+ let s = o.state.tr;
618
+ return a.descendants((l, i) => {
619
+ l.type.name === "heading" && l.attrs.level && (l.attrs.id || (s = s.setNodeMarkup(i, void 0, {
620
+ ...l.attrs,
621
+ id: t(l)
622
+ })));
623
+ }), o.dispatch(s), {};
624
+ }
625
+ });
626
+ }, at = (c, e, t) => new H({
627
+ key: nt,
628
+ state: {
629
+ init: () => O.empty,
630
+ apply: (r) => {
631
+ const n = c.get(B);
632
+ if (!n.hasFocus || !n.editable)
633
+ return O.empty;
634
+ const { $from: o } = r.selection, a = o.node();
635
+ if (a.type !== e)
636
+ return O.empty;
637
+ const s = a.attrs.level, l = (g) => Array(g).fill(0).map((d) => "#").join(""), i = document.createElement("span");
638
+ i.textContent = l(s), i.contentEditable = "false", t.themeManager.onFlush(() => {
639
+ const g = t.getStyle(({ css: d }) => {
640
+ const m = Te(t.themeManager);
641
+ return d`
642
+ margin-right: 4px;
643
+ color: ${m("primary")};
644
+ `;
645
+ });
646
+ g && (i.className = g);
647
+ });
648
+ const u = J.widget(o.before() + 1, i, { side: -1 });
649
+ return O.create(r.doc, [u]);
650
+ }
651
+ },
652
+ props: {
653
+ handleDOMEvents: {
654
+ focus: (r) => {
655
+ const n = Ae(r.state.tr);
656
+ return r.dispatch(n), !1;
657
+ }
658
+ },
659
+ decorations(r) {
660
+ return this.getState(r);
661
+ }
662
+ }
663
+ }), lt = w((c, e) => {
664
+ var o, a;
665
+ const t = "heading", r = (o = e == null ? void 0 : e.getId) != null ? o : st, n = (a = e == null ? void 0 : e.displayHashtag) != null ? a : !0;
674
666
  return {
675
- id: id2,
667
+ id: t,
676
668
  schema: () => ({
677
669
  content: "inline*",
678
670
  group: "block",
679
- defining: true,
671
+ defining: !0,
680
672
  attrs: {
681
673
  id: {
682
674
  default: ""
@@ -685,393 +677,351 @@ const heading = createNode((utils) => {
685
677
  default: 1
686
678
  }
687
679
  },
688
- parseDOM: headingIndex.map((x) => ({
689
- tag: `h${x}`,
690
- getAttrs: (node) => {
691
- if (!(node instanceof HTMLElement)) {
692
- throw new Error();
693
- }
694
- return { level: x, id: node.id };
680
+ parseDOM: ke.map((s) => ({
681
+ tag: `h${s}`,
682
+ getAttrs: (l) => {
683
+ if (!(l instanceof HTMLElement))
684
+ throw D(l);
685
+ return { level: s, id: l.id };
695
686
  }
696
687
  })),
697
- toDOM: (node) => {
698
- return [
699
- `h${node.attrs["level"]}`,
700
- {
701
- id: node.attrs["id"] || createId(node),
702
- class: utils.getClassName(node.attrs, `heading h${node.attrs["level"]}`)
703
- },
704
- 0
705
- ];
706
- },
688
+ toDOM: (s) => [
689
+ `h${s.attrs.level}`,
690
+ {
691
+ id: s.attrs.id || r(s),
692
+ class: c.getClassName(s.attrs, `heading h${s.attrs.level}`)
693
+ },
694
+ 0
695
+ ],
707
696
  parseMarkdown: {
708
- match: ({ type }) => type === id2,
709
- runner: (state, node, type) => {
710
- const depth = node["depth"];
711
- state.openNode(type, { level: depth });
712
- state.next(node.children);
713
- state.closeNode();
697
+ match: ({ type: s }) => s === t,
698
+ runner: (s, l, i) => {
699
+ const u = l.depth;
700
+ s.openNode(i, { level: u }), s.next(l.children), s.closeNode();
714
701
  }
715
702
  },
716
703
  toMarkdown: {
717
- match: (node) => node.type.name === id2,
718
- runner: (state, node) => {
719
- state.openNode("heading", void 0, { depth: node.attrs["level"] });
720
- state.next(node.content);
721
- state.closeNode();
704
+ match: (s) => s.type.name === t,
705
+ runner: (s, l) => {
706
+ var u;
707
+ if (s.openNode("heading", void 0, { depth: l.attrs.level }), l.childCount >= 1 && ((u = l.lastChild) == null ? void 0 : u.type.name) === "hardbreak") {
708
+ const g = [];
709
+ l.content.forEach((d, m, f) => {
710
+ f !== l.childCount - 1 && g.push(d);
711
+ }), s.next(ge.fromArray(g));
712
+ } else
713
+ s.next(l.content);
714
+ s.closeNode();
722
715
  }
723
716
  }
724
717
  }),
725
- inputRules: (type) => headingIndex.map((x) => textblockTypeInputRule(new RegExp(`^(#{1,${x}})\\s$`), type, () => ({
726
- level: x
727
- }))),
728
- commands: (type) => [createCmd(TurnIntoHeading, (level = 1) => setBlockType(type, { level }))],
718
+ inputRules: (s, l) => ke.map((i) => G(new RegExp(`^(#{1,${i}})\\s$`), s, () => {
719
+ const u = l.get(B), { $from: g } = u.state.selection, d = g.node();
720
+ if (d.type.name === "heading") {
721
+ let m = Number(d.attrs.level) + Number(i);
722
+ return m > 6 && (m = 6), {
723
+ level: m
724
+ };
725
+ }
726
+ return {
727
+ level: i
728
+ };
729
+ })),
730
+ commands: (s, l) => [
731
+ M(C, (i = 1) => i < 1 ? E(i === 0 && l.get(A).nodes.paragraph || s) : E(i === 0 && l.get(A).nodes.paragraph || s, { level: i })),
732
+ M(Me, () => (i, u, g) => {
733
+ const { $from: d } = i.selection, m = d.node();
734
+ if (m.type !== s || !i.selection.empty || d.parentOffset !== 0)
735
+ return !1;
736
+ const f = m.attrs.level - 1;
737
+ return f ? (u == null || u(i.tr.setNodeMarkup(i.selection.$from.before(), void 0, {
738
+ ...m.attrs,
739
+ level: f
740
+ })), !0) : E(l.get(A).nodes.paragraph || s)(i, u, g);
741
+ })
742
+ ],
729
743
  shortcuts: {
730
- [SupportedKeys.H1]: createShortcut(TurnIntoHeading, "Mod-Alt-1", 1),
731
- [SupportedKeys.H2]: createShortcut(TurnIntoHeading, "Mod-Alt-2", 2),
732
- [SupportedKeys.H3]: createShortcut(TurnIntoHeading, "Mod-Alt-3", 3),
733
- [SupportedKeys.H4]: createShortcut(TurnIntoHeading, "Mod-Alt-4", 4),
734
- [SupportedKeys.H5]: createShortcut(TurnIntoHeading, "Mod-Alt-5", 5),
735
- [SupportedKeys.H6]: createShortcut(TurnIntoHeading, "Mod-Alt-6", 6)
744
+ [k.H1]: h(C, "Mod-Alt-1", 1),
745
+ [k.H2]: h(C, "Mod-Alt-2", 2),
746
+ [k.H3]: h(C, "Mod-Alt-3", 3),
747
+ [k.H4]: h(C, "Mod-Alt-4", 4),
748
+ [k.H5]: h(C, "Mod-Alt-5", 5),
749
+ [k.H6]: h(C, "Mod-Alt-6", 6),
750
+ [k.DowngradeHeading]: h(Me, ["Backspace", "Delete"])
736
751
  },
737
- prosePlugins: (type, ctx) => {
738
- let lock = false;
739
- const walkThrough = (state, callback) => {
740
- const tr = state.tr;
741
- state.doc.descendants((node, pos) => {
742
- if (node.type === type && !lock) {
743
- if (node.textContent.trim().length === 0) {
744
- return;
745
- }
746
- const attrs = node.attrs;
747
- const id22 = createId(node);
748
- if (attrs["id"] !== id22) {
749
- tr.setMeta(headingPluginKey, true).setNodeMarkup(pos, void 0, __spreadProps(__spreadValues({}, attrs), {
750
- id: id22
751
- }));
752
- }
753
- }
754
- });
755
- callback(tr);
756
- };
757
- return [
758
- new Plugin({
759
- key: headingPluginKey,
760
- props: {
761
- handleDOMEvents: {
762
- compositionstart: () => {
763
- lock = true;
764
- return false;
765
- },
766
- compositionend: () => {
767
- lock = false;
768
- const view = ctx.get(editorViewCtx);
769
- setTimeout(() => {
770
- walkThrough(view.state, (tr) => view.dispatch(tr));
771
- }, 0);
772
- return false;
773
- }
774
- }
775
- },
776
- appendTransaction: (transactions, _, nextState) => {
777
- let tr = null;
778
- if (transactions.every((transaction) => !transaction.getMeta(headingPluginKey)) && transactions.some((transaction) => transaction.docChanged)) {
779
- walkThrough(nextState, (t) => {
780
- tr = t;
781
- });
782
- }
783
- return tr;
784
- }
785
- })
786
- ];
752
+ prosePlugins: (s, l) => {
753
+ const i = [ot(l, s, r)];
754
+ return n && i.push(at(l, s, c)), i;
787
755
  }
788
756
  };
789
- });
790
- const id$4 = "hr";
791
- const InsertHr = createCmdKey("InsertHr");
792
- const hr = createNode((utils) => {
793
- return {
794
- id: id$4,
795
- schema: () => ({
796
- group: "block",
797
- parseDOM: [{ tag: "hr" }],
798
- toDOM: (node) => ["hr", { class: utils.getClassName(node.attrs, id$4) }],
799
- parseMarkdown: {
800
- match: ({ type }) => type === "thematicBreak",
801
- runner: (state, _, type) => {
802
- state.addNode(type);
803
- }
804
- },
805
- toMarkdown: {
806
- match: (node) => node.type.name === id$4,
807
- runner: (state) => {
808
- state.addNode("thematicBreak");
809
- }
757
+ }), z = "hr", Ce = I("InsertHr"), ct = w((c) => ({
758
+ id: z,
759
+ schema: () => ({
760
+ group: "block",
761
+ parseDOM: [{ tag: "hr" }],
762
+ toDOM: (e) => ["hr", { class: c.getClassName(e.attrs, z) }],
763
+ parseMarkdown: {
764
+ match: ({ type: e }) => e === "thematicBreak",
765
+ runner: (e, t, r) => {
766
+ e.addNode(r);
810
767
  }
811
- }),
812
- inputRules: (type) => [
813
- new InputRule(/^(?:---|___\s|\*\*\*\s)$/, (state, match, start, end) => {
814
- const { tr } = state;
815
- if (match[0]) {
816
- tr.replaceWith(start - 1, end, type.create());
817
- }
818
- return tr;
819
- })
820
- ],
821
- commands: (type, ctx) => [
822
- createCmd(InsertHr, () => (state, dispatch) => {
823
- if (!dispatch)
824
- return true;
825
- const { tr, selection } = state;
826
- const from = selection.from;
827
- const node = type.create();
828
- if (!node) {
829
- return true;
830
- }
831
- const _tr = tr.replaceSelectionWith(node).insert(from, ctx.get(schemaCtx).node("paragraph"));
832
- const sel = Selection.findFrom(_tr.doc.resolve(from), 1, true);
833
- if (!sel) {
834
- return true;
835
- }
836
- dispatch(_tr.setSelection(sel).scrollIntoView());
837
- return true;
838
- })
839
- ]
840
- };
841
- });
842
- const ModifyImage = createCmdKey("ModifyImage");
843
- const InsertImage = createCmdKey("InsertImage");
844
- const id$3 = "image";
845
- const key = new PluginKey("MILKDOWN_IMAGE_INPUT");
846
- const image = createNode((utils, options) => {
847
- return {
848
- id: "image",
849
- schema: () => ({
850
- inline: true,
851
- group: "inline",
852
- selectable: true,
853
- draggable: true,
854
- marks: "",
855
- atom: true,
856
- defining: true,
857
- isolating: true,
858
- attrs: {
859
- src: { default: "" },
860
- alt: { default: null },
861
- title: { default: null }
862
- },
863
- parseDOM: [
864
- {
865
- tag: "img[src]",
866
- getAttrs: (dom) => {
867
- if (!(dom instanceof HTMLElement)) {
868
- throw new Error();
869
- }
870
- return {
871
- src: dom.getAttribute("src") || "",
872
- alt: dom.getAttribute("alt"),
873
- title: dom.getAttribute("title") || dom.getAttribute("alt"),
874
- width: dom.getAttribute("width")
875
- };
876
- }
877
- }
878
- ],
879
- toDOM: (node) => {
880
- return [
881
- "img",
882
- __spreadProps(__spreadValues({}, node.attrs), {
883
- class: utils.getClassName(node.attrs, id$3)
884
- })
885
- ];
886
- },
887
- parseMarkdown: {
888
- match: ({ type }) => type === id$3,
889
- runner: (state, node, type) => {
890
- const url = node["url"];
891
- const alt = node["alt"];
892
- const title = node["title"];
893
- state.addNode(type, {
894
- src: url,
895
- alt,
896
- title
897
- });
898
- }
899
- },
900
- toMarkdown: {
901
- match: (node) => node.type.name === id$3,
902
- runner: (state, node) => {
903
- state.addNode("image", void 0, void 0, {
904
- title: node.attrs["title"],
905
- url: node.attrs["src"],
906
- alt: node.attrs["alt"]
907
- });
908
- }
768
+ },
769
+ toMarkdown: {
770
+ match: (e) => e.type.name === z,
771
+ runner: (e) => {
772
+ e.addNode("thematicBreak");
909
773
  }
910
- }),
911
- commands: (type) => [
912
- createCmd(InsertImage, (src = "") => (state, dispatch) => {
913
- if (!dispatch)
914
- return true;
915
- const { tr } = state;
916
- const node = type.create({ src });
917
- if (!node) {
918
- return true;
774
+ }
775
+ }),
776
+ inputRules: (e) => [
777
+ new me(/^(?:---|___\s|\*\*\*\s)$/, (t, r, n, o) => {
778
+ const { tr: a } = t;
779
+ return r[0] && a.replaceWith(n - 1, o, e.create()), a;
780
+ })
781
+ ],
782
+ commands: (e, t) => [
783
+ M(Ce, () => (r, n) => {
784
+ if (!n)
785
+ return !0;
786
+ const o = t.get(A).node("paragraph"), { tr: a, selection: s } = r, { from: l } = s, i = e.create();
787
+ if (!i)
788
+ return !0;
789
+ const u = a.replaceSelectionWith(i).insert(l, o), g = Le.findFrom(u.doc.resolve(l), 1, !0);
790
+ return g && n(u.setSelection(g).scrollIntoView()), !0;
791
+ })
792
+ ]
793
+ })), se = I("ModifyImage"), De = I("InsertImage"), S = "image", it = new T("MILKDOWN_IMAGE_INPUT"), ut = w((c, e) => ({
794
+ id: "image",
795
+ schema: () => ({
796
+ inline: !0,
797
+ group: "inline",
798
+ selectable: !0,
799
+ draggable: !0,
800
+ marks: "",
801
+ atom: !0,
802
+ defining: !0,
803
+ isolating: !0,
804
+ attrs: {
805
+ src: { default: "" },
806
+ alt: { default: null },
807
+ title: { default: null }
808
+ },
809
+ parseDOM: [
810
+ {
811
+ tag: "img[src]",
812
+ getAttrs: (t) => {
813
+ if (!(t instanceof HTMLElement))
814
+ throw D(t);
815
+ return {
816
+ src: t.getAttribute("src") || "",
817
+ alt: t.getAttribute("alt"),
818
+ title: t.getAttribute("title") || t.getAttribute("alt"),
819
+ width: t.getAttribute("width")
820
+ };
919
821
  }
920
- const _tr = tr.replaceSelectionWith(node);
921
- dispatch(_tr.scrollIntoView());
922
- return true;
923
- }),
924
- createCmd(ModifyImage, (src = "") => (state, dispatch) => {
925
- const node = findSelectedNodeOfType(state.selection, type);
926
- if (!node)
927
- return false;
928
- const { tr } = state;
929
- dispatch == null ? void 0 : dispatch(tr.setNodeMarkup(node.pos, void 0, __spreadProps(__spreadValues({}, node.node.attrs), { loading: true, src })).scrollIntoView());
930
- return true;
931
- })
822
+ }
932
823
  ],
933
- inputRules: (type) => [
934
- new InputRule(/!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/, (state, match, start, end) => {
935
- const [okay, alt, src = "", title] = match;
936
- const { tr } = state;
937
- if (okay) {
938
- tr.replaceWith(start, end, type.create({ src, alt, title }));
939
- }
940
- return tr;
941
- })
824
+ toDOM: (t) => [
825
+ "img",
826
+ {
827
+ ...t.attrs,
828
+ class: c.getClassName(t.attrs, S)
829
+ }
942
830
  ],
943
- view: () => (node) => {
944
- var _a, _b;
945
- let currNode = node;
946
- const placeholder = (_a = options == null ? void 0 : options.placeholder) != null ? _a : "Add an Image";
947
- const isBlock = (_b = options == null ? void 0 : options.isBlock) != null ? _b : false;
948
- const renderer = utils.themeManager.get("image", {
949
- placeholder,
950
- isBlock
951
- });
952
- if (!renderer) {
953
- return {};
831
+ parseMarkdown: {
832
+ match: ({ type: t }) => t === S,
833
+ runner: (t, r, n) => {
834
+ const o = r.url, a = r.alt, s = r.title;
835
+ t.addNode(n, {
836
+ src: o,
837
+ alt: a,
838
+ title: s
839
+ });
954
840
  }
955
- const { dom, onUpdate } = renderer;
956
- onUpdate(currNode);
957
- return {
958
- dom,
959
- update: (updatedNode) => {
960
- if (updatedNode.type.name !== id$3)
961
- return false;
962
- currNode = updatedNode;
963
- onUpdate(currNode);
964
- return true;
965
- },
966
- selectNode: () => {
967
- dom.classList.add("ProseMirror-selectednode");
968
- },
969
- deselectNode: () => {
970
- dom.classList.remove("ProseMirror-selectednode");
971
- }
972
- };
973
841
  },
974
- prosePlugins: (type, ctx) => {
975
- return [
976
- new Plugin({
977
- key,
978
- view: (editorView) => {
979
- var _a, _b, _c;
980
- const inputChipRenderer = utils.themeManager.get("input-chip", {
981
- placeholder: (_b = (_a = options == null ? void 0 : options.input) == null ? void 0 : _a.placeholder) != null ? _b : "Input Image Link",
982
- buttonText: (_c = options == null ? void 0 : options.input) == null ? void 0 : _c.buttonText,
983
- onUpdate: (value) => {
984
- ctx.get(commandsCtx).call(ModifyImage, value);
985
- }
986
- });
987
- if (!inputChipRenderer)
988
- return {};
989
- const shouldDisplay = (view) => {
990
- return Boolean(view.hasFocus() && type && findSelectedNodeOfType(view.state.selection, type));
991
- };
992
- const getCurrentLink = (view) => {
993
- const result = findSelectedNodeOfType(view.state.selection, type);
994
- if (!result)
995
- return;
996
- const value = result.node.attrs["src"];
997
- return value;
998
- };
999
- const renderByView = (view) => {
1000
- if (!view.editable) {
1001
- return;
1002
- }
1003
- const display = shouldDisplay(view);
1004
- if (display) {
1005
- inputChipRenderer.show(view);
1006
- inputChipRenderer.update(getCurrentLink(view));
1007
- } else {
1008
- inputChipRenderer.hide();
1009
- }
1010
- };
1011
- inputChipRenderer.init(editorView);
1012
- renderByView(editorView);
1013
- return {
1014
- update: (view, prevState) => {
1015
- const isEqualSelection = (prevState == null ? void 0 : prevState.doc.eq(view.state.doc)) && prevState.selection.eq(view.state.selection);
1016
- if (isEqualSelection)
1017
- return;
1018
- renderByView(view);
1019
- },
1020
- destroy: () => {
1021
- inputChipRenderer.destroy();
1022
- }
1023
- };
1024
- }
1025
- })
1026
- ];
842
+ toMarkdown: {
843
+ match: (t) => t.type.name === S,
844
+ runner: (t, r) => {
845
+ t.addNode("image", void 0, void 0, {
846
+ title: r.attrs.title,
847
+ url: r.attrs.src,
848
+ alt: r.attrs.alt
849
+ });
850
+ }
1027
851
  }
852
+ }),
853
+ commands: (t) => [
854
+ M(De, (r = "") => (n, o) => {
855
+ if (!o)
856
+ return !0;
857
+ const { tr: a } = n, s = t.create({ src: r });
858
+ if (!s)
859
+ return !0;
860
+ const l = a.replaceSelectionWith(s);
861
+ return o(l.scrollIntoView()), !0;
862
+ }),
863
+ M(se, (r = "") => (n, o) => {
864
+ const a = K(n.selection, t);
865
+ if (!a)
866
+ return !1;
867
+ const { tr: s } = n;
868
+ return o == null || o(s.setNodeMarkup(a.pos, void 0, { ...a.node.attrs, loading: !0, src: r }).scrollIntoView()), !0;
869
+ })
870
+ ],
871
+ inputRules: (t) => [
872
+ new me(/!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/, (r, n, o, a) => {
873
+ const [s, l, i = "", u] = n, { tr: g } = r;
874
+ return s && g.replaceWith(o, a, t.create({ src: i, alt: l, title: u })), g;
875
+ })
876
+ ],
877
+ view: () => (t) => {
878
+ var i, u;
879
+ let r = t;
880
+ 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, a = c.themeManager.get("image", {
881
+ placeholder: n,
882
+ isBlock: o
883
+ });
884
+ if (!a)
885
+ return {};
886
+ const { dom: s, onUpdate: l } = a;
887
+ return l(r), {
888
+ dom: s,
889
+ update: (g) => g.type.name !== S ? !1 : (r = g, l(r), !0),
890
+ selectNode: () => {
891
+ s.classList.add("ProseMirror-selectednode");
892
+ },
893
+ deselectNode: () => {
894
+ s.classList.remove("ProseMirror-selectednode");
895
+ }
896
+ };
897
+ },
898
+ prosePlugins: (t, r) => [
899
+ new H({
900
+ key: it,
901
+ view: (n) => {
902
+ var i, u, g;
903
+ const o = c.themeManager.get("input-chip", {
904
+ placeholder: (u = (i = e == null ? void 0 : e.input) == null ? void 0 : i.placeholder) != null ? u : "Input Image Link",
905
+ buttonText: (g = e == null ? void 0 : e.input) == null ? void 0 : g.buttonText,
906
+ onUpdate: (d) => {
907
+ r.get(we).call(se, d);
908
+ }
909
+ });
910
+ if (!o)
911
+ return {};
912
+ const a = (d) => Boolean(d.hasFocus() && t && K(d.state.selection, t)), s = (d) => {
913
+ const m = K(d.state.selection, t);
914
+ return m ? m.node.attrs.src : void 0;
915
+ }, l = (d) => {
916
+ if (!d.editable)
917
+ return;
918
+ a(d) ? (o.show(d), o.update(s(d))) : o.hide();
919
+ };
920
+ return o.init(n), l(n), {
921
+ update: (d, m) => {
922
+ (m == null ? void 0 : m.doc.eq(d.state.doc)) && m.selection.eq(d.state.selection) || l(d);
923
+ },
924
+ destroy: () => {
925
+ o.destroy();
926
+ }
927
+ };
928
+ }
929
+ })
930
+ ]
931
+ })), Ie = "list_item", oe = I("SplitListItem"), ae = I("SinkListItem"), le = I("LiftListItem"), dt = new T("MILKDOWN_KEEP_LIST_ORDER"), mt = (c) => {
932
+ const e = (t, r) => {
933
+ const n = Ee("ordered_list", t.schema);
934
+ let o = t.tr;
935
+ t.doc.descendants((a, s, l, i) => {
936
+ if (a.type === c && (l == null ? void 0 : l.type) === n) {
937
+ let u = !1;
938
+ const g = { ...a.attrs };
939
+ a.attrs.listType !== "ordered" && (g.listType = "ordered", u = !0);
940
+ const d = l == null ? void 0 : l.maybeChild(i - 1);
941
+ if (d && d.type === c && d.attrs.listType === "ordered") {
942
+ const m = d.attrs.label;
943
+ g.label = `${Number(m.slice(0, -1)) + 1}.`, u = !0;
944
+ }
945
+ a.attrs.label === "\u2022" && (g.label = `${i + 1}.`, u = !0), u && (o = o.setNodeMarkup(s, void 0, g));
946
+ }
947
+ }), r(o);
1028
948
  };
1029
- });
1030
- const id$2 = "list_item";
1031
- const SplitListItem = createCmdKey("SplitListItem");
1032
- const SinkListItem = createCmdKey("SinkListItem");
1033
- const LiftListItem = createCmdKey("LiftListItem");
1034
- const listItem = createNode((utils) => ({
1035
- id: id$2,
949
+ return new H({
950
+ key: dt,
951
+ appendTransaction: (t, r, n) => {
952
+ let o = null;
953
+ return t.some((a) => a.docChanged) && e(n, (a) => {
954
+ o = a;
955
+ }), o;
956
+ }
957
+ });
958
+ }, gt = w((c) => ({
959
+ id: Ie,
1036
960
  schema: () => ({
1037
961
  group: "listItem",
1038
962
  content: "paragraph block*",
1039
- defining: true,
1040
- parseDOM: [{ tag: "li" }],
1041
- toDOM: (node) => ["li", { class: utils.getClassName(node.attrs, "list-item") }, 0],
963
+ attrs: {
964
+ label: {
965
+ default: "\u2022"
966
+ },
967
+ listType: {
968
+ default: "bullet"
969
+ }
970
+ },
971
+ defining: !0,
972
+ parseDOM: [
973
+ {
974
+ tag: "li.list-item",
975
+ getAttrs: (e) => {
976
+ if (!(e instanceof HTMLElement))
977
+ throw D(e);
978
+ return {
979
+ label: e.dataset.label,
980
+ listType: e.dataset["list-type"]
981
+ };
982
+ },
983
+ contentElement: "div.list-item_body"
984
+ },
985
+ { tag: "li" }
986
+ ],
987
+ toDOM: (e) => [
988
+ "li",
989
+ {
990
+ class: c.getClassName(e.attrs, "list-item"),
991
+ "data-label": e.attrs.label,
992
+ "data-list-type": e.attrs.listType
993
+ },
994
+ ["div", { class: c.getClassName(e.attrs, "list-item_label") }, e.attrs.label],
995
+ ["div", { class: c.getClassName(e.attrs, "list-item_body") }, 0]
996
+ ],
1042
997
  parseMarkdown: {
1043
- match: ({ type, checked }) => type === "listItem" && checked === null,
1044
- runner: (state, node, type) => {
1045
- state.openNode(type);
1046
- state.next(node.children);
1047
- state.closeNode();
998
+ match: ({ type: e, checked: t }) => e === "listItem" && t === null,
999
+ runner: (e, t, r) => {
1000
+ const n = t.label != null ? `${t.label}.` : "\u2022", o = t.label != null ? "ordered" : "bullet";
1001
+ e.openNode(r, { label: n, listType: o }), e.next(t.children), e.closeNode();
1048
1002
  }
1049
1003
  },
1050
1004
  toMarkdown: {
1051
- match: (node) => node.type.name === id$2,
1052
- runner: (state, node) => {
1053
- state.openNode("listItem");
1054
- state.next(node.content);
1055
- state.closeNode();
1005
+ match: (e) => e.type.name === Ie,
1006
+ runner: (e, t) => {
1007
+ e.openNode("listItem"), e.next(t.content), e.closeNode();
1056
1008
  }
1057
1009
  }
1058
1010
  }),
1059
- inputRules: (nodeType) => [wrappingInputRule(/^\s*([-+*])\s$/, nodeType)],
1060
- commands: (nodeType) => [
1061
- createCmd(SplitListItem, () => splitListItem(nodeType)),
1062
- createCmd(SinkListItem, () => sinkListItem(nodeType)),
1063
- createCmd(LiftListItem, () => liftListItem(nodeType))
1011
+ inputRules: (e) => [W(/^\s*([-+*])\s$/, e)],
1012
+ commands: (e) => [
1013
+ M(oe, () => Re(e)),
1014
+ M(ae, () => Be(e)),
1015
+ M(le, () => Pe(e))
1064
1016
  ],
1065
1017
  shortcuts: {
1066
- [SupportedKeys.NextListItem]: createShortcut(SplitListItem, "Enter"),
1067
- [SupportedKeys.SinkListItem]: createShortcut(SinkListItem, "Mod-]"),
1068
- [SupportedKeys.LiftListItem]: createShortcut(LiftListItem, "Mod-[")
1069
- }
1070
- }));
1071
- const WrapInOrderedList = createCmdKey("WrapInOrderedList");
1072
- const id$1 = "ordered_list";
1073
- const orderedList = createNode((utils) => ({
1074
- id: id$1,
1018
+ [k.NextListItem]: h(oe, "Enter"),
1019
+ [k.SinkListItem]: h(ae, "Mod-]"),
1020
+ [k.LiftListItem]: h(le, "Mod-[")
1021
+ },
1022
+ prosePlugins: (e) => [mt(e)]
1023
+ })), ce = I("WrapInOrderedList"), be = "ordered_list", ft = w((c) => ({
1024
+ id: be,
1075
1025
  schema: () => ({
1076
1026
  content: "listItem+",
1077
1027
  group: "block",
@@ -1083,235 +1033,251 @@ const orderedList = createNode((utils) => ({
1083
1033
  parseDOM: [
1084
1034
  {
1085
1035
  tag: "ol",
1086
- getAttrs: (dom) => {
1087
- if (!(dom instanceof HTMLElement)) {
1088
- throw new Error();
1089
- }
1090
- return { order: dom.hasAttribute("start") ? Number(dom.getAttribute("start")) : 1 };
1036
+ getAttrs: (e) => {
1037
+ if (!(e instanceof HTMLElement))
1038
+ throw D(e);
1039
+ return { order: e.hasAttribute("start") ? Number(e.getAttribute("start")) : 1 };
1091
1040
  }
1092
1041
  }
1093
1042
  ],
1094
- toDOM: (node) => [
1043
+ toDOM: (e) => [
1095
1044
  "ol",
1096
- __spreadProps(__spreadValues({}, node.attrs["order"] === 1 ? {} : node.attrs["order"]), {
1097
- class: utils.getClassName(node.attrs, "ordered-list")
1098
- }),
1045
+ {
1046
+ ...e.attrs.order === 1 ? {} : e.attrs.order,
1047
+ class: c.getClassName(e.attrs, "ordered-list")
1048
+ },
1099
1049
  0
1100
1050
  ],
1101
1051
  parseMarkdown: {
1102
- match: ({ type, ordered }) => type === "list" && !!ordered,
1103
- runner: (state, node, type) => {
1104
- state.openNode(type).next(node.children).closeNode();
1052
+ match: ({ type: e, ordered: t }) => e === "list" && !!t,
1053
+ runner: (e, t, r) => {
1054
+ e.openNode(r).next(t.children).closeNode();
1105
1055
  }
1106
1056
  },
1107
1057
  toMarkdown: {
1108
- match: (node) => node.type.name === id$1,
1109
- runner: (state, node) => {
1110
- state.openNode("list", void 0, { ordered: true, start: 1 });
1111
- state.next(node.content);
1112
- state.closeNode();
1058
+ match: (e) => e.type.name === be,
1059
+ runner: (e, t) => {
1060
+ e.openNode("list", void 0, { ordered: !0, start: 1 }), e.next(t.content), e.closeNode();
1113
1061
  }
1114
1062
  }
1115
1063
  }),
1116
- inputRules: (nodeType) => [
1117
- wrappingInputRule(/^(\d+)\.\s$/, nodeType, (match) => ({ order: Number(match[1]) }), (match, node) => node.childCount + node.attrs["order"] === Number(match[1]))
1064
+ inputRules: (e) => [
1065
+ W(/^(\d+)\.\s$/, e, (t) => ({ order: Number(t[1]) }), (t, r) => r.childCount + r.attrs.order === Number(t[1]))
1118
1066
  ],
1119
- commands: (nodeType) => [createCmd(WrapInOrderedList, () => wrapIn(nodeType))],
1067
+ commands: (e) => [M(ce, () => de(e))],
1120
1068
  shortcuts: {
1121
- [SupportedKeys.OrderedList]: createShortcut(WrapInOrderedList, "Mod-Alt-7")
1069
+ [k.OrderedList]: h(ce, "Mod-Alt-7")
1122
1070
  }
1123
- }));
1124
- const TurnIntoText = createCmdKey("TurnIntoText");
1125
- const id = "paragraph";
1126
- const paragraph = createNode((utils) => {
1127
- return {
1128
- id,
1129
- schema: () => ({
1130
- content: "inline*",
1131
- group: "block",
1132
- parseDOM: [{ tag: "p" }],
1133
- toDOM: (node) => ["p", { class: utils.getClassName(node.attrs, id) }, 0],
1134
- parseMarkdown: {
1135
- match: (node) => node.type === "paragraph",
1136
- runner: (state, node, type) => {
1137
- state.openNode(type);
1138
- if (node.children) {
1139
- state.next(node.children);
1140
- } else {
1141
- state.addText(node["value"]);
1142
- }
1143
- state.closeNode();
1144
- }
1145
- },
1146
- toMarkdown: {
1147
- match: (node) => node.type.name === "paragraph",
1148
- runner: (state, node) => {
1149
- var _a;
1150
- state.openNode("paragraph");
1151
- const onlyHardbreak = node.childCount === 1 && ((_a = node.firstChild) == null ? void 0 : _a.type.name) === "hardbreak";
1152
- if (!onlyHardbreak) {
1153
- state.next(node.content);
1154
- }
1155
- state.closeNode();
1156
- }
1071
+ })), ie = I("TurnIntoText"), ye = "paragraph", pt = w((c) => ({
1072
+ id: ye,
1073
+ schema: () => ({
1074
+ content: "inline*",
1075
+ group: "block",
1076
+ parseDOM: [{ tag: "p" }],
1077
+ toDOM: (e) => ["p", { class: c.getClassName(e.attrs, ye) }, 0],
1078
+ parseMarkdown: {
1079
+ match: (e) => e.type === "paragraph",
1080
+ runner: (e, t, r) => {
1081
+ e.openNode(r), t.children ? e.next(t.children) : e.addText(t.value), e.closeNode();
1082
+ }
1083
+ },
1084
+ toMarkdown: {
1085
+ match: (e) => e.type.name === "paragraph",
1086
+ runner: (e, t) => {
1087
+ var n;
1088
+ if (e.openNode("paragraph"), t.childCount >= 1 && ((n = t.lastChild) == null ? void 0 : n.type.name) === "hardbreak") {
1089
+ const o = [];
1090
+ t.content.forEach((a, s, l) => {
1091
+ l !== t.childCount - 1 && o.push(a);
1092
+ }), e.next(ge.fromArray(o));
1093
+ } else
1094
+ e.next(t.content);
1095
+ e.closeNode();
1157
1096
  }
1158
- }),
1159
- commands: (nodeType) => [createCmd(TurnIntoText, () => setBlockType(nodeType))],
1160
- shortcuts: {
1161
- [SupportedKeys.Text]: createShortcut(TurnIntoText, "Mod-Alt-0")
1162
1097
  }
1163
- };
1164
- });
1165
- const text = createNode(() => ({
1098
+ }),
1099
+ commands: (e) => [M(ie, () => E(e))],
1100
+ shortcuts: {
1101
+ [k.Text]: h(ie, "Mod-Alt-0")
1102
+ }
1103
+ })), ht = w(() => ({
1166
1104
  id: "text",
1167
1105
  schema: () => ({
1168
1106
  group: "inline",
1169
1107
  parseMarkdown: {
1170
- match: ({ type }) => type === "text",
1171
- runner: (state, node) => {
1172
- state.addText(node["value"]);
1108
+ match: ({ type: c }) => c === "text",
1109
+ runner: (c, e) => {
1110
+ c.addText(e.value);
1173
1111
  }
1174
1112
  },
1175
1113
  toMarkdown: {
1176
- match: (node) => node.type.name === "text",
1177
- runner: (state, node) => {
1178
- state.addNode("text", void 0, node.text);
1114
+ match: (c) => c.type.name === "text",
1115
+ runner: (c, e) => {
1116
+ c.addNode("text", void 0, e.text);
1179
1117
  }
1180
1118
  }
1181
1119
  })
1182
- }));
1183
- const nodes = [
1184
- doc(),
1185
- paragraph(),
1186
- hardbreak(),
1187
- blockquote(),
1188
- codeFence(),
1189
- bulletList(),
1190
- orderedList(),
1191
- listItem(),
1192
- heading(),
1193
- hr(),
1194
- image(),
1195
- text()
1196
- ];
1197
- const isParent = (node) => !!node.children;
1198
- const isHTML = (node) => node.type === "html";
1199
- function flatMapWithDepth(ast, fn) {
1200
- return transform(ast, 0, null)[0];
1201
- function transform(node, index, parent) {
1202
- if (isParent(node)) {
1203
- const out = [];
1204
- for (let i = 0, n = node.children.length; i < n; i++) {
1205
- const nthChild = node.children[i];
1206
- if (nthChild) {
1207
- const xs = transform(nthChild, i, node);
1208
- if (xs) {
1209
- for (let j = 0, m = xs.length; j < m; j++) {
1210
- const item = xs[j];
1211
- if (item) {
1212
- out.push(item);
1213
- }
1120
+ })), kt = [
1121
+ et(),
1122
+ pt(),
1123
+ rt(),
1124
+ Ge(),
1125
+ Ze(),
1126
+ Je(),
1127
+ ft(),
1128
+ gt(),
1129
+ lt(),
1130
+ ct(),
1131
+ ut(),
1132
+ ht()
1133
+ ], Mt = () => {
1134
+ function c(e) {
1135
+ qe(e, "list", (t) => {
1136
+ var r;
1137
+ if (t.ordered) {
1138
+ const n = (r = t.start) != null ? r : 1;
1139
+ t.children.forEach((o, a) => {
1140
+ o.label = a + n;
1141
+ });
1142
+ return;
1143
+ }
1144
+ });
1145
+ }
1146
+ return c;
1147
+ }, It = (c) => !!c.children, bt = (c) => c.type === "html";
1148
+ function yt(c, e) {
1149
+ return t(c, 0, null)[0];
1150
+ function t(r, n, o) {
1151
+ if (It(r)) {
1152
+ const a = [];
1153
+ for (let s = 0, l = r.children.length; s < l; s++) {
1154
+ const i = r.children[s];
1155
+ if (i) {
1156
+ const u = t(i, s, r);
1157
+ if (u)
1158
+ for (let g = 0, d = u.length; g < d; g++) {
1159
+ const m = u[g];
1160
+ m && a.push(m);
1214
1161
  }
1215
- }
1216
1162
  }
1217
1163
  }
1218
- node.children = out;
1164
+ r.children = a;
1219
1165
  }
1220
- return fn(node, index, parent);
1166
+ return e(r, n, o);
1221
1167
  }
1222
1168
  }
1223
- const filterHTMLPlugin = () => {
1224
- function transformer(tree) {
1225
- flatMapWithDepth(tree, (node) => {
1226
- if (!isHTML(node)) {
1227
- return [node];
1228
- }
1229
- return [];
1230
- });
1169
+ const Nt = () => {
1170
+ function c(e) {
1171
+ yt(e, (t) => bt(t) ? [] : [t]);
1231
1172
  }
1232
- return transformer;
1233
- };
1234
- const inlineNodesCursorPluginKey = new PluginKey("MILKDOWN_INLINE_NODES_CURSOR");
1235
- const inlineNodesCursorPlugin = new Plugin({
1236
- key: inlineNodesCursorPluginKey,
1173
+ return c;
1174
+ }, wt = new T("MILKDOWN_INLINE_NODES_CURSOR"), ue = new H({
1175
+ key: wt,
1237
1176
  state: {
1238
1177
  init() {
1239
- return false;
1178
+ return !1;
1240
1179
  },
1241
- apply(tr) {
1242
- if (!tr.selection.empty) {
1243
- return false;
1244
- }
1245
- const pos = tr.selection.$from;
1246
- const left = pos.nodeBefore;
1247
- const right = pos.nodeAfter;
1248
- if (left && right && left.isInline && !left.isText && right.isInline && !right.isText) {
1249
- return true;
1250
- }
1251
- return false;
1180
+ apply(c) {
1181
+ if (!c.selection.empty)
1182
+ return !1;
1183
+ const e = c.selection.$from, t = e.nodeBefore, r = e.nodeAfter;
1184
+ return !!(t && r && t.isInline && !t.isText && r.isInline && !r.isText);
1252
1185
  }
1253
1186
  },
1254
1187
  props: {
1255
1188
  handleDOMEvents: {
1256
- beforeinput: (view, e) => {
1257
- const active = inlineNodesCursorPlugin.getState(view.state);
1258
- if (active) {
1259
- const from = view.state.selection.from;
1260
- e.preventDefault();
1261
- view.dispatch(view.state.tr.insertText(e.data || "", from));
1262
- return true;
1189
+ beforeinput: (c, e) => {
1190
+ if (ue.getState(c.state) && e instanceof InputEvent) {
1191
+ const r = c.state.selection.from;
1192
+ return e.preventDefault(), c.dispatch(c.state.tr.insertText(e.data || "", r)), !0;
1263
1193
  }
1264
- return false;
1194
+ return !1;
1265
1195
  }
1266
1196
  },
1267
- decorations(state) {
1268
- const active = inlineNodesCursorPlugin.getState(state);
1269
- if (active) {
1270
- const pos = state.selection.$from;
1271
- const position = pos.pos;
1272
- const left = document.createElement("span");
1273
- const leftDec = Decoration.widget(position, left, {
1197
+ decorations(c) {
1198
+ if (ue.getState(c)) {
1199
+ const r = c.selection.$from.pos, n = document.createElement("span"), o = J.widget(r, n, {
1274
1200
  side: -1
1275
- });
1276
- const right = document.createElement("span");
1277
- const rightDec = Decoration.widget(position, right);
1278
- setTimeout(() => {
1279
- left.contentEditable = "true";
1280
- right.contentEditable = "true";
1281
- });
1282
- return DecorationSet.create(state.doc, [leftDec, rightDec]);
1201
+ }), a = document.createElement("span"), s = J.widget(r, a);
1202
+ return setTimeout(() => {
1203
+ n.contentEditable = "true", a.contentEditable = "true";
1204
+ }), O.create(c.doc, [o, s]);
1283
1205
  }
1284
- return DecorationSet.empty;
1206
+ return O.empty;
1285
1207
  }
1286
1208
  }
1287
- });
1288
- const commonmarkPlugins = [
1289
- createPlugin(() => ({
1290
- prosePlugins: () => [inlineNodesCursorPlugin],
1291
- remarkPlugins: () => [links, filterHTMLPlugin]
1209
+ }), Lt = [
1210
+ He(() => ({
1211
+ prosePlugins: () => [ue],
1212
+ remarkPlugins: () => [We, Nt, Mt]
1292
1213
  }))()
1293
- ];
1294
- const commonmarkNodes = AtomList.create([...nodes, ...marks]);
1295
- const commonmark = AtomList.create([...commonmarkPlugins, ...commonmarkNodes]);
1296
- const commands = {
1297
- ToggleInlineCode,
1298
- ToggleItalic,
1299
- ToggleLink,
1300
- ToggleBold,
1301
- ModifyLink,
1302
- ModifyImage,
1303
- WrapInBlockquote,
1304
- WrapInBulletList,
1305
- WrapInOrderedList,
1306
- TurnIntoCodeFence,
1307
- TurnIntoHeading,
1308
- TurnIntoText,
1309
- InsertHardbreak,
1310
- InsertHr,
1311
- InsertImage,
1312
- SplitListItem,
1313
- SinkListItem,
1314
- LiftListItem
1214
+ ], xt = Ne.create([...kt, ...ze]), Pt = Ne.create([...Lt, ...xt]), Wt = {
1215
+ ToggleInlineCode: Q,
1216
+ ToggleItalic: X,
1217
+ ToggleLink: xe,
1218
+ ToggleBold: Z,
1219
+ ModifyLink: Y,
1220
+ ModifyImage: se,
1221
+ WrapInBlockquote: ee,
1222
+ WrapInBulletList: te,
1223
+ WrapInOrderedList: ce,
1224
+ TurnIntoCodeFence: re,
1225
+ TurnIntoHeading: C,
1226
+ TurnIntoText: ie,
1227
+ InsertHardbreak: ne,
1228
+ InsertHr: Ce,
1229
+ InsertImage: De,
1230
+ SplitListItem: oe,
1231
+ SinkListItem: ae,
1232
+ LiftListItem: le
1233
+ };
1234
+ export {
1235
+ Me as DowngradeHeading,
1236
+ tt as HardbreakFilterPluginKey,
1237
+ ne as InsertHardbreak,
1238
+ Ce as InsertHr,
1239
+ De as InsertImage,
1240
+ le as LiftListItem,
1241
+ se as ModifyImage,
1242
+ Y as ModifyLink,
1243
+ ae as SinkListItem,
1244
+ oe as SplitListItem,
1245
+ k as SupportedKeys,
1246
+ Z as ToggleBold,
1247
+ Q as ToggleInlineCode,
1248
+ X as ToggleItalic,
1249
+ xe as ToggleLink,
1250
+ re as TurnIntoCodeFence,
1251
+ C as TurnIntoHeading,
1252
+ ie as TurnIntoText,
1253
+ ee as WrapInBlockquote,
1254
+ te as WrapInBulletList,
1255
+ ce as WrapInOrderedList,
1256
+ Xe as backtickInputRegex,
1257
+ Ge as blockquote,
1258
+ Je as bulletList,
1259
+ Ze as codeFence,
1260
+ Ke as codeInline,
1261
+ Wt as commands,
1262
+ Pt as commonmark,
1263
+ xt as commonmarkNodes,
1264
+ Lt as commonmarkPlugins,
1265
+ et as doc,
1266
+ Fe as em,
1267
+ rt as hardbreak,
1268
+ lt as heading,
1269
+ nt as headingHashPluginKey,
1270
+ j as headingIdPluginKey,
1271
+ ct as hr,
1272
+ ut as image,
1273
+ Ve as link,
1274
+ gt as listItem,
1275
+ ze as marks,
1276
+ kt as nodes,
1277
+ ft as orderedList,
1278
+ pt as paragraph,
1279
+ je as strong,
1280
+ ht as text,
1281
+ Ye as tildeInputRegex
1315
1282
  };
1316
- export { InsertHardbreak, InsertHr, InsertImage, LiftListItem, ModifyImage, ModifyLink, SinkListItem, SplitListItem, SupportedKeys, ToggleBold, ToggleInlineCode, ToggleItalic, ToggleLink, TurnIntoCodeFence, TurnIntoHeading, TurnIntoText, WrapInBlockquote, WrapInBulletList, WrapInOrderedList, backtickInputRegex, blockquote, bulletList, codeFence, codeInline, commands, commonmark, commonmarkNodes, commonmarkPlugins, doc, em, hardbreak, heading, headingPluginKey, hr, image, link, listItem, marks, nodes, orderedList, paragraph, strong, text, tildeInputRegex };
1317
1283
  //# sourceMappingURL=index.es.js.map