@esportsplus/template 0.15.12 → 0.15.13
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 +4 -4
- package/build/types.d.ts +2 -2
- package/package.json +1 -1
- package/src/attributes.ts +3 -14
- package/src/event.ts +5 -5
- package/src/slot.ts +4 -4
- 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 { onCleanup } 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
|
+
onCleanup(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 { onCleanup } 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
|
+
onCleanup(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
|
+
onCleanup(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 onCleanup: (element: Element, fn: VoidFunction) => void;
|
|
19
19
|
declare const _default: (marker: Element, value: unknown) => Slot;
|
|
20
20
|
export default _default;
|
|
21
|
-
export {
|
|
21
|
+
export { onCleanup, Slot };
|
package/build/slot.js
CHANGED
|
@@ -100,7 +100,7 @@ class Slot {
|
|
|
100
100
|
nodes;
|
|
101
101
|
text = null;
|
|
102
102
|
constructor(marker) {
|
|
103
|
-
|
|
103
|
+
onCleanup(marker, () => this.clear());
|
|
104
104
|
this.marker = marker;
|
|
105
105
|
this.nodes = [];
|
|
106
106
|
}
|
|
@@ -137,7 +137,7 @@ class Slot {
|
|
|
137
137
|
}
|
|
138
138
|
render(input) {
|
|
139
139
|
if (isFunction(input)) {
|
|
140
|
-
|
|
140
|
+
onCleanup(this.marker, effect(() => {
|
|
141
141
|
let v = input();
|
|
142
142
|
if (isFunction(v)) {
|
|
143
143
|
root(() => this.render(v()));
|
|
@@ -181,10 +181,10 @@ class Slot {
|
|
|
181
181
|
return this.nodes.unshift(...after(this.marker, groups));
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
|
-
const
|
|
184
|
+
const onCleanup = (element, fn) => {
|
|
185
185
|
(element[SLOT_CLEANUP] ??= []).push(fn);
|
|
186
186
|
};
|
|
187
187
|
export default (marker, value) => {
|
|
188
188
|
return new Slot(marker).render(value);
|
|
189
189
|
};
|
|
190
|
-
export {
|
|
190
|
+
export { onCleanup, 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
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 { onCleanup } 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
|
+
onCleanup(
|
|
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 { onCleanup } 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
|
+
onCleanup(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
|
+
onCleanup(element, () => {
|
|
74
74
|
if (--controller.listeners) {
|
|
75
75
|
return;
|
|
76
76
|
}
|
package/src/slot.ts
CHANGED
|
@@ -136,7 +136,7 @@ class Slot {
|
|
|
136
136
|
|
|
137
137
|
|
|
138
138
|
constructor(marker: Element) {
|
|
139
|
-
|
|
139
|
+
onCleanup(marker, () => this.clear());
|
|
140
140
|
|
|
141
141
|
this.marker = marker;
|
|
142
142
|
this.nodes = [];
|
|
@@ -190,7 +190,7 @@ class Slot {
|
|
|
190
190
|
|
|
191
191
|
render(input: unknown) {
|
|
192
192
|
if (isFunction(input)) {
|
|
193
|
-
|
|
193
|
+
onCleanup(
|
|
194
194
|
this.marker,
|
|
195
195
|
effect(() => {
|
|
196
196
|
let v = (input as Function)();
|
|
@@ -256,7 +256,7 @@ class Slot {
|
|
|
256
256
|
}
|
|
257
257
|
|
|
258
258
|
|
|
259
|
-
const
|
|
259
|
+
const onCleanup = (element: Element, fn: VoidFunction) => {
|
|
260
260
|
( element[SLOT_CLEANUP] ??= [] ).push(fn);
|
|
261
261
|
};
|
|
262
262
|
|
|
@@ -264,4 +264,4 @@ const onRemove = (element: Element, fn: VoidFunction) => {
|
|
|
264
264
|
export default (marker: Element, value: unknown) => {
|
|
265
265
|
return new Slot(marker).render(value);
|
|
266
266
|
};
|
|
267
|
-
export {
|
|
267
|
+
export { onCleanup, 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;
|