@tempots/dom 5.0.0 → 5.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/dist/clean.d.ts +2 -0
- package/dist/clean.js +1 -0
- package/dist/components/Attribute.d.ts +15 -0
- package/dist/components/Attribute.js +16 -0
- package/dist/components/BooleanAttribute.d.ts +15 -0
- package/dist/components/BooleanAttribute.js +16 -0
- package/dist/components/ClassName.d.ts +13 -0
- package/dist/components/ClassName.js +14 -0
- package/dist/components/El.d.ts +15 -0
- package/dist/components/El.js +21 -0
- package/dist/components/FadeIn.d.ts +18 -0
- package/dist/components/FadeIn.js +52 -0
- package/dist/components/FadeOut.d.ts +16 -0
- package/dist/components/FadeOut.js +39 -0
- package/dist/components/For.d.ts +7 -0
- package/dist/components/For.js +15 -0
- package/dist/components/Fragment.d.ts +12 -0
- package/dist/components/Fragment.js +16 -0
- package/dist/components/HiddenWhenEmpty.d.ts +7 -0
- package/dist/components/HiddenWhenEmpty.js +12 -0
- package/dist/components/If.d.ts +14 -0
- package/dist/components/If.js +19 -0
- package/dist/components/InnerHTML.d.ts +13 -0
- package/dist/components/InnerHTML.js +23 -0
- package/dist/components/Lifecycle.d.ts +14 -0
- package/dist/components/Lifecycle.js +18 -0
- package/dist/components/Match.d.ts +33 -0
- package/dist/components/Match.js +44 -0
- package/dist/components/NotEmpty.d.ts +10 -0
- package/dist/components/NotEmpty.js +11 -0
- package/dist/components/On.d.ts +15 -0
- package/dist/components/On.js +14 -0
- package/dist/components/OnRemove.d.ts +11 -0
- package/dist/components/OnRemove.js +14 -0
- package/dist/components/OneOf.d.ts +20 -0
- package/dist/components/OneOf.js +45 -0
- package/dist/components/Portal.d.ts +15 -0
- package/dist/components/Portal.js +20 -0
- package/dist/components/Property.d.ts +15 -0
- package/dist/components/Property.js +16 -0
- package/dist/components/Provider.d.ts +28 -0
- package/dist/components/Provider.js +44 -0
- package/dist/components/Repeat.d.ts +15 -0
- package/dist/components/Repeat.js +33 -0
- package/dist/components/Shadow.d.ts +0 -0
- package/dist/components/Shadow.js +1 -0
- package/dist/components/Show.d.ts +20 -0
- package/dist/components/Show.js +22 -0
- package/dist/components/Text.d.ts +15 -0
- package/dist/components/Text.js +33 -0
- package/dist/components/TextContent.d.ts +13 -0
- package/dist/components/TextContent.js +23 -0
- package/dist/components/Tween.d.ts +75 -0
- package/dist/components/Tween.js +242 -0
- package/dist/components/animatable.d.ts +53 -0
- package/dist/components/animatable.js +156 -0
- package/dist/dom-context.d.ts +38 -0
- package/dist/dom-context.js +260 -0
- package/dist/helpers/handle-anchor-click.d.ts +4 -0
- package/dist/helpers/handle-anchor-click.js +43 -0
- package/dist/helpers/handle-text-input.d.ts +1 -0
- package/dist/helpers/handle-text-input.js +4 -0
- package/dist/helpers/is-empty-element.d.ts +2 -0
- package/dist/helpers/is-empty-element.js +8 -0
- package/dist/index.d.ts +36 -0
- package/dist/jsx-dev-runtime.d.ts +1 -0
- package/dist/jsx-dev-runtime.js +1 -0
- package/dist/jsx-runtime.d.ts +9 -0
- package/dist/jsx-runtime.js +157 -0
- package/dist/jsx.d.ts +806 -0
- package/dist/jsx.js +1 -0
- package/dist/prop.d.ts +43 -0
- package/dist/prop.js +174 -0
- package/dist/render.d.ts +3 -0
- package/dist/render.js +7 -0
- package/dist/renderable.d.ts +5 -0
- package/dist/renderable.js +1 -0
- package/dist/types/clean.d.ts +2 -0
- package/dist/types/clean.js +1 -0
- package/dist/types/idom-context.d.ts +27 -0
- package/dist/types/idom-context.js +3 -0
- package/dist/types/renderable.d.ts +5 -0
- package/dist/types/renderable.js +1 -0
- package/package.json +5 -1
- package/.eslintignore +0 -10
- package/.eslintrc.cjs +0 -28
- package/coverage/clover.xml +0 -39
- package/coverage/coverage-final.json +0 -2
- package/coverage/lcov-report/OneOf.ts.html +0 -256
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/dom-context.ts.html +0 -928
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -116
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/prop.ts.html +0 -691
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/src/components/Attribute.ts.html +0 -154
- package/coverage/lcov-report/src/components/BooleanAttribute.ts.html +0 -154
- package/coverage/lcov-report/src/components/ClassName.ts.html +0 -151
- package/coverage/lcov-report/src/components/El.ts.html +0 -166
- package/coverage/lcov-report/src/components/FadeIn.ts.html +0 -262
- package/coverage/lcov-report/src/components/FadeOut.ts.html +0 -226
- package/coverage/lcov-report/src/components/For.ts.html +0 -151
- package/coverage/lcov-report/src/components/Fragment.ts.html +0 -142
- package/coverage/lcov-report/src/components/HiddenWhenEmpty.ts.html +0 -133
- package/coverage/lcov-report/src/components/If.ts.html +0 -217
- package/coverage/lcov-report/src/components/InnerHTML.ts.html +0 -178
- package/coverage/lcov-report/src/components/Lifecycle.ts.html +0 -157
- package/coverage/lcov-report/src/components/Match.ts.html +0 -286
- package/coverage/lcov-report/src/components/NotEmpty.tsx.html +0 -184
- package/coverage/lcov-report/src/components/On.ts.html +0 -151
- package/coverage/lcov-report/src/components/OnRemove.ts.html +0 -145
- package/coverage/lcov-report/src/components/OneOf.ts.html +0 -256
- package/coverage/lcov-report/src/components/Portal.ts.html +0 -175
- package/coverage/lcov-report/src/components/Property.ts.html +0 -154
- package/coverage/lcov-report/src/components/Provider.ts.html +0 -244
- package/coverage/lcov-report/src/components/Repeat.ts.html +0 -223
- package/coverage/lcov-report/src/components/Show.tsx.html +0 -190
- package/coverage/lcov-report/src/components/Text.ts.html +0 -229
- package/coverage/lcov-report/src/components/TextContent.ts.html +0 -178
- package/coverage/lcov-report/src/components/Tween.tsx.html +0 -943
- package/coverage/lcov-report/src/components/animatable.ts.html +0 -619
- package/coverage/lcov-report/src/components/index.html +0 -476
- package/coverage/lcov-report/src/dom-context.ts.html +0 -928
- package/coverage/lcov-report/src/helpers/handle-anchor-click.ts.html +0 -277
- package/coverage/lcov-report/src/helpers/handle-text-input.ts.html +0 -100
- package/coverage/lcov-report/src/helpers/index.html +0 -146
- package/coverage/lcov-report/src/helpers/is-empty-element.ts.html +0 -112
- package/coverage/lcov-report/src/index.html +0 -176
- package/coverage/lcov-report/src/index.ts.html +0 -412
- package/coverage/lcov-report/src/jsx-runtime.ts.html +0 -601
- package/coverage/lcov-report/src/prop.ts.html +0 -691
- package/coverage/lcov-report/src/render.ts.html +0 -112
- package/coverage/lcov-report/src/types/idom-context.ts.html +0 -184
- package/coverage/lcov-report/src/types/index.html +0 -116
- package/coverage/lcov-report/test/common.ts.html +0 -112
- package/coverage/lcov-report/test/index.html +0 -116
- package/coverage/lcov.info +0 -57
- package/jest.config.js +0 -5
- package/src/clean.ts +0 -2
- package/src/components/Attribute.ts +0 -23
- package/src/components/BooleanAttribute.ts +0 -23
- package/src/components/ClassName.ts +0 -22
- package/src/components/El.ts +0 -27
- package/src/components/FadeIn.ts +0 -59
- package/src/components/FadeOut.ts +0 -47
- package/src/components/For.ts +0 -22
- package/src/components/Fragment.ts +0 -19
- package/src/components/HiddenWhenEmpty.ts +0 -16
- package/src/components/If.ts +0 -44
- package/src/components/InnerHTML.ts +0 -31
- package/src/components/Lifecycle.ts +0 -24
- package/src/components/Match.ts +0 -67
- package/src/components/NotEmpty.tsx +0 -33
- package/src/components/On.ts +0 -22
- package/src/components/OnRemove.ts +0 -20
- package/src/components/OneOf.ts +0 -57
- package/src/components/Portal.ts +0 -30
- package/src/components/Property.ts +0 -23
- package/src/components/Provider.ts +0 -53
- package/src/components/Repeat.ts +0 -46
- package/src/components/Show.tsx +0 -35
- package/src/components/Text.ts +0 -48
- package/src/components/TextContent.ts +0 -31
- package/src/components/animatable.ts +0 -178
- package/src/dom-context.ts +0 -281
- package/src/helpers/handle-anchor-click.ts +0 -64
- package/src/helpers/handle-text-input.ts +0 -5
- package/src/helpers/is-empty-element.ts +0 -9
- package/src/index.ts +0 -109
- package/src/jsx-dev-runtime.ts +0 -8
- package/src/jsx-runtime.ts +0 -172
- package/src/jsx.ts +0 -1046
- package/src/prop.ts +0 -202
- package/src/render.ts +0 -9
- package/src/renderable.ts +0 -6
- package/test/common.ts +0 -9
- package/test/component.spec.tsx +0 -27
- package/test/domcontext.spec.ts +0 -36
- package/test/fadein.spec.tsx +0 -36
- package/test/fadeout.spec.tsx +0 -41
- package/test/if.spec.tsx +0 -30
- package/test/innerhtml.spec.tsx +0 -45
- package/test/prop.spec.ts +0 -10
- package/test/render.spec.tsx +0 -19
- package/test/textcontent.spec.tsx +0 -45
- package/test/when.spec.tsx +0 -30
- package/tsconfig.json +0 -21
package/dist/clean.d.ts
ADDED
package/dist/clean.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type DOMContext } from '../dom-context';
|
|
2
|
+
import { type Signal } from '../prop';
|
|
3
|
+
import { type Clear } from '../clean';
|
|
4
|
+
import { type Renderable } from '../renderable';
|
|
5
|
+
export declare class AttributeImpl implements Renderable {
|
|
6
|
+
private readonly name;
|
|
7
|
+
private readonly value;
|
|
8
|
+
constructor(name: string, value: Signal<string>);
|
|
9
|
+
readonly appendTo: (ctx: DOMContext) => Clear;
|
|
10
|
+
}
|
|
11
|
+
export interface AttributeProps {
|
|
12
|
+
name: string;
|
|
13
|
+
value: Signal<string>;
|
|
14
|
+
}
|
|
15
|
+
export declare function Attribute({ name, value }: AttributeProps): Renderable;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { subscribeToSignal } from './Text';
|
|
2
|
+
export class AttributeImpl {
|
|
3
|
+
name;
|
|
4
|
+
value;
|
|
5
|
+
constructor(name, value) {
|
|
6
|
+
this.name = name;
|
|
7
|
+
this.value = value;
|
|
8
|
+
}
|
|
9
|
+
appendTo = (ctx) => {
|
|
10
|
+
const [set, clear] = ctx.createAttribute(this.name, this.value.get());
|
|
11
|
+
return subscribeToSignal(this.value, set, clear);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function Attribute({ name, value }) {
|
|
15
|
+
return new AttributeImpl(name, value);
|
|
16
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type DOMContext } from '../dom-context';
|
|
2
|
+
import { type Signal } from '../prop';
|
|
3
|
+
import { type Clear } from '../clean';
|
|
4
|
+
import { type Renderable } from '../renderable';
|
|
5
|
+
export declare class BooleanAttributeImpl implements Renderable {
|
|
6
|
+
private readonly name;
|
|
7
|
+
private readonly value;
|
|
8
|
+
constructor(name: string, value: Signal<boolean>);
|
|
9
|
+
readonly appendTo: (ctx: DOMContext) => Clear;
|
|
10
|
+
}
|
|
11
|
+
export interface BooleanAttributeProps {
|
|
12
|
+
name: string;
|
|
13
|
+
value: Signal<boolean>;
|
|
14
|
+
}
|
|
15
|
+
export declare function BooleanAttribute({ name, value }: BooleanAttributeProps): Renderable;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { subscribeToSignal } from './Text';
|
|
2
|
+
export class BooleanAttributeImpl {
|
|
3
|
+
name;
|
|
4
|
+
value;
|
|
5
|
+
constructor(name, value) {
|
|
6
|
+
this.name = name;
|
|
7
|
+
this.value = value;
|
|
8
|
+
}
|
|
9
|
+
appendTo = (ctx) => {
|
|
10
|
+
const [set, clear] = ctx.createBooleanAttribute(this.name, this.value.get());
|
|
11
|
+
return subscribeToSignal(this.value, set, clear);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function BooleanAttribute({ name, value }) {
|
|
15
|
+
return new BooleanAttributeImpl(name, value);
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Signal } from '../prop';
|
|
2
|
+
import { type Renderable } from '../renderable';
|
|
3
|
+
import { type Clear } from '../clean';
|
|
4
|
+
import { type DOMContext } from '../dom-context';
|
|
5
|
+
export declare class ClassNameImpl implements Renderable {
|
|
6
|
+
private readonly cls;
|
|
7
|
+
constructor(cls: Signal<string> | Signal<string | undefined>);
|
|
8
|
+
readonly appendTo: (ctx: DOMContext) => Clear;
|
|
9
|
+
}
|
|
10
|
+
export interface ClassNameProps {
|
|
11
|
+
value: Signal<string> | Signal<string | undefined>;
|
|
12
|
+
}
|
|
13
|
+
export declare function ClassName({ value }: ClassNameProps): Renderable;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { subscribeToSignal } from './Text';
|
|
2
|
+
export class ClassNameImpl {
|
|
3
|
+
cls;
|
|
4
|
+
constructor(cls) {
|
|
5
|
+
this.cls = cls;
|
|
6
|
+
}
|
|
7
|
+
appendTo = (ctx) => {
|
|
8
|
+
const [set, clear] = ctx.createClass(this.cls.get() ?? '');
|
|
9
|
+
return subscribeToSignal(this.cls.map(v => v ?? ''), set, clear);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export function ClassName({ value }) {
|
|
13
|
+
return new ClassNameImpl(value);
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type DOMContext } from '../dom-context';
|
|
2
|
+
import { type Clear } from '../clean';
|
|
3
|
+
import { type Renderable } from '../renderable';
|
|
4
|
+
import { type JSX } from '../jsx';
|
|
5
|
+
export declare class ElImpl implements Renderable {
|
|
6
|
+
private readonly tagName;
|
|
7
|
+
private readonly children;
|
|
8
|
+
constructor(tagName: string, children: Renderable[]);
|
|
9
|
+
readonly appendTo: (ctx: DOMContext) => Clear;
|
|
10
|
+
}
|
|
11
|
+
export interface ElProps {
|
|
12
|
+
tagName: string;
|
|
13
|
+
children?: JSX.DOMNode;
|
|
14
|
+
}
|
|
15
|
+
export declare function El({ tagName, children }: ElProps): Renderable;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { makeRenderables } from '../jsx-runtime';
|
|
2
|
+
export class ElImpl {
|
|
3
|
+
tagName;
|
|
4
|
+
children;
|
|
5
|
+
constructor(tagName, children) {
|
|
6
|
+
this.tagName = tagName;
|
|
7
|
+
this.children = children;
|
|
8
|
+
}
|
|
9
|
+
appendTo = (ctx) => {
|
|
10
|
+
const newCtx = ctx.makeElement(this.tagName);
|
|
11
|
+
const clears = this.children.map(child => child.appendTo(newCtx));
|
|
12
|
+
return (removeTree) => {
|
|
13
|
+
newCtx.requestClear(removeTree, () => {
|
|
14
|
+
clears.forEach(clear => { clear(false); });
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function El({ tagName, children }) {
|
|
20
|
+
return new ElImpl(tagName, makeRenderables(children));
|
|
21
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Clear } from "../clean";
|
|
2
|
+
import { DOMContext } from "../dom-context";
|
|
3
|
+
import { Renderable } from "../renderable";
|
|
4
|
+
import { Animatable } from "./animatable";
|
|
5
|
+
export declare class FadeInImpl implements Renderable {
|
|
6
|
+
private readonly end;
|
|
7
|
+
private readonly start;
|
|
8
|
+
private readonly duration;
|
|
9
|
+
private readonly delay;
|
|
10
|
+
constructor(end: Animatable, start: Animatable | undefined, duration: number, delay: number);
|
|
11
|
+
appendTo(ctx: DOMContext): Clear;
|
|
12
|
+
}
|
|
13
|
+
export interface FadeInProps extends Animatable {
|
|
14
|
+
start?: Animatable;
|
|
15
|
+
duration?: number;
|
|
16
|
+
delay?: number;
|
|
17
|
+
}
|
|
18
|
+
export declare function FadeIn(props: FadeInProps): Renderable;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { getComputedAnimatable, applyInterpolatedAnimatable, applyAnimatable } from "./animatable";
|
|
2
|
+
export class FadeInImpl {
|
|
3
|
+
end;
|
|
4
|
+
start;
|
|
5
|
+
duration;
|
|
6
|
+
delay;
|
|
7
|
+
constructor(end, start, duration, delay) {
|
|
8
|
+
this.end = end;
|
|
9
|
+
this.start = start;
|
|
10
|
+
this.duration = duration;
|
|
11
|
+
this.delay = delay;
|
|
12
|
+
}
|
|
13
|
+
appendTo(ctx) {
|
|
14
|
+
const el = ctx.getElement();
|
|
15
|
+
const start = (() => {
|
|
16
|
+
if (this.start != null) {
|
|
17
|
+
applyAnimatable(el, this.start);
|
|
18
|
+
return this.start;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return getComputedAnimatable(el, this.end);
|
|
22
|
+
}
|
|
23
|
+
})();
|
|
24
|
+
const startTime = Date.now() + this.delay;
|
|
25
|
+
const { duration, end } = this;
|
|
26
|
+
let nextFrameId = null;
|
|
27
|
+
function frame() {
|
|
28
|
+
const now = Date.now();
|
|
29
|
+
if (now < startTime) {
|
|
30
|
+
nextFrameId = requestAnimationFrame(frame);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const progress = Math.min((now - startTime) / duration, 1);
|
|
34
|
+
applyInterpolatedAnimatable(el, start, end, progress);
|
|
35
|
+
if (progress < 1) {
|
|
36
|
+
nextFrameId = requestAnimationFrame(frame);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
nextFrameId = null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
frame();
|
|
43
|
+
return (_) => {
|
|
44
|
+
if (nextFrameId != null)
|
|
45
|
+
cancelAnimationFrame(nextFrameId);
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export function FadeIn(props) {
|
|
50
|
+
const { start, duration, delay, ...end } = props;
|
|
51
|
+
return new FadeInImpl(end, start, duration ?? 200, delay ?? 0);
|
|
52
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Clear } from "../clean";
|
|
2
|
+
import { DOMContext } from "../dom-context";
|
|
3
|
+
import { Renderable } from "../renderable";
|
|
4
|
+
import { Animatable } from "./animatable";
|
|
5
|
+
export declare class FadeOutImpl implements Renderable {
|
|
6
|
+
private readonly end;
|
|
7
|
+
private readonly duration;
|
|
8
|
+
private readonly delay;
|
|
9
|
+
constructor(end: Animatable, duration: number, delay: number);
|
|
10
|
+
appendTo(ctx: DOMContext): Clear;
|
|
11
|
+
}
|
|
12
|
+
export interface FadeOutProps extends Animatable {
|
|
13
|
+
duration?: number;
|
|
14
|
+
delay?: number;
|
|
15
|
+
}
|
|
16
|
+
export declare function FadeOut(props: FadeOutProps): Renderable;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { getComputedAnimatable, applyInterpolatedAnimatable } from "./animatable";
|
|
2
|
+
export class FadeOutImpl {
|
|
3
|
+
end;
|
|
4
|
+
duration;
|
|
5
|
+
delay;
|
|
6
|
+
constructor(end, duration, delay) {
|
|
7
|
+
this.end = end;
|
|
8
|
+
this.duration = duration;
|
|
9
|
+
this.delay = delay;
|
|
10
|
+
}
|
|
11
|
+
appendTo(ctx) {
|
|
12
|
+
const el = ctx.getElement();
|
|
13
|
+
const { duration, end } = this;
|
|
14
|
+
return ctx.delayClear((removeTree, clear) => {
|
|
15
|
+
const start = getComputedAnimatable(el, this.end);
|
|
16
|
+
const startTime = Date.now() + this.delay;
|
|
17
|
+
function frame() {
|
|
18
|
+
const now = Date.now();
|
|
19
|
+
if (now < startTime) {
|
|
20
|
+
requestAnimationFrame(frame);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const progress = Math.min((now - startTime) / duration, 1);
|
|
24
|
+
applyInterpolatedAnimatable(el, start, end, progress);
|
|
25
|
+
if (progress < 1) {
|
|
26
|
+
requestAnimationFrame(frame);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
clear();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
requestAnimationFrame(frame);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function FadeOut(props) {
|
|
37
|
+
const { duration, delay, ...end } = props;
|
|
38
|
+
return new FadeOutImpl(end, duration ?? 200, delay ?? 0);
|
|
39
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Signal } from '../prop';
|
|
2
|
+
import { type JSX } from '../jsx-runtime';
|
|
3
|
+
export interface ForProps<T> {
|
|
4
|
+
of: Signal<T[]>;
|
|
5
|
+
children?: (value: Signal<T>, index: number) => JSX.DOMNode;
|
|
6
|
+
}
|
|
7
|
+
export declare function For<T>({ of, children: render }: ForProps<T>): JSX.DOMNode;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { RepeatImpl } from './Repeat';
|
|
2
|
+
import { makeRenderable } from '../jsx-runtime';
|
|
3
|
+
import { FragmentImpl } from './Fragment';
|
|
4
|
+
import { OnRemoveImpl } from './OnRemove';
|
|
5
|
+
// <For of={values}>{(value) => <span>{value}</span>}</For>
|
|
6
|
+
export function For({ of, children: render }) {
|
|
7
|
+
const times = of.map(v => v.length);
|
|
8
|
+
return new RepeatImpl(times, (index) => {
|
|
9
|
+
const value = of.at(index);
|
|
10
|
+
return new FragmentImpl([
|
|
11
|
+
makeRenderable(render?.(value, index)),
|
|
12
|
+
new OnRemoveImpl(value.clean)
|
|
13
|
+
]);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Renderable } from '../renderable';
|
|
2
|
+
import { type Clear } from '../clean';
|
|
3
|
+
import { type DOMContext } from '../dom-context';
|
|
4
|
+
import { type JSX } from '../jsx';
|
|
5
|
+
export declare class FragmentImpl implements Renderable {
|
|
6
|
+
private readonly children;
|
|
7
|
+
constructor(children: Renderable[]);
|
|
8
|
+
readonly appendTo: (ctx: DOMContext) => Clear;
|
|
9
|
+
}
|
|
10
|
+
export declare function Fragment({ children }: {
|
|
11
|
+
children: JSX.DOMNode;
|
|
12
|
+
}): Renderable;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { makeRenderables } from '../jsx-runtime';
|
|
2
|
+
export class FragmentImpl {
|
|
3
|
+
children;
|
|
4
|
+
constructor(children) {
|
|
5
|
+
this.children = children;
|
|
6
|
+
}
|
|
7
|
+
appendTo = (ctx) => {
|
|
8
|
+
const clears = this.children.map(child => child.appendTo(ctx));
|
|
9
|
+
return (removeTree) => {
|
|
10
|
+
clears.forEach(clear => { clear(removeTree); });
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function Fragment({ children }) {
|
|
15
|
+
return new FragmentImpl(makeRenderables(children));
|
|
16
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Renderable } from '../renderable';
|
|
2
|
+
import { type DOMContext } from '../dom-context';
|
|
3
|
+
import { type Clear } from '../clean';
|
|
4
|
+
export declare class HiddenWhenEmptyImpl implements Renderable {
|
|
5
|
+
appendTo(ctx: DOMContext): Clear;
|
|
6
|
+
}
|
|
7
|
+
export declare function HiddenWhenEmpty(): HiddenWhenEmptyImpl;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class HiddenWhenEmptyImpl {
|
|
2
|
+
appendTo(ctx) {
|
|
3
|
+
ctx.setStyle(':empty', 'display: none');
|
|
4
|
+
return (removeTree) => {
|
|
5
|
+
if (removeTree)
|
|
6
|
+
ctx.setStyle(':empty', null);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function HiddenWhenEmpty() {
|
|
11
|
+
return new HiddenWhenEmptyImpl();
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type JSX } from '../jsx';
|
|
2
|
+
import { type Signal } from '../prop';
|
|
3
|
+
export interface IfProps {
|
|
4
|
+
is: Signal<boolean>;
|
|
5
|
+
then?: JSX.DOMNode;
|
|
6
|
+
otherwise?: JSX.DOMNode;
|
|
7
|
+
}
|
|
8
|
+
export declare function If({ is, then, otherwise }: IfProps): JSX.DOMNode;
|
|
9
|
+
export interface WhenProps {
|
|
10
|
+
is: Signal<boolean>;
|
|
11
|
+
children?: JSX.DOMNode;
|
|
12
|
+
}
|
|
13
|
+
export declare function When({ is, children }: WhenProps): JSX.DOMNode;
|
|
14
|
+
export declare function Unless({ is, children }: WhenProps): JSX.DOMNode;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { OneOfImpl } from './OneOf';
|
|
2
|
+
export function If({ is, then, otherwise }) {
|
|
3
|
+
return new OneOfImpl(is.map(v => v ? [1, true] : [2, false]), {
|
|
4
|
+
1: () => then,
|
|
5
|
+
2: () => otherwise
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
export function When({ is, children }) {
|
|
9
|
+
return new OneOfImpl(is.map(v => v ? [1, true] : [2, false]), {
|
|
10
|
+
1: () => children,
|
|
11
|
+
2: () => null
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export function Unless({ is, children }) {
|
|
15
|
+
return new OneOfImpl(is.map(v => v ? [1, true] : [2, false]), {
|
|
16
|
+
1: () => null,
|
|
17
|
+
2: () => children
|
|
18
|
+
});
|
|
19
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Signal } from '../prop';
|
|
2
|
+
import { type Clear } from '../clean';
|
|
3
|
+
import { type DOMContext } from '../dom-context';
|
|
4
|
+
import { type Renderable } from '../renderable';
|
|
5
|
+
export declare class InnerHTMLImpl implements Renderable {
|
|
6
|
+
private readonly html;
|
|
7
|
+
constructor(html: Signal<string> | Signal<string | undefined>);
|
|
8
|
+
readonly appendTo: (ctx: DOMContext) => Clear;
|
|
9
|
+
}
|
|
10
|
+
export interface InnerHTMLProps {
|
|
11
|
+
html: Signal<string> | Signal<string | undefined>;
|
|
12
|
+
}
|
|
13
|
+
export declare function InnerHTML({ html }: InnerHTMLProps): InnerHTMLImpl;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export class InnerHTMLImpl {
|
|
2
|
+
html;
|
|
3
|
+
constructor(html) {
|
|
4
|
+
this.html = html;
|
|
5
|
+
}
|
|
6
|
+
appendTo = (ctx) => {
|
|
7
|
+
const el = ctx.getElement();
|
|
8
|
+
const previous = el.innerHTML;
|
|
9
|
+
el.innerHTML = this.html.get() ?? '';
|
|
10
|
+
const cancel = this.html.subscribe(value => {
|
|
11
|
+
el.innerHTML = value ?? '';
|
|
12
|
+
});
|
|
13
|
+
return (removeTree) => {
|
|
14
|
+
cancel();
|
|
15
|
+
if (removeTree) {
|
|
16
|
+
el.innerHTML = previous;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function InnerHTML({ html }) {
|
|
22
|
+
return new InnerHTMLImpl(html);
|
|
23
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Clear } from '../clean';
|
|
2
|
+
import { type DOMContext } from '../dom-context';
|
|
3
|
+
import { type Renderable } from '../renderable';
|
|
4
|
+
export declare class LifecycleImpl implements Renderable {
|
|
5
|
+
private readonly onMount;
|
|
6
|
+
private readonly onUnmount;
|
|
7
|
+
constructor(onMount: (el: HTMLElement) => void, onUnmount: (el: HTMLElement) => void);
|
|
8
|
+
readonly appendTo: (ctx: DOMContext) => Clear;
|
|
9
|
+
}
|
|
10
|
+
export interface LifecycleProps {
|
|
11
|
+
onMount?: (el: HTMLElement) => void;
|
|
12
|
+
onUnmount?: (el: HTMLElement) => void;
|
|
13
|
+
}
|
|
14
|
+
export declare function Lifecycle({ onMount, onUnmount }: LifecycleProps): Renderable;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class LifecycleImpl {
|
|
2
|
+
onMount;
|
|
3
|
+
onUnmount;
|
|
4
|
+
constructor(onMount, onUnmount) {
|
|
5
|
+
this.onMount = onMount;
|
|
6
|
+
this.onUnmount = onUnmount;
|
|
7
|
+
}
|
|
8
|
+
appendTo = (ctx) => {
|
|
9
|
+
this.onMount(ctx.getElement());
|
|
10
|
+
return () => {
|
|
11
|
+
this.onUnmount(ctx.getElement());
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export function Lifecycle({ onMount, onUnmount }) {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
17
|
+
return new LifecycleImpl(onMount ?? (() => { }), onUnmount ?? (() => { }));
|
|
18
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type Signal } from '../prop';
|
|
2
|
+
import { type DOMContext } from '../dom-context';
|
|
3
|
+
import { type AnyKey } from './OneOf';
|
|
4
|
+
import { type JSX } from '../jsx-runtime';
|
|
5
|
+
import { type Clear } from '../clean';
|
|
6
|
+
export declare class MatchImpl<T extends {
|
|
7
|
+
[_ in K]: any;
|
|
8
|
+
}, K extends keyof T> {
|
|
9
|
+
private readonly on;
|
|
10
|
+
private readonly using;
|
|
11
|
+
private readonly matches;
|
|
12
|
+
constructor(on: Signal<T>, using: K, matches: {
|
|
13
|
+
[KIND in T[K]]: (_: Signal<T & {
|
|
14
|
+
[KK in K]: KIND extends T[KK] ? KIND : never;
|
|
15
|
+
}>) => JSX.DOMNode;
|
|
16
|
+
});
|
|
17
|
+
readonly appendTo: (ctx: DOMContext) => Clear;
|
|
18
|
+
}
|
|
19
|
+
export type MatchProps<T extends {
|
|
20
|
+
[_ in K]: AnyKey;
|
|
21
|
+
}, K extends keyof T> = {
|
|
22
|
+
on: Signal<T>;
|
|
23
|
+
using: K;
|
|
24
|
+
} & {
|
|
25
|
+
matches: {
|
|
26
|
+
[KIND in T[K]]: (_: Signal<T & {
|
|
27
|
+
[KK in K]: KIND extends T[KK] ? KIND : never;
|
|
28
|
+
}>) => JSX.DOMNode;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export declare function Match<T extends {
|
|
32
|
+
[_ in K]: AnyKey;
|
|
33
|
+
}, K extends keyof T>({ on, using, matches }: MatchProps<T, K>): JSX.DOMNode;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { makeRenderable } from '../jsx-runtime';
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3
|
+
export class MatchImpl {
|
|
4
|
+
on;
|
|
5
|
+
using;
|
|
6
|
+
matches;
|
|
7
|
+
constructor(on, using, matches) {
|
|
8
|
+
this.on = on;
|
|
9
|
+
this.using = using;
|
|
10
|
+
this.matches = matches;
|
|
11
|
+
}
|
|
12
|
+
appendTo = (ctx) => {
|
|
13
|
+
let newCtx = ctx.makeReference();
|
|
14
|
+
const value = this.on.get();
|
|
15
|
+
let key = value[this.using];
|
|
16
|
+
let derived = this.on.map(v => v);
|
|
17
|
+
let renderable = makeRenderable(this.matches[key](derived));
|
|
18
|
+
let clear = renderable.appendTo(newCtx);
|
|
19
|
+
const cancel = this.on.subscribe(newValue => {
|
|
20
|
+
const newKey = newValue[this.using];
|
|
21
|
+
if (newKey === key)
|
|
22
|
+
return;
|
|
23
|
+
newCtx.requestClear(true, () => {
|
|
24
|
+
clear(true);
|
|
25
|
+
derived.clean();
|
|
26
|
+
key = newKey;
|
|
27
|
+
derived = this.on.map(v => v);
|
|
28
|
+
newCtx = newCtx.makeReference();
|
|
29
|
+
renderable = makeRenderable(this.matches[key](derived));
|
|
30
|
+
clear = renderable.appendTo(newCtx);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
return (removeTree) => {
|
|
34
|
+
newCtx.requestClear(removeTree, () => {
|
|
35
|
+
cancel();
|
|
36
|
+
derived.clean();
|
|
37
|
+
clear(removeTree);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export function Match({ on, using, matches }) {
|
|
43
|
+
return new MatchImpl(on, using, matches);
|
|
44
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** @jsxImportSource .. */
|
|
2
|
+
import { type Signal } from '../prop';
|
|
3
|
+
import { type AnyKey } from './OneOf';
|
|
4
|
+
import { type JSX } from '../jsx-runtime';
|
|
5
|
+
export interface NotEmptyProps<T> {
|
|
6
|
+
on: Signal<T>;
|
|
7
|
+
whenEmpty?: JSX.DOMNode;
|
|
8
|
+
display: JSX.DOMNode;
|
|
9
|
+
}
|
|
10
|
+
export declare function NotEmpty<T extends unknown[] | Record<AnyKey, unknown>>({ on, display, whenEmpty }: NotEmptyProps<T>): JSX.DOMNode;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "../jsx-runtime";
|
|
2
|
+
import { If } from './If';
|
|
3
|
+
function isEmpty(obj) {
|
|
4
|
+
return Object.keys(obj).length === 0;
|
|
5
|
+
}
|
|
6
|
+
// <NotEmpty on={maybevalue} whenEmpty={<span>nothing to show</span>}}>{value => value.toText()}</NotEmpty>
|
|
7
|
+
export function NotEmpty({ on, display, whenEmpty }) {
|
|
8
|
+
return (_jsx(If, { is: on.map((v) =>
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
+
Array.isArray(v) ? v.length > 0 : v != null && !isEmpty(v)), then: display, otherwise: whenEmpty }));
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Renderable } from '../renderable';
|
|
2
|
+
import { type Clear } from '../clean';
|
|
3
|
+
import { type DOMContext } from '../dom-context';
|
|
4
|
+
export type OnFn<T> = (value: T) => void;
|
|
5
|
+
export declare class OnImpl<T> implements Renderable {
|
|
6
|
+
private readonly name;
|
|
7
|
+
private readonly handler;
|
|
8
|
+
constructor(name: string, handler: OnFn<T>);
|
|
9
|
+
readonly appendTo: (ctx: DOMContext) => Clear;
|
|
10
|
+
}
|
|
11
|
+
export interface OnProps<T> {
|
|
12
|
+
name: string;
|
|
13
|
+
handler: OnFn<T>;
|
|
14
|
+
}
|
|
15
|
+
export declare function On<T>({ name, handler }: OnProps<T>): Renderable;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export class OnImpl {
|
|
2
|
+
name;
|
|
3
|
+
handler;
|
|
4
|
+
constructor(name, handler) {
|
|
5
|
+
this.name = name;
|
|
6
|
+
this.handler = handler;
|
|
7
|
+
}
|
|
8
|
+
appendTo = (ctx) => {
|
|
9
|
+
return ctx.createHandler(this.name, this.handler);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export function On({ name, handler }) {
|
|
13
|
+
return new OnImpl(name, handler);
|
|
14
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Clear } from '../clean';
|
|
2
|
+
import { type Renderable } from '../renderable';
|
|
3
|
+
export declare class OnRemoveImpl implements Renderable {
|
|
4
|
+
private readonly clear;
|
|
5
|
+
constructor(clear: Clear);
|
|
6
|
+
readonly appendTo: () => Clear;
|
|
7
|
+
}
|
|
8
|
+
export interface OnRemoveProps {
|
|
9
|
+
clear: Clear;
|
|
10
|
+
}
|
|
11
|
+
export declare function OnRemove(props: OnRemoveProps): OnRemoveImpl;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export class OnRemoveImpl {
|
|
2
|
+
clear;
|
|
3
|
+
constructor(clear) {
|
|
4
|
+
this.clear = clear;
|
|
5
|
+
}
|
|
6
|
+
appendTo = () => {
|
|
7
|
+
return (removeTree) => {
|
|
8
|
+
this.clear(removeTree);
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export function OnRemove(props) {
|
|
13
|
+
return new OnRemoveImpl(props.clear);
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type Signal } from '../prop';
|
|
2
|
+
import { type Clear } from '../clean';
|
|
3
|
+
import { type DOMContext } from '../dom-context';
|
|
4
|
+
import { type Renderable } from '../renderable';
|
|
5
|
+
import { type JSX } from '../jsx';
|
|
6
|
+
export type AnyKey = string | number | symbol;
|
|
7
|
+
export declare class OneOfImpl<T extends [AnyKey, unknown]> implements Renderable {
|
|
8
|
+
private readonly match;
|
|
9
|
+
private readonly cases;
|
|
10
|
+
constructor(match: Signal<T>, cases: {
|
|
11
|
+
[KK in T[0]]: (value: Signal<T[1]>) => JSX.DOMNode;
|
|
12
|
+
});
|
|
13
|
+
readonly appendTo: (ctx: DOMContext) => Clear;
|
|
14
|
+
}
|
|
15
|
+
export type OneOfProps<T extends [AnyKey, unknown]> = {
|
|
16
|
+
match: Signal<T>;
|
|
17
|
+
} & {
|
|
18
|
+
[KK in T[0]]: (value: Signal<T[1]>) => JSX.DOMNode;
|
|
19
|
+
};
|
|
20
|
+
export declare function OneOf<T extends [AnyKey, unknown]>(props: OneOfProps<T>): JSX.DOMNode;
|