@esportsplus/template 0.15.13 → 0.15.15
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.
Potentially problematic release.
This version of @esportsplus/template might be problematic. Click here for more details.
- package/build/attributes.js +2 -2
- package/build/event.js +3 -3
- package/build/slot.d.ts +2 -2
- package/build/slot.js +22 -18
- package/build/utilities.d.ts +2 -1
- package/build/utilities.js +4 -3
- package/package.json +4 -3
- package/src/attributes.ts +2 -2
- package/src/event.ts +3 -3
- package/src/slot.ts +23 -18
- package/src/utilities.ts +5 -2
package/build/attributes.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { effect } from '@esportsplus/reactivity';
|
|
2
2
|
import { isArray, isFunction, isObject, isString } from '@esportsplus/utilities';
|
|
3
|
-
import {
|
|
3
|
+
import { ondisconnect } from './slot.js';
|
|
4
4
|
import { className, raf, removeAttribute, setAttribute } from './utilities.js';
|
|
5
5
|
import event from './event.js';
|
|
6
6
|
let attributes = {}, delimiters = {
|
|
@@ -33,7 +33,7 @@ function set(element, value, name, wait = false) {
|
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
35
|
let id = ('e' + store(element)[key]++);
|
|
36
|
-
|
|
36
|
+
ondisconnect(element, effect(() => {
|
|
37
37
|
let v = value(element);
|
|
38
38
|
if (isArray(v)) {
|
|
39
39
|
let last = v.length - 1;
|
package/build/event.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { root } from '@esportsplus/reactivity';
|
|
2
2
|
import { defineProperty } from '@esportsplus/utilities';
|
|
3
|
-
import {
|
|
3
|
+
import { ondisconnect } from './slot.js';
|
|
4
4
|
import { addEventListener, parentElement } from './utilities.js';
|
|
5
5
|
let capture = new Set(['onblur', 'onfocus', 'onscroll']), controllers = new Map(), keys = {}, passive = new Set([
|
|
6
6
|
'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel',
|
|
@@ -26,7 +26,7 @@ export default (element, event, listener) => {
|
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
28
|
else if (event === 'ondisconnect') {
|
|
29
|
-
|
|
29
|
+
ondisconnect(element, () => listener(element));
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
32
|
else if (event === 'onrender') {
|
|
@@ -44,7 +44,7 @@ export default (element, event, listener) => {
|
|
|
44
44
|
}
|
|
45
45
|
if (controller) {
|
|
46
46
|
controller.listeners++;
|
|
47
|
-
|
|
47
|
+
ondisconnect(element, () => {
|
|
48
48
|
if (--controller.listeners) {
|
|
49
49
|
return;
|
|
50
50
|
}
|
package/build/slot.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ declare class Slot {
|
|
|
15
15
|
splice(start: number, stop?: number, ...groups: Elements[]): Elements[];
|
|
16
16
|
unshift(...groups: Elements[]): number;
|
|
17
17
|
}
|
|
18
|
-
declare const
|
|
18
|
+
declare const ondisconnect: (element: Element, fn: VoidFunction) => void;
|
|
19
19
|
declare const _default: (marker: Element, value: unknown) => Slot;
|
|
20
20
|
export default _default;
|
|
21
|
-
export {
|
|
21
|
+
export { ondisconnect, Slot };
|
package/build/slot.js
CHANGED
|
@@ -2,8 +2,9 @@ import { effect, root } from '@esportsplus/reactivity';
|
|
|
2
2
|
import { isArray, isFunction, isInstanceOf, isObject } from '@esportsplus/utilities';
|
|
3
3
|
import { RENDERABLE, RENDERABLE_REACTIVE, SLOT_CLEANUP } from './constants.js';
|
|
4
4
|
import { hydrate } from './html/index.js';
|
|
5
|
-
import { firstChild, nextSibling, nodeValue, raf, text } from './utilities.js';
|
|
6
|
-
|
|
5
|
+
import { firstChild, microtask, nextSibling, nodeValue, raf, text } from './utilities.js';
|
|
6
|
+
import queue from '@esportsplus/queue';
|
|
7
|
+
let cleanup = queue(1024), scheduled = false;
|
|
7
8
|
function after(anchor, groups) {
|
|
8
9
|
for (let i = 0, n = groups.length; i < n; i++) {
|
|
9
10
|
let group = groups[i];
|
|
@@ -20,7 +21,7 @@ function remove(...groups) {
|
|
|
20
21
|
for (let j = 0, o = group.length; j < o; j++) {
|
|
21
22
|
let item = group[j];
|
|
22
23
|
if (item[SLOT_CLEANUP]) {
|
|
23
|
-
cleanup.
|
|
24
|
+
cleanup.add(item[SLOT_CLEANUP]);
|
|
24
25
|
}
|
|
25
26
|
item.remove();
|
|
26
27
|
}
|
|
@@ -81,26 +82,29 @@ function schedule() {
|
|
|
81
82
|
return;
|
|
82
83
|
}
|
|
83
84
|
scheduled = true;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
microtask.add(task);
|
|
86
|
+
}
|
|
87
|
+
function task() {
|
|
88
|
+
let fns;
|
|
89
|
+
while (fns = cleanup.next()) {
|
|
90
|
+
for (let i = 0, n = fns.length; i < n; i++) {
|
|
91
|
+
try {
|
|
92
|
+
fns[i]();
|
|
89
93
|
}
|
|
94
|
+
catch { }
|
|
90
95
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
});
|
|
96
|
+
}
|
|
97
|
+
scheduled = false;
|
|
98
|
+
if (cleanup.length) {
|
|
99
|
+
schedule();
|
|
100
|
+
}
|
|
97
101
|
}
|
|
98
102
|
class Slot {
|
|
99
103
|
marker;
|
|
100
104
|
nodes;
|
|
101
105
|
text = null;
|
|
102
106
|
constructor(marker) {
|
|
103
|
-
|
|
107
|
+
ondisconnect(marker, () => this.clear());
|
|
104
108
|
this.marker = marker;
|
|
105
109
|
this.nodes = [];
|
|
106
110
|
}
|
|
@@ -137,7 +141,7 @@ class Slot {
|
|
|
137
141
|
}
|
|
138
142
|
render(input) {
|
|
139
143
|
if (isFunction(input)) {
|
|
140
|
-
|
|
144
|
+
ondisconnect(this.marker, effect(() => {
|
|
141
145
|
let v = input();
|
|
142
146
|
if (isFunction(v)) {
|
|
143
147
|
root(() => this.render(v()));
|
|
@@ -181,10 +185,10 @@ class Slot {
|
|
|
181
185
|
return this.nodes.unshift(...after(this.marker, groups));
|
|
182
186
|
}
|
|
183
187
|
}
|
|
184
|
-
const
|
|
188
|
+
const ondisconnect = (element, fn) => {
|
|
185
189
|
(element[SLOT_CLEANUP] ??= []).push(fn);
|
|
186
190
|
};
|
|
187
191
|
export default (marker, value) => {
|
|
188
192
|
return new Slot(marker).render(value);
|
|
189
193
|
};
|
|
190
|
-
export {
|
|
194
|
+
export { ondisconnect, Slot };
|
package/build/utilities.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ declare const nodeValue: (v: any) => void;
|
|
|
21
21
|
declare const parentElement: () => any;
|
|
22
22
|
declare const parentNode: () => any;
|
|
23
23
|
declare const fragment: (html: string) => DocumentFragment;
|
|
24
|
+
declare const microtask: import("@esportsplus/tasks/build/factory").Scheduler;
|
|
24
25
|
declare const raf: import("@esportsplus/tasks/build/factory").Scheduler;
|
|
25
26
|
declare const text: (value: string) => E;
|
|
26
|
-
export { addEventListener, className, cloneNode, firstChild, firstElementChild, fragment, innerHTML, nextElementSibling, nextSibling, nodeValue, parentElement, parentNode, prepend, raf, removeAttribute, removeEventListener, setAttribute, text };
|
|
27
|
+
export { addEventListener, className, cloneNode, firstChild, firstElementChild, fragment, innerHTML, microtask, nextElementSibling, nextSibling, nodeValue, parentElement, parentNode, prepend, raf, removeAttribute, removeEventListener, setAttribute, text };
|
package/build/utilities.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { raf as
|
|
1
|
+
import { micro as m, raf as r } from '@esportsplus/tasks';
|
|
2
2
|
let prototype, template = document.createElement('template'), t = document.createTextNode('');
|
|
3
3
|
prototype = Element.prototype;
|
|
4
4
|
const addEventListener = prototype.addEventListener;
|
|
@@ -23,7 +23,8 @@ const fragment = (html) => {
|
|
|
23
23
|
template = cloneNode.call(template);
|
|
24
24
|
return content;
|
|
25
25
|
};
|
|
26
|
-
const
|
|
26
|
+
const microtask = m();
|
|
27
|
+
const raf = r();
|
|
27
28
|
const text = (value) => {
|
|
28
29
|
let element = cloneNode.call(t);
|
|
29
30
|
if (value !== '') {
|
|
@@ -31,4 +32,4 @@ const text = (value) => {
|
|
|
31
32
|
}
|
|
32
33
|
return element;
|
|
33
34
|
};
|
|
34
|
-
export { addEventListener, className, cloneNode, firstChild, firstElementChild, fragment, innerHTML, nextElementSibling, nextSibling, nodeValue, parentElement, parentNode, prepend, raf, removeAttribute, removeEventListener, setAttribute, text };
|
|
35
|
+
export { addEventListener, className, cloneNode, firstChild, firstElementChild, fragment, innerHTML, microtask, nextElementSibling, nextSibling, nodeValue, parentElement, parentNode, prepend, raf, removeAttribute, removeEventListener, setAttribute, text };
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "ICJR",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@esportsplus/
|
|
5
|
-
"@esportsplus/
|
|
4
|
+
"@esportsplus/queue": "^0.1.0",
|
|
5
|
+
"@esportsplus/reactivity": "^0.12.2",
|
|
6
|
+
"@esportsplus/tasks": "^0.2.1",
|
|
6
7
|
"@esportsplus/utilities": "^0.21.1"
|
|
7
8
|
},
|
|
8
9
|
"devDependencies": {
|
|
@@ -13,7 +14,7 @@
|
|
|
13
14
|
"private": false,
|
|
14
15
|
"type": "module",
|
|
15
16
|
"types": "./build/index.d.ts",
|
|
16
|
-
"version": "0.15.
|
|
17
|
+
"version": "0.15.15",
|
|
17
18
|
"scripts": {
|
|
18
19
|
"build": "tsc && tsc-alias",
|
|
19
20
|
"-": "-"
|
package/src/attributes.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { effect } from '@esportsplus/reactivity';
|
|
2
2
|
import { isArray, isFunction, isObject, isString } from '@esportsplus/utilities';
|
|
3
|
-
import {
|
|
3
|
+
import { ondisconnect } from './slot';
|
|
4
4
|
import { Attributes, Element } from './types';
|
|
5
5
|
import { className, raf, removeAttribute, setAttribute } from './utilities';
|
|
6
6
|
import event from './event';
|
|
@@ -42,7 +42,7 @@ function set(element: Element, value: unknown, name: string, wait = false) {
|
|
|
42
42
|
else {
|
|
43
43
|
let id = ('e' + store(element)[key]++);
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
ondisconnect(
|
|
46
46
|
element,
|
|
47
47
|
effect(() => {
|
|
48
48
|
let v = (value as Function)(element);
|
package/src/event.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { root } from '@esportsplus/reactivity';
|
|
2
2
|
import { defineProperty } from '@esportsplus/utilities';
|
|
3
|
-
import {
|
|
3
|
+
import { ondisconnect } from './slot';
|
|
4
4
|
import { Element } from './types';
|
|
5
5
|
import { addEventListener, parentElement } from './utilities';
|
|
6
6
|
|
|
@@ -43,7 +43,7 @@ export default (element: Element, event: `on${string}`, listener: Function): voi
|
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
45
|
else if (event === 'ondisconnect') {
|
|
46
|
-
|
|
46
|
+
ondisconnect(element, () => listener(element));
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
else if (event === 'onrender') {
|
|
@@ -70,7 +70,7 @@ export default (element: Element, event: `on${string}`, listener: Function): voi
|
|
|
70
70
|
if (controller) {
|
|
71
71
|
controller.listeners++;
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
ondisconnect(element, () => {
|
|
74
74
|
if (--controller.listeners) {
|
|
75
75
|
return;
|
|
76
76
|
}
|
package/src/slot.ts
CHANGED
|
@@ -3,10 +3,11 @@ import { isArray, isFunction, isInstanceOf, isObject } from '@esportsplus/utili
|
|
|
3
3
|
import { RENDERABLE, RENDERABLE_REACTIVE, SLOT_CLEANUP } from './constants';
|
|
4
4
|
import { hydrate } from './html';
|
|
5
5
|
import { Element, Elements, RenderableReactive, RenderableTemplate } from './types';
|
|
6
|
-
import { firstChild, nextSibling, nodeValue, raf, text } from './utilities'
|
|
6
|
+
import { firstChild, microtask, nextSibling, nodeValue, raf, text } from './utilities'
|
|
7
|
+
import queue from '@esportsplus/queue';
|
|
7
8
|
|
|
8
9
|
|
|
9
|
-
let cleanup
|
|
10
|
+
let cleanup = queue<VoidFunction[]>(1024),
|
|
10
11
|
scheduled = false;
|
|
11
12
|
|
|
12
13
|
|
|
@@ -31,7 +32,7 @@ function remove(...groups: Elements[]) {
|
|
|
31
32
|
let item = group[j];
|
|
32
33
|
|
|
33
34
|
if (item[SLOT_CLEANUP]) {
|
|
34
|
-
cleanup.
|
|
35
|
+
cleanup.add( item[SLOT_CLEANUP] );
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
item.remove();
|
|
@@ -110,22 +111,26 @@ function schedule() {
|
|
|
110
111
|
|
|
111
112
|
scheduled = true;
|
|
112
113
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
microtask.add(task);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function task() {
|
|
118
|
+
let fns;
|
|
116
119
|
|
|
117
|
-
|
|
118
|
-
|
|
120
|
+
while (fns = cleanup.next()) {
|
|
121
|
+
for (let i = 0, n = fns.length; i < n; i++) {
|
|
122
|
+
try {
|
|
123
|
+
fns[i]();
|
|
119
124
|
}
|
|
125
|
+
catch { }
|
|
120
126
|
}
|
|
121
|
-
|
|
127
|
+
}
|
|
122
128
|
|
|
123
|
-
|
|
129
|
+
scheduled = false;
|
|
124
130
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
});
|
|
131
|
+
if (cleanup.length) {
|
|
132
|
+
schedule();
|
|
133
|
+
}
|
|
129
134
|
}
|
|
130
135
|
|
|
131
136
|
|
|
@@ -136,7 +141,7 @@ class Slot {
|
|
|
136
141
|
|
|
137
142
|
|
|
138
143
|
constructor(marker: Element) {
|
|
139
|
-
|
|
144
|
+
ondisconnect(marker, () => this.clear());
|
|
140
145
|
|
|
141
146
|
this.marker = marker;
|
|
142
147
|
this.nodes = [];
|
|
@@ -190,7 +195,7 @@ class Slot {
|
|
|
190
195
|
|
|
191
196
|
render(input: unknown) {
|
|
192
197
|
if (isFunction(input)) {
|
|
193
|
-
|
|
198
|
+
ondisconnect(
|
|
194
199
|
this.marker,
|
|
195
200
|
effect(() => {
|
|
196
201
|
let v = (input as Function)();
|
|
@@ -256,7 +261,7 @@ class Slot {
|
|
|
256
261
|
}
|
|
257
262
|
|
|
258
263
|
|
|
259
|
-
const
|
|
264
|
+
const ondisconnect = (element: Element, fn: VoidFunction) => {
|
|
260
265
|
( element[SLOT_CLEANUP] ??= [] ).push(fn);
|
|
261
266
|
};
|
|
262
267
|
|
|
@@ -264,4 +269,4 @@ const onCleanup = (element: Element, fn: VoidFunction) => {
|
|
|
264
269
|
export default (marker: Element, value: unknown) => {
|
|
265
270
|
return new Slot(marker).render(value);
|
|
266
271
|
};
|
|
267
|
-
export {
|
|
272
|
+
export { ondisconnect, Slot };
|
package/src/utilities.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { raf as
|
|
1
|
+
import { micro as m, raf as r } from '@esportsplus/tasks';
|
|
2
2
|
import { Element as E } from './types';
|
|
3
3
|
|
|
4
4
|
|
|
@@ -54,7 +54,9 @@ const fragment = (html: string) => {
|
|
|
54
54
|
return content;
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
-
const
|
|
57
|
+
const microtask = m();
|
|
58
|
+
|
|
59
|
+
const raf = r();
|
|
58
60
|
|
|
59
61
|
const text = (value: string) => {
|
|
60
62
|
let element = cloneNode.call(t);
|
|
@@ -72,6 +74,7 @@ export {
|
|
|
72
74
|
className, cloneNode,
|
|
73
75
|
firstChild, firstElementChild, fragment,
|
|
74
76
|
innerHTML,
|
|
77
|
+
microtask,
|
|
75
78
|
nextElementSibling, nextSibling, nodeValue,
|
|
76
79
|
parentElement, parentNode, prepend,
|
|
77
80
|
raf, removeAttribute, removeEventListener,
|