@sigil-dev/runtime 0.9.29 → 0.9.30
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/index.ts +1671 -1672
- package/package.json +1 -1
- package/reactivity/map.ts +23 -12
- package/reactivity/set.ts +14 -11
- package/transition.ts +69 -69
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@sigil-dev/runtime",
|
|
3
3
|
"module": "index.ts",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.9.
|
|
5
|
+
"version": "0.9.30",
|
|
6
6
|
"description": "Signals and fine-grained DOM updates for compiled Sigil components",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"homepage": "https://sigil.cane1712.dev/docs/reference/runtime",
|
package/reactivity/map.ts
CHANGED
|
@@ -26,19 +26,30 @@ export class ReactiveMap<K, V> extends Map<K, V> {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
constructor(entries?: readonly (readonly [K, V])[] | null) {
|
|
29
|
-
super(entries)
|
|
29
|
+
// Not super(entries): Map's constructor adds them through this.set,
|
|
30
|
+
// which runs before the private fields exist and threw.
|
|
31
|
+
super();
|
|
30
32
|
this.#structVersion = createSignal(0);
|
|
31
33
|
if (entries) {
|
|
32
|
-
for (const [k] of entries)
|
|
34
|
+
for (const [k, v] of entries) {
|
|
35
|
+
super.set(k, v);
|
|
36
|
+
this.#getKeyVersion(k);
|
|
37
|
+
}
|
|
33
38
|
}
|
|
34
39
|
}
|
|
35
40
|
|
|
36
|
-
|
|
41
|
+
/** Tracked per key, like get: an effect re-runs when the key is added or removed. */
|
|
42
|
+
override has(key: K): boolean {
|
|
43
|
+
this.#getKeyVersion(key)();
|
|
44
|
+
return super.has(key);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
override get(key: K): V | undefined {
|
|
37
48
|
this.#getKeyVersion(key)();
|
|
38
49
|
return super.get(key);
|
|
39
50
|
}
|
|
40
51
|
|
|
41
|
-
set(key: K, value: V): this {
|
|
52
|
+
override set(key: K, value: V): this {
|
|
42
53
|
const existed = super.has(key);
|
|
43
54
|
super.set(key, value);
|
|
44
55
|
this.#bumpKey(key);
|
|
@@ -46,7 +57,7 @@ export class ReactiveMap<K, V> extends Map<K, V> {
|
|
|
46
57
|
return this;
|
|
47
58
|
}
|
|
48
59
|
|
|
49
|
-
delete(key: K): boolean {
|
|
60
|
+
override delete(key: K): boolean {
|
|
50
61
|
const result = super.delete(key);
|
|
51
62
|
if (result) {
|
|
52
63
|
this.#bumpKey(key);
|
|
@@ -55,7 +66,7 @@ export class ReactiveMap<K, V> extends Map<K, V> {
|
|
|
55
66
|
return result;
|
|
56
67
|
}
|
|
57
68
|
|
|
58
|
-
clear(): void {
|
|
69
|
+
override clear(): void {
|
|
59
70
|
if (this.size > 0) {
|
|
60
71
|
for (const key of this.keys()) this.#bumpKey(key);
|
|
61
72
|
super.clear();
|
|
@@ -63,7 +74,7 @@ export class ReactiveMap<K, V> extends Map<K, V> {
|
|
|
63
74
|
}
|
|
64
75
|
}
|
|
65
76
|
|
|
66
|
-
forEach(
|
|
77
|
+
override forEach(
|
|
67
78
|
callbackfn: (value: V, key: K, map: Map<K, V>) => void,
|
|
68
79
|
thisArg?: unknown,
|
|
69
80
|
): void {
|
|
@@ -71,27 +82,27 @@ export class ReactiveMap<K, V> extends Map<K, V> {
|
|
|
71
82
|
super.forEach(callbackfn, thisArg);
|
|
72
83
|
}
|
|
73
84
|
|
|
74
|
-
get size(): number {
|
|
85
|
+
override get size(): number {
|
|
75
86
|
this.#structVersion();
|
|
76
87
|
return super.size;
|
|
77
88
|
}
|
|
78
89
|
|
|
79
|
-
entries(): ReturnType<Map<K, V>["entries"]> {
|
|
90
|
+
override entries(): ReturnType<Map<K, V>["entries"]> {
|
|
80
91
|
this.#structVersion();
|
|
81
92
|
return super.entries();
|
|
82
93
|
}
|
|
83
94
|
|
|
84
|
-
keys(): ReturnType<Map<K, V>["keys"]> {
|
|
95
|
+
override keys(): ReturnType<Map<K, V>["keys"]> {
|
|
85
96
|
this.#structVersion();
|
|
86
97
|
return super.keys();
|
|
87
98
|
}
|
|
88
99
|
|
|
89
|
-
values(): ReturnType<Map<K, V>["values"]> {
|
|
100
|
+
override values(): ReturnType<Map<K, V>["values"]> {
|
|
90
101
|
this.#structVersion();
|
|
91
102
|
return super.values();
|
|
92
103
|
}
|
|
93
104
|
|
|
94
|
-
[Symbol.iterator](): ReturnType<Map<K, V>[typeof Symbol.iterator]> {
|
|
105
|
+
override [Symbol.iterator](): ReturnType<Map<K, V>[typeof Symbol.iterator]> {
|
|
95
106
|
this.#structVersion();
|
|
96
107
|
return super[Symbol.iterator]();
|
|
97
108
|
}
|
package/reactivity/set.ts
CHANGED
|
@@ -5,8 +5,11 @@ export class ReactiveSet<T> extends Set<T> {
|
|
|
5
5
|
#versionVal: number = 0;
|
|
6
6
|
|
|
7
7
|
constructor(values?: readonly T[] | null) {
|
|
8
|
-
super(values)
|
|
8
|
+
// Not super(values): Set's constructor adds them through this.add,
|
|
9
|
+
// which runs before the private fields exist and threw.
|
|
10
|
+
super();
|
|
9
11
|
this.#version = createSignal(0);
|
|
12
|
+
if (values) for (const v of values) super.add(v);
|
|
10
13
|
}
|
|
11
14
|
|
|
12
15
|
#bump() {
|
|
@@ -14,32 +17,32 @@ export class ReactiveSet<T> extends Set<T> {
|
|
|
14
17
|
this.#version.set(this.#versionVal);
|
|
15
18
|
}
|
|
16
19
|
|
|
17
|
-
has(value: T): boolean {
|
|
20
|
+
override has(value: T): boolean {
|
|
18
21
|
this.#version();
|
|
19
22
|
return super.has(value);
|
|
20
23
|
}
|
|
21
24
|
|
|
22
|
-
add(value: T): this {
|
|
25
|
+
override add(value: T): this {
|
|
23
26
|
const sizeBefore = super.size;
|
|
24
27
|
super.add(value);
|
|
25
28
|
if (super.size !== sizeBefore) this.#bump();
|
|
26
29
|
return this;
|
|
27
30
|
}
|
|
28
31
|
|
|
29
|
-
delete(value: T): boolean {
|
|
32
|
+
override delete(value: T): boolean {
|
|
30
33
|
const result = super.delete(value);
|
|
31
34
|
if (result) this.#bump();
|
|
32
35
|
return result;
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
clear(): void {
|
|
38
|
+
override clear(): void {
|
|
36
39
|
if (this.size > 0) {
|
|
37
40
|
super.clear();
|
|
38
41
|
this.#bump();
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
44
|
|
|
42
|
-
forEach(
|
|
45
|
+
override forEach(
|
|
43
46
|
callbackfn: (value: T, value2: T, set: Set<T>) => void,
|
|
44
47
|
thisArg?: unknown,
|
|
45
48
|
): void {
|
|
@@ -47,27 +50,27 @@ export class ReactiveSet<T> extends Set<T> {
|
|
|
47
50
|
super.forEach(callbackfn, thisArg);
|
|
48
51
|
}
|
|
49
52
|
|
|
50
|
-
get size(): number {
|
|
53
|
+
override get size(): number {
|
|
51
54
|
this.#version();
|
|
52
55
|
return super.size;
|
|
53
56
|
}
|
|
54
57
|
|
|
55
|
-
entries(): ReturnType<Set<T>["entries"]> {
|
|
58
|
+
override entries(): ReturnType<Set<T>["entries"]> {
|
|
56
59
|
this.#version();
|
|
57
60
|
return super.entries();
|
|
58
61
|
}
|
|
59
62
|
|
|
60
|
-
keys(): ReturnType<Set<T>["keys"]> {
|
|
63
|
+
override keys(): ReturnType<Set<T>["keys"]> {
|
|
61
64
|
this.#version();
|
|
62
65
|
return super.keys();
|
|
63
66
|
}
|
|
64
67
|
|
|
65
|
-
values(): ReturnType<Set<T>["values"]> {
|
|
68
|
+
override values(): ReturnType<Set<T>["values"]> {
|
|
66
69
|
this.#version();
|
|
67
70
|
return super.values();
|
|
68
71
|
}
|
|
69
72
|
|
|
70
|
-
[Symbol.iterator](): ReturnType<Set<T>[typeof Symbol.iterator]> {
|
|
73
|
+
override [Symbol.iterator](): ReturnType<Set<T>[typeof Symbol.iterator]> {
|
|
71
74
|
this.#version();
|
|
72
75
|
return super[Symbol.iterator]();
|
|
73
76
|
}
|
package/transition.ts
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* transition:/in:/out: directive support.
|
|
3
|
-
*
|
|
4
|
-
* The compiler lowers `<div transition:fade={fade}>` to
|
|
5
|
-
* `mountTransition(el, fade, "transition")` (bare expression or
|
|
6
|
-
* `[fn, params]` tuple), and swaps anchor-mount cleanup's `node.remove()`
|
|
7
|
-
* for `removeAnimated(node)` so out-directions can play before unmount.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
export type TransitionFn = (
|
|
11
|
-
el: Element,
|
|
12
|
-
params: unknown,
|
|
13
|
-
direction: "in" | "out",
|
|
14
|
-
) => Animation | undefined | void;
|
|
15
|
-
|
|
16
|
-
const outRegistry = new WeakMap<
|
|
17
|
-
Element,
|
|
18
|
-
{ fn: TransitionFn; params: unknown }
|
|
19
|
-
>();
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Play an in-animation immediately (when kind includes it) and register the
|
|
23
|
-
* element for an out-animation on removal (when kind includes that).
|
|
24
|
-
* Returns a cleanup that unregisters the element.
|
|
25
|
-
*/
|
|
26
|
-
export function mountTransition(
|
|
27
|
-
el: Element,
|
|
28
|
-
spec: TransitionFn | [TransitionFn, unknown],
|
|
29
|
-
kind: "in" | "out" | "transition",
|
|
30
|
-
): () => void {
|
|
31
|
-
const [fn, params] = Array.isArray(spec) ? spec : [spec, undefined];
|
|
32
|
-
if (kind === "in" || kind === "transition") {
|
|
33
|
-
fn(el, params, "in");
|
|
34
|
-
}
|
|
35
|
-
if (kind === "out" || kind === "transition") {
|
|
36
|
-
outRegistry.set(el, { fn, params });
|
|
37
|
-
}
|
|
38
|
-
return () => {
|
|
39
|
-
outRegistry.delete(el);
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Remove a node, playing its registered out-animation first when one exists.
|
|
45
|
-
* No registration → immediate removal (plain remove() semantics).
|
|
46
|
-
*/
|
|
47
|
-
export function removeAnimated(node: Node): void {
|
|
48
|
-
if (!(node instanceof Element)) {
|
|
49
|
-
(node as ChildNode).remove();
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const entry = outRegistry.get(node);
|
|
53
|
-
if (!entry) {
|
|
54
|
-
node.remove();
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
const animation = entry.fn(node, entry.params, "out");
|
|
58
|
-
if (animation?.finished && typeof animation.finished.finally === "function") {
|
|
59
|
-
animation.finished
|
|
60
|
-
.finally(() => {
|
|
61
|
-
node.remove();
|
|
62
|
-
})
|
|
63
|
-
.catch(() => {
|
|
64
|
-
node.remove();
|
|
65
|
-
});
|
|
66
|
-
} else {
|
|
67
|
-
node.remove();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* transition:/in:/out: directive support.
|
|
3
|
+
*
|
|
4
|
+
* The compiler lowers `<div transition:fade={fade}>` to
|
|
5
|
+
* `mountTransition(el, fade, "transition")` (bare expression or
|
|
6
|
+
* `[fn, params]` tuple), and swaps anchor-mount cleanup's `node.remove()`
|
|
7
|
+
* for `removeAnimated(node)` so out-directions can play before unmount.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export type TransitionFn = (
|
|
11
|
+
el: Element,
|
|
12
|
+
params: unknown,
|
|
13
|
+
direction: "in" | "out",
|
|
14
|
+
) => Animation | undefined | void;
|
|
15
|
+
|
|
16
|
+
const outRegistry = new WeakMap<
|
|
17
|
+
Element,
|
|
18
|
+
{ fn: TransitionFn; params: unknown }
|
|
19
|
+
>();
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Play an in-animation immediately (when kind includes it) and register the
|
|
23
|
+
* element for an out-animation on removal (when kind includes that).
|
|
24
|
+
* Returns a cleanup that unregisters the element.
|
|
25
|
+
*/
|
|
26
|
+
export function mountTransition(
|
|
27
|
+
el: Element,
|
|
28
|
+
spec: TransitionFn | [TransitionFn, unknown],
|
|
29
|
+
kind: "in" | "out" | "transition",
|
|
30
|
+
): () => void {
|
|
31
|
+
const [fn, params] = Array.isArray(spec) ? spec : [spec, undefined];
|
|
32
|
+
if (kind === "in" || kind === "transition") {
|
|
33
|
+
fn(el, params, "in");
|
|
34
|
+
}
|
|
35
|
+
if (kind === "out" || kind === "transition") {
|
|
36
|
+
outRegistry.set(el, { fn, params });
|
|
37
|
+
}
|
|
38
|
+
return () => {
|
|
39
|
+
outRegistry.delete(el);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Remove a node, playing its registered out-animation first when one exists.
|
|
45
|
+
* No registration → immediate removal (plain remove() semantics).
|
|
46
|
+
*/
|
|
47
|
+
export function removeAnimated(node: Node): void {
|
|
48
|
+
if (!(node instanceof Element)) {
|
|
49
|
+
(node as ChildNode).remove();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const entry = outRegistry.get(node);
|
|
53
|
+
if (!entry) {
|
|
54
|
+
node.remove();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const animation = entry.fn(node, entry.params, "out");
|
|
58
|
+
if (animation?.finished && typeof animation.finished.finally === "function") {
|
|
59
|
+
animation.finished
|
|
60
|
+
.finally(() => {
|
|
61
|
+
node.remove();
|
|
62
|
+
})
|
|
63
|
+
.catch(() => {
|
|
64
|
+
node.remove();
|
|
65
|
+
});
|
|
66
|
+
} else {
|
|
67
|
+
node.remove();
|
|
68
|
+
}
|
|
69
|
+
}
|