@builder.io/sdk-react 0.2.0 → 0.2.2
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 +13 -1
- package/dist/react/blocks/symbol/symbol.js +2 -1
- package/dist/react/components/render-block/block-styles.js +3 -0
- package/dist/react/components/render-block/render-block.helpers.js +16 -1
- package/dist/react/components/render-block/render-block.js +36 -55
- package/dist/react/components/render-content/render-content.js +8 -7
- package/dist/react/components/render-content-variants/helpers.js +98 -0
- package/dist/react/components/render-content-variants/render-content-variants.js +45 -0
- package/dist/react/components/render-inlined-styles.js +3 -3
- package/dist/react/functions/get-block-properties.js +4 -1
- package/dist/react/functions/get-content/index.js +22 -15
- package/dist/react/functions/track/index.js +2 -1
- package/dist/react/helpers/logger.js +7 -0
- package/dist/rsc/blocks/symbol/symbol.js +2 -1
- package/dist/rsc/components/render-block/block-styles.js +3 -0
- package/dist/rsc/components/render-block/render-block.helpers.js +16 -1
- package/dist/rsc/components/render-block/render-block.js +32 -51
- package/dist/rsc/components/render-content/render-content.js +1 -0
- package/dist/rsc/components/render-content-variants/helpers.js +99 -0
- package/dist/rsc/components/render-content-variants/render-content-variants.js +45 -0
- package/dist/rsc/components/render-inlined-styles.js +3 -3
- package/dist/rsc/functions/get-block-properties.js +4 -1
- package/dist/rsc/functions/get-content/index.js +22 -15
- package/dist/rsc/functions/track/index.js +2 -1
- package/dist/rsc/helpers/logger.js +7 -0
- package/package.json +1 -1
- package/packages/react/src/blocks/symbol/symbol.jsx +2 -1
- package/packages/react/src/components/render-block/block-styles.jsx +3 -0
- package/packages/react/src/components/render-block/render-block.helpers.js +16 -0
- package/packages/react/src/components/render-block/render-block.jsx +42 -61
- package/packages/react/src/components/render-content/render-content.jsx +11 -8
- package/packages/react/src/components/render-inlined-styles.jsx +4 -4
- package/packages/react/src/functions/get-block-properties.js +4 -1
- package/packages/react/src/functions/get-content/index.js +21 -15
- package/packages/react/src/functions/track/index.js +2 -1
- package/packages/react/src/helpers/logger.js +9 -0
- package/packages/rsc/src/blocks/symbol/symbol.jsx +2 -4
- package/packages/rsc/src/components/render-block/block-styles.jsx +3 -0
- package/packages/rsc/src/components/render-block/render-block.helpers.js +16 -0
- package/packages/rsc/src/components/render-block/render-block.jsx +32 -53
- package/packages/rsc/src/components/render-content/render-content.jsx +1 -0
- package/packages/rsc/src/components/render-inlined-styles.jsx +3 -3
- package/packages/rsc/src/functions/get-block-properties.js +4 -1
- package/packages/rsc/src/functions/get-content/index.js +21 -15
- package/packages/rsc/src/functions/track/index.js +2 -1
- package/packages/rsc/src/helpers/logger.js +9 -0
- package/packages/react/src/functions/get-block-tag.js +0 -6
- package/packages/rsc/src/functions/get-block-tag.js +0 -6
- package/src/blocks/BaseText.jsx +0 -9
- package/src/blocks/button/button.jsx +0 -27
- package/src/blocks/button/component-info.js +0 -41
- package/src/blocks/columns/columns.jsx +0 -172
- package/src/blocks/columns/component-info.js +0 -242
- package/src/blocks/custom-code/component-info.js +0 -31
- package/src/blocks/custom-code/custom-code.jsx +0 -64
- package/src/blocks/embed/component-info.js +0 -44
- package/src/blocks/embed/embed.jsx +0 -49
- package/src/blocks/embed/helpers.js +0 -9
- package/src/blocks/form/component-info.js +0 -262
- package/src/blocks/form/form.jsx +0 -253
- package/src/blocks/fragment/component-info.js +0 -11
- package/src/blocks/fragment/fragment.jsx +0 -5
- package/src/blocks/image/component-info.js +0 -151
- package/src/blocks/image/image.helpers.js +0 -48
- package/src/blocks/image/image.jsx +0 -122
- package/src/blocks/img/component-info.js +0 -20
- package/src/blocks/img/img.jsx +0 -17
- package/src/blocks/input/component-info.js +0 -74
- package/src/blocks/input/input.jsx +0 -19
- package/src/blocks/raw-text/component-info.js +0 -16
- package/src/blocks/raw-text/raw-text.jsx +0 -10
- package/src/blocks/section/component-info.js +0 -49
- package/src/blocks/section/section.jsx +0 -27
- package/src/blocks/select/component-info.js +0 -59
- package/src/blocks/select/select.jsx +0 -20
- package/src/blocks/submit-button/component-info.js +0 -28
- package/src/blocks/submit-button/submit-button.jsx +0 -9
- package/src/blocks/symbol/component-info.js +0 -43
- package/src/blocks/symbol/symbol.jsx +0 -84
- package/src/blocks/text/component-info.js +0 -24
- package/src/blocks/text/text.jsx +0 -10
- package/src/blocks/textarea/component-info.js +0 -47
- package/src/blocks/textarea/textarea.jsx +0 -13
- package/src/blocks/util.js +0 -8
- package/src/blocks/video/component-info.js +0 -106
- package/src/blocks/video/video.jsx +0 -58
- package/src/components/render-block/block-styles.jsx +0 -69
- package/src/components/render-block/render-block.helpers.js +0 -23
- package/src/components/render-block/render-block.jsx +0 -252
- package/src/components/render-block/render-component-with-context.jsx +0 -38
- package/src/components/render-block/render-component.jsx +0 -33
- package/src/components/render-block/render-repeated-block.jsx +0 -33
- package/src/components/render-block/types.js +0 -0
- package/src/components/render-blocks.jsx +0 -89
- package/src/components/render-content/builder-editing.jsx +0 -5
- package/src/components/render-content/components/render-styles.jsx +0 -64
- package/src/components/render-content/index.js +0 -4
- package/src/components/render-content/render-content.jsx +0 -370
- package/src/components/render-inlined-styles.jsx +0 -28
- package/src/constants/builder-registered-components.js +0 -54
- package/src/constants/device-sizes.js +0 -48
- package/src/constants/target.js +0 -4
- package/src/context/builder.context.js +0 -12
- package/src/context/types.js +0 -0
- package/src/functions/camel-to-kebab-case.js +0 -4
- package/src/functions/evaluate.js +0 -29
- package/src/functions/event-handler-name.js +0 -7
- package/src/functions/extract-text-styles.js +0 -22
- package/src/functions/fast-clone.js +0 -4
- package/src/functions/get-block-actions-handler.js +0 -11
- package/src/functions/get-block-actions.js +0 -18
- package/src/functions/get-block-component-options.js +0 -28
- package/src/functions/get-block-properties.js +0 -50
- package/src/functions/get-block-tag.js +0 -6
- package/src/functions/get-builder-search-params/fn.test.js +0 -13
- package/src/functions/get-builder-search-params/index.js +0 -38
- package/src/functions/get-content/ab-testing.js +0 -99
- package/src/functions/get-content/generate-content-url.js +0 -55
- package/src/functions/get-content/generate-content-url.test.js +0 -31
- package/src/functions/get-content/index.js +0 -65
- package/src/functions/get-content/types.js +0 -0
- package/src/functions/get-fetch.js +0 -14
- package/src/functions/get-global-this.js +0 -18
- package/src/functions/get-processed-block.js +0 -59
- package/src/functions/get-processed-block.test.js +0 -32
- package/src/functions/get-react-native-block-styles.js +0 -33
- package/src/functions/if-target.js +0 -15
- package/src/functions/is-browser.js +0 -6
- package/src/functions/is-editing.js +0 -7
- package/src/functions/is-iframe.js +0 -7
- package/src/functions/is-previewing.js +0 -14
- package/src/functions/on-change.js +0 -27
- package/src/functions/on-change.test.js +0 -19
- package/src/functions/register-component.js +0 -68
- package/src/functions/register.js +0 -29
- package/src/functions/sanitize-react-native-block-styles.js +0 -66
- package/src/functions/set-editor-settings.js +0 -15
- package/src/functions/set.js +0 -11
- package/src/functions/set.test.js +0 -16
- package/src/functions/track.js +0 -124
- package/src/functions/transform-block-properties.js +0 -6
- package/src/functions/transform-block.js +0 -6
- package/src/helpers/ab-tests.js +0 -16
- package/src/helpers/cookie.js +0 -81
- package/src/helpers/css.js +0 -34
- package/src/helpers/flatten.js +0 -34
- package/src/helpers/localStorage.js +0 -35
- package/src/helpers/nullable.js +0 -4
- package/src/helpers/sessionId.js +0 -52
- package/src/helpers/time.js +0 -5
- package/src/helpers/url.js +0 -13
- package/src/helpers/url.test.js +0 -21
- package/src/helpers/uuid.js +0 -13
- package/src/helpers/visitorId.js +0 -34
- package/src/index-helpers/blocks-exports.js +0 -22
- package/src/index-helpers/top-of-file.js +0 -4
- package/src/index.js +0 -14
- package/src/scripts/init-editing.js +0 -93
- package/src/types/builder-block.js +0 -0
- package/src/types/builder-content.js +0 -0
- package/src/types/can-track.js +0 -0
- package/src/types/components.js +0 -0
- package/src/types/deep-partial.js +0 -0
- package/src/types/element.js +0 -0
- package/src/types/targets.js +0 -0
- package/src/types/typescript.js +0 -0
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
getContextStateInitialValue,
|
|
27
27
|
} from "./render-content.helpers.js";
|
|
28
28
|
import { TARGET } from "../../constants/target.js";
|
|
29
|
+
import { logger } from "../../helpers/logger.js";
|
|
29
30
|
|
|
30
31
|
function RenderContent(props) {
|
|
31
32
|
const elementRef = useRef(null);
|
|
@@ -233,8 +234,8 @@ function RenderContent(props) {
|
|
|
233
234
|
|
|
234
235
|
useEffect(() => {
|
|
235
236
|
if (!props.apiKey) {
|
|
236
|
-
|
|
237
|
-
"
|
|
237
|
+
logger.error(
|
|
238
|
+
"No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop."
|
|
238
239
|
);
|
|
239
240
|
}
|
|
240
241
|
if (isBrowser()) {
|
|
@@ -280,22 +281,24 @@ function RenderContent(props) {
|
|
|
280
281
|
// override normal content in preview mode
|
|
281
282
|
if (isPreviewing()) {
|
|
282
283
|
const searchParams = new URL(location.href).searchParams;
|
|
283
|
-
const
|
|
284
|
+
const searchParamPreviewModel = searchParams.get("builder.preview");
|
|
285
|
+
const searchParamPreviewId = searchParams.get(
|
|
286
|
+
`builder.preview.${searchParamPreviewModel}`
|
|
287
|
+
);
|
|
284
288
|
const previewApiKey =
|
|
285
289
|
searchParams.get("apiKey") || searchParams.get("builder.space");
|
|
286
290
|
|
|
287
291
|
/**
|
|
288
292
|
* Make sure that:
|
|
289
293
|
* - the preview model name is the same as the one we're rendering, since there can be multiple models rendered * at the same time, e.g. header/page/footer. * - the API key is the same, since we don't want to preview content from other organizations.
|
|
290
|
-
*
|
|
291
|
-
* TO-DO: should we check that the preview item ID is the same as the initial one being rendered? Or would
|
|
292
|
-
* this break scenarios where the item is not published yet?
|
|
294
|
+
* - if there is content, that the preview ID is the same as that of the one we receive.
|
|
293
295
|
*
|
|
294
296
|
* TO-DO: should we only update the state when there is a change?
|
|
295
297
|
**/
|
|
296
298
|
if (
|
|
297
|
-
|
|
298
|
-
previewApiKey === props.apiKey
|
|
299
|
+
searchParamPreviewModel === props.model &&
|
|
300
|
+
previewApiKey === props.apiKey &&
|
|
301
|
+
(!props.content || searchParamPreviewId === props.content.id)
|
|
299
302
|
) {
|
|
300
303
|
getContent({
|
|
301
304
|
model: props.model,
|
|
@@ -2,16 +2,16 @@ import * as React from "react";
|
|
|
2
2
|
import { TARGET } from "../constants/target.js";
|
|
3
3
|
|
|
4
4
|
function RenderInlinedStyles(props) {
|
|
5
|
-
function injectedStyleScript() {
|
|
6
|
-
return `<${tag()}>${props.styles}</${tag()}>`;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
5
|
function tag() {
|
|
10
6
|
// NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
|
|
11
7
|
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
|
|
12
8
|
return "sty" + "le";
|
|
13
9
|
}
|
|
14
10
|
|
|
11
|
+
function injectedStyleScript() {
|
|
12
|
+
return `<${tag()}>${props.styles}</${tag()}>`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
15
|
const TagRef = tag();
|
|
16
16
|
|
|
17
17
|
return (
|
|
@@ -20,9 +20,12 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
20
20
|
import { TARGET } from "../constants/target.js";
|
|
21
21
|
import { convertStyleMapToCSSArray } from "../helpers/css.js";
|
|
22
22
|
import { transformBlockProperties } from "./transform-block-properties.js";
|
|
23
|
+
const extractRelevantRootBlockProperties = (block) => {
|
|
24
|
+
return { href: block.href };
|
|
25
|
+
};
|
|
23
26
|
function getBlockProperties(block) {
|
|
24
27
|
var _a;
|
|
25
|
-
const properties = __spreadProps(__spreadValues({}, block.properties), {
|
|
28
|
+
const properties = __spreadProps(__spreadValues(__spreadValues({}, extractRelevantRootBlockProperties(block)), block.properties), {
|
|
26
29
|
"builder-id": block.id,
|
|
27
30
|
style: getStyleAttribute(block.style),
|
|
28
31
|
class: [block.id, "builder-block", block.class, (_a = block.properties) == null ? void 0 : _a.class].filter(Boolean).join(" ")
|
|
@@ -37,13 +37,14 @@ var __async = (__this, __arguments, generator) => {
|
|
|
37
37
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
|
+
import { logger } from "../../helpers/logger.js";
|
|
40
41
|
import { fetch } from "../get-fetch.js";
|
|
41
42
|
import { handleABTesting } from "./ab-testing.js";
|
|
42
43
|
import { generateContentUrl } from "./generate-content-url.js";
|
|
43
44
|
function getContent(options) {
|
|
44
45
|
return __async(this, null, function* () {
|
|
45
46
|
const allContent = yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }));
|
|
46
|
-
if ("results" in allContent) {
|
|
47
|
+
if (allContent && "results" in allContent) {
|
|
47
48
|
return (allContent == null ? void 0 : allContent.results[0]) || null;
|
|
48
49
|
}
|
|
49
50
|
return null;
|
|
@@ -51,24 +52,29 @@ function getContent(options) {
|
|
|
51
52
|
}
|
|
52
53
|
function getAllContent(options) {
|
|
53
54
|
return __async(this, null, function* () {
|
|
54
|
-
const url = generateContentUrl(options);
|
|
55
|
-
const res = yield fetch(url.href);
|
|
56
|
-
const content = yield res.json();
|
|
57
|
-
if ("status" in content && !("results" in content)) {
|
|
58
|
-
console.error("[Builder.io]: Error fetching data. ", content, options);
|
|
59
|
-
return content;
|
|
60
|
-
}
|
|
61
|
-
const canTrack = options.canTrack !== false;
|
|
62
55
|
try {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
56
|
+
const url = generateContentUrl(options);
|
|
57
|
+
const res = yield fetch(url.href);
|
|
58
|
+
const content = yield res.json();
|
|
59
|
+
if ("status" in content && !("results" in content)) {
|
|
60
|
+
logger.error("Error fetching data. ", content, options);
|
|
61
|
+
return content;
|
|
62
|
+
}
|
|
63
|
+
const canTrack = options.canTrack !== false;
|
|
64
|
+
try {
|
|
65
|
+
if (canTrack && Array.isArray(content.results)) {
|
|
66
|
+
for (const item of content.results) {
|
|
67
|
+
yield handleABTesting({ item, canTrack });
|
|
68
|
+
}
|
|
66
69
|
}
|
|
70
|
+
} catch (e) {
|
|
71
|
+
logger.error("Could not setup A/B testing. ", e);
|
|
67
72
|
}
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
return content;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
logger.error("Error fetching data. ", error);
|
|
76
|
+
return null;
|
|
70
77
|
}
|
|
71
|
-
return content;
|
|
72
78
|
});
|
|
73
79
|
}
|
|
74
80
|
export {
|
|
@@ -50,6 +50,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
50
50
|
});
|
|
51
51
|
};
|
|
52
52
|
import { TARGET } from "../../constants/target.js";
|
|
53
|
+
import { logger } from "../../helpers/logger.js";
|
|
53
54
|
import { getSessionId } from "../../helpers/sessionId.js";
|
|
54
55
|
import { getVisitorId } from "../../helpers/visitorId.js";
|
|
55
56
|
import { isBrowser } from "../is-browser.js";
|
|
@@ -95,7 +96,7 @@ const createEvent = (_a) => __async(void 0, null, function* () {
|
|
|
95
96
|
function _track(eventProps) {
|
|
96
97
|
return __async(this, null, function* () {
|
|
97
98
|
if (!eventProps.apiKey) {
|
|
98
|
-
|
|
99
|
+
logger.error("Missing API key for track call. Please provide your API key.");
|
|
99
100
|
return;
|
|
100
101
|
}
|
|
101
102
|
if (!eventProps.canTrack) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const MSG_PREFIX = "[Builder.io]: ";
|
|
2
|
+
const logger = {
|
|
3
|
+
log: (...message) => console.log(MSG_PREFIX, ...message),
|
|
4
|
+
error: (...message) => console.error(MSG_PREFIX, ...message),
|
|
5
|
+
warn: (...message) => console.warn(MSG_PREFIX, ...message)
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
logger
|
|
9
|
+
};
|
|
@@ -3,6 +3,7 @@ import RenderContent from "../../components/render-content/render-content";
|
|
|
3
3
|
import BuilderContext from "../../context/builder.context.js";
|
|
4
4
|
import { getContent } from "../../functions/get-content/index.js";
|
|
5
5
|
import { TARGET } from "../../constants/target";
|
|
6
|
+
import { logger } from "../../helpers/logger";
|
|
6
7
|
|
|
7
8
|
function Symbol(props) {
|
|
8
9
|
const _context = { ...props["_context"] };
|
|
@@ -51,10 +52,7 @@ function Symbol(props) {
|
|
|
51
52
|
}
|
|
52
53
|
})
|
|
53
54
|
.catch((err) => {
|
|
54
|
-
|
|
55
|
-
"[Builder.io]: Could not fetch symbol content: ",
|
|
56
|
-
err
|
|
57
|
-
);
|
|
55
|
+
logger.error("Could not fetch symbol content: ", err);
|
|
58
56
|
});
|
|
59
57
|
}
|
|
60
58
|
},
|
|
@@ -41,6 +41,9 @@ function BlockStyles(props) {
|
|
|
41
41
|
const mediumStyles = styles?.medium;
|
|
42
42
|
const smallStyles = styles?.small;
|
|
43
43
|
const className = state.useBlock.id;
|
|
44
|
+
if (!className) {
|
|
45
|
+
return "";
|
|
46
|
+
}
|
|
44
47
|
const largeStylesClass = largeStyles
|
|
45
48
|
? createCssClass({
|
|
46
49
|
className,
|
|
@@ -106,8 +106,24 @@ const getRepeatItemData = ({
|
|
|
106
106
|
}));
|
|
107
107
|
return repeatArray;
|
|
108
108
|
};
|
|
109
|
+
const getProxyState = (context) => {
|
|
110
|
+
if (typeof Proxy === "undefined") {
|
|
111
|
+
console.error("no Proxy available in this environment, cannot proxy state.");
|
|
112
|
+
return context.state;
|
|
113
|
+
}
|
|
114
|
+
const useState = new Proxy(context.state, {
|
|
115
|
+
set: (obj, prop, value) => {
|
|
116
|
+
var _a;
|
|
117
|
+
obj[prop] = value;
|
|
118
|
+
(_a = context.setState) == null ? void 0 : _a.call(context, obj);
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
return useState;
|
|
123
|
+
};
|
|
109
124
|
export {
|
|
110
125
|
getComponent,
|
|
126
|
+
getProxyState,
|
|
111
127
|
getRepeatItemData,
|
|
112
128
|
isEmptyHtmlElement
|
|
113
129
|
};
|
|
@@ -2,11 +2,11 @@ import * as React from "react";
|
|
|
2
2
|
import { getBlockActions } from "../../functions/get-block-actions.js";
|
|
3
3
|
import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
|
|
4
4
|
import { getBlockProperties } from "../../functions/get-block-properties.js";
|
|
5
|
-
import { getBlockTag } from "../../functions/get-block-tag.js";
|
|
6
5
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
7
6
|
import BlockStyles from "./block-styles";
|
|
8
7
|
import {
|
|
9
8
|
getComponent,
|
|
9
|
+
getProxyState,
|
|
10
10
|
getRepeatItemData,
|
|
11
11
|
isEmptyHtmlElement,
|
|
12
12
|
} from "./render-block.helpers.js";
|
|
@@ -15,7 +15,6 @@ import { TARGET } from "../../constants/target.js";
|
|
|
15
15
|
import { extractTextStyles } from "../../functions/extract-text-styles.js";
|
|
16
16
|
import RenderComponent from "./render-component";
|
|
17
17
|
import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
|
|
18
|
-
import { checkIsDefined } from "../../helpers/nullable.js";
|
|
19
18
|
|
|
20
19
|
function RenderBlock(props) {
|
|
21
20
|
const _context = { ...props["_context"] };
|
|
@@ -25,9 +24,10 @@ function RenderBlock(props) {
|
|
|
25
24
|
block: props.block,
|
|
26
25
|
context: props.context,
|
|
27
26
|
}),
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
repeatItemData: getRepeatItemData({
|
|
28
|
+
block: props.block,
|
|
29
|
+
context: props.context,
|
|
30
|
+
}),
|
|
31
31
|
get useBlock() {
|
|
32
32
|
return state.repeatItemData
|
|
33
33
|
? props.block
|
|
@@ -38,38 +38,21 @@ function RenderBlock(props) {
|
|
|
38
38
|
shouldEvaluateBindings: true,
|
|
39
39
|
});
|
|
40
40
|
},
|
|
41
|
+
tag: props.block.tagName || "div",
|
|
41
42
|
get canShowBlock() {
|
|
42
|
-
if (
|
|
43
|
+
if ("hide" in state.useBlock) {
|
|
43
44
|
return !state.useBlock.hide;
|
|
44
45
|
}
|
|
45
|
-
if (
|
|
46
|
+
if ("show" in state.useBlock) {
|
|
46
47
|
return state.useBlock.show;
|
|
47
48
|
}
|
|
48
49
|
return true;
|
|
49
50
|
},
|
|
50
|
-
|
|
51
|
-
if (typeof Proxy === "undefined") {
|
|
52
|
-
console.error(
|
|
53
|
-
"no Proxy available in this environment, cannot proxy state."
|
|
54
|
-
);
|
|
55
|
-
return props.context.state;
|
|
56
|
-
}
|
|
57
|
-
const useState = new Proxy(props.context.state, {
|
|
58
|
-
set: (obj, prop, value) => {
|
|
59
|
-
// set the value on the state object, so that the event handler instantly gets the update.
|
|
60
|
-
obj[prop] = value;
|
|
61
|
-
|
|
62
|
-
// set the value in the context, so that the rest of the app gets the update.
|
|
63
|
-
props.context.setState?.(obj);
|
|
64
|
-
return true;
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
return useState;
|
|
68
|
-
},
|
|
51
|
+
proxyState: getProxyState(props.context),
|
|
69
52
|
get actions() {
|
|
70
53
|
return getBlockActions({
|
|
71
54
|
block: state.useBlock,
|
|
72
|
-
state: state.proxyState,
|
|
55
|
+
state: TARGET === "qwik" ? props.context.state : state.proxyState,
|
|
73
56
|
context: props.context.context,
|
|
74
57
|
});
|
|
75
58
|
},
|
|
@@ -88,28 +71,6 @@ function RenderBlock(props) {
|
|
|
88
71
|
: {}),
|
|
89
72
|
};
|
|
90
73
|
},
|
|
91
|
-
get renderComponentProps() {
|
|
92
|
-
return {
|
|
93
|
-
blockChildren: state.useBlock.children ?? [],
|
|
94
|
-
componentRef: state.component?.component,
|
|
95
|
-
componentOptions: {
|
|
96
|
-
...getBlockComponentOptions(state.useBlock),
|
|
97
|
-
/**
|
|
98
|
-
* These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
|
|
99
|
-
* they are provided to the component itself directly.
|
|
100
|
-
*/
|
|
101
|
-
...(!state.component?.noWrap
|
|
102
|
-
? {}
|
|
103
|
-
: {
|
|
104
|
-
attributes: {
|
|
105
|
-
...state.attributes,
|
|
106
|
-
...state.actions,
|
|
107
|
-
},
|
|
108
|
-
}),
|
|
109
|
-
},
|
|
110
|
-
context: state.childrenContext,
|
|
111
|
-
};
|
|
112
|
-
},
|
|
113
74
|
get childrenWithoutParentComponent() {
|
|
114
75
|
/**
|
|
115
76
|
* When there is no `componentRef`, there might still be children that need to be rendered. In this case,
|
|
@@ -123,10 +84,6 @@ function RenderBlock(props) {
|
|
|
123
84
|
? state.useBlock.children ?? []
|
|
124
85
|
: [];
|
|
125
86
|
},
|
|
126
|
-
repeatItemData: getRepeatItemData({
|
|
127
|
-
block: props.block,
|
|
128
|
-
context: props.context,
|
|
129
|
-
}),
|
|
130
87
|
get childrenContext() {
|
|
131
88
|
const getInheritedTextStyles = () => {
|
|
132
89
|
if (TARGET !== "reactNative") {
|
|
@@ -151,6 +108,28 @@ function RenderBlock(props) {
|
|
|
151
108
|
inheritedStyles: getInheritedTextStyles(),
|
|
152
109
|
};
|
|
153
110
|
},
|
|
111
|
+
get renderComponentProps() {
|
|
112
|
+
return {
|
|
113
|
+
blockChildren: state.useBlock.children ?? [],
|
|
114
|
+
componentRef: state.component?.component,
|
|
115
|
+
componentOptions: {
|
|
116
|
+
...getBlockComponentOptions(state.useBlock),
|
|
117
|
+
/**
|
|
118
|
+
* These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
|
|
119
|
+
* they are provided to the component itself directly.
|
|
120
|
+
*/
|
|
121
|
+
...(!state.component?.noWrap
|
|
122
|
+
? {}
|
|
123
|
+
: {
|
|
124
|
+
attributes: {
|
|
125
|
+
...state.attributes,
|
|
126
|
+
...state.actions,
|
|
127
|
+
},
|
|
128
|
+
}),
|
|
129
|
+
},
|
|
130
|
+
context: state.childrenContext,
|
|
131
|
+
};
|
|
132
|
+
},
|
|
154
133
|
};
|
|
155
134
|
|
|
156
135
|
const TagRef = state.tag;
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
getContextStateInitialValue,
|
|
26
26
|
} from "./render-content.helpers.js";
|
|
27
27
|
import { TARGET } from "../../constants/target.js";
|
|
28
|
+
import { logger } from "../../helpers/logger.js";
|
|
28
29
|
|
|
29
30
|
function RenderContent(props) {
|
|
30
31
|
const _context = { ...props["_context"] };
|
|
@@ -5,14 +5,14 @@ function RenderInlinedStyles(props) {
|
|
|
5
5
|
const _context = { ...props["_context"] };
|
|
6
6
|
|
|
7
7
|
const state = {
|
|
8
|
-
get injectedStyleScript() {
|
|
9
|
-
return `<${state.tag}>${props.styles}</${state.tag}>`;
|
|
10
|
-
},
|
|
11
8
|
get tag() {
|
|
12
9
|
// NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
|
|
13
10
|
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
|
|
14
11
|
return "sty" + "le";
|
|
15
12
|
},
|
|
13
|
+
get injectedStyleScript() {
|
|
14
|
+
return `<${state.tag}>${props.styles}</${state.tag}>`;
|
|
15
|
+
},
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
const TagRef = state.tag;
|
|
@@ -20,9 +20,12 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
20
20
|
import { TARGET } from "../constants/target.js";
|
|
21
21
|
import { convertStyleMapToCSSArray } from "../helpers/css.js";
|
|
22
22
|
import { transformBlockProperties } from "./transform-block-properties.js";
|
|
23
|
+
const extractRelevantRootBlockProperties = (block) => {
|
|
24
|
+
return { href: block.href };
|
|
25
|
+
};
|
|
23
26
|
function getBlockProperties(block) {
|
|
24
27
|
var _a;
|
|
25
|
-
const properties = __spreadProps(__spreadValues({}, block.properties), {
|
|
28
|
+
const properties = __spreadProps(__spreadValues(__spreadValues({}, extractRelevantRootBlockProperties(block)), block.properties), {
|
|
26
29
|
"builder-id": block.id,
|
|
27
30
|
style: getStyleAttribute(block.style),
|
|
28
31
|
class: [block.id, "builder-block", block.class, (_a = block.properties) == null ? void 0 : _a.class].filter(Boolean).join(" ")
|
|
@@ -37,13 +37,14 @@ var __async = (__this, __arguments, generator) => {
|
|
|
37
37
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
|
+
import { logger } from "../../helpers/logger.js";
|
|
40
41
|
import { fetch } from "../get-fetch.js";
|
|
41
42
|
import { handleABTesting } from "./ab-testing.js";
|
|
42
43
|
import { generateContentUrl } from "./generate-content-url.js";
|
|
43
44
|
function getContent(options) {
|
|
44
45
|
return __async(this, null, function* () {
|
|
45
46
|
const allContent = yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }));
|
|
46
|
-
if ("results" in allContent) {
|
|
47
|
+
if (allContent && "results" in allContent) {
|
|
47
48
|
return (allContent == null ? void 0 : allContent.results[0]) || null;
|
|
48
49
|
}
|
|
49
50
|
return null;
|
|
@@ -51,24 +52,29 @@ function getContent(options) {
|
|
|
51
52
|
}
|
|
52
53
|
function getAllContent(options) {
|
|
53
54
|
return __async(this, null, function* () {
|
|
54
|
-
const url = generateContentUrl(options);
|
|
55
|
-
const res = yield fetch(url.href);
|
|
56
|
-
const content = yield res.json();
|
|
57
|
-
if ("status" in content && !("results" in content)) {
|
|
58
|
-
console.error("[Builder.io]: Error fetching data. ", content, options);
|
|
59
|
-
return content;
|
|
60
|
-
}
|
|
61
|
-
const canTrack = options.canTrack !== false;
|
|
62
55
|
try {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
56
|
+
const url = generateContentUrl(options);
|
|
57
|
+
const res = yield fetch(url.href);
|
|
58
|
+
const content = yield res.json();
|
|
59
|
+
if ("status" in content && !("results" in content)) {
|
|
60
|
+
logger.error("Error fetching data. ", content, options);
|
|
61
|
+
return content;
|
|
62
|
+
}
|
|
63
|
+
const canTrack = options.canTrack !== false;
|
|
64
|
+
try {
|
|
65
|
+
if (canTrack && Array.isArray(content.results)) {
|
|
66
|
+
for (const item of content.results) {
|
|
67
|
+
yield handleABTesting({ item, canTrack });
|
|
68
|
+
}
|
|
66
69
|
}
|
|
70
|
+
} catch (e) {
|
|
71
|
+
logger.error("Could not setup A/B testing. ", e);
|
|
67
72
|
}
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
return content;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
logger.error("Error fetching data. ", error);
|
|
76
|
+
return null;
|
|
70
77
|
}
|
|
71
|
-
return content;
|
|
72
78
|
});
|
|
73
79
|
}
|
|
74
80
|
export {
|
|
@@ -50,6 +50,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
50
50
|
});
|
|
51
51
|
};
|
|
52
52
|
import { TARGET } from "../../constants/target.js";
|
|
53
|
+
import { logger } from "../../helpers/logger.js";
|
|
53
54
|
import { getSessionId } from "../../helpers/sessionId.js";
|
|
54
55
|
import { getVisitorId } from "../../helpers/visitorId.js";
|
|
55
56
|
import { isBrowser } from "../is-browser.js";
|
|
@@ -95,7 +96,7 @@ const createEvent = (_a) => __async(void 0, null, function* () {
|
|
|
95
96
|
function _track(eventProps) {
|
|
96
97
|
return __async(this, null, function* () {
|
|
97
98
|
if (!eventProps.apiKey) {
|
|
98
|
-
|
|
99
|
+
logger.error("Missing API key for track call. Please provide your API key.");
|
|
99
100
|
return;
|
|
100
101
|
}
|
|
101
102
|
if (!eventProps.canTrack) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const MSG_PREFIX = "[Builder.io]: ";
|
|
2
|
+
const logger = {
|
|
3
|
+
log: (...message) => console.log(MSG_PREFIX, ...message),
|
|
4
|
+
error: (...message) => console.error(MSG_PREFIX, ...message),
|
|
5
|
+
warn: (...message) => console.warn(MSG_PREFIX, ...message)
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
logger
|
|
9
|
+
};
|
package/src/blocks/BaseText.jsx
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { useContext } from "react";
|
|
3
|
-
import BuilderContext from "../context/builder.context.js";
|
|
4
|
-
|
|
5
|
-
export default function BaseText(props) {
|
|
6
|
-
const builderContext = useContext(BuilderContext);
|
|
7
|
-
|
|
8
|
-
return <span style={builderContext.inheritedStyles}>{props.text}</span>;
|
|
9
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
|
|
3
|
-
export default function Button(props) {
|
|
4
|
-
return (
|
|
5
|
-
<>
|
|
6
|
-
{props.link ? (
|
|
7
|
-
<>
|
|
8
|
-
<a
|
|
9
|
-
role="button"
|
|
10
|
-
{...props.attributes}
|
|
11
|
-
href={props.link}
|
|
12
|
-
target={props.openLinkInNewTab ? "_blank" : undefined}
|
|
13
|
-
>
|
|
14
|
-
{props.text}
|
|
15
|
-
</a>
|
|
16
|
-
</>
|
|
17
|
-
) : (
|
|
18
|
-
<button className="button-7028b0a4" {...props.attributes}>
|
|
19
|
-
{props.text}
|
|
20
|
-
</button>
|
|
21
|
-
)}
|
|
22
|
-
<style>{`.button-7028b0a4 {
|
|
23
|
-
all: unset;
|
|
24
|
-
}`}</style>
|
|
25
|
-
</>
|
|
26
|
-
);
|
|
27
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const componentInfo = {
|
|
2
|
-
name: "Core:Button",
|
|
3
|
-
builtIn: true,
|
|
4
|
-
image: "https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2F81a15681c3e74df09677dfc57a615b13",
|
|
5
|
-
defaultStyles: {
|
|
6
|
-
appearance: "none",
|
|
7
|
-
paddingTop: "15px",
|
|
8
|
-
paddingBottom: "15px",
|
|
9
|
-
paddingLeft: "25px",
|
|
10
|
-
paddingRight: "25px",
|
|
11
|
-
backgroundColor: "#000000",
|
|
12
|
-
color: "white",
|
|
13
|
-
borderRadius: "4px",
|
|
14
|
-
textAlign: "center",
|
|
15
|
-
cursor: "pointer"
|
|
16
|
-
},
|
|
17
|
-
inputs: [
|
|
18
|
-
{
|
|
19
|
-
name: "text",
|
|
20
|
-
type: "text",
|
|
21
|
-
defaultValue: "Click me!",
|
|
22
|
-
bubble: true
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
name: "link",
|
|
26
|
-
type: "url",
|
|
27
|
-
bubble: true
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
name: "openLinkInNewTab",
|
|
31
|
-
type: "boolean",
|
|
32
|
-
defaultValue: false,
|
|
33
|
-
friendlyName: "Open link in new tab"
|
|
34
|
-
}
|
|
35
|
-
],
|
|
36
|
-
static: true,
|
|
37
|
-
noWrap: true
|
|
38
|
-
};
|
|
39
|
-
export {
|
|
40
|
-
componentInfo
|
|
41
|
-
};
|