@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,13 +1,15 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import type { Node, NodeType, Schema } from '@milkdown/prose/model'
|
|
4
|
+
import { Fragment, Slice } from '@milkdown/prose/model'
|
|
5
|
+
import type { EditorState, Transaction } from '@milkdown/prose/state'
|
|
6
|
+
import { Transform } from '@milkdown/prose/transform'
|
|
6
7
|
|
|
7
|
-
import { CellSelection } from './cell-selection'
|
|
8
|
-
import { tableNodeTypes } from './schema'
|
|
9
|
-
import { Rect
|
|
10
|
-
import {
|
|
8
|
+
import { CellSelection } from './cell-selection'
|
|
9
|
+
import { tableNodeTypes } from './schema'
|
|
10
|
+
import type { Rect } from './table-map'
|
|
11
|
+
import { TableMap } from './table-map'
|
|
12
|
+
import { removeColSpan, setAttr } from './util'
|
|
11
13
|
|
|
12
14
|
// Utilities to help with copying and pasting table cells
|
|
13
15
|
|
|
@@ -15,292 +17,306 @@ import { removeColSpan, setAttr } from './util';
|
|
|
15
17
|
// Get a rectangular area of cells from a slice, or null if the outer
|
|
16
18
|
// nodes of the slice aren't table cells or rows.
|
|
17
19
|
export function pastedCells(slice: Slice) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
if (!slice.size)
|
|
21
|
+
return null
|
|
22
|
+
let { content, openStart, openEnd } = slice
|
|
23
|
+
while (
|
|
24
|
+
content.childCount == 1
|
|
25
|
+
&& ((openStart > 0 && openEnd > 0) || (content.firstChild as Node).type.spec.tableRole == 'table')
|
|
26
|
+
) {
|
|
27
|
+
openStart--
|
|
28
|
+
openEnd--
|
|
29
|
+
content = (content.firstChild as Node).content
|
|
30
|
+
}
|
|
31
|
+
const first = content.firstChild as Node
|
|
32
|
+
const role = first.type.spec.tableRole
|
|
33
|
+
const schema = first.type.schema
|
|
34
|
+
const rows = []
|
|
35
|
+
if (role == 'row') {
|
|
36
|
+
for (let i = 0; i < content.childCount; i++) {
|
|
37
|
+
let cells = content.child(i).content
|
|
38
|
+
const left = i ? 0 : Math.max(0, openStart - 1)
|
|
39
|
+
const right = i < content.childCount - 1 ? 0 : Math.max(0, openEnd - 1)
|
|
40
|
+
if (left || right)
|
|
41
|
+
cells = fitSlice(tableNodeTypes(schema).row, new Slice(cells, left, right)).content
|
|
42
|
+
rows.push(cells)
|
|
27
43
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
} else if (role == 'cell' || role == 'header_cell') {
|
|
41
|
-
rows.push(
|
|
42
|
-
openStart || openEnd
|
|
43
|
-
? fitSlice(tableNodeTypes(schema).row, new Slice(content, openStart, openEnd)).content
|
|
44
|
-
: content,
|
|
45
|
-
);
|
|
46
|
-
} else {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
return ensureRectangular(schema, rows);
|
|
44
|
+
}
|
|
45
|
+
else if (role == 'cell' || role == 'header_cell') {
|
|
46
|
+
rows.push(
|
|
47
|
+
openStart || openEnd
|
|
48
|
+
? fitSlice(tableNodeTypes(schema).row, new Slice(content, openStart, openEnd)).content
|
|
49
|
+
: content,
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return null
|
|
54
|
+
}
|
|
55
|
+
return ensureRectangular(schema, rows)
|
|
50
56
|
}
|
|
51
57
|
|
|
52
58
|
// : (Schema, [Fragment]) → {width: number, height: number, rows: [Fragment]}
|
|
53
59
|
// Compute the width and height of a set of cells, and make sure each
|
|
54
60
|
// row has the same number of cells.
|
|
55
|
-
export
|
|
61
|
+
export interface R { width: number; height: number; rows: Fragment[] }
|
|
56
62
|
function ensureRectangular(schema: Schema, rows: Fragment[]): R {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
63
|
+
const widths: number[] = []
|
|
64
|
+
for (let i = 0; i < rows.length; i++) {
|
|
65
|
+
const row = rows[i] as Fragment
|
|
66
|
+
for (let j = row.childCount - 1; j >= 0; j--) {
|
|
67
|
+
const { rowspan, colspan } = row.child(j).attrs
|
|
68
|
+
for (let r = i; r < i + rowspan; r++) widths[r] = (widths[r] || 0) + colspan
|
|
64
69
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
}
|
|
71
|
+
let width = 0
|
|
72
|
+
for (let r = 0; r < widths.length; r++) width = Math.max(width, widths[r] as number)
|
|
73
|
+
for (let r = 0; r < widths.length; r++) {
|
|
74
|
+
if (r >= rows.length)
|
|
75
|
+
rows.push(Fragment.empty)
|
|
76
|
+
if ((widths[r] as number) < width) {
|
|
77
|
+
const empty = tableNodeTypes(schema).cell.createAndFill()
|
|
78
|
+
const cells = []
|
|
79
|
+
for (let i = widths[r] as number; i < width; i++) cells.push(empty)
|
|
80
|
+
rows[r] = (rows[r] as Fragment).append(Fragment.from(cells))
|
|
75
81
|
}
|
|
76
|
-
|
|
82
|
+
}
|
|
83
|
+
return { height: rows.length, width, rows }
|
|
77
84
|
}
|
|
78
85
|
|
|
79
86
|
export function fitSlice(nodeType: NodeType, slice: Slice) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
87
|
+
const node = nodeType.createAndFill() as Node
|
|
88
|
+
const tr = new Transform(node).replace(0, node.content.size, slice)
|
|
89
|
+
return tr.doc
|
|
83
90
|
}
|
|
84
91
|
|
|
85
92
|
// Clip or extend (repeat) the given set of cells to cover the given
|
|
86
93
|
// width and height. Will clip rowspan/colspan cells at the edges when
|
|
87
94
|
// they stick out.
|
|
88
95
|
export function clipCells({ width, height, rows }: R, newWidth: number, newHeight: number): R {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
cells.push(cell);
|
|
103
|
-
col += cell.attrs['colspan'];
|
|
104
|
-
for (let j = 1; j < cell.attrs['rowspan']; j++)
|
|
105
|
-
added[row + j] = (added[row + j] || 0) + cell.attrs['colspan'];
|
|
106
|
-
}
|
|
107
|
-
newRows.push(Fragment.from(cells));
|
|
96
|
+
if (width != newWidth) {
|
|
97
|
+
const added: number[] = []
|
|
98
|
+
const newRows: Fragment[] = []
|
|
99
|
+
for (let row = 0; row < rows.length; row++) {
|
|
100
|
+
const frag = rows[row] as Fragment
|
|
101
|
+
const cells = []
|
|
102
|
+
for (let col = added[row] || 0, i = 0; col < newWidth; i++) {
|
|
103
|
+
let cell = frag.child(i % frag.childCount)
|
|
104
|
+
if (col + cell.attrs.colspan > newWidth) {
|
|
105
|
+
cell = cell.type.create(
|
|
106
|
+
removeColSpan(cell.attrs, cell.attrs.colspan, col + cell.attrs.colspan - newWidth),
|
|
107
|
+
cell.content,
|
|
108
|
+
)
|
|
108
109
|
}
|
|
109
|
-
|
|
110
|
-
|
|
110
|
+
cells.push(cell)
|
|
111
|
+
col += cell.attrs.colspan
|
|
112
|
+
for (let j = 1; j < cell.attrs.rowspan; j++)
|
|
113
|
+
added[row + j] = (added[row + j] || 0) + cell.attrs.colspan
|
|
114
|
+
}
|
|
115
|
+
newRows.push(Fragment.from(cells))
|
|
111
116
|
}
|
|
117
|
+
rows = newRows
|
|
118
|
+
width = newWidth
|
|
119
|
+
}
|
|
112
120
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
cells.push(cell);
|
|
126
|
-
}
|
|
127
|
-
newRows.push(Fragment.from(cells));
|
|
121
|
+
if (height != newHeight) {
|
|
122
|
+
const newRows = []
|
|
123
|
+
for (let row = 0, i = 0; row < newHeight; row++, i++) {
|
|
124
|
+
const cells = []
|
|
125
|
+
const source = rows[i % height] as Fragment
|
|
126
|
+
for (let j = 0; j < source.childCount; j++) {
|
|
127
|
+
let cell = source.child(j)
|
|
128
|
+
if (row + cell.attrs.rowspan > newHeight) {
|
|
129
|
+
cell = cell.type.create(
|
|
130
|
+
setAttr(cell.attrs, 'rowspan', Math.max(1, newHeight - cell.attrs.rowspan)),
|
|
131
|
+
cell.content,
|
|
132
|
+
)
|
|
128
133
|
}
|
|
129
|
-
|
|
130
|
-
|
|
134
|
+
cells.push(cell)
|
|
135
|
+
}
|
|
136
|
+
newRows.push(Fragment.from(cells))
|
|
131
137
|
}
|
|
138
|
+
rows = newRows
|
|
139
|
+
height = newHeight
|
|
140
|
+
}
|
|
132
141
|
|
|
133
|
-
|
|
142
|
+
return { width, height, rows }
|
|
134
143
|
}
|
|
135
144
|
|
|
136
145
|
// Make sure a table has at least the given width and height. Return
|
|
137
146
|
// true if something was changed.
|
|
138
147
|
function growTable(
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
148
|
+
tr: Transaction,
|
|
149
|
+
map: TableMap,
|
|
150
|
+
table: Node,
|
|
151
|
+
start: number,
|
|
152
|
+
width: number,
|
|
153
|
+
height: number,
|
|
154
|
+
mapFrom: number,
|
|
146
155
|
) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
156
|
+
const schema = tr.doc.type.schema
|
|
157
|
+
const types = tableNodeTypes(schema)
|
|
158
|
+
let empty, emptyHead
|
|
159
|
+
if (width > map.width) {
|
|
160
|
+
for (let row = 0, rowEnd = 0; row < map.height; row++) {
|
|
161
|
+
const rowNode = table.child(row)
|
|
162
|
+
rowEnd += rowNode.nodeSize
|
|
163
|
+
const cells = []
|
|
164
|
+
let add
|
|
165
|
+
if (rowNode.lastChild == null || rowNode.lastChild.type == types.cell)
|
|
166
|
+
add = empty || (empty = types.cell.createAndFill())
|
|
167
|
+
else add = emptyHead || (emptyHead = types.header_cell.createAndFill())
|
|
168
|
+
for (let i = map.width; i < width; i++) cells.push(add)
|
|
169
|
+
tr.insert(tr.mapping.slice(mapFrom).map(rowEnd - 1 + start), cells)
|
|
162
170
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const emptyRow = types.row.create(null, Fragment.from(cells)),
|
|
176
|
-
rows = [];
|
|
177
|
-
for (let i = map.height; i < height; i++) rows.push(emptyRow);
|
|
178
|
-
tr.insert(tr.mapping.slice(mapFrom).map(start + table.nodeSize - 2), rows);
|
|
171
|
+
}
|
|
172
|
+
if (height > map.height) {
|
|
173
|
+
const cells = []
|
|
174
|
+
for (let i = 0, start = (map.height - 1) * map.width; i < Math.max(map.width, width); i++) {
|
|
175
|
+
const header
|
|
176
|
+
= i >= map.width ? false : (table.nodeAt(map.map[start + i] as number) as Node).type == types.header_cell
|
|
177
|
+
cells.push(
|
|
178
|
+
header
|
|
179
|
+
? emptyHead || (emptyHead = types.header_cell.createAndFill())
|
|
180
|
+
: empty || (empty = types.cell.createAndFill()),
|
|
181
|
+
)
|
|
179
182
|
}
|
|
180
|
-
|
|
183
|
+
|
|
184
|
+
const emptyRow = types.row.create(null, Fragment.from(cells))
|
|
185
|
+
const rows = []
|
|
186
|
+
for (let i = map.height; i < height; i++) rows.push(emptyRow)
|
|
187
|
+
tr.insert(tr.mapping.slice(mapFrom).map(start + table.nodeSize - 2), rows)
|
|
188
|
+
}
|
|
189
|
+
return !!(empty || emptyHead)
|
|
181
190
|
}
|
|
182
191
|
|
|
183
192
|
// Make sure the given line (left, top) to (right, top) doesn't cross
|
|
184
193
|
// any rowspan cells by splitting cells that cross it. Return true if
|
|
185
194
|
// something changed.
|
|
186
195
|
function isolateHorizontal(
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
196
|
+
tr: Transaction,
|
|
197
|
+
map: TableMap,
|
|
198
|
+
table: Node,
|
|
199
|
+
start: number,
|
|
200
|
+
left: number,
|
|
201
|
+
right: number,
|
|
202
|
+
top: number,
|
|
203
|
+
mapFrom: number,
|
|
195
204
|
) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
205
|
+
if (top == 0 || top == map.height)
|
|
206
|
+
return false
|
|
207
|
+
let found = false
|
|
208
|
+
for (let col = left; col < right; col++) {
|
|
209
|
+
const index = top * map.width + col
|
|
210
|
+
const pos = map.map[index] as number
|
|
211
|
+
if (map.map[index - map.width] == pos) {
|
|
212
|
+
found = true
|
|
213
|
+
const cell = table.nodeAt(pos) as Node
|
|
214
|
+
const { top: cellTop, left: cellLeft } = map.findCell(pos)
|
|
215
|
+
tr.setNodeMarkup(
|
|
216
|
+
tr.mapping.slice(mapFrom).map(pos + start),
|
|
217
|
+
null,
|
|
218
|
+
setAttr(cell.attrs, 'rowspan', top - cellTop),
|
|
219
|
+
)
|
|
220
|
+
tr.insert(
|
|
221
|
+
tr.mapping.slice(mapFrom).map(map.positionAt(top, cellLeft, table)),
|
|
222
|
+
cell.type.createAndFill(setAttr(cell.attrs, 'rowspan', cellTop + cell.attrs.rowspan - top)) as Node,
|
|
223
|
+
)
|
|
224
|
+
col += cell.attrs.colspan - 1
|
|
216
225
|
}
|
|
217
|
-
|
|
226
|
+
}
|
|
227
|
+
return found
|
|
218
228
|
}
|
|
219
229
|
|
|
220
230
|
// Make sure the given line (left, top) to (left, bottom) doesn't
|
|
221
231
|
// cross any colspan cells by splitting cells that cross it. Return
|
|
222
232
|
// true if something changed.
|
|
223
233
|
function isolateVertical(
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
234
|
+
tr: Transaction,
|
|
235
|
+
map: TableMap,
|
|
236
|
+
table: Node,
|
|
237
|
+
start: number,
|
|
238
|
+
top: number,
|
|
239
|
+
bottom: number,
|
|
240
|
+
left: number,
|
|
241
|
+
mapFrom: number,
|
|
232
242
|
) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
243
|
+
if (left == 0 || left == map.width)
|
|
244
|
+
return false
|
|
245
|
+
let found = false
|
|
246
|
+
for (let row = top; row < bottom; row++) {
|
|
247
|
+
const index = row * map.width + left
|
|
248
|
+
const pos = map.map[index] as number
|
|
249
|
+
if (map.map[index - 1] == pos) {
|
|
250
|
+
found = true
|
|
251
|
+
const cell = table.nodeAt(pos) as Node
|
|
252
|
+
const cellLeft = map.colCount(pos)
|
|
253
|
+
const updatePos = tr.mapping.slice(mapFrom).map(pos + start)
|
|
254
|
+
tr.setNodeMarkup(
|
|
255
|
+
updatePos,
|
|
256
|
+
null,
|
|
257
|
+
removeColSpan(cell.attrs, left - cellLeft, cell.attrs.colspan - (left - cellLeft)),
|
|
258
|
+
)
|
|
259
|
+
tr.insert(
|
|
260
|
+
updatePos + cell.nodeSize,
|
|
261
|
+
cell.type.createAndFill(removeColSpan(cell.attrs, 0, left - cellLeft)) as Node,
|
|
262
|
+
)
|
|
263
|
+
row += cell.attrs.rowspan - 1
|
|
254
264
|
}
|
|
255
|
-
|
|
265
|
+
}
|
|
266
|
+
return found
|
|
256
267
|
}
|
|
257
268
|
|
|
258
269
|
// Insert the given set of cells (as returned by `pastedCells`) into a
|
|
259
270
|
// table, at the position pointed at by rect.
|
|
260
271
|
export function insertCells(
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
272
|
+
state: EditorState,
|
|
273
|
+
dispatch: (tr: Transaction) => void,
|
|
274
|
+
tableStart: number,
|
|
275
|
+
rect: Rect,
|
|
276
|
+
cells: R,
|
|
266
277
|
) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
278
|
+
let table = (tableStart ? state.doc.nodeAt(tableStart - 1) : state.doc) as Node
|
|
279
|
+
let map = TableMap.get(table)
|
|
280
|
+
const { top, left } = rect
|
|
281
|
+
const right = left + cells.width
|
|
282
|
+
const bottom = top + cells.height
|
|
283
|
+
const tr = state.tr
|
|
284
|
+
let mapFrom = 0
|
|
285
|
+
function recomp() {
|
|
286
|
+
table = (tableStart ? tr.doc.nodeAt(tableStart - 1) : tr.doc) as Node
|
|
287
|
+
map = TableMap.get(table)
|
|
288
|
+
mapFrom = tr.mapping.maps.length
|
|
289
|
+
}
|
|
290
|
+
// Prepare the table to be large enough and not have any cells
|
|
291
|
+
// crossing the boundaries of the rectangle that we want to
|
|
292
|
+
// insert into. If anything about it changes, recompute the table
|
|
293
|
+
// map so that subsequent operations can see the current shape.
|
|
294
|
+
if (growTable(tr, map, table, tableStart, right, bottom, mapFrom))
|
|
295
|
+
recomp()
|
|
296
|
+
if (isolateHorizontal(tr, map, table, tableStart, left, right, top, mapFrom))
|
|
297
|
+
recomp()
|
|
298
|
+
if (isolateHorizontal(tr, map, table, tableStart, left, right, bottom, mapFrom))
|
|
299
|
+
recomp()
|
|
300
|
+
if (isolateVertical(tr, map, table, tableStart, top, bottom, left, mapFrom))
|
|
301
|
+
recomp()
|
|
302
|
+
if (isolateVertical(tr, map, table, tableStart, top, bottom, right, mapFrom))
|
|
303
|
+
recomp()
|
|
288
304
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
305
|
+
for (let row = top; row < bottom; row++) {
|
|
306
|
+
const from = map.positionAt(row, left, table)
|
|
307
|
+
const to = map.positionAt(row, right, table)
|
|
308
|
+
tr.replace(
|
|
309
|
+
tr.mapping.slice(mapFrom).map(from + tableStart),
|
|
310
|
+
tr.mapping.slice(mapFrom).map(to + tableStart),
|
|
311
|
+
new Slice(cells.rows[row - top] as Fragment, 0, 0),
|
|
312
|
+
)
|
|
313
|
+
}
|
|
314
|
+
recomp()
|
|
315
|
+
tr.setSelection(
|
|
316
|
+
new CellSelection(
|
|
317
|
+
tr.doc.resolve(tableStart + map.positionAt(top, left, table)),
|
|
318
|
+
tr.doc.resolve(tableStart + map.positionAt(bottom - 1, right - 1, table)),
|
|
319
|
+
),
|
|
320
|
+
)
|
|
321
|
+
dispatch(tr)
|
|
306
322
|
}
|