@kerebron/extension-tables 0.0.1
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/LICENSE +23 -0
- package/README.md +34 -0
- package/assets/tables.css +48 -0
- package/esm/ExtensionTables.d.ts +10 -0
- package/esm/ExtensionTables.d.ts.map +1 -0
- package/esm/ExtensionTables.js +27 -0
- package/esm/NodeTable.d.ts +24 -0
- package/esm/NodeTable.d.ts.map +1 -0
- package/esm/NodeTable.js +115 -0
- package/esm/NodeTableCell.d.ts +16 -0
- package/esm/NodeTableCell.d.ts.map +1 -0
- package/esm/NodeTableCell.js +77 -0
- package/esm/NodeTableHeader.d.ts +16 -0
- package/esm/NodeTableHeader.d.ts.map +1 -0
- package/esm/NodeTableHeader.js +75 -0
- package/esm/NodeTableRow.d.ts +16 -0
- package/esm/NodeTableRow.d.ts.map +1 -0
- package/esm/NodeTableRow.js +47 -0
- package/esm/_dnt.shims.d.ts +6 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +61 -0
- package/esm/package.json +3 -0
- package/esm/utilities/CellSelection.d.ts +53 -0
- package/esm/utilities/CellSelection.d.ts.map +1 -0
- package/esm/utilities/CellSelection.js +382 -0
- package/esm/utilities/TableMap.d.ts +92 -0
- package/esm/utilities/TableMap.d.ts.map +1 -0
- package/esm/utilities/TableMap.js +335 -0
- package/esm/utilities/TableView.d.ts +21 -0
- package/esm/utilities/TableView.d.ts.map +1 -0
- package/esm/utilities/TableView.js +108 -0
- package/esm/utilities/columnResizing.d.ts +50 -0
- package/esm/utilities/columnResizing.d.ts.map +1 -0
- package/esm/utilities/columnResizing.js +307 -0
- package/esm/utilities/commands.d.ts +166 -0
- package/esm/utilities/commands.d.ts.map +1 -0
- package/esm/utilities/commands.js +702 -0
- package/esm/utilities/copypaste.d.ts +35 -0
- package/esm/utilities/copypaste.d.ts.map +1 -0
- package/esm/utilities/copypaste.js +283 -0
- package/esm/utilities/createCell.d.ts +3 -0
- package/esm/utilities/createCell.d.ts.map +1 -0
- package/esm/utilities/createCell.js +6 -0
- package/esm/utilities/createTable.d.ts +3 -0
- package/esm/utilities/createTable.d.ts.map +1 -0
- package/esm/utilities/createTable.js +30 -0
- package/esm/utilities/fixTables.d.ts +18 -0
- package/esm/utilities/fixTables.d.ts.map +1 -0
- package/esm/utilities/fixTables.js +146 -0
- package/esm/utilities/getTableNodeTypes.d.ts +5 -0
- package/esm/utilities/getTableNodeTypes.d.ts.map +1 -0
- package/esm/utilities/getTableNodeTypes.js +14 -0
- package/esm/utilities/input.d.ts +21 -0
- package/esm/utilities/input.d.ts.map +1 -0
- package/esm/utilities/input.js +241 -0
- package/esm/utilities/tableEditing.d.ts +23 -0
- package/esm/utilities/tableEditing.d.ts.map +1 -0
- package/esm/utilities/tableEditing.js +63 -0
- package/esm/utilities/tableNodeTypes.d.ts +14 -0
- package/esm/utilities/tableNodeTypes.d.ts.map +1 -0
- package/esm/utilities/tableNodeTypes.js +16 -0
- package/esm/utilities/util.d.ts +73 -0
- package/esm/utilities/util.d.ts.map +1 -0
- package/esm/utilities/util.js +155 -0
- package/package.json +30 -0
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import * as dntShim from "../_dnt.shims.js";
|
|
2
|
+
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
3
|
+
import { Decoration, DecorationSet, } from 'prosemirror-view';
|
|
4
|
+
import { tableNodeTypes } from './tableNodeTypes.js';
|
|
5
|
+
import { TableMap } from './TableMap.js';
|
|
6
|
+
import { TableView, updateColumnsOnResize } from './TableView.js';
|
|
7
|
+
import { cellAround, pointsAtCell } from './util.js';
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export const columnResizingPluginKey = new PluginKey('tableColumnResizing');
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export function columnResizing({ handleWidth = 5, cellMinWidth = 25, defaultCellMinWidth = 100, View = TableView, lastColumnResizable = true, } = {}) {
|
|
16
|
+
const plugin = new Plugin({
|
|
17
|
+
key: columnResizingPluginKey,
|
|
18
|
+
state: {
|
|
19
|
+
init(_, state) {
|
|
20
|
+
const nodeViews = plugin.spec?.props?.nodeViews;
|
|
21
|
+
const tableName = tableNodeTypes(state.schema).table.name;
|
|
22
|
+
if (View && nodeViews) {
|
|
23
|
+
nodeViews[tableName] = (node, view) => {
|
|
24
|
+
return new View(node, defaultCellMinWidth, view);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
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 = columnResizingPluginKey.getState(state);
|
|
36
|
+
return pluginState && pluginState.activeHandle > -1
|
|
37
|
+
? { class: 'resize-cursor' }
|
|
38
|
+
: {};
|
|
39
|
+
},
|
|
40
|
+
handleDOMEvents: {
|
|
41
|
+
mousemove: (view, event) => {
|
|
42
|
+
handleMouseMove(view, event, handleWidth, lastColumnResizable);
|
|
43
|
+
},
|
|
44
|
+
mouseleave: (view) => {
|
|
45
|
+
handleMouseLeave(view);
|
|
46
|
+
},
|
|
47
|
+
mousedown: (view, event) => {
|
|
48
|
+
handleMouseDown(view, event, cellMinWidth, defaultCellMinWidth);
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
decorations: (state) => {
|
|
52
|
+
const pluginState = columnResizingPluginKey.getState(state);
|
|
53
|
+
if (pluginState && pluginState.activeHandle > -1) {
|
|
54
|
+
return handleDecorations(state, pluginState.activeHandle);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
nodeViews: {},
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
return plugin;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
export class ResizeState {
|
|
66
|
+
constructor(activeHandle, dragging) {
|
|
67
|
+
Object.defineProperty(this, "activeHandle", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
configurable: true,
|
|
70
|
+
writable: true,
|
|
71
|
+
value: activeHandle
|
|
72
|
+
});
|
|
73
|
+
Object.defineProperty(this, "dragging", {
|
|
74
|
+
enumerable: true,
|
|
75
|
+
configurable: true,
|
|
76
|
+
writable: true,
|
|
77
|
+
value: dragging
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
apply(tr) {
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
82
|
+
const action = tr.getMeta(columnResizingPluginKey);
|
|
83
|
+
if (action && action.setHandle != null) {
|
|
84
|
+
return new ResizeState(action.setHandle, false);
|
|
85
|
+
}
|
|
86
|
+
if (action && action.setDragging !== undefined) {
|
|
87
|
+
return new ResizeState(this.activeHandle, action.setDragging);
|
|
88
|
+
}
|
|
89
|
+
if (this.activeHandle > -1 && tr.docChanged) {
|
|
90
|
+
let handle = tr.mapping.map(this.activeHandle, -1);
|
|
91
|
+
if (!pointsAtCell(tr.doc.resolve(handle))) {
|
|
92
|
+
handle = -1;
|
|
93
|
+
}
|
|
94
|
+
return new ResizeState(handle, this.dragging);
|
|
95
|
+
}
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function handleMouseMove(view, event, handleWidth, lastColumnResizable) {
|
|
100
|
+
if (!view.editable)
|
|
101
|
+
return;
|
|
102
|
+
const pluginState = columnResizingPluginKey.getState(view.state);
|
|
103
|
+
if (!pluginState)
|
|
104
|
+
return;
|
|
105
|
+
if (!pluginState.dragging) {
|
|
106
|
+
const target = domCellAround(event.target);
|
|
107
|
+
let cell = -1;
|
|
108
|
+
if (target) {
|
|
109
|
+
const { left, right } = target.getBoundingClientRect();
|
|
110
|
+
if (event.clientX - left <= handleWidth) {
|
|
111
|
+
cell = edgeCell(view, event, 'left', handleWidth);
|
|
112
|
+
}
|
|
113
|
+
else if (right - event.clientX <= handleWidth) {
|
|
114
|
+
cell = edgeCell(view, event, 'right', handleWidth);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (cell != pluginState.activeHandle) {
|
|
118
|
+
if (!lastColumnResizable && cell !== -1) {
|
|
119
|
+
const $cell = view.state.doc.resolve(cell);
|
|
120
|
+
const table = $cell.node(-1);
|
|
121
|
+
const map = TableMap.get(table);
|
|
122
|
+
const tableStart = $cell.start(-1);
|
|
123
|
+
const col = map.colCount($cell.pos - tableStart) +
|
|
124
|
+
$cell.nodeAfter.attrs.colspan -
|
|
125
|
+
1;
|
|
126
|
+
if (col == map.width - 1) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
updateHandle(view, cell);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function handleMouseLeave(view) {
|
|
135
|
+
if (!view.editable)
|
|
136
|
+
return;
|
|
137
|
+
const pluginState = columnResizingPluginKey.getState(view.state);
|
|
138
|
+
if (pluginState && pluginState.activeHandle > -1 && !pluginState.dragging) {
|
|
139
|
+
updateHandle(view, -1);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function handleMouseDown(view, event, cellMinWidth, defaultCellMinWidth) {
|
|
143
|
+
if (!view.editable)
|
|
144
|
+
return false;
|
|
145
|
+
const win = view.dom.ownerDocument.defaultView ?? dntShim.dntGlobalThis;
|
|
146
|
+
const pluginState = columnResizingPluginKey.getState(view.state);
|
|
147
|
+
if (!pluginState || pluginState.activeHandle == -1 || pluginState.dragging) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
const cell = view.state.doc.nodeAt(pluginState.activeHandle);
|
|
151
|
+
const width = currentColWidth(view, pluginState.activeHandle, cell.attrs);
|
|
152
|
+
view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, {
|
|
153
|
+
setDragging: { startX: event.clientX, startWidth: width },
|
|
154
|
+
}));
|
|
155
|
+
function finish(event) {
|
|
156
|
+
win.removeEventListener('mouseup', finish);
|
|
157
|
+
win.removeEventListener('mousemove', move);
|
|
158
|
+
const pluginState = columnResizingPluginKey.getState(view.state);
|
|
159
|
+
if (pluginState?.dragging) {
|
|
160
|
+
updateColumnWidth(view, pluginState.activeHandle, draggedWidth(pluginState.dragging, event, cellMinWidth));
|
|
161
|
+
view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setDragging: null }));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function move(event) {
|
|
165
|
+
if (!event.which)
|
|
166
|
+
return finish(event);
|
|
167
|
+
const pluginState = columnResizingPluginKey.getState(view.state);
|
|
168
|
+
if (!pluginState)
|
|
169
|
+
return;
|
|
170
|
+
if (pluginState.dragging) {
|
|
171
|
+
const dragged = draggedWidth(pluginState.dragging, event, cellMinWidth);
|
|
172
|
+
displayColumnWidth(view, pluginState.activeHandle, dragged, defaultCellMinWidth);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
displayColumnWidth(view, pluginState.activeHandle, width, defaultCellMinWidth);
|
|
176
|
+
win.addEventListener('mouseup', finish);
|
|
177
|
+
win.addEventListener('mousemove', move);
|
|
178
|
+
event.preventDefault();
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
function currentColWidth(view, cellPos, { colspan, colwidth }) {
|
|
182
|
+
const width = colwidth && colwidth[colwidth.length - 1];
|
|
183
|
+
if (width)
|
|
184
|
+
return width;
|
|
185
|
+
const dom = view.domAtPos(cellPos);
|
|
186
|
+
const node = dom.node.childNodes[dom.offset];
|
|
187
|
+
let domWidth = node.offsetWidth, parts = colspan;
|
|
188
|
+
if (colwidth) {
|
|
189
|
+
for (let i = 0; i < colspan; i++) {
|
|
190
|
+
if (colwidth[i]) {
|
|
191
|
+
domWidth -= colwidth[i];
|
|
192
|
+
parts--;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return domWidth / parts;
|
|
197
|
+
}
|
|
198
|
+
function domCellAround(target) {
|
|
199
|
+
while (target && target.nodeName != 'TD' && target.nodeName != 'TH') {
|
|
200
|
+
target = target.classList && target.classList.contains('ProseMirror')
|
|
201
|
+
? null
|
|
202
|
+
: target.parentNode;
|
|
203
|
+
}
|
|
204
|
+
return target;
|
|
205
|
+
}
|
|
206
|
+
function edgeCell(view, event, side, handleWidth) {
|
|
207
|
+
// posAtCoords returns inconsistent positions when cursor is moving
|
|
208
|
+
// across a collapsed table border. Use an offset to adjust the
|
|
209
|
+
// target viewport coordinates away from the table border.
|
|
210
|
+
const offset = side == 'right' ? -handleWidth : handleWidth;
|
|
211
|
+
const found = view.posAtCoords({
|
|
212
|
+
left: event.clientX + offset,
|
|
213
|
+
top: event.clientY,
|
|
214
|
+
});
|
|
215
|
+
if (!found)
|
|
216
|
+
return -1;
|
|
217
|
+
const { pos } = found;
|
|
218
|
+
const $cell = cellAround(view.state.doc.resolve(pos));
|
|
219
|
+
if (!$cell)
|
|
220
|
+
return -1;
|
|
221
|
+
if (side == 'right')
|
|
222
|
+
return $cell.pos;
|
|
223
|
+
const map = TableMap.get($cell.node(-1)), start = $cell.start(-1);
|
|
224
|
+
const index = map.map.indexOf($cell.pos - start);
|
|
225
|
+
return index % map.width == 0 ? -1 : start + map.map[index - 1];
|
|
226
|
+
}
|
|
227
|
+
function draggedWidth(dragging, event, resizeMinWidth) {
|
|
228
|
+
const offset = event.clientX - dragging.startX;
|
|
229
|
+
return Math.max(resizeMinWidth, dragging.startWidth + offset);
|
|
230
|
+
}
|
|
231
|
+
function updateHandle(view, value) {
|
|
232
|
+
view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setHandle: value }));
|
|
233
|
+
}
|
|
234
|
+
function updateColumnWidth(view, cell, width) {
|
|
235
|
+
const $cell = view.state.doc.resolve(cell);
|
|
236
|
+
const table = $cell.node(-1), map = TableMap.get(table), start = $cell.start(-1);
|
|
237
|
+
const col = map.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan -
|
|
238
|
+
1;
|
|
239
|
+
const tr = view.state.tr;
|
|
240
|
+
for (let row = 0; row < map.height; row++) {
|
|
241
|
+
const mapIndex = row * map.width + col;
|
|
242
|
+
// Rowspanning cell that has already been handled
|
|
243
|
+
if (row && map.map[mapIndex] == map.map[mapIndex - map.width])
|
|
244
|
+
continue;
|
|
245
|
+
const pos = map.map[mapIndex];
|
|
246
|
+
const attrs = table.nodeAt(pos).attrs;
|
|
247
|
+
const index = attrs.colspan == 1 ? 0 : col - map.colCount(pos);
|
|
248
|
+
if (attrs.colwidth && attrs.colwidth[index] == width)
|
|
249
|
+
continue;
|
|
250
|
+
const colwidth = attrs.colwidth
|
|
251
|
+
? attrs.colwidth.slice()
|
|
252
|
+
: zeroes(attrs.colspan);
|
|
253
|
+
colwidth[index] = width;
|
|
254
|
+
tr.setNodeMarkup(start + pos, null, { ...attrs, colwidth: colwidth });
|
|
255
|
+
}
|
|
256
|
+
if (tr.docChanged)
|
|
257
|
+
view.dispatch(tr);
|
|
258
|
+
}
|
|
259
|
+
function displayColumnWidth(view, cell, width, defaultCellMinWidth) {
|
|
260
|
+
const $cell = view.state.doc.resolve(cell);
|
|
261
|
+
const table = $cell.node(-1), start = $cell.start(-1);
|
|
262
|
+
const col = TableMap.get(table).colCount($cell.pos - start) +
|
|
263
|
+
$cell.nodeAfter.attrs.colspan -
|
|
264
|
+
1;
|
|
265
|
+
let dom = view.domAtPos($cell.start(-1)).node;
|
|
266
|
+
while (dom && dom.nodeName != 'TABLE') {
|
|
267
|
+
dom = dom.parentNode;
|
|
268
|
+
}
|
|
269
|
+
if (!dom)
|
|
270
|
+
return;
|
|
271
|
+
updateColumnsOnResize(table, dom.firstChild, dom, defaultCellMinWidth, col, width);
|
|
272
|
+
}
|
|
273
|
+
function zeroes(n) {
|
|
274
|
+
return Array(n).fill(0);
|
|
275
|
+
}
|
|
276
|
+
export function handleDecorations(state, cell) {
|
|
277
|
+
const decorations = [];
|
|
278
|
+
const $cell = state.doc.resolve(cell);
|
|
279
|
+
const table = $cell.node(-1);
|
|
280
|
+
if (!table) {
|
|
281
|
+
return DecorationSet.empty;
|
|
282
|
+
}
|
|
283
|
+
const map = TableMap.get(table);
|
|
284
|
+
const start = $cell.start(-1);
|
|
285
|
+
const col = map.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan -
|
|
286
|
+
1;
|
|
287
|
+
for (let row = 0; row < map.height; row++) {
|
|
288
|
+
const index = col + row * map.width;
|
|
289
|
+
// For positions that have either a different cell or the end
|
|
290
|
+
// of the table to their right, and either the top of the table or
|
|
291
|
+
// a different cell above them, add a decoration
|
|
292
|
+
if ((col == map.width - 1 || map.map[index] != map.map[index + 1]) &&
|
|
293
|
+
(row == 0 || map.map[index] != map.map[index - map.width])) {
|
|
294
|
+
const cellPos = map.map[index];
|
|
295
|
+
const pos = start + cellPos + table.nodeAt(cellPos).nodeSize - 1;
|
|
296
|
+
const dom = document.createElement('div');
|
|
297
|
+
dom.className = 'column-resize-handle';
|
|
298
|
+
if (columnResizingPluginKey.getState(state)?.dragging) {
|
|
299
|
+
decorations.push(Decoration.node(start + cellPos, start + cellPos + table.nodeAt(cellPos).nodeSize, {
|
|
300
|
+
class: 'column-resize-dragging',
|
|
301
|
+
}));
|
|
302
|
+
}
|
|
303
|
+
decorations.push(Decoration.widget(pos, dom));
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return DecorationSet.create(state.doc, decorations);
|
|
307
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { Node, NodeType } from 'prosemirror-model';
|
|
2
|
+
import { Command, EditorState, Transaction } from 'prosemirror-state';
|
|
3
|
+
import type { Direction } from './input.js';
|
|
4
|
+
import { Rect, TableMap } from './TableMap.js';
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export type TableRect = Rect & {
|
|
9
|
+
tableStart: number;
|
|
10
|
+
map: TableMap;
|
|
11
|
+
table: Node;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Helper to get the selected rectangle in a table, if any. Adds table
|
|
15
|
+
* map, table node, and table start offset to the object for
|
|
16
|
+
* convenience.
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export declare function selectedRect(state: EditorState): TableRect;
|
|
21
|
+
/**
|
|
22
|
+
* Add a column at the given position in a table.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export declare function addColumn(tr: Transaction, { map, tableStart, table }: TableRect, col: number): Transaction;
|
|
27
|
+
/**
|
|
28
|
+
* Command to add a column before the column with the selection.
|
|
29
|
+
*
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
export declare function addColumnBefore(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Command to add a column after the column with the selection.
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export declare function addColumnAfter(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export declare function removeColumn(tr: Transaction, { map, table, tableStart }: TableRect, col: number): void;
|
|
43
|
+
/**
|
|
44
|
+
* Command function that removes the selected columns from a table.
|
|
45
|
+
*
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
export declare function deleteColumn(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export declare function rowIsHeader(map: TableMap, table: Node, row: number): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
export declare function addRow(tr: Transaction, { map, tableStart, table }: TableRect, row: number): Transaction;
|
|
57
|
+
/**
|
|
58
|
+
* Add a table row before the selection.
|
|
59
|
+
*
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
export declare function addRowBefore(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Add a table row after the selection.
|
|
65
|
+
*
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
export declare function addRowAfter(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
export declare function removeRow(tr: Transaction, { map, table, tableStart }: TableRect, row: number): void;
|
|
73
|
+
/**
|
|
74
|
+
* Remove the selected rows from a table.
|
|
75
|
+
*
|
|
76
|
+
* @public
|
|
77
|
+
*/
|
|
78
|
+
export declare function deleteRow(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Merge the selected cells into a single cell. Only available when
|
|
81
|
+
* the selected cells' outline forms a rectangle.
|
|
82
|
+
*
|
|
83
|
+
* @public
|
|
84
|
+
*/
|
|
85
|
+
export declare function mergeCells(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Split a selected cell, whose rowpan or colspan is greater than one,
|
|
88
|
+
* into smaller cells. Use the first cell type for the new cells.
|
|
89
|
+
*
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
export declare function splitCell(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* @public
|
|
95
|
+
*/
|
|
96
|
+
export interface GetCellTypeOptions {
|
|
97
|
+
node: Node;
|
|
98
|
+
row: number;
|
|
99
|
+
col: number;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Split a selected cell, whose rowpan or colspan is greater than one,
|
|
103
|
+
* into smaller cells with the cell type (th, td) returned by getType function.
|
|
104
|
+
*
|
|
105
|
+
* @public
|
|
106
|
+
*/
|
|
107
|
+
export declare function splitCellWithType(getCellType: (options: GetCellTypeOptions) => NodeType): Command;
|
|
108
|
+
/**
|
|
109
|
+
* Returns a command that sets the given attribute to the given value,
|
|
110
|
+
* and is only available when the currently selected cell doesn't
|
|
111
|
+
* already have that attribute set to that value.
|
|
112
|
+
*
|
|
113
|
+
* @public
|
|
114
|
+
*/
|
|
115
|
+
export declare function setCellAttr(name: string, value: unknown): Command;
|
|
116
|
+
/**
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
export type ToggleHeaderType = 'column' | 'row' | 'cell';
|
|
120
|
+
/**
|
|
121
|
+
* Toggles between row/column header and normal cells (Only applies to first row/column).
|
|
122
|
+
* For deprecated behavior pass `useDeprecatedLogic` in options with true.
|
|
123
|
+
*
|
|
124
|
+
* @public
|
|
125
|
+
*/
|
|
126
|
+
export declare function toggleHeader(type: ToggleHeaderType, options?: {
|
|
127
|
+
useDeprecatedLogic: boolean;
|
|
128
|
+
} | undefined): Command;
|
|
129
|
+
/**
|
|
130
|
+
* Toggles whether the selected row contains header cells.
|
|
131
|
+
*
|
|
132
|
+
* @public
|
|
133
|
+
*/
|
|
134
|
+
export declare const toggleHeaderRow: Command;
|
|
135
|
+
/**
|
|
136
|
+
* Toggles whether the selected column contains header cells.
|
|
137
|
+
*
|
|
138
|
+
* @public
|
|
139
|
+
*/
|
|
140
|
+
export declare const toggleHeaderColumn: Command;
|
|
141
|
+
/**
|
|
142
|
+
* Toggles whether the selected cells are header cells.
|
|
143
|
+
*
|
|
144
|
+
* @public
|
|
145
|
+
*/
|
|
146
|
+
export declare const toggleHeaderCell: Command;
|
|
147
|
+
/**
|
|
148
|
+
* Returns a command for selecting the next (direction=1) or previous
|
|
149
|
+
* (direction=-1) cell in a table.
|
|
150
|
+
*
|
|
151
|
+
* @public
|
|
152
|
+
*/
|
|
153
|
+
export declare function goToNextCell(direction: Direction): Command;
|
|
154
|
+
/**
|
|
155
|
+
* Deletes the table around the selection, if any.
|
|
156
|
+
*
|
|
157
|
+
* @public
|
|
158
|
+
*/
|
|
159
|
+
export declare function deleteTable(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
|
|
160
|
+
/**
|
|
161
|
+
* Deletes the content of the selected cells, if they are not empty.
|
|
162
|
+
*
|
|
163
|
+
* @public
|
|
164
|
+
*/
|
|
165
|
+
export declare function deleteCellSelection(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
|
|
166
|
+
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/utilities/commands.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,IAAI,EACJ,QAAQ,EAGT,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,OAAO,EACP,WAAW,EAEX,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAG3B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAa/C;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,QAAQ,CAAC;IACd,KAAK,EAAE,IAAI,CAAC;CACb,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,WAAW,GAAG,SAAS,CAa1D;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CACvB,EAAE,EAAE,WAAW,EACf,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,SAAS,EACrC,GAAG,EAAE,MAAM,GACV,WAAW,CA4Bb;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,WAAW,EAClB,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,WAAW,KAAK,IAAI,GACnC,OAAO,CAOT;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,WAAW,EAClB,QAAQ,CAAC,EAAE,CAAC,EAAE,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