@builder.io/sdk-svelte 2.0.31 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/blocks/image/component-info.js +2 -1
- package/lib/browser/blocks/image/image.svelte +2 -1
- package/lib/browser/blocks/img/component-info.js +2 -1
- package/lib/browser/blocks/video/component-info.js +3 -2
- package/lib/browser/components/block/block.helpers.d.ts +6 -3
- package/lib/browser/components/block/block.helpers.js +16 -5
- package/lib/browser/components/block/block.svelte +2 -1
- package/lib/browser/components/content/components/enable-editor.helpers.d.ts +11 -0
- package/lib/browser/components/content/components/enable-editor.helpers.js +15 -0
- package/lib/browser/components/content/components/enable-editor.svelte +24 -3
- package/lib/browser/components/content/content.svelte +4 -15
- package/lib/browser/components/content/content.svelte.d.ts +1 -1
- package/lib/browser/constants/file-types.d.ts +2 -0
- package/lib/browser/constants/file-types.js +2 -0
- package/lib/browser/constants/sdk-version.d.ts +1 -1
- package/lib/browser/constants/sdk-version.js +1 -1
- package/lib/browser/context/builder.context.d.ts +1 -0
- package/lib/browser/context/builder.context.js +1 -0
- package/lib/browser/context/types.d.ts +1 -0
- package/lib/browser/functions/extract-localized-values.d.ts +2 -0
- package/lib/browser/functions/extract-localized-values.js +37 -0
- package/lib/browser/functions/get-content/index.d.ts +1 -1
- package/lib/browser/functions/get-content/index.js +10 -16
- package/lib/browser/functions/get-processed-block.js +3 -1
- package/lib/browser/functions/register-component.js +4 -1
- package/lib/browser/functions/traverse.d.ts +34 -0
- package/lib/browser/functions/traverse.js +63 -0
- package/lib/browser/types/components.d.ts +3 -0
- package/lib/edge/blocks/image/component-info.js +2 -1
- package/lib/edge/blocks/image/image.svelte +2 -1
- package/lib/edge/blocks/img/component-info.js +2 -1
- package/lib/edge/blocks/video/component-info.js +3 -2
- package/lib/edge/components/block/block.helpers.d.ts +6 -3
- package/lib/edge/components/block/block.helpers.js +16 -5
- package/lib/edge/components/block/block.svelte +2 -1
- package/lib/edge/components/content/components/enable-editor.helpers.d.ts +11 -0
- package/lib/edge/components/content/components/enable-editor.helpers.js +15 -0
- package/lib/edge/components/content/components/enable-editor.svelte +24 -3
- package/lib/edge/components/content/content.svelte +4 -15
- package/lib/edge/components/content/content.svelte.d.ts +1 -1
- package/lib/edge/constants/file-types.d.ts +2 -0
- package/lib/edge/constants/file-types.js +2 -0
- package/lib/edge/constants/sdk-version.d.ts +1 -1
- package/lib/edge/constants/sdk-version.js +1 -1
- package/lib/edge/context/builder.context.d.ts +1 -0
- package/lib/edge/context/builder.context.js +1 -0
- package/lib/edge/context/types.d.ts +1 -0
- package/lib/edge/functions/extract-localized-values.d.ts +2 -0
- package/lib/edge/functions/extract-localized-values.js +37 -0
- package/lib/edge/functions/get-content/index.d.ts +1 -1
- package/lib/edge/functions/get-content/index.js +10 -16
- package/lib/edge/functions/get-processed-block.js +3 -1
- package/lib/edge/functions/register-component.js +4 -1
- package/lib/edge/functions/traverse.d.ts +34 -0
- package/lib/edge/functions/traverse.js +63 -0
- package/lib/edge/types/components.d.ts +3 -0
- package/lib/node/blocks/image/component-info.js +2 -1
- package/lib/node/blocks/image/image.svelte +2 -1
- package/lib/node/blocks/img/component-info.js +2 -1
- package/lib/node/blocks/video/component-info.js +3 -2
- package/lib/node/components/block/block.helpers.d.ts +6 -3
- package/lib/node/components/block/block.helpers.js +16 -5
- package/lib/node/components/block/block.svelte +2 -1
- package/lib/node/components/content/components/enable-editor.helpers.d.ts +11 -0
- package/lib/node/components/content/components/enable-editor.helpers.js +15 -0
- package/lib/node/components/content/components/enable-editor.svelte +24 -3
- package/lib/node/components/content/content.svelte +4 -15
- package/lib/node/components/content/content.svelte.d.ts +1 -1
- package/lib/node/constants/file-types.d.ts +2 -0
- package/lib/node/constants/file-types.js +2 -0
- package/lib/node/constants/sdk-version.d.ts +1 -1
- package/lib/node/constants/sdk-version.js +1 -1
- package/lib/node/context/builder.context.d.ts +1 -0
- package/lib/node/context/builder.context.js +1 -0
- package/lib/node/context/types.d.ts +1 -0
- package/lib/node/functions/extract-localized-values.d.ts +2 -0
- package/lib/node/functions/extract-localized-values.js +37 -0
- package/lib/node/functions/get-content/index.d.ts +1 -1
- package/lib/node/functions/get-content/index.js +10 -16
- package/lib/node/functions/get-processed-block.js +3 -1
- package/lib/node/functions/register-component.js +4 -1
- package/lib/node/functions/traverse.d.ts +34 -0
- package/lib/node/functions/traverse.js +63 -0
- package/lib/node/types/components.d.ts +3 -0
- package/package.json +1 -1
- package/src/blocks/image/component-info.ts +2 -1
- package/src/blocks/image/image.svelte +4 -1
- package/src/blocks/img/component-info.ts +2 -1
- package/src/blocks/video/component-info.ts +3 -2
- package/src/components/block/block.helpers.ts +18 -6
- package/src/components/block/block.svelte +6 -1
- package/src/components/content/components/enable-editor.helpers.ts +18 -0
- package/src/components/content/components/enable-editor.svelte +27 -3
- package/src/components/content/content.svelte +4 -11
- package/src/constants/file-types.ts +2 -0
- package/src/constants/sdk-version.ts +1 -1
- package/src/context/builder.context.ts +1 -0
- package/src/context/types.ts +1 -0
- package/src/functions/extract-localized-values.ts +38 -0
- package/src/functions/get-content/index.ts +10 -15
- package/src/functions/get-processed-block.ts +3 -1
- package/src/functions/register-component.ts +4 -1
- package/src/functions/traverse.ts +64 -0
- package/src/types/components.ts +3 -0
|
@@ -3,9 +3,10 @@ import type { Writable } from "svelte/store";
|
|
|
3
3
|
import type { BuilderContextInterface, RegisteredComponent, RegisteredComponents } from '../../context/types';
|
|
4
4
|
import type { BuilderBlock } from '../../types/builder-block';
|
|
5
5
|
import type { RepeatData } from './types';
|
|
6
|
-
export declare const getComponent: ({ block, registeredComponents }: {
|
|
6
|
+
export declare const getComponent: ({ block, registeredComponents, model }: {
|
|
7
7
|
block: BuilderBlock;
|
|
8
8
|
registeredComponents: RegisteredComponents;
|
|
9
|
+
model: string;
|
|
9
10
|
}) => RegisteredComponent | null | undefined;
|
|
10
11
|
export declare const getRepeatItemData: ({ block, context }: {
|
|
11
12
|
block: BuilderBlock;
|
|
@@ -20,8 +21,10 @@ export declare const provideLinkComponent: (block: RegisteredComponent | null |
|
|
|
20
21
|
} | {
|
|
21
22
|
builderLinkComponent?: undefined;
|
|
22
23
|
};
|
|
23
|
-
export declare const provideRegisteredComponents: (block: RegisteredComponent | null | undefined, registeredComponents: RegisteredComponents) => {
|
|
24
|
-
builderComponents:
|
|
24
|
+
export declare const provideRegisteredComponents: (block: RegisteredComponent | null | undefined, registeredComponents: RegisteredComponents, model: string) => {
|
|
25
|
+
builderComponents: {
|
|
26
|
+
[k: string]: RegisteredComponent;
|
|
27
|
+
};
|
|
25
28
|
} | {
|
|
26
29
|
builderComponents?: undefined;
|
|
27
30
|
};
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { evaluate } from '../../functions/evaluate/index';
|
|
2
2
|
import { extractTextStyles } from '../../functions/extract-text-styles';
|
|
3
3
|
import { getStyle } from '../../functions/get-style';
|
|
4
|
-
|
|
4
|
+
const checkIsComponentRestricted = (component, model) => {
|
|
5
|
+
if (!component)
|
|
6
|
+
return true;
|
|
7
|
+
if (!model)
|
|
8
|
+
return false;
|
|
9
|
+
return component.models && component.models.length > 0 && !component.models.includes(model);
|
|
10
|
+
};
|
|
11
|
+
export const getComponent = ({ block, registeredComponents, model }) => {
|
|
5
12
|
const componentName = block.component?.name;
|
|
6
13
|
if (!componentName) {
|
|
7
14
|
return null;
|
|
8
15
|
}
|
|
9
16
|
const ref = registeredComponents[componentName];
|
|
10
|
-
if (!ref) {
|
|
17
|
+
if (!ref || checkIsComponentRestricted(ref, model)) {
|
|
11
18
|
// TODO: Public doc page with more info about this message
|
|
12
19
|
console.warn(`
|
|
13
20
|
Could not find a registered component named "${componentName}".
|
|
@@ -71,11 +78,15 @@ export const provideLinkComponent = (block, linkComponent) => {
|
|
|
71
78
|
};
|
|
72
79
|
return {};
|
|
73
80
|
};
|
|
74
|
-
export const provideRegisteredComponents = (block, registeredComponents) => {
|
|
75
|
-
if (block?.shouldReceiveBuilderProps?.builderComponents)
|
|
81
|
+
export const provideRegisteredComponents = (block, registeredComponents, model) => {
|
|
82
|
+
if (block?.shouldReceiveBuilderProps?.builderComponents) {
|
|
83
|
+
const filteredRegisteredComponents = Object.fromEntries(Object.entries(registeredComponents).filter(([_, component]) => {
|
|
84
|
+
return !checkIsComponentRestricted(component, model);
|
|
85
|
+
}));
|
|
76
86
|
return {
|
|
77
|
-
builderComponents:
|
|
87
|
+
builderComponents: filteredRegisteredComponents
|
|
78
88
|
};
|
|
89
|
+
}
|
|
79
90
|
return {};
|
|
80
91
|
};
|
|
81
92
|
export const provideBuilderBlock = (block, builderBlock) => {
|
|
@@ -39,6 +39,7 @@ $: blockComponent = () => {
|
|
|
39
39
|
return getComponent({
|
|
40
40
|
block: processedBlock(),
|
|
41
41
|
registeredComponents: registeredComponents,
|
|
42
|
+
model: $context.model,
|
|
42
43
|
});
|
|
43
44
|
};
|
|
44
45
|
$: Tag = () => {
|
|
@@ -81,7 +82,7 @@ $: componentRefProps = () => {
|
|
|
81
82
|
...provideBuilderBlock(blockComponent(), processedBlock()),
|
|
82
83
|
...provideBuilderContext(blockComponent(), context),
|
|
83
84
|
...provideLinkComponent(blockComponent(), linkComponent),
|
|
84
|
-
...provideRegisteredComponents(blockComponent(), registeredComponents),
|
|
85
|
+
...provideRegisteredComponents(blockComponent(), registeredComponents, $context.model),
|
|
85
86
|
},
|
|
86
87
|
context: context,
|
|
87
88
|
linkComponent: linkComponent,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Target } from '../../../types/targets';
|
|
2
|
+
/**
|
|
3
|
+
* SDKS that use the elementRef approach to enable visual editing.
|
|
4
|
+
* We don't need to render the div for other SDKs as they attach event listeners to the window.
|
|
5
|
+
*/
|
|
6
|
+
export declare const SDKS_USING_ELEMENT_REF_APPROACH: Target[];
|
|
7
|
+
/**
|
|
8
|
+
* We need to attach this div only when content exists or isPreviewing/isEditing even when content is null,
|
|
9
|
+
* as we need to set the elementRef and allow previewing and visual editing
|
|
10
|
+
*/
|
|
11
|
+
export declare const needsElementRefDivForEditing: () => boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TARGET } from '../../../constants/target';
|
|
2
|
+
import { isEditing } from '../../../functions/is-editing';
|
|
3
|
+
import { isPreviewing } from '../../../functions/is-previewing';
|
|
4
|
+
/**
|
|
5
|
+
* SDKS that use the elementRef approach to enable visual editing.
|
|
6
|
+
* We don't need to render the div for other SDKs as they attach event listeners to the window.
|
|
7
|
+
*/
|
|
8
|
+
export const SDKS_USING_ELEMENT_REF_APPROACH = ['svelte', 'qwik', 'vue'];
|
|
9
|
+
/**
|
|
10
|
+
* We need to attach this div only when content exists or isPreviewing/isEditing even when content is null,
|
|
11
|
+
* as we need to set the elementRef and allow previewing and visual editing
|
|
12
|
+
*/
|
|
13
|
+
export const needsElementRefDivForEditing = () => {
|
|
14
|
+
return SDKS_USING_ELEMENT_REF_APPROACH.includes(TARGET) && (isEditing() || isPreviewing());
|
|
15
|
+
};
|
|
@@ -18,6 +18,7 @@ import { createEditorListener } from "../../../helpers/subscribe-to-editor";
|
|
|
18
18
|
import { registerInsertMenu, setupBrowserForEditing, } from "../../../scripts/init-editing";
|
|
19
19
|
import { triggerAnimation } from "../../block/animator";
|
|
20
20
|
import "../../dynamic-div.svelte";
|
|
21
|
+
import { needsElementRefDivForEditing } from "./enable-editor.helpers";
|
|
21
22
|
import { getWrapperClassName } from "./styles.helpers";
|
|
22
23
|
export let isNestedRender = undefined;
|
|
23
24
|
export let builderContextSignal;
|
|
@@ -34,6 +35,16 @@ export let showContent;
|
|
|
34
35
|
export let contentWrapper = undefined;
|
|
35
36
|
export let context = undefined;
|
|
36
37
|
export let contentWrapperProps = undefined;
|
|
38
|
+
function stringifyStyles(stylesObj) {
|
|
39
|
+
let styles = "";
|
|
40
|
+
for (let key in stylesObj) {
|
|
41
|
+
const dashedKey = key.replace(/[A-Z]/g, function (match) {
|
|
42
|
+
return "-" + match.toLowerCase();
|
|
43
|
+
});
|
|
44
|
+
styles += dashedKey + ":" + stylesObj[key] + ";";
|
|
45
|
+
}
|
|
46
|
+
return styles;
|
|
47
|
+
}
|
|
37
48
|
function mergeNewRootState(newData) {
|
|
38
49
|
const combinedState = {
|
|
39
50
|
...$builderContextSignal.rootState,
|
|
@@ -178,8 +189,12 @@ function elementRef_onIniteditingbldr(event) {
|
|
|
178
189
|
: {}),
|
|
179
190
|
});
|
|
180
191
|
Object.values($builderContextSignal.componentInfos).forEach((registeredComponent) => {
|
|
181
|
-
|
|
182
|
-
|
|
192
|
+
if (!model ||
|
|
193
|
+
!registeredComponent.models?.length ||
|
|
194
|
+
registeredComponent.models.includes(model)) {
|
|
195
|
+
const message = createRegisterComponentMessage(registeredComponent);
|
|
196
|
+
window.parent?.postMessage(message, "*");
|
|
197
|
+
}
|
|
183
198
|
});
|
|
184
199
|
window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
|
|
185
200
|
}
|
|
@@ -293,9 +308,15 @@ onDestroy(() => {
|
|
|
293
308
|
});
|
|
294
309
|
</script>
|
|
295
310
|
|
|
296
|
-
{#if $builderContextSignal.content}
|
|
311
|
+
{#if $builderContextSignal.content || needsElementRefDivForEditing()}
|
|
297
312
|
<svelte:element
|
|
298
313
|
this={ContentWrapper}
|
|
314
|
+
style={stringifyStyles({
|
|
315
|
+
display:
|
|
316
|
+
!$builderContextSignal.content && needsElementRefDivForEditing()
|
|
317
|
+
? "none"
|
|
318
|
+
: undefined,
|
|
319
|
+
})}
|
|
299
320
|
{...{}}
|
|
300
321
|
bind:this={elementRef}
|
|
301
322
|
on:click={(event) => {
|
|
@@ -18,7 +18,6 @@ export let apiKey;
|
|
|
18
18
|
export let context = undefined;
|
|
19
19
|
export let content = undefined;
|
|
20
20
|
export let customComponents = undefined;
|
|
21
|
-
export let model = undefined;
|
|
22
21
|
export let data = undefined;
|
|
23
22
|
export let locale = undefined;
|
|
24
23
|
export let canTrack = undefined;
|
|
@@ -26,6 +25,7 @@ export let apiVersion = undefined;
|
|
|
26
25
|
export let blocksWrapper = undefined;
|
|
27
26
|
export let blocksWrapperProps = undefined;
|
|
28
27
|
export let nonce = undefined;
|
|
28
|
+
export let model = undefined;
|
|
29
29
|
export let apiHost = undefined;
|
|
30
30
|
export let enrich = undefined;
|
|
31
31
|
export let showContent;
|
|
@@ -46,13 +46,7 @@ let scriptStr = getUpdateVariantVisibilityScript({
|
|
|
46
46
|
});
|
|
47
47
|
let registeredComponents = [
|
|
48
48
|
...getDefaultRegisteredComponents(),
|
|
49
|
-
...(customComponents
|
|
50
|
-
if (!models?.length)
|
|
51
|
-
return true;
|
|
52
|
-
if (!model)
|
|
53
|
-
return true;
|
|
54
|
-
return models.includes(model);
|
|
55
|
-
}) || []),
|
|
49
|
+
...(customComponents || []),
|
|
56
50
|
].reduce((acc, { component, ...info }) => ({
|
|
57
51
|
...acc,
|
|
58
52
|
[info.name]: {
|
|
@@ -78,13 +72,7 @@ let builderContextSignal = writable({
|
|
|
78
72
|
apiVersion: apiVersion,
|
|
79
73
|
componentInfos: [
|
|
80
74
|
...getDefaultRegisteredComponents(),
|
|
81
|
-
...(customComponents
|
|
82
|
-
if (!models?.length)
|
|
83
|
-
return true;
|
|
84
|
-
if (!model)
|
|
85
|
-
return true;
|
|
86
|
-
return models.includes(model);
|
|
87
|
-
}) || []),
|
|
75
|
+
...(customComponents || []),
|
|
88
76
|
].reduce((acc, { component: _, ...info }) => ({
|
|
89
77
|
...acc,
|
|
90
78
|
[info.name]: serializeIncludingFunctions(info),
|
|
@@ -93,6 +81,7 @@ let builderContextSignal = writable({
|
|
|
93
81
|
BlocksWrapper: blocksWrapper || "div",
|
|
94
82
|
BlocksWrapperProps: blocksWrapperProps || {},
|
|
95
83
|
nonce: nonce || "",
|
|
84
|
+
model: model || "",
|
|
96
85
|
});
|
|
97
86
|
if (!apiKey) {
|
|
98
87
|
logger.error("No API key provided to `Content` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
|
|
@@ -6,7 +6,6 @@ declare const __propDef: {
|
|
|
6
6
|
context?: ContentProps["context"];
|
|
7
7
|
content?: ContentProps["content"];
|
|
8
8
|
customComponents?: ContentProps["customComponents"];
|
|
9
|
-
model?: ContentProps["model"];
|
|
10
9
|
data?: ContentProps["data"];
|
|
11
10
|
locale?: ContentProps["locale"];
|
|
12
11
|
canTrack?: ContentProps["canTrack"];
|
|
@@ -14,6 +13,7 @@ declare const __propDef: {
|
|
|
14
13
|
blocksWrapper?: ContentProps["blocksWrapper"];
|
|
15
14
|
blocksWrapperProps?: ContentProps["blocksWrapperProps"];
|
|
16
15
|
nonce?: ContentProps["nonce"];
|
|
16
|
+
model?: ContentProps["model"];
|
|
17
17
|
apiHost?: ContentProps["apiHost"];
|
|
18
18
|
enrich?: ContentProps["enrich"];
|
|
19
19
|
showContent: ContentProps["showContent"];
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export const IMAGE_FILE_TYPES = ['jpeg', 'jpg', 'png', 'svg', 'webp', 'gif', 'jfif', 'pjpeg', 'pjp', 'apng', 'avif', 'tif', 'tiff', 'heif', 'bmp', 'eps', 'raw', 'cr2', 'nef', 'orf', 'sr2', 'psd', 'heic', 'dib', 'ai'];
|
|
2
|
+
export const VIDEO_FILE_TYPES = ['mp4', 'webm', 'mkv', 'flv', 'vob', 'ogv', 'ogg', 'drc', 'gif', 'gifv', 'mng', 'avi', 'mov', 'qt', 'mts', 'm2ts', 'ts', 'wmv', 'yuv', 'rm', 'rmvb', 'viv', 'asf', 'amv', 'm4p', 'mpeg', 'mpe', 'm2v', 'm4v', 'svi', '3gp', '3g2', 'mxf', 'roq', 'nsv', 'f4v', 'f4p', 'f4a', 'f4b'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "
|
|
1
|
+
export declare const SDK_VERSION = "3.0.1";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "
|
|
1
|
+
export const SDK_VERSION = "3.0.1";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { traverse } from './traverse';
|
|
2
|
+
function isLocalizedField(value) {
|
|
3
|
+
return value && typeof value === 'object' && value['@type'] === '@builder.io/core:LocalizedValue';
|
|
4
|
+
}
|
|
5
|
+
function containsLocalizedValues(data) {
|
|
6
|
+
if (!data || !Object.getOwnPropertyNames(data).length) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
let hasLocalizedValues = false;
|
|
10
|
+
traverse(data, value => {
|
|
11
|
+
if (isLocalizedField(value)) {
|
|
12
|
+
hasLocalizedValues = true;
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
return hasLocalizedValues;
|
|
17
|
+
}
|
|
18
|
+
function extractLocalizedValues(data, locale) {
|
|
19
|
+
if (!data || !Object.getOwnPropertyNames(data).length) {
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
traverse(data, (value, update) => {
|
|
23
|
+
if (isLocalizedField(value)) {
|
|
24
|
+
update(value[locale] ?? undefined);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
export function resolveLocalizedValues(block, locale) {
|
|
30
|
+
if (block.component?.options && containsLocalizedValues(block.component?.options)) {
|
|
31
|
+
if (!locale) {
|
|
32
|
+
console.warn('[Builder.io] In order to use localized fields in Builder, you must pass a locale prop to the BuilderComponent or to options object while fetching the content to resolve localized fields. Learn more: https://www.builder.io/c/docs/localization-inline#targeting-and-inline-localization');
|
|
33
|
+
}
|
|
34
|
+
block.component.options = extractLocalizedValues(block.component.options, locale ?? 'Default');
|
|
35
|
+
}
|
|
36
|
+
return block;
|
|
37
|
+
}
|
|
@@ -14,5 +14,5 @@ export declare const _processContentResult: (options: GetContentOptions, content
|
|
|
14
14
|
/**
|
|
15
15
|
* Returns a paginated array of entries that match the given options.
|
|
16
16
|
*/
|
|
17
|
-
export declare function fetchEntries(options: GetContentOptions): Promise<BuilderContent[]
|
|
17
|
+
export declare function fetchEntries(options: GetContentOptions): Promise<BuilderContent[]>;
|
|
18
18
|
export {};
|
|
@@ -78,21 +78,15 @@ export const _processContentResult = async (options, content, url = generateCont
|
|
|
78
78
|
* Returns a paginated array of entries that match the given options.
|
|
79
79
|
*/
|
|
80
80
|
export async function fetchEntries(options) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
return _processContentResult(options, content);
|
|
93
|
-
}
|
|
94
|
-
catch (error) {
|
|
95
|
-
logger.error('Error fetching data. ', error);
|
|
96
|
-
return null;
|
|
81
|
+
const url = generateContentUrl(options);
|
|
82
|
+
const content = await _fetchContent(options);
|
|
83
|
+
if (!checkContentHasResults(content)) {
|
|
84
|
+
logger.error('Error fetching data. ', {
|
|
85
|
+
url,
|
|
86
|
+
content,
|
|
87
|
+
options
|
|
88
|
+
});
|
|
89
|
+
throw content;
|
|
97
90
|
}
|
|
91
|
+
return _processContentResult(options, content);
|
|
98
92
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TARGET } from '../constants/target';
|
|
2
2
|
import { omit } from '../helpers/omit';
|
|
3
3
|
import { evaluate } from './evaluate/index';
|
|
4
|
+
import { resolveLocalizedValues } from './extract-localized-values';
|
|
4
5
|
import { fastClone } from './fast-clone';
|
|
5
6
|
import { set } from './set';
|
|
6
7
|
import { transformBlock } from './transform-block';
|
|
@@ -72,7 +73,8 @@ const evaluateBindings = ({ block, context, localState, rootState, rootSetState
|
|
|
72
73
|
return copied;
|
|
73
74
|
};
|
|
74
75
|
export function getProcessedBlock({ block, context, shouldEvaluateBindings, localState, rootState, rootSetState }) {
|
|
75
|
-
|
|
76
|
+
let transformedBlock = resolveLocalizedValues(block, rootState.locale);
|
|
77
|
+
transformedBlock = transformBlock(transformedBlock);
|
|
76
78
|
if (shouldEvaluateBindings) {
|
|
77
79
|
return evaluateBindings({
|
|
78
80
|
block: transformedBlock,
|
|
@@ -10,8 +10,11 @@ const serializeFn = (fnValue) => {
|
|
|
10
10
|
// 2. `name(args) => {code}`
|
|
11
11
|
// 3. `(args) => {}`
|
|
12
12
|
// 4. `args => {}`
|
|
13
|
+
// 5. `async function(args) {code}`
|
|
14
|
+
// 6. `async (args) => {}`
|
|
15
|
+
// 7. `async args => {}`
|
|
13
16
|
const isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
|
|
14
|
-
const appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(') && !isArrowWithoutParens;
|
|
17
|
+
const appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('async') && !fnStr.startsWith('(') && !isArrowWithoutParens;
|
|
15
18
|
return `return (${appendFunction ? 'function ' : ''}${fnStr}).apply(this, arguments)`;
|
|
16
19
|
};
|
|
17
20
|
export function serializeIncludingFunctions(info) {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
type TraverseCallback = (value: any, update: (newValue: any) => void) => void;
|
|
2
|
+
/**
|
|
3
|
+
* Recursively traverses an object or array, invoking a callback on each value.
|
|
4
|
+
*
|
|
5
|
+
* @param {any} obj - The object or array to traverse. Can also handle primitives, null, or undefined.
|
|
6
|
+
* @param {TraverseCallback} callback - The function to invoke on each value. Receives the current value
|
|
7
|
+
* and an `update` function to modify the value in its parent container.
|
|
8
|
+
* @param {any} [parent=null] - The parent object or array of the current value. Used internally.
|
|
9
|
+
* @param {any} [key=null] - The key or index of the current value in its parent. Used internally.
|
|
10
|
+
* @param {WeakSet} [visited=new WeakSet()] - Tracks visited objects to handle circular references. Used internally.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Example: Doubling all numbers in an object
|
|
14
|
+
* const obj = { a: 1, b: [2, 3, { c: 4 }] };
|
|
15
|
+
* traverse(obj, (value, update) => {
|
|
16
|
+
* if (typeof value === 'number') {
|
|
17
|
+
* update(value * 2);
|
|
18
|
+
* }
|
|
19
|
+
* });
|
|
20
|
+
* console.log(obj); // { a: 2, b: [4, 6, { c: 8 }] }
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // Example: Handling circular references
|
|
24
|
+
* const obj = { a: 1 };
|
|
25
|
+
* obj.self = obj;
|
|
26
|
+
* traverse(obj, (value, update) => {
|
|
27
|
+
* if (typeof value === 'number') {
|
|
28
|
+
* update(value * 2);
|
|
29
|
+
* }
|
|
30
|
+
* });
|
|
31
|
+
* console.log(obj.a); // 2
|
|
32
|
+
*/
|
|
33
|
+
export declare function traverse(obj: any, callback: TraverseCallback, parent?: any, key?: any, visited?: WeakSet<WeakKey>): void;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively traverses an object or array, invoking a callback on each value.
|
|
3
|
+
*
|
|
4
|
+
* @param {any} obj - The object or array to traverse. Can also handle primitives, null, or undefined.
|
|
5
|
+
* @param {TraverseCallback} callback - The function to invoke on each value. Receives the current value
|
|
6
|
+
* and an `update` function to modify the value in its parent container.
|
|
7
|
+
* @param {any} [parent=null] - The parent object or array of the current value. Used internally.
|
|
8
|
+
* @param {any} [key=null] - The key or index of the current value in its parent. Used internally.
|
|
9
|
+
* @param {WeakSet} [visited=new WeakSet()] - Tracks visited objects to handle circular references. Used internally.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* // Example: Doubling all numbers in an object
|
|
13
|
+
* const obj = { a: 1, b: [2, 3, { c: 4 }] };
|
|
14
|
+
* traverse(obj, (value, update) => {
|
|
15
|
+
* if (typeof value === 'number') {
|
|
16
|
+
* update(value * 2);
|
|
17
|
+
* }
|
|
18
|
+
* });
|
|
19
|
+
* console.log(obj); // { a: 2, b: [4, 6, { c: 8 }] }
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Example: Handling circular references
|
|
23
|
+
* const obj = { a: 1 };
|
|
24
|
+
* obj.self = obj;
|
|
25
|
+
* traverse(obj, (value, update) => {
|
|
26
|
+
* if (typeof value === 'number') {
|
|
27
|
+
* update(value * 2);
|
|
28
|
+
* }
|
|
29
|
+
* });
|
|
30
|
+
* console.log(obj.a); // 2
|
|
31
|
+
*/
|
|
32
|
+
export function traverse(obj, callback, parent = null, key = null, visited = new WeakSet()) {
|
|
33
|
+
if (obj == null || typeof obj !== 'object') {
|
|
34
|
+
callback(obj, (newValue) => {
|
|
35
|
+
if (parent !== null && key !== null) {
|
|
36
|
+
parent[key] = newValue;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (visited.has(obj)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
visited.add(obj);
|
|
45
|
+
if (Array.isArray(obj)) {
|
|
46
|
+
obj.forEach((item, index) => {
|
|
47
|
+
const update = (newValue) => {
|
|
48
|
+
obj[index] = newValue;
|
|
49
|
+
};
|
|
50
|
+
callback(item, update);
|
|
51
|
+
traverse(item, callback, obj, index, visited);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
Object.entries(obj).forEach(([key, value]) => {
|
|
56
|
+
const update = (newValue) => {
|
|
57
|
+
obj[key] = newValue;
|
|
58
|
+
};
|
|
59
|
+
callback(value, update);
|
|
60
|
+
traverse(value, callback, obj, key, visited);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IMAGE_FILE_TYPES } from '../../constants/file-types';
|
|
1
2
|
export const componentInfo = {
|
|
2
3
|
name: 'Image',
|
|
3
4
|
static: true,
|
|
@@ -13,7 +14,7 @@ export const componentInfo = {
|
|
|
13
14
|
name: 'image',
|
|
14
15
|
type: 'file',
|
|
15
16
|
bubble: true,
|
|
16
|
-
allowedFileTypes:
|
|
17
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
17
18
|
required: true,
|
|
18
19
|
defaultValue: 'https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F72c80f114dc149019051b6852a9e3b7a',
|
|
19
20
|
onChange: (options) => {
|
|
@@ -29,7 +29,8 @@ $: srcSetToUse = () => {
|
|
|
29
29
|
if (!url ||
|
|
30
30
|
// We can auto add srcset for cdn.builder.io and shopify
|
|
31
31
|
// images, otherwise you can supply this prop manually
|
|
32
|
-
!(url
|
|
32
|
+
!(typeof url === "string" &&
|
|
33
|
+
(url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/)))) {
|
|
33
34
|
return srcset;
|
|
34
35
|
}
|
|
35
36
|
if (noWebp) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IMAGE_FILE_TYPES } from '../../constants/file-types';
|
|
1
2
|
export const componentInfo = {
|
|
2
3
|
// friendlyName?
|
|
3
4
|
name: 'Raw:Img',
|
|
@@ -7,7 +8,7 @@ export const componentInfo = {
|
|
|
7
8
|
name: 'image',
|
|
8
9
|
bubble: true,
|
|
9
10
|
type: 'file',
|
|
10
|
-
allowedFileTypes:
|
|
11
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
11
12
|
required: true
|
|
12
13
|
}],
|
|
13
14
|
noWrap: true,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IMAGE_FILE_TYPES, VIDEO_FILE_TYPES } from '../../constants/file-types';
|
|
1
2
|
export const componentInfo = {
|
|
2
3
|
name: 'Video',
|
|
3
4
|
canHaveChildren: true,
|
|
@@ -9,14 +10,14 @@ export const componentInfo = {
|
|
|
9
10
|
inputs: [{
|
|
10
11
|
name: 'video',
|
|
11
12
|
type: 'file',
|
|
12
|
-
allowedFileTypes:
|
|
13
|
+
allowedFileTypes: VIDEO_FILE_TYPES,
|
|
13
14
|
bubble: true,
|
|
14
15
|
defaultValue: 'https://cdn.builder.io/o/assets%2FYJIGb4i01jvw0SRdL5Bt%2Fd27731a526464deba0016216f5f9e570%2Fcompressed?apiKey=YJIGb4i01jvw0SRdL5Bt&token=d27731a526464deba0016216f5f9e570&alt=media&optimized=true',
|
|
15
16
|
required: true
|
|
16
17
|
}, {
|
|
17
18
|
name: 'posterImage',
|
|
18
19
|
type: 'file',
|
|
19
|
-
allowedFileTypes:
|
|
20
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
20
21
|
helperText: 'Image to show before the video plays'
|
|
21
22
|
}, {
|
|
22
23
|
name: 'autoPlay',
|
|
@@ -3,9 +3,10 @@ import type { Writable } from "svelte/store";
|
|
|
3
3
|
import type { BuilderContextInterface, RegisteredComponent, RegisteredComponents } from '../../context/types';
|
|
4
4
|
import type { BuilderBlock } from '../../types/builder-block';
|
|
5
5
|
import type { RepeatData } from './types';
|
|
6
|
-
export declare const getComponent: ({ block, registeredComponents }: {
|
|
6
|
+
export declare const getComponent: ({ block, registeredComponents, model }: {
|
|
7
7
|
block: BuilderBlock;
|
|
8
8
|
registeredComponents: RegisteredComponents;
|
|
9
|
+
model: string;
|
|
9
10
|
}) => RegisteredComponent | null | undefined;
|
|
10
11
|
export declare const getRepeatItemData: ({ block, context }: {
|
|
11
12
|
block: BuilderBlock;
|
|
@@ -20,8 +21,10 @@ export declare const provideLinkComponent: (block: RegisteredComponent | null |
|
|
|
20
21
|
} | {
|
|
21
22
|
builderLinkComponent?: undefined;
|
|
22
23
|
};
|
|
23
|
-
export declare const provideRegisteredComponents: (block: RegisteredComponent | null | undefined, registeredComponents: RegisteredComponents) => {
|
|
24
|
-
builderComponents:
|
|
24
|
+
export declare const provideRegisteredComponents: (block: RegisteredComponent | null | undefined, registeredComponents: RegisteredComponents, model: string) => {
|
|
25
|
+
builderComponents: {
|
|
26
|
+
[k: string]: RegisteredComponent;
|
|
27
|
+
};
|
|
25
28
|
} | {
|
|
26
29
|
builderComponents?: undefined;
|
|
27
30
|
};
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { evaluate } from '../../functions/evaluate/index';
|
|
2
2
|
import { extractTextStyles } from '../../functions/extract-text-styles';
|
|
3
3
|
import { getStyle } from '../../functions/get-style';
|
|
4
|
-
|
|
4
|
+
const checkIsComponentRestricted = (component, model) => {
|
|
5
|
+
if (!component)
|
|
6
|
+
return true;
|
|
7
|
+
if (!model)
|
|
8
|
+
return false;
|
|
9
|
+
return component.models && component.models.length > 0 && !component.models.includes(model);
|
|
10
|
+
};
|
|
11
|
+
export const getComponent = ({ block, registeredComponents, model }) => {
|
|
5
12
|
const componentName = block.component?.name;
|
|
6
13
|
if (!componentName) {
|
|
7
14
|
return null;
|
|
8
15
|
}
|
|
9
16
|
const ref = registeredComponents[componentName];
|
|
10
|
-
if (!ref) {
|
|
17
|
+
if (!ref || checkIsComponentRestricted(ref, model)) {
|
|
11
18
|
// TODO: Public doc page with more info about this message
|
|
12
19
|
console.warn(`
|
|
13
20
|
Could not find a registered component named "${componentName}".
|
|
@@ -71,11 +78,15 @@ export const provideLinkComponent = (block, linkComponent) => {
|
|
|
71
78
|
};
|
|
72
79
|
return {};
|
|
73
80
|
};
|
|
74
|
-
export const provideRegisteredComponents = (block, registeredComponents) => {
|
|
75
|
-
if (block?.shouldReceiveBuilderProps?.builderComponents)
|
|
81
|
+
export const provideRegisteredComponents = (block, registeredComponents, model) => {
|
|
82
|
+
if (block?.shouldReceiveBuilderProps?.builderComponents) {
|
|
83
|
+
const filteredRegisteredComponents = Object.fromEntries(Object.entries(registeredComponents).filter(([_, component]) => {
|
|
84
|
+
return !checkIsComponentRestricted(component, model);
|
|
85
|
+
}));
|
|
76
86
|
return {
|
|
77
|
-
builderComponents:
|
|
87
|
+
builderComponents: filteredRegisteredComponents
|
|
78
88
|
};
|
|
89
|
+
}
|
|
79
90
|
return {};
|
|
80
91
|
};
|
|
81
92
|
export const provideBuilderBlock = (block, builderBlock) => {
|