forked from ProseMirror/prosemirror-tables
-
Notifications
You must be signed in to change notification settings - Fork 24
/
index.d.ts
398 lines (328 loc) · 8.94 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
// Type definitions for prosemirror-tables 0.8
// Project: https://github.com/ProseMirror/prosemirror-tables
// Definitions by: Oscar Wallhult <https://github.com/superchu>
// Eduard Shvedai <https://github.com/eshvedai>
// Patrick Simmelbauer <https://github.com/patsimm>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import {
EditorState,
Plugin,
SelectionRange,
Transaction,
PluginKey,
Selection,
} from 'prosemirror-state';
import {
Node as ProsemirrorNode,
NodeSpec,
Slice,
ResolvedPos,
Schema,
NodeType,
} from 'prosemirror-model';
import { Mappable } from 'prosemirror-transform';
import { EditorView, NodeView } from 'prosemirror-view';
export interface TableEditingOptions {
allowTableNodeSelection?: boolean;
}
export interface TableNodesOptions {
tableGroup?: string;
cellContent: string;
cellAttributes: { [key: string]: CellAttributes };
cellContentGroup: string;
}
export type getFromDOM = (dom: Element) => any;
export type setDOMAttr = (value: any, attrs: any) => any;
export interface CellAttributes {
default: any;
getFromDOM?: getFromDOM;
setDOMAttr?: setDOMAttr;
}
export enum NodeNames {
TABLE= 'table',
TABLE_ROW= 'table_row',
TABLE_CELL= 'table_cell',
TABLE_HEADER= 'table_header',
CHECKBOX= 'checkbox',
DATE= 'date',
LABEL= 'label'
}
export interface TableNodes {
table: NodeSpec;
table_row: NodeSpec;
table_cell: NodeSpec;
table_header: NodeSpec;
}
export function tableNodes(options: TableNodesOptions): TableNodes;
export interface CellSelectionJSON {
type: string;
anchor: number;
head: number;
}
export class CellSelection extends Selection {
constructor($anchorCell: ResolvedPos, $headCell?: ResolvedPos);
$anchor: ResolvedPos;
$head: ResolvedPos;
$anchorCell: ResolvedPos;
$headCell: ResolvedPos;
ranges: Array<SelectionRange>;
map(doc: ProsemirrorNode, mapping: Mappable): any;
content(): Slice;
replace(tr: Transaction, content: Slice): void;
replaceWith(tr: Transaction, node: ProsemirrorNode): void;
forEachCell(f: (node: ProsemirrorNode, pos: number) => void): void;
isRowSelection(): boolean;
isColSelection(): boolean;
eq(other: Selection): boolean;
toJSON(): CellSelectionJSON;
getBookmark(): CellBookmark;
static colSelection(
anchorCell: ResolvedPos,
headCell?: ResolvedPos,
): CellSelection;
static rowSelection(
anchorCell: ResolvedPos,
headCell?: ResolvedPos,
): CellSelection;
static create(
doc: ProsemirrorNode,
anchorCell: number,
headCell?: number,
): CellSelection;
static fromJSON(doc: ProsemirrorNode, json: CellSelectionJSON): CellSelection;
}
export interface Rect {
left: number;
top: number;
right: number;
bottom: number;
}
export interface TableRect extends Rect {
tableStart: number;
map: TableMap;
table: ProsemirrorNode;
}
export class TableMap {
width: number;
height: number;
map: number[];
problems?: object[];
findCell(pos: number): Rect;
colCount(pos: number): number;
nextCell(pos: number, axis: string, dir: number): number;
rectBetween(a: number, b: number): Rect;
cellsInRect(rect: Rect): number[];
positionAt(row: number, col: number, table: ProsemirrorNode): number;
static get(table: ProsemirrorNode): TableMap;
}
export interface CellBookmark {
anchor: number;
head: number;
map(mapping: Mappable): CellBookmark;
resolve(doc: ProsemirrorNode): Selection;
}
export function tableEditing(options?: TableEditingOptions): Plugin;
export function columnHandles(): Plugin;
export function deleteTable(
state: EditorState,
dispatch?: (tr: Transaction) => void,
): boolean;
export function sortColumn(
state: EditorState,
dispatch?: (tr: Transaction) => void
): boolean;
export function goToNextCell<S extends Schema = any>(
direction: number,
): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
export function toggleHeaderCell(
state: EditorState,
dispatch?: (tr: Transaction) => void,
): boolean;
export function toggleHeaderColumn(
state: EditorState,
dispatch?: (tr: Transaction) => void,
): boolean;
export function toggleHeaderRow(
state: EditorState,
dispatch?: (tr: Transaction) => void,
): boolean;
/**
* Toggles between row/column header and normal cells (Only applies to first row/column).
* For deprecated behavior pass useDeprecatedLogic in options with true.
*/
export function toggleHeader(
type: 'column' | 'row',
options?: { useDeprecatedLogic?: boolean },
): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
export function setCellAttr(
name: string,
value: any,
): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
export function splitCell(
state: EditorState,
dispatch?: (tr: Transaction) => void,
): boolean;
export interface GetCellTypeOptions {
node: ProsemirrorNode;
row: number;
col: number;
}
export function splitCellWithType(
getCellType: (options: GetCellTypeOptions) => NodeType,
): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
export function mergeCells(
state: EditorState,
dispatch?: (tr: Transaction) => void,
): boolean;
export function deleteRow(
state: EditorState,
dispatch?: (tr: Transaction) => void,
): boolean;
export function selectedRect(state: EditorState): TableRect;
export function rowIsHeader(
map: TableMap,
table: ProsemirrorNode,
row: number,
): boolean;
export function addRowAfter(
state: EditorState,
dispatch?: (tr: Transaction) => void,
): boolean;
export function addRowBefore(
state: EditorState,
dispatch?: (tr: Transaction) => void,
): boolean;
export function addRow(
transaction: Transaction,
rect: TableRect,
row: number,
): Transaction;
export function deleteColumn(
state: EditorState,
dispatch?: (tr: Transaction) => void,
): boolean;
export function addColumnAfter(
state: EditorState,
dispatch?: (tr: Transaction) => void,
): boolean;
export function addColumnBefore(
state: EditorState,
dispatch?: (tr: Transaction) => void,
): boolean;
export function addColumn(
transaction: Transaction,
rect: TableRect,
row: number,
): Transaction;
export function columnResizing(props: {
handleWidth?: number;
cellMinWidth?: number;
View?: new (
node: ProsemirrorNode,
cellMinWidth: number,
view: EditorView,
) => NodeView;
}): Plugin;
export const columnResizingPluginKey: PluginKey;
export const tableEditingKey: PluginKey;
export const fixTablesKey: PluginKey;
export function updateColumnsOnResize(
node: ProsemirrorNode,
colgroup: Element,
table: Element,
cellMinWidth: number,
overrideCol?: number,
overrideValue?: number,
): void;
export function cellAround(pos: ResolvedPos): ResolvedPos | null;
export function isInTable(state: EditorState): boolean;
export function removeColSpan<T extends {}>(
attrs: T,
pos: number,
n?: number,
): T;
export function addColSpan<T extends {}>(attrs: T, pos: number, n?: number): T;
type TableRoles = 'table' | 'row' | 'cell' | 'header_cell';
export function columnIsHeader(
map: TableMap,
table: ProsemirrorNode,
col: number,
): boolean;
export function tableNodeTypes(schema: Schema): Record<TableRoles, NodeType>;
export function selectionCell(
state: EditorState,
): ResolvedPos | null | undefined;
export function moveCellForward(pos: ResolvedPos): ResolvedPos;
export function inSameTable($a: ResolvedPos, $b: ResolvedPos): boolean;
export function findCell(pos: ResolvedPos): {
top: number;
left: number;
right: number;
bottom: number;
};
export function colCount(pos: ResolvedPos): number;
export function nextCell(
pos: ResolvedPos,
axis: string,
dir: number,
): null | ResolvedPos;
export function fixTables(
state: EditorState,
oldState?: EditorState,
): null | Transaction;
export function addBottomRow(
state: EditorState,
dispatch: (tr: Transaction) => void,
pos: number
): void
export function addRightColumn(
state: EditorState,
dispatch: (tr: Transaction) => void,
pos: number
): void
export function deleteLastRow(
state: EditorState,
dispatch: (tr: Transaction) => void,
): void
export function deleteLastCol(
state: EditorState,
dispatch: (tr: Transaction) => void,
): void
export function changeCellsBackgroundColor(
state: EditorState,
dispatch: (tr: Transaction) => void,
color: string
): void
export function toggleTableHeaders(
state: EditorState,
dispatch: (tr: Transaction) => void,
view: EditorView
): void
export function getDeleteCommand(
state: EditorState
): (
state: EditorState,
dispatch: (tr: Transaction) => void,
) => void
export function isCellColorActive(
state: EditorState,
color: string
)
export function getSelectedCellsCoords(
view: EditorView
): {
top: number,
bottom: number,
right: number,
left: number,
width: number,
height: number
}
export function setBaseName(
name: string
)
export function fixTables(
state: EditorState,
oldState?: EditorState,
): null | Transaction;