@milkdown/preset-commonmark 6.2.0 → 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.
- package/lib/index.es.js +1012 -1153
- package/lib/index.es.js.map +1 -1
- package/lib/mark/link.d.ts.map +1 -1
- package/lib/node/code-fence.d.ts.map +1 -1
- package/lib/node/heading.d.ts +5 -2
- package/lib/node/heading.d.ts.map +1 -1
- package/lib/node/image.d.ts.map +1 -1
- package/lib/node/list-item.d.ts.map +1 -1
- package/lib/node/ordered-list.d.ts.map +1 -1
- package/lib/plugin/add-order-in-list.d.ts +3 -0
- package/lib/plugin/add-order-in-list.d.ts.map +1 -0
- package/lib/plugin/index.d.ts.map +1 -1
- package/lib/supported-keys.d.ts +1 -0
- package/lib/supported-keys.d.ts.map +1 -1
- package/package.json +7 -5
- package/src/mark/link.ts +3 -2
- package/src/node/code-fence.ts +4 -3
- package/src/node/heading.ts +261 -145
- package/src/node/image.ts +2 -1
- package/src/node/list-item.ts +93 -3
- package/src/node/ordered-list.ts +2 -1
- package/src/plugin/add-order-in-list.ts +19 -0
- package/src/plugin/index.ts +2 -1
- package/src/supported-keys.ts +1 -0
package/lib/index.es.js
CHANGED
|
@@ -1,34 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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, calculateTextPosition, 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, NodeSelection, 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,372 +31,283 @@ const SupportedKeys = {
|
|
|
47
31
|
NextListItem: "NextListItem",
|
|
48
32
|
SinkListItem: "SinkListItem",
|
|
49
33
|
LiftListItem: "LiftListItem"
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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: (
|
|
66
|
+
{ style: "font-style", getAttrs: (e) => e === "italic" }
|
|
93
67
|
],
|
|
94
|
-
toDOM: (
|
|
68
|
+
toDOM: (e) => ["em", { class: c.getClassName(e.attrs, F) }],
|
|
95
69
|
parseMarkdown: {
|
|
96
|
-
match: (
|
|
97
|
-
runner: (
|
|
98
|
-
|
|
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: (
|
|
105
|
-
runner: (
|
|
106
|
-
|
|
76
|
+
match: (e) => e.type.name === F,
|
|
77
|
+
runner: (e, t) => {
|
|
78
|
+
e.withMark(t, "emphasis");
|
|
107
79
|
}
|
|
108
80
|
}
|
|
109
81
|
}),
|
|
110
|
-
inputRules: (
|
|
111
|
-
|
|
112
|
-
|
|
82
|
+
inputRules: (e) => [
|
|
83
|
+
_(/(?:^|[^_])(_([^_]+)_)$/, e),
|
|
84
|
+
_(/(?:^|[^*])(\*([^*]+)\*)$/, e)
|
|
113
85
|
],
|
|
114
|
-
commands: (
|
|
86
|
+
commands: (e) => [M(X, () => P(e))],
|
|
115
87
|
shortcuts: {
|
|
116
|
-
[
|
|
88
|
+
[k.Em]: h(X, "Mod-i")
|
|
117
89
|
}
|
|
118
|
-
}))
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
var _a;
|
|
168
|
-
if (!dispatch)
|
|
169
|
-
return false;
|
|
170
|
-
const { marks: marks2 } = state.schema;
|
|
171
|
-
let node;
|
|
172
|
-
let pos = -1;
|
|
173
|
-
const { selection } = state;
|
|
174
|
-
const { from, to } = selection;
|
|
175
|
-
state.doc.nodesBetween(from, from === to ? to + 1 : to, (n, p) => {
|
|
176
|
-
var _a2;
|
|
177
|
-
if ((_a2 = marks2["link"]) == null ? void 0 : _a2.isInSet(n.marks)) {
|
|
178
|
-
node = n;
|
|
179
|
-
pos = p;
|
|
180
|
-
return false;
|
|
181
|
-
}
|
|
182
|
-
return;
|
|
183
|
-
});
|
|
184
|
-
if (!node)
|
|
185
|
-
return false;
|
|
186
|
-
const mark = node.marks.find(({ type }) => type === markType);
|
|
187
|
-
if (!mark)
|
|
188
|
-
return false;
|
|
189
|
-
const start = pos;
|
|
190
|
-
const end = pos + node.nodeSize;
|
|
191
|
-
const { tr } = state;
|
|
192
|
-
const linkMark = (_a = marks2["link"]) == null ? void 0 : _a.create(__spreadProps(__spreadValues({}, mark.attrs), { href }));
|
|
193
|
-
if (!linkMark)
|
|
194
|
-
return false;
|
|
195
|
-
dispatch(tr.removeMark(start, end, mark).addMark(start, end, linkMark).setSelection(new TextSelection(tr.selection.$anchor)).scrollIntoView());
|
|
196
|
-
return true;
|
|
197
|
-
})
|
|
198
107
|
],
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
+
};
|
|
206
222
|
}
|
|
207
|
-
return tr;
|
|
208
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" }
|
|
209
233
|
],
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
ctx.get(commandsCtx).call(ModifyLink, value);
|
|
222
|
-
},
|
|
223
|
-
calculatePosition: (view, input) => {
|
|
224
|
-
calculateTextPosition(view, input, (start, end, target, parent) => {
|
|
225
|
-
const $editor = view.dom.parentElement;
|
|
226
|
-
if (!$editor) {
|
|
227
|
-
throw new Error();
|
|
228
|
-
}
|
|
229
|
-
const selectionWidth = end.left - start.left;
|
|
230
|
-
let left = start.left - parent.left - (target.width - selectionWidth) / 2;
|
|
231
|
-
let top = start.bottom - parent.top + 14 + $editor.scrollTop;
|
|
232
|
-
if (renderOnTop) {
|
|
233
|
-
top = start.top - parent.top - target.height - 14 + $editor.scrollTop;
|
|
234
|
-
}
|
|
235
|
-
if (left < 0)
|
|
236
|
-
left = 0;
|
|
237
|
-
return [top, left];
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
if (!inputChipRenderer)
|
|
242
|
-
return {};
|
|
243
|
-
const shouldDisplay = (view) => {
|
|
244
|
-
const { selection, doc: doc2 } = view.state;
|
|
245
|
-
const { from, to } = selection;
|
|
246
|
-
if (!view.hasFocus()) {
|
|
247
|
-
return false;
|
|
248
|
-
}
|
|
249
|
-
if (selection.empty && selection instanceof TextSelection && to < doc2.content.size && from < doc2.content.size && doc2.rangeHasMark(from, from === to ? to + 1 : to, type)) {
|
|
250
|
-
renderOnTop = false;
|
|
251
|
-
return true;
|
|
252
|
-
}
|
|
253
|
-
if (selection instanceof NodeSelection) {
|
|
254
|
-
const { node } = selection;
|
|
255
|
-
if (node.type.name === "image" && node.marks.findIndex((mark) => mark.type.name === id$8) > -1) {
|
|
256
|
-
renderOnTop = true;
|
|
257
|
-
return true;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
return false;
|
|
261
|
-
};
|
|
262
|
-
const getCurrentLink = (view) => {
|
|
263
|
-
const { selection } = view.state;
|
|
264
|
-
let node;
|
|
265
|
-
const { from, to } = selection;
|
|
266
|
-
view.state.doc.nodesBetween(from, from === to ? to + 1 : to, (n) => {
|
|
267
|
-
if (type.isInSet(n.marks)) {
|
|
268
|
-
node = n;
|
|
269
|
-
return false;
|
|
270
|
-
}
|
|
271
|
-
return;
|
|
272
|
-
});
|
|
273
|
-
if (!node)
|
|
274
|
-
return;
|
|
275
|
-
const mark = node.marks.find((m) => m.type === type);
|
|
276
|
-
if (!mark)
|
|
277
|
-
return;
|
|
278
|
-
const value = mark.attrs["href"];
|
|
279
|
-
return value;
|
|
280
|
-
};
|
|
281
|
-
const renderByView = (view) => {
|
|
282
|
-
if (!view.editable) {
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
285
|
-
const display = shouldDisplay(view);
|
|
286
|
-
if (display) {
|
|
287
|
-
inputChipRenderer.show(view);
|
|
288
|
-
inputChipRenderer.update(getCurrentLink(view));
|
|
289
|
-
} else {
|
|
290
|
-
inputChipRenderer.hide();
|
|
291
|
-
}
|
|
292
|
-
};
|
|
293
|
-
inputChipRenderer.init(editorView);
|
|
294
|
-
renderByView(editorView);
|
|
295
|
-
return {
|
|
296
|
-
update: (view, prevState) => {
|
|
297
|
-
const isEqualSelection = (prevState == null ? void 0 : prevState.doc.eq(view.state.doc)) && prevState.selection.eq(view.state.selection);
|
|
298
|
-
if (isEqualSelection)
|
|
299
|
-
return;
|
|
300
|
-
requestAnimationFrame(() => {
|
|
301
|
-
renderByView(view);
|
|
302
|
-
});
|
|
303
|
-
},
|
|
304
|
-
destroy: () => {
|
|
305
|
-
inputChipRenderer.destroy();
|
|
306
|
-
}
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
})
|
|
310
|
-
];
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
});
|
|
314
|
-
const id$7 = "strong";
|
|
315
|
-
const ToggleBold = createCmdKey("ToggleBold");
|
|
316
|
-
const strong = createMark((utils) => {
|
|
317
|
-
return {
|
|
318
|
-
id: id$7,
|
|
319
|
-
schema: () => ({
|
|
320
|
-
parseDOM: [
|
|
321
|
-
{ tag: "b" },
|
|
322
|
-
{ tag: "strong" },
|
|
323
|
-
{ style: "font-style", getAttrs: (value) => value === "bold" }
|
|
324
|
-
],
|
|
325
|
-
toDOM: (mark) => ["strong", { class: utils.getClassName(mark.attrs, id$7) }],
|
|
326
|
-
parseMarkdown: {
|
|
327
|
-
match: (node) => node.type === "strong",
|
|
328
|
-
runner: (state, node, markType) => {
|
|
329
|
-
state.openMark(markType);
|
|
330
|
-
state.next(node.children);
|
|
331
|
-
state.closeMark(markType);
|
|
332
|
-
}
|
|
333
|
-
},
|
|
334
|
-
toMarkdown: {
|
|
335
|
-
match: (mark) => mark.type.name === id$7,
|
|
336
|
-
runner: (state, mark) => {
|
|
337
|
-
state.withMark(mark, "strong");
|
|
338
|
-
}
|
|
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");
|
|
339
245
|
}
|
|
340
|
-
}),
|
|
341
|
-
inputRules: (markType) => [
|
|
342
|
-
markRule(/(?:__)([^_]+)(?:__)$/, markType),
|
|
343
|
-
markRule(/(?:\*\*)([^*]+)(?:\*\*)$/, markType)
|
|
344
|
-
],
|
|
345
|
-
commands: (markType) => [createCmd(ToggleBold, () => toggleMark(markType))],
|
|
346
|
-
shortcuts: {
|
|
347
|
-
[SupportedKeys.Bold]: createShortcut(ToggleBold, "Mod-b")
|
|
348
246
|
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
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();
|
|
374
274
|
}
|
|
375
|
-
}),
|
|
376
|
-
inputRules: (nodeType) => [wrappingInputRule(/^\s*>\s$/, nodeType)],
|
|
377
|
-
commands: (nodeType) => [createCmd(WrapInBlockquote, () => wrapIn(nodeType))],
|
|
378
|
-
shortcuts: {
|
|
379
|
-
[SupportedKeys.Blockquote]: createShortcut(WrapInBlockquote, "Mod-Shift-b")
|
|
380
275
|
}
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
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";
|
|
386
284
|
return {
|
|
387
|
-
id:
|
|
285
|
+
id: e,
|
|
388
286
|
schema: () => ({
|
|
389
287
|
content: "listItem+",
|
|
390
288
|
group: "block",
|
|
391
289
|
parseDOM: [{ tag: "ul" }],
|
|
392
|
-
toDOM: (
|
|
393
|
-
return ["ul", { class: utils.getClassName(node.attrs, "bullet-list") }, 0];
|
|
394
|
-
},
|
|
290
|
+
toDOM: (t) => ["ul", { class: c.getClassName(t.attrs, "bullet-list") }, 0],
|
|
395
291
|
parseMarkdown: {
|
|
396
|
-
match: ({ type, ordered }) =>
|
|
397
|
-
runner: (
|
|
398
|
-
|
|
292
|
+
match: ({ type: t, ordered: r }) => t === "list" && !r,
|
|
293
|
+
runner: (t, r, n) => {
|
|
294
|
+
t.openNode(n).next(r.children).closeNode();
|
|
399
295
|
}
|
|
400
296
|
},
|
|
401
297
|
toMarkdown: {
|
|
402
|
-
match: (
|
|
403
|
-
runner: (
|
|
404
|
-
|
|
298
|
+
match: (t) => t.type.name === e,
|
|
299
|
+
runner: (t, r) => {
|
|
300
|
+
t.openNode("list", void 0, { ordered: !1 }).next(r.content).closeNode();
|
|
405
301
|
}
|
|
406
302
|
}
|
|
407
303
|
}),
|
|
408
|
-
inputRules: (
|
|
409
|
-
commands: (
|
|
304
|
+
inputRules: (t) => [W(/^\s*([-+*])\s$/, t)],
|
|
305
|
+
commands: (t) => [M(te, () => de(t))],
|
|
410
306
|
shortcuts: {
|
|
411
|
-
[
|
|
307
|
+
[k.BulletList]: h(te, "Mod-Alt-8")
|
|
412
308
|
}
|
|
413
309
|
};
|
|
414
|
-
})
|
|
415
|
-
const languageOptions = [
|
|
310
|
+
}), Qe = [
|
|
416
311
|
"",
|
|
417
312
|
"javascript",
|
|
418
313
|
"typescript",
|
|
@@ -429,304 +324,333 @@ const languageOptions = [
|
|
|
429
324
|
"go",
|
|
430
325
|
"rust",
|
|
431
326
|
"markdown"
|
|
432
|
-
]
|
|
433
|
-
const
|
|
434
|
-
const tildeInputRegex = /^~~~(?<language>[a-z]*)?[\s\n]$/;
|
|
435
|
-
const TurnIntoCodeFence = createCmdKey("TurnIntoCodeFence");
|
|
436
|
-
const id$5 = "fence";
|
|
437
|
-
const codeFence = createNode((utils, options) => {
|
|
438
|
-
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;
|
|
439
329
|
return {
|
|
440
|
-
id:
|
|
441
|
-
schema: (
|
|
330
|
+
id: V,
|
|
331
|
+
schema: (r) => ({
|
|
442
332
|
content: "text*",
|
|
443
333
|
group: "block",
|
|
444
334
|
marks: "",
|
|
445
|
-
defining:
|
|
446
|
-
code:
|
|
335
|
+
defining: !0,
|
|
336
|
+
code: !0,
|
|
447
337
|
attrs: {
|
|
448
338
|
language: {
|
|
449
339
|
default: ""
|
|
450
340
|
},
|
|
451
341
|
fold: {
|
|
452
|
-
default:
|
|
342
|
+
default: !0
|
|
453
343
|
}
|
|
454
344
|
},
|
|
455
345
|
parseDOM: [
|
|
456
346
|
{
|
|
457
347
|
tag: "div.code-fence-container",
|
|
458
348
|
preserveWhitespace: "full",
|
|
459
|
-
getAttrs: (
|
|
460
|
-
var
|
|
461
|
-
if (!(
|
|
462
|
-
throw
|
|
463
|
-
}
|
|
464
|
-
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 };
|
|
465
354
|
},
|
|
466
|
-
getContent: (
|
|
467
|
-
var
|
|
468
|
-
if (!(
|
|
469
|
-
throw
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
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);
|
|
473
361
|
}
|
|
474
362
|
},
|
|
475
363
|
{
|
|
476
364
|
tag: "pre",
|
|
477
365
|
preserveWhitespace: "full",
|
|
478
|
-
getAttrs: (
|
|
479
|
-
if (!(
|
|
480
|
-
throw
|
|
481
|
-
}
|
|
482
|
-
return { language: dom.dataset["language"] };
|
|
366
|
+
getAttrs: (n) => {
|
|
367
|
+
if (!(n instanceof HTMLElement))
|
|
368
|
+
throw D(n);
|
|
369
|
+
return { language: n.dataset.language };
|
|
483
370
|
}
|
|
484
371
|
}
|
|
485
372
|
],
|
|
486
|
-
toDOM: (
|
|
487
|
-
const
|
|
488
|
-
|
|
489
|
-
const
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
}
|
|
495
|
-
select.appendChild(option);
|
|
496
|
-
});
|
|
497
|
-
select.onchange = (e) => {
|
|
498
|
-
const target = e.target;
|
|
499
|
-
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))
|
|
500
381
|
return;
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
target.value = node.attrs["language"];
|
|
382
|
+
const l = r.get(R);
|
|
383
|
+
if (!l.editable) {
|
|
384
|
+
o.value = n.attrs.language;
|
|
505
385
|
return;
|
|
506
386
|
}
|
|
507
|
-
const { top, left } =
|
|
508
|
-
|
|
509
|
-
if (!result)
|
|
387
|
+
const { top: i, left: d } = o.getBoundingClientRect(), m = l.posAtCoords({ top: i, left: d });
|
|
388
|
+
if (!m)
|
|
510
389
|
return;
|
|
511
|
-
const { tr } =
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
390
|
+
const { tr: g } = l.state;
|
|
391
|
+
l.dispatch(g.setNodeMarkup(m.inside, void 0, {
|
|
392
|
+
...n.attrs,
|
|
393
|
+
language: o.value
|
|
394
|
+
}));
|
|
395
|
+
}, [
|
|
517
396
|
"div",
|
|
518
397
|
{
|
|
519
398
|
class: "code-fence-container"
|
|
520
399
|
},
|
|
521
|
-
|
|
400
|
+
s,
|
|
522
401
|
[
|
|
523
402
|
"pre",
|
|
524
403
|
{
|
|
525
|
-
"data-language":
|
|
526
|
-
class:
|
|
404
|
+
"data-language": n.attrs.language,
|
|
405
|
+
class: c.getClassName(n.attrs, "code-fence")
|
|
527
406
|
},
|
|
528
407
|
["code", { spellCheck: "false" }, 0]
|
|
529
408
|
]
|
|
530
409
|
];
|
|
531
410
|
},
|
|
532
411
|
parseMarkdown: {
|
|
533
|
-
match: ({ type }) =>
|
|
534
|
-
runner: (
|
|
535
|
-
const
|
|
536
|
-
|
|
537
|
-
state.openNode(type, { language });
|
|
538
|
-
if (value) {
|
|
539
|
-
state.addText(value);
|
|
540
|
-
}
|
|
541
|
-
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();
|
|
542
416
|
}
|
|
543
417
|
},
|
|
544
418
|
toMarkdown: {
|
|
545
|
-
match: (
|
|
546
|
-
runner: (
|
|
547
|
-
var
|
|
548
|
-
|
|
549
|
-
lang:
|
|
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
|
|
550
424
|
});
|
|
551
425
|
}
|
|
552
426
|
}
|
|
553
427
|
}),
|
|
554
|
-
inputRules: (
|
|
555
|
-
|
|
556
|
-
const [
|
|
557
|
-
if (
|
|
558
|
-
return;
|
|
559
|
-
return { language };
|
|
428
|
+
inputRules: (r) => [
|
|
429
|
+
G(Xe, r, (n) => {
|
|
430
|
+
const [s, a] = n;
|
|
431
|
+
if (!!s)
|
|
432
|
+
return { language: a };
|
|
560
433
|
}),
|
|
561
|
-
|
|
562
|
-
const [
|
|
563
|
-
if (
|
|
564
|
-
return;
|
|
565
|
-
return { language };
|
|
434
|
+
G(Ye, r, (n) => {
|
|
435
|
+
const [s, a] = n;
|
|
436
|
+
if (!!s)
|
|
437
|
+
return { language: a };
|
|
566
438
|
})
|
|
567
439
|
],
|
|
568
|
-
commands: (
|
|
440
|
+
commands: (r) => [M(re, () => E(r))],
|
|
569
441
|
shortcuts: {
|
|
570
|
-
[
|
|
442
|
+
[k.CodeFence]: h(re, "Mod-Alt-c")
|
|
571
443
|
},
|
|
572
|
-
view: () => (
|
|
573
|
-
let
|
|
574
|
-
const
|
|
575
|
-
const { tr } =
|
|
576
|
-
|
|
577
|
-
fold:
|
|
578
|
-
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
|
|
579
451
|
}));
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
fold:
|
|
585
|
-
}))
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
fold:
|
|
591
|
-
}))
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
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
|
|
599
470
|
});
|
|
600
|
-
if (!
|
|
471
|
+
if (!d)
|
|
601
472
|
return {};
|
|
602
|
-
const { dom, contentDOM, onUpdate, onDestroy } =
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
if (updatedNode.type.name !== id$5)
|
|
609
|
-
return false;
|
|
610
|
-
currNode = updatedNode;
|
|
611
|
-
onUpdate(currNode);
|
|
612
|
-
return true;
|
|
613
|
-
},
|
|
614
|
-
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
|
|
615
479
|
};
|
|
616
480
|
}
|
|
617
481
|
};
|
|
618
|
-
})
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
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, []);
|
|
628
550
|
}
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
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;
|
|
635
557
|
}
|
|
636
558
|
}
|
|
637
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);
|
|
638
576
|
};
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
parseMarkdown: {
|
|
651
|
-
match: ({ type }) => type === "break",
|
|
652
|
-
runner: (state, _, type) => {
|
|
653
|
-
state.addNode(type);
|
|
654
|
-
}
|
|
655
|
-
},
|
|
656
|
-
toMarkdown: {
|
|
657
|
-
match: (node) => node.type.name === "hardbreak",
|
|
658
|
-
runner: (state) => {
|
|
659
|
-
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;
|
|
660
588
|
}
|
|
661
589
|
}
|
|
662
|
-
}),
|
|
663
|
-
commands: (type) => [
|
|
664
|
-
createCmd(InsertHardbreak, () => (state, dispatch) => {
|
|
665
|
-
var _a;
|
|
666
|
-
const { selection, tr } = state;
|
|
667
|
-
if (selection.empty) {
|
|
668
|
-
const node = selection.$from.node();
|
|
669
|
-
if (node.childCount > 0 && ((_a = node.lastChild) == null ? void 0 : _a.type.name) === "hardbreak") {
|
|
670
|
-
dispatch == null ? void 0 : dispatch(tr.replaceRangeWith(selection.to - 1, selection.to, state.schema.node("paragraph")).setSelection(Selection.near(tr.doc.resolve(selection.to))).scrollIntoView());
|
|
671
|
-
return true;
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
dispatch == null ? void 0 : dispatch(tr.setMeta("hardbreak", true).replaceSelectionWith(type.create()).scrollIntoView());
|
|
675
|
-
return true;
|
|
676
|
-
})
|
|
677
|
-
],
|
|
678
|
-
shortcuts: {
|
|
679
|
-
[SupportedKeys.HardBreak]: createShortcut(InsertHardbreak, "Shift-Enter")
|
|
680
590
|
},
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
const
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
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;
|
|
724
648
|
return {
|
|
725
|
-
id:
|
|
649
|
+
id: t,
|
|
726
650
|
schema: () => ({
|
|
727
651
|
content: "inline*",
|
|
728
652
|
group: "block",
|
|
729
|
-
defining:
|
|
653
|
+
defining: !0,
|
|
730
654
|
attrs: {
|
|
731
655
|
id: {
|
|
732
656
|
default: ""
|
|
@@ -735,422 +659,351 @@ const heading = createNode((utils, options) => {
|
|
|
735
659
|
default: 1
|
|
736
660
|
}
|
|
737
661
|
},
|
|
738
|
-
parseDOM:
|
|
739
|
-
tag: `h${
|
|
740
|
-
getAttrs: (
|
|
741
|
-
if (!(
|
|
742
|
-
throw
|
|
743
|
-
}
|
|
744
|
-
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 };
|
|
745
668
|
}
|
|
746
669
|
})),
|
|
747
|
-
toDOM: (
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
];
|
|
756
|
-
},
|
|
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
|
+
],
|
|
757
678
|
parseMarkdown: {
|
|
758
|
-
match: ({ type }) =>
|
|
759
|
-
runner: (
|
|
760
|
-
const
|
|
761
|
-
|
|
762
|
-
state.next(node.children);
|
|
763
|
-
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();
|
|
764
683
|
}
|
|
765
684
|
},
|
|
766
685
|
toMarkdown: {
|
|
767
|
-
match: (
|
|
768
|
-
runner: (
|
|
769
|
-
var
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
contentArr.push(n);
|
|
779
|
-
});
|
|
780
|
-
state.next(Fragment.fromArray(contentArr));
|
|
781
|
-
} else {
|
|
782
|
-
state.next(node.content);
|
|
783
|
-
}
|
|
784
|
-
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();
|
|
785
697
|
}
|
|
786
698
|
}
|
|
787
699
|
}),
|
|
788
|
-
inputRules: (
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
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
|
+
],
|
|
792
725
|
shortcuts: {
|
|
793
|
-
[
|
|
794
|
-
[
|
|
795
|
-
[
|
|
796
|
-
[
|
|
797
|
-
[
|
|
798
|
-
[
|
|
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"])
|
|
799
733
|
},
|
|
800
|
-
prosePlugins: (
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
const tr = state.tr;
|
|
804
|
-
state.doc.descendants((node, pos) => {
|
|
805
|
-
if (node.type === type && !lock) {
|
|
806
|
-
if (node.textContent.trim().length === 0) {
|
|
807
|
-
return;
|
|
808
|
-
}
|
|
809
|
-
const attrs = node.attrs;
|
|
810
|
-
const id22 = getId(node);
|
|
811
|
-
if (attrs["id"] !== id22) {
|
|
812
|
-
tr.setMeta(headingPluginKey, true).setNodeMarkup(pos, void 0, __spreadProps(__spreadValues({}, attrs), {
|
|
813
|
-
id: id22
|
|
814
|
-
}));
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
});
|
|
818
|
-
callback(tr);
|
|
819
|
-
};
|
|
820
|
-
return [
|
|
821
|
-
new Plugin({
|
|
822
|
-
key: headingPluginKey,
|
|
823
|
-
props: {
|
|
824
|
-
handleDOMEvents: {
|
|
825
|
-
compositionstart: () => {
|
|
826
|
-
lock = true;
|
|
827
|
-
return false;
|
|
828
|
-
},
|
|
829
|
-
compositionend: () => {
|
|
830
|
-
lock = false;
|
|
831
|
-
const view = ctx.get(editorViewCtx);
|
|
832
|
-
setTimeout(() => {
|
|
833
|
-
walkThrough(view.state, (tr) => view.dispatch(tr));
|
|
834
|
-
}, 0);
|
|
835
|
-
return false;
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
},
|
|
839
|
-
appendTransaction: (transactions, _, nextState) => {
|
|
840
|
-
let tr = null;
|
|
841
|
-
if (transactions.every((transaction) => !transaction.getMeta(headingPluginKey)) && transactions.some((transaction) => transaction.docChanged)) {
|
|
842
|
-
walkThrough(nextState, (t) => {
|
|
843
|
-
tr = t;
|
|
844
|
-
});
|
|
845
|
-
}
|
|
846
|
-
return tr;
|
|
847
|
-
},
|
|
848
|
-
view: (view) => {
|
|
849
|
-
const doc2 = view.state.doc;
|
|
850
|
-
let tr = view.state.tr;
|
|
851
|
-
doc2.descendants((node, pos) => {
|
|
852
|
-
if (node.type.name === "heading" && node.attrs["level"]) {
|
|
853
|
-
if (!node.attrs["id"]) {
|
|
854
|
-
tr = tr.setNodeMarkup(pos, void 0, __spreadProps(__spreadValues({}, node.attrs), {
|
|
855
|
-
id: getId(node)
|
|
856
|
-
}));
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
});
|
|
860
|
-
view.dispatch(tr);
|
|
861
|
-
return {};
|
|
862
|
-
}
|
|
863
|
-
})
|
|
864
|
-
];
|
|
734
|
+
prosePlugins: (o, l) => {
|
|
735
|
+
const i = [st(l, o, r)];
|
|
736
|
+
return n && i.push(ot(l, o, c)), i;
|
|
865
737
|
}
|
|
866
738
|
};
|
|
867
|
-
})
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
parseMarkdown: {
|
|
878
|
-
match: ({ type }) => type === "thematicBreak",
|
|
879
|
-
runner: (state, _, type) => {
|
|
880
|
-
state.addNode(type);
|
|
881
|
-
}
|
|
882
|
-
},
|
|
883
|
-
toMarkdown: {
|
|
884
|
-
match: (node) => node.type.name === id$4,
|
|
885
|
-
runner: (state) => {
|
|
886
|
-
state.addNode("thematicBreak");
|
|
887
|
-
}
|
|
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);
|
|
888
749
|
}
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
tr.replaceWith(start - 1, end, type.create());
|
|
895
|
-
}
|
|
896
|
-
return tr;
|
|
897
|
-
})
|
|
898
|
-
],
|
|
899
|
-
commands: (type, ctx) => [
|
|
900
|
-
createCmd(InsertHr, () => (state, dispatch) => {
|
|
901
|
-
if (!dispatch)
|
|
902
|
-
return true;
|
|
903
|
-
const paragraph2 = ctx.get(schemaCtx).node("paragraph");
|
|
904
|
-
const { tr, selection } = state;
|
|
905
|
-
const { from } = selection;
|
|
906
|
-
const node = type.create();
|
|
907
|
-
if (!node) {
|
|
908
|
-
return true;
|
|
909
|
-
}
|
|
910
|
-
const _tr = tr.replaceSelectionWith(node).insert(from, paragraph2);
|
|
911
|
-
const sel = Selection.findFrom(_tr.doc.resolve(from), 1, true);
|
|
912
|
-
if (!sel) {
|
|
913
|
-
return true;
|
|
914
|
-
}
|
|
915
|
-
dispatch(_tr.setSelection(sel).scrollIntoView());
|
|
916
|
-
return true;
|
|
917
|
-
})
|
|
918
|
-
]
|
|
919
|
-
};
|
|
920
|
-
});
|
|
921
|
-
const ModifyImage = createCmdKey("ModifyImage");
|
|
922
|
-
const InsertImage = createCmdKey("InsertImage");
|
|
923
|
-
const id$3 = "image";
|
|
924
|
-
const key = new PluginKey("MILKDOWN_IMAGE_INPUT");
|
|
925
|
-
const image = createNode((utils, options) => {
|
|
926
|
-
return {
|
|
927
|
-
id: "image",
|
|
928
|
-
schema: () => ({
|
|
929
|
-
inline: true,
|
|
930
|
-
group: "inline",
|
|
931
|
-
selectable: true,
|
|
932
|
-
draggable: true,
|
|
933
|
-
marks: "",
|
|
934
|
-
atom: true,
|
|
935
|
-
defining: true,
|
|
936
|
-
isolating: true,
|
|
937
|
-
attrs: {
|
|
938
|
-
src: { default: "" },
|
|
939
|
-
alt: { default: null },
|
|
940
|
-
title: { default: null }
|
|
941
|
-
},
|
|
942
|
-
parseDOM: [
|
|
943
|
-
{
|
|
944
|
-
tag: "img[src]",
|
|
945
|
-
getAttrs: (dom) => {
|
|
946
|
-
if (!(dom instanceof HTMLElement)) {
|
|
947
|
-
throw new Error();
|
|
948
|
-
}
|
|
949
|
-
return {
|
|
950
|
-
src: dom.getAttribute("src") || "",
|
|
951
|
-
alt: dom.getAttribute("alt"),
|
|
952
|
-
title: dom.getAttribute("title") || dom.getAttribute("alt"),
|
|
953
|
-
width: dom.getAttribute("width")
|
|
954
|
-
};
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
],
|
|
958
|
-
toDOM: (node) => {
|
|
959
|
-
return [
|
|
960
|
-
"img",
|
|
961
|
-
__spreadProps(__spreadValues({}, node.attrs), {
|
|
962
|
-
class: utils.getClassName(node.attrs, id$3)
|
|
963
|
-
})
|
|
964
|
-
];
|
|
965
|
-
},
|
|
966
|
-
parseMarkdown: {
|
|
967
|
-
match: ({ type }) => type === id$3,
|
|
968
|
-
runner: (state, node, type) => {
|
|
969
|
-
const url = node["url"];
|
|
970
|
-
const alt = node["alt"];
|
|
971
|
-
const title = node["title"];
|
|
972
|
-
state.addNode(type, {
|
|
973
|
-
src: url,
|
|
974
|
-
alt,
|
|
975
|
-
title
|
|
976
|
-
});
|
|
977
|
-
}
|
|
978
|
-
},
|
|
979
|
-
toMarkdown: {
|
|
980
|
-
match: (node) => node.type.name === id$3,
|
|
981
|
-
runner: (state, node) => {
|
|
982
|
-
state.addNode("image", void 0, void 0, {
|
|
983
|
-
title: node.attrs["title"],
|
|
984
|
-
url: node.attrs["src"],
|
|
985
|
-
alt: node.attrs["alt"]
|
|
986
|
-
});
|
|
987
|
-
}
|
|
750
|
+
},
|
|
751
|
+
toMarkdown: {
|
|
752
|
+
match: (e) => e.type.name === z,
|
|
753
|
+
runner: (e) => {
|
|
754
|
+
e.addNode("thematicBreak");
|
|
988
755
|
}
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
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
|
+
};
|
|
998
803
|
}
|
|
999
|
-
|
|
1000
|
-
dispatch(_tr.scrollIntoView());
|
|
1001
|
-
return true;
|
|
1002
|
-
}),
|
|
1003
|
-
createCmd(ModifyImage, (src = "") => (state, dispatch) => {
|
|
1004
|
-
const node = findSelectedNodeOfType(state.selection, type);
|
|
1005
|
-
if (!node)
|
|
1006
|
-
return false;
|
|
1007
|
-
const { tr } = state;
|
|
1008
|
-
dispatch == null ? void 0 : dispatch(tr.setNodeMarkup(node.pos, void 0, __spreadProps(__spreadValues({}, node.node.attrs), { loading: true, src })).scrollIntoView());
|
|
1009
|
-
return true;
|
|
1010
|
-
})
|
|
804
|
+
}
|
|
1011
805
|
],
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
}
|
|
1019
|
-
return tr;
|
|
1020
|
-
})
|
|
806
|
+
toDOM: (t) => [
|
|
807
|
+
"img",
|
|
808
|
+
{
|
|
809
|
+
...t.attrs,
|
|
810
|
+
class: c.getClassName(t.attrs, S)
|
|
811
|
+
}
|
|
1021
812
|
],
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
if (!renderer) {
|
|
1032
|
-
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
|
+
});
|
|
1033
822
|
}
|
|
1034
|
-
const { dom, onUpdate } = renderer;
|
|
1035
|
-
onUpdate(currNode);
|
|
1036
|
-
return {
|
|
1037
|
-
dom,
|
|
1038
|
-
update: (updatedNode) => {
|
|
1039
|
-
if (updatedNode.type.name !== id$3)
|
|
1040
|
-
return false;
|
|
1041
|
-
currNode = updatedNode;
|
|
1042
|
-
onUpdate(currNode);
|
|
1043
|
-
return true;
|
|
1044
|
-
},
|
|
1045
|
-
selectNode: () => {
|
|
1046
|
-
dom.classList.add("ProseMirror-selectednode");
|
|
1047
|
-
},
|
|
1048
|
-
deselectNode: () => {
|
|
1049
|
-
dom.classList.remove("ProseMirror-selectednode");
|
|
1050
|
-
}
|
|
1051
|
-
};
|
|
1052
823
|
},
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
onUpdate: (value) => {
|
|
1063
|
-
ctx.get(commandsCtx).call(ModifyImage, value);
|
|
1064
|
-
}
|
|
1065
|
-
});
|
|
1066
|
-
if (!inputChipRenderer)
|
|
1067
|
-
return {};
|
|
1068
|
-
const shouldDisplay = (view) => {
|
|
1069
|
-
return Boolean(view.hasFocus() && type && findSelectedNodeOfType(view.state.selection, type));
|
|
1070
|
-
};
|
|
1071
|
-
const getCurrentLink = (view) => {
|
|
1072
|
-
const result = findSelectedNodeOfType(view.state.selection, type);
|
|
1073
|
-
if (!result)
|
|
1074
|
-
return;
|
|
1075
|
-
const value = result.node.attrs["src"];
|
|
1076
|
-
return value;
|
|
1077
|
-
};
|
|
1078
|
-
const renderByView = (view) => {
|
|
1079
|
-
if (!view.editable) {
|
|
1080
|
-
return;
|
|
1081
|
-
}
|
|
1082
|
-
const display = shouldDisplay(view);
|
|
1083
|
-
if (display) {
|
|
1084
|
-
inputChipRenderer.show(view);
|
|
1085
|
-
inputChipRenderer.update(getCurrentLink(view));
|
|
1086
|
-
} else {
|
|
1087
|
-
inputChipRenderer.hide();
|
|
1088
|
-
}
|
|
1089
|
-
};
|
|
1090
|
-
inputChipRenderer.init(editorView);
|
|
1091
|
-
renderByView(editorView);
|
|
1092
|
-
return {
|
|
1093
|
-
update: (view, prevState) => {
|
|
1094
|
-
const isEqualSelection = (prevState == null ? void 0 : prevState.doc.eq(view.state.doc)) && prevState.selection.eq(view.state.selection);
|
|
1095
|
-
if (isEqualSelection)
|
|
1096
|
-
return;
|
|
1097
|
-
renderByView(view);
|
|
1098
|
-
},
|
|
1099
|
-
destroy: () => {
|
|
1100
|
-
inputChipRenderer.destroy();
|
|
1101
|
-
}
|
|
1102
|
-
};
|
|
1103
|
-
}
|
|
1104
|
-
})
|
|
1105
|
-
];
|
|
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
|
+
}
|
|
1106
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);
|
|
1107
930
|
};
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
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,
|
|
1115
942
|
schema: () => ({
|
|
1116
943
|
group: "listItem",
|
|
1117
944
|
content: "paragraph block*",
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
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
|
+
],
|
|
1121
979
|
parseMarkdown: {
|
|
1122
|
-
match: ({ type, checked }) =>
|
|
1123
|
-
runner: (
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
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();
|
|
1127
984
|
}
|
|
1128
985
|
},
|
|
1129
986
|
toMarkdown: {
|
|
1130
|
-
match: (
|
|
1131
|
-
runner: (
|
|
1132
|
-
|
|
1133
|
-
state.next(node.content);
|
|
1134
|
-
state.closeNode();
|
|
987
|
+
match: (e) => e.type.name === Ie,
|
|
988
|
+
runner: (e, t) => {
|
|
989
|
+
e.openNode("listItem"), e.next(t.content), e.closeNode();
|
|
1135
990
|
}
|
|
1136
991
|
}
|
|
1137
992
|
}),
|
|
1138
|
-
inputRules: (
|
|
1139
|
-
commands: (
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
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))
|
|
1143
998
|
],
|
|
1144
999
|
shortcuts: {
|
|
1145
|
-
[
|
|
1146
|
-
[
|
|
1147
|
-
[
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
const orderedList = createNode((utils) => ({
|
|
1153
|
-
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,
|
|
1154
1007
|
schema: () => ({
|
|
1155
1008
|
content: "listItem+",
|
|
1156
1009
|
group: "block",
|
|
@@ -1162,244 +1015,250 @@ const orderedList = createNode((utils) => ({
|
|
|
1162
1015
|
parseDOM: [
|
|
1163
1016
|
{
|
|
1164
1017
|
tag: "ol",
|
|
1165
|
-
getAttrs: (
|
|
1166
|
-
if (!(
|
|
1167
|
-
throw
|
|
1168
|
-
}
|
|
1169
|
-
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 };
|
|
1170
1022
|
}
|
|
1171
1023
|
}
|
|
1172
1024
|
],
|
|
1173
|
-
toDOM: (
|
|
1025
|
+
toDOM: (e) => [
|
|
1174
1026
|
"ol",
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1027
|
+
{
|
|
1028
|
+
...e.attrs.order === 1 ? {} : e.attrs.order,
|
|
1029
|
+
class: c.getClassName(e.attrs, "ordered-list")
|
|
1030
|
+
},
|
|
1178
1031
|
0
|
|
1179
1032
|
],
|
|
1180
1033
|
parseMarkdown: {
|
|
1181
|
-
match: ({ type, ordered }) =>
|
|
1182
|
-
runner: (
|
|
1183
|
-
|
|
1034
|
+
match: ({ type: e, ordered: t }) => e === "list" && !!t,
|
|
1035
|
+
runner: (e, t, r) => {
|
|
1036
|
+
e.openNode(r).next(t.children).closeNode();
|
|
1184
1037
|
}
|
|
1185
1038
|
},
|
|
1186
1039
|
toMarkdown: {
|
|
1187
|
-
match: (
|
|
1188
|
-
runner: (
|
|
1189
|
-
|
|
1190
|
-
state.next(node.content);
|
|
1191
|
-
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();
|
|
1192
1043
|
}
|
|
1193
1044
|
}
|
|
1194
1045
|
}),
|
|
1195
|
-
inputRules: (
|
|
1196
|
-
|
|
1046
|
+
inputRules: (e) => [
|
|
1047
|
+
W(/^(\d+)\.\s$/, e, (t) => ({ order: Number(t[1]) }), (t, r) => r.childCount + r.attrs.order === Number(t[1]))
|
|
1197
1048
|
],
|
|
1198
|
-
commands: (
|
|
1049
|
+
commands: (e) => [M(ce, () => de(e))],
|
|
1199
1050
|
shortcuts: {
|
|
1200
|
-
[
|
|
1051
|
+
[k.OrderedList]: h(ce, "Mod-Alt-7")
|
|
1201
1052
|
}
|
|
1202
|
-
}))
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
runner: (state, node) => {
|
|
1228
|
-
var _a;
|
|
1229
|
-
state.openNode("paragraph");
|
|
1230
|
-
const lastIsHardbreak = node.childCount >= 1 && ((_a = node.lastChild) == null ? void 0 : _a.type.name) === "hardbreak";
|
|
1231
|
-
if (lastIsHardbreak) {
|
|
1232
|
-
const contentArr = [];
|
|
1233
|
-
node.content.forEach((n, _, i) => {
|
|
1234
|
-
if (i === node.childCount - 1) {
|
|
1235
|
-
return;
|
|
1236
|
-
}
|
|
1237
|
-
contentArr.push(n);
|
|
1238
|
-
});
|
|
1239
|
-
state.next(Fragment.fromArray(contentArr));
|
|
1240
|
-
} else {
|
|
1241
|
-
state.next(node.content);
|
|
1242
|
-
}
|
|
1243
|
-
state.closeNode();
|
|
1244
|
-
}
|
|
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();
|
|
1245
1078
|
}
|
|
1246
|
-
}),
|
|
1247
|
-
commands: (nodeType) => [createCmd(TurnIntoText, () => setBlockType(nodeType))],
|
|
1248
|
-
shortcuts: {
|
|
1249
|
-
[SupportedKeys.Text]: createShortcut(TurnIntoText, "Mod-Alt-0")
|
|
1250
1079
|
}
|
|
1251
|
-
}
|
|
1252
|
-
|
|
1253
|
-
|
|
1080
|
+
}),
|
|
1081
|
+
commands: (e) => [M(ie, () => E(e))],
|
|
1082
|
+
shortcuts: {
|
|
1083
|
+
[k.Text]: h(ie, "Mod-Alt-0")
|
|
1084
|
+
}
|
|
1085
|
+
})), pt = w(() => ({
|
|
1254
1086
|
id: "text",
|
|
1255
1087
|
schema: () => ({
|
|
1256
1088
|
group: "inline",
|
|
1257
1089
|
parseMarkdown: {
|
|
1258
|
-
match: ({ type }) =>
|
|
1259
|
-
runner: (
|
|
1260
|
-
|
|
1090
|
+
match: ({ type: c }) => c === "text",
|
|
1091
|
+
runner: (c, e) => {
|
|
1092
|
+
c.addText(e.value);
|
|
1261
1093
|
}
|
|
1262
1094
|
},
|
|
1263
1095
|
toMarkdown: {
|
|
1264
|
-
match: (
|
|
1265
|
-
runner: (
|
|
1266
|
-
|
|
1096
|
+
match: (c) => c.type.name === "text",
|
|
1097
|
+
runner: (c, e) => {
|
|
1098
|
+
c.addNode("text", void 0, e.text);
|
|
1267
1099
|
}
|
|
1268
1100
|
}
|
|
1269
1101
|
})
|
|
1270
|
-
}))
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
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);
|
|
1302
1143
|
}
|
|
1303
|
-
}
|
|
1304
1144
|
}
|
|
1305
1145
|
}
|
|
1306
|
-
|
|
1146
|
+
r.children = a;
|
|
1307
1147
|
}
|
|
1308
|
-
return
|
|
1148
|
+
return e(r, n, s);
|
|
1309
1149
|
}
|
|
1310
1150
|
}
|
|
1311
|
-
const
|
|
1312
|
-
function
|
|
1313
|
-
|
|
1314
|
-
if (!isHTML(node)) {
|
|
1315
|
-
return [node];
|
|
1316
|
-
}
|
|
1317
|
-
return [];
|
|
1318
|
-
});
|
|
1151
|
+
const yt = () => {
|
|
1152
|
+
function c(e) {
|
|
1153
|
+
bt(e, (t) => It(t) ? [] : [t]);
|
|
1319
1154
|
}
|
|
1320
|
-
return
|
|
1321
|
-
}
|
|
1322
|
-
|
|
1323
|
-
const inlineNodesCursorPlugin = new Plugin({
|
|
1324
|
-
key: inlineNodesCursorPluginKey,
|
|
1155
|
+
return c;
|
|
1156
|
+
}, Nt = new H("MILKDOWN_INLINE_NODES_CURSOR"), ue = new T({
|
|
1157
|
+
key: Nt,
|
|
1325
1158
|
state: {
|
|
1326
1159
|
init() {
|
|
1327
|
-
return
|
|
1160
|
+
return !1;
|
|
1328
1161
|
},
|
|
1329
|
-
apply(
|
|
1330
|
-
if (!
|
|
1331
|
-
return
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
const left = pos.nodeBefore;
|
|
1335
|
-
const right = pos.nodeAfter;
|
|
1336
|
-
if (left && right && left.isInline && !left.isText && right.isInline && !right.isText) {
|
|
1337
|
-
return true;
|
|
1338
|
-
}
|
|
1339
|
-
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);
|
|
1340
1167
|
}
|
|
1341
1168
|
},
|
|
1342
1169
|
props: {
|
|
1343
1170
|
handleDOMEvents: {
|
|
1344
|
-
beforeinput: (
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
e.preventDefault();
|
|
1349
|
-
view.dispatch(view.state.tr.insertText(e.data || "", from));
|
|
1350
|
-
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;
|
|
1351
1175
|
}
|
|
1352
|
-
return
|
|
1176
|
+
return !1;
|
|
1353
1177
|
}
|
|
1354
1178
|
},
|
|
1355
|
-
decorations(
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
const pos = state.selection.$from;
|
|
1359
|
-
const position = pos.pos;
|
|
1360
|
-
const left = document.createElement("span");
|
|
1361
|
-
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, {
|
|
1362
1182
|
side: -1
|
|
1363
|
-
});
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
left.contentEditable = "true";
|
|
1368
|
-
right.contentEditable = "true";
|
|
1369
|
-
});
|
|
1370
|
-
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]);
|
|
1371
1187
|
}
|
|
1372
|
-
return
|
|
1188
|
+
return O.empty;
|
|
1373
1189
|
}
|
|
1374
1190
|
}
|
|
1375
|
-
})
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
remarkPlugins: () => [links, filterHTMLPlugin]
|
|
1191
|
+
}), wt = [
|
|
1192
|
+
He(() => ({
|
|
1193
|
+
prosePlugins: () => [ue],
|
|
1194
|
+
remarkPlugins: () => [We, yt, kt]
|
|
1380
1195
|
}))()
|
|
1381
|
-
]
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
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
|
|
1403
1263
|
};
|
|
1404
|
-
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 };
|
|
1405
1264
|
//# sourceMappingURL=index.es.js.map
|