forked from revolist/revogrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterfaces.d.ts
417 lines (347 loc) · 10.6 KB
/
interfaces.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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
/* eslint-disable */
/* tslint:disable */
// @ts-ignore
import { VNode } from '@stencil/core';
// @ts-ignore
import { ObservableMap, Subscription } from '@stencil/store';
export type Observable<T> = ObservableMap<T>;
export type PluginSubscribe<T> = Subscription<T>;
export declare namespace RevoGrid {
// --------------------------------------------------------------------------
//
// Dimensions
//
// --------------------------------------------------------------------------
type DimensionTypeRow = 'rgRow';
type DimensionTypeCol = 'rgCol';
type DimensionColPin = 'colPinStart' | 'colPinEnd';
type DimensionRowPin = 'rowPinStart' | 'rowPinEnd';
type DimensionType = DimensionTypeCol | DimensionTypeRow;
type DimensionCols = DimensionColPin | DimensionTypeCol;
type DimensionRows = DimensionTypeRow | DimensionRowPin;
type MultiDimensionType = DimensionCols | DimensionRows;
// --------------------------------------------------------------------------
//
// Columns
//
// --------------------------------------------------------------------------
type ColumnDataSchemaModel = {
// property
prop: ColumnProp;
// rgRow model
model: DataType;
// column data
column: ColumnRegular;
// index in grid datasource
rowIndex: number;
// grid datasource
data: DataSource;
};
type ReadOnlyFormat = boolean | ((params: ColumnDataSchemaModel) => boolean);
type RowDrag = boolean | { (params: ColumnDataSchemaModel): boolean };
interface ColumnGrouping {
children: ColumnDataSchema[];
name: DataFormat;
}
interface ColumnProperties {
/** column inner template */
columnTemplate?: ColumnTemplateFunc<VNode>;
/** cell properties */
columnProperties?: ColPropertiesFunc;
}
type ColumnTypes = { [name: string]: RevoGrid.ColumnType };
interface ColumnType extends ColumnProperties {
/** is column or cell readonly */
readonly?: ReadOnlyFormat;
/** cell properties */
cellProperties?: PropertiesFunc;
/** cell inner template */
cellTemplate?: CellTemplateFunc<VNode>;
/** cell compare function */
cellCompare?: CellCompareFunc;
/** default column size */
size?: number;
/**
* minimal column size
* this property can not be less than cell padding
* in order to keep performance on top and minimize dom elements number
*/
minSize?: number;
/** max column size */
maxSize?: number;
/** represents custom editor defined in @editors property */
editor?: string | Edition.EditorCtr;
}
type Order = 'asc' | 'desc' | undefined;
interface ColumnRegular extends ColumnType {
/** mapping to data */
prop?: ColumnProp;
/** column pin 'colPinStart'|'colPinEnd' */
pin?: DimensionColPin;
/** column header */
name?: DataFormat;
/** is column can be sorted */
sortable?: boolean;
/** column size would be changed based on content size */
autoSize?: boolean;
/** filter */
filter?: boolean | string | string[];
order?: Order;
/** is cell in column or individual can be dragged */
rowDrag?: RowDrag;
/** represents type defined in @columnTypes property */
columnType?: string;
beforeSetup?(rgCol: ColumnRegular): void;
[key: string]: any;
}
type ColumnDataSchema = ColumnGrouping | ColumnRegular;
type ColumnData = ColumnDataSchema[];
type ColumnProp = string | number;
type DataFormat = any;
type CellProp = string | number | object | boolean | undefined;
type CellProps = {
style?: { [key: string]: string | undefined };
class?: { [key: string]: boolean } | string;
[attr: string]: CellProp;
};
// --------------------------------------------------------------------------
//
// Create Element function description
//
// --------------------------------------------------------------------------
interface HyperFunc<T> {
(tag: any): T;
}
interface HyperFunc<T> {
(tag: any, data: any): T;
}
interface HyperFunc<T> {
(tag: any, text: string): T;
}
interface HyperFunc<T> {
(sel: any, children: Array<T | undefined | null>): T;
}
interface HyperFunc<T> {
(sel: any, data: any, text: string): T;
}
interface HyperFunc<T> {
(sel: any, data: any, children: Array<T | undefined | null>): T;
}
interface HyperFunc<T> {
(sel: any, data: any, children: T): T;
}
type CellTemplateFunc<T> = (createElement: HyperFunc<T>, props: ColumnDataSchemaModel) => any;
type CellCompareFunc = (prop: ColumnProp, a: DataType, b: DataType) => number;
type ColumnTemplateFunc<T> = (createElement: HyperFunc<T>, props: ColumnRegular) => T | T[] | string;
type PropertiesFunc = (props: ColumnDataSchemaModel) => CellProps | void | undefined;
type ColPropertiesFunc = (props: ColumnDataSchema) => CellProps | void | undefined;
// --------------------------------------------------------------------------
//
// Row data source
//
// --------------------------------------------------------------------------
type DataType = { [T in ColumnProp]: DataFormat };
type DataSource = DataType[];
type DataLookup = { [rowIndex: number]: DataType };
// --------------------------------------------------------------------------
//
// Row definitions
//
// --------------------------------------------------------------------------
type RowDefinition = {
type: DimensionRows;
size: number;
index: number;
};
interface RowHeaders extends RevoGrid.ColumnRegular {}
// --------------------------------------------------------------------------
//
// Events
//
// --------------------------------------------------------------------------
type ViewPortResizeEvent = {
dimension: DimensionType;
size: number;
};
type ViewPortScrollEvent = {
dimension: DimensionType;
coordinate: number;
delta?: number;
};
type InitialHeaderClick = {
index: number;
originalEvent: MouseEvent;
column: RevoGrid.ColumnRegular;
};
// --------------------------------------------------------------------------
//
// Viewport store
//
// --------------------------------------------------------------------------
type Range = {
start: number;
end: number;
};
type ViewportStateItems = {
items: VirtualPositionItem[];
} & Range;
interface ViewportState extends ViewportStateItems {
realCount: number;
virtualSize: number;
lastCoordinate: number;
}
type ViewSettingSizeProp = Record<string, number>;
interface VirtualPositionItem extends PositionItem {
size: number;
}
interface PositionItem {
itemIndex: number;
start: number;
end: number;
}
// --------------------------------------------------------------------------
//
// Dimension store
//
// --------------------------------------------------------------------------
interface DimensionCalc {
indexes: number[];
positionIndexes: number[];
positionIndexToItem: { [position: number]: PositionItem };
indexToItem: { [index: number]: PositionItem };
sizes: ViewSettingSizeProp;
}
interface DimensionSettingsState extends DimensionCalc {
frameOffset: number;
realSize: number;
originItemSize: number;
}
}
// --------------------------------------------------------------------------
//
// Plugin space
//
// --------------------------------------------------------------------------
export declare namespace RevoPlugin {
class Plugin {
constructor(revogrid: HTMLRevoGridElement, ...[]);
destroy(): void;
}
type PluginClass = typeof Plugin;
}
// --------------------------------------------------------------------------
//
// Selection space
//
// --------------------------------------------------------------------------
export declare namespace Selection {
type RowIndex = number;
type ColIndex = number;
type SelectionStoreState = {
range: RangeArea | null;
tempRange: RangeArea | null;
tempRangeType: string | null;
focus: Cell | null;
edit: Edition.EditCellStore | null;
lastCell: Cell | null;
};
type RangeArea = {
x: ColIndex;
y: RowIndex;
x1: ColIndex;
y1: RowIndex;
};
type TempRange = {
type: string;
area: RangeArea;
};
type ChangedRange = {
type: RevoGrid.DimensionRows;
newRange: RangeArea;
oldRange: RangeArea;
newProps: RevoGrid.ColumnProp[];
oldProps: RevoGrid.ColumnProp[];
newData: { [key: number]: RevoGrid.DataType };
};
interface Cell {
x: ColIndex;
y: RowIndex;
}
type FocusedCells = {
focus: Selection.Cell;
end: Selection.Cell;
};
type RangeAreaCss = {
left: string;
top: string;
width: string;
height: string;
};
}
// --------------------------------------------------------------------------
//
// Edition space
//
// --------------------------------------------------------------------------
export declare namespace Edition {
import HyperFunc = RevoGrid.HyperFunc;
type SaveData = string;
type SaveDataDetails = {
rgRow: Selection.RowIndex;
rgCol: Selection.ColIndex;
val: any;
preventFocus?: boolean;
};
type BeforeEdit = {
isCancel: boolean;
} & Edition.BeforeSaveDataDetails;
type BeforeSaveDataDetails = {
prop: RevoGrid.ColumnProp;
model: RevoGrid.DataType;
val?: SaveData;
rowIndex: number;
type: RevoGrid.DimensionRows;
};
type BeforeRangeSaveDataDetails = {
data: RevoGrid.DataLookup;
models: { [rowIndex: number]: RevoGrid.DataType };
type: RevoGrid.DimensionRows;
};
interface EditCellStore extends Selection.Cell {
val?: SaveData;
}
type EditCell = EditCellStore & BeforeSaveDataDetails;
type Editors = { [name: string]: EditorCtr };
interface EditorCtr {
new (
// column data
column: RevoGrid.ColumnRegular,
// to save changes
saveCallback: (value: Edition.SaveData, preventFocus?: boolean) => void,
// to close editor, if focusNext true, after close editor focus on next cell
closeCallback: (focusNext?: boolean) => void,
): EditorBase;
}
interface EditorBase {
element?: Element | null;
editCell?: EditCell;
componentDidRender?(): void;
disconnectedCallback?(): void;
render(createElement?: HyperFunc<VNode>): VNode | VNode[] | string | void;
}
}
export declare namespace ThemeSpace {
interface ThemePackage {
defaultRowSize: number;
}
type ThemeConfig = {
rowSize: number;
};
type Theme = 'default' | 'material' | 'compact' | 'darkMaterial' | 'darkCompact';
}
export type DimensionStores = {
[T in RevoGrid.MultiDimensionType]: Observable<RevoGrid.DimensionSettingsState>;
};
export type ViewportStores = {
[T in RevoGrid.MultiDimensionType]: Observable<RevoGrid.ViewportState>;
};