@esportsplus/template 0.26.2 → 0.26.4

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.
@@ -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], type = typeof value;
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 && type === 'string') {
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 && type === 'string') {
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, type = typeof value;
130
- if (type === 'function') {
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 (type !== 'object') {
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++) {
@@ -40,15 +40,18 @@ class EffectSlot {
40
40
  }
41
41
  }
42
42
  update(value) {
43
- if (this.group) {
44
- remove(this.group);
43
+ let { anchor, group, textnode } = this;
44
+ if (group) {
45
+ remove(group);
45
46
  this.group = null;
46
47
  }
47
48
  if (value == null || value === false) {
48
49
  value = '';
49
50
  }
50
- let { anchor, textnode } = this;
51
- if (typeof value !== 'object') {
51
+ if (typeof value === 'function') {
52
+ this.update(value());
53
+ }
54
+ else if (typeof value !== 'object') {
52
55
  if (textnode) {
53
56
  nodeValue.call(textnode, String(value));
54
57
  if (!textnode.isConnected) {
@@ -1,2 +1,2 @@
1
1
  import { Element } from '../types.js';
2
- export default function render(anchor: Element, input: unknown): Node;
2
+ export default function render(anchor: Element, value: unknown): Node;
@@ -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, input) {
8
- if (input == null || input === false || input === '') {
7
+ export default function render(anchor, value) {
8
+ if (value == null || value === false || value === '') {
9
9
  return EMPTY_FRAGMENT;
10
10
  }
11
- if (typeof input !== 'object') {
12
- return text(input);
11
+ if (typeof value !== 'object') {
12
+ return text(value);
13
13
  }
14
- if (RENDERABLE in input) {
15
- return array(anchor, input);
14
+ if (RENDERABLE in value) {
15
+ return array(anchor, value);
16
16
  }
17
- if ('nodeType' in input) {
18
- return input;
17
+ if ('nodeType' in value) {
18
+ return value;
19
19
  }
20
- if (isArray(input)) {
20
+ if (isArray(value)) {
21
21
  let fragment = cloneNode.call(EMPTY_FRAGMENT);
22
- for (let i = 0, n = input.length; i < n; i++) {
23
- append.call(fragment, render(anchor, input[i]));
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 (input instanceof NodeList) {
29
- let fragment = cloneNode.call(EMPTY_FRAGMENT), nodes = Array.from(input);
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(input);
35
+ return text(value);
36
36
  }
37
37
  ;
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.18.0",
6
- "@esportsplus/tasks": "^0.2.1",
7
- "@esportsplus/utilities": "^0.22.2"
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.2",
17
+ "version": "0.26.4",
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 && type === 'string') {
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 && type === 'string') {
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 (type === 'function') {
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 (type !== 'object') {
244
+ if (typeof value !== 'object') {
247
245
  // Skip isArray when possible
248
246
  }
249
247
  else if (isArray(value)) {
@@ -53,9 +53,11 @@ class EffectSlot {
53
53
  }
54
54
  }
55
55
 
56
- update(value: unknown) {
57
- if (this.group) {
58
- remove(this.group);
56
+ update(value: unknown): void {
57
+ let { anchor, group, textnode } = this;
58
+
59
+ if (group) {
60
+ remove(group);
59
61
  this.group = null;
60
62
  }
61
63
 
@@ -63,9 +65,10 @@ class EffectSlot {
63
65
  value = '';
64
66
  }
65
67
 
66
- let { anchor, textnode } = this;
67
-
68
- if (typeof value !== 'object') {
68
+ if (typeof value === 'function') {
69
+ this.update( value() );
70
+ }
71
+ else if (typeof value !== 'object') {
69
72
  if (textnode) {
70
73
  nodeValue.call(textnode, String(value));
71
74
 
@@ -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, input: unknown): Node {
11
- if (input == null || input === false || input === '') {
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 input !== 'object') {
16
- return text(input as any);
15
+ if (typeof value !== 'object') {
16
+ return text(value as any);
17
17
  }
18
18
 
19
- if (RENDERABLE in input) {
20
- return array(anchor, input as RenderableReactive<unknown>);
19
+ if (RENDERABLE in value) {
20
+ return array(anchor, value as RenderableReactive<unknown>);
21
21
  }
22
22
 
23
- if ('nodeType' in input) {
24
- return input as Node;
23
+ if ('nodeType' in value) {
24
+ return value as Node;
25
25
  }
26
26
 
27
- if (isArray(input)) {
27
+ if (isArray(value)) {
28
28
  let fragment = cloneNode.call(EMPTY_FRAGMENT);
29
29
 
30
- for (let i = 0, n = (input as unknown[]).length; i < n; i++) {
31
- append.call(fragment, render(anchor, (input as unknown[])[i]));
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 (input instanceof NodeList) {
38
+ if (value instanceof NodeList) {
39
39
  let fragment = cloneNode.call(EMPTY_FRAGMENT),
40
- nodes = Array.from(input as NodeList);
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(input as any);
49
+ return text(value as any);
50
50
  };