view-contracts 0.5.11 → 0.5.12
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/cli-contract.yaml +1 -1
- package/dist/preview.mjs +140 -132
- package/dist/preview.mjs.map +4 -4
- package/dist/types/renderers/compose/lowering/lowerToCompose.d.ts +2 -1
- package/dist/types/renderers/swiftui/lowering/lowerToSwiftUI.d.ts +2 -1
- package/dist/types/src/compiler/jsxToIr.d.ts +2 -1
- package/dist/types/src/compiler/viewPartial.d.ts +2 -0
- package/dist/types/src/ir/types.d.ts +8 -0
- package/dist/types/src/lib/rendererPaths.d.ts +2 -0
- package/dist/types/src/renderer/native/optionalGate.d.ts +33 -0
- package/dist/view-contracts.bundle.mjs +202 -194
- package/dist/view-contracts.bundle.mjs.map +4 -4
- package/docs/cli-reference.md +1 -1
- package/package.json +1 -1
- package/renderers/compose/README.md +1 -0
- package/renderers/compose/lowering/lowerToCompose.ts +54 -25
- package/renderers/compose/renderComponents.ts +6 -18
- package/renderers/react/renderComponents.ts +2 -8
- package/renderers/swiftui/README.md +1 -0
- package/renderers/swiftui/lowering/lowerToSwiftUI.ts +34 -13
- package/renderers/swiftui/renderComponents.ts +6 -18
- package/spec/ui-dsl.schema.json +17 -0
|
@@ -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;
|
|
@@ -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,6 +6,8 @@ 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
|
}
|
|
10
12
|
export declare function parseViewImports(sourceFile: ts.SourceFile, fileDir: string): Map<string, string>;
|
|
11
13
|
export declare function findViewPartialInSource(sourceFile: ts.SourceFile, exportName: string): ParsedViewPartial | null;
|
|
@@ -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 {
|
|
@@ -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;
|