@builder.io/sdk-react-native 1.0.33 → 1.0.34
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/commonjs/blocks/text/text.js +1 -1
- package/lib/browser/commonjs/constants/sdk-version.js +1 -1
- package/lib/browser/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js +4 -18
- package/lib/browser/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
- package/lib/browser/commonjs/helpers/cookie.js +12 -2
- package/lib/browser/commonjs/helpers/cookie.js.map +1 -1
- package/lib/browser/module/blocks/text/text.js +1 -1
- package/lib/browser/module/blocks/text/text.js.map +1 -1
- package/lib/browser/module/constants/sdk-version.js +1 -1
- package/lib/browser/module/functions/evaluate/node-runtime/safeDynamicRequire.js +5 -18
- package/lib/browser/module/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
- package/lib/browser/module/helpers/cookie.js +11 -2
- package/lib/browser/module/helpers/cookie.js.map +1 -1
- package/lib/browser/typescript/constants/sdk-version.d.ts +1 -1
- package/lib/browser/typescript/helpers/cookie.d.ts +1 -0
- package/lib/browser/typescript/helpers/cookie.d.ts.map +1 -1
- package/lib/edge/commonjs/blocks/text/text.js +1 -1
- package/lib/edge/commonjs/constants/sdk-version.js +1 -1
- package/lib/edge/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js +4 -18
- package/lib/edge/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
- package/lib/edge/commonjs/helpers/cookie.js +12 -2
- package/lib/edge/commonjs/helpers/cookie.js.map +1 -1
- package/lib/edge/module/blocks/text/text.js +1 -1
- package/lib/edge/module/blocks/text/text.js.map +1 -1
- package/lib/edge/module/constants/sdk-version.js +1 -1
- package/lib/edge/module/functions/evaluate/node-runtime/safeDynamicRequire.js +5 -18
- package/lib/edge/module/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
- package/lib/edge/module/helpers/cookie.js +11 -2
- package/lib/edge/module/helpers/cookie.js.map +1 -1
- package/lib/edge/typescript/constants/sdk-version.d.ts +1 -1
- package/lib/edge/typescript/helpers/cookie.d.ts +1 -0
- package/lib/edge/typescript/helpers/cookie.d.ts.map +1 -1
- package/lib/node/commonjs/blocks/text/text.js +1 -1
- package/lib/node/commonjs/constants/sdk-version.js +1 -1
- package/lib/node/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js +4 -18
- package/lib/node/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
- package/lib/node/commonjs/helpers/cookie.js +12 -2
- package/lib/node/commonjs/helpers/cookie.js.map +1 -1
- package/lib/node/module/blocks/text/text.js +1 -1
- package/lib/node/module/blocks/text/text.js.map +1 -1
- package/lib/node/module/constants/sdk-version.js +1 -1
- package/lib/node/module/functions/evaluate/node-runtime/safeDynamicRequire.js +5 -18
- package/lib/node/module/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
- package/lib/node/module/helpers/cookie.js +11 -2
- package/lib/node/module/helpers/cookie.js.map +1 -1
- package/lib/node/typescript/constants/sdk-version.d.ts +1 -1
- package/lib/node/typescript/helpers/cookie.d.ts +1 -0
- package/lib/node/typescript/helpers/cookie.d.ts.map +1 -1
- package/package.json +10 -7
- package/src/blocks/BaseText.tsx +17 -0
- package/src/blocks/accordion/accordion.tsx +181 -0
- package/src/blocks/accordion/accordion.types.ts +12 -0
- package/src/blocks/accordion/component-info.ts +124 -0
- package/src/blocks/accordion/helpers.ts +3 -0
- package/src/blocks/accordion/index.ts +1 -0
- package/src/blocks/button/button.tsx +56 -0
- package/src/blocks/button/button.types.ts +7 -0
- package/src/blocks/button/component-info.ts +35 -0
- package/src/blocks/button/index.ts +1 -0
- package/src/blocks/columns/columns.tsx +199 -0
- package/src/blocks/columns/columns.types.ts +14 -0
- package/src/blocks/columns/component-info.ts +219 -0
- package/src/blocks/columns/helpers.ts +3 -0
- package/src/blocks/columns/index.ts +1 -0
- package/src/blocks/custom-code/component-info.ts +24 -0
- package/src/blocks/custom-code/custom-code.tsx +71 -0
- package/src/blocks/custom-code/index.ts +1 -0
- package/src/blocks/embed/component-info.ts +38 -0
- package/src/blocks/embed/embed.tsx +62 -0
- package/src/blocks/embed/helpers.ts +2 -0
- package/src/blocks/embed/index.ts +1 -0
- package/src/blocks/form/form/component-info.ts +233 -0
- package/src/blocks/form/form/form.tsx +324 -0
- package/src/blocks/form/form/index.ts +1 -0
- package/src/blocks/form/input/component-info.ts +47 -0
- package/src/blocks/form/input/index.ts +1 -0
- package/src/blocks/form/input/input.tsx +49 -0
- package/src/blocks/form/select/component-info.ts +44 -0
- package/src/blocks/form/select/index.ts +1 -0
- package/src/blocks/form/select/select.tsx +54 -0
- package/src/blocks/form/submit-button/component-info.ts +27 -0
- package/src/blocks/form/submit-button/index.ts +1 -0
- package/src/blocks/form/submit-button/submit-button.tsx +34 -0
- package/src/blocks/fragment/component-info.ts +8 -0
- package/src/blocks/fragment/fragment.tsx +18 -0
- package/src/blocks/fragment/fragment.types.ts +5 -0
- package/src/blocks/fragment/index.ts +1 -0
- package/src/blocks/helpers.ts +43 -0
- package/src/blocks/image/component-info.ts +129 -0
- package/src/blocks/image/image.helpers.ts +47 -0
- package/src/blocks/image/image.tsx +65 -0
- package/src/blocks/image/image.types.ts +20 -0
- package/src/blocks/image/index.ts +1 -0
- package/src/blocks/img/component-info.ts +16 -0
- package/src/blocks/img/img.tsx +55 -0
- package/src/blocks/img/index.ts +1 -0
- package/src/blocks/raw-text/component-info.ts +11 -0
- package/src/blocks/raw-text/index.ts +1 -0
- package/src/blocks/raw-text/raw-text.tsx +1 -0
- package/src/blocks/section/component-info.ts +41 -0
- package/src/blocks/section/index.ts +1 -0
- package/src/blocks/section/section.tsx +39 -0
- package/src/blocks/section/section.types.ts +6 -0
- package/src/blocks/slot/component-info.ts +15 -0
- package/src/blocks/slot/index.ts +1 -0
- package/src/blocks/slot/slot.tsx +42 -0
- package/src/blocks/symbol/component-info.ts +35 -0
- package/src/blocks/symbol/index.ts +1 -0
- package/src/blocks/symbol/symbol.helpers.ts +47 -0
- package/src/blocks/symbol/symbol.tsx +100 -0
- package/src/blocks/symbol/symbol.types.ts +17 -0
- package/src/blocks/tabs/component-info.ts +139 -0
- package/src/blocks/tabs/index.ts +1 -0
- package/src/blocks/tabs/tabs.tsx +79 -0
- package/src/blocks/tabs/tabs.types.ts +13 -0
- package/src/blocks/text/component-info.ts +20 -0
- package/src/blocks/text/index.ts +1 -0
- package/src/blocks/text/text.tsx +105 -0
- package/src/blocks/text/text.types.ts +4 -0
- package/src/blocks/textarea/component-info.ts +38 -0
- package/src/blocks/textarea/index.ts +1 -0
- package/src/blocks/textarea/textarea.tsx +41 -0
- package/src/blocks/video/component-info.ts +83 -0
- package/src/blocks/video/index.ts +1 -0
- package/src/blocks/video/video.tsx +70 -0
- package/src/blocks/video/video.types.ts +21 -0
- package/src/components/block/animator.ts +220 -0
- package/src/components/block/block.helpers.ts +124 -0
- package/src/components/block/block.tsx +232 -0
- package/src/components/block/components/block-styles.tsx +136 -0
- package/src/components/block/components/block-wrapper.tsx +52 -0
- package/src/components/block/components/component-ref/component-ref.helpers.ts +55 -0
- package/src/components/block/components/component-ref/component-ref.tsx +66 -0
- package/src/components/block/components/interactive-element.tsx +53 -0
- package/src/components/block/components/repeated-block.tsx +37 -0
- package/src/components/block/types.ts +6 -0
- package/src/components/blocks/blocks-wrapper.tsx +93 -0
- package/src/components/blocks/blocks.tsx +57 -0
- package/src/components/blocks/blocks.types.ts +7 -0
- package/src/components/blocks/index.ts +1 -0
- package/src/components/content/components/enable-editor.tsx +472 -0
- package/src/components/content/components/styles.helpers.ts +101 -0
- package/src/components/content/components/styles.tsx +42 -0
- package/src/components/content/content.helpers.ts +40 -0
- package/src/components/content/content.tsx +150 -0
- package/src/components/content/content.types.ts +13 -0
- package/src/components/content/contentProps.types.ts +17 -0
- package/src/components/content/index.ts +1 -0
- package/src/components/content/wrap-component-ref.ts +6 -0
- package/src/components/content-variants/content-variants.tsx +146 -0
- package/src/components/content-variants/content-variants.types.ts +84 -0
- package/src/components/content-variants/helpers.ts +72 -0
- package/src/components/content-variants/index.ts +1 -0
- package/src/components/content-variants/inlined-fns.ts +22 -0
- package/src/components/dynamic-div.tsx +30 -0
- package/src/components/dynamic-renderer/dynamic-renderer.helpers.ts +7 -0
- package/src/components/dynamic-renderer/dynamic-renderer.tsx +47 -0
- package/src/components/error-boundary.tsx +38 -0
- package/src/components/inlined-script.tsx +10 -0
- package/src/components/inlined-styles.tsx +10 -0
- package/src/constants/builder-registered-components.ts +59 -0
- package/src/constants/device-sizes.ts +59 -0
- package/src/constants/extra-components.ts +1 -0
- package/src/constants/sdk-version.ts +1 -0
- package/src/constants/target.ts +3 -0
- package/src/context/builder.context.ts +15 -0
- package/src/context/components.context.ts +3 -0
- package/src/context/index.ts +1 -0
- package/src/context/types.ts +38 -0
- package/src/functions/apply-patch-with-mutation.ts +61 -0
- package/src/functions/camel-to-kebab-case.ts +1 -0
- package/src/functions/deopt.ts +6 -0
- package/src/functions/evaluate/browser-runtime/browser.ts +61 -0
- package/src/functions/evaluate/browser-runtime/index.ts +1 -0
- package/src/functions/evaluate/choose-eval.ts +23 -0
- package/src/functions/evaluate/edge-runtime/acorn-interpreter.ts +2891 -0
- package/src/functions/evaluate/edge-runtime/edge-runtime.ts +89 -0
- package/src/functions/evaluate/edge-runtime/index.ts +1 -0
- package/src/functions/evaluate/evaluate.ts +76 -0
- package/src/functions/evaluate/helpers.ts +56 -0
- package/src/functions/evaluate/index.ts +1 -0
- package/src/functions/evaluate/node-runtime/index.ts +1 -0
- package/src/functions/evaluate/node-runtime/init.ts +33 -0
- package/src/functions/evaluate/node-runtime/node-runtime.ts +176 -0
- package/src/functions/evaluate/node-runtime/safeDynamicRequire.ts +14 -0
- package/src/functions/evaluate/placeholder-runtime.ts +4 -0
- package/src/functions/evaluate/should-force-browser-runtime-in-node.ts +16 -0
- package/src/functions/event-handler-name.ts +4 -0
- package/src/functions/extract-text-styles.ts +24 -0
- package/src/functions/fast-clone.ts +4 -0
- package/src/functions/fetch-builder-props.ts +75 -0
- package/src/functions/get-block-actions-handler.ts +17 -0
- package/src/functions/get-block-actions.ts +35 -0
- package/src/functions/get-block-component-options.ts +7 -0
- package/src/functions/get-block-properties.ts +62 -0
- package/src/functions/get-builder-search-params/index.ts +33 -0
- package/src/functions/get-class-prop-name.ts +15 -0
- package/src/functions/get-content/generate-content-url.ts +88 -0
- package/src/functions/get-content/index.ts +99 -0
- package/src/functions/get-content/types.ts +157 -0
- package/src/functions/get-env.ts +5 -0
- package/src/functions/get-fetch.ts +11 -0
- package/src/functions/get-global-this.ts +16 -0
- package/src/functions/get-processed-block.ts +70 -0
- package/src/functions/get-style.ts +38 -0
- package/src/functions/get.ts +4 -0
- package/src/functions/is-browser.ts +3 -0
- package/src/functions/is-edge-runtime.ts +9 -0
- package/src/functions/is-editing.ts +8 -0
- package/src/functions/is-from-trusted-host.ts +11 -0
- package/src/functions/is-iframe.ts +4 -0
- package/src/functions/is-node-runtime.ts +8 -0
- package/src/functions/is-previewing.ts +16 -0
- package/src/functions/on-change.ts +29 -0
- package/src/functions/register-component.ts +30 -0
- package/src/functions/register.ts +44 -0
- package/src/functions/set-editor-settings.ts +15 -0
- package/src/functions/set.ts +14 -0
- package/src/functions/track/helpers.ts +51 -0
- package/src/functions/track/index.ts +131 -0
- package/src/functions/track/interaction.ts +63 -0
- package/src/functions/transform-block-properties.ts +33 -0
- package/src/functions/transform-block.ts +30 -0
- package/src/functions/transform-style-property.ts +296 -0
- package/src/helpers/ab-tests.ts +166 -0
- package/src/helpers/canTrack.ts +2 -0
- package/src/helpers/cookie.ts +109 -0
- package/src/helpers/css.ts +33 -0
- package/src/helpers/flatten.ts +41 -0
- package/src/helpers/localStorage.ts +36 -0
- package/src/helpers/logger.ts +7 -0
- package/src/helpers/nullable.ts +2 -0
- package/src/helpers/omit.ts +7 -0
- package/src/helpers/preview-lru-cache/get.ts +4 -0
- package/src/helpers/preview-lru-cache/helpers.ts +1 -0
- package/src/helpers/preview-lru-cache/init.ts +7 -0
- package/src/helpers/preview-lru-cache/set.ts +12 -0
- package/src/helpers/preview-lru-cache/types.ts +1 -0
- package/src/helpers/search/search.ts +18 -0
- package/src/helpers/sessionId.ts +37 -0
- package/src/helpers/subscribe-to-editor.ts +95 -0
- package/src/helpers/time.ts +2 -0
- package/src/helpers/url.ts +15 -0
- package/src/helpers/uuid.ts +17 -0
- package/src/helpers/visitorId.ts +37 -0
- package/src/index-helpers/blocks-exports.ts +16 -0
- package/src/index-helpers/top-of-file.ts +2 -0
- package/src/index.ts +15 -0
- package/src/scripts/init-editing.ts +119 -0
- package/src/server-index.ts +43 -0
- package/src/types/api-version.ts +2 -0
- package/src/types/builder-block.ts +89 -0
- package/src/types/builder-content.ts +47 -0
- package/src/types/builder-props.ts +12 -0
- package/src/types/can-track.ts +3 -0
- package/src/types/components.ts +119 -0
- package/src/types/deep-partial.ts +1 -0
- package/src/types/element.ts +57 -0
- package/src/types/enforced-partials.ts +19 -0
- package/src/types/input.ts +123 -0
- package/src/types/targets.ts +1 -0
- package/src/types/typescript.ts +9 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WARNING: This file contains functions that get stringified and inlined into the HTML at build-time.
|
|
3
|
+
* They cannot import anything.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
type VariantData = {
|
|
7
|
+
id: string;
|
|
8
|
+
testRatio?: number;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* For more information on how this works,
|
|
13
|
+
* see our [SSR A/B Test Docs](https://github.com/BuilderIO/builder/tree/main/packages/sdks/src/SSR_AB_TEST.md)
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* For more information on how this works,
|
|
18
|
+
* see our [SSR A/B Test Docs](https://github.com/BuilderIO/builder/tree/main/packages/sdks/src/SSR_AB_TEST.md)
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export const UPDATE_COOKIES_AND_STYLES_SCRIPT = "function updateCookiesAndStyles(contentId, variants, isHydrationTarget) {\n function getAndSetVariantId() {\n function setCookie(name, value, days) {\n let expires = '';\n if (days) {\n const date = new Date();\n date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);\n expires = '; expires=' + date.toUTCString();\n }\n document.cookie = name + '=' + (value || '') + expires + '; path=/' + '; Secure; SameSite=None';\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${contentId}`;\n const variantInCookie = getCookie(cookieName);\n const availableIDs = variants.map(vr => vr.id).concat(contentId);\n if (variantInCookie && availableIDs.includes(variantInCookie)) {\n return variantInCookie;\n }\n let n = 0;\n const random = Math.random();\n for (let i = 0; i < variants.length; i++) {\n const variant = variants[i];\n const testRatio = variant.testRatio;\n n += testRatio;\n if (random < n) {\n setCookie(cookieName, variant.id);\n return variant.id;\n }\n }\n setCookie(cookieName, contentId);\n return contentId;\n }\n const winningVariantId = getAndSetVariantId();\n const styleEl = document.currentScript?.previousElementSibling;\n if (isHydrationTarget) {\n styleEl.remove();\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n } else {\n const newStyleStr = variants.concat({\n id: contentId\n }).filter(variant => variant.id !== winningVariantId).map(value => {\n return `.variant-${value.id} { display: none; }\n `;\n }).join('');\n styleEl.innerHTML = newStyleStr;\n }\n}";
|
|
22
|
+
export const UPDATE_VARIANT_VISIBILITY_SCRIPT = "function updateVariantVisibility(variantContentId, defaultContentId, isHydrationTarget) {\n if (!navigator.cookieEnabled) {\n return;\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${defaultContentId}`;\n const winningVariant = getCookie(cookieName);\n const parentDiv = document.currentScript?.parentElement;\n const isDefaultContent = variantContentId === defaultContentId;\n const isWinningVariant = winningVariant === variantContentId;\n if (isWinningVariant && !isDefaultContent) {\n parentDiv?.removeAttribute('hidden');\n parentDiv?.removeAttribute('aria-hidden');\n } else if (!isWinningVariant && isDefaultContent) {\n parentDiv?.setAttribute('hidden', 'true');\n parentDiv?.setAttribute('aria-hidden', 'true');\n }\n if (isHydrationTarget) {\n if (!isWinningVariant) {\n parentDiv?.remove();\n }\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n }\n return;\n}";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import {
|
|
3
|
+
FlatList,
|
|
4
|
+
ScrollView,
|
|
5
|
+
View,
|
|
6
|
+
StyleSheet,
|
|
7
|
+
Image,
|
|
8
|
+
Text,
|
|
9
|
+
Pressable,
|
|
10
|
+
TextInput,
|
|
11
|
+
} from "react-native";
|
|
12
|
+
|
|
13
|
+
export interface DynamicDivProps {
|
|
14
|
+
children?: any;
|
|
15
|
+
attributes: any;
|
|
16
|
+
actionAttributes: any;
|
|
17
|
+
BlockWrapperProps: any;
|
|
18
|
+
builderPath: any;
|
|
19
|
+
builderParentId: any;
|
|
20
|
+
BlocksWrapperProps: any;
|
|
21
|
+
contentWrapperProps: any;
|
|
22
|
+
builderModel: any;
|
|
23
|
+
ref: any;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function DynamicDiv(props: DynamicDivProps) {
|
|
27
|
+
return <View>{props.children}</View>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default DynamicDiv;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
|
|
3
|
+
*/
|
|
4
|
+
const EMPTY_HTML_ELEMENTS = new Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
|
|
5
|
+
export const isEmptyElement = (tagName: any): boolean => {
|
|
6
|
+
return typeof tagName === 'string' && EMPTY_HTML_ELEMENTS.has(tagName.toLowerCase());
|
|
7
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import {
|
|
3
|
+
FlatList,
|
|
4
|
+
ScrollView,
|
|
5
|
+
View,
|
|
6
|
+
StyleSheet,
|
|
7
|
+
Image,
|
|
8
|
+
Text,
|
|
9
|
+
Pressable,
|
|
10
|
+
TextInput,
|
|
11
|
+
} from "react-native";
|
|
12
|
+
|
|
13
|
+
export interface DynamicRendererProps {
|
|
14
|
+
children?: any;
|
|
15
|
+
TagName: any;
|
|
16
|
+
attributes: any;
|
|
17
|
+
actionAttributes: any;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
import { isEmptyElement } from "./dynamic-renderer.helpers";
|
|
21
|
+
import { setAttrs } from "../../blocks/helpers";
|
|
22
|
+
|
|
23
|
+
function DynamicRenderer(props: DynamicRendererProps) {
|
|
24
|
+
return (
|
|
25
|
+
<>
|
|
26
|
+
{!isEmptyElement(props.TagName) ? (
|
|
27
|
+
<>
|
|
28
|
+
{typeof props.TagName === "string" ? (
|
|
29
|
+
<props.TagName {...props.attributes} {...props.actionAttributes}>
|
|
30
|
+
{props.children}
|
|
31
|
+
</props.TagName>
|
|
32
|
+
) : (
|
|
33
|
+
<props.TagName {...props.attributes} {...props.actionAttributes}>
|
|
34
|
+
{props.children}
|
|
35
|
+
</props.TagName>
|
|
36
|
+
)}
|
|
37
|
+
</>
|
|
38
|
+
) : (
|
|
39
|
+
<>
|
|
40
|
+
<props.TagName {...props.attributes} {...props.actionAttributes} />
|
|
41
|
+
</>
|
|
42
|
+
)}
|
|
43
|
+
</>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default DynamicRenderer;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { logger } from '../helpers/logger';
|
|
3
|
+
|
|
4
|
+
export default class ErrorBoundary extends React.Component<
|
|
5
|
+
React.PropsWithChildren,
|
|
6
|
+
{ hasError: boolean }
|
|
7
|
+
> {
|
|
8
|
+
constructor(props) {
|
|
9
|
+
super(props);
|
|
10
|
+
this.state = { hasError: false };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static getDerivedStateFromError(_error) {
|
|
14
|
+
// Update state so the next render will show the fallback UI.
|
|
15
|
+
return { hasError: true };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
componentDidCatch(error, info) {
|
|
19
|
+
logger.error(
|
|
20
|
+
'ErrorBoundary caught error:',
|
|
21
|
+
info.error,
|
|
22
|
+
info.componentStack
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
render() {
|
|
27
|
+
if (this.state.hasError) {
|
|
28
|
+
return (
|
|
29
|
+
<p>
|
|
30
|
+
Builder.io SDK: error while rendering block. See console for full
|
|
31
|
+
logs.
|
|
32
|
+
</p>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return this.props.children;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { componentInfo as accordionComponentInfo } from '../blocks/accordion/component-info';
|
|
2
|
+
import { default as Accordion } from '../blocks/accordion/index';
|
|
3
|
+
import { componentInfo as buttonComponentInfo } from '../blocks/button/component-info';
|
|
4
|
+
import { default as Button } from '../blocks/button/index';
|
|
5
|
+
import { componentInfo as columnsComponentInfo } from '../blocks/columns/component-info';
|
|
6
|
+
import { default as Columns } from '../blocks/columns/index';
|
|
7
|
+
import { componentInfo as fragmentComponentInfo } from '../blocks/fragment/component-info';
|
|
8
|
+
import { default as Fragment } from '../blocks/fragment/index';
|
|
9
|
+
import { componentInfo as imageComponentInfo } from '../blocks/image/component-info';
|
|
10
|
+
import { default as Image } from '../blocks/image/index';
|
|
11
|
+
import { componentInfo as sectionComponentInfo } from '../blocks/section/component-info';
|
|
12
|
+
import { default as Section } from '../blocks/section/index';
|
|
13
|
+
import { componentInfo as slotComponentInfo } from '../blocks/slot/component-info';
|
|
14
|
+
import { default as Slot } from '../blocks/slot/index';
|
|
15
|
+
import { componentInfo as symbolComponentInfo } from '../blocks/symbol/component-info';
|
|
16
|
+
import { default as Symbol } from '../blocks/symbol/index';
|
|
17
|
+
import { componentInfo as tabsComponentInfo } from '../blocks/tabs/component-info';
|
|
18
|
+
import { default as Tabs } from '../blocks/tabs/index';
|
|
19
|
+
import { componentInfo as textComponentInfo } from '../blocks/text/component-info';
|
|
20
|
+
import { default as Text } from '../blocks/text/index';
|
|
21
|
+
import type { RegisteredComponent } from '../context/types';
|
|
22
|
+
import { getExtraComponents } from './extra-components';
|
|
23
|
+
import { TARGET } from './target';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Returns a list of all registered components.
|
|
27
|
+
* NOTE: This needs to be a function to work around ESM circular dependencies.
|
|
28
|
+
*/
|
|
29
|
+
export const getDefaultRegisteredComponents: () => RegisteredComponent[] = () => [{
|
|
30
|
+
component: Button,
|
|
31
|
+
...buttonComponentInfo
|
|
32
|
+
}, {
|
|
33
|
+
component: Columns,
|
|
34
|
+
...columnsComponentInfo
|
|
35
|
+
}, {
|
|
36
|
+
component: Fragment,
|
|
37
|
+
...fragmentComponentInfo
|
|
38
|
+
}, {
|
|
39
|
+
component: Image,
|
|
40
|
+
...imageComponentInfo
|
|
41
|
+
}, {
|
|
42
|
+
component: Section,
|
|
43
|
+
...sectionComponentInfo
|
|
44
|
+
}, {
|
|
45
|
+
component: Slot,
|
|
46
|
+
...slotComponentInfo
|
|
47
|
+
}, {
|
|
48
|
+
component: Symbol,
|
|
49
|
+
...symbolComponentInfo
|
|
50
|
+
}, {
|
|
51
|
+
component: Text,
|
|
52
|
+
...textComponentInfo
|
|
53
|
+
}, ...(TARGET === 'rsc' ? [] : [{
|
|
54
|
+
component: Tabs,
|
|
55
|
+
...tabsComponentInfo
|
|
56
|
+
}, {
|
|
57
|
+
component: Accordion,
|
|
58
|
+
...accordionComponentInfo
|
|
59
|
+
}]), ...getExtraComponents()]
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { fastClone } from '../functions/fast-clone';
|
|
2
|
+
export type SizeName = 'large' | 'medium' | 'small';
|
|
3
|
+
interface Size {
|
|
4
|
+
min: number;
|
|
5
|
+
default: number;
|
|
6
|
+
max: number;
|
|
7
|
+
}
|
|
8
|
+
const SIZES: Record<SizeName, Size> = {
|
|
9
|
+
small: {
|
|
10
|
+
min: 320,
|
|
11
|
+
default: 321,
|
|
12
|
+
max: 640
|
|
13
|
+
},
|
|
14
|
+
medium: {
|
|
15
|
+
min: 641,
|
|
16
|
+
default: 642,
|
|
17
|
+
max: 991
|
|
18
|
+
},
|
|
19
|
+
large: {
|
|
20
|
+
min: 990,
|
|
21
|
+
default: 991,
|
|
22
|
+
max: 1200
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export const getMaxWidthQueryForSize = (size: SizeName, sizeValues = SIZES) => `@media (max-width: ${sizeValues[size].max}px)`;
|
|
26
|
+
interface Breakpoints {
|
|
27
|
+
small?: number;
|
|
28
|
+
medium?: number;
|
|
29
|
+
}
|
|
30
|
+
export const getSizesForBreakpoints = ({
|
|
31
|
+
small,
|
|
32
|
+
medium
|
|
33
|
+
}: Breakpoints) => {
|
|
34
|
+
const newSizes = fastClone(SIZES); // Note: this helps to get a deep clone of fields like small, medium etc
|
|
35
|
+
|
|
36
|
+
if (!small || !medium) {
|
|
37
|
+
return newSizes;
|
|
38
|
+
}
|
|
39
|
+
const smallMin = Math.floor(small / 2);
|
|
40
|
+
newSizes.small = {
|
|
41
|
+
max: small,
|
|
42
|
+
min: smallMin,
|
|
43
|
+
default: smallMin + 1
|
|
44
|
+
};
|
|
45
|
+
const mediumMin = newSizes.small.max + 1;
|
|
46
|
+
newSizes.medium = {
|
|
47
|
+
max: medium,
|
|
48
|
+
min: mediumMin,
|
|
49
|
+
default: mediumMin + 1
|
|
50
|
+
};
|
|
51
|
+
const largeMin = newSizes.medium.max + 1;
|
|
52
|
+
newSizes.large = {
|
|
53
|
+
max: 2000,
|
|
54
|
+
// TODO: decide upper limit
|
|
55
|
+
min: largeMin,
|
|
56
|
+
default: largeMin + 1
|
|
57
|
+
};
|
|
58
|
+
return newSizes;
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const getExtraComponents = () => [];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const SDK_VERSION = "1.0.34"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
|
|
3
|
+
export default createContext<any>({
|
|
4
|
+
content: null,
|
|
5
|
+
context: {},
|
|
6
|
+
localState: undefined,
|
|
7
|
+
rootSetState() {},
|
|
8
|
+
rootState: {},
|
|
9
|
+
apiKey: null,
|
|
10
|
+
apiVersion: undefined,
|
|
11
|
+
componentInfos: {},
|
|
12
|
+
inheritedStyles: {},
|
|
13
|
+
BlocksWrapper: "div",
|
|
14
|
+
BlocksWrapperProps: {},
|
|
15
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as BuilderContext } from './builder.context'
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { BlocksWrapperProps } from '../components/blocks/blocks-wrapper';
|
|
2
|
+
import type { ApiVersion } from '../types/api-version';
|
|
3
|
+
import type { BuilderContent } from '../types/builder-content';
|
|
4
|
+
import type { ComponentInfo } from '../types/components';
|
|
5
|
+
import type { Dictionary, Nullable } from '../types/typescript';
|
|
6
|
+
export type RegisteredComponent = ComponentInfo & {
|
|
7
|
+
component: any;
|
|
8
|
+
};
|
|
9
|
+
export type RegisteredComponents = Dictionary<RegisteredComponent>;
|
|
10
|
+
export type BuilderRenderState = Record<string, unknown>;
|
|
11
|
+
export type BuilderRenderContext = Record<string, unknown>;
|
|
12
|
+
export interface BuilderContextInterface extends Pick<BlocksWrapperProps, 'BlocksWrapper' | 'BlocksWrapperProps'> {
|
|
13
|
+
content: Nullable<BuilderContent>;
|
|
14
|
+
context: BuilderRenderContext;
|
|
15
|
+
/**
|
|
16
|
+
* The state of the application.
|
|
17
|
+
*
|
|
18
|
+
* NOTE: see `localState` below to understand how it is different from `rootState`.
|
|
19
|
+
*/
|
|
20
|
+
rootState: BuilderRenderState;
|
|
21
|
+
/**
|
|
22
|
+
* Some frameworks have a `setState` function which needs to be invoked to notify
|
|
23
|
+
* the framework of state change. (other frameworks don't in which case it is `undefined')
|
|
24
|
+
*/
|
|
25
|
+
rootSetState: ((rootState: BuilderRenderState) => void) | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* The local state of the current component. This is different from `rootState` in that
|
|
28
|
+
* it can be a child state created by a repeater containing local state.
|
|
29
|
+
* The `rootState` is where all of the state mutations are actually stored.
|
|
30
|
+
*/
|
|
31
|
+
localState: BuilderRenderState | undefined;
|
|
32
|
+
apiKey: string | null;
|
|
33
|
+
apiVersion: ApiVersion | undefined;
|
|
34
|
+
componentInfos: Dictionary<ComponentInfo>;
|
|
35
|
+
// Used to recursively store all CSS coming from a parent that would apply to a Text block
|
|
36
|
+
inheritedStyles: Record<string, unknown>;
|
|
37
|
+
canTrack?: boolean;
|
|
38
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export type Patch = {
|
|
2
|
+
path: string;
|
|
3
|
+
op: 'add' | 'remove' | 'replace';
|
|
4
|
+
value: any;
|
|
5
|
+
};
|
|
6
|
+
export const applyPatchWithMinimalMutationChain = <T extends object,>(obj: T, patch: {
|
|
7
|
+
path: string;
|
|
8
|
+
op: 'add' | 'remove' | 'replace';
|
|
9
|
+
value: any;
|
|
10
|
+
}, preserveRoot = false): T => {
|
|
11
|
+
if (Object(obj) !== obj) {
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
const {
|
|
15
|
+
path,
|
|
16
|
+
op,
|
|
17
|
+
value
|
|
18
|
+
} = patch;
|
|
19
|
+
const pathArr: string[] = path.split(/\//);
|
|
20
|
+
if (pathArr[0] === '') {
|
|
21
|
+
pathArr.shift();
|
|
22
|
+
}
|
|
23
|
+
const newObj = preserveRoot ? obj : {
|
|
24
|
+
...obj
|
|
25
|
+
};
|
|
26
|
+
let objPart = (newObj as any);
|
|
27
|
+
for (let i = 0; i < pathArr.length; i++) {
|
|
28
|
+
const isLast = i === pathArr.length - 1;
|
|
29
|
+
const property = pathArr[i];
|
|
30
|
+
if (isLast) {
|
|
31
|
+
if (op === 'replace') {
|
|
32
|
+
objPart[property] = value;
|
|
33
|
+
} else if (op === 'add') {
|
|
34
|
+
const index = Number(property);
|
|
35
|
+
if (Array.isArray(objPart)) {
|
|
36
|
+
if (property === '-') {
|
|
37
|
+
objPart.push(value);
|
|
38
|
+
} else {
|
|
39
|
+
objPart.splice(index, 0, value);
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
objPart[property] = value;
|
|
43
|
+
}
|
|
44
|
+
} else if (op === 'remove') {
|
|
45
|
+
const index = Number(property);
|
|
46
|
+
if (Array.isArray(objPart)) {
|
|
47
|
+
objPart.splice(index, 1);
|
|
48
|
+
} else {
|
|
49
|
+
delete objPart[property];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
const nextProperty = pathArr[i + 1];
|
|
54
|
+
const newPart = Object(objPart[property]) === objPart[property] ? objPart[property] : String(Number(nextProperty)) === nextProperty ? [] : {};
|
|
55
|
+
objPart = objPart[property] = Array.isArray(newPart) ? [...newPart] : {
|
|
56
|
+
...newPart
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return newObj;
|
|
61
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const camelToKebabCase = (str?: string) => str ? str.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase() : ''
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { BuilderRenderState } from '../../../context/types';
|
|
2
|
+
import type { ExecutorArgs } from '../helpers';
|
|
3
|
+
import { getFunctionArguments } from '../helpers';
|
|
4
|
+
export const runInBrowser = ({
|
|
5
|
+
code,
|
|
6
|
+
builder,
|
|
7
|
+
context,
|
|
8
|
+
event,
|
|
9
|
+
localState,
|
|
10
|
+
rootSetState,
|
|
11
|
+
rootState
|
|
12
|
+
}: ExecutorArgs) => {
|
|
13
|
+
const functionArgs = getFunctionArguments({
|
|
14
|
+
builder,
|
|
15
|
+
context,
|
|
16
|
+
event,
|
|
17
|
+
state: flattenState({
|
|
18
|
+
rootState,
|
|
19
|
+
localState,
|
|
20
|
+
rootSetState
|
|
21
|
+
})
|
|
22
|
+
});
|
|
23
|
+
return new Function(...functionArgs.map(([name]) => name), code)(...functionArgs.map(([, value]) => value));
|
|
24
|
+
};
|
|
25
|
+
export function flattenState({
|
|
26
|
+
rootState,
|
|
27
|
+
localState,
|
|
28
|
+
rootSetState
|
|
29
|
+
}: {
|
|
30
|
+
rootState: Record<string | symbol, any>;
|
|
31
|
+
localState: Record<string | symbol, any> | undefined;
|
|
32
|
+
rootSetState: ((rootState: BuilderRenderState) => void) | undefined;
|
|
33
|
+
}): BuilderRenderState {
|
|
34
|
+
return new Proxy(rootState, {
|
|
35
|
+
get: (target, prop) => {
|
|
36
|
+
if (localState && prop in localState) {
|
|
37
|
+
return localState[prop];
|
|
38
|
+
}
|
|
39
|
+
const val = target[prop];
|
|
40
|
+
if (typeof val === 'object' && val !== null) {
|
|
41
|
+
return flattenState({
|
|
42
|
+
rootState: val,
|
|
43
|
+
localState: undefined,
|
|
44
|
+
rootSetState: rootSetState ? subState => {
|
|
45
|
+
target[prop] = subState;
|
|
46
|
+
rootSetState(target);
|
|
47
|
+
} : undefined
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return val;
|
|
51
|
+
},
|
|
52
|
+
set: (target, prop, value) => {
|
|
53
|
+
if (localState && prop in localState) {
|
|
54
|
+
throw new Error('Writing to local state is not allowed as it is read-only.');
|
|
55
|
+
}
|
|
56
|
+
target[prop] = value;
|
|
57
|
+
rootSetState?.(target);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { runInBrowser as evaluator } from './browser'
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isBrowser } from '../is-browser';
|
|
2
|
+
import { runInBrowser } from './browser-runtime/browser';
|
|
3
|
+
import type { ExecutorArgs } from './helpers';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* THIS IS A MAGICAL IMPORT. It is aliased by the build process of every SDK configuration, so that
|
|
7
|
+
* it points to the correct runtime for that configuration, which are expected to live exactly at:
|
|
8
|
+
* - ./browser-runtime/index.js
|
|
9
|
+
* - ./node-runtime/index.js
|
|
10
|
+
* - ./edge-runtime/index.js
|
|
11
|
+
*
|
|
12
|
+
* We have code in `/output-generation` that does this aliasing, and is re-used by each SDK.
|
|
13
|
+
* Also, each individual `tsconfig.json` aliases this import to the browser runtime so that the
|
|
14
|
+
* types can be resolved correctly.
|
|
15
|
+
*/
|
|
16
|
+
import { evaluator } from 'placeholder-runtime';
|
|
17
|
+
import { shouldForceBrowserRuntimeInNode } from './should-force-browser-runtime-in-node';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Even though we have separate runtimes for browser/node/edge, sometimes frameworks will
|
|
21
|
+
* end up sending the server runtime code to the browser (most notably in dev mode).
|
|
22
|
+
*/
|
|
23
|
+
export const chooseBrowserOrServerEval = (args: ExecutorArgs) => isBrowser() || shouldForceBrowserRuntimeInNode() ? runInBrowser(args) : evaluator(args)
|