@json-render/react-native 0.7.0 → 0.9.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/dist/index.js CHANGED
@@ -35,11 +35,12 @@ __export(index_exports, {
35
35
  JSONUIProvider: () => JSONUIProvider,
36
36
  Renderer: () => Renderer,
37
37
  RepeatScopeProvider: () => RepeatScopeProvider,
38
- StateProvider: () => StateProvider,
38
+ StateProvider: () => import_react_state.StateProvider,
39
39
  ValidationProvider: () => ValidationProvider,
40
40
  VisibilityProvider: () => VisibilityProvider,
41
41
  createRenderer: () => createRenderer,
42
42
  createStandardActionHandlers: () => createStandardActionHandlers,
43
+ createStateStore: () => import_core7.createStateStore,
43
44
  defineRegistry: () => defineRegistry,
44
45
  elementTreeSchema: () => elementTreeSchema,
45
46
  flatToTree: () => flatToTree,
@@ -53,9 +54,9 @@ __export(index_exports, {
53
54
  useFieldValidation: () => useFieldValidation,
54
55
  useIsVisible: () => useIsVisible,
55
56
  useRepeatScope: () => useRepeatScope,
56
- useStateBinding: () => useStateBinding,
57
- useStateStore: () => useStateStore,
58
- useStateValue: () => useStateValue,
57
+ useStateBinding: () => import_react_state.useStateBinding,
58
+ useStateStore: () => import_react_state.useStateStore,
59
+ useStateValue: () => import_react_state.useStateValue,
59
60
  useUIStream: () => useUIStream,
60
61
  useValidation: () => useValidation,
61
62
  useVisibility: () => useVisibility
@@ -63,116 +64,33 @@ __export(index_exports, {
63
64
  module.exports = __toCommonJS(index_exports);
64
65
 
65
66
  // src/contexts/state.tsx
67
+ var import_react_state = require("@internal/react-state");
68
+
69
+ // src/contexts/visibility.tsx
66
70
  var import_react = require("react");
67
71
  var import_core = require("@json-render/core");
68
72
  var import_jsx_runtime = require("react/jsx-runtime");
69
- var StateContext = (0, import_react.createContext)(null);
70
- function StateProvider({
71
- initialState = {},
72
- onStateChange,
73
- children
74
- }) {
75
- const [state, setStateInternal] = (0, import_react.useState)(initialState);
76
- const stateRef = (0, import_react.useRef)(state);
77
- stateRef.current = state;
78
- const initialStateJsonRef = (0, import_react.useRef)(JSON.stringify(initialState));
79
- (0, import_react.useEffect)(() => {
80
- const newJson = JSON.stringify(initialState);
81
- if (newJson !== initialStateJsonRef.current) {
82
- initialStateJsonRef.current = newJson;
83
- if (initialState && Object.keys(initialState).length > 0) {
84
- setStateInternal((prev) => ({ ...prev, ...initialState }));
85
- }
86
- }
87
- }, [initialState]);
88
- const get = (0, import_react.useCallback)(
89
- (path) => (0, import_core.getByPath)(stateRef.current, path),
90
- []
91
- );
92
- const set = (0, import_react.useCallback)(
93
- (path, value2) => {
94
- setStateInternal((prev) => {
95
- const next = { ...prev };
96
- (0, import_core.setByPath)(next, path, value2);
97
- return next;
98
- });
99
- onStateChange?.(path, value2);
100
- },
101
- [onStateChange]
102
- );
103
- const update = (0, import_react.useCallback)(
104
- (updates) => {
105
- const entries = Object.entries(updates);
106
- setStateInternal((prev) => {
107
- const next = { ...prev };
108
- for (const [path, value2] of entries) {
109
- (0, import_core.setByPath)(next, path, value2);
110
- }
111
- return next;
112
- });
113
- for (const [path, value2] of entries) {
114
- onStateChange?.(path, value2);
115
- }
116
- },
117
- [onStateChange]
118
- );
119
- const value = (0, import_react.useMemo)(
120
- () => ({
121
- state,
122
- get,
123
- set,
124
- update
125
- }),
126
- [state, get, set, update]
127
- );
128
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StateContext.Provider, { value, children });
129
- }
130
- function useStateStore() {
131
- const ctx = (0, import_react.useContext)(StateContext);
132
- if (!ctx) {
133
- throw new Error("useStateStore must be used within a StateProvider");
134
- }
135
- return ctx;
136
- }
137
- function useStateValue(path) {
138
- const { state } = useStateStore();
139
- return (0, import_core.getByPath)(state, path);
140
- }
141
- function useStateBinding(path) {
142
- const { state, set } = useStateStore();
143
- const value = (0, import_core.getByPath)(state, path);
144
- const setValue = (0, import_react.useCallback)(
145
- (newValue) => set(path, newValue),
146
- [path, set]
147
- );
148
- return [value, setValue];
149
- }
150
-
151
- // src/contexts/visibility.tsx
152
- var import_react2 = require("react");
153
- var import_core2 = require("@json-render/core");
154
- var import_jsx_runtime2 = require("react/jsx-runtime");
155
- var VisibilityContext = (0, import_react2.createContext)(null);
73
+ var VisibilityContext = (0, import_react.createContext)(null);
156
74
  function VisibilityProvider({ children }) {
157
- const { state } = useStateStore();
158
- const ctx = (0, import_react2.useMemo)(
75
+ const { state } = (0, import_react_state.useStateStore)();
76
+ const ctx = (0, import_react.useMemo)(
159
77
  () => ({
160
78
  stateModel: state
161
79
  }),
162
80
  [state]
163
81
  );
164
- const isVisible = (0, import_react2.useMemo)(
165
- () => (condition) => (0, import_core2.evaluateVisibility)(condition, ctx),
82
+ const isVisible = (0, import_react.useMemo)(
83
+ () => (condition) => (0, import_core.evaluateVisibility)(condition, ctx),
166
84
  [ctx]
167
85
  );
168
- const value = (0, import_react2.useMemo)(
86
+ const value = (0, import_react.useMemo)(
169
87
  () => ({ isVisible, ctx }),
170
88
  [isVisible, ctx]
171
89
  );
172
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(VisibilityContext.Provider, { value, children });
90
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VisibilityContext.Provider, { value, children });
173
91
  }
174
92
  function useVisibility() {
175
- const ctx = (0, import_react2.useContext)(VisibilityContext);
93
+ const ctx = (0, import_react.useContext)(VisibilityContext);
176
94
  if (!ctx) {
177
95
  throw new Error("useVisibility must be used within a VisibilityProvider");
178
96
  }
@@ -184,10 +102,10 @@ function useIsVisible(condition) {
184
102
  }
185
103
 
186
104
  // src/contexts/actions.tsx
187
- var import_react3 = require("react");
105
+ var import_react2 = require("react");
188
106
  var import_react_native = require("react-native");
189
- var import_core3 = require("@json-render/core");
190
- var import_jsx_runtime3 = require("react/jsx-runtime");
107
+ var import_core2 = require("@json-render/core");
108
+ var import_jsx_runtime2 = require("react/jsx-runtime");
191
109
  var idCounter = 0;
192
110
  function generateUniqueId() {
193
111
  idCounter += 1;
@@ -220,25 +138,25 @@ function deepResolveValue(value, get) {
220
138
  }
221
139
  return value;
222
140
  }
223
- var ActionContext = (0, import_react3.createContext)(null);
141
+ var ActionContext = (0, import_react2.createContext)(null);
224
142
  function ActionProvider({
225
143
  handlers: initialHandlers = {},
226
144
  navigate,
227
145
  children
228
146
  }) {
229
- const { state, get, set } = useStateStore();
230
- const [handlers, setHandlers] = (0, import_react3.useState)(initialHandlers);
231
- const [loadingActions, setLoadingActions] = (0, import_react3.useState)(/* @__PURE__ */ new Set());
232
- const [pendingConfirmation, setPendingConfirmation] = (0, import_react3.useState)(null);
233
- const registerHandler = (0, import_react3.useCallback)(
147
+ const { get, set, getSnapshot } = (0, import_react_state.useStateStore)();
148
+ const [handlers, setHandlers] = (0, import_react2.useState)(initialHandlers);
149
+ const [loadingActions, setLoadingActions] = (0, import_react2.useState)(/* @__PURE__ */ new Set());
150
+ const [pendingConfirmation, setPendingConfirmation] = (0, import_react2.useState)(null);
151
+ const registerHandler = (0, import_react2.useCallback)(
234
152
  (name, handler) => {
235
153
  setHandlers((prev) => ({ ...prev, [name]: handler }));
236
154
  },
237
155
  []
238
156
  );
239
- const execute = (0, import_react3.useCallback)(
157
+ const execute = (0, import_react2.useCallback)(
240
158
  async (binding) => {
241
- const resolved = (0, import_core3.resolveAction)(binding, state);
159
+ const resolved = (0, import_core2.resolveAction)(binding, getSnapshot());
242
160
  if (resolved.action === "setState" && resolved.params) {
243
161
  const statePath = resolved.params.statePath;
244
162
  const value2 = resolved.params.value;
@@ -322,7 +240,7 @@ function ActionProvider({
322
240
  }).then(async () => {
323
241
  setLoadingActions((prev) => new Set(prev).add(resolved.action));
324
242
  try {
325
- await (0, import_core3.executeAction)({
243
+ await (0, import_core2.executeAction)({
326
244
  action: resolved,
327
245
  handler,
328
246
  setState: set,
@@ -343,7 +261,7 @@ function ActionProvider({
343
261
  }
344
262
  setLoadingActions((prev) => new Set(prev).add(resolved.action));
345
263
  try {
346
- await (0, import_core3.executeAction)({
264
+ await (0, import_core2.executeAction)({
347
265
  action: resolved,
348
266
  handler,
349
267
  setState: set,
@@ -361,15 +279,15 @@ function ActionProvider({
361
279
  });
362
280
  }
363
281
  },
364
- [state, handlers, get, set, navigate]
282
+ [handlers, get, set, getSnapshot, navigate]
365
283
  );
366
- const confirm = (0, import_react3.useCallback)(() => {
284
+ const confirm = (0, import_react2.useCallback)(() => {
367
285
  pendingConfirmation?.resolve();
368
286
  }, [pendingConfirmation]);
369
- const cancel = (0, import_react3.useCallback)(() => {
287
+ const cancel = (0, import_react2.useCallback)(() => {
370
288
  pendingConfirmation?.reject();
371
289
  }, [pendingConfirmation]);
372
- const value = (0, import_react3.useMemo)(
290
+ const value = (0, import_react2.useMemo)(
373
291
  () => ({
374
292
  handlers,
375
293
  loadingActions,
@@ -389,10 +307,10 @@ function ActionProvider({
389
307
  registerHandler
390
308
  ]
391
309
  );
392
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ActionContext.Provider, { value, children });
310
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ActionContext.Provider, { value, children });
393
311
  }
394
312
  function useActions() {
395
- const ctx = (0, import_react3.useContext)(ActionContext);
313
+ const ctx = (0, import_react2.useContext)(ActionContext);
396
314
  if (!ctx) {
397
315
  throw new Error("useActions must be used within an ActionProvider");
398
316
  }
@@ -401,7 +319,7 @@ function useActions() {
401
319
  function useAction(binding) {
402
320
  const { execute, loadingActions } = useActions();
403
321
  const isLoading = loadingActions.has(binding.action);
404
- const executeAction2 = (0, import_react3.useCallback)(() => execute(binding), [execute, binding]);
322
+ const executeAction2 = (0, import_react2.useCallback)(() => execute(binding), [execute, binding]);
405
323
  return { execute: executeAction2, isLoading };
406
324
  }
407
325
  function ConfirmDialog({
@@ -410,13 +328,13 @@ function ConfirmDialog({
410
328
  onCancel
411
329
  }) {
412
330
  const isDanger = confirm.variant === "danger";
413
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native.Modal, { transparent: true, animationType: "fade", visible: true, onRequestClose: onCancel, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native.Pressable, { style: styles.overlay, onPress: onCancel, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react_native.Pressable, { style: styles.dialog, onPress: () => {
331
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native.Modal, { transparent: true, animationType: "fade", visible: true, onRequestClose: onCancel, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native.Pressable, { style: styles.overlay, onPress: onCancel, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native.Pressable, { style: styles.dialog, onPress: () => {
414
332
  }, children: [
415
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native.Text, { style: styles.title, children: confirm.title }),
416
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native.Text, { style: styles.message, children: confirm.message }),
417
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react_native.View, { style: styles.buttons, children: [
418
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native.Pressable, { style: styles.cancelButton, onPress: onCancel, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native.Text, { style: styles.cancelButtonText, children: confirm.cancelLabel ?? "Cancel" }) }),
419
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
333
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native.Text, { style: styles.title, children: confirm.title }),
334
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native.Text, { style: styles.message, children: confirm.message }),
335
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native.View, { style: styles.buttons, children: [
336
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native.Pressable, { style: styles.cancelButton, onPress: onCancel, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native.Text, { style: styles.cancelButtonText, children: confirm.cancelLabel ?? "Cancel" }) }),
337
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
420
338
  import_react_native.Pressable,
421
339
  {
422
340
  style: [
@@ -424,7 +342,7 @@ function ConfirmDialog({
424
342
  isDanger && styles.confirmButtonDanger
425
343
  ],
426
344
  onPress: onConfirm,
427
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native.Text, { style: styles.confirmButtonText, children: confirm.confirmLabel ?? "Confirm" })
345
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native.Text, { style: styles.confirmButtonText, children: confirm.confirmLabel ?? "Confirm" })
428
346
  }
429
347
  )
430
348
  ] })
@@ -492,10 +410,10 @@ var styles = import_react_native.StyleSheet.create({
492
410
  });
493
411
 
494
412
  // src/contexts/validation.tsx
495
- var import_react4 = __toESM(require("react"));
496
- var import_core4 = require("@json-render/core");
497
- var import_jsx_runtime4 = require("react/jsx-runtime");
498
- var ValidationContext = (0, import_react4.createContext)(null);
413
+ var import_react3 = __toESM(require("react"));
414
+ var import_core3 = require("@json-render/core");
415
+ var import_jsx_runtime3 = require("react/jsx-runtime");
416
+ var ValidationContext = (0, import_react3.createContext)(null);
499
417
  function dynamicArgsEqual(a, b) {
500
418
  if (a === b) return true;
501
419
  if (!a || !b) return false;
@@ -534,10 +452,10 @@ function ValidationProvider({
534
452
  customFunctions = {},
535
453
  children
536
454
  }) {
537
- const { state } = useStateStore();
538
- const [fieldStates, setFieldStates] = (0, import_react4.useState)({});
539
- const [fieldConfigs, setFieldConfigs] = (0, import_react4.useState)({});
540
- const registerField = (0, import_react4.useCallback)(
455
+ const { state } = (0, import_react_state.useStateStore)();
456
+ const [fieldStates, setFieldStates] = (0, import_react3.useState)({});
457
+ const [fieldConfigs, setFieldConfigs] = (0, import_react3.useState)({});
458
+ const registerField = (0, import_react3.useCallback)(
541
459
  (path, config) => {
542
460
  setFieldConfigs((prev) => {
543
461
  const existing = prev[path];
@@ -549,7 +467,7 @@ function ValidationProvider({
549
467
  },
550
468
  []
551
469
  );
552
- const validate = (0, import_react4.useCallback)(
470
+ const validate = (0, import_react3.useCallback)(
553
471
  (path, config) => {
554
472
  const segments = path.split("/").filter(Boolean);
555
473
  let value2 = state;
@@ -561,7 +479,7 @@ function ValidationProvider({
561
479
  break;
562
480
  }
563
481
  }
564
- const result = (0, import_core4.runValidation)(config, {
482
+ const result = (0, import_core3.runValidation)(config, {
565
483
  value: value2,
566
484
  stateModel: state,
567
485
  customFunctions
@@ -578,7 +496,7 @@ function ValidationProvider({
578
496
  },
579
497
  [state, customFunctions]
580
498
  );
581
- const touch = (0, import_react4.useCallback)((path) => {
499
+ const touch = (0, import_react3.useCallback)((path) => {
582
500
  setFieldStates((prev) => ({
583
501
  ...prev,
584
502
  [path]: {
@@ -589,13 +507,13 @@ function ValidationProvider({
589
507
  }
590
508
  }));
591
509
  }, []);
592
- const clear = (0, import_react4.useCallback)((path) => {
510
+ const clear = (0, import_react3.useCallback)((path) => {
593
511
  setFieldStates((prev) => {
594
512
  const { [path]: _, ...rest } = prev;
595
513
  return rest;
596
514
  });
597
515
  }, []);
598
- const validateAll = (0, import_react4.useCallback)(() => {
516
+ const validateAll = (0, import_react3.useCallback)(() => {
599
517
  let allValid = true;
600
518
  for (const [path, config] of Object.entries(fieldConfigs)) {
601
519
  const result = validate(path, config);
@@ -605,7 +523,7 @@ function ValidationProvider({
605
523
  }
606
524
  return allValid;
607
525
  }, [fieldConfigs, validate]);
608
- const value = (0, import_react4.useMemo)(
526
+ const value = (0, import_react3.useMemo)(
609
527
  () => ({
610
528
  customFunctions,
611
529
  fieldStates,
@@ -625,10 +543,10 @@ function ValidationProvider({
625
543
  registerField
626
544
  ]
627
545
  );
628
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ValidationContext.Provider, { value, children });
546
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ValidationContext.Provider, { value, children });
629
547
  }
630
548
  function useValidation() {
631
- const ctx = (0, import_react4.useContext)(ValidationContext);
549
+ const ctx = (0, import_react3.useContext)(ValidationContext);
632
550
  if (!ctx) {
633
551
  throw new Error("useValidation must be used within a ValidationProvider");
634
552
  }
@@ -642,7 +560,7 @@ function useFieldValidation(path, config) {
642
560
  clear: clearField,
643
561
  registerField
644
562
  } = useValidation();
645
- import_react4.default.useEffect(() => {
563
+ import_react3.default.useEffect(() => {
646
564
  if (config) {
647
565
  registerField(path, config);
648
566
  }
@@ -652,12 +570,12 @@ function useFieldValidation(path, config) {
652
570
  validated: false,
653
571
  result: null
654
572
  };
655
- const validate = (0, import_react4.useCallback)(
573
+ const validate = (0, import_react3.useCallback)(
656
574
  () => validateField(path, config ?? { checks: [] }),
657
575
  [path, config, validateField]
658
576
  );
659
- const touch = (0, import_react4.useCallback)(() => touchField(path), [path, touchField]);
660
- const clear = (0, import_react4.useCallback)(() => clearField(path), [path, clearField]);
577
+ const touch = (0, import_react3.useCallback)(() => touchField(path), [path, touchField]);
578
+ const clear = (0, import_react3.useCallback)(() => clearField(path), [path, clearField]);
661
579
  return {
662
580
  state,
663
581
  validate,
@@ -669,24 +587,24 @@ function useFieldValidation(path, config) {
669
587
  }
670
588
 
671
589
  // src/contexts/repeat-scope.tsx
672
- var import_react5 = require("react");
673
- var import_jsx_runtime5 = require("react/jsx-runtime");
674
- var RepeatScopeContext = (0, import_react5.createContext)(null);
590
+ var import_react4 = require("react");
591
+ var import_jsx_runtime4 = require("react/jsx-runtime");
592
+ var RepeatScopeContext = (0, import_react4.createContext)(null);
675
593
  function RepeatScopeProvider({
676
594
  item,
677
595
  index,
678
596
  basePath,
679
597
  children
680
598
  }) {
681
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(RepeatScopeContext.Provider, { value: { item, index, basePath }, children });
599
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(RepeatScopeContext.Provider, { value: { item, index, basePath }, children });
682
600
  }
683
601
  function useRepeatScope() {
684
- return (0, import_react5.useContext)(RepeatScopeContext);
602
+ return (0, import_react4.useContext)(RepeatScopeContext);
685
603
  }
686
604
 
687
605
  // src/schema.ts
688
- var import_core5 = require("@json-render/core");
689
- var schema = (0, import_core5.defineSchema)(
606
+ var import_core4 = require("@json-render/core");
607
+ var schema = (0, import_core4.defineSchema)(
690
608
  (s) => ({
691
609
  // What the AI-generated SPEC looks like
692
610
  spec: s.object({
@@ -762,19 +680,22 @@ var schema = (0, import_core5.defineSchema)(
762
680
  );
763
681
  var elementTreeSchema = schema;
764
682
 
765
- // src/renderer.tsx
766
- var import_react7 = __toESM(require("react"));
683
+ // src/index.ts
767
684
  var import_core7 = require("@json-render/core");
768
685
 
686
+ // src/renderer.tsx
687
+ var import_react6 = __toESM(require("react"));
688
+ var import_core6 = require("@json-render/core");
689
+
769
690
  // src/components/standard.tsx
770
691
  var import_react_native2 = require("react-native");
771
692
 
772
693
  // src/hooks.ts
773
- var import_react6 = require("react");
774
- var import_core6 = require("@json-render/core");
694
+ var import_react5 = require("react");
695
+ var import_core5 = require("@json-render/core");
775
696
  function useBoundProp(propValue, bindingPath) {
776
- const { set } = useStateStore();
777
- const setValue = (0, import_react6.useCallback)(
697
+ const { set } = (0, import_react_state.useStateStore)();
698
+ const setValue = (0, import_react5.useCallback)(
778
699
  (value) => {
779
700
  if (bindingPath) set(bindingPath, value);
780
701
  },
@@ -828,7 +749,7 @@ function setSpecValue(newSpec, path, value) {
828
749
  if (path.startsWith("/state/")) {
829
750
  if (!newSpec.state) newSpec.state = {};
830
751
  const statePath = path.slice("/state".length);
831
- (0, import_core6.setByPath)(newSpec.state, statePath, value);
752
+ (0, import_core5.setByPath)(newSpec.state, statePath, value);
832
753
  return;
833
754
  }
834
755
  if (path.startsWith("/elements/")) {
@@ -842,7 +763,7 @@ function setSpecValue(newSpec, path, value) {
842
763
  if (element) {
843
764
  const propPath = "/" + pathParts.slice(1).join("/");
844
765
  const newElement = { ...element };
845
- (0, import_core6.setByPath)(
766
+ (0, import_core5.setByPath)(
846
767
  newElement,
847
768
  propPath,
848
769
  value
@@ -859,7 +780,7 @@ function removeSpecValue(newSpec, path) {
859
780
  }
860
781
  if (path.startsWith("/state/") && newSpec.state) {
861
782
  const statePath = path.slice("/state".length);
862
- (0, import_core6.removeByPath)(newSpec.state, statePath);
783
+ (0, import_core5.removeByPath)(newSpec.state, statePath);
863
784
  return;
864
785
  }
865
786
  if (path.startsWith("/elements/")) {
@@ -874,7 +795,7 @@ function removeSpecValue(newSpec, path) {
874
795
  if (element) {
875
796
  const propPath = "/" + pathParts.slice(1).join("/");
876
797
  const newElement = { ...element };
877
- (0, import_core6.removeByPath)(
798
+ (0, import_core5.removeByPath)(
878
799
  newElement,
879
800
  propPath
880
801
  );
@@ -885,7 +806,7 @@ function removeSpecValue(newSpec, path) {
885
806
  }
886
807
  function getSpecValue(spec, path) {
887
808
  if (path === "/root") return spec.root;
888
- return (0, import_core6.getByPath)(spec, path);
809
+ return (0, import_core5.getByPath)(spec, path);
889
810
  }
890
811
  function applyPatch(spec, patch) {
891
812
  const newSpec = { ...spec, elements: { ...spec.elements } };
@@ -926,22 +847,22 @@ function useUIStream({
926
847
  validate: enableValidation = false,
927
848
  maxRetries = 5
928
849
  }) {
929
- const [spec, setSpec] = (0, import_react6.useState)(null);
930
- const [isStreaming, setIsStreaming] = (0, import_react6.useState)(false);
931
- const [error, setError] = (0, import_react6.useState)(null);
932
- const [rawLines, setRawLines] = (0, import_react6.useState)([]);
933
- const abortControllerRef = (0, import_react6.useRef)(null);
934
- const stop = (0, import_react6.useCallback)(() => {
850
+ const [spec, setSpec] = (0, import_react5.useState)(null);
851
+ const [isStreaming, setIsStreaming] = (0, import_react5.useState)(false);
852
+ const [error, setError] = (0, import_react5.useState)(null);
853
+ const [rawLines, setRawLines] = (0, import_react5.useState)([]);
854
+ const abortControllerRef = (0, import_react5.useRef)(null);
855
+ const stop = (0, import_react5.useCallback)(() => {
935
856
  abortControllerRef.current?.abort();
936
857
  abortControllerRef.current = null;
937
858
  setIsStreaming(false);
938
859
  }, []);
939
- const clear = (0, import_react6.useCallback)(() => {
860
+ const clear = (0, import_react5.useCallback)(() => {
940
861
  setSpec(null);
941
862
  setError(null);
942
863
  setRawLines([]);
943
864
  }, []);
944
- const streamRequest = (0, import_react6.useCallback)(
865
+ const streamRequest = (0, import_react5.useCallback)(
945
866
  async (prompt, context, initialSpec, abortOnMalformed) => {
946
867
  let currentSpec = initialSpec;
947
868
  setSpec(currentSpec);
@@ -1022,7 +943,7 @@ function useUIStream({
1022
943
  },
1023
944
  [api, fetchFn]
1024
945
  );
1025
- const send = (0, import_react6.useCallback)(
946
+ const send = (0, import_react5.useCallback)(
1026
947
  async (prompt, context) => {
1027
948
  abortControllerRef.current?.abort();
1028
949
  abortControllerRef.current = new AbortController();
@@ -1059,12 +980,12 @@ The current spec state is provided. Continue generating from where you left off.
1059
980
  if (!enableValidation || !currentSpec.root) {
1060
981
  break;
1061
982
  }
1062
- const { spec: fixedSpec, fixes } = (0, import_core6.autoFixSpec)(currentSpec);
983
+ const { spec: fixedSpec, fixes } = (0, import_core5.autoFixSpec)(currentSpec);
1063
984
  if (fixes.length > 0) {
1064
985
  currentSpec = fixedSpec;
1065
986
  setSpec({ ...currentSpec });
1066
987
  }
1067
- const validation = (0, import_core6.validateSpec)(currentSpec);
988
+ const validation = (0, import_core5.validateSpec)(currentSpec);
1068
989
  if (validation.valid) {
1069
990
  break;
1070
991
  }
@@ -1075,7 +996,7 @@ The current spec state is provided. Continue generating from where you left off.
1075
996
  break;
1076
997
  }
1077
998
  retriesUsed++;
1078
- const issueText = (0, import_core6.formatSpecIssues)(validation.issues);
999
+ const issueText = (0, import_core5.formatSpecIssues)(validation.issues);
1079
1000
  currentContext = { ...context, previousSpec: currentSpec };
1080
1001
  currentPrompt = `FIX THE FOLLOWING ERRORS in the current UI spec. Output ONLY the patches needed to fix these issues, do not recreate the entire UI.
1081
1002
 
@@ -1103,7 +1024,7 @@ The current spec state is provided. Continue generating from where you left off.
1103
1024
  streamRequest
1104
1025
  ]
1105
1026
  );
1106
- (0, import_react6.useEffect)(() => {
1027
+ (0, import_react5.useEffect)(() => {
1107
1028
  return () => {
1108
1029
  abortControllerRef.current?.abort();
1109
1030
  };
@@ -1146,10 +1067,10 @@ function flatToTree(elements) {
1146
1067
  }
1147
1068
 
1148
1069
  // src/components/standard.tsx
1149
- var import_jsx_runtime6 = require("react/jsx-runtime");
1070
+ var import_jsx_runtime5 = require("react/jsx-runtime");
1150
1071
  function ContainerComponent({ element, children }) {
1151
1072
  const p = element.props;
1152
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1073
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1153
1074
  import_react_native2.View,
1154
1075
  {
1155
1076
  style: {
@@ -1167,7 +1088,7 @@ function ContainerComponent({ element, children }) {
1167
1088
  }
1168
1089
  function RowComponent({ element, children }) {
1169
1090
  const p = element.props;
1170
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1091
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1171
1092
  import_react_native2.View,
1172
1093
  {
1173
1094
  style: {
@@ -1185,7 +1106,7 @@ function RowComponent({ element, children }) {
1185
1106
  }
1186
1107
  function ColumnComponent({ element, children }) {
1187
1108
  const p = element.props;
1188
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1109
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1189
1110
  import_react_native2.View,
1190
1111
  {
1191
1112
  style: {
@@ -1202,7 +1123,7 @@ function ColumnComponent({ element, children }) {
1202
1123
  }
1203
1124
  function ScrollContainerComponent({ element, children }) {
1204
1125
  const p = element.props;
1205
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1126
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1206
1127
  import_react_native2.ScrollView,
1207
1128
  {
1208
1129
  horizontal: p.horizontal ?? false,
@@ -1221,7 +1142,7 @@ function ScrollContainerComponent({ element, children }) {
1221
1142
  }
1222
1143
  function SafeAreaComponent({ element, children }) {
1223
1144
  const p = element.props;
1224
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1145
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1225
1146
  import_react_native2.SafeAreaView,
1226
1147
  {
1227
1148
  style: {
@@ -1234,7 +1155,7 @@ function SafeAreaComponent({ element, children }) {
1234
1155
  }
1235
1156
  function SpacerComponent({ element }) {
1236
1157
  const p = element.props;
1237
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1158
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1238
1159
  import_react_native2.View,
1239
1160
  {
1240
1161
  style: {
@@ -1246,7 +1167,7 @@ function SpacerComponent({ element }) {
1246
1167
  );
1247
1168
  }
1248
1169
  function PressableComponent({ children, emit }) {
1249
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1170
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1250
1171
  import_react_native2.Pressable,
1251
1172
  {
1252
1173
  onPress: () => emit("press"),
@@ -1263,7 +1184,7 @@ function DividerComponent({ element }) {
1263
1184
  const isVertical = p.direction === "vertical";
1264
1185
  const thickness = p.thickness ?? 1;
1265
1186
  const color = p.color ?? "#e5e7eb";
1266
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1187
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1267
1188
  import_react_native2.View,
1268
1189
  {
1269
1190
  style: {
@@ -1285,7 +1206,7 @@ var headingSizes = {
1285
1206
  function HeadingComponent({ element }) {
1286
1207
  const p = element.props;
1287
1208
  const level = p.level ?? "h2";
1288
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1209
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1289
1210
  import_react_native2.Text,
1290
1211
  {
1291
1212
  style: {
@@ -1300,7 +1221,7 @@ function HeadingComponent({ element }) {
1300
1221
  }
1301
1222
  function ParagraphComponent({ element }) {
1302
1223
  const p = element.props;
1303
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1224
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1304
1225
  import_react_native2.Text,
1305
1226
  {
1306
1227
  numberOfLines: p.numberOfLines ?? void 0,
@@ -1321,7 +1242,7 @@ var labelSizes = {
1321
1242
  };
1322
1243
  function LabelComponent({ element }) {
1323
1244
  const p = element.props;
1324
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1245
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1325
1246
  import_react_native2.Text,
1326
1247
  {
1327
1248
  style: {
@@ -1335,7 +1256,7 @@ function LabelComponent({ element }) {
1335
1256
  }
1336
1257
  function ImageComponent({ element }) {
1337
1258
  const p = element.props;
1338
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1259
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1339
1260
  import_react_native2.Image,
1340
1261
  {
1341
1262
  source: { uri: p.src },
@@ -1360,7 +1281,7 @@ function AvatarComponent({ element }) {
1360
1281
  const size = avatarSizeMap[p.size ?? "md"];
1361
1282
  const bgColor = p.backgroundColor ?? "#6366f1";
1362
1283
  if (p.src) {
1363
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1284
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1364
1285
  import_react_native2.Image,
1365
1286
  {
1366
1287
  source: { uri: p.src },
@@ -1373,7 +1294,7 @@ function AvatarComponent({ element }) {
1373
1294
  }
1374
1295
  );
1375
1296
  }
1376
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1297
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1377
1298
  import_react_native2.View,
1378
1299
  {
1379
1300
  style: {
@@ -1384,7 +1305,7 @@ function AvatarComponent({ element }) {
1384
1305
  alignItems: "center",
1385
1306
  justifyContent: "center"
1386
1307
  },
1387
- children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1308
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1388
1309
  import_react_native2.Text,
1389
1310
  {
1390
1311
  style: {
@@ -1411,7 +1332,7 @@ function BadgeComponent({ element }) {
1411
1332
  bg: "#e5e7eb",
1412
1333
  text: "#374151"
1413
1334
  };
1414
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1335
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1415
1336
  import_react_native2.View,
1416
1337
  {
1417
1338
  style: {
@@ -1421,7 +1342,7 @@ function BadgeComponent({ element }) {
1421
1342
  borderRadius: 9999,
1422
1343
  alignSelf: "flex-start"
1423
1344
  },
1424
- children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1345
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1425
1346
  import_react_native2.Text,
1426
1347
  {
1427
1348
  style: {
@@ -1440,7 +1361,7 @@ function ChipComponent({ element, emit }) {
1440
1361
  const bgColor = p.selected ? "#6366f1" : p.backgroundColor ?? "#f3f4f6";
1441
1362
  const textColor = p.selected ? "#ffffff" : "#374151";
1442
1363
  const hasRemove = !!element.on?.remove;
1443
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1364
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1444
1365
  import_react_native2.Pressable,
1445
1366
  {
1446
1367
  onPress: () => emit("press"),
@@ -1454,8 +1375,8 @@ function ChipComponent({ element, emit }) {
1454
1375
  alignSelf: "flex-start"
1455
1376
  },
1456
1377
  children: [
1457
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native2.Text, { style: { fontSize: 14, color: textColor }, children: p.label }),
1458
- hasRemove && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native2.Pressable, { onPress: () => emit("remove"), style: { marginLeft: 4 }, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native2.Text, { style: { fontSize: 14, color: textColor, fontWeight: "700" }, children: "x" }) })
1378
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native2.Text, { style: { fontSize: 14, color: textColor }, children: p.label }),
1379
+ hasRemove && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native2.Pressable, { onPress: () => emit("remove"), style: { marginLeft: 4 }, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native2.Text, { style: { fontSize: 14, color: textColor, fontWeight: "700" }, children: "x" }) })
1459
1380
  ]
1460
1381
  }
1461
1382
  );
@@ -1484,7 +1405,7 @@ function ButtonComponent({ element, emit }) {
1484
1405
  fontSize: 15
1485
1406
  };
1486
1407
  const disabled = p.disabled || p.loading;
1487
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1408
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1488
1409
  import_react_native2.Pressable,
1489
1410
  {
1490
1411
  disabled,
@@ -1503,7 +1424,7 @@ function ButtonComponent({ element, emit }) {
1503
1424
  alignSelf: "flex-start"
1504
1425
  }),
1505
1426
  children: [
1506
- p.loading && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1427
+ p.loading && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1507
1428
  import_react_native2.ActivityIndicator,
1508
1429
  {
1509
1430
  size: "small",
@@ -1511,7 +1432,7 @@ function ButtonComponent({ element, emit }) {
1511
1432
  style: { marginRight: 8 }
1512
1433
  }
1513
1434
  ),
1514
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1435
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1515
1436
  import_react_native2.Text,
1516
1437
  {
1517
1438
  style: {
@@ -1533,9 +1454,9 @@ function TextInputComponent({ element, bindings }) {
1533
1454
  bindings?.value
1534
1455
  );
1535
1456
  const displayValue = boundValue ?? "";
1536
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_react_native2.View, { style: p.flex != null ? { flex: p.flex } : void 0, children: [
1537
- p.label && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native2.Text, { style: inputStyles.label, children: p.label }),
1538
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1457
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_react_native2.View, { style: p.flex != null ? { flex: p.flex } : void 0, children: [
1458
+ p.label && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native2.Text, { style: inputStyles.label, children: p.label }),
1459
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1539
1460
  import_react_native2.TextInput,
1540
1461
  {
1541
1462
  placeholder: p.placeholder ?? void 0,
@@ -1563,8 +1484,8 @@ function SwitchComponent({ element, bindings }) {
1563
1484
  bindings?.checked
1564
1485
  );
1565
1486
  const displayValue = checked ?? false;
1566
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_react_native2.View, { style: { flexDirection: "row", alignItems: "center", gap: 8 }, children: [
1567
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1487
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_react_native2.View, { style: { flexDirection: "row", alignItems: "center", gap: 8 }, children: [
1488
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1568
1489
  import_react_native2.Switch,
1569
1490
  {
1570
1491
  value: displayValue,
@@ -1572,7 +1493,7 @@ function SwitchComponent({ element, bindings }) {
1572
1493
  disabled: p.disabled ?? false
1573
1494
  }
1574
1495
  ),
1575
- p.label && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native2.Text, { style: { fontSize: 16, color: "#374151" }, children: p.label })
1496
+ p.label && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native2.Text, { style: { fontSize: 16, color: "#374151" }, children: p.label })
1576
1497
  ] });
1577
1498
  }
1578
1499
  function CheckboxComponent({ element, bindings }) {
@@ -1582,7 +1503,7 @@ function CheckboxComponent({ element, bindings }) {
1582
1503
  bindings?.checked
1583
1504
  );
1584
1505
  const isChecked = checked ?? false;
1585
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1506
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1586
1507
  import_react_native2.Pressable,
1587
1508
  {
1588
1509
  disabled: p.disabled ?? false,
@@ -1598,7 +1519,7 @@ function CheckboxComponent({ element, bindings }) {
1598
1519
  opacity: p.disabled ? 0.5 : 1
1599
1520
  },
1600
1521
  children: [
1601
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1522
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1602
1523
  import_react_native2.View,
1603
1524
  {
1604
1525
  style: {
@@ -1611,10 +1532,10 @@ function CheckboxComponent({ element, bindings }) {
1611
1532
  alignItems: "center",
1612
1533
  justifyContent: "center"
1613
1534
  },
1614
- children: isChecked && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native2.Text, { style: { color: "#ffffff", fontSize: 12, fontWeight: "700" }, children: "\u2713" })
1535
+ children: isChecked && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native2.Text, { style: { color: "#ffffff", fontSize: 12, fontWeight: "700" }, children: "\u2713" })
1615
1536
  }
1616
1537
  ),
1617
- p.label && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native2.Text, { style: { fontSize: 16, color: "#374151" }, children: p.label })
1538
+ p.label && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native2.Text, { style: { fontSize: 16, color: "#374151" }, children: p.label })
1618
1539
  ]
1619
1540
  }
1620
1541
  );
@@ -1626,8 +1547,8 @@ function SliderComponent({ element }) {
1626
1547
  const value = p.value ?? min;
1627
1548
  const progress = max > min ? (value - min) / (max - min) : 0;
1628
1549
  const trackColor = p.color ?? "#3b82f6";
1629
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_react_native2.View, { children: [
1630
- p.label && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1550
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_react_native2.View, { children: [
1551
+ p.label && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1631
1552
  import_react_native2.View,
1632
1553
  {
1633
1554
  style: {
@@ -1636,12 +1557,12 @@ function SliderComponent({ element }) {
1636
1557
  marginBottom: 4
1637
1558
  },
1638
1559
  children: [
1639
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native2.Text, { style: { fontSize: 14, color: "#374151" }, children: p.label }),
1640
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native2.Text, { style: { fontSize: 14, color: "#6b7280" }, children: value })
1560
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native2.Text, { style: { fontSize: 14, color: "#374151" }, children: p.label }),
1561
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native2.Text, { style: { fontSize: 14, color: "#6b7280" }, children: value })
1641
1562
  ]
1642
1563
  }
1643
1564
  ),
1644
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1565
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1645
1566
  import_react_native2.View,
1646
1567
  {
1647
1568
  style: {
@@ -1650,7 +1571,7 @@ function SliderComponent({ element }) {
1650
1571
  borderRadius: 3,
1651
1572
  overflow: "hidden"
1652
1573
  },
1653
- children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1574
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1654
1575
  import_react_native2.View,
1655
1576
  {
1656
1577
  style: {
@@ -1667,7 +1588,7 @@ function SliderComponent({ element }) {
1667
1588
  }
1668
1589
  function SearchBarComponent({ element, emit }) {
1669
1590
  const p = element.props;
1670
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1591
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1671
1592
  import_react_native2.View,
1672
1593
  {
1673
1594
  style: {
@@ -1678,8 +1599,8 @@ function SearchBarComponent({ element, emit }) {
1678
1599
  paddingHorizontal: 12
1679
1600
  },
1680
1601
  children: [
1681
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native2.Text, { style: { fontSize: 16, color: "#9ca3af", marginRight: 8 }, children: "Search" }),
1682
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1602
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native2.Text, { style: { fontSize: 16, color: "#9ca3af", marginRight: 8 }, children: "Search" }),
1603
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1683
1604
  import_react_native2.TextInput,
1684
1605
  {
1685
1606
  placeholder: p.placeholder ?? "Search...",
@@ -1700,13 +1621,13 @@ function SearchBarComponent({ element, emit }) {
1700
1621
  }
1701
1622
  function SpinnerComponent({ element }) {
1702
1623
  const p = element.props;
1703
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native2.ActivityIndicator, { size: p.size ?? "small", color: p.color ?? "#3b82f6" });
1624
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native2.ActivityIndicator, { size: p.size ?? "small", color: p.color ?? "#3b82f6" });
1704
1625
  }
1705
1626
  function ProgressBarComponent({ element }) {
1706
1627
  const p = element.props;
1707
1628
  const height = p.height ?? 6;
1708
1629
  const progress = Math.min(Math.max(p.progress, 0), 1);
1709
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1630
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1710
1631
  import_react_native2.View,
1711
1632
  {
1712
1633
  style: {
@@ -1715,7 +1636,7 @@ function ProgressBarComponent({ element }) {
1715
1636
  borderRadius: height / 2,
1716
1637
  overflow: "hidden"
1717
1638
  },
1718
- children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1639
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1719
1640
  import_react_native2.View,
1720
1641
  {
1721
1642
  style: {
@@ -1733,7 +1654,7 @@ function CardComponent({ element, children }) {
1733
1654
  const p = element.props;
1734
1655
  const elevated = p.elevated !== false;
1735
1656
  const padding = p.padding ?? 16;
1736
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1657
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1737
1658
  import_react_native2.View,
1738
1659
  {
1739
1660
  style: [
@@ -1751,7 +1672,7 @@ function CardComponent({ element, children }) {
1751
1672
  }
1752
1673
  ],
1753
1674
  children: [
1754
- p.title && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1675
+ p.title && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1755
1676
  import_react_native2.Text,
1756
1677
  {
1757
1678
  style: {
@@ -1763,7 +1684,7 @@ function CardComponent({ element, children }) {
1763
1684
  children: p.title
1764
1685
  }
1765
1686
  ),
1766
- p.subtitle && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1687
+ p.subtitle && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1767
1688
  import_react_native2.Text,
1768
1689
  {
1769
1690
  style: {
@@ -1782,7 +1703,7 @@ function CardComponent({ element, children }) {
1782
1703
  function ListItemComponent({ element, emit }) {
1783
1704
  const p = element.props;
1784
1705
  const hasPress = !!element.on?.press;
1785
- const content = /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1706
+ const content = /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1786
1707
  import_react_native2.View,
1787
1708
  {
1788
1709
  style: {
@@ -1792,7 +1713,7 @@ function ListItemComponent({ element, emit }) {
1792
1713
  paddingHorizontal: 16
1793
1714
  },
1794
1715
  children: [
1795
- p.leading && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1716
+ p.leading && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1796
1717
  import_react_native2.Text,
1797
1718
  {
1798
1719
  style: {
@@ -1805,17 +1726,17 @@ function ListItemComponent({ element, emit }) {
1805
1726
  children: p.leading
1806
1727
  }
1807
1728
  ),
1808
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_react_native2.View, { style: { flex: 1 }, children: [
1809
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native2.Text, { style: { fontSize: 16, color: "#111827" }, children: p.title }),
1810
- p.subtitle && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native2.Text, { style: { fontSize: 14, color: "#6b7280", marginTop: 2 }, children: p.subtitle })
1729
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_react_native2.View, { style: { flex: 1 }, children: [
1730
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native2.Text, { style: { fontSize: 16, color: "#111827" }, children: p.title }),
1731
+ p.subtitle && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native2.Text, { style: { fontSize: 14, color: "#6b7280", marginTop: 2 }, children: p.subtitle })
1811
1732
  ] }),
1812
- p.trailing && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native2.Text, { style: { fontSize: 14, color: "#6b7280", marginLeft: 8 }, children: p.trailing }),
1813
- p.showChevron && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native2.Text, { style: { fontSize: 16, color: "#9ca3af", marginLeft: 8 }, children: ">" })
1733
+ p.trailing && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native2.Text, { style: { fontSize: 14, color: "#6b7280", marginLeft: 8 }, children: p.trailing }),
1734
+ p.showChevron && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native2.Text, { style: { fontSize: 16, color: "#9ca3af", marginLeft: 8 }, children: ">" })
1814
1735
  ]
1815
1736
  }
1816
1737
  );
1817
1738
  if (hasPress) {
1818
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1739
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1819
1740
  import_react_native2.Pressable,
1820
1741
  {
1821
1742
  onPress: () => emit("press"),
@@ -1831,14 +1752,14 @@ function ListItemComponent({ element, emit }) {
1831
1752
  }
1832
1753
  function ModalComponent({ element, children }) {
1833
1754
  const p = element.props;
1834
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1755
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1835
1756
  import_react_native2.Modal,
1836
1757
  {
1837
1758
  visible: p.visible,
1838
1759
  animationType: p.animationType ?? "slide",
1839
1760
  transparent: true,
1840
- children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native2.View, { style: modalStyles.overlay, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_react_native2.View, { style: modalStyles.content, children: [
1841
- p.title && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native2.Text, { style: modalStyles.title, children: p.title }),
1761
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native2.View, { style: modalStyles.overlay, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_react_native2.View, { style: modalStyles.content, children: [
1762
+ p.title && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native2.Text, { style: modalStyles.title, children: p.title }),
1842
1763
  children
1843
1764
  ] }) })
1844
1765
  }
@@ -1961,8 +1882,8 @@ var modalStyles = import_react_native2.StyleSheet.create({
1961
1882
  });
1962
1883
 
1963
1884
  // src/renderer.tsx
1964
- var import_jsx_runtime7 = require("react/jsx-runtime");
1965
- var ElementErrorBoundary = class extends import_react7.default.Component {
1885
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1886
+ var ElementErrorBoundary = class extends import_react6.default.Component {
1966
1887
  constructor(props) {
1967
1888
  super(props);
1968
1889
  this.state = { hasError: false };
@@ -1984,7 +1905,7 @@ var ElementErrorBoundary = class extends import_react7.default.Component {
1984
1905
  return this.props.children;
1985
1906
  }
1986
1907
  };
1987
- var ElementRenderer = import_react7.default.memo(function ElementRenderer2({
1908
+ var ElementRenderer = import_react6.default.memo(function ElementRenderer2({
1988
1909
  element,
1989
1910
  spec,
1990
1911
  registry,
@@ -1994,7 +1915,8 @@ var ElementRenderer = import_react7.default.memo(function ElementRenderer2({
1994
1915
  const repeatScope = useRepeatScope();
1995
1916
  const { ctx } = useVisibility();
1996
1917
  const { execute } = useActions();
1997
- const fullCtx = (0, import_react7.useMemo)(
1918
+ const { getSnapshot } = (0, import_react_state.useStateStore)();
1919
+ const fullCtx = (0, import_react6.useMemo)(
1998
1920
  () => repeatScope ? {
1999
1921
  ...ctx,
2000
1922
  repeatItem: repeatScope.item,
@@ -2003,40 +1925,44 @@ var ElementRenderer = import_react7.default.memo(function ElementRenderer2({
2003
1925
  } : ctx,
2004
1926
  [ctx, repeatScope]
2005
1927
  );
2006
- const isVisible = element.visible === void 0 ? true : (0, import_core7.evaluateVisibility)(element.visible, fullCtx);
1928
+ const isVisible = element.visible === void 0 ? true : (0, import_core6.evaluateVisibility)(element.visible, fullCtx);
2007
1929
  const onBindings = element.on;
2008
- const emit = (0, import_react7.useCallback)(
2009
- (eventName) => {
1930
+ const emit = (0, import_react6.useCallback)(
1931
+ async (eventName) => {
2010
1932
  const binding = onBindings?.[eventName];
2011
1933
  if (!binding) return;
2012
1934
  const actionBindings = Array.isArray(binding) ? binding : [binding];
2013
1935
  for (const b of actionBindings) {
2014
1936
  if (!b.params) {
2015
- execute(b);
1937
+ await execute(b);
2016
1938
  continue;
2017
1939
  }
1940
+ const liveCtx = {
1941
+ ...fullCtx,
1942
+ stateModel: getSnapshot()
1943
+ };
2018
1944
  const resolved = {};
2019
1945
  for (const [key, val] of Object.entries(b.params)) {
2020
- resolved[key] = (0, import_core7.resolveActionParam)(val, fullCtx);
1946
+ resolved[key] = (0, import_core6.resolveActionParam)(val, liveCtx);
2021
1947
  }
2022
- execute({ ...b, params: resolved });
1948
+ await execute({ ...b, params: resolved });
2023
1949
  }
2024
1950
  },
2025
- [onBindings, execute, fullCtx]
1951
+ [onBindings, execute, fullCtx, getSnapshot]
2026
1952
  );
2027
1953
  if (!isVisible) {
2028
1954
  return null;
2029
1955
  }
2030
1956
  const rawProps = element.props;
2031
- const elementBindings = (0, import_core7.resolveBindings)(rawProps, fullCtx);
2032
- const resolvedProps = (0, import_core7.resolveElementProps)(rawProps, fullCtx);
1957
+ const elementBindings = (0, import_core6.resolveBindings)(rawProps, fullCtx);
1958
+ const resolvedProps = (0, import_core6.resolveElementProps)(rawProps, fullCtx);
2033
1959
  const resolvedElement = resolvedProps !== element.props ? { ...element, props: resolvedProps } : element;
2034
1960
  const Component = registry[resolvedElement.type] ?? fallback;
2035
1961
  if (!Component) {
2036
1962
  console.warn(`No renderer for component type: ${resolvedElement.type}`);
2037
1963
  return null;
2038
1964
  }
2039
- const children = resolvedElement.repeat ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1965
+ const children = resolvedElement.repeat ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2040
1966
  RepeatChildren,
2041
1967
  {
2042
1968
  element: resolvedElement,
@@ -2055,7 +1981,7 @@ var ElementRenderer = import_react7.default.memo(function ElementRenderer2({
2055
1981
  }
2056
1982
  return null;
2057
1983
  }
2058
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1984
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2059
1985
  ElementRenderer2,
2060
1986
  {
2061
1987
  element: childElement,
@@ -2067,7 +1993,7 @@ var ElementRenderer = import_react7.default.memo(function ElementRenderer2({
2067
1993
  childKey
2068
1994
  );
2069
1995
  });
2070
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ElementErrorBoundary, { elementType: resolvedElement.type, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1996
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ElementErrorBoundary, { elementType: resolvedElement.type, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2071
1997
  Component,
2072
1998
  {
2073
1999
  element: resolvedElement,
@@ -2085,15 +2011,15 @@ function RepeatChildren({
2085
2011
  loading,
2086
2012
  fallback
2087
2013
  }) {
2088
- const { state } = useStateStore();
2014
+ const { state } = (0, import_react_state.useStateStore)();
2089
2015
  const repeat = element.repeat;
2090
2016
  const statePath = repeat.statePath;
2091
- const items = (0, import_core7.getByPath)(state, statePath) ?? [];
2092
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: items.map((itemValue, index) => {
2017
+ const items = (0, import_core6.getByPath)(state, statePath) ?? [];
2018
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_jsx_runtime6.Fragment, { children: items.map((itemValue, index) => {
2093
2019
  const key = repeat.key && typeof itemValue === "object" && itemValue !== null ? String(
2094
2020
  itemValue[repeat.key] ?? index
2095
2021
  ) : String(index);
2096
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2022
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2097
2023
  RepeatScopeProvider,
2098
2024
  {
2099
2025
  item: itemValue,
@@ -2109,7 +2035,7 @@ function RepeatChildren({
2109
2035
  }
2110
2036
  return null;
2111
2037
  }
2112
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2038
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2113
2039
  ElementRenderer,
2114
2040
  {
2115
2041
  element: childElement,
@@ -2133,7 +2059,7 @@ function Renderer({
2133
2059
  loading,
2134
2060
  fallback
2135
2061
  }) {
2136
- const registry = (0, import_react7.useMemo)(
2062
+ const registry = (0, import_react6.useMemo)(
2137
2063
  () => ({
2138
2064
  ...includeStandard ? standardComponents : {},
2139
2065
  ...customRegistry
@@ -2147,7 +2073,7 @@ function Renderer({
2147
2073
  if (!rootElement) {
2148
2074
  return null;
2149
2075
  }
2150
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2076
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2151
2077
  ElementRenderer,
2152
2078
  {
2153
2079
  element: rootElement,
@@ -2160,6 +2086,7 @@ function Renderer({
2160
2086
  }
2161
2087
  function JSONUIProvider({
2162
2088
  registry,
2089
+ store,
2163
2090
  initialState,
2164
2091
  handlers,
2165
2092
  navigate,
@@ -2167,17 +2094,25 @@ function JSONUIProvider({
2167
2094
  onStateChange,
2168
2095
  children
2169
2096
  }) {
2170
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StateProvider, { initialState, onStateChange, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(VisibilityProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ActionProvider, { handlers, navigate, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(ValidationProvider, { customFunctions: validationFunctions, children: [
2171
- children,
2172
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ConfirmationDialogManager, {})
2173
- ] }) }) }) });
2097
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2098
+ import_react_state.StateProvider,
2099
+ {
2100
+ store,
2101
+ initialState,
2102
+ onStateChange,
2103
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(VisibilityProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ActionProvider, { handlers, navigate, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(ValidationProvider, { customFunctions: validationFunctions, children: [
2104
+ children,
2105
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ConfirmationDialogManager, {})
2106
+ ] }) }) })
2107
+ }
2108
+ );
2174
2109
  }
2175
2110
  function ConfirmationDialogManager() {
2176
2111
  const { pendingConfirmation, confirm, cancel } = useActions();
2177
2112
  if (!pendingConfirmation?.action.confirm) {
2178
2113
  return null;
2179
2114
  }
2180
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2115
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2181
2116
  ConfirmDialog,
2182
2117
  {
2183
2118
  confirm: pendingConfirmation.action.confirm,
@@ -2235,6 +2170,7 @@ function createRenderer(catalog, components) {
2235
2170
  const registry = components;
2236
2171
  return function CatalogRenderer({
2237
2172
  spec,
2173
+ store,
2238
2174
  state,
2239
2175
  onAction,
2240
2176
  onStateChange,
@@ -2250,18 +2186,26 @@ function createRenderer(catalog, components) {
2250
2186
  has: () => true
2251
2187
  }
2252
2188
  ) : void 0;
2253
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StateProvider, { initialState: state, onStateChange, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(VisibilityProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ActionProvider, { handlers: actionHandlers, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(ValidationProvider, { children: [
2254
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2255
- Renderer,
2256
- {
2257
- spec,
2258
- registry,
2259
- loading,
2260
- fallback
2261
- }
2262
- ),
2263
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ConfirmationDialogManager, {})
2264
- ] }) }) }) });
2189
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2190
+ import_react_state.StateProvider,
2191
+ {
2192
+ store,
2193
+ initialState: state,
2194
+ onStateChange,
2195
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(VisibilityProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ActionProvider, { handlers: actionHandlers, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(ValidationProvider, { children: [
2196
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2197
+ Renderer,
2198
+ {
2199
+ spec,
2200
+ registry,
2201
+ loading,
2202
+ fallback
2203
+ }
2204
+ ),
2205
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ConfirmationDialogManager, {})
2206
+ ] }) }) })
2207
+ }
2208
+ );
2265
2209
  };
2266
2210
  }
2267
2211
 
@@ -2671,6 +2615,7 @@ var standardActionDefinitions = {
2671
2615
  VisibilityProvider,
2672
2616
  createRenderer,
2673
2617
  createStandardActionHandlers,
2618
+ createStateStore,
2674
2619
  defineRegistry,
2675
2620
  elementTreeSchema,
2676
2621
  flatToTree,