view-contracts 0.5.11 → 0.5.13

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.
Files changed (36) hide show
  1. package/cli-contract.yaml +1 -1
  2. package/dist/preview.mjs +148 -140
  3. package/dist/preview.mjs.map +4 -4
  4. package/dist/types/renderers/compose/lowering/lowerToCompose.d.ts +2 -1
  5. package/dist/types/renderers/react/dataAttributes.d.ts +2 -0
  6. package/dist/types/renderers/swiftui/lowering/lowerToSwiftUI.d.ts +2 -1
  7. package/dist/types/src/compiler/jsxToIr.d.ts +2 -1
  8. package/dist/types/src/compiler/viewPartial.d.ts +3 -1
  9. package/dist/types/src/config.d.ts +1 -3
  10. package/dist/types/src/dsl/types.d.ts +2 -3
  11. package/dist/types/src/ir/types.d.ts +8 -0
  12. package/dist/types/src/lib/projectPath.d.ts +2 -0
  13. package/dist/types/src/lib/rendererPaths.d.ts +2 -0
  14. package/dist/types/src/renderer/native/optionalGate.d.ts +33 -0
  15. package/dist/types/src/scaffold/standalone.d.ts +2 -2
  16. package/dist/types/src/schema/dsl-catalog.d.ts +1 -0
  17. package/dist/types/src/schema/loadSchema.d.ts +7 -0
  18. package/dist/types/src/schema/types.d.ts +31 -0
  19. package/dist/types/src/validate/validateViewProps.d.ts +0 -3
  20. package/dist/view-contracts.bundle.mjs +214 -200
  21. package/dist/view-contracts.bundle.mjs.map +4 -4
  22. package/docs/cli-reference.md +1 -1
  23. package/package.json +1 -1
  24. package/renderers/compose/README.md +1 -0
  25. package/renderers/compose/lowering/lowerToCompose.ts +54 -25
  26. package/renderers/compose/renderComponents.ts +6 -18
  27. package/renderers/react/dataAttributes.ts +4 -0
  28. package/renderers/react/lowering/lowerToJsx.ts +45 -11
  29. package/renderers/react/preview/vocabulary.tsx +7 -3
  30. package/renderers/react/renderComponents.ts +2 -8
  31. package/renderers/swiftui/README.md +1 -0
  32. package/renderers/swiftui/lowering/lowerToSwiftUI.ts +34 -13
  33. package/renderers/swiftui/renderComponents.ts +6 -18
  34. package/spec/ui-dsl.schema.json +263 -0
  35. package/src/dsl/types.ts +2 -3
  36. package/renderers/react/templates/handlers.ts.hbs +0 -4
@@ -1,7 +1,8 @@
1
1
  import type { ThemeIR, TokenIR } from '../../../src/design/types.js';
2
+ import { type OptionalGateState } from '../../../src/renderer/native/optionalGate.js';
2
3
  import type { IrNode } from '../../../src/ir/types.js';
3
4
  import type { ComposeElementMap } from '../elementMap.js';
4
- export interface ComposeRenderContext {
5
+ export interface ComposeRenderContext extends OptionalGateState {
5
6
  map: ComposeElementMap;
6
7
  theme: ThemeIR;
7
8
  tokens: TokenIR;
@@ -0,0 +1,2 @@
1
+ /** HTML attribute name for a `data={{ ... }}` key: `testId` → `data-test-id`. */
2
+ export declare function dataAttributeName(key: string): string;
@@ -1,7 +1,8 @@
1
1
  import type { ThemeIR, TokenIR } from '../../../src/design/types.js';
2
+ import { type OptionalGateState } from '../../../src/renderer/native/optionalGate.js';
2
3
  import type { IrNode } from '../../../src/ir/types.js';
3
4
  import type { SwiftUIElementMap } from '../elementMap.js';
4
- export interface SwiftUIRenderContext {
5
+ export interface SwiftUIRenderContext extends OptionalGateState {
5
6
  map: SwiftUIElementMap;
6
7
  theme: ThemeIR;
7
8
  tokens: TokenIR;
@@ -1,4 +1,4 @@
1
- import type { IrBinding, IrNode } from '../ir/types.js';
1
+ import type { IrBinding, IrNode, IrPropDecl } from '../ir/types.js';
2
2
  export interface CompileContext {
3
3
  vmName: string;
4
4
  scopes: string[];
@@ -13,6 +13,7 @@ export interface CompileContext {
13
13
  export interface ParsedViewPartialResult {
14
14
  exportName: string;
15
15
  propsType?: string;
16
+ propDecls?: IrPropDecl[];
16
17
  propNames: string[];
17
18
  root: IrNode;
18
19
  errors: string[];
@@ -6,8 +6,10 @@ export interface ParsedViewPartial {
6
6
  propNames: string[];
7
7
  /** Raw TypeScript type from view<T>() generic, if present. */
8
8
  propsType?: string;
9
+ /** The view<T>() generic type node, if present. */
10
+ propsTypeNode?: ts.TypeNode;
9
11
  }
12
+ /** Named value imports from relative modules — the only way a view() partial is imported. */
10
13
  export declare function parseViewImports(sourceFile: ts.SourceFile, fileDir: string): Map<string, string>;
11
14
  export declare function findViewPartialInSource(sourceFile: ts.SourceFile, exportName: string): ParsedViewPartial | null;
12
15
  export declare function loadViewPartial(filePath: string, exportName: string): ParsedViewPartial | null;
13
- export declare function resolveViewModulePath(importPath: string, fileDir: string): string;
@@ -66,12 +66,10 @@ export declare function loadConfig(configPath: string): Promise<ViewContractsCon
66
66
  export declare function normalizeConfig(configPath: string, config: ViewContractsConfig): ViewContractsConfig;
67
67
  export declare function loadBindings(bindingsPath: string): Promise<ViewBindingsFile>;
68
68
  export declare function reactOutputPath(config: ViewContractsConfig, view: ViewBinding): string;
69
+ export declare function reactRuntimePath(config: ViewContractsConfig): string;
69
70
  export declare function projectRoot(configPath: string): string;
70
71
  export declare function themeCssPath(_configPath: string, config: ViewContractsConfig): string;
71
72
  export declare function requireDesignPaths(config: ViewContractsConfig): {
72
73
  tokensPath: string;
73
74
  themePath: string;
74
75
  };
75
- export declare function runtimeImportSpecifier(_configPath: string, _config: ViewContractsConfig, outputPath: string): string;
76
- /** @deprecated Use runtimeImportSpecifier */
77
- export declare function componentsImportSpecifier(configPath: string, config: ViewContractsConfig, outputPath: string): string;
@@ -25,10 +25,9 @@ export type FieldSize = 'sm' | 'md' | 'lg';
25
25
  */
26
26
  export interface CommonProps {
27
27
  id?: string;
28
- testId?: string;
29
- ariaLabel?: string;
28
+ /** Custom data attributes; web only (`data-<kebab-key>`). */
29
+ data?: Record<string, string | number | boolean>;
30
30
  children?: ReactNode;
31
- hidden?: boolean;
32
31
  width?: number;
33
32
  minWidth?: number;
34
33
  maxWidth?: number;
@@ -14,6 +14,14 @@ export interface ViewIrDocument {
14
14
  isPartial?: boolean;
15
15
  /** TypeScript props type for partial exports (e.g. "{ items: KpiCardViewModel[] }"). */
16
16
  propsType?: string;
17
+ /** Props declared by the partial's `view<{ ... }>()` type literal; absent when the type is not a literal. */
18
+ propDecls?: IrPropDecl[];
19
+ }
20
+ export interface IrPropDecl {
21
+ name: string;
22
+ /** TypeScript type text of the prop (e.g. "KpiCardViewModel[]"). */
23
+ type: string;
24
+ optional: boolean;
17
25
  }
18
26
  export type IrNode = IrComponentNode | IrTextNode | IrMapNode | IrFragmentNode | IrBinding | IrViewRefNode;
19
27
  export interface IrComponentNode {
@@ -1,2 +1,4 @@
1
1
  /** Project-relative POSIX path for generated artifacts (no absolute paths). */
2
2
  export declare function relativeProjectPath(projectDir: string, absolutePath: string): string;
3
+ /** Relative ESM import specifier from one generated/scaffolded file to another (`.ts`/`.tsx` → `.js`). */
4
+ export declare function relImport(from: string, to: string): string;
@@ -8,6 +8,8 @@ type RendererRegistry = typeof import('../../renderers/registry.js');
8
8
  export declare function loadRendererRegistry(): Promise<RendererRegistry>;
9
9
  export declare function reactTemplatesDir(customDir?: string): string;
10
10
  export declare function reactRuntimeDir(): string;
11
+ /** Preview vocabulary stubs that `.view.tsx` files import as `@view-contracts/components`. */
12
+ export declare function reactPreviewComponentsPath(): string;
11
13
  export declare function reactStructuralCssPath(): string;
12
14
  export declare function reactElementsYamlPath(): string;
13
15
  export declare function isReactElementsYamlFile(filePath: string): boolean;
@@ -0,0 +1,33 @@
1
+ import type { IrValue } from '../../ir/types.js';
2
+ /**
3
+ * Tracks optional partial props while a native renderer lowers a partial body.
4
+ * Native targets must unwrap an optional value before passing it where a value is required;
5
+ * a node that emits one renders only when the value is present.
6
+ */
7
+ export interface OptionalGateState {
8
+ /** Optional partial props that are not unwrapped at the current render position. */
9
+ optionalProps?: Set<string>;
10
+ /** Scopes of the bindings emitted since the innermost enclosing gate started rendering. */
11
+ emittedScopes?: Set<string>;
12
+ }
13
+ /**
14
+ * Scopes (`binding.scope`) of the bindings in the given values: bindings, concat parts and
15
+ * array items. Action params are a dispatched payload, not a rendered value, and are not included.
16
+ */
17
+ export declare function bindingScopes(values: Iterable<IrValue>): Set<string>;
18
+ /** Called by a renderer's binding lowering for every binding it emits. */
19
+ export declare function recordEmittedScope(state: OptionalGateState, scope: string | undefined): void;
20
+ /**
21
+ * Renders a node whose own values reference `scopes`. When the node itself emits any of its
22
+ * optional props, it is re-rendered with those props unwrapped and passed to `wrap`, which makes
23
+ * the output conditional on them being present. Descendants gate the optional props they emit.
24
+ */
25
+ export declare function gateOptional(state: OptionalGateState, scopes: Set<string>, render: () => string, wrap: (names: string[], inner: string) => string): string;
26
+ /**
27
+ * Renders code where `shadowed` names are rebound (a map item) or where an optional value is
28
+ * passed on as-is (a view() partial argument): those names are not optional props inside, and
29
+ * the emitted bindings do not gate the enclosing node.
30
+ */
31
+ export declare function renderUngated(state: OptionalGateState, shadowed: string[], render: () => string): string;
32
+ /** Indents every non-empty line of rendered code by `prefix`. */
33
+ export declare function indentBlock(code: string, prefix: string): string;
@@ -1,2 +1,2 @@
1
- import type { ViewBindingsFile } from '../config.js';
2
- export declare function scaffoldStandaloneApp(configPath: string, bindings: ViewBindingsFile): Promise<void>;
1
+ import type { ViewBindingsFile, ViewContractsConfig } from '../config.js';
2
+ export declare function scaffoldStandaloneApp(configPath: string, config: ViewContractsConfig, bindings: ViewBindingsFile): Promise<void>;
@@ -44,6 +44,7 @@ export declare const TOKEN_CATALOG: {
44
44
  readonly imageFit: readonly ["contain", "cover", "fill", "none"];
45
45
  readonly keyboardType: readonly ["text", "number", "email", "url", "password", "tel"];
46
46
  readonly inputType: readonly ["text", "password", "email", "url", "tel"];
47
+ readonly buttonType: readonly ["button", "submit", "reset"];
47
48
  readonly clip: readonly ["none", "bounds", "shape"];
48
49
  };
49
50
  export declare const PROPERTY_CATALOG: Record<string, PropertyDef>;
@@ -0,0 +1,7 @@
1
+ import type { UiDslSchema } from './types.js';
2
+ export type { UiDslSchema } from './types.js';
3
+ export { elementProps, propertyAppliesTo } from './dsl-catalog.js';
4
+ export declare const DEFAULT_SCHEMA_PATH = "spec/ui-dsl.schema.json";
5
+ export declare function loadPackageVersion(root?: string): Promise<string>;
6
+ export declare function loadUiDslSchema(schemaPath?: string): Promise<UiDslSchema>;
7
+ export declare function allComponentNames(): string[];
@@ -0,0 +1,31 @@
1
+ export type { PropertyDef, ElementDef, LoweringMode, } from './dsl-catalog.js';
2
+ export { PROPERTY_CATALOG, ELEMENT_CATALOG, TOKEN_CATALOG } from './dsl-catalog.js';
3
+ /**
4
+ * UiDslSchema — the shape of spec/ui-dsl.schema.json (user-facing).
5
+ * Used only by the schema loader for meta-validation; program control
6
+ * decisions use dsl-catalog.ts directly.
7
+ */
8
+ export interface UiDslSchema {
9
+ tokens: Record<string, string[]>;
10
+ properties: Record<string, {
11
+ type: string | string[];
12
+ enum?: string;
13
+ description?: string;
14
+ 'x-category': string;
15
+ 'x-appliesTo'?: string[];
16
+ 'x-notes'?: string;
17
+ }>;
18
+ elements: Record<string, {
19
+ description: string;
20
+ 'x-tier': string;
21
+ 'x-category': string;
22
+ 'x-notes'?: string;
23
+ properties: Record<string, {
24
+ $ref: string;
25
+ } | Record<string, unknown>>;
26
+ _children: {
27
+ 'x-kind': string;
28
+ 'x-items'?: string[];
29
+ };
30
+ }>;
31
+ }
@@ -1,5 +1,2 @@
1
1
  import type { ViewIrDocument } from '../ir/types.js';
2
- import { type PropertyDef } from '../schema/dsl-catalog.js';
3
2
  export declare function validateViewProps(docs: Iterable<ViewIrDocument>, allowlistExtra?: string[]): Promise<void>;
4
- /** @internal Exported for tests. */
5
- export declare function isVisualProperty(def: PropertyDef | undefined): boolean;