mirror of
https://github.com/jaandrle/deka-dom-el
synced 2025-07-01 12:22:15 +02:00
💥 📝
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
export const prop_process= { setDeleteAttr };
|
||||
export const enviroment= { setDeleteAttr, ssr: false };
|
||||
import { isUndef } from './helpers.js';
|
||||
function setDeleteAttr(obj, prop, val){
|
||||
/* Issue
|
||||
|
16
src/dom.js
16
src/dom.js
@ -1,11 +1,12 @@
|
||||
import { signals } from "./signals-common.js";
|
||||
import { enviroment } from './dom-common.js';
|
||||
|
||||
/** @type {{ scope: object, prevent: boolean, host: function }[]} */
|
||||
const scopes= [ {
|
||||
scope: document.body,
|
||||
host: c=> c ? c(document.body) : document.body,
|
||||
custom_element: false,
|
||||
prevent: true,
|
||||
inherit_host: false,
|
||||
} ];
|
||||
export const scope= {
|
||||
get current(){ return scopes[scopes.length-1]; },
|
||||
@ -25,7 +26,7 @@ export const scope= {
|
||||
};
|
||||
let namespace;
|
||||
export function createElement(tag, attributes, ...modifiers){
|
||||
/* jshint maxcomplexity: 16 */
|
||||
/* jshint maxcomplexity: 15 */
|
||||
const s= signals(this);
|
||||
let scoped= 0;
|
||||
let el, el_host;
|
||||
@ -35,15 +36,14 @@ export function createElement(tag, attributes, ...modifiers){
|
||||
switch(true){
|
||||
case typeof tag==="function": {
|
||||
scoped= 1;
|
||||
const { inherit_host, host: hostParent }= scope.current;
|
||||
const host= inherit_host ? hostParent : c=> c ? (scoped===1 ? modifiers.unshift(c) : c(el_host), undefined) : el_host;
|
||||
scope.push({ scope: tag, host, inherit_host });
|
||||
scope.push({ scope: tag, host: c=> c ? (scoped===1 ? modifiers.unshift(c) : c(el_host), undefined) : el_host });
|
||||
el= tag(attributes || undefined);
|
||||
const is_fragment= el instanceof DocumentFragment;
|
||||
if(el.nodeName==="#comment") break;
|
||||
const el_mark= createElement.mark({
|
||||
type: "component",
|
||||
name: tag.name,
|
||||
host: is_fragment ? "this" : ( el.nodeName==="#comment" ? "previousLater" : "parentElement" )
|
||||
host: is_fragment ? "this" : "parentElement",
|
||||
});
|
||||
el.prepend(el_mark);
|
||||
if(is_fragment) el_host= el_mark;
|
||||
@ -66,6 +66,7 @@ export function createElement(tag, attributes, ...modifiers){
|
||||
* @param {boolean} [is_open=false]
|
||||
* */
|
||||
createElement.mark= function(attrs, is_open= false){
|
||||
if(enviroment.ssr) attrs.ssr= true;
|
||||
attrs= Object.entries(attrs).map(([ n, v ])=> n+`="${v}"`).join(" ");
|
||||
const end= is_open ? "" : "/";
|
||||
const out= document.createComment(`<dde:mark ${attrs}${end}>`);
|
||||
@ -91,8 +92,7 @@ export function createElementNS(ns){
|
||||
}
|
||||
export { createElementNS as elNS };
|
||||
|
||||
import { prop_process } from './dom-common.js';
|
||||
const { setDeleteAttr }= prop_process;
|
||||
const { setDeleteAttr }= enviroment;
|
||||
const assign_context= new WeakMap();
|
||||
export function assign(element, ...attributes){
|
||||
if(!attributes.length) return element;
|
||||
|
@ -13,14 +13,17 @@ export function on(event, listener, options){
|
||||
|
||||
const c_ch_o= connectionsChangesObserverConstructor();
|
||||
const els_attribute_store= new WeakSet();
|
||||
import { scope } from "./dom.js";
|
||||
import { onAbort } from './helpers.js';
|
||||
//TODO: cleanUp when event before abort?
|
||||
on.connected= function(listener, options){
|
||||
const { custom_element }= scope.current;
|
||||
const name= "connected";
|
||||
if(typeof options !== "object")
|
||||
options= {};
|
||||
options.once= true;
|
||||
return function registerElement(element){
|
||||
if(custom_element) element= custom_element;
|
||||
const event= "dde:"+name;
|
||||
element.addEventListener(event, listener, options);
|
||||
if(element.__dde_lifecycleToEvents) return element;
|
||||
@ -32,11 +35,13 @@ on.connected= function(listener, options){
|
||||
};
|
||||
};
|
||||
on.disconnected= function(listener, options){
|
||||
const { custom_element }= scope.current;
|
||||
const name= "disconnected";
|
||||
if(typeof options !== "object")
|
||||
options= {};
|
||||
options.once= true;
|
||||
return function registerElement(element){
|
||||
if(custom_element) element= custom_element;
|
||||
const event= "dde:"+name;
|
||||
element.addEventListener(event, listener, options);
|
||||
if(element.__dde_lifecycleToEvents) return element;
|
||||
|
Reference in New Issue
Block a user