praxis-kit 7.5.0 → 7.8.0
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.
- package/dist/_shared/diagnostics.d.ts +3 -0
- package/dist/_shared/diagnostics.js +3 -0
- package/dist/{chunk-SMHJEFNE.js → chunk-QYP7KLRE.js} +316 -154
- package/dist/contract/index.d.ts +3 -3
- package/dist/eslint/index.js +227 -187
- package/dist/html/index.d.ts +6 -1
- package/dist/html/index.js +234 -68
- package/dist/lit/index.d.ts +3 -3
- package/dist/lit/index.js +305 -141
- package/dist/preact/index.d.ts +90 -5
- package/dist/preact/index.js +316 -152
- package/dist/react/index.d.ts +3 -2
- package/dist/react/index.js +1 -1
- package/dist/react/legacy.d.ts +8 -5
- package/dist/react/legacy.js +8 -8
- package/dist/{react-options-5GbZ8Tbv.d.ts → react-options-DU3EdFOv.d.ts} +102 -6
- package/dist/solid/index.d.ts +103 -7
- package/dist/solid/index.js +316 -152
- package/dist/svelte/Polymorphic.svelte +8 -0
- package/dist/svelte/index.d.ts +196 -10
- package/dist/svelte/index.js +319 -152
- package/dist/tailwind/index.d.ts +1 -1
- package/dist/vite-plugin/index.d.ts +6 -3
- package/dist/vue/index.d.ts +70 -5
- package/dist/vue/index.js +316 -152
- package/dist/web/index.d.ts +3 -3
- package/dist/web/index.js +305 -141
- package/package.json +9 -9
package/dist/preact/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { RequireAtLeastOne, Simplify, ReadonlyDeep, OmitIndexSignature } from 'type-fest';
|
|
2
2
|
import { Diagnostics, DiagnosticInput, DiagnosticsMode } from '../_shared/diagnostics.js';
|
|
3
3
|
import { ComponentChildren, VNode, ComponentType, JSX, Ref } from 'preact';
|
|
4
|
+
import { HasGenerics, Mode, PickMode } from '@praxis-kit/contract-props';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* A string-keyed object whose values are of type `T`.
|
|
@@ -189,20 +190,75 @@ type DefaultVariants<V extends VariantMap> = {
|
|
|
189
190
|
* Presets are named bundles of variant props that callers activate by key,
|
|
190
191
|
* avoiding the need to repeat variant combinations at each call site.
|
|
191
192
|
*/
|
|
192
|
-
type RecipeMap<V extends VariantMap = VariantMap> = Readonly<
|
|
193
|
+
type RecipeMap<V extends VariantMap = VariantMap> = Readonly<StringMap<VariantSelection<V>>>;
|
|
193
194
|
|
|
194
195
|
type RecipeTarget<TVariants extends VariantMap = VariantMap> = VariantSelection<TVariants>;
|
|
195
196
|
|
|
196
|
-
|
|
197
|
+
/**
|
|
198
|
+
* The framework-neutral descriptor for a single praxis-kit component's contract — every render
|
|
199
|
+
* mechanism (tag resolution, prop merging, classes, ARIA) and every framework adapter's
|
|
200
|
+
* component type is built from this one shape. Deliberately just data: five type parameters and
|
|
201
|
+
* their corresponding properties, with no notion of JSX, call signatures, refs, or any
|
|
202
|
+
* framework-specific rendering concern. Each adapter (React, Vue, Svelte, Solid, Lit, Web) builds
|
|
203
|
+
* its own idiomatic component type on top of a `PolymorphicGenerics<...>` instantiation — see
|
|
204
|
+
* `PolymorphicComponent<G>` (`adapters/react/src/shared/types/polymorphic-props.ts`) for the
|
|
205
|
+
* React example — rather than this interface knowing anything about any of them.
|
|
206
|
+
*
|
|
207
|
+
* Use the `*Of<T>` accessor aliases below (`DefaultOf<G>`, `PropsOf<G>`, etc.) to read a single
|
|
208
|
+
* field back out of an already-resolved `G`, instead of indexing `G['default']` etc. directly at
|
|
209
|
+
* call sites — same rationale as any accessor: the property name stays an implementation detail,
|
|
210
|
+
* and every reader benefits together if it ever needs to change.
|
|
211
|
+
*/
|
|
212
|
+
interface PolymorphicGenerics<
|
|
213
|
+
/**
|
|
214
|
+
* The element/tag this component renders as when the consumer doesn't override it via `as`
|
|
215
|
+
* (`AllowedOf<G>` permitting) — e.g. `'button'`, `'div'`. Defaults to the widest `ElementType`
|
|
216
|
+
* so a generic `PolymorphicGenerics` reference (with nothing else specified) still compiles.
|
|
217
|
+
*/
|
|
218
|
+
TDefault extends ElementType = ElementType,
|
|
219
|
+
/**
|
|
220
|
+
* The props this specific component declares — its own contract, before variants are mixed
|
|
221
|
+
* in. Defaults to `AnyRecord` for the same "still compiles unspecified" reason as `TDefault`.
|
|
222
|
+
*/
|
|
223
|
+
Props extends AnyRecord = AnyRecord,
|
|
224
|
+
/**
|
|
225
|
+
* This component's variant definitions (e.g. `{ intent: { primary: ..., ghost: ... } }`).
|
|
226
|
+
* Constrained to `Readonly<VariantMap>` — not the wider `AnyRecord` — specifically so `TPreset`
|
|
227
|
+
* below can be expressed as `RecipeMap<Variants>` and get real per-variant-key checking,
|
|
228
|
+
* instead of falling back to an unconstrained `RecipeMap<VariantMap>`.
|
|
229
|
+
*/
|
|
230
|
+
Variants extends Readonly<VariantMap> = Readonly<VariantMap>,
|
|
231
|
+
/**
|
|
232
|
+
* Named presets (`RecipeMap<Variants>`) — bundles of variant selections a consumer activates
|
|
233
|
+
* by key instead of repeating the same variant combination at every call site. Tied to
|
|
234
|
+
* `Variants`, not `AnyRecord`, precisely so a preset can only ever select keys/values that
|
|
235
|
+
* `Variants` actually defines — an invalid preset is a type error, not a silent no-op.
|
|
236
|
+
* Defaults to `Readonly<EmptyRecord>` (no presets), which is the common case: a component can
|
|
237
|
+
* have variants without necessarily defining any named presets over them, and most don't.
|
|
238
|
+
*/
|
|
239
|
+
TPreset extends RecipeMap<Variants> = Readonly<EmptyRecord>,
|
|
240
|
+
/**
|
|
241
|
+
* The set of elements/tags a consumer is allowed to switch to via `as`. Defaults to the widest
|
|
242
|
+
* `ElementType`, under which `AllowedOf<G>` imposes no restriction at all (see
|
|
243
|
+
* `PolymorphicControlProps.as`'s own comment in the React adapter for the concrete effect this
|
|
244
|
+
* has at a component's actual call site).
|
|
245
|
+
*/
|
|
246
|
+
TAllowed extends ElementType = ElementType> {
|
|
197
247
|
default: TDefault;
|
|
198
248
|
props: Props;
|
|
199
249
|
variants: Variants;
|
|
200
250
|
preset: TPreset;
|
|
201
251
|
allowed: TAllowed;
|
|
202
252
|
}
|
|
253
|
+
/** This component's variant definitions. See `PolymorphicGenerics`'s `Variants` parameter. */
|
|
203
254
|
type VariantsOf<T extends PolymorphicGenerics> = T['variants'];
|
|
255
|
+
/** This component's named presets. See `PolymorphicGenerics`'s `TPreset` parameter. */
|
|
204
256
|
type RecipeOf<T extends PolymorphicGenerics> = T['preset'];
|
|
257
|
+
/** The element/tag this component renders as by default. See `PolymorphicGenerics`'s `TDefault`
|
|
258
|
+
* parameter. */
|
|
205
259
|
type DefaultOf<T extends PolymorphicGenerics> = T['default'];
|
|
260
|
+
/** This component's own declared props, before variants are mixed in. See `PolymorphicGenerics`'s
|
|
261
|
+
* `Props` parameter. */
|
|
206
262
|
type PropsOf<T extends PolymorphicGenerics> = T['props'];
|
|
207
263
|
|
|
208
264
|
type RequireAtLeastOneIfNotEmpty<T> = keyof T extends never ? EmptyRecord : RequireAtLeastOne<T>;
|
|
@@ -235,7 +291,7 @@ interface BaseClassOptions {
|
|
|
235
291
|
type ClassPipelineFn = (tag: unknown, props: AnyRecord, className?: ClassName, recipe?: string) => string | undefined;
|
|
236
292
|
|
|
237
293
|
interface RecipeOptions<TVariants extends VariantMap = VariantMap> {
|
|
238
|
-
recipeMap?:
|
|
294
|
+
recipeMap?: StringMap<RecipeTarget<TVariants>>;
|
|
239
295
|
}
|
|
240
296
|
|
|
241
297
|
interface TagMapOptions {
|
|
@@ -404,7 +460,7 @@ type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPre
|
|
|
404
460
|
* combination, skipping runtime class computation entirely when a match is found. Normally
|
|
405
461
|
* generated by a build-time class-extraction plugin rather than hand-authored.
|
|
406
462
|
*/
|
|
407
|
-
readonly precomputedClasses?: Readonly<
|
|
463
|
+
readonly precomputedClasses?: Readonly<StringMap<string>>;
|
|
408
464
|
};
|
|
409
465
|
|
|
410
466
|
type NormalizeFn<Props extends AnyRecord = AnyRecord> = {
|
|
@@ -520,8 +576,37 @@ type PolymorphicComponent<G extends PolymorphicGenerics> = {
|
|
|
520
576
|
* inference for tools such as Storybook and `ComponentProps`.
|
|
521
577
|
*/
|
|
522
578
|
(props: PolymorphicProps<G, DefaultOf<G>>): AnyVNode;
|
|
579
|
+
/**
|
|
580
|
+
* Type-only; never assigned at runtime. See `HasGenerics<G>` (`@praxis-kit/contract-props`) for
|
|
581
|
+
* the full rationale — kept as an inline field rather than `HasGenerics<G> & {...}` because
|
|
582
|
+
* intersecting it onto this callable type changes how `PolymorphicComponent<any>` resolves
|
|
583
|
+
* against concrete instantiations (confirmed for React's identical shape,
|
|
584
|
+
* `adapters/react/src/shared/types/polymorphic-props.test.ts`); structurally identical to
|
|
585
|
+
* `HasGenerics<G>` either way, which is what lets `ContractProps` constrain against it.
|
|
586
|
+
*/
|
|
587
|
+
readonly __generics?: G;
|
|
523
588
|
displayName?: string;
|
|
524
589
|
};
|
|
590
|
+
/**
|
|
591
|
+
* Recovers a built `PolymorphicComponent<G>`'s prop shape for a specific render mode, from
|
|
592
|
+
* outside the file that built it — the missing piece `ComponentProps<typeof Component>` can't
|
|
593
|
+
* provide, since it always resolves against `PolymorphicComponent`'s normal-mode fallback
|
|
594
|
+
* overload (see that type's own doc comment).
|
|
595
|
+
*
|
|
596
|
+
* No `'render'` mode — Preact has no render-callback render strategy, unlike React.
|
|
597
|
+
*
|
|
598
|
+
* ```tsx
|
|
599
|
+
* const Container = createContractComponent({ tag: 'div', name: 'Container', /* ... *\/ })
|
|
600
|
+
*
|
|
601
|
+
* // Normal-mode props (equivalent to ComponentProps<typeof Container>, but works for asChild too):
|
|
602
|
+
* type ContainerProps = ContractProps<typeof Container>
|
|
603
|
+
*
|
|
604
|
+
* // A wrapper that always renders Container with asChild — ComponentProps<typeof Container>
|
|
605
|
+
* // fails here ("Type 'true' is not assignable to type 'false'"); ContractProps doesn't.
|
|
606
|
+
* type ContainerAsChildProps = ContractProps<typeof Container, 'asChild'>
|
|
607
|
+
* ```
|
|
608
|
+
*/
|
|
609
|
+
type ContractProps<T extends HasGenerics<PolymorphicGenerics>, M extends Exclude<Mode, 'render'> = 'normal'> = T extends HasGenerics<infer G extends PolymorphicGenerics> ? PickMode<M, PolymorphicProps<G, DefaultOf<G>>, PolymorphicWithAsChild<G, DefaultOf<G>>, never> : never;
|
|
525
610
|
|
|
526
611
|
/**
|
|
527
612
|
* Creates a polymorphic Preact component with praxis-kit contracts applied.
|
|
@@ -548,4 +633,4 @@ declare function createContractComponent<TDefault extends ElementType, Props ext
|
|
|
548
633
|
readonly subComponents?: TSubComponents;
|
|
549
634
|
}): MergeRecords<PolymorphicComponent<PolymorphicGenerics<TDefault, MergeRecords<Props, ExtractPluginProps<TPlugin>>, Variants, TPreset>>, TSubComponents>;
|
|
550
635
|
|
|
551
|
-
export { type AnyFactoryOptions, type ElementRef, type ElementType, type EmptyRecord, type PolymorphicComponent, type PolymorphicGenerics, type PolymorphicProps, type PolymorphicWithAsChild, type PreactFactoryOptions, Slottable, createContractComponent, defineContractComponent };
|
|
636
|
+
export { type AnyFactoryOptions, type ContractProps, type ElementRef, type ElementType, type EmptyRecord, type PolymorphicComponent, type PolymorphicGenerics, type PolymorphicProps, type PolymorphicWithAsChild, type PreactFactoryOptions, Slottable, createContractComponent, defineContractComponent };
|