@esportsplus/template 0.26.3 → 0.26.5
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/build/slot/effect.js +12 -11
- package/build/slot/render.d.ts +1 -1
- package/build/slot/render.js +14 -14
- package/package.json +1 -1
- package/src/slot/effect.ts +16 -14
- package/src/slot/render.ts +14 -14
package/build/slot/effect.js
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
import { effect } from '@esportsplus/reactivity';
|
|
2
|
-
import { STATE_HYDRATING, STATE_NONE } from '../constants.js';
|
|
3
2
|
import { firstChild, lastChild, nodeValue } from '../utilities/node.js';
|
|
4
3
|
import { raf } from '../utilities/queue.js';
|
|
5
4
|
import { remove } from './cleanup.js';
|
|
6
5
|
import text from '../utilities/text.js';
|
|
7
6
|
import render from './render.js';
|
|
7
|
+
function read(value) {
|
|
8
|
+
if (typeof value === 'function') {
|
|
9
|
+
return read(value());
|
|
10
|
+
}
|
|
11
|
+
if (value == null || value === false) {
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
8
16
|
class EffectSlot {
|
|
9
17
|
anchor;
|
|
10
18
|
disposer;
|
|
11
19
|
group = null;
|
|
12
20
|
textnode = null;
|
|
13
21
|
constructor(anchor, fn) {
|
|
14
|
-
let dispose = fn.length ? () => this.dispose() : undefined
|
|
22
|
+
let dispose = fn.length ? () => this.dispose() : undefined;
|
|
15
23
|
this.anchor = anchor;
|
|
16
24
|
this.disposer = effect(() => {
|
|
17
|
-
let value = fn(dispose);
|
|
18
|
-
if (
|
|
19
|
-
state = STATE_NONE;
|
|
25
|
+
let value = read(fn(dispose));
|
|
26
|
+
if (!this.disposer) {
|
|
20
27
|
this.update(value);
|
|
21
28
|
}
|
|
22
29
|
else {
|
|
@@ -40,17 +47,11 @@ class EffectSlot {
|
|
|
40
47
|
}
|
|
41
48
|
}
|
|
42
49
|
update(value) {
|
|
43
|
-
if (typeof value === 'function') {
|
|
44
|
-
return this.update(value());
|
|
45
|
-
}
|
|
46
50
|
let { anchor, group, textnode } = this;
|
|
47
51
|
if (group) {
|
|
48
52
|
remove(group);
|
|
49
53
|
this.group = null;
|
|
50
54
|
}
|
|
51
|
-
if (value == null || value === false) {
|
|
52
|
-
value = '';
|
|
53
|
-
}
|
|
54
55
|
if (typeof value !== 'object') {
|
|
55
56
|
if (textnode) {
|
|
56
57
|
nodeValue.call(textnode, String(value));
|
package/build/slot/render.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Element } from '../types.js';
|
|
2
|
-
export default function render(anchor: Element,
|
|
2
|
+
export default function render(anchor: Element, value: unknown): Node;
|
package/build/slot/render.js
CHANGED
|
@@ -4,34 +4,34 @@ import { cloneNode, lastChild } from '../utilities/node.js';
|
|
|
4
4
|
import { append } from '../utilities/fragment.js';
|
|
5
5
|
import text from '../utilities/text.js';
|
|
6
6
|
import array from './array.js';
|
|
7
|
-
export default function render(anchor,
|
|
8
|
-
if (
|
|
7
|
+
export default function render(anchor, value) {
|
|
8
|
+
if (value == null || value === false || value === '') {
|
|
9
9
|
return EMPTY_FRAGMENT;
|
|
10
10
|
}
|
|
11
|
-
if (typeof
|
|
12
|
-
return text(
|
|
11
|
+
if (typeof value !== 'object') {
|
|
12
|
+
return text(value);
|
|
13
13
|
}
|
|
14
|
-
if (RENDERABLE in
|
|
15
|
-
return array(anchor,
|
|
14
|
+
if (RENDERABLE in value) {
|
|
15
|
+
return array(anchor, value);
|
|
16
16
|
}
|
|
17
|
-
if ('nodeType' in
|
|
18
|
-
return
|
|
17
|
+
if ('nodeType' in value) {
|
|
18
|
+
return value;
|
|
19
19
|
}
|
|
20
|
-
if (isArray(
|
|
20
|
+
if (isArray(value)) {
|
|
21
21
|
let fragment = cloneNode.call(EMPTY_FRAGMENT);
|
|
22
|
-
for (let i = 0, n =
|
|
23
|
-
append.call(fragment, render(anchor,
|
|
22
|
+
for (let i = 0, n = value.length; i < n; i++) {
|
|
23
|
+
append.call(fragment, render(anchor, value[i]));
|
|
24
24
|
anchor = lastChild.call(fragment);
|
|
25
25
|
}
|
|
26
26
|
return fragment;
|
|
27
27
|
}
|
|
28
|
-
if (
|
|
29
|
-
let fragment = cloneNode.call(EMPTY_FRAGMENT), nodes = Array.from(
|
|
28
|
+
if (value instanceof NodeList) {
|
|
29
|
+
let fragment = cloneNode.call(EMPTY_FRAGMENT), nodes = Array.from(value);
|
|
30
30
|
for (let i = 0, n = nodes.length; i < n; i++) {
|
|
31
31
|
append.call(fragment, nodes[i]);
|
|
32
32
|
}
|
|
33
33
|
return fragment;
|
|
34
34
|
}
|
|
35
|
-
return text(
|
|
35
|
+
return text(value);
|
|
36
36
|
}
|
|
37
37
|
;
|
package/package.json
CHANGED
package/src/slot/effect.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { effect } from '@esportsplus/reactivity';
|
|
2
|
-
import { STATE_HYDRATING, STATE_NONE } from '~/constants';
|
|
3
2
|
import { Element, Renderable, SlotGroup } from '~/types';
|
|
4
3
|
import { firstChild, lastChild, nodeValue } from '~/utilities/node'
|
|
5
4
|
import { raf } from '~/utilities/queue'
|
|
@@ -8,6 +7,19 @@ import text from '~/utilities/text';
|
|
|
8
7
|
import render from './render';
|
|
9
8
|
|
|
10
9
|
|
|
10
|
+
function read(value: unknown): unknown {
|
|
11
|
+
if (typeof value === 'function') {
|
|
12
|
+
return read( value() );
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (value == null || value === false) {
|
|
16
|
+
return '';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
11
23
|
class EffectSlot {
|
|
12
24
|
anchor: Element;
|
|
13
25
|
disposer: VoidFunction;
|
|
@@ -16,15 +28,13 @@ class EffectSlot {
|
|
|
16
28
|
|
|
17
29
|
|
|
18
30
|
constructor(anchor: Element, fn: (dispose?: VoidFunction) => Renderable<any>) {
|
|
19
|
-
let dispose = fn.length ? () => this.dispose() : undefined
|
|
20
|
-
state = STATE_HYDRATING;
|
|
31
|
+
let dispose = fn.length ? () => this.dispose() : undefined;
|
|
21
32
|
|
|
22
33
|
this.anchor = anchor;
|
|
23
34
|
this.disposer = effect(() => {
|
|
24
|
-
let value = fn(dispose);
|
|
35
|
+
let value = read( fn(dispose) );
|
|
25
36
|
|
|
26
|
-
if (
|
|
27
|
-
state = STATE_NONE;
|
|
37
|
+
if (!this.disposer) {
|
|
28
38
|
this.update(value);
|
|
29
39
|
}
|
|
30
40
|
else {
|
|
@@ -54,10 +64,6 @@ class EffectSlot {
|
|
|
54
64
|
}
|
|
55
65
|
|
|
56
66
|
update(value: unknown): void {
|
|
57
|
-
if (typeof value === 'function') {
|
|
58
|
-
return this.update( value() );
|
|
59
|
-
}
|
|
60
|
-
|
|
61
67
|
let { anchor, group, textnode } = this;
|
|
62
68
|
|
|
63
69
|
if (group) {
|
|
@@ -65,10 +71,6 @@ class EffectSlot {
|
|
|
65
71
|
this.group = null;
|
|
66
72
|
}
|
|
67
73
|
|
|
68
|
-
if (value == null || value === false) {
|
|
69
|
-
value = '';
|
|
70
|
-
}
|
|
71
|
-
|
|
72
74
|
if (typeof value !== 'object') {
|
|
73
75
|
if (textnode) {
|
|
74
76
|
nodeValue.call(textnode, String(value));
|
package/src/slot/render.ts
CHANGED
|
@@ -7,37 +7,37 @@ import text from '~/utilities/text';
|
|
|
7
7
|
import array from './array';
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
export default function render(anchor: Element,
|
|
11
|
-
if (
|
|
10
|
+
export default function render(anchor: Element, value: unknown): Node {
|
|
11
|
+
if (value == null || value === false || value === '') {
|
|
12
12
|
return EMPTY_FRAGMENT;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
if (typeof
|
|
16
|
-
return text(
|
|
15
|
+
if (typeof value !== 'object') {
|
|
16
|
+
return text(value as any);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
if (RENDERABLE in
|
|
20
|
-
return array(anchor,
|
|
19
|
+
if (RENDERABLE in value) {
|
|
20
|
+
return array(anchor, value as RenderableReactive<unknown>);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
if ('nodeType' in
|
|
24
|
-
return
|
|
23
|
+
if ('nodeType' in value) {
|
|
24
|
+
return value as Node;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
if (isArray(
|
|
27
|
+
if (isArray(value)) {
|
|
28
28
|
let fragment = cloneNode.call(EMPTY_FRAGMENT);
|
|
29
29
|
|
|
30
|
-
for (let i = 0, n = (
|
|
31
|
-
append.call(fragment, render(anchor, (
|
|
30
|
+
for (let i = 0, n = (value as unknown[]).length; i < n; i++) {
|
|
31
|
+
append.call(fragment, render(anchor, (value as unknown[])[i]));
|
|
32
32
|
anchor = lastChild.call(fragment);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
return fragment;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
if (
|
|
38
|
+
if (value instanceof NodeList) {
|
|
39
39
|
let fragment = cloneNode.call(EMPTY_FRAGMENT),
|
|
40
|
-
nodes = Array.from(
|
|
40
|
+
nodes = Array.from(value as NodeList);
|
|
41
41
|
|
|
42
42
|
for (let i = 0, n = nodes.length; i < n; i++) {
|
|
43
43
|
append.call(fragment, nodes[i]);
|
|
@@ -46,5 +46,5 @@ export default function render(anchor: Element, input: unknown): Node {
|
|
|
46
46
|
return fragment;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
return text(
|
|
49
|
+
return text(value as any);
|
|
50
50
|
};
|