@milkdown/preset-commonmark 5.4.0 → 6.0.0-next.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 (90) hide show
  1. package/README.md +5 -4
  2. package/lib/index.d.ts +34 -1
  3. package/lib/index.d.ts.map +1 -0
  4. package/lib/index.es.js +320 -573
  5. package/lib/index.es.js.map +1 -1
  6. package/lib/{src/mark → mark}/code-inline.d.ts +1 -1
  7. package/lib/mark/code-inline.d.ts.map +1 -0
  8. package/lib/{src/mark → mark}/em.d.ts +1 -1
  9. package/lib/mark/em.d.ts.map +1 -0
  10. package/lib/mark/index.d.ts +6 -0
  11. package/lib/mark/index.d.ts.map +1 -0
  12. package/lib/{src/mark → mark}/link.d.ts +7 -1
  13. package/lib/mark/link.d.ts.map +1 -0
  14. package/lib/{src/mark → mark}/strong.d.ts +1 -1
  15. package/lib/mark/strong.d.ts.map +1 -0
  16. package/lib/{src/node → node}/blockquote.d.ts +1 -1
  17. package/lib/node/blockquote.d.ts.map +1 -0
  18. package/lib/{src/node → node}/bullet-list.d.ts +1 -1
  19. package/lib/node/bullet-list.d.ts.map +1 -0
  20. package/lib/{src/node → node}/code-fence.d.ts +1 -1
  21. package/lib/node/code-fence.d.ts.map +1 -0
  22. package/lib/{src/node → node}/doc.d.ts +1 -1
  23. package/lib/node/doc.d.ts.map +1 -0
  24. package/lib/{src/node → node}/hardbreak.d.ts +1 -1
  25. package/lib/node/hardbreak.d.ts.map +1 -0
  26. package/lib/{src/node → node}/heading.d.ts +1 -1
  27. package/lib/node/heading.d.ts.map +1 -0
  28. package/lib/{src/node → node}/hr.d.ts +1 -1
  29. package/lib/node/hr.d.ts.map +1 -0
  30. package/lib/{src/node → node}/image.d.ts +5 -5
  31. package/lib/node/image.d.ts.map +1 -0
  32. package/lib/{src/node → node}/index.d.ts +2 -2
  33. package/lib/node/index.d.ts.map +1 -0
  34. package/lib/{src/node → node}/list-item.d.ts +1 -1
  35. package/lib/node/list-item.d.ts.map +1 -0
  36. package/lib/{src/node → node}/ordered-list.d.ts +1 -1
  37. package/lib/node/ordered-list.d.ts.map +1 -0
  38. package/lib/{src/node → node}/paragraph.d.ts +1 -1
  39. package/lib/node/paragraph.d.ts.map +1 -0
  40. package/lib/{src/node → node}/text.d.ts +1 -1
  41. package/lib/node/text.d.ts.map +1 -0
  42. package/lib/{src/plugin → plugin}/filter-html.d.ts +0 -0
  43. package/lib/plugin/filter-html.d.ts.map +1 -0
  44. package/lib/plugin/index.d.ts +2 -0
  45. package/lib/plugin/index.d.ts.map +1 -0
  46. package/lib/{src/supported-keys.d.ts → supported-keys.d.ts} +0 -0
  47. package/lib/supported-keys.d.ts.map +1 -0
  48. package/package.json +33 -10
  49. package/src/mark/code-inline.ts +3 -14
  50. package/src/mark/em.ts +1 -1
  51. package/src/mark/link.ts +98 -24
  52. package/src/mark/strong.ts +2 -8
  53. package/src/node/blockquote.ts +2 -15
  54. package/src/node/bullet-list.ts +1 -1
  55. package/src/node/code-fence.ts +80 -188
  56. package/src/node/hardbreak.ts +3 -2
  57. package/src/node/heading.ts +15 -46
  58. package/src/node/hr.ts +2 -9
  59. package/src/node/image.ts +88 -240
  60. package/src/node/list-item.ts +37 -56
  61. package/src/node/ordered-list.ts +3 -3
  62. package/src/node/paragraph.ts +3 -11
  63. package/src/node/text.ts +1 -1
  64. package/src/plugin/filter-html.ts +10 -4
  65. package/lib/src/index.d.ts +0 -34
  66. package/lib/src/index.d.ts.map +0 -1
  67. package/lib/src/mark/code-inline.d.ts.map +0 -1
  68. package/lib/src/mark/em.d.ts.map +0 -1
  69. package/lib/src/mark/index.d.ts +0 -6
  70. package/lib/src/mark/index.d.ts.map +0 -1
  71. package/lib/src/mark/link.d.ts.map +0 -1
  72. package/lib/src/mark/strong.d.ts.map +0 -1
  73. package/lib/src/node/blockquote.d.ts.map +0 -1
  74. package/lib/src/node/bullet-list.d.ts.map +0 -1
  75. package/lib/src/node/code-fence.d.ts.map +0 -1
  76. package/lib/src/node/doc.d.ts.map +0 -1
  77. package/lib/src/node/hardbreak.d.ts.map +0 -1
  78. package/lib/src/node/heading.d.ts.map +0 -1
  79. package/lib/src/node/hr.d.ts.map +0 -1
  80. package/lib/src/node/image.d.ts.map +0 -1
  81. package/lib/src/node/index.d.ts.map +0 -1
  82. package/lib/src/node/list-item.d.ts.map +0 -1
  83. package/lib/src/node/ordered-list.d.ts.map +0 -1
  84. package/lib/src/node/paragraph.d.ts.map +0 -1
  85. package/lib/src/node/text.d.ts.map +0 -1
  86. package/lib/src/plugin/filter-html.d.ts.map +0 -1
  87. package/lib/src/plugin/index.d.ts +0 -2
  88. package/lib/src/plugin/index.d.ts.map +0 -1
  89. package/lib/src/supported-keys.d.ts.map +0 -1
  90. package/lib/src/types.d.ts +0 -5
package/lib/index.es.js CHANGED
@@ -4,7 +4,7 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
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;
7
+ var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
8
8
  var __spreadValues = (a, b) => {
9
9
  for (var prop in b || (b = {}))
10
10
  if (__hasOwnProp.call(b, prop))
@@ -18,8 +18,8 @@ var __spreadValues = (a, b) => {
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
  import { createMark, createShortcut, createNode, createPlugin, AtomList } from "@milkdown/utils";
21
- import { createCmdKey, createCmd, schemaCtx, themeToolCtx, editorViewCtx } from "@milkdown/core";
22
- import { markRule, toggleMark, TextSelection, InputRule, wrappingInputRule, wrapIn, textblockTypeInputRule, setBlockType, Plugin, PluginKey, ReplaceStep, AddMarkStep, Selection, findSelectedNodeOfType, splitListItem, sinkListItem, liftListItem } from "@milkdown/prose";
21
+ import { createCmdKey, createCmd, schemaCtx, commandsCtx, editorViewCtx } from "@milkdown/core";
22
+ import { markRule, toggleMark, PluginKey, TextSelection, InputRule, Plugin, wrappingInputRule, wrapIn, textblockTypeInputRule, setBlockType, ReplaceStep, AddMarkStep, Selection, findSelectedNodeOfType, splitListItem, sinkListItem, liftListItem } from "@milkdown/prose";
23
23
  import links from "remark-inline-links";
24
24
  const SupportedKeys = {
25
25
  HardBreak: "HardBreak",
@@ -42,16 +42,8 @@ const SupportedKeys = {
42
42
  LiftListItem: "LiftListItem"
43
43
  };
44
44
  const id$a = "code_inline";
45
- const ToggleInlineCode = createCmdKey();
45
+ const ToggleInlineCode = createCmdKey("ToggleInlineCode");
46
46
  const codeInline = createMark((utils) => {
47
- const style = utils.getStyle(({ palette, size, font }, { css }) => css`
48
- background-color: ${palette("neutral")};
49
- color: ${palette("background")};
50
- border-radius: ${size.radius};
51
- font-weight: 500;
52
- font-family: ${font.code};
53
- padding: 0 0.2rem;
54
- `);
55
47
  return {
56
48
  id: id$a,
57
49
  schema: () => ({
@@ -59,12 +51,12 @@ const codeInline = createMark((utils) => {
59
51
  code: true,
60
52
  inclusive: false,
61
53
  parseDOM: [{ tag: "code" }],
62
- toDOM: (mark) => ["code", { class: utils.getClassName(mark.attrs, "code-inline", style) }],
54
+ toDOM: (mark) => ["code", { class: utils.getClassName(mark.attrs, "code-inline") }],
63
55
  parseMarkdown: {
64
56
  match: (node) => node.type === "inlineCode",
65
57
  runner: (state, node, markType) => {
66
58
  state.openMark(markType);
67
- state.addText(node.value);
59
+ state.addText(node["value"]);
68
60
  state.closeMark(markType);
69
61
  }
70
62
  },
@@ -83,7 +75,7 @@ const codeInline = createMark((utils) => {
83
75
  };
84
76
  });
85
77
  const id$9 = "em";
86
- const ToggleItalic = createCmdKey();
78
+ const ToggleItalic = createCmdKey("ToggleItalic");
87
79
  const em = createMark((utils) => ({
88
80
  id: id$9,
89
81
  schema: () => ({
@@ -117,23 +109,11 @@ const em = createMark((utils) => ({
117
109
  [SupportedKeys.Em]: createShortcut(ToggleItalic, "Mod-i")
118
110
  }
119
111
  }));
120
- const ToggleLink = createCmdKey();
121
- const ModifyLink = createCmdKey();
112
+ const key$1 = new PluginKey("MILKDOWN_PLUGIN_LINK_INPUT");
113
+ const ToggleLink = createCmdKey("ToggleLink");
114
+ const ModifyLink = createCmdKey("ModifyLink");
122
115
  const id$8 = "link";
123
- const link = createMark((utils) => {
124
- const style = utils.getStyle((themeTool, { css }) => {
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
- });
116
+ const link = createMark((utils, options) => {
137
117
  return {
138
118
  id: id$8,
139
119
  schema: () => ({
@@ -153,12 +133,12 @@ const link = createMark((utils) => {
153
133
  }
154
134
  }
155
135
  ],
156
- toDOM: (mark) => ["a", __spreadProps(__spreadValues({}, mark.attrs), { class: utils.getClassName(mark.attrs, id$8, style) })],
136
+ toDOM: (mark) => ["a", __spreadProps(__spreadValues({}, mark.attrs), { class: utils.getClassName(mark.attrs, id$8) })],
157
137
  parseMarkdown: {
158
138
  match: (node) => node.type === "link",
159
139
  runner: (state, node, markType) => {
160
- const url = node.url;
161
- const title = node.title;
140
+ const url = node["url"];
141
+ const title = node["title"];
162
142
  state.openMark(markType, { href: url, title });
163
143
  state.next(node.children);
164
144
  state.closeMark(markType);
@@ -168,8 +148,8 @@ const link = createMark((utils) => {
168
148
  match: (mark) => mark.type.name === id$8,
169
149
  runner: (state, mark) => {
170
150
  state.withMark(mark, "link", void 0, {
171
- title: mark.attrs.title,
172
- url: mark.attrs.href
151
+ title: mark.attrs["title"],
152
+ url: mark.attrs["href"]
173
153
  });
174
154
  }
175
155
  }
@@ -214,15 +194,78 @@ const link = createMark((utils) => {
214
194
  }
215
195
  return tr;
216
196
  })
217
- ]
197
+ ],
198
+ prosePlugins: (type, ctx) => {
199
+ var _a, _b, _c;
200
+ const inputChipRenderer = utils.themeManager.get("input-chip", {
201
+ placeholder: (_b = (_a = options == null ? void 0 : options.input) == null ? void 0 : _a.placeholder) != null ? _b : "Input Web Link",
202
+ buttonText: (_c = options == null ? void 0 : options.input) == null ? void 0 : _c.buttonText,
203
+ onUpdate: (value) => {
204
+ ctx.get(commandsCtx).call(ModifyLink, value);
205
+ }
206
+ });
207
+ const shouldDisplay = (view) => {
208
+ const { selection, doc: doc2 } = view.state;
209
+ const { from, to } = selection;
210
+ return selection.empty && selection instanceof TextSelection && doc2.rangeHasMark(from, from === to ? to + 1 : to, type);
211
+ };
212
+ const getCurrentLink = (view) => {
213
+ const { selection } = view.state;
214
+ let node;
215
+ const { from, to } = selection;
216
+ view.state.doc.nodesBetween(from, from === to ? to + 1 : to, (n) => {
217
+ if (type.isInSet(n.marks)) {
218
+ node = n;
219
+ return false;
220
+ }
221
+ return;
222
+ });
223
+ if (!node)
224
+ return;
225
+ const mark = node.marks.find((m) => m.type === type);
226
+ if (!mark)
227
+ return;
228
+ const value = mark.attrs["href"];
229
+ return value;
230
+ };
231
+ const renderByView = (view) => {
232
+ if (!view.editable) {
233
+ return;
234
+ }
235
+ const display = shouldDisplay(view);
236
+ if (display) {
237
+ inputChipRenderer.show(view);
238
+ inputChipRenderer.update(getCurrentLink(view));
239
+ } else {
240
+ inputChipRenderer.hide();
241
+ }
242
+ };
243
+ return [
244
+ new Plugin({
245
+ key: key$1,
246
+ view: (editorView) => {
247
+ inputChipRenderer.init(editorView);
248
+ renderByView(editorView);
249
+ return {
250
+ update: (view, prevState) => {
251
+ const isEqualSelection = (prevState == null ? void 0 : prevState.doc.eq(view.state.doc)) && prevState.selection.eq(view.state.selection);
252
+ if (isEqualSelection)
253
+ return;
254
+ renderByView(view);
255
+ },
256
+ destroy: () => {
257
+ inputChipRenderer.destroy();
258
+ }
259
+ };
260
+ }
261
+ })
262
+ ];
263
+ }
218
264
  };
219
265
  });
220
266
  const id$7 = "strong";
221
- const ToggleBold = createCmdKey();
267
+ const ToggleBold = createCmdKey("ToggleBold");
222
268
  const strong = createMark((utils) => {
223
- const style = utils.getStyle((_, { css }) => css`
224
- font-weight: 600;
225
- `);
226
269
  return {
227
270
  id: id$7,
228
271
  schema: () => ({
@@ -231,7 +274,7 @@ const strong = createMark((utils) => {
231
274
  { tag: "strong" },
232
275
  { style: "font-style", getAttrs: (value) => value === "bold" }
233
276
  ],
234
- toDOM: (mark) => ["strong", { class: utils.getClassName(mark.attrs, id$7, style) }],
277
+ toDOM: (mark) => ["strong", { class: utils.getClassName(mark.attrs, id$7) }],
235
278
  parseMarkdown: {
236
279
  match: (node) => node.type === "strong",
237
280
  runner: (state, node, markType) => {
@@ -259,17 +302,8 @@ const strong = createMark((utils) => {
259
302
  });
260
303
  const marks = [codeInline(), em(), strong(), link()];
261
304
  const id$6 = "blockquote";
262
- const WrapInBlockquote = createCmdKey();
305
+ const WrapInBlockquote = createCmdKey("WrapInBlockquote");
263
306
  const blockquote = createNode((utils) => {
264
- const style = utils.getStyle((themeTool, { css }) => 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
307
  return {
274
308
  id: id$6,
275
309
  schema: () => ({
@@ -277,7 +311,7 @@ const blockquote = createNode((utils) => {
277
311
  group: "block",
278
312
  defining: true,
279
313
  parseDOM: [{ tag: "blockquote" }],
280
- toDOM: (node) => ["blockquote", { class: utils.getClassName(node.attrs, id$6, style) }, 0],
314
+ toDOM: (node) => ["blockquote", { class: utils.getClassName(node.attrs, id$6) }, 0],
281
315
  parseMarkdown: {
282
316
  match: ({ type }) => type === id$6,
283
317
  runner: (state, node, type) => {
@@ -298,7 +332,7 @@ const blockquote = createNode((utils) => {
298
332
  }
299
333
  };
300
334
  });
301
- const WrapInBulletList = createCmdKey();
335
+ const WrapInBulletList = createCmdKey("WrapInBulletList");
302
336
  const bulletList = createNode((utils) => {
303
337
  const id2 = "bullet_list";
304
338
  return {
@@ -350,121 +384,13 @@ const languageOptions = [
350
384
  ];
351
385
  const backtickInputRegex = /^```(?<language>[a-z]*)?[\s\n]$/;
352
386
  const tildeInputRegex = /^~~~(?<language>[a-z]*)?[\s\n]$/;
353
- const TurnIntoCodeFence = createCmdKey();
387
+ const TurnIntoCodeFence = createCmdKey("TurnIntoCodeFence");
354
388
  const id$5 = "fence";
355
389
  const codeFence = createNode((utils, options) => {
356
- const style = utils.getStyle(({ palette, mixin, size, font }, { css }) => {
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
- white-space: pre;
460
- overflow: auto;
461
- ${scrollbar("x")};
462
- }
463
- `;
464
- });
390
+ const languageList = (options == null ? void 0 : options.languageList) || languageOptions;
465
391
  return {
466
392
  id: id$5,
467
- schema: () => ({
393
+ schema: (ctx) => ({
468
394
  content: "text*",
469
395
  group: "block",
470
396
  marks: "",
@@ -486,25 +412,61 @@ const codeFence = createNode((utils, options) => {
486
412
  if (!(dom instanceof HTMLElement)) {
487
413
  throw new Error("Parse DOM error.");
488
414
  }
489
- return { language: dom.dataset.language };
415
+ return { language: dom.dataset["language"] };
490
416
  }
491
417
  }
492
418
  ],
493
419
  toDOM: (node) => {
420
+ const select = document.createElement("select");
421
+ languageList.forEach((lang) => {
422
+ const option = document.createElement("option");
423
+ option.value = lang;
424
+ option.innerText = !lang ? "--" : lang;
425
+ if (lang === node.attrs["language"]) {
426
+ option.selected = true;
427
+ }
428
+ select.appendChild(option);
429
+ });
430
+ select.onchange = (e) => {
431
+ const target = e.target;
432
+ if (!(target instanceof HTMLSelectElement)) {
433
+ return;
434
+ }
435
+ const view = ctx.get(editorViewCtx);
436
+ if (!view.editable) {
437
+ target.value = node.attrs["language"];
438
+ return;
439
+ }
440
+ const { top, left } = target.getBoundingClientRect();
441
+ const result = view.posAtCoords({ top, left });
442
+ if (!result)
443
+ return;
444
+ const { tr } = view.state;
445
+ view.dispatch(tr.setNodeMarkup(result.inside, void 0, __spreadProps(__spreadValues({}, node.attrs), {
446
+ language: target.value
447
+ })));
448
+ };
494
449
  return [
495
- "pre",
450
+ "div",
496
451
  {
497
- "data-language": node.attrs.language,
498
- class: utils.getClassName(node.attrs, "code-fence", style)
452
+ class: "code-fence-container"
499
453
  },
500
- ["code", { spellCheck: "false" }, 0]
454
+ select,
455
+ [
456
+ "pre",
457
+ {
458
+ "data-language": node.attrs["language"],
459
+ class: utils.getClassName(node.attrs, "code-fence")
460
+ },
461
+ ["code", { spellCheck: "false" }, 0]
462
+ ]
501
463
  ];
502
464
  },
503
465
  parseMarkdown: {
504
466
  match: ({ type }) => type === "code",
505
467
  runner: (state, node, type) => {
506
- const language = node.lang;
507
- const value = node.value;
468
+ const language = node["lang"];
469
+ const value = node["value"];
508
470
  state.openNode(type, { language });
509
471
  if (value) {
510
472
  state.addText(value);
@@ -517,7 +479,7 @@ const codeFence = createNode((utils, options) => {
517
479
  runner: (state, node) => {
518
480
  var _a;
519
481
  state.addNode("code", void 0, ((_a = node.content.firstChild) == null ? void 0 : _a.text) || "", {
520
- lang: node.attrs.language
482
+ lang: node.attrs["language"]
521
483
  });
522
484
  }
523
485
  }
@@ -540,87 +502,49 @@ const codeFence = createNode((utils, options) => {
540
502
  shortcuts: {
541
503
  [SupportedKeys.CodeFence]: createShortcut(TurnIntoCodeFence, "Mod-Alt-c")
542
504
  },
543
- view: (ctx) => (node, view, getPos) => {
544
- const container = document.createElement("div");
545
- const selectWrapper = document.createElement("div");
546
- const select = document.createElement("ul");
547
- const pre = document.createElement("pre");
548
- const code = document.createElement("code");
549
- const valueWrapper = document.createElement("div");
550
- valueWrapper.className = "code-fence_value";
551
- const value = document.createElement("span");
552
- valueWrapper.appendChild(value);
553
- if (view.editable) {
554
- valueWrapper.appendChild(ctx.get(themeToolCtx).slots.icon("downArrow"));
555
- }
556
- select.className = "code-fence_select";
557
- select.addEventListener("mousedown", (e) => {
558
- e.preventDefault();
559
- e.stopPropagation();
560
- if (!view.editable)
561
- return;
562
- const el = e.target;
563
- if (!(el instanceof HTMLLIElement))
564
- return;
505
+ view: () => (node, view, getPos) => {
506
+ let currNode = node;
507
+ const onSelectLanguage = (language) => {
565
508
  const { tr } = view.state;
566
509
  view.dispatch(tr.setNodeMarkup(getPos(), void 0, {
567
510
  fold: true,
568
- language: el.dataset.value
511
+ language
569
512
  }));
570
- });
571
- valueWrapper.addEventListener("mousedown", (e) => {
572
- e.preventDefault();
573
- e.stopPropagation();
574
- if (!view.editable)
575
- return;
513
+ };
514
+ const onBlur = () => {
576
515
  const { tr } = view.state;
577
- view.dispatch(tr.setNodeMarkup(getPos(), void 0, {
578
- fold: false,
579
- language: container.dataset.language
580
- }));
581
- });
582
- document.addEventListener("mousedown", () => {
583
- if (!view.editable || select.dataset.fold === "true")
584
- return;
516
+ view.dispatch(tr.setNodeMarkup(getPos(), void 0, __spreadProps(__spreadValues({}, currNode.attrs), {
517
+ fold: true
518
+ })));
519
+ };
520
+ const onFocus = () => {
585
521
  const { tr } = view.state;
586
- view.dispatch(tr.setNodeMarkup(getPos(), void 0, {
587
- fold: true,
588
- language: container.dataset.language
589
- }));
590
- });
591
- ((options == null ? void 0 : options.languageList) || languageOptions).forEach((lang) => {
592
- const option = document.createElement("li");
593
- option.className = "code-fence_select-option";
594
- option.innerText = lang || "--";
595
- select.appendChild(option);
596
- option.setAttribute("data-value", lang);
522
+ view.dispatch(tr.setNodeMarkup(getPos(), void 0, __spreadProps(__spreadValues({}, currNode.attrs), {
523
+ fold: false
524
+ })));
525
+ };
526
+ const renderer = utils.themeManager.get("code-fence", {
527
+ onBlur,
528
+ onFocus,
529
+ onSelectLanguage,
530
+ editable: () => view.editable,
531
+ languageList
597
532
  });
598
- code.spellcheck = false;
599
- selectWrapper.className = "code-fence_select-wrapper";
600
- selectWrapper.contentEditable = "false";
601
- selectWrapper.append(valueWrapper);
602
- selectWrapper.append(select);
603
- pre.append(code);
604
- const codeContent = document.createElement("div");
605
- code.append(codeContent);
606
- codeContent.style.whiteSpace = "inherit";
607
- container.append(selectWrapper, pre);
608
- container.setAttribute("class", utils.getClassName(node.attrs, "code-fence", style));
609
- container.setAttribute("data-language", node.attrs.language);
610
- value.innerText = node.attrs.language || "--";
611
- select.setAttribute("data-fold", node.attrs.fold ? "true" : "false");
533
+ if (!renderer)
534
+ return {};
535
+ const { dom, contentDOM, onUpdate, onDestroy } = renderer;
536
+ onUpdate(currNode);
612
537
  return {
613
- dom: container,
614
- contentDOM: codeContent,
538
+ dom,
539
+ contentDOM,
615
540
  update: (updatedNode) => {
616
541
  if (updatedNode.type.name !== id$5)
617
542
  return false;
618
- const lang = updatedNode.attrs.language;
619
- container.dataset.language = lang;
620
- value.innerText = lang || "--";
621
- select.setAttribute("data-fold", updatedNode.attrs.fold ? "true" : "false");
543
+ currNode = updatedNode;
544
+ onUpdate(currNode);
622
545
  return true;
623
- }
546
+ },
547
+ destroy: onDestroy
624
548
  };
625
549
  }
626
550
  };
@@ -646,7 +570,7 @@ const doc = createNode(() => {
646
570
  })
647
571
  };
648
572
  });
649
- const InsertHardbreak = createCmdKey();
573
+ const InsertHardbreak = createCmdKey("InsertHardbreak");
650
574
  const hardbreak = createNode((utils) => {
651
575
  return {
652
576
  id: "hardbreak",
@@ -680,11 +604,13 @@ const hardbreak = createNode((utils) => {
680
604
  },
681
605
  prosePlugins: (type) => [
682
606
  new Plugin({
683
- key: new PluginKey("hardbreak-marks"),
607
+ key: new PluginKey("MILKDOWN_PLUGIN_HARDBREAK_MARKS"),
684
608
  appendTransaction: (trs, _oldState, newState) => {
685
609
  if (!trs.length)
686
610
  return;
687
611
  const [tr] = trs;
612
+ if (!tr)
613
+ return;
688
614
  const [step] = tr.steps;
689
615
  const isInsertHr = tr.getMeta("hardbreak");
690
616
  if (isInsertHr) {
@@ -712,43 +638,10 @@ const hardbreak = createNode((utils) => {
712
638
  };
713
639
  });
714
640
  const headingIndex = Array(6).fill(0).map((_, i) => i + 1);
715
- const TurnIntoHeading = createCmdKey();
641
+ const TurnIntoHeading = createCmdKey("TurnIntoHeading");
716
642
  const headingPluginKey = new PluginKey("MILKDOWN_PLUGIN_ID");
717
643
  const heading = createNode((utils) => {
718
644
  const id2 = "heading";
719
- const style = (level) => utils.getStyle((_, { css }) => {
720
- const headingMap = {
721
- 1: css`
722
- font-size: 3rem;
723
- line-height: 3.5rem;
724
- `,
725
- 2: css`
726
- font-size: 2.5rem;
727
- line-height: 3rem;
728
- `,
729
- 3: css`
730
- font-size: 2.125rem;
731
- line-height: 2.25rem;
732
- `,
733
- 4: css`
734
- font-size: 1.75rem;
735
- line-height: 2rem;
736
- `,
737
- 5: css`
738
- font-size: 1.5rem;
739
- line-height: 1.5rem;
740
- `,
741
- 6: css`
742
- font-size: 1.25rem;
743
- line-height: 1.25rem;
744
- `
745
- };
746
- return css`
747
- ${headingMap[level] || ""}
748
- margin: 2.5rem 0 !important;
749
- font-weight: 400;
750
- `;
751
- });
752
645
  return {
753
646
  id: id2,
754
647
  schema: () => ({
@@ -774,10 +667,10 @@ const heading = createNode((utils) => {
774
667
  })),
775
668
  toDOM: (node) => {
776
669
  return [
777
- `h${node.attrs.level}`,
670
+ `h${node.attrs["level"]}`,
778
671
  {
779
- id: node.attrs.id || node.textContent.split(" ").join("-").toLocaleLowerCase(),
780
- class: utils.getClassName(node.attrs, `heading h${node.attrs.level}`, style(node.attrs.level))
672
+ id: node.attrs["id"] || node.textContent.split(" ").join("-").toLocaleLowerCase(),
673
+ class: utils.getClassName(node.attrs, `heading h${node.attrs["level"]}`)
781
674
  },
782
675
  0
783
676
  ];
@@ -785,7 +678,7 @@ const heading = createNode((utils) => {
785
678
  parseMarkdown: {
786
679
  match: ({ type }) => type === id2,
787
680
  runner: (state, node, type) => {
788
- const depth = node.depth;
681
+ const depth = node["depth"];
789
682
  state.openNode(type, { level: depth });
790
683
  state.next(node.children);
791
684
  state.closeNode();
@@ -794,7 +687,7 @@ const heading = createNode((utils) => {
794
687
  toMarkdown: {
795
688
  match: (node) => node.type.name === id2,
796
689
  runner: (state, node) => {
797
- state.openNode("heading", void 0, { depth: node.attrs.level });
690
+ state.openNode("heading", void 0, { depth: node.attrs["level"] });
798
691
  state.next(node.content);
799
692
  state.closeNode();
800
693
  }
@@ -826,8 +719,8 @@ const heading = createNode((utils) => {
826
719
  }
827
720
  const attrs = node.attrs;
828
721
  const id22 = createId(node);
829
- if (attrs.id !== id22) {
830
- tr.setNodeMarkup(pos, void 0, __spreadProps(__spreadValues({}, attrs), {
722
+ if (attrs["id"] !== id22) {
723
+ tr.setMeta(headingPluginKey, true).setNodeMarkup(pos, void 0, __spreadProps(__spreadValues({}, attrs), {
831
724
  id: id22
832
725
  }));
833
726
  }
@@ -847,14 +740,16 @@ const heading = createNode((utils) => {
847
740
  compositionend: () => {
848
741
  lock = false;
849
742
  const view = ctx.get(editorViewCtx);
850
- walkThrough(view.state, (tr) => view.dispatch(tr));
743
+ setTimeout(() => {
744
+ walkThrough(view.state, (tr) => view.dispatch(tr));
745
+ }, 0);
851
746
  return false;
852
747
  }
853
748
  }
854
749
  },
855
750
  appendTransaction: (transactions, _, nextState) => {
856
751
  let tr = null;
857
- if (transactions.some((transaction) => transaction.docChanged)) {
752
+ if (transactions.every((transaction) => !transaction.getMeta(headingPluginKey)) && transactions.some((transaction) => transaction.docChanged)) {
858
753
  walkThrough(nextState, (t) => {
859
754
  tr = t;
860
755
  });
@@ -867,19 +762,14 @@ const heading = createNode((utils) => {
867
762
  };
868
763
  });
869
764
  const id$4 = "hr";
870
- const InsertHr = createCmdKey();
765
+ const InsertHr = createCmdKey("InsertHr");
871
766
  const hr = createNode((utils) => {
872
- const style = utils.getStyle((themeTool, { css }) => css`
873
- height: ${themeTool.size.lineWidth};
874
- background-color: ${themeTool.palette("line")};
875
- border-width: 0;
876
- `);
877
767
  return {
878
768
  id: id$4,
879
769
  schema: () => ({
880
770
  group: "block",
881
771
  parseDOM: [{ tag: "hr" }],
882
- toDOM: (node) => ["hr", { class: utils.getClassName(node.attrs, id$4, style) }],
772
+ toDOM: (node) => ["hr", { class: utils.getClassName(node.attrs, id$4) }],
883
773
  parseMarkdown: {
884
774
  match: ({ type }) => type === "thematicBreak",
885
775
  runner: (state, _, type) => {
@@ -923,118 +813,11 @@ const hr = createNode((utils) => {
923
813
  ]
924
814
  };
925
815
  });
926
- const ModifyImage = createCmdKey();
927
- const InsertImage = createCmdKey();
816
+ const ModifyImage = createCmdKey("ModifyImage");
817
+ const InsertImage = createCmdKey("InsertImage");
928
818
  const id$3 = "image";
819
+ const key = new PluginKey("MILKDOWN_PLUGIN_IMAGE_INPUT");
929
820
  const image = createNode((utils, options) => {
930
- var _a, _b;
931
- const placeholder = __spreadValues({
932
- loading: "Loading...",
933
- empty: "Add an Image",
934
- failed: "Image loads failed"
935
- }, (_a = options == null ? void 0 : options.placeholder) != null ? _a : {});
936
- const isBlock = (_b = options == null ? void 0 : options.isBlock) != null ? _b : false;
937
- const containerStyle = utils.getStyle((themeTool, { css }) => css`
938
- display: inline-block;
939
- position: relative;
940
- text-align: center;
941
- font-size: 0;
942
- vertical-align: text-bottom;
943
- line-height: 1;
944
-
945
- ${isBlock ? `
946
- width: 100%;
947
- margin: 0 auto;
948
- ` : ""}
949
-
950
- &.ProseMirror-selectednode::after {
951
- content: '';
952
- background: ${themeTool.palette("secondary", 0.38)};
953
- position: absolute;
954
- top: 0;
955
- left: 0;
956
- right: 0;
957
- bottom: 0;
958
- }
959
-
960
- img {
961
- max-width: 100%;
962
- height: auto;
963
- object-fit: contain;
964
- margin: 0 2px;
965
- }
966
- .icon,
967
- .placeholder {
968
- display: none;
969
- }
970
-
971
- &.system {
972
- width: 100%;
973
- padding: 0 2rem;
974
-
975
- img {
976
- width: 0;
977
- height: 0;
978
- display: none;
979
- }
980
-
981
- .icon,
982
- .placeholder {
983
- display: inline;
984
- }
985
-
986
- box-sizing: border-box;
987
- height: 3rem;
988
- background-color: ${themeTool.palette("background")};
989
- border-radius: ${themeTool.size.radius};
990
- display: inline-flex;
991
- gap: 2rem;
992
- justify-content: flex-start;
993
- align-items: center;
994
- .placeholder {
995
- margin: 0;
996
- line-height: 1;
997
- &::before {
998
- content: '';
999
- font-size: 0.875rem;
1000
- color: ${themeTool.palette("neutral", 0.6)};
1001
- }
1002
- }
1003
- }
1004
-
1005
- &.loading {
1006
- .placeholder {
1007
- &::before {
1008
- content: '${placeholder.loading}';
1009
- }
1010
- }
1011
- }
1012
-
1013
- &.empty {
1014
- .placeholder {
1015
- &::before {
1016
- content: '${placeholder.empty}';
1017
- }
1018
- }
1019
- }
1020
-
1021
- &.failed {
1022
- .placeholder {
1023
- &::before {
1024
- content: '${placeholder.failed}';
1025
- }
1026
- }
1027
- }
1028
- `);
1029
- const style = utils.getStyle((_, { css }) => css`
1030
- display: inline-block;
1031
- margin: 0 auto;
1032
- object-fit: contain;
1033
- width: 100%;
1034
- position: relative;
1035
- height: auto;
1036
- text-align: center;
1037
- `);
1038
821
  return {
1039
822
  id: "image",
1040
823
  schema: () => ({
@@ -1049,10 +832,7 @@ const image = createNode((utils, options) => {
1049
832
  attrs: {
1050
833
  src: { default: "" },
1051
834
  alt: { default: null },
1052
- title: { default: null },
1053
- failed: { default: false },
1054
- loading: { default: true },
1055
- width: { default: null }
835
+ title: { default: null }
1056
836
  },
1057
837
  parseDOM: [
1058
838
  {
@@ -1062,8 +842,6 @@ const image = createNode((utils, options) => {
1062
842
  throw new Error();
1063
843
  }
1064
844
  return {
1065
- failed: dom.classList.contains("failed"),
1066
- loading: dom.classList.contains("loading"),
1067
845
  src: dom.getAttribute("src") || "",
1068
846
  alt: dom.getAttribute("alt"),
1069
847
  title: dom.getAttribute("title") || dom.getAttribute("alt"),
@@ -1076,16 +854,16 @@ const image = createNode((utils, options) => {
1076
854
  return [
1077
855
  "img",
1078
856
  __spreadProps(__spreadValues({}, node.attrs), {
1079
- class: utils.getClassName(node.attrs, id$3, node.attrs.failed ? "failed" : "", node.attrs.loading ? "loading" : "", style)
857
+ class: utils.getClassName(node.attrs, id$3)
1080
858
  })
1081
859
  ];
1082
860
  },
1083
861
  parseMarkdown: {
1084
862
  match: ({ type }) => type === id$3,
1085
863
  runner: (state, node, type) => {
1086
- const url = node.url;
1087
- const alt = node.alt;
1088
- const title = node.title;
864
+ const url = node["url"];
865
+ const alt = node["alt"];
866
+ const title = node["title"];
1089
867
  state.addNode(type, {
1090
868
  src: url,
1091
869
  alt,
@@ -1097,9 +875,9 @@ const image = createNode((utils, options) => {
1097
875
  match: (node) => node.type.name === id$3,
1098
876
  runner: (state, node) => {
1099
877
  state.addNode("image", void 0, void 0, {
1100
- title: node.attrs.title,
1101
- url: node.attrs.src,
1102
- alt: node.attrs.alt
878
+ title: node.attrs["title"],
879
+ url: node.attrs["src"],
880
+ alt: node.attrs["alt"]
1103
881
  });
1104
882
  }
1105
883
  }
@@ -1136,163 +914,133 @@ const image = createNode((utils, options) => {
1136
914
  return tr;
1137
915
  })
1138
916
  ],
1139
- view: (ctx) => (node, view, getPos) => {
1140
- const nodeType = node.type;
1141
- const createIcon = ctx.get(themeToolCtx).slots.icon;
1142
- const container = document.createElement("span");
1143
- container.className = utils.getClassName(node.attrs, id$3, containerStyle);
1144
- const content = document.createElement("img");
1145
- container.append(content);
1146
- let icon = createIcon("image");
1147
- const placeholder2 = document.createElement("span");
1148
- placeholder2.classList.add("placeholder");
1149
- container.append(icon, placeholder2);
1150
- const setIcon = (name) => {
1151
- const nextIcon = createIcon(name);
1152
- container.replaceChild(nextIcon, icon);
1153
- icon = nextIcon;
1154
- };
1155
- const loadImage = (src2) => {
1156
- container.classList.add("system", "loading");
1157
- setIcon("loading");
1158
- const img = document.createElement("img");
1159
- img.src = src2;
1160
- img.onerror = () => {
1161
- const pos = getPos();
1162
- if (!pos)
1163
- return;
1164
- const { tr } = view.state;
1165
- const _tr = tr.setNodeMarkup(pos, nodeType, __spreadProps(__spreadValues({}, node.attrs), {
1166
- src: src2,
1167
- loading: false,
1168
- failed: true
1169
- }));
1170
- view.dispatch(_tr);
1171
- };
1172
- img.onload = () => {
1173
- const { tr } = view.state;
1174
- const pos = getPos();
1175
- if (!pos)
1176
- return;
1177
- const _tr = tr.setNodeMarkup(pos, nodeType, __spreadProps(__spreadValues({}, node.attrs), {
1178
- width: img.width,
1179
- src: src2,
1180
- loading: false,
1181
- failed: false
1182
- }));
1183
- view.dispatch(_tr);
1184
- };
1185
- };
1186
- const { src, loading, title, alt, width } = node.attrs;
1187
- content.src = src;
1188
- content.title = title || alt;
1189
- content.alt = alt;
1190
- if (width) {
1191
- content.width = width;
1192
- }
1193
- if (src.length === 0) {
1194
- container.classList.add("system", "empty");
1195
- setIcon("image");
1196
- } else if (loading) {
1197
- loadImage(src);
917
+ view: () => (node) => {
918
+ var _a, _b;
919
+ let currNode = node;
920
+ const placeholder = (_a = options == null ? void 0 : options.placeholder) != null ? _a : "Add an Image";
921
+ const isBlock = (_b = options == null ? void 0 : options.isBlock) != null ? _b : false;
922
+ const renderer = utils.themeManager.get("image", {
923
+ placeholder,
924
+ isBlock
925
+ });
926
+ if (!renderer) {
927
+ return {};
1198
928
  }
929
+ const { dom, onUpdate } = renderer;
930
+ onUpdate(currNode);
1199
931
  return {
1200
- dom: container,
932
+ dom,
1201
933
  update: (updatedNode) => {
1202
934
  if (updatedNode.type.name !== id$3)
1203
935
  return false;
1204
- const { src: src2, alt: alt2, title: title2, loading: loading2, failed, width: width2 } = updatedNode.attrs;
1205
- content.src = src2;
1206
- content.alt = alt2;
1207
- content.title = title2 || alt2;
1208
- if (width2) {
1209
- content.width = width2;
1210
- }
1211
- if (loading2) {
1212
- loadImage(src2);
1213
- return true;
1214
- }
1215
- if (failed) {
1216
- container.classList.remove("loading", "empty");
1217
- container.classList.add("system", "failed");
1218
- setIcon("brokenImage");
1219
- return true;
1220
- }
1221
- if (src2.length > 0) {
1222
- container.classList.remove("system", "empty", "loading");
1223
- return true;
1224
- }
1225
- container.classList.add("system", "empty");
1226
- setIcon("image");
936
+ currNode = updatedNode;
937
+ onUpdate(currNode);
1227
938
  return true;
1228
939
  },
1229
940
  selectNode: () => {
1230
- container.classList.add("ProseMirror-selectednode");
941
+ dom.classList.add("ProseMirror-selectednode");
1231
942
  },
1232
943
  deselectNode: () => {
1233
- container.classList.remove("ProseMirror-selectednode");
944
+ dom.classList.remove("ProseMirror-selectednode");
945
+ }
946
+ };
947
+ },
948
+ prosePlugins: (type, ctx) => {
949
+ var _a, _b, _c;
950
+ const inputChipRenderer = utils.themeManager.get("input-chip", {
951
+ placeholder: (_b = (_a = options == null ? void 0 : options.input) == null ? void 0 : _a.placeholder) != null ? _b : "Input Image Link",
952
+ buttonText: (_c = options == null ? void 0 : options.input) == null ? void 0 : _c.buttonText,
953
+ onUpdate: (value) => {
954
+ ctx.get(commandsCtx).call(ModifyImage, value);
955
+ }
956
+ });
957
+ const shouldDisplay = (view) => {
958
+ return Boolean(type && findSelectedNodeOfType(view.state.selection, type));
959
+ };
960
+ const getCurrentLink = (view) => {
961
+ const result = findSelectedNodeOfType(view.state.selection, type);
962
+ if (!result)
963
+ return;
964
+ const value = result.node.attrs["src"];
965
+ return value;
966
+ };
967
+ const renderByView = (view) => {
968
+ if (!view.editable) {
969
+ return;
970
+ }
971
+ const display = shouldDisplay(view);
972
+ if (display) {
973
+ inputChipRenderer.show(view);
974
+ inputChipRenderer.update(getCurrentLink(view));
975
+ } else {
976
+ inputChipRenderer.hide();
1234
977
  }
1235
978
  };
979
+ return [
980
+ new Plugin({
981
+ key,
982
+ view: (editorView) => {
983
+ inputChipRenderer.init(editorView);
984
+ renderByView(editorView);
985
+ return {
986
+ update: (view, prevState) => {
987
+ const isEqualSelection = (prevState == null ? void 0 : prevState.doc.eq(view.state.doc)) && prevState.selection.eq(view.state.selection);
988
+ if (isEqualSelection)
989
+ return;
990
+ renderByView(view);
991
+ },
992
+ destroy: () => {
993
+ inputChipRenderer.destroy();
994
+ }
995
+ };
996
+ }
997
+ })
998
+ ];
1236
999
  }
1237
1000
  };
1238
1001
  });
1239
1002
  const id$2 = "list_item";
1240
- const SplitListItem = createCmdKey();
1241
- const SinkListItem = createCmdKey();
1242
- const LiftListItem = createCmdKey();
1243
- const listItem = createNode((utils) => {
1244
- const style = utils.getStyle((themeTool, { css }) => css`
1245
- &,
1246
- & > * {
1247
- margin: 0.5rem 0;
1248
- }
1249
-
1250
- &,
1251
- li {
1252
- &::marker {
1253
- color: ${themeTool.palette("primary")};
1254
- }
1255
- }
1256
- `);
1257
- return {
1258
- id: id$2,
1259
- schema: () => ({
1260
- group: "listItem",
1261
- content: "paragraph block*",
1262
- defining: true,
1263
- parseDOM: [{ tag: "li" }],
1264
- toDOM: (node) => ["li", { class: utils.getClassName(node.attrs, "list-item", style) }, 0],
1265
- parseMarkdown: {
1266
- match: ({ type, checked }) => type === "listItem" && checked === null,
1267
- runner: (state, node, type) => {
1268
- state.openNode(type);
1269
- state.next(node.children);
1270
- state.closeNode();
1271
- }
1272
- },
1273
- toMarkdown: {
1274
- match: (node) => node.type.name === id$2,
1275
- runner: (state, node) => {
1276
- state.openNode("listItem");
1277
- state.next(node.content);
1278
- state.closeNode();
1279
- }
1003
+ const SplitListItem = createCmdKey("SplitListItem");
1004
+ const SinkListItem = createCmdKey("SinkListItem");
1005
+ const LiftListItem = createCmdKey("LiftListItem");
1006
+ const listItem = createNode((utils) => ({
1007
+ id: id$2,
1008
+ schema: () => ({
1009
+ group: "listItem",
1010
+ content: "paragraph block*",
1011
+ defining: true,
1012
+ parseDOM: [{ tag: "li" }],
1013
+ toDOM: (node) => ["li", { class: utils.getClassName(node.attrs, "list-item") }, 0],
1014
+ parseMarkdown: {
1015
+ match: ({ type, checked }) => type === "listItem" && checked === null,
1016
+ runner: (state, node, type) => {
1017
+ state.openNode(type);
1018
+ state.next(node.children);
1019
+ state.closeNode();
1020
+ }
1021
+ },
1022
+ toMarkdown: {
1023
+ match: (node) => node.type.name === id$2,
1024
+ runner: (state, node) => {
1025
+ state.openNode("listItem");
1026
+ state.next(node.content);
1027
+ state.closeNode();
1280
1028
  }
1281
- }),
1282
- inputRules: (nodeType) => [wrappingInputRule(/^\s*([-+*])\s$/, nodeType)],
1283
- commands: (nodeType) => [
1284
- createCmd(SplitListItem, () => splitListItem(nodeType)),
1285
- createCmd(SinkListItem, () => sinkListItem(nodeType)),
1286
- createCmd(LiftListItem, () => liftListItem(nodeType))
1287
- ],
1288
- shortcuts: {
1289
- [SupportedKeys.NextListItem]: createShortcut(SplitListItem, "Enter"),
1290
- [SupportedKeys.SinkListItem]: createShortcut(SinkListItem, "Mod-]"),
1291
- [SupportedKeys.LiftListItem]: createShortcut(LiftListItem, "Mod-[")
1292
1029
  }
1293
- };
1294
- });
1295
- const WrapInOrderedList = createCmdKey();
1030
+ }),
1031
+ inputRules: (nodeType) => [wrappingInputRule(/^\s*([-+*])\s$/, nodeType)],
1032
+ commands: (nodeType) => [
1033
+ createCmd(SplitListItem, () => splitListItem(nodeType)),
1034
+ createCmd(SinkListItem, () => sinkListItem(nodeType)),
1035
+ createCmd(LiftListItem, () => liftListItem(nodeType))
1036
+ ],
1037
+ shortcuts: {
1038
+ [SupportedKeys.NextListItem]: createShortcut(SplitListItem, "Enter"),
1039
+ [SupportedKeys.SinkListItem]: createShortcut(SinkListItem, "Mod-]"),
1040
+ [SupportedKeys.LiftListItem]: createShortcut(LiftListItem, "Mod-[")
1041
+ }
1042
+ }));
1043
+ const WrapInOrderedList = createCmdKey("WrapInOrderedList");
1296
1044
  const id$1 = "ordered_list";
1297
1045
  const orderedList = createNode((utils) => ({
1298
1046
  id: id$1,
@@ -1317,7 +1065,7 @@ const orderedList = createNode((utils) => ({
1317
1065
  ],
1318
1066
  toDOM: (node) => [
1319
1067
  "ol",
1320
- __spreadProps(__spreadValues({}, node.attrs.order === 1 ? {} : node.attrs.order), {
1068
+ __spreadProps(__spreadValues({}, node.attrs["order"] === 1 ? {} : node.attrs["order"]), {
1321
1069
  class: utils.getClassName(node.attrs, "ordered-list")
1322
1070
  }),
1323
1071
  0
@@ -1338,30 +1086,23 @@ const orderedList = createNode((utils) => ({
1338
1086
  }
1339
1087
  }),
1340
1088
  inputRules: (nodeType) => [
1341
- wrappingInputRule(/^(\d+)\.\s$/, nodeType, (match) => ({ order: Number(match[1]) }), (match, node) => node.childCount + node.attrs.order === Number(match[1]))
1089
+ wrappingInputRule(/^(\d+)\.\s$/, nodeType, (match) => ({ order: Number(match[1]) }), (match, node) => node.childCount + node.attrs["order"] === Number(match[1]))
1342
1090
  ],
1343
1091
  commands: (nodeType) => [createCmd(WrapInOrderedList, () => wrapIn(nodeType))],
1344
1092
  shortcuts: {
1345
1093
  [SupportedKeys.OrderedList]: createShortcut(WrapInOrderedList, "Mod-Alt-7")
1346
1094
  }
1347
1095
  }));
1348
- const TurnIntoText = createCmdKey();
1096
+ const TurnIntoText = createCmdKey("TurnIntoText");
1349
1097
  const id = "paragraph";
1350
1098
  const paragraph = createNode((utils) => {
1351
- const style = utils.getStyle((_, { css }) => {
1352
- return css`
1353
- font-size: 1rem;
1354
- line-height: 1.5;
1355
- letter-spacing: 0.5px;
1356
- `;
1357
- });
1358
1099
  return {
1359
1100
  id,
1360
1101
  schema: () => ({
1361
1102
  content: "inline*",
1362
1103
  group: "block",
1363
1104
  parseDOM: [{ tag: "p" }],
1364
- toDOM: (node) => ["p", { class: utils.getClassName(node.attrs, id, style) }, 0],
1105
+ toDOM: (node) => ["p", { class: utils.getClassName(node.attrs, id) }, 0],
1365
1106
  parseMarkdown: {
1366
1107
  match: (node) => node.type === "paragraph",
1367
1108
  runner: (state, node, type) => {
@@ -1369,7 +1110,7 @@ const paragraph = createNode((utils) => {
1369
1110
  if (node.children) {
1370
1111
  state.next(node.children);
1371
1112
  } else {
1372
- state.addText(node.value);
1113
+ state.addText(node["value"]);
1373
1114
  }
1374
1115
  state.closeNode();
1375
1116
  }
@@ -1396,7 +1137,7 @@ const text = createNode(() => ({
1396
1137
  parseMarkdown: {
1397
1138
  match: ({ type }) => type === "text",
1398
1139
  runner: (state, node) => {
1399
- state.addText(node.value);
1140
+ state.addText(node["value"]);
1400
1141
  }
1401
1142
  },
1402
1143
  toMarkdown: {
@@ -1429,10 +1170,16 @@ function flatMapWithDepth(ast, fn) {
1429
1170
  if (isParent(node)) {
1430
1171
  const out = [];
1431
1172
  for (let i = 0, n = node.children.length; i < n; i++) {
1432
- const xs = transform(node.children[i], i, node);
1433
- if (xs) {
1434
- for (let j = 0, m = xs.length; j < m; j++) {
1435
- out.push(xs[j]);
1173
+ const nthChild = node.children[i];
1174
+ if (nthChild) {
1175
+ const xs = transform(nthChild, i, node);
1176
+ if (xs) {
1177
+ for (let j = 0, m = xs.length; j < m; j++) {
1178
+ const item = xs[j];
1179
+ if (item) {
1180
+ out.push(item);
1181
+ }
1182
+ }
1436
1183
  }
1437
1184
  }
1438
1185
  }