-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy patheditor.interface.ts
130 lines (105 loc) · 5.62 KB
/
editor.interface.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
import type { EditorArguments, EditorValidationResult } from './index.js';
/**
* SlickGrid Editor interface, more info can be found on the SlickGrid repo
* https://github.com/6pac/SlickGrid/wiki/Writing-custom-cell-editors
*/
export interface Editor {
/** item data context object */
dataContext?: any;
/** is the Editor disabled when we first open it? This could happen when we use "collectionAsync" and we wait for the "collection" to be filled before enabling the Editor. */
disabled?: boolean;
/** List of key codes, which will not be captured by default slickgrid hotkeys listeners */
keyCaptureList?: number[];
/** Initialize the Editor */
init: (args?: EditorArguments) => void;
/**
* Dynamically change an Editor option, this is especially useful when using a Composite Editor
* since this is the only way to change/update an option of the Editor after its creation
* (not all Editors support this feature, current only available with AutoComplete, Date, MultipleSelect & SingleSelect Editors).
* For example, a use case could be to dynamically change the "minDate" of another Date Editor in the Composite Editor form.
* @param {string} optionName - option name
* @param {newValue} newValue - new option value
*/
changeEditorOption?: (optionName: any, newValue: any) => void;
/**
* Disable the Editor input, this is only used by the Composite Editor Modal
* @param {boolean} isDisabled - optionally specify if the editor is disabled or not.
*/
disable?: (isDisabled?: boolean) => void;
/**
* Reset (or clear) editor function, when no value(s) is provided it will use the original value to reset.
* Also note that if this is called by the Composite Editor, it will by default also trigger the "onCompositeEditor" event
* For example if your editor is the TextEditor and you want to clear the input, then you can pass an empty string as the input value.
* @param value - optional input value, if not provided it will use the original value to reset
* @param triggerCompositeEventWhenExist - True by default, when the editor from the Composite Editor Modal, do we want to trigger the "onCompositeEditor" event
* @param clearByDisableCommand - False by default, is the reset called by the "disable()" method?
*/
reset?: (value?: any, triggerCompositeEventWhenExist?: boolean, clearByDisableCommand?: boolean) => void;
/** Saves the Editor value */
save?: () => void;
/** Cancels the Editor */
cancel?: () => void;
/**
* if implemented, this will be called if the cell being edited is scrolled out of the view
* implement this is your UI is not appended to the cell itself or if you open any secondary
* selector controls (like a calendar for a datepicker input)
*/
hide?: () => void;
/** pretty much the opposite of hide */
show?: () => void;
/**
* if implemented, this will be called by the grid if any of the cell containers are scrolled
* and the absolute position of the edited cell is changed
* if your UI is constructed as a child of document BODY, implement this to update the
* position of the elements as the position of the cell changes
* @param {object} - cellBox position: { top, left, bottom, right, width, height, visible }
*/
position?: (position: any) => void;
/** remove all data, events & dom elements created in the constructor */
destroy: () => void;
/** set the focus on the main input control (if any) */
focus: () => void;
/**
* Deserialize the value(s) saved to "state" and apply them to the data item.
* This method may get called after the editor itself has been destroyed,
* treat it as an equivalent of a Java/C# "static" method - no instance variables should be accessed
*/
applyValue: (item: any, state: any) => void;
/**
* Load the value(s) from the data item and update the UI
* this method will be called immediately after the editor is initialized
* it may also be called by the grid if if the row/cell being edited is updated via grid.updateRow/updateCell
*/
loadValue: (item: any) => void;
preClick?: () => void;
/**
* Return the value(s) being edited by the user in a serialized form
* can be an arbitrary object
* the only restriction is that it must be a simple object that can be passed around even
* when the editor itself has been destroyed
*/
serializeValue: () => any;
/** return true if the value(s) being edited by the user has/have been changed */
isValueChanged: () => boolean;
/**
* return true if the value(s) was touched.
* It is very similar to isValueChanged() except that if editor value goes back to original value
* then isValueTouched() will return True while isValueChanged() will return False
*/
isValueTouched?: () => boolean;
/** Optional render DOM element function */
renderDomElement?: (collection?: any[]) => any | void;
/** Update the Editor DOM element value with a provided value, we can optionally apply the value to the item dataContext object */
setValue?: (value: any, isApplyingValue?: boolean, triggerOnCompositeEditorChange?: boolean) => void;
/**
* Validate user input and return the result along with the validation message.
* if the input is valid then the validation result output would be returning { valid:true, msg:null }
* The first argument "targetElm" is ONLY used internally by the Composite Editor in most cases you want to make this null or undefined
*/
validate: (targetElm?: HTMLElement, options?: any) => EditorValidationResult;
}
export type EditorConstructor = {
new (args: EditorArguments): Editor;
/** Static flag used in makeActiveCellEditable. */
suppressClearOnEdit?: boolean;
};