@milkdown/preset-gfm 5.4.1 → 6.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/README.md +4 -4
  2. package/lib/{src/auto-link.d.ts → auto-link.d.ts} +0 -0
  3. package/lib/auto-link.d.ts.map +1 -0
  4. package/lib/footnote/definition.d.ts +7 -0
  5. package/lib/footnote/definition.d.ts.map +1 -0
  6. package/lib/footnote/index.d.ts +3 -0
  7. package/lib/footnote/index.d.ts.map +1 -0
  8. package/lib/footnote/reference.d.ts +7 -0
  9. package/lib/footnote/reference.d.ts.map +1 -0
  10. package/lib/footnote/utils.d.ts +3 -0
  11. package/lib/footnote/utils.d.ts.map +1 -0
  12. package/lib/index.d.ts +37 -1
  13. package/lib/index.d.ts.map +1 -0
  14. package/lib/index.es.js +572 -443
  15. package/lib/index.es.js.map +1 -1
  16. package/lib/{src/strike-through.d.ts → strike-through.d.ts} +1 -1
  17. package/lib/strike-through.d.ts.map +1 -0
  18. package/lib/{src/supported-keys.d.ts → supported-keys.d.ts} +0 -0
  19. package/lib/supported-keys.d.ts.map +1 -0
  20. package/lib/{src/table → table}/command.d.ts +0 -0
  21. package/lib/table/command.d.ts.map +1 -0
  22. package/lib/{src/table → table}/index.d.ts +0 -0
  23. package/lib/table/index.d.ts.map +1 -0
  24. package/lib/{src/table → table}/nodes/index.d.ts +7 -6
  25. package/lib/table/nodes/index.d.ts.map +1 -0
  26. package/lib/{src/table → table}/nodes/schema.d.ts +0 -0
  27. package/lib/table/nodes/schema.d.ts.map +1 -0
  28. package/lib/{src/table → table}/operator-plugin/actions.d.ts +0 -0
  29. package/lib/table/operator-plugin/actions.d.ts.map +1 -0
  30. package/lib/{src/table → table}/operator-plugin/calc-pos.d.ts +0 -0
  31. package/lib/table/operator-plugin/calc-pos.d.ts.map +1 -0
  32. package/lib/{src/table → table}/operator-plugin/constant.d.ts +0 -0
  33. package/lib/table/operator-plugin/constant.d.ts.map +1 -0
  34. package/lib/{src/table → table}/operator-plugin/helper.d.ts +0 -0
  35. package/lib/table/operator-plugin/helper.d.ts.map +1 -0
  36. package/lib/{src/table → table}/operator-plugin/index.d.ts +0 -0
  37. package/lib/table/operator-plugin/index.d.ts.map +1 -0
  38. package/lib/table/operator-plugin/style.d.ts +3 -0
  39. package/lib/table/operator-plugin/style.d.ts.map +1 -0
  40. package/lib/{src/table → table}/operator-plugin/widget.d.ts +0 -0
  41. package/lib/table/operator-plugin/widget.d.ts.map +1 -0
  42. package/lib/{src/table → table}/utils.d.ts +1 -0
  43. package/lib/table/utils.d.ts.map +1 -0
  44. package/lib/{src/task-list-item.d.ts → task-list-item.d.ts} +1 -1
  45. package/lib/task-list-item.d.ts.map +1 -0
  46. package/package.json +36 -12
  47. package/src/auto-link.ts +1 -1
  48. package/src/footnote/definition.ts +181 -0
  49. package/src/footnote/index.ts +3 -0
  50. package/src/footnote/reference.ts +153 -0
  51. package/src/footnote/utils.ts +4 -0
  52. package/src/index.ts +5 -0
  53. package/src/strike-through.ts +2 -9
  54. package/src/table/nodes/index.ts +20 -14
  55. package/src/table/operator-plugin/actions.ts +9 -9
  56. package/src/table/operator-plugin/helper.ts +1 -1
  57. package/src/table/operator-plugin/index.ts +8 -6
  58. package/src/table/operator-plugin/style.ts +109 -37
  59. package/src/table/operator-plugin/widget.ts +3 -4
  60. package/src/table/utils.ts +9 -6
  61. package/src/task-list-item.ts +65 -130
  62. package/lib/src/auto-link.d.ts.map +0 -1
  63. package/lib/src/index.d.ts +0 -36
  64. package/lib/src/index.d.ts.map +0 -1
  65. package/lib/src/strike-through.d.ts.map +0 -1
  66. package/lib/src/supported-keys.d.ts.map +0 -1
  67. package/lib/src/table/command.d.ts.map +0 -1
  68. package/lib/src/table/index.d.ts.map +0 -1
  69. package/lib/src/table/nodes/index.d.ts.map +0 -1
  70. package/lib/src/table/nodes/schema.d.ts.map +0 -1
  71. package/lib/src/table/nodes/style.d.ts +0 -3
  72. package/lib/src/table/nodes/style.d.ts.map +0 -1
  73. package/lib/src/table/operator-plugin/actions.d.ts.map +0 -1
  74. package/lib/src/table/operator-plugin/calc-pos.d.ts.map +0 -1
  75. package/lib/src/table/operator-plugin/constant.d.ts.map +0 -1
  76. package/lib/src/table/operator-plugin/helper.d.ts.map +0 -1
  77. package/lib/src/table/operator-plugin/index.d.ts.map +0 -1
  78. package/lib/src/table/operator-plugin/style.d.ts +0 -3
  79. package/lib/src/table/operator-plugin/style.d.ts.map +0 -1
  80. package/lib/src/table/operator-plugin/widget.d.ts.map +0 -1
  81. package/lib/src/table/utils.d.ts.map +0 -1
  82. package/lib/src/task-list-item.d.ts.map +0 -1
  83. package/src/table/nodes/style.ts +0 -170
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))
@@ -19,11 +19,11 @@ var __spreadValues = (a, b) => {
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
  import { SupportedKeys as SupportedKeys$2, commonmark, commands as commands$1 } from "@milkdown/preset-commonmark";
21
21
  export { InsertHardbreak, InsertHr, InsertImage, LiftListItem, ModifyImage, ModifyLink, SinkListItem, SplitListItem, ToggleBold, ToggleInlineCode, ToggleItalic, ToggleLink, TurnIntoCodeFence, TurnIntoHeading, TurnIntoText, WrapInBlockquote, WrapInBulletList, WrapInOrderedList, blockquote, bulletList, codeFence, codeInline, commonmark, commonmarkNodes, commonmarkPlugins, doc, em, hardbreak, heading, hr, image, link, listItem, orderedList, paragraph, strong, text } from "@milkdown/preset-commonmark";
22
- import { $prose, createPlugin, createShortcut, createMark, createNode, AtomList, $remark } from "@milkdown/utils";
22
+ import { $prose, createNode, createPlugin, createShortcut, createMark, AtomList, $remark } from "@milkdown/utils";
23
23
  import remarkGFM from "remark-gfm";
24
- import { inputRules, InputRule, isInTable, Selection, findParentNode, TableMap, tableNodeTypes, CellSelection, cloneTr, addColumnBefore, addColumnAfter, selectedRect, setCellAttr, deleteTable, deleteColumn, deleteRow, calculateNodePosition, Decoration, Plugin, PluginKey, DecorationSet, tableNodes, TextSelection, goToNextCell, columnResizing, tableEditing, markRule, toggleMark, wrappingInputRule, splitListItem, sinkListItem, liftListItem, wrapIn } from "@milkdown/prose";
25
- import { themeToolCtx, createCmdKey, schemaCtx, createCmd } from "@milkdown/core";
26
- const urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;
24
+ import { inputRules, InputRule, PluginKey, NodeSelection, findSelectedNodeOfType, wrappingInputRule, Plugin, isInTable, Selection, findParentNode, TableMap, CellSelection, cloneTr, tableNodeTypes, addColumnBefore, addColumnAfter, selectedRect, setCellAttr, deleteTable, deleteColumn, deleteRow, calculateNodePosition, Decoration, DecorationSet, tableNodes, TextSelection, goToNextCell, columnResizing, tableEditing, markRule, toggleMark, splitListItem, sinkListItem, liftListItem, wrapIn } from "@milkdown/prose";
25
+ import { createCmdKey, editorViewCtx, createCmd, commandsCtx, themeManagerCtx, ThemeIcon, getPalette, ThemeSize, ThemeBorder, ThemeShadow, schemaCtx } from "@milkdown/core";
26
+ const urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)$/;
27
27
  const proseUrlPlugin = () => inputRules({
28
28
  rules: [
29
29
  new InputRule(urlRegex, (state, match, start, end) => {
@@ -36,6 +36,298 @@ const proseUrlPlugin = () => inputRules({
36
36
  ]
37
37
  });
38
38
  const urlPlugin = $prose(() => proseUrlPlugin());
39
+ const getFootnoteRefId = (label) => `milkdown_footnote_ref_${label}`;
40
+ const getFootnoteDefId = (label) => `milkdown_footnote_def_${label}`;
41
+ const key$1 = new PluginKey("MILKDOWN_PLUGIN_FOOTNOTE_DEF_INPUT");
42
+ const ModifyFootnoteDef = createCmdKey("ModifyFootnoteDef");
43
+ const footnoteDefinition = createNode((utils) => {
44
+ const id2 = "footnote_definition";
45
+ const markdownId = "footnoteDefinition";
46
+ return {
47
+ id: id2,
48
+ schema: (ctx) => ({
49
+ group: "block",
50
+ content: "block+",
51
+ defining: true,
52
+ attrs: {
53
+ label: {
54
+ default: ""
55
+ }
56
+ },
57
+ parseDOM: [
58
+ {
59
+ tag: `div[data-type="${id2}"]`,
60
+ getAttrs: (dom) => {
61
+ if (!(dom instanceof HTMLElement)) {
62
+ throw new Error();
63
+ }
64
+ return {
65
+ label: dom.dataset["label"]
66
+ };
67
+ }
68
+ }
69
+ ],
70
+ toDOM: (node) => {
71
+ const label = node.attrs["label"];
72
+ const className = utils.getClassName(node.attrs, "footnote-definition");
73
+ const dt = document.createElement("dt");
74
+ dt.textContent = `[ ${label} ]:`;
75
+ dt.onclick = () => {
76
+ const view = ctx.get(editorViewCtx);
77
+ const selection = NodeSelection.create(view.state.doc, view.state.selection.from - 2);
78
+ view.dispatch(view.state.tr.setSelection(selection));
79
+ };
80
+ return [
81
+ "div",
82
+ {
83
+ class: className,
84
+ "data-label": label,
85
+ "data-type": id2,
86
+ id: getFootnoteDefId(label)
87
+ },
88
+ ["div", { class: "footnote-definition_content" }, dt, ["dd", 0]],
89
+ [
90
+ "div",
91
+ { class: "footnote-definition_anchor" },
92
+ [
93
+ "a",
94
+ {
95
+ href: `#${getFootnoteRefId(label)}`,
96
+ "content-editable": "false",
97
+ class: className
98
+ },
99
+ "\u21A9"
100
+ ]
101
+ ]
102
+ ];
103
+ },
104
+ parseMarkdown: {
105
+ match: ({ type }) => type === markdownId,
106
+ runner: (state, node, type) => {
107
+ state.openNode(type, {
108
+ label: node["label"]
109
+ }).next(node.children).closeNode();
110
+ }
111
+ },
112
+ toMarkdown: {
113
+ match: (node) => node.type.name === id2,
114
+ runner: (state, node) => {
115
+ state.openNode(markdownId, void 0, {
116
+ label: node.attrs["label"],
117
+ identifier: node.attrs["label"]
118
+ }).next(node.content).closeNode();
119
+ }
120
+ }
121
+ }),
122
+ commands: (nodeType) => [
123
+ createCmd(ModifyFootnoteDef, (label = "") => (state, dispatch) => {
124
+ const node = findSelectedNodeOfType(state.selection, nodeType);
125
+ if (!node)
126
+ return false;
127
+ const { tr } = state;
128
+ const _tr = tr.setNodeMarkup(node.pos, void 0, __spreadProps(__spreadValues({}, node.node.attrs), { label }));
129
+ dispatch == null ? void 0 : dispatch(_tr.setSelection(NodeSelection.create(_tr.doc, node.pos)));
130
+ return true;
131
+ })
132
+ ],
133
+ inputRules: (nodeType) => [
134
+ wrappingInputRule(/(?:\[\^)([^:]+)(?::)$/, nodeType, (match) => {
135
+ var _a;
136
+ const label = (_a = match[1]) != null ? _a : "footnote";
137
+ return {
138
+ label
139
+ };
140
+ })
141
+ ],
142
+ prosePlugins: (type, ctx) => {
143
+ const inputChipRenderer = utils.themeManager.get("input-chip", {
144
+ placeholder: "Input Footnote Label",
145
+ onUpdate: (value) => {
146
+ ctx.get(commandsCtx).call(ModifyFootnoteDef, value);
147
+ },
148
+ isBindMode: true
149
+ });
150
+ const shouldDisplay = (view) => {
151
+ return Boolean(type && findSelectedNodeOfType(view.state.selection, type));
152
+ };
153
+ const getCurrentLabel = (view) => {
154
+ const result = findSelectedNodeOfType(view.state.selection, type);
155
+ if (!result)
156
+ return;
157
+ const value = result.node.attrs["label"];
158
+ return value;
159
+ };
160
+ const renderByView = (view) => {
161
+ if (!view.editable) {
162
+ return;
163
+ }
164
+ const display = shouldDisplay(view);
165
+ if (display) {
166
+ inputChipRenderer.show(view);
167
+ inputChipRenderer.update(getCurrentLabel(view));
168
+ } else {
169
+ inputChipRenderer.hide();
170
+ }
171
+ };
172
+ return [
173
+ new Plugin({
174
+ key: key$1,
175
+ view: (editorView) => {
176
+ inputChipRenderer.init(editorView);
177
+ renderByView(editorView);
178
+ return {
179
+ update: (view, prevState) => {
180
+ const isEqualSelection = (prevState == null ? void 0 : prevState.doc.eq(view.state.doc)) && prevState.selection.eq(view.state.selection);
181
+ if (isEqualSelection)
182
+ return;
183
+ renderByView(view);
184
+ },
185
+ destroy: () => {
186
+ inputChipRenderer.destroy();
187
+ }
188
+ };
189
+ }
190
+ })
191
+ ];
192
+ }
193
+ };
194
+ });
195
+ const ModifyFootnoteRef = createCmdKey("ModifyFootnoteRef");
196
+ const key = new PluginKey("MILKDOWN_PLUGIN_FOOTNOTE_REF_INPUT");
197
+ const footnoteReference = createNode((utils) => {
198
+ const id2 = "footnote_reference";
199
+ return {
200
+ id: id2,
201
+ schema: () => ({
202
+ group: "inline",
203
+ inline: true,
204
+ atom: true,
205
+ attrs: {
206
+ label: {
207
+ default: ""
208
+ }
209
+ },
210
+ parseDOM: [
211
+ {
212
+ tag: `sup[data-type="${id2}"]`,
213
+ getAttrs: (dom) => {
214
+ if (!(dom instanceof HTMLElement)) {
215
+ throw new Error();
216
+ }
217
+ return {
218
+ label: dom.dataset["label"]
219
+ };
220
+ }
221
+ }
222
+ ],
223
+ toDOM: (node) => {
224
+ const label = node.attrs["label"];
225
+ return [
226
+ "sup",
227
+ {
228
+ "data-label": label,
229
+ "data-type": id2,
230
+ id: getFootnoteRefId(label)
231
+ },
232
+ ["a", { href: `#${getFootnoteDefId(label)}` }, `[${label}]`]
233
+ ];
234
+ },
235
+ parseMarkdown: {
236
+ match: ({ type }) => type === "footnoteReference",
237
+ runner: (state, node, type) => {
238
+ state.addNode(type, {
239
+ label: node["label"]
240
+ });
241
+ }
242
+ },
243
+ toMarkdown: {
244
+ match: (node) => node.type.name === id2,
245
+ runner: (state, node) => {
246
+ state.addNode("footnoteReference", void 0, void 0, {
247
+ label: node.attrs["label"],
248
+ identifier: node.attrs["label"]
249
+ });
250
+ }
251
+ }
252
+ }),
253
+ commands: (nodeType) => [
254
+ createCmd(ModifyFootnoteRef, (label = "") => (state, dispatch) => {
255
+ const node = findSelectedNodeOfType(state.selection, nodeType);
256
+ if (!node)
257
+ return false;
258
+ const { tr } = state;
259
+ const _tr = tr.setNodeMarkup(node.pos, void 0, __spreadProps(__spreadValues({}, node.node.attrs), { label }));
260
+ dispatch == null ? void 0 : dispatch(_tr.setSelection(NodeSelection.create(_tr.doc, node.pos)));
261
+ return true;
262
+ })
263
+ ],
264
+ inputRules: (nodeType) => [
265
+ new InputRule(/(?:\[\^)([^\]]+)(?:\])$/, (state, match, start, end) => {
266
+ const $start = state.doc.resolve(start);
267
+ const index = $start.index();
268
+ const $end = state.doc.resolve(end);
269
+ if (!$start.parent.canReplaceWith(index, $end.index(), nodeType)) {
270
+ return null;
271
+ }
272
+ const label = match[1];
273
+ return state.tr.replaceRangeWith(start, end, nodeType.create({
274
+ label
275
+ }));
276
+ })
277
+ ],
278
+ prosePlugins: (type, ctx) => {
279
+ const inputChipRenderer = utils.themeManager.get("input-chip", {
280
+ placeholder: "Input Footnote Label",
281
+ onUpdate: (value) => {
282
+ ctx.get(commandsCtx).call(ModifyFootnoteRef, value);
283
+ },
284
+ isBindMode: true
285
+ });
286
+ const shouldDisplay = (view) => {
287
+ return Boolean(type && findSelectedNodeOfType(view.state.selection, type));
288
+ };
289
+ const getCurrentLabel = (view) => {
290
+ const result = findSelectedNodeOfType(view.state.selection, type);
291
+ if (!result)
292
+ return;
293
+ const value = result.node.attrs["label"];
294
+ return value;
295
+ };
296
+ const renderByView = (view) => {
297
+ if (!view.editable) {
298
+ return;
299
+ }
300
+ const display = shouldDisplay(view);
301
+ if (display) {
302
+ inputChipRenderer.show(view);
303
+ inputChipRenderer.update(getCurrentLabel(view));
304
+ } else {
305
+ inputChipRenderer.hide();
306
+ }
307
+ };
308
+ return [
309
+ new Plugin({
310
+ key,
311
+ view: (editorView) => {
312
+ inputChipRenderer.init(editorView);
313
+ renderByView(editorView);
314
+ return {
315
+ update: (view, prevState) => {
316
+ const isEqualSelection = (prevState == null ? void 0 : prevState.doc.eq(view.state.doc)) && prevState.selection.eq(view.state.selection);
317
+ if (isEqualSelection)
318
+ return;
319
+ renderByView(view);
320
+ },
321
+ destroy: () => {
322
+ inputChipRenderer.destroy();
323
+ }
324
+ };
325
+ }
326
+ })
327
+ ];
328
+ }
329
+ };
330
+ });
39
331
  const exitTable = (node) => (state, dispatch) => {
40
332
  if (!isInTable(state)) {
41
333
  return false;
@@ -47,7 +339,7 @@ const exitTable = (node) => (state, dispatch) => {
47
339
  dispatch == null ? void 0 : dispatch(tr.scrollIntoView());
48
340
  return true;
49
341
  };
50
- const findTable = (selection) => findParentNode((node) => node.type.spec.tableRole === "table")(selection);
342
+ const findTable = (selection) => findParentNode((node) => node.type.spec["tableRole"] === "table")(selection);
51
343
  const getCellsInColumn = (columnIndex) => (selection) => {
52
344
  const table2 = findTable(selection);
53
345
  if (!table2)
@@ -131,10 +423,13 @@ const getCellsInTable = (selection) => {
131
423
  };
132
424
  const selectTable = (tr) => {
133
425
  const cells = getCellsInTable(tr.selection);
134
- if (cells) {
426
+ if (cells && cells[0]) {
135
427
  const $firstCell = tr.doc.resolve(cells[0].pos);
136
- const $lastCell = tr.doc.resolve(cells[cells.length - 1].pos);
137
- return cloneTr(tr.setSelection(new CellSelection($lastCell, $firstCell)));
428
+ const last = cells[cells.length - 1];
429
+ if (last) {
430
+ const $lastCell = tr.doc.resolve(last.pos);
431
+ return cloneTr(tr.setSelection(new CellSelection($lastCell, $firstCell)));
432
+ }
138
433
  }
139
434
  return tr;
140
435
  };
@@ -145,7 +440,7 @@ function addRowWithAlignment(tr, { map, tableStart, table: table2 }, row) {
145
440
  const { cell: cellType, row: rowType } = tableNodeTypes(table2.type.schema);
146
441
  const cells = Array(map.width).fill(0).map((_, col) => {
147
442
  const headerCol = table2.nodeAt(map.map[col]);
148
- return cellType.createAndFill({ alignment: headerCol == null ? void 0 : headerCol.attrs.alignment });
443
+ return cellType.createAndFill({ alignment: headerCol == null ? void 0 : headerCol.attrs["alignment"] });
149
444
  });
150
445
  tr.insert(rowPos, rowType.create(null, cells));
151
446
  return tr;
@@ -179,95 +474,87 @@ const calculateItem = (actions, view) => {
179
474
  item.$.classList.remove("hide");
180
475
  });
181
476
  };
182
- var Action;
183
- (function(Action2) {
184
- Action2[Action2["AddColLeft"] = 0] = "AddColLeft";
185
- Action2[Action2["AddColRight"] = 1] = "AddColRight";
186
- Action2[Action2["AddRowTop"] = 2] = "AddRowTop";
187
- Action2[Action2["AddRowBottom"] = 3] = "AddRowBottom";
188
- Action2[Action2["AlignLeft"] = 4] = "AlignLeft";
189
- Action2[Action2["AlignCenter"] = 5] = "AlignCenter";
190
- Action2[Action2["AlignRight"] = 6] = "AlignRight";
191
- Action2[Action2["Delete"] = 7] = "Delete";
192
- })(Action || (Action = {}));
193
- const createActions = (ctx) => ({
194
- [0]: {
195
- $: ctx.get(themeToolCtx).slots.icon("leftArrow"),
196
- command: () => addColumnBefore,
197
- disable: (view) => !getCellSelection(view).isColSelection()
198
- },
199
- [1]: {
200
- $: ctx.get(themeToolCtx).slots.icon("rightArrow"),
201
- command: () => addColumnAfter,
202
- disable: (view) => !getCellSelection(view).isColSelection()
203
- },
204
- [2]: {
205
- $: ctx.get(themeToolCtx).slots.icon("upArrow"),
206
- command: () => (state, dispatch) => {
207
- if (!isInTable(state))
208
- return false;
209
- if (dispatch) {
210
- const rect = selectedRect(state);
211
- dispatch(addRowWithAlignment(state.tr, rect, rect.top));
212
- }
213
- return true;
477
+ const createActions = (ctx) => {
478
+ var _a, _b, _c, _d, _e, _f, _g, _h;
479
+ return {
480
+ [0]: {
481
+ $: (_a = ctx.get(themeManagerCtx).get(ThemeIcon, "leftArrow")) == null ? void 0 : _a.dom,
482
+ command: () => addColumnBefore,
483
+ disable: (view) => !getCellSelection(view).isColSelection()
214
484
  },
215
- disable: (view) => !getCellSelection(view).isRowSelection() || getCellSelection(view).$head.parent.type.name === "table_header"
216
- },
217
- [3]: {
218
- $: ctx.get(themeToolCtx).slots.icon("downArrow"),
219
- command: () => (state, dispatch) => {
220
- if (!isInTable(state))
221
- return false;
222
- if (dispatch) {
223
- const rect = selectedRect(state);
224
- dispatch(addRowWithAlignment(state.tr, rect, rect.bottom));
225
- }
226
- return true;
485
+ [1]: {
486
+ $: (_b = ctx.get(themeManagerCtx).get(ThemeIcon, "rightArrow")) == null ? void 0 : _b.dom,
487
+ command: () => addColumnAfter,
488
+ disable: (view) => !getCellSelection(view).isColSelection()
227
489
  },
228
- disable: (view) => !getCellSelection(view).isRowSelection()
229
- },
230
- [4]: {
231
- $: ctx.get(themeToolCtx).slots.icon("alignLeft"),
232
- command: () => setCellAttr("alignment", "left"),
233
- disable: (view) => !getCellSelection(view).isColSelection()
234
- },
235
- [5]: {
236
- $: ctx.get(themeToolCtx).slots.icon("alignCenter"),
237
- command: () => setCellAttr("alignment", "center"),
238
- disable: (view) => !getCellSelection(view).isColSelection()
239
- },
240
- [6]: {
241
- $: ctx.get(themeToolCtx).slots.icon("alignRight"),
242
- command: () => setCellAttr("alignment", "right"),
243
- disable: (view) => !getCellSelection(view).isColSelection()
244
- },
245
- [7]: {
246
- $: ctx.get(themeToolCtx).slots.icon("delete"),
247
- command: (_, view) => {
248
- const selection = getCellSelection(view);
249
- const isCol = selection.isColSelection();
250
- const isRow = selection.isRowSelection();
251
- if (isCol && isRow) {
252
- return deleteTable;
253
- }
254
- if (isCol) {
255
- return deleteColumn;
256
- }
257
- return deleteRow;
490
+ [2]: {
491
+ $: (_c = ctx.get(themeManagerCtx).get(ThemeIcon, "upArrow")) == null ? void 0 : _c.dom,
492
+ command: () => (state, dispatch) => {
493
+ if (!isInTable(state))
494
+ return false;
495
+ if (dispatch) {
496
+ const rect = selectedRect(state);
497
+ dispatch(addRowWithAlignment(state.tr, rect, rect.top));
498
+ }
499
+ return true;
500
+ },
501
+ disable: (view) => !getCellSelection(view).isRowSelection() || getCellSelection(view).$head.parent.type.name === "table_header"
258
502
  },
259
- disable: (view) => {
260
- const selection = getCellSelection(view);
261
- if (selection.isRowSelection()) {
262
- if (selection.isColSelection()) {
503
+ [3]: {
504
+ $: (_d = ctx.get(themeManagerCtx).get(ThemeIcon, "downArrow")) == null ? void 0 : _d.dom,
505
+ command: () => (state, dispatch) => {
506
+ if (!isInTable(state))
263
507
  return false;
508
+ if (dispatch) {
509
+ const rect = selectedRect(state);
510
+ dispatch(addRowWithAlignment(state.tr, rect, rect.bottom));
264
511
  }
265
- return isFirstRowSelected(selection);
512
+ return true;
513
+ },
514
+ disable: (view) => !getCellSelection(view).isRowSelection()
515
+ },
516
+ [4]: {
517
+ $: (_e = ctx.get(themeManagerCtx).get(ThemeIcon, "alignLeft")) == null ? void 0 : _e.dom,
518
+ command: () => setCellAttr("alignment", "left"),
519
+ disable: (view) => !getCellSelection(view).isColSelection()
520
+ },
521
+ [5]: {
522
+ $: (_f = ctx.get(themeManagerCtx).get(ThemeIcon, "alignCenter")) == null ? void 0 : _f.dom,
523
+ command: () => setCellAttr("alignment", "center"),
524
+ disable: (view) => !getCellSelection(view).isColSelection()
525
+ },
526
+ [6]: {
527
+ $: (_g = ctx.get(themeManagerCtx).get(ThemeIcon, "alignRight")) == null ? void 0 : _g.dom,
528
+ command: () => setCellAttr("alignment", "right"),
529
+ disable: (view) => !getCellSelection(view).isColSelection()
530
+ },
531
+ [7]: {
532
+ $: (_h = ctx.get(themeManagerCtx).get(ThemeIcon, "delete")) == null ? void 0 : _h.dom,
533
+ command: (_, view) => {
534
+ const selection = getCellSelection(view);
535
+ const isCol = selection.isColSelection();
536
+ const isRow = selection.isRowSelection();
537
+ if (isCol && isRow) {
538
+ return deleteTable;
539
+ }
540
+ if (isCol) {
541
+ return deleteColumn;
542
+ }
543
+ return deleteRow;
544
+ },
545
+ disable: (view) => {
546
+ const selection = getCellSelection(view);
547
+ if (selection.isRowSelection()) {
548
+ if (selection.isColSelection()) {
549
+ return false;
550
+ }
551
+ return isFirstRowSelected(selection);
552
+ }
553
+ return false;
266
554
  }
267
- return false;
268
555
  }
269
- }
270
- });
556
+ };
557
+ };
271
558
  const calculatePosition = (view, dom) => {
272
559
  const { selection } = view.state;
273
560
  const isCol = selection.isColSelection();
@@ -285,61 +572,128 @@ const calculatePosition = (view, dom) => {
285
572
  return [top, left];
286
573
  });
287
574
  };
288
- var ToolTipPos;
289
- (function(ToolTipPos2) {
575
+ var ToolTipPos = /* @__PURE__ */ ((ToolTipPos2) => {
290
576
  ToolTipPos2["Left"] = "Left";
291
577
  ToolTipPos2["Top"] = "Top";
292
578
  ToolTipPos2["Point"] = "Point";
293
- })(ToolTipPos || (ToolTipPos = {}));
294
- const injectStyle$1 = ({ size, mixin, palette }, { css }) => {
295
- var _a, _b;
579
+ return ToolTipPos2;
580
+ })(ToolTipPos || {});
581
+ const injectStyle = (themeManager, { css, injectGlobal }) => {
582
+ const palette = getPalette(themeManager);
583
+ const radius = themeManager.get(ThemeSize, "radius");
584
+ const lineWidth = themeManager.get(ThemeSize, "lineWidth");
585
+ injectGlobal`
586
+ .milkdown {
587
+ .tableWrapper {
588
+ table {
589
+ width: calc(100% - 2em) !important;
590
+ margin: 1em 0 1em 1em !important;
591
+
592
+ .milkdown-cell-left,
593
+ .milkdown-cell-point,
594
+ .milkdown-cell-top {
595
+ position: absolute;
596
+
597
+ &::after {
598
+ cursor: pointer;
599
+ position: absolute;
600
+ top: 0;
601
+ left: 0;
602
+ height: 100%;
603
+ width: 100%;
604
+ display: block;
605
+ transition: all 0.2s ease-in-out;
606
+ background: ${palette("secondary", 0.12)};
607
+ content: '';
608
+ }
609
+
610
+ &:hover::after {
611
+ background: ${palette("secondary", 0.38)};
612
+ }
613
+ }
614
+
615
+ .milkdown-cell-left {
616
+ left: calc(-6px - 0.5em);
617
+ top: 0;
618
+ bottom: 0;
619
+ width: 0.5em;
620
+ }
621
+
622
+ .milkdown-cell-top {
623
+ left: 0;
624
+ right: 0;
625
+ top: calc(-6px - 0.5em);
626
+ height: 0.5em;
627
+ }
628
+
629
+ .milkdown-cell-point {
630
+ left: calc(-2px - 1em);
631
+ top: calc(-2px - 1em);
632
+ width: 1em;
633
+ height: 1em;
634
+
635
+ .icon {
636
+ position: absolute;
637
+ top: 0;
638
+ bottom: 0;
639
+ left: 0;
640
+ right: 0;
641
+ }
642
+ }
643
+ }
644
+ }
645
+ }
646
+ `;
296
647
  return css`
297
- display: inline-flex;
298
- cursor: pointer;
299
- z-index: 2;
648
+ display: inline-flex;
649
+ cursor: pointer;
650
+ z-index: 2;
300
651
 
301
- justify-content: space-evenly;
652
+ justify-content: space-evenly;
302
653
 
303
- position: absolute;
654
+ position: absolute;
304
655
 
305
- border-radius: ${size.radius};
656
+ border-radius: ${radius};
306
657
 
307
- ${(_a = mixin.border) == null ? void 0 : _a.call(mixin)};
658
+ ${themeManager.get(ThemeBorder, void 0)};
659
+ ${themeManager.get(ThemeShadow, void 0)};
308
660
 
309
- ${(_b = mixin.shadow) == null ? void 0 : _b.call(mixin)};
661
+ overflow: hidden;
662
+ background: ${palette("surface")};
310
663
 
311
- overflow: hidden;
312
- background: ${palette("surface")};
664
+ .icon {
665
+ position: relative;
666
+ color: ${palette("solid", 0.87)};
313
667
 
314
- .icon {
315
- position: relative;
316
- color: ${palette("solid", 0.87)};
668
+ width: 2em;
669
+ line-height: 2em;
670
+ text-align: center;
671
+ transition: all 0.4s ease-in-out;
317
672
 
318
- width: 3rem;
319
- line-height: 3rem;
320
- text-align: center;
321
- transition: all 0.4s ease-in-out;
322
- &:hover {
323
- background-color: ${palette("secondary", 0.12)};
324
- }
325
- &.active {
326
- color: ${palette("primary")};
673
+ &:hover {
674
+ background-color: ${palette("secondary", 0.12)};
675
+ }
676
+
677
+ &.active {
678
+ color: ${palette("primary")};
679
+ }
680
+
681
+ &:not(:last-child)::after {
682
+ content: '';
683
+ position: absolute;
684
+ right: 0;
685
+ top: 0;
686
+ width: ${lineWidth};
687
+ bottom: 0;
688
+ background: ${palette("line")};
689
+ }
327
690
  }
328
- &:not(:last-child)::after {
329
- content: '';
330
- position: absolute;
331
- right: 0px;
332
- top: 0;
333
- width: ${size.lineWidth};
334
- bottom: 0;
335
- background: ${palette("line")};
691
+
692
+ &.hide,
693
+ .hide {
694
+ display: none;
336
695
  }
337
- }
338
- &.hide,
339
- .hide {
340
- display: none;
341
- }
342
- `;
696
+ `;
343
697
  };
344
698
  const calculateClassName = (pos) => {
345
699
  switch (pos) {
@@ -356,11 +710,12 @@ const calculateClassName = (pos) => {
356
710
  }
357
711
  };
358
712
  function createWidget(ctx, cell, pos, index = 0) {
359
- const widget = Decoration.widget(cell.pos + 1, (view) => {
713
+ return Decoration.widget(cell.pos + 1, (view) => {
714
+ var _a;
360
715
  const div = document.createElement("div");
361
716
  div.classList.add(calculateClassName(pos));
362
717
  if (pos === ToolTipPos.Point) {
363
- div.appendChild(ctx.get(themeToolCtx).slots.icon("select"));
718
+ div.appendChild((_a = ctx.get(themeManagerCtx).get(ThemeIcon, "select")) == null ? void 0 : _a.dom);
364
719
  }
365
720
  div.addEventListener("mousedown", (e) => {
366
721
  if (!view)
@@ -383,15 +738,16 @@ function createWidget(ctx, cell, pos, index = 0) {
383
738
  });
384
739
  return div;
385
740
  });
386
- return widget;
387
741
  }
388
742
  const operatorPlugin = (ctx, utils) => {
389
743
  const items = createActions(ctx);
390
744
  const tooltip = document.createElement("div");
391
- const style = utils.getStyle(injectStyle$1);
392
- if (style) {
393
- tooltip.classList.add(style);
394
- }
745
+ utils.themeManager.onFlush(() => {
746
+ const style = utils.getStyle(injectStyle);
747
+ if (style) {
748
+ tooltip.classList.add(style);
749
+ }
750
+ });
395
751
  tooltip.classList.add("table-tooltip", "hide");
396
752
  return new Plugin({
397
753
  key: new PluginKey("MILKDOWN_TABLE_OP"),
@@ -473,172 +829,6 @@ const schema = tableNodes({
473
829
  }
474
830
  }
475
831
  });
476
- const proseTableStyle = ({ css }) => css`
477
- /* copy from https://github.com/ProseMirror/prosemirror-tables/blob/master/style/tables.css */
478
- .ProseMirror .tableWrapper {
479
- overflow-x: auto;
480
- }
481
- .ProseMirror table {
482
- border-collapse: collapse;
483
- table-layout: fixed;
484
- width: 100%;
485
- overflow: hidden;
486
- }
487
- .ProseMirror td,
488
- .ProseMirror th {
489
- vertical-align: top;
490
- box-sizing: border-box;
491
- position: relative;
492
- }
493
- .ProseMirror .column-resize-handle {
494
- position: absolute;
495
- right: -2px;
496
- top: 0;
497
- bottom: 0;
498
- width: 4px;
499
- z-index: 20;
500
- background-color: #adf;
501
- pointer-events: none;
502
- }
503
- .ProseMirror.resize-cursor {
504
- cursor: ew-resize;
505
- cursor: col-resize;
506
- }
507
- /* Give selected cells a blue overlay */
508
- .ProseMirror .selectedCell:after {
509
- z-index: 2;
510
- position: absolute;
511
- content: '';
512
- left: 0;
513
- right: 0;
514
- top: 0;
515
- bottom: 0;
516
- background: rgba(200, 200, 255, 0.4);
517
- pointer-events: none;
518
- }
519
- `;
520
- const injectStyle = (utils) => {
521
- return utils.getStyle(({ size, palette, mixin }, emotion) => {
522
- var _a, _b, _c;
523
- const css = emotion.injectGlobal;
524
- css`
525
- ${proseTableStyle(emotion)}
526
-
527
- .tableWrapper {
528
- margin: 0 !important;
529
-
530
- ${(_a = mixin.scrollbar) == null ? void 0 : _a.call(mixin, "x")};
531
-
532
- width: 100%;
533
-
534
- table {
535
- width: calc(100% - 2rem) !important;
536
- border-radius: ${size.radius};
537
- box-sizing: border-box;
538
- margin: 1rem 0 1rem 1rem !important;
539
- overflow: auto !important;
540
- * {
541
- margin: 0 !important;
542
- box-sizing: border-box;
543
- font-size: 1rem;
544
- }
545
- tr {
546
- ${(_b = mixin.border) == null ? void 0 : _b.call(mixin, "bottom")};
547
- }
548
-
549
- th {
550
- background: ${palette("background", 0.5)};
551
- font-weight: 400;
552
- }
553
-
554
- th,
555
- td {
556
- min-width: 100px;
557
- ${(_c = mixin.border) == null ? void 0 : _c.call(mixin)};
558
- text-align: left;
559
- position: relative;
560
- line-height: 3rem;
561
- box-sizing: border-box;
562
- height: 3rem;
563
- }
564
-
565
- .selectedCell {
566
- &::after {
567
- background: ${palette("secondary", 0.38)};
568
- }
569
- & ::selection {
570
- background: transparent;
571
- }
572
- }
573
-
574
- .column-resize-handle {
575
- background: ${palette("primary")};
576
- width: ${size.lineWidth};
577
- }
578
-
579
- th,
580
- td {
581
- padding: 0 1rem;
582
- p {
583
- line-height: unset !important;
584
- }
585
- }
586
-
587
- .milkdown-cell-left,
588
- .milkdown-cell-point,
589
- .milkdown-cell-top {
590
- position: absolute;
591
-
592
- &::after {
593
- cursor: pointer;
594
- position: absolute;
595
- top: 0;
596
- left: 0;
597
- height: 100%;
598
- width: 100%;
599
- display: block;
600
- transition: all 0.2s ease-in-out;
601
- background: ${palette("secondary", 0.12)};
602
- content: '';
603
- }
604
- &:hover::after {
605
- background: ${palette("secondary", 0.38)};
606
- }
607
- }
608
-
609
- .milkdown-cell-left {
610
- left: calc(-6px - 0.5rem);
611
- top: 0;
612
- bottom: 0;
613
- width: 0.5rem;
614
- }
615
-
616
- .milkdown-cell-top {
617
- left: 0;
618
- right: 0;
619
- top: calc(-6px - 0.5rem);
620
- height: 0.5rem;
621
- }
622
-
623
- .milkdown-cell-point {
624
- left: calc(-2px - 1rem);
625
- top: calc(-2px - 1rem);
626
- width: 1rem;
627
- height: 1rem;
628
-
629
- .icon {
630
- position: absolute;
631
- top: 0;
632
- bottom: 0;
633
- left: 0;
634
- right: 0;
635
- }
636
- }
637
- }
638
- }
639
- `;
640
- });
641
- };
642
832
  const SupportedKeys$1 = {
643
833
  NextCell: "NextCell",
644
834
  PrevCell: "PrevCell",
@@ -649,7 +839,6 @@ const NextCell = createCmdKey("NextCell");
649
839
  const BreakTable = createCmdKey("BreakTable");
650
840
  const InsertTable = createCmdKey("InsertTable");
651
841
  const table = createPlugin((utils) => {
652
- injectStyle(utils);
653
842
  return {
654
843
  schema: () => ({
655
844
  node: {
@@ -657,7 +846,7 @@ const table = createPlugin((utils) => {
657
846
  parseMarkdown: {
658
847
  match: (node) => node.type === "table",
659
848
  runner: (state, node, type) => {
660
- const align = node.align;
849
+ const align = node["align"];
661
850
  const children = node.children.map((x, i) => __spreadProps(__spreadValues({}, x), {
662
851
  align,
663
852
  isHeader: i === 0
@@ -676,7 +865,7 @@ const table = createPlugin((utils) => {
676
865
  return;
677
866
  const align = [];
678
867
  firstLine.forEach((cell) => {
679
- align.push(cell.attrs.alignment);
868
+ align.push(cell.attrs["alignment"]);
680
869
  });
681
870
  state.openNode("table", void 0, { align });
682
871
  state.next(node.content);
@@ -688,10 +877,10 @@ const table = createPlugin((utils) => {
688
877
  parseMarkdown: {
689
878
  match: (node) => node.type === "tableRow",
690
879
  runner: (state, node, type) => {
691
- const align = node.align;
880
+ const align = node["align"];
692
881
  const children = node.children.map((x, i) => __spreadProps(__spreadValues({}, x), {
693
882
  align: align[i],
694
- isHeader: node.isHeader
883
+ isHeader: node["isHeader"]
695
884
  }));
696
885
  state.openNode(type);
697
886
  state.next(children);
@@ -709,10 +898,10 @@ const table = createPlugin((utils) => {
709
898
  }),
710
899
  table_cell: __spreadProps(__spreadValues({}, schema.table_cell), {
711
900
  parseMarkdown: {
712
- match: (node) => node.type === "tableCell" && !node.isHeader,
901
+ match: (node) => node.type === "tableCell" && !node["isHeader"],
713
902
  runner: (state, node, type) => {
714
- const align = node.align;
715
- state.openNode(type, { alignment: align }).openNode(state.schema.nodes.paragraph).next(node.children).closeNode().closeNode();
903
+ const align = node["align"];
904
+ state.openNode(type, { alignment: align }).openNode(state.schema.nodes["paragraph"]).next(node.children).closeNode().closeNode();
716
905
  }
717
906
  },
718
907
  toMarkdown: {
@@ -724,11 +913,11 @@ const table = createPlugin((utils) => {
724
913
  }),
725
914
  table_header: __spreadProps(__spreadValues({}, schema.table_header), {
726
915
  parseMarkdown: {
727
- match: (node) => node.type === "tableCell" && !!node.isHeader,
916
+ match: (node) => node.type === "tableCell" && !!node["isHeader"],
728
917
  runner: (state, node, type) => {
729
- const align = node.align;
918
+ const align = node["align"];
730
919
  state.openNode(type, { alignment: align });
731
- state.openNode(state.schema.nodes.paragraph);
920
+ state.openNode(state.schema.nodes["paragraph"]);
732
921
  state.next(node.children);
733
922
  state.closeNode();
734
923
  state.closeNode();
@@ -758,7 +947,7 @@ const table = createPlugin((utils) => {
758
947
  commands: (_, ctx) => [
759
948
  createCmd(PrevCell, () => goToNextCell(-1)),
760
949
  createCmd(NextCell, () => goToNextCell(1)),
761
- createCmd(BreakTable, () => exitTable(ctx.get(schemaCtx).nodes.paragraph)),
950
+ createCmd(BreakTable, () => exitTable(ctx.get(schemaCtx).nodes["paragraph"])),
762
951
  createCmd(InsertTable, () => (state, dispatch) => {
763
952
  const { selection, tr } = state;
764
953
  const { from } = selection;
@@ -786,11 +975,8 @@ const SupportedKeys = __spreadProps(__spreadValues(__spreadValues({}, SupportedK
786
975
  TaskList: "TaskList"
787
976
  });
788
977
  const ToggleStrikeThrough = createCmdKey("ToggleStrikeThrough");
978
+ const id = "strike_through";
789
979
  const strikeThrough = createMark((utils) => {
790
- const id = "strike_through";
791
- const style = utils.getStyle((themeTool, { css }) => css`
792
- text-decoration-color: ${themeTool.palette("secondary")};
793
- `);
794
980
  return {
795
981
  id,
796
982
  schema: () => ({
@@ -798,7 +984,7 @@ const strikeThrough = createMark((utils) => {
798
984
  { tag: "del" },
799
985
  { style: "text-decoration", getAttrs: (value) => value === "line-through" }
800
986
  ],
801
- toDOM: (mark) => ["del", { class: utils.getClassName(mark.attrs, "strike-through", style) }],
987
+ toDOM: (mark) => ["del", { class: utils.getClassName(mark.attrs, "strike-through") }],
802
988
  parseMarkdown: {
803
989
  match: (node) => node.type === "delete",
804
990
  runner: (state, node, markType) => {
@@ -829,56 +1015,10 @@ const SinkTaskListItem = createCmdKey("SinkTaskListItem");
829
1015
  const LiftTaskListItem = createCmdKey("LiftTaskListItem");
830
1016
  const TurnIntoTaskList = createCmdKey("TurnIntoTaskList");
831
1017
  const taskListItem = createNode((utils) => {
832
- const id = "task_list_item";
833
- const style = utils.getStyle(({ palette, size }, { css }) => css`
834
- list-style-type: none;
835
- position: relative;
836
-
837
- & > div {
838
- overflow: hidden;
839
- padding: 0 2px;
840
- }
841
-
842
- label {
843
- position: absolute;
844
- top: 0;
845
- left: -2rem;
846
- display: inline-block;
847
- width: 1.5rem;
848
- height: 1.5rem;
849
- margin: 0.5rem 0;
850
- input {
851
- visibility: hidden;
852
- }
853
- }
854
- label:before {
855
- position: absolute;
856
- top: 0;
857
- right: 0;
858
- bottom: 0;
859
- left: 0;
860
- border-radius: ${size.radius};
861
- }
862
- label:hover:before {
863
- background: ${palette("background")};
864
- }
865
- &[data-checked='true'] {
866
- label {
867
- color: ${palette("primary")};
868
- }
869
- }
870
- &[data-checked='false'] {
871
- label {
872
- color: ${palette("solid", 0.87)};
873
- }
874
- }
875
- .paragraph {
876
- margin: 0.5rem 0;
877
- }
878
- `);
1018
+ const id2 = "task_list_item";
879
1019
  return {
880
- id,
881
- schema: () => ({
1020
+ id: id2,
1021
+ schema: (ctx) => ({
882
1022
  group: "listItem",
883
1023
  content: "paragraph block*",
884
1024
  defining: true,
@@ -895,33 +1035,58 @@ const taskListItem = createNode((utils) => {
895
1035
  if (!(dom instanceof HTMLElement)) {
896
1036
  throw new Error();
897
1037
  }
898
- return { checked: dom.dataset.checked === "true" };
1038
+ return { checked: dom.dataset["checked"] === "true" };
899
1039
  }
900
1040
  }
901
1041
  ],
902
- toDOM: (node) => [
903
- "li",
904
- {
905
- "data-type": "task-item",
906
- "data-checked": node.attrs.checked ? "true" : "false",
907
- class: utils.getClassName(node.attrs, "task-list-item", style)
908
- },
909
- 0
910
- ],
1042
+ toDOM: (node) => {
1043
+ const checkbox = document.createElement("input");
1044
+ checkbox.type = "checkbox";
1045
+ checkbox.checked = node.attrs["checked"];
1046
+ checkbox.className = utils.getClassName(node.attrs, "task-list-item_checkbox");
1047
+ checkbox.onchange = (event) => {
1048
+ const target = event.target;
1049
+ if (!(target instanceof HTMLInputElement))
1050
+ return;
1051
+ const view = ctx.get(editorViewCtx);
1052
+ if (!view.editable) {
1053
+ checkbox.checked = !checkbox.checked;
1054
+ return;
1055
+ }
1056
+ const { top, left } = target.getBoundingClientRect();
1057
+ const result = view.posAtCoords({ top, left });
1058
+ if (!result)
1059
+ return;
1060
+ const { tr } = view.state;
1061
+ view.dispatch(tr.setNodeMarkup(result.inside, void 0, {
1062
+ checked: target.checked
1063
+ }));
1064
+ };
1065
+ return [
1066
+ "li",
1067
+ {
1068
+ "data-type": "task-item",
1069
+ "data-checked": node.attrs["checked"] ? "true" : "false",
1070
+ class: utils.getClassName(node.attrs, "task-list-item")
1071
+ },
1072
+ checkbox,
1073
+ ["span", { class: utils.getClassName(node.attrs, "task-list-item_body") }, 0]
1074
+ ];
1075
+ },
911
1076
  parseMarkdown: {
912
1077
  match: ({ type, checked }) => {
913
1078
  return type === "listItem" && checked !== null;
914
1079
  },
915
1080
  runner: (state, node, type) => {
916
- state.openNode(type, { checked: node.checked });
1081
+ state.openNode(type, { checked: node["checked"] });
917
1082
  state.next(node.children);
918
1083
  state.closeNode();
919
1084
  }
920
1085
  },
921
1086
  toMarkdown: {
922
- match: (node) => node.type.name === id,
1087
+ match: (node) => node.type.name === id2,
923
1088
  runner: (state, node) => {
924
- state.openNode("listItem", void 0, { checked: node.attrs.checked });
1089
+ state.openNode("listItem", void 0, { checked: node.attrs["checked"] });
925
1090
  state.next(node.content);
926
1091
  state.closeNode();
927
1092
  }
@@ -944,68 +1109,30 @@ const taskListItem = createNode((utils) => {
944
1109
  [SupportedKeys.LiftListItem]: createShortcut(LiftTaskListItem, "Mod-["),
945
1110
  [SupportedKeys.TaskList]: createShortcut(TurnIntoTaskList, "Mod-Alt-9")
946
1111
  },
947
- view: (ctx) => (node, view, getPos) => {
948
- const createIcon = ctx.get(themeToolCtx).slots.icon;
949
- const listItem2 = document.createElement("li");
950
- const checkboxWrapper = document.createElement("label");
951
- const checkboxStyler = document.createElement("span");
952
- const checkbox = document.createElement("input");
953
- const content = document.createElement("div");
954
- let icon = createIcon("unchecked");
955
- checkboxWrapper.appendChild(icon);
956
- const setIcon = (name) => {
957
- const nextIcon = createIcon(name);
958
- checkboxWrapper.replaceChild(nextIcon, icon);
959
- icon = nextIcon;
960
- };
961
- checkboxWrapper.contentEditable = "false";
962
- checkbox.type = "checkbox";
963
- const onChange = (event) => {
964
- const target = event.target;
965
- if (!(target instanceof HTMLInputElement))
966
- return;
967
- if (!view.editable) {
968
- checkbox.checked = !checkbox.checked;
969
- return;
1112
+ view: () => (node, view, getPos) => {
1113
+ let currNode = node;
1114
+ const renderer = utils.themeManager.get("task-list-item", {
1115
+ editable: () => view.editable,
1116
+ onChange: (selected) => {
1117
+ const { tr } = view.state;
1118
+ view.dispatch(tr.setNodeMarkup(getPos(), void 0, {
1119
+ checked: selected
1120
+ }));
970
1121
  }
971
- const { tr } = view.state;
972
- view.dispatch(tr.setNodeMarkup(getPos(), void 0, {
973
- checked: target.checked
974
- }));
975
- };
976
- checkbox.addEventListener("change", onChange);
977
- listItem2.dataset.checked = node.attrs.checked;
978
- if (node.attrs.checked) {
979
- checkbox.setAttribute("checked", "checked");
980
- }
981
- checkboxWrapper.append(checkbox, checkboxStyler);
982
- listItem2.append(checkboxWrapper, content);
983
- const attributes = {
984
- "data-type": "task-item",
985
- "data-checked": node.attrs.checked ? "true" : "false",
986
- class: utils.getClassName(node.attrs, "task-list-item", style)
987
- };
988
- Object.entries(attributes).forEach(([key, value]) => {
989
- listItem2.setAttribute(key, value);
990
1122
  });
991
- setIcon(node.attrs.checked ? "checked" : "unchecked");
1123
+ if (!renderer)
1124
+ return {};
1125
+ const { dom, contentDOM, onUpdate } = renderer;
1126
+ onUpdate(currNode);
992
1127
  return {
993
- dom: listItem2,
994
- contentDOM: content,
1128
+ dom,
1129
+ contentDOM,
995
1130
  update: (updatedNode) => {
996
- if (updatedNode.type.name !== id)
1131
+ if (updatedNode.type.name !== id2)
997
1132
  return false;
998
- listItem2.dataset.checked = updatedNode.attrs.checked;
999
- if (updatedNode.attrs.checked) {
1000
- checkbox.setAttribute("checked", "checked");
1001
- } else {
1002
- checkbox.removeAttribute("checked");
1003
- }
1004
- setIcon(updatedNode.attrs.checked ? "checked" : "unchecked");
1133
+ currNode = updatedNode;
1134
+ onUpdate(currNode);
1005
1135
  return true;
1006
- },
1007
- destroy: () => {
1008
- checkbox.removeEventListener("change", onChange);
1009
1136
  }
1010
1137
  };
1011
1138
  }
@@ -1017,7 +1144,9 @@ const gfm = AtomList.create([
1017
1144
  table(),
1018
1145
  urlPlugin,
1019
1146
  strikeThrough(),
1020
- taskListItem()
1147
+ taskListItem(),
1148
+ footnoteReference(),
1149
+ footnoteDefinition()
1021
1150
  ]);
1022
1151
  const commands = __spreadProps(__spreadValues({}, commands$1), {
1023
1152
  ToggleStrikeThrough,
@@ -1026,5 +1155,5 @@ const commands = __spreadProps(__spreadValues({}, commands$1), {
1026
1155
  LiftTaskListItem,
1027
1156
  SplitTaskListItem
1028
1157
  });
1029
- export { BreakTable, InsertTable, LiftTaskListItem, NextCell, PrevCell, SinkTaskListItem, SplitTaskListItem, SupportedKeys, ToggleStrikeThrough, TurnIntoTaskList, commands, createTable, gfm, strikeThrough, table, taskListItem };
1158
+ export { BreakTable, InsertTable, LiftTaskListItem, ModifyFootnoteDef, ModifyFootnoteRef, NextCell, PrevCell, SinkTaskListItem, SplitTaskListItem, SupportedKeys, ToggleStrikeThrough, TurnIntoTaskList, commands, createTable, footnoteDefinition, footnoteReference, gfm, strikeThrough, table, taskListItem };
1030
1159
  //# sourceMappingURL=index.es.js.map