@builder.io/sdk-solid 0.4.5 → 0.5.1
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/CHANGELOG.md +8 -0
- package/package.json +1 -1
- package/src/blocks/BaseText.jsx +1 -1
- package/src/blocks/button/button.jsx +5 -3
- package/src/blocks/button/component-info.js +16 -22
- package/src/blocks/columns/columns.jsx +12 -21
- package/src/blocks/columns/component-info.js +203 -226
- package/src/blocks/custom-code/component-info.js +19 -25
- package/src/blocks/embed/component-info.js +31 -37
- package/src/blocks/embed/helpers.js +3 -9
- package/src/blocks/form/component-info.js +174 -212
- package/src/blocks/form/form.jsx +1 -268
- package/src/blocks/fragment/component-info.js +1 -3
- package/src/blocks/helpers.js +27 -0
- package/src/blocks/image/component-info.js +105 -133
- package/src/blocks/image/image.helpers.js +3 -5
- package/src/blocks/img/component-info.js +8 -12
- package/src/blocks/img/img.jsx +2 -0
- package/src/blocks/input/component-info.js +29 -57
- package/src/blocks/input/input.jsx +2 -0
- package/src/blocks/raw-text/component-info.js +7 -11
- package/src/blocks/raw-text/raw-text.jsx +2 -2
- package/src/blocks/section/component-info.js +24 -31
- package/src/blocks/section/section.jsx +3 -0
- package/src/blocks/select/component-info.js +34 -48
- package/src/blocks/select/select.jsx +2 -0
- package/src/blocks/submit-button/component-info.js +6 -10
- package/src/blocks/submit-button/submit-button.jsx +3 -1
- package/src/blocks/symbol/component-info.js +30 -37
- package/src/blocks/symbol/symbol.helpers.js +60 -0
- package/src/blocks/symbol/symbol.jsx +31 -68
- package/src/blocks/text/component-info.js +10 -13
- package/src/blocks/text/text.jsx +1 -1
- package/src/blocks/textarea/component-info.js +22 -30
- package/src/blocks/textarea/textarea.jsx +3 -0
- package/src/blocks/video/component-info.js +74 -96
- package/src/blocks/video/video.jsx +1 -0
- package/src/components/{render-block/render-block.helpers.js → block/block.helpers.js} +26 -44
- package/src/components/{render-block/render-block.jsx → block/block.jsx} +65 -80
- package/src/components/{render-block → block/components}/block-styles.jsx +16 -16
- package/src/components/block/components/block-wrapper.jsx +50 -0
- package/src/components/block/components/component-ref/component-ref.helpers.js +41 -0
- package/src/components/block/components/component-ref/component-ref.jsx +58 -0
- package/src/components/block/components/interactive-element.jsx +30 -0
- package/src/components/block/components/repeated-block.jsx +20 -0
- package/src/components/blocks/blocks-wrapper.jsx +66 -0
- package/src/components/blocks/blocks.jsx +57 -0
- package/src/components/{render-content/render-content.jsx → content/components/enable-editor.jsx} +86 -175
- package/src/components/{render-content/components/render-styles.helpers.js → content/components/styles.helpers.js} +6 -7
- package/src/components/{render-content/components/render-styles.jsx → content/components/styles.jsx} +4 -4
- package/src/components/{render-content/render-content.helpers.js → content/content.helpers.js} +15 -15
- package/src/components/content/content.jsx +136 -0
- package/src/components/content/index.js +2 -0
- package/src/components/content/wrap-component-ref.js +2 -0
- package/src/components/{render-content-variants/render-content-variants.jsx → content-variants/content-variants.jsx} +19 -22
- package/src/components/{render-content-variants → content-variants}/helpers.js +28 -40
- package/src/constants/builder-registered-components.js +34 -25
- package/src/constants/device-sizes.js +6 -6
- package/src/constants/sdk-version.js +1 -1
- package/src/context/builder.context.js +1 -1
- package/src/context/components.context.js +5 -0
- package/src/functions/apply-patch-with-mutation.js +66 -0
- package/src/functions/camel-to-kebab-case.js +2 -4
- package/src/functions/evaluate/acorn.js +1595 -0
- package/src/functions/{evaluate.js → evaluate/evaluate.js} +36 -10
- package/src/functions/evaluate/index.js +2 -0
- package/src/functions/evaluate/interpreter.js +2801 -0
- package/src/functions/evaluate/non-node-runtime.js +92 -0
- package/src/functions/evaluate/types.js +0 -0
- package/src/functions/event-handler-name.js +2 -4
- package/src/functions/extract-text-styles.js +4 -12
- package/src/functions/fast-clone.js +2 -4
- package/src/functions/get-block-actions-handler.js +3 -5
- package/src/functions/get-block-actions.js +15 -4
- package/src/functions/get-block-component-options.js +11 -12
- package/src/functions/get-block-properties.js +29 -19
- package/src/functions/get-builder-search-params/index.js +5 -10
- package/src/functions/get-content/generate-content-url.js +17 -19
- package/src/functions/get-content/index.js +43 -29
- package/src/functions/get-fetch.js +1 -3
- package/src/functions/get-global-this.js +1 -3
- package/src/functions/get-processed-block.js +12 -13
- package/src/functions/get-react-native-block-styles.js +11 -12
- package/src/functions/if-target.js +1 -3
- package/src/functions/is-browser.js +1 -3
- package/src/functions/is-editing.js +1 -3
- package/src/functions/is-iframe.js +1 -3
- package/src/functions/is-non-node-server.js +9 -0
- package/src/functions/is-previewing.js +1 -3
- package/src/functions/on-change.js +1 -4
- package/src/functions/register-component.js +34 -42
- package/src/functions/register.js +1 -3
- package/src/functions/sanitize-react-native-block-styles.js +22 -17
- package/src/functions/set-editor-settings.js +1 -3
- package/src/functions/set.js +1 -3
- package/src/functions/track/helpers.js +3 -5
- package/src/functions/track/index.js +45 -43
- package/src/functions/track/interaction.js +11 -7
- package/src/functions/transform-block-properties.js +1 -3
- package/src/functions/transform-block.js +1 -3
- package/src/helpers/ab-tests.js +45 -28
- package/src/helpers/canTrack.js +3 -5
- package/src/helpers/cookie.js +15 -24
- package/src/helpers/css.js +3 -7
- package/src/helpers/flatten.js +15 -18
- package/src/helpers/localStorage.js +1 -4
- package/src/helpers/logger.js +1 -3
- package/src/helpers/nullable.js +2 -4
- package/src/helpers/preview-lru-cache/get.js +8 -0
- package/src/helpers/preview-lru-cache/helpers.js +10 -0
- package/src/helpers/preview-lru-cache/init.js +10 -0
- package/src/helpers/preview-lru-cache/set.js +35 -0
- package/src/helpers/preview-lru-cache/types.js +0 -0
- package/src/helpers/sessionId.js +14 -11
- package/src/helpers/time.js +1 -3
- package/src/helpers/url.js +2 -4
- package/src/helpers/uuid.js +4 -6
- package/src/helpers/visitorId.js +8 -7
- package/src/index-helpers/blocks-exports.js +3 -14
- package/src/index-helpers/top-of-file.js +1 -3
- package/src/index.js +2 -17
- package/src/scripts/init-editing.js +62 -48
- package/src/types/api-version.js +1 -3
- package/src/types/builder-props.js +0 -0
- package/src/blocks/util.js +0 -8
- package/src/components/render-block/render-component.jsx +0 -40
- package/src/components/render-block/render-repeated-block.jsx +0 -16
- package/src/components/render-blocks.jsx +0 -100
- package/src/components/render-content/builder-editing.jsx +0 -5
- package/src/components/render-content/index.js +0 -4
- package/src/components/render-content/wrap-component-ref.js +0 -4
- package/src/functions/evaluate.test.js +0 -17
- package/src/functions/get-builder-search-params/fn.test.js +0 -13
- package/src/functions/get-content/generate-content-url.test.js +0 -97
- package/src/functions/get-processed-block.test.js +0 -34
- package/src/functions/on-change.test.js +0 -19
- package/src/functions/set.test.js +0 -16
- package/src/helpers/url.test.js +0 -21
- /package/src/components/{render-block → block}/types.js +0 -0
- /package/src/components/{render-content/render-content.types.js → content/content.types.js} +0 -0
- /package/src/components/{render-content-variants/render-content-variants.types.js → content-variants/content-variants.types.js} +0 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true,
|
|
9
|
+
value
|
|
10
|
+
}) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
15
|
+
}
|
|
16
|
+
return a;
|
|
17
|
+
};
|
|
18
|
+
import { logger } from "../../helpers/logger";
|
|
19
|
+
import { set } from "../set";
|
|
20
|
+
import Interpreter from "./interpreter.js";
|
|
21
|
+
const processCode = code => {
|
|
22
|
+
return code.split("\n").map(line => {
|
|
23
|
+
const trimmed = line.trim();
|
|
24
|
+
if (line.includes("__awaiter")) return void 0;
|
|
25
|
+
const isStateSetter = trimmed.startsWith("state.");
|
|
26
|
+
if (!isStateSetter) return line;
|
|
27
|
+
const [lhs, rhs] = trimmed.split("=");
|
|
28
|
+
const setStr = lhs.replace("state.", "").trim();
|
|
29
|
+
const setExpr = `setRootState('${setStr}', ${rhs.trim()})`;
|
|
30
|
+
return `
|
|
31
|
+
${line}
|
|
32
|
+
${setExpr}
|
|
33
|
+
`;
|
|
34
|
+
}).filter(Boolean).join("\n");
|
|
35
|
+
};
|
|
36
|
+
const getJSONValName = val => val + "JSON";
|
|
37
|
+
const runInNonNode = ({
|
|
38
|
+
builder,
|
|
39
|
+
context,
|
|
40
|
+
event,
|
|
41
|
+
rootState,
|
|
42
|
+
localState,
|
|
43
|
+
rootSetState,
|
|
44
|
+
useCode
|
|
45
|
+
}) => {
|
|
46
|
+
const state = __spreadValues(__spreadValues({}, rootState), localState);
|
|
47
|
+
const properties = {
|
|
48
|
+
state,
|
|
49
|
+
Builder: builder,
|
|
50
|
+
builder,
|
|
51
|
+
context,
|
|
52
|
+
event
|
|
53
|
+
};
|
|
54
|
+
const prependedCode = Object.keys(properties).map(key => `var ${key} = JSON.parse(${getJSONValName(key)});`).join("\n");
|
|
55
|
+
const cleanedCode = processCode(useCode);
|
|
56
|
+
if (cleanedCode === "") {
|
|
57
|
+
logger.warn("Skipping evaluation of empty code block.");
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const transformed = `
|
|
61
|
+
function theFunction() {
|
|
62
|
+
${prependedCode}
|
|
63
|
+
|
|
64
|
+
${cleanedCode}
|
|
65
|
+
}
|
|
66
|
+
theFunction();
|
|
67
|
+
`;
|
|
68
|
+
const setRootState = (prop, value) => {
|
|
69
|
+
const newState = set(state, prop, value);
|
|
70
|
+
rootSetState == null ? void 0 : rootSetState(newState);
|
|
71
|
+
};
|
|
72
|
+
const initFunc = function (interpreter, globalObject) {
|
|
73
|
+
Object.keys(properties).forEach(key => {
|
|
74
|
+
const val = properties[key] || {};
|
|
75
|
+
const jsonVal = JSON.stringify(val);
|
|
76
|
+
interpreter.setProperty(globalObject, getJSONValName(key), jsonVal);
|
|
77
|
+
});
|
|
78
|
+
interpreter.setProperty(globalObject, "setRootState", interpreter.createNativeFunction(setRootState));
|
|
79
|
+
};
|
|
80
|
+
try {
|
|
81
|
+
const myInterpreter = new Interpreter(transformed, initFunc);
|
|
82
|
+
myInterpreter.run();
|
|
83
|
+
const output = myInterpreter.pseudoToNative(myInterpreter.value);
|
|
84
|
+
return output;
|
|
85
|
+
} catch (e) {
|
|
86
|
+
logger.warn("Custom code error in non-node runtime. SDK can only execute ES5 JavaScript.", {
|
|
87
|
+
e
|
|
88
|
+
});
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
export { runInNonNode }
|
|
File without changes
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
function capitalizeFirstLetter(string) {
|
|
2
2
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
3
3
|
}
|
|
4
|
-
const getEventHandlerName =
|
|
5
|
-
export {
|
|
6
|
-
getEventHandlerName
|
|
7
|
-
};
|
|
4
|
+
const getEventHandlerName = key => `on${capitalizeFirstLetter(key)}`;
|
|
5
|
+
export { getEventHandlerName }
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
const TEXT_STYLE_KEYS = [
|
|
2
|
-
|
|
3
|
-
"whiteSpace",
|
|
4
|
-
"direction",
|
|
5
|
-
"hyphens",
|
|
6
|
-
"overflowWrap"
|
|
7
|
-
];
|
|
8
|
-
const isTextStyle = (key) => {
|
|
1
|
+
const TEXT_STYLE_KEYS = ["color", "whiteSpace", "direction", "hyphens", "overflowWrap"];
|
|
2
|
+
const isTextStyle = key => {
|
|
9
3
|
return TEXT_STYLE_KEYS.includes(key) || key.startsWith("font") || key.startsWith("text") || key.startsWith("letter") || key.startsWith("line") || key.startsWith("word") || key.startsWith("writing");
|
|
10
4
|
};
|
|
11
|
-
const extractTextStyles =
|
|
5
|
+
const extractTextStyles = styles => {
|
|
12
6
|
const textStyles = {};
|
|
13
7
|
Object.entries(styles).forEach(([key, value]) => {
|
|
14
8
|
if (isTextStyle(key)) {
|
|
@@ -17,6 +11,4 @@ const extractTextStyles = (styles) => {
|
|
|
17
11
|
});
|
|
18
12
|
return textStyles;
|
|
19
13
|
};
|
|
20
|
-
export {
|
|
21
|
-
extractTextStyles
|
|
22
|
-
};
|
|
14
|
+
export { extractTextStyles }
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { evaluate } from "./evaluate
|
|
2
|
-
const createEventHandler = (value, options) =>
|
|
1
|
+
import { evaluate } from "./evaluate";
|
|
2
|
+
const createEventHandler = (value, options) => event => evaluate({
|
|
3
3
|
code: value,
|
|
4
4
|
context: options.context,
|
|
5
5
|
localState: options.localState,
|
|
@@ -8,6 +8,4 @@ const createEventHandler = (value, options) => (event) => evaluate({
|
|
|
8
8
|
event,
|
|
9
9
|
isExpression: false
|
|
10
10
|
});
|
|
11
|
-
export {
|
|
12
|
-
createEventHandler
|
|
13
|
-
};
|
|
11
|
+
export { createEventHandler }
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TARGET } from "../constants/target.js";
|
|
1
2
|
import { getEventHandlerName } from "./event-handler-name.js";
|
|
2
3
|
import { createEventHandler } from "./get-block-actions-handler.js";
|
|
3
4
|
function getBlockActions(options) {
|
|
@@ -9,10 +10,20 @@ function getBlockActions(options) {
|
|
|
9
10
|
continue;
|
|
10
11
|
}
|
|
11
12
|
const value = optionActions[key];
|
|
12
|
-
|
|
13
|
+
let eventHandlerName = getEventHandlerName(key);
|
|
14
|
+
if (options.stripPrefix) {
|
|
15
|
+
switch (TARGET) {
|
|
16
|
+
case "vue2":
|
|
17
|
+
case "vue3":
|
|
18
|
+
eventHandlerName = eventHandlerName.replace("v-on:", "");
|
|
19
|
+
break;
|
|
20
|
+
case "svelte":
|
|
21
|
+
eventHandlerName = eventHandlerName.replace("on:", "");
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
obj[eventHandlerName] = createEventHandler(value, options);
|
|
13
26
|
}
|
|
14
27
|
return obj;
|
|
15
28
|
}
|
|
16
|
-
export {
|
|
17
|
-
getBlockActions
|
|
18
|
-
};
|
|
29
|
+
export { getBlockActions }
|
|
@@ -4,16 +4,17 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
|
4
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value
|
|
12
|
+
}) : obj[key] = value;
|
|
8
13
|
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
14
|
+
for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
17
18
|
return a;
|
|
18
19
|
};
|
|
19
20
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
@@ -23,6 +24,4 @@ function getBlockComponentOptions(block) {
|
|
|
23
24
|
builderBlock: block
|
|
24
25
|
});
|
|
25
26
|
}
|
|
26
|
-
export {
|
|
27
|
-
getBlockComponentOptions
|
|
28
|
-
};
|
|
27
|
+
export { getBlockComponentOptions }
|
|
@@ -4,38 +4,49 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
|
4
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value
|
|
12
|
+
}) : obj[key] = value;
|
|
8
13
|
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
14
|
+
for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
17
18
|
return a;
|
|
18
19
|
};
|
|
19
20
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
21
|
import { TARGET } from "../constants/target.js";
|
|
21
22
|
import { convertStyleMapToCSSArray } from "../helpers/css.js";
|
|
23
|
+
import { getReactNativeBlockStyles } from "./get-react-native-block-styles.js";
|
|
22
24
|
import { transformBlockProperties } from "./transform-block-properties.js";
|
|
23
|
-
const extractRelevantRootBlockProperties =
|
|
24
|
-
return {
|
|
25
|
+
const extractRelevantRootBlockProperties = block => {
|
|
26
|
+
return {
|
|
27
|
+
href: block.href
|
|
28
|
+
};
|
|
25
29
|
};
|
|
26
|
-
function getBlockProperties(
|
|
30
|
+
function getBlockProperties({
|
|
31
|
+
block,
|
|
32
|
+
context
|
|
33
|
+
}) {
|
|
27
34
|
var _a;
|
|
28
35
|
const properties = __spreadProps(__spreadValues(__spreadValues({}, extractRelevantRootBlockProperties(block)), block.properties), {
|
|
29
36
|
"builder-id": block.id,
|
|
30
|
-
style: getStyleAttribute(block.style),
|
|
37
|
+
style: block.style ? getStyleAttribute(block.style) : void 0,
|
|
31
38
|
class: [block.id, "builder-block", block.class, (_a = block.properties) == null ? void 0 : _a.class].filter(Boolean).join(" ")
|
|
32
39
|
});
|
|
40
|
+
if (TARGET === "reactNative") {
|
|
41
|
+
properties.style = getReactNativeBlockStyles({
|
|
42
|
+
block,
|
|
43
|
+
context,
|
|
44
|
+
blockStyles: properties.style
|
|
45
|
+
});
|
|
46
|
+
}
|
|
33
47
|
return transformBlockProperties(properties);
|
|
34
48
|
}
|
|
35
49
|
function getStyleAttribute(style) {
|
|
36
|
-
if (!style) {
|
|
37
|
-
return void 0;
|
|
38
|
-
}
|
|
39
50
|
switch (TARGET) {
|
|
40
51
|
case "svelte":
|
|
41
52
|
case "vue2":
|
|
@@ -45,9 +56,8 @@ function getStyleAttribute(style) {
|
|
|
45
56
|
case "qwik":
|
|
46
57
|
case "reactNative":
|
|
47
58
|
case "react":
|
|
59
|
+
case "rsc":
|
|
48
60
|
return style;
|
|
49
61
|
}
|
|
50
62
|
}
|
|
51
|
-
export {
|
|
52
|
-
getBlockProperties
|
|
53
|
-
};
|
|
63
|
+
export { getBlockProperties }
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { isBrowser } from "../is-browser.js";
|
|
2
2
|
const BUILDER_SEARCHPARAMS_PREFIX = "builder.";
|
|
3
3
|
const BUILDER_OPTIONS_PREFIX = "options.";
|
|
4
|
-
const convertSearchParamsToQueryObject =
|
|
4
|
+
const convertSearchParamsToQueryObject = searchParams => {
|
|
5
5
|
const options = {};
|
|
6
6
|
searchParams.forEach((value, key) => {
|
|
7
7
|
options[key] = value;
|
|
8
8
|
});
|
|
9
9
|
return options;
|
|
10
10
|
};
|
|
11
|
-
const getBuilderSearchParams =
|
|
11
|
+
const getBuilderSearchParams = _options => {
|
|
12
12
|
if (!_options) {
|
|
13
13
|
return {};
|
|
14
14
|
}
|
|
15
15
|
const options = normalizeSearchParams(_options);
|
|
16
16
|
const newOptions = {};
|
|
17
|
-
Object.keys(options).forEach(
|
|
17
|
+
Object.keys(options).forEach(key => {
|
|
18
18
|
if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
|
|
19
19
|
const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, "").replace(BUILDER_OPTIONS_PREFIX, "");
|
|
20
20
|
newOptions[trimmedKey] = options[key];
|
|
@@ -29,10 +29,5 @@ const getBuilderSearchParamsFromWindow = () => {
|
|
|
29
29
|
const searchParams = new URLSearchParams(window.location.search);
|
|
30
30
|
return getBuilderSearchParams(searchParams);
|
|
31
31
|
};
|
|
32
|
-
const normalizeSearchParams =
|
|
33
|
-
export {
|
|
34
|
-
convertSearchParamsToQueryObject,
|
|
35
|
-
getBuilderSearchParams,
|
|
36
|
-
getBuilderSearchParamsFromWindow,
|
|
37
|
-
normalizeSearchParams
|
|
38
|
-
};
|
|
32
|
+
const normalizeSearchParams = searchParams => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
|
|
33
|
+
export { convertSearchParamsToQueryObject, getBuilderSearchParams, getBuilderSearchParamsFromWindow, normalizeSearchParams }
|
|
@@ -2,25 +2,23 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
3
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
4
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true,
|
|
9
|
+
value
|
|
10
|
+
}) : obj[key] = value;
|
|
6
11
|
var __spreadValues = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
12
|
+
for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
15
|
+
}
|
|
15
16
|
return a;
|
|
16
17
|
};
|
|
17
18
|
import { flatten } from "../../helpers/flatten.js";
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
} from "../get-builder-search-params/index.js";
|
|
22
|
-
import { DEFAULT_API_VERSION } from "../../types/api-version";
|
|
23
|
-
const generateContentUrl = (options) => {
|
|
19
|
+
import { getBuilderSearchParamsFromWindow, normalizeSearchParams } from "../get-builder-search-params/index.js";
|
|
20
|
+
import { DEFAULT_API_VERSION } from "../../types/api-version.js";
|
|
21
|
+
const generateContentUrl = options => {
|
|
24
22
|
const {
|
|
25
23
|
limit = 30,
|
|
26
24
|
userAttributes,
|
|
@@ -49,13 +47,13 @@ const generateContentUrl = (options) => {
|
|
|
49
47
|
url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
|
|
50
48
|
}
|
|
51
49
|
if (query) {
|
|
52
|
-
const flattened2 = flatten({
|
|
50
|
+
const flattened2 = flatten({
|
|
51
|
+
query
|
|
52
|
+
});
|
|
53
53
|
for (const key in flattened2) {
|
|
54
54
|
url.searchParams.set(key, JSON.stringify(flattened2[key]));
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
return url;
|
|
58
58
|
};
|
|
59
|
-
export {
|
|
60
|
-
generateContentUrl
|
|
61
|
-
};
|
|
59
|
+
export { generateContentUrl }
|
|
@@ -4,36 +4,37 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
|
4
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value
|
|
12
|
+
}) : obj[key] = value;
|
|
8
13
|
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
14
|
+
for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
17
18
|
return a;
|
|
18
19
|
};
|
|
19
20
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
21
|
var __async = (__this, __arguments, generator) => {
|
|
21
22
|
return new Promise((resolve, reject) => {
|
|
22
|
-
var fulfilled =
|
|
23
|
+
var fulfilled = value => {
|
|
23
24
|
try {
|
|
24
25
|
step(generator.next(value));
|
|
25
26
|
} catch (e) {
|
|
26
27
|
reject(e);
|
|
27
28
|
}
|
|
28
29
|
};
|
|
29
|
-
var rejected =
|
|
30
|
+
var rejected = value => {
|
|
30
31
|
try {
|
|
31
32
|
step(generator.throw(value));
|
|
32
33
|
} catch (e) {
|
|
33
34
|
reject(e);
|
|
34
35
|
}
|
|
35
36
|
};
|
|
36
|
-
var step =
|
|
37
|
+
var step = x => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
38
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
39
|
});
|
|
39
40
|
};
|
|
@@ -41,35 +42,48 @@ import { TARGET } from "../../constants/target.js";
|
|
|
41
42
|
import { handleABTesting } from "../../helpers/ab-tests.js";
|
|
42
43
|
import { getDefaultCanTrack } from "../../helpers/canTrack.js";
|
|
43
44
|
import { logger } from "../../helpers/logger.js";
|
|
45
|
+
import { getPreviewContent } from "../../helpers/preview-lru-cache/get.js";
|
|
44
46
|
import { fetch } from "../get-fetch.js";
|
|
45
47
|
import { isBrowser } from "../is-browser.js";
|
|
46
48
|
import { generateContentUrl } from "./generate-content-url.js";
|
|
47
|
-
const checkContentHasResults =
|
|
49
|
+
const checkContentHasResults = content => "results" in content;
|
|
48
50
|
function getContent(options) {
|
|
49
51
|
return __async(this, null, function* () {
|
|
50
|
-
const allContent = yield getAllContent(__spreadProps(__spreadValues({}, options), {
|
|
51
|
-
|
|
52
|
+
const allContent = yield getAllContent(__spreadProps(__spreadValues({}, options), {
|
|
53
|
+
limit: 1
|
|
54
|
+
}));
|
|
55
|
+
if (allContent) {
|
|
52
56
|
return allContent.results[0] || null;
|
|
53
57
|
}
|
|
54
58
|
return null;
|
|
55
59
|
});
|
|
56
60
|
}
|
|
57
|
-
const fetchContent =
|
|
61
|
+
const fetchContent = options => __async(void 0, null, function* () {
|
|
58
62
|
const url = generateContentUrl(options);
|
|
59
63
|
const res = yield fetch(url.href);
|
|
60
64
|
const content = yield res.json();
|
|
61
65
|
return content;
|
|
62
66
|
});
|
|
63
|
-
const processContentResult = (
|
|
67
|
+
const processContentResult = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (options, content, url = generateContentUrl(options)) {
|
|
64
68
|
const canTrack = getDefaultCanTrack(options.canTrack);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
const isPreviewing = url.search.includes(`preview=`);
|
|
70
|
+
if (TARGET === "rsc" && isPreviewing) {
|
|
71
|
+
const newResults = [];
|
|
72
|
+
for (const item of content.results) {
|
|
73
|
+
const previewContent = getPreviewContent(url.searchParams);
|
|
74
|
+
newResults.push(previewContent || item);
|
|
75
|
+
}
|
|
76
|
+
content.results = newResults;
|
|
77
|
+
}
|
|
78
|
+
if (!canTrack) return content;
|
|
79
|
+
if (!(isBrowser() || TARGET === "reactNative")) return content;
|
|
69
80
|
try {
|
|
70
81
|
const newResults = [];
|
|
71
82
|
for (const item of content.results) {
|
|
72
|
-
newResults.push(yield handleABTesting({
|
|
83
|
+
newResults.push(yield handleABTesting({
|
|
84
|
+
item,
|
|
85
|
+
canTrack
|
|
86
|
+
}));
|
|
73
87
|
}
|
|
74
88
|
content.results = newResults;
|
|
75
89
|
} catch (e) {
|
|
@@ -83,8 +97,12 @@ function getAllContent(options) {
|
|
|
83
97
|
const url = generateContentUrl(options);
|
|
84
98
|
const content = yield fetchContent(options);
|
|
85
99
|
if (!checkContentHasResults(content)) {
|
|
86
|
-
logger.error("Error fetching data. ", {
|
|
87
|
-
|
|
100
|
+
logger.error("Error fetching data. ", {
|
|
101
|
+
url,
|
|
102
|
+
content,
|
|
103
|
+
options
|
|
104
|
+
});
|
|
105
|
+
return null;
|
|
88
106
|
}
|
|
89
107
|
return processContentResult(options, content);
|
|
90
108
|
} catch (error) {
|
|
@@ -93,8 +111,4 @@ function getAllContent(options) {
|
|
|
93
111
|
}
|
|
94
112
|
});
|
|
95
113
|
}
|
|
96
|
-
export {
|
|
97
|
-
getAllContent,
|
|
98
|
-
getContent,
|
|
99
|
-
processContentResult
|
|
100
|
-
};
|
|
114
|
+
export { getAllContent, getContent, processContentResult }
|
|
@@ -4,20 +4,21 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
|
4
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value
|
|
12
|
+
}) : obj[key] = value;
|
|
8
13
|
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
14
|
+
for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
17
18
|
return a;
|
|
18
19
|
};
|
|
19
20
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
import { evaluate } from "./evaluate
|
|
21
|
+
import { evaluate } from "./evaluate";
|
|
21
22
|
import { fastClone } from "./fast-clone.js";
|
|
22
23
|
import { set } from "./set.js";
|
|
23
24
|
import { transformBlock } from "./transform-block.js";
|
|
@@ -70,6 +71,4 @@ function getProcessedBlock({
|
|
|
70
71
|
return transformedBlock;
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
|
-
export {
|
|
74
|
-
getProcessedBlock
|
|
75
|
-
};
|
|
74
|
+
export { getProcessedBlock }
|
|
@@ -2,16 +2,17 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
3
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
4
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true,
|
|
9
|
+
value
|
|
10
|
+
}) : obj[key] = value;
|
|
6
11
|
var __spreadValues = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
12
|
+
for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
15
|
+
}
|
|
15
16
|
return a;
|
|
16
17
|
};
|
|
17
18
|
import { sanitizeReactNativeBlockStyles } from "./sanitize-react-native-block-styles.js";
|
|
@@ -28,6 +29,4 @@ function getReactNativeBlockStyles({
|
|
|
28
29
|
const newStyles = sanitizeReactNativeBlockStyles(styles);
|
|
29
30
|
return newStyles;
|
|
30
31
|
}
|
|
31
|
-
export {
|
|
32
|
-
getReactNativeBlockStyles
|
|
33
|
-
};
|
|
32
|
+
export { getReactNativeBlockStyles }
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { isBrowser } from "./is-browser";
|
|
2
|
+
function isNonNodeServer() {
|
|
3
|
+
const hasNode = () => {
|
|
4
|
+
var _a;
|
|
5
|
+
return typeof process !== "undefined" && ((_a = process == null ? void 0 : process.versions) == null ? void 0 : _a.node);
|
|
6
|
+
};
|
|
7
|
+
return !isBrowser() && !hasNode();
|
|
8
|
+
}
|
|
9
|
+
export { isNonNodeServer }
|