@yahoo/uds-create-config 1.2.0-v3-import.2 → 1.2.1
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/Component.d.ts +1 -11
- package/dist/Component.js +0 -14
- package/dist/Props.d.ts +5 -18
- package/dist/StyleProp.js +0 -1
- package/dist/factories.d.ts +11 -103
- package/dist/factories.js +1 -25
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/refs.d.ts +1 -2
- package/dist/spec/specToJsx.js +32 -7
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/css-properties.d.ts +0 -1
- package/dist/types.d.ts +6 -35
- package/package.json +4 -2
package/dist/Component.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseStyles, ComponentDefinition, ComponentMetadata, ComponentMotionValue, CompoundPropsEntry, LayerInput, PreviewDefinition, PropBinding,
|
|
1
|
+
import { BaseStyles, ComponentDefinition, ComponentMetadata, ComponentMotionValue, CompoundPropsEntry, LayerInput, PreviewDefinition, PropBinding, SerializedComponent } from "./types.js";
|
|
2
2
|
import { SlotValueType } from "./markers.js";
|
|
3
3
|
import { ComponentClassNames } from "@yahoo/uds-create-utils";
|
|
4
4
|
|
|
@@ -164,9 +164,6 @@ declare class Component {
|
|
|
164
164
|
readonly defaultProps?: Record<string, unknown>;
|
|
165
165
|
readonly compoundProps?: readonly CompoundPropsEntry[];
|
|
166
166
|
readonly motion?: ComponentMotionValue;
|
|
167
|
-
/** Opt-in forwarded-ref target tag (`.config({ ref: 'button' })`). Drives the
|
|
168
|
-
* typed `ref` prop in `@yahoo/uds-create-config` and the codegen forwardRef wrapper. */
|
|
169
|
-
readonly ref?: RefTag;
|
|
170
167
|
readonly preview?: PreviewDefinition;
|
|
171
168
|
readonly metadata?: ComponentMetadata;
|
|
172
169
|
/**
|
|
@@ -197,13 +194,6 @@ declare class Component {
|
|
|
197
194
|
* that path.
|
|
198
195
|
*/
|
|
199
196
|
readonly renderFn?: unknown;
|
|
200
|
-
/** `true` when the authored definition chained `.renderCanvas(fn)` — the
|
|
201
|
-
* non-enumerable `__hasRenderCanvasFn` flag. Codegen emits a canvas-only
|
|
202
|
-
* overlay artifact for these; spec extraction prefers the canvas fn. */
|
|
203
|
-
readonly hasCanvasRenderFn: boolean;
|
|
204
|
-
/** The `.renderCanvas(fn)` callback when `hasCanvasRenderFn` is `true`.
|
|
205
|
-
* In-memory only (functions never serialize). */
|
|
206
|
-
readonly canvasRenderFn?: unknown;
|
|
207
197
|
/**
|
|
208
198
|
* Name of the component this one value-extends from
|
|
209
199
|
* (`defineComponent(Box)` → `'Box'`). Resolved from the non-
|
package/dist/Component.js
CHANGED
|
@@ -135,9 +135,6 @@ var Component = class {
|
|
|
135
135
|
defaultProps;
|
|
136
136
|
compoundProps;
|
|
137
137
|
motion;
|
|
138
|
-
/** Opt-in forwarded-ref target tag (`.config({ ref: 'button' })`). Drives the
|
|
139
|
-
* typed `ref` prop in `@yahoo/uds-create-config` and the codegen forwardRef wrapper. */
|
|
140
|
-
ref;
|
|
141
138
|
preview;
|
|
142
139
|
metadata;
|
|
143
140
|
/**
|
|
@@ -168,13 +165,6 @@ var Component = class {
|
|
|
168
165
|
* that path.
|
|
169
166
|
*/
|
|
170
167
|
renderFn;
|
|
171
|
-
/** `true` when the authored definition chained `.renderCanvas(fn)` — the
|
|
172
|
-
* non-enumerable `__hasRenderCanvasFn` flag. Codegen emits a canvas-only
|
|
173
|
-
* overlay artifact for these; spec extraction prefers the canvas fn. */
|
|
174
|
-
hasCanvasRenderFn;
|
|
175
|
-
/** The `.renderCanvas(fn)` callback when `hasCanvasRenderFn` is `true`.
|
|
176
|
-
* In-memory only (functions never serialize). */
|
|
177
|
-
canvasRenderFn;
|
|
178
168
|
/**
|
|
179
169
|
* Name of the component this one value-extends from
|
|
180
170
|
* (`defineComponent(Box)` → `'Box'`). Resolved from the non-
|
|
@@ -249,7 +239,6 @@ var Component = class {
|
|
|
249
239
|
this.defaultProps = args.definition.defaultProps;
|
|
250
240
|
this.compoundProps = args.definition.compoundProps;
|
|
251
241
|
this.motion = args.definition.motion;
|
|
252
|
-
this.ref = args.definition.ref;
|
|
253
242
|
const def = args.definition;
|
|
254
243
|
const previewField = typeof def.preview === "function" ? void 0 : def.preview;
|
|
255
244
|
this.preview = def.__preview ?? previewField;
|
|
@@ -261,8 +250,6 @@ var Component = class {
|
|
|
261
250
|
this.sourceFilePath = readSourcePath(args.definition);
|
|
262
251
|
this.hasRenderFn = args.definition.__hasRenderFn === true;
|
|
263
252
|
this.renderFn = args.definition.__renderFn;
|
|
264
|
-
this.hasCanvasRenderFn = args.definition.__hasRenderCanvasFn === true;
|
|
265
|
-
this.canvasRenderFn = args.definition.__renderCanvasFn;
|
|
266
253
|
const extendsFromSeed = args.definition.__extendsFrom;
|
|
267
254
|
const extendsFromName = extendsFromSeed && typeof extendsFromSeed === "object" && typeof extendsFromSeed.__componentName === "string" ? extendsFromSeed.__componentName : void 0;
|
|
268
255
|
this.extendsFrom = extendsFromName ?? args.definition.extendsFrom;
|
|
@@ -330,7 +317,6 @@ var Component = class {
|
|
|
330
317
|
defaultProps: this.defaultProps,
|
|
331
318
|
compoundProps: this.compoundProps,
|
|
332
319
|
motion: this.motion,
|
|
333
|
-
ref: this.ref,
|
|
334
320
|
preview: this.preview ? serializeElementsDeep(this.preview) : void 0,
|
|
335
321
|
metadata: this.metadata,
|
|
336
322
|
sourceFilePath,
|
package/dist/Props.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RegisteredCompositeStyles, RegisteredModifiers, RegisteredStyleProps, TagRef } from "./refs.js";
|
|
2
2
|
import { ColorExpression } from "./colorExpressions.js";
|
|
3
|
-
import { ComponentDefinition, LayerInput, PropBinding,
|
|
4
|
-
import { ComponentPropsWithRef,
|
|
3
|
+
import { ComponentDefinition, LayerInput, PropBinding, RootTag } from "./types.js";
|
|
4
|
+
import { ComponentPropsWithRef, HTMLAttributes, JSX, ReactNode } from "react";
|
|
5
5
|
|
|
6
6
|
//#region src/Props.d.ts
|
|
7
7
|
/**
|
|
@@ -270,7 +270,7 @@ type EffectiveTag<TDef, TTag, TLayers> = TDef extends {
|
|
|
270
270
|
};
|
|
271
271
|
} ? A : string extends TTag ? RootTag<TLayers> : [TTag] extends [undefined] ? RootTag<TLayers> : TTag extends string ? TTag : RootTag<TLayers>;
|
|
272
272
|
type PropsBase<TDef extends ComponentDefinition<Record<string, LayerInput>, Record<string, PropBinding>, string | undefined>> = TDef extends ComponentDefinition<infer TLayers extends Record<string, LayerInput>, infer TProps extends Record<string, PropBinding>, infer TTag extends string | undefined> ? PropsFromBindings<TProps, TLayers> & Omit<ComposedRootProps<TLayers>, keyof TProps | 'children'> & Omit<ElementProps<EffectiveTag<TDef, TTag, TLayers>>, keyof TProps | keyof ComposedRootProps<TLayers>> & DataAttrs & {
|
|
273
|
-
as?:
|
|
273
|
+
as?: keyof JSX.IntrinsicElements;
|
|
274
274
|
layerProps?: LayerPropsMap<TLayers>;
|
|
275
275
|
} : never;
|
|
276
276
|
/**
|
|
@@ -298,29 +298,16 @@ type PropsBase<TDef extends ComponentDefinition<Record<string, LayerInput>, Reco
|
|
|
298
298
|
* during package-wide typechecks (`@yahoo/uds-create-codegen` builds saw this
|
|
299
299
|
* at `factories.ts:853`).
|
|
300
300
|
*/
|
|
301
|
-
/**
|
|
302
|
-
* Opt-in forwarded-ref prop. A component declares its ref target via
|
|
303
|
-
* `.config({ ref: 'button' })`; that tag is captured on the definition's `ref`
|
|
304
|
-
* field and mapped here to `ref?: Ref<HTMLButtonElement>`. When declared and
|
|
305
|
-
* resolvable, it *overrides* the element's natural ref (see `Props`, which omits
|
|
306
|
-
* exactly `keyof RefProp` before re-adding this). When it can't resolve to a
|
|
307
|
-
* tag, it contributes nothing and the natural ref is left intact.
|
|
308
|
-
*/
|
|
309
|
-
type RefProp<TDef> = TDef extends {
|
|
310
|
-
ref: infer Tag extends string;
|
|
311
|
-
} ? {
|
|
312
|
-
ref?: Ref<RefElement<Tag>>;
|
|
313
|
-
} : Record<never, never>;
|
|
314
301
|
type Props<TDef extends ComponentDefinition<Record<string, LayerInput>, Record<string, PropBinding>, string | undefined>> = TDef extends {
|
|
315
302
|
layers: Record<string, LayerInput>;
|
|
316
|
-
} ? Record<string, LayerInput> extends TDef['layers'] ? PermissiveProps : Prettify<
|
|
303
|
+
} ? Record<string, LayerInput> extends TDef['layers'] ? PermissiveProps : Prettify<PropsBase<TDef> & RegisteredModifiers<PropsBase<TDef>>> : PermissiveProps;
|
|
317
304
|
/**
|
|
318
305
|
* Permissive prop bag used as the bail-out shape when `Props<TDef>`
|
|
319
306
|
* can't narrow against a concrete `layers` map (mirrors the
|
|
320
307
|
* `FC<any>` slot the pre-Props builder used to carry).
|
|
321
308
|
*/
|
|
322
309
|
type PermissiveProps = HTMLAttributes<HTMLElement> & DataAttrs & Record<string, any> & {
|
|
323
|
-
as?:
|
|
310
|
+
as?: keyof JSX.IntrinsicElements;
|
|
324
311
|
};
|
|
325
312
|
/**
|
|
326
313
|
* `Props<typeof boxConfig>` for the common 'use the definition's inferred
|
package/dist/StyleProp.js
CHANGED
|
@@ -116,7 +116,6 @@ var StyleProp = class StyleProp {
|
|
|
116
116
|
const keywords = /* @__PURE__ */ new Map();
|
|
117
117
|
for (const entry of values) if (typeof entry === "string") keywords.set(entry, this.transform ? this.transform(entry) : entry);
|
|
118
118
|
else if (typeof entry === "number") keywords.set(entry, this.transform ? this.transform(entry) : String(entry));
|
|
119
|
-
else if (typeof entry === "boolean") keywords.set(entry, String(entry));
|
|
120
119
|
else if (typeof entry === "object" && entry !== null && "alias" in entry && "value" in entry) keywords.set(entry.alias, entry.value);
|
|
121
120
|
this.#derived = {
|
|
122
121
|
keywords,
|
package/dist/factories.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { RegisteredModifiers, TagRef, TokenGroupRef,
|
|
1
|
+
import { RegisteredModifiers, TagRef, TokenGroupRef, composite, styleProp, token } from "./refs.js";
|
|
2
2
|
import { darken, lighten } from "./colorExpressions.js";
|
|
3
|
-
import { ComponentDefinition, ComponentGroupDefinition, ComponentMetadata, CompositeStyleDefinition, LayerInput, ModeDefinition, ModifierDefinition, MotionDefinitionInput, PreviewDefinition,
|
|
3
|
+
import { ComponentDefinition, ComponentGroupDefinition, ComponentMetadata, CompositeStyleDefinition, LayerInput, ModeDefinition, ModifierDefinition, MotionDefinitionInput, PreviewDefinition, StylePropDefinition, StylePropMetadata, StylePropProperty, TokenDefinition } from "./types.js";
|
|
4
4
|
import { BooleanMarker, ComponentSlotMarker, LayerMarker, NumberMarker, PreviewAxisMarker, PreviewPropsRule, RequiredBrand, SlotMarker, SlotRef, SlotValueType, StringMarker, VariantMarker, VariantMarkerArray, VariantMarkerObject } from "./markers.js";
|
|
5
5
|
import { BaseLayerStyles, LayerPropsMap, LayerTag, Props, PropsFromBindings, SlotPropValue } from "./Props.js";
|
|
6
6
|
import { defineProvider } from "./defineProvider.js";
|
|
7
|
-
import { ComponentPropsWithRef,
|
|
7
|
+
import { ComponentPropsWithRef, ComponentType, FC, HTMLAttributes, JSX, ReactNode } from "react";
|
|
8
8
|
|
|
9
9
|
//#region src/factories.d.ts
|
|
10
10
|
/**
|
|
@@ -140,19 +140,6 @@ declare function boolean(values?: {
|
|
|
140
140
|
true?: Record<string, Record<string, unknown>>;
|
|
141
141
|
false?: Record<string, Record<string, unknown>>;
|
|
142
142
|
}): Chainable<BooleanMarker>;
|
|
143
|
-
/**
|
|
144
|
-
* `asChild()` — opt a **single-layer** component into the polymorphic-child
|
|
145
|
-
* Slot pattern. Declare it as a prop (`props: { asChild: asChild() }`); when a
|
|
146
|
-
* consumer passes `asChild`, the component merges its computed props (className,
|
|
147
|
-
* style props, handlers) onto its single child element instead of rendering its
|
|
148
|
-
* own tag — codegen wires the `_renderAsChild` Slot. Typed as a boolean prop
|
|
149
|
-
* (`asChild?: boolean`), so no extra type plumbing.
|
|
150
|
-
*
|
|
151
|
-
* Opt-in only and single-layer only: multi-layer composites render multiple
|
|
152
|
-
* children and can't slot a single child, so the codegen Slot branch is emitted
|
|
153
|
-
* solely for inline single-layer FCs.
|
|
154
|
-
*/
|
|
155
|
-
declare function asChild(): BooleanMarker;
|
|
156
143
|
/**
|
|
157
144
|
* Cross-layer style override — `_hover: layer('close', { opacity: 1 })`
|
|
158
145
|
* declares "when this layer is hovered, apply these styles to the
|
|
@@ -212,7 +199,6 @@ interface ConfigCallbackHelpers {
|
|
|
212
199
|
readonly slot: typeof slot;
|
|
213
200
|
readonly variant: typeof variant;
|
|
214
201
|
readonly boolean: typeof boolean;
|
|
215
|
-
readonly asChild: typeof asChild;
|
|
216
202
|
readonly string: typeof string;
|
|
217
203
|
readonly number: typeof number;
|
|
218
204
|
readonly layer: typeof layer;
|
|
@@ -362,7 +348,6 @@ type TypedConfigHelpers<T extends ComponentDefinition> = T extends ComponentDefi
|
|
|
362
348
|
readonly slot: TypedSlotHelper<TLayers>;
|
|
363
349
|
readonly variant: TypedVariantHelper<TLayers>;
|
|
364
350
|
readonly boolean: TypedBooleanHelper<TLayers>;
|
|
365
|
-
readonly asChild: typeof asChild;
|
|
366
351
|
readonly layer: TypedLayerHelper<TLayers>;
|
|
367
352
|
readonly string: typeof string;
|
|
368
353
|
readonly number: typeof number;
|
|
@@ -459,28 +444,13 @@ type ConfigCallbackResultFor<T extends ComponentDefinition> = Omit<ConfigCallbac
|
|
|
459
444
|
* key is omitted.
|
|
460
445
|
*/
|
|
461
446
|
type MergeNested<T, C, K extends string> = C extends Record<K, infer CV> ? T extends Record<K, infer TV> ? Record<K, Omit<TV, keyof CV> & CV> : Record<K, CV> : T extends Record<K, infer TV> ? Record<K, TV> : {};
|
|
462
|
-
/**
|
|
463
|
-
* `ref` is a scalar tag, so a value-extend that re-declares it must *override*
|
|
464
|
-
* the inherited tag (Pressable's `'button'` over Box's `'div'`). A plain
|
|
465
|
-
* intersection would collapse `'div' & 'button'` to `never` — poisoning the
|
|
466
|
-
* whole merged definition. C wins; falls back to T's tag when C omits `ref`.
|
|
467
|
-
*/
|
|
468
|
-
type MergeRef<T, C> = C extends {
|
|
469
|
-
ref: infer CR;
|
|
470
|
-
} ? {
|
|
471
|
-
ref: CR;
|
|
472
|
-
} : T extends {
|
|
473
|
-
ref: infer TR;
|
|
474
|
-
} ? {
|
|
475
|
-
ref: TR;
|
|
476
|
-
} : Record<never, never>;
|
|
477
447
|
/**
|
|
478
448
|
* Merge a `.config(cb)` callback result `C` over the chain seed `T`.
|
|
479
449
|
* Nested fields (`props`, `defaultProps`, `base`) merge per-key (C
|
|
480
|
-
* overrides T at the leaf level);
|
|
481
|
-
*
|
|
450
|
+
* overrides T at the leaf level); other fields fall back to the
|
|
451
|
+
* historic `T & C` intersection.
|
|
482
452
|
*/
|
|
483
|
-
type MergeChainConfig<T, C> = Omit<T, 'props' | 'defaultProps' | 'base'
|
|
453
|
+
type MergeChainConfig<T, C> = Omit<T, 'props' | 'defaultProps' | 'base'> & Omit<C, 'props' | 'defaultProps' | 'base'> & MergeNested<T, C, 'props'> & MergeNested<T, C, 'defaultProps'> & MergeNested<T, C, 'base'>;
|
|
484
454
|
/**
|
|
485
455
|
* Per-config slot-prop map: walk a `props` block, pick out every
|
|
486
456
|
* `slot()`-marked entry, and surface it as `ReactNode | undefined` on
|
|
@@ -542,41 +512,6 @@ type RenderPropsFromConfig<TProps, TDefaultKeys extends PropertyKey = never> = {
|
|
|
542
512
|
* render fn just spreads them with `{...props.<layer>}`.
|
|
543
513
|
*/
|
|
544
514
|
type LayerPropsBundle<TLayers> = { [K in keyof TLayers]: Record<string, unknown> };
|
|
545
|
-
/**
|
|
546
|
-
* Resolved value object for a single token. `value` is the
|
|
547
|
-
* light-mode (or single-mode) CSS value string. Any `_${string}` key
|
|
548
|
-
* (e.g. `_dark`) holds the override for that mode. `type` is an
|
|
549
|
-
* optional token-category hint (e.g. `'color'`, `'dimension'`).
|
|
550
|
-
*
|
|
551
|
-
* The precise qualified-name union for `tokenRaw`'s `name` parameter
|
|
552
|
-
* is layered on at the call site via codegen's `uds-env.d.ts`
|
|
553
|
-
* augmentation — keep this type config-agnostic.
|
|
554
|
-
*/
|
|
555
|
-
type RawToken = {
|
|
556
|
-
value: string;
|
|
557
|
-
type?: string;
|
|
558
|
-
} & { [K in `_${string}`]?: string };
|
|
559
|
-
/** The accepted `name` argument for `tokenRaw`. Narrows to the
|
|
560
|
-
* config's registered `'<group>/<token>'` union when codegen has
|
|
561
|
-
* augmented `TokenRawNameRegistry`; falls back to `string` in
|
|
562
|
-
* un-augmented contexts (this package's own tests, fresh consumers
|
|
563
|
-
* before the first build). */
|
|
564
|
-
type TokenRawName = [keyof TokenRawNameRegistry] extends [never] ? string : keyof TokenRawNameRegistry;
|
|
565
|
-
/**
|
|
566
|
-
* Resolved return shape of `tokenRaw(name)` for a specific `name`. Once codegen
|
|
567
|
-
* has augmented `TokenRawNameRegistry`, each registered name maps to its own
|
|
568
|
-
* per-token shape — `{ value: string; _dark: string }` for a themed token,
|
|
569
|
-
* `{ value: string }` for one with no mode overrides. A finite template/union
|
|
570
|
-
* name (e.g. `` `spectrum/blue/${step}` `` with `step` a finite union) resolves
|
|
571
|
-
* to the union of the matching tokens' shapes, which collapses to a single type
|
|
572
|
-
* when they share one. Falls back to the open `RawToken` in un-augmented
|
|
573
|
-
* contexts (this package's own tests, fresh consumers before the first build).
|
|
574
|
-
*
|
|
575
|
-
* Values are `string`, not literals: token values are indirection by design and
|
|
576
|
-
* change with theming, so a baked-in literal would go stale — the stable,
|
|
577
|
-
* useful information a name carries is which keys it has.
|
|
578
|
-
*/
|
|
579
|
-
type TokenRawValue<N extends TokenRawName> = N extends keyof TokenRawNameRegistry ? TokenRawNameRegistry[N] : RawToken;
|
|
580
515
|
/**
|
|
581
516
|
* Shape of the render fn passed to `.render<TExtra>(fn)`. `props` is
|
|
582
517
|
* the per-layer bundle injected by the codegen-emitted wrapper FC,
|
|
@@ -587,22 +522,10 @@ type TokenRawValue<N extends TokenRawName> = N extends keyof TokenRawNameRegistr
|
|
|
587
522
|
* (function-typed handlers, complex object pass-throughs) that the
|
|
588
523
|
* marker system doesn't express yet.
|
|
589
524
|
*/
|
|
590
|
-
|
|
591
|
-
* The render fn's `ref` arg, present only when the component declares
|
|
592
|
-
* `.config({ ref: 'tag' })`. The author attaches it to the real root element
|
|
593
|
-
* (`<svg ref={ref} {...props.root} />`), so TS checks the attachment against
|
|
594
|
-
* the declared element. No declaration → no `ref` arg (empty intersection).
|
|
595
|
-
*/
|
|
596
|
-
type RefArgFor<TDef> = TDef extends {
|
|
597
|
-
ref: infer Tag extends string;
|
|
598
|
-
} ? {
|
|
599
|
-
ref?: Ref<RefElement<Tag>>;
|
|
600
|
-
} : Record<never, never>;
|
|
601
|
-
type ComponentRenderFn<TExtra = unknown, TConfigProps = unknown, TLayers = Record<string, unknown>, TRefArg = Record<never, never>> = (args: {
|
|
525
|
+
type ComponentRenderFn<TExtra = unknown, TConfigProps = unknown, TLayers = Record<string, unknown>> = (args: {
|
|
602
526
|
props: LayerPropsBundle<TLayers>;
|
|
603
527
|
children?: ReactNode;
|
|
604
|
-
|
|
605
|
-
} & TConfigProps & TExtra & TRefArg) => ReactNode;
|
|
528
|
+
} & TConfigProps & TExtra) => ReactNode;
|
|
606
529
|
/**
|
|
607
530
|
* Chain methods attached to every `defineComponent` result. The
|
|
608
531
|
* builder type intersects with the underlying `ComponentDefinition`
|
|
@@ -637,7 +560,7 @@ interface ComponentBuilderMethods<T extends ComponentDefinition> {
|
|
|
637
560
|
defaultProps: infer D;
|
|
638
561
|
} ? keyof D : never> : unknown, T extends {
|
|
639
562
|
layers: infer L;
|
|
640
|
-
} ? L : Record<string, unknown
|
|
563
|
+
} ? L : Record<string, unknown>>): BoundComponent<T, TExtra>;
|
|
641
564
|
/**
|
|
642
565
|
* Attach a declarative preview spec — stored under non-enumerable
|
|
643
566
|
* `__preview` so the authored builder stays JSON-clean. Callback
|
|
@@ -684,15 +607,7 @@ interface ComponentBuilderMethods<T extends ComponentDefinition> {
|
|
|
684
607
|
* concession that keeps source files typechecking against this
|
|
685
608
|
* value as if it were the rewritten artifact.
|
|
686
609
|
*/
|
|
687
|
-
|
|
688
|
-
<C extends ElementType, TExtra = {}>(props: Omit<P, 'ref'> & {
|
|
689
|
-
as: C;
|
|
690
|
-
ref?: Ref<ComponentRef<C>>;
|
|
691
|
-
} & NoInfer<TExtra>): ReactElement | null;
|
|
692
|
-
<TExtra = {}>(props: P & NoInfer<TExtra>): ReactElement | null;
|
|
693
|
-
readonly displayName?: string;
|
|
694
|
-
}
|
|
695
|
-
type ComponentBuilder<T extends ComponentDefinition> = T & ComponentBuilderMethods<T> & UdsComponent<Props<T>>;
|
|
610
|
+
type ComponentBuilder<T extends ComponentDefinition> = T & ComponentBuilderMethods<T> & FC<Props<T>>;
|
|
696
611
|
/**
|
|
697
612
|
* Bound component returned by `.render<TExtra>(fn)`. Mirrors main's
|
|
698
613
|
* `BoundComponent`: an `FC` whose JSX props are
|
|
@@ -717,13 +632,6 @@ interface BoundComponentMethods<T extends ComponentDefinition, TExtra extends Re
|
|
|
717
632
|
preview(spec: PreviewDefinition<Omit<DefaultPropsFor<T>, keyof TExtra> & TExtra> | ((helpers: TypedPreviewHelpers<T>) => PreviewDefinition<Omit<DefaultPropsFor<T>, keyof TExtra> & TExtra>)): BoundComponent<T, TExtra>;
|
|
718
633
|
subcomponents(children: Record<string, ComponentDefinition>): BoundComponent<T, TExtra>;
|
|
719
634
|
metadata(meta: ComponentMetadata): BoundComponent<T, TExtra>;
|
|
720
|
-
renderCanvas<TCanvasExtra extends Record<string, unknown> = TExtra>(fn: ComponentRenderFn<TCanvasExtra, T extends {
|
|
721
|
-
props: infer P;
|
|
722
|
-
} ? RenderPropsFromConfig<P, T extends {
|
|
723
|
-
defaultProps: infer D;
|
|
724
|
-
} ? keyof D : never> : unknown, T extends {
|
|
725
|
-
layers: infer L;
|
|
726
|
-
} ? L : Record<string, unknown>, RefArgFor<T>>): BoundComponent<T, TExtra>;
|
|
727
635
|
}
|
|
728
636
|
type BoundComponent<T extends ComponentDefinition, TExtra extends Record<string, unknown> = {}> = T & FC<Omit<Props<T>, keyof TExtra> & TExtra> & BoundComponentMethods<T, TExtra> & {
|
|
729
637
|
readonly __config: T;
|
|
@@ -796,4 +704,4 @@ type ProviderComponent<TProps = Record<never, never>> = FC<{
|
|
|
796
704
|
*/
|
|
797
705
|
type DefinedProvider<TContext = unknown, TProps = Record<never, never>> = readonly [ProviderComponent<TProps>, () => TContext];
|
|
798
706
|
//#endregion
|
|
799
|
-
export { BoundComponent, ComponentBuilder, ComponentBuilderMethods, ComponentRenderFn, ConfigCallbackHelpers, DefineComponentFn, DefinedComponent, DefinedProvider, DefinedStyleProp, DefinedTokenGroup, PreviewCallbackHelpers, ProviderComponent, ProviderRenderFn,
|
|
707
|
+
export { BoundComponent, ComponentBuilder, ComponentBuilderMethods, ComponentRenderFn, ConfigCallbackHelpers, DefineComponentFn, DefinedComponent, DefinedProvider, DefinedStyleProp, DefinedTokenGroup, PreviewCallbackHelpers, ProviderComponent, ProviderRenderFn, TokenGroupMetadata, TypedSlotRef, boolean, defineComponent, defineComponentGroup, defineCompositeStyle, defineMode, defineModifier, defineMotion, defineStyleProp, defineTokenGroup, number, slot, string, variant };
|
package/dist/factories.js
CHANGED
|
@@ -192,24 +192,6 @@ function boolean(values) {
|
|
|
192
192
|
});
|
|
193
193
|
}
|
|
194
194
|
/**
|
|
195
|
-
* `asChild()` — opt a **single-layer** component into the polymorphic-child
|
|
196
|
-
* Slot pattern. Declare it as a prop (`props: { asChild: asChild() }`); when a
|
|
197
|
-
* consumer passes `asChild`, the component merges its computed props (className,
|
|
198
|
-
* style props, handlers) onto its single child element instead of rendering its
|
|
199
|
-
* own tag — codegen wires the `_renderAsChild` Slot. Typed as a boolean prop
|
|
200
|
-
* (`asChild?: boolean`), so no extra type plumbing.
|
|
201
|
-
*
|
|
202
|
-
* Opt-in only and single-layer only: multi-layer composites render multiple
|
|
203
|
-
* children and can't slot a single child, so the codegen Slot branch is emitted
|
|
204
|
-
* solely for inline single-layer FCs.
|
|
205
|
-
*/
|
|
206
|
-
function asChild() {
|
|
207
|
-
return {
|
|
208
|
-
__kind: "boolean",
|
|
209
|
-
__asChild: true
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
195
|
* Cross-layer style override — `_hover: layer('close', { opacity: 1 })`
|
|
214
196
|
* declares "when this layer is hovered, apply these styles to the
|
|
215
197
|
* named layer". Codegen emits a descendant-combinator rule pointing
|
|
@@ -277,7 +259,6 @@ const configHelpers = {
|
|
|
277
259
|
slot,
|
|
278
260
|
variant,
|
|
279
261
|
boolean,
|
|
280
|
-
asChild,
|
|
281
262
|
string,
|
|
282
263
|
number,
|
|
283
264
|
layer,
|
|
@@ -367,11 +348,6 @@ function attachChainMethods(seed) {
|
|
|
367
348
|
def("__hasRenderFn", true);
|
|
368
349
|
return seed;
|
|
369
350
|
});
|
|
370
|
-
def("renderCanvas", function renderCanvasMethod(fn) {
|
|
371
|
-
def("__renderCanvasFn", fn);
|
|
372
|
-
def("__hasRenderCanvasFn", true);
|
|
373
|
-
return seed;
|
|
374
|
-
});
|
|
375
351
|
def("preview", function previewMethod(spec) {
|
|
376
352
|
def("__preview", typeof spec === "function" ? spec(previewHelpers) : spec);
|
|
377
353
|
return seed;
|
|
@@ -416,4 +392,4 @@ defineComponentImpl.layers = function layersEntry(layers) {
|
|
|
416
392
|
};
|
|
417
393
|
const defineComponent = defineComponentImpl;
|
|
418
394
|
//#endregion
|
|
419
|
-
export {
|
|
395
|
+
export { boolean, defineComponent, defineComponentGroup, defineCompositeStyle, defineMode, defineModifier, defineMotion, defineStyleProp, defineTokenGroup, number, slot, string, variant };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ASSET_CLASS_CAPABILITIES, AssetKind, isPlaceable } from "./asset-kind.js";
|
|
2
|
-
import { AnyRef, AssetGroupName, AssetGroupRef, ComponentName, ComponentRef, CompositeName, CompositeRef, CompositeRefBuilder, ModeName, ModeRef, RegisteredAssetGroups, RegisteredComponents, RegisteredCompositeStyles, RegisteredModes, RegisteredModifiers, RegisteredMotionDefs, RegisteredStyleProps, RegisteredTokenGroups, StylePropName, StylePropRef, TagName, TagRef, TokenGroupName, TokenGroupRef, TokenName, TokenQualifiedName,
|
|
2
|
+
import { AnyRef, AssetGroupName, AssetGroupRef, ComponentName, ComponentRef, CompositeName, CompositeRef, CompositeRefBuilder, ModeName, ModeRef, RegisteredAssetGroups, RegisteredComponents, RegisteredCompositeStyles, RegisteredModes, RegisteredModifiers, RegisteredMotionDefs, RegisteredStyleProps, RegisteredTokenGroups, StylePropName, StylePropRef, TagName, TagRef, TokenGroupName, TokenGroupRef, TokenName, TokenQualifiedName, TokenRef, assetGroup, component, composite, isAssetGroupRef, isComponentRef, isCompositeRef, isModeRef, isStylePropRef, isTagRef, isTokenGroupRef, isTokenRef, mode, styleProp, tag, token, tokenGroup } from "./refs.js";
|
|
3
3
|
import { ColorFn, ColorKeyword, CssAngle, CssColor, CssLength, CssPercentage, CssRatio, CssTime, CssValue, CssValueTypeName, CssVarRef, HexColor, HslColor, RgbColor } from "./types/css-values.js";
|
|
4
4
|
import { ColorExpression, ColorSpace, ColorValue, GradientStop, GradientValue, LengthOrPercent, LineDirection, LinearGradientExpr, MixExpr, RadialGradientExpr, RadialSize, TokenRefToCss, alpha, isColorExpression, isLinearGradientExpr, isMixExpr, isRadialGradientExpr, linearGradient, mix, radialGradient, resolveColorExpression } from "./colorExpressions.js";
|
|
5
5
|
import { CSS_GLOBAL_KEYWORDS, CSS_PROPERTY_KEYWORDS, CssPropertyWithKeywords } from "./types/css-property-keywords.js";
|
|
@@ -15,7 +15,7 @@ import { CompositeStyle } from "./CompositeStyle.js";
|
|
|
15
15
|
import { makeTokenRefToCss } from "./entity-utils.js";
|
|
16
16
|
import { DataAttrs } from "./Props.js";
|
|
17
17
|
import { defineProvider } from "./defineProvider.js";
|
|
18
|
-
import { BoundComponent, ComponentBuilder, ComponentBuilderMethods, ComponentRenderFn, ConfigCallbackHelpers, DefineComponentFn, DefinedComponent, DefinedProvider, DefinedStyleProp, DefinedTokenGroup, PreviewCallbackHelpers,
|
|
18
|
+
import { BoundComponent, ComponentBuilder, ComponentBuilderMethods, ComponentRenderFn, ConfigCallbackHelpers, DefineComponentFn, DefinedComponent, DefinedProvider, DefinedStyleProp, DefinedTokenGroup, PreviewCallbackHelpers, TokenGroupMetadata, TypedSlotRef, boolean, defineComponent, defineComponentGroup, defineCompositeStyle, defineMode, defineModifier, defineMotion, defineStyleProp, defineTokenGroup, number, slot, string, variant } from "./factories.js";
|
|
19
19
|
import { Mode, ModeOption } from "./Mode.js";
|
|
20
20
|
import { Modifier } from "./Modifier.js";
|
|
21
21
|
import { CssMotionDef, JsMotionDef, MotionDef } from "./MotionDef.js";
|
|
@@ -30,4 +30,4 @@ import { ELEMENT_MARKER_KIND, ElementMarker, OpaqueLeafPredicate, hasElementMark
|
|
|
30
30
|
import { interpolate } from "./interpolate.js";
|
|
31
31
|
import { ModeBackedModifierDefinition, ModeBackedModifierInput, ModeBackedModifierLookup, OverrideModeRef, OverrideRow, buildModeBackedModifierLookup, buildNestedModifierUpdate, createModeBackedModifierLookup, mergeModifierUpdates, modifierIdToPath, modifierPathToId, modifierTreeToOverrideRows, overrideRowsToModifierTree, resolveOverrideRowValue } from "./token-override-rows.js";
|
|
32
32
|
import { rem } from "./units.js";
|
|
33
|
-
export { ASSET_CLASS_CAPABILITIES, type AnyRef, type AnyStylePropDefinition, type ArbitrarySpec, AssetGroup, type AssetGroupBuilder, type AssetGroupConfig, type AssetGroupDefinition, type AssetGroupName, type AssetGroupRef, type AssetKind, type BaseStyles, type BooleanMarker, type BoundComponent, type BuildOptions, CSS_GLOBAL_KEYWORDS, CSS_PROPERTY_KEYWORDS, type ColorCssProperty, type ColorExpression, type ColorFn, type ColorKeyword, type ColorSpace, type ColorValue, Component, type ComponentBuilder, type ComponentBuilderMethods, type ComponentDefinition, ComponentGroup, type ComponentGroupDefinition, type ComponentKind, type ComponentMetadata, type ComponentName, type ComponentRef, type ComponentRenderFn, type CompositeInfo, type CompositeName, type CompositeRef, type CompositeRefBuilder, CompositeStyle, type CompositeStyleDefinition, type CompositeStyleObject, type CompoundPropsEntry, Config, type ConfigCallbackHelpers, type Css, type CssAngle, type CssClassName, type CssColor, type CssDeclaration, type CssGlobalKeyword, type CssLength, CssMotionDef, type CssMotionDefinition, type CssPercentage, type CssPropertyName, type CssPropertyValues, type CssPropertyWithKeywords, type CssRatio, type CssSelector, type CssTime, type CssValue, type CssValueTypeName, type CssVar, type CssVarRef, type DataAttrs, type DefineComponentFn, type DefinedComponent, type DefinedProvider, type DefinedStyleProp, type DefinedTokenGroup, type DependenciesQuery, type DependencyKind, type DependencyRef, type DependentsQuery, ELEMENT_MARKER_KIND, type ElementMarker, type FontAssetGroupConfig, type FontAssetGroupDefinition, type FontAssetMember, type FunctionInfo, type GlobalStylesDef, type GradientStop, type GradientValue, type HexColor, type HslColor, type IconAssetGroupConfig, type IconAssetGroupDefinition, type IconAssetMember, type IconAssetMetadata, JsMotionDef, type JsMotionDefinition, Layer, type LayerInput, type LayerMarker, type LengthOrPercent, type LineDirection, type LinearGradientExpr, type LiteralFor, type MixExpr, Mode, type ModeBackedModifierDefinition, type ModeBackedModifierInput, type ModeBackedModifierLookup, type ModeDefinition, type ModeName, ModeOption, type ModeOptionDefinition, type ModeRef, Modifier, type ModifierDefinition, type MotionDef, type MotionDefinitionInput, type MotionKeyframes, type MotionStateKeyframe, type MotionTransition, type NumberMarker, type OpacityPairSpec, type OpaqueLeafPredicate, type OverrideModeRef, type OverrideRow, PREVIEW_SEED_KEY, type PreviewAxisMarker, type PreviewCallbackHelpers, type PreviewDefinition, type PreviewPropsRule, type PrimitivePropKind, type PropBase, type PropBinding, type PropInfo, type PropKind, Provider, type RadialGradientExpr, type RadialSize, type
|
|
33
|
+
export { ASSET_CLASS_CAPABILITIES, type AnyRef, type AnyStylePropDefinition, type ArbitrarySpec, AssetGroup, type AssetGroupBuilder, type AssetGroupConfig, type AssetGroupDefinition, type AssetGroupName, type AssetGroupRef, type AssetKind, type BaseStyles, type BooleanMarker, type BoundComponent, type BuildOptions, CSS_GLOBAL_KEYWORDS, CSS_PROPERTY_KEYWORDS, type ColorCssProperty, type ColorExpression, type ColorFn, type ColorKeyword, type ColorSpace, type ColorValue, Component, type ComponentBuilder, type ComponentBuilderMethods, type ComponentDefinition, ComponentGroup, type ComponentGroupDefinition, type ComponentKind, type ComponentMetadata, type ComponentName, type ComponentRef, type ComponentRenderFn, type CompositeInfo, type CompositeName, type CompositeRef, type CompositeRefBuilder, CompositeStyle, type CompositeStyleDefinition, type CompositeStyleObject, type CompoundPropsEntry, Config, type ConfigCallbackHelpers, type Css, type CssAngle, type CssClassName, type CssColor, type CssDeclaration, type CssGlobalKeyword, type CssLength, CssMotionDef, type CssMotionDefinition, type CssPercentage, type CssPropertyName, type CssPropertyValues, type CssPropertyWithKeywords, type CssRatio, type CssSelector, type CssTime, type CssValue, type CssValueTypeName, type CssVar, type CssVarRef, type DataAttrs, type DefineComponentFn, type DefinedComponent, type DefinedProvider, type DefinedStyleProp, type DefinedTokenGroup, type DependenciesQuery, type DependencyKind, type DependencyRef, type DependentsQuery, ELEMENT_MARKER_KIND, type ElementMarker, type FontAssetGroupConfig, type FontAssetGroupDefinition, type FontAssetMember, type FunctionInfo, type GlobalStylesDef, type GradientStop, type GradientValue, type HexColor, type HslColor, type IconAssetGroupConfig, type IconAssetGroupDefinition, type IconAssetMember, type IconAssetMetadata, JsMotionDef, type JsMotionDefinition, Layer, type LayerInput, type LayerMarker, type LengthOrPercent, type LineDirection, type LinearGradientExpr, type LiteralFor, type MixExpr, Mode, type ModeBackedModifierDefinition, type ModeBackedModifierInput, type ModeBackedModifierLookup, type ModeDefinition, type ModeName, ModeOption, type ModeOptionDefinition, type ModeRef, Modifier, type ModifierDefinition, type MotionDef, type MotionDefinitionInput, type MotionKeyframes, type MotionStateKeyframe, type MotionTransition, type NumberMarker, type OpacityPairSpec, type OpaqueLeafPredicate, type OverrideModeRef, type OverrideRow, PREVIEW_SEED_KEY, type PreviewAxisMarker, type PreviewCallbackHelpers, type PreviewDefinition, type PreviewPropsRule, type PrimitivePropKind, type PropBase, type PropBinding, type PropInfo, type PropKind, Provider, type RadialGradientExpr, type RadialSize, type RegisteredAssetGroups, type RegisteredComponents, type RegisteredCompositeStyles, type RegisteredModes, type RegisteredModifiers, type RegisteredMotionDefs, type RegisteredStyleProps, type RegisteredTokenGroups, type RequiredBrand, type ResolvedCompoundOverrides, type ResolvedTokenLiteral, type RgbColor, SOURCE_PATH_KEY, type SerializedAssetGroup, type SerializedComponentGroup, type SerializedConfig, type SerializedFontAssetGroup, type SerializedIconAssetGroup, type SerializedTokenGroup, type SlotInfo, type SlotMarker, type SlotMotion, type SlotRef, type SlotValueKind, type SlotValueType, type StringMarker, StyleProp, type StylePropDefinition, type StylePropInfo, type StylePropKeyword, type StylePropMetadata, type StylePropName, type StylePropProperty, type StylePropRef, type StylePropTokenUsage, type TagName, type TagRef, Token, type TokenDefinition, TokenGroup, type TokenGroupDefinition, type TokenGroupMetadata, type TokenGroupName, type TokenGroupRef, type TokenModifierKey, type TokenModifierValue, type TokenName, type TokenQualifiedName, type TokenRef, type TokenRefToCss, type TokenType, type TokenValue, type TypedSlotRef, type ValuesEntry, type VariantInfo, type VariantMarker, type VariantMarkerArray, type VariantMarkerObject, alpha, assetGroup, attachSourcePath, boolean, buildModeBackedModifierLookup, buildNestedModifierUpdate, captureCallerPath, component, composite, createModeBackedModifierLookup, cssClassName, cssDeclaration, cssSelector, cssVar, defineAssetGroup, defineAssetIcon, defineComponent, defineComponentGroup, defineCompositeStyle, defineMode, defineModifier, defineMotion, defineProvider, defineStyleProp, defineTokenGroup, findComponentReferrers, hasElementMarkerDeep, interpolate, isAssetGroupRef, isBoolMarker, isColorExpression, isComponentRef, isCompositeRef, isElementLikeValue, isElementMarker, isLayerMarker, isLinearGradientExpr, isMixExpr, isModeRef, isNumberMarker, isPlaceable, isPreviewAxisMarker, isRadialGradientExpr, isSlotMarker, isStringMarker, isStylePropRef, isTagRef, isTokenGroupRef, isTokenRef, isVariantArrayMarker, isVariantMarker, linearGradient, makeTokenRefToCss, matchesPreviewWhen, mergeModifierUpdates, mix, mode, modifierIdToPath, modifierPathToId, modifierTreeToOverrideRows, number, overrideRowsToModifierTree, parseRegistryKey, radialGradient, readSourcePath, rem, resolveColorExpression, resolveOverrideRowValue, resolvePreviewRules, reviveElementMarkersDeep, slot, string, styleProp, tag, token, tokenGroup, variant };
|
package/dist/index.js
CHANGED
|
@@ -21,9 +21,9 @@ import { TokenGroup } from "./TokenGroup.js";
|
|
|
21
21
|
import { Config, parseRegistryKey } from "./Config.js";
|
|
22
22
|
import { findComponentReferrers } from "./component-referrers.js";
|
|
23
23
|
import { defineProvider } from "./defineProvider.js";
|
|
24
|
-
import {
|
|
24
|
+
import { boolean, defineComponent, defineComponentGroup, defineCompositeStyle, defineMode, defineModifier, defineMotion, defineStyleProp, defineTokenGroup, number, slot, string, variant } from "./factories.js";
|
|
25
25
|
import { interpolate } from "./interpolate.js";
|
|
26
26
|
import { buildModeBackedModifierLookup, buildNestedModifierUpdate, createModeBackedModifierLookup, mergeModifierUpdates, modifierIdToPath, modifierPathToId, modifierTreeToOverrideRows, overrideRowsToModifierTree, resolveOverrideRowValue } from "./token-override-rows.js";
|
|
27
27
|
import { CSS_GLOBAL_KEYWORDS, CSS_PROPERTY_KEYWORDS } from "./types/css-property-keywords.js";
|
|
28
28
|
import { rem } from "./units.js";
|
|
29
|
-
export { ASSET_CLASS_CAPABILITIES, AssetGroup, CSS_GLOBAL_KEYWORDS, CSS_PROPERTY_KEYWORDS, Component, ComponentGroup, CompositeStyle, Config, CssMotionDef, ELEMENT_MARKER_KIND, JsMotionDef, Layer, Mode, ModeOption, Modifier, PREVIEW_SEED_KEY, Provider, SOURCE_PATH_KEY, StyleProp, Token, TokenGroup, alpha,
|
|
29
|
+
export { ASSET_CLASS_CAPABILITIES, AssetGroup, CSS_GLOBAL_KEYWORDS, CSS_PROPERTY_KEYWORDS, Component, ComponentGroup, CompositeStyle, Config, CssMotionDef, ELEMENT_MARKER_KIND, JsMotionDef, Layer, Mode, ModeOption, Modifier, PREVIEW_SEED_KEY, Provider, SOURCE_PATH_KEY, StyleProp, Token, TokenGroup, alpha, assetGroup, attachSourcePath, boolean, buildModeBackedModifierLookup, buildNestedModifierUpdate, captureCallerPath, component, composite, createModeBackedModifierLookup, cssClassName, cssDeclaration, cssSelector, cssVar, defineAssetGroup, defineAssetIcon, defineComponent, defineComponentGroup, defineCompositeStyle, defineMode, defineModifier, defineMotion, defineProvider, defineStyleProp, defineTokenGroup, findComponentReferrers, hasElementMarkerDeep, interpolate, isAssetGroupRef, isBoolMarker, isColorExpression, isComponentRef, isCompositeRef, isElementLikeValue, isElementMarker, isLayerMarker, isLinearGradientExpr, isMixExpr, isModeRef, isNumberMarker, isPlaceable, isPreviewAxisMarker, isRadialGradientExpr, isSlotMarker, isStringMarker, isStylePropRef, isTagRef, isTokenGroupRef, isTokenRef, isVariantArrayMarker, isVariantMarker, linearGradient, makeTokenRefToCss, matchesPreviewWhen, mergeModifierUpdates, mix, mode, modifierIdToPath, modifierPathToId, modifierTreeToOverrideRows, number, overrideRowsToModifierTree, parseRegistryKey, radialGradient, readSourcePath, rem, resolveColorExpression, resolveOverrideRowValue, resolvePreviewRules, reviveElementMarkersDeep, slot, string, styleProp, tag, token, tokenGroup, variant };
|
package/dist/refs.d.ts
CHANGED
|
@@ -34,7 +34,6 @@ interface RegisteredStyleProps {}
|
|
|
34
34
|
interface RegisteredComponents {}
|
|
35
35
|
interface RegisteredMotionDefs {}
|
|
36
36
|
interface RegisteredAssetGroups {}
|
|
37
|
-
interface TokenRawNameRegistry {}
|
|
38
37
|
/** `<groupName>/<tokenName>` for every registered token. */
|
|
39
38
|
type TokenName = [keyof RegisteredTokenGroups] extends [never] ? string : { [G in keyof RegisteredTokenGroups & string]: `${G}/${keyof RegisteredTokenGroups[G] & string}` }[keyof RegisteredTokenGroups & string];
|
|
40
39
|
/** Bare group names — `'color'`, `'spacing'`. */
|
|
@@ -156,4 +155,4 @@ declare function isTagRef(value: unknown): value is TagRef;
|
|
|
156
155
|
declare function isComponentRef(value: unknown): value is ComponentRef;
|
|
157
156
|
declare function isAssetGroupRef(value: unknown): value is AssetGroupRef;
|
|
158
157
|
//#endregion
|
|
159
|
-
export { AnyRef, AssetGroupName, AssetGroupRef, ComponentName, ComponentRef, CompositeName, CompositeRef, CompositeRefBuilder, ModeName, ModeRef, RegisteredAssetGroups, RegisteredComponents, RegisteredCompositeStyles, RegisteredModes, RegisteredModifiers, RegisteredMotionDefs, RegisteredStyleProps, RegisteredTokenGroups, StylePropName, StylePropRef, TagName, TagRef, TokenGroupName, TokenGroupRef, TokenName, TokenQualifiedName,
|
|
158
|
+
export { AnyRef, AssetGroupName, AssetGroupRef, ComponentName, ComponentRef, CompositeName, CompositeRef, CompositeRefBuilder, ModeName, ModeRef, RegisteredAssetGroups, RegisteredComponents, RegisteredCompositeStyles, RegisteredModes, RegisteredModifiers, RegisteredMotionDefs, RegisteredStyleProps, RegisteredTokenGroups, StylePropName, StylePropRef, TagName, TagRef, TokenGroupName, TokenGroupRef, TokenName, TokenQualifiedName, TokenRef, assetGroup, component, composite, isAssetGroupRef, isComponentRef, isCompositeRef, isModeRef, isStylePropRef, isTagRef, isTokenGroupRef, isTokenRef, mode, styleProp, tag, token, tokenGroup };
|
package/dist/spec/specToJsx.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isSlotRef } from "./slot-refs.js";
|
|
2
2
|
import { assetJsxForm } from "./asset-jsx.js";
|
|
3
|
-
import {
|
|
3
|
+
import { serializeProps } from "@json-render/codegen";
|
|
4
4
|
//#region src/spec/specToJsx.ts
|
|
5
5
|
function statePathToExpression(path) {
|
|
6
6
|
return `state${path.split("/").filter(Boolean).map((s) => `.${s}`).join("")}`;
|
|
@@ -28,10 +28,35 @@ function renderActionBinding(binding) {
|
|
|
28
28
|
function eventNameToJsx(name) {
|
|
29
29
|
return `on${name.charAt(0).toUpperCase()}${name.slice(1)}`;
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Collect every element `type` reachable from `spec.root` via `children`.
|
|
33
|
+
* A local, cycle-safe stand-in for `@json-render/codegen`'s
|
|
34
|
+
* `collectUsedComponents` — that helper's `children` walk has no visited
|
|
35
|
+
* guard and stack-overflows on a cyclic element graph, the same failure
|
|
36
|
+
* mode `renderElement`'s `ancestors` guard protects against below (see
|
|
37
|
+
* UDS-2351).
|
|
38
|
+
*/
|
|
39
|
+
function collectUsedComponentTypes(spec) {
|
|
40
|
+
const types = /* @__PURE__ */ new Set();
|
|
41
|
+
const visited = /* @__PURE__ */ new Set();
|
|
42
|
+
const stack = [spec.root];
|
|
43
|
+
while (stack.length > 0) {
|
|
44
|
+
const key = stack.pop();
|
|
45
|
+
if (key === void 0 || visited.has(key)) continue;
|
|
46
|
+
visited.add(key);
|
|
47
|
+
const element = spec.elements[key];
|
|
48
|
+
if (!element) continue;
|
|
49
|
+
types.add(element.type);
|
|
50
|
+
for (const childKey of element.children ?? []) stack.push(childKey);
|
|
51
|
+
}
|
|
52
|
+
return types;
|
|
53
|
+
}
|
|
54
|
+
function renderElement(key, spec, depth, assetComponents, ancestors) {
|
|
32
55
|
const element = spec.elements[key];
|
|
33
56
|
if (!element) return "";
|
|
34
57
|
const indent = " ".repeat(depth);
|
|
58
|
+
if (ancestors.has(key)) return `${indent}{/* cyclic reference to "${key}" omitted */}`;
|
|
59
|
+
const withSelf = new Set(ancestors).add(key);
|
|
35
60
|
const { children: _children, ...restProps } = element.props ?? {};
|
|
36
61
|
const slotKeys = collectSlotKeys(restProps);
|
|
37
62
|
const slotAttrs = [];
|
|
@@ -39,10 +64,10 @@ function renderElement(key, spec, depth, assetComponents) {
|
|
|
39
64
|
for (const [propName, propValue] of Object.entries(restProps)) if (isSlotRef(propValue)) {
|
|
40
65
|
const refs = Array.isArray(propValue.$slot) ? propValue.$slot : [propValue.$slot];
|
|
41
66
|
if (refs.length === 1) {
|
|
42
|
-
const rendered = renderElement(refs[0], spec, 0, assetComponents).trim();
|
|
67
|
+
const rendered = renderElement(refs[0], spec, 0, assetComponents, withSelf).trim();
|
|
43
68
|
slotAttrs.push(`${propName}={${rendered}}`);
|
|
44
69
|
} else {
|
|
45
|
-
const rendered = refs.map((r) => renderElement(r, spec, 0, assetComponents).trim()).filter(Boolean);
|
|
70
|
+
const rendered = refs.map((r) => renderElement(r, spec, 0, assetComponents, withSelf).trim()).filter(Boolean);
|
|
46
71
|
slotAttrs.push(`${propName}={<>${rendered.join("")}</>}`);
|
|
47
72
|
}
|
|
48
73
|
} else propsWithoutSlots[propName] = propValue;
|
|
@@ -92,7 +117,7 @@ function renderElement(key, spec, depth, assetComponents) {
|
|
|
92
117
|
if (inlineContent !== null) childLines.push(`${" ".repeat(depth + 1)}${inlineContent}`);
|
|
93
118
|
for (const childKey of childKeys) {
|
|
94
119
|
if (!spec.elements[childKey]) continue;
|
|
95
|
-
childLines.push(renderElement(childKey, spec, depth + 1, assetComponents));
|
|
120
|
+
childLines.push(renderElement(childKey, spec, depth + 1, assetComponents, withSelf));
|
|
96
121
|
}
|
|
97
122
|
jsxLine = `${indent}<${tag}${propsStr}>\n${childLines.join("\n")}\n${indent}</${tag}>`;
|
|
98
123
|
}
|
|
@@ -112,8 +137,8 @@ function specToJsx(spec, options) {
|
|
|
112
137
|
imports: []
|
|
113
138
|
};
|
|
114
139
|
const assetComponents = options?.assetComponents;
|
|
115
|
-
const sortedImports = [...new Set([...
|
|
116
|
-
const jsxTree = renderElement(spec.root, spec, 0, assetComponents);
|
|
140
|
+
const sortedImports = [...new Set([...collectUsedComponentTypes(spec)].map((type) => assetJsxForm(type, assetComponents)?.importName ?? type))].sort();
|
|
141
|
+
const jsxTree = renderElement(spec.root, spec, 0, assetComponents, /* @__PURE__ */ new Set());
|
|
117
142
|
if (options?.omitImports) return {
|
|
118
143
|
jsx: jsxTree,
|
|
119
144
|
imports: sortedImports
|