x4js 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +12 -9
- package/lib/README.txt +0 -15
- package/lib/src/assets/house-light.svg +0 -1
- package/lib/src/assets/radio.svg +0 -4
- package/lib/src/components/base.scss +0 -26
- package/lib/src/components/boxes/boxes.module.scss +0 -37
- package/lib/src/components/boxes/boxes.ts +0 -125
- package/lib/src/components/btngroup/btngroup.module.scss +0 -29
- package/lib/src/components/btngroup/btngroup.ts +0 -106
- package/lib/src/components/button/button.module.scss +0 -154
- package/lib/src/components/button/button.ts +0 -117
- package/lib/src/components/calendar/calendar-check-sharp-light.svg +0 -1
- package/lib/src/components/calendar/calendar.module.scss +0 -163
- package/lib/src/components/calendar/calendar.ts +0 -326
- package/lib/src/components/calendar/chevron-left-sharp-light.svg +0 -1
- package/lib/src/components/calendar/chevron-right-sharp-light.svg +0 -1
- package/lib/src/components/checkbox/check.svg +0 -4
- package/lib/src/components/checkbox/checkbox.module.scss +0 -142
- package/lib/src/components/checkbox/checkbox.ts +0 -125
- package/lib/src/components/colorinput/colorinput.module.scss +0 -65
- package/lib/src/components/colorinput/colorinput.ts +0 -88
- package/lib/src/components/colorinput/crosshairs-simple-sharp-light.svg +0 -1
- package/lib/src/components/colorpicker/colorpicker.module.scss +0 -133
- package/lib/src/components/colorpicker/colorpicker.ts +0 -477
- package/lib/src/components/combobox/combobox.module.scss +0 -121
- package/lib/src/components/combobox/combobox.ts +0 -190
- package/lib/src/components/combobox/updown.svg +0 -4
- package/lib/src/components/dialog/dialog.module.scss +0 -71
- package/lib/src/components/dialog/dialog.ts +0 -91
- package/lib/src/components/dialog/xmark-sharp-light.svg +0 -1
- package/lib/src/components/form/form.module.scss +0 -34
- package/lib/src/components/form/form.ts +0 -36
- package/lib/src/components/header/header.module.scss +0 -40
- package/lib/src/components/header/header.ts +0 -124
- package/lib/src/components/icon/icon.module.scss +0 -30
- package/lib/src/components/icon/icon.ts +0 -134
- package/lib/src/components/image/image.module.scss +0 -21
- package/lib/src/components/image/image.ts +0 -67
- package/lib/src/components/input/input.module.scss +0 -69
- package/lib/src/components/input/input.ts +0 -274
- package/lib/src/components/label/label.module.scss +0 -52
- package/lib/src/components/label/label.ts +0 -55
- package/lib/src/components/listbox/listbox.module.scss +0 -103
- package/lib/src/components/listbox/listbox.ts +0 -427
- package/lib/src/components/menu/caret-right-solid.svg +0 -1
- package/lib/src/components/menu/menu.module.scss +0 -108
- package/lib/src/components/menu/menu.ts +0 -168
- package/lib/src/components/messages/circle-exclamation.svg +0 -1
- package/lib/src/components/messages/messages.module.scss +0 -47
- package/lib/src/components/messages/messages.ts +0 -64
- package/lib/src/components/normalize.scss +0 -386
- package/lib/src/components/notification/circle-check-solid.svg +0 -1
- package/lib/src/components/notification/circle-exclamation-solid.svg +0 -1
- package/lib/src/components/notification/circle-notch-light.svg +0 -1
- package/lib/src/components/notification/notification.module.scss +0 -82
- package/lib/src/components/notification/notification.ts +0 -108
- package/lib/src/components/notification/xmark-sharp-light.svg +0 -1
- package/lib/src/components/panel/panel.module.scss +0 -48
- package/lib/src/components/panel/panel.ts +0 -57
- package/lib/src/components/popup/popup.module.scss +0 -43
- package/lib/src/components/popup/popup.ts +0 -395
- package/lib/src/components/progress/progress.module.scss +0 -57
- package/lib/src/components/progress/progress.ts +0 -43
- package/lib/src/components/rating/rating.module.scss +0 -23
- package/lib/src/components/rating/rating.ts +0 -125
- package/lib/src/components/rating/star-sharp-light.svg +0 -1
- package/lib/src/components/rating/star-sharp-solid.svg +0 -1
- package/lib/src/components/shared.scss +0 -76
- package/lib/src/components/sizers/sizer.module.scss +0 -90
- package/lib/src/components/sizers/sizer.ts +0 -120
- package/lib/src/components/slider/slider.module.scss +0 -71
- package/lib/src/components/slider/slider.ts +0 -143
- package/lib/src/components/switch/switch.module.scss +0 -127
- package/lib/src/components/switch/switch.ts +0 -56
- package/lib/src/components/tabs/tabs.module.scss +0 -46
- package/lib/src/components/tabs/tabs.ts +0 -157
- package/lib/src/components/textarea/textarea.module.scss +0 -59
- package/lib/src/components/textarea/textarea.ts +0 -54
- package/lib/src/components/textedit/textedit.module.scss +0 -114
- package/lib/src/components/textedit/textedit.ts +0 -82
- package/lib/src/components/themes.scss +0 -77
- package/lib/src/components/tooltips/circle-info-sharp-light.svg +0 -1
- package/lib/src/components/tooltips/tooltips.scss +0 -51
- package/lib/src/components/tooltips/tooltips.ts +0 -103
- package/lib/src/components/treeview/chevron-down-light.svg +0 -1
- package/lib/src/components/treeview/treeview.module.scss +0 -116
- package/lib/src/components/treeview/treeview.ts +0 -403
- package/lib/src/components/viewport/viewport.module.scss +0 -25
- package/lib/src/components/viewport/viewport.ts +0 -38
- package/lib/src/core/component.ts +0 -979
- package/lib/src/core/core_colors.ts +0 -250
- package/lib/src/core/core_dom.ts +0 -471
- package/lib/src/core/core_dragdrop.ts +0 -201
- package/lib/src/core/core_element.ts +0 -98
- package/lib/src/core/core_events.ts +0 -149
- package/lib/src/core/core_i18n.ts +0 -377
- package/lib/src/core/core_router.ts +0 -221
- package/lib/src/core/core_styles.ts +0 -215
- package/lib/src/core/core_svg.ts +0 -550
- package/lib/src/core/core_tools.ts +0 -673
- package/lib/src/main.scss +0 -21
- package/lib/src/main.tsx +0 -323
- package/lib/src/x4.scss +0 -19
- package/lib/types/x4.d.ts +0 -2624
- package/scripts/build.mjs +0 -351
- package/scripts/prepack.mjs +0 -15
- package/src/assets/house-light.svg +0 -1
- package/src/assets/radio.svg +0 -4
- package/src/components/base.scss +0 -26
- package/src/components/boxes/boxes.module.scss +0 -37
- package/src/components/boxes/boxes.ts +0 -125
- package/src/components/btngroup/btngroup.module.scss +0 -29
- package/src/components/btngroup/btngroup.ts +0 -106
- package/src/components/button/button.module.scss +0 -154
- package/src/components/button/button.ts +0 -117
- package/src/components/calendar/calendar-check-sharp-light.svg +0 -1
- package/src/components/calendar/calendar.module.scss +0 -163
- package/src/components/calendar/calendar.ts +0 -326
- package/src/components/calendar/chevron-left-sharp-light.svg +0 -1
- package/src/components/calendar/chevron-right-sharp-light.svg +0 -1
- package/src/components/checkbox/check.svg +0 -4
- package/src/components/checkbox/checkbox.module.scss +0 -142
- package/src/components/checkbox/checkbox.ts +0 -125
- package/src/components/colorinput/colorinput.module.scss +0 -65
- package/src/components/colorinput/colorinput.ts +0 -88
- package/src/components/colorinput/crosshairs-simple-sharp-light.svg +0 -1
- package/src/components/colorpicker/colorpicker.module.scss +0 -133
- package/src/components/colorpicker/colorpicker.ts +0 -477
- package/src/components/combobox/combobox.module.scss +0 -121
- package/src/components/combobox/combobox.ts +0 -190
- package/src/components/combobox/updown.svg +0 -4
- package/src/components/dialog/dialog.module.scss +0 -71
- package/src/components/dialog/dialog.ts +0 -91
- package/src/components/dialog/xmark-sharp-light.svg +0 -1
- package/src/components/form/form.module.scss +0 -34
- package/src/components/form/form.ts +0 -36
- package/src/components/header/header.module.scss +0 -40
- package/src/components/header/header.ts +0 -124
- package/src/components/icon/icon.module.scss +0 -30
- package/src/components/icon/icon.ts +0 -134
- package/src/components/image/image.module.scss +0 -21
- package/src/components/image/image.ts +0 -67
- package/src/components/input/input.module.scss +0 -69
- package/src/components/input/input.ts +0 -274
- package/src/components/label/label.module.scss +0 -52
- package/src/components/label/label.ts +0 -55
- package/src/components/listbox/listbox.module.scss +0 -103
- package/src/components/listbox/listbox.ts +0 -427
- package/src/components/menu/caret-right-solid.svg +0 -1
- package/src/components/menu/menu.module.scss +0 -108
- package/src/components/menu/menu.ts +0 -168
- package/src/components/messages/circle-exclamation.svg +0 -1
- package/src/components/messages/messages.module.scss +0 -47
- package/src/components/messages/messages.ts +0 -64
- package/src/components/normalize.scss +0 -386
- package/src/components/notification/circle-check-solid.svg +0 -1
- package/src/components/notification/circle-exclamation-solid.svg +0 -1
- package/src/components/notification/circle-notch-light.svg +0 -1
- package/src/components/notification/notification.module.scss +0 -82
- package/src/components/notification/notification.ts +0 -108
- package/src/components/notification/xmark-sharp-light.svg +0 -1
- package/src/components/panel/panel.module.scss +0 -48
- package/src/components/panel/panel.ts +0 -57
- package/src/components/popup/popup.module.scss +0 -43
- package/src/components/popup/popup.ts +0 -395
- package/src/components/progress/progress.module.scss +0 -57
- package/src/components/progress/progress.ts +0 -43
- package/src/components/rating/rating.module.scss +0 -23
- package/src/components/rating/rating.ts +0 -125
- package/src/components/rating/star-sharp-light.svg +0 -1
- package/src/components/rating/star-sharp-solid.svg +0 -1
- package/src/components/shared.scss +0 -76
- package/src/components/sizers/sizer.module.scss +0 -90
- package/src/components/sizers/sizer.ts +0 -120
- package/src/components/slider/slider.module.scss +0 -71
- package/src/components/slider/slider.ts +0 -143
- package/src/components/switch/switch.module.scss +0 -127
- package/src/components/switch/switch.ts +0 -56
- package/src/components/tabs/tabs.module.scss +0 -46
- package/src/components/tabs/tabs.ts +0 -157
- package/src/components/textarea/textarea.module.scss +0 -59
- package/src/components/textarea/textarea.ts +0 -54
- package/src/components/textedit/textedit.module.scss +0 -114
- package/src/components/textedit/textedit.ts +0 -82
- package/src/components/themes.scss +0 -77
- package/src/components/tooltips/circle-info-sharp-light.svg +0 -1
- package/src/components/tooltips/tooltips.scss +0 -51
- package/src/components/tooltips/tooltips.ts +0 -103
- package/src/components/treeview/chevron-down-light.svg +0 -1
- package/src/components/treeview/treeview.module.scss +0 -116
- package/src/components/treeview/treeview.ts +0 -403
- package/src/components/viewport/viewport.module.scss +0 -25
- package/src/components/viewport/viewport.ts +0 -38
- package/src/core/component.ts +0 -979
- package/src/core/core_colors.ts +0 -250
- package/src/core/core_dom.ts +0 -471
- package/src/core/core_dragdrop.ts +0 -201
- package/src/core/core_element.ts +0 -98
- package/src/core/core_events.ts +0 -149
- package/src/core/core_i18n.ts +0 -377
- package/src/core/core_router.ts +0 -221
- package/src/core/core_styles.ts +0 -215
- package/src/core/core_svg.ts +0 -550
- package/src/core/core_tools.ts +0 -673
- package/src/main.scss +0 -21
- package/src/main.tsx +0 -323
- package/src/x4.scss +0 -19
- package/tsconfig.json +0 -14
- package/types/scss.d.ts +0 -4
- package/types/svg.d.ts +0 -4
- package/types/x4react.d.ts +0 -9
package/src/core/component.ts
DELETED
|
@@ -1,979 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / \____ _|
|
|
6
|
-
* /__/\__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file component.ts
|
|
9
|
-
* @author Etienne Cochard
|
|
10
|
-
*
|
|
11
|
-
* @copyright (c) 2024 R-libre ingenierie
|
|
12
|
-
*
|
|
13
|
-
* Use of this source code is governed by an MIT-style license
|
|
14
|
-
* that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
|
15
|
-
**/
|
|
16
|
-
|
|
17
|
-
import { isArray, UnsafeHtml, isNumber, Rect, Constructor } from './core_tools';
|
|
18
|
-
import { CoreElement } from './core_element';
|
|
19
|
-
import { ariaValues, unitless } from './core_styles';
|
|
20
|
-
import { CoreEvent, EventMap } from './core_events';
|
|
21
|
-
import { addEvent, DOMEventHandler, GlobalDOMEvents } from './core_dom';
|
|
22
|
-
|
|
23
|
-
interface RefType<T extends Component> {
|
|
24
|
-
dom: T;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
type ComponentAttributes = Record<string,string|number|boolean>;
|
|
28
|
-
|
|
29
|
-
const FRAGMENT = Symbol( "fragment" );
|
|
30
|
-
const COMPONENT = Symbol( "component" );
|
|
31
|
-
|
|
32
|
-
const RE_NUMBER = /^-?\d+(\.\d*)?$/;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
*
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
function genClassNames( x: any ) {
|
|
39
|
-
|
|
40
|
-
let classes = [];
|
|
41
|
-
let self = Object.getPrototypeOf(x);
|
|
42
|
-
|
|
43
|
-
while (self && self.constructor !== Component ) {
|
|
44
|
-
let clsname:string = self.constructor.name;
|
|
45
|
-
classes.push( 'x4'+clsname.toLowerCase() );
|
|
46
|
-
self = Object.getPrototypeOf(self);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return classes;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
*
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
export type ComponentContent = Component | string | UnsafeHtml | number | boolean | Component[];
|
|
57
|
-
|
|
58
|
-
let gen_id = 1000;
|
|
59
|
-
|
|
60
|
-
export const makeUniqueComponentId = ( ) => {
|
|
61
|
-
return `x4-${gen_id++}`;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
*
|
|
66
|
-
*/
|
|
67
|
-
|
|
68
|
-
export interface ComponentProps {
|
|
69
|
-
tag?: string;
|
|
70
|
-
ns?: string;
|
|
71
|
-
|
|
72
|
-
style?: Partial<CSSStyleDeclaration>;
|
|
73
|
-
attrs?: Record<string,string|number|boolean>;
|
|
74
|
-
content?: ComponentContent;
|
|
75
|
-
dom_events?: GlobalDOMEvents;
|
|
76
|
-
cls?: string;
|
|
77
|
-
id?: string;
|
|
78
|
-
ref?: RefType<any>;
|
|
79
|
-
|
|
80
|
-
// shortcuts
|
|
81
|
-
width?: string | number;
|
|
82
|
-
height?: string | number;
|
|
83
|
-
disabled?: true,
|
|
84
|
-
hidden?: true,
|
|
85
|
-
|
|
86
|
-
tooltip?: string;
|
|
87
|
-
|
|
88
|
-
// wrapper
|
|
89
|
-
existingDOM?: HTMLElement;
|
|
90
|
-
|
|
91
|
-
// index signature
|
|
92
|
-
// to avoid errors: Type 'X' has no properties in common with type 'Y'
|
|
93
|
-
// because all memebers here are optional.
|
|
94
|
-
// this allow TS to recongnize derived props as ComponentProps
|
|
95
|
-
//[key: string]: any;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
*
|
|
101
|
-
*/
|
|
102
|
-
|
|
103
|
-
export interface ComponentEvent extends CoreEvent {
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
*
|
|
108
|
-
*/
|
|
109
|
-
|
|
110
|
-
export interface ComponentEvents extends EventMap {
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
*
|
|
115
|
-
*/
|
|
116
|
-
|
|
117
|
-
export class Component<P extends ComponentProps = ComponentProps, E extends ComponentEvents = ComponentEvents>
|
|
118
|
-
extends CoreElement<E> {
|
|
119
|
-
|
|
120
|
-
readonly dom: Element;
|
|
121
|
-
readonly props: P;
|
|
122
|
-
private store: Map<string|Symbol,any>;
|
|
123
|
-
|
|
124
|
-
constructor( props: P ) {
|
|
125
|
-
super( );
|
|
126
|
-
|
|
127
|
-
this.props = props; // copy ?
|
|
128
|
-
|
|
129
|
-
if( props.existingDOM ) {
|
|
130
|
-
this.dom = props.existingDOM;
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
if( props.ns ) {
|
|
134
|
-
this.dom = document.createElementNS( props.ns, props.tag ?? "div" );
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
this.dom = document.createElement( props.tag ?? "div" );
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (props.attrs) {
|
|
141
|
-
this.setAttributes( props.attrs );
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if( props.cls ) {
|
|
145
|
-
this.addClass( props.cls );
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if( props.hidden ) {
|
|
149
|
-
this.show( false );
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if( props.id!==undefined ) {
|
|
153
|
-
this.setAttribute( "id", props.id );
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// small shortcut
|
|
157
|
-
if( props.width!==undefined ) {
|
|
158
|
-
this.setStyleValue( "width", props.width );
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if( props.height!==undefined ) {
|
|
162
|
-
this.setStyleValue( "height", props.height );
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if( props.tooltip ) {
|
|
166
|
-
this.setAttribute( "tooltip", props.tooltip );
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
if( props.style ) {
|
|
170
|
-
this.setStyle( props.style );
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if( props.content ) {
|
|
174
|
-
this.setContent( props.content );
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if( props.dom_events ) {
|
|
178
|
-
this.setDOMEvents( props.dom_events );
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const classes = genClassNames( this );
|
|
182
|
-
this.dom.classList.add( ...classes );
|
|
183
|
-
|
|
184
|
-
// need to have children for next statements
|
|
185
|
-
// and children way be created in caller
|
|
186
|
-
if( props.disabled ) {
|
|
187
|
-
this.addDOMEvent( "created", ( ) => {
|
|
188
|
-
this.enable( false );
|
|
189
|
-
} );
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
(this.dom as any)[COMPONENT] = this;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
// :: CLASSES ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
*
|
|
201
|
-
*/
|
|
202
|
-
|
|
203
|
-
hasClass( cls: string ) {
|
|
204
|
-
return this.dom.classList.contains( cls );
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
*
|
|
209
|
-
*/
|
|
210
|
-
|
|
211
|
-
addClass( cls: string ) {
|
|
212
|
-
if( !cls ) return;
|
|
213
|
-
|
|
214
|
-
if( cls.indexOf(' ')>=0 ) {
|
|
215
|
-
const ccs = cls.split( " " );
|
|
216
|
-
this.dom.classList.add(...ccs);
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
this.dom.classList.add(cls);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
*
|
|
225
|
-
*/
|
|
226
|
-
|
|
227
|
-
removeClass( cls: string ) {
|
|
228
|
-
if( !cls ) return;
|
|
229
|
-
|
|
230
|
-
if( cls.indexOf(' ')>=0 ) {
|
|
231
|
-
const ccs = cls.split( " " );
|
|
232
|
-
this.dom.classList.remove(...ccs);
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
this.dom.classList.remove(cls);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
*
|
|
241
|
-
*/
|
|
242
|
-
|
|
243
|
-
toggleClass( cls: string ) {
|
|
244
|
-
if( !cls ) return;
|
|
245
|
-
|
|
246
|
-
const toggle = ( x: string ) => {
|
|
247
|
-
this.dom.classList.toggle(x);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
if( cls.indexOf(' ')>=0 ) {
|
|
251
|
-
const ccs = cls.split( " " );
|
|
252
|
-
ccs.forEach( toggle );
|
|
253
|
-
}
|
|
254
|
-
else {
|
|
255
|
-
toggle( cls );
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
*
|
|
261
|
-
*/
|
|
262
|
-
|
|
263
|
-
setClass( cls: string, set: boolean = true ) {
|
|
264
|
-
if( set ) this.addClass(cls);
|
|
265
|
-
else this.removeClass( cls );
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// :: ATTRIBUTES ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* attributes
|
|
272
|
-
*/
|
|
273
|
-
|
|
274
|
-
setAttributes( attrs: ComponentAttributes ) {
|
|
275
|
-
|
|
276
|
-
for( const name in attrs ) {
|
|
277
|
-
const value = attrs[name];
|
|
278
|
-
this.setAttribute( name, value );
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
*
|
|
284
|
-
*/
|
|
285
|
-
|
|
286
|
-
setAttribute( name: string, value: string | number | boolean ) {
|
|
287
|
-
if( value===null || value===undefined ) {
|
|
288
|
-
this.dom.removeAttribute( name );
|
|
289
|
-
}
|
|
290
|
-
else {
|
|
291
|
-
this.dom.setAttribute( name, ""+value );
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
*
|
|
297
|
-
*/
|
|
298
|
-
|
|
299
|
-
getAttribute( name: string ): string {
|
|
300
|
-
return this.dom.getAttribute( name );
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
*
|
|
305
|
-
*/
|
|
306
|
-
|
|
307
|
-
getData( name: string ) : string {
|
|
308
|
-
return this.getAttribute( "data-"+name );
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
*
|
|
313
|
-
*/
|
|
314
|
-
|
|
315
|
-
setData( name: string, value: string ) {
|
|
316
|
-
return this.setAttribute( "data-"+name, value );
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* idem as setData but onot on dom, you can store anything
|
|
321
|
-
*/
|
|
322
|
-
|
|
323
|
-
setInternalData( name: string|Symbol, value: any ): this {
|
|
324
|
-
if( !this.store ) {
|
|
325
|
-
this.store = new Map( );
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
this.store.set( name, value );
|
|
329
|
-
return this;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
getInternalData( name: string|Symbol ): any {
|
|
333
|
-
return this.store?.get(name);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
// :: DOM EVENTS ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
*
|
|
341
|
-
*/
|
|
342
|
-
|
|
343
|
-
addDOMEvent<K extends keyof GlobalDOMEvents>( name: K, listener: GlobalDOMEvents[K], prepend = false ) {
|
|
344
|
-
addEvent( this.dom, name, listener as DOMEventHandler, prepend );
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
*
|
|
349
|
-
*/
|
|
350
|
-
|
|
351
|
-
setDOMEvents( events: GlobalDOMEvents ) {
|
|
352
|
-
for( const name in events ) {
|
|
353
|
-
this.addDOMEvent( name as any, (events as any)[name] );
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
// :: HILEVEL EVENTS ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* tool to move named events to internal event map
|
|
361
|
-
* @internal
|
|
362
|
-
*/
|
|
363
|
-
|
|
364
|
-
protected mapPropEvents<N extends keyof E>(props: P, ...elements: N[] ) {
|
|
365
|
-
const p = props as any;
|
|
366
|
-
elements.forEach( n => {
|
|
367
|
-
if (p.hasOwnProperty(n) ) {
|
|
368
|
-
this.on( n, p[n] );
|
|
369
|
-
}
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// :: CONTENT ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* remove all content from component
|
|
377
|
-
*/
|
|
378
|
-
|
|
379
|
-
clearContent( ) {
|
|
380
|
-
const d = this.dom;
|
|
381
|
-
while( d.firstChild ) {
|
|
382
|
-
d.removeChild( d.firstChild );
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* change the whole content of the component
|
|
388
|
-
* clear the content before
|
|
389
|
-
* @param content new content
|
|
390
|
-
*/
|
|
391
|
-
|
|
392
|
-
setContent( content: ComponentContent ) {
|
|
393
|
-
this.clearContent( );
|
|
394
|
-
this.appendContent( content );
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
/**
|
|
398
|
-
* cf. appendContent
|
|
399
|
-
* @param content content to append
|
|
400
|
-
*/
|
|
401
|
-
|
|
402
|
-
appendContent( content: ComponentContent ) {
|
|
403
|
-
const set = ( d: any, c: Component | string | UnsafeHtml | number | boolean ) => {
|
|
404
|
-
|
|
405
|
-
if (c instanceof Component ) {
|
|
406
|
-
d.appendChild( c.dom );
|
|
407
|
-
}
|
|
408
|
-
else if( c instanceof UnsafeHtml) {
|
|
409
|
-
d.insertAdjacentHTML( 'beforeend' , c.toString() );
|
|
410
|
-
}
|
|
411
|
-
else if (typeof c === "string" || typeof c === "number") {
|
|
412
|
-
const tnode = document.createTextNode(c.toString());
|
|
413
|
-
d.appendChild( tnode );
|
|
414
|
-
}
|
|
415
|
-
else if( c ) {
|
|
416
|
-
console.warn("Unknown type to append: ", c);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
if( !isArray(content) ) {
|
|
421
|
-
set( this.dom, content );
|
|
422
|
-
}
|
|
423
|
-
else if( content.length<=8 ) {
|
|
424
|
-
for( const c of content ) {
|
|
425
|
-
set( this.dom, c );
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
else {
|
|
429
|
-
const fragment = document.createDocumentFragment( );
|
|
430
|
-
for (const child of content ) {
|
|
431
|
-
set( fragment, child );
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
this.dom.appendChild( fragment );
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* cf. appendContent
|
|
440
|
-
* @param content content to append
|
|
441
|
-
*/
|
|
442
|
-
|
|
443
|
-
prependContent( content: ComponentContent ) {
|
|
444
|
-
const d = this.dom;
|
|
445
|
-
|
|
446
|
-
const set = ( c: Component | string | UnsafeHtml | number | boolean ) => {
|
|
447
|
-
if (c instanceof Component ) {
|
|
448
|
-
d.insertBefore( d.firstChild, c.dom );
|
|
449
|
-
}
|
|
450
|
-
else if( c instanceof UnsafeHtml) {
|
|
451
|
-
d.insertAdjacentHTML( 'beforebegin', c.toString() );
|
|
452
|
-
}
|
|
453
|
-
else if (typeof c === "string" || typeof c === "number") {
|
|
454
|
-
const tnode = document.createTextNode(c.toString());
|
|
455
|
-
d.insertBefore( d.firstChild, tnode );
|
|
456
|
-
}
|
|
457
|
-
else {
|
|
458
|
-
console.warn("Unknown type to append: ", c);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
if( !isArray(content) ) {
|
|
463
|
-
set( content );
|
|
464
|
-
}
|
|
465
|
-
else {
|
|
466
|
-
const fragment = document.createDocumentFragment( );
|
|
467
|
-
for (const child of content ) {
|
|
468
|
-
set( child );
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
d.insertBefore( d.firstChild, fragment );
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* remove a single child
|
|
477
|
-
* @see clearContent
|
|
478
|
-
*/
|
|
479
|
-
|
|
480
|
-
removeChild( child: Component ) {
|
|
481
|
-
this.dom.removeChild( child.dom );
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
/**
|
|
486
|
-
* query all elements by selector
|
|
487
|
-
*/
|
|
488
|
-
|
|
489
|
-
queryAll( selector: string ): Component[] {
|
|
490
|
-
const all = this.dom.querySelectorAll( selector );
|
|
491
|
-
const rc = new Array( all.length );
|
|
492
|
-
all.forEach( (x,i) => rc[i]=componentFromDOM(x) );
|
|
493
|
-
return rc;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
/**
|
|
497
|
-
*
|
|
498
|
-
*/
|
|
499
|
-
|
|
500
|
-
query<T extends Component = Component>( selector: string ): T {
|
|
501
|
-
const r = this.dom.querySelector( selector );
|
|
502
|
-
return componentFromDOM<T>(r);
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
// :: STYLES ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
/**
|
|
509
|
-
*
|
|
510
|
-
*/
|
|
511
|
-
|
|
512
|
-
setAria( name: keyof ariaValues, value: string | number | boolean ): this {
|
|
513
|
-
this.setAttribute( name, value );
|
|
514
|
-
return this;
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
/**
|
|
519
|
-
*
|
|
520
|
-
*/
|
|
521
|
-
|
|
522
|
-
setStyle( style: Partial<CSSStyleDeclaration> ): this {
|
|
523
|
-
const _style = (this.dom as HTMLElement).style;
|
|
524
|
-
|
|
525
|
-
for( const name in style ) {
|
|
526
|
-
|
|
527
|
-
let value = style[name];
|
|
528
|
-
if( !unitless[name] && (isNumber(value) || RE_NUMBER.test(value)) ) {
|
|
529
|
-
value += "px";
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
_style[name] = value;
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
return this;
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
/**
|
|
539
|
-
*
|
|
540
|
-
*/
|
|
541
|
-
|
|
542
|
-
setStyleValue<K extends keyof CSSStyleDeclaration>( name: K, value: CSSStyleDeclaration[K] | number ): this {
|
|
543
|
-
|
|
544
|
-
const _style = (this.dom as HTMLElement).style;
|
|
545
|
-
|
|
546
|
-
if( isNumber(value) ) {
|
|
547
|
-
let v = value+"";
|
|
548
|
-
if( !unitless[name as string] ) {
|
|
549
|
-
v += "px";
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
(_style as any)[name] = v;
|
|
553
|
-
}
|
|
554
|
-
else {
|
|
555
|
-
_style[name] = value;
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
return this;
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
/**
|
|
562
|
-
*
|
|
563
|
-
* @param name
|
|
564
|
-
* @returns
|
|
565
|
-
*/
|
|
566
|
-
|
|
567
|
-
getStyleValue<K extends keyof CSSStyleDeclaration>( name: K ) {
|
|
568
|
-
const _style = (this.dom as HTMLElement).style;
|
|
569
|
-
return _style[name];
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
setWidth( w: number | string ) {
|
|
573
|
-
this.setStyleValue( "width", isNumber(w) ? w+"px" : w );
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
setHeight( h: number | string ) {
|
|
577
|
-
this.setStyleValue( "height", isNumber(h) ? h+"px" : h );
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
/**
|
|
581
|
-
*
|
|
582
|
-
*/
|
|
583
|
-
|
|
584
|
-
setStyleVariable( name: string, value: string ) {
|
|
585
|
-
(this.dom as HTMLElement).style.setProperty( name, value );
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
/**
|
|
589
|
-
*
|
|
590
|
-
*/
|
|
591
|
-
|
|
592
|
-
getStyleVariable( name: string ) {
|
|
593
|
-
const style = this.getComputedStyle( );
|
|
594
|
-
return style.getPropertyValue( name );
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
/**
|
|
598
|
-
*
|
|
599
|
-
* @returns
|
|
600
|
-
*/
|
|
601
|
-
|
|
602
|
-
getComputedStyle( ) {
|
|
603
|
-
return getComputedStyle( this.dom );
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
/**
|
|
607
|
-
*
|
|
608
|
-
*/
|
|
609
|
-
|
|
610
|
-
setCapture( pointerId: number ) {
|
|
611
|
-
this.dom.setPointerCapture( pointerId );
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
/**
|
|
615
|
-
*
|
|
616
|
-
*/
|
|
617
|
-
|
|
618
|
-
releaseCapture( pointerId: number ) {
|
|
619
|
-
this.dom.releasePointerCapture( pointerId );
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
/**
|
|
623
|
-
*
|
|
624
|
-
*/
|
|
625
|
-
|
|
626
|
-
getBoundingRect( ): Rect {
|
|
627
|
-
const rc = this.dom.getBoundingClientRect( );
|
|
628
|
-
return new Rect( rc.x, rc.y, rc.width, rc.height );
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
// :: MISC ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
632
|
-
|
|
633
|
-
/**
|
|
634
|
-
*
|
|
635
|
-
*/
|
|
636
|
-
|
|
637
|
-
focus( ) {
|
|
638
|
-
(this.dom as HTMLElement).focus( );
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
/**
|
|
642
|
-
*
|
|
643
|
-
*/
|
|
644
|
-
|
|
645
|
-
scrollIntoView(arg?: boolean | ScrollIntoViewOptions) {
|
|
646
|
-
this.dom.scrollIntoView(arg);
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
/**
|
|
650
|
-
*
|
|
651
|
-
*/
|
|
652
|
-
|
|
653
|
-
isVisible( ) {
|
|
654
|
-
return (this.dom as HTMLElement).offsetParent !== null;
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
/**
|
|
658
|
-
*
|
|
659
|
-
*/
|
|
660
|
-
|
|
661
|
-
show( vis = true ) {
|
|
662
|
-
this.setClass( 'x4hidden', !vis );
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
/**
|
|
666
|
-
*
|
|
667
|
-
*/
|
|
668
|
-
|
|
669
|
-
hide( ) {
|
|
670
|
-
this.show( false );
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
/**
|
|
674
|
-
* enable or disable a component (all sub HTMLElement will be also disabled)
|
|
675
|
-
*/
|
|
676
|
-
|
|
677
|
-
enable( ena = true ) {
|
|
678
|
-
this.setAttribute( "disabled", !ena );
|
|
679
|
-
|
|
680
|
-
// propagate diable state to all input children
|
|
681
|
-
const nodes = this.enumChildNodes( true );
|
|
682
|
-
nodes.forEach( x => {
|
|
683
|
-
if( x instanceof HTMLInputElement ) {
|
|
684
|
-
x.disabled = !ena;
|
|
685
|
-
}
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
/**
|
|
690
|
-
*
|
|
691
|
-
*/
|
|
692
|
-
|
|
693
|
-
disable( ) {
|
|
694
|
-
this.enable( false );
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
/**
|
|
698
|
-
* check if element is marked disabled
|
|
699
|
-
*/
|
|
700
|
-
|
|
701
|
-
isDisabled( ) {
|
|
702
|
-
return this.getAttribute('disabled');
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
/**
|
|
706
|
-
*
|
|
707
|
-
*/
|
|
708
|
-
|
|
709
|
-
nextElement<T extends Component = Component>( ): T {
|
|
710
|
-
const nxt = this.dom.nextElementSibling;
|
|
711
|
-
return componentFromDOM<T>( nxt );
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
/**
|
|
715
|
-
*
|
|
716
|
-
* @returns
|
|
717
|
-
*/
|
|
718
|
-
|
|
719
|
-
prevElement<T extends Component = Component>( ): T {
|
|
720
|
-
const nxt = this.dom.previousElementSibling;
|
|
721
|
-
return componentFromDOM<T>( nxt );
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
/**
|
|
725
|
-
* search for parent that match the given contructor
|
|
726
|
-
*/
|
|
727
|
-
|
|
728
|
-
parentElement<T extends Component>( cls?: Constructor<T> ): T {
|
|
729
|
-
let p = this.dom;
|
|
730
|
-
|
|
731
|
-
while( p.parentElement ) {
|
|
732
|
-
const cp = componentFromDOM( p.parentElement );
|
|
733
|
-
if( !cls ) {
|
|
734
|
-
return cp as T;
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
if( cp && cp instanceof cls ) {
|
|
738
|
-
return cp;
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
p = p.parentElement;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
return null;
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
/**
|
|
748
|
-
*
|
|
749
|
-
* @returns
|
|
750
|
-
*/
|
|
751
|
-
|
|
752
|
-
firstChild<T extends Component = Component>( ) : T {
|
|
753
|
-
const nxt = this.dom.firstElementChild;
|
|
754
|
-
return componentFromDOM<T>( nxt );
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
/**
|
|
758
|
-
*
|
|
759
|
-
* @returns
|
|
760
|
-
*/
|
|
761
|
-
|
|
762
|
-
lastChild<T extends Component = Component>( ) : T {
|
|
763
|
-
const nxt = this.dom.lastElementChild;
|
|
764
|
-
return componentFromDOM( nxt );
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
/**
|
|
768
|
-
* renvoie la liste des Composants enfants
|
|
769
|
-
*/
|
|
770
|
-
|
|
771
|
-
enumChildComponents( recursive: boolean ) {
|
|
772
|
-
|
|
773
|
-
let children: Component[] = [];
|
|
774
|
-
|
|
775
|
-
const nodes = this.enumChildNodes( recursive );
|
|
776
|
-
nodes.forEach( ( c: Node ) => {
|
|
777
|
-
const cc = componentFromDOM( c as HTMLElement );
|
|
778
|
-
if( cc ) {
|
|
779
|
-
children.push(cc);
|
|
780
|
-
}
|
|
781
|
-
} );
|
|
782
|
-
|
|
783
|
-
return children;
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
/**
|
|
787
|
-
* return children list of node (not all should be components)
|
|
788
|
-
*/
|
|
789
|
-
|
|
790
|
-
enumChildNodes( recursive: boolean ) {
|
|
791
|
-
let children: Node[] = Array.from( recursive ? this.dom.querySelectorAll( '*' ) : this.dom.children );
|
|
792
|
-
return children;
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
/**
|
|
796
|
-
*
|
|
797
|
-
*/
|
|
798
|
-
|
|
799
|
-
animate( keyframes: Keyframe[], duration: number ) {
|
|
800
|
-
this.dom.animate(keyframes,duration);
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
// :: TSX/REACT ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
805
|
-
|
|
806
|
-
/**
|
|
807
|
-
* called by the compiler when a jsx element is seen
|
|
808
|
-
*/
|
|
809
|
-
|
|
810
|
-
static createElement( clsOrTag: string | ComponentConstructor | Symbol | Function, attrs: any, ...children: Component[] ): Component | Component[] {
|
|
811
|
-
|
|
812
|
-
let comp: Component;
|
|
813
|
-
|
|
814
|
-
// fragment
|
|
815
|
-
if( clsOrTag==this.createFragment || clsOrTag===FRAGMENT ) {
|
|
816
|
-
return children;
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
// class constructor, yes : dirty
|
|
820
|
-
if( clsOrTag instanceof Function ) {
|
|
821
|
-
attrs = attrs ?? {};
|
|
822
|
-
if( !attrs.children && children && children.length ) {
|
|
823
|
-
attrs.content = children;
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
comp = new (clsOrTag as any)( attrs ?? {} );
|
|
827
|
-
}
|
|
828
|
-
// basic tag
|
|
829
|
-
else {
|
|
830
|
-
comp = new Component( {
|
|
831
|
-
tag: clsOrTag,
|
|
832
|
-
content: children,
|
|
833
|
-
...attrs,
|
|
834
|
-
});
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
if( children && children.length ) {
|
|
838
|
-
//comp.setContent( children );
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
return comp;
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
/**
|
|
845
|
-
*
|
|
846
|
-
*/
|
|
847
|
-
|
|
848
|
-
static createFragment( ): Component[] {
|
|
849
|
-
return this.createElement( FRAGMENT, null ) as Component[];
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
// :: SPECIALS ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
853
|
-
|
|
854
|
-
/**
|
|
855
|
-
*
|
|
856
|
-
*/
|
|
857
|
-
|
|
858
|
-
queryInterface<T extends IComponmentInterface>( name: string ): T {
|
|
859
|
-
return null;
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
/**
|
|
865
|
-
*
|
|
866
|
-
*/
|
|
867
|
-
|
|
868
|
-
type ComponentConstructor = {
|
|
869
|
-
new(...params: any[]): Component;
|
|
870
|
-
};
|
|
871
|
-
|
|
872
|
-
/**
|
|
873
|
-
* get a component element from it's DOM counterpart
|
|
874
|
-
*/
|
|
875
|
-
|
|
876
|
-
export function componentFromDOM<T extends Component = Component>( node: Element ) {
|
|
877
|
-
return node ? (node as any)[COMPONENT] as T : null;
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
/**
|
|
881
|
-
* create a component from an existing DOM
|
|
882
|
-
*/
|
|
883
|
-
|
|
884
|
-
export function wrapDOM( el: HTMLElement ): Component {
|
|
885
|
-
const com = componentFromDOM(el);
|
|
886
|
-
if( com ) {
|
|
887
|
-
return com;
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
return new Component( { existingDOM: el } );
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
// :: Special components ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
895
|
-
|
|
896
|
-
// just a flexible element that push other
|
|
897
|
-
export class Flex extends Component {
|
|
898
|
-
constructor( ) {
|
|
899
|
-
super({})
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
// :: HIGH LEVEL BASIC EVENTS ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
/**
|
|
909
|
-
* Click Event
|
|
910
|
-
* click event do not have any additional parameters
|
|
911
|
-
*/
|
|
912
|
-
|
|
913
|
-
export interface EvClick extends ComponentEvent {
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
/**
|
|
917
|
-
* Change Event
|
|
918
|
-
* value is the the element value
|
|
919
|
-
*/
|
|
920
|
-
|
|
921
|
-
export interface EvChange extends ComponentEvent {
|
|
922
|
-
readonly value: any;
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
/**
|
|
926
|
-
* Selection Event
|
|
927
|
-
* value is the new selection or null
|
|
928
|
-
*/
|
|
929
|
-
|
|
930
|
-
interface ISelection {
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
export interface EvSelectionChange extends ComponentEvent {
|
|
934
|
-
readonly selection: ISelection;
|
|
935
|
-
}
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
/**
|
|
939
|
-
* ContextMenu Event
|
|
940
|
-
*/
|
|
941
|
-
|
|
942
|
-
export interface EvContextMenu extends ComponentEvent {
|
|
943
|
-
uievent: UIEvent; // UI event that fire this event
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
/**
|
|
947
|
-
* Simple message
|
|
948
|
-
*/
|
|
949
|
-
|
|
950
|
-
export interface EvMessage extends ComponentEvent {
|
|
951
|
-
readonly msg: string;
|
|
952
|
-
readonly params?: any;
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
/**
|
|
956
|
-
* Drag/Drop event
|
|
957
|
-
*/
|
|
958
|
-
|
|
959
|
-
export interface EvDrag extends ComponentEvent {
|
|
960
|
-
element: unknown;
|
|
961
|
-
data: any;
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
/**
|
|
965
|
-
* Errors
|
|
966
|
-
*/
|
|
967
|
-
|
|
968
|
-
export interface EvError extends ComponentEvent {
|
|
969
|
-
code: number;
|
|
970
|
-
message: string;
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
/**
|
|
974
|
-
* DblClick Event
|
|
975
|
-
*/
|
|
976
|
-
|
|
977
|
-
export interface EvDblClick extends ComponentEvent {
|
|
978
|
-
}
|
|
979
|
-
|