@milkdown/preset-commonmark 5.2.0 → 5.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/lib/index.es.js +1394 -0
  2. package/lib/index.es.js.map +1 -0
  3. package/lib/node/code-fence.d.ts +2 -0
  4. package/lib/node/code-fence.d.ts.map +1 -1
  5. package/lib/node/hardbreak.d.ts.map +1 -1
  6. package/lib/node/heading.d.ts.map +1 -1
  7. package/lib/node/image.d.ts.map +1 -1
  8. package/lib/node/list-item.d.ts.map +1 -1
  9. package/package.json +14 -19
  10. package/src/mark/code-inline.ts +5 -5
  11. package/src/node/bullet-list.ts +1 -1
  12. package/src/node/code-fence.ts +16 -6
  13. package/src/node/hardbreak.ts +2 -1
  14. package/src/node/heading.ts +1 -3
  15. package/src/node/image.ts +8 -4
  16. package/src/node/list-item.ts +1 -2
  17. package/src/node/ordered-list.ts +1 -1
  18. package/lib/index.js +0 -32
  19. package/lib/index.js.map +0 -1
  20. package/lib/mark/code-inline.js +0 -47
  21. package/lib/mark/code-inline.js.map +0 -1
  22. package/lib/mark/em.js +0 -41
  23. package/lib/mark/em.js.map +0 -1
  24. package/lib/mark/index.js +0 -11
  25. package/lib/mark/index.js.map +0 -1
  26. package/lib/mark/link.js +0 -110
  27. package/lib/mark/link.js.map +0 -1
  28. package/lib/mark/strong.js +0 -47
  29. package/lib/mark/strong.js.map +0 -1
  30. package/lib/node/blockquote.js +0 -47
  31. package/lib/node/blockquote.js.map +0 -1
  32. package/lib/node/bullet-list.js +0 -38
  33. package/lib/node/bullet-list.js.map +0 -1
  34. package/lib/node/code-fence.js +0 -288
  35. package/lib/node/code-fence.js.map +0 -1
  36. package/lib/node/doc.js +0 -24
  37. package/lib/node/doc.js.map +0 -1
  38. package/lib/node/hardbreak.js +0 -70
  39. package/lib/node/hardbreak.js.map +0 -1
  40. package/lib/node/heading.js +0 -89
  41. package/lib/node/heading.js.map +0 -1
  42. package/lib/node/hr.js +0 -63
  43. package/lib/node/hr.js.map +0 -1
  44. package/lib/node/image.js +0 -297
  45. package/lib/node/image.js.map +0 -1
  46. package/lib/node/index.js +0 -40
  47. package/lib/node/index.js.map +0 -1
  48. package/lib/node/list-item.js +0 -64
  49. package/lib/node/list-item.js.map +0 -1
  50. package/lib/node/ordered-list.js +0 -57
  51. package/lib/node/ordered-list.js.map +0 -1
  52. package/lib/node/paragraph.js +0 -52
  53. package/lib/node/paragraph.js.map +0 -1
  54. package/lib/node/text.js +0 -21
  55. package/lib/node/text.js.map +0 -1
  56. package/lib/plugin/filter-html.js +0 -32
  57. package/lib/plugin/filter-html.js.map +0 -1
  58. package/lib/plugin/index.js +0 -10
  59. package/lib/plugin/index.js.map +0 -1
  60. package/lib/supported-keys.js +0 -22
  61. package/lib/supported-keys.js.map +0 -1
@@ -0,0 +1,1394 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ import { createMark, createShortcut, createNode, createPlugin, AtomList } from "@milkdown/utils";
21
+ import { css } from "@emotion/css";
22
+ import { createCmdKey, createCmd, schemaCtx, themeToolCtx } from "@milkdown/core";
23
+ import { markRule, toggleMark, TextSelection, InputRule, wrappingInputRule, wrapIn, textblockTypeInputRule, setBlockType, Plugin, PluginKey, ReplaceStep, AddMarkStep, Selection, findSelectedNodeOfType, splitListItem, sinkListItem, liftListItem } from "@milkdown/prose";
24
+ import links from "remark-inline-links";
25
+ const SupportedKeys = {
26
+ HardBreak: "HardBreak",
27
+ Blockquote: "Blockquote",
28
+ BulletList: "BulletList",
29
+ OrderedList: "OrderedList",
30
+ CodeFence: "CodeFence",
31
+ H1: "H1",
32
+ H2: "H2",
33
+ H3: "H3",
34
+ H4: "H4",
35
+ H5: "H5",
36
+ H6: "H6",
37
+ Text: "Text",
38
+ CodeInline: "CodeInline",
39
+ Em: "Em",
40
+ Bold: "Bold",
41
+ NextListItem: "NextListItem",
42
+ SinkListItem: "SinkListItem",
43
+ LiftListItem: "LiftListItem"
44
+ };
45
+ const id$a = "code_inline";
46
+ const ToggleInlineCode = createCmdKey();
47
+ const codeInline = createMark((utils) => {
48
+ const style = utils.getStyle(({ palette, size, font }) => css`
49
+ background-color: ${palette("neutral")};
50
+ color: ${palette("background")};
51
+ border-radius: ${size.radius};
52
+ font-weight: 500;
53
+ font-family: ${font.code};
54
+ padding: 0 0.2rem;
55
+ `);
56
+ return {
57
+ id: id$a,
58
+ schema: () => ({
59
+ priority: 100,
60
+ code: true,
61
+ inclusive: false,
62
+ parseDOM: [{ tag: "code" }],
63
+ toDOM: (mark) => ["code", { class: utils.getClassName(mark.attrs, "code-inline", style) }],
64
+ parseMarkdown: {
65
+ match: (node) => node.type === "inlineCode",
66
+ runner: (state, node, markType) => {
67
+ state.openMark(markType);
68
+ state.addText(node.value);
69
+ state.closeMark(markType);
70
+ }
71
+ },
72
+ toMarkdown: {
73
+ match: (mark) => mark.type.name === id$a,
74
+ runner: (state, mark, node) => {
75
+ state.withMark(mark, "inlineCode", node.text || "");
76
+ }
77
+ }
78
+ }),
79
+ inputRules: (markType) => [markRule(/(?:^|[^`])(`([^`]+)`)$/, markType)],
80
+ commands: (markType) => [createCmd(ToggleInlineCode, () => toggleMark(markType))],
81
+ shortcuts: {
82
+ [SupportedKeys.CodeInline]: createShortcut(ToggleInlineCode, "Mod-e")
83
+ }
84
+ };
85
+ });
86
+ const id$9 = "em";
87
+ const ToggleItalic = createCmdKey();
88
+ const em = createMark((utils) => ({
89
+ id: id$9,
90
+ schema: () => ({
91
+ parseDOM: [
92
+ { tag: "i" },
93
+ { tag: "em" },
94
+ { style: "font-style", getAttrs: (value) => value === "italic" }
95
+ ],
96
+ toDOM: (mark) => ["em", { class: utils.getClassName(mark.attrs, id$9) }],
97
+ parseMarkdown: {
98
+ match: (node) => node.type === "emphasis",
99
+ runner: (state, node, markType) => {
100
+ state.openMark(markType);
101
+ state.next(node.children);
102
+ state.closeMark(markType);
103
+ }
104
+ },
105
+ toMarkdown: {
106
+ match: (mark) => mark.type.name === id$9,
107
+ runner: (state, mark) => {
108
+ state.withMark(mark, "emphasis");
109
+ }
110
+ }
111
+ }),
112
+ inputRules: (markType) => [
113
+ markRule(/(?:^|[^_])(_([^_]+)_)$/, markType),
114
+ markRule(/(?:^|[^*])(\*([^*]+)\*)$/, markType)
115
+ ],
116
+ commands: (markType) => [createCmd(ToggleItalic, () => toggleMark(markType))],
117
+ shortcuts: {
118
+ [SupportedKeys.Em]: createShortcut(ToggleItalic, "Mod-i")
119
+ }
120
+ }));
121
+ const ToggleLink = createCmdKey();
122
+ const ModifyLink = createCmdKey();
123
+ const id$8 = "link";
124
+ const link = createMark((utils) => {
125
+ const style = utils.getStyle((themeTool) => {
126
+ const lineColor = themeTool.palette("line");
127
+ return css`
128
+ color: ${themeTool.palette("secondary")};
129
+ cursor: pointer;
130
+ transition: all 0.4s ease-in-out;
131
+ font-weight: 500;
132
+ &:hover {
133
+ background-color: ${lineColor};
134
+ box-shadow: 0 0.2rem ${lineColor}, 0 -0.2rem ${lineColor};
135
+ }
136
+ `;
137
+ });
138
+ return {
139
+ id: id$8,
140
+ schema: () => ({
141
+ attrs: {
142
+ href: {},
143
+ title: { default: null }
144
+ },
145
+ inclusive: false,
146
+ parseDOM: [
147
+ {
148
+ tag: "a[href]",
149
+ getAttrs: (dom) => {
150
+ if (!(dom instanceof HTMLElement)) {
151
+ throw new Error();
152
+ }
153
+ return { href: dom.getAttribute("href"), title: dom.getAttribute("title") };
154
+ }
155
+ }
156
+ ],
157
+ toDOM: (mark) => ["a", __spreadProps(__spreadValues({}, mark.attrs), { class: utils.getClassName(mark.attrs, id$8, style) })],
158
+ parseMarkdown: {
159
+ match: (node) => node.type === "link",
160
+ runner: (state, node, markType) => {
161
+ const url = node.url;
162
+ const title = node.title;
163
+ state.openMark(markType, { href: url, title });
164
+ state.next(node.children);
165
+ state.closeMark(markType);
166
+ }
167
+ },
168
+ toMarkdown: {
169
+ match: (mark) => mark.type.name === id$8,
170
+ runner: (state, mark) => {
171
+ state.withMark(mark, "link", void 0, {
172
+ title: mark.attrs.title,
173
+ url: mark.attrs.href
174
+ });
175
+ }
176
+ }
177
+ }),
178
+ commands: (markType) => [
179
+ createCmd(ToggleLink, (href = "") => toggleMark(markType, { href })),
180
+ createCmd(ModifyLink, (href = "") => (state, dispatch) => {
181
+ if (!dispatch)
182
+ return false;
183
+ const { marks: marks2 } = state.schema;
184
+ let node;
185
+ let pos = -1;
186
+ const { selection } = state;
187
+ state.doc.nodesBetween(selection.from, selection.to, (n, p) => {
188
+ if (marks2.link.isInSet(n.marks)) {
189
+ node = n;
190
+ pos = p;
191
+ return false;
192
+ }
193
+ return;
194
+ });
195
+ if (!node)
196
+ return false;
197
+ const mark = node.marks.find(({ type }) => type === markType);
198
+ if (!mark)
199
+ return false;
200
+ const start = pos;
201
+ const end = pos + node.nodeSize;
202
+ const { tr } = state;
203
+ const linkMark = marks2.link.create(__spreadProps(__spreadValues({}, mark.attrs), { href }));
204
+ dispatch(tr.removeMark(start, end, mark).addMark(start, end, linkMark).setSelection(new TextSelection(tr.selection.$anchor)).scrollIntoView());
205
+ return true;
206
+ })
207
+ ],
208
+ inputRules: (markType, ctx) => [
209
+ new InputRule(/\[(?<text>.*?)]\((?<href>.*?)(?=“|\))"?(?<title>[^"]+)?"?\)/, (state, match, start, end) => {
210
+ const [okay, text2 = "", href, title] = match;
211
+ const { tr } = state;
212
+ if (okay) {
213
+ const content = text2 || "link";
214
+ tr.replaceWith(start, end, ctx.get(schemaCtx).text(content)).addMark(start, content.length + start, markType.create({ title, href }));
215
+ }
216
+ return tr;
217
+ })
218
+ ]
219
+ };
220
+ });
221
+ const id$7 = "strong";
222
+ const ToggleBold = createCmdKey();
223
+ const strong = createMark((utils) => {
224
+ const style = utils.getStyle(() => css`
225
+ font-weight: 600;
226
+ `);
227
+ return {
228
+ id: id$7,
229
+ schema: () => ({
230
+ parseDOM: [
231
+ { tag: "b" },
232
+ { tag: "strong" },
233
+ { style: "font-style", getAttrs: (value) => value === "bold" }
234
+ ],
235
+ toDOM: (mark) => ["strong", { class: utils.getClassName(mark.attrs, id$7, style) }],
236
+ parseMarkdown: {
237
+ match: (node) => node.type === "strong",
238
+ runner: (state, node, markType) => {
239
+ state.openMark(markType);
240
+ state.next(node.children);
241
+ state.closeMark(markType);
242
+ }
243
+ },
244
+ toMarkdown: {
245
+ match: (mark) => mark.type.name === id$7,
246
+ runner: (state, mark) => {
247
+ state.withMark(mark, "strong");
248
+ }
249
+ }
250
+ }),
251
+ inputRules: (markType) => [
252
+ markRule(/(?:__)([^_]+)(?:__)$/, markType),
253
+ markRule(/(?:\*\*)([^*]+)(?:\*\*)$/, markType)
254
+ ],
255
+ commands: (markType) => [createCmd(ToggleBold, () => toggleMark(markType))],
256
+ shortcuts: {
257
+ [SupportedKeys.Bold]: createShortcut(ToggleBold, "Mod-b")
258
+ }
259
+ };
260
+ });
261
+ const marks = [codeInline(), em(), strong(), link()];
262
+ const id$6 = "blockquote";
263
+ const WrapInBlockquote = createCmdKey();
264
+ const blockquote = createNode((utils) => {
265
+ const style = utils.getStyle((themeTool) => css`
266
+ padding-left: 1.875rem;
267
+ line-height: 1.75rem;
268
+ border-left: 4px solid ${themeTool.palette("primary")};
269
+ * {
270
+ font-size: 1rem;
271
+ line-height: 1.5rem;
272
+ }
273
+ `);
274
+ return {
275
+ id: id$6,
276
+ schema: () => ({
277
+ content: "block+",
278
+ group: "block",
279
+ defining: true,
280
+ parseDOM: [{ tag: "blockquote" }],
281
+ toDOM: (node) => ["blockquote", { class: utils.getClassName(node.attrs, id$6, style) }, 0],
282
+ parseMarkdown: {
283
+ match: ({ type }) => type === id$6,
284
+ runner: (state, node, type) => {
285
+ state.openNode(type).next(node.children).closeNode();
286
+ }
287
+ },
288
+ toMarkdown: {
289
+ match: (node) => node.type.name === id$6,
290
+ runner: (state, node) => {
291
+ state.openNode("blockquote").next(node.content).closeNode();
292
+ }
293
+ }
294
+ }),
295
+ inputRules: (nodeType) => [wrappingInputRule(/^\s*>\s$/, nodeType)],
296
+ commands: (nodeType) => [createCmd(WrapInBlockquote, () => wrapIn(nodeType))],
297
+ shortcuts: {
298
+ [SupportedKeys.Blockquote]: createShortcut(WrapInBlockquote, "Mod-Shift-b")
299
+ }
300
+ };
301
+ });
302
+ const WrapInBulletList = createCmdKey();
303
+ const bulletList = createNode((utils) => {
304
+ const id2 = "bullet_list";
305
+ return {
306
+ id: id2,
307
+ schema: () => ({
308
+ content: "listItem+",
309
+ group: "block",
310
+ parseDOM: [{ tag: "ul" }],
311
+ toDOM: (node) => {
312
+ return ["ul", { class: utils.getClassName(node.attrs, "bullet-list") }, 0];
313
+ },
314
+ parseMarkdown: {
315
+ match: ({ type, ordered }) => type === "list" && !ordered,
316
+ runner: (state, node, type) => {
317
+ state.openNode(type).next(node.children).closeNode();
318
+ }
319
+ },
320
+ toMarkdown: {
321
+ match: (node) => node.type.name === id2,
322
+ runner: (state, node) => {
323
+ state.openNode("list", void 0, { ordered: false }).next(node.content).closeNode();
324
+ }
325
+ }
326
+ }),
327
+ inputRules: (nodeType) => [wrappingInputRule(/^\s*([-+*])\s$/, nodeType)],
328
+ commands: (nodeType) => [createCmd(WrapInBulletList, () => wrapIn(nodeType))],
329
+ shortcuts: {
330
+ [SupportedKeys.BulletList]: createShortcut(WrapInBulletList, "Mod-Alt-8")
331
+ }
332
+ };
333
+ });
334
+ const languageOptions = [
335
+ "",
336
+ "javascript",
337
+ "typescript",
338
+ "bash",
339
+ "sql",
340
+ "json",
341
+ "html",
342
+ "css",
343
+ "c",
344
+ "cpp",
345
+ "java",
346
+ "ruby",
347
+ "python",
348
+ "go",
349
+ "rust",
350
+ "markdown"
351
+ ];
352
+ const backtickInputRegex = /^```(?<language>[a-z]*)?[\s\n]$/;
353
+ const tildeInputRegex = /^~~~(?<language>[a-z]*)?[\s\n]$/;
354
+ const TurnIntoCodeFence = createCmdKey();
355
+ const id$5 = "fence";
356
+ const codeFence = createNode((utils, options) => {
357
+ const style = utils.getStyle(({ palette, mixin, size, font }) => {
358
+ const { shadow, scrollbar, border } = mixin;
359
+ const { lineWidth, radius } = size;
360
+ return css`
361
+ background-color: ${palette("background")};
362
+ color: ${palette("neutral")};
363
+ font-size: 0.85rem;
364
+ padding: 1.2rem 0.4rem 1.4rem;
365
+ border-radius: ${radius};
366
+ font-family: ${font.typography};
367
+
368
+ * {
369
+ margin: 0;
370
+ }
371
+
372
+ .code-fence_select-wrapper {
373
+ position: relative;
374
+ }
375
+
376
+ .code-fence_value {
377
+ width: 10.25rem;
378
+ box-sizing: border-box;
379
+ border-radius: ${size.radius};
380
+ margin: 0 1.2rem 1.2rem;
381
+ ${border()};
382
+ ${shadow()};
383
+ cursor: pointer;
384
+ background-color: ${palette("surface")};
385
+ position: relative;
386
+ display: flex;
387
+ color: ${palette("neutral", 0.87)};
388
+ letter-spacing: 0.5px;
389
+ height: 2.625rem;
390
+ align-items: center;
391
+
392
+ & > .icon {
393
+ width: 2.625rem;
394
+ height: 100%;
395
+ display: flex;
396
+ justify-content: center;
397
+ align-items: center;
398
+ color: ${palette("solid", 0.87)};
399
+ border-left: ${lineWidth} solid ${palette("line")};
400
+
401
+ text-align: center;
402
+ transition: all 0.2s ease-in-out;
403
+ &:hover {
404
+ background: ${palette("background")};
405
+ color: ${palette("primary")};
406
+ }
407
+ }
408
+
409
+ > span:first-child {
410
+ padding-left: 1rem;
411
+ flex: 1;
412
+ font-weight: 500;
413
+ }
414
+ }
415
+
416
+ .code-fence_select-option {
417
+ list-style: none;
418
+ line-height: 2rem;
419
+ padding-left: 1rem;
420
+ cursor: pointer;
421
+ :hover {
422
+ background: ${palette("secondary", 0.12)};
423
+ color: ${palette("primary")};
424
+ }
425
+ }
426
+
427
+ .code-fence_select {
428
+ &[data-fold='true'] {
429
+ display: none;
430
+ }
431
+
432
+ font-weight: 500;
433
+ position: absolute;
434
+ z-index: 1;
435
+ top: 2.625rem;
436
+ box-sizing: border-box;
437
+ left: 1.2rem;
438
+ padding: 0.5rem 0;
439
+ max-height: 16.75rem;
440
+ width: 10.25rem;
441
+ ${border()};
442
+ ${shadow()};
443
+ background-color: ${palette("surface")};
444
+ border-top: none;
445
+ overflow-y: auto;
446
+ display: flex;
447
+ flex-direction: column;
448
+
449
+ ${scrollbar("y")}
450
+ }
451
+
452
+ code {
453
+ line-height: 1.5;
454
+ font-family: ${font.code};
455
+ }
456
+
457
+ pre {
458
+ font-family: ${font.code};
459
+ margin: 0 1.2rem !important;
460
+ }
461
+ `;
462
+ });
463
+ return {
464
+ id: id$5,
465
+ schema: () => ({
466
+ content: "text*",
467
+ group: "block",
468
+ marks: "",
469
+ defining: true,
470
+ code: true,
471
+ attrs: {
472
+ language: {
473
+ default: ""
474
+ },
475
+ fold: {
476
+ default: true
477
+ }
478
+ },
479
+ parseDOM: [
480
+ {
481
+ tag: "pre",
482
+ preserveWhitespace: "full",
483
+ getAttrs: (dom) => {
484
+ if (!(dom instanceof HTMLElement)) {
485
+ throw new Error("Parse DOM error.");
486
+ }
487
+ return { language: dom.dataset.language };
488
+ }
489
+ }
490
+ ],
491
+ toDOM: (node) => {
492
+ return [
493
+ "pre",
494
+ {
495
+ "data-language": node.attrs.language,
496
+ class: utils.getClassName(node.attrs, "code-fence", style)
497
+ },
498
+ ["code", { spellCheck: "false" }, 0]
499
+ ];
500
+ },
501
+ parseMarkdown: {
502
+ match: ({ type }) => type === "code",
503
+ runner: (state, node, type) => {
504
+ const language = node.lang;
505
+ const value = node.value;
506
+ state.openNode(type, { language });
507
+ if (value) {
508
+ state.addText(value);
509
+ }
510
+ state.closeNode();
511
+ }
512
+ },
513
+ toMarkdown: {
514
+ match: (node) => node.type.name === id$5,
515
+ runner: (state, node) => {
516
+ var _a;
517
+ state.addNode("code", void 0, ((_a = node.content.firstChild) == null ? void 0 : _a.text) || "", {
518
+ lang: node.attrs.language
519
+ });
520
+ }
521
+ }
522
+ }),
523
+ inputRules: (nodeType) => [
524
+ textblockTypeInputRule(backtickInputRegex, nodeType, (match) => {
525
+ const [ok, language] = match;
526
+ if (!ok)
527
+ return;
528
+ return { language };
529
+ }),
530
+ textblockTypeInputRule(tildeInputRegex, nodeType, (match) => {
531
+ const [ok, language] = match;
532
+ if (!ok)
533
+ return;
534
+ return { language };
535
+ })
536
+ ],
537
+ commands: (nodeType) => [createCmd(TurnIntoCodeFence, () => setBlockType(nodeType))],
538
+ shortcuts: {
539
+ [SupportedKeys.CodeFence]: createShortcut(TurnIntoCodeFence, "Mod-Alt-c")
540
+ },
541
+ view: (ctx) => (node, view, getPos) => {
542
+ const container = document.createElement("div");
543
+ const selectWrapper = document.createElement("div");
544
+ const select = document.createElement("ul");
545
+ const pre = document.createElement("pre");
546
+ const code = document.createElement("code");
547
+ const valueWrapper = document.createElement("div");
548
+ valueWrapper.className = "code-fence_value";
549
+ const value = document.createElement("span");
550
+ valueWrapper.appendChild(value);
551
+ if (view.editable) {
552
+ valueWrapper.appendChild(ctx.get(themeToolCtx).slots.icon("downArrow"));
553
+ }
554
+ select.className = "code-fence_select";
555
+ select.addEventListener("mousedown", (e) => {
556
+ e.preventDefault();
557
+ e.stopPropagation();
558
+ if (!view.editable)
559
+ return;
560
+ const el = e.target;
561
+ if (!(el instanceof HTMLLIElement))
562
+ return;
563
+ const { tr } = view.state;
564
+ view.dispatch(tr.setNodeMarkup(getPos(), void 0, {
565
+ fold: true,
566
+ language: el.dataset.value
567
+ }));
568
+ });
569
+ valueWrapper.addEventListener("mousedown", (e) => {
570
+ e.preventDefault();
571
+ e.stopPropagation();
572
+ if (!view.editable)
573
+ return;
574
+ const { tr } = view.state;
575
+ view.dispatch(tr.setNodeMarkup(getPos(), void 0, {
576
+ fold: false,
577
+ language: container.dataset.language
578
+ }));
579
+ });
580
+ document.addEventListener("mousedown", () => {
581
+ if (!view.editable || select.dataset.fold === "true")
582
+ return;
583
+ const { tr } = view.state;
584
+ view.dispatch(tr.setNodeMarkup(getPos(), void 0, {
585
+ fold: true,
586
+ language: container.dataset.language
587
+ }));
588
+ });
589
+ ((options == null ? void 0 : options.languageList) || languageOptions).forEach((lang) => {
590
+ const option = document.createElement("li");
591
+ option.className = "code-fence_select-option";
592
+ option.innerText = lang || "--";
593
+ select.appendChild(option);
594
+ option.setAttribute("data-value", lang);
595
+ });
596
+ code.spellcheck = false;
597
+ selectWrapper.className = "code-fence_select-wrapper";
598
+ selectWrapper.contentEditable = "false";
599
+ selectWrapper.append(valueWrapper);
600
+ selectWrapper.append(select);
601
+ pre.append(code);
602
+ const codeContent = document.createElement("div");
603
+ code.append(codeContent);
604
+ codeContent.style.whiteSpace = "inherit";
605
+ container.append(selectWrapper, pre);
606
+ container.setAttribute("class", utils.getClassName(node.attrs, "code-fence", style));
607
+ container.setAttribute("data-language", node.attrs.language);
608
+ value.innerText = node.attrs.language || "--";
609
+ select.setAttribute("data-fold", node.attrs.fold ? "true" : "false");
610
+ return {
611
+ dom: container,
612
+ contentDOM: codeContent,
613
+ update: (updatedNode) => {
614
+ if (updatedNode.type.name !== id$5)
615
+ return false;
616
+ const lang = updatedNode.attrs.language;
617
+ container.dataset.language = lang;
618
+ value.innerText = lang || "--";
619
+ select.setAttribute("data-fold", updatedNode.attrs.fold ? "true" : "false");
620
+ return true;
621
+ }
622
+ };
623
+ }
624
+ };
625
+ });
626
+ const doc = createNode(() => {
627
+ return {
628
+ id: "doc",
629
+ schema: () => ({
630
+ content: "block+",
631
+ parseMarkdown: {
632
+ match: ({ type }) => type === "root",
633
+ runner: (state, node, type) => {
634
+ state.injectRoot(node, type);
635
+ }
636
+ },
637
+ toMarkdown: {
638
+ match: (node) => node.type.name === "doc",
639
+ runner: (state, node) => {
640
+ state.openNode("root");
641
+ state.next(node.content);
642
+ }
643
+ }
644
+ })
645
+ };
646
+ });
647
+ const InsertHardbreak = createCmdKey();
648
+ const hardbreak = createNode((utils) => {
649
+ return {
650
+ id: "hardbreak",
651
+ schema: () => ({
652
+ inline: true,
653
+ group: "inline",
654
+ selectable: false,
655
+ parseDOM: [{ tag: "br" }],
656
+ toDOM: (node) => ["br", { class: utils.getClassName(node.attrs, "hardbreak") }],
657
+ parseMarkdown: {
658
+ match: ({ type }) => type === "break",
659
+ runner: (state, _, type) => {
660
+ state.addNode(type);
661
+ }
662
+ },
663
+ toMarkdown: {
664
+ match: (node) => node.type.name === "hardbreak",
665
+ runner: (state) => {
666
+ state.addNode("break");
667
+ }
668
+ }
669
+ }),
670
+ commands: (type) => [
671
+ createCmd(InsertHardbreak, () => (state, dispatch) => {
672
+ dispatch == null ? void 0 : dispatch(state.tr.setMeta("hardbreak", true).replaceSelectionWith(type.create()).scrollIntoView());
673
+ return true;
674
+ })
675
+ ],
676
+ shortcuts: {
677
+ [SupportedKeys.HardBreak]: createShortcut(InsertHardbreak, "Shift-Enter")
678
+ },
679
+ prosePlugins: (type) => [
680
+ new Plugin({
681
+ key: new PluginKey("hardbreak-marks"),
682
+ appendTransaction: (trs, _oldState, newState) => {
683
+ if (!trs.length)
684
+ return;
685
+ const [tr] = trs;
686
+ const [step] = tr.steps;
687
+ const isInsertHr = tr.getMeta("hardbreak");
688
+ if (isInsertHr) {
689
+ if (!(step instanceof ReplaceStep)) {
690
+ return;
691
+ }
692
+ const { from } = step;
693
+ return newState.tr.setNodeMarkup(from, type, void 0, []);
694
+ }
695
+ const isAddMarkStep = step instanceof AddMarkStep;
696
+ if (isAddMarkStep) {
697
+ let _tr = newState.tr;
698
+ const { from, to } = step;
699
+ newState.doc.nodesBetween(from, to, (node, pos) => {
700
+ if (node.type === type) {
701
+ _tr = _tr.setNodeMarkup(pos, type, void 0, []);
702
+ }
703
+ });
704
+ return _tr;
705
+ }
706
+ return;
707
+ }
708
+ })
709
+ ]
710
+ };
711
+ });
712
+ const headingIndex = Array(6).fill(0).map((_, i) => i + 1);
713
+ const TurnIntoHeading = createCmdKey();
714
+ const heading = createNode((utils, options) => {
715
+ const id2 = "heading";
716
+ const headingMap = {
717
+ 1: css`
718
+ font-size: 3rem;
719
+ line-height: 3.5rem;
720
+ `,
721
+ 2: css`
722
+ font-size: 2.125rem;
723
+ line-height: 2.25rem;
724
+ `,
725
+ 3: css`
726
+ font-size: 1.5rem;
727
+ line-height: 1.5rem;
728
+ `
729
+ };
730
+ const style = (level) => (options == null ? void 0 : options.headless) ? null : css`
731
+ ${headingMap[level] || ""}
732
+ margin: 2.5rem 0 !important;
733
+ font-weight: 400;
734
+ `;
735
+ return {
736
+ id: id2,
737
+ schema: () => ({
738
+ content: "inline*",
739
+ group: "block",
740
+ defining: true,
741
+ attrs: {
742
+ level: {
743
+ default: 1
744
+ }
745
+ },
746
+ parseDOM: headingIndex.map((x) => ({ tag: `h${x}`, attrs: { level: x } })),
747
+ toDOM: (node) => {
748
+ return [
749
+ `h${node.attrs.level}`,
750
+ {
751
+ class: utils.getClassName(node.attrs, `heading h${node.attrs.level}`, style(node.attrs.level))
752
+ },
753
+ 0
754
+ ];
755
+ },
756
+ parseMarkdown: {
757
+ match: ({ type }) => type === id2,
758
+ runner: (state, node, type) => {
759
+ const depth = node.depth;
760
+ state.openNode(type, { level: depth });
761
+ state.next(node.children);
762
+ state.closeNode();
763
+ }
764
+ },
765
+ toMarkdown: {
766
+ match: (node) => node.type.name === id2,
767
+ runner: (state, node) => {
768
+ state.openNode("heading", void 0, { depth: node.attrs.level });
769
+ state.next(node.content);
770
+ state.closeNode();
771
+ }
772
+ }
773
+ }),
774
+ inputRules: (type) => headingIndex.map((x) => textblockTypeInputRule(new RegExp(`^(#{1,${x}})\\s$`), type, () => ({
775
+ level: x
776
+ }))),
777
+ commands: (type) => [createCmd(TurnIntoHeading, (level = 1) => setBlockType(type, { level }))],
778
+ shortcuts: {
779
+ [SupportedKeys.H1]: createShortcut(TurnIntoHeading, "Mod-Alt-1", 1),
780
+ [SupportedKeys.H2]: createShortcut(TurnIntoHeading, "Mod-Alt-2", 2),
781
+ [SupportedKeys.H3]: createShortcut(TurnIntoHeading, "Mod-Alt-3", 3),
782
+ [SupportedKeys.H4]: createShortcut(TurnIntoHeading, "Mod-Alt-4", 4),
783
+ [SupportedKeys.H5]: createShortcut(TurnIntoHeading, "Mod-Alt-5", 5),
784
+ [SupportedKeys.H6]: createShortcut(TurnIntoHeading, "Mod-Alt-6", 6)
785
+ }
786
+ };
787
+ });
788
+ const id$4 = "hr";
789
+ const InsertHr = createCmdKey();
790
+ const hr = createNode((utils) => {
791
+ const style = utils.getStyle((themeTool) => css`
792
+ height: ${themeTool.size.lineWidth};
793
+ background-color: ${themeTool.palette("line")};
794
+ border-width: 0;
795
+ `);
796
+ return {
797
+ id: id$4,
798
+ schema: () => ({
799
+ group: "block",
800
+ parseDOM: [{ tag: "hr" }],
801
+ toDOM: (node) => ["hr", { class: utils.getClassName(node.attrs, id$4, style) }],
802
+ parseMarkdown: {
803
+ match: ({ type }) => type === "thematicBreak",
804
+ runner: (state, _, type) => {
805
+ state.addNode(type);
806
+ }
807
+ },
808
+ toMarkdown: {
809
+ match: (node) => node.type.name === id$4,
810
+ runner: (state) => {
811
+ state.addNode("thematicBreak");
812
+ }
813
+ }
814
+ }),
815
+ inputRules: (type) => [
816
+ new InputRule(/^(?:---|___\s|\*\*\*\s)$/, (state, match, start, end) => {
817
+ const { tr } = state;
818
+ if (match[0]) {
819
+ tr.replaceWith(start - 1, end, type.create());
820
+ }
821
+ return tr;
822
+ })
823
+ ],
824
+ commands: (type, ctx) => [
825
+ createCmd(InsertHr, () => (state, dispatch) => {
826
+ if (!dispatch)
827
+ return true;
828
+ const { tr, selection } = state;
829
+ const from = selection.from;
830
+ const node = type.create();
831
+ if (!node) {
832
+ return true;
833
+ }
834
+ const _tr = tr.replaceSelectionWith(node).insert(from, ctx.get(schemaCtx).node("paragraph"));
835
+ const sel = Selection.findFrom(_tr.doc.resolve(from), 1, true);
836
+ if (!sel) {
837
+ return true;
838
+ }
839
+ dispatch(_tr.setSelection(sel).scrollIntoView());
840
+ return true;
841
+ })
842
+ ]
843
+ };
844
+ });
845
+ const ModifyImage = createCmdKey();
846
+ const InsertImage = createCmdKey();
847
+ const id$3 = "image";
848
+ const image = createNode((utils, options) => {
849
+ var _a, _b;
850
+ const placeholder = __spreadValues({
851
+ loading: "Loading...",
852
+ empty: "Add an Image",
853
+ failed: "Image loads failed"
854
+ }, (_a = options == null ? void 0 : options.placeholder) != null ? _a : {});
855
+ const isBlock = (_b = options == null ? void 0 : options.isBlock) != null ? _b : false;
856
+ const containerStyle = utils.getStyle((themeTool) => css`
857
+ display: inline-block;
858
+ position: relative;
859
+ text-align: center;
860
+ font-size: 0;
861
+ vertical-align: text-bottom;
862
+ line-height: 1;
863
+
864
+ ${isBlock ? `
865
+ width: 100%;
866
+ margin: 0 auto;
867
+ ` : ""}
868
+
869
+ &.ProseMirror-selectednode::after {
870
+ content: '';
871
+ background: ${themeTool.palette("secondary", 0.38)};
872
+ position: absolute;
873
+ top: 0;
874
+ left: 0;
875
+ right: 0;
876
+ bottom: 0;
877
+ }
878
+
879
+ img {
880
+ max-width: 100%;
881
+ height: auto;
882
+ object-fit: contain;
883
+ margin: 0 2px;
884
+ }
885
+ .icon,
886
+ .placeholder {
887
+ display: none;
888
+ }
889
+
890
+ &.system {
891
+ width: 100%;
892
+ padding: 0 2rem;
893
+
894
+ img {
895
+ width: 0;
896
+ height: 0;
897
+ display: none;
898
+ }
899
+
900
+ .icon,
901
+ .placeholder {
902
+ display: inline;
903
+ }
904
+
905
+ box-sizing: border-box;
906
+ height: 3rem;
907
+ background-color: ${themeTool.palette("background")};
908
+ border-radius: ${themeTool.size.radius};
909
+ display: inline-flex;
910
+ gap: 2rem;
911
+ justify-content: flex-start;
912
+ align-items: center;
913
+ .placeholder {
914
+ margin: 0;
915
+ line-height: 1;
916
+ &::before {
917
+ content: '';
918
+ font-size: 0.875rem;
919
+ color: ${themeTool.palette("neutral", 0.6)};
920
+ }
921
+ }
922
+ }
923
+
924
+ &.loading {
925
+ .placeholder {
926
+ &::before {
927
+ content: '${placeholder.loading}';
928
+ }
929
+ }
930
+ }
931
+
932
+ &.empty {
933
+ .placeholder {
934
+ &::before {
935
+ content: '${placeholder.empty}';
936
+ }
937
+ }
938
+ }
939
+
940
+ &.failed {
941
+ .placeholder {
942
+ &::before {
943
+ content: '${placeholder.failed}';
944
+ }
945
+ }
946
+ }
947
+ `);
948
+ const style = utils.getStyle(() => css`
949
+ display: inline-block;
950
+ margin: 0 auto;
951
+ object-fit: contain;
952
+ width: 100%;
953
+ position: relative;
954
+ height: auto;
955
+ text-align: center;
956
+ `);
957
+ return {
958
+ id: "image",
959
+ schema: () => ({
960
+ inline: true,
961
+ group: "inline",
962
+ selectable: true,
963
+ draggable: true,
964
+ marks: "",
965
+ atom: true,
966
+ defining: true,
967
+ isolating: true,
968
+ attrs: {
969
+ src: { default: "" },
970
+ alt: { default: null },
971
+ title: { default: null },
972
+ failed: { default: false },
973
+ loading: { default: true },
974
+ width: { default: null }
975
+ },
976
+ parseDOM: [
977
+ {
978
+ tag: "img[src]",
979
+ getAttrs: (dom) => {
980
+ if (!(dom instanceof HTMLElement)) {
981
+ throw new Error();
982
+ }
983
+ return {
984
+ failed: dom.classList.contains("failed"),
985
+ loading: dom.classList.contains("loading"),
986
+ src: dom.getAttribute("src") || "",
987
+ alt: dom.getAttribute("alt"),
988
+ title: dom.getAttribute("title") || dom.getAttribute("alt"),
989
+ width: dom.getAttribute("width")
990
+ };
991
+ }
992
+ }
993
+ ],
994
+ toDOM: (node) => {
995
+ return [
996
+ "img",
997
+ __spreadProps(__spreadValues({}, node.attrs), {
998
+ class: utils.getClassName(node.attrs, id$3, node.attrs.failed ? "failed" : "", node.attrs.loading ? "loading" : "", style)
999
+ })
1000
+ ];
1001
+ },
1002
+ parseMarkdown: {
1003
+ match: ({ type }) => type === id$3,
1004
+ runner: (state, node, type) => {
1005
+ const url = node.url;
1006
+ const alt = node.alt;
1007
+ const title = node.title;
1008
+ state.addNode(type, {
1009
+ src: url,
1010
+ alt,
1011
+ title
1012
+ });
1013
+ }
1014
+ },
1015
+ toMarkdown: {
1016
+ match: (node) => node.type.name === id$3,
1017
+ runner: (state, node) => {
1018
+ state.addNode("image", void 0, void 0, {
1019
+ title: node.attrs.title,
1020
+ url: node.attrs.src,
1021
+ alt: node.attrs.alt
1022
+ });
1023
+ }
1024
+ }
1025
+ }),
1026
+ commands: (type) => [
1027
+ createCmd(InsertImage, (src = "") => (state, dispatch) => {
1028
+ if (!dispatch)
1029
+ return true;
1030
+ const { tr } = state;
1031
+ const node = type.create({ src });
1032
+ if (!node) {
1033
+ return true;
1034
+ }
1035
+ const _tr = tr.replaceSelectionWith(node);
1036
+ dispatch(_tr.scrollIntoView());
1037
+ return true;
1038
+ }),
1039
+ createCmd(ModifyImage, (src = "") => (state, dispatch) => {
1040
+ const node = findSelectedNodeOfType(state.selection, type);
1041
+ if (!node)
1042
+ return false;
1043
+ const { tr } = state;
1044
+ dispatch == null ? void 0 : dispatch(tr.setNodeMarkup(node.pos, void 0, __spreadProps(__spreadValues({}, node.node.attrs), { loading: true, src })).scrollIntoView());
1045
+ return true;
1046
+ })
1047
+ ],
1048
+ inputRules: (type) => [
1049
+ new InputRule(/!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/, (state, match, start, end) => {
1050
+ const [okay, alt, src = "", title] = match;
1051
+ const { tr } = state;
1052
+ if (okay) {
1053
+ tr.replaceWith(start, end, type.create({ src, alt, title }));
1054
+ }
1055
+ return tr;
1056
+ })
1057
+ ],
1058
+ view: (ctx) => (node, view, getPos) => {
1059
+ const nodeType = node.type;
1060
+ const createIcon = ctx.get(themeToolCtx).slots.icon;
1061
+ const container = document.createElement("span");
1062
+ container.className = utils.getClassName(node.attrs, id$3, containerStyle);
1063
+ const content = document.createElement("img");
1064
+ container.append(content);
1065
+ let icon = createIcon("image");
1066
+ const placeholder2 = document.createElement("span");
1067
+ placeholder2.classList.add("placeholder");
1068
+ container.append(icon, placeholder2);
1069
+ const setIcon = (name) => {
1070
+ const nextIcon = createIcon(name);
1071
+ container.replaceChild(nextIcon, icon);
1072
+ icon = nextIcon;
1073
+ };
1074
+ const loadImage = (src2) => {
1075
+ container.classList.add("system", "loading");
1076
+ setIcon("loading");
1077
+ const img = document.createElement("img");
1078
+ img.src = src2;
1079
+ img.onerror = () => {
1080
+ const { tr } = view.state;
1081
+ const _tr = tr.setNodeMarkup(getPos(), nodeType, __spreadProps(__spreadValues({}, node.attrs), {
1082
+ src: src2,
1083
+ loading: false,
1084
+ failed: true
1085
+ }));
1086
+ view.dispatch(_tr);
1087
+ };
1088
+ img.onload = () => {
1089
+ const { tr } = view.state;
1090
+ const _tr = tr.setNodeMarkup(getPos(), nodeType, __spreadProps(__spreadValues({}, node.attrs), {
1091
+ width: img.width,
1092
+ src: src2,
1093
+ loading: false,
1094
+ failed: false
1095
+ }));
1096
+ view.dispatch(_tr);
1097
+ };
1098
+ };
1099
+ const { src, loading, title, alt, width } = node.attrs;
1100
+ content.src = src;
1101
+ content.title = title || alt;
1102
+ content.alt = alt;
1103
+ if (width) {
1104
+ content.width = width;
1105
+ }
1106
+ if (src.length === 0) {
1107
+ container.classList.add("system", "empty");
1108
+ setIcon("image");
1109
+ } else if (loading) {
1110
+ loadImage(src);
1111
+ }
1112
+ return {
1113
+ dom: container,
1114
+ update: (updatedNode) => {
1115
+ if (updatedNode.type.name !== id$3)
1116
+ return false;
1117
+ const { src: src2, alt: alt2, title: title2, loading: loading2, failed, width: width2 } = updatedNode.attrs;
1118
+ content.src = src2;
1119
+ content.alt = alt2;
1120
+ content.title = title2 || alt2;
1121
+ if (width2) {
1122
+ content.width = width2;
1123
+ }
1124
+ if (loading2) {
1125
+ loadImage(src2);
1126
+ return true;
1127
+ }
1128
+ if (failed) {
1129
+ container.classList.remove("loading", "empty");
1130
+ container.classList.add("system", "failed");
1131
+ setIcon("brokenImage");
1132
+ return true;
1133
+ }
1134
+ if (src2.length > 0) {
1135
+ container.classList.remove("system", "empty", "loading");
1136
+ return true;
1137
+ }
1138
+ container.classList.add("system", "empty");
1139
+ setIcon("image");
1140
+ return true;
1141
+ },
1142
+ selectNode: () => {
1143
+ container.classList.add("ProseMirror-selectednode");
1144
+ },
1145
+ deselectNode: () => {
1146
+ container.classList.remove("ProseMirror-selectednode");
1147
+ }
1148
+ };
1149
+ }
1150
+ };
1151
+ });
1152
+ const id$2 = "list_item";
1153
+ const SplitListItem = createCmdKey();
1154
+ const SinkListItem = createCmdKey();
1155
+ const LiftListItem = createCmdKey();
1156
+ const listItem = createNode((utils) => {
1157
+ const style = utils.getStyle((themeTool) => css`
1158
+ &,
1159
+ & > * {
1160
+ margin: 0.5rem 0;
1161
+ }
1162
+
1163
+ &,
1164
+ li {
1165
+ &::marker {
1166
+ color: ${themeTool.palette("primary")};
1167
+ }
1168
+ }
1169
+ `);
1170
+ return {
1171
+ id: id$2,
1172
+ schema: () => ({
1173
+ group: "listItem",
1174
+ content: "paragraph block*",
1175
+ defining: true,
1176
+ parseDOM: [{ tag: "li" }],
1177
+ toDOM: (node) => ["li", { class: utils.getClassName(node.attrs, "list-item", style) }, 0],
1178
+ parseMarkdown: {
1179
+ match: ({ type, checked }) => type === "listItem" && checked === null,
1180
+ runner: (state, node, type) => {
1181
+ state.openNode(type);
1182
+ state.next(node.children);
1183
+ state.closeNode();
1184
+ }
1185
+ },
1186
+ toMarkdown: {
1187
+ match: (node) => node.type.name === id$2,
1188
+ runner: (state, node) => {
1189
+ state.openNode("listItem");
1190
+ state.next(node.content);
1191
+ state.closeNode();
1192
+ }
1193
+ }
1194
+ }),
1195
+ inputRules: (nodeType) => [wrappingInputRule(/^\s*([-+*])\s$/, nodeType)],
1196
+ commands: (nodeType) => [
1197
+ createCmd(SplitListItem, () => splitListItem(nodeType)),
1198
+ createCmd(SinkListItem, () => sinkListItem(nodeType)),
1199
+ createCmd(LiftListItem, () => liftListItem(nodeType))
1200
+ ],
1201
+ shortcuts: {
1202
+ [SupportedKeys.NextListItem]: createShortcut(SplitListItem, "Enter"),
1203
+ [SupportedKeys.SinkListItem]: createShortcut(SinkListItem, "Mod-]"),
1204
+ [SupportedKeys.LiftListItem]: createShortcut(LiftListItem, "Mod-[")
1205
+ }
1206
+ };
1207
+ });
1208
+ const WrapInOrderedList = createCmdKey();
1209
+ const id$1 = "ordered_list";
1210
+ const orderedList = createNode((utils) => ({
1211
+ id: id$1,
1212
+ schema: () => ({
1213
+ content: "listItem+",
1214
+ group: "block",
1215
+ attrs: {
1216
+ order: {
1217
+ default: 1
1218
+ }
1219
+ },
1220
+ parseDOM: [
1221
+ {
1222
+ tag: "ol",
1223
+ getAttrs: (dom) => {
1224
+ if (!(dom instanceof HTMLElement)) {
1225
+ throw new Error();
1226
+ }
1227
+ return { order: dom.hasAttribute("start") ? Number(dom.getAttribute("start")) : 1 };
1228
+ }
1229
+ }
1230
+ ],
1231
+ toDOM: (node) => [
1232
+ "ol",
1233
+ __spreadProps(__spreadValues({}, node.attrs.order === 1 ? {} : node.attrs.order), {
1234
+ class: utils.getClassName(node.attrs, "ordered-list")
1235
+ }),
1236
+ 0
1237
+ ],
1238
+ parseMarkdown: {
1239
+ match: ({ type, ordered }) => type === "list" && !!ordered,
1240
+ runner: (state, node, type) => {
1241
+ state.openNode(type).next(node.children).closeNode();
1242
+ }
1243
+ },
1244
+ toMarkdown: {
1245
+ match: (node) => node.type.name === id$1,
1246
+ runner: (state, node) => {
1247
+ state.openNode("list", void 0, { ordered: true, start: 1 });
1248
+ state.next(node.content);
1249
+ state.closeNode();
1250
+ }
1251
+ }
1252
+ }),
1253
+ inputRules: (nodeType) => [
1254
+ wrappingInputRule(/^(\d+)\.\s$/, nodeType, (match) => ({ order: Number(match[1]) }), (match, node) => node.childCount + node.attrs.order === Number(match[1]))
1255
+ ],
1256
+ commands: (nodeType) => [createCmd(WrapInOrderedList, () => wrapIn(nodeType))],
1257
+ shortcuts: {
1258
+ [SupportedKeys.OrderedList]: createShortcut(WrapInOrderedList, "Mod-Alt-7")
1259
+ }
1260
+ }));
1261
+ const TurnIntoText = createCmdKey();
1262
+ const id = "paragraph";
1263
+ const paragraph = createNode((utils, options) => {
1264
+ const style = (options == null ? void 0 : options.headless) ? null : css`
1265
+ font-size: 1rem;
1266
+ line-height: 1.5;
1267
+ letter-spacing: 0.5px;
1268
+ `;
1269
+ return {
1270
+ id,
1271
+ schema: () => ({
1272
+ content: "inline*",
1273
+ group: "block",
1274
+ parseDOM: [{ tag: "p" }],
1275
+ toDOM: (node) => ["p", { class: utils.getClassName(node.attrs, id, style) }, 0],
1276
+ parseMarkdown: {
1277
+ match: (node) => node.type === "paragraph",
1278
+ runner: (state, node, type) => {
1279
+ state.openNode(type);
1280
+ if (node.children) {
1281
+ state.next(node.children);
1282
+ } else {
1283
+ state.addText(node.value);
1284
+ }
1285
+ state.closeNode();
1286
+ }
1287
+ },
1288
+ toMarkdown: {
1289
+ match: (node) => node.type.name === "paragraph",
1290
+ runner: (state, node) => {
1291
+ state.openNode("paragraph");
1292
+ state.next(node.content);
1293
+ state.closeNode();
1294
+ }
1295
+ }
1296
+ }),
1297
+ commands: (nodeType) => [createCmd(TurnIntoText, () => setBlockType(nodeType))],
1298
+ shortcuts: {
1299
+ [SupportedKeys.Text]: createShortcut(TurnIntoText, "Mod-Alt-0")
1300
+ }
1301
+ };
1302
+ });
1303
+ const text = createNode(() => ({
1304
+ id: "text",
1305
+ schema: () => ({
1306
+ group: "inline",
1307
+ parseMarkdown: {
1308
+ match: ({ type }) => type === "text",
1309
+ runner: (state, node) => {
1310
+ state.addText(node.value);
1311
+ }
1312
+ },
1313
+ toMarkdown: {
1314
+ match: (node) => node.type.name === "text",
1315
+ runner: (state, node) => {
1316
+ state.addNode("text", void 0, node.text);
1317
+ }
1318
+ }
1319
+ })
1320
+ }));
1321
+ const nodes = [
1322
+ doc(),
1323
+ paragraph(),
1324
+ hardbreak(),
1325
+ blockquote(),
1326
+ codeFence(),
1327
+ bulletList(),
1328
+ orderedList(),
1329
+ listItem(),
1330
+ heading(),
1331
+ hr(),
1332
+ image(),
1333
+ text()
1334
+ ];
1335
+ const isParent = (node) => !!node.children;
1336
+ const isHTML = (node) => node.type === "html";
1337
+ function flatMapWithDepth(ast, fn) {
1338
+ return transform(ast, 0, null)[0];
1339
+ function transform(node, index, parent) {
1340
+ if (isParent(node)) {
1341
+ const out = [];
1342
+ for (let i = 0, n = node.children.length; i < n; i++) {
1343
+ const xs = transform(node.children[i], i, node);
1344
+ if (xs) {
1345
+ for (let j = 0, m = xs.length; j < m; j++) {
1346
+ out.push(xs[j]);
1347
+ }
1348
+ }
1349
+ }
1350
+ node.children = out;
1351
+ }
1352
+ return fn(node, index, parent);
1353
+ }
1354
+ }
1355
+ const filterHTMLPlugin = () => {
1356
+ function transformer(tree) {
1357
+ flatMapWithDepth(tree, (node) => {
1358
+ if (!isHTML(node)) {
1359
+ return [node];
1360
+ }
1361
+ return [];
1362
+ });
1363
+ }
1364
+ return transformer;
1365
+ };
1366
+ const commonmarkPlugins = [
1367
+ createPlugin(() => ({
1368
+ remarkPlugins: () => [links, filterHTMLPlugin]
1369
+ }))()
1370
+ ];
1371
+ const commonmarkNodes = AtomList.create([...nodes, ...marks]);
1372
+ const commonmark = AtomList.create([...commonmarkPlugins, ...commonmarkNodes]);
1373
+ const commands = {
1374
+ ToggleInlineCode,
1375
+ ToggleItalic,
1376
+ ToggleLink,
1377
+ ToggleBold,
1378
+ ModifyLink,
1379
+ ModifyImage,
1380
+ WrapInBlockquote,
1381
+ WrapInBulletList,
1382
+ WrapInOrderedList,
1383
+ TurnIntoCodeFence,
1384
+ TurnIntoHeading,
1385
+ TurnIntoText,
1386
+ InsertHardbreak,
1387
+ InsertHr,
1388
+ InsertImage,
1389
+ SplitListItem,
1390
+ SinkListItem,
1391
+ LiftListItem
1392
+ };
1393
+ export { InsertHardbreak, InsertHr, InsertImage, LiftListItem, ModifyImage, ModifyLink, SinkListItem, SplitListItem, SupportedKeys, ToggleBold, ToggleInlineCode, ToggleItalic, ToggleLink, TurnIntoCodeFence, TurnIntoHeading, TurnIntoText, WrapInBlockquote, WrapInBulletList, WrapInOrderedList, backtickInputRegex, blockquote, bulletList, codeFence, codeInline, commands, commonmark, commonmarkNodes, commonmarkPlugins, doc, em, hardbreak, heading, hr, image, link, listItem, marks, nodes, orderedList, paragraph, strong, text, tildeInputRegex };
1394
+ //# sourceMappingURL=index.es.js.map