@pwfabric/runtime 2.0.0 → 2.1.0
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/LICENSE +2 -2
- package/dist/binding/expression.js +4 -1
- package/dist/binding/expression.js.map +1 -1
- package/dist/connectors/types.d.ts +4 -2
- package/dist/connectors/types.js +4 -2
- package/dist/connectors/types.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/render/DataBoundSurfaceRenderer.d.ts +10 -0
- package/dist/render/DataBoundSurfaceRenderer.js +45 -11
- package/dist/render/DataBoundSurfaceRenderer.js.map +1 -1
- package/dist/render/data-binding-types.d.ts +13 -2
- package/dist/render/data-binding-types.js.map +1 -1
- package/dist/render/index.d.ts +3 -1
- package/dist/render/index.js +2 -1
- package/dist/render/index.js.map +1 -1
- package/dist/render/links.d.ts +50 -0
- package/dist/render/links.js +78 -0
- package/dist/render/links.js.map +1 -0
- package/dist/render/resolve-expressions.d.ts +22 -1
- package/dist/render/resolve-expressions.js +65 -5
- package/dist/render/resolve-expressions.js.map +1 -1
- package/dist/render/scoped-css.d.ts +8 -1
- package/dist/render/scoped-css.js +16 -0
- package/dist/render/scoped-css.js.map +1 -1
- package/dist/surface/expression.js +0 -1
- package/dist/surface/expression.js.map +1 -1
- package/dist/surface/output.js +1 -1
- package/dist/surface/output.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-binding-types.js","sourceRoot":"","sources":["../../src/render/data-binding-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * Data Binding Types for Surface Renderer\n *\n * Type definitions for data-bound surface rendering.\n * These types define the shape of surface JSON definitions that include\n * dataSources, state, and expression-based prop bindings.\n *\n * @module @pwfabric/runtime/render/data-binding-types\n */\n\nimport type { SurfaceDataCache } from './data-cache.js'\nimport type { Block } from '@pwfabric/core'\nimport type { RenderableSurface, SurfaceRendererProps } from './types.js'\nimport type { DataServiceConfig } from '../data/types.js'\n\n// ============================================================\n// DATA SOURCE DEFINITION (Surface JSON level)\n// ============================================================\n\n/**\n * Source kinds supported in surface JSON definitions.\n * Note: 'computed' is excluded because functions can't be serialized in JSON.\n */\nexport type SurfaceDataSourceKind = 'rest' | 'static' | 'state' | 'entity'\n\n/**\n * Data source definition within a surface JSON.\n * Unlike DataSourceDefinition from data/types, this is JSON-serializable.\n */\nexport interface SurfaceDataSourceDefinition {\n /** Unique source identifier, used as the key in expression context */\n readonly id: string\n /** Source kind */\n readonly kind: SurfaceDataSourceKind\n /** REST endpoint (may contain {{state.key}} placeholders) */\n readonly endpoint?: string\n /** HTTP method for REST sources */\n readonly method?: 'GET' | 'POST' | 'PUT' | 'DELETE'\n /** Static inline data */\n readonly staticData?: unknown\n /** Auto-refresh interval in ms (0 or undefined = no auto-refresh) */\n readonly refreshInterval?: number\n /** Optional HTTP headers to include in REST requests (e.g. Authorization) */\n readonly headers?: Readonly<Record<string, string>>\n /** Entity type to list (kind: 'entity') via the platform/entities facade */\n readonly entityType?: string\n /** Optional query for entity sources (filter/sort/pagination). String\n * leaves may carry `{{state.x}}` expressions — resolved against surface\n * state before the connector is called (see render/query-state.ts). */\n readonly query?: Readonly<Record<string, unknown>>\n /** Payload bound when the source cannot be served (connector missing /\n * failed). `__errors.<id>` stays populated alongside it. */\n readonly fallback?: unknown\n /**\n * Contract parity with `dataSourceSchema.connector`: which\n * data-plane engine serves this entity source (e.g. 'graph-lists').\n * Routed through the host-provided `ConnectorEngineRegistry` when the\n * connection is registered there; absent/unregistered = the default\n * entity facade path (today's behavior).\n */\n readonly connector?: string\n /**\n * The response property holding the list — `data`, `products`, or absent\n * when the body IS the array. Dotted paths allowed for a nested one.\n */\n readonly returns?: string\n /** world auth binding BY NAME — never credential values. */\n readonly authProviderRef?: string\n /**\n * Contract parity with `dataSourceSchema.aggregate`: ask for ONE\n * NUMBER over the collection instead of its rows. The source binds\n * `{ fn, field?, value, count }` — `{{<id>.value}}` — and is exempt from\n * the list wrap. `filter` leaves may carry `{{state.x}}` like `query`.\n */\n readonly aggregate?: {\n readonly fn: 'count' | 'sum' | 'avg'\n readonly field?: string\n readonly filter?: Readonly<Record<string, unknown>>\n }\n}\n\n// ============================================================\n// SURFACE ACTIONS\n// ============================================================\n\n/**\n * Action types that blocks can dispatch via their action prop.\n */\nexport type SurfaceActionType =\n | 'setState'\n | 'refresh'\n | 'refreshAll'\n | 'showBlock'\n | 'hideBlock'\n | 'navigate'\n\n/**\n * Action dispatched by a block (e.g. button click, tab change).\n */\nexport type SurfaceAction =\n | { readonly type: 'setState'; readonly key: string; readonly value: unknown }\n | { readonly type: 'refresh'; readonly sourceId: string }\n | { readonly type: 'refreshAll' }\n | { readonly type: 'showBlock'; readonly blockId: string }\n | { readonly type: 'hideBlock'; readonly blockId: string }\n | { readonly type: 'navigate'; readonly url: string }\n\n/**\n * What a block's `action` prop may hold: one action, or a list run in order\n * on the block's click (`block:click`) — never on its other events.\n */\nexport type BlockActionProp = SurfaceAction | readonly SurfaceAction[]\n\n/**\n * A behavior stored on a published surface — maps an event trigger to one or more actions.\n * The `event` field accepts canonical colon form (`block:click`) or legacy dot form\n * (`surface.load`) — normalized at match time by `canonicalizeEventType`.\n */\nexport interface RuntimeBehavior {\n readonly id: string\n readonly event: string\n readonly targetBlockId?: string\n readonly actions: readonly SurfaceAction[]\n}\n\n// ============================================================\n// DATA-BOUND SURFACE\n// ============================================================\n\n/**\n * Surface definition extended with data binding capabilities.\n * This is the shape of a surface JSON that uses live data.\n */\nexport interface DataBoundSurface {\n /**\n * Stable surface id — SurfaceRenderer's render scope.\n *\n * Omitted from this type originally, which made the drop invisible: the\n * renderer decomposes the surface into blocks/appearance/capabilities and\n * rebuilds it, and a field the type never had could not survive the rebuild.\n * Downstream, `[data-pw-surface]` rendered with an EMPTY value and every\n * per-surface rule (dark theme, visibility, interaction states) fell back to\n * the value-less selector shared by every surface in the document — the exact\n * collision the scoping was added to prevent.\n */\n readonly id?: string\n /** Block composition */\n readonly blocks: readonly Block[]\n /** ui-appearance atom reference (theme + layout + styleVariables consolidated). */\n readonly appearance?: RenderableSurface['appearance']\n /** capability list — `platform/persistence` carries dataSources + initialState in its config. */\n readonly capabilities?: RenderableSurface['capabilities']\n}\n\n// ============================================================\n// RENDERER PROPS\n// ============================================================\n\n/**\n * Props for DataBoundSurfaceRenderer.\n * Extends SurfaceRendererProps but accepts a DataBoundSurface.\n */\nexport interface DataBoundSurfaceRendererProps extends Omit<SurfaceRendererProps, 'surface'> {\n /** Surface definition with optional dataSources and state */\n readonly surface: DataBoundSurface\n /** Stored behaviors to execute when their trigger event fires on the bus */\n readonly behaviors?: readonly RuntimeBehavior[]\n /**\n * Intercept a `navigate` action before the default `window.location.assign`\n * fallback runs. Return `true` to signal the host handled it (e.g. swapped\n * to a sibling page in place, connected-preview style) — the default hard\n * navigation is skipped. Return `false`/`undefined` to fall through to the\n * default behavior.\n */\n readonly onNavigateAction?: (url: string) => boolean\n /**\n * What to render while the initial `fetchAllSources` pass is in flight.\n *\n * - `'gate'` (default) — the historical behavior: an all-or-nothing\n * \"Loading data...\" placeholder replaces the ENTIRE block tree until the\n * first fetch settles. Kept as the default so existing consumers (e.g.\n * published `/s/` pages) are byte-identical.\n * - `'immediate'` — render the block tree right away; expressions bound to\n * still-loading sources resolve to `undefined` (never a literal `{{…}}`\n * string — path expressions always evaluate successfully) and fill in as\n * each source lands. Static chrome (navbar, headings, footer) is visible\n * from the first frame. Pair with the `__loading.<sourceId>` /\n * `__anyLoading` expression keys to drive per-widget skeletons.\n */\n readonly loadingStrategy?: 'gate' | 'immediate'\n /**\n * Yesterday's rows while today's load. A source whose key (see\n * `dataSourceCacheKey`) is present is seeded from the cache on the first\n * frame and still re-fetched; the fresh result replaces the seed and is\n * written back. Pairs naturally with `loadingStrategy: 'immediate'`.\n */\n readonly dataCache?: SurfaceDataCache\n\n /**\n * Configuration for the DataService this renderer creates.\n *\n * IT WAS NEVER PASSED. `<DataCapabilityProvider>` was mounted bare, so the\n * service was built with no config — which means `getAccessToken` was always\n * undefined and every `authProviderRef` on every rest source resolved to\n * nobody. The field parsed, travelled and was read by a resolver that could\n * not exist. Threading it is the repair; it is also what lets a host say\n * which origin is its own, so our API can be called with a cookie and\n * nobody else's can.\n */\n readonly dataServiceConfig?: DataServiceConfig\n}\n"]}
|
|
1
|
+
{"version":3,"file":"data-binding-types.js","sourceRoot":"","sources":["../../src/render/data-binding-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * Data Binding Types for Surface Renderer\n *\n * Type definitions for data-bound surface rendering.\n * These types define the shape of surface JSON definitions that include\n * dataSources, state, and expression-based prop bindings.\n *\n * @module @pwfabric/runtime/render/data-binding-types\n */\n\nimport type { SurfaceDataCache } from './data-cache.js'\nimport type { LinkHref } from './links.js'\nimport type { Block } from '@pwfabric/core'\nimport type { RenderableSurface, SurfaceRendererProps } from './types.js'\nimport type { DataServiceConfig } from '../data/types.js'\n\n// ============================================================\n// DATA SOURCE DEFINITION (Surface JSON level)\n// ============================================================\n\n/**\n * Source kinds supported in surface JSON definitions.\n * Note: 'computed' is excluded because functions can't be serialized in JSON.\n */\nexport type SurfaceDataSourceKind = 'rest' | 'static' | 'state' | 'entity'\n\n/**\n * Data source definition within a surface JSON.\n * Unlike DataSourceDefinition from data/types, this is JSON-serializable.\n */\nexport interface SurfaceDataSourceDefinition {\n /** Unique source identifier, used as the key in expression context */\n readonly id: string\n /** Source kind */\n readonly kind: SurfaceDataSourceKind\n /** REST endpoint (may contain {{state.key}} placeholders) */\n readonly endpoint?: string\n /** HTTP method for REST sources */\n readonly method?: 'GET' | 'POST' | 'PUT' | 'DELETE'\n /** Static inline data */\n readonly staticData?: unknown\n /** Auto-refresh interval in ms (0 or undefined = no auto-refresh) */\n readonly refreshInterval?: number\n /** Optional HTTP headers to include in REST requests (e.g. Authorization) */\n readonly headers?: Readonly<Record<string, string>>\n /** Entity type to list (kind: 'entity') via the platform/entities facade */\n readonly entityType?: string\n /** Optional query for entity sources (filter/sort/pagination). String\n * leaves may carry `{{state.x}}` expressions — resolved against surface\n * state before the connector is called (see render/query-state.ts). */\n readonly query?: Readonly<Record<string, unknown>>\n /** Payload bound when the source cannot be served (connector missing /\n * failed). `__errors.<id>` stays populated alongside it. */\n readonly fallback?: unknown\n /**\n * Contract parity with `dataSourceSchema.connector`: which\n * data-plane engine serves this entity source (e.g. 'graph-lists').\n * Routed through the host-provided `ConnectorEngineRegistry` when the\n * connection is registered there; absent/unregistered = the host's\n * entity facade, when it provides one. Absent means the app's own records\n * of `entityType` (data-protocol §2.2) — the reference runner serves those\n * from the app's record endpoints, never from a default connection.\n */\n readonly connector?: string\n /**\n * The response property holding the list — `data`, `products`, or absent\n * when the body IS the array. Dotted paths allowed for a nested one.\n */\n readonly returns?: string\n /** world auth binding BY NAME — never credential values. */\n readonly authProviderRef?: string\n /**\n * Contract parity with `dataSourceSchema.aggregate`: ask for ONE\n * NUMBER over the collection instead of its rows. The source binds\n * `{ fn, field?, value, count }` — `{{<id>.value}}` — and is exempt from\n * the list wrap. `filter` leaves may carry `{{state.x}}` like `query`.\n */\n readonly aggregate?: {\n readonly fn: 'count' | 'sum' | 'avg'\n readonly field?: string\n readonly filter?: Readonly<Record<string, unknown>>\n }\n}\n\n// ============================================================\n// SURFACE ACTIONS\n// ============================================================\n\n/**\n * Action types that blocks can dispatch via their action prop.\n */\nexport type SurfaceActionType =\n | 'setState'\n | 'refresh'\n | 'refreshAll'\n | 'showBlock'\n | 'hideBlock'\n | 'navigate'\n\n/**\n * Action dispatched by a block (e.g. button click, tab change).\n */\nexport type SurfaceAction =\n | { readonly type: 'setState'; readonly key: string; readonly value: unknown }\n | { readonly type: 'refresh'; readonly sourceId: string }\n | { readonly type: 'refreshAll' }\n | { readonly type: 'showBlock'; readonly blockId: string }\n | { readonly type: 'hideBlock'; readonly blockId: string }\n | { readonly type: 'navigate'; readonly url: string }\n\n/**\n * What a block's `action` prop may hold: one action, or a list run in order\n * on the block's click (`block:click`) — never on its other events.\n */\nexport type BlockActionProp = SurfaceAction | readonly SurfaceAction[]\n\n/**\n * A behavior stored on a published surface — maps an event trigger to one or more actions.\n * The `event` field accepts canonical colon form (`block:click`) or legacy dot form\n * (`surface.load`) — normalized at match time by `canonicalizeEventType`.\n */\nexport interface RuntimeBehavior {\n readonly id: string\n readonly event: string\n /** The block whose event it hears. A template id inside a `repeat` names every copy (`<id>--<index>`). */\n readonly targetBlockId?: string\n readonly actions: readonly SurfaceAction[]\n}\n\n// ============================================================\n// DATA-BOUND SURFACE\n// ============================================================\n\n/**\n * Surface definition extended with data binding capabilities.\n * This is the shape of a surface JSON that uses live data.\n */\nexport interface DataBoundSurface {\n /**\n * Stable surface id — SurfaceRenderer's render scope.\n *\n * Omitted from this type originally, which made the drop invisible: the\n * renderer decomposes the surface into blocks/appearance/capabilities and\n * rebuilds it, and a field the type never had could not survive the rebuild.\n * Downstream, `[data-pw-surface]` rendered with an EMPTY value and every\n * per-surface rule (dark theme, visibility, interaction states) fell back to\n * the value-less selector shared by every surface in the document — the exact\n * collision the scoping was added to prevent.\n */\n readonly id?: string\n /** Block composition */\n readonly blocks: readonly Block[]\n /** ui-appearance atom reference (theme + layout + styleVariables consolidated). */\n readonly appearance?: RenderableSurface['appearance']\n /** capability list — `platform/persistence` carries dataSources + initialState in its config. */\n readonly capabilities?: RenderableSurface['capabilities']\n}\n\n// ============================================================\n// RENDERER PROPS\n// ============================================================\n\n/**\n * Props for DataBoundSurfaceRenderer.\n * Extends SurfaceRendererProps but accepts a DataBoundSurface.\n */\nexport interface DataBoundSurfaceRendererProps extends Omit<SurfaceRendererProps, 'surface'> {\n /** Surface definition with optional dataSources and state */\n readonly surface: DataBoundSurface\n /** Stored behaviors to execute when their trigger event fires on the bus */\n readonly behaviors?: readonly RuntimeBehavior[]\n /**\n * Intercept a `navigate` action before the default `window.location.assign`\n * fallback runs. Return `true` to signal the host handled it (e.g. swapped\n * to a sibling page in place, connected-preview style) — the default hard\n * navigation is skipped. Return `false`/`undefined` to fall through to the\n * default behavior.\n */\n readonly onNavigateAction?: (url: string) => boolean\n /**\n * What to render while the initial `fetchAllSources` pass is in flight.\n *\n * - `'gate'` (default) — the historical behavior: an all-or-nothing\n * \"Loading data...\" placeholder replaces the ENTIRE block tree until the\n * first fetch settles. Kept as the default so existing consumers (e.g.\n * published `/s/` pages) are byte-identical.\n * - `'immediate'` — render the block tree right away; expressions bound to\n * still-loading sources resolve to `undefined` (never a literal `{{…}}`\n * string — path expressions always evaluate successfully) and fill in as\n * each source lands. Static chrome (navbar, headings, footer) is visible\n * from the first frame. Pair with the `__loading.<sourceId>` /\n * `__anyLoading` expression keys to drive per-widget skeletons.\n */\n readonly loadingStrategy?: 'gate' | 'immediate'\n /**\n * Yesterday's rows while today's load. A source whose key (see\n * `dataSourceCacheKey`) is present is seeded from the cache on the first\n * frame and still re-fetched; the fresh result replaces the seed and is\n * written back. Pairs naturally with `loadingStrategy: 'immediate'`.\n */\n readonly dataCache?: SurfaceDataCache\n /**\n * How the host writes an in-app link (`/session?id=4` → `#/session?id=4`).\n * A host rewrites the links it can read before render; a link whose page is\n * an expression (`href: \"{{item.url}}\"`) it leaves as written, and the\n * renderer passes its resolved value through this. See render/links.ts.\n */\n readonly linkHref?: LinkHref\n\n /**\n * Configuration for the DataService this renderer creates.\n *\n * IT WAS NEVER PASSED. `<DataCapabilityProvider>` was mounted bare, so the\n * service was built with no config — which means `getAccessToken` was always\n * undefined and every `authProviderRef` on every rest source resolved to\n * nobody. The field parsed, travelled and was read by a resolver that could\n * not exist. Threading it is the repair; it is also what lets a host say\n * which origin is its own, so our API can be called with a cookie and\n * nobody else's can.\n */\n readonly dataServiceConfig?: DataServiceConfig\n}\n"]}
|
package/dist/render/index.d.ts
CHANGED
|
@@ -24,7 +24,9 @@ export { DataBoundSurfaceRenderer, surfaceNeedsDataBinding, blockActionsOf } fro
|
|
|
24
24
|
export { resolveEndpoint, encodeEndpointValue } from './endpoint.js';
|
|
25
25
|
export { dataSourceCacheKey } from './data-cache.js';
|
|
26
26
|
export type { SurfaceDataCache } from './data-cache.js';
|
|
27
|
-
export { resolveBlockExpressions, resolveString } from './resolve-expressions.js';
|
|
27
|
+
export { literalPropsOf, resolveBlockExpressions, resolveString, type LiteralProps } from './resolve-expressions.js';
|
|
28
|
+
export { isHrefKey, isLinkMember, isExpressionLink, safeDataLink } from './links.js';
|
|
29
|
+
export type { LinkHref } from './links.js';
|
|
28
30
|
export { BlockErrorBoundary } from './BlockErrorBoundary.js';
|
|
29
31
|
export type { EntitlementContextValue, EntitlementProviderProps, GatedBlockPlaceholderProps, } from './capability-gate.js';
|
|
30
32
|
export { EntitlementProvider, useEntitlements, GatedBlockPlaceholder } from './capability-gate.js';
|
package/dist/render/index.js
CHANGED
|
@@ -36,7 +36,8 @@ export { resolveAppearanceDarkVars, resolveAppearanceKeyframes } from './appeara
|
|
|
36
36
|
export { DataBoundSurfaceRenderer, surfaceNeedsDataBinding, blockActionsOf } from './DataBoundSurfaceRenderer.js';
|
|
37
37
|
export { resolveEndpoint, encodeEndpointValue } from './endpoint.js';
|
|
38
38
|
export { dataSourceCacheKey } from './data-cache.js';
|
|
39
|
-
export { resolveBlockExpressions, resolveString } from './resolve-expressions.js';
|
|
39
|
+
export { literalPropsOf, resolveBlockExpressions, resolveString } from './resolve-expressions.js';
|
|
40
|
+
export { isHrefKey, isLinkMember, isExpressionLink, safeDataLink } from './links.js';
|
|
40
41
|
// Block Error Boundary (crash isolation)
|
|
41
42
|
export { BlockErrorBoundary } from './BlockErrorBoundary.js';
|
|
42
43
|
export { EntitlementProvider, useEntitlements, GatedBlockPlaceholder } from './capability-gate.js';
|
package/dist/render/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/render/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAuBH,aAAa;AACb,OAAO,EAC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CAAA;AACjH,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEpD,OAAO,EAAE,uBAAuB,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/render/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAuBH,aAAa;AACb,OAAO,EACL,eAAe,EACf,aAAa,EACb,WAAW,EACX,aAAa,EACb,eAAe,GAChB,MAAM,eAAe,CAAA;AAEtB,qDAAqD;AACrD,wEAAwE;AACxE,yEAAyE;AACzE,uCAAuC;AAEvC,kBAAkB;AAClB,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAExD,uBAAuB;AACvB,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,EACnB,uBAAuB,EACvB,WAAW,GACZ,MAAM,iBAAiB,CAAA;AAExB,2DAA2D;AAC3D,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,qBAAqB,CAAA;AAE5B,wDAAwD;AACxD,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAElE,qEAAqE;AACrE,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,GAC1B,MAAM,6BAA6B,CAAA;AAEpC,yEAAyE;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAEtD,yEAAyE;AACzE,OAAO,EACL,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,2BAA2B,CAAA;AAElC,8EAA8E;AAC9E,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAElF,qEAAqE;AACrE,OAAO,EACL,WAAW,EACX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EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAEtD,8CAA8C;AAC9C,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAEjF,oFAAoF;AACpF,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAG9E,4DAA4D;AAC5D,OAAO,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAA;AAK3F,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,yBAAyB,EACzB,iBAAiB,GAClB,MAAM,sBAAsB,CAAA","sourcesContent":["/**\n * Surface Renderer Module\n *\n * Phase 2A.1: Surface-to-React rendering infrastructure\n *\n * @module @pwfabric/runtime/render\n */\n\n// Types\nexport type {\n BlockComponentProps,\n BlockComponent,\n BlockComponentRegistry,\n CapabilityProvider,\n BlockContext,\n SurfaceEventType,\n SurfaceEvent,\n SurfaceRendererProps,\n BlockRendererProps,\n RenderResult,\n RenderableSurface,\n CapabilityType,\n ImageAdapter,\n ImageAdapterProps,\n BlockWrapperProps,\n BlockWrapperRenderArgs,\n BlockInteractionMode,\n} from './types.js'\n\n// Components\nexport {\n SurfaceRenderer,\n BlockRenderer,\n getBlockIds,\n findBlockById,\n updateBlockById,\n} from './renderer.js'\n\n// legacy first-party `*Block` component re-exports +\n// `defaultBlockComponents` retired. Components flow through the install\n// pipeline (pwpack publish → CDN bundle → BlockModuleLoader); the static\n// re-exports that lived here are gone.\n\n// Theme utilities\nexport { surfaceThemeToCSS } from './theme-utils.js'\nexport { deriveDarkTheme } from './derive-dark-theme.js'\n\n// Responsive utilities\nexport {\n resolveResponsiveValue,\n resolveSpanAtBreakpoint,\n getColumnsAtBreakpoint,\n getBreakpointForWidth,\n resolveBlockLayout,\n resolveMeasureStyle,\n resolveSurfaceRootStyle,\n useViewport,\n} from './responsive.js'\n\n// Per-breakpoint visibility (hideOn/showOn) CSS generation\nexport {\n collectVisibilityCss,\n blockVisibilityCss,\n resolveHiddenBreakpoints,\n} from './visibility-css.js'\n\n// Interaction-state (hover/active/focus) CSS generation\nexport { collectStatesCss, blockStatesCss } from './states-css.js'\n\n// Conditional-state (aria/data/disabled/checked/:has) CSS generation\nexport {\n collectConditionalStatesCss,\n blockConditionalStatesCss,\n} from './conditional-states-css.js'\n\n// Surface keyframe registry (appearance.config.keyframes) CSS generation\nexport { buildKeyframesCss } from './keyframes-css.js'\n\n// Per-prop responsive style (block.style breakpoint maps) CSS generation\nexport {\n collectResponsiveStyleCss,\n blockResponsiveStyleCss,\n} from './responsive-style-css.js'\n\n// Group-hover (block.groupRoot + descendant block.groupStates) CSS generation\nexport { collectGroupStatesCss, blockGroupStatesCss } from './group-states-css.js'\n\n// Shared scoped-CSS helpers (used by the per-block collectors above)\nexport {\n cssEscapeId,\n camelToKebab,\n blockIdAttr,\n blockSelector,\n collectScopedCss,\n} from './scoped-css.js'\n\n// Dark theme variant CSS generation + resolver\nexport { buildDarkThemeCss } from './dark-theme-css.js'\nexport { resolveAppearanceDarkVars, resolveAppearanceKeyframes } from './appearance-resolver.js'\n\n// Data-bound rendering\nexport type {\n SurfaceDataSourceKind,\n SurfaceDataSourceDefinition,\n SurfaceActionType,\n SurfaceAction,\n BlockActionProp,\n DataBoundSurface,\n DataBoundSurfaceRendererProps,\n} from './data-binding-types.js'\n\nexport { DataBoundSurfaceRenderer, surfaceNeedsDataBinding, blockActionsOf } from './DataBoundSurfaceRenderer.js'\nexport { resolveEndpoint, encodeEndpointValue } from './endpoint.js'\nexport { dataSourceCacheKey } from './data-cache.js'\nexport type { SurfaceDataCache } from './data-cache.js'\nexport { literalPropsOf, resolveBlockExpressions, resolveString, type LiteralProps } from './resolve-expressions.js'\nexport { isHrefKey, isLinkMember, isExpressionLink, safeDataLink } from './links.js'\nexport type { LinkHref } from './links.js'\n\n// Block Error Boundary (crash isolation)\nexport { BlockErrorBoundary } from './BlockErrorBoundary.js'\n\n// Capability Gate (Entitlement enforcement)\nexport type {\n EntitlementContextValue,\n EntitlementProviderProps,\n GatedBlockPlaceholderProps,\n} from './capability-gate.js'\nexport { EntitlementProvider, useEntitlements, GatedBlockPlaceholder } from './capability-gate.js'\n\n// Dynamic Artifact Loading\nexport { BlockModuleLoader } from './dynamic-block-loader.js'\nexport type { DynamicBlockWrapperProps } from './DynamicBlockWrapper.js'\nexport { DynamicBlockWrapper } from './DynamicBlockWrapper.js'\nexport type {\n DynamicArtifactContextValue,\n DynamicArtifactProviderProps,\n} from './dynamic-artifact-context.js'\nexport {\n DynamicArtifactProvider,\n preloadDynamicBlocks,\n useDynamicBlocks,\n useDynamicStarters,\n} from './dynamic-artifact-context.js'\n\n// Surface event protocol\nexport { createSurfaceEventBus } from './surface-event-bus.js'\nexport { SurfaceEventContext } from './surface-event-context.js'\nexport { useSurfaceEvents } from './hooks/useSurfaceEvents.js'\n\n// BehaviorSurfaceProvider — runtime surface wiring\nexport type { BehaviorSurfaceProviderProps } from './BehaviorSurfaceProvider.js'\nexport { BehaviorSurfaceProvider } from './BehaviorSurfaceProvider.js'\nexport { SurfaceIdContext } from './surface-id-context.js'\nexport { useSurfaceId } from './hooks/useSurfaceId.js'\n\n// EntityFacade → Surface Renderer integration\nexport { EntityFacadeContext, useEntityFacade } from './entity-facade-context.js'\n\n// What the data-bound path has currently bound, by source id (form writer reads it)\nexport { SurfaceDataContext, useSurfaceData } from './surface-data-context.js'\nexport type { SurfaceData } from './surface-data-context.js'\n\n// Connections context (world connections + engine registry)\nexport { SurfaceConnectionsContext, useSurfaceConnections } from './connections-context.js'\n\n// Shell × body: SPLIT shell selection, projected onto the URL so a selected\n// record can be linked to and the Back button undoes the selection.\nexport type { ShellSelectionStore, ShellSelectionOptions, ShellSelectionProviderProps } from './shell-selection.js'\nexport {\n ShellSelectionContext,\n ShellSelectionProvider,\n createShellSelectionStore,\n useShellSelection,\n} from './shell-selection.js'\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which values in a page are links to the app's pages.
|
|
3
|
+
*
|
|
4
|
+
* A host turns an authored page path (`/about`, `/session?id={{item.id}}`)
|
|
5
|
+
* into its router's form (`#/about`, `<base>/about`) before the page renders.
|
|
6
|
+
* It cannot do that for a link whose value starts with an expression —
|
|
7
|
+
* `{{item.url}}` — because which page it names is only known once the data is
|
|
8
|
+
* in: rewritten as written it became `#/{{item.url}}`, and then
|
|
9
|
+
* `#//session?id=…`, a page that does not exist. Such a link is left as
|
|
10
|
+
* written for the host and rewritten by the renderer when its value is known
|
|
11
|
+
* (`linkHref`, see resolve-expressions).
|
|
12
|
+
*
|
|
13
|
+
* One rule for both sides, so the host and the renderer cannot disagree on
|
|
14
|
+
* which value is a link.
|
|
15
|
+
*
|
|
16
|
+
* @module @pwfabric/runtime/render/links
|
|
17
|
+
*/
|
|
18
|
+
/** Turns a resolved in-app path into the active router's href. */
|
|
19
|
+
export type LinkHref = (href: string) => string;
|
|
20
|
+
/**
|
|
21
|
+
* Which prop keys carry a link. `href` is the obvious one; the pack also
|
|
22
|
+
* names links by role — a navbar's `ctaHref`, a card's `linkHref`. A key
|
|
23
|
+
* naming a FIELD that holds a link (`ctaHrefField`) is not a link.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isHrefKey(key: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* A member of `owner` that goes to a page: a `…Href` prop, a form binding's
|
|
28
|
+
* `successRedirect`, a `navigate` action's `url`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isLinkMember(key: string, owner: Readonly<Record<string, unknown>>): boolean;
|
|
31
|
+
/** A link whose page is an expression: known only when the data is. */
|
|
32
|
+
export declare function isExpressionLink(value: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* The scheme a browser will read from `url`, lower-cased, or null when it has
|
|
35
|
+
* none. A browser's URL parser DELETES tabs, newlines and other control
|
|
36
|
+
* characters before it reads the scheme, so `java\tscript:` is a `javascript:`
|
|
37
|
+
* URL; the scheme is judged on the string with them removed (`readableUrl`).
|
|
38
|
+
*/
|
|
39
|
+
export declare function urlSchemeOf(url: string): string | null;
|
|
40
|
+
/** `url` as the browser parses it: without whitespace and control characters. */
|
|
41
|
+
export declare function readableUrl(url: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* What a link whose value came from data may be: a root-relative path (`/x`,
|
|
44
|
+
* which the host then writes for its router), a fragment (`#x`), or an
|
|
45
|
+
* absolute URL with an allowed scheme. Anything else — `javascript:`,
|
|
46
|
+
* `data:`, a protocol-relative `//host` or `/\host`, a bare relative path — is
|
|
47
|
+
* `undefined`, and the link gets no href. Data is not the author: an author's
|
|
48
|
+
* literal link is checked when the page is validated; a row's value never is.
|
|
49
|
+
*/
|
|
50
|
+
export declare function safeDataLink(href: string): string | undefined;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which values in a page are links to the app's pages.
|
|
3
|
+
*
|
|
4
|
+
* A host turns an authored page path (`/about`, `/session?id={{item.id}}`)
|
|
5
|
+
* into its router's form (`#/about`, `<base>/about`) before the page renders.
|
|
6
|
+
* It cannot do that for a link whose value starts with an expression —
|
|
7
|
+
* `{{item.url}}` — because which page it names is only known once the data is
|
|
8
|
+
* in: rewritten as written it became `#/{{item.url}}`, and then
|
|
9
|
+
* `#//session?id=…`, a page that does not exist. Such a link is left as
|
|
10
|
+
* written for the host and rewritten by the renderer when its value is known
|
|
11
|
+
* (`linkHref`, see resolve-expressions).
|
|
12
|
+
*
|
|
13
|
+
* One rule for both sides, so the host and the renderer cannot disagree on
|
|
14
|
+
* which value is a link.
|
|
15
|
+
*
|
|
16
|
+
* @module @pwfabric/runtime/render/links
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Which prop keys carry a link. `href` is the obvious one; the pack also
|
|
20
|
+
* names links by role — a navbar's `ctaHref`, a card's `linkHref`. A key
|
|
21
|
+
* naming a FIELD that holds a link (`ctaHrefField`) is not a link.
|
|
22
|
+
*/
|
|
23
|
+
export function isHrefKey(key) {
|
|
24
|
+
return key === 'href' || /Href$/.test(key);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A member of `owner` that goes to a page: a `…Href` prop, a form binding's
|
|
28
|
+
* `successRedirect`, a `navigate` action's `url`.
|
|
29
|
+
*/
|
|
30
|
+
export function isLinkMember(key, owner) {
|
|
31
|
+
return isHrefKey(key) || key === 'successRedirect' || (key === 'url' && owner['type'] === 'navigate');
|
|
32
|
+
}
|
|
33
|
+
/** A link whose page is an expression: known only when the data is. */
|
|
34
|
+
export function isExpressionLink(value) {
|
|
35
|
+
return value.startsWith('{{');
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The scheme a browser will read from `url`, lower-cased, or null when it has
|
|
39
|
+
* none. A browser's URL parser DELETES tabs, newlines and other control
|
|
40
|
+
* characters before it reads the scheme, so `java\tscript:` is a `javascript:`
|
|
41
|
+
* URL; the scheme is judged on the string with them removed (`readableUrl`).
|
|
42
|
+
*/
|
|
43
|
+
export function urlSchemeOf(url) {
|
|
44
|
+
const scheme = /^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(readableUrl(url));
|
|
45
|
+
return scheme ? (scheme[1] ?? '').toLowerCase() : null;
|
|
46
|
+
}
|
|
47
|
+
/** `url` as the browser parses it: without whitespace and control characters. */
|
|
48
|
+
export function readableUrl(url) {
|
|
49
|
+
return url.replace(/[^!-~]/g, '');
|
|
50
|
+
}
|
|
51
|
+
/** The schemes a link resolved from data may carry. */
|
|
52
|
+
const LINK_SCHEMES = new Set(['http', 'https', 'mailto', 'tel']);
|
|
53
|
+
/**
|
|
54
|
+
* What a link whose value came from data may be: a root-relative path (`/x`,
|
|
55
|
+
* which the host then writes for its router), a fragment (`#x`), or an
|
|
56
|
+
* absolute URL with an allowed scheme. Anything else — `javascript:`,
|
|
57
|
+
* `data:`, a protocol-relative `//host` or `/\host`, a bare relative path — is
|
|
58
|
+
* `undefined`, and the link gets no href. Data is not the author: an author's
|
|
59
|
+
* literal link is checked when the page is validated; a row's value never is.
|
|
60
|
+
*/
|
|
61
|
+
export function safeDataLink(href) {
|
|
62
|
+
// Judged on what the browser reads; the value itself is kept (a path may
|
|
63
|
+
// carry characters `readableUrl` removes, such as `/café`).
|
|
64
|
+
const url = readableUrl(href);
|
|
65
|
+
if (url === '')
|
|
66
|
+
return undefined;
|
|
67
|
+
const kept = href.trim();
|
|
68
|
+
const scheme = urlSchemeOf(url);
|
|
69
|
+
if (scheme !== null)
|
|
70
|
+
return LINK_SCHEMES.has(scheme) ? kept : undefined;
|
|
71
|
+
if (url.startsWith('#'))
|
|
72
|
+
return kept;
|
|
73
|
+
// `//host` and `/\host` (browsers read `\` as `/`) leave the origin.
|
|
74
|
+
if (url.startsWith('/') && !url.startsWith('//') && !url.startsWith('/\\'))
|
|
75
|
+
return kept;
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=links.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"links.js","sourceRoot":"","sources":["../../src/render/links.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAKH;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,OAAO,GAAG,KAAK,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC5C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW,EAAE,KAAwC;IAChF,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,KAAK,iBAAiB,IAAI,CAAC,GAAG,KAAK,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,UAAU,CAAC,CAAA;AACvG,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,OAAO,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;AAC/B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,MAAM,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n *\n * A host turns an authored page path (`/about`, `/session?id={{item.id}}`)\n * into its router's form (`#/about`, `<base>/about`) before the page renders.\n * It cannot do that for a link whose value starts with an expression —\n * `{{item.url}}` — because which page it names is only known once the data is\n * in: rewritten as written it became `#/{{item.url}}`, and then\n * `#//session?id=…`, a page that does not exist. Such a link is left as\n * written for the host and rewritten by the renderer when its value is known\n * (`linkHref`, see resolve-expressions).\n *\n * One rule for both sides, so the host and the renderer cannot disagree on\n * which value is a link.\n *\n * @module @pwfabric/runtime/render/links\n */\n\n/** Turns a resolved in-app path into the active router's href. */\nexport type LinkHref = (href: string) => string\n\n/**\n * Which prop keys carry a link. `href` is the obvious one; the pack also\n * names links by role — a navbar's `ctaHref`, a card's `linkHref`. A key\n * naming a FIELD that holds a link (`ctaHrefField`) is not a link.\n */\nexport function isHrefKey(key: string): boolean {\n return key === 'href' || /Href$/.test(key)\n}\n\n/**\n * A member of `owner` that goes to a page: a `…Href` prop, a form binding's\n * `successRedirect`, a `navigate` action's `url`.\n */\nexport function isLinkMember(key: string, owner: Readonly<Record<string, unknown>>): boolean {\n return isHrefKey(key) || key === 'successRedirect' || (key === 'url' && owner['type'] === 'navigate')\n}\n\n/** A link whose page is an expression: known only when the data is. */\nexport function isExpressionLink(value: string): boolean {\n return value.startsWith('{{')\n}\n\n/**\n * The scheme a browser will read from `url`, lower-cased, or null when it has\n * none. A browser's URL parser DELETES tabs, newlines and other control\n * characters before it reads the scheme, so `java\\tscript:` is a `javascript:`\n * URL; the scheme is judged on the string with them removed (`readableUrl`).\n */\nexport function urlSchemeOf(url: string): string | null {\n const scheme = /^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(readableUrl(url))\n return scheme ? (scheme[1] ?? '').toLowerCase() : null\n}\n\n/** `url` as the browser parses it: without whitespace and control characters. */\nexport function readableUrl(url: string): string {\n return url.replace(/[^!-~]/g, '')\n}\n\n/** The schemes a link resolved from data may carry. */\nconst LINK_SCHEMES: ReadonlySet<string> = new Set(['http', 'https', 'mailto', 'tel'])\n\n/**\n * What a link whose value came from data may be: a root-relative path (`/x`,\n * which the host then writes for its router), a fragment (`#x`), or an\n * absolute URL with an allowed scheme. Anything else — `javascript:`,\n * `data:`, a protocol-relative `//host` or `/\\host`, a bare relative path — is\n * `undefined`, and the link gets no href. Data is not the author: an author's\n * literal link is checked when the page is validated; a row's value never is.\n */\nexport function safeDataLink(href: string): string | undefined {\n // Judged on what the browser reads; the value itself is kept (a path may\n // carry characters `readableUrl` removes, such as `/café`).\n const url = readableUrl(href)\n if (url === '') return undefined\n const kept = href.trim()\n const scheme = urlSchemeOf(url)\n if (scheme !== null) return LINK_SCHEMES.has(scheme) ? kept : undefined\n if (url.startsWith('#')) return kept\n // `//host` and `/\\host` (browsers read `\\` as `/`) leave the origin.\n if (url.startsWith('/') && !url.startsWith('//') && !url.startsWith('/\\\\')) return kept\n return undefined\n}\n"]}
|
|
@@ -8,11 +8,25 @@
|
|
|
8
8
|
* - Whole-value: "{{items}}" returns raw value (array, object, etc.)
|
|
9
9
|
* - String interpolation: "Total: {{count}}" returns interpolated string
|
|
10
10
|
* - Recursively walks block tree and nested objects/arrays in props
|
|
11
|
+
* - A prop the block's manifest declares `bindable: false` is a literal: it is
|
|
12
|
+
* left exactly as written, nested values included (block-manifest, "Prop
|
|
13
|
+
* descriptor"). A prop with no declaration is bindable.
|
|
11
14
|
*
|
|
12
15
|
* @module @pwfabric/runtime/render/resolve-expressions
|
|
13
16
|
*/
|
|
14
17
|
import type { Block } from '@pwfabric/core';
|
|
18
|
+
import type { DynamicBlockDescriptor } from '@pwfabric/contracts';
|
|
15
19
|
import type { ExpressionContext } from '../surface/expression.js';
|
|
20
|
+
import { type LinkHref } from './links.js';
|
|
21
|
+
/** Block type → the names of its props that take a literal only (`bindable: false`). */
|
|
22
|
+
export type LiteralProps = ReadonlyMap<string, ReadonlySet<string>>;
|
|
23
|
+
/**
|
|
24
|
+
* The literal props of each block type, read from the descriptors the host
|
|
25
|
+
* hands the renderer (`blocks/manifest.json` entries): every prop whose
|
|
26
|
+
* `definition.props` entry says `bindable: false`. A type with none is left
|
|
27
|
+
* out, so its props all resolve.
|
|
28
|
+
*/
|
|
29
|
+
export declare function literalPropsOf(descriptors: Iterable<DynamicBlockDescriptor>): Map<string, ReadonlySet<string>>;
|
|
16
30
|
/**
|
|
17
31
|
* Resolve a single string value.
|
|
18
32
|
*
|
|
@@ -30,8 +44,15 @@ export declare function resolveString(value: string, context: ExpressionContext)
|
|
|
30
44
|
* @param blocks - Block array to resolve
|
|
31
45
|
* @param data - Data context (keyed by source ID, plus 'state')
|
|
32
46
|
* @param helpers - Optional additional helper functions
|
|
47
|
+
* @param options.linkHref - Writes a resolved in-app link in the host's router
|
|
48
|
+
* form; applied to links whose page is an expression (see links.ts)
|
|
49
|
+
* @param options.literalProps - Per block type, the props left as written
|
|
50
|
+
* (`bindable: false`; see literalPropsOf)
|
|
33
51
|
* @returns New block array with resolved prop values
|
|
34
52
|
*/
|
|
35
|
-
export declare function resolveBlockExpressions(blocks: readonly Block[], data: Record<string, unknown>, helpers?: Record<string, (...args: unknown[]) => unknown
|
|
53
|
+
export declare function resolveBlockExpressions(blocks: readonly Block[], data: Record<string, unknown>, helpers?: Record<string, (...args: unknown[]) => unknown>, options?: {
|
|
54
|
+
readonly linkHref?: LinkHref;
|
|
55
|
+
readonly literalProps?: LiteralProps;
|
|
56
|
+
}): Block[];
|
|
36
57
|
/** True when this resolved block expanded a `repeat` — its children are clones. */
|
|
37
58
|
export declare function isRepeatExpanded(block: Block | undefined): boolean;
|
|
@@ -8,11 +8,30 @@
|
|
|
8
8
|
* - Whole-value: "{{items}}" returns raw value (array, object, etc.)
|
|
9
9
|
* - String interpolation: "Total: {{count}}" returns interpolated string
|
|
10
10
|
* - Recursively walks block tree and nested objects/arrays in props
|
|
11
|
+
* - A prop the block's manifest declares `bindable: false` is a literal: it is
|
|
12
|
+
* left exactly as written, nested values included (block-manifest, "Prop
|
|
13
|
+
* descriptor"). A prop with no declaration is bindable.
|
|
11
14
|
*
|
|
12
15
|
* @module @pwfabric/runtime/render/resolve-expressions
|
|
13
16
|
*/
|
|
14
17
|
import { BREAKPOINT_ORDER } from '@pwfabric/core';
|
|
15
18
|
import { evaluate, interpolate, createExpressionContext } from '../surface/expression.js';
|
|
19
|
+
import { isExpressionLink, isLinkMember, safeDataLink } from './links.js';
|
|
20
|
+
/**
|
|
21
|
+
* The literal props of each block type, read from the descriptors the host
|
|
22
|
+
* hands the renderer (`blocks/manifest.json` entries): every prop whose
|
|
23
|
+
* `definition.props` entry says `bindable: false`. A type with none is left
|
|
24
|
+
* out, so its props all resolve.
|
|
25
|
+
*/
|
|
26
|
+
export function literalPropsOf(descriptors) {
|
|
27
|
+
const out = new Map();
|
|
28
|
+
for (const d of descriptors) {
|
|
29
|
+
const names = (d.definition.props ?? []).filter((p) => p.bindable === false).map((p) => p.name);
|
|
30
|
+
if (names.length > 0)
|
|
31
|
+
out.set(d.blockType, new Set(names));
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
16
35
|
// ============================================================
|
|
17
36
|
// WHOLE-VALUE PATTERN
|
|
18
37
|
// ============================================================
|
|
@@ -81,6 +100,22 @@ function resolveValue(value, context) {
|
|
|
81
100
|
const resolved = {};
|
|
82
101
|
for (const [key, val] of Object.entries(value)) {
|
|
83
102
|
resolved[key] = resolveValue(val, context);
|
|
103
|
+
// A link whose page is an expression (`href: "{{item.url}}"`) was left
|
|
104
|
+
// as written by the host; now that its value is known, it is written in
|
|
105
|
+
// the active router's form. Its value came from DATA, so it must be a
|
|
106
|
+
// link and nothing else: `javascript:alert(1)` in a row is dropped and
|
|
107
|
+
// the link has no href (safeDataLink). FAIL CLOSED: a value that is not
|
|
108
|
+
// a string (a list, an object, a number, undefined while loading) is
|
|
109
|
+
// no link either. Only a link that did not resolve — the template
|
|
110
|
+
// left as written — stays as it is.
|
|
111
|
+
const href = resolved[key];
|
|
112
|
+
if (typeof val === 'string' &&
|
|
113
|
+
href !== val &&
|
|
114
|
+
isExpressionLink(val) &&
|
|
115
|
+
isLinkMember(key, value)) {
|
|
116
|
+
const safe = typeof href === 'string' ? safeDataLink(href) : undefined;
|
|
117
|
+
resolved[key] = safe === undefined ? undefined : context.linkHref ? context.linkHref(safe) : safe;
|
|
118
|
+
}
|
|
84
119
|
}
|
|
85
120
|
return resolved;
|
|
86
121
|
}
|
|
@@ -98,10 +133,18 @@ function resolveValue(value, context) {
|
|
|
98
133
|
* @param blocks - Block array to resolve
|
|
99
134
|
* @param data - Data context (keyed by source ID, plus 'state')
|
|
100
135
|
* @param helpers - Optional additional helper functions
|
|
136
|
+
* @param options.linkHref - Writes a resolved in-app link in the host's router
|
|
137
|
+
* form; applied to links whose page is an expression (see links.ts)
|
|
138
|
+
* @param options.literalProps - Per block type, the props left as written
|
|
139
|
+
* (`bindable: false`; see literalPropsOf)
|
|
101
140
|
* @returns New block array with resolved prop values
|
|
102
141
|
*/
|
|
103
|
-
export function resolveBlockExpressions(blocks, data, helpers) {
|
|
104
|
-
const context =
|
|
142
|
+
export function resolveBlockExpressions(blocks, data, helpers, options = {}) {
|
|
143
|
+
const context = {
|
|
144
|
+
...createExpressionContext(data, helpers),
|
|
145
|
+
...(options.linkHref ? { linkHref: options.linkHref } : {}),
|
|
146
|
+
...(options.literalProps && options.literalProps.size > 0 ? { literalProps: options.literalProps } : {}),
|
|
147
|
+
};
|
|
105
148
|
return blocks
|
|
106
149
|
.map((block) => resolveBlock(block, context, false))
|
|
107
150
|
.filter((b) => b !== null);
|
|
@@ -224,9 +267,7 @@ function resolveBlock(block, context, insideForm) {
|
|
|
224
267
|
return hidden ? hideInPlace(resolved) : resolved;
|
|
225
268
|
}
|
|
226
269
|
function resolveVisibleBlock(block, context, insideForm) {
|
|
227
|
-
const resolvedProps = block.props
|
|
228
|
-
? resolveValue(block.props, context)
|
|
229
|
-
: block.props;
|
|
270
|
+
const resolvedProps = block.props ? resolveProps(block, block.props, context) : block.props;
|
|
230
271
|
// Item-template expansion (repeat + {{item.*}} scope): a block carrying a
|
|
231
272
|
// block-level `repeat` expression treats its authored children as a PER-ITEM
|
|
232
273
|
// TEMPLATE. The binding resolves to an array; for each element the template
|
|
@@ -272,6 +313,25 @@ function resolveVisibleBlock(block, context, insideForm) {
|
|
|
272
313
|
props: resolvedProps,
|
|
273
314
|
};
|
|
274
315
|
}
|
|
316
|
+
/**
|
|
317
|
+
* A block's props, resolved — except those its manifest declares
|
|
318
|
+
* `bindable: false`, which are copied as written: a code sample that shows
|
|
319
|
+
* `{{state.x}}` must show those braces, not the value.
|
|
320
|
+
*/
|
|
321
|
+
function resolveProps(block, props, context) {
|
|
322
|
+
const literal = context.literalProps?.get(block.type);
|
|
323
|
+
if (!literal)
|
|
324
|
+
return resolveValue(props, context);
|
|
325
|
+
const bound = {};
|
|
326
|
+
for (const [key, val] of Object.entries(props))
|
|
327
|
+
if (!literal.has(key))
|
|
328
|
+
bound[key] = val;
|
|
329
|
+
const resolved = resolveValue(bound, context);
|
|
330
|
+
const out = {};
|
|
331
|
+
for (const [key, val] of Object.entries(props))
|
|
332
|
+
out[key] = literal.has(key) ? val : resolved[key];
|
|
333
|
+
return out;
|
|
334
|
+
}
|
|
275
335
|
/**
|
|
276
336
|
* THE BLOCK THAT EXPANDED A REPEAT OWNS ITS CLONES' LAYOUT.
|
|
277
337
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-expressions.js","sourceRoot":"","sources":["../../src/render/resolve-expressions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AAGzF,+DAA+D;AAC/D,sBAAsB;AACtB,+DAA+D;AAE/D;;;;;GAKG;AACH,MAAM,mBAAmB,GAAG,6BAA6B,CAAA;AAEzD;;GAEG;AACH,MAAM,sBAAsB,GAA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AC,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE;YAC9D,CAAC,CAAC,EAAE,CAAC;KACR,CAAA;AACH,CAAC","sourcesContent":["/**\n * Expression Resolution for Block Props\n *\n * Resolves {{expression}} placeholders in block prop values.\n * Uses the existing expression engine (evaluate/interpolate) from surface/expression.\n *\n * Key behavior:\n * - Whole-value: \"{{items}}\" returns raw value (array, object, etc.)\n * - String interpolation: \"Total: {{count}}\" returns interpolated string\n * - Recursively walks block tree and nested objects/arrays in props\n *\n * @module @pwfabric/runtime/render/resolve-expressions\n */\n\nimport type { Block } from '@pwfabric/core'\nimport { BREAKPOINT_ORDER } from '@pwfabric/core'\nimport { evaluate, interpolate, createExpressionContext } from '../surface/expression.js'\nimport type { ExpressionContext } from '../surface/expression.js'\n\n// ============================================================\n// WHOLE-VALUE PATTERN\n// ============================================================\n\n/**\n * Matches a string that is exactly one expression placeholder with no surrounding text.\n * e.g. \"{{products}}\" or \"{{ state.x === 'a' ? 'primary' : 'outline' }}\"\n * The inner capture uses a negative lookahead to prevent matching across }} boundaries,\n * so \"{{a}} · {{b}}\" is NOT treated as a whole-value expression.\n */\nconst WHOLE_VALUE_PATTERN = /^\\{\\{((?:(?!\\}\\}).)+)\\}\\}$/s\n\n/**\n * Matches strings that contain at least one expression placeholder.\n */\nconst HAS_EXPRESSION_PATTERN = /\\{\\{.+?\\}\\}/\n\n// ============================================================\n// STRING RESOLUTION\n// ============================================================\n\n/**\n * Resolve a single string value.\n *\n * - If the string is exactly \"{{expr}}\", evaluate and return the raw value (preserving type).\n * - If the string contains embedded \"{{expr}}\", interpolate and return a string.\n * - Otherwise return as-is.\n */\nexport function resolveString(value: string, context: ExpressionContext): unknown {\n // Check for whole-value expression first\n const wholeMatch = WHOLE_VALUE_PATTERN.exec(value)\n if (wholeMatch) {\n const expr = (wholeMatch[1] ?? '').trim()\n const result = evaluate(expr, context)\n if (result.success) {\n return result.value\n }\n // On failure, return original string as fallback\n return value\n }\n\n // Check for embedded expressions\n if (HAS_EXPRESSION_PATTERN.test(value)) {\n const result = interpolate(value, context)\n if (result.success) {\n return result.value\n }\n // On failure, return original string as fallback\n return value\n }\n\n // No expressions, return as-is\n return value\n}\n\n// ============================================================\n// PROP VALUE RESOLUTION\n// ============================================================\n\n/**\n * Recursively resolve expressions in a prop value.\n * - Strings are checked for expressions\n * - Arrays and plain objects are traversed\n * - Other types pass through unchanged\n */\nfunction resolveValue(value: unknown, context: ExpressionContext): unknown {\n if (typeof value === 'string') {\n return resolveString(value, context)\n }\n\n if (Array.isArray(value)) {\n return value.map((item) => resolveValue(item, context))\n }\n\n if (value !== null && typeof value === 'object') {\n const resolved: Record<string, unknown> = {}\n for (const [key, val] of Object.entries(value)) {\n resolved[key] = resolveValue(val, context)\n }\n return resolved\n }\n\n return value\n}\n\n// ============================================================\n// BLOCK EXPRESSION RESOLUTION\n// ============================================================\n\n/**\n * Resolve all {{expression}} placeholders in a block tree.\n *\n * Creates a deep copy of the blocks with all string prop values\n * containing expressions resolved against the provided data context.\n *\n * @param blocks - Block array to resolve\n * @param data - Data context (keyed by source ID, plus 'state')\n * @param helpers - Optional additional helper functions\n * @returns New block array with resolved prop values\n */\nexport function resolveBlockExpressions(\n blocks: readonly Block[],\n data: Record<string, unknown>,\n helpers?: Record<string, (...args: unknown[]) => unknown>\n): Block[] {\n const context = createExpressionContext(data, helpers)\n return blocks\n .map((block) => resolveBlock(block, context, false))\n .filter((b): b is Block => b !== null)\n}\n\n/**\n * A block may carry a conditional-visibility expression — `visibleWhen` (or the\n * shorthand `if`) — a template string evaluated against surface state/data. When\n * it resolves falsy the block (and its subtree) is omitted from the render\n * entirely. This drives state-driven UI in the blocks-array receipt path:\n * form↔success toggles, wizard steps, \"show X only when {{state.y}}\". The\n * companion is a `setState` action (e.g. a form's onSubmitAction) flipping state.\n *\n * Falsy = empty string, 'false', 'undefined', 'null', '0', NaN or a falsy primitive.\n */\nfunction isFalsyCondition(value: unknown): boolean {\n if (value == null || value === false) return true\n if (typeof value === 'string') {\n const t = value.trim().toLowerCase()\n return t === '' || t === 'false' || t === 'undefined' || t === 'null' || t === '0'\n }\n if (typeof value === 'number') return value === 0 || Number.isNaN(value)\n return false\n}\n\n/**\n * Evaluate a `visibleWhen` / `if` condition. Unlike a prop, a condition that\n * cannot be evaluated has NO fallback value: a prop keeps its raw template so\n * the author can see it, but a raw template in a condition is a non-empty\n * string — truthy — and the block would show forever (a \"no results\" empty\n * state beside the results). FAIL CLOSED: not evaluable means hidden.\n */\nfunction evaluateCondition(\n condition: string,\n context: ExpressionContext\n): { ok: true; value: unknown } | { ok: false; error: string } {\n const whole = WHOLE_VALUE_PATTERN.exec(condition)\n if (whole) {\n const r = evaluate((whole[1] ?? '').trim(), context)\n return r.success ? { ok: true, value: r.value } : { ok: false, error: r.error }\n }\n if (HAS_EXPRESSION_PATTERN.test(condition)) {\n const r = interpolate(condition, context)\n return r.success ? { ok: true, value: r.value } : { ok: false, error: r.error }\n }\n return { ok: true, value: condition }\n}\n\n/** One warning per block + condition, not one per render. */\nconst warnedConditions = new Set<string>()\n\nfunction warnUnevaluable(blockId: string, condition: string, error: string): void {\n const nodeEnv = typeof process !== 'undefined' ? process.env?.['NODE_ENV'] : undefined\n if (nodeEnv === 'production') return\n const key = `${blockId}|${condition}`\n if (warnedConditions.has(key)) return\n if (warnedConditions.size > 500) warnedConditions.clear()\n warnedConditions.add(key)\n console.warn(\n `[surface] block \"${blockId}\": visibleWhen ${JSON.stringify(condition)} could not be evaluated, so the block is HIDDEN. ${error}`\n )\n}\n\n/** The block that gathers its descendants' fields into one submission. */\nfunction isFormBlock(block: Block): boolean {\n const type = String((block as { type?: unknown }).type ?? '')\n return type === 'form' || type.endsWith('/form')\n}\n\n/** `layout.hidden` is responsive; every breakpoint, so no authored one wins. */\nconst HIDDEN_AT_EVERY_BREAKPOINT: Readonly<Record<string, boolean>> = Object.freeze(\n Object.fromEntries(BREAKPOINT_ORDER.map((bp) => [bp, true]))\n)\n\n/**\n * Hidden but still mounted: the wrapper gets `display: none` through the\n * block's own layout (`layout.hidden`, the same switch the responsive layout\n * uses), so the renderer keeps the subtree — and its inputs — in the DOM.\n */\nfunction hideInPlace(block: Block): Block {\n const layout = block.layout as unknown as Record<string, unknown> | undefined\n return { ...block, layout: { ...(layout ?? {}), hidden: HIDDEN_AT_EVERY_BREAKPOINT } } as Block\n}\n\n/**\n * Resolve expressions in a single block and its children recursively.\n * Returns null when the block's `visibleWhen`/`if` condition resolves falsy\n * (or cannot be evaluated — see evaluateCondition).\n *\n * A reserved surface-state key `__show:<blockId>` (written by `showBlock`/\n * `hideBlock` actions) acts as a visibility OVERRIDE that is checked BEFORE\n * the `visibleWhen`/`if` template evaluation:\n * - `true` → block is forced VISIBLE (visibleWhen/if skipped)\n * - `false` → block is forced HIDDEN\n * - absent → fall through to the visibleWhen/if logic\n *\n * The key is read directly from the context data (not via the template\n * evaluator) because the colon in `__show:<id>` breaks the path grammar.\n *\n * INSIDE A FORM, HIDDEN MEANS HIDDEN — NOT UNMOUNTED. A wizard is\n * one `form` whose steps are sections gated by `visibleWhen: {{state.step == N}}`.\n * The form block gathers its values from the DOM (`new FormData(form)`), so an\n * unmounted step contributed nothing: the RSVP wizard submitted an empty\n * record, and going \"back\" remounted step 1 with empty inputs. A block under a\n * form is therefore kept in the tree with `layout.hidden` (display:none) — its\n * inputs keep their values and stay part of the submission. The form itself,\n * and everything outside forms, still unmounts as before.\n */\nfunction resolveBlock(block: Block, context: ExpressionContext, insideForm: boolean): Block | null {\n const stateMap = context.data['state'] as Record<string, unknown> | undefined\n const override = stateMap?.[`__show:${block.id}`]\n let hidden = override === false\n if (override !== true && override !== false) {\n const condition = (block as { visibleWhen?: unknown; if?: unknown }).visibleWhen\n ?? (block as { visibleWhen?: unknown; if?: unknown }).if\n if (typeof condition === 'string' && condition.trim()) {\n const r = evaluateCondition(condition, context)\n if (!r.ok) {\n warnUnevaluable(block.id, condition, r.error)\n hidden = true\n } else if (isFalsyCondition(r.value)) {\n hidden = true\n }\n }\n }\n if (hidden && !insideForm) return null\n\n const resolved = resolveVisibleBlock(block, context, insideForm || isFormBlock(block))\n return hidden ? hideInPlace(resolved) : resolved\n}\n\nfunction resolveVisibleBlock(block: Block, context: ExpressionContext, insideForm: boolean): Block {\n const resolvedProps = block.props\n ? (resolveValue(block.props, context) as Record<string, unknown>)\n : block.props\n\n // Item-template expansion (repeat + {{item.*}} scope): a block carrying a\n // block-level `repeat` expression treats its authored children as a PER-ITEM\n // TEMPLATE. The binding resolves to an array; for each element the template\n // subtree is cloned and re-resolved with `item` and `index` added to the\n // expression context — so `{{item.Title}}` / `{{index}}` resolve per row.\n // Cloned block ids get a `--<index>` suffix (unique React keys /\n // data-block-id). Without `repeat` nothing changes (children resolve\n // normally, byte-identical to the previous behavior); a non-array binding\n // (source still loading) expands to zero children rather than leaking the\n // raw template. First consumer: the repeater block family — but the\n // contract is deliberately block-agnostic (a plain container can repeat).\n const repeatExpr = (block as { repeat?: unknown }).repeat\n if (typeof repeatExpr === 'string' && repeatExpr.trim() && block.children?.length) {\n const resolved = resolveValue(repeatExpr, context)\n const items = Array.isArray(resolved) ? resolved : []\n const template = block.children\n const expanded: Block[] = []\n for (let index = 0; index < items.length; index++) {\n const itemContext: ExpressionContext = {\n ...context,\n data: { ...context.data, item: items[index], index },\n }\n for (const child of template) {\n const clone = resolveBlock(suffixIds(child, index), itemContext, insideForm)\n if (clone) expanded.push(clone)\n }\n }\n const { repeat: _repeat, ...rest } = block as Block & { repeat?: unknown }\n return markRepeatExpanded({ ...(rest as Block), props: resolvedProps, children: expanded })\n }\n\n if (block.children) {\n return {\n ...block,\n props: resolvedProps,\n children: block.children\n .map((child) => resolveBlock(child, context, insideForm))\n .filter((b): b is Block => b !== null),\n }\n }\n\n return {\n ...block,\n props: resolvedProps,\n }\n}\n\n/**\n * THE BLOCK THAT EXPANDED A REPEAT OWNS ITS CLONES' LAYOUT.\n *\n * `repeat` is stripped from the resolved block, so the renderer could no\n * longer tell a repeater from any other parent: every clone got the surface\n * default `gridColumn: span 12`, and inside the repeater's own grid\n * (`repeat(auto-fit, minmax(…))`) a 12-column span put each item on a row of\n * its own — every repeater wall rendered as one column. The mark survives\n * object spread (an own enumerable symbol key) and never reaches JSON, so the\n * surface document is unchanged; the renderer reads it through\n * `isRepeatExpanded` and leaves the clones to the parent's own grid.\n */\nconst REPEAT_EXPANDED: unique symbol = Symbol.for('pwfabric.repeatExpanded')\n\nfunction markRepeatExpanded(block: Block): Block {\n return { ...block, [REPEAT_EXPANDED]: true } as Block\n}\n\n/** True when this resolved block expanded a `repeat` — its children are clones. */\nexport function isRepeatExpanded(block: Block | undefined): boolean {\n return (block as { [REPEAT_EXPANDED]?: unknown } | undefined)?.[REPEAT_EXPANDED] === true\n}\n\n/**\n * Deep-clone a template subtree, suffixing every block id with `--<index>` so\n * expanded clones stay unique across rows (React keys, data-block-id lookups,\n * label htmlFor targets).\n */\nfunction suffixIds(block: Block, index: number): Block {\n return {\n ...block,\n id: `${block.id}--${index}`,\n ...(block.children\n ? { children: block.children.map((c) => suffixIds(c, index)) }\n : {}),\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"resolve-expressions.js","sourceRoot":"","sources":["../../src/render/resolve-expressions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AAEzF,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY,EAAiB,MAAM,YAAY,CAAA;AAcxF;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,WAA6C;IAC1E,MAAM,GAAG,GAAG,IAAI,GAAG,EAA+B,CAAA;IAClD,KAAK,MAAM,CAAC,IAAI,WAAW,EAAE,CAAC;QAC5B,MAAM,KAAK,GAAG,CAAC,CA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AK,CAAC,CAAC,EAAE;YAC9D,CAAC,CAAC,EAAE,CAAC;KACR,CAAA;AACH,CAAC","sourcesContent":["/**\n * Expression Resolution for Block Props\n *\n * Resolves {{expression}} placeholders in block prop values.\n * Uses the existing expression engine (evaluate/interpolate) from surface/expression.\n *\n * Key behavior:\n * - Whole-value: \"{{items}}\" returns raw value (array, object, etc.)\n * - String interpolation: \"Total: {{count}}\" returns interpolated string\n * - Recursively walks block tree and nested objects/arrays in props\n * - A prop the block's manifest declares `bindable: false` is a literal: it is\n * left exactly as written, nested values included (block-manifest, \"Prop\n * descriptor\"). A prop with no declaration is bindable.\n *\n * @module @pwfabric/runtime/render/resolve-expressions\n */\n\nimport type { Block } from '@pwfabric/core'\nimport type { DynamicBlockDescriptor } from '@pwfabric/contracts'\nimport { BREAKPOINT_ORDER } from '@pwfabric/core'\nimport { evaluate, interpolate, createExpressionContext } from '../surface/expression.js'\nimport type { ExpressionContext } from '../surface/expression.js'\nimport { isExpressionLink, isLinkMember, safeDataLink, type LinkHref } from './links.js'\n\n/**\n * The expression scope plus how this page writes an in-app link. Carried in\n * the context so a repeat's per-row context (`{ ...context, data }`) keeps it.\n */\ntype ResolveContext = ExpressionContext & {\n readonly linkHref?: LinkHref\n readonly literalProps?: LiteralProps\n}\n\n/** Block type → the names of its props that take a literal only (`bindable: false`). */\nexport type LiteralProps = ReadonlyMap<string, ReadonlySet<string>>\n\n/**\n * The literal props of each block type, read from the descriptors the host\n * hands the renderer (`blocks/manifest.json` entries): every prop whose\n * `definition.props` entry says `bindable: false`. A type with none is left\n * out, so its props all resolve.\n */\nexport function literalPropsOf(descriptors: Iterable<DynamicBlockDescriptor>): Map<string, ReadonlySet<string>> {\n const out = new Map<string, ReadonlySet<string>>()\n for (const d of descriptors) {\n const names = (d.definition.props ?? []).filter((p) => p.bindable === false).map((p) => p.name)\n if (names.length > 0) out.set(d.blockType, new Set(names))\n }\n return out\n}\n\n// ============================================================\n// WHOLE-VALUE PATTERN\n// ============================================================\n\n/**\n * Matches a string that is exactly one expression placeholder with no surrounding text.\n * e.g. \"{{products}}\" or \"{{ state.x === 'a' ? 'primary' : 'outline' }}\"\n * The inner capture uses a negative lookahead to prevent matching across }} boundaries,\n * so \"{{a}} · {{b}}\" is NOT treated as a whole-value expression.\n */\nconst WHOLE_VALUE_PATTERN = /^\\{\\{((?:(?!\\}\\}).)+)\\}\\}$/s\n\n/**\n * Matches strings that contain at least one expression placeholder.\n */\nconst HAS_EXPRESSION_PATTERN = /\\{\\{.+?\\}\\}/\n\n// ============================================================\n// STRING RESOLUTION\n// ============================================================\n\n/**\n * Resolve a single string value.\n *\n * - If the string is exactly \"{{expr}}\", evaluate and return the raw value (preserving type).\n * - If the string contains embedded \"{{expr}}\", interpolate and return a string.\n * - Otherwise return as-is.\n */\nexport function resolveString(value: string, context: ExpressionContext): unknown {\n // Check for whole-value expression first\n const wholeMatch = WHOLE_VALUE_PATTERN.exec(value)\n if (wholeMatch) {\n const expr = (wholeMatch[1] ?? '').trim()\n const result = evaluate(expr, context)\n if (result.success) {\n return result.value\n }\n // On failure, return original string as fallback\n return value\n }\n\n // Check for embedded expressions\n if (HAS_EXPRESSION_PATTERN.test(value)) {\n const result = interpolate(value, context)\n if (result.success) {\n return result.value\n }\n // On failure, return original string as fallback\n return value\n }\n\n // No expressions, return as-is\n return value\n}\n\n// ============================================================\n// PROP VALUE RESOLUTION\n// ============================================================\n\n/**\n * Recursively resolve expressions in a prop value.\n * - Strings are checked for expressions\n * - Arrays and plain objects are traversed\n * - Other types pass through unchanged\n */\nfunction resolveValue(value: unknown, context: ResolveContext): unknown {\n if (typeof value === 'string') {\n return resolveString(value, context)\n }\n\n if (Array.isArray(value)) {\n return value.map((item) => resolveValue(item, context))\n }\n\n if (value !== null && typeof value === 'object') {\n const resolved: Record<string, unknown> = {}\n for (const [key, val] of Object.entries(value)) {\n resolved[key] = resolveValue(val, context)\n // A link whose page is an expression (`href: \"{{item.url}}\"`) was left\n // as written by the host; now that its value is known, it is written in\n // the active router's form. Its value came from DATA, so it must be a\n // link and nothing else: `javascript:alert(1)` in a row is dropped and\n // the link has no href (safeDataLink). FAIL CLOSED: a value that is not\n // a string (a list, an object, a number, undefined while loading) is\n // no link either. Only a link that did not resolve — the template\n // left as written — stays as it is.\n const href = resolved[key]\n if (\n typeof val === 'string' &&\n href !== val &&\n isExpressionLink(val) &&\n isLinkMember(key, value as Record<string, unknown>)\n ) {\n const safe = typeof href === 'string' ? safeDataLink(href) : undefined\n resolved[key] = safe === undefined ? undefined : context.linkHref ? context.linkHref(safe) : safe\n }\n }\n return resolved\n }\n\n return value\n}\n\n// ============================================================\n// BLOCK EXPRESSION RESOLUTION\n// ============================================================\n\n/**\n * Resolve all {{expression}} placeholders in a block tree.\n *\n * Creates a deep copy of the blocks with all string prop values\n * containing expressions resolved against the provided data context.\n *\n * @param blocks - Block array to resolve\n * @param data - Data context (keyed by source ID, plus 'state')\n * @param helpers - Optional additional helper functions\n * @param options.linkHref - Writes a resolved in-app link in the host's router\n * form; applied to links whose page is an expression (see links.ts)\n * @param options.literalProps - Per block type, the props left as written\n * (`bindable: false`; see literalPropsOf)\n * @returns New block array with resolved prop values\n */\nexport function resolveBlockExpressions(\n blocks: readonly Block[],\n data: Record<string, unknown>,\n helpers?: Record<string, (...args: unknown[]) => unknown>,\n options: { readonly linkHref?: LinkHref; readonly literalProps?: LiteralProps } = {}\n): Block[] {\n const context: ResolveContext = {\n ...createExpressionContext(data, helpers),\n ...(options.linkHref ? { linkHref: options.linkHref } : {}),\n ...(options.literalProps && options.literalProps.size > 0 ? { literalProps: options.literalProps } : {}),\n }\n return blocks\n .map((block) => resolveBlock(block, context, false))\n .filter((b): b is Block => b !== null)\n}\n\n/**\n * A block may carry a conditional-visibility expression — `visibleWhen` (or the\n * shorthand `if`) — a template string evaluated against surface state/data. When\n * it resolves falsy the block (and its subtree) is omitted from the render\n * entirely. This drives state-driven UI in the blocks-array receipt path:\n * form↔success toggles, wizard steps, \"show X only when {{state.y}}\". The\n * companion is a `setState` action (e.g. a form's onSubmitAction) flipping state.\n *\n * Falsy = empty string, 'false', 'undefined', 'null', '0', NaN or a falsy primitive.\n */\nfunction isFalsyCondition(value: unknown): boolean {\n if (value == null || value === false) return true\n if (typeof value === 'string') {\n const t = value.trim().toLowerCase()\n return t === '' || t === 'false' || t === 'undefined' || t === 'null' || t === '0'\n }\n if (typeof value === 'number') return value === 0 || Number.isNaN(value)\n return false\n}\n\n/**\n * Evaluate a `visibleWhen` / `if` condition. Unlike a prop, a condition that\n * cannot be evaluated has NO fallback value: a prop keeps its raw template so\n * the author can see it, but a raw template in a condition is a non-empty\n * string — truthy — and the block would show forever (a \"no results\" empty\n * state beside the results). FAIL CLOSED: not evaluable means hidden.\n */\nfunction evaluateCondition(\n condition: string,\n context: ExpressionContext\n): { ok: true; value: unknown } | { ok: false; error: string } {\n const whole = WHOLE_VALUE_PATTERN.exec(condition)\n if (whole) {\n const r = evaluate((whole[1] ?? '').trim(), context)\n return r.success ? { ok: true, value: r.value } : { ok: false, error: r.error }\n }\n if (HAS_EXPRESSION_PATTERN.test(condition)) {\n const r = interpolate(condition, context)\n return r.success ? { ok: true, value: r.value } : { ok: false, error: r.error }\n }\n return { ok: true, value: condition }\n}\n\n/** One warning per block + condition, not one per render. */\nconst warnedConditions = new Set<string>()\n\nfunction warnUnevaluable(blockId: string, condition: string, error: string): void {\n const nodeEnv = typeof process !== 'undefined' ? process.env?.['NODE_ENV'] : undefined\n if (nodeEnv === 'production') return\n const key = `${blockId}|${condition}`\n if (warnedConditions.has(key)) return\n if (warnedConditions.size > 500) warnedConditions.clear()\n warnedConditions.add(key)\n console.warn(\n `[surface] block \"${blockId}\": visibleWhen ${JSON.stringify(condition)} could not be evaluated, so the block is HIDDEN. ${error}`\n )\n}\n\n/** The block that gathers its descendants' fields into one submission. */\nfunction isFormBlock(block: Block): boolean {\n const type = String((block as { type?: unknown }).type ?? '')\n return type === 'form' || type.endsWith('/form')\n}\n\n/** `layout.hidden` is responsive; every breakpoint, so no authored one wins. */\nconst HIDDEN_AT_EVERY_BREAKPOINT: Readonly<Record<string, boolean>> = Object.freeze(\n Object.fromEntries(BREAKPOINT_ORDER.map((bp) => [bp, true]))\n)\n\n/**\n * Hidden but still mounted: the wrapper gets `display: none` through the\n * block's own layout (`layout.hidden`, the same switch the responsive layout\n * uses), so the renderer keeps the subtree — and its inputs — in the DOM.\n */\nfunction hideInPlace(block: Block): Block {\n const layout = block.layout as unknown as Record<string, unknown> | undefined\n return { ...block, layout: { ...(layout ?? {}), hidden: HIDDEN_AT_EVERY_BREAKPOINT } } as Block\n}\n\n/**\n * Resolve expressions in a single block and its children recursively.\n * Returns null when the block's `visibleWhen`/`if` condition resolves falsy\n * (or cannot be evaluated — see evaluateCondition).\n *\n * A reserved surface-state key `__show:<blockId>` (written by `showBlock`/\n * `hideBlock` actions) acts as a visibility OVERRIDE that is checked BEFORE\n * the `visibleWhen`/`if` template evaluation:\n * - `true` → block is forced VISIBLE (visibleWhen/if skipped)\n * - `false` → block is forced HIDDEN\n * - absent → fall through to the visibleWhen/if logic\n *\n * The key is read directly from the context data (not via the template\n * evaluator) because the colon in `__show:<id>` breaks the path grammar.\n *\n * INSIDE A FORM, HIDDEN MEANS HIDDEN — NOT UNMOUNTED. A wizard is\n * one `form` whose steps are sections gated by `visibleWhen: {{state.step == N}}`.\n * The form block gathers its values from the DOM (`new FormData(form)`), so an\n * unmounted step contributed nothing: the RSVP wizard submitted an empty\n * record, and going \"back\" remounted step 1 with empty inputs. A block under a\n * form is therefore kept in the tree with `layout.hidden` (display:none) — its\n * inputs keep their values and stay part of the submission. The form itself,\n * and everything outside forms, still unmounts as before.\n */\nfunction resolveBlock(block: Block, context: ResolveContext, insideForm: boolean): Block | null {\n const stateMap = context.data['state'] as Record<string, unknown> | undefined\n const override = stateMap?.[`__show:${block.id}`]\n let hidden = override === false\n if (override !== true && override !== false) {\n const condition = (block as { visibleWhen?: unknown; if?: unknown }).visibleWhen\n ?? (block as { visibleWhen?: unknown; if?: unknown }).if\n if (typeof condition === 'string' && condition.trim()) {\n const r = evaluateCondition(condition, context)\n if (!r.ok) {\n warnUnevaluable(block.id, condition, r.error)\n hidden = true\n } else if (isFalsyCondition(r.value)) {\n hidden = true\n }\n }\n }\n if (hidden && !insideForm) return null\n\n const resolved = resolveVisibleBlock(block, context, insideForm || isFormBlock(block))\n return hidden ? hideInPlace(resolved) : resolved\n}\n\nfunction resolveVisibleBlock(block: Block, context: ResolveContext, insideForm: boolean): Block {\n const resolvedProps = block.props ? resolveProps(block, block.props, context) : block.props\n\n // Item-template expansion (repeat + {{item.*}} scope): a block carrying a\n // block-level `repeat` expression treats its authored children as a PER-ITEM\n // TEMPLATE. The binding resolves to an array; for each element the template\n // subtree is cloned and re-resolved with `item` and `index` added to the\n // expression context — so `{{item.Title}}` / `{{index}}` resolve per row.\n // Cloned block ids get a `--<index>` suffix (unique React keys /\n // data-block-id). Without `repeat` nothing changes (children resolve\n // normally, byte-identical to the previous behavior); a non-array binding\n // (source still loading) expands to zero children rather than leaking the\n // raw template. First consumer: the repeater block family — but the\n // contract is deliberately block-agnostic (a plain container can repeat).\n const repeatExpr = (block as { repeat?: unknown }).repeat\n if (typeof repeatExpr === 'string' && repeatExpr.trim() && block.children?.length) {\n const resolved = resolveValue(repeatExpr, context)\n const items = Array.isArray(resolved) ? resolved : []\n const template = block.children\n const expanded: Block[] = []\n for (let index = 0; index < items.length; index++) {\n const itemContext: ResolveContext = {\n ...context,\n data: { ...context.data, item: items[index], index },\n }\n for (const child of template) {\n const clone = resolveBlock(suffixIds(child, index), itemContext, insideForm)\n if (clone) expanded.push(clone)\n }\n }\n const { repeat: _repeat, ...rest } = block as Block & { repeat?: unknown }\n return markRepeatExpanded({ ...(rest as Block), props: resolvedProps, children: expanded })\n }\n\n if (block.children) {\n return {\n ...block,\n props: resolvedProps,\n children: block.children\n .map((child) => resolveBlock(child, context, insideForm))\n .filter((b): b is Block => b !== null),\n }\n }\n\n return {\n ...block,\n props: resolvedProps,\n }\n}\n\n/**\n * A block's props, resolved — except those its manifest declares\n * `bindable: false`, which are copied as written: a code sample that shows\n * `{{state.x}}` must show those braces, not the value.\n */\nfunction resolveProps(block: Block, props: Record<string, unknown>, context: ResolveContext): Record<string, unknown> {\n const literal = context.literalProps?.get(block.type)\n if (!literal) return resolveValue(props, context) as Record<string, unknown>\n const bound: Record<string, unknown> = {}\n for (const [key, val] of Object.entries(props)) if (!literal.has(key)) bound[key] = val\n const resolved = resolveValue(bound, context) as Record<string, unknown>\n const out: Record<string, unknown> = {}\n for (const [key, val] of Object.entries(props)) out[key] = literal.has(key) ? val : resolved[key]\n return out\n}\n\n/**\n * THE BLOCK THAT EXPANDED A REPEAT OWNS ITS CLONES' LAYOUT.\n *\n * `repeat` is stripped from the resolved block, so the renderer could no\n * longer tell a repeater from any other parent: every clone got the surface\n * default `gridColumn: span 12`, and inside the repeater's own grid\n * (`repeat(auto-fit, minmax(…))`) a 12-column span put each item on a row of\n * its own — every repeater wall rendered as one column. The mark survives\n * object spread (an own enumerable symbol key) and never reaches JSON, so the\n * surface document is unchanged; the renderer reads it through\n * `isRepeatExpanded` and leaves the clones to the parent's own grid.\n */\nconst REPEAT_EXPANDED: unique symbol = Symbol.for('pwfabric.repeatExpanded')\n\nfunction markRepeatExpanded(block: Block): Block {\n return { ...block, [REPEAT_EXPANDED]: true } as Block\n}\n\n/** True when this resolved block expanded a `repeat` — its children are clones. */\nexport function isRepeatExpanded(block: Block | undefined): boolean {\n return (block as { [REPEAT_EXPANDED]?: unknown } | undefined)?.[REPEAT_EXPANDED] === true\n}\n\n/**\n * Deep-clone a template subtree, suffixing every block id with `--<index>` so\n * expanded clones stay unique across rows (React keys, data-block-id lookups,\n * label htmlFor targets).\n */\nfunction suffixIds(block: Block, index: number): Block {\n return {\n ...block,\n id: `${block.id}--${index}`,\n ...(block.children\n ? { children: block.children.map((c) => suffixIds(c, index)) }\n : {}),\n }\n}\n"]}
|
|
@@ -66,6 +66,13 @@ export declare function collectScopedCss(blocks: readonly Block[], perBlockFn: (
|
|
|
66
66
|
* (`marginTop:'-40%'` would move content by both -335px and -256px).
|
|
67
67
|
*/
|
|
68
68
|
export declare const FLEX_HOIST_KEYS: readonly ["flex", "flexGrow", "flexShrink", "flexBasis"];
|
|
69
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Where a block sits in its parent's grid. The grid item is the WRAPPER the
|
|
71
|
+
* renderer draws (it carries the `layout.span` column too); on the component
|
|
72
|
+
* root, one level down, `gridColumn: {xs: 'span 12', md: 'span 4'}` placed
|
|
73
|
+
* nothing — the root is the wrapper's only child, not a grid item.
|
|
74
|
+
*/
|
|
75
|
+
export declare const GRID_PLACEMENT_KEYS: readonly ["gridColumn", "gridColumnStart", "gridColumnEnd", "gridRow", "gridRowStart", "gridRowEnd", "gridArea"];
|
|
76
|
+
export declare const LAYOUT_HOIST_KEYS: readonly ["margin", "marginTop", "marginRight", "marginBottom", "marginLeft", "maxWidth", "minWidth", "flex", "flexGrow", "flexShrink", "flexBasis", "gridColumn", "gridColumnStart", "gridColumnEnd", "gridRow", "gridRowStart", "gridRowEnd", "gridArea"];
|
|
70
77
|
/** The attribute that tells the wrapper from the component root (the same marker states-css uses). */
|
|
71
78
|
export declare const WRAPPER_ATTR = "[data-block-wrapper]";
|
|
@@ -87,6 +87,21 @@ export function collectScopedCss(blocks, perBlockFn) {
|
|
|
87
87
|
* (`marginTop:'-40%'` would move content by both -335px and -256px).
|
|
88
88
|
*/
|
|
89
89
|
export const FLEX_HOIST_KEYS = ['flex', 'flexGrow', 'flexShrink', 'flexBasis'];
|
|
90
|
+
/**
|
|
91
|
+
* Where a block sits in its parent's grid. The grid item is the WRAPPER the
|
|
92
|
+
* renderer draws (it carries the `layout.span` column too); on the component
|
|
93
|
+
* root, one level down, `gridColumn: {xs: 'span 12', md: 'span 4'}` placed
|
|
94
|
+
* nothing — the root is the wrapper's only child, not a grid item.
|
|
95
|
+
*/
|
|
96
|
+
export const GRID_PLACEMENT_KEYS = [
|
|
97
|
+
'gridColumn',
|
|
98
|
+
'gridColumnStart',
|
|
99
|
+
'gridColumnEnd',
|
|
100
|
+
'gridRow',
|
|
101
|
+
'gridRowStart',
|
|
102
|
+
'gridRowEnd',
|
|
103
|
+
'gridArea',
|
|
104
|
+
];
|
|
90
105
|
export const LAYOUT_HOIST_KEYS = [
|
|
91
106
|
'margin',
|
|
92
107
|
'marginTop',
|
|
@@ -96,6 +111,7 @@ export const LAYOUT_HOIST_KEYS = [
|
|
|
96
111
|
'maxWidth',
|
|
97
112
|
'minWidth',
|
|
98
113
|
...FLEX_HOIST_KEYS,
|
|
114
|
+
...GRID_PLACEMENT_KEYS,
|
|
99
115
|
];
|
|
100
116
|
/** The attribute that tells the wrapper from the component root (the same marker states-css uses). */
|
|
101
117
|
export const WRAPPER_ATTR = '[data-block-wrapper]';
|