@esportsplus/template 0.15.12 → 0.15.14
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 +3 -12
- package/build/event.js +5 -5
- package/build/slot.d.ts +2 -2
- package/build/slot.js +12 -9
- package/build/types.d.ts +2 -2
- package/package.json +4 -3
- package/src/attributes.ts +3 -14
- package/src/event.ts +5 -5
- package/src/slot.ts +12 -9
- package/src/types.ts +2 -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 = {
|
|
@@ -8,10 +8,7 @@ let attributes = {}, delimiters = {
|
|
|
8
8
|
style: ';'
|
|
9
9
|
}, key = Symbol();
|
|
10
10
|
function attribute(element, name, value) {
|
|
11
|
-
if (value === false || value == null) {
|
|
12
|
-
value = '';
|
|
13
|
-
}
|
|
14
|
-
if (value === '') {
|
|
11
|
+
if (value === '' || value === false || value == null) {
|
|
15
12
|
removeAttribute.call(element, name);
|
|
16
13
|
}
|
|
17
14
|
else if (name === 'class') {
|
|
@@ -36,7 +33,7 @@ function set(element, value, name, wait = false) {
|
|
|
36
33
|
}
|
|
37
34
|
else {
|
|
38
35
|
let id = ('e' + store(element)[key]++);
|
|
39
|
-
|
|
36
|
+
ondisconnect(element, effect(() => {
|
|
40
37
|
let v = value(element);
|
|
41
38
|
if (isArray(v)) {
|
|
42
39
|
let last = v.length - 1;
|
|
@@ -136,17 +133,11 @@ const spread = function (element, attributes) {
|
|
|
136
133
|
else if (isArray(attributes)) {
|
|
137
134
|
for (let i = 0, n = attributes.length; i < n; i++) {
|
|
138
135
|
let attrs = attributes[i];
|
|
139
|
-
if (!isObject(attrs)) {
|
|
140
|
-
throw new Error('@esportsplus/template: attributes must be of type `Attributes` or `Attributes[]`; Received ' + JSON.stringify(attributes));
|
|
141
|
-
}
|
|
142
136
|
for (let name in attrs) {
|
|
143
137
|
set(element, attrs[name], name, true);
|
|
144
138
|
}
|
|
145
139
|
}
|
|
146
140
|
}
|
|
147
|
-
else {
|
|
148
|
-
throw new Error('@esportsplus/template: attributes must be of type `Attributes` or `Attributes[]`; Received ' + JSON.stringify(attributes));
|
|
149
|
-
}
|
|
150
141
|
};
|
|
151
142
|
export default { apply, spread };
|
|
152
143
|
export { apply, spread };
|
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',
|
|
@@ -12,7 +12,7 @@ let capture = new Set(['onblur', 'onfocus', 'onscroll']), controllers = new Map(
|
|
|
12
12
|
controllers.set(event, null);
|
|
13
13
|
});
|
|
14
14
|
export default (element, event, listener) => {
|
|
15
|
-
if (event === '
|
|
15
|
+
if (event === 'onconnect') {
|
|
16
16
|
let interval = setInterval(() => {
|
|
17
17
|
retry--;
|
|
18
18
|
if (element.isConnected) {
|
|
@@ -25,8 +25,8 @@ export default (element, event, listener) => {
|
|
|
25
25
|
}, 1000 / 60), retry = 60;
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
|
-
else if (event === '
|
|
29
|
-
|
|
28
|
+
else if (event === 'ondisconnect') {
|
|
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
|
@@ -3,7 +3,8 @@ import { isArray, isFunction, isInstanceOf, isObject } from '@esportsplus/utilit
|
|
|
3
3
|
import { RENDERABLE, RENDERABLE_REACTIVE, SLOT_CLEANUP } from './constants.js';
|
|
4
4
|
import { hydrate } from './html/index.js';
|
|
5
5
|
import { firstChild, nextSibling, nodeValue, raf, text } from './utilities.js';
|
|
6
|
-
|
|
6
|
+
import queue from '@esportsplus/queue';
|
|
7
|
+
let cleanup = queue(), 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
|
}
|
|
@@ -83,9 +84,11 @@ function schedule() {
|
|
|
83
84
|
scheduled = true;
|
|
84
85
|
raf.add(() => {
|
|
85
86
|
try {
|
|
86
|
-
let
|
|
87
|
-
while (
|
|
88
|
-
|
|
87
|
+
let fns;
|
|
88
|
+
while (fns = cleanup.next()) {
|
|
89
|
+
for (let i = 0, n = fns.length; i < n; i++) {
|
|
90
|
+
fns[i]();
|
|
91
|
+
}
|
|
89
92
|
}
|
|
90
93
|
}
|
|
91
94
|
catch (e) { }
|
|
@@ -100,7 +103,7 @@ class Slot {
|
|
|
100
103
|
nodes;
|
|
101
104
|
text = null;
|
|
102
105
|
constructor(marker) {
|
|
103
|
-
|
|
106
|
+
ondisconnect(marker, () => this.clear());
|
|
104
107
|
this.marker = marker;
|
|
105
108
|
this.nodes = [];
|
|
106
109
|
}
|
|
@@ -137,7 +140,7 @@ class Slot {
|
|
|
137
140
|
}
|
|
138
141
|
render(input) {
|
|
139
142
|
if (isFunction(input)) {
|
|
140
|
-
|
|
143
|
+
ondisconnect(this.marker, effect(() => {
|
|
141
144
|
let v = input();
|
|
142
145
|
if (isFunction(v)) {
|
|
143
146
|
root(() => this.render(v()));
|
|
@@ -181,10 +184,10 @@ class Slot {
|
|
|
181
184
|
return this.nodes.unshift(...after(this.marker, groups));
|
|
182
185
|
}
|
|
183
186
|
}
|
|
184
|
-
const
|
|
187
|
+
const ondisconnect = (element, fn) => {
|
|
185
188
|
(element[SLOT_CLEANUP] ??= []).push(fn);
|
|
186
189
|
};
|
|
187
190
|
export default (marker, value) => {
|
|
188
191
|
return new Slot(marker).render(value);
|
|
189
192
|
};
|
|
190
|
-
export {
|
|
193
|
+
export { ondisconnect, Slot };
|
package/build/types.d.ts
CHANGED
|
@@ -13,8 +13,8 @@ type Attributes = {
|
|
|
13
13
|
} & {
|
|
14
14
|
[key: `aria-${string}`]: string | number | boolean | undefined;
|
|
15
15
|
[key: `data-${string}`]: string | undefined;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
onconnect?: (element: Element) => void;
|
|
17
|
+
ondisconnect?: (element: Element) => void;
|
|
18
18
|
onrender?: (element: Element) => void;
|
|
19
19
|
} & Record<PropertyKey, unknown>;
|
|
20
20
|
type Effect<T> = () => EffectResponse<T>;
|
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.0.1",
|
|
5
|
+
"@esportsplus/reactivity": "^0.12.1",
|
|
6
|
+
"@esportsplus/tasks": "^0.2.0",
|
|
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.14",
|
|
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';
|
|
@@ -15,11 +15,7 @@ let attributes: Record<string, unknown> = {},
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
function attribute(element: Element, name: string, value: unknown) {
|
|
18
|
-
if (value === false || value == null) {
|
|
19
|
-
value = '';
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (value === '') {
|
|
18
|
+
if (value === '' || value === false || value == null) {
|
|
23
19
|
removeAttribute.call(element, name);
|
|
24
20
|
}
|
|
25
21
|
else if (name === 'class') {
|
|
@@ -46,7 +42,7 @@ function set(element: Element, value: unknown, name: string, wait = false) {
|
|
|
46
42
|
else {
|
|
47
43
|
let id = ('e' + store(element)[key]++);
|
|
48
44
|
|
|
49
|
-
|
|
45
|
+
ondisconnect(
|
|
50
46
|
element,
|
|
51
47
|
effect(() => {
|
|
52
48
|
let v = (value as Function)(element);
|
|
@@ -181,18 +177,11 @@ const spread = function (element: Element, attributes: Attributes | Attributes[]
|
|
|
181
177
|
for (let i = 0, n = attributes.length; i < n; i++) {
|
|
182
178
|
let attrs = attributes[i];
|
|
183
179
|
|
|
184
|
-
if (!isObject(attrs)) {
|
|
185
|
-
throw new Error('@esportsplus/template: attributes must be of type `Attributes` or `Attributes[]`; Received ' + JSON.stringify(attributes));
|
|
186
|
-
}
|
|
187
|
-
|
|
188
180
|
for (let name in attrs) {
|
|
189
181
|
set(element, attrs[name], name, true);
|
|
190
182
|
}
|
|
191
183
|
}
|
|
192
184
|
}
|
|
193
|
-
else {
|
|
194
|
-
throw new Error('@esportsplus/template: attributes must be of type `Attributes` or `Attributes[]`; Received ' + JSON.stringify(attributes));
|
|
195
|
-
}
|
|
196
185
|
};
|
|
197
186
|
|
|
198
187
|
|
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
|
|
|
@@ -25,7 +25,7 @@ let capture = new Set<`on${string}`>(['onblur', 'onfocus', 'onscroll']),
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
export default (element: Element, event: `on${string}`, listener: Function): void => {
|
|
28
|
-
if (event === '
|
|
28
|
+
if (event === 'onconnect') {
|
|
29
29
|
let interval = setInterval(() => {
|
|
30
30
|
retry--;
|
|
31
31
|
|
|
@@ -42,8 +42,8 @@ export default (element: Element, event: `on${string}`, listener: Function): voi
|
|
|
42
42
|
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
|
-
else if (event === '
|
|
46
|
-
|
|
45
|
+
else if (event === 'ondisconnect') {
|
|
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
|
@@ -4,9 +4,10 @@ import { RENDERABLE, RENDERABLE_REACTIVE, SLOT_CLEANUP } from './constants';
|
|
|
4
4
|
import { hydrate } from './html';
|
|
5
5
|
import { Element, Elements, RenderableReactive, RenderableTemplate } from './types';
|
|
6
6
|
import { firstChild, nextSibling, nodeValue, raf, text } from './utilities'
|
|
7
|
+
import queue from '@esportsplus/queue';
|
|
7
8
|
|
|
8
9
|
|
|
9
|
-
let cleanup
|
|
10
|
+
let cleanup = queue<VoidFunction[]>(),
|
|
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();
|
|
@@ -112,10 +113,12 @@ function schedule() {
|
|
|
112
113
|
|
|
113
114
|
raf.add(() => {
|
|
114
115
|
try {
|
|
115
|
-
let
|
|
116
|
+
let fns;
|
|
116
117
|
|
|
117
|
-
while (
|
|
118
|
-
|
|
118
|
+
while (fns = cleanup.next()) {
|
|
119
|
+
for (let i = 0, n = fns.length; i < n; i++) {
|
|
120
|
+
fns[i]();
|
|
121
|
+
}
|
|
119
122
|
}
|
|
120
123
|
}
|
|
121
124
|
catch(e) { }
|
|
@@ -136,7 +139,7 @@ class Slot {
|
|
|
136
139
|
|
|
137
140
|
|
|
138
141
|
constructor(marker: Element) {
|
|
139
|
-
|
|
142
|
+
ondisconnect(marker, () => this.clear());
|
|
140
143
|
|
|
141
144
|
this.marker = marker;
|
|
142
145
|
this.nodes = [];
|
|
@@ -190,7 +193,7 @@ class Slot {
|
|
|
190
193
|
|
|
191
194
|
render(input: unknown) {
|
|
192
195
|
if (isFunction(input)) {
|
|
193
|
-
|
|
196
|
+
ondisconnect(
|
|
194
197
|
this.marker,
|
|
195
198
|
effect(() => {
|
|
196
199
|
let v = (input as Function)();
|
|
@@ -256,7 +259,7 @@ class Slot {
|
|
|
256
259
|
}
|
|
257
260
|
|
|
258
261
|
|
|
259
|
-
const
|
|
262
|
+
const ondisconnect = (element: Element, fn: VoidFunction) => {
|
|
260
263
|
( element[SLOT_CLEANUP] ??= [] ).push(fn);
|
|
261
264
|
};
|
|
262
265
|
|
|
@@ -264,4 +267,4 @@ const onRemove = (element: Element, fn: VoidFunction) => {
|
|
|
264
267
|
export default (marker: Element, value: unknown) => {
|
|
265
268
|
return new Slot(marker).render(value);
|
|
266
269
|
};
|
|
267
|
-
export {
|
|
270
|
+
export { ondisconnect, Slot };
|
package/src/types.ts
CHANGED
|
@@ -16,8 +16,8 @@ type Attributes = {
|
|
|
16
16
|
} & {
|
|
17
17
|
[key: `aria-${string}`]: string | number | boolean | undefined;
|
|
18
18
|
[key: `data-${string}`]: string | undefined;
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
onconnect?: (element: Element) => void;
|
|
20
|
+
ondisconnect?: (element: Element) => void;
|
|
21
21
|
// Rendered in fragment
|
|
22
22
|
// - Used to retrieve reference to the element
|
|
23
23
|
onrender?: (element: Element) => void;
|