@arcanejs/toolkit 0.3.0 → 0.4.0
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/dist/backend/components/base.d.mts +5 -1
- package/dist/backend/components/base.d.ts +5 -1
- package/dist/backend/components/base.js +2 -2
- package/dist/backend/components/base.mjs +1 -1
- package/dist/backend/components/button.js +3 -3
- package/dist/backend/components/button.mjs +2 -2
- package/dist/backend/components/group.js +3 -3
- package/dist/backend/components/group.mjs +2 -2
- package/dist/backend/components/label.js +3 -3
- package/dist/backend/components/label.mjs +2 -2
- package/dist/backend/components/rect.js +3 -3
- package/dist/backend/components/rect.mjs +2 -2
- package/dist/backend/components/slider-button.d.mts +9 -4
- package/dist/backend/components/slider-button.d.ts +9 -4
- package/dist/backend/components/slider-button.js +3 -3
- package/dist/backend/components/slider-button.mjs +2 -2
- package/dist/backend/components/switch.d.mts +8 -1
- package/dist/backend/components/switch.d.ts +8 -1
- package/dist/backend/components/switch.js +3 -3
- package/dist/backend/components/switch.mjs +2 -2
- package/dist/backend/components/tabs.js +3 -3
- package/dist/backend/components/tabs.mjs +2 -2
- package/dist/backend/components/text-input.js +3 -3
- package/dist/backend/components/text-input.mjs +2 -2
- package/dist/backend/components/timeline.js +3 -3
- package/dist/backend/components/timeline.mjs +2 -2
- package/dist/{chunk-QUA3NBLD.js → chunk-4HHKW7VA.js} +4 -4
- package/dist/{chunk-J46AJUGE.js → chunk-4X3QY5EP.js} +3 -3
- package/dist/{chunk-H2UQDFTS.mjs → chunk-A2STBGBE.mjs} +28 -11
- package/dist/{chunk-WXSKMMCV.js → chunk-C2TVGO43.js} +3 -3
- package/dist/{chunk-NZUYU32Z.js → chunk-CFO5PSSK.js} +25 -20
- package/dist/{chunk-POUQGJN4.mjs → chunk-DBSYI5Z4.mjs} +1 -1
- package/dist/{chunk-IW3JCC73.js → chunk-DONU33U4.js} +3 -3
- package/dist/{chunk-TSC5C5XR.js → chunk-FLRGYURV.js} +2 -2
- package/dist/{chunk-DV5WTSFW.js → chunk-FUINWM5H.js} +2 -2
- package/dist/{chunk-EH73E5FP.mjs → chunk-G5QXW2L3.mjs} +1 -1
- package/dist/chunk-G7GFSIHY.js +76 -0
- package/dist/{chunk-YIXRQHTA.mjs → chunk-H734NV65.mjs} +1 -1
- package/dist/{chunk-7ITSSJE2.mjs → chunk-JOW3XRQI.mjs} +1 -1
- package/dist/{chunk-WIPEQNWR.js → chunk-K572ZPUS.js} +2 -2
- package/dist/{chunk-3Y3HRYLC.mjs → chunk-KBPQZJKE.mjs} +1 -1
- package/dist/{chunk-SMTUN6HG.mjs → chunk-KOKUFP6V.mjs} +1 -1
- package/dist/{chunk-NKNDCRUR.mjs → chunk-KR6LSBBX.mjs} +1 -1
- package/dist/{chunk-EDTJ75FT.mjs → chunk-PW7QVLLF.mjs} +6 -1
- package/dist/chunk-Q3NG5UUN.mjs +61 -0
- package/dist/chunk-Q5TEM6MM.js +61 -0
- package/dist/frontend.js.map +1 -1
- package/dist/index.js +11 -11
- package/dist/index.mjs +10 -10
- package/package.json +5 -3
- package/dist/chunk-DNCHAOYH.js +0 -42
- package/dist/chunk-YN3FZMXY.js +0 -59
- package/dist/chunk-YYM7PBRN.mjs +0 -42
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3;// src/backend/components/base.ts
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3;// src/backend/components/base.ts
|
|
2
2
|
var Base = (_class = class {
|
|
3
3
|
/** @hidden */
|
|
4
4
|
__init() {this.parent = null}
|
|
@@ -6,15 +6,18 @@ var Base = (_class = class {
|
|
|
6
6
|
|
|
7
7
|
/** @hidden */
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
/** @hidden */
|
|
10
|
+
__init2() {this._onPropsUpdated = null}
|
|
11
|
+
constructor(defaultProps, props, options) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);
|
|
10
12
|
this.defaultProps = defaultProps;
|
|
11
13
|
this._props = Object.freeze({
|
|
12
14
|
...defaultProps,
|
|
13
15
|
...props
|
|
14
16
|
});
|
|
17
|
+
this._onPropsUpdated = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _8 => _8.onPropsUpdated]), () => ( null));
|
|
15
18
|
}
|
|
16
|
-
|
|
17
|
-
return _optionalChain([this, 'access',
|
|
19
|
+
__init3() {this.log = () => {
|
|
20
|
+
return _optionalChain([this, 'access', _9 => _9.parent, 'optionalAccess', _10 => _10.log, 'call', _11 => _11()]) || null;
|
|
18
21
|
}}
|
|
19
22
|
get props() {
|
|
20
23
|
return this._props;
|
|
@@ -22,18 +25,20 @@ var Base = (_class = class {
|
|
|
22
25
|
set props(props) {
|
|
23
26
|
this.setProps(props);
|
|
24
27
|
}
|
|
25
|
-
|
|
28
|
+
__init4() {this.setProps = (props) => {
|
|
26
29
|
this._props = Object.freeze({
|
|
27
30
|
...this.defaultProps,
|
|
28
31
|
...props
|
|
29
32
|
});
|
|
33
|
+
_optionalChain([this, 'access', _12 => _12._onPropsUpdated, 'optionalCall', _13 => _13()]);
|
|
30
34
|
this.updateTree();
|
|
31
35
|
}}
|
|
32
|
-
|
|
36
|
+
__init5() {this.updateProps = (updates) => {
|
|
33
37
|
this._props = Object.freeze({
|
|
34
38
|
...this._props,
|
|
35
39
|
...updates
|
|
36
40
|
});
|
|
41
|
+
_optionalChain([this, 'access', _14 => _14._onPropsUpdated, 'optionalCall', _15 => _15()]);
|
|
37
42
|
this.updateTree();
|
|
38
43
|
}}
|
|
39
44
|
/** @hidden */
|
|
@@ -53,10 +58,10 @@ var Base = (_class = class {
|
|
|
53
58
|
routeMessage(_idMap, _message) {
|
|
54
59
|
}
|
|
55
60
|
}, _class);
|
|
56
|
-
var BaseParent = (_class2 = class extends Base {constructor(...args2) { super(...args2); _class2.prototype.
|
|
61
|
+
var BaseParent = (_class2 = class extends Base {constructor(...args2) { super(...args2); _class2.prototype.__init6.call(this);_class2.prototype.__init7.call(this);_class2.prototype.__init8.call(this);_class2.prototype.__init9.call(this);_class2.prototype.__init10.call(this);_class2.prototype.__init11.call(this); }
|
|
57
62
|
/** @hidden */
|
|
58
|
-
|
|
59
|
-
|
|
63
|
+
__init6() {this.children = []}
|
|
64
|
+
__init7() {this.appendChildren = (...children) => {
|
|
60
65
|
for (const c of children) {
|
|
61
66
|
const newChildren = [...this.children.filter((ch) => ch !== c), c];
|
|
62
67
|
this.validateChildren(newChildren);
|
|
@@ -66,11 +71,11 @@ var BaseParent = (_class2 = class extends Base {constructor(...args2) { super(..
|
|
|
66
71
|
this.updateTree();
|
|
67
72
|
return children;
|
|
68
73
|
}}
|
|
69
|
-
|
|
74
|
+
__init8() {this.appendChild = (child) => {
|
|
70
75
|
this.appendChildren(child);
|
|
71
76
|
return child;
|
|
72
77
|
}}
|
|
73
|
-
|
|
78
|
+
__init9() {this.removeChild = (component) => {
|
|
74
79
|
const match = this.children.findIndex((c) => c === component);
|
|
75
80
|
if (match >= 0) {
|
|
76
81
|
const removingChild = this.children[match];
|
|
@@ -80,11 +85,11 @@ var BaseParent = (_class2 = class extends Base {constructor(...args2) { super(..
|
|
|
80
85
|
];
|
|
81
86
|
this.validateChildren(newChildren);
|
|
82
87
|
this.children = Object.freeze(newChildren);
|
|
83
|
-
_optionalChain([removingChild, 'optionalAccess',
|
|
88
|
+
_optionalChain([removingChild, 'optionalAccess', _18 => _18.setParent, 'call', _19 => _19(null)]);
|
|
84
89
|
this.updateTree();
|
|
85
90
|
}
|
|
86
91
|
}}
|
|
87
|
-
|
|
92
|
+
__init10() {this.removeAllChildren = () => {
|
|
88
93
|
this.children.map((c) => c.setParent(null));
|
|
89
94
|
this.children = Object.freeze([]);
|
|
90
95
|
this.updateTree();
|
|
@@ -92,7 +97,7 @@ var BaseParent = (_class2 = class extends Base {constructor(...args2) { super(..
|
|
|
92
97
|
/**
|
|
93
98
|
* Return all children components that messages need to be routed to
|
|
94
99
|
*/
|
|
95
|
-
|
|
100
|
+
__init11() {this.getChildren = () => this.children}
|
|
96
101
|
/**
|
|
97
102
|
* TODO: we can do this better, right now it broadcasts the message to all
|
|
98
103
|
* components of the tree
|
|
@@ -129,9 +134,9 @@ var BaseParent = (_class2 = class extends Base {constructor(...args2) { super(..
|
|
|
129
134
|
this.updateTree();
|
|
130
135
|
}
|
|
131
136
|
}, _class2);
|
|
132
|
-
var EventEmitter = (_class3 = class {constructor() { _class3.prototype.
|
|
133
|
-
|
|
134
|
-
|
|
137
|
+
var EventEmitter = (_class3 = class {constructor() { _class3.prototype.__init12.call(this);_class3.prototype.__init13.call(this);_class3.prototype.__init14.call(this);_class3.prototype.__init15.call(this); }
|
|
138
|
+
__init12() {this.listeners = /* @__PURE__ */ new Map()}
|
|
139
|
+
__init13() {this.addListener = (type, listener) => {
|
|
135
140
|
let set = this.listeners.get(type);
|
|
136
141
|
if (!set) {
|
|
137
142
|
set = /* @__PURE__ */ new Set();
|
|
@@ -139,10 +144,10 @@ var EventEmitter = (_class3 = class {constructor() { _class3.prototype.__init11.
|
|
|
139
144
|
}
|
|
140
145
|
set.add(listener);
|
|
141
146
|
}}
|
|
142
|
-
|
|
143
|
-
_optionalChain([this, 'access',
|
|
147
|
+
__init14() {this.removeListener = (type, listener) => {
|
|
148
|
+
_optionalChain([this, 'access', _25 => _25.listeners, 'access', _26 => _26.get, 'call', _27 => _27(type), 'optionalAccess', _28 => _28.delete, 'call', _29 => _29(listener)]);
|
|
144
149
|
}}
|
|
145
|
-
|
|
150
|
+
__init15() {this.emit = (type, ...args) => {
|
|
146
151
|
return Promise.all(
|
|
147
152
|
[...this.listeners.get(type) || []].map(
|
|
148
153
|
(l) => new Promise((resolve, reject) => {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkCFO5PSSKjs = require('./chunk-CFO5PSSK.js');
|
|
5
5
|
|
|
6
6
|
// src/backend/components/text-input.ts
|
|
7
7
|
var DEFAULT_PROPS = {
|
|
8
8
|
value: null
|
|
9
9
|
};
|
|
10
|
-
var TextInput = (_class = class extends
|
|
10
|
+
var TextInput = (_class = class extends _chunkCFO5PSSKjs.Base {
|
|
11
11
|
/** @hidden */
|
|
12
|
-
__init() {this.events = new (0,
|
|
12
|
+
__init() {this.events = new (0, _chunkCFO5PSSKjs.EventEmitter)()}
|
|
13
13
|
constructor(props) {
|
|
14
14
|
super(DEFAULT_PROPS, props);_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);_class.prototype.__init6.call(this);_class.prototype.__init7.call(this);_class.prototype.__init8.call(this);;
|
|
15
15
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkCFO5PSSKjs = require('./chunk-CFO5PSSK.js');
|
|
4
4
|
|
|
5
5
|
// src/backend/components/label.ts
|
|
6
|
-
var Label = class extends
|
|
6
|
+
var Label = class extends _chunkCFO5PSSKjs.Base {
|
|
7
7
|
constructor(props) {
|
|
8
8
|
super({ text: null }, props);
|
|
9
9
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkCFO5PSSKjs = require('./chunk-CFO5PSSK.js');
|
|
4
4
|
|
|
5
5
|
// src/backend/components/timeline.ts
|
|
6
6
|
var DEFAULT_PROPS = {
|
|
@@ -13,7 +13,7 @@ var DEFAULT_PROPS = {
|
|
|
13
13
|
subtitles: null,
|
|
14
14
|
source: null
|
|
15
15
|
};
|
|
16
|
-
var Timeline = (_class = class extends
|
|
16
|
+
var Timeline = (_class = class extends _chunkCFO5PSSKjs.Base {
|
|
17
17
|
constructor(props) {
|
|
18
18
|
super(DEFAULT_PROPS, props);_class.prototype.__init.call(this);;
|
|
19
19
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkCFO5PSSKjs = require('./chunk-CFO5PSSK.js');
|
|
5
|
+
|
|
6
|
+
// src/backend/components/slider-button.ts
|
|
7
|
+
var DEFAULT_PROPS = {
|
|
8
|
+
min: 0,
|
|
9
|
+
max: 255,
|
|
10
|
+
step: 5
|
|
11
|
+
};
|
|
12
|
+
var SliderButton = (_class = class extends _chunkCFO5PSSKjs.Base {
|
|
13
|
+
/** @hidden */
|
|
14
|
+
__init() {this.events = new (0, _chunkCFO5PSSKjs.EventEmitter)()}
|
|
15
|
+
/**
|
|
16
|
+
* Manually manage the state of the slider,
|
|
17
|
+
* to support both controlled and uncontrolled inputs.
|
|
18
|
+
*/
|
|
19
|
+
__init2() {this._value = null}
|
|
20
|
+
constructor(props) {
|
|
21
|
+
super(DEFAULT_PROPS, props, {
|
|
22
|
+
onPropsUpdated: () => this.onPropsUpdated()
|
|
23
|
+
});_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);;
|
|
24
|
+
this.onPropsUpdated();
|
|
25
|
+
}
|
|
26
|
+
__init3() {this.addListener = this.events.addListener}
|
|
27
|
+
__init4() {this.removeListener = this.events.removeListener}
|
|
28
|
+
/** @hidden */
|
|
29
|
+
getProtoInfo(idMap) {
|
|
30
|
+
return {
|
|
31
|
+
component: "slider_button",
|
|
32
|
+
key: idMap.getId(this),
|
|
33
|
+
min: this.props.min,
|
|
34
|
+
max: this.props.max,
|
|
35
|
+
step: this.props.step,
|
|
36
|
+
value: this._value
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** @hidden */
|
|
40
|
+
handleMessage(message) {
|
|
41
|
+
if (message.component !== "slider_button") return;
|
|
42
|
+
const newValue = this.sanitizeNumber(message.value);
|
|
43
|
+
if (this._value === newValue) return;
|
|
44
|
+
if (this.props.value === void 0) {
|
|
45
|
+
this._value = newValue;
|
|
46
|
+
this.updateTree();
|
|
47
|
+
}
|
|
48
|
+
this.events.emit("change", newValue);
|
|
49
|
+
}
|
|
50
|
+
setValue(value) {
|
|
51
|
+
if (this.props.value) {
|
|
52
|
+
throw new Error("Cannot set value on controlled input");
|
|
53
|
+
}
|
|
54
|
+
const newValue = this.sanitizeNumber(value);
|
|
55
|
+
if (this._value === newValue) return;
|
|
56
|
+
this._value = newValue;
|
|
57
|
+
this.updateTree();
|
|
58
|
+
}
|
|
59
|
+
sanitizeNumber(value) {
|
|
60
|
+
const i = Math.round((value - this.props.min) / this.props.step);
|
|
61
|
+
const v = i * this.props.step + this.props.min;
|
|
62
|
+
const clampedValue = Math.max(this.props.min, Math.min(this.props.max, v));
|
|
63
|
+
return clampedValue;
|
|
64
|
+
}
|
|
65
|
+
__init5() {this.onPropsUpdated = () => {
|
|
66
|
+
if (this.props.value !== void 0) {
|
|
67
|
+
this._value = this.props.value;
|
|
68
|
+
} else if (this._value === null && this.props.defaultValue) {
|
|
69
|
+
this._value = this.props.defaultValue;
|
|
70
|
+
}
|
|
71
|
+
}}
|
|
72
|
+
}, _class);
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
exports.SliderButton = SliderButton;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkCFO5PSSKjs = require('./chunk-CFO5PSSK.js');
|
|
4
4
|
|
|
5
5
|
// src/backend/components/rect.ts
|
|
6
6
|
var DEFAULT_PROPS = {
|
|
7
7
|
color: "rgba(0, 0, 0, 0)"
|
|
8
8
|
};
|
|
9
|
-
var Rect = class extends
|
|
9
|
+
var Rect = class extends _chunkCFO5PSSKjs.Base {
|
|
10
10
|
constructor(props) {
|
|
11
11
|
super(DEFAULT_PROPS, props);
|
|
12
12
|
}
|
|
@@ -6,12 +6,15 @@ var Base = class {
|
|
|
6
6
|
defaultProps;
|
|
7
7
|
/** @hidden */
|
|
8
8
|
_props;
|
|
9
|
-
|
|
9
|
+
/** @hidden */
|
|
10
|
+
_onPropsUpdated = null;
|
|
11
|
+
constructor(defaultProps, props, options) {
|
|
10
12
|
this.defaultProps = defaultProps;
|
|
11
13
|
this._props = Object.freeze({
|
|
12
14
|
...defaultProps,
|
|
13
15
|
...props
|
|
14
16
|
});
|
|
17
|
+
this._onPropsUpdated = options?.onPropsUpdated ?? null;
|
|
15
18
|
}
|
|
16
19
|
log = () => {
|
|
17
20
|
return this.parent?.log() || null;
|
|
@@ -27,6 +30,7 @@ var Base = class {
|
|
|
27
30
|
...this.defaultProps,
|
|
28
31
|
...props
|
|
29
32
|
});
|
|
33
|
+
this._onPropsUpdated?.();
|
|
30
34
|
this.updateTree();
|
|
31
35
|
};
|
|
32
36
|
updateProps = (updates) => {
|
|
@@ -34,6 +38,7 @@ var Base = class {
|
|
|
34
38
|
...this._props,
|
|
35
39
|
...updates
|
|
36
40
|
});
|
|
41
|
+
this._onPropsUpdated?.();
|
|
37
42
|
this.updateTree();
|
|
38
43
|
};
|
|
39
44
|
/** @hidden */
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Base,
|
|
3
|
+
EventEmitter
|
|
4
|
+
} from "./chunk-PW7QVLLF.mjs";
|
|
5
|
+
|
|
6
|
+
// src/backend/components/switch.ts
|
|
7
|
+
var DEFAULT_PROPS = {};
|
|
8
|
+
var Switch = class extends Base {
|
|
9
|
+
/** @hidden */
|
|
10
|
+
events = new EventEmitter();
|
|
11
|
+
/**
|
|
12
|
+
* Manually manage the state of the switch,
|
|
13
|
+
* to support both controlled and uncontrolled inputs.
|
|
14
|
+
*/
|
|
15
|
+
_value = null;
|
|
16
|
+
constructor(props) {
|
|
17
|
+
super(DEFAULT_PROPS, props, {
|
|
18
|
+
onPropsUpdated: () => this.onPropsUpdated()
|
|
19
|
+
});
|
|
20
|
+
this.onPropsUpdated();
|
|
21
|
+
}
|
|
22
|
+
addListener = this.events.addListener;
|
|
23
|
+
removeListener = this.events.removeListener;
|
|
24
|
+
/** @hidden */
|
|
25
|
+
getProtoInfo(idMap) {
|
|
26
|
+
return {
|
|
27
|
+
component: "switch",
|
|
28
|
+
key: idMap.getId(this),
|
|
29
|
+
state: this._value ?? "off"
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** @hidden */
|
|
33
|
+
handleMessage(message) {
|
|
34
|
+
if (message.component === "switch") {
|
|
35
|
+
const state = this._value === "on" ? "off" : "on";
|
|
36
|
+
if (this.props.value === void 0) {
|
|
37
|
+
this._value = state;
|
|
38
|
+
this.updateTree();
|
|
39
|
+
}
|
|
40
|
+
this.events.emit("change", state);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
setValue(state) {
|
|
44
|
+
if (this.props.value) {
|
|
45
|
+
throw new Error("Cannot set value on controlled input");
|
|
46
|
+
}
|
|
47
|
+
this._value = state;
|
|
48
|
+
this.updateTree();
|
|
49
|
+
}
|
|
50
|
+
onPropsUpdated = () => {
|
|
51
|
+
if (this.props.value !== void 0) {
|
|
52
|
+
this._value = this.props.value;
|
|
53
|
+
} else if (this._value === null && this.props.defaultValue) {
|
|
54
|
+
this._value = this.props.defaultValue;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export {
|
|
60
|
+
Switch
|
|
61
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkCFO5PSSKjs = require('./chunk-CFO5PSSK.js');
|
|
5
|
+
|
|
6
|
+
// src/backend/components/switch.ts
|
|
7
|
+
var DEFAULT_PROPS = {};
|
|
8
|
+
var Switch = (_class = class extends _chunkCFO5PSSKjs.Base {
|
|
9
|
+
/** @hidden */
|
|
10
|
+
__init() {this.events = new (0, _chunkCFO5PSSKjs.EventEmitter)()}
|
|
11
|
+
/**
|
|
12
|
+
* Manually manage the state of the switch,
|
|
13
|
+
* to support both controlled and uncontrolled inputs.
|
|
14
|
+
*/
|
|
15
|
+
__init2() {this._value = null}
|
|
16
|
+
constructor(props) {
|
|
17
|
+
super(DEFAULT_PROPS, props, {
|
|
18
|
+
onPropsUpdated: () => this.onPropsUpdated()
|
|
19
|
+
});_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);;
|
|
20
|
+
this.onPropsUpdated();
|
|
21
|
+
}
|
|
22
|
+
__init3() {this.addListener = this.events.addListener}
|
|
23
|
+
__init4() {this.removeListener = this.events.removeListener}
|
|
24
|
+
/** @hidden */
|
|
25
|
+
getProtoInfo(idMap) {
|
|
26
|
+
return {
|
|
27
|
+
component: "switch",
|
|
28
|
+
key: idMap.getId(this),
|
|
29
|
+
state: _nullishCoalesce(this._value, () => ( "off"))
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** @hidden */
|
|
33
|
+
handleMessage(message) {
|
|
34
|
+
if (message.component === "switch") {
|
|
35
|
+
const state = this._value === "on" ? "off" : "on";
|
|
36
|
+
if (this.props.value === void 0) {
|
|
37
|
+
this._value = state;
|
|
38
|
+
this.updateTree();
|
|
39
|
+
}
|
|
40
|
+
this.events.emit("change", state);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
setValue(state) {
|
|
44
|
+
if (this.props.value) {
|
|
45
|
+
throw new Error("Cannot set value on controlled input");
|
|
46
|
+
}
|
|
47
|
+
this._value = state;
|
|
48
|
+
this.updateTree();
|
|
49
|
+
}
|
|
50
|
+
__init5() {this.onPropsUpdated = () => {
|
|
51
|
+
if (this.props.value !== void 0) {
|
|
52
|
+
this._value = this.props.value;
|
|
53
|
+
} else if (this._value === null && this.props.defaultValue) {
|
|
54
|
+
this._value = this.props.defaultValue;
|
|
55
|
+
}
|
|
56
|
+
}}
|
|
57
|
+
}, _class);
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
exports.Switch = Switch;
|