From 3866b29436281deeb16d3780d453b9b3835fef74 Mon Sep 17 00:00:00 2001 From: Jan Andrle Date: Tue, 7 Nov 2023 17:30:15 +0100 Subject: [PATCH] =?UTF-8?q?:hammer:=20ElementExtender=20=E2=86=92=20Elemen?= =?UTF-8?q?tModifier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.d.ts | 22 +++++++++++----------- src/dom.js | 6 +++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/index.d.ts b/index.d.ts index 57ca496..e7dbb53 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,6 +1,6 @@ declare global { type ddeComponentAttributes= Record | undefined | string; - type ddeElementExtender= (element: El)=> El; + type ddeElementModifier= (element: El)=> El; } type ElementTagNameMap= HTMLElementTagNameMap & { // & SVGElementTagNameMap '#text': Text @@ -41,7 +41,7 @@ export function assign(element: El, ...attrs_array: Partial< export function el( tag_name: TAG, attrs?: Partial>, - ...extenders: ddeElementExtender[] + ...modifiers: ddeElementModifier[] ): ElementTagNameMap[TAG] export function el( tag_name?: "<>", @@ -52,36 +52,36 @@ export function el< C extends (attr: A)=> Element | DocumentFragment>( fComponent: C, attrs?: A, - ...extenders: ddeElementExtender>[] + ...modifiers: ddeElementModifier>[] ): ReturnType export function el( tag_name: string, attrs?: Record, - ...extenders: ddeElementExtender[] + ...modifiers: ddeElementModifier[] ): HTMLElement export function dispatchEvent(element: HTMLElement, name: keyof DocumentEventMap): void; export function dispatchEvent(element: HTMLElement, name: string, data: any): void; interface On{ < - EE extends ddeElementExtender, - El extends ( EE extends ddeElementExtender ? El : never ), + EE extends ddeElementModifier, + El extends ( EE extends ddeElementModifier ? El : never ), Event extends keyof DocumentEventMap>( type: Event, listener: (this: El, ev: DocumentEventMap[Event]) => any, options?: AddEventListenerOptions ) : EE; connected< - EE extends ddeElementExtender, - El extends ( EE extends ddeElementExtender ? El : never ) + EE extends ddeElementModifier, + El extends ( EE extends ddeElementModifier ? El : never ) >( listener: (el: El) => any, options?: AddEventListenerOptions ) : EE; disconnected< - EE extends ddeElementExtender, - El extends ( EE extends ddeElementExtender ? El : never ) + EE extends ddeElementModifier, + El extends ( EE extends ddeElementModifier ? El : never ) >( listener: (el: El) => any, options?: AddEventListenerOptions @@ -91,7 +91,7 @@ export const on: On; export const scope: { namespace: string, - host: ddeElementExtender, + host: ddeElementModifier, elNamespace: (ns: string)=> ({ append(...els: (HTMLElement | SVGElement)[]): HTMLElement | SVGElement | DocumentFragment }) }; diff --git a/src/dom.js b/src/dom.js index 37f5c48..fc00d68 100644 --- a/src/dom.js +++ b/src/dom.js @@ -39,7 +39,7 @@ export const scope= { }, pop(){ return scopes.pop(); }, }; -export function createElement(tag, attributes, ...connect){ +export function createElement(tag, attributes, ...modifiers){ const s= signals(this); const { namespace }= scope; let scoped= 0; @@ -50,7 +50,7 @@ export function createElement(tag, attributes, ...connect){ switch(true){ case typeof tag==="function": { scoped= 1; - scope.push({ scope: tag, host: c=> c ? (scoped===1 ? connect.unshift(c) : c(el_host), undefined) : el_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; const el_mark= document.createComment(``); @@ -64,7 +64,7 @@ export function createElement(tag, attributes, ...connect){ case !el: el= assign.call(this, document.createElement(tag), attributes); } if(!el_host) el_host= el; - connect.forEach(c=> c(el_host)); + modifiers.forEach(c=> c(el_host)); if(scoped) scope.pop(); scoped= 2; return el;