@json-render/react 0.2.0 → 0.4.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 +253 -175
- package/dist/chunk-IGPI5WNB.mjs +52 -0
- package/dist/chunk-IGPI5WNB.mjs.map +1 -0
- package/dist/index.d.mts +138 -16
- package/dist/index.d.ts +138 -16
- package/dist/index.js +150 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +109 -38
- package/dist/index.mjs.map +1 -1
- package/dist/schema.d.mts +106 -0
- package/dist/schema.d.ts +106 -0
- package/dist/schema.js +77 -0
- package/dist/schema.js.map +1 -0
- package/dist/schema.mjs +9 -0
- package/dist/schema.mjs.map +1 -0
- package/package.json +7 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode, ComponentType } from 'react';
|
|
3
|
-
import { DataModel, AuthState, VisibilityCondition, VisibilityContext, ActionHandler, ResolvedAction, Action, ActionConfirm, ValidationFunction, ValidationResult, ValidationConfig,
|
|
3
|
+
import { DataModel as DataModel$1, AuthState, VisibilityCondition, VisibilityContext, ActionHandler, ResolvedAction, Action, ActionConfirm, ValidationFunction, ValidationResult, ValidationConfig, Catalog, InferCatalogComponents, InferComponentProps, InferCatalogActions, InferActionParams, SchemaDefinition, UIElement, Spec, LegacyCatalog, ComponentDefinition } from '@json-render/core';
|
|
4
|
+
export { Spec } from '@json-render/core';
|
|
5
|
+
export { ElementTreeSchema, ElementTreeSpec, ReactSchema, ReactSpec, elementTreeSchema, schema } from './schema.mjs';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* Data context value
|
|
7
9
|
*/
|
|
8
10
|
interface DataContextValue {
|
|
9
11
|
/** The current data model */
|
|
10
|
-
data: DataModel;
|
|
12
|
+
data: DataModel$1;
|
|
11
13
|
/** Auth state for visibility evaluation */
|
|
12
14
|
authState?: AuthState;
|
|
13
15
|
/** Get a value by path */
|
|
@@ -22,7 +24,7 @@ interface DataContextValue {
|
|
|
22
24
|
*/
|
|
23
25
|
interface DataProviderProps {
|
|
24
26
|
/** Initial data model */
|
|
25
|
-
initialData?: DataModel;
|
|
27
|
+
initialData?: DataModel$1;
|
|
26
28
|
/** Auth state */
|
|
27
29
|
authState?: AuthState;
|
|
28
30
|
/** Callback when data changes */
|
|
@@ -205,6 +207,74 @@ declare function useFieldValidation(path: string, config?: ValidationConfig): {
|
|
|
205
207
|
isValid: boolean;
|
|
206
208
|
};
|
|
207
209
|
|
|
210
|
+
/**
|
|
211
|
+
* Data setter function for updating application state
|
|
212
|
+
*/
|
|
213
|
+
type SetData = (updater: (prev: Record<string, unknown>) => Record<string, unknown>) => void;
|
|
214
|
+
/**
|
|
215
|
+
* Data model type (generic record)
|
|
216
|
+
*/
|
|
217
|
+
type DataModel = Record<string, unknown>;
|
|
218
|
+
/**
|
|
219
|
+
* Action trigger for component callbacks
|
|
220
|
+
*/
|
|
221
|
+
interface ActionTrigger {
|
|
222
|
+
name: string;
|
|
223
|
+
params?: Record<string, unknown>;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Context passed to component render functions
|
|
227
|
+
* @example
|
|
228
|
+
* const Button: ComponentFn<typeof catalog, 'Button'> = (ctx) => {
|
|
229
|
+
* return <button onClick={() => ctx.onAction?.({ name: ctx.props.action })}>{ctx.props.label}</button>
|
|
230
|
+
* }
|
|
231
|
+
*/
|
|
232
|
+
interface ComponentContext<C extends Catalog, K extends keyof InferCatalogComponents<C>> {
|
|
233
|
+
props: InferComponentProps<C, K>;
|
|
234
|
+
children?: ReactNode;
|
|
235
|
+
onAction?: (action: ActionTrigger) => void;
|
|
236
|
+
loading?: boolean;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Component render function type for React
|
|
240
|
+
* @example
|
|
241
|
+
* const Button: ComponentFn<typeof catalog, 'Button'> = ({ props, onAction }) => (
|
|
242
|
+
* <button onClick={() => onAction?.({ name: props.action })}>{props.label}</button>
|
|
243
|
+
* );
|
|
244
|
+
*/
|
|
245
|
+
type ComponentFn<C extends Catalog, K extends keyof InferCatalogComponents<C>> = (ctx: ComponentContext<C, K>) => ReactNode;
|
|
246
|
+
/**
|
|
247
|
+
* Registry of all component render functions for a catalog
|
|
248
|
+
* @example
|
|
249
|
+
* const components: Components<typeof myCatalog> = {
|
|
250
|
+
* Button: ({ props }) => <button>{props.label}</button>,
|
|
251
|
+
* Input: ({ props }) => <input placeholder={props.placeholder} />,
|
|
252
|
+
* };
|
|
253
|
+
*/
|
|
254
|
+
type Components<C extends Catalog> = {
|
|
255
|
+
[K in keyof InferCatalogComponents<C>]: ComponentFn<C, K>;
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* Action handler function type
|
|
259
|
+
* @example
|
|
260
|
+
* const viewCustomers: ActionFn<typeof catalog, 'viewCustomers'> = async (params, setData) => {
|
|
261
|
+
* const data = await fetch('/api/customers');
|
|
262
|
+
* setData(prev => ({ ...prev, customers: data }));
|
|
263
|
+
* };
|
|
264
|
+
*/
|
|
265
|
+
type ActionFn<C extends Catalog, K extends keyof InferCatalogActions<C>> = (params: InferActionParams<C, K> | undefined, setData: SetData, data: DataModel) => Promise<void>;
|
|
266
|
+
/**
|
|
267
|
+
* Registry of all action handlers for a catalog
|
|
268
|
+
* @example
|
|
269
|
+
* const actions: Actions<typeof myCatalog> = {
|
|
270
|
+
* viewCustomers: async (params, setData) => { ... },
|
|
271
|
+
* createCustomer: async (params, setData) => { ... },
|
|
272
|
+
* };
|
|
273
|
+
*/
|
|
274
|
+
type Actions<C extends Catalog> = {
|
|
275
|
+
[K in keyof InferCatalogActions<C>]: ActionFn<C, K>;
|
|
276
|
+
};
|
|
277
|
+
|
|
208
278
|
/**
|
|
209
279
|
* Props passed to component renderers
|
|
210
280
|
*/
|
|
@@ -230,11 +300,11 @@ type ComponentRegistry = Record<string, ComponentRenderer<any>>;
|
|
|
230
300
|
* Props for the Renderer component
|
|
231
301
|
*/
|
|
232
302
|
interface RendererProps {
|
|
233
|
-
/** The UI
|
|
234
|
-
|
|
303
|
+
/** The UI spec to render */
|
|
304
|
+
spec: Spec | null;
|
|
235
305
|
/** Component registry */
|
|
236
306
|
registry: ComponentRegistry;
|
|
237
|
-
/** Whether the
|
|
307
|
+
/** Whether the spec is currently loading/streaming */
|
|
238
308
|
loading?: boolean;
|
|
239
309
|
/** Fallback component for unknown types */
|
|
240
310
|
fallback?: ComponentRenderer;
|
|
@@ -242,7 +312,7 @@ interface RendererProps {
|
|
|
242
312
|
/**
|
|
243
313
|
* Main renderer component
|
|
244
314
|
*/
|
|
245
|
-
declare function Renderer({
|
|
315
|
+
declare function Renderer({ spec, registry, loading, fallback }: RendererProps): react_jsx_runtime.JSX.Element | null;
|
|
246
316
|
/**
|
|
247
317
|
* Props for JSONUIProvider
|
|
248
318
|
*/
|
|
@@ -271,9 +341,61 @@ interface JSONUIProviderProps {
|
|
|
271
341
|
*/
|
|
272
342
|
declare function JSONUIProvider({ registry, initialData, authState, actionHandlers, navigate, validationFunctions, onDataChange, children, }: JSONUIProviderProps): react_jsx_runtime.JSX.Element;
|
|
273
343
|
/**
|
|
274
|
-
*
|
|
344
|
+
* Legacy helper to create a renderer component from a catalog
|
|
345
|
+
* @deprecated Use createRenderer with the new catalog API instead
|
|
346
|
+
*/
|
|
347
|
+
declare function createRendererFromCatalog<C extends LegacyCatalog<Record<string, ComponentDefinition>>>(_catalog: C, registry: ComponentRegistry): ComponentType<Omit<RendererProps, "registry">>;
|
|
348
|
+
/**
|
|
349
|
+
* Props for renderers created with createRenderer
|
|
275
350
|
*/
|
|
276
|
-
|
|
351
|
+
interface CreateRendererProps {
|
|
352
|
+
/** The spec to render (AI-generated JSON) */
|
|
353
|
+
spec: Spec | null;
|
|
354
|
+
/** Data context for dynamic values */
|
|
355
|
+
data?: Record<string, unknown>;
|
|
356
|
+
/** Action handler */
|
|
357
|
+
onAction?: (actionName: string, params?: Record<string, unknown>) => void;
|
|
358
|
+
/** Callback when data changes (e.g., from form inputs) */
|
|
359
|
+
onDataChange?: (path: string, value: unknown) => void;
|
|
360
|
+
/** Whether the spec is currently loading/streaming */
|
|
361
|
+
loading?: boolean;
|
|
362
|
+
/** Auth state for visibility conditions */
|
|
363
|
+
authState?: {
|
|
364
|
+
isSignedIn: boolean;
|
|
365
|
+
user?: Record<string, unknown>;
|
|
366
|
+
};
|
|
367
|
+
/** Fallback component for unknown types */
|
|
368
|
+
fallback?: ComponentRenderer;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Component map type - maps component names to React components
|
|
372
|
+
*/
|
|
373
|
+
type ComponentMap<TComponents extends Record<string, {
|
|
374
|
+
props: unknown;
|
|
375
|
+
}>> = {
|
|
376
|
+
[K in keyof TComponents]: ComponentType<ComponentRenderProps<TComponents[K]["props"] extends {
|
|
377
|
+
_output: infer O;
|
|
378
|
+
} ? O : Record<string, unknown>>>;
|
|
379
|
+
};
|
|
380
|
+
/**
|
|
381
|
+
* Create a renderer from a catalog
|
|
382
|
+
*
|
|
383
|
+
* @example
|
|
384
|
+
* ```typescript
|
|
385
|
+
* const DashboardRenderer = createRenderer(dashboardCatalog, {
|
|
386
|
+
* Card: ({ element, children }) => <div className="card">{children}</div>,
|
|
387
|
+
* Metric: ({ element }) => <span>{element.props.value}</span>,
|
|
388
|
+
* });
|
|
389
|
+
*
|
|
390
|
+
* // Usage
|
|
391
|
+
* <DashboardRenderer spec={aiGeneratedSpec} data={data} />
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
394
|
+
declare function createRenderer<TDef extends SchemaDefinition, TCatalog extends {
|
|
395
|
+
components: Record<string, {
|
|
396
|
+
props: unknown;
|
|
397
|
+
}>;
|
|
398
|
+
}>(catalog: Catalog<TDef, TCatalog>, components: ComponentMap<TCatalog["components"]>): ComponentType<CreateRendererProps>;
|
|
277
399
|
|
|
278
400
|
/**
|
|
279
401
|
* Options for useUIStream
|
|
@@ -282,7 +404,7 @@ interface UseUIStreamOptions {
|
|
|
282
404
|
/** API endpoint */
|
|
283
405
|
api: string;
|
|
284
406
|
/** Callback when complete */
|
|
285
|
-
onComplete?: (
|
|
407
|
+
onComplete?: (spec: Spec) => void;
|
|
286
408
|
/** Callback on error */
|
|
287
409
|
onError?: (error: Error) => void;
|
|
288
410
|
}
|
|
@@ -290,15 +412,15 @@ interface UseUIStreamOptions {
|
|
|
290
412
|
* Return type for useUIStream
|
|
291
413
|
*/
|
|
292
414
|
interface UseUIStreamReturn {
|
|
293
|
-
/** Current UI
|
|
294
|
-
|
|
415
|
+
/** Current UI spec */
|
|
416
|
+
spec: Spec | null;
|
|
295
417
|
/** Whether currently streaming */
|
|
296
418
|
isStreaming: boolean;
|
|
297
419
|
/** Error if any */
|
|
298
420
|
error: Error | null;
|
|
299
421
|
/** Send a prompt to generate UI */
|
|
300
422
|
send: (prompt: string, context?: Record<string, unknown>) => Promise<void>;
|
|
301
|
-
/** Clear the current
|
|
423
|
+
/** Clear the current spec */
|
|
302
424
|
clear: () => void;
|
|
303
425
|
}
|
|
304
426
|
/**
|
|
@@ -306,10 +428,10 @@ interface UseUIStreamReturn {
|
|
|
306
428
|
*/
|
|
307
429
|
declare function useUIStream({ api, onComplete, onError, }: UseUIStreamOptions): UseUIStreamReturn;
|
|
308
430
|
/**
|
|
309
|
-
* Convert a flat element list to a
|
|
431
|
+
* Convert a flat element list to a Spec
|
|
310
432
|
*/
|
|
311
433
|
declare function flatToTree(elements: Array<UIElement & {
|
|
312
434
|
parentKey?: string | null;
|
|
313
|
-
}>):
|
|
435
|
+
}>): Spec;
|
|
314
436
|
|
|
315
|
-
export { type ActionContextValue, ActionProvider, type ActionProviderProps, type ComponentRegistry, type ComponentRenderProps, type ComponentRenderer, ConfirmDialog, type ConfirmDialogProps, type DataContextValue, DataProvider, type DataProviderProps, type FieldValidationState, JSONUIProvider, type JSONUIProviderProps, type PendingConfirmation, Renderer, type RendererProps, type UseUIStreamOptions, type UseUIStreamReturn, type ValidationContextValue, ValidationProvider, type ValidationProviderProps, type VisibilityContextValue, VisibilityProvider, type VisibilityProviderProps, createRendererFromCatalog, flatToTree, useAction, useActions, useData, useDataBinding, useDataValue, useFieldValidation, useIsVisible, useUIStream, useValidation, useVisibility };
|
|
437
|
+
export { type ActionContextValue, type ActionFn, ActionProvider, type ActionProviderProps, type ActionTrigger, type Actions, type ComponentContext, type ComponentFn, type ComponentMap, type ComponentRegistry, type ComponentRenderProps, type ComponentRenderer, type Components, ConfirmDialog, type ConfirmDialogProps, type CreateRendererProps, type DataContextValue, type DataModel, DataProvider, type DataProviderProps, type FieldValidationState, JSONUIProvider, type JSONUIProviderProps, type PendingConfirmation, Renderer, type RendererProps, type SetData, type UseUIStreamOptions, type UseUIStreamReturn, type ValidationContextValue, ValidationProvider, type ValidationProviderProps, type VisibilityContextValue, VisibilityProvider, type VisibilityProviderProps, createRenderer, createRendererFromCatalog, flatToTree, useAction, useActions, useData, useDataBinding, useDataValue, useFieldValidation, useIsVisible, useUIStream, useValidation, useVisibility };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode, ComponentType } from 'react';
|
|
3
|
-
import { DataModel, AuthState, VisibilityCondition, VisibilityContext, ActionHandler, ResolvedAction, Action, ActionConfirm, ValidationFunction, ValidationResult, ValidationConfig,
|
|
3
|
+
import { DataModel as DataModel$1, AuthState, VisibilityCondition, VisibilityContext, ActionHandler, ResolvedAction, Action, ActionConfirm, ValidationFunction, ValidationResult, ValidationConfig, Catalog, InferCatalogComponents, InferComponentProps, InferCatalogActions, InferActionParams, SchemaDefinition, UIElement, Spec, LegacyCatalog, ComponentDefinition } from '@json-render/core';
|
|
4
|
+
export { Spec } from '@json-render/core';
|
|
5
|
+
export { ElementTreeSchema, ElementTreeSpec, ReactSchema, ReactSpec, elementTreeSchema, schema } from './schema.js';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* Data context value
|
|
7
9
|
*/
|
|
8
10
|
interface DataContextValue {
|
|
9
11
|
/** The current data model */
|
|
10
|
-
data: DataModel;
|
|
12
|
+
data: DataModel$1;
|
|
11
13
|
/** Auth state for visibility evaluation */
|
|
12
14
|
authState?: AuthState;
|
|
13
15
|
/** Get a value by path */
|
|
@@ -22,7 +24,7 @@ interface DataContextValue {
|
|
|
22
24
|
*/
|
|
23
25
|
interface DataProviderProps {
|
|
24
26
|
/** Initial data model */
|
|
25
|
-
initialData?: DataModel;
|
|
27
|
+
initialData?: DataModel$1;
|
|
26
28
|
/** Auth state */
|
|
27
29
|
authState?: AuthState;
|
|
28
30
|
/** Callback when data changes */
|
|
@@ -205,6 +207,74 @@ declare function useFieldValidation(path: string, config?: ValidationConfig): {
|
|
|
205
207
|
isValid: boolean;
|
|
206
208
|
};
|
|
207
209
|
|
|
210
|
+
/**
|
|
211
|
+
* Data setter function for updating application state
|
|
212
|
+
*/
|
|
213
|
+
type SetData = (updater: (prev: Record<string, unknown>) => Record<string, unknown>) => void;
|
|
214
|
+
/**
|
|
215
|
+
* Data model type (generic record)
|
|
216
|
+
*/
|
|
217
|
+
type DataModel = Record<string, unknown>;
|
|
218
|
+
/**
|
|
219
|
+
* Action trigger for component callbacks
|
|
220
|
+
*/
|
|
221
|
+
interface ActionTrigger {
|
|
222
|
+
name: string;
|
|
223
|
+
params?: Record<string, unknown>;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Context passed to component render functions
|
|
227
|
+
* @example
|
|
228
|
+
* const Button: ComponentFn<typeof catalog, 'Button'> = (ctx) => {
|
|
229
|
+
* return <button onClick={() => ctx.onAction?.({ name: ctx.props.action })}>{ctx.props.label}</button>
|
|
230
|
+
* }
|
|
231
|
+
*/
|
|
232
|
+
interface ComponentContext<C extends Catalog, K extends keyof InferCatalogComponents<C>> {
|
|
233
|
+
props: InferComponentProps<C, K>;
|
|
234
|
+
children?: ReactNode;
|
|
235
|
+
onAction?: (action: ActionTrigger) => void;
|
|
236
|
+
loading?: boolean;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Component render function type for React
|
|
240
|
+
* @example
|
|
241
|
+
* const Button: ComponentFn<typeof catalog, 'Button'> = ({ props, onAction }) => (
|
|
242
|
+
* <button onClick={() => onAction?.({ name: props.action })}>{props.label}</button>
|
|
243
|
+
* );
|
|
244
|
+
*/
|
|
245
|
+
type ComponentFn<C extends Catalog, K extends keyof InferCatalogComponents<C>> = (ctx: ComponentContext<C, K>) => ReactNode;
|
|
246
|
+
/**
|
|
247
|
+
* Registry of all component render functions for a catalog
|
|
248
|
+
* @example
|
|
249
|
+
* const components: Components<typeof myCatalog> = {
|
|
250
|
+
* Button: ({ props }) => <button>{props.label}</button>,
|
|
251
|
+
* Input: ({ props }) => <input placeholder={props.placeholder} />,
|
|
252
|
+
* };
|
|
253
|
+
*/
|
|
254
|
+
type Components<C extends Catalog> = {
|
|
255
|
+
[K in keyof InferCatalogComponents<C>]: ComponentFn<C, K>;
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* Action handler function type
|
|
259
|
+
* @example
|
|
260
|
+
* const viewCustomers: ActionFn<typeof catalog, 'viewCustomers'> = async (params, setData) => {
|
|
261
|
+
* const data = await fetch('/api/customers');
|
|
262
|
+
* setData(prev => ({ ...prev, customers: data }));
|
|
263
|
+
* };
|
|
264
|
+
*/
|
|
265
|
+
type ActionFn<C extends Catalog, K extends keyof InferCatalogActions<C>> = (params: InferActionParams<C, K> | undefined, setData: SetData, data: DataModel) => Promise<void>;
|
|
266
|
+
/**
|
|
267
|
+
* Registry of all action handlers for a catalog
|
|
268
|
+
* @example
|
|
269
|
+
* const actions: Actions<typeof myCatalog> = {
|
|
270
|
+
* viewCustomers: async (params, setData) => { ... },
|
|
271
|
+
* createCustomer: async (params, setData) => { ... },
|
|
272
|
+
* };
|
|
273
|
+
*/
|
|
274
|
+
type Actions<C extends Catalog> = {
|
|
275
|
+
[K in keyof InferCatalogActions<C>]: ActionFn<C, K>;
|
|
276
|
+
};
|
|
277
|
+
|
|
208
278
|
/**
|
|
209
279
|
* Props passed to component renderers
|
|
210
280
|
*/
|
|
@@ -230,11 +300,11 @@ type ComponentRegistry = Record<string, ComponentRenderer<any>>;
|
|
|
230
300
|
* Props for the Renderer component
|
|
231
301
|
*/
|
|
232
302
|
interface RendererProps {
|
|
233
|
-
/** The UI
|
|
234
|
-
|
|
303
|
+
/** The UI spec to render */
|
|
304
|
+
spec: Spec | null;
|
|
235
305
|
/** Component registry */
|
|
236
306
|
registry: ComponentRegistry;
|
|
237
|
-
/** Whether the
|
|
307
|
+
/** Whether the spec is currently loading/streaming */
|
|
238
308
|
loading?: boolean;
|
|
239
309
|
/** Fallback component for unknown types */
|
|
240
310
|
fallback?: ComponentRenderer;
|
|
@@ -242,7 +312,7 @@ interface RendererProps {
|
|
|
242
312
|
/**
|
|
243
313
|
* Main renderer component
|
|
244
314
|
*/
|
|
245
|
-
declare function Renderer({
|
|
315
|
+
declare function Renderer({ spec, registry, loading, fallback }: RendererProps): react_jsx_runtime.JSX.Element | null;
|
|
246
316
|
/**
|
|
247
317
|
* Props for JSONUIProvider
|
|
248
318
|
*/
|
|
@@ -271,9 +341,61 @@ interface JSONUIProviderProps {
|
|
|
271
341
|
*/
|
|
272
342
|
declare function JSONUIProvider({ registry, initialData, authState, actionHandlers, navigate, validationFunctions, onDataChange, children, }: JSONUIProviderProps): react_jsx_runtime.JSX.Element;
|
|
273
343
|
/**
|
|
274
|
-
*
|
|
344
|
+
* Legacy helper to create a renderer component from a catalog
|
|
345
|
+
* @deprecated Use createRenderer with the new catalog API instead
|
|
346
|
+
*/
|
|
347
|
+
declare function createRendererFromCatalog<C extends LegacyCatalog<Record<string, ComponentDefinition>>>(_catalog: C, registry: ComponentRegistry): ComponentType<Omit<RendererProps, "registry">>;
|
|
348
|
+
/**
|
|
349
|
+
* Props for renderers created with createRenderer
|
|
275
350
|
*/
|
|
276
|
-
|
|
351
|
+
interface CreateRendererProps {
|
|
352
|
+
/** The spec to render (AI-generated JSON) */
|
|
353
|
+
spec: Spec | null;
|
|
354
|
+
/** Data context for dynamic values */
|
|
355
|
+
data?: Record<string, unknown>;
|
|
356
|
+
/** Action handler */
|
|
357
|
+
onAction?: (actionName: string, params?: Record<string, unknown>) => void;
|
|
358
|
+
/** Callback when data changes (e.g., from form inputs) */
|
|
359
|
+
onDataChange?: (path: string, value: unknown) => void;
|
|
360
|
+
/** Whether the spec is currently loading/streaming */
|
|
361
|
+
loading?: boolean;
|
|
362
|
+
/** Auth state for visibility conditions */
|
|
363
|
+
authState?: {
|
|
364
|
+
isSignedIn: boolean;
|
|
365
|
+
user?: Record<string, unknown>;
|
|
366
|
+
};
|
|
367
|
+
/** Fallback component for unknown types */
|
|
368
|
+
fallback?: ComponentRenderer;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Component map type - maps component names to React components
|
|
372
|
+
*/
|
|
373
|
+
type ComponentMap<TComponents extends Record<string, {
|
|
374
|
+
props: unknown;
|
|
375
|
+
}>> = {
|
|
376
|
+
[K in keyof TComponents]: ComponentType<ComponentRenderProps<TComponents[K]["props"] extends {
|
|
377
|
+
_output: infer O;
|
|
378
|
+
} ? O : Record<string, unknown>>>;
|
|
379
|
+
};
|
|
380
|
+
/**
|
|
381
|
+
* Create a renderer from a catalog
|
|
382
|
+
*
|
|
383
|
+
* @example
|
|
384
|
+
* ```typescript
|
|
385
|
+
* const DashboardRenderer = createRenderer(dashboardCatalog, {
|
|
386
|
+
* Card: ({ element, children }) => <div className="card">{children}</div>,
|
|
387
|
+
* Metric: ({ element }) => <span>{element.props.value}</span>,
|
|
388
|
+
* });
|
|
389
|
+
*
|
|
390
|
+
* // Usage
|
|
391
|
+
* <DashboardRenderer spec={aiGeneratedSpec} data={data} />
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
394
|
+
declare function createRenderer<TDef extends SchemaDefinition, TCatalog extends {
|
|
395
|
+
components: Record<string, {
|
|
396
|
+
props: unknown;
|
|
397
|
+
}>;
|
|
398
|
+
}>(catalog: Catalog<TDef, TCatalog>, components: ComponentMap<TCatalog["components"]>): ComponentType<CreateRendererProps>;
|
|
277
399
|
|
|
278
400
|
/**
|
|
279
401
|
* Options for useUIStream
|
|
@@ -282,7 +404,7 @@ interface UseUIStreamOptions {
|
|
|
282
404
|
/** API endpoint */
|
|
283
405
|
api: string;
|
|
284
406
|
/** Callback when complete */
|
|
285
|
-
onComplete?: (
|
|
407
|
+
onComplete?: (spec: Spec) => void;
|
|
286
408
|
/** Callback on error */
|
|
287
409
|
onError?: (error: Error) => void;
|
|
288
410
|
}
|
|
@@ -290,15 +412,15 @@ interface UseUIStreamOptions {
|
|
|
290
412
|
* Return type for useUIStream
|
|
291
413
|
*/
|
|
292
414
|
interface UseUIStreamReturn {
|
|
293
|
-
/** Current UI
|
|
294
|
-
|
|
415
|
+
/** Current UI spec */
|
|
416
|
+
spec: Spec | null;
|
|
295
417
|
/** Whether currently streaming */
|
|
296
418
|
isStreaming: boolean;
|
|
297
419
|
/** Error if any */
|
|
298
420
|
error: Error | null;
|
|
299
421
|
/** Send a prompt to generate UI */
|
|
300
422
|
send: (prompt: string, context?: Record<string, unknown>) => Promise<void>;
|
|
301
|
-
/** Clear the current
|
|
423
|
+
/** Clear the current spec */
|
|
302
424
|
clear: () => void;
|
|
303
425
|
}
|
|
304
426
|
/**
|
|
@@ -306,10 +428,10 @@ interface UseUIStreamReturn {
|
|
|
306
428
|
*/
|
|
307
429
|
declare function useUIStream({ api, onComplete, onError, }: UseUIStreamOptions): UseUIStreamReturn;
|
|
308
430
|
/**
|
|
309
|
-
* Convert a flat element list to a
|
|
431
|
+
* Convert a flat element list to a Spec
|
|
310
432
|
*/
|
|
311
433
|
declare function flatToTree(elements: Array<UIElement & {
|
|
312
434
|
parentKey?: string | null;
|
|
313
|
-
}>):
|
|
435
|
+
}>): Spec;
|
|
314
436
|
|
|
315
|
-
export { type ActionContextValue, ActionProvider, type ActionProviderProps, type ComponentRegistry, type ComponentRenderProps, type ComponentRenderer, ConfirmDialog, type ConfirmDialogProps, type DataContextValue, DataProvider, type DataProviderProps, type FieldValidationState, JSONUIProvider, type JSONUIProviderProps, type PendingConfirmation, Renderer, type RendererProps, type UseUIStreamOptions, type UseUIStreamReturn, type ValidationContextValue, ValidationProvider, type ValidationProviderProps, type VisibilityContextValue, VisibilityProvider, type VisibilityProviderProps, createRendererFromCatalog, flatToTree, useAction, useActions, useData, useDataBinding, useDataValue, useFieldValidation, useIsVisible, useUIStream, useValidation, useVisibility };
|
|
437
|
+
export { type ActionContextValue, type ActionFn, ActionProvider, type ActionProviderProps, type ActionTrigger, type Actions, type ComponentContext, type ComponentFn, type ComponentMap, type ComponentRegistry, type ComponentRenderProps, type ComponentRenderer, type Components, ConfirmDialog, type ConfirmDialogProps, type CreateRendererProps, type DataContextValue, type DataModel, DataProvider, type DataProviderProps, type FieldValidationState, JSONUIProvider, type JSONUIProviderProps, type PendingConfirmation, Renderer, type RendererProps, type SetData, type UseUIStreamOptions, type UseUIStreamReturn, type ValidationContextValue, ValidationProvider, type ValidationProviderProps, type VisibilityContextValue, VisibilityProvider, type VisibilityProviderProps, createRenderer, createRendererFromCatalog, flatToTree, useAction, useActions, useData, useDataBinding, useDataValue, useFieldValidation, useIsVisible, useUIStream, useValidation, useVisibility };
|