x4js 1.4.4 → 1.4.7

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 (85) hide show
  1. package/lib/application.d.ts +96 -0
  2. package/lib/application.js +146 -0
  3. package/lib/base64.d.ts +31 -0
  4. package/lib/base64.js +139 -0
  5. package/lib/base_component.d.ts +64 -0
  6. package/lib/base_component.js +81 -0
  7. package/lib/button.d.ts +145 -0
  8. package/lib/button.js +241 -0
  9. package/lib/calendar.d.ts +77 -0
  10. package/lib/calendar.js +241 -0
  11. package/lib/canvas.d.ts +88 -0
  12. package/lib/canvas.js +358 -0
  13. package/lib/cardview.d.ts +83 -0
  14. package/lib/cardview.js +156 -0
  15. package/lib/checkbox.d.ts +72 -0
  16. package/lib/checkbox.js +130 -0
  17. package/lib/color.d.ts +144 -0
  18. package/lib/color.js +588 -0
  19. package/lib/colorpicker.js +86 -80
  20. package/lib/combobox.js +26 -22
  21. package/lib/component.d.ts +572 -0
  22. package/lib/component.js +1729 -0
  23. package/lib/datastore.js +29 -20
  24. package/lib/dialog.js +41 -36
  25. package/lib/dom_events.d.ts +284 -0
  26. package/lib/dom_events.js +14 -0
  27. package/lib/drag_manager.js +4 -1
  28. package/lib/drawtext.js +9 -5
  29. package/lib/fileupload.js +19 -12
  30. package/lib/form.js +29 -25
  31. package/lib/formatters.js +19 -10
  32. package/lib/gridview.js +40 -35
  33. package/lib/hosts/host.d.ts +44 -0
  34. package/lib/hosts/host.js +73 -0
  35. package/lib/i18n.d.ts +67 -0
  36. package/lib/i18n.js +175 -0
  37. package/lib/icon.d.ts +56 -0
  38. package/lib/icon.js +178 -0
  39. package/lib/image.js +7 -3
  40. package/lib/index.js +71 -55
  41. package/lib/input.d.ts +86 -0
  42. package/lib/input.js +176 -0
  43. package/lib/label.d.ts +54 -0
  44. package/lib/label.js +90 -0
  45. package/lib/layout.d.ts +77 -0
  46. package/lib/layout.js +271 -0
  47. package/lib/link.js +9 -5
  48. package/lib/listview.js +34 -27
  49. package/lib/md5.js +5 -1
  50. package/lib/menu.d.ts +122 -0
  51. package/lib/menu.js +284 -0
  52. package/lib/messagebox.js +22 -17
  53. package/lib/panel.js +13 -9
  54. package/lib/popup.d.ts +71 -0
  55. package/lib/popup.js +378 -0
  56. package/lib/property_editor.js +20 -16
  57. package/lib/radiobtn.js +13 -9
  58. package/lib/rating.js +13 -9
  59. package/lib/request.js +16 -9
  60. package/lib/router.js +5 -1
  61. package/lib/settings.d.ts +33 -0
  62. package/lib/settings.js +67 -0
  63. package/lib/sidebarview.js +12 -8
  64. package/lib/smartedit.js +16 -11
  65. package/lib/spreadsheet.js +35 -31
  66. package/lib/styles.d.ts +81 -0
  67. package/lib/styles.js +268 -0
  68. package/lib/svgcomponent.js +8 -3
  69. package/lib/tabbar.js +10 -6
  70. package/lib/tabview.js +10 -6
  71. package/lib/textarea.js +10 -6
  72. package/lib/textedit.js +39 -35
  73. package/lib/texthiliter.js +8 -4
  74. package/lib/toaster.js +8 -4
  75. package/lib/tools.d.ts +382 -0
  76. package/lib/tools.js +1142 -0
  77. package/lib/tooltips.js +14 -9
  78. package/lib/treeview.js +30 -26
  79. package/lib/x4_events.d.ts +253 -0
  80. package/lib/x4_events.js +375 -0
  81. package/package.json +1 -1
  82. package/src/application.ts +9 -4
  83. package/src/x4.less +143 -107
  84. package/tsconfig.json +1 -1
  85. package/x4.css +1541 -0
@@ -0,0 +1,375 @@
1
+ "use strict";
2
+ /**
3
+ * ___ ___ __
4
+ * \ \_/ / / _
5
+ * \ / /_| |_
6
+ * / _ \____ _|
7
+ * /__/ \__\ |_|
8
+ *
9
+ * @file observable.ts
10
+ * @author Etienne Cochard
11
+ * @license
12
+ * Copyright (c) 2019-2021 R-libre ingenierie
13
+ *
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License as published by
16
+ * the Free Software Foundation; either version 3 of the License, or
17
+ * (at your option) any later version.
18
+ *
19
+ * This program is distributed in the hope that it will be useful,
20
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ * GNU General Public License for more details.
23
+ *
24
+ * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
25
+ **/
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.EventSource = exports.EvDrag = exports.EvMessage = exports.EvTimer = exports.EvContextMenu = exports.EvSelectionChange = exports.EvChange = exports.EvClick = exports.BasicEvent = void 0;
28
+ // default stopPropagation implementation for Events
29
+ const stopPropagation = function () {
30
+ this.propagationStopped = true;
31
+ };
32
+ // default preventDefault implementation for Events
33
+ const preventDefault = function () {
34
+ this.defaultPrevented = true;
35
+ };
36
+ ;
37
+ /**
38
+ * BasicEvent Builder
39
+ * this function is responsable of BasicEvent creation
40
+ * ie. is equivalent of new BasicEvent( xxx );
41
+ * @param params
42
+ * @returns BasicEvent
43
+ */
44
+ function BasicEvent(params) {
45
+ return {
46
+ stopPropagation,
47
+ preventDefault,
48
+ ...params,
49
+ };
50
+ }
51
+ exports.BasicEvent = BasicEvent;
52
+ function EvClick(context = null) {
53
+ return BasicEvent({ context });
54
+ }
55
+ exports.EvClick = EvClick;
56
+ function EvChange(value, context = null) {
57
+ return BasicEvent({ value, context });
58
+ }
59
+ exports.EvChange = EvChange;
60
+ function EvSelectionChange(selection, context = null) {
61
+ return BasicEvent({ selection, context });
62
+ }
63
+ exports.EvSelectionChange = EvSelectionChange;
64
+ function EvContextMenu(uievent, context = null) {
65
+ return BasicEvent({ uievent, context });
66
+ }
67
+ exports.EvContextMenu = EvContextMenu;
68
+ function EvTimer(timer, time = 0, context = null) {
69
+ return BasicEvent({ timer, time, context });
70
+ }
71
+ exports.EvTimer = EvTimer;
72
+ function EvMessage(msg, params, source) {
73
+ return BasicEvent({ msg, params, source });
74
+ }
75
+ exports.EvMessage = EvMessage;
76
+ function EvDrag(element, data, ctx) {
77
+ return BasicEvent({ element, data, context: ctx });
78
+ }
79
+ exports.EvDrag = EvDrag;
80
+ /**
81
+ * Event emitter class
82
+ * this class allow you to emit and handle events
83
+ *
84
+ * @example:
85
+ * ```ts
86
+ *
87
+ * interface EvDoIt extends BasicEvent {
88
+ * param: unknown;
89
+ * }
90
+ *
91
+ * function EvDoIt( e: EvDoIt ) : EvDoIt {
92
+ * return BasicEvent<EvDoIt>( e );
93
+ * }
94
+ *
95
+ * interface TestEventMap extends EventMap {
96
+ * doit: EvDoIt;
97
+ * }
98
+ *
99
+ * let ee = new EventSource<TestEventMap>(null);
100
+ * ee.listen({
101
+ * doit: (e) => {
102
+ * console.log(e);
103
+ * e.preventDefault();
104
+ * },
105
+ * });
106
+ *
107
+ * ee.defaults({
108
+ * doit: (e) => {
109
+ * console.log('default handler for ', e.type, e.selection);
110
+ * },
111
+ * })
112
+ *
113
+ * ee.on('doit', (e) => {
114
+ * debugger;
115
+ * })
116
+ *
117
+ * const ev = EvDoIt({ param: 10 });
118
+ * ee.emit('change', ev);
119
+ * if (ev.defaultPrevented) {
120
+ * console.log('prevented');
121
+ * }
122
+ * ```
123
+ */
124
+ class EventSource {
125
+ m_source;
126
+ m_eventRegistry;
127
+ m_defaultHandlers;
128
+ constructor(source = null) {
129
+ this.m_source = source ?? this;
130
+ }
131
+ /**
132
+ * emit an event
133
+ * you can stop propagation of event or prevent default
134
+ * @param eventName - name of event to emit
135
+ * @param event - event data
136
+ */
137
+ emit(type, event) {
138
+ this._emit(type, event);
139
+ }
140
+ _emit(eventName, e) {
141
+ let listeners = this.m_eventRegistry?.get(eventName);
142
+ const defaultHandler = this.m_defaultHandlers?.get(eventName);
143
+ if (!e) {
144
+ e = {};
145
+ }
146
+ if (!e.source) {
147
+ e.source = this.m_source;
148
+ }
149
+ if (!e.type) {
150
+ e.type = eventName;
151
+ }
152
+ if (listeners && listeners.length) {
153
+ if (!e.preventDefault) {
154
+ e.preventDefault = preventDefault;
155
+ }
156
+ if (!e.stopPropagation) {
157
+ e.stopPropagation = stopPropagation;
158
+ }
159
+ // small optimisation
160
+ if (listeners.length == 1) {
161
+ listeners[0](e);
162
+ }
163
+ else {
164
+ const temp = listeners.slice();
165
+ for (let i = 0, n = temp.length; i < n; i++) {
166
+ temp[i](e);
167
+ if (e.propagationStopped) {
168
+ break;
169
+ }
170
+ }
171
+ }
172
+ }
173
+ if (defaultHandler && defaultHandler.length && !e.defaultPrevented) {
174
+ return defaultHandler[0](e);
175
+ }
176
+ }
177
+ /**
178
+ * signal en event
179
+ * signaled event are notification : no way to prevent default not stop propagation
180
+ * @param eventName name of event to signal
181
+ * @param event event data
182
+ */
183
+ signal(type, event, delay = -1) {
184
+ this._signal(type, event, delay);
185
+ }
186
+ _signal(eventName, e, delay = -1) {
187
+ if (!this.m_eventRegistry) {
188
+ return;
189
+ }
190
+ const listeners = this.m_eventRegistry.get(eventName);
191
+ if (!listeners || !listeners.length) {
192
+ return;
193
+ }
194
+ if (!e) {
195
+ e = {};
196
+ }
197
+ if (!e.type) {
198
+ e.type = eventName;
199
+ }
200
+ if (!e.source) {
201
+ e.source = this.m_source;
202
+ }
203
+ e.preventDefault = e.stopPropagation = () => {
204
+ console.error('this event cannot be stopped not default prevented');
205
+ };
206
+ // small optimisation
207
+ if (listeners.length == 1 && delay == -1) {
208
+ listeners[0](e);
209
+ }
210
+ else {
211
+ const temp = listeners.slice();
212
+ const call = () => {
213
+ for (let i = 0, n = temp.length; i < n; i++) {
214
+ temp[i](e);
215
+ }
216
+ };
217
+ if (delay == -1) {
218
+ call();
219
+ }
220
+ else {
221
+ setTimeout(call, delay);
222
+ }
223
+ }
224
+ }
225
+ /**
226
+ * handle an event one time
227
+ * @param eventName - event name to handle
228
+ * @param callback - callback to call when event is signaled
229
+ * @returns Promise if callback is null
230
+ *
231
+ * take care with that because if the event is never fired and you await it,
232
+ * the system may overflow
233
+ */
234
+ once(type, callback) {
235
+ this._once(type, callback);
236
+ }
237
+ _once(eventName, callback) {
238
+ const newCallback = (ev) => {
239
+ this.off(eventName, newCallback);
240
+ callback(ev);
241
+ };
242
+ this._on(eventName, newCallback);
243
+ if (!callback) {
244
+ return new Promise(function (resolve) {
245
+ callback = resolve;
246
+ });
247
+ }
248
+ }
249
+ /**
250
+ * set the event default handler
251
+ * @param eventName - name of the event
252
+ * @param callback - callback to call when the event is not handled (and preventDeault has not been called)
253
+ */
254
+ setDefaultHandler(eventName, callback) {
255
+ let handlers = this.m_defaultHandlers;
256
+ if (!handlers) {
257
+ handlers = this.m_defaultHandlers = new Map();
258
+ }
259
+ let stack = handlers.get(eventName);
260
+ if (stack) {
261
+ // if already in the stack, remove it
262
+ const idx = stack.indexOf(callback);
263
+ if (idx != -1) {
264
+ stack.splice(idx, 1);
265
+ }
266
+ // then make it first
267
+ stack.unshift(callback);
268
+ }
269
+ else {
270
+ handlers.set(eventName, [callback]);
271
+ }
272
+ }
273
+ /**
274
+ * remove the previous default handler installed for an event
275
+ * @param eventName - event name
276
+ * @param callback - callback handler to remove (must be the same as in setDefaultHandler)
277
+ */
278
+ removeDefaultHandler(eventName, callback) {
279
+ const handlers = this.m_defaultHandlers;
280
+ if (!handlers) {
281
+ return;
282
+ }
283
+ const stack = handlers.get(eventName);
284
+ if (stack) {
285
+ const idx = stack.indexOf(callback);
286
+ if (idx != -1) {
287
+ stack.splice(idx, 1);
288
+ }
289
+ }
290
+ }
291
+ /**
292
+ * define a set of listeners in one call
293
+ * @param events
294
+ */
295
+ listen(events) {
296
+ for (let n in events) {
297
+ this._on(n, events[n]);
298
+ }
299
+ }
300
+ /**
301
+ * define a set of default handlers in one call
302
+ * @param events
303
+ */
304
+ defaults(events) {
305
+ for (let n in events) {
306
+ this.setDefaultHandler(n, events[n]);
307
+ }
308
+ }
309
+ /**
310
+ * listen for an event
311
+ * @param eventName - event name to listen on
312
+ * @param callback - callback to call
313
+ * @param capturing - if true, capture event before other registred event handlers
314
+ */
315
+ on(type, callback) {
316
+ return this._on(type, callback);
317
+ }
318
+ _on(eventName, callback, capturing = false) {
319
+ if (!this.m_eventRegistry) {
320
+ this.m_eventRegistry = new Map();
321
+ }
322
+ let listeners = this.m_eventRegistry.get(eventName);
323
+ if (!listeners) {
324
+ listeners = [];
325
+ this.m_eventRegistry.set(eventName, listeners);
326
+ }
327
+ if (listeners.indexOf(callback) == -1) {
328
+ if (capturing) {
329
+ listeners.unshift(callback);
330
+ }
331
+ else {
332
+ listeners.push(callback);
333
+ }
334
+ }
335
+ return {
336
+ dispose: () => { this.off(eventName, callback); }
337
+ };
338
+ }
339
+ /**
340
+ * stop listening to an event
341
+ * @param eventName - event name
342
+ * @param callback - callback to remove (must be the same as in on )
343
+ */
344
+ off(eventName, callback) {
345
+ if (!this.m_eventRegistry) {
346
+ return;
347
+ }
348
+ let listeners = this.m_eventRegistry.get(eventName);
349
+ if (!listeners) {
350
+ return;
351
+ }
352
+ const idx = listeners.indexOf(callback);
353
+ if (idx !== -1) {
354
+ listeners.splice(idx, 1);
355
+ }
356
+ }
357
+ /**
358
+ * remove all listeners for an event
359
+ * @param eventName - event name
360
+ */
361
+ removeAllListeners(eventName) {
362
+ if (!eventName) {
363
+ this.m_eventRegistry = this.m_defaultHandlers = undefined;
364
+ }
365
+ else {
366
+ if (this.m_eventRegistry) {
367
+ this.m_eventRegistry[eventName] = undefined;
368
+ }
369
+ if (this.m_defaultHandlers) {
370
+ this.m_defaultHandlers[eventName] = undefined;
371
+ }
372
+ }
373
+ }
374
+ }
375
+ exports.EventSource = EventSource;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x4js",
3
- "version": "1.4.4",
3
+ "version": "1.4.7",
4
4
  "description": "X4js core files",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -43,8 +43,9 @@ interface ApplicationEventMap extends BaseComponentEventMap {
43
43
  export interface ApplicationProps extends BaseComponentProps<ApplicationEventMap> {
44
44
  app_name: string; //
45
45
  app_version: string; //
46
- app_uid: string;
47
- locale: string; // fr-FR
46
+ app_uid?: string;
47
+ locale?: string; // fr-FR
48
+ renderTo?: HTMLElement;
48
49
  }
49
50
 
50
51
  /**
@@ -113,7 +114,6 @@ export class Application<P extends ApplicationProps = ApplicationProps, E extend
113
114
  }
114
115
 
115
116
  ApplicationCreated( ) {
116
-
117
117
  }
118
118
 
119
119
  public get app_name( ) {
@@ -158,9 +158,14 @@ export class Application<P extends ApplicationProps = ApplicationProps, E extend
158
158
  public set mainView( root: Component ) {
159
159
 
160
160
  this.m_mainView = root;
161
+ this.mainView.addClass( 'x4-root-element' );
161
162
 
162
163
  deferCall( ( ) => {
163
- document.body.appendChild(root._build());
164
+ const dest = this.m_props.renderTo ?? document.body;
165
+ while (dest.firstChild) {
166
+ dest.removeChild(dest.firstChild);
167
+ }
168
+ dest.appendChild(root._build());
164
169
  } );
165
170
  }
166
171