@builder.io/sdk-svelte 0.12.0 → 0.12.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/slot/component-info.d.ts +2 -0
- package/lib/browser/blocks/slot/component-info.js +14 -0
- package/lib/browser/blocks/slot/slot.svelte +33 -0
- package/lib/browser/blocks/slot/slot.svelte.d.ts +26 -0
- package/lib/browser/blocks/symbol/symbol.svelte +5 -1
- package/lib/browser/blocks/symbol/symbol.svelte.d.ts +1 -0
- package/lib/browser/components/block/block.helpers.d.ts +0 -1
- package/lib/browser/components/block/block.helpers.js +0 -7
- package/lib/browser/components/block/block.svelte +11 -27
- package/lib/browser/components/block/components/block-wrapper.svelte +18 -44
- package/lib/browser/components/block/components/block-wrapper.svelte.d.ts +0 -5
- package/lib/browser/components/content/components/enable-editor.svelte +10 -0
- package/lib/browser/components/content/components/enable-editor.svelte.d.ts +1 -0
- package/lib/browser/components/content/content.svelte +2 -0
- package/lib/browser/components/content/content.svelte.d.ts +1 -0
- package/lib/browser/components/content-variants/content-variants.svelte +3 -0
- package/lib/browser/components/content-variants/content-variants.svelte.d.ts +1 -0
- package/lib/browser/components/content-variants/content-variants.types.d.ts +4 -0
- package/lib/browser/components/dynamic-renderer/dynamic-renderer.helpers.d.ts +1 -0
- package/lib/browser/components/dynamic-renderer/dynamic-renderer.helpers.js +7 -0
- package/lib/browser/components/dynamic-renderer/dynamic-renderer.svelte +28 -0
- package/lib/browser/components/dynamic-renderer/dynamic-renderer.svelte.d.ts +21 -0
- package/lib/browser/constants/builder-registered-components.js +5 -0
- package/lib/browser/constants/sdk-version.d.ts +1 -1
- package/lib/browser/constants/sdk-version.js +1 -1
- package/lib/browser/functions/is-from-trusted-host.d.ts +3 -0
- package/lib/browser/functions/is-from-trusted-host.js +5 -0
- package/lib/browser/scripts/init-editing.d.ts +1 -0
- package/lib/browser/scripts/init-editing.js +6 -1
- package/lib/edge/blocks/slot/component-info.d.ts +2 -0
- package/lib/edge/blocks/slot/component-info.js +14 -0
- package/lib/edge/blocks/slot/slot.svelte +33 -0
- package/lib/edge/blocks/slot/slot.svelte.d.ts +26 -0
- package/lib/edge/blocks/symbol/symbol.svelte +5 -1
- package/lib/edge/blocks/symbol/symbol.svelte.d.ts +1 -0
- package/lib/edge/components/block/block.helpers.d.ts +0 -1
- package/lib/edge/components/block/block.helpers.js +0 -7
- package/lib/edge/components/block/block.svelte +11 -27
- package/lib/edge/components/block/components/block-wrapper.svelte +18 -44
- package/lib/edge/components/block/components/block-wrapper.svelte.d.ts +0 -5
- package/lib/edge/components/content/components/enable-editor.svelte +10 -0
- package/lib/edge/components/content/components/enable-editor.svelte.d.ts +1 -0
- package/lib/edge/components/content/content.svelte +2 -0
- package/lib/edge/components/content/content.svelte.d.ts +1 -0
- package/lib/edge/components/content-variants/content-variants.svelte +3 -0
- package/lib/edge/components/content-variants/content-variants.svelte.d.ts +1 -0
- package/lib/edge/components/content-variants/content-variants.types.d.ts +4 -0
- package/lib/edge/components/dynamic-renderer/dynamic-renderer.helpers.d.ts +1 -0
- package/lib/edge/components/dynamic-renderer/dynamic-renderer.helpers.js +7 -0
- package/lib/edge/components/dynamic-renderer/dynamic-renderer.svelte +28 -0
- package/lib/edge/components/dynamic-renderer/dynamic-renderer.svelte.d.ts +21 -0
- package/lib/edge/constants/builder-registered-components.js +5 -0
- package/lib/edge/constants/sdk-version.d.ts +1 -1
- package/lib/edge/constants/sdk-version.js +1 -1
- package/lib/edge/functions/is-from-trusted-host.d.ts +3 -0
- package/lib/edge/functions/is-from-trusted-host.js +5 -0
- package/lib/edge/scripts/init-editing.d.ts +1 -0
- package/lib/edge/scripts/init-editing.js +6 -1
- package/lib/node/blocks/slot/component-info.d.ts +2 -0
- package/lib/node/blocks/slot/component-info.js +14 -0
- package/lib/node/blocks/slot/slot.svelte +33 -0
- package/lib/node/blocks/slot/slot.svelte.d.ts +26 -0
- package/lib/node/blocks/symbol/symbol.svelte +5 -1
- package/lib/node/blocks/symbol/symbol.svelte.d.ts +1 -0
- package/lib/node/components/block/block.helpers.d.ts +0 -1
- package/lib/node/components/block/block.helpers.js +0 -7
- package/lib/node/components/block/block.svelte +11 -27
- package/lib/node/components/block/components/block-wrapper.svelte +18 -44
- package/lib/node/components/block/components/block-wrapper.svelte.d.ts +0 -5
- package/lib/node/components/content/components/enable-editor.svelte +10 -0
- package/lib/node/components/content/components/enable-editor.svelte.d.ts +1 -0
- package/lib/node/components/content/content.svelte +2 -0
- package/lib/node/components/content/content.svelte.d.ts +1 -0
- package/lib/node/components/content-variants/content-variants.svelte +3 -0
- package/lib/node/components/content-variants/content-variants.svelte.d.ts +1 -0
- package/lib/node/components/content-variants/content-variants.types.d.ts +4 -0
- package/lib/node/components/dynamic-renderer/dynamic-renderer.helpers.d.ts +1 -0
- package/lib/node/components/dynamic-renderer/dynamic-renderer.helpers.js +7 -0
- package/lib/node/components/dynamic-renderer/dynamic-renderer.svelte +28 -0
- package/lib/node/components/dynamic-renderer/dynamic-renderer.svelte.d.ts +21 -0
- package/lib/node/constants/builder-registered-components.js +5 -0
- package/lib/node/constants/sdk-version.d.ts +1 -1
- package/lib/node/constants/sdk-version.js +1 -1
- package/lib/node/functions/is-from-trusted-host.d.ts +3 -0
- package/lib/node/functions/is-from-trusted-host.js +5 -0
- package/lib/node/scripts/init-editing.d.ts +1 -0
- package/lib/node/scripts/init-editing.js +6 -1
- package/package.json +1 -1
- package/src/blocks/slot/component-info.ts +15 -0
- package/src/blocks/slot/slot.svelte +45 -0
- package/src/blocks/symbol/symbol.svelte +5 -1
- package/src/components/block/block.helpers.ts +0 -8
- package/src/components/block/block.svelte +11 -31
- package/src/components/block/components/block-wrapper.svelte +18 -46
- package/src/components/content/components/enable-editor.svelte +10 -0
- package/src/components/content/content.svelte +2 -0
- package/src/components/content-variants/content-variants.svelte +3 -0
- package/src/components/content-variants/content-variants.types.ts +5 -0
- package/src/components/dynamic-renderer/dynamic-renderer.helpers.ts +7 -0
- package/src/components/dynamic-renderer/dynamic-renderer.svelte +43 -0
- package/src/constants/builder-registered-components.ts +5 -0
- package/src/constants/sdk-version.ts +1 -1
- package/src/functions/is-from-trusted-host.ts +8 -0
- package/src/scripts/init-editing.ts +9 -3
|
@@ -1,56 +1,30 @@
|
|
|
1
1
|
<script context="module">/**
|
|
2
|
-
* This import is used by the Svelte SDK. Do not remove.
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
2
|
* This component renders a block's wrapper HTML element (from the block's `tagName` property).
|
|
6
|
-
* It reuses the exact same logic as the `InteractiveElement` component, but we need to have 2 separate components for
|
|
7
|
-
* Svelte's sake, as it needs to know at compile-time whether to use:
|
|
8
|
-
* - `<svelte:element>` (for HTML element) or
|
|
9
|
-
* - `<svelte:component>` (for custom components)
|
|
10
3
|
*/
|
|
11
4
|
</script>
|
|
12
5
|
|
|
13
6
|
<script>import { getBlockActions } from "../../../functions/get-block-actions.js";
|
|
14
7
|
import { getBlockProperties } from "../../../functions/get-block-properties.js";
|
|
15
|
-
import
|
|
8
|
+
import DynamicRenderer from "../../dynamic-renderer/dynamic-renderer.svelte";
|
|
16
9
|
export let Wrapper;
|
|
17
10
|
export let block;
|
|
18
11
|
export let context;
|
|
19
|
-
export let hasChildren;
|
|
20
12
|
</script>
|
|
21
13
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
</svelte:element>
|
|
40
|
-
{:else}
|
|
41
|
-
<svelte:element
|
|
42
|
-
this={Wrapper}
|
|
43
|
-
{...getBlockProperties({
|
|
44
|
-
block: block,
|
|
45
|
-
context: $context,
|
|
46
|
-
})}
|
|
47
|
-
use:setAttrs={getBlockActions({
|
|
48
|
-
block: block,
|
|
49
|
-
rootState: $context.rootState,
|
|
50
|
-
rootSetState: $context.rootSetState,
|
|
51
|
-
localState: $context.localState,
|
|
52
|
-
context: $context.context,
|
|
53
|
-
stripPrefix: true,
|
|
54
|
-
})}
|
|
55
|
-
/>
|
|
56
|
-
{/if}
|
|
14
|
+
<DynamicRenderer
|
|
15
|
+
TagName={Wrapper}
|
|
16
|
+
attributes={getBlockProperties({
|
|
17
|
+
block: block,
|
|
18
|
+
context: $context,
|
|
19
|
+
})}
|
|
20
|
+
actionAttributes={getBlockActions({
|
|
21
|
+
block: block,
|
|
22
|
+
rootState: $context.rootState,
|
|
23
|
+
rootSetState: $context.rootSetState,
|
|
24
|
+
localState: $context.localState,
|
|
25
|
+
context: $context.context,
|
|
26
|
+
stripPrefix: true,
|
|
27
|
+
})}
|
|
28
|
+
>
|
|
29
|
+
<slot />
|
|
30
|
+
</DynamicRenderer>
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
|
-
/**
|
|
3
|
-
* This import is used by the Svelte SDK. Do not remove.
|
|
4
|
-
*/
|
|
5
2
|
type BlockWrapperProps = {
|
|
6
3
|
Wrapper: string;
|
|
7
4
|
block: BuilderBlock;
|
|
8
5
|
context: Writable<BuilderContextInterface>;
|
|
9
|
-
hasChildren: boolean;
|
|
10
6
|
};
|
|
11
7
|
import type { BuilderContextInterface } from "../../../context/types.js";
|
|
12
8
|
import type { BuilderBlock } from "../../../types/builder-block.js";
|
|
@@ -17,7 +13,6 @@ declare const __propDef: {
|
|
|
17
13
|
Wrapper: PropsWithChildren<BlockWrapperProps>["Wrapper"];
|
|
18
14
|
block: PropsWithChildren<BlockWrapperProps>["block"];
|
|
19
15
|
context: PropsWithChildren<BlockWrapperProps>["context"];
|
|
20
|
-
hasChildren: PropsWithChildren<BlockWrapperProps>["hasChildren"];
|
|
21
16
|
};
|
|
22
17
|
events: {
|
|
23
18
|
[evt: string]: CustomEvent<any>;
|
|
@@ -8,6 +8,7 @@ import { fetchOneEntry } from "../../../functions/get-content/index.js";
|
|
|
8
8
|
import { fetch } from "../../../functions/get-fetch.js";
|
|
9
9
|
import { isBrowser } from "../../../functions/is-browser.js";
|
|
10
10
|
import { isEditing } from "../../../functions/is-editing.js";
|
|
11
|
+
import { isFromTrustedHost } from "../../../functions/is-from-trusted-host.js";
|
|
11
12
|
import { isPreviewing } from "../../../functions/is-previewing.js";
|
|
12
13
|
import { createRegisterComponentMessage } from "../../../functions/register-component.js";
|
|
13
14
|
import { _track } from "../../../functions/track/index.js";
|
|
@@ -18,6 +19,7 @@ import "../../../helpers/preview-lru-cache/set.js";
|
|
|
18
19
|
import { registerInsertMenu, setupBrowserForEditing, } from "../../../scripts/init-editing.js";
|
|
19
20
|
export let builderContextSignal;
|
|
20
21
|
export let contentWrapper = undefined;
|
|
22
|
+
export let trustedHosts = undefined;
|
|
21
23
|
export let model = undefined;
|
|
22
24
|
export let context = undefined;
|
|
23
25
|
export let canTrack = undefined;
|
|
@@ -59,6 +61,9 @@ function mergeNewContent(newContent) {
|
|
|
59
61
|
$builderContextSignal.content = newContentValue;
|
|
60
62
|
}
|
|
61
63
|
function processMessage(event) {
|
|
64
|
+
if (!isFromTrustedHost(trustedHosts, event)) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
62
67
|
const { data } = event;
|
|
63
68
|
if (data) {
|
|
64
69
|
switch (data.type) {
|
|
@@ -193,6 +198,11 @@ function elementRef_onIniteditingbldr(event) {
|
|
|
193
198
|
enrich: enrich,
|
|
194
199
|
}
|
|
195
200
|
: {}),
|
|
201
|
+
...(trustedHosts
|
|
202
|
+
? {
|
|
203
|
+
trustedHosts: trustedHosts,
|
|
204
|
+
}
|
|
205
|
+
: {}),
|
|
196
206
|
});
|
|
197
207
|
Object.values($builderContextSignal.componentInfos).forEach((registeredComponent) => {
|
|
198
208
|
const message = createRegisterComponentMessage(registeredComponent);
|
|
@@ -11,6 +11,7 @@ declare const __propDef: {
|
|
|
11
11
|
props: {
|
|
12
12
|
builderContextSignal: BuilderEditorProps["builderContextSignal"];
|
|
13
13
|
contentWrapper?: BuilderEditorProps["contentWrapper"];
|
|
14
|
+
trustedHosts?: BuilderEditorProps["trustedHosts"];
|
|
14
15
|
model?: BuilderEditorProps["model"];
|
|
15
16
|
context?: BuilderEditorProps["context"];
|
|
16
17
|
canTrack?: BuilderEditorProps["canTrack"];
|
|
@@ -27,6 +27,7 @@ export let enrich = undefined;
|
|
|
27
27
|
export let showContent;
|
|
28
28
|
export let contentWrapper = undefined;
|
|
29
29
|
export let contentWrapperProps = undefined;
|
|
30
|
+
export let trustedHosts = undefined;
|
|
30
31
|
export let isSsrAbTest;
|
|
31
32
|
function contentSetState(newRootState) {
|
|
32
33
|
$builderContextSignal.rootState = newRootState;
|
|
@@ -104,6 +105,7 @@ setContext(ComponentsContext.key, {
|
|
|
104
105
|
{builderContextSignal}
|
|
105
106
|
{contentWrapper}
|
|
106
107
|
{contentWrapperProps}
|
|
108
|
+
{trustedHosts}
|
|
107
109
|
{...{}}
|
|
108
110
|
>
|
|
109
111
|
{#if isSsrAbTest}
|
|
@@ -18,6 +18,7 @@ declare const __propDef: {
|
|
|
18
18
|
showContent: ContentProps["showContent"];
|
|
19
19
|
contentWrapper?: ContentProps["contentWrapper"];
|
|
20
20
|
contentWrapperProps?: ContentProps["contentWrapperProps"];
|
|
21
|
+
trustedHosts?: ContentProps["trustedHosts"];
|
|
21
22
|
isSsrAbTest: ContentProps["isSsrAbTest"];
|
|
22
23
|
};
|
|
23
24
|
events: {
|
|
@@ -24,6 +24,7 @@ export let blocksWrapper = undefined;
|
|
|
24
24
|
export let blocksWrapperProps = undefined;
|
|
25
25
|
export let contentWrapper = undefined;
|
|
26
26
|
export let contentWrapperProps = undefined;
|
|
27
|
+
export let trustedHosts = undefined;
|
|
27
28
|
$: updateCookieAndStylesScriptStr = () => {
|
|
28
29
|
return getUpdateCookieAndStylesScript(getVariants(content).map((value) => ({
|
|
29
30
|
id: value.testVariationId,
|
|
@@ -89,6 +90,7 @@ onMount(() => {
|
|
|
89
90
|
{blocksWrapperProps}
|
|
90
91
|
{contentWrapper}
|
|
91
92
|
{contentWrapperProps}
|
|
93
|
+
{trustedHosts}
|
|
92
94
|
/>
|
|
93
95
|
{/each}
|
|
94
96
|
{/if}
|
|
@@ -112,4 +114,5 @@ onMount(() => {
|
|
|
112
114
|
{blocksWrapperProps}
|
|
113
115
|
{contentWrapper}
|
|
114
116
|
{contentWrapperProps}
|
|
117
|
+
{trustedHosts}
|
|
115
118
|
/>
|
|
@@ -24,6 +24,7 @@ declare const __propDef: {
|
|
|
24
24
|
blocksWrapperProps?: VariantsProviderProps["blocksWrapperProps"];
|
|
25
25
|
contentWrapper?: VariantsProviderProps["contentWrapper"];
|
|
26
26
|
contentWrapperProps?: VariantsProviderProps["contentWrapperProps"];
|
|
27
|
+
trustedHosts?: VariantsProviderProps["trustedHosts"];
|
|
27
28
|
};
|
|
28
29
|
events: {
|
|
29
30
|
[evt: string]: CustomEvent<any>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isEmptyElement: (tagName: any) => boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
|
|
3
|
+
*/
|
|
4
|
+
const EMPTY_HTML_ELEMENTS = new Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
|
|
5
|
+
export const isEmptyElement = (tagName) => {
|
|
6
|
+
return typeof tagName === 'string' && EMPTY_HTML_ELEMENTS.has(tagName.toLowerCase());
|
|
7
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<script>import { isEmptyElement } from "./dynamic-renderer.helpers.js";
|
|
2
|
+
import { setAttrs } from "../../blocks/helpers.js";
|
|
3
|
+
export let attributes;
|
|
4
|
+
export let TagName;
|
|
5
|
+
export let actionAttributes;
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
{#if !isEmptyElement(TagName)}
|
|
9
|
+
{#if typeof TagName === "string"}
|
|
10
|
+
<svelte:element
|
|
11
|
+
this={TagName}
|
|
12
|
+
{...attributes}
|
|
13
|
+
use:setAttrs={actionAttributes}
|
|
14
|
+
>
|
|
15
|
+
<slot />
|
|
16
|
+
</svelte:element>
|
|
17
|
+
{:else}
|
|
18
|
+
<svelte:component this={TagName} {...attributes} {...actionAttributes}>
|
|
19
|
+
<slot />
|
|
20
|
+
</svelte:component>
|
|
21
|
+
{/if}
|
|
22
|
+
{:else}
|
|
23
|
+
<svelte:element
|
|
24
|
+
this={TagName}
|
|
25
|
+
{...attributes}
|
|
26
|
+
use:setAttrs={actionAttributes}
|
|
27
|
+
/>
|
|
28
|
+
{/if}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { PropsWithChildren } from "../../types/typescript.js";
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
attributes: any;
|
|
6
|
+
TagName: any;
|
|
7
|
+
actionAttributes: any;
|
|
8
|
+
};
|
|
9
|
+
events: {
|
|
10
|
+
[evt: string]: CustomEvent<any>;
|
|
11
|
+
};
|
|
12
|
+
slots: {
|
|
13
|
+
default: {};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export type DynamicRendererProps = typeof __propDef.props;
|
|
17
|
+
export type DynamicRendererEvents = typeof __propDef.events;
|
|
18
|
+
export type DynamicRendererSlots = typeof __propDef.slots;
|
|
19
|
+
export default class DynamicRenderer extends SvelteComponent<DynamicRendererProps, DynamicRendererEvents, DynamicRendererSlots> {
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -14,6 +14,8 @@ import { componentInfo as imgComponentInfo } from '../blocks/img/component-info.
|
|
|
14
14
|
import { default as Img } from '../blocks/img/img.svelte';
|
|
15
15
|
import { componentInfo as sectionComponentInfo } from '../blocks/section/component-info.js';
|
|
16
16
|
import { default as Section } from '../blocks/section/section.svelte';
|
|
17
|
+
import { componentInfo as slotComponentInfo } from '../blocks/slot/component-info.js';
|
|
18
|
+
import { default as Slot } from '../blocks/slot/slot.svelte';
|
|
17
19
|
import { componentInfo as symbolComponentInfo } from '../blocks/symbol/component-info.js';
|
|
18
20
|
import { default as Symbol } from '../blocks/symbol/symbol.svelte';
|
|
19
21
|
import { componentInfo as textComponentInfo } from '../blocks/text/component-info.js';
|
|
@@ -57,4 +59,7 @@ export const getDefaultRegisteredComponents = () => [{
|
|
|
57
59
|
}, {
|
|
58
60
|
component: Video,
|
|
59
61
|
...videoComponentInfo
|
|
62
|
+
}, {
|
|
63
|
+
component: Slot,
|
|
64
|
+
...slotComponentInfo
|
|
60
65
|
}];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.12.
|
|
1
|
+
export declare const SDK_VERSION = "0.12.2";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.12.
|
|
1
|
+
export const SDK_VERSION = "0.12.2";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
const DEFAULT_TRUSTED_HOSTS = ['*.beta.builder.io', 'beta.builder.io', 'builder.io', 'localhost', 'qa.builder.io'];
|
|
2
|
+
export function isFromTrustedHost(trustedHosts, e) {
|
|
3
|
+
const url = new URL(e.origin), hostname = url.hostname;
|
|
4
|
+
return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex(trustedHost => trustedHost.startsWith('*.') ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
|
|
5
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SDK_VERSION } from '../constants/sdk-version.js';
|
|
2
2
|
import { TARGET } from '../constants/target.js';
|
|
3
3
|
import { isBrowser } from '../functions/is-browser.js';
|
|
4
|
+
import { isFromTrustedHost } from '../functions/is-from-trusted-host.js';
|
|
4
5
|
import { register } from '../functions/register.js';
|
|
5
6
|
export const registerInsertMenu = () => {
|
|
6
7
|
register('insertMenu', {
|
|
@@ -50,7 +51,11 @@ export const setupBrowserForEditing = (options = {}) => {
|
|
|
50
51
|
options
|
|
51
52
|
}
|
|
52
53
|
}, '*');
|
|
53
|
-
window.addEventListener('message', (
|
|
54
|
+
window.addEventListener('message', (event) => {
|
|
55
|
+
if (!isFromTrustedHost(options.trustedHosts, event)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const { data } = event;
|
|
54
59
|
if (!data?.type) {
|
|
55
60
|
return;
|
|
56
61
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ComponentInfo } from '../../types/components.js';
|
|
2
|
+
export const componentInfo: ComponentInfo = {
|
|
3
|
+
name: 'Slot',
|
|
4
|
+
isRSC: true,
|
|
5
|
+
description: 'Allow child blocks to be inserted into this content when used as a Symbol',
|
|
6
|
+
docsLink: 'https://www.builder.io/c/docs/symbols-with-blocks',
|
|
7
|
+
image: 'https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F3aad6de36eae43b59b52c85190fdef56',
|
|
8
|
+
// Maybe wrap this for canHaveChildren so bind children to this hm
|
|
9
|
+
inputs: [{
|
|
10
|
+
name: 'name',
|
|
11
|
+
type: 'string',
|
|
12
|
+
required: true,
|
|
13
|
+
defaultValue: 'children'
|
|
14
|
+
}]
|
|
15
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
export interface DropzoneProps {
|
|
3
|
+
name: string;
|
|
4
|
+
builderBlock: BuilderBlock;
|
|
5
|
+
builderContext: Writable<BuilderContextInterface>;
|
|
6
|
+
attributes: any;
|
|
7
|
+
}
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<script lang="ts">
|
|
11
|
+
import Blocks from "../../components/blocks/blocks.svelte";
|
|
12
|
+
import type { BuilderContextInterface } from "../../context/types.js";
|
|
13
|
+
import { deoptSignal } from "../../functions/deopt.js";
|
|
14
|
+
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
15
|
+
import type { Writable } from "svelte/store";
|
|
16
|
+
|
|
17
|
+
export let builderContext: DropzoneProps["builderContext"];
|
|
18
|
+
export let name: DropzoneProps["name"];
|
|
19
|
+
|
|
20
|
+
function mitosis_styling(node, vars) {
|
|
21
|
+
Object.entries(vars || {}).forEach(([p, v]) => {
|
|
22
|
+
if (p.startsWith("--")) {
|
|
23
|
+
node.style.setProperty(p, v);
|
|
24
|
+
} else {
|
|
25
|
+
node.style[p] = v;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<div
|
|
32
|
+
use:mitosis_styling={{
|
|
33
|
+
pointerEvents: "auto",
|
|
34
|
+
}}
|
|
35
|
+
{...!$builderContext.context?.symbolId && {
|
|
36
|
+
"builder-slot": name,
|
|
37
|
+
}}
|
|
38
|
+
>
|
|
39
|
+
<Blocks
|
|
40
|
+
parent={$builderContext.context?.symbolId}
|
|
41
|
+
path={`symbol.data.${name}`}
|
|
42
|
+
context={builderContext}
|
|
43
|
+
blocks={$builderContext.rootState?.[name]}
|
|
44
|
+
/>
|
|
45
|
+
</div>
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
export let symbol: PropsWithBuilderData<SymbolProps>["symbol"] = undefined;
|
|
17
17
|
export let dynamic: PropsWithBuilderData<SymbolProps>["dynamic"] = undefined;
|
|
18
18
|
export let builderContext: PropsWithBuilderData<SymbolProps>["builderContext"];
|
|
19
|
+
export let builderBlock: PropsWithBuilderData<SymbolProps>["builderBlock"];
|
|
19
20
|
export let builderComponents: PropsWithBuilderData<SymbolProps>["builderComponents"];
|
|
20
21
|
|
|
21
22
|
function setContent() {
|
|
@@ -62,7 +63,10 @@
|
|
|
62
63
|
__isNestedRender={true}
|
|
63
64
|
apiVersion={$builderContext.apiVersion}
|
|
64
65
|
apiKey={$builderContext.apiKey}
|
|
65
|
-
context={
|
|
66
|
+
context={{
|
|
67
|
+
...$builderContext.context,
|
|
68
|
+
symbolId: builderBlock?.id,
|
|
69
|
+
}}
|
|
66
70
|
customComponents={Object.values(builderComponents)}
|
|
67
71
|
data={{
|
|
68
72
|
...symbol?.data,
|
|
@@ -3,14 +3,6 @@ import { evaluate } from '../../functions/evaluate/index.js';
|
|
|
3
3
|
import { getProcessedBlock } from '../../functions/get-processed-block.js';
|
|
4
4
|
import type { BuilderBlock } from '../../types/builder-block.js';
|
|
5
5
|
import type { RepeatData } from './types.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
|
|
9
|
-
*/
|
|
10
|
-
const EMPTY_HTML_ELEMENTS = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
|
|
11
|
-
export const isEmptyHtmlElement = (tagName: unknown) => {
|
|
12
|
-
return typeof tagName === 'string' && EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase());
|
|
13
|
-
};
|
|
14
6
|
export const getComponent = ({
|
|
15
7
|
block,
|
|
16
8
|
context,
|
|
@@ -18,11 +18,7 @@
|
|
|
18
18
|
import { getBlockProperties } from "../../functions/get-block-properties.js";
|
|
19
19
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
20
20
|
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
21
|
-
import {
|
|
22
|
-
getComponent,
|
|
23
|
-
getRepeatItemData,
|
|
24
|
-
isEmptyHtmlElement,
|
|
25
|
-
} from "./block.helpers.js";
|
|
21
|
+
import { getComponent, getRepeatItemData } from "./block.helpers.js";
|
|
26
22
|
import BlockStyles from "./components/block-styles.svelte";
|
|
27
23
|
import BlockWrapper from "./components/block-wrapper.svelte";
|
|
28
24
|
import type { ComponentProps } from "./components/component-ref/component-ref.helpers.js";
|
|
@@ -115,32 +111,8 @@
|
|
|
115
111
|
<BlockStyles {block} context={$context} />
|
|
116
112
|
|
|
117
113
|
{#if !blockComponent?.()?.noWrap}
|
|
118
|
-
{#if
|
|
119
|
-
<BlockWrapper
|
|
120
|
-
Wrapper={Tag()}
|
|
121
|
-
block={processedBlock()}
|
|
122
|
-
{context}
|
|
123
|
-
hasChildren={false}
|
|
124
|
-
/>
|
|
125
|
-
{/if}
|
|
126
|
-
|
|
127
|
-
{#if !isEmptyHtmlElement(Tag()) && repeatItem()}
|
|
128
|
-
{#each repeatItem() as data, index (index)}
|
|
129
|
-
<RepeatedBlock
|
|
130
|
-
repeatContext={data.context}
|
|
131
|
-
block={data.block}
|
|
132
|
-
{registeredComponents}
|
|
133
|
-
/>
|
|
134
|
-
{/each}
|
|
135
|
-
{/if}
|
|
136
|
-
|
|
137
|
-
{#if !isEmptyHtmlElement(Tag()) && !repeatItem()}
|
|
138
|
-
<BlockWrapper
|
|
139
|
-
Wrapper={Tag()}
|
|
140
|
-
block={processedBlock()}
|
|
141
|
-
{context}
|
|
142
|
-
hasChildren={true}
|
|
143
|
-
>
|
|
114
|
+
{#if !repeatItem()}
|
|
115
|
+
<BlockWrapper Wrapper={Tag()} block={processedBlock()} {context}>
|
|
144
116
|
<ComponentRef
|
|
145
117
|
componentRef={componentRefProps().componentRef}
|
|
146
118
|
componentOptions={componentRefProps().componentOptions}
|
|
@@ -160,6 +132,14 @@
|
|
|
160
132
|
/>
|
|
161
133
|
{/each}
|
|
162
134
|
</BlockWrapper>
|
|
135
|
+
{:else}
|
|
136
|
+
{#each repeatItem() as data, index (index)}
|
|
137
|
+
<RepeatedBlock
|
|
138
|
+
repeatContext={data.context}
|
|
139
|
+
block={data.block}
|
|
140
|
+
{registeredComponents}
|
|
141
|
+
/>
|
|
142
|
+
{/each}
|
|
163
143
|
{/if}
|
|
164
144
|
{:else}
|
|
165
145
|
<ComponentRef
|
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
<script context="module" lang="ts">
|
|
2
|
-
/**
|
|
3
|
-
* This import is used by the Svelte SDK. Do not remove.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
2
|
type BlockWrapperProps = {
|
|
7
3
|
Wrapper: string;
|
|
8
4
|
block: BuilderBlock;
|
|
9
5
|
context: Writable<BuilderContextInterface>;
|
|
10
|
-
hasChildren: boolean;
|
|
11
6
|
};
|
|
12
7
|
|
|
13
8
|
/**
|
|
14
9
|
* This component renders a block's wrapper HTML element (from the block's `tagName` property).
|
|
15
|
-
* It reuses the exact same logic as the `InteractiveElement` component, but we need to have 2 separate components for
|
|
16
|
-
* Svelte's sake, as it needs to know at compile-time whether to use:
|
|
17
|
-
* - `<svelte:element>` (for HTML element) or
|
|
18
|
-
* - `<svelte:component>` (for custom components)
|
|
19
10
|
*/
|
|
20
11
|
</script>
|
|
21
12
|
|
|
@@ -25,47 +16,28 @@
|
|
|
25
16
|
import { getBlockProperties } from "../../../functions/get-block-properties.js";
|
|
26
17
|
import type { BuilderBlock } from "../../../types/builder-block.js";
|
|
27
18
|
import type { PropsWithChildren } from "../../../types/typescript.js";
|
|
28
|
-
import
|
|
19
|
+
import DynamicRenderer from "../../dynamic-renderer/dynamic-renderer.svelte";
|
|
29
20
|
import type { Writable } from "svelte/store";
|
|
30
21
|
|
|
31
22
|
export let Wrapper: PropsWithChildren<BlockWrapperProps>["Wrapper"];
|
|
32
23
|
export let block: PropsWithChildren<BlockWrapperProps>["block"];
|
|
33
24
|
export let context: PropsWithChildren<BlockWrapperProps>["context"];
|
|
34
|
-
export let hasChildren: PropsWithChildren<BlockWrapperProps>["hasChildren"];
|
|
35
25
|
</script>
|
|
36
26
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
</svelte:element>
|
|
55
|
-
{:else}
|
|
56
|
-
<svelte:element
|
|
57
|
-
this={Wrapper}
|
|
58
|
-
{...getBlockProperties({
|
|
59
|
-
block: block,
|
|
60
|
-
context: $context,
|
|
61
|
-
})}
|
|
62
|
-
use:setAttrs={getBlockActions({
|
|
63
|
-
block: block,
|
|
64
|
-
rootState: $context.rootState,
|
|
65
|
-
rootSetState: $context.rootSetState,
|
|
66
|
-
localState: $context.localState,
|
|
67
|
-
context: $context.context,
|
|
68
|
-
stripPrefix: true,
|
|
69
|
-
})}
|
|
70
|
-
/>
|
|
71
|
-
{/if}
|
|
27
|
+
<DynamicRenderer
|
|
28
|
+
TagName={Wrapper}
|
|
29
|
+
attributes={getBlockProperties({
|
|
30
|
+
block: block,
|
|
31
|
+
context: $context,
|
|
32
|
+
})}
|
|
33
|
+
actionAttributes={getBlockActions({
|
|
34
|
+
block: block,
|
|
35
|
+
rootState: $context.rootState,
|
|
36
|
+
rootSetState: $context.rootSetState,
|
|
37
|
+
localState: $context.localState,
|
|
38
|
+
context: $context.context,
|
|
39
|
+
stripPrefix: true,
|
|
40
|
+
})}
|
|
41
|
+
>
|
|
42
|
+
<slot />
|
|
43
|
+
</DynamicRenderer>
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
import { fetch } from "../../../functions/get-fetch.js";
|
|
25
25
|
import { isBrowser } from "../../../functions/is-browser.js";
|
|
26
26
|
import { isEditing } from "../../../functions/is-editing.js";
|
|
27
|
+
import { isFromTrustedHost } from "../../../functions/is-from-trusted-host.js";
|
|
27
28
|
import { isPreviewing } from "../../../functions/is-previewing.js";
|
|
28
29
|
import { createRegisterComponentMessage } from "../../../functions/register-component.js";
|
|
29
30
|
import { _track } from "../../../functions/track/index.js";
|
|
@@ -46,6 +47,7 @@
|
|
|
46
47
|
|
|
47
48
|
export let builderContextSignal: BuilderEditorProps["builderContextSignal"];
|
|
48
49
|
export let contentWrapper: BuilderEditorProps["contentWrapper"] = undefined;
|
|
50
|
+
export let trustedHosts: BuilderEditorProps["trustedHosts"] = undefined;
|
|
49
51
|
export let model: BuilderEditorProps["model"] = undefined;
|
|
50
52
|
export let context: BuilderEditorProps["context"] = undefined;
|
|
51
53
|
export let canTrack: BuilderEditorProps["canTrack"] = undefined;
|
|
@@ -90,6 +92,9 @@
|
|
|
90
92
|
$builderContextSignal.content = newContentValue;
|
|
91
93
|
}
|
|
92
94
|
function processMessage(event: MessageEvent) {
|
|
95
|
+
if (!isFromTrustedHost(trustedHosts, event)) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
93
98
|
const { data } = event;
|
|
94
99
|
if (data) {
|
|
95
100
|
switch (data.type) {
|
|
@@ -234,6 +239,11 @@
|
|
|
234
239
|
enrich: enrich,
|
|
235
240
|
}
|
|
236
241
|
: {}),
|
|
242
|
+
...(trustedHosts
|
|
243
|
+
? {
|
|
244
|
+
trustedHosts: trustedHosts,
|
|
245
|
+
}
|
|
246
|
+
: {}),
|
|
237
247
|
});
|
|
238
248
|
Object.values<ComponentInfo>($builderContextSignal.componentInfos).forEach(
|
|
239
249
|
(registeredComponent) => {
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
export let contentWrapper: ContentProps["contentWrapper"] = undefined;
|
|
46
46
|
export let contentWrapperProps: ContentProps["contentWrapperProps"] =
|
|
47
47
|
undefined;
|
|
48
|
+
export let trustedHosts: ContentProps["trustedHosts"] = undefined;
|
|
48
49
|
export let isSsrAbTest: ContentProps["isSsrAbTest"];
|
|
49
50
|
|
|
50
51
|
function contentSetState(newRootState: BuilderRenderState) {
|
|
@@ -131,6 +132,7 @@
|
|
|
131
132
|
{builderContextSignal}
|
|
132
133
|
{contentWrapper}
|
|
133
134
|
{contentWrapperProps}
|
|
135
|
+
{trustedHosts}
|
|
134
136
|
{...{}}
|
|
135
137
|
>
|
|
136
138
|
{#if isSsrAbTest}
|