@builder.io/sdk-react-nextjs 0.4.5
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/README.md +80 -0
- package/dist/blocks/button/button.d.ts +11 -0
- package/dist/blocks/button/button.js +12 -0
- package/dist/blocks/button/component-info.d.ts +2 -0
- package/dist/blocks/button/component-info.js +34 -0
- package/dist/blocks/columns/columns.d.ts +16 -0
- package/dist/blocks/columns/columns.js +119 -0
- package/dist/blocks/columns/component-info.d.ts +2 -0
- package/dist/blocks/columns/component-info.js +219 -0
- package/dist/blocks/custom-code/component-info.d.ts +2 -0
- package/dist/blocks/custom-code/component-info.js +23 -0
- package/dist/blocks/custom-code/custom-code.d.ts +6 -0
- package/dist/blocks/custom-code/custom-code.js +51 -0
- package/dist/blocks/embed/component-info.d.ts +2 -0
- package/dist/blocks/embed/component-info.js +38 -0
- package/dist/blocks/embed/embed.d.ts +5 -0
- package/dist/blocks/embed/embed.js +42 -0
- package/dist/blocks/embed/helpers.d.ts +1 -0
- package/dist/blocks/embed/helpers.js +2 -0
- package/dist/blocks/fragment/component-info.d.ts +2 -0
- package/dist/blocks/fragment/component-info.js +7 -0
- package/dist/blocks/fragment/fragment.d.ts +7 -0
- package/dist/blocks/fragment/fragment.js +6 -0
- package/dist/blocks/helpers.d.ts +13 -0
- package/dist/blocks/helpers.js +40 -0
- package/dist/blocks/image/component-info.d.ts +2 -0
- package/dist/blocks/image/component-info.js +121 -0
- package/dist/blocks/image/image.d.ts +21 -0
- package/dist/blocks/image/image.helpers.d.ts +1 -0
- package/dist/blocks/image/image.helpers.js +47 -0
- package/dist/blocks/image/image.js +81 -0
- package/dist/blocks/img/component-info.d.ts +2 -0
- package/dist/blocks/img/component-info.js +15 -0
- package/dist/blocks/img/img.d.ts +13 -0
- package/dist/blocks/img/img.js +10 -0
- package/dist/blocks/section/component-info.d.ts +2 -0
- package/dist/blocks/section/component-info.js +40 -0
- package/dist/blocks/section/section.d.ts +11 -0
- package/dist/blocks/section/section.js +17 -0
- package/dist/blocks/symbol/component-info.d.ts +2 -0
- package/dist/blocks/symbol/component-info.js +34 -0
- package/dist/blocks/symbol/symbol.d.ts +25 -0
- package/dist/blocks/symbol/symbol.helpers.d.ts +14 -0
- package/dist/blocks/symbol/symbol.helpers.js +30 -0
- package/dist/blocks/symbol/symbol.js +29 -0
- package/dist/blocks/text/component-info.d.ts +2 -0
- package/dist/blocks/text/component-info.js +19 -0
- package/dist/blocks/text/text.d.ts +5 -0
- package/dist/blocks/text/text.js +7 -0
- package/dist/blocks/video/component-info.d.ts +2 -0
- package/dist/blocks/video/component-info.js +82 -0
- package/dist/blocks/video/video.d.ts +19 -0
- package/dist/blocks/video/video.js +47 -0
- package/dist/components/block/block.d.ts +9 -0
- package/dist/components/block/block.helpers.d.ts +13 -0
- package/dist/components/block/block.helpers.js +67 -0
- package/dist/components/block/block.js +92 -0
- package/dist/components/block/components/block-styles.d.ts +8 -0
- package/dist/components/block/components/block-styles.js +65 -0
- package/dist/components/block/components/block-wrapper.d.ts +17 -0
- package/dist/components/block/components/block-wrapper.js +36 -0
- package/dist/components/block/components/component-ref/component-ref.d.ts +3 -0
- package/dist/components/block/components/component-ref/component-ref.helpers.d.ts +28 -0
- package/dist/components/block/components/component-ref/component-ref.helpers.js +21 -0
- package/dist/components/block/components/component-ref/component-ref.js +21 -0
- package/dist/components/block/components/interactive-element.d.ts +11 -0
- package/dist/components/block/components/interactive-element.js +20 -0
- package/dist/components/block/components/repeated-block.d.ts +9 -0
- package/dist/components/block/components/repeated-block.js +7 -0
- package/dist/components/block/types.d.ts +6 -0
- package/dist/components/block/types.js +1 -0
- package/dist/components/blocks/blocks-wrapper.d.ts +10 -0
- package/dist/components/blocks/blocks-wrapper.js +38 -0
- package/dist/components/blocks/blocks.d.ts +8 -0
- package/dist/components/blocks/blocks.js +10 -0
- package/dist/components/content/components/enable-editor.d.ts +9 -0
- package/dist/components/content/components/enable-editor.js +249 -0
- package/dist/components/content/components/styles.d.ts +8 -0
- package/dist/components/content/components/styles.helpers.d.ts +15 -0
- package/dist/components/content/components/styles.helpers.js +56 -0
- package/dist/components/content/components/styles.js +30 -0
- package/dist/components/content/content.d.ts +3 -0
- package/dist/components/content/content.helpers.d.ts +7 -0
- package/dist/components/content/content.helpers.js +25 -0
- package/dist/components/content/content.js +72 -0
- package/dist/components/content/content.types.d.ts +24 -0
- package/dist/components/content/content.types.js +1 -0
- package/dist/components/content/wrap-component-ref.d.ts +6 -0
- package/dist/components/content/wrap-component-ref.js +6 -0
- package/dist/components/content-variants/content-variants.d.ts +9 -0
- package/dist/components/content-variants/content-variants.js +39 -0
- package/dist/components/content-variants/content-variants.types.d.ts +20 -0
- package/dist/components/content-variants/content-variants.types.js +1 -0
- package/dist/components/content-variants/helpers.d.ts +41 -0
- package/dist/components/content-variants/helpers.js +188 -0
- package/dist/components/inlined-script.d.ts +6 -0
- package/dist/components/inlined-script.js +5 -0
- package/dist/components/inlined-styles.d.ts +6 -0
- package/dist/components/inlined-styles.js +5 -0
- package/dist/constants/builder-registered-components.d.ts +6 -0
- package/dist/constants/builder-registered-components.js +60 -0
- package/dist/constants/device-sizes.d.ts +13 -0
- package/dist/constants/device-sizes.js +45 -0
- package/dist/constants/sdk-version.d.ts +1 -0
- package/dist/constants/sdk-version.js +1 -0
- package/dist/constants/target.d.ts +2 -0
- package/dist/constants/target.js +2 -0
- package/dist/context/builder.context.d.ts +3 -0
- package/dist/context/builder.context.js +12 -0
- package/dist/context/types.d.ts +35 -0
- package/dist/context/types.js +1 -0
- package/dist/functions/apply-patch-with-mutation.d.ts +10 -0
- package/dist/functions/apply-patch-with-mutation.js +54 -0
- package/dist/functions/camel-to-kebab-case.d.ts +1 -0
- package/dist/functions/camel-to-kebab-case.js +1 -0
- package/dist/functions/evaluate.d.ts +7 -0
- package/dist/functions/evaluate.js +46 -0
- package/dist/functions/event-handler-name.d.ts +1 -0
- package/dist/functions/event-handler-name.js +4 -0
- package/dist/functions/extract-text-styles.d.ts +4 -0
- package/dist/functions/extract-text-styles.js +21 -0
- package/dist/functions/fast-clone.d.ts +4 -0
- package/dist/functions/fast-clone.js +4 -0
- package/dist/functions/get-block-actions-handler.d.ts +8 -0
- package/dist/functions/get-block-actions-handler.js +10 -0
- package/dist/functions/get-block-actions.d.ts +10 -0
- package/dist/functions/get-block-actions.js +28 -0
- package/dist/functions/get-block-component-options.d.ts +2 -0
- package/dist/functions/get-block-component-options.js +8 -0
- package/dist/functions/get-block-properties.d.ts +6 -0
- package/dist/functions/get-block-properties.js +71 -0
- package/dist/functions/get-builder-search-params/index.d.ts +12 -0
- package/dist/functions/get-builder-search-params/index.js +38 -0
- package/dist/functions/get-content/generate-content-url.d.ts +2 -0
- package/dist/functions/get-content/generate-content-url.js +32 -0
- package/dist/functions/get-content/index.d.ts +16 -0
- package/dist/functions/get-content/index.js +82 -0
- package/dist/functions/get-content/processCookies.d.ts +2 -0
- package/dist/functions/get-content/processCookies.js +35 -0
- package/dist/functions/get-content/types.d.ts +51 -0
- package/dist/functions/get-content/types.js +1 -0
- package/dist/functions/get-fetch.d.ts +1 -0
- package/dist/functions/get-fetch.js +11 -0
- package/dist/functions/get-global-this.d.ts +4 -0
- package/dist/functions/get-global-this.js +15 -0
- package/dist/functions/get-processed-block.d.ts +10 -0
- package/dist/functions/get-processed-block.js +43 -0
- package/dist/functions/get-react-native-block-styles.d.ts +7 -0
- package/dist/functions/get-react-native-block-styles.js +16 -0
- package/dist/functions/is-browser.d.ts +1 -0
- package/dist/functions/is-browser.js +3 -0
- package/dist/functions/is-editing.d.ts +1 -0
- package/dist/functions/is-editing.js +5 -0
- package/dist/functions/is-iframe.d.ts +1 -0
- package/dist/functions/is-iframe.js +4 -0
- package/dist/functions/is-previewing.d.ts +1 -0
- package/dist/functions/is-previewing.js +11 -0
- package/dist/functions/register-component.d.ts +15 -0
- package/dist/functions/register-component.js +34 -0
- package/dist/functions/register.d.ts +16 -0
- package/dist/functions/register.js +27 -0
- package/dist/functions/sanitize-react-native-block-styles.d.ts +3 -0
- package/dist/functions/sanitize-react-native-block-styles.js +58 -0
- package/dist/functions/set-editor-settings.d.ts +4 -0
- package/dist/functions/set-editor-settings.js +12 -0
- package/dist/functions/set.d.ts +7 -0
- package/dist/functions/set.js +14 -0
- package/dist/functions/track/helpers.d.ts +5 -0
- package/dist/functions/track/helpers.js +50 -0
- package/dist/functions/track/index.d.ts +51 -0
- package/dist/functions/track/index.js +69 -0
- package/dist/functions/track/interaction.d.ts +13 -0
- package/dist/functions/track/interaction.js +53 -0
- package/dist/functions/transform-block-properties.d.ts +1 -0
- package/dist/functions/transform-block-properties.js +5 -0
- package/dist/functions/transform-block.d.ts +2 -0
- package/dist/functions/transform-block.js +3 -0
- package/dist/helpers/ab-tests.d.ts +9 -0
- package/dist/helpers/ab-tests.js +116 -0
- package/dist/helpers/canTrack.d.ts +1 -0
- package/dist/helpers/canTrack.js +2 -0
- package/dist/helpers/cookie.d.ts +19 -0
- package/dist/helpers/cookie.js +54 -0
- package/dist/helpers/css.d.ts +7 -0
- package/dist/helpers/css.js +27 -0
- package/dist/helpers/flatten.d.ts +6 -0
- package/dist/helpers/flatten.js +17 -0
- package/dist/helpers/localStorage.d.ts +9 -0
- package/dist/helpers/localStorage.js +24 -0
- package/dist/helpers/logger.d.ts +6 -0
- package/dist/helpers/logger.js +7 -0
- package/dist/helpers/nullable.d.ts +2 -0
- package/dist/helpers/nullable.js +1 -0
- package/dist/helpers/preview-lru-cache/get.d.ts +1 -0
- package/dist/helpers/preview-lru-cache/get.js +7 -0
- package/dist/helpers/preview-lru-cache/helpers.d.ts +1 -0
- package/dist/helpers/preview-lru-cache/helpers.js +9 -0
- package/dist/helpers/preview-lru-cache/init.d.ts +1 -0
- package/dist/helpers/preview-lru-cache/init.js +15 -0
- package/dist/helpers/preview-lru-cache/set.d.ts +7 -0
- package/dist/helpers/preview-lru-cache/set.js +9 -0
- package/dist/helpers/preview-lru-cache/types.d.ts +12 -0
- package/dist/helpers/preview-lru-cache/types.js +1 -0
- package/dist/helpers/sessionId.d.ts +6 -0
- package/dist/helpers/sessionId.js +30 -0
- package/dist/helpers/url.d.ts +6 -0
- package/dist/helpers/url.js +15 -0
- package/dist/helpers/uuid.d.ts +8 -0
- package/dist/helpers/uuid.js +15 -0
- package/dist/helpers/visitorId.d.ts +6 -0
- package/dist/helpers/visitorId.js +30 -0
- package/dist/index-helpers/blocks-exports.d.ts +10 -0
- package/dist/index-helpers/blocks-exports.js +10 -0
- package/dist/index-helpers/top-of-file.d.ts +1 -0
- package/dist/index-helpers/top-of-file.js +4 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +10 -0
- package/dist/scripts/init-editing.d.ts +6 -0
- package/dist/scripts/init-editing.js +109 -0
- package/dist/types/api-version.d.ts +2 -0
- package/dist/types/api-version.js +1 -0
- package/dist/types/builder-block.d.ts +66 -0
- package/dist/types/builder-block.js +1 -0
- package/dist/types/builder-content.d.ts +44 -0
- package/dist/types/builder-content.js +1 -0
- package/dist/types/builder-props.d.ts +9 -0
- package/dist/types/builder-props.js +1 -0
- package/dist/types/can-track.d.ts +3 -0
- package/dist/types/can-track.js +1 -0
- package/dist/types/components.d.ts +111 -0
- package/dist/types/components.js +1 -0
- package/dist/types/deep-partial.d.ts +3 -0
- package/dist/types/deep-partial.js +1 -0
- package/dist/types/element.d.ts +59 -0
- package/dist/types/element.js +1 -0
- package/dist/types/enforced-partials.d.ts +21 -0
- package/dist/types/enforced-partials.js +1 -0
- package/dist/types/input.d.ts +121 -0
- package/dist/types/input.js +1 -0
- package/dist/types/targets.d.ts +1 -0
- package/dist/types/targets.js +1 -0
- package/dist/types/typescript.d.ts +11 -0
- package/dist/types/typescript.js +1 -0
- package/package.json +27 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { isBrowser } from '../functions/is-browser.js';
|
|
2
|
+
import { logger } from './logger.js';
|
|
3
|
+
import { checkIsDefined } from './nullable.js';
|
|
4
|
+
import { getTopLevelDomain } from './url.js';
|
|
5
|
+
export const getCookieSync = ({ name, canTrack }) => {
|
|
6
|
+
try {
|
|
7
|
+
if (!canTrack) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Extracted from MDN docs
|
|
12
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie#example_2_get_a_sample_cookie_named_test2
|
|
13
|
+
*/
|
|
14
|
+
return document.cookie.split('; ').find(row => row.startsWith(`${name}=`))?.split('=')[1];
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
logger.warn('[COOKIE] GET error: ', err?.message || err);
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* NOTE: This function is `async` because its react-native override is async. Do not remove the `async` keyword!
|
|
23
|
+
* The sync version is only safe to use in code blocks that `react-native` is guaranteed not to not run.
|
|
24
|
+
*/
|
|
25
|
+
export const getCookie = async (args) => getCookieSync(args);
|
|
26
|
+
const stringifyCookie = (cookie) => cookie.map(([key, value]) => value ? `${key}=${value}` : key).filter(checkIsDefined).join('; ');
|
|
27
|
+
const SECURE_CONFIG = [['secure', ''], ['SameSite', 'None']];
|
|
28
|
+
const createCookieString = ({ name, value, expires }) => {
|
|
29
|
+
const secure = isBrowser() ? location.protocol === 'https:' : true;
|
|
30
|
+
const secureObj = secure ? SECURE_CONFIG : [[]]; // TODO: need to know if secure server side
|
|
31
|
+
const expiresObj = expires ? [['expires', expires.toUTCString()]] : [[]];
|
|
32
|
+
const cookieValue = [[name, value], ...expiresObj, ['path', '/'], ['domain', getTopLevelDomain(window.location.hostname)], ...secureObj];
|
|
33
|
+
const cookie = stringifyCookie(cookieValue);
|
|
34
|
+
return cookie;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* NOTE: This function is `async` because its react-native override is async. Do not remove the `async` keyword!
|
|
38
|
+
*/
|
|
39
|
+
export const setCookie = async ({ name, value, expires, canTrack }) => {
|
|
40
|
+
try {
|
|
41
|
+
if (!canTrack) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const cookie = createCookieString({
|
|
45
|
+
name,
|
|
46
|
+
value,
|
|
47
|
+
expires
|
|
48
|
+
});
|
|
49
|
+
document.cookie = cookie;
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
logger.warn('[COOKIE] SET error: ', err?.message || err);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const convertStyleMapToCSSArray: (style: Partial<CSSStyleDeclaration>) => string[];
|
|
2
|
+
export declare const convertStyleMapToCSS: (style: Partial<CSSStyleDeclaration>) => string;
|
|
3
|
+
export declare const createCssClass: ({ mediaQuery, className, styles }: {
|
|
4
|
+
mediaQuery?: string;
|
|
5
|
+
className: string;
|
|
6
|
+
styles: Partial<CSSStyleDeclaration>;
|
|
7
|
+
}) => string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { camelToKebabCase } from '../functions/camel-to-kebab-case.js';
|
|
2
|
+
import { checkIsDefined } from './nullable.js';
|
|
3
|
+
export const convertStyleMapToCSSArray = (style) => {
|
|
4
|
+
const cssProps = Object.entries(style).map(([key, value]) => {
|
|
5
|
+
if (typeof value === 'string') {
|
|
6
|
+
return `${camelToKebabCase(key)}: ${value};`;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
return cssProps.filter(checkIsDefined);
|
|
13
|
+
};
|
|
14
|
+
export const convertStyleMapToCSS = (style) => convertStyleMapToCSSArray(style).join('\n');
|
|
15
|
+
export const createCssClass = ({ mediaQuery, className, styles }) => {
|
|
16
|
+
const cssClass = `.${className} {
|
|
17
|
+
${convertStyleMapToCSS(styles)}
|
|
18
|
+
}`;
|
|
19
|
+
if (mediaQuery) {
|
|
20
|
+
return `${mediaQuery} {
|
|
21
|
+
${cssClass}
|
|
22
|
+
}`;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return cssClass;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert deep object to a flat object with dots
|
|
3
|
+
*
|
|
4
|
+
* { foo: { bar: 'baz' }} -> { 'foo.bar': 'baz' }
|
|
5
|
+
*/
|
|
6
|
+
export function flatten(object, path = null, separator = '.') {
|
|
7
|
+
return Object.keys(object).reduce((acc, key) => {
|
|
8
|
+
const value = object[key];
|
|
9
|
+
const newPath = [path, key].filter(Boolean).join(separator);
|
|
10
|
+
const isObject = [typeof value === 'object', value !== null, !(Array.isArray(value) && value.length === 0)].every(Boolean);
|
|
11
|
+
return isObject ? { ...acc,
|
|
12
|
+
...flatten(value, newPath, separator)
|
|
13
|
+
} : { ...acc,
|
|
14
|
+
[newPath]: value
|
|
15
|
+
};
|
|
16
|
+
}, {});
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CanTrack } from '../types/can-track.js';
|
|
2
|
+
import type { Nullable } from './nullable.js';
|
|
3
|
+
export declare const getLocalStorageItem: ({ key, canTrack }: {
|
|
4
|
+
key: string;
|
|
5
|
+
} & CanTrack) => Nullable<string>;
|
|
6
|
+
export declare const setLocalStorageItem: ({ key, canTrack, value }: {
|
|
7
|
+
key: string;
|
|
8
|
+
value: string;
|
|
9
|
+
} & CanTrack) => void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isBrowser } from '../functions/is-browser.js';
|
|
2
|
+
const getLocalStorage = () => isBrowser() && typeof localStorage !== 'undefined' ? localStorage : undefined;
|
|
3
|
+
export const getLocalStorageItem = ({ key, canTrack }) => {
|
|
4
|
+
try {
|
|
5
|
+
if (canTrack) {
|
|
6
|
+
return getLocalStorage()?.getItem(key);
|
|
7
|
+
}
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
catch (err) {
|
|
11
|
+
console.debug('[LocalStorage] GET error: ', err);
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
export const setLocalStorageItem = ({ key, canTrack, value }) => {
|
|
16
|
+
try {
|
|
17
|
+
if (canTrack) {
|
|
18
|
+
getLocalStorage()?.setItem(key, value);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
console.debug('[LocalStorage] SET error: ', err);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const MSG_PREFIX = '[Builder.io]: ';
|
|
2
|
+
export const logger = {
|
|
3
|
+
log: (...message) => console.log(MSG_PREFIX, ...message),
|
|
4
|
+
error: (...message) => console.error(MSG_PREFIX, ...message),
|
|
5
|
+
warn: (...message) => console.warn(MSG_PREFIX, ...message),
|
|
6
|
+
debug: (...message) => console.debug(MSG_PREFIX, ...message)
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const checkIsDefined = (maybeT) => maybeT !== null && maybeT !== undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getPreviewContent(searchParams: URLSearchParams): import("../../types/builder-content").BuilderContent;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { getIdFromSearchParams } from './helpers';
|
|
2
|
+
import { init } from './init';
|
|
3
|
+
export function getPreviewContent(searchParams) {
|
|
4
|
+
init();
|
|
5
|
+
const id = getIdFromSearchParams(searchParams);
|
|
6
|
+
return typeof id === 'string' ? globalThis._BUILDER_PREVIEW_LRU_CACHE.get(id) : undefined;
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getIdFromSearchParams: (searchParams: URLSearchParams) => string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { logger } from '../logger';
|
|
2
|
+
export const getIdFromSearchParams = (searchParams) => {
|
|
3
|
+
const previewedModel = searchParams.get('preview');
|
|
4
|
+
const previewedId = searchParams.get('overrides.' + previewedModel);
|
|
5
|
+
if (!previewedId) {
|
|
6
|
+
logger.warn('No previewed ID found in search params.');
|
|
7
|
+
}
|
|
8
|
+
return previewedId;
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function init(): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is an LRU cache to hold preview content on the server-side.
|
|
3
|
+
*
|
|
4
|
+
* Note: This logic is only used by the NextJS SDK.
|
|
5
|
+
*/
|
|
6
|
+
import { LRUCache } from 'lru-cache';
|
|
7
|
+
export function init() {
|
|
8
|
+
if (!globalThis._BUILDER_PREVIEW_LRU_CACHE) {
|
|
9
|
+
globalThis._BUILDER_PREVIEW_LRU_CACHE = new LRUCache({
|
|
10
|
+
max: 500,
|
|
11
|
+
// how long to live in ms
|
|
12
|
+
ttl: 1000 * 60 * 5
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is an LRU cache to hold preview content on the server-side.
|
|
3
|
+
*
|
|
4
|
+
* Note: This logic is only used by the NextJS SDK.
|
|
5
|
+
*/
|
|
6
|
+
import type { LRUCache } from 'lru-cache';
|
|
7
|
+
import type { BuilderContent } from '../../types/builder-content';
|
|
8
|
+
type BuilderLRUCache = LRUCache<string, BuilderContent>;
|
|
9
|
+
export type GlobalWCache = typeof globalThis & {
|
|
10
|
+
_BUILDER_PREVIEW_LRU_CACHE: BuilderLRUCache;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CanTrack } from '../types/can-track.js';
|
|
2
|
+
export declare const getSessionId: ({ canTrack }: CanTrack) => Promise<string | undefined>;
|
|
3
|
+
export declare const createSessionId: () => string;
|
|
4
|
+
export declare const setSessionId: ({ id, canTrack }: {
|
|
5
|
+
id: string;
|
|
6
|
+
} & CanTrack) => Promise<void>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getCookie, setCookie } from './cookie.js';
|
|
2
|
+
import { checkIsDefined } from './nullable.js';
|
|
3
|
+
import { uuid } from './uuid.js';
|
|
4
|
+
const SESSION_LOCAL_STORAGE_KEY = 'builderSessionId';
|
|
5
|
+
export const getSessionId = async ({ canTrack }) => {
|
|
6
|
+
if (!canTrack) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
const sessionId = await getCookie({
|
|
10
|
+
name: SESSION_LOCAL_STORAGE_KEY,
|
|
11
|
+
canTrack
|
|
12
|
+
});
|
|
13
|
+
if (checkIsDefined(sessionId)) {
|
|
14
|
+
return sessionId;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
const newSessionId = createSessionId();
|
|
18
|
+
setSessionId({
|
|
19
|
+
id: newSessionId,
|
|
20
|
+
canTrack
|
|
21
|
+
});
|
|
22
|
+
return newSessionId;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export const createSessionId = () => uuid();
|
|
26
|
+
export const setSessionId = ({ id, canTrack }) => setCookie({
|
|
27
|
+
name: SESSION_LOCAL_STORAGE_KEY,
|
|
28
|
+
value: id,
|
|
29
|
+
canTrack
|
|
30
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Only gets one level up from hostname
|
|
3
|
+
* wwww.example.com -> example.com
|
|
4
|
+
* www.example.co.uk -> example.co.uk
|
|
5
|
+
*/
|
|
6
|
+
export const getTopLevelDomain = (host) => {
|
|
7
|
+
if (host === 'localhost' || host === '127.0.0.1') {
|
|
8
|
+
return host;
|
|
9
|
+
}
|
|
10
|
+
const parts = host.split('.');
|
|
11
|
+
if (parts.length > 2) {
|
|
12
|
+
return parts.slice(1).join('.');
|
|
13
|
+
}
|
|
14
|
+
return host;
|
|
15
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @credit https://stackoverflow.com/a/2117523
|
|
3
|
+
*/
|
|
4
|
+
export function uuidv4() {
|
|
5
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
6
|
+
const r = Math.random() * 16 | 0, v = c == 'x' ? r : r & 0x3 | 0x8;
|
|
7
|
+
return v.toString(16);
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Slightly cleaner and smaller UUIDs
|
|
12
|
+
*/
|
|
13
|
+
export function uuid() {
|
|
14
|
+
return uuidv4().replace(/-/g, '');
|
|
15
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CanTrack } from '../types/can-track.js';
|
|
2
|
+
export declare const getVisitorId: ({ canTrack }: CanTrack) => string | undefined;
|
|
3
|
+
export declare const createVisitorId: () => string;
|
|
4
|
+
export declare const setVisitorId: ({ id, canTrack }: {
|
|
5
|
+
id: string;
|
|
6
|
+
} & CanTrack) => void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getLocalStorageItem, setLocalStorageItem } from './localStorage.js';
|
|
2
|
+
import { checkIsDefined } from './nullable.js';
|
|
3
|
+
import { uuid } from './uuid.js';
|
|
4
|
+
const VISITOR_LOCAL_STORAGE_KEY = 'builderVisitorId';
|
|
5
|
+
export const getVisitorId = ({ canTrack }) => {
|
|
6
|
+
if (!canTrack) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
const visitorId = getLocalStorageItem({
|
|
10
|
+
key: VISITOR_LOCAL_STORAGE_KEY,
|
|
11
|
+
canTrack
|
|
12
|
+
});
|
|
13
|
+
if (checkIsDefined(visitorId)) {
|
|
14
|
+
return visitorId;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
const newVisitorId = createVisitorId();
|
|
18
|
+
setVisitorId({
|
|
19
|
+
id: newVisitorId,
|
|
20
|
+
canTrack
|
|
21
|
+
});
|
|
22
|
+
return newVisitorId;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export const createVisitorId = () => uuid();
|
|
26
|
+
export const setVisitorId = ({ id, canTrack }) => setLocalStorageItem({
|
|
27
|
+
key: VISITOR_LOCAL_STORAGE_KEY,
|
|
28
|
+
value: id,
|
|
29
|
+
canTrack
|
|
30
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { default as Button } from '../blocks/button/button.js';
|
|
2
|
+
export { default as Columns } from '../blocks/columns/columns.js';
|
|
3
|
+
export { default as Fragment } from '../blocks/fragment/fragment.js';
|
|
4
|
+
export { default as Image } from '../blocks/image/image.js';
|
|
5
|
+
export { default as RenderBlocks } from '../components/blocks/blocks.js';
|
|
6
|
+
export { default as Section } from '../blocks/section/section.js';
|
|
7
|
+
export { default as Symbol } from '../blocks/symbol/symbol.js';
|
|
8
|
+
export { default as Text } from '../blocks/text/text.js';
|
|
9
|
+
export { default as Video } from '../blocks/video/video.js';
|
|
10
|
+
export { default as RenderContent } from '../components/content-variants/content-variants.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { default as Button } from '../blocks/button/button.js';
|
|
2
|
+
export { default as Columns } from '../blocks/columns/columns.js';
|
|
3
|
+
export { default as Fragment } from '../blocks/fragment/fragment.js';
|
|
4
|
+
export { default as Image } from '../blocks/image/image.js';
|
|
5
|
+
export { default as RenderBlocks } from '../components/blocks/blocks.js';
|
|
6
|
+
export { default as Section } from '../blocks/section/section.js';
|
|
7
|
+
export { default as Symbol } from '../blocks/symbol/symbol.js';
|
|
8
|
+
export { default as Text } from '../blocks/text/text.js';
|
|
9
|
+
export { default as Video } from '../blocks/video/video.js';
|
|
10
|
+
export { default as RenderContent } from '../components/content-variants/content-variants.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default undefined;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './index-helpers/top-of-file.js';
|
|
2
|
+
export * from './index-helpers/blocks-exports.js';
|
|
3
|
+
export { isEditing } from './functions/is-editing.js';
|
|
4
|
+
export { isPreviewing } from './functions/is-previewing.js';
|
|
5
|
+
export { createRegisterComponentMessage } from './functions/register-component.js';
|
|
6
|
+
export { register } from './functions/register.js';
|
|
7
|
+
export type { InsertMenuConfig, InsertMenuItem } from './functions/register.js';
|
|
8
|
+
export { setEditorSettings } from './functions/set-editor-settings.js';
|
|
9
|
+
export type { Settings } from './functions/set-editor-settings.js';
|
|
10
|
+
export { getAllContent, getContent, processContentResult } from './functions/get-content/index.js';
|
|
11
|
+
export { getBuilderSearchParams } from './functions/get-builder-search-params/index.js';
|
|
12
|
+
export { track } from './functions/track/index.js';
|
|
13
|
+
export type { RegisteredComponent } from './context/types';
|
|
14
|
+
export type { ComponentInfo } from './types/components';
|
|
15
|
+
export type { ContentProps } from './components/content/content.types.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './index-helpers/top-of-file.js';
|
|
2
|
+
export * from './index-helpers/blocks-exports.js';
|
|
3
|
+
export { isEditing } from './functions/is-editing.js';
|
|
4
|
+
export { isPreviewing } from './functions/is-previewing.js';
|
|
5
|
+
export { createRegisterComponentMessage } from './functions/register-component.js';
|
|
6
|
+
export { register } from './functions/register.js';
|
|
7
|
+
export { setEditorSettings } from './functions/set-editor-settings.js';
|
|
8
|
+
export { getAllContent, getContent, processContentResult } from './functions/get-content/index.js';
|
|
9
|
+
export { getBuilderSearchParams } from './functions/get-builder-search-params/index.js';
|
|
10
|
+
export { track } from './functions/track/index.js';
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { SDK_VERSION } from '../constants/sdk-version.js';
|
|
2
|
+
import { TARGET } from '../constants/target.js';
|
|
3
|
+
import { isBrowser } from '../functions/is-browser.js';
|
|
4
|
+
import { register } from '../functions/register.js';
|
|
5
|
+
export const registerInsertMenu = () => {
|
|
6
|
+
register('insertMenu', {
|
|
7
|
+
name: '_default',
|
|
8
|
+
default: true,
|
|
9
|
+
items: [{
|
|
10
|
+
name: 'Box'
|
|
11
|
+
}, {
|
|
12
|
+
name: 'Text'
|
|
13
|
+
}, {
|
|
14
|
+
name: 'Image'
|
|
15
|
+
}, {
|
|
16
|
+
name: 'Columns'
|
|
17
|
+
}, ...(TARGET === 'reactNative' ? [] : [{
|
|
18
|
+
name: 'Core:Section'
|
|
19
|
+
}, {
|
|
20
|
+
name: 'Core:Button'
|
|
21
|
+
}, {
|
|
22
|
+
name: 'Embed'
|
|
23
|
+
}, {
|
|
24
|
+
name: 'Custom Code'
|
|
25
|
+
}])]
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
let isSetupForEditing = false;
|
|
29
|
+
export const setupBrowserForEditing = (options = {}) => {
|
|
30
|
+
if (isSetupForEditing) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
isSetupForEditing = true;
|
|
34
|
+
if (isBrowser()) {
|
|
35
|
+
window.parent?.postMessage({
|
|
36
|
+
type: 'builder.sdkInfo',
|
|
37
|
+
data: {
|
|
38
|
+
target: TARGET,
|
|
39
|
+
version: SDK_VERSION,
|
|
40
|
+
supportsPatchUpdates: false,
|
|
41
|
+
// Supports builder-model="..." attribute which is needed to
|
|
42
|
+
// scope our '+ add block' button styling
|
|
43
|
+
supportsAddBlockScoping: true,
|
|
44
|
+
supportsCustomBreakpoints: true
|
|
45
|
+
}
|
|
46
|
+
}, '*');
|
|
47
|
+
window.parent?.postMessage({
|
|
48
|
+
type: 'builder.updateContent',
|
|
49
|
+
data: {
|
|
50
|
+
options
|
|
51
|
+
}
|
|
52
|
+
}, '*');
|
|
53
|
+
window.addEventListener('message', ({ data }) => {
|
|
54
|
+
if (!data?.type) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
switch (data.type) {
|
|
58
|
+
case 'builder.evaluate':
|
|
59
|
+
{
|
|
60
|
+
const text = data.data.text;
|
|
61
|
+
const args = data.data.arguments || [];
|
|
62
|
+
const id = data.data.id; // tslint:disable-next-line:no-function-constructor-with-string-args
|
|
63
|
+
const fn = new Function(text);
|
|
64
|
+
let result;
|
|
65
|
+
let error = null;
|
|
66
|
+
try {
|
|
67
|
+
// eslint-disable-next-line prefer-spread
|
|
68
|
+
result = fn.apply(null, args);
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
error = err;
|
|
72
|
+
}
|
|
73
|
+
if (error) {
|
|
74
|
+
window.parent?.postMessage({
|
|
75
|
+
type: 'builder.evaluateError',
|
|
76
|
+
data: {
|
|
77
|
+
id,
|
|
78
|
+
error: error.message
|
|
79
|
+
}
|
|
80
|
+
}, '*');
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
if (result && typeof result.then === 'function') {
|
|
84
|
+
result.then(finalResult => {
|
|
85
|
+
window.parent?.postMessage({
|
|
86
|
+
type: 'builder.evaluateResult',
|
|
87
|
+
data: {
|
|
88
|
+
id,
|
|
89
|
+
result: finalResult
|
|
90
|
+
}
|
|
91
|
+
}, '*');
|
|
92
|
+
}).catch(console.error);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
window.parent?.postMessage({
|
|
96
|
+
type: 'builder.evaluateResult',
|
|
97
|
+
data: {
|
|
98
|
+
result,
|
|
99
|
+
id
|
|
100
|
+
}
|
|
101
|
+
}, '*');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const DEFAULT_API_VERSION = 'v3';
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
type JSONValue = string | number | boolean | JSONObject | JSONArray;
|
|
2
|
+
interface JSONObject {
|
|
3
|
+
[x: string]: JSONValue;
|
|
4
|
+
}
|
|
5
|
+
interface JSONArray extends Array<JSONValue> {
|
|
6
|
+
}
|
|
7
|
+
/** @todo typedoc this */
|
|
8
|
+
export interface BuilderBlock {
|
|
9
|
+
'@type': '@builder.io/sdk:Element';
|
|
10
|
+
'@version'?: number;
|
|
11
|
+
id?: string;
|
|
12
|
+
tagName?: string;
|
|
13
|
+
layerName?: string;
|
|
14
|
+
groupLocked?: boolean;
|
|
15
|
+
layerLocked?: boolean;
|
|
16
|
+
/** @todo make alias for properties.class */
|
|
17
|
+
class?: string;
|
|
18
|
+
children?: BuilderBlock[];
|
|
19
|
+
responsiveStyles?: {
|
|
20
|
+
large?: Partial<CSSStyleDeclaration>;
|
|
21
|
+
medium?: Partial<CSSStyleDeclaration>;
|
|
22
|
+
small?: Partial<CSSStyleDeclaration>;
|
|
23
|
+
/** @deprecated */
|
|
24
|
+
xsmall?: Partial<CSSStyleDeclaration>;
|
|
25
|
+
};
|
|
26
|
+
component?: {
|
|
27
|
+
name: string;
|
|
28
|
+
options?: any;
|
|
29
|
+
tag?: string;
|
|
30
|
+
};
|
|
31
|
+
bindings?: {
|
|
32
|
+
[key: string]: string;
|
|
33
|
+
};
|
|
34
|
+
meta?: {
|
|
35
|
+
[key: string]: JSONValue;
|
|
36
|
+
};
|
|
37
|
+
actions?: {
|
|
38
|
+
[key: string]: string;
|
|
39
|
+
};
|
|
40
|
+
properties?: {
|
|
41
|
+
[key: string]: string;
|
|
42
|
+
};
|
|
43
|
+
code?: {
|
|
44
|
+
bindings?: {
|
|
45
|
+
[key: string]: string;
|
|
46
|
+
};
|
|
47
|
+
actions?: {
|
|
48
|
+
[key: string]: string;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
repeat?: {
|
|
52
|
+
collection: string;
|
|
53
|
+
itemName?: string;
|
|
54
|
+
} | null;
|
|
55
|
+
animations?: any[];
|
|
56
|
+
style?: Partial<CSSStyleDeclaration>;
|
|
57
|
+
/**
|
|
58
|
+
* generated by the "Hide If" binding
|
|
59
|
+
*/
|
|
60
|
+
hide?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* generated by the "Show If" binding
|
|
63
|
+
*/
|
|
64
|
+
show?: boolean;
|
|
65
|
+
}
|
|
66
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|