@builder.io/sdk-react-native 0.0.10 → 0.0.12

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-react-native",
3
3
  "description": "Builder.io SDK for React Native",
4
- "version": "0.0.10",
4
+ "version": "0.0.12",
5
5
  "main": "src/index.js",
6
6
  "files": [
7
7
  "src"
@@ -12,6 +12,7 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "@react-native-async-storage/async-storage": "^1.17.10",
15
+ "node-fetch": "^2.6.1",
15
16
  "react-native-render-html": "^6.3.4",
16
17
  "react-native-storage": "^1.0.1",
17
18
  "react-native-video": "^5.1.1"
@@ -21,8 +21,9 @@ import BaseText from "../BaseText";
21
21
  import * as React from "react";
22
22
  import { View, StyleSheet } from "react-native";
23
23
  function Button(props) {
24
- return /* @__PURE__ */ React.createElement(React.Fragment, null, props.link ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(View, __spreadProps(__spreadValues({}, props.attributes), {
25
- role: "button",
24
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, props.link ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(View, __spreadProps(__spreadValues({
25
+ role: "button"
26
+ }, props.attributes), {
26
27
  href: props.link,
27
28
  target: props.openLinkInNewTab ? "_blank" : void 0
28
29
  }), /* @__PURE__ */ React.createElement(BaseText, null, props.text))) : /* @__PURE__ */ React.createElement(View, __spreadProps(__spreadValues({}, props.attributes), {
@@ -1,4 +1,4 @@
1
- import { markSerializable } from "../util.js";
1
+ import { serializeFn } from "../util.js";
2
2
  const componentInfo = {
3
3
  name: "Columns",
4
4
  builtIn: true,
@@ -187,7 +187,7 @@ const componentInfo = {
187
187
  ]
188
188
  }
189
189
  ],
190
- onChange: markSerializable((options) => {
190
+ onChange: serializeFn((options) => {
191
191
  function clearWidths() {
192
192
  columns.forEach((col) => {
193
193
  col.delete("width");
@@ -1,4 +1,4 @@
1
- import { markSerializable } from "../util.js";
1
+ import { serializeFn } from "../util.js";
2
2
  const componentInfo = {
3
3
  name: "Embed",
4
4
  static: true,
@@ -10,7 +10,7 @@ const componentInfo = {
10
10
  required: true,
11
11
  defaultValue: "",
12
12
  helperText: "e.g. enter a youtube url, google map, etc",
13
- onChange: markSerializable((options) => {
13
+ onChange: serializeFn((options) => {
14
14
  const url = options.get("url");
15
15
  if (url) {
16
16
  options.set("content", "Loading...");
@@ -1,6 +1,4 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
2
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
3
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
4
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -16,7 +14,6 @@ var __spreadValues = (a, b) => {
16
14
  }
17
15
  return a;
18
16
  };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
17
  var __async = (__this, __arguments, generator) => {
21
18
  return new Promise((resolve, reject) => {
22
19
  var fulfilled = (value) => {
@@ -194,14 +191,14 @@ function FormComponent(props) {
194
191
  }
195
192
  }
196
193
  const builderContext = useContext(BuilderContext);
197
- return /* @__PURE__ */ React.createElement(View, __spreadProps(__spreadValues({}, props.attributes), {
194
+ return /* @__PURE__ */ React.createElement(View, __spreadValues({
198
195
  validate: props.validate,
199
196
  ref: formRef,
200
197
  action: !props.sendWithJs && props.action,
201
198
  method: props.method,
202
199
  name: props.name,
203
200
  onSubmit: (event) => onSubmit(event)
204
- }), " ", props.builderBlock && props.builderBlock.children ? /* @__PURE__ */ React.createElement(React.Fragment, null, (_b = (_a = props.builderBlock) == null ? void 0 : _a.children) == null ? void 0 : _b.map((block) => /* @__PURE__ */ React.createElement(RenderBlock, {
201
+ }, props.attributes), " ", props.builderBlock && props.builderBlock.children ? /* @__PURE__ */ React.createElement(React.Fragment, null, (_b = (_a = props.builderBlock) == null ? void 0 : _a.children) == null ? void 0 : _b.map((block) => /* @__PURE__ */ React.createElement(RenderBlock, {
205
202
  block,
206
203
  context: builderContext
207
204
  }))) : null, " ", submissionState() === "error" ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(BuilderBlocks, {
@@ -1,4 +1,4 @@
1
- import { markSerializable } from "../util.js";
1
+ import { serializeFn } from "../util.js";
2
2
  const componentInfo = {
3
3
  name: "Image",
4
4
  static: true,
@@ -19,7 +19,7 @@ const componentInfo = {
19
19
  allowedFileTypes: ["jpeg", "jpg", "png", "svg"],
20
20
  required: true,
21
21
  defaultValue: "https://cdn.builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d",
22
- onChange: markSerializable((options) => {
22
+ onChange: serializeFn((options) => {
23
23
  const DEFAULT_ASPECT_RATIO = 0.7041;
24
24
  options.delete("srcset");
25
25
  options.delete("noWebp");
@@ -1,6 +1,4 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
2
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
3
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
4
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -16,12 +14,11 @@ var __spreadValues = (a, b) => {
16
14
  }
17
15
  return a;
18
16
  };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
17
  import * as React from "react";
21
18
  import { View } from "react-native";
22
19
  import { isEditing } from "../../functions/is-editing.js";
23
20
  function ImgComponent(props) {
24
- return /* @__PURE__ */ React.createElement(View, __spreadProps(__spreadValues({}, props.attributes), {
21
+ return /* @__PURE__ */ React.createElement(View, __spreadValues({
25
22
  style: {
26
23
  objectFit: props.backgroundSize || "cover",
27
24
  objectPosition: props.backgroundPosition || "center"
@@ -29,7 +26,7 @@ function ImgComponent(props) {
29
26
  key: isEditing() && props.imgSrc || "default-key",
30
27
  alt: props.altText,
31
28
  src: props.imgSrc || props.image
32
- }));
29
+ }, props.attributes));
33
30
  }
34
31
  export {
35
32
  ImgComponent as default
@@ -1,6 +1,4 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
2
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
3
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
4
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -16,14 +14,13 @@ var __spreadValues = (a, b) => {
16
14
  }
17
15
  return a;
18
16
  };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
17
  import BaseText from "../BaseText";
21
18
  import * as React from "react";
22
19
  import { View } from "react-native";
23
20
  function SubmitButton(props) {
24
- return /* @__PURE__ */ React.createElement(View, __spreadProps(__spreadValues({}, props.attributes), {
21
+ return /* @__PURE__ */ React.createElement(View, __spreadValues({
25
22
  type: "submit"
26
- }), /* @__PURE__ */ React.createElement(BaseText, null, props.text));
23
+ }, props.attributes), /* @__PURE__ */ React.createElement(BaseText, null, props.text));
27
24
  }
28
25
  export {
29
26
  SubmitButton as default
@@ -1,7 +1,8 @@
1
- function markSerializable(fn) {
2
- fn.__qwik_serializable__ = true;
3
- return fn;
4
- }
1
+ const serializeFn = (fnValue) => {
2
+ const fnStr = fnValue.toString().trim();
3
+ const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(");
4
+ return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
5
+ };
5
6
  export {
6
- markSerializable
7
+ serializeFn
7
8
  };
@@ -30,6 +30,7 @@ var __objRest = (source, exclude) => {
30
30
  return target;
31
31
  };
32
32
  import * as React from "react";
33
+ import { View } from "react-native";
33
34
  import { useState } from "react";
34
35
  import { getBlockActions } from "../../functions/get-block-actions.js";
35
36
  import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
@@ -68,7 +69,7 @@ function RenderBlock(props) {
68
69
  return ref;
69
70
  }
70
71
  }
71
- function tagName() {
72
+ function tag() {
72
73
  return getBlockTag(useBlock());
73
74
  }
74
75
  function useBlock() {
@@ -98,7 +99,7 @@ function RenderBlock(props) {
98
99
  function renderComponentProps() {
99
100
  var _a2;
100
101
  return {
101
- blockChildren: children(),
102
+ blockChildren: useChildren(),
102
103
  componentRef: (_a2 = component == null ? void 0 : component()) == null ? void 0 : _a2.component,
103
104
  componentOptions: __spreadValues(__spreadValues({}, getBlockComponentOptions(useBlock())), shouldWrap() ? {} : {
104
105
  attributes: attributes()
@@ -106,14 +107,14 @@ function RenderBlock(props) {
106
107
  context: childrenContext()
107
108
  };
108
109
  }
109
- function children() {
110
+ function useChildren() {
110
111
  var _a2;
111
112
  return (_a2 = useBlock().children) != null ? _a2 : [];
112
113
  }
113
114
  function childrenWithoutParentComponent() {
114
115
  var _a2;
115
116
  const shouldRenderChildrenOutsideRef = !((_a2 = component == null ? void 0 : component()) == null ? void 0 : _a2.component) && !repeatItemData();
116
- return shouldRenderChildrenOutsideRef ? children() : [];
117
+ return shouldRenderChildrenOutsideRef ? useChildren() : [];
117
118
  }
118
119
  function repeatItemData() {
119
120
  const _a2 = props.block, { repeat } = _a2, blockWithoutRepeat = __objRest(_a2, ["repeat"]);
@@ -174,12 +175,11 @@ function RenderBlock(props) {
174
175
  }
175
176
  const [componentInfo, setComponentInfo] = useState(() => null);
176
177
  const RenderComponentTagRef = renderComponentTag();
177
- const TagNameRef = tagName();
178
- return /* @__PURE__ */ React.createElement(React.Fragment, null, shouldWrap() ? /* @__PURE__ */ React.createElement(React.Fragment, null, isEmptyHtmlElement(tagName()) ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(TagNameRef, __spreadValues({}, attributes()))) : null, !isEmptyHtmlElement(tagName()) && repeatItemData() ? /* @__PURE__ */ React.createElement(React.Fragment, null, (_a = repeatItemData()) == null ? void 0 : _a.map((data, index) => /* @__PURE__ */ React.createElement(RenderRepeatedBlock, {
178
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, shouldWrap() ? /* @__PURE__ */ React.createElement(React.Fragment, null, isEmptyHtmlElement(tag()) ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(View, __spreadValues({}, attributes()))) : null, !isEmptyHtmlElement(tag()) && repeatItemData() ? /* @__PURE__ */ React.createElement(React.Fragment, null, (_a = repeatItemData()) == null ? void 0 : _a.map((data, index) => /* @__PURE__ */ React.createElement(RenderRepeatedBlock, {
179
179
  key: index,
180
180
  repeatContext: data.context,
181
181
  block: data.block
182
- }))) : null, !isEmptyHtmlElement(tagName()) && !repeatItemData() ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(TagNameRef, __spreadValues({}, attributes()), /* @__PURE__ */ React.createElement(RenderComponentTagRef, __spreadValues({}, renderComponentProps())), (_b = childrenWithoutParentComponent()) == null ? void 0 : _b.map((child) => /* @__PURE__ */ React.createElement(RenderBlock, {
182
+ }))) : null, !isEmptyHtmlElement(tag()) && !repeatItemData() ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(View, __spreadValues({}, attributes()), /* @__PURE__ */ React.createElement(RenderComponentTagRef, __spreadValues({}, renderComponentProps())), (_b = childrenWithoutParentComponent()) == null ? void 0 : _b.map((child) => /* @__PURE__ */ React.createElement(RenderBlock, {
183
183
  key: "render-block-" + child.id,
184
184
  block: child,
185
185
  context: childrenContext()
@@ -0,0 +1,8 @@
1
+ import * as React from "react";
2
+ import { View } from "react-native";
3
+ function BuilderEditing(props) {
4
+ return /* @__PURE__ */ React.createElement(View, null);
5
+ }
6
+ export {
7
+ BuilderEditing as default
8
+ };
@@ -33,7 +33,7 @@ import {
33
33
  components,
34
34
  createRegisterComponentMessage
35
35
  } from "../../functions/register-component.js";
36
- import { track } from "../../functions/track.js";
36
+ import { _track } from "../../functions/track.js";
37
37
  import RenderBlocks from "../render-blocks.js";
38
38
  import RenderContentStyles from "./components/render-styles.js";
39
39
  import {
@@ -114,13 +114,16 @@ function RenderContent(props) {
114
114
  return {};
115
115
  }
116
116
  function onClick(_event) {
117
- var _a2;
117
+ var _a2, _b2;
118
118
  if (useContent()) {
119
- track({
119
+ const variationId = (_a2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _a2.testVariationId;
120
+ const contentId = (_b2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _b2.id;
121
+ _track({
120
122
  type: "click",
121
123
  canTrack: canTrackToUse(),
122
- contentId: (_a2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _a2.id,
123
- orgId: props.apiKey
124
+ contentId,
125
+ apiKey: props.apiKey,
126
+ variationId: variationId !== contentId ? variationId : void 0
124
127
  });
125
128
  }
126
129
  }
@@ -171,7 +174,7 @@ function RenderContent(props) {
171
174
  return Boolean((((_b2 = (_a2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _a2.data) == null ? void 0 : _b2.cssCode) || ((_e2 = (_d2 = (_c2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _c2.data) == null ? void 0 : _d2.customFonts) == null ? void 0 : _e2.length)) && TARGET !== "reactNative");
172
175
  }
173
176
  useEffect(() => {
174
- var _a2;
177
+ var _a2, _b2;
175
178
  if (isBrowser()) {
176
179
  if (isEditing()) {
177
180
  setForceReRenderCount(forceReRenderCount + 1);
@@ -186,11 +189,14 @@ function RenderContent(props) {
186
189
  window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
187
190
  }
188
191
  if (useContent()) {
189
- track({
192
+ const variationId = (_a2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _a2.testVariationId;
193
+ const contentId = (_b2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _b2.id;
194
+ _track({
190
195
  type: "impression",
191
196
  canTrack: canTrackToUse(),
192
- contentId: (_a2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _a2.id,
193
- orgId: props.apiKey
197
+ contentId,
198
+ apiKey: props.apiKey,
199
+ variationId: variationId !== contentId ? variationId : void 0
194
200
  });
195
201
  }
196
202
  if (isPreviewing()) {
@@ -3,15 +3,14 @@ import { View, Text } from "react-native";
3
3
  import { TARGET } from "../constants/target.js";
4
4
  function RenderInlinedStyles(props) {
5
5
  function injectedStyleScript() {
6
- return `<${tagName()}>${props.styles}</${tagName()}>`;
6
+ return `<${tag()}>${props.styles}</${tag()}>`;
7
7
  }
8
- function tagName() {
8
+ function tag() {
9
9
  return "style";
10
10
  }
11
- const TagNameRef = tagName();
12
11
  return /* @__PURE__ */ React.createElement(React.Fragment, null, TARGET === "svelte" ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(View, {
13
12
  dangerouslySetInnerHTML: { __html: injectedStyleScript() }
14
- })) : /* @__PURE__ */ React.createElement(TagNameRef, null, /* @__PURE__ */ React.createElement(Text, null, props.styles)));
13
+ })) : /* @__PURE__ */ React.createElement(View, null, /* @__PURE__ */ React.createElement(Text, null, props.styles)));
15
14
  }
16
15
  export {
17
16
  RenderInlinedStyles as default
@@ -56,9 +56,13 @@ const generateContentUrl = (options) => {
56
56
  query,
57
57
  noTraverse = false,
58
58
  model,
59
- apiKey
59
+ apiKey,
60
+ includeRefs = true
60
61
  } = options;
61
- const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}`);
62
+ if (!apiKey) {
63
+ throw new Error("Missing API key");
64
+ }
65
+ const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}`);
62
66
  const queryOptions = __spreadValues(__spreadValues({}, getBuilderSearchParamsFromWindow()), normalizeSearchParams(options.options || {}));
63
67
  const flattened = flatten(queryOptions);
64
68
  for (const key in flattened) {
@@ -29,6 +29,7 @@ var __objRest = (source, exclude) => {
29
29
  }
30
30
  return target;
31
31
  };
32
+ import { serializeFn } from "../blocks/util.js";
32
33
  import { fastClone } from "./fast-clone.js";
33
34
  const components = [];
34
35
  function registerComponent(component, info) {
@@ -48,11 +49,6 @@ const createRegisterComponentMessage = (_a) => {
48
49
  };
49
50
  };
50
51
  const serializeValue = (value) => typeof value === "function" ? serializeFn(value) : fastClone(value);
51
- const serializeFn = (fnValue) => {
52
- const fnStr = fnValue.toString().trim();
53
- const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(");
54
- return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
55
- };
56
52
  const prepareComponentInfoToSend = (_c) => {
57
53
  var _d = _c, {
58
54
  inputs
@@ -71,23 +71,24 @@ const createEvent = (_a) => __async(void 0, null, function* () {
71
71
  var _b = _a, {
72
72
  type: eventType,
73
73
  canTrack,
74
- orgId,
75
- contentId
74
+ apiKey,
75
+ metadata
76
76
  } = _b, properties = __objRest(_b, [
77
77
  "type",
78
78
  "canTrack",
79
- "orgId",
80
- "contentId"
79
+ "apiKey",
80
+ "metadata"
81
81
  ]);
82
82
  return {
83
83
  type: eventType,
84
- data: __spreadProps(__spreadValues(__spreadValues({}, properties), yield getTrackingEventData({ canTrack })), {
85
- ownerId: orgId,
86
- contentId
84
+ data: __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, properties), {
85
+ metadata: JSON.stringify(metadata)
86
+ }), yield getTrackingEventData({ canTrack })), {
87
+ ownerId: apiKey
87
88
  })
88
89
  };
89
90
  });
90
- function track(eventProps) {
91
+ function _track(eventProps) {
91
92
  return __async(this, null, function* () {
92
93
  if (!eventProps.canTrack) {
93
94
  return;
@@ -112,6 +113,8 @@ function track(eventProps) {
112
113
  });
113
114
  });
114
115
  }
116
+ const track = (args) => _track(__spreadProps(__spreadValues({}, args), { canTrack: true }));
115
117
  export {
118
+ _track,
116
119
  track
117
120
  };
package/src/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./index-helpers/top-of-file.js";
1
+ export * from "./index-helpers/top-of-file.js";
2
2
  import "./scripts/init-editing.js";
3
3
  export * from "./index-helpers/blocks-exports.js";
4
4
  export * from "./functions/is-editing.js";
@@ -8,3 +8,7 @@ export * from "./functions/register.js";
8
8
  export * from "./functions/set-editor-settings.js";
9
9
  export * from "./functions/get-content/index.js";
10
10
  export * from "./functions/get-builder-search-params/index.js";
11
+ import { track } from "./functions/track";
12
+ export {
13
+ track
14
+ };
@@ -19,8 +19,13 @@ const registerInsertMenu = () => {
19
19
  ]
20
20
  });
21
21
  };
22
+ let isSetupForEditing = false;
22
23
  const setupBrowserForEditing = () => {
23
24
  var _a;
25
+ if (isSetupForEditing) {
26
+ return;
27
+ }
28
+ isSetupForEditing = true;
24
29
  if (isBrowser()) {
25
30
  (_a = window.parent) == null ? void 0 : _a.postMessage({
26
31
  type: "builder.sdkInfo",