@esportsplus/template 0.22.0 → 0.22.2

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.
@@ -26,7 +26,7 @@ const NODE_WHITELIST = {
26
26
  'track': NODE_VOID,
27
27
  'wbr': NODE_VOID
28
28
  };
29
- const REGEX_EMPTY_TEXT_NODES = /(>|})\s+(<|{)/g;
29
+ const REGEX_EMPTY_TEXT_NODES = /(>|}|)\s+(<|{|\s)/g;
30
30
  const REGEX_EVENTS = /(?:\s*on[\w-:]+\s*=(?:\s*["'][^"']*["'])*)/g;
31
31
  const REGEX_SLOT_ATTRIBUTES = /<[\w-]+([^><]*{{\$}}[^><]*)>/g;
32
32
  const REGEX_SLOT_NODES = /<([\w-]+|[\/!])(?:([^><]*{{\$}}[^><]*)|(?:[^><]*))?>|{{\$}}/g;
@@ -4,16 +4,21 @@ import parser from './parser.js';
4
4
  const html = (literals, ...values) => {
5
5
  let { fragment, slots } = parser.parse(literals), clone = cloneNode.call(fragment, true);
6
6
  if (slots !== null) {
7
- let node, nodePath;
7
+ let e, p;
8
8
  for (let i = slots.length - 1; i >= 0; i--) {
9
- let { fn, path } = slots[i];
10
- if (nodePath !== path) {
11
- node = clone;
9
+ let { fn, name, path } = slots[i];
10
+ if (p !== path) {
11
+ e = clone;
12
12
  for (let i = 0, n = path.length; i < n; i++) {
13
- node = path[i].call(node);
13
+ e = path[i].call(e);
14
14
  }
15
15
  }
16
- fn(node, values[i]);
16
+ if (name === null) {
17
+ fn(e, values[i]);
18
+ }
19
+ else {
20
+ fn(e, name, values[i]);
21
+ }
17
22
  }
18
23
  }
19
24
  return clone;
package/build/types.d.ts CHANGED
@@ -4,7 +4,7 @@ import { firstChild } from './utilities/node.js';
4
4
  import attributes from './attributes.js';
5
5
  import slot from './slot/index.js';
6
6
  import html from './html/index.js';
7
- type Attribute = Effect<Primitive | Primitive[]> | (<T>(...args: T[]) => void) | Primitive;
7
+ type Attribute = Effect<Primitive | Primitive[]> | ((...args: any[]) => void) | Primitive;
8
8
  type Attributes<T extends HTMLElement = Element> = {
9
9
  [key: `aria-${string}`]: string | number | boolean | undefined;
10
10
  [key: `data-${string}`]: string | undefined;
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "private": false,
15
15
  "type": "module",
16
16
  "types": "./build/index.d.ts",
17
- "version": "0.22.0",
17
+ "version": "0.22.2",
18
18
  "scripts": {
19
19
  "build": "tsc && tsc-alias",
20
20
  "-": "-"
package/src/constants.ts CHANGED
@@ -40,7 +40,7 @@ const NODE_WHITELIST: Record<string, number> = {
40
40
  };
41
41
 
42
42
 
43
- const REGEX_EMPTY_TEXT_NODES = /(>|})\s+(<|{)/g;
43
+ const REGEX_EMPTY_TEXT_NODES = /(>|}|)\s+(<|{|\s)/g;
44
44
 
45
45
  const REGEX_EVENTS = /(?:\s*on[\w-:]+\s*=(?:\s*["'][^"']*["'])*)/g;
46
46
 
package/src/html/index.ts CHANGED
@@ -3,6 +3,8 @@ import { RENDERABLE, RENDERABLE_HTML_REACTIVE_ARRAY } from '~/constants';
3
3
  import { Attribute, Attributes, Renderable, RenderableReactive } from '~/types';
4
4
  import { cloneNode } from '~/utilities/node';
5
5
  import parser from './parser';
6
+ import attributes from '~/attributes';
7
+ import slot from '~/slot';
6
8
 
7
9
 
8
10
  type Values<T> = Attribute | Attributes<any> | Renderable<T>;
@@ -13,21 +15,25 @@ const html = <T>(literals: TemplateStringsArray, ...values: (Values<T> | Values<
13
15
  clone = cloneNode.call(fragment, true);
14
16
 
15
17
  if (slots !== null) {
16
- let node, nodePath;
18
+ let e, p;
17
19
 
18
20
  for (let i = slots.length - 1; i >= 0; i--) {
19
- let { fn, path } = slots[i];
21
+ let { fn, name, path } = slots[i];
20
22
 
21
- if (nodePath !== path) {
22
- node = clone;
23
+ if (p !== path) {
24
+ e = clone;
23
25
 
24
26
  for (let i = 0, n = path.length; i < n; i++) {
25
- node = path[i].call(node);
27
+ e = path[i].call(e);
26
28
  }
27
29
  }
28
30
 
29
- // @ts-ignore
30
- fn(node, values[i]);
31
+ if (name === null) {
32
+ (fn as typeof attributes.spread | typeof slot)(e, values[i] as any);
33
+ }
34
+ else {
35
+ (fn as typeof attributes.set)(e, name, values[i]);
36
+ }
31
37
  }
32
38
  }
33
39
 
package/src/types.ts CHANGED
@@ -6,7 +6,7 @@ import slot from './slot';
6
6
  import html from './html';
7
7
 
8
8
 
9
- type Attribute = Effect<Primitive | Primitive[]> | (<T>(...args: T[]) => void) | Primitive;
9
+ type Attribute = Effect<Primitive | Primitive[]> | ((...args: any[]) => void) | Primitive;
10
10
 
11
11
  type Attributes<T extends HTMLElement = Element> = {
12
12
  [key: `aria-${string}`]: string | number | boolean | undefined;