@snupo/jmc 1.0.49 → 1.0.50
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/jmc.js +11 -12
- package/dist/jmc.js.map +1 -1
- package/package.json +1 -1
- package/src/jmc.ts +12 -12
package/dist/jmc.js
CHANGED
|
@@ -33,19 +33,17 @@ let removeexcesschildren = (n, i) => {
|
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
/** synchronizes children starting at the i-th element. returns the index of the last child synchronized */
|
|
36
|
-
let syncchildren = (p, cn, i,
|
|
36
|
+
let syncchildren = (p, cn, i, depth, uc) => {
|
|
37
37
|
cn.flat(999)
|
|
38
38
|
.filter(hc => hc !== null && hc !== undefined) // skip. keep 0 and false renderable, per comment below)
|
|
39
|
-
.forEach(hc => (i = sync(p, i, hc,
|
|
39
|
+
.forEach(hc => (i = sync(p, i, hc, depth, uc)));
|
|
40
40
|
return i;
|
|
41
41
|
};
|
|
42
|
-
function sync(parent, i, h,
|
|
42
|
+
function sync(parent, i, h, depth, uc) {
|
|
43
43
|
// console.log('%csync2', "background:orange", parent.tagName, i, h, depth)
|
|
44
44
|
if (h === null || h === undefined)
|
|
45
45
|
return i; // skip. keep 0 and false renderable, per comment below
|
|
46
46
|
let c = parent.childNodes[i];
|
|
47
|
-
if (parent.tagName == "foreignObject")
|
|
48
|
-
ns = document.body.namespaceURI;
|
|
49
47
|
switch (h.kind) {
|
|
50
48
|
case 1:
|
|
51
49
|
{
|
|
@@ -56,12 +54,13 @@ function sync(parent, i, h, ns, depth, uc) {
|
|
|
56
54
|
setprops(n, n.h?.p, p);
|
|
57
55
|
n.h = h; // sets the new property values
|
|
58
56
|
if (--depth && !n.h?.p?.const && !iswebcomponent(h)) {
|
|
59
|
-
const j = syncchildren(n, cn, 0,
|
|
57
|
+
const j = syncchildren(n, cn, 0, depth, uc);
|
|
60
58
|
removeexcesschildren(n, j);
|
|
61
59
|
}
|
|
62
60
|
};
|
|
63
61
|
if (c?.tagName?.toLowerCase() != tag.toLowerCase()) {
|
|
64
|
-
|
|
62
|
+
let ns = p?.xmlns ?? (parent.tagName == "foreignObject" ? 'http://www.w3.org/1999/xhtml' : parent.namespaceURI);
|
|
63
|
+
n = document.createElementNS(ns, tag);
|
|
65
64
|
c ? c.replaceWith(n) : parent.appendChild(n);
|
|
66
65
|
process();
|
|
67
66
|
p?.mounted?.(n);
|
|
@@ -76,12 +75,12 @@ function sync(parent, i, h, ns, depth, uc) {
|
|
|
76
75
|
}
|
|
77
76
|
case 4:
|
|
78
77
|
{
|
|
79
|
-
return syncchildren(parent, h.cn ?? [], i,
|
|
78
|
+
return syncchildren(parent, h.cn ?? [], i, --depth, uc);
|
|
80
79
|
}
|
|
81
80
|
case 2:
|
|
82
81
|
{
|
|
83
82
|
let hr = h.tag(h.p, h.cn);
|
|
84
|
-
let j = sync(parent, i, hr,
|
|
83
|
+
let j = sync(parent, i, hr, depth, uc);
|
|
85
84
|
let n = parent.childNodes[i]; // now the dom element exists, unless the function returned undefined or null
|
|
86
85
|
if (n)
|
|
87
86
|
n.h = h;
|
|
@@ -93,10 +92,10 @@ function sync(parent, i, h, ns, depth, uc) {
|
|
|
93
92
|
let ci = c.h.i;
|
|
94
93
|
ci.props = h.p;
|
|
95
94
|
// update() substitutes view/sync when returning truthy
|
|
96
|
-
return (ci.update?.(uc)) ? i + 1 : sync(parent, i, ci.view(),
|
|
95
|
+
return (ci.update?.(uc)) ? i + 1 : sync(parent, i, ci.view(), depth, uc);
|
|
97
96
|
}
|
|
98
97
|
let ci = h.i = rebind(new h.tag(h.p));
|
|
99
|
-
let j = sync(parent, i, ci.view(),
|
|
98
|
+
let j = sync(parent, i, ci.view(), depth, uc);
|
|
100
99
|
let n = parent.childNodes[i];
|
|
101
100
|
ci.element = n;
|
|
102
101
|
n.h = h;
|
|
@@ -125,7 +124,7 @@ export function patch(e, h, depth = 999, uc = {}) {
|
|
|
125
124
|
}
|
|
126
125
|
let p = e.parentElement;
|
|
127
126
|
let i = [].indexOf.call(p.childNodes, e);
|
|
128
|
-
sync(p, i, h,
|
|
127
|
+
sync(p, i, h, depth, uc);
|
|
129
128
|
}
|
|
130
129
|
export function updateview(...cmds) {
|
|
131
130
|
if (!cmds.length)
|
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;AAEzD,MAAM,UAAU,GAAG,CAAC,CAAU,EAAE,IAAY,EAAE,KAAU,EAAE,EAAE,CACxD,IAAI,KAAK,SAAS;IAClB,CAAC,KAAK,YAAY,MAAM;QACpB,KAAK,YAAY,QAAQ;QACzB,CAAC,CAAC,CAAC,YAAY,KAAK,4BAA4B,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,OAAO,CAAC,CAAC,CAAA;AAE1F,IAAI,QAAQ,GAAG,CAAC,CAAc,EAAE,GAAkB,EAAE,GAAkB,EAAE,EAAE;IAEtE,GAAG,KAAK,EAAE,CAAA;IACV,GAAG,KAAK,EAAE,CAAA;IAEV,WAAW;IACX,KAAK,IAAI,CAAC,IAAI,GAAG;QACb,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC;YACX,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;gBACpB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;gBACjD,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAA;IAClC,UAAU;IACV,KAAK,IAA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L,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, HU } 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\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 if (parent.tagName == \"foreignObject\") ns = document.body.namespaceURI!\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 let process = () => {\r\n setprops(n, n.h?.p, p)\r\n n.h = h // sets the new property values\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 removeexcesschildren(n, j)\r\n }\r\n }\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 process()\r\n p?.mounted?.(n)\r\n } else {\r\n n = c as Element\r\n process()\r\n if (p?.update?.(c, uc)) return i + 1\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"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAYlC,IAAI,cAAc,GAAG,CAAC,CAAW,EAAE,EAA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AC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,CAAA;AAC5B,CAAC;AAID,MAAM,UAAU,UAAU,CAAC,GAAG,IAAe;IAEzC,IAAI,CAAC,IAAI,CAAC,MAAM;QAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACnC,IAAI,EAAE,GAAG,EAAE,CAAA;IACX,IAAI,KAAK,GAAG,GAAG,CAAA;IACf,IAAI,UAAU,GAAG,CAAC,CAAA;IAElB,SAAS,CAAC,CAAC,IAAe;QACtB,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;YACnB,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,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, HU } 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\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, 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, depth, uc)))\r\n return i\r\n}\r\n\r\nfunction sync(parent: Element, i: number, h: HU, 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 let process = () => {\r\n setprops(n, n.h?.p, p)\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, depth, uc)\r\n removeexcesschildren(n, j)\r\n }\r\n }\r\n\r\n if ((<Element>c)?.tagName?.toLowerCase() != tag.toLowerCase()) {\r\n let ns = p?.xmlns ?? (parent.tagName == \"foreignObject\" ? 'http://www.w3.org/1999/xhtml' : parent.namespaceURI)\r\n n = document.createElementNS(ns, tag)\r\n c ? c.replaceWith(n) : parent.appendChild(n)\r\n process()\r\n p?.mounted?.(n)\r\n } else {\r\n n = c as Element\r\n process()\r\n if (p?.update?.(c, uc)) return i + 1\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, --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, 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(), 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(), 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, 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
package/src/jmc.ts
CHANGED
|
@@ -49,14 +49,14 @@ let removeexcesschildren = (n: Element, i: number) => {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/** synchronizes children starting at the i-th element. returns the index of the last child synchronized */
|
|
52
|
-
let syncchildren = (p: Element, cn: Children, i: number,
|
|
52
|
+
let syncchildren = (p: Element, cn: Children, i: number, depth: number, uc: J): number => {
|
|
53
53
|
cn.flat(999)
|
|
54
54
|
.filter(hc => hc !== null && hc !== undefined) // skip. keep 0 and false renderable, per comment below)
|
|
55
|
-
.forEach(hc => (i = sync(p, i, hc,
|
|
55
|
+
.forEach(hc => (i = sync(p, i, hc, depth, uc)))
|
|
56
56
|
return i
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
function sync(parent: Element, i: number, h: HU,
|
|
59
|
+
function sync(parent: Element, i: number, h: HU, depth: number, uc: J): number {
|
|
60
60
|
|
|
61
61
|
// console.log('%csync2', "background:orange", parent.tagName, i, h, depth)
|
|
62
62
|
|
|
@@ -64,8 +64,6 @@ function sync(parent: Element, i: number, h: HU, ns: string, depth: number, uc:
|
|
|
64
64
|
|
|
65
65
|
let c = parent.childNodes[i]
|
|
66
66
|
|
|
67
|
-
if (parent.tagName == "foreignObject") ns = document.body.namespaceURI!
|
|
68
|
-
|
|
69
67
|
switch (h.kind) {
|
|
70
68
|
case 1:
|
|
71
69
|
{
|
|
@@ -76,14 +74,16 @@ function sync(parent: Element, i: number, h: HU, ns: string, depth: number, uc:
|
|
|
76
74
|
let process = () => {
|
|
77
75
|
setprops(n, n.h?.p, p)
|
|
78
76
|
n.h = h // sets the new property values
|
|
77
|
+
|
|
79
78
|
if (--depth && !n.h?.p?.const && !iswebcomponent(h as HElement)) {
|
|
80
|
-
const j = syncchildren(n, cn, 0,
|
|
79
|
+
const j = syncchildren(n, cn, 0, depth, uc)
|
|
81
80
|
removeexcesschildren(n, j)
|
|
82
81
|
}
|
|
83
82
|
}
|
|
84
83
|
|
|
85
84
|
if ((<Element>c)?.tagName?.toLowerCase() != tag.toLowerCase()) {
|
|
86
|
-
|
|
85
|
+
let ns = p?.xmlns ?? (parent.tagName == "foreignObject" ? 'http://www.w3.org/1999/xhtml' : parent.namespaceURI)
|
|
86
|
+
n = document.createElementNS(ns, tag)
|
|
87
87
|
c ? c.replaceWith(n) : parent.appendChild(n)
|
|
88
88
|
process()
|
|
89
89
|
p?.mounted?.(n)
|
|
@@ -98,13 +98,13 @@ function sync(parent: Element, i: number, h: HU, ns: string, depth: number, uc:
|
|
|
98
98
|
|
|
99
99
|
case 4:
|
|
100
100
|
{
|
|
101
|
-
return syncchildren(parent, h.cn ?? [], i,
|
|
101
|
+
return syncchildren(parent, h.cn ?? [], i, --depth, uc)
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
case 2:
|
|
105
105
|
{
|
|
106
106
|
let hr = h.tag(h.p, h.cn)
|
|
107
|
-
let j = sync(parent, i, hr,
|
|
107
|
+
let j = sync(parent, i, hr, depth, uc)
|
|
108
108
|
let n = parent.childNodes[i]! // now the dom element exists, unless the function returned undefined or null
|
|
109
109
|
if (n) n.h = h
|
|
110
110
|
return j
|
|
@@ -118,11 +118,11 @@ function sync(parent: Element, i: number, h: HU, ns: string, depth: number, uc:
|
|
|
118
118
|
ci.props = h.p
|
|
119
119
|
|
|
120
120
|
// update() substitutes view/sync when returning truthy
|
|
121
|
-
return (ci.update?.(uc)) ? i + 1 : sync(parent, i, ci.view(),
|
|
121
|
+
return (ci.update?.(uc)) ? i + 1 : sync(parent, i, ci.view(), depth, uc)
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
let ci = h.i = rebind(new h.tag(h.p))
|
|
125
|
-
let j = sync(parent, i, ci.view(),
|
|
125
|
+
let j = sync(parent, i, ci.view(), depth, uc)
|
|
126
126
|
let n = parent.childNodes[i]!
|
|
127
127
|
ci.element = n
|
|
128
128
|
n.h = h
|
|
@@ -150,7 +150,7 @@ export function patch(e: Node | null, h: H, depth = 999, uc = {} as J) {
|
|
|
150
150
|
}
|
|
151
151
|
let p = e.parentElement as HTMLElement
|
|
152
152
|
let i = [].indexOf.call<any, any, any>(p.childNodes, e)
|
|
153
|
-
sync(p, i, h,
|
|
153
|
+
sync(p, i, h, depth, uc)
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
export type Command = Selector | J | number
|