@pwfabric/runtime 1.0.0-rc.1 → 1.0.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/README.md
CHANGED
|
@@ -7,7 +7,7 @@ re-exports `@pwfabric/contracts`.
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
pnpm add @pwfabric/runtime
|
|
10
|
+
pnpm add @pwfabric/runtime zod@3 react react-dom
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
ESM only: import it from an ES module (`"type": "module"` or `.mjs`). Node 22+. Peers: `react` and `react-dom` 18 or 19; `next` 14–16 only if you use the
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Wraps EntityStore.query() as a minimal DataSource-compatible
|
|
5
5
|
* adapter so the surface expression system can resolve entity data via the
|
|
6
|
-
* existing {{
|
|
6
|
+
* existing binding path: the records bind under the source id, {{<id>}}.
|
|
7
7
|
*
|
|
8
8
|
* @module @pwfabric/runtime/entity/entity-datasource
|
|
9
9
|
*/
|
|
@@ -24,7 +24,9 @@ export interface EntityDataSourceConfig {
|
|
|
24
24
|
/**
|
|
25
25
|
* Minimal DataSource-compatible adapter for entity queries.
|
|
26
26
|
* fetch() delegates to EntityFacade.resolveBinding() and returns EntityQueryResult.
|
|
27
|
-
*
|
|
27
|
+
* A surface binds a source's records as a list under its id — {{<id>}}, the
|
|
28
|
+
* `items` of this result (`{{data.<id>}}` names the same value). The result's
|
|
29
|
+
* `total` does not reach the binding context.
|
|
28
30
|
*/
|
|
29
31
|
export interface EntityDataSource {
|
|
30
32
|
readonly id: string;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Wraps EntityStore.query() as a minimal DataSource-compatible
|
|
5
5
|
* adapter so the surface expression system can resolve entity data via the
|
|
6
|
-
* existing {{
|
|
6
|
+
* existing binding path: the records bind under the source id, {{<id>}}.
|
|
7
7
|
*
|
|
8
8
|
* @module @pwfabric/runtime/entity/entity-datasource
|
|
9
9
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-datasource.js","sourceRoot":"","sources":["../../src/entity/entity-datasource.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"entity-datasource.js","sourceRoot":"","sources":["../../src/entity/entity-datasource.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAmCH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,sBAAsB,CACpC,MAAoB,EACpB,MAA8B;IAE9B,OAAO;QACL,EAAE,EAAE,MAAM,CAAC,EAAE;QACb,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC;KACpE,CAAA;AACH,CAAC","sourcesContent":["/**\n * Entity DataSource Adapter\n *\n * Wraps EntityStore.query() as a minimal DataSource-compatible\n * adapter so the surface expression system can resolve entity data via the\n * existing binding path: the records bind under the source id, {{<id>}}.\n *\n * @module @pwfabric/runtime/entity/entity-datasource\n */\n\nimport type { EntityFacade } from './facade.js'\nimport type { EntityTypeId, EntityQuery, EntityQueryResult } from './types.js'\n\n// ============================================================\n// ENTITY DATA SOURCE\n// ============================================================\n\n/**\n * Configuration for an EntityDataSource instance.\n * Matches the `entity`-typed entry in a surface definition's dataSources array.\n */\nexport interface EntityDataSourceConfig {\n /** Unique identifier — matches the surface definition id used in expressions */\n readonly id: string\n /** Entity type to query (e.g. 'Employee', 'Product') */\n readonly entityType: EntityTypeId\n /** Optional query parameters (filter, sort, pagination) */\n readonly query?: EntityQuery\n}\n\n/**\n * Minimal DataSource-compatible adapter for entity queries.\n * fetch() delegates to EntityFacade.resolveBinding() and returns EntityQueryResult.\n * A surface binds a source's records as a list under its id — {{<id>}}, the\n * `items` of this result (`{{data.<id>}}` names the same value). The result's\n * `total` does not reach the binding context.\n */\nexport interface EntityDataSource {\n readonly id: string\n readonly type: 'entity'\n fetch(): Promise<EntityQueryResult>\n}\n\n/**\n * Creates an EntityDataSource that wraps EntityStore.query() for a specific\n * entity type. Register with the surface data context to make results\n * available in block expression props.\n *\n * @example\n * ```ts\n * const employeesSource = createEntityDataSource(facade, {\n * id: 'employees',\n * entityType: 'Employee',\n * query: { sort: [{ field: 'name', direction: 'asc' }] },\n * })\n * const result = await employeesSource.fetch()\n * // result.items — array of employee records\n * ```\n */\nexport function createEntityDataSource(\n facade: EntityFacade,\n config: EntityDataSourceConfig\n): EntityDataSource {\n return {\n id: config.id,\n type: 'entity',\n fetch: () => facade.resolveBinding(config.entityType, config.query),\n }\n}\n"]}
|
|
@@ -80,6 +80,9 @@ export function DynamicBlockWrapper({ descriptor, block, context, children, }) {
|
|
|
80
80
|
})
|
|
81
81
|
.catch((err) => {
|
|
82
82
|
const msg = err instanceof Error ? err.message : 'Unknown error';
|
|
83
|
+
// The placeholder says it on the page; the console says it to whoever
|
|
84
|
+
// is debugging a block that "just does not render".
|
|
85
|
+
console.error(`[pwfabric] block "${descriptor.blockType}" failed to load: ${msg}`);
|
|
83
86
|
setErrorMessage(msg);
|
|
84
87
|
setState('error');
|
|
85
88
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynamicBlockWrapper.js","sourceRoot":"","sources":["../../src/render/DynamicBlockWrapper.tsx"],"names":[],"mappings":";AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAkB,MAAM,OAAO,CAAA;AAIxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAe7D,+DAA+D;AAC/D,8BAA8B;AAC9B,+DAA+D;AAE/D;;;;;;;;GAQG;AACH,SAAS,oBAAoB,CAAC,EAAE,SAAS,EAAkC;IACzE,OAAO,CACL,oCACsB,SAAS,gBAClB,SAAS,eACV,MAAM,EAChB,KAAK,EAA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d,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAA;IAEvB,MAAM,WAAW,GAAG,WAAW,CAAC,GAAG,EAAE;QACnC,iBAAiB,CAAC,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;QAClD,UAAU,EAAE,CAAA;IACd,CAAC,EAAE,CAAC,UAAU,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAA;IAEtC,iFAAiF;IACjF,qFAAqF;IACrF,kFAAkF;IAClF,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,SAAS,GAAG,SAAS,CAAA;QAC3B,2EAA2E;QAC3E,6EAA6E;QAC7E,wEAAwE;QACxE,2DAA2D;QAC3D,EAAE;QACF,wEAAwE;QACxE,yEAAyE;QACzE,0EAA0E;QAC1E,6CAA6C;QAC7C,OAAO,CACL,KAAC,SAAS,IAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,EAAE,EAAE,OAAO,EAAE,OAAO,YAChE,QAAQ,GACC,CACb,CAAA;IACH,CAAC;IAED,IAAI,KAAK,KAAK,OAAO,EAAE,CAAC;QACtB,OAAO,CACL,KAAC,iBAAiB,IAChB,SAAS,EAAE,UAAU,CAAC,SAAS,EAC/B,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,WAAW,GACpB,CACH,CAAA;IACH,CAAC;IAED,OAAO,KAAC,oBAAoB,IAAC,SAAS,EAAE,UAAU,CAAC,SAAS,GAAI,CAAA;AAClE,CAAC","sourcesContent":["/**\n * Dynamic Block Wrapper Component\n *\n * Wraps dynamically loaded block components with loading,\n * error, and loaded state management.\n *\n * @module @pwfabric/runtime/render/DynamicBlockWrapper\n */\n\nimport { useState, useEffect, useCallback, type ReactNode } from 'react'\nimport type { DynamicBlockDescriptor } from '@pwfabric/contracts'\nimport type { Block } from '@pwfabric/core'\nimport type { BlockComponent, BlockContext } from './types.js'\nimport { BlockModuleLoader } from './dynamic-block-loader.js'\n\n// ============================================================\n// TYPES\n// ============================================================\n\nexport interface DynamicBlockWrapperProps {\n readonly descriptor: DynamicBlockDescriptor\n readonly block: Block\n readonly context: BlockContext\n readonly children?: ReactNode\n}\n\ntype LoadState = 'idle' | 'loading' | 'loaded' | 'error'\n\n// ============================================================\n// SKELETON & ERROR COMPONENTS\n// ============================================================\n\n/**\n * Quiet, theme-tokened module-load placeholder. Deliberately renders NO\n * visible text or spinner — the earlier \"Loading {blockType}...\" card was a\n * hardcoded light-theme box (gray fill, indigo spinner, English dev-facing\n * label) that flashed as a burst of bright cards on dark-themed surfaces\n * during a cold load. A low-contrast wash derived from the local text token\n * reads as \"something is about to appear\" in any theme and inside any card.\n * The data attributes keep the state machine observable for tests/tooling.\n */\nfunction DynamicBlockSkeleton({ blockType }: { readonly blockType: string }): ReactNode {\n return (\n <div\n data-dynamic-block={blockType}\n data-state=\"loading\"\n aria-busy=\"true\"\n style={{\n minHeight: '24px',\n borderRadius: '8px',\n backgroundColor: 'color-mix(in srgb, var(--pw-color-text, #9ca3af) 6%, transparent)',\n }}\n />\n )\n}\n\n/**\n * Module-load failure. Same quiet-shape rule: no visible copy — the error\n * tint + dashed border carry the meaning, the technical message lives in the\n * title tooltip (and the loader already logs it), and the single retry\n * control is an icon button with an English aria-label.\n */\nfunction DynamicBlockError({\n blockType,\n error,\n onRetry,\n}: {\n readonly blockType: string\n readonly error: string\n readonly onRetry: () => void\n}): ReactNode {\n return (\n <div\n data-dynamic-block={blockType}\n data-state=\"error\"\n title={error}\n style={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n padding: '12px',\n border: '2px dashed var(--pw-color-error, #fca5a5)',\n borderRadius: '8px',\n backgroundColor: 'color-mix(in srgb, var(--pw-color-error, #ef4444) 8%, transparent)',\n minHeight: '48px',\n }}\n >\n <button\n type=\"button\"\n onClick={onRetry}\n aria-label={`Retry loading ${blockType}`}\n style={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n width: '28px',\n height: '28px',\n border: '1px solid var(--pw-color-error, #fca5a5)',\n borderRadius: '50%',\n backgroundColor: 'transparent',\n color: 'var(--pw-color-error, #991b1b)',\n cursor: 'pointer',\n padding: 0,\n }}\n >\n <svg\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth={2}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <path d=\"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8\" />\n <path d=\"M3 3v5h5\" />\n </svg>\n </button>\n </div>\n )\n}\n\n// ============================================================\n// WRAPPER COMPONENT\n// ============================================================\n\n/**\n * Wraps a dynamically loaded block component.\n * Manages loading → loaded | error state machine.\n */\nexport function DynamicBlockWrapper({\n descriptor,\n block,\n context,\n children,\n}: DynamicBlockWrapperProps): ReactNode {\n const [state, setState] = useState<LoadState>(\n BlockModuleLoader.isLoaded(descriptor.blockType) ? 'loaded' : 'idle'\n )\n const [component, setComponent] = useState<BlockComponent | null>(() =>\n BlockModuleLoader.getSync(descriptor.blockType)\n )\n const [errorMessage, setErrorMessage] = useState('')\n\n const loadModule = useCallback(() => {\n setComponent(null)\n setState('loading')\n setErrorMessage('')\n\n BlockModuleLoader.load(descriptor)\n .then((comp) => {\n setComponent(() => comp)\n setState('loaded')\n })\n .catch((err: unknown) => {\n const msg = err instanceof Error ? err.message : 'Unknown error'\n setErrorMessage(msg)\n setState('error')\n })\n }, [descriptor])\n\n useEffect(() => {\n if (state === 'idle') {\n loadModule()\n }\n }, [state, loadModule])\n\n const handleRetry = useCallback(() => {\n BlockModuleLoader.invalidate(descriptor.blockType)\n loadModule()\n }, [descriptor.blockType, loadModule])\n\n // Component-first: if we have a loaded component, always render it regardless of\n // the state machine. This prevents the skeleton from flashing when state transitions\n // to 'loading' (e.g. retry) while the previous component is still valid in cache.\n if (component) {\n const Component = component\n // `props` is NEVER undefined. A node may legitimately carry no `props` key\n // at all — `{id, type, children}` is a valid section — and a block component\n // reads `props.x` directly, so handing it `undefined` throws inside the\n // component and the block renders as an error placeholder.\n //\n // A `section` authored without a `props` key would otherwise crash with\n // \"Cannot read properties of undefined (reading 'paddingY')\". The static\n // renderer guards this too (`renderer.tsx`: `block.props ?? {}`); this is\n // the path every PACK-INSTALLED block takes.\n return (\n <Component block={block} props={block.props ?? {}} context={context}>\n {children}\n </Component>\n )\n }\n\n if (state === 'error') {\n return (\n <DynamicBlockError\n blockType={descriptor.blockType}\n error={errorMessage}\n onRetry={handleRetry}\n />\n )\n }\n\n return <DynamicBlockSkeleton blockType={descriptor.blockType} />\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DynamicBlockWrapper.js","sourceRoot":"","sources":["../../src/render/DynamicBlockWrapper.tsx"],"names":[],"mappings":";AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAkB,MAAM,OAAO,CAAA;AAIxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAe7D,+DAA+D;AAC/D,8BAA8B;AAC9B,+DAA+D;AAE/D;;;;;;;;GAQG;AACH,SAAS,oBAAoB,CAAC,EAAE,SAAS,EAAkC;IACzE,OAAO,CACL,oCACsB,SAAS,gBAClB,SAAS,eACV,MAAM,EAChB,KAAK,EAAE;YACL,SAAS,EAAE,MAAM;YACjB,YAAY,EAAE,KAAK;YACnB,eAAe,EAAE,mEAAmE;SACrF,GACD,CACH,CAAA;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAS,iBAAiB,CAAC,EACzB,SAAS,EACT,KAAK,EACL,OAAO,GAKR;IACC,OAAO,CACL,oCACsB,SAAS,gBAClB,OAAO,EAClB,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE;YACL,OAAO,EAAE,MAAM;YACf,UAAU,EAAE,QAAQ;YACpB,cAAc,EAAE,QAAQ;YACxB,OAAO,EAAE,MAAM;YACf,MAAM,EAAE,2C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AA;IAEtC,iFAAiF;IACjF,qFAAqF;IACrF,kFAAkF;IAClF,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,SAAS,GAAG,SAAS,CAAA;QAC3B,2EAA2E;QAC3E,6EAA6E;QAC7E,wEAAwE;QACxE,2DAA2D;QAC3D,EAAE;QACF,wEAAwE;QACxE,yEAAyE;QACzE,0EAA0E;QAC1E,6CAA6C;QAC7C,OAAO,CACL,KAAC,SAAS,IAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,EAAE,EAAE,OAAO,EAAE,OAAO,YAChE,QAAQ,GACC,CACb,CAAA;IACH,CAAC;IAED,IAAI,KAAK,KAAK,OAAO,EAAE,CAAC;QACtB,OAAO,CACL,KAAC,iBAAiB,IAChB,SAAS,EAAE,UAAU,CAAC,SAAS,EAC/B,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,WAAW,GACpB,CACH,CAAA;IACH,CAAC;IAED,OAAO,KAAC,oBAAoB,IAAC,SAAS,EAAE,UAAU,CAAC,SAAS,GAAI,CAAA;AAClE,CAAC","sourcesContent":["/**\n * Dynamic Block Wrapper Component\n *\n * Wraps dynamically loaded block components with loading,\n * error, and loaded state management.\n *\n * @module @pwfabric/runtime/render/DynamicBlockWrapper\n */\n\nimport { useState, useEffect, useCallback, type ReactNode } from 'react'\nimport type { DynamicBlockDescriptor } from '@pwfabric/contracts'\nimport type { Block } from '@pwfabric/core'\nimport type { BlockComponent, BlockContext } from './types.js'\nimport { BlockModuleLoader } from './dynamic-block-loader.js'\n\n// ============================================================\n// TYPES\n// ============================================================\n\nexport interface DynamicBlockWrapperProps {\n readonly descriptor: DynamicBlockDescriptor\n readonly block: Block\n readonly context: BlockContext\n readonly children?: ReactNode\n}\n\ntype LoadState = 'idle' | 'loading' | 'loaded' | 'error'\n\n// ============================================================\n// SKELETON & ERROR COMPONENTS\n// ============================================================\n\n/**\n * Quiet, theme-tokened module-load placeholder. Deliberately renders NO\n * visible text or spinner — the earlier \"Loading {blockType}...\" card was a\n * hardcoded light-theme box (gray fill, indigo spinner, English dev-facing\n * label) that flashed as a burst of bright cards on dark-themed surfaces\n * during a cold load. A low-contrast wash derived from the local text token\n * reads as \"something is about to appear\" in any theme and inside any card.\n * The data attributes keep the state machine observable for tests/tooling.\n */\nfunction DynamicBlockSkeleton({ blockType }: { readonly blockType: string }): ReactNode {\n return (\n <div\n data-dynamic-block={blockType}\n data-state=\"loading\"\n aria-busy=\"true\"\n style={{\n minHeight: '24px',\n borderRadius: '8px',\n backgroundColor: 'color-mix(in srgb, var(--pw-color-text, #9ca3af) 6%, transparent)',\n }}\n />\n )\n}\n\n/**\n * Module-load failure. Same quiet-shape rule: no visible copy — the error\n * tint + dashed border carry the meaning, the technical message lives in the\n * title tooltip (and the loader already logs it), and the single retry\n * control is an icon button with an English aria-label.\n */\nfunction DynamicBlockError({\n blockType,\n error,\n onRetry,\n}: {\n readonly blockType: string\n readonly error: string\n readonly onRetry: () => void\n}): ReactNode {\n return (\n <div\n data-dynamic-block={blockType}\n data-state=\"error\"\n title={error}\n style={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n padding: '12px',\n border: '2px dashed var(--pw-color-error, #fca5a5)',\n borderRadius: '8px',\n backgroundColor: 'color-mix(in srgb, var(--pw-color-error, #ef4444) 8%, transparent)',\n minHeight: '48px',\n }}\n >\n <button\n type=\"button\"\n onClick={onRetry}\n aria-label={`Retry loading ${blockType}`}\n style={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n width: '28px',\n height: '28px',\n border: '1px solid var(--pw-color-error, #fca5a5)',\n borderRadius: '50%',\n backgroundColor: 'transparent',\n color: 'var(--pw-color-error, #991b1b)',\n cursor: 'pointer',\n padding: 0,\n }}\n >\n <svg\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth={2}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <path d=\"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8\" />\n <path d=\"M3 3v5h5\" />\n </svg>\n </button>\n </div>\n )\n}\n\n// ============================================================\n// WRAPPER COMPONENT\n// ============================================================\n\n/**\n * Wraps a dynamically loaded block component.\n * Manages loading → loaded | error state machine.\n */\nexport function DynamicBlockWrapper({\n descriptor,\n block,\n context,\n children,\n}: DynamicBlockWrapperProps): ReactNode {\n const [state, setState] = useState<LoadState>(\n BlockModuleLoader.isLoaded(descriptor.blockType) ? 'loaded' : 'idle'\n )\n const [component, setComponent] = useState<BlockComponent | null>(() =>\n BlockModuleLoader.getSync(descriptor.blockType)\n )\n const [errorMessage, setErrorMessage] = useState('')\n\n const loadModule = useCallback(() => {\n setComponent(null)\n setState('loading')\n setErrorMessage('')\n\n BlockModuleLoader.load(descriptor)\n .then((comp) => {\n setComponent(() => comp)\n setState('loaded')\n })\n .catch((err: unknown) => {\n const msg = err instanceof Error ? err.message : 'Unknown error'\n // The placeholder says it on the page; the console says it to whoever\n // is debugging a block that \"just does not render\".\n console.error(`[pwfabric] block \"${descriptor.blockType}\" failed to load: ${msg}`)\n setErrorMessage(msg)\n setState('error')\n })\n }, [descriptor])\n\n useEffect(() => {\n if (state === 'idle') {\n loadModule()\n }\n }, [state, loadModule])\n\n const handleRetry = useCallback(() => {\n BlockModuleLoader.invalidate(descriptor.blockType)\n loadModule()\n }, [descriptor.blockType, loadModule])\n\n // Component-first: if we have a loaded component, always render it regardless of\n // the state machine. This prevents the skeleton from flashing when state transitions\n // to 'loading' (e.g. retry) while the previous component is still valid in cache.\n if (component) {\n const Component = component\n // `props` is NEVER undefined. A node may legitimately carry no `props` key\n // at all — `{id, type, children}` is a valid section — and a block component\n // reads `props.x` directly, so handing it `undefined` throws inside the\n // component and the block renders as an error placeholder.\n //\n // A `section` authored without a `props` key would otherwise crash with\n // \"Cannot read properties of undefined (reading 'paddingY')\". The static\n // renderer guards this too (`renderer.tsx`: `block.props ?? {}`); this is\n // the path every PACK-INSTALLED block takes.\n return (\n <Component block={block} props={block.props ?? {}} context={context}>\n {children}\n </Component>\n )\n }\n\n if (state === 'error') {\n return (\n <DynamicBlockError\n blockType={descriptor.blockType}\n error={errorMessage}\n onRetry={handleRetry}\n />\n )\n }\n\n return <DynamicBlockSkeleton blockType={descriptor.blockType} />\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pwfabric/runtime",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "PWFabric runtime and execution engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "BUSL-1.1",
|
|
@@ -69,8 +69,8 @@
|
|
|
69
69
|
"node": ">=22"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@pwfabric/contracts": "1.0.0
|
|
73
|
-
"@pwfabric/core": "1.0.0
|
|
72
|
+
"@pwfabric/contracts": "1.0.0",
|
|
73
|
+
"@pwfabric/core": "1.0.0"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
76
|
"react": "^18.0.0 || ^19.0.0",
|