typed-dom
Advanced tools
Comparing version 0.0.275 to 0.0.276
{ | ||
"name": "typed-dom", | ||
"version": "0.0.275", | ||
"version": "0.0.276", | ||
"description": "A value-level and type-level DOM builder.", | ||
@@ -5,0 +5,0 @@ "private": false, |
@@ -353,3 +353,3 @@ # typed-dom | ||
```ts | ||
import { API, Attrs, Factory, html } from 'typed-dom'; | ||
import { API, El, html } from 'typed-dom'; | ||
@@ -370,9 +370,7 @@ const i18n = i18next.createInstance({ | ||
const Trans = API<HTMLElementTagNameMap>(html); | ||
const data = <K extends keyof TransDataMap>(data: TransDataMap[K]) => | ||
<T extends keyof HTMLElementTagNameMap>( | ||
html: Factory<HTMLElementTagNameMap>, | ||
tag: T, | ||
_: Attrs, | ||
children: K, | ||
) => | ||
function data | ||
<K extends keyof TransDataMap> | ||
(data: TransDataMap[K]) | ||
: El.Factory<HTMLElementTagNameMap, K> { | ||
return (html, tag, _, children) => | ||
html(tag, { | ||
@@ -385,2 +383,3 @@ onmutate: ev => | ||
}); | ||
} | ||
@@ -395,9 +394,7 @@ const el = Trans.span('Greeting', data({ name: 'world' })); | ||
```ts | ||
const bind = <K extends keyof TransDataMap>(children: K, data: TransDataMap[K]) => | ||
<T extends keyof HTMLElementTagNameMap>( | ||
html: Factory<HTMLElementTagNameMap>, | ||
tag: T, | ||
_: Attrs, | ||
__: El.Children.Void, | ||
) => { | ||
function bind | ||
<K extends keyof TransDataMap> | ||
(children: K, data: TransDataMap[K]) | ||
: El.Factory<HTMLElementTagNameMap, void> { | ||
return (html, tag, _, __) => { | ||
const el = html(tag); | ||
@@ -410,2 +407,3 @@ i18n.init((err, t) => | ||
}; | ||
} | ||
@@ -412,0 +410,0 @@ const el = Trans.span(bind('Greeting', { name: 'world' })); |
@@ -24,31 +24,39 @@ import { Symbol, Proxy } from 'spica/global'; | ||
type El_Children_Unit = readonly []; | ||
export type ElFactory< | ||
M extends TagNameMap, | ||
T extends keyof M & string = keyof M & string, | ||
C extends El.Children = El.Children, | ||
> = | ||
// Bug: TypeScript: Type U must not affect Type C | ||
//<U extends T>(baseFactory: Factory<M>, tag: U, attrs: Attrs, children: C) => M[U]; | ||
(baseFactory: Factory<M>, tag: T, attrs: Attrs, children: C) => M[T]; | ||
interface BuilderFunction<M extends TagNameMap> { | ||
<T extends K<M>, C extends El.Children.Void >(tag: T, attrs: Attrs<E<M[T]>> | undefined, factory?: El.Factory<M, T, C>): El<T, E<M[T]>, El.Children.Void>; | ||
<T extends K<M>, C extends El.Children.Void >(tag: T, attrs: Attrs<E<M[T]>> | undefined, children: C, factory?: El.Factory<M, T, C>): El<T, E<M[T]>, El.Children.Void>; | ||
<T extends K<M>, C extends El.Children.Text >(tag: T, attrs: Attrs<E<M[T]>> | undefined, children: C, factory?: El.Factory<M, T, C>): El<T, E<M[T]>, El.Children.Text>; | ||
<T extends K<M>, C extends El_Children_Unit >(tag: T, attrs: Attrs<E<M[T]>> | undefined, children: C, factory?: El.Factory<M, T, C>): El<T, E<M[T]>, El.Children.Array>; | ||
<T extends K<M>, C extends El.Children.Array >(tag: T, attrs: Attrs<E<M[T]>> | undefined, children: C, factory?: El.Factory<M, T, C>): El<T, E<M[T]>, Readonly<C>>; | ||
<T extends K<M>, C extends El.Children.Struct>(tag: T, attrs: Attrs<E<M[T]>> | undefined, children: C, factory?: El.Factory<M, T, C>): El<T, E<M[T]>, C>; | ||
<T extends K<M>, C extends El.Children.Void >(tag: T, children: C, factory?: El.Factory<M, T, C>): El<T, E<M[T]>, El.Children.Void>; | ||
<T extends K<M>, C extends El.Children.Text >(tag: T, children: C, factory?: El.Factory<M, T, C>): El<T, E<M[T]>, El.Children.Text>; | ||
<T extends K<M>, C extends El_Children_Unit >(tag: T, children: C, factory?: El.Factory<M, T, C>): El<T, E<M[T]>, El.Children.Array>; | ||
<T extends K<M>, C extends El.Children.Array >(tag: T, children: C, factory?: El.Factory<M, T, C>): El<T, E<M[T]>, Readonly<C>>; | ||
<T extends K<M>, C extends El.Children.Struct>(tag: T, children: C, factory?: El.Factory<M, T, C>): El<T, E<M[T]>, C>; | ||
<T extends K<M>, C extends El.Children.Void >(tag: T, factory?: El.Factory<M, T, C>): El<T, E<M[T]>, El.Children.Void>; | ||
<T extends K<M>, C extends El.Children.Void >(tag: T, attrs: Attrs<E<M[T]>> | undefined, factory?: ElFactory<M, T, C>): El<T, E<M[T]>, El.Children.Void>; | ||
<T extends K<M>, C extends El.Children.Void >(tag: T, attrs: Attrs<E<M[T]>> | undefined, children: C, factory?: ElFactory<M, T, C>): El<T, E<M[T]>, El.Children.Void>; | ||
<T extends K<M>, C extends El.Children.Text >(tag: T, attrs: Attrs<E<M[T]>> | undefined, children: C, factory?: ElFactory<M, T, C>): El<T, E<M[T]>, El.Children.Text>; | ||
<T extends K<M>, C extends El_Children_Unit >(tag: T, attrs: Attrs<E<M[T]>> | undefined, children: C, factory?: ElFactory<M, T, C>): El<T, E<M[T]>, El.Children.Array>; | ||
<T extends K<M>, C extends El.Children.Array >(tag: T, attrs: Attrs<E<M[T]>> | undefined, children: C, factory?: ElFactory<M, T, C>): El<T, E<M[T]>, Readonly<C>>; | ||
<T extends K<M>, C extends El.Children.Struct>(tag: T, attrs: Attrs<E<M[T]>> | undefined, children: C, factory?: ElFactory<M, T, C>): El<T, E<M[T]>, C>; | ||
<T extends K<M>, C extends El.Children.Void >(tag: T, children: C, factory?: ElFactory<M, T, C>): El<T, E<M[T]>, El.Children.Void>; | ||
<T extends K<M>, C extends El.Children.Text >(tag: T, children: C, factory?: ElFactory<M, T, C>): El<T, E<M[T]>, El.Children.Text>; | ||
<T extends K<M>, C extends El_Children_Unit >(tag: T, children: C, factory?: ElFactory<M, T, C>): El<T, E<M[T]>, El.Children.Array>; | ||
<T extends K<M>, C extends El.Children.Array >(tag: T, children: C, factory?: ElFactory<M, T, C>): El<T, E<M[T]>, Readonly<C>>; | ||
<T extends K<M>, C extends El.Children.Struct>(tag: T, children: C, factory?: ElFactory<M, T, C>): El<T, E<M[T]>, C>; | ||
<T extends K<M>, C extends El.Children.Void >(tag: T, factory?: ElFactory<M, T, C>): El<T, E<M[T]>, El.Children.Void>; | ||
} | ||
interface BuilderMethod<M extends TagNameMap, T extends K<M>> { | ||
<C extends El.Children.Void >( attrs: Attrs<E<M[T]>> | undefined, factory?: El.Factory<M, T, C>): El<T, E<M[T]>, El.Children.Void>; | ||
<C extends El.Children.Void >( attrs: Attrs<E<M[T]>> | undefined, children: C, factory?: El.Factory<M, T, C>): El<T, E<M[T]>, El.Children.Void>; | ||
<C extends El.Children.Text >( attrs: Attrs<E<M[T]>> | undefined, children: C, factory?: El.Factory<M, T, C>): El<T, E<M[T]>, El.Children.Text>; | ||
<C extends El_Children_Unit >( attrs: Attrs<E<M[T]>> | undefined, children: C, factory?: El.Factory<M, T, C>): El<T, E<M[T]>, El.Children.Array>; | ||
<C extends El.Children.Array >( attrs: Attrs<E<M[T]>> | undefined, children: C, factory?: El.Factory<M, T, C>): El<T, E<M[T]>, Readonly<C>>; | ||
<C extends El.Children.Struct>( attrs: Attrs<E<M[T]>> | undefined, children: C, factory?: El.Factory<M, T, C>): El<T, E<M[T]>, C>; | ||
<C extends El.Children.Void >( children: C, factory?: El.Factory<M, T, C>): El<T, E<M[T]>, El.Children.Void>; | ||
<C extends El.Children.Text >( children: C, factory?: El.Factory<M, T, C>): El<T, E<M[T]>, El.Children.Text>; | ||
<C extends El_Children_Unit >( children: C, factory?: El.Factory<M, T, C>): El<T, E<M[T]>, El.Children.Array>; | ||
<C extends El.Children.Array >( children: C, factory?: El.Factory<M, T, C>): El<T, E<M[T]>, Readonly<C>>; | ||
<C extends El.Children.Struct>( children: C, factory?: El.Factory<M, T, C>): El<T, E<M[T]>, C>; | ||
<C extends El.Children.Void >( factory?: El.Factory<M, T, C>): El<T, E<M[T]>, El.Children.Void>; | ||
<C extends El.Children.Void >( attrs: Attrs<E<M[T]>> | undefined, factory?: ElFactory<M, T, C>): El<T, E<M[T]>, El.Children.Void>; | ||
<C extends El.Children.Void >( attrs: Attrs<E<M[T]>> | undefined, children: C, factory?: ElFactory<M, T, C>): El<T, E<M[T]>, El.Children.Void>; | ||
<C extends El.Children.Text >( attrs: Attrs<E<M[T]>> | undefined, children: C, factory?: ElFactory<M, T, C>): El<T, E<M[T]>, El.Children.Text>; | ||
<C extends El_Children_Unit >( attrs: Attrs<E<M[T]>> | undefined, children: C, factory?: ElFactory<M, T, C>): El<T, E<M[T]>, El.Children.Array>; | ||
<C extends El.Children.Array >( attrs: Attrs<E<M[T]>> | undefined, children: C, factory?: ElFactory<M, T, C>): El<T, E<M[T]>, Readonly<C>>; | ||
<C extends El.Children.Struct>( attrs: Attrs<E<M[T]>> | undefined, children: C, factory?: ElFactory<M, T, C>): El<T, E<M[T]>, C>; | ||
<C extends El.Children.Void >( children: C, factory?: ElFactory<M, T, C>): El<T, E<M[T]>, El.Children.Void>; | ||
<C extends El.Children.Text >( children: C, factory?: ElFactory<M, T, C>): El<T, E<M[T]>, El.Children.Text>; | ||
<C extends El_Children_Unit >( children: C, factory?: ElFactory<M, T, C>): El<T, E<M[T]>, El.Children.Array>; | ||
<C extends El.Children.Array >( children: C, factory?: ElFactory<M, T, C>): El<T, E<M[T]>, Readonly<C>>; | ||
<C extends El.Children.Struct>( children: C, factory?: ElFactory<M, T, C>): El<T, E<M[T]>, C>; | ||
<C extends El.Children.Void >( factory?: ElFactory<M, T, C>): El<T, E<M[T]>, El.Children.Void>; | ||
} | ||
@@ -71,3 +79,3 @@ | ||
function builder(tag: keyof M & string) { | ||
return function build(attrs?: Attrs | El.Children, children?: El.Children, factory?: El.Factory<M, keyof M & string, El.Children>): El { | ||
return function build(attrs?: Attrs | El.Children, children?: El.Children, factory?: ElFactory<M, keyof M & string, El.Children>): El { | ||
if (typeof children === 'function') return build(attrs, void 0, children); | ||
@@ -83,3 +91,3 @@ if (typeof attrs === 'function') return build(void 0, void 0, attrs); | ||
function elem(tag: keyof M & string, factory: El.Factory<M, keyof M & string, El.Children> | undefined, attrs: Attrs | undefined, children: El.Children): Element { | ||
function elem(tag: keyof M & string, factory: ElFactory<M, keyof M & string, El.Children> | undefined, attrs: Attrs | undefined, children: El.Children): Element { | ||
const el = factory | ||
@@ -86,0 +94,0 @@ ? define(factory(baseFactory, tag, attrs ?? {}, children) as unknown as Element, attrs) |
@@ -47,8 +47,5 @@ import { Event } from 'spica/global'; | ||
M extends TagNameMap, | ||
T extends keyof M & string = keyof M & string, | ||
C extends El.Children = El.Children, | ||
> = | ||
// Bug: TypeScript: Type U must not affect Type C | ||
//<U extends T>(baseFactory: BaseFactory<M>, tag: U, attrs: Attrs, children: C) => M[U]; | ||
(baseFactory: BaseFactory<M>, tag: T, attrs: Attrs, children: C) => M[T]; | ||
<T extends keyof M & string>(baseFactory: BaseFactory<M>, tag: T, attrs: Attrs, children: C) => M[T]; | ||
} | ||
@@ -55,0 +52,0 @@ const enum ElChildType { |
@@ -1,2 +0,2 @@ | ||
import { API, Shadow, HTML, SVG, El, Attrs, Factory, shadow, html } from '../..'; | ||
import { API, Shadow, HTML, SVG, El, Attrs, shadow, html } from '../..'; | ||
import { Coroutine } from 'spica/coroutine'; | ||
@@ -587,9 +587,7 @@ import { Sequence } from 'spica/sequence'; | ||
const Trans = API<HTMLElementTagNameMap>(html); | ||
const data = <K extends keyof TransDataMap>(data: TransDataMap[K]) => | ||
<T extends keyof HTMLElementTagNameMap>( | ||
html: Factory<HTMLElementTagNameMap>, | ||
tag: T, | ||
_: Attrs, | ||
children: K, | ||
) => | ||
function data | ||
<K extends keyof TransDataMap> | ||
(data: TransDataMap[K]) | ||
: El.Factory<HTMLElementTagNameMap, K> { | ||
return (html, tag, _, children) => | ||
html(tag, { | ||
@@ -602,2 +600,3 @@ onmutate: ev => | ||
}); | ||
} | ||
@@ -614,9 +613,7 @@ const el = Trans.span('Greeting', data({ name: 'world' })); | ||
const bind = <K extends keyof TransDataMap>(children: K, data: TransDataMap[K]) => | ||
<T extends keyof HTMLElementTagNameMap>( | ||
html: Factory<HTMLElementTagNameMap>, | ||
tag: T, | ||
_: Attrs, | ||
__: El.Children.Void, | ||
) => { | ||
function bind | ||
<K extends keyof TransDataMap> | ||
(children: K, data: TransDataMap[K]) | ||
: El.Factory<HTMLElementTagNameMap, void> { | ||
return (html, tag, _, __) => { | ||
const el = html(tag); | ||
@@ -629,2 +626,3 @@ i18n.init((err, t) => | ||
}; | ||
} | ||
@@ -631,0 +629,0 @@ assert(Trans.span(bind('Greeting', { name: 'world' })).children === undefined); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15921
677837
413