@designos/renderer-react 0.0.0-stage → 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.
@@ -0,0 +1,55 @@
1
+ import * as react from 'react';
2
+ import { ComponentType, ReactNode } from 'react';
3
+ import { PageDocument, DesignDocument, ComponentRegistry, RuntimeResolverMap, RuntimeActionDispatcher, RuntimeActionRequest, RuntimeActionResult, ComponentRegistryContract } from '@designos/core';
4
+
5
+ type ComponentMap = Record<string, ComponentType<any>>;
6
+
7
+ interface RenderProps {
8
+ page: PageDocument;
9
+ design: DesignDocument;
10
+ components: ComponentMap;
11
+ registry?: ComponentRegistry;
12
+ debug?: boolean;
13
+ /** Optional host-owned derived-data resolver map. */
14
+ resolvers?: RuntimeResolverMap;
15
+ /** Request-scoped context; never serialized into PageDocument. */
16
+ dataContext?: unknown;
17
+ /** Change this key to force a resolver pass (e.g. explicit refresh). */
18
+ resolverRefreshKey?: string | number;
19
+ /** Host integration boundary for forms/navigation/analytics; not authored page data. */
20
+ actionDispatcher?: RuntimeActionDispatcher;
21
+ onResolutionError?: (error: Error, nodeId: string, componentType: string) => void;
22
+ }
23
+
24
+ declare function Render({ page, design, components, registry, debug, resolvers, dataContext, resolverRefreshKey, actionDispatcher, onResolutionError, }: RenderProps): react.JSX.Element;
25
+
26
+ interface RuntimeNodeContext {
27
+ nodeId: string;
28
+ componentType: string;
29
+ dataContext?: unknown;
30
+ }
31
+ declare function RuntimeActionProvider({ dispatcher, node, children }: {
32
+ dispatcher?: RuntimeActionDispatcher;
33
+ node?: RuntimeNodeContext;
34
+ children: ReactNode;
35
+ }): react.JSX.Element;
36
+ /** Called by runtime components; handler implementation and credentials remain host-owned. */
37
+ declare function useDesignOSAction(): (action: Pick<RuntimeActionRequest, "name" | "payload">) => Promise<RuntimeActionResult>;
38
+
39
+ type ReactCompatibleComponentMap = Record<string, ComponentType<any>>;
40
+ interface ReactCompatibleRenderOptions {
41
+ registry?: ComponentRegistryContract;
42
+ missingComponent?: ComponentType<any>;
43
+ }
44
+ /** Stateless React-element projection shared by React-compatible runtime targets. */
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>;
49
+
50
+ declare const rendererTarget: {
51
+ readonly id: "react";
52
+ readonly kind: "runtime";
53
+ };
54
+
55
+ export { type ComponentMap, type ReactCompatibleComponentMap, type ReactCompatibleRenderOptions, Render, type RenderProps, RuntimeActionProvider, designStyle, renderReactPage, rendererTarget, useDesignOSAction };
package/dist/index.js ADDED
@@ -0,0 +1,303 @@
1
+ // src/components/Render.tsx
2
+ import { useCallback, useRef as useRef2 } from "react";
3
+
4
+ // src/runtime/render-session.tsx
5
+ import { createContext, useContext } from "react";
6
+ var RuntimeResolutionSessionContext = createContext(void 0);
7
+ function useRuntimeResolutionSession() {
8
+ return useContext(RuntimeResolutionSessionContext);
9
+ }
10
+
11
+ // src/components/RenderNode.tsx
12
+ import { resolveNodeComposition } from "@designos/renderer-core";
13
+
14
+ // src/components/MissingComponent.tsx
15
+ import { jsxs } from "react/jsx-runtime";
16
+ function MissingComponent({
17
+ type
18
+ }) {
19
+ return /* @__PURE__ */ jsxs(
20
+ "div",
21
+ {
22
+ style: {
23
+ padding: "12px",
24
+ border: "1px solid red",
25
+ background: "#fff4f4",
26
+ color: "#cc0000"
27
+ },
28
+ children: [
29
+ "Missing Component:",
30
+ /* @__PURE__ */ jsxs("strong", { children: [
31
+ " ",
32
+ type
33
+ ] })
34
+ ]
35
+ }
36
+ );
37
+ }
38
+
39
+ // src/runtime/use-resolved-props.ts
40
+ import { useEffect, useMemo, useRef, useState } from "react";
41
+ import { createRuntimeDataCacheKey } from "@designos/core";
42
+ function serialize(value) {
43
+ try {
44
+ return JSON.stringify(value) ?? "undefined";
45
+ } catch {
46
+ return "[unserializable]";
47
+ }
48
+ }
49
+ function definitionFor(value) {
50
+ return typeof value === "function" ? { resolve: value } : value;
51
+ }
52
+ function useResolvedProps(node, resolvers, dataContext, location, refreshKey, onError) {
53
+ const resolverValue = resolvers?.[node.type];
54
+ const resolveFunction = typeof resolverValue === "function" ? resolverValue : resolverValue?.resolve;
55
+ const resolverCache = typeof resolverValue === "function" ? void 0 : resolverValue?.cache;
56
+ const cacheTtlMs = typeof resolverValue === "function" ? void 0 : resolverValue?.cacheTtlMs;
57
+ const definition = useMemo(() => resolverValue ? definitionFor(resolverValue) : void 0, [resolveFunction, resolverCache, cacheTtlMs]);
58
+ const propsKey = serialize(node.props);
59
+ const dataKey = serialize(dataContext);
60
+ const refreshKeyValue = String(refreshKey ?? "");
61
+ let cacheKey;
62
+ let cacheKeyAvailable = true;
63
+ try {
64
+ cacheKey = createRuntimeDataCacheKey({
65
+ componentType: node.type,
66
+ nodeId: node.id,
67
+ authoredProps: node.props,
68
+ dataContext,
69
+ parentId: location.parentId,
70
+ slotName: location.slotName
71
+ });
72
+ } catch {
73
+ cacheKeyAvailable = false;
74
+ cacheKey = `${node.type}:${node.id}:${propsKey}:${dataKey}:${location.parentId ?? ""}:${location.slotName ?? ""}`;
75
+ }
76
+ const [state, setState] = useState({ resolvedProps: {}, status: definition ? "loading" : "idle" });
77
+ const session = useRuntimeResolutionSession();
78
+ const localPrevious = useRef(void 0);
79
+ useEffect(() => {
80
+ if (!definition) {
81
+ setState({ resolvedProps: {}, status: "idle" });
82
+ const currentLocation2 = { propsKey, dataKey, parentId: location.parentId, slotName: location.slotName, refreshKey: refreshKeyValue };
83
+ localPrevious.current = currentLocation2;
84
+ session?.set(node.id, currentLocation2);
85
+ return;
86
+ }
87
+ const before = session?.get(node.id) ?? localPrevious.current;
88
+ let trigger = "initial";
89
+ if (before) {
90
+ if (before.refreshKey !== refreshKeyValue) trigger = "forced";
91
+ else if (before.propsKey !== propsKey || before.dataKey !== dataKey) trigger = "props-change";
92
+ else if (before.parentId !== location.parentId || before.slotName !== location.slotName) trigger = "move";
93
+ }
94
+ const currentLocation = { propsKey, parentId: location.parentId, slotName: location.slotName, refreshKey: refreshKeyValue, dataKey };
95
+ localPrevious.current = currentLocation;
96
+ session?.set(node.id, currentLocation);
97
+ const controller = new AbortController();
98
+ let active = true;
99
+ const canUseCache = trigger !== "forced" && trigger !== "move";
100
+ const cached = canUseCache && cacheKeyAvailable ? definition.cache?.get(cacheKey) : void 0;
101
+ if (cached) {
102
+ setState({ resolvedProps: cached, status: "ready", requestKey: cacheKey });
103
+ return () => {
104
+ active = false;
105
+ controller.abort();
106
+ };
107
+ }
108
+ setState({ resolvedProps: {}, status: "loading", requestKey: cacheKey });
109
+ Promise.resolve().then(() => definition.resolve({
110
+ node,
111
+ authoredProps: node.props,
112
+ trigger,
113
+ parentId: location.parentId,
114
+ slotName: location.slotName,
115
+ dataContext,
116
+ signal: controller.signal
117
+ })).then((resolved) => {
118
+ if (!active || controller.signal.aborted) return;
119
+ const safeResult = { ...resolved };
120
+ if (cacheKeyAvailable) definition.cache?.set(cacheKey, safeResult, definition.cacheTtlMs ?? 3e4);
121
+ setState({ resolvedProps: safeResult, status: "ready", requestKey: cacheKey });
122
+ }).catch((cause) => {
123
+ if (!active || controller.signal.aborted) return;
124
+ const error = cause instanceof Error ? cause : new Error(String(cause));
125
+ setState({ resolvedProps: {}, status: "error", error, requestKey: cacheKey });
126
+ onError?.(error, node);
127
+ });
128
+ return () => {
129
+ active = false;
130
+ controller.abort();
131
+ };
132
+ }, [definition, node, propsKey, dataKey, dataContext, location.parentId, location.slotName, refreshKeyValue, cacheKey, cacheKeyAvailable, onError, session]);
133
+ if (!definition) return { resolvedProps: {}, status: "idle" };
134
+ return state.requestKey === cacheKey ? state : { resolvedProps: {}, status: "loading" };
135
+ }
136
+
137
+ // src/runtime/runtime-action-context.tsx
138
+ import { createContext as createContext2, useContext as useContext2 } from "react";
139
+ import { jsx } from "react/jsx-runtime";
140
+ var Context = createContext2({});
141
+ function RuntimeActionProvider({ dispatcher, node, children }) {
142
+ return /* @__PURE__ */ jsx(Context.Provider, { value: { dispatcher, node }, children });
143
+ }
144
+ function useDesignOSAction() {
145
+ const { dispatcher, node } = useContext2(Context);
146
+ return async (action) => {
147
+ if (!action.name.trim()) return { ok: false, error: "Action name is required", code: "INVALID_ACTION" };
148
+ if (!dispatcher || !node) return { ok: false, error: "No host action dispatcher is configured", code: "ACTION_UNAVAILABLE" };
149
+ try {
150
+ return await dispatcher({ ...action, nodeId: node.nodeId, componentType: node.componentType, dataContext: node.dataContext });
151
+ } catch (cause) {
152
+ return { ok: false, error: cause instanceof Error ? cause.message : "Action failed", code: "ACTION_FAILED" };
153
+ }
154
+ };
155
+ }
156
+
157
+ // src/components/RenderNode.tsx
158
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
159
+ function RenderNode({
160
+ node,
161
+ design,
162
+ components,
163
+ registry,
164
+ debug,
165
+ resolvers,
166
+ dataContext,
167
+ resolverRefreshKey,
168
+ actionDispatcher,
169
+ onResolutionError,
170
+ parentId,
171
+ slotName
172
+ }) {
173
+ const Component = components[node.type];
174
+ const resolution = useResolvedProps(node, resolvers, dataContext, { parentId, slotName }, resolverRefreshKey, onResolutionError);
175
+ if (!Component) return /* @__PURE__ */ jsx2(MissingComponent, { type: node.type });
176
+ const composition = resolveNodeComposition(node, registry);
177
+ const renderChildren = (nodes, childSlotName) => nodes.map((child) => /* @__PURE__ */ jsx2(
178
+ RenderNode,
179
+ {
180
+ node: child,
181
+ design,
182
+ components,
183
+ registry,
184
+ debug,
185
+ resolvers,
186
+ dataContext,
187
+ resolverRefreshKey,
188
+ actionDispatcher,
189
+ onResolutionError,
190
+ parentId: node.id,
191
+ slotName: childSlotName
192
+ },
193
+ child.id
194
+ ));
195
+ const children = renderChildren(composition.children);
196
+ const slots = Object.keys(composition.slots).length > 0 ? Object.fromEntries(Object.entries(composition.slots).map(([name, nodes]) => [name, renderChildren(nodes, name)])) : void 0;
197
+ const renderState = {
198
+ authoredProps: node.props,
199
+ resolvedProps: resolution.resolvedProps,
200
+ status: resolution.status,
201
+ error: resolution.error
202
+ };
203
+ return /* @__PURE__ */ jsxs2(RuntimeActionProvider, { dispatcher: actionDispatcher, node: { nodeId: node.id, componentType: node.type, dataContext }, children: [
204
+ debug && /* @__PURE__ */ jsxs2("div", { style: { fontSize: "11px", color: "#999" }, children: [
205
+ node.type,
206
+ " \u2022 ",
207
+ node.id
208
+ ] }),
209
+ /* @__PURE__ */ jsx2(Component, { ...node.props, ...resolution.resolvedProps, design, designosRuntime: renderState, ...slots ? { slots } : {}, children })
210
+ ] });
211
+ }
212
+
213
+ // src/components/RendererErrorBoundary.tsx
214
+ import React from "react";
215
+ import { jsx as jsx3 } from "react/jsx-runtime";
216
+ var RendererErrorBoundary = class extends React.Component {
217
+ constructor(props) {
218
+ super(props);
219
+ this.state = {
220
+ hasError: false
221
+ };
222
+ }
223
+ static getDerivedStateFromError() {
224
+ return {
225
+ hasError: true
226
+ };
227
+ }
228
+ render() {
229
+ if (this.state.hasError) {
230
+ return /* @__PURE__ */ jsx3("div", { children: "Component rendering failed" });
231
+ }
232
+ return this.props.children;
233
+ }
234
+ };
235
+
236
+ // src/components/Render.tsx
237
+ import { jsx as jsx4 } from "react/jsx-runtime";
238
+ function Render({
239
+ page,
240
+ design,
241
+ components,
242
+ registry,
243
+ debug,
244
+ resolvers,
245
+ dataContext,
246
+ resolverRefreshKey,
247
+ actionDispatcher,
248
+ onResolutionError
249
+ }) {
250
+ const session = useRef2(/* @__PURE__ */ new Map()).current;
251
+ const errorHandler = useCallback((error, node) => {
252
+ onResolutionError?.(error, node.id, node.type);
253
+ }, [onResolutionError]);
254
+ return /* @__PURE__ */ jsx4(RuntimeResolutionSessionContext.Provider, { value: session, children: /* @__PURE__ */ jsx4(RendererErrorBoundary, { children: /* @__PURE__ */ jsx4(
255
+ RenderNode,
256
+ {
257
+ node: page.root,
258
+ design,
259
+ components,
260
+ registry,
261
+ debug,
262
+ resolvers,
263
+ dataContext,
264
+ resolverRefreshKey,
265
+ actionDispatcher,
266
+ onResolutionError: errorHandler
267
+ }
268
+ ) }) });
269
+ }
270
+
271
+ // src/utils/render-page-react.ts
272
+ import { createElement, Fragment } from "react";
273
+ import { renderPageDocument } from "@designos/renderer-core";
274
+ function renderReactPage(page, design, components, options = {}) {
275
+ return renderPageDocument(page, design, {
276
+ renderNode(view) {
277
+ const Component = components[view.node.type];
278
+ if (!Component) {
279
+ const Missing = options.missingComponent;
280
+ return Missing ? createElement(Missing, { componentType: view.node.type }, ...view.children) : createElement(Fragment, null, ...view.children);
281
+ }
282
+ return createElement(Component, { ...view.props, design: view.design, slots: view.slots }, ...view.children);
283
+ }
284
+ }, { registry: options.registry });
285
+ }
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
+
293
+ // src/index.ts
294
+ var rendererTarget = { id: "react", kind: "runtime" };
295
+ export {
296
+ Render,
297
+ RuntimeActionProvider,
298
+ designStyle,
299
+ renderReactPage,
300
+ rendererTarget,
301
+ useDesignOSAction
302
+ };
303
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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/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,O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C;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,46 @@
1
1
  {
2
2
  "name": "@designos/renderer-react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0",
4
+ "private": false,
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.js"
10
+ }
11
+ },
12
+ "peerDependencies": {
13
+ "react": "^19.0.0",
14
+ "react-dom": "^19.0.0"
15
+ },
16
+ "dependencies": {
17
+ "@designos/core": "0.2.0",
18
+ "@designos/renderer-core": "1.0.0"
19
+ },
20
+ "devDependencies": {
21
+ "@types/react": "^19.1.12",
22
+ "@types/react-dom": "^19.1.9",
23
+ "typescript": "^5.9.2",
24
+ "tsup": "^8.5.0",
25
+ "vitest": "^3.2.4"
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "README.md"
30
+ ],
31
+ "main": "./dist/index.js",
32
+ "types": "./dist/index.d.ts",
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/relacloud/design-os.git",
39
+ "directory": "packages/renderer-react"
40
+ },
41
+ "scripts": {
42
+ "typecheck": "tsc --noEmit",
43
+ "build": "tsup",
44
+ "test": "vitest"
45
+ }
6
46
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.