@jvs-milkdown/preset-commonmark 1.0.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/LICENSE +21 -0
- package/README.md +11 -0
- package/lib/__internal__/index.d.ts +3 -0
- package/lib/__internal__/index.d.ts.map +1 -0
- package/lib/__internal__/serialize-text.d.ts +4 -0
- package/lib/__internal__/serialize-text.d.ts.map +1 -0
- package/lib/__internal__/with-meta.d.ts +3 -0
- package/lib/__internal__/with-meta.d.ts.map +1 -0
- package/lib/__test__/html.spec.d.ts +2 -0
- package/lib/__test__/html.spec.d.ts.map +1 -0
- package/lib/__test__/trailing-space.spec.d.ts +2 -0
- package/lib/__test__/trailing-space.spec.d.ts.map +1 -0
- package/lib/__test__/vitest.setup.d.ts +1 -0
- package/lib/__test__/vitest.setup.d.ts.map +1 -0
- package/lib/commands/index.d.ts +20 -0
- package/lib/commands/index.d.ts.map +1 -0
- package/lib/composed/commands.d.ts +3 -0
- package/lib/composed/commands.d.ts.map +1 -0
- package/lib/composed/index.d.ts +6 -0
- package/lib/composed/index.d.ts.map +1 -0
- package/lib/composed/inputrules.d.ts +4 -0
- package/lib/composed/inputrules.d.ts.map +1 -0
- package/lib/composed/keymap.d.ts +3 -0
- package/lib/composed/keymap.d.ts.map +1 -0
- package/lib/composed/plugins.d.ts +3 -0
- package/lib/composed/plugins.d.ts.map +1 -0
- package/lib/composed/schema.d.ts +3 -0
- package/lib/composed/schema.d.ts.map +1 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +2153 -0
- package/lib/index.js.map +1 -0
- package/lib/mark/emphasis.d.ts +7 -0
- package/lib/mark/emphasis.d.ts.map +1 -0
- package/lib/mark/index.d.ts +5 -0
- package/lib/mark/index.d.ts.map +1 -0
- package/lib/mark/inline-code.d.ts +6 -0
- package/lib/mark/inline-code.d.ts.map +1 -0
- package/lib/mark/link.d.ts +9 -0
- package/lib/mark/link.d.ts.map +1 -0
- package/lib/mark/strong.d.ts +6 -0
- package/lib/mark/strong.d.ts.map +1 -0
- package/lib/node/blockquote.d.ts +7 -0
- package/lib/node/blockquote.d.ts.map +1 -0
- package/lib/node/bullet-list.d.ts +6 -0
- package/lib/node/bullet-list.d.ts.map +1 -0
- package/lib/node/code-block.d.ts +10 -0
- package/lib/node/code-block.d.ts.map +1 -0
- package/lib/node/doc.d.ts +2 -0
- package/lib/node/doc.d.ts.map +1 -0
- package/lib/node/hardbreak.d.ts +5 -0
- package/lib/node/hardbreak.d.ts.map +1 -0
- package/lib/node/heading.d.ts +11 -0
- package/lib/node/heading.d.ts.map +1 -0
- package/lib/node/hr.d.ts +5 -0
- package/lib/node/hr.d.ts.map +1 -0
- package/lib/node/html.d.ts +3 -0
- package/lib/node/html.d.ts.map +1 -0
- package/lib/node/image.d.ts +11 -0
- package/lib/node/image.d.ts.map +1 -0
- package/lib/node/index.d.ts +14 -0
- package/lib/node/index.d.ts.map +1 -0
- package/lib/node/list-item.d.ts +8 -0
- package/lib/node/list-item.d.ts.map +1 -0
- package/lib/node/ordered-list.d.ts +6 -0
- package/lib/node/ordered-list.d.ts.map +1 -0
- package/lib/node/paragraph.d.ts +5 -0
- package/lib/node/paragraph.d.ts.map +1 -0
- package/lib/node/text.d.ts +2 -0
- package/lib/node/text.d.ts.map +1 -0
- package/lib/plugin/hardbreak-clear-mark-plugin.d.ts +2 -0
- package/lib/plugin/hardbreak-clear-mark-plugin.d.ts.map +1 -0
- package/lib/plugin/hardbreak-filter-plugin.d.ts +3 -0
- package/lib/plugin/hardbreak-filter-plugin.d.ts.map +1 -0
- package/lib/plugin/index.d.ts +12 -0
- package/lib/plugin/index.d.ts.map +1 -0
- package/lib/plugin/inline-nodes-cursor-plugin.d.ts +2 -0
- package/lib/plugin/inline-nodes-cursor-plugin.d.ts.map +1 -0
- package/lib/plugin/remark-add-order-in-list-plugin.d.ts +2 -0
- package/lib/plugin/remark-add-order-in-list-plugin.d.ts.map +1 -0
- package/lib/plugin/remark-html-transformer.d.ts +2 -0
- package/lib/plugin/remark-html-transformer.d.ts.map +1 -0
- package/lib/plugin/remark-inline-link-plugin.d.ts +2 -0
- package/lib/plugin/remark-inline-link-plugin.d.ts.map +1 -0
- package/lib/plugin/remark-line-break.d.ts +2 -0
- package/lib/plugin/remark-line-break.d.ts.map +1 -0
- package/lib/plugin/remark-marker-plugin.d.ts +2 -0
- package/lib/plugin/remark-marker-plugin.d.ts.map +1 -0
- package/lib/plugin/remark-preserve-empty-line.d.ts +2 -0
- package/lib/plugin/remark-preserve-empty-line.d.ts.map +1 -0
- package/lib/plugin/sync-heading-id-plugin.d.ts +2 -0
- package/lib/plugin/sync-heading-id-plugin.d.ts.map +1 -0
- package/lib/plugin/sync-list-order-plugin.d.ts +2 -0
- package/lib/plugin/sync-list-order-plugin.d.ts.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +44 -0
- package/src/__internal__/index.ts +2 -0
- package/src/__internal__/serialize-text.ts +21 -0
- package/src/__internal__/with-meta.ts +15 -0
- package/src/__test__/html.spec.ts +46 -0
- package/src/__test__/trailing-space.spec.ts +27 -0
- package/src/__test__/vitest.setup.ts +65 -0
- package/src/commands/index.ts +140 -0
- package/src/composed/commands.ts +72 -0
- package/src/composed/index.ts +5 -0
- package/src/composed/inputrules.ts +34 -0
- package/src/composed/keymap.ts +29 -0
- package/src/composed/plugins.ts +35 -0
- package/src/composed/schema.ts +92 -0
- package/src/index.ts +26 -0
- package/src/mark/emphasis.ts +130 -0
- package/src/mark/index.ts +4 -0
- package/src/mark/inline-code.ts +123 -0
- package/src/mark/link.ts +134 -0
- package/src/mark/strong.ts +130 -0
- package/src/node/blockquote.ts +100 -0
- package/src/node/bullet-list.ts +129 -0
- package/src/node/code-block.ts +176 -0
- package/src/node/doc.ts +26 -0
- package/src/node/hardbreak.ts +134 -0
- package/src/node/heading.ts +271 -0
- package/src/node/hr.ts +87 -0
- package/src/node/html.ts +66 -0
- package/src/node/image.ts +173 -0
- package/src/node/index.ts +14 -0
- package/src/node/list-item.ts +244 -0
- package/src/node/ordered-list.ts +141 -0
- package/src/node/paragraph.ts +136 -0
- package/src/node/text.ts +25 -0
- package/src/plugin/hardbreak-clear-mark-plugin.ts +58 -0
- package/src/plugin/hardbreak-filter-plugin.ts +46 -0
- package/src/plugin/index.ts +14 -0
- package/src/plugin/inline-nodes-cursor-plugin.ts +103 -0
- package/src/plugin/remark-add-order-in-list-plugin.ts +29 -0
- package/src/plugin/remark-html-transformer.ts +74 -0
- package/src/plugin/remark-inline-link-plugin.ts +20 -0
- package/src/plugin/remark-line-break.ts +69 -0
- package/src/plugin/remark-marker-plugin.ts +33 -0
- package/src/plugin/remark-preserve-empty-line.ts +49 -0
- package/src/plugin/sync-heading-id-plugin.ts +67 -0
- package/src/plugin/sync-list-order-plugin.ts +112 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,2153 @@
|
|
|
1
|
+
import { commandsCtx, editorViewCtx, remarkStringifyOptionsCtx } from "@jvs-milkdown/core";
|
|
2
|
+
import { findNodeInSelection, findSelectedNodeOfType, markRule } from "@jvs-milkdown/prose";
|
|
3
|
+
import { joinBackward, setBlockType, toggleMark, wrapIn } from "@jvs-milkdown/prose/commands";
|
|
4
|
+
import { $command, $ctx, $inputRule, $markAttr, $markSchema, $node, $nodeAttr, $nodeSchema, $prose, $remark, $useKeymap } from "@jvs-milkdown/utils";
|
|
5
|
+
import { Fragment, Node } from "@jvs-milkdown/prose/model";
|
|
6
|
+
import { expectDomTypeError } from "@jvs-milkdown/exception";
|
|
7
|
+
import { Plugin, PluginKey, Selection, TextSelection } from "@jvs-milkdown/prose/state";
|
|
8
|
+
import { InputRule, textblockTypeInputRule, wrappingInputRule } from "@jvs-milkdown/prose/inputrules";
|
|
9
|
+
import { visitParents } from "unist-util-visit-parents";
|
|
10
|
+
import { liftListItem, sinkListItem, splitListItem } from "@jvs-milkdown/prose/schema-list";
|
|
11
|
+
import { AddMarkStep, ReplaceStep, findWrapping } from "@jvs-milkdown/prose/transform";
|
|
12
|
+
import { visit } from "unist-util-visit";
|
|
13
|
+
import remarkInlineLinks from "remark-inline-links";
|
|
14
|
+
import { Decoration, DecorationSet } from "@jvs-milkdown/prose/view";
|
|
15
|
+
//#region src/__internal__/serialize-text.ts
|
|
16
|
+
function serializeText(state, node) {
|
|
17
|
+
if (!(node.childCount >= 1 && node.lastChild?.type.name === "hardbreak")) {
|
|
18
|
+
state.next(node.content);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const contentArr = [];
|
|
22
|
+
node.content.forEach((n, _, i) => {
|
|
23
|
+
if (i === node.childCount - 1) return;
|
|
24
|
+
contentArr.push(n);
|
|
25
|
+
});
|
|
26
|
+
state.next(Fragment.fromArray(contentArr));
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/__internal__/with-meta.ts
|
|
30
|
+
function withMeta(plugin, meta) {
|
|
31
|
+
Object.assign(plugin, { meta: {
|
|
32
|
+
package: "@jvs-milkdown/preset-commonmark",
|
|
33
|
+
...meta
|
|
34
|
+
} });
|
|
35
|
+
return plugin;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/mark/emphasis.ts
|
|
39
|
+
var emphasisAttr = $markAttr("emphasis");
|
|
40
|
+
withMeta(emphasisAttr, {
|
|
41
|
+
displayName: "Attr<emphasis>",
|
|
42
|
+
group: "Emphasis"
|
|
43
|
+
});
|
|
44
|
+
var emphasisSchema = $markSchema("emphasis", (ctx) => ({
|
|
45
|
+
attrs: { marker: {
|
|
46
|
+
default: ctx.get(remarkStringifyOptionsCtx).emphasis || "*",
|
|
47
|
+
validate: "string"
|
|
48
|
+
} },
|
|
49
|
+
parseDOM: [
|
|
50
|
+
{ tag: "i" },
|
|
51
|
+
{ tag: "em" },
|
|
52
|
+
{
|
|
53
|
+
style: "font-style",
|
|
54
|
+
getAttrs: (value) => value === "italic"
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
toDOM: (mark) => ["em", ctx.get(emphasisAttr.key)(mark)],
|
|
58
|
+
parseMarkdown: {
|
|
59
|
+
match: (node) => node.type === "emphasis",
|
|
60
|
+
runner: (state, node, markType) => {
|
|
61
|
+
state.openMark(markType, { marker: node.marker });
|
|
62
|
+
state.next(node.children);
|
|
63
|
+
state.closeMark(markType);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
toMarkdown: {
|
|
67
|
+
match: (mark) => mark.type.name === "emphasis",
|
|
68
|
+
runner: (state, mark) => {
|
|
69
|
+
state.withMark(mark, "emphasis", void 0, { marker: mark.attrs.marker });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}));
|
|
73
|
+
withMeta(emphasisSchema.mark, {
|
|
74
|
+
displayName: "MarkSchema<emphasis>",
|
|
75
|
+
group: "Emphasis"
|
|
76
|
+
});
|
|
77
|
+
withMeta(emphasisSchema.ctx, {
|
|
78
|
+
displayName: "MarkSchemaCtx<emphasis>",
|
|
79
|
+
group: "Emphasis"
|
|
80
|
+
});
|
|
81
|
+
var toggleEmphasisCommand = $command("ToggleEmphasis", (ctx) => () => {
|
|
82
|
+
return toggleMark(emphasisSchema.type(ctx));
|
|
83
|
+
});
|
|
84
|
+
withMeta(toggleEmphasisCommand, {
|
|
85
|
+
displayName: "Command<toggleEmphasisCommand>",
|
|
86
|
+
group: "Emphasis"
|
|
87
|
+
});
|
|
88
|
+
var emphasisStarInputRule = $inputRule((ctx) => {
|
|
89
|
+
return markRule(/(?:^|[^*])\*([^*]+)\*$/, emphasisSchema.type(ctx), {
|
|
90
|
+
getAttr: () => ({ marker: "*" }),
|
|
91
|
+
updateCaptured: ({ fullMatch, start }) => !fullMatch.startsWith("*") ? {
|
|
92
|
+
fullMatch: fullMatch.slice(1),
|
|
93
|
+
start: start + 1
|
|
94
|
+
} : {}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
withMeta(emphasisStarInputRule, {
|
|
98
|
+
displayName: "InputRule<emphasis>|Star",
|
|
99
|
+
group: "Emphasis"
|
|
100
|
+
});
|
|
101
|
+
var emphasisUnderscoreInputRule = $inputRule((ctx) => {
|
|
102
|
+
return markRule(/\b_(?![_\s])(.*?[^_\s])_\b/, emphasisSchema.type(ctx), {
|
|
103
|
+
getAttr: () => ({ marker: "_" }),
|
|
104
|
+
updateCaptured: ({ fullMatch, start }) => !fullMatch.startsWith("_") ? {
|
|
105
|
+
fullMatch: fullMatch.slice(1),
|
|
106
|
+
start: start + 1
|
|
107
|
+
} : {}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
withMeta(emphasisUnderscoreInputRule, {
|
|
111
|
+
displayName: "InputRule<emphasis>|Underscore",
|
|
112
|
+
group: "Emphasis"
|
|
113
|
+
});
|
|
114
|
+
var emphasisKeymap = $useKeymap("emphasisKeymap", { ToggleEmphasis: {
|
|
115
|
+
shortcuts: "Mod-i",
|
|
116
|
+
command: (ctx) => {
|
|
117
|
+
const commands = ctx.get(commandsCtx);
|
|
118
|
+
return () => commands.call(toggleEmphasisCommand.key);
|
|
119
|
+
}
|
|
120
|
+
} });
|
|
121
|
+
withMeta(emphasisKeymap.ctx, {
|
|
122
|
+
displayName: "KeymapCtx<emphasis>",
|
|
123
|
+
group: "Emphasis"
|
|
124
|
+
});
|
|
125
|
+
withMeta(emphasisKeymap.shortcuts, {
|
|
126
|
+
displayName: "Keymap<emphasis>",
|
|
127
|
+
group: "Emphasis"
|
|
128
|
+
});
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/mark/strong.ts
|
|
131
|
+
var strongAttr = $markAttr("strong");
|
|
132
|
+
withMeta(strongAttr, {
|
|
133
|
+
displayName: "Attr<strong>",
|
|
134
|
+
group: "Strong"
|
|
135
|
+
});
|
|
136
|
+
var strongSchema = $markSchema("strong", (ctx) => ({
|
|
137
|
+
attrs: { marker: {
|
|
138
|
+
default: ctx.get(remarkStringifyOptionsCtx).strong || "*",
|
|
139
|
+
validate: "string"
|
|
140
|
+
} },
|
|
141
|
+
parseDOM: [
|
|
142
|
+
{
|
|
143
|
+
tag: "b",
|
|
144
|
+
getAttrs: (node) => node.style.fontWeight != "normal" && null
|
|
145
|
+
},
|
|
146
|
+
{ tag: "strong" },
|
|
147
|
+
{
|
|
148
|
+
style: "font-style",
|
|
149
|
+
getAttrs: (value) => value === "bold"
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
style: "font-weight=400",
|
|
153
|
+
clearMark: (m) => m.type.name == "strong"
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
style: "font-weight",
|
|
157
|
+
getAttrs: (value) => /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null
|
|
158
|
+
}
|
|
159
|
+
],
|
|
160
|
+
toDOM: (mark) => ["strong", ctx.get(strongAttr.key)(mark)],
|
|
161
|
+
parseMarkdown: {
|
|
162
|
+
match: (node) => node.type === "strong",
|
|
163
|
+
runner: (state, node, markType) => {
|
|
164
|
+
state.openMark(markType, { marker: node.marker });
|
|
165
|
+
state.next(node.children);
|
|
166
|
+
state.closeMark(markType);
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
toMarkdown: {
|
|
170
|
+
match: (mark) => mark.type.name === "strong",
|
|
171
|
+
runner: (state, mark) => {
|
|
172
|
+
state.withMark(mark, "strong", void 0, { marker: mark.attrs.marker });
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}));
|
|
176
|
+
withMeta(strongSchema.mark, {
|
|
177
|
+
displayName: "MarkSchema<strong>",
|
|
178
|
+
group: "Strong"
|
|
179
|
+
});
|
|
180
|
+
withMeta(strongSchema.ctx, {
|
|
181
|
+
displayName: "MarkSchemaCtx<strong>",
|
|
182
|
+
group: "Strong"
|
|
183
|
+
});
|
|
184
|
+
var toggleStrongCommand = $command("ToggleStrong", (ctx) => () => {
|
|
185
|
+
return toggleMark(strongSchema.type(ctx));
|
|
186
|
+
});
|
|
187
|
+
withMeta(toggleStrongCommand, {
|
|
188
|
+
displayName: "Command<toggleStrongCommand>",
|
|
189
|
+
group: "Strong"
|
|
190
|
+
});
|
|
191
|
+
var strongInputRule = $inputRule((ctx) => {
|
|
192
|
+
return markRule(/(?<![\w:/])(?:\*\*|__)([^*_]+?)(?:\*\*|__)(?![\w/])$/, strongSchema.type(ctx), { getAttr: (match) => {
|
|
193
|
+
return { marker: match[0].startsWith("*") ? "*" : "_" };
|
|
194
|
+
} });
|
|
195
|
+
});
|
|
196
|
+
withMeta(strongInputRule, {
|
|
197
|
+
displayName: "InputRule<strong>",
|
|
198
|
+
group: "Strong"
|
|
199
|
+
});
|
|
200
|
+
var strongKeymap = $useKeymap("strongKeymap", { ToggleBold: {
|
|
201
|
+
shortcuts: ["Mod-b"],
|
|
202
|
+
command: (ctx) => {
|
|
203
|
+
const commands = ctx.get(commandsCtx);
|
|
204
|
+
return () => commands.call(toggleStrongCommand.key);
|
|
205
|
+
}
|
|
206
|
+
} });
|
|
207
|
+
withMeta(strongKeymap.ctx, {
|
|
208
|
+
displayName: "KeymapCtx<strong>",
|
|
209
|
+
group: "Strong"
|
|
210
|
+
});
|
|
211
|
+
withMeta(strongKeymap.shortcuts, {
|
|
212
|
+
displayName: "Keymap<strong>",
|
|
213
|
+
group: "Strong"
|
|
214
|
+
});
|
|
215
|
+
//#endregion
|
|
216
|
+
//#region src/mark/inline-code.ts
|
|
217
|
+
var inlineCodeAttr = $markAttr("inlineCode");
|
|
218
|
+
withMeta(inlineCodeAttr, {
|
|
219
|
+
displayName: "Attr<inlineCode>",
|
|
220
|
+
group: "InlineCode"
|
|
221
|
+
});
|
|
222
|
+
var inlineCodeSchema = $markSchema("inlineCode", (ctx) => ({
|
|
223
|
+
priority: 100,
|
|
224
|
+
code: true,
|
|
225
|
+
parseDOM: [{ tag: "code" }],
|
|
226
|
+
toDOM: (mark) => ["code", ctx.get(inlineCodeAttr.key)(mark)],
|
|
227
|
+
parseMarkdown: {
|
|
228
|
+
match: (node) => node.type === "inlineCode",
|
|
229
|
+
runner: (state, node, markType) => {
|
|
230
|
+
state.openMark(markType);
|
|
231
|
+
state.addText(node.value);
|
|
232
|
+
state.closeMark(markType);
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
toMarkdown: {
|
|
236
|
+
match: (mark) => mark.type.name === "inlineCode",
|
|
237
|
+
runner: (state, mark, node) => {
|
|
238
|
+
state.withMark(mark, "inlineCode", node.text || "");
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}));
|
|
243
|
+
withMeta(inlineCodeSchema.mark, {
|
|
244
|
+
displayName: "MarkSchema<inlineCode>",
|
|
245
|
+
group: "InlineCode"
|
|
246
|
+
});
|
|
247
|
+
withMeta(inlineCodeSchema.ctx, {
|
|
248
|
+
displayName: "MarkSchemaCtx<inlineCode>",
|
|
249
|
+
group: "InlineCode"
|
|
250
|
+
});
|
|
251
|
+
var toggleInlineCodeCommand = $command("ToggleInlineCode", (ctx) => () => (state, dispatch) => {
|
|
252
|
+
const { selection, tr } = state;
|
|
253
|
+
if (selection.empty) return false;
|
|
254
|
+
const { from, to } = selection;
|
|
255
|
+
if (state.doc.rangeHasMark(from, to, inlineCodeSchema.type(ctx))) {
|
|
256
|
+
dispatch?.(tr.removeMark(from, to, inlineCodeSchema.type(ctx)));
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
Object.keys(state.schema.marks).filter((x) => x !== inlineCodeSchema.type.name).map((name) => state.schema.marks[name]).forEach((t) => {
|
|
260
|
+
tr.removeMark(from, to, t);
|
|
261
|
+
});
|
|
262
|
+
dispatch?.(tr.addMark(from, to, inlineCodeSchema.type(ctx).create()));
|
|
263
|
+
return true;
|
|
264
|
+
});
|
|
265
|
+
withMeta(toggleInlineCodeCommand, {
|
|
266
|
+
displayName: "Command<toggleInlineCodeCommand>",
|
|
267
|
+
group: "InlineCode"
|
|
268
|
+
});
|
|
269
|
+
var inlineCodeInputRule = $inputRule((ctx) => {
|
|
270
|
+
return markRule(/(?:`)([^`]+)(?:`)$/, inlineCodeSchema.type(ctx));
|
|
271
|
+
});
|
|
272
|
+
withMeta(inlineCodeInputRule, {
|
|
273
|
+
displayName: "InputRule<inlineCodeInputRule>",
|
|
274
|
+
group: "InlineCode"
|
|
275
|
+
});
|
|
276
|
+
var inlineCodeKeymap = $useKeymap("inlineCodeKeymap", { ToggleInlineCode: {
|
|
277
|
+
shortcuts: "Mod-e",
|
|
278
|
+
command: (ctx) => {
|
|
279
|
+
const commands = ctx.get(commandsCtx);
|
|
280
|
+
return () => commands.call(toggleInlineCodeCommand.key);
|
|
281
|
+
}
|
|
282
|
+
} });
|
|
283
|
+
withMeta(inlineCodeKeymap.ctx, {
|
|
284
|
+
displayName: "KeymapCtx<inlineCode>",
|
|
285
|
+
group: "InlineCode"
|
|
286
|
+
});
|
|
287
|
+
withMeta(inlineCodeKeymap.shortcuts, {
|
|
288
|
+
displayName: "Keymap<inlineCode>",
|
|
289
|
+
group: "InlineCode"
|
|
290
|
+
});
|
|
291
|
+
//#endregion
|
|
292
|
+
//#region src/mark/link.ts
|
|
293
|
+
var linkAttr = $markAttr("link");
|
|
294
|
+
withMeta(linkAttr, {
|
|
295
|
+
displayName: "Attr<link>",
|
|
296
|
+
group: "Link"
|
|
297
|
+
});
|
|
298
|
+
var linkSchema = $markSchema("link", (ctx) => ({
|
|
299
|
+
attrs: {
|
|
300
|
+
href: { validate: "string" },
|
|
301
|
+
title: {
|
|
302
|
+
default: null,
|
|
303
|
+
validate: "string|null"
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
parseDOM: [{
|
|
307
|
+
tag: "a[href]",
|
|
308
|
+
getAttrs: (dom) => {
|
|
309
|
+
if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
|
|
310
|
+
return {
|
|
311
|
+
href: dom.getAttribute("href"),
|
|
312
|
+
title: dom.getAttribute("title")
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
}],
|
|
316
|
+
toDOM: (mark) => ["a", {
|
|
317
|
+
...ctx.get(linkAttr.key)(mark),
|
|
318
|
+
...mark.attrs
|
|
319
|
+
}],
|
|
320
|
+
parseMarkdown: {
|
|
321
|
+
match: (node) => node.type === "link",
|
|
322
|
+
runner: (state, node, markType) => {
|
|
323
|
+
const url = node.url;
|
|
324
|
+
const title = node.title;
|
|
325
|
+
state.openMark(markType, {
|
|
326
|
+
href: url,
|
|
327
|
+
title
|
|
328
|
+
});
|
|
329
|
+
state.next(node.children);
|
|
330
|
+
state.closeMark(markType);
|
|
331
|
+
}
|
|
332
|
+
},
|
|
333
|
+
toMarkdown: {
|
|
334
|
+
match: (mark) => mark.type.name === "link",
|
|
335
|
+
runner: (state, mark) => {
|
|
336
|
+
state.withMark(mark, "link", void 0, {
|
|
337
|
+
title: mark.attrs.title,
|
|
338
|
+
url: mark.attrs.href
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}));
|
|
343
|
+
withMeta(linkSchema.mark, {
|
|
344
|
+
displayName: "MarkSchema<link>",
|
|
345
|
+
group: "Link"
|
|
346
|
+
});
|
|
347
|
+
var toggleLinkCommand = $command("ToggleLink", (ctx) => (payload = {}) => toggleMark(linkSchema.type(ctx), payload));
|
|
348
|
+
withMeta(toggleLinkCommand, {
|
|
349
|
+
displayName: "Command<toggleLinkCommand>",
|
|
350
|
+
group: "Link"
|
|
351
|
+
});
|
|
352
|
+
var updateLinkCommand = $command("UpdateLink", (ctx) => (payload = {}) => (state, dispatch) => {
|
|
353
|
+
if (!dispatch) return false;
|
|
354
|
+
let node;
|
|
355
|
+
let pos = -1;
|
|
356
|
+
const { selection } = state;
|
|
357
|
+
const { from, to } = selection;
|
|
358
|
+
state.doc.nodesBetween(from, from === to ? to + 1 : to, (n, p) => {
|
|
359
|
+
if (linkSchema.type(ctx).isInSet(n.marks)) {
|
|
360
|
+
node = n;
|
|
361
|
+
pos = p;
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
if (!node) return false;
|
|
366
|
+
const mark = node.marks.find(({ type }) => type === linkSchema.type(ctx));
|
|
367
|
+
if (!mark) return false;
|
|
368
|
+
const start = pos;
|
|
369
|
+
const end = pos + node.nodeSize;
|
|
370
|
+
const { tr } = state;
|
|
371
|
+
const linkMark = linkSchema.type(ctx).create({
|
|
372
|
+
...mark.attrs,
|
|
373
|
+
...payload
|
|
374
|
+
});
|
|
375
|
+
if (!linkMark) return false;
|
|
376
|
+
dispatch(tr.removeMark(start, end, mark).addMark(start, end, linkMark).setSelection(new TextSelection(tr.selection.$anchor)).scrollIntoView());
|
|
377
|
+
return true;
|
|
378
|
+
});
|
|
379
|
+
withMeta(updateLinkCommand, {
|
|
380
|
+
displayName: "Command<updateLinkCommand>",
|
|
381
|
+
group: "Link"
|
|
382
|
+
});
|
|
383
|
+
//#endregion
|
|
384
|
+
//#region src/node/doc.ts
|
|
385
|
+
var docSchema = $node("doc", () => ({
|
|
386
|
+
content: "block+",
|
|
387
|
+
parseMarkdown: {
|
|
388
|
+
match: ({ type }) => type === "root",
|
|
389
|
+
runner: (state, node, type) => {
|
|
390
|
+
state.injectRoot(node, type);
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
toMarkdown: {
|
|
394
|
+
match: (node) => node.type.name === "doc",
|
|
395
|
+
runner: (state, node) => {
|
|
396
|
+
state.openNode("root");
|
|
397
|
+
state.next(node.content);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}));
|
|
401
|
+
withMeta(docSchema, {
|
|
402
|
+
displayName: "NodeSchema<doc>",
|
|
403
|
+
group: "Doc"
|
|
404
|
+
});
|
|
405
|
+
//#endregion
|
|
406
|
+
//#region src/plugin/remark-preserve-empty-line.ts
|
|
407
|
+
function visitEmptyLine(ast) {
|
|
408
|
+
return visitParents(ast, (node) => node.type === "html" && [
|
|
409
|
+
"<br />",
|
|
410
|
+
"<br>",
|
|
411
|
+
"<br >",
|
|
412
|
+
"<br/>"
|
|
413
|
+
].includes(node.value?.trim()), (node, parents) => {
|
|
414
|
+
if (!parents.length) return;
|
|
415
|
+
const parent = parents[parents.length - 1];
|
|
416
|
+
if (!parent) return;
|
|
417
|
+
const index = parent.children.indexOf(node);
|
|
418
|
+
if (index === -1) return;
|
|
419
|
+
parent.children.splice(index, 1);
|
|
420
|
+
}, true);
|
|
421
|
+
}
|
|
422
|
+
var remarkPreserveEmptyLinePlugin = $remark("remark-preserve-empty-line", () => () => visitEmptyLine);
|
|
423
|
+
withMeta(remarkPreserveEmptyLinePlugin.plugin, {
|
|
424
|
+
displayName: "Remark<remarkPreserveEmptyLine>",
|
|
425
|
+
group: "Remark"
|
|
426
|
+
});
|
|
427
|
+
withMeta(remarkPreserveEmptyLinePlugin.options, {
|
|
428
|
+
displayName: "RemarkConfig<remarkPreserveEmptyLine>",
|
|
429
|
+
group: "Remark"
|
|
430
|
+
});
|
|
431
|
+
//#endregion
|
|
432
|
+
//#region src/node/paragraph.ts
|
|
433
|
+
var paragraphAttr = $nodeAttr("paragraph");
|
|
434
|
+
withMeta(paragraphAttr, {
|
|
435
|
+
displayName: "Attr<paragraph>",
|
|
436
|
+
group: "Paragraph"
|
|
437
|
+
});
|
|
438
|
+
var paragraphSchema = $nodeSchema("paragraph", (ctx) => ({
|
|
439
|
+
content: "inline*",
|
|
440
|
+
group: "block",
|
|
441
|
+
attrs: {
|
|
442
|
+
align: { default: null },
|
|
443
|
+
indent: { default: 0 }
|
|
444
|
+
},
|
|
445
|
+
parseDOM: [{
|
|
446
|
+
tag: "p",
|
|
447
|
+
getAttrs: (dom) => {
|
|
448
|
+
if (!(dom instanceof HTMLElement)) return null;
|
|
449
|
+
return {
|
|
450
|
+
align: dom.style.textAlign || dom.getAttribute("data-align") || null,
|
|
451
|
+
indent: parseInt(dom.getAttribute("data-indent") || "0", 10) || 0
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
}],
|
|
455
|
+
toDOM: (node) => {
|
|
456
|
+
const { align, indent } = node.attrs;
|
|
457
|
+
const attrs = { ...ctx.get(paragraphAttr.key)(node) };
|
|
458
|
+
if (align) {
|
|
459
|
+
attrs.style = (attrs.style || "") + `text-align: ${align};`;
|
|
460
|
+
attrs["data-align"] = align;
|
|
461
|
+
}
|
|
462
|
+
if (indent) {
|
|
463
|
+
attrs.style = (attrs.style || "") + `margin-left: ${indent * 2}em;`;
|
|
464
|
+
attrs["data-indent"] = indent.toString();
|
|
465
|
+
}
|
|
466
|
+
return [
|
|
467
|
+
"p",
|
|
468
|
+
attrs,
|
|
469
|
+
0
|
|
470
|
+
];
|
|
471
|
+
},
|
|
472
|
+
parseMarkdown: {
|
|
473
|
+
match: (node) => node.type === "paragraph",
|
|
474
|
+
runner: (state, node, type) => {
|
|
475
|
+
state.openNode(type);
|
|
476
|
+
if (node.children) state.next(node.children);
|
|
477
|
+
else state.addText(node.value || "");
|
|
478
|
+
state.closeNode();
|
|
479
|
+
}
|
|
480
|
+
},
|
|
481
|
+
toMarkdown: {
|
|
482
|
+
match: (node) => node.type.name === "paragraph",
|
|
483
|
+
runner: (state, node) => {
|
|
484
|
+
const lastNode = ctx.get(editorViewCtx).state?.doc.lastChild;
|
|
485
|
+
state.openNode("paragraph");
|
|
486
|
+
if ((!node.content || node.content.size === 0) && node !== lastNode && shouldPreserveEmptyLine(ctx)) state.addNode("html", void 0, "<br />");
|
|
487
|
+
else serializeText(state, node);
|
|
488
|
+
state.closeNode();
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}));
|
|
492
|
+
function shouldPreserveEmptyLine(ctx) {
|
|
493
|
+
let shouldPreserveEmptyLine = false;
|
|
494
|
+
try {
|
|
495
|
+
ctx.get(remarkPreserveEmptyLinePlugin.id);
|
|
496
|
+
shouldPreserveEmptyLine = true;
|
|
497
|
+
} catch {
|
|
498
|
+
shouldPreserveEmptyLine = false;
|
|
499
|
+
}
|
|
500
|
+
return shouldPreserveEmptyLine;
|
|
501
|
+
}
|
|
502
|
+
withMeta(paragraphSchema.node, {
|
|
503
|
+
displayName: "NodeSchema<paragraph>",
|
|
504
|
+
group: "Paragraph"
|
|
505
|
+
});
|
|
506
|
+
withMeta(paragraphSchema.ctx, {
|
|
507
|
+
displayName: "NodeSchemaCtx<paragraph>",
|
|
508
|
+
group: "Paragraph"
|
|
509
|
+
});
|
|
510
|
+
var turnIntoTextCommand = $command("TurnIntoText", (ctx) => () => setBlockType(paragraphSchema.type(ctx)));
|
|
511
|
+
withMeta(turnIntoTextCommand, {
|
|
512
|
+
displayName: "Command<turnIntoTextCommand>",
|
|
513
|
+
group: "Paragraph"
|
|
514
|
+
});
|
|
515
|
+
var paragraphKeymap = $useKeymap("paragraphKeymap", { TurnIntoText: {
|
|
516
|
+
shortcuts: "Mod-Alt-0",
|
|
517
|
+
command: (ctx) => {
|
|
518
|
+
const commands = ctx.get(commandsCtx);
|
|
519
|
+
return () => commands.call(turnIntoTextCommand.key);
|
|
520
|
+
}
|
|
521
|
+
} });
|
|
522
|
+
withMeta(paragraphKeymap.ctx, {
|
|
523
|
+
displayName: "KeymapCtx<paragraph>",
|
|
524
|
+
group: "Paragraph"
|
|
525
|
+
});
|
|
526
|
+
withMeta(paragraphKeymap.shortcuts, {
|
|
527
|
+
displayName: "Keymap<paragraph>",
|
|
528
|
+
group: "Paragraph"
|
|
529
|
+
});
|
|
530
|
+
//#endregion
|
|
531
|
+
//#region src/node/heading.ts
|
|
532
|
+
var headingIndex = Array(6).fill(0).map((_, i) => i + 1);
|
|
533
|
+
function defaultHeadingIdGenerator(node) {
|
|
534
|
+
return node.textContent.toLowerCase().trim().replace(/\s+/g, "-");
|
|
535
|
+
}
|
|
536
|
+
var headingIdGenerator = $ctx(defaultHeadingIdGenerator, "headingIdGenerator");
|
|
537
|
+
withMeta(headingIdGenerator, {
|
|
538
|
+
displayName: "Ctx<HeadingIdGenerator>",
|
|
539
|
+
group: "Heading"
|
|
540
|
+
});
|
|
541
|
+
var headingAttr = $nodeAttr("heading");
|
|
542
|
+
withMeta(headingAttr, {
|
|
543
|
+
displayName: "Attr<heading>",
|
|
544
|
+
group: "Heading"
|
|
545
|
+
});
|
|
546
|
+
var headingSchema = $nodeSchema("heading", (ctx) => {
|
|
547
|
+
const getId = ctx.get(headingIdGenerator.key);
|
|
548
|
+
return {
|
|
549
|
+
content: "inline*",
|
|
550
|
+
group: "block",
|
|
551
|
+
defining: true,
|
|
552
|
+
attrs: {
|
|
553
|
+
id: {
|
|
554
|
+
default: "",
|
|
555
|
+
validate: "string"
|
|
556
|
+
},
|
|
557
|
+
level: {
|
|
558
|
+
default: 1,
|
|
559
|
+
validate: "number"
|
|
560
|
+
},
|
|
561
|
+
align: { default: null },
|
|
562
|
+
indent: { default: 0 }
|
|
563
|
+
},
|
|
564
|
+
parseDOM: headingIndex.map((x) => ({
|
|
565
|
+
tag: `h${x}`,
|
|
566
|
+
getAttrs: (node) => {
|
|
567
|
+
if (!(node instanceof HTMLElement)) throw expectDomTypeError(node);
|
|
568
|
+
return {
|
|
569
|
+
level: x,
|
|
570
|
+
id: node.id,
|
|
571
|
+
align: node.style.textAlign || node.getAttribute("data-align") || null,
|
|
572
|
+
indent: parseInt(node.getAttribute("data-indent") || "0", 10) || 0
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
})),
|
|
576
|
+
toDOM: (node) => {
|
|
577
|
+
const { align, indent } = node.attrs;
|
|
578
|
+
const attrs = {
|
|
579
|
+
...ctx.get(headingAttr.key)(node),
|
|
580
|
+
id: node.attrs.id || getId(node)
|
|
581
|
+
};
|
|
582
|
+
if (align) {
|
|
583
|
+
attrs.style = (attrs.style || "") + `text-align: ${align};`;
|
|
584
|
+
attrs["data-align"] = align;
|
|
585
|
+
}
|
|
586
|
+
if (indent) {
|
|
587
|
+
attrs.style = (attrs.style || "") + `margin-left: ${indent * 2}em;`;
|
|
588
|
+
attrs["data-indent"] = indent.toString();
|
|
589
|
+
}
|
|
590
|
+
return [
|
|
591
|
+
`h${node.attrs.level}`,
|
|
592
|
+
attrs,
|
|
593
|
+
0
|
|
594
|
+
];
|
|
595
|
+
},
|
|
596
|
+
parseMarkdown: {
|
|
597
|
+
match: ({ type }) => type === "heading",
|
|
598
|
+
runner: (state, node, type) => {
|
|
599
|
+
const depth = node.depth;
|
|
600
|
+
state.openNode(type, { level: depth });
|
|
601
|
+
state.next(node.children);
|
|
602
|
+
state.closeNode();
|
|
603
|
+
}
|
|
604
|
+
},
|
|
605
|
+
toMarkdown: {
|
|
606
|
+
match: (node) => node.type.name === "heading",
|
|
607
|
+
runner: (state, node) => {
|
|
608
|
+
state.openNode("heading", void 0, { depth: node.attrs.level });
|
|
609
|
+
serializeText(state, node);
|
|
610
|
+
state.closeNode();
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
});
|
|
615
|
+
withMeta(headingSchema.node, {
|
|
616
|
+
displayName: "NodeSchema<heading>",
|
|
617
|
+
group: "Heading"
|
|
618
|
+
});
|
|
619
|
+
withMeta(headingSchema.ctx, {
|
|
620
|
+
displayName: "NodeSchemaCtx<heading>",
|
|
621
|
+
group: "Heading"
|
|
622
|
+
});
|
|
623
|
+
var wrapInHeadingInputRule = $inputRule((ctx) => {
|
|
624
|
+
return textblockTypeInputRule(/^(?<hashes>#+)\s$/, headingSchema.type(ctx), (match) => {
|
|
625
|
+
const x = match.groups?.hashes?.length || 0;
|
|
626
|
+
const { $from } = ctx.get(editorViewCtx).state.selection;
|
|
627
|
+
const node = $from.node();
|
|
628
|
+
if (node.type.name === "heading") {
|
|
629
|
+
let level = Number(node.attrs.level) + Number(x);
|
|
630
|
+
if (level > 6) level = 6;
|
|
631
|
+
return { level };
|
|
632
|
+
}
|
|
633
|
+
return { level: x };
|
|
634
|
+
});
|
|
635
|
+
});
|
|
636
|
+
withMeta(wrapInHeadingInputRule, {
|
|
637
|
+
displayName: "InputRule<wrapInHeadingInputRule>",
|
|
638
|
+
group: "Heading"
|
|
639
|
+
});
|
|
640
|
+
var wrapInHeadingCommand = $command("WrapInHeading", (ctx) => {
|
|
641
|
+
return (level) => {
|
|
642
|
+
level ??= 1;
|
|
643
|
+
if (level < 1) return setBlockType(paragraphSchema.type(ctx));
|
|
644
|
+
return setBlockType(headingSchema.type(ctx), { level });
|
|
645
|
+
};
|
|
646
|
+
});
|
|
647
|
+
withMeta(wrapInHeadingCommand, {
|
|
648
|
+
displayName: "Command<wrapInHeadingCommand>",
|
|
649
|
+
group: "Heading"
|
|
650
|
+
});
|
|
651
|
+
var downgradeHeadingCommand = $command("DowngradeHeading", (ctx) => () => (state, dispatch, view) => {
|
|
652
|
+
const { $from } = state.selection;
|
|
653
|
+
const node = $from.node();
|
|
654
|
+
if (node.type !== headingSchema.type(ctx) || !state.selection.empty || $from.parentOffset !== 0) return false;
|
|
655
|
+
const level = node.attrs.level - 1;
|
|
656
|
+
if (!level) return setBlockType(paragraphSchema.type(ctx))(state, dispatch, view);
|
|
657
|
+
dispatch?.(state.tr.setNodeMarkup(state.selection.$from.before(), void 0, {
|
|
658
|
+
...node.attrs,
|
|
659
|
+
level
|
|
660
|
+
}));
|
|
661
|
+
return true;
|
|
662
|
+
});
|
|
663
|
+
withMeta(downgradeHeadingCommand, {
|
|
664
|
+
displayName: "Command<downgradeHeadingCommand>",
|
|
665
|
+
group: "Heading"
|
|
666
|
+
});
|
|
667
|
+
var headingKeymap = $useKeymap("headingKeymap", {
|
|
668
|
+
TurnIntoH1: {
|
|
669
|
+
shortcuts: "Mod-Alt-1",
|
|
670
|
+
command: (ctx) => {
|
|
671
|
+
const commands = ctx.get(commandsCtx);
|
|
672
|
+
return () => commands.call(wrapInHeadingCommand.key, 1);
|
|
673
|
+
}
|
|
674
|
+
},
|
|
675
|
+
TurnIntoH2: {
|
|
676
|
+
shortcuts: "Mod-Alt-2",
|
|
677
|
+
command: (ctx) => {
|
|
678
|
+
const commands = ctx.get(commandsCtx);
|
|
679
|
+
return () => commands.call(wrapInHeadingCommand.key, 2);
|
|
680
|
+
}
|
|
681
|
+
},
|
|
682
|
+
TurnIntoH3: {
|
|
683
|
+
shortcuts: "Mod-Alt-3",
|
|
684
|
+
command: (ctx) => {
|
|
685
|
+
const commands = ctx.get(commandsCtx);
|
|
686
|
+
return () => commands.call(wrapInHeadingCommand.key, 3);
|
|
687
|
+
}
|
|
688
|
+
},
|
|
689
|
+
TurnIntoH4: {
|
|
690
|
+
shortcuts: "Mod-Alt-4",
|
|
691
|
+
command: (ctx) => {
|
|
692
|
+
const commands = ctx.get(commandsCtx);
|
|
693
|
+
return () => commands.call(wrapInHeadingCommand.key, 4);
|
|
694
|
+
}
|
|
695
|
+
},
|
|
696
|
+
TurnIntoH5: {
|
|
697
|
+
shortcuts: "Mod-Alt-5",
|
|
698
|
+
command: (ctx) => {
|
|
699
|
+
const commands = ctx.get(commandsCtx);
|
|
700
|
+
return () => commands.call(wrapInHeadingCommand.key, 5);
|
|
701
|
+
}
|
|
702
|
+
},
|
|
703
|
+
TurnIntoH6: {
|
|
704
|
+
shortcuts: "Mod-Alt-6",
|
|
705
|
+
command: (ctx) => {
|
|
706
|
+
const commands = ctx.get(commandsCtx);
|
|
707
|
+
return () => commands.call(wrapInHeadingCommand.key, 6);
|
|
708
|
+
}
|
|
709
|
+
},
|
|
710
|
+
DowngradeHeading: {
|
|
711
|
+
shortcuts: ["Delete", "Backspace"],
|
|
712
|
+
command: (ctx) => {
|
|
713
|
+
const commands = ctx.get(commandsCtx);
|
|
714
|
+
return () => commands.call(downgradeHeadingCommand.key);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
});
|
|
718
|
+
withMeta(headingKeymap.ctx, {
|
|
719
|
+
displayName: "KeymapCtx<heading>",
|
|
720
|
+
group: "Heading"
|
|
721
|
+
});
|
|
722
|
+
withMeta(headingKeymap.shortcuts, {
|
|
723
|
+
displayName: "Keymap<heading>",
|
|
724
|
+
group: "Heading"
|
|
725
|
+
});
|
|
726
|
+
//#endregion
|
|
727
|
+
//#region src/node/blockquote.ts
|
|
728
|
+
var blockquoteAttr = $nodeAttr("blockquote");
|
|
729
|
+
withMeta(blockquoteAttr, {
|
|
730
|
+
displayName: "Attr<blockquote>",
|
|
731
|
+
group: "Blockquote"
|
|
732
|
+
});
|
|
733
|
+
var blockquoteSchema = $nodeSchema("blockquote", (ctx) => ({
|
|
734
|
+
content: "block+",
|
|
735
|
+
group: "block",
|
|
736
|
+
defining: true,
|
|
737
|
+
parseDOM: [{ tag: "blockquote" }],
|
|
738
|
+
toDOM: (node) => [
|
|
739
|
+
"blockquote",
|
|
740
|
+
ctx.get(blockquoteAttr.key)(node),
|
|
741
|
+
0
|
|
742
|
+
],
|
|
743
|
+
parseMarkdown: {
|
|
744
|
+
match: ({ type }) => type === "blockquote",
|
|
745
|
+
runner: (state, node, type) => {
|
|
746
|
+
state.openNode(type).next(node.children).closeNode();
|
|
747
|
+
}
|
|
748
|
+
},
|
|
749
|
+
toMarkdown: {
|
|
750
|
+
match: (node) => node.type.name === "blockquote",
|
|
751
|
+
runner: (state, node) => {
|
|
752
|
+
state.openNode("blockquote").next(node.content).closeNode();
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
}));
|
|
756
|
+
withMeta(blockquoteSchema.node, {
|
|
757
|
+
displayName: "NodeSchema<blockquote>",
|
|
758
|
+
group: "Blockquote"
|
|
759
|
+
});
|
|
760
|
+
withMeta(blockquoteSchema.ctx, {
|
|
761
|
+
displayName: "NodeSchemaCtx<blockquote>",
|
|
762
|
+
group: "Blockquote"
|
|
763
|
+
});
|
|
764
|
+
var wrapInBlockquoteInputRule = $inputRule((ctx) => wrappingInputRule(/^\s*>\s$/, blockquoteSchema.type(ctx)));
|
|
765
|
+
withMeta(wrapInBlockquoteInputRule, {
|
|
766
|
+
displayName: "InputRule<wrapInBlockquoteInputRule>",
|
|
767
|
+
group: "Blockquote"
|
|
768
|
+
});
|
|
769
|
+
var wrapInBlockquoteCommand = $command("WrapInBlockquote", (ctx) => () => wrapIn(blockquoteSchema.type(ctx)));
|
|
770
|
+
withMeta(wrapInBlockquoteCommand, {
|
|
771
|
+
displayName: "Command<wrapInBlockquoteCommand>",
|
|
772
|
+
group: "Blockquote"
|
|
773
|
+
});
|
|
774
|
+
var blockquoteKeymap = $useKeymap("blockquoteKeymap", { WrapInBlockquote: {
|
|
775
|
+
shortcuts: "Mod-Shift-b",
|
|
776
|
+
command: (ctx) => {
|
|
777
|
+
const commands = ctx.get(commandsCtx);
|
|
778
|
+
return () => commands.call(wrapInBlockquoteCommand.key);
|
|
779
|
+
}
|
|
780
|
+
} });
|
|
781
|
+
withMeta(blockquoteKeymap.ctx, {
|
|
782
|
+
displayName: "KeymapCtx<blockquote>",
|
|
783
|
+
group: "Blockquote"
|
|
784
|
+
});
|
|
785
|
+
withMeta(blockquoteKeymap.shortcuts, {
|
|
786
|
+
displayName: "Keymap<blockquote>",
|
|
787
|
+
group: "Blockquote"
|
|
788
|
+
});
|
|
789
|
+
//#endregion
|
|
790
|
+
//#region src/node/code-block.ts
|
|
791
|
+
var codeBlockAttr = $nodeAttr("codeBlock", () => ({
|
|
792
|
+
pre: {},
|
|
793
|
+
code: {}
|
|
794
|
+
}));
|
|
795
|
+
withMeta(codeBlockAttr, {
|
|
796
|
+
displayName: "Attr<codeBlock>",
|
|
797
|
+
group: "CodeBlock"
|
|
798
|
+
});
|
|
799
|
+
var codeBlockSchema = $nodeSchema("code_block", (ctx) => {
|
|
800
|
+
return {
|
|
801
|
+
content: "text*",
|
|
802
|
+
group: "block",
|
|
803
|
+
marks: "",
|
|
804
|
+
defining: true,
|
|
805
|
+
code: true,
|
|
806
|
+
attrs: { language: {
|
|
807
|
+
default: "",
|
|
808
|
+
validate: "string"
|
|
809
|
+
} },
|
|
810
|
+
parseDOM: [{
|
|
811
|
+
tag: "pre",
|
|
812
|
+
preserveWhitespace: "full",
|
|
813
|
+
getAttrs: (dom) => {
|
|
814
|
+
if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
|
|
815
|
+
return { language: dom.dataset.language };
|
|
816
|
+
}
|
|
817
|
+
}],
|
|
818
|
+
toDOM: (node) => {
|
|
819
|
+
const attr = ctx.get(codeBlockAttr.key)(node);
|
|
820
|
+
const language = node.attrs.language;
|
|
821
|
+
const languageAttrs = language && language.length > 0 ? { "data-language": language } : void 0;
|
|
822
|
+
return [
|
|
823
|
+
"pre",
|
|
824
|
+
{
|
|
825
|
+
...attr.pre,
|
|
826
|
+
...languageAttrs
|
|
827
|
+
},
|
|
828
|
+
[
|
|
829
|
+
"code",
|
|
830
|
+
attr.code,
|
|
831
|
+
0
|
|
832
|
+
]
|
|
833
|
+
];
|
|
834
|
+
},
|
|
835
|
+
parseMarkdown: {
|
|
836
|
+
match: ({ type }) => type === "code",
|
|
837
|
+
runner: (state, node, type) => {
|
|
838
|
+
const language = node.lang ?? "";
|
|
839
|
+
const value = node.value;
|
|
840
|
+
state.openNode(type, { language });
|
|
841
|
+
if (value) state.addText(value);
|
|
842
|
+
state.closeNode();
|
|
843
|
+
}
|
|
844
|
+
},
|
|
845
|
+
toMarkdown: {
|
|
846
|
+
match: (node) => node.type.name === "code_block",
|
|
847
|
+
runner: (state, node) => {
|
|
848
|
+
state.addNode("code", void 0, node.content.firstChild?.text || "", { lang: node.attrs.language });
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
});
|
|
853
|
+
withMeta(codeBlockSchema.node, {
|
|
854
|
+
displayName: "NodeSchema<codeBlock>",
|
|
855
|
+
group: "CodeBlock"
|
|
856
|
+
});
|
|
857
|
+
withMeta(codeBlockSchema.ctx, {
|
|
858
|
+
displayName: "NodeSchemaCtx<codeBlock>",
|
|
859
|
+
group: "CodeBlock"
|
|
860
|
+
});
|
|
861
|
+
var createCodeBlockInputRule = $inputRule((ctx) => textblockTypeInputRule(/^```(?<language>[a-z]*)?[\s\n]$/, codeBlockSchema.type(ctx), (match) => ({ language: match.groups?.language ?? "" })));
|
|
862
|
+
withMeta(createCodeBlockInputRule, {
|
|
863
|
+
displayName: "InputRule<createCodeBlockInputRule>",
|
|
864
|
+
group: "CodeBlock"
|
|
865
|
+
});
|
|
866
|
+
var createCodeBlockCommand = $command("CreateCodeBlock", (ctx) => (language = "") => setBlockType(codeBlockSchema.type(ctx), { language }));
|
|
867
|
+
withMeta(createCodeBlockCommand, {
|
|
868
|
+
displayName: "Command<createCodeBlockCommand>",
|
|
869
|
+
group: "CodeBlock"
|
|
870
|
+
});
|
|
871
|
+
var updateCodeBlockLanguageCommand = $command("UpdateCodeBlockLanguage", () => ({ pos, language } = {
|
|
872
|
+
pos: -1,
|
|
873
|
+
language: ""
|
|
874
|
+
}) => (state, dispatch) => {
|
|
875
|
+
if (pos >= 0) {
|
|
876
|
+
dispatch?.(state.tr.setNodeAttribute(pos, "language", language));
|
|
877
|
+
return true;
|
|
878
|
+
}
|
|
879
|
+
return false;
|
|
880
|
+
});
|
|
881
|
+
withMeta(updateCodeBlockLanguageCommand, {
|
|
882
|
+
displayName: "Command<updateCodeBlockLanguageCommand>",
|
|
883
|
+
group: "CodeBlock"
|
|
884
|
+
});
|
|
885
|
+
var codeBlockKeymap = $useKeymap("codeBlockKeymap", { CreateCodeBlock: {
|
|
886
|
+
shortcuts: "Mod-Alt-c",
|
|
887
|
+
command: (ctx) => {
|
|
888
|
+
const commands = ctx.get(commandsCtx);
|
|
889
|
+
return () => commands.call(createCodeBlockCommand.key);
|
|
890
|
+
}
|
|
891
|
+
} });
|
|
892
|
+
withMeta(codeBlockKeymap.ctx, {
|
|
893
|
+
displayName: "KeymapCtx<codeBlock>",
|
|
894
|
+
group: "CodeBlock"
|
|
895
|
+
});
|
|
896
|
+
withMeta(codeBlockKeymap.shortcuts, {
|
|
897
|
+
displayName: "Keymap<codeBlock>",
|
|
898
|
+
group: "CodeBlock"
|
|
899
|
+
});
|
|
900
|
+
//#endregion
|
|
901
|
+
//#region src/node/image.ts
|
|
902
|
+
var imageAttr = $nodeAttr("image");
|
|
903
|
+
withMeta(imageAttr, {
|
|
904
|
+
displayName: "Attr<image>",
|
|
905
|
+
group: "Image"
|
|
906
|
+
});
|
|
907
|
+
var imageSchema = $nodeSchema("image", (ctx) => {
|
|
908
|
+
return {
|
|
909
|
+
inline: true,
|
|
910
|
+
group: "inline",
|
|
911
|
+
selectable: true,
|
|
912
|
+
draggable: true,
|
|
913
|
+
marks: "",
|
|
914
|
+
atom: true,
|
|
915
|
+
defining: true,
|
|
916
|
+
isolating: true,
|
|
917
|
+
attrs: {
|
|
918
|
+
src: {
|
|
919
|
+
default: "",
|
|
920
|
+
validate: "string"
|
|
921
|
+
},
|
|
922
|
+
alt: {
|
|
923
|
+
default: "",
|
|
924
|
+
validate: "string"
|
|
925
|
+
},
|
|
926
|
+
title: {
|
|
927
|
+
default: "",
|
|
928
|
+
validate: "string"
|
|
929
|
+
}
|
|
930
|
+
},
|
|
931
|
+
parseDOM: [{
|
|
932
|
+
tag: "img[src]",
|
|
933
|
+
getAttrs: (dom) => {
|
|
934
|
+
if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
|
|
935
|
+
return {
|
|
936
|
+
src: dom.getAttribute("src") || "",
|
|
937
|
+
alt: dom.getAttribute("alt") || "",
|
|
938
|
+
title: dom.getAttribute("title") || dom.getAttribute("alt") || ""
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
}],
|
|
942
|
+
toDOM: (node) => {
|
|
943
|
+
return ["img", {
|
|
944
|
+
...ctx.get(imageAttr.key)(node),
|
|
945
|
+
...node.attrs
|
|
946
|
+
}];
|
|
947
|
+
},
|
|
948
|
+
parseMarkdown: {
|
|
949
|
+
match: ({ type }) => type === "image",
|
|
950
|
+
runner: (state, node, type) => {
|
|
951
|
+
const url = node.url;
|
|
952
|
+
const alt = node.alt;
|
|
953
|
+
const title = node.title;
|
|
954
|
+
state.addNode(type, {
|
|
955
|
+
src: url,
|
|
956
|
+
alt,
|
|
957
|
+
title
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
},
|
|
961
|
+
toMarkdown: {
|
|
962
|
+
match: (node) => node.type.name === "image",
|
|
963
|
+
runner: (state, node) => {
|
|
964
|
+
state.addNode("image", void 0, void 0, {
|
|
965
|
+
title: node.attrs.title,
|
|
966
|
+
url: node.attrs.src,
|
|
967
|
+
alt: node.attrs.alt
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
};
|
|
972
|
+
});
|
|
973
|
+
withMeta(imageSchema.node, {
|
|
974
|
+
displayName: "NodeSchema<image>",
|
|
975
|
+
group: "Image"
|
|
976
|
+
});
|
|
977
|
+
withMeta(imageSchema.ctx, {
|
|
978
|
+
displayName: "NodeSchemaCtx<image>",
|
|
979
|
+
group: "Image"
|
|
980
|
+
});
|
|
981
|
+
var insertImageCommand = $command("InsertImage", (ctx) => (payload = {}) => (state, dispatch) => {
|
|
982
|
+
if (!dispatch) return true;
|
|
983
|
+
const { src = "", alt = "", title = "" } = payload;
|
|
984
|
+
const node = imageSchema.type(ctx).create({
|
|
985
|
+
src,
|
|
986
|
+
alt,
|
|
987
|
+
title
|
|
988
|
+
});
|
|
989
|
+
if (!node) return true;
|
|
990
|
+
dispatch(state.tr.replaceSelectionWith(node).scrollIntoView());
|
|
991
|
+
return true;
|
|
992
|
+
});
|
|
993
|
+
withMeta(insertImageCommand, {
|
|
994
|
+
displayName: "Command<insertImageCommand>",
|
|
995
|
+
group: "Image"
|
|
996
|
+
});
|
|
997
|
+
var updateImageCommand = $command("UpdateImage", (ctx) => (payload = {}) => (state, dispatch) => {
|
|
998
|
+
const nodeWithPos = findSelectedNodeOfType(state.selection, imageSchema.type(ctx));
|
|
999
|
+
if (!nodeWithPos) return false;
|
|
1000
|
+
const { node, pos } = nodeWithPos;
|
|
1001
|
+
const newAttrs = { ...node.attrs };
|
|
1002
|
+
const { src, alt, title } = payload;
|
|
1003
|
+
if (src !== void 0) newAttrs.src = src;
|
|
1004
|
+
if (alt !== void 0) newAttrs.alt = alt;
|
|
1005
|
+
if (title !== void 0) newAttrs.title = title;
|
|
1006
|
+
dispatch?.(state.tr.setNodeMarkup(pos, void 0, newAttrs).scrollIntoView());
|
|
1007
|
+
return true;
|
|
1008
|
+
});
|
|
1009
|
+
withMeta(updateImageCommand, {
|
|
1010
|
+
displayName: "Command<updateImageCommand>",
|
|
1011
|
+
group: "Image"
|
|
1012
|
+
});
|
|
1013
|
+
var insertImageInputRule = $inputRule((ctx) => new InputRule(/!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/, (state, match, start, end) => {
|
|
1014
|
+
const [matched, alt, src = "", title] = match;
|
|
1015
|
+
if (matched) return state.tr.replaceWith(start, end, imageSchema.type(ctx).create({
|
|
1016
|
+
src,
|
|
1017
|
+
alt,
|
|
1018
|
+
title
|
|
1019
|
+
}));
|
|
1020
|
+
return null;
|
|
1021
|
+
}));
|
|
1022
|
+
withMeta(insertImageInputRule, {
|
|
1023
|
+
displayName: "InputRule<insertImageInputRule>",
|
|
1024
|
+
group: "Image"
|
|
1025
|
+
});
|
|
1026
|
+
//#endregion
|
|
1027
|
+
//#region src/node/hardbreak.ts
|
|
1028
|
+
var hardbreakAttr = $nodeAttr("hardbreak", (node) => {
|
|
1029
|
+
return {
|
|
1030
|
+
"data-type": "hardbreak",
|
|
1031
|
+
"data-is-inline": node.attrs.isInline
|
|
1032
|
+
};
|
|
1033
|
+
});
|
|
1034
|
+
withMeta(hardbreakAttr, {
|
|
1035
|
+
displayName: "Attr<hardbreak>",
|
|
1036
|
+
group: "Hardbreak"
|
|
1037
|
+
});
|
|
1038
|
+
var hardbreakSchema = $nodeSchema("hardbreak", (ctx) => ({
|
|
1039
|
+
inline: true,
|
|
1040
|
+
group: "inline",
|
|
1041
|
+
attrs: { isInline: {
|
|
1042
|
+
default: false,
|
|
1043
|
+
validate: "boolean"
|
|
1044
|
+
} },
|
|
1045
|
+
selectable: false,
|
|
1046
|
+
parseDOM: [{ tag: "br" }, {
|
|
1047
|
+
tag: "span[data-type=\"hardbreak\"]",
|
|
1048
|
+
getAttrs: () => ({ isInline: true })
|
|
1049
|
+
}],
|
|
1050
|
+
toDOM: (node) => node.attrs.isInline ? [
|
|
1051
|
+
"span",
|
|
1052
|
+
ctx.get(hardbreakAttr.key)(node),
|
|
1053
|
+
" "
|
|
1054
|
+
] : ["br", ctx.get(hardbreakAttr.key)(node)],
|
|
1055
|
+
parseMarkdown: {
|
|
1056
|
+
match: ({ type }) => type === "break",
|
|
1057
|
+
runner: (state, node, type) => {
|
|
1058
|
+
state.addNode(type, { isInline: Boolean(node.data?.isInline) });
|
|
1059
|
+
}
|
|
1060
|
+
},
|
|
1061
|
+
leafText: () => "\n",
|
|
1062
|
+
toMarkdown: {
|
|
1063
|
+
match: (node) => node.type.name === "hardbreak",
|
|
1064
|
+
runner: (state, node) => {
|
|
1065
|
+
if (node.attrs.isInline) state.addNode("text", void 0, "\n");
|
|
1066
|
+
else state.addNode("break");
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
}));
|
|
1070
|
+
withMeta(hardbreakSchema.node, {
|
|
1071
|
+
displayName: "NodeSchema<hardbreak>",
|
|
1072
|
+
group: "Hardbreak"
|
|
1073
|
+
});
|
|
1074
|
+
withMeta(hardbreakSchema.ctx, {
|
|
1075
|
+
displayName: "NodeSchemaCtx<hardbreak>",
|
|
1076
|
+
group: "Hardbreak"
|
|
1077
|
+
});
|
|
1078
|
+
var insertHardbreakCommand = $command("InsertHardbreak", (ctx) => () => (state, dispatch) => {
|
|
1079
|
+
const { selection, tr } = state;
|
|
1080
|
+
if (!(selection instanceof TextSelection)) return false;
|
|
1081
|
+
if (selection.empty) {
|
|
1082
|
+
const node = selection.$from.node();
|
|
1083
|
+
if (node.childCount > 0 && node.lastChild?.type.name === "hardbreak") {
|
|
1084
|
+
dispatch?.(tr.replaceRangeWith(selection.to - 1, selection.to, state.schema.node("paragraph")).setSelection(Selection.near(tr.doc.resolve(selection.to))).scrollIntoView());
|
|
1085
|
+
return true;
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
dispatch?.(tr.setMeta("hardbreak", true).replaceSelectionWith(hardbreakSchema.type(ctx).create()).scrollIntoView());
|
|
1089
|
+
return true;
|
|
1090
|
+
});
|
|
1091
|
+
withMeta(insertHardbreakCommand, {
|
|
1092
|
+
displayName: "Command<insertHardbreakCommand>",
|
|
1093
|
+
group: "Hardbreak"
|
|
1094
|
+
});
|
|
1095
|
+
var hardbreakKeymap = $useKeymap("hardbreakKeymap", { InsertHardbreak: {
|
|
1096
|
+
shortcuts: "Shift-Enter",
|
|
1097
|
+
command: (ctx) => {
|
|
1098
|
+
const commands = ctx.get(commandsCtx);
|
|
1099
|
+
return () => commands.call(insertHardbreakCommand.key);
|
|
1100
|
+
}
|
|
1101
|
+
} });
|
|
1102
|
+
withMeta(hardbreakKeymap.ctx, {
|
|
1103
|
+
displayName: "KeymapCtx<hardbreak>",
|
|
1104
|
+
group: "Hardbreak"
|
|
1105
|
+
});
|
|
1106
|
+
withMeta(hardbreakKeymap.shortcuts, {
|
|
1107
|
+
displayName: "Keymap<hardbreak>",
|
|
1108
|
+
group: "Hardbreak"
|
|
1109
|
+
});
|
|
1110
|
+
//#endregion
|
|
1111
|
+
//#region src/node/hr.ts
|
|
1112
|
+
var hrAttr = $nodeAttr("hr");
|
|
1113
|
+
withMeta(hrAttr, {
|
|
1114
|
+
displayName: "Attr<hr>",
|
|
1115
|
+
group: "Hr"
|
|
1116
|
+
});
|
|
1117
|
+
var hrSchema = $nodeSchema("hr", (ctx) => ({
|
|
1118
|
+
group: "block",
|
|
1119
|
+
parseDOM: [{ tag: "hr" }],
|
|
1120
|
+
toDOM: (node) => ["hr", ctx.get(hrAttr.key)(node)],
|
|
1121
|
+
parseMarkdown: {
|
|
1122
|
+
match: ({ type }) => type === "thematicBreak",
|
|
1123
|
+
runner: (state, _, type) => {
|
|
1124
|
+
state.addNode(type);
|
|
1125
|
+
}
|
|
1126
|
+
},
|
|
1127
|
+
toMarkdown: {
|
|
1128
|
+
match: (node) => node.type.name === "hr",
|
|
1129
|
+
runner: (state) => {
|
|
1130
|
+
state.addNode("thematicBreak");
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
}));
|
|
1134
|
+
withMeta(hrSchema.node, {
|
|
1135
|
+
displayName: "NodeSchema<hr>",
|
|
1136
|
+
group: "Hr"
|
|
1137
|
+
});
|
|
1138
|
+
withMeta(hrSchema.ctx, {
|
|
1139
|
+
displayName: "NodeSchemaCtx<hr>",
|
|
1140
|
+
group: "Hr"
|
|
1141
|
+
});
|
|
1142
|
+
var insertHrInputRule = $inputRule((ctx) => new InputRule(/^(?:---|___\s|\*\*\*\s)$/, (state, match, start, end) => {
|
|
1143
|
+
const { tr } = state;
|
|
1144
|
+
if (match[0]) tr.replaceWith(start - 1, end, hrSchema.type(ctx).create());
|
|
1145
|
+
return tr;
|
|
1146
|
+
}));
|
|
1147
|
+
withMeta(insertHrInputRule, {
|
|
1148
|
+
displayName: "InputRule<insertHrInputRule>",
|
|
1149
|
+
group: "Hr"
|
|
1150
|
+
});
|
|
1151
|
+
var insertHrCommand = $command("InsertHr", (ctx) => () => (state, dispatch) => {
|
|
1152
|
+
if (!dispatch) return true;
|
|
1153
|
+
const paragraph = paragraphSchema.node.type(ctx).create();
|
|
1154
|
+
const { tr, selection } = state;
|
|
1155
|
+
const { from } = selection;
|
|
1156
|
+
const node = hrSchema.type(ctx).create();
|
|
1157
|
+
if (!node) return true;
|
|
1158
|
+
const _tr = tr.replaceSelectionWith(node).insert(from, paragraph);
|
|
1159
|
+
const sel = Selection.findFrom(_tr.doc.resolve(from), 1, true);
|
|
1160
|
+
if (!sel) return true;
|
|
1161
|
+
dispatch(_tr.setSelection(sel).scrollIntoView());
|
|
1162
|
+
return true;
|
|
1163
|
+
});
|
|
1164
|
+
withMeta(insertHrCommand, {
|
|
1165
|
+
displayName: "Command<insertHrCommand>",
|
|
1166
|
+
group: "Hr"
|
|
1167
|
+
});
|
|
1168
|
+
//#endregion
|
|
1169
|
+
//#region src/node/bullet-list.ts
|
|
1170
|
+
var bulletListAttr = $nodeAttr("bulletList");
|
|
1171
|
+
withMeta(bulletListAttr, {
|
|
1172
|
+
displayName: "Attr<bulletList>",
|
|
1173
|
+
group: "BulletList"
|
|
1174
|
+
});
|
|
1175
|
+
var bulletListSchema = $nodeSchema("bullet_list", (ctx) => {
|
|
1176
|
+
return {
|
|
1177
|
+
content: "listItem+",
|
|
1178
|
+
group: "block",
|
|
1179
|
+
attrs: { spread: {
|
|
1180
|
+
default: false,
|
|
1181
|
+
validate: "boolean"
|
|
1182
|
+
} },
|
|
1183
|
+
parseDOM: [{
|
|
1184
|
+
tag: "ul",
|
|
1185
|
+
getAttrs: (dom) => {
|
|
1186
|
+
if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
|
|
1187
|
+
return { spread: dom.dataset.spread === "true" };
|
|
1188
|
+
}
|
|
1189
|
+
}],
|
|
1190
|
+
toDOM: (node) => {
|
|
1191
|
+
return [
|
|
1192
|
+
"ul",
|
|
1193
|
+
{
|
|
1194
|
+
...ctx.get(bulletListAttr.key)(node),
|
|
1195
|
+
"data-spread": node.attrs.spread
|
|
1196
|
+
},
|
|
1197
|
+
0
|
|
1198
|
+
];
|
|
1199
|
+
},
|
|
1200
|
+
parseMarkdown: {
|
|
1201
|
+
match: ({ type, ordered }) => type === "list" && !ordered,
|
|
1202
|
+
runner: (state, node, type) => {
|
|
1203
|
+
const spread = node.spread != null ? `${node.spread}` : "false";
|
|
1204
|
+
state.openNode(type, { spread }).next(node.children).closeNode();
|
|
1205
|
+
}
|
|
1206
|
+
},
|
|
1207
|
+
toMarkdown: {
|
|
1208
|
+
match: (node) => node.type.name === "bullet_list",
|
|
1209
|
+
runner: (state, node) => {
|
|
1210
|
+
state.openNode("list", void 0, {
|
|
1211
|
+
ordered: false,
|
|
1212
|
+
spread: node.attrs.spread
|
|
1213
|
+
}).next(node.content).closeNode();
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
};
|
|
1217
|
+
});
|
|
1218
|
+
withMeta(bulletListSchema.node, {
|
|
1219
|
+
displayName: "NodeSchema<bulletList>",
|
|
1220
|
+
group: "BulletList"
|
|
1221
|
+
});
|
|
1222
|
+
withMeta(bulletListSchema.ctx, {
|
|
1223
|
+
displayName: "NodeSchemaCtx<bulletList>",
|
|
1224
|
+
group: "BulletList"
|
|
1225
|
+
});
|
|
1226
|
+
var wrapInBulletListInputRule = $inputRule((ctx) => wrappingInputRule(/^\s*([-+*])\s$/, bulletListSchema.type(ctx)));
|
|
1227
|
+
withMeta(wrapInBulletListInputRule, {
|
|
1228
|
+
displayName: "InputRule<wrapInBulletListInputRule>",
|
|
1229
|
+
group: "BulletList"
|
|
1230
|
+
});
|
|
1231
|
+
var wrapInBulletListCommand = $command("WrapInBulletList", (ctx) => () => wrapIn(bulletListSchema.type(ctx)));
|
|
1232
|
+
withMeta(wrapInBulletListCommand, {
|
|
1233
|
+
displayName: "Command<wrapInBulletListCommand>",
|
|
1234
|
+
group: "BulletList"
|
|
1235
|
+
});
|
|
1236
|
+
var bulletListKeymap = $useKeymap("bulletListKeymap", { WrapInBulletList: {
|
|
1237
|
+
shortcuts: "Mod-Alt-8",
|
|
1238
|
+
command: (ctx) => {
|
|
1239
|
+
const commands = ctx.get(commandsCtx);
|
|
1240
|
+
return () => commands.call(wrapInBulletListCommand.key);
|
|
1241
|
+
}
|
|
1242
|
+
} });
|
|
1243
|
+
withMeta(bulletListKeymap.ctx, {
|
|
1244
|
+
displayName: "KeymapCtx<bulletListKeymap>",
|
|
1245
|
+
group: "BulletList"
|
|
1246
|
+
});
|
|
1247
|
+
withMeta(bulletListKeymap.shortcuts, {
|
|
1248
|
+
displayName: "Keymap<bulletListKeymap>",
|
|
1249
|
+
group: "BulletList"
|
|
1250
|
+
});
|
|
1251
|
+
//#endregion
|
|
1252
|
+
//#region src/node/ordered-list.ts
|
|
1253
|
+
var orderedListAttr = $nodeAttr("orderedList");
|
|
1254
|
+
withMeta(orderedListAttr, {
|
|
1255
|
+
displayName: "Attr<orderedList>",
|
|
1256
|
+
group: "OrderedList"
|
|
1257
|
+
});
|
|
1258
|
+
var orderedListSchema = $nodeSchema("ordered_list", (ctx) => ({
|
|
1259
|
+
content: "listItem+",
|
|
1260
|
+
group: "block",
|
|
1261
|
+
attrs: {
|
|
1262
|
+
order: {
|
|
1263
|
+
default: 1,
|
|
1264
|
+
validate: "number"
|
|
1265
|
+
},
|
|
1266
|
+
spread: {
|
|
1267
|
+
default: false,
|
|
1268
|
+
validate: "boolean"
|
|
1269
|
+
}
|
|
1270
|
+
},
|
|
1271
|
+
parseDOM: [{
|
|
1272
|
+
tag: "ol",
|
|
1273
|
+
getAttrs: (dom) => {
|
|
1274
|
+
if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
|
|
1275
|
+
return {
|
|
1276
|
+
spread: dom.dataset.spread,
|
|
1277
|
+
order: dom.hasAttribute("start") ? Number(dom.getAttribute("start")) : 1
|
|
1278
|
+
};
|
|
1279
|
+
}
|
|
1280
|
+
}],
|
|
1281
|
+
toDOM: (node) => [
|
|
1282
|
+
"ol",
|
|
1283
|
+
{
|
|
1284
|
+
...ctx.get(orderedListAttr.key)(node),
|
|
1285
|
+
...node.attrs.order === 1 ? {} : { start: node.attrs.order },
|
|
1286
|
+
"data-spread": node.attrs.spread
|
|
1287
|
+
},
|
|
1288
|
+
0
|
|
1289
|
+
],
|
|
1290
|
+
parseMarkdown: {
|
|
1291
|
+
match: ({ type, ordered }) => type === "list" && !!ordered,
|
|
1292
|
+
runner: (state, node, type) => {
|
|
1293
|
+
const spread = node.spread != null ? `${node.spread}` : "true";
|
|
1294
|
+
state.openNode(type, {
|
|
1295
|
+
spread,
|
|
1296
|
+
order: node.start ?? 1
|
|
1297
|
+
}).next(node.children).closeNode();
|
|
1298
|
+
}
|
|
1299
|
+
},
|
|
1300
|
+
toMarkdown: {
|
|
1301
|
+
match: (node) => node.type.name === "ordered_list",
|
|
1302
|
+
runner: (state, node) => {
|
|
1303
|
+
state.openNode("list", void 0, {
|
|
1304
|
+
ordered: true,
|
|
1305
|
+
start: node.attrs.order ?? 1,
|
|
1306
|
+
spread: node.attrs.spread === "true"
|
|
1307
|
+
});
|
|
1308
|
+
state.next(node.content);
|
|
1309
|
+
state.closeNode();
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
}));
|
|
1313
|
+
withMeta(orderedListSchema.node, {
|
|
1314
|
+
displayName: "NodeSchema<orderedList>",
|
|
1315
|
+
group: "OrderedList"
|
|
1316
|
+
});
|
|
1317
|
+
withMeta(orderedListSchema.ctx, {
|
|
1318
|
+
displayName: "NodeSchemaCtx<orderedList>",
|
|
1319
|
+
group: "OrderedList"
|
|
1320
|
+
});
|
|
1321
|
+
var wrapInOrderedListInputRule = $inputRule((ctx) => wrappingInputRule(/^\s*(\d+)\.\s$/, orderedListSchema.type(ctx), (match) => ({ order: Number(match[1]) }), (match, node) => node.childCount + node.attrs.order === Number(match[1])));
|
|
1322
|
+
withMeta(wrapInOrderedListInputRule, {
|
|
1323
|
+
displayName: "InputRule<wrapInOrderedListInputRule>",
|
|
1324
|
+
group: "OrderedList"
|
|
1325
|
+
});
|
|
1326
|
+
var wrapInOrderedListCommand = $command("WrapInOrderedList", (ctx) => () => wrapIn(orderedListSchema.type(ctx)));
|
|
1327
|
+
withMeta(wrapInOrderedListCommand, {
|
|
1328
|
+
displayName: "Command<wrapInOrderedListCommand>",
|
|
1329
|
+
group: "OrderedList"
|
|
1330
|
+
});
|
|
1331
|
+
var orderedListKeymap = $useKeymap("orderedListKeymap", { WrapInOrderedList: {
|
|
1332
|
+
shortcuts: "Mod-Alt-7",
|
|
1333
|
+
command: (ctx) => {
|
|
1334
|
+
const commands = ctx.get(commandsCtx);
|
|
1335
|
+
return () => commands.call(wrapInOrderedListCommand.key);
|
|
1336
|
+
}
|
|
1337
|
+
} });
|
|
1338
|
+
withMeta(orderedListKeymap.ctx, {
|
|
1339
|
+
displayName: "KeymapCtx<orderedList>",
|
|
1340
|
+
group: "OrderedList"
|
|
1341
|
+
});
|
|
1342
|
+
withMeta(orderedListKeymap.shortcuts, {
|
|
1343
|
+
displayName: "Keymap<orderedList>",
|
|
1344
|
+
group: "OrderedList"
|
|
1345
|
+
});
|
|
1346
|
+
//#endregion
|
|
1347
|
+
//#region src/node/list-item.ts
|
|
1348
|
+
var listItemAttr = $nodeAttr("listItem");
|
|
1349
|
+
withMeta(listItemAttr, {
|
|
1350
|
+
displayName: "Attr<listItem>",
|
|
1351
|
+
group: "ListItem"
|
|
1352
|
+
});
|
|
1353
|
+
var listItemSchema = $nodeSchema("list_item", (ctx) => ({
|
|
1354
|
+
group: "listItem",
|
|
1355
|
+
content: "paragraph block*",
|
|
1356
|
+
attrs: {
|
|
1357
|
+
label: {
|
|
1358
|
+
default: "•",
|
|
1359
|
+
validate: "string"
|
|
1360
|
+
},
|
|
1361
|
+
listType: {
|
|
1362
|
+
default: "bullet",
|
|
1363
|
+
validate: "string"
|
|
1364
|
+
},
|
|
1365
|
+
spread: {
|
|
1366
|
+
default: true,
|
|
1367
|
+
validate: "boolean"
|
|
1368
|
+
}
|
|
1369
|
+
},
|
|
1370
|
+
defining: true,
|
|
1371
|
+
parseDOM: [{
|
|
1372
|
+
tag: "li",
|
|
1373
|
+
getAttrs: (dom) => {
|
|
1374
|
+
if (!(dom instanceof HTMLElement)) throw expectDomTypeError(dom);
|
|
1375
|
+
return {
|
|
1376
|
+
label: dom.dataset.label,
|
|
1377
|
+
listType: dom.dataset.listType,
|
|
1378
|
+
spread: dom.dataset.spread === "true"
|
|
1379
|
+
};
|
|
1380
|
+
}
|
|
1381
|
+
}],
|
|
1382
|
+
toDOM: (node) => [
|
|
1383
|
+
"li",
|
|
1384
|
+
{
|
|
1385
|
+
...ctx.get(listItemAttr.key)(node),
|
|
1386
|
+
"data-label": node.attrs.label,
|
|
1387
|
+
"data-list-type": node.attrs.listType,
|
|
1388
|
+
"data-spread": node.attrs.spread
|
|
1389
|
+
},
|
|
1390
|
+
0
|
|
1391
|
+
],
|
|
1392
|
+
parseMarkdown: {
|
|
1393
|
+
match: ({ type }) => type === "listItem",
|
|
1394
|
+
runner: (state, node, type) => {
|
|
1395
|
+
const label = node.label != null ? `${node.label}.` : "•";
|
|
1396
|
+
const listType = node.label != null ? "ordered" : "bullet";
|
|
1397
|
+
const spread = node.spread != null ? `${node.spread}` : "true";
|
|
1398
|
+
state.openNode(type, {
|
|
1399
|
+
label,
|
|
1400
|
+
listType,
|
|
1401
|
+
spread
|
|
1402
|
+
});
|
|
1403
|
+
state.next(node.children);
|
|
1404
|
+
state.closeNode();
|
|
1405
|
+
}
|
|
1406
|
+
},
|
|
1407
|
+
toMarkdown: {
|
|
1408
|
+
match: (node) => node.type.name === "list_item",
|
|
1409
|
+
runner: (state, node) => {
|
|
1410
|
+
state.openNode("listItem", void 0, { spread: node.attrs.spread });
|
|
1411
|
+
state.next(node.content);
|
|
1412
|
+
state.closeNode();
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
}));
|
|
1416
|
+
withMeta(listItemSchema.node, {
|
|
1417
|
+
displayName: "NodeSchema<listItem>",
|
|
1418
|
+
group: "ListItem"
|
|
1419
|
+
});
|
|
1420
|
+
withMeta(listItemSchema.ctx, {
|
|
1421
|
+
displayName: "NodeSchemaCtx<listItem>",
|
|
1422
|
+
group: "ListItem"
|
|
1423
|
+
});
|
|
1424
|
+
var sinkListItemCommand = $command("SinkListItem", (ctx) => () => sinkListItem(listItemSchema.type(ctx)));
|
|
1425
|
+
withMeta(sinkListItemCommand, {
|
|
1426
|
+
displayName: "Command<sinkListItemCommand>",
|
|
1427
|
+
group: "ListItem"
|
|
1428
|
+
});
|
|
1429
|
+
var liftListItemCommand = $command("LiftListItem", (ctx) => () => liftListItem(listItemSchema.type(ctx)));
|
|
1430
|
+
withMeta(liftListItemCommand, {
|
|
1431
|
+
displayName: "Command<liftListItemCommand>",
|
|
1432
|
+
group: "ListItem"
|
|
1433
|
+
});
|
|
1434
|
+
var splitListItemCommand = $command("SplitListItem", (ctx) => () => splitListItem(listItemSchema.type(ctx)));
|
|
1435
|
+
withMeta(splitListItemCommand, {
|
|
1436
|
+
displayName: "Command<splitListItemCommand>",
|
|
1437
|
+
group: "ListItem"
|
|
1438
|
+
});
|
|
1439
|
+
function liftFirstListItem(ctx) {
|
|
1440
|
+
return (state, dispatch, view) => {
|
|
1441
|
+
const { selection } = state;
|
|
1442
|
+
if (!(selection instanceof TextSelection)) return false;
|
|
1443
|
+
const { empty, $from } = selection;
|
|
1444
|
+
if (!empty || $from.parentOffset !== 0) return false;
|
|
1445
|
+
if ($from.node(-1).type !== listItemSchema.type(ctx)) return false;
|
|
1446
|
+
return joinBackward(state, dispatch, view);
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
var liftFirstListItemCommand = $command("LiftFirstListItem", (ctx) => () => liftFirstListItem(ctx));
|
|
1450
|
+
withMeta(liftFirstListItemCommand, {
|
|
1451
|
+
displayName: "Command<liftFirstListItemCommand>",
|
|
1452
|
+
group: "ListItem"
|
|
1453
|
+
});
|
|
1454
|
+
var listItemKeymap = $useKeymap("listItemKeymap", {
|
|
1455
|
+
NextListItem: {
|
|
1456
|
+
shortcuts: "Enter",
|
|
1457
|
+
command: (ctx) => {
|
|
1458
|
+
const commands = ctx.get(commandsCtx);
|
|
1459
|
+
return () => commands.call(splitListItemCommand.key);
|
|
1460
|
+
}
|
|
1461
|
+
},
|
|
1462
|
+
SinkListItem: {
|
|
1463
|
+
shortcuts: ["Tab", "Mod-]"],
|
|
1464
|
+
command: (ctx) => {
|
|
1465
|
+
const commands = ctx.get(commandsCtx);
|
|
1466
|
+
return () => commands.call(sinkListItemCommand.key);
|
|
1467
|
+
}
|
|
1468
|
+
},
|
|
1469
|
+
LiftListItem: {
|
|
1470
|
+
shortcuts: ["Shift-Tab", "Mod-["],
|
|
1471
|
+
command: (ctx) => {
|
|
1472
|
+
const commands = ctx.get(commandsCtx);
|
|
1473
|
+
return () => commands.call(liftListItemCommand.key);
|
|
1474
|
+
}
|
|
1475
|
+
},
|
|
1476
|
+
LiftFirstListItem: {
|
|
1477
|
+
shortcuts: ["Backspace", "Delete"],
|
|
1478
|
+
command: (ctx) => {
|
|
1479
|
+
const commands = ctx.get(commandsCtx);
|
|
1480
|
+
return () => commands.call(liftFirstListItemCommand.key);
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
});
|
|
1484
|
+
withMeta(listItemKeymap.ctx, {
|
|
1485
|
+
displayName: "KeymapCtx<listItem>",
|
|
1486
|
+
group: "ListItem"
|
|
1487
|
+
});
|
|
1488
|
+
withMeta(listItemKeymap.shortcuts, {
|
|
1489
|
+
displayName: "Keymap<listItem>",
|
|
1490
|
+
group: "ListItem"
|
|
1491
|
+
});
|
|
1492
|
+
//#endregion
|
|
1493
|
+
//#region src/node/text.ts
|
|
1494
|
+
var textSchema = $node("text", () => ({
|
|
1495
|
+
group: "inline",
|
|
1496
|
+
parseMarkdown: {
|
|
1497
|
+
match: ({ type }) => type === "text",
|
|
1498
|
+
runner: (state, node) => {
|
|
1499
|
+
state.addText(node.value);
|
|
1500
|
+
}
|
|
1501
|
+
},
|
|
1502
|
+
toMarkdown: {
|
|
1503
|
+
match: (node) => node.type.name === "text",
|
|
1504
|
+
runner: (state, node) => {
|
|
1505
|
+
state.addNode("text", void 0, node.text);
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
}));
|
|
1509
|
+
withMeta(textSchema, {
|
|
1510
|
+
displayName: "NodeSchema<text>",
|
|
1511
|
+
group: "Text"
|
|
1512
|
+
});
|
|
1513
|
+
//#endregion
|
|
1514
|
+
//#region src/node/html.ts
|
|
1515
|
+
var htmlAttr = $nodeAttr("html");
|
|
1516
|
+
withMeta(htmlAttr, {
|
|
1517
|
+
displayName: "Attr<html>",
|
|
1518
|
+
group: "Html"
|
|
1519
|
+
});
|
|
1520
|
+
var htmlSchema = $nodeSchema("html", (ctx) => {
|
|
1521
|
+
return {
|
|
1522
|
+
atom: true,
|
|
1523
|
+
group: "inline",
|
|
1524
|
+
inline: true,
|
|
1525
|
+
attrs: { value: {
|
|
1526
|
+
default: "",
|
|
1527
|
+
validate: "string"
|
|
1528
|
+
} },
|
|
1529
|
+
toDOM: (node) => {
|
|
1530
|
+
const span = document.createElement("span");
|
|
1531
|
+
const attr = {
|
|
1532
|
+
...ctx.get(htmlAttr.key)(node),
|
|
1533
|
+
"data-value": node.attrs.value,
|
|
1534
|
+
"data-type": "html"
|
|
1535
|
+
};
|
|
1536
|
+
span.textContent = node.attrs.value;
|
|
1537
|
+
return [
|
|
1538
|
+
"span",
|
|
1539
|
+
attr,
|
|
1540
|
+
node.attrs.value
|
|
1541
|
+
];
|
|
1542
|
+
},
|
|
1543
|
+
parseDOM: [{
|
|
1544
|
+
tag: "span[data-type=\"html\"]",
|
|
1545
|
+
getAttrs: (dom) => {
|
|
1546
|
+
return { value: dom.dataset.value ?? "" };
|
|
1547
|
+
}
|
|
1548
|
+
}],
|
|
1549
|
+
parseMarkdown: {
|
|
1550
|
+
match: ({ type }) => Boolean(type === "html"),
|
|
1551
|
+
runner: (state, node, type) => {
|
|
1552
|
+
state.addNode(type, { value: node.value });
|
|
1553
|
+
}
|
|
1554
|
+
},
|
|
1555
|
+
toMarkdown: {
|
|
1556
|
+
match: (node) => node.type.name === "html",
|
|
1557
|
+
runner: (state, node) => {
|
|
1558
|
+
state.addNode("html", void 0, node.attrs.value);
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
};
|
|
1562
|
+
});
|
|
1563
|
+
withMeta(htmlSchema.node, {
|
|
1564
|
+
displayName: "NodeSchema<html>",
|
|
1565
|
+
group: "Html"
|
|
1566
|
+
});
|
|
1567
|
+
withMeta(htmlSchema.ctx, {
|
|
1568
|
+
displayName: "NodeSchemaCtx<html>",
|
|
1569
|
+
group: "Html"
|
|
1570
|
+
});
|
|
1571
|
+
//#endregion
|
|
1572
|
+
//#region src/composed/schema.ts
|
|
1573
|
+
var schema = [
|
|
1574
|
+
docSchema,
|
|
1575
|
+
paragraphAttr,
|
|
1576
|
+
paragraphSchema,
|
|
1577
|
+
headingIdGenerator,
|
|
1578
|
+
headingAttr,
|
|
1579
|
+
headingSchema,
|
|
1580
|
+
hardbreakAttr,
|
|
1581
|
+
hardbreakSchema,
|
|
1582
|
+
blockquoteAttr,
|
|
1583
|
+
blockquoteSchema,
|
|
1584
|
+
codeBlockAttr,
|
|
1585
|
+
codeBlockSchema,
|
|
1586
|
+
hrAttr,
|
|
1587
|
+
hrSchema,
|
|
1588
|
+
imageAttr,
|
|
1589
|
+
imageSchema,
|
|
1590
|
+
bulletListAttr,
|
|
1591
|
+
bulletListSchema,
|
|
1592
|
+
orderedListAttr,
|
|
1593
|
+
orderedListSchema,
|
|
1594
|
+
listItemAttr,
|
|
1595
|
+
listItemSchema,
|
|
1596
|
+
emphasisAttr,
|
|
1597
|
+
emphasisSchema,
|
|
1598
|
+
strongAttr,
|
|
1599
|
+
strongSchema,
|
|
1600
|
+
inlineCodeAttr,
|
|
1601
|
+
inlineCodeSchema,
|
|
1602
|
+
linkAttr,
|
|
1603
|
+
linkSchema,
|
|
1604
|
+
htmlAttr,
|
|
1605
|
+
htmlSchema,
|
|
1606
|
+
textSchema
|
|
1607
|
+
].flat();
|
|
1608
|
+
//#endregion
|
|
1609
|
+
//#region src/composed/inputrules.ts
|
|
1610
|
+
var inputRules = [
|
|
1611
|
+
wrapInBlockquoteInputRule,
|
|
1612
|
+
wrapInBulletListInputRule,
|
|
1613
|
+
wrapInOrderedListInputRule,
|
|
1614
|
+
createCodeBlockInputRule,
|
|
1615
|
+
insertHrInputRule,
|
|
1616
|
+
wrapInHeadingInputRule
|
|
1617
|
+
].flat();
|
|
1618
|
+
var markInputRules = [
|
|
1619
|
+
emphasisStarInputRule,
|
|
1620
|
+
emphasisUnderscoreInputRule,
|
|
1621
|
+
inlineCodeInputRule,
|
|
1622
|
+
strongInputRule
|
|
1623
|
+
];
|
|
1624
|
+
//#endregion
|
|
1625
|
+
//#region src/commands/index.ts
|
|
1626
|
+
var isMarkSelectedCommand = $command("IsMarkSelected", () => (markType) => (state) => {
|
|
1627
|
+
if (!markType) return false;
|
|
1628
|
+
const { doc, selection } = state;
|
|
1629
|
+
return doc.rangeHasMark(selection.from, selection.to, markType);
|
|
1630
|
+
});
|
|
1631
|
+
var isNodeSelectedCommand = $command("IsNoteSelected", () => (nodeType) => (state) => {
|
|
1632
|
+
if (!nodeType) return false;
|
|
1633
|
+
return findNodeInSelection(state, nodeType).hasNode;
|
|
1634
|
+
});
|
|
1635
|
+
var clearTextInCurrentBlockCommand = $command("ClearTextInCurrentBlock", () => () => (state, dispatch) => {
|
|
1636
|
+
let tr = state.tr;
|
|
1637
|
+
const { $from, $to } = tr.selection;
|
|
1638
|
+
const { pos: from } = $from;
|
|
1639
|
+
const { pos: right } = $to;
|
|
1640
|
+
const left = from - $from.node().content.size;
|
|
1641
|
+
if (left < 0) return false;
|
|
1642
|
+
tr = tr.deleteRange(left, right);
|
|
1643
|
+
dispatch?.(tr);
|
|
1644
|
+
return true;
|
|
1645
|
+
});
|
|
1646
|
+
var setBlockTypeCommand = $command("SetBlockType", () => (payload) => (state, dispatch) => {
|
|
1647
|
+
const { nodeType, attrs = null } = payload ?? {};
|
|
1648
|
+
if (!nodeType) return false;
|
|
1649
|
+
const tr = state.tr;
|
|
1650
|
+
const { from, to } = tr.selection;
|
|
1651
|
+
try {
|
|
1652
|
+
tr.setBlockType(from, to, nodeType, attrs);
|
|
1653
|
+
} catch {
|
|
1654
|
+
return false;
|
|
1655
|
+
}
|
|
1656
|
+
dispatch?.(tr);
|
|
1657
|
+
return true;
|
|
1658
|
+
});
|
|
1659
|
+
var wrapInBlockTypeCommand = $command("WrapInBlockType", () => (payload) => (state, dispatch) => {
|
|
1660
|
+
const { nodeType, attrs = null } = payload ?? {};
|
|
1661
|
+
if (!nodeType) return false;
|
|
1662
|
+
let tr = state.tr;
|
|
1663
|
+
try {
|
|
1664
|
+
const { $from, $to } = tr.selection;
|
|
1665
|
+
const blockRange = $from.blockRange($to);
|
|
1666
|
+
const wrapping = blockRange && findWrapping(blockRange, nodeType, attrs);
|
|
1667
|
+
if (!wrapping) return false;
|
|
1668
|
+
tr = tr.wrap(blockRange, wrapping);
|
|
1669
|
+
} catch {
|
|
1670
|
+
return false;
|
|
1671
|
+
}
|
|
1672
|
+
dispatch?.(tr);
|
|
1673
|
+
return true;
|
|
1674
|
+
});
|
|
1675
|
+
var addBlockTypeCommand = $command("AddBlockType", () => (payload) => (state, dispatch) => {
|
|
1676
|
+
const { nodeType, attrs = null } = payload ?? {};
|
|
1677
|
+
if (!nodeType) return false;
|
|
1678
|
+
const tr = state.tr;
|
|
1679
|
+
try {
|
|
1680
|
+
const node = nodeType instanceof Node ? nodeType : nodeType.createAndFill(attrs);
|
|
1681
|
+
if (!node) return false;
|
|
1682
|
+
tr.replaceSelectionWith(node);
|
|
1683
|
+
} catch {
|
|
1684
|
+
return false;
|
|
1685
|
+
}
|
|
1686
|
+
dispatch?.(tr);
|
|
1687
|
+
return true;
|
|
1688
|
+
});
|
|
1689
|
+
var selectTextNearPosCommand = $command("SelectTextNearPos", () => (payload) => (state, dispatch) => {
|
|
1690
|
+
const { pos } = payload ?? {};
|
|
1691
|
+
if (pos == null) return false;
|
|
1692
|
+
const clamp = (value, min, max) => Math.min(Math.max(value, min), max);
|
|
1693
|
+
const tr = state.tr;
|
|
1694
|
+
try {
|
|
1695
|
+
const $pos = state.doc.resolve(clamp(pos, 0, state.doc.content.size));
|
|
1696
|
+
tr.setSelection(TextSelection.near($pos));
|
|
1697
|
+
} catch {
|
|
1698
|
+
return false;
|
|
1699
|
+
}
|
|
1700
|
+
dispatch?.(tr.scrollIntoView());
|
|
1701
|
+
return true;
|
|
1702
|
+
});
|
|
1703
|
+
//#endregion
|
|
1704
|
+
//#region src/composed/commands.ts
|
|
1705
|
+
var commands = [
|
|
1706
|
+
turnIntoTextCommand,
|
|
1707
|
+
wrapInBlockquoteCommand,
|
|
1708
|
+
wrapInHeadingCommand,
|
|
1709
|
+
downgradeHeadingCommand,
|
|
1710
|
+
createCodeBlockCommand,
|
|
1711
|
+
insertHardbreakCommand,
|
|
1712
|
+
insertHrCommand,
|
|
1713
|
+
insertImageCommand,
|
|
1714
|
+
updateImageCommand,
|
|
1715
|
+
wrapInOrderedListCommand,
|
|
1716
|
+
wrapInBulletListCommand,
|
|
1717
|
+
sinkListItemCommand,
|
|
1718
|
+
splitListItemCommand,
|
|
1719
|
+
liftListItemCommand,
|
|
1720
|
+
liftFirstListItemCommand,
|
|
1721
|
+
toggleEmphasisCommand,
|
|
1722
|
+
toggleInlineCodeCommand,
|
|
1723
|
+
toggleStrongCommand,
|
|
1724
|
+
toggleLinkCommand,
|
|
1725
|
+
updateLinkCommand,
|
|
1726
|
+
isMarkSelectedCommand,
|
|
1727
|
+
isNodeSelectedCommand,
|
|
1728
|
+
clearTextInCurrentBlockCommand,
|
|
1729
|
+
setBlockTypeCommand,
|
|
1730
|
+
wrapInBlockTypeCommand,
|
|
1731
|
+
addBlockTypeCommand,
|
|
1732
|
+
selectTextNearPosCommand
|
|
1733
|
+
];
|
|
1734
|
+
//#endregion
|
|
1735
|
+
//#region src/composed/keymap.ts
|
|
1736
|
+
var keymap = [
|
|
1737
|
+
blockquoteKeymap,
|
|
1738
|
+
codeBlockKeymap,
|
|
1739
|
+
hardbreakKeymap,
|
|
1740
|
+
headingKeymap,
|
|
1741
|
+
listItemKeymap,
|
|
1742
|
+
orderedListKeymap,
|
|
1743
|
+
bulletListKeymap,
|
|
1744
|
+
paragraphKeymap,
|
|
1745
|
+
emphasisKeymap,
|
|
1746
|
+
inlineCodeKeymap,
|
|
1747
|
+
strongKeymap
|
|
1748
|
+
].flat();
|
|
1749
|
+
//#endregion
|
|
1750
|
+
//#region src/plugin/remark-add-order-in-list-plugin.ts
|
|
1751
|
+
var remarkAddOrderInListPlugin = $remark("remarkAddOrderInList", () => () => (tree) => {
|
|
1752
|
+
visit(tree, "list", (node) => {
|
|
1753
|
+
if (node.ordered) {
|
|
1754
|
+
const start = node.start ?? 1;
|
|
1755
|
+
node.children.forEach((child, index) => {
|
|
1756
|
+
child.label = index + start;
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
});
|
|
1760
|
+
});
|
|
1761
|
+
withMeta(remarkAddOrderInListPlugin.plugin, {
|
|
1762
|
+
displayName: "Remark<remarkAddOrderInListPlugin>",
|
|
1763
|
+
group: "Remark"
|
|
1764
|
+
});
|
|
1765
|
+
withMeta(remarkAddOrderInListPlugin.options, {
|
|
1766
|
+
displayName: "RemarkConfig<remarkAddOrderInListPlugin>",
|
|
1767
|
+
group: "Remark"
|
|
1768
|
+
});
|
|
1769
|
+
//#endregion
|
|
1770
|
+
//#region src/plugin/remark-line-break.ts
|
|
1771
|
+
var remarkLineBreak = $remark("remarkLineBreak", () => () => (tree) => {
|
|
1772
|
+
const find = /[\t ]*(?:\r?\n|\r)/g;
|
|
1773
|
+
visit(tree, "text", (node, index, parent) => {
|
|
1774
|
+
if (!node.value || typeof node.value !== "string") return;
|
|
1775
|
+
const result = [];
|
|
1776
|
+
let start = 0;
|
|
1777
|
+
find.lastIndex = 0;
|
|
1778
|
+
let match = find.exec(node.value);
|
|
1779
|
+
while (match) {
|
|
1780
|
+
const position = match.index;
|
|
1781
|
+
if (start !== position) result.push({
|
|
1782
|
+
type: "text",
|
|
1783
|
+
value: node.value.slice(start, position)
|
|
1784
|
+
});
|
|
1785
|
+
result.push({
|
|
1786
|
+
type: "break",
|
|
1787
|
+
data: { isInline: true }
|
|
1788
|
+
});
|
|
1789
|
+
start = position + match[0].length;
|
|
1790
|
+
match = find.exec(node.value);
|
|
1791
|
+
}
|
|
1792
|
+
if (!(result.length > 0 && parent && typeof index === "number")) return;
|
|
1793
|
+
if (start < node.value.length) result.push({
|
|
1794
|
+
type: "text",
|
|
1795
|
+
value: node.value.slice(start)
|
|
1796
|
+
});
|
|
1797
|
+
parent.children.splice(index, 1, ...result);
|
|
1798
|
+
return index + result.length;
|
|
1799
|
+
});
|
|
1800
|
+
});
|
|
1801
|
+
withMeta(remarkLineBreak.plugin, {
|
|
1802
|
+
displayName: "Remark<remarkLineBreak>",
|
|
1803
|
+
group: "Remark"
|
|
1804
|
+
});
|
|
1805
|
+
withMeta(remarkLineBreak.options, {
|
|
1806
|
+
displayName: "RemarkConfig<remarkLineBreak>",
|
|
1807
|
+
group: "Remark"
|
|
1808
|
+
});
|
|
1809
|
+
//#endregion
|
|
1810
|
+
//#region src/plugin/remark-inline-link-plugin.ts
|
|
1811
|
+
var remarkInlineLinkPlugin = $remark("remarkInlineLink", () => remarkInlineLinks);
|
|
1812
|
+
withMeta(remarkInlineLinkPlugin.plugin, {
|
|
1813
|
+
displayName: "Remark<remarkInlineLinkPlugin>",
|
|
1814
|
+
group: "Remark"
|
|
1815
|
+
});
|
|
1816
|
+
withMeta(remarkInlineLinkPlugin.options, {
|
|
1817
|
+
displayName: "RemarkConfig<remarkInlineLinkPlugin>",
|
|
1818
|
+
group: "Remark"
|
|
1819
|
+
});
|
|
1820
|
+
//#endregion
|
|
1821
|
+
//#region src/plugin/remark-html-transformer.ts
|
|
1822
|
+
var isParent = (node) => !!node.children;
|
|
1823
|
+
var isHTML = (node) => node.type === "html";
|
|
1824
|
+
function flatMapWithDepth(ast, fn) {
|
|
1825
|
+
return transform(ast, 0, null)[0];
|
|
1826
|
+
function transform(node, index, parent) {
|
|
1827
|
+
if (isParent(node)) {
|
|
1828
|
+
const out = [];
|
|
1829
|
+
for (let i = 0, n = node.children.length; i < n; i++) {
|
|
1830
|
+
const nthChild = node.children[i];
|
|
1831
|
+
if (nthChild) {
|
|
1832
|
+
const xs = transform(nthChild, i, node);
|
|
1833
|
+
if (xs) for (let j = 0, m = xs.length; j < m; j++) {
|
|
1834
|
+
const item = xs[j];
|
|
1835
|
+
if (item) out.push(item);
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
node.children = out;
|
|
1840
|
+
}
|
|
1841
|
+
return fn(node, index, parent);
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
var BLOCK_CONTAINER_TYPES = [
|
|
1845
|
+
"root",
|
|
1846
|
+
"blockquote",
|
|
1847
|
+
"listItem"
|
|
1848
|
+
];
|
|
1849
|
+
var remarkHtmlTransformer = $remark("remarkHTMLTransformer", () => () => (tree) => {
|
|
1850
|
+
flatMapWithDepth(tree, (node, _index, parent) => {
|
|
1851
|
+
if (!isHTML(node)) return [node];
|
|
1852
|
+
if (parent && BLOCK_CONTAINER_TYPES.includes(parent.type)) {
|
|
1853
|
+
node.children = [{ ...node }];
|
|
1854
|
+
delete node.value;
|
|
1855
|
+
node.type = "paragraph";
|
|
1856
|
+
}
|
|
1857
|
+
return [node];
|
|
1858
|
+
});
|
|
1859
|
+
});
|
|
1860
|
+
withMeta(remarkHtmlTransformer.plugin, {
|
|
1861
|
+
displayName: "Remark<remarkHtmlTransformer>",
|
|
1862
|
+
group: "Remark"
|
|
1863
|
+
});
|
|
1864
|
+
withMeta(remarkHtmlTransformer.options, {
|
|
1865
|
+
displayName: "RemarkConfig<remarkHtmlTransformer>",
|
|
1866
|
+
group: "Remark"
|
|
1867
|
+
});
|
|
1868
|
+
//#endregion
|
|
1869
|
+
//#region src/plugin/remark-marker-plugin.ts
|
|
1870
|
+
var remarkMarker = $remark("remarkMarker", () => () => (tree, file) => {
|
|
1871
|
+
const getMarker = (node) => {
|
|
1872
|
+
return file.value.charAt(node.position.start.offset);
|
|
1873
|
+
};
|
|
1874
|
+
visit(tree, (node) => ["strong", "emphasis"].includes(node.type), (node) => {
|
|
1875
|
+
node.marker = getMarker(node);
|
|
1876
|
+
});
|
|
1877
|
+
});
|
|
1878
|
+
withMeta(remarkMarker.plugin, {
|
|
1879
|
+
displayName: "Remark<remarkMarker>",
|
|
1880
|
+
group: "Remark"
|
|
1881
|
+
});
|
|
1882
|
+
withMeta(remarkMarker.options, {
|
|
1883
|
+
displayName: "RemarkConfig<remarkMarker>",
|
|
1884
|
+
group: "Remark"
|
|
1885
|
+
});
|
|
1886
|
+
//#endregion
|
|
1887
|
+
//#region src/plugin/inline-nodes-cursor-plugin.ts
|
|
1888
|
+
var inlineNodesCursorPlugin = $prose(() => {
|
|
1889
|
+
let lock = false;
|
|
1890
|
+
const inlineNodesCursorPlugin = new Plugin({
|
|
1891
|
+
key: new PluginKey("MILKDOWN_INLINE_NODES_CURSOR"),
|
|
1892
|
+
state: {
|
|
1893
|
+
init() {
|
|
1894
|
+
return false;
|
|
1895
|
+
},
|
|
1896
|
+
apply(tr) {
|
|
1897
|
+
if (!tr.selection.empty) return false;
|
|
1898
|
+
const pos = tr.selection.$from;
|
|
1899
|
+
const left = pos.nodeBefore;
|
|
1900
|
+
const right = pos.nodeAfter;
|
|
1901
|
+
if (left && right && left.isInline && !left.isText && right.isInline && !right.isText) return true;
|
|
1902
|
+
return false;
|
|
1903
|
+
}
|
|
1904
|
+
},
|
|
1905
|
+
props: {
|
|
1906
|
+
handleDOMEvents: {
|
|
1907
|
+
compositionend: (view, e) => {
|
|
1908
|
+
if (lock) {
|
|
1909
|
+
lock = false;
|
|
1910
|
+
requestAnimationFrame(() => {
|
|
1911
|
+
if (inlineNodesCursorPlugin.getState(view.state)) {
|
|
1912
|
+
const from = view.state.selection.from;
|
|
1913
|
+
e.preventDefault();
|
|
1914
|
+
view.dispatch(view.state.tr.insertText(e.data || "", from));
|
|
1915
|
+
}
|
|
1916
|
+
});
|
|
1917
|
+
return true;
|
|
1918
|
+
}
|
|
1919
|
+
return false;
|
|
1920
|
+
},
|
|
1921
|
+
compositionstart: (view) => {
|
|
1922
|
+
if (inlineNodesCursorPlugin.getState(view.state)) lock = true;
|
|
1923
|
+
return false;
|
|
1924
|
+
},
|
|
1925
|
+
beforeinput: (view, e) => {
|
|
1926
|
+
if (inlineNodesCursorPlugin.getState(view.state) && e instanceof InputEvent && e.data && !lock) {
|
|
1927
|
+
const from = view.state.selection.from;
|
|
1928
|
+
e.preventDefault();
|
|
1929
|
+
view.dispatch(view.state.tr.insertText(e.data || "", from));
|
|
1930
|
+
return true;
|
|
1931
|
+
}
|
|
1932
|
+
return false;
|
|
1933
|
+
}
|
|
1934
|
+
},
|
|
1935
|
+
decorations(state) {
|
|
1936
|
+
if (inlineNodesCursorPlugin.getState(state)) {
|
|
1937
|
+
const position = state.selection.$from.pos;
|
|
1938
|
+
const left = document.createElement("span");
|
|
1939
|
+
const leftDec = Decoration.widget(position, left, { side: -1 });
|
|
1940
|
+
const right = document.createElement("span");
|
|
1941
|
+
const rightDec = Decoration.widget(position, right);
|
|
1942
|
+
setTimeout(() => {
|
|
1943
|
+
left.contentEditable = "true";
|
|
1944
|
+
right.contentEditable = "true";
|
|
1945
|
+
});
|
|
1946
|
+
return DecorationSet.create(state.doc, [leftDec, rightDec]);
|
|
1947
|
+
}
|
|
1948
|
+
return DecorationSet.empty;
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
});
|
|
1952
|
+
return inlineNodesCursorPlugin;
|
|
1953
|
+
});
|
|
1954
|
+
withMeta(inlineNodesCursorPlugin, {
|
|
1955
|
+
displayName: "Prose<inlineNodesCursorPlugin>",
|
|
1956
|
+
group: "Prose"
|
|
1957
|
+
});
|
|
1958
|
+
//#endregion
|
|
1959
|
+
//#region src/plugin/hardbreak-clear-mark-plugin.ts
|
|
1960
|
+
var hardbreakClearMarkPlugin = $prose((ctx) => {
|
|
1961
|
+
return new Plugin({
|
|
1962
|
+
key: new PluginKey("MILKDOWN_HARDBREAK_MARKS"),
|
|
1963
|
+
appendTransaction: (trs, _oldState, newState) => {
|
|
1964
|
+
if (!trs.length) return;
|
|
1965
|
+
const [tr] = trs;
|
|
1966
|
+
if (!tr) return;
|
|
1967
|
+
const [step] = tr.steps;
|
|
1968
|
+
if (tr.getMeta("hardbreak")) {
|
|
1969
|
+
if (!(step instanceof ReplaceStep)) return;
|
|
1970
|
+
const { from } = step;
|
|
1971
|
+
return newState.tr.setNodeMarkup(from, hardbreakSchema.type(ctx), void 0, []);
|
|
1972
|
+
}
|
|
1973
|
+
if (step instanceof AddMarkStep) {
|
|
1974
|
+
let _tr = newState.tr;
|
|
1975
|
+
const { from, to } = step;
|
|
1976
|
+
newState.doc.nodesBetween(from, to, (node, pos) => {
|
|
1977
|
+
if (node.type === hardbreakSchema.type(ctx)) _tr = _tr.setNodeMarkup(pos, hardbreakSchema.type(ctx), void 0, []);
|
|
1978
|
+
});
|
|
1979
|
+
return _tr;
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
});
|
|
1983
|
+
});
|
|
1984
|
+
withMeta(hardbreakClearMarkPlugin, {
|
|
1985
|
+
displayName: "Prose<hardbreakClearMarkPlugin>",
|
|
1986
|
+
group: "Prose"
|
|
1987
|
+
});
|
|
1988
|
+
//#endregion
|
|
1989
|
+
//#region src/plugin/hardbreak-filter-plugin.ts
|
|
1990
|
+
var hardbreakFilterNodes = $ctx(["table", "code_block"], "hardbreakFilterNodes");
|
|
1991
|
+
withMeta(hardbreakFilterNodes, {
|
|
1992
|
+
displayName: "Ctx<hardbreakFilterNodes>",
|
|
1993
|
+
group: "Prose"
|
|
1994
|
+
});
|
|
1995
|
+
var hardbreakFilterPlugin = $prose((ctx) => {
|
|
1996
|
+
const notIn = ctx.get(hardbreakFilterNodes.key);
|
|
1997
|
+
return new Plugin({
|
|
1998
|
+
key: new PluginKey("MILKDOWN_HARDBREAK_FILTER"),
|
|
1999
|
+
filterTransaction: (tr, state) => {
|
|
2000
|
+
const isInsertHr = tr.getMeta("hardbreak");
|
|
2001
|
+
const [step] = tr.steps;
|
|
2002
|
+
if (isInsertHr && step) {
|
|
2003
|
+
const { from } = step;
|
|
2004
|
+
const $from = state.doc.resolve(from);
|
|
2005
|
+
let curDepth = $from.depth;
|
|
2006
|
+
let canApply = true;
|
|
2007
|
+
while (curDepth > 0) {
|
|
2008
|
+
if (notIn.includes($from.node(curDepth).type.name)) canApply = false;
|
|
2009
|
+
curDepth--;
|
|
2010
|
+
}
|
|
2011
|
+
return canApply;
|
|
2012
|
+
}
|
|
2013
|
+
return true;
|
|
2014
|
+
}
|
|
2015
|
+
});
|
|
2016
|
+
});
|
|
2017
|
+
withMeta(hardbreakFilterPlugin, {
|
|
2018
|
+
displayName: "Prose<hardbreakFilterPlugin>",
|
|
2019
|
+
group: "Prose"
|
|
2020
|
+
});
|
|
2021
|
+
//#endregion
|
|
2022
|
+
//#region src/plugin/sync-heading-id-plugin.ts
|
|
2023
|
+
var syncHeadingIdPlugin = $prose((ctx) => {
|
|
2024
|
+
const headingIdPluginKey = new PluginKey("MILKDOWN_HEADING_ID");
|
|
2025
|
+
const updateId = (view) => {
|
|
2026
|
+
if (view.composing) return;
|
|
2027
|
+
const getId = ctx.get(headingIdGenerator.key);
|
|
2028
|
+
const tr = view.state.tr.setMeta("addToHistory", false);
|
|
2029
|
+
let found = false;
|
|
2030
|
+
const idMap = {};
|
|
2031
|
+
view.state.doc.descendants((node, pos) => {
|
|
2032
|
+
if (node.type === headingSchema.type(ctx)) {
|
|
2033
|
+
if (node.textContent.trim().length === 0) return;
|
|
2034
|
+
const attrs = node.attrs;
|
|
2035
|
+
let id = getId(node);
|
|
2036
|
+
if (idMap[id]) {
|
|
2037
|
+
idMap[id] += 1;
|
|
2038
|
+
id += `-#${idMap[id]}`;
|
|
2039
|
+
} else idMap[id] = 1;
|
|
2040
|
+
if (attrs.id !== id) {
|
|
2041
|
+
found = true;
|
|
2042
|
+
tr.setMeta(headingIdPluginKey, true).setNodeMarkup(pos, void 0, {
|
|
2043
|
+
...attrs,
|
|
2044
|
+
id
|
|
2045
|
+
});
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
});
|
|
2049
|
+
if (found) view.dispatch(tr);
|
|
2050
|
+
};
|
|
2051
|
+
return new Plugin({
|
|
2052
|
+
key: headingIdPluginKey,
|
|
2053
|
+
view: (view) => {
|
|
2054
|
+
updateId(view);
|
|
2055
|
+
return { update: (view, prevState) => {
|
|
2056
|
+
if (view.state.doc.eq(prevState.doc)) return;
|
|
2057
|
+
updateId(view);
|
|
2058
|
+
} };
|
|
2059
|
+
}
|
|
2060
|
+
});
|
|
2061
|
+
});
|
|
2062
|
+
withMeta(syncHeadingIdPlugin, {
|
|
2063
|
+
displayName: "Prose<syncHeadingIdPlugin>",
|
|
2064
|
+
group: "Prose"
|
|
2065
|
+
});
|
|
2066
|
+
//#endregion
|
|
2067
|
+
//#region src/plugin/sync-list-order-plugin.ts
|
|
2068
|
+
var syncListOrderPlugin = $prose((ctx) => {
|
|
2069
|
+
const syncOrderLabel = (transactions, _oldState, newState) => {
|
|
2070
|
+
if (!newState.selection || transactions.some((tr) => tr.getMeta("addToHistory") === false || !tr.isGeneric)) return null;
|
|
2071
|
+
const orderedListType = orderedListSchema.type(ctx);
|
|
2072
|
+
const bulletListType = bulletListSchema.type(ctx);
|
|
2073
|
+
const listItemType = listItemSchema.type(ctx);
|
|
2074
|
+
const handleNodeItem = (attrs, index, order = 1) => {
|
|
2075
|
+
let changed = false;
|
|
2076
|
+
const expectedLabel = `${index + order}.`;
|
|
2077
|
+
if (attrs.label !== expectedLabel) {
|
|
2078
|
+
attrs.label = expectedLabel;
|
|
2079
|
+
changed = true;
|
|
2080
|
+
}
|
|
2081
|
+
return changed;
|
|
2082
|
+
};
|
|
2083
|
+
let tr = newState.tr;
|
|
2084
|
+
let needDispatch = false;
|
|
2085
|
+
newState.doc.descendants((node, pos, parent, index) => {
|
|
2086
|
+
if (node.type === bulletListType) {
|
|
2087
|
+
const base = node.maybeChild(0);
|
|
2088
|
+
if (base?.type === listItemType && base.attrs.listType === "ordered") {
|
|
2089
|
+
needDispatch = true;
|
|
2090
|
+
tr.setNodeMarkup(pos, orderedListType, { spread: "true" });
|
|
2091
|
+
node.descendants((child, pos, _parent, index) => {
|
|
2092
|
+
if (child.type === listItemType) {
|
|
2093
|
+
const attrs = { ...child.attrs };
|
|
2094
|
+
if (handleNodeItem(attrs, index)) tr = tr.setNodeMarkup(pos, void 0, attrs);
|
|
2095
|
+
}
|
|
2096
|
+
return false;
|
|
2097
|
+
});
|
|
2098
|
+
}
|
|
2099
|
+
} else if (node.type === listItemType && parent?.type === orderedListType) {
|
|
2100
|
+
const attrs = { ...node.attrs };
|
|
2101
|
+
let changed = false;
|
|
2102
|
+
if (attrs.listType !== "ordered") {
|
|
2103
|
+
attrs.listType = "ordered";
|
|
2104
|
+
changed = true;
|
|
2105
|
+
}
|
|
2106
|
+
if (parent?.maybeChild(0)) changed = handleNodeItem(attrs, index, parent?.attrs.order ?? 1);
|
|
2107
|
+
if (changed) {
|
|
2108
|
+
tr = tr.setNodeMarkup(pos, void 0, attrs);
|
|
2109
|
+
needDispatch = true;
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
});
|
|
2113
|
+
return needDispatch ? tr.setMeta("addToHistory", false) : null;
|
|
2114
|
+
};
|
|
2115
|
+
return new Plugin({
|
|
2116
|
+
key: new PluginKey("MILKDOWN_KEEP_LIST_ORDER"),
|
|
2117
|
+
appendTransaction: syncOrderLabel
|
|
2118
|
+
});
|
|
2119
|
+
});
|
|
2120
|
+
withMeta(syncListOrderPlugin, {
|
|
2121
|
+
displayName: "Prose<syncListOrderPlugin>",
|
|
2122
|
+
group: "Prose"
|
|
2123
|
+
});
|
|
2124
|
+
//#endregion
|
|
2125
|
+
//#region src/composed/plugins.ts
|
|
2126
|
+
var plugins = [
|
|
2127
|
+
hardbreakClearMarkPlugin,
|
|
2128
|
+
hardbreakFilterNodes,
|
|
2129
|
+
hardbreakFilterPlugin,
|
|
2130
|
+
inlineNodesCursorPlugin,
|
|
2131
|
+
remarkAddOrderInListPlugin,
|
|
2132
|
+
remarkInlineLinkPlugin,
|
|
2133
|
+
remarkLineBreak,
|
|
2134
|
+
remarkHtmlTransformer,
|
|
2135
|
+
remarkMarker,
|
|
2136
|
+
remarkPreserveEmptyLinePlugin,
|
|
2137
|
+
syncHeadingIdPlugin,
|
|
2138
|
+
syncListOrderPlugin
|
|
2139
|
+
].flat();
|
|
2140
|
+
//#endregion
|
|
2141
|
+
//#region src/index.ts
|
|
2142
|
+
var commonmark = [
|
|
2143
|
+
schema,
|
|
2144
|
+
inputRules,
|
|
2145
|
+
markInputRules,
|
|
2146
|
+
commands,
|
|
2147
|
+
keymap,
|
|
2148
|
+
plugins
|
|
2149
|
+
].flat();
|
|
2150
|
+
//#endregion
|
|
2151
|
+
export { addBlockTypeCommand, blockquoteAttr, blockquoteKeymap, blockquoteSchema, bulletListAttr, bulletListKeymap, bulletListSchema, clearTextInCurrentBlockCommand, codeBlockAttr, codeBlockKeymap, codeBlockSchema, commands, commonmark, createCodeBlockCommand, createCodeBlockInputRule, docSchema, downgradeHeadingCommand, emphasisAttr, emphasisKeymap, emphasisSchema, emphasisStarInputRule, emphasisUnderscoreInputRule, hardbreakAttr, hardbreakClearMarkPlugin, hardbreakFilterNodes, hardbreakFilterPlugin, hardbreakKeymap, hardbreakSchema, headingAttr, headingIdGenerator, headingKeymap, headingSchema, hrAttr, hrSchema, htmlAttr, htmlSchema, imageAttr, imageSchema, inlineCodeAttr, inlineCodeInputRule, inlineCodeKeymap, inlineCodeSchema, inlineNodesCursorPlugin, inputRules, insertHardbreakCommand, insertHrCommand, insertHrInputRule, insertImageCommand, insertImageInputRule, isMarkSelectedCommand, isNodeSelectedCommand, keymap, liftFirstListItemCommand, liftListItemCommand, linkAttr, linkSchema, listItemAttr, listItemKeymap, listItemSchema, markInputRules, orderedListAttr, orderedListKeymap, orderedListSchema, paragraphAttr, paragraphKeymap, paragraphSchema, plugins, remarkAddOrderInListPlugin, remarkHtmlTransformer, remarkInlineLinkPlugin, remarkLineBreak, remarkMarker, remarkPreserveEmptyLinePlugin, schema, selectTextNearPosCommand, setBlockTypeCommand, sinkListItemCommand, splitListItemCommand, strongAttr, strongInputRule, strongKeymap, strongSchema, syncHeadingIdPlugin, syncListOrderPlugin, textSchema, toggleEmphasisCommand, toggleInlineCodeCommand, toggleLinkCommand, toggleStrongCommand, turnIntoTextCommand, updateCodeBlockLanguageCommand, updateImageCommand, updateLinkCommand, wrapInBlockTypeCommand, wrapInBlockquoteCommand, wrapInBlockquoteInputRule, wrapInBulletListCommand, wrapInBulletListInputRule, wrapInHeadingCommand, wrapInHeadingInputRule, wrapInOrderedListCommand, wrapInOrderedListInputRule };
|
|
2152
|
+
|
|
2153
|
+
//# sourceMappingURL=index.js.map
|