@milkdown/preset-commonmark 5.5.0 → 6.0.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 (84) 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 +283 -523
  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 +1 -12
  50. package/src/mark/link.ts +93 -18
  51. package/src/mark/strong.ts +1 -7
  52. package/src/node/blockquote.ts +1 -14
  53. package/src/node/code-fence.ts +94 -184
  54. package/src/node/heading.ts +1 -41
  55. package/src/node/hr.ts +1 -8
  56. package/src/node/image.ts +81 -232
  57. package/src/node/list-item.ts +34 -53
  58. package/src/node/paragraph.ts +1 -9
  59. package/lib/src/index.d.ts +0 -34
  60. package/lib/src/index.d.ts.map +0 -1
  61. package/lib/src/mark/code-inline.d.ts.map +0 -1
  62. package/lib/src/mark/em.d.ts.map +0 -1
  63. package/lib/src/mark/index.d.ts +0 -6
  64. package/lib/src/mark/index.d.ts.map +0 -1
  65. package/lib/src/mark/link.d.ts.map +0 -1
  66. package/lib/src/mark/strong.d.ts.map +0 -1
  67. package/lib/src/node/blockquote.d.ts.map +0 -1
  68. package/lib/src/node/bullet-list.d.ts.map +0 -1
  69. package/lib/src/node/code-fence.d.ts.map +0 -1
  70. package/lib/src/node/doc.d.ts.map +0 -1
  71. package/lib/src/node/hardbreak.d.ts.map +0 -1
  72. package/lib/src/node/heading.d.ts.map +0 -1
  73. package/lib/src/node/hr.d.ts.map +0 -1
  74. package/lib/src/node/image.d.ts.map +0 -1
  75. package/lib/src/node/index.d.ts.map +0 -1
  76. package/lib/src/node/list-item.d.ts.map +0 -1
  77. package/lib/src/node/ordered-list.d.ts.map +0 -1
  78. package/lib/src/node/paragraph.d.ts.map +0 -1
  79. package/lib/src/node/text.d.ts.map +0 -1
  80. package/lib/src/plugin/filter-html.d.ts.map +0 -1
  81. package/lib/src/plugin/index.d.ts +0 -2
  82. package/lib/src/plugin/index.d.ts.map +0 -1
  83. package/lib/src/supported-keys.d.ts.map +0 -1
  84. 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, Fragment, 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",
@@ -44,14 +44,6 @@ const SupportedKeys = {
44
44
  const id$a = "code_inline";
45
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,7 +51,7 @@ 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) => {
@@ -117,23 +109,11 @@ const em = createMark((utils) => ({
117
109
  [SupportedKeys.Em]: createShortcut(ToggleItalic, "Mod-i")
118
110
  }
119
111
  }));
112
+ const key$1 = new PluginKey("MILKDOWN_PLUGIN_LINK_INPUT");
120
113
  const ToggleLink = createCmdKey("ToggleLink");
121
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,7 +133,7 @@ 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) => {
@@ -214,15 +194,80 @@ const link = createMark((utils) => {
214
194
  }
215
195
  return tr;
216
196
  })
217
- ]
197
+ ],
198
+ prosePlugins: (type, ctx) => {
199
+ return [
200
+ new Plugin({
201
+ key: key$1,
202
+ view: (editorView) => {
203
+ var _a, _b, _c;
204
+ const inputChipRenderer = utils.themeManager.get("input-chip", {
205
+ placeholder: (_b = (_a = options == null ? void 0 : options.input) == null ? void 0 : _a.placeholder) != null ? _b : "Input Web Link",
206
+ buttonText: (_c = options == null ? void 0 : options.input) == null ? void 0 : _c.buttonText,
207
+ onUpdate: (value) => {
208
+ ctx.get(commandsCtx).call(ModifyLink, value);
209
+ }
210
+ });
211
+ if (!inputChipRenderer)
212
+ return {};
213
+ const shouldDisplay = (view) => {
214
+ const { selection, doc: doc2 } = view.state;
215
+ const { from, to } = selection;
216
+ return selection.empty && selection instanceof TextSelection && doc2.rangeHasMark(from, from === to ? to + 1 : to, type);
217
+ };
218
+ const getCurrentLink = (view) => {
219
+ const { selection } = view.state;
220
+ let node;
221
+ const { from, to } = selection;
222
+ view.state.doc.nodesBetween(from, from === to ? to + 1 : to, (n) => {
223
+ if (type.isInSet(n.marks)) {
224
+ node = n;
225
+ return false;
226
+ }
227
+ return;
228
+ });
229
+ if (!node)
230
+ return;
231
+ const mark = node.marks.find((m) => m.type === type);
232
+ if (!mark)
233
+ return;
234
+ const value = mark.attrs["href"];
235
+ return value;
236
+ };
237
+ const renderByView = (view) => {
238
+ if (!view.editable) {
239
+ return;
240
+ }
241
+ const display = shouldDisplay(view);
242
+ if (display) {
243
+ inputChipRenderer.show(view);
244
+ inputChipRenderer.update(getCurrentLink(view));
245
+ } else {
246
+ inputChipRenderer.hide();
247
+ }
248
+ };
249
+ inputChipRenderer.init(editorView);
250
+ renderByView(editorView);
251
+ return {
252
+ update: (view, prevState) => {
253
+ const isEqualSelection = (prevState == null ? void 0 : prevState.doc.eq(view.state.doc)) && prevState.selection.eq(view.state.selection);
254
+ if (isEqualSelection)
255
+ return;
256
+ renderByView(view);
257
+ },
258
+ destroy: () => {
259
+ inputChipRenderer.destroy();
260
+ }
261
+ };
262
+ }
263
+ })
264
+ ];
265
+ }
218
266
  };
219
267
  });
220
268
  const id$7 = "strong";
221
269
  const ToggleBold = createCmdKey("ToggleBold");
222
270
  const strong = createMark((utils) => {
223
- const style = utils.getStyle((_, { css }) => css`
224
- font-weight: 600;
225
- `);
226
271
  return {
227
272
  id: id$7,
228
273
  schema: () => ({
@@ -231,7 +276,7 @@ const strong = createMark((utils) => {
231
276
  { tag: "strong" },
232
277
  { style: "font-style", getAttrs: (value) => value === "bold" }
233
278
  ],
234
- toDOM: (mark) => ["strong", { class: utils.getClassName(mark.attrs, id$7, style) }],
279
+ toDOM: (mark) => ["strong", { class: utils.getClassName(mark.attrs, id$7) }],
235
280
  parseMarkdown: {
236
281
  match: (node) => node.type === "strong",
237
282
  runner: (state, node, markType) => {
@@ -261,15 +306,6 @@ const marks = [codeInline(), em(), strong(), link()];
261
306
  const id$6 = "blockquote";
262
307
  const WrapInBlockquote = createCmdKey("WrapInBlockquote");
263
308
  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
309
  return {
274
310
  id: id$6,
275
311
  schema: () => ({
@@ -277,7 +313,7 @@ const blockquote = createNode((utils) => {
277
313
  group: "block",
278
314
  defining: true,
279
315
  parseDOM: [{ tag: "blockquote" }],
280
- toDOM: (node) => ["blockquote", { class: utils.getClassName(node.attrs, id$6, style) }, 0],
316
+ toDOM: (node) => ["blockquote", { class: utils.getClassName(node.attrs, id$6) }, 0],
281
317
  parseMarkdown: {
282
318
  match: ({ type }) => type === id$6,
283
319
  runner: (state, node, type) => {
@@ -353,118 +389,10 @@ const tildeInputRegex = /^~~~(?<language>[a-z]*)?[\s\n]$/;
353
389
  const TurnIntoCodeFence = createCmdKey("TurnIntoCodeFence");
354
390
  const id$5 = "fence";
355
391
  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
- });
392
+ const languageList = (options == null ? void 0 : options.languageList) || languageOptions;
465
393
  return {
466
394
  id: id$5,
467
- schema: () => ({
395
+ schema: (ctx) => ({
468
396
  content: "text*",
469
397
  group: "block",
470
398
  marks: "",
@@ -479,6 +407,25 @@ const codeFence = createNode((utils, options) => {
479
407
  }
480
408
  },
481
409
  parseDOM: [
410
+ {
411
+ tag: "div.code-fence-container",
412
+ preserveWhitespace: "full",
413
+ getAttrs: (dom) => {
414
+ var _a;
415
+ if (!(dom instanceof HTMLElement)) {
416
+ throw new Error("Parse DOM error.");
417
+ }
418
+ return { language: (_a = dom.querySelector("pre")) == null ? void 0 : _a.dataset["language"] };
419
+ },
420
+ getContent: (dom, schema) => {
421
+ var _a, _b;
422
+ if (!(dom instanceof HTMLElement)) {
423
+ throw new Error("Parse DOM error.");
424
+ }
425
+ const textNode = schema.text((_b = (_a = dom.querySelector("pre")) == null ? void 0 : _a.textContent) != null ? _b : "");
426
+ return Fragment.from(textNode);
427
+ }
428
+ },
482
429
  {
483
430
  tag: "pre",
484
431
  preserveWhitespace: "full",
@@ -491,13 +438,49 @@ const codeFence = createNode((utils, options) => {
491
438
  }
492
439
  ],
493
440
  toDOM: (node) => {
441
+ const select = document.createElement("select");
442
+ languageList.forEach((lang) => {
443
+ const option = document.createElement("option");
444
+ option.value = lang;
445
+ option.innerText = !lang ? "--" : lang;
446
+ if (lang === node.attrs["language"]) {
447
+ option.selected = true;
448
+ }
449
+ select.appendChild(option);
450
+ });
451
+ select.onchange = (e) => {
452
+ const target = e.target;
453
+ if (!(target instanceof HTMLSelectElement)) {
454
+ return;
455
+ }
456
+ const view = ctx.get(editorViewCtx);
457
+ if (!view.editable) {
458
+ target.value = node.attrs["language"];
459
+ return;
460
+ }
461
+ const { top, left } = target.getBoundingClientRect();
462
+ const result = view.posAtCoords({ top, left });
463
+ if (!result)
464
+ return;
465
+ const { tr } = view.state;
466
+ view.dispatch(tr.setNodeMarkup(result.inside, void 0, __spreadProps(__spreadValues({}, node.attrs), {
467
+ language: target.value
468
+ })));
469
+ };
494
470
  return [
495
- "pre",
471
+ "div",
496
472
  {
497
- "data-language": node.attrs["language"],
498
- class: utils.getClassName(node.attrs, "code-fence", style)
473
+ class: "code-fence-container"
499
474
  },
500
- ["code", { spellCheck: "false" }, 0]
475
+ select,
476
+ [
477
+ "pre",
478
+ {
479
+ "data-language": node.attrs["language"],
480
+ class: utils.getClassName(node.attrs, "code-fence")
481
+ },
482
+ ["code", { spellCheck: "false" }, 0]
483
+ ]
501
484
  ];
502
485
  },
503
486
  parseMarkdown: {
@@ -540,87 +523,49 @@ const codeFence = createNode((utils, options) => {
540
523
  shortcuts: {
541
524
  [SupportedKeys.CodeFence]: createShortcut(TurnIntoCodeFence, "Mod-Alt-c")
542
525
  },
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;
526
+ view: () => (node, view, getPos) => {
527
+ let currNode = node;
528
+ const onSelectLanguage = (language) => {
565
529
  const { tr } = view.state;
566
530
  view.dispatch(tr.setNodeMarkup(getPos(), void 0, {
567
531
  fold: true,
568
- language: el.dataset["value"]
532
+ language
569
533
  }));
570
- });
571
- valueWrapper.addEventListener("mousedown", (e) => {
572
- e.preventDefault();
573
- e.stopPropagation();
574
- if (!view.editable)
575
- return;
534
+ };
535
+ const onBlur = () => {
576
536
  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;
537
+ view.dispatch(tr.setNodeMarkup(getPos(), void 0, __spreadProps(__spreadValues({}, currNode.attrs), {
538
+ fold: true
539
+ })));
540
+ };
541
+ const onFocus = () => {
585
542
  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);
543
+ view.dispatch(tr.setNodeMarkup(getPos(), void 0, __spreadProps(__spreadValues({}, currNode.attrs), {
544
+ fold: false
545
+ })));
546
+ };
547
+ const renderer = utils.themeManager.get("code-fence", {
548
+ onBlur,
549
+ onFocus,
550
+ onSelectLanguage,
551
+ editable: () => view.editable,
552
+ languageList
597
553
  });
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");
554
+ if (!renderer)
555
+ return {};
556
+ const { dom, contentDOM, onUpdate, onDestroy } = renderer;
557
+ onUpdate(currNode);
612
558
  return {
613
- dom: container,
614
- contentDOM: codeContent,
559
+ dom,
560
+ contentDOM,
615
561
  update: (updatedNode) => {
616
562
  if (updatedNode.type.name !== id$5)
617
563
  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");
564
+ currNode = updatedNode;
565
+ onUpdate(currNode);
622
566
  return true;
623
- }
567
+ },
568
+ destroy: onDestroy
624
569
  };
625
570
  }
626
571
  };
@@ -718,39 +663,6 @@ const TurnIntoHeading = createCmdKey("TurnIntoHeading");
718
663
  const headingPluginKey = new PluginKey("MILKDOWN_PLUGIN_ID");
719
664
  const heading = createNode((utils) => {
720
665
  const id2 = "heading";
721
- const style = (level) => utils.getStyle((_, { css }) => {
722
- const headingMap = {
723
- 1: css`
724
- font-size: 3rem;
725
- line-height: 3.5rem;
726
- `,
727
- 2: css`
728
- font-size: 2.5rem;
729
- line-height: 3rem;
730
- `,
731
- 3: css`
732
- font-size: 2.125rem;
733
- line-height: 2.25rem;
734
- `,
735
- 4: css`
736
- font-size: 1.75rem;
737
- line-height: 2rem;
738
- `,
739
- 5: css`
740
- font-size: 1.5rem;
741
- line-height: 1.5rem;
742
- `,
743
- 6: css`
744
- font-size: 1.25rem;
745
- line-height: 1.25rem;
746
- `
747
- };
748
- return css`
749
- ${headingMap[level] || ""}
750
- margin: 2.5rem 0 !important;
751
- font-weight: 400;
752
- `;
753
- });
754
666
  return {
755
667
  id: id2,
756
668
  schema: () => ({
@@ -779,7 +691,7 @@ const heading = createNode((utils) => {
779
691
  `h${node.attrs["level"]}`,
780
692
  {
781
693
  id: node.attrs["id"] || node.textContent.split(" ").join("-").toLocaleLowerCase(),
782
- class: utils.getClassName(node.attrs, `heading h${node.attrs["level"]}`, style(node.attrs["level"]))
694
+ class: utils.getClassName(node.attrs, `heading h${node.attrs["level"]}`)
783
695
  },
784
696
  0
785
697
  ];
@@ -873,17 +785,12 @@ const heading = createNode((utils) => {
873
785
  const id$4 = "hr";
874
786
  const InsertHr = createCmdKey("InsertHr");
875
787
  const hr = createNode((utils) => {
876
- const style = utils.getStyle((themeTool, { css }) => css`
877
- height: ${themeTool.size.lineWidth};
878
- background-color: ${themeTool.palette("line")};
879
- border-width: 0;
880
- `);
881
788
  return {
882
789
  id: id$4,
883
790
  schema: () => ({
884
791
  group: "block",
885
792
  parseDOM: [{ tag: "hr" }],
886
- toDOM: (node) => ["hr", { class: utils.getClassName(node.attrs, id$4, style) }],
793
+ toDOM: (node) => ["hr", { class: utils.getClassName(node.attrs, id$4) }],
887
794
  parseMarkdown: {
888
795
  match: ({ type }) => type === "thematicBreak",
889
796
  runner: (state, _, type) => {
@@ -930,115 +837,8 @@ const hr = createNode((utils) => {
930
837
  const ModifyImage = createCmdKey("ModifyImage");
931
838
  const InsertImage = createCmdKey("InsertImage");
932
839
  const id$3 = "image";
840
+ const key = new PluginKey("MILKDOWN_PLUGIN_IMAGE_INPUT");
933
841
  const image = createNode((utils, options) => {
934
- var _a, _b;
935
- const placeholder = __spreadValues({
936
- loading: "Loading...",
937
- empty: "Add an Image",
938
- failed: "Image loads failed"
939
- }, (_a = options == null ? void 0 : options.placeholder) != null ? _a : {});
940
- const isBlock = (_b = options == null ? void 0 : options.isBlock) != null ? _b : false;
941
- const containerStyle = utils.getStyle((themeTool, { css }) => css`
942
- display: inline-block;
943
- position: relative;
944
- text-align: center;
945
- font-size: 0;
946
- vertical-align: text-bottom;
947
- line-height: 1;
948
-
949
- ${isBlock ? `
950
- width: 100%;
951
- margin: 0 auto;
952
- ` : ""}
953
-
954
- &.ProseMirror-selectednode::after {
955
- content: '';
956
- background: ${themeTool.palette("secondary", 0.38)};
957
- position: absolute;
958
- top: 0;
959
- left: 0;
960
- right: 0;
961
- bottom: 0;
962
- }
963
-
964
- img {
965
- max-width: 100%;
966
- height: auto;
967
- object-fit: contain;
968
- margin: 0 2px;
969
- }
970
- .icon,
971
- .placeholder {
972
- display: none;
973
- }
974
-
975
- &.system {
976
- width: 100%;
977
- padding: 0 2rem;
978
-
979
- img {
980
- width: 0;
981
- height: 0;
982
- display: none;
983
- }
984
-
985
- .icon,
986
- .placeholder {
987
- display: inline;
988
- }
989
-
990
- box-sizing: border-box;
991
- height: 3rem;
992
- background-color: ${themeTool.palette("background")};
993
- border-radius: ${themeTool.size.radius};
994
- display: inline-flex;
995
- gap: 2rem;
996
- justify-content: flex-start;
997
- align-items: center;
998
- .placeholder {
999
- margin: 0;
1000
- line-height: 1;
1001
- &::before {
1002
- content: '';
1003
- font-size: 0.875rem;
1004
- color: ${themeTool.palette("neutral", 0.6)};
1005
- }
1006
- }
1007
- }
1008
-
1009
- &.loading {
1010
- .placeholder {
1011
- &::before {
1012
- content: '${placeholder.loading}';
1013
- }
1014
- }
1015
- }
1016
-
1017
- &.empty {
1018
- .placeholder {
1019
- &::before {
1020
- content: '${placeholder.empty}';
1021
- }
1022
- }
1023
- }
1024
-
1025
- &.failed {
1026
- .placeholder {
1027
- &::before {
1028
- content: '${placeholder.failed}';
1029
- }
1030
- }
1031
- }
1032
- `);
1033
- const style = utils.getStyle((_, { css }) => css`
1034
- display: inline-block;
1035
- margin: 0 auto;
1036
- object-fit: contain;
1037
- width: 100%;
1038
- position: relative;
1039
- height: auto;
1040
- text-align: center;
1041
- `);
1042
842
  return {
1043
843
  id: "image",
1044
844
  schema: () => ({
@@ -1053,10 +853,7 @@ const image = createNode((utils, options) => {
1053
853
  attrs: {
1054
854
  src: { default: "" },
1055
855
  alt: { default: null },
1056
- title: { default: null },
1057
- failed: { default: false },
1058
- loading: { default: true },
1059
- width: { default: null }
856
+ title: { default: null }
1060
857
  },
1061
858
  parseDOM: [
1062
859
  {
@@ -1066,8 +863,6 @@ const image = createNode((utils, options) => {
1066
863
  throw new Error();
1067
864
  }
1068
865
  return {
1069
- failed: dom.classList.contains("failed"),
1070
- loading: dom.classList.contains("loading"),
1071
866
  src: dom.getAttribute("src") || "",
1072
867
  alt: dom.getAttribute("alt"),
1073
868
  title: dom.getAttribute("title") || dom.getAttribute("alt"),
@@ -1080,7 +875,7 @@ const image = createNode((utils, options) => {
1080
875
  return [
1081
876
  "img",
1082
877
  __spreadProps(__spreadValues({}, node.attrs), {
1083
- class: utils.getClassName(node.attrs, id$3, node.attrs["failed"] ? "failed" : "", node.attrs["loading"] ? "loading" : "", style)
878
+ class: utils.getClassName(node.attrs, id$3)
1084
879
  })
1085
880
  ];
1086
881
  },
@@ -1140,103 +935,90 @@ const image = createNode((utils, options) => {
1140
935
  return tr;
1141
936
  })
1142
937
  ],
1143
- view: (ctx) => (node, view, getPos) => {
1144
- const nodeType = node.type;
1145
- const createIcon = ctx.get(themeToolCtx).slots.icon;
1146
- const container = document.createElement("span");
1147
- container.className = utils.getClassName(node.attrs, id$3, containerStyle);
1148
- const content = document.createElement("img");
1149
- container.append(content);
1150
- let icon = createIcon("image");
1151
- const placeholder2 = document.createElement("span");
1152
- placeholder2.classList.add("placeholder");
1153
- container.append(icon, placeholder2);
1154
- const setIcon = (name) => {
1155
- const nextIcon = createIcon(name);
1156
- container.replaceChild(nextIcon, icon);
1157
- icon = nextIcon;
1158
- };
1159
- const loadImage = (src2) => {
1160
- container.classList.add("system", "loading");
1161
- setIcon("loading");
1162
- const img = document.createElement("img");
1163
- img.src = src2;
1164
- img.onerror = () => {
1165
- const pos = getPos();
1166
- if (!pos)
1167
- return;
1168
- const { tr } = view.state;
1169
- const _tr = tr.setNodeMarkup(pos, nodeType, __spreadProps(__spreadValues({}, node.attrs), {
1170
- src: src2,
1171
- loading: false,
1172
- failed: true
1173
- }));
1174
- view.dispatch(_tr);
1175
- };
1176
- img.onload = () => {
1177
- const { tr } = view.state;
1178
- const pos = getPos();
1179
- if (!pos)
1180
- return;
1181
- const _tr = tr.setNodeMarkup(pos, nodeType, __spreadProps(__spreadValues({}, node.attrs), {
1182
- width: img.width,
1183
- src: src2,
1184
- loading: false,
1185
- failed: false
1186
- }));
1187
- view.dispatch(_tr);
1188
- };
1189
- };
1190
- const { src, loading, title, alt, width } = node.attrs;
1191
- content.src = src;
1192
- content.title = title || alt;
1193
- content.alt = alt;
1194
- if (width) {
1195
- content.width = width;
1196
- }
1197
- if (src.length === 0) {
1198
- container.classList.add("system", "empty");
1199
- setIcon("image");
1200
- } else if (loading) {
1201
- loadImage(src);
938
+ view: () => (node) => {
939
+ var _a, _b;
940
+ let currNode = node;
941
+ const placeholder = (_a = options == null ? void 0 : options.placeholder) != null ? _a : "Add an Image";
942
+ const isBlock = (_b = options == null ? void 0 : options.isBlock) != null ? _b : false;
943
+ const renderer = utils.themeManager.get("image", {
944
+ placeholder,
945
+ isBlock
946
+ });
947
+ if (!renderer) {
948
+ return {};
1202
949
  }
950
+ const { dom, onUpdate } = renderer;
951
+ onUpdate(currNode);
1203
952
  return {
1204
- dom: container,
953
+ dom,
1205
954
  update: (updatedNode) => {
1206
955
  if (updatedNode.type.name !== id$3)
1207
956
  return false;
1208
- const { src: src2, alt: alt2, title: title2, loading: loading2, failed, width: width2 } = updatedNode.attrs;
1209
- content.src = src2;
1210
- content.alt = alt2;
1211
- content.title = title2 || alt2;
1212
- if (width2) {
1213
- content.width = width2;
1214
- }
1215
- if (loading2) {
1216
- loadImage(src2);
1217
- return true;
1218
- }
1219
- if (failed) {
1220
- container.classList.remove("loading", "empty");
1221
- container.classList.add("system", "failed");
1222
- setIcon("brokenImage");
1223
- return true;
1224
- }
1225
- if (src2.length > 0) {
1226
- container.classList.remove("system", "empty", "loading");
1227
- return true;
1228
- }
1229
- container.classList.add("system", "empty");
1230
- setIcon("image");
957
+ currNode = updatedNode;
958
+ onUpdate(currNode);
1231
959
  return true;
1232
960
  },
1233
961
  selectNode: () => {
1234
- container.classList.add("ProseMirror-selectednode");
962
+ dom.classList.add("ProseMirror-selectednode");
1235
963
  },
1236
964
  deselectNode: () => {
1237
- container.classList.remove("ProseMirror-selectednode");
965
+ dom.classList.remove("ProseMirror-selectednode");
1238
966
  }
1239
967
  };
968
+ },
969
+ prosePlugins: (type, ctx) => {
970
+ return [
971
+ new Plugin({
972
+ key,
973
+ view: (editorView) => {
974
+ var _a, _b, _c;
975
+ const inputChipRenderer = utils.themeManager.get("input-chip", {
976
+ placeholder: (_b = (_a = options == null ? void 0 : options.input) == null ? void 0 : _a.placeholder) != null ? _b : "Input Image Link",
977
+ buttonText: (_c = options == null ? void 0 : options.input) == null ? void 0 : _c.buttonText,
978
+ onUpdate: (value) => {
979
+ ctx.get(commandsCtx).call(ModifyImage, value);
980
+ }
981
+ });
982
+ if (!inputChipRenderer)
983
+ return {};
984
+ const shouldDisplay = (view) => {
985
+ return Boolean(type && findSelectedNodeOfType(view.state.selection, type));
986
+ };
987
+ const getCurrentLink = (view) => {
988
+ const result = findSelectedNodeOfType(view.state.selection, type);
989
+ if (!result)
990
+ return;
991
+ const value = result.node.attrs["src"];
992
+ return value;
993
+ };
994
+ const renderByView = (view) => {
995
+ if (!view.editable) {
996
+ return;
997
+ }
998
+ const display = shouldDisplay(view);
999
+ if (display) {
1000
+ inputChipRenderer.show(view);
1001
+ inputChipRenderer.update(getCurrentLink(view));
1002
+ } else {
1003
+ inputChipRenderer.hide();
1004
+ }
1005
+ };
1006
+ inputChipRenderer.init(editorView);
1007
+ renderByView(editorView);
1008
+ return {
1009
+ update: (view, prevState) => {
1010
+ const isEqualSelection = (prevState == null ? void 0 : prevState.doc.eq(view.state.doc)) && prevState.selection.eq(view.state.selection);
1011
+ if (isEqualSelection)
1012
+ return;
1013
+ renderByView(view);
1014
+ },
1015
+ destroy: () => {
1016
+ inputChipRenderer.destroy();
1017
+ }
1018
+ };
1019
+ }
1020
+ })
1021
+ ];
1240
1022
  }
1241
1023
  };
1242
1024
  });
@@ -1244,58 +1026,43 @@ const id$2 = "list_item";
1244
1026
  const SplitListItem = createCmdKey("SplitListItem");
1245
1027
  const SinkListItem = createCmdKey("SinkListItem");
1246
1028
  const LiftListItem = createCmdKey("LiftListItem");
1247
- const listItem = createNode((utils) => {
1248
- const style = utils.getStyle((themeTool, { css }) => css`
1249
- &,
1250
- & > * {
1251
- margin: 0.5rem 0;
1252
- }
1253
-
1254
- &,
1255
- li {
1256
- &::marker {
1257
- color: ${themeTool.palette("primary")};
1258
- }
1259
- }
1260
- `);
1261
- return {
1262
- id: id$2,
1263
- schema: () => ({
1264
- group: "listItem",
1265
- content: "paragraph block*",
1266
- defining: true,
1267
- parseDOM: [{ tag: "li" }],
1268
- toDOM: (node) => ["li", { class: utils.getClassName(node.attrs, "list-item", style) }, 0],
1269
- parseMarkdown: {
1270
- match: ({ type, checked }) => type === "listItem" && checked === null,
1271
- runner: (state, node, type) => {
1272
- state.openNode(type);
1273
- state.next(node.children);
1274
- state.closeNode();
1275
- }
1276
- },
1277
- toMarkdown: {
1278
- match: (node) => node.type.name === id$2,
1279
- runner: (state, node) => {
1280
- state.openNode("listItem");
1281
- state.next(node.content);
1282
- state.closeNode();
1283
- }
1029
+ const listItem = createNode((utils) => ({
1030
+ id: id$2,
1031
+ schema: () => ({
1032
+ group: "listItem",
1033
+ content: "paragraph block*",
1034
+ defining: true,
1035
+ parseDOM: [{ tag: "li" }],
1036
+ toDOM: (node) => ["li", { class: utils.getClassName(node.attrs, "list-item") }, 0],
1037
+ parseMarkdown: {
1038
+ match: ({ type, checked }) => type === "listItem" && checked === null,
1039
+ runner: (state, node, type) => {
1040
+ state.openNode(type);
1041
+ state.next(node.children);
1042
+ state.closeNode();
1043
+ }
1044
+ },
1045
+ toMarkdown: {
1046
+ match: (node) => node.type.name === id$2,
1047
+ runner: (state, node) => {
1048
+ state.openNode("listItem");
1049
+ state.next(node.content);
1050
+ state.closeNode();
1284
1051
  }
1285
- }),
1286
- inputRules: (nodeType) => [wrappingInputRule(/^\s*([-+*])\s$/, nodeType)],
1287
- commands: (nodeType) => [
1288
- createCmd(SplitListItem, () => splitListItem(nodeType)),
1289
- createCmd(SinkListItem, () => sinkListItem(nodeType)),
1290
- createCmd(LiftListItem, () => liftListItem(nodeType))
1291
- ],
1292
- shortcuts: {
1293
- [SupportedKeys.NextListItem]: createShortcut(SplitListItem, "Enter"),
1294
- [SupportedKeys.SinkListItem]: createShortcut(SinkListItem, "Mod-]"),
1295
- [SupportedKeys.LiftListItem]: createShortcut(LiftListItem, "Mod-[")
1296
1052
  }
1297
- };
1298
- });
1053
+ }),
1054
+ inputRules: (nodeType) => [wrappingInputRule(/^\s*([-+*])\s$/, nodeType)],
1055
+ commands: (nodeType) => [
1056
+ createCmd(SplitListItem, () => splitListItem(nodeType)),
1057
+ createCmd(SinkListItem, () => sinkListItem(nodeType)),
1058
+ createCmd(LiftListItem, () => liftListItem(nodeType))
1059
+ ],
1060
+ shortcuts: {
1061
+ [SupportedKeys.NextListItem]: createShortcut(SplitListItem, "Enter"),
1062
+ [SupportedKeys.SinkListItem]: createShortcut(SinkListItem, "Mod-]"),
1063
+ [SupportedKeys.LiftListItem]: createShortcut(LiftListItem, "Mod-[")
1064
+ }
1065
+ }));
1299
1066
  const WrapInOrderedList = createCmdKey("WrapInOrderedList");
1300
1067
  const id$1 = "ordered_list";
1301
1068
  const orderedList = createNode((utils) => ({
@@ -1352,20 +1119,13 @@ const orderedList = createNode((utils) => ({
1352
1119
  const TurnIntoText = createCmdKey("TurnIntoText");
1353
1120
  const id = "paragraph";
1354
1121
  const paragraph = createNode((utils) => {
1355
- const style = utils.getStyle((_, { css }) => {
1356
- return css`
1357
- font-size: 1rem;
1358
- line-height: 1.5;
1359
- letter-spacing: 0.5px;
1360
- `;
1361
- });
1362
1122
  return {
1363
1123
  id,
1364
1124
  schema: () => ({
1365
1125
  content: "inline*",
1366
1126
  group: "block",
1367
1127
  parseDOM: [{ tag: "p" }],
1368
- toDOM: (node) => ["p", { class: utils.getClassName(node.attrs, id, style) }, 0],
1128
+ toDOM: (node) => ["p", { class: utils.getClassName(node.attrs, id) }, 0],
1369
1129
  parseMarkdown: {
1370
1130
  match: (node) => node.type === "paragraph",
1371
1131
  runner: (state, node, type) => {