@wotnak/json-render-react-native 0.0.0-pr.slots.9c5563f
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 +201 -0
- package/README.md +229 -0
- package/dist/catalog.d.mts +515 -0
- package/dist/catalog.d.ts +515 -0
- package/dist/catalog.js +425 -0
- package/dist/catalog.js.map +1 -0
- package/dist/catalog.mjs +9 -0
- package/dist/catalog.mjs.map +1 -0
- package/dist/chunk-QYY3Q42V.mjs +400 -0
- package/dist/chunk-QYY3Q42V.mjs.map +1 -0
- package/dist/chunk-T27PQA6P.mjs +83 -0
- package/dist/chunk-T27PQA6P.mjs.map +1 -0
- package/dist/index.d.mts +590 -0
- package/dist/index.d.ts +590 -0
- package/dist/index.js +2694 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2227 -0
- package/dist/index.mjs.map +1 -0
- package/dist/schema.d.mts +102 -0
- package/dist/schema.d.ts +102 -0
- package/dist/schema.js +108 -0
- package/dist/schema.js.map +1 -0
- package/dist/schema.mjs +9 -0
- package/dist/schema.mjs.map +1 -0
- package/package.json +73 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,590 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode, ComponentType } from 'react';
|
|
3
|
+
import { StateModel, VisibilityCondition, VisibilityContext, ActionHandler, ResolvedAction, ActionBinding, ActionConfirm, ValidationFunction, ValidationResult, ValidationConfig, Catalog, InferCatalogComponents, InferComponentProps, InferCatalogActions, InferActionParams, UIElement, SchemaDefinition, Spec, FlatElement } from '@json-render/core';
|
|
4
|
+
export { Spec, StateModel } from '@json-render/core';
|
|
5
|
+
export { ElementTreeSchema, ElementTreeSpec, ReactNativeSchema, ReactNativeSpec, elementTreeSchema, schema } from './schema.js';
|
|
6
|
+
export { ActionDefinition, ComponentDefinition, standardActionDefinitions, standardComponentDefinitions } from './catalog.js';
|
|
7
|
+
import 'zod';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* State context value
|
|
11
|
+
*/
|
|
12
|
+
interface StateContextValue {
|
|
13
|
+
/** The current state model */
|
|
14
|
+
state: StateModel;
|
|
15
|
+
/** Get a value by path */
|
|
16
|
+
get: (path: string) => unknown;
|
|
17
|
+
/** Set a value by path */
|
|
18
|
+
set: (path: string, value: unknown) => void;
|
|
19
|
+
/** Update multiple values at once */
|
|
20
|
+
update: (updates: Record<string, unknown>) => void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Props for StateProvider
|
|
24
|
+
*/
|
|
25
|
+
interface StateProviderProps {
|
|
26
|
+
/** Initial state model */
|
|
27
|
+
initialState?: StateModel;
|
|
28
|
+
/** Callback when state changes */
|
|
29
|
+
onStateChange?: (path: string, value: unknown) => void;
|
|
30
|
+
children: ReactNode;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Provider for state model context
|
|
34
|
+
*/
|
|
35
|
+
declare function StateProvider({ initialState, onStateChange, children, }: StateProviderProps): react_jsx_runtime.JSX.Element;
|
|
36
|
+
/**
|
|
37
|
+
* Hook to access the state context
|
|
38
|
+
*/
|
|
39
|
+
declare function useStateStore(): StateContextValue;
|
|
40
|
+
/**
|
|
41
|
+
* Hook to get a value from the state model
|
|
42
|
+
*/
|
|
43
|
+
declare function useStateValue<T>(path: string): T | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Hook to get and set a value from the state model (like useState).
|
|
46
|
+
*
|
|
47
|
+
* @deprecated Use {@link useBoundProp} with `$bindState` expressions instead.
|
|
48
|
+
* `useStateBinding` takes a raw state path string, while `useBoundProp` works
|
|
49
|
+
* with the renderer's `bindings` map and supports both `$bindState` and
|
|
50
|
+
* `$bindItem` expressions.
|
|
51
|
+
*/
|
|
52
|
+
declare function useStateBinding<T>(path: string): [T | undefined, (value: T) => void];
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Visibility context value
|
|
56
|
+
*/
|
|
57
|
+
interface VisibilityContextValue {
|
|
58
|
+
/** Evaluate a visibility condition */
|
|
59
|
+
isVisible: (condition: VisibilityCondition | undefined) => boolean;
|
|
60
|
+
/** The underlying visibility context */
|
|
61
|
+
ctx: VisibilityContext;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Props for VisibilityProvider
|
|
65
|
+
*/
|
|
66
|
+
interface VisibilityProviderProps {
|
|
67
|
+
children: ReactNode;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Provider for visibility evaluation
|
|
71
|
+
*/
|
|
72
|
+
declare function VisibilityProvider({ children }: VisibilityProviderProps): react_jsx_runtime.JSX.Element;
|
|
73
|
+
/**
|
|
74
|
+
* Hook to access visibility evaluation
|
|
75
|
+
*/
|
|
76
|
+
declare function useVisibility(): VisibilityContextValue;
|
|
77
|
+
/**
|
|
78
|
+
* Hook to check if a condition is visible
|
|
79
|
+
*/
|
|
80
|
+
declare function useIsVisible(condition: VisibilityCondition | undefined): boolean;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Pending confirmation state
|
|
84
|
+
*/
|
|
85
|
+
interface PendingConfirmation {
|
|
86
|
+
/** The resolved action */
|
|
87
|
+
action: ResolvedAction;
|
|
88
|
+
/** The action handler */
|
|
89
|
+
handler: ActionHandler;
|
|
90
|
+
/** Resolve callback */
|
|
91
|
+
resolve: () => void;
|
|
92
|
+
/** Reject callback */
|
|
93
|
+
reject: () => void;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Action context value
|
|
97
|
+
*/
|
|
98
|
+
interface ActionContextValue {
|
|
99
|
+
/** Registered action handlers */
|
|
100
|
+
handlers: Record<string, ActionHandler>;
|
|
101
|
+
/** Currently loading action names */
|
|
102
|
+
loadingActions: Set<string>;
|
|
103
|
+
/** Pending confirmation dialog */
|
|
104
|
+
pendingConfirmation: PendingConfirmation | null;
|
|
105
|
+
/** Execute an action binding */
|
|
106
|
+
execute: (binding: ActionBinding) => Promise<void>;
|
|
107
|
+
/** Confirm the pending action */
|
|
108
|
+
confirm: () => void;
|
|
109
|
+
/** Cancel the pending action */
|
|
110
|
+
cancel: () => void;
|
|
111
|
+
/** Register an action handler */
|
|
112
|
+
registerHandler: (name: string, handler: ActionHandler) => void;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Props for ActionProvider
|
|
116
|
+
*/
|
|
117
|
+
interface ActionProviderProps {
|
|
118
|
+
/** Initial action handlers */
|
|
119
|
+
handlers?: Record<string, ActionHandler>;
|
|
120
|
+
/** Navigation function */
|
|
121
|
+
navigate?: (path: string) => void;
|
|
122
|
+
children: ReactNode;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Provider for action execution
|
|
126
|
+
*/
|
|
127
|
+
declare function ActionProvider({ handlers: initialHandlers, navigate, children, }: ActionProviderProps): react_jsx_runtime.JSX.Element;
|
|
128
|
+
/**
|
|
129
|
+
* Hook to access action context
|
|
130
|
+
*/
|
|
131
|
+
declare function useActions(): ActionContextValue;
|
|
132
|
+
/**
|
|
133
|
+
* Hook to execute an action binding
|
|
134
|
+
*/
|
|
135
|
+
declare function useAction(binding: ActionBinding): {
|
|
136
|
+
execute: () => Promise<void>;
|
|
137
|
+
isLoading: boolean;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Props for ConfirmDialog component
|
|
141
|
+
*/
|
|
142
|
+
interface ConfirmDialogProps {
|
|
143
|
+
/** The confirmation config */
|
|
144
|
+
confirm: ActionConfirm;
|
|
145
|
+
/** Called when confirmed */
|
|
146
|
+
onConfirm: () => void;
|
|
147
|
+
/** Called when cancelled */
|
|
148
|
+
onCancel: () => void;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Default confirmation dialog component for React Native
|
|
152
|
+
*/
|
|
153
|
+
declare function ConfirmDialog({ confirm, onConfirm, onCancel, }: ConfirmDialogProps): react_jsx_runtime.JSX.Element;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Field validation state
|
|
157
|
+
*/
|
|
158
|
+
interface FieldValidationState {
|
|
159
|
+
/** Whether the field has been touched */
|
|
160
|
+
touched: boolean;
|
|
161
|
+
/** Whether the field has been validated */
|
|
162
|
+
validated: boolean;
|
|
163
|
+
/** Validation result */
|
|
164
|
+
result: ValidationResult | null;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Validation context value
|
|
168
|
+
*/
|
|
169
|
+
interface ValidationContextValue {
|
|
170
|
+
/** Custom validation functions from catalog */
|
|
171
|
+
customFunctions: Record<string, ValidationFunction>;
|
|
172
|
+
/** Validation state by field path */
|
|
173
|
+
fieldStates: Record<string, FieldValidationState>;
|
|
174
|
+
/** Validate a field */
|
|
175
|
+
validate: (path: string, config: ValidationConfig) => ValidationResult;
|
|
176
|
+
/** Mark field as touched */
|
|
177
|
+
touch: (path: string) => void;
|
|
178
|
+
/** Clear validation for a field */
|
|
179
|
+
clear: (path: string) => void;
|
|
180
|
+
/** Validate all fields */
|
|
181
|
+
validateAll: () => boolean;
|
|
182
|
+
/** Register field config */
|
|
183
|
+
registerField: (path: string, config: ValidationConfig) => void;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Props for ValidationProvider
|
|
187
|
+
*/
|
|
188
|
+
interface ValidationProviderProps {
|
|
189
|
+
/** Custom validation functions from catalog */
|
|
190
|
+
customFunctions?: Record<string, ValidationFunction>;
|
|
191
|
+
children: ReactNode;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Provider for validation
|
|
195
|
+
*/
|
|
196
|
+
declare function ValidationProvider({ customFunctions, children, }: ValidationProviderProps): react_jsx_runtime.JSX.Element;
|
|
197
|
+
/**
|
|
198
|
+
* Hook to access validation context
|
|
199
|
+
*/
|
|
200
|
+
declare function useValidation(): ValidationContextValue;
|
|
201
|
+
/**
|
|
202
|
+
* Hook to get validation state for a field
|
|
203
|
+
*/
|
|
204
|
+
declare function useFieldValidation(path: string, config?: ValidationConfig): {
|
|
205
|
+
state: FieldValidationState;
|
|
206
|
+
validate: () => ValidationResult;
|
|
207
|
+
touch: () => void;
|
|
208
|
+
clear: () => void;
|
|
209
|
+
errors: string[];
|
|
210
|
+
isValid: boolean;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Repeat scope value provided to child elements inside a repeated element.
|
|
215
|
+
*/
|
|
216
|
+
interface RepeatScopeValue {
|
|
217
|
+
/** The current array item object */
|
|
218
|
+
item: unknown;
|
|
219
|
+
/** Index of the current item in the array */
|
|
220
|
+
index: number;
|
|
221
|
+
/** Absolute state path to the current array item (e.g. "/todos/0") — used for statePath two-way binding */
|
|
222
|
+
basePath: string;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Provides repeat scope to child elements so $item and $index expressions resolve correctly.
|
|
226
|
+
*/
|
|
227
|
+
declare function RepeatScopeProvider({ item, index, basePath, children, }: RepeatScopeValue & {
|
|
228
|
+
children: ReactNode;
|
|
229
|
+
}): react_jsx_runtime.JSX.Element;
|
|
230
|
+
/**
|
|
231
|
+
* Read the current repeat scope (or null if not inside a repeated element).
|
|
232
|
+
*/
|
|
233
|
+
declare function useRepeatScope(): RepeatScopeValue | null;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* State setter function for updating application state
|
|
237
|
+
*/
|
|
238
|
+
type SetState = (updater: (prev: Record<string, unknown>) => Record<string, unknown>) => void;
|
|
239
|
+
/**
|
|
240
|
+
* Context passed to component render functions
|
|
241
|
+
* @example
|
|
242
|
+
* const Button: ComponentFn<typeof catalog, 'Button'> = (ctx) => {
|
|
243
|
+
* return <Pressable onPress={() => ctx.emit("press")}><Text>{ctx.props.label}</Text></Pressable>
|
|
244
|
+
* }
|
|
245
|
+
*/
|
|
246
|
+
interface ComponentContext<C extends Catalog, K extends keyof InferCatalogComponents<C>> {
|
|
247
|
+
props: InferComponentProps<C, K>;
|
|
248
|
+
children?: ReactNode;
|
|
249
|
+
/** Emit a named event. The renderer resolves the event to an action binding from the element's `on` field. */
|
|
250
|
+
emit: (event: string) => void;
|
|
251
|
+
/**
|
|
252
|
+
* Two-way binding paths resolved from `$bindState` / `$bindItem` expressions.
|
|
253
|
+
* Maps prop name → absolute state path for write-back.
|
|
254
|
+
*/
|
|
255
|
+
bindings?: Record<string, string>;
|
|
256
|
+
loading?: boolean;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Component render function type for React Native
|
|
260
|
+
* @example
|
|
261
|
+
* const Button: ComponentFn<typeof catalog, 'Button'> = ({ props, emit }) => (
|
|
262
|
+
* <Pressable onPress={() => emit("press")}><Text>{props.label}</Text></Pressable>
|
|
263
|
+
* );
|
|
264
|
+
*/
|
|
265
|
+
type ComponentFn<C extends Catalog, K extends keyof InferCatalogComponents<C>> = (ctx: ComponentContext<C, K>) => ReactNode;
|
|
266
|
+
/**
|
|
267
|
+
* Registry of all component render functions for a catalog
|
|
268
|
+
* @example
|
|
269
|
+
* const components: Components<typeof myCatalog> = {
|
|
270
|
+
* Button: ({ props }) => <Pressable><Text>{props.label}</Text></Pressable>,
|
|
271
|
+
* Input: ({ props }) => <TextInput placeholder={props.placeholder} />,
|
|
272
|
+
* };
|
|
273
|
+
*/
|
|
274
|
+
type Components<C extends Catalog> = {
|
|
275
|
+
[K in keyof InferCatalogComponents<C>]: ComponentFn<C, K>;
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* Action handler function type
|
|
279
|
+
* @example
|
|
280
|
+
* const viewCustomers: ActionFn<typeof catalog, 'viewCustomers'> = async (params, setState) => {
|
|
281
|
+
* const data = await fetch('/api/customers');
|
|
282
|
+
* setState(prev => ({ ...prev, customers: data }));
|
|
283
|
+
* };
|
|
284
|
+
*/
|
|
285
|
+
type ActionFn<C extends Catalog, K extends keyof InferCatalogActions<C>> = (params: InferActionParams<C, K> | undefined, setState: SetState, state: StateModel) => Promise<void>;
|
|
286
|
+
/**
|
|
287
|
+
* Registry of all action handlers for a catalog
|
|
288
|
+
* @example
|
|
289
|
+
* const actions: Actions<typeof myCatalog> = {
|
|
290
|
+
* viewCustomers: async (params, setState) => { ... },
|
|
291
|
+
* createCustomer: async (params, setState) => { ... },
|
|
292
|
+
* };
|
|
293
|
+
*/
|
|
294
|
+
type Actions<C extends Catalog> = {
|
|
295
|
+
[K in keyof InferCatalogActions<C>]: ActionFn<C, K>;
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Create standard action handlers for React Native.
|
|
300
|
+
*
|
|
301
|
+
* @param options - Configuration for standard actions
|
|
302
|
+
* @returns Action handler map compatible with ActionProvider
|
|
303
|
+
*/
|
|
304
|
+
declare function createStandardActionHandlers(options?: {
|
|
305
|
+
/** Navigation function - called by navigate and goBack actions */
|
|
306
|
+
navigate?: (screen: string, params?: Record<string, unknown>) => void;
|
|
307
|
+
/** Go back function */
|
|
308
|
+
goBack?: () => void;
|
|
309
|
+
/** Called when setData action is triggered */
|
|
310
|
+
onSetData?: (path: string, value: unknown) => void;
|
|
311
|
+
/** Called when refresh action is triggered */
|
|
312
|
+
onRefresh?: (target?: string) => void;
|
|
313
|
+
}): Record<string, (params: Record<string, unknown>) => Promise<void>>;
|
|
314
|
+
/**
|
|
315
|
+
* Standard component registry with all built-in React Native components.
|
|
316
|
+
* Pass to Renderer or merge with custom components.
|
|
317
|
+
*/
|
|
318
|
+
declare const standardComponents: ComponentRegistry;
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Props passed to component renderers
|
|
322
|
+
*/
|
|
323
|
+
interface ComponentRenderProps<P = Record<string, unknown>> {
|
|
324
|
+
/** The element being rendered */
|
|
325
|
+
element: UIElement<string, P>;
|
|
326
|
+
/** Rendered children */
|
|
327
|
+
children?: ReactNode;
|
|
328
|
+
/** Emit a named event. The renderer resolves the event to action binding(s) from the element's `on` field. Always provided by the renderer. */
|
|
329
|
+
emit: (event: string) => void;
|
|
330
|
+
/**
|
|
331
|
+
* Two-way binding paths resolved from `$bindState` / `$bindItem` expressions.
|
|
332
|
+
* Maps prop name → absolute state path for write-back.
|
|
333
|
+
* Only present when at least one prop uses `{ $bindState: "..." }` or `{ $bindItem: "..." }`.
|
|
334
|
+
*/
|
|
335
|
+
bindings?: Record<string, string>;
|
|
336
|
+
/** Whether the parent is loading */
|
|
337
|
+
loading?: boolean;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Component renderer type
|
|
341
|
+
*/
|
|
342
|
+
type ComponentRenderer<P = Record<string, unknown>> = ComponentType<ComponentRenderProps<P>>;
|
|
343
|
+
/**
|
|
344
|
+
* Registry of component renderers
|
|
345
|
+
*/
|
|
346
|
+
type ComponentRegistry = Record<string, ComponentRenderer<any>>;
|
|
347
|
+
/**
|
|
348
|
+
* Props for the Renderer component
|
|
349
|
+
*/
|
|
350
|
+
interface RendererProps {
|
|
351
|
+
/** The UI spec to render */
|
|
352
|
+
spec: Spec | null;
|
|
353
|
+
/**
|
|
354
|
+
* Component registry. If omitted, only standard components are used.
|
|
355
|
+
* When provided, custom components are merged with (and override) standard components.
|
|
356
|
+
*/
|
|
357
|
+
registry?: ComponentRegistry;
|
|
358
|
+
/** Whether to include standard components (default: true) */
|
|
359
|
+
includeStandard?: boolean;
|
|
360
|
+
/** Whether the spec is currently loading/streaming */
|
|
361
|
+
loading?: boolean;
|
|
362
|
+
/** Fallback component for unknown types */
|
|
363
|
+
fallback?: ComponentRenderer;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Main renderer component.
|
|
367
|
+
*
|
|
368
|
+
* By default, standard React Native components are included.
|
|
369
|
+
* Custom components in `registry` override standard ones with the same name.
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
372
|
+
* ```tsx
|
|
373
|
+
* // Use standard components only
|
|
374
|
+
* <Renderer spec={spec} />
|
|
375
|
+
*
|
|
376
|
+
* // Add/override components
|
|
377
|
+
* <Renderer spec={spec} registry={{ CustomCard: MyCard }} />
|
|
378
|
+
*
|
|
379
|
+
* // Disable standard components entirely
|
|
380
|
+
* <Renderer spec={spec} registry={myRegistry} includeStandard={false} />
|
|
381
|
+
* ```
|
|
382
|
+
*/
|
|
383
|
+
declare function Renderer({ spec, registry: customRegistry, includeStandard, loading, fallback, }: RendererProps): react_jsx_runtime.JSX.Element | null;
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Props for JSONUIProvider
|
|
387
|
+
*/
|
|
388
|
+
interface JSONUIProviderProps {
|
|
389
|
+
/**
|
|
390
|
+
* Component registry. If omitted, only standard components are used.
|
|
391
|
+
* Custom components are merged with (and override) standard components.
|
|
392
|
+
*/
|
|
393
|
+
registry?: ComponentRegistry;
|
|
394
|
+
/** Initial state model */
|
|
395
|
+
initialState?: Record<string, unknown>;
|
|
396
|
+
/** Action handlers */
|
|
397
|
+
handlers?: Record<string, (params: Record<string, unknown>) => Promise<unknown> | unknown>;
|
|
398
|
+
/** Navigation function */
|
|
399
|
+
navigate?: (path: string) => void;
|
|
400
|
+
/** Custom validation functions */
|
|
401
|
+
validationFunctions?: Record<string, (value: unknown, args?: Record<string, unknown>) => boolean>;
|
|
402
|
+
/** Callback when state changes */
|
|
403
|
+
onStateChange?: (path: string, value: unknown) => void;
|
|
404
|
+
children: ReactNode;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Combined provider for all JSONUI contexts
|
|
408
|
+
*/
|
|
409
|
+
declare function JSONUIProvider({ registry, initialState, handlers, navigate, validationFunctions, onStateChange, children, }: JSONUIProviderProps): react_jsx_runtime.JSX.Element;
|
|
410
|
+
/**
|
|
411
|
+
* Result returned by defineRegistry
|
|
412
|
+
*/
|
|
413
|
+
interface DefineRegistryResult {
|
|
414
|
+
/** Component registry for `<Renderer registry={...} />` */
|
|
415
|
+
registry: ComponentRegistry;
|
|
416
|
+
/**
|
|
417
|
+
* Create ActionProvider-compatible handlers.
|
|
418
|
+
* Accepts getter functions so handlers always read the latest state/setState
|
|
419
|
+
* (e.g. from React refs).
|
|
420
|
+
*/
|
|
421
|
+
handlers: (getSetState: () => SetState | undefined, getState: () => StateModel) => Record<string, (params: Record<string, unknown>) => Promise<void>>;
|
|
422
|
+
/**
|
|
423
|
+
* Execute an action by name imperatively
|
|
424
|
+
* (for use outside the React tree, e.g. initial state loading).
|
|
425
|
+
*/
|
|
426
|
+
executeAction: (actionName: string, params: Record<string, unknown> | undefined, setState: SetState, state?: StateModel) => Promise<void>;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Create a registry from a catalog with components and/or actions.
|
|
430
|
+
*
|
|
431
|
+
* @example
|
|
432
|
+
* ```tsx
|
|
433
|
+
* // Components only
|
|
434
|
+
* const { registry } = defineRegistry(catalog, {
|
|
435
|
+
* components: {
|
|
436
|
+
* Card: ({ props, children }) => (
|
|
437
|
+
* <View style={styles.card}><Text>{props.title}</Text>{children}</View>
|
|
438
|
+
* ),
|
|
439
|
+
* },
|
|
440
|
+
* });
|
|
441
|
+
*
|
|
442
|
+
* // Actions only
|
|
443
|
+
* const { handlers, executeAction } = defineRegistry(catalog, {
|
|
444
|
+
* actions: {
|
|
445
|
+
* viewCustomers: async (params, setState) => { ... },
|
|
446
|
+
* },
|
|
447
|
+
* });
|
|
448
|
+
*
|
|
449
|
+
* // Both
|
|
450
|
+
* const { registry, handlers, executeAction } = defineRegistry(catalog, {
|
|
451
|
+
* components: { ... },
|
|
452
|
+
* actions: { ... },
|
|
453
|
+
* });
|
|
454
|
+
* ```
|
|
455
|
+
*/
|
|
456
|
+
declare function defineRegistry<C extends Catalog>(_catalog: C, options: {
|
|
457
|
+
components?: Components<C>;
|
|
458
|
+
actions?: Actions<C>;
|
|
459
|
+
}): DefineRegistryResult;
|
|
460
|
+
/**
|
|
461
|
+
* Props for renderers created with createRenderer
|
|
462
|
+
*/
|
|
463
|
+
interface CreateRendererProps {
|
|
464
|
+
/** The spec to render (AI-generated JSON) */
|
|
465
|
+
spec: Spec | null;
|
|
466
|
+
/** State context for dynamic values */
|
|
467
|
+
state?: Record<string, unknown>;
|
|
468
|
+
/** Action handler */
|
|
469
|
+
onAction?: (actionName: string, params?: Record<string, unknown>) => void;
|
|
470
|
+
/** Callback when state changes (e.g., from form inputs) */
|
|
471
|
+
onStateChange?: (path: string, value: unknown) => void;
|
|
472
|
+
/** Whether the spec is currently loading/streaming */
|
|
473
|
+
loading?: boolean;
|
|
474
|
+
/** Fallback component for unknown types */
|
|
475
|
+
fallback?: ComponentRenderer;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Component map type - maps component names to React Native components
|
|
479
|
+
*/
|
|
480
|
+
type ComponentMap<TComponents extends Record<string, {
|
|
481
|
+
props: unknown;
|
|
482
|
+
}>> = {
|
|
483
|
+
[K in keyof TComponents]: ComponentType<ComponentRenderProps<TComponents[K]["props"] extends {
|
|
484
|
+
_output: infer O;
|
|
485
|
+
} ? O : Record<string, unknown>>>;
|
|
486
|
+
};
|
|
487
|
+
/**
|
|
488
|
+
* Create a renderer from a catalog
|
|
489
|
+
*
|
|
490
|
+
* @example
|
|
491
|
+
* ```typescript
|
|
492
|
+
* const DashboardRenderer = createRenderer(dashboardCatalog, {
|
|
493
|
+
* Card: ({ element, children }) => <View style={styles.card}>{children}</View>,
|
|
494
|
+
* Metric: ({ element }) => <Text>{element.props.value}</Text>,
|
|
495
|
+
* });
|
|
496
|
+
*
|
|
497
|
+
* // Usage
|
|
498
|
+
* <DashboardRenderer spec={aiGeneratedSpec} state={state} />
|
|
499
|
+
* ```
|
|
500
|
+
*/
|
|
501
|
+
declare function createRenderer<TDef extends SchemaDefinition, TCatalog extends {
|
|
502
|
+
components: Record<string, {
|
|
503
|
+
props: unknown;
|
|
504
|
+
}>;
|
|
505
|
+
}>(catalog: Catalog<TDef, TCatalog>, components: ComponentMap<TCatalog["components"]>): ComponentType<CreateRendererProps>;
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Hook for two-way bound props. Returns `[value, setValue]` where:
|
|
509
|
+
*
|
|
510
|
+
* - `value` is the already-resolved prop value (passed through from render props)
|
|
511
|
+
* - `setValue` writes back to the bound state path (no-op if not bound)
|
|
512
|
+
*
|
|
513
|
+
* @example
|
|
514
|
+
* ```tsx
|
|
515
|
+
* const [value, setValue] = useBoundProp<string>(element.props.value, bindings?.value);
|
|
516
|
+
* ```
|
|
517
|
+
*/
|
|
518
|
+
declare function useBoundProp<T>(propValue: T | undefined, bindingPath: string | undefined): [T | undefined, (value: T) => void];
|
|
519
|
+
/**
|
|
520
|
+
* Options for useUIStream
|
|
521
|
+
*/
|
|
522
|
+
interface UseUIStreamOptions {
|
|
523
|
+
/** API endpoint */
|
|
524
|
+
api: string;
|
|
525
|
+
/** Callback when complete */
|
|
526
|
+
onComplete?: (spec: Spec) => void;
|
|
527
|
+
/** Callback on error */
|
|
528
|
+
onError?: (error: Error) => void;
|
|
529
|
+
/**
|
|
530
|
+
* Custom fetch implementation with ReadableStream support.
|
|
531
|
+
*
|
|
532
|
+
* React Native's built-in fetch does not support `response.body`
|
|
533
|
+
* (ReadableStream). Pass a streaming-capable fetch here, e.g.
|
|
534
|
+
* `import { fetch } from 'expo/fetch'`.
|
|
535
|
+
*
|
|
536
|
+
* Falls back to the global `fetch` if not provided.
|
|
537
|
+
*/
|
|
538
|
+
fetch?: (url: string, init?: any) => Promise<Response>;
|
|
539
|
+
/**
|
|
540
|
+
* Enable validation and auto-repair.
|
|
541
|
+
*
|
|
542
|
+
* When true:
|
|
543
|
+
* - **Mid-stream**: Each JSONL line is validated as it arrives. If a line
|
|
544
|
+
* is malformed JSON (and recovery fails), the stream is aborted
|
|
545
|
+
* immediately and a repair prompt is sent to continue generation.
|
|
546
|
+
* - **Post-stream**: After the stream completes, structural validation
|
|
547
|
+
* runs (missing children, visible-in-props, etc.). Issues that can be
|
|
548
|
+
* auto-fixed are fixed locally; remaining errors trigger a repair prompt.
|
|
549
|
+
*
|
|
550
|
+
* Defaults to false.
|
|
551
|
+
*/
|
|
552
|
+
validate?: boolean;
|
|
553
|
+
/**
|
|
554
|
+
* Maximum number of automatic repair retries (covers both mid-stream
|
|
555
|
+
* and post-stream retries combined). Defaults to 5.
|
|
556
|
+
*/
|
|
557
|
+
maxRetries?: number;
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Return type for useUIStream
|
|
561
|
+
*/
|
|
562
|
+
interface UseUIStreamReturn {
|
|
563
|
+
/** Current UI spec */
|
|
564
|
+
spec: Spec | null;
|
|
565
|
+
/** Whether currently streaming */
|
|
566
|
+
isStreaming: boolean;
|
|
567
|
+
/** Error if any */
|
|
568
|
+
error: Error | null;
|
|
569
|
+
/** Raw JSONL lines received from the stream */
|
|
570
|
+
rawLines: string[];
|
|
571
|
+
/** Send a prompt to generate UI */
|
|
572
|
+
send: (prompt: string, context?: Record<string, unknown>) => Promise<void>;
|
|
573
|
+
/** Stop the current generation */
|
|
574
|
+
stop: () => void;
|
|
575
|
+
/** Clear the current spec */
|
|
576
|
+
clear: () => void;
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Hook for streaming UI generation
|
|
580
|
+
*/
|
|
581
|
+
declare function useUIStream({ api, onComplete, onError, fetch: fetchFn, validate: enableValidation, maxRetries, }: UseUIStreamOptions): UseUIStreamReturn;
|
|
582
|
+
/**
|
|
583
|
+
* Convert a flat element list to a Spec.
|
|
584
|
+
* Input elements use key/parentKey to establish identity and relationships.
|
|
585
|
+
* Output spec uses the map-based format where key is the map entry key
|
|
586
|
+
* and parent-child relationships are expressed through children arrays.
|
|
587
|
+
*/
|
|
588
|
+
declare function flatToTree(elements: FlatElement[]): Spec;
|
|
589
|
+
|
|
590
|
+
export { type ActionContextValue, type ActionFn, ActionProvider, type ActionProviderProps, type Actions, type ComponentContext, type ComponentFn, type ComponentMap, type ComponentRegistry, type ComponentRenderProps, type ComponentRenderer, type Components, ConfirmDialog, type ConfirmDialogProps, type CreateRendererProps, type DefineRegistryResult, type FieldValidationState, JSONUIProvider, type JSONUIProviderProps, type PendingConfirmation, Renderer, type RendererProps, RepeatScopeProvider, type RepeatScopeValue, type SetState, type StateContextValue, StateProvider, type StateProviderProps, type UseUIStreamOptions, type UseUIStreamReturn, type ValidationContextValue, ValidationProvider, type ValidationProviderProps, type VisibilityContextValue, VisibilityProvider, type VisibilityProviderProps, createRenderer, createStandardActionHandlers, defineRegistry, flatToTree, standardComponents, useAction, useActions, useBoundProp, useFieldValidation, useIsVisible, useRepeatScope, useStateBinding, useStateStore, useStateValue, useUIStream, useValidation, useVisibility };
|