@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.
- 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 +22 -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,275 +1,369 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { keydownHandler } from '@milkdown/prose/keymap';
|
|
3
|
-
import { Fragment, ResolvedPos, Slice } from '@milkdown/prose/model';
|
|
4
|
-
import { Command, EditorState, Plugin, PluginKey, Selection, TextSelection, Transaction } from '@milkdown/prose/state';
|
|
5
|
-
import { EditorView } from '@milkdown/prose/view';
|
|
6
2
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
3
|
+
import { keydownHandler } from '@milkdown/prose/keymap'
|
|
4
|
+
import type { ResolvedPos } from '@milkdown/prose/model'
|
|
5
|
+
import { Fragment, Slice } from '@milkdown/prose/model'
|
|
6
|
+
import type { Command, EditorState, Transaction } from '@milkdown/prose/state'
|
|
7
|
+
import {
|
|
8
|
+
Plugin,
|
|
9
|
+
PluginKey,
|
|
10
|
+
Selection,
|
|
11
|
+
TextSelection,
|
|
12
|
+
} from '@milkdown/prose/state'
|
|
13
|
+
import type { EditorView } from '@milkdown/prose/view'
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
import {
|
|
16
|
+
CellSelection,
|
|
17
|
+
drawCellSelection,
|
|
18
|
+
normalizeSelection,
|
|
19
|
+
} from './cell-selection'
|
|
20
|
+
import { clipCells, fitSlice, insertCells, pastedCells } from './copy-paste'
|
|
21
|
+
import { fixTables } from './fix-tables'
|
|
22
|
+
import { tableNodeTypes } from './schema'
|
|
23
|
+
import { TableMap } from './table-map'
|
|
24
|
+
import {
|
|
25
|
+
cellAround,
|
|
26
|
+
inSameTable,
|
|
27
|
+
isInTable,
|
|
28
|
+
nextCell,
|
|
29
|
+
selectionCell,
|
|
30
|
+
} from './util'
|
|
31
|
+
|
|
32
|
+
export const tableEditingKey = new PluginKey('selectingCells')
|
|
15
33
|
|
|
16
34
|
function domInCell(view: EditorView, dom: EventTarget | null) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
35
|
+
for (; dom && dom != view.dom; dom = (dom as Element).parentNode as Element) {
|
|
36
|
+
if ((dom as Element).nodeName == 'TD' || (dom as Element).nodeName == 'TH')
|
|
37
|
+
return dom
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return undefined
|
|
20
41
|
}
|
|
21
42
|
|
|
22
43
|
function cellUnderMouse(view: EditorView, event: MouseEvent) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
44
|
+
const mousePos = view.posAtCoords({
|
|
45
|
+
left: event.clientX,
|
|
46
|
+
top: event.clientY,
|
|
47
|
+
})
|
|
48
|
+
if (!mousePos)
|
|
49
|
+
return null
|
|
50
|
+
return mousePos ? cellAround(view.state.doc.resolve(mousePos.pos)) : null
|
|
26
51
|
}
|
|
27
52
|
|
|
28
53
|
function handleMouseDown(view: EditorView, event: Event) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const startDOMCell = domInCell(view, startEvent.target as Element);
|
|
33
|
-
let $anchor;
|
|
34
|
-
if (startEvent.shiftKey && view.state.selection instanceof CellSelection) {
|
|
35
|
-
// Adding to an existing cell selection
|
|
36
|
-
setCellSelection(view.state.selection.$anchorCell, startEvent);
|
|
37
|
-
startEvent.preventDefault();
|
|
38
|
-
} else if (
|
|
39
|
-
startEvent.shiftKey &&
|
|
40
|
-
startDOMCell &&
|
|
41
|
-
($anchor = cellAround(view.state.selection.$anchor)) != null &&
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
43
|
-
cellUnderMouse(view, startEvent)!.pos != $anchor.pos
|
|
44
|
-
) {
|
|
45
|
-
// Adding to a selection that starts in another cell (causing a
|
|
46
|
-
// cell selection to be created).
|
|
47
|
-
setCellSelection($anchor, startEvent);
|
|
48
|
-
startEvent.preventDefault();
|
|
49
|
-
} else if (!startDOMCell) {
|
|
50
|
-
// Not in a cell, let the default behavior happen.
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
54
|
+
const startEvent = event as MouseEvent
|
|
55
|
+
if (startEvent.ctrlKey || startEvent.metaKey)
|
|
56
|
+
return
|
|
53
57
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
58
|
+
const startDOMCell = domInCell(view, startEvent.target as Element)
|
|
59
|
+
let $anchor
|
|
60
|
+
if (startEvent.shiftKey && view.state.selection instanceof CellSelection) {
|
|
61
|
+
// Adding to an existing cell selection
|
|
62
|
+
setCellSelection(view.state.selection.$anchorCell, startEvent)
|
|
63
|
+
startEvent.preventDefault()
|
|
64
|
+
}
|
|
65
|
+
else if (
|
|
66
|
+
startEvent.shiftKey
|
|
67
|
+
&& startDOMCell
|
|
68
|
+
// eslint-disable-next-line no-cond-assign
|
|
69
|
+
&& ($anchor = cellAround(view.state.selection.$anchor)) != null
|
|
70
|
+
&& cellUnderMouse(view, startEvent)!.pos != $anchor.pos
|
|
71
|
+
) {
|
|
72
|
+
// Adding to a selection that starts in another cell (causing a
|
|
73
|
+
// cell selection to be created).
|
|
74
|
+
setCellSelection($anchor, startEvent)
|
|
75
|
+
startEvent.preventDefault()
|
|
76
|
+
}
|
|
77
|
+
else if (!startDOMCell) {
|
|
78
|
+
// Not in a cell, let the default behavior happen.
|
|
79
|
+
return
|
|
80
|
+
}
|
|
70
81
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
82
|
+
// Create and dispatch a cell selection between the given anchor and
|
|
83
|
+
// the position under the mouse.
|
|
84
|
+
function setCellSelection($anchor: ResolvedPos, event: MouseEvent) {
|
|
85
|
+
let $head = cellUnderMouse(view, event)
|
|
86
|
+
const starting = tableEditingKey.getState(view.state) == null
|
|
87
|
+
if (!$head || !inSameTable($anchor, $head)) {
|
|
88
|
+
if (starting)
|
|
89
|
+
$head = $anchor
|
|
90
|
+
else return
|
|
91
|
+
}
|
|
92
|
+
const selection = new CellSelection($anchor, $head)
|
|
93
|
+
if (starting || !view.state.selection.eq(selection)) {
|
|
94
|
+
const tr = view.state.tr.setSelection(selection)
|
|
95
|
+
if (starting)
|
|
96
|
+
tr.setMeta(tableEditingKey, $anchor.pos)
|
|
97
|
+
view.dispatch(tr)
|
|
77
98
|
}
|
|
99
|
+
}
|
|
78
100
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
101
|
+
// Stop listening to mouse motion events.
|
|
102
|
+
function stop() {
|
|
103
|
+
view.root.removeEventListener('mouseup', stop)
|
|
104
|
+
view.root.removeEventListener('dragstart', stop)
|
|
105
|
+
view.root.removeEventListener('mousemove', move)
|
|
106
|
+
if (tableEditingKey.getState(view.state) != null)
|
|
107
|
+
view.dispatch(view.state.tr.setMeta(tableEditingKey, -1))
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function move(event: Event) {
|
|
111
|
+
const anchor = tableEditingKey.getState(view.state)
|
|
112
|
+
let $anchor
|
|
113
|
+
if (anchor != null) {
|
|
114
|
+
// Continuing an existing cross-cell selection
|
|
115
|
+
$anchor = view.state.doc.resolve(anchor)
|
|
116
|
+
}
|
|
117
|
+
else if (domInCell(view, event.target) != startDOMCell) {
|
|
118
|
+
// Moving out of the initial cell -- start a new cell selection
|
|
119
|
+
$anchor = cellUnderMouse(view, startEvent)
|
|
120
|
+
if (!$anchor)
|
|
121
|
+
return stop()
|
|
91
122
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
123
|
+
if ($anchor)
|
|
124
|
+
setCellSelection($anchor, event as MouseEvent)
|
|
125
|
+
}
|
|
126
|
+
view.root.addEventListener('mouseup', stop)
|
|
127
|
+
view.root.addEventListener('dragstart', stop)
|
|
128
|
+
view.root.addEventListener('mousemove', move)
|
|
95
129
|
}
|
|
96
130
|
|
|
97
131
|
function handleTripleClick(view: EditorView, pos: number) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
132
|
+
const doc = view.state.doc
|
|
133
|
+
const $cell = cellAround(doc.resolve(pos))
|
|
134
|
+
if (!$cell)
|
|
135
|
+
return false
|
|
136
|
+
view.dispatch(view.state.tr.setSelection(new CellSelection($cell)))
|
|
137
|
+
return true
|
|
103
138
|
}
|
|
104
139
|
|
|
105
140
|
function maybeSetSelection(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
141
|
+
state: EditorState,
|
|
142
|
+
dispatch: undefined | ((tr: Transaction) => void),
|
|
143
|
+
selection: Selection,
|
|
109
144
|
) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
145
|
+
if (selection.eq(state.selection))
|
|
146
|
+
return false
|
|
147
|
+
if (dispatch)
|
|
148
|
+
dispatch(state.tr.setSelection(selection).scrollIntoView())
|
|
149
|
+
return true
|
|
113
150
|
}
|
|
114
151
|
|
|
115
152
|
function atEndOfCell(view: EditorView, axis: string, dir: number) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
153
|
+
if (!(view.state.selection instanceof TextSelection))
|
|
154
|
+
return null
|
|
155
|
+
const { $head } = view.state.selection
|
|
156
|
+
for (let d = $head.depth - 1; d >= 0; d--) {
|
|
157
|
+
const parent = $head.node(d)
|
|
158
|
+
const index = dir < 0 ? $head.index(d) : $head.indexAfter(d)
|
|
159
|
+
if (index != (dir < 0 ? 0 : parent.childCount))
|
|
160
|
+
return null
|
|
161
|
+
if (
|
|
162
|
+
parent.type.spec.tableRole == 'cell'
|
|
163
|
+
|| parent.type.spec.tableRole == 'header_cell'
|
|
164
|
+
) {
|
|
165
|
+
const cellPos = $head.before(d)
|
|
166
|
+
const dirStr
|
|
167
|
+
= axis == 'vert' ? (dir > 0 ? 'down' : 'up') : dir > 0 ? 'right' : 'left'
|
|
168
|
+
return view.endOfTextblock(dirStr) ? cellPos : null
|
|
127
169
|
}
|
|
128
|
-
|
|
170
|
+
}
|
|
171
|
+
return null
|
|
129
172
|
}
|
|
130
173
|
|
|
131
174
|
function arrow(axis: string, dir: number): Command {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
175
|
+
return (state, dispatch, view) => {
|
|
176
|
+
const sel = state.selection
|
|
177
|
+
if (sel instanceof CellSelection) {
|
|
178
|
+
return maybeSetSelection(
|
|
179
|
+
state,
|
|
180
|
+
dispatch,
|
|
181
|
+
Selection.near(sel.$headCell, dir),
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (axis != 'horiz' && !sel.empty)
|
|
186
|
+
return false
|
|
187
|
+
const end = atEndOfCell(view as EditorView, axis, dir)
|
|
188
|
+
if (end == null)
|
|
189
|
+
return false
|
|
190
|
+
if (axis == 'horiz') {
|
|
191
|
+
return maybeSetSelection(
|
|
192
|
+
state,
|
|
193
|
+
dispatch,
|
|
194
|
+
Selection.near(state.doc.resolve(sel.head + dir), dir),
|
|
195
|
+
)
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
const $cell = state.doc.resolve(end)
|
|
199
|
+
const $next = nextCell($cell, axis, dir)
|
|
200
|
+
let newSel
|
|
201
|
+
if ($next)
|
|
202
|
+
newSel = Selection.near($next, 1)
|
|
203
|
+
else if (dir < 0)
|
|
204
|
+
newSel = Selection.near(state.doc.resolve($cell.before(-1)), -1)
|
|
205
|
+
else newSel = Selection.near(state.doc.resolve($cell.after(-1)), 1)
|
|
206
|
+
return maybeSetSelection(state, dispatch, newSel)
|
|
207
|
+
}
|
|
208
|
+
}
|
|
152
209
|
}
|
|
153
210
|
|
|
154
211
|
function shiftArrow(axis: string, dir: number): Command {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
212
|
+
return (state, dispatch, view) => {
|
|
213
|
+
let sel = state.selection
|
|
214
|
+
if (!(sel instanceof CellSelection)) {
|
|
215
|
+
const end = atEndOfCell(view as EditorView, axis, dir)
|
|
216
|
+
if (end == null)
|
|
217
|
+
return false
|
|
218
|
+
sel = new CellSelection(state.doc.resolve(end))
|
|
219
|
+
}
|
|
220
|
+
const $head = nextCell((sel as CellSelection).$headCell, axis, dir)
|
|
221
|
+
if (!$head)
|
|
222
|
+
return false
|
|
223
|
+
return maybeSetSelection(
|
|
224
|
+
state,
|
|
225
|
+
dispatch,
|
|
226
|
+
new CellSelection((sel as CellSelection).$anchorCell, $head),
|
|
227
|
+
)
|
|
228
|
+
}
|
|
166
229
|
}
|
|
167
230
|
|
|
168
|
-
function deleteCellSelection(
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
231
|
+
function deleteCellSelection(
|
|
232
|
+
state: EditorState,
|
|
233
|
+
dispatch?: (tr: Transaction) => void,
|
|
234
|
+
) {
|
|
235
|
+
const sel = state.selection
|
|
236
|
+
if (!(sel instanceof CellSelection))
|
|
237
|
+
return false
|
|
238
|
+
if (dispatch) {
|
|
239
|
+
const tr = state.tr
|
|
240
|
+
const baseContent = tableNodeTypes(state.schema).cell.createAndFill()
|
|
241
|
+
.content
|
|
242
|
+
sel.forEachCell((cell, pos) => {
|
|
243
|
+
if (!cell.content.eq(baseContent)) {
|
|
244
|
+
tr.replace(
|
|
245
|
+
tr.mapping.map(pos + 1),
|
|
246
|
+
tr.mapping.map(pos + cell.nodeSize - 1),
|
|
247
|
+
new Slice(baseContent, 0, 0),
|
|
248
|
+
)
|
|
249
|
+
}
|
|
250
|
+
})
|
|
251
|
+
if (tr.docChanged)
|
|
252
|
+
dispatch(tr)
|
|
253
|
+
}
|
|
254
|
+
return true
|
|
185
255
|
}
|
|
186
256
|
|
|
187
257
|
const handleKeyDown = keydownHandler({
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
})
|
|
258
|
+
'ArrowLeft': arrow('horiz', -1),
|
|
259
|
+
'ArrowRight': arrow('horiz', 1),
|
|
260
|
+
'ArrowUp': arrow('vert', -1),
|
|
261
|
+
'ArrowDown': arrow('vert', 1),
|
|
262
|
+
|
|
263
|
+
'Shift-ArrowLeft': shiftArrow('horiz', -1),
|
|
264
|
+
'Shift-ArrowRight': shiftArrow('horiz', 1),
|
|
265
|
+
'Shift-ArrowUp': shiftArrow('vert', -1),
|
|
266
|
+
'Shift-ArrowDown': shiftArrow('vert', 1),
|
|
267
|
+
|
|
268
|
+
'Backspace': deleteCellSelection,
|
|
269
|
+
'Mod-Backspace': deleteCellSelection,
|
|
270
|
+
'Delete': deleteCellSelection,
|
|
271
|
+
'Mod-Delete': deleteCellSelection,
|
|
272
|
+
})
|
|
203
273
|
|
|
204
274
|
export function handlePaste(view: EditorView, _: Event, slice: Slice) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
return true;
|
|
221
|
-
} else if (cells) {
|
|
222
|
-
const $cell = selectionCell(view.state) as ResolvedPos,
|
|
223
|
-
start = $cell.start(-1);
|
|
224
|
-
insertCells(view.state, view.dispatch, start, TableMap.get($cell.node(-1)).findCell($cell.pos - start), cells);
|
|
225
|
-
return true;
|
|
226
|
-
} else {
|
|
227
|
-
return false;
|
|
275
|
+
if (!isInTable(view.state))
|
|
276
|
+
return false
|
|
277
|
+
let cells = pastedCells(slice)
|
|
278
|
+
const sel = view.state.selection
|
|
279
|
+
if (sel instanceof CellSelection) {
|
|
280
|
+
if (!cells) {
|
|
281
|
+
cells = {
|
|
282
|
+
width: 1,
|
|
283
|
+
height: 1,
|
|
284
|
+
rows: [
|
|
285
|
+
Fragment.from(
|
|
286
|
+
fitSlice(tableNodeTypes(view.state.schema).cell, slice),
|
|
287
|
+
),
|
|
288
|
+
],
|
|
289
|
+
}
|
|
228
290
|
}
|
|
291
|
+
const table = sel.$anchorCell.node(-1)
|
|
292
|
+
const start = sel.$anchorCell.start(-1)
|
|
293
|
+
const rect = TableMap.get(table).rectBetween(
|
|
294
|
+
sel.$anchorCell.pos - start,
|
|
295
|
+
sel.$headCell.pos - start,
|
|
296
|
+
)
|
|
297
|
+
cells = clipCells(cells, rect.right - rect.left, rect.bottom - rect.top)
|
|
298
|
+
insertCells(view.state, view.dispatch, start, rect, cells)
|
|
299
|
+
return true
|
|
300
|
+
}
|
|
301
|
+
else if (cells) {
|
|
302
|
+
const $cell = selectionCell(view.state) as ResolvedPos
|
|
303
|
+
const start = $cell.start(-1)
|
|
304
|
+
insertCells(
|
|
305
|
+
view.state,
|
|
306
|
+
view.dispatch,
|
|
307
|
+
start,
|
|
308
|
+
TableMap.get($cell.node(-1)).findCell($cell.pos - start),
|
|
309
|
+
cells,
|
|
310
|
+
)
|
|
311
|
+
return true
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
return false
|
|
315
|
+
}
|
|
229
316
|
}
|
|
230
317
|
|
|
231
318
|
export function tableEditing({ allowTableNodeSelection = false } = {}) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
319
|
+
return new Plugin({
|
|
320
|
+
key: tableEditingKey,
|
|
321
|
+
|
|
322
|
+
// This piece of state is used to remember when a mouse-drag
|
|
323
|
+
// cell-selection is happening, so that it can continue even as
|
|
324
|
+
// transactions (which might move its anchor cell) come in.
|
|
325
|
+
state: {
|
|
326
|
+
init() {
|
|
327
|
+
return null
|
|
328
|
+
},
|
|
329
|
+
apply(tr, cur) {
|
|
330
|
+
const set = tr.getMeta(tableEditingKey)
|
|
331
|
+
if (set != null)
|
|
332
|
+
return set == -1 ? null : set
|
|
333
|
+
if (cur == null || !tr.docChanged)
|
|
334
|
+
return cur
|
|
335
|
+
const { deleted, pos } = tr.mapping.mapResult(cur)
|
|
336
|
+
return deleted ? null : pos
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
|
|
340
|
+
props: {
|
|
341
|
+
decorations: drawCellSelection,
|
|
342
|
+
|
|
343
|
+
handleDOMEvents: {
|
|
344
|
+
mousedown: handleMouseDown,
|
|
345
|
+
},
|
|
346
|
+
|
|
347
|
+
createSelectionBetween(view) {
|
|
348
|
+
if (tableEditingKey.getState(view.state) != null)
|
|
349
|
+
return view.state.selection
|
|
350
|
+
|
|
351
|
+
return null
|
|
352
|
+
},
|
|
353
|
+
|
|
354
|
+
handleTripleClick,
|
|
355
|
+
|
|
356
|
+
handleKeyDown,
|
|
357
|
+
|
|
358
|
+
handlePaste,
|
|
359
|
+
},
|
|
360
|
+
|
|
361
|
+
appendTransaction(_, oldState, state) {
|
|
362
|
+
return normalizeSelection(
|
|
363
|
+
state,
|
|
364
|
+
fixTables(state, oldState),
|
|
365
|
+
allowTableNodeSelection,
|
|
366
|
+
)
|
|
367
|
+
},
|
|
368
|
+
})
|
|
275
369
|
}
|