sinho 0.2.2 → 0.3.0
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 +16 -5
- package/dist/bundle.js +99 -80
- 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 +11 -7
- 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/scope.d.ts +9 -3
- package/dist/scope.js +32 -22
- package/dist/scope.js.map +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 -8
- package/src/intrinsic/Portal.ts +6 -4
- package/src/intrinsic/TagComponent.ts +4 -3
- package/src/mod.ts +2 -2
- package/src/scope.ts +52 -28
- 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
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useScope, useSignal } from "../scope.js";
|
|
2
|
+
import { createTemplate } from "../template.js";
|
|
3
|
+
import { Fragment } from "./Fragment.js";
|
|
4
|
+
import { createContext, provideContext, useContext } from "../context.js";
|
|
5
|
+
import { If } from "./If.js";
|
|
6
|
+
const ErrorContext = createContext([
|
|
7
|
+
(err) => {
|
|
8
|
+
throw err;
|
|
9
|
+
},
|
|
10
|
+
() => { },
|
|
11
|
+
]);
|
|
12
|
+
/**
|
|
13
|
+
* `ErrorBoundary` is a component that can be used to catch errors in the
|
|
14
|
+
* component tree.
|
|
15
|
+
*/
|
|
16
|
+
export const ErrorBoundary = ({ fallback, children }) => {
|
|
17
|
+
let error;
|
|
18
|
+
const [showError, setShowError] = useSignal(false);
|
|
19
|
+
const show = (err) => {
|
|
20
|
+
error = err;
|
|
21
|
+
setShowError(true);
|
|
22
|
+
};
|
|
23
|
+
const reset = () => setShowError(false);
|
|
24
|
+
return If({
|
|
25
|
+
condition: showError,
|
|
26
|
+
then: createTemplate(() => fallback?.({ error, reset }) ?? []),
|
|
27
|
+
else: createTemplate(() => {
|
|
28
|
+
provideContext(ErrorContext, () => [show, reset]);
|
|
29
|
+
const s = useScope();
|
|
30
|
+
s._onError = show;
|
|
31
|
+
return Fragment({ children });
|
|
32
|
+
}),
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
export const useErrorBoundary = () => useContext(ErrorContext)();
|
|
36
|
+
//# sourceMappingURL=ErrorBoundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorBoundary.js","sourceRoot":"","sources":["../../src/intrinsic/ErrorBoundary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa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AAC;QAChC,CAAC,CAAC;KACH,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAG9B,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC"}
|
package/dist/intrinsic/For.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useArrayMutation } from "../array_mutation.js";
|
|
2
2
|
import { MaybeSignal, useEffect, useSignal, useSubscope, } from "../scope.js";
|
|
3
3
|
import { useRenderer } from "../renderer.js";
|
|
4
|
-
import { createTemplate } from "../template.js";
|
|
4
|
+
import { createTemplate, TemplateNodes } from "../template.js";
|
|
5
5
|
/**
|
|
6
6
|
* `For` is a component that can be used to render a list of items.
|
|
7
7
|
*/
|
|
@@ -10,33 +10,21 @@ export const For = (props) => createTemplate(() => {
|
|
|
10
10
|
const items = MaybeSignal.upgrade(props.each ?? []);
|
|
11
11
|
const anchor = renderer._node(() => document.createComment(""));
|
|
12
12
|
const keyFn = props.key ?? ((_, i) => i);
|
|
13
|
-
const nodes = [anchor];
|
|
13
|
+
const nodes = [anchor, []];
|
|
14
14
|
const keyMap = new Map();
|
|
15
15
|
const mutationResult = useArrayMutation(items, keyFn);
|
|
16
|
-
const lookForAnchor = (index) =>
|
|
17
|
-
for (let i = index - 1; i >= 0; i--) {
|
|
18
|
-
const key = keyFn(items()[index - 1], index - 1);
|
|
19
|
-
const nodes = keyMap.get(key)?._subnodes ?? [];
|
|
20
|
-
if (nodes.length > 0) {
|
|
21
|
-
return nodes[nodes.length - 1];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return anchor;
|
|
25
|
-
};
|
|
16
|
+
const lookForAnchor = (index) => TemplateNodes.last(nodes[1], index - 1) ?? anchor;
|
|
26
17
|
useEffect(() => {
|
|
27
18
|
for (const mutation of mutationResult()._mutations) {
|
|
28
19
|
if (mutation._type == "r") {
|
|
29
|
-
const { _subnodes
|
|
20
|
+
const { _subnodes, _destroy } = keyMap.get(mutation._key) ?? {};
|
|
30
21
|
_destroy?.();
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
nodes.splice(index, _subnodes.length);
|
|
34
|
-
}
|
|
35
|
-
_subnodes.forEach((node) => node.parentNode?.removeChild(node));
|
|
22
|
+
nodes[1].splice(mutation._index, 1);
|
|
23
|
+
TemplateNodes.forEach(_subnodes ?? [], (node) => node.parentNode?.removeChild(node));
|
|
36
24
|
keyMap.delete(mutation._key);
|
|
37
25
|
}
|
|
38
26
|
else if (mutation._type == "a") {
|
|
39
|
-
let _subnodes
|
|
27
|
+
let _subnodes;
|
|
40
28
|
const [, destroy] = useSubscope(() => {
|
|
41
29
|
const [index, setIndex] = useSignal(mutation._index);
|
|
42
30
|
const [item, setItem] = useSignal(items()[mutation._index]);
|
|
@@ -52,27 +40,24 @@ export const For = (props) => createTemplate(() => {
|
|
|
52
40
|
}
|
|
53
41
|
});
|
|
54
42
|
_subnodes = props.children?.(item, index, items).build() ?? [];
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
43
|
+
nodes[1].splice(mutation._index, 0, _subnodes);
|
|
44
|
+
let itemAnchor = lookForAnchor(mutation._index);
|
|
45
|
+
TemplateNodes.forEach(_subnodes, (node) => {
|
|
46
|
+
itemAnchor.parentNode?.insertBefore(node, itemAnchor.nextSibling);
|
|
47
|
+
itemAnchor = node;
|
|
48
|
+
});
|
|
61
49
|
});
|
|
62
50
|
keyMap.set(mutation._key, { _subnodes, _destroy: destroy });
|
|
63
51
|
}
|
|
64
52
|
else if (mutation._type == "m") {
|
|
65
|
-
const { _subnodes
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
nodes.splice(anchorIndex + 1, 0, ..._subnodes);
|
|
74
|
-
}
|
|
75
|
-
_subnodes.forEach((node) => itemAnchor.parentNode?.insertBefore(node, itemAnchor.nextSibling));
|
|
53
|
+
const { _subnodes } = keyMap.get(mutation._key) ?? {};
|
|
54
|
+
nodes[1].splice(mutation._from, 1);
|
|
55
|
+
nodes[1].splice(mutation._to, 0, _subnodes ?? []);
|
|
56
|
+
let itemAnchor = lookForAnchor(mutation._to);
|
|
57
|
+
TemplateNodes.forEach(_subnodes ?? [], (node) => {
|
|
58
|
+
itemAnchor.parentNode?.insertBefore(node, itemAnchor.nextSibling);
|
|
59
|
+
itemAnchor = node;
|
|
60
|
+
});
|
|
76
61
|
}
|
|
77
62
|
}
|
|
78
63
|
}, [mutationResult]);
|
|
@@ -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;IA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BAEH,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;YAC9D,CAAC;iBAAM,IAAI,QAAQ,CAAC,KAAK,IAAI,GAAG,EAAE,CAAC;gBACjC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;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,5 +1,5 @@
|
|
|
1
|
-
import { createTemplate } from "../template.js";
|
|
2
|
-
import { MaybeSignal, useEffect, useMemo, useSubscope } from "../scope.js";
|
|
1
|
+
import { TemplateNodes, createTemplate } from "../template.js";
|
|
2
|
+
import { MaybeSignal, useEffect, useMemo, useSubscope, } from "../scope.js";
|
|
3
3
|
import { runWithRenderer, useRenderer } from "../renderer.js";
|
|
4
4
|
import { Fragment } from "./Fragment.js";
|
|
5
5
|
/**
|
|
@@ -22,16 +22,20 @@ export const ElseIf = (props) => {
|
|
|
22
22
|
renderer._ifConditions = [...conditions, condition];
|
|
23
23
|
return runWithRenderer({ _ifConditions: [] }, () => createTemplate(() => {
|
|
24
24
|
const anchor = renderer._node(() => document.createComment(""));
|
|
25
|
-
const nodes = [anchor];
|
|
25
|
+
const nodes = [anchor, []];
|
|
26
26
|
const template = useMemo(() => condition() ? 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,EAAiB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"If.js","sourceRoot":"","sources":["../../src/intrinsic/If.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAiB,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EACL,WAAW,EAEX,SAAS,EACT,OAAO,EAEP,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,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,UAAU,GAAG,QAAQ,CAAC,aAAa,CAAC;IAC1C,MAAM,SAAS,GAAG,OAAO,CACvB,GAAG,EAAE,CACH,UAAU,CAAC,KAAK,CAAC,CAAC,SAAS,EA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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,aAAa,CA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rD,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/scope.d.ts
CHANGED
|
@@ -18,6 +18,12 @@ export interface Signal<out T> extends SignalLike<T> {
|
|
|
18
18
|
*/
|
|
19
19
|
peek(): T;
|
|
20
20
|
}
|
|
21
|
+
export interface SignalOptions<T> extends SetSignalOptions {
|
|
22
|
+
/**
|
|
23
|
+
* A custom equality function to compare the new value with the old value.
|
|
24
|
+
*/
|
|
25
|
+
equals?: (a: T, b: T) => boolean;
|
|
26
|
+
}
|
|
21
27
|
export interface SetSignalOptions {
|
|
22
28
|
/**
|
|
23
29
|
* Whether to force the update of the signal even if the new value has the
|
|
@@ -64,7 +70,7 @@ export declare const useScope: <T = {}>() => Scope<T>;
|
|
|
64
70
|
* Creates a new signal with the given value.
|
|
65
71
|
* @returns A tuple with the signal and its setter.
|
|
66
72
|
*/
|
|
67
|
-
export declare const useSignal: (<T>(value: T, opts?:
|
|
73
|
+
export declare const useSignal: (<T>(value: T, opts?: SignalOptions<T>) => readonly [Signal<T>, SignalSetter<T>]) & (<T>(value?: T, opts?: SignalOptions<T | undefined>) => readonly [Signal<T | undefined>, SignalSetter<T | undefined>]);
|
|
68
74
|
/**
|
|
69
75
|
* Runs the given function in a batch.
|
|
70
76
|
*
|
|
@@ -84,7 +90,7 @@ export declare const useEffect: (fn: () => Cleanup, deps?: SignalLike<unknown>[]
|
|
|
84
90
|
*
|
|
85
91
|
* @param fn The computation function.
|
|
86
92
|
*/
|
|
87
|
-
export declare const useMemo: <T>(fn: () => T, opts?:
|
|
93
|
+
export declare const useMemo: <T>(fn: () => T, opts?: SignalOptions<T>) => Signal<T>;
|
|
88
94
|
/**
|
|
89
95
|
* Executes a function inside a subscope which can be manually destroyed.
|
|
90
96
|
*
|
|
@@ -113,7 +119,7 @@ export interface RefSignalSetter<in T> {
|
|
|
113
119
|
/**
|
|
114
120
|
* Creates a new signal with write capabilities.
|
|
115
121
|
*/
|
|
116
|
-
export declare const useRef: (<T>(value: T, opts?:
|
|
122
|
+
export declare const useRef: (<T>(value: T, opts?: SignalOptions<T>) => RefSignal<T>) & (<T>(value?: T, opts?: SignalOptions<T | undefined>) => RefSignal<T | undefined>);
|
|
117
123
|
/**
|
|
118
124
|
* Represents a value that can be a signal or a constant value.
|
|
119
125
|
*
|
package/dist/scope.js
CHANGED
|
@@ -52,25 +52,33 @@ export const useSignal = (value, opts) => {
|
|
|
52
52
|
signal._effects = new Set();
|
|
53
53
|
signal.peek = () => value;
|
|
54
54
|
const setter = (arg, innerOpts) => {
|
|
55
|
-
|
|
55
|
+
const allOpts = { ...opts, ...innerOpts };
|
|
56
|
+
allOpts.equals ??= (a, b) => a === b;
|
|
56
57
|
if (currBatch) {
|
|
57
58
|
const newValue = typeof arg == "function"
|
|
58
59
|
? arg(signal.peek())
|
|
59
60
|
: arg;
|
|
60
|
-
if (
|
|
61
|
-
if (
|
|
61
|
+
if (allOpts?.force || !allOpts.equals(newValue, signal.peek())) {
|
|
62
|
+
if (allOpts?.force) {
|
|
62
63
|
value = newValue;
|
|
63
64
|
}
|
|
64
65
|
else {
|
|
65
66
|
currBatch._setters.push(() => (value = newValue));
|
|
66
67
|
}
|
|
67
|
-
if (!
|
|
68
|
-
signal._effects.forEach((effect) =>
|
|
68
|
+
if (!allOpts?.silent) {
|
|
69
|
+
signal._effects.forEach((effect) => {
|
|
70
|
+
if (effect._pure) {
|
|
71
|
+
currBatch._pureEffects.add(effect);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
currBatch._effects.add(effect);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
69
77
|
}
|
|
70
78
|
}
|
|
71
79
|
}
|
|
72
80
|
else {
|
|
73
|
-
useBatch(() => setter(arg,
|
|
81
|
+
useBatch(() => setter(arg, allOpts));
|
|
74
82
|
}
|
|
75
83
|
};
|
|
76
84
|
return [signal, setter];
|
|
@@ -84,7 +92,11 @@ export const useSignal = (value, opts) => {
|
|
|
84
92
|
export const useBatch = (fn) => {
|
|
85
93
|
if (currBatch)
|
|
86
94
|
return fn();
|
|
87
|
-
currBatch = {
|
|
95
|
+
currBatch = {
|
|
96
|
+
_setters: [],
|
|
97
|
+
_effects: new Set(),
|
|
98
|
+
_pureEffects: new Set(),
|
|
99
|
+
};
|
|
88
100
|
try {
|
|
89
101
|
const result = fn();
|
|
90
102
|
flushBatch();
|
|
@@ -95,25 +107,23 @@ export const useBatch = (fn) => {
|
|
|
95
107
|
}
|
|
96
108
|
};
|
|
97
109
|
export const flushBatch = () => {
|
|
98
|
-
|
|
99
|
-
|
|
110
|
+
while (currBatch &&
|
|
111
|
+
currBatch._setters.length +
|
|
112
|
+
currBatch._effects.size +
|
|
113
|
+
currBatch._pureEffects.size >
|
|
114
|
+
0) {
|
|
100
115
|
// Clean effect subscope
|
|
101
116
|
currBatch._effects.forEach((effect) => effect._clean?.());
|
|
102
117
|
// Run signal updates
|
|
103
118
|
currBatch._setters.forEach((setter) => setter());
|
|
104
119
|
currBatch._setters = [];
|
|
105
120
|
// Run next effect
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
currBatch._effects.delete(effect);
|
|
110
|
-
continue a;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
for (const effect of currBatch._effects) {
|
|
121
|
+
const effect = currBatch._pureEffects.values().next().value ??
|
|
122
|
+
currBatch._effects.values().next().value;
|
|
123
|
+
if (effect) {
|
|
114
124
|
effect._run();
|
|
125
|
+
currBatch._pureEffects.delete(effect);
|
|
115
126
|
currBatch._effects.delete(effect);
|
|
116
|
-
break;
|
|
117
127
|
}
|
|
118
128
|
}
|
|
119
129
|
};
|
|
@@ -174,12 +184,12 @@ export const useEffect = (fn, deps) => {
|
|
|
174
184
|
* @param fn The computation function.
|
|
175
185
|
*/
|
|
176
186
|
export const useMemo = (fn, opts) => {
|
|
177
|
-
const [memo, setMemo] = useSignal();
|
|
187
|
+
const [memo, setMemo] = useSignal(undefined, opts);
|
|
178
188
|
let firstTime = true;
|
|
179
189
|
pureEffectFlag = true;
|
|
180
190
|
try {
|
|
181
191
|
useEffect(() => {
|
|
182
|
-
setMemo(fn, firstTime ? {
|
|
192
|
+
setMemo(fn, firstTime ? { force: true } : {});
|
|
183
193
|
firstTime = false;
|
|
184
194
|
});
|
|
185
195
|
}
|
|
@@ -221,11 +231,11 @@ export const useSubscope = (fn, opts) => {
|
|
|
221
231
|
/**
|
|
222
232
|
* Creates a new signal with write capabilities.
|
|
223
233
|
*/
|
|
224
|
-
export const useRef = (value, opts) => {
|
|
234
|
+
export const useRef = ((value, opts) => {
|
|
225
235
|
const [signal, setter] = useSignal(value, opts);
|
|
226
236
|
signal.set = setter;
|
|
227
237
|
return signal;
|
|
228
|
-
};
|
|
238
|
+
});
|
|
229
239
|
/**
|
|
230
240
|
* @namespace
|
|
231
241
|
*/
|
package/dist/scope.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AA8EA,MAAM,WAAW,GAAG,CAAC,MAAc,EAAS,EAAE;IAC5C,OAAO;QACL,OAAO,EAAE,MAAM;QACf,QAAQ,EAAE,EAAE;QACZ,UAAU,EAAE,EAAE;QACd,QAAQ,EAAE,EAAE,GAAG,MAAM,EAAE,QAAQ,EAAE;QAEjC,IAAI,CAAI,EAAW;YACjB,MAAM,SAAS,GAAG,SAAS,CAAC;YAC5B,SAAS,GAAG,IAAI,CAAC;YAEjB,IAAI,CAAC;gBACH,OAAO,EAAE,EAAE,CAAC;YACd,CAAC;oBAAS,CAAC;gBACT,SAAS,GAAG,SAAS,CAAC;YACxB,CAAC;QACH,CAAC;QAED,QAAQ;Y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M,GAIgB,CAAC,CAClC,KAAS,EACT,IAAmC,EACM,EAAE;IAC3C,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC/C,MAAmC,CAAC,GAAG,GAAG,MAAM,CAAC;IAClD,OAAO,MAAiD,CAAC;AAC3D,CAAC,CAAQ,CAAC;AASV;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB;;OAEG;IACH,OAAO,EACL,CAAI,MAAsB,EAAiB,EAAE,CAC7C,GAAG,EAAE,CACH,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC;IAE3B;;OAEG;IACH,GAAG,EAAE,CAAI,MAAsB,EAAK,EAAE,CACpC,OAAO,MAAM,IAAI,UAAU,CAAC,CAAC,CAAE,MAAwB,EAAE,CAAC,CAAC,CAAC,MAAM;IAEpE;;OAEG;IACH,IAAI,CAAI,MAAsB;QAC5B,MAAM,aAAa,GAAG,aAAa,CAAC;QACpC,aAAa,GAAG,IAAI,CAAC;QAErB,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC1B,CAAC;gBAAS,CAAC;YACT,aAAa,GAAG,aAAa,CAAC;QAChC,CAAC;IACH,CAAC;CACF,CAAC"}
|
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
|
|