@milkdown/preset-gfm 6.5.2 → 6.5.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 (94) hide show
  1. package/lib/footnote/definition.d.ts +1 -1
  2. package/lib/footnote/definition.d.ts.map +1 -1
  3. package/lib/footnote/index.d.ts.map +1 -1
  4. package/lib/footnote/reference.d.ts +1 -1
  5. package/lib/footnote/reference.d.ts.map +1 -1
  6. package/lib/footnote/utils.d.ts.map +1 -1
  7. package/lib/index.d.ts +1 -1
  8. package/lib/index.d.ts.map +1 -1
  9. package/lib/index.es.js +649 -607
  10. package/lib/index.es.js.map +1 -1
  11. package/lib/strike-through.d.ts +1 -1
  12. package/lib/strike-through.d.ts.map +1 -1
  13. package/lib/supported-keys.d.ts +1 -1
  14. package/lib/supported-keys.d.ts.map +1 -1
  15. package/lib/table/command.d.ts +2 -2
  16. package/lib/table/command.d.ts.map +1 -1
  17. package/lib/table/index.d.ts +1 -1
  18. package/lib/table/index.d.ts.map +1 -1
  19. package/lib/table/nodes/index.d.ts +1 -1
  20. package/lib/table/nodes/index.d.ts.map +1 -1
  21. package/lib/table/operator-plugin/actions.d.ts +5 -5
  22. package/lib/table/operator-plugin/actions.d.ts.map +1 -1
  23. package/lib/table/operator-plugin/calc-pos.d.ts +1 -1
  24. package/lib/table/operator-plugin/calc-pos.d.ts.map +1 -1
  25. package/lib/table/operator-plugin/constant.d.ts.map +1 -1
  26. package/lib/table/operator-plugin/helper.d.ts +3 -3
  27. package/lib/table/operator-plugin/helper.d.ts.map +1 -1
  28. package/lib/table/operator-plugin/index.d.ts +2 -2
  29. package/lib/table/operator-plugin/index.d.ts.map +1 -1
  30. package/lib/table/operator-plugin/style.d.ts +1 -1
  31. package/lib/table/operator-plugin/style.d.ts.map +1 -1
  32. package/lib/table/operator-plugin/widget.d.ts +2 -2
  33. package/lib/table/operator-plugin/widget.d.ts.map +1 -1
  34. package/lib/table/plugin/auto-insert-zero-space.d.ts.map +1 -1
  35. package/lib/table/plugin/cell-selection.d.ts +5 -3
  36. package/lib/table/plugin/cell-selection.d.ts.map +1 -1
  37. package/lib/table/plugin/column-resizing.d.ts +2 -1
  38. package/lib/table/plugin/column-resizing.d.ts.map +1 -1
  39. package/lib/table/plugin/commands.d.ts +2 -2
  40. package/lib/table/plugin/commands.d.ts.map +1 -1
  41. package/lib/table/plugin/copy-paste.d.ts +6 -5
  42. package/lib/table/plugin/copy-paste.d.ts.map +1 -1
  43. package/lib/table/plugin/fix-tables.d.ts +3 -2
  44. package/lib/table/plugin/fix-tables.d.ts.map +1 -1
  45. package/lib/table/plugin/index.d.ts.map +1 -1
  46. package/lib/table/plugin/schema.d.ts +1 -1
  47. package/lib/table/plugin/schema.d.ts.map +1 -1
  48. package/lib/table/plugin/table-editing.d.ts +1 -1
  49. package/lib/table/plugin/table-editing.d.ts.map +1 -1
  50. package/lib/table/plugin/table-map.d.ts +2 -2
  51. package/lib/table/plugin/table-map.d.ts.map +1 -1
  52. package/lib/table/plugin/table-view.d.ts +2 -2
  53. package/lib/table/plugin/table-view.d.ts.map +1 -1
  54. package/lib/table/plugin/types.d.ts +2 -2
  55. package/lib/table/plugin/types.d.ts.map +1 -1
  56. package/lib/table/plugin/util.d.ts +2 -2
  57. package/lib/table/plugin/util.d.ts.map +1 -1
  58. package/lib/table/utils.d.ts +5 -5
  59. package/lib/table/utils.d.ts.map +1 -1
  60. package/lib/task-list-item.d.ts +2 -2
  61. package/lib/task-list-item.d.ts.map +1 -1
  62. package/package.json +22 -17
  63. package/src/footnote/definition.ts +172 -166
  64. package/src/footnote/index.ts +2 -2
  65. package/src/footnote/reference.ts +166 -162
  66. package/src/footnote/utils.ts +2 -2
  67. package/src/index.ts +83 -83
  68. package/src/strike-through.ts +36 -36
  69. package/src/supported-keys.ts +9 -8
  70. package/src/table/command.ts +17 -16
  71. package/src/table/index.ts +9 -9
  72. package/src/table/nodes/index.ts +177 -174
  73. package/src/table/operator-plugin/actions.ts +103 -102
  74. package/src/table/operator-plugin/calc-pos.ts +31 -34
  75. package/src/table/operator-plugin/constant.ts +3 -3
  76. package/src/table/operator-plugin/helper.ts +31 -32
  77. package/src/table/operator-plugin/index.ts +104 -95
  78. package/src/table/operator-plugin/style.ts +10 -9
  79. package/src/table/operator-plugin/widget.ts +47 -45
  80. package/src/table/plugin/auto-insert-zero-space.ts +41 -41
  81. package/src/table/plugin/cell-selection.ts +325 -296
  82. package/src/table/plugin/column-resizing.ts +226 -198
  83. package/src/table/plugin/commands.ts +464 -421
  84. package/src/table/plugin/copy-paste.ts +256 -240
  85. package/src/table/plugin/fix-tables.ts +103 -88
  86. package/src/table/plugin/index.ts +3 -3
  87. package/src/table/plugin/schema.ts +100 -94
  88. package/src/table/plugin/table-editing.ts +324 -230
  89. package/src/table/plugin/table-map.ts +294 -229
  90. package/src/table/plugin/table-view.ts +66 -62
  91. package/src/table/plugin/types.ts +8 -8
  92. package/src/table/plugin/util.ts +78 -66
  93. package/src/table/utils.ts +141 -138
  94. package/src/task-list-item.ts +151 -146
@@ -1,76 +1,80 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { Node } from '@milkdown/prose/model';
3
- import { NodeView } from '@milkdown/prose/view';
2
+ import type { Node } from '@milkdown/prose/model'
3
+ import type { NodeView } from '@milkdown/prose/view'
4
4
 
5
- /* Copyright 2021, Milkdown by Mirone. */
6
5
  export class TableView implements NodeView {
7
- public dom: HTMLElement;
8
- public contentDOM: HTMLElement;
9
- public table: HTMLTableElement;
10
- public colgroup: HTMLTableColElement;
6
+ public dom: HTMLElement
7
+ public contentDOM: HTMLElement
8
+ public table: HTMLTableElement
9
+ public colgroup: HTMLTableColElement
11
10
 
12
- constructor(public node: Node, public cellMinWidth: number) {
13
- this.node = node;
14
- this.cellMinWidth = cellMinWidth;
15
- this.dom = document.createElement('div');
16
- this.dom.className = 'tableWrapper';
17
- this.table = this.dom.appendChild(document.createElement('table'));
18
- this.colgroup = this.table.appendChild(document.createElement('colgroup'));
19
- updateColumns(node, this.colgroup, this.table, cellMinWidth);
20
- this.contentDOM = this.table.appendChild(document.createElement('tbody'));
21
- }
11
+ constructor(public node: Node, public cellMinWidth: number) {
12
+ this.node = node
13
+ this.cellMinWidth = cellMinWidth
14
+ this.dom = document.createElement('div')
15
+ this.dom.className = 'tableWrapper'
16
+ this.table = this.dom.appendChild(document.createElement('table'))
17
+ this.colgroup = this.table.appendChild(document.createElement('colgroup'))
18
+ updateColumns(node, this.colgroup, this.table, cellMinWidth)
19
+ this.contentDOM = this.table.appendChild(document.createElement('tbody'))
20
+ }
22
21
 
23
- update(node: Node) {
24
- if (node.type != this.node.type) return false;
25
- this.node = node;
26
- updateColumns(node, this.colgroup, this.table, this.cellMinWidth);
27
- return true;
28
- }
22
+ update(node: Node) {
23
+ if (node.type != this.node.type)
24
+ return false
25
+ this.node = node
26
+ updateColumns(node, this.colgroup, this.table, this.cellMinWidth)
27
+ return true
28
+ }
29
29
 
30
- ignoreMutation(record: MutationRecord) {
31
- return record.type == 'attributes' && (record.target == this.table || this.colgroup.contains(record.target));
32
- }
30
+ ignoreMutation(record: MutationRecord) {
31
+ return record.type == 'attributes' && (record.target == this.table || this.colgroup.contains(record.target))
32
+ }
33
33
  }
34
34
 
35
35
  export function updateColumns(
36
- node: Node,
37
- colgroup: HTMLTableColElement,
38
- table: HTMLTableElement,
39
- cellMinWidth: number,
40
- overrideCol?: number,
41
- overrideValue?: number,
36
+ node: Node,
37
+ colgroup: HTMLTableColElement,
38
+ table: HTMLTableElement,
39
+ cellMinWidth: number,
40
+ overrideCol?: number,
41
+ overrideValue?: number,
42
42
  ) {
43
- let totalWidth = 0,
44
- fixedWidth = true;
45
- let nextDOM = colgroup.firstChild;
46
- const row = node.firstChild as Node;
47
- for (let i = 0, col = 0; i < row.childCount; i++) {
48
- const { colspan, colwidth } = row.child(i).attrs;
49
- for (let j = 0; j < colspan; j++, col++) {
50
- const hasWidth = overrideCol == col ? overrideValue : colwidth && colwidth[j];
51
- const cssWidth = hasWidth ? hasWidth + 'px' : '';
52
- totalWidth += hasWidth || cellMinWidth;
53
- if (!hasWidth) fixedWidth = false;
54
- if (!nextDOM) {
55
- colgroup.appendChild(document.createElement('col')).style.width = cssWidth;
56
- } else {
57
- if ((nextDOM as HTMLElement).style.width != cssWidth) (nextDOM as HTMLElement).style.width = cssWidth;
58
- nextDOM = nextDOM.nextSibling;
59
- }
60
- }
43
+ let totalWidth = 0
44
+ let fixedWidth = true
45
+ let nextDOM = colgroup.firstChild
46
+ const row = node.firstChild as Node
47
+ for (let i = 0, col = 0; i < row.childCount; i++) {
48
+ const { colspan, colwidth } = row.child(i).attrs
49
+ for (let j = 0; j < colspan; j++, col++) {
50
+ const hasWidth = overrideCol == col ? overrideValue : colwidth && colwidth[j]
51
+ const cssWidth = hasWidth ? `${hasWidth}px` : ''
52
+ totalWidth += hasWidth || cellMinWidth
53
+ if (!hasWidth)
54
+ fixedWidth = false
55
+ if (!nextDOM) {
56
+ colgroup.appendChild(document.createElement('col')).style.width = cssWidth
57
+ }
58
+ else {
59
+ if ((nextDOM as HTMLElement).style.width != cssWidth)
60
+ (nextDOM as HTMLElement).style.width = cssWidth
61
+ nextDOM = nextDOM.nextSibling
62
+ }
61
63
  }
64
+ }
62
65
 
63
- while (nextDOM) {
64
- const after = nextDOM.nextSibling;
65
- nextDOM.parentNode?.removeChild(nextDOM);
66
- nextDOM = after;
67
- }
66
+ while (nextDOM) {
67
+ const after = nextDOM.nextSibling
68
+ nextDOM.parentNode?.removeChild(nextDOM)
69
+ nextDOM = after
70
+ }
68
71
 
69
- if (fixedWidth) {
70
- table.style.width = totalWidth + 'px';
71
- table.style.minWidth = '';
72
- } else {
73
- table.style.width = '';
74
- table.style.minWidth = totalWidth + 'px';
75
- }
72
+ if (fixedWidth) {
73
+ table.style.width = `${totalWidth}px`
74
+ table.style.minWidth = ''
75
+ }
76
+ else {
77
+ table.style.width = ''
78
+ table.style.minWidth = `${totalWidth}px`
79
+ }
76
80
  }
@@ -1,16 +1,16 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
 
3
- export type getFromDOM<T> = (dom: Element) => T;
4
- export type setDOMAttr = <Value>(value: Value, attrs: Record<string, unknown>) => void;
3
+ export type getFromDOM<T> = (dom: Element) => T
4
+ export type setDOMAttr = <Value>(value: Value, attrs: Record<string, unknown>) => void
5
5
 
6
6
  export interface CellAttributes<T = unknown> {
7
- default: T;
8
- getFromDOM?: getFromDOM<T>;
9
- setDOMAttr?: setDOMAttr;
7
+ default: T
8
+ getFromDOM?: getFromDOM<T>
9
+ setDOMAttr?: setDOMAttr
10
10
  }
11
11
 
12
12
  export interface TableNodesOptions {
13
- tableGroup?: string;
14
- cellContent: string;
15
- cellAttributes: { [key: string]: CellAttributes };
13
+ tableGroup?: string
14
+ cellContent: string
15
+ cellAttributes: { [key: string]: CellAttributes }
16
16
  }
@@ -1,107 +1,119 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { Attrs, Node, ResolvedPos } from '@milkdown/prose/model';
3
- import { EditorState, NodeSelection } from '@milkdown/prose/state';
2
+ import type { Attrs, Node, ResolvedPos } from '@milkdown/prose/model'
3
+ import type { EditorState, NodeSelection } from '@milkdown/prose/state'
4
4
 
5
- import { CellSelection } from './cell-selection';
6
- import { tableNodeTypes } from './schema';
7
- import { TableMap } from './table-map';
5
+ import { CellSelection } from './cell-selection'
6
+ import { tableNodeTypes } from './schema'
7
+ import { TableMap } from './table-map'
8
8
 
9
9
  export function cellAround($pos: ResolvedPos) {
10
- for (let d = $pos.depth - 1; d > 0; d--)
11
- if ($pos.node(d).type.spec['tableRole'] == 'row') return $pos.node(0).resolve($pos.before(d + 1));
12
- return undefined;
10
+ for (let d = $pos.depth - 1; d > 0; d--) {
11
+ if ($pos.node(d).type.spec.tableRole == 'row')
12
+ return $pos.node(0).resolve($pos.before(d + 1))
13
+ }
14
+ return undefined
13
15
  }
14
16
 
15
17
  export function cellWrapping($pos: ResolvedPos) {
16
- for (let d = $pos.depth; d > 0; d--) {
17
- // Sometimes the cell can be in the same depth.
18
- const role = $pos.node(d).type.spec['tableRole'];
19
- if (role === 'cell' || role === 'header_cell') return $pos.node(d);
20
- }
21
- return null;
18
+ for (let d = $pos.depth; d > 0; d--) {
19
+ // Sometimes the cell can be in the same depth.
20
+ const role = $pos.node(d).type.spec.tableRole
21
+ if (role === 'cell' || role === 'header_cell')
22
+ return $pos.node(d)
23
+ }
24
+ return null
22
25
  }
23
26
 
24
27
  export function pointsAtCell($pos: ResolvedPos): Node | null {
25
- if ($pos.parent.type.spec['tableRole'] == 'row') return $pos.nodeAfter;
26
- return null;
28
+ if ($pos.parent.type.spec.tableRole == 'row')
29
+ return $pos.nodeAfter
30
+ return null
27
31
  }
28
32
 
29
33
  export function moveCellForward($pos: ResolvedPos) {
30
- return $pos.node(0).resolve($pos.pos + ($pos.nodeAfter as Node).nodeSize);
34
+ return $pos.node(0).resolve($pos.pos + ($pos.nodeAfter as Node).nodeSize)
31
35
  }
32
36
 
33
37
  export function inSameTable($a: ResolvedPos, $b: ResolvedPos) {
34
- return $a.depth == $b.depth && $a.pos >= $b.start(-1) && $a.pos <= $b.end(-1);
38
+ return $a.depth == $b.depth && $a.pos >= $b.start(-1) && $a.pos <= $b.end(-1)
35
39
  }
36
40
 
37
41
  export function nextCell($pos: ResolvedPos, axis: string, dir: number) {
38
- const start = $pos.start(-1),
39
- map = TableMap.get($pos.node(-1));
40
- const moved = map.nextCell($pos.pos - start, axis, dir);
41
- return moved == null ? null : $pos.node(0).resolve(start + moved);
42
+ const start = $pos.start(-1)
43
+ const map = TableMap.get($pos.node(-1))
44
+ const moved = map.nextCell($pos.pos - start, axis, dir)
45
+ return moved == null ? null : $pos.node(0).resolve(start + moved)
42
46
  }
43
47
 
44
48
  export function setAttr<T>(attrs: Attrs, name: string, value: T) {
45
- const result: Record<string, unknown> = {};
46
- for (const prop in attrs) result[prop] = attrs[prop];
47
- result[name] = value;
48
- return result as Attrs;
49
+ const result: Record<string, unknown> = {}
50
+ for (const prop in attrs) result[prop] = attrs[prop]
51
+ result[name] = value
52
+ return result as Attrs
49
53
  }
50
54
 
51
55
  export function removeColSpan(attrs: Attrs, pos: number, n = 1) {
52
- const result = setAttr(attrs, 'colspan', attrs['colspan'] - n) as Record<string, unknown>;
53
- if (result['colwidth']) {
54
- const widths = result['colwidth'] as number[];
55
- result['colwidth'] = widths.slice();
56
- widths.splice(pos, n);
57
- if (!widths.some((w) => w > 0)) result['colwidth'] = null;
58
- }
59
- return result;
56
+ const result = setAttr(attrs, 'colspan', attrs.colspan - n) as Record<string, unknown>
57
+ if (result.colwidth) {
58
+ const widths = result.colwidth as number[]
59
+ result.colwidth = widths.slice()
60
+ widths.splice(pos, n)
61
+ if (!widths.some(w => w > 0))
62
+ result.colwidth = null
63
+ }
64
+ return result
60
65
  }
61
66
 
62
67
  export function isInTable(state: EditorState) {
63
- const $head = state.selection.$head;
64
- for (let d = $head.depth; d > 0; d--) if ($head.node(d).type.spec['tableRole'] == 'row') return true;
65
- return false;
68
+ const $head = state.selection.$head
69
+ for (let d = $head.depth; d > 0; d--) {
70
+ if ($head.node(d).type.spec.tableRole == 'row')
71
+ return true
72
+ }
73
+ return false
66
74
  }
67
75
 
68
76
  export function selectionCell(state: EditorState) {
69
- const sel = state.selection;
70
- if (sel instanceof CellSelection) {
71
- return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell;
72
- } else if ((sel as NodeSelection).node && (sel as NodeSelection).node.type.spec['tableRole'] == 'cell') {
73
- return sel.$anchor;
74
- }
75
- return cellAround(sel.$head) || cellNear(sel.$head);
77
+ const sel = state.selection
78
+ if (sel instanceof CellSelection)
79
+ return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell
80
+ else if ((sel as NodeSelection).node && (sel as NodeSelection).node.type.spec.tableRole == 'cell')
81
+ return sel.$anchor
82
+
83
+ return cellAround(sel.$head) || cellNear(sel.$head)
76
84
  }
77
85
 
78
86
  function cellNear($pos: ResolvedPos) {
79
- for (let after = $pos.nodeAfter, pos = $pos.pos; after; after = after.firstChild, pos++) {
80
- const role = after.type.spec['tableRole'];
81
- if (role == 'cell' || role == 'header_cell') return $pos.doc.resolve(pos);
82
- }
83
- for (let before = $pos.nodeBefore, pos = $pos.pos; before; before = before.lastChild, pos--) {
84
- const role = before.type.spec['tableRole'];
85
- if (role == 'cell' || role == 'header_cell') return $pos.doc.resolve(pos - before.nodeSize);
86
- }
87
- return;
87
+ for (let after = $pos.nodeAfter, pos = $pos.pos; after; after = after.firstChild, pos++) {
88
+ const role = after.type.spec.tableRole
89
+ if (role == 'cell' || role == 'header_cell')
90
+ return $pos.doc.resolve(pos)
91
+ }
92
+ for (let before = $pos.nodeBefore, pos = $pos.pos; before; before = before.lastChild, pos--) {
93
+ const role = before.type.spec.tableRole
94
+ if (role == 'cell' || role == 'header_cell')
95
+ return $pos.doc.resolve(pos - before.nodeSize)
96
+ }
97
+
98
+ return undefined
88
99
  }
89
100
 
90
101
  export function addColSpan(attrs: Attrs, pos: number, n = 1) {
91
- const result = setAttr(attrs, 'colspan', attrs['colspan'] + n) as Record<string, unknown>;
92
- if (result['colwidth']) {
93
- const widths = result['colwidth'] as number[];
94
- result['colwidth'] = widths.slice();
95
- for (let i = 0; i < n; i++) widths.splice(pos, 0, 0);
96
- }
97
- return result as Attrs;
102
+ const result = setAttr(attrs, 'colspan', attrs.colspan + n) as Record<string, unknown>
103
+ if (result.colwidth) {
104
+ const widths = result.colwidth as number[]
105
+ result.colwidth = widths.slice()
106
+ for (let i = 0; i < n; i++) widths.splice(pos, 0, 0)
107
+ }
108
+ return result as Attrs
98
109
  }
99
110
 
100
111
  export function columnIsHeader(map: TableMap, table: Node, col: number) {
101
- const headerCell = tableNodeTypes(table.type.schema).header_cell;
102
- for (let row = 0; row < map.height; row++) {
103
- const pos = map.map[col + row * map.width] as number;
104
- if ((table.nodeAt(pos) as Node).type != headerCell) return false;
105
- }
106
- return true;
112
+ const headerCell = tableNodeTypes(table.type.schema).header_cell
113
+ for (let row = 0; row < map.height; row++) {
114
+ const pos = map.map[col + row * map.width] as number
115
+ if ((table.nodeAt(pos) as Node).type != headerCell)
116
+ return false
117
+ }
118
+ return true
107
119
  }