From 64ddd3f41f0ac1de8a460da490362dcda5562fd7 Mon Sep 17 00:00:00 2001 From: Jan Andrle Date: Sun, 17 Dec 2023 13:22:58 +0100 Subject: [PATCH] :recycle: :bug: Update types --- docs_src/layout/head.html.js | 5 +---- docs_src/layout/simplePage.html.js | 2 +- index.d.ts | 32 ++++++++++++++++++------------ 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/docs_src/layout/head.html.js b/docs_src/layout/head.html.js index 58e1a3f..e55b41e 100644 --- a/docs_src/layout/head.html.js +++ b/docs_src/layout/head.html.js @@ -3,10 +3,7 @@ import { pages } from "../ssr.js"; /** * @param {object} def * @param {import("../types.d.ts").Info} def.info - * @param {object} def.pkg Package information. - * @param {string} def.pkg.name - * @param {string} def.pkg.description - * @param {string} def.pkg.homepage + * @param {import("../types.d.ts").Pkg} def.pkg Package information. * */ export function header({ info: { href, title, description }, pkg }){ title= `\`${pkg.name}\` — ${title}`; diff --git a/docs_src/layout/simplePage.html.js b/docs_src/layout/simplePage.html.js index a0c5eb9..8520843 100644 --- a/docs_src/layout/simplePage.html.js +++ b/docs_src/layout/simplePage.html.js @@ -4,7 +4,7 @@ import { el, simulateSlots } from "deka-dom-el"; import { header } from "./head.html.js"; import { prevNext } from "../components/pageUtils.html.js"; -/** @param {import("../types.d.ts").PageAttrs} attrs */ +/** @param {Pick} attrs */ export function simplePage({ pkg, info }){ return simulateSlots(el().append( el(header, { info, pkg }), diff --git a/index.d.ts b/index.d.ts index 7e0fae2..b152d18 100644 --- a/index.d.ts +++ b/index.d.ts @@ -43,18 +43,19 @@ type _fromElsInterfaces= Omit= Partial<_fromElsInterfaces & { [K in keyof _fromElsInterfaces]: Observable<_fromElsInterfaces[K], any> } & AttrsModified>; +type ElementAttributes= Partial<_fromElsInterfaces & { [K in keyof _fromElsInterfaces]: Observable<_fromElsInterfaces[K], any> } & AttrsModified> & Record; export function classListDeclarative(element: El, classList: AttrsModified["classList"]): El export function assign(element: El, ...attrs_array: ElementAttributes[]): El export function assignAttribute>(element: El, attr: ATT, value: ElementAttributes[ATT]): ElementAttributes[ATT] type ExtendedHTMLElementTagNameMap= HTMLElementTagNameMap & CustomElementTagNameMap & ddePublicElementTagNameMap +type textContent= string | ( (set?: string)=> string ); // TODO: for some reason `Observable` leads to `attrs?: any` export function el< TAG extends keyof ExtendedHTMLElementTagNameMap & string, EL extends (TAG extends keyof ExtendedHTMLElementTagNameMap ? ExtendedHTMLElementTagNameMap[TAG] : HTMLElement) >( tag_name: TAG, - attrs?: string | Observable | ElementAttributes, + attrs?: ElementAttributes | textContent, ...addons: ddeElementAddon[] ): TAG extends keyof ddeHTMLElementTagNameMap ? ddeHTMLElementTagNameMap[TAG] : ddeHTMLElement export function el( @@ -62,34 +63,39 @@ export function el( ): ddeDocumentFragment export function el< - A extends ddeComponentAttributes, - C extends (attr: Partial)=> SupportedElement | DocumentFragment + C extends (attr: ddeComponentAttributes)=> SupportedElement | ddeDocumentFragment >( component: C, - attrs?: A | string, + attrs?: Parameters[0] | textContent, ...addons: ddeElementAddon>[] -): ReturnType +): ReturnType extends ddeHTMLElementTagNameMap[keyof ddeHTMLElementTagNameMap] ? ReturnType : ddeHTMLElement export { el as createElement } export function elNS( namespace: "http://www.w3.org/2000/svg" -): ( +): < + TAG extends keyof SVGElementTagNameMap & string, + EL extends ( TAG extends keyof SVGElementTagNameMap ? SVGElementTagNameMap[TAG] : SVGElement ), +>( tag_name: TAG, - attrs?: string | Partial<{ [key in KEYS]: EL[key] | string | number | boolean }>, + attrs?: ElementAttributes | textContent, ...addons: ddeElementAddon[] -)=> EL +)=> TAG extends keyof ddeSVGElementTagNameMap ? ddeSVGElementTagNameMap[TAG] : ddeSVGElement export function elNS( namespace: "http://www.w3.org/1998/Math/MathML" -): ( +): < + TAG extends keyof MathMLElementTagNameMap & string, + EL extends ( TAG extends keyof MathMLElementTagNameMap ? MathMLElementTagNameMap[TAG] : MathMLElement ), +>( tag_name: TAG, - attrs?: string | Partial<{ [key in KEYS]: MathMLElementTagNameMap[TAG][key] | string | number | boolean }>, - ...addons: ddeElementAddon[] + attrs?: string | textContent | Partial<{ [key in keyof EL]: EL[key] | Observable | string | number | boolean }>, + ...addons: ddeElementAddon[] )=> ddeMathMLElement export function elNS( namespace: string ): ( tag_name: string, - attrs?: string | Record, + attrs?: string | textContent | Record, ...addons: ddeElementAddon[] )=> SupportedElement export { elNS as createElementNS }