@yahoo/uds-create-config 2.45.0 → 3.0.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/README.md +129 -0
- package/dist/ai-lanes.d.ts +23 -0
- package/dist/ai-lanes.js +34 -0
- package/dist/authoring/define-component.d.ts +85 -0
- package/dist/configs/CanvasConfig.d.ts +3237 -0
- package/dist/configs/CanvasConfig.js +332 -0
- package/dist/configs/build-options.d.ts +10 -0
- package/dist/configs/build-options.js +68 -0
- package/dist/configs/platform.d.ts +15 -0
- package/dist/configs/platform.js +17 -0
- package/dist/configs/react-native-system.d.ts +3026 -0
- package/dist/configs/react-native-system.js +64 -0
- package/dist/configs/system.d.ts +2771 -0
- package/dist/configs/system.js +74 -0
- package/dist/css/properties.generated.d.ts +14 -0
- package/dist/css/properties.generated.js +6260 -0
- package/dist/css/value-type.d.ts +48 -0
- package/dist/css/value-type.js +131 -0
- package/dist/css/values.d.ts +33 -0
- package/dist/css/values.js +116 -0
- package/dist/entities/native/NativeModifier.d.ts +25 -0
- package/dist/entities/native/NativeModifier.js +41 -0
- package/dist/entities/native/NativeSettings.d.ts +44 -0
- package/dist/entities/native/NativeSettings.js +39 -0
- package/dist/entities/native/NativeStyleProperty.d.ts +355 -0
- package/dist/entities/native/NativeStyleProperty.js +28 -0
- package/dist/entities/native/NativeToken.d.ts +31 -0
- package/dist/entities/native/NativeToken.js +49 -0
- package/dist/entities/system/CanvasRole.d.ts +34 -0
- package/dist/entities/system/CanvasRole.js +45 -0
- package/dist/entities/system/Component.d.ts +1287 -0
- package/dist/entities/system/Component.js +1840 -0
- package/dist/entities/system/Composite.d.ts +12 -0
- package/dist/entities/system/Composite.js +26 -0
- package/dist/entities/system/Device.d.ts +11 -0
- package/dist/entities/system/Device.js +18 -0
- package/dist/entities/system/File.d.ts +72 -0
- package/dist/entities/system/File.js +136 -0
- package/dist/entities/system/Font.d.ts +48 -0
- package/dist/entities/system/Font.js +56 -0
- package/dist/entities/system/GlobalStyle.d.ts +26 -0
- package/dist/entities/system/GlobalStyle.js +54 -0
- package/dist/entities/system/Guidance.d.ts +85 -0
- package/dist/entities/system/Guidance.js +59 -0
- package/dist/entities/system/GuidanceStyle.d.ts +14 -0
- package/dist/entities/system/GuidanceStyle.js +8 -0
- package/dist/entities/system/Icon.d.ts +46 -0
- package/dist/entities/system/Icon.js +46 -0
- package/dist/entities/system/LinkedSystem.d.ts +504 -0
- package/dist/entities/system/LinkedSystem.js +814 -0
- package/dist/entities/system/Modifier.d.ts +92 -0
- package/dist/entities/system/Modifier.js +120 -0
- package/dist/entities/system/Motion.d.ts +28 -0
- package/dist/entities/system/Motion.js +48 -0
- package/dist/entities/system/Operation.d.ts +100 -0
- package/dist/entities/system/Operation.js +236 -0
- package/dist/entities/system/Package.d.ts +42 -0
- package/dist/entities/system/Package.js +75 -0
- package/dist/entities/system/Settings.d.ts +94 -0
- package/dist/entities/system/Settings.js +166 -0
- package/dist/entities/system/StyleProperty.d.ts +135 -0
- package/dist/entities/system/StyleProperty.js +438 -0
- package/dist/entities/system/Token.d.ts +67 -0
- package/dist/entities/system/Token.js +129 -0
- package/dist/entities/system/Tool.d.ts +134 -0
- package/dist/entities/system/Tool.js +124 -0
- package/dist/entities/system/color.d.ts +64 -0
- package/dist/entities/system/color.js +123 -0
- package/dist/entities/system/component-module.d.ts +63 -0
- package/dist/entities/system/component-module.js +258 -0
- package/dist/entities/system/copy-plan.d.ts +98 -0
- package/dist/entities/system/copy-plan.js +451 -0
- package/dist/entities/system/defineComponent.d.ts +428 -0
- package/dist/entities/system/defineComponent.js +337 -0
- package/dist/entities/system/element.d.ts +101 -0
- package/dist/entities/system/element.js +171 -0
- package/dist/entities/system/icon-library.d.ts +64 -0
- package/dist/entities/system/icon-library.js +112 -0
- package/dist/entities/system/icon-metadata.d.ts +72 -0
- package/dist/entities/system/icon-metadata.js +111 -0
- package/dist/entities/system/link-declaration.d.ts +27 -0
- package/dist/entities/system/link-declaration.js +64 -0
- package/dist/entities/system/link-plan.d.ts +160 -0
- package/dist/entities/system/link-plan.js +770 -0
- package/dist/entities/system/runtime-modules.d.ts +25 -0
- package/dist/entities/system/runtime-modules.js +38 -0
- package/dist/entities/system/style-bag.d.ts +20 -0
- package/dist/entities/system/style-bag.js +246 -0
- package/dist/entities/system/token-index.d.ts +89 -0
- package/dist/entities/system/token-index.js +112 -0
- package/dist/framework/Config.d.ts +2472 -0
- package/dist/framework/Config.js +5023 -0
- package/dist/framework/Entity.d.ts +127 -0
- package/dist/framework/Entity.js +125 -0
- package/dist/framework/authoring.d.ts +24 -0
- package/dist/framework/authoring.js +7 -0
- package/dist/framework/change-hooks.d.ts +119 -0
- package/dist/framework/change-hooks.js +131 -0
- package/dist/framework/changes.d.ts +88 -0
- package/dist/framework/changes.js +246 -0
- package/dist/framework/class-names.d.ts +260 -0
- package/dist/framework/class-names.js +630 -0
- package/dist/framework/coalesce.d.ts +25 -0
- package/dist/framework/coalesce.js +60 -0
- package/dist/framework/config-op.d.ts +76 -0
- package/dist/framework/config-op.js +43 -0
- package/dist/framework/config-operation-kind.d.ts +14 -0
- package/dist/framework/config-operation-kind.js +14 -0
- package/dist/framework/config-ops.d.ts +34 -0
- package/dist/framework/config-ops.js +187 -0
- package/dist/framework/defineConfig.d.ts +196 -0
- package/dist/framework/defineConfig.js +100 -0
- package/dist/framework/defineDerivedEntity.d.ts +74 -0
- package/dist/framework/defineDerivedEntity.js +83 -0
- package/dist/framework/defineEntity.d.ts +318 -0
- package/dist/framework/defineEntity.js +183 -0
- package/dist/framework/defineSubEntity.d.ts +148 -0
- package/dist/framework/defineSubEntity.js +121 -0
- package/dist/framework/derived-mutations.d.ts +20 -0
- package/dist/framework/derived-mutations.js +38 -0
- package/dist/framework/entity-search.d.ts +29 -0
- package/dist/framework/entity-search.js +117 -0
- package/dist/framework/inline-sources.d.ts +49 -0
- package/dist/framework/inline-sources.js +388 -0
- package/dist/framework/layer-styles.d.ts +25 -0
- package/dist/framework/layer-styles.js +49 -0
- package/dist/framework/memo.d.ts +48 -0
- package/dist/framework/memo.js +84 -0
- package/dist/framework/overlay.d.ts +49 -0
- package/dist/framework/overlay.js +17 -0
- package/dist/framework/plan.d.ts +49 -0
- package/dist/framework/plan.js +73 -0
- package/dist/framework/projections.d.ts +480 -0
- package/dist/framework/projections.js +974 -0
- package/dist/framework/prop-surface.d.ts +132 -0
- package/dist/framework/prop-surface.js +278 -0
- package/dist/framework/ref-graph.d.ts +71 -0
- package/dist/framework/ref-graph.js +158 -0
- package/dist/framework/ref-integrity.d.ts +55 -0
- package/dist/framework/ref-integrity.js +171 -0
- package/dist/framework/registered.d.ts +95 -0
- package/dist/framework/registry-dir.d.ts +42 -0
- package/dist/framework/registry-dir.js +48 -0
- package/dist/framework/registry.d.ts +300 -0
- package/dist/framework/registry.js +104 -0
- package/dist/framework/rejection.d.ts +58 -0
- package/dist/framework/rejection.js +111 -0
- package/dist/framework/rename-inference.d.ts +26 -0
- package/dist/framework/rename-inference.js +50 -0
- package/dist/framework/render-spec.d.ts +296 -0
- package/dist/framework/render-spec.js +809 -0
- package/dist/framework/schema-version.d.ts +140 -0
- package/dist/framework/schema-version.js +214 -0
- package/dist/framework/schemas.d.ts +109 -0
- package/dist/framework/schemas.js +615 -0
- package/dist/framework/session.d.ts +196 -0
- package/dist/framework/session.js +367 -0
- package/dist/framework/signature.d.ts +15 -0
- package/dist/framework/signature.js +83 -0
- package/dist/framework/snapshot.d.ts +115 -0
- package/dist/framework/snapshot.js +277 -0
- package/dist/framework/source-integrity.d.ts +226 -0
- package/dist/framework/source-integrity.js +478 -0
- package/dist/framework/sources.d.ts +211 -0
- package/dist/framework/sources.js +89 -0
- package/dist/framework/utils/compiled-schema.d.ts +23 -0
- package/dist/framework/utils/compiled-schema.js +46 -0
- package/dist/framework/utils/content-key.d.ts +15 -0
- package/dist/framework/utils/content-key.js +33 -0
- package/dist/framework/utils/enumerated.d.ts +13 -0
- package/dist/framework/utils/enumerated.js +19 -0
- package/dist/framework/utils/field-path.d.ts +95 -0
- package/dist/framework/utils/field-path.js +136 -0
- package/dist/framework/utils/field-schema.d.ts +55 -0
- package/dist/framework/utils/field-schema.js +183 -0
- package/dist/framework/utils/group.d.ts +37 -0
- package/dist/framework/utils/group.js +13 -0
- package/dist/framework/utils/package-path.d.ts +37 -0
- package/dist/framework/utils/package-path.js +61 -0
- package/dist/framework/utils/refs.d.ts +194 -0
- package/dist/framework/utils/refs.js +403 -0
- package/dist/framework/validate-spec.d.ts +27 -0
- package/dist/framework/validate-spec.js +45 -0
- package/dist/framework/value-domain.d.ts +26 -0
- package/dist/framework/value-domain.js +202 -0
- package/dist/framework/views-facade.d.ts +15 -0
- package/dist/framework/views-facade.js +19 -0
- package/dist/index.d.ts +90 -42
- package/dist/index.js +86 -37
- package/dist/migrations/2.0.0/raw-css.d.ts +11 -0
- package/dist/migrations/2.0.0/raw-css.js +72 -0
- package/dist/migrations/2.0.0/v1-artifact.d.ts +1559 -0
- package/dist/migrations/2.0.0/v1-artifact.js +1018 -0
- package/dist/migrations/20260908171448_settings_as_kind.d.ts +22 -0
- package/dist/migrations/20260908171448_settings_as_kind.js +89 -0
- package/dist/migrations/20260908194245_visible_state_pointer.d.ts +19 -0
- package/dist/migrations/20260908194245_visible_state_pointer.js +115 -0
- package/dist/migrations/20260909183001_icon_knockout_variants.d.ts +18 -0
- package/dist/migrations/20260909183001_icon_knockout_variants.js +8 -0
- package/dist/migrations/20260910212453_linked_system_link_ops.d.ts +13 -0
- package/dist/migrations/20260910212453_linked_system_link_ops.js +8 -0
- package/dist/migrations/index.d.ts +2 -0
- package/dist/migrations/index.js +2 -0
- package/dist/react-native/style-keys.generated.d.ts +10 -0
- package/dist/react-native/style-keys.generated.js +167 -0
- package/dist/renderer/RendererErrorBoundary.d.ts +32 -5
- package/dist/renderer/RendererErrorBoundary.js +59 -10
- package/dist/renderer/UdsRenderer.d.ts +11 -10
- package/dist/renderer/UdsRenderer.js +1 -1
- package/dist/renderer/assetEntries.d.ts +37 -0
- package/dist/renderer/assetEntries.js +39 -0
- package/dist/renderer/assetRenderable.d.ts +14 -6
- package/dist/renderer/assetRenderable.js +8 -2
- package/dist/renderer/componentEntry.d.ts +58 -0
- package/dist/renderer/componentEntry.js +71 -0
- package/dist/renderer/icon-library.d.ts +20 -0
- package/dist/renderer/index.d.ts +7 -7
- package/dist/renderer/index.js +5 -5
- package/dist/renderer/primitives/SlotRenderer.d.ts +1 -1
- package/dist/renderer/primitives/SlotRenderer.js +1 -1
- package/dist/renderer/runtimeComponent.d.ts +33 -0
- package/dist/renderer/runtimeComponent.js +113 -0
- package/dist/renderer/spec-content.d.ts +43 -0
- package/dist/renderer/spec-content.js +95 -0
- package/dist/renderer/wrapRegistry.d.ts +22 -37
- package/dist/renderer/wrapRegistry.js +10 -20
- package/dist/renderer/wrappers/event-bridge.js +6 -5
- package/dist/renderer/wrappers/hex-normalize.js +6 -5
- package/dist/renderer/wrappers/html-aliases.d.ts +7 -2
- package/dist/renderer/wrappers/html-aliases.js +36 -19
- package/dist/renderer/wrappers/inline-styles.js +7 -6
- package/dist/spec/asset-jsx.d.ts +18 -5
- package/dist/spec/asset-jsx.js +27 -16
- package/dist/spec/collapse-text-labels.d.ts +5 -15
- package/dist/spec/collapse-text-labels.js +26 -19
- package/dist/spec/empty-node-slots.d.ts +56 -34
- package/dist/spec/empty-node-slots.js +87 -47
- package/dist/spec/index.d.ts +21 -10
- package/dist/spec/index.js +21 -10
- package/dist/spec/jsxToSpec.d.ts +14 -9
- package/dist/spec/jsxToSpec.js +20 -3
- package/dist/spec/preview-elements.d.ts +63 -0
- package/dist/spec/preview-elements.js +89 -0
- package/dist/spec/rewrite-refs.d.ts +58 -0
- package/dist/spec/rewrite-refs.js +250 -0
- package/dist/spec/specToJsx.js +18 -29
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +39 -52
- package/dist/AssetGroup.d.ts +0 -77
- package/dist/AssetGroup.js +0 -125
- package/dist/Component.d.ts +0 -333
- package/dist/Component.js +0 -1061
- package/dist/ComponentGroup.d.ts +0 -22
- package/dist/ComponentGroup.js +0 -51
- package/dist/CompositeStyle.d.ts +0 -30
- package/dist/CompositeStyle.js +0 -59
- package/dist/Config.d.ts +0 -528
- package/dist/Config.js +0 -1712
- package/dist/Mode.d.ts +0 -41
- package/dist/Mode.js +0 -81
- package/dist/Modifier.d.ts +0 -51
- package/dist/Modifier.js +0 -97
- package/dist/MotionDef.d.ts +0 -81
- package/dist/MotionDef.js +0 -212
- package/dist/Props.d.ts +0 -332
- package/dist/Props.js +0 -35
- package/dist/Provider.d.ts +0 -20
- package/dist/Provider.js +0 -14
- package/dist/StyleProp.d.ts +0 -145
- package/dist/StyleProp.js +0 -239
- package/dist/Token.d.ts +0 -76
- package/dist/Token.js +0 -133
- package/dist/TokenGroup.d.ts +0 -33
- package/dist/TokenGroup.js +0 -69
- package/dist/asset-kind.d.ts +0 -55
- package/dist/asset-kind.js +0 -29
- package/dist/asset-value.d.ts +0 -23
- package/dist/asset-value.js +0 -40
- package/dist/brands.d.ts +0 -30
- package/dist/brands.js +0 -20
- package/dist/captureCallerPath.d.ts +0 -48
- package/dist/captureCallerPath.js +0 -95
- package/dist/colorExpressions.d.ts +0 -131
- package/dist/colorExpressions.js +0 -148
- package/dist/component-referrers.d.ts +0 -30
- package/dist/component-referrers.js +0 -40
- package/dist/config-diagnostics.d.ts +0 -21
- package/dist/config-diagnostics.js +0 -12
- package/dist/defineAssetGroup.d.ts +0 -200
- package/dist/defineAssetGroup.js +0 -323
- package/dist/defineProvider.d.ts +0 -29
- package/dist/defineProvider.js +0 -60
- package/dist/element-marker.d.ts +0 -63
- package/dist/element-marker.js +0 -113
- package/dist/entity-utils.d.ts +0 -56
- package/dist/entity-utils.js +0 -105
- package/dist/extension.d.ts +0 -55
- package/dist/extension.js +0 -214
- package/dist/factories.d.ts +0 -863
- package/dist/factories.js +0 -475
- package/dist/font-face.d.ts +0 -25
- package/dist/font-face.js +0 -72
- package/dist/foreign-component-name.d.ts +0 -21
- package/dist/foreign-component-name.js +0 -42
- package/dist/interpolate.d.ts +0 -20
- package/dist/interpolate.js +0 -10
- package/dist/jsx/__fixtures__/cross-component-preview.d.ts +0 -3
- package/dist/jsx/__fixtures__/cross-component-preview.js +0 -15
- package/dist/jsx/jsx-dev-runtime.d.ts +0 -15
- package/dist/jsx/jsx-dev-runtime.js +0 -11
- package/dist/jsx/jsx-runtime.d.ts +0 -48
- package/dist/jsx/jsx-runtime.js +0 -305
- package/dist/linked-system-pins.d.ts +0 -30
- package/dist/linked-system-pins.js +0 -45
- package/dist/linkedNodePrefixes.d.ts +0 -73
- package/dist/linkedNodePrefixes.js +0 -99
- package/dist/markers.d.ts +0 -235
- package/dist/markers.js +0 -70
- package/dist/motion-constants.d.ts +0 -37
- package/dist/motion-constants.js +0 -61
- package/dist/native/NativeConfig.d.ts +0 -56
- package/dist/native/NativeConfig.js +0 -162
- package/dist/native/assets.d.ts +0 -20
- package/dist/native/assets.js +0 -17
- package/dist/native/components.d.ts +0 -139
- package/dist/native/components.js +0 -67
- package/dist/native/index.d.ts +0 -18
- package/dist/native/index.js +0 -17
- package/dist/native/modes.d.ts +0 -10
- package/dist/native/modes.js +0 -11
- package/dist/native/types.d.ts +0 -95
- package/dist/native/types.js +0 -0
- package/dist/native/validation.d.ts +0 -8
- package/dist/native/validation.js +0 -885
- package/dist/native/values.d.ts +0 -7
- package/dist/native/values.js +0 -15
- package/dist/native.d.ts +0 -12
- package/dist/native.js +0 -10
- package/dist/refs.d.ts +0 -204
- package/dist/refs.js +0 -129
- package/dist/registry-aliases.d.ts +0 -33
- package/dist/registry-aliases.js +0 -35
- package/dist/registry-dir.d.ts +0 -22
- package/dist/registry-dir.js +0 -10
- package/dist/renderer/makeRegistry.d.ts +0 -34
- package/dist/renderer/makeRegistry.js +0 -52
- package/dist/renderer/makeUdsRenderer.d.ts +0 -13
- package/dist/renderer/makeUdsRenderer.js +0 -51
- package/dist/renderer/wrappers/component-slots.d.ts +0 -41
- package/dist/renderer/wrappers/component-slots.js +0 -66
- package/dist/renderer/wrappers/slot-resolution.d.ts +0 -25
- package/dist/renderer/wrappers/slot-resolution.js +0 -68
- package/dist/renderer/wrappers/void-elements.d.ts +0 -37
- package/dist/renderer/wrappers/void-elements.js +0 -40
- package/dist/spec/layer-props.d.ts +0 -52
- package/dist/spec/layer-props.js +0 -149
- package/dist/spec/preview-controls.d.ts +0 -44
- package/dist/spec/preview-controls.js +0 -139
- package/dist/spec/slot-refs.d.ts +0 -39
- package/dist/spec/slot-refs.js +0 -56
- package/dist/token-override-rows.d.ts +0 -68
- package/dist/token-override-rows.js +0 -233
- package/dist/tokenValueType.d.ts +0 -34
- package/dist/tokenValueType.js +0 -138
- package/dist/types/css-properties.d.ts +0 -233
- package/dist/types/css-properties.js +0 -14
- package/dist/types/css-property-keywords.d.ts +0 -156
- package/dist/types/css-property-keywords.js +0 -616
- package/dist/types/css-values.d.ts +0 -63
- package/dist/types/css-values.js +0 -16
- package/dist/types.d.ts +0 -1138
- package/dist/types.js +0 -12
- package/dist/units.d.ts +0 -14
- package/dist/units.js +0 -16
- package/dist/utils/index.d.ts +0 -4
- package/dist/utils/index.js +0 -4
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
//#region src/spec/preview-elements.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A preview element is the JSON-safe form of JSX stored in a component's preview props.
|
|
4
|
+
*
|
|
5
|
+
* It is authoring data, not a React element and not yet a json-render node. The helpers in this file
|
|
6
|
+
* own the conversion into the UDS spec dialect so every render host receives the same shape.
|
|
7
|
+
*/
|
|
8
|
+
interface PreviewElement {
|
|
9
|
+
readonly element: string | {
|
|
10
|
+
readonly __ref: string;
|
|
11
|
+
};
|
|
12
|
+
readonly props?: Record<string, string | number | boolean>;
|
|
13
|
+
readonly children?: PreviewElement[];
|
|
14
|
+
readonly text?: string;
|
|
15
|
+
}
|
|
16
|
+
type PreviewValue = string | number | boolean | PreviewElement | PreviewValue[] | {
|
|
17
|
+
readonly [key: string]: PreviewValue;
|
|
18
|
+
};
|
|
19
|
+
/** Whether a stored value names an element to render. */
|
|
20
|
+
declare function isPreviewElement(value: unknown): value is PreviewElement;
|
|
21
|
+
/**
|
|
22
|
+
* Whether anything under a value is a stored preview element. Stops at live React elements: walking
|
|
23
|
+
* through their owner Fiber reaches a circular structure.
|
|
24
|
+
*/
|
|
25
|
+
declare function hasPreviewElementDeep(value: unknown): boolean;
|
|
26
|
+
/** The json-render `type` a stored element names. */
|
|
27
|
+
declare function previewElementType(element: PreviewElement['element']): string;
|
|
28
|
+
/** One flattened node in a json-render spec. */
|
|
29
|
+
interface PreviewSpecNode {
|
|
30
|
+
readonly type: string;
|
|
31
|
+
readonly props?: Record<string, unknown>;
|
|
32
|
+
/** Child element keys, never literal content. */
|
|
33
|
+
readonly children?: string[];
|
|
34
|
+
}
|
|
35
|
+
/** Flatten one stored preview element into json-render's keyed element map. */
|
|
36
|
+
declare function previewElementNodes(root: PreviewElement, rootKey: string, taken?: ReadonlySet<string>): {
|
|
37
|
+
root: string;
|
|
38
|
+
elements: Record<string, PreviewSpecNode>;
|
|
39
|
+
};
|
|
40
|
+
/** The portion of a spec needed to graft stored preview elements into it. */
|
|
41
|
+
type GraftableSpec = {
|
|
42
|
+
root: string;
|
|
43
|
+
elements: Record<string, GraftableElement>;
|
|
44
|
+
};
|
|
45
|
+
type GraftableElement = {
|
|
46
|
+
props?: Record<string, unknown>;
|
|
47
|
+
children?: string[];
|
|
48
|
+
slots?: Record<string, string[]>;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Lower direct element-valued props into json-render's native slot form.
|
|
52
|
+
*
|
|
53
|
+
* The element subtrees join the spec's keyed element map, and the root's `slots` record names their
|
|
54
|
+
* keys under the prop that carried them — json-render traverses `slots` itself, so the keys join
|
|
55
|
+
* neither `props` nor `children`. Plain values—including text in `props.children`—remain props.
|
|
56
|
+
*
|
|
57
|
+
* Elements nested inside arbitrary structured data are deliberately left for runtime marker
|
|
58
|
+
* revival. A `slots` entry identifies a component prop, not a path inside an opaque application
|
|
59
|
+
* value.
|
|
60
|
+
*/
|
|
61
|
+
declare function graftPreviewElements<S extends GraftableSpec>(spec: S, values: Record<string, unknown>): S;
|
|
62
|
+
//#endregion
|
|
63
|
+
export { GraftableElement, GraftableSpec, PreviewElement, PreviewSpecNode, PreviewValue, graftPreviewElements, hasPreviewElementDeep, isPreviewElement, previewElementNodes, previewElementType };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
//#region src/spec/preview-elements.ts
|
|
2
|
+
/** Whether a stored value names an element to render. */
|
|
3
|
+
function isPreviewElement(value) {
|
|
4
|
+
if (typeof value !== "object" || value === null) return false;
|
|
5
|
+
const { element } = value;
|
|
6
|
+
return typeof element === "string" || typeof element === "object" && element !== null && typeof element.__ref === "string";
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Whether anything under a value is a stored preview element. Stops at live React elements: walking
|
|
10
|
+
* through their owner Fiber reaches a circular structure.
|
|
11
|
+
*/
|
|
12
|
+
function hasPreviewElementDeep(value) {
|
|
13
|
+
if (typeof value !== "object" || value === null) return false;
|
|
14
|
+
if ("$$typeof" in value) return false;
|
|
15
|
+
if (isPreviewElement(value)) return true;
|
|
16
|
+
return (Array.isArray(value) ? value : Object.values(value)).some(hasPreviewElementDeep);
|
|
17
|
+
}
|
|
18
|
+
/** The json-render `type` a stored element names. */
|
|
19
|
+
function previewElementType(element) {
|
|
20
|
+
return typeof element === "string" ? element : element.__ref;
|
|
21
|
+
}
|
|
22
|
+
/** Flatten one stored preview element into json-render's keyed element map. */
|
|
23
|
+
function previewElementNodes(root, rootKey, taken = /* @__PURE__ */ new Set()) {
|
|
24
|
+
const elements = {};
|
|
25
|
+
const used = new Set(taken);
|
|
26
|
+
const add = (node, base) => {
|
|
27
|
+
let key = base;
|
|
28
|
+
while (used.has(key)) key = `${key}_`;
|
|
29
|
+
used.add(key);
|
|
30
|
+
const children = (node.children ?? []).map((child, index) => add(child, `${key}_${index}`));
|
|
31
|
+
elements[key] = {
|
|
32
|
+
type: previewElementType(node.element),
|
|
33
|
+
props: {
|
|
34
|
+
...node.props ?? {},
|
|
35
|
+
...node.text !== void 0 ? { children: node.text } : {}
|
|
36
|
+
},
|
|
37
|
+
...children.length > 0 ? { children } : {}
|
|
38
|
+
};
|
|
39
|
+
return key;
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
root: add(root, rootKey),
|
|
43
|
+
elements
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** A direct element-valued prop or a list of element values. */
|
|
47
|
+
function isElementValue(value) {
|
|
48
|
+
return isPreviewElement(value) || Array.isArray(value) && value.some(isPreviewElement);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Lower direct element-valued props into json-render's native slot form.
|
|
52
|
+
*
|
|
53
|
+
* The element subtrees join the spec's keyed element map, and the root's `slots` record names their
|
|
54
|
+
* keys under the prop that carried them — json-render traverses `slots` itself, so the keys join
|
|
55
|
+
* neither `props` nor `children`. Plain values—including text in `props.children`—remain props.
|
|
56
|
+
*
|
|
57
|
+
* Elements nested inside arbitrary structured data are deliberately left for runtime marker
|
|
58
|
+
* revival. A `slots` entry identifies a component prop, not a path inside an opaque application
|
|
59
|
+
* value.
|
|
60
|
+
*/
|
|
61
|
+
function graftPreviewElements(spec, values) {
|
|
62
|
+
const entries = Object.entries(values).filter(([, value]) => isElementValue(value));
|
|
63
|
+
if (entries.length === 0) return spec;
|
|
64
|
+
const next = structuredClone(spec);
|
|
65
|
+
const elements = next.elements;
|
|
66
|
+
const rootKey = next.root;
|
|
67
|
+
const rootElement = elements[rootKey];
|
|
68
|
+
if (!rootElement) return spec;
|
|
69
|
+
const used = new Set(Object.keys(elements));
|
|
70
|
+
const rootProps = { ...rootElement.props ?? {} };
|
|
71
|
+
const rootSlots = { ...rootElement.slots ?? {} };
|
|
72
|
+
for (const [prop, value] of entries) {
|
|
73
|
+
const keys = (Array.isArray(value) ? value.filter(isPreviewElement) : [value]).map((node, index) => {
|
|
74
|
+
const graft = previewElementNodes(node, `${rootKey}__${prop}__${index}`, used);
|
|
75
|
+
for (const [key, element] of Object.entries(graft.elements)) {
|
|
76
|
+
elements[key] = element;
|
|
77
|
+
used.add(key);
|
|
78
|
+
}
|
|
79
|
+
return graft.root;
|
|
80
|
+
});
|
|
81
|
+
delete rootProps[prop];
|
|
82
|
+
rootSlots[prop] = keys;
|
|
83
|
+
}
|
|
84
|
+
rootElement.props = rootProps;
|
|
85
|
+
rootElement.slots = rootSlots;
|
|
86
|
+
return next;
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
export { graftPreviewElements, hasPreviewElementDeep, isPreviewElement, previewElementNodes, previewElementType };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Config } from "../framework/Config.js";
|
|
2
|
+
|
|
3
|
+
//#region src/spec/rewrite-refs.d.ts
|
|
4
|
+
/** One rename to carry into a document, named by WHAT was renamed. */
|
|
5
|
+
type DocumentRename = /** A component's path — `element.type` and a node's own component name. */{
|
|
6
|
+
readonly kind: 'component';
|
|
7
|
+
readonly from: string;
|
|
8
|
+
readonly to: string;
|
|
9
|
+
} /** One component's own prop — a `props` KEY, on that component's elements only. */ | {
|
|
10
|
+
readonly kind: 'component-prop';
|
|
11
|
+
readonly component: string;
|
|
12
|
+
readonly from: string;
|
|
13
|
+
readonly to: string;
|
|
14
|
+
} /** One value of one variant prop — a `props` VALUE, on that component's elements only. */ | {
|
|
15
|
+
readonly kind: 'variant-value';
|
|
16
|
+
readonly component: string;
|
|
17
|
+
readonly prop: string;
|
|
18
|
+
readonly from: string;
|
|
19
|
+
readonly to: string;
|
|
20
|
+
} /** A style property — a `props` KEY on every element that doesn't declare its own prop of that name. */ | {
|
|
21
|
+
readonly kind: 'style-property';
|
|
22
|
+
readonly from: string;
|
|
23
|
+
readonly to: string;
|
|
24
|
+
} /** A token — a `props` VALUE, on props drawing from that token's group. Paths, not leaves. */ | {
|
|
25
|
+
readonly kind: 'token';
|
|
26
|
+
readonly from: string;
|
|
27
|
+
readonly to: string;
|
|
28
|
+
} /** A modifier — the `_`-prefixed `props` KEY its block hangs off, on every element. Paths, not `_` keys. */ | {
|
|
29
|
+
readonly kind: 'modifier';
|
|
30
|
+
readonly from: string;
|
|
31
|
+
readonly to: string;
|
|
32
|
+
} /** One layer of one component — a key inside `layerProps`, on that component's elements only. */ | {
|
|
33
|
+
readonly kind: 'layer';
|
|
34
|
+
readonly component: string;
|
|
35
|
+
readonly from: string;
|
|
36
|
+
readonly to: string;
|
|
37
|
+
};
|
|
38
|
+
/** A spec as this reads it: the structural subset, loose because the rows are whatever was written months ago. */
|
|
39
|
+
interface RewritableSpec {
|
|
40
|
+
elements?: Record<string, {
|
|
41
|
+
type?: unknown;
|
|
42
|
+
props?: Record<string, unknown>;
|
|
43
|
+
} | undefined>;
|
|
44
|
+
}
|
|
45
|
+
interface SpecRewrite {
|
|
46
|
+
readonly spec: RewritableSpec;
|
|
47
|
+
/** How many positions changed. Zero means the same spec object comes back, by identity. */
|
|
48
|
+
readonly changed: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The spec with every reference the renames name pointing at its new name.
|
|
52
|
+
*
|
|
53
|
+
* Returns the same spec object when nothing matched, so a caller can skip the write entirely rather than store a
|
|
54
|
+
* copy of what it read — a cascade that touches every row on every rename is its own problem.
|
|
55
|
+
*/
|
|
56
|
+
declare function rewriteSpecRefs(config: Config, spec: RewritableSpec, renames: readonly DocumentRename[]): SpecRewrite;
|
|
57
|
+
//#endregion
|
|
58
|
+
export { DocumentRename, RewritableSpec, SpecRewrite, rewriteSpecRefs };
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { isRef, kindOf, pathOf } from "../framework/utils/refs.js";
|
|
2
|
+
import { StyleProperty } from "../entities/system/StyleProperty.js";
|
|
3
|
+
import { propOwner, resolveComponentProps } from "../framework/projections.js";
|
|
4
|
+
import { Component } from "../entities/system/Component.js";
|
|
5
|
+
//#region src/spec/rewrite-refs.ts
|
|
6
|
+
/**
|
|
7
|
+
* Carrying a config rename into the documents that reference it.
|
|
8
|
+
*
|
|
9
|
+
* A canvas spec references the config in more places than its element types. Counted on one real branch: 2,207
|
|
10
|
+
* elements set a component's own prop (`variant`), several thousand set a style property (`bg`, `color`, `gap`,
|
|
11
|
+
* `borderRadius`, …), and the values they set are token leaves and variant values. Renaming any of those inside
|
|
12
|
+
* the config cascades through `cascadeRename` — which walks the ref index — and reaches none of the documents,
|
|
13
|
+
* because a document holds no ref that index can see.
|
|
14
|
+
*
|
|
15
|
+
* So the rename has to be applied here, and the difficulty is that a spec's positions are CONTEXT-DEPENDENT:
|
|
16
|
+
*
|
|
17
|
+
* - `props.variant` is `Button`'s own prop only on elements whose type is `Button`. Rewriting the key wherever
|
|
18
|
+
* it appears would rename an unrelated component's `variant` too.
|
|
19
|
+
* - `props.bg` is the `bg` STYLE PROPERTY — unless the element's component declares its own `bg`, in which case
|
|
20
|
+
* the component's declaration wins and a style-property rename must leave it alone.
|
|
21
|
+
* - `props.bg = 'primary'` is a token LEAF inside whatever group the `bg` style property draws from, so a token
|
|
22
|
+
* rename only touches values on props that draw from that token's group.
|
|
23
|
+
*
|
|
24
|
+
* Every one of those questions is answered by the config (`resolveComponentProps`, the prop's declaration, the
|
|
25
|
+
* style property's own `values`), which is why this takes one and resolves rather than matching strings.
|
|
26
|
+
*
|
|
27
|
+
* A MODIFIER is the one position that answers for itself. `_hover` is a prop bag keyed by a modifier's path, and
|
|
28
|
+
* nothing else in a spec is `_`-prefixed — a component can't declare such a prop, and both the style resolver and
|
|
29
|
+
* the prop validator skip the prefix on sight. So a modifier rename moves the key unconditionally, with no
|
|
30
|
+
* component to scope it by. What the block CONTAINS is a second props bag against the same element, which is why
|
|
31
|
+
* every other rename here descends into it: `_hover: { bg: 'accent' }` sets the same style property and the same
|
|
32
|
+
* token as the bag around it, and stopping at the top level would leave the conditional half of a component
|
|
33
|
+
* stale while the base half moved.
|
|
34
|
+
*
|
|
35
|
+
* `layerProps` is the same shape with one twist: its keys are the component's LAYER names, and each bag under one
|
|
36
|
+
* belongs to what that layer RENDERS rather than to the component around it. So a layer rename moves the key —
|
|
37
|
+
* scoped to its component, since `text` on one component is a different layer from `text` on another — and every
|
|
38
|
+
* other rename descends with the layer's own declarations, because `layerProps.text.variant` is `Text`'s variant.
|
|
39
|
+
* A layer that renders a component can itself be overridden through `layerProps`, and that nests the same way.
|
|
40
|
+
*
|
|
41
|
+
* Renames arrive TYPED and EXACT, from the patch that recorded them — never inferred. The config supports a
|
|
42
|
+
* rename op per kind and a sub-rename for a component's `props` and `props/value`, so the patch log names both
|
|
43
|
+
* halves of every case below.
|
|
44
|
+
*/
|
|
45
|
+
/** Whether a stored `type` names this component path, in either form it may be written in. */
|
|
46
|
+
function namesComponent(type, path) {
|
|
47
|
+
if (typeof type !== "string") return false;
|
|
48
|
+
if (type === path) return true;
|
|
49
|
+
return type.includes(":") && kindOf(type) === "component" ? type === `component:${path}` : false;
|
|
50
|
+
}
|
|
51
|
+
/** The component an element names, as a path — `undefined` for an intrinsic tag or another kind. */
|
|
52
|
+
function componentOf(type) {
|
|
53
|
+
if (typeof type !== "string") return void 0;
|
|
54
|
+
if (!type.includes(":")) return type;
|
|
55
|
+
return kindOf(type) === "component" ? pathOf(type) : void 0;
|
|
56
|
+
}
|
|
57
|
+
/** The style property a prop declaration BINDS, when it binds one. */
|
|
58
|
+
function boundStylePropPath(declaration) {
|
|
59
|
+
const decl = declaration;
|
|
60
|
+
return decl?.type === "styleProperty" && isRef(decl.value) ? pathOf(decl.value.__ref) : void 0;
|
|
61
|
+
}
|
|
62
|
+
/** The token GROUP a prop declaration draws its values from, if it draws from one. */
|
|
63
|
+
function tokenGroupOf(config, declaration) {
|
|
64
|
+
const decl = declaration;
|
|
65
|
+
if (decl?.type !== "styleProperty" || !isRef(decl.value)) return;
|
|
66
|
+
const styleProp = StyleProperty.get(config, pathOf(decl.value.__ref));
|
|
67
|
+
for (const value of styleProp?.values ?? []) if (isRef(value) && kindOf(value.__ref) === "token") return pathOf(value.__ref);
|
|
68
|
+
}
|
|
69
|
+
/** The prop a call site overrides a component's inner layers through — see `deriveSpec`, which spreads each of
|
|
70
|
+
* its bags onto the node whose layer the key names. */
|
|
71
|
+
const LAYER_PROPS = "layerProps";
|
|
72
|
+
/** A nested props bag as stored — `undefined` for anything in a bag that is a VALUE rather than a bag. */
|
|
73
|
+
function nestedBag(value) {
|
|
74
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The nested props bag a modifier block holds — `undefined` for anything else in the bag.
|
|
78
|
+
*
|
|
79
|
+
* The `_` prefix is the whole test, which is the same test `styleDeclarations` and the prop validator make. A
|
|
80
|
+
* key naming a modifier the config no longer holds still reads as a block: an unresolvable one is a document
|
|
81
|
+
* that needs repairing, not a reason to leave the props inside it un-renamed.
|
|
82
|
+
*/
|
|
83
|
+
function modifierBlock(key, value) {
|
|
84
|
+
return key.startsWith("_") ? nestedBag(value) : void 0;
|
|
85
|
+
}
|
|
86
|
+
const INTRINSIC = {
|
|
87
|
+
component: void 0,
|
|
88
|
+
declared: {}
|
|
89
|
+
};
|
|
90
|
+
function scopeFor(config, component) {
|
|
91
|
+
return component ? {
|
|
92
|
+
component,
|
|
93
|
+
declared: resolveComponentProps(config, component)
|
|
94
|
+
} : INTRINSIC;
|
|
95
|
+
}
|
|
96
|
+
/** The scope one `layerProps` entry's bag belongs to — the element the named layer renders. */
|
|
97
|
+
function layerScope(config, scope, layer) {
|
|
98
|
+
if (!scope.component) return INTRINSIC;
|
|
99
|
+
const element = Component.get(config, scope.component)?.layers?.[layer];
|
|
100
|
+
return scopeFor(config, isRef(element) ? pathOf(element.__ref) : void 0);
|
|
101
|
+
}
|
|
102
|
+
/** Rename a KEY inside a props bag, preserving insertion order — order is meaning in a stored document. */
|
|
103
|
+
function withRenamedKey(props, from, to) {
|
|
104
|
+
const out = {};
|
|
105
|
+
for (const [key, value] of Object.entries(props)) out[key === from ? to : key] = value;
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* One rename applied to the keys and values of ONE bag — `undefined` when it matched nothing there.
|
|
110
|
+
*
|
|
111
|
+
* Everything scoped to a component is scoped to THIS bag's component, which is the element's for its own props
|
|
112
|
+
* and the layer's element for a `layerProps` bag.
|
|
113
|
+
*/
|
|
114
|
+
function rewriteOwnEntries(config, scope, props, rename) {
|
|
115
|
+
if (rename.kind === "layer") return void 0;
|
|
116
|
+
if (rename.kind === "component-prop" || rename.kind === "variant-value") {
|
|
117
|
+
if (!scope.component) return void 0;
|
|
118
|
+
if (scope.component !== rename.component) {
|
|
119
|
+
const target = rename.kind === "component-prop" ? rename.to : rename.prop;
|
|
120
|
+
if (!(propOwner(config, scope.component, target) === rename.component || rename.kind === "component-prop" && propOwner(config, scope.component, rename.from) === rename.component)) return void 0;
|
|
121
|
+
if (rename.kind === "component-prop" && propOwner(config, scope.component, rename.from) === scope.component) return;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const declared = scope.declared;
|
|
125
|
+
if (rename.kind === "modifier") {
|
|
126
|
+
const from = `_${rename.from}`;
|
|
127
|
+
return from in props ? withRenamedKey(props, from, `_${rename.to}`) : void 0;
|
|
128
|
+
}
|
|
129
|
+
if (rename.kind === "component-prop") return rename.from in props ? withRenamedKey(props, rename.from, rename.to) : void 0;
|
|
130
|
+
if (rename.kind === "variant-value") return props[rename.prop] === rename.from ? {
|
|
131
|
+
...props,
|
|
132
|
+
[rename.prop]: rename.to
|
|
133
|
+
} : void 0;
|
|
134
|
+
if (rename.kind === "style-property") {
|
|
135
|
+
if (!(rename.from in props)) return void 0;
|
|
136
|
+
const declaration = declared[rename.from];
|
|
137
|
+
if (declaration !== void 0 && boundStylePropPath(declaration) !== rename.from) return;
|
|
138
|
+
return withRenamedKey(props, rename.from, rename.to);
|
|
139
|
+
}
|
|
140
|
+
const group = rename.from.slice(0, rename.from.lastIndexOf("/"));
|
|
141
|
+
const leaf = rename.from.slice(rename.from.lastIndexOf("/") + 1);
|
|
142
|
+
const toLeaf = rename.to.slice(rename.to.lastIndexOf("/") + 1);
|
|
143
|
+
if (!group) return void 0;
|
|
144
|
+
let next;
|
|
145
|
+
for (const [prop, value] of Object.entries(props)) {
|
|
146
|
+
if (value !== leaf) continue;
|
|
147
|
+
if (tokenGroupOf(config, declared[prop]) !== group) continue;
|
|
148
|
+
next ??= { ...props };
|
|
149
|
+
next[prop] = toLeaf;
|
|
150
|
+
}
|
|
151
|
+
return next;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* One rename applied to a props bag, to every modifier block nested inside it, and to every layer override under
|
|
155
|
+
* its `layerProps` — at any depth.
|
|
156
|
+
*
|
|
157
|
+
* `undefined` when nothing matched, so a caller can leave the element it came from untouched.
|
|
158
|
+
*/
|
|
159
|
+
function rewriteProps(config, scope, props, rename) {
|
|
160
|
+
let next = rewriteOwnEntries(config, scope, props, rename);
|
|
161
|
+
for (const [key, value] of Object.entries(next ?? props)) {
|
|
162
|
+
let rewritten;
|
|
163
|
+
if (key === LAYER_PROPS) rewritten = rewriteLayerProps(config, scope, value, rename);
|
|
164
|
+
else {
|
|
165
|
+
const block = modifierBlock(key, value);
|
|
166
|
+
rewritten = block ? rewriteProps(config, scope, block, rename) : void 0;
|
|
167
|
+
}
|
|
168
|
+
if (!rewritten) continue;
|
|
169
|
+
next ??= { ...props };
|
|
170
|
+
next[key] = rewritten;
|
|
171
|
+
}
|
|
172
|
+
return next;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* One rename applied to a `layerProps` override map: KEYS are the enclosing component's layer names, and each
|
|
176
|
+
* value is a props bag belonging to what that layer renders.
|
|
177
|
+
*
|
|
178
|
+
* The key rename is the only thing here scoped to the enclosing component rather than to the bag's own — a layer
|
|
179
|
+
* name means nothing on its own, and two components' `text` layers are unrelated.
|
|
180
|
+
*/
|
|
181
|
+
function rewriteLayerProps(config, scope, layerProps, rename) {
|
|
182
|
+
const bags = nestedBag(layerProps);
|
|
183
|
+
if (!bags) return void 0;
|
|
184
|
+
let next;
|
|
185
|
+
if (rename.kind === "layer" && scope.component === rename.component && rename.from in bags) next = withRenamedKey(bags, rename.from, rename.to);
|
|
186
|
+
for (const [layer, value] of Object.entries(next ?? bags)) {
|
|
187
|
+
const bag = nestedBag(value);
|
|
188
|
+
if (!bag) continue;
|
|
189
|
+
const rewritten = rewriteProps(config, layerScope(config, scope, layer), bag, rename);
|
|
190
|
+
if (!rewritten) continue;
|
|
191
|
+
next ??= { ...bags };
|
|
192
|
+
next[layer] = rewritten;
|
|
193
|
+
}
|
|
194
|
+
return next;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* The spec with every reference the renames name pointing at its new name.
|
|
198
|
+
*
|
|
199
|
+
* Returns the same spec object when nothing matched, so a caller can skip the write entirely rather than store a
|
|
200
|
+
* copy of what it read — a cascade that touches every row on every rename is its own problem.
|
|
201
|
+
*/
|
|
202
|
+
function rewriteSpecRefs(config, spec, renames) {
|
|
203
|
+
if (renames.length === 0) return {
|
|
204
|
+
spec,
|
|
205
|
+
changed: 0
|
|
206
|
+
};
|
|
207
|
+
let elements;
|
|
208
|
+
let changed = 0;
|
|
209
|
+
for (const [key, element] of Object.entries(spec.elements ?? {})) {
|
|
210
|
+
if (!element) continue;
|
|
211
|
+
let type = element.type;
|
|
212
|
+
let props = element.props;
|
|
213
|
+
let touched = 0;
|
|
214
|
+
const scope = scopeFor(config, componentOf(element.type));
|
|
215
|
+
for (const rename of renames) {
|
|
216
|
+
if (rename.from === rename.to) continue;
|
|
217
|
+
if (rename.kind === "component") {
|
|
218
|
+
if (!namesComponent(type, rename.from)) continue;
|
|
219
|
+
type = typeof type === "string" && type.includes(":") ? `component:${rename.to}` : rename.to;
|
|
220
|
+
touched++;
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (!props) continue;
|
|
224
|
+
const next = rewriteProps(config, scope, props, rename);
|
|
225
|
+
if (!next) continue;
|
|
226
|
+
props = next;
|
|
227
|
+
touched++;
|
|
228
|
+
}
|
|
229
|
+
if (touched === 0) continue;
|
|
230
|
+
elements ??= { ...spec.elements };
|
|
231
|
+
elements[key] = {
|
|
232
|
+
...element,
|
|
233
|
+
...type !== void 0 ? { type } : {},
|
|
234
|
+
...props ? { props } : {}
|
|
235
|
+
};
|
|
236
|
+
changed += touched;
|
|
237
|
+
}
|
|
238
|
+
return elements ? {
|
|
239
|
+
spec: {
|
|
240
|
+
...spec,
|
|
241
|
+
elements
|
|
242
|
+
},
|
|
243
|
+
changed
|
|
244
|
+
} : {
|
|
245
|
+
spec,
|
|
246
|
+
changed: 0
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
//#endregion
|
|
250
|
+
export { rewriteSpecRefs };
|
package/dist/spec/specToJsx.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { assetJsxForm } from "./asset-jsx.js";
|
|
1
|
+
import { assetJsxForm, jsxIdentifier } from "./asset-jsx.js";
|
|
3
2
|
import { serializeProps } from "@json-render/codegen";
|
|
4
3
|
//#region src/spec/specToJsx.ts
|
|
5
4
|
function statePathToExpression(path) {
|
|
@@ -8,14 +7,10 @@ function statePathToExpression(path) {
|
|
|
8
7
|
function isDynamicValue(value) {
|
|
9
8
|
return typeof value === "object" && value !== null && "$state" in value && typeof value.$state === "string";
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return Array.isArray(value.$slot) ? value.$slot : [value.$slot];
|
|
14
|
-
}
|
|
15
|
-
/** Collect all element keys referenced via $slot in a spec element's props */
|
|
16
|
-
function collectSlotKeys(props) {
|
|
10
|
+
/** All element keys an element's `slots` record pulls in. */
|
|
11
|
+
function collectSlotKeys(slots) {
|
|
17
12
|
const keys = /* @__PURE__ */ new Set();
|
|
18
|
-
for (const
|
|
13
|
+
for (const fills of Object.values(slots ?? {})) for (const ref of fills) keys.add(ref);
|
|
19
14
|
return keys;
|
|
20
15
|
}
|
|
21
16
|
function resolveDynamicValue(value) {
|
|
@@ -30,8 +25,7 @@ function eventNameToJsx(name) {
|
|
|
30
25
|
return `on${name.charAt(0).toUpperCase()}${name.slice(1)}`;
|
|
31
26
|
}
|
|
32
27
|
/**
|
|
33
|
-
* Collect every element `type` reachable from `spec.root` via `children
|
|
34
|
-
* `$slot` refs.
|
|
28
|
+
* Collect every element `type` reachable from `spec.root` via `children`.
|
|
35
29
|
* A local, cycle-safe stand-in for `@json-render/codegen`'s
|
|
36
30
|
* `collectUsedComponents` — that helper's `children` walk has no visited
|
|
37
31
|
* guard and stack-overflows on a cyclic element graph, the same failure
|
|
@@ -50,7 +44,7 @@ function collectUsedComponentTypes(spec) {
|
|
|
50
44
|
if (!element) continue;
|
|
51
45
|
types.add(element.type);
|
|
52
46
|
for (const childKey of element.children ?? []) stack.push(childKey);
|
|
53
|
-
for (const slotKey of collectSlotKeys(element.
|
|
47
|
+
for (const slotKey of collectSlotKeys(element.slots)) stack.push(slotKey);
|
|
54
48
|
}
|
|
55
49
|
return types;
|
|
56
50
|
}
|
|
@@ -60,22 +54,18 @@ function renderElement(key, spec, depth, assetComponents, ancestors) {
|
|
|
60
54
|
const indent = " ".repeat(depth);
|
|
61
55
|
if (ancestors.has(key)) return `${indent}{/* cyclic reference to "${key}" omitted */}`;
|
|
62
56
|
const withSelf = new Set(ancestors).add(key);
|
|
63
|
-
const { children: _children, ...
|
|
64
|
-
const slotKeys = collectSlotKeys(
|
|
57
|
+
const { children: _children, ...propsWithoutSlots } = element.props ?? {};
|
|
58
|
+
const slotKeys = collectSlotKeys(element.slots);
|
|
65
59
|
const slotAttrs = [];
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const rendered = refs.map((r) => renderElement(r, spec, 0, assetComponents, withSelf).trim()).filter(Boolean);
|
|
74
|
-
slotAttrs.push(`${propName}={<>${rendered.join("")}</>}`);
|
|
75
|
-
}
|
|
76
|
-
} else propsWithoutSlots[propName] = propValue;
|
|
60
|
+
for (const [propName, fills] of Object.entries(element.slots ?? {})) if (fills.length === 1) {
|
|
61
|
+
const rendered = renderElement(fills[0], spec, 0, assetComponents, withSelf).trim();
|
|
62
|
+
slotAttrs.push(`${propName}={${rendered}}`);
|
|
63
|
+
} else {
|
|
64
|
+
const rendered = fills.map((r) => renderElement(r, spec, 0, assetComponents, withSelf).trim()).filter(Boolean);
|
|
65
|
+
slotAttrs.push(`${propName}={<>${rendered.join("")}</>}`);
|
|
66
|
+
}
|
|
77
67
|
const assetForm = assetJsxForm(element.type, assetComponents);
|
|
78
|
-
const tag = assetForm?.tag ?? element.type;
|
|
68
|
+
const tag = assetForm?.tag ?? jsxIdentifier(element.type);
|
|
79
69
|
const nameAttr = assetForm?.nameAttr ? `name="${assetForm.nameAttr}"` : "";
|
|
80
70
|
if (assetForm?.nameAttr) delete propsWithoutSlots.name;
|
|
81
71
|
const staticAttrs = Object.keys(propsWithoutSlots).length > 0 ? serializeProps(propsWithoutSlots) : "";
|
|
@@ -110,8 +100,7 @@ function renderElement(key, spec, depth, assetComponents, ancestors) {
|
|
|
110
100
|
const textContent = typeof rawChildren === "string" || typeof rawChildren === "number" ? String(rawChildren) : null;
|
|
111
101
|
const dynamicChildren = isDynamicValue(rawChildren) ? `{${resolveDynamicValue(rawChildren)}}` : null;
|
|
112
102
|
const inlineContent = textContent ?? dynamicChildren;
|
|
113
|
-
const
|
|
114
|
-
const childKeys = [...new Set([...element.children ?? [], ...bodySlotKeys])].filter((k) => !slotKeys.has(k));
|
|
103
|
+
const childKeys = (element.children ?? []).filter((k) => !slotKeys.has(k));
|
|
115
104
|
const hasChildren = childKeys.length > 0 || inlineContent !== null;
|
|
116
105
|
let jsxLine;
|
|
117
106
|
if (!hasChildren) jsxLine = `${indent}<${tag}${propsStr} />`;
|
|
@@ -141,7 +130,7 @@ function specToJsx(spec, options) {
|
|
|
141
130
|
imports: []
|
|
142
131
|
};
|
|
143
132
|
const assetComponents = options?.assetComponents;
|
|
144
|
-
const sortedImports = [...new Set([...collectUsedComponentTypes(spec)].map((type) => assetJsxForm(type, assetComponents)?.importName ?? type))].sort();
|
|
133
|
+
const sortedImports = [...new Set([...collectUsedComponentTypes(spec)].map((type) => assetJsxForm(type, assetComponents)?.importName ?? jsxIdentifier(type)))].sort();
|
|
145
134
|
const jsxTree = renderElement(spec.root, spec, 0, assetComponents, /* @__PURE__ */ new Set());
|
|
146
135
|
if (options?.omitImports) return {
|
|
147
136
|
jsx: jsxTree,
|