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