praxis-kit 4.0.0 → 4.0.3

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.
@@ -1,144 +0,0 @@
1
- import { ComponentType, PropsWithChildren, ReactElement, JSX, Ref, ReactNode } from 'react';
2
- import { ElementType, VariantMap, RecipeMap, EmptyRecord, ClassPluginFactory, AnyRecord, FactoryOptions, IntrinsicTag, PolymorphicGenerics, DefaultOf, PropsOf, VariantProps, VariantsOf, AllowedOf, ClassName, RecipeOf } from '@praxis-kit/core';
3
- import { ComponentDefinition } from '@praxis-kit/runtime';
4
- import { Simplify, NonEmptyTuple } from 'type-fest';
5
-
6
- type UnknownProps = Record<string, unknown>;
7
- type SlotComponent = ComponentType<UnknownProps>;
8
-
9
- /**
10
- * Props passed to the `render` callback — the component's resolved className,
11
- * filtered own props, and ref. Spread these onto the target element.
12
- *
13
- * Typed loosely to accommodate any element tag the user chooses.
14
- */
15
- type RenderCallbackProps = Readonly<Record<string, unknown>>;
16
-
17
- type SlottableProps = PropsWithChildren;
18
- declare function Slottable({ children }: SlottableProps): ReactElement;
19
-
20
- /** Structural subset of `CompiledComponentArtifact` consumed by the React adapter. */
21
- interface CompiledArtifact {
22
- readonly definition: ComponentDefinition;
23
- readonly precomputed?: {
24
- readonly variantLookup?: Record<string, string>;
25
- };
26
- }
27
- /**
28
- * Extends FactoryOptions with React-specific configuration.
29
- * slotComponent is intentionally not in core — it is a React rendering concern.
30
- */
31
- type ReactFactoryOptions<TDefault extends ElementType, Props extends UnknownProps, Variants extends Readonly<VariantMap>, TPreset extends RecipeMap<Variants> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined, TAllowed extends ElementType = ElementType> = FactoryOptions<TDefault, Props, Variants, TPreset, TPlugin, TAllowed> & {
32
- /** Component used to render the asChild slot. Defaults to the built-in Slot. */
33
- slotComponent?: SlotComponent;
34
- /**
35
- * Return true for any prop key that should be consumed but not forwarded to the DOM.
36
- * The adapter strips nothing by default — implementations decide what is safe to drop.
37
- * Receives `runtime.options.variantKeys` as a convenience if needed.
38
- */
39
- filterProps?: (key: string, variantKeys: ReadonlySet<string>) => boolean;
40
- /** Pre-compiled artifact from `@praxis-kit/runtime`'s compiler. When provided, replaces the stub
41
- * definition and enables the precomputed variant lookup fast path. */
42
- artifact?: CompiledArtifact;
43
- };
44
-
45
- /** Maps a core ElementType to its DOM instance type for ref inference. */
46
- type ElementRef<T extends ElementType> = T extends IntrinsicTag ? HTMLElementTagNameMap[T] : unknown;
47
- /** @internal React JSX intrinsic props for a given element type. */
48
- type IntrinsicJSXProps<T extends ElementType> = T extends IntrinsicTag ? JSX.IntrinsicElements[T] : UnknownProps;
49
- /**
50
- * @internal
51
- * Removes index signatures (e.g. `[key: string]: T`) from a type, keeping only
52
- * explicitly named properties. Used to prevent fallback-to-constraint generics
53
- * like `Record<string, unknown>` or `Readonly<VariantMap>` from producing a
54
- * `[key: string]: T` member that makes `keyof` resolve to `string` — which
55
- * would cause `Omit<IntrinsicJSXProps<TAs>, string>` to remove all HTML props.
56
- */
57
- type StripIndexSignature<T> = {
58
- [K in keyof T as string extends K ? never : K]: T[K];
59
- };
60
- type ComponentProps<G extends PolymorphicGenerics> = StripIndexSignature<PropsOf<G>>;
61
- type ComponentVariants<G extends PolymorphicGenerics> = StripIndexSignature<VariantProps<VariantsOf<G>>>;
62
- type OwnedProps<G extends PolymorphicGenerics> = ComponentProps<G> & ComponentVariants<G>;
63
- /**
64
- * @internal
65
- * Polymorphic machinery props. Separated from `OwnedProps` so the two concerns
66
- * are distinct: user-defined props vs. the tag/ref/class system.
67
- *
68
- * `asChild` and `children` are excluded — typed separately in the discriminated
69
- * union below so each render mode can enforce different child constraints.
70
- */
71
- type PolymorphicControlProps<G extends PolymorphicGenerics, TAs extends ElementType> = {
72
- as?: TAs & AllowedOf<G>;
73
- className?: ClassName | undefined;
74
- recipe?: keyof RecipeOf<G>;
75
- ref?: Ref<ElementRef<TAs>>;
76
- };
77
- /** @internal Full set of props owned by the component — used as the Omit key in IntrinsicPropsWithoutOwned. */
78
- type ControlProps<G extends PolymorphicGenerics, TAs extends ElementType> = OwnedProps<G> & PolymorphicControlProps<G, TAs>;
79
- type IntrinsicPropsWithoutOwned<G extends PolymorphicGenerics, TAs extends ElementType> = Omit<IntrinsicJSXProps<TAs>, keyof ControlProps<G, TAs> | 'children'>;
80
- type SharedProps<G extends PolymorphicGenerics, TAs extends ElementType> = IntrinsicPropsWithoutOwned<G, TAs> & ControlProps<G, TAs>;
81
- /** Discriminant for the normal render path: `asChild` absent or false, any children. */
82
- type NormalRenderMode = {
83
- asChild?: false;
84
- children?: ReactNode | undefined;
85
- };
86
- /**
87
- * Discriminant for the slot render path. One or more `ReactElement` children required.
88
- * `as` is forbidden — combining `as` with `asChild` is a runtime invariant violation.
89
- */
90
- type SlotRenderMode = {
91
- asChild: true;
92
- as?: never;
93
- children: ReactElement | NonEmptyTuple<ReactElement>;
94
- };
95
- /**
96
- * Discriminant for the render-prop path. The callback receives all resolved props
97
- * (className, ref, filtered component props) and returns the target element.
98
- *
99
- * This is the output form for the compile-time `asChild` transform: keeps the same
100
- * rendering flexibility as `asChild` without the `cloneElement` cost at runtime.
101
- * Unlike `asChild`, the render callback does not auto-merge conflicting event
102
- * handlers — spread position determines precedence.
103
- *
104
- * ```tsx
105
- * <Button render={(p) => <a href="/home" {...p} />} size="lg" />
106
- * ```
107
- */
108
- type CallbackRenderMode = {
109
- render: (props: RenderCallbackProps) => ReactElement;
110
- asChild?: never;
111
- children?: never;
112
- };
113
- /**
114
- * Props for the normal render path. HTML attributes are inferred from `TAs`.
115
- *
116
- * `Omit + intersection` (not `Merge`) is used so TypeScript can infer `TAs` from
117
- * the `as` prop value; control props win on key conflicts.
118
- */
119
- type PolymorphicProps<G extends PolymorphicGenerics, TAs extends ElementType = DefaultOf<G>> = Simplify<SharedProps<G, TAs> & NormalRenderMode>;
120
- /**
121
- * Props for the slot render path (`asChild: true`). One or more `ReactElement`
122
- * children are required. Multiple children are permitted for the Slottable
123
- * sibling pattern where one child is a `<Slottable>` wrapper.
124
- */
125
- type PolymorphicWithAsChild<G extends PolymorphicGenerics, TAs extends ElementType = DefaultOf<G>> = Simplify<SharedProps<G, TAs> & SlotRenderMode>;
126
- type PolymorphicWithRender<G extends PolymorphicGenerics, TAs extends ElementType = DefaultOf<G>> = Simplify<SharedProps<G, TAs> & CallbackRenderMode>;
127
- /**
128
- * A polymorphic component that infers HTML attributes and ref type from the `as` prop.
129
- *
130
- * Three call signatures form a discriminated union:
131
- * - `render` present → render-prop path; no Slot or cloneElement at runtime
132
- * - `asChild: true` → slot path; exactly one `ReactElement` child required
133
- * - `asChild?: false` → normal path; any `ReactNode` children accepted
134
- */
135
- type PolymorphicComponent<G extends PolymorphicGenerics> = {
136
- <TAs extends ElementType = DefaultOf<G>>(props: PolymorphicWithRender<G, TAs>): ReactElement;
137
- <TAs extends ElementType = DefaultOf<G>>(props: PolymorphicWithAsChild<G, TAs>): ReactElement;
138
- <TAs extends ElementType = DefaultOf<G>>(props: PolymorphicProps<G, TAs>): ReactElement;
139
- displayName?: string;
140
- };
141
-
142
- declare function mergeRefs<T>(...refs: (Ref<T> | null | undefined)[]): Ref<T> | null;
143
-
144
- export { type ElementRef as E, type PolymorphicComponent as P, type ReactFactoryOptions as R, Slottable as S, type UnknownProps as U, type PolymorphicProps as a, type PolymorphicWithAsChild as b, type PolymorphicWithRender as c, type RenderCallbackProps as d, type SlottableProps as e, mergeRefs as m };