@yahoo/uds-v5-wip 1.61.0 → 1.62.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/config/dist/AssetGroup.d.ts +75 -0
- package/dist/config/dist/AssetGroup.js +114 -0
- package/dist/config/dist/Component.d.ts +309 -0
- package/dist/config/dist/Component.js +897 -0
- package/dist/config/dist/ComponentGroup.d.ts +21 -0
- package/dist/config/dist/ComponentGroup.js +46 -0
- package/dist/config/dist/CompositeStyle.d.ts +28 -0
- package/dist/config/dist/CompositeStyle.js +52 -0
- package/dist/config/dist/Config.d.ts +422 -0
- package/dist/config/dist/Config.js +1426 -0
- package/dist/config/dist/Mode.d.ts +42 -0
- package/dist/config/dist/Mode.js +81 -0
- package/dist/config/dist/Modifier.d.ts +52 -0
- package/dist/config/dist/Modifier.js +97 -0
- package/dist/config/dist/MotionDef.d.ts +50 -0
- package/dist/config/dist/MotionDef.js +97 -0
- package/dist/config/dist/Props.d.ts +235 -126
- package/dist/config/dist/Provider.d.ts +21 -0
- package/dist/config/dist/Provider.js +14 -0
- package/dist/config/dist/StyleProp.d.ts +113 -0
- package/dist/config/dist/StyleProp.js +197 -0
- package/dist/config/dist/Token.d.ts +56 -0
- package/dist/config/dist/Token.js +112 -0
- package/dist/config/dist/TokenGroup.d.ts +33 -0
- package/dist/config/dist/TokenGroup.js +68 -0
- package/dist/config/dist/asset-kind.d.ts +56 -0
- package/dist/config/dist/asset-kind.js +29 -0
- package/dist/config/dist/brands.d.ts +31 -0
- package/dist/config/dist/brands.js +20 -0
- package/dist/config/dist/captureCallerPath.d.ts +49 -0
- package/dist/config/dist/captureCallerPath.js +95 -0
- package/dist/config/dist/colorExpressions.d.ts +132 -0
- package/dist/config/dist/colorExpressions.js +148 -0
- package/dist/config/dist/defineAssetGroup.d.ts +158 -0
- package/dist/config/dist/defineAssetGroup.js +263 -0
- package/dist/config/dist/defineProvider.d.ts +30 -0
- package/dist/config/dist/defineProvider.js +60 -0
- package/dist/config/dist/element-marker.d.ts +55 -0
- package/dist/config/dist/element-marker.js +113 -0
- package/dist/config/dist/entity-utils.d.ts +27 -0
- package/dist/config/dist/entity-utils.js +105 -0
- package/dist/config/dist/factories.d.ts +707 -0
- package/dist/config/dist/factories.js +393 -0
- package/dist/config/dist/foreign-component-name.js +42 -0
- package/dist/config/dist/index.d.ts +30 -21
- package/dist/config/dist/index.js +26 -14
- package/dist/config/dist/interpolate.d.ts +21 -0
- package/dist/config/dist/interpolate.js +10 -0
- package/dist/config/dist/markers.d.ts +218 -0
- package/dist/config/dist/markers.js +67 -0
- package/dist/config/dist/refs.d.ts +143 -69
- package/dist/config/dist/refs.js +95 -113
- package/dist/config/dist/token-override-rows.d.ts +67 -0
- package/dist/config/dist/token-override-rows.js +223 -0
- package/dist/config/dist/tokenValueType.js +138 -0
- package/dist/config/dist/types/css-properties.d.ts +132 -122
- package/dist/config/dist/types/css-property-keywords.d.ts +157 -0
- package/dist/config/dist/types/css-property-keywords.js +616 -0
- package/dist/config/dist/types/css-values.d.ts +18 -16
- package/dist/config/dist/types.d.ts +688 -66
- package/dist/config/dist/units.d.ts +15 -0
- package/dist/config/dist/units.js +16 -0
- package/dist/config.d.ts +31 -22
- package/dist/config.js +28 -16
- package/dist/loader/dist/loader/artifacts.js +26 -9
- package/dist/loader/dist/loader.d.ts +11 -23
- package/dist/loader/dist/loader.js +54 -99
- package/dist/loader/dist/next.js +3 -3
- package/dist/loader/dist/transform-runner.js +1 -8
- package/dist/loader/dist/unplugin.d.ts +2 -2
- package/dist/loader/dist/unplugin.js +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/dist/index.js +1 -0
- package/dist/utils/dist/motion-utils/resolveMotionState.d.ts +35 -0
- package/dist/utils/dist/motion-utils/resolveMotionState.js +33 -0
- package/dist/utils/dist/string-utils/componentClassName.d.ts +41 -8
- package/dist/utils/dist/string-utils/componentClassName.js +48 -11
- package/dist/utils.d.ts +3 -2
- package/dist/utils.js +3 -2
- package/package.json +3 -3
- package/dist/codegen/dist/loader/getLoaderArtifacts.js +0 -2
- package/dist/config/dist/bindRender.d.ts +0 -16
- package/dist/config/dist/bindRender.js +0 -310
- package/dist/config/dist/className.d.ts +0 -54
- package/dist/config/dist/className.js +0 -77
- package/dist/config/dist/component-config.d.ts +0 -862
- package/dist/config/dist/component-config.js +0 -163
- package/dist/config/dist/component-refs.d.ts +0 -121
- package/dist/config/dist/createConfig.d.ts +0 -456
- package/dist/config/dist/createConfig.js +0 -503
- package/dist/config/dist/createStyler.d.ts +0 -35
- package/dist/config/dist/createStyler.js +0 -93
- package/dist/config/dist/defineComponent.d.ts +0 -317
- package/dist/config/dist/defineComponent.js +0 -264
- package/dist/config/dist/defineCompositeStyle.d.ts +0 -93
- package/dist/config/dist/defineCompositeStyle.js +0 -18
- package/dist/config/dist/defineMotionConfig.d.ts +0 -152
- package/dist/config/dist/definePreview.d.ts +0 -45
- package/dist/config/dist/definePreview.js +0 -35
- package/dist/config/dist/defineStyleProp.d.ts +0 -289
- package/dist/config/dist/defineStyleProp.js +0 -61
- package/dist/config/dist/merge-utils.js +0 -51
- package/dist/config/dist/propertyAcceptedTypes.d.ts +0 -19
- package/dist/config/dist/propertyAcceptedTypes.js +0 -220
- package/dist/config/dist/resolveCompoundProps.d.ts +0 -65
- package/dist/config/dist/resolveCompoundProps.js +0 -120
- package/dist/config/dist/resolveStyleProp.d.ts +0 -157
- package/dist/config/dist/resolveStyleProp.js +0 -260
- package/dist/config/dist/runtime-registry.js +0 -37
- package/dist/config/dist/serialize.d.ts +0 -47
- package/dist/config/dist/serialize.js +0 -111
- package/dist/config/dist/sniffTokenType.d.ts +0 -7
- package/dist/config/dist/sniffTokenType.js +0 -67
- package/dist/config/dist/style-prop-runtime.d.ts +0 -75
- package/dist/config/dist/style-prop-runtime.js +0 -390
- package/dist/loader/dist/loader/internal-meta.js +0 -59
- package/dist/loader/dist/loader/lower-new-api-primitive.js +0 -252
|
@@ -1,862 +0,0 @@
|
|
|
1
|
-
import { CompositeRef, RegisteredComposites, StylePropRef } from "./component-refs.js";
|
|
2
|
-
import { SlotMotionConfig } from "./defineMotionConfig.js";
|
|
3
|
-
import { Props } from "./Props.js";
|
|
4
|
-
import * as _$react from "react";
|
|
5
|
-
import { CSSProperties, ReactNode } from "react";
|
|
6
|
-
import { ArbitraryValue, ModifierProp } from "@uds/types";
|
|
7
|
-
|
|
8
|
-
//#region ../config/dist/component-config.d.ts
|
|
9
|
-
//#region src/component-config.d.ts
|
|
10
|
-
/**
|
|
11
|
-
* Style values for a component-config slot. Accepts every registered
|
|
12
|
-
* style-prop name (per-app `RegisteredStyleProps` augmentation provides
|
|
13
|
-
* autocomplete), standard CSS properties (camelCase), and modifier
|
|
14
|
-
* objects (e.g. `_hover: { ... }`). Values are raw CSS strings, token
|
|
15
|
-
* literals, or `token('ns/name')` markers — not typed token names.
|
|
16
|
-
*/
|
|
17
|
-
type ComponentSlotStyles = { [K in Exclude<string | keyof CSSProperties, 'motion'>]?: string | number | boolean | TokenMarker | undefined } & { [K in ModifierProp]?: ComponentSlotStyles } & {
|
|
18
|
-
/** Per-slot motion config (JS runtime): co-located with slot styles. */motion?: SlotMotionConfig;
|
|
19
|
-
};
|
|
20
|
-
/** Allowed values for component slot motion in config objects. */
|
|
21
|
-
type ComponentMotionValue<TMotionAlias extends string = string> = SlotMotionConfig | TMotionAlias | ArbitraryValue;
|
|
22
|
-
/**
|
|
23
|
-
* HTML tag literal. The TypeScript type is `string` (any tag name);
|
|
24
|
-
* runtime renders it via `React.createElement(tag, ...)`.
|
|
25
|
-
*
|
|
26
|
-
* Kept as `string` instead of `keyof JSX.IntrinsicElements` so the type
|
|
27
|
-
* doesn't pull a 200-key union into every layer position. Editors still
|
|
28
|
-
* autocomplete tag names from JSX.
|
|
29
|
-
*/
|
|
30
|
-
type HtmlTag = string;
|
|
31
|
-
/**
|
|
32
|
-
* Per-slot motion descriptor — same shape the legacy `base.<slot>.motion`
|
|
33
|
-
* carried, surfaced verbatim into the build-time manifest under
|
|
34
|
-
* `components.<Name>.motion.<slot>`. Codegen does not interpret the
|
|
35
|
-
* keys; the loader's `applySlotMotionToElement` reads them at JSX
|
|
36
|
-
* rewrite time, so adding a new field here automatically flows through
|
|
37
|
-
* once the loader picks it up.
|
|
38
|
-
*
|
|
39
|
-
* `runtime: 'css'` opts out — the loader's `getCustomSlotMotion` skips
|
|
40
|
-
* css-runtime entries (CSS keyframes are handled elsewhere).
|
|
41
|
-
*/
|
|
42
|
-
interface SlotMotion {
|
|
43
|
-
readonly runtime?: 'js' | 'css';
|
|
44
|
-
readonly initial?: unknown;
|
|
45
|
-
readonly animate?: unknown;
|
|
46
|
-
readonly exit?: unknown;
|
|
47
|
-
readonly transition?: unknown;
|
|
48
|
-
readonly whileHover?: unknown;
|
|
49
|
-
readonly whileTap?: unknown;
|
|
50
|
-
readonly drag?: unknown;
|
|
51
|
-
readonly dragConstraints?: unknown;
|
|
52
|
-
readonly dragElastic?: unknown;
|
|
53
|
-
readonly dragSnapToOrigin?: unknown;
|
|
54
|
-
readonly layout?: unknown;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Object form for a primitive (HTML-tag) layer that needs locked attrs
|
|
58
|
-
* (e.g. `role`, `aria-*`, locked `href`).
|
|
59
|
-
*
|
|
60
|
-
* Distributive mapped union over `keyof React.JSX.IntrinsicElements` so
|
|
61
|
-
* `attrs` is narrowed to the HTML props valid for the chosen `tag` at
|
|
62
|
-
* the call site — `{ tag: 'a', attrs: { href: '/x' } }` type-checks;
|
|
63
|
-
* `{ tag: 'div', attrs: { href: '/x' } }` does not.
|
|
64
|
-
*
|
|
65
|
-
* Per-layer base styles live in the config's top-level
|
|
66
|
-
* `base: { <layer>: {...} }` block — not inside this object.
|
|
67
|
-
*/
|
|
68
|
-
type PrimitiveLayer = { [T in keyof _$react.JSX.IntrinsicElements]: {
|
|
69
|
-
tag: T;
|
|
70
|
-
attrs?: Partial<_$react.ComponentPropsWithoutRef<T>>;
|
|
71
|
-
} }[keyof _$react.JSX.IntrinsicElements];
|
|
72
|
-
/**
|
|
73
|
-
* Structural shape of a `defineComponent` value as it appears in a
|
|
74
|
-
* `layers` slot. Mirrors `BoundComponent` from `defineComponent.ts` but
|
|
75
|
-
* defined locally to avoid the circular import (`defineComponent.ts`
|
|
76
|
-
* imports types from this file). Authors don't see this shape directly
|
|
77
|
-
* — they pass the actual `BoundComponent` value, which satisfies it.
|
|
78
|
-
*
|
|
79
|
-
* The `__config` slot is the discriminator that distinguishes a
|
|
80
|
-
* composed-component layer from a plain function (which a layer can't
|
|
81
|
-
* be — guards on the layer position rely on this brand).
|
|
82
|
-
*/
|
|
83
|
-
type ComposedComponentValue = _$react.FC< // biome-ignore lint/suspicious/noExplicitAny: any registered component
|
|
84
|
-
any> & {
|
|
85
|
-
readonly __config: ComponentConfigValue<Record<string, LayerInput>, any, HtmlTag | undefined>;
|
|
86
|
-
};
|
|
87
|
-
/**
|
|
88
|
-
* Allowed forms for a single layer's value:
|
|
89
|
-
*
|
|
90
|
-
* - **`HtmlTag`** — bare string (`'div'`, `'span'`, `'a'`, …) for
|
|
91
|
-
* plain HTML elements.
|
|
92
|
-
* - **`PrimitiveLayer`** — `{ tag, attrs }` object form for HTML
|
|
93
|
-
* layers that need locked attributes (`role`, `aria-*`, etc.).
|
|
94
|
-
* - **`ComposedComponentValue`** — a `defineComponent`-produced
|
|
95
|
-
* value (`Box`, `Pressable`, `Text`, …) used directly as the
|
|
96
|
-
* layer value.
|
|
97
|
-
*
|
|
98
|
-
* Per-layer base styles always live in the config's top-level
|
|
99
|
-
* `base: { <layer>: {...} }` block; consumer-facing JSX defaults go
|
|
100
|
-
* in `defaultProps: { <prop>: value }`.
|
|
101
|
-
*/
|
|
102
|
-
type LayerInput = HtmlTag | PrimitiveLayer | ComposedComponentValue;
|
|
103
|
-
/**
|
|
104
|
-
* Bind a registered style prop to a specific layer. The style prop's
|
|
105
|
-
* resolved class name is added to that layer's `className` bundle at
|
|
106
|
-
* render time.
|
|
107
|
-
*
|
|
108
|
-
* `styleProp` is narrowed against `RegisteredStyleProps`. `layer` is a
|
|
109
|
-
* string at this level — the consuming type (`ComponentConfig.props`)
|
|
110
|
-
* narrows it against the component's own `layers` keys.
|
|
111
|
-
*/
|
|
112
|
-
interface StylePropBinding {
|
|
113
|
-
layer: string;
|
|
114
|
-
styleProp: StylePropRef;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Extract the root tag literal from a `layers` map when it can be read
|
|
118
|
-
* statically. Returns the string literal `'a' | 'div' | …` when:
|
|
119
|
-
*
|
|
120
|
-
* - `layers.root` is a bare tag string (`'a'`),
|
|
121
|
-
* - `layers.root` is `{ tag: 'a', attrs?: … }`, or
|
|
122
|
-
* - `layers.root` is a component value whose `__config` carries its
|
|
123
|
-
* own captured root tag (recurses one level so a wrapper of
|
|
124
|
-
* `defineComponent('button', …)` inherits `'button'`).
|
|
125
|
-
*
|
|
126
|
-
* Returns `undefined` when `layers.root` is a composed-component layer
|
|
127
|
-
* without a captured tag, or not present. `Props<TConfig>` reads this
|
|
128
|
-
* and substitutes `React.ComponentPropsWithRef<TTag>` for the generic
|
|
129
|
-
* `HTMLAttributes<HTMLElement>` when narrowable.
|
|
130
|
-
*/
|
|
131
|
-
type RootTag<TLayers> = TLayers extends {
|
|
132
|
-
root: infer R;
|
|
133
|
-
} ? R extends HtmlTag ? R extends `{${string}}` ? undefined : R : R extends {
|
|
134
|
-
tag: infer T extends HtmlTag;
|
|
135
|
-
} ? T : R extends {
|
|
136
|
-
readonly __config: ComponentConfigValue<Record<string, LayerInput>, any, infer TInnerTag extends HtmlTag | undefined>;
|
|
137
|
-
} ? TInnerTag : undefined : undefined;
|
|
138
|
-
/**
|
|
139
|
-
* Bind a registered composite to a single layer. Multi-layer composites
|
|
140
|
-
* use the `CompositeBinding` shape instead (see below).
|
|
141
|
-
*/
|
|
142
|
-
interface SingleLayerCompositeBinding {
|
|
143
|
-
layer: string;
|
|
144
|
-
composite: CompositeRef;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Multi-layer composite binding — explicit composite-layer → component-
|
|
148
|
-
* layer mapping. The composite declares its own internal layer names
|
|
149
|
-
* (`default`, `label`, …) and this binding tells the framework which
|
|
150
|
-
* component layer each one maps to.
|
|
151
|
-
*/
|
|
152
|
-
interface CompositeBinding {
|
|
153
|
-
composite: CompositeRef;
|
|
154
|
-
layers: Record<string, string>;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Boolean prop — toggled on/off, no value beyond presence. Useful for
|
|
158
|
-
* `loading`, `disabled`, `selected`. Each layer's bundle gets a
|
|
159
|
-
* data-attribute (`data-loading="true"`) the consumer can target.
|
|
160
|
-
*/
|
|
161
|
-
interface BoolMarker {
|
|
162
|
-
readonly __kind: 'bool';
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* String-valued prop — parallel to `bool()` but the JSX value is a
|
|
166
|
-
* string. Each layer's bundle gets `data-<kebab-name>="<value>"` at
|
|
167
|
-
* render time so CSS can target it (`[data-kind="primary"]`).
|
|
168
|
-
*
|
|
169
|
-
* Authored via `string()` in the `props` block — surfaces as a typed
|
|
170
|
-
* `string` prop at the JSX call site and as a text-input control in
|
|
171
|
-
* the Studio design panel (driven by the `__kind` discriminator).
|
|
172
|
-
*/
|
|
173
|
-
interface StringMarker {
|
|
174
|
-
readonly __kind: 'string';
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Style-prop binding marker — JSX value contributes one resolved
|
|
178
|
-
* utility class to a layer's bundle, looked up by `ref` in the
|
|
179
|
-
* registered style-prop registry. The `__kind` discriminator lets
|
|
180
|
-
* the design panel and codegen branch on prop kind by reading the
|
|
181
|
-
* marker shape directly.
|
|
182
|
-
*
|
|
183
|
-
* Authored via the `styleProp` helper passed into the
|
|
184
|
-
* `defineComponent` callback. Two forms:
|
|
185
|
-
*
|
|
186
|
-
* styleProp('bg') // root layer, shorthand
|
|
187
|
-
* styleProp('label', 'color') // explicit layer
|
|
188
|
-
*/
|
|
189
|
-
interface StylePropMarker<TLayer extends string = string, TRef extends string = string> {
|
|
190
|
-
readonly __kind: 'styleProp';
|
|
191
|
-
readonly layer: TLayer;
|
|
192
|
-
readonly ref: TRef;
|
|
193
|
-
/**
|
|
194
|
-
* Re-target the marker to a different layer. Returns a fresh marker
|
|
195
|
-
* carrying the same `ref` but with `layer` set to `name`:
|
|
196
|
-
*
|
|
197
|
-
* styleProp('color').on('label')
|
|
198
|
-
* // → { __kind: 'styleProp', ref: 'color', layer: 'label' }
|
|
199
|
-
*/
|
|
200
|
-
on<TNewLayer extends string>(name: TNewLayer): StylePropMarker<TNewLayer, TRef>;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Token-reference marker for use inside style values (`base`, `enums`,
|
|
204
|
-
* `compoundProps`). The value tells codegen "look up the token at
|
|
205
|
-
* path `<namespace>/<name>`" — it resolves to `var(--<prefix>-<ns>-<name>)`
|
|
206
|
-
* at build time. The `__kind` discriminator lets the design panel
|
|
207
|
-
* detect a token reference and offer a token picker.
|
|
208
|
-
*
|
|
209
|
-
* Authored via the `token(...)` helper:
|
|
210
|
-
*
|
|
211
|
-
* base: { root: { bg: token('bg/brand') } }
|
|
212
|
-
*/
|
|
213
|
-
interface TokenMarker<TRef extends string = string> {
|
|
214
|
-
readonly __kind: 'token';
|
|
215
|
-
readonly ref: TRef;
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Token-group reference marker for `defineStyleProp({ values: [...] })`
|
|
219
|
-
* entries. Tells the resolver "every token in this namespace is a
|
|
220
|
-
* valid value for this style prop" — so `tokenGroup('spacing')` on a
|
|
221
|
-
* `padding` prop pulls in `spacing/1`, `spacing/2`, … as accepted
|
|
222
|
-
* values that map to `p-1`, `p-2`, … utility classes.
|
|
223
|
-
*
|
|
224
|
-
* Authored via the `tokenGroup(...)` helper.
|
|
225
|
-
*/
|
|
226
|
-
interface TokenGroupMarker<TGroup extends string = string> {
|
|
227
|
-
readonly __kind: 'tokenGroup';
|
|
228
|
-
readonly group: TGroup;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Slot prop — JSX-prop that accepts a `ReactNode` and routes it onto a
|
|
232
|
-
* named layer's bundle. Authored via `slot('layerName')` in the
|
|
233
|
-
* `props` block:
|
|
234
|
-
*
|
|
235
|
-
* defineComponent({
|
|
236
|
-
* layers: { root: 'div', title: 'div', content: 'div' },
|
|
237
|
-
* props: {
|
|
238
|
-
* title: slot('title'),
|
|
239
|
-
* content: slot('content'),
|
|
240
|
-
* },
|
|
241
|
-
* }).render(({ props, children }) => (
|
|
242
|
-
* <div {...props.root}>
|
|
243
|
-
* <div {...props.title} /> // renders the `title` JSX prop
|
|
244
|
-
* <div {...props.content} /> // renders the `content` JSX prop
|
|
245
|
-
* {children}
|
|
246
|
-
* </div>
|
|
247
|
-
* ));
|
|
248
|
-
*
|
|
249
|
-
* **Children routing (default).** Without `as`, the runtime puts the
|
|
250
|
-
* incoming value on `bundles[layer].children`, so spreading the layer
|
|
251
|
-
* bundle places the children automatically.
|
|
252
|
-
*
|
|
253
|
-
* **Named-prop routing (`{ as }`).** With `as: 'propName'`, the runtime
|
|
254
|
-
* puts the value on `bundles[layer][propName]` instead — useful when
|
|
255
|
-
* the layer is a composed component that already exposes its own
|
|
256
|
-
* named slots (`startContent`, `endContent`, …). Lets a wrapper like
|
|
257
|
-
* `EnhancedCard` declare its own JSX prop that forwards into the
|
|
258
|
-
* wrapped `Card`'s slot surface:
|
|
259
|
-
*
|
|
260
|
-
* const EnhancedCard = defineComponent({
|
|
261
|
-
* layers: { root: Card }, // Card as a layer
|
|
262
|
-
* props: {
|
|
263
|
-
* headline: slot('root', { as: 'startContent' }), // → Card.startContent
|
|
264
|
-
* cta: slot('root', { as: 'endContent' }), // → Card.endContent
|
|
265
|
-
* },
|
|
266
|
-
* });
|
|
267
|
-
*
|
|
268
|
-
* Codegen treats slot props as the canonical signal of named slots:
|
|
269
|
-
* each `slot()` entry in a `props` block becomes both a `ReactNode`
|
|
270
|
-
* prop in the catalog (typed as `string | { $slot: elementKey }` in
|
|
271
|
-
* json-render) AND adds the JSX-prop key to the prompt's
|
|
272
|
-
* `[slots: ...]` tag. Replaces the verbose `{ layer, from: 'children' }`
|
|
273
|
-
* forward binding for the common ReactNode-into-layer case.
|
|
274
|
-
*/
|
|
275
|
-
interface SlotMarker<TLayer extends string = '', TProp extends string = 'children'> {
|
|
276
|
-
readonly __kind: 'slot';
|
|
277
|
-
/**
|
|
278
|
-
* Target layer the incoming JSX value routes onto. Empty string
|
|
279
|
-
* (`slot()` with no path) means the value is *not* routed — the
|
|
280
|
-
* marker just declares the JSX-prop key + types it as
|
|
281
|
-
* `ReactNode`; the render function receives the value verbatim in
|
|
282
|
-
* its args.
|
|
283
|
-
*/
|
|
284
|
-
readonly layer: TLayer;
|
|
285
|
-
/**
|
|
286
|
-
* Target prop name on the layer's bundle. Defaults to `'children'`,
|
|
287
|
-
* which is what most slots want (the value lands as the layer
|
|
288
|
-
* element's children). Set to a different name to route into
|
|
289
|
-
* arbitrary props on the target layer's surface (`onClick`,
|
|
290
|
-
* `aria-label`, `startContent`, …).
|
|
291
|
-
*/
|
|
292
|
-
readonly prop?: TProp;
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Composite-style prop — the JSX value picks one entry from a
|
|
296
|
-
* registered composite group's `styles` map. The runtime expands
|
|
297
|
-
* the matched style bag into the layer's bundle and emits a marker
|
|
298
|
-
* class. Implicit `'root'` layer target.
|
|
299
|
-
*
|
|
300
|
-
* Authored via `composite('textVariant')` (bare name — narrowed
|
|
301
|
-
* against the registered composite names) in the `props` block:
|
|
302
|
-
*
|
|
303
|
-
* defineComponent(Box, {
|
|
304
|
-
* defaultProps: { as: 'p' },
|
|
305
|
-
* props: {
|
|
306
|
-
* variant: composite('textVariant'),
|
|
307
|
-
* },
|
|
308
|
-
* });
|
|
309
|
-
*
|
|
310
|
-
* For multi-layer composites or non-root layer targets, use the
|
|
311
|
-
* verbose `{ composite: '{ref}', layers: {...} }` /
|
|
312
|
-
* `{ layer: 'X', composite: '{ref}' }` binding shapes directly (the
|
|
313
|
-
* verbose forms keep the brace-ref shape for consistency with
|
|
314
|
-
* style-prop refs).
|
|
315
|
-
*/
|
|
316
|
-
interface CompositeMarker<TRef extends string = string> {
|
|
317
|
-
readonly __kind: 'composite';
|
|
318
|
-
readonly ref: TRef;
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Enum prop — the value picks one entry from a map. Each entry can
|
|
322
|
-
* declare per-layer style overrides. Mirrors today's `variants.X`
|
|
323
|
-
* surface but co-located with other prop bindings.
|
|
324
|
-
*/
|
|
325
|
-
interface EnumMarker<TValues extends Record<string, unknown>> {
|
|
326
|
-
readonly __kind: 'enum';
|
|
327
|
-
readonly values: TValues;
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* Shorthand binding form — a brace-ref string standing in for the
|
|
331
|
-
* verbose object. `'{bg}'` means "bind the registered style prop `bg`
|
|
332
|
-
* to the *root* layer".
|
|
333
|
-
*
|
|
334
|
-
* Only legal in the primitive form `defineComponent('div', { props: { bg: '{bg}' } })`,
|
|
335
|
-
* where the root layer is unambiguous. In the verbose form
|
|
336
|
-
* `defineComponent({ layers: {...}, props: {...} })` authors must use
|
|
337
|
-
* the explicit long-form `{ layer, styleProp: '{bg}' }` binding so
|
|
338
|
-
* the target layer is named at the call site.
|
|
339
|
-
*/
|
|
340
|
-
type StylePropShorthand = StylePropRef;
|
|
341
|
-
/**
|
|
342
|
-
* Every allowed shape for a single entry in a `props` block. Each
|
|
343
|
-
* shape comes from a marker helper (`styleProp`, `slot`, `bool`,
|
|
344
|
-
* `string`, `enums`, `composite`) and carries an introspectable
|
|
345
|
-
* `__kind` discriminator. `TLayers` parameterizes the layer-bound
|
|
346
|
-
* markers (`slot('layer/prop')`, `styleProp('bg').on('layer')`) so
|
|
347
|
-
* typos in layer names surface at the authoring site.
|
|
348
|
-
*/
|
|
349
|
-
type VerbosePropBinding<TLayers extends Record<string, LayerInput> = Record<string, LayerInput>> = StylePropMarker<keyof TLayers & string, string> | StylePropBinding | SingleLayerCompositeBinding | CompositeBinding | CompositeMarker | BoolMarker | StringMarker | EnumMarker<any> | SlotMarker<(keyof TLayers & string) | '', string>;
|
|
350
|
-
/**
|
|
351
|
-
* All allowed shapes for a single entry in the primitive form's `props`
|
|
352
|
-
* block. Primitive form adds the `StylePropShorthand` brace-ref
|
|
353
|
-
* (`'{bg}'`) on top of every verbose form — the root layer is
|
|
354
|
-
* unambiguous so the shorthand resolves trivially.
|
|
355
|
-
*/
|
|
356
|
-
type PrimitivePropBinding<TLayers extends Record<string, LayerInput> = Record<string, LayerInput>> = StylePropShorthand | VerbosePropBinding<TLayers>;
|
|
357
|
-
/**
|
|
358
|
-
* Union of every legal prop-binding shape across both forms. Read-side
|
|
359
|
-
* helpers (`Props<TConfig>`, runtime resolution) accept this widest
|
|
360
|
-
* union; authoring-side input types (`ComponentConfigInput`) take the
|
|
361
|
-
* tighter `VerbosePropBinding`.
|
|
362
|
-
*/
|
|
363
|
-
type PropBinding<TLayers extends Record<string, LayerInput> = Record<string, LayerInput>> = PrimitivePropBinding<TLayers>;
|
|
364
|
-
/**
|
|
365
|
-
* Marker for a boolean JSX prop. Use inside the `props` block:
|
|
366
|
-
*
|
|
367
|
-
* props: {
|
|
368
|
-
* loading: bool(),
|
|
369
|
-
* disabled: bool(),
|
|
370
|
-
* }
|
|
371
|
-
*
|
|
372
|
-
* Drives both the TS type (consumer sees `loading?: boolean`) and the
|
|
373
|
-
* Studio design panel control (toggle).
|
|
374
|
-
*/
|
|
375
|
-
declare function bool(): BoolMarker;
|
|
376
|
-
/**
|
|
377
|
-
* Marker for a string-valued JSX prop. Parallel to `bool()` — emits
|
|
378
|
-
* `data-<kebab-name>="<value>"` on each layer's bundle so CSS can
|
|
379
|
-
* target the rendered value. Use inside the `props` block:
|
|
380
|
-
*
|
|
381
|
-
* props: {
|
|
382
|
-
* kind: string(),
|
|
383
|
-
* tone: string(),
|
|
384
|
-
* }
|
|
385
|
-
*
|
|
386
|
-
* Drives both the TS type (consumer sees `kind?: string`) and the
|
|
387
|
-
* Studio design panel control (text input).
|
|
388
|
-
*/
|
|
389
|
-
declare function string(): StringMarker;
|
|
390
|
-
/**
|
|
391
|
-
* Bind a registered style prop. Single string arg defaults to the
|
|
392
|
-
* root layer; chain `.on(layerName)` to target a non-root layer:
|
|
393
|
-
*
|
|
394
|
-
* props: {
|
|
395
|
-
* bg: styleProp('bg'), // root layer
|
|
396
|
-
* textColor: styleProp('color').on('label'), // label layer
|
|
397
|
-
* }
|
|
398
|
-
*
|
|
399
|
-
* The `__kind: 'styleProp'` discriminator lets the design panel render
|
|
400
|
-
* a color/token picker (driven by the registered style prop's value
|
|
401
|
-
* space) and lets codegen scan props uniformly off the marker shape.
|
|
402
|
-
*/
|
|
403
|
-
declare function styleProp<TRef extends string>(ref: TRef): StylePropMarker<'root', TRef>;
|
|
404
|
-
/**
|
|
405
|
-
* Token-reference marker for style values. Use inside `base`, enum
|
|
406
|
-
* entries, and `compoundProps` overrides:
|
|
407
|
-
*
|
|
408
|
-
* base: { root: { bg: token('bg/brand') } }
|
|
409
|
-
* props: {
|
|
410
|
-
* variant: enums({
|
|
411
|
-
* brand: { root: { color: token('color/on-brand') } },
|
|
412
|
-
* }),
|
|
413
|
-
* }
|
|
414
|
-
*
|
|
415
|
-
* Codegen and runtime detect the `__kind: 'token'` discriminator and
|
|
416
|
-
* resolve the `ref` to `var(--<prefix>-<ns>-<name>)`. The design
|
|
417
|
-
* panel uses the same discriminator to offer a token picker.
|
|
418
|
-
*/
|
|
419
|
-
declare function token<TRef extends string>(ref: TRef): TokenMarker<TRef>;
|
|
420
|
-
/**
|
|
421
|
-
* Token-group reference for `defineStyleProp({ values: [...] })`. Pulls
|
|
422
|
-
* every token in the named namespace into the style prop's accepted
|
|
423
|
-
* value set. The resolver expands the group at registration time:
|
|
424
|
-
*
|
|
425
|
-
* defineStyleProp({
|
|
426
|
-
* cssProperty: 'padding',
|
|
427
|
-
* classPrefix: 'p',
|
|
428
|
-
* values: [tokenGroup('spacing')], // → p-1, p-2, p-3, …
|
|
429
|
-
* })
|
|
430
|
-
*
|
|
431
|
-
* The `__kind: 'tokenGroup'` discriminator lets codegen and the design
|
|
432
|
-
* panel branch on group references without parsing strings.
|
|
433
|
-
*/
|
|
434
|
-
declare function tokenGroup<TGroup extends string>(group: TGroup): TokenGroupMarker<TGroup>;
|
|
435
|
-
/**
|
|
436
|
-
* Marker for an enum-valued JSX prop. Each value maps to a per-layer
|
|
437
|
-
* style override. Use inside the `props` block:
|
|
438
|
-
*
|
|
439
|
-
* props: {
|
|
440
|
-
* variant: enums({
|
|
441
|
-
* brand: { root: { bg: '{bg/brand}', color: '{color/on-brand}' } },
|
|
442
|
-
* ghost: { root: { color: '{color/on-primary}' } },
|
|
443
|
-
* }),
|
|
444
|
-
* }
|
|
445
|
-
*
|
|
446
|
-
* The shape of each value mirrors a partial layer-style map keyed by
|
|
447
|
-
* the component's own layer names.
|
|
448
|
-
*/
|
|
449
|
-
declare function enums<const TValues extends Record<string, unknown>>(values: TValues): EnumMarker<TValues>;
|
|
450
|
-
/**
|
|
451
|
-
* Marker for a composite-style JSX prop. The JSX value picks one
|
|
452
|
-
* entry from the referenced composite group's `styles` map; the
|
|
453
|
-
* runtime expands the matched style bag onto the root layer's bundle
|
|
454
|
-
* and emits a marker class.
|
|
455
|
-
*
|
|
456
|
-
* // packages/.../text-variant.ts
|
|
457
|
-
* export const textVariant = defineCompositeStyle({
|
|
458
|
-
* label: 'Text Variant',
|
|
459
|
-
* styles: {
|
|
460
|
-
* body: { fontSize: '[1rem]', fontWeight: 'normal' },
|
|
461
|
-
* heading: { fontSize: '[1.5rem]', fontWeight: 'bold' },
|
|
462
|
-
* },
|
|
463
|
-
* });
|
|
464
|
-
*
|
|
465
|
-
* // apps/<consumer>/uds.config.ts
|
|
466
|
-
* udsBuilder.registerComposites({ textVariant });
|
|
467
|
-
*
|
|
468
|
-
* // The component:
|
|
469
|
-
* export const Text = defineComponent(Box, {
|
|
470
|
-
* defaultProps: { as: 'p' },
|
|
471
|
-
* props: {
|
|
472
|
-
* variant: composite('textVariant'),
|
|
473
|
-
* },
|
|
474
|
-
* });
|
|
475
|
-
*
|
|
476
|
-
* Argument is the bare composite name (no `{...}` brace wrapping) —
|
|
477
|
-
* the `composite()` function's position already establishes the
|
|
478
|
-
* composite-ref context, so the braces would be redundant. Authoring
|
|
479
|
-
* sites type-narrow `ref` against `keyof RegisteredComposites` so
|
|
480
|
-
* typos surface as compile errors.
|
|
481
|
-
*
|
|
482
|
-
* Layer target is implicit `'root'`. For multi-layer composite
|
|
483
|
-
* bindings or non-root layer targets, drop down to the verbose
|
|
484
|
-
* `{ layer: 'X', composite: '{ref}' }` /
|
|
485
|
-
* `{ composite: '{ref}', layers: {...} }` shapes (those keep the
|
|
486
|
-
* brace-ref form for consistency with style-prop refs).
|
|
487
|
-
*/
|
|
488
|
-
type CompositeName = [keyof RegisteredComposites] extends [never] ? string : keyof RegisteredComposites & string;
|
|
489
|
-
declare function composite<TRef extends CompositeName>(ref: TRef): CompositeMarker<TRef>;
|
|
490
|
-
/**
|
|
491
|
-
* Splits a `'layer/prop'` slot path into its two segments. Mirrors the
|
|
492
|
-
* `{namespace/name}` token-ref convention — the slash is the delimiter
|
|
493
|
-
* and the second segment is the target prop on the layer's bundle.
|
|
494
|
-
* When no slash is present, the path is a bare layer name and the
|
|
495
|
-
* target prop defaults to `'children'`.
|
|
496
|
-
*/
|
|
497
|
-
type SplitSlotPath<T extends string> = T extends `${infer L}/${infer A}` ? [L, A] : [T, 'children'];
|
|
498
|
-
/**
|
|
499
|
-
* Marker for a layer-targeted JSX-prop binding. Routes the incoming
|
|
500
|
-
* JSX value into `bundles[layer][prop]` at render time. The prop's
|
|
501
|
-
* TS value type is inferred from the target layer's surface — see
|
|
502
|
-
* `SlotPropValue` in `Props.ts`.
|
|
503
|
-
*
|
|
504
|
-
* Authoring forms:
|
|
505
|
-
*
|
|
506
|
-
* - **Canonical: `slot('layer/prop')`** — slash-separated path. The
|
|
507
|
-
* first segment names a declared layer; the second names the prop
|
|
508
|
-
* on that layer's bundle where the JSX value lands.
|
|
509
|
-
*
|
|
510
|
-
* props: {
|
|
511
|
-
* title: slot('triggerText/children'), // → Text.children
|
|
512
|
-
* onClick: slot('button/onClick'), // → button's onClick
|
|
513
|
-
* headline: slot('root/startContent'), // → Card.startContent
|
|
514
|
-
* }
|
|
515
|
-
*
|
|
516
|
-
* - **Sugar: `slot('layer')`** — equivalent to `slot('layer/children')`.
|
|
517
|
-
*
|
|
518
|
-
* - **Object form: `slot('layer', { prop: 'name' })`** — same as
|
|
519
|
-
* `slot('layer/name')` but reads better when `name` is a long
|
|
520
|
-
* identifier or contains characters the slash form can't carry.
|
|
521
|
-
*
|
|
522
|
-
* - **No-arg: `slot()`** — type-only declaration. The JSX value is
|
|
523
|
-
* typed as `ReactNode` and flows through to the render fn's args
|
|
524
|
-
* verbatim (no layer routing). Use for `children: slot()` to
|
|
525
|
-
* declare children without routing them to a specific layer.
|
|
526
|
-
*
|
|
527
|
-
* The marker is the canonical signal — to codegen and to json-render
|
|
528
|
-
* — that this JSX prop is a named slot.
|
|
529
|
-
*/
|
|
530
|
-
declare function slot(): SlotMarker<'', 'children'>;
|
|
531
|
-
declare function slot<const TPath extends string>(path: TPath): SlotMarker<SplitSlotPath<TPath>[0], SplitSlotPath<TPath>[1]>;
|
|
532
|
-
declare function slot<const TLayer extends string, const TProp extends string>(layer: TLayer, options: {
|
|
533
|
-
prop: TProp;
|
|
534
|
-
}): SlotMarker<TLayer, TProp>;
|
|
535
|
-
/**
|
|
536
|
-
* Per-layer override shape, narrowed by the layer's declared form.
|
|
537
|
-
*
|
|
538
|
-
* Same shape as a single enum-value's per-layer style map — registered
|
|
539
|
-
* style props, CSS properties, and `_hover`/`_focus`/etc. modifier
|
|
540
|
-
* keys. Uniform across all layer forms (HTML tag, PrimitiveLayer, and
|
|
541
|
-
* ComposedLayer) because `ComposedLayer.defaultProps` is also
|
|
542
|
-
* `Record<string, unknown>` and narrowing here would over-constrain
|
|
543
|
-
* authoring relative to the layer's own surface.
|
|
544
|
-
*
|
|
545
|
-
* Authors use `hidden()` (a sibling marker) to hide a layer entirely;
|
|
546
|
-
* style-map values never carry the `hidden` flag inline.
|
|
547
|
-
*/
|
|
548
|
-
type LayerOverride = ComponentSlotStyles;
|
|
549
|
-
/**
|
|
550
|
-
* Marker that hides an entire layer when the parent `compoundProps`
|
|
551
|
-
* entry matches. Separated from the style-map shape so authors don't
|
|
552
|
-
* mix structural visibility with style overrides inline.
|
|
553
|
-
*
|
|
554
|
-
* V1 `applyCompoundProps` translates a hidden layer to `display: none`
|
|
555
|
-
* on the resolved bundle — the DOM node still renders; see UDS-1631's
|
|
556
|
-
* open questions for the "strip entirely" follow-up.
|
|
557
|
-
*/
|
|
558
|
-
interface HiddenMarker {
|
|
559
|
-
readonly __kind: 'hidden';
|
|
560
|
-
}
|
|
561
|
-
/**
|
|
562
|
-
* Marker factory — use inside `compoundProps[].layers.<layer>` to hide
|
|
563
|
-
* a layer entirely when the entry's `when` clause matches.
|
|
564
|
-
*
|
|
565
|
-
* compoundProps: [
|
|
566
|
-
* {
|
|
567
|
-
* when: { variant: 'compact' },
|
|
568
|
-
* layers: { endIcon: hidden() },
|
|
569
|
-
* },
|
|
570
|
-
* ]
|
|
571
|
-
*/
|
|
572
|
-
declare function hidden(): HiddenMarker;
|
|
573
|
-
/**
|
|
574
|
-
* Names of prop bindings that participate in `when` clauses — i.e.
|
|
575
|
-
* props authored as `enums({...})` or `bool()`. Other bindings (style
|
|
576
|
-
* props, forwards, composites) don't have a fixed enumerable value set
|
|
577
|
-
* and so aren't valid `when` keys. File-private — re-inlined here
|
|
578
|
-
* after the original `IterableAxisOf` was removed from the public
|
|
579
|
-
* surface along with the matrix-examples API.
|
|
580
|
-
*/
|
|
581
|
-
type IterableAxisOf<TProps> = { [K in keyof TProps]: TProps[K] extends EnumMarker<Record<string, unknown>> | BoolMarker ? K : never }[keyof TProps] & string;
|
|
582
|
-
/**
|
|
583
|
-
* Resolve the legal value set for an iteration axis. `enums({...})` →
|
|
584
|
-
* the union of value keys; `bool()` → `boolean`. Used to narrow per-
|
|
585
|
-
* coord values in `compoundProps.when`. File-private (see `IterableAxisOf`).
|
|
586
|
-
*/
|
|
587
|
-
type PropValuesOf<TBinding> = TBinding extends EnumMarker<infer TValues> ? keyof TValues & string : TBinding extends BoolMarker ? boolean : never;
|
|
588
|
-
/**
|
|
589
|
-
* A `compoundProps` `when` clause: partial map of iterable-axis prop
|
|
590
|
-
* names → required value. All listed keys must match the active props
|
|
591
|
-
* for the entry to apply. Keys narrow to enum/bool bindings only — so
|
|
592
|
-
* non-enum/non-bool props (style props, forwards, composites) are a
|
|
593
|
-
* type error at the authoring site. Values narrow to declared enum
|
|
594
|
-
* keys or `boolean`.
|
|
595
|
-
*/
|
|
596
|
-
type WhenClause<TProps> = { [K in IterableAxisOf<TProps>]?: K extends keyof TProps ? PropValuesOf<TProps[K]> : never };
|
|
597
|
-
/**
|
|
598
|
-
* A single `compoundProps` entry — applies per-layer overrides when
|
|
599
|
-
* *all* `when` keys match the active prop values.
|
|
600
|
-
*
|
|
601
|
-
* compoundProps: [
|
|
602
|
-
* {
|
|
603
|
-
* when: { variant: 'secondary', textVariant: 'legal1' },
|
|
604
|
-
* layers: {
|
|
605
|
-
* root: { color: '{color/tertiary}' },
|
|
606
|
-
* endIcon: hidden(),
|
|
607
|
-
* },
|
|
608
|
-
* },
|
|
609
|
-
* ]
|
|
610
|
-
*
|
|
611
|
-
* Multiple entries can match a given combination — specificity (number
|
|
612
|
-
* of keys in `when`) decides who wins per layer-property pair; ties
|
|
613
|
-
* break by source order (later wins).
|
|
614
|
-
*/
|
|
615
|
-
interface CompoundPropsEntry<TLayers extends Record<string, LayerInput>, TProps extends Record<string, unknown> = Record<string, unknown>> {
|
|
616
|
-
when: WhenClause<TProps>;
|
|
617
|
-
/**
|
|
618
|
-
* Per-layer overrides. Style maps narrow against `ComponentSlotStyles`
|
|
619
|
-
* (registered style props + CSS properties + modifier keys); use
|
|
620
|
-
* `hidden()` to hide a layer entirely. Layer keys narrow to the
|
|
621
|
-
* component's declared layer names.
|
|
622
|
-
*/
|
|
623
|
-
layers: { [K in keyof TLayers & string]?: LayerOverride | HiddenMarker };
|
|
624
|
-
}
|
|
625
|
-
/**
|
|
626
|
-
* The architecture-doc-target component config. Distinct from today's
|
|
627
|
-
* `SingleComponentDef` (`base` + `variants` shape) — this is the
|
|
628
|
-
* pure-data, layers-first shape the new `defineComponent` accepts.
|
|
629
|
-
*
|
|
630
|
-
* `TLayers` is inferred from the `layers` block so prop bindings can
|
|
631
|
-
* narrow their `layer` field against the component's actual layer
|
|
632
|
-
* names; typos surface at the authoring site.
|
|
633
|
-
*/
|
|
634
|
-
/**
|
|
635
|
-
* Static, always-on per-layer styles + props for verbose-form
|
|
636
|
-
* `defineComponent({...})`. Keyed by layer name — each value is
|
|
637
|
-
* `Partial<Props<TLayer>>` where `TLayer` is the layer's resolved
|
|
638
|
-
* component (Box / Pressable / Text / …). Mirrors the legacy
|
|
639
|
-
* `defineComponents({ <Name>: { base: { <slot>: {...} } } })`
|
|
640
|
-
* shape — `base` styles are unconditional, contrasted with the
|
|
641
|
-
* `props` block where `enums()` / `composite()` / style-prop
|
|
642
|
-
* bindings associate styles with consumer-controllable values.
|
|
643
|
-
*
|
|
644
|
-
* defineComponent({
|
|
645
|
-
* layers: { trigger: { component: Pressable } },
|
|
646
|
-
* base: {
|
|
647
|
-
* trigger: { padding: '4' }, // ✗ ERROR — Pressable exposes `spacing`, not `padding`
|
|
648
|
-
* trigger: { spacing: '4' }, // ✓
|
|
649
|
-
* },
|
|
650
|
-
* });
|
|
651
|
-
*
|
|
652
|
-
* Composed-component layers narrow to the wrapped component's prop
|
|
653
|
-
* surface via `Props<TLayer['__config']>` — catches style-prop typos
|
|
654
|
-
* at the authoring site. Bare-tag layers (`'div'`) fall back to
|
|
655
|
-
* `Record<string, unknown>` since they don't have a component-side
|
|
656
|
-
* prop registry; those layers' styles go through `prepareCss` as
|
|
657
|
-
* `@utility` CSS rules instead.
|
|
658
|
-
*
|
|
659
|
-
* `base[<layer>].as` on a composed layer overrides the layer's
|
|
660
|
-
* rendered tag (mirroring the existing primitive-form behavior).
|
|
661
|
-
*/
|
|
662
|
-
/**
|
|
663
|
-
* Resolves the accepted JSX-value shape for a single prop binding —
|
|
664
|
-
* what `defaultProps` for that binding should be typed as.
|
|
665
|
-
*
|
|
666
|
-
* - `EnumMarker` → the union of declared value keys.
|
|
667
|
-
* - `BoolMarker` → `boolean`.
|
|
668
|
-
* - `CompositeMarker` → registered composite-value keys (loosely
|
|
669
|
-
* typed `string` here; consumer apps' augmentation refines it).
|
|
670
|
-
* - `SlotMarker` → `ReactNode` (slot-position values).
|
|
671
|
-
* - `BoolMarker` etc. follow.
|
|
672
|
-
* - Style-prop bindings (`'{bg}'` shorthand or
|
|
673
|
-
* `{ layer, styleProp: '{bg}' }`) → string (the resolved token
|
|
674
|
-
* or alias name; precise narrowing happens at the consumer's
|
|
675
|
-
* augmented-types boundary).
|
|
676
|
-
* - Everything else → `unknown`.
|
|
677
|
-
*/
|
|
678
|
-
type BindingValueType<T> = T extends EnumMarker<infer V> ? keyof V & string : T extends BoolMarker ? boolean : T extends StringMarker ? string : T extends StylePropMarker ? string : T extends CompositeMarker ? string : T extends SlotMarker ? _$react.ReactNode : T extends string ? string : T extends {
|
|
679
|
-
readonly styleProp: string;
|
|
680
|
-
} ? string : unknown;
|
|
681
|
-
/**
|
|
682
|
-
* `defaultProps` for verbose-form `defineComponent({...})` —
|
|
683
|
-
* type-narrowed against the keys + binding values declared in the
|
|
684
|
-
* `props` block. Catches typos / wrong-value assignments at the
|
|
685
|
-
* authoring site:
|
|
686
|
-
*
|
|
687
|
-
* props: {
|
|
688
|
-
* variant: enums({ brand: {...}, ghost: {...} }),
|
|
689
|
-
* loading: bool(),
|
|
690
|
-
* },
|
|
691
|
-
* defaultProps: {
|
|
692
|
-
* variant: 'brand', // ✓
|
|
693
|
-
* variant: 'extra', // ✗ — not a declared enum value
|
|
694
|
-
* loading: false, // ✓
|
|
695
|
-
* typo: 'foo', // ✗ — not a declared prop key
|
|
696
|
-
* }
|
|
697
|
-
*/
|
|
698
|
-
type BindingValueDefaults<TProps> = { [K in keyof TProps]?: BindingValueType<TProps[K]> };
|
|
699
|
-
type LayerBaseStyles<TLayers extends Record<string, LayerInput>> = { [K in keyof TLayers]?: TLayers[K] extends {
|
|
700
|
-
readonly __config: infer TLayerConfig;
|
|
701
|
-
} ? TLayerConfig extends ComponentConfigValue<Record<string, LayerInput>, any, HtmlTag | undefined> ? Partial<Props<TLayerConfig>> : Record<string, unknown> : Record<string, unknown> };
|
|
702
|
-
/**
|
|
703
|
-
* Per-layer motion descriptors for verbose-form
|
|
704
|
-
* `defineComponent({...})`. Keyed by layer name; each value is a
|
|
705
|
-
* {@link SlotMotion} (framer-motion `initial`/`animate`/`exit`/
|
|
706
|
-
* `transition`/etc. shape). Codegen surfaces these into the manifest
|
|
707
|
-
* under `components.<Name>.motion.<slot>` and uses them to rewrite
|
|
708
|
-
* the slot's JSX into a motion-wrapped element at build time —
|
|
709
|
-
* `<Box {...props.icon}>` becomes `<motion.create(Box) ...>` and
|
|
710
|
-
* conditional renders are wrapped in `<AnimatePresence>` when
|
|
711
|
-
* `exit` is set.
|
|
712
|
-
*/
|
|
713
|
-
type LayerMotion<TLayers extends Record<string, LayerInput>> = { [K in keyof TLayers]?: SlotMotion };
|
|
714
|
-
interface ComponentConfigInput<TLayers extends Record<string, LayerInput>, TProps extends Record<string, VerbosePropBinding<TLayers>> = Record<string, VerbosePropBinding<TLayers>>> {
|
|
715
|
-
layers: TLayers;
|
|
716
|
-
props?: TProps;
|
|
717
|
-
/**
|
|
718
|
-
* Static per-layer styles + props applied unconditionally to every
|
|
719
|
-
* render. Each key is a layer name from `layers`; each value is
|
|
720
|
-
* `Partial<Props<that-layer's-component>>`. See {@link LayerBaseStyles}.
|
|
721
|
-
*
|
|
722
|
-
* base: {
|
|
723
|
-
* root: { borderWidth: 'thin', bg: 'primary' },
|
|
724
|
-
* trigger: { spacing: '4', _hover: { bg: 'tertiary' } },
|
|
725
|
-
* }
|
|
726
|
-
*
|
|
727
|
-
* Variant-controlled styles (per consumer JSX value) go through
|
|
728
|
-
* `enums()` / `composite()` / style-prop bindings in the `props`
|
|
729
|
-
* block. `base` is the always-on foundation; `props` adds
|
|
730
|
-
* value-driven overrides on top.
|
|
731
|
-
*
|
|
732
|
-
* Type-checked per layer — typos on composed layers surface as TS
|
|
733
|
-
* errors at the authoring site.
|
|
734
|
-
*/
|
|
735
|
-
base?: LayerBaseStyles<TLayers>;
|
|
736
|
-
/**
|
|
737
|
-
* Default values for the consumer-controllable JSX props declared
|
|
738
|
-
* in the `props` block. Keys narrow against `keyof TProps`; values
|
|
739
|
-
* narrow against each binding's accepted shape (enum keys for
|
|
740
|
-
* `enums()`, composite values for `composite()`, registered tokens
|
|
741
|
-
* for style-prop bindings, `boolean` for `bool()`).
|
|
742
|
-
*
|
|
743
|
-
* props: {
|
|
744
|
-
* variant: enums({ brand: {...}, ghost: {...} }),
|
|
745
|
-
* loading: bool(),
|
|
746
|
-
* },
|
|
747
|
-
* defaultProps: {
|
|
748
|
-
* variant: 'brand', // narrows to `keyof enum.values`
|
|
749
|
-
* loading: false,
|
|
750
|
-
* typo: '...', // ✗ ERROR — not a declared prop
|
|
751
|
-
* }
|
|
752
|
-
*/
|
|
753
|
-
defaultProps?: BindingValueDefaults<TProps>;
|
|
754
|
-
/**
|
|
755
|
-
* Per-layer motion descriptors. Keyed by layer name; each value is
|
|
756
|
-
* a {@link SlotMotion} (framer-motion shape). See {@link LayerMotion}.
|
|
757
|
-
*
|
|
758
|
-
* motion: {
|
|
759
|
-
* icon: {
|
|
760
|
-
* animate: { 'data-state': { open: { rotate: 180 }, closed: { rotate: 0 } } },
|
|
761
|
-
* transition: { duration: 0.2 },
|
|
762
|
-
* },
|
|
763
|
-
* content: {
|
|
764
|
-
* initial: { height: 0, opacity: 0 },
|
|
765
|
-
* animate: { height: 'auto', opacity: 1 },
|
|
766
|
-
* exit: { height: 0, opacity: 0 },
|
|
767
|
-
* },
|
|
768
|
-
* }
|
|
769
|
-
*/
|
|
770
|
-
motion?: LayerMotion<TLayers>;
|
|
771
|
-
/**
|
|
772
|
-
* Per-combination layer overrides keyed on enum/bool prop values.
|
|
773
|
-
* See {@link CompoundPropsEntry}.
|
|
774
|
-
*/
|
|
775
|
-
compoundProps?: CompoundPropsEntry<TLayers, TProps>[];
|
|
776
|
-
}
|
|
777
|
-
/**
|
|
778
|
-
* Branded shape returned by `defineComponent({...})`. Carries `layers`,
|
|
779
|
-
* `props`, AND a phantom `__tag` slot as const-narrowed types so
|
|
780
|
-
* downstream type-only imports (`import type { AlertConfig } from
|
|
781
|
-
* './alert.config'`) thread the full shape through to
|
|
782
|
-
* `Props<typeof config>` — per-prop literal binding values (e.g.
|
|
783
|
-
* `'{bg}'`) survive for `Props<TConfig>` to resolve against
|
|
784
|
-
* `RegisteredStyleProps`, and the root tag survives for HTML-attribute
|
|
785
|
-
* narrowing via `React.ComponentPropsWithoutRef<TTag>`.
|
|
786
|
-
*
|
|
787
|
-
* `__tag` is a *phantom* type slot — there is no runtime field. It's
|
|
788
|
-
* derived from either the primitive-form first arg (`defineComponent('a',
|
|
789
|
-
* …)`) or from `layers.root` via `RootTag<TLayers>` for the verbose form.
|
|
790
|
-
* When the root isn't a literal tag (brace-ref / composed layer), it's
|
|
791
|
-
* `undefined` and `Props<TConfig>` falls back to `HTMLAttributes<HTMLElement>`.
|
|
792
|
-
*
|
|
793
|
-
* `__componentName` is a non-enumerable runtime slot assigned by
|
|
794
|
-
* `.registerComponents({ Name: config })` — the key becomes the name.
|
|
795
|
-
* The renderer reads it to emit `componentName-layerName` @utility
|
|
796
|
-
* classes onto each layer's bundle (matching the classes codegen emits
|
|
797
|
-
* from the same `defaultProps`). Absent until registered.
|
|
798
|
-
*/
|
|
799
|
-
interface ComponentConfigValue<TLayers extends Record<string, LayerInput>, TProps extends Record<string, PropBinding> = Record<string, PropBinding>, TTag extends HtmlTag | undefined = RootTag<TLayers>> {
|
|
800
|
-
readonly __kind: 'componentConfig';
|
|
801
|
-
readonly __tag?: TTag;
|
|
802
|
-
readonly __componentName?: string;
|
|
803
|
-
readonly layers: TLayers;
|
|
804
|
-
readonly props?: TProps;
|
|
805
|
-
/**
|
|
806
|
-
* Static per-layer styles, keyed by layer name. Codegen's
|
|
807
|
-
* downleveler spreads each entry into the layer's runtime bundle.
|
|
808
|
-
* Distinct from `defaultProps`, which carries declared-prop
|
|
809
|
-
* defaults.
|
|
810
|
-
*/
|
|
811
|
-
readonly base?: Record<string, Record<string, unknown>>;
|
|
812
|
-
/**
|
|
813
|
-
* Per-layer motion descriptors keyed by layer name. Same shape as
|
|
814
|
-
* `LayerMotion<TLayers>` (loosened here so the read-side type
|
|
815
|
-
* doesn't require parameterizing against TLayers' Props).
|
|
816
|
-
*/
|
|
817
|
-
readonly motion?: Record<string, SlotMotion>;
|
|
818
|
-
readonly defaultProps?: Record<string, unknown>;
|
|
819
|
-
/**
|
|
820
|
-
* Per-combination layer overrides — see {@link CompoundPropsEntry}.
|
|
821
|
-
* Carried through from `ComponentConfigInput.compoundProps`.
|
|
822
|
-
*/
|
|
823
|
-
readonly compoundProps?: CompoundPropsEntry<TLayers, TProps>[];
|
|
824
|
-
/**
|
|
825
|
-
* Authoring metadata (description, events) attached via the bound
|
|
826
|
-
* component's `.metadata({...})` chain. Stored non-enumerably on
|
|
827
|
-
* the config object so `JSON.stringify` output stays clean. Read by
|
|
828
|
-
* codegen's prompt + catalog generators.
|
|
829
|
-
*
|
|
830
|
-
* `acceptsChildren` isn't stored here — codegen derives it from
|
|
831
|
-
* `layers` + `props` shape so authors don't have to declare what's
|
|
832
|
-
* already obvious from the config (primitive + value-extend forms
|
|
833
|
-
* accept children unconditionally; verbose form derives from
|
|
834
|
-
* `ForwardBinding { from: 'children' }`).
|
|
835
|
-
*/
|
|
836
|
-
readonly metadata?: {
|
|
837
|
-
readonly description?: string;
|
|
838
|
-
readonly events?: readonly string[];
|
|
839
|
-
};
|
|
840
|
-
}
|
|
841
|
-
/**
|
|
842
|
-
* The bundle passed to the render function for each layer — a ready-to-
|
|
843
|
-
* spread object with `className` and any forwarded attrs. The render
|
|
844
|
-
* function destructures `props.<layerName>` into the JSX position.
|
|
845
|
-
*/
|
|
846
|
-
interface LayerBundle {
|
|
847
|
-
/** Resolved CSS class names for this layer. Omitted when empty so the
|
|
848
|
-
* rendered HTML doesn't carry a literal `class=""` attribute. */
|
|
849
|
-
className?: string;
|
|
850
|
-
[key: string]: unknown;
|
|
851
|
-
}
|
|
852
|
-
/**
|
|
853
|
-
* Derive the render-function argument shape from a component config
|
|
854
|
-
* type. The render fn receives `props: { <each layer>: LayerBundle }`
|
|
855
|
-
* plus `children` (always present at the React level).
|
|
856
|
-
*/
|
|
857
|
-
type RenderArgs<TConfig extends ComponentConfigValue<Record<string, LayerInput>>> = {
|
|
858
|
-
props: { [K in keyof TConfig['layers']]: LayerBundle };
|
|
859
|
-
children?: ReactNode;
|
|
860
|
-
} & Record<string, unknown>; //#endregion
|
|
861
|
-
//#endregion
|
|
862
|
-
export { BoolMarker, ComponentConfigInput, ComponentConfigValue, ComponentMotionValue, ComponentSlotStyles, CompositeBinding, CompositeMarker, CompoundPropsEntry, EnumMarker, HiddenMarker, HtmlTag, LayerBundle, LayerInput, LayerOverride, PrimitiveLayer, PrimitivePropBinding, PropBinding, RenderArgs, RootTag, SingleLayerCompositeBinding, SlotMarker, SlotMotion, SplitSlotPath, StringMarker, StylePropBinding, StylePropMarker, StylePropShorthand, TokenGroupMarker, TokenMarker, VerbosePropBinding, WhenClause, bool, composite, enums, hidden, slot, string, styleProp, token, tokenGroup };
|