@builder.io/sdk-react-native 1.0.32 → 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/functions/is-from-trusted-host.js +3 -0
- package/lib/browser/commonjs/functions/is-from-trusted-host.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/functions/is-from-trusted-host.js +3 -0
- package/lib/browser/module/functions/is-from-trusted-host.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/functions/is-from-trusted-host.d.ts.map +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/functions/is-from-trusted-host.js +3 -0
- package/lib/edge/commonjs/functions/is-from-trusted-host.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/functions/is-from-trusted-host.js +3 -0
- package/lib/edge/module/functions/is-from-trusted-host.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/functions/is-from-trusted-host.d.ts.map +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/functions/is-from-trusted-host.js +3 -0
- package/lib/node/commonjs/functions/is-from-trusted-host.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/functions/is-from-trusted-host.js +3 -0
- package/lib/node/module/functions/is-from-trusted-host.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/functions/is-from-trusted-host.d.ts.map +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,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)
|