-
Notifications
You must be signed in to change notification settings - Fork 98
/
types.ts
103 lines (99 loc) · 2.93 KB
/
types.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
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export interface IEditor<V = any> {
/**
* Called when cell enters edit mode.
*
* Warning will be thrown if you don't provide this function
* after removal of `beginEditing`.
*/
onStart: (context: EditContext<V>) => void;
/**
* called when cell exits edit mode.
*
* Warning will be thrown if you don't provide this function
* after removal of `exit`.
*/
onEnd: () => void;
/**
* Called when user click somewhere while editor is in edit mode.
*
* If returns falsy, VTable will exit edit mode.
*
* If returns truthy or not defined, nothing will happen.
* Which means, in this scenario, you need to call `endEdit` manually
* to end edit mode.
*/
isEditorElement?: (target: HTMLElement) => boolean;
/**
* Before set new value to table, use it to validate value.
* If the interface returns true, the value takes effect; otherwise, it does not take effect.
*/
validateValue?: () => boolean | Promise<boolean>;
/**
* Called when editor mode is exited by any means.
* Expected to return the current value of the cell.
*/
getValue: () => V;
/**
* Called when cell enter edit mode.
* @deprecated use `onStart` instead.
*/
beginEditing?: (container: HTMLElement, referencePosition: ReferencePosition, value: V) => void;
/**
* @see onEnd
* @deprecated use `onEnd` instead.
*/
exit?: () => void;
/**
* @see isEditorElement
* @deprecated use `isEditorElement` instead.
*/
targetIsOnEditor?: (target: HTMLElement) => boolean;
/**
* Called when cell enters edit mode with a callback function
* that can be used to end edit mode.
* @see EditContext#endEdit
* @deprecated callback is provided as `endEdit` in `EditContext`, use `onStart` instead.
*/
bindSuccessCallback?: (callback: () => void) => void;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export interface EditContext<V = any> {
/** Container element of the VTable instance. */
container: HTMLElement;
/** Position info of the cell that is being edited. */
referencePosition: ReferencePosition;
/** Cell value before editing. */
value: V;
/**
* Callback function that can be used to end edit mode.
*
* In most cases you don't need to call this function,
* since Enter key click is handled by VTable automatically,
* and mouse click can be handled by `isEditorElement`.
*
* However, if your editor has its own complete button,
* or you have external elements like Tooltip,
* you may want to use this callback to help you
* end edit mode.
*/
endEdit: () => void;
col: number;
row: number;
}
export interface RectProps {
left: number;
top: number;
width: number;
height: number;
}
export enum Placement {
top = 'top',
bottom = 'bottom',
left = 'left',
right = 'right'
}
export interface ReferencePosition {
rect: RectProps;
placement?: Placement;
}