@milkdown/preset-commonmark 7.19.0 → 7.19.1

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