@builder.io/sdk-svelte 0.12.1 → 0.12.3
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/button/button.svelte +3 -8
- 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/components/styles.svelte +4 -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/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/button/button.svelte +3 -8
- 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/components/styles.svelte +4 -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/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/button/button.svelte +3 -8
- 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/components/styles.svelte +4 -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/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/button/button.svelte +3 -8
- 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/components/styles.svelte +4 -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/sdk-version.ts +1 -1
- package/src/functions/is-from-trusted-host.ts +8 -0
- package/src/scripts/init-editing.ts +9 -3
|
@@ -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
|
@@ -32,16 +32,11 @@
|
|
|
32
32
|
{:else}
|
|
33
33
|
<button
|
|
34
34
|
use:mitosis_styling={attributes.style}
|
|
35
|
+
role="button"
|
|
35
36
|
{...filterAttrs(attributes, "on:", false)}
|
|
36
|
-
class={attributes.class
|
|
37
|
+
class={`builder-button ${attributes.class}`}
|
|
37
38
|
use:setAttrs={filterAttrs(attributes, "on:", true)}
|
|
38
39
|
>
|
|
39
40
|
{text}
|
|
40
41
|
</button>
|
|
41
|
-
{/if}
|
|
42
|
-
|
|
43
|
-
<style>
|
|
44
|
-
.button {
|
|
45
|
-
all: unset;
|
|
46
|
-
}
|
|
47
|
-
</style>
|
|
42
|
+
{/if}
|
|
@@ -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}
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
undefined;
|
|
46
46
|
export let contentWrapperProps: VariantsProviderProps["contentWrapperProps"] =
|
|
47
47
|
undefined;
|
|
48
|
+
export let trustedHosts: VariantsProviderProps["trustedHosts"] = undefined;
|
|
48
49
|
|
|
49
50
|
$: updateCookieAndStylesScriptStr = () => {
|
|
50
51
|
return getUpdateCookieAndStylesScript(
|
|
@@ -116,6 +117,7 @@
|
|
|
116
117
|
{blocksWrapperProps}
|
|
117
118
|
{contentWrapper}
|
|
118
119
|
{contentWrapperProps}
|
|
120
|
+
{trustedHosts}
|
|
119
121
|
/>
|
|
120
122
|
{/each}
|
|
121
123
|
{/if}
|
|
@@ -139,4 +141,5 @@
|
|
|
139
141
|
{blocksWrapperProps}
|
|
140
142
|
{contentWrapper}
|
|
141
143
|
{contentWrapperProps}
|
|
144
|
+
{trustedHosts}
|
|
142
145
|
/>
|
|
@@ -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: any): boolean => {
|
|
6
|
+
return typeof tagName === 'string' && EMPTY_HTML_ELEMENTS.has(tagName.toLowerCase());
|
|
7
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { isEmptyElement } from "./dynamic-renderer.helpers.js";
|
|
3
|
+
import { setAttrs } from "../../blocks/helpers.js";
|
|
4
|
+
import type { PropsWithChildren } from "../../types/typescript.js";
|
|
5
|
+
|
|
6
|
+
export let attributes: PropsWithChildren<{
|
|
7
|
+
TagName: any;
|
|
8
|
+
attributes: any;
|
|
9
|
+
actionAttributes: any;
|
|
10
|
+
}>["attributes"];
|
|
11
|
+
export let TagName: PropsWithChildren<{
|
|
12
|
+
TagName: any;
|
|
13
|
+
attributes: any;
|
|
14
|
+
actionAttributes: any;
|
|
15
|
+
}>["TagName"];
|
|
16
|
+
export let actionAttributes: PropsWithChildren<{
|
|
17
|
+
TagName: any;
|
|
18
|
+
attributes: any;
|
|
19
|
+
actionAttributes: any;
|
|
20
|
+
}>["actionAttributes"];
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
{#if !isEmptyElement(TagName)}
|
|
24
|
+
{#if typeof TagName === "string"}
|
|
25
|
+
<svelte:element
|
|
26
|
+
this={TagName}
|
|
27
|
+
{...attributes}
|
|
28
|
+
use:setAttrs={actionAttributes}
|
|
29
|
+
>
|
|
30
|
+
<slot />
|
|
31
|
+
</svelte:element>
|
|
32
|
+
{:else}
|
|
33
|
+
<svelte:component this={TagName} {...attributes} {...actionAttributes}>
|
|
34
|
+
<slot />
|
|
35
|
+
</svelte:component>
|
|
36
|
+
{/if}
|
|
37
|
+
{:else}
|
|
38
|
+
<svelte:element
|
|
39
|
+
this={TagName}
|
|
40
|
+
{...attributes}
|
|
41
|
+
use:setAttrs={actionAttributes}
|
|
42
|
+
/>
|
|
43
|
+
{/if}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.12.
|
|
1
|
+
export const SDK_VERSION = "0.12.3"
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const DEFAULT_TRUSTED_HOSTS = ['*.beta.builder.io', 'beta.builder.io', 'builder.io', 'localhost', 'qa.builder.io'];
|
|
2
|
+
export function isFromTrustedHost(trustedHosts: string[] | undefined, e: {
|
|
3
|
+
origin: string;
|
|
4
|
+
}): boolean {
|
|
5
|
+
const url = new URL(e.origin),
|
|
6
|
+
hostname = url.hostname;
|
|
7
|
+
return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex(trustedHost => trustedHost.startsWith('*.') ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
|
|
8
|
+
}
|
|
@@ -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', {
|
|
@@ -30,6 +31,7 @@ export const setupBrowserForEditing = (options: {
|
|
|
30
31
|
enrich?: boolean;
|
|
31
32
|
includeRefs?: boolean;
|
|
32
33
|
locale?: string;
|
|
34
|
+
trustedHosts?: string[];
|
|
33
35
|
} = {}) => {
|
|
34
36
|
if (isSetupForEditing) {
|
|
35
37
|
return;
|
|
@@ -54,9 +56,13 @@ export const setupBrowserForEditing = (options: {
|
|
|
54
56
|
options
|
|
55
57
|
}
|
|
56
58
|
}, '*');
|
|
57
|
-
window.addEventListener('message', ({
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
window.addEventListener('message', (event: MessageEvent) => {
|
|
60
|
+
if (!isFromTrustedHost(options.trustedHosts, event)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const {
|
|
64
|
+
data
|
|
65
|
+
} = event;
|
|
60
66
|
if (!data?.type) {
|
|
61
67
|
return;
|
|
62
68
|
}
|