@milkdown/preset-commonmark 5.1.1 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/lib/index.cjs.js +261 -0
  2. package/lib/index.cjs.js.map +1 -0
  3. package/lib/index.es.js +1389 -0
  4. package/lib/index.es.js.map +1 -0
  5. package/lib/node/code-fence.d.ts +2 -0
  6. package/lib/node/code-fence.d.ts.map +1 -1
  7. package/lib/node/hardbreak.d.ts.map +1 -1
  8. package/lib/node/image.d.ts.map +1 -1
  9. package/lib/node/list-item.d.ts.map +1 -1
  10. package/package.json +19 -12
  11. package/src/node/code-fence.ts +16 -10
  12. package/src/node/hardbreak.ts +26 -6
  13. package/src/node/image.ts +20 -2
  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 -57
  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,1389 @@
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
+ & > *:last-child {
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
+ valueWrapper.appendChild(ctx.get(themeToolCtx).slots.icon("downArrow"));
551
+ select.className = "code-fence_select";
552
+ select.addEventListener("mousedown", (e) => {
553
+ e.preventDefault();
554
+ e.stopPropagation();
555
+ if (!view.editable)
556
+ return;
557
+ const el = e.target;
558
+ if (!(el instanceof HTMLLIElement))
559
+ return;
560
+ const { tr } = view.state;
561
+ view.dispatch(tr.setNodeMarkup(getPos(), void 0, {
562
+ fold: true,
563
+ language: el.dataset.value
564
+ }));
565
+ });
566
+ valueWrapper.addEventListener("mousedown", (e) => {
567
+ e.preventDefault();
568
+ e.stopPropagation();
569
+ if (!view.editable)
570
+ return;
571
+ const { tr } = view.state;
572
+ view.dispatch(tr.setNodeMarkup(getPos(), void 0, {
573
+ fold: false,
574
+ language: container.dataset.language
575
+ }));
576
+ });
577
+ document.addEventListener("mousedown", () => {
578
+ if (!view.editable || select.dataset.fold === "true")
579
+ return;
580
+ const { tr } = view.state;
581
+ view.dispatch(tr.setNodeMarkup(getPos(), void 0, {
582
+ fold: true,
583
+ language: container.dataset.language
584
+ }));
585
+ });
586
+ ((options == null ? void 0 : options.languageList) || languageOptions).forEach((lang) => {
587
+ const option = document.createElement("li");
588
+ option.className = "code-fence_select-option";
589
+ option.innerText = lang || "--";
590
+ select.appendChild(option);
591
+ option.setAttribute("data-value", lang);
592
+ });
593
+ code.spellcheck = false;
594
+ selectWrapper.className = "code-fence_select-wrapper";
595
+ selectWrapper.contentEditable = "false";
596
+ selectWrapper.append(valueWrapper);
597
+ selectWrapper.append(select);
598
+ pre.append(code);
599
+ const codeContent = document.createElement("div");
600
+ code.append(codeContent);
601
+ codeContent.style.whiteSpace = "inherit";
602
+ container.append(selectWrapper, pre);
603
+ container.setAttribute("class", utils.getClassName(node.attrs, "code-fence", style));
604
+ container.setAttribute("data-language", node.attrs.language);
605
+ value.innerText = node.attrs.language || "--";
606
+ select.setAttribute("data-fold", node.attrs.fold ? "true" : "false");
607
+ return {
608
+ dom: container,
609
+ contentDOM: codeContent,
610
+ update: (updatedNode) => {
611
+ if (updatedNode.type.name !== id$5)
612
+ return false;
613
+ const lang = updatedNode.attrs.language;
614
+ container.dataset.language = lang;
615
+ value.innerText = lang || "--";
616
+ select.setAttribute("data-fold", updatedNode.attrs.fold ? "true" : "false");
617
+ return true;
618
+ }
619
+ };
620
+ }
621
+ };
622
+ });
623
+ const doc = createNode(() => {
624
+ return {
625
+ id: "doc",
626
+ schema: () => ({
627
+ content: "block+",
628
+ parseMarkdown: {
629
+ match: ({ type }) => type === "root",
630
+ runner: (state, node, type) => {
631
+ state.injectRoot(node, type);
632
+ }
633
+ },
634
+ toMarkdown: {
635
+ match: (node) => node.type.name === "doc",
636
+ runner: (state, node) => {
637
+ state.openNode("root");
638
+ state.next(node.content);
639
+ }
640
+ }
641
+ })
642
+ };
643
+ });
644
+ const InsertHardbreak = createCmdKey();
645
+ const hardbreak = createNode((utils) => {
646
+ return {
647
+ id: "hardbreak",
648
+ schema: () => ({
649
+ inline: true,
650
+ group: "inline",
651
+ selectable: false,
652
+ parseDOM: [{ tag: "br" }],
653
+ toDOM: (node) => ["br", { class: utils.getClassName(node.attrs, "hardbreak") }],
654
+ parseMarkdown: {
655
+ match: ({ type }) => type === "break",
656
+ runner: (state, _, type) => {
657
+ state.addNode(type);
658
+ }
659
+ },
660
+ toMarkdown: {
661
+ match: (node) => node.type.name === "hardbreak",
662
+ runner: (state) => {
663
+ state.addNode("break");
664
+ }
665
+ }
666
+ }),
667
+ commands: (type) => [
668
+ createCmd(InsertHardbreak, () => (state, dispatch) => {
669
+ dispatch == null ? void 0 : dispatch(state.tr.setMeta("hardbreak", true).replaceSelectionWith(type.create()).scrollIntoView());
670
+ return true;
671
+ })
672
+ ],
673
+ shortcuts: {
674
+ [SupportedKeys.HardBreak]: createShortcut(InsertHardbreak, "Shift-Enter")
675
+ },
676
+ prosePlugins: (type) => [
677
+ new Plugin({
678
+ key: new PluginKey("hardbreak-marks"),
679
+ appendTransaction: (trs, _oldState, newState) => {
680
+ if (!trs.length)
681
+ return;
682
+ const [tr] = trs;
683
+ const [step] = tr.steps;
684
+ const isInsertHr = tr.getMeta("hardbreak");
685
+ if (isInsertHr) {
686
+ if (!(step instanceof ReplaceStep)) {
687
+ return;
688
+ }
689
+ const { from } = step;
690
+ return newState.tr.setNodeMarkup(from, type, void 0, []);
691
+ }
692
+ const isAddMarkStep = step instanceof AddMarkStep;
693
+ if (isAddMarkStep) {
694
+ let _tr = newState.tr;
695
+ const { from, to } = step;
696
+ newState.doc.nodesBetween(from, to, (node, pos) => {
697
+ if (node.type === type) {
698
+ _tr = _tr.setNodeMarkup(pos, type, void 0, []);
699
+ }
700
+ });
701
+ return _tr;
702
+ }
703
+ return;
704
+ }
705
+ })
706
+ ]
707
+ };
708
+ });
709
+ const headingIndex = Array(6).fill(0).map((_, i) => i + 1);
710
+ const TurnIntoHeading = createCmdKey();
711
+ const heading = createNode((utils, options) => {
712
+ const id2 = "heading";
713
+ const headingMap = {
714
+ 1: css`
715
+ font-size: 3rem;
716
+ line-height: 3.5rem;
717
+ `,
718
+ 2: css`
719
+ font-size: 2.125rem;
720
+ line-height: 2.25rem;
721
+ `,
722
+ 3: css`
723
+ font-size: 1.5rem;
724
+ line-height: 1.5rem;
725
+ `
726
+ };
727
+ const style = (level) => (options == null ? void 0 : options.headless) ? null : css`
728
+ ${headingMap[level] || ""}
729
+ margin: 2.5rem 0 !important;
730
+ font-weight: 400;
731
+ `;
732
+ return {
733
+ id: id2,
734
+ schema: () => ({
735
+ content: "inline*",
736
+ group: "block",
737
+ attrs: {
738
+ level: {
739
+ default: 1
740
+ },
741
+ id: {
742
+ default: ""
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: 0 }
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") || 0
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
+ content.width = width;
1103
+ if (src.length === 0) {
1104
+ container.classList.add("system", "empty");
1105
+ setIcon("image");
1106
+ } else if (loading) {
1107
+ loadImage(src);
1108
+ }
1109
+ return {
1110
+ dom: container,
1111
+ update: (updatedNode) => {
1112
+ if (updatedNode.type.name !== id$3)
1113
+ return false;
1114
+ const { src: src2, alt: alt2, title: title2, loading: loading2, failed, width: width2 } = updatedNode.attrs;
1115
+ content.src = src2;
1116
+ content.alt = alt2;
1117
+ content.title = title2 || alt2;
1118
+ content.width = width2;
1119
+ if (loading2) {
1120
+ loadImage(src2);
1121
+ return true;
1122
+ }
1123
+ if (failed) {
1124
+ container.classList.remove("loading", "empty");
1125
+ container.classList.add("system", "failed");
1126
+ setIcon("brokenImage");
1127
+ return true;
1128
+ }
1129
+ if (src2.length > 0) {
1130
+ container.classList.remove("system", "empty", "loading");
1131
+ return true;
1132
+ }
1133
+ container.classList.add("system", "empty");
1134
+ setIcon("image");
1135
+ return true;
1136
+ },
1137
+ selectNode: () => {
1138
+ container.classList.add("ProseMirror-selectednode");
1139
+ },
1140
+ deselectNode: () => {
1141
+ container.classList.remove("ProseMirror-selectednode");
1142
+ }
1143
+ };
1144
+ }
1145
+ };
1146
+ });
1147
+ const id$2 = "list_item";
1148
+ const SplitListItem = createCmdKey();
1149
+ const SinkListItem = createCmdKey();
1150
+ const LiftListItem = createCmdKey();
1151
+ const listItem = createNode((utils) => {
1152
+ const style = utils.getStyle((themeTool) => css`
1153
+ &,
1154
+ & > * {
1155
+ margin: 0.5rem 0;
1156
+ }
1157
+
1158
+ &,
1159
+ li {
1160
+ &::marker {
1161
+ color: ${themeTool.palette("primary")};
1162
+ }
1163
+ }
1164
+ `);
1165
+ return {
1166
+ id: id$2,
1167
+ schema: () => ({
1168
+ group: "listItem",
1169
+ content: "paragraph block*",
1170
+ defining: true,
1171
+ parseDOM: [{ tag: "li" }],
1172
+ toDOM: (node) => ["li", { class: utils.getClassName(node.attrs, "list-item", style) }, 0],
1173
+ parseMarkdown: {
1174
+ match: ({ type, checked }) => type === "listItem" && checked === null,
1175
+ runner: (state, node, type) => {
1176
+ state.openNode(type);
1177
+ state.next(node.children);
1178
+ state.closeNode();
1179
+ }
1180
+ },
1181
+ toMarkdown: {
1182
+ match: (node) => node.type.name === id$2,
1183
+ runner: (state, node) => {
1184
+ state.openNode("listItem");
1185
+ state.next(node.content);
1186
+ state.closeNode();
1187
+ }
1188
+ }
1189
+ }),
1190
+ inputRules: (nodeType) => [wrappingInputRule(/^\s*([-+*])\s$/, nodeType)],
1191
+ commands: (nodeType) => [
1192
+ createCmd(SplitListItem, () => splitListItem(nodeType)),
1193
+ createCmd(SinkListItem, () => sinkListItem(nodeType)),
1194
+ createCmd(LiftListItem, () => liftListItem(nodeType))
1195
+ ],
1196
+ shortcuts: {
1197
+ [SupportedKeys.NextListItem]: createShortcut(SplitListItem, "Enter"),
1198
+ [SupportedKeys.SinkListItem]: createShortcut(SinkListItem, "Mod-]"),
1199
+ [SupportedKeys.LiftListItem]: createShortcut(LiftListItem, "Mod-[")
1200
+ }
1201
+ };
1202
+ });
1203
+ const WrapInOrderedList = createCmdKey();
1204
+ const id$1 = "ordered_list";
1205
+ const orderedList = createNode((utils) => ({
1206
+ id: id$1,
1207
+ schema: () => ({
1208
+ content: "listItem+",
1209
+ group: "block",
1210
+ attrs: {
1211
+ order: {
1212
+ default: 1
1213
+ }
1214
+ },
1215
+ parseDOM: [
1216
+ {
1217
+ tag: "ol",
1218
+ getAttrs: (dom) => {
1219
+ if (!(dom instanceof HTMLElement)) {
1220
+ throw new Error();
1221
+ }
1222
+ return { order: dom.hasAttribute("start") ? Number(dom.getAttribute("start")) : 1 };
1223
+ }
1224
+ }
1225
+ ],
1226
+ toDOM: (node) => [
1227
+ "ol",
1228
+ __spreadProps(__spreadValues({}, node.attrs.order === 1 ? {} : node.attrs.order), {
1229
+ class: utils.getClassName(node.attrs, "ordered-list")
1230
+ }),
1231
+ 0
1232
+ ],
1233
+ parseMarkdown: {
1234
+ match: ({ type, ordered }) => type === "list" && !!ordered,
1235
+ runner: (state, node, type) => {
1236
+ state.openNode(type).next(node.children).closeNode();
1237
+ }
1238
+ },
1239
+ toMarkdown: {
1240
+ match: (node) => node.type.name === id$1,
1241
+ runner: (state, node) => {
1242
+ state.openNode("list", void 0, { ordered: true, start: 1 });
1243
+ state.next(node.content);
1244
+ state.closeNode();
1245
+ }
1246
+ }
1247
+ }),
1248
+ inputRules: (nodeType) => [
1249
+ wrappingInputRule(/^(\d+)\.\s$/, nodeType, (match) => ({ order: Number(match[1]) }), (match, node) => node.childCount + node.attrs.order === Number(match[1]))
1250
+ ],
1251
+ commands: (nodeType) => [createCmd(WrapInOrderedList, () => wrapIn(nodeType))],
1252
+ shortcuts: {
1253
+ [SupportedKeys.OrderedList]: createShortcut(WrapInOrderedList, "Mod-Shift-7")
1254
+ }
1255
+ }));
1256
+ const TurnIntoText = createCmdKey();
1257
+ const id = "paragraph";
1258
+ const paragraph = createNode((utils, options) => {
1259
+ const style = (options == null ? void 0 : options.headless) ? null : css`
1260
+ font-size: 1rem;
1261
+ line-height: 1.5;
1262
+ letter-spacing: 0.5px;
1263
+ `;
1264
+ return {
1265
+ id,
1266
+ schema: () => ({
1267
+ content: "inline*",
1268
+ group: "block",
1269
+ parseDOM: [{ tag: "p" }],
1270
+ toDOM: (node) => ["p", { class: utils.getClassName(node.attrs, id, style) }, 0],
1271
+ parseMarkdown: {
1272
+ match: (node) => node.type === "paragraph",
1273
+ runner: (state, node, type) => {
1274
+ state.openNode(type);
1275
+ if (node.children) {
1276
+ state.next(node.children);
1277
+ } else {
1278
+ state.addText(node.value);
1279
+ }
1280
+ state.closeNode();
1281
+ }
1282
+ },
1283
+ toMarkdown: {
1284
+ match: (node) => node.type.name === "paragraph",
1285
+ runner: (state, node) => {
1286
+ state.openNode("paragraph");
1287
+ state.next(node.content);
1288
+ state.closeNode();
1289
+ }
1290
+ }
1291
+ }),
1292
+ commands: (nodeType) => [createCmd(TurnIntoText, () => setBlockType(nodeType))],
1293
+ shortcuts: {
1294
+ [SupportedKeys.Text]: createShortcut(TurnIntoText, "Mod-Alt-0")
1295
+ }
1296
+ };
1297
+ });
1298
+ const text = createNode(() => ({
1299
+ id: "text",
1300
+ schema: () => ({
1301
+ group: "inline",
1302
+ parseMarkdown: {
1303
+ match: ({ type }) => type === "text",
1304
+ runner: (state, node) => {
1305
+ state.addText(node.value);
1306
+ }
1307
+ },
1308
+ toMarkdown: {
1309
+ match: (node) => node.type.name === "text",
1310
+ runner: (state, node) => {
1311
+ state.addNode("text", void 0, node.text);
1312
+ }
1313
+ }
1314
+ })
1315
+ }));
1316
+ const nodes = [
1317
+ doc(),
1318
+ paragraph(),
1319
+ hardbreak(),
1320
+ blockquote(),
1321
+ codeFence(),
1322
+ bulletList(),
1323
+ orderedList(),
1324
+ listItem(),
1325
+ heading(),
1326
+ hr(),
1327
+ image(),
1328
+ text()
1329
+ ];
1330
+ const isParent = (node) => !!node.children;
1331
+ const isHTML = (node) => node.type === "html";
1332
+ function flatMapWithDepth(ast, fn) {
1333
+ return transform(ast, 0, null)[0];
1334
+ function transform(node, index, parent) {
1335
+ if (isParent(node)) {
1336
+ const out = [];
1337
+ for (let i = 0, n = node.children.length; i < n; i++) {
1338
+ const xs = transform(node.children[i], i, node);
1339
+ if (xs) {
1340
+ for (let j = 0, m = xs.length; j < m; j++) {
1341
+ out.push(xs[j]);
1342
+ }
1343
+ }
1344
+ }
1345
+ node.children = out;
1346
+ }
1347
+ return fn(node, index, parent);
1348
+ }
1349
+ }
1350
+ const filterHTMLPlugin = () => {
1351
+ function transformer(tree) {
1352
+ flatMapWithDepth(tree, (node) => {
1353
+ if (!isHTML(node)) {
1354
+ return [node];
1355
+ }
1356
+ return [];
1357
+ });
1358
+ }
1359
+ return transformer;
1360
+ };
1361
+ const commonmarkPlugins = [
1362
+ createPlugin(() => ({
1363
+ remarkPlugins: () => [links, filterHTMLPlugin]
1364
+ }))()
1365
+ ];
1366
+ const commonmarkNodes = AtomList.create([...nodes, ...marks]);
1367
+ const commonmark = AtomList.create([...commonmarkPlugins, ...commonmarkNodes]);
1368
+ const commands = {
1369
+ ToggleInlineCode,
1370
+ ToggleItalic,
1371
+ ToggleLink,
1372
+ ToggleBold,
1373
+ ModifyLink,
1374
+ ModifyImage,
1375
+ WrapInBlockquote,
1376
+ WrapInBulletList,
1377
+ WrapInOrderedList,
1378
+ TurnIntoCodeFence,
1379
+ TurnIntoHeading,
1380
+ TurnIntoText,
1381
+ InsertHardbreak,
1382
+ InsertHr,
1383
+ InsertImage,
1384
+ SplitListItem,
1385
+ SinkListItem,
1386
+ LiftListItem
1387
+ };
1388
+ 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 };
1389
+ //# sourceMappingURL=index.es.js.map