@builder.io/sdk-svelte 0.0.3 → 0.0.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/package/--package.json +160 -0
- package/package/blocks/BaseText.svelte +19 -0
- package/package/blocks/BaseText.svelte.d.ts +19 -0
- package/package/blocks/columns/columns.svelte +13 -4
- package/package/blocks/columns/columns.svelte.d.ts +1 -1
- package/package/blocks/custom-code/custom-code.svelte +1 -1
- package/package/blocks/embed/embed.svelte +2 -0
- package/package/blocks/form/form.svelte +7 -5
- package/package/blocks/image/image.svelte +48 -46
- package/package/blocks/image/image.svelte.d.ts +1 -1
- package/package/blocks/img/img.svelte +7 -2
- package/package/blocks/section/section.svelte +7 -2
- package/package/blocks/symbol/symbol.svelte +13 -13
- package/package/blocks/symbol/symbol.svelte.d.ts +3 -3
- package/package/blocks/video/video.svelte +14 -3
- package/package/components/render-block/block-styles.svelte +24 -19
- package/package/components/render-block/block-styles.svelte.d.ts +2 -2
- package/package/components/render-block/render-block.svelte +81 -58
- package/package/components/render-block/render-block.svelte.d.ts +2 -2
- package/package/components/render-block/render-component-with-context.svelte +32 -0
- package/package/components/render-block/render-component-with-context.svelte.d.ts +19 -0
- package/package/components/render-block/render-component.svelte +1 -3
- package/package/components/render-block/render-component.svelte.d.ts +2 -2
- package/package/components/render-block/render-repeated-block.svelte +3 -0
- package/package/components/render-block/types.d.ts +2 -2
- package/package/components/render-block/types.js +1 -2
- package/package/components/render-blocks.svelte +12 -1
- package/package/components/render-blocks.svelte.d.ts +3 -1
- package/package/components/render-content/components/render-styles.svelte +2 -1
- package/package/components/render-content/render-content.svelte +24 -8
- package/package/components/render-content/render-content.svelte.d.ts +2 -2
- package/package/constants/builder-registered-components.js +3 -0
- package/package/context/builder.context.d.ts +1 -0
- package/package/context/builder.context.js +1 -0
- package/package/context/types.d.ts +4 -3
- package/package/context/types.js +1 -3
- package/package/functions/extract-text-styles.d.ts +4 -0
- package/package/functions/extract-text-styles.js +34 -0
- package/package/functions/fast-clone.d.ts +4 -0
- package/package/functions/fast-clone.js +4 -0
- package/package/functions/get-block-actions-handler.d.ts +5 -0
- package/package/functions/get-block-actions-handler.js +9 -0
- package/package/functions/get-block-actions.d.ts +1 -1
- package/package/functions/get-block-actions.js +2 -8
- package/package/functions/get-block-component-options.d.ts +1 -1
- package/package/functions/get-block-component-options.js +0 -1
- package/package/functions/get-block-properties.d.ts +1 -1
- package/package/functions/get-block-properties.js +0 -1
- package/package/functions/get-block-tag.d.ts +1 -1
- package/package/functions/get-block-tag.js +0 -1
- package/package/functions/get-content/ab-testing.d.ts +5 -3
- package/package/functions/get-content/ab-testing.js +75 -37
- package/package/functions/get-content/index.d.ts +1 -1
- package/package/functions/get-content/index.js +4 -5
- package/package/functions/get-content/types.d.ts +7 -2
- package/package/functions/get-processed-block.d.ts +1 -1
- package/package/functions/get-processed-block.js +5 -4
- package/package/functions/get-processed-block.test.js +0 -1
- package/package/functions/get-react-native-block-styles.d.ts +6 -0
- package/package/functions/get-react-native-block-styles.js +16 -0
- package/package/functions/register-component.d.ts +2 -2
- package/package/functions/register-component.js +1 -5
- package/package/functions/register.d.ts +2 -2
- package/package/functions/register.js +0 -2
- package/package/functions/sanitize-react-native-block-styles.d.ts +3 -0
- package/package/functions/sanitize-react-native-block-styles.js +53 -0
- package/package/functions/track.d.ts +1 -1
- package/package/functions/track.js +5 -6
- package/package/functions/transform-block.d.ts +1 -1
- package/package/functions/transform-block.js +0 -1
- package/package/helpers/ab-tests.d.ts +8 -0
- package/package/helpers/ab-tests.js +5 -0
- package/package/helpers/cookie.d.ts +9 -3
- package/package/helpers/cookie.js +8 -3
- package/package/helpers/css.d.ts +5 -1
- package/package/helpers/css.js +14 -1
- package/package/helpers/localStorage.d.ts +3 -4
- package/package/helpers/sessionId.d.ts +3 -4
- package/package/helpers/sessionId.js +5 -3
- package/package/helpers/visitorId.d.ts +3 -5
- package/package/scripts/init-editing.js +42 -38
- package/package/types/builder-content.d.ts +1 -1
- package/package/types/builder-content.js +1 -1
- package/package/types/targets.d.ts +1 -1
- package/package/types/typescript.d.ts +1 -0
- package/package.json +10 -4
- package/src/blocks/BaseText.svelte +27 -0
- package/{package/blocks/button/button.lite.tsx → src/blocks/button/button.svelte} +0 -0
- package/src/blocks/button/component-info.ts +42 -0
- package/{package/blocks/columns/columns.lite.tsx → src/blocks/columns/columns.svelte} +26 -17
- package/src/blocks/columns/component-info.ts +254 -0
- package/src/blocks/custom-code/component-info.ts +31 -0
- package/{package/blocks/custom-code/custom-code.lite.tsx → src/blocks/custom-code/custom-code.svelte} +1 -5
- package/src/blocks/embed/component-info.ts +53 -0
- package/{package/blocks/embed/embed.lite.tsx → src/blocks/embed/embed.svelte} +1 -2
- package/src/blocks/embed/helpers.ts +8 -0
- package/src/blocks/form/component-info.ts +282 -0
- package/{package/blocks/form/form.lite.tsx → src/blocks/form/form.svelte} +12 -31
- package/src/blocks/fragment/component-info.ts +10 -0
- package/{package/blocks/fragment/fragment.lite.tsx → src/blocks/fragment/fragment.svelte} +0 -0
- package/src/blocks/image/component-info.ts +170 -0
- package/src/blocks/image/image.helpers.ts +75 -0
- package/{package/blocks/image/image.lite.tsx → src/blocks/image/image.svelte} +47 -50
- package/src/blocks/img/component-info.ts +21 -0
- package/{package/blocks/img/img.lite.tsx → src/blocks/img/img.svelte} +6 -3
- package/src/blocks/input/component-info.ts +78 -0
- package/{package/blocks/input/input.lite.tsx → src/blocks/input/input.svelte} +0 -0
- package/src/blocks/raw-text/component-info.ts +15 -0
- package/{package/blocks/raw-text/raw-text.lite.tsx → src/blocks/raw-text/raw-text.svelte} +2 -1
- package/src/blocks/section/component-info.ts +50 -0
- package/{package/blocks/section/section.lite.tsx → src/blocks/section/section.svelte} +6 -2
- package/src/blocks/select/component-info.ts +61 -0
- package/{package/blocks/select/select.lite.tsx → src/blocks/select/select.svelte} +0 -0
- package/src/blocks/submit-button/component-info.ts +32 -0
- package/{package/blocks/submit-button/submit-button.lite.tsx → src/blocks/submit-button/submit-button.svelte} +0 -0
- package/src/blocks/symbol/component-info.ts +43 -0
- package/{package/blocks/symbol/symbol.lite.tsx → src/blocks/symbol/symbol.svelte} +23 -15
- package/src/blocks/text/component-info.ts +24 -0
- package/{package/blocks/text/text.lite.tsx → src/blocks/text/text.svelte} +0 -0
- package/src/blocks/textarea/component-info.ts +48 -0
- package/{package/blocks/textarea/textarea.lite.tsx → src/blocks/textarea/textarea.svelte} +0 -0
- package/src/blocks/util.ts +6 -0
- package/src/blocks/video/component-info.ts +109 -0
- package/{package/blocks/video/video.lite.tsx → src/blocks/video/video.svelte} +13 -3
- package/{package/components/render-block/block-styles.lite.tsx → src/components/render-block/block-styles.svelte} +28 -26
- package/src/components/render-block/render-block.helpers.ts +27 -0
- package/{package/components/render-block/render-block.lite.tsx → src/components/render-block/render-block.svelte} +93 -81
- package/src/components/render-block/render-component-with-context.svelte +38 -0
- package/{package/components/render-block/render-component.lite.tsx → src/components/render-block/render-component.svelte} +5 -3
- package/{package/components/render-block/render-repeated-block.lite.tsx → src/components/render-block/render-repeated-block.svelte} +4 -0
- package/src/components/render-block/types.ts +7 -0
- package/{package/components/render-blocks.lite.tsx → src/components/render-blocks.svelte} +15 -2
- package/{package/components/render-content/components/render-styles.lite.tsx → src/components/render-content/components/render-styles.svelte} +2 -8
- package/src/components/render-content/index.ts +1 -0
- package/{package/components/render-content/render-content.lite.tsx → src/components/render-content/render-content.svelte} +34 -36
- package/{package/components/render-inlined-styles.lite.tsx → src/components/render-inlined-styles.svelte} +0 -1
- package/src/constants/builder-registered-components.ts +42 -0
- package/src/constants/device-sizes.ts +28 -0
- package/src/constants/target.ts +2 -0
- package/src/context/builder.context.ts +13 -0
- package/src/context/types.ts +23 -0
- package/src/functions/camel-to-kebab-case.ts +2 -0
- package/src/functions/evaluate.ts +52 -0
- package/src/functions/event-handler-name.ts +6 -0
- package/src/functions/extract-text-styles.ts +39 -0
- package/src/functions/fast-clone.ts +5 -0
- package/src/functions/get-block-actions-handler.ts +19 -0
- package/src/functions/get-block-actions.ts +25 -0
- package/src/functions/get-block-component-options.ts +12 -0
- package/src/functions/get-block-properties.ts +11 -0
- package/src/functions/get-block-tag.ts +7 -0
- package/src/functions/get-builder-search-params/fn.test.ts +19 -0
- package/src/functions/get-builder-search-params/index.ts +48 -0
- package/src/functions/get-content/ab-testing.ts +132 -0
- package/src/functions/get-content/fn.test.ts +35 -0
- package/src/functions/get-content/index.ts +77 -0
- package/src/functions/get-content/types.ts +36 -0
- package/src/functions/get-fetch.ts +14 -0
- package/src/functions/get-global-this.ts +15 -0
- package/src/functions/get-processed-block.test.ts +33 -0
- package/src/functions/get-processed-block.ts +54 -0
- package/src/functions/get-react-native-block-styles.ts +30 -0
- package/src/functions/if-target.ts +20 -0
- package/src/functions/is-browser.ts +3 -0
- package/src/functions/is-editing.ts +7 -0
- package/src/functions/is-iframe.ts +5 -0
- package/src/functions/is-previewing.ts +14 -0
- package/src/functions/mark-mutable.ts +7 -0
- package/src/functions/on-change.test.ts +23 -0
- package/src/functions/on-change.ts +29 -0
- package/src/functions/register-component.ts +67 -0
- package/src/functions/register.ts +46 -0
- package/src/functions/sanitize-react-native-block-styles.ts +65 -0
- package/src/functions/set-editor-settings.ts +16 -0
- package/src/functions/set.test.ts +19 -0
- package/src/functions/set.ts +26 -0
- package/src/functions/track.ts +90 -0
- package/src/functions/transform-block.ts +6 -0
- package/src/helpers/ab-tests.ts +22 -0
- package/src/helpers/cookie.ts +102 -0
- package/src/helpers/css.ts +33 -0
- package/src/helpers/flatten.ts +24 -0
- package/src/helpers/localStorage.ts +38 -0
- package/src/helpers/nullable.ts +4 -0
- package/src/helpers/sessionId.ts +34 -0
- package/src/helpers/time.ts +4 -0
- package/src/helpers/url.test.ts +16 -0
- package/src/helpers/url.ts +12 -0
- package/src/helpers/uuid.ts +17 -0
- package/src/helpers/visitorId.ts +38 -0
- package/src/index-helpers/blocks-exports.ts +10 -0
- package/src/index-helpers/top-of-file.ts +4 -0
- package/src/index.ts +12 -0
- package/src/scripts/init-editing.ts +102 -0
- package/src/types/builder-block.ts +58 -0
- package/src/types/builder-content.ts +39 -0
- package/src/types/can-track.ts +3 -0
- package/src/types/components.ts +188 -0
- package/src/types/deep-partial.ts +7 -0
- package/src/types/element.ts +60 -0
- package/src/types/targets.ts +6 -0
- package/src/types/typescript.ts +7 -0
- package/package/blocks/button/button.lite.d.ts +0 -0
- package/package/blocks/columns/columns.lite.d.ts +0 -0
- package/package/blocks/custom-code/custom-code.lite.d.ts +0 -0
- package/package/blocks/embed/embed.lite.d.ts +0 -0
- package/package/blocks/form/form.lite.d.ts +0 -0
- package/package/blocks/fragment/fragment.lite.d.ts +0 -0
- package/package/blocks/image/image.lite.d.ts +0 -0
- package/package/blocks/img/img.lite.d.ts +0 -0
- package/package/blocks/input/input.lite.d.ts +0 -0
- package/package/blocks/raw-text/raw-text.lite.d.ts +0 -0
- package/package/blocks/section/section.lite.d.ts +0 -0
- package/package/blocks/select/select.lite.d.ts +0 -0
- package/package/blocks/submit-button/submit-button.lite.d.ts +0 -0
- package/package/blocks/symbol/symbol.lite.d.ts +0 -0
- package/package/blocks/text/text.lite.d.ts +0 -0
- package/package/blocks/textarea/textarea.lite.d.ts +0 -0
- package/package/blocks/video/video.lite.d.ts +0 -0
- package/package/components/render-block/block-styles.lite.d.ts +0 -0
- package/package/components/render-block/render-block.lite.d.ts +0 -0
- package/package/components/render-block/render-component.lite.d.ts +0 -0
- package/package/components/render-block/render-repeated-block.lite.d.ts +0 -0
- package/package/components/render-blocks.lite.d.ts +0 -0
- package/package/components/render-content/components/render-styles.lite.d.ts +0 -0
- package/package/components/render-content/render-content.lite.d.ts +0 -0
- package/package/components/render-inlined-styles.lite.d.ts +0 -0
- package/package/functions/convert-style-object.d.ts +0 -1
- package/package/functions/convert-style-object.js +0 -3
- package/package/functions/get-block-styles.d.ts +0 -2
- package/package/functions/get-block-styles.js +0 -21
- package/package/functions/sanitize-styles.d.ts +0 -4
- package/package/functions/sanitize-styles.js +0 -6
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { isBrowser } from '../functions/is-browser.js';
|
|
2
|
+
import type { CanTrack } from '../types/can-track.js';
|
|
3
|
+
import { getTopLevelDomain } from './url.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* NOTE: This function is `async` because its react-native override is async. Do not remove the `async` keyword!
|
|
7
|
+
*/
|
|
8
|
+
export const getCookie = async ({
|
|
9
|
+
name,
|
|
10
|
+
canTrack,
|
|
11
|
+
}: {
|
|
12
|
+
name: string;
|
|
13
|
+
} & CanTrack) => {
|
|
14
|
+
try {
|
|
15
|
+
if (!canTrack) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Extracted from MDN docs
|
|
21
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie#example_2_get_a_sample_cookie_named_test2
|
|
22
|
+
*/
|
|
23
|
+
return document.cookie
|
|
24
|
+
.split('; ')
|
|
25
|
+
.find((row) => row.startsWith(`${name}=`))
|
|
26
|
+
?.split('=')[1];
|
|
27
|
+
} catch (err) {
|
|
28
|
+
console.debug('[COOKIE] GET error: ', err);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
type CookieConfiguration = Array<
|
|
33
|
+
| ['expires', string]
|
|
34
|
+
| ['path', '/']
|
|
35
|
+
| ['domain', string]
|
|
36
|
+
| ['secure', '']
|
|
37
|
+
| ['SameSite', 'None']
|
|
38
|
+
| [string, string]
|
|
39
|
+
| []
|
|
40
|
+
>;
|
|
41
|
+
|
|
42
|
+
const stringifyCookie = (cookie: CookieConfiguration): string =>
|
|
43
|
+
cookie.map(([key, value]) => (value ? `${key}=${value}` : key)).join('; ');
|
|
44
|
+
|
|
45
|
+
const SECURE_CONFIG: CookieConfiguration = [
|
|
46
|
+
['secure', ''],
|
|
47
|
+
['SameSite', 'None'],
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
const createCookieString = ({
|
|
51
|
+
name,
|
|
52
|
+
value,
|
|
53
|
+
expires,
|
|
54
|
+
}: {
|
|
55
|
+
name: string;
|
|
56
|
+
value: string;
|
|
57
|
+
expires?: Date;
|
|
58
|
+
}) => {
|
|
59
|
+
const secure = isBrowser() ? location.protocol === 'https:' : true;
|
|
60
|
+
|
|
61
|
+
const secureObj: CookieConfiguration = secure ? SECURE_CONFIG : [[]];
|
|
62
|
+
|
|
63
|
+
// TODO: need to know if secure server side
|
|
64
|
+
const expiresObj: CookieConfiguration = expires
|
|
65
|
+
? [['expires', expires.toUTCString()]]
|
|
66
|
+
: [[]];
|
|
67
|
+
|
|
68
|
+
const cookieValue: CookieConfiguration = [
|
|
69
|
+
[name, value],
|
|
70
|
+
...expiresObj,
|
|
71
|
+
['path', '/'],
|
|
72
|
+
['domain', getTopLevelDomain(window.location.hostname)],
|
|
73
|
+
...secureObj,
|
|
74
|
+
];
|
|
75
|
+
const cookie = stringifyCookie(cookieValue);
|
|
76
|
+
|
|
77
|
+
return cookie;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* NOTE: This function is `async` because its react-native override is async. Do not remove the `async` keyword!
|
|
82
|
+
*/
|
|
83
|
+
export const setCookie = async ({
|
|
84
|
+
name,
|
|
85
|
+
value,
|
|
86
|
+
expires,
|
|
87
|
+
canTrack,
|
|
88
|
+
}: {
|
|
89
|
+
name: string;
|
|
90
|
+
value: string;
|
|
91
|
+
expires?: Date;
|
|
92
|
+
} & CanTrack) => {
|
|
93
|
+
try {
|
|
94
|
+
if (!canTrack) {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
const cookie = createCookieString({ name, value, expires });
|
|
98
|
+
document.cookie = cookie;
|
|
99
|
+
} catch (err) {
|
|
100
|
+
console.warn('[COOKIE] SET error: ', err);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { camelToKebabCase } from '../functions/camel-to-kebab-case.js';
|
|
2
|
+
|
|
3
|
+
const convertStyleMaptoCSS = (style: Partial<CSSStyleDeclaration>): string => {
|
|
4
|
+
const cssProps = Object.entries(style).map(([key, value]) => {
|
|
5
|
+
if (typeof value === 'string') {
|
|
6
|
+
return `${camelToKebabCase(key)}: ${value};`;
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
return cssProps.join('\n');
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const createCssClass = ({
|
|
14
|
+
mediaQuery,
|
|
15
|
+
className,
|
|
16
|
+
styles,
|
|
17
|
+
}: {
|
|
18
|
+
mediaQuery?: string;
|
|
19
|
+
className: string;
|
|
20
|
+
styles: Partial<CSSStyleDeclaration>;
|
|
21
|
+
}) => {
|
|
22
|
+
const cssClass = `.${className} {
|
|
23
|
+
${convertStyleMaptoCSS(styles)}
|
|
24
|
+
}`;
|
|
25
|
+
|
|
26
|
+
if (mediaQuery) {
|
|
27
|
+
return `${mediaQuery} {
|
|
28
|
+
${cssClass}
|
|
29
|
+
}`;
|
|
30
|
+
} else {
|
|
31
|
+
return cssClass;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert deep object to a flat object with dots
|
|
3
|
+
*
|
|
4
|
+
* { foo: { bar: 'baz' }} -> { 'foo.bar': 'baz' }
|
|
5
|
+
*/
|
|
6
|
+
export function flatten<T extends Record<string, any>>(
|
|
7
|
+
object: T,
|
|
8
|
+
path: string | null = null,
|
|
9
|
+
separator = '.'
|
|
10
|
+
): T {
|
|
11
|
+
return Object.keys(object).reduce((acc: T, key: string): T => {
|
|
12
|
+
const value = object[key];
|
|
13
|
+
const newPath = [path, key].filter(Boolean).join(separator);
|
|
14
|
+
const isObject = [
|
|
15
|
+
typeof value === 'object',
|
|
16
|
+
value !== null,
|
|
17
|
+
!(Array.isArray(value) && value.length === 0),
|
|
18
|
+
].every(Boolean);
|
|
19
|
+
|
|
20
|
+
return isObject
|
|
21
|
+
? { ...acc, ...flatten(value, newPath, separator) }
|
|
22
|
+
: { ...acc, [newPath]: value };
|
|
23
|
+
}, {} as T);
|
|
24
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isBrowser } from '../functions/is-browser.js';
|
|
2
|
+
import type { CanTrack } from '../types/can-track.js';
|
|
3
|
+
|
|
4
|
+
const getLocalStorage = () =>
|
|
5
|
+
isBrowser() && typeof localStorage !== 'undefined' ? localStorage : undefined;
|
|
6
|
+
|
|
7
|
+
export const getLocalStorageItem = ({
|
|
8
|
+
key,
|
|
9
|
+
canTrack,
|
|
10
|
+
}: {
|
|
11
|
+
key: string;
|
|
12
|
+
} & CanTrack) => {
|
|
13
|
+
try {
|
|
14
|
+
if (canTrack) {
|
|
15
|
+
return getLocalStorage()?.getItem(key);
|
|
16
|
+
}
|
|
17
|
+
return undefined;
|
|
18
|
+
} catch (err) {
|
|
19
|
+
console.debug('[LocalStorage] GET error: ', err);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const setLocalStorageItem = ({
|
|
24
|
+
key,
|
|
25
|
+
canTrack,
|
|
26
|
+
value,
|
|
27
|
+
}: {
|
|
28
|
+
key: string;
|
|
29
|
+
value: string;
|
|
30
|
+
} & CanTrack) => {
|
|
31
|
+
try {
|
|
32
|
+
if (canTrack) {
|
|
33
|
+
getLocalStorage()?.setItem(key, value);
|
|
34
|
+
}
|
|
35
|
+
} catch (err) {
|
|
36
|
+
console.debug('[LocalStorage] SET error: ', err);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { CanTrack } from '../types/can-track.js';
|
|
2
|
+
import { getCookie, setCookie } from './cookie.js';
|
|
3
|
+
import { checkIsDefined } from './nullable.js';
|
|
4
|
+
import { uuid } from './uuid.js';
|
|
5
|
+
|
|
6
|
+
const SESSION_LOCAL_STORAGE_KEY = 'builderSessionId';
|
|
7
|
+
|
|
8
|
+
export const getSessionId = async ({ canTrack }: CanTrack) => {
|
|
9
|
+
if (!canTrack) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const sessionId = await getCookie({
|
|
14
|
+
name: SESSION_LOCAL_STORAGE_KEY,
|
|
15
|
+
canTrack,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
if (checkIsDefined(sessionId)) {
|
|
19
|
+
return sessionId;
|
|
20
|
+
} else {
|
|
21
|
+
const newSessionId = createSessionId();
|
|
22
|
+
setSessionId({ id: newSessionId, canTrack });
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const createSessionId = () => uuid();
|
|
27
|
+
|
|
28
|
+
export const setSessionId = ({
|
|
29
|
+
id,
|
|
30
|
+
canTrack,
|
|
31
|
+
}: {
|
|
32
|
+
id: string;
|
|
33
|
+
} & CanTrack) =>
|
|
34
|
+
setCookie({ name: SESSION_LOCAL_STORAGE_KEY, value: id, canTrack });
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getTopLevelDomain } from './url.js';
|
|
2
|
+
|
|
3
|
+
describe('getTopLevelDomain', () => {
|
|
4
|
+
test('handles root domain', () => {
|
|
5
|
+
const output = getTopLevelDomain('example.com');
|
|
6
|
+
expect(output).toBe('example.com');
|
|
7
|
+
});
|
|
8
|
+
test('handles subdomain', () => {
|
|
9
|
+
const output = getTopLevelDomain('wwww.example.com');
|
|
10
|
+
expect(output).toBe('example.com');
|
|
11
|
+
});
|
|
12
|
+
test('handles subdomain with long suffix', () => {
|
|
13
|
+
const output = getTopLevelDomain('www.example.co.uk');
|
|
14
|
+
expect(output).toBe('example.co.uk');
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
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: string) => {
|
|
7
|
+
const parts = host.split('.');
|
|
8
|
+
if (parts.length > 2) {
|
|
9
|
+
return parts.slice(1).join('.');
|
|
10
|
+
}
|
|
11
|
+
return host;
|
|
12
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
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,
|
|
7
|
+
v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
8
|
+
return v.toString(16);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Slightly cleaner and smaller UUIDs
|
|
14
|
+
*/
|
|
15
|
+
export function uuid() {
|
|
16
|
+
return uuidv4().replace(/-/g, '');
|
|
17
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { CanTrack } from '../types/can-track.js';
|
|
2
|
+
import { getLocalStorageItem, setLocalStorageItem } from './localStorage.js';
|
|
3
|
+
import { checkIsDefined } from './nullable.js';
|
|
4
|
+
import { uuid } from './uuid.js';
|
|
5
|
+
|
|
6
|
+
const VISITOR_LOCAL_STORAGE_KEY = 'builderVisitorId';
|
|
7
|
+
|
|
8
|
+
export const getVisitorId = ({ canTrack }: CanTrack) => {
|
|
9
|
+
if (!canTrack) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const visitorId = getLocalStorageItem({
|
|
14
|
+
key: VISITOR_LOCAL_STORAGE_KEY,
|
|
15
|
+
canTrack,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
if (checkIsDefined(visitorId)) {
|
|
19
|
+
return visitorId;
|
|
20
|
+
} else {
|
|
21
|
+
const newVisitorId = createVisitorId();
|
|
22
|
+
setVisitorId({ id: newVisitorId, canTrack });
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const createVisitorId = () => uuid();
|
|
27
|
+
|
|
28
|
+
export const setVisitorId = ({
|
|
29
|
+
id,
|
|
30
|
+
canTrack,
|
|
31
|
+
}: {
|
|
32
|
+
id: string;
|
|
33
|
+
} & CanTrack) =>
|
|
34
|
+
setLocalStorageItem({
|
|
35
|
+
key: VISITOR_LOCAL_STORAGE_KEY,
|
|
36
|
+
value: id,
|
|
37
|
+
canTrack,
|
|
38
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { default as Columns } from '../blocks/columns/columns.svelte';
|
|
2
|
+
export { default as Image } from '../blocks/image/image.svelte';
|
|
3
|
+
export { default as Text } from '../blocks/text/text.svelte';
|
|
4
|
+
export { default as Video } from '../blocks/video/video.svelte';
|
|
5
|
+
export { default as Symbol } from '../blocks/symbol/symbol.svelte';
|
|
6
|
+
export { default as Button } from '../blocks/button/button.svelte';
|
|
7
|
+
export { default as Section } from '../blocks/section/section.svelte';
|
|
8
|
+
export { default as Fragment } from '../blocks/fragment/fragment.svelte';
|
|
9
|
+
export { default as RenderContent } from '../components/render-content/render-content.svelte';
|
|
10
|
+
export { default as RenderBlocks } from '../components/render-blocks.svelte';
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import './index-helpers/top-of-file.js';
|
|
2
|
+
import './scripts/init-editing.js';
|
|
3
|
+
|
|
4
|
+
export * from './index-helpers/blocks-exports.js';
|
|
5
|
+
|
|
6
|
+
export * from './functions/is-editing.js';
|
|
7
|
+
export * from './functions/is-previewing.js';
|
|
8
|
+
export * from './functions/register-component.js';
|
|
9
|
+
export * from './functions/register.js';
|
|
10
|
+
export * from './functions/set-editor-settings.js';
|
|
11
|
+
export * from './functions/get-content/index.js';
|
|
12
|
+
export * from './functions/get-builder-search-params/index.js';
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { TARGET } from '../constants/target.js';
|
|
2
|
+
import { isBrowser } from '../functions/is-browser.js';
|
|
3
|
+
import { register } from '../functions/register.js';
|
|
4
|
+
|
|
5
|
+
export const registerInsertMenu = () => {
|
|
6
|
+
register('insertMenu', {
|
|
7
|
+
name: '_default',
|
|
8
|
+
default: true,
|
|
9
|
+
items: [
|
|
10
|
+
{ name: 'Box' },
|
|
11
|
+
{ name: 'Text' },
|
|
12
|
+
{ name: 'Image' },
|
|
13
|
+
{ name: 'Columns' },
|
|
14
|
+
...(TARGET === 'reactNative'
|
|
15
|
+
? []
|
|
16
|
+
: [
|
|
17
|
+
{ name: 'Core:Section' },
|
|
18
|
+
{ name: 'Core:Button' },
|
|
19
|
+
{ name: 'Embed' },
|
|
20
|
+
{ name: 'Custom Code' },
|
|
21
|
+
]),
|
|
22
|
+
],
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const setupBrowserForEditing = () => {
|
|
27
|
+
if (isBrowser()) {
|
|
28
|
+
window.parent?.postMessage(
|
|
29
|
+
{
|
|
30
|
+
type: 'builder.sdkInfo',
|
|
31
|
+
data: {
|
|
32
|
+
target: TARGET,
|
|
33
|
+
// TODO: compile these in
|
|
34
|
+
// type: process.env.SDK_TYPE,
|
|
35
|
+
// version: process.env.SDK_VERSION,
|
|
36
|
+
supportsPatchUpdates: false,
|
|
37
|
+
// Supports builder-model="..." attribute which is needed to
|
|
38
|
+
// scope our '+ add block' button styling
|
|
39
|
+
supportsAddBlockScoping: true,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
'*'
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
window.addEventListener('message', ({ data }) => {
|
|
46
|
+
if (!data?.type) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
switch (data.type) {
|
|
51
|
+
case 'builder.evaluate': {
|
|
52
|
+
const text = data.data.text;
|
|
53
|
+
const args = data.data.arguments || [];
|
|
54
|
+
const id = data.data.id;
|
|
55
|
+
// tslint:disable-next-line:no-function-constructor-with-string-args
|
|
56
|
+
const fn = new Function(text);
|
|
57
|
+
let result: any;
|
|
58
|
+
let error: Error | null = null;
|
|
59
|
+
try {
|
|
60
|
+
// eslint-disable-next-line prefer-spread
|
|
61
|
+
result = fn.apply(null, args);
|
|
62
|
+
} catch (err) {
|
|
63
|
+
error = err as Error;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (error) {
|
|
67
|
+
window.parent?.postMessage(
|
|
68
|
+
{
|
|
69
|
+
type: 'builder.evaluateError',
|
|
70
|
+
data: { id, error: error.message },
|
|
71
|
+
},
|
|
72
|
+
'*'
|
|
73
|
+
);
|
|
74
|
+
} else {
|
|
75
|
+
if (result && typeof result.then === 'function') {
|
|
76
|
+
(result as Promise<any>)
|
|
77
|
+
.then((finalResult) => {
|
|
78
|
+
window.parent?.postMessage(
|
|
79
|
+
{
|
|
80
|
+
type: 'builder.evaluateResult',
|
|
81
|
+
data: { id, result: finalResult },
|
|
82
|
+
},
|
|
83
|
+
'*'
|
|
84
|
+
);
|
|
85
|
+
})
|
|
86
|
+
.catch(console.error);
|
|
87
|
+
} else {
|
|
88
|
+
window.parent?.postMessage(
|
|
89
|
+
{
|
|
90
|
+
type: 'builder.evaluateResult',
|
|
91
|
+
data: { result, id },
|
|
92
|
+
},
|
|
93
|
+
'*'
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
type JSONValue = string | number | boolean | JSONObject | JSONArray;
|
|
2
|
+
|
|
3
|
+
interface JSONObject {
|
|
4
|
+
[x: string]: JSONValue;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface JSONArray extends Array<JSONValue> {}
|
|
8
|
+
|
|
9
|
+
/** @todo typedoc this */
|
|
10
|
+
export interface BuilderBlock {
|
|
11
|
+
'@type': '@builder.io/sdk:Element';
|
|
12
|
+
'@version'?: number;
|
|
13
|
+
id?: string;
|
|
14
|
+
tagName?: string;
|
|
15
|
+
layerName?: string;
|
|
16
|
+
groupLocked?: boolean;
|
|
17
|
+
layerLocked?: boolean;
|
|
18
|
+
/** @todo make alias for properties.class */
|
|
19
|
+
class?: string;
|
|
20
|
+
children?: BuilderBlock[];
|
|
21
|
+
responsiveStyles?: {
|
|
22
|
+
large?: Partial<CSSStyleDeclaration>;
|
|
23
|
+
medium?: Partial<CSSStyleDeclaration>;
|
|
24
|
+
small?: Partial<CSSStyleDeclaration>;
|
|
25
|
+
/** @deprecated */
|
|
26
|
+
xsmall?: Partial<CSSStyleDeclaration>;
|
|
27
|
+
};
|
|
28
|
+
component?: {
|
|
29
|
+
name: string;
|
|
30
|
+
options?: any;
|
|
31
|
+
tag?: string;
|
|
32
|
+
};
|
|
33
|
+
bindings?: {
|
|
34
|
+
[key: string]: string;
|
|
35
|
+
};
|
|
36
|
+
meta?: {
|
|
37
|
+
[key: string]: JSONValue;
|
|
38
|
+
};
|
|
39
|
+
actions?: {
|
|
40
|
+
[key: string]: string;
|
|
41
|
+
};
|
|
42
|
+
properties?: {
|
|
43
|
+
[key: string]: string;
|
|
44
|
+
};
|
|
45
|
+
code?: {
|
|
46
|
+
bindings?: {
|
|
47
|
+
[key: string]: string;
|
|
48
|
+
};
|
|
49
|
+
actions?: {
|
|
50
|
+
[key: string]: string;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
repeat?: {
|
|
54
|
+
collection: string;
|
|
55
|
+
itemName?: string;
|
|
56
|
+
} | null;
|
|
57
|
+
animations?: any[]; // TODO: type the animation spec
|
|
58
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { BuilderBlock } from './builder-block.js';
|
|
2
|
+
|
|
3
|
+
// TODO
|
|
4
|
+
type Input = any;
|
|
5
|
+
|
|
6
|
+
export interface BuilderContentVariation {
|
|
7
|
+
data?: {
|
|
8
|
+
title?: string;
|
|
9
|
+
blocks?: BuilderBlock[];
|
|
10
|
+
inputs?: Input[];
|
|
11
|
+
state?: { [key: string]: any };
|
|
12
|
+
jsCode?: string;
|
|
13
|
+
tsCode?: string;
|
|
14
|
+
httpRequests?: { [key: string]: string };
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
};
|
|
17
|
+
name?: string;
|
|
18
|
+
testRatio?: number;
|
|
19
|
+
id?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// TODO: separate full and partial versions
|
|
23
|
+
export interface BuilderContent extends BuilderContentVariation {
|
|
24
|
+
// TODO: query
|
|
25
|
+
'@version'?: number;
|
|
26
|
+
id?: string;
|
|
27
|
+
name?: string;
|
|
28
|
+
published?: 'published' | 'draft' | 'archived';
|
|
29
|
+
modelId?: string;
|
|
30
|
+
priority?: number;
|
|
31
|
+
lastUpdated?: number;
|
|
32
|
+
startDate?: number;
|
|
33
|
+
endDate?: number;
|
|
34
|
+
variations?: {
|
|
35
|
+
[id: string]: BuilderContentVariation | undefined;
|
|
36
|
+
};
|
|
37
|
+
testVariationId?: string;
|
|
38
|
+
testVariationName?: string;
|
|
39
|
+
}
|