@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
|
@@ -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}
|
|
@@ -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';
|
|
@@ -59,4 +61,7 @@ export const getDefaultRegisteredComponents: () => RegisteredComponent[] = () =>
|
|
|
59
61
|
}, {
|
|
60
62
|
component: Video,
|
|
61
63
|
...videoComponentInfo
|
|
64
|
+
}, {
|
|
65
|
+
component: Slot,
|
|
66
|
+
...slotComponentInfo
|
|
62
67
|
}]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.12.
|
|
1
|
+
export const SDK_VERSION = "0.12.2"
|
|
@@ -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
|
}
|