@milkdown/preset-gfm 6.5.2 → 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.
- package/lib/footnote/definition.d.ts +1 -1
- package/lib/footnote/definition.d.ts.map +1 -1
- package/lib/footnote/index.d.ts.map +1 -1
- package/lib/footnote/reference.d.ts +1 -1
- package/lib/footnote/reference.d.ts.map +1 -1
- package/lib/footnote/utils.d.ts.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.es.js +649 -607
- package/lib/index.es.js.map +1 -1
- package/lib/strike-through.d.ts +1 -1
- package/lib/strike-through.d.ts.map +1 -1
- package/lib/supported-keys.d.ts +1 -1
- package/lib/supported-keys.d.ts.map +1 -1
- package/lib/table/command.d.ts +2 -2
- package/lib/table/command.d.ts.map +1 -1
- package/lib/table/index.d.ts +1 -1
- package/lib/table/index.d.ts.map +1 -1
- package/lib/table/nodes/index.d.ts +1 -1
- package/lib/table/nodes/index.d.ts.map +1 -1
- package/lib/table/operator-plugin/actions.d.ts +5 -5
- package/lib/table/operator-plugin/actions.d.ts.map +1 -1
- package/lib/table/operator-plugin/calc-pos.d.ts +1 -1
- package/lib/table/operator-plugin/calc-pos.d.ts.map +1 -1
- package/lib/table/operator-plugin/constant.d.ts.map +1 -1
- package/lib/table/operator-plugin/helper.d.ts +3 -3
- package/lib/table/operator-plugin/helper.d.ts.map +1 -1
- package/lib/table/operator-plugin/index.d.ts +2 -2
- package/lib/table/operator-plugin/index.d.ts.map +1 -1
- package/lib/table/operator-plugin/style.d.ts +1 -1
- package/lib/table/operator-plugin/style.d.ts.map +1 -1
- package/lib/table/operator-plugin/widget.d.ts +2 -2
- package/lib/table/operator-plugin/widget.d.ts.map +1 -1
- package/lib/table/plugin/auto-insert-zero-space.d.ts.map +1 -1
- package/lib/table/plugin/cell-selection.d.ts +5 -3
- package/lib/table/plugin/cell-selection.d.ts.map +1 -1
- package/lib/table/plugin/column-resizing.d.ts +2 -1
- package/lib/table/plugin/column-resizing.d.ts.map +1 -1
- package/lib/table/plugin/commands.d.ts +2 -2
- package/lib/table/plugin/commands.d.ts.map +1 -1
- package/lib/table/plugin/copy-paste.d.ts +6 -5
- package/lib/table/plugin/copy-paste.d.ts.map +1 -1
- package/lib/table/plugin/fix-tables.d.ts +3 -2
- package/lib/table/plugin/fix-tables.d.ts.map +1 -1
- package/lib/table/plugin/index.d.ts.map +1 -1
- package/lib/table/plugin/schema.d.ts +1 -1
- package/lib/table/plugin/schema.d.ts.map +1 -1
- package/lib/table/plugin/table-editing.d.ts +1 -1
- package/lib/table/plugin/table-editing.d.ts.map +1 -1
- package/lib/table/plugin/table-map.d.ts +2 -2
- package/lib/table/plugin/table-map.d.ts.map +1 -1
- package/lib/table/plugin/table-view.d.ts +2 -2
- package/lib/table/plugin/table-view.d.ts.map +1 -1
- package/lib/table/plugin/types.d.ts +2 -2
- package/lib/table/plugin/types.d.ts.map +1 -1
- package/lib/table/plugin/util.d.ts +2 -2
- package/lib/table/plugin/util.d.ts.map +1 -1
- package/lib/table/utils.d.ts +5 -5
- package/lib/table/utils.d.ts.map +1 -1
- package/lib/task-list-item.d.ts +2 -2
- package/lib/task-list-item.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/footnote/definition.ts +172 -166
- package/src/footnote/index.ts +2 -2
- package/src/footnote/reference.ts +166 -162
- package/src/footnote/utils.ts +2 -2
- package/src/index.ts +83 -83
- package/src/strike-through.ts +36 -36
- package/src/supported-keys.ts +9 -8
- package/src/table/command.ts +17 -16
- package/src/table/index.ts +9 -9
- package/src/table/nodes/index.ts +177 -174
- package/src/table/operator-plugin/actions.ts +103 -102
- package/src/table/operator-plugin/calc-pos.ts +31 -34
- package/src/table/operator-plugin/constant.ts +3 -3
- package/src/table/operator-plugin/helper.ts +31 -32
- package/src/table/operator-plugin/index.ts +104 -95
- package/src/table/operator-plugin/style.ts +10 -9
- package/src/table/operator-plugin/widget.ts +47 -45
- package/src/table/plugin/auto-insert-zero-space.ts +41 -41
- package/src/table/plugin/cell-selection.ts +325 -296
- package/src/table/plugin/column-resizing.ts +226 -198
- package/src/table/plugin/commands.ts +464 -421
- package/src/table/plugin/copy-paste.ts +256 -240
- package/src/table/plugin/fix-tables.ts +103 -88
- package/src/table/plugin/index.ts +3 -3
- package/src/table/plugin/schema.ts +100 -94
- package/src/table/plugin/table-editing.ts +324 -230
- package/src/table/plugin/table-map.ts +294 -229
- package/src/table/plugin/table-view.ts +66 -62
- package/src/table/plugin/types.ts +8 -8
- package/src/table/plugin/util.ts +78 -66
- package/src/table/utils.ts +141 -138
- 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,
|
|
4
|
-
import {
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
handleWidth = 5,
|
|
17
|
+
cellMinWidth = 25,
|
|
18
|
+
View = TableView,
|
|
19
|
+
lastColumnResizable = true,
|
|
18
20
|
} = {}) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
57
|
+
decorations(state) {
|
|
58
|
+
const pluginState = key.getState(state)
|
|
59
|
+
if (pluginState.activeHandle > -1)
|
|
60
|
+
return handleDecorations(state, pluginState.activeHandle)
|
|
53
61
|
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
return null
|
|
63
|
+
},
|
|
56
64
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
65
|
+
nodeViews: {},
|
|
66
|
+
},
|
|
67
|
+
})
|
|
68
|
+
return plugin
|
|
61
69
|
}
|
|
62
70
|
|
|
63
71
|
class ResizeState {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
72
|
+
constructor(public activeHandle: number, public dragging: null | boolean) {
|
|
73
|
+
this.activeHandle = activeHandle
|
|
74
|
+
this.dragging = dragging
|
|
75
|
+
}
|
|
68
76
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
96
|
+
const pluginState = key.getState(view.state)
|
|
86
97
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
122
|
+
if (col == map.width - 1)
|
|
123
|
+
return
|
|
124
|
+
}
|
|
109
125
|
|
|
110
|
-
|
|
111
|
-
}
|
|
126
|
+
updateHandle(view, cell)
|
|
112
127
|
}
|
|
128
|
+
}
|
|
113
129
|
}
|
|
114
130
|
|
|
115
131
|
function handleMouseLeave(view: EditorView) {
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
|
|
122
|
-
|
|
138
|
+
const pluginState = key.getState(view.state)
|
|
139
|
+
if (pluginState.activeHandle == -1 || pluginState.dragging)
|
|
140
|
+
return false
|
|
123
141
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
-
|
|
191
|
-
|
|
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
|
-
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
(row == 0 || map.map[index - 1] != map.map[index - 1 - map.width])
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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
|
-
|
|
286
|
+
}
|
|
287
|
+
return DecorationSet.create(state.doc, decorations)
|
|
260
288
|
}
|