@milkdown/preset-gfm 6.5.0 → 6.5.3

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 +1007 -863
  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 +17 -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 -24
  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,260 +1,288 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { Attrs, Node } from '@milkdown/prose/model';
3
- import { EditorState, Plugin, PluginKey, Transaction } from '@milkdown/prose/state';
4
- import { Decoration, DecorationSet, EditorView } from '@milkdown/prose/view';
2
+ import type { Attrs, Node } from '@milkdown/prose/model'
3
+ import type { EditorState, Transaction } from '@milkdown/prose/state'
4
+ import { Plugin, PluginKey } from '@milkdown/prose/state'
5
+ import type { EditorView } from '@milkdown/prose/view'
6
+ import { Decoration, DecorationSet } from '@milkdown/prose/view'
5
7
 
6
- import { tableNodeTypes } from './schema';
7
- import { TableMap } from './table-map';
8
- import { TableView, updateColumns } from './table-view';
9
- import { cellAround, pointsAtCell, setAttr } from './util';
8
+ import { tableNodeTypes } from './schema'
9
+ import { TableMap } from './table-map'
10
+ import { TableView, updateColumns } from './table-view'
11
+ import { cellAround, pointsAtCell, setAttr } from './util'
10
12
 
11
- export const key = new PluginKey('tableColumnResizing');
13
+ export const key = new PluginKey('tableColumnResizing')
12
14
 
13
15
  export function columnResizing({
14
- handleWidth = 5,
15
- cellMinWidth = 25,
16
- View = TableView,
17
- lastColumnResizable = true,
16
+ handleWidth = 5,
17
+ cellMinWidth = 25,
18
+ View = TableView,
19
+ lastColumnResizable = true,
18
20
  } = {}) {
19
- const plugin = new Plugin({
20
- key,
21
- state: {
22
- init(this: Plugin, _, state) {
23
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
24
- this.spec.props!.nodeViews![tableNodeTypes(state.schema).table.name] = (node) =>
25
- new View(node, cellMinWidth);
26
- return new ResizeState(-1, false);
27
- },
28
- apply(tr, prev) {
29
- return prev.apply(tr);
30
- },
31
- },
32
- props: {
33
- attributes(state) {
34
- const pluginState = key.getState(state);
35
- return pluginState.activeHandle > -1 ? { class: 'resize-cursor' } : (undefined as unknown as Attrs);
36
- },
21
+ const plugin = new Plugin({
22
+ key,
23
+ state: {
24
+ init(this: Plugin, _, state) {
25
+ this.spec.props!.nodeViews![tableNodeTypes(state.schema).table.name] = node =>
26
+ new View(node, cellMinWidth)
27
+ return new ResizeState(-1, false)
28
+ },
29
+ apply(tr, prev) {
30
+ return prev.apply(tr)
31
+ },
32
+ },
33
+ props: {
34
+ attributes(state) {
35
+ const pluginState = key.getState(state)
36
+ return pluginState.activeHandle > -1 ? { class: 'resize-cursor' } : (undefined as unknown as Attrs)
37
+ },
37
38
 
38
- handleDOMEvents: {
39
- mousemove(view, event) {
40
- handleMouseMove(view, event as MouseEvent, handleWidth, lastColumnResizable);
41
- },
42
- mouseleave(view) {
43
- handleMouseLeave(view);
44
- },
45
- mousedown(view, event) {
46
- handleMouseDown(view, event as MouseEvent, cellMinWidth);
47
- },
48
- },
39
+ handleDOMEvents: {
40
+ mousemove(view, event) {
41
+ if (!view.editable)
42
+ return
43
+ handleMouseMove(view, event as MouseEvent, handleWidth, lastColumnResizable)
44
+ },
45
+ mouseleave(view) {
46
+ if (!view.editable)
47
+ return
48
+ handleMouseLeave(view)
49
+ },
50
+ mousedown(view, event) {
51
+ if (!view.editable)
52
+ return
53
+ handleMouseDown(view, event as MouseEvent, cellMinWidth)
54
+ },
55
+ },
49
56
 
50
- decorations(state) {
51
- const pluginState = key.getState(state);
52
- if (pluginState.activeHandle > -1) return handleDecorations(state, pluginState.activeHandle);
57
+ decorations(state) {
58
+ const pluginState = key.getState(state)
59
+ if (pluginState.activeHandle > -1)
60
+ return handleDecorations(state, pluginState.activeHandle)
53
61
 
54
- return null;
55
- },
62
+ return null
63
+ },
56
64
 
57
- nodeViews: {},
58
- },
59
- });
60
- return plugin;
65
+ nodeViews: {},
66
+ },
67
+ })
68
+ return plugin
61
69
  }
62
70
 
63
71
  class ResizeState {
64
- constructor(public activeHandle: number, public dragging: null | boolean) {
65
- this.activeHandle = activeHandle;
66
- this.dragging = dragging;
67
- }
72
+ constructor(public activeHandle: number, public dragging: null | boolean) {
73
+ this.activeHandle = activeHandle
74
+ this.dragging = dragging
75
+ }
68
76
 
69
- apply(this: ResizeState, tr: Transaction) {
70
- // eslint-disable-next-line @typescript-eslint/no-this-alias
71
- let state = this;
72
- const action = tr.getMeta(key);
73
- if (action && action.setHandle != null) return new ResizeState(action.setHandle, null);
74
- if (action && action.setDragging !== undefined) return new ResizeState(state.activeHandle, action.setDragging);
75
- if (state.activeHandle > -1 && tr.docChanged) {
76
- let handle = tr.mapping.map(state.activeHandle, -1);
77
- if (!pointsAtCell(tr.doc.resolve(handle))) handle = 0;
78
- state = new ResizeState(handle, state.dragging);
79
- }
80
- return state;
77
+ apply(this: ResizeState, tr: Transaction) {
78
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
79
+ let state = this
80
+ const action = tr.getMeta(key)
81
+ if (action && action.setHandle != null)
82
+ return new ResizeState(action.setHandle, null)
83
+ if (action && action.setDragging !== undefined)
84
+ return new ResizeState(state.activeHandle, action.setDragging)
85
+ if (state.activeHandle > -1 && tr.docChanged) {
86
+ let handle = tr.mapping.map(state.activeHandle, -1)
87
+ if (!pointsAtCell(tr.doc.resolve(handle)))
88
+ handle = 0
89
+ state = new ResizeState(handle, state.dragging)
81
90
  }
91
+ return state
92
+ }
82
93
  }
83
94
 
84
95
  function handleMouseMove(view: EditorView, event: MouseEvent, handleWidth: number, lastColumnResizable: boolean) {
85
- const pluginState = key.getState(view.state);
96
+ const pluginState = key.getState(view.state)
86
97
 
87
- if (!pluginState.dragging) {
88
- const target = domCellAround(event.target as Element);
89
- let cell = -1;
90
- if (target) {
91
- const { left, right } = target.getBoundingClientRect();
92
- if (event.clientX - left <= handleWidth) cell = edgeCell(view, event, 'left');
93
- else if (right - event.clientX <= handleWidth) cell = edgeCell(view, event, 'right');
94
- }
98
+ if (!pluginState.dragging) {
99
+ const target = domCellAround(event.target as Element)
100
+ let cell = -1
101
+ if (target) {
102
+ const { left, right } = target.getBoundingClientRect()
103
+ if (
104
+ right - event.clientX <= handleWidth
105
+ // hover on the right border of the cell, the `target` is the next cell
106
+ || event.clientX === Math.floor(left)
107
+ )
108
+ cell = edgeCell(view, event, 'right')
109
+ else if (event.clientX - left <= handleWidth)
110
+ cell = edgeCell(view, event, 'left')
111
+ }
112
+
113
+ if (cell != pluginState.activeHandle) {
114
+ if (!lastColumnResizable && cell !== -1) {
115
+ const $cell = view.state.doc.resolve(cell)
116
+ const table = $cell.node(-1)
117
+ const map = TableMap.get(table)
118
+ const start = $cell.start(-1)
95
119
 
96
- if (cell != pluginState.activeHandle) {
97
- if (!lastColumnResizable && cell !== -1) {
98
- const $cell = view.state.doc.resolve(cell);
99
- const table = $cell.node(-1),
100
- map = TableMap.get(table),
101
- start = $cell.start(-1);
102
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
103
- const col = map.colCount($cell.pos - start) + $cell.nodeAfter!.attrs['colspan'] - 1;
120
+ const col = map.colCount($cell.pos - start) + $cell.nodeAfter!.attrs.colspan - 1
104
121
 
105
- if (col == map.width - 1) {
106
- return;
107
- }
108
- }
122
+ if (col == map.width - 1)
123
+ return
124
+ }
109
125
 
110
- updateHandle(view, cell);
111
- }
126
+ updateHandle(view, cell)
112
127
  }
128
+ }
113
129
  }
114
130
 
115
131
  function handleMouseLeave(view: EditorView) {
116
- const pluginState = key.getState(view.state);
117
- if (pluginState.activeHandle > -1 && !pluginState.dragging) updateHandle(view, -1);
132
+ const pluginState = key.getState(view.state)
133
+ if (pluginState.activeHandle > -1 && !pluginState.dragging)
134
+ updateHandle(view, -1)
118
135
  }
119
136
 
120
137
  function handleMouseDown(view: EditorView, event: MouseEvent, cellMinWidth: number) {
121
- const pluginState = key.getState(view.state);
122
- if (pluginState.activeHandle == -1 || pluginState.dragging) return false;
138
+ const pluginState = key.getState(view.state)
139
+ if (pluginState.activeHandle == -1 || pluginState.dragging)
140
+ return false
123
141
 
124
- const cell = view.state.doc.nodeAt(pluginState.activeHandle) as Node;
125
- const width = currentColWidth(view, pluginState.activeHandle, cell.attrs);
126
- view.dispatch(
127
- view.state.tr.setMeta(key, {
128
- setDragging: { startX: event.clientX, startWidth: width },
129
- }),
130
- );
142
+ const cell = view.state.doc.nodeAt(pluginState.activeHandle) as Node
143
+ const width = currentColWidth(view, pluginState.activeHandle, cell.attrs)
144
+ view.dispatch(
145
+ view.state.tr.setMeta(key, {
146
+ setDragging: { startX: event.clientX, startWidth: width },
147
+ }),
148
+ )
131
149
 
132
- function finish(event: MouseEvent) {
133
- window.removeEventListener('mouseup', finish);
134
- window.removeEventListener('mousemove', move);
135
- const pluginState = key.getState(view.state);
136
- if (pluginState.dragging) {
137
- updateColumnWidth(view, pluginState.activeHandle, draggedWidth(pluginState.dragging, event, cellMinWidth));
138
- view.dispatch(view.state.tr.setMeta(key, { setDragging: null }));
139
- }
140
- }
141
- function move(event: MouseEvent) {
142
- if (!event.which) return finish(event);
143
- const pluginState = key.getState(view.state);
144
- const dragged = draggedWidth(pluginState.dragging, event, cellMinWidth);
145
- displayColumnWidth(view, pluginState.activeHandle, dragged, cellMinWidth);
150
+ function finish(event: MouseEvent) {
151
+ window.removeEventListener('mouseup', finish)
152
+ window.removeEventListener('mousemove', move)
153
+ const pluginState = key.getState(view.state)
154
+ if (pluginState.dragging) {
155
+ updateColumnWidth(view, pluginState.activeHandle, draggedWidth(pluginState.dragging, event, cellMinWidth))
156
+ view.dispatch(view.state.tr.setMeta(key, { setDragging: null }))
146
157
  }
158
+ }
159
+ function move(event: MouseEvent) {
160
+ if (!event.which)
161
+ return finish(event)
162
+ const pluginState = key.getState(view.state)
163
+ const dragged = draggedWidth(pluginState.dragging, event, cellMinWidth)
164
+ displayColumnWidth(view, pluginState.activeHandle, dragged, cellMinWidth)
165
+ }
147
166
 
148
- window.addEventListener('mouseup', finish);
149
- window.addEventListener('mousemove', move);
150
- event.preventDefault();
151
- return true;
167
+ window.addEventListener('mouseup', finish)
168
+ window.addEventListener('mousemove', move)
169
+ event.preventDefault()
170
+ return true
152
171
  }
153
172
 
154
173
  function currentColWidth(view: EditorView, cellPos: number, { colspan, colwidth }: Attrs) {
155
- const width = colwidth && colwidth[colwidth.length - 1];
156
- if (width) return width;
157
- const dom = view.domAtPos(cellPos);
158
- const node = dom.node.childNodes[dom.offset] as HTMLElement;
159
- let domWidth = node.offsetWidth,
160
- parts = colspan;
161
- if (colwidth)
162
- for (let i = 0; i < colspan; i++)
163
- if (colwidth[i]) {
164
- domWidth -= colwidth[i];
165
- parts--;
166
- }
167
- return domWidth / parts;
174
+ const width = colwidth && colwidth[colwidth.length - 1]
175
+ if (width)
176
+ return width
177
+ const dom = view.domAtPos(cellPos)
178
+ const node = dom.node.childNodes[dom.offset] as HTMLElement
179
+ let domWidth = node.offsetWidth
180
+ let parts = colspan
181
+ if (colwidth) {
182
+ for (let i = 0; i < colspan; i++) {
183
+ if (colwidth[i]) {
184
+ domWidth -= colwidth[i]
185
+ parts--
186
+ }
187
+ }
188
+ }
189
+ return domWidth / parts
168
190
  }
169
191
 
170
192
  function domCellAround(target: Element | null) {
171
- while (target && target.nodeName != 'TD' && target.nodeName != 'TH')
172
- target = target.classList.contains('ProseMirror') ? null : (target.parentNode as Element);
173
- return target;
193
+ while (target && target.nodeName != 'TD' && target.nodeName != 'TH')
194
+ target = target.classList.contains('ProseMirror') ? null : (target.parentNode as Element)
195
+ return target
174
196
  }
175
197
 
176
198
  function edgeCell(view: EditorView, event: MouseEvent, side: 'left' | 'right') {
177
- const found = view.posAtCoords({ left: event.clientX, top: event.clientY });
178
- if (!found) return -1;
179
- const { pos } = found;
180
- const $cell = cellAround(view.state.doc.resolve(pos));
181
- if (!$cell) return -1;
182
- if (side == 'right') return $cell.pos;
183
- const map = TableMap.get($cell.node(-1)),
184
- start = $cell.start(-1);
185
- const index = map.map.indexOf($cell.pos - start);
186
- return index % map.width == 0 ? -1 : start + (map.map[index - 1] as number);
199
+ const found = view.posAtCoords({ left: event.clientX, top: event.clientY })
200
+ if (!found)
201
+ return -1
202
+ const { pos } = found
203
+ const $cell = cellAround(view.state.doc.resolve(pos))
204
+ if (!$cell)
205
+ return -1
206
+ if (side == 'right')
207
+ return $cell.pos
208
+ const map = TableMap.get($cell.node(-1))
209
+ const start = $cell.start(-1)
210
+ const index = map.map.indexOf($cell.pos - start)
211
+ return index % map.width == 0 ? -1 : start + (map.map[index - 1] as number)
187
212
  }
188
213
 
189
214
  function draggedWidth(dragging: { startX: number; startWidth: number }, event: MouseEvent, cellMinWidth: number) {
190
- const offset = event.clientX - dragging.startX;
191
- return Math.max(cellMinWidth, dragging.startWidth + offset);
215
+ const offset = event.clientX - dragging.startX
216
+ return Math.max(cellMinWidth, dragging.startWidth + offset)
192
217
  }
193
218
 
194
219
  function updateHandle(view: EditorView, value: number) {
195
- view.dispatch(view.state.tr.setMeta(key, { setHandle: value }));
220
+ view.dispatch(view.state.tr.setMeta(key, { setHandle: value }))
196
221
  }
197
222
 
198
223
  function updateColumnWidth(view: EditorView, cell: number, width: number) {
199
- const $cell = view.state.doc.resolve(cell);
200
- const table = $cell.node(-1),
201
- map = TableMap.get(table),
202
- start = $cell.start(-1);
203
- const col = map.colCount($cell.pos - start) + ($cell.nodeAfter as Node).attrs['colspan'] - 1;
204
- const tr = view.state.tr;
205
- for (let row = 0; row < map.height; row++) {
206
- const mapIndex = row * map.width + col;
207
- // Rowspanning cell that has already been handled
208
- if (row && map.map[mapIndex] == map.map[mapIndex - map.width]) continue;
209
- const pos = map.map[mapIndex] as number,
210
- { attrs } = table.nodeAt(pos) as Node;
211
- const index = attrs['colspan'] == 1 ? 0 : col - map.colCount(pos);
212
- if (attrs['colwidth'] && attrs['colwidth'][index] == width) continue;
213
- const colwidth = attrs['colwidth'] ? attrs['colwidth'].slice() : zeroes(attrs['colspan']);
214
- colwidth[index] = width;
215
- tr.setNodeMarkup(start + pos, null, setAttr(attrs, 'colwidth', colwidth));
216
- }
217
- if (tr.docChanged) view.dispatch(tr);
224
+ const $cell = view.state.doc.resolve(cell)
225
+ const table = $cell.node(-1)
226
+ const map = TableMap.get(table)
227
+ const start = $cell.start(-1)
228
+ const col = map.colCount($cell.pos - start) + ($cell.nodeAfter as Node).attrs.colspan - 1
229
+ const tr = view.state.tr
230
+ for (let row = 0; row < map.height; row++) {
231
+ const mapIndex = row * map.width + col
232
+ // Rowspanning cell that has already been handled
233
+ if (row && map.map[mapIndex] == map.map[mapIndex - map.width])
234
+ continue
235
+ const pos = map.map[mapIndex] as number
236
+ const { attrs } = table.nodeAt(pos) as Node
237
+ const index = attrs.colspan == 1 ? 0 : col - map.colCount(pos)
238
+ if (attrs.colwidth && attrs.colwidth[index] == width)
239
+ continue
240
+ const colwidth = attrs.colwidth ? attrs.colwidth.slice() : zeroes(attrs.colspan)
241
+ colwidth[index] = width
242
+ tr.setNodeMarkup(start + pos, null, setAttr(attrs, 'colwidth', colwidth))
243
+ }
244
+ if (tr.docChanged)
245
+ view.dispatch(tr)
218
246
  }
219
247
 
220
248
  function displayColumnWidth(view: EditorView, cell: number, width: number, cellMinWidth: number) {
221
- const $cell = view.state.doc.resolve(cell);
222
- const table = $cell.node(-1),
223
- start = $cell.start(-1);
224
- const col = TableMap.get(table).colCount($cell.pos - start) + ($cell.nodeAfter as Node).attrs['colspan'] - 1;
225
- let dom = view.domAtPos($cell.start(-1)).node as HTMLElement;
226
- while (dom.nodeName != 'TABLE') dom = dom.parentNode as HTMLElement;
227
- updateColumns(table, dom.firstChild as HTMLTableColElement, dom as HTMLTableElement, cellMinWidth, col, width);
249
+ const $cell = view.state.doc.resolve(cell)
250
+ const table = $cell.node(-1)
251
+ const start = $cell.start(-1)
252
+ const col = TableMap.get(table).colCount($cell.pos - start) + ($cell.nodeAfter as Node).attrs.colspan - 1
253
+ let dom = view.domAtPos($cell.start(-1)).node as HTMLElement
254
+ while (dom.nodeName != 'TABLE') dom = dom.parentNode as HTMLElement
255
+ updateColumns(table, dom.firstChild as HTMLTableColElement, dom as HTMLTableElement, cellMinWidth, col, width)
228
256
  }
229
257
 
230
258
  function zeroes(n: number) {
231
- const result = [];
232
- for (let i = 0; i < n; i++) result.push(0);
233
- return result;
259
+ const result = []
260
+ for (let i = 0; i < n; i++) result.push(0)
261
+ return result
234
262
  }
235
263
 
236
264
  function handleDecorations(state: EditorState, cell: number) {
237
- const decorations = [];
238
- const $cell = state.doc.resolve(cell);
239
- const table = $cell.node(-1),
240
- map = TableMap.get(table),
241
- start = $cell.start(-1);
242
- const col = map.colCount($cell.pos - start) + ($cell.nodeAfter as Node).attrs['colspan'];
243
- for (let row = 0; row < map.height; row++) {
244
- const index = col + row * map.width - 1;
245
- // For positions that are have either a different cell or the end
246
- // of the table to their right, and either the top of the table or
247
- // a different cell above them, add a decoration
248
- if (
249
- (col == map.width || map.map[index] != map.map[index + 1]) &&
250
- (row == 0 || map.map[index - 1] != map.map[index - 1 - map.width])
251
- ) {
252
- const cellPos = map.map[index] as number;
253
- const pos = start + cellPos + (table.nodeAt(cellPos) as Node).nodeSize - 1;
254
- const dom = document.createElement('div');
255
- dom.className = 'column-resize-handle';
256
- decorations.push(Decoration.widget(pos, dom));
257
- }
265
+ const decorations = []
266
+ const $cell = state.doc.resolve(cell)
267
+ const table = $cell.node(-1)
268
+ const map = TableMap.get(table)
269
+ const start = $cell.start(-1)
270
+ const col = map.colCount($cell.pos - start) + ($cell.nodeAfter as Node).attrs.colspan
271
+ for (let row = 0; row < map.height; row++) {
272
+ const index = col + row * map.width - 1
273
+ // For positions that are have either a different cell or the end
274
+ // of the table to their right, and either the top of the table or
275
+ // a different cell above them, add a decoration
276
+ if (
277
+ (col == map.width || map.map[index] != map.map[index + 1])
278
+ && (row == 0 || map.map[index - 1] != map.map[index - 1 - map.width])
279
+ ) {
280
+ const cellPos = map.map[index] as number
281
+ const pos = start + cellPos + (table.nodeAt(cellPos) as Node).nodeSize - 1
282
+ const dom = document.createElement('div')
283
+ dom.className = 'column-resize-handle'
284
+ decorations.push(Decoration.widget(pos, dom))
258
285
  }
259
- return DecorationSet.create(state.doc, decorations);
286
+ }
287
+ return DecorationSet.create(state.doc, decorations)
260
288
  }