@yahoo/uds-create-config 5.68.2 → 5.68.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -15,8 +15,8 @@ declare const DocumentationDefinition: EntityClass<z.ZodObject<{
|
|
|
15
15
|
uds: "uds";
|
|
16
16
|
}>>;
|
|
17
17
|
platform: z.ZodOptional<z.ZodEnum<{
|
|
18
|
-
mobile: "mobile";
|
|
19
18
|
web: "web";
|
|
19
|
+
mobile: "mobile";
|
|
20
20
|
}>>;
|
|
21
21
|
}, z.core.$strict>, z.ZodObject<Record<never, never>, z.core.$strip>, "documentation", {
|
|
22
22
|
readonly search: {
|
|
@@ -14,9 +14,8 @@ import { AllHTMLAttributes, ComponentPropsWithRef, ComponentType, ElementType, J
|
|
|
14
14
|
* Enough of another component to BE a layer's element — the handle `defineComponent` returns, with
|
|
15
15
|
* its declarations forgotten so a builder of any shape fits.
|
|
16
16
|
*
|
|
17
|
-
* Named separately from `AuthoredComponent
|
|
18
|
-
*
|
|
19
|
-
* from. `ComponentBuilder<{root:'button'}, …>` satisfies this; it does not satisfy `AuthoredComponent`.
|
|
17
|
+
* Named separately from `AuthoredComponent`, which is what a registry holds; a layer only needs to know
|
|
18
|
+
* the value is a component, and keeps the referenced component's own type for its props.
|
|
20
19
|
*/
|
|
21
20
|
interface ComponentElement extends Authored {
|
|
22
21
|
readonly kind: 'component';
|
|
@@ -497,7 +496,20 @@ type AsInput = ElementType | string;
|
|
|
497
496
|
*/
|
|
498
497
|
type UnionToIntersection<U> = (U extends unknown ? (member: U) => void : never) extends ((member: infer I) => void) ? I : never;
|
|
499
498
|
/** One element's contribution, a union of tags folded into one object type. */
|
|
500
|
-
type ElementSurface<Element> = UnionToIntersection<
|
|
499
|
+
type ElementSurface<Element> = UnionToIntersection<SurfacePropsOf<Element>>;
|
|
500
|
+
/**
|
|
501
|
+
* {@link ElementPropsOf} as a surface takes it, beside the system's tail: a component's props less the
|
|
502
|
+
* style props and modifiers it takes from that tail unchanged, which are the ones it neither declares
|
|
503
|
+
* nor redefines in its render extra. The surface intersects the tail anyway, so each of those has the
|
|
504
|
+
* same type and modifiers either way, and it isn't declared twice in every component's props.
|
|
505
|
+
*/
|
|
506
|
+
type SurfacePropsOf<Element> = Element extends keyof JSX.IntrinsicElements ? ElementPropsOf<Element> : Element extends ((props: infer PropsOfComponent) => unknown) ? Element extends {
|
|
507
|
+
metadata(meta: never): infer Builder;
|
|
508
|
+
} ? Builder extends ComponentBuilder<infer _L extends LayerMap, infer P extends PropMap, infer E, infer _D, infer _F extends string, infer _S extends StateMap> ? DeclaredExcept<PropsOfComponent, Exclude<keyof SystemTail, RedeclaredKeys<P, E>>> : Declared<PropsOfComponent> : Declared<PropsOfComponent> : Element extends {
|
|
509
|
+
readonly __ref: `component:${infer Path}`;
|
|
510
|
+
} ? Path extends keyof RegisteredComponentHandles ? SurfacePropsOf<RegisteredComponentHandles[Path]> : Record<never, never> : Record<never, never>;
|
|
511
|
+
/** {@link Declared}, less the keys in `K`. */
|
|
512
|
+
type DeclaredExcept<T, K> = { [Key in keyof T as string extends Key ? never : number extends Key ? never : Key extends K ? never : Key]: T[Key] };
|
|
501
513
|
/**
|
|
502
514
|
* What the root layer contributes to the surface.
|
|
503
515
|
*
|
|
@@ -508,7 +520,7 @@ type ElementSurface<Element> = UnionToIntersection<ElementPropsOf<Element>>;
|
|
|
508
520
|
* than intersected, or a handler is typed against both elements when only one renders. A style
|
|
509
521
|
* prop the root declares is not an element key (see {@link ElementPropsOf}), so it survives the swap.
|
|
510
522
|
*/
|
|
511
|
-
type RootSurface<L extends LayerMap, D, As> = [RenderedElementOf<L, D, As>] extends [L['root']] ? ElementSurface<L['root']> : Without<ElementSurface<L['root']>, keyof
|
|
523
|
+
type RootSurface<L extends LayerMap, D, As> = [RenderedElementOf<L, D, As>] extends [L['root']] ? ElementSurface<L['root']> : Without<ElementSurface<L['root']>, keyof UnionToIntersection<ElementPropsOf<RenderedElementOf<L, D, As>>>> & ElementSurface<RenderedElementOf<L, D, As>>;
|
|
512
524
|
/**
|
|
513
525
|
* The element one call renders: what its `as` names, else what the component fixes.
|
|
514
526
|
*
|
|
@@ -565,8 +577,12 @@ type LayerProps<L extends LayerMap> = {
|
|
|
565
577
|
*
|
|
566
578
|
* Open before the build: which names are style props is the system's to say, and until its emitted
|
|
567
579
|
* types say it, anything may be one.
|
|
580
|
+
*
|
|
581
|
+
* The style props and modifiers are one type for the whole system, kept apart from the layer channel,
|
|
582
|
+
* so a component that declares none of their names takes that type as it is.
|
|
568
583
|
*/
|
|
569
|
-
type OpenTail<L extends LayerMap> = Registered extends true ?
|
|
584
|
+
type OpenTail<L extends LayerMap, P, E> = Registered extends true ? Shadowed<SystemTail, RedeclaredKeys<P, E>> & Redeclared<LayerProps<L>, P, E> : Redeclared<Record<string, unknown>, P, E>;
|
|
585
|
+
type SystemTail = StyleProps & ModifierProps;
|
|
570
586
|
/**
|
|
571
587
|
* The props a consumer may pass — the declared ones, the rendered element's, and the style props.
|
|
572
588
|
*
|
|
@@ -580,13 +596,21 @@ type OpenTail<L extends LayerMap> = Registered extends true ? StyleProps & Modif
|
|
|
580
596
|
*
|
|
581
597
|
* Ends in {@link OpenTail}: the system's own surface, open until the system's build has named it.
|
|
582
598
|
*/
|
|
583
|
-
type ComponentPropsOf<L extends LayerMap, P extends PropMap, D = Record<never, never>, E = Record<never, never>, F extends string = never, As = never> = ConsumerDeclaredProps<P, D, E, L, ComponentBuilder<L, P, E, D, F>> & Partial<E> & Redeclared<RootSurface<L, D, As>, P, E> &
|
|
599
|
+
type ComponentPropsOf<L extends LayerMap, P extends PropMap, D = Record<never, never>, E = Record<never, never>, F extends string = never, As = never> = ConsumerDeclaredProps<P, D, E, L, ComponentBuilder<L, P, E, D, F>> & Partial<E> & Redeclared<RootSurface<L, D, As>, P, E> & Shadowed<ForwardedPropsOf<L, F>, RedeclaredKeys<P, E>> & AsPropsOf<As, P, E> & OpenTail<L, P, E>;
|
|
584
600
|
/**
|
|
585
|
-
* `T` less the keys the component declares and the keys its render extra names
|
|
586
|
-
*
|
|
587
|
-
* extra (`extends Record<string, unknown>`) must not stop the declared
|
|
601
|
+
* `T` less the keys the component declares and the keys its render extra names. {@link Without} leaves
|
|
602
|
+
* `T` whole when its key set is open, so an open set of either kind is left out of the union rather
|
|
603
|
+
* than opening it: an open render extra (`extends Record<string, unknown>`) must not stop the declared
|
|
604
|
+
* props from shadowing.
|
|
588
605
|
*/
|
|
589
|
-
type Redeclared<T, P, E> = Without<
|
|
606
|
+
type Redeclared<T, P, E> = Without<T, RedeclaredKeys<P, E>>;
|
|
607
|
+
type RedeclaredKeys<P, E> = string extends Redefined<E> ? keyof P : string extends keyof P ? Redefined<E> : keyof P | Redefined<E>;
|
|
608
|
+
/**
|
|
609
|
+
* `T` without the keys in `K` it has, and `T` itself when it has none of them. The system's tail is one
|
|
610
|
+
* type every component shares, and a mapped copy per component would cost the size of that type
|
|
611
|
+
* rather than the size of what the component declares.
|
|
612
|
+
*/
|
|
613
|
+
type Shadowed<T, K extends PropertyKey> = [Extract<K, keyof T>] extends [never] ? T : Without<T, Extract<K, keyof T>>;
|
|
590
614
|
/**
|
|
591
615
|
* The phantom call signature's parameter. `As` is inferred from `as` alone; the rest of the surface
|
|
592
616
|
* is `NoInfer`, so inference never walks it. Open to inference, a spread of
|
|
@@ -642,7 +666,13 @@ type IntrinsicAttributeNames<As> = As extends keyof JSX.IntrinsicElements ? keyo
|
|
|
642
666
|
* there is no telling a stray attribute from a style prop, and an unbuilt consumer compiles the way
|
|
643
667
|
* the registry promises.
|
|
644
668
|
*/
|
|
645
|
-
type ForeignAttributesOf<As, P, E> = Registered extends false ? Record<never, never> : [As] extends [keyof JSX.IntrinsicElements] ? { [K in Exclude<
|
|
669
|
+
type ForeignAttributesOf<As, P, E> = Registered extends false ? Record<never, never> : [As] extends [keyof JSX.IntrinsicElements] ? { [K in Exclude<AttributeNames, IntrinsicAttributeNames<As> | keyof P | keyof E>]?: never } : Record<never, never>;
|
|
670
|
+
/**
|
|
671
|
+
* The HTML attribute names less `as` and the registered style props, which are the same for every
|
|
672
|
+
* component. A single `Exclude` over this concrete union takes out the rest: one over a deferred
|
|
673
|
+
* `Exclude<…, IntrinsicAttributeNames<As>>` would build an intersection per name while `As` is generic.
|
|
674
|
+
*/
|
|
675
|
+
type AttributeNames = Exclude<keyof AllHTMLAttributes<HTMLElement>, 'as' | keyof RegisteredStyleProps>;
|
|
646
676
|
/**
|
|
647
677
|
* The props a component picks up from the layers it FORWARDS.
|
|
648
678
|
*
|
|
@@ -656,7 +686,7 @@ type ForeignAttributesOf<As, P, E> = Registered extends false ? Record<never, ne
|
|
|
656
686
|
* accept `HTMLDivElement | HTMLInputElement` instead of the input it actually receives.
|
|
657
687
|
*/
|
|
658
688
|
type NonRootForward<L extends LayerMap, F extends string> = Exclude<F, 'root'> & keyof L;
|
|
659
|
-
type ForwardedPropsOf<L extends LayerMap, F extends string> = [NonRootForward<L, F>] extends [never] ? Record<never, never> : Partial<
|
|
689
|
+
type ForwardedPropsOf<L extends LayerMap, F extends string> = [NonRootForward<L, F>] extends [never] ? Record<never, never> : Partial<SurfacePropsOf<L[NonRootForward<L, F>]>>;
|
|
660
690
|
/**
|
|
661
691
|
* Defaults a component applies with nothing set — its declared props, typed, plus the style props it
|
|
662
692
|
* may also default.
|
|
@@ -753,19 +783,24 @@ type WhenAny<K, T> = [K] extends [never] ? unknown : T;
|
|
|
753
783
|
* with `P` in full as its type argument.
|
|
754
784
|
*/
|
|
755
785
|
type CompactProps<P extends PropMap> = [StyleRefKeys<P> | StyleRefPropKeys<P>] extends [never] ? P : { [K in keyof P as K extends StyleRefKeys<P> | StyleRefPropKeys<P> ? never : K]: P[K] } & WhenAny<StyleRefKeys<P>, StyleRefs<StyleRefKeys<P> & string>> & WhenAny<StyleRefPropKeys<P>, StyleRefProps<StyleRefPropKeys<P> & string>>;
|
|
756
|
-
|
|
786
|
+
/**
|
|
787
|
+
* Every type parameter is declared `in out`. Measured instead, TypeScript relates two instantiations
|
|
788
|
+
* with `P` generic, which crosses every registered style prop and modifier name with every other, and
|
|
789
|
+
* past 316 of them that is over its 100,000-member union limit (TS2590).
|
|
790
|
+
*/
|
|
791
|
+
interface ComponentBuilder<in out L extends LayerMap, in out P extends PropMap,
|
|
757
792
|
/** Props the RENDER takes that the config doesn't describe — React handlers, mostly (`onPress`).
|
|
758
793
|
* They're part of the component's surface but not of its data, which is why they're declared at
|
|
759
794
|
* `.render()` rather than in `.props()`. */
|
|
760
|
-
E = Record<never, never>,
|
|
795
|
+
in out E = Record<never, never>,
|
|
761
796
|
/** The defaults as AUTHORED, kept because one of them decides the type of every other prop: an
|
|
762
797
|
* `as` fixes which element this renders. See {@link ElementOf}. */
|
|
763
|
-
D = Record<never, never>,
|
|
798
|
+
in out D = Record<never, never>,
|
|
764
799
|
/** The layers this component FORWARDS from, as a union of their names. Accumulates through
|
|
765
800
|
* `.forwards()` so `ComponentPropsOf` can union each forwarded layer's element props — `root` is
|
|
766
801
|
* already covered structurally by {@link ElementOf}, so for a root-only forward this changes no
|
|
767
802
|
* inferred type, which is what makes replacing `inherits` a no-op at every call site. */
|
|
768
|
-
F extends string = never, /** The states `.states()` declared — what the render knows and reports, never a caller's prop. */S extends StateMap = Record<never, never>> extends Authored {
|
|
803
|
+
in out F extends string = never, /** The states `.states()` declared — what the render knows and reports, never a caller's prop. */in out S extends StateMap = Record<never, never>> extends Authored {
|
|
769
804
|
/**
|
|
770
805
|
* The phantom call signature — the authored value is never rendered (the build substitutes the
|
|
771
806
|
* emitted module), but a call site is checked against it. Generic over the element a call site
|
|
@@ -884,8 +919,19 @@ F extends string = never, /** The states `.states()` declared — what the rende
|
|
|
884
919
|
toStored(): Record<string, unknown>;
|
|
885
920
|
assignPath(path: string): void;
|
|
886
921
|
}
|
|
887
|
-
/**
|
|
888
|
-
|
|
922
|
+
/**
|
|
923
|
+
* A component under authorship, with its declarations forgotten — what a registry holds. It names only
|
|
924
|
+
* the members every builder has with the same type, so a builder of any shape is assignable to it.
|
|
925
|
+
*/
|
|
926
|
+
interface AuthoredComponent extends Authored {
|
|
927
|
+
readonly kind: 'component';
|
|
928
|
+
readonly body: Record<string, unknown>;
|
|
929
|
+
readonly path?: string;
|
|
930
|
+
toStored(): Record<string, unknown>;
|
|
931
|
+
assignPath(path: string): void;
|
|
932
|
+
}
|
|
933
|
+
/** What the whole-body form returns: a builder whose declarations are all at their widest. */
|
|
934
|
+
type WidestComponentBuilder = ComponentBuilder<LayerMap, PropMap, unknown, unknown>;
|
|
889
935
|
/**
|
|
890
936
|
* A linked component's handle as the system that links it holds it. The build emits one for each
|
|
891
937
|
* linked component the link changes, and the system's linked alias resolves to it first (UDS-4611).
|
|
@@ -931,7 +977,7 @@ interface DefineComponent {
|
|
|
931
977
|
root: El;
|
|
932
978
|
}, Record<never, never>>;
|
|
933
979
|
/** The whole body at once, for a component with nothing to narrow step by step. */
|
|
934
|
-
(body?: ComponentSourceInput<Record<string, unknown>>):
|
|
980
|
+
(body?: ComponentSourceInput<Record<string, unknown>>): WidestComponentBuilder;
|
|
935
981
|
layers<const L extends LayerMap>(layers: L): ComponentBuilder<L, Record<never, never>>;
|
|
936
982
|
props: typeof definePropsFirst;
|
|
937
983
|
}
|
|
@@ -402,24 +402,6 @@ function toStored(body) {
|
|
|
402
402
|
styles: storedStyleRules(rules)
|
|
403
403
|
};
|
|
404
404
|
}
|
|
405
|
-
/**
|
|
406
|
-
* Author a component.
|
|
407
|
-
*
|
|
408
|
-
* Callable for the case with nothing to narrow — `defineComponent({ layers: { root: 'div' } })` — and
|
|
409
|
-
* chainable for every other, since a chain is what lets each step's types come from the last.
|
|
410
|
-
*/
|
|
411
|
-
/**
|
|
412
|
-
* Author a component.
|
|
413
|
-
*
|
|
414
|
-
* Called with an ELEMENT — `defineComponent('input')`, `defineComponent(Component.ref('Box'))` — that
|
|
415
|
-
* element becomes the root layer, because a component with one layer IS that element and saying so
|
|
416
|
-
* twice adds nothing. It's also what makes the element's props type correctly: v1 expressed this as a
|
|
417
|
-
* `defaultProps: { as: 'input' }` on a `div`-rooted component, which left the config claiming the
|
|
418
|
-
* element was a `div` while every call site treated it as an input.
|
|
419
|
-
*
|
|
420
|
-
* The render follows from it too — one layer needs no anatomy, so the build generates the element
|
|
421
|
-
* rather than reading a `.render()` that would only restate the layer.
|
|
422
|
-
*/
|
|
423
405
|
function defineComponentImpl(bodyOrElement) {
|
|
424
406
|
if (isComponentElement(bodyOrElement)) return build({ layers: { root: bodyOrElement } });
|
|
425
407
|
if (typeof bodyOrElement === "function" || isRef(bodyOrElement) && kindOf(bodyOrElement) === "package") throw new Error("[uds] defineComponent(<package export>): a package export cannot be a component's only layer yet — the generated one-layer render emits web elements. Declare `layers` and a `.render()` instead.");
|