@milkdown/preset-gfm 5.4.0 → 6.0.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) 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/index.d.ts +36 -1
  5. package/lib/index.d.ts.map +1 -0
  6. package/lib/index.es.js +283 -448
  7. package/lib/index.es.js.map +1 -1
  8. package/lib/{src/strike-through.d.ts → strike-through.d.ts} +1 -1
  9. package/lib/strike-through.d.ts.map +1 -0
  10. package/lib/{src/supported-keys.d.ts → supported-keys.d.ts} +0 -0
  11. package/lib/supported-keys.d.ts.map +1 -0
  12. package/lib/{src/table → table}/command.d.ts +0 -0
  13. package/lib/table/command.d.ts.map +1 -0
  14. package/lib/{src/table → table}/index.d.ts +0 -0
  15. package/lib/table/index.d.ts.map +1 -0
  16. package/lib/{src/table → table}/nodes/index.d.ts +7 -6
  17. package/lib/table/nodes/index.d.ts.map +1 -0
  18. package/lib/{src/table → table}/nodes/schema.d.ts +0 -0
  19. package/lib/table/nodes/schema.d.ts.map +1 -0
  20. package/lib/{src/table → table}/operator-plugin/actions.d.ts +0 -0
  21. package/lib/table/operator-plugin/actions.d.ts.map +1 -0
  22. package/lib/{src/table → table}/operator-plugin/calc-pos.d.ts +0 -0
  23. package/lib/table/operator-plugin/calc-pos.d.ts.map +1 -0
  24. package/lib/{src/table → table}/operator-plugin/constant.d.ts +0 -0
  25. package/lib/table/operator-plugin/constant.d.ts.map +1 -0
  26. package/lib/{src/table → table}/operator-plugin/helper.d.ts +0 -0
  27. package/lib/table/operator-plugin/helper.d.ts.map +1 -0
  28. package/lib/{src/table → table}/operator-plugin/index.d.ts +0 -0
  29. package/lib/table/operator-plugin/index.d.ts.map +1 -0
  30. package/lib/table/operator-plugin/style.d.ts +3 -0
  31. package/lib/table/operator-plugin/style.d.ts.map +1 -0
  32. package/lib/{src/table → table}/operator-plugin/widget.d.ts +0 -0
  33. package/lib/table/operator-plugin/widget.d.ts.map +1 -0
  34. package/lib/{src/table → table}/utils.d.ts +1 -0
  35. package/lib/table/utils.d.ts.map +1 -0
  36. package/lib/{src/task-list-item.d.ts → task-list-item.d.ts} +1 -1
  37. package/lib/task-list-item.d.ts.map +1 -0
  38. package/package.json +36 -12
  39. package/src/auto-link.ts +1 -1
  40. package/src/strike-through.ts +3 -10
  41. package/src/table/nodes/index.ts +24 -18
  42. package/src/table/operator-plugin/actions.ts +9 -9
  43. package/src/table/operator-plugin/helper.ts +1 -1
  44. package/src/table/operator-plugin/index.ts +8 -6
  45. package/src/table/operator-plugin/style.ts +109 -37
  46. package/src/table/operator-plugin/widget.ts +3 -4
  47. package/src/table/utils.ts +9 -6
  48. package/src/task-list-item.ts +69 -134
  49. package/lib/src/auto-link.d.ts.map +0 -1
  50. package/lib/src/index.d.ts +0 -36
  51. package/lib/src/index.d.ts.map +0 -1
  52. package/lib/src/strike-through.d.ts.map +0 -1
  53. package/lib/src/supported-keys.d.ts.map +0 -1
  54. package/lib/src/table/command.d.ts.map +0 -1
  55. package/lib/src/table/index.d.ts.map +0 -1
  56. package/lib/src/table/nodes/index.d.ts.map +0 -1
  57. package/lib/src/table/nodes/schema.d.ts.map +0 -1
  58. package/lib/src/table/nodes/style.d.ts +0 -3
  59. package/lib/src/table/nodes/style.d.ts.map +0 -1
  60. package/lib/src/table/operator-plugin/actions.d.ts.map +0 -1
  61. package/lib/src/table/operator-plugin/calc-pos.d.ts.map +0 -1
  62. package/lib/src/table/operator-plugin/constant.d.ts.map +0 -1
  63. package/lib/src/table/operator-plugin/helper.d.ts.map +0 -1
  64. package/lib/src/table/operator-plugin/index.d.ts.map +0 -1
  65. package/lib/src/table/operator-plugin/style.d.ts +0 -3
  66. package/lib/src/table/operator-plugin/style.d.ts.map +0 -1
  67. package/lib/src/table/operator-plugin/widget.d.ts.map +0 -1
  68. package/lib/src/table/utils.d.ts.map +0 -1
  69. package/lib/src/task-list-item.d.ts.map +0 -1
  70. package/src/table/nodes/style.ts +0 -170
package/lib/index.es.js CHANGED
@@ -21,9 +21,9 @@ import { SupportedKeys as SupportedKeys$2, commonmark, commands as commands$1 }
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
22
  import { $prose, createPlugin, createShortcut, createMark, createNode, 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, isInTable, Selection, findParentNode, TableMap, CellSelection, cloneTr, tableNodeTypes, 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 { themeManagerCtx, ThemeIcon, getPalette, ThemeSize, ThemeBorder, ThemeShadow, createCmdKey, schemaCtx, createCmd, editorViewCtx } 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) => {
@@ -47,7 +47,7 @@ const exitTable = (node) => (state, dispatch) => {
47
47
  dispatch == null ? void 0 : dispatch(tr.scrollIntoView());
48
48
  return true;
49
49
  };
50
- const findTable = (selection) => findParentNode((node) => node.type.spec.tableRole === "table")(selection);
50
+ const findTable = (selection) => findParentNode((node) => node.type.spec["tableRole"] === "table")(selection);
51
51
  const getCellsInColumn = (columnIndex) => (selection) => {
52
52
  const table2 = findTable(selection);
53
53
  if (!table2)
@@ -131,10 +131,13 @@ const getCellsInTable = (selection) => {
131
131
  };
132
132
  const selectTable = (tr) => {
133
133
  const cells = getCellsInTable(tr.selection);
134
- if (cells) {
134
+ if (cells && cells[0]) {
135
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)));
136
+ const last = cells[cells.length - 1];
137
+ if (last) {
138
+ const $lastCell = tr.doc.resolve(last.pos);
139
+ return cloneTr(tr.setSelection(new CellSelection($lastCell, $firstCell)));
140
+ }
138
141
  }
139
142
  return tr;
140
143
  };
@@ -145,7 +148,7 @@ function addRowWithAlignment(tr, { map, tableStart, table: table2 }, row) {
145
148
  const { cell: cellType, row: rowType } = tableNodeTypes(table2.type.schema);
146
149
  const cells = Array(map.width).fill(0).map((_, col) => {
147
150
  const headerCol = table2.nodeAt(map.map[col]);
148
- return cellType.createAndFill({ alignment: headerCol == null ? void 0 : headerCol.attrs.alignment });
151
+ return cellType.createAndFill({ alignment: headerCol == null ? void 0 : headerCol.attrs["alignment"] });
149
152
  });
150
153
  tr.insert(rowPos, rowType.create(null, cells));
151
154
  return tr;
@@ -179,95 +182,87 @@ const calculateItem = (actions, view) => {
179
182
  item.$.classList.remove("hide");
180
183
  });
181
184
  };
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;
185
+ const createActions = (ctx) => {
186
+ var _a, _b, _c, _d, _e, _f, _g, _h;
187
+ return {
188
+ [0]: {
189
+ $: (_a = ctx.get(themeManagerCtx).get(ThemeIcon, "leftArrow")) == null ? void 0 : _a.dom,
190
+ command: () => addColumnBefore,
191
+ disable: (view) => !getCellSelection(view).isColSelection()
214
192
  },
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;
193
+ [1]: {
194
+ $: (_b = ctx.get(themeManagerCtx).get(ThemeIcon, "rightArrow")) == null ? void 0 : _b.dom,
195
+ command: () => addColumnAfter,
196
+ disable: (view) => !getCellSelection(view).isColSelection()
227
197
  },
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;
198
+ [2]: {
199
+ $: (_c = ctx.get(themeManagerCtx).get(ThemeIcon, "upArrow")) == null ? void 0 : _c.dom,
200
+ command: () => (state, dispatch) => {
201
+ if (!isInTable(state))
202
+ return false;
203
+ if (dispatch) {
204
+ const rect = selectedRect(state);
205
+ dispatch(addRowWithAlignment(state.tr, rect, rect.top));
206
+ }
207
+ return true;
208
+ },
209
+ disable: (view) => !getCellSelection(view).isRowSelection() || getCellSelection(view).$head.parent.type.name === "table_header"
258
210
  },
259
- disable: (view) => {
260
- const selection = getCellSelection(view);
261
- if (selection.isRowSelection()) {
262
- if (selection.isColSelection()) {
211
+ [3]: {
212
+ $: (_d = ctx.get(themeManagerCtx).get(ThemeIcon, "downArrow")) == null ? void 0 : _d.dom,
213
+ command: () => (state, dispatch) => {
214
+ if (!isInTable(state))
263
215
  return false;
216
+ if (dispatch) {
217
+ const rect = selectedRect(state);
218
+ dispatch(addRowWithAlignment(state.tr, rect, rect.bottom));
219
+ }
220
+ return true;
221
+ },
222
+ disable: (view) => !getCellSelection(view).isRowSelection()
223
+ },
224
+ [4]: {
225
+ $: (_e = ctx.get(themeManagerCtx).get(ThemeIcon, "alignLeft")) == null ? void 0 : _e.dom,
226
+ command: () => setCellAttr("alignment", "left"),
227
+ disable: (view) => !getCellSelection(view).isColSelection()
228
+ },
229
+ [5]: {
230
+ $: (_f = ctx.get(themeManagerCtx).get(ThemeIcon, "alignCenter")) == null ? void 0 : _f.dom,
231
+ command: () => setCellAttr("alignment", "center"),
232
+ disable: (view) => !getCellSelection(view).isColSelection()
233
+ },
234
+ [6]: {
235
+ $: (_g = ctx.get(themeManagerCtx).get(ThemeIcon, "alignRight")) == null ? void 0 : _g.dom,
236
+ command: () => setCellAttr("alignment", "right"),
237
+ disable: (view) => !getCellSelection(view).isColSelection()
238
+ },
239
+ [7]: {
240
+ $: (_h = ctx.get(themeManagerCtx).get(ThemeIcon, "delete")) == null ? void 0 : _h.dom,
241
+ command: (_, view) => {
242
+ const selection = getCellSelection(view);
243
+ const isCol = selection.isColSelection();
244
+ const isRow = selection.isRowSelection();
245
+ if (isCol && isRow) {
246
+ return deleteTable;
247
+ }
248
+ if (isCol) {
249
+ return deleteColumn;
264
250
  }
265
- return isFirstRowSelected(selection);
251
+ return deleteRow;
252
+ },
253
+ disable: (view) => {
254
+ const selection = getCellSelection(view);
255
+ if (selection.isRowSelection()) {
256
+ if (selection.isColSelection()) {
257
+ return false;
258
+ }
259
+ return isFirstRowSelected(selection);
260
+ }
261
+ return false;
266
262
  }
267
- return false;
268
263
  }
269
- }
270
- });
264
+ };
265
+ };
271
266
  const calculatePosition = (view, dom) => {
272
267
  const { selection } = view.state;
273
268
  const isCol = selection.isColSelection();
@@ -285,61 +280,128 @@ const calculatePosition = (view, dom) => {
285
280
  return [top, left];
286
281
  });
287
282
  };
288
- var ToolTipPos;
289
- (function(ToolTipPos2) {
283
+ var ToolTipPos = /* @__PURE__ */ ((ToolTipPos2) => {
290
284
  ToolTipPos2["Left"] = "Left";
291
285
  ToolTipPos2["Top"] = "Top";
292
286
  ToolTipPos2["Point"] = "Point";
293
- })(ToolTipPos || (ToolTipPos = {}));
294
- const injectStyle$1 = ({ size, mixin, palette }, { css }) => {
295
- var _a, _b;
287
+ return ToolTipPos2;
288
+ })(ToolTipPos || {});
289
+ const injectStyle = (themeManager, { css, injectGlobal }) => {
290
+ const palette = getPalette(themeManager);
291
+ const radius = themeManager.get(ThemeSize, "radius");
292
+ const lineWidth = themeManager.get(ThemeSize, "lineWidth");
293
+ injectGlobal`
294
+ .milkdown {
295
+ .tableWrapper {
296
+ table {
297
+ width: calc(100% - 2em) !important;
298
+ margin: 1em 0 1em 1em !important;
299
+
300
+ .milkdown-cell-left,
301
+ .milkdown-cell-point,
302
+ .milkdown-cell-top {
303
+ position: absolute;
304
+
305
+ &::after {
306
+ cursor: pointer;
307
+ position: absolute;
308
+ top: 0;
309
+ left: 0;
310
+ height: 100%;
311
+ width: 100%;
312
+ display: block;
313
+ transition: all 0.2s ease-in-out;
314
+ background: ${palette("secondary", 0.12)};
315
+ content: '';
316
+ }
317
+
318
+ &:hover::after {
319
+ background: ${palette("secondary", 0.38)};
320
+ }
321
+ }
322
+
323
+ .milkdown-cell-left {
324
+ left: calc(-6px - 0.5em);
325
+ top: 0;
326
+ bottom: 0;
327
+ width: 0.5em;
328
+ }
329
+
330
+ .milkdown-cell-top {
331
+ left: 0;
332
+ right: 0;
333
+ top: calc(-6px - 0.5em);
334
+ height: 0.5em;
335
+ }
336
+
337
+ .milkdown-cell-point {
338
+ left: calc(-2px - 1em);
339
+ top: calc(-2px - 1em);
340
+ width: 1em;
341
+ height: 1em;
342
+
343
+ .icon {
344
+ position: absolute;
345
+ top: 0;
346
+ bottom: 0;
347
+ left: 0;
348
+ right: 0;
349
+ }
350
+ }
351
+ }
352
+ }
353
+ }
354
+ `;
296
355
  return css`
297
- display: inline-flex;
298
- cursor: pointer;
299
- z-index: 2;
356
+ display: inline-flex;
357
+ cursor: pointer;
358
+ z-index: 2;
300
359
 
301
- justify-content: space-evenly;
360
+ justify-content: space-evenly;
302
361
 
303
- position: absolute;
362
+ position: absolute;
304
363
 
305
- border-radius: ${size.radius};
364
+ border-radius: ${radius};
306
365
 
307
- ${(_a = mixin.border) == null ? void 0 : _a.call(mixin)};
366
+ ${themeManager.get(ThemeBorder, void 0)};
367
+ ${themeManager.get(ThemeShadow, void 0)};
308
368
 
309
- ${(_b = mixin.shadow) == null ? void 0 : _b.call(mixin)};
369
+ overflow: hidden;
370
+ background: ${palette("surface")};
310
371
 
311
- overflow: hidden;
312
- background: ${palette("surface")};
372
+ .icon {
373
+ position: relative;
374
+ color: ${palette("solid", 0.87)};
313
375
 
314
- .icon {
315
- position: relative;
316
- color: ${palette("solid", 0.87)};
376
+ width: 2em;
377
+ line-height: 2em;
378
+ text-align: center;
379
+ transition: all 0.4s ease-in-out;
317
380
 
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")};
381
+ &:hover {
382
+ background-color: ${palette("secondary", 0.12)};
383
+ }
384
+
385
+ &.active {
386
+ color: ${palette("primary")};
387
+ }
388
+
389
+ &:not(:last-child)::after {
390
+ content: '';
391
+ position: absolute;
392
+ right: 0;
393
+ top: 0;
394
+ width: ${lineWidth};
395
+ bottom: 0;
396
+ background: ${palette("line")};
397
+ }
327
398
  }
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")};
399
+
400
+ &.hide,
401
+ .hide {
402
+ display: none;
336
403
  }
337
- }
338
- &.hide,
339
- .hide {
340
- display: none;
341
- }
342
- `;
404
+ `;
343
405
  };
344
406
  const calculateClassName = (pos) => {
345
407
  switch (pos) {
@@ -356,11 +418,12 @@ const calculateClassName = (pos) => {
356
418
  }
357
419
  };
358
420
  function createWidget(ctx, cell, pos, index = 0) {
359
- const widget = Decoration.widget(cell.pos + 1, (view) => {
421
+ return Decoration.widget(cell.pos + 1, (view) => {
422
+ var _a;
360
423
  const div = document.createElement("div");
361
424
  div.classList.add(calculateClassName(pos));
362
425
  if (pos === ToolTipPos.Point) {
363
- div.appendChild(ctx.get(themeToolCtx).slots.icon("select"));
426
+ div.appendChild((_a = ctx.get(themeManagerCtx).get(ThemeIcon, "select")) == null ? void 0 : _a.dom);
364
427
  }
365
428
  div.addEventListener("mousedown", (e) => {
366
429
  if (!view)
@@ -383,15 +446,16 @@ function createWidget(ctx, cell, pos, index = 0) {
383
446
  });
384
447
  return div;
385
448
  });
386
- return widget;
387
449
  }
388
450
  const operatorPlugin = (ctx, utils) => {
389
451
  const items = createActions(ctx);
390
452
  const tooltip = document.createElement("div");
391
- const style = utils.getStyle(injectStyle$1);
392
- if (style) {
393
- tooltip.classList.add(style);
394
- }
453
+ utils.themeManager.onFlush(() => {
454
+ const style = utils.getStyle(injectStyle);
455
+ if (style) {
456
+ tooltip.classList.add(style);
457
+ }
458
+ });
395
459
  tooltip.classList.add("table-tooltip", "hide");
396
460
  return new Plugin({
397
461
  key: new PluginKey("MILKDOWN_TABLE_OP"),
@@ -473,183 +537,16 @@ const schema = tableNodes({
473
537
  }
474
538
  }
475
539
  });
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
540
  const SupportedKeys$1 = {
643
541
  NextCell: "NextCell",
644
542
  PrevCell: "PrevCell",
645
543
  ExitTable: "ExitTable"
646
544
  };
647
- const PrevCell = createCmdKey();
648
- const NextCell = createCmdKey();
649
- const BreakTable = createCmdKey();
650
- const InsertTable = createCmdKey();
545
+ const PrevCell = createCmdKey("PrevCell");
546
+ const NextCell = createCmdKey("NextCell");
547
+ const BreakTable = createCmdKey("BreakTable");
548
+ const InsertTable = createCmdKey("InsertTable");
651
549
  const table = createPlugin((utils) => {
652
- injectStyle(utils);
653
550
  return {
654
551
  schema: () => ({
655
552
  node: {
@@ -657,7 +554,7 @@ const table = createPlugin((utils) => {
657
554
  parseMarkdown: {
658
555
  match: (node) => node.type === "table",
659
556
  runner: (state, node, type) => {
660
- const align = node.align;
557
+ const align = node["align"];
661
558
  const children = node.children.map((x, i) => __spreadProps(__spreadValues({}, x), {
662
559
  align,
663
560
  isHeader: i === 0
@@ -676,7 +573,7 @@ const table = createPlugin((utils) => {
676
573
  return;
677
574
  const align = [];
678
575
  firstLine.forEach((cell) => {
679
- align.push(cell.attrs.alignment);
576
+ align.push(cell.attrs["alignment"]);
680
577
  });
681
578
  state.openNode("table", void 0, { align });
682
579
  state.next(node.content);
@@ -688,10 +585,10 @@ const table = createPlugin((utils) => {
688
585
  parseMarkdown: {
689
586
  match: (node) => node.type === "tableRow",
690
587
  runner: (state, node, type) => {
691
- const align = node.align;
588
+ const align = node["align"];
692
589
  const children = node.children.map((x, i) => __spreadProps(__spreadValues({}, x), {
693
590
  align: align[i],
694
- isHeader: node.isHeader
591
+ isHeader: node["isHeader"]
695
592
  }));
696
593
  state.openNode(type);
697
594
  state.next(children);
@@ -709,10 +606,10 @@ const table = createPlugin((utils) => {
709
606
  }),
710
607
  table_cell: __spreadProps(__spreadValues({}, schema.table_cell), {
711
608
  parseMarkdown: {
712
- match: (node) => node.type === "tableCell" && !node.isHeader,
609
+ match: (node) => node.type === "tableCell" && !node["isHeader"],
713
610
  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();
611
+ const align = node["align"];
612
+ state.openNode(type, { alignment: align }).openNode(state.schema.nodes["paragraph"]).next(node.children).closeNode().closeNode();
716
613
  }
717
614
  },
718
615
  toMarkdown: {
@@ -724,11 +621,11 @@ const table = createPlugin((utils) => {
724
621
  }),
725
622
  table_header: __spreadProps(__spreadValues({}, schema.table_header), {
726
623
  parseMarkdown: {
727
- match: (node) => node.type === "tableCell" && !!node.isHeader,
624
+ match: (node) => node.type === "tableCell" && !!node["isHeader"],
728
625
  runner: (state, node, type) => {
729
- const align = node.align;
626
+ const align = node["align"];
730
627
  state.openNode(type, { alignment: align });
731
- state.openNode(state.schema.nodes.paragraph);
628
+ state.openNode(state.schema.nodes["paragraph"]);
732
629
  state.next(node.children);
733
630
  state.closeNode();
734
631
  state.closeNode();
@@ -758,7 +655,7 @@ const table = createPlugin((utils) => {
758
655
  commands: (_, ctx) => [
759
656
  createCmd(PrevCell, () => goToNextCell(-1)),
760
657
  createCmd(NextCell, () => goToNextCell(1)),
761
- createCmd(BreakTable, () => exitTable(ctx.get(schemaCtx).nodes.paragraph)),
658
+ createCmd(BreakTable, () => exitTable(ctx.get(schemaCtx).nodes["paragraph"])),
762
659
  createCmd(InsertTable, () => (state, dispatch) => {
763
660
  const { selection, tr } = state;
764
661
  const { from } = selection;
@@ -785,12 +682,9 @@ const SupportedKeys = __spreadProps(__spreadValues(__spreadValues({}, SupportedK
785
682
  StrikeThrough: "StrikeThrough",
786
683
  TaskList: "TaskList"
787
684
  });
788
- const ToggleStrikeThrough = createCmdKey();
685
+ const ToggleStrikeThrough = createCmdKey("ToggleStrikeThrough");
686
+ const id = "strike_through";
789
687
  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
688
  return {
795
689
  id,
796
690
  schema: () => ({
@@ -798,7 +692,7 @@ const strikeThrough = createMark((utils) => {
798
692
  { tag: "del" },
799
693
  { style: "text-decoration", getAttrs: (value) => value === "line-through" }
800
694
  ],
801
- toDOM: (mark) => ["del", { class: utils.getClassName(mark.attrs, "strike-through", style) }],
695
+ toDOM: (mark) => ["del", { class: utils.getClassName(mark.attrs, "strike-through") }],
802
696
  parseMarkdown: {
803
697
  match: (node) => node.type === "delete",
804
698
  runner: (state, node, markType) => {
@@ -824,61 +718,15 @@ const strikeThrough = createMark((utils) => {
824
718
  }
825
719
  };
826
720
  });
827
- const SplitTaskListItem = createCmdKey();
828
- const SinkTaskListItem = createCmdKey();
829
- const LiftTaskListItem = createCmdKey();
830
- const TurnIntoTaskList = createCmdKey();
721
+ const SplitTaskListItem = createCmdKey("SplitTaskListItem");
722
+ const SinkTaskListItem = createCmdKey("SinkTaskListItem");
723
+ const LiftTaskListItem = createCmdKey("LiftTaskListItem");
724
+ const TurnIntoTaskList = createCmdKey("TurnIntoTaskList");
831
725
  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
- `);
726
+ const id2 = "task_list_item";
879
727
  return {
880
- id,
881
- schema: () => ({
728
+ id: id2,
729
+ schema: (ctx) => ({
882
730
  group: "listItem",
883
731
  content: "paragraph block*",
884
732
  defining: true,
@@ -895,33 +743,58 @@ const taskListItem = createNode((utils) => {
895
743
  if (!(dom instanceof HTMLElement)) {
896
744
  throw new Error();
897
745
  }
898
- return { checked: dom.dataset.checked === "true" };
746
+ return { checked: dom.dataset["checked"] === "true" };
899
747
  }
900
748
  }
901
749
  ],
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
- ],
750
+ toDOM: (node) => {
751
+ const checkbox = document.createElement("input");
752
+ checkbox.type = "checkbox";
753
+ checkbox.checked = node.attrs["checked"];
754
+ checkbox.className = utils.getClassName(node.attrs, "task-list-item_checkbox");
755
+ checkbox.onchange = (event) => {
756
+ const target = event.target;
757
+ if (!(target instanceof HTMLInputElement))
758
+ return;
759
+ const view = ctx.get(editorViewCtx);
760
+ if (!view.editable) {
761
+ checkbox.checked = !checkbox.checked;
762
+ return;
763
+ }
764
+ const { top, left } = target.getBoundingClientRect();
765
+ const result = view.posAtCoords({ top, left });
766
+ if (!result)
767
+ return;
768
+ const { tr } = view.state;
769
+ view.dispatch(tr.setNodeMarkup(result.inside, void 0, {
770
+ checked: target.checked
771
+ }));
772
+ };
773
+ return [
774
+ "li",
775
+ {
776
+ "data-type": "task-item",
777
+ "data-checked": node.attrs["checked"] ? "true" : "false",
778
+ class: utils.getClassName(node.attrs, "task-list-item")
779
+ },
780
+ checkbox,
781
+ ["span", { class: utils.getClassName(node.attrs, "task-list-item_body") }, 0]
782
+ ];
783
+ },
911
784
  parseMarkdown: {
912
785
  match: ({ type, checked }) => {
913
786
  return type === "listItem" && checked !== null;
914
787
  },
915
788
  runner: (state, node, type) => {
916
- state.openNode(type, { checked: node.checked });
789
+ state.openNode(type, { checked: node["checked"] });
917
790
  state.next(node.children);
918
791
  state.closeNode();
919
792
  }
920
793
  },
921
794
  toMarkdown: {
922
- match: (node) => node.type.name === id,
795
+ match: (node) => node.type.name === id2,
923
796
  runner: (state, node) => {
924
- state.openNode("listItem", void 0, { checked: node.attrs.checked });
797
+ state.openNode("listItem", void 0, { checked: node.attrs["checked"] });
925
798
  state.next(node.content);
926
799
  state.closeNode();
927
800
  }
@@ -944,68 +817,30 @@ const taskListItem = createNode((utils) => {
944
817
  [SupportedKeys.LiftListItem]: createShortcut(LiftTaskListItem, "Mod-["),
945
818
  [SupportedKeys.TaskList]: createShortcut(TurnIntoTaskList, "Mod-Alt-9")
946
819
  },
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;
820
+ view: () => (node, view, getPos) => {
821
+ let currNode = node;
822
+ const renderer = utils.themeManager.get("task-list-item", {
823
+ editable: () => view.editable,
824
+ onChange: (selected) => {
825
+ const { tr } = view.state;
826
+ view.dispatch(tr.setNodeMarkup(getPos(), void 0, {
827
+ checked: selected
828
+ }));
970
829
  }
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
830
  });
991
- setIcon(node.attrs.checked ? "checked" : "unchecked");
831
+ if (!renderer)
832
+ return {};
833
+ const { dom, contentDOM, onUpdate } = renderer;
834
+ onUpdate(currNode);
992
835
  return {
993
- dom: listItem2,
994
- contentDOM: content,
836
+ dom,
837
+ contentDOM,
995
838
  update: (updatedNode) => {
996
- if (updatedNode.type.name !== id)
839
+ if (updatedNode.type.name !== id2)
997
840
  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");
841
+ currNode = updatedNode;
842
+ onUpdate(currNode);
1005
843
  return true;
1006
- },
1007
- destroy: () => {
1008
- checkbox.removeEventListener("change", onChange);
1009
844
  }
1010
845
  };
1011
846
  }