vasille-jsx 3.0.2 → 3.1.2
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 +5 -6
- package/lib/components.js +10 -30
- package/lib/compose.js +7 -17
- package/lib/index.js +4 -4
- package/lib/internal.js +31 -25
- package/lib/library.js +37 -17
- package/lib/models.js +14 -20
- package/lib/objects.js +22 -2
- package/package.json +22 -18
- package/types/components.d.ts +27 -33
- package/types/compose.d.ts +4 -5
- package/types/index.d.ts +4 -6
- package/types/internal.d.ts +19 -19
- package/types/library.d.ts +2 -1
- package/types/objects.d.ts +4 -1
- package/lib/expression.js +0 -52
- package/lib/inline.js +0 -23
- package/lib/spec/html.js +0 -1
- package/lib/spec/svg.js +0 -1
- package/lib-node/components.js +0 -162
- package/lib-node/compose.js +0 -51
- package/lib-node/expression.js +0 -56
- package/lib-node/index.js +0 -23
- package/lib-node/inline.js +0 -28
- package/lib-node/internal.js +0 -46
- package/lib-node/library.js +0 -29
- package/lib-node/models.js +0 -176
- package/lib-node/objects.js +0 -86
- package/lib-node/spec/html.js +0 -2
- package/lib-node/spec/svg.js +0 -2
- package/types/expression.d.ts +0 -14
- package/types/inline.d.ts +0 -4
- package/types/spec/html.d.ts +0 -974
- package/types/spec/svg.d.ts +0 -314
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ $ npx degit vasille-js/example-javascript my-project
|
|
|
47
47
|
|
|
48
48
|
### Examples
|
|
49
49
|
* [TypeScript Example](https://github.com/vasille-js/example-typescript)
|
|
50
|
-
* [JavaScript Example](https://github.com/
|
|
50
|
+
* [JavaScript Example](https://github.com/vasille-js/example-javascript)
|
|
51
51
|
|
|
52
52
|
<hr>
|
|
53
53
|
|
|
@@ -103,12 +103,11 @@ All of these are supported:
|
|
|
103
103
|
* [x] Develop the `Vasille JSX` library.
|
|
104
104
|
* [x] `100%` Test Coverage for the JSX library.
|
|
105
105
|
* [x] Develop the `Vasille Babel Plugin`.
|
|
106
|
-
* [
|
|
107
|
-
* [
|
|
108
|
-
* [ ] Add custom `<input/>` components with 2-way value binding.
|
|
106
|
+
* [x] `100%` Test Coverage fot babel plugin.
|
|
107
|
+
* [x] Add CSS support (define styles in components).
|
|
109
108
|
* [ ] Add router.
|
|
110
|
-
* [ ]
|
|
111
|
-
* [ ] Develop
|
|
109
|
+
* [ ] Add SSR (server side rendering).
|
|
110
|
+
* [ ] Develop tools extension for debugging.
|
|
112
111
|
|
|
113
112
|
## Questions
|
|
114
113
|
|
package/lib/components.js
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
import { ArrayModel, ArrayView, Fragment, IValue, MapModel, MapView, SetModel, SetView, userError, Watch as CoreWatch,
|
|
1
|
+
import { ArrayModel, ArrayView, Fragment, IValue, MapModel, MapView, SetModel, SetView, userError, Watch as CoreWatch, } from "vasille";
|
|
2
2
|
export function readValue(v) {
|
|
3
3
|
return v instanceof IValue ? v.$ : v;
|
|
4
4
|
}
|
|
5
|
-
export function Adapter(ctx, { node, slot }) {
|
|
6
|
-
const dNode = readValue(node);
|
|
7
|
-
const dSlot = readValue(slot);
|
|
8
|
-
if (dNode && dSlot) {
|
|
9
|
-
ctx.create(dNode, dSlot);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
5
|
export function Slot(ctx, options) {
|
|
13
|
-
var _a;
|
|
14
6
|
const model = readValue(options.model);
|
|
15
7
|
if (model) {
|
|
16
8
|
if (model.length <= 1) {
|
|
@@ -30,16 +22,16 @@ export function Slot(ctx, options) {
|
|
|
30
22
|
model(options, ctx);
|
|
31
23
|
}
|
|
32
24
|
else {
|
|
33
|
-
|
|
25
|
+
readValue(options.slot)?.(ctx);
|
|
34
26
|
}
|
|
35
27
|
}
|
|
36
28
|
export function If(ctx, { condition, slot: magicSlot }) {
|
|
37
29
|
const slot = readValue(magicSlot);
|
|
38
|
-
ctx.if(condition instanceof IValue ? condition : ctx.ref(condition), slot
|
|
30
|
+
ctx.if(condition instanceof IValue ? condition : ctx.ref(condition), slot ?? (() => { }));
|
|
39
31
|
}
|
|
40
32
|
export function ElseIf(ctx, { condition, slot: magicSlot }) {
|
|
41
33
|
const slot = readValue(magicSlot);
|
|
42
|
-
ctx.elif(condition instanceof IValue ? condition : ctx.ref(condition), slot
|
|
34
|
+
ctx.elif(condition instanceof IValue ? condition : ctx.ref(condition), slot ?? (() => { }));
|
|
43
35
|
}
|
|
44
36
|
export function Else(ctx, { slot: magicSlot }) {
|
|
45
37
|
const slot = readValue(magicSlot);
|
|
@@ -55,7 +47,7 @@ export function For(ctx, { of, slot: magicSlot }) {
|
|
|
55
47
|
slot: function (ctx, model) {
|
|
56
48
|
create(model, ctx);
|
|
57
49
|
},
|
|
58
|
-
}));
|
|
50
|
+
}, ctx.runner));
|
|
59
51
|
}
|
|
60
52
|
else if (of) {
|
|
61
53
|
create(of, ctx);
|
|
@@ -68,19 +60,19 @@ export function For(ctx, { of, slot: magicSlot }) {
|
|
|
68
60
|
node.create(new ArrayView({
|
|
69
61
|
model,
|
|
70
62
|
slot: slot,
|
|
71
|
-
}));
|
|
63
|
+
}, node.runner));
|
|
72
64
|
}
|
|
73
65
|
else if (model instanceof MapModel) {
|
|
74
66
|
node.create(new MapView({
|
|
75
67
|
model,
|
|
76
68
|
slot,
|
|
77
|
-
}));
|
|
69
|
+
}, node.runner));
|
|
78
70
|
}
|
|
79
71
|
else if (model instanceof SetModel) {
|
|
80
72
|
node.create(new SetView({
|
|
81
73
|
model,
|
|
82
74
|
slot,
|
|
83
|
-
}));
|
|
75
|
+
}, node.runner));
|
|
84
76
|
}
|
|
85
77
|
// fallback if is used external Array/Map/Set
|
|
86
78
|
else {
|
|
@@ -109,27 +101,15 @@ export function For(ctx, { of, slot: magicSlot }) {
|
|
|
109
101
|
export function Watch(ctx, { model, slot: magicSlot }) {
|
|
110
102
|
const slot = readValue(magicSlot);
|
|
111
103
|
if (slot && model instanceof IValue) {
|
|
112
|
-
ctx.create(new CoreWatch({ model, slot }));
|
|
104
|
+
ctx.create(new CoreWatch({ model, slot }, ctx.runner));
|
|
113
105
|
}
|
|
114
106
|
}
|
|
115
107
|
export function Debug(ctx, { model }) {
|
|
116
108
|
const value = model instanceof IValue ? model : ctx.ref(model);
|
|
117
109
|
ctx.debug(value);
|
|
118
110
|
}
|
|
119
|
-
export function Mount(ctx, { bind }) {
|
|
120
|
-
if (!(ctx instanceof Tag)) {
|
|
121
|
-
throw userError("<Mount bind/> can be used only as direct child of html tags", "context-mismatch");
|
|
122
|
-
}
|
|
123
|
-
ctx.bindMount(bind instanceof IValue ? bind : ctx.ref(bind));
|
|
124
|
-
}
|
|
125
|
-
export function Show(ctx, { bind }) {
|
|
126
|
-
if (!(ctx instanceof Tag)) {
|
|
127
|
-
throw userError("<Show bind/> can be used only as direct child of html tags", "context-mismatch");
|
|
128
|
-
}
|
|
129
|
-
ctx.bindShow(bind instanceof IValue ? bind : ctx.ref(bind));
|
|
130
|
-
}
|
|
131
111
|
export function Delay(ctx, { time, slot }) {
|
|
132
|
-
const fragment = new Fragment({}, ":timer");
|
|
112
|
+
const fragment = new Fragment({}, ctx.runner, ":timer");
|
|
133
113
|
const dSlot = readValue(slot);
|
|
134
114
|
let timer;
|
|
135
115
|
ctx.create(fragment, function (node) {
|
package/lib/compose.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Fragment, App, reportError, IValue, Reference } from "vasille";
|
|
2
2
|
function proxy(obj) {
|
|
3
3
|
return new Proxy(obj, {
|
|
4
4
|
get(target, p) {
|
|
@@ -6,9 +6,9 @@ function proxy(obj) {
|
|
|
6
6
|
},
|
|
7
7
|
});
|
|
8
8
|
}
|
|
9
|
-
function create(renderer,
|
|
9
|
+
function create(renderer, name) {
|
|
10
10
|
return function (node, props, slot) {
|
|
11
|
-
const frag =
|
|
11
|
+
const frag = new Fragment(props, node.runner, name);
|
|
12
12
|
if (slot) {
|
|
13
13
|
props.slot = slot;
|
|
14
14
|
}
|
|
@@ -20,26 +20,16 @@ function create(renderer, create, name) {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
catch (e) {
|
|
23
|
-
if (config.debugUi) {
|
|
24
|
-
console.error(`Vasille: Error found in component ${name}`, e);
|
|
25
|
-
}
|
|
26
23
|
reportError(e);
|
|
27
24
|
}
|
|
28
25
|
};
|
|
29
26
|
}
|
|
30
27
|
export function compose(renderer, name) {
|
|
31
|
-
return create(renderer,
|
|
32
|
-
return new Fragment(props, name);
|
|
33
|
-
}, name);
|
|
34
|
-
}
|
|
35
|
-
export function extend(renderer, name) {
|
|
36
|
-
return create(renderer, props => {
|
|
37
|
-
return new Extension(props, name);
|
|
38
|
-
}, name);
|
|
28
|
+
return create(renderer, name);
|
|
39
29
|
}
|
|
40
|
-
export function mount(tag, component, $) {
|
|
41
|
-
const root = new App(tag, {});
|
|
42
|
-
const frag = new Fragment({}, ":app-root");
|
|
30
|
+
export function mount(tag, component, runner, $) {
|
|
31
|
+
const root = new App(tag, runner, {});
|
|
32
|
+
const frag = new Fragment({}, runner, ":app-root");
|
|
43
33
|
root.create(frag, function () {
|
|
44
34
|
component(frag, $);
|
|
45
35
|
});
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { compose,
|
|
3
|
-
export { awaited } from "./library";
|
|
4
|
-
export { internal as $ } from "./internal";
|
|
1
|
+
export { Debug, Delay, Else, ElseIf, For, If, Slot, Watch } from "./components.js";
|
|
2
|
+
export { compose, mount } from "./compose.js";
|
|
3
|
+
export { awaited } from "./library.js";
|
|
4
|
+
export { internal as $ } from "./internal.js";
|
package/lib/internal.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { proxyArrayModel, Expression, Pointer, Reference } from "vasille";
|
|
2
|
-
import { reactiveObject, reactiveObjectProxy } from "./objects";
|
|
3
|
-
import { ContextArray, ContextMap, ContextSet } from "./models";
|
|
2
|
+
import { reactiveObject, reactiveObjectProxy, storeReactiveObject } from "./objects.js";
|
|
3
|
+
import { ContextArray, ContextMap, ContextSet } from "./models.js";
|
|
4
4
|
export const internal = {
|
|
5
5
|
/** create an expression (without context), use it for OwningPointer */
|
|
6
|
-
ex(func,
|
|
7
|
-
return new Expression(func,
|
|
6
|
+
ex(func, values) {
|
|
7
|
+
return new Expression(func, values);
|
|
8
8
|
},
|
|
9
9
|
/** create a forward-only pointer (without context), use it for OwningPointer */
|
|
10
10
|
fo(v) {
|
|
11
|
-
return new Pointer(v);
|
|
11
|
+
return new Pointer(v instanceof Reference ? v : new Reference(v));
|
|
12
12
|
},
|
|
13
13
|
/** create a reference (without context), use it for default composing props values */
|
|
14
14
|
r(v) {
|
|
@@ -18,26 +18,32 @@ export const internal = {
|
|
|
18
18
|
rop(o) {
|
|
19
19
|
return reactiveObjectProxy(o);
|
|
20
20
|
},
|
|
21
|
-
/**
|
|
22
|
-
* translate `{...}` to `$.ro(this, {...})`
|
|
23
|
-
*/
|
|
21
|
+
/** translate `{...}` to `$.ro(this, {...})` */
|
|
24
22
|
ro: reactiveObject,
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return node.register(new
|
|
36
|
-
},
|
|
37
|
-
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return
|
|
23
|
+
/** translate `new Set(#)` to `$.sm(this, #)` */
|
|
24
|
+
sm(node, data, name) {
|
|
25
|
+
return node.register(new ContextSet(data), name);
|
|
26
|
+
},
|
|
27
|
+
/** translate `new Map(#)` to `$.mm(this, #)` */
|
|
28
|
+
mm(node, data, name) {
|
|
29
|
+
return node.register(new ContextMap(data), name);
|
|
30
|
+
},
|
|
31
|
+
/** translate `[...]` to `$.am(this, [...])` */
|
|
32
|
+
am(node, data, name) {
|
|
33
|
+
return node.register(proxyArrayModel(new ContextArray(data)), name);
|
|
34
|
+
},
|
|
35
|
+
/** translate `{...} to $.sro({...})` */
|
|
36
|
+
sro: storeReactiveObject,
|
|
37
|
+
/** translate `new Set(#)` to `$.ssm(#)` */
|
|
38
|
+
ssm(data) {
|
|
39
|
+
return new ContextSet(data);
|
|
40
|
+
},
|
|
41
|
+
/** translate `new Map(#)` to `$.smm(#)` */
|
|
42
|
+
smm(data) {
|
|
43
|
+
return new ContextMap(data);
|
|
44
|
+
},
|
|
45
|
+
/** translate `[...]` to `$.sam([...])` */
|
|
46
|
+
sam(data) {
|
|
47
|
+
return proxyArrayModel(new ContextArray(data));
|
|
42
48
|
},
|
|
43
49
|
};
|
package/lib/library.js
CHANGED
|
@@ -1,24 +1,44 @@
|
|
|
1
1
|
import { IValue } from "vasille";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import { storeReactiveObject } from "./objects.js";
|
|
3
|
+
export function awaited(node, target, errName, dataName) {
|
|
4
|
+
const value = node.ref(undefined, dataName);
|
|
5
|
+
const err = node.ref(undefined, errName);
|
|
6
|
+
let running = false;
|
|
7
|
+
function run() {
|
|
8
|
+
if (running) {
|
|
9
|
+
return;
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
let current = target;
|
|
12
|
+
running = true;
|
|
13
|
+
err.$ = undefined;
|
|
14
|
+
value.$ = undefined;
|
|
15
|
+
if (typeof current === "function") {
|
|
16
|
+
try {
|
|
17
|
+
current = current();
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
current = undefined;
|
|
21
|
+
err.$ = e;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (current instanceof Promise) {
|
|
25
|
+
current
|
|
26
|
+
.then(result => (value.$ = result))
|
|
27
|
+
.catch(e => (err.$ = e))
|
|
28
|
+
.finally(() => (running = false));
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
value.$ = current;
|
|
32
|
+
running = false;
|
|
13
33
|
}
|
|
14
34
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
35
|
+
run();
|
|
36
|
+
return [err, value, run];
|
|
37
|
+
}
|
|
38
|
+
export function store(fn) {
|
|
39
|
+
return (input) => {
|
|
40
|
+
return input ? fn(storeReactiveObject(input)) : fn();
|
|
41
|
+
};
|
|
22
42
|
}
|
|
23
43
|
export function ensureIValue(node, value) {
|
|
24
44
|
return value instanceof IValue ? value : node.ref(value);
|
package/lib/models.js
CHANGED
|
@@ -1,41 +1,35 @@
|
|
|
1
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
-
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");
|
|
4
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
-
};
|
|
6
|
-
var _Context_instances, _Context_ctx, _Context_enableObject, _Context_disableObject;
|
|
7
1
|
import { ArrayModel, Destroyable, MapModel, Reactive, SetModel } from "vasille";
|
|
8
|
-
import { ProxyReference, proxyObject } from "./objects";
|
|
2
|
+
import { ProxyReference, proxyObject } from "./objects.js";
|
|
9
3
|
const symbol = Symbol("proxy");
|
|
10
4
|
class Context extends Destroyable {
|
|
11
5
|
constructor() {
|
|
12
6
|
super(...arguments);
|
|
13
|
-
|
|
14
|
-
_Context_ctx.set(this, new Reactive({}));
|
|
7
|
+
this.ctx = new Reactive({});
|
|
15
8
|
}
|
|
16
9
|
checkEnable(value) {
|
|
17
10
|
if (value && typeof value === "object" && value.constructor === Object) {
|
|
18
|
-
return
|
|
11
|
+
return this.enableObject(value);
|
|
19
12
|
}
|
|
20
13
|
return value;
|
|
21
14
|
}
|
|
22
15
|
checkDisable(value) {
|
|
23
16
|
if (value && typeof value === "object" && value.constructor === Object) {
|
|
24
|
-
|
|
17
|
+
this.disableObject(value);
|
|
25
18
|
}
|
|
26
19
|
}
|
|
20
|
+
enableObject(o) {
|
|
21
|
+
const ref = new ProxyReference(undefined);
|
|
22
|
+
o[symbol] = ref;
|
|
23
|
+
this.ctx.register(ref);
|
|
24
|
+
return proxyObject(o, ref);
|
|
25
|
+
}
|
|
26
|
+
disableObject(o) {
|
|
27
|
+
this.ctx.release(o[symbol]);
|
|
28
|
+
}
|
|
27
29
|
destroy() {
|
|
28
|
-
|
|
30
|
+
this.ctx.destroy();
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
|
-
_Context_ctx = new WeakMap(), _Context_instances = new WeakSet(), _Context_enableObject = function _Context_enableObject(o) {
|
|
32
|
-
const ref = new ProxyReference(undefined);
|
|
33
|
-
o[symbol] = ref;
|
|
34
|
-
__classPrivateFieldGet(this, _Context_ctx, "f").register(ref);
|
|
35
|
-
return proxyObject(o, ref);
|
|
36
|
-
}, _Context_disableObject = function _Context_disableObject(o) {
|
|
37
|
-
__classPrivateFieldGet(this, _Context_ctx, "f").release(o[symbol]);
|
|
38
|
-
};
|
|
39
33
|
export class ContextArray extends ArrayModel {
|
|
40
34
|
constructor(data) {
|
|
41
35
|
const ctx = new Context();
|
package/lib/objects.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IValue, Reference } from "vasille";
|
|
2
|
-
import { ensureIValue } from "./library";
|
|
2
|
+
import { ensureIValue } from "./library.js";
|
|
3
3
|
export class ProxyReference extends Reference {
|
|
4
4
|
forceUpdate() {
|
|
5
5
|
this.updateDeps(this.state);
|
|
@@ -42,12 +42,15 @@ export function proxy(o) {
|
|
|
42
42
|
}
|
|
43
43
|
return o;
|
|
44
44
|
}
|
|
45
|
-
export function reactiveObject(node, o) {
|
|
45
|
+
export function reactiveObject(node, o, name) {
|
|
46
46
|
for (const key of Object.keys(o)) {
|
|
47
47
|
if (!(o[key] instanceof IValue)) {
|
|
48
48
|
o[key] = ensureIValue(node, proxy(o[key]));
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
+
if (name) {
|
|
52
|
+
node.addState("reactiveObject", name, o);
|
|
53
|
+
}
|
|
51
54
|
return new Proxy(o, {
|
|
52
55
|
get(_, p) {
|
|
53
56
|
if (p in o) {
|
|
@@ -76,3 +79,20 @@ export function reactiveObjectProxy(o) {
|
|
|
76
79
|
},
|
|
77
80
|
});
|
|
78
81
|
}
|
|
82
|
+
export function storeReactiveObject(o) {
|
|
83
|
+
for (const key of Object.keys(o)) {
|
|
84
|
+
if (!(o[key] instanceof IValue)) {
|
|
85
|
+
o[key] = new Reference(proxy(o[key]));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return new Proxy(o, {
|
|
89
|
+
get(_, p) {
|
|
90
|
+
if (p in o) {
|
|
91
|
+
return o[p];
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
return (o[p] = new Reference(undefined));
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
}
|
package/package.json
CHANGED
|
@@ -1,27 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vasille-jsx",
|
|
3
|
-
"version": "3.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "3.1.2",
|
|
4
|
+
"description": "The first Developer eXperience Orientated front-end framework (JSX components)",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"exports": {
|
|
7
|
+
"types": "./types/index.d.ts",
|
|
7
8
|
"import": "./lib/index.js",
|
|
8
|
-
"browser": "./lib/index.js"
|
|
9
|
-
"node": "./lib-node/index.js",
|
|
10
|
-
"require": "./lib-node/index.js"
|
|
9
|
+
"browser": "./lib/index.js"
|
|
11
10
|
},
|
|
11
|
+
"types": "./types/index.d.ts",
|
|
12
12
|
"scripts": {
|
|
13
13
|
"prepack": "cp -f ../README.md ./README.md",
|
|
14
14
|
"prettier": "npx prettier src test --write",
|
|
15
15
|
"build": "tsc --build tsconfig.json",
|
|
16
|
-
"build-node": "tsc --build tsconfig-build-node.json",
|
|
17
16
|
"update-types": "tsc --build tsconfig-types.json",
|
|
18
|
-
"test": "jest",
|
|
19
|
-
"test-coverage": "jest --coverage"
|
|
17
|
+
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
|
|
18
|
+
"test-coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage"
|
|
20
19
|
},
|
|
20
|
+
"type": "module",
|
|
21
21
|
"keywords": [
|
|
22
22
|
"frone-end",
|
|
23
23
|
"jsx",
|
|
24
|
-
"vasille"
|
|
24
|
+
"vasille",
|
|
25
|
+
"safe",
|
|
26
|
+
"simple",
|
|
27
|
+
"poweful"
|
|
25
28
|
],
|
|
26
29
|
"author": "lixcode",
|
|
27
30
|
"license": "MIT",
|
|
@@ -34,17 +37,18 @@
|
|
|
34
37
|
"url": "git+https://github.com/vasille-js/vasille-js.git"
|
|
35
38
|
},
|
|
36
39
|
"dependencies": {
|
|
37
|
-
"vasille": "^3.0
|
|
40
|
+
"vasille": "^3.1.0"
|
|
38
41
|
},
|
|
39
42
|
"devDependencies": {
|
|
40
|
-
"@types/jest": "^
|
|
43
|
+
"@types/jest": "^30.0.0",
|
|
41
44
|
"@types/jsdom": "^21.1.7",
|
|
42
|
-
"@typescript-eslint/parser": "^8.
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
45
|
+
"@typescript-eslint/parser": "^8.38.0",
|
|
46
|
+
"cross-env": "^10.0.0",
|
|
47
|
+
"eslint": "^9.32.0",
|
|
48
|
+
"jest": "^30.0.5",
|
|
49
|
+
"jsdom": "^26.1.0",
|
|
50
|
+
"prettier": "^3.6.2",
|
|
51
|
+
"ts-jest": "^29.4.0",
|
|
52
|
+
"typescript": "^5.8.3"
|
|
49
53
|
}
|
|
50
54
|
}
|
package/types/components.d.ts
CHANGED
|
@@ -3,44 +3,38 @@ type Magic<T extends object> = {
|
|
|
3
3
|
[K in keyof T]: T[K] | IValue<T[K]> | undefined;
|
|
4
4
|
};
|
|
5
5
|
export declare function readValue<T>(v: T | IValue<T>): T;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
slot?: (ctx: Fragment) => void;
|
|
9
|
-
}
|
|
10
|
-
export declare function Slot<T extends object = {}>(ctx: Fragment, options: Magic<
|
|
11
|
-
|
|
12
|
-
slot?: (ctx: Fragment) => void;
|
|
13
|
-
}> & T): void;
|
|
14
|
-
export declare function If(ctx: Fragment, { condition, slot: magicSlot }: Magic<{
|
|
6
|
+
interface SlotOptions<Node, Element, TagOptions extends object, T extends object> {
|
|
7
|
+
model?: (input: T, ctx: Fragment<Node, Element, TagOptions>) => void;
|
|
8
|
+
slot?: (ctx: Fragment<Node, Element, TagOptions>) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function Slot<Node, Element, TagOptions extends object, T extends object = {}>(ctx: Fragment<Node, Element, TagOptions>, options: Magic<SlotOptions<Node, Element, TagOptions, T>> & T): void;
|
|
11
|
+
interface IfOptions {
|
|
15
12
|
condition: unknown;
|
|
16
13
|
slot?: () => void;
|
|
17
|
-
}
|
|
18
|
-
export declare function
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}>): void;
|
|
22
|
-
export declare function Else(ctx: Fragment, { slot: magicSlot }: Magic<{
|
|
14
|
+
}
|
|
15
|
+
export declare function If<Node, Element, TagOptions extends object>(ctx: Fragment<Node, Element, TagOptions>, { condition, slot: magicSlot }: Magic<IfOptions>): void;
|
|
16
|
+
export declare function ElseIf<Node, Element, TagOptions extends object>(ctx: Fragment<Node, Element, TagOptions>, { condition, slot: magicSlot }: Magic<IfOptions>): void;
|
|
17
|
+
interface ElseOptions {
|
|
23
18
|
slot?: () => void;
|
|
24
|
-
}
|
|
25
|
-
export declare function
|
|
19
|
+
}
|
|
20
|
+
export declare function Else<Node, Element, TagOptions extends object>(ctx: Fragment<Node, Element, TagOptions>, { slot: magicSlot }: Magic<ElseOptions>): void;
|
|
21
|
+
interface ForOptions<Node, Element, TagOptions extends object, T, K, V> {
|
|
26
22
|
of: T;
|
|
27
|
-
slot?: (ctx: Fragment, value: T, index: K) => void;
|
|
28
|
-
}
|
|
29
|
-
export declare function
|
|
23
|
+
slot?: (ctx: Fragment<Node, Element, TagOptions>, value: T, index: K) => void;
|
|
24
|
+
}
|
|
25
|
+
export declare function For<Node, Element, TagOptions extends object, T extends Set<unknown> | Map<unknown, unknown> | unknown[], K = T extends unknown[] ? number : T extends Set<infer R> ? R : T extends Map<infer R, unknown> ? R : never, V = T extends (infer R)[] ? R : T extends Set<infer R> ? R : T extends Map<unknown, infer R> ? R : never>(ctx: Fragment<Node, Element, TagOptions>, { of, slot: magicSlot }: Magic<ForOptions<Node, Element, TagOptions, T, K, V>>): void;
|
|
26
|
+
interface WatchOptions<Node, Element, TagOptions extends object, T> {
|
|
30
27
|
model: T;
|
|
31
|
-
slot?: (ctx: Fragment, value: T) => void;
|
|
32
|
-
}
|
|
33
|
-
export declare function
|
|
28
|
+
slot?: (ctx: Fragment<Node, Element, TagOptions>, value: T) => void;
|
|
29
|
+
}
|
|
30
|
+
export declare function Watch<Node, Element, TagOptions extends object, T>(ctx: Fragment<Node, Element, TagOptions>, { model, slot: magicSlot }: Magic<WatchOptions<Node, Element, TagOptions, T>>): void;
|
|
31
|
+
interface DebugOptions {
|
|
34
32
|
model: unknown;
|
|
35
|
-
}
|
|
36
|
-
export declare function
|
|
37
|
-
|
|
38
|
-
}>): void;
|
|
39
|
-
export declare function Show(ctx: Fragment, { bind }: Magic<{
|
|
40
|
-
bind: unknown;
|
|
41
|
-
}>): void;
|
|
42
|
-
export declare function Delay(ctx: Fragment, { time, slot }: Magic<{
|
|
33
|
+
}
|
|
34
|
+
export declare function Debug<Node, Element, TagOptions extends object>(ctx: Fragment<Node, Element, TagOptions>, { model }: DebugOptions): void;
|
|
35
|
+
interface DelayOptions<Node, Element, TagOptions extends object> {
|
|
43
36
|
time?: number;
|
|
44
|
-
slot?: (ctx: Fragment) => unknown;
|
|
45
|
-
}
|
|
37
|
+
slot?: (ctx: Fragment<Node, Element, TagOptions>) => unknown;
|
|
38
|
+
}
|
|
39
|
+
export declare function Delay<Node, Element, TagOptions extends object>(ctx: Fragment<Node, Element, TagOptions>, { time, slot }: Magic<DelayOptions<Node, Element, TagOptions>>): void;
|
|
46
40
|
export {};
|
package/types/compose.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { Fragment } from "vasille";
|
|
1
|
+
import { Fragment, Runner } from "vasille";
|
|
2
2
|
interface CompositionProps {
|
|
3
3
|
slot?: (...args: any[]) => void;
|
|
4
4
|
}
|
|
5
|
-
type Composed<In extends CompositionProps, Out> = (node: Fragment, $: In & {
|
|
5
|
+
type Composed<Node, Element, TagOptions extends object, In extends CompositionProps, Out> = (node: Fragment<Node, Element, TagOptions>, $: In & {
|
|
6
6
|
callback?(data: Out | undefined): void;
|
|
7
7
|
}, slot?: In["slot"]) => void;
|
|
8
|
-
export declare function compose<In extends CompositionProps, Out>(renderer: (node: Fragment, input: In) => Out, name: string): Composed<In, Out>;
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function mount<T>(tag: Element, component: (node: Fragment, $: T) => unknown, $: T): void;
|
|
8
|
+
export declare function compose<Node, Element, TagOptions extends object, In extends CompositionProps, Out>(renderer: (node: Fragment<Node, Element, TagOptions>, input: In) => Out, name: string): Composed<Node, Element, TagOptions, In, Out>;
|
|
9
|
+
export declare function mount<Node, Element, TagOptions extends object, T>(tag: Element, component: (node: Fragment<Node, Element, TagOptions>, $: T) => unknown, runner: Runner<Node, Element, TagOptions>, $: T): void;
|
|
11
10
|
export {};
|
package/types/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { compose,
|
|
3
|
-
export { awaited } from "./library";
|
|
4
|
-
export { internal as $ } from "./internal";
|
|
5
|
-
export { TagNameMap, HtmlTagMap, Tag, HtmlAndSvgEvents, EventHandler } from "./spec/html";
|
|
6
|
-
export { SvgTagMap, SvgTagNameMap } from "./spec/svg";
|
|
1
|
+
export { Debug, Delay, Else, ElseIf, For, If, Slot, Watch } from "./components.js";
|
|
2
|
+
export { compose, mount } from "./compose.js";
|
|
3
|
+
export { awaited } from "./library.js";
|
|
4
|
+
export { internal as $ } from "./internal.js";
|
package/types/internal.d.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import { IValue, Reactive, KindOfIValue, Expression } from "vasille";
|
|
2
|
-
import { reactiveObject } from "./objects";
|
|
3
|
-
import { ContextMap, ContextSet } from "./models";
|
|
2
|
+
import { reactiveObject, storeReactiveObject } from "./objects.js";
|
|
3
|
+
import { ContextMap, ContextSet } from "./models.js";
|
|
4
4
|
export declare const internal: {
|
|
5
5
|
/** create an expression (without context), use it for OwningPointer */
|
|
6
|
-
ex<T, Args extends unknown[]>(func: (...args: Args) => T,
|
|
6
|
+
ex<T, Args extends unknown[]>(func: (...args: Args) => T, values: KindOfIValue<Args>): Expression<T, Args>;
|
|
7
7
|
/** create a forward-only pointer (without context), use it for OwningPointer */
|
|
8
|
-
fo<T>(v: IValue<T>): IValue<T>;
|
|
8
|
+
fo<T>(v: IValue<T> | T): IValue<T>;
|
|
9
9
|
/** create a reference (without context), use it for default composing props values */
|
|
10
10
|
r<T>(v: T): IValue<T>;
|
|
11
11
|
/** create a reactive object proxy, use it for sending reactive objects to child components */
|
|
12
12
|
rop<T extends {
|
|
13
13
|
[k: string | symbol]: IValue<unknown>;
|
|
14
14
|
}>(o: T): { [K in keyof T]: T[K] extends IValue<infer R> ? R : never; };
|
|
15
|
-
/**
|
|
16
|
-
* translate `{...}` to `$.ro(this, {...})`
|
|
17
|
-
*/
|
|
15
|
+
/** translate `{...}` to `$.ro(this, {...})` */
|
|
18
16
|
ro: typeof reactiveObject;
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
17
|
+
/** translate `new Set(#)` to `$.sm(this, #)` */
|
|
18
|
+
sm(node: Reactive, data?: unknown[], name?: string): ContextSet<unknown>;
|
|
19
|
+
/** translate `new Map(#)` to `$.mm(this, #)` */
|
|
20
|
+
mm(node: Reactive, data?: [unknown, unknown][], name?: string): ContextMap<unknown, unknown>;
|
|
21
|
+
/** translate `[...]` to `$.am(this, [...])` */
|
|
22
|
+
am(node: Reactive, data?: unknown[], name?: string): import("vasille").ArrayModel<unknown>;
|
|
23
|
+
/** translate `{...} to $.sro({...})` */
|
|
24
|
+
sro: typeof storeReactiveObject;
|
|
25
|
+
/** translate `new Set(#)` to `$.ssm(#)` */
|
|
26
|
+
ssm(data?: unknown[]): ContextSet<unknown>;
|
|
27
|
+
/** translate `new Map(#)` to `$.smm(#)` */
|
|
28
|
+
smm(data?: [unknown, unknown][]): ContextMap<unknown, unknown>;
|
|
29
|
+
/** translate `[...]` to `$.sam([...])` */
|
|
30
|
+
sam(data?: unknown[]): import("vasille").ArrayModel<unknown>;
|
|
31
31
|
};
|