x4js 1.5.17 → 1.5.20

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.
Files changed (242) hide show
  1. package/lib/{README.md → README.txt} +0 -0
  2. package/lib/cjs/index.js +39 -103
  3. package/lib/cjs/index.js.map +7 -0
  4. package/lib/esm/index.mjs +39 -87
  5. package/lib/esm/index.mjs.map +7 -0
  6. package/lib/{license.md → licence.md} +0 -0
  7. package/lib/src/MIT-license.md +14 -0
  8. package/lib/{types/action.d.ts → src/action.ts} +64 -33
  9. package/lib/src/alpha.jpg +0 -0
  10. package/lib/src/app_sockets.ts +81 -0
  11. package/lib/src/application.ts +251 -0
  12. package/lib/src/autocomplete.ts +197 -0
  13. package/lib/src/base64.ts +166 -0
  14. package/lib/src/base_component.ts +152 -0
  15. package/lib/src/button.ts +355 -0
  16. package/lib/src/calendar.ts +328 -0
  17. package/lib/src/canvas.ts +505 -0
  18. package/lib/src/cardview.ts +227 -0
  19. package/lib/src/checkbox.ts +188 -0
  20. package/lib/src/color.ts +752 -0
  21. package/lib/src/colorpicker.ts +1639 -0
  22. package/lib/src/combobox.ts +465 -0
  23. package/lib/src/component.ts +2329 -0
  24. package/lib/{esm/dom_events.js → src/copyright.txt} +27 -29
  25. package/lib/src/datastore.ts +1322 -0
  26. package/lib/src/dialog.ts +656 -0
  27. package/lib/src/dom_events.ts +315 -0
  28. package/lib/src/drag_manager.ts +199 -0
  29. package/lib/src/drawtext.ts +355 -0
  30. package/lib/src/fileupload.ts +213 -0
  31. package/lib/src/form.ts +375 -0
  32. package/lib/src/formatters.ts +105 -0
  33. package/lib/src/gridview.ts +1185 -0
  34. package/lib/src/i18n.ts +346 -0
  35. package/lib/src/icon.ts +335 -0
  36. package/lib/src/image.ts +204 -0
  37. package/lib/src/index.ts +89 -0
  38. package/lib/src/input.ts +249 -0
  39. package/lib/src/label.ts +128 -0
  40. package/lib/src/layout.ts +430 -0
  41. package/lib/src/link.ts +86 -0
  42. package/lib/src/listview.ts +765 -0
  43. package/lib/{esm/md5.js → src/md5.ts} +438 -403
  44. package/lib/src/menu.ts +425 -0
  45. package/lib/src/messagebox.ts +224 -0
  46. package/lib/src/panel.ts +86 -0
  47. package/lib/src/popup.ts +494 -0
  48. package/lib/src/property_editor.ts +337 -0
  49. package/lib/src/radiobtn.ts +197 -0
  50. package/lib/src/rating.ts +135 -0
  51. package/lib/src/request.ts +300 -0
  52. package/lib/src/router.ts +185 -0
  53. package/lib/src/settings.ts +77 -0
  54. package/lib/src/sidebarview.ts +103 -0
  55. package/lib/src/spreadsheet.ts +1449 -0
  56. package/lib/src/styles.ts +343 -0
  57. package/lib/src/svgcomponent.ts +577 -0
  58. package/lib/src/tabbar.ts +151 -0
  59. package/lib/src/tabview.ts +110 -0
  60. package/lib/src/textarea.ts +235 -0
  61. package/lib/src/textedit.ts +544 -0
  62. package/lib/src/toaster.ts +80 -0
  63. package/lib/src/tools.ts +1473 -0
  64. package/lib/src/tooltips.ts +191 -0
  65. package/lib/src/treeview.ts +716 -0
  66. package/lib/{esm/version.js → src/version.ts} +30 -29
  67. package/lib/{styles → src}/x4.less +0 -0
  68. package/lib/src/x4dom.ts +57 -0
  69. package/lib/src/x4events.ts +585 -0
  70. package/lib/src/x4react.ts +90 -0
  71. package/package.json +52 -49
  72. package/lib/cjs/action.js +0 -58
  73. package/lib/cjs/app_sockets.js +0 -74
  74. package/lib/cjs/application.js +0 -182
  75. package/lib/cjs/autocomplete.js +0 -155
  76. package/lib/cjs/base_component.js +0 -124
  77. package/lib/cjs/button.js +0 -263
  78. package/lib/cjs/calendar.js +0 -254
  79. package/lib/cjs/canvas.js +0 -361
  80. package/lib/cjs/cardview.js +0 -161
  81. package/lib/cjs/checkbox.js +0 -139
  82. package/lib/cjs/color.js +0 -591
  83. package/lib/cjs/colorpicker.js +0 -1468
  84. package/lib/cjs/combobox.js +0 -349
  85. package/lib/cjs/component.js +0 -1719
  86. package/lib/cjs/datastore.js +0 -985
  87. package/lib/cjs/dialog.js +0 -478
  88. package/lib/cjs/dom_events.js +0 -30
  89. package/lib/cjs/drag_manager.js +0 -145
  90. package/lib/cjs/drawtext.js +0 -276
  91. package/lib/cjs/fileupload.js +0 -167
  92. package/lib/cjs/form.js +0 -304
  93. package/lib/cjs/formatters.js +0 -90
  94. package/lib/cjs/gridview.js +0 -881
  95. package/lib/cjs/i18n.js +0 -266
  96. package/lib/cjs/icon.js +0 -272
  97. package/lib/cjs/image.js +0 -157
  98. package/lib/cjs/input.js +0 -174
  99. package/lib/cjs/label.js +0 -95
  100. package/lib/cjs/layout.js +0 -322
  101. package/lib/cjs/link.js +0 -64
  102. package/lib/cjs/listview.js +0 -546
  103. package/lib/cjs/md5.js +0 -403
  104. package/lib/cjs/menu.js +0 -301
  105. package/lib/cjs/messagebox.js +0 -177
  106. package/lib/cjs/panel.js +0 -68
  107. package/lib/cjs/popup.js +0 -383
  108. package/lib/cjs/property_editor.js +0 -252
  109. package/lib/cjs/radiobtn.js +0 -140
  110. package/lib/cjs/rating.js +0 -102
  111. package/lib/cjs/request.js +0 -246
  112. package/lib/cjs/router.js +0 -139
  113. package/lib/cjs/settings.js +0 -69
  114. package/lib/cjs/sidebarview.js +0 -82
  115. package/lib/cjs/spreadsheet.js +0 -1084
  116. package/lib/cjs/styles.js +0 -275
  117. package/lib/cjs/svgcomponent.js +0 -447
  118. package/lib/cjs/tabbar.js +0 -111
  119. package/lib/cjs/tabview.js +0 -85
  120. package/lib/cjs/textarea.js +0 -165
  121. package/lib/cjs/textedit.js +0 -415
  122. package/lib/cjs/toaster.js +0 -64
  123. package/lib/cjs/tools.js +0 -1197
  124. package/lib/cjs/tooltips.js +0 -157
  125. package/lib/cjs/treeview.js +0 -535
  126. package/lib/cjs/version.js +0 -32
  127. package/lib/cjs/x4dom.js +0 -32
  128. package/lib/cjs/x4events.js +0 -384
  129. package/lib/cjs/x4react.js +0 -72
  130. package/lib/esm/action.js +0 -53
  131. package/lib/esm/app_sockets.js +0 -70
  132. package/lib/esm/application.js +0 -184
  133. package/lib/esm/autocomplete.js +0 -155
  134. package/lib/esm/base_component.js +0 -107
  135. package/lib/esm/button.js +0 -257
  136. package/lib/esm/calendar.js +0 -249
  137. package/lib/esm/canvas.js +0 -358
  138. package/lib/esm/cardview.js +0 -159
  139. package/lib/esm/checkbox.js +0 -134
  140. package/lib/esm/color.js +0 -588
  141. package/lib/esm/colorpicker.js +0 -1475
  142. package/lib/esm/combobox.js +0 -351
  143. package/lib/esm/component.js +0 -1711
  144. package/lib/esm/datastore.js +0 -990
  145. package/lib/esm/dialog.js +0 -490
  146. package/lib/esm/drag_manager.js +0 -147
  147. package/lib/esm/drawtext.js +0 -271
  148. package/lib/esm/fileupload.js +0 -163
  149. package/lib/esm/form.js +0 -304
  150. package/lib/esm/formatters.js +0 -81
  151. package/lib/esm/gridview.js +0 -889
  152. package/lib/esm/i18n.js +0 -257
  153. package/lib/esm/icon.js +0 -261
  154. package/lib/esm/image.js +0 -154
  155. package/lib/esm/input.js +0 -182
  156. package/lib/esm/label.js +0 -90
  157. package/lib/esm/layout.js +0 -310
  158. package/lib/esm/link.js +0 -59
  159. package/lib/esm/listview.js +0 -534
  160. package/lib/esm/menu.js +0 -300
  161. package/lib/esm/messagebox.js +0 -161
  162. package/lib/esm/panel.js +0 -65
  163. package/lib/esm/popup.js +0 -379
  164. package/lib/esm/property_editor.js +0 -251
  165. package/lib/esm/radiobtn.js +0 -136
  166. package/lib/esm/rating.js +0 -97
  167. package/lib/esm/request.js +0 -224
  168. package/lib/esm/router.js +0 -136
  169. package/lib/esm/settings.js +0 -66
  170. package/lib/esm/sidebarview.js +0 -79
  171. package/lib/esm/spreadsheet.js +0 -1097
  172. package/lib/esm/styles.js +0 -270
  173. package/lib/esm/svgcomponent.js +0 -450
  174. package/lib/esm/tabbar.js +0 -107
  175. package/lib/esm/tabview.js +0 -83
  176. package/lib/esm/textarea.js +0 -160
  177. package/lib/esm/textedit.js +0 -412
  178. package/lib/esm/toaster.js +0 -62
  179. package/lib/esm/tools.js +0 -1158
  180. package/lib/esm/tooltips.js +0 -153
  181. package/lib/esm/treeview.js +0 -527
  182. package/lib/esm/x4dom.js +0 -29
  183. package/lib/esm/x4events.js +0 -376
  184. package/lib/esm/x4react.js +0 -71
  185. package/lib/types/app_sockets.d.ts +0 -29
  186. package/lib/types/application.d.ts +0 -104
  187. package/lib/types/autocomplete.d.ts +0 -58
  188. package/lib/types/base_component.d.ts +0 -88
  189. package/lib/types/button.d.ts +0 -151
  190. package/lib/types/calendar.d.ts +0 -82
  191. package/lib/types/canvas.d.ts +0 -92
  192. package/lib/types/cardview.d.ts +0 -87
  193. package/lib/types/checkbox.d.ts +0 -77
  194. package/lib/types/color.d.ts +0 -148
  195. package/lib/types/colorpicker.d.ts +0 -107
  196. package/lib/types/combobox.d.ts +0 -107
  197. package/lib/types/component.d.ts +0 -601
  198. package/lib/types/datastore.d.ts +0 -396
  199. package/lib/types/dialog.d.ts +0 -175
  200. package/lib/types/dom_events.d.ts +0 -302
  201. package/lib/types/drag_manager.d.ts +0 -54
  202. package/lib/types/drawtext.d.ts +0 -48
  203. package/lib/types/fileupload.d.ts +0 -64
  204. package/lib/types/form.d.ts +0 -133
  205. package/lib/types/formatters.d.ts +0 -35
  206. package/lib/types/gridview.d.ts +0 -175
  207. package/lib/types/i18n.d.ts +0 -73
  208. package/lib/types/icon.d.ts +0 -64
  209. package/lib/types/image.d.ts +0 -55
  210. package/lib/types/index.d.ts +0 -84
  211. package/lib/types/input.d.ts +0 -91
  212. package/lib/types/label.d.ts +0 -58
  213. package/lib/types/layout.d.ts +0 -87
  214. package/lib/types/link.d.ts +0 -50
  215. package/lib/types/listview.d.ts +0 -178
  216. package/lib/types/md5.d.ts +0 -61
  217. package/lib/types/menu.d.ts +0 -130
  218. package/lib/types/messagebox.d.ts +0 -69
  219. package/lib/types/panel.d.ts +0 -47
  220. package/lib/types/popup.d.ts +0 -75
  221. package/lib/types/property_editor.d.ts +0 -71
  222. package/lib/types/radiobtn.d.ts +0 -73
  223. package/lib/types/rating.d.ts +0 -53
  224. package/lib/types/request.d.ts +0 -52
  225. package/lib/types/router.d.ts +0 -42
  226. package/lib/types/settings.d.ts +0 -37
  227. package/lib/types/sidebarview.d.ts +0 -49
  228. package/lib/types/spreadsheet.d.ts +0 -222
  229. package/lib/types/styles.d.ts +0 -85
  230. package/lib/types/svgcomponent.d.ts +0 -215
  231. package/lib/types/tabbar.d.ts +0 -58
  232. package/lib/types/tabview.d.ts +0 -49
  233. package/lib/types/textarea.d.ts +0 -77
  234. package/lib/types/textedit.d.ts +0 -123
  235. package/lib/types/toaster.d.ts +0 -42
  236. package/lib/types/tools.d.ts +0 -394
  237. package/lib/types/tooltips.d.ts +0 -46
  238. package/lib/types/treeview.d.ts +0 -144
  239. package/lib/types/version.d.ts +0 -29
  240. package/lib/types/x4dom.d.ts +0 -49
  241. package/lib/types/x4events.d.ts +0 -269
  242. package/lib/types/x4react.d.ts +0 -41
@@ -1,29 +1,30 @@
1
- /**
2
- * ___ ___ __
3
- * \ \_/ / / _
4
- * \ / /_| |_
5
- * / _ \____ _|
6
- * /__/ \__\ |_|
7
- *
8
- * @file version.ts
9
- * @author Etienne Cochard
10
- *
11
- * Copyright (c) 2019-2022 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
- export const x4js_version = "1.5.17";
1
+ /**
2
+ * ___ ___ __
3
+ * \ \_/ / / _
4
+ * \ / /_| |_
5
+ * / _ \____ _|
6
+ * /__/ \__\ |_|
7
+ *
8
+ * @file version.ts
9
+ * @author Etienne Cochard
10
+ *
11
+ * Copyright (c) 2019-2022 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
+ export const x4js_version = "1.5.20";
File without changes
@@ -0,0 +1,57 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \_/ / / _
4
+ * \ / /_| |_
5
+ * / _ \____ _|
6
+ * /__/ \__\ |_|
7
+ *
8
+ * @file x4events.ts
9
+ * @author Etienne Cochard
10
+ *
11
+ * Copyright (c) 2019-2022 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
+
@@ -0,0 +1,585 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \_/ / / _
4
+ * \ / /_| |_
5
+ * / _ \____ _|
6
+ * /__/ \__\ |_|
7
+ *
8
+ * @file x4events.ts
9
+ * @author Etienne Cochard
10
+ *
11
+ * Copyright (c) 2019-2022 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 = 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 = 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 = 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 = 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 = 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 ) => {
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 | null): void {
572
+ if (!eventName) {
573
+ this.m_eventRegistry = this.m_defaultHandlers = undefined;
574
+ }
575
+ else {
576
+ if (this.m_eventRegistry) {
577
+ this.m_eventRegistry[eventName] = undefined;
578
+ }
579
+
580
+ if (this.m_defaultHandlers) {
581
+ this.m_defaultHandlers[eventName] = undefined;
582
+ }
583
+ }
584
+ }
585
+ }