@pushframe/sdk 0.1.2 → 0.1.4

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.mjs CHANGED
@@ -36,7 +36,7 @@ var ScrollView = forwardRef(function ScrollView2({ if: _if, actions: _actions, .
36
36
  return /* @__PURE__ */ jsx(ScrollView$1, { ref, ...rest });
37
37
  });
38
38
  function Image({ if: _if, actions: _actions, src, source, ...rest }) {
39
- const resolvedSource = src ? { uri: src } : source ?? { uri: "" };
39
+ const resolvedSource = src ? { uri: src } : source != null ? source : { uri: "" };
40
40
  return /* @__PURE__ */ jsx(Image$1, { source: resolvedSource, ...rest });
41
41
  }
42
42
  function Pressable({ if: _if, actions: _actions, ...rest }) {
@@ -160,7 +160,8 @@ var ComponentRegistry = class {
160
160
  * Returns null if no component is registered for the type.
161
161
  */
162
162
  resolve(type) {
163
- return this.components.get(type) ?? null;
163
+ var _a;
164
+ return (_a = this.components.get(type)) != null ? _a : null;
164
165
  }
165
166
  /**
166
167
  * Returns all registered type strings (useful for debugging).
@@ -176,6 +177,7 @@ var TYPE_COLORS = {
176
177
  warning: "#f59e0b"
177
178
  };
178
179
  var ToastHost = forwardRef(function ToastHost2(_props, ref) {
180
+ var _a, _b;
179
181
  const [toast, setToast] = useState(null);
180
182
  const opacity = useRef(new Animated.Value(0)).current;
181
183
  const idRef = useRef(0);
@@ -206,12 +208,13 @@ var ToastHost = forwardRef(function ToastHost2(_props, ref) {
206
208
  ref,
207
209
  () => ({
208
210
  show(payload) {
211
+ var _a2, _b2;
209
212
  idRef.current += 1;
210
213
  setToast({
211
214
  id: idRef.current,
212
215
  message: payload.message,
213
- duration: payload.duration ?? 3e3,
214
- type: payload.type ?? "info"
216
+ duration: (_a2 = payload.duration) != null ? _a2 : 3e3,
217
+ type: (_b2 = payload.type) != null ? _b2 : "info"
215
218
  });
216
219
  opacity.setValue(0);
217
220
  }
@@ -219,7 +222,7 @@ var ToastHost = forwardRef(function ToastHost2(_props, ref) {
219
222
  [opacity]
220
223
  );
221
224
  if (!toast) return null;
222
- const backgroundColor = TYPE_COLORS[toast.type ?? "info"] ?? TYPE_COLORS.info;
225
+ const backgroundColor = (_b = TYPE_COLORS[(_a = toast.type) != null ? _a : "info"]) != null ? _b : TYPE_COLORS.info;
223
226
  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
227
  });
225
228
  var styles = StyleSheet.create({
@@ -269,7 +272,7 @@ var BottomSheetHost = forwardRef(
269
272
  duration: 250,
270
273
  useNativeDriver: true
271
274
  }).start(() => {
272
- onDone?.();
275
+ onDone == null ? void 0 : onDone();
273
276
  });
274
277
  },
275
278
  [translateY]
@@ -376,7 +379,7 @@ function resolveValue(value, context) {
376
379
  return value;
377
380
  }
378
381
  const fullMatch = FULL_BINDING_RE.exec(value);
379
- if (fullMatch?.[1] !== void 0) {
382
+ if ((fullMatch == null ? void 0 : fullMatch[1]) !== void 0) {
380
383
  return evaluateExpression(fullMatch[1].trim(), context);
381
384
  }
382
385
  if (INLINE_BINDING_RE.test(value)) {
@@ -566,13 +569,16 @@ function PushFrameProvider({
566
569
  const toastRef = useRef(null);
567
570
  const bottomSheetRef = useRef(null);
568
571
  const showToast = useCallback((payload) => {
569
- toastRef.current?.show(payload);
572
+ var _a;
573
+ (_a = toastRef.current) == null ? void 0 : _a.show(payload);
570
574
  }, []);
571
575
  const showBottomSheet = useCallback((payload) => {
572
- bottomSheetRef.current?.show(payload);
576
+ var _a;
577
+ (_a = bottomSheetRef.current) == null ? void 0 : _a.show(payload);
573
578
  }, []);
574
579
  const dismissBottomSheet = useCallback(() => {
575
- bottomSheetRef.current?.dismiss();
580
+ var _a;
581
+ (_a = bottomSheetRef.current) == null ? void 0 : _a.dismiss();
576
582
  }, []);
577
583
  const renderBottomSheetContent = useCallback(
578
584
  (schema, sheetContext) => {
@@ -586,7 +592,7 @@ function PushFrameProvider({
586
592
  showToast(payload);
587
593
  return;
588
594
  }
589
- onAction?.(action, payload);
595
+ onAction == null ? void 0 : onAction(action, payload);
590
596
  };
591
597
  return /* @__PURE__ */ jsx(
592
598
  RecursiveRenderer,
@@ -638,6 +644,7 @@ function PushFrameProvider({
638
644
  ] });
639
645
  }
640
646
  async function fetchSchema(baseUrl, apiKey, path) {
647
+ var _a;
641
648
  const url = new URL(path, baseUrl + "/").toString();
642
649
  const headers = {
643
650
  Accept: "application/json",
@@ -649,7 +656,7 @@ async function fetchSchema(baseUrl, apiKey, path) {
649
656
  throw new Error(`[PushFrame] HTTP ${res.status} fetching "${path}"`);
650
657
  }
651
658
  const envelope = await res.json();
652
- return envelope.schema ?? envelope;
659
+ return (_a = envelope.schema) != null ? _a : envelope;
653
660
  }
654
661
  function PushFrameComponentInternal({
655
662
  id,
@@ -678,7 +685,7 @@ function PushFrameComponentInternal({
678
685
  const [schema, setSchema] = useState(null);
679
686
  const [fetchError, setFetchError] = useState(null);
680
687
  const [isFetching, setIsFetching] = useState(true);
681
- const fetchPath = `${resourceType}/${encodeURIComponent(id)}/${encodeURIComponent(appVersion ?? "null")}`;
688
+ const fetchPath = `${resourceType}/${encodeURIComponent(id)}/${encodeURIComponent(appVersion != null ? appVersion : "null")}`;
682
689
  const mergedContext = slotContext ? { ...globalContext, ...slotContext } : globalContext;
683
690
  const loadingUI = slotLoading !== void 0 ? slotLoading : providerLoading;
684
691
  const fallbackUI = slotFallback !== void 0 ? slotFallback : providerFallback;
@@ -697,7 +704,7 @@ function PushFrameComponentInternal({
697
704
  const error = err instanceof Error ? err : new Error(String(err));
698
705
  setFetchError(error);
699
706
  setIsFetching(false);
700
- onError?.(error);
707
+ onError == null ? void 0 : onError(error);
701
708
  }
702
709
  });
703
710
  return () => {
@@ -721,18 +728,18 @@ function PushFrameComponentInternal({
721
728
  if (action === "scroll-to") {
722
729
  return;
723
730
  }
724
- const stopped = slotOnAction?.(action, payload);
731
+ const stopped = slotOnAction == null ? void 0 : slotOnAction(action, payload);
725
732
  if (stopped) return;
726
- providerOnAction?.(action, payload);
733
+ providerOnAction == null ? void 0 : providerOnAction(action, payload);
727
734
  },
728
735
  [showToast, showBottomSheet, dismissBottomSheet, slotOnAction, providerOnAction]
729
736
  );
730
737
  const isShowingLoader = externalLoading || isFetching;
731
738
  if (isShowingLoader) {
732
- return loadingUI ?? null;
739
+ return loadingUI != null ? loadingUI : null;
733
740
  }
734
741
  if (fetchError || !schema) {
735
- return fallbackUI ?? null;
742
+ return fallbackUI != null ? fallbackUI : null;
736
743
  }
737
744
  const rendered = /* @__PURE__ */ jsx(
738
745
  RecursiveRenderer,
@@ -924,14 +931,15 @@ function resolveAccessibilityProps(props) {
924
931
  return out;
925
932
  }
926
933
  function buildFrameStyle(props, parentDirection) {
934
+ var _a, _b, _c, _d;
927
935
  const style = {};
928
- const frameType = props.type ?? "stack";
936
+ const frameType = (_a = props.type) != null ? _a : "stack";
929
937
  if (frameType === "grid") {
930
- if (props.align) style.alignItems = ALIGN_MAP[props.align] ?? props.align;
938
+ if (props.align) style.alignItems = (_b = ALIGN_MAP[props.align]) != null ? _b : props.align;
931
939
  } else {
932
940
  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;
941
+ if (props.align) style.alignItems = (_c = ALIGN_MAP[props.align]) != null ? _c : props.align;
942
+ if (props.distribute) style.justifyContent = (_d = DISTRIBUTE_MAP[props.distribute]) != null ? _d : props.distribute;
935
943
  if (props.gap !== void 0 && props.gap !== 0) style.gap = props.gap;
936
944
  if (props.wrap === "yes") style.flexWrap = "wrap";
937
945
  }
@@ -1051,9 +1059,10 @@ function transformScreen(id, raw, children) {
1051
1059
  return node;
1052
1060
  }
1053
1061
  function transformFrame(id, raw, children, parentDirection) {
1062
+ var _a, _b;
1054
1063
  const { actions, condition } = extractMeta(raw);
1055
1064
  const p = stripBridgeKeys(raw);
1056
- const isGrid = (p.type ?? "stack") === "grid";
1065
+ const isGrid = ((_a = p.type) != null ? _a : "stack") === "grid";
1057
1066
  const isScrollable = p.scrollable === true;
1058
1067
  const isPressable = p.pressable === true;
1059
1068
  const direction = p.direction === "horizontal" ? "horizontal" : "vertical";
@@ -1080,7 +1089,7 @@ function transformFrame(id, raw, children, parentDirection) {
1080
1089
  type: "view",
1081
1090
  props: {
1082
1091
  ...Object.keys(gridStyle).length ? { style: gridStyle } : {},
1083
- numColumns: p.columns ?? 2,
1092
+ numColumns: (_b = p.columns) != null ? _b : 2,
1084
1093
  ...access,
1085
1094
  ...hasSafeArea || isPressable ? {} : vis
1086
1095
  },
@@ -1204,6 +1213,7 @@ function transformFrame(id, raw, children, parentDirection) {
1204
1213
  });
1205
1214
  }
1206
1215
  function transformText(id, raw, parentDirection) {
1216
+ var _a, _b;
1207
1217
  const { actions, condition } = extractMeta(raw);
1208
1218
  const props = stripBridgeKeys(raw);
1209
1219
  const style = {};
@@ -1219,7 +1229,7 @@ function transformText(id, raw, parentDirection) {
1219
1229
  }
1220
1230
  if (props.color) style.color = props.color;
1221
1231
  if (props.fontSize !== void 0) style.fontSize = props.fontSize;
1222
- if (props.fontWeight) style.fontWeight = FONT_WEIGHT_MAP[props.fontWeight] ?? props.fontWeight;
1232
+ if (props.fontWeight) style.fontWeight = (_a = FONT_WEIGHT_MAP[props.fontWeight]) != null ? _a : props.fontWeight;
1223
1233
  if (props.fontFamily) style.fontFamily = props.fontFamily;
1224
1234
  if (props.fontStyle) style.fontStyle = props.fontStyle;
1225
1235
  if (props.lineHeight !== void 0) style.lineHeight = props.lineHeight;
@@ -1246,7 +1256,7 @@ function transformText(id, raw, parentDirection) {
1246
1256
  props: {
1247
1257
  // SDK contract: text content lives in the `value` prop.
1248
1258
  // The Craft editor stores text in `content`; map it to `value` here.
1249
- value: props.content ?? "",
1259
+ value: (_b = props.content) != null ? _b : "",
1250
1260
  ...Object.keys(style).length ? { style } : {},
1251
1261
  ...textProps,
1252
1262
  ...resolveAccessibilityProps(props),
@@ -1258,6 +1268,7 @@ function transformText(id, raw, parentDirection) {
1258
1268
  return node;
1259
1269
  }
1260
1270
  function transformImage(id, raw, children, parentDirection) {
1271
+ var _a, _b;
1261
1272
  const { actions, condition } = extractMeta(raw);
1262
1273
  const props = stripBridgeKeys(raw);
1263
1274
  const style = {};
@@ -1271,7 +1282,7 @@ function transformImage(id, raw, children, parentDirection) {
1271
1282
  if (props.src) imageProps.source = { uri: props.src };
1272
1283
  if (props.placeholder) imageProps.defaultSource = { uri: props.placeholder };
1273
1284
  if (props.fallback) imageProps.fallback = { uri: props.fallback };
1274
- imageProps.resizeMode = FIT_TO_RESIZE_MODE[props.fit ?? "cover"] ?? "cover";
1285
+ imageProps.resizeMode = (_b = FIT_TO_RESIZE_MODE[(_a = props.fit) != null ? _a : "cover"]) != null ? _b : "cover";
1275
1286
  if (props.background === true) imageProps.background = true;
1276
1287
  if (props.decorative) {
1277
1288
  imageProps.accessible = false;
@@ -1296,14 +1307,15 @@ function transformImage(id, raw, children, parentDirection) {
1296
1307
  return node;
1297
1308
  }
1298
1309
  function transformInput(id, raw, parentDirection) {
1310
+ var _a, _b, _c, _d, _e, _f, _g;
1299
1311
  const { actions, condition } = extractMeta(raw);
1300
1312
  const props = stripBridgeKeys(raw);
1301
1313
  const style = {};
1302
- resolveSizeModeRN(props.width ?? "fill", "width", style, parentDirection);
1314
+ resolveSizeModeRN((_a = props.width) != null ? _a : "fill", "width", style, parentDirection);
1303
1315
  Object.assign(style, resolvePaddingRN(props.padding));
1304
1316
  if (props.opacity !== void 0) style.opacity = props.opacity / 100;
1305
1317
  Object.assign(style, resolvePositionRN(props));
1306
- const inputTypeDefaults = INPUT_TYPE_MAP[props.inputType ?? "text"] ?? INPUT_TYPE_MAP.text;
1318
+ const inputTypeDefaults = (_c = INPUT_TYPE_MAP[(_b = props.inputType) != null ? _b : "text"]) != null ? _c : INPUT_TYPE_MAP.text;
1307
1319
  const node = {
1308
1320
  id,
1309
1321
  type: "textinput",
@@ -1316,12 +1328,12 @@ function transformInput(id, raw, parentDirection) {
1316
1328
  ...props.errorText !== void 0 ? { errorText: props.errorText } : {},
1317
1329
  ...inputTypeDefaults,
1318
1330
  ...props.autoCapitalize ? { autoCapitalize: props.autoCapitalize } : {},
1319
- returnKeyType: props.returnKey ?? "done",
1320
- multiline: props.multiline ?? false,
1331
+ returnKeyType: (_d = props.returnKey) != null ? _d : "done",
1332
+ multiline: (_e = props.multiline) != null ? _e : false,
1321
1333
  ...props.multiline && props.minLines ? { numberOfLines: props.minLines } : {},
1322
1334
  ...props.multiline && props.maxLines ? { maxNumberOfLines: props.maxLines } : {},
1323
- variant: props.variant ?? "outline",
1324
- size: props.size ?? "md",
1335
+ variant: (_f = props.variant) != null ? _f : "outline",
1336
+ size: (_g = props.size) != null ? _g : "md",
1325
1337
  ...props.leadingIcon ? { leadingIcon: props.leadingIcon } : {},
1326
1338
  ...props.trailingIcon ? { trailingIcon: props.trailingIcon } : {},
1327
1339
  ...resolveAccessibilityProps(props),
@@ -1333,9 +1345,10 @@ function transformInput(id, raw, parentDirection) {
1333
1345
  return node;
1334
1346
  }
1335
1347
  function transformList(id, raw, children, parentDirection) {
1348
+ var _a, _b, _c;
1336
1349
  const { actions, condition } = extractMeta(raw);
1337
1350
  const props = stripBridgeKeys(raw);
1338
- const listType = props.type ?? "stack";
1351
+ const listType = (_a = props.type) != null ? _a : "stack";
1339
1352
  const direction = props.direction === "horizontal" ? "horizontal" : "vertical";
1340
1353
  const edges = safeAreaEdges(props.safeArea);
1341
1354
  const hasSafeArea = edges.length > 0;
@@ -1357,8 +1370,8 @@ function transformList(id, raw, children, parentDirection) {
1357
1370
  // `data` holds the binding expression for the list items array.
1358
1371
  // RecursiveRenderer resolves it and passes items to the FlatList primitive.
1359
1372
  data: props.data,
1360
- keyExtractor: props.keyExtractor ?? "id",
1361
- ...listType === "grid" ? { numColumns: props.columns ?? 2 } : {},
1373
+ keyExtractor: (_b = props.keyExtractor) != null ? _b : "id",
1374
+ ...listType === "grid" ? { numColumns: (_c = props.columns) != null ? _c : 2 } : {},
1362
1375
  ...listType === "grid" && props.columnGap ? { columnGap: props.columnGap } : {},
1363
1376
  ...listType === "grid" && props.rowGap ? { rowGap: props.rowGap } : {},
1364
1377
  horizontal: direction === "horizontal",
@@ -1390,6 +1403,7 @@ function transformList(id, raw, children, parentDirection) {
1390
1403
  return savNode;
1391
1404
  }
1392
1405
  function transformIcon(id, raw) {
1406
+ var _a, _b;
1393
1407
  const { actions, condition } = extractMeta(raw);
1394
1408
  const props = stripBridgeKeys(raw);
1395
1409
  const style = {};
@@ -1400,8 +1414,8 @@ function transformIcon(id, raw) {
1400
1414
  type: "icon",
1401
1415
  props: {
1402
1416
  name: props.name,
1403
- set: props.set ?? "default",
1404
- size: props.size ?? 24,
1417
+ set: (_a = props.set) != null ? _a : "default",
1418
+ size: (_b = props.size) != null ? _b : 24,
1405
1419
  ...props.color ? { color: props.color } : {},
1406
1420
  ...Object.keys(style).length ? { style } : {},
1407
1421
  ...resolveAccessibilityProps(props),
@@ -1413,18 +1427,19 @@ function transformIcon(id, raw) {
1413
1427
  return node;
1414
1428
  }
1415
1429
  function buildNodeFromSchema(nodeId, schema, customComponents, visited, parentId) {
1430
+ var _a, _b, _c, _d, _e;
1416
1431
  if (visited.has(nodeId)) {
1417
1432
  throw new Error(`Circular reference detected at node ${nodeId}`);
1418
1433
  }
1419
1434
  visited.add(nodeId);
1420
1435
  const node = schema[nodeId];
1421
1436
  if (!node) throw new Error(`Node not found: ${nodeId}`);
1422
- const resolvedName = node.type?.resolvedName;
1437
+ const resolvedName = (_a = node.type) == null ? void 0 : _a.resolvedName;
1423
1438
  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";
1439
+ const raw = (_b = node.props) != null ? _b : {};
1440
+ const parentDirection = parentId ? ((_d = (_c = schema[parentId]) == null ? void 0 : _c.props) == null ? void 0 : _d["direction"]) === "horizontal" ? "horizontal" : "vertical" : "vertical";
1426
1441
  const outputId = nodeId === "ROOT" ? "root" : nodeId;
1427
- const childNodes = (node.nodes ?? []).map(
1442
+ const childNodes = ((_e = node.nodes) != null ? _e : []).map(
1428
1443
  (childId) => buildNodeFromSchema(childId, schema, customComponents, visited, nodeId)
1429
1444
  );
1430
1445
  switch (resolvedName) {
@@ -1452,7 +1467,7 @@ function resolveCustomComponent(id, raw, parentDirection, customComponents) {
1452
1467
  const { actions, condition } = extractMeta(raw);
1453
1468
  const props = stripBridgeKeys(raw);
1454
1469
  const { componentId, componentKey, propValues, ...frameProps } = props;
1455
- const key = componentKey ?? componentId;
1470
+ const key = componentKey != null ? componentKey : componentId;
1456
1471
  const def = key ? customComponents[key] : void 0;
1457
1472
  const wrapperStyle = buildFrameStyle(frameProps, parentDirection);
1458
1473
  const vis = props.visible !== void 0 && props.visible !== true ? { visible: props.visible } : {};