x4js 1.4.20 → 1.4.24
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 +4 -3
- package/lib/action.d.ts +57 -0
- package/lib/action.js +59 -0
- package/lib/application.d.ts +2 -1
- package/lib/application.js +15 -11
- package/lib/base_component.d.ts +6 -0
- package/lib/base_component.js +13 -0
- package/lib/button.d.ts +2 -0
- package/lib/button.js +18 -4
- package/lib/component.d.ts +0 -1
- package/lib/component.js +0 -8
- package/lib/icon.js +9 -3
- package/lib/menu.d.ts +4 -0
- package/lib/menu.js +17 -1
- package/lib/settings.js +2 -3
- package/lib/x4dom.d.ts +29 -1
- package/lib/x4dom.js +27 -2
- package/lib/x4events.d.ts +1 -1
- package/lib/x4events.js +1 -1
- package/package.json +1 -1
- package/src/action.ts +88 -0
- package/src/application.ts +19 -10
- package/src/base_component.ts +15 -0
- package/src/button.ts +25 -5
- package/src/component.ts +4 -10
- package/src/icon.ts +9 -4
- package/src/menu.ts +24 -2
- package/src/settings.ts +2 -4
- package/tsconfig.json +0 -2
- package/src/hosts/electron.ts +0 -164
- package/src/hosts/host.ts +0 -100
- package/src/hosts/nwjs.ts +0 -141
- package/src/hosts/nwjs_types.ts +0 -339
- package/src/smartedit.ts +0 -537
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
#
|
|
2
|
-
x4 framework repository
|
|
1
|
+
# x4js framework
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
This is the x4 framework repository.
|
|
4
|
+
|
|
5
|
+
You will find the documentation & tutorials [Here](https://x4js.org)
|
package/lib/action.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file action.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
|
+
import { BasicEvent } from './x4events';
|
|
30
|
+
import { BaseComponent, BaseComponentEventMap, BaseComponentProps } from './base_component';
|
|
31
|
+
import { IconID } from "./icon";
|
|
32
|
+
import { EvChange, EventHandler } from 'x4js';
|
|
33
|
+
export interface EvAction extends BasicEvent {
|
|
34
|
+
}
|
|
35
|
+
export declare function EvAction(source: Action): EvAction;
|
|
36
|
+
interface ActionEventMap extends BaseComponentEventMap {
|
|
37
|
+
run: EvAction;
|
|
38
|
+
change: EvChange;
|
|
39
|
+
}
|
|
40
|
+
interface ActionProps extends BaseComponentProps<ActionEventMap> {
|
|
41
|
+
id?: any;
|
|
42
|
+
text?: string;
|
|
43
|
+
icon?: IconID;
|
|
44
|
+
disabled?: boolean;
|
|
45
|
+
hidden?: boolean;
|
|
46
|
+
checked?: boolean;
|
|
47
|
+
run: EventHandler<EvAction>;
|
|
48
|
+
change?: EventHandler<EvChange>;
|
|
49
|
+
}
|
|
50
|
+
export declare class Action extends BaseComponent<ActionProps, ActionEventMap> {
|
|
51
|
+
constructor(props: ActionProps);
|
|
52
|
+
get props(): ActionProps;
|
|
53
|
+
set text(t: string);
|
|
54
|
+
set icon(i: IconID);
|
|
55
|
+
fire(): void;
|
|
56
|
+
}
|
|
57
|
+
export {};
|
package/lib/action.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ___ ___ __
|
|
4
|
+
* \ \/ / / _
|
|
5
|
+
* \ / /_| |_
|
|
6
|
+
* / \____ _|
|
|
7
|
+
* /__/\__\ |_|
|
|
8
|
+
*
|
|
9
|
+
* @file action.ts
|
|
10
|
+
* @author Etienne Cochard
|
|
11
|
+
*
|
|
12
|
+
* Copyright (c) 2019-2022 R-libre ingenierie
|
|
13
|
+
*
|
|
14
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
15
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
16
|
+
* in the Software without restriction, including without limitation the rights
|
|
17
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
18
|
+
* of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
19
|
+
* subject to the following conditions:
|
|
20
|
+
* The above copyright notice and this permission notice shall be included in all copies
|
|
21
|
+
* or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
24
|
+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
25
|
+
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
26
|
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
27
|
+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
28
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
29
|
+
**/
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.Action = exports.EvAction = void 0;
|
|
32
|
+
const x4events_1 = require("./x4events");
|
|
33
|
+
const base_component_1 = require("./base_component");
|
|
34
|
+
const x4js_1 = require("x4js");
|
|
35
|
+
function EvAction(source) {
|
|
36
|
+
return (0, x4events_1.BasicEvent)({ source });
|
|
37
|
+
}
|
|
38
|
+
exports.EvAction = EvAction;
|
|
39
|
+
class Action extends base_component_1.BaseComponent {
|
|
40
|
+
constructor(props) {
|
|
41
|
+
super(props);
|
|
42
|
+
this.mapPropEvents(props, "run");
|
|
43
|
+
}
|
|
44
|
+
get props() {
|
|
45
|
+
return this.m_props;
|
|
46
|
+
}
|
|
47
|
+
set text(t) {
|
|
48
|
+
this.m_props.text = t;
|
|
49
|
+
this.emit("change", (0, x4js_1.EvChange)(this));
|
|
50
|
+
}
|
|
51
|
+
set icon(i) {
|
|
52
|
+
this.m_props.icon = i;
|
|
53
|
+
this.emit("change", (0, x4js_1.EvChange)(this));
|
|
54
|
+
}
|
|
55
|
+
fire() {
|
|
56
|
+
this.emit("run", EvAction(this));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.Action = Action;
|
package/lib/application.d.ts
CHANGED
|
@@ -91,8 +91,9 @@ export declare class Application<P extends ApplicationProps = ApplicationProps,
|
|
|
91
91
|
*
|
|
92
92
|
* let myApp = new Application( ... );
|
|
93
93
|
* let mainView = new VLayout( ... );
|
|
94
|
-
* myApp.
|
|
94
|
+
* myApp.mainView = mainView;
|
|
95
95
|
*/
|
|
96
|
+
setMainView(root: Component, clearBefore: boolean): void;
|
|
96
97
|
set mainView(root: Component);
|
|
97
98
|
get mainView(): Component;
|
|
98
99
|
setTitle(title: string): void;
|
package/lib/application.js
CHANGED
|
@@ -33,7 +33,7 @@ const x4dom_1 = require("./x4dom");
|
|
|
33
33
|
const base_component_1 = require("./base_component");
|
|
34
34
|
const component_1 = require("./component");
|
|
35
35
|
const settings_1 = require("./settings");
|
|
36
|
-
const
|
|
36
|
+
const x4js_1 = require("x4js");
|
|
37
37
|
const _x4_touch_time = Symbol();
|
|
38
38
|
/**
|
|
39
39
|
* Represents an x4 application, which is typically a single page app.
|
|
@@ -123,18 +123,22 @@ class Application extends base_component_1.BaseComponent {
|
|
|
123
123
|
*
|
|
124
124
|
* let myApp = new Application( ... );
|
|
125
125
|
* let mainView = new VLayout( ... );
|
|
126
|
-
* myApp.
|
|
126
|
+
* myApp.mainView = mainView;
|
|
127
127
|
*/
|
|
128
|
-
|
|
128
|
+
setMainView(root, clearBefore) {
|
|
129
|
+
const ddom = this.m_props.renderTo ?? x4dom_1.x4document.body;
|
|
130
|
+
const dest = (0, x4js_1.flyWrap)(ddom);
|
|
131
|
+
dest.addClass('x4-root-element');
|
|
132
|
+
if (clearBefore) {
|
|
133
|
+
dest._empty();
|
|
134
|
+
}
|
|
129
135
|
this.m_mainView = root;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
dest.appendChild(root._build());
|
|
137
|
-
});
|
|
136
|
+
root.setStyleValue('position', 'absolute');
|
|
137
|
+
root._build();
|
|
138
|
+
ddom.appendChild(root.dom);
|
|
139
|
+
}
|
|
140
|
+
set mainView(root) {
|
|
141
|
+
this.setMainView(root, false);
|
|
138
142
|
}
|
|
139
143
|
get mainView() {
|
|
140
144
|
return this.m_mainView;
|
package/lib/base_component.d.ts
CHANGED
|
@@ -77,5 +77,11 @@ export declare class BaseComponent<P extends BaseComponentProps<BaseComponentEve
|
|
|
77
77
|
* @param timeout
|
|
78
78
|
*/
|
|
79
79
|
singleShot(callback: TimerCallback, timeout?: number): void;
|
|
80
|
+
/**
|
|
81
|
+
*
|
|
82
|
+
* @param props
|
|
83
|
+
* @param elements
|
|
84
|
+
*/
|
|
85
|
+
mapPropEvents<N extends keyof E>(props: P, ...elements: N[]): void;
|
|
80
86
|
}
|
|
81
87
|
export {};
|
package/lib/base_component.js
CHANGED
|
@@ -94,5 +94,18 @@ class BaseComponent extends x4events_1.EventSource {
|
|
|
94
94
|
singleShot(callback, timeout = 0) {
|
|
95
95
|
setTimeout(callback, timeout);
|
|
96
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
*
|
|
99
|
+
* @param props
|
|
100
|
+
* @param elements
|
|
101
|
+
*/
|
|
102
|
+
mapPropEvents(props, ...elements) {
|
|
103
|
+
elements.forEach(name => {
|
|
104
|
+
const n = name;
|
|
105
|
+
if (props[n]) {
|
|
106
|
+
this._on(n, props[n]);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
97
110
|
}
|
|
98
111
|
exports.BaseComponent = BaseComponent;
|
package/lib/button.d.ts
CHANGED
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
**/
|
|
29
29
|
import { Component, CProps, CEventMap, HtmlString } from './component';
|
|
30
30
|
import { EventCallback, EvClick, EvChange } from './x4events';
|
|
31
|
+
import { Action } from './action';
|
|
31
32
|
import { IconID } from './icon';
|
|
32
33
|
import { MenuItem, MenuOrSep } from './menu';
|
|
33
34
|
/**
|
|
@@ -48,6 +49,7 @@ interface ButtonProps<E extends ButtonEventMap = ButtonEventMap> extends CProps<
|
|
|
48
49
|
autoRepeat?: number;
|
|
49
50
|
menu?: MenuOrSep[] | MenuCallBack;
|
|
50
51
|
click?: EventCallback<EvClick>;
|
|
52
|
+
action?: Action;
|
|
51
53
|
}
|
|
52
54
|
/**
|
|
53
55
|
* Base button
|
package/lib/button.js
CHANGED
|
@@ -49,10 +49,21 @@ class BaseButton extends component_1.Component {
|
|
|
49
49
|
this.mapPropEvents(props, 'click');
|
|
50
50
|
}
|
|
51
51
|
render(props) {
|
|
52
|
-
|
|
53
|
-
let
|
|
54
|
-
let
|
|
55
|
-
|
|
52
|
+
const action = props.action;
|
|
53
|
+
let icon = props.icon;
|
|
54
|
+
let text = props.text;
|
|
55
|
+
if (action) {
|
|
56
|
+
if (!icon && action.props.icon) {
|
|
57
|
+
icon = action.props.icon;
|
|
58
|
+
}
|
|
59
|
+
if (text === undefined && action.props.text) {
|
|
60
|
+
text = action.props.text;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const ui_icon = icon ? new icon_1.Icon({ icon, cls: 'left', ref: 'l_icon' }) : null;
|
|
64
|
+
const ui_label = new label_1.Label({ flex: 1, text: text ?? '', align: props.align, ref: 'label' });
|
|
65
|
+
const ui_ricon = props.rightIcon ? new icon_1.Icon({ icon: props.rightIcon, cls: 'right', ref: 'r_icon' }) : null;
|
|
66
|
+
this.setContent([ui_icon, ui_label, ui_ricon]);
|
|
56
67
|
this._setTabIndex(props.tabIndex);
|
|
57
68
|
}
|
|
58
69
|
/**
|
|
@@ -115,6 +126,9 @@ class BaseButton extends component_1.Component {
|
|
|
115
126
|
}
|
|
116
127
|
else {
|
|
117
128
|
this.emit('click', (0, x4events_1.EvClick)());
|
|
129
|
+
if (this.m_props.action) {
|
|
130
|
+
this.m_props.action.fire();
|
|
131
|
+
}
|
|
118
132
|
}
|
|
119
133
|
}
|
|
120
134
|
/**
|
package/lib/component.d.ts
CHANGED
|
@@ -314,7 +314,6 @@ export declare class Component<P extends CProps<BaseComponentEventMap> = CProps<
|
|
|
314
314
|
*
|
|
315
315
|
*/
|
|
316
316
|
clearDomEvent<K extends keyof X4ElementEventMap>(type: K): void;
|
|
317
|
-
mapPropEvents<N extends keyof E>(props: P, ...elements: N[]): void;
|
|
318
317
|
/**
|
|
319
318
|
*
|
|
320
319
|
* @param name
|
package/lib/component.js
CHANGED
|
@@ -849,14 +849,6 @@ class Component extends base_component_1.BaseComponent {
|
|
|
849
849
|
}
|
|
850
850
|
}
|
|
851
851
|
}
|
|
852
|
-
mapPropEvents(props, ...elements) {
|
|
853
|
-
elements.forEach(name => {
|
|
854
|
-
const n = name;
|
|
855
|
-
if (props[n]) {
|
|
856
|
-
this._on(n, props[n]);
|
|
857
|
-
}
|
|
858
|
-
});
|
|
859
|
-
}
|
|
860
852
|
/**
|
|
861
853
|
*
|
|
862
854
|
* @param name
|
package/lib/icon.js
CHANGED
|
@@ -75,9 +75,15 @@ class Loader extends x4events_1.EventSource {
|
|
|
75
75
|
const r = await fetch(url);
|
|
76
76
|
if (r.ok) {
|
|
77
77
|
const svg = await r.text();
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
// check response, must be svg
|
|
79
|
+
if (!svg.startsWith("<svg")) {
|
|
80
|
+
console.error("svg loading error: ", svg);
|
|
81
|
+
this.signal('loaded', EvLoaded(url, ""));
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
this.svgs.set(url, svg);
|
|
85
|
+
this.signal('loaded', EvLoaded(url, svg));
|
|
86
|
+
}
|
|
81
87
|
}
|
|
82
88
|
}
|
|
83
89
|
};
|
package/lib/menu.d.ts
CHANGED
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
**/
|
|
29
29
|
import { CEventMap, Component, CProps } from './component';
|
|
30
30
|
import { EvClick, EventCallback } from './x4events';
|
|
31
|
+
import { Action } from './action';
|
|
31
32
|
import { Popup, PopupProps } from './popup';
|
|
32
33
|
import { IconID } from './icon';
|
|
33
34
|
import { Label } from './label';
|
|
@@ -99,10 +100,13 @@ export interface MenuItemProps extends CProps {
|
|
|
99
100
|
checked?: boolean;
|
|
100
101
|
cls?: string;
|
|
101
102
|
click?: EventCallback<EvClick>;
|
|
103
|
+
action?: Action;
|
|
102
104
|
}
|
|
103
105
|
export declare class MenuItem extends Component<MenuItemProps, MenuItemEventMap> {
|
|
104
106
|
private m_menu;
|
|
105
107
|
private m_isOpen;
|
|
108
|
+
private m_action;
|
|
109
|
+
constructor(action: Action);
|
|
106
110
|
constructor(text: string, click: EventCallback<EvClick>);
|
|
107
111
|
constructor(props: MenuItemProps);
|
|
108
112
|
/** @ignore */
|
package/lib/menu.js
CHANGED
|
@@ -32,6 +32,7 @@ exports.MenuBar = exports.MenuItem = exports.Menu = exports.MenuTitle = exports.
|
|
|
32
32
|
const x4dom_1 = require("./x4dom");
|
|
33
33
|
const component_1 = require("./component");
|
|
34
34
|
const x4events_1 = require("./x4events");
|
|
35
|
+
const action_1 = require("./action");
|
|
35
36
|
const popup_1 = require("./popup");
|
|
36
37
|
const icon_1 = require("./icon");
|
|
37
38
|
const label_1 = require("./label");
|
|
@@ -177,8 +178,15 @@ exports.Menu = Menu;
|
|
|
177
178
|
class MenuItem extends component_1.Component {
|
|
178
179
|
m_menu;
|
|
179
180
|
m_isOpen;
|
|
181
|
+
m_action;
|
|
180
182
|
constructor(a, b) {
|
|
181
|
-
if (
|
|
183
|
+
if (a instanceof action_1.Action) {
|
|
184
|
+
super({
|
|
185
|
+
click: () => { a.fire(); }
|
|
186
|
+
});
|
|
187
|
+
this.m_action = a;
|
|
188
|
+
}
|
|
189
|
+
else if ((0, tools_1.isString)(a)) {
|
|
182
190
|
super({
|
|
183
191
|
text: a,
|
|
184
192
|
click: b
|
|
@@ -200,6 +208,14 @@ class MenuItem extends component_1.Component {
|
|
|
200
208
|
if (props.checked !== undefined) {
|
|
201
209
|
icon = props.checked ? 'cls(far fa-check)' : 0; //todo: use stylesheet
|
|
202
210
|
}
|
|
211
|
+
if (this.m_action) {
|
|
212
|
+
if (!icon) {
|
|
213
|
+
icon = this.m_action.props.icon;
|
|
214
|
+
}
|
|
215
|
+
if (text === undefined) {
|
|
216
|
+
text = this.m_action.props.text;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
203
219
|
let popIco = null;
|
|
204
220
|
if (this.isPopup) {
|
|
205
221
|
this.addClass('@popup-menu-item');
|
package/lib/settings.js
CHANGED
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
**/
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
31
|
exports.Settings = void 0;
|
|
32
|
-
const host_1 = require("./hosts/host");
|
|
33
32
|
class Settings {
|
|
34
33
|
m_data;
|
|
35
34
|
m_name;
|
|
@@ -48,14 +47,14 @@ class Settings {
|
|
|
48
47
|
}
|
|
49
48
|
_save() {
|
|
50
49
|
let data = JSON.stringify(this.m_data);
|
|
51
|
-
|
|
50
|
+
localStorage.setItem(this.m_name, data);
|
|
52
51
|
}
|
|
53
52
|
_load() {
|
|
54
53
|
if (this.m_data) {
|
|
55
54
|
return;
|
|
56
55
|
}
|
|
57
56
|
this.m_data = {};
|
|
58
|
-
let data =
|
|
57
|
+
let data = localStorage.getItem(this.m_name);
|
|
59
58
|
if (data !== null) {
|
|
60
59
|
data = JSON.parse(data);
|
|
61
60
|
if (data) {
|
package/lib/x4dom.d.ts
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
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
|
+
* SSR preparation
|
|
3
31
|
*/
|
|
4
32
|
interface IX4Document {
|
|
5
33
|
createElement<K extends keyof HTMLElementTagNameMap>(tagName: K, options?: ElementCreationOptions): HTMLElementTagNameMap[K];
|
package/lib/x4dom.js
CHANGED
|
@@ -1,7 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
* ___ ___ __
|
|
4
|
+
* \ \_/ / / _
|
|
5
|
+
* \ / /_| |_
|
|
6
|
+
* / _ \____ _|
|
|
7
|
+
* /__/ \__\ |_|
|
|
8
|
+
*
|
|
9
|
+
* @file x4events.ts
|
|
10
|
+
* @author Etienne Cochard
|
|
11
|
+
*
|
|
12
|
+
* Copyright (c) 2019-2022 R-libre ingenierie
|
|
13
|
+
*
|
|
14
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
15
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
16
|
+
* in the Software without restriction, including without limitation the rights
|
|
17
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
18
|
+
* of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
19
|
+
* subject to the following conditions:
|
|
20
|
+
* The above copyright notice and this permission notice shall be included in all copies
|
|
21
|
+
* or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
24
|
+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
25
|
+
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
26
|
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
27
|
+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
28
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
29
|
+
**/
|
|
5
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
31
|
exports.x4document = void 0;
|
|
7
32
|
exports.x4document = document;
|
package/lib/x4events.d.ts
CHANGED
package/lib/x4events.js
CHANGED
package/package.json
CHANGED
package/src/action.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file action.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
|
+
import { BasicEvent } from './x4events'
|
|
31
|
+
import { BaseComponent, BaseComponentEventMap, BaseComponentProps } from './base_component'
|
|
32
|
+
import { IconID } from "./icon"
|
|
33
|
+
import { EvChange, EventHandler } from 'x4js';
|
|
34
|
+
|
|
35
|
+
//TODO: implement all
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
export interface EvAction extends BasicEvent {
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function EvAction( source: Action ) {
|
|
42
|
+
return BasicEvent<EvAction>({source});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface ActionEventMap extends BaseComponentEventMap {
|
|
46
|
+
run: EvAction;
|
|
47
|
+
change: EvChange;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface ActionProps extends BaseComponentProps<ActionEventMap> {
|
|
51
|
+
id?: any;
|
|
52
|
+
text?: string;
|
|
53
|
+
icon?: IconID;
|
|
54
|
+
disabled?: boolean;
|
|
55
|
+
hidden?: boolean;
|
|
56
|
+
checked?: boolean;
|
|
57
|
+
|
|
58
|
+
run: EventHandler<EvAction>;
|
|
59
|
+
change?: EventHandler<EvChange>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export class Action extends BaseComponent<ActionProps,ActionEventMap> {
|
|
63
|
+
|
|
64
|
+
constructor( props: ActionProps ) {
|
|
65
|
+
super( props );
|
|
66
|
+
|
|
67
|
+
this.mapPropEvents( props, "run" );
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get props( ) {
|
|
71
|
+
return this.m_props;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
set text( t: string ) {
|
|
75
|
+
this.m_props.text = t;
|
|
76
|
+
this.emit( "change", EvChange(this) );
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
set icon( i: IconID ) {
|
|
80
|
+
this.m_props.icon = i;
|
|
81
|
+
this.emit( "change", EvChange(this) );
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
fire( ) {
|
|
85
|
+
this.emit( "run", EvAction(this) );
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
package/src/application.ts
CHANGED
|
@@ -34,6 +34,7 @@ import { Component } from './component'
|
|
|
34
34
|
import { Settings } from './settings'
|
|
35
35
|
import { deferCall } from './tools'
|
|
36
36
|
import { _tr } from './i18n'
|
|
37
|
+
import { flyWrap } from 'x4js'
|
|
37
38
|
|
|
38
39
|
const _x4_touch_time = Symbol( );
|
|
39
40
|
|
|
@@ -165,21 +166,29 @@ export class Application<P extends ApplicationProps = ApplicationProps, E extend
|
|
|
165
166
|
*
|
|
166
167
|
* let myApp = new Application( ... );
|
|
167
168
|
* let mainView = new VLayout( ... );
|
|
168
|
-
* myApp.
|
|
169
|
+
* myApp.mainView = mainView;
|
|
169
170
|
*/
|
|
170
171
|
|
|
171
|
-
public
|
|
172
|
+
public setMainView( root: Component, clearBefore: boolean ) {
|
|
173
|
+
|
|
174
|
+
const ddom = this.m_props.renderTo ?? x4document.body;
|
|
175
|
+
const dest = flyWrap( ddom );
|
|
176
|
+
|
|
177
|
+
dest.addClass( 'x4-root-element' );
|
|
178
|
+
if( clearBefore ) {
|
|
179
|
+
dest._empty( );
|
|
180
|
+
}
|
|
172
181
|
|
|
173
182
|
this.m_mainView = root;
|
|
174
|
-
this.mainView.addClass( 'x4-root-element' );
|
|
175
183
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
184
|
+
root.setStyleValue( 'position', 'absolute' );
|
|
185
|
+
root._build();
|
|
186
|
+
|
|
187
|
+
ddom.appendChild( root.dom );
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
set mainView( root: Component ) {
|
|
191
|
+
this.setMainView( root, false );
|
|
183
192
|
}
|
|
184
193
|
|
|
185
194
|
public get mainView( ) : Component {
|
package/src/base_component.ts
CHANGED
|
@@ -132,4 +132,19 @@ export class BaseComponent< P extends BaseComponentProps<BaseComponentEventMap>,
|
|
|
132
132
|
singleShot( callback: TimerCallback, timeout = 0 ) {
|
|
133
133
|
setTimeout( callback, timeout );
|
|
134
134
|
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
*
|
|
138
|
+
* @param props
|
|
139
|
+
* @param elements
|
|
140
|
+
*/
|
|
141
|
+
|
|
142
|
+
public mapPropEvents<N extends keyof E>(props: P, ...elements: N[] ) {
|
|
143
|
+
elements.forEach( name => {
|
|
144
|
+
const n = name as string;
|
|
145
|
+
if (props[n]) {
|
|
146
|
+
this._on(n, props[n]);
|
|
147
|
+
}
|
|
148
|
+
})
|
|
149
|
+
}
|
|
135
150
|
}
|