wrec 0.21.4 → 0.22.0
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/dist/wrec-ssr.d.ts +79 -0
- package/dist/wrec-ssr.es.js +71 -0
- package/dist/wrec.d.ts +8 -3
- package/dist/wrec.es.js +351 -377
- package/package.json +7 -3
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export declare type ChangeListener = {
|
|
2
|
+
changed: (statePath: string, componentProperty: string, newValue: unknown, oldValue: unknown, state: WrecState) => void;
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
export declare function createElement(name: string, attributes: StringToString, innerHTML: string): HTMLElement;
|
|
6
|
+
|
|
7
|
+
export declare function css(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
8
|
+
|
|
9
|
+
export declare function html(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
10
|
+
|
|
11
|
+
declare const HTMLElementBase: {
|
|
12
|
+
new (): HTMLElement;
|
|
13
|
+
prototype: HTMLElement;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
declare type LooseObject = Record<string, unknown>;
|
|
17
|
+
|
|
18
|
+
declare type StringToAny = Record<string, any>;
|
|
19
|
+
|
|
20
|
+
declare type StringToString = Record<string, string>;
|
|
21
|
+
|
|
22
|
+
export declare abstract class Wrec extends HTMLElementBase implements ChangeListener {
|
|
23
|
+
#private;
|
|
24
|
+
private static attrToPropMap;
|
|
25
|
+
private static propToAttrMap;
|
|
26
|
+
static context: {};
|
|
27
|
+
static css: string;
|
|
28
|
+
private static elementName;
|
|
29
|
+
static formAssociated: boolean;
|
|
30
|
+
static html: string;
|
|
31
|
+
static properties: StringToAny;
|
|
32
|
+
private static propToComputedMap;
|
|
33
|
+
private static propToExprsMap;
|
|
34
|
+
private static template;
|
|
35
|
+
[key: string]: any;
|
|
36
|
+
static define(elementName: string): void;
|
|
37
|
+
constructor();
|
|
38
|
+
attributeChangedCallback(attrName: string, oldValue: string | null, newValue: string | null): void;
|
|
39
|
+
batchSet(changes: StringToAny): void;
|
|
40
|
+
private static buildHTML;
|
|
41
|
+
changed(_statePath: string, componentProp: string, newValue: unknown): void;
|
|
42
|
+
connectedCallback(): void;
|
|
43
|
+
disconnectedCallback(): void;
|
|
44
|
+
dispatch(name: string, detail: any): void;
|
|
45
|
+
displayIfSet(value: any, display?: string): string;
|
|
46
|
+
formAssociatedCallback(): void;
|
|
47
|
+
formResetCallback(): void;
|
|
48
|
+
private static getAttrName;
|
|
49
|
+
static getPropName(attrName: string): string;
|
|
50
|
+
static get observedAttributes(): string[];
|
|
51
|
+
propertyChangedCallback(_propName: string, _oldValue: unknown, _newValue: unknown): void;
|
|
52
|
+
setAttributeSafe(name: string, value: string): void;
|
|
53
|
+
setFormValue(propName: string, value: string): void;
|
|
54
|
+
static ssr(properties?: StringToAny): void;
|
|
55
|
+
/**
|
|
56
|
+
* @param state - WrecState object
|
|
57
|
+
* @param map - object whose keys are state properties and
|
|
58
|
+
* whose values are component properties
|
|
59
|
+
*/
|
|
60
|
+
useState(state: WrecState, map?: StringToString): void;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export declare class WrecState {
|
|
64
|
+
#private;
|
|
65
|
+
static get(name: string): WrecState | undefined;
|
|
66
|
+
[key: string]: unknown;
|
|
67
|
+
constructor(name: string, persist: boolean, initial?: LooseObject);
|
|
68
|
+
/**
|
|
69
|
+
* @param listener - object that has a "changed" method
|
|
70
|
+
* @param map - map from state property paths to component properties
|
|
71
|
+
*/
|
|
72
|
+
addListener(listener: ChangeListener, map?: Record<string, string>): void;
|
|
73
|
+
addProperty(propName: string, initialValue: unknown): void;
|
|
74
|
+
get id(): symbol;
|
|
75
|
+
log(): void;
|
|
76
|
+
removeListener(listener: ChangeListener): void;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { }
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { HTMLElement as y, parse as H, NodeType as T, TextNode as M } from "node-html-parser";
|
|
2
|
+
import { Wrec as R } from "./wrec.es.js";
|
|
3
|
+
import { WrecState as I, createElement as C, css as D, html as F } from "./wrec.es.js";
|
|
4
|
+
const b = "a-zA-Z_$", S = b + "0-9", h = `[${b}][${S}]*`, N = new RegExp(`this\\.${h}(\\.${h})*`), _ = 5, O = (c) => c.substring(_).split(".")[0];
|
|
5
|
+
typeof window > "u" && !globalThis.HTMLElement && (globalThis.HTMLElement = y);
|
|
6
|
+
typeof window > "u" && !globalThis.customElements && (globalThis.customElements = {
|
|
7
|
+
get: (c) => {
|
|
8
|
+
},
|
|
9
|
+
getName: () => "",
|
|
10
|
+
define: () => {
|
|
11
|
+
},
|
|
12
|
+
upgrade: () => {
|
|
13
|
+
},
|
|
14
|
+
whenDefined: () => Promise.reject(new Error("customElements is not available"))
|
|
15
|
+
});
|
|
16
|
+
R.ssr = function(o = {}) {
|
|
17
|
+
let l = "";
|
|
18
|
+
const m = Object.keys(o);
|
|
19
|
+
m.sort();
|
|
20
|
+
for (const t of m) {
|
|
21
|
+
const n = this.getAttrName(t);
|
|
22
|
+
l += ` ${n}="${o[t]}"`;
|
|
23
|
+
}
|
|
24
|
+
const u = this.properties;
|
|
25
|
+
for (const [t, n] of Object.entries(u))
|
|
26
|
+
if (o[t] === void 0) {
|
|
27
|
+
const { value: s } = n;
|
|
28
|
+
s !== void 0 && (o[t] = s);
|
|
29
|
+
}
|
|
30
|
+
function f(t) {
|
|
31
|
+
return new Function("return " + t).call(o);
|
|
32
|
+
}
|
|
33
|
+
function E(t) {
|
|
34
|
+
const { attributes: n } = t;
|
|
35
|
+
for (const [e, i] of Object.entries(n))
|
|
36
|
+
if (N.test(i)) {
|
|
37
|
+
const r = f(i), a = O(e), v = u[a]?.value ?? "";
|
|
38
|
+
r === v ? t.removeAttribute(e) : t.setAttribute(e, String(r));
|
|
39
|
+
}
|
|
40
|
+
const { childNodes: s } = t;
|
|
41
|
+
s.forEach((e, i) => {
|
|
42
|
+
if (e.nodeType === T.ELEMENT_NODE)
|
|
43
|
+
E(e);
|
|
44
|
+
else if (e.nodeType === T.COMMENT_NODE) {
|
|
45
|
+
const r = e.textContent ?? "";
|
|
46
|
+
if (N.test(r)) {
|
|
47
|
+
const a = f(r);
|
|
48
|
+
s[i] = new M(String(a));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const g = this.buildHTML(), w = H(g, { comment: !0 }), { children: d } = w;
|
|
54
|
+
d.forEach(E);
|
|
55
|
+
const $ = d.map((t) => t.outerHTML).join(`
|
|
56
|
+
`), p = this.elementName;
|
|
57
|
+
return `
|
|
58
|
+
<${p}${l}>
|
|
59
|
+
<template shadowrootmode="open">
|
|
60
|
+
${$}
|
|
61
|
+
</template>
|
|
62
|
+
</${p}>
|
|
63
|
+
`;
|
|
64
|
+
};
|
|
65
|
+
export {
|
|
66
|
+
R as Wrec,
|
|
67
|
+
I as WrecState,
|
|
68
|
+
C as createElement,
|
|
69
|
+
D as css,
|
|
70
|
+
F as html
|
|
71
|
+
};
|
package/dist/wrec.d.ts
CHANGED
|
@@ -8,13 +8,18 @@ export declare function css(strings: TemplateStringsArray, ...values: unknown[])
|
|
|
8
8
|
|
|
9
9
|
export declare function html(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
10
10
|
|
|
11
|
+
declare const HTMLElementBase: {
|
|
12
|
+
new (): HTMLElement;
|
|
13
|
+
prototype: HTMLElement;
|
|
14
|
+
};
|
|
15
|
+
|
|
11
16
|
declare type LooseObject = Record<string, unknown>;
|
|
12
17
|
|
|
13
18
|
declare type StringToAny = Record<string, any>;
|
|
14
19
|
|
|
15
20
|
declare type StringToString = Record<string, string>;
|
|
16
21
|
|
|
17
|
-
export declare abstract class Wrec extends
|
|
22
|
+
export declare abstract class Wrec extends HTMLElementBase implements ChangeListener {
|
|
18
23
|
#private;
|
|
19
24
|
private static attrToPropMap;
|
|
20
25
|
private static propToAttrMap;
|
|
@@ -30,7 +35,7 @@ export declare abstract class Wrec extends HTMLElement implements ChangeListener
|
|
|
30
35
|
[key: string]: any;
|
|
31
36
|
static define(elementName: string): void;
|
|
32
37
|
constructor();
|
|
33
|
-
attributeChangedCallback(attrName: string, oldValue: string, newValue: string |
|
|
38
|
+
attributeChangedCallback(attrName: string, oldValue: string | null, newValue: string | null): void;
|
|
34
39
|
batchSet(changes: StringToAny): void;
|
|
35
40
|
private static buildHTML;
|
|
36
41
|
changed(_statePath: string, componentProp: string, newValue: unknown): void;
|
|
@@ -46,7 +51,7 @@ export declare abstract class Wrec extends HTMLElement implements ChangeListener
|
|
|
46
51
|
propertyChangedCallback(_propName: string, _oldValue: unknown, _newValue: unknown): void;
|
|
47
52
|
setAttributeSafe(name: string, value: string): void;
|
|
48
53
|
setFormValue(propName: string, value: string): void;
|
|
49
|
-
static ssr(properties?: StringToAny):
|
|
54
|
+
static ssr(properties?: StringToAny): void;
|
|
50
55
|
/**
|
|
51
56
|
* @param state - WrecState object
|
|
52
57
|
* @param map - object whose keys are state properties and
|