@pushframe/sdk 0.1.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 ADDED
@@ -0,0 +1,788 @@
1
+ 'use strict';
2
+
3
+ var React4 = require('react');
4
+ var reactNative = require('react-native');
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+
7
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
+
9
+ var React4__default = /*#__PURE__*/_interopDefault(React4);
10
+
11
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
12
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
13
+ }) : x)(function(x) {
14
+ if (typeof require !== "undefined") return require.apply(this, arguments);
15
+ throw Error('Dynamic require of "' + x + '" is not supported');
16
+ });
17
+ var PushFrameContext = React4.createContext(null);
18
+ function usePushFrameContext() {
19
+ const ctx = React4.useContext(PushFrameContext);
20
+ if (!ctx) {
21
+ throw new Error("[PushFrame] usePushFrameContext must be called inside <PushFrame.Provider>");
22
+ }
23
+ return ctx;
24
+ }
25
+ function Text({ if: _if, actions: _actions, value, children, ...rest }) {
26
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { ...rest, children: value !== void 0 ? value : children });
27
+ }
28
+ function View({ if: _if, actions: _actions, ...rest }) {
29
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { ...rest });
30
+ }
31
+ var ScrollView = React4.forwardRef(function ScrollView2({ if: _if, actions: _actions, ...rest }, ref) {
32
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.ScrollView, { ref, ...rest });
33
+ });
34
+ function Image({ if: _if, actions: _actions, src, source, ...rest }) {
35
+ const resolvedSource = src ? { uri: src } : source ?? { uri: "" };
36
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Image, { source: resolvedSource, ...rest });
37
+ }
38
+ function Pressable({ if: _if, actions: _actions, ...rest }) {
39
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Pressable, { ...rest });
40
+ }
41
+ function TextInput({
42
+ if: _if,
43
+ actions: _actions,
44
+ onChange,
45
+ onSubmit,
46
+ ...rest
47
+ }) {
48
+ return /* @__PURE__ */ jsxRuntime.jsx(
49
+ reactNative.TextInput,
50
+ {
51
+ onChangeText: onChange,
52
+ onSubmitEditing: onSubmit ? () => onSubmit() : void 0,
53
+ ...rest
54
+ }
55
+ );
56
+ }
57
+ function FlatList({
58
+ if: _if,
59
+ actions: _actions,
60
+ items,
61
+ direction,
62
+ numColumns,
63
+ ...rest
64
+ }) {
65
+ return /* @__PURE__ */ jsxRuntime.jsx(
66
+ reactNative.FlatList,
67
+ {
68
+ data: items,
69
+ horizontal: direction === "horizontal",
70
+ numColumns,
71
+ ...rest
72
+ }
73
+ );
74
+ }
75
+ function Modal({ if: _if, actions: _actions, ...rest }) {
76
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Modal, { ...rest });
77
+ }
78
+ function ActivityIndicator({
79
+ if: _if,
80
+ actions: _actions,
81
+ ...rest
82
+ }) {
83
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.ActivityIndicator, { ...rest });
84
+ }
85
+ function Switch({ if: _if, actions: _actions, onChange, ...rest }) {
86
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Switch, { onValueChange: onChange, ...rest });
87
+ }
88
+ function KeyboardAvoidingView({
89
+ if: _if,
90
+ actions: _actions,
91
+ ...rest
92
+ }) {
93
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.KeyboardAvoidingView, { ...rest });
94
+ }
95
+ var NativeSafeAreaView;
96
+ try {
97
+ NativeSafeAreaView = __require("react-native-safe-area-context").SafeAreaView;
98
+ } catch {
99
+ NativeSafeAreaView = __require("react-native").SafeAreaView;
100
+ }
101
+ function SafeAreaView({ if: _if, actions: _actions, ...rest }) {
102
+ return /* @__PURE__ */ jsxRuntime.jsx(NativeSafeAreaView, { ...rest });
103
+ }
104
+ function StatusBar({ if: _if, actions: _actions, ...rest }) {
105
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.StatusBar, { ...rest });
106
+ }
107
+
108
+ // src/registry/ComponentRegistry.ts
109
+ var BUILT_IN_TYPES = /* @__PURE__ */ new Set([
110
+ "text",
111
+ "view",
112
+ "scrollview",
113
+ "image",
114
+ "pressable",
115
+ "textinput",
116
+ "flatlist",
117
+ "modal",
118
+ "activityindicator",
119
+ "switch",
120
+ "keyboardavoidingview",
121
+ "safeareaview",
122
+ "statusbar"
123
+ ]);
124
+ var BUILT_IN_COMPONENTS = /* @__PURE__ */ new Map([
125
+ ["text", Text],
126
+ ["view", View],
127
+ ["scrollview", ScrollView],
128
+ ["image", Image],
129
+ ["pressable", Pressable],
130
+ ["textinput", TextInput],
131
+ ["flatlist", FlatList],
132
+ ["modal", Modal],
133
+ ["activityindicator", ActivityIndicator],
134
+ ["switch", Switch],
135
+ ["keyboardavoidingview", KeyboardAvoidingView],
136
+ ["safeareaview", SafeAreaView],
137
+ ["statusbar", StatusBar]
138
+ ]);
139
+ var ComponentRegistry = class {
140
+ constructor(developerComponents) {
141
+ this.components = new Map(BUILT_IN_COMPONENTS);
142
+ if (developerComponents) {
143
+ for (const [type, component] of Object.entries(developerComponents)) {
144
+ if (BUILT_IN_TYPES.has(type)) {
145
+ console.warn(
146
+ `[PushFrame] ComponentRegistry: "${type}" is a built-in type and cannot be overridden. Registration skipped.`
147
+ );
148
+ continue;
149
+ }
150
+ this.components.set(type, component);
151
+ }
152
+ }
153
+ }
154
+ /**
155
+ * Resolve a type string to its React component.
156
+ * Returns null if no component is registered for the type.
157
+ */
158
+ resolve(type) {
159
+ return this.components.get(type) ?? null;
160
+ }
161
+ /**
162
+ * Returns all registered type strings (useful for debugging).
163
+ */
164
+ types() {
165
+ return Array.from(this.components.keys());
166
+ }
167
+ };
168
+ var TYPE_COLORS = {
169
+ success: "#22c55e",
170
+ error: "#ef4444",
171
+ info: "#3b82f6",
172
+ warning: "#f59e0b"
173
+ };
174
+ var ToastHost = React4.forwardRef(function ToastHost2(_props, ref) {
175
+ const [toast, setToast] = React4.useState(null);
176
+ const opacity = React4.useRef(new reactNative.Animated.Value(0)).current;
177
+ const idRef = React4.useRef(0);
178
+ const hide = React4.useCallback(() => {
179
+ reactNative.Animated.timing(opacity, {
180
+ toValue: 0,
181
+ duration: 200,
182
+ useNativeDriver: true
183
+ }).start(() => {
184
+ setToast(null);
185
+ });
186
+ }, [opacity]);
187
+ React4.useEffect(() => {
188
+ if (!toast) return;
189
+ reactNative.Animated.timing(opacity, {
190
+ toValue: 1,
191
+ duration: 200,
192
+ useNativeDriver: true
193
+ }).start();
194
+ const timer = setTimeout(() => {
195
+ hide();
196
+ }, toast.duration);
197
+ return () => {
198
+ clearTimeout(timer);
199
+ };
200
+ }, [toast, opacity, hide]);
201
+ React4.useImperativeHandle(
202
+ ref,
203
+ () => ({
204
+ show(payload) {
205
+ idRef.current += 1;
206
+ setToast({
207
+ id: idRef.current,
208
+ message: payload.message,
209
+ duration: payload.duration ?? 3e3,
210
+ type: payload.type ?? "info"
211
+ });
212
+ opacity.setValue(0);
213
+ }
214
+ }),
215
+ [opacity]
216
+ );
217
+ if (!toast) return null;
218
+ const backgroundColor = TYPE_COLORS[toast.type ?? "info"] ?? TYPE_COLORS.info;
219
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles.container, pointerEvents: "none", children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Animated.View, { style: [styles.toast, { backgroundColor, opacity }], children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: styles.message, children: toast.message }) }) });
220
+ });
221
+ var styles = reactNative.StyleSheet.create({
222
+ container: {
223
+ position: "absolute",
224
+ bottom: 60,
225
+ left: 16,
226
+ right: 16,
227
+ alignItems: "center",
228
+ zIndex: 9999
229
+ },
230
+ toast: {
231
+ paddingVertical: 12,
232
+ paddingHorizontal: 20,
233
+ borderRadius: 8,
234
+ maxWidth: 400,
235
+ shadowColor: "#000",
236
+ shadowOffset: { width: 0, height: 2 },
237
+ shadowOpacity: 0.2,
238
+ shadowRadius: 4,
239
+ elevation: 6
240
+ },
241
+ message: {
242
+ color: "#fff",
243
+ fontSize: 14,
244
+ fontWeight: "500",
245
+ textAlign: "center"
246
+ }
247
+ });
248
+ var SCREEN_HEIGHT = reactNative.Dimensions.get("window").height;
249
+ var BottomSheetHost = React4.forwardRef(
250
+ function BottomSheetHost2({ renderContent }, ref) {
251
+ const [visible, setVisible] = React4.useState(false);
252
+ const [payload, setPayload] = React4.useState(null);
253
+ const translateY = React4.useRef(new reactNative.Animated.Value(SCREEN_HEIGHT)).current;
254
+ const animateIn = React4.useCallback(() => {
255
+ reactNative.Animated.spring(translateY, {
256
+ toValue: 0,
257
+ useNativeDriver: true,
258
+ bounciness: 4
259
+ }).start();
260
+ }, [translateY]);
261
+ const animateOut = React4.useCallback(
262
+ (onDone) => {
263
+ reactNative.Animated.timing(translateY, {
264
+ toValue: SCREEN_HEIGHT,
265
+ duration: 250,
266
+ useNativeDriver: true
267
+ }).start(() => {
268
+ onDone?.();
269
+ });
270
+ },
271
+ [translateY]
272
+ );
273
+ React4.useEffect(() => {
274
+ if (visible) {
275
+ translateY.setValue(SCREEN_HEIGHT);
276
+ animateIn();
277
+ }
278
+ }, [visible, translateY, animateIn]);
279
+ const dismiss = React4.useCallback(() => {
280
+ animateOut(() => {
281
+ setVisible(false);
282
+ setPayload(null);
283
+ });
284
+ }, [animateOut]);
285
+ React4.useImperativeHandle(
286
+ ref,
287
+ () => ({
288
+ show(p) {
289
+ setPayload(p);
290
+ setVisible(true);
291
+ },
292
+ dismiss() {
293
+ dismiss();
294
+ }
295
+ }),
296
+ [dismiss]
297
+ );
298
+ if (!visible || !payload) return null;
299
+ return /* @__PURE__ */ jsxRuntime.jsxs(
300
+ reactNative.Modal,
301
+ {
302
+ visible,
303
+ transparent: true,
304
+ animationType: "none",
305
+ onRequestClose: dismiss,
306
+ statusBarTranslucent: true,
307
+ children: [
308
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Pressable, { style: styles2.backdrop, onPress: dismiss }),
309
+ /* @__PURE__ */ jsxRuntime.jsxs(reactNative.Animated.View, { style: [styles2.sheet, { transform: [{ translateY }] }], children: [
310
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles2.handle }),
311
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles2.content, children: renderContent(payload.schema, payload.context) })
312
+ ] })
313
+ ]
314
+ }
315
+ );
316
+ }
317
+ );
318
+ var styles2 = reactNative.StyleSheet.create({
319
+ backdrop: {
320
+ ...reactNative.StyleSheet.absoluteFillObject,
321
+ backgroundColor: "rgba(0,0,0,0.5)"
322
+ },
323
+ sheet: {
324
+ position: "absolute",
325
+ bottom: 0,
326
+ left: 0,
327
+ right: 0,
328
+ backgroundColor: "#fff",
329
+ borderTopLeftRadius: 16,
330
+ borderTopRightRadius: 16,
331
+ paddingBottom: 34,
332
+ // safe-area approximation
333
+ minHeight: 200,
334
+ maxHeight: "80%",
335
+ shadowColor: "#000",
336
+ shadowOffset: { width: 0, height: -4 },
337
+ shadowOpacity: 0.15,
338
+ shadowRadius: 12,
339
+ elevation: 20
340
+ },
341
+ handle: {
342
+ alignSelf: "center",
343
+ width: 36,
344
+ height: 4,
345
+ borderRadius: 2,
346
+ backgroundColor: "#d1d5db",
347
+ marginTop: 12,
348
+ marginBottom: 8
349
+ },
350
+ content: {
351
+ flex: 1,
352
+ paddingHorizontal: 16,
353
+ paddingTop: 8
354
+ }
355
+ });
356
+
357
+ // src/renderer/bindingResolver.ts
358
+ var FULL_BINDING_RE = /^\{\{(.+)\}\}$/;
359
+ var INLINE_BINDING_RE = /\{\{([^}]+)\}\}/g;
360
+ function evaluateExpression(expr, context) {
361
+ try {
362
+ const keys = Object.keys(context);
363
+ const values = keys.map((k) => context[k]);
364
+ const fn = new Function(...keys, `"use strict"; try { return (${expr}); } catch(e) { return undefined; }`);
365
+ return fn(...values);
366
+ } catch {
367
+ return void 0;
368
+ }
369
+ }
370
+ function resolveValue(value, context) {
371
+ if (typeof value !== "string") {
372
+ return value;
373
+ }
374
+ const fullMatch = FULL_BINDING_RE.exec(value);
375
+ if (fullMatch?.[1] !== void 0) {
376
+ return evaluateExpression(fullMatch[1].trim(), context);
377
+ }
378
+ if (INLINE_BINDING_RE.test(value)) {
379
+ INLINE_BINDING_RE.lastIndex = 0;
380
+ return value.replace(INLINE_BINDING_RE, (_, expr) => {
381
+ const resolved = evaluateExpression(expr.trim(), context);
382
+ return resolved !== void 0 && resolved !== null ? String(resolved) : "";
383
+ });
384
+ }
385
+ return value;
386
+ }
387
+ function resolveProps(props, context) {
388
+ if (!props) return {};
389
+ const resolved = {};
390
+ for (const [key, value] of Object.entries(props)) {
391
+ resolved[key] = resolveDeep(value, context);
392
+ }
393
+ return resolved;
394
+ }
395
+ function resolveDeep(value, context) {
396
+ if (Array.isArray(value)) {
397
+ return value.map((item) => resolveDeep(item, context));
398
+ }
399
+ if (typeof value === "object" && value !== null) {
400
+ const result = {};
401
+ for (const [k, v] of Object.entries(value)) {
402
+ result[k] = resolveDeep(v, context);
403
+ }
404
+ return result;
405
+ }
406
+ return resolveValue(value, context);
407
+ }
408
+
409
+ // src/renderer/conditionalEvaluator.ts
410
+ function evaluateIf(ifExpr, context) {
411
+ if (ifExpr === void 0) return true;
412
+ const resolved = resolveValue(ifExpr, context);
413
+ return Boolean(resolved);
414
+ }
415
+ function buildActionProps(actions, context, dispatchAction) {
416
+ const grouped = /* @__PURE__ */ new Map();
417
+ for (const action of actions) {
418
+ const existing = grouped.get(action.trigger);
419
+ if (existing) {
420
+ existing.push(action);
421
+ } else {
422
+ grouped.set(action.trigger, [action]);
423
+ }
424
+ }
425
+ const result = {};
426
+ for (const [trigger, triggerActions] of grouped) {
427
+ result[trigger] = (..._args) => {
428
+ for (const action of triggerActions) {
429
+ const resolvedPayload = action.payload !== void 0 ? resolveDeep(action.payload, context) : void 0;
430
+ dispatchAction(action.action, resolvedPayload);
431
+ }
432
+ };
433
+ }
434
+ return result;
435
+ }
436
+ function renderFlatListNode(node, context, registry, dispatchAction, fallbackComponent) {
437
+ const resolvedProps = resolveProps(node.props, context);
438
+ const items = Array.isArray(resolvedProps["items"]) ? resolvedProps["items"] : [];
439
+ const actionProps = node.actions ? buildActionProps(node.actions, context, dispatchAction) : {};
440
+ const { items: _items, keyExtractor: keyExtractorExpr, direction, numColumns, ...restProps } = resolvedProps;
441
+ let keyExtractorFn;
442
+ if (typeof keyExtractorExpr === "string") {
443
+ const extractorExpr = keyExtractorExpr;
444
+ keyExtractorFn = (item, index) => {
445
+ const itemContext = { ...context, item, index };
446
+ const resolved = resolveValue(extractorExpr, itemContext);
447
+ return resolved !== void 0 && resolved !== null ? String(resolved) : String(index);
448
+ };
449
+ }
450
+ const renderItemFn = ({ item, index }) => {
451
+ const itemContext = { ...context, item, index };
452
+ return /* @__PURE__ */ jsxRuntime.jsx(
453
+ RecursiveRenderer,
454
+ {
455
+ node: node.renderItem,
456
+ context: itemContext,
457
+ registry,
458
+ dispatchAction,
459
+ fallbackComponent
460
+ },
461
+ keyExtractorFn ? keyExtractorFn(item, index) : index
462
+ );
463
+ };
464
+ const FlatListComponent = registry.resolve("flatlist");
465
+ if (!FlatListComponent) {
466
+ console.warn('[PushFrame] RecursiveRenderer: "flatlist" not found in registry.');
467
+ return fallbackComponent ? fallbackComponent : null;
468
+ }
469
+ return React4__default.default.createElement(FlatListComponent, {
470
+ ...restProps,
471
+ ...actionProps,
472
+ items,
473
+ direction,
474
+ numColumns,
475
+ keyExtractor: keyExtractorFn,
476
+ renderItem: renderItemFn
477
+ });
478
+ }
479
+ function RecursiveRenderer({
480
+ node,
481
+ context,
482
+ registry,
483
+ dispatchAction,
484
+ fallbackComponent
485
+ }) {
486
+ if (!evaluateIf(node.if, context)) {
487
+ return null;
488
+ }
489
+ if (node.type === "flatlist") {
490
+ return renderFlatListNode(
491
+ node,
492
+ context,
493
+ registry,
494
+ dispatchAction,
495
+ fallbackComponent
496
+ );
497
+ }
498
+ const resolvedProps = resolveProps(node.props, context);
499
+ const actionProps = node.actions ? buildActionProps(node.actions, context, dispatchAction) : {};
500
+ const Component = registry.resolve(node.type);
501
+ if (!Component) {
502
+ console.warn(
503
+ `[PushFrame] RecursiveRenderer: Unknown component type "${node.type}". Registered types: ${registry.types().join(", ")}`
504
+ );
505
+ return fallbackComponent ? fallbackComponent : null;
506
+ }
507
+ const children = node.children && node.children.length > 0 ? node.children.map((child, index) => /* @__PURE__ */ jsxRuntime.jsx(
508
+ RecursiveRenderer,
509
+ {
510
+ node: child,
511
+ context,
512
+ registry,
513
+ dispatchAction,
514
+ fallbackComponent
515
+ },
516
+ `${child.type}-${index}`
517
+ )) : void 0;
518
+ return React4__default.default.createElement(Component, {
519
+ ...resolvedProps,
520
+ ...actionProps,
521
+ children
522
+ });
523
+ }
524
+ var DEFAULT_BASE_URL = "https://api.pushframe.io";
525
+ function PushFrameProvider({
526
+ apiKey,
527
+ context = {},
528
+ baseUrl = DEFAULT_BASE_URL,
529
+ appVersion,
530
+ components,
531
+ loadingComponent,
532
+ fallbackComponent,
533
+ onAction,
534
+ onError,
535
+ children
536
+ }) {
537
+ const registry = React4.useMemo(
538
+ () => new ComponentRegistry(components),
539
+ // eslint-disable-next-line react-hooks/exhaustive-deps
540
+ []
541
+ );
542
+ const toastRef = React4.useRef(null);
543
+ const bottomSheetRef = React4.useRef(null);
544
+ const showToast = React4.useCallback((payload) => {
545
+ toastRef.current?.show(payload);
546
+ }, []);
547
+ const showBottomSheet = React4.useCallback((payload) => {
548
+ bottomSheetRef.current?.show(payload);
549
+ }, []);
550
+ const dismissBottomSheet = React4.useCallback(() => {
551
+ bottomSheetRef.current?.dismiss();
552
+ }, []);
553
+ const renderBottomSheetContent = React4.useCallback(
554
+ (schema, sheetContext) => {
555
+ const mergedContext = sheetContext ? { ...context, ...sheetContext } : context;
556
+ const dispatchAction = (action, payload) => {
557
+ if (action === "dismiss-bottom-sheet") {
558
+ dismissBottomSheet();
559
+ return;
560
+ }
561
+ if (action === "show-toast") {
562
+ showToast(payload);
563
+ return;
564
+ }
565
+ onAction?.(action, payload);
566
+ };
567
+ return /* @__PURE__ */ jsxRuntime.jsx(
568
+ RecursiveRenderer,
569
+ {
570
+ node: schema,
571
+ context: mergedContext,
572
+ registry,
573
+ dispatchAction,
574
+ fallbackComponent
575
+ }
576
+ );
577
+ },
578
+ [context, registry, fallbackComponent, onAction, dismissBottomSheet, showToast]
579
+ );
580
+ const contextValue = React4.useMemo(
581
+ () => ({
582
+ apiKey,
583
+ baseUrl,
584
+ appVersion,
585
+ globalContext: context,
586
+ registry,
587
+ loadingComponent,
588
+ fallbackComponent,
589
+ onAction,
590
+ onError,
591
+ showToast,
592
+ showBottomSheet,
593
+ dismissBottomSheet
594
+ }),
595
+ [
596
+ apiKey,
597
+ baseUrl,
598
+ appVersion,
599
+ context,
600
+ registry,
601
+ loadingComponent,
602
+ fallbackComponent,
603
+ onAction,
604
+ onError,
605
+ showToast,
606
+ showBottomSheet,
607
+ dismissBottomSheet
608
+ ]
609
+ );
610
+ return /* @__PURE__ */ jsxRuntime.jsxs(PushFrameContext.Provider, { value: contextValue, children: [
611
+ children,
612
+ /* @__PURE__ */ jsxRuntime.jsx(ToastHost, { ref: toastRef }),
613
+ /* @__PURE__ */ jsxRuntime.jsx(BottomSheetHost, { ref: bottomSheetRef, renderContent: renderBottomSheetContent })
614
+ ] });
615
+ }
616
+ async function fetchSchema(baseUrl, apiKey, path) {
617
+ const url = new URL(path, baseUrl + "/").toString();
618
+ const headers = {
619
+ Accept: "application/json",
620
+ Authorization: `Bearer ${apiKey}`,
621
+ "x-project-key": apiKey
622
+ };
623
+ const res = await fetch(url, { headers });
624
+ if (!res.ok) {
625
+ throw new Error(`[PushFrame] HTTP ${res.status} fetching "${path}"`);
626
+ }
627
+ const envelope = await res.json();
628
+ return envelope.schema ?? envelope;
629
+ }
630
+ function PushFrameComponentInternal({
631
+ id,
632
+ resourceType,
633
+ context: slotContext,
634
+ isLoading: externalLoading,
635
+ loadingComponent: slotLoading,
636
+ fallbackComponent: slotFallback,
637
+ onAction: slotOnAction,
638
+ fullscreen
639
+ }) {
640
+ const {
641
+ apiKey,
642
+ baseUrl,
643
+ appVersion,
644
+ globalContext,
645
+ registry,
646
+ loadingComponent: providerLoading,
647
+ fallbackComponent: providerFallback,
648
+ onAction: providerOnAction,
649
+ onError,
650
+ showToast,
651
+ showBottomSheet,
652
+ dismissBottomSheet
653
+ } = usePushFrameContext();
654
+ const [schema, setSchema] = React4.useState(null);
655
+ const [fetchError, setFetchError] = React4.useState(null);
656
+ const [isFetching, setIsFetching] = React4.useState(true);
657
+ const fetchPath = `${resourceType}/${encodeURIComponent(id)}/${encodeURIComponent(appVersion ?? "null")}`;
658
+ const mergedContext = slotContext ? { ...globalContext, ...slotContext } : globalContext;
659
+ const loadingUI = slotLoading !== void 0 ? slotLoading : providerLoading;
660
+ const fallbackUI = slotFallback !== void 0 ? slotFallback : providerFallback;
661
+ React4.useEffect(() => {
662
+ let cancelled = false;
663
+ setSchema(null);
664
+ setFetchError(null);
665
+ setIsFetching(true);
666
+ fetchSchema(baseUrl, apiKey, fetchPath).then((s) => {
667
+ if (!cancelled) {
668
+ setSchema(s);
669
+ setIsFetching(false);
670
+ }
671
+ }).catch((err) => {
672
+ if (!cancelled) {
673
+ const error = err instanceof Error ? err : new Error(String(err));
674
+ setFetchError(error);
675
+ setIsFetching(false);
676
+ onError?.(error);
677
+ }
678
+ });
679
+ return () => {
680
+ cancelled = true;
681
+ };
682
+ }, [fetchPath, baseUrl, apiKey, onError]);
683
+ const dispatchAction = React4.useCallback(
684
+ (action, payload) => {
685
+ if (action === "show-toast") {
686
+ showToast(payload);
687
+ return;
688
+ }
689
+ if (action === "show-bottom-sheet") {
690
+ showBottomSheet(payload);
691
+ return;
692
+ }
693
+ if (action === "dismiss-bottom-sheet") {
694
+ dismissBottomSheet();
695
+ return;
696
+ }
697
+ if (action === "scroll-to") {
698
+ return;
699
+ }
700
+ const stopped = slotOnAction?.(action, payload);
701
+ if (stopped) return;
702
+ providerOnAction?.(action, payload);
703
+ },
704
+ [showToast, showBottomSheet, dismissBottomSheet, slotOnAction, providerOnAction]
705
+ );
706
+ const isShowingLoader = externalLoading || isFetching;
707
+ if (isShowingLoader) {
708
+ return loadingUI ?? null;
709
+ }
710
+ if (fetchError || !schema) {
711
+ return fallbackUI ?? null;
712
+ }
713
+ const rendered = /* @__PURE__ */ jsxRuntime.jsx(
714
+ RecursiveRenderer,
715
+ {
716
+ node: schema,
717
+ context: mergedContext,
718
+ registry,
719
+ dispatchAction,
720
+ fallbackComponent: fallbackUI
721
+ }
722
+ );
723
+ if (fullscreen) {
724
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: rendered });
725
+ }
726
+ return rendered;
727
+ }
728
+ function PushFrameComponent(props) {
729
+ return /* @__PURE__ */ jsxRuntime.jsx(PushFrameComponentInternal, { ...props, resourceType: "components" });
730
+ }
731
+ function PushFrameScreen(props) {
732
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles3.container, children: /* @__PURE__ */ jsxRuntime.jsx(PushFrameComponentInternal, { ...props, resourceType: "screens", fullscreen: true }) });
733
+ }
734
+ var styles3 = reactNative.StyleSheet.create({
735
+ container: {
736
+ flex: 1
737
+ }
738
+ });
739
+
740
+ // src/index.ts
741
+ var PushFrame = {
742
+ // Slot components
743
+ Provider: PushFrameProvider,
744
+ Screen: PushFrameScreen,
745
+ Component: PushFrameComponent,
746
+ // Primitives
747
+ Text,
748
+ View,
749
+ ScrollView,
750
+ Image,
751
+ Pressable,
752
+ TextInput,
753
+ FlatList,
754
+ Modal,
755
+ ActivityIndicator,
756
+ Switch,
757
+ KeyboardAvoidingView,
758
+ SafeAreaView,
759
+ StatusBar
760
+ };
761
+
762
+ exports.ActivityIndicator = ActivityIndicator;
763
+ exports.ComponentRegistry = ComponentRegistry;
764
+ exports.FlatList = FlatList;
765
+ exports.Image = Image;
766
+ exports.KeyboardAvoidingView = KeyboardAvoidingView;
767
+ exports.Modal = Modal;
768
+ exports.Pressable = Pressable;
769
+ exports.PushFrame = PushFrame;
770
+ exports.PushFrameComponent = PushFrameComponent;
771
+ exports.PushFrameContext = PushFrameContext;
772
+ exports.PushFrameProvider = PushFrameProvider;
773
+ exports.PushFrameScreen = PushFrameScreen;
774
+ exports.RecursiveRenderer = RecursiveRenderer;
775
+ exports.SafeAreaView = SafeAreaView;
776
+ exports.ScrollView = ScrollView;
777
+ exports.StatusBar = StatusBar;
778
+ exports.Switch = Switch;
779
+ exports.Text = Text;
780
+ exports.TextInput = TextInput;
781
+ exports.View = View;
782
+ exports.evaluateIf = evaluateIf;
783
+ exports.resolveDeep = resolveDeep;
784
+ exports.resolveProps = resolveProps;
785
+ exports.resolveValue = resolveValue;
786
+ exports.usePushFrameContext = usePushFrameContext;
787
+ //# sourceMappingURL=index.js.map
788
+ //# sourceMappingURL=index.js.map