@builder.io/sdk-react-nextjs 0.5.9 → 0.6.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/lib/browser/USE_CLIENT_BUNDLE-12f42430.js +23 -0
- package/lib/browser/USE_CLIENT_BUNDLE-a8b60f05.mjs +664 -0
- package/lib/browser/USE_SERVER_BUNDLE-9abdf89a.js +1 -0
- package/lib/browser/USE_SERVER_BUNDLE-df74a63e.mjs +11 -0
- package/lib/browser/bundle-0ec2f27e.js +76 -0
- package/lib/browser/bundle-474f2dd7.mjs +2419 -0
- package/lib/browser/index.cjs +1 -0
- package/lib/browser/index.mjs +34 -0
- package/lib/edge/USE_CLIENT_BUNDLE-71a5598d.mjs +664 -0
- package/lib/edge/USE_CLIENT_BUNDLE-ec253910.js +23 -0
- package/lib/edge/USE_SERVER_BUNDLE-7cbf6eb1.js +1 -0
- package/lib/edge/USE_SERVER_BUNDLE-fdc79a6a.mjs +11 -0
- package/lib/edge/bundle-5d80175b.js +96 -0
- package/lib/edge/bundle-9492bb4e.mjs +4863 -0
- package/lib/edge/index.cjs +1 -0
- package/lib/edge/index.mjs +34 -0
- package/lib/node/USE_CLIENT_BUNDLE-12f42430.js +23 -0
- package/lib/node/USE_CLIENT_BUNDLE-a8b60f05.mjs +664 -0
- package/lib/node/USE_SERVER_BUNDLE-9abdf89a.js +1 -0
- package/lib/node/USE_SERVER_BUNDLE-df74a63e.mjs +11 -0
- package/lib/node/bundle-0ec2f27e.js +76 -0
- package/lib/node/bundle-474f2dd7.mjs +2419 -0
- package/lib/node/index.cjs +1 -0
- package/lib/node/index.mjs +34 -0
- package/package.json +100 -13
- package/types/constants/sdk-version.d.ts +1 -0
- package/types/functions/deopt.d.ts +4 -0
- package/types/functions/evaluate/browser-runtime/index.d.ts +1 -0
- package/{dist → types}/functions/fetch-builder-props.d.ts +2 -1
- package/{dist → types}/functions/get-content/index.d.ts +4 -5
- package/{dist → types}/index-helpers/blocks-exports.d.ts +2 -2
- package/dist/blocks/button/button.js +0 -12
- package/dist/blocks/button/component-info.js +0 -34
- package/dist/blocks/columns/columns.js +0 -119
- package/dist/blocks/columns/component-info.js +0 -219
- package/dist/blocks/custom-code/component-info.js +0 -23
- package/dist/blocks/custom-code/custom-code.js +0 -51
- package/dist/blocks/embed/component-info.js +0 -39
- package/dist/blocks/embed/embed.js +0 -42
- package/dist/blocks/embed/helpers.js +0 -2
- package/dist/blocks/fragment/component-info.js +0 -7
- package/dist/blocks/fragment/fragment.js +0 -6
- package/dist/blocks/helpers.js +0 -40
- package/dist/blocks/image/component-info.js +0 -122
- package/dist/blocks/image/image.helpers.js +0 -47
- package/dist/blocks/image/image.js +0 -82
- package/dist/blocks/img/component-info.js +0 -15
- package/dist/blocks/img/img.js +0 -10
- package/dist/blocks/section/component-info.js +0 -40
- package/dist/blocks/section/section.js +0 -17
- package/dist/blocks/symbol/component-info.js +0 -34
- package/dist/blocks/symbol/symbol.helpers.js +0 -31
- package/dist/blocks/symbol/symbol.js +0 -29
- package/dist/blocks/text/component-info.js +0 -19
- package/dist/blocks/text/text.js +0 -7
- package/dist/blocks/video/component-info.js +0 -82
- package/dist/blocks/video/video.js +0 -50
- package/dist/components/block/block.helpers.js +0 -69
- package/dist/components/block/block.js +0 -92
- package/dist/components/block/components/block-styles.js +0 -65
- package/dist/components/block/components/block-wrapper.js +0 -36
- package/dist/components/block/components/component-ref/component-ref.helpers.js +0 -22
- package/dist/components/block/components/component-ref/component-ref.js +0 -21
- package/dist/components/block/components/interactive-element.js +0 -20
- package/dist/components/block/components/repeated-block.js +0 -7
- package/dist/components/block/types.js +0 -1
- package/dist/components/blocks/blocks-wrapper.js +0 -38
- package/dist/components/blocks/blocks.js +0 -10
- package/dist/components/content/components/enable-editor.js +0 -250
- package/dist/components/content/components/styles.helpers.js +0 -58
- package/dist/components/content/components/styles.js +0 -30
- package/dist/components/content/content.helpers.js +0 -30
- package/dist/components/content/content.js +0 -74
- package/dist/components/content/content.types.js +0 -1
- package/dist/components/content/wrap-component-ref.js +0 -6
- package/dist/components/content-variants/content-variants.js +0 -45
- package/dist/components/content-variants/content-variants.types.js +0 -1
- package/dist/components/content-variants/helpers.js +0 -189
- package/dist/components/inlined-script.js +0 -5
- package/dist/components/inlined-styles.js +0 -5
- package/dist/constants/builder-registered-components.js +0 -60
- package/dist/constants/device-sizes.js +0 -45
- package/dist/constants/sdk-version.d.ts +0 -1
- package/dist/constants/sdk-version.js +0 -1
- package/dist/constants/target.js +0 -2
- package/dist/context/builder.context.js +0 -12
- package/dist/context/components.context.js +0 -2
- package/dist/context/types.js +0 -1
- package/dist/functions/camel-to-kebab-case.js +0 -1
- package/dist/functions/evaluate/browser-runtime/browser.js +0 -31
- package/dist/functions/evaluate/evaluate.js +0 -47
- package/dist/functions/evaluate/helpers.js +0 -10
- package/dist/functions/evaluate/index.js +0 -1
- package/dist/functions/evaluate/non-node-runtime/acorn-interpreter.d.ts +0 -2
- package/dist/functions/evaluate/non-node-runtime/acorn-interpreter.js +0 -3111
- package/dist/functions/evaluate/non-node-runtime/index.d.ts +0 -1
- package/dist/functions/evaluate/non-node-runtime/index.js +0 -2
- package/dist/functions/evaluate/non-node-runtime/non-node-runtime.d.ts +0 -2
- package/dist/functions/evaluate/non-node-runtime/non-node-runtime.js +0 -83
- package/dist/functions/event-handler-name.js +0 -4
- package/dist/functions/extract-text-styles.js +0 -22
- package/dist/functions/fast-clone.js +0 -4
- package/dist/functions/fetch-builder-props.js +0 -25
- package/dist/functions/get-block-actions-handler.js +0 -10
- package/dist/functions/get-block-actions.js +0 -28
- package/dist/functions/get-block-component-options.js +0 -10
- package/dist/functions/get-block-properties.js +0 -72
- package/dist/functions/get-builder-search-params/index.js +0 -38
- package/dist/functions/get-content/generate-content-url.js +0 -33
- package/dist/functions/get-content/index.js +0 -100
- package/dist/functions/get-content/types.js +0 -1
- package/dist/functions/get-fetch.js +0 -11
- package/dist/functions/get-global-this.js +0 -15
- package/dist/functions/get-processed-block.js +0 -46
- package/dist/functions/get-react-native-block-styles.js +0 -17
- package/dist/functions/is-browser.js +0 -3
- package/dist/functions/is-editing.js +0 -5
- package/dist/functions/is-iframe.js +0 -4
- package/dist/functions/is-non-node-server.d.ts +0 -4
- package/dist/functions/is-non-node-server.js +0 -8
- package/dist/functions/is-previewing.js +0 -11
- package/dist/functions/register-component.js +0 -38
- package/dist/functions/register.js +0 -27
- package/dist/functions/sanitize-react-native-block-styles.js +0 -61
- package/dist/functions/set-editor-settings.js +0 -12
- package/dist/functions/set.js +0 -14
- package/dist/functions/track/helpers.js +0 -51
- package/dist/functions/track/index.js +0 -71
- package/dist/functions/track/interaction.js +0 -53
- package/dist/functions/transform-block-properties.js +0 -5
- package/dist/functions/transform-block.js +0 -4
- package/dist/helpers/ab-tests.js +0 -122
- package/dist/helpers/canTrack.js +0 -2
- package/dist/helpers/cookie.js +0 -55
- package/dist/helpers/css.js +0 -27
- package/dist/helpers/flatten.js +0 -19
- package/dist/helpers/localStorage.js +0 -24
- package/dist/helpers/logger.js +0 -7
- package/dist/helpers/nullable.js +0 -1
- package/dist/helpers/preview-lru-cache/get.js +0 -9
- package/dist/helpers/preview-lru-cache/helpers.js +0 -9
- package/dist/helpers/preview-lru-cache/init.js +0 -15
- package/dist/helpers/preview-lru-cache/set.js +0 -7
- package/dist/helpers/preview-lru-cache/types.js +0 -6
- package/dist/helpers/sessionId.js +0 -30
- package/dist/helpers/url.js +0 -15
- package/dist/helpers/uuid.js +0 -15
- package/dist/helpers/visitorId.js +0 -30
- package/dist/index-helpers/blocks-exports.js +0 -19
- package/dist/index-helpers/top-of-file.js +0 -4
- package/dist/index.js +0 -7
- package/dist/scripts/init-editing.js +0 -110
- package/dist/server-index.js +0 -10
- package/dist/types/api-version.js +0 -1
- package/dist/types/builder-block.js +0 -1
- package/dist/types/builder-content.js +0 -1
- package/dist/types/builder-props.js +0 -1
- package/dist/types/can-track.js +0 -1
- package/dist/types/components.js +0 -1
- package/dist/types/deep-partial.js +0 -1
- package/dist/types/element.js +0 -1
- package/dist/types/enforced-partials.js +0 -1
- package/dist/types/input.js +0 -1
- package/dist/types/targets.js +0 -1
- package/dist/types/typescript.js +0 -1
- /package/{dist → types}/blocks/button/button.d.ts +0 -0
- /package/{dist → types}/blocks/button/component-info.d.ts +0 -0
- /package/{dist → types}/blocks/columns/columns.d.ts +0 -0
- /package/{dist → types}/blocks/columns/component-info.d.ts +0 -0
- /package/{dist → types}/blocks/custom-code/component-info.d.ts +0 -0
- /package/{dist → types}/blocks/custom-code/custom-code.d.ts +0 -0
- /package/{dist → types}/blocks/embed/component-info.d.ts +0 -0
- /package/{dist → types}/blocks/embed/embed.d.ts +0 -0
- /package/{dist → types}/blocks/embed/helpers.d.ts +0 -0
- /package/{dist → types}/blocks/fragment/component-info.d.ts +0 -0
- /package/{dist → types}/blocks/fragment/fragment.d.ts +0 -0
- /package/{dist → types}/blocks/helpers.d.ts +0 -0
- /package/{dist → types}/blocks/image/component-info.d.ts +0 -0
- /package/{dist → types}/blocks/image/image.d.ts +0 -0
- /package/{dist → types}/blocks/image/image.helpers.d.ts +0 -0
- /package/{dist → types}/blocks/img/component-info.d.ts +0 -0
- /package/{dist → types}/blocks/img/img.d.ts +0 -0
- /package/{dist → types}/blocks/section/component-info.d.ts +0 -0
- /package/{dist → types}/blocks/section/section.d.ts +0 -0
- /package/{dist → types}/blocks/symbol/component-info.d.ts +0 -0
- /package/{dist → types}/blocks/symbol/symbol.d.ts +0 -0
- /package/{dist → types}/blocks/symbol/symbol.helpers.d.ts +0 -0
- /package/{dist → types}/blocks/text/component-info.d.ts +0 -0
- /package/{dist → types}/blocks/text/text.d.ts +0 -0
- /package/{dist → types}/blocks/video/component-info.d.ts +0 -0
- /package/{dist → types}/blocks/video/video.d.ts +0 -0
- /package/{dist → types}/components/block/block.d.ts +0 -0
- /package/{dist → types}/components/block/block.helpers.d.ts +0 -0
- /package/{dist → types}/components/block/components/block-styles.d.ts +0 -0
- /package/{dist → types}/components/block/components/block-wrapper.d.ts +0 -0
- /package/{dist → types}/components/block/components/component-ref/component-ref.d.ts +0 -0
- /package/{dist → types}/components/block/components/component-ref/component-ref.helpers.d.ts +0 -0
- /package/{dist → types}/components/block/components/interactive-element.d.ts +0 -0
- /package/{dist → types}/components/block/components/repeated-block.d.ts +0 -0
- /package/{dist → types}/components/block/types.d.ts +0 -0
- /package/{dist → types}/components/blocks/blocks-wrapper.d.ts +0 -0
- /package/{dist → types}/components/blocks/blocks.d.ts +0 -0
- /package/{dist → types}/components/content/components/enable-editor.d.ts +0 -0
- /package/{dist → types}/components/content/components/styles.d.ts +0 -0
- /package/{dist → types}/components/content/components/styles.helpers.d.ts +0 -0
- /package/{dist → types}/components/content/content.d.ts +0 -0
- /package/{dist → types}/components/content/content.helpers.d.ts +0 -0
- /package/{dist → types}/components/content/content.types.d.ts +0 -0
- /package/{dist → types}/components/content/wrap-component-ref.d.ts +0 -0
- /package/{dist → types}/components/content-variants/content-variants.d.ts +0 -0
- /package/{dist → types}/components/content-variants/content-variants.types.d.ts +0 -0
- /package/{dist → types}/components/content-variants/helpers.d.ts +0 -0
- /package/{dist → types}/components/inlined-script.d.ts +0 -0
- /package/{dist → types}/components/inlined-styles.d.ts +0 -0
- /package/{dist → types}/constants/builder-registered-components.d.ts +0 -0
- /package/{dist → types}/constants/device-sizes.d.ts +0 -0
- /package/{dist → types}/constants/target.d.ts +0 -0
- /package/{dist → types}/context/builder.context.d.ts +0 -0
- /package/{dist → types}/context/components.context.d.ts +0 -0
- /package/{dist → types}/context/types.d.ts +0 -0
- /package/{dist → types}/functions/camel-to-kebab-case.d.ts +0 -0
- /package/{dist → types}/functions/evaluate/browser-runtime/browser.d.ts +0 -0
- /package/{dist → types}/functions/evaluate/evaluate.d.ts +0 -0
- /package/{dist → types}/functions/evaluate/helpers.d.ts +0 -0
- /package/{dist → types}/functions/evaluate/index.d.ts +0 -0
- /package/{dist → types}/functions/event-handler-name.d.ts +0 -0
- /package/{dist → types}/functions/extract-text-styles.d.ts +0 -0
- /package/{dist → types}/functions/fast-clone.d.ts +0 -0
- /package/{dist → types}/functions/get-block-actions-handler.d.ts +0 -0
- /package/{dist → types}/functions/get-block-actions.d.ts +0 -0
- /package/{dist → types}/functions/get-block-component-options.d.ts +0 -0
- /package/{dist → types}/functions/get-block-properties.d.ts +0 -0
- /package/{dist → types}/functions/get-builder-search-params/index.d.ts +0 -0
- /package/{dist → types}/functions/get-content/generate-content-url.d.ts +0 -0
- /package/{dist → types}/functions/get-content/types.d.ts +0 -0
- /package/{dist → types}/functions/get-fetch.d.ts +0 -0
- /package/{dist → types}/functions/get-global-this.d.ts +0 -0
- /package/{dist → types}/functions/get-processed-block.d.ts +0 -0
- /package/{dist → types}/functions/get-react-native-block-styles.d.ts +0 -0
- /package/{dist → types}/functions/is-browser.d.ts +0 -0
- /package/{dist → types}/functions/is-editing.d.ts +0 -0
- /package/{dist → types}/functions/is-iframe.d.ts +0 -0
- /package/{dist → types}/functions/is-previewing.d.ts +0 -0
- /package/{dist → types}/functions/register-component.d.ts +0 -0
- /package/{dist → types}/functions/register.d.ts +0 -0
- /package/{dist → types}/functions/sanitize-react-native-block-styles.d.ts +0 -0
- /package/{dist → types}/functions/set-editor-settings.d.ts +0 -0
- /package/{dist → types}/functions/set.d.ts +0 -0
- /package/{dist → types}/functions/track/helpers.d.ts +0 -0
- /package/{dist → types}/functions/track/index.d.ts +0 -0
- /package/{dist → types}/functions/track/interaction.d.ts +0 -0
- /package/{dist → types}/functions/transform-block-properties.d.ts +0 -0
- /package/{dist → types}/functions/transform-block.d.ts +0 -0
- /package/{dist → types}/helpers/ab-tests.d.ts +0 -0
- /package/{dist → types}/helpers/canTrack.d.ts +0 -0
- /package/{dist → types}/helpers/cookie.d.ts +0 -0
- /package/{dist → types}/helpers/css.d.ts +0 -0
- /package/{dist → types}/helpers/flatten.d.ts +0 -0
- /package/{dist → types}/helpers/localStorage.d.ts +0 -0
- /package/{dist → types}/helpers/logger.d.ts +0 -0
- /package/{dist → types}/helpers/nullable.d.ts +0 -0
- /package/{dist → types}/helpers/preview-lru-cache/get.d.ts +0 -0
- /package/{dist → types}/helpers/preview-lru-cache/helpers.d.ts +0 -0
- /package/{dist → types}/helpers/preview-lru-cache/init.d.ts +0 -0
- /package/{dist → types}/helpers/preview-lru-cache/set.d.ts +0 -0
- /package/{dist → types}/helpers/preview-lru-cache/types.d.ts +0 -0
- /package/{dist → types}/helpers/sessionId.d.ts +0 -0
- /package/{dist → types}/helpers/url.d.ts +0 -0
- /package/{dist → types}/helpers/uuid.d.ts +0 -0
- /package/{dist → types}/helpers/visitorId.d.ts +0 -0
- /package/{dist → types}/index-helpers/top-of-file.d.ts +0 -0
- /package/{dist → types}/index.d.ts +0 -0
- /package/{dist → types}/scripts/init-editing.d.ts +0 -0
- /package/{dist → types}/server-index.d.ts +0 -0
- /package/{dist → types}/types/api-version.d.ts +0 -0
- /package/{dist → types}/types/builder-block.d.ts +0 -0
- /package/{dist → types}/types/builder-content.d.ts +0 -0
- /package/{dist → types}/types/builder-props.d.ts +0 -0
- /package/{dist → types}/types/can-track.d.ts +0 -0
- /package/{dist → types}/types/components.d.ts +0 -0
- /package/{dist → types}/types/deep-partial.d.ts +0 -0
- /package/{dist → types}/types/element.d.ts +0 -0
- /package/{dist → types}/types/enforced-partials.d.ts +0 -0
- /package/{dist → types}/types/input.d.ts +0 -0
- /package/{dist → types}/types/targets.d.ts +0 -0
- /package/{dist → types}/types/typescript.d.ts +0 -0
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { TARGET } from '../../constants/target.js';
|
|
2
|
-
import { isBrowser } from '../../functions/is-browser.js';
|
|
3
|
-
export const getVariants = (content) => Object.values(content?.variations || {}).map(variant => ({
|
|
4
|
-
...variant,
|
|
5
|
-
testVariationId: variant.id,
|
|
6
|
-
id: content?.id
|
|
7
|
-
}));
|
|
8
|
-
export const checkShouldRunVariants = ({ canTrack, content }) => {
|
|
9
|
-
const hasVariants = getVariants(content).length > 0;
|
|
10
|
-
/**
|
|
11
|
-
* We cannot SSR in React-Native.
|
|
12
|
-
*/
|
|
13
|
-
if (TARGET === 'reactNative')
|
|
14
|
-
return false;
|
|
15
|
-
if (!hasVariants)
|
|
16
|
-
return false;
|
|
17
|
-
if (!canTrack)
|
|
18
|
-
return false;
|
|
19
|
-
/**
|
|
20
|
-
* For Vue 2 and Vue 3, we need to (initially) render the variants. This is to avoid hydration mismatch errors.
|
|
21
|
-
* Unlike React, Vue's hydration checks are shallow and do not check the attributes/contents of each element, so we
|
|
22
|
-
* are able to modify the `hidden` HTML attributes and `display` CSS properties without causing a hydration mismatch error.
|
|
23
|
-
*
|
|
24
|
-
* NOTE: after the app is hydrated, we strip the variants from the DOM (on mount) to reduce the amount of HTML in the DOM.
|
|
25
|
-
*/
|
|
26
|
-
if (TARGET === 'vue2' || TARGET === 'vue3')
|
|
27
|
-
return true;
|
|
28
|
-
if (isBrowser())
|
|
29
|
-
return false;
|
|
30
|
-
return true;
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* NOTE: when this function is stringified, single-line comments can cause weird issues when compiled by Sveltekit.
|
|
34
|
-
* Make sure to write multi-line comments only.
|
|
35
|
-
*/
|
|
36
|
-
function bldrAbTest(contentId, variants, isHydrationTarget) {
|
|
37
|
-
function getAndSetVariantId() {
|
|
38
|
-
function setCookie(name, value, days) {
|
|
39
|
-
let expires = '';
|
|
40
|
-
if (days) {
|
|
41
|
-
const date = new Date();
|
|
42
|
-
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
|
|
43
|
-
expires = '; expires=' + date.toUTCString();
|
|
44
|
-
}
|
|
45
|
-
document.cookie = name + '=' + (value || '') + expires + '; path=/' + '; Secure; SameSite=None';
|
|
46
|
-
}
|
|
47
|
-
function getCookie(name) {
|
|
48
|
-
const nameEQ = name + '=';
|
|
49
|
-
const ca = document.cookie.split(';');
|
|
50
|
-
for (let i = 0; i < ca.length; i++) {
|
|
51
|
-
let c = ca[i];
|
|
52
|
-
while (c.charAt(0) === ' ')
|
|
53
|
-
c = c.substring(1, c.length);
|
|
54
|
-
if (c.indexOf(nameEQ) === 0)
|
|
55
|
-
return c.substring(nameEQ.length, c.length);
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
const cookieName = `builder.tests.${contentId}`;
|
|
60
|
-
const variantInCookie = getCookie(cookieName);
|
|
61
|
-
const availableIDs = variants.map(vr => vr.id).concat(contentId);
|
|
62
|
-
/**
|
|
63
|
-
* cookie already exists
|
|
64
|
-
*/
|
|
65
|
-
if (variantInCookie && availableIDs.includes(variantInCookie)) {
|
|
66
|
-
return variantInCookie;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* no cookie exists, find variant
|
|
70
|
-
*/
|
|
71
|
-
let n = 0;
|
|
72
|
-
const random = Math.random();
|
|
73
|
-
for (let i = 0; i < variants.length; i++) {
|
|
74
|
-
const variant = variants[i];
|
|
75
|
-
const testRatio = variant.testRatio;
|
|
76
|
-
n += testRatio;
|
|
77
|
-
if (random < n) {
|
|
78
|
-
setCookie(cookieName, variant.id);
|
|
79
|
-
return variant.id;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* no variant found, assign default content
|
|
84
|
-
*/
|
|
85
|
-
setCookie(cookieName, contentId);
|
|
86
|
-
return contentId;
|
|
87
|
-
}
|
|
88
|
-
const winningVariantId = getAndSetVariantId();
|
|
89
|
-
const styleEl = document.currentScript?.previousElementSibling;
|
|
90
|
-
/**
|
|
91
|
-
* For React to work, we need hydration to match SSR, so we completely remove this node and the styles tag.
|
|
92
|
-
*/
|
|
93
|
-
if (isHydrationTarget) {
|
|
94
|
-
styleEl.remove();
|
|
95
|
-
const thisScriptEl = document.currentScript;
|
|
96
|
-
thisScriptEl?.remove();
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
/* update styles to hide all variants except the winning variant */
|
|
100
|
-
const newStyleStr = variants.concat({
|
|
101
|
-
id: contentId
|
|
102
|
-
}).filter(variant => variant.id !== winningVariantId).map(value => {
|
|
103
|
-
return `.variant-${value.id} { display: none; }
|
|
104
|
-
`;
|
|
105
|
-
}).join('');
|
|
106
|
-
styleEl.innerHTML = newStyleStr;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* NOTE: when this function is stringified, single-line comments can cause weird issues when compiled by Sveltekit.
|
|
111
|
-
* Make sure to write multi-line comments only.
|
|
112
|
-
*/
|
|
113
|
-
function bldrCntntScrpt(variantContentId, defaultContentId, isHydrationTarget) {
|
|
114
|
-
if (!navigator.cookieEnabled) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
function getCookie(name) {
|
|
118
|
-
const nameEQ = name + '=';
|
|
119
|
-
const ca = document.cookie.split(';');
|
|
120
|
-
for (let i = 0; i < ca.length; i++) {
|
|
121
|
-
let c = ca[i];
|
|
122
|
-
while (c.charAt(0) === ' ')
|
|
123
|
-
c = c.substring(1, c.length);
|
|
124
|
-
if (c.indexOf(nameEQ) === 0)
|
|
125
|
-
return c.substring(nameEQ.length, c.length);
|
|
126
|
-
}
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
const cookieName = `builder.tests.${defaultContentId}`;
|
|
130
|
-
const variantId = getCookie(cookieName);
|
|
131
|
-
const parentDiv = document.currentScript?.parentElement;
|
|
132
|
-
const variantIsDefaultContent = variantContentId === defaultContentId;
|
|
133
|
-
if (variantId === variantContentId) {
|
|
134
|
-
if (variantIsDefaultContent) {
|
|
135
|
-
/** the default content is already visible, no need to do anything */
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
/** this is the winning variant and not already visible: remove `hidden` and `aria-hidden` attr */
|
|
139
|
-
parentDiv?.removeAttribute('hidden');
|
|
140
|
-
parentDiv?.removeAttribute('aria-hidden');
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
if (variantIsDefaultContent) {
|
|
144
|
-
if (isHydrationTarget) {
|
|
145
|
-
/**
|
|
146
|
-
* For React to work, we need to support hydration, in which case the first CSR will have none of the hidden variants.
|
|
147
|
-
* So we completely remove that node.
|
|
148
|
-
*/
|
|
149
|
-
parentDiv?.remove();
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
/** this is not the winning variant, add `hidden` attr */
|
|
153
|
-
parentDiv?.setAttribute('hidden', 'true');
|
|
154
|
-
parentDiv?.setAttribute('aria-hidden', 'true');
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
/** This is not the winning variant, and it's not the default content.
|
|
158
|
-
* There's no need to hide it, because it's already hidden.
|
|
159
|
-
*/
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
const getIsHydrationTarget = (target) => target === 'react' || target === 'reactNative';
|
|
165
|
-
const isHydrationTarget = getIsHydrationTarget(TARGET);
|
|
166
|
-
/**
|
|
167
|
-
* We hardcode explicit function names here, because the `.toString()` of a function can change depending on the bundler.
|
|
168
|
-
* Some bundlers will minify the fn name, etc.
|
|
169
|
-
*
|
|
170
|
-
* So we hardcode the function names here, and then use those names in the script string to make sure the function names are consistent.
|
|
171
|
-
*/
|
|
172
|
-
const AB_TEST_FN_NAME = 'builderIoAbTest';
|
|
173
|
-
const CONTENT_FN_NAME = 'builderIoRenderContent';
|
|
174
|
-
export const getScriptString = () => {
|
|
175
|
-
const fnStr = bldrAbTest.toString().replace(/\s+/g, ' ');
|
|
176
|
-
const fnStr2 = bldrCntntScrpt.toString().replace(/\s+/g, ' ');
|
|
177
|
-
return `
|
|
178
|
-
window.${AB_TEST_FN_NAME} = ${fnStr}
|
|
179
|
-
window.${CONTENT_FN_NAME} = ${fnStr2}
|
|
180
|
-
`;
|
|
181
|
-
};
|
|
182
|
-
export const getVariantsScriptString = (variants, contentId) => {
|
|
183
|
-
return `
|
|
184
|
-
window.${AB_TEST_FN_NAME}("${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget})`;
|
|
185
|
-
};
|
|
186
|
-
export const getRenderContentScriptString = ({ contentId, variationId }) => {
|
|
187
|
-
return `
|
|
188
|
-
window.${CONTENT_FN_NAME}("${variationId}", "${contentId}", ${isHydrationTarget})`;
|
|
189
|
-
};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { default as Button } from '../blocks/button/button';
|
|
2
|
-
import { componentInfo as buttonComponentInfo } from '../blocks/button/component-info.js';
|
|
3
|
-
import { default as Columns } from '../blocks/columns/columns';
|
|
4
|
-
import { componentInfo as columnsComponentInfo } from '../blocks/columns/component-info.js';
|
|
5
|
-
import { componentInfo as fragmentComponentInfo } from '../blocks/fragment/component-info.js';
|
|
6
|
-
import { default as Fragment } from '../blocks/fragment/fragment';
|
|
7
|
-
import { componentInfo as imageComponentInfo } from '../blocks/image/component-info.js';
|
|
8
|
-
import { default as Image } from '../blocks/image/image';
|
|
9
|
-
import { componentInfo as sectionComponentInfo } from '../blocks/section/component-info.js';
|
|
10
|
-
import { default as Section } from '../blocks/section/section';
|
|
11
|
-
import { componentInfo as symbolComponentInfo } from '../blocks/symbol/component-info.js';
|
|
12
|
-
import { default as Symbol } from '../blocks/symbol/symbol';
|
|
13
|
-
import { componentInfo as textComponentInfo } from '../blocks/text/component-info.js';
|
|
14
|
-
import { default as Text } from '../blocks/text/text';
|
|
15
|
-
import { componentInfo as videoComponentInfo } from '../blocks/video/component-info.js';
|
|
16
|
-
import { default as Video } from '../blocks/video/video';
|
|
17
|
-
import { componentInfo as embedComponentInfo } from '../blocks/embed/component-info.js';
|
|
18
|
-
import { default as embed } from '../blocks/embed/embed';
|
|
19
|
-
import { default as Img } from '../blocks/img/img';
|
|
20
|
-
import { componentInfo as imgComponentInfo } from '../blocks/img/component-info.js';
|
|
21
|
-
import { default as customCode } from '../blocks/custom-code/custom-code';
|
|
22
|
-
import { componentInfo as customCodeInfo } from '../blocks/custom-code/component-info.js';
|
|
23
|
-
/**
|
|
24
|
-
* Returns a list of all registered components.
|
|
25
|
-
* NOTE: This needs to be a function to work around ESM circular dependencies.
|
|
26
|
-
*/
|
|
27
|
-
export const getDefaultRegisteredComponents = () => [{
|
|
28
|
-
component: Button,
|
|
29
|
-
...buttonComponentInfo
|
|
30
|
-
}, {
|
|
31
|
-
component: Columns,
|
|
32
|
-
...columnsComponentInfo
|
|
33
|
-
}, {
|
|
34
|
-
component: customCode,
|
|
35
|
-
...customCodeInfo
|
|
36
|
-
}, {
|
|
37
|
-
component: embed,
|
|
38
|
-
...embedComponentInfo
|
|
39
|
-
}, {
|
|
40
|
-
component: Fragment,
|
|
41
|
-
...fragmentComponentInfo
|
|
42
|
-
}, {
|
|
43
|
-
component: Image,
|
|
44
|
-
...imageComponentInfo
|
|
45
|
-
}, {
|
|
46
|
-
component: Img,
|
|
47
|
-
...imgComponentInfo
|
|
48
|
-
}, {
|
|
49
|
-
component: Section,
|
|
50
|
-
...sectionComponentInfo
|
|
51
|
-
}, {
|
|
52
|
-
component: Symbol,
|
|
53
|
-
...symbolComponentInfo
|
|
54
|
-
}, {
|
|
55
|
-
component: Text,
|
|
56
|
-
...textComponentInfo
|
|
57
|
-
}, {
|
|
58
|
-
component: Video,
|
|
59
|
-
...videoComponentInfo
|
|
60
|
-
}];
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { fastClone } from '../functions/fast-clone.js';
|
|
2
|
-
const SIZES = {
|
|
3
|
-
small: {
|
|
4
|
-
min: 320,
|
|
5
|
-
default: 321,
|
|
6
|
-
max: 640
|
|
7
|
-
},
|
|
8
|
-
medium: {
|
|
9
|
-
min: 641,
|
|
10
|
-
default: 642,
|
|
11
|
-
max: 991
|
|
12
|
-
},
|
|
13
|
-
large: {
|
|
14
|
-
min: 990,
|
|
15
|
-
default: 991,
|
|
16
|
-
max: 1200
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
export const getMaxWidthQueryForSize = (size, sizeValues = SIZES) => `@media (max-width: ${sizeValues[size].max}px)`;
|
|
20
|
-
export const getSizesForBreakpoints = ({ small, medium }) => {
|
|
21
|
-
const newSizes = fastClone(SIZES); // Note: this helps to get a deep clone of fields like small, medium etc
|
|
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: 2000,
|
|
40
|
-
// TODO: decide upper limit
|
|
41
|
-
min: largeMin,
|
|
42
|
-
default: largeMin + 1
|
|
43
|
-
};
|
|
44
|
-
return newSizes;
|
|
45
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.5.9";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.5.9";
|
package/dist/constants/target.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { createContext } from "react";
|
|
2
|
-
export default createContext({
|
|
3
|
-
content: null,
|
|
4
|
-
context: {},
|
|
5
|
-
localState: undefined,
|
|
6
|
-
rootSetState() { },
|
|
7
|
-
rootState: {},
|
|
8
|
-
apiKey: null,
|
|
9
|
-
apiVersion: undefined,
|
|
10
|
-
componentInfos: {},
|
|
11
|
-
inheritedStyles: {},
|
|
12
|
-
});
|
package/dist/context/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const camelToKebabCase = (string) => string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { getFunctionArguments } from '../helpers.js';
|
|
2
|
-
export const runInBrowser = ({ code, builder, context, event, localState, rootSetState, rootState }) => {
|
|
3
|
-
const functionArgs = getFunctionArguments({
|
|
4
|
-
builder,
|
|
5
|
-
context,
|
|
6
|
-
event,
|
|
7
|
-
state: flattenState(rootState, localState, rootSetState)
|
|
8
|
-
});
|
|
9
|
-
return new Function(...functionArgs.map(([name]) => name), code)(...functionArgs.map(([, value]) => value));
|
|
10
|
-
};
|
|
11
|
-
export function flattenState(rootState, localState, rootSetState) {
|
|
12
|
-
if (rootState === localState) {
|
|
13
|
-
throw new Error('rootState === localState');
|
|
14
|
-
}
|
|
15
|
-
return new Proxy(rootState, {
|
|
16
|
-
get: (_, prop) => {
|
|
17
|
-
if (localState && prop in localState) {
|
|
18
|
-
return localState[prop];
|
|
19
|
-
}
|
|
20
|
-
return rootState[prop];
|
|
21
|
-
},
|
|
22
|
-
set: (_, prop, value) => {
|
|
23
|
-
if (localState && prop in localState) {
|
|
24
|
-
throw new Error('Writing to local state is not allowed as it is read-only.');
|
|
25
|
-
}
|
|
26
|
-
rootState[prop] = value;
|
|
27
|
-
rootSetState?.(rootState);
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { logger } from '../../helpers/logger.js';
|
|
2
|
-
import { isBrowser } from '../is-browser.js';
|
|
3
|
-
import { isEditing } from '../is-editing.js';
|
|
4
|
-
import { getUserAttributes } from '../track/helpers.js';
|
|
5
|
-
import { runInBrowser } from './browser-runtime/browser.js';
|
|
6
|
-
import { runInNonNode } from './non-node-runtime/index.js';
|
|
7
|
-
import { isNonNodeServer } from '../is-non-node-server.js';
|
|
8
|
-
export function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
|
|
9
|
-
if (code === '') {
|
|
10
|
-
logger.warn('Skipping evaluation of empty code block.');
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
const builder = {
|
|
14
|
-
isEditing: isEditing(),
|
|
15
|
-
isBrowser: isBrowser(),
|
|
16
|
-
isServer: !isBrowser(),
|
|
17
|
-
getUserAttributes: () => getUserAttributes()
|
|
18
|
-
};
|
|
19
|
-
// Be able to handle simple expressions like "state.foo" or "1 + 1"
|
|
20
|
-
// as well as full blocks like "var foo = "bar"; return foo"
|
|
21
|
-
const useReturn =
|
|
22
|
-
// we disable this for cases where we definitely don't want a return
|
|
23
|
-
isExpression && !(code.includes(';') || code.includes(' return ') || code.trim().startsWith('return '));
|
|
24
|
-
const useCode = useReturn ? `return (${code});` : code;
|
|
25
|
-
const args = {
|
|
26
|
-
code: useCode,
|
|
27
|
-
builder,
|
|
28
|
-
context,
|
|
29
|
-
event,
|
|
30
|
-
rootSetState,
|
|
31
|
-
rootState,
|
|
32
|
-
localState
|
|
33
|
-
};
|
|
34
|
-
try {
|
|
35
|
-
if (isBrowser())
|
|
36
|
-
return runInBrowser(args);
|
|
37
|
-
if (isNonNodeServer())
|
|
38
|
-
return runInNonNode(args);
|
|
39
|
-
return runInBrowser(args);
|
|
40
|
-
}
|
|
41
|
-
catch (e) {
|
|
42
|
-
logger.error('Failed code evaluation: ' + e.message, {
|
|
43
|
-
code
|
|
44
|
-
});
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { evaluate } from './evaluate.js';
|