@esportsplus/template 0.26.1 → 0.26.3
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/attributes.js +6 -6
- package/build/slot/array.js +1 -11
- package/build/slot/effect.js +6 -3
- package/package.json +4 -4
- package/src/attributes.ts +6 -8
- package/src/slot/array.ts +2 -14
- package/src/slot/effect.ts +9 -5
package/build/attributes.js
CHANGED
|
@@ -31,20 +31,20 @@ function list(ctx, element, id, name, state, value) {
|
|
|
31
31
|
if (value == null || value === false || value === '') {
|
|
32
32
|
value = '';
|
|
33
33
|
}
|
|
34
|
-
let base = name + '.static', delimiter = delimiters[name], store = (ctx ??= context(element)).store ??= {}, dynamic = store[name]
|
|
34
|
+
let base = name + '.static', delimiter = delimiters[name], store = (ctx ??= context(element)).store ??= {}, dynamic = store[name];
|
|
35
35
|
if (dynamic === undefined) {
|
|
36
36
|
let value = (element.getAttribute(name) || '').trim();
|
|
37
37
|
store[base] = value;
|
|
38
38
|
store[name] = dynamic = new Set();
|
|
39
39
|
}
|
|
40
40
|
if (id === null) {
|
|
41
|
-
if (value &&
|
|
41
|
+
if (value && typeof value === 'string') {
|
|
42
42
|
store[base] += (store[base] ? delimiter : '') + value;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
46
46
|
let hot = {};
|
|
47
|
-
if (value &&
|
|
47
|
+
if (value && typeof value === 'string') {
|
|
48
48
|
let part, parts = value.split(delimiter);
|
|
49
49
|
for (let i = 0, n = parts.length; i < n; i++) {
|
|
50
50
|
part = parts[i].trim();
|
|
@@ -126,8 +126,8 @@ function task() {
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
const set = (element, name, value) => {
|
|
129
|
-
let fn = name === 'class' || name === 'style' ? list : property, state = STATE_HYDRATING
|
|
130
|
-
if (
|
|
129
|
+
let fn = name === 'class' || name === 'style' ? list : property, state = STATE_HYDRATING;
|
|
130
|
+
if (typeof value === 'function') {
|
|
131
131
|
if (name.startsWith('on')) {
|
|
132
132
|
return event(element, name, value);
|
|
133
133
|
}
|
|
@@ -151,7 +151,7 @@ const set = (element, name, value) => {
|
|
|
151
151
|
state = STATE_NONE;
|
|
152
152
|
return;
|
|
153
153
|
}
|
|
154
|
-
if (
|
|
154
|
+
if (typeof value !== 'object') {
|
|
155
155
|
}
|
|
156
156
|
else if (isArray(value)) {
|
|
157
157
|
for (let i = 0, n = value.length; i < n; i++) {
|
package/build/slot/array.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { root } from '@esportsplus/reactivity';
|
|
2
2
|
import { EMPTY_FRAGMENT } from '../constants.js';
|
|
3
3
|
import { append } from '../utilities/fragment.js';
|
|
4
4
|
import { cloneNode, firstChild, lastChild } from '../utilities/node.js';
|
|
@@ -9,7 +9,6 @@ class ArraySlot {
|
|
|
9
9
|
marker;
|
|
10
10
|
nodes = [];
|
|
11
11
|
template;
|
|
12
|
-
trigger = signal(false);
|
|
13
12
|
constructor(anchor, array, template) {
|
|
14
13
|
let fragment = this.fragment = cloneNode.call(EMPTY_FRAGMENT);
|
|
15
14
|
this.array = array;
|
|
@@ -46,7 +45,6 @@ class ArraySlot {
|
|
|
46
45
|
});
|
|
47
46
|
}
|
|
48
47
|
get length() {
|
|
49
|
-
read(this.trigger);
|
|
50
48
|
return this.nodes.length;
|
|
51
49
|
}
|
|
52
50
|
set length(n) {
|
|
@@ -59,7 +57,6 @@ class ArraySlot {
|
|
|
59
57
|
else {
|
|
60
58
|
this.splice(n);
|
|
61
59
|
}
|
|
62
|
-
set(this.trigger, !this.trigger.value);
|
|
63
60
|
}
|
|
64
61
|
anchor(index = this.nodes.length - 1) {
|
|
65
62
|
let node = this.nodes[index];
|
|
@@ -70,20 +67,17 @@ class ArraySlot {
|
|
|
70
67
|
}
|
|
71
68
|
clear() {
|
|
72
69
|
remove(...this.nodes.splice(0));
|
|
73
|
-
set(this.trigger, !this.trigger.value);
|
|
74
70
|
}
|
|
75
71
|
pop() {
|
|
76
72
|
let group = this.nodes.pop();
|
|
77
73
|
if (group) {
|
|
78
74
|
remove(group);
|
|
79
|
-
set(this.trigger, !this.trigger.value);
|
|
80
75
|
}
|
|
81
76
|
}
|
|
82
77
|
push(items) {
|
|
83
78
|
let anchor = this.anchor();
|
|
84
79
|
this.nodes.push(...items.map(this.template));
|
|
85
80
|
anchor.after(this.fragment);
|
|
86
|
-
set(this.trigger, !this.trigger.value);
|
|
87
81
|
}
|
|
88
82
|
render() {
|
|
89
83
|
if (this.nodes.length) {
|
|
@@ -96,23 +90,19 @@ class ArraySlot {
|
|
|
96
90
|
let group = this.nodes.shift();
|
|
97
91
|
if (group) {
|
|
98
92
|
remove(group);
|
|
99
|
-
set(this.trigger, !this.trigger.value);
|
|
100
93
|
}
|
|
101
94
|
}
|
|
102
95
|
splice(start, stop = this.nodes.length, ...items) {
|
|
103
96
|
if (!items.length) {
|
|
104
97
|
remove(...this.nodes.splice(start, stop));
|
|
105
|
-
set(this.trigger, !this.trigger.value);
|
|
106
98
|
return;
|
|
107
99
|
}
|
|
108
100
|
remove(...this.nodes.splice(start, stop, ...items.map(this.template)));
|
|
109
101
|
this.anchor(start - 1).after(this.fragment);
|
|
110
|
-
set(this.trigger, !this.trigger.value);
|
|
111
102
|
}
|
|
112
103
|
unshift(items) {
|
|
113
104
|
this.nodes.unshift(...items.map(this.template));
|
|
114
105
|
this.marker.after(this.fragment);
|
|
115
|
-
set(this.trigger, !this.trigger.value);
|
|
116
106
|
}
|
|
117
107
|
}
|
|
118
108
|
export default (anchor, renderable) => {
|
package/build/slot/effect.js
CHANGED
|
@@ -40,14 +40,17 @@ class EffectSlot {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
update(value) {
|
|
43
|
-
if (
|
|
44
|
-
|
|
43
|
+
if (typeof value === 'function') {
|
|
44
|
+
return this.update(value());
|
|
45
|
+
}
|
|
46
|
+
let { anchor, group, textnode } = this;
|
|
47
|
+
if (group) {
|
|
48
|
+
remove(group);
|
|
45
49
|
this.group = null;
|
|
46
50
|
}
|
|
47
51
|
if (value == null || value === false) {
|
|
48
52
|
value = '';
|
|
49
53
|
}
|
|
50
|
-
let { anchor, textnode } = this;
|
|
51
54
|
if (typeof value !== 'object') {
|
|
52
55
|
if (textnode) {
|
|
53
56
|
nodeValue.call(textnode, String(value));
|
package/package.json
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"author": "ICJR",
|
|
3
3
|
"dependencies": {
|
|
4
4
|
"@esportsplus/queue": "^0.1.0",
|
|
5
|
-
"@esportsplus/reactivity": "^0.
|
|
6
|
-
"@esportsplus/tasks": "^0.
|
|
7
|
-
"@esportsplus/utilities": "^0.
|
|
5
|
+
"@esportsplus/reactivity": "^0.18.1",
|
|
6
|
+
"@esportsplus/tasks": "^0.4.0",
|
|
7
|
+
"@esportsplus/utilities": "^0.25.0"
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
10
|
"@esportsplus/typescript": "^0.9.2"
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"private": false,
|
|
15
15
|
"type": "module",
|
|
16
16
|
"types": "./build/index.d.ts",
|
|
17
|
-
"version": "0.26.
|
|
17
|
+
"version": "0.26.3",
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "tsc && tsc-alias",
|
|
20
20
|
"-": "-"
|
package/src/attributes.ts
CHANGED
|
@@ -64,8 +64,7 @@ function list(
|
|
|
64
64
|
let base = name + '.static',
|
|
65
65
|
delimiter = delimiters[name],
|
|
66
66
|
store = (ctx ??= context(element)).store ??= {},
|
|
67
|
-
dynamic = store[name] as Set<string> | undefined
|
|
68
|
-
type = typeof value;
|
|
67
|
+
dynamic = store[name] as Set<string> | undefined;
|
|
69
68
|
|
|
70
69
|
if (dynamic === undefined) {
|
|
71
70
|
let value = (element.getAttribute(name) || '').trim();
|
|
@@ -75,14 +74,14 @@ function list(
|
|
|
75
74
|
}
|
|
76
75
|
|
|
77
76
|
if (id === null) {
|
|
78
|
-
if (value &&
|
|
77
|
+
if (value && typeof value === 'string') {
|
|
79
78
|
store[base] += (store[base] ? delimiter : '') + value;
|
|
80
79
|
}
|
|
81
80
|
}
|
|
82
81
|
else {
|
|
83
82
|
let hot: Attributes = {};
|
|
84
83
|
|
|
85
|
-
if (value &&
|
|
84
|
+
if (value && typeof value === 'string') {
|
|
86
85
|
let part: string,
|
|
87
86
|
parts = (value as string).split(delimiter);
|
|
88
87
|
|
|
@@ -200,10 +199,9 @@ function task() {
|
|
|
200
199
|
|
|
201
200
|
const set = (element: Element, name: string, value: unknown) => {
|
|
202
201
|
let fn = name === 'class' || name === 'style' ? list : property,
|
|
203
|
-
state: State = STATE_HYDRATING
|
|
204
|
-
type = typeof value;
|
|
202
|
+
state: State = STATE_HYDRATING;
|
|
205
203
|
|
|
206
|
-
if (
|
|
204
|
+
if (typeof value === 'function') {
|
|
207
205
|
if (name.startsWith('on')) {
|
|
208
206
|
return event(element, name as `on${string}`, value as Function);
|
|
209
207
|
}
|
|
@@ -243,7 +241,7 @@ const set = (element: Element, name: string, value: unknown) => {
|
|
|
243
241
|
return;
|
|
244
242
|
}
|
|
245
243
|
|
|
246
|
-
if (
|
|
244
|
+
if (typeof value !== 'object') {
|
|
247
245
|
// Skip isArray when possible
|
|
248
246
|
}
|
|
249
247
|
else if (isArray(value)) {
|
package/src/slot/array.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { root, ReactiveArray } from '@esportsplus/reactivity';
|
|
2
2
|
import { EMPTY_FRAGMENT } from '~/constants';
|
|
3
3
|
import { RenderableReactive, SlotGroup } from '~/types';
|
|
4
4
|
import { append } from '~/utilities/fragment';
|
|
@@ -12,7 +12,6 @@ class ArraySlot<T> {
|
|
|
12
12
|
marker: Element;
|
|
13
13
|
nodes: SlotGroup[] = [];
|
|
14
14
|
template: (...args: Parameters< RenderableReactive<T>['template'] >) => SlotGroup;
|
|
15
|
-
trigger = signal(false);
|
|
16
15
|
|
|
17
16
|
|
|
18
17
|
constructor(anchor: Element, array: ReactiveArray<T>, template: RenderableReactive<T>['template']) {
|
|
@@ -59,7 +58,6 @@ class ArraySlot<T> {
|
|
|
59
58
|
|
|
60
59
|
|
|
61
60
|
get length() {
|
|
62
|
-
read(this.trigger);
|
|
63
61
|
return this.nodes.length;
|
|
64
62
|
}
|
|
65
63
|
|
|
@@ -73,8 +71,6 @@ class ArraySlot<T> {
|
|
|
73
71
|
else {
|
|
74
72
|
this.splice(n);
|
|
75
73
|
}
|
|
76
|
-
|
|
77
|
-
set(this.trigger, !this.trigger.value);
|
|
78
74
|
}
|
|
79
75
|
|
|
80
76
|
|
|
@@ -90,7 +86,7 @@ class ArraySlot<T> {
|
|
|
90
86
|
|
|
91
87
|
clear() {
|
|
92
88
|
remove(...this.nodes.splice(0));
|
|
93
|
-
|
|
89
|
+
|
|
94
90
|
}
|
|
95
91
|
|
|
96
92
|
pop() {
|
|
@@ -98,7 +94,6 @@ class ArraySlot<T> {
|
|
|
98
94
|
|
|
99
95
|
if (group) {
|
|
100
96
|
remove(group);
|
|
101
|
-
set(this.trigger, !this.trigger.value);
|
|
102
97
|
}
|
|
103
98
|
}
|
|
104
99
|
|
|
@@ -108,7 +103,6 @@ class ArraySlot<T> {
|
|
|
108
103
|
this.nodes.push( ...items.map(this.template) );
|
|
109
104
|
|
|
110
105
|
anchor.after(this.fragment);
|
|
111
|
-
set(this.trigger, !this.trigger.value);
|
|
112
106
|
}
|
|
113
107
|
|
|
114
108
|
render() {
|
|
@@ -125,28 +119,22 @@ class ArraySlot<T> {
|
|
|
125
119
|
|
|
126
120
|
if (group) {
|
|
127
121
|
remove(group);
|
|
128
|
-
set(this.trigger, !this.trigger.value);
|
|
129
122
|
}
|
|
130
123
|
}
|
|
131
124
|
|
|
132
125
|
splice(start: number, stop: number = this.nodes.length, ...items: T[]) {
|
|
133
126
|
if (!items.length) {
|
|
134
127
|
remove(...this.nodes.splice(start, stop));
|
|
135
|
-
set(this.trigger, !this.trigger.value);
|
|
136
128
|
return;
|
|
137
129
|
}
|
|
138
130
|
|
|
139
131
|
remove( ...this.nodes.splice(start, stop, ...items.map(this.template)) );
|
|
140
132
|
this.anchor(start - 1).after(this.fragment);
|
|
141
|
-
|
|
142
|
-
set(this.trigger, !this.trigger.value);
|
|
143
133
|
}
|
|
144
134
|
|
|
145
135
|
unshift(items: T[]) {
|
|
146
136
|
this.nodes.unshift(...items.map(this.template));
|
|
147
137
|
this.marker.after(this.fragment);
|
|
148
|
-
|
|
149
|
-
set(this.trigger, !this.trigger.value);
|
|
150
138
|
}
|
|
151
139
|
}
|
|
152
140
|
|
package/src/slot/effect.ts
CHANGED
|
@@ -53,9 +53,15 @@ class EffectSlot {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
update(value: unknown) {
|
|
57
|
-
if (
|
|
58
|
-
|
|
56
|
+
update(value: unknown): void {
|
|
57
|
+
if (typeof value === 'function') {
|
|
58
|
+
return this.update( value() );
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let { anchor, group, textnode } = this;
|
|
62
|
+
|
|
63
|
+
if (group) {
|
|
64
|
+
remove(group);
|
|
59
65
|
this.group = null;
|
|
60
66
|
}
|
|
61
67
|
|
|
@@ -63,8 +69,6 @@ class EffectSlot {
|
|
|
63
69
|
value = '';
|
|
64
70
|
}
|
|
65
71
|
|
|
66
|
-
let { anchor, textnode } = this;
|
|
67
|
-
|
|
68
72
|
if (typeof value !== 'object') {
|
|
69
73
|
if (textnode) {
|
|
70
74
|
nodeValue.call(textnode, String(value));
|