@esportsplus/template 0.19.1 → 0.19.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.
- package/build/html/index.d.ts +3 -2
- package/build/index.d.ts +1 -1
- package/build/types.d.ts +3 -5
- package/package.json +1 -1
- package/src/html/index.ts +5 -2
- package/src/index.ts +1 -1
- package/src/types.ts +3 -9
package/build/html/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ReactiveArray } from '@esportsplus/reactivity';
|
|
2
|
-
import {
|
|
2
|
+
import { Attributes, Renderable, RenderableReactive } from '../types.js';
|
|
3
|
+
type Values<T = unknown> = Attributes | Attributes[] | Readonly<Attributes> | Readonly<Attributes[]> | Renderable<T>;
|
|
3
4
|
declare const html: {
|
|
4
|
-
(literals: TemplateStringsArray, ...values: (
|
|
5
|
+
(literals: TemplateStringsArray, ...values: (Values | Values[])[]): Node;
|
|
5
6
|
reactive<T>(array: ReactiveArray<T[]>, template: RenderableReactive["template"]): RenderableReactive;
|
|
6
7
|
};
|
|
7
8
|
export default html;
|
package/build/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default as html } from './html/index.js';
|
|
2
2
|
export { default as render } from './render.js';
|
|
3
3
|
export { default as svg } from './svg.js';
|
|
4
|
-
export type { Attributes, Element, Renderable
|
|
4
|
+
export type { Attributes, Element, Renderable } from './types.js';
|
package/build/types.d.ts
CHANGED
|
@@ -17,17 +17,15 @@ type Attributes = {
|
|
|
17
17
|
ondisconnect?: (element: Element) => void;
|
|
18
18
|
onrender?: (element: Element) => void;
|
|
19
19
|
} & Record<PropertyKey, unknown>;
|
|
20
|
-
type Effect<T> = () =>
|
|
21
|
-
type EffectResponse<T> = T extends [] ? (Primitive | Renderable)[] : Primitive | Renderable;
|
|
20
|
+
type Effect<T> = () => T extends [] ? Renderable[] : Renderable;
|
|
22
21
|
type Element = HTMLElement & Attributes & Record<PropertyKey, unknown>;
|
|
23
22
|
type Primitive = bigint | boolean | null | number | string | undefined;
|
|
24
|
-
type Renderable = DocumentFragment | Node | NodeList | Primitive | RenderableReactive | Renderable[];
|
|
23
|
+
type Renderable<T = unknown> = DocumentFragment | Effect<T> | Node | NodeList | Primitive | RenderableReactive | Renderable[];
|
|
25
24
|
type RenderableReactive = Readonly<{
|
|
26
25
|
[RENDERABLE]: typeof RENDERABLE_HTML_REACTIVE_ARRAY;
|
|
27
26
|
array: ReactiveArray<unknown[]>;
|
|
28
27
|
template: (this: ReactiveArray<unknown[]>, ...args: Parameters<Parameters<ReactiveArray<unknown[]>['map']>[0]>) => ReturnType<typeof html>;
|
|
29
28
|
}>;
|
|
30
|
-
type RenderableValue<T = unknown> = Attributes | Readonly<Attributes> | Readonly<Attributes[]> | Effect<T> | Primitive | RenderableReactive;
|
|
31
29
|
type SlotGroup = {
|
|
32
30
|
head: Element;
|
|
33
31
|
tail: Element;
|
|
@@ -42,4 +40,4 @@ type Template = {
|
|
|
42
40
|
slot: number;
|
|
43
41
|
}[] | null;
|
|
44
42
|
};
|
|
45
|
-
export type { Attributes, Effect, Element, Renderable, RenderableReactive,
|
|
43
|
+
export type { Attributes, Effect, Element, Renderable, RenderableReactive, SlotGroup, Template };
|
package/package.json
CHANGED
package/src/html/index.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { ReactiveArray } from '@esportsplus/reactivity';
|
|
2
2
|
import { RENDERABLE, RENDERABLE_HTML_REACTIVE_ARRAY } from '~/constants';
|
|
3
|
-
import {
|
|
3
|
+
import { Attributes, Renderable, RenderableReactive } from '~/types';
|
|
4
4
|
import { cloneNode } from '~/utilities/node';
|
|
5
5
|
import parser from './parser';
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
type Values<T = unknown> = Attributes | Attributes[] | Readonly<Attributes> | Readonly<Attributes[]> | Renderable<T>;
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
const html = (literals: TemplateStringsArray, ...values: (Values | Values[])[]) => {
|
|
9
12
|
let { fragment, slots } = parser.parse(literals),
|
|
10
13
|
clone = cloneNode.call(fragment, true);
|
|
11
14
|
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default as html } from './html';
|
|
2
2
|
export { default as render } from './render';
|
|
3
3
|
export { default as svg } from './svg';
|
|
4
|
-
export type { Attributes, Element, Renderable
|
|
4
|
+
export type { Attributes, Element, Renderable } from './types';
|
package/src/types.ts
CHANGED
|
@@ -18,14 +18,10 @@ type Attributes = {
|
|
|
18
18
|
[key: `data-${string}`]: string | undefined;
|
|
19
19
|
onconnect?: (element: Element) => void;
|
|
20
20
|
ondisconnect?: (element: Element) => void;
|
|
21
|
-
// Rendered in fragment
|
|
22
|
-
// - Used to retrieve reference to the element
|
|
23
21
|
onrender?: (element: Element) => void;
|
|
24
22
|
} & Record<PropertyKey, unknown>;
|
|
25
23
|
|
|
26
|
-
type Effect<T> = () =>
|
|
27
|
-
|
|
28
|
-
type EffectResponse<T> = T extends [] ? (Primitive | Renderable)[] : Primitive | Renderable;
|
|
24
|
+
type Effect<T> = () => T extends [] ? Renderable[] : Renderable;
|
|
29
25
|
|
|
30
26
|
type Element = HTMLElement & Attributes & Record<PropertyKey, unknown>;
|
|
31
27
|
|
|
@@ -33,7 +29,7 @@ type Element = HTMLElement & Attributes & Record<PropertyKey, unknown>;
|
|
|
33
29
|
// - Importing from ^ causes 'cannot be named without a reference to...' error
|
|
34
30
|
type Primitive = bigint | boolean | null | number | string | undefined;
|
|
35
31
|
|
|
36
|
-
type Renderable = DocumentFragment | Node | NodeList | Primitive | RenderableReactive | Renderable[];
|
|
32
|
+
type Renderable<T = unknown> = DocumentFragment | Effect<T> | Node | NodeList | Primitive | RenderableReactive | Renderable[];
|
|
37
33
|
|
|
38
34
|
type RenderableReactive = Readonly<{
|
|
39
35
|
[RENDERABLE]: typeof RENDERABLE_HTML_REACTIVE_ARRAY;
|
|
@@ -44,8 +40,6 @@ type RenderableReactive = Readonly<{
|
|
|
44
40
|
) => ReturnType<typeof html>;
|
|
45
41
|
}>;
|
|
46
42
|
|
|
47
|
-
type RenderableValue<T = unknown> = Attributes | Readonly<Attributes> | Readonly<Attributes[]> | Effect<T> | Primitive | RenderableReactive;
|
|
48
|
-
|
|
49
43
|
type SlotGroup = {
|
|
50
44
|
head: Element;
|
|
51
45
|
tail: Element;
|
|
@@ -72,7 +66,7 @@ type Template = {
|
|
|
72
66
|
export type {
|
|
73
67
|
Attributes,
|
|
74
68
|
Effect, Element,
|
|
75
|
-
Renderable, RenderableReactive,
|
|
69
|
+
Renderable, RenderableReactive,
|
|
76
70
|
SlotGroup,
|
|
77
71
|
Template
|
|
78
72
|
};
|