mirror of
https://github.com/jaandrle/deka-dom-el
synced 2024-12-04 04:43:55 +01:00
♻️ 🐛 Update types
This commit is contained in:
parent
f31808c2d6
commit
64ddd3f41f
@ -3,10 +3,7 @@ import { pages } from "../ssr.js";
|
|||||||
/**
|
/**
|
||||||
* @param {object} def
|
* @param {object} def
|
||||||
* @param {import("../types.d.ts").Info} def.info
|
* @param {import("../types.d.ts").Info} def.info
|
||||||
* @param {object} def.pkg Package information.
|
* @param {import("../types.d.ts").Pkg} def.pkg Package information.
|
||||||
* @param {string} def.pkg.name
|
|
||||||
* @param {string} def.pkg.description
|
|
||||||
* @param {string} def.pkg.homepage
|
|
||||||
* */
|
* */
|
||||||
export function header({ info: { href, title, description }, pkg }){
|
export function header({ info: { href, title, description }, pkg }){
|
||||||
title= `\`${pkg.name}\` — ${title}`;
|
title= `\`${pkg.name}\` — ${title}`;
|
||||||
|
@ -4,7 +4,7 @@ import { el, simulateSlots } from "deka-dom-el";
|
|||||||
import { header } from "./head.html.js";
|
import { header } from "./head.html.js";
|
||||||
import { prevNext } from "../components/pageUtils.html.js";
|
import { prevNext } from "../components/pageUtils.html.js";
|
||||||
|
|
||||||
/** @param {import("../types.d.ts").PageAttrs} attrs */
|
/** @param {Pick<import("../types.d.ts").PageAttrs, "pkg" | "info">} attrs */
|
||||||
export function simplePage({ pkg, info }){
|
export function simplePage({ pkg, info }){
|
||||||
return simulateSlots(el().append(
|
return simulateSlots(el().append(
|
||||||
el(header, { info, pkg }),
|
el(header, { info, pkg }),
|
||||||
|
32
index.d.ts
vendored
32
index.d.ts
vendored
@ -43,18 +43,19 @@ type _fromElsInterfaces<EL extends SupportedElement>= Omit<EL, keyof AttrsModifi
|
|||||||
* There is added support for `data[A-Z].*`/`aria[A-Z].*` to be converted to the kebab-case alternatives.
|
* There is added support for `data[A-Z].*`/`aria[A-Z].*` to be converted to the kebab-case alternatives.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
type ElementAttributes<T extends SupportedElement>= Partial<_fromElsInterfaces<T> & { [K in keyof _fromElsInterfaces<T>]: Observable<_fromElsInterfaces<T>[K], any> } & AttrsModified>;
|
type ElementAttributes<T extends SupportedElement>= Partial<_fromElsInterfaces<T> & { [K in keyof _fromElsInterfaces<T>]: Observable<_fromElsInterfaces<T>[K], any> } & AttrsModified> & Record<string, any>;
|
||||||
export function classListDeclarative<El extends SupportedElement>(element: El, classList: AttrsModified["classList"]): El
|
export function classListDeclarative<El extends SupportedElement>(element: El, classList: AttrsModified["classList"]): El
|
||||||
export function assign<El extends SupportedElement>(element: El, ...attrs_array: ElementAttributes<El>[]): El
|
export function assign<El extends SupportedElement>(element: El, ...attrs_array: ElementAttributes<El>[]): El
|
||||||
export function assignAttribute<El extends SupportedElement, ATT extends keyof ElementAttributes<El>>(element: El, attr: ATT, value: ElementAttributes<El>[ATT]): ElementAttributes<El>[ATT]
|
export function assignAttribute<El extends SupportedElement, ATT extends keyof ElementAttributes<El>>(element: El, attr: ATT, value: ElementAttributes<El>[ATT]): ElementAttributes<El>[ATT]
|
||||||
|
|
||||||
type ExtendedHTMLElementTagNameMap= HTMLElementTagNameMap & CustomElementTagNameMap & ddePublicElementTagNameMap
|
type ExtendedHTMLElementTagNameMap= HTMLElementTagNameMap & CustomElementTagNameMap & ddePublicElementTagNameMap
|
||||||
|
type textContent= string | ( (set?: string)=> string ); // TODO: for some reason `Observable<string, any>` leads to `attrs?: any`
|
||||||
export function el<
|
export function el<
|
||||||
TAG extends keyof ExtendedHTMLElementTagNameMap & string,
|
TAG extends keyof ExtendedHTMLElementTagNameMap & string,
|
||||||
EL extends (TAG extends keyof ExtendedHTMLElementTagNameMap ? ExtendedHTMLElementTagNameMap[TAG] : HTMLElement)
|
EL extends (TAG extends keyof ExtendedHTMLElementTagNameMap ? ExtendedHTMLElementTagNameMap[TAG] : HTMLElement)
|
||||||
>(
|
>(
|
||||||
tag_name: TAG,
|
tag_name: TAG,
|
||||||
attrs?: string | Observable<string, any> | ElementAttributes<EL>,
|
attrs?: ElementAttributes<EL> | textContent,
|
||||||
...addons: ddeElementAddon<EL>[]
|
...addons: ddeElementAddon<EL>[]
|
||||||
): TAG extends keyof ddeHTMLElementTagNameMap ? ddeHTMLElementTagNameMap[TAG] : ddeHTMLElement
|
): TAG extends keyof ddeHTMLElementTagNameMap ? ddeHTMLElementTagNameMap[TAG] : ddeHTMLElement
|
||||||
export function el(
|
export function el(
|
||||||
@ -62,34 +63,39 @@ export function el(
|
|||||||
): ddeDocumentFragment
|
): ddeDocumentFragment
|
||||||
|
|
||||||
export function el<
|
export function el<
|
||||||
A extends ddeComponentAttributes,
|
C extends (attr: ddeComponentAttributes)=> SupportedElement | ddeDocumentFragment
|
||||||
C extends (attr: Partial<A>)=> SupportedElement | DocumentFragment
|
|
||||||
>(
|
>(
|
||||||
component: C,
|
component: C,
|
||||||
attrs?: A | string,
|
attrs?: Parameters<C>[0] | textContent,
|
||||||
...addons: ddeElementAddon<ReturnType<C>>[]
|
...addons: ddeElementAddon<ReturnType<C>>[]
|
||||||
): ReturnType<C>
|
): ReturnType<C> extends ddeHTMLElementTagNameMap[keyof ddeHTMLElementTagNameMap] ? ReturnType<C> : ddeHTMLElement
|
||||||
export { el as createElement }
|
export { el as createElement }
|
||||||
|
|
||||||
export function elNS(
|
export function elNS(
|
||||||
namespace: "http://www.w3.org/2000/svg"
|
namespace: "http://www.w3.org/2000/svg"
|
||||||
): <TAG, EL extends ( TAG extends keyof ddeSVGElementTagNameMap ? ddeSVGElementTagNameMap[TAG] : ddeSVGElement ), KEYS extends keyof EL & { d: string }>(
|
): <
|
||||||
|
TAG extends keyof SVGElementTagNameMap & string,
|
||||||
|
EL extends ( TAG extends keyof SVGElementTagNameMap ? SVGElementTagNameMap[TAG] : SVGElement ),
|
||||||
|
>(
|
||||||
tag_name: TAG,
|
tag_name: TAG,
|
||||||
attrs?: string | Partial<{ [key in KEYS]: EL[key] | string | number | boolean }>,
|
attrs?: ElementAttributes<EL> | textContent,
|
||||||
...addons: ddeElementAddon<EL>[]
|
...addons: ddeElementAddon<EL>[]
|
||||||
)=> EL
|
)=> TAG extends keyof ddeSVGElementTagNameMap ? ddeSVGElementTagNameMap[TAG] : ddeSVGElement
|
||||||
export function elNS(
|
export function elNS(
|
||||||
namespace: "http://www.w3.org/1998/Math/MathML"
|
namespace: "http://www.w3.org/1998/Math/MathML"
|
||||||
): <TAG extends keyof MathMLElementTagNameMap, KEYS extends keyof MathMLElementTagNameMap[TAG] & { d: string }>(
|
): <
|
||||||
|
TAG extends keyof MathMLElementTagNameMap & string,
|
||||||
|
EL extends ( TAG extends keyof MathMLElementTagNameMap ? MathMLElementTagNameMap[TAG] : MathMLElement ),
|
||||||
|
>(
|
||||||
tag_name: TAG,
|
tag_name: TAG,
|
||||||
attrs?: string | Partial<{ [key in KEYS]: MathMLElementTagNameMap[TAG][key] | string | number | boolean }>,
|
attrs?: string | textContent | Partial<{ [key in keyof EL]: EL[key] | Observable<EL[key], any> | string | number | boolean }>,
|
||||||
...addons: ddeElementAddon<MathMLElementTagNameMap[TAG]>[]
|
...addons: ddeElementAddon<EL>[]
|
||||||
)=> ddeMathMLElement
|
)=> ddeMathMLElement
|
||||||
export function elNS(
|
export function elNS(
|
||||||
namespace: string
|
namespace: string
|
||||||
): (
|
): (
|
||||||
tag_name: string,
|
tag_name: string,
|
||||||
attrs?: string | Record<string, any>,
|
attrs?: string | textContent | Record<string, any>,
|
||||||
...addons: ddeElementAddon<SupportedElement>[]
|
...addons: ddeElementAddon<SupportedElement>[]
|
||||||
)=> SupportedElement
|
)=> SupportedElement
|
||||||
export { elNS as createElementNS }
|
export { elNS as createElementNS }
|
||||||
|
Loading…
Reference in New Issue
Block a user