@builder.io/sdk-react-native 0.0.12 → 0.0.14
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 +2 -1
- package/src/blocks/columns/columns.js +1 -2
- package/src/blocks/symbol/symbol.js +3 -4
- package/src/blocks/text/text.js +5 -3
- package/src/components/render-block/block-styles.js +9 -3
- package/src/components/render-block/render-block.js +9 -6
- package/src/components/render-block/render-component.js +1 -2
- package/src/components/render-content/render-content.js +14 -6
- package/src/constants/device-sizes.js +29 -2
- package/src/functions/evaluate.js +4 -3
- package/src/functions/get-block-actions-handler.js +8 -9
- package/src/functions/get-block-actions.js +2 -2
- package/src/functions/get-builder-search-params/index.js +2 -1
- package/src/functions/get-content/index.js +4 -3
- package/src/functions/track.js +4 -0
- package/src/scripts/init-editing.js +12 -5
- package/src/functions/mark-mutable.js +0 -10
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder.io/sdk-react-native",
|
|
3
3
|
"description": "Builder.io SDK for React Native",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.14",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"src"
|
|
8
8
|
],
|
|
9
9
|
"scripts": {
|
|
10
|
+
"build": "echo 'no need to build react-native SDK'",
|
|
10
11
|
"release:patch": "npm version patch --no-git-tag-version && npm publish --access public",
|
|
11
12
|
"release:dev": "npm version prerelease --no-git-tag-version && npm publish --tag dev --access public"
|
|
12
13
|
},
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { View, StyleSheet } from "react-native";
|
|
3
3
|
import RenderBlocks from "../../components/render-blocks.js";
|
|
4
|
-
import { markMutable } from "../../functions/mark-mutable";
|
|
5
4
|
function Columns(props) {
|
|
6
5
|
var _a;
|
|
7
6
|
function getGutterSize() {
|
|
@@ -48,7 +47,7 @@ function Columns(props) {
|
|
|
48
47
|
style: styles.view2,
|
|
49
48
|
key: index
|
|
50
49
|
}, /* @__PURE__ */ React.createElement(RenderBlocks, {
|
|
51
|
-
blocks:
|
|
50
|
+
blocks: column.blocks,
|
|
52
51
|
path: `component.options.columns.${index}.blocks`,
|
|
53
52
|
parent: props.builderBlock.id,
|
|
54
53
|
styleProp: {
|
|
@@ -23,7 +23,6 @@ import { useState, useContext, useEffect } from "react";
|
|
|
23
23
|
import RenderContent from "../../components/render-content/render-content.js";
|
|
24
24
|
import BuilderContext from "../../context/builder.context.js";
|
|
25
25
|
import { getContent } from "../../functions/get-content/index.js";
|
|
26
|
-
import { markMutable } from "../../functions/mark-mutable";
|
|
27
26
|
function Symbol(props) {
|
|
28
27
|
var _a, _b, _c, _d, _e;
|
|
29
28
|
const [className, setClassName] = useState(() => "builder-symbol");
|
|
@@ -54,10 +53,10 @@ function Symbol(props) {
|
|
|
54
53
|
}), /* @__PURE__ */ React.createElement(RenderContent, {
|
|
55
54
|
apiKey: builderContext.apiKey,
|
|
56
55
|
context: builderContext.context,
|
|
57
|
-
customComponents:
|
|
58
|
-
data:
|
|
56
|
+
customComponents: Object.values(builderContext.registeredComponents),
|
|
57
|
+
data: __spreadValues(__spreadValues(__spreadValues({}, (_a = props.symbol) == null ? void 0 : _a.data), builderContext.state), (_d = (_c = (_b = props.symbol) == null ? void 0 : _b.content) == null ? void 0 : _c.data) == null ? void 0 : _d.state),
|
|
59
58
|
model: (_e = props.symbol) == null ? void 0 : _e.model,
|
|
60
|
-
content:
|
|
59
|
+
content: contentToUse()
|
|
61
60
|
}));
|
|
62
61
|
}
|
|
63
62
|
export {
|
package/src/blocks/text/text.js
CHANGED
|
@@ -16,6 +16,7 @@ var __spreadValues = (a, b) => {
|
|
|
16
16
|
};
|
|
17
17
|
import * as React from "react";
|
|
18
18
|
import HTML from "react-native-render-html";
|
|
19
|
+
import BuilderContext from "../../context/builder.context";
|
|
19
20
|
function camelToKebabCase(string) {
|
|
20
21
|
return string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
|
|
21
22
|
}
|
|
@@ -39,8 +40,8 @@ function getBlockStyles(block) {
|
|
|
39
40
|
}
|
|
40
41
|
return styles;
|
|
41
42
|
}
|
|
42
|
-
function getCss(block) {
|
|
43
|
-
const styleObject = pick(getBlockStyles(block), PICK_STYLES);
|
|
43
|
+
function getCss(block, inheritedStyles) {
|
|
44
|
+
const styleObject = __spreadValues(__spreadValues({}, inheritedStyles), pick(getBlockStyles(block), PICK_STYLES));
|
|
44
45
|
if (!styleObject) {
|
|
45
46
|
return "";
|
|
46
47
|
}
|
|
@@ -54,9 +55,10 @@ function getCss(block) {
|
|
|
54
55
|
return str;
|
|
55
56
|
}
|
|
56
57
|
function Text(props) {
|
|
58
|
+
const builderContext = React.useContext(BuilderContext);
|
|
57
59
|
return /* @__PURE__ */ React.createElement(HTML, {
|
|
58
60
|
source: {
|
|
59
|
-
html: `<div style="${getCss(props.builderBlock)}">${props.text || ""}</div>`
|
|
61
|
+
html: `<div style="${getCss(props.builderBlock, builderContext.inheritedStyles)}">${props.text || ""}</div>`
|
|
60
62
|
}
|
|
61
63
|
});
|
|
62
64
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
getMaxWidthQueryForSize,
|
|
4
|
+
getSizesForBreakpoints
|
|
5
|
+
} from "../../constants/device-sizes.js";
|
|
3
6
|
import { TARGET } from "../../constants/target.js";
|
|
4
7
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
5
8
|
import { createCssClass } from "../../helpers/css.js";
|
|
@@ -14,7 +17,10 @@ function BlockStyles(props) {
|
|
|
14
17
|
});
|
|
15
18
|
}
|
|
16
19
|
function css() {
|
|
20
|
+
var _a;
|
|
17
21
|
const styles = useBlock().responsiveStyles;
|
|
22
|
+
const content = props.context.content;
|
|
23
|
+
const sizesWithUpdatedBreakpoints = getSizesForBreakpoints(((_a = content == null ? void 0 : content.meta) == null ? void 0 : _a.breakpoints) || {});
|
|
18
24
|
const largeStyles = styles == null ? void 0 : styles.large;
|
|
19
25
|
const mediumStyles = styles == null ? void 0 : styles.medium;
|
|
20
26
|
const smallStyles = styles == null ? void 0 : styles.small;
|
|
@@ -26,12 +32,12 @@ function BlockStyles(props) {
|
|
|
26
32
|
const mediumStylesClass = mediumStyles ? createCssClass({
|
|
27
33
|
className,
|
|
28
34
|
styles: mediumStyles,
|
|
29
|
-
mediaQuery: getMaxWidthQueryForSize("medium")
|
|
35
|
+
mediaQuery: getMaxWidthQueryForSize("medium", sizesWithUpdatedBreakpoints)
|
|
30
36
|
}) : "";
|
|
31
37
|
const smallStylesClass = smallStyles ? createCssClass({
|
|
32
38
|
className,
|
|
33
39
|
styles: smallStyles,
|
|
34
|
-
mediaQuery: getMaxWidthQueryForSize("small")
|
|
40
|
+
mediaQuery: getMaxWidthQueryForSize("small", sizesWithUpdatedBreakpoints)
|
|
35
41
|
}) : "";
|
|
36
42
|
return [largeStylesClass, mediumStylesClass, smallStylesClass].join(" ");
|
|
37
43
|
}
|
|
@@ -80,12 +80,15 @@ function RenderBlock(props) {
|
|
|
80
80
|
shouldEvaluateBindings: true
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
|
-
function
|
|
84
|
-
return
|
|
83
|
+
function actions() {
|
|
84
|
+
return getBlockActions({
|
|
85
85
|
block: useBlock(),
|
|
86
86
|
state: props.context.state,
|
|
87
87
|
context: props.context.context
|
|
88
|
-
})
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function attributes() {
|
|
91
|
+
return __spreadValues(__spreadValues({}, getBlockProperties(useBlock())), TARGET === "reactNative" ? {
|
|
89
92
|
style: getReactNativeBlockStyles({
|
|
90
93
|
block: useBlock(),
|
|
91
94
|
context: props.context
|
|
@@ -102,7 +105,7 @@ function RenderBlock(props) {
|
|
|
102
105
|
blockChildren: useChildren(),
|
|
103
106
|
componentRef: (_a2 = component == null ? void 0 : component()) == null ? void 0 : _a2.component,
|
|
104
107
|
componentOptions: __spreadValues(__spreadValues({}, getBlockComponentOptions(useBlock())), shouldWrap() ? {} : {
|
|
105
|
-
attributes: attributes()
|
|
108
|
+
attributes: __spreadValues(__spreadValues({}, attributes()), actions())
|
|
106
109
|
}),
|
|
107
110
|
context: childrenContext()
|
|
108
111
|
};
|
|
@@ -175,11 +178,11 @@ function RenderBlock(props) {
|
|
|
175
178
|
}
|
|
176
179
|
const [componentInfo, setComponentInfo] = useState(() => null);
|
|
177
180
|
const RenderComponentTagRef = renderComponentTag();
|
|
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, {
|
|
181
|
+
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(__spreadValues({}, attributes()), actions()))) : null, !isEmptyHtmlElement(tag()) && repeatItemData() ? /* @__PURE__ */ React.createElement(React.Fragment, null, (_a = repeatItemData()) == null ? void 0 : _a.map((data, index) => /* @__PURE__ */ React.createElement(RenderRepeatedBlock, {
|
|
179
182
|
key: index,
|
|
180
183
|
repeatContext: data.context,
|
|
181
184
|
block: data.block
|
|
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, {
|
|
185
|
+
}))) : null, !isEmptyHtmlElement(tag()) && !repeatItemData() ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(View, __spreadValues(__spreadValues({}, attributes()), actions()), /* @__PURE__ */ React.createElement(RenderComponentTagRef, __spreadValues({}, renderComponentProps())), (_b = childrenWithoutParentComponent()) == null ? void 0 : _b.map((child) => /* @__PURE__ */ React.createElement(RenderBlock, {
|
|
183
186
|
key: "render-block-" + child.id,
|
|
184
187
|
block: child,
|
|
185
188
|
context: childrenContext()
|
|
@@ -17,11 +17,10 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
import * as React from "react";
|
|
18
18
|
import BlockStyles from "./block-styles.js";
|
|
19
19
|
import RenderBlock from "./render-block.js";
|
|
20
|
-
import { markPropsMutable } from "../../functions/mark-mutable.js";
|
|
21
20
|
function RenderComponent(props) {
|
|
22
21
|
var _a, _b;
|
|
23
22
|
const ComponentRefRef = props.componentRef;
|
|
24
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, props.componentRef ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(ComponentRefRef, __spreadValues({},
|
|
23
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, props.componentRef ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(ComponentRefRef, __spreadValues({}, props.componentOptions), (_a = props.blockChildren) == null ? void 0 : _a.map((child) => /* @__PURE__ */ React.createElement(RenderBlock, {
|
|
25
24
|
key: "render-block-" + child.id,
|
|
26
25
|
block: child,
|
|
27
26
|
context: props.context
|
|
@@ -22,7 +22,6 @@ import { View } from "react-native";
|
|
|
22
22
|
import { useState, useRef, useEffect } from "react";
|
|
23
23
|
import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
|
|
24
24
|
import { TARGET } from "../../constants/target.js";
|
|
25
|
-
import BuilderContext from "../../context/builder.context.js";
|
|
26
25
|
import { evaluate } from "../../functions/evaluate.js";
|
|
27
26
|
import { getContent } from "../../functions/get-content/index.js";
|
|
28
27
|
import { getFetch } from "../../functions/get-fetch.js";
|
|
@@ -36,11 +35,11 @@ import {
|
|
|
36
35
|
import { _track } from "../../functions/track.js";
|
|
37
36
|
import RenderBlocks from "../render-blocks.js";
|
|
38
37
|
import RenderContentStyles from "./components/render-styles.js";
|
|
38
|
+
import BuilderContext from "../../context/builder.context.js";
|
|
39
39
|
import {
|
|
40
40
|
registerInsertMenu,
|
|
41
41
|
setupBrowserForEditing
|
|
42
42
|
} from "../../scripts/init-editing.js";
|
|
43
|
-
import { markMutable } from "../../functions/mark-mutable.js";
|
|
44
43
|
function RenderContent(props) {
|
|
45
44
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
46
45
|
const elementRef = useRef(null);
|
|
@@ -63,7 +62,9 @@ function RenderContent(props) {
|
|
|
63
62
|
const [overrideState, setOverrideState] = useState(() => ({}));
|
|
64
63
|
function contentState() {
|
|
65
64
|
var _a2, _b2;
|
|
66
|
-
return __spreadValues(__spreadValues(__spreadValues({}, (_b2 = (_a2 = props.content) == null ? void 0 : _a2.data) == null ? void 0 : _b2.state), props.data),
|
|
65
|
+
return __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, (_b2 = (_a2 = props.content) == null ? void 0 : _a2.data) == null ? void 0 : _b2.state), props.data), props.locale ? {
|
|
66
|
+
locale: props.locale
|
|
67
|
+
} : {}), overrideState);
|
|
67
68
|
}
|
|
68
69
|
function contextContext() {
|
|
69
70
|
return props.context || {};
|
|
@@ -175,11 +176,18 @@ function RenderContent(props) {
|
|
|
175
176
|
}
|
|
176
177
|
useEffect(() => {
|
|
177
178
|
var _a2, _b2;
|
|
179
|
+
if (!props.apiKey) {
|
|
180
|
+
console.error("[Builder.io]: No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
|
|
181
|
+
}
|
|
178
182
|
if (isBrowser()) {
|
|
179
183
|
if (isEditing()) {
|
|
180
184
|
setForceReRenderCount(forceReRenderCount + 1);
|
|
181
185
|
registerInsertMenu();
|
|
182
|
-
setupBrowserForEditing(
|
|
186
|
+
setupBrowserForEditing(__spreadValues(__spreadValues({}, props.locale ? {
|
|
187
|
+
locale: props.locale
|
|
188
|
+
} : {}), props.includeRefs ? {
|
|
189
|
+
includeRefs: props.includeRefs
|
|
190
|
+
} : {}));
|
|
183
191
|
Object.values(allRegisteredComponents()).forEach((registeredComponent) => {
|
|
184
192
|
var _a3;
|
|
185
193
|
const message = createRegisterComponentMessage(registeredComponent);
|
|
@@ -222,7 +230,7 @@ function RenderContent(props) {
|
|
|
222
230
|
}, []);
|
|
223
231
|
useEffect(() => {
|
|
224
232
|
evaluateJsCode();
|
|
225
|
-
}, [(_b = (_a = useContent == null ? void 0 : useContent()) == null ? void 0 : _a.data) == null ? void 0 : _b.jsCode]);
|
|
233
|
+
}, [(_b = (_a = useContent == null ? void 0 : useContent()) == null ? void 0 : _a.data) == null ? void 0 : _b.jsCode, contentState()]);
|
|
226
234
|
useEffect(() => {
|
|
227
235
|
runHttpRequests();
|
|
228
236
|
}, [(_d = (_c = useContent == null ? void 0 : useContent()) == null ? void 0 : _c.data) == null ? void 0 : _d.httpRequests]);
|
|
@@ -264,7 +272,7 @@ function RenderContent(props) {
|
|
|
264
272
|
cssCode: (_g = (_f = useContent == null ? void 0 : useContent()) == null ? void 0 : _f.data) == null ? void 0 : _g.cssCode,
|
|
265
273
|
customFonts: (_i = (_h = useContent == null ? void 0 : useContent()) == null ? void 0 : _h.data) == null ? void 0 : _i.customFonts
|
|
266
274
|
}) : null, /* @__PURE__ */ React.createElement(RenderBlocks, {
|
|
267
|
-
blocks:
|
|
275
|
+
blocks: (_k = (_j = useContent == null ? void 0 : useContent()) == null ? void 0 : _j.data) == null ? void 0 : _k.blocks,
|
|
268
276
|
key: forceReRenderCount
|
|
269
277
|
}))) : null);
|
|
270
278
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fastClone } from "../functions/fast-clone";
|
|
1
2
|
const SIZES = {
|
|
2
3
|
small: {
|
|
3
4
|
min: 320,
|
|
@@ -15,7 +16,33 @@ const SIZES = {
|
|
|
15
16
|
max: 1200
|
|
16
17
|
}
|
|
17
18
|
};
|
|
18
|
-
const getMaxWidthQueryForSize = (size) => `@media (max-width: ${
|
|
19
|
+
const getMaxWidthQueryForSize = (size, sizeValues = SIZES) => `@media (max-width: ${sizeValues[size].max}px)`;
|
|
20
|
+
const getSizesForBreakpoints = ({ small, medium }) => {
|
|
21
|
+
const newSizes = fastClone(SIZES);
|
|
22
|
+
if (!small || !medium) {
|
|
23
|
+
return newSizes;
|
|
24
|
+
}
|
|
25
|
+
const smallMin = Math.floor(small / 2);
|
|
26
|
+
newSizes.small = {
|
|
27
|
+
max: small,
|
|
28
|
+
min: smallMin,
|
|
29
|
+
default: smallMin + 1
|
|
30
|
+
};
|
|
31
|
+
const mediumMin = newSizes.small.max + 1;
|
|
32
|
+
newSizes.medium = {
|
|
33
|
+
max: medium,
|
|
34
|
+
min: mediumMin,
|
|
35
|
+
default: mediumMin + 1
|
|
36
|
+
};
|
|
37
|
+
const largeMin = newSizes.medium.max + 1;
|
|
38
|
+
newSizes.large = {
|
|
39
|
+
max: 2e3,
|
|
40
|
+
min: largeMin,
|
|
41
|
+
default: largeMin + 1
|
|
42
|
+
};
|
|
43
|
+
return newSizes;
|
|
44
|
+
};
|
|
19
45
|
export {
|
|
20
|
-
getMaxWidthQueryForSize
|
|
46
|
+
getMaxWidthQueryForSize,
|
|
47
|
+
getSizesForBreakpoints
|
|
21
48
|
};
|
|
@@ -4,7 +4,8 @@ function evaluate({
|
|
|
4
4
|
code,
|
|
5
5
|
context,
|
|
6
6
|
state,
|
|
7
|
-
event
|
|
7
|
+
event,
|
|
8
|
+
isExpression = true
|
|
8
9
|
}) {
|
|
9
10
|
if (code === "") {
|
|
10
11
|
console.warn("Skipping evaluation of empty code block.");
|
|
@@ -15,12 +16,12 @@ function evaluate({
|
|
|
15
16
|
isBrowser: isBrowser(),
|
|
16
17
|
isServer: !isBrowser()
|
|
17
18
|
};
|
|
18
|
-
const useReturn = !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
|
|
19
|
+
const useReturn = isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
|
|
19
20
|
const useCode = useReturn ? `return (${code});` : code;
|
|
20
21
|
try {
|
|
21
22
|
return new Function("builder", "Builder", "state", "context", "event", useCode)(builder, builder, state, context, event);
|
|
22
23
|
} catch (e) {
|
|
23
|
-
console.warn("Builder custom code error: \n While Evaluating: \n ", useCode, "\n", e
|
|
24
|
+
console.warn("Builder custom code error: \n While Evaluating: \n ", useCode, "\n", e);
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
export {
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { evaluate } from "./evaluate.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
2
|
+
const createEventHandler = (value, options) => (event) => evaluate({
|
|
3
|
+
code: value,
|
|
4
|
+
context: options.context,
|
|
5
|
+
state: options.state,
|
|
6
|
+
event,
|
|
7
|
+
isExpression: false
|
|
8
|
+
});
|
|
10
9
|
export {
|
|
11
|
-
|
|
10
|
+
createEventHandler
|
|
12
11
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getEventHandlerName } from "./event-handler-name.js";
|
|
2
|
-
import {
|
|
2
|
+
import { createEventHandler } from "./get-block-actions-handler.js";
|
|
3
3
|
function getBlockActions(options) {
|
|
4
4
|
var _a;
|
|
5
5
|
const obj = {};
|
|
@@ -9,7 +9,7 @@ function getBlockActions(options) {
|
|
|
9
9
|
continue;
|
|
10
10
|
}
|
|
11
11
|
const value = optionActions[key];
|
|
12
|
-
obj[getEventHandlerName(key)] =
|
|
12
|
+
obj[getEventHandlerName(key)] = createEventHandler(value, options);
|
|
13
13
|
}
|
|
14
14
|
return obj;
|
|
15
15
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isBrowser } from "../is-browser.js";
|
|
2
2
|
const BUILDER_SEARCHPARAMS_PREFIX = "builder.";
|
|
3
|
+
const BUILDER_OPTIONS_PREFIX = "options.";
|
|
3
4
|
const convertSearchParamsToQueryObject = (searchParams) => {
|
|
4
5
|
const options = {};
|
|
5
6
|
searchParams.forEach((value, key) => {
|
|
@@ -15,7 +16,7 @@ const getBuilderSearchParams = (_options) => {
|
|
|
15
16
|
const newOptions = {};
|
|
16
17
|
Object.keys(options).forEach((key) => {
|
|
17
18
|
if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
|
|
18
|
-
const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, "");
|
|
19
|
+
const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, "").replace(BUILDER_OPTIONS_PREFIX, "");
|
|
19
20
|
newOptions[trimmedKey] = options[key];
|
|
20
21
|
}
|
|
21
22
|
});
|
|
@@ -57,12 +57,13 @@ const generateContentUrl = (options) => {
|
|
|
57
57
|
noTraverse = false,
|
|
58
58
|
model,
|
|
59
59
|
apiKey,
|
|
60
|
-
includeRefs = true
|
|
60
|
+
includeRefs = true,
|
|
61
|
+
locale
|
|
61
62
|
} = options;
|
|
62
63
|
if (!apiKey) {
|
|
63
64
|
throw new Error("Missing API key");
|
|
64
65
|
}
|
|
65
|
-
const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}`);
|
|
66
|
+
const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}`);
|
|
66
67
|
const queryOptions = __spreadValues(__spreadValues({}, getBuilderSearchParamsFromWindow()), normalizeSearchParams(options.options || {}));
|
|
67
68
|
const flattened = flatten(queryOptions);
|
|
68
69
|
for (const key in flattened) {
|
|
@@ -85,7 +86,7 @@ function getAllContent(options) {
|
|
|
85
86
|
const fetch = yield getFetch();
|
|
86
87
|
const content = yield fetch(url.href).then((res) => res.json());
|
|
87
88
|
const canTrack = options.canTrack !== false;
|
|
88
|
-
if (canTrack) {
|
|
89
|
+
if (canTrack && Array.isArray(content.results)) {
|
|
89
90
|
for (const item of content.results) {
|
|
90
91
|
yield handleABTesting({ item, canTrack });
|
|
91
92
|
}
|
package/src/functions/track.js
CHANGED
|
@@ -90,6 +90,10 @@ const createEvent = (_a) => __async(void 0, null, function* () {
|
|
|
90
90
|
});
|
|
91
91
|
function _track(eventProps) {
|
|
92
92
|
return __async(this, null, function* () {
|
|
93
|
+
if (!eventProps.apiKey) {
|
|
94
|
+
console.error("[Builder.io]: Missing API key for track call. Please provide your API key.");
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
93
97
|
if (!eventProps.canTrack) {
|
|
94
98
|
return;
|
|
95
99
|
}
|
|
@@ -20,8 +20,8 @@ const registerInsertMenu = () => {
|
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
22
|
let isSetupForEditing = false;
|
|
23
|
-
const setupBrowserForEditing = () => {
|
|
24
|
-
var _a;
|
|
23
|
+
const setupBrowserForEditing = (options = {}) => {
|
|
24
|
+
var _a, _b;
|
|
25
25
|
if (isSetupForEditing) {
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
@@ -32,11 +32,18 @@ const setupBrowserForEditing = () => {
|
|
|
32
32
|
data: {
|
|
33
33
|
target: TARGET,
|
|
34
34
|
supportsPatchUpdates: false,
|
|
35
|
-
supportsAddBlockScoping: true
|
|
35
|
+
supportsAddBlockScoping: true,
|
|
36
|
+
supportsCustomBreakpoints: true
|
|
37
|
+
}
|
|
38
|
+
}, "*");
|
|
39
|
+
(_b = window.parent) == null ? void 0 : _b.postMessage({
|
|
40
|
+
type: "builder.updateContent",
|
|
41
|
+
data: {
|
|
42
|
+
options
|
|
36
43
|
}
|
|
37
44
|
}, "*");
|
|
38
45
|
window.addEventListener("message", ({ data }) => {
|
|
39
|
-
var _a2,
|
|
46
|
+
var _a2, _b2;
|
|
40
47
|
if (!(data == null ? void 0 : data.type)) {
|
|
41
48
|
return;
|
|
42
49
|
}
|
|
@@ -68,7 +75,7 @@ const setupBrowserForEditing = () => {
|
|
|
68
75
|
}, "*");
|
|
69
76
|
}).catch(console.error);
|
|
70
77
|
} else {
|
|
71
|
-
(
|
|
78
|
+
(_b2 = window.parent) == null ? void 0 : _b2.postMessage({
|
|
72
79
|
type: "builder.evaluateResult",
|
|
73
80
|
data: { result, id }
|
|
74
81
|
}, "*");
|