vasille-jsx 3.0.1
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 +122 -0
- package/lib/components.js +148 -0
- package/lib/compose.js +46 -0
- package/lib/expression.js +52 -0
- package/lib/index.js +4 -0
- package/lib/inline.js +23 -0
- package/lib/internal.js +43 -0
- package/lib/library.js +25 -0
- package/lib/models.js +170 -0
- package/lib/objects.js +78 -0
- package/lib/spec/html.js +1 -0
- package/lib/spec/svg.js +1 -0
- package/lib-node/components.js +162 -0
- package/lib-node/compose.js +51 -0
- package/lib-node/expression.js +56 -0
- package/lib-node/index.js +23 -0
- package/lib-node/inline.js +28 -0
- package/lib-node/internal.js +46 -0
- package/lib-node/library.js +29 -0
- package/lib-node/models.js +176 -0
- package/lib-node/objects.js +86 -0
- package/lib-node/spec/html.js +2 -0
- package/lib-node/spec/svg.js +2 -0
- package/package.json +42 -0
- package/types/components.d.ts +46 -0
- package/types/compose.d.ts +11 -0
- package/types/expression.d.ts +14 -0
- package/types/index.d.ts +6 -0
- package/types/inline.d.ts +4 -0
- package/types/internal.d.ts +31 -0
- package/types/library.d.ts +3 -0
- package/types/models.d.ts +31 -0
- package/types/objects.d.ts +14 -0
- package/types/spec/html.d.ts +974 -0
- package/types/spec/svg.d.ts +314 -0
package/lib/objects.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { IValue, Reference } from "vasille";
|
|
2
|
+
import { ensureIValue } from "./library";
|
|
3
|
+
export class ProxyReference extends Reference {
|
|
4
|
+
forceUpdate() {
|
|
5
|
+
this.updateDeps(this.state);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export function proxyObject(obj, proxyRef) {
|
|
9
|
+
return new Proxy(obj, {
|
|
10
|
+
get(target, p, receiver) {
|
|
11
|
+
const value = Reflect.get(target, p, receiver);
|
|
12
|
+
return value instanceof Object ? proxyObject(value, proxyRef) : value;
|
|
13
|
+
},
|
|
14
|
+
set(target, p, newValue, receiver) {
|
|
15
|
+
const response = Reflect.set(target, p, newValue, receiver);
|
|
16
|
+
if (response) {
|
|
17
|
+
proxyRef.forceUpdate();
|
|
18
|
+
}
|
|
19
|
+
return response;
|
|
20
|
+
},
|
|
21
|
+
defineProperty(target, property, attributes) {
|
|
22
|
+
const response = Reflect.defineProperty(target, property, attributes);
|
|
23
|
+
if (response) {
|
|
24
|
+
proxyRef.forceUpdate();
|
|
25
|
+
}
|
|
26
|
+
return response;
|
|
27
|
+
},
|
|
28
|
+
deleteProperty(target, p) {
|
|
29
|
+
const response = Reflect.deleteProperty(target, p);
|
|
30
|
+
if (response) {
|
|
31
|
+
proxyRef.forceUpdate();
|
|
32
|
+
}
|
|
33
|
+
return response;
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export function proxy(o) {
|
|
38
|
+
if (typeof o === "object" && o && o.constructor === Object) {
|
|
39
|
+
const proxyRef = new ProxyReference(undefined);
|
|
40
|
+
proxyRef.$ = proxyObject(o, proxyRef);
|
|
41
|
+
return proxyRef;
|
|
42
|
+
}
|
|
43
|
+
return o;
|
|
44
|
+
}
|
|
45
|
+
export function reactiveObject(node, o) {
|
|
46
|
+
for (const key of Object.keys(o)) {
|
|
47
|
+
if (!(o[key] instanceof IValue)) {
|
|
48
|
+
o[key] = ensureIValue(node, proxy(o[key]));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return new Proxy(o, {
|
|
52
|
+
get(_, p) {
|
|
53
|
+
if (p in o) {
|
|
54
|
+
return o[p];
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
return (o[p] = node.register(new Reference(undefined)));
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
deleteProperty(_, p) {
|
|
61
|
+
if (p in o && o[p] instanceof IValue) {
|
|
62
|
+
node.release(p[0]);
|
|
63
|
+
}
|
|
64
|
+
return Reflect.deleteProperty(o, p);
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
export function reactiveObjectProxy(o) {
|
|
69
|
+
return new Proxy(o, {
|
|
70
|
+
get(_, p) {
|
|
71
|
+
return o[p].$;
|
|
72
|
+
},
|
|
73
|
+
set(_, p, newValue) {
|
|
74
|
+
o[p].$ = newValue;
|
|
75
|
+
return true;
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
}
|
package/lib/spec/html.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/spec/svg.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readValue = readValue;
|
|
4
|
+
exports.Adapter = Adapter;
|
|
5
|
+
exports.Slot = Slot;
|
|
6
|
+
exports.If = If;
|
|
7
|
+
exports.ElseIf = ElseIf;
|
|
8
|
+
exports.Else = Else;
|
|
9
|
+
exports.For = For;
|
|
10
|
+
exports.Watch = Watch;
|
|
11
|
+
exports.Debug = Debug;
|
|
12
|
+
exports.Mount = Mount;
|
|
13
|
+
exports.Show = Show;
|
|
14
|
+
exports.Delay = Delay;
|
|
15
|
+
const vasille_1 = require("vasille");
|
|
16
|
+
function readValue(v) {
|
|
17
|
+
return v instanceof vasille_1.IValue ? v.$ : v;
|
|
18
|
+
}
|
|
19
|
+
function Adapter(ctx, { node, slot }) {
|
|
20
|
+
const dNode = readValue(node);
|
|
21
|
+
const dSlot = readValue(slot);
|
|
22
|
+
if (dNode && dSlot) {
|
|
23
|
+
ctx.create(dNode, dSlot);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function Slot(ctx, options) {
|
|
27
|
+
var _a;
|
|
28
|
+
const model = readValue(options.model);
|
|
29
|
+
if (model) {
|
|
30
|
+
if (model.length <= 1) {
|
|
31
|
+
for (const key in options) {
|
|
32
|
+
if (options[key] instanceof vasille_1.IValue) {
|
|
33
|
+
options[key] = options[key].$;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
for (const key in options) {
|
|
39
|
+
if (!(options[key] instanceof vasille_1.IValue)) {
|
|
40
|
+
options[key] = ctx.ref(options[key]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
model(options, ctx);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
(_a = readValue(options.slot)) === null || _a === void 0 ? void 0 : _a(ctx);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function If(ctx, { condition, slot: magicSlot }) {
|
|
51
|
+
const slot = readValue(magicSlot);
|
|
52
|
+
ctx.if(condition instanceof vasille_1.IValue ? condition : ctx.ref(condition), slot !== null && slot !== void 0 ? slot : (() => { }));
|
|
53
|
+
}
|
|
54
|
+
function ElseIf(ctx, { condition, slot: magicSlot }) {
|
|
55
|
+
const slot = readValue(magicSlot);
|
|
56
|
+
ctx.elif(condition instanceof vasille_1.IValue ? condition : ctx.ref(condition), slot !== null && slot !== void 0 ? slot : (() => { }));
|
|
57
|
+
}
|
|
58
|
+
function Else(ctx, { slot: magicSlot }) {
|
|
59
|
+
const slot = readValue(magicSlot);
|
|
60
|
+
if (slot) {
|
|
61
|
+
ctx.else(slot);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function For(ctx, { of, slot: magicSlot }) {
|
|
65
|
+
const slot = readValue(magicSlot);
|
|
66
|
+
if (of instanceof vasille_1.IValue) {
|
|
67
|
+
ctx.create(new vasille_1.Watch({
|
|
68
|
+
model: of,
|
|
69
|
+
slot: function (ctx, model) {
|
|
70
|
+
create(model, ctx);
|
|
71
|
+
},
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
else if (of) {
|
|
75
|
+
create(of, ctx);
|
|
76
|
+
}
|
|
77
|
+
function create(model, node) {
|
|
78
|
+
if (!slot) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (model instanceof vasille_1.ArrayModel) {
|
|
82
|
+
node.create(new vasille_1.ArrayView({
|
|
83
|
+
model,
|
|
84
|
+
slot: slot,
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
else if (model instanceof vasille_1.MapModel) {
|
|
88
|
+
node.create(new vasille_1.MapView({
|
|
89
|
+
model,
|
|
90
|
+
slot,
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
else if (model instanceof vasille_1.SetModel) {
|
|
94
|
+
node.create(new vasille_1.SetView({
|
|
95
|
+
model,
|
|
96
|
+
slot,
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
// fallback if is used external Array/Map/Set
|
|
100
|
+
else {
|
|
101
|
+
console.warn("Vasille <For of/> fallback detected. Please provide reactive data.");
|
|
102
|
+
if (model instanceof Array) {
|
|
103
|
+
model.forEach((value) => {
|
|
104
|
+
slot(node, value, value);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
else if (model instanceof Map) {
|
|
108
|
+
for (const [key, value] of model) {
|
|
109
|
+
slot(node, value, key);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else if (model instanceof Set) {
|
|
113
|
+
for (const value of model) {
|
|
114
|
+
slot(node, value, value);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
throw (0, vasille_1.userError)("wrong use of `<For of/>` component", "wrong-model");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function Watch(ctx, { model, slot: magicSlot }) {
|
|
124
|
+
const slot = readValue(magicSlot);
|
|
125
|
+
if (slot && model instanceof vasille_1.IValue) {
|
|
126
|
+
ctx.create(new vasille_1.Watch({ model, slot }));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function Debug(ctx, { model }) {
|
|
130
|
+
const value = model instanceof vasille_1.IValue ? model : ctx.ref(model);
|
|
131
|
+
ctx.debug(value);
|
|
132
|
+
}
|
|
133
|
+
function Mount(ctx, { bind }) {
|
|
134
|
+
if (!(ctx instanceof vasille_1.Tag)) {
|
|
135
|
+
throw (0, vasille_1.userError)("<Mount bind/> can be used only as direct child of html tags", "context-mismatch");
|
|
136
|
+
}
|
|
137
|
+
ctx.bindMount(bind instanceof vasille_1.IValue ? bind : ctx.ref(bind));
|
|
138
|
+
}
|
|
139
|
+
function Show(ctx, { bind }) {
|
|
140
|
+
if (!(ctx instanceof vasille_1.Tag)) {
|
|
141
|
+
throw (0, vasille_1.userError)("<Show bind/> can be used only as direct child of html tags", "context-mismatch");
|
|
142
|
+
}
|
|
143
|
+
ctx.bindShow(bind instanceof vasille_1.IValue ? bind : ctx.ref(bind));
|
|
144
|
+
}
|
|
145
|
+
function Delay(ctx, { time, slot }) {
|
|
146
|
+
const fragment = new vasille_1.Fragment({}, ":timer");
|
|
147
|
+
const dSlot = readValue(slot);
|
|
148
|
+
let timer;
|
|
149
|
+
ctx.create(fragment, function (node) {
|
|
150
|
+
if (dSlot) {
|
|
151
|
+
timer = setTimeout(() => {
|
|
152
|
+
dSlot(node);
|
|
153
|
+
timer = undefined;
|
|
154
|
+
}, readValue(time));
|
|
155
|
+
}
|
|
156
|
+
node.runOnDestroy(() => {
|
|
157
|
+
if (timer !== undefined) {
|
|
158
|
+
clearTimeout(timer);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compose = compose;
|
|
4
|
+
exports.extend = extend;
|
|
5
|
+
exports.mount = mount;
|
|
6
|
+
const vasille_1 = require("vasille");
|
|
7
|
+
function proxy(obj) {
|
|
8
|
+
return new Proxy(obj, {
|
|
9
|
+
get(target, p) {
|
|
10
|
+
return p in target && target[p] instanceof vasille_1.IValue ? target[p] : new vasille_1.Reference(target[p]);
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function create(renderer, create, name) {
|
|
15
|
+
return function (node, props, slot) {
|
|
16
|
+
const frag = create(props);
|
|
17
|
+
if (slot) {
|
|
18
|
+
props.slot = slot;
|
|
19
|
+
}
|
|
20
|
+
node.create(frag);
|
|
21
|
+
try {
|
|
22
|
+
const result = renderer(frag, proxy(props));
|
|
23
|
+
if (result !== undefined && props.callback) {
|
|
24
|
+
props.callback(result);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
if (vasille_1.config.debugUi) {
|
|
29
|
+
console.error(`Vasille: Error found in component ${name}`, e);
|
|
30
|
+
}
|
|
31
|
+
(0, vasille_1.reportError)(e);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function compose(renderer, name) {
|
|
36
|
+
return create(renderer, props => {
|
|
37
|
+
return new vasille_1.Fragment(props, name);
|
|
38
|
+
}, name);
|
|
39
|
+
}
|
|
40
|
+
function extend(renderer, name) {
|
|
41
|
+
return create(renderer, props => {
|
|
42
|
+
return new vasille_1.Extension(props, name);
|
|
43
|
+
}, name);
|
|
44
|
+
}
|
|
45
|
+
function mount(tag, component, $) {
|
|
46
|
+
const root = new vasille_1.App(tag, {});
|
|
47
|
+
const frag = new vasille_1.Fragment({}, ":app-root");
|
|
48
|
+
root.create(frag, function () {
|
|
49
|
+
component(frag, $);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PartialExpression = void 0;
|
|
4
|
+
const vasille_1 = require("vasille");
|
|
5
|
+
class PartialExpression extends vasille_1.IValue {
|
|
6
|
+
constructor(func, values) {
|
|
7
|
+
super();
|
|
8
|
+
this.linkedFunc = [];
|
|
9
|
+
const handler = (i) => {
|
|
10
|
+
if (typeof i === "number") {
|
|
11
|
+
const dependency = this.values[i];
|
|
12
|
+
if (dependency instanceof vasille_1.IValue) {
|
|
13
|
+
this.valuesCache[i] = dependency.$;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
this.sync.$ = func.apply(this, this.valuesCache);
|
|
17
|
+
};
|
|
18
|
+
this.valuesCache = values.map(item => (item instanceof vasille_1.IValue ? item.$ : item));
|
|
19
|
+
this.sync = new vasille_1.Reference(func.apply(this, this.valuesCache));
|
|
20
|
+
let i = 0;
|
|
21
|
+
for (const value of values) {
|
|
22
|
+
const index = i++;
|
|
23
|
+
if (value instanceof vasille_1.IValue) {
|
|
24
|
+
value.on((this.linkedFunc[index] = handler.bind(this, index)));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
this.values = values;
|
|
28
|
+
this.func = handler;
|
|
29
|
+
handler();
|
|
30
|
+
}
|
|
31
|
+
get $() {
|
|
32
|
+
return this.sync.$;
|
|
33
|
+
}
|
|
34
|
+
set $(value) {
|
|
35
|
+
this.sync.$ = value;
|
|
36
|
+
}
|
|
37
|
+
on(handler) {
|
|
38
|
+
this.sync.on(handler);
|
|
39
|
+
}
|
|
40
|
+
off(handler) {
|
|
41
|
+
this.sync.off(handler);
|
|
42
|
+
}
|
|
43
|
+
destroy() {
|
|
44
|
+
for (let i = 0; i < this.values.length; i++) {
|
|
45
|
+
const value = this.values[i];
|
|
46
|
+
if (value instanceof vasille_1.IValue) {
|
|
47
|
+
value.off(this.linkedFunc[i]);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
this.values.splice(0);
|
|
51
|
+
this.valuesCache.splice(0);
|
|
52
|
+
this.linkedFunc.splice(0);
|
|
53
|
+
super.destroy();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.PartialExpression = PartialExpression;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.$ = exports.awaited = exports.mount = exports.extend = exports.compose = exports.Watch = exports.Slot = exports.Show = exports.Mount = exports.If = exports.For = exports.ElseIf = exports.Else = exports.Delay = exports.Debug = exports.Adapter = void 0;
|
|
4
|
+
var components_1 = require("./components");
|
|
5
|
+
Object.defineProperty(exports, "Adapter", { enumerable: true, get: function () { return components_1.Adapter; } });
|
|
6
|
+
Object.defineProperty(exports, "Debug", { enumerable: true, get: function () { return components_1.Debug; } });
|
|
7
|
+
Object.defineProperty(exports, "Delay", { enumerable: true, get: function () { return components_1.Delay; } });
|
|
8
|
+
Object.defineProperty(exports, "Else", { enumerable: true, get: function () { return components_1.Else; } });
|
|
9
|
+
Object.defineProperty(exports, "ElseIf", { enumerable: true, get: function () { return components_1.ElseIf; } });
|
|
10
|
+
Object.defineProperty(exports, "For", { enumerable: true, get: function () { return components_1.For; } });
|
|
11
|
+
Object.defineProperty(exports, "If", { enumerable: true, get: function () { return components_1.If; } });
|
|
12
|
+
Object.defineProperty(exports, "Mount", { enumerable: true, get: function () { return components_1.Mount; } });
|
|
13
|
+
Object.defineProperty(exports, "Show", { enumerable: true, get: function () { return components_1.Show; } });
|
|
14
|
+
Object.defineProperty(exports, "Slot", { enumerable: true, get: function () { return components_1.Slot; } });
|
|
15
|
+
Object.defineProperty(exports, "Watch", { enumerable: true, get: function () { return components_1.Watch; } });
|
|
16
|
+
var compose_1 = require("./compose");
|
|
17
|
+
Object.defineProperty(exports, "compose", { enumerable: true, get: function () { return compose_1.compose; } });
|
|
18
|
+
Object.defineProperty(exports, "extend", { enumerable: true, get: function () { return compose_1.extend; } });
|
|
19
|
+
Object.defineProperty(exports, "mount", { enumerable: true, get: function () { return compose_1.mount; } });
|
|
20
|
+
var library_1 = require("./library");
|
|
21
|
+
Object.defineProperty(exports, "awaited", { enumerable: true, get: function () { return library_1.awaited; } });
|
|
22
|
+
var internal_1 = require("./internal");
|
|
23
|
+
Object.defineProperty(exports, "$", { enumerable: true, get: function () { return internal_1.internal; } });
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readValue = readValue;
|
|
4
|
+
exports.setValue = setValue;
|
|
5
|
+
exports.asFragment = asFragment;
|
|
6
|
+
const vasille_1 = require("vasille");
|
|
7
|
+
function readValue(v) {
|
|
8
|
+
return v instanceof vasille_1.IValue ? v.$ : v;
|
|
9
|
+
}
|
|
10
|
+
function setValue(target, value, fallback) {
|
|
11
|
+
if (target instanceof vasille_1.IValue) {
|
|
12
|
+
if (target instanceof vasille_1.Pointer && value instanceof vasille_1.IValue) {
|
|
13
|
+
target.$$ = value;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
target.$ = value instanceof vasille_1.IValue ? value.$ : value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
fallback === null || fallback === void 0 ? void 0 : fallback(value);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function asFragment(node) {
|
|
24
|
+
if (!(node instanceof vasille_1.Fragment)) {
|
|
25
|
+
throw (0, vasille_1.userError)("missing context", "out-of-context");
|
|
26
|
+
}
|
|
27
|
+
return node;
|
|
28
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.internal = void 0;
|
|
4
|
+
const vasille_1 = require("vasille");
|
|
5
|
+
const objects_1 = require("./objects");
|
|
6
|
+
const models_1 = require("./models");
|
|
7
|
+
exports.internal = {
|
|
8
|
+
/** create an expression (without context), use it for OwningPointer */
|
|
9
|
+
ex(func, ...values) {
|
|
10
|
+
return new vasille_1.Expression(func, ...values);
|
|
11
|
+
},
|
|
12
|
+
/** create a forward-only pointer (without context), use it for OwningPointer */
|
|
13
|
+
fo(v) {
|
|
14
|
+
return new vasille_1.Pointer(v);
|
|
15
|
+
},
|
|
16
|
+
/** create a reference (without context), use it for default composing props values */
|
|
17
|
+
r(v) {
|
|
18
|
+
return new vasille_1.Reference(v);
|
|
19
|
+
},
|
|
20
|
+
/** create a reactive object proxy, use it for sending reactive objects to child components */
|
|
21
|
+
rop(o) {
|
|
22
|
+
return (0, objects_1.reactiveObjectProxy)(o);
|
|
23
|
+
},
|
|
24
|
+
/**
|
|
25
|
+
* translate `{...}` to `$.ro(this, {...})`
|
|
26
|
+
*/
|
|
27
|
+
ro: objects_1.reactiveObject,
|
|
28
|
+
/**
|
|
29
|
+
* translate `new Set(#)` to `$.sm(this, #)`
|
|
30
|
+
*/
|
|
31
|
+
sm(node, data) {
|
|
32
|
+
return node.register(new models_1.ContextSet(data));
|
|
33
|
+
},
|
|
34
|
+
/**
|
|
35
|
+
* translate `new Map(#)` to `$.mm(this, #)`
|
|
36
|
+
*/
|
|
37
|
+
mm(node, data) {
|
|
38
|
+
return node.register(new models_1.ContextMap(data));
|
|
39
|
+
},
|
|
40
|
+
/**
|
|
41
|
+
* translate `[...]` to `$.am(this, [...])`
|
|
42
|
+
*/
|
|
43
|
+
am(node, data) {
|
|
44
|
+
return node.register((0, vasille_1.proxyArrayModel)(new models_1.ContextArray(data)));
|
|
45
|
+
},
|
|
46
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.awaited = awaited;
|
|
4
|
+
exports.ensureIValue = ensureIValue;
|
|
5
|
+
const vasille_1 = require("vasille");
|
|
6
|
+
function awaited(node, target) {
|
|
7
|
+
const value = node.ref(undefined);
|
|
8
|
+
const err = node.ref(undefined);
|
|
9
|
+
let current = target;
|
|
10
|
+
if (typeof current === "function") {
|
|
11
|
+
try {
|
|
12
|
+
current = current();
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
current = undefined;
|
|
16
|
+
err.$ = e;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (current instanceof Promise) {
|
|
20
|
+
current.then(result => (value.$ = result)).catch(e => (err.$ = e));
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
value.$ = current;
|
|
24
|
+
}
|
|
25
|
+
return [err, value];
|
|
26
|
+
}
|
|
27
|
+
function ensureIValue(node, value) {
|
|
28
|
+
return value instanceof vasille_1.IValue ? value : node.ref(value);
|
|
29
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var _Context_instances, _Context_ctx, _Context_enableObject, _Context_disableObject;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ContextSet = exports.ContextMap = exports.ContextArray = void 0;
|
|
10
|
+
const vasille_1 = require("vasille");
|
|
11
|
+
const objects_1 = require("./objects");
|
|
12
|
+
const symbol = Symbol("proxy");
|
|
13
|
+
class Context extends vasille_1.Destroyable {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
_Context_instances.add(this);
|
|
17
|
+
_Context_ctx.set(this, new vasille_1.Reactive({}));
|
|
18
|
+
}
|
|
19
|
+
checkEnable(value) {
|
|
20
|
+
if (value && typeof value === "object" && value.constructor === Object) {
|
|
21
|
+
return __classPrivateFieldGet(this, _Context_instances, "m", _Context_enableObject).call(this, value);
|
|
22
|
+
}
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
checkDisable(value) {
|
|
26
|
+
if (value && typeof value === "object" && value.constructor === Object) {
|
|
27
|
+
__classPrivateFieldGet(this, _Context_instances, "m", _Context_disableObject).call(this, value);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
destroy() {
|
|
31
|
+
__classPrivateFieldGet(this, _Context_ctx, "f").destroy();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
_Context_ctx = new WeakMap(), _Context_instances = new WeakSet(), _Context_enableObject = function _Context_enableObject(o) {
|
|
35
|
+
const ref = new objects_1.ProxyReference(undefined);
|
|
36
|
+
o[symbol] = ref;
|
|
37
|
+
__classPrivateFieldGet(this, _Context_ctx, "f").register(ref);
|
|
38
|
+
return (0, objects_1.proxyObject)(o, ref);
|
|
39
|
+
}, _Context_disableObject = function _Context_disableObject(o) {
|
|
40
|
+
__classPrivateFieldGet(this, _Context_ctx, "f").release(o[symbol]);
|
|
41
|
+
};
|
|
42
|
+
class ContextArray extends vasille_1.ArrayModel {
|
|
43
|
+
constructor(data) {
|
|
44
|
+
const ctx = new Context();
|
|
45
|
+
if (data instanceof Array) {
|
|
46
|
+
for (let i = 0; i < data.length; i++) {
|
|
47
|
+
data[i] = ctx.checkEnable(data[i]);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
super(data);
|
|
51
|
+
this.ctx = ctx;
|
|
52
|
+
}
|
|
53
|
+
fill(value, start, end) {
|
|
54
|
+
value = this.ctx.checkEnable(value);
|
|
55
|
+
return super.fill(value, start, end);
|
|
56
|
+
}
|
|
57
|
+
pop() {
|
|
58
|
+
const value = super.pop();
|
|
59
|
+
this.ctx.checkDisable(value);
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
push(...items) {
|
|
63
|
+
for (let i = 0; i < items.length; i++) {
|
|
64
|
+
items[i] = this.ctx.checkEnable(items[i]);
|
|
65
|
+
}
|
|
66
|
+
return super.push(...items);
|
|
67
|
+
}
|
|
68
|
+
shift() {
|
|
69
|
+
const value = super.shift();
|
|
70
|
+
this.ctx.checkDisable(value);
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
splice(start, deleteCount, ...items) {
|
|
74
|
+
for (let i = 0; i < items.length; i++) {
|
|
75
|
+
items[i] = this.ctx.checkEnable(items[i]);
|
|
76
|
+
}
|
|
77
|
+
const removed = super.splice(start, deleteCount, ...items);
|
|
78
|
+
for (const item of removed) {
|
|
79
|
+
this.ctx.checkDisable(removed);
|
|
80
|
+
}
|
|
81
|
+
return removed;
|
|
82
|
+
}
|
|
83
|
+
unshift(...items) {
|
|
84
|
+
for (let i = 0; i < items.length; i++) {
|
|
85
|
+
items[i] = this.ctx.checkEnable(items[i]);
|
|
86
|
+
}
|
|
87
|
+
return super.unshift(...items);
|
|
88
|
+
}
|
|
89
|
+
replace(at, with_) {
|
|
90
|
+
this.ctx.checkDisable(this[at]);
|
|
91
|
+
with_ = this.ctx.checkEnable(with_);
|
|
92
|
+
return super.replace(at, with_);
|
|
93
|
+
}
|
|
94
|
+
destroy() {
|
|
95
|
+
super.destroy();
|
|
96
|
+
this.ctx.destroy();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.ContextArray = ContextArray;
|
|
100
|
+
class ContextMap extends vasille_1.MapModel {
|
|
101
|
+
constructor(map) {
|
|
102
|
+
const ctx = new Context();
|
|
103
|
+
if (map) {
|
|
104
|
+
for (const item of map) {
|
|
105
|
+
item[1] = ctx.checkEnable(item[1]);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
super(map);
|
|
109
|
+
this.ctx = ctx;
|
|
110
|
+
}
|
|
111
|
+
clear() {
|
|
112
|
+
for (const value of this.values()) {
|
|
113
|
+
this.ctx.checkDisable(value);
|
|
114
|
+
}
|
|
115
|
+
super.clear();
|
|
116
|
+
}
|
|
117
|
+
delete(key) {
|
|
118
|
+
this.ctx.checkDisable(this.get(key));
|
|
119
|
+
return super.delete(key);
|
|
120
|
+
}
|
|
121
|
+
set(key, value) {
|
|
122
|
+
this.ctx.checkDisable(this.get(key));
|
|
123
|
+
value = this.ctx.checkEnable(value);
|
|
124
|
+
return super.set(key, value);
|
|
125
|
+
}
|
|
126
|
+
destroy() {
|
|
127
|
+
super.destroy();
|
|
128
|
+
this.ctx.destroy();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.ContextMap = ContextMap;
|
|
132
|
+
class ContextSet extends vasille_1.SetModel {
|
|
133
|
+
constructor(set) {
|
|
134
|
+
const ctx = new Context();
|
|
135
|
+
const real = new Map();
|
|
136
|
+
if (set) {
|
|
137
|
+
for (let i = 0; i < set.length; i++) {
|
|
138
|
+
real.set(set[i], (set[i] = ctx.checkEnable(set[i])));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
super(set);
|
|
142
|
+
this.ctx = ctx;
|
|
143
|
+
this.real = real;
|
|
144
|
+
}
|
|
145
|
+
add(value) {
|
|
146
|
+
if (!this.real.has(value)) {
|
|
147
|
+
this.real.set(value, (value = this.ctx.checkEnable(value)));
|
|
148
|
+
return super.add(value);
|
|
149
|
+
}
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
has(value) {
|
|
153
|
+
return this.real.has(value);
|
|
154
|
+
}
|
|
155
|
+
clear() {
|
|
156
|
+
for (const item of this) {
|
|
157
|
+
this.ctx.checkDisable(item);
|
|
158
|
+
}
|
|
159
|
+
super.clear();
|
|
160
|
+
this.real.clear();
|
|
161
|
+
}
|
|
162
|
+
delete(value) {
|
|
163
|
+
const real = this.real.get(value);
|
|
164
|
+
if (real !== undefined) {
|
|
165
|
+
this.ctx.checkDisable(value);
|
|
166
|
+
this.real.delete(value);
|
|
167
|
+
return super.delete(real);
|
|
168
|
+
}
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
destroy() {
|
|
172
|
+
super.destroy();
|
|
173
|
+
this.ctx.destroy();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
exports.ContextSet = ContextSet;
|