1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2024-11-23 00:59:38 +01:00

Compare commits

..

2 Commits

Author SHA1 Message Date
5e7f7558b5
cross-platform using enviroment (#14)
* 🎉

* Dev bugs@v0.7.6 (#12)

* Update observables-lib.js

* `collectChildren`

* Update todosComponent.js

* 🚀 filter for `collectChildren`

* finalization
2024-01-07 13:22:55 +01:00
d2ddaaec6f
Dev bugs@v0.7.6 (#12)
* Update observables-lib.js

* `collectChildren`

* Update todosComponent.js

* 🚀 filter for `collectChildren`
2024-01-07 12:33:56 +01:00
13 changed files with 252 additions and 204 deletions

File diff suppressed because one or more lines are too long

32
dist/dde.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/esm.js vendored

File diff suppressed because one or more lines are too long

View File

@ -16,7 +16,7 @@ const className= style.host(todosComponent).css`
`; `;
/** @param {{ todos: string[] }} */ /** @param {{ todos: string[] }} */
export function todosComponent({ todos= [ "Task A" ] }= {}){ export function todosComponent({ todos= [ "Task A" ] }= {}){
const todosS= O(todos.map(t=> O(t)), { const todosO= O(todos.map(t=> O(t)), {
add(v){ this.value.push(O(v)); }, add(v){ this.value.push(O(v)); },
remove(i){ O.clear(this.value.splice(i, 1)[0]); } remove(i){ O.clear(this.value.splice(i, 1)[0]); }
}); });
@ -25,24 +25,31 @@ export function todosComponent({ todos= [ "Task A" ] }= {}){
const onsubmitAdd= on("submit", event=> { const onsubmitAdd= on("submit", event=> {
const el= event.target.elements[name]; const el= event.target.elements[name];
event.preventDefault(); event.preventDefault();
O.action(todosS, "add", el.value); O.action(todosO, "add", el.value);
el.value= ""; el.value= "";
}); });
const onremove= on("remove", event=> const onremove= on("remove", event=>
O.action(todosS, "remove", event.detail)); O.action(todosO, "remove", event.detail));
const ul_todos= el("ul").append( const ul_todos_version= 1; // ul_todos_v1/ul_todos_v2
O.el(todosS, ts=> ts const ul_todos_v1= el("ul").append(
O.el(todosO, ts=> ts
.map((textContent, value)=> .map((textContent, value)=>
el(todoComponent, { textContent, value, className }, onremove)) el(todoComponent, { textContent, value, className }, onremove))
)); ));
const ul_todos_v2= (ts)=> el("ul").append(
...ts.map((textContent, value)=>
el(todoComponent, { textContent, value, className }, onremove))
);
return el("div", { className }).append( return el("div", { className }).append(
el("div").append( el("div").append(
el("h2", "Todos:"), el("h2", "Todos:"),
el("h3", "List of todos:"), el("h3", "List of todos:"),
O.el(todosS, ts=> !ts.length O.el(todosO, ts=> !ts.length
? el("p", "No todos yet") ? el("p", "No todos yet")
: ul_todos), : ( (ul_todos_version-1) ? ul_todos_v1 : ul_todos_v2(ts) )
),
el("p", "Click to the text to edit it.") el("p", "Click to the text to edit it.")
), ),
el("form", null, onsubmitAdd).append( el("form", null, onsubmitAdd).append(
@ -54,12 +61,12 @@ export function todosComponent({ todos= [ "Task A" ] }= {}){
), ),
el("div").append( el("div").append(
el("h3", "Output (JSON):"), el("h3", "Output (JSON):"),
el("output", O(()=> JSON.stringify(todosS, null, "\t"))) el("output", O(()=> JSON.stringify(todosO, null, "\t")))
) )
) )
} }
/** /**
* @dispatch {number} remove * @dispatchs {number} remove
* */ * */
function todoComponent({ textContent, value }){ function todoComponent({ textContent, value }){
const { host }= scope; const { host }= scope;

8
jsdom.d.ts vendored
View File

@ -1,5 +1,13 @@
import { el, assign, on } from "./index.d"; import { el, assign, on } from "./index.d";
export * from "./index.d"; export * from "./index.d";
type JSDOM= {
window: Window,
document: Document,
HTMLElement: typeof HTMLElement,
SVGElement: typeof SVGElement,
DocumentFragment: typeof DocumentFragment,
MutationObserver?: typeof MutationObserver
};
export function register(dom: JSDOM): Promise<{ export function register(dom: JSDOM): Promise<{
el: typeof el, el: typeof el,
assign: typeof assign, assign: typeof assign,

View File

@ -1,23 +1,25 @@
//TODO: https://www.npmjs.com/package/html-element //TODO: https://www.npmjs.com/package/html-element
import { enviroment } from './src/dom-common.js'; import { enviroment as env } from './src/dom-common.js';
enviroment.ssr= " ssr"; env.ssr= " ssr";
const { setDeleteAttr }= enviroment; const { setDeleteAttr }= env;
/** @param {HTMLElement} obj */ /** @param {HTMLElement} obj */
enviroment.setDeleteAttr= function(obj, prop, value){ env.setDeleteAttr= function(obj, prop, value){
if("value"===prop) return obj.setAttribute(prop, value); if("value"===prop) return obj.setAttribute(prop, value);
if("checked"!==prop) return setDeleteAttr(obj, prop, value); if("checked"!==prop) return setDeleteAttr(obj, prop, value);
if(value) return obj.setAttribute(prop, ""); if(value) return obj.setAttribute(prop, "");
obj.removeAttribute(prop); obj.removeAttribute(prop);
}; };
const keys= [ "HTMLElement", "SVGElement", "DocumentFragment", "MutationObserver", "document" ]; const keys= { H: "HTMLElement", S: "SVGElement", F: "DocumentFragment", M: "MutationObserver", D: "document" };
let env_bk= {};
let dom_last; let dom_last;
export function register(dom, keys_aditional= []){ export function register(dom){
if(dom_last!==dom){ if(dom_last!==dom){
keys.push(...keys_aditional);
const w= dom.window; const w= dom.window;
keys.forEach(key=> globalThis[key]= w[key]); Object.entries(keys).forEach(([ kE, kW ])=> {
globalThis.window= w; env_bk[kE]= env[kE];
env[kE]= w[kW];
});
w.console= globalThis.console; w.console= globalThis.console;
} }
dom_last= dom; dom_last= dom;
@ -28,8 +30,8 @@ export function unregister(){
if(!dom_last) if(!dom_last)
return false; return false;
keys.forEach(key=> Reflect.deleteProperty(globalThis, key)); Object.assign(env, env_bk);
Reflect.deleteProperty(globalThis, "window"); env_bk= {};
dom_last= undefined; dom_last= undefined;
return true; return true;
} }

245
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "deka-dom-el", "name": "deka-dom-el",
"version": "0.7.3", "version": "0.7.7",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "deka-dom-el", "name": "deka-dom-el",
"version": "0.7.3", "version": "0.7.7",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@size-limit/preset-small-lib": "^11.0.1", "@size-limit/preset-small-lib": "^11.0.1",
@ -21,10 +21,26 @@
"node": ">=18" "node": ">=18"
} }
}, },
"node_modules/@esbuild/aix-ppc64": {
"version": "0.19.11",
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.19.11.tgz",
"integrity": "sha512-FnzU0LyE3ySQk7UntJO4+qIiQgI7KoODnZg5xzXIrFJlKd2P2gwHsHY4927xj9y5PJmJSzULiUCWmv7iWnNa7g==",
"cpu": [
"ppc64"
],
"dev": true,
"optional": true,
"os": [
"aix"
],
"engines": {
"node": ">=12"
}
},
"node_modules/@esbuild/android-arm": { "node_modules/@esbuild/android-arm": {
"version": "0.19.9", "version": "0.19.11",
"resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.19.9.tgz", "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.19.11.tgz",
"integrity": "sha512-jkYjjq7SdsWuNI6b5quymW0oC83NN5FdRPuCbs9HZ02mfVdAP8B8eeqLSYU3gb6OJEaY5CQabtTFbqBf26H3GA==", "integrity": "sha512-5OVapq0ClabvKvQ58Bws8+wkLCV+Rxg7tUVbo9xu034Nm536QTII4YzhaFriQ7rMrorfnFKUsArD2lqKbFY4vw==",
"cpu": [ "cpu": [
"arm" "arm"
], ],
@ -38,9 +54,9 @@
} }
}, },
"node_modules/@esbuild/android-arm64": { "node_modules/@esbuild/android-arm64": {
"version": "0.19.9", "version": "0.19.11",
"resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.19.9.tgz", "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.19.11.tgz",
"integrity": "sha512-q4cR+6ZD0938R19MyEW3jEsMzbb/1rulLXiNAJQADD/XYp7pT+rOS5JGxvpRW8dFDEfjW4wLgC/3FXIw4zYglQ==", "integrity": "sha512-aiu7K/5JnLj//KOnOfEZ0D90obUkRzDMyqd/wNAUQ34m4YUPVhRZpnqKV9uqDGxT7cToSDnIHsGooyIczu9T+Q==",
"cpu": [ "cpu": [
"arm64" "arm64"
], ],
@ -54,9 +70,9 @@
} }
}, },
"node_modules/@esbuild/android-x64": { "node_modules/@esbuild/android-x64": {
"version": "0.19.9", "version": "0.19.11",
"resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.19.9.tgz", "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.19.11.tgz",
"integrity": "sha512-KOqoPntWAH6ZxDwx1D6mRntIgZh9KodzgNOy5Ebt9ghzffOk9X2c1sPwtM9P+0eXbefnDhqYfkh5PLP5ULtWFA==", "integrity": "sha512-eccxjlfGw43WYoY9QgB82SgGgDbibcqyDTlk3l3C0jOVHKxrjdc9CTwDUQd0vkvYg5um0OH+GpxYvp39r+IPOg==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@ -70,9 +86,9 @@
} }
}, },
"node_modules/@esbuild/darwin-arm64": { "node_modules/@esbuild/darwin-arm64": {
"version": "0.19.9", "version": "0.19.11",
"resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.19.9.tgz", "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.19.11.tgz",
"integrity": "sha512-KBJ9S0AFyLVx2E5D8W0vExqRW01WqRtczUZ8NRu+Pi+87opZn5tL4Y0xT0mA4FtHctd0ZgwNoN639fUUGlNIWw==", "integrity": "sha512-ETp87DRWuSt9KdDVkqSoKoLFHYTrkyz2+65fj9nfXsaV3bMhTCjtQfw3y+um88vGRKRiF7erPrh/ZuIdLUIVxQ==",
"cpu": [ "cpu": [
"arm64" "arm64"
], ],
@ -86,9 +102,9 @@
} }
}, },
"node_modules/@esbuild/darwin-x64": { "node_modules/@esbuild/darwin-x64": {
"version": "0.19.9", "version": "0.19.11",
"resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.19.9.tgz", "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.19.11.tgz",
"integrity": "sha512-vE0VotmNTQaTdX0Q9dOHmMTao6ObjyPm58CHZr1UK7qpNleQyxlFlNCaHsHx6Uqv86VgPmR4o2wdNq3dP1qyDQ==", "integrity": "sha512-fkFUiS6IUK9WYUO/+22omwetaSNl5/A8giXvQlcinLIjVkxwTLSktbF5f/kJMftM2MJp9+fXqZ5ezS7+SALp4g==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@ -102,9 +118,9 @@
} }
}, },
"node_modules/@esbuild/freebsd-arm64": { "node_modules/@esbuild/freebsd-arm64": {
"version": "0.19.9", "version": "0.19.11",
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.19.9.tgz", "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.19.11.tgz",
"integrity": "sha512-uFQyd/o1IjiEk3rUHSwUKkqZwqdvuD8GevWF065eqgYfexcVkxh+IJgwTaGZVu59XczZGcN/YMh9uF1fWD8j1g==", "integrity": "sha512-lhoSp5K6bxKRNdXUtHoNc5HhbXVCS8V0iZmDvyWvYq9S5WSfTIHU2UGjcGt7UeS6iEYp9eeymIl5mJBn0yiuxA==",
"cpu": [ "cpu": [
"arm64" "arm64"
], ],
@ -118,9 +134,9 @@
} }
}, },
"node_modules/@esbuild/freebsd-x64": { "node_modules/@esbuild/freebsd-x64": {
"version": "0.19.9", "version": "0.19.11",
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.19.9.tgz", "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.19.11.tgz",
"integrity": "sha512-WMLgWAtkdTbTu1AWacY7uoj/YtHthgqrqhf1OaEWnZb7PQgpt8eaA/F3LkV0E6K/Lc0cUr/uaVP/49iE4M4asA==", "integrity": "sha512-JkUqn44AffGXitVI6/AbQdoYAq0TEullFdqcMY/PCUZ36xJ9ZJRtQabzMA+Vi7r78+25ZIBosLTOKnUXBSi1Kw==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@ -134,9 +150,9 @@
} }
}, },
"node_modules/@esbuild/linux-arm": { "node_modules/@esbuild/linux-arm": {
"version": "0.19.9", "version": "0.19.11",
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.19.9.tgz", "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.19.11.tgz",
"integrity": "sha512-C/ChPohUYoyUaqn1h17m/6yt6OB14hbXvT8EgM1ZWaiiTYz7nWZR0SYmMnB5BzQA4GXl3BgBO1l8MYqL/He3qw==", "integrity": "sha512-3CRkr9+vCV2XJbjwgzjPtO8T0SZUmRZla+UL1jw+XqHZPkPgZiyWvbDvl9rqAN8Zl7qJF0O/9ycMtjU67HN9/Q==",
"cpu": [ "cpu": [
"arm" "arm"
], ],
@ -150,9 +166,9 @@
} }
}, },
"node_modules/@esbuild/linux-arm64": { "node_modules/@esbuild/linux-arm64": {
"version": "0.19.9", "version": "0.19.11",
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.19.9.tgz", "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.19.11.tgz",
"integrity": "sha512-PiPblfe1BjK7WDAKR1Cr9O7VVPqVNpwFcPWgfn4xu0eMemzRp442hXyzF/fSwgrufI66FpHOEJk0yYdPInsmyQ==", "integrity": "sha512-LneLg3ypEeveBSMuoa0kwMpCGmpu8XQUh+mL8XXwoYZ6Be2qBnVtcDI5azSvh7vioMDhoJFZzp9GWp9IWpYoUg==",
"cpu": [ "cpu": [
"arm64" "arm64"
], ],
@ -166,9 +182,9 @@
} }
}, },
"node_modules/@esbuild/linux-ia32": { "node_modules/@esbuild/linux-ia32": {
"version": "0.19.9", "version": "0.19.11",
"resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.19.9.tgz", "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.19.11.tgz",
"integrity": "sha512-f37i/0zE0MjDxijkPSQw1CO/7C27Eojqb+r3BbHVxMLkj8GCa78TrBZzvPyA/FNLUMzP3eyHCVkAopkKVja+6Q==", "integrity": "sha512-caHy++CsD8Bgq2V5CodbJjFPEiDPq8JJmBdeyZ8GWVQMjRD0sU548nNdwPNvKjVpamYYVL40AORekgfIubwHoA==",
"cpu": [ "cpu": [
"ia32" "ia32"
], ],
@ -182,9 +198,9 @@
} }
}, },
"node_modules/@esbuild/linux-loong64": { "node_modules/@esbuild/linux-loong64": {
"version": "0.19.9", "version": "0.19.11",
"resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.19.9.tgz", "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.19.11.tgz",
"integrity": "sha512-t6mN147pUIf3t6wUt3FeumoOTPfmv9Cc6DQlsVBpB7eCpLOqQDyWBP1ymXn1lDw4fNUSb/gBcKAmvTP49oIkaA==", "integrity": "sha512-ppZSSLVpPrwHccvC6nQVZaSHlFsvCQyjnvirnVjbKSHuE5N24Yl8F3UwYUUR1UEPaFObGD2tSvVKbvR+uT1Nrg==",
"cpu": [ "cpu": [
"loong64" "loong64"
], ],
@ -198,9 +214,9 @@
} }
}, },
"node_modules/@esbuild/linux-mips64el": { "node_modules/@esbuild/linux-mips64el": {
"version": "0.19.9", "version": "0.19.11",
"resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.19.9.tgz", "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.19.11.tgz",
"integrity": "sha512-jg9fujJTNTQBuDXdmAg1eeJUL4Jds7BklOTkkH80ZgQIoCTdQrDaHYgbFZyeTq8zbY+axgptncko3v9p5hLZtw==", "integrity": "sha512-B5x9j0OgjG+v1dF2DkH34lr+7Gmv0kzX6/V0afF41FkPMMqaQ77pH7CrhWeR22aEeHKaeZVtZ6yFwlxOKPVFyg==",
"cpu": [ "cpu": [
"mips64el" "mips64el"
], ],
@ -214,9 +230,9 @@
} }
}, },
"node_modules/@esbuild/linux-ppc64": { "node_modules/@esbuild/linux-ppc64": {
"version": "0.19.9", "version": "0.19.11",
"resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.19.9.tgz", "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.19.11.tgz",
"integrity": "sha512-tkV0xUX0pUUgY4ha7z5BbDS85uI7ABw3V1d0RNTii7E9lbmV8Z37Pup2tsLV46SQWzjOeyDi1Q7Wx2+QM8WaCQ==", "integrity": "sha512-MHrZYLeCG8vXblMetWyttkdVRjQlQUb/oMgBNurVEnhj4YWOr4G5lmBfZjHYQHHN0g6yDmCAQRR8MUHldvvRDA==",
"cpu": [ "cpu": [
"ppc64" "ppc64"
], ],
@ -230,9 +246,9 @@
} }
}, },
"node_modules/@esbuild/linux-riscv64": { "node_modules/@esbuild/linux-riscv64": {
"version": "0.19.9", "version": "0.19.11",
"resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.19.9.tgz", "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.19.11.tgz",
"integrity": "sha512-DfLp8dj91cufgPZDXr9p3FoR++m3ZJ6uIXsXrIvJdOjXVREtXuQCjfMfvmc3LScAVmLjcfloyVtpn43D56JFHg==", "integrity": "sha512-f3DY++t94uVg141dozDu4CCUkYW+09rWtaWfnb3bqe4w5NqmZd6nPVBm+qbz7WaHZCoqXqHz5p6CM6qv3qnSSQ==",
"cpu": [ "cpu": [
"riscv64" "riscv64"
], ],
@ -246,9 +262,9 @@
} }
}, },
"node_modules/@esbuild/linux-s390x": { "node_modules/@esbuild/linux-s390x": {
"version": "0.19.9", "version": "0.19.11",
"resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.19.9.tgz", "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.19.11.tgz",
"integrity": "sha512-zHbglfEdC88KMgCWpOl/zc6dDYJvWGLiUtmPRsr1OgCViu3z5GncvNVdf+6/56O2Ca8jUU+t1BW261V6kp8qdw==", "integrity": "sha512-A5xdUoyWJHMMlcSMcPGVLzYzpcY8QP1RtYzX5/bS4dvjBGVxdhuiYyFwp7z74ocV7WDc0n1harxmpq2ePOjI0Q==",
"cpu": [ "cpu": [
"s390x" "s390x"
], ],
@ -262,9 +278,9 @@
} }
}, },
"node_modules/@esbuild/linux-x64": { "node_modules/@esbuild/linux-x64": {
"version": "0.19.9", "version": "0.19.11",
"resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.19.9.tgz", "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.19.11.tgz",
"integrity": "sha512-JUjpystGFFmNrEHQnIVG8hKwvA2DN5o7RqiO1CVX8EN/F/gkCjkUMgVn6hzScpwnJtl2mPR6I9XV1oW8k9O+0A==", "integrity": "sha512-grbyMlVCvJSfxFQUndw5mCtWs5LO1gUlwP4CDi4iJBbVpZcqLVT29FxgGuBJGSzyOxotFG4LoO5X+M1350zmPA==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@ -278,9 +294,9 @@
} }
}, },
"node_modules/@esbuild/netbsd-x64": { "node_modules/@esbuild/netbsd-x64": {
"version": "0.19.9", "version": "0.19.11",
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.19.9.tgz", "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.19.11.tgz",
"integrity": "sha512-GThgZPAwOBOsheA2RUlW5UeroRfESwMq/guy8uEe3wJlAOjpOXuSevLRd70NZ37ZrpO6RHGHgEHvPg1h3S1Jug==", "integrity": "sha512-13jvrQZJc3P230OhU8xgwUnDeuC/9egsjTkXN49b3GcS5BKvJqZn86aGM8W9pd14Kd+u7HuFBMVtrNGhh6fHEQ==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@ -294,9 +310,9 @@
} }
}, },
"node_modules/@esbuild/openbsd-x64": { "node_modules/@esbuild/openbsd-x64": {
"version": "0.19.9", "version": "0.19.11",
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.19.9.tgz", "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.19.11.tgz",
"integrity": "sha512-Ki6PlzppaFVbLnD8PtlVQfsYw4S9n3eQl87cqgeIw+O3sRr9IghpfSKY62mggdt1yCSZ8QWvTZ9jo9fjDSg9uw==", "integrity": "sha512-ysyOGZuTp6SNKPE11INDUeFVVQFrhcNDVUgSQVDzqsqX38DjhPEPATpid04LCoUr2WXhQTEZ8ct/EgJCUDpyNw==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@ -310,9 +326,9 @@
} }
}, },
"node_modules/@esbuild/sunos-x64": { "node_modules/@esbuild/sunos-x64": {
"version": "0.19.9", "version": "0.19.11",
"resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.19.9.tgz", "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.19.11.tgz",
"integrity": "sha512-MLHj7k9hWh4y1ddkBpvRj2b9NCBhfgBt3VpWbHQnXRedVun/hC7sIyTGDGTfsGuXo4ebik2+3ShjcPbhtFwWDw==", "integrity": "sha512-Hf+Sad9nVwvtxy4DXCZQqLpgmRTQqyFyhT3bZ4F2XlJCjxGmRFF0Shwn9rzhOYRB61w9VMXUkxlBy56dk9JJiQ==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@ -326,9 +342,9 @@
} }
}, },
"node_modules/@esbuild/win32-arm64": { "node_modules/@esbuild/win32-arm64": {
"version": "0.19.9", "version": "0.19.11",
"resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.19.9.tgz", "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.19.11.tgz",
"integrity": "sha512-GQoa6OrQ8G08guMFgeXPH7yE/8Dt0IfOGWJSfSH4uafwdC7rWwrfE6P9N8AtPGIjUzdo2+7bN8Xo3qC578olhg==", "integrity": "sha512-0P58Sbi0LctOMOQbpEOvOL44Ne0sqbS0XWHMvvrg6NE5jQ1xguCSSw9jQeUk2lfrXYsKDdOe6K+oZiwKPilYPQ==",
"cpu": [ "cpu": [
"arm64" "arm64"
], ],
@ -342,9 +358,9 @@
} }
}, },
"node_modules/@esbuild/win32-ia32": { "node_modules/@esbuild/win32-ia32": {
"version": "0.19.9", "version": "0.19.11",
"resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.19.9.tgz", "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.19.11.tgz",
"integrity": "sha512-UOozV7Ntykvr5tSOlGCrqU3NBr3d8JqPes0QWN2WOXfvkWVGRajC+Ym0/Wj88fUgecUCLDdJPDF0Nna2UK3Qtg==", "integrity": "sha512-6YOrWS+sDJDmshdBIQU+Uoyh7pQKrdykdefC1avn76ss5c+RN6gut3LZA4E2cH5xUEp5/cA0+YxRaVtRAb0xBg==",
"cpu": [ "cpu": [
"ia32" "ia32"
], ],
@ -358,9 +374,9 @@
} }
}, },
"node_modules/@esbuild/win32-x64": { "node_modules/@esbuild/win32-x64": {
"version": "0.19.9", "version": "0.19.11",
"resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.19.9.tgz", "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.19.11.tgz",
"integrity": "sha512-oxoQgglOP7RH6iasDrhY+R/3cHrfwIDvRlT4CGChflq6twk8iENeVvMJjmvBb94Ik1Z+93iGO27err7w6l54GQ==", "integrity": "sha512-vfkhltrjCAb603XaFhqhAF4LGDi2M4OrCRrFusyQ+iTLQ/o60QQXxc9cZC/FFpihBI9N1Grn6SMKVJ4KP7Fuiw==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@ -485,9 +501,9 @@
"dev": true "dev": true
}, },
"node_modules/@types/node": { "node_modules/@types/node": {
"version": "20.10.4", "version": "20.10.6",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.4.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.6.tgz",
"integrity": "sha512-D08YG6rr8X90YB56tSIuBaddy/UXAA9RKJoFvrsnogAum/0pmjkgi4+2nx96A330FmioegBWmEYQ+syqCFaveg==", "integrity": "sha512-Vac8H+NlRNNlAmDfGUP7b5h/KA+AtWIzuXy0E6OyP8f1tCLYAtPvKRRDJjAPqhpCb0t6U2j7/xqAuLEebW2kiw==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"undici-types": "~5.26.4" "undici-types": "~5.26.4"
@ -756,15 +772,15 @@
} }
}, },
"node_modules/cssstyle": { "node_modules/cssstyle": {
"version": "3.0.0", "version": "4.0.1",
"resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-3.0.0.tgz", "resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-4.0.1.tgz",
"integrity": "sha512-N4u2ABATi3Qplzf0hWbVCdjenim8F3ojEXpBDF5hBpjzW182MjNGLqfmQ0SkSPeQ+V86ZXgeH8aXj6kayd4jgg==", "integrity": "sha512-8ZYiJ3A/3OkDd093CBT/0UKDWry7ak4BdPTFP2+QEP7cmhouyq/Up709ASSj2cK02BbZiMgk7kYjZNS4QP5qrQ==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"rrweb-cssom": "^0.6.0" "rrweb-cssom": "^0.6.0"
}, },
"engines": { "engines": {
"node": ">=14" "node": ">=18"
} }
}, },
"node_modules/data-uri-to-buffer": { "node_modules/data-uri-to-buffer": {
@ -905,9 +921,9 @@
"dev": true "dev": true
}, },
"node_modules/esbuild": { "node_modules/esbuild": {
"version": "0.19.9", "version": "0.19.11",
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.19.9.tgz", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.19.11.tgz",
"integrity": "sha512-U9CHtKSy+EpPsEBa+/A2gMs/h3ylBC0H0KSqIg7tpztHerLi6nrrcoUJAkNCEPumx8yJ+Byic4BVwHgRbN0TBg==", "integrity": "sha512-HJ96Hev2hX/6i5cDVwcqiJBBtuo9+FeIJOtZ9W1kA5M6AMJRHUZlpYZ1/SbEwtO0ioNAW8rUooVpC/WehY2SfA==",
"dev": true, "dev": true,
"hasInstallScript": true, "hasInstallScript": true,
"bin": { "bin": {
@ -917,28 +933,29 @@
"node": ">=12" "node": ">=12"
}, },
"optionalDependencies": { "optionalDependencies": {
"@esbuild/android-arm": "0.19.9", "@esbuild/aix-ppc64": "0.19.11",
"@esbuild/android-arm64": "0.19.9", "@esbuild/android-arm": "0.19.11",
"@esbuild/android-x64": "0.19.9", "@esbuild/android-arm64": "0.19.11",
"@esbuild/darwin-arm64": "0.19.9", "@esbuild/android-x64": "0.19.11",
"@esbuild/darwin-x64": "0.19.9", "@esbuild/darwin-arm64": "0.19.11",
"@esbuild/freebsd-arm64": "0.19.9", "@esbuild/darwin-x64": "0.19.11",
"@esbuild/freebsd-x64": "0.19.9", "@esbuild/freebsd-arm64": "0.19.11",
"@esbuild/linux-arm": "0.19.9", "@esbuild/freebsd-x64": "0.19.11",
"@esbuild/linux-arm64": "0.19.9", "@esbuild/linux-arm": "0.19.11",
"@esbuild/linux-ia32": "0.19.9", "@esbuild/linux-arm64": "0.19.11",
"@esbuild/linux-loong64": "0.19.9", "@esbuild/linux-ia32": "0.19.11",
"@esbuild/linux-mips64el": "0.19.9", "@esbuild/linux-loong64": "0.19.11",
"@esbuild/linux-ppc64": "0.19.9", "@esbuild/linux-mips64el": "0.19.11",
"@esbuild/linux-riscv64": "0.19.9", "@esbuild/linux-ppc64": "0.19.11",
"@esbuild/linux-s390x": "0.19.9", "@esbuild/linux-riscv64": "0.19.11",
"@esbuild/linux-x64": "0.19.9", "@esbuild/linux-s390x": "0.19.11",
"@esbuild/netbsd-x64": "0.19.9", "@esbuild/linux-x64": "0.19.11",
"@esbuild/openbsd-x64": "0.19.9", "@esbuild/netbsd-x64": "0.19.11",
"@esbuild/sunos-x64": "0.19.9", "@esbuild/openbsd-x64": "0.19.11",
"@esbuild/win32-arm64": "0.19.9", "@esbuild/sunos-x64": "0.19.11",
"@esbuild/win32-ia32": "0.19.9", "@esbuild/win32-arm64": "0.19.11",
"@esbuild/win32-x64": "0.19.9" "@esbuild/win32-ia32": "0.19.11",
"@esbuild/win32-x64": "0.19.11"
} }
}, },
"node_modules/event-target-shim": { "node_modules/event-target-shim": {
@ -976,9 +993,9 @@
} }
}, },
"node_modules/fastq": { "node_modules/fastq": {
"version": "1.15.0", "version": "1.16.0",
"resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.16.0.tgz",
"integrity": "sha512-wBrocU2LCXXa+lWBt8RoIRD89Fi8OdABODa/kEnyeyjS5aZO5/GNvI5sEINADqP/h8M29UHTHUb53sUu5Ihqdw==", "integrity": "sha512-ifCoaXsDrsdkWTtiNJX5uzHDsrck5TzfKKDcuFFTIrrc/BS076qgEIfoIy1VeZqViznfKiysPYTh/QeHtnIsYA==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"reusify": "^1.0.4" "reusify": "^1.0.4"
@ -1329,12 +1346,12 @@
"dev": true "dev": true
}, },
"node_modules/jsdom": { "node_modules/jsdom": {
"version": "23.0.1", "version": "23.1.0",
"resolved": "https://registry.npmjs.org/jsdom/-/jsdom-23.0.1.tgz", "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-23.1.0.tgz",
"integrity": "sha512-2i27vgvlUsGEBO9+/kJQRbtqtm+191b5zAZrU/UezVmnC2dlDAFLgDYJvAEi94T4kjsRKkezEtLQTgsNEsW2lQ==", "integrity": "sha512-wRscu8dBFxi7O65Cvi0jFRDv0Qa7XEHPix8Qg/vlXHLAMQsRWV1EDeQHBermzXf4Dt7JtFgBLbva3iTcBZDXEQ==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"cssstyle": "^3.0.0", "cssstyle": "^4.0.1",
"data-urls": "^5.0.0", "data-urls": "^5.0.0",
"decimal.js": "^10.4.3", "decimal.js": "^10.4.3",
"form-data": "^4.0.0", "form-data": "^4.0.0",
@ -1353,7 +1370,7 @@
"whatwg-encoding": "^3.1.1", "whatwg-encoding": "^3.1.1",
"whatwg-mimetype": "^4.0.0", "whatwg-mimetype": "^4.0.0",
"whatwg-url": "^14.0.0", "whatwg-url": "^14.0.0",
"ws": "^8.14.2", "ws": "^8.16.0",
"xml-name-validator": "^5.0.0" "xml-name-validator": "^5.0.0"
}, },
"engines": { "engines": {
@ -2156,9 +2173,9 @@
} }
}, },
"node_modules/web-streams-polyfill": { "node_modules/web-streams-polyfill": {
"version": "3.2.1", "version": "3.3.2",
"resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.2.tgz",
"integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==", "integrity": "sha512-3pRGuxRF5gpuZc0W+EpwQRmCD7gRqcDOMt688KmdlDAgAyaB1XlN0zq2njfDNm44XVdIouE7pZ6GzbdyH47uIQ==",
"dev": true, "dev": true,
"engines": { "engines": {
"node": ">= 8" "node": ">= 8"
@ -2231,9 +2248,9 @@
"dev": true "dev": true
}, },
"node_modules/ws": { "node_modules/ws": {
"version": "8.15.1", "version": "8.16.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.15.1.tgz", "resolved": "https://registry.npmjs.org/ws/-/ws-8.16.0.tgz",
"integrity": "sha512-W5OZiCjXEmk0yZ66ZN82beM5Sz7l7coYxpRkzS+p9PP+ToQry8szKh+61eNktr7EA9DOwvFGhfC605jDHbP6QQ==", "integrity": "sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==",
"dev": true, "dev": true,
"engines": { "engines": {
"node": ">=10.0.0" "node": ">=10.0.0"

View File

@ -1,6 +1,6 @@
{ {
"name": "deka-dom-el", "name": "deka-dom-el",
"version": "0.7.6", "version": "0.7.7",
"description": "A low-code library that simplifies the creation of native DOM elements/components using small wrappers and tweaks.", "description": "A low-code library that simplifies the creation of native DOM elements/components using small wrappers and tweaks.",
"author": "Jan Andrle <andrle.jan@centrum.cz>", "author": "Jan Andrle <andrle.jan@centrum.cz>",
"license": "MIT", "license": "MIT",
@ -59,7 +59,7 @@
"size-limit": [ "size-limit": [
{ {
"path": "./index.js", "path": "./index.js",
"limit": "9.85 kB", "limit": "10 kB",
"gzip": false, "gzip": false,
"brotli": false "brotli": false

View File

@ -1,4 +1,12 @@
export const enviroment= { setDeleteAttr, ssr: "" }; export const enviroment= {
setDeleteAttr,
ssr: "",
D: globalThis.document,
F: globalThis.DocumentFragment,
H: globalThis.HTMLElement,
S: globalThis.SVGElement,
M: globalThis.MutationObserver,
};
import { isUndef } from './helpers.js'; import { isUndef } from './helpers.js';
function setDeleteAttr(obj, prop, val){ function setDeleteAttr(obj, prop, val){
/* Issue /* Issue
@ -13,7 +21,7 @@ function setDeleteAttr(obj, prop, val){
Reflect.set(obj, prop, val); Reflect.set(obj, prop, val);
if(!isUndef(val)) return; if(!isUndef(val)) return;
Reflect.deleteProperty(obj, prop); Reflect.deleteProperty(obj, prop);
if(obj instanceof HTMLElement && obj.getAttribute(prop)==="undefined") if(obj instanceof enviroment.H && obj.getAttribute(prop)==="undefined")
return obj.removeAttribute(prop); return obj.removeAttribute(prop);
if(Reflect.get(obj, prop)==="undefined") if(Reflect.get(obj, prop)==="undefined")
return Reflect.set(obj, prop, ""); return Reflect.set(obj, prop, "");

View File

@ -1,10 +1,10 @@
import { observables } from "./observables-common.js"; import { observables } from "./observables-common.js";
import { enviroment } from './dom-common.js'; import { enviroment as env } from './dom-common.js';
/** @type {{ scope: object, prevent: boolean, host: function }[]} */ /** @type {{ scope: object, prevent: boolean, host: function }[]} */
const scopes= [ { const scopes= [ {
scope: document.body, get scope(){ return env.D.body; },
host: c=> c ? c(document.body) : document.body, host: c=> c ? c(env.D.body) : env.D.body,
custom_element: false, custom_element: false,
prevent: true, prevent: true,
} ]; } ];
@ -43,7 +43,7 @@ export function createElement(tag, attributes, ...addons){
scoped= 1; scoped= 1;
scope.push({ scope: tag, host: (...c)=> c.length ? (scoped===1 ? addons.unshift(...c) : c.forEach(c=> c(el_host)), undefined) : el_host }); scope.push({ scope: tag, host: (...c)=> c.length ? (scoped===1 ? addons.unshift(...c) : c.forEach(c=> c(el_host)), undefined) : el_host });
el= tag(attributes || undefined); el= tag(attributes || undefined);
const is_fragment= el instanceof DocumentFragment; const is_fragment= el instanceof env.F;
if(el.nodeName==="#comment") break; if(el.nodeName==="#comment") break;
const el_mark= createElement.mark({ const el_mark= createElement.mark({
type: "component", type: "component",
@ -54,10 +54,10 @@ export function createElement(tag, attributes, ...addons){
if(is_fragment) el_host= el_mark; if(is_fragment) el_host= el_mark;
break; break;
} }
case tag==="#text": el= assign.call(this, document.createTextNode(""), attributes); break; case tag==="#text": el= assign.call(this, env.D.createTextNode(""), attributes); break;
case tag==="<>" || !tag: el= assign.call(this, document.createDocumentFragment(), attributes); break; case tag==="<>" || !tag: el= assign.call(this, env.D.createDocumentFragment(), attributes); break;
case Boolean(namespace): el= assign.call(this, document.createElementNS(namespace, tag), attributes); break; case Boolean(namespace): el= assign.call(this, env.D.createElementNS(namespace, tag), attributes); break;
case !el: el= assign.call(this, document.createElement(tag), attributes); case !el: el= assign.call(this, env.D.createElement(tag), attributes);
} }
chainableAppend(el); chainableAppend(el);
if(!el_host) el_host= el; if(!el_host) el_host= el;
@ -76,7 +76,7 @@ export function simulateSlots(element, root= element, mapper= undefined){
apply(orig, _, els){ apply(orig, _, els){
if(!els.length) return element; if(!els.length) return element;
const d= document.createDocumentFragment(); const d= env.D.createDocumentFragment();
for(const el of els){ for(const el of els){
if(!el || !el.slot){ if(has_d) d.appendChild(el); continue; } if(!el || !el.slot){ if(has_d) d.appendChild(el); continue; }
const name= el.slot; const name= el.slot;
@ -113,8 +113,8 @@ function simulateSlotReplace(slot, element, mapper){
createElement.mark= function(attrs, is_open= false){ createElement.mark= function(attrs, is_open= false){
attrs= Object.entries(attrs).map(([ n, v ])=> n+`="${v}"`).join(" "); attrs= Object.entries(attrs).map(([ n, v ])=> n+`="${v}"`).join(" ");
const end= is_open ? "" : "/"; const end= is_open ? "" : "/";
const out= document.createComment(`<dde:mark ${attrs}${enviroment.ssr}${end}>`); const out= env.D.createComment(`<dde:mark ${attrs}${env.ssr}${end}>`);
if(!is_open) out.end= document.createComment("</dde:mark>"); if(!is_open) out.end= env.D.createComment("</dde:mark>");
return out; return out;
}; };
export { createElement as el }; export { createElement as el };
@ -131,8 +131,8 @@ export function createElementNS(ns){
} }
export { createElementNS as elNS }; export { createElementNS as elNS };
const { setDeleteAttr }= enviroment;
const assign_context= new WeakMap(); const assign_context= new WeakMap();
const { setDeleteAttr }= env;
export function assign(element, ...attributes){ export function assign(element, ...attributes){
if(!attributes.length) return element; if(!attributes.length) return element;
assign_context.set(element, assignContext(element, this)); assign_context.set(element, assignContext(element, this));
@ -175,7 +175,7 @@ export function assignAttribute(element, key, value){
} }
function assignContext(element, _this){ function assignContext(element, _this){
if(assign_context.has(element)) return assign_context.get(element); if(assign_context.has(element)) return assign_context.get(element);
const is_svg= element instanceof SVGElement; const is_svg= element instanceof env.S;
const setRemoveAttr= (is_svg ? setRemoveNS : setRemove).bind(null, element, "Attribute"); const setRemoveAttr= (is_svg ? setRemoveNS : setRemove).bind(null, element, "Attribute");
const s= observables(_this); const s= observables(_this);
return { setRemoveAttr, s }; return { setRemoveAttr, s };
@ -192,7 +192,7 @@ export function empty(el){
return el; return el;
} }
export function elementAttribute(element, op, key, value){ export function elementAttribute(element, op, key, value){
if(element instanceof HTMLElement) if(element instanceof env.H)
return element[op+"Attribute"](key, value); return element[op+"Attribute"](key, value);
return element[op+"AttributeNS"](null, key, value); return element[op+"AttributeNS"](null, key, value);
} }

View File

@ -1,4 +1,5 @@
export { registerReactivity } from './observables-common.js'; export { registerReactivity } from './observables-common.js';
import { enviroment as env } from './dom-common.js';
export function dispatchEvent(name, options, host){ export function dispatchEvent(name, options, host){
if(!options) options= {}; if(!options) options= {};
@ -18,7 +19,9 @@ export function on(event, listener, options){
}; };
} }
const c_ch_o= connectionsChangesObserverConstructor(); const c_ch_o= env.M ? connectionsChangesObserverConstructor() : new Proxy({}, {
get(){ return ()=> {}; }
});
const els_attribute_store= new WeakSet(); const els_attribute_store= new WeakSet();
import { scope } from "./dom.js"; import { scope } from "./dom.js";
import { onAbort } from './helpers.js'; import { onAbort } from './helpers.js';
@ -77,7 +80,9 @@ on.attributeChanged= function(listener, options){
if(element.__dde_lifecycleToEvents || els_attribute_store.has(element)) if(element.__dde_lifecycleToEvents || els_attribute_store.has(element))
return element; return element;
const observer= new MutationObserver(function(mutations){ if(!env.M) return element;
const observer= new env.M(function(mutations){
for(const { attributeName, target } of mutations) for(const { attributeName, target } of mutations)
target.dispatchEvent( target.dispatchEvent(
new CustomEvent(event, { detail: [ attributeName, target.getAttribute(attributeName) ] })); new CustomEvent(event, { detail: [ attributeName, target.getAttribute(attributeName) ] }));
@ -92,7 +97,7 @@ on.attributeChanged= function(listener, options){
function connectionsChangesObserverConstructor(){ function connectionsChangesObserverConstructor(){
const store= new Map(); const store= new Map();
let is_observing= false; let is_observing= false;
const observer= new MutationObserver(function(mutations){ const observer= new env.M(function(mutations){
for(const mutation of mutations){ for(const mutation of mutations){
if(mutation.type!=="childList") continue; if(mutation.type!=="childList") continue;
if(observerAdded(mutation.addedNodes, true)){ if(observerAdded(mutation.addedNodes, true)){
@ -155,7 +160,7 @@ function connectionsChangesObserverConstructor(){
function start(){ function start(){
if(is_observing) return; if(is_observing) return;
is_observing= true; is_observing= true;
observer.observe(document.body, { childList: true, subtree: true }); observer.observe(env.D.body, { childList: true, subtree: true });
} }
function stop(){ function stop(){
if(!is_observing || store.size) return; if(!is_observing || store.size) return;
@ -166,13 +171,13 @@ function connectionsChangesObserverConstructor(){
function requestIdle(){ return new Promise(function(resolve){ function requestIdle(){ return new Promise(function(resolve){
(requestIdleCallback || requestAnimationFrame)(resolve); (requestIdleCallback || requestAnimationFrame)(resolve);
}); } }); }
async function collectChildren(element){ async function collectChildren(element, filter){
if(store.size > 30)//TODO limit? if(store.size > 30)//TODO limit?
await requestIdle(); await requestIdle();
const out= []; const out= [];
if(!(element instanceof Node)) return out; if(!(element instanceof Node)) return out;
for(const el of store.keys()){ for(const el of store.keys()){
if(el===element || !(el instanceof Node)) continue; if(el===element || !(el instanceof Node) || filter(el)) continue;
if(element.contains(el)) if(element.contains(el))
out.push(el); out.push(el);
} }
@ -181,7 +186,7 @@ function connectionsChangesObserverConstructor(){
function observerAdded(addedNodes, is_root){ function observerAdded(addedNodes, is_root){
let out= false; let out= false;
for(const element of addedNodes){ for(const element of addedNodes){
if(is_root) collectChildren(element).then(observerAdded); if(is_root) collectChildren(element, el=> !el.isConnectedd).then(observerAdded);
if(!store.has(element)) continue; if(!store.has(element)) continue;
const ls= store.get(element); const ls= store.get(element);
@ -198,7 +203,7 @@ function connectionsChangesObserverConstructor(){
function observerRemoved(removedNodes, is_root){ function observerRemoved(removedNodes, is_root){
let out= false; let out= false;
for(const element of removedNodes){ for(const element of removedNodes){
if(is_root) collectChildren(element).then(observerRemoved); if(is_root) collectChildren(element, el=> el.isConnectedd).then(observerRemoved);
if(!store.has(element)) continue; if(!store.has(element)) continue;
const ls= store.get(element); const ls= store.get(element);

View File

@ -86,12 +86,13 @@ observable.clear= function(...observables){
} }
}; };
const key_reactive= "__dde_reactive"; const key_reactive= "__dde_reactive";
import { el, elementAttribute } from "./dom.js"; import { enviroment as env } from "./dom-common.js";
import { el } from "./dom.js";
import { scope } from "./dom.js"; import { scope } from "./dom.js";
observable.el= function(o, map){ observable.el= function(o, map){
const mark_start= el.mark({ type: "reactive" }, false); const mark_start= el.mark({ type: "reactive" }, false);
const mark_end= mark_start.end; const mark_end= mark_start.end;
const out= document.createDocumentFragment(); const out= env.D.createDocumentFragment();
out.append(mark_start, mark_end); out.append(mark_start, mark_end);
const { current }= scope; const { current }= scope;
const reRenderReactiveElement= v=> { const reRenderReactiveElement= v=> {
@ -249,7 +250,7 @@ function removeObservableListener(o, listener, clear_when_empty){
if(!s) return; if(!s) return;
const out= s.listeners.delete(listener); const out= s.listeners.delete(listener);
if(clear_when_empty && !s.listeners.size){ if(clear_when_empty && !s.listeners.size){
o.clear(o); observable.clear(o);
if(!deps.has(s)) return out; if(!deps.has(s)) return out;
const c= deps.get(s); const c= deps.get(s);
if(!deps.has(c)) return out; if(!deps.has(c)) return out;