@milkdown/preset-commonmark 6.1.4 → 6.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) 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 +1012 -1065
  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/index.d.ts +1 -1
  10. package/lib/mark/index.d.ts.map +1 -1
  11. package/lib/mark/link.d.ts +1 -5
  12. package/lib/mark/link.d.ts.map +1 -1
  13. package/lib/mark/strong.d.ts +1 -5
  14. package/lib/mark/strong.d.ts.map +1 -1
  15. package/lib/node/blockquote.d.ts +1 -5
  16. package/lib/node/blockquote.d.ts.map +1 -1
  17. package/lib/node/bullet-list.d.ts +1 -5
  18. package/lib/node/bullet-list.d.ts.map +1 -1
  19. package/lib/node/code-fence.d.ts +1 -5
  20. package/lib/node/code-fence.d.ts.map +1 -1
  21. package/lib/node/doc.d.ts +1 -5
  22. package/lib/node/doc.d.ts.map +1 -1
  23. package/lib/node/hardbreak.d.ts +1 -5
  24. package/lib/node/hardbreak.d.ts.map +1 -1
  25. package/lib/node/heading.d.ts +8 -6
  26. package/lib/node/heading.d.ts.map +1 -1
  27. package/lib/node/hr.d.ts +1 -5
  28. package/lib/node/hr.d.ts.map +1 -1
  29. package/lib/node/image.d.ts +1 -5
  30. package/lib/node/image.d.ts.map +1 -1
  31. package/lib/node/index.d.ts +2 -3
  32. package/lib/node/index.d.ts.map +1 -1
  33. package/lib/node/list-item.d.ts +1 -5
  34. package/lib/node/list-item.d.ts.map +1 -1
  35. package/lib/node/ordered-list.d.ts +1 -5
  36. package/lib/node/ordered-list.d.ts.map +1 -1
  37. package/lib/node/paragraph.d.ts +1 -5
  38. package/lib/node/paragraph.d.ts.map +1 -1
  39. package/lib/node/text.d.ts +1 -5
  40. package/lib/node/text.d.ts.map +1 -1
  41. package/lib/plugin/add-order-in-list.d.ts +3 -0
  42. package/lib/plugin/add-order-in-list.d.ts.map +1 -0
  43. package/lib/plugin/index.d.ts +1 -1
  44. package/lib/plugin/index.d.ts.map +1 -1
  45. package/lib/supported-keys.d.ts +1 -0
  46. package/lib/supported-keys.d.ts.map +1 -1
  47. package/package.json +7 -5
  48. package/src/mark/link.ts +55 -9
  49. package/src/node/code-fence.ts +7 -6
  50. package/src/node/hardbreak.ts +16 -2
  51. package/src/node/heading.ts +264 -117
  52. package/src/node/hr.ts +4 -2
  53. package/src/node/image.ts +4 -3
  54. package/src/node/index.ts +3 -1
  55. package/src/node/list-item.ts +93 -3
  56. package/src/node/ordered-list.ts +2 -1
  57. package/src/node/paragraph.ts +12 -2
  58. package/src/plugin/add-order-in-list.ts +19 -0
  59. package/src/plugin/index.ts +2 -1
  60. package/src/plugin/inline-nodes-cursor.ts +1 -1
  61. 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 B, 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 R, 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 H, TextSelection as pe, Plugin as T, 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 Be, sinkListItem as Re, 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 = B((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 = B((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 H("MILKDOWN_LINK_INPUT"), xe = I("ToggleLink"), Y = I("ModifyLink"), v = "link", Ve = B((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 s = r.url, a = r.title;
113
+ t.openMark(n, { href: s, 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, s) => {
129
+ var b;
130
+ if (!s)
131
+ return !1;
132
+ const { marks: a } = n.schema;
133
+ let o, l = -1;
134
+ const { selection: i } = n, { from: d, to: m } = i;
135
+ if (n.doc.nodesBetween(d, d === m ? m + 1 : m, (y, x) => {
136
+ var L;
137
+ if ((L = a.link) != null && L.isInSet(y.marks))
138
+ return o = y, l = x, !1;
139
+ }), !o)
140
+ return !1;
141
+ const g = o.marks.find(({ type: y }) => y === t);
142
+ if (!g)
143
+ return !1;
144
+ const u = l, f = l + o.nodeSize, { tr: p } = n, N = (b = a.link) == null ? void 0 : b.create({ ...g.attrs, href: r });
145
+ return N ? (s(p.removeMark(u, f, g).addMark(u, f, N).setSelection(new pe(p.selection.$anchor)).scrollIntoView()), !0) : !1;
146
+ })
147
+ ],
148
+ inputRules: (t, r) => [
149
+ new me(/\[(?<text>.*?)]\((?<href>.*?)(?=“|\))"?(?<title>[^"]+)?"?\)/, (n, s, a, o) => {
150
+ const [l, i = "", d, m] = s, { tr: g } = n;
151
+ if (l) {
152
+ const u = i || "link";
153
+ g.replaceWith(a, o, r.get(A).text(u)).addMark(a, u.length + a, t.create({ title: m, href: d }));
154
+ }
155
+ return g;
156
+ })
157
+ ],
158
+ prosePlugins: (t, r) => {
159
+ let n = !1;
160
+ return [
161
+ new T({
162
+ key: Ue,
163
+ view: (s) => {
164
+ var d, m, g;
165
+ const a = c.themeManager.get("input-chip", {
166
+ placeholder: (m = (d = e == null ? void 0 : e.input) == null ? void 0 : d.placeholder) != null ? m : "Input Web Link",
167
+ buttonText: (g = e == null ? void 0 : e.input) == null ? void 0 : g.buttonText,
168
+ onUpdate: (u) => {
169
+ r.get(we).call(Y, u);
170
+ },
171
+ calculatePosition: (u, f) => {
172
+ Oe(u, f, (p, N, b, y) => {
173
+ const x = u.dom.parentElement;
174
+ if (!x)
175
+ throw _e();
176
+ const L = N.left - p.left;
177
+ let q = p.left - y.left - (b.width - L) / 2, fe = p.bottom - y.top + 14 + x.scrollTop;
178
+ return n && (fe = p.top - y.top - b.height - 14 + x.scrollTop), q < 0 && (q = 0), [fe, q];
179
+ });
180
+ }
181
+ });
182
+ if (!a)
183
+ return {};
184
+ const o = (u) => {
185
+ const { selection: f, doc: p } = u.state, { from: N, to: b } = f;
186
+ if (!u.hasFocus())
187
+ return !1;
188
+ if (f.empty && f instanceof pe && b < p.content.size && N < p.content.size && p.rangeHasMark(N, N === b ? b + 1 : b, t))
189
+ return n = !1, !0;
190
+ if (f instanceof ve) {
191
+ const { node: y } = f;
192
+ if (y.type.name === "image" && y.marks.findIndex((x) => x.type.name === v) > -1)
193
+ return n = !0, !0;
194
+ }
195
+ return !1;
196
+ }, l = (u) => {
197
+ const { selection: f } = u.state;
198
+ let p;
199
+ const { from: N, to: b } = f;
200
+ if (u.state.doc.nodesBetween(N, N === b ? b + 1 : b, (L) => {
201
+ if (t.isInSet(L.marks))
202
+ return p = L, !1;
203
+ }), !p)
204
+ return;
205
+ const y = p.marks.find((L) => L.type === t);
206
+ return y ? y.attrs.href : void 0;
207
+ }, i = (u) => {
208
+ if (!u.editable)
209
+ return;
210
+ o(u) ? (a.show(u), a.update(l(u))) : a.hide();
211
+ };
212
+ return a.init(s), i(s), {
213
+ update: (u, f) => {
214
+ (f == null ? void 0 : f.doc.eq(u.state.doc)) && f.selection.eq(u.state.selection) || requestAnimationFrame(() => {
215
+ i(u);
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 = B((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,333 @@ 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 s;
351
+ if (!(n instanceof HTMLElement))
352
+ throw D(n);
353
+ return { language: (s = n.querySelector("pre")) == null ? void 0 : s.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, s) => {
356
+ var o, l;
357
+ if (!(n instanceof HTMLElement))
358
+ throw D(n);
359
+ const a = s.text((l = (o = n.querySelector("pre")) == null ? void 0 : o.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 s = document.createElement("select");
375
+ return t.forEach((a) => {
376
+ const o = document.createElement("option");
377
+ o.value = a, o.innerText = a || "--", a === n.attrs.language && (o.selected = !0), s.appendChild(o);
378
+ }), s.onchange = (a) => {
379
+ const o = a.target;
380
+ if (!(o 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(R);
383
+ if (!l.editable) {
384
+ o.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: d } = o.getBoundingClientRect(), m = l.posAtCoords({ top: i, left: d });
388
+ if (!m)
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: g } = l.state;
391
+ l.dispatch(g.setNodeMarkup(m.inside, void 0, {
392
+ ...n.attrs,
393
+ language: o.value
394
+ }));
395
+ }, [
478
396
  "div",
479
397
  {
480
398
  class: "code-fence-container"
481
399
  },
482
- select,
400
+ s,
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, s, a) => {
414
+ const o = s.lang, l = s.value;
415
+ n.openNode(a, { language: o }), 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, s) => {
421
+ var a;
422
+ n.addNode("code", void 0, ((a = s.content.firstChild) == null ? void 0 : a.text) || "", {
423
+ lang: s.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 [s, a] = n;
431
+ if (!!s)
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 [s, a] = n;
436
+ if (!!s)
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, s) => {
445
+ let a = r;
446
+ const o = (p) => {
447
+ const { tr: N } = n.state;
448
+ n.dispatch(N.setNodeMarkup(s(), 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(s(), void 0, {
455
+ ...a.attrs,
456
+ fold: !0
457
+ }));
458
+ }, i = () => {
459
+ const { tr: p } = n.state;
460
+ n.dispatch(p.setNodeMarkup(s(), void 0, {
461
+ ...a.attrs,
462
+ fold: !1
463
+ }));
464
+ }, d = c.themeManager.get("code-fence", {
465
+ onBlur: l,
466
+ onFocus: i,
467
+ onSelectLanguage: o,
468
+ editable: () => n.editable,
469
+ languageList: t
560
470
  });
561
- if (!renderer)
471
+ if (!d)
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: m, contentDOM: g, onUpdate: u, onDestroy: f } = d;
474
+ return u(a), {
475
+ dom: m,
476
+ contentDOM: g,
477
+ update: (p) => p.type.name !== V ? !1 : (a = p, u(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);
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);
490
+ }
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 = w((c) => ({
500
+ id: "hardbreak",
501
+ schema: () => ({
502
+ inline: !0,
503
+ group: "inline",
504
+ selectable: !1,
505
+ parseDOM: [{ tag: "br" }],
506
+ toDOM: (e) => ["br", { class: c.getClassName(e.attrs, "hardbreak") }],
507
+ parseMarkdown: {
508
+ match: ({ type: e }) => e === "break",
509
+ runner: (e, t, r) => {
510
+ e.addNode(r);
511
+ }
512
+ },
513
+ toMarkdown: {
514
+ match: (e) => e.type.name === "hardbreak",
515
+ runner: (e) => {
516
+ e.addNode("break");
517
+ }
518
+ }
519
+ }),
520
+ commands: (e) => [
521
+ M(ne, () => (t, r) => {
522
+ var a;
523
+ const { selection: n, tr: s } = t;
524
+ if (n.empty) {
525
+ const o = n.$from.node();
526
+ if (o.childCount > 0 && ((a = o.lastChild) == null ? void 0 : a.type.name) === "hardbreak")
527
+ return r == null || r(s.replaceRangeWith(n.to - 1, n.to, t.schema.node("paragraph")).setSelection(Le.near(s.doc.resolve(n.to))).scrollIntoView()), !0;
528
+ }
529
+ return r == null || r(s.setMeta("hardbreak", !0).replaceSelectionWith(e.create()).scrollIntoView()), !0;
530
+ })
531
+ ],
532
+ shortcuts: {
533
+ [k.HardBreak]: h(ne, "Shift-Enter")
534
+ },
535
+ prosePlugins: (e) => [
536
+ new T({
537
+ key: new H("MILKDOWN_HARDBREAK_MARKS"),
538
+ appendTransaction: (t, r, n) => {
539
+ if (!t.length)
540
+ return;
541
+ const [s] = t;
542
+ if (!s)
543
+ return;
544
+ const [a] = s.steps;
545
+ if (s.getMeta("hardbreak")) {
546
+ if (!(a instanceof $e))
547
+ return;
548
+ const { from: i } = a;
549
+ return n.tr.setNodeMarkup(i, e, void 0, []);
589
550
  }
590
- },
591
- toMarkdown: {
592
- match: (node) => node.type.name === "doc",
593
- runner: (state, node) => {
594
- state.openNode("root");
595
- state.next(node.content);
551
+ if (a instanceof Se) {
552
+ let i = n.tr;
553
+ const { from: d, to: m } = a;
554
+ return n.doc.nodesBetween(d, m, (g, u) => {
555
+ g.type === e && (i = i.setNodeMarkup(u, e, void 0, []));
556
+ }), i;
596
557
  }
597
558
  }
598
559
  })
560
+ ]
561
+ })), ke = Array(6).fill(0).map((c, e) => e + 1), C = I("TurnIntoHeading"), Me = I("DowngradeHeading"), j = new H("MILKDOWN_HEADING_ID"), rt = new H("MILKDOWN_HEADING_HASH"), nt = (c) => c.textContent.replace(/[\p{P}\p{S}]/gu, "").replace(/\s/g, "-").toLowerCase().trim(), st = (c, e, t) => {
562
+ let r = !1;
563
+ const n = (s, a) => {
564
+ const o = s.tr;
565
+ s.doc.descendants((l, i) => {
566
+ if (l.type === e && !r) {
567
+ if (l.textContent.trim().length === 0)
568
+ return;
569
+ const d = l.attrs, m = t(l);
570
+ d.id !== m && o.setMeta(j, !0).setNodeMarkup(i, void 0, {
571
+ ...d,
572
+ id: m
573
+ });
574
+ }
575
+ }), a(o);
599
576
  };
600
- });
601
- const InsertHardbreak = createCmdKey("InsertHardbreak");
602
- const hardbreak = createNode((utils) => {
603
- return {
604
- id: "hardbreak",
605
- schema: () => ({
606
- inline: true,
607
- group: "inline",
608
- selectable: false,
609
- parseDOM: [{ tag: "br" }],
610
- toDOM: (node) => ["br", { class: utils.getClassName(node.attrs, "hardbreak") }],
611
- parseMarkdown: {
612
- match: ({ type }) => type === "break",
613
- runner: (state, _, type) => {
614
- state.addNode(type);
615
- }
616
- },
617
- toMarkdown: {
618
- match: (node) => node.type.name === "hardbreak",
619
- runner: (state) => {
620
- state.addNode("break");
577
+ return new T({
578
+ key: j,
579
+ props: {
580
+ handleDOMEvents: {
581
+ compositionstart: () => (r = !0, !1),
582
+ compositionend: () => {
583
+ r = !1;
584
+ const s = c.get(R);
585
+ return setTimeout(() => {
586
+ n(s.state, (a) => s.dispatch(a));
587
+ }, 0), !1;
621
588
  }
622
589
  }
623
- }),
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;
628
- })
629
- ],
630
- shortcuts: {
631
- [SupportedKeys.HardBreak]: createShortcut(InsertHardbreak, "Shift-Enter")
632
590
  },
633
- prosePlugins: (type) => [
634
- new Plugin({
635
- key: new PluginKey("MILKDOWN_HARDBREAK_MARKS"),
636
- appendTransaction: (trs, _oldState, newState) => {
637
- if (!trs.length)
638
- return;
639
- const [tr] = trs;
640
- if (!tr)
641
- return;
642
- const [step] = tr.steps;
643
- const isInsertHr = tr.getMeta("hardbreak");
644
- if (isInsertHr) {
645
- if (!(step instanceof ReplaceStep)) {
646
- return;
647
- }
648
- const { from } = step;
649
- return newState.tr.setNodeMarkup(from, type, void 0, []);
650
- }
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;
661
- }
662
- return;
663
- }
664
- })
665
- ]
666
- };
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";
591
+ appendTransaction: (s, a, o) => {
592
+ let l = null;
593
+ return s.every((i) => !i.getMeta(j)) && s.some((i) => i.docChanged) && n(o, (i) => {
594
+ l = i;
595
+ }), l;
596
+ },
597
+ view: (s) => {
598
+ const a = s.state.doc;
599
+ let o = s.state.tr;
600
+ return a.descendants((l, i) => {
601
+ l.type.name === "heading" && l.attrs.level && (l.attrs.id || (o = o.setNodeMarkup(i, void 0, {
602
+ ...l.attrs,
603
+ id: t(l)
604
+ })));
605
+ }), s.dispatch(o), {};
606
+ }
607
+ });
608
+ }, ot = (c, e, t) => new T({
609
+ key: rt,
610
+ state: {
611
+ init: () => O.empty,
612
+ apply: (r) => {
613
+ const n = c.get(R);
614
+ if (!n.hasFocus || !n.editable)
615
+ return O.empty;
616
+ const { $from: s } = r.selection, a = s.node();
617
+ if (a.type !== e)
618
+ return O.empty;
619
+ const o = a.attrs.level, l = (m) => Array(m).fill(0).map((g) => "#").join(""), i = document.createElement("span");
620
+ i.textContent = l(o), i.contentEditable = "false", t.themeManager.onFlush(() => {
621
+ const m = t.getStyle(({ css: g }) => {
622
+ const u = Te(t.themeManager);
623
+ return g`
624
+ margin-right: 4px;
625
+ color: ${u("primary")};
626
+ `;
627
+ });
628
+ m && (i.className = m);
629
+ });
630
+ const d = J.widget(s.before() + 1, i, { side: -1 });
631
+ return O.create(r.doc, [d]);
632
+ }
633
+ },
634
+ props: {
635
+ handleDOMEvents: {
636
+ focus: (r) => {
637
+ const n = Ae(r.state.tr);
638
+ return r.dispatch(n), !1;
639
+ }
640
+ },
641
+ decorations(r) {
642
+ return this.getState(r);
643
+ }
644
+ }
645
+ }), at = w((c, e) => {
646
+ var s, a;
647
+ const t = "heading", r = (s = e == null ? void 0 : e.getId) != null ? s : nt, n = (a = e == null ? void 0 : e.displayHashtag) != null ? a : !0;
674
648
  return {
675
- id: id2,
649
+ id: t,
676
650
  schema: () => ({
677
651
  content: "inline*",
678
652
  group: "block",
679
- defining: true,
653
+ defining: !0,
680
654
  attrs: {
681
655
  id: {
682
656
  default: ""
@@ -685,393 +659,351 @@ const heading = createNode((utils) => {
685
659
  default: 1
686
660
  }
687
661
  },
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 };
662
+ parseDOM: ke.map((o) => ({
663
+ tag: `h${o}`,
664
+ getAttrs: (l) => {
665
+ if (!(l instanceof HTMLElement))
666
+ throw D(l);
667
+ return { level: o, id: l.id };
695
668
  }
696
669
  })),
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
- },
670
+ toDOM: (o) => [
671
+ `h${o.attrs.level}`,
672
+ {
673
+ id: o.attrs.id || r(o),
674
+ class: c.getClassName(o.attrs, `heading h${o.attrs.level}`)
675
+ },
676
+ 0
677
+ ],
707
678
  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();
679
+ match: ({ type: o }) => o === t,
680
+ runner: (o, l, i) => {
681
+ const d = l.depth;
682
+ o.openNode(i, { level: d }), o.next(l.children), o.closeNode();
714
683
  }
715
684
  },
716
685
  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();
686
+ match: (o) => o.type.name === t,
687
+ runner: (o, l) => {
688
+ var d;
689
+ if (o.openNode("heading", void 0, { depth: l.attrs.level }), l.childCount >= 1 && ((d = l.lastChild) == null ? void 0 : d.type.name) === "hardbreak") {
690
+ const m = [];
691
+ l.content.forEach((g, u, f) => {
692
+ f !== l.childCount - 1 && m.push(g);
693
+ }), o.next(ge.fromArray(m));
694
+ } else
695
+ o.next(l.content);
696
+ o.closeNode();
722
697
  }
723
698
  }
724
699
  }),
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 }))],
700
+ inputRules: (o, l) => ke.map((i) => G(new RegExp(`^(#{1,${i}})\\s$`), o, () => {
701
+ const d = l.get(R), { $from: m } = d.state.selection, g = m.node();
702
+ if (g.type.name === "heading") {
703
+ let u = Number(g.attrs.level) + Number(i);
704
+ return u > 6 && (u = 6), {
705
+ level: u
706
+ };
707
+ }
708
+ return {
709
+ level: i
710
+ };
711
+ })),
712
+ commands: (o, l) => [
713
+ M(C, (i = 1) => i < 1 ? E(i === 0 && l.get(A).nodes.paragraph || o) : E(i === 0 && l.get(A).nodes.paragraph || o, { level: i })),
714
+ M(Me, () => (i, d, m) => {
715
+ const { $from: g } = i.selection, u = g.node();
716
+ if (u.type !== o || !i.selection.empty || g.parentOffset !== 0)
717
+ return !1;
718
+ const f = u.attrs.level - 1;
719
+ return f ? (d == null || d(i.tr.setNodeMarkup(i.selection.$from.before(), void 0, {
720
+ ...u.attrs,
721
+ level: f
722
+ })), !0) : E(l.get(A).nodes.paragraph || o)(i, d, m);
723
+ })
724
+ ],
729
725
  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)
726
+ [k.H1]: h(C, "Mod-Alt-1", 1),
727
+ [k.H2]: h(C, "Mod-Alt-2", 2),
728
+ [k.H3]: h(C, "Mod-Alt-3", 3),
729
+ [k.H4]: h(C, "Mod-Alt-4", 4),
730
+ [k.H5]: h(C, "Mod-Alt-5", 5),
731
+ [k.H6]: h(C, "Mod-Alt-6", 6),
732
+ [k.DowngradeHeading]: h(Me, ["Backspace", "Delete"])
736
733
  },
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
- ];
734
+ prosePlugins: (o, l) => {
735
+ const i = [st(l, o, r)];
736
+ return n && i.push(ot(l, o, c)), i;
787
737
  }
788
738
  };
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
- }
739
+ }), z = "hr", Ce = I("InsertHr"), lt = w((c) => ({
740
+ id: z,
741
+ schema: () => ({
742
+ group: "block",
743
+ parseDOM: [{ tag: "hr" }],
744
+ toDOM: (e) => ["hr", { class: c.getClassName(e.attrs, z) }],
745
+ parseMarkdown: {
746
+ match: ({ type: e }) => e === "thematicBreak",
747
+ runner: (e, t, r) => {
748
+ e.addNode(r);
810
749
  }
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
- }
750
+ },
751
+ toMarkdown: {
752
+ match: (e) => e.type.name === z,
753
+ runner: (e) => {
754
+ e.addNode("thematicBreak");
909
755
  }
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;
756
+ }
757
+ }),
758
+ inputRules: (e) => [
759
+ new me(/^(?:---|___\s|\*\*\*\s)$/, (t, r, n, s) => {
760
+ const { tr: a } = t;
761
+ return r[0] && a.replaceWith(n - 1, s, e.create()), a;
762
+ })
763
+ ],
764
+ commands: (e, t) => [
765
+ M(Ce, () => (r, n) => {
766
+ if (!n)
767
+ return !0;
768
+ const s = t.get(A).node("paragraph"), { tr: a, selection: o } = r, { from: l } = o, i = e.create();
769
+ if (!i)
770
+ return !0;
771
+ const d = a.replaceSelectionWith(i).insert(l, s), m = Le.findFrom(d.doc.resolve(l), 1, !0);
772
+ return m && n(d.setSelection(m).scrollIntoView()), !0;
773
+ })
774
+ ]
775
+ })), se = I("ModifyImage"), De = I("InsertImage"), S = "image", ct = new H("MILKDOWN_IMAGE_INPUT"), it = w((c, e) => ({
776
+ id: "image",
777
+ schema: () => ({
778
+ inline: !0,
779
+ group: "inline",
780
+ selectable: !0,
781
+ draggable: !0,
782
+ marks: "",
783
+ atom: !0,
784
+ defining: !0,
785
+ isolating: !0,
786
+ attrs: {
787
+ src: { default: "" },
788
+ alt: { default: null },
789
+ title: { default: null }
790
+ },
791
+ parseDOM: [
792
+ {
793
+ tag: "img[src]",
794
+ getAttrs: (t) => {
795
+ if (!(t instanceof HTMLElement))
796
+ throw D(t);
797
+ return {
798
+ src: t.getAttribute("src") || "",
799
+ alt: t.getAttribute("alt"),
800
+ title: t.getAttribute("title") || t.getAttribute("alt"),
801
+ width: t.getAttribute("width")
802
+ };
919
803
  }
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
- })
804
+ }
932
805
  ],
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
- })
806
+ toDOM: (t) => [
807
+ "img",
808
+ {
809
+ ...t.attrs,
810
+ class: c.getClassName(t.attrs, S)
811
+ }
942
812
  ],
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 {};
813
+ parseMarkdown: {
814
+ match: ({ type: t }) => t === S,
815
+ runner: (t, r, n) => {
816
+ const s = r.url, a = r.alt, o = r.title;
817
+ t.addNode(n, {
818
+ src: s,
819
+ alt: a,
820
+ title: o
821
+ });
954
822
  }
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
823
  },
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
- ];
824
+ toMarkdown: {
825
+ match: (t) => t.type.name === S,
826
+ runner: (t, r) => {
827
+ t.addNode("image", void 0, void 0, {
828
+ title: r.attrs.title,
829
+ url: r.attrs.src,
830
+ alt: r.attrs.alt
831
+ });
832
+ }
1027
833
  }
834
+ }),
835
+ commands: (t) => [
836
+ M(De, (r = "") => (n, s) => {
837
+ if (!s)
838
+ return !0;
839
+ const { tr: a } = n, o = t.create({ src: r });
840
+ if (!o)
841
+ return !0;
842
+ const l = a.replaceSelectionWith(o);
843
+ return s(l.scrollIntoView()), !0;
844
+ }),
845
+ M(se, (r = "") => (n, s) => {
846
+ const a = K(n.selection, t);
847
+ if (!a)
848
+ return !1;
849
+ const { tr: o } = n;
850
+ return s == null || s(o.setNodeMarkup(a.pos, void 0, { ...a.node.attrs, loading: !0, src: r }).scrollIntoView()), !0;
851
+ })
852
+ ],
853
+ inputRules: (t) => [
854
+ new me(/!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/, (r, n, s, a) => {
855
+ const [o, l, i = "", d] = n, { tr: m } = r;
856
+ return o && m.replaceWith(s, a, t.create({ src: i, alt: l, title: d })), m;
857
+ })
858
+ ],
859
+ view: () => (t) => {
860
+ var i, d;
861
+ let r = t;
862
+ const n = (i = e == null ? void 0 : e.placeholder) != null ? i : "Add an Image", s = (d = e == null ? void 0 : e.isBlock) != null ? d : !1, a = c.themeManager.get("image", {
863
+ placeholder: n,
864
+ isBlock: s
865
+ });
866
+ if (!a)
867
+ return {};
868
+ const { dom: o, onUpdate: l } = a;
869
+ return l(r), {
870
+ dom: o,
871
+ update: (m) => m.type.name !== S ? !1 : (r = m, l(r), !0),
872
+ selectNode: () => {
873
+ o.classList.add("ProseMirror-selectednode");
874
+ },
875
+ deselectNode: () => {
876
+ o.classList.remove("ProseMirror-selectednode");
877
+ }
878
+ };
879
+ },
880
+ prosePlugins: (t, r) => [
881
+ new T({
882
+ key: ct,
883
+ view: (n) => {
884
+ var i, d, m;
885
+ const s = c.themeManager.get("input-chip", {
886
+ placeholder: (d = (i = e == null ? void 0 : e.input) == null ? void 0 : i.placeholder) != null ? d : "Input Image Link",
887
+ buttonText: (m = e == null ? void 0 : e.input) == null ? void 0 : m.buttonText,
888
+ onUpdate: (g) => {
889
+ r.get(we).call(se, g);
890
+ }
891
+ });
892
+ if (!s)
893
+ return {};
894
+ const a = (g) => Boolean(g.hasFocus() && t && K(g.state.selection, t)), o = (g) => {
895
+ const u = K(g.state.selection, t);
896
+ return u ? u.node.attrs.src : void 0;
897
+ }, l = (g) => {
898
+ if (!g.editable)
899
+ return;
900
+ a(g) ? (s.show(g), s.update(o(g))) : s.hide();
901
+ };
902
+ return s.init(n), l(n), {
903
+ update: (g, u) => {
904
+ (u == null ? void 0 : u.doc.eq(g.state.doc)) && u.selection.eq(g.state.selection) || l(g);
905
+ },
906
+ destroy: () => {
907
+ s.destroy();
908
+ }
909
+ };
910
+ }
911
+ })
912
+ ]
913
+ })), Ie = "list_item", oe = I("SplitListItem"), ae = I("SinkListItem"), le = I("LiftListItem"), ut = new H("MILKDOWN_KEEP_LIST_ORDER"), dt = (c) => {
914
+ const e = (t, r) => {
915
+ const n = Ee("ordered_list", t.schema);
916
+ let s = t.tr;
917
+ t.doc.descendants((a, o, l, i) => {
918
+ if (a.type === c && (l == null ? void 0 : l.type) === n) {
919
+ let d = !1;
920
+ const m = { ...a.attrs };
921
+ a.attrs.listType !== "ordered" && (m.listType = "ordered", d = !0);
922
+ const g = l == null ? void 0 : l.maybeChild(i - 1);
923
+ if (g && g.type === c && g.attrs.listType === "ordered") {
924
+ const u = g.attrs.label;
925
+ m.label = `${Number(u.slice(0, -1)) + 1}.`, d = !0;
926
+ }
927
+ a.attrs.label === "\u2022" && (m.label = `${i + 1}.`, d = !0), d && (s = s.setNodeMarkup(o, void 0, m));
928
+ }
929
+ }), r(s);
1028
930
  };
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,
931
+ return new T({
932
+ key: ut,
933
+ appendTransaction: (t, r, n) => {
934
+ let s = null;
935
+ return t.some((a) => a.docChanged) && e(n, (a) => {
936
+ s = a;
937
+ }), s;
938
+ }
939
+ });
940
+ }, mt = w((c) => ({
941
+ id: Ie,
1036
942
  schema: () => ({
1037
943
  group: "listItem",
1038
944
  content: "paragraph block*",
1039
- defining: true,
1040
- parseDOM: [{ tag: "li" }],
1041
- toDOM: (node) => ["li", { class: utils.getClassName(node.attrs, "list-item") }, 0],
945
+ attrs: {
946
+ label: {
947
+ default: "\u2022"
948
+ },
949
+ listType: {
950
+ default: "bullet"
951
+ }
952
+ },
953
+ defining: !0,
954
+ parseDOM: [
955
+ {
956
+ tag: "li.list-item",
957
+ getAttrs: (e) => {
958
+ if (!(e instanceof HTMLElement))
959
+ throw D(e);
960
+ return {
961
+ label: e.dataset.label,
962
+ listType: e.dataset["list-type"]
963
+ };
964
+ },
965
+ contentElement: "div.list-item_body"
966
+ },
967
+ { tag: "li" }
968
+ ],
969
+ toDOM: (e) => [
970
+ "li",
971
+ {
972
+ class: c.getClassName(e.attrs, "list-item"),
973
+ "data-label": e.attrs.label,
974
+ "data-list-type": e.attrs.listType
975
+ },
976
+ ["div", { class: c.getClassName(e.attrs, "list-item_label") }, e.attrs.label],
977
+ ["div", { class: c.getClassName(e.attrs, "list-item_body") }, 0]
978
+ ],
1042
979
  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();
980
+ match: ({ type: e, checked: t }) => e === "listItem" && t === null,
981
+ runner: (e, t, r) => {
982
+ const n = t.label != null ? `${t.label}.` : "\u2022", s = t.label != null ? "ordered" : "bullet";
983
+ e.openNode(r, { label: n, listType: s }), e.next(t.children), e.closeNode();
1048
984
  }
1049
985
  },
1050
986
  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();
987
+ match: (e) => e.type.name === Ie,
988
+ runner: (e, t) => {
989
+ e.openNode("listItem"), e.next(t.content), e.closeNode();
1056
990
  }
1057
991
  }
1058
992
  }),
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))
993
+ inputRules: (e) => [W(/^\s*([-+*])\s$/, e)],
994
+ commands: (e) => [
995
+ M(oe, () => Be(e)),
996
+ M(ae, () => Re(e)),
997
+ M(le, () => Pe(e))
1064
998
  ],
1065
999
  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,
1000
+ [k.NextListItem]: h(oe, "Enter"),
1001
+ [k.SinkListItem]: h(ae, "Mod-]"),
1002
+ [k.LiftListItem]: h(le, "Mod-[")
1003
+ },
1004
+ prosePlugins: (e) => [dt(e)]
1005
+ })), ce = I("WrapInOrderedList"), be = "ordered_list", gt = w((c) => ({
1006
+ id: be,
1075
1007
  schema: () => ({
1076
1008
  content: "listItem+",
1077
1009
  group: "block",
@@ -1083,235 +1015,250 @@ const orderedList = createNode((utils) => ({
1083
1015
  parseDOM: [
1084
1016
  {
1085
1017
  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 };
1018
+ getAttrs: (e) => {
1019
+ if (!(e instanceof HTMLElement))
1020
+ throw D(e);
1021
+ return { order: e.hasAttribute("start") ? Number(e.getAttribute("start")) : 1 };
1091
1022
  }
1092
1023
  }
1093
1024
  ],
1094
- toDOM: (node) => [
1025
+ toDOM: (e) => [
1095
1026
  "ol",
1096
- __spreadProps(__spreadValues({}, node.attrs["order"] === 1 ? {} : node.attrs["order"]), {
1097
- class: utils.getClassName(node.attrs, "ordered-list")
1098
- }),
1027
+ {
1028
+ ...e.attrs.order === 1 ? {} : e.attrs.order,
1029
+ class: c.getClassName(e.attrs, "ordered-list")
1030
+ },
1099
1031
  0
1100
1032
  ],
1101
1033
  parseMarkdown: {
1102
- match: ({ type, ordered }) => type === "list" && !!ordered,
1103
- runner: (state, node, type) => {
1104
- state.openNode(type).next(node.children).closeNode();
1034
+ match: ({ type: e, ordered: t }) => e === "list" && !!t,
1035
+ runner: (e, t, r) => {
1036
+ e.openNode(r).next(t.children).closeNode();
1105
1037
  }
1106
1038
  },
1107
1039
  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();
1040
+ match: (e) => e.type.name === be,
1041
+ runner: (e, t) => {
1042
+ e.openNode("list", void 0, { ordered: !0, start: 1 }), e.next(t.content), e.closeNode();
1113
1043
  }
1114
1044
  }
1115
1045
  }),
1116
- inputRules: (nodeType) => [
1117
- wrappingInputRule(/^(\d+)\.\s$/, nodeType, (match) => ({ order: Number(match[1]) }), (match, node) => node.childCount + node.attrs["order"] === Number(match[1]))
1046
+ inputRules: (e) => [
1047
+ W(/^(\d+)\.\s$/, e, (t) => ({ order: Number(t[1]) }), (t, r) => r.childCount + r.attrs.order === Number(t[1]))
1118
1048
  ],
1119
- commands: (nodeType) => [createCmd(WrapInOrderedList, () => wrapIn(nodeType))],
1049
+ commands: (e) => [M(ce, () => de(e))],
1120
1050
  shortcuts: {
1121
- [SupportedKeys.OrderedList]: createShortcut(WrapInOrderedList, "Mod-Alt-7")
1051
+ [k.OrderedList]: h(ce, "Mod-Alt-7")
1122
1052
  }
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
- }
1053
+ })), ie = I("TurnIntoText"), ye = "paragraph", ft = w((c) => ({
1054
+ id: ye,
1055
+ schema: () => ({
1056
+ content: "inline*",
1057
+ group: "block",
1058
+ parseDOM: [{ tag: "p" }],
1059
+ toDOM: (e) => ["p", { class: c.getClassName(e.attrs, ye) }, 0],
1060
+ parseMarkdown: {
1061
+ match: (e) => e.type === "paragraph",
1062
+ runner: (e, t, r) => {
1063
+ e.openNode(r), t.children ? e.next(t.children) : e.addText(t.value), e.closeNode();
1064
+ }
1065
+ },
1066
+ toMarkdown: {
1067
+ match: (e) => e.type.name === "paragraph",
1068
+ runner: (e, t) => {
1069
+ var n;
1070
+ if (e.openNode("paragraph"), t.childCount >= 1 && ((n = t.lastChild) == null ? void 0 : n.type.name) === "hardbreak") {
1071
+ const s = [];
1072
+ t.content.forEach((a, o, l) => {
1073
+ l !== t.childCount - 1 && s.push(a);
1074
+ }), e.next(ge.fromArray(s));
1075
+ } else
1076
+ e.next(t.content);
1077
+ e.closeNode();
1157
1078
  }
1158
- }),
1159
- commands: (nodeType) => [createCmd(TurnIntoText, () => setBlockType(nodeType))],
1160
- shortcuts: {
1161
- [SupportedKeys.Text]: createShortcut(TurnIntoText, "Mod-Alt-0")
1162
1079
  }
1163
- };
1164
- });
1165
- const text = createNode(() => ({
1080
+ }),
1081
+ commands: (e) => [M(ie, () => E(e))],
1082
+ shortcuts: {
1083
+ [k.Text]: h(ie, "Mod-Alt-0")
1084
+ }
1085
+ })), pt = w(() => ({
1166
1086
  id: "text",
1167
1087
  schema: () => ({
1168
1088
  group: "inline",
1169
1089
  parseMarkdown: {
1170
- match: ({ type }) => type === "text",
1171
- runner: (state, node) => {
1172
- state.addText(node["value"]);
1090
+ match: ({ type: c }) => c === "text",
1091
+ runner: (c, e) => {
1092
+ c.addText(e.value);
1173
1093
  }
1174
1094
  },
1175
1095
  toMarkdown: {
1176
- match: (node) => node.type.name === "text",
1177
- runner: (state, node) => {
1178
- state.addNode("text", void 0, node.text);
1096
+ match: (c) => c.type.name === "text",
1097
+ runner: (c, e) => {
1098
+ c.addNode("text", void 0, e.text);
1179
1099
  }
1180
1100
  }
1181
1101
  })
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
- }
1102
+ })), ht = [
1103
+ et(),
1104
+ ft(),
1105
+ tt(),
1106
+ Ge(),
1107
+ Ze(),
1108
+ Je(),
1109
+ gt(),
1110
+ mt(),
1111
+ at(),
1112
+ lt(),
1113
+ it(),
1114
+ pt()
1115
+ ], kt = () => {
1116
+ function c(e) {
1117
+ qe(e, "list", (t) => {
1118
+ var r;
1119
+ if (t.ordered) {
1120
+ const n = (r = t.start) != null ? r : 1;
1121
+ t.children.forEach((s, a) => {
1122
+ s.label = a + n;
1123
+ });
1124
+ return;
1125
+ }
1126
+ });
1127
+ }
1128
+ return c;
1129
+ }, Mt = (c) => !!c.children, It = (c) => c.type === "html";
1130
+ function bt(c, e) {
1131
+ return t(c, 0, null)[0];
1132
+ function t(r, n, s) {
1133
+ if (Mt(r)) {
1134
+ const a = [];
1135
+ for (let o = 0, l = r.children.length; o < l; o++) {
1136
+ const i = r.children[o];
1137
+ if (i) {
1138
+ const d = t(i, o, r);
1139
+ if (d)
1140
+ for (let m = 0, g = d.length; m < g; m++) {
1141
+ const u = d[m];
1142
+ u && a.push(u);
1214
1143
  }
1215
- }
1216
1144
  }
1217
1145
  }
1218
- node.children = out;
1146
+ r.children = a;
1219
1147
  }
1220
- return fn(node, index, parent);
1148
+ return e(r, n, s);
1221
1149
  }
1222
1150
  }
1223
- const filterHTMLPlugin = () => {
1224
- function transformer(tree) {
1225
- flatMapWithDepth(tree, (node) => {
1226
- if (!isHTML(node)) {
1227
- return [node];
1228
- }
1229
- return [];
1230
- });
1151
+ const yt = () => {
1152
+ function c(e) {
1153
+ bt(e, (t) => It(t) ? [] : [t]);
1231
1154
  }
1232
- return transformer;
1233
- };
1234
- const inlineNodesCursorPluginKey = new PluginKey("MILKDOWN_INLINE_NODES_CURSOR");
1235
- const inlineNodesCursorPlugin = new Plugin({
1236
- key: inlineNodesCursorPluginKey,
1155
+ return c;
1156
+ }, Nt = new H("MILKDOWN_INLINE_NODES_CURSOR"), ue = new T({
1157
+ key: Nt,
1237
1158
  state: {
1238
1159
  init() {
1239
- return false;
1160
+ return !1;
1240
1161
  },
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;
1162
+ apply(c) {
1163
+ if (!c.selection.empty)
1164
+ return !1;
1165
+ const e = c.selection.$from, t = e.nodeBefore, r = e.nodeAfter;
1166
+ return !!(t && r && t.isInline && !t.isText && r.isInline && !r.isText);
1252
1167
  }
1253
1168
  },
1254
1169
  props: {
1255
1170
  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;
1171
+ beforeinput: (c, e) => {
1172
+ if (ue.getState(c.state) && e instanceof InputEvent) {
1173
+ const r = c.state.selection.from;
1174
+ return e.preventDefault(), c.dispatch(c.state.tr.insertText(e.data || "", r)), !0;
1263
1175
  }
1264
- return false;
1176
+ return !1;
1265
1177
  }
1266
1178
  },
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, {
1179
+ decorations(c) {
1180
+ if (ue.getState(c)) {
1181
+ const r = c.selection.$from.pos, n = document.createElement("span"), s = J.widget(r, n, {
1274
1182
  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]);
1183
+ }), a = document.createElement("span"), o = J.widget(r, a);
1184
+ return setTimeout(() => {
1185
+ n.contentEditable = "true", a.contentEditable = "true";
1186
+ }), O.create(c.doc, [s, o]);
1283
1187
  }
1284
- return DecorationSet.empty;
1188
+ return O.empty;
1285
1189
  }
1286
1190
  }
1287
- });
1288
- const commonmarkPlugins = [
1289
- createPlugin(() => ({
1290
- prosePlugins: () => [inlineNodesCursorPlugin],
1291
- remarkPlugins: () => [links, filterHTMLPlugin]
1191
+ }), wt = [
1192
+ He(() => ({
1193
+ prosePlugins: () => [ue],
1194
+ remarkPlugins: () => [We, yt, kt]
1292
1195
  }))()
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
1196
+ ], Lt = Ne.create([...ht, ...ze]), Rt = Ne.create([...wt, ...Lt]), Pt = {
1197
+ ToggleInlineCode: Q,
1198
+ ToggleItalic: X,
1199
+ ToggleLink: xe,
1200
+ ToggleBold: Z,
1201
+ ModifyLink: Y,
1202
+ ModifyImage: se,
1203
+ WrapInBlockquote: ee,
1204
+ WrapInBulletList: te,
1205
+ WrapInOrderedList: ce,
1206
+ TurnIntoCodeFence: re,
1207
+ TurnIntoHeading: C,
1208
+ TurnIntoText: ie,
1209
+ InsertHardbreak: ne,
1210
+ InsertHr: Ce,
1211
+ InsertImage: De,
1212
+ SplitListItem: oe,
1213
+ SinkListItem: ae,
1214
+ LiftListItem: le
1215
+ };
1216
+ export {
1217
+ Me as DowngradeHeading,
1218
+ ne as InsertHardbreak,
1219
+ Ce as InsertHr,
1220
+ De as InsertImage,
1221
+ le as LiftListItem,
1222
+ se as ModifyImage,
1223
+ Y as ModifyLink,
1224
+ ae as SinkListItem,
1225
+ oe as SplitListItem,
1226
+ k as SupportedKeys,
1227
+ Z as ToggleBold,
1228
+ Q as ToggleInlineCode,
1229
+ X as ToggleItalic,
1230
+ xe as ToggleLink,
1231
+ re as TurnIntoCodeFence,
1232
+ C as TurnIntoHeading,
1233
+ ie as TurnIntoText,
1234
+ ee as WrapInBlockquote,
1235
+ te as WrapInBulletList,
1236
+ ce as WrapInOrderedList,
1237
+ Xe as backtickInputRegex,
1238
+ Ge as blockquote,
1239
+ Je as bulletList,
1240
+ Ze as codeFence,
1241
+ Ke as codeInline,
1242
+ Pt as commands,
1243
+ Rt as commonmark,
1244
+ Lt as commonmarkNodes,
1245
+ wt as commonmarkPlugins,
1246
+ et as doc,
1247
+ Fe as em,
1248
+ tt as hardbreak,
1249
+ at as heading,
1250
+ rt as headingHashPluginKey,
1251
+ j as headingIdPluginKey,
1252
+ lt as hr,
1253
+ it as image,
1254
+ Ve as link,
1255
+ mt as listItem,
1256
+ ze as marks,
1257
+ ht as nodes,
1258
+ gt as orderedList,
1259
+ ft as paragraph,
1260
+ je as strong,
1261
+ pt as text,
1262
+ Ye as tildeInputRegex
1315
1263
  };
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
1264
  //# sourceMappingURL=index.es.js.map