@pushframe/sdk 0.1.1 → 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.d.ts +89 -13
- package/dist/index.js +810 -26
- package/dist/index.js.map +1 -1
- package/package.json +14 -12
- package/dist/index.d.mts +0 -458
- package/dist/index.mjs +0 -758
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -22,8 +22,18 @@ function usePushFrameContext() {
|
|
|
22
22
|
}
|
|
23
23
|
return ctx;
|
|
24
24
|
}
|
|
25
|
-
function Text({
|
|
26
|
-
|
|
25
|
+
function Text({
|
|
26
|
+
if: _if,
|
|
27
|
+
actions: _actions,
|
|
28
|
+
value,
|
|
29
|
+
content,
|
|
30
|
+
...rest
|
|
31
|
+
}) {
|
|
32
|
+
const textContent = value !== void 0 ? value : content;
|
|
33
|
+
if (textContent !== void 0) {
|
|
34
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { ...rest, children: textContent });
|
|
35
|
+
}
|
|
36
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { ...rest });
|
|
27
37
|
}
|
|
28
38
|
function View({ if: _if, actions: _actions, ...rest }) {
|
|
29
39
|
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { ...rest });
|
|
@@ -32,7 +42,7 @@ var ScrollView = React4.forwardRef(function ScrollView2({ if: _if, actions: _act
|
|
|
32
42
|
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.ScrollView, { ref, ...rest });
|
|
33
43
|
});
|
|
34
44
|
function Image({ if: _if, actions: _actions, src, source, ...rest }) {
|
|
35
|
-
const resolvedSource = src ? { uri: src } : source
|
|
45
|
+
const resolvedSource = src ? { uri: src } : source != null ? source : { uri: "" };
|
|
36
46
|
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Image, { source: resolvedSource, ...rest });
|
|
37
47
|
}
|
|
38
48
|
function Pressable({ if: _if, actions: _actions, ...rest }) {
|
|
@@ -156,7 +166,8 @@ var ComponentRegistry = class {
|
|
|
156
166
|
* Returns null if no component is registered for the type.
|
|
157
167
|
*/
|
|
158
168
|
resolve(type) {
|
|
159
|
-
|
|
169
|
+
var _a;
|
|
170
|
+
return (_a = this.components.get(type)) != null ? _a : null;
|
|
160
171
|
}
|
|
161
172
|
/**
|
|
162
173
|
* Returns all registered type strings (useful for debugging).
|
|
@@ -172,6 +183,7 @@ var TYPE_COLORS = {
|
|
|
172
183
|
warning: "#f59e0b"
|
|
173
184
|
};
|
|
174
185
|
var ToastHost = React4.forwardRef(function ToastHost2(_props, ref) {
|
|
186
|
+
var _a, _b;
|
|
175
187
|
const [toast, setToast] = React4.useState(null);
|
|
176
188
|
const opacity = React4.useRef(new reactNative.Animated.Value(0)).current;
|
|
177
189
|
const idRef = React4.useRef(0);
|
|
@@ -202,12 +214,13 @@ var ToastHost = React4.forwardRef(function ToastHost2(_props, ref) {
|
|
|
202
214
|
ref,
|
|
203
215
|
() => ({
|
|
204
216
|
show(payload) {
|
|
217
|
+
var _a2, _b2;
|
|
205
218
|
idRef.current += 1;
|
|
206
219
|
setToast({
|
|
207
220
|
id: idRef.current,
|
|
208
221
|
message: payload.message,
|
|
209
|
-
duration: payload.duration
|
|
210
|
-
type: payload.type
|
|
222
|
+
duration: (_a2 = payload.duration) != null ? _a2 : 3e3,
|
|
223
|
+
type: (_b2 = payload.type) != null ? _b2 : "info"
|
|
211
224
|
});
|
|
212
225
|
opacity.setValue(0);
|
|
213
226
|
}
|
|
@@ -215,7 +228,7 @@ var ToastHost = React4.forwardRef(function ToastHost2(_props, ref) {
|
|
|
215
228
|
[opacity]
|
|
216
229
|
);
|
|
217
230
|
if (!toast) return null;
|
|
218
|
-
const backgroundColor = TYPE_COLORS[toast.type
|
|
231
|
+
const backgroundColor = (_b = TYPE_COLORS[(_a = toast.type) != null ? _a : "info"]) != null ? _b : TYPE_COLORS.info;
|
|
219
232
|
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
233
|
});
|
|
221
234
|
var styles = reactNative.StyleSheet.create({
|
|
@@ -265,7 +278,7 @@ var BottomSheetHost = React4.forwardRef(
|
|
|
265
278
|
duration: 250,
|
|
266
279
|
useNativeDriver: true
|
|
267
280
|
}).start(() => {
|
|
268
|
-
onDone
|
|
281
|
+
onDone == null ? void 0 : onDone();
|
|
269
282
|
});
|
|
270
283
|
},
|
|
271
284
|
[translateY]
|
|
@@ -372,7 +385,7 @@ function resolveValue(value, context) {
|
|
|
372
385
|
return value;
|
|
373
386
|
}
|
|
374
387
|
const fullMatch = FULL_BINDING_RE.exec(value);
|
|
375
|
-
if (fullMatch
|
|
388
|
+
if ((fullMatch == null ? void 0 : fullMatch[1]) !== void 0) {
|
|
376
389
|
return evaluateExpression(fullMatch[1].trim(), context);
|
|
377
390
|
}
|
|
378
391
|
if (INLINE_BINDING_RE.test(value)) {
|
|
@@ -408,7 +421,8 @@ function resolveDeep(value, context) {
|
|
|
408
421
|
|
|
409
422
|
// src/renderer/conditionalEvaluator.ts
|
|
410
423
|
function evaluateIf(ifExpr, context) {
|
|
411
|
-
if (ifExpr === void 0) return true;
|
|
424
|
+
if (ifExpr === void 0 || ifExpr === null) return true;
|
|
425
|
+
if (typeof ifExpr !== "string") return Boolean(ifExpr);
|
|
412
426
|
const resolved = resolveValue(ifExpr, context);
|
|
413
427
|
return Boolean(resolved);
|
|
414
428
|
}
|
|
@@ -435,9 +449,18 @@ function buildActionProps(actions, context, dispatchAction) {
|
|
|
435
449
|
}
|
|
436
450
|
function renderFlatListNode(node, context, registry, dispatchAction, fallbackComponent) {
|
|
437
451
|
const resolvedProps = resolveProps(node.props, context);
|
|
438
|
-
const items = Array.isArray(resolvedProps["items"]) ? resolvedProps["items"] : [];
|
|
439
452
|
const actionProps = node.actions ? buildActionProps(node.actions, context, dispatchAction) : {};
|
|
440
|
-
const {
|
|
453
|
+
const {
|
|
454
|
+
data: resolvedData,
|
|
455
|
+
items: resolvedItems,
|
|
456
|
+
keyExtractor: keyExtractorExpr,
|
|
457
|
+
direction,
|
|
458
|
+
numColumns,
|
|
459
|
+
visible: _visible,
|
|
460
|
+
_propValues: _pv,
|
|
461
|
+
...restProps
|
|
462
|
+
} = resolvedProps;
|
|
463
|
+
const items = Array.isArray(resolvedData) ? resolvedData : Array.isArray(resolvedItems) ? resolvedItems : [];
|
|
441
464
|
let keyExtractorFn;
|
|
442
465
|
if (typeof keyExtractorExpr === "string") {
|
|
443
466
|
const extractorExpr = keyExtractorExpr;
|
|
@@ -452,7 +475,7 @@ function renderFlatListNode(node, context, registry, dispatchAction, fallbackCom
|
|
|
452
475
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
453
476
|
RecursiveRenderer,
|
|
454
477
|
{
|
|
455
|
-
node: node.
|
|
478
|
+
node: node.itemTemplate,
|
|
456
479
|
context: itemContext,
|
|
457
480
|
registry,
|
|
458
481
|
dispatchAction,
|
|
@@ -496,6 +519,16 @@ function RecursiveRenderer({
|
|
|
496
519
|
);
|
|
497
520
|
}
|
|
498
521
|
const resolvedProps = resolveProps(node.props, context);
|
|
522
|
+
if (resolvedProps.visible !== void 0 && !resolvedProps.visible) {
|
|
523
|
+
return null;
|
|
524
|
+
}
|
|
525
|
+
const {
|
|
526
|
+
visible: _visible,
|
|
527
|
+
_propValues: propValuesRaw,
|
|
528
|
+
...propsToForward
|
|
529
|
+
} = resolvedProps;
|
|
530
|
+
const propValues = propValuesRaw;
|
|
531
|
+
const childContext = propValues && Object.keys(propValues).length > 0 ? { ...context, ...propValues } : context;
|
|
499
532
|
const actionProps = node.actions ? buildActionProps(node.actions, context, dispatchAction) : {};
|
|
500
533
|
const Component = registry.resolve(node.type);
|
|
501
534
|
if (!Component) {
|
|
@@ -508,7 +541,7 @@ function RecursiveRenderer({
|
|
|
508
541
|
RecursiveRenderer,
|
|
509
542
|
{
|
|
510
543
|
node: child,
|
|
511
|
-
context,
|
|
544
|
+
context: childContext,
|
|
512
545
|
registry,
|
|
513
546
|
dispatchAction,
|
|
514
547
|
fallbackComponent
|
|
@@ -516,7 +549,7 @@ function RecursiveRenderer({
|
|
|
516
549
|
`${child.type}-${index}`
|
|
517
550
|
)) : void 0;
|
|
518
551
|
return React4__default.default.createElement(Component, {
|
|
519
|
-
...
|
|
552
|
+
...propsToForward,
|
|
520
553
|
...actionProps,
|
|
521
554
|
children
|
|
522
555
|
});
|
|
@@ -542,13 +575,16 @@ function PushFrameProvider({
|
|
|
542
575
|
const toastRef = React4.useRef(null);
|
|
543
576
|
const bottomSheetRef = React4.useRef(null);
|
|
544
577
|
const showToast = React4.useCallback((payload) => {
|
|
545
|
-
|
|
578
|
+
var _a;
|
|
579
|
+
(_a = toastRef.current) == null ? void 0 : _a.show(payload);
|
|
546
580
|
}, []);
|
|
547
581
|
const showBottomSheet = React4.useCallback((payload) => {
|
|
548
|
-
|
|
582
|
+
var _a;
|
|
583
|
+
(_a = bottomSheetRef.current) == null ? void 0 : _a.show(payload);
|
|
549
584
|
}, []);
|
|
550
585
|
const dismissBottomSheet = React4.useCallback(() => {
|
|
551
|
-
|
|
586
|
+
var _a;
|
|
587
|
+
(_a = bottomSheetRef.current) == null ? void 0 : _a.dismiss();
|
|
552
588
|
}, []);
|
|
553
589
|
const renderBottomSheetContent = React4.useCallback(
|
|
554
590
|
(schema, sheetContext) => {
|
|
@@ -562,7 +598,7 @@ function PushFrameProvider({
|
|
|
562
598
|
showToast(payload);
|
|
563
599
|
return;
|
|
564
600
|
}
|
|
565
|
-
onAction
|
|
601
|
+
onAction == null ? void 0 : onAction(action, payload);
|
|
566
602
|
};
|
|
567
603
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
568
604
|
RecursiveRenderer,
|
|
@@ -614,6 +650,7 @@ function PushFrameProvider({
|
|
|
614
650
|
] });
|
|
615
651
|
}
|
|
616
652
|
async function fetchSchema(baseUrl, apiKey, path) {
|
|
653
|
+
var _a;
|
|
617
654
|
const url = new URL(path, baseUrl + "/").toString();
|
|
618
655
|
const headers = {
|
|
619
656
|
Accept: "application/json",
|
|
@@ -625,7 +662,7 @@ async function fetchSchema(baseUrl, apiKey, path) {
|
|
|
625
662
|
throw new Error(`[PushFrame] HTTP ${res.status} fetching "${path}"`);
|
|
626
663
|
}
|
|
627
664
|
const envelope = await res.json();
|
|
628
|
-
return envelope.schema
|
|
665
|
+
return (_a = envelope.schema) != null ? _a : envelope;
|
|
629
666
|
}
|
|
630
667
|
function PushFrameComponentInternal({
|
|
631
668
|
id,
|
|
@@ -654,7 +691,7 @@ function PushFrameComponentInternal({
|
|
|
654
691
|
const [schema, setSchema] = React4.useState(null);
|
|
655
692
|
const [fetchError, setFetchError] = React4.useState(null);
|
|
656
693
|
const [isFetching, setIsFetching] = React4.useState(true);
|
|
657
|
-
const fetchPath = `${resourceType}/${encodeURIComponent(id)}/${encodeURIComponent(appVersion
|
|
694
|
+
const fetchPath = `${resourceType}/${encodeURIComponent(id)}/${encodeURIComponent(appVersion != null ? appVersion : "null")}`;
|
|
658
695
|
const mergedContext = slotContext ? { ...globalContext, ...slotContext } : globalContext;
|
|
659
696
|
const loadingUI = slotLoading !== void 0 ? slotLoading : providerLoading;
|
|
660
697
|
const fallbackUI = slotFallback !== void 0 ? slotFallback : providerFallback;
|
|
@@ -673,7 +710,7 @@ function PushFrameComponentInternal({
|
|
|
673
710
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
674
711
|
setFetchError(error);
|
|
675
712
|
setIsFetching(false);
|
|
676
|
-
onError
|
|
713
|
+
onError == null ? void 0 : onError(error);
|
|
677
714
|
}
|
|
678
715
|
});
|
|
679
716
|
return () => {
|
|
@@ -697,18 +734,18 @@ function PushFrameComponentInternal({
|
|
|
697
734
|
if (action === "scroll-to") {
|
|
698
735
|
return;
|
|
699
736
|
}
|
|
700
|
-
const stopped = slotOnAction
|
|
737
|
+
const stopped = slotOnAction == null ? void 0 : slotOnAction(action, payload);
|
|
701
738
|
if (stopped) return;
|
|
702
|
-
providerOnAction
|
|
739
|
+
providerOnAction == null ? void 0 : providerOnAction(action, payload);
|
|
703
740
|
},
|
|
704
741
|
[showToast, showBottomSheet, dismissBottomSheet, slotOnAction, providerOnAction]
|
|
705
742
|
);
|
|
706
743
|
const isShowingLoader = externalLoading || isFetching;
|
|
707
744
|
if (isShowingLoader) {
|
|
708
|
-
return loadingUI
|
|
745
|
+
return loadingUI != null ? loadingUI : null;
|
|
709
746
|
}
|
|
710
747
|
if (fetchError || !schema) {
|
|
711
|
-
return fallbackUI
|
|
748
|
+
return fallbackUI != null ? fallbackUI : null;
|
|
712
749
|
}
|
|
713
750
|
const rendered = /* @__PURE__ */ jsxRuntime.jsx(
|
|
714
751
|
RecursiveRenderer,
|
|
@@ -737,6 +774,752 @@ var styles3 = reactNative.StyleSheet.create({
|
|
|
737
774
|
}
|
|
738
775
|
});
|
|
739
776
|
|
|
777
|
+
// src/transformer/index.ts
|
|
778
|
+
var BRIDGE_KEYS = /* @__PURE__ */ new Set([
|
|
779
|
+
"_schemaId",
|
|
780
|
+
"_schemaType",
|
|
781
|
+
"_schemaActions",
|
|
782
|
+
"_schemaIf",
|
|
783
|
+
"_schemaRenderItem"
|
|
784
|
+
]);
|
|
785
|
+
var ALIGN_MAP = {
|
|
786
|
+
start: "flex-start",
|
|
787
|
+
center: "center",
|
|
788
|
+
end: "flex-end",
|
|
789
|
+
stretch: "stretch",
|
|
790
|
+
baseline: "baseline"
|
|
791
|
+
};
|
|
792
|
+
var DISTRIBUTE_MAP = {
|
|
793
|
+
start: "flex-start",
|
|
794
|
+
center: "center",
|
|
795
|
+
end: "flex-end",
|
|
796
|
+
"space-between": "space-between",
|
|
797
|
+
"space-around": "space-around",
|
|
798
|
+
"space-evenly": "space-evenly"
|
|
799
|
+
};
|
|
800
|
+
var FIT_TO_RESIZE_MODE = {
|
|
801
|
+
cover: "cover",
|
|
802
|
+
contain: "contain",
|
|
803
|
+
fill: "stretch",
|
|
804
|
+
// RN uses 'stretch', not 'fill'
|
|
805
|
+
center: "center"
|
|
806
|
+
};
|
|
807
|
+
var FONT_WEIGHT_MAP = {
|
|
808
|
+
regular: "400",
|
|
809
|
+
medium: "500",
|
|
810
|
+
semibold: "600",
|
|
811
|
+
bold: "700"
|
|
812
|
+
};
|
|
813
|
+
var TEXT_STYLE_PRESETS = {
|
|
814
|
+
"heading-1": { fontSize: 28, fontWeight: "700" },
|
|
815
|
+
"heading-2": { fontSize: 22, fontWeight: "700" },
|
|
816
|
+
"heading-3": { fontSize: 18, fontWeight: "600" },
|
|
817
|
+
"body": { fontSize: 16, fontWeight: "400" },
|
|
818
|
+
"body-sm": { fontSize: 14, fontWeight: "400" },
|
|
819
|
+
"caption": { fontSize: 12, fontWeight: "400" },
|
|
820
|
+
"label": { fontSize: 13, fontWeight: "500" },
|
|
821
|
+
"overline": { fontSize: 11, fontWeight: "500", textTransform: "uppercase", letterSpacing: 0.8 }
|
|
822
|
+
};
|
|
823
|
+
var INPUT_TYPE_MAP = {
|
|
824
|
+
text: { keyboardType: "default", secureTextEntry: false, autoCapitalize: "sentences", autoCorrect: true },
|
|
825
|
+
email: { keyboardType: "email-address", secureTextEntry: false, autoCapitalize: "none", autoCorrect: false },
|
|
826
|
+
password: { keyboardType: "default", secureTextEntry: true, autoCapitalize: "none", autoCorrect: false },
|
|
827
|
+
number: { keyboardType: "numeric", secureTextEntry: false, autoCapitalize: "none", autoCorrect: false },
|
|
828
|
+
decimal: { keyboardType: "decimal-pad", secureTextEntry: false, autoCapitalize: "none", autoCorrect: false },
|
|
829
|
+
phone: { keyboardType: "phone-pad", secureTextEntry: false, autoCapitalize: "none", autoCorrect: false },
|
|
830
|
+
url: { keyboardType: "url", secureTextEntry: false, autoCapitalize: "none", autoCorrect: false },
|
|
831
|
+
search: { keyboardType: "default", secureTextEntry: false, autoCapitalize: "none", autoCorrect: false }
|
|
832
|
+
};
|
|
833
|
+
function stripBridgeKeys(props) {
|
|
834
|
+
const out = {};
|
|
835
|
+
for (const k in props) {
|
|
836
|
+
if (!BRIDGE_KEYS.has(k)) out[k] = props[k];
|
|
837
|
+
}
|
|
838
|
+
return out;
|
|
839
|
+
}
|
|
840
|
+
function extractMeta(raw) {
|
|
841
|
+
return {
|
|
842
|
+
actions: raw._schemaActions,
|
|
843
|
+
condition: raw._schemaIf
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
function resolveSizeModeRN(value, axis, out, parentDirection) {
|
|
847
|
+
if (value === void 0) return;
|
|
848
|
+
if (value === "fill") {
|
|
849
|
+
const isMainAxis = parentDirection === "vertical" && axis === "height" || parentDirection === "horizontal" && axis === "width";
|
|
850
|
+
if (isMainAxis) {
|
|
851
|
+
out.flex = 1;
|
|
852
|
+
} else {
|
|
853
|
+
out.alignSelf = "stretch";
|
|
854
|
+
}
|
|
855
|
+
} else if (value === "hug") {
|
|
856
|
+
out.alignSelf = "flex-start";
|
|
857
|
+
} else {
|
|
858
|
+
out[axis] = value;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
function resolvePaddingRN(padding) {
|
|
862
|
+
if (padding === void 0) return {};
|
|
863
|
+
if (typeof padding === "number") return { padding };
|
|
864
|
+
const { top, right, bottom, left } = padding;
|
|
865
|
+
if (top === bottom && left === right && top !== void 0 && left !== void 0) {
|
|
866
|
+
return { paddingVertical: top, paddingHorizontal: left };
|
|
867
|
+
}
|
|
868
|
+
return {
|
|
869
|
+
...top !== void 0 ? { paddingTop: top } : {},
|
|
870
|
+
...right !== void 0 ? { paddingRight: right } : {},
|
|
871
|
+
...bottom !== void 0 ? { paddingBottom: bottom } : {},
|
|
872
|
+
...left !== void 0 ? { paddingLeft: left } : {}
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
function resolveRadiusRN(radius) {
|
|
876
|
+
if (radius === void 0) return {};
|
|
877
|
+
if (typeof radius === "number") return { borderRadius: radius };
|
|
878
|
+
return {
|
|
879
|
+
...radius.tl !== void 0 ? { borderTopLeftRadius: radius.tl } : {},
|
|
880
|
+
...radius.tr !== void 0 ? { borderTopRightRadius: radius.tr } : {},
|
|
881
|
+
...radius.br !== void 0 ? { borderBottomRightRadius: radius.br } : {},
|
|
882
|
+
...radius.bl !== void 0 ? { borderBottomLeftRadius: radius.bl } : {}
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
function resolveBorderRN(border) {
|
|
886
|
+
if (!border) return {};
|
|
887
|
+
const out = {};
|
|
888
|
+
if (border.style) out.borderStyle = border.style;
|
|
889
|
+
if (border.color) out.borderColor = border.color;
|
|
890
|
+
if (border.widths) {
|
|
891
|
+
const w = border.widths;
|
|
892
|
+
if (w.top !== void 0) out.borderTopWidth = w.top;
|
|
893
|
+
if (w.right !== void 0) out.borderRightWidth = w.right;
|
|
894
|
+
if (w.bottom !== void 0) out.borderBottomWidth = w.bottom;
|
|
895
|
+
if (w.left !== void 0) out.borderLeftWidth = w.left;
|
|
896
|
+
} else if (border.width !== void 0) {
|
|
897
|
+
out.borderWidth = border.width;
|
|
898
|
+
}
|
|
899
|
+
return out;
|
|
900
|
+
}
|
|
901
|
+
function resolveShadowRN(shadow) {
|
|
902
|
+
if (!shadow) return {};
|
|
903
|
+
return {
|
|
904
|
+
shadowColor: shadow.color,
|
|
905
|
+
shadowOffset: { width: shadow.offsetX, height: shadow.offsetY },
|
|
906
|
+
shadowRadius: shadow.blur,
|
|
907
|
+
shadowOpacity: shadow.opacity,
|
|
908
|
+
elevation: Math.round(shadow.blur / 2)
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
function resolveTransformRN(props) {
|
|
912
|
+
const transforms = [];
|
|
913
|
+
if (props.rotate !== void 0 && props.rotate !== 0) transforms.push({ rotate: `${props.rotate}deg` });
|
|
914
|
+
if (props.scale !== void 0 && props.scale !== 1) transforms.push({ scale: props.scale });
|
|
915
|
+
if (props.translateX !== void 0 && props.translateX !== 0) transforms.push({ translateX: props.translateX });
|
|
916
|
+
if (props.translateY !== void 0 && props.translateY !== 0) transforms.push({ translateY: props.translateY });
|
|
917
|
+
return transforms.length ? { transform: transforms } : {};
|
|
918
|
+
}
|
|
919
|
+
function resolvePositionRN(props) {
|
|
920
|
+
const out = {};
|
|
921
|
+
if (props.position) out.position = props.position;
|
|
922
|
+
if (props.position === "absolute") {
|
|
923
|
+
if (props.top !== void 0) out.top = props.top;
|
|
924
|
+
if (props.right !== void 0) out.right = props.right;
|
|
925
|
+
if (props.bottom !== void 0) out.bottom = props.bottom;
|
|
926
|
+
if (props.left !== void 0) out.left = props.left;
|
|
927
|
+
}
|
|
928
|
+
if (props.zIndex !== void 0) out.zIndex = props.zIndex;
|
|
929
|
+
return out;
|
|
930
|
+
}
|
|
931
|
+
function resolveAccessibilityProps(props) {
|
|
932
|
+
const out = {};
|
|
933
|
+
if (props.accessible !== void 0) out.accessible = props.accessible;
|
|
934
|
+
if (props.accessibilityLabel) out.accessibilityLabel = props.accessibilityLabel;
|
|
935
|
+
if (props.accessibilityRole) out.accessibilityRole = props.accessibilityRole;
|
|
936
|
+
if (props.testID) out.testID = props.testID;
|
|
937
|
+
return out;
|
|
938
|
+
}
|
|
939
|
+
function buildFrameStyle(props, parentDirection) {
|
|
940
|
+
var _a, _b, _c, _d;
|
|
941
|
+
const style = {};
|
|
942
|
+
const frameType = (_a = props.type) != null ? _a : "stack";
|
|
943
|
+
if (frameType === "grid") {
|
|
944
|
+
if (props.align) style.alignItems = (_b = ALIGN_MAP[props.align]) != null ? _b : props.align;
|
|
945
|
+
} else {
|
|
946
|
+
style.flexDirection = props.direction === "horizontal" ? "row" : "column";
|
|
947
|
+
if (props.align) style.alignItems = (_c = ALIGN_MAP[props.align]) != null ? _c : props.align;
|
|
948
|
+
if (props.distribute) style.justifyContent = (_d = DISTRIBUTE_MAP[props.distribute]) != null ? _d : props.distribute;
|
|
949
|
+
if (props.gap !== void 0 && props.gap !== 0) style.gap = props.gap;
|
|
950
|
+
if (props.wrap === "yes") style.flexWrap = "wrap";
|
|
951
|
+
}
|
|
952
|
+
resolveSizeModeRN(props.width, "width", style, parentDirection);
|
|
953
|
+
resolveSizeModeRN(props.height, "height", style, parentDirection);
|
|
954
|
+
if (props.minWidth !== void 0) style.minWidth = props.minWidth;
|
|
955
|
+
if (props.maxWidth !== void 0) style.maxWidth = props.maxWidth;
|
|
956
|
+
if (props.minHeight !== void 0) style.minHeight = props.minHeight;
|
|
957
|
+
if (props.maxHeight !== void 0) style.maxHeight = props.maxHeight;
|
|
958
|
+
if (props.aspectRatio !== void 0) style.aspectRatio = props.aspectRatio;
|
|
959
|
+
Object.assign(style, resolvePaddingRN(props.padding));
|
|
960
|
+
if (props.fill && props.fill !== "transparent") style.backgroundColor = props.fill;
|
|
961
|
+
Object.assign(style, resolveRadiusRN(props.radius));
|
|
962
|
+
Object.assign(style, resolveBorderRN(props.border));
|
|
963
|
+
Object.assign(style, resolveShadowRN(props.shadow));
|
|
964
|
+
if (props.opacity !== void 0) style.opacity = props.opacity / 100;
|
|
965
|
+
if (props.overflow === true) style.overflow = "hidden";
|
|
966
|
+
Object.assign(style, resolvePositionRN(props));
|
|
967
|
+
Object.assign(style, resolveTransformRN(props));
|
|
968
|
+
return style;
|
|
969
|
+
}
|
|
970
|
+
function splitFrameStyle(style) {
|
|
971
|
+
const OUTER_KEYS = /* @__PURE__ */ new Set([
|
|
972
|
+
"flex",
|
|
973
|
+
"alignSelf",
|
|
974
|
+
"width",
|
|
975
|
+
"height",
|
|
976
|
+
"minWidth",
|
|
977
|
+
"maxWidth",
|
|
978
|
+
"minHeight",
|
|
979
|
+
"maxHeight",
|
|
980
|
+
"aspectRatio",
|
|
981
|
+
"position",
|
|
982
|
+
"top",
|
|
983
|
+
"right",
|
|
984
|
+
"bottom",
|
|
985
|
+
"left",
|
|
986
|
+
"zIndex",
|
|
987
|
+
"transform"
|
|
988
|
+
]);
|
|
989
|
+
const outer = {};
|
|
990
|
+
const inner = {};
|
|
991
|
+
for (const [k, v] of Object.entries(style)) {
|
|
992
|
+
if (OUTER_KEYS.has(k)) outer[k] = v;
|
|
993
|
+
else inner[k] = v;
|
|
994
|
+
}
|
|
995
|
+
return { outer, inner };
|
|
996
|
+
}
|
|
997
|
+
function splitScrollStyle(style) {
|
|
998
|
+
const CONTENT_KEYS = /* @__PURE__ */ new Set([
|
|
999
|
+
"flexDirection",
|
|
1000
|
+
"justifyContent",
|
|
1001
|
+
"alignItems",
|
|
1002
|
+
"flexWrap",
|
|
1003
|
+
"gap",
|
|
1004
|
+
"padding",
|
|
1005
|
+
"paddingTop",
|
|
1006
|
+
"paddingRight",
|
|
1007
|
+
"paddingBottom",
|
|
1008
|
+
"paddingLeft",
|
|
1009
|
+
"paddingVertical",
|
|
1010
|
+
"paddingHorizontal"
|
|
1011
|
+
]);
|
|
1012
|
+
const containerStyle = {};
|
|
1013
|
+
const contentStyle = {};
|
|
1014
|
+
for (const [k, v] of Object.entries(style)) {
|
|
1015
|
+
if (CONTENT_KEYS.has(k)) contentStyle[k] = v;
|
|
1016
|
+
else containerStyle[k] = v;
|
|
1017
|
+
}
|
|
1018
|
+
return { containerStyle, contentStyle };
|
|
1019
|
+
}
|
|
1020
|
+
function safeAreaEdges(safeArea) {
|
|
1021
|
+
if (!safeArea) return [];
|
|
1022
|
+
return Object.entries(safeArea).filter(([, v]) => v === true).map(([edge]) => edge);
|
|
1023
|
+
}
|
|
1024
|
+
function transformScreen(id, raw, children) {
|
|
1025
|
+
const { actions, condition } = extractMeta(raw);
|
|
1026
|
+
const props = stripBridgeKeys(raw);
|
|
1027
|
+
const edges = safeAreaEdges(props.safeArea);
|
|
1028
|
+
const hasSafeArea = edges.length > 0;
|
|
1029
|
+
const vis = props.visible !== void 0 && props.visible !== true ? { visible: props.visible } : {};
|
|
1030
|
+
const style = { flex: 1 };
|
|
1031
|
+
if (props.backgroundColor) style.backgroundColor = props.backgroundColor;
|
|
1032
|
+
let content;
|
|
1033
|
+
if (props.scrollable) {
|
|
1034
|
+
const paddingStyle = resolvePaddingRN(props.padding);
|
|
1035
|
+
const scrollNode = {
|
|
1036
|
+
id: `${id}__scroll`,
|
|
1037
|
+
type: "scrollview",
|
|
1038
|
+
props: {
|
|
1039
|
+
style: { flex: 1 },
|
|
1040
|
+
...Object.keys(paddingStyle).length ? { contentContainerStyle: paddingStyle } : {},
|
|
1041
|
+
showsVerticalScrollIndicator: false,
|
|
1042
|
+
showsHorizontalScrollIndicator: false
|
|
1043
|
+
},
|
|
1044
|
+
children
|
|
1045
|
+
};
|
|
1046
|
+
content = [scrollNode];
|
|
1047
|
+
} else {
|
|
1048
|
+
Object.assign(style, resolvePaddingRN(props.padding));
|
|
1049
|
+
content = children;
|
|
1050
|
+
}
|
|
1051
|
+
const statusBar = props.statusBarStyle && props.statusBarStyle !== "dark" ? { statusBarStyle: props.statusBarStyle } : {};
|
|
1052
|
+
const node = {
|
|
1053
|
+
id,
|
|
1054
|
+
type: hasSafeArea ? "safeareaview" : "view",
|
|
1055
|
+
props: {
|
|
1056
|
+
style,
|
|
1057
|
+
...hasSafeArea ? { edges } : {},
|
|
1058
|
+
...statusBar,
|
|
1059
|
+
...vis
|
|
1060
|
+
},
|
|
1061
|
+
children: content
|
|
1062
|
+
};
|
|
1063
|
+
if (condition !== void 0) node.if = condition;
|
|
1064
|
+
if (actions) node.actions = actions;
|
|
1065
|
+
return node;
|
|
1066
|
+
}
|
|
1067
|
+
function transformFrame(id, raw, children, parentDirection) {
|
|
1068
|
+
var _a, _b;
|
|
1069
|
+
const { actions, condition } = extractMeta(raw);
|
|
1070
|
+
const p = stripBridgeKeys(raw);
|
|
1071
|
+
const isGrid = ((_a = p.type) != null ? _a : "stack") === "grid";
|
|
1072
|
+
const isScrollable = p.scrollable === true;
|
|
1073
|
+
const isPressable = p.pressable === true;
|
|
1074
|
+
const direction = p.direction === "horizontal" ? "horizontal" : "vertical";
|
|
1075
|
+
const edges = safeAreaEdges(p.safeArea);
|
|
1076
|
+
const hasSafeArea = edges.length > 0;
|
|
1077
|
+
const access = resolveAccessibilityProps(p);
|
|
1078
|
+
const vis = p.visible !== void 0 && p.visible !== true ? { visible: p.visible } : {};
|
|
1079
|
+
const fullStyle = buildFrameStyle(p, parentDirection);
|
|
1080
|
+
const { outer: sizingStyle, inner: appearanceStyle } = splitFrameStyle(fullStyle);
|
|
1081
|
+
const { containerStyle: scrollOuter, contentStyle: scrollContent } = splitScrollStyle(fullStyle);
|
|
1082
|
+
function finalize(node) {
|
|
1083
|
+
if (condition !== void 0) node.if = condition;
|
|
1084
|
+
if (actions && node.type === "pressable") node.actions = actions;
|
|
1085
|
+
else if (actions && !isPressable) node.actions = actions;
|
|
1086
|
+
return node;
|
|
1087
|
+
}
|
|
1088
|
+
if (isGrid) {
|
|
1089
|
+
const gridStyle = { ...fullStyle, flexDirection: "row", flexWrap: "wrap" };
|
|
1090
|
+
delete gridStyle.gap;
|
|
1091
|
+
if (p.columnGap !== void 0) gridStyle.columnGap = p.columnGap;
|
|
1092
|
+
if (p.rowGap !== void 0) gridStyle.rowGap = p.rowGap;
|
|
1093
|
+
const gridView = {
|
|
1094
|
+
id: hasSafeArea || isPressable ? `${id}__grid` : id,
|
|
1095
|
+
type: "view",
|
|
1096
|
+
props: {
|
|
1097
|
+
...Object.keys(gridStyle).length ? { style: gridStyle } : {},
|
|
1098
|
+
numColumns: (_b = p.columns) != null ? _b : 2,
|
|
1099
|
+
...access,
|
|
1100
|
+
...hasSafeArea || isPressable ? {} : vis
|
|
1101
|
+
},
|
|
1102
|
+
children
|
|
1103
|
+
};
|
|
1104
|
+
if (!hasSafeArea && !isPressable) return finalize(gridView);
|
|
1105
|
+
let inner = gridView;
|
|
1106
|
+
if (hasSafeArea) {
|
|
1107
|
+
inner = {
|
|
1108
|
+
id: isPressable ? `${id}__sav` : id,
|
|
1109
|
+
type: "safeareaview",
|
|
1110
|
+
props: { edges, ...isPressable ? {} : vis },
|
|
1111
|
+
children: [gridView]
|
|
1112
|
+
};
|
|
1113
|
+
}
|
|
1114
|
+
if (!isPressable) return finalize(inner);
|
|
1115
|
+
return finalize({
|
|
1116
|
+
id,
|
|
1117
|
+
type: "pressable",
|
|
1118
|
+
props: {
|
|
1119
|
+
...Object.keys(sizingStyle).length ? { style: sizingStyle } : {},
|
|
1120
|
+
...actions ? { actions } : {},
|
|
1121
|
+
...vis
|
|
1122
|
+
},
|
|
1123
|
+
children: [inner]
|
|
1124
|
+
});
|
|
1125
|
+
}
|
|
1126
|
+
if (isScrollable) {
|
|
1127
|
+
const scrollNode = {
|
|
1128
|
+
id: hasSafeArea || isPressable ? `${id}__scroll` : id,
|
|
1129
|
+
type: "scrollview",
|
|
1130
|
+
props: {
|
|
1131
|
+
...Object.keys(scrollOuter).length ? { style: scrollOuter } : {},
|
|
1132
|
+
...Object.keys(scrollContent).length ? { contentContainerStyle: scrollContent } : {},
|
|
1133
|
+
horizontal: direction === "horizontal",
|
|
1134
|
+
showsHorizontalScrollIndicator: p.showScrollIndicator === true,
|
|
1135
|
+
showsVerticalScrollIndicator: p.showScrollIndicator === true,
|
|
1136
|
+
...access,
|
|
1137
|
+
...hasSafeArea || isPressable ? {} : vis
|
|
1138
|
+
},
|
|
1139
|
+
children
|
|
1140
|
+
};
|
|
1141
|
+
if (!hasSafeArea && !isPressable) return finalize(scrollNode);
|
|
1142
|
+
let inner = scrollNode;
|
|
1143
|
+
if (hasSafeArea) {
|
|
1144
|
+
inner = {
|
|
1145
|
+
id: isPressable ? `${id}__sav` : id,
|
|
1146
|
+
type: "safeareaview",
|
|
1147
|
+
props: {
|
|
1148
|
+
edges,
|
|
1149
|
+
...Object.keys(sizingStyle).length ? { style: sizingStyle } : {},
|
|
1150
|
+
...isPressable ? {} : vis
|
|
1151
|
+
},
|
|
1152
|
+
children: [scrollNode]
|
|
1153
|
+
};
|
|
1154
|
+
}
|
|
1155
|
+
if (!isPressable) return finalize(inner);
|
|
1156
|
+
return finalize({
|
|
1157
|
+
id,
|
|
1158
|
+
type: "pressable",
|
|
1159
|
+
props: {
|
|
1160
|
+
...Object.keys(sizingStyle).length ? { style: sizingStyle } : {},
|
|
1161
|
+
...actions ? { actions } : {},
|
|
1162
|
+
...vis
|
|
1163
|
+
},
|
|
1164
|
+
children: [inner]
|
|
1165
|
+
});
|
|
1166
|
+
}
|
|
1167
|
+
if (!isPressable && !hasSafeArea) {
|
|
1168
|
+
return finalize({
|
|
1169
|
+
id,
|
|
1170
|
+
type: "view",
|
|
1171
|
+
props: {
|
|
1172
|
+
...Object.keys(fullStyle).length ? { style: fullStyle } : {},
|
|
1173
|
+
...access,
|
|
1174
|
+
...vis
|
|
1175
|
+
},
|
|
1176
|
+
children
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
if (!isPressable && hasSafeArea) {
|
|
1180
|
+
return finalize({
|
|
1181
|
+
id,
|
|
1182
|
+
type: "safeareaview",
|
|
1183
|
+
props: {
|
|
1184
|
+
edges,
|
|
1185
|
+
...Object.keys(fullStyle).length ? { style: fullStyle } : {},
|
|
1186
|
+
...access,
|
|
1187
|
+
...vis
|
|
1188
|
+
},
|
|
1189
|
+
children
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
const innerNode = hasSafeArea ? {
|
|
1193
|
+
id: `${id}__sav`,
|
|
1194
|
+
type: "safeareaview",
|
|
1195
|
+
props: {
|
|
1196
|
+
edges,
|
|
1197
|
+
...Object.keys(appearanceStyle).length ? { style: appearanceStyle } : {},
|
|
1198
|
+
...access
|
|
1199
|
+
},
|
|
1200
|
+
children
|
|
1201
|
+
} : {
|
|
1202
|
+
id: `${id}__content`,
|
|
1203
|
+
type: "view",
|
|
1204
|
+
props: {
|
|
1205
|
+
...Object.keys(appearanceStyle).length ? { style: appearanceStyle } : {},
|
|
1206
|
+
...access
|
|
1207
|
+
},
|
|
1208
|
+
children
|
|
1209
|
+
};
|
|
1210
|
+
return finalize({
|
|
1211
|
+
id,
|
|
1212
|
+
type: "pressable",
|
|
1213
|
+
props: {
|
|
1214
|
+
...Object.keys(sizingStyle).length ? { style: sizingStyle } : {},
|
|
1215
|
+
...actions ? { actions } : {},
|
|
1216
|
+
...vis
|
|
1217
|
+
},
|
|
1218
|
+
children: [innerNode]
|
|
1219
|
+
});
|
|
1220
|
+
}
|
|
1221
|
+
function transformText(id, raw, parentDirection) {
|
|
1222
|
+
var _a, _b;
|
|
1223
|
+
const { actions, condition } = extractMeta(raw);
|
|
1224
|
+
const props = stripBridgeKeys(raw);
|
|
1225
|
+
const style = {};
|
|
1226
|
+
if (props.textStyle) {
|
|
1227
|
+
const preset = TEXT_STYLE_PRESETS[props.textStyle];
|
|
1228
|
+
if (preset) {
|
|
1229
|
+
style.fontSize = preset.fontSize;
|
|
1230
|
+
style.fontWeight = preset.fontWeight;
|
|
1231
|
+
if (preset.lineHeight !== void 0) style.lineHeight = preset.lineHeight;
|
|
1232
|
+
if (preset.textTransform) style.textTransform = preset.textTransform;
|
|
1233
|
+
if (preset.letterSpacing !== void 0) style.letterSpacing = preset.letterSpacing;
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
if (props.color) style.color = props.color;
|
|
1237
|
+
if (props.fontSize !== void 0) style.fontSize = props.fontSize;
|
|
1238
|
+
if (props.fontWeight) style.fontWeight = (_a = FONT_WEIGHT_MAP[props.fontWeight]) != null ? _a : props.fontWeight;
|
|
1239
|
+
if (props.fontFamily) style.fontFamily = props.fontFamily;
|
|
1240
|
+
if (props.fontStyle) style.fontStyle = props.fontStyle;
|
|
1241
|
+
if (props.lineHeight !== void 0) style.lineHeight = props.lineHeight;
|
|
1242
|
+
if (props.letterSpacing !== void 0) style.letterSpacing = props.letterSpacing;
|
|
1243
|
+
if (props.align) style.textAlign = props.align;
|
|
1244
|
+
if (props.transform && props.transform !== "none") style.textTransform = props.transform;
|
|
1245
|
+
if (props.decoration && props.decoration !== "none") style.textDecorationLine = props.decoration;
|
|
1246
|
+
if (props.opacity !== void 0) style.opacity = props.opacity / 100;
|
|
1247
|
+
Object.assign(style, resolvePositionRN(props));
|
|
1248
|
+
resolveSizeModeRN(props.width, "width", style, parentDirection);
|
|
1249
|
+
const textProps = {};
|
|
1250
|
+
if (typeof props.truncate === "number" && props.truncate > 0) {
|
|
1251
|
+
textProps.numberOfLines = props.truncate;
|
|
1252
|
+
textProps.ellipsizeMode = "tail";
|
|
1253
|
+
}
|
|
1254
|
+
if (props.adjustFontSize === true) {
|
|
1255
|
+
textProps.adjustsFontSizeToFit = true;
|
|
1256
|
+
if (props.minFontSize !== void 0) textProps.minimumFontScale = props.minFontSize;
|
|
1257
|
+
}
|
|
1258
|
+
if (props.selectable !== void 0) textProps.selectable = props.selectable;
|
|
1259
|
+
const node = {
|
|
1260
|
+
id,
|
|
1261
|
+
type: "text",
|
|
1262
|
+
props: {
|
|
1263
|
+
// SDK contract: text content lives in the `value` prop.
|
|
1264
|
+
// The Craft editor stores text in `content`; map it to `value` here.
|
|
1265
|
+
value: (_b = props.content) != null ? _b : "",
|
|
1266
|
+
...Object.keys(style).length ? { style } : {},
|
|
1267
|
+
...textProps,
|
|
1268
|
+
...resolveAccessibilityProps(props),
|
|
1269
|
+
...props.visible !== void 0 && props.visible !== true ? { visible: props.visible } : {}
|
|
1270
|
+
}
|
|
1271
|
+
};
|
|
1272
|
+
if (condition !== void 0) node.if = condition;
|
|
1273
|
+
if (actions) node.actions = actions;
|
|
1274
|
+
return node;
|
|
1275
|
+
}
|
|
1276
|
+
function transformImage(id, raw, children, parentDirection) {
|
|
1277
|
+
var _a, _b;
|
|
1278
|
+
const { actions, condition } = extractMeta(raw);
|
|
1279
|
+
const props = stripBridgeKeys(raw);
|
|
1280
|
+
const style = {};
|
|
1281
|
+
resolveSizeModeRN(props.width, "width", style, parentDirection);
|
|
1282
|
+
resolveSizeModeRN(props.height, "height", style, parentDirection);
|
|
1283
|
+
if (props.aspectRatio !== void 0) style.aspectRatio = props.aspectRatio;
|
|
1284
|
+
Object.assign(style, resolveRadiusRN(props.radius));
|
|
1285
|
+
if (props.opacity !== void 0) style.opacity = props.opacity / 100;
|
|
1286
|
+
Object.assign(style, resolvePositionRN(props));
|
|
1287
|
+
const imageProps = {};
|
|
1288
|
+
if (props.src) imageProps.source = { uri: props.src };
|
|
1289
|
+
if (props.placeholder) imageProps.defaultSource = { uri: props.placeholder };
|
|
1290
|
+
if (props.fallback) imageProps.fallback = { uri: props.fallback };
|
|
1291
|
+
imageProps.resizeMode = (_b = FIT_TO_RESIZE_MODE[(_a = props.fit) != null ? _a : "cover"]) != null ? _b : "cover";
|
|
1292
|
+
if (props.background === true) imageProps.background = true;
|
|
1293
|
+
if (props.decorative) {
|
|
1294
|
+
imageProps.accessible = false;
|
|
1295
|
+
imageProps.accessibilityElementsHidden = true;
|
|
1296
|
+
} else if (props.alt) {
|
|
1297
|
+
imageProps.accessible = true;
|
|
1298
|
+
imageProps.accessibilityLabel = props.alt;
|
|
1299
|
+
}
|
|
1300
|
+
if (props.testID) imageProps.testID = props.testID;
|
|
1301
|
+
const node = {
|
|
1302
|
+
id,
|
|
1303
|
+
type: "image",
|
|
1304
|
+
props: {
|
|
1305
|
+
...Object.keys(style).length ? { style } : {},
|
|
1306
|
+
...imageProps,
|
|
1307
|
+
...props.visible !== void 0 && props.visible !== true ? { visible: props.visible } : {}
|
|
1308
|
+
},
|
|
1309
|
+
...props.background === true && children.length ? { children } : {}
|
|
1310
|
+
};
|
|
1311
|
+
if (condition !== void 0) node.if = condition;
|
|
1312
|
+
if (actions) node.actions = actions;
|
|
1313
|
+
return node;
|
|
1314
|
+
}
|
|
1315
|
+
function transformInput(id, raw, parentDirection) {
|
|
1316
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1317
|
+
const { actions, condition } = extractMeta(raw);
|
|
1318
|
+
const props = stripBridgeKeys(raw);
|
|
1319
|
+
const style = {};
|
|
1320
|
+
resolveSizeModeRN((_a = props.width) != null ? _a : "fill", "width", style, parentDirection);
|
|
1321
|
+
Object.assign(style, resolvePaddingRN(props.padding));
|
|
1322
|
+
if (props.opacity !== void 0) style.opacity = props.opacity / 100;
|
|
1323
|
+
Object.assign(style, resolvePositionRN(props));
|
|
1324
|
+
const inputTypeDefaults = (_c = INPUT_TYPE_MAP[(_b = props.inputType) != null ? _b : "text"]) != null ? _c : INPUT_TYPE_MAP.text;
|
|
1325
|
+
const node = {
|
|
1326
|
+
id,
|
|
1327
|
+
type: "textinput",
|
|
1328
|
+
props: {
|
|
1329
|
+
...Object.keys(style).length ? { style } : {},
|
|
1330
|
+
...props.label !== void 0 ? { label: props.label } : {},
|
|
1331
|
+
...props.placeholder !== void 0 ? { placeholder: props.placeholder } : {},
|
|
1332
|
+
...props.value !== void 0 ? { value: props.value } : {},
|
|
1333
|
+
...props.helperText !== void 0 ? { helperText: props.helperText } : {},
|
|
1334
|
+
...props.errorText !== void 0 ? { errorText: props.errorText } : {},
|
|
1335
|
+
...inputTypeDefaults,
|
|
1336
|
+
...props.autoCapitalize ? { autoCapitalize: props.autoCapitalize } : {},
|
|
1337
|
+
returnKeyType: (_d = props.returnKey) != null ? _d : "done",
|
|
1338
|
+
multiline: (_e = props.multiline) != null ? _e : false,
|
|
1339
|
+
...props.multiline && props.minLines ? { numberOfLines: props.minLines } : {},
|
|
1340
|
+
...props.multiline && props.maxLines ? { maxNumberOfLines: props.maxLines } : {},
|
|
1341
|
+
variant: (_f = props.variant) != null ? _f : "outline",
|
|
1342
|
+
size: (_g = props.size) != null ? _g : "md",
|
|
1343
|
+
...props.leadingIcon ? { leadingIcon: props.leadingIcon } : {},
|
|
1344
|
+
...props.trailingIcon ? { trailingIcon: props.trailingIcon } : {},
|
|
1345
|
+
...resolveAccessibilityProps(props),
|
|
1346
|
+
...props.visible !== void 0 && props.visible !== true ? { visible: props.visible } : {}
|
|
1347
|
+
}
|
|
1348
|
+
};
|
|
1349
|
+
if (condition !== void 0) node.if = condition;
|
|
1350
|
+
if (actions) node.actions = actions;
|
|
1351
|
+
return node;
|
|
1352
|
+
}
|
|
1353
|
+
function transformList(id, raw, children, parentDirection) {
|
|
1354
|
+
var _a, _b, _c;
|
|
1355
|
+
const { actions, condition } = extractMeta(raw);
|
|
1356
|
+
const props = stripBridgeKeys(raw);
|
|
1357
|
+
const listType = (_a = props.type) != null ? _a : "stack";
|
|
1358
|
+
const direction = props.direction === "horizontal" ? "horizontal" : "vertical";
|
|
1359
|
+
const edges = safeAreaEdges(props.safeArea);
|
|
1360
|
+
const hasSafeArea = edges.length > 0;
|
|
1361
|
+
const vis = props.visible !== void 0 && props.visible !== true ? { visible: props.visible } : {};
|
|
1362
|
+
const fullStyle = buildFrameStyle(props, parentDirection);
|
|
1363
|
+
const { containerStyle, contentStyle } = splitScrollStyle(fullStyle);
|
|
1364
|
+
let itemTemplate;
|
|
1365
|
+
if (children.length === 1) {
|
|
1366
|
+
itemTemplate = children[0];
|
|
1367
|
+
} else if (children.length > 1) {
|
|
1368
|
+
itemTemplate = { id: `${id}__template`, type: "view", props: {}, children };
|
|
1369
|
+
}
|
|
1370
|
+
const flatlistNode = {
|
|
1371
|
+
id: hasSafeArea ? `${id}__list` : id,
|
|
1372
|
+
type: "flatlist",
|
|
1373
|
+
props: {
|
|
1374
|
+
...Object.keys(containerStyle).length ? { style: containerStyle } : {},
|
|
1375
|
+
...Object.keys(contentStyle).length ? { contentContainerStyle: contentStyle } : {},
|
|
1376
|
+
// `data` holds the binding expression for the list items array.
|
|
1377
|
+
// RecursiveRenderer resolves it and passes items to the FlatList primitive.
|
|
1378
|
+
data: props.data,
|
|
1379
|
+
keyExtractor: (_b = props.keyExtractor) != null ? _b : "id",
|
|
1380
|
+
...listType === "grid" ? { numColumns: (_c = props.columns) != null ? _c : 2 } : {},
|
|
1381
|
+
...listType === "grid" && props.columnGap ? { columnGap: props.columnGap } : {},
|
|
1382
|
+
...listType === "grid" && props.rowGap ? { rowGap: props.rowGap } : {},
|
|
1383
|
+
horizontal: direction === "horizontal",
|
|
1384
|
+
showsHorizontalScrollIndicator: props.showScrollIndicator === true,
|
|
1385
|
+
showsVerticalScrollIndicator: props.showScrollIndicator === true,
|
|
1386
|
+
...resolveAccessibilityProps(props),
|
|
1387
|
+
...hasSafeArea ? {} : vis
|
|
1388
|
+
},
|
|
1389
|
+
...itemTemplate ? { itemTemplate } : {}
|
|
1390
|
+
};
|
|
1391
|
+
if (!hasSafeArea) {
|
|
1392
|
+
if (condition !== void 0) flatlistNode.if = condition;
|
|
1393
|
+
if (actions) flatlistNode.actions = actions;
|
|
1394
|
+
return flatlistNode;
|
|
1395
|
+
}
|
|
1396
|
+
const { outer: sizingStyle } = splitFrameStyle(fullStyle);
|
|
1397
|
+
const savNode = {
|
|
1398
|
+
id,
|
|
1399
|
+
type: "safeareaview",
|
|
1400
|
+
props: {
|
|
1401
|
+
edges,
|
|
1402
|
+
...Object.keys(sizingStyle).length ? { style: sizingStyle } : {},
|
|
1403
|
+
...vis
|
|
1404
|
+
},
|
|
1405
|
+
children: [flatlistNode]
|
|
1406
|
+
};
|
|
1407
|
+
if (condition !== void 0) savNode.if = condition;
|
|
1408
|
+
if (actions) savNode.actions = actions;
|
|
1409
|
+
return savNode;
|
|
1410
|
+
}
|
|
1411
|
+
function transformIcon(id, raw) {
|
|
1412
|
+
var _a, _b;
|
|
1413
|
+
const { actions, condition } = extractMeta(raw);
|
|
1414
|
+
const props = stripBridgeKeys(raw);
|
|
1415
|
+
const style = {};
|
|
1416
|
+
if (props.opacity !== void 0) style.opacity = props.opacity / 100;
|
|
1417
|
+
Object.assign(style, resolvePositionRN(props));
|
|
1418
|
+
const node = {
|
|
1419
|
+
id,
|
|
1420
|
+
type: "icon",
|
|
1421
|
+
props: {
|
|
1422
|
+
name: props.name,
|
|
1423
|
+
set: (_a = props.set) != null ? _a : "default",
|
|
1424
|
+
size: (_b = props.size) != null ? _b : 24,
|
|
1425
|
+
...props.color ? { color: props.color } : {},
|
|
1426
|
+
...Object.keys(style).length ? { style } : {},
|
|
1427
|
+
...resolveAccessibilityProps(props),
|
|
1428
|
+
...props.visible !== void 0 && props.visible !== true ? { visible: props.visible } : {}
|
|
1429
|
+
}
|
|
1430
|
+
};
|
|
1431
|
+
if (condition !== void 0) node.if = condition;
|
|
1432
|
+
if (actions) node.actions = actions;
|
|
1433
|
+
return node;
|
|
1434
|
+
}
|
|
1435
|
+
function buildNodeFromSchema(nodeId, schema, customComponents, visited, parentId) {
|
|
1436
|
+
var _a, _b, _c, _d, _e;
|
|
1437
|
+
if (visited.has(nodeId)) {
|
|
1438
|
+
throw new Error(`Circular reference detected at node ${nodeId}`);
|
|
1439
|
+
}
|
|
1440
|
+
visited.add(nodeId);
|
|
1441
|
+
const node = schema[nodeId];
|
|
1442
|
+
if (!node) throw new Error(`Node not found: ${nodeId}`);
|
|
1443
|
+
const resolvedName = (_a = node.type) == null ? void 0 : _a.resolvedName;
|
|
1444
|
+
if (!resolvedName) throw new Error(`Invalid node type at ${nodeId}`);
|
|
1445
|
+
const raw = (_b = node.props) != null ? _b : {};
|
|
1446
|
+
const parentDirection = parentId ? ((_d = (_c = schema[parentId]) == null ? void 0 : _c.props) == null ? void 0 : _d["direction"]) === "horizontal" ? "horizontal" : "vertical" : "vertical";
|
|
1447
|
+
const outputId = nodeId === "ROOT" ? "root" : nodeId;
|
|
1448
|
+
const childNodes = ((_e = node.nodes) != null ? _e : []).map(
|
|
1449
|
+
(childId) => buildNodeFromSchema(childId, schema, customComponents, visited, nodeId)
|
|
1450
|
+
);
|
|
1451
|
+
switch (resolvedName) {
|
|
1452
|
+
case "PF.Screen":
|
|
1453
|
+
return transformScreen(outputId, raw, childNodes);
|
|
1454
|
+
case "PF.Frame":
|
|
1455
|
+
return transformFrame(outputId, raw, childNodes, parentDirection);
|
|
1456
|
+
case "PF.Text":
|
|
1457
|
+
return transformText(outputId, raw, parentDirection);
|
|
1458
|
+
case "PF.Image":
|
|
1459
|
+
return transformImage(outputId, raw, childNodes, parentDirection);
|
|
1460
|
+
case "PF.Input":
|
|
1461
|
+
return transformInput(outputId, raw, parentDirection);
|
|
1462
|
+
case "PF.List":
|
|
1463
|
+
return transformList(outputId, raw, childNodes, parentDirection);
|
|
1464
|
+
case "PF.Icon":
|
|
1465
|
+
return transformIcon(outputId, raw);
|
|
1466
|
+
case "Component":
|
|
1467
|
+
return resolveCustomComponent(outputId, raw, parentDirection, customComponents);
|
|
1468
|
+
default:
|
|
1469
|
+
return { id: outputId, type: "view", props: {}, children: childNodes };
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
function resolveCustomComponent(id, raw, parentDirection, customComponents) {
|
|
1473
|
+
const { actions, condition } = extractMeta(raw);
|
|
1474
|
+
const props = stripBridgeKeys(raw);
|
|
1475
|
+
const { componentId, componentKey, propValues, ...frameProps } = props;
|
|
1476
|
+
const key = componentKey != null ? componentKey : componentId;
|
|
1477
|
+
const def = key ? customComponents[key] : void 0;
|
|
1478
|
+
const wrapperStyle = buildFrameStyle(frameProps, parentDirection);
|
|
1479
|
+
const vis = props.visible !== void 0 && props.visible !== true ? { visible: props.visible } : {};
|
|
1480
|
+
if (!def) {
|
|
1481
|
+
return {
|
|
1482
|
+
id,
|
|
1483
|
+
type: "view",
|
|
1484
|
+
props: { ...Object.keys(wrapperStyle).length ? { style: wrapperStyle } : {}, ...vis },
|
|
1485
|
+
children: []
|
|
1486
|
+
};
|
|
1487
|
+
}
|
|
1488
|
+
const componentVisited = /* @__PURE__ */ new Set();
|
|
1489
|
+
const componentRoot = buildNodeFromSchema(
|
|
1490
|
+
def.rootNodeId,
|
|
1491
|
+
def.nodes,
|
|
1492
|
+
customComponents,
|
|
1493
|
+
componentVisited
|
|
1494
|
+
);
|
|
1495
|
+
if (propValues && Object.keys(propValues).length) {
|
|
1496
|
+
componentRoot.props = { ...componentRoot.props, _propValues: propValues };
|
|
1497
|
+
}
|
|
1498
|
+
if (Object.keys(wrapperStyle).length > 0) {
|
|
1499
|
+
const wrapper = {
|
|
1500
|
+
id,
|
|
1501
|
+
type: "view",
|
|
1502
|
+
props: { style: wrapperStyle, ...vis },
|
|
1503
|
+
children: [componentRoot]
|
|
1504
|
+
};
|
|
1505
|
+
if (condition !== void 0) wrapper.if = condition;
|
|
1506
|
+
if (actions) wrapper.actions = actions;
|
|
1507
|
+
return wrapper;
|
|
1508
|
+
}
|
|
1509
|
+
componentRoot.id = id;
|
|
1510
|
+
componentRoot.props = { ...componentRoot.props, ...vis };
|
|
1511
|
+
if (condition !== void 0) componentRoot.if = condition;
|
|
1512
|
+
if (actions) componentRoot.actions = actions;
|
|
1513
|
+
return componentRoot;
|
|
1514
|
+
}
|
|
1515
|
+
function transformCraftToSDUI(craftJson, customComponents = {}) {
|
|
1516
|
+
if (!craftJson || typeof craftJson !== "object") {
|
|
1517
|
+
throw new Error("Invalid craft schema");
|
|
1518
|
+
}
|
|
1519
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1520
|
+
return buildNodeFromSchema("ROOT", craftJson, customComponents, visited);
|
|
1521
|
+
}
|
|
1522
|
+
|
|
740
1523
|
// src/index.ts
|
|
741
1524
|
var PushFrame = {
|
|
742
1525
|
// Slot components
|
|
@@ -783,6 +1566,7 @@ exports.evaluateIf = evaluateIf;
|
|
|
783
1566
|
exports.resolveDeep = resolveDeep;
|
|
784
1567
|
exports.resolveProps = resolveProps;
|
|
785
1568
|
exports.resolveValue = resolveValue;
|
|
1569
|
+
exports.transformCraftToSDUI = transformCraftToSDUI;
|
|
786
1570
|
exports.usePushFrameContext = usePushFrameContext;
|
|
787
1571
|
//# sourceMappingURL=index.js.map
|
|
788
1572
|
//# sourceMappingURL=index.js.map
|