@pushframe/sdk 0.1.2 → 0.1.3
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 +58 -43
- package/dist/index.js.map +1 -1
- package/package.json +14 -12
- package/dist/index.d.mts +0 -534
- package/dist/index.mjs +0 -1526
- package/dist/index.mjs.map +0 -1
package/dist/index.mjs
DELETED
|
@@ -1,1526 +0,0 @@
|
|
|
1
|
-
import React4, { createContext, forwardRef, useState, useRef, useCallback, useEffect, useImperativeHandle, useContext, useMemo } from 'react';
|
|
2
|
-
import { ScrollView as ScrollView$1, Animated, View as View$1, Text as Text$1, StyleSheet, Dimensions, Modal as Modal$1, Pressable as Pressable$1, Image as Image$1, TextInput as TextInput$1, FlatList as FlatList$1, ActivityIndicator as ActivityIndicator$1, Switch as Switch$1, KeyboardAvoidingView as KeyboardAvoidingView$1, StatusBar as StatusBar$1 } from 'react-native';
|
|
3
|
-
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
|
-
|
|
5
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
6
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
7
|
-
}) : x)(function(x) {
|
|
8
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
9
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
10
|
-
});
|
|
11
|
-
var PushFrameContext = createContext(null);
|
|
12
|
-
function usePushFrameContext() {
|
|
13
|
-
const ctx = useContext(PushFrameContext);
|
|
14
|
-
if (!ctx) {
|
|
15
|
-
throw new Error("[PushFrame] usePushFrameContext must be called inside <PushFrame.Provider>");
|
|
16
|
-
}
|
|
17
|
-
return ctx;
|
|
18
|
-
}
|
|
19
|
-
function Text({
|
|
20
|
-
if: _if,
|
|
21
|
-
actions: _actions,
|
|
22
|
-
value,
|
|
23
|
-
content,
|
|
24
|
-
...rest
|
|
25
|
-
}) {
|
|
26
|
-
const textContent = value !== void 0 ? value : content;
|
|
27
|
-
if (textContent !== void 0) {
|
|
28
|
-
return /* @__PURE__ */ jsx(Text$1, { ...rest, children: textContent });
|
|
29
|
-
}
|
|
30
|
-
return /* @__PURE__ */ jsx(Text$1, { ...rest });
|
|
31
|
-
}
|
|
32
|
-
function View({ if: _if, actions: _actions, ...rest }) {
|
|
33
|
-
return /* @__PURE__ */ jsx(View$1, { ...rest });
|
|
34
|
-
}
|
|
35
|
-
var ScrollView = forwardRef(function ScrollView2({ if: _if, actions: _actions, ...rest }, ref) {
|
|
36
|
-
return /* @__PURE__ */ jsx(ScrollView$1, { ref, ...rest });
|
|
37
|
-
});
|
|
38
|
-
function Image({ if: _if, actions: _actions, src, source, ...rest }) {
|
|
39
|
-
const resolvedSource = src ? { uri: src } : source ?? { uri: "" };
|
|
40
|
-
return /* @__PURE__ */ jsx(Image$1, { source: resolvedSource, ...rest });
|
|
41
|
-
}
|
|
42
|
-
function Pressable({ if: _if, actions: _actions, ...rest }) {
|
|
43
|
-
return /* @__PURE__ */ jsx(Pressable$1, { ...rest });
|
|
44
|
-
}
|
|
45
|
-
function TextInput({
|
|
46
|
-
if: _if,
|
|
47
|
-
actions: _actions,
|
|
48
|
-
onChange,
|
|
49
|
-
onSubmit,
|
|
50
|
-
...rest
|
|
51
|
-
}) {
|
|
52
|
-
return /* @__PURE__ */ jsx(
|
|
53
|
-
TextInput$1,
|
|
54
|
-
{
|
|
55
|
-
onChangeText: onChange,
|
|
56
|
-
onSubmitEditing: onSubmit ? () => onSubmit() : void 0,
|
|
57
|
-
...rest
|
|
58
|
-
}
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
function FlatList({
|
|
62
|
-
if: _if,
|
|
63
|
-
actions: _actions,
|
|
64
|
-
items,
|
|
65
|
-
direction,
|
|
66
|
-
numColumns,
|
|
67
|
-
...rest
|
|
68
|
-
}) {
|
|
69
|
-
return /* @__PURE__ */ jsx(
|
|
70
|
-
FlatList$1,
|
|
71
|
-
{
|
|
72
|
-
data: items,
|
|
73
|
-
horizontal: direction === "horizontal",
|
|
74
|
-
numColumns,
|
|
75
|
-
...rest
|
|
76
|
-
}
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
function Modal({ if: _if, actions: _actions, ...rest }) {
|
|
80
|
-
return /* @__PURE__ */ jsx(Modal$1, { ...rest });
|
|
81
|
-
}
|
|
82
|
-
function ActivityIndicator({
|
|
83
|
-
if: _if,
|
|
84
|
-
actions: _actions,
|
|
85
|
-
...rest
|
|
86
|
-
}) {
|
|
87
|
-
return /* @__PURE__ */ jsx(ActivityIndicator$1, { ...rest });
|
|
88
|
-
}
|
|
89
|
-
function Switch({ if: _if, actions: _actions, onChange, ...rest }) {
|
|
90
|
-
return /* @__PURE__ */ jsx(Switch$1, { onValueChange: onChange, ...rest });
|
|
91
|
-
}
|
|
92
|
-
function KeyboardAvoidingView({
|
|
93
|
-
if: _if,
|
|
94
|
-
actions: _actions,
|
|
95
|
-
...rest
|
|
96
|
-
}) {
|
|
97
|
-
return /* @__PURE__ */ jsx(KeyboardAvoidingView$1, { ...rest });
|
|
98
|
-
}
|
|
99
|
-
var NativeSafeAreaView;
|
|
100
|
-
try {
|
|
101
|
-
NativeSafeAreaView = __require("react-native-safe-area-context").SafeAreaView;
|
|
102
|
-
} catch {
|
|
103
|
-
NativeSafeAreaView = __require("react-native").SafeAreaView;
|
|
104
|
-
}
|
|
105
|
-
function SafeAreaView({ if: _if, actions: _actions, ...rest }) {
|
|
106
|
-
return /* @__PURE__ */ jsx(NativeSafeAreaView, { ...rest });
|
|
107
|
-
}
|
|
108
|
-
function StatusBar({ if: _if, actions: _actions, ...rest }) {
|
|
109
|
-
return /* @__PURE__ */ jsx(StatusBar$1, { ...rest });
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// src/registry/ComponentRegistry.ts
|
|
113
|
-
var BUILT_IN_TYPES = /* @__PURE__ */ new Set([
|
|
114
|
-
"text",
|
|
115
|
-
"view",
|
|
116
|
-
"scrollview",
|
|
117
|
-
"image",
|
|
118
|
-
"pressable",
|
|
119
|
-
"textinput",
|
|
120
|
-
"flatlist",
|
|
121
|
-
"modal",
|
|
122
|
-
"activityindicator",
|
|
123
|
-
"switch",
|
|
124
|
-
"keyboardavoidingview",
|
|
125
|
-
"safeareaview",
|
|
126
|
-
"statusbar"
|
|
127
|
-
]);
|
|
128
|
-
var BUILT_IN_COMPONENTS = /* @__PURE__ */ new Map([
|
|
129
|
-
["text", Text],
|
|
130
|
-
["view", View],
|
|
131
|
-
["scrollview", ScrollView],
|
|
132
|
-
["image", Image],
|
|
133
|
-
["pressable", Pressable],
|
|
134
|
-
["textinput", TextInput],
|
|
135
|
-
["flatlist", FlatList],
|
|
136
|
-
["modal", Modal],
|
|
137
|
-
["activityindicator", ActivityIndicator],
|
|
138
|
-
["switch", Switch],
|
|
139
|
-
["keyboardavoidingview", KeyboardAvoidingView],
|
|
140
|
-
["safeareaview", SafeAreaView],
|
|
141
|
-
["statusbar", StatusBar]
|
|
142
|
-
]);
|
|
143
|
-
var ComponentRegistry = class {
|
|
144
|
-
constructor(developerComponents) {
|
|
145
|
-
this.components = new Map(BUILT_IN_COMPONENTS);
|
|
146
|
-
if (developerComponents) {
|
|
147
|
-
for (const [type, component] of Object.entries(developerComponents)) {
|
|
148
|
-
if (BUILT_IN_TYPES.has(type)) {
|
|
149
|
-
console.warn(
|
|
150
|
-
`[PushFrame] ComponentRegistry: "${type}" is a built-in type and cannot be overridden. Registration skipped.`
|
|
151
|
-
);
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
this.components.set(type, component);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Resolve a type string to its React component.
|
|
160
|
-
* Returns null if no component is registered for the type.
|
|
161
|
-
*/
|
|
162
|
-
resolve(type) {
|
|
163
|
-
return this.components.get(type) ?? null;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Returns all registered type strings (useful for debugging).
|
|
167
|
-
*/
|
|
168
|
-
types() {
|
|
169
|
-
return Array.from(this.components.keys());
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
var TYPE_COLORS = {
|
|
173
|
-
success: "#22c55e",
|
|
174
|
-
error: "#ef4444",
|
|
175
|
-
info: "#3b82f6",
|
|
176
|
-
warning: "#f59e0b"
|
|
177
|
-
};
|
|
178
|
-
var ToastHost = forwardRef(function ToastHost2(_props, ref) {
|
|
179
|
-
const [toast, setToast] = useState(null);
|
|
180
|
-
const opacity = useRef(new Animated.Value(0)).current;
|
|
181
|
-
const idRef = useRef(0);
|
|
182
|
-
const hide = useCallback(() => {
|
|
183
|
-
Animated.timing(opacity, {
|
|
184
|
-
toValue: 0,
|
|
185
|
-
duration: 200,
|
|
186
|
-
useNativeDriver: true
|
|
187
|
-
}).start(() => {
|
|
188
|
-
setToast(null);
|
|
189
|
-
});
|
|
190
|
-
}, [opacity]);
|
|
191
|
-
useEffect(() => {
|
|
192
|
-
if (!toast) return;
|
|
193
|
-
Animated.timing(opacity, {
|
|
194
|
-
toValue: 1,
|
|
195
|
-
duration: 200,
|
|
196
|
-
useNativeDriver: true
|
|
197
|
-
}).start();
|
|
198
|
-
const timer = setTimeout(() => {
|
|
199
|
-
hide();
|
|
200
|
-
}, toast.duration);
|
|
201
|
-
return () => {
|
|
202
|
-
clearTimeout(timer);
|
|
203
|
-
};
|
|
204
|
-
}, [toast, opacity, hide]);
|
|
205
|
-
useImperativeHandle(
|
|
206
|
-
ref,
|
|
207
|
-
() => ({
|
|
208
|
-
show(payload) {
|
|
209
|
-
idRef.current += 1;
|
|
210
|
-
setToast({
|
|
211
|
-
id: idRef.current,
|
|
212
|
-
message: payload.message,
|
|
213
|
-
duration: payload.duration ?? 3e3,
|
|
214
|
-
type: payload.type ?? "info"
|
|
215
|
-
});
|
|
216
|
-
opacity.setValue(0);
|
|
217
|
-
}
|
|
218
|
-
}),
|
|
219
|
-
[opacity]
|
|
220
|
-
);
|
|
221
|
-
if (!toast) return null;
|
|
222
|
-
const backgroundColor = TYPE_COLORS[toast.type ?? "info"] ?? TYPE_COLORS.info;
|
|
223
|
-
return /* @__PURE__ */ jsx(View$1, { style: styles.container, pointerEvents: "none", children: /* @__PURE__ */ jsx(Animated.View, { style: [styles.toast, { backgroundColor, opacity }], children: /* @__PURE__ */ jsx(Text$1, { style: styles.message, children: toast.message }) }) });
|
|
224
|
-
});
|
|
225
|
-
var styles = StyleSheet.create({
|
|
226
|
-
container: {
|
|
227
|
-
position: "absolute",
|
|
228
|
-
bottom: 60,
|
|
229
|
-
left: 16,
|
|
230
|
-
right: 16,
|
|
231
|
-
alignItems: "center",
|
|
232
|
-
zIndex: 9999
|
|
233
|
-
},
|
|
234
|
-
toast: {
|
|
235
|
-
paddingVertical: 12,
|
|
236
|
-
paddingHorizontal: 20,
|
|
237
|
-
borderRadius: 8,
|
|
238
|
-
maxWidth: 400,
|
|
239
|
-
shadowColor: "#000",
|
|
240
|
-
shadowOffset: { width: 0, height: 2 },
|
|
241
|
-
shadowOpacity: 0.2,
|
|
242
|
-
shadowRadius: 4,
|
|
243
|
-
elevation: 6
|
|
244
|
-
},
|
|
245
|
-
message: {
|
|
246
|
-
color: "#fff",
|
|
247
|
-
fontSize: 14,
|
|
248
|
-
fontWeight: "500",
|
|
249
|
-
textAlign: "center"
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
var SCREEN_HEIGHT = Dimensions.get("window").height;
|
|
253
|
-
var BottomSheetHost = forwardRef(
|
|
254
|
-
function BottomSheetHost2({ renderContent }, ref) {
|
|
255
|
-
const [visible, setVisible] = useState(false);
|
|
256
|
-
const [payload, setPayload] = useState(null);
|
|
257
|
-
const translateY = useRef(new Animated.Value(SCREEN_HEIGHT)).current;
|
|
258
|
-
const animateIn = useCallback(() => {
|
|
259
|
-
Animated.spring(translateY, {
|
|
260
|
-
toValue: 0,
|
|
261
|
-
useNativeDriver: true,
|
|
262
|
-
bounciness: 4
|
|
263
|
-
}).start();
|
|
264
|
-
}, [translateY]);
|
|
265
|
-
const animateOut = useCallback(
|
|
266
|
-
(onDone) => {
|
|
267
|
-
Animated.timing(translateY, {
|
|
268
|
-
toValue: SCREEN_HEIGHT,
|
|
269
|
-
duration: 250,
|
|
270
|
-
useNativeDriver: true
|
|
271
|
-
}).start(() => {
|
|
272
|
-
onDone?.();
|
|
273
|
-
});
|
|
274
|
-
},
|
|
275
|
-
[translateY]
|
|
276
|
-
);
|
|
277
|
-
useEffect(() => {
|
|
278
|
-
if (visible) {
|
|
279
|
-
translateY.setValue(SCREEN_HEIGHT);
|
|
280
|
-
animateIn();
|
|
281
|
-
}
|
|
282
|
-
}, [visible, translateY, animateIn]);
|
|
283
|
-
const dismiss = useCallback(() => {
|
|
284
|
-
animateOut(() => {
|
|
285
|
-
setVisible(false);
|
|
286
|
-
setPayload(null);
|
|
287
|
-
});
|
|
288
|
-
}, [animateOut]);
|
|
289
|
-
useImperativeHandle(
|
|
290
|
-
ref,
|
|
291
|
-
() => ({
|
|
292
|
-
show(p) {
|
|
293
|
-
setPayload(p);
|
|
294
|
-
setVisible(true);
|
|
295
|
-
},
|
|
296
|
-
dismiss() {
|
|
297
|
-
dismiss();
|
|
298
|
-
}
|
|
299
|
-
}),
|
|
300
|
-
[dismiss]
|
|
301
|
-
);
|
|
302
|
-
if (!visible || !payload) return null;
|
|
303
|
-
return /* @__PURE__ */ jsxs(
|
|
304
|
-
Modal$1,
|
|
305
|
-
{
|
|
306
|
-
visible,
|
|
307
|
-
transparent: true,
|
|
308
|
-
animationType: "none",
|
|
309
|
-
onRequestClose: dismiss,
|
|
310
|
-
statusBarTranslucent: true,
|
|
311
|
-
children: [
|
|
312
|
-
/* @__PURE__ */ jsx(Pressable$1, { style: styles2.backdrop, onPress: dismiss }),
|
|
313
|
-
/* @__PURE__ */ jsxs(Animated.View, { style: [styles2.sheet, { transform: [{ translateY }] }], children: [
|
|
314
|
-
/* @__PURE__ */ jsx(View$1, { style: styles2.handle }),
|
|
315
|
-
/* @__PURE__ */ jsx(View$1, { style: styles2.content, children: renderContent(payload.schema, payload.context) })
|
|
316
|
-
] })
|
|
317
|
-
]
|
|
318
|
-
}
|
|
319
|
-
);
|
|
320
|
-
}
|
|
321
|
-
);
|
|
322
|
-
var styles2 = StyleSheet.create({
|
|
323
|
-
backdrop: {
|
|
324
|
-
...StyleSheet.absoluteFillObject,
|
|
325
|
-
backgroundColor: "rgba(0,0,0,0.5)"
|
|
326
|
-
},
|
|
327
|
-
sheet: {
|
|
328
|
-
position: "absolute",
|
|
329
|
-
bottom: 0,
|
|
330
|
-
left: 0,
|
|
331
|
-
right: 0,
|
|
332
|
-
backgroundColor: "#fff",
|
|
333
|
-
borderTopLeftRadius: 16,
|
|
334
|
-
borderTopRightRadius: 16,
|
|
335
|
-
paddingBottom: 34,
|
|
336
|
-
// safe-area approximation
|
|
337
|
-
minHeight: 200,
|
|
338
|
-
maxHeight: "80%",
|
|
339
|
-
shadowColor: "#000",
|
|
340
|
-
shadowOffset: { width: 0, height: -4 },
|
|
341
|
-
shadowOpacity: 0.15,
|
|
342
|
-
shadowRadius: 12,
|
|
343
|
-
elevation: 20
|
|
344
|
-
},
|
|
345
|
-
handle: {
|
|
346
|
-
alignSelf: "center",
|
|
347
|
-
width: 36,
|
|
348
|
-
height: 4,
|
|
349
|
-
borderRadius: 2,
|
|
350
|
-
backgroundColor: "#d1d5db",
|
|
351
|
-
marginTop: 12,
|
|
352
|
-
marginBottom: 8
|
|
353
|
-
},
|
|
354
|
-
content: {
|
|
355
|
-
flex: 1,
|
|
356
|
-
paddingHorizontal: 16,
|
|
357
|
-
paddingTop: 8
|
|
358
|
-
}
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
// src/renderer/bindingResolver.ts
|
|
362
|
-
var FULL_BINDING_RE = /^\{\{(.+)\}\}$/;
|
|
363
|
-
var INLINE_BINDING_RE = /\{\{([^}]+)\}\}/g;
|
|
364
|
-
function evaluateExpression(expr, context) {
|
|
365
|
-
try {
|
|
366
|
-
const keys = Object.keys(context);
|
|
367
|
-
const values = keys.map((k) => context[k]);
|
|
368
|
-
const fn = new Function(...keys, `"use strict"; try { return (${expr}); } catch(e) { return undefined; }`);
|
|
369
|
-
return fn(...values);
|
|
370
|
-
} catch {
|
|
371
|
-
return void 0;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
function resolveValue(value, context) {
|
|
375
|
-
if (typeof value !== "string") {
|
|
376
|
-
return value;
|
|
377
|
-
}
|
|
378
|
-
const fullMatch = FULL_BINDING_RE.exec(value);
|
|
379
|
-
if (fullMatch?.[1] !== void 0) {
|
|
380
|
-
return evaluateExpression(fullMatch[1].trim(), context);
|
|
381
|
-
}
|
|
382
|
-
if (INLINE_BINDING_RE.test(value)) {
|
|
383
|
-
INLINE_BINDING_RE.lastIndex = 0;
|
|
384
|
-
return value.replace(INLINE_BINDING_RE, (_, expr) => {
|
|
385
|
-
const resolved = evaluateExpression(expr.trim(), context);
|
|
386
|
-
return resolved !== void 0 && resolved !== null ? String(resolved) : "";
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
return value;
|
|
390
|
-
}
|
|
391
|
-
function resolveProps(props, context) {
|
|
392
|
-
if (!props) return {};
|
|
393
|
-
const resolved = {};
|
|
394
|
-
for (const [key, value] of Object.entries(props)) {
|
|
395
|
-
resolved[key] = resolveDeep(value, context);
|
|
396
|
-
}
|
|
397
|
-
return resolved;
|
|
398
|
-
}
|
|
399
|
-
function resolveDeep(value, context) {
|
|
400
|
-
if (Array.isArray(value)) {
|
|
401
|
-
return value.map((item) => resolveDeep(item, context));
|
|
402
|
-
}
|
|
403
|
-
if (typeof value === "object" && value !== null) {
|
|
404
|
-
const result = {};
|
|
405
|
-
for (const [k, v] of Object.entries(value)) {
|
|
406
|
-
result[k] = resolveDeep(v, context);
|
|
407
|
-
}
|
|
408
|
-
return result;
|
|
409
|
-
}
|
|
410
|
-
return resolveValue(value, context);
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
// src/renderer/conditionalEvaluator.ts
|
|
414
|
-
function evaluateIf(ifExpr, context) {
|
|
415
|
-
if (ifExpr === void 0 || ifExpr === null) return true;
|
|
416
|
-
if (typeof ifExpr !== "string") return Boolean(ifExpr);
|
|
417
|
-
const resolved = resolveValue(ifExpr, context);
|
|
418
|
-
return Boolean(resolved);
|
|
419
|
-
}
|
|
420
|
-
function buildActionProps(actions, context, dispatchAction) {
|
|
421
|
-
const grouped = /* @__PURE__ */ new Map();
|
|
422
|
-
for (const action of actions) {
|
|
423
|
-
const existing = grouped.get(action.trigger);
|
|
424
|
-
if (existing) {
|
|
425
|
-
existing.push(action);
|
|
426
|
-
} else {
|
|
427
|
-
grouped.set(action.trigger, [action]);
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
const result = {};
|
|
431
|
-
for (const [trigger, triggerActions] of grouped) {
|
|
432
|
-
result[trigger] = (..._args) => {
|
|
433
|
-
for (const action of triggerActions) {
|
|
434
|
-
const resolvedPayload = action.payload !== void 0 ? resolveDeep(action.payload, context) : void 0;
|
|
435
|
-
dispatchAction(action.action, resolvedPayload);
|
|
436
|
-
}
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
|
-
return result;
|
|
440
|
-
}
|
|
441
|
-
function renderFlatListNode(node, context, registry, dispatchAction, fallbackComponent) {
|
|
442
|
-
const resolvedProps = resolveProps(node.props, context);
|
|
443
|
-
const actionProps = node.actions ? buildActionProps(node.actions, context, dispatchAction) : {};
|
|
444
|
-
const {
|
|
445
|
-
data: resolvedData,
|
|
446
|
-
items: resolvedItems,
|
|
447
|
-
keyExtractor: keyExtractorExpr,
|
|
448
|
-
direction,
|
|
449
|
-
numColumns,
|
|
450
|
-
visible: _visible,
|
|
451
|
-
_propValues: _pv,
|
|
452
|
-
...restProps
|
|
453
|
-
} = resolvedProps;
|
|
454
|
-
const items = Array.isArray(resolvedData) ? resolvedData : Array.isArray(resolvedItems) ? resolvedItems : [];
|
|
455
|
-
let keyExtractorFn;
|
|
456
|
-
if (typeof keyExtractorExpr === "string") {
|
|
457
|
-
const extractorExpr = keyExtractorExpr;
|
|
458
|
-
keyExtractorFn = (item, index) => {
|
|
459
|
-
const itemContext = { ...context, item, index };
|
|
460
|
-
const resolved = resolveValue(extractorExpr, itemContext);
|
|
461
|
-
return resolved !== void 0 && resolved !== null ? String(resolved) : String(index);
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
const renderItemFn = ({ item, index }) => {
|
|
465
|
-
const itemContext = { ...context, item, index };
|
|
466
|
-
return /* @__PURE__ */ jsx(
|
|
467
|
-
RecursiveRenderer,
|
|
468
|
-
{
|
|
469
|
-
node: node.itemTemplate,
|
|
470
|
-
context: itemContext,
|
|
471
|
-
registry,
|
|
472
|
-
dispatchAction,
|
|
473
|
-
fallbackComponent
|
|
474
|
-
},
|
|
475
|
-
keyExtractorFn ? keyExtractorFn(item, index) : index
|
|
476
|
-
);
|
|
477
|
-
};
|
|
478
|
-
const FlatListComponent = registry.resolve("flatlist");
|
|
479
|
-
if (!FlatListComponent) {
|
|
480
|
-
console.warn('[PushFrame] RecursiveRenderer: "flatlist" not found in registry.');
|
|
481
|
-
return fallbackComponent ? fallbackComponent : null;
|
|
482
|
-
}
|
|
483
|
-
return React4.createElement(FlatListComponent, {
|
|
484
|
-
...restProps,
|
|
485
|
-
...actionProps,
|
|
486
|
-
items,
|
|
487
|
-
direction,
|
|
488
|
-
numColumns,
|
|
489
|
-
keyExtractor: keyExtractorFn,
|
|
490
|
-
renderItem: renderItemFn
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
function RecursiveRenderer({
|
|
494
|
-
node,
|
|
495
|
-
context,
|
|
496
|
-
registry,
|
|
497
|
-
dispatchAction,
|
|
498
|
-
fallbackComponent
|
|
499
|
-
}) {
|
|
500
|
-
if (!evaluateIf(node.if, context)) {
|
|
501
|
-
return null;
|
|
502
|
-
}
|
|
503
|
-
if (node.type === "flatlist") {
|
|
504
|
-
return renderFlatListNode(
|
|
505
|
-
node,
|
|
506
|
-
context,
|
|
507
|
-
registry,
|
|
508
|
-
dispatchAction,
|
|
509
|
-
fallbackComponent
|
|
510
|
-
);
|
|
511
|
-
}
|
|
512
|
-
const resolvedProps = resolveProps(node.props, context);
|
|
513
|
-
if (resolvedProps.visible !== void 0 && !resolvedProps.visible) {
|
|
514
|
-
return null;
|
|
515
|
-
}
|
|
516
|
-
const {
|
|
517
|
-
visible: _visible,
|
|
518
|
-
_propValues: propValuesRaw,
|
|
519
|
-
...propsToForward
|
|
520
|
-
} = resolvedProps;
|
|
521
|
-
const propValues = propValuesRaw;
|
|
522
|
-
const childContext = propValues && Object.keys(propValues).length > 0 ? { ...context, ...propValues } : context;
|
|
523
|
-
const actionProps = node.actions ? buildActionProps(node.actions, context, dispatchAction) : {};
|
|
524
|
-
const Component = registry.resolve(node.type);
|
|
525
|
-
if (!Component) {
|
|
526
|
-
console.warn(
|
|
527
|
-
`[PushFrame] RecursiveRenderer: Unknown component type "${node.type}". Registered types: ${registry.types().join(", ")}`
|
|
528
|
-
);
|
|
529
|
-
return fallbackComponent ? fallbackComponent : null;
|
|
530
|
-
}
|
|
531
|
-
const children = node.children && node.children.length > 0 ? node.children.map((child, index) => /* @__PURE__ */ jsx(
|
|
532
|
-
RecursiveRenderer,
|
|
533
|
-
{
|
|
534
|
-
node: child,
|
|
535
|
-
context: childContext,
|
|
536
|
-
registry,
|
|
537
|
-
dispatchAction,
|
|
538
|
-
fallbackComponent
|
|
539
|
-
},
|
|
540
|
-
`${child.type}-${index}`
|
|
541
|
-
)) : void 0;
|
|
542
|
-
return React4.createElement(Component, {
|
|
543
|
-
...propsToForward,
|
|
544
|
-
...actionProps,
|
|
545
|
-
children
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
var DEFAULT_BASE_URL = "https://api.pushframe.io";
|
|
549
|
-
function PushFrameProvider({
|
|
550
|
-
apiKey,
|
|
551
|
-
context = {},
|
|
552
|
-
baseUrl = DEFAULT_BASE_URL,
|
|
553
|
-
appVersion,
|
|
554
|
-
components,
|
|
555
|
-
loadingComponent,
|
|
556
|
-
fallbackComponent,
|
|
557
|
-
onAction,
|
|
558
|
-
onError,
|
|
559
|
-
children
|
|
560
|
-
}) {
|
|
561
|
-
const registry = useMemo(
|
|
562
|
-
() => new ComponentRegistry(components),
|
|
563
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
564
|
-
[]
|
|
565
|
-
);
|
|
566
|
-
const toastRef = useRef(null);
|
|
567
|
-
const bottomSheetRef = useRef(null);
|
|
568
|
-
const showToast = useCallback((payload) => {
|
|
569
|
-
toastRef.current?.show(payload);
|
|
570
|
-
}, []);
|
|
571
|
-
const showBottomSheet = useCallback((payload) => {
|
|
572
|
-
bottomSheetRef.current?.show(payload);
|
|
573
|
-
}, []);
|
|
574
|
-
const dismissBottomSheet = useCallback(() => {
|
|
575
|
-
bottomSheetRef.current?.dismiss();
|
|
576
|
-
}, []);
|
|
577
|
-
const renderBottomSheetContent = useCallback(
|
|
578
|
-
(schema, sheetContext) => {
|
|
579
|
-
const mergedContext = sheetContext ? { ...context, ...sheetContext } : context;
|
|
580
|
-
const dispatchAction = (action, payload) => {
|
|
581
|
-
if (action === "dismiss-bottom-sheet") {
|
|
582
|
-
dismissBottomSheet();
|
|
583
|
-
return;
|
|
584
|
-
}
|
|
585
|
-
if (action === "show-toast") {
|
|
586
|
-
showToast(payload);
|
|
587
|
-
return;
|
|
588
|
-
}
|
|
589
|
-
onAction?.(action, payload);
|
|
590
|
-
};
|
|
591
|
-
return /* @__PURE__ */ jsx(
|
|
592
|
-
RecursiveRenderer,
|
|
593
|
-
{
|
|
594
|
-
node: schema,
|
|
595
|
-
context: mergedContext,
|
|
596
|
-
registry,
|
|
597
|
-
dispatchAction,
|
|
598
|
-
fallbackComponent
|
|
599
|
-
}
|
|
600
|
-
);
|
|
601
|
-
},
|
|
602
|
-
[context, registry, fallbackComponent, onAction, dismissBottomSheet, showToast]
|
|
603
|
-
);
|
|
604
|
-
const contextValue = useMemo(
|
|
605
|
-
() => ({
|
|
606
|
-
apiKey,
|
|
607
|
-
baseUrl,
|
|
608
|
-
appVersion,
|
|
609
|
-
globalContext: context,
|
|
610
|
-
registry,
|
|
611
|
-
loadingComponent,
|
|
612
|
-
fallbackComponent,
|
|
613
|
-
onAction,
|
|
614
|
-
onError,
|
|
615
|
-
showToast,
|
|
616
|
-
showBottomSheet,
|
|
617
|
-
dismissBottomSheet
|
|
618
|
-
}),
|
|
619
|
-
[
|
|
620
|
-
apiKey,
|
|
621
|
-
baseUrl,
|
|
622
|
-
appVersion,
|
|
623
|
-
context,
|
|
624
|
-
registry,
|
|
625
|
-
loadingComponent,
|
|
626
|
-
fallbackComponent,
|
|
627
|
-
onAction,
|
|
628
|
-
onError,
|
|
629
|
-
showToast,
|
|
630
|
-
showBottomSheet,
|
|
631
|
-
dismissBottomSheet
|
|
632
|
-
]
|
|
633
|
-
);
|
|
634
|
-
return /* @__PURE__ */ jsxs(PushFrameContext.Provider, { value: contextValue, children: [
|
|
635
|
-
children,
|
|
636
|
-
/* @__PURE__ */ jsx(ToastHost, { ref: toastRef }),
|
|
637
|
-
/* @__PURE__ */ jsx(BottomSheetHost, { ref: bottomSheetRef, renderContent: renderBottomSheetContent })
|
|
638
|
-
] });
|
|
639
|
-
}
|
|
640
|
-
async function fetchSchema(baseUrl, apiKey, path) {
|
|
641
|
-
const url = new URL(path, baseUrl + "/").toString();
|
|
642
|
-
const headers = {
|
|
643
|
-
Accept: "application/json",
|
|
644
|
-
Authorization: `Bearer ${apiKey}`,
|
|
645
|
-
"x-project-key": apiKey
|
|
646
|
-
};
|
|
647
|
-
const res = await fetch(url, { headers });
|
|
648
|
-
if (!res.ok) {
|
|
649
|
-
throw new Error(`[PushFrame] HTTP ${res.status} fetching "${path}"`);
|
|
650
|
-
}
|
|
651
|
-
const envelope = await res.json();
|
|
652
|
-
return envelope.schema ?? envelope;
|
|
653
|
-
}
|
|
654
|
-
function PushFrameComponentInternal({
|
|
655
|
-
id,
|
|
656
|
-
resourceType,
|
|
657
|
-
context: slotContext,
|
|
658
|
-
isLoading: externalLoading,
|
|
659
|
-
loadingComponent: slotLoading,
|
|
660
|
-
fallbackComponent: slotFallback,
|
|
661
|
-
onAction: slotOnAction,
|
|
662
|
-
fullscreen
|
|
663
|
-
}) {
|
|
664
|
-
const {
|
|
665
|
-
apiKey,
|
|
666
|
-
baseUrl,
|
|
667
|
-
appVersion,
|
|
668
|
-
globalContext,
|
|
669
|
-
registry,
|
|
670
|
-
loadingComponent: providerLoading,
|
|
671
|
-
fallbackComponent: providerFallback,
|
|
672
|
-
onAction: providerOnAction,
|
|
673
|
-
onError,
|
|
674
|
-
showToast,
|
|
675
|
-
showBottomSheet,
|
|
676
|
-
dismissBottomSheet
|
|
677
|
-
} = usePushFrameContext();
|
|
678
|
-
const [schema, setSchema] = useState(null);
|
|
679
|
-
const [fetchError, setFetchError] = useState(null);
|
|
680
|
-
const [isFetching, setIsFetching] = useState(true);
|
|
681
|
-
const fetchPath = `${resourceType}/${encodeURIComponent(id)}/${encodeURIComponent(appVersion ?? "null")}`;
|
|
682
|
-
const mergedContext = slotContext ? { ...globalContext, ...slotContext } : globalContext;
|
|
683
|
-
const loadingUI = slotLoading !== void 0 ? slotLoading : providerLoading;
|
|
684
|
-
const fallbackUI = slotFallback !== void 0 ? slotFallback : providerFallback;
|
|
685
|
-
useEffect(() => {
|
|
686
|
-
let cancelled = false;
|
|
687
|
-
setSchema(null);
|
|
688
|
-
setFetchError(null);
|
|
689
|
-
setIsFetching(true);
|
|
690
|
-
fetchSchema(baseUrl, apiKey, fetchPath).then((s) => {
|
|
691
|
-
if (!cancelled) {
|
|
692
|
-
setSchema(s);
|
|
693
|
-
setIsFetching(false);
|
|
694
|
-
}
|
|
695
|
-
}).catch((err) => {
|
|
696
|
-
if (!cancelled) {
|
|
697
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
698
|
-
setFetchError(error);
|
|
699
|
-
setIsFetching(false);
|
|
700
|
-
onError?.(error);
|
|
701
|
-
}
|
|
702
|
-
});
|
|
703
|
-
return () => {
|
|
704
|
-
cancelled = true;
|
|
705
|
-
};
|
|
706
|
-
}, [fetchPath, baseUrl, apiKey, onError]);
|
|
707
|
-
const dispatchAction = useCallback(
|
|
708
|
-
(action, payload) => {
|
|
709
|
-
if (action === "show-toast") {
|
|
710
|
-
showToast(payload);
|
|
711
|
-
return;
|
|
712
|
-
}
|
|
713
|
-
if (action === "show-bottom-sheet") {
|
|
714
|
-
showBottomSheet(payload);
|
|
715
|
-
return;
|
|
716
|
-
}
|
|
717
|
-
if (action === "dismiss-bottom-sheet") {
|
|
718
|
-
dismissBottomSheet();
|
|
719
|
-
return;
|
|
720
|
-
}
|
|
721
|
-
if (action === "scroll-to") {
|
|
722
|
-
return;
|
|
723
|
-
}
|
|
724
|
-
const stopped = slotOnAction?.(action, payload);
|
|
725
|
-
if (stopped) return;
|
|
726
|
-
providerOnAction?.(action, payload);
|
|
727
|
-
},
|
|
728
|
-
[showToast, showBottomSheet, dismissBottomSheet, slotOnAction, providerOnAction]
|
|
729
|
-
);
|
|
730
|
-
const isShowingLoader = externalLoading || isFetching;
|
|
731
|
-
if (isShowingLoader) {
|
|
732
|
-
return loadingUI ?? null;
|
|
733
|
-
}
|
|
734
|
-
if (fetchError || !schema) {
|
|
735
|
-
return fallbackUI ?? null;
|
|
736
|
-
}
|
|
737
|
-
const rendered = /* @__PURE__ */ jsx(
|
|
738
|
-
RecursiveRenderer,
|
|
739
|
-
{
|
|
740
|
-
node: schema,
|
|
741
|
-
context: mergedContext,
|
|
742
|
-
registry,
|
|
743
|
-
dispatchAction,
|
|
744
|
-
fallbackComponent: fallbackUI
|
|
745
|
-
}
|
|
746
|
-
);
|
|
747
|
-
if (fullscreen) {
|
|
748
|
-
return /* @__PURE__ */ jsx(Fragment, { children: rendered });
|
|
749
|
-
}
|
|
750
|
-
return rendered;
|
|
751
|
-
}
|
|
752
|
-
function PushFrameComponent(props) {
|
|
753
|
-
return /* @__PURE__ */ jsx(PushFrameComponentInternal, { ...props, resourceType: "components" });
|
|
754
|
-
}
|
|
755
|
-
function PushFrameScreen(props) {
|
|
756
|
-
return /* @__PURE__ */ jsx(View$1, { style: styles3.container, children: /* @__PURE__ */ jsx(PushFrameComponentInternal, { ...props, resourceType: "screens", fullscreen: true }) });
|
|
757
|
-
}
|
|
758
|
-
var styles3 = StyleSheet.create({
|
|
759
|
-
container: {
|
|
760
|
-
flex: 1
|
|
761
|
-
}
|
|
762
|
-
});
|
|
763
|
-
|
|
764
|
-
// src/transformer/index.ts
|
|
765
|
-
var BRIDGE_KEYS = /* @__PURE__ */ new Set([
|
|
766
|
-
"_schemaId",
|
|
767
|
-
"_schemaType",
|
|
768
|
-
"_schemaActions",
|
|
769
|
-
"_schemaIf",
|
|
770
|
-
"_schemaRenderItem"
|
|
771
|
-
]);
|
|
772
|
-
var ALIGN_MAP = {
|
|
773
|
-
start: "flex-start",
|
|
774
|
-
center: "center",
|
|
775
|
-
end: "flex-end",
|
|
776
|
-
stretch: "stretch",
|
|
777
|
-
baseline: "baseline"
|
|
778
|
-
};
|
|
779
|
-
var DISTRIBUTE_MAP = {
|
|
780
|
-
start: "flex-start",
|
|
781
|
-
center: "center",
|
|
782
|
-
end: "flex-end",
|
|
783
|
-
"space-between": "space-between",
|
|
784
|
-
"space-around": "space-around",
|
|
785
|
-
"space-evenly": "space-evenly"
|
|
786
|
-
};
|
|
787
|
-
var FIT_TO_RESIZE_MODE = {
|
|
788
|
-
cover: "cover",
|
|
789
|
-
contain: "contain",
|
|
790
|
-
fill: "stretch",
|
|
791
|
-
// RN uses 'stretch', not 'fill'
|
|
792
|
-
center: "center"
|
|
793
|
-
};
|
|
794
|
-
var FONT_WEIGHT_MAP = {
|
|
795
|
-
regular: "400",
|
|
796
|
-
medium: "500",
|
|
797
|
-
semibold: "600",
|
|
798
|
-
bold: "700"
|
|
799
|
-
};
|
|
800
|
-
var TEXT_STYLE_PRESETS = {
|
|
801
|
-
"heading-1": { fontSize: 28, fontWeight: "700" },
|
|
802
|
-
"heading-2": { fontSize: 22, fontWeight: "700" },
|
|
803
|
-
"heading-3": { fontSize: 18, fontWeight: "600" },
|
|
804
|
-
"body": { fontSize: 16, fontWeight: "400" },
|
|
805
|
-
"body-sm": { fontSize: 14, fontWeight: "400" },
|
|
806
|
-
"caption": { fontSize: 12, fontWeight: "400" },
|
|
807
|
-
"label": { fontSize: 13, fontWeight: "500" },
|
|
808
|
-
"overline": { fontSize: 11, fontWeight: "500", textTransform: "uppercase", letterSpacing: 0.8 }
|
|
809
|
-
};
|
|
810
|
-
var INPUT_TYPE_MAP = {
|
|
811
|
-
text: { keyboardType: "default", secureTextEntry: false, autoCapitalize: "sentences", autoCorrect: true },
|
|
812
|
-
email: { keyboardType: "email-address", secureTextEntry: false, autoCapitalize: "none", autoCorrect: false },
|
|
813
|
-
password: { keyboardType: "default", secureTextEntry: true, autoCapitalize: "none", autoCorrect: false },
|
|
814
|
-
number: { keyboardType: "numeric", secureTextEntry: false, autoCapitalize: "none", autoCorrect: false },
|
|
815
|
-
decimal: { keyboardType: "decimal-pad", secureTextEntry: false, autoCapitalize: "none", autoCorrect: false },
|
|
816
|
-
phone: { keyboardType: "phone-pad", secureTextEntry: false, autoCapitalize: "none", autoCorrect: false },
|
|
817
|
-
url: { keyboardType: "url", secureTextEntry: false, autoCapitalize: "none", autoCorrect: false },
|
|
818
|
-
search: { keyboardType: "default", secureTextEntry: false, autoCapitalize: "none", autoCorrect: false }
|
|
819
|
-
};
|
|
820
|
-
function stripBridgeKeys(props) {
|
|
821
|
-
const out = {};
|
|
822
|
-
for (const k in props) {
|
|
823
|
-
if (!BRIDGE_KEYS.has(k)) out[k] = props[k];
|
|
824
|
-
}
|
|
825
|
-
return out;
|
|
826
|
-
}
|
|
827
|
-
function extractMeta(raw) {
|
|
828
|
-
return {
|
|
829
|
-
actions: raw._schemaActions,
|
|
830
|
-
condition: raw._schemaIf
|
|
831
|
-
};
|
|
832
|
-
}
|
|
833
|
-
function resolveSizeModeRN(value, axis, out, parentDirection) {
|
|
834
|
-
if (value === void 0) return;
|
|
835
|
-
if (value === "fill") {
|
|
836
|
-
const isMainAxis = parentDirection === "vertical" && axis === "height" || parentDirection === "horizontal" && axis === "width";
|
|
837
|
-
if (isMainAxis) {
|
|
838
|
-
out.flex = 1;
|
|
839
|
-
} else {
|
|
840
|
-
out.alignSelf = "stretch";
|
|
841
|
-
}
|
|
842
|
-
} else if (value === "hug") {
|
|
843
|
-
out.alignSelf = "flex-start";
|
|
844
|
-
} else {
|
|
845
|
-
out[axis] = value;
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
function resolvePaddingRN(padding) {
|
|
849
|
-
if (padding === void 0) return {};
|
|
850
|
-
if (typeof padding === "number") return { padding };
|
|
851
|
-
const { top, right, bottom, left } = padding;
|
|
852
|
-
if (top === bottom && left === right && top !== void 0 && left !== void 0) {
|
|
853
|
-
return { paddingVertical: top, paddingHorizontal: left };
|
|
854
|
-
}
|
|
855
|
-
return {
|
|
856
|
-
...top !== void 0 ? { paddingTop: top } : {},
|
|
857
|
-
...right !== void 0 ? { paddingRight: right } : {},
|
|
858
|
-
...bottom !== void 0 ? { paddingBottom: bottom } : {},
|
|
859
|
-
...left !== void 0 ? { paddingLeft: left } : {}
|
|
860
|
-
};
|
|
861
|
-
}
|
|
862
|
-
function resolveRadiusRN(radius) {
|
|
863
|
-
if (radius === void 0) return {};
|
|
864
|
-
if (typeof radius === "number") return { borderRadius: radius };
|
|
865
|
-
return {
|
|
866
|
-
...radius.tl !== void 0 ? { borderTopLeftRadius: radius.tl } : {},
|
|
867
|
-
...radius.tr !== void 0 ? { borderTopRightRadius: radius.tr } : {},
|
|
868
|
-
...radius.br !== void 0 ? { borderBottomRightRadius: radius.br } : {},
|
|
869
|
-
...radius.bl !== void 0 ? { borderBottomLeftRadius: radius.bl } : {}
|
|
870
|
-
};
|
|
871
|
-
}
|
|
872
|
-
function resolveBorderRN(border) {
|
|
873
|
-
if (!border) return {};
|
|
874
|
-
const out = {};
|
|
875
|
-
if (border.style) out.borderStyle = border.style;
|
|
876
|
-
if (border.color) out.borderColor = border.color;
|
|
877
|
-
if (border.widths) {
|
|
878
|
-
const w = border.widths;
|
|
879
|
-
if (w.top !== void 0) out.borderTopWidth = w.top;
|
|
880
|
-
if (w.right !== void 0) out.borderRightWidth = w.right;
|
|
881
|
-
if (w.bottom !== void 0) out.borderBottomWidth = w.bottom;
|
|
882
|
-
if (w.left !== void 0) out.borderLeftWidth = w.left;
|
|
883
|
-
} else if (border.width !== void 0) {
|
|
884
|
-
out.borderWidth = border.width;
|
|
885
|
-
}
|
|
886
|
-
return out;
|
|
887
|
-
}
|
|
888
|
-
function resolveShadowRN(shadow) {
|
|
889
|
-
if (!shadow) return {};
|
|
890
|
-
return {
|
|
891
|
-
shadowColor: shadow.color,
|
|
892
|
-
shadowOffset: { width: shadow.offsetX, height: shadow.offsetY },
|
|
893
|
-
shadowRadius: shadow.blur,
|
|
894
|
-
shadowOpacity: shadow.opacity,
|
|
895
|
-
elevation: Math.round(shadow.blur / 2)
|
|
896
|
-
};
|
|
897
|
-
}
|
|
898
|
-
function resolveTransformRN(props) {
|
|
899
|
-
const transforms = [];
|
|
900
|
-
if (props.rotate !== void 0 && props.rotate !== 0) transforms.push({ rotate: `${props.rotate}deg` });
|
|
901
|
-
if (props.scale !== void 0 && props.scale !== 1) transforms.push({ scale: props.scale });
|
|
902
|
-
if (props.translateX !== void 0 && props.translateX !== 0) transforms.push({ translateX: props.translateX });
|
|
903
|
-
if (props.translateY !== void 0 && props.translateY !== 0) transforms.push({ translateY: props.translateY });
|
|
904
|
-
return transforms.length ? { transform: transforms } : {};
|
|
905
|
-
}
|
|
906
|
-
function resolvePositionRN(props) {
|
|
907
|
-
const out = {};
|
|
908
|
-
if (props.position) out.position = props.position;
|
|
909
|
-
if (props.position === "absolute") {
|
|
910
|
-
if (props.top !== void 0) out.top = props.top;
|
|
911
|
-
if (props.right !== void 0) out.right = props.right;
|
|
912
|
-
if (props.bottom !== void 0) out.bottom = props.bottom;
|
|
913
|
-
if (props.left !== void 0) out.left = props.left;
|
|
914
|
-
}
|
|
915
|
-
if (props.zIndex !== void 0) out.zIndex = props.zIndex;
|
|
916
|
-
return out;
|
|
917
|
-
}
|
|
918
|
-
function resolveAccessibilityProps(props) {
|
|
919
|
-
const out = {};
|
|
920
|
-
if (props.accessible !== void 0) out.accessible = props.accessible;
|
|
921
|
-
if (props.accessibilityLabel) out.accessibilityLabel = props.accessibilityLabel;
|
|
922
|
-
if (props.accessibilityRole) out.accessibilityRole = props.accessibilityRole;
|
|
923
|
-
if (props.testID) out.testID = props.testID;
|
|
924
|
-
return out;
|
|
925
|
-
}
|
|
926
|
-
function buildFrameStyle(props, parentDirection) {
|
|
927
|
-
const style = {};
|
|
928
|
-
const frameType = props.type ?? "stack";
|
|
929
|
-
if (frameType === "grid") {
|
|
930
|
-
if (props.align) style.alignItems = ALIGN_MAP[props.align] ?? props.align;
|
|
931
|
-
} else {
|
|
932
|
-
style.flexDirection = props.direction === "horizontal" ? "row" : "column";
|
|
933
|
-
if (props.align) style.alignItems = ALIGN_MAP[props.align] ?? props.align;
|
|
934
|
-
if (props.distribute) style.justifyContent = DISTRIBUTE_MAP[props.distribute] ?? props.distribute;
|
|
935
|
-
if (props.gap !== void 0 && props.gap !== 0) style.gap = props.gap;
|
|
936
|
-
if (props.wrap === "yes") style.flexWrap = "wrap";
|
|
937
|
-
}
|
|
938
|
-
resolveSizeModeRN(props.width, "width", style, parentDirection);
|
|
939
|
-
resolveSizeModeRN(props.height, "height", style, parentDirection);
|
|
940
|
-
if (props.minWidth !== void 0) style.minWidth = props.minWidth;
|
|
941
|
-
if (props.maxWidth !== void 0) style.maxWidth = props.maxWidth;
|
|
942
|
-
if (props.minHeight !== void 0) style.minHeight = props.minHeight;
|
|
943
|
-
if (props.maxHeight !== void 0) style.maxHeight = props.maxHeight;
|
|
944
|
-
if (props.aspectRatio !== void 0) style.aspectRatio = props.aspectRatio;
|
|
945
|
-
Object.assign(style, resolvePaddingRN(props.padding));
|
|
946
|
-
if (props.fill && props.fill !== "transparent") style.backgroundColor = props.fill;
|
|
947
|
-
Object.assign(style, resolveRadiusRN(props.radius));
|
|
948
|
-
Object.assign(style, resolveBorderRN(props.border));
|
|
949
|
-
Object.assign(style, resolveShadowRN(props.shadow));
|
|
950
|
-
if (props.opacity !== void 0) style.opacity = props.opacity / 100;
|
|
951
|
-
if (props.overflow === true) style.overflow = "hidden";
|
|
952
|
-
Object.assign(style, resolvePositionRN(props));
|
|
953
|
-
Object.assign(style, resolveTransformRN(props));
|
|
954
|
-
return style;
|
|
955
|
-
}
|
|
956
|
-
function splitFrameStyle(style) {
|
|
957
|
-
const OUTER_KEYS = /* @__PURE__ */ new Set([
|
|
958
|
-
"flex",
|
|
959
|
-
"alignSelf",
|
|
960
|
-
"width",
|
|
961
|
-
"height",
|
|
962
|
-
"minWidth",
|
|
963
|
-
"maxWidth",
|
|
964
|
-
"minHeight",
|
|
965
|
-
"maxHeight",
|
|
966
|
-
"aspectRatio",
|
|
967
|
-
"position",
|
|
968
|
-
"top",
|
|
969
|
-
"right",
|
|
970
|
-
"bottom",
|
|
971
|
-
"left",
|
|
972
|
-
"zIndex",
|
|
973
|
-
"transform"
|
|
974
|
-
]);
|
|
975
|
-
const outer = {};
|
|
976
|
-
const inner = {};
|
|
977
|
-
for (const [k, v] of Object.entries(style)) {
|
|
978
|
-
if (OUTER_KEYS.has(k)) outer[k] = v;
|
|
979
|
-
else inner[k] = v;
|
|
980
|
-
}
|
|
981
|
-
return { outer, inner };
|
|
982
|
-
}
|
|
983
|
-
function splitScrollStyle(style) {
|
|
984
|
-
const CONTENT_KEYS = /* @__PURE__ */ new Set([
|
|
985
|
-
"flexDirection",
|
|
986
|
-
"justifyContent",
|
|
987
|
-
"alignItems",
|
|
988
|
-
"flexWrap",
|
|
989
|
-
"gap",
|
|
990
|
-
"padding",
|
|
991
|
-
"paddingTop",
|
|
992
|
-
"paddingRight",
|
|
993
|
-
"paddingBottom",
|
|
994
|
-
"paddingLeft",
|
|
995
|
-
"paddingVertical",
|
|
996
|
-
"paddingHorizontal"
|
|
997
|
-
]);
|
|
998
|
-
const containerStyle = {};
|
|
999
|
-
const contentStyle = {};
|
|
1000
|
-
for (const [k, v] of Object.entries(style)) {
|
|
1001
|
-
if (CONTENT_KEYS.has(k)) contentStyle[k] = v;
|
|
1002
|
-
else containerStyle[k] = v;
|
|
1003
|
-
}
|
|
1004
|
-
return { containerStyle, contentStyle };
|
|
1005
|
-
}
|
|
1006
|
-
function safeAreaEdges(safeArea) {
|
|
1007
|
-
if (!safeArea) return [];
|
|
1008
|
-
return Object.entries(safeArea).filter(([, v]) => v === true).map(([edge]) => edge);
|
|
1009
|
-
}
|
|
1010
|
-
function transformScreen(id, raw, children) {
|
|
1011
|
-
const { actions, condition } = extractMeta(raw);
|
|
1012
|
-
const props = stripBridgeKeys(raw);
|
|
1013
|
-
const edges = safeAreaEdges(props.safeArea);
|
|
1014
|
-
const hasSafeArea = edges.length > 0;
|
|
1015
|
-
const vis = props.visible !== void 0 && props.visible !== true ? { visible: props.visible } : {};
|
|
1016
|
-
const style = { flex: 1 };
|
|
1017
|
-
if (props.backgroundColor) style.backgroundColor = props.backgroundColor;
|
|
1018
|
-
let content;
|
|
1019
|
-
if (props.scrollable) {
|
|
1020
|
-
const paddingStyle = resolvePaddingRN(props.padding);
|
|
1021
|
-
const scrollNode = {
|
|
1022
|
-
id: `${id}__scroll`,
|
|
1023
|
-
type: "scrollview",
|
|
1024
|
-
props: {
|
|
1025
|
-
style: { flex: 1 },
|
|
1026
|
-
...Object.keys(paddingStyle).length ? { contentContainerStyle: paddingStyle } : {},
|
|
1027
|
-
showsVerticalScrollIndicator: false,
|
|
1028
|
-
showsHorizontalScrollIndicator: false
|
|
1029
|
-
},
|
|
1030
|
-
children
|
|
1031
|
-
};
|
|
1032
|
-
content = [scrollNode];
|
|
1033
|
-
} else {
|
|
1034
|
-
Object.assign(style, resolvePaddingRN(props.padding));
|
|
1035
|
-
content = children;
|
|
1036
|
-
}
|
|
1037
|
-
const statusBar = props.statusBarStyle && props.statusBarStyle !== "dark" ? { statusBarStyle: props.statusBarStyle } : {};
|
|
1038
|
-
const node = {
|
|
1039
|
-
id,
|
|
1040
|
-
type: hasSafeArea ? "safeareaview" : "view",
|
|
1041
|
-
props: {
|
|
1042
|
-
style,
|
|
1043
|
-
...hasSafeArea ? { edges } : {},
|
|
1044
|
-
...statusBar,
|
|
1045
|
-
...vis
|
|
1046
|
-
},
|
|
1047
|
-
children: content
|
|
1048
|
-
};
|
|
1049
|
-
if (condition !== void 0) node.if = condition;
|
|
1050
|
-
if (actions) node.actions = actions;
|
|
1051
|
-
return node;
|
|
1052
|
-
}
|
|
1053
|
-
function transformFrame(id, raw, children, parentDirection) {
|
|
1054
|
-
const { actions, condition } = extractMeta(raw);
|
|
1055
|
-
const p = stripBridgeKeys(raw);
|
|
1056
|
-
const isGrid = (p.type ?? "stack") === "grid";
|
|
1057
|
-
const isScrollable = p.scrollable === true;
|
|
1058
|
-
const isPressable = p.pressable === true;
|
|
1059
|
-
const direction = p.direction === "horizontal" ? "horizontal" : "vertical";
|
|
1060
|
-
const edges = safeAreaEdges(p.safeArea);
|
|
1061
|
-
const hasSafeArea = edges.length > 0;
|
|
1062
|
-
const access = resolveAccessibilityProps(p);
|
|
1063
|
-
const vis = p.visible !== void 0 && p.visible !== true ? { visible: p.visible } : {};
|
|
1064
|
-
const fullStyle = buildFrameStyle(p, parentDirection);
|
|
1065
|
-
const { outer: sizingStyle, inner: appearanceStyle } = splitFrameStyle(fullStyle);
|
|
1066
|
-
const { containerStyle: scrollOuter, contentStyle: scrollContent } = splitScrollStyle(fullStyle);
|
|
1067
|
-
function finalize(node) {
|
|
1068
|
-
if (condition !== void 0) node.if = condition;
|
|
1069
|
-
if (actions && node.type === "pressable") node.actions = actions;
|
|
1070
|
-
else if (actions && !isPressable) node.actions = actions;
|
|
1071
|
-
return node;
|
|
1072
|
-
}
|
|
1073
|
-
if (isGrid) {
|
|
1074
|
-
const gridStyle = { ...fullStyle, flexDirection: "row", flexWrap: "wrap" };
|
|
1075
|
-
delete gridStyle.gap;
|
|
1076
|
-
if (p.columnGap !== void 0) gridStyle.columnGap = p.columnGap;
|
|
1077
|
-
if (p.rowGap !== void 0) gridStyle.rowGap = p.rowGap;
|
|
1078
|
-
const gridView = {
|
|
1079
|
-
id: hasSafeArea || isPressable ? `${id}__grid` : id,
|
|
1080
|
-
type: "view",
|
|
1081
|
-
props: {
|
|
1082
|
-
...Object.keys(gridStyle).length ? { style: gridStyle } : {},
|
|
1083
|
-
numColumns: p.columns ?? 2,
|
|
1084
|
-
...access,
|
|
1085
|
-
...hasSafeArea || isPressable ? {} : vis
|
|
1086
|
-
},
|
|
1087
|
-
children
|
|
1088
|
-
};
|
|
1089
|
-
if (!hasSafeArea && !isPressable) return finalize(gridView);
|
|
1090
|
-
let inner = gridView;
|
|
1091
|
-
if (hasSafeArea) {
|
|
1092
|
-
inner = {
|
|
1093
|
-
id: isPressable ? `${id}__sav` : id,
|
|
1094
|
-
type: "safeareaview",
|
|
1095
|
-
props: { edges, ...isPressable ? {} : vis },
|
|
1096
|
-
children: [gridView]
|
|
1097
|
-
};
|
|
1098
|
-
}
|
|
1099
|
-
if (!isPressable) return finalize(inner);
|
|
1100
|
-
return finalize({
|
|
1101
|
-
id,
|
|
1102
|
-
type: "pressable",
|
|
1103
|
-
props: {
|
|
1104
|
-
...Object.keys(sizingStyle).length ? { style: sizingStyle } : {},
|
|
1105
|
-
...actions ? { actions } : {},
|
|
1106
|
-
...vis
|
|
1107
|
-
},
|
|
1108
|
-
children: [inner]
|
|
1109
|
-
});
|
|
1110
|
-
}
|
|
1111
|
-
if (isScrollable) {
|
|
1112
|
-
const scrollNode = {
|
|
1113
|
-
id: hasSafeArea || isPressable ? `${id}__scroll` : id,
|
|
1114
|
-
type: "scrollview",
|
|
1115
|
-
props: {
|
|
1116
|
-
...Object.keys(scrollOuter).length ? { style: scrollOuter } : {},
|
|
1117
|
-
...Object.keys(scrollContent).length ? { contentContainerStyle: scrollContent } : {},
|
|
1118
|
-
horizontal: direction === "horizontal",
|
|
1119
|
-
showsHorizontalScrollIndicator: p.showScrollIndicator === true,
|
|
1120
|
-
showsVerticalScrollIndicator: p.showScrollIndicator === true,
|
|
1121
|
-
...access,
|
|
1122
|
-
...hasSafeArea || isPressable ? {} : vis
|
|
1123
|
-
},
|
|
1124
|
-
children
|
|
1125
|
-
};
|
|
1126
|
-
if (!hasSafeArea && !isPressable) return finalize(scrollNode);
|
|
1127
|
-
let inner = scrollNode;
|
|
1128
|
-
if (hasSafeArea) {
|
|
1129
|
-
inner = {
|
|
1130
|
-
id: isPressable ? `${id}__sav` : id,
|
|
1131
|
-
type: "safeareaview",
|
|
1132
|
-
props: {
|
|
1133
|
-
edges,
|
|
1134
|
-
...Object.keys(sizingStyle).length ? { style: sizingStyle } : {},
|
|
1135
|
-
...isPressable ? {} : vis
|
|
1136
|
-
},
|
|
1137
|
-
children: [scrollNode]
|
|
1138
|
-
};
|
|
1139
|
-
}
|
|
1140
|
-
if (!isPressable) return finalize(inner);
|
|
1141
|
-
return finalize({
|
|
1142
|
-
id,
|
|
1143
|
-
type: "pressable",
|
|
1144
|
-
props: {
|
|
1145
|
-
...Object.keys(sizingStyle).length ? { style: sizingStyle } : {},
|
|
1146
|
-
...actions ? { actions } : {},
|
|
1147
|
-
...vis
|
|
1148
|
-
},
|
|
1149
|
-
children: [inner]
|
|
1150
|
-
});
|
|
1151
|
-
}
|
|
1152
|
-
if (!isPressable && !hasSafeArea) {
|
|
1153
|
-
return finalize({
|
|
1154
|
-
id,
|
|
1155
|
-
type: "view",
|
|
1156
|
-
props: {
|
|
1157
|
-
...Object.keys(fullStyle).length ? { style: fullStyle } : {},
|
|
1158
|
-
...access,
|
|
1159
|
-
...vis
|
|
1160
|
-
},
|
|
1161
|
-
children
|
|
1162
|
-
});
|
|
1163
|
-
}
|
|
1164
|
-
if (!isPressable && hasSafeArea) {
|
|
1165
|
-
return finalize({
|
|
1166
|
-
id,
|
|
1167
|
-
type: "safeareaview",
|
|
1168
|
-
props: {
|
|
1169
|
-
edges,
|
|
1170
|
-
...Object.keys(fullStyle).length ? { style: fullStyle } : {},
|
|
1171
|
-
...access,
|
|
1172
|
-
...vis
|
|
1173
|
-
},
|
|
1174
|
-
children
|
|
1175
|
-
});
|
|
1176
|
-
}
|
|
1177
|
-
const innerNode = hasSafeArea ? {
|
|
1178
|
-
id: `${id}__sav`,
|
|
1179
|
-
type: "safeareaview",
|
|
1180
|
-
props: {
|
|
1181
|
-
edges,
|
|
1182
|
-
...Object.keys(appearanceStyle).length ? { style: appearanceStyle } : {},
|
|
1183
|
-
...access
|
|
1184
|
-
},
|
|
1185
|
-
children
|
|
1186
|
-
} : {
|
|
1187
|
-
id: `${id}__content`,
|
|
1188
|
-
type: "view",
|
|
1189
|
-
props: {
|
|
1190
|
-
...Object.keys(appearanceStyle).length ? { style: appearanceStyle } : {},
|
|
1191
|
-
...access
|
|
1192
|
-
},
|
|
1193
|
-
children
|
|
1194
|
-
};
|
|
1195
|
-
return finalize({
|
|
1196
|
-
id,
|
|
1197
|
-
type: "pressable",
|
|
1198
|
-
props: {
|
|
1199
|
-
...Object.keys(sizingStyle).length ? { style: sizingStyle } : {},
|
|
1200
|
-
...actions ? { actions } : {},
|
|
1201
|
-
...vis
|
|
1202
|
-
},
|
|
1203
|
-
children: [innerNode]
|
|
1204
|
-
});
|
|
1205
|
-
}
|
|
1206
|
-
function transformText(id, raw, parentDirection) {
|
|
1207
|
-
const { actions, condition } = extractMeta(raw);
|
|
1208
|
-
const props = stripBridgeKeys(raw);
|
|
1209
|
-
const style = {};
|
|
1210
|
-
if (props.textStyle) {
|
|
1211
|
-
const preset = TEXT_STYLE_PRESETS[props.textStyle];
|
|
1212
|
-
if (preset) {
|
|
1213
|
-
style.fontSize = preset.fontSize;
|
|
1214
|
-
style.fontWeight = preset.fontWeight;
|
|
1215
|
-
if (preset.lineHeight !== void 0) style.lineHeight = preset.lineHeight;
|
|
1216
|
-
if (preset.textTransform) style.textTransform = preset.textTransform;
|
|
1217
|
-
if (preset.letterSpacing !== void 0) style.letterSpacing = preset.letterSpacing;
|
|
1218
|
-
}
|
|
1219
|
-
}
|
|
1220
|
-
if (props.color) style.color = props.color;
|
|
1221
|
-
if (props.fontSize !== void 0) style.fontSize = props.fontSize;
|
|
1222
|
-
if (props.fontWeight) style.fontWeight = FONT_WEIGHT_MAP[props.fontWeight] ?? props.fontWeight;
|
|
1223
|
-
if (props.fontFamily) style.fontFamily = props.fontFamily;
|
|
1224
|
-
if (props.fontStyle) style.fontStyle = props.fontStyle;
|
|
1225
|
-
if (props.lineHeight !== void 0) style.lineHeight = props.lineHeight;
|
|
1226
|
-
if (props.letterSpacing !== void 0) style.letterSpacing = props.letterSpacing;
|
|
1227
|
-
if (props.align) style.textAlign = props.align;
|
|
1228
|
-
if (props.transform && props.transform !== "none") style.textTransform = props.transform;
|
|
1229
|
-
if (props.decoration && props.decoration !== "none") style.textDecorationLine = props.decoration;
|
|
1230
|
-
if (props.opacity !== void 0) style.opacity = props.opacity / 100;
|
|
1231
|
-
Object.assign(style, resolvePositionRN(props));
|
|
1232
|
-
resolveSizeModeRN(props.width, "width", style, parentDirection);
|
|
1233
|
-
const textProps = {};
|
|
1234
|
-
if (typeof props.truncate === "number" && props.truncate > 0) {
|
|
1235
|
-
textProps.numberOfLines = props.truncate;
|
|
1236
|
-
textProps.ellipsizeMode = "tail";
|
|
1237
|
-
}
|
|
1238
|
-
if (props.adjustFontSize === true) {
|
|
1239
|
-
textProps.adjustsFontSizeToFit = true;
|
|
1240
|
-
if (props.minFontSize !== void 0) textProps.minimumFontScale = props.minFontSize;
|
|
1241
|
-
}
|
|
1242
|
-
if (props.selectable !== void 0) textProps.selectable = props.selectable;
|
|
1243
|
-
const node = {
|
|
1244
|
-
id,
|
|
1245
|
-
type: "text",
|
|
1246
|
-
props: {
|
|
1247
|
-
// SDK contract: text content lives in the `value` prop.
|
|
1248
|
-
// The Craft editor stores text in `content`; map it to `value` here.
|
|
1249
|
-
value: props.content ?? "",
|
|
1250
|
-
...Object.keys(style).length ? { style } : {},
|
|
1251
|
-
...textProps,
|
|
1252
|
-
...resolveAccessibilityProps(props),
|
|
1253
|
-
...props.visible !== void 0 && props.visible !== true ? { visible: props.visible } : {}
|
|
1254
|
-
}
|
|
1255
|
-
};
|
|
1256
|
-
if (condition !== void 0) node.if = condition;
|
|
1257
|
-
if (actions) node.actions = actions;
|
|
1258
|
-
return node;
|
|
1259
|
-
}
|
|
1260
|
-
function transformImage(id, raw, children, parentDirection) {
|
|
1261
|
-
const { actions, condition } = extractMeta(raw);
|
|
1262
|
-
const props = stripBridgeKeys(raw);
|
|
1263
|
-
const style = {};
|
|
1264
|
-
resolveSizeModeRN(props.width, "width", style, parentDirection);
|
|
1265
|
-
resolveSizeModeRN(props.height, "height", style, parentDirection);
|
|
1266
|
-
if (props.aspectRatio !== void 0) style.aspectRatio = props.aspectRatio;
|
|
1267
|
-
Object.assign(style, resolveRadiusRN(props.radius));
|
|
1268
|
-
if (props.opacity !== void 0) style.opacity = props.opacity / 100;
|
|
1269
|
-
Object.assign(style, resolvePositionRN(props));
|
|
1270
|
-
const imageProps = {};
|
|
1271
|
-
if (props.src) imageProps.source = { uri: props.src };
|
|
1272
|
-
if (props.placeholder) imageProps.defaultSource = { uri: props.placeholder };
|
|
1273
|
-
if (props.fallback) imageProps.fallback = { uri: props.fallback };
|
|
1274
|
-
imageProps.resizeMode = FIT_TO_RESIZE_MODE[props.fit ?? "cover"] ?? "cover";
|
|
1275
|
-
if (props.background === true) imageProps.background = true;
|
|
1276
|
-
if (props.decorative) {
|
|
1277
|
-
imageProps.accessible = false;
|
|
1278
|
-
imageProps.accessibilityElementsHidden = true;
|
|
1279
|
-
} else if (props.alt) {
|
|
1280
|
-
imageProps.accessible = true;
|
|
1281
|
-
imageProps.accessibilityLabel = props.alt;
|
|
1282
|
-
}
|
|
1283
|
-
if (props.testID) imageProps.testID = props.testID;
|
|
1284
|
-
const node = {
|
|
1285
|
-
id,
|
|
1286
|
-
type: "image",
|
|
1287
|
-
props: {
|
|
1288
|
-
...Object.keys(style).length ? { style } : {},
|
|
1289
|
-
...imageProps,
|
|
1290
|
-
...props.visible !== void 0 && props.visible !== true ? { visible: props.visible } : {}
|
|
1291
|
-
},
|
|
1292
|
-
...props.background === true && children.length ? { children } : {}
|
|
1293
|
-
};
|
|
1294
|
-
if (condition !== void 0) node.if = condition;
|
|
1295
|
-
if (actions) node.actions = actions;
|
|
1296
|
-
return node;
|
|
1297
|
-
}
|
|
1298
|
-
function transformInput(id, raw, parentDirection) {
|
|
1299
|
-
const { actions, condition } = extractMeta(raw);
|
|
1300
|
-
const props = stripBridgeKeys(raw);
|
|
1301
|
-
const style = {};
|
|
1302
|
-
resolveSizeModeRN(props.width ?? "fill", "width", style, parentDirection);
|
|
1303
|
-
Object.assign(style, resolvePaddingRN(props.padding));
|
|
1304
|
-
if (props.opacity !== void 0) style.opacity = props.opacity / 100;
|
|
1305
|
-
Object.assign(style, resolvePositionRN(props));
|
|
1306
|
-
const inputTypeDefaults = INPUT_TYPE_MAP[props.inputType ?? "text"] ?? INPUT_TYPE_MAP.text;
|
|
1307
|
-
const node = {
|
|
1308
|
-
id,
|
|
1309
|
-
type: "textinput",
|
|
1310
|
-
props: {
|
|
1311
|
-
...Object.keys(style).length ? { style } : {},
|
|
1312
|
-
...props.label !== void 0 ? { label: props.label } : {},
|
|
1313
|
-
...props.placeholder !== void 0 ? { placeholder: props.placeholder } : {},
|
|
1314
|
-
...props.value !== void 0 ? { value: props.value } : {},
|
|
1315
|
-
...props.helperText !== void 0 ? { helperText: props.helperText } : {},
|
|
1316
|
-
...props.errorText !== void 0 ? { errorText: props.errorText } : {},
|
|
1317
|
-
...inputTypeDefaults,
|
|
1318
|
-
...props.autoCapitalize ? { autoCapitalize: props.autoCapitalize } : {},
|
|
1319
|
-
returnKeyType: props.returnKey ?? "done",
|
|
1320
|
-
multiline: props.multiline ?? false,
|
|
1321
|
-
...props.multiline && props.minLines ? { numberOfLines: props.minLines } : {},
|
|
1322
|
-
...props.multiline && props.maxLines ? { maxNumberOfLines: props.maxLines } : {},
|
|
1323
|
-
variant: props.variant ?? "outline",
|
|
1324
|
-
size: props.size ?? "md",
|
|
1325
|
-
...props.leadingIcon ? { leadingIcon: props.leadingIcon } : {},
|
|
1326
|
-
...props.trailingIcon ? { trailingIcon: props.trailingIcon } : {},
|
|
1327
|
-
...resolveAccessibilityProps(props),
|
|
1328
|
-
...props.visible !== void 0 && props.visible !== true ? { visible: props.visible } : {}
|
|
1329
|
-
}
|
|
1330
|
-
};
|
|
1331
|
-
if (condition !== void 0) node.if = condition;
|
|
1332
|
-
if (actions) node.actions = actions;
|
|
1333
|
-
return node;
|
|
1334
|
-
}
|
|
1335
|
-
function transformList(id, raw, children, parentDirection) {
|
|
1336
|
-
const { actions, condition } = extractMeta(raw);
|
|
1337
|
-
const props = stripBridgeKeys(raw);
|
|
1338
|
-
const listType = props.type ?? "stack";
|
|
1339
|
-
const direction = props.direction === "horizontal" ? "horizontal" : "vertical";
|
|
1340
|
-
const edges = safeAreaEdges(props.safeArea);
|
|
1341
|
-
const hasSafeArea = edges.length > 0;
|
|
1342
|
-
const vis = props.visible !== void 0 && props.visible !== true ? { visible: props.visible } : {};
|
|
1343
|
-
const fullStyle = buildFrameStyle(props, parentDirection);
|
|
1344
|
-
const { containerStyle, contentStyle } = splitScrollStyle(fullStyle);
|
|
1345
|
-
let itemTemplate;
|
|
1346
|
-
if (children.length === 1) {
|
|
1347
|
-
itemTemplate = children[0];
|
|
1348
|
-
} else if (children.length > 1) {
|
|
1349
|
-
itemTemplate = { id: `${id}__template`, type: "view", props: {}, children };
|
|
1350
|
-
}
|
|
1351
|
-
const flatlistNode = {
|
|
1352
|
-
id: hasSafeArea ? `${id}__list` : id,
|
|
1353
|
-
type: "flatlist",
|
|
1354
|
-
props: {
|
|
1355
|
-
...Object.keys(containerStyle).length ? { style: containerStyle } : {},
|
|
1356
|
-
...Object.keys(contentStyle).length ? { contentContainerStyle: contentStyle } : {},
|
|
1357
|
-
// `data` holds the binding expression for the list items array.
|
|
1358
|
-
// RecursiveRenderer resolves it and passes items to the FlatList primitive.
|
|
1359
|
-
data: props.data,
|
|
1360
|
-
keyExtractor: props.keyExtractor ?? "id",
|
|
1361
|
-
...listType === "grid" ? { numColumns: props.columns ?? 2 } : {},
|
|
1362
|
-
...listType === "grid" && props.columnGap ? { columnGap: props.columnGap } : {},
|
|
1363
|
-
...listType === "grid" && props.rowGap ? { rowGap: props.rowGap } : {},
|
|
1364
|
-
horizontal: direction === "horizontal",
|
|
1365
|
-
showsHorizontalScrollIndicator: props.showScrollIndicator === true,
|
|
1366
|
-
showsVerticalScrollIndicator: props.showScrollIndicator === true,
|
|
1367
|
-
...resolveAccessibilityProps(props),
|
|
1368
|
-
...hasSafeArea ? {} : vis
|
|
1369
|
-
},
|
|
1370
|
-
...itemTemplate ? { itemTemplate } : {}
|
|
1371
|
-
};
|
|
1372
|
-
if (!hasSafeArea) {
|
|
1373
|
-
if (condition !== void 0) flatlistNode.if = condition;
|
|
1374
|
-
if (actions) flatlistNode.actions = actions;
|
|
1375
|
-
return flatlistNode;
|
|
1376
|
-
}
|
|
1377
|
-
const { outer: sizingStyle } = splitFrameStyle(fullStyle);
|
|
1378
|
-
const savNode = {
|
|
1379
|
-
id,
|
|
1380
|
-
type: "safeareaview",
|
|
1381
|
-
props: {
|
|
1382
|
-
edges,
|
|
1383
|
-
...Object.keys(sizingStyle).length ? { style: sizingStyle } : {},
|
|
1384
|
-
...vis
|
|
1385
|
-
},
|
|
1386
|
-
children: [flatlistNode]
|
|
1387
|
-
};
|
|
1388
|
-
if (condition !== void 0) savNode.if = condition;
|
|
1389
|
-
if (actions) savNode.actions = actions;
|
|
1390
|
-
return savNode;
|
|
1391
|
-
}
|
|
1392
|
-
function transformIcon(id, raw) {
|
|
1393
|
-
const { actions, condition } = extractMeta(raw);
|
|
1394
|
-
const props = stripBridgeKeys(raw);
|
|
1395
|
-
const style = {};
|
|
1396
|
-
if (props.opacity !== void 0) style.opacity = props.opacity / 100;
|
|
1397
|
-
Object.assign(style, resolvePositionRN(props));
|
|
1398
|
-
const node = {
|
|
1399
|
-
id,
|
|
1400
|
-
type: "icon",
|
|
1401
|
-
props: {
|
|
1402
|
-
name: props.name,
|
|
1403
|
-
set: props.set ?? "default",
|
|
1404
|
-
size: props.size ?? 24,
|
|
1405
|
-
...props.color ? { color: props.color } : {},
|
|
1406
|
-
...Object.keys(style).length ? { style } : {},
|
|
1407
|
-
...resolveAccessibilityProps(props),
|
|
1408
|
-
...props.visible !== void 0 && props.visible !== true ? { visible: props.visible } : {}
|
|
1409
|
-
}
|
|
1410
|
-
};
|
|
1411
|
-
if (condition !== void 0) node.if = condition;
|
|
1412
|
-
if (actions) node.actions = actions;
|
|
1413
|
-
return node;
|
|
1414
|
-
}
|
|
1415
|
-
function buildNodeFromSchema(nodeId, schema, customComponents, visited, parentId) {
|
|
1416
|
-
if (visited.has(nodeId)) {
|
|
1417
|
-
throw new Error(`Circular reference detected at node ${nodeId}`);
|
|
1418
|
-
}
|
|
1419
|
-
visited.add(nodeId);
|
|
1420
|
-
const node = schema[nodeId];
|
|
1421
|
-
if (!node) throw new Error(`Node not found: ${nodeId}`);
|
|
1422
|
-
const resolvedName = node.type?.resolvedName;
|
|
1423
|
-
if (!resolvedName) throw new Error(`Invalid node type at ${nodeId}`);
|
|
1424
|
-
const raw = node.props ?? {};
|
|
1425
|
-
const parentDirection = parentId ? schema[parentId]?.props?.["direction"] === "horizontal" ? "horizontal" : "vertical" : "vertical";
|
|
1426
|
-
const outputId = nodeId === "ROOT" ? "root" : nodeId;
|
|
1427
|
-
const childNodes = (node.nodes ?? []).map(
|
|
1428
|
-
(childId) => buildNodeFromSchema(childId, schema, customComponents, visited, nodeId)
|
|
1429
|
-
);
|
|
1430
|
-
switch (resolvedName) {
|
|
1431
|
-
case "PF.Screen":
|
|
1432
|
-
return transformScreen(outputId, raw, childNodes);
|
|
1433
|
-
case "PF.Frame":
|
|
1434
|
-
return transformFrame(outputId, raw, childNodes, parentDirection);
|
|
1435
|
-
case "PF.Text":
|
|
1436
|
-
return transformText(outputId, raw, parentDirection);
|
|
1437
|
-
case "PF.Image":
|
|
1438
|
-
return transformImage(outputId, raw, childNodes, parentDirection);
|
|
1439
|
-
case "PF.Input":
|
|
1440
|
-
return transformInput(outputId, raw, parentDirection);
|
|
1441
|
-
case "PF.List":
|
|
1442
|
-
return transformList(outputId, raw, childNodes, parentDirection);
|
|
1443
|
-
case "PF.Icon":
|
|
1444
|
-
return transformIcon(outputId, raw);
|
|
1445
|
-
case "Component":
|
|
1446
|
-
return resolveCustomComponent(outputId, raw, parentDirection, customComponents);
|
|
1447
|
-
default:
|
|
1448
|
-
return { id: outputId, type: "view", props: {}, children: childNodes };
|
|
1449
|
-
}
|
|
1450
|
-
}
|
|
1451
|
-
function resolveCustomComponent(id, raw, parentDirection, customComponents) {
|
|
1452
|
-
const { actions, condition } = extractMeta(raw);
|
|
1453
|
-
const props = stripBridgeKeys(raw);
|
|
1454
|
-
const { componentId, componentKey, propValues, ...frameProps } = props;
|
|
1455
|
-
const key = componentKey ?? componentId;
|
|
1456
|
-
const def = key ? customComponents[key] : void 0;
|
|
1457
|
-
const wrapperStyle = buildFrameStyle(frameProps, parentDirection);
|
|
1458
|
-
const vis = props.visible !== void 0 && props.visible !== true ? { visible: props.visible } : {};
|
|
1459
|
-
if (!def) {
|
|
1460
|
-
return {
|
|
1461
|
-
id,
|
|
1462
|
-
type: "view",
|
|
1463
|
-
props: { ...Object.keys(wrapperStyle).length ? { style: wrapperStyle } : {}, ...vis },
|
|
1464
|
-
children: []
|
|
1465
|
-
};
|
|
1466
|
-
}
|
|
1467
|
-
const componentVisited = /* @__PURE__ */ new Set();
|
|
1468
|
-
const componentRoot = buildNodeFromSchema(
|
|
1469
|
-
def.rootNodeId,
|
|
1470
|
-
def.nodes,
|
|
1471
|
-
customComponents,
|
|
1472
|
-
componentVisited
|
|
1473
|
-
);
|
|
1474
|
-
if (propValues && Object.keys(propValues).length) {
|
|
1475
|
-
componentRoot.props = { ...componentRoot.props, _propValues: propValues };
|
|
1476
|
-
}
|
|
1477
|
-
if (Object.keys(wrapperStyle).length > 0) {
|
|
1478
|
-
const wrapper = {
|
|
1479
|
-
id,
|
|
1480
|
-
type: "view",
|
|
1481
|
-
props: { style: wrapperStyle, ...vis },
|
|
1482
|
-
children: [componentRoot]
|
|
1483
|
-
};
|
|
1484
|
-
if (condition !== void 0) wrapper.if = condition;
|
|
1485
|
-
if (actions) wrapper.actions = actions;
|
|
1486
|
-
return wrapper;
|
|
1487
|
-
}
|
|
1488
|
-
componentRoot.id = id;
|
|
1489
|
-
componentRoot.props = { ...componentRoot.props, ...vis };
|
|
1490
|
-
if (condition !== void 0) componentRoot.if = condition;
|
|
1491
|
-
if (actions) componentRoot.actions = actions;
|
|
1492
|
-
return componentRoot;
|
|
1493
|
-
}
|
|
1494
|
-
function transformCraftToSDUI(craftJson, customComponents = {}) {
|
|
1495
|
-
if (!craftJson || typeof craftJson !== "object") {
|
|
1496
|
-
throw new Error("Invalid craft schema");
|
|
1497
|
-
}
|
|
1498
|
-
const visited = /* @__PURE__ */ new Set();
|
|
1499
|
-
return buildNodeFromSchema("ROOT", craftJson, customComponents, visited);
|
|
1500
|
-
}
|
|
1501
|
-
|
|
1502
|
-
// src/index.ts
|
|
1503
|
-
var PushFrame = {
|
|
1504
|
-
// Slot components
|
|
1505
|
-
Provider: PushFrameProvider,
|
|
1506
|
-
Screen: PushFrameScreen,
|
|
1507
|
-
Component: PushFrameComponent,
|
|
1508
|
-
// Primitives
|
|
1509
|
-
Text,
|
|
1510
|
-
View,
|
|
1511
|
-
ScrollView,
|
|
1512
|
-
Image,
|
|
1513
|
-
Pressable,
|
|
1514
|
-
TextInput,
|
|
1515
|
-
FlatList,
|
|
1516
|
-
Modal,
|
|
1517
|
-
ActivityIndicator,
|
|
1518
|
-
Switch,
|
|
1519
|
-
KeyboardAvoidingView,
|
|
1520
|
-
SafeAreaView,
|
|
1521
|
-
StatusBar
|
|
1522
|
-
};
|
|
1523
|
-
|
|
1524
|
-
export { ActivityIndicator, ComponentRegistry, FlatList, Image, KeyboardAvoidingView, Modal, Pressable, PushFrame, PushFrameComponent, PushFrameContext, PushFrameProvider, PushFrameScreen, RecursiveRenderer, SafeAreaView, ScrollView, StatusBar, Switch, Text, TextInput, View, evaluateIf, resolveDeep, resolveProps, resolveValue, transformCraftToSDUI, usePushFrameContext };
|
|
1525
|
-
//# sourceMappingURL=index.mjs.map
|
|
1526
|
-
//# sourceMappingURL=index.mjs.map
|