@pwfabric/runtime 1.2.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/README.md +1 -1
- 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/entity/http-connector.js +1 -1
- package/dist/entity/http-connector.js.map +1 -1
- package/dist/entity/registry.js +1 -1
- package/dist/entity/registry.js.map +1 -1
- package/dist/forms/validator.js +1 -1
- package/dist/forms/validator.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 +4 -4
- package/dist/surface/output.js.map +1 -1
- package/dist/surface/schemas.d.ts +28 -96
- package/dist/surface/schemas.js +3 -3
- package/dist/surface/schemas.js.map +1 -1
- package/dist/surface/transforms.d.ts +7 -33
- package/dist/surface/transforms.js +2 -2
- package/dist/surface/transforms.js.map +1 -1
- package/dist/surface/validation.js +1 -1
- package/dist/surface/validation.js.map +1 -1
- package/dist/validator.js +1 -1
- package/dist/validator.js.map +1 -1
- package/package.json +8 -8
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,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,YAAY,EACZ,WAAW,EACX,aAAa,EACb,gBAAgB,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B,CAAA;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAI9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAA;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,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,C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E,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IACvF,OAAO,SAAS,CAAA;AAClB,CAAC","sourcesContent":["/**\n * Which values in a page are links to the app's pages.\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,MAA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,SAAS,SAAS,CAAC,KAAY,EAAE,KAAa;IAC5C,OAAO;QACL,GAAG,KAAK;QACR,EAAE,EAAE,GAAG,KAAK,CAAC,EAAE,KAAK,KAAK,EAAE;QAC3B,GAAG,CAAC,KAAK,CAAC,QAAQ;YAChB,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,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,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,KAAK;QACR,EAAE,EAAE,GAAG,KAAK,CAAC,EAAE,KAAK,KAAK,EAAE;QAC3B,GAAG,CAAC,KAAK,CAAC,QAAQ;YAChB,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,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 * - 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]';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scoped-css.js","sourceRoot":"","sources":["../../src/render/scoped-css.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,4FAA4F;AAC5F,MAAM,UAAU,WAAW,CAAC,EAAU;IACpC,OAAO,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;AACrC,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;AAC7D,CAAC;AAED,uFAAuF;AAC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AAM;QAAE,IAAI,CAAC,KAAK,CAAC,CAAA;IACvC,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,CAAU,CAAA;AAEvF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,YAAY;IACZ,iBAAiB;IACjB,eAAe;IACf,SAAS;IACT,cAAc;IACd,YAAY;IACZ,UAAU;CACF,CAAA;AAEV,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,QAAQ;IACR,WAAW;IACX,aAAa;IACb,cAAc;IACd,YAAY;IACZ,UAAU;IACV,UAAU;IACV,GAAG,eAAe;IAClB,GAAG,mBAAmB;CACd,CAAA;AAEV,sGAAsG;AACtG,MAAM,CAAC,MAAM,YAAY,GAAG,sBAAsB,CAAA","sourcesContent":["/**\n * Shared helpers for the scoped per-block CSS collectors.\n *\n * The runtime emits several kinds of scoped `<style>` rules keyed by a block's\n * stable `data-block-id` (visibility / interaction-states / responsive-style /\n * conditional-states / group-states). They all share the SAME primitives:\n *\n * - `cssEscapeId(id)` — conservative attribute-value escaper for block ids.\n * - `camelToKebab(prop)` — CSS camelCase property name → kebab-case.\n * - `blockSelector(id)` — `[data-pw-surface] [data-block-id=\"<escaped>\"]`,\n * the scoped base selector every rule attaches to.\n * - `collectScopedCss(blocks, perBlockFn)` — walk the block tree (including\n * children) and concatenate each block's CSS as\n * produced by `perBlockFn(block)`.\n *\n * Centralising these keeps the per-collector files focused on their own\n * selector/declaration semantics and guarantees byte-identical output across\n * the family (the same escaper, the same selector string, the same walk order).\n *\n * @module @pwfabric/runtime/render/scoped-css\n */\n\nimport type { Block } from '@pwfabric/core'\n\n/** Conservative CSS attribute-selector value escaper (block ids are slugs, but be safe). */\nexport function cssEscapeId(id: string): string {\n return id.replace(/[\"\\\\]/g, '\\\\$&')\n}\n\n/** camelCase CSS property → kebab-case (e.g. `backgroundColor` → `background-color`). */\nexport function camelToKebab(prop: string): string {\n return prop.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`)\n}\n\n/** The bare `[data-block-id=\"<escaped-id>\"]` attribute selector (no surface scope). */\nexport function blockIdAttr(id: string): string {\n return `[data-block-id=\"${cssEscapeId(id)}\"]`\n}\n\n/**\n * The surface-root selector a scoped rule hangs off.\n *\n * With a `surfaceId` this is `[data-pw-surface=\"<id>\"]` — scope carried by the\n * attribute's VALUE, not merely its presence. That matters because the embed\n * autoloader hydrates EVERY `[data-pw-surface]` element in a document, so a host\n * page can hold several surfaces at once; a value-less selector makes each\n * surface's rules apply to all of them, and the last one in document order wins.\n *\n * Without a `surfaceId` it degrades to the historical `[data-pw-surface]`, which\n * is correct for rules whose content is identical for every surface (the base\n * CSS) and for unit tests that render a single surface.\n */\nexport function surfaceScope(surfaceId?: string): string {\n return surfaceId ? `[data-pw-surface=\"${cssEscapeId(surfaceId)}\"]` : '[data-pw-surface]'\n}\n\n/**\n * The scoped base selector a per-block rule attaches to:\n * `[data-pw-surface=\"<sid>\"] [data-block-id=\"<escaped-id>\"]`. Scoped under the\n * surface root so a rule can never leak to the host page — and, when the surface\n * id is supplied, never to a SIBLING surface that happens to reuse a block id.\n */\nexport function blockSelector(id: string, surfaceId?: string): string {\n return `${surfaceScope(surfaceId)} ${blockIdAttr(id)}`\n}\n\n/**\n * Walk a surface block tree (depth-first, children after their parent — the\n * order all collectors used) and concatenate the per-block CSS produced by\n * `perBlockFn(block)`. Blocks for which `perBlockFn` returns '' contribute zero\n * bytes, so existing surfaces stay byte-identical.\n */\nexport function collectScopedCss(\n blocks: readonly Block[],\n perBlockFn: (block: Block) => string\n): string {\n let css = ''\n const walk = (block: Block): void => {\n css += perBlockFn(block)\n if (block.children) {\n for (const child of block.children) walk(child)\n }\n }\n for (const block of blocks) walk(block)\n return css\n}\n\n/**\n * Style keys HOISTED to the wrapper — kept here so the renderer and the\n * responsive CSS generator see the SAME list.\n *\n * This list is a RULE: these keys apply to the outer wrapper, not the\n * component root. For flat values the renderer hoists them; for responsive\n * values the value leaves the inline style entirely and lands in CSS, so the\n * same rule has to be expressed on the selector side — otherwise the rule\n * matches both the wrapper and the root and the value is applied TWICE\n * (`marginTop:'-40%'` would move content by both -335px and -256px).\n */\nexport const FLEX_HOIST_KEYS = ['flex', 'flexGrow', 'flexShrink', 'flexBasis'] as const\n\n/**\n * Where a block sits in its parent's grid. The grid item is the WRAPPER the\n * renderer draws (it carries the `layout.span` column too); on the component\n * root, one level down, `gridColumn: {xs: 'span 12', md: 'span 4'}` placed\n * nothing — the root is the wrapper's only child, not a grid item.\n */\nexport const GRID_PLACEMENT_KEYS = [\n 'gridColumn',\n 'gridColumnStart',\n 'gridColumnEnd',\n 'gridRow',\n 'gridRowStart',\n 'gridRowEnd',\n 'gridArea',\n] as const\n\nexport const LAYOUT_HOIST_KEYS = [\n 'margin',\n 'marginTop',\n 'marginRight',\n 'marginBottom',\n 'marginLeft',\n 'maxWidth',\n 'minWidth',\n ...FLEX_HOIST_KEYS,\n ...GRID_PLACEMENT_KEYS,\n] as const\n\n/** The attribute that tells the wrapper from the component root (the same marker states-css uses). */\nexport const WRAPPER_ATTR = '[data-block-wrapper]'\n"]}
|
|
@@ -145,7 +145,6 @@ export const DEFAULT_HELPERS = {
|
|
|
145
145
|
upper: (s) => String(s).toUpperCase(),
|
|
146
146
|
lower: (s) => String(s).toLowerCase(),
|
|
147
147
|
trim: (s) => String(s).trim(),
|
|
148
|
-
length: (s) => (Array.isArray(s) ? s.length : String(s).length),
|
|
149
148
|
concat: (...args) => args.map(String).join(''),
|
|
150
149
|
// Number helpers
|
|
151
150
|
// `round` comes from the binding set: `round(n)` as before, `round(n, 2)`
|