@builder.io/sdk-svelte 3.0.0 → 3.0.2
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/text/text.svelte +2 -15
- package/lib/browser/blocks/text/text.svelte.d.ts +0 -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 +3 -3
- 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 +37 -8
- package/lib/browser/components/content/components/enable-editor.svelte.d.ts +1 -1
- 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/evaluate/edge-runtime/edge-runtime.js +1 -4
- 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-block-component-options.d.ts +2 -1
- package/lib/browser/functions/get-block-component-options.js +18 -2
- package/lib/browser/functions/get-content/generate-content-url.js +28 -3
- package/lib/browser/functions/get-processed-block.d.ts +1 -6
- package/lib/browser/functions/get-processed-block.js +11 -14
- 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/helpers/flatten.d.ts +6 -0
- package/lib/browser/helpers/flatten.js +23 -0
- package/lib/browser/server-index.d.ts +1 -1
- 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/text/text.svelte +2 -15
- package/lib/edge/blocks/text/text.svelte.d.ts +0 -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 +3 -3
- 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 +37 -8
- package/lib/edge/components/content/components/enable-editor.svelte.d.ts +1 -1
- 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/evaluate/edge-runtime/edge-runtime.js +1 -4
- 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-block-component-options.d.ts +2 -1
- package/lib/edge/functions/get-block-component-options.js +18 -2
- package/lib/edge/functions/get-content/generate-content-url.js +28 -3
- package/lib/edge/functions/get-processed-block.d.ts +1 -6
- package/lib/edge/functions/get-processed-block.js +11 -14
- 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/helpers/flatten.d.ts +6 -0
- package/lib/edge/helpers/flatten.js +23 -0
- package/lib/edge/server-index.d.ts +1 -1
- 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/text/text.svelte +2 -15
- package/lib/node/blocks/text/text.svelte.d.ts +0 -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 +3 -3
- 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 +37 -8
- package/lib/node/components/content/components/enable-editor.svelte.d.ts +1 -1
- 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/evaluate/edge-runtime/edge-runtime.js +1 -4
- 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-block-component-options.d.ts +2 -1
- package/lib/node/functions/get-block-component-options.js +18 -2
- package/lib/node/functions/get-content/generate-content-url.js +28 -3
- package/lib/node/functions/get-processed-block.d.ts +1 -6
- package/lib/node/functions/get-processed-block.js +11 -14
- 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/helpers/flatten.d.ts +6 -0
- package/lib/node/helpers/flatten.js +23 -0
- package/lib/node/server-index.d.ts +1 -1
- 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/text/text.svelte +1 -24
- package/src/blocks/video/component-info.ts +3 -2
- package/src/components/block/block.helpers.ts +18 -6
- package/src/components/block/block.svelte +7 -3
- package/src/components/content/components/enable-editor.helpers.ts +18 -0
- package/src/components/content/components/enable-editor.svelte +40 -8
- 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/evaluate/edge-runtime/edge-runtime.ts +1 -5
- package/src/functions/extract-localized-values.ts +38 -0
- package/src/functions/get-block-component-options.ts +19 -2
- package/src/functions/get-content/generate-content-url.ts +30 -3
- package/src/functions/get-processed-block.ts +10 -18
- package/src/functions/register-component.ts +4 -1
- package/src/functions/traverse.ts +64 -0
- package/src/helpers/flatten.ts +23 -0
- package/src/server-index.ts +1 -1
- package/src/types/components.ts +3 -0
|
@@ -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,6 +1,4 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
export let builderContext;
|
|
3
|
-
export let text = undefined;
|
|
1
|
+
<script>export let text = undefined;
|
|
4
2
|
function stringifyStyles(stylesObj) {
|
|
5
3
|
let styles = "";
|
|
6
4
|
for (let key in stylesObj) {
|
|
@@ -11,17 +9,6 @@ function stringifyStyles(stylesObj) {
|
|
|
11
9
|
}
|
|
12
10
|
return styles;
|
|
13
11
|
}
|
|
14
|
-
$: processedText = () => {
|
|
15
|
-
const context = $builderContext;
|
|
16
|
-
const { context: contextContext, localState, rootState, rootSetState, } = context;
|
|
17
|
-
return String(text?.toString() || "").replace(/{{([^}]+)}}/g, (match, group) => evaluate({
|
|
18
|
-
code: group,
|
|
19
|
-
context: contextContext,
|
|
20
|
-
localState,
|
|
21
|
-
rootState,
|
|
22
|
-
rootSetState,
|
|
23
|
-
}));
|
|
24
|
-
};
|
|
25
12
|
</script>
|
|
26
13
|
|
|
27
14
|
<div
|
|
@@ -30,5 +17,5 @@ $: processedText = () => {
|
|
|
30
17
|
})}
|
|
31
18
|
class="builder-text"
|
|
32
19
|
>
|
|
33
|
-
{@html
|
|
20
|
+
{@html text?.toString() || ""}
|
|
34
21
|
</div>
|
|
@@ -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) => {
|
|
@@ -31,7 +31,6 @@ $: processedBlock = () => {
|
|
|
31
31
|
rootState: $context.rootState,
|
|
32
32
|
rootSetState: $context.rootSetState,
|
|
33
33
|
context: $context.context,
|
|
34
|
-
shouldEvaluateBindings: true,
|
|
35
34
|
});
|
|
36
35
|
return blockToUse;
|
|
37
36
|
};
|
|
@@ -39,6 +38,7 @@ $: blockComponent = () => {
|
|
|
39
38
|
return getComponent({
|
|
40
39
|
block: processedBlock(),
|
|
41
40
|
registeredComponents: registeredComponents,
|
|
41
|
+
model: $context.model,
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
44
|
$: Tag = () => {
|
|
@@ -77,11 +77,11 @@ $: componentRefProps = () => {
|
|
|
77
77
|
blockChildren: processedBlock().children ?? [],
|
|
78
78
|
componentRef: blockComponent?.()?.component,
|
|
79
79
|
componentOptions: {
|
|
80
|
-
...getBlockComponentOptions(processedBlock()),
|
|
80
|
+
...getBlockComponentOptions(processedBlock(), $context),
|
|
81
81
|
...provideBuilderBlock(blockComponent(), processedBlock()),
|
|
82
82
|
...provideBuilderContext(blockComponent(), context),
|
|
83
83
|
...provideLinkComponent(blockComponent(), linkComponent),
|
|
84
|
-
...provideRegisteredComponents(blockComponent(), registeredComponents),
|
|
84
|
+
...provideRegisteredComponents(blockComponent(), registeredComponents, $context.model),
|
|
85
85
|
},
|
|
86
86
|
context: context,
|
|
87
87
|
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;
|
|
@@ -29,11 +30,21 @@ export let enrich = undefined;
|
|
|
29
30
|
export let trustedHosts = undefined;
|
|
30
31
|
export let model = undefined;
|
|
31
32
|
export let content = undefined;
|
|
33
|
+
export let context = undefined;
|
|
32
34
|
export let data = undefined;
|
|
33
35
|
export let showContent;
|
|
34
36
|
export let contentWrapper = undefined;
|
|
35
|
-
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
|
}
|
|
@@ -197,13 +212,21 @@ function elementRef_onInitpreviewingbldr(event) {
|
|
|
197
212
|
*
|
|
198
213
|
* TO-DO: should we only update the state when there is a change?
|
|
199
214
|
**/
|
|
200
|
-
if (searchParamPreviewModel ===
|
|
201
|
-
|
|
202
|
-
|
|
215
|
+
if (searchParamPreviewModel === "BUILDER_STUDIO" ||
|
|
216
|
+
(searchParamPreviewModel === model &&
|
|
217
|
+
previewApiKey === apiKey &&
|
|
218
|
+
(!content || searchParamPreviewId === content.id))) {
|
|
203
219
|
fetchOneEntry({
|
|
204
|
-
model: model,
|
|
220
|
+
model: model || "",
|
|
205
221
|
apiKey: apiKey,
|
|
206
222
|
apiVersion: $builderContextSignal.apiVersion,
|
|
223
|
+
...(searchParamPreviewModel === "BUILDER_STUDIO" && context?.symbolId
|
|
224
|
+
? {
|
|
225
|
+
query: {
|
|
226
|
+
id: context.symbolId,
|
|
227
|
+
},
|
|
228
|
+
}
|
|
229
|
+
: {}),
|
|
207
230
|
}).then((content) => {
|
|
208
231
|
if (content) {
|
|
209
232
|
mergeNewContent(content);
|
|
@@ -293,9 +316,15 @@ onDestroy(() => {
|
|
|
293
316
|
});
|
|
294
317
|
</script>
|
|
295
318
|
|
|
296
|
-
{#if $builderContextSignal.content}
|
|
319
|
+
{#if $builderContextSignal.content || needsElementRefDivForEditing()}
|
|
297
320
|
<svelte:element
|
|
298
321
|
this={ContentWrapper}
|
|
322
|
+
style={stringifyStyles({
|
|
323
|
+
display:
|
|
324
|
+
!$builderContextSignal.content && needsElementRefDivForEditing()
|
|
325
|
+
? "none"
|
|
326
|
+
: undefined,
|
|
327
|
+
})}
|
|
299
328
|
{...{}}
|
|
300
329
|
bind:this={elementRef}
|
|
301
330
|
on:click={(event) => {
|
|
@@ -19,10 +19,10 @@ declare const __propDef: {
|
|
|
19
19
|
trustedHosts?: BuilderEditorProps["trustedHosts"];
|
|
20
20
|
model?: BuilderEditorProps["model"];
|
|
21
21
|
content?: BuilderEditorProps["content"];
|
|
22
|
+
context?: BuilderEditorProps["context"];
|
|
22
23
|
data?: BuilderEditorProps["data"];
|
|
23
24
|
showContent: BuilderEditorProps["showContent"];
|
|
24
25
|
contentWrapper?: BuilderEditorProps["contentWrapper"];
|
|
25
|
-
context?: BuilderEditorProps["context"];
|
|
26
26
|
contentWrapperProps?: BuilderEditorProps["contentWrapperProps"];
|
|
27
27
|
};
|
|
28
28
|
events: {
|
|
@@ -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 = "3.0.
|
|
1
|
+
export declare const SDK_VERSION = "3.0.2";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "3.0.
|
|
1
|
+
export const SDK_VERSION = "3.0.2";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { logger } from '../../../helpers/logger';
|
|
2
1
|
import { flattenState, getFunctionArguments } from '../helpers';
|
|
3
2
|
import Interpreter from './acorn-interpreter';
|
|
4
3
|
/**
|
|
@@ -84,10 +83,8 @@ export const runInEdge = ({ builder, context, event, rootState, localState, root
|
|
|
84
83
|
return `var ${key} = ${jsonValName} === undefined ? undefined : JSON.parse(${jsonValName});`;
|
|
85
84
|
}).join('\n');
|
|
86
85
|
const cleanedCode = processCode(code);
|
|
87
|
-
if (cleanedCode === '')
|
|
88
|
-
logger.warn('Skipping evaluation of empty code block.');
|
|
86
|
+
if (cleanedCode === '')
|
|
89
87
|
return;
|
|
90
|
-
}
|
|
91
88
|
const transformed = `
|
|
92
89
|
function theFunction() {
|
|
93
90
|
${prependedCode}
|
|
@@ -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
|
+
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import type { BuilderContextInterface } from '../context/types';
|
|
1
2
|
import type { BuilderBlock } from '../types/builder-block';
|
|
2
|
-
export declare function getBlockComponentOptions(block: BuilderBlock): any;
|
|
3
|
+
export declare function getBlockComponentOptions(block: BuilderBlock, context: Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): any;
|
|
@@ -1,6 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
import { evaluate } from './evaluate/evaluate';
|
|
2
|
+
export function getBlockComponentOptions(block, context) {
|
|
2
3
|
return {
|
|
3
4
|
...block.component?.options,
|
|
4
|
-
...block.options
|
|
5
|
+
...block.options,
|
|
6
|
+
...evaluateTextComponentTextOption(block, context)
|
|
5
7
|
};
|
|
6
8
|
}
|
|
9
|
+
const evaluateTextComponentTextOption = (block, context) => {
|
|
10
|
+
if (block.component?.name === 'Text' && block.component.options?.text && typeof block.component.options.text === 'string') {
|
|
11
|
+
return {
|
|
12
|
+
...block.component.options,
|
|
13
|
+
text: block.component.options.text.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
|
|
14
|
+
code: group,
|
|
15
|
+
context,
|
|
16
|
+
localState: context.localState,
|
|
17
|
+
rootState: context.rootState,
|
|
18
|
+
rootSetState: context.rootSetState
|
|
19
|
+
}))
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { flatten, flattenMongoQuery } from '../../helpers/flatten';
|
|
1
|
+
import { flatten, flattenMongoQuery, unflatten } from '../../helpers/flatten';
|
|
2
2
|
import { normalizeSearchParams } from '../../helpers/search/search';
|
|
3
3
|
import { DEFAULT_API_VERSION } from '../../types/api-version';
|
|
4
4
|
import { getBuilderSearchParamsFromWindow } from '../get-builder-search-params/index';
|
|
5
|
+
import { isBrowser } from '../is-browser';
|
|
5
6
|
const isPositiveNumber = (thing) => typeof thing === 'number' && !isNaN(thing) && thing >= 0;
|
|
6
7
|
export const generateContentUrl = (options) => {
|
|
7
8
|
const { limit = 30, userAttributes, query, model, apiKey, enrich, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished, apiHost } = options;
|
|
@@ -20,7 +21,7 @@ export const generateContentUrl = (options) => {
|
|
|
20
21
|
url.searchParams.set('noTraverse', String(noTraverse));
|
|
21
22
|
url.searchParams.set('includeRefs', String(true));
|
|
22
23
|
const finalLocale = locale || userAttributes?.locale;
|
|
23
|
-
let finalUserAttributes = userAttributes;
|
|
24
|
+
let finalUserAttributes = userAttributes || {};
|
|
24
25
|
if (finalLocale) {
|
|
25
26
|
url.searchParams.set('locale', finalLocale);
|
|
26
27
|
finalUserAttributes = {
|
|
@@ -59,11 +60,15 @@ export const generateContentUrl = (options) => {
|
|
|
59
60
|
...getBuilderSearchParamsFromWindow(),
|
|
60
61
|
...normalizeSearchParams(options.options || {})
|
|
61
62
|
};
|
|
63
|
+
finalUserAttributes = {
|
|
64
|
+
...finalUserAttributes,
|
|
65
|
+
...getUserAttributesAsJSON(queryOptions)
|
|
66
|
+
};
|
|
62
67
|
const flattened = flatten(queryOptions);
|
|
63
68
|
for (const key in flattened) {
|
|
64
69
|
url.searchParams.set(key, String(flattened[key]));
|
|
65
70
|
}
|
|
66
|
-
if (finalUserAttributes) {
|
|
71
|
+
if (Object.keys(finalUserAttributes).length > 0) {
|
|
67
72
|
url.searchParams.set('userAttributes', JSON.stringify(finalUserAttributes));
|
|
68
73
|
}
|
|
69
74
|
if (query) {
|
|
@@ -76,3 +81,23 @@ export const generateContentUrl = (options) => {
|
|
|
76
81
|
}
|
|
77
82
|
return url;
|
|
78
83
|
};
|
|
84
|
+
const getUserAttributesFromQueryOptions = (queryOptions) => {
|
|
85
|
+
const newUserAttributes = {};
|
|
86
|
+
for (const key in queryOptions) {
|
|
87
|
+
if (key.startsWith('userAttributes.')) {
|
|
88
|
+
newUserAttributes[key] = queryOptions[key];
|
|
89
|
+
delete queryOptions[key];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return newUserAttributes;
|
|
93
|
+
};
|
|
94
|
+
const getUserAttributesAsJSON = (queryOptions) => {
|
|
95
|
+
if (isBrowser() && queryOptions['preview'] === 'BUILDER_STUDIO') {
|
|
96
|
+
queryOptions['userAttributes.urlPath'] = window.location.pathname;
|
|
97
|
+
queryOptions['userAttributes.host'] = window.location.host;
|
|
98
|
+
const queryOptionsForUserAttributes = getUserAttributesFromQueryOptions(queryOptions);
|
|
99
|
+
const { userAttributes } = unflatten(queryOptionsForUserAttributes);
|
|
100
|
+
return userAttributes;
|
|
101
|
+
}
|
|
102
|
+
return {};
|
|
103
|
+
};
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import type { BuilderContextInterface } from '../context/types';
|
|
2
2
|
import type { BuilderBlock } from '../types/builder-block';
|
|
3
3
|
export declare function deepCloneWithConditions<T = any>(obj: T): T;
|
|
4
|
-
export declare function getProcessedBlock({ block, context,
|
|
4
|
+
export declare function getProcessedBlock({ block, context, localState, rootState, rootSetState }: {
|
|
5
5
|
block: BuilderBlock;
|
|
6
|
-
/**
|
|
7
|
-
* In some cases, we want to avoid evaluating bindings and only want framework-specific block transformation. It is
|
|
8
|
-
* also sometimes too early to consider bindings, e.g. when we might be looking at a repeated block.
|
|
9
|
-
*/
|
|
10
|
-
shouldEvaluateBindings: boolean;
|
|
11
6
|
} & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): BuilderBlock;
|
|
@@ -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';
|
|
@@ -71,18 +72,14 @@ const evaluateBindings = ({ block, context, localState, rootState, rootSetState
|
|
|
71
72
|
}
|
|
72
73
|
return copied;
|
|
73
74
|
};
|
|
74
|
-
export function getProcessedBlock({ block, context,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
return transformedBlock;
|
|
87
|
-
}
|
|
75
|
+
export function getProcessedBlock({ block, context, localState, rootState, rootSetState }) {
|
|
76
|
+
let transformedBlock = resolveLocalizedValues(block, rootState.locale);
|
|
77
|
+
transformedBlock = transformBlock(transformedBlock);
|
|
78
|
+
return evaluateBindings({
|
|
79
|
+
block: transformedBlock,
|
|
80
|
+
localState,
|
|
81
|
+
rootState,
|
|
82
|
+
rootSetState,
|
|
83
|
+
context
|
|
84
|
+
});
|
|
88
85
|
}
|