@builder.io/sdk-svelte 0.2.3 → 0.4.0
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 +10 -5
- package/package/CHANGELOG.md +17 -0
- package/package/blocks/columns/columns.svelte +1 -1
- package/package/blocks/symbol/symbol.svelte +1 -1
- package/package/components/render-block/block-styles.svelte +3 -1
- package/package/components/render-block/render-block.helpers.d.ts +0 -1
- package/package/components/render-block/render-block.helpers.js +8 -20
- package/package/components/render-block/render-block.svelte +25 -19
- package/package/components/render-block/render-repeated-block.svelte +3 -2
- package/package/components/render-content/components/render-styles.svelte +1 -1
- package/package/components/render-content/render-content.svelte +99 -10
- package/package/components/render-content/render-content.svelte.d.ts +5 -0
- package/package/components/render-content/render-content.types.d.ts +11 -2
- package/package/components/render-content/wrap-component-ref.d.ts +6 -0
- package/package/components/render-content/wrap-component-ref.js +6 -0
- package/package/components/render-content-variants/helpers.d.ts +17 -0
- package/package/components/render-content-variants/helpers.js +182 -0
- package/package/components/render-content-variants/render-content-variants.svelte +70 -0
- package/package/components/render-content-variants/render-content-variants.svelte.d.ts +23 -0
- package/package/components/render-inlined-styles.svelte +3 -15
- package/package/components/render-inlined-styles.svelte.d.ts +2 -0
- package/package/constants/sdk-version.d.ts +1 -0
- package/package/constants/sdk-version.js +1 -0
- package/package/context/builder.context.d.ts +3 -2
- package/package/context/builder.context.js +3 -2
- package/package/context/types.d.ts +17 -2
- package/package/functions/evaluate.d.ts +4 -3
- package/package/functions/evaluate.js +23 -2
- package/package/functions/evaluate.test.d.ts +1 -0
- package/package/functions/evaluate.test.js +17 -0
- package/package/functions/get-block-actions-handler.d.ts +1 -1
- package/package/functions/get-block-actions-handler.js +3 -1
- package/package/functions/get-block-actions.d.ts +1 -1
- package/package/functions/get-content/generate-content-url.js +2 -2
- package/package/functions/get-content/generate-content-url.test.js +15 -0
- package/package/functions/get-content/index.d.ts +7 -2
- package/package/functions/get-content/index.js +43 -20
- package/package/functions/get-content/types.d.ts +6 -0
- package/package/functions/get-processed-block.d.ts +2 -2
- package/package/functions/get-processed-block.js +16 -4
- package/package/functions/get-processed-block.test.js +3 -1
- package/package/helpers/ab-tests.d.ts +8 -7
- package/package/helpers/ab-tests.js +103 -4
- package/package/helpers/canTrack.d.ts +1 -0
- package/package/helpers/canTrack.js +2 -0
- package/package/helpers/cookie.d.ts +7 -3
- package/package/helpers/cookie.js +9 -6
- package/package/helpers/logger.d.ts +1 -0
- package/package/helpers/logger.js +1 -0
- package/package/index-helpers/blocks-exports.d.ts +1 -1
- package/package/index-helpers/blocks-exports.js +1 -1
- package/package/index.d.ts +8 -7
- package/package/index.js +6 -7
- package/package/scripts/init-editing.d.ts +1 -0
- package/package/scripts/init-editing.js +2 -0
- package/package/types/builder-content.d.ts +1 -3
- package/package.json +4 -8
- package/src/blocks/columns/columns.svelte +1 -5
- package/src/blocks/symbol/symbol.svelte +1 -1
- package/src/components/render-block/block-styles.svelte +3 -1
- package/src/components/render-block/render-block.helpers.ts +9 -31
- package/src/components/render-block/render-block.svelte +24 -19
- package/src/components/render-block/render-repeated-block.svelte +3 -2
- package/src/components/render-content/components/render-styles.svelte +1 -1
- package/src/components/render-content/render-content.svelte +101 -10
- package/src/components/render-content/render-content.types.ts +11 -2
- package/src/components/render-content/wrap-component-ref.ts +6 -0
- package/src/components/render-content-variants/helpers.ts +245 -0
- package/src/components/render-content-variants/render-content-variants.svelte +83 -0
- package/src/components/render-inlined-styles.svelte +3 -16
- package/src/constants/sdk-version.ts +1 -0
- package/src/context/builder.context.ts +3 -2
- package/src/context/types.ts +17 -2
- package/src/functions/evaluate.test.ts +21 -0
- package/src/functions/evaluate.ts +46 -4
- package/src/functions/get-block-actions-handler.ts +7 -2
- package/src/functions/get-block-actions.ts +4 -1
- package/src/functions/get-content/generate-content-url.test.ts +17 -0
- package/src/functions/get-content/generate-content-url.ts +2 -1
- package/src/functions/get-content/index.ts +57 -26
- package/src/functions/get-content/types.ts +7 -0
- package/src/functions/get-processed-block.test.ts +3 -1
- package/src/functions/get-processed-block.ts +28 -6
- package/src/helpers/ab-tests.ts +164 -11
- package/src/helpers/canTrack.ts +4 -0
- package/src/helpers/cookie.ts +16 -11
- package/src/helpers/logger.ts +1 -0
- package/src/index-helpers/blocks-exports.ts +1 -1
- package/src/index.ts +17 -8
- package/src/scripts/init-editing.ts +3 -0
- package/src/types/builder-content.ts +1 -3
- package/package/functions/get-content/ab-testing.d.ts +0 -5
- package/package/functions/get-content/ab-testing.js +0 -78
- package/src/functions/get-content/ab-testing.ts +0 -132
|
@@ -2,7 +2,7 @@ import { evaluate } from './evaluate.js';
|
|
|
2
2
|
import { fastClone } from './fast-clone.js';
|
|
3
3
|
import { set } from './set.js';
|
|
4
4
|
import { transformBlock } from './transform-block.js';
|
|
5
|
-
const evaluateBindings = ({ block, context,
|
|
5
|
+
const evaluateBindings = ({ block, context, localState, rootState, rootSetState, }) => {
|
|
6
6
|
if (!block.bindings) {
|
|
7
7
|
return block;
|
|
8
8
|
}
|
|
@@ -14,15 +14,27 @@ const evaluateBindings = ({ block, context, state, }) => {
|
|
|
14
14
|
};
|
|
15
15
|
for (const binding in block.bindings) {
|
|
16
16
|
const expression = block.bindings[binding];
|
|
17
|
-
const value = evaluate({
|
|
17
|
+
const value = evaluate({
|
|
18
|
+
code: expression,
|
|
19
|
+
localState,
|
|
20
|
+
rootState,
|
|
21
|
+
rootSetState,
|
|
22
|
+
context,
|
|
23
|
+
});
|
|
18
24
|
set(copied, binding, value);
|
|
19
25
|
}
|
|
20
26
|
return copied;
|
|
21
27
|
};
|
|
22
|
-
export function getProcessedBlock({ block, context, shouldEvaluateBindings,
|
|
28
|
+
export function getProcessedBlock({ block, context, shouldEvaluateBindings, localState, rootState, rootSetState, }) {
|
|
23
29
|
const transformedBlock = transformBlock(block);
|
|
24
30
|
if (shouldEvaluateBindings) {
|
|
25
|
-
return evaluateBindings({
|
|
31
|
+
return evaluateBindings({
|
|
32
|
+
block: transformedBlock,
|
|
33
|
+
localState,
|
|
34
|
+
rootState,
|
|
35
|
+
rootSetState,
|
|
36
|
+
context,
|
|
37
|
+
});
|
|
26
38
|
}
|
|
27
39
|
else {
|
|
28
40
|
return transformedBlock;
|
|
@@ -19,7 +19,9 @@ test('Can process bindings', () => {
|
|
|
19
19
|
const processed = getProcessedBlock({
|
|
20
20
|
block,
|
|
21
21
|
context: {},
|
|
22
|
-
|
|
22
|
+
rootState: { test: 'hello' },
|
|
23
|
+
rootSetState: undefined,
|
|
24
|
+
localState: undefined,
|
|
23
25
|
shouldEvaluateBindings: true,
|
|
24
26
|
});
|
|
25
27
|
expect(processed).not.toEqual(block);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { CanTrack } from '../types/can-track.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import type { BuilderContent } from '../types/builder-content.js';
|
|
3
|
+
import type { Nullable } from '../types/typescript.js';
|
|
4
|
+
export declare const handleABTestingSync: ({ item, canTrack, }: {
|
|
5
|
+
item: Nullable<BuilderContent>;
|
|
6
|
+
} & CanTrack) => Nullable<BuilderContent>;
|
|
7
|
+
export declare const handleABTesting: ({ item, canTrack, }: {
|
|
8
|
+
item: BuilderContent;
|
|
9
|
+
} & CanTrack) => Promise<BuilderContent>;
|
|
@@ -1,5 +1,104 @@
|
|
|
1
|
-
import { getCookie, setCookie } from './cookie.js';
|
|
2
|
-
|
|
1
|
+
import { getCookie, getCookieSync, setCookie } from './cookie.js';
|
|
2
|
+
import { checkIsDefined } from '../helpers/nullable.js';
|
|
3
|
+
import { logger } from './logger.js';
|
|
4
|
+
const BUILDER_STORE_PREFIX = 'builder.tests';
|
|
3
5
|
const getContentTestKey = (id) => `${BUILDER_STORE_PREFIX}.${id}`;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
const getContentVariationCookie = ({ contentId }) => getCookie({ name: getContentTestKey(contentId), canTrack: true });
|
|
7
|
+
const getContentVariationCookieSync = ({ contentId }) => getCookieSync({ name: getContentTestKey(contentId), canTrack: true });
|
|
8
|
+
const setContentVariationCookie = ({ contentId, value, }) => setCookie({ name: getContentTestKey(contentId), value, canTrack: true });
|
|
9
|
+
const checkIsBuilderContentWithVariations = (item) => checkIsDefined(item.id) &&
|
|
10
|
+
checkIsDefined(item.variations) &&
|
|
11
|
+
Object.keys(item.variations).length > 0;
|
|
12
|
+
/**
|
|
13
|
+
* Randomly assign a variation to a user
|
|
14
|
+
*/
|
|
15
|
+
const getRandomVariationId = ({ id, variations, }) => {
|
|
16
|
+
let n = 0;
|
|
17
|
+
const random = Math.random();
|
|
18
|
+
// loop over variations test ratios, incrementing a counter,
|
|
19
|
+
// until we find the variation that this user should be assigned to
|
|
20
|
+
for (const id in variations) {
|
|
21
|
+
const testRatio = variations[id]?.testRatio;
|
|
22
|
+
n += testRatio;
|
|
23
|
+
if (random < n) {
|
|
24
|
+
return id;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// the variations array does not include the default variation.
|
|
28
|
+
// if we arrive here, then it means that the random number fits in the default variation bucket.
|
|
29
|
+
return id;
|
|
30
|
+
};
|
|
31
|
+
const getAndSetVariantId = (args) => {
|
|
32
|
+
// if variation not found in storage, assign a random variation to this user
|
|
33
|
+
const randomVariationId = getRandomVariationId(args);
|
|
34
|
+
// store variation in cookies/storage
|
|
35
|
+
setContentVariationCookie({
|
|
36
|
+
contentId: args.id,
|
|
37
|
+
value: randomVariationId,
|
|
38
|
+
}).catch((err) => {
|
|
39
|
+
logger.error('could not store A/B test variation: ', err);
|
|
40
|
+
});
|
|
41
|
+
return randomVariationId;
|
|
42
|
+
};
|
|
43
|
+
const getTestFields = ({ item, testGroupId, }) => {
|
|
44
|
+
const variationValue = item.variations[testGroupId];
|
|
45
|
+
if (testGroupId === item.id ||
|
|
46
|
+
// handle edge-case where `testGroupId` points to non-existing variation
|
|
47
|
+
!variationValue) {
|
|
48
|
+
return {
|
|
49
|
+
testVariationId: item.id,
|
|
50
|
+
testVariationName: 'Default',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return {
|
|
55
|
+
data: variationValue.data,
|
|
56
|
+
testVariationId: variationValue.id,
|
|
57
|
+
testVariationName: variationValue.name || (variationValue.id === item.id ? 'Default' : ''),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
export const handleABTestingSync = ({ item, canTrack, }) => {
|
|
62
|
+
if (!canTrack) {
|
|
63
|
+
return item;
|
|
64
|
+
}
|
|
65
|
+
if (!item) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
if (!checkIsBuilderContentWithVariations(item)) {
|
|
69
|
+
return item;
|
|
70
|
+
}
|
|
71
|
+
const testGroupId = getContentVariationCookieSync({
|
|
72
|
+
contentId: item.id,
|
|
73
|
+
}) ||
|
|
74
|
+
getAndSetVariantId({
|
|
75
|
+
variations: item.variations,
|
|
76
|
+
id: item.id,
|
|
77
|
+
});
|
|
78
|
+
const variationValue = getTestFields({ item, testGroupId });
|
|
79
|
+
return {
|
|
80
|
+
...item,
|
|
81
|
+
...variationValue,
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
export const handleABTesting = async ({ item, canTrack, }) => {
|
|
85
|
+
if (!canTrack) {
|
|
86
|
+
return item;
|
|
87
|
+
}
|
|
88
|
+
if (!checkIsBuilderContentWithVariations(item)) {
|
|
89
|
+
return item;
|
|
90
|
+
}
|
|
91
|
+
const cookieValue = await getContentVariationCookie({
|
|
92
|
+
contentId: item.id,
|
|
93
|
+
});
|
|
94
|
+
const testGroupId = cookieValue ||
|
|
95
|
+
getAndSetVariantId({
|
|
96
|
+
variations: item.variations,
|
|
97
|
+
id: item.id,
|
|
98
|
+
});
|
|
99
|
+
const variationValue = getTestFields({ item, testGroupId });
|
|
100
|
+
return {
|
|
101
|
+
...item,
|
|
102
|
+
...variationValue,
|
|
103
|
+
};
|
|
104
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getDefaultCanTrack: (canTrack?: boolean) => boolean;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { CanTrack } from '../types/can-track.js';
|
|
2
|
+
type GetCookieArgs = {
|
|
3
|
+
name: string;
|
|
4
|
+
} & CanTrack;
|
|
5
|
+
export declare const getCookieSync: ({ name, canTrack, }: GetCookieArgs) => string | undefined;
|
|
2
6
|
/**
|
|
3
7
|
* NOTE: This function is `async` because its react-native override is async. Do not remove the `async` keyword!
|
|
8
|
+
* The sync version is only safe to use in code blocks that `react-native` is guaranteed not to not run.
|
|
4
9
|
*/
|
|
5
|
-
export declare const getCookie: (
|
|
6
|
-
name: string;
|
|
7
|
-
} & CanTrack) => Promise<string | undefined>;
|
|
10
|
+
export declare const getCookie: (args: GetCookieArgs) => Promise<string | undefined>;
|
|
8
11
|
/**
|
|
9
12
|
* NOTE: This function is `async` because its react-native override is async. Do not remove the `async` keyword!
|
|
10
13
|
*/
|
|
@@ -13,3 +16,4 @@ export declare const setCookie: ({ name, value, expires, canTrack, }: {
|
|
|
13
16
|
value: string;
|
|
14
17
|
expires?: Date | undefined;
|
|
15
18
|
} & CanTrack) => Promise<void>;
|
|
19
|
+
export {};
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { isBrowser } from '../functions/is-browser.js';
|
|
2
|
+
import { logger } from './logger.js';
|
|
2
3
|
import { checkIsDefined } from './nullable.js';
|
|
3
4
|
import { getTopLevelDomain } from './url.js';
|
|
4
|
-
|
|
5
|
-
* NOTE: This function is `async` because its react-native override is async. Do not remove the `async` keyword!
|
|
6
|
-
*/
|
|
7
|
-
export const getCookie = async ({ name, canTrack, }) => {
|
|
5
|
+
export const getCookieSync = ({ name, canTrack, }) => {
|
|
8
6
|
try {
|
|
9
7
|
if (!canTrack) {
|
|
10
8
|
return undefined;
|
|
@@ -19,10 +17,15 @@ export const getCookie = async ({ name, canTrack, }) => {
|
|
|
19
17
|
?.split('=')[1];
|
|
20
18
|
}
|
|
21
19
|
catch (err) {
|
|
22
|
-
|
|
20
|
+
logger.warn('[COOKIE] GET error: ', err?.message || err);
|
|
23
21
|
return undefined;
|
|
24
22
|
}
|
|
25
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* NOTE: This function is `async` because its react-native override is async. Do not remove the `async` keyword!
|
|
26
|
+
* The sync version is only safe to use in code blocks that `react-native` is guaranteed not to not run.
|
|
27
|
+
*/
|
|
28
|
+
export const getCookie = async (args) => getCookieSync(args);
|
|
26
29
|
const stringifyCookie = (cookie) => cookie
|
|
27
30
|
.map(([key, value]) => (value ? `${key}=${value}` : key))
|
|
28
31
|
.filter(checkIsDefined)
|
|
@@ -60,6 +63,6 @@ export const setCookie = async ({ name, value, expires, canTrack, }) => {
|
|
|
60
63
|
document.cookie = cookie;
|
|
61
64
|
}
|
|
62
65
|
catch (err) {
|
|
63
|
-
|
|
66
|
+
logger.warn('[COOKIE] SET error: ', err?.message || err);
|
|
64
67
|
}
|
|
65
68
|
};
|
|
@@ -3,4 +3,5 @@ export const logger = {
|
|
|
3
3
|
log: (...message) => console.log(MSG_PREFIX, ...message),
|
|
4
4
|
error: (...message) => console.error(MSG_PREFIX, ...message),
|
|
5
5
|
warn: (...message) => console.warn(MSG_PREFIX, ...message),
|
|
6
|
+
debug: (...message) => console.debug(MSG_PREFIX, ...message),
|
|
6
7
|
};
|
|
@@ -3,8 +3,8 @@ export { default as Columns } from '../blocks/columns/columns.svelte';
|
|
|
3
3
|
export { default as Fragment } from '../blocks/fragment/fragment.svelte';
|
|
4
4
|
export { default as Image } from '../blocks/image/image.svelte';
|
|
5
5
|
export { default as RenderBlocks } from '../components/render-blocks.svelte';
|
|
6
|
-
export { default as RenderContent } from '../components/render-content/render-content.svelte';
|
|
7
6
|
export { default as Section } from '../blocks/section/section.svelte';
|
|
8
7
|
export { default as Symbol } from '../blocks/symbol/symbol.svelte';
|
|
9
8
|
export { default as Text } from '../blocks/text/text.svelte';
|
|
10
9
|
export { default as Video } from '../blocks/video/video.svelte';
|
|
10
|
+
export { default as RenderContent } from '../components/render-content-variants/render-content-variants.svelte';
|
|
@@ -3,8 +3,8 @@ export { default as Columns } from '../blocks/columns/columns.svelte';
|
|
|
3
3
|
export { default as Fragment } from '../blocks/fragment/fragment.svelte';
|
|
4
4
|
export { default as Image } from '../blocks/image/image.svelte';
|
|
5
5
|
export { default as RenderBlocks } from '../components/render-blocks.svelte';
|
|
6
|
-
export { default as RenderContent } from '../components/render-content/render-content.svelte';
|
|
7
6
|
export { default as Section } from '../blocks/section/section.svelte';
|
|
8
7
|
export { default as Symbol } from '../blocks/symbol/symbol.svelte';
|
|
9
8
|
export { default as Text } from '../blocks/text/text.svelte';
|
|
10
9
|
export { default as Video } from '../blocks/video/video.svelte';
|
|
10
|
+
export { default as RenderContent } from '../components/render-content-variants/render-content-variants.svelte';
|
package/package/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
export * from './index-helpers/top-of-file.js';
|
|
2
2
|
export * from './index-helpers/blocks-exports.js';
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
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';
|
|
10
11
|
export { track } from './functions/track/index.js';
|
|
11
12
|
export type { RegisteredComponent } from './context/types';
|
|
12
13
|
export type { ComponentInfo } from './types/components';
|
package/package/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
export * from './index-helpers/top-of-file.js';
|
|
2
2
|
export * from './index-helpers/blocks-exports.js';
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export * from './functions/get-builder-search-params/index.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';
|
|
10
9
|
export { track } from './functions/track/index.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SDK_VERSION } from '../constants/sdk-version.js';
|
|
1
2
|
import { TARGET } from '../constants/target.js';
|
|
2
3
|
import { isBrowser } from '../functions/is-browser.js';
|
|
3
4
|
import { register } from '../functions/register.js';
|
|
@@ -32,6 +33,7 @@ export const setupBrowserForEditing = (options = {}) => {
|
|
|
32
33
|
type: 'builder.sdkInfo',
|
|
33
34
|
data: {
|
|
34
35
|
target: TARGET,
|
|
36
|
+
version: SDK_VERSION,
|
|
35
37
|
// TODO: compile these in
|
|
36
38
|
// type: process.env.SDK_TYPE,
|
|
37
39
|
// version: process.env.SDK_VERSION,
|
|
@@ -30,8 +30,6 @@ export interface BuilderContentVariation {
|
|
|
30
30
|
}
|
|
31
31
|
export interface BuilderContent extends BuilderContentVariation {
|
|
32
32
|
'@version'?: number;
|
|
33
|
-
id?: string;
|
|
34
|
-
name?: string;
|
|
35
33
|
published?: 'published' | 'draft' | 'archived';
|
|
36
34
|
modelId?: string;
|
|
37
35
|
priority?: number;
|
|
@@ -39,7 +37,7 @@ export interface BuilderContent extends BuilderContentVariation {
|
|
|
39
37
|
startDate?: number;
|
|
40
38
|
endDate?: number;
|
|
41
39
|
variations?: {
|
|
42
|
-
[id: string]: BuilderContentVariation
|
|
40
|
+
[id: string]: BuilderContentVariation;
|
|
43
41
|
};
|
|
44
42
|
testVariationId?: string;
|
|
45
43
|
testVariationName?: string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder.io/sdk-svelte",
|
|
3
3
|
"description": "Builder.io SDK for Svelte",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"package",
|
|
@@ -28,10 +28,6 @@
|
|
|
28
28
|
},
|
|
29
29
|
"types": "./package/index.d.ts",
|
|
30
30
|
"scripts": {
|
|
31
|
-
"release:patch": "yarn run build && npm version patch && npm publish",
|
|
32
|
-
"release:minor": "yarn run build && npm version minor && npm publish",
|
|
33
|
-
"release:dev": "yarn run build && npm version prerelease && npm publish --tag dev",
|
|
34
|
-
"dev": "vite dev",
|
|
35
31
|
"build": "svelte-kit sync && svelte-package",
|
|
36
32
|
"build:watch": "svelte-kit sync && svelte-package --watch",
|
|
37
33
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
@@ -39,10 +35,10 @@
|
|
|
39
35
|
},
|
|
40
36
|
"devDependencies": {
|
|
41
37
|
"@sveltejs/adapter-auto": "1.0.0-next.71",
|
|
42
|
-
"@sveltejs/kit": "^1.
|
|
38
|
+
"@sveltejs/kit": "^1.16.2",
|
|
43
39
|
"@sveltejs/package": "1.0.0-next.1",
|
|
44
|
-
"svelte": "^3.
|
|
45
|
-
"svelte-check": "^
|
|
40
|
+
"svelte": "^3.59.1",
|
|
41
|
+
"svelte-check": "^3.3.2",
|
|
46
42
|
"svelte-preprocess": "^4.10.6",
|
|
47
43
|
"tslib": "^2.3.1",
|
|
48
44
|
"typescript": "^4",
|
|
@@ -11,12 +11,8 @@
|
|
|
11
11
|
export interface ColumnProps {
|
|
12
12
|
columns?: Column[];
|
|
13
13
|
builderBlock: BuilderBlock;
|
|
14
|
-
|
|
15
|
-
// TODO: Implement this when support for dynamic CSS lands
|
|
16
14
|
space?: number;
|
|
17
|
-
// TODO: Implement this when support for dynamic CSS lands
|
|
18
15
|
stackColumnsAt?: StackColumnsAt;
|
|
19
|
-
// TODO: Implement this when support for dynamic CSS lands
|
|
20
16
|
reverseColumnsWhenStacked?: boolean;
|
|
21
17
|
}
|
|
22
18
|
</script>
|
|
@@ -84,7 +80,7 @@
|
|
|
84
80
|
} as any as Dictionary<string>;
|
|
85
81
|
}
|
|
86
82
|
const width = getColumnCssWidth(index);
|
|
87
|
-
const gutterPixels = `${
|
|
83
|
+
const gutterPixels = `${gutter}px`;
|
|
88
84
|
const mobileWidth = "100%";
|
|
89
85
|
const mobileMarginLeft = 0;
|
|
90
86
|
return {
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
$: useBlock = () => {
|
|
25
25
|
return getProcessedBlock({
|
|
26
26
|
block: block,
|
|
27
|
-
|
|
27
|
+
localState: context.localState,
|
|
28
|
+
rootState: context.rootState,
|
|
29
|
+
rootSetState: context.rootSetState,
|
|
28
30
|
context: context.context,
|
|
29
31
|
shouldEvaluateBindings: true,
|
|
30
32
|
});
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BuilderContextInterface,
|
|
3
|
-
BuilderRenderState,
|
|
4
|
-
} from '../../context/types';
|
|
1
|
+
import type { BuilderContextInterface } from '../../context/types';
|
|
5
2
|
import { evaluate } from '../../functions/evaluate';
|
|
6
3
|
import { getProcessedBlock } from '../../functions/get-processed-block';
|
|
7
4
|
import type { BuilderBlock } from '../../types/builder-block';
|
|
@@ -44,7 +41,9 @@ export const getComponent = ({
|
|
|
44
41
|
}) => {
|
|
45
42
|
const componentName = getProcessedBlock({
|
|
46
43
|
block,
|
|
47
|
-
|
|
44
|
+
localState: context.localState,
|
|
45
|
+
rootState: context.rootState,
|
|
46
|
+
rootSetState: context.rootSetState,
|
|
48
47
|
context: context.context,
|
|
49
48
|
shouldEvaluateBindings: false,
|
|
50
49
|
}).component?.name;
|
|
@@ -85,7 +84,9 @@ export const getRepeatItemData = ({
|
|
|
85
84
|
|
|
86
85
|
const itemsArray = evaluate({
|
|
87
86
|
code: repeat.collection,
|
|
88
|
-
|
|
87
|
+
localState: context.localState,
|
|
88
|
+
rootState: context.rootState,
|
|
89
|
+
rootSetState: context.rootSetState,
|
|
89
90
|
context: context.context,
|
|
90
91
|
});
|
|
91
92
|
|
|
@@ -100,8 +101,8 @@ export const getRepeatItemData = ({
|
|
|
100
101
|
const repeatArray = itemsArray.map<RepeatData>((item, index) => ({
|
|
101
102
|
context: {
|
|
102
103
|
...context,
|
|
103
|
-
|
|
104
|
-
...context.
|
|
104
|
+
localState: {
|
|
105
|
+
...context.localState,
|
|
105
106
|
$index: index,
|
|
106
107
|
$item: item,
|
|
107
108
|
[itemNameToUse]: item,
|
|
@@ -113,26 +114,3 @@ export const getRepeatItemData = ({
|
|
|
113
114
|
|
|
114
115
|
return repeatArray;
|
|
115
116
|
};
|
|
116
|
-
|
|
117
|
-
export const getProxyState = (
|
|
118
|
-
context: BuilderContextInterface
|
|
119
|
-
): BuilderContextInterface['state'] => {
|
|
120
|
-
if (typeof Proxy === 'undefined') {
|
|
121
|
-
console.error(
|
|
122
|
-
'no Proxy available in this environment, cannot proxy state.'
|
|
123
|
-
);
|
|
124
|
-
return context.state;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const useState = new Proxy(context.state, {
|
|
128
|
-
set: (obj, prop: keyof BuilderRenderState, value) => {
|
|
129
|
-
// set the value on the state object, so that the event handler instantly gets the update.
|
|
130
|
-
obj[prop] = value;
|
|
131
|
-
|
|
132
|
-
// set the value in the context, so that the rest of the app gets the update.
|
|
133
|
-
context.setState?.(obj);
|
|
134
|
-
return true;
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
|
-
return useState;
|
|
138
|
-
};
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
import BlockStyles from "./block-styles.svelte";
|
|
16
16
|
import {
|
|
17
17
|
getComponent,
|
|
18
|
-
getProxyState,
|
|
19
18
|
getRepeatItemData,
|
|
20
19
|
isEmptyHtmlElement,
|
|
21
20
|
} from "./render-block.helpers.js";
|
|
@@ -47,12 +46,20 @@
|
|
|
47
46
|
export let block: RenderBlockProps["block"];
|
|
48
47
|
export let context: RenderBlockProps["context"];
|
|
49
48
|
|
|
49
|
+
$: repeatItem = () => {
|
|
50
|
+
return getRepeatItemData({
|
|
51
|
+
block: block,
|
|
52
|
+
context: context,
|
|
53
|
+
});
|
|
54
|
+
};
|
|
50
55
|
$: useBlock = () => {
|
|
51
|
-
return
|
|
56
|
+
return repeatItem()
|
|
52
57
|
? block
|
|
53
58
|
: getProcessedBlock({
|
|
54
59
|
block: block,
|
|
55
|
-
|
|
60
|
+
localState: context.localState,
|
|
61
|
+
rootState: context.rootState,
|
|
62
|
+
rootSetState: context.rootSetState,
|
|
56
63
|
context: context.context,
|
|
57
64
|
shouldEvaluateBindings: true,
|
|
58
65
|
});
|
|
@@ -69,7 +76,9 @@
|
|
|
69
76
|
$: actions = () => {
|
|
70
77
|
return getBlockActions({
|
|
71
78
|
block: useBlock(),
|
|
72
|
-
|
|
79
|
+
rootState: context.rootState,
|
|
80
|
+
rootSetState: context.rootSetState,
|
|
81
|
+
localState: context.localState,
|
|
73
82
|
context: context.context,
|
|
74
83
|
});
|
|
75
84
|
};
|
|
@@ -96,7 +105,7 @@
|
|
|
96
105
|
* blocks, and the children will be repeated within those blocks.
|
|
97
106
|
*/
|
|
98
107
|
const shouldRenderChildrenOutsideRef =
|
|
99
|
-
!component?.component && !
|
|
108
|
+
!component?.component && !repeatItem();
|
|
100
109
|
return shouldRenderChildrenOutsideRef ? useBlock().children ?? [] : [];
|
|
101
110
|
};
|
|
102
111
|
$: childrenContext = () => {
|
|
@@ -115,10 +124,11 @@
|
|
|
115
124
|
return {
|
|
116
125
|
apiKey: context.apiKey,
|
|
117
126
|
apiVersion: context.apiVersion,
|
|
118
|
-
|
|
127
|
+
localState: context.localState,
|
|
128
|
+
rootState: context.rootState,
|
|
129
|
+
rootSetState: context.rootSetState,
|
|
119
130
|
content: context.content,
|
|
120
131
|
context: context.context,
|
|
121
|
-
setState: context.setState,
|
|
122
132
|
registeredComponents: context.registeredComponents,
|
|
123
133
|
inheritedStyles: getInheritedTextStyles(),
|
|
124
134
|
};
|
|
@@ -150,28 +160,23 @@
|
|
|
150
160
|
block: block,
|
|
151
161
|
context: context,
|
|
152
162
|
});
|
|
153
|
-
let
|
|
154
|
-
block: block,
|
|
155
|
-
context: context,
|
|
156
|
-
});
|
|
157
|
-
let tag = block.tagName || "div";
|
|
158
|
-
let proxyState = getProxyState(context);
|
|
163
|
+
let Tag = block.tagName || "div";
|
|
159
164
|
</script>
|
|
160
165
|
|
|
161
166
|
{#if canShowBlock()}
|
|
162
167
|
{#if !component?.noWrap}
|
|
163
|
-
{#if isEmptyHtmlElement(
|
|
164
|
-
<svelte:element this={
|
|
168
|
+
{#if isEmptyHtmlElement(Tag)}
|
|
169
|
+
<svelte:element this={Tag} {...attributes()} use:setAttrs={actions()} />
|
|
165
170
|
{/if}
|
|
166
171
|
|
|
167
|
-
{#if !isEmptyHtmlElement(
|
|
168
|
-
{#each
|
|
172
|
+
{#if !isEmptyHtmlElement(Tag) && repeatItem()}
|
|
173
|
+
{#each repeatItem() as data, index (index)}
|
|
169
174
|
<RenderRepeatedBlock repeatContext={data.context} block={data.block} />
|
|
170
175
|
{/each}
|
|
171
176
|
{/if}
|
|
172
177
|
|
|
173
|
-
{#if !isEmptyHtmlElement(
|
|
174
|
-
<svelte:element this={
|
|
178
|
+
{#if !isEmptyHtmlElement(Tag) && !repeatItem()}
|
|
179
|
+
<svelte:element this={Tag} {...attributes()} use:setAttrs={actions()}>
|
|
175
180
|
<RenderComponent {...renderComponentProps()} />
|
|
176
181
|
|
|
177
182
|
{#each childrenWithoutParentComponent() as child ("render-block-" + child.id)}
|
|
@@ -28,8 +28,9 @@
|
|
|
28
28
|
|
|
29
29
|
setContext(BuilderContext.key, {
|
|
30
30
|
content: repeatContext.content,
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
localState: repeatContext.localState,
|
|
32
|
+
rootState: repeatContext.rootState,
|
|
33
|
+
rootSetState: repeatContext.rootSetState,
|
|
33
34
|
context: repeatContext.context,
|
|
34
35
|
apiKey: repeatContext.apiKey,
|
|
35
36
|
registeredComponents: repeatContext.registeredComponents,
|