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

♻️ remove/change type definitions

This commit is contained in:
Jan Andrle 2023-10-12 10:48:44 +02:00
parent 6a52972373
commit b9bbd105a5
Signed by: jaandrle
GPG Key ID: B3A25AED155AFFAB
2 changed files with 18 additions and 33 deletions

View File

@ -59,11 +59,7 @@ export function todosComponent({ todos= [ "Task A" ] }= {}){
) )
} }
/** /**
* @type {ddeComponent< * @dispatch {number} remove
* { textContent: ddeSignal<string, any>, value: number },
* HTMLLIElement,
* [ "click" ]
* >}
* */ * */
function todoComponent({ textContent, value }){ function todoComponent({ textContent, value }){
const { host }= scope; const { host }= scope;

45
index.d.ts vendored
View File

@ -1,16 +1,6 @@
import { Signal } from "./signals";
//TODO?
/** Is filled when function is succesfully called ⇒ and returns component's root element. */
type Host<el extends Element>= (extender?: ElementExtender<el>)=> el | undefined;
declare global { declare global {
/** type ddeComponentAttributes= Record<any, any> | undefined | string;
* `ref` is filled when function is succesfully called and returns component's root element. type ddeElementExtender<El extends Element>= (element: El)=> El;
* */
type ddeComponent<
A extends Record<any, any>,
R extends Element,
T extends string[] = []
>= (attrs: A, ref: Host<R>)=> R & { _events: T };
} }
type ElementTagNameMap= HTMLElementTagNameMap & SVGElementTagNameMap & { type ElementTagNameMap= HTMLElementTagNameMap & SVGElementTagNameMap & {
'#text': Text '#text': Text
@ -48,43 +38,45 @@ type ElementAttributes<T extends keyof ElementTagNameMap | ElementTagNameMap[key
Omit<T,"classList"|"className"> & AttrsModified; Omit<T,"classList"|"className"> & AttrsModified;
export function assign<El extends Element>(element: El, ...attrs_array: Partial<ElementAttributes<El>>[]): El export function assign<El extends Element>(element: El, ...attrs_array: Partial<ElementAttributes<El>>[]): El
type ElementExtender<El extends Element>= (element: El)=> El;
type TagNameFragment= "<>"; type TagNameFragment= "<>";
export function el<TAG extends keyof ElementTagNameMap>( export function el<TAG extends keyof ElementTagNameMap>(
tag_name: TAG, tag_name: TAG,
attrs?: Partial<ElementAttributes<ElementTagNameMap[TAG]>>, attrs?: Partial<ElementAttributes<ElementTagNameMap[TAG]>>,
...extenders: ElementExtender<ElementTagNameMap[TAG]>[] ...extenders: ddeElementExtender<ElementTagNameMap[TAG]>[]
): ElementTagNameMap[TAG] ): ElementTagNameMap[TAG]
export function el<T>( export function el<T>(
tag_name: TagNameFragment, tag_name: TagNameFragment,
): DocumentFragment ): DocumentFragment
export function el<R extends Element, T extends (attrs: any, host: Host<R>)=> R>(
fComponent: T, export function el<
attrs?: Parameters<T>, A extends ddeComponentAttributes,
...extenders: ElementExtender<ReturnType<T>>[] C extends (attr: A)=> Element>(
): ReturnType<T> fComponent: C,
attrs?: A,
...extenders: ddeElementExtender<ReturnType<C>>[]
): ReturnType<C>
export function dispatchEvent(element: HTMLElement, name: keyof DocumentEventMap): void; export function dispatchEvent(element: HTMLElement, name: keyof DocumentEventMap): void;
export function dispatchEvent(element: HTMLElement, name: string, data: any): void; export function dispatchEvent(element: HTMLElement, name: string, data: any): void;
interface On{ interface On{
< <
EE extends ElementExtender<Element>, EE extends ddeElementExtender<Element>,
El extends ( EE extends ElementExtender<infer El> ? El : never ), El extends ( EE extends ddeElementExtender<infer El> ? El : never ),
Event extends keyof DocumentEventMap>( Event extends keyof DocumentEventMap>(
type: Event, type: Event,
listener: (this: El, ev: DocumentEventMap[Event]) => any, listener: (this: El, ev: DocumentEventMap[Event]) => any,
options?: AddEventListenerOptions options?: AddEventListenerOptions
) : EE; ) : EE;
connected< connected<
EE extends ElementExtender<Element>, EE extends ddeElementExtender<Element>,
El extends ( EE extends ElementExtender<infer El> ? El : never ) El extends ( EE extends ddeElementExtender<infer El> ? El : never )
>( >(
listener: (el: El) => any, listener: (el: El) => any,
options?: AddEventListenerOptions options?: AddEventListenerOptions
) : EE; ) : EE;
disconnected< disconnected<
EE extends ElementExtender<Element>, EE extends ddeElementExtender<Element>,
El extends ( EE extends ElementExtender<infer El> ? El : never ) El extends ( EE extends ddeElementExtender<infer El> ? El : never )
>( >(
listener: (el: El) => any, listener: (el: El) => any,
options?: AddEventListenerOptions options?: AddEventListenerOptions
@ -92,9 +84,6 @@ interface On{
} }
export const on: On; export const on: On;
//TODO?
export type Fires<T extends string[]>= ( (...a: any[])=> any ) & { events: T };
//TODO for SVG //TODO for SVG
declare global{ declare global{
interface HTMLDivElement{ append(...nodes: (Node | string)[]): HTMLDivElement; } interface HTMLDivElement{ append(...nodes: (Node | string)[]): HTMLDivElement; }