@designos/renderer-react 0.1.0 → 1.0.1
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 +21 -0
- package/dist/index.d.ts +9 -5
- package/dist/index.js +17 -6
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 relacloud
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ComponentType, ReactNode } from 'react';
|
|
3
|
-
import { PageDocument, ComponentRegistry, RuntimeResolverMap, RuntimeActionDispatcher, RuntimeActionRequest, RuntimeActionResult, ComponentRegistryContract } from '@designos/core';
|
|
3
|
+
import { PageDocument, DesignDocument, ComponentRegistry, RuntimeResolverMap, RuntimeActionDispatcher, RuntimeActionRequest, RuntimeActionResult, ComponentRegistryContract } from '@designos/core';
|
|
4
4
|
|
|
5
5
|
type ComponentMap = Record<string, ComponentType<any>>;
|
|
6
6
|
|
|
7
7
|
interface RenderProps {
|
|
8
|
-
|
|
8
|
+
page: PageDocument;
|
|
9
|
+
design: DesignDocument;
|
|
9
10
|
components: ComponentMap;
|
|
10
11
|
registry?: ComponentRegistry;
|
|
11
12
|
debug?: boolean;
|
|
@@ -20,7 +21,7 @@ interface RenderProps {
|
|
|
20
21
|
onResolutionError?: (error: Error, nodeId: string, componentType: string) => void;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
declare function Render({
|
|
24
|
+
declare function Render({ page, design, components, registry, debug, resolvers, dataContext, resolverRefreshKey, actionDispatcher, onResolutionError, }: RenderProps): react.JSX.Element;
|
|
24
25
|
|
|
25
26
|
interface RuntimeNodeContext {
|
|
26
27
|
nodeId: string;
|
|
@@ -41,11 +42,14 @@ interface ReactCompatibleRenderOptions {
|
|
|
41
42
|
missingComponent?: ComponentType<any>;
|
|
42
43
|
}
|
|
43
44
|
/** Stateless React-element projection shared by React-compatible runtime targets. */
|
|
44
|
-
declare function renderReactPage(
|
|
45
|
+
declare function renderReactPage(page: PageDocument, design: DesignDocument, components: ReactCompatibleComponentMap, options?: ReactCompatibleRenderOptions): ReactNode;
|
|
46
|
+
|
|
47
|
+
/** Convert a DesignDocument into the standard custom-property style record. */
|
|
48
|
+
declare function designStyle(design: DesignDocument): Record<string, string>;
|
|
45
49
|
|
|
46
50
|
declare const rendererTarget: {
|
|
47
51
|
readonly id: "react";
|
|
48
52
|
readonly kind: "runtime";
|
|
49
53
|
};
|
|
50
54
|
|
|
51
|
-
export { type ComponentMap, type ReactCompatibleComponentMap, type ReactCompatibleRenderOptions, Render, type RenderProps, RuntimeActionProvider, renderReactPage, rendererTarget, useDesignOSAction };
|
|
55
|
+
export { type ComponentMap, type ReactCompatibleComponentMap, type ReactCompatibleRenderOptions, Render, type RenderProps, RuntimeActionProvider, designStyle, renderReactPage, rendererTarget, useDesignOSAction };
|
package/dist/index.js
CHANGED
|
@@ -158,6 +158,7 @@ function useDesignOSAction() {
|
|
|
158
158
|
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
159
159
|
function RenderNode({
|
|
160
160
|
node,
|
|
161
|
+
design,
|
|
161
162
|
components,
|
|
162
163
|
registry,
|
|
163
164
|
debug,
|
|
@@ -177,6 +178,7 @@ function RenderNode({
|
|
|
177
178
|
RenderNode,
|
|
178
179
|
{
|
|
179
180
|
node: child,
|
|
181
|
+
design,
|
|
180
182
|
components,
|
|
181
183
|
registry,
|
|
182
184
|
debug,
|
|
@@ -204,7 +206,7 @@ function RenderNode({
|
|
|
204
206
|
" \u2022 ",
|
|
205
207
|
node.id
|
|
206
208
|
] }),
|
|
207
|
-
/* @__PURE__ */ jsx2(Component, { ...node.props, ...resolution.resolvedProps, designosRuntime: renderState, ...slots ? { slots } : {}, children })
|
|
209
|
+
/* @__PURE__ */ jsx2(Component, { ...node.props, ...resolution.resolvedProps, design, designosRuntime: renderState, ...slots ? { slots } : {}, children })
|
|
208
210
|
] });
|
|
209
211
|
}
|
|
210
212
|
|
|
@@ -234,7 +236,8 @@ var RendererErrorBoundary = class extends React.Component {
|
|
|
234
236
|
// src/components/Render.tsx
|
|
235
237
|
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
236
238
|
function Render({
|
|
237
|
-
|
|
239
|
+
page,
|
|
240
|
+
design,
|
|
238
241
|
components,
|
|
239
242
|
registry,
|
|
240
243
|
debug,
|
|
@@ -251,7 +254,8 @@ function Render({
|
|
|
251
254
|
return /* @__PURE__ */ jsx4(RuntimeResolutionSessionContext.Provider, { value: session, children: /* @__PURE__ */ jsx4(RendererErrorBoundary, { children: /* @__PURE__ */ jsx4(
|
|
252
255
|
RenderNode,
|
|
253
256
|
{
|
|
254
|
-
node:
|
|
257
|
+
node: page.root,
|
|
258
|
+
design,
|
|
255
259
|
components,
|
|
256
260
|
registry,
|
|
257
261
|
debug,
|
|
@@ -267,24 +271,31 @@ function Render({
|
|
|
267
271
|
// src/utils/render-page-react.ts
|
|
268
272
|
import { createElement, Fragment } from "react";
|
|
269
273
|
import { renderPageDocument } from "@designos/renderer-core";
|
|
270
|
-
function renderReactPage(
|
|
271
|
-
return renderPageDocument(
|
|
274
|
+
function renderReactPage(page, design, components, options = {}) {
|
|
275
|
+
return renderPageDocument(page, design, {
|
|
272
276
|
renderNode(view) {
|
|
273
277
|
const Component = components[view.node.type];
|
|
274
278
|
if (!Component) {
|
|
275
279
|
const Missing = options.missingComponent;
|
|
276
280
|
return Missing ? createElement(Missing, { componentType: view.node.type }, ...view.children) : createElement(Fragment, null, ...view.children);
|
|
277
281
|
}
|
|
278
|
-
return createElement(Component, { ...view.props, slots: view.slots }, ...view.children);
|
|
282
|
+
return createElement(Component, { ...view.props, design: view.design, slots: view.slots }, ...view.children);
|
|
279
283
|
}
|
|
280
284
|
}, { registry: options.registry });
|
|
281
285
|
}
|
|
282
286
|
|
|
287
|
+
// src/utils/design-style.ts
|
|
288
|
+
import { createDesignRuntime } from "@designos/renderer-core";
|
|
289
|
+
function designStyle(design) {
|
|
290
|
+
return createDesignRuntime(design).cssVariables();
|
|
291
|
+
}
|
|
292
|
+
|
|
283
293
|
// src/index.ts
|
|
284
294
|
var rendererTarget = { id: "react", kind: "runtime" };
|
|
285
295
|
export {
|
|
286
296
|
Render,
|
|
287
297
|
RuntimeActionProvider,
|
|
298
|
+
designStyle,
|
|
288
299
|
renderReactPage,
|
|
289
300
|
rendererTarget,
|
|
290
301
|
useDesignOSAction
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Render.tsx","../src/runtime/render-session.tsx","../src/components/RenderNode.tsx","../src/components/MissingComponent.tsx","../src/runtime/use-resolved-props.ts","../src/runtime/runtime-action-context.tsx","../src/components/RendererErrorBoundary.tsx","../src/utils/render-page-react.ts","../src/index.ts"],"sourcesContent":["import { useCallback, useRef } from \"react\";\nimport type { RenderProps } from \"../types/render-props\";\nimport type { PageNode } from \"@designos/core\";\nimport { RuntimeResolutionSessionContext } from \"../runtime/render-session\";\nimport { RenderNode } from \"./RenderNode\";\nimport { RendererErrorBoundary } from \"./RendererErrorBoundary\";\n\nexport function Render({\n data, components, registry, debug, resolvers, dataContext, resolverRefreshKey,\n actionDispatcher, onResolutionError,\n}: RenderProps) {\n const session = useRef(new Map()).current;\n const errorHandler = useCallback((error: Error, node: PageNode) => {\n onResolutionError?.(error, node.id, node.type);\n }, [onResolutionError]);\n return (\n <RuntimeResolutionSessionContext.Provider value={session}>\n <RendererErrorBoundary>\n <RenderNode\n node={data.root}\n components={components}\n registry={registry}\n debug={debug}\n resolvers={resolvers}\n dataContext={dataContext}\n resolverRefreshKey={resolverRefreshKey}\n actionDispatcher={actionDispatcher}\n onResolutionError={errorHandler}\n />\n </RendererErrorBoundary>\n </RuntimeResolutionSessionContext.Provider>\n );\n}\n","import { createContext, useContext } from \"react\";\n\nexport interface RuntimeNodeLocation {\n propsKey: string;\n dataKey: string;\n parentId?: string;\n slotName?: string;\n refreshKey: string;\n}\nexport type RuntimeResolutionSession = Map<string, RuntimeNodeLocation>;\nexport const RuntimeResolutionSessionContext = createContext<RuntimeResolutionSession | undefined>(undefined);\nexport function useRuntimeResolutionSession() {\n return useContext(RuntimeResolutionSessionContext);\n}\n","import type { ComponentRegistry, PageNode, RuntimeActionDispatcher, RuntimeResolverMap } from \"@designos/core\";\nimport { resolveNodeComposition } from \"@designos/renderer-core\";\nimport type { ComponentMap } from \"../types/component-map\";\nimport { MissingComponent } from \"./MissingComponent\";\nimport { useResolvedProps } from \"../runtime/use-resolved-props\";\nimport { RuntimeActionProvider } from \"../runtime/runtime-action-context\";\n\ninterface RenderNodeProps {\n node: PageNode;\n components: ComponentMap;\n registry?: ComponentRegistry;\n debug?: boolean;\n resolvers?: RuntimeResolverMap;\n dataContext?: unknown;\n resolverRefreshKey?: string | number;\n actionDispatcher?: RuntimeActionDispatcher;\n onResolutionError?: (error: Error, node: PageNode) => void;\n parentId?: string;\n slotName?: string;\n}\n\nexport function RenderNode({\n node, components, registry, debug, resolvers, dataContext, resolverRefreshKey,\n actionDispatcher, onResolutionError, parentId, slotName,\n}: RenderNodeProps) {\n const Component = components[node.type];\n const resolution = useResolvedProps(node, resolvers, dataContext, { parentId, slotName }, resolverRefreshKey, onResolutionError);\n if (!Component) return <MissingComponent type={node.type} />;\n\n const composition = resolveNodeComposition(node, registry);\n const renderChildren = (nodes: PageNode[], childSlotName?: string) => nodes.map((child) => (\n <RenderNode\n key={child.id}\n node={child}\n components={components}\n registry={registry}\n debug={debug}\n resolvers={resolvers}\n dataContext={dataContext}\n resolverRefreshKey={resolverRefreshKey}\n actionDispatcher={actionDispatcher}\n onResolutionError={onResolutionError}\n parentId={node.id}\n slotName={childSlotName}\n />\n ));\n const children = renderChildren(composition.children);\n const slots = Object.keys(composition.slots).length > 0\n ? Object.fromEntries(Object.entries(composition.slots).map(([name, nodes]) => [name, renderChildren(nodes, name)]))\n : undefined;\n\n const renderState = {\n authoredProps: node.props,\n resolvedProps: resolution.resolvedProps,\n status: resolution.status,\n error: resolution.error,\n } as const;\n\n return (\n <RuntimeActionProvider dispatcher={actionDispatcher} node={{ nodeId: node.id, componentType: node.type, dataContext }}>\n {debug && <div style={{ fontSize: \"11px\", color: \"#999\" }}>{node.type}{\" • \"}{node.id}</div>}\n <Component {...node.props} {...resolution.resolvedProps} designosRuntime={renderState} {...(slots ? { slots } : {})}>\n {children}\n </Component>\n </RuntimeActionProvider>\n );\n}\n","interface MissingComponentProps {\r\n type: string;\r\n}\r\n\r\nexport function MissingComponent({\r\n type\r\n}: MissingComponentProps) {\r\n\r\n return (\r\n <div\r\n style={{\r\n padding: \"12px\",\r\n border: \"1px solid red\",\r\n background: \"#fff4f4\",\r\n color: \"#cc0000\"\r\n }}\r\n >\r\n Missing Component:\r\n <strong>\r\n {\" \"}\r\n {type}\r\n </strong>\r\n </div>\r\n );\r\n}","import { useEffect, useMemo, useRef, useState } from \"react\";\nimport { createRuntimeDataCacheKey } from \"@designos/core\";\nimport type { PageNode, RuntimeDataResolver, RuntimeResolvedProps, RuntimeResolveTrigger, RuntimeResolverDefinition, RuntimeResolverMap } from \"@designos/core\";\nimport { useRuntimeResolutionSession } from \"./render-session\";\n\nexport interface ResolveLocation { parentId?: string; slotName?: string }\nexport interface ResolvedPropsState {\n resolvedProps: RuntimeResolvedProps;\n status: \"idle\" | \"loading\" | \"ready\" | \"error\";\n error?: Error;\n requestKey?: string;\n}\n\nfunction serialize(value: unknown): string {\n try { return JSON.stringify(value) ?? \"undefined\"; }\n catch { return \"[unserializable]\"; }\n}\n\nfunction definitionFor(value: RuntimeDataResolver | RuntimeResolverDefinition): RuntimeResolverDefinition {\n return typeof value === \"function\" ? { resolve: value } : value;\n}\n\nexport function useResolvedProps(\n node: PageNode,\n resolvers: RuntimeResolverMap | undefined,\n dataContext: unknown,\n location: ResolveLocation,\n refreshKey: string | number | undefined,\n onError?: (error: Error, node: PageNode) => void,\n): ResolvedPropsState {\n const resolverValue = resolvers?.[node.type];\n const resolveFunction = typeof resolverValue === \"function\" ? resolverValue : resolverValue?.resolve;\n const resolverCache = typeof resolverValue === \"function\" ? undefined : resolverValue?.cache;\n const cacheTtlMs = typeof resolverValue === \"function\" ? undefined : resolverValue?.cacheTtlMs;\n const definition = useMemo(() => resolverValue ? definitionFor(resolverValue) : undefined, [resolveFunction, resolverCache, cacheTtlMs]);\n const propsKey = serialize(node.props);\n const dataKey = serialize(dataContext);\n const refreshKeyValue = String(refreshKey ?? \"\");\n let cacheKey: string;\n let cacheKeyAvailable = true;\n try {\n cacheKey = createRuntimeDataCacheKey({\n componentType: node.type,\n nodeId: node.id,\n authoredProps: node.props,\n dataContext,\n parentId: location.parentId,\n slotName: location.slotName,\n });\n } catch {\n cacheKeyAvailable = false;\n cacheKey = `${node.type}:${node.id}:${propsKey}:${dataKey}:${location.parentId ?? \"\"}:${location.slotName ?? \"\"}`;\n }\n const [state, setState] = useState<ResolvedPropsState>({ resolvedProps: {}, status: definition ? \"loading\" : \"idle\" });\n const session = useRuntimeResolutionSession();\n const localPrevious = useRef<{ propsKey: string; dataKey: string; parentId?: string; slotName?: string; refreshKey: string } | undefined>(undefined);\n\n useEffect(() => {\n if (!definition) {\n setState({ resolvedProps: {}, status: \"idle\" });\n const currentLocation = { propsKey, dataKey, parentId: location.parentId, slotName: location.slotName, refreshKey: refreshKeyValue };\n localPrevious.current = currentLocation;\n session?.set(node.id, currentLocation);\n return;\n }\n\n const before = session?.get(node.id) ?? localPrevious.current;\n let trigger: RuntimeResolveTrigger = \"initial\";\n if (before) {\n if (before.refreshKey !== refreshKeyValue) trigger = \"forced\";\n else if (before.propsKey !== propsKey || before.dataKey !== dataKey) trigger = \"props-change\";\n else if (before.parentId !== location.parentId || before.slotName !== location.slotName) trigger = \"move\";\n }\n const currentLocation = { propsKey, parentId: location.parentId, slotName: location.slotName, refreshKey: refreshKeyValue, dataKey };\n localPrevious.current = currentLocation;\n session?.set(node.id, currentLocation);\n\n const controller = new AbortController();\n let active = true;\n const canUseCache = trigger !== \"forced\" && trigger !== \"move\";\n const cached = canUseCache && cacheKeyAvailable ? definition.cache?.get(cacheKey) : undefined;\n if (cached) {\n setState({ resolvedProps: cached, status: \"ready\", requestKey: cacheKey });\n return () => { active = false; controller.abort(); };\n }\n\n setState({ resolvedProps: {}, status: \"loading\", requestKey: cacheKey });\n Promise.resolve().then(() => definition.resolve({\n node,\n authoredProps: node.props,\n trigger,\n parentId: location.parentId,\n slotName: location.slotName,\n dataContext,\n signal: controller.signal,\n })).then((resolved) => {\n if (!active || controller.signal.aborted) return;\n const safeResult = { ...resolved };\n if (cacheKeyAvailable) definition.cache?.set(cacheKey, safeResult, definition.cacheTtlMs ?? 30_000);\n setState({ resolvedProps: safeResult, status: \"ready\", requestKey: cacheKey });\n }).catch((cause: unknown) => {\n if (!active || controller.signal.aborted) return;\n const error = cause instanceof Error ? cause : new Error(String(cause));\n setState({ resolvedProps: {}, status: \"error\", error, requestKey: cacheKey });\n onError?.(error, node);\n });\n\n return () => { active = false; controller.abort(); };\n }, [definition, node, propsKey, dataKey, dataContext, location.parentId, location.slotName, refreshKeyValue, cacheKey, cacheKeyAvailable, onError, session]);\n\n if (!definition) return { resolvedProps: {}, status: \"idle\" };\n return state.requestKey === cacheKey ? state : { resolvedProps: {}, status: \"loading\" };\n}\n","import { createContext, useContext } from \"react\";\nimport type { ReactNode } from \"react\";\nimport type { RuntimeActionDispatcher, RuntimeActionRequest, RuntimeActionResult } from \"@designos/core\";\n\ninterface RuntimeNodeContext { nodeId: string; componentType: string; dataContext?: unknown }\nconst Context = createContext<{ dispatcher?: RuntimeActionDispatcher; node?: RuntimeNodeContext }>({});\n\nexport function RuntimeActionProvider({ dispatcher, node, children }: {\n dispatcher?: RuntimeActionDispatcher;\n node?: RuntimeNodeContext;\n children: ReactNode;\n}) {\n return <Context.Provider value={{ dispatcher, node }}>{children}</Context.Provider>;\n}\n\n/** Called by runtime components; handler implementation and credentials remain host-owned. */\nexport function useDesignOSAction() {\n const { dispatcher, node } = useContext(Context);\n return async (action: Pick<RuntimeActionRequest, \"name\" | \"payload\">): Promise<RuntimeActionResult> => {\n if (!action.name.trim()) return { ok: false, error: \"Action name is required\", code: \"INVALID_ACTION\" };\n if (!dispatcher || !node) return { ok: false, error: \"No host action dispatcher is configured\", code: \"ACTION_UNAVAILABLE\" };\n try {\n return await dispatcher({ ...action, nodeId: node.nodeId, componentType: node.componentType, dataContext: node.dataContext });\n } catch (cause) {\n return { ok: false, error: cause instanceof Error ? cause.message : \"Action failed\", code: \"ACTION_FAILED\" };\n }\n };\n}\n","import React from \"react\";\r\n\r\ninterface Props {\r\n children: React.ReactNode;\r\n}\r\n\r\ninterface State {\r\n hasError: boolean;\r\n}\r\n\r\nexport class RendererErrorBoundary\r\nextends React.Component<\r\n Props,\r\n State\r\n> {\r\n\r\n constructor(\r\n props: Props\r\n ) {\r\n super(props);\r\n\r\n this.state = {\r\n hasError: false\r\n };\r\n }\r\n\r\n static getDerivedStateFromError() {\r\n\r\n return {\r\n hasError: true\r\n };\r\n }\r\n\r\n override render() {\r\n\r\n if (\r\n this.state.hasError\r\n ) {\r\n return (\r\n <div>\r\n Component rendering failed\r\n </div>\r\n );\r\n }\r\n\r\n return this.props.children;\r\n }\r\n}","import { createElement, Fragment, type ComponentType, type ReactNode } from \"react\";\nimport type { ComponentRegistryContract, PageDocument } from \"@designos/core\";\nimport { renderPageDocument } from \"@designos/renderer-core\";\n\nexport type ReactCompatibleComponentMap = Record<string, ComponentType<any>>;\n\nexport interface ReactCompatibleRenderOptions {\n registry?: ComponentRegistryContract;\n missingComponent?: ComponentType<any>;\n}\n\n/** Stateless React-element projection shared by React-compatible runtime targets. */\nexport function renderReactPage(\n data: PageDocument,\n components: ReactCompatibleComponentMap,\n options: ReactCompatibleRenderOptions = {},\n): ReactNode {\n return renderPageDocument<ReactNode>(data, {\n renderNode(view) {\n const Component = components[view.node.type];\n if (!Component) {\n const Missing = options.missingComponent;\n return Missing\n ? createElement(Missing, { componentType: view.node.type }, ...view.children)\n : createElement(Fragment, null, ...view.children);\n }\n return createElement(Component, { ...view.props, slots: view.slots }, ...view.children);\n },\n }, { registry: options.registry });\n}\n","export * from \"./components/Render\";\n\nexport * from \"./types/component-map\";\nexport * from \"./types/render-props\";\nexport * from \"./runtime/runtime-action-context\";\nexport * from \"./utils/render-page-react\";\n\nexport const rendererTarget = { id: \"react\", kind: \"runtime\" } as const;\n"],"mappings":";AAAA,SAAS,aAAa,UAAAA,eAAc;;;ACApC,SAAS,eAAe,kBAAkB;AAUnC,IAAM,kCAAkC,cAAoD,MAAS;AACrG,SA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AG,GAAG,KAAK,QAAQ;AAAA,IACxF;AAAA,EACF,GAAG,EAAE,UAAU,QAAQ,SAAS,CAAC;AACnC;;;ACtBO,IAAM,iBAAiB,EAAE,IAAI,SAAS,MAAM,UAAU;","names":["useRef","currentLocation","createContext","useContext","jsx","jsxs","jsx","jsx","useRef"]}
|
|
1
|
+
{"version":3,"sources":["../src/components/Render.tsx","../src/runtime/render-session.tsx","../src/components/RenderNode.tsx","../src/components/MissingComponent.tsx","../src/runtime/use-resolved-props.ts","../src/runtime/runtime-action-context.tsx","../src/components/RendererErrorBoundary.tsx","../src/utils/render-page-react.ts","../src/utils/design-style.ts","../src/index.ts"],"sourcesContent":["import { useCallback, useRef } from \"react\";\nimport type { RenderProps } from \"../types/render-props\";\nimport type { PageNode } from \"@designos/core\";\nimport { RuntimeResolutionSessionContext } from \"../runtime/render-session\";\nimport { RenderNode } from \"./RenderNode\";\nimport { RendererErrorBoundary } from \"./RendererErrorBoundary\";\n\nexport function Render({\n page, design, components, registry, debug, resolvers, dataContext, resolverRefreshKey,\n actionDispatcher, onResolutionError,\n}: RenderProps) {\n const session = useRef(new Map()).current;\n const errorHandler = useCallback((error: Error, node: PageNode) => {\n onResolutionError?.(error, node.id, node.type);\n }, [onResolutionError]);\n return (\n <RuntimeResolutionSessionContext.Provider value={session}>\n <RendererErrorBoundary>\n <RenderNode\n node={page.root}\n design={design}\n components={components}\n registry={registry}\n debug={debug}\n resolvers={resolvers}\n dataContext={dataContext}\n resolverRefreshKey={resolverRefreshKey}\n actionDispatcher={actionDispatcher}\n onResolutionError={errorHandler}\n />\n </RendererErrorBoundary>\n </RuntimeResolutionSessionContext.Provider>\n );\n}\n","import { createContext, useContext } from \"react\";\n\nexport interface RuntimeNodeLocation {\n propsKey: string;\n dataKey: string;\n parentId?: string;\n slotName?: string;\n refreshKey: string;\n}\nexport type RuntimeResolutionSession = Map<string, RuntimeNodeLocation>;\nexport const RuntimeResolutionSessionContext = createContext<RuntimeResolutionSession | undefined>(undefined);\nexport function useRuntimeResolutionSession() {\n return useContext(RuntimeResolutionSessionContext);\n}\n","import type { ComponentRegistry, DesignDocument, PageNode, RuntimeActionDispatcher, RuntimeResolverMap } from \"@designos/core\";\nimport { resolveNodeComposition } from \"@designos/renderer-core\";\nimport type { ComponentMap } from \"../types/component-map\";\nimport { MissingComponent } from \"./MissingComponent\";\nimport { useResolvedProps } from \"../runtime/use-resolved-props\";\nimport { RuntimeActionProvider } from \"../runtime/runtime-action-context\";\n\ninterface RenderNodeProps {\n node: PageNode;\n design: DesignDocument;\n components: ComponentMap;\n registry?: ComponentRegistry;\n debug?: boolean;\n resolvers?: RuntimeResolverMap;\n dataContext?: unknown;\n resolverRefreshKey?: string | number;\n actionDispatcher?: RuntimeActionDispatcher;\n onResolutionError?: (error: Error, node: PageNode) => void;\n parentId?: string;\n slotName?: string;\n}\n\nexport function RenderNode({\n node, design, components, registry, debug, resolvers, dataContext, resolverRefreshKey,\n actionDispatcher, onResolutionError, parentId, slotName,\n}: RenderNodeProps) {\n const Component = components[node.type];\n const resolution = useResolvedProps(node, resolvers, dataContext, { parentId, slotName }, resolverRefreshKey, onResolutionError);\n if (!Component) return <MissingComponent type={node.type} />;\n\n const composition = resolveNodeComposition(node, registry);\n const renderChildren = (nodes: PageNode[], childSlotName?: string) => nodes.map((child) => (\n <RenderNode\n key={child.id}\n node={child}\n design={design}\n components={components}\n registry={registry}\n debug={debug}\n resolvers={resolvers}\n dataContext={dataContext}\n resolverRefreshKey={resolverRefreshKey}\n actionDispatcher={actionDispatcher}\n onResolutionError={onResolutionError}\n parentId={node.id}\n slotName={childSlotName}\n />\n ));\n const children = renderChildren(composition.children);\n const slots = Object.keys(composition.slots).length > 0\n ? Object.fromEntries(Object.entries(composition.slots).map(([name, nodes]) => [name, renderChildren(nodes, name)]))\n : undefined;\n\n const renderState = {\n authoredProps: node.props,\n resolvedProps: resolution.resolvedProps,\n status: resolution.status,\n error: resolution.error,\n } as const;\n\n return (\n <RuntimeActionProvider dispatcher={actionDispatcher} node={{ nodeId: node.id, componentType: node.type, dataContext }}>\n {debug && <div style={{ fontSize: \"11px\", color: \"#999\" }}>{node.type}{\" • \"}{node.id}</div>}\n <Component {...node.props} {...resolution.resolvedProps} design={design} designosRuntime={renderState} {...(slots ? { slots } : {})}>\n {children}\n </Component>\n </RuntimeActionProvider>\n );\n}\n","interface MissingComponentProps {\r\n type: string;\r\n}\r\n\r\nexport function MissingComponent({\r\n type\r\n}: MissingComponentProps) {\r\n\r\n return (\r\n <div\r\n style={{\r\n padding: \"12px\",\r\n border: \"1px solid red\",\r\n background: \"#fff4f4\",\r\n color: \"#cc0000\"\r\n }}\r\n >\r\n Missing Component:\r\n <strong>\r\n {\" \"}\r\n {type}\r\n </strong>\r\n </div>\r\n );\r\n}","import { useEffect, useMemo, useRef, useState } from \"react\";\nimport { createRuntimeDataCacheKey } from \"@designos/core\";\nimport type { PageNode, RuntimeDataResolver, RuntimeResolvedProps, RuntimeResolveTrigger, RuntimeResolverDefinition, RuntimeResolverMap } from \"@designos/core\";\nimport { useRuntimeResolutionSession } from \"./render-session\";\n\nexport interface ResolveLocation { parentId?: string; slotName?: string }\nexport interface ResolvedPropsState {\n resolvedProps: RuntimeResolvedProps;\n status: \"idle\" | \"loading\" | \"ready\" | \"error\";\n error?: Error;\n requestKey?: string;\n}\n\nfunction serialize(value: unknown): string {\n try { return JSON.stringify(value) ?? \"undefined\"; }\n catch { return \"[unserializable]\"; }\n}\n\nfunction definitionFor(value: RuntimeDataResolver | RuntimeResolverDefinition): RuntimeResolverDefinition {\n return typeof value === \"function\" ? { resolve: value } : value;\n}\n\nexport function useResolvedProps(\n node: PageNode,\n resolvers: RuntimeResolverMap | undefined,\n dataContext: unknown,\n location: ResolveLocation,\n refreshKey: string | number | undefined,\n onError?: (error: Error, node: PageNode) => void,\n): ResolvedPropsState {\n const resolverValue = resolvers?.[node.type];\n const resolveFunction = typeof resolverValue === \"function\" ? resolverValue : resolverValue?.resolve;\n const resolverCache = typeof resolverValue === \"function\" ? undefined : resolverValue?.cache;\n const cacheTtlMs = typeof resolverValue === \"function\" ? undefined : resolverValue?.cacheTtlMs;\n const definition = useMemo(() => resolverValue ? definitionFor(resolverValue) : undefined, [resolveFunction, resolverCache, cacheTtlMs]);\n const propsKey = serialize(node.props);\n const dataKey = serialize(dataContext);\n const refreshKeyValue = String(refreshKey ?? \"\");\n let cacheKey: string;\n let cacheKeyAvailable = true;\n try {\n cacheKey = createRuntimeDataCacheKey({\n componentType: node.type,\n nodeId: node.id,\n authoredProps: node.props,\n dataContext,\n parentId: location.parentId,\n slotName: location.slotName,\n });\n } catch {\n cacheKeyAvailable = false;\n cacheKey = `${node.type}:${node.id}:${propsKey}:${dataKey}:${location.parentId ?? \"\"}:${location.slotName ?? \"\"}`;\n }\n const [state, setState] = useState<ResolvedPropsState>({ resolvedProps: {}, status: definition ? \"loading\" : \"idle\" });\n const session = useRuntimeResolutionSession();\n const localPrevious = useRef<{ propsKey: string; dataKey: string; parentId?: string; slotName?: string; refreshKey: string } | undefined>(undefined);\n\n useEffect(() => {\n if (!definition) {\n setState({ resolvedProps: {}, status: \"idle\" });\n const currentLocation = { propsKey, dataKey, parentId: location.parentId, slotName: location.slotName, refreshKey: refreshKeyValue };\n localPrevious.current = currentLocation;\n session?.set(node.id, currentLocation);\n return;\n }\n\n const before = session?.get(node.id) ?? localPrevious.current;\n let trigger: RuntimeResolveTrigger = \"initial\";\n if (before) {\n if (before.refreshKey !== refreshKeyValue) trigger = \"forced\";\n else if (before.propsKey !== propsKey || before.dataKey !== dataKey) trigger = \"props-change\";\n else if (before.parentId !== location.parentId || before.slotName !== location.slotName) trigger = \"move\";\n }\n const currentLocation = { propsKey, parentId: location.parentId, slotName: location.slotName, refreshKey: refreshKeyValue, dataKey };\n localPrevious.current = currentLocation;\n session?.set(node.id, currentLocation);\n\n const controller = new AbortController();\n let active = true;\n const canUseCache = trigger !== \"forced\" && trigger !== \"move\";\n const cached = canUseCache && cacheKeyAvailable ? definition.cache?.get(cacheKey) : undefined;\n if (cached) {\n setState({ resolvedProps: cached, status: \"ready\", requestKey: cacheKey });\n return () => { active = false; controller.abort(); };\n }\n\n setState({ resolvedProps: {}, status: \"loading\", requestKey: cacheKey });\n Promise.resolve().then(() => definition.resolve({\n node,\n authoredProps: node.props,\n trigger,\n parentId: location.parentId,\n slotName: location.slotName,\n dataContext,\n signal: controller.signal,\n })).then((resolved) => {\n if (!active || controller.signal.aborted) return;\n const safeResult = { ...resolved };\n if (cacheKeyAvailable) definition.cache?.set(cacheKey, safeResult, definition.cacheTtlMs ?? 30_000);\n setState({ resolvedProps: safeResult, status: \"ready\", requestKey: cacheKey });\n }).catch((cause: unknown) => {\n if (!active || controller.signal.aborted) return;\n const error = cause instanceof Error ? cause : new Error(String(cause));\n setState({ resolvedProps: {}, status: \"error\", error, requestKey: cacheKey });\n onError?.(error, node);\n });\n\n return () => { active = false; controller.abort(); };\n }, [definition, node, propsKey, dataKey, dataContext, location.parentId, location.slotName, refreshKeyValue, cacheKey, cacheKeyAvailable, onError, session]);\n\n if (!definition) return { resolvedProps: {}, status: \"idle\" };\n return state.requestKey === cacheKey ? state : { resolvedProps: {}, status: \"loading\" };\n}\n","import { createContext, useContext } from \"react\";\nimport type { ReactNode } from \"react\";\nimport type { RuntimeActionDispatcher, RuntimeActionRequest, RuntimeActionResult } from \"@designos/core\";\n\ninterface RuntimeNodeContext { nodeId: string; componentType: string; dataContext?: unknown }\nconst Context = createContext<{ dispatcher?: RuntimeActionDispatcher; node?: RuntimeNodeContext }>({});\n\nexport function RuntimeActionProvider({ dispatcher, node, children }: {\n dispatcher?: RuntimeActionDispatcher;\n node?: RuntimeNodeContext;\n children: ReactNode;\n}) {\n return <Context.Provider value={{ dispatcher, node }}>{children}</Context.Provider>;\n}\n\n/** Called by runtime components; handler implementation and credentials remain host-owned. */\nexport function useDesignOSAction() {\n const { dispatcher, node } = useContext(Context);\n return async (action: Pick<RuntimeActionRequest, \"name\" | \"payload\">): Promise<RuntimeActionResult> => {\n if (!action.name.trim()) return { ok: false, error: \"Action name is required\", code: \"INVALID_ACTION\" };\n if (!dispatcher || !node) return { ok: false, error: \"No host action dispatcher is configured\", code: \"ACTION_UNAVAILABLE\" };\n try {\n return await dispatcher({ ...action, nodeId: node.nodeId, componentType: node.componentType, dataContext: node.dataContext });\n } catch (cause) {\n return { ok: false, error: cause instanceof Error ? cause.message : \"Action failed\", code: \"ACTION_FAILED\" };\n }\n };\n}\n","import React from \"react\";\r\n\r\ninterface Props {\r\n children: React.ReactNode;\r\n}\r\n\r\ninterface State {\r\n hasError: boolean;\r\n}\r\n\r\nexport class RendererErrorBoundary\r\nextends React.Component<\r\n Props,\r\n State\r\n> {\r\n\r\n constructor(\r\n props: Props\r\n ) {\r\n super(props);\r\n\r\n this.state = {\r\n hasError: false\r\n };\r\n }\r\n\r\n static getDerivedStateFromError() {\r\n\r\n return {\r\n hasError: true\r\n };\r\n }\r\n\r\n override render() {\r\n\r\n if (\r\n this.state.hasError\r\n ) {\r\n return (\r\n <div>\r\n Component rendering failed\r\n </div>\r\n );\r\n }\r\n\r\n return this.props.children;\r\n }\r\n}","import { createElement, Fragment, type ComponentType, type ReactNode } from \"react\";\nimport type { ComponentRegistryContract, DesignDocument, PageDocument } from \"@designos/core\";\nimport { renderPageDocument } from \"@designos/renderer-core\";\n\nexport type ReactCompatibleComponentMap = Record<string, ComponentType<any>>;\n\nexport interface ReactCompatibleRenderOptions {\n registry?: ComponentRegistryContract;\n missingComponent?: ComponentType<any>;\n}\n\n/** Stateless React-element projection shared by React-compatible runtime targets. */\nexport function renderReactPage(\n page: PageDocument,\n design: DesignDocument,\n components: ReactCompatibleComponentMap,\n options: ReactCompatibleRenderOptions = {},\n): ReactNode {\n return renderPageDocument<ReactNode>(page, design, {\n renderNode(view) {\n const Component = components[view.node.type];\n if (!Component) {\n const Missing = options.missingComponent;\n return Missing\n ? createElement(Missing, { componentType: view.node.type }, ...view.children)\n : createElement(Fragment, null, ...view.children);\n }\n return createElement(Component, { ...view.props, design: view.design, slots: view.slots }, ...view.children);\n },\n }, { registry: options.registry });\n}\n","import type { DesignDocument } from \"@designos/core\";\nimport { createDesignRuntime } from \"@designos/renderer-core\";\n\n/** Convert a DesignDocument into the standard custom-property style record. */\nexport function designStyle(design: DesignDocument): Record<string, string> {\n return createDesignRuntime(design).cssVariables();\n}\n","export * from \"./components/Render\";\n\nexport * from \"./types/component-map\";\nexport * from \"./types/render-props\";\nexport * from \"./runtime/runtime-action-context\";\nexport * from \"./utils/render-page-react\";\nexport * from \"./utils/design-style\";\n\nexport const rendererTarget = { id: \"react\", kind: \"runtime\" } as const;\n"],"mappings":";AAAA,SAAS,aAAa,UAAAA,eAAc;;;ACApC,SAAS,eAAe,kBAAkB;AAUnC,IAAM,kCAAkC,cAAoD,MAAS;AACrG,SAAS,8BAA8B;AAC5C,SAAO,WAAW,+BAA+B;AACnD;;;ACZA,SAAS,8BAA8B;;;ACiBjC;AAdC,SAAS,iBAAiB;AAAA,EAC/B;AACF,GAA0B;AAExB,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO;AAAA,QACL,SAAS;AAAA,QACT,QAAQ;AAAA,QACR,YAAY;AAAA,QACZ,OAAO;AAAA,MACT;AAAA,MACD;AAAA;AAAA,QAEC,qBAAC,YACE;AAAA;AAAA,UACA;AAAA,WACH;AAAA;AAAA;AAAA,EACF;AAEJ;;;ACxBA,SAAS,WAAW,SAAS,QAAQ,gBAAgB;AACrD,SAAS,iCAAiC;AAY1C,SAAS,UAAU,OAAwB;AACzC,MAAI;AAAE,WAAO,KAAK,UAAU,KAAK,KAAK;AAAA,EAAa,QAC7C;AAAE,WAAO;AAAA,EAAoB;AACrC;AAEA,SAAS,cAAc,OAAmF;AACxG,SAAO,OAAO,UAAU,aAAa,EAAE,SAAS,MAAM,IAAI;AAC5D;AAEO,SAAS,iBACd,MACA,WACA,aACA,UACA,YACA,SACoB;AACpB,QAAM,gBAAgB,YAAY,KAAK,IAAI;AAC3C,QAAM,kBA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AA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,mBAAmB;AAAA;AAAA,EACrB,GACF,GACF;AAEJ;;;AOjCA,SAAS,eAAe,gBAAoD;AAE5E,SAAS,0BAA0B;AAU5B,SAAS,gBACd,MACA,QACA,YACA,UAAwC,CAAC,GAC9B;AACX,SAAO,mBAA8B,MAAM,QAAQ;AAAA,IACjD,WAAW,MAAM;AACf,YAAM,YAAY,WAAW,KAAK,KAAK,IAAI;AAC3C,UAAI,CAAC,WAAW;AACd,cAAM,UAAU,QAAQ;AACxB,eAAO,UACH,cAAc,SAAS,EAAE,eAAe,KAAK,KAAK,KAAK,GAAG,GAAG,KAAK,QAAQ,IAC1E,cAAc,UAAU,MAAM,GAAG,KAAK,QAAQ;AAAA,MACpD;AACA,aAAO,cAAc,WAAW,EAAE,GAAG,KAAK,OAAO,QAAQ,KAAK,QAAQ,OAAO,KAAK,MAAM,GAAG,GAAG,KAAK,QAAQ;AAAA,IAC7G;AAAA,EACF,GAAG,EAAE,UAAU,QAAQ,SAAS,CAAC;AACnC;;;AC7BA,SAAS,2BAA2B;AAG7B,SAAS,YAAY,QAAgD;AAC1E,SAAO,oBAAoB,MAAM,EAAE,aAAa;AAClD;;;ACEO,IAAM,iBAAiB,EAAE,IAAI,SAAS,MAAM,UAAU;","names":["useRef","currentLocation","createContext","useContext","jsx","jsxs","jsx","jsx","useRef"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@designos/renderer-react",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"license": "MIT",
|
|
4
5
|
"private": false,
|
|
5
6
|
"type": "module",
|
|
6
7
|
"exports": {
|
|
@@ -14,8 +15,8 @@
|
|
|
14
15
|
"react-dom": "^19.0.0"
|
|
15
16
|
},
|
|
16
17
|
"dependencies": {
|
|
17
|
-
"@designos/core": "0.1
|
|
18
|
-
"@designos/renderer-core": "0.1
|
|
18
|
+
"@designos/core": "0.2.1",
|
|
19
|
+
"@designos/renderer-core": "1.0.1"
|
|
19
20
|
},
|
|
20
21
|
"devDependencies": {
|
|
21
22
|
"@types/react": "^19.1.12",
|