forked from trilogy-group/contently-prosemirror-tables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
321 lines (267 loc) · 8.26 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
// 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 { NodeView } from 'prosemirror-view';
export interface TableEditingOptions {
allowTableNodeSelection?: boolean;
}
export interface TableNodesOptions {
tableGroup?: string;
cellContent: string;
cellAttributes: { [key: string]: CellAttributes };
}
export type getFromDOM = (dom: Element) => any;
export type setDOMAttr = (value: any, attrs: any) => any;
export interface CellAttributes {
default: any;
getFromDOM?: getFromDOM;
setDOMAttr?: setDOMAttr;
}
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<S extends Schema = any> {
constructor($anchorCell: ResolvedPos<S>, $headCell?: ResolvedPos<S>);
from: number;
to: number;
$from: ResolvedPos<S>;
$to: ResolvedPos<S>;
anchor: number;
head: number;
$anchor: ResolvedPos<S>;
$head: ResolvedPos<S>;
$anchorCell: ResolvedPos<S>;
$headCell: ResolvedPos<S>;
empty: boolean;
ranges: Array<SelectionRange<S>>;
map(doc: ProsemirrorNode<S>, mapping: Mappable): any;
content(): Slice<S>;
replace(tr: Transaction<S>, content: Slice<S>): void;
replaceWith(tr: Transaction<S>, node: ProsemirrorNode<S>): void;
forEachCell(f: (node: ProsemirrorNode<S>, pos: number) => void): void;
isRowSelection(): boolean;
isColSelection(): boolean;
eq(other: Selection<S>): boolean;
toJSON(): CellSelectionJSON;
getBookmark(): { anchor: number; head: number };
static colSelection<S extends Schema = any>(
anchorCell: ResolvedPos<S>,
headCell?: ResolvedPos<S>,
): CellSelection<S>;
static rowSelection<S extends Schema = any>(
anchorCell: ResolvedPos<S>,
headCell?: ResolvedPos<S>,
): CellSelection<S>;
static create<S extends Schema = any>(
doc: ProsemirrorNode<S>,
anchorCell: number,
headCell?: number,
): CellSelection<S>;
static fromJSON<S extends Schema = any>(
doc: ProsemirrorNode<S>,
json: CellSelectionJSON,
): CellSelection<S>;
}
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 function tableEditing(options?: TableEditingOptions): Plugin;
export function deleteTable<S extends Schema = any>(
state: EditorState<S>,
dispatch?: (tr: Transaction<S>) => void,
): boolean;
export function goToNextCell<S extends Schema = any>(
direction: number,
): (state: EditorState<S>, dispatch?: (tr: Transaction<S>) => void) => boolean;
export function toggleHeaderCell<S extends Schema = any>(
state: EditorState<S>,
dispatch?: (tr: Transaction<S>) => void,
): boolean;
export function toggleHeaderColumn<S extends Schema = any>(
state: EditorState<S>,
dispatch?: (tr: Transaction<S>) => void,
): boolean;
export function toggleHeaderRow<S extends Schema = any>(
state: EditorState<S>,
dispatch?: (tr: Transaction<S>) => 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<S extends Schema = any>(
type: 'column' | 'row',
options?: { useDeprecatedLogic?: boolean },
): (state: EditorState<S>, dispatch?: (tr: Transaction<S>) => void) => boolean;
export function setCellAttr<S extends Schema = any>(
name: string,
value: any,
): (state: EditorState<S>, dispatch?: (tr: Transaction<S>) => void) => boolean;
export function splitCell<S extends Schema = any>(
state: EditorState<S>,
dispatch?: (tr: Transaction<S>) => void,
): boolean;
export interface GetCellTypeOptions {
node: ProsemirrorNode;
row: number;
col: number;
}
export function splitCellWithType<S extends Schema = any>(
getCellType: (options: GetCellTypeOptions) => NodeType<S>,
): (state: EditorState<S>, dispatch?: (tr: Transaction<S>) => void) => boolean;
export function mergeCells<S extends Schema = any>(
state: EditorState<S>,
dispatch?: (tr: Transaction<S>) => void,
): boolean;
export function deleteRow<S extends Schema = any>(
state: EditorState<S>,
dispatch?: (tr: Transaction<S>) => void,
): boolean;
export function selectedRect<S extends Schema = any>(
state: EditorState<S>,
): TableRect;
export function rowIsHeader<S extends Schema = any>(
map: TableMap,
table: ProsemirrorNode<S>,
row: number,
): boolean;
export function addRowAfter<S extends Schema = any>(
state: EditorState<S>,
dispatch?: (tr: Transaction<S>) => void,
): boolean;
export function addRowBefore<S extends Schema = any>(
state: EditorState<S>,
dispatch?: (tr: Transaction<S>) => void,
): boolean;
export function addRow<S extends Schema = any>(
transaction: Transaction<S>,
rect: TableRect,
row: number,
): Transaction<S>;
export function deleteColumn<S extends Schema = any>(
state: EditorState<S>,
dispatch?: (tr: Transaction<S>) => void,
): boolean;
export function addColumnAfter<S extends Schema = any>(
state: EditorState<S>,
dispatch?: (tr: Transaction<S>) => void,
): boolean;
export function addColumnBefore<S extends Schema = any>(
state: EditorState<S>,
dispatch?: (tr: Transaction<S>) => void,
): boolean;
export function addColumn<S extends Schema = any>(
transaction: Transaction<S>,
rect: TableRect,
row: number,
): Transaction<S>;
export function columnResizing<S extends Schema = any>(props: {
handleWidth?: number;
cellMinWidth?: number;
View?: NodeView<S>;
}): Plugin<S>;
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<S extends Schema = any>(
pos: ResolvedPos<S>,
): ResolvedPos<S> | 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<S extends Schema = any>(
state: EditorState<S>,
): ResolvedPos<S> | null | undefined;
export function moveCellForward<S extends Schema = any>(
pos: ResolvedPos<S>,
): ResolvedPos<S>;
export function inSameTable<S extends Schema = any>(
$a: ResolvedPos<S>,
$b: ResolvedPos<S>,
): boolean;
export function findCell(pos: ResolvedPos): {
top: number;
left: number;
right: number;
bottom: number;
};
export function colCount(pos: ResolvedPos): number;
export function nextCell<S extends Schema = any>(
pos: ResolvedPos<S>,
axis: string,
dir: number,
): null | ResolvedPos<S>;
export function fixTables<S extends Schema = any>(
state: EditorState<S>,
oldState?: EditorState<S>,
): null | Transaction<S>;