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
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProxyReference = void 0;
|
|
4
|
+
exports.proxyObject = proxyObject;
|
|
5
|
+
exports.proxy = proxy;
|
|
6
|
+
exports.reactiveObject = reactiveObject;
|
|
7
|
+
exports.reactiveObjectProxy = reactiveObjectProxy;
|
|
8
|
+
const vasille_1 = require("vasille");
|
|
9
|
+
const library_1 = require("./library");
|
|
10
|
+
class ProxyReference extends vasille_1.Reference {
|
|
11
|
+
forceUpdate() {
|
|
12
|
+
this.updateDeps(this.state);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.ProxyReference = ProxyReference;
|
|
16
|
+
function proxyObject(obj, proxyRef) {
|
|
17
|
+
return new Proxy(obj, {
|
|
18
|
+
get(target, p, receiver) {
|
|
19
|
+
const value = Reflect.get(target, p, receiver);
|
|
20
|
+
return value instanceof Object ? proxyObject(value, proxyRef) : value;
|
|
21
|
+
},
|
|
22
|
+
set(target, p, newValue, receiver) {
|
|
23
|
+
const response = Reflect.set(target, p, newValue, receiver);
|
|
24
|
+
if (response) {
|
|
25
|
+
proxyRef.forceUpdate();
|
|
26
|
+
}
|
|
27
|
+
return response;
|
|
28
|
+
},
|
|
29
|
+
defineProperty(target, property, attributes) {
|
|
30
|
+
const response = Reflect.defineProperty(target, property, attributes);
|
|
31
|
+
if (response) {
|
|
32
|
+
proxyRef.forceUpdate();
|
|
33
|
+
}
|
|
34
|
+
return response;
|
|
35
|
+
},
|
|
36
|
+
deleteProperty(target, p) {
|
|
37
|
+
const response = Reflect.deleteProperty(target, p);
|
|
38
|
+
if (response) {
|
|
39
|
+
proxyRef.forceUpdate();
|
|
40
|
+
}
|
|
41
|
+
return response;
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function proxy(o) {
|
|
46
|
+
if (typeof o === "object" && o && o.constructor === Object) {
|
|
47
|
+
const proxyRef = new ProxyReference(undefined);
|
|
48
|
+
proxyRef.$ = proxyObject(o, proxyRef);
|
|
49
|
+
return proxyRef;
|
|
50
|
+
}
|
|
51
|
+
return o;
|
|
52
|
+
}
|
|
53
|
+
function reactiveObject(node, o) {
|
|
54
|
+
for (const key of Object.keys(o)) {
|
|
55
|
+
if (!(o[key] instanceof vasille_1.IValue)) {
|
|
56
|
+
o[key] = (0, library_1.ensureIValue)(node, proxy(o[key]));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return new Proxy(o, {
|
|
60
|
+
get(_, p) {
|
|
61
|
+
if (p in o) {
|
|
62
|
+
return o[p];
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
return (o[p] = node.register(new vasille_1.Reference(undefined)));
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
deleteProperty(_, p) {
|
|
69
|
+
if (p in o && o[p] instanceof vasille_1.IValue) {
|
|
70
|
+
node.release(p[0]);
|
|
71
|
+
}
|
|
72
|
+
return Reflect.deleteProperty(o, p);
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function reactiveObjectProxy(o) {
|
|
77
|
+
return new Proxy(o, {
|
|
78
|
+
get(_, p) {
|
|
79
|
+
return o[p].$;
|
|
80
|
+
},
|
|
81
|
+
set(_, p, newValue) {
|
|
82
|
+
o[p].$ = newValue;
|
|
83
|
+
return true;
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vasille-jsx",
|
|
3
|
+
"version": "3.0.1",
|
|
4
|
+
"description": "Describe Vasille components using JSX",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
"import": "./lib/index.js",
|
|
8
|
+
"browser": "./lib/index.js",
|
|
9
|
+
"node": "./lib-node/index.js",
|
|
10
|
+
"require": "./lib-node/index.js"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"prepack": "cp -f ../README.md ./README.md",
|
|
14
|
+
"prettier": "npx prettier src test --write",
|
|
15
|
+
"build": "tsc --build tsconfig.json",
|
|
16
|
+
"build-node": "tsc --build tsconfig-build-node.json",
|
|
17
|
+
"update-types": "tsc --build tsconfig-types.json",
|
|
18
|
+
"test": "jest",
|
|
19
|
+
"test-coverage": "jest --coverage"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"frone-end",
|
|
23
|
+
"jsx",
|
|
24
|
+
"vasille"
|
|
25
|
+
],
|
|
26
|
+
"author": "lixcode",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"vasille": "^3.0.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/jest": "^29.5.13",
|
|
33
|
+
"@types/jsdom": "^21.1.7",
|
|
34
|
+
"@typescript-eslint/parser": "^8.9.0",
|
|
35
|
+
"eslint": "^9.12.0",
|
|
36
|
+
"jest": "^29.7.0",
|
|
37
|
+
"jsdom": "^25.0.1",
|
|
38
|
+
"prettier": "^3.3.3",
|
|
39
|
+
"ts-jest": "^29.2.5",
|
|
40
|
+
"typescript": "5.6.3"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Fragment, IValue } from "vasille";
|
|
2
|
+
type Magic<T extends object> = {
|
|
3
|
+
[K in keyof T]: T[K] | IValue<T[K]> | undefined;
|
|
4
|
+
};
|
|
5
|
+
export declare function readValue<T>(v: T | IValue<T>): T;
|
|
6
|
+
export declare function Adapter(ctx: Fragment, { node, slot }: Magic<{
|
|
7
|
+
node: Fragment;
|
|
8
|
+
slot?: (ctx: Fragment) => void;
|
|
9
|
+
}>): void;
|
|
10
|
+
export declare function Slot<T extends object = {}>(ctx: Fragment, options: Magic<{
|
|
11
|
+
model?: (input: T, ctx: Fragment) => void;
|
|
12
|
+
slot?: (ctx: Fragment) => void;
|
|
13
|
+
}> & T): void;
|
|
14
|
+
export declare function If(ctx: Fragment, { condition, slot: magicSlot }: Magic<{
|
|
15
|
+
condition: unknown;
|
|
16
|
+
slot?: () => void;
|
|
17
|
+
}>): void;
|
|
18
|
+
export declare function ElseIf(ctx: Fragment, { condition, slot: magicSlot }: Magic<{
|
|
19
|
+
condition: unknown;
|
|
20
|
+
slot?: () => void;
|
|
21
|
+
}>): void;
|
|
22
|
+
export declare function Else(ctx: Fragment, { slot: magicSlot }: Magic<{
|
|
23
|
+
slot?: () => void;
|
|
24
|
+
}>): void;
|
|
25
|
+
export declare function For<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, { of, slot: magicSlot }: Magic<{
|
|
26
|
+
of: T;
|
|
27
|
+
slot?: (ctx: Fragment, value: T, index: K) => void;
|
|
28
|
+
}>): void;
|
|
29
|
+
export declare function Watch<T>(ctx: Fragment, { model, slot: magicSlot }: Magic<{
|
|
30
|
+
model: T;
|
|
31
|
+
slot?: (ctx: Fragment, value: T) => void;
|
|
32
|
+
}>): void;
|
|
33
|
+
export declare function Debug(ctx: Fragment, { model }: {
|
|
34
|
+
model: unknown;
|
|
35
|
+
}): void;
|
|
36
|
+
export declare function Mount(ctx: Fragment, { bind }: Magic<{
|
|
37
|
+
bind: unknown;
|
|
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<{
|
|
43
|
+
time?: number;
|
|
44
|
+
slot?: (ctx: Fragment) => unknown;
|
|
45
|
+
}>): void;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Fragment } from "vasille";
|
|
2
|
+
interface CompositionProps {
|
|
3
|
+
slot?: (...args: any[]) => void;
|
|
4
|
+
}
|
|
5
|
+
type Composed<In extends CompositionProps, Out> = (node: Fragment, $: In & {
|
|
6
|
+
callback?(data: Out | undefined): void;
|
|
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 extend<In extends CompositionProps, Out>(renderer: (node: Fragment, input: In) => Out, name: string): Composed<In, Out>;
|
|
10
|
+
export declare function mount<T>(tag: Element, component: (node: Fragment, $: T) => unknown, $: T): void;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IValue } from "vasille";
|
|
2
|
+
export declare class PartialExpression extends IValue<unknown> {
|
|
3
|
+
private readonly values;
|
|
4
|
+
private readonly valuesCache;
|
|
5
|
+
private readonly func;
|
|
6
|
+
private readonly linkedFunc;
|
|
7
|
+
private readonly sync;
|
|
8
|
+
constructor(func: (...args: unknown[]) => unknown, values: unknown[]);
|
|
9
|
+
get $(): unknown;
|
|
10
|
+
set $(value: unknown);
|
|
11
|
+
on(handler: (value: unknown) => void): void;
|
|
12
|
+
off(handler: (value: unknown) => void): void;
|
|
13
|
+
destroy(): void;
|
|
14
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Adapter, Debug, Delay, Else, ElseIf, For, If, Mount, Show, Slot, Watch } from "./components";
|
|
2
|
+
export { compose, extend, mount } from "./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";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Fragment, IValue } from "vasille";
|
|
2
|
+
export declare function readValue<T>(v: T | IValue<T>): T;
|
|
3
|
+
export declare function setValue(target: unknown, value: unknown, fallback?: (v: unknown) => void): void;
|
|
4
|
+
export declare function asFragment(node: unknown): Fragment;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { IValue, Reactive, KindOfIValue, Expression } from "vasille";
|
|
2
|
+
import { reactiveObject } from "./objects";
|
|
3
|
+
import { ContextMap, ContextSet } from "./models";
|
|
4
|
+
export declare const internal: {
|
|
5
|
+
/** create an expression (without context), use it for OwningPointer */
|
|
6
|
+
ex<T, Args extends unknown[]>(func: (...args: Args) => T, ...values: KindOfIValue<Args>): Expression<T, Args>;
|
|
7
|
+
/** create a forward-only pointer (without context), use it for OwningPointer */
|
|
8
|
+
fo<T>(v: IValue<T>): IValue<T>;
|
|
9
|
+
/** create a reference (without context), use it for default composing props values */
|
|
10
|
+
r<T>(v: T): IValue<T>;
|
|
11
|
+
/** create a reactive object proxy, use it for sending reactive objects to child components */
|
|
12
|
+
rop<T extends {
|
|
13
|
+
[k: string | symbol]: IValue<unknown>;
|
|
14
|
+
}>(o: T): { [K in keyof T]: T[K] extends IValue<infer R> ? R : never; };
|
|
15
|
+
/**
|
|
16
|
+
* translate `{...}` to `$.ro(this, {...})`
|
|
17
|
+
*/
|
|
18
|
+
ro: typeof reactiveObject;
|
|
19
|
+
/**
|
|
20
|
+
* translate `new Set(#)` to `$.sm(this, #)`
|
|
21
|
+
*/
|
|
22
|
+
sm(node: Reactive, data?: unknown[]): ContextSet<unknown>;
|
|
23
|
+
/**
|
|
24
|
+
* translate `new Map(#)` to `$.mm(this, #)`
|
|
25
|
+
*/
|
|
26
|
+
mm(node: Reactive, data?: [unknown, unknown][]): ContextMap<unknown, unknown>;
|
|
27
|
+
/**
|
|
28
|
+
* translate `[...]` to `$.am(this, [...])`
|
|
29
|
+
*/
|
|
30
|
+
am(node: Reactive, data?: unknown[]): import("vasille").ArrayModel<unknown>;
|
|
31
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ArrayModel, MapModel, SetModel } from "vasille";
|
|
2
|
+
export declare class ContextArray<T> extends ArrayModel<T> {
|
|
3
|
+
private ctx;
|
|
4
|
+
constructor(data?: Array<T> | number);
|
|
5
|
+
fill(value: T, start?: number, end?: number): this;
|
|
6
|
+
pop(): T | undefined;
|
|
7
|
+
push(...items: Array<T>): number;
|
|
8
|
+
shift(): T | undefined;
|
|
9
|
+
splice(start: number, deleteCount?: number | undefined, ...items: T[]): ArrayModel<T>;
|
|
10
|
+
unshift(...items: T[]): number;
|
|
11
|
+
replace(at: number, with_: T): this;
|
|
12
|
+
destroy(): void;
|
|
13
|
+
}
|
|
14
|
+
export declare class ContextMap<K, T> extends MapModel<K, T> {
|
|
15
|
+
private ctx;
|
|
16
|
+
constructor(map?: [K, T][]);
|
|
17
|
+
clear(): void;
|
|
18
|
+
delete(key: K): boolean;
|
|
19
|
+
set(key: K, value: T): this;
|
|
20
|
+
destroy(): void;
|
|
21
|
+
}
|
|
22
|
+
export declare class ContextSet<T> extends SetModel<T> {
|
|
23
|
+
private ctx;
|
|
24
|
+
private real;
|
|
25
|
+
constructor(set?: T[]);
|
|
26
|
+
add(value: T): this;
|
|
27
|
+
has(value: T): boolean;
|
|
28
|
+
clear(): void;
|
|
29
|
+
delete(value: T): boolean;
|
|
30
|
+
destroy(): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IValue, Reactive, Reference } from "vasille";
|
|
2
|
+
export declare class ProxyReference extends Reference<unknown> {
|
|
3
|
+
forceUpdate(): void;
|
|
4
|
+
}
|
|
5
|
+
export declare function proxyObject(obj: object, proxyRef: ProxyReference): object;
|
|
6
|
+
export declare function proxy(o: unknown): unknown;
|
|
7
|
+
export declare function reactiveObject<T extends object>(node: Reactive, o: T): {
|
|
8
|
+
[K in keyof T]: T[K] extends IValue<unknown> ? T[K] : IValue<T[K]>;
|
|
9
|
+
};
|
|
10
|
+
export declare function reactiveObjectProxy<T extends {
|
|
11
|
+
[k: string | symbol]: IValue<unknown>;
|
|
12
|
+
}>(o: T): {
|
|
13
|
+
[K in keyof T]: T[K] extends IValue<infer R> ? R : never;
|
|
14
|
+
};
|