x4js 2.0.18 → 2.0.21
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 +1 -0
- package/lib/cjs/x4.css +1 -1
- package/lib/cjs/x4.js +2 -2
- package/lib/esm/x4.css +1 -1
- package/lib/esm/x4.mjs +2 -2
- package/lib/styles/x4.css +1 -1
- package/lib/types/x4js.d.ts +92 -77
- package/package.json +1 -1
- package/src/components/boxes/boxes.ts +35 -3
- package/src/components/breadcrumb/breadcrumb.ts +4 -4
- package/src/components/btngroup/btngroup.ts +4 -4
- package/src/components/button/button.ts +2 -2
- package/src/components/calendar/calendar.ts +1 -1
- package/src/components/canvas/canvas.ts +2 -2
- package/src/components/checkbox/checkbox.ts +4 -4
- package/src/components/colorinput/colorinput.ts +3 -3
- package/src/components/combobox/combobox.module.scss +13 -0
- package/src/components/combobox/combobox.ts +10 -3
- package/src/components/dialog/dialog.ts +7 -7
- package/src/components/form/form.ts +5 -5
- package/src/components/gridview/gridview.ts +12 -9
- package/src/components/header/header.module.scss +2 -1
- package/src/components/header/header.ts +22 -10
- package/src/components/icon/icon.module.scss +1 -0
- package/src/components/icon/icon.ts +1 -1
- package/src/components/image/image.ts +3 -3
- package/src/components/input/input.ts +2 -2
- package/src/components/keyboard/keyboard.ts +5 -5
- package/src/components/label/label.module.scss +6 -1
- package/src/components/label/label.ts +1 -1
- package/src/components/listbox/listbox.module.scss +35 -31
- package/src/components/listbox/listbox.ts +53 -15
- package/src/components/messages/messages.ts +15 -1
- package/src/components/notification/notification.ts +8 -8
- package/src/components/popup/popup.ts +14 -3
- package/src/components/progress/progress.ts +1 -1
- package/src/components/propgrid/propgrid.ts +5 -3
- package/src/components/radio/radio.ts +2 -2
- package/src/components/rating/rating.ts +6 -6
- package/src/components/select/select.ts +1 -1
- package/src/components/sizers/sizer.ts +5 -5
- package/src/components/slider/slider.ts +3 -3
- package/src/components/switch/switch.ts +3 -3
- package/src/components/tabs/tabs.module.scss +2 -2
- package/src/components/tabs/tabs.ts +29 -5
- package/src/components/textarea/textarea.ts +1 -1
- package/src/components/textedit/textedit.ts +2 -2
- package/src/components/tickline/tickline.ts +1 -1
- package/src/components/tooltips/tooltips.ts +2 -2
- package/src/components/treeview/treeview.module.scss +9 -1
- package/src/components/treeview/treeview.ts +53 -14
- package/src/components/viewport/viewport.ts +1 -1
- package/src/core/component.ts +46 -9
- package/src/core/core_application.ts +3 -3
- package/src/core/core_data.ts +12 -12
- package/src/core/core_element.ts +1 -1
- package/src/core/core_react.ts +2 -2
- package/src/core/core_router.ts +2 -2
- package/src/core/core_state.ts +1 -1
- package/src/core/core_styles.ts +1 -1
- package/src/core/core_tools.ts +2 -0
- package/lib/src/components/base.scss +0 -25
- package/lib/src/components/boxes/boxes.module.scss +0 -54
- package/lib/src/components/boxes/boxes.ts +0 -370
- package/lib/src/components/breadcrumb/breadcrumb.scss +0 -56
- package/lib/src/components/breadcrumb/breadcrumb.ts +0 -93
- package/lib/src/components/breadcrumb/chevron-right.svg +0 -1
- package/lib/src/components/btngroup/btngroup.module.scss +0 -41
- package/lib/src/components/btngroup/btngroup.ts +0 -153
- package/lib/src/components/button/button.module.scss +0 -173
- package/lib/src/components/button/button.ts +0 -185
- package/lib/src/components/calendar/calendar-check-sharp-light.svg +0 -1
- package/lib/src/components/calendar/calendar.module.scss +0 -163
- package/lib/src/components/calendar/calendar.ts +0 -327
- package/lib/src/components/calendar/chevron-left-sharp-light.svg +0 -1
- package/lib/src/components/calendar/chevron-right-sharp-light.svg +0 -1
- package/lib/src/components/canvas/canvas.module.scss +0 -25
- package/lib/src/components/canvas/canvas.ts +0 -189
- package/lib/src/components/canvas/canvas_ex.ts +0 -276
- package/lib/src/components/checkbox/check.svg +0 -4
- package/lib/src/components/checkbox/checkbox.module.scss +0 -142
- package/lib/src/components/checkbox/checkbox.ts +0 -140
- package/lib/src/components/colorinput/colorinput.module.scss +0 -65
- package/lib/src/components/colorinput/colorinput.ts +0 -91
- package/lib/src/components/colorinput/crosshairs-simple-sharp-light.svg +0 -1
- package/lib/src/components/colorpicker/colorpicker.module.scss +0 -133
- package/lib/src/components/colorpicker/colorpicker.ts +0 -482
- package/lib/src/components/combobox/combobox.module.scss +0 -133
- package/lib/src/components/combobox/combobox.ts +0 -275
- package/lib/src/components/combobox/updown.svg +0 -4
- package/lib/src/components/components.ts +0 -42
- package/lib/src/components/dialog/dialog.module.scss +0 -104
- package/lib/src/components/dialog/dialog.ts +0 -229
- package/lib/src/components/dialog/xmark-sharp-light.svg +0 -1
- package/lib/src/components/filedrop/cloud-arrow-up.svg +0 -1
- package/lib/src/components/filedrop/filedrop.module.scss +0 -70
- package/lib/src/components/filedrop/filedrop.ts +0 -131
- package/lib/src/components/form/form.module.scss +0 -38
- package/lib/src/components/form/form.ts +0 -172
- package/lib/src/components/gridview/arrow-down-light.svg +0 -1
- package/lib/src/components/gridview/arrow-up-light.svg +0 -1
- package/lib/src/components/gridview/gridview.module.scss +0 -324
- package/lib/src/components/gridview/gridview.ts +0 -1175
- package/lib/src/components/header/header.module.scss +0 -40
- package/lib/src/components/header/header.ts +0 -130
- package/lib/src/components/icon/icon.module.scss +0 -31
- package/lib/src/components/icon/icon.ts +0 -137
- package/lib/src/components/image/image.module.scss +0 -28
- package/lib/src/components/image/image.ts +0 -168
- package/lib/src/components/input/input.module.scss +0 -74
- package/lib/src/components/input/input.ts +0 -422
- package/lib/src/components/keyboard/arrow-up.svg +0 -1
- package/lib/src/components/keyboard/delete-left.svg +0 -1
- package/lib/src/components/keyboard/eye-slash.svg +0 -1
- package/lib/src/components/keyboard/keyboard.module.scss +0 -134
- package/lib/src/components/keyboard/keyboard.ts +0 -526
- package/lib/src/components/label/label.module.scss +0 -76
- package/lib/src/components/label/label.ts +0 -97
- package/lib/src/components/link/link.ts +0 -81
- package/lib/src/components/listbox/listbox.module.scss +0 -161
- package/lib/src/components/listbox/listbox.ts +0 -539
- package/lib/src/components/menu/caret-right-solid.svg +0 -1
- package/lib/src/components/menu/menu.module.scss +0 -117
- package/lib/src/components/menu/menu.ts +0 -174
- package/lib/src/components/messages/circle-exclamation.svg +0 -1
- package/lib/src/components/messages/messages.module.scss +0 -92
- package/lib/src/components/messages/messages.ts +0 -215
- package/lib/src/components/messages/pen-field.svg +0 -1
- package/lib/src/components/normalize.scss +0 -391
- package/lib/src/components/notification/circle-check-solid.svg +0 -1
- package/lib/src/components/notification/circle-exclamation-solid.svg +0 -1
- package/lib/src/components/notification/circle-notch-light.svg +0 -1
- package/lib/src/components/notification/notification.module.scss +0 -84
- package/lib/src/components/notification/notification.ts +0 -107
- package/lib/src/components/notification/xmark-sharp-light.svg +0 -1
- package/lib/src/components/panel/panel.module.scss +0 -60
- package/lib/src/components/panel/panel.ts +0 -58
- package/lib/src/components/popup/popup.module.scss +0 -51
- package/lib/src/components/popup/popup.ts +0 -442
- package/lib/src/components/progress/progress.module.scss +0 -57
- package/lib/src/components/progress/progress.ts +0 -44
- package/lib/src/components/propgrid/folder-closed.svg +0 -1
- package/lib/src/components/propgrid/folder-open.svg +0 -1
- package/lib/src/components/propgrid/progrid.module.scss +0 -112
- package/lib/src/components/propgrid/propgrid.ts +0 -288
- package/lib/src/components/propgrid/updown.svg +0 -4
- package/lib/src/components/radio/radio.module.scss +0 -147
- package/lib/src/components/radio/radio.svg +0 -4
- package/lib/src/components/radio/radio.ts +0 -142
- package/lib/src/components/rating/rating.module.scss +0 -23
- package/lib/src/components/rating/rating.ts +0 -131
- package/lib/src/components/rating/star-sharp-light.svg +0 -1
- package/lib/src/components/rating/star-sharp-solid.svg +0 -1
- package/lib/src/components/select/select.module.scss +0 -9
- package/lib/src/components/select/select.ts +0 -134
- package/lib/src/components/shared.scss +0 -137
- package/lib/src/components/sizers/sizer.module.scss +0 -90
- package/lib/src/components/sizers/sizer.ts +0 -132
- package/lib/src/components/slider/slider.module.scss +0 -118
- package/lib/src/components/slider/slider.ts +0 -198
- package/lib/src/components/switch/switch.module.scss +0 -127
- package/lib/src/components/switch/switch.ts +0 -62
- package/lib/src/components/tabs/tabs.module.scss +0 -45
- package/lib/src/components/tabs/tabs.ts +0 -205
- package/lib/src/components/textarea/textarea.module.scss +0 -63
- package/lib/src/components/textarea/textarea.ts +0 -125
- package/lib/src/components/textedit/textedit.module.scss +0 -116
- package/lib/src/components/textedit/textedit.ts +0 -115
- package/lib/src/components/themes.scss +0 -88
- package/lib/src/components/tickline/tickline.module.scss +0 -26
- package/lib/src/components/tickline/tickline.ts +0 -82
- package/lib/src/components/tooltips/circle-info-sharp-light.svg +0 -1
- package/lib/src/components/tooltips/comments-question.svg +0 -1
- package/lib/src/components/tooltips/tooltips.scss +0 -72
- package/lib/src/components/tooltips/tooltips.ts +0 -109
- package/lib/src/components/treeview/chevron-down-light.svg +0 -1
- package/lib/src/components/treeview/treeview.module.scss +0 -185
- package/lib/src/components/treeview/treeview.ts +0 -445
- package/lib/src/components/viewport/viewport.module.scss +0 -32
- package/lib/src/components/viewport/viewport.ts +0 -41
- package/lib/src/core/component.ts +0 -1066
- package/lib/src/core/core_application.ts +0 -265
- package/lib/src/core/core_colors.ts +0 -250
- package/lib/src/core/core_data.ts +0 -1310
- package/lib/src/core/core_dom.ts +0 -471
- package/lib/src/core/core_dragdrop.ts +0 -201
- package/lib/src/core/core_element.ts +0 -115
- package/lib/src/core/core_events.ts +0 -177
- package/lib/src/core/core_i18n.ts +0 -393
- package/lib/src/core/core_react.ts +0 -79
- package/lib/src/core/core_router.ts +0 -237
- package/lib/src/core/core_state.ts +0 -62
- package/lib/src/core/core_styles.ts +0 -214
- package/lib/src/core/core_svg.ts +0 -712
- package/lib/src/core/core_tools.ts +0 -906
- package/lib/src/types/scss.d.ts +0 -4
- package/lib/src/types/svg.d.ts +0 -1
- package/lib/src/types/x4react.d.ts +0 -9
- package/lib/src/x4.scss +0 -19
- package/lib/src/x4.ts +0 -35
- package/lib/src/x4tsx.d.ts +0 -25
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / \____ _|
|
|
6
|
-
* /__/\__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file core_element.ts
|
|
9
|
-
* @author Etienne Cochard
|
|
10
|
-
*
|
|
11
|
-
* @copyright (c) 2024 R-libre ingenierie
|
|
12
|
-
*
|
|
13
|
-
* Use of this source code is governed by an MIT-style license
|
|
14
|
-
* that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
|
15
|
-
**/
|
|
16
|
-
|
|
17
|
-
import { EventMap, EventSource } from './core_events.js';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
export class CoreElement<E extends EventMap = EventMap> {
|
|
24
|
-
|
|
25
|
-
#events: EventSource<E>;
|
|
26
|
-
#timers: Map<string, Function>;
|
|
27
|
-
|
|
28
|
-
private __startTimer( name: string, ms: number, repeat: boolean, callback: ( ) => void ) {
|
|
29
|
-
if (!this.#timers) {
|
|
30
|
-
this.#timers = new Map();
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
this.__stopTimer(name);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const id = (repeat ? setInterval : setTimeout)( callback, ms );
|
|
37
|
-
|
|
38
|
-
this.#timers.set(name, () => {
|
|
39
|
-
(repeat ? clearInterval : clearTimeout)(id);
|
|
40
|
-
this.#timers.delete(name)
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
private __stopTimer( name: string ) {
|
|
45
|
-
const clear = this.#timers?.get(name);
|
|
46
|
-
if (clear) { clear(); }
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
setTimeout( name: string, ms: number, callback: () => void ) {
|
|
50
|
-
this.__startTimer( name, ms, false, callback );
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
clearTimeout( name: string ) {
|
|
54
|
-
this.__stopTimer( name );
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
setInterval( name: string, ms: number, callback: ( ) => void ) {
|
|
58
|
-
this.__startTimer( name, ms, true, callback );
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
clearInterval( name: string ) {
|
|
62
|
-
this.__stopTimer( name );
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
clearTimeouts( ) {
|
|
66
|
-
for( const [id,val] of this.#timers ) {
|
|
67
|
-
val( );
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
this.#timers.clear( );
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// :: EVENTS ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* attach to an event
|
|
77
|
-
*/
|
|
78
|
-
|
|
79
|
-
on<K extends keyof E>( name: K, listener: ( ev: E[K] ) => void ) {
|
|
80
|
-
console.assert( listener!==undefined && listener!==null );
|
|
81
|
-
|
|
82
|
-
if( !this.#events ) {
|
|
83
|
-
this.#events = new EventSource( this );
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
this.#events.addListener( name, listener );
|
|
87
|
-
return {
|
|
88
|
-
off: ( ) => {
|
|
89
|
-
this.#events.removeListener( name, listener );
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* detach
|
|
96
|
-
*/
|
|
97
|
-
|
|
98
|
-
off<K extends keyof E>( name: K, listener: ( ev: E[K] ) => void ) {
|
|
99
|
-
console.assert( listener!==undefined && listener!==null );
|
|
100
|
-
|
|
101
|
-
if( this.#events ) {
|
|
102
|
-
this.#events.removeListener( name, listener );
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
*
|
|
108
|
-
*/
|
|
109
|
-
|
|
110
|
-
fire<K extends keyof E>( name: K, ev: E[K] ) {
|
|
111
|
-
if( this.#events ) {
|
|
112
|
-
this.#events.fire( name, ev );
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / \____ _|
|
|
6
|
-
* /__/\__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file core_events.ts
|
|
9
|
-
* @author Etienne Cochard
|
|
10
|
-
*
|
|
11
|
-
* @copyright (c) 2024 R-libre ingenierie
|
|
12
|
-
*
|
|
13
|
-
* Use of this source code is governed by an MIT-style license
|
|
14
|
-
* that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
|
15
|
-
**/
|
|
16
|
-
|
|
17
|
-
import { CoreElement } from './core_element';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
export interface CoreEvent {
|
|
24
|
-
readonly type?: string; // type of the event 'click', 'change', ...
|
|
25
|
-
readonly source?: CoreElement; // object that fires the event
|
|
26
|
-
readonly context?: any; // contextual data, left to the user
|
|
27
|
-
|
|
28
|
-
propagationStopped?: boolean; // if true, do not propagate the event
|
|
29
|
-
defaultPrevented?: boolean; // if true, do not call default handler (if any)
|
|
30
|
-
|
|
31
|
-
stopPropagation?(): void; // stop the propagation
|
|
32
|
-
preventDefault?(): void; // prevent the default handler
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// default stopPropagation implementation for Events
|
|
36
|
-
const stopPropagation = function ( this: CoreEvent ) {
|
|
37
|
-
this.propagationStopped = true;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// default preventDefault implementation for Events
|
|
41
|
-
const preventDefault = function ( this: CoreEvent ) {
|
|
42
|
-
this.defaultPrevented = true;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
*
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
export interface EventMap {
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
*
|
|
55
|
-
*/
|
|
56
|
-
|
|
57
|
-
export type EventCallback<T extends CoreEvent = CoreEvent> = (event: T) => any;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
*
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
export class EventSource<E extends EventMap = EventMap > {
|
|
64
|
-
|
|
65
|
-
private _source: unknown;
|
|
66
|
-
private _registry: Map<string,EventCallback[]>;
|
|
67
|
-
|
|
68
|
-
constructor(source: unknown = null) {
|
|
69
|
-
this._source = source ?? this;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
addListener<K extends keyof E>( name: K, callback: ( ev: E[K] ) => void, capturing = false ) {
|
|
73
|
-
|
|
74
|
-
if (!this._registry) {
|
|
75
|
-
this._registry = new Map();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
let listeners = this._registry.get(name as string);
|
|
79
|
-
if (!listeners) {
|
|
80
|
-
listeners = [];
|
|
81
|
-
this._registry.set(name as string, listeners);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const cb = callback as EventCallback;
|
|
85
|
-
|
|
86
|
-
if (listeners.indexOf(cb) == -1) {
|
|
87
|
-
if (capturing) {
|
|
88
|
-
listeners.unshift(cb);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
listeners.push(cb);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return ( ) => {
|
|
96
|
-
this.removeListener( name, callback );
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* stop listening to an event
|
|
102
|
-
* @param eventName - event name
|
|
103
|
-
* @param callback - callback to remove (must be the same as in on )
|
|
104
|
-
*/
|
|
105
|
-
|
|
106
|
-
removeListener<K extends keyof E>(name: K, callback: (ev: E[K]) => any) {
|
|
107
|
-
|
|
108
|
-
if (!this._registry ) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
let listeners = this._registry.get(name as string);
|
|
113
|
-
if (!listeners) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const cb = callback as EventCallback;
|
|
118
|
-
const idx = listeners.indexOf(cb);
|
|
119
|
-
if (idx !== -1) {
|
|
120
|
-
listeners.splice(idx, 1);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
fire<K extends keyof E>(name: K, evx: E[K]) {
|
|
125
|
-
|
|
126
|
-
let listeners = this._registry?.get(name as string);
|
|
127
|
-
//const defaultHandler = this.m_defaultHandlers?.get(eventName);
|
|
128
|
-
|
|
129
|
-
if (listeners && listeners.length) {
|
|
130
|
-
let ev = evx as CoreEvent;
|
|
131
|
-
if (!ev) {
|
|
132
|
-
ev = {};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (!ev.source) {
|
|
136
|
-
// readonly
|
|
137
|
-
(ev as any).source = this._source;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (!ev.type) {
|
|
141
|
-
// readonly
|
|
142
|
-
(ev as any).type = name;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if (!ev.preventDefault) {
|
|
147
|
-
ev.preventDefault = preventDefault;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (!ev.stopPropagation) {
|
|
151
|
-
ev.stopPropagation = stopPropagation;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// small optimisation
|
|
155
|
-
if (listeners.length == 1) {
|
|
156
|
-
listeners[0](ev);
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
const temp = listeners.slice();
|
|
160
|
-
for (let i = 0, n = temp.length; i < n; i++) {
|
|
161
|
-
temp[i](ev);
|
|
162
|
-
if (ev.propagationStopped) {
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
//if (defaultHandler && defaultHandler.length && !e.defaultPrevented) {
|
|
170
|
-
// return defaultHandler[0](e);
|
|
171
|
-
//}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
@@ -1,393 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / \____ _|
|
|
6
|
-
* /__/\__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file core_i18n.ts
|
|
9
|
-
* @author Etienne Cochard
|
|
10
|
-
*
|
|
11
|
-
* @copyright (c) 2024 R-libre ingenierie
|
|
12
|
-
*
|
|
13
|
-
* Use of this source code is governed by an MIT-style license
|
|
14
|
-
* that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
|
15
|
-
**/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* language definition
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
interface Language {
|
|
23
|
-
name: string;
|
|
24
|
-
base: string;
|
|
25
|
-
src_translations: any;
|
|
26
|
-
translations: any;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const sym_lang = Symbol( "i18n" );
|
|
30
|
-
|
|
31
|
-
let languages: Record<string,Language> = {
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* create a new language
|
|
36
|
-
* @param name language name (code)
|
|
37
|
-
* @param base base language (code)
|
|
38
|
-
* @example:
|
|
39
|
-
* ```js
|
|
40
|
-
* createLanguage( 'en', 'fr' );
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
export function createLanguage( name: string, base: string ) {
|
|
45
|
-
languages[name] = {
|
|
46
|
-
name,
|
|
47
|
-
base,
|
|
48
|
-
src_translations: {},
|
|
49
|
-
translations: {}
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* check if the given language is known
|
|
55
|
-
* @param name language name (code)
|
|
56
|
-
*/
|
|
57
|
-
|
|
58
|
-
export function isLanguage( name: string ): boolean {
|
|
59
|
-
return languages[name]!==undefined;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* build the language with given fragments
|
|
64
|
-
* @param name language name (code)
|
|
65
|
-
* @param parts misc elements that make the language
|
|
66
|
-
* @example:
|
|
67
|
-
* ```js
|
|
68
|
-
* createLanguage( 'en', 'fr' );
|
|
69
|
-
* const app = {
|
|
70
|
-
* clients: {
|
|
71
|
-
* translation1: "hello",
|
|
72
|
-
* }
|
|
73
|
-
* }
|
|
74
|
-
* addTranslation( 'en', app );
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
export function addTranslation( name: string, ...parts: any[] ) {
|
|
79
|
-
|
|
80
|
-
if( !isLanguage(name) ) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const lang = languages[name];
|
|
85
|
-
|
|
86
|
-
parts.forEach( p => {
|
|
87
|
-
_patch( lang.src_translations, p );
|
|
88
|
-
} );
|
|
89
|
-
|
|
90
|
-
lang.translations = _proxyfy( lang.src_translations, lang.base, true );
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* patch the base object with the given object
|
|
95
|
-
* (real patch)
|
|
96
|
-
*/
|
|
97
|
-
|
|
98
|
-
function _patch( obj: any, by: any ) {
|
|
99
|
-
|
|
100
|
-
for( const n in by ) {
|
|
101
|
-
const src = by[n];
|
|
102
|
-
if( typeof src === "string" ) {
|
|
103
|
-
obj[n] = src;
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
if( Array.isArray(src) && (!obj[n] || !Array.isArray(obj[n])) ) {
|
|
107
|
-
obj[n] = [...src];
|
|
108
|
-
}
|
|
109
|
-
else if( !obj[n] || (typeof obj[n] !== "object") ) {
|
|
110
|
-
obj[n] = { ...src };
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
_patch( obj[n], by[n] );
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* create a proxy for all sub objects
|
|
121
|
-
* (deep traverse)
|
|
122
|
-
*/
|
|
123
|
-
|
|
124
|
-
function _proxyfy( obj: any, base: any, root: any ) {
|
|
125
|
-
|
|
126
|
-
const result: any = {}
|
|
127
|
-
|
|
128
|
-
for( const n in obj ) {
|
|
129
|
-
if( typeof obj[n]!=="string" && !Array.isArray(obj[n])) {
|
|
130
|
-
result[n] = _proxyfy( obj[n], base, false );
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
result[n] = obj[n];
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return _mk_proxy( result, base, root );
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* create a proxy for the given object
|
|
143
|
-
*/
|
|
144
|
-
|
|
145
|
-
function _mk_proxy( obj: any, base: string, root: boolean ) : any {
|
|
146
|
-
return new Proxy( obj, {
|
|
147
|
-
get: (target, prop) => {
|
|
148
|
-
if( root ) {
|
|
149
|
-
req_path = [prop];
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
req_path.push( prop );
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
let value = target[prop];
|
|
156
|
-
if( value===undefined ) {
|
|
157
|
-
if( base ) {
|
|
158
|
-
value = _findBaseTrans( base );
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if( value===undefined ) {
|
|
162
|
-
console.error( "I18N error: unable to find", '_tr.'+req_path.join('.') );
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return value;
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* when we ask for _tr.xxx
|
|
174
|
-
* reqpath is set to [xxx]
|
|
175
|
-
*
|
|
176
|
-
* then when we try to get _tr.xxx.yyy
|
|
177
|
-
* reqpath is [xxx,yyy]
|
|
178
|
-
* if yyy is not found, we try with base langage for the full reqpath
|
|
179
|
-
* until no base found
|
|
180
|
-
*/
|
|
181
|
-
|
|
182
|
-
let req_path: (string | symbol)[];
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
*
|
|
186
|
-
*/
|
|
187
|
-
|
|
188
|
-
function _findBaseTrans( base: any ) {
|
|
189
|
-
|
|
190
|
-
while( base ) {
|
|
191
|
-
const lang = languages[base];
|
|
192
|
-
let trans = lang.translations;
|
|
193
|
-
let value;
|
|
194
|
-
|
|
195
|
-
for( const p of req_path ) {
|
|
196
|
-
value = trans[p];
|
|
197
|
-
if( value===undefined ) {
|
|
198
|
-
break;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
trans = value;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if( value!==undefined ) {
|
|
205
|
-
return trans;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
base = lang.base;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
return undefined;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export let _tr: Partial<typeof fr> = {};
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* select the given language as current
|
|
218
|
-
* @param name laguage name (code)
|
|
219
|
-
*/
|
|
220
|
-
|
|
221
|
-
export function selectLanguage( name: string ) {
|
|
222
|
-
|
|
223
|
-
if( !isLanguage(name) ) {
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
_tr = languages[name].translations;
|
|
228
|
-
(_tr as any)[sym_lang] = name;
|
|
229
|
-
return _tr;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
*
|
|
234
|
-
*/
|
|
235
|
-
|
|
236
|
-
export function getCurrentLanguage( ): string {
|
|
237
|
-
return (_tr as any)[sym_lang];
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
*
|
|
242
|
-
*/
|
|
243
|
-
|
|
244
|
-
export function getAvailableLanguages( ): string[] {
|
|
245
|
-
return Object.keys( languages );
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* language definition
|
|
253
|
-
* x4 specific strings
|
|
254
|
-
*/
|
|
255
|
-
|
|
256
|
-
let fr = {
|
|
257
|
-
global: {
|
|
258
|
-
ok: 'OK',
|
|
259
|
-
cancel: 'Annuler',
|
|
260
|
-
ignore: 'Ignorer',
|
|
261
|
-
yes: 'Oui',
|
|
262
|
-
no: 'Non',
|
|
263
|
-
abort: "Abandonner",
|
|
264
|
-
retry: "Réessayer",
|
|
265
|
-
|
|
266
|
-
error: "Erreur",
|
|
267
|
-
today: "Aujourd'hui",
|
|
268
|
-
|
|
269
|
-
open: 'Ouvrir',
|
|
270
|
-
new: 'Nouveau',
|
|
271
|
-
delete: 'Supprimer',
|
|
272
|
-
close: 'Fermer',
|
|
273
|
-
save: 'Enregistrer',
|
|
274
|
-
|
|
275
|
-
search: 'Rechercher',
|
|
276
|
-
search_tip: 'Saisissez le texte à rechercher. <b>Enter</b> pour lancer la recherche. <b>Esc</b> pour annuler.',
|
|
277
|
-
|
|
278
|
-
required_field: "information requise",
|
|
279
|
-
invalid_format: "format invalide",
|
|
280
|
-
invalid_email: 'adresse mail invalide',
|
|
281
|
-
invalid_number: 'valeur numérique invalide',
|
|
282
|
-
|
|
283
|
-
diff_date_seconds: '{0} secondes',
|
|
284
|
-
diff_date_minutes: '{0} minutes',
|
|
285
|
-
diff_date_hours: '{0} heures',
|
|
286
|
-
|
|
287
|
-
invalid_date: 'Date non reconnue ({0})',
|
|
288
|
-
empty_list: 'Liste vide',
|
|
289
|
-
|
|
290
|
-
date_input_formats: 'd/m/y|d.m.y|d m y|d-m-y|dmy',
|
|
291
|
-
date_format: 'D/M/Y',
|
|
292
|
-
|
|
293
|
-
day_short: [ 'dim', 'lun', 'mar', 'mer', 'jeu', 'ven', 'sam' ],
|
|
294
|
-
day_long: [ 'dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi' ],
|
|
295
|
-
|
|
296
|
-
month_short: [ 'jan', 'fév', 'mar', 'avr', 'mai', 'jun', 'jui', 'aoû', 'sep', 'oct', 'nov', 'déc' ],
|
|
297
|
-
month_long: [ 'janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre' ],
|
|
298
|
-
|
|
299
|
-
property: 'Propriété',
|
|
300
|
-
value: 'Valeur',
|
|
301
|
-
|
|
302
|
-
err_403: `Vous n'avez pas les droits suffisants pour effectuer cette action`,
|
|
303
|
-
|
|
304
|
-
copy: 'Copier',
|
|
305
|
-
cut: 'Couper',
|
|
306
|
-
paste: 'Coller',
|
|
307
|
-
|
|
308
|
-
filedrop: 'Déposez un fichier',
|
|
309
|
-
|
|
310
|
-
keyboard: {
|
|
311
|
-
next: 'Suivant',
|
|
312
|
-
numeric: '123',
|
|
313
|
-
alpha: 'Abc'
|
|
314
|
-
},
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
/** @ignore */
|
|
319
|
-
|
|
320
|
-
let en = {
|
|
321
|
-
global: {
|
|
322
|
-
ok: 'OK',
|
|
323
|
-
cancel: 'Cancel',
|
|
324
|
-
ignore: 'Ignore',
|
|
325
|
-
yes: 'Yes',
|
|
326
|
-
no: 'No',
|
|
327
|
-
abort: "Abort",
|
|
328
|
-
retry: "Retry",
|
|
329
|
-
|
|
330
|
-
error: "Error",
|
|
331
|
-
today: "Today",
|
|
332
|
-
|
|
333
|
-
open: 'Open',
|
|
334
|
-
new: 'New',
|
|
335
|
-
delete: 'Delete',
|
|
336
|
-
close: 'Close',
|
|
337
|
-
save: 'Save',
|
|
338
|
-
|
|
339
|
-
search: 'Search',
|
|
340
|
-
search_tip: 'Type in the text to search. <b>Enter</b> to start the search. <b>Esc</b> to cancel.',
|
|
341
|
-
|
|
342
|
-
required_field: "missing information",
|
|
343
|
-
invalid_format: "invalid format",
|
|
344
|
-
invalid_email: 'invalid email address',
|
|
345
|
-
invalid_number: 'bad numeric value',
|
|
346
|
-
|
|
347
|
-
diff_date_seconds: '{0} seconds',
|
|
348
|
-
diff_date_minutes: '{0} minutes',
|
|
349
|
-
diff_date_hours: '{0} hours',
|
|
350
|
-
|
|
351
|
-
invalid_date: 'Unrecognized date({0})',
|
|
352
|
-
empty_list: 'Empty list',
|
|
353
|
-
|
|
354
|
-
date_input_formats: 'm/d/y|m.d.y|m d y|m-d-y|mdy',
|
|
355
|
-
date_format: 'M/D/Y',
|
|
356
|
-
|
|
357
|
-
day_short: [ 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat' ],
|
|
358
|
-
day_long: [ 'sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday' ],
|
|
359
|
-
|
|
360
|
-
month_short: [ 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jui', 'aug', 'sep', 'oct', 'nov', 'dec' ],
|
|
361
|
-
month_long: [ 'january', 'february', 'march', 'april', 'mau', 'june', 'jully', 'august', 'september', 'october', 'november', 'december' ],
|
|
362
|
-
|
|
363
|
-
property: 'Property',
|
|
364
|
-
value: 'Value',
|
|
365
|
-
|
|
366
|
-
err_403: `You do not have sufficient rights to do that action`,
|
|
367
|
-
|
|
368
|
-
copy: 'Copy',
|
|
369
|
-
cut: 'Cut',
|
|
370
|
-
paste: 'Paste',
|
|
371
|
-
|
|
372
|
-
filedrop: 'Drop a file',
|
|
373
|
-
|
|
374
|
-
keyboard: {
|
|
375
|
-
next: 'Next',
|
|
376
|
-
numeric: '123',
|
|
377
|
-
alpha: 'Abc'
|
|
378
|
-
},
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
createLanguage( 'fr', null );
|
|
383
|
-
addTranslation( 'fr', fr );
|
|
384
|
-
|
|
385
|
-
createLanguage( 'en', 'fr' );
|
|
386
|
-
addTranslation( 'en', en );
|
|
387
|
-
|
|
388
|
-
selectLanguage( 'fr' ); // by default
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|