@snupo/jmc 1.0.43 → 1.0.45
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/h.d.ts +5 -4
- package/dist/h.d.ts.map +1 -1
- package/dist/h.js.map +1 -1
- package/dist/jmc.d.ts.map +1 -1
- package/dist/jmc.js +13 -1
- package/dist/jmc.js.map +1 -1
- package/package.json +5 -2
- package/src/h.ts +7 -5
- package/src/jmc.ts +13 -3
package/dist/h.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type J = Record<string, any>;
|
|
2
2
|
export type Selector = string | Node;
|
|
3
|
-
export type FComponent = (props: J | undefined, children?: Children) =>
|
|
4
|
-
export type FComponentT<P> = (pcn: P, cn?: Children) =>
|
|
3
|
+
export type FComponent = (props: J | undefined, children?: Children) => HU;
|
|
4
|
+
export type FComponentT<P> = (pcn: P, cn?: Children) => HU;
|
|
5
5
|
type HKindElement = 1;
|
|
6
6
|
type HKindFunctionComponent = 2;
|
|
7
7
|
type HKindClassComponent = 3;
|
|
@@ -10,14 +10,14 @@ export type HKind = HKindElement | HKindFunctionComponent | HKindClassComponent
|
|
|
10
10
|
export interface IClassComponent {
|
|
11
11
|
element: Node;
|
|
12
12
|
props?: Record<string, any>;
|
|
13
|
-
view():
|
|
13
|
+
view(): HU;
|
|
14
14
|
update(uc: any): boolean | void;
|
|
15
15
|
mounted?(): void;
|
|
16
16
|
}
|
|
17
17
|
export interface CComponent {
|
|
18
18
|
new (props: any): IClassComponent;
|
|
19
19
|
}
|
|
20
|
-
export type Children =
|
|
20
|
+
export type Children = HU[];
|
|
21
21
|
export type HText = string | number | boolean;
|
|
22
22
|
export type HFragment = {
|
|
23
23
|
kind: HKindFragment;
|
|
@@ -46,6 +46,7 @@ export type HComp = HFunctionComponent | HClassComponent;
|
|
|
46
46
|
export type H = HText & {
|
|
47
47
|
kind?: undefined;
|
|
48
48
|
} | HElement | HFunctionComponent | HClassComponent | HFragment;
|
|
49
|
+
export type HU = H | undefined | null;
|
|
49
50
|
export declare function jsx(tag: any, p: any, ...cn: any[]): HElement | HFunctionComponent | HClassComponent | HFragment;
|
|
50
51
|
export declare let jsxf: symbol;
|
|
51
52
|
export {};
|
package/dist/h.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"h.d.ts","sourceRoot":"","sources":["../src/h.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAGnC,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,IAAI,CAAA;AAEpC,MAAM,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,SAAS,EAAE,QAAQ,CAAC,EAAE,QAAQ,KAAK,
|
|
1
|
+
{"version":3,"file":"h.d.ts","sourceRoot":"","sources":["../src/h.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAGnC,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,IAAI,CAAA;AAEpC,MAAM,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,SAAS,EAAE,QAAQ,CAAC,EAAE,QAAQ,KAAK,EAAE,CAAA;AAC1E,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,QAAQ,KAAK,EAAE,CAAA;AAE1D,KAAK,YAAY,GAAG,CAAC,CAAA;AACrB,KAAK,sBAAsB,GAAG,CAAC,CAAA;AAC/B,KAAK,mBAAmB,GAAG,CAAC,CAAA;AAC5B,KAAK,aAAa,GAAG,CAAC,CAAA;AAOtB,MAAM,MAAM,KAAK,GAAG,YAAY,GAAG,sBAAsB,GAAG,mBAAmB,GAAG,aAAa,CAAA;AAE/F,MAAM,WAAW,eAAe;IAC5B,OAAO,EAAE,IAAI,CA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kB,GAClB,eAAe,GACf,SAAS,CAAA;AAEf,MAAM,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,GAAG,IAAI,CAAA;AAIrC,wBAAgB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,GAAG,QAAQ,GAAG,kBAAkB,GAAG,eAAe,GAAG,SAAS,CAU/G;AAGD,eAAO,IAAI,IAAI,QAAW,CAAA"}
|
package/dist/h.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"h.js","sourceRoot":"","sources":["../src/h.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"h.js","sourceRoot":"","sources":["../src/h.ts"],"names":[],"mappings":"AA6EA,IAAI,OAAO,GAAG,CAAC,CAAW,EAAE,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;AAErE,MAAM,UAAU,GAAG,CAAC,GAAQ,EAAE,CAAM,EAAE,GAAG,EAAS;IAC9C,IAAI,GAAG,EAAE,IAAI;QAAE,OAAO,GAAG,CAAA,CAAC,kCAAkC;IAE5D,IAAI,IAAI,GAAU,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAExF,IAAI,CAAC,GAAQ,EAAE,IAAI,EAAE,CAAA;IACrB,IAAI,IAAI,IAAI,CAAC;QAAE,CAAC,CAAC,GAAG,GAAG,GAAG,CAAA;IAC1B,IAAI,CAAC;QAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;IACd,IAAI,EAAE,EAAE,MAAM;QAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAA;IACzB,OAAO,CAAC,CAAA;AACZ,CAAC;AAED,4CAA4C;AAC5C,MAAM,CAAC,IAAI,IAAI,GAAG,MAAM,EAAE,CAAA","sourcesContent":["export type J = Record<string, any> // a json record\r\n\r\n// Overload signatures\r\nexport type Selector = string | Node\r\n\r\nexport type FComponent = (props: J | undefined, children?: Children) => HU\r\nexport type FComponentT<P> = (pcn: P, cn?: Children) => HU\r\n\r\ntype HKindElement = 1\r\ntype HKindFunctionComponent = 2\r\ntype HKindClassComponent = 3\r\ntype HKindFragment = 4\r\n\r\n// export const kindelement : HKindElement = 1\r\n// export const kindfc : HKindFunctionComponent = 2\r\n// export const kindcc : HKindClassComponent = 3\r\n// export const kindfragment : HKindFragment = 4\r\n\r\nexport type HKind = HKindElement | HKindFunctionComponent | HKindClassComponent | HKindFragment\r\n\r\nexport interface IClassComponent {\r\n element: Node\r\n props?: Record<string, any>\r\n view(): HU\r\n update(uc: any): boolean | void\r\n mounted?(): void\r\n}\r\n\r\nexport interface CComponent {\r\n new(props: any): IClassComponent\r\n}\r\n\r\nexport type Children = HU[]\r\n\r\nexport type HText =\r\n | string // text node\r\n | number // text node\r\n | boolean // do not allow boolean, that\r\n\r\nexport type HFragment = {\r\n kind: HKindFragment\r\n cn?: Children\r\n}\r\n\r\nexport type HElement = {\r\n kind: HKindElement\r\n tag: string\r\n p?: J\r\n cn?: Children\r\n}\r\n\r\nexport type HFunctionComponent = {\r\n kind: HKindFunctionComponent\r\n tag: FComponent\r\n p?: J\r\n cn?: Children\r\n}\r\n\r\nexport type HClassComponent = {\r\n kind: HKindClassComponent\r\n tag: CComponent\r\n p?: J\r\n cn?: Children\r\n i?: IClassComponent\r\n}\r\n\r\nexport type HComp = HFunctionComponent | HClassComponent\r\n\r\nexport type H =\r\n | HText & { kind?: undefined } // text nodes never have a kind. but this type addition makes H a full DU\r\n | HElement\r\n | HFunctionComponent\r\n | HClassComponent\r\n | HFragment \r\n\r\nexport type HU = H | undefined | null\r\n\r\nlet isclass = (f: Function) => /^class\\s|^class\\{/.test(f.toString())\r\n\r\nexport function jsx(tag: any, p: any, ...cn: any[]): HElement | HFunctionComponent | HClassComponent | HFragment {\r\n if (tag?.kind) return tag // already an H node, flatten tree\r\n\r\n let kind: HKind = tag == jsxf ? 4 : tag instanceof Function ? (isclass(tag) ? 3 : 2) : 1\r\n\r\n let h: any = { kind }\r\n if (kind != 4) h.tag = tag\r\n if (p) h.p = p\r\n if (cn?.length) h.cn = cn\r\n return h\r\n}\r\n\r\n// fragment is only used above as a sentinel\r\nexport let jsxf = Symbol()"]}
|
package/dist/jmc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jmc.d.ts","sourceRoot":"","sources":["../src/jmc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAY,CAAC,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"jmc.d.ts","sourceRoot":"","sources":["../src/jmc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAY,CAAC,EAAE,QAAQ,EAAiC,MAAM,KAAK,CAAA;AAOlF,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,IAAI;QACV,CAAC,CAAC,EAAE,CAAC,GAAG;YAAE,CAAC,CAAC,EAAE,CAAC,CAAA;SAAE,CAAA;KACpB;CACJ;AAkID,wBAAgB,KAAK,CAAC,CAAC,EAAE,IAAI,GAAG,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,SAAM,EAAE,EAAE,GAAS,CAAC,QASpE;AAED,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,CAAC,GAAG,MAAM,CAAA;AAE3C,wBAAgB,UAAU,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CA2BnD"}
|
package/dist/jmc.js
CHANGED
|
@@ -23,6 +23,15 @@ let setprops = (e, old, now) => {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
|
+
let removeexcesschildren = (n, i) => {
|
|
27
|
+
let c;
|
|
28
|
+
while ((c = n.childNodes[i])) {
|
|
29
|
+
try {
|
|
30
|
+
c.remove();
|
|
31
|
+
}
|
|
32
|
+
catch (_) { } // due to blur-event-handlers, this can fail
|
|
33
|
+
}
|
|
34
|
+
};
|
|
26
35
|
/** synchronizes children starting at the i-th element. returns the index of the last child synchronized */
|
|
27
36
|
let syncchildren = (p, cn, i, ns, depth, uc) => {
|
|
28
37
|
cn.flat(999)
|
|
@@ -32,6 +41,8 @@ let syncchildren = (p, cn, i, ns, depth, uc) => {
|
|
|
32
41
|
};
|
|
33
42
|
function sync(parent, i, h, ns, depth, uc) {
|
|
34
43
|
// console.log('%csync2', "background:orange", parent.tagName, i, h, depth)
|
|
44
|
+
if (h === null || h === undefined)
|
|
45
|
+
return i; // skip. keep 0 and false renderable, per comment below
|
|
35
46
|
let c = parent.childNodes[i];
|
|
36
47
|
switch (h.kind) {
|
|
37
48
|
case 1:
|
|
@@ -54,7 +65,8 @@ function sync(parent, i, h, ns, depth, uc) {
|
|
|
54
65
|
n.h = h; // sets the new property values
|
|
55
66
|
if (--depth && !n.h?.p?.const && !iswebcomponent(h)) {
|
|
56
67
|
const j = syncchildren(n, cn, 0, ns, depth, uc);
|
|
57
|
-
n.replaceChildren(...[...n.childNodes].slice(0, j))
|
|
68
|
+
// n.replaceChildren(...[...n.childNodes].slice(0, j)) // strip excess children
|
|
69
|
+
removeexcesschildren(n, j);
|
|
58
70
|
}
|
|
59
71
|
return i + 1;
|
|
60
72
|
}
|
package/dist/jmc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jmc.js","sourceRoot":"","sources":["../src/jmc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAYlC,IAAI,cAAc,GAAG,CAAC,CAAW,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AAE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AAE,CAAC;gBACxB,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;YACxC,CAAC;iBAAM,IAAI,CAAC,YAAY,IAAI,EAAE,CAAC;gBAC3B,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;oBACN,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,CAAA;oBACxB,UAAU,EAAE,CAAA;gBAChB,CAAC;YACL,CAAC;iBAAM,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;gBAC/B,KAAK,GAAG,CAAC,CAAA;YACb,CAAC;iBAAM,CAAC;gBACJ,EAAE,GAAG,CAAC,CAAA;YACV,CAAC;QACL,CAAC;IACL,CAAC;IAED,CAAC,CAAC,IAAI,CAAC,CAAA;IAEP,IAAI,CAAC,UAAU;QAAE,OAAO,CAAC,IAAI,CAAC,2CAA2C,EAAE,GAAG,IAAI,CAAC,CAAA;AACvF,CAAC","sourcesContent":["import type { H, HElement, J, Selector, Children, HClassComponent } from './h'\r\nimport { rebind } from './base.js'\r\n\r\nconst enum NodeType { // vaporizes (but for that must be in this file, otherwise not)\r\n TextNode = 3\r\n}\r\n\r\ndeclare global {\r\n interface Node {\r\n h?: H & { p?: J }\r\n }\r\n}\r\n\r\nlet iswebcomponent = (h: HElement) => h.tag.includes('-')\r\n\r\nconst isproperty = (e: Element, name: string, value: any) =>\r\n name !== \"viewBox\" &&\r\n (value instanceof Object ||\r\n value instanceof Function ||\r\n (e.namespaceURI !== \"http://www.w3.org/2000/svg\" && name in e && name != 'style'))\r\n\r\nlet setprops = (e: Element & J, old: J | undefined, now: J | undefined) => {\r\n\r\n old ??= {}\r\n now ??= {}\r\n\r\n // removals\r\n for (let p in old)\r\n if (!(p in now))\r\n isproperty(e, p, old[p])\r\n ? e[p] = typeof old[p] === 'boolean' ? false : ''\r\n : e.removeAttribute(p)\r\n // updates\r\n for (let p in now) {\r\n let v = now[p]\r\n if (v != old[p]) {\r\n isproperty(e, p, v)\r\n ? e[p] = v\r\n : e.setAttribute(p, v)\r\n }\r\n }\r\n}\r\n\r\n/** synchronizes children starting at the i-th element. returns the index of the last child synchronized */\r\nlet syncchildren = (p: Element, cn: Children, i: number, ns: string, depth: number, uc: J): number => {\r\n cn.flat(999)\r\n .filter(hc => hc !== null && hc !== undefined) // skip. keep 0 and false renderable, per comment below)\r\n .forEach(hc => (i = sync(p, i, hc, ns, depth, uc)))\r\n return i\r\n}\r\n\r\nfunction sync(parent: Element, i: number, h: H, ns: string, depth: number, uc: J): number {\r\n\r\n // console.log('%csync2', \"background:orange\", parent.tagName, i, h, depth)\r\n\r\n let c = parent.childNodes[i]\r\n\r\n switch (h.kind) {\r\n case 1:\r\n {\r\n let n: Element\r\n let { tag, cn, p } = h\r\n cn ??= []\r\n\r\n if ((<Element>c)?.tagName?.toLowerCase() != tag.toLowerCase()) {\r\n n = document.createElementNS(ns = p?.xmlns ?? ns, tag) // replace namespace with propertyvalue if set. otherwise pass forward to children\r\n c ? c.replaceWith(n) : parent.appendChild(n)\r\n setprops(n, {}, p)\r\n p?.mounted?.(n)\r\n } else {\r\n n = c as Element\r\n setprops(n, n.h?.p, p)\r\n if (p?.update?.(c, uc)) return i + 1\r\n }\r\n\r\n n.h = h // sets the new property values\r\n\r\n if (--depth && !n.h?.p?.const && !iswebcomponent(h as HElement)) {\r\n const j = syncchildren(n, cn, 0, ns, depth, uc)\r\n n.replaceChildren(...[...n.childNodes].slice(0, j)) // strip excess children\r\n }\r\n\r\n return i + 1\r\n }\r\n\r\n case 4:\r\n {\r\n return syncchildren(parent, h.cn ?? [], i, ns, --depth, uc)\r\n }\r\n\r\n case 2:\r\n {\r\n let hr = h.tag(h.p, h.cn)\r\n let j = sync(parent, i, hr, ns, depth, uc)\r\n let n = parent.childNodes[i]! // now the dom element exists, unless the function returned undefined or null\r\n if (n) n.h = h\r\n return j\r\n }\r\n\r\n case 3: {\r\n let isupdate = (c?.h as any)?.tag == h.tag\r\n\r\n if (isupdate) {\r\n let ci = (c!.h as HClassComponent).i!\r\n ci.props = h.p\r\n\r\n // update() substitutes view/sync when returning truthy\r\n return (ci.update?.(uc)) ? i + 1 : sync(parent, i, ci.view(), ns, depth, uc)\r\n }\r\n\r\n let ci = h.i = rebind(new h.tag(h.p))\r\n let j = sync(parent, i, ci.view(), ns, depth, uc)\r\n let n = parent.childNodes[i]!\r\n ci.element = n\r\n n.h = h\r\n ci.mounted?.()\r\n return j\r\n }\r\n\r\n default:\r\n // textnode\r\n let s = h.toString()\r\n if (c?.nodeType == NodeType.TextNode) {\r\n if (c.textContent != s) c.textContent = s // firefox updates equal text, loosing existing text selection\r\n } else {\r\n c ? c.replaceWith(s) : parent.append(s)\r\n }\r\n return i + 1\r\n }\r\n}\r\n\r\nexport function patch(e: Node | null, h: H, depth = 999, uc = {} as J) {\r\n if (!e) return\r\n if (depth == 0) {\r\n (e as HTMLElement).replaceChildren()\r\n depth = 999\r\n }\r\n let p = e.parentElement as HTMLElement\r\n let i = [].indexOf.call<any, any, any>(p.childNodes, e)\r\n sync(p, i, h, p.namespaceURI!, depth, uc)\r\n}\r\n\r\nexport type Command = Selector | J | number\r\n\r\nexport function updateview(...cmds: Command[]): void {\r\n\r\n if (!cmds.length) cmds.push('body')\r\n let uc = {}\r\n let depth = 999\r\n let patchcount = 0\r\n\r\n function f(cmds: Command[]) {\r\n for (const c of cmds) {\r\n if (typeof c === 'string') {\r\n f([...document.querySelectorAll(c)])\r\n } else if (c instanceof Node) {\r\n if (c.h) {\r\n patch(c, c.h, depth, uc)\r\n patchcount++\r\n }\r\n } else if (typeof c === 'number') {\r\n depth = c\r\n } else {\r\n uc = c\r\n }\r\n }\r\n }\r\n\r\n f(cmds)\r\n\r\n if (!patchcount) console.warn(\"updateview did not update anything. cmds=\", ...cmds)\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"jmc.js","sourceRoot":"","sources":["../src/jmc.ts"],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r\n\r\nconst enum NodeType { // vaporizes (but for that must be in this file, otherwise not)\r\n TextNode = 3\r\n}\r\n\r\ndeclare global {\r\n interface Node {\r\n h?: H & { p?: J }\r\n }\r\n}\r\n\r\nlet iswebcomponent = (h: HElement) => h.tag.includes('-')\r\n\r\nconst isproperty = (e: Element, name: string, value: any) =>\r\n name !== \"viewBox\" &&\r\n (value instanceof Object ||\r\n value instanceof Function ||\r\n (e.namespaceURI !== \"http://www.w3.org/2000/svg\" && name in e && name != 'style'))\r\n\r\nlet setprops = (e: Element & J, old: J | undefined, now: J | undefined) => {\r\n\r\n old ??= {}\r\n now ??= {}\r\n\r\n // removals\r\n for (let p in old)\r\n if (!(p in now))\r\n isproperty(e, p, old[p])\r\n ? e[p] = typeof old[p] === 'boolean' ? false : ''\r\n : e.removeAttribute(p)\r\n // updates\r\n for (let p in now) {\r\n let v = now[p]\r\n if (v != old[p]) {\r\n isproperty(e, p, v)\r\n ? e[p] = v\r\n : e.setAttribute(p, v)\r\n }\r\n }\r\n}\r\n\r\nlet removeexcesschildren = (n: Element, i: number) => {\r\n let c: ChildNode\r\n while ((c = n.childNodes[i])) {\r\n try { c.remove() } catch (_) { } // due to blur-event-handlers, this can fail\r\n }\r\n}\r\n\r\n/** synchronizes children starting at the i-th element. returns the index of the last child synchronized */\r\nlet syncchildren = (p: Element, cn: Children, i: number, ns: string, depth: number, uc: J): number => {\r\n cn.flat(999)\r\n .filter(hc => hc !== null && hc !== undefined) // skip. keep 0 and false renderable, per comment below)\r\n .forEach(hc => (i = sync(p, i, hc, ns, depth, uc)))\r\n return i\r\n}\r\n\r\nfunction sync(parent: Element, i: number, h: HU, ns: string, depth: number, uc: J): number {\r\n\r\n // console.log('%csync2', \"background:orange\", parent.tagName, i, h, depth)\r\n\r\n if (h === null || h === undefined) return i // skip. keep 0 and false renderable, per comment below\r\n\r\n let c = parent.childNodes[i]\r\n\r\n switch (h.kind) {\r\n case 1:\r\n {\r\n let n: Element\r\n let { tag, cn, p } = h\r\n cn ??= []\r\n\r\n if ((<Element>c)?.tagName?.toLowerCase() != tag.toLowerCase()) {\r\n n = document.createElementNS(ns = p?.xmlns ?? ns, tag) // replace namespace with propertyvalue if set. otherwise pass forward to children\r\n c ? c.replaceWith(n) : parent.appendChild(n)\r\n setprops(n, {}, p)\r\n p?.mounted?.(n)\r\n } else {\r\n n = c as Element\r\n setprops(n, n.h?.p, p)\r\n if (p?.update?.(c, uc)) return i + 1\r\n }\r\n\r\n n.h = h // sets the new property values\r\n\r\n if (--depth && !n.h?.p?.const && !iswebcomponent(h as HElement)) {\r\n const j = syncchildren(n, cn, 0, ns, depth, uc)\r\n // n.replaceChildren(...[...n.childNodes].slice(0, j)) // strip excess children\r\n removeexcesschildren(n, j)\r\n }\r\n\r\n return i + 1\r\n }\r\n\r\n case 4:\r\n {\r\n return syncchildren(parent, h.cn ?? [], i, ns, --depth, uc)\r\n }\r\n\r\n case 2:\r\n {\r\n let hr = h.tag(h.p, h.cn)\r\n let j = sync(parent, i, hr, ns, depth, uc)\r\n let n = parent.childNodes[i]! // now the dom element exists, unless the function returned undefined or null\r\n if (n) n.h = h\r\n return j\r\n }\r\n\r\n case 3: {\r\n let isupdate = (c?.h as any)?.tag == h.tag\r\n\r\n if (isupdate) {\r\n let ci = (c!.h as HClassComponent).i!\r\n ci.props = h.p\r\n\r\n // update() substitutes view/sync when returning truthy\r\n return (ci.update?.(uc)) ? i + 1 : sync(parent, i, ci.view(), ns, depth, uc)\r\n }\r\n\r\n let ci = h.i = rebind(new h.tag(h.p))\r\n let j = sync(parent, i, ci.view(), ns, depth, uc)\r\n let n = parent.childNodes[i]!\r\n ci.element = n\r\n n.h = h\r\n ci.mounted?.()\r\n return j\r\n }\r\n\r\n default:\r\n // textnode\r\n let s = h.toString()\r\n if (c?.nodeType == NodeType.TextNode) {\r\n if (c.textContent != s) c.textContent = s // firefox updates equal text, loosing existing text selection\r\n } else {\r\n c ? c.replaceWith(s) : parent.append(s)\r\n }\r\n return i + 1\r\n }\r\n}\r\n\r\nexport function patch(e: Node | null, h: H, depth = 999, uc = {} as J) {\r\n if (!e) return\r\n if (depth == 0) {\r\n (e as HTMLElement).replaceChildren()\r\n depth = 999\r\n }\r\n let p = e.parentElement as HTMLElement\r\n let i = [].indexOf.call<any, any, any>(p.childNodes, e)\r\n sync(p, i, h, p.namespaceURI!, depth, uc)\r\n}\r\n\r\nexport type Command = Selector | J | number\r\n\r\nexport function updateview(...cmds: Command[]): void {\r\n\r\n if (!cmds.length) cmds.push('body')\r\n let uc = {}\r\n let depth = 999\r\n let patchcount = 0\r\n\r\n function f(cmds: Command[]) {\r\n for (const c of cmds) {\r\n if (typeof c === 'string') {\r\n f([...document.querySelectorAll(c)])\r\n } else if (c instanceof Node) {\r\n if (c.h) {\r\n patch(c, c.h, depth, uc)\r\n patchcount++\r\n }\r\n } else if (typeof c === 'number') {\r\n depth = c\r\n } else {\r\n uc = c\r\n }\r\n }\r\n }\r\n\r\n f(cmds)\r\n\r\n if (!patchcount) console.warn(\"updateview did not update anything. cmds=\", ...cmds)\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snupo/jmc",
|
|
3
3
|
"author": "snupo",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.45",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -20,7 +20,10 @@
|
|
|
20
20
|
],
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"rimraf": "^6.1.3",
|
|
23
|
-
"typescript": "^6.0.3"
|
|
23
|
+
"typescript": "^6.0.3",
|
|
24
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
25
|
+
"happy-dom": "^16.8.1",
|
|
26
|
+
"vitest": "4.1.10"
|
|
24
27
|
},
|
|
25
28
|
"dependencies": {
|
|
26
29
|
"@types/react": "^19.2.17"
|
package/src/h.ts
CHANGED
|
@@ -3,8 +3,8 @@ export type J = Record<string, any> // a json record
|
|
|
3
3
|
// Overload signatures
|
|
4
4
|
export type Selector = string | Node
|
|
5
5
|
|
|
6
|
-
export type FComponent = (props: J | undefined, children?: Children) =>
|
|
7
|
-
export type FComponentT<P> = (pcn: P, cn?: Children) =>
|
|
6
|
+
export type FComponent = (props: J | undefined, children?: Children) => HU
|
|
7
|
+
export type FComponentT<P> = (pcn: P, cn?: Children) => HU
|
|
8
8
|
|
|
9
9
|
type HKindElement = 1
|
|
10
10
|
type HKindFunctionComponent = 2
|
|
@@ -21,7 +21,7 @@ export type HKind = HKindElement | HKindFunctionComponent | HKindClassComponent
|
|
|
21
21
|
export interface IClassComponent {
|
|
22
22
|
element: Node
|
|
23
23
|
props?: Record<string, any>
|
|
24
|
-
view():
|
|
24
|
+
view(): HU
|
|
25
25
|
update(uc: any): boolean | void
|
|
26
26
|
mounted?(): void
|
|
27
27
|
}
|
|
@@ -30,7 +30,7 @@ export interface CComponent {
|
|
|
30
30
|
new(props: any): IClassComponent
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export type Children =
|
|
33
|
+
export type Children = HU[]
|
|
34
34
|
|
|
35
35
|
export type HText =
|
|
36
36
|
| string // text node
|
|
@@ -71,7 +71,9 @@ export type H =
|
|
|
71
71
|
| HElement
|
|
72
72
|
| HFunctionComponent
|
|
73
73
|
| HClassComponent
|
|
74
|
-
| HFragment
|
|
74
|
+
| HFragment
|
|
75
|
+
|
|
76
|
+
export type HU = H | undefined | null
|
|
75
77
|
|
|
76
78
|
let isclass = (f: Function) => /^class\s|^class\{/.test(f.toString())
|
|
77
79
|
|
package/src/jmc.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { H, HElement, J, Selector, Children, HClassComponent } from './h'
|
|
1
|
+
import type { H, HElement, J, Selector, Children, HClassComponent, HU } from './h'
|
|
2
2
|
import { rebind } from './base.js'
|
|
3
3
|
|
|
4
4
|
const enum NodeType { // vaporizes (but for that must be in this file, otherwise not)
|
|
@@ -41,6 +41,13 @@ let setprops = (e: Element & J, old: J | undefined, now: J | undefined) => {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
let removeexcesschildren = (n: Element, i: number) => {
|
|
45
|
+
let c: ChildNode
|
|
46
|
+
while ((c = n.childNodes[i])) {
|
|
47
|
+
try { c.remove() } catch (_) { } // due to blur-event-handlers, this can fail
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
44
51
|
/** synchronizes children starting at the i-th element. returns the index of the last child synchronized */
|
|
45
52
|
let syncchildren = (p: Element, cn: Children, i: number, ns: string, depth: number, uc: J): number => {
|
|
46
53
|
cn.flat(999)
|
|
@@ -49,10 +56,12 @@ let syncchildren = (p: Element, cn: Children, i: number, ns: string, depth: numb
|
|
|
49
56
|
return i
|
|
50
57
|
}
|
|
51
58
|
|
|
52
|
-
function sync(parent: Element, i: number, h:
|
|
59
|
+
function sync(parent: Element, i: number, h: HU, ns: string, depth: number, uc: J): number {
|
|
53
60
|
|
|
54
61
|
// console.log('%csync2', "background:orange", parent.tagName, i, h, depth)
|
|
55
62
|
|
|
63
|
+
if (h === null || h === undefined) return i // skip. keep 0 and false renderable, per comment below
|
|
64
|
+
|
|
56
65
|
let c = parent.childNodes[i]
|
|
57
66
|
|
|
58
67
|
switch (h.kind) {
|
|
@@ -77,7 +86,8 @@ function sync(parent: Element, i: number, h: H, ns: string, depth: number, uc: J
|
|
|
77
86
|
|
|
78
87
|
if (--depth && !n.h?.p?.const && !iswebcomponent(h as HElement)) {
|
|
79
88
|
const j = syncchildren(n, cn, 0, ns, depth, uc)
|
|
80
|
-
n.replaceChildren(...[...n.childNodes].slice(0, j)) // strip excess children
|
|
89
|
+
// n.replaceChildren(...[...n.childNodes].slice(0, j)) // strip excess children
|
|
90
|
+
removeexcesschildren(n, j)
|
|
81
91
|
}
|
|
82
92
|
|
|
83
93
|
return i + 1
|