@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/README.md +21 -0
- package/dist/index.d.mts +27 -55
- package/dist/index.d.ts +27 -55
- package/dist/index.js +221 -276
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +202 -261
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
package/dist/index.mjs
CHANGED
|
@@ -9,129 +9,43 @@ import {
|
|
|
9
9
|
|
|
10
10
|
// src/contexts/state.tsx
|
|
11
11
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
useEffect,
|
|
18
|
-
useRef
|
|
19
|
-
} from "react";
|
|
20
|
-
import { getByPath, setByPath } from "@json-render/core";
|
|
21
|
-
import { jsx } from "react/jsx-runtime";
|
|
22
|
-
var StateContext = createContext(null);
|
|
23
|
-
function StateProvider({
|
|
24
|
-
initialState = {},
|
|
25
|
-
onStateChange,
|
|
26
|
-
children
|
|
27
|
-
}) {
|
|
28
|
-
const [state, setStateInternal] = useState(initialState);
|
|
29
|
-
const stateRef = useRef(state);
|
|
30
|
-
stateRef.current = state;
|
|
31
|
-
const initialStateJsonRef = useRef(JSON.stringify(initialState));
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
const newJson = JSON.stringify(initialState);
|
|
34
|
-
if (newJson !== initialStateJsonRef.current) {
|
|
35
|
-
initialStateJsonRef.current = newJson;
|
|
36
|
-
if (initialState && Object.keys(initialState).length > 0) {
|
|
37
|
-
setStateInternal((prev) => ({ ...prev, ...initialState }));
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}, [initialState]);
|
|
41
|
-
const get = useCallback(
|
|
42
|
-
(path) => getByPath(stateRef.current, path),
|
|
43
|
-
[]
|
|
44
|
-
);
|
|
45
|
-
const set = useCallback(
|
|
46
|
-
(path, value2) => {
|
|
47
|
-
setStateInternal((prev) => {
|
|
48
|
-
const next = { ...prev };
|
|
49
|
-
setByPath(next, path, value2);
|
|
50
|
-
return next;
|
|
51
|
-
});
|
|
52
|
-
onStateChange?.(path, value2);
|
|
53
|
-
},
|
|
54
|
-
[onStateChange]
|
|
55
|
-
);
|
|
56
|
-
const update = useCallback(
|
|
57
|
-
(updates) => {
|
|
58
|
-
const entries = Object.entries(updates);
|
|
59
|
-
setStateInternal((prev) => {
|
|
60
|
-
const next = { ...prev };
|
|
61
|
-
for (const [path, value2] of entries) {
|
|
62
|
-
setByPath(next, path, value2);
|
|
63
|
-
}
|
|
64
|
-
return next;
|
|
65
|
-
});
|
|
66
|
-
for (const [path, value2] of entries) {
|
|
67
|
-
onStateChange?.(path, value2);
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
[onStateChange]
|
|
71
|
-
);
|
|
72
|
-
const value = useMemo(
|
|
73
|
-
() => ({
|
|
74
|
-
state,
|
|
75
|
-
get,
|
|
76
|
-
set,
|
|
77
|
-
update
|
|
78
|
-
}),
|
|
79
|
-
[state, get, set, update]
|
|
80
|
-
);
|
|
81
|
-
return /* @__PURE__ */ jsx(StateContext.Provider, { value, children });
|
|
82
|
-
}
|
|
83
|
-
function useStateStore() {
|
|
84
|
-
const ctx = useContext(StateContext);
|
|
85
|
-
if (!ctx) {
|
|
86
|
-
throw new Error("useStateStore must be used within a StateProvider");
|
|
87
|
-
}
|
|
88
|
-
return ctx;
|
|
89
|
-
}
|
|
90
|
-
function useStateValue(path) {
|
|
91
|
-
const { state } = useStateStore();
|
|
92
|
-
return getByPath(state, path);
|
|
93
|
-
}
|
|
94
|
-
function useStateBinding(path) {
|
|
95
|
-
const { state, set } = useStateStore();
|
|
96
|
-
const value = getByPath(state, path);
|
|
97
|
-
const setValue = useCallback(
|
|
98
|
-
(newValue) => set(path, newValue),
|
|
99
|
-
[path, set]
|
|
100
|
-
);
|
|
101
|
-
return [value, setValue];
|
|
102
|
-
}
|
|
12
|
+
StateProvider,
|
|
13
|
+
useStateStore,
|
|
14
|
+
useStateValue,
|
|
15
|
+
useStateBinding
|
|
16
|
+
} from "@internal/react-state";
|
|
103
17
|
|
|
104
18
|
// src/contexts/visibility.tsx
|
|
105
19
|
import {
|
|
106
|
-
createContext
|
|
107
|
-
useContext
|
|
108
|
-
useMemo
|
|
20
|
+
createContext,
|
|
21
|
+
useContext,
|
|
22
|
+
useMemo
|
|
109
23
|
} from "react";
|
|
110
24
|
import {
|
|
111
25
|
evaluateVisibility
|
|
112
26
|
} from "@json-render/core";
|
|
113
|
-
import { jsx
|
|
114
|
-
var VisibilityContext =
|
|
27
|
+
import { jsx } from "react/jsx-runtime";
|
|
28
|
+
var VisibilityContext = createContext(null);
|
|
115
29
|
function VisibilityProvider({ children }) {
|
|
116
30
|
const { state } = useStateStore();
|
|
117
|
-
const ctx =
|
|
31
|
+
const ctx = useMemo(
|
|
118
32
|
() => ({
|
|
119
33
|
stateModel: state
|
|
120
34
|
}),
|
|
121
35
|
[state]
|
|
122
36
|
);
|
|
123
|
-
const isVisible =
|
|
37
|
+
const isVisible = useMemo(
|
|
124
38
|
() => (condition) => evaluateVisibility(condition, ctx),
|
|
125
39
|
[ctx]
|
|
126
40
|
);
|
|
127
|
-
const value =
|
|
41
|
+
const value = useMemo(
|
|
128
42
|
() => ({ isVisible, ctx }),
|
|
129
43
|
[isVisible, ctx]
|
|
130
44
|
);
|
|
131
|
-
return /* @__PURE__ */
|
|
45
|
+
return /* @__PURE__ */ jsx(VisibilityContext.Provider, { value, children });
|
|
132
46
|
}
|
|
133
47
|
function useVisibility() {
|
|
134
|
-
const ctx =
|
|
48
|
+
const ctx = useContext(VisibilityContext);
|
|
135
49
|
if (!ctx) {
|
|
136
50
|
throw new Error("useVisibility must be used within a VisibilityProvider");
|
|
137
51
|
}
|
|
@@ -144,18 +58,18 @@ function useIsVisible(condition) {
|
|
|
144
58
|
|
|
145
59
|
// src/contexts/actions.tsx
|
|
146
60
|
import {
|
|
147
|
-
createContext as
|
|
148
|
-
useContext as
|
|
149
|
-
useState
|
|
150
|
-
useCallback
|
|
151
|
-
useMemo as
|
|
61
|
+
createContext as createContext2,
|
|
62
|
+
useContext as useContext2,
|
|
63
|
+
useState,
|
|
64
|
+
useCallback,
|
|
65
|
+
useMemo as useMemo2
|
|
152
66
|
} from "react";
|
|
153
67
|
import { Modal, View, Text, Pressable, StyleSheet } from "react-native";
|
|
154
68
|
import {
|
|
155
69
|
resolveAction,
|
|
156
70
|
executeAction
|
|
157
71
|
} from "@json-render/core";
|
|
158
|
-
import { jsx as
|
|
72
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
159
73
|
var idCounter = 0;
|
|
160
74
|
function generateUniqueId() {
|
|
161
75
|
idCounter += 1;
|
|
@@ -188,25 +102,25 @@ function deepResolveValue(value, get) {
|
|
|
188
102
|
}
|
|
189
103
|
return value;
|
|
190
104
|
}
|
|
191
|
-
var ActionContext =
|
|
105
|
+
var ActionContext = createContext2(null);
|
|
192
106
|
function ActionProvider({
|
|
193
107
|
handlers: initialHandlers = {},
|
|
194
108
|
navigate,
|
|
195
109
|
children
|
|
196
110
|
}) {
|
|
197
|
-
const {
|
|
198
|
-
const [handlers, setHandlers] =
|
|
199
|
-
const [loadingActions, setLoadingActions] =
|
|
200
|
-
const [pendingConfirmation, setPendingConfirmation] =
|
|
201
|
-
const registerHandler =
|
|
111
|
+
const { get, set, getSnapshot } = useStateStore();
|
|
112
|
+
const [handlers, setHandlers] = useState(initialHandlers);
|
|
113
|
+
const [loadingActions, setLoadingActions] = useState(/* @__PURE__ */ new Set());
|
|
114
|
+
const [pendingConfirmation, setPendingConfirmation] = useState(null);
|
|
115
|
+
const registerHandler = useCallback(
|
|
202
116
|
(name, handler) => {
|
|
203
117
|
setHandlers((prev) => ({ ...prev, [name]: handler }));
|
|
204
118
|
},
|
|
205
119
|
[]
|
|
206
120
|
);
|
|
207
|
-
const execute =
|
|
121
|
+
const execute = useCallback(
|
|
208
122
|
async (binding) => {
|
|
209
|
-
const resolved = resolveAction(binding,
|
|
123
|
+
const resolved = resolveAction(binding, getSnapshot());
|
|
210
124
|
if (resolved.action === "setState" && resolved.params) {
|
|
211
125
|
const statePath = resolved.params.statePath;
|
|
212
126
|
const value2 = resolved.params.value;
|
|
@@ -329,15 +243,15 @@ function ActionProvider({
|
|
|
329
243
|
});
|
|
330
244
|
}
|
|
331
245
|
},
|
|
332
|
-
[
|
|
246
|
+
[handlers, get, set, getSnapshot, navigate]
|
|
333
247
|
);
|
|
334
|
-
const confirm =
|
|
248
|
+
const confirm = useCallback(() => {
|
|
335
249
|
pendingConfirmation?.resolve();
|
|
336
250
|
}, [pendingConfirmation]);
|
|
337
|
-
const cancel =
|
|
251
|
+
const cancel = useCallback(() => {
|
|
338
252
|
pendingConfirmation?.reject();
|
|
339
253
|
}, [pendingConfirmation]);
|
|
340
|
-
const value =
|
|
254
|
+
const value = useMemo2(
|
|
341
255
|
() => ({
|
|
342
256
|
handlers,
|
|
343
257
|
loadingActions,
|
|
@@ -357,10 +271,10 @@ function ActionProvider({
|
|
|
357
271
|
registerHandler
|
|
358
272
|
]
|
|
359
273
|
);
|
|
360
|
-
return /* @__PURE__ */
|
|
274
|
+
return /* @__PURE__ */ jsx2(ActionContext.Provider, { value, children });
|
|
361
275
|
}
|
|
362
276
|
function useActions() {
|
|
363
|
-
const ctx =
|
|
277
|
+
const ctx = useContext2(ActionContext);
|
|
364
278
|
if (!ctx) {
|
|
365
279
|
throw new Error("useActions must be used within an ActionProvider");
|
|
366
280
|
}
|
|
@@ -369,7 +283,7 @@ function useActions() {
|
|
|
369
283
|
function useAction(binding) {
|
|
370
284
|
const { execute, loadingActions } = useActions();
|
|
371
285
|
const isLoading = loadingActions.has(binding.action);
|
|
372
|
-
const executeAction2 =
|
|
286
|
+
const executeAction2 = useCallback(() => execute(binding), [execute, binding]);
|
|
373
287
|
return { execute: executeAction2, isLoading };
|
|
374
288
|
}
|
|
375
289
|
function ConfirmDialog({
|
|
@@ -378,13 +292,13 @@ function ConfirmDialog({
|
|
|
378
292
|
onCancel
|
|
379
293
|
}) {
|
|
380
294
|
const isDanger = confirm.variant === "danger";
|
|
381
|
-
return /* @__PURE__ */
|
|
295
|
+
return /* @__PURE__ */ jsx2(Modal, { transparent: true, animationType: "fade", visible: true, onRequestClose: onCancel, children: /* @__PURE__ */ jsx2(Pressable, { style: styles.overlay, onPress: onCancel, children: /* @__PURE__ */ jsxs(Pressable, { style: styles.dialog, onPress: () => {
|
|
382
296
|
}, children: [
|
|
383
|
-
/* @__PURE__ */
|
|
384
|
-
/* @__PURE__ */
|
|
297
|
+
/* @__PURE__ */ jsx2(Text, { style: styles.title, children: confirm.title }),
|
|
298
|
+
/* @__PURE__ */ jsx2(Text, { style: styles.message, children: confirm.message }),
|
|
385
299
|
/* @__PURE__ */ jsxs(View, { style: styles.buttons, children: [
|
|
386
|
-
/* @__PURE__ */
|
|
387
|
-
/* @__PURE__ */
|
|
300
|
+
/* @__PURE__ */ jsx2(Pressable, { style: styles.cancelButton, onPress: onCancel, children: /* @__PURE__ */ jsx2(Text, { style: styles.cancelButtonText, children: confirm.cancelLabel ?? "Cancel" }) }),
|
|
301
|
+
/* @__PURE__ */ jsx2(
|
|
388
302
|
Pressable,
|
|
389
303
|
{
|
|
390
304
|
style: [
|
|
@@ -392,7 +306,7 @@ function ConfirmDialog({
|
|
|
392
306
|
isDanger && styles.confirmButtonDanger
|
|
393
307
|
],
|
|
394
308
|
onPress: onConfirm,
|
|
395
|
-
children: /* @__PURE__ */
|
|
309
|
+
children: /* @__PURE__ */ jsx2(Text, { style: styles.confirmButtonText, children: confirm.confirmLabel ?? "Confirm" })
|
|
396
310
|
}
|
|
397
311
|
)
|
|
398
312
|
] })
|
|
@@ -460,18 +374,18 @@ var styles = StyleSheet.create({
|
|
|
460
374
|
});
|
|
461
375
|
|
|
462
376
|
// src/contexts/validation.tsx
|
|
463
|
-
import
|
|
464
|
-
createContext as
|
|
465
|
-
useContext as
|
|
466
|
-
useState as
|
|
467
|
-
useCallback as
|
|
468
|
-
useMemo as
|
|
377
|
+
import React3, {
|
|
378
|
+
createContext as createContext3,
|
|
379
|
+
useContext as useContext3,
|
|
380
|
+
useState as useState2,
|
|
381
|
+
useCallback as useCallback2,
|
|
382
|
+
useMemo as useMemo3
|
|
469
383
|
} from "react";
|
|
470
384
|
import {
|
|
471
385
|
runValidation
|
|
472
386
|
} from "@json-render/core";
|
|
473
|
-
import { jsx as
|
|
474
|
-
var ValidationContext =
|
|
387
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
388
|
+
var ValidationContext = createContext3(null);
|
|
475
389
|
function dynamicArgsEqual(a, b) {
|
|
476
390
|
if (a === b) return true;
|
|
477
391
|
if (!a || !b) return false;
|
|
@@ -511,9 +425,9 @@ function ValidationProvider({
|
|
|
511
425
|
children
|
|
512
426
|
}) {
|
|
513
427
|
const { state } = useStateStore();
|
|
514
|
-
const [fieldStates, setFieldStates] =
|
|
515
|
-
const [fieldConfigs, setFieldConfigs] =
|
|
516
|
-
const registerField =
|
|
428
|
+
const [fieldStates, setFieldStates] = useState2({});
|
|
429
|
+
const [fieldConfigs, setFieldConfigs] = useState2({});
|
|
430
|
+
const registerField = useCallback2(
|
|
517
431
|
(path, config) => {
|
|
518
432
|
setFieldConfigs((prev) => {
|
|
519
433
|
const existing = prev[path];
|
|
@@ -525,7 +439,7 @@ function ValidationProvider({
|
|
|
525
439
|
},
|
|
526
440
|
[]
|
|
527
441
|
);
|
|
528
|
-
const validate =
|
|
442
|
+
const validate = useCallback2(
|
|
529
443
|
(path, config) => {
|
|
530
444
|
const segments = path.split("/").filter(Boolean);
|
|
531
445
|
let value2 = state;
|
|
@@ -554,7 +468,7 @@ function ValidationProvider({
|
|
|
554
468
|
},
|
|
555
469
|
[state, customFunctions]
|
|
556
470
|
);
|
|
557
|
-
const touch =
|
|
471
|
+
const touch = useCallback2((path) => {
|
|
558
472
|
setFieldStates((prev) => ({
|
|
559
473
|
...prev,
|
|
560
474
|
[path]: {
|
|
@@ -565,13 +479,13 @@ function ValidationProvider({
|
|
|
565
479
|
}
|
|
566
480
|
}));
|
|
567
481
|
}, []);
|
|
568
|
-
const clear =
|
|
482
|
+
const clear = useCallback2((path) => {
|
|
569
483
|
setFieldStates((prev) => {
|
|
570
484
|
const { [path]: _, ...rest } = prev;
|
|
571
485
|
return rest;
|
|
572
486
|
});
|
|
573
487
|
}, []);
|
|
574
|
-
const validateAll =
|
|
488
|
+
const validateAll = useCallback2(() => {
|
|
575
489
|
let allValid = true;
|
|
576
490
|
for (const [path, config] of Object.entries(fieldConfigs)) {
|
|
577
491
|
const result = validate(path, config);
|
|
@@ -581,7 +495,7 @@ function ValidationProvider({
|
|
|
581
495
|
}
|
|
582
496
|
return allValid;
|
|
583
497
|
}, [fieldConfigs, validate]);
|
|
584
|
-
const value =
|
|
498
|
+
const value = useMemo3(
|
|
585
499
|
() => ({
|
|
586
500
|
customFunctions,
|
|
587
501
|
fieldStates,
|
|
@@ -601,10 +515,10 @@ function ValidationProvider({
|
|
|
601
515
|
registerField
|
|
602
516
|
]
|
|
603
517
|
);
|
|
604
|
-
return /* @__PURE__ */
|
|
518
|
+
return /* @__PURE__ */ jsx3(ValidationContext.Provider, { value, children });
|
|
605
519
|
}
|
|
606
520
|
function useValidation() {
|
|
607
|
-
const ctx =
|
|
521
|
+
const ctx = useContext3(ValidationContext);
|
|
608
522
|
if (!ctx) {
|
|
609
523
|
throw new Error("useValidation must be used within a ValidationProvider");
|
|
610
524
|
}
|
|
@@ -618,7 +532,7 @@ function useFieldValidation(path, config) {
|
|
|
618
532
|
clear: clearField,
|
|
619
533
|
registerField
|
|
620
534
|
} = useValidation();
|
|
621
|
-
|
|
535
|
+
React3.useEffect(() => {
|
|
622
536
|
if (config) {
|
|
623
537
|
registerField(path, config);
|
|
624
538
|
}
|
|
@@ -628,12 +542,12 @@ function useFieldValidation(path, config) {
|
|
|
628
542
|
validated: false,
|
|
629
543
|
result: null
|
|
630
544
|
};
|
|
631
|
-
const validate =
|
|
545
|
+
const validate = useCallback2(
|
|
632
546
|
() => validateField(path, config ?? { checks: [] }),
|
|
633
547
|
[path, config, validateField]
|
|
634
548
|
);
|
|
635
|
-
const touch =
|
|
636
|
-
const clear =
|
|
549
|
+
const touch = useCallback2(() => touchField(path), [path, touchField]);
|
|
550
|
+
const clear = useCallback2(() => clearField(path), [path, clearField]);
|
|
637
551
|
return {
|
|
638
552
|
state,
|
|
639
553
|
validate,
|
|
@@ -645,32 +559,35 @@ function useFieldValidation(path, config) {
|
|
|
645
559
|
}
|
|
646
560
|
|
|
647
561
|
// src/contexts/repeat-scope.tsx
|
|
648
|
-
import { createContext as
|
|
649
|
-
import { jsx as
|
|
650
|
-
var RepeatScopeContext =
|
|
562
|
+
import { createContext as createContext4, useContext as useContext4 } from "react";
|
|
563
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
564
|
+
var RepeatScopeContext = createContext4(null);
|
|
651
565
|
function RepeatScopeProvider({
|
|
652
566
|
item,
|
|
653
567
|
index,
|
|
654
568
|
basePath,
|
|
655
569
|
children
|
|
656
570
|
}) {
|
|
657
|
-
return /* @__PURE__ */
|
|
571
|
+
return /* @__PURE__ */ jsx4(RepeatScopeContext.Provider, { value: { item, index, basePath }, children });
|
|
658
572
|
}
|
|
659
573
|
function useRepeatScope() {
|
|
660
|
-
return
|
|
574
|
+
return useContext4(RepeatScopeContext);
|
|
661
575
|
}
|
|
662
576
|
|
|
577
|
+
// src/index.ts
|
|
578
|
+
import { createStateStore } from "@json-render/core";
|
|
579
|
+
|
|
663
580
|
// src/renderer.tsx
|
|
664
|
-
import
|
|
665
|
-
useCallback as
|
|
666
|
-
useMemo as
|
|
581
|
+
import React5, {
|
|
582
|
+
useCallback as useCallback4,
|
|
583
|
+
useMemo as useMemo4
|
|
667
584
|
} from "react";
|
|
668
585
|
import {
|
|
669
586
|
resolveElementProps,
|
|
670
587
|
resolveBindings,
|
|
671
588
|
resolveActionParam,
|
|
672
589
|
evaluateVisibility as evaluateVisibility2,
|
|
673
|
-
getByPath as
|
|
590
|
+
getByPath as getByPath2
|
|
674
591
|
} from "@json-render/core";
|
|
675
592
|
|
|
676
593
|
// src/components/standard.tsx
|
|
@@ -692,10 +609,10 @@ import {
|
|
|
692
609
|
} from "react-native";
|
|
693
610
|
|
|
694
611
|
// src/hooks.ts
|
|
695
|
-
import { useState as
|
|
612
|
+
import { useState as useState3, useCallback as useCallback3, useRef, useEffect } from "react";
|
|
696
613
|
import {
|
|
697
|
-
setByPath
|
|
698
|
-
getByPath
|
|
614
|
+
setByPath,
|
|
615
|
+
getByPath,
|
|
699
616
|
removeByPath,
|
|
700
617
|
validateSpec,
|
|
701
618
|
autoFixSpec,
|
|
@@ -703,7 +620,7 @@ import {
|
|
|
703
620
|
} from "@json-render/core";
|
|
704
621
|
function useBoundProp(propValue, bindingPath) {
|
|
705
622
|
const { set } = useStateStore();
|
|
706
|
-
const setValue =
|
|
623
|
+
const setValue = useCallback3(
|
|
707
624
|
(value) => {
|
|
708
625
|
if (bindingPath) set(bindingPath, value);
|
|
709
626
|
},
|
|
@@ -757,7 +674,7 @@ function setSpecValue(newSpec, path, value) {
|
|
|
757
674
|
if (path.startsWith("/state/")) {
|
|
758
675
|
if (!newSpec.state) newSpec.state = {};
|
|
759
676
|
const statePath = path.slice("/state".length);
|
|
760
|
-
|
|
677
|
+
setByPath(newSpec.state, statePath, value);
|
|
761
678
|
return;
|
|
762
679
|
}
|
|
763
680
|
if (path.startsWith("/elements/")) {
|
|
@@ -771,7 +688,7 @@ function setSpecValue(newSpec, path, value) {
|
|
|
771
688
|
if (element) {
|
|
772
689
|
const propPath = "/" + pathParts.slice(1).join("/");
|
|
773
690
|
const newElement = { ...element };
|
|
774
|
-
|
|
691
|
+
setByPath(
|
|
775
692
|
newElement,
|
|
776
693
|
propPath,
|
|
777
694
|
value
|
|
@@ -814,7 +731,7 @@ function removeSpecValue(newSpec, path) {
|
|
|
814
731
|
}
|
|
815
732
|
function getSpecValue(spec, path) {
|
|
816
733
|
if (path === "/root") return spec.root;
|
|
817
|
-
return
|
|
734
|
+
return getByPath(spec, path);
|
|
818
735
|
}
|
|
819
736
|
function applyPatch(spec, patch) {
|
|
820
737
|
const newSpec = { ...spec, elements: { ...spec.elements } };
|
|
@@ -855,22 +772,22 @@ function useUIStream({
|
|
|
855
772
|
validate: enableValidation = false,
|
|
856
773
|
maxRetries = 5
|
|
857
774
|
}) {
|
|
858
|
-
const [spec, setSpec] =
|
|
859
|
-
const [isStreaming, setIsStreaming] =
|
|
860
|
-
const [error, setError] =
|
|
861
|
-
const [rawLines, setRawLines] =
|
|
862
|
-
const abortControllerRef =
|
|
863
|
-
const stop =
|
|
775
|
+
const [spec, setSpec] = useState3(null);
|
|
776
|
+
const [isStreaming, setIsStreaming] = useState3(false);
|
|
777
|
+
const [error, setError] = useState3(null);
|
|
778
|
+
const [rawLines, setRawLines] = useState3([]);
|
|
779
|
+
const abortControllerRef = useRef(null);
|
|
780
|
+
const stop = useCallback3(() => {
|
|
864
781
|
abortControllerRef.current?.abort();
|
|
865
782
|
abortControllerRef.current = null;
|
|
866
783
|
setIsStreaming(false);
|
|
867
784
|
}, []);
|
|
868
|
-
const clear =
|
|
785
|
+
const clear = useCallback3(() => {
|
|
869
786
|
setSpec(null);
|
|
870
787
|
setError(null);
|
|
871
788
|
setRawLines([]);
|
|
872
789
|
}, []);
|
|
873
|
-
const streamRequest =
|
|
790
|
+
const streamRequest = useCallback3(
|
|
874
791
|
async (prompt, context, initialSpec, abortOnMalformed) => {
|
|
875
792
|
let currentSpec = initialSpec;
|
|
876
793
|
setSpec(currentSpec);
|
|
@@ -951,7 +868,7 @@ function useUIStream({
|
|
|
951
868
|
},
|
|
952
869
|
[api, fetchFn]
|
|
953
870
|
);
|
|
954
|
-
const send =
|
|
871
|
+
const send = useCallback3(
|
|
955
872
|
async (prompt, context) => {
|
|
956
873
|
abortControllerRef.current?.abort();
|
|
957
874
|
abortControllerRef.current = new AbortController();
|
|
@@ -1032,7 +949,7 @@ The current spec state is provided. Continue generating from where you left off.
|
|
|
1032
949
|
streamRequest
|
|
1033
950
|
]
|
|
1034
951
|
);
|
|
1035
|
-
|
|
952
|
+
useEffect(() => {
|
|
1036
953
|
return () => {
|
|
1037
954
|
abortControllerRef.current?.abort();
|
|
1038
955
|
};
|
|
@@ -1075,10 +992,10 @@ function flatToTree(elements) {
|
|
|
1075
992
|
}
|
|
1076
993
|
|
|
1077
994
|
// src/components/standard.tsx
|
|
1078
|
-
import { jsx as
|
|
995
|
+
import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
1079
996
|
function ContainerComponent({ element, children }) {
|
|
1080
997
|
const p = element.props;
|
|
1081
|
-
return /* @__PURE__ */
|
|
998
|
+
return /* @__PURE__ */ jsx5(
|
|
1082
999
|
View2,
|
|
1083
1000
|
{
|
|
1084
1001
|
style: {
|
|
@@ -1096,7 +1013,7 @@ function ContainerComponent({ element, children }) {
|
|
|
1096
1013
|
}
|
|
1097
1014
|
function RowComponent({ element, children }) {
|
|
1098
1015
|
const p = element.props;
|
|
1099
|
-
return /* @__PURE__ */
|
|
1016
|
+
return /* @__PURE__ */ jsx5(
|
|
1100
1017
|
View2,
|
|
1101
1018
|
{
|
|
1102
1019
|
style: {
|
|
@@ -1114,7 +1031,7 @@ function RowComponent({ element, children }) {
|
|
|
1114
1031
|
}
|
|
1115
1032
|
function ColumnComponent({ element, children }) {
|
|
1116
1033
|
const p = element.props;
|
|
1117
|
-
return /* @__PURE__ */
|
|
1034
|
+
return /* @__PURE__ */ jsx5(
|
|
1118
1035
|
View2,
|
|
1119
1036
|
{
|
|
1120
1037
|
style: {
|
|
@@ -1131,7 +1048,7 @@ function ColumnComponent({ element, children }) {
|
|
|
1131
1048
|
}
|
|
1132
1049
|
function ScrollContainerComponent({ element, children }) {
|
|
1133
1050
|
const p = element.props;
|
|
1134
|
-
return /* @__PURE__ */
|
|
1051
|
+
return /* @__PURE__ */ jsx5(
|
|
1135
1052
|
ScrollView,
|
|
1136
1053
|
{
|
|
1137
1054
|
horizontal: p.horizontal ?? false,
|
|
@@ -1150,7 +1067,7 @@ function ScrollContainerComponent({ element, children }) {
|
|
|
1150
1067
|
}
|
|
1151
1068
|
function SafeAreaComponent({ element, children }) {
|
|
1152
1069
|
const p = element.props;
|
|
1153
|
-
return /* @__PURE__ */
|
|
1070
|
+
return /* @__PURE__ */ jsx5(
|
|
1154
1071
|
SafeAreaView,
|
|
1155
1072
|
{
|
|
1156
1073
|
style: {
|
|
@@ -1163,7 +1080,7 @@ function SafeAreaComponent({ element, children }) {
|
|
|
1163
1080
|
}
|
|
1164
1081
|
function SpacerComponent({ element }) {
|
|
1165
1082
|
const p = element.props;
|
|
1166
|
-
return /* @__PURE__ */
|
|
1083
|
+
return /* @__PURE__ */ jsx5(
|
|
1167
1084
|
View2,
|
|
1168
1085
|
{
|
|
1169
1086
|
style: {
|
|
@@ -1175,7 +1092,7 @@ function SpacerComponent({ element }) {
|
|
|
1175
1092
|
);
|
|
1176
1093
|
}
|
|
1177
1094
|
function PressableComponent({ children, emit }) {
|
|
1178
|
-
return /* @__PURE__ */
|
|
1095
|
+
return /* @__PURE__ */ jsx5(
|
|
1179
1096
|
Pressable2,
|
|
1180
1097
|
{
|
|
1181
1098
|
onPress: () => emit("press"),
|
|
@@ -1192,7 +1109,7 @@ function DividerComponent({ element }) {
|
|
|
1192
1109
|
const isVertical = p.direction === "vertical";
|
|
1193
1110
|
const thickness = p.thickness ?? 1;
|
|
1194
1111
|
const color = p.color ?? "#e5e7eb";
|
|
1195
|
-
return /* @__PURE__ */
|
|
1112
|
+
return /* @__PURE__ */ jsx5(
|
|
1196
1113
|
View2,
|
|
1197
1114
|
{
|
|
1198
1115
|
style: {
|
|
@@ -1214,7 +1131,7 @@ var headingSizes = {
|
|
|
1214
1131
|
function HeadingComponent({ element }) {
|
|
1215
1132
|
const p = element.props;
|
|
1216
1133
|
const level = p.level ?? "h2";
|
|
1217
|
-
return /* @__PURE__ */
|
|
1134
|
+
return /* @__PURE__ */ jsx5(
|
|
1218
1135
|
Text2,
|
|
1219
1136
|
{
|
|
1220
1137
|
style: {
|
|
@@ -1229,7 +1146,7 @@ function HeadingComponent({ element }) {
|
|
|
1229
1146
|
}
|
|
1230
1147
|
function ParagraphComponent({ element }) {
|
|
1231
1148
|
const p = element.props;
|
|
1232
|
-
return /* @__PURE__ */
|
|
1149
|
+
return /* @__PURE__ */ jsx5(
|
|
1233
1150
|
Text2,
|
|
1234
1151
|
{
|
|
1235
1152
|
numberOfLines: p.numberOfLines ?? void 0,
|
|
@@ -1250,7 +1167,7 @@ var labelSizes = {
|
|
|
1250
1167
|
};
|
|
1251
1168
|
function LabelComponent({ element }) {
|
|
1252
1169
|
const p = element.props;
|
|
1253
|
-
return /* @__PURE__ */
|
|
1170
|
+
return /* @__PURE__ */ jsx5(
|
|
1254
1171
|
Text2,
|
|
1255
1172
|
{
|
|
1256
1173
|
style: {
|
|
@@ -1264,7 +1181,7 @@ function LabelComponent({ element }) {
|
|
|
1264
1181
|
}
|
|
1265
1182
|
function ImageComponent({ element }) {
|
|
1266
1183
|
const p = element.props;
|
|
1267
|
-
return /* @__PURE__ */
|
|
1184
|
+
return /* @__PURE__ */ jsx5(
|
|
1268
1185
|
RNImage,
|
|
1269
1186
|
{
|
|
1270
1187
|
source: { uri: p.src },
|
|
@@ -1289,7 +1206,7 @@ function AvatarComponent({ element }) {
|
|
|
1289
1206
|
const size = avatarSizeMap[p.size ?? "md"];
|
|
1290
1207
|
const bgColor = p.backgroundColor ?? "#6366f1";
|
|
1291
1208
|
if (p.src) {
|
|
1292
|
-
return /* @__PURE__ */
|
|
1209
|
+
return /* @__PURE__ */ jsx5(
|
|
1293
1210
|
RNImage,
|
|
1294
1211
|
{
|
|
1295
1212
|
source: { uri: p.src },
|
|
@@ -1302,7 +1219,7 @@ function AvatarComponent({ element }) {
|
|
|
1302
1219
|
}
|
|
1303
1220
|
);
|
|
1304
1221
|
}
|
|
1305
|
-
return /* @__PURE__ */
|
|
1222
|
+
return /* @__PURE__ */ jsx5(
|
|
1306
1223
|
View2,
|
|
1307
1224
|
{
|
|
1308
1225
|
style: {
|
|
@@ -1313,7 +1230,7 @@ function AvatarComponent({ element }) {
|
|
|
1313
1230
|
alignItems: "center",
|
|
1314
1231
|
justifyContent: "center"
|
|
1315
1232
|
},
|
|
1316
|
-
children: /* @__PURE__ */
|
|
1233
|
+
children: /* @__PURE__ */ jsx5(
|
|
1317
1234
|
Text2,
|
|
1318
1235
|
{
|
|
1319
1236
|
style: {
|
|
@@ -1340,7 +1257,7 @@ function BadgeComponent({ element }) {
|
|
|
1340
1257
|
bg: "#e5e7eb",
|
|
1341
1258
|
text: "#374151"
|
|
1342
1259
|
};
|
|
1343
|
-
return /* @__PURE__ */
|
|
1260
|
+
return /* @__PURE__ */ jsx5(
|
|
1344
1261
|
View2,
|
|
1345
1262
|
{
|
|
1346
1263
|
style: {
|
|
@@ -1350,7 +1267,7 @@ function BadgeComponent({ element }) {
|
|
|
1350
1267
|
borderRadius: 9999,
|
|
1351
1268
|
alignSelf: "flex-start"
|
|
1352
1269
|
},
|
|
1353
|
-
children: /* @__PURE__ */
|
|
1270
|
+
children: /* @__PURE__ */ jsx5(
|
|
1354
1271
|
Text2,
|
|
1355
1272
|
{
|
|
1356
1273
|
style: {
|
|
@@ -1383,8 +1300,8 @@ function ChipComponent({ element, emit }) {
|
|
|
1383
1300
|
alignSelf: "flex-start"
|
|
1384
1301
|
},
|
|
1385
1302
|
children: [
|
|
1386
|
-
/* @__PURE__ */
|
|
1387
|
-
hasRemove && /* @__PURE__ */
|
|
1303
|
+
/* @__PURE__ */ jsx5(Text2, { style: { fontSize: 14, color: textColor }, children: p.label }),
|
|
1304
|
+
hasRemove && /* @__PURE__ */ jsx5(Pressable2, { onPress: () => emit("remove"), style: { marginLeft: 4 }, children: /* @__PURE__ */ jsx5(Text2, { style: { fontSize: 14, color: textColor, fontWeight: "700" }, children: "x" }) })
|
|
1388
1305
|
]
|
|
1389
1306
|
}
|
|
1390
1307
|
);
|
|
@@ -1432,7 +1349,7 @@ function ButtonComponent({ element, emit }) {
|
|
|
1432
1349
|
alignSelf: "flex-start"
|
|
1433
1350
|
}),
|
|
1434
1351
|
children: [
|
|
1435
|
-
p.loading && /* @__PURE__ */
|
|
1352
|
+
p.loading && /* @__PURE__ */ jsx5(
|
|
1436
1353
|
ActivityIndicator,
|
|
1437
1354
|
{
|
|
1438
1355
|
size: "small",
|
|
@@ -1440,7 +1357,7 @@ function ButtonComponent({ element, emit }) {
|
|
|
1440
1357
|
style: { marginRight: 8 }
|
|
1441
1358
|
}
|
|
1442
1359
|
),
|
|
1443
|
-
/* @__PURE__ */
|
|
1360
|
+
/* @__PURE__ */ jsx5(
|
|
1444
1361
|
Text2,
|
|
1445
1362
|
{
|
|
1446
1363
|
style: {
|
|
@@ -1463,8 +1380,8 @@ function TextInputComponent({ element, bindings }) {
|
|
|
1463
1380
|
);
|
|
1464
1381
|
const displayValue = boundValue ?? "";
|
|
1465
1382
|
return /* @__PURE__ */ jsxs2(View2, { style: p.flex != null ? { flex: p.flex } : void 0, children: [
|
|
1466
|
-
p.label && /* @__PURE__ */
|
|
1467
|
-
/* @__PURE__ */
|
|
1383
|
+
p.label && /* @__PURE__ */ jsx5(Text2, { style: inputStyles.label, children: p.label }),
|
|
1384
|
+
/* @__PURE__ */ jsx5(
|
|
1468
1385
|
RNTextInput,
|
|
1469
1386
|
{
|
|
1470
1387
|
placeholder: p.placeholder ?? void 0,
|
|
@@ -1493,7 +1410,7 @@ function SwitchComponent({ element, bindings }) {
|
|
|
1493
1410
|
);
|
|
1494
1411
|
const displayValue = checked ?? false;
|
|
1495
1412
|
return /* @__PURE__ */ jsxs2(View2, { style: { flexDirection: "row", alignItems: "center", gap: 8 }, children: [
|
|
1496
|
-
/* @__PURE__ */
|
|
1413
|
+
/* @__PURE__ */ jsx5(
|
|
1497
1414
|
RNSwitch,
|
|
1498
1415
|
{
|
|
1499
1416
|
value: displayValue,
|
|
@@ -1501,7 +1418,7 @@ function SwitchComponent({ element, bindings }) {
|
|
|
1501
1418
|
disabled: p.disabled ?? false
|
|
1502
1419
|
}
|
|
1503
1420
|
),
|
|
1504
|
-
p.label && /* @__PURE__ */
|
|
1421
|
+
p.label && /* @__PURE__ */ jsx5(Text2, { style: { fontSize: 16, color: "#374151" }, children: p.label })
|
|
1505
1422
|
] });
|
|
1506
1423
|
}
|
|
1507
1424
|
function CheckboxComponent({ element, bindings }) {
|
|
@@ -1527,7 +1444,7 @@ function CheckboxComponent({ element, bindings }) {
|
|
|
1527
1444
|
opacity: p.disabled ? 0.5 : 1
|
|
1528
1445
|
},
|
|
1529
1446
|
children: [
|
|
1530
|
-
/* @__PURE__ */
|
|
1447
|
+
/* @__PURE__ */ jsx5(
|
|
1531
1448
|
View2,
|
|
1532
1449
|
{
|
|
1533
1450
|
style: {
|
|
@@ -1540,10 +1457,10 @@ function CheckboxComponent({ element, bindings }) {
|
|
|
1540
1457
|
alignItems: "center",
|
|
1541
1458
|
justifyContent: "center"
|
|
1542
1459
|
},
|
|
1543
|
-
children: isChecked && /* @__PURE__ */
|
|
1460
|
+
children: isChecked && /* @__PURE__ */ jsx5(Text2, { style: { color: "#ffffff", fontSize: 12, fontWeight: "700" }, children: "\u2713" })
|
|
1544
1461
|
}
|
|
1545
1462
|
),
|
|
1546
|
-
p.label && /* @__PURE__ */
|
|
1463
|
+
p.label && /* @__PURE__ */ jsx5(Text2, { style: { fontSize: 16, color: "#374151" }, children: p.label })
|
|
1547
1464
|
]
|
|
1548
1465
|
}
|
|
1549
1466
|
);
|
|
@@ -1565,12 +1482,12 @@ function SliderComponent({ element }) {
|
|
|
1565
1482
|
marginBottom: 4
|
|
1566
1483
|
},
|
|
1567
1484
|
children: [
|
|
1568
|
-
/* @__PURE__ */
|
|
1569
|
-
/* @__PURE__ */
|
|
1485
|
+
/* @__PURE__ */ jsx5(Text2, { style: { fontSize: 14, color: "#374151" }, children: p.label }),
|
|
1486
|
+
/* @__PURE__ */ jsx5(Text2, { style: { fontSize: 14, color: "#6b7280" }, children: value })
|
|
1570
1487
|
]
|
|
1571
1488
|
}
|
|
1572
1489
|
),
|
|
1573
|
-
/* @__PURE__ */
|
|
1490
|
+
/* @__PURE__ */ jsx5(
|
|
1574
1491
|
View2,
|
|
1575
1492
|
{
|
|
1576
1493
|
style: {
|
|
@@ -1579,7 +1496,7 @@ function SliderComponent({ element }) {
|
|
|
1579
1496
|
borderRadius: 3,
|
|
1580
1497
|
overflow: "hidden"
|
|
1581
1498
|
},
|
|
1582
|
-
children: /* @__PURE__ */
|
|
1499
|
+
children: /* @__PURE__ */ jsx5(
|
|
1583
1500
|
View2,
|
|
1584
1501
|
{
|
|
1585
1502
|
style: {
|
|
@@ -1607,8 +1524,8 @@ function SearchBarComponent({ element, emit }) {
|
|
|
1607
1524
|
paddingHorizontal: 12
|
|
1608
1525
|
},
|
|
1609
1526
|
children: [
|
|
1610
|
-
/* @__PURE__ */
|
|
1611
|
-
/* @__PURE__ */
|
|
1527
|
+
/* @__PURE__ */ jsx5(Text2, { style: { fontSize: 16, color: "#9ca3af", marginRight: 8 }, children: "Search" }),
|
|
1528
|
+
/* @__PURE__ */ jsx5(
|
|
1612
1529
|
RNTextInput,
|
|
1613
1530
|
{
|
|
1614
1531
|
placeholder: p.placeholder ?? "Search...",
|
|
@@ -1629,13 +1546,13 @@ function SearchBarComponent({ element, emit }) {
|
|
|
1629
1546
|
}
|
|
1630
1547
|
function SpinnerComponent({ element }) {
|
|
1631
1548
|
const p = element.props;
|
|
1632
|
-
return /* @__PURE__ */
|
|
1549
|
+
return /* @__PURE__ */ jsx5(ActivityIndicator, { size: p.size ?? "small", color: p.color ?? "#3b82f6" });
|
|
1633
1550
|
}
|
|
1634
1551
|
function ProgressBarComponent({ element }) {
|
|
1635
1552
|
const p = element.props;
|
|
1636
1553
|
const height = p.height ?? 6;
|
|
1637
1554
|
const progress = Math.min(Math.max(p.progress, 0), 1);
|
|
1638
|
-
return /* @__PURE__ */
|
|
1555
|
+
return /* @__PURE__ */ jsx5(
|
|
1639
1556
|
View2,
|
|
1640
1557
|
{
|
|
1641
1558
|
style: {
|
|
@@ -1644,7 +1561,7 @@ function ProgressBarComponent({ element }) {
|
|
|
1644
1561
|
borderRadius: height / 2,
|
|
1645
1562
|
overflow: "hidden"
|
|
1646
1563
|
},
|
|
1647
|
-
children: /* @__PURE__ */
|
|
1564
|
+
children: /* @__PURE__ */ jsx5(
|
|
1648
1565
|
View2,
|
|
1649
1566
|
{
|
|
1650
1567
|
style: {
|
|
@@ -1680,7 +1597,7 @@ function CardComponent({ element, children }) {
|
|
|
1680
1597
|
}
|
|
1681
1598
|
],
|
|
1682
1599
|
children: [
|
|
1683
|
-
p.title && /* @__PURE__ */
|
|
1600
|
+
p.title && /* @__PURE__ */ jsx5(
|
|
1684
1601
|
Text2,
|
|
1685
1602
|
{
|
|
1686
1603
|
style: {
|
|
@@ -1692,7 +1609,7 @@ function CardComponent({ element, children }) {
|
|
|
1692
1609
|
children: p.title
|
|
1693
1610
|
}
|
|
1694
1611
|
),
|
|
1695
|
-
p.subtitle && /* @__PURE__ */
|
|
1612
|
+
p.subtitle && /* @__PURE__ */ jsx5(
|
|
1696
1613
|
Text2,
|
|
1697
1614
|
{
|
|
1698
1615
|
style: {
|
|
@@ -1721,7 +1638,7 @@ function ListItemComponent({ element, emit }) {
|
|
|
1721
1638
|
paddingHorizontal: 16
|
|
1722
1639
|
},
|
|
1723
1640
|
children: [
|
|
1724
|
-
p.leading && /* @__PURE__ */
|
|
1641
|
+
p.leading && /* @__PURE__ */ jsx5(
|
|
1725
1642
|
Text2,
|
|
1726
1643
|
{
|
|
1727
1644
|
style: {
|
|
@@ -1735,16 +1652,16 @@ function ListItemComponent({ element, emit }) {
|
|
|
1735
1652
|
}
|
|
1736
1653
|
),
|
|
1737
1654
|
/* @__PURE__ */ jsxs2(View2, { style: { flex: 1 }, children: [
|
|
1738
|
-
/* @__PURE__ */
|
|
1739
|
-
p.subtitle && /* @__PURE__ */
|
|
1655
|
+
/* @__PURE__ */ jsx5(Text2, { style: { fontSize: 16, color: "#111827" }, children: p.title }),
|
|
1656
|
+
p.subtitle && /* @__PURE__ */ jsx5(Text2, { style: { fontSize: 14, color: "#6b7280", marginTop: 2 }, children: p.subtitle })
|
|
1740
1657
|
] }),
|
|
1741
|
-
p.trailing && /* @__PURE__ */
|
|
1742
|
-
p.showChevron && /* @__PURE__ */
|
|
1658
|
+
p.trailing && /* @__PURE__ */ jsx5(Text2, { style: { fontSize: 14, color: "#6b7280", marginLeft: 8 }, children: p.trailing }),
|
|
1659
|
+
p.showChevron && /* @__PURE__ */ jsx5(Text2, { style: { fontSize: 16, color: "#9ca3af", marginLeft: 8 }, children: ">" })
|
|
1743
1660
|
]
|
|
1744
1661
|
}
|
|
1745
1662
|
);
|
|
1746
1663
|
if (hasPress) {
|
|
1747
|
-
return /* @__PURE__ */
|
|
1664
|
+
return /* @__PURE__ */ jsx5(
|
|
1748
1665
|
Pressable2,
|
|
1749
1666
|
{
|
|
1750
1667
|
onPress: () => emit("press"),
|
|
@@ -1760,14 +1677,14 @@ function ListItemComponent({ element, emit }) {
|
|
|
1760
1677
|
}
|
|
1761
1678
|
function ModalComponent({ element, children }) {
|
|
1762
1679
|
const p = element.props;
|
|
1763
|
-
return /* @__PURE__ */
|
|
1680
|
+
return /* @__PURE__ */ jsx5(
|
|
1764
1681
|
RNModal,
|
|
1765
1682
|
{
|
|
1766
1683
|
visible: p.visible,
|
|
1767
1684
|
animationType: p.animationType ?? "slide",
|
|
1768
1685
|
transparent: true,
|
|
1769
|
-
children: /* @__PURE__ */
|
|
1770
|
-
p.title && /* @__PURE__ */
|
|
1686
|
+
children: /* @__PURE__ */ jsx5(View2, { style: modalStyles.overlay, children: /* @__PURE__ */ jsxs2(View2, { style: modalStyles.content, children: [
|
|
1687
|
+
p.title && /* @__PURE__ */ jsx5(Text2, { style: modalStyles.title, children: p.title }),
|
|
1771
1688
|
children
|
|
1772
1689
|
] }) })
|
|
1773
1690
|
}
|
|
@@ -1890,8 +1807,8 @@ var modalStyles = StyleSheet2.create({
|
|
|
1890
1807
|
});
|
|
1891
1808
|
|
|
1892
1809
|
// src/renderer.tsx
|
|
1893
|
-
import { Fragment, jsx as
|
|
1894
|
-
var ElementErrorBoundary = class extends
|
|
1810
|
+
import { Fragment, jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1811
|
+
var ElementErrorBoundary = class extends React5.Component {
|
|
1895
1812
|
constructor(props) {
|
|
1896
1813
|
super(props);
|
|
1897
1814
|
this.state = { hasError: false };
|
|
@@ -1913,7 +1830,7 @@ var ElementErrorBoundary = class extends React6.Component {
|
|
|
1913
1830
|
return this.props.children;
|
|
1914
1831
|
}
|
|
1915
1832
|
};
|
|
1916
|
-
var ElementRenderer =
|
|
1833
|
+
var ElementRenderer = React5.memo(function ElementRenderer2({
|
|
1917
1834
|
element,
|
|
1918
1835
|
spec,
|
|
1919
1836
|
registry,
|
|
@@ -1923,7 +1840,8 @@ var ElementRenderer = React6.memo(function ElementRenderer2({
|
|
|
1923
1840
|
const repeatScope = useRepeatScope();
|
|
1924
1841
|
const { ctx } = useVisibility();
|
|
1925
1842
|
const { execute } = useActions();
|
|
1926
|
-
const
|
|
1843
|
+
const { getSnapshot } = useStateStore();
|
|
1844
|
+
const fullCtx = useMemo4(
|
|
1927
1845
|
() => repeatScope ? {
|
|
1928
1846
|
...ctx,
|
|
1929
1847
|
repeatItem: repeatScope.item,
|
|
@@ -1934,24 +1852,28 @@ var ElementRenderer = React6.memo(function ElementRenderer2({
|
|
|
1934
1852
|
);
|
|
1935
1853
|
const isVisible = element.visible === void 0 ? true : evaluateVisibility2(element.visible, fullCtx);
|
|
1936
1854
|
const onBindings = element.on;
|
|
1937
|
-
const emit =
|
|
1938
|
-
(eventName) => {
|
|
1855
|
+
const emit = useCallback4(
|
|
1856
|
+
async (eventName) => {
|
|
1939
1857
|
const binding = onBindings?.[eventName];
|
|
1940
1858
|
if (!binding) return;
|
|
1941
1859
|
const actionBindings = Array.isArray(binding) ? binding : [binding];
|
|
1942
1860
|
for (const b of actionBindings) {
|
|
1943
1861
|
if (!b.params) {
|
|
1944
|
-
execute(b);
|
|
1862
|
+
await execute(b);
|
|
1945
1863
|
continue;
|
|
1946
1864
|
}
|
|
1865
|
+
const liveCtx = {
|
|
1866
|
+
...fullCtx,
|
|
1867
|
+
stateModel: getSnapshot()
|
|
1868
|
+
};
|
|
1947
1869
|
const resolved = {};
|
|
1948
1870
|
for (const [key, val] of Object.entries(b.params)) {
|
|
1949
|
-
resolved[key] = resolveActionParam(val,
|
|
1871
|
+
resolved[key] = resolveActionParam(val, liveCtx);
|
|
1950
1872
|
}
|
|
1951
|
-
execute({ ...b, params: resolved });
|
|
1873
|
+
await execute({ ...b, params: resolved });
|
|
1952
1874
|
}
|
|
1953
1875
|
},
|
|
1954
|
-
[onBindings, execute, fullCtx]
|
|
1876
|
+
[onBindings, execute, fullCtx, getSnapshot]
|
|
1955
1877
|
);
|
|
1956
1878
|
if (!isVisible) {
|
|
1957
1879
|
return null;
|
|
@@ -1965,7 +1887,7 @@ var ElementRenderer = React6.memo(function ElementRenderer2({
|
|
|
1965
1887
|
console.warn(`No renderer for component type: ${resolvedElement.type}`);
|
|
1966
1888
|
return null;
|
|
1967
1889
|
}
|
|
1968
|
-
const children = resolvedElement.repeat ? /* @__PURE__ */
|
|
1890
|
+
const children = resolvedElement.repeat ? /* @__PURE__ */ jsx6(
|
|
1969
1891
|
RepeatChildren,
|
|
1970
1892
|
{
|
|
1971
1893
|
element: resolvedElement,
|
|
@@ -1984,7 +1906,7 @@ var ElementRenderer = React6.memo(function ElementRenderer2({
|
|
|
1984
1906
|
}
|
|
1985
1907
|
return null;
|
|
1986
1908
|
}
|
|
1987
|
-
return /* @__PURE__ */
|
|
1909
|
+
return /* @__PURE__ */ jsx6(
|
|
1988
1910
|
ElementRenderer2,
|
|
1989
1911
|
{
|
|
1990
1912
|
element: childElement,
|
|
@@ -1996,7 +1918,7 @@ var ElementRenderer = React6.memo(function ElementRenderer2({
|
|
|
1996
1918
|
childKey
|
|
1997
1919
|
);
|
|
1998
1920
|
});
|
|
1999
|
-
return /* @__PURE__ */
|
|
1921
|
+
return /* @__PURE__ */ jsx6(ElementErrorBoundary, { elementType: resolvedElement.type, children: /* @__PURE__ */ jsx6(
|
|
2000
1922
|
Component,
|
|
2001
1923
|
{
|
|
2002
1924
|
element: resolvedElement,
|
|
@@ -2017,12 +1939,12 @@ function RepeatChildren({
|
|
|
2017
1939
|
const { state } = useStateStore();
|
|
2018
1940
|
const repeat = element.repeat;
|
|
2019
1941
|
const statePath = repeat.statePath;
|
|
2020
|
-
const items =
|
|
2021
|
-
return /* @__PURE__ */
|
|
1942
|
+
const items = getByPath2(state, statePath) ?? [];
|
|
1943
|
+
return /* @__PURE__ */ jsx6(Fragment, { children: items.map((itemValue, index) => {
|
|
2022
1944
|
const key = repeat.key && typeof itemValue === "object" && itemValue !== null ? String(
|
|
2023
1945
|
itemValue[repeat.key] ?? index
|
|
2024
1946
|
) : String(index);
|
|
2025
|
-
return /* @__PURE__ */
|
|
1947
|
+
return /* @__PURE__ */ jsx6(
|
|
2026
1948
|
RepeatScopeProvider,
|
|
2027
1949
|
{
|
|
2028
1950
|
item: itemValue,
|
|
@@ -2038,7 +1960,7 @@ function RepeatChildren({
|
|
|
2038
1960
|
}
|
|
2039
1961
|
return null;
|
|
2040
1962
|
}
|
|
2041
|
-
return /* @__PURE__ */
|
|
1963
|
+
return /* @__PURE__ */ jsx6(
|
|
2042
1964
|
ElementRenderer,
|
|
2043
1965
|
{
|
|
2044
1966
|
element: childElement,
|
|
@@ -2062,7 +1984,7 @@ function Renderer({
|
|
|
2062
1984
|
loading,
|
|
2063
1985
|
fallback
|
|
2064
1986
|
}) {
|
|
2065
|
-
const registry =
|
|
1987
|
+
const registry = useMemo4(
|
|
2066
1988
|
() => ({
|
|
2067
1989
|
...includeStandard ? standardComponents : {},
|
|
2068
1990
|
...customRegistry
|
|
@@ -2076,7 +1998,7 @@ function Renderer({
|
|
|
2076
1998
|
if (!rootElement) {
|
|
2077
1999
|
return null;
|
|
2078
2000
|
}
|
|
2079
|
-
return /* @__PURE__ */
|
|
2001
|
+
return /* @__PURE__ */ jsx6(
|
|
2080
2002
|
ElementRenderer,
|
|
2081
2003
|
{
|
|
2082
2004
|
element: rootElement,
|
|
@@ -2089,6 +2011,7 @@ function Renderer({
|
|
|
2089
2011
|
}
|
|
2090
2012
|
function JSONUIProvider({
|
|
2091
2013
|
registry,
|
|
2014
|
+
store,
|
|
2092
2015
|
initialState,
|
|
2093
2016
|
handlers,
|
|
2094
2017
|
navigate,
|
|
@@ -2096,17 +2019,25 @@ function JSONUIProvider({
|
|
|
2096
2019
|
onStateChange,
|
|
2097
2020
|
children
|
|
2098
2021
|
}) {
|
|
2099
|
-
return /* @__PURE__ */
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2022
|
+
return /* @__PURE__ */ jsx6(
|
|
2023
|
+
StateProvider,
|
|
2024
|
+
{
|
|
2025
|
+
store,
|
|
2026
|
+
initialState,
|
|
2027
|
+
onStateChange,
|
|
2028
|
+
children: /* @__PURE__ */ jsx6(VisibilityProvider, { children: /* @__PURE__ */ jsx6(ActionProvider, { handlers, navigate, children: /* @__PURE__ */ jsxs3(ValidationProvider, { customFunctions: validationFunctions, children: [
|
|
2029
|
+
children,
|
|
2030
|
+
/* @__PURE__ */ jsx6(ConfirmationDialogManager, {})
|
|
2031
|
+
] }) }) })
|
|
2032
|
+
}
|
|
2033
|
+
);
|
|
2103
2034
|
}
|
|
2104
2035
|
function ConfirmationDialogManager() {
|
|
2105
2036
|
const { pendingConfirmation, confirm, cancel } = useActions();
|
|
2106
2037
|
if (!pendingConfirmation?.action.confirm) {
|
|
2107
2038
|
return null;
|
|
2108
2039
|
}
|
|
2109
|
-
return /* @__PURE__ */
|
|
2040
|
+
return /* @__PURE__ */ jsx6(
|
|
2110
2041
|
ConfirmDialog,
|
|
2111
2042
|
{
|
|
2112
2043
|
confirm: pendingConfirmation.action.confirm,
|
|
@@ -2164,6 +2095,7 @@ function createRenderer(catalog, components) {
|
|
|
2164
2095
|
const registry = components;
|
|
2165
2096
|
return function CatalogRenderer({
|
|
2166
2097
|
spec,
|
|
2098
|
+
store,
|
|
2167
2099
|
state,
|
|
2168
2100
|
onAction,
|
|
2169
2101
|
onStateChange,
|
|
@@ -2179,18 +2111,26 @@ function createRenderer(catalog, components) {
|
|
|
2179
2111
|
has: () => true
|
|
2180
2112
|
}
|
|
2181
2113
|
) : void 0;
|
|
2182
|
-
return /* @__PURE__ */
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2114
|
+
return /* @__PURE__ */ jsx6(
|
|
2115
|
+
StateProvider,
|
|
2116
|
+
{
|
|
2117
|
+
store,
|
|
2118
|
+
initialState: state,
|
|
2119
|
+
onStateChange,
|
|
2120
|
+
children: /* @__PURE__ */ jsx6(VisibilityProvider, { children: /* @__PURE__ */ jsx6(ActionProvider, { handlers: actionHandlers, children: /* @__PURE__ */ jsxs3(ValidationProvider, { children: [
|
|
2121
|
+
/* @__PURE__ */ jsx6(
|
|
2122
|
+
Renderer,
|
|
2123
|
+
{
|
|
2124
|
+
spec,
|
|
2125
|
+
registry,
|
|
2126
|
+
loading,
|
|
2127
|
+
fallback
|
|
2128
|
+
}
|
|
2129
|
+
),
|
|
2130
|
+
/* @__PURE__ */ jsx6(ConfirmationDialogManager, {})
|
|
2131
|
+
] }) }) })
|
|
2132
|
+
}
|
|
2133
|
+
);
|
|
2194
2134
|
};
|
|
2195
2135
|
}
|
|
2196
2136
|
export {
|
|
@@ -2204,6 +2144,7 @@ export {
|
|
|
2204
2144
|
VisibilityProvider,
|
|
2205
2145
|
createRenderer,
|
|
2206
2146
|
createStandardActionHandlers,
|
|
2147
|
+
createStateStore,
|
|
2207
2148
|
defineRegistry,
|
|
2208
2149
|
elementTreeSchema,
|
|
2209
2150
|
flatToTree,
|