x4js 1.6.4 → 2.0.1
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/README.md +3 -14
- package/lib/README.txt +3 -14
- package/lib/src/assets/house-light.svg +1 -0
- package/lib/src/assets/radio.svg +4 -0
- package/lib/src/components/base.scss +26 -0
- package/lib/src/components/boxes/boxes.module.scss +37 -0
- package/lib/src/components/boxes/boxes.ts +125 -0
- package/lib/src/components/btngroup/btngroup.module.scss +29 -0
- package/lib/src/components/btngroup/btngroup.ts +106 -0
- package/lib/src/components/button/button.module.scss +154 -0
- package/lib/src/components/button/button.ts +117 -0
- package/lib/src/components/calendar/calendar-check-sharp-light.svg +1 -0
- package/lib/src/components/calendar/calendar.module.scss +163 -0
- package/lib/src/{calendar.ts → components/calendar/calendar.ts} +81 -83
- package/lib/src/components/calendar/chevron-left-sharp-light.svg +1 -0
- package/lib/src/components/calendar/chevron-right-sharp-light.svg +1 -0
- package/lib/src/components/checkbox/check.svg +4 -0
- package/lib/src/components/checkbox/checkbox.module.scss +142 -0
- package/lib/src/components/checkbox/checkbox.ts +125 -0
- package/lib/src/components/colorinput/colorinput.module.scss +65 -0
- package/lib/src/components/colorinput/colorinput.ts +88 -0
- package/lib/src/components/colorinput/crosshairs-simple-sharp-light.svg +1 -0
- package/lib/src/components/colorpicker/colorpicker.module.scss +133 -0
- package/lib/src/components/colorpicker/colorpicker.ts +477 -0
- package/lib/src/components/combobox/combobox.module.scss +121 -0
- package/lib/src/components/combobox/combobox.ts +190 -0
- package/lib/src/components/combobox/updown.svg +4 -0
- package/lib/src/components/dialog/dialog.module.scss +71 -0
- package/lib/src/components/dialog/dialog.ts +91 -0
- package/lib/src/components/dialog/xmark-sharp-light.svg +1 -0
- package/lib/src/components/form/form.module.scss +34 -0
- package/lib/src/components/form/form.ts +36 -0
- package/lib/src/components/header/header.module.scss +40 -0
- package/lib/src/components/header/header.ts +124 -0
- package/lib/src/components/icon/icon.module.scss +30 -0
- package/lib/src/components/icon/icon.ts +134 -0
- package/lib/src/components/image/image.module.scss +21 -0
- package/lib/src/components/image/image.ts +67 -0
- package/lib/src/components/input/input.module.scss +69 -0
- package/lib/src/components/input/input.ts +274 -0
- package/lib/src/components/label/label.module.scss +52 -0
- package/lib/src/components/label/label.ts +55 -0
- package/lib/src/components/listbox/listbox.module.scss +103 -0
- package/lib/src/components/listbox/listbox.ts +427 -0
- package/lib/src/components/menu/caret-right-solid.svg +1 -0
- package/lib/src/components/menu/menu.module.scss +108 -0
- package/lib/src/components/menu/menu.ts +168 -0
- package/lib/src/components/messages/circle-exclamation.svg +1 -0
- package/lib/src/components/messages/messages.module.scss +47 -0
- package/lib/src/components/messages/messages.ts +64 -0
- package/lib/src/components/normalize.scss +386 -0
- package/lib/src/components/notification/circle-check-solid.svg +1 -0
- package/lib/src/components/notification/circle-exclamation-solid.svg +1 -0
- package/lib/src/components/notification/circle-notch-light.svg +1 -0
- package/lib/src/components/notification/notification.module.scss +82 -0
- package/lib/src/components/notification/notification.ts +108 -0
- package/lib/src/components/notification/xmark-sharp-light.svg +1 -0
- package/lib/src/components/panel/panel.module.scss +48 -0
- package/lib/src/components/panel/panel.ts +57 -0
- package/lib/src/components/popup/popup.module.scss +43 -0
- package/lib/src/components/popup/popup.ts +395 -0
- package/lib/src/components/progress/progress.module.scss +57 -0
- package/lib/src/components/progress/progress.ts +43 -0
- package/lib/src/components/rating/rating.module.scss +23 -0
- package/lib/src/components/rating/rating.ts +125 -0
- package/lib/src/components/rating/star-sharp-light.svg +1 -0
- package/lib/src/components/rating/star-sharp-solid.svg +1 -0
- package/lib/src/components/shared.scss +76 -0
- package/lib/src/components/sizers/sizer.module.scss +90 -0
- package/lib/src/components/sizers/sizer.ts +120 -0
- package/lib/src/components/slider/slider.module.scss +71 -0
- package/lib/src/components/slider/slider.ts +143 -0
- package/lib/src/components/switch/switch.module.scss +127 -0
- package/lib/src/components/switch/switch.ts +56 -0
- package/lib/src/components/tabs/tabs.module.scss +46 -0
- package/lib/src/components/tabs/tabs.ts +157 -0
- package/lib/src/components/textarea/textarea.module.scss +59 -0
- package/lib/src/components/textarea/textarea.ts +54 -0
- package/lib/src/components/textedit/textedit.module.scss +114 -0
- package/lib/src/components/textedit/textedit.ts +82 -0
- package/lib/src/components/themes.scss +77 -0
- package/lib/src/components/tooltips/circle-info-sharp-light.svg +1 -0
- package/lib/src/components/tooltips/tooltips.scss +51 -0
- package/lib/src/components/tooltips/tooltips.ts +103 -0
- package/lib/src/components/treeview/chevron-down-light.svg +1 -0
- package/lib/src/components/treeview/treeview.module.scss +116 -0
- package/lib/src/components/treeview/treeview.ts +403 -0
- package/lib/src/components/viewport/viewport.module.scss +25 -0
- package/lib/src/components/viewport/viewport.ts +38 -0
- package/lib/src/core/component.ts +979 -0
- package/lib/src/core/core_colors.ts +250 -0
- package/lib/src/{dom_events.ts → core/core_dom.ts} +195 -39
- package/lib/src/{drag_manager.ts → core/core_dragdrop.ts} +29 -44
- package/lib/src/core/core_element.ts +98 -0
- package/lib/src/core/core_events.ts +149 -0
- package/lib/src/{i18n.ts → core/core_i18n.ts} +43 -42
- package/lib/src/{router.ts → core/core_router.ts} +27 -40
- package/lib/src/core/core_styles.ts +215 -0
- package/lib/src/core/core_svg.ts +550 -0
- package/lib/src/core/core_tools.ts +673 -0
- package/lib/src/main.scss +21 -0
- package/lib/src/main.tsx +323 -0
- package/lib/src/x4.scss +19 -0
- package/lib/types/x4.d.ts +2624 -0
- package/package.json +67 -59
- package/scripts/build.mjs +351 -0
- package/scripts/prepack.mjs +15 -0
- package/src/assets/house-light.svg +1 -0
- package/src/assets/radio.svg +4 -0
- package/src/components/base.scss +26 -0
- package/src/components/boxes/boxes.module.scss +37 -0
- package/src/components/boxes/boxes.ts +125 -0
- package/src/components/btngroup/btngroup.module.scss +29 -0
- package/src/components/btngroup/btngroup.ts +106 -0
- package/src/components/button/button.module.scss +154 -0
- package/src/components/button/button.ts +117 -0
- package/src/components/calendar/calendar-check-sharp-light.svg +1 -0
- package/src/components/calendar/calendar.module.scss +163 -0
- package/src/components/calendar/calendar.ts +326 -0
- package/src/components/calendar/chevron-left-sharp-light.svg +1 -0
- package/src/components/calendar/chevron-right-sharp-light.svg +1 -0
- package/src/components/checkbox/check.svg +4 -0
- package/src/components/checkbox/checkbox.module.scss +142 -0
- package/src/components/checkbox/checkbox.ts +125 -0
- package/src/components/colorinput/colorinput.module.scss +65 -0
- package/src/components/colorinput/colorinput.ts +88 -0
- package/src/components/colorinput/crosshairs-simple-sharp-light.svg +1 -0
- package/src/components/colorpicker/colorpicker.module.scss +133 -0
- package/src/components/colorpicker/colorpicker.ts +477 -0
- package/src/components/combobox/combobox.module.scss +121 -0
- package/src/components/combobox/combobox.ts +190 -0
- package/src/components/combobox/updown.svg +4 -0
- package/src/components/dialog/dialog.module.scss +71 -0
- package/src/components/dialog/dialog.ts +91 -0
- package/src/components/dialog/xmark-sharp-light.svg +1 -0
- package/src/components/form/form.module.scss +34 -0
- package/src/components/form/form.ts +36 -0
- package/src/components/header/header.module.scss +40 -0
- package/src/components/header/header.ts +124 -0
- package/src/components/icon/icon.module.scss +30 -0
- package/src/components/icon/icon.ts +134 -0
- package/src/components/image/image.module.scss +21 -0
- package/src/components/image/image.ts +67 -0
- package/src/components/input/input.module.scss +69 -0
- package/src/components/input/input.ts +274 -0
- package/src/components/label/label.module.scss +52 -0
- package/src/components/label/label.ts +55 -0
- package/src/components/listbox/listbox.module.scss +103 -0
- package/src/components/listbox/listbox.ts +427 -0
- package/src/components/menu/caret-right-solid.svg +1 -0
- package/src/components/menu/menu.module.scss +108 -0
- package/src/components/menu/menu.ts +168 -0
- package/src/components/messages/circle-exclamation.svg +1 -0
- package/src/components/messages/messages.module.scss +47 -0
- package/src/components/messages/messages.ts +64 -0
- package/src/components/normalize.scss +386 -0
- package/src/components/notification/circle-check-solid.svg +1 -0
- package/src/components/notification/circle-exclamation-solid.svg +1 -0
- package/src/components/notification/circle-notch-light.svg +1 -0
- package/src/components/notification/notification.module.scss +82 -0
- package/src/components/notification/notification.ts +108 -0
- package/src/components/notification/xmark-sharp-light.svg +1 -0
- package/src/components/panel/panel.module.scss +48 -0
- package/src/components/panel/panel.ts +57 -0
- package/src/components/popup/popup.module.scss +43 -0
- package/src/components/popup/popup.ts +395 -0
- package/src/components/progress/progress.module.scss +57 -0
- package/src/components/progress/progress.ts +43 -0
- package/src/components/rating/rating.module.scss +23 -0
- package/src/components/rating/rating.ts +125 -0
- package/src/components/rating/star-sharp-light.svg +1 -0
- package/src/components/rating/star-sharp-solid.svg +1 -0
- package/src/components/shared.scss +76 -0
- package/src/components/sizers/sizer.module.scss +90 -0
- package/src/components/sizers/sizer.ts +120 -0
- package/src/components/slider/slider.module.scss +71 -0
- package/src/components/slider/slider.ts +143 -0
- package/src/components/switch/switch.module.scss +127 -0
- package/src/components/switch/switch.ts +56 -0
- package/src/components/tabs/tabs.module.scss +46 -0
- package/src/components/tabs/tabs.ts +157 -0
- package/src/components/textarea/textarea.module.scss +59 -0
- package/src/components/textarea/textarea.ts +54 -0
- package/src/components/textedit/textedit.module.scss +114 -0
- package/src/components/textedit/textedit.ts +82 -0
- package/src/components/themes.scss +77 -0
- package/src/components/tooltips/circle-info-sharp-light.svg +1 -0
- package/src/components/tooltips/tooltips.scss +51 -0
- package/src/components/tooltips/tooltips.ts +103 -0
- package/src/components/treeview/chevron-down-light.svg +1 -0
- package/src/components/treeview/treeview.module.scss +116 -0
- package/src/components/treeview/treeview.ts +403 -0
- package/src/components/viewport/viewport.module.scss +25 -0
- package/src/components/viewport/viewport.ts +38 -0
- package/src/core/component.ts +979 -0
- package/src/core/core_colors.ts +250 -0
- package/src/core/core_dom.ts +471 -0
- package/src/core/core_dragdrop.ts +201 -0
- package/src/core/core_element.ts +98 -0
- package/src/core/core_events.ts +149 -0
- package/src/core/core_i18n.ts +377 -0
- package/src/core/core_router.ts +221 -0
- package/src/core/core_styles.ts +215 -0
- package/src/core/core_svg.ts +550 -0
- package/src/core/core_tools.ts +673 -0
- package/src/main.scss +21 -0
- package/src/main.tsx +323 -0
- package/src/x4.scss +19 -0
- package/tsconfig.json +14 -0
- package/types/scss.d.ts +4 -0
- package/types/svg.d.ts +4 -0
- package/types/x4react.d.ts +9 -0
- package/lib/changelog.txt +0 -23
- package/lib/cjs/x4js.js +0 -39
- package/lib/cjs/x4js.js.map +0 -7
- package/lib/esm/x4js.mjs +0 -15972
- package/lib/esm/x4js.mjs.map +0 -7
- package/lib/licence.md +0 -21
- package/lib/src/MIT-license.md +0 -14
- package/lib/src/action.ts +0 -88
- package/lib/src/alpha.jpg +0 -0
- package/lib/src/app_sockets.ts +0 -81
- package/lib/src/application.ts +0 -262
- package/lib/src/autocomplete.ts +0 -232
- package/lib/src/base64.ts +0 -166
- package/lib/src/base_component.ts +0 -152
- package/lib/src/button.ts +0 -355
- package/lib/src/canvas.ts +0 -510
- package/lib/src/cardview.ts +0 -228
- package/lib/src/checkbox.ts +0 -188
- package/lib/src/color.ts +0 -752
- package/lib/src/colorpicker.ts +0 -1649
- package/lib/src/combobox.ts +0 -512
- package/lib/src/component.ts +0 -2367
- package/lib/src/copyright.txt +0 -27
- package/lib/src/datastore.ts +0 -1302
- package/lib/src/dialog.ts +0 -656
- package/lib/src/drawtext.ts +0 -355
- package/lib/src/fileupload.ts +0 -213
- package/lib/src/form.ts +0 -413
- package/lib/src/formatters.ts +0 -105
- package/lib/src/gridview.ts +0 -1185
- package/lib/src/icon.ts +0 -362
- package/lib/src/image.ts +0 -225
- package/lib/src/index.ts +0 -89
- package/lib/src/input.ts +0 -297
- package/lib/src/label.ts +0 -153
- package/lib/src/layout.ts +0 -442
- package/lib/src/link.ts +0 -86
- package/lib/src/listview.ts +0 -765
- package/lib/src/md5.ts +0 -438
- package/lib/src/menu.ts +0 -425
- package/lib/src/messagebox.ts +0 -224
- package/lib/src/panel.ts +0 -86
- package/lib/src/popup.ts +0 -494
- package/lib/src/property_editor.ts +0 -337
- package/lib/src/radiobtn.ts +0 -197
- package/lib/src/rating.ts +0 -135
- package/lib/src/request.ts +0 -300
- package/lib/src/settings.ts +0 -77
- package/lib/src/sidebarview.ts +0 -108
- package/lib/src/spreadsheet.ts +0 -1449
- package/lib/src/styles.ts +0 -343
- package/lib/src/svgcomponent.ts +0 -592
- package/lib/src/tabbar.ts +0 -151
- package/lib/src/tabview.ts +0 -110
- package/lib/src/textarea.ts +0 -235
- package/lib/src/textedit.ts +0 -533
- package/lib/src/toaster.ts +0 -80
- package/lib/src/tools.ts +0 -1473
- package/lib/src/tooltips.ts +0 -191
- package/lib/src/treeview.ts +0 -716
- package/lib/src/version.ts +0 -30
- package/lib/src/x4.less +0 -2242
- package/lib/src/x4dom.ts +0 -57
- package/lib/src/x4events.ts +0 -585
- package/lib/src/x4js.ts +0 -89
- package/lib/src/x4react.ts +0 -90
- package/lib/styles/x4.css +0 -1785
- package/lib/styles/x4.less +0 -2242
- package/lib/types/x4js.d.ts +0 -6728
- package/license.md +0 -21
package/lib/src/x4dom.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \_/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / _ \____ _|
|
|
6
|
-
* /__/ \__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file x4events.ts
|
|
9
|
-
* @author Etienne Cochard
|
|
10
|
-
*
|
|
11
|
-
* Copyright (c) 2019-2023 R-libre ingenierie
|
|
12
|
-
*
|
|
13
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
-
* in the Software without restriction, including without limitation the rights
|
|
16
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
17
|
-
* of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
18
|
-
* subject to the following conditions:
|
|
19
|
-
* The above copyright notice and this permission notice shall be included in all copies
|
|
20
|
-
* or substantial portions of the Software.
|
|
21
|
-
*
|
|
22
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
23
|
-
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
24
|
-
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
25
|
-
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
26
|
-
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
27
|
-
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
28
|
-
**/
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* SSR preparation
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
interface IX4Document {
|
|
35
|
-
createElement<K extends keyof HTMLElementTagNameMap>(tagName: K, options?: ElementCreationOptions): HTMLElementTagNameMap[K];
|
|
36
|
-
createElementNS(namespace: string | null, qualifiedName: string, options?: string | ElementCreationOptions): Element;
|
|
37
|
-
createTextNode(data: string): Text;
|
|
38
|
-
|
|
39
|
-
addEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
40
|
-
removeEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
|
|
41
|
-
|
|
42
|
-
querySelectorAll<E extends Element = Element>(selectors: string): NodeListOf<E>;
|
|
43
|
-
querySelector<E extends Element = Element>(selectors: string): E | null;
|
|
44
|
-
|
|
45
|
-
get body( ) : HTMLElement;
|
|
46
|
-
get activeElement( ): Element;
|
|
47
|
-
get location( ): Location;
|
|
48
|
-
get styleSheets( ): StyleSheetList;
|
|
49
|
-
get head( ): HTMLHeadElement;
|
|
50
|
-
get documentElement( ): HTMLElement;
|
|
51
|
-
|
|
52
|
-
set title( title: string );
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
export let x4document: IX4Document = document;
|
|
57
|
-
|
package/lib/src/x4events.ts
DELETED
|
@@ -1,585 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \_/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / _ \____ _|
|
|
6
|
-
* /__/ \__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file x4events.ts
|
|
9
|
-
* @author Etienne Cochard
|
|
10
|
-
*
|
|
11
|
-
* Copyright (c) 2019-2023 R-libre ingenierie
|
|
12
|
-
*
|
|
13
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
-
* in the Software without restriction, including without limitation the rights
|
|
16
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
17
|
-
* of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
18
|
-
* subject to the following conditions:
|
|
19
|
-
* The above copyright notice and this permission notice shall be included in all copies
|
|
20
|
-
* or substantial portions of the Software.
|
|
21
|
-
*
|
|
22
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
23
|
-
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
24
|
-
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
25
|
-
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
26
|
-
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
27
|
-
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
28
|
-
**/
|
|
29
|
-
|
|
30
|
-
// default stopPropagation implementation for Events
|
|
31
|
-
const stopPropagation = function ( this: any ) {
|
|
32
|
-
this.propagationStopped = true;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// default preventDefault implementation for Events
|
|
36
|
-
const preventDefault = function ( this: any ) {
|
|
37
|
-
this.defaultPrevented = true;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// default callback type for events
|
|
41
|
-
export type EventCallback<T extends BasicEvent = BasicEvent> = (event: T) => any;
|
|
42
|
-
export interface EventDisposer {
|
|
43
|
-
dispose( ) : void;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Basic event
|
|
49
|
-
* name like that to avoid conflict with Browsers Event class.
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
export interface BasicEvent {
|
|
53
|
-
readonly type?: string; // type of the event 'click', 'change', ...
|
|
54
|
-
readonly source?: unknown; // object that fires the event
|
|
55
|
-
readonly context?: any; // contextual data, left to the user
|
|
56
|
-
|
|
57
|
-
propagationStopped?: boolean; // if true, do not propagate the event
|
|
58
|
-
defaultPrevented?: boolean; // if true, do not call default handler (if any)
|
|
59
|
-
|
|
60
|
-
stopPropagation?(): void; // stop the propagation
|
|
61
|
-
preventDefault?(): void; // prevent the default handler
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* BasicEvent Builder
|
|
66
|
-
* this function is responsable of BasicEvent creation
|
|
67
|
-
* ie. is equivalent of new BasicEvent( xxx );
|
|
68
|
-
* @param params
|
|
69
|
-
* @returns BasicEvent
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
export function BasicEvent<T extends BasicEvent = BasicEvent>(params: any): T {
|
|
73
|
-
return {
|
|
74
|
-
stopPropagation,
|
|
75
|
-
preventDefault,
|
|
76
|
-
...params,
|
|
77
|
-
} as T;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Click Event
|
|
82
|
-
* click event do not have any additional parameters
|
|
83
|
-
*/
|
|
84
|
-
|
|
85
|
-
export interface EvClick extends BasicEvent {
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function EvClick( context: any = null ) {
|
|
89
|
-
return BasicEvent<EvClick>({ context });
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Change Event
|
|
95
|
-
* value is the the element value
|
|
96
|
-
*/
|
|
97
|
-
|
|
98
|
-
export interface EvChange extends BasicEvent {
|
|
99
|
-
readonly value: any;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export function EvChange(value: unknown, context: any = null ) {
|
|
103
|
-
return BasicEvent<EvChange>({ value, context });
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Selection Event
|
|
108
|
-
* value is the new selection or null
|
|
109
|
-
*/
|
|
110
|
-
|
|
111
|
-
interface X4Selection {
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export interface EvSelectionChange extends BasicEvent {
|
|
115
|
-
readonly selection: X4Selection;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export function EvSelectionChange( selection: X4Selection, context: any = null ) {
|
|
119
|
-
return BasicEvent<EvSelectionChange>( { selection, context } );
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* ContextMenu Event
|
|
124
|
-
*/
|
|
125
|
-
|
|
126
|
-
export interface EvContextMenu extends BasicEvent {
|
|
127
|
-
uievent: UIEvent; // UI event that fire this event
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function EvContextMenu( uievent: UIEvent, context: any = null ) {
|
|
131
|
-
return BasicEvent<EvContextMenu>( { uievent, context } );
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Timer Event
|
|
136
|
-
* @see startTimer, stopTimer
|
|
137
|
-
*/
|
|
138
|
-
|
|
139
|
-
export interface EvTimer extends BasicEvent {
|
|
140
|
-
timer: string;
|
|
141
|
-
time: number;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export function EvTimer( timer: string, time = 0, context: any = null ) {
|
|
145
|
-
return BasicEvent<EvTimer>( { timer, time, context });
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Simple message
|
|
150
|
-
*/
|
|
151
|
-
|
|
152
|
-
export interface EvMessage extends BasicEvent {
|
|
153
|
-
readonly msg: string;
|
|
154
|
-
readonly params?: any;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export function EvMessage( msg: string, params?: unknown, source?: unknown ) {
|
|
158
|
-
return BasicEvent<EvMessage>({msg,params,source});
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Drag/Drop event
|
|
163
|
-
*/
|
|
164
|
-
|
|
165
|
-
export interface EvDrag extends BasicEvent {
|
|
166
|
-
element: unknown;
|
|
167
|
-
data: any;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export function EvDrag(element: unknown, data: any, ctx: any ) {
|
|
171
|
-
return BasicEvent<EvDrag>({ element, data, context: ctx });
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Errors
|
|
176
|
-
*/
|
|
177
|
-
|
|
178
|
-
export interface EvError extends BasicEvent {
|
|
179
|
-
code: number;
|
|
180
|
-
message: string;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export function EvError( code: number, message: string ) : EvError {
|
|
184
|
-
return BasicEvent<EvError>( {code, message} );
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* this Base interface is used to describe available events & their types
|
|
190
|
-
*
|
|
191
|
-
* you can implement your own event mapping:
|
|
192
|
-
* @example
|
|
193
|
-
* ```ts
|
|
194
|
-
* interface MyEventMap extends EventMap {
|
|
195
|
-
* click: EvClick,
|
|
196
|
-
* 'custom-message': Event,
|
|
197
|
-
* [key: string]: Event,
|
|
198
|
-
* }
|
|
199
|
-
* ```
|
|
200
|
-
*/
|
|
201
|
-
|
|
202
|
-
export interface EventMap {
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* basic event types, in general the type is builded from the eventMap
|
|
207
|
-
* this is very usefull for editor completion
|
|
208
|
-
* @example
|
|
209
|
-
* ```ts
|
|
210
|
-
* type MyEventType = MapEvents<MyEventMap>;
|
|
211
|
-
* ```
|
|
212
|
-
*/
|
|
213
|
-
export interface EventTypes {
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* convert an EventMap to a EventType
|
|
218
|
-
*/
|
|
219
|
-
|
|
220
|
-
export type MapEvents<Type> = {
|
|
221
|
-
[Property in keyof Type]?: (ev: Type[Property]) => any;
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Event emitter class
|
|
227
|
-
* this class allow you to emit and handle events
|
|
228
|
-
*
|
|
229
|
-
* @example:
|
|
230
|
-
* ```ts
|
|
231
|
-
*
|
|
232
|
-
* interface EvDoIt extends BasicEvent {
|
|
233
|
-
* param: unknown;
|
|
234
|
-
* }
|
|
235
|
-
*
|
|
236
|
-
* function EvDoIt( e: EvDoIt ) : EvDoIt {
|
|
237
|
-
* return BasicEvent<EvDoIt>( e );
|
|
238
|
-
* }
|
|
239
|
-
*
|
|
240
|
-
* interface TestEventMap extends EventMap {
|
|
241
|
-
* doit: EvDoIt;
|
|
242
|
-
* }
|
|
243
|
-
*
|
|
244
|
-
* let ee = new EventSource<TestEventMap>(null);
|
|
245
|
-
* ee.listen({
|
|
246
|
-
* doit: (e) => {
|
|
247
|
-
* console.log(e);
|
|
248
|
-
* e.preventDefault();
|
|
249
|
-
* },
|
|
250
|
-
* });
|
|
251
|
-
*
|
|
252
|
-
* ee.defaults({
|
|
253
|
-
* doit: (e) => {
|
|
254
|
-
* console.log('default handler for ', e.type, e.selection);
|
|
255
|
-
* },
|
|
256
|
-
* })
|
|
257
|
-
*
|
|
258
|
-
* ee.on('doit', (e) => {
|
|
259
|
-
* debugger;
|
|
260
|
-
* })
|
|
261
|
-
*
|
|
262
|
-
* const ev = EvDoIt({ param: 10 });
|
|
263
|
-
* ee.emit('change', ev);
|
|
264
|
-
* if (ev.defaultPrevented) {
|
|
265
|
-
* console.log('prevented');
|
|
266
|
-
* }
|
|
267
|
-
* ```
|
|
268
|
-
*/
|
|
269
|
-
|
|
270
|
-
export class EventSource<Q extends EventMap, T extends EventTypes = MapEvents<Q>> {
|
|
271
|
-
|
|
272
|
-
private m_source: unknown;
|
|
273
|
-
private m_eventRegistry: Map<string, EventCallback[]>;
|
|
274
|
-
private m_defaultHandlers: Map<string, EventCallback[]>;
|
|
275
|
-
|
|
276
|
-
constructor(source: unknown = null) {
|
|
277
|
-
this.m_source = source ?? this;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* emit an event
|
|
282
|
-
* you can stop propagation of event or prevent default
|
|
283
|
-
* @param eventName - name of event to emit
|
|
284
|
-
* @param event - event data
|
|
285
|
-
*/
|
|
286
|
-
|
|
287
|
-
emit<K extends keyof Q>(type: K, event?: Q[K]) {
|
|
288
|
-
this._emit(type as string, event);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
_emit(eventName: string, e: BasicEvent): void {
|
|
292
|
-
let listeners = this.m_eventRegistry?.get(eventName);
|
|
293
|
-
const defaultHandler = this.m_defaultHandlers?.get(eventName);
|
|
294
|
-
|
|
295
|
-
if (!e) {
|
|
296
|
-
e = {};
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
if (!e.source) {
|
|
300
|
-
(e as any).source = this.m_source;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
if (!e.type) {
|
|
304
|
-
(e as any).type = eventName;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
if (listeners && listeners.length) {
|
|
308
|
-
|
|
309
|
-
if (!e.preventDefault) {
|
|
310
|
-
e.preventDefault = preventDefault;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
if (!e.stopPropagation) {
|
|
314
|
-
e.stopPropagation = stopPropagation;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// small optimisation
|
|
318
|
-
if (listeners.length == 1) {
|
|
319
|
-
listeners[0](e);
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
const temp = listeners.slice();
|
|
323
|
-
for (let i = 0, n = temp.length; i < n; i++) {
|
|
324
|
-
temp[i](e);
|
|
325
|
-
if (e.propagationStopped) {
|
|
326
|
-
break;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
if (defaultHandler && defaultHandler.length && !e.defaultPrevented) {
|
|
333
|
-
return defaultHandler[0](e);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* signal en event
|
|
339
|
-
* signaled event are notification : no way to prevent default not stop propagation
|
|
340
|
-
* @param eventName name of event to signal
|
|
341
|
-
* @param event event data
|
|
342
|
-
*/
|
|
343
|
-
|
|
344
|
-
signal<K extends keyof Q>(type: K, event: Q[K], delay=-1) {
|
|
345
|
-
this._signal(type as string, event,delay);
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
_signal(eventName: string, e: BasicEvent,delay=-1): void {
|
|
349
|
-
|
|
350
|
-
if (!this.m_eventRegistry) {
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
const listeners = this.m_eventRegistry.get(eventName);
|
|
355
|
-
if (!listeners || !listeners.length ) {
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
if (!e) {
|
|
360
|
-
e = {};
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
if (!e.type) {
|
|
364
|
-
(e as any).type = eventName;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
if (!e.source) {
|
|
368
|
-
(e as any).source = this.m_source;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
e.preventDefault = e.stopPropagation = () => {
|
|
372
|
-
console.error('this event cannot be stopped not default prevented');
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
// small optimisation
|
|
376
|
-
if (listeners.length == 1 && delay==-1 ) {
|
|
377
|
-
listeners[0](e);
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
const temp = listeners.slice();
|
|
381
|
-
|
|
382
|
-
const call = ( ) => {
|
|
383
|
-
for (let i = 0, n = temp.length; i < n; i++) {
|
|
384
|
-
temp[i](e);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
if( delay==-1 ) {
|
|
389
|
-
call( );
|
|
390
|
-
}
|
|
391
|
-
else {
|
|
392
|
-
setTimeout( call, delay );
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
/**
|
|
398
|
-
* handle an event one time
|
|
399
|
-
* @param eventName - event name to handle
|
|
400
|
-
* @param callback - callback to call when event is signaled
|
|
401
|
-
* @returns Promise if callback is null
|
|
402
|
-
*
|
|
403
|
-
* take care with that because if the event is never fired and you await it,
|
|
404
|
-
* the system may overflow
|
|
405
|
-
*/
|
|
406
|
-
|
|
407
|
-
once<K extends keyof Q>(type: K, callback: (ev: Q[K]) => any) {
|
|
408
|
-
//@ts-ignore
|
|
409
|
-
this._once(type as string, callback);
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
_once(eventName: string, callback: EventCallback) {
|
|
413
|
-
|
|
414
|
-
const newCallback = ( ev: BasicEvent ) => {
|
|
415
|
-
this._off(eventName, newCallback);
|
|
416
|
-
callback( ev );
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
this._on(eventName, newCallback);
|
|
420
|
-
|
|
421
|
-
if (!callback) {
|
|
422
|
-
return new Promise(function (resolve) {
|
|
423
|
-
callback = resolve;
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
* set the event default handler
|
|
430
|
-
* @param eventName - name of the event
|
|
431
|
-
* @param callback - callback to call when the event is not handled (and preventDeault has not been called)
|
|
432
|
-
*/
|
|
433
|
-
|
|
434
|
-
setDefaultHandler(eventName: string, callback: EventCallback): void {
|
|
435
|
-
|
|
436
|
-
let handlers = this.m_defaultHandlers;
|
|
437
|
-
if (!handlers) {
|
|
438
|
-
handlers = this.m_defaultHandlers = new Map()
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
let stack = handlers.get(eventName);
|
|
442
|
-
if (stack) {
|
|
443
|
-
|
|
444
|
-
// if already in the stack, remove it
|
|
445
|
-
const idx = stack.indexOf(callback);
|
|
446
|
-
if (idx != -1) {
|
|
447
|
-
stack.splice(idx, 1);
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
// then make it first
|
|
451
|
-
stack.unshift(callback);
|
|
452
|
-
}
|
|
453
|
-
else {
|
|
454
|
-
handlers.set(eventName, [callback]);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* remove the previous default handler installed for an event
|
|
460
|
-
* @param eventName - event name
|
|
461
|
-
* @param callback - callback handler to remove (must be the same as in setDefaultHandler)
|
|
462
|
-
*/
|
|
463
|
-
|
|
464
|
-
removeDefaultHandler(eventName: string, callback: EventCallback): void {
|
|
465
|
-
const handlers = this.m_defaultHandlers;
|
|
466
|
-
if (!handlers) {
|
|
467
|
-
return;
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
const stack = handlers.get(eventName);
|
|
471
|
-
if (stack) {
|
|
472
|
-
const idx = stack.indexOf(callback);
|
|
473
|
-
if (idx != -1) {
|
|
474
|
-
stack.splice(idx, 1);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* define a set of listeners in one call
|
|
481
|
-
* @param events
|
|
482
|
-
*/
|
|
483
|
-
|
|
484
|
-
listen(events: T) {
|
|
485
|
-
for (let n in events) {
|
|
486
|
-
this._on(n, events[n] as unknown as EventCallback);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
/**
|
|
491
|
-
* define a set of default handlers in one call
|
|
492
|
-
* @param events
|
|
493
|
-
*/
|
|
494
|
-
|
|
495
|
-
defaults(events: T) {
|
|
496
|
-
for (let n in events) {
|
|
497
|
-
this.setDefaultHandler(n, events[n] as unknown as EventCallback);
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
/**
|
|
502
|
-
* listen for an event
|
|
503
|
-
* @param eventName - event name to listen on
|
|
504
|
-
* @param callback - callback to call
|
|
505
|
-
* @param capturing - if true, capture event before other registred event handlers
|
|
506
|
-
*/
|
|
507
|
-
|
|
508
|
-
on<K extends keyof Q>(type: K, callback: (ev: Q[K]) => any) : EventDisposer {
|
|
509
|
-
//@ts-ignore
|
|
510
|
-
return this._on(type as string, callback);
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
_on(eventName: string, callback: EventCallback, capturing = false): EventDisposer {
|
|
514
|
-
|
|
515
|
-
if (!this.m_eventRegistry) {
|
|
516
|
-
this.m_eventRegistry = new Map();
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
let listeners = this.m_eventRegistry.get(eventName);
|
|
520
|
-
if (!listeners) {
|
|
521
|
-
listeners = [];
|
|
522
|
-
this.m_eventRegistry.set(eventName, listeners);
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
if (listeners.indexOf(callback) == -1) {
|
|
526
|
-
if (capturing) {
|
|
527
|
-
listeners.unshift(callback);
|
|
528
|
-
}
|
|
529
|
-
else {
|
|
530
|
-
listeners.push(callback);
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
return {
|
|
535
|
-
dispose: ( ) => { this._off( eventName, callback ); }
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
/**
|
|
540
|
-
* stop listening to an event
|
|
541
|
-
* @param eventName - event name
|
|
542
|
-
* @param callback - callback to remove (must be the same as in on )
|
|
543
|
-
*/
|
|
544
|
-
|
|
545
|
-
off<K extends keyof Q>(type: K, callback: (ev: Q[K]) => any) {
|
|
546
|
-
//@ts-ignore
|
|
547
|
-
return this._off(type as string, callback);
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
_off(eventName: string, callback: EventCallback ): void {
|
|
551
|
-
if (!this.m_eventRegistry) {
|
|
552
|
-
return;
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
let listeners = this.m_eventRegistry.get(eventName);
|
|
556
|
-
if (!listeners) {
|
|
557
|
-
return;
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
const idx = listeners.indexOf(callback);
|
|
561
|
-
if (idx !== -1) {
|
|
562
|
-
listeners.splice(idx, 1);
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
/**
|
|
567
|
-
* remove all listeners for an event
|
|
568
|
-
* @param eventName - event name
|
|
569
|
-
*/
|
|
570
|
-
|
|
571
|
-
removeAllListeners(eventName: string ): void {
|
|
572
|
-
if (!eventName) {
|
|
573
|
-
this.m_eventRegistry = this.m_defaultHandlers = undefined;
|
|
574
|
-
}
|
|
575
|
-
else {
|
|
576
|
-
if (this.m_eventRegistry) {
|
|
577
|
-
this.m_eventRegistry.delete( eventName );
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
if (this.m_defaultHandlers) {
|
|
581
|
-
this.m_defaultHandlers.delete( eventName );
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
}
|