peryl 1.5.2 → 1.5.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.
- package/README.md +31 -17
- package/demo/hsml-app-form-validation_demo.html +1 -0
- package/demo/hsml-app-form-validation_demo.ts +22 -23
- package/demo/hsml-app-form_demo.html +1 -0
- package/demo/hsml-app-form_demo.ts +24 -20
- package/demo/hsml-app-test_demo.ts +36 -41
- package/demo/hsml-app-tictactoe_demo.ts +17 -16
- package/demo/hsml-app_demo.html +1 -0
- package/demo/hsml-app_demo.ts +16 -16
- package/demo/hsml-appel_demo.html +7 -0
- package/demo/hsml-appel_demo.ts +47 -27
- package/demo/hsml-appi_demo.ts +15 -22
- package/demo/hsml_demo.ts +27 -22
- package/demo/js/hsml-app-js-happi_demo.html +28 -21
- package/demo/js/hsml-app-js_demo.html +15 -17
- package/dist/browser-esmodule/encode.js.map +1 -1
- package/dist/browser-esmodule/hsml-app.js +114 -123
- package/dist/browser-esmodule/hsml-app.js.map +1 -1
- package/dist/browser-esmodule/hsml-convert.js.map +1 -1
- package/dist/browser-esmodule/hsml-dom.js +3 -3
- package/dist/browser-esmodule/hsml-dom.js.map +1 -1
- package/dist/browser-esmodule/hsml-h.js.map +1 -1
- package/dist/browser-esmodule/hsml-html.js +2 -2
- package/dist/browser-esmodule/hsml-html.js.map +1 -1
- package/dist/browser-esmodule/hsml-idom.js +5 -5
- package/dist/browser-esmodule/hsml-idom.js.map +1 -1
- package/dist/browser-esmodule/hsml.js.map +1 -1
- package/dist/browser-esmodule/http.js.map +1 -1
- package/dist/browser-esmodule/index.js +118 -127
- package/dist/browser-esmodule/index.js.map +1 -1
- package/dist/browser-esmodule/router.js.map +1 -1
- package/dist/browser-umd/encode.js +1 -1
- package/dist/browser-umd/encode.js.map +1 -1
- package/dist/browser-umd/hsml-app.js +1 -1
- package/dist/browser-umd/hsml-app.js.map +1 -1
- package/dist/browser-umd/hsml-convert.js.map +1 -1
- package/dist/browser-umd/hsml-dom.js +1 -1
- package/dist/browser-umd/hsml-dom.js.map +1 -1
- package/dist/browser-umd/hsml-h.js.map +1 -1
- package/dist/browser-umd/hsml-html.js +1 -1
- package/dist/browser-umd/hsml-html.js.map +1 -1
- package/dist/browser-umd/hsml-idom.js +1 -1
- package/dist/browser-umd/hsml-idom.js.map +1 -1
- package/dist/browser-umd/hsml.js.map +1 -1
- package/dist/browser-umd/http.js +1 -1
- package/dist/browser-umd/http.js.map +1 -1
- package/dist/browser-umd/index.js +1 -1
- package/dist/browser-umd/index.js.map +1 -1
- package/dist/browser-umd/router.js +1 -1
- package/dist/browser-umd/router.js.map +1 -1
- package/dist/browser-umd/validators-moment.js +1 -1
- package/dist/browser-umd/validators-moment.js.map +1 -1
- package/dist/browser-umd/validators-numeral.js.map +1 -1
- package/dist/demo/encode_demo.ce182166.js.map +1 -1
- package/dist/demo/encode_demo.f40a44eb.js.map +1 -1
- package/dist/demo/hsml-app-form-validation_demo.8e406f15.js +2 -0
- package/dist/demo/hsml-app-form-validation_demo.8e406f15.js.map +1 -0
- package/dist/demo/hsml-app-form-validation_demo.9a95cff3.js +2 -0
- package/dist/demo/hsml-app-form-validation_demo.9a95cff3.js.map +1 -0
- package/dist/demo/hsml-app-form-validation_demo.c6856b02.js +2 -0
- package/dist/demo/hsml-app-form-validation_demo.c6856b02.js.map +1 -0
- package/dist/demo/hsml-app-form-validation_demo.fdcc0b2d.js +2 -0
- package/dist/demo/hsml-app-form-validation_demo.fdcc0b2d.js.map +1 -0
- package/dist/demo/hsml-app-form-validation_demo.html +1 -1
- package/dist/demo/hsml-app-form_demo.950b2a09.js +2 -0
- package/dist/demo/hsml-app-form_demo.950b2a09.js.map +1 -0
- package/dist/demo/hsml-app-form_demo.ea3af725.js +2 -0
- package/dist/demo/hsml-app-form_demo.ea3af725.js.map +1 -0
- package/dist/demo/hsml-app-form_demo.html +1 -1
- package/dist/demo/hsml-app-test_demo.36a210b8.js +2 -0
- package/dist/demo/hsml-app-test_demo.36a210b8.js.map +1 -0
- package/dist/demo/hsml-app-test_demo.6ab4ea94.js +2 -0
- package/dist/demo/hsml-app-test_demo.6ab4ea94.js.map +1 -0
- package/dist/demo/hsml-app-test_demo.html +1 -1
- package/dist/demo/hsml-app-tictactoe_demo.7a91c368.js +2 -0
- package/dist/demo/hsml-app-tictactoe_demo.7a91c368.js.map +1 -0
- package/dist/demo/hsml-app-tictactoe_demo.97905c2f.js +2 -0
- package/dist/demo/hsml-app-tictactoe_demo.97905c2f.js.map +1 -0
- package/dist/demo/hsml-app-tictactoe_demo.html +1 -1
- package/dist/demo/hsml-app_demo.b5c1d27d.js +2 -0
- package/dist/demo/hsml-app_demo.b5c1d27d.js.map +1 -0
- package/dist/demo/hsml-app_demo.bbebbbcf.js +2 -0
- package/dist/demo/hsml-app_demo.bbebbbcf.js.map +1 -0
- package/dist/demo/hsml-app_demo.html +1 -1
- package/dist/demo/hsml-appel_demo.4d9e135c.js +2 -0
- package/dist/demo/hsml-appel_demo.4d9e135c.js.map +1 -0
- package/dist/demo/hsml-appel_demo.7ddb6fb3.js +2 -0
- package/dist/demo/hsml-appel_demo.7ddb6fb3.js.map +1 -0
- package/dist/demo/hsml-appel_demo.html +1 -1
- package/dist/demo/hsml-appi_demo.e5e28a65.js +2 -0
- package/dist/demo/hsml-appi_demo.e5e28a65.js.map +1 -0
- package/dist/demo/hsml-appi_demo.fef950c1.js +2 -0
- package/dist/demo/hsml-appi_demo.fef950c1.js.map +1 -0
- package/dist/demo/hsml-appi_demo.html +1 -1
- package/dist/demo/hsml-convert_demo.0ea1fa3b.js.map +1 -1
- package/dist/demo/hsml-convert_demo.63e3e7b5.js.map +1 -1
- package/dist/demo/{hsml_demo.ff950ba1.js → hsml_demo.a248689a.js} +2 -2
- package/dist/demo/hsml_demo.a248689a.js.map +1 -0
- package/dist/demo/hsml_demo.eb3b08be.js +2 -0
- package/dist/demo/hsml_demo.eb3b08be.js.map +1 -0
- package/dist/demo/hsml_demo.html +1 -1
- package/dist/demo/http_demo.3e7da3d8.js.map +1 -1
- package/dist/demo/http_demo.8e435f23.js.map +1 -1
- package/dist/demo/i18n_demo.html +1 -1
- package/dist/demo/router_demo.3cfa03aa.js.map +1 -1
- package/dist/demo/router_demo.89ab1681.js.map +1 -1
- package/dist/demo/{validators_demo.252e13a6.js → validators_demo.90ff6001.js} +2 -2
- package/dist/demo/validators_demo.90ff6001.js.map +1 -0
- package/dist/demo/{validators_demo.66893723.js → validators_demo.ef5b2dea.js} +2 -2
- package/dist/demo/validators_demo.ef5b2dea.js.map +1 -0
- package/dist/demo/validators_demo.html +1 -1
- package/dist/encode.js +1 -1
- package/dist/encode.js.map +1 -1
- package/dist/hsml-app.d.ts +63 -42
- package/dist/hsml-app.js +110 -117
- package/dist/hsml-app.js.map +1 -1
- package/dist/hsml-convert.d.ts +3 -3
- package/dist/hsml-convert.js.map +1 -1
- package/dist/hsml-dom.d.ts +2 -2
- package/dist/hsml-dom.js +3 -3
- package/dist/hsml-dom.js.map +1 -1
- package/dist/hsml-h.d.ts +8 -8
- package/dist/hsml-h.js.map +1 -1
- package/dist/hsml-html.d.ts +4 -4
- package/dist/hsml-html.js +2 -2
- package/dist/hsml-html.js.map +1 -1
- package/dist/hsml-idom.d.ts +2 -2
- package/dist/hsml-idom.js +5 -5
- package/dist/hsml-idom.js.map +1 -1
- package/dist/hsml.d.ts +26 -27
- package/dist/hsml.js.map +1 -1
- package/dist/http.js +1 -1
- package/dist/http.js.map +1 -1
- package/dist/router.js +1 -1
- package/dist/router.js.map +1 -1
- package/package.json +8 -8
- package/src/hsml-app.ts +305 -197
- package/src/hsml-convert.ts +8 -8
- package/src/hsml-dom.ts +18 -18
- package/src/hsml-h.ts +10 -10
- package/src/hsml-html.ts +19 -19
- package/src/hsml-idom.ts +25 -25
- package/src/hsml.ts +46 -143
- package/demo/hsml-appc_demo.html +0 -16
- package/demo/hsml-appc_demo.ts +0 -49
- package/dist/demo/hsml-app-form-validation_demo.0b03b743.js +0 -2
- package/dist/demo/hsml-app-form-validation_demo.0b03b743.js.map +0 -1
- package/dist/demo/hsml-app-form-validation_demo.b3a5c810.js +0 -2
- package/dist/demo/hsml-app-form-validation_demo.b3a5c810.js.map +0 -1
- package/dist/demo/hsml-app-form-validation_demo.d3925067.js +0 -2
- package/dist/demo/hsml-app-form-validation_demo.d3925067.js.map +0 -1
- package/dist/demo/hsml-app-form-validation_demo.f757d763.js +0 -2
- package/dist/demo/hsml-app-form-validation_demo.f757d763.js.map +0 -1
- package/dist/demo/hsml-app-form_demo.007ffcaa.js +0 -2
- package/dist/demo/hsml-app-form_demo.007ffcaa.js.map +0 -1
- package/dist/demo/hsml-app-form_demo.a034239d.js +0 -2
- package/dist/demo/hsml-app-form_demo.a034239d.js.map +0 -1
- package/dist/demo/hsml-app-test_demo.35c14dc9.js +0 -2
- package/dist/demo/hsml-app-test_demo.35c14dc9.js.map +0 -1
- package/dist/demo/hsml-app-test_demo.3c7e16ae.js +0 -2
- package/dist/demo/hsml-app-test_demo.3c7e16ae.js.map +0 -1
- package/dist/demo/hsml-app-tictactoe_demo.5f4861c1.js +0 -2
- package/dist/demo/hsml-app-tictactoe_demo.5f4861c1.js.map +0 -1
- package/dist/demo/hsml-app-tictactoe_demo.7deeabad.js +0 -2
- package/dist/demo/hsml-app-tictactoe_demo.7deeabad.js.map +0 -1
- package/dist/demo/hsml-app_demo.87d83c29.js +0 -2
- package/dist/demo/hsml-app_demo.87d83c29.js.map +0 -1
- package/dist/demo/hsml-app_demo.941a13a6.js +0 -2
- package/dist/demo/hsml-app_demo.941a13a6.js.map +0 -1
- package/dist/demo/hsml-appc_demo.0234ff15.js +0 -2
- package/dist/demo/hsml-appc_demo.0234ff15.js.map +0 -1
- package/dist/demo/hsml-appc_demo.f5783031.js +0 -2
- package/dist/demo/hsml-appc_demo.f5783031.js.map +0 -1
- package/dist/demo/hsml-appc_demo.html +0 -1
- package/dist/demo/hsml-appel_demo.0e8a4d4c.js +0 -2
- package/dist/demo/hsml-appel_demo.0e8a4d4c.js.map +0 -1
- package/dist/demo/hsml-appel_demo.1a5c2c26.js +0 -2
- package/dist/demo/hsml-appel_demo.1a5c2c26.js.map +0 -1
- package/dist/demo/hsml-appi_demo.2c3fb511.js +0 -2
- package/dist/demo/hsml-appi_demo.2c3fb511.js.map +0 -1
- package/dist/demo/hsml-appi_demo.427fdebd.js +0 -2
- package/dist/demo/hsml-appi_demo.427fdebd.js.map +0 -1
- package/dist/demo/hsml_demo.33f28c29.js +0 -2
- package/dist/demo/hsml_demo.33f28c29.js.map +0 -1
- package/dist/demo/hsml_demo.ff950ba1.js.map +0 -1
- package/dist/demo/validators_demo.252e13a6.js.map +0 -1
- package/dist/demo/validators_demo.66893723.js.map +0 -1
package/src/hsml-convert.ts
CHANGED
|
@@ -114,14 +114,14 @@ interface Handler {
|
|
|
114
114
|
close(tag: string): void;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
class HsmlHandler implements Handler {
|
|
117
|
+
class HsmlHandler<HActionType extends string> implements Handler {
|
|
118
118
|
|
|
119
|
-
private _root = [[]] as HElements[];
|
|
119
|
+
private _root = [[]] as HElements<HActionType>[];
|
|
120
120
|
private _nodePath = [] as any; // path that consist of previous hsml nodes
|
|
121
121
|
private _pointer = this._root;
|
|
122
122
|
private _dataRegex = /data-(.+)/;
|
|
123
123
|
|
|
124
|
-
root(): HElement {
|
|
124
|
+
root(): HElement<HActionType> {
|
|
125
125
|
return this._root[0][0];
|
|
126
126
|
}
|
|
127
127
|
|
|
@@ -175,7 +175,7 @@ class HsmlHandler implements Handler {
|
|
|
175
175
|
const children: any[] = [];
|
|
176
176
|
hsmlNode.push(children);
|
|
177
177
|
|
|
178
|
-
this._pointer[this._pointer.length - 1].push(hsmlNode as HElement);
|
|
178
|
+
this._pointer[this._pointer.length - 1].push(hsmlNode as HElement<HActionType>);
|
|
179
179
|
this._nodePath.push(hsmlNode);
|
|
180
180
|
this._pointer = hsmlNode;
|
|
181
181
|
// console.log(">>>", hsmlPath.map(x => x[0]));
|
|
@@ -222,13 +222,13 @@ function domTraverse(node: Node, handler: Handler ): void {
|
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
-
export function dom2hsml(node: Node): HElement {
|
|
226
|
-
const h = new HsmlHandler();
|
|
225
|
+
export function dom2hsml<HActionType extends string>(node: Node): HElement<HActionType> {
|
|
226
|
+
const h = new HsmlHandler<HActionType>();
|
|
227
227
|
node && domTraverse(node, h);
|
|
228
228
|
return h.root();
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
-
export function html2hsml(html: string): HElement {
|
|
231
|
+
export function html2hsml<HActionType extends string>(html: string): HElement<HActionType> {
|
|
232
232
|
const node = new DOMParser()
|
|
233
233
|
.parseFromString(html, "text/html")
|
|
234
234
|
.getElementsByTagName("body")[0]
|
|
@@ -236,7 +236,7 @@ export function html2hsml(html: string): HElement {
|
|
|
236
236
|
return node && dom2hsml(node);
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
-
export function hsml2str(hsml: HElement
|
|
239
|
+
export function hsml2str<HActionType extends string>(hsml: HElement<HActionType>, condense = true): HElement<HActionType> {
|
|
240
240
|
let str = JSON.stringify(hsml, undefined, 4);
|
|
241
241
|
if (condense) {
|
|
242
242
|
str = str.replace(/(\[)\s+(\"[a-zA-Z0-9_\#\.-]+\")\s+(\],?)$/mg, "$1$2$3");
|
package/src/hsml-dom.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
2
|
HAttrClasses,
|
|
3
3
|
HAttrData, HAttrOn, HAttrOnAct,
|
|
4
|
-
|
|
4
|
+
HAttrOnCb, HAttrOnData, HAttrStyles, HElement,
|
|
5
5
|
HElements, HFnc, HHandler,
|
|
6
6
|
HHandlerCtx, HObj, hsml, HTagAttrs, HTagHeadName
|
|
7
7
|
} from "./hsml";
|
|
8
8
|
|
|
9
|
-
function ctxActionCb(ctx: HHandlerCtx | undefined, attrOn: HAttrOn
|
|
9
|
+
function ctxActionCb<HAttrOnActType extends string>(ctx: HHandlerCtx<HAttrOnActType> | undefined, attrOn: HAttrOn<HAttrOnActType>, e: Event) {
|
|
10
10
|
ctx &&
|
|
11
11
|
ctx.actionCb &&
|
|
12
12
|
typeof ctx.actionCb === "function" &&
|
|
13
|
-
ctx.actionCb(attrOn[1] as
|
|
13
|
+
ctx.actionCb(attrOn[1] as HAttrOnActType, attrOn[2] as HAttrOnData, e);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
class HsmlDomHandler implements HHandler<HHandlerCtx
|
|
16
|
+
class HsmlDomHandler<HAttrOnActType extends string> implements HHandler<HAttrOnActType, HHandlerCtx<HAttrOnActType>> {
|
|
17
17
|
|
|
18
18
|
element?: HTMLElement;
|
|
19
19
|
|
|
20
20
|
private _current?: HTMLElement;
|
|
21
21
|
|
|
22
|
-
open(tag: HTagHeadName, attrs: HTagAttrs
|
|
22
|
+
open(tag: HTagHeadName, attrs: HTagAttrs<HAttrOnActType>, children: HElements<HAttrOnActType>, ctx?: HHandlerCtx<HAttrOnActType>): boolean {
|
|
23
23
|
const e = document.createElement(tag);
|
|
24
24
|
let id = attrs._id;
|
|
25
25
|
let classes: string[] = attrs._classes ? attrs._classes : [];
|
|
@@ -31,9 +31,9 @@ class HsmlDomHandler implements HHandler<HHandlerCtx> {
|
|
|
31
31
|
case "_id":
|
|
32
32
|
case "_classes":
|
|
33
33
|
case "_ref":
|
|
34
|
-
case "_key":
|
|
35
|
-
case "_skip":
|
|
36
34
|
case "_hObj":
|
|
35
|
+
case "key":
|
|
36
|
+
case "skip":
|
|
37
37
|
break;
|
|
38
38
|
case "id":
|
|
39
39
|
id = attrs[a] as string;
|
|
@@ -73,7 +73,7 @@ class HsmlDomHandler implements HHandler<HHandlerCtx> {
|
|
|
73
73
|
}
|
|
74
74
|
break;
|
|
75
75
|
case "on":
|
|
76
|
-
const attrOn = attrs[a] as HAttrOn
|
|
76
|
+
const attrOn = attrs[a] as HAttrOn<HAttrOnActType>;
|
|
77
77
|
if (typeof attrOn[0] === "string") {
|
|
78
78
|
if (typeof attrOn[1] === "function") {
|
|
79
79
|
e.addEventListener(attrOn[0] as string, attrOn[1] as (e: Event) => void);
|
|
@@ -82,7 +82,7 @@ class HsmlDomHandler implements HHandler<HHandlerCtx> {
|
|
|
82
82
|
(e: Event) => ctxActionCb(ctx, attrOn, e));
|
|
83
83
|
}
|
|
84
84
|
} else {
|
|
85
|
-
(attrOn as Array<HAttrOnCb | HAttrOnAct
|
|
85
|
+
(attrOn as Array<HAttrOnCb | HAttrOnAct<HAttrOnActType>>)
|
|
86
86
|
.forEach(attr => {
|
|
87
87
|
if (typeof attr[1] === "function") {
|
|
88
88
|
e.addEventListener(attr[0] as string, attr[1] as (e: Event) => void);
|
|
@@ -123,26 +123,26 @@ class HsmlDomHandler implements HHandler<HHandlerCtx> {
|
|
|
123
123
|
if (hObj && hObj.mount && hObj.mount.constructor === Function) {
|
|
124
124
|
hObj.mount(e);
|
|
125
125
|
}
|
|
126
|
-
return attrs.
|
|
126
|
+
return attrs.skip ? true : false;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
close(tag: HTagHeadName, children: HElements
|
|
129
|
+
close(tag: HTagHeadName, children: HElements<HAttrOnActType>, ctx?: HHandlerCtx<HAttrOnActType>): void {
|
|
130
130
|
if (this._current !== this.element) {
|
|
131
131
|
this._current && (this._current = this._current.parentElement ?? undefined);
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
text(text: string, ctx?: HHandlerCtx): void {
|
|
135
|
+
text(text: string, ctx?: HHandlerCtx<HAttrOnActType>): void {
|
|
136
136
|
this._current && this._current.appendChild(document.createTextNode(text));
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
fnc(fnc: HFnc, ctx?: HHandlerCtx): void {
|
|
139
|
+
fnc(fnc: HFnc, ctx?: HHandlerCtx<HAttrOnActType>): void {
|
|
140
140
|
this._current && fnc(this._current);
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
obj(obj: HObj
|
|
143
|
+
obj(obj: HObj<HAttrOnActType>, ctx?: HHandlerCtx<HAttrOnActType>): void {
|
|
144
144
|
if ("toHsml" in obj) {
|
|
145
|
-
obj.toHsml && hsml(obj.toHsml(), this, obj as HHandlerCtx);
|
|
145
|
+
obj.toHsml && hsml(obj.toHsml(), this, obj as HHandlerCtx<HAttrOnActType>);
|
|
146
146
|
} else {
|
|
147
147
|
this.text("" + obj, ctx);
|
|
148
148
|
}
|
|
@@ -150,13 +150,13 @@ class HsmlDomHandler implements HHandler<HHandlerCtx> {
|
|
|
150
150
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
export function hsml2dom(hml: HElement
|
|
153
|
+
export function hsml2dom<HAttrOnActType extends string>(hml: HElement<HAttrOnActType>, ctx?: HHandlerCtx<HAttrOnActType>): HTMLElement | undefined {
|
|
154
154
|
const handler = new HsmlDomHandler();
|
|
155
155
|
hsml(hml, handler, ctx);
|
|
156
156
|
return handler.element;
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
export function hsmls2dom(hmls: HElements
|
|
159
|
+
export function hsmls2dom<HAttrOnActType extends string>(hmls: HElements<HAttrOnActType>, ctx?: HHandlerCtx<HAttrOnActType>): Node[] {
|
|
160
160
|
const elems: Node[] = [];
|
|
161
161
|
for (const hml of hmls) {
|
|
162
162
|
if (hml === undefined || hml === null) {
|
|
@@ -165,7 +165,7 @@ export function hsmls2dom(hmls: HElements, ctx?: HHandlerCtx): Node[] {
|
|
|
165
165
|
if (hml.constructor === String) {
|
|
166
166
|
elems.push(document.createTextNode(hml as string));
|
|
167
167
|
} else if ("toHsml" in (hml as object)) {
|
|
168
|
-
const obj = hml as HHandlerCtx
|
|
168
|
+
const obj = hml as HHandlerCtx<HAttrOnActType>;
|
|
169
169
|
if (obj.toHsml) {
|
|
170
170
|
elems.push(hsml2dom(obj.toHsml(), obj)!);
|
|
171
171
|
}
|
package/src/hsml-h.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { HElement, HTagAttrs, HTagHead, HFnc, HTagChildren } from "./hsml";
|
|
2
2
|
|
|
3
|
-
export function h(tag: HTagHead): HElement
|
|
4
|
-
export function h(tag: HTagHead, text: string | number): HElement
|
|
5
|
-
export function h(tag: HTagHead, children: HTagChildren): HElement
|
|
6
|
-
export function h(tag: HTagHead, fnc: HFnc): HElement
|
|
7
|
-
export function h(tag: HTagHead, attrs: HTagAttrs): HElement
|
|
8
|
-
export function h(tag: HTagHead, attrs: HTagAttrs
|
|
9
|
-
export function h(tag: HTagHead, attrs: HTagAttrs
|
|
10
|
-
export function h(tag: HTagHead, attrs: HTagAttrs
|
|
11
|
-
export function h(tag: HTagHead, second?: HTagAttrs | HTagChildren
|
|
3
|
+
export function h<ActionType extends string>(tag: HTagHead): HElement<ActionType>;
|
|
4
|
+
export function h<ActionType extends string>(tag: HTagHead, text: string | number): HElement<ActionType>;
|
|
5
|
+
export function h<ActionType extends string>(tag: HTagHead, children: HTagChildren<ActionType>): HElement<ActionType>;
|
|
6
|
+
export function h<ActionType extends string>(tag: HTagHead, fnc: HFnc): HElement<ActionType>;
|
|
7
|
+
export function h<ActionType extends string>(tag: HTagHead, attrs: HTagAttrs<ActionType>): HElement<ActionType>;
|
|
8
|
+
export function h<ActionType extends string>(tag: HTagHead, attrs: HTagAttrs<ActionType>, text: string | number): HElement<ActionType>;
|
|
9
|
+
export function h<ActionType extends string>(tag: HTagHead, attrs: HTagAttrs<ActionType>, children: HElement<ActionType>[]): HElement<ActionType>;
|
|
10
|
+
export function h<ActionType extends string>(tag: HTagHead, attrs: HTagAttrs<ActionType>, fnc: HFnc): HElement<ActionType>;
|
|
11
|
+
export function h<ActionType extends string>(tag: HTagHead, second?: HTagAttrs<ActionType> | HTagChildren<ActionType>, third?: HTagAttrs<ActionType> | HTagChildren<ActionType>): HElement<ActionType> {
|
|
12
12
|
const result: [string, ...any[]] = [tag];
|
|
13
13
|
if (second) {
|
|
14
14
|
if (typeof second === "string" || typeof second === "number") {
|
|
@@ -27,5 +27,5 @@ export function h(tag: HTagHead, second?: HTagAttrs | HTagChildren, third?: HTag
|
|
|
27
27
|
result.push(third);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
return result as HElement
|
|
30
|
+
return result as HElement<ActionType>;
|
|
31
31
|
}
|
package/src/hsml-html.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
HHandlerCtx, HObj, hsml, HTagAttrs, HTagHeadName
|
|
7
7
|
} from "./hsml";
|
|
8
8
|
|
|
9
|
-
class HsmlHtmlHandler implements HHandler<HHandlerCtx
|
|
9
|
+
class HsmlHtmlHandler<HAttrOnActType extends string> implements HHandler<HAttrOnActType, HHandlerCtx<HAttrOnActType>> {
|
|
10
10
|
|
|
11
11
|
private static _pairTags = [
|
|
12
12
|
"script", "iframe",
|
|
@@ -29,7 +29,7 @@ class HsmlHtmlHandler implements HHandler<HHandlerCtx> {
|
|
|
29
29
|
this._indent = indent;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
open(tag: HTagHeadName, attrs: HTagAttrs
|
|
32
|
+
open(tag: HTagHeadName, attrs: HTagAttrs<HAttrOnActType>, children: HElements<HAttrOnActType>, ctx?: HHandlerCtx<HAttrOnActType>): boolean {
|
|
33
33
|
const props: any[] = [];
|
|
34
34
|
let id = attrs._id;
|
|
35
35
|
let classes: string[] = attrs._classes ? attrs._classes : [];
|
|
@@ -40,9 +40,9 @@ class HsmlHtmlHandler implements HHandler<HHandlerCtx> {
|
|
|
40
40
|
case "_id":
|
|
41
41
|
case "_classes":
|
|
42
42
|
case "_ref":
|
|
43
|
-
case "_key":
|
|
44
|
-
case "_skip":
|
|
45
43
|
case "_hObj":
|
|
44
|
+
case "key":
|
|
45
|
+
case "skip":
|
|
46
46
|
break;
|
|
47
47
|
case "id":
|
|
48
48
|
id = attrs[a] as string;
|
|
@@ -57,7 +57,7 @@ class HsmlHtmlHandler implements HHandler<HHandlerCtx> {
|
|
|
57
57
|
: (c[1] ? c[0] as string : undefined))
|
|
58
58
|
.filter((c): c is string => c !== undefined)
|
|
59
59
|
: [] as string[]);
|
|
60
|
-
|
|
60
|
+
break;
|
|
61
61
|
case "class":
|
|
62
62
|
classes = classes.concat((attrs[a] as string).split(" "));
|
|
63
63
|
break;
|
|
@@ -121,7 +121,7 @@ class HsmlHtmlHandler implements HHandler<HHandlerCtx> {
|
|
|
121
121
|
}
|
|
122
122
|
this._onHtml(html);
|
|
123
123
|
if (hObj && "render" in hObj && hObj.render.constructor === Function) {
|
|
124
|
-
const hsmls = hObj.render() as HElements
|
|
124
|
+
const hsmls = hObj.render() as HElements<HAttrOnActType>;
|
|
125
125
|
for (const hml of hsmls) {
|
|
126
126
|
if (hml === undefined || hml === null) {
|
|
127
127
|
continue;
|
|
@@ -129,17 +129,17 @@ class HsmlHtmlHandler implements HHandler<HHandlerCtx> {
|
|
|
129
129
|
if (hml.constructor === String) {
|
|
130
130
|
this._onHtml(hml + (this._pretty ? "\n" : ""));
|
|
131
131
|
} else if ("toHsml" in (hml as any)) {
|
|
132
|
-
const obj = hml as HObj
|
|
132
|
+
const obj = hml as HObj<HAttrOnActType>;
|
|
133
133
|
obj.toHsml && hsml(obj.toHsml(), this);
|
|
134
134
|
} else {
|
|
135
|
-
hsml(hml as HElement
|
|
135
|
+
hsml(hml as HElement<HAttrOnActType>, this);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
return false;
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
close(tag: HTagHeadName, children: HElements
|
|
142
|
+
close(tag: HTagHeadName, children: HElements<HAttrOnActType>, ctx?: HHandlerCtx<HAttrOnActType>): void {
|
|
143
143
|
let html = "";
|
|
144
144
|
const pairTag = (children.length || HsmlHtmlHandler._pairTags.indexOf(tag) !== -1);
|
|
145
145
|
if (this._pretty) {
|
|
@@ -157,7 +157,7 @@ class HsmlHtmlHandler implements HHandler<HHandlerCtx> {
|
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
text(text: string, ctx?: HHandlerCtx): void {
|
|
160
|
+
text(text: string, ctx?: HHandlerCtx<HAttrOnActType>): void {
|
|
161
161
|
let html = "";
|
|
162
162
|
if (this._pretty) {
|
|
163
163
|
html += this._mkIndent(this._depth);
|
|
@@ -171,12 +171,12 @@ class HsmlHtmlHandler implements HHandler<HHandlerCtx> {
|
|
|
171
171
|
this._onHtml(html);
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
fnc(fnc: HFnc, ctx?: HHandlerCtx): void {
|
|
174
|
+
fnc(fnc: HFnc, ctx?: HHandlerCtx<HAttrOnActType>): void {
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
obj(obj: HObj
|
|
177
|
+
obj(obj: HObj<HAttrOnActType>, ctx?: HHandlerCtx<HAttrOnActType>): void {
|
|
178
178
|
if ("toHsml" in obj) {
|
|
179
|
-
obj.toHsml && hsml(obj.toHsml(), this, obj as HHandlerCtx);
|
|
179
|
+
obj.toHsml && hsml(obj.toHsml(), this, obj as HHandlerCtx<HAttrOnActType>);
|
|
180
180
|
} else {
|
|
181
181
|
this.text("" + obj, ctx);
|
|
182
182
|
}
|
|
@@ -192,12 +192,12 @@ class HsmlHtmlHandler implements HHandler<HHandlerCtx> {
|
|
|
192
192
|
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
export function hsml2html(hsmlEl: HElement
|
|
195
|
+
export function hsml2html<HAttrOnActType extends string>(hsmlEl: HElement<HAttrOnActType>, onHtml: (html: string) => void, pretty = false): void {
|
|
196
196
|
const handler = new HsmlHtmlHandler(onHtml, pretty);
|
|
197
197
|
hsml(hsmlEl, handler);
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
-
export function hsmls2html(hsmls: HElements
|
|
200
|
+
export function hsmls2html<HAttrOnActType extends string>(hsmls: HElements<HAttrOnActType>, onHtml: (html: string) => void, pretty = false): void {
|
|
201
201
|
for (const hml of hsmls) {
|
|
202
202
|
if (hml === undefined || hml === null) {
|
|
203
203
|
continue;
|
|
@@ -205,21 +205,21 @@ export function hsmls2html(hsmls: HElements, onHtml: (html: string) => void, pre
|
|
|
205
205
|
if (hml.constructor === String) {
|
|
206
206
|
onHtml(hml + (pretty ? "\n" : ""));
|
|
207
207
|
} else if ("toHsml" in (hml as any)) {
|
|
208
|
-
const obj = hml as HObj
|
|
208
|
+
const obj = hml as HObj<HAttrOnActType>;
|
|
209
209
|
obj.toHsml && hsml2html(obj.toHsml(), onHtml, pretty);
|
|
210
210
|
} else {
|
|
211
|
-
hsml2html(hml as HElement
|
|
211
|
+
hsml2html(hml as HElement<HAttrOnActType>, onHtml, pretty);
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
export function hsml2htmls(hsml: HElement
|
|
216
|
+
export function hsml2htmls<HAttrOnActType extends string>(hsml: HElement<HAttrOnActType>, pretty = false): string[] {
|
|
217
217
|
const htmls: string[] = [];
|
|
218
218
|
hsml2html(hsml, html => htmls.push(html), pretty);
|
|
219
219
|
return htmls;
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
-
export function hsmls2htmls(hsmls: HElements
|
|
222
|
+
export function hsmls2htmls<HAttrOnActType extends string>(hsmls: HElements<HAttrOnActType>, pretty = false): string[] {
|
|
223
223
|
const htmls: string[] = [];
|
|
224
224
|
hsmls2html(hsmls, html => htmls.push(html), pretty);
|
|
225
225
|
return htmls;
|
package/src/hsml-idom.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
HAttrClasses,
|
|
3
3
|
HAttrData, HAttrOn, HAttrOnAct,
|
|
4
|
-
|
|
4
|
+
HAttrOnCb, HAttrOnData, HAttrStyles, HElement,
|
|
5
5
|
HElements, HFnc, HHandler,
|
|
6
6
|
HHandlerCtx, HObj, hsml, HTagAttrs, HTagHeadName
|
|
7
7
|
} from "./hsml";
|
|
@@ -52,16 +52,16 @@ import { currentElement, elementClose, elementOpen, patch, skip, text } from "./
|
|
|
52
52
|
|
|
53
53
|
// boolAttrProps.forEach(a => idom.attributes[a] = setBoolAttrProp);
|
|
54
54
|
|
|
55
|
-
function ctxActionCb(ctx: HHandlerCtx | undefined, attrOn: HAttrOn
|
|
55
|
+
function ctxActionCb<HAttrOnActType extends string>(ctx: HHandlerCtx<HAttrOnActType> | undefined, attrOn: HAttrOn<HAttrOnActType>, e: Event) {
|
|
56
56
|
ctx &&
|
|
57
57
|
ctx.actionCb &&
|
|
58
58
|
typeof ctx.actionCb === "function" &&
|
|
59
|
-
ctx.actionCb(attrOn[1] as
|
|
59
|
+
ctx.actionCb(attrOn[1] as HAttrOnActType, attrOn[2] as HAttrOnData, e);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
class HsmlIDomHandler implements HHandler<HHandlerCtx
|
|
62
|
+
class HsmlIDomHandler<HAttrOnActType extends string> implements HHandler<HAttrOnActType, HHandlerCtx<HAttrOnActType>> {
|
|
63
63
|
|
|
64
|
-
open(tag: HTagHeadName, attrs: HTagAttrs
|
|
64
|
+
open(tag: HTagHeadName, attrs: HTagAttrs<HAttrOnActType>, children: HElements<HAttrOnActType>, ctx?: HHandlerCtx<HAttrOnActType>): boolean {
|
|
65
65
|
const props: any[] = [];
|
|
66
66
|
let id = attrs._id;
|
|
67
67
|
let classes: string[] = attrs._classes ? attrs._classes : [];
|
|
@@ -73,9 +73,9 @@ class HsmlIDomHandler implements HHandler<HHandlerCtx> {
|
|
|
73
73
|
case "_id":
|
|
74
74
|
case "_classes":
|
|
75
75
|
case "_ref":
|
|
76
|
-
case "_key":
|
|
77
|
-
case "_skip":
|
|
78
76
|
case "_hObj":
|
|
77
|
+
case "key":
|
|
78
|
+
case "skip":
|
|
79
79
|
break;
|
|
80
80
|
case "id":
|
|
81
81
|
id = attrs[a] as string;
|
|
@@ -110,7 +110,7 @@ class HsmlIDomHandler implements HHandler<HHandlerCtx> {
|
|
|
110
110
|
props.push("style", attrs[a] as HAttrStyles);
|
|
111
111
|
break;
|
|
112
112
|
case "on":
|
|
113
|
-
const attrOn = attrs[a] as HAttrOn
|
|
113
|
+
const attrOn = attrs[a] as HAttrOn<HAttrOnActType>;
|
|
114
114
|
if (typeof attrOn[0] === "string") {
|
|
115
115
|
if (typeof attrOn[1] === "function") {
|
|
116
116
|
props.push("on" + attrOn[0], attrOn[1]);
|
|
@@ -119,7 +119,7 @@ class HsmlIDomHandler implements HHandler<HHandlerCtx> {
|
|
|
119
119
|
(e: Event) => ctxActionCb(ctx, attrOn, e));
|
|
120
120
|
}
|
|
121
121
|
} else {
|
|
122
|
-
(attrOn as Array<HAttrOnCb | HAttrOnAct
|
|
122
|
+
(attrOn as Array<HAttrOnCb | HAttrOnAct<HAttrOnActType>>)
|
|
123
123
|
.forEach(attr => {
|
|
124
124
|
if (typeof attr[1] === "function") {
|
|
125
125
|
props.push("on" + attr[0], attr[1]);
|
|
@@ -166,8 +166,8 @@ class HsmlIDomHandler implements HHandler<HHandlerCtx> {
|
|
|
166
166
|
if (id) {
|
|
167
167
|
props.unshift("id", id);
|
|
168
168
|
}
|
|
169
|
-
elementOpen(tag, attrs.
|
|
170
|
-
if (attrs.
|
|
169
|
+
elementOpen(tag, attrs.key, undefined, ...props);
|
|
170
|
+
if (attrs.skip) {
|
|
171
171
|
skip();
|
|
172
172
|
}
|
|
173
173
|
if (ctx && ref) {
|
|
@@ -177,25 +177,25 @@ class HsmlIDomHandler implements HHandler<HHandlerCtx> {
|
|
|
177
177
|
hObj.mount(currentElement());
|
|
178
178
|
skip();
|
|
179
179
|
}
|
|
180
|
-
return attrs.
|
|
180
|
+
return attrs.skip ? true : false;
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
close(tag: HTagHeadName, children: HElements
|
|
183
|
+
close(tag: HTagHeadName, children: HElements<HAttrOnActType>, ctx?: HHandlerCtx<HAttrOnActType>): void {
|
|
184
184
|
elementClose(tag);
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
text(txt: string, ctx?: HHandlerCtx): void {
|
|
187
|
+
text(txt: string, ctx?: HHandlerCtx<HAttrOnActType>): void {
|
|
188
188
|
text(txt);
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
fnc(fnc: HFnc, ctx?: HHandlerCtx): void {
|
|
191
|
+
fnc(fnc: HFnc, ctx?: HHandlerCtx<HAttrOnActType>): void {
|
|
192
192
|
const skipFnc = fnc(currentElement());
|
|
193
193
|
skipFnc && skip();
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
obj(obj: HObj
|
|
196
|
+
obj(obj: HObj<HAttrOnActType>, ctx?: HHandlerCtx<HAttrOnActType>): void {
|
|
197
197
|
if ("toHsml" in obj) {
|
|
198
|
-
obj.toHsml && hsml(obj.toHsml(), this, obj as HHandlerCtx);
|
|
198
|
+
obj.toHsml && hsml(obj.toHsml(), this, obj as HHandlerCtx<HAttrOnActType>);
|
|
199
199
|
} else {
|
|
200
200
|
this.text("" + obj, ctx);
|
|
201
201
|
}
|
|
@@ -203,11 +203,11 @@ class HsmlIDomHandler implements HHandler<HHandlerCtx> {
|
|
|
203
203
|
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
-
function hsml2idom(hml: HElement
|
|
206
|
+
function hsml2idom<HAttrOnActType extends string>(hml: HElement<HAttrOnActType>, ctx?: HHandlerCtx<HAttrOnActType>): void {
|
|
207
207
|
hsml(hml, new HsmlIDomHandler(), ctx);
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
function hsmls2idom(hmls: HElements
|
|
210
|
+
function hsmls2idom<HAttrOnActType extends string>(hmls: HElements<HAttrOnActType>, ctx?: HHandlerCtx<HAttrOnActType>): void {
|
|
211
211
|
for (const hml of hmls) {
|
|
212
212
|
if (hml === undefined || hml === null) {
|
|
213
213
|
continue;
|
|
@@ -215,20 +215,20 @@ function hsmls2idom(hmls: HElements, ctx?: HHandlerCtx): void {
|
|
|
215
215
|
if (hml.constructor === String) {
|
|
216
216
|
text(hml as string);
|
|
217
217
|
} else if ("toHsml" in (hml as any)) {
|
|
218
|
-
const obj = hml as HHandlerCtx
|
|
218
|
+
const obj = hml as HHandlerCtx<HAttrOnActType>;
|
|
219
219
|
obj.toHsml && hsml2idom(obj.toHsml(), obj);
|
|
220
220
|
} else {
|
|
221
|
-
hsml2idom(hml as HElement
|
|
221
|
+
hsml2idom(hml as HElement<HAttrOnActType>, ctx);
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
export function hsml2idomPatch(node: Element, hsmlEl: HElement
|
|
226
|
+
export function hsml2idomPatch<HAttrOnActType extends string>(node: Element, hsmlEl: HElement<HAttrOnActType>, ctx?: HHandlerCtx<HAttrOnActType>): void {
|
|
227
227
|
patch(node,
|
|
228
|
-
(data?: HElement) => (data && hsml2idom(data, ctx)), hsmlEl);
|
|
228
|
+
(data?: HElement<HAttrOnActType>) => (data && hsml2idom(data, ctx)), hsmlEl);
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
-
export function hsmls2idomPatch(node: Element, hsmlFr: HElements
|
|
231
|
+
export function hsmls2idomPatch<HAttrOnActType extends string>(node: Element, hsmlFr: HElements<HAttrOnActType>, ctx?: HHandlerCtx<HAttrOnActType>): void {
|
|
232
232
|
patch(node,
|
|
233
|
-
(data?: HElements) => (data && hsmls2idom(data, ctx)), hsmlFr);
|
|
233
|
+
(data?: HElements<HAttrOnActType>) => (data && hsmls2idom(data, ctx)), hsmlFr);
|
|
234
234
|
}
|