@milkdown/preset-gfm 5.3.0 → 5.3.4

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 (66) hide show
  1. package/lib/index.d.ts +1 -36
  2. package/lib/index.es.js +768 -17
  3. package/lib/index.es.js.map +1 -1
  4. package/lib/src/auto-link.d.ts +2 -0
  5. package/lib/src/auto-link.d.ts.map +1 -0
  6. package/lib/src/index.d.ts +36 -0
  7. package/lib/src/index.d.ts.map +1 -0
  8. package/lib/{strike-through.d.ts → src/strike-through.d.ts} +1 -1
  9. package/lib/src/strike-through.d.ts.map +1 -0
  10. package/lib/{supported-keys.d.ts → src/supported-keys.d.ts} +0 -0
  11. package/lib/src/supported-keys.d.ts.map +1 -0
  12. package/lib/src/table/command.d.ts +3 -0
  13. package/lib/src/table/command.d.ts.map +1 -0
  14. package/lib/src/table/index.d.ts +10 -0
  15. package/lib/src/table/index.d.ts.map +1 -0
  16. package/lib/src/table/nodes/index.d.ts +32 -0
  17. package/lib/src/table/nodes/index.d.ts.map +1 -0
  18. package/lib/src/table/nodes/schema.d.ts +2 -0
  19. package/lib/src/table/nodes/schema.d.ts.map +1 -0
  20. package/lib/src/table/nodes/style.d.ts +3 -0
  21. package/lib/src/table/nodes/style.d.ts.map +1 -0
  22. package/lib/src/table/operator-plugin/actions.d.ts +19 -0
  23. package/lib/src/table/operator-plugin/actions.d.ts.map +1 -0
  24. package/lib/src/table/operator-plugin/calc-pos.d.ts +3 -0
  25. package/lib/src/table/operator-plugin/calc-pos.d.ts.map +1 -0
  26. package/lib/src/table/operator-plugin/constant.d.ts +6 -0
  27. package/lib/src/table/operator-plugin/constant.d.ts.map +1 -0
  28. package/lib/src/table/operator-plugin/helper.d.ts +6 -0
  29. package/lib/src/table/operator-plugin/helper.d.ts.map +1 -0
  30. package/lib/src/table/operator-plugin/index.d.ts +6 -0
  31. package/lib/src/table/operator-plugin/index.d.ts.map +1 -0
  32. package/lib/src/table/operator-plugin/style.d.ts +3 -0
  33. package/lib/src/table/operator-plugin/style.d.ts.map +1 -0
  34. package/lib/src/table/operator-plugin/widget.d.ts +8 -0
  35. package/lib/src/table/operator-plugin/widget.d.ts.map +1 -0
  36. package/lib/src/table/utils.d.ts +19 -0
  37. package/lib/src/table/utils.d.ts.map +1 -0
  38. package/lib/{task-list-item.d.ts → src/task-list-item.d.ts} +1 -1
  39. package/lib/src/task-list-item.d.ts.map +1 -0
  40. package/package.json +12 -26
  41. package/src/auto-link.ts +4 -9
  42. package/src/index.ts +13 -6
  43. package/src/strike-through.ts +1 -2
  44. package/src/supported-keys.ts +2 -1
  45. package/src/table/command.ts +16 -0
  46. package/src/table/index.ts +13 -0
  47. package/src/table/nodes/index.ts +169 -0
  48. package/src/table/nodes/schema.ts +16 -0
  49. package/src/table/nodes/style.ts +170 -0
  50. package/src/table/operator-plugin/actions.ts +115 -0
  51. package/src/table/operator-plugin/calc-pos.ts +25 -0
  52. package/src/table/operator-plugin/constant.ts +7 -0
  53. package/src/table/operator-plugin/helper.ts +38 -0
  54. package/src/table/operator-plugin/index.ts +98 -0
  55. package/src/table/operator-plugin/style.ts +50 -0
  56. package/src/table/operator-plugin/widget.ts +66 -0
  57. package/src/table/utils.ts +158 -0
  58. package/src/task-list-item.ts +3 -3
  59. package/lib/auto-link.d.ts +0 -16
  60. package/lib/auto-link.d.ts.map +0 -1
  61. package/lib/index.cjs.js +0 -49
  62. package/lib/index.cjs.js.map +0 -1
  63. package/lib/index.d.ts.map +0 -1
  64. package/lib/strike-through.d.ts.map +0 -1
  65. package/lib/supported-keys.d.ts.map +0 -1
  66. package/lib/task-list-item.d.ts.map +0 -1
package/lib/index.es.js CHANGED
@@ -17,35 +17,778 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- import { SupportedKeys as SupportedKeys$2, tablePlugin } from "@milkdown/plugin-table";
21
- export { BreakTable, InsertTable, NextCell, PrevCell, createTable, table, tablePlugin } from "@milkdown/plugin-table";
22
- import { SupportedKeys as SupportedKeys$1, commonmark, commands as commands$1 } from "@milkdown/preset-commonmark";
20
+ import { SupportedKeys as SupportedKeys$2, commonmark, commands as commands$1 } from "@milkdown/preset-commonmark";
23
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";
24
- import { createPlugin, createMark, createShortcut, createNode, AtomList } from "@milkdown/utils";
25
- import { inputRules, InputRule, markRule, toggleMark, wrappingInputRule, splitListItem, sinkListItem, liftListItem, wrapIn } from "@milkdown/prose";
26
- import { css } from "@emotion/css";
27
- import { createCmdKey, createCmd, themeToolCtx } from "@milkdown/core";
28
- const urlRegex = /(https?:\/\/)?www\.[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,}\b(?:[-a-zA-Z0-9@:%._+~#=?!&/]*)(?:[-a-zA-Z0-9@:%._+~#=?!&/]*)$/;
22
+ import { $prose, createPlugin, createShortcut, createMark, createNode, AtomList, $remark } from "@milkdown/utils";
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()@:%_+.~#?&//=]*)/;
29
27
  const proseUrlPlugin = () => inputRules({
30
28
  rules: [
31
29
  new InputRule(urlRegex, (state, match, start, end) => {
32
- const { schema } = state;
30
+ const { schema: schema2 } = state;
33
31
  const [text2] = match;
34
32
  if (!text2)
35
33
  return null;
36
- return state.tr.replaceWith(start, end, schema.text(text2)).addMark(start, text2.length + start, schema.marks.link.create({ href: text2.startsWith("www") ? `https://${text2}` : text2 }));
34
+ return state.tr.replaceWith(start, end, schema2.text(text2)).addMark(start, text2.length + start, schema2.marks.link.create({ href: text2 }));
37
35
  })
38
36
  ]
39
37
  });
40
- const urlPlugin = createPlugin(() => ({ prosePlugins: () => [proseUrlPlugin()] }));
41
- const SupportedKeys = __spreadProps(__spreadValues(__spreadValues({}, SupportedKeys$1), SupportedKeys$2), {
38
+ const urlPlugin = $prose(() => proseUrlPlugin());
39
+ const exitTable = (node) => (state, dispatch) => {
40
+ if (!isInTable(state)) {
41
+ return false;
42
+ }
43
+ const { $head } = state.selection;
44
+ const pos = $head.after();
45
+ const tr = state.tr.replaceWith(pos, pos, node.createAndFill());
46
+ tr.setSelection(Selection.near(tr.doc.resolve(pos), 1));
47
+ dispatch == null ? void 0 : dispatch(tr.scrollIntoView());
48
+ return true;
49
+ };
50
+ const findTable = (selection) => findParentNode((node) => node.type.spec.tableRole === "table")(selection);
51
+ const getCellsInColumn = (columnIndex) => (selection) => {
52
+ const table2 = findTable(selection);
53
+ if (!table2)
54
+ return void 0;
55
+ const map = TableMap.get(table2.node);
56
+ if (columnIndex < 0 || columnIndex >= map.width) {
57
+ return void 0;
58
+ }
59
+ return map.cellsInRect({ left: columnIndex, right: columnIndex + 1, top: 0, bottom: map.height }).map((pos) => {
60
+ const node = table2.node.nodeAt(pos);
61
+ if (!node)
62
+ throw new Error();
63
+ const start = pos + table2.start;
64
+ return {
65
+ pos: start,
66
+ start: start + 1,
67
+ node
68
+ };
69
+ });
70
+ };
71
+ const getCellsInRow = (rowIndex) => (selection) => {
72
+ const table2 = findTable(selection);
73
+ if (!table2)
74
+ return void 0;
75
+ const map = TableMap.get(table2.node);
76
+ if (rowIndex < 0 || rowIndex >= map.height) {
77
+ return void 0;
78
+ }
79
+ return map.cellsInRect({ left: 0, right: map.width, top: rowIndex, bottom: rowIndex + 1 }).map((pos) => {
80
+ const node = table2.node.nodeAt(pos);
81
+ if (!node)
82
+ throw new Error();
83
+ const start = pos + table2.start;
84
+ return {
85
+ pos: start,
86
+ start: start + 1,
87
+ node
88
+ };
89
+ });
90
+ };
91
+ const createTable = (schema2, rowsCount = 3, colsCount = 3) => {
92
+ const { cell: tableCell, header_cell: tableHeader, row: tableRow, table: table2 } = tableNodeTypes(schema2);
93
+ const cells = Array(colsCount).fill(0).map(() => tableCell.createAndFill(null));
94
+ const headerCells = Array(colsCount).fill(0).map(() => tableHeader.createAndFill(null));
95
+ const rows = Array(rowsCount).fill(0).map((_, i) => tableRow.create(null, i === 0 ? headerCells : cells));
96
+ return table2.create(null, rows);
97
+ };
98
+ const selectLine = (type) => (index) => (tr) => {
99
+ const table2 = findTable(tr.selection);
100
+ const isRowSelection = type === "row";
101
+ if (table2) {
102
+ const map = TableMap.get(table2.node);
103
+ if (index >= 0 && index < (isRowSelection ? map.height : map.width)) {
104
+ const lastCell = map.positionAt(isRowSelection ? index : map.height - 1, isRowSelection ? map.width - 1 : index, table2.node);
105
+ const $lastCell = tr.doc.resolve(table2.start + lastCell);
106
+ const createCellSelection = isRowSelection ? CellSelection.rowSelection : CellSelection.colSelection;
107
+ const firstCell = map.positionAt(isRowSelection ? index : 0, isRowSelection ? 0 : index, table2.node);
108
+ const $firstCell = tr.doc.resolve(table2.start + firstCell);
109
+ return cloneTr(tr.setSelection(createCellSelection($lastCell, $firstCell)));
110
+ }
111
+ }
112
+ return tr;
113
+ };
114
+ const getCellsInTable = (selection) => {
115
+ const table2 = findTable(selection);
116
+ if (!table2) {
117
+ return;
118
+ }
119
+ const map = TableMap.get(table2.node);
120
+ const cells = map.cellsInRect({
121
+ left: 0,
122
+ right: map.width,
123
+ top: 0,
124
+ bottom: map.height
125
+ });
126
+ return cells.map((nodePos) => {
127
+ const node = table2.node.nodeAt(nodePos);
128
+ const pos = nodePos + table2.start;
129
+ return { pos, start: pos + 1, node };
130
+ });
131
+ };
132
+ const selectTable = (tr) => {
133
+ const cells = getCellsInTable(tr.selection);
134
+ if (cells) {
135
+ 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)));
138
+ }
139
+ return tr;
140
+ };
141
+ function addRowWithAlignment(tr, { map, tableStart, table: table2 }, row) {
142
+ const rowPos = Array(row).fill(0).reduce((acc, _, i) => {
143
+ return acc + table2.child(i).nodeSize;
144
+ }, tableStart);
145
+ const { cell: cellType, row: rowType } = tableNodeTypes(table2.type.schema);
146
+ const cells = Array(map.width).fill(0).map((_, col) => {
147
+ const headerCol = table2.nodeAt(map.map[col]);
148
+ return cellType.createAndFill({ alignment: headerCol == null ? void 0 : headerCol.attrs.alignment });
149
+ });
150
+ tr.insert(rowPos, rowType.create(null, cells));
151
+ return tr;
152
+ }
153
+ const getCellSelection = (view) => view.state.selection;
154
+ const isFirstRowSelected = (selection) => {
155
+ const map = TableMap.get(selection.$anchorCell.node(-1));
156
+ const start = selection.$anchorCell.start(-1);
157
+ const cells = map.cellsInRect({
158
+ left: 0,
159
+ right: map.width,
160
+ top: 0,
161
+ bottom: 1
162
+ });
163
+ const selectedCells = map.cellsInRect(map.rectBetween(selection.$anchorCell.pos - start, selection.$headCell.pos - start));
164
+ for (let i = 0, count = cells.length; i < count; i++) {
165
+ if (selectedCells.indexOf(cells[i]) === -1) {
166
+ return false;
167
+ }
168
+ }
169
+ return true;
170
+ };
171
+ const calculateItem = (actions, view) => {
172
+ Object.values(actions).forEach((item) => {
173
+ var _a;
174
+ const disable = (_a = item.disable) == null ? void 0 : _a.call(item, view);
175
+ if (disable) {
176
+ item.$.classList.add("hide");
177
+ return;
178
+ }
179
+ item.$.classList.remove("hide");
180
+ });
181
+ };
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;
214
+ },
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;
227
+ },
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;
258
+ },
259
+ disable: (view) => {
260
+ const selection = getCellSelection(view);
261
+ if (selection.isRowSelection()) {
262
+ if (selection.isColSelection()) {
263
+ return false;
264
+ }
265
+ return isFirstRowSelected(selection);
266
+ }
267
+ return false;
268
+ }
269
+ }
270
+ });
271
+ const calculatePosition = (view, dom) => {
272
+ const { selection } = view.state;
273
+ const isCol = selection.isColSelection();
274
+ const isRow = selection.isRowSelection();
275
+ calculateNodePosition(view, dom, (selected, target, parent) => {
276
+ const $editor = dom.parentElement;
277
+ if (!$editor) {
278
+ throw new Error();
279
+ }
280
+ let left = !isRow ? selected.left - parent.left + (selected.width - target.width) / 2 : selected.left - parent.left - target.width / 2 - 8;
281
+ const top = selected.top - parent.top - target.height - (isCol ? 14 : 0) - 14 + $editor.scrollTop;
282
+ if (left < 0) {
283
+ left = 0;
284
+ }
285
+ return [top, left];
286
+ });
287
+ };
288
+ var ToolTipPos;
289
+ (function(ToolTipPos2) {
290
+ ToolTipPos2["Left"] = "Left";
291
+ ToolTipPos2["Top"] = "Top";
292
+ ToolTipPos2["Point"] = "Point";
293
+ })(ToolTipPos || (ToolTipPos = {}));
294
+ const injectStyle$1 = ({ size, mixin, palette }, { css }) => {
295
+ var _a, _b;
296
+ return css`
297
+ display: inline-flex;
298
+ cursor: pointer;
299
+ z-index: 2;
300
+
301
+ justify-content: space-evenly;
302
+
303
+ position: absolute;
304
+
305
+ border-radius: ${size.radius};
306
+
307
+ ${(_a = mixin.border) == null ? void 0 : _a.call(mixin)};
308
+
309
+ ${(_b = mixin.shadow) == null ? void 0 : _b.call(mixin)};
310
+
311
+ overflow: hidden;
312
+ background: ${palette("surface")};
313
+
314
+ .icon {
315
+ position: relative;
316
+ color: ${palette("solid", 0.87)};
317
+
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")};
327
+ }
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")};
336
+ }
337
+ }
338
+ &.hide,
339
+ .hide {
340
+ display: none;
341
+ }
342
+ `;
343
+ };
344
+ const calculateClassName = (pos) => {
345
+ switch (pos) {
346
+ case ToolTipPos.Left: {
347
+ return "milkdown-cell-left";
348
+ }
349
+ case ToolTipPos.Top: {
350
+ return "milkdown-cell-top";
351
+ }
352
+ case ToolTipPos.Point:
353
+ default: {
354
+ return "milkdown-cell-point";
355
+ }
356
+ }
357
+ };
358
+ function createWidget(ctx, cell, pos, index = 0) {
359
+ const widget = Decoration.widget(cell.pos + 1, (view) => {
360
+ const div = document.createElement("div");
361
+ div.classList.add(calculateClassName(pos));
362
+ if (pos === ToolTipPos.Point) {
363
+ div.appendChild(ctx.get(themeToolCtx).slots.icon("select"));
364
+ }
365
+ div.addEventListener("mousedown", (e) => {
366
+ if (!view)
367
+ return;
368
+ e.preventDefault();
369
+ switch (pos) {
370
+ case ToolTipPos.Point: {
371
+ view.dispatch(selectTable(view.state.tr));
372
+ return;
373
+ }
374
+ case ToolTipPos.Left: {
375
+ view.dispatch(selectLine("row")(index)(view.state.tr));
376
+ return;
377
+ }
378
+ case ToolTipPos.Top: {
379
+ view.dispatch(selectLine("col")(index)(view.state.tr));
380
+ return;
381
+ }
382
+ }
383
+ });
384
+ return div;
385
+ });
386
+ return widget;
387
+ }
388
+ const operatorPlugin = (ctx, utils) => {
389
+ const items = createActions(ctx);
390
+ const tooltip = document.createElement("div");
391
+ const style = utils.getStyle(injectStyle$1);
392
+ if (style) {
393
+ tooltip.classList.add(style);
394
+ }
395
+ tooltip.classList.add("table-tooltip", "hide");
396
+ return new Plugin({
397
+ key: new PluginKey("MILKDOWN_TABLE_OP"),
398
+ props: {
399
+ decorations: (state) => {
400
+ const decorations = [];
401
+ const leftCells = getCellsInColumn(0)(state.selection);
402
+ if (!leftCells)
403
+ return null;
404
+ const topCells = getCellsInRow(0)(state.selection);
405
+ if (!topCells)
406
+ return null;
407
+ const [topLeft] = leftCells;
408
+ decorations.push(createWidget(ctx, topLeft, ToolTipPos.Point));
409
+ leftCells.forEach((cell, i) => {
410
+ decorations.push(createWidget(ctx, cell, ToolTipPos.Left, i));
411
+ });
412
+ topCells.forEach((cell, i) => {
413
+ decorations.push(createWidget(ctx, cell, ToolTipPos.Top, i));
414
+ });
415
+ return DecorationSet.create(state.doc, decorations);
416
+ }
417
+ },
418
+ view: (editorView) => {
419
+ var _a;
420
+ Object.values(items).forEach(({ $ }) => tooltip.appendChild($));
421
+ (_a = editorView.dom.parentNode) == null ? void 0 : _a.appendChild(tooltip);
422
+ const listener = (e) => {
423
+ if (!editorView)
424
+ return;
425
+ e.stopPropagation();
426
+ e.preventDefault();
427
+ Object.values(items).forEach(({ $, command }) => {
428
+ if ($.contains(e.target)) {
429
+ command(e, editorView)(editorView.state, editorView.dispatch, editorView);
430
+ }
431
+ });
432
+ };
433
+ const hide = () => {
434
+ tooltip.classList.add("hide");
435
+ };
436
+ tooltip.addEventListener("mousedown", listener);
437
+ return {
438
+ update: (view, prevState) => {
439
+ const state = view.state;
440
+ if ((prevState == null ? void 0 : prevState.doc.eq(state.doc)) && prevState.selection.eq(state.selection))
441
+ return;
442
+ const isCellSelection = state.selection instanceof CellSelection;
443
+ if (!isCellSelection || !view.editable) {
444
+ hide();
445
+ return;
446
+ }
447
+ calculateItem(items, view);
448
+ if (Object.values(items).every(({ $ }) => $.classList.contains("hide"))) {
449
+ hide();
450
+ return;
451
+ }
452
+ tooltip.classList.remove("hide");
453
+ calculatePosition(view, tooltip);
454
+ },
455
+ destroy: () => {
456
+ tooltip.removeEventListener("mousedown", listener);
457
+ tooltip.remove();
458
+ }
459
+ };
460
+ }
461
+ });
462
+ };
463
+ const schema = tableNodes({
464
+ tableGroup: "block",
465
+ cellContent: "paragraph",
466
+ cellAttributes: {
467
+ alignment: {
468
+ default: "left",
469
+ getFromDOM: (dom) => dom.style.textAlign || "left",
470
+ setDOMAttr: (value, attrs) => {
471
+ attrs.style = `text-align: ${value || "left"}`;
472
+ }
473
+ }
474
+ }
475
+ });
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
+ const SupportedKeys$1 = {
643
+ NextCell: "NextCell",
644
+ PrevCell: "PrevCell",
645
+ ExitTable: "ExitTable"
646
+ };
647
+ const PrevCell = createCmdKey();
648
+ const NextCell = createCmdKey();
649
+ const BreakTable = createCmdKey();
650
+ const InsertTable = createCmdKey();
651
+ const table = createPlugin((utils) => {
652
+ injectStyle(utils);
653
+ return {
654
+ schema: () => ({
655
+ node: {
656
+ table: __spreadProps(__spreadValues({}, schema.table), {
657
+ parseMarkdown: {
658
+ match: (node) => node.type === "table",
659
+ runner: (state, node, type) => {
660
+ const align = node.align;
661
+ const children = node.children.map((x, i) => __spreadProps(__spreadValues({}, x), {
662
+ align,
663
+ isHeader: i === 0
664
+ }));
665
+ state.openNode(type);
666
+ state.next(children);
667
+ state.closeNode();
668
+ }
669
+ },
670
+ toMarkdown: {
671
+ match: (node) => node.type.name === "table",
672
+ runner: (state, node) => {
673
+ var _a;
674
+ const firstLine = (_a = node.content.firstChild) == null ? void 0 : _a.content;
675
+ if (!firstLine)
676
+ return;
677
+ const align = [];
678
+ firstLine.forEach((cell) => {
679
+ align.push(cell.attrs.alignment);
680
+ });
681
+ state.openNode("table", void 0, { align });
682
+ state.next(node.content);
683
+ state.closeNode();
684
+ }
685
+ }
686
+ }),
687
+ table_row: __spreadProps(__spreadValues({}, schema.table_row), {
688
+ parseMarkdown: {
689
+ match: (node) => node.type === "tableRow",
690
+ runner: (state, node, type) => {
691
+ const align = node.align;
692
+ const children = node.children.map((x, i) => __spreadProps(__spreadValues({}, x), {
693
+ align: align[i],
694
+ isHeader: node.isHeader
695
+ }));
696
+ state.openNode(type);
697
+ state.next(children);
698
+ state.closeNode();
699
+ }
700
+ },
701
+ toMarkdown: {
702
+ match: (node) => node.type.name === "table_row",
703
+ runner: (state, node) => {
704
+ state.openNode("tableRow");
705
+ state.next(node.content);
706
+ state.closeNode();
707
+ }
708
+ }
709
+ }),
710
+ table_cell: __spreadProps(__spreadValues({}, schema.table_cell), {
711
+ parseMarkdown: {
712
+ match: (node) => node.type === "tableCell" && !node.isHeader,
713
+ 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();
716
+ }
717
+ },
718
+ toMarkdown: {
719
+ match: (node) => node.type.name === "table_cell",
720
+ runner: (state, node) => {
721
+ state.openNode("tableCell").next(node.content).closeNode();
722
+ }
723
+ }
724
+ }),
725
+ table_header: __spreadProps(__spreadValues({}, schema.table_header), {
726
+ parseMarkdown: {
727
+ match: (node) => node.type === "tableCell" && !!node.isHeader,
728
+ runner: (state, node, type) => {
729
+ const align = node.align;
730
+ state.openNode(type, { alignment: align });
731
+ state.openNode(state.schema.nodes.paragraph);
732
+ state.next(node.children);
733
+ state.closeNode();
734
+ state.closeNode();
735
+ }
736
+ },
737
+ toMarkdown: {
738
+ match: (node) => node.type.name === "table_header",
739
+ runner: (state, node) => {
740
+ state.openNode("tableCell");
741
+ state.next(node.content);
742
+ state.closeNode();
743
+ }
744
+ }
745
+ })
746
+ }
747
+ }),
748
+ inputRules: (nodeType, ctx) => [
749
+ new InputRule(/^\|\|\s$/, (state, _match, start, end) => {
750
+ const $start = state.doc.resolve(start);
751
+ if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType.table))
752
+ return null;
753
+ const tableNode = createTable(ctx.get(schemaCtx));
754
+ const tr = state.tr.replaceRangeWith(start, end, tableNode).scrollIntoView();
755
+ return tr.setSelection(TextSelection.create(tr.doc, start + 3));
756
+ })
757
+ ],
758
+ commands: (_, ctx) => [
759
+ createCmd(PrevCell, () => goToNextCell(-1)),
760
+ createCmd(NextCell, () => goToNextCell(1)),
761
+ createCmd(BreakTable, () => exitTable(ctx.get(schemaCtx).nodes.paragraph)),
762
+ createCmd(InsertTable, () => (state, dispatch) => {
763
+ const { selection, tr } = state;
764
+ const { from } = selection;
765
+ const table2 = createTable(ctx.get(schemaCtx));
766
+ const _tr = tr.replaceSelectionWith(table2);
767
+ const sel = Selection.findFrom(_tr.doc.resolve(from), 1, true);
768
+ if (sel) {
769
+ dispatch == null ? void 0 : dispatch(_tr.setSelection(sel));
770
+ }
771
+ return true;
772
+ })
773
+ ],
774
+ shortcuts: {
775
+ [SupportedKeys$1.NextCell]: createShortcut(NextCell, "Mod-]"),
776
+ [SupportedKeys$1.PrevCell]: createShortcut(PrevCell, "Mod-["),
777
+ [SupportedKeys$1.ExitTable]: createShortcut(BreakTable, "Mod-Enter")
778
+ },
779
+ prosePlugins: (_, ctx) => {
780
+ return [operatorPlugin(ctx, utils), columnResizing({}), tableEditing()];
781
+ }
782
+ };
783
+ });
784
+ const SupportedKeys = __spreadProps(__spreadValues(__spreadValues({}, SupportedKeys$2), SupportedKeys$1), {
42
785
  StrikeThrough: "StrikeThrough",
43
786
  TaskList: "TaskList"
44
787
  });
45
788
  const ToggleStrikeThrough = createCmdKey();
46
789
  const strikeThrough = createMark((utils) => {
47
790
  const id = "strike_through";
48
- const style = utils.getStyle((themeTool) => css`
791
+ const style = utils.getStyle((themeTool, { css }) => css`
49
792
  text-decoration-color: ${themeTool.palette("secondary")};
50
793
  `);
51
794
  return {
@@ -87,7 +830,7 @@ const LiftTaskListItem = createCmdKey();
87
830
  const TurnIntoTaskList = createCmdKey();
88
831
  const taskListItem = createNode((utils) => {
89
832
  const id = "task_list_item";
90
- const style = utils.getStyle(({ palette, size }) => css`
833
+ const style = utils.getStyle(({ palette, size }, { css }) => css`
91
834
  list-style-type: none;
92
835
  position: relative;
93
836
 
@@ -139,6 +882,7 @@ const taskListItem = createNode((utils) => {
139
882
  group: "listItem",
140
883
  content: "paragraph block*",
141
884
  defining: true,
885
+ priority: 60,
142
886
  attrs: {
143
887
  checked: {
144
888
  default: false
@@ -146,7 +890,7 @@ const taskListItem = createNode((utils) => {
146
890
  },
147
891
  parseDOM: [
148
892
  {
149
- tag: 'li[data-type="task-list-item"]',
893
+ tag: 'li[data-type="task-item"]',
150
894
  getAttrs: (dom) => {
151
895
  if (!(dom instanceof HTMLElement)) {
152
896
  throw new Error();
@@ -267,7 +1011,14 @@ const taskListItem = createNode((utils) => {
267
1011
  }
268
1012
  };
269
1013
  });
270
- const gfm = AtomList.create([...commonmark, tablePlugin(), urlPlugin(), strikeThrough(), taskListItem()]);
1014
+ const gfm = AtomList.create([
1015
+ ...commonmark,
1016
+ $remark(() => remarkGFM),
1017
+ table(),
1018
+ urlPlugin,
1019
+ strikeThrough(),
1020
+ taskListItem()
1021
+ ]);
271
1022
  const commands = __spreadProps(__spreadValues({}, commands$1), {
272
1023
  ToggleStrikeThrough,
273
1024
  TurnIntoTaskList,
@@ -275,5 +1026,5 @@ const commands = __spreadProps(__spreadValues({}, commands$1), {
275
1026
  LiftTaskListItem,
276
1027
  SplitTaskListItem
277
1028
  });
278
- export { LiftTaskListItem, SinkTaskListItem, SplitTaskListItem, SupportedKeys, ToggleStrikeThrough, TurnIntoTaskList, commands, gfm, strikeThrough, taskListItem };
1029
+ export { BreakTable, InsertTable, LiftTaskListItem, NextCell, PrevCell, SinkTaskListItem, SplitTaskListItem, SupportedKeys, ToggleStrikeThrough, TurnIntoTaskList, commands, createTable, gfm, strikeThrough, table, taskListItem };
279
1030
  //# sourceMappingURL=index.es.js.map