sinho 0.2.3 → 0.3.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/array_mutation.js +1 -1
- package/dist/array_mutation.js.map +1 -1
- package/dist/bundle.d.ts +7 -2
- package/dist/bundle.js +73 -64
- package/dist/bundle.min.js +1 -1
- package/dist/component.js +4 -1
- package/dist/component.js.map +1 -1
- package/dist/intrinsic/Dynamic.d.ts +33 -0
- package/dist/intrinsic/Dynamic.js +53 -0
- package/dist/intrinsic/Dynamic.js.map +1 -0
- package/dist/intrinsic/ErrorBoundary.d.ts +14 -0
- package/dist/intrinsic/ErrorBoundary.js +36 -0
- package/dist/intrinsic/ErrorBoundary.js.map +1 -0
- package/dist/intrinsic/For.js +21 -36
- package/dist/intrinsic/For.js.map +1 -1
- package/dist/intrinsic/Fragment.d.ts +1 -1
- package/dist/intrinsic/Fragment.js +5 -3
- package/dist/intrinsic/Fragment.js.map +1 -1
- package/dist/intrinsic/If.js +16 -12
- package/dist/intrinsic/If.js.map +1 -1
- package/dist/intrinsic/Portal.js +4 -4
- package/dist/intrinsic/Portal.js.map +1 -1
- package/dist/intrinsic/TagComponent.js +3 -3
- package/dist/intrinsic/TagComponent.js.map +1 -1
- package/dist/mod.d.ts +2 -2
- package/dist/mod.js +1 -0
- package/dist/mod.js.map +1 -1
- package/dist/renderer.d.ts +1 -1
- package/dist/template.d.ts +7 -2
- package/dist/template.js +16 -0
- package/dist/template.js.map +1 -1
- package/package.json +1 -1
- package/src/array_mutation.ts +7 -4
- package/src/component.ts +4 -2
- package/src/intrinsic/For.ts +26 -43
- package/src/intrinsic/Fragment.ts +6 -4
- package/src/intrinsic/If.ts +22 -16
- package/src/intrinsic/Portal.ts +6 -4
- package/src/intrinsic/TagComponent.ts +4 -3
- package/src/mod.ts +2 -2
- package/src/renderer.ts +1 -1
- package/src/template.ts +31 -2
- package/tsconfig.json +2 -1
- package/web/dist/shingo.min.d.ts +1131 -0
- package/web/dist/shingo.min.js +1 -0
- package/web/static/dist/bundle.d.ts +1126 -0
- package/web/static/dist/bundle.min.js +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"For.js","sourceRoot":"","sources":["../../src/intrinsic/For.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EACL,WAAW,EAGX,SAAS,
|
|
1
|
+
{"version":3,"file":"For.js","sourceRoot":"","sources":["../../src/intrinsic/For.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EACL,WAAW,EAGX,SAAS,EAET,SAAS,EACT,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAY,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAOzE;;GAEG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,CAAI,KAQtB,EAAY,EAAE,CACb,cAAc,CAAC,GAAG,EAAE;IAClB,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,MAAM,KAAK,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;IACpD,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC;IAChE,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IACzC,MAAM,KAAK,GAA+B,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACvD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC3C,MAAM,cAAc,GAAG,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC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gBAEtD,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;gBACnC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,EAAE,SAAS,IAAI,EAAE,CAAC,CAAC;gBAElD,IAAI,UAAU,GAAG,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;gBAE7C,aAAa,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE;oBAC9C,UAAU,CAAC,UAAU,EAAE,YAAY,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;oBAClE,UAAU,GAAG,IAAI,CAAC;gBACpB,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC;IAErB,OAAO,KAAK,CAAC;AACf,CAAC,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FunctionalComponent } from "../component.js";
|
|
2
2
|
import { Template } from "../template.js";
|
|
3
|
-
import type
|
|
3
|
+
import { type MaybeSignal } from "../scope.js";
|
|
4
4
|
export type Children = Template | MaybeSignal<string | number | null | undefined> | Children[];
|
|
5
5
|
/**
|
|
6
6
|
* Fragment is a component that can be used to wrap multiple children without
|
|
@@ -20,9 +20,11 @@ export const Fragment = ({ children }) => createTemplate(() => {
|
|
|
20
20
|
return !Array.isArray(children)
|
|
21
21
|
? children == null
|
|
22
22
|
? []
|
|
23
|
-
:
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
: [
|
|
24
|
+
typeof children == "object"
|
|
25
|
+
? children.build()
|
|
26
|
+
: Text({ text: children }).build(),
|
|
27
|
+
]
|
|
26
28
|
: children.flatMap((children) => Fragment({ children }).build());
|
|
27
29
|
});
|
|
28
30
|
//# sourceMappingURL=Fragment.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Fragment.js","sourceRoot":"","sources":["../../src/intrinsic/Fragment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAY,MAAM,gBAAgB,CAAC;AAQ1D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,QAAQ,GAEhB,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CACpB,cAAc,CAAC,GAAG,EAAE;IAClB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;QAC7B,CAAC,CAAC,QAAQ,IAAI,IAAI;YAChB,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,OAAO,QAAQ,IAAI,QAAQ;
|
|
1
|
+
{"version":3,"file":"Fragment.js","sourceRoot":"","sources":["../../src/intrinsic/Fragment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAY,MAAM,gBAAgB,CAAC;AAQ1D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,QAAQ,GAEhB,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CACpB,cAAc,CAAC,GAAG,EAAE;IAClB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;QAC7B,CAAC,CAAC,QAAQ,IAAI,IAAI;YAChB,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC;gBACE,OAAO,QAAQ,IAAI,QAAQ;oBACzB,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE;oBAClB,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE;aACrC;QACL,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;AACrE,CAAC,CAAC,CAAC"}
|
package/dist/intrinsic/If.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createTemplate } from "../template.js";
|
|
1
|
+
import { TemplateNodes, createTemplate } from "../template.js";
|
|
2
2
|
import { MaybeSignal, useEffect, useMemo, useSubscope } from "../scope.js";
|
|
3
3
|
import { runWithRenderer, useRenderer } from "../renderer.js";
|
|
4
4
|
import { Fragment } from "./Fragment.js";
|
|
@@ -16,22 +16,26 @@ export const If = (props) => {
|
|
|
16
16
|
*/
|
|
17
17
|
export const ElseIf = (props) => {
|
|
18
18
|
const renderer = useRenderer();
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
renderer._ifConditions = [...
|
|
23
|
-
return runWithRenderer({ _ifConditions: [] }, () =>
|
|
19
|
+
const prevConditions = renderer._ifConditions;
|
|
20
|
+
const myCondition = MaybeSignal.upgrade(props.condition);
|
|
21
|
+
const fullCondition = useMemo(() => prevConditions.every((condition) => !condition()) && myCondition());
|
|
22
|
+
renderer._ifConditions = [...prevConditions, myCondition];
|
|
23
|
+
return createTemplate(() => runWithRenderer({ _ifConditions: [] }, () => {
|
|
24
24
|
const anchor = renderer._node(() => document.createComment(""));
|
|
25
|
-
const nodes = [anchor];
|
|
26
|
-
const template = useMemo(() =>
|
|
25
|
+
const nodes = [anchor, []];
|
|
26
|
+
const template = useMemo(() => fullCondition() ? Fragment({ children: props.children }) : null);
|
|
27
27
|
let subnodes = [];
|
|
28
28
|
useEffect(() => {
|
|
29
|
-
|
|
30
|
-
nodes
|
|
29
|
+
TemplateNodes.forEach(subnodes, (node) => node.parentNode?.removeChild(node));
|
|
30
|
+
nodes[1] = [];
|
|
31
31
|
const [, destroy] = useSubscope(() => {
|
|
32
32
|
subnodes = template()?.build() ?? [];
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
nodes[1] = subnodes;
|
|
34
|
+
let before = anchor;
|
|
35
|
+
TemplateNodes.forEach(subnodes, (node) => {
|
|
36
|
+
before.parentNode?.insertBefore(node, before.nextSibling);
|
|
37
|
+
before = node;
|
|
38
|
+
});
|
|
35
39
|
});
|
|
36
40
|
return destroy;
|
|
37
41
|
}, [template]);
|
package/dist/intrinsic/If.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"If.js","sourceRoot":"","sources":["../../src/intrinsic/If.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"If.js","sourceRoot":"","sources":["../../src/intrinsic/If.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAY,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEnD;;GAEG;AACH,MAAM,CAAC,MAAM,EAAE,GAGV,CAAC,KAAK,EAAE,EAAE;IACb,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,QAAQ,CAAC,aAAa,GAAG,EAAE,CAAC;IAE5B,OAAO,MAAM,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC1E,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAGd,CAAC,KAAK,EAAE,EAAE;IACb,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,MAAM,cAAc,GAAG,QAAQ,CAAC,aAAa,CAAC;IAC9C,MAAM,WAAW,GAAG,WAAW,CAAC,OAAO,CAAsB,KAAK,CAAC,SAAS,CAAC,CAAC;IAC9E,MAAM,aAAa,GAAG,OAAO,CAC3B,GAAG,EAA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E,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;oBAC1D,MAAM,GAAG,IAAI,CAAC;gBAChB,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,OAAO,OAAO,CAAC;QACjB,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;QAEf,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CACH,CAAC;AACJ,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,IAAI,GAAiD,CAAC,EACjE,QAAQ,GACT,EAAE,EAAE;IACH,OAAO,MAAM,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;AAC/C,CAAC,CAAC"}
|
package/dist/intrinsic/Portal.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { runWithRenderer } from "../renderer.js";
|
|
2
2
|
import { useEffect } from "../scope.js";
|
|
3
|
-
import { createTemplate } from "../template.js";
|
|
3
|
+
import { TemplateNodes, createTemplate } from "../template.js";
|
|
4
4
|
import { Fragment } from "./Fragment.js";
|
|
5
5
|
export const Portal = ({ mount, children }) => createTemplate(() => runWithRenderer({ _nodes: undefined }, () => {
|
|
6
6
|
const nodes = Fragment({ children }).build();
|
|
7
7
|
useEffect(() => {
|
|
8
|
-
|
|
8
|
+
TemplateNodes.forEach(nodes, (node) => mount.appendChild(node));
|
|
9
9
|
return () => {
|
|
10
|
-
|
|
10
|
+
TemplateNodes.forEach(nodes, (node) => node.parentNode?.removeChild(node));
|
|
11
11
|
};
|
|
12
|
-
});
|
|
12
|
+
}, []);
|
|
13
13
|
return [];
|
|
14
14
|
}));
|
|
15
15
|
//# sourceMappingURL=Portal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Portal.js","sourceRoot":"","sources":["../../src/intrinsic/Portal.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Portal.js","sourceRoot":"","sources":["../../src/intrinsic/Portal.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAY,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEnD,MAAM,CAAC,MAAM,MAAM,GAGd,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,CAC3B,cAAc,CAAC,GAAG,EAAE,CAClB,eAAe,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE;IAC1C,MAAM,KAAK,GAAG,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;IAE7C,SAAS,CAAC,GAAG,EAAE;QACb,aAAa,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;QAEhE,OAAO,GAAG,EAAE;YACV,aAAa,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CACpC,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,IAAI,CAAC,CACnC,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC,CACH,CAAC"}
|
|
@@ -3,7 +3,7 @@ import { jsxPropNameToEventName } from "../utils.js";
|
|
|
3
3
|
import { MaybeSignal, useBatch, useEffect, useScope } from "../scope.js";
|
|
4
4
|
import { Fragment } from "./Fragment.js";
|
|
5
5
|
import { runWithRenderer, useRenderer } from "../renderer.js";
|
|
6
|
-
import { createTemplate } from "../template.js";
|
|
6
|
+
import { createTemplate, TemplateNodes } from "../template.js";
|
|
7
7
|
export const hydrateElement = (node, svg, props, heuristic) => {
|
|
8
8
|
const { ref, style, children, dangerouslySetInnerHTML, ...attrs } = props;
|
|
9
9
|
for (const name in style ?? {}) {
|
|
@@ -49,10 +49,10 @@ export const hydrateElement = (node, svg, props, heuristic) => {
|
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
if (props.children != null) {
|
|
52
|
-
|
|
52
|
+
TemplateNodes.forEach(runWithRenderer({
|
|
53
53
|
_svg: svg,
|
|
54
54
|
_nodes: node.childNodes.values(),
|
|
55
|
-
}, () => Fragment({ children: props.children }).build()));
|
|
55
|
+
}, () => Fragment({ children: props.children }).build()), (subnode) => node.append(subnode));
|
|
56
56
|
}
|
|
57
57
|
return node;
|
|
58
58
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TagComponent.js","sourceRoot":"","sources":["../../src/intrinsic/TagComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAY,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"TagComponent.js","sourceRoot":"","sources":["../../src/intrinsic/TagComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,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EAAE,CACrD,EACD,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAClC,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,OAAe,EACf,QAAuB,EAAE,EACf,EAAE,CACZ,cAAc,CAAC,GAAG,EAAE;IAClB,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,MAAM,GAAG,GAAG,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;IACtD,MAAM,IAAI,GAAG,cAAc,CACzB,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,CAClB,CAAC,GAAG;QACF,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC;QACjC,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,4BAA4B,EAAE,OAAO,CAAC,CACpE,EACD,GAAG,EACH,KAAK,EACL,IAAI,CACL,CAAC;IAEF,OAAO,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC,CAAC,CAAC"}
|
package/dist/mod.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { type AttributeOptions, Component, type ComponentConstructor, type ComponentOptions, defineComponents, event, type EventConstructor, type FunctionalComponent, isComponent, type Metadata, prop, type PropOptions, useMountEffect as useEffect, } from "./component.js";
|
|
2
2
|
export { type Context, createContext, useContext } from "./context.js";
|
|
3
3
|
export { createElement, h } from "./create_element.js";
|
|
4
|
-
export { DangerousHtml, Styles } from "./dom.js";
|
|
5
|
-
export { type Template } from "./template.js";
|
|
4
|
+
export { type DangerousHtml, type Styles } from "./dom.js";
|
|
5
|
+
export { type Template, TemplateNodes } from "./template.js";
|
|
6
6
|
export { type Cleanup, MaybeSignal, type SetSignalOptions, type Signal, type SignalLike, type SignalSetter, type SubscopeOptions, type RefSignal, type RefSignalSetter, useSubscope, useMemo, useSignal, useRef, useBatch, flushBatch, } from "./scope.js";
|
|
7
7
|
export * from "./intrinsic/mod.js";
|
|
8
8
|
export * from "./jsx-runtime/mod.js";
|
package/dist/mod.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { Component, defineComponents, event, isComponent, prop, useMountEffect as useEffect, } from "./component.js";
|
|
2
2
|
export { createContext, useContext } from "./context.js";
|
|
3
3
|
export { createElement, h } from "./create_element.js";
|
|
4
|
+
export { TemplateNodes } from "./template.js";
|
|
4
5
|
export { MaybeSignal, useSubscope, useMemo, useSignal, useRef, useBatch, flushBatch, } from "./scope.js";
|
|
5
6
|
export * from "./intrinsic/mod.js";
|
|
6
7
|
export * from "./jsx-runtime/mod.js";
|
package/dist/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,SAAS,EAGT,gBAAgB,EAChB,KAAK,EAGL,WAAW,EAEX,IAAI,EAEJ,cAAc,IAAI,SAAS,GAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAgB,aAAa,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,SAAS,EAGT,gBAAgB,EAChB,KAAK,EAGL,WAAW,EAEX,IAAI,EAEJ,cAAc,IAAI,SAAS,GAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAgB,aAAa,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EAAiB,aAAa,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAEL,WAAW,EAQX,WAAW,EACX,OAAO,EACP,SAAS,EACT,MAAM,EACN,QAAQ,EACR,UAAU,GACX,MAAM,YAAY,CAAC;AAEpB,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC"}
|
package/dist/renderer.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ interface Renderer {
|
|
|
4
4
|
_component?: Component;
|
|
5
5
|
_svg?: boolean;
|
|
6
6
|
_nodes?: IterableIterator<Node>;
|
|
7
|
-
_ifConditions: SignalLike<boolean | undefined>[]
|
|
7
|
+
_ifConditions: Readonly<SignalLike<boolean | undefined>[]>;
|
|
8
8
|
_node<N extends Node>(fallback: () => N): N;
|
|
9
9
|
}
|
|
10
10
|
type RendererOverrides = Partial<Omit<Renderer, "_node">>;
|
package/dist/template.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
export type TemplateNodes = (Node | TemplateNodes)[];
|
|
2
|
+
export declare namespace TemplateNodes {
|
|
3
|
+
const forEach: (nodes: TemplateNodes, fn: (node: Node) => void) => void;
|
|
4
|
+
const last: (nodes: TemplateNodes, lastIndex?: number) => Node | undefined;
|
|
5
|
+
}
|
|
1
6
|
/**
|
|
2
7
|
* Represents a render result of a component.
|
|
3
8
|
*/
|
|
@@ -5,6 +10,6 @@ export interface Template {
|
|
|
5
10
|
/**
|
|
6
11
|
* Build the DOM elements represented by this template.
|
|
7
12
|
*/
|
|
8
|
-
build():
|
|
13
|
+
build(): TemplateNodes;
|
|
9
14
|
}
|
|
10
|
-
export declare const createTemplate: (build: () => Template |
|
|
15
|
+
export declare const createTemplate: (build: () => Template | TemplateNodes) => Template;
|
package/dist/template.js
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
export var TemplateNodes;
|
|
2
|
+
(function (TemplateNodes) {
|
|
3
|
+
TemplateNodes.forEach = (nodes, fn) => nodes.forEach((node) => Array.isArray(node) ? TemplateNodes.forEach(node, fn) : fn(node));
|
|
4
|
+
TemplateNodes.last = (nodes, lastIndex = nodes.length - 1) => {
|
|
5
|
+
if (!nodes.length)
|
|
6
|
+
return;
|
|
7
|
+
for (let i = lastIndex; i >= 0; i--) {
|
|
8
|
+
const last = nodes[i];
|
|
9
|
+
if (!Array.isArray(last))
|
|
10
|
+
return last;
|
|
11
|
+
const lastNode = TemplateNodes.last(last);
|
|
12
|
+
if (lastNode)
|
|
13
|
+
return lastNode;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
})(TemplateNodes || (TemplateNodes = {}));
|
|
1
17
|
export const createTemplate = (build) => ({
|
|
2
18
|
build() {
|
|
3
19
|
const nodes = build();
|
package/dist/template.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template.js","sourceRoot":"","sources":["../src/template.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../src/template.ts"],"names":[],"mappings":"AAEA,MAAM,KAAW,aAAa,CAuB7B;AAvBD,WAAiB,aAAa;IACf,qBAAO,GAAG,CACrB,KAAoB,EACpB,EAAwB,EAClB,EAAE,CACR,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CACrB,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CACjE,CAAC;IAES,kBAAI,GAAG,CAClB,KAAoB,EACpB,YAAoB,KAAK,CAAC,MAAM,GAAG,CAAC,EAClB,EAAE;QACpB,IAAI,CAAC,KAAK,CAAC,MAAM;YAAE,OAAO;QAE1B,KAAK,IAAI,CAAC,GAAG,SAAS,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YACpC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YACtB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;gBAAE,OAAO,IAAI,CAAC;YAEtC,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC1C,IAAI,QAAQ;gBAAE,OAAO,QAAQ,CAAC;QAChC,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,EAvBgB,aAAa,KAAb,aAAa,QAuB7B;AAYD,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,KAAqC,EAC3B,EAAE,CAAC,CAAC;IACd,KAAK;QACH,MAAM,KAAK,GAAG,KAAK,EAAE,CAAC;QACtB,OAAQ,KAAkB,CAAC,KAAK,EAAE,EAAE,IAAI,KAAK,CAAC;IAChD,CAAC;CACF,CAAC,CAAC"}
|
package/package.json
CHANGED
package/src/array_mutation.ts
CHANGED
|
@@ -41,10 +41,13 @@ export const useArrayMutation = <T extends unknown>(
|
|
|
41
41
|
array: SignalLike<readonly T[]>,
|
|
42
42
|
keyFn: (entry: T, index: number) => unknown,
|
|
43
43
|
): Signal<ArrayMutationResult> => {
|
|
44
|
-
const [result, setResult] = useSignal<ArrayMutationResult>(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
const [result, setResult] = useSignal<ArrayMutationResult>(
|
|
45
|
+
{
|
|
46
|
+
_mutations: [],
|
|
47
|
+
_map: new Map(),
|
|
48
|
+
},
|
|
49
|
+
{ force: true },
|
|
50
|
+
);
|
|
48
51
|
|
|
49
52
|
let indexMap = new Map<unknown, number>();
|
|
50
53
|
|
package/src/component.ts
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
} from "./utils.js";
|
|
17
17
|
import { useScope } from "./scope.js";
|
|
18
18
|
import { Context, isContext, provideContext } from "./context.js";
|
|
19
|
-
import { Template } from "./template.js";
|
|
19
|
+
import { Template, TemplateNodes } from "./template.js";
|
|
20
20
|
|
|
21
21
|
interface Tagged<in out T> {
|
|
22
22
|
_tag: T;
|
|
@@ -543,7 +543,9 @@ export const Component: ((tagName: string) => ComponentConstructor<{}>) &
|
|
|
543
543
|
mountEffects = [];
|
|
544
544
|
|
|
545
545
|
try {
|
|
546
|
-
|
|
546
|
+
TemplateNodes.forEach(this.render().build(), (node) => {
|
|
547
|
+
renderParent.append(node);
|
|
548
|
+
});
|
|
547
549
|
|
|
548
550
|
// Run mount effects
|
|
549
551
|
|
package/src/intrinsic/For.ts
CHANGED
|
@@ -4,14 +4,15 @@ import {
|
|
|
4
4
|
Signal,
|
|
5
5
|
SignalLike,
|
|
6
6
|
useEffect,
|
|
7
|
+
useMemo,
|
|
7
8
|
useSignal,
|
|
8
9
|
useSubscope,
|
|
9
10
|
} from "../scope.js";
|
|
10
11
|
import { useRenderer } from "../renderer.js";
|
|
11
|
-
import { createTemplate, Template } from "../template.js";
|
|
12
|
+
import { createTemplate, Template, TemplateNodes } from "../template.js";
|
|
12
13
|
|
|
13
14
|
interface KeyMeta {
|
|
14
|
-
_subnodes:
|
|
15
|
+
_subnodes: TemplateNodes;
|
|
15
16
|
_destroy: () => void;
|
|
16
17
|
}
|
|
17
18
|
|
|
@@ -32,38 +33,27 @@ export const For = <T>(props: {
|
|
|
32
33
|
const items = MaybeSignal.upgrade(props.each ?? []);
|
|
33
34
|
const anchor = renderer._node(() => document.createComment(""));
|
|
34
35
|
const keyFn = props.key ?? ((_, i) => i);
|
|
35
|
-
const nodes:
|
|
36
|
+
const nodes: [Comment, TemplateNodes[]] = [anchor, []];
|
|
36
37
|
const keyMap = new Map<unknown, KeyMeta>();
|
|
37
38
|
const mutationResult = useArrayMutation(items, keyFn);
|
|
38
39
|
|
|
39
|
-
const lookForAnchor = (index: number): Node =>
|
|
40
|
-
|
|
41
|
-
const key = keyFn(items()[index - 1], index - 1);
|
|
42
|
-
const nodes = keyMap.get(key)?._subnodes ?? [];
|
|
43
|
-
|
|
44
|
-
if (nodes.length > 0) {
|
|
45
|
-
return nodes[nodes.length - 1];
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return anchor;
|
|
50
|
-
};
|
|
40
|
+
const lookForAnchor = (index: number): Node =>
|
|
41
|
+
TemplateNodes.last(nodes[1], index - 1) ?? anchor;
|
|
51
42
|
|
|
52
43
|
useEffect(() => {
|
|
53
44
|
for (const mutation of mutationResult()._mutations) {
|
|
54
45
|
if (mutation._type == "r") {
|
|
55
|
-
const { _subnodes
|
|
46
|
+
const { _subnodes, _destroy } = keyMap.get(mutation._key) ?? {};
|
|
56
47
|
_destroy?.();
|
|
57
48
|
|
|
58
|
-
|
|
59
|
-
if (index > 0) {
|
|
60
|
-
nodes.splice(index, _subnodes.length);
|
|
61
|
-
}
|
|
49
|
+
nodes[1].splice(mutation._index, 1);
|
|
62
50
|
|
|
63
|
-
|
|
51
|
+
TemplateNodes.forEach(_subnodes ?? [], (node) =>
|
|
52
|
+
node.parentNode?.removeChild(node),
|
|
53
|
+
);
|
|
64
54
|
keyMap.delete(mutation._key);
|
|
65
55
|
} else if (mutation._type == "a") {
|
|
66
|
-
let _subnodes
|
|
56
|
+
let _subnodes!: TemplateNodes;
|
|
67
57
|
|
|
68
58
|
const [, destroy] = useSubscope(() => {
|
|
69
59
|
const [index, setIndex] = useSignal(mutation._index);
|
|
@@ -84,36 +74,29 @@ export const For = <T>(props: {
|
|
|
84
74
|
});
|
|
85
75
|
|
|
86
76
|
_subnodes = props.children?.(item, index, items).build() ?? [];
|
|
77
|
+
nodes[1].splice(mutation._index, 0, _subnodes);
|
|
87
78
|
|
|
88
|
-
|
|
89
|
-
const anchorIndex = nodes.indexOf(itemAnchor);
|
|
90
|
-
if (anchorIndex >= 0) {
|
|
91
|
-
nodes.splice(anchorIndex + 1, 0, ..._subnodes);
|
|
92
|
-
}
|
|
79
|
+
let itemAnchor = lookForAnchor(mutation._index);
|
|
93
80
|
|
|
94
|
-
|
|
95
|
-
itemAnchor.parentNode?.insertBefore(node, itemAnchor.nextSibling)
|
|
96
|
-
|
|
81
|
+
TemplateNodes.forEach(_subnodes, (node) => {
|
|
82
|
+
itemAnchor.parentNode?.insertBefore(node, itemAnchor.nextSibling);
|
|
83
|
+
itemAnchor = node;
|
|
84
|
+
});
|
|
97
85
|
});
|
|
98
86
|
|
|
99
87
|
keyMap.set(mutation._key, { _subnodes, _destroy: destroy });
|
|
100
88
|
} else if (mutation._type == "m") {
|
|
101
|
-
const { _subnodes
|
|
89
|
+
const { _subnodes } = keyMap.get(mutation._key) ?? {};
|
|
102
90
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
nodes.splice(index, _subnodes.length);
|
|
106
|
-
}
|
|
91
|
+
nodes[1].splice(mutation._from, 1);
|
|
92
|
+
nodes[1].splice(mutation._to, 0, _subnodes ?? []);
|
|
107
93
|
|
|
108
|
-
|
|
109
|
-
const anchorIndex = nodes.indexOf(itemAnchor);
|
|
110
|
-
if (anchorIndex >= 0) {
|
|
111
|
-
nodes.splice(anchorIndex + 1, 0, ..._subnodes);
|
|
112
|
-
}
|
|
94
|
+
let itemAnchor = lookForAnchor(mutation._to);
|
|
113
95
|
|
|
114
|
-
|
|
115
|
-
itemAnchor.parentNode?.insertBefore(node, itemAnchor.nextSibling)
|
|
116
|
-
|
|
96
|
+
TemplateNodes.forEach(_subnodes ?? [], (node) => {
|
|
97
|
+
itemAnchor.parentNode?.insertBefore(node, itemAnchor.nextSibling);
|
|
98
|
+
itemAnchor = node;
|
|
99
|
+
});
|
|
117
100
|
}
|
|
118
101
|
}
|
|
119
102
|
}, [mutationResult]);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Text } from "./Text.js";
|
|
2
2
|
import { FunctionalComponent } from "../component.js";
|
|
3
3
|
import { createTemplate, Template } from "../template.js";
|
|
4
|
-
import type
|
|
4
|
+
import { useMemo, type MaybeSignal } from "../scope.js";
|
|
5
5
|
|
|
6
6
|
export type Children =
|
|
7
7
|
| Template
|
|
@@ -31,8 +31,10 @@ export const Fragment: FunctionalComponent<{
|
|
|
31
31
|
return !Array.isArray(children)
|
|
32
32
|
? children == null
|
|
33
33
|
? []
|
|
34
|
-
:
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
: [
|
|
35
|
+
typeof children == "object"
|
|
36
|
+
? children.build()
|
|
37
|
+
: Text({ text: children }).build(),
|
|
38
|
+
]
|
|
37
39
|
: children.flatMap((children) => Fragment({ children }).build());
|
|
38
40
|
});
|
package/src/intrinsic/If.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FunctionalComponent } from "../component.js";
|
|
2
|
-
import {
|
|
2
|
+
import { TemplateNodes, createTemplate } from "../template.js";
|
|
3
3
|
import { MaybeSignal, useEffect, useMemo, useSubscope } from "../scope.js";
|
|
4
4
|
import { runWithRenderer, useRenderer } from "../renderer.js";
|
|
5
5
|
import { Children, Fragment } from "./Fragment.js";
|
|
@@ -26,33 +26,39 @@ export const ElseIf: FunctionalComponent<{
|
|
|
26
26
|
children?: Children;
|
|
27
27
|
}> = (props) => {
|
|
28
28
|
const renderer = useRenderer();
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
MaybeSignal.get<boolean | undefined>(props.condition),
|
|
29
|
+
const prevConditions = renderer._ifConditions;
|
|
30
|
+
const myCondition = MaybeSignal.upgrade<boolean | undefined>(props.condition);
|
|
31
|
+
const fullCondition = useMemo(
|
|
32
|
+
() => prevConditions.every((condition) => !condition()) && myCondition(),
|
|
34
33
|
);
|
|
35
34
|
|
|
36
|
-
renderer._ifConditions = [...
|
|
35
|
+
renderer._ifConditions = [...prevConditions, myCondition];
|
|
37
36
|
|
|
38
|
-
return
|
|
39
|
-
|
|
37
|
+
return createTemplate(() =>
|
|
38
|
+
runWithRenderer({ _ifConditions: [] }, () => {
|
|
40
39
|
const anchor = renderer._node(() => document.createComment(""));
|
|
41
|
-
const nodes:
|
|
40
|
+
const nodes: [Comment, TemplateNodes] = [anchor, []];
|
|
42
41
|
const template = useMemo(() =>
|
|
43
|
-
|
|
42
|
+
fullCondition() ? Fragment({ children: props.children }) : null,
|
|
44
43
|
);
|
|
45
44
|
|
|
46
|
-
let subnodes:
|
|
45
|
+
let subnodes: TemplateNodes = [];
|
|
47
46
|
|
|
48
47
|
useEffect(() => {
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
TemplateNodes.forEach(subnodes, (node) =>
|
|
49
|
+
node.parentNode?.removeChild(node),
|
|
50
|
+
);
|
|
51
|
+
nodes[1] = [];
|
|
51
52
|
|
|
52
53
|
const [, destroy] = useSubscope(() => {
|
|
53
54
|
subnodes = template()?.build() ?? [];
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
nodes[1] = subnodes;
|
|
56
|
+
|
|
57
|
+
let before: Node = anchor;
|
|
58
|
+
TemplateNodes.forEach(subnodes, (node) => {
|
|
59
|
+
before.parentNode?.insertBefore(node, before.nextSibling);
|
|
60
|
+
before = node;
|
|
61
|
+
});
|
|
56
62
|
});
|
|
57
63
|
|
|
58
64
|
return destroy;
|
package/src/intrinsic/Portal.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FunctionalComponent } from "../component.js";
|
|
2
2
|
import { runWithRenderer } from "../renderer.js";
|
|
3
3
|
import { useEffect } from "../scope.js";
|
|
4
|
-
import { createTemplate } from "../template.js";
|
|
4
|
+
import { TemplateNodes, createTemplate } from "../template.js";
|
|
5
5
|
import { Children, Fragment } from "./Fragment.js";
|
|
6
6
|
|
|
7
7
|
export const Portal: FunctionalComponent<{
|
|
@@ -13,12 +13,14 @@ export const Portal: FunctionalComponent<{
|
|
|
13
13
|
const nodes = Fragment({ children }).build();
|
|
14
14
|
|
|
15
15
|
useEffect(() => {
|
|
16
|
-
|
|
16
|
+
TemplateNodes.forEach(nodes, (node) => mount.appendChild(node));
|
|
17
17
|
|
|
18
18
|
return () => {
|
|
19
|
-
|
|
19
|
+
TemplateNodes.forEach(nodes, (node) =>
|
|
20
|
+
node.parentNode?.removeChild(node),
|
|
21
|
+
);
|
|
20
22
|
};
|
|
21
|
-
});
|
|
23
|
+
}, []);
|
|
22
24
|
|
|
23
25
|
return [];
|
|
24
26
|
}),
|
|
@@ -3,7 +3,7 @@ import { jsxPropNameToEventName } from "../utils.js";
|
|
|
3
3
|
import { MaybeSignal, useBatch, useEffect, useScope } from "../scope.js";
|
|
4
4
|
import { Fragment } from "./Fragment.js";
|
|
5
5
|
import { runWithRenderer, useRenderer } from "../renderer.js";
|
|
6
|
-
import { createTemplate, Template } from "../template.js";
|
|
6
|
+
import { createTemplate, Template, TemplateNodes } from "../template.js";
|
|
7
7
|
|
|
8
8
|
export const hydrateElement = <E extends HTMLElement | SVGElement>(
|
|
9
9
|
node: E,
|
|
@@ -66,14 +66,15 @@ export const hydrateElement = <E extends HTMLElement | SVGElement>(
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
if (props.children != null) {
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
TemplateNodes.forEach(
|
|
70
|
+
runWithRenderer(
|
|
71
71
|
{
|
|
72
72
|
_svg: svg,
|
|
73
73
|
_nodes: node.childNodes.values(),
|
|
74
74
|
},
|
|
75
75
|
() => Fragment({ children: props.children }).build(),
|
|
76
76
|
),
|
|
77
|
+
(subnode) => node.append(subnode),
|
|
77
78
|
);
|
|
78
79
|
}
|
|
79
80
|
|
package/src/mod.ts
CHANGED
|
@@ -15,8 +15,8 @@ export {
|
|
|
15
15
|
} from "./component.js";
|
|
16
16
|
export { type Context, createContext, useContext } from "./context.js";
|
|
17
17
|
export { createElement, h } from "./create_element.js";
|
|
18
|
-
export { DangerousHtml, Styles } from "./dom.js";
|
|
19
|
-
export { type Template } from "./template.js";
|
|
18
|
+
export { type DangerousHtml, type Styles } from "./dom.js";
|
|
19
|
+
export { type Template, TemplateNodes } from "./template.js";
|
|
20
20
|
export {
|
|
21
21
|
type Cleanup,
|
|
22
22
|
MaybeSignal,
|
package/src/renderer.ts
CHANGED
|
@@ -5,7 +5,7 @@ interface Renderer {
|
|
|
5
5
|
_component?: Component;
|
|
6
6
|
_svg?: boolean;
|
|
7
7
|
_nodes?: IterableIterator<Node>;
|
|
8
|
-
_ifConditions: SignalLike<boolean | undefined>[]
|
|
8
|
+
_ifConditions: Readonly<SignalLike<boolean | undefined>[]>;
|
|
9
9
|
|
|
10
10
|
_node<N extends Node>(fallback: () => N): N;
|
|
11
11
|
}
|