x4js 1.4.3 → 1.4.4

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 (56) hide show
  1. package/lib/index.d.ts +55 -0
  2. package/lib/index.js +55 -56
  3. package/lib/router.d.ts +1 -8
  4. package/lib/router.js +1 -1
  5. package/package.json +2 -1
  6. package/src/index.ts +55 -0
  7. package/src/router.ts +1 -1
  8. package/tsconfig.json +2 -1
  9. package/lib/application.d.ts +0 -95
  10. package/lib/application.js +0 -137
  11. package/lib/base64.d.ts +0 -31
  12. package/lib/base64.js +0 -135
  13. package/lib/base_component.d.ts +0 -64
  14. package/lib/base_component.js +0 -77
  15. package/lib/button.d.ts +0 -145
  16. package/lib/button.js +0 -235
  17. package/lib/calendar.d.ts +0 -77
  18. package/lib/calendar.js +0 -236
  19. package/lib/canvas.d.ts +0 -88
  20. package/lib/canvas.js +0 -354
  21. package/lib/cardview.d.ts +0 -83
  22. package/lib/cardview.js +0 -152
  23. package/lib/checkbox.d.ts +0 -72
  24. package/lib/checkbox.js +0 -126
  25. package/lib/color.d.ts +0 -144
  26. package/lib/color.js +0 -584
  27. package/lib/component.d.ts +0 -572
  28. package/lib/component.js +0 -1712
  29. package/lib/dom_events.d.ts +0 -284
  30. package/lib/dom_events.js +0 -13
  31. package/lib/hosts/host.d.ts +0 -44
  32. package/lib/hosts/host.js +0 -69
  33. package/lib/i18n.d.ts +0 -67
  34. package/lib/i18n.js +0 -169
  35. package/lib/icon.d.ts +0 -56
  36. package/lib/icon.js +0 -173
  37. package/lib/input.d.ts +0 -86
  38. package/lib/input.js +0 -172
  39. package/lib/label.d.ts +0 -54
  40. package/lib/label.js +0 -86
  41. package/lib/layout.d.ts +0 -77
  42. package/lib/layout.js +0 -261
  43. package/lib/list.txt +0 -56
  44. package/lib/menu.d.ts +0 -122
  45. package/lib/menu.js +0 -276
  46. package/lib/popup.d.ts +0 -71
  47. package/lib/popup.js +0 -373
  48. package/lib/settings.d.ts +0 -33
  49. package/lib/settings.js +0 -63
  50. package/lib/styles.d.ts +0 -81
  51. package/lib/styles.js +0 -262
  52. package/lib/tools.d.ts +0 -382
  53. package/lib/tools.js +0 -1096
  54. package/lib/x4_events.d.ts +0 -253
  55. package/lib/x4_events.js +0 -363
  56. package/list.txt +0 -0
package/lib/popup.d.ts DELETED
@@ -1,71 +0,0 @@
1
- /**
2
- * ___ ___ __
3
- * \ \_/ / / _
4
- * \ / /_| |_
5
- * / _ \____ _|
6
- * /__/ \__\ |_|
7
- *
8
- * @file popup.ts
9
- * @author Etienne Cochard
10
- * @license
11
- * Copyright (c) 2019-2021 R-libre ingenierie
12
- *
13
- * This program is free software; you can redistribute it and/or modify
14
- * it under the terms of the GNU General Public License as published by
15
- * the Free Software Foundation; either version 3 of the License, or
16
- * (at your option) any later version.
17
- *
18
- * This program is distributed in the hope that it will be useful,
19
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- * GNU General Public License for more details.
22
- *
23
- * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
24
- **/
25
- import { Container, CProps, ContainerEventMap, EvSize } from './component';
26
- import { Point } from './tools';
27
- import { BasicEvent } from './x4_events';
28
- export interface EvMove extends BasicEvent {
29
- pos: Point;
30
- }
31
- export declare function EvMove(pos: Point): EvMove;
32
- export interface PopupEventMap extends ContainerEventMap {
33
- size: EvSize;
34
- move: EvMove;
35
- }
36
- export interface PopupProps<E extends PopupEventMap = PopupEventMap> extends CProps<E> {
37
- sizable?: boolean;
38
- }
39
- /**
40
- * base class for all popup elements
41
- */
42
- export declare class Popup<P extends PopupProps = PopupProps, E extends PopupEventMap = PopupEventMap> extends Container<P, E> {
43
- protected m_ui_mask: HTMLElement;
44
- private m_hasMask;
45
- static modal_stack: HTMLElement[];
46
- constructor(props: P);
47
- enableMask(enable?: boolean): void;
48
- /**
49
- * display the popup on screen
50
- */
51
- show(modal?: boolean): void;
52
- centerOnScreen(): void;
53
- /**
54
- * display the popup at a specific position
55
- * @param x
56
- * @param y
57
- */
58
- displayAt(x: number, y: number, align?: string, offset?: {
59
- x: any;
60
- y: any;
61
- }): void;
62
- /**
63
- * close the popup
64
- */
65
- close(): void;
66
- componentCreated(): void;
67
- /**
68
- * resize for 'all' resize attribute
69
- */
70
- private _mouseResize;
71
- }
package/lib/popup.js DELETED
@@ -1,373 +0,0 @@
1
- /**
2
- * ___ ___ __
3
- * \ \_/ / / _
4
- * \ / /_| |_
5
- * / _ \____ _|
6
- * /__/ \__\ |_|
7
- *
8
- * @file popup.ts
9
- * @author Etienne Cochard
10
- * @license
11
- * Copyright (c) 2019-2021 R-libre ingenierie
12
- *
13
- * This program is free software; you can redistribute it and/or modify
14
- * it under the terms of the GNU General Public License as published by
15
- * the Free Software Foundation; either version 3 of the License, or
16
- * (at your option) any later version.
17
- *
18
- * This program is distributed in the hope that it will be useful,
19
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- * GNU General Public License for more details.
22
- *
23
- * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
24
- **/
25
- import { Container, flyWrap, SizerOverlay, Component, EvSize } from './component';
26
- import { Size, getMousePos } from './tools';
27
- import { BasicEvent } from './x4_events';
28
- import { Application } from './application';
29
- export function EvMove(pos) {
30
- return BasicEvent({ pos });
31
- }
32
- /**
33
- * base class for all popup elements
34
- */
35
- export class Popup extends Container {
36
- m_ui_mask;
37
- m_hasMask = true;
38
- static modal_stack = [];
39
- constructor(props) {
40
- super(props);
41
- this.addClass('@hidden');
42
- }
43
- enableMask(enable = true) {
44
- this.m_hasMask = enable;
45
- }
46
- /**
47
- * display the popup on screen
48
- */
49
- show(modal) {
50
- if (modal !== undefined) {
51
- this.m_hasMask = modal ? true : false;
52
- }
53
- else {
54
- modal = this.m_hasMask;
55
- }
56
- if (this.m_hasMask) {
57
- // remove the focus
58
- const focus = document.activeElement;
59
- if (focus) {
60
- focus.blur();
61
- }
62
- this.m_ui_mask = document.body.lastChild;
63
- while (this.m_ui_mask) {
64
- if (this.m_ui_mask.nodeType == 1) { // only element nodes
65
- let elUI = flyWrap(this.m_ui_mask);
66
- if (elUI.hasClass('@menu') || elUI.hasClass('@non-maskable')) {
67
- /* avoid circular dependencies instanceof Menu*/
68
- /* avoid nonmaskable elements tobe masked */
69
- }
70
- else if (elUI.getStyleValue('display') == 'none' || !elUI.isUserVisible()) {
71
- /* avoid masking hidden elements */
72
- }
73
- else if (!elUI.hasClass('@comp')) {
74
- /* avoid masking element that are not to us */
75
- }
76
- else {
77
- break;
78
- }
79
- }
80
- this.m_ui_mask = this.m_ui_mask.previousSibling;
81
- }
82
- if (this.m_ui_mask) {
83
- flyWrap(this.m_ui_mask).addClass('@mask');
84
- }
85
- }
86
- if (modal) {
87
- Application.instance().enterModal(true);
88
- }
89
- // to avoid body growing because of appendChild
90
- this.setStyle({
91
- left: 0,
92
- top: 0
93
- });
94
- document.body.appendChild(this._build());
95
- this.removeClass('@hidden');
96
- this.centerOnScreen();
97
- if (modal) {
98
- let focus = document.activeElement;
99
- if (!this.dom.contains(focus)) {
100
- const autofocus = this.queryItem('[autofocus]');
101
- if (autofocus) {
102
- autofocus.focus();
103
- }
104
- else {
105
- let tabbable = this.queryItem('[tabindex]');
106
- if (tabbable) {
107
- let tab_indexes = [].map.call(tabbable, (e) => { return e; });
108
- // remove hidden elements
109
- tab_indexes = tab_indexes.filter((el) => el.offsetParent !== null);
110
- if (tab_indexes.length) {
111
- tab_indexes[0].focus();
112
- }
113
- }
114
- }
115
- }
116
- Popup.modal_stack.push(this.dom);
117
- }
118
- }
119
- centerOnScreen() {
120
- let rc = this.getBoundingRect();
121
- let x = (document.body.clientWidth - rc.width) / 2, y = (document.body.clientHeight - rc.height) / 2;
122
- this.setStyleValue('left', x);
123
- this.setStyleValue('top', y);
124
- }
125
- /**
126
- * display the popup at a specific position
127
- * @param x
128
- * @param y
129
- */
130
- displayAt(x, y, align = 'top left', offset) {
131
- this.show();
132
- let halign = 'l', valign = 't';
133
- if (align.indexOf('right') >= 0) {
134
- halign = 'r';
135
- }
136
- if (align.indexOf('bottom') >= 0) {
137
- valign = 'b';
138
- }
139
- // @TODO: this is a minimal overflow problem solution
140
- let rc = document.body.getBoundingClientRect(), rm = this.getBoundingRect();
141
- if (halign == 'r') {
142
- x -= rm.width;
143
- }
144
- if (valign == 'b') {
145
- y -= rm.height;
146
- }
147
- if (offset) {
148
- x += offset.x;
149
- y += offset.y;
150
- }
151
- if (x < 4) {
152
- x = 4;
153
- }
154
- if ((x + rm.width) > rc.right - 4) {
155
- x = rc.right - 4 - rm.width;
156
- if (offset?.x < 0) {
157
- x += offset.x;
158
- }
159
- }
160
- if (y < 4) {
161
- y = 4;
162
- }
163
- if ((y + rm.height) > rc.bottom - 4) {
164
- y = rc.bottom - 4 - rm.height;
165
- if (offset?.y < 0) {
166
- y += offset.y;
167
- }
168
- }
169
- this.setStyle({ left: x, top: y });
170
- }
171
- /**
172
- * close the popup
173
- */
174
- close() {
175
- this.hide();
176
- if (this.m_hasMask && this.m_ui_mask) {
177
- flyWrap(this.m_ui_mask).removeClass('@mask');
178
- const app = Application.instance();
179
- app.enterModal(false);
180
- }
181
- let index = Popup.modal_stack.indexOf(this.dom);
182
- if (index >= 0) {
183
- Popup.modal_stack.splice(index);
184
- }
185
- this.dispose();
186
- }
187
- componentCreated() {
188
- if (this.m_props.sizable) {
189
- this.addClass('@size-all');
190
- let els = ['top', 'right', 'bottom', 'left', 'topleft', 'topright', 'bottomleft', 'bottomright'];
191
- for (let sens of els) {
192
- new SizerOverlay({
193
- target: this,
194
- sens: sens,
195
- events: { rawresize: (e) => this._mouseResize(e) }
196
- });
197
- }
198
- }
199
- }
200
- /**
201
- * resize for 'all' resize attribute
202
- */
203
- _mouseResize(event) {
204
- event.preventDefault();
205
- let irc = this.getBoundingRect();
206
- let st = this.getComputedStyle();
207
- let ev = event.ui_event;
208
- let tm = st.parse('marginTop'), lm = st.parse('marginLeft'), rm = st.parse('marginRight'), bm = st.parse('marginBottom');
209
- let ix = 0, iy = 0;
210
- let mp = getMousePos(ev, true);
211
- // horz
212
- switch (event.sens) {
213
- case 'topright':
214
- case 'bottomright':
215
- case 'right':
216
- ix = (irc.right - rm) - mp.x;
217
- break;
218
- case 'topleft':
219
- case 'bottomleft':
220
- case 'left':
221
- ix = (irc.left - lm) - mp.x;
222
- break;
223
- }
224
- // vert
225
- switch (event.sens) {
226
- case 'bottomleft':
227
- case 'bottomright':
228
- case 'bottom':
229
- iy = (irc.bottom - bm) - mp.y;
230
- break;
231
- case 'topleft':
232
- case 'topright':
233
- case 'top':
234
- iy = (irc.top - tm) - mp.y;
235
- break;
236
- }
237
- // left & top are with margin
238
- // width & height not
239
- irc.left -= lm;
240
- irc.top -= tm;
241
- //console.log( 'capture' );
242
- let sens = event.sens;
243
- Component.setCapture(this, (ne) => {
244
- //console.log( ne );
245
- let __move = (ex, ey) => {
246
- let left = irc.left, top = irc.top, width = irc.width, height = irc.height;
247
- let dx, dy;
248
- let px = ex + ix, py = ey + iy;
249
- if (px < 0) {
250
- px = 0;
251
- }
252
- if (py < 0) {
253
- py = 0;
254
- }
255
- // horz
256
- switch (sens) {
257
- case 'topright':
258
- case 'bottomright':
259
- case 'right':
260
- width = px - left;
261
- break;
262
- case 'topleft':
263
- case 'bottomleft':
264
- case 'left':
265
- dx = left - px;
266
- width += dx;
267
- left -= dx;
268
- break;
269
- }
270
- // vert
271
- switch (sens) {
272
- case 'bottomleft':
273
- case 'bottomright':
274
- case 'bottom':
275
- height = py - top;
276
- break;
277
- case 'topleft':
278
- case 'topright':
279
- case 'top':
280
- dy = top - py;
281
- height += dy;
282
- top -= dy;
283
- break;
284
- }
285
- let newsize = new Size(width, height);
286
- this.setStyle({ left, top, width: newsize.width, height: newsize.height });
287
- this.emit('size', EvSize(newsize));
288
- };
289
- if (ne.type == 'mouseup' || ne.type == 'touchend') {
290
- Component.releaseCapture();
291
- }
292
- else if (ne.type == 'mousemove') {
293
- let me = ne;
294
- __move(me.pageX, me.pageY);
295
- }
296
- else if (ne.type == 'touchmove') {
297
- let tev = ne;
298
- __move(tev.touches[0].pageX, tev.touches[0].pageY);
299
- }
300
- });
301
- }
302
- }
303
- /**
304
- * handle tab key
305
- */
306
- function x4handleKeyDown(e) {
307
- if (e.key == 'Tab' || e.key == 'Enter') {
308
- const target = e.target;
309
- if (target.tagName == 'TEXTAREA') {
310
- return;
311
- }
312
- const el = Component.getElement(target);
313
- if (el && (el.hasAttribute('wants-tab') || el.hasAttribute('wants-enter'))) {
314
- return;
315
- }
316
- let topStack = document.body;
317
- if (Popup.modal_stack.length) {
318
- topStack = Popup.modal_stack[Popup.modal_stack.length - 1];
319
- }
320
- _nextTab(topStack, e.target, e.shiftKey);
321
- e.stopPropagation();
322
- e.preventDefault();
323
- }
324
- }
325
- /**
326
- * cycle through tabs
327
- */
328
- function _nextTab(root, el, prev) {
329
- // first check if the focus is one of our child (disabled...)
330
- let focusEl = document.activeElement;
331
- if (!root.contains(focusEl)) {
332
- return;
333
- }
334
- let comp = Component.getElement(el);
335
- // get a list of elements with tab index, this way we should abble to
336
- // cycle on them (not on browser address nor under dialog elements)
337
- let tabbable = root.querySelectorAll('[tabindex]');
338
- let tab_indexes = [].map.call(tabbable, (e) => { return e; });
339
- // remove hidden elements
340
- tab_indexes = tab_indexes.filter((el) => el.offsetParent !== null);
341
- if (!tab_indexes.length) {
342
- return;
343
- }
344
- let ct = tab_indexes.indexOf(el);
345
- if (ct < 0) {
346
- ct = 0;
347
- }
348
- else {
349
- if (prev) {
350
- if (ct > 0) {
351
- ct--;
352
- }
353
- else {
354
- ct = tab_indexes.length - 1;
355
- }
356
- }
357
- else {
358
- if (ct < tab_indexes.length - 1) {
359
- ct++;
360
- }
361
- else {
362
- ct = 0;
363
- }
364
- }
365
- }
366
- tab_indexes[ct].focus();
367
- }
368
- function installKBHandler() {
369
- // set on body to be called after document (where all component domevent go)
370
- document.body.addEventListener('keydown', x4handleKeyDown, true);
371
- }
372
- // too early ?
373
- document.body ? installKBHandler() : window.addEventListener('load', installKBHandler);
package/lib/settings.d.ts DELETED
@@ -1,33 +0,0 @@
1
- /**
2
- * ___ ___ __
3
- * \ \_/ / / _
4
- * \ / /_| |_
5
- * / _ \____ _|
6
- * /__/ \__\ |_|
7
- *
8
- * @file local_storage.ts
9
- * @author Etienne Cochard
10
- * @license
11
- * Copyright (c) 2019-2021 R-libre ingenierie
12
- *
13
- * This program is free software; you can redistribute it and/or modify
14
- * it under the terms of the GNU General Public License as published by
15
- * the Free Software Foundation; either version 3 of the License, or
16
- * (at your option) any later version.
17
- *
18
- * This program is distributed in the hope that it will be useful,
19
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- * GNU General Public License for more details.
22
- *
23
- * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
24
- **/
25
- export declare class Settings {
26
- private m_data;
27
- private m_name;
28
- constructor(name?: string);
29
- set(name: string, value: any): void;
30
- get(name: string, defValue?: any): any;
31
- private _save;
32
- private _load;
33
- }
package/lib/settings.js DELETED
@@ -1,63 +0,0 @@
1
- /**
2
- * ___ ___ __
3
- * \ \_/ / / _
4
- * \ / /_| |_
5
- * / _ \____ _|
6
- * /__/ \__\ |_|
7
- *
8
- * @file local_storage.ts
9
- * @author Etienne Cochard
10
- * @license
11
- * Copyright (c) 2019-2021 R-libre ingenierie
12
- *
13
- * This program is free software; you can redistribute it and/or modify
14
- * it under the terms of the GNU General Public License as published by
15
- * the Free Software Foundation; either version 3 of the License, or
16
- * (at your option) any later version.
17
- *
18
- * This program is distributed in the hope that it will be useful,
19
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- * GNU General Public License for more details.
22
- *
23
- * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
24
- **/
25
- import { host } from './hosts/host';
26
- export class Settings {
27
- m_data;
28
- m_name;
29
- constructor(name) {
30
- this.m_data = null;
31
- this.m_name = name ?? 'settings';
32
- }
33
- set(name, value) {
34
- this._load();
35
- this.m_data[name] = value;
36
- this._save();
37
- }
38
- get(name, defValue) {
39
- this._load();
40
- return this.m_data[name] ?? defValue;
41
- }
42
- _save() {
43
- let data = JSON.stringify(this.m_data);
44
- host.writeLocalStorage(this.m_name, data);
45
- }
46
- _load() {
47
- if (this.m_data) {
48
- return;
49
- }
50
- this.m_data = {};
51
- let data = host.readLocalStorage(this.m_name);
52
- if (data !== null) {
53
- data = JSON.parse(data);
54
- if (data) {
55
- this.m_data = data;
56
- }
57
- else {
58
- console.info('There was an error attempting to read your settings.');
59
- }
60
- }
61
- // console.info('There was an error attempting to read your settings.');
62
- }
63
- }
package/lib/styles.d.ts DELETED
@@ -1,81 +0,0 @@
1
- /**
2
- * ___ ___ __
3
- * \ \_/ / / _
4
- * \ / /_| |_
5
- * / _ \____ _|
6
- * /__/ \__\ |_|
7
- *
8
- * @file styles.ts
9
- * @author Etienne Cochard
10
- * @license
11
- * Copyright (c) 2019-2021 R-libre ingenierie
12
- *
13
- * This program is free software; you can redistribute it and/or modify
14
- * it under the terms of the GNU General Public License as published by
15
- * the Free Software Foundation; either version 3 of the License, or
16
- * (at your option) any later version.
17
- *
18
- * This program is distributed in the hope that it will be useful,
19
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- * GNU General Public License for more details.
22
- *
23
- * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
24
- **/
25
- /**
26
- * -- [ @STYLESHEET ] -----------------------------------------------------------------
27
- */
28
- export declare class Stylesheet {
29
- private m_sheet;
30
- private m_rules;
31
- constructor();
32
- /**
33
- * add a new rule to the style sheet
34
- * @param {string} name - internal rule name
35
- * @param {string} definition - css definition of the rule
36
- * @example
37
- * setRule('xbody', "body { background-color: #ff0000; }" );
38
- */
39
- setRule(name: string, definition: any): void;
40
- /**
41
- * return the style variable value
42
- * @param name - variable name without '--'
43
- * @example
44
- * ```
45
- * let color = Component.getCss( ).getVar( 'button-color' );
46
- * ```
47
- */
48
- static getVar(name: string): any;
49
- static guid: number;
50
- static doc_style: CSSStyleDeclaration;
51
- }
52
- /**
53
- * -- [ @CSSPARSER ] -----------------------------------------------------------------
54
- *
55
- * adaptation of jss-for-node-js
56
- */
57
- export declare class CSSParser {
58
- private result;
59
- parse(css: any): string;
60
- static mk_string(rules: any): string;
61
- private parse_json;
62
- private makePropertyName;
63
- private makeSelectorName;
64
- addProperty(scope: string, property: string, value: any): void;
65
- }
66
- export declare class ComputedStyle {
67
- m_style: CSSStyleDeclaration;
68
- constructor(style: CSSStyleDeclaration);
69
- /**
70
- * return the raw value
71
- */
72
- value(name: string): string;
73
- /**
74
- * return the interpreted value
75
- */
76
- parse(name: string): number;
77
- /**
78
- *
79
- */
80
- get style(): CSSStyleDeclaration;
81
- }