@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.
Files changed (87) hide show
  1. package/lib/browser/blocks/button/button.svelte +3 -8
  2. package/lib/browser/components/block/block.helpers.d.ts +0 -1
  3. package/lib/browser/components/block/block.helpers.js +0 -7
  4. package/lib/browser/components/block/block.svelte +11 -27
  5. package/lib/browser/components/block/components/block-wrapper.svelte +18 -44
  6. package/lib/browser/components/block/components/block-wrapper.svelte.d.ts +0 -5
  7. package/lib/browser/components/content/components/enable-editor.svelte +10 -0
  8. package/lib/browser/components/content/components/enable-editor.svelte.d.ts +1 -0
  9. package/lib/browser/components/content/components/styles.svelte +4 -0
  10. package/lib/browser/components/content/content.svelte +2 -0
  11. package/lib/browser/components/content/content.svelte.d.ts +1 -0
  12. package/lib/browser/components/content-variants/content-variants.svelte +3 -0
  13. package/lib/browser/components/content-variants/content-variants.svelte.d.ts +1 -0
  14. package/lib/browser/components/content-variants/content-variants.types.d.ts +4 -0
  15. package/lib/browser/components/dynamic-renderer/dynamic-renderer.helpers.d.ts +1 -0
  16. package/lib/browser/components/dynamic-renderer/dynamic-renderer.helpers.js +7 -0
  17. package/lib/browser/components/dynamic-renderer/dynamic-renderer.svelte +28 -0
  18. package/lib/browser/components/dynamic-renderer/dynamic-renderer.svelte.d.ts +21 -0
  19. package/lib/browser/constants/sdk-version.d.ts +1 -1
  20. package/lib/browser/constants/sdk-version.js +1 -1
  21. package/lib/browser/functions/is-from-trusted-host.d.ts +3 -0
  22. package/lib/browser/functions/is-from-trusted-host.js +5 -0
  23. package/lib/browser/scripts/init-editing.d.ts +1 -0
  24. package/lib/browser/scripts/init-editing.js +6 -1
  25. package/lib/edge/blocks/button/button.svelte +3 -8
  26. package/lib/edge/components/block/block.helpers.d.ts +0 -1
  27. package/lib/edge/components/block/block.helpers.js +0 -7
  28. package/lib/edge/components/block/block.svelte +11 -27
  29. package/lib/edge/components/block/components/block-wrapper.svelte +18 -44
  30. package/lib/edge/components/block/components/block-wrapper.svelte.d.ts +0 -5
  31. package/lib/edge/components/content/components/enable-editor.svelte +10 -0
  32. package/lib/edge/components/content/components/enable-editor.svelte.d.ts +1 -0
  33. package/lib/edge/components/content/components/styles.svelte +4 -0
  34. package/lib/edge/components/content/content.svelte +2 -0
  35. package/lib/edge/components/content/content.svelte.d.ts +1 -0
  36. package/lib/edge/components/content-variants/content-variants.svelte +3 -0
  37. package/lib/edge/components/content-variants/content-variants.svelte.d.ts +1 -0
  38. package/lib/edge/components/content-variants/content-variants.types.d.ts +4 -0
  39. package/lib/edge/components/dynamic-renderer/dynamic-renderer.helpers.d.ts +1 -0
  40. package/lib/edge/components/dynamic-renderer/dynamic-renderer.helpers.js +7 -0
  41. package/lib/edge/components/dynamic-renderer/dynamic-renderer.svelte +28 -0
  42. package/lib/edge/components/dynamic-renderer/dynamic-renderer.svelte.d.ts +21 -0
  43. package/lib/edge/constants/sdk-version.d.ts +1 -1
  44. package/lib/edge/constants/sdk-version.js +1 -1
  45. package/lib/edge/functions/is-from-trusted-host.d.ts +3 -0
  46. package/lib/edge/functions/is-from-trusted-host.js +5 -0
  47. package/lib/edge/scripts/init-editing.d.ts +1 -0
  48. package/lib/edge/scripts/init-editing.js +6 -1
  49. package/lib/node/blocks/button/button.svelte +3 -8
  50. package/lib/node/components/block/block.helpers.d.ts +0 -1
  51. package/lib/node/components/block/block.helpers.js +0 -7
  52. package/lib/node/components/block/block.svelte +11 -27
  53. package/lib/node/components/block/components/block-wrapper.svelte +18 -44
  54. package/lib/node/components/block/components/block-wrapper.svelte.d.ts +0 -5
  55. package/lib/node/components/content/components/enable-editor.svelte +10 -0
  56. package/lib/node/components/content/components/enable-editor.svelte.d.ts +1 -0
  57. package/lib/node/components/content/components/styles.svelte +4 -0
  58. package/lib/node/components/content/content.svelte +2 -0
  59. package/lib/node/components/content/content.svelte.d.ts +1 -0
  60. package/lib/node/components/content-variants/content-variants.svelte +3 -0
  61. package/lib/node/components/content-variants/content-variants.svelte.d.ts +1 -0
  62. package/lib/node/components/content-variants/content-variants.types.d.ts +4 -0
  63. package/lib/node/components/dynamic-renderer/dynamic-renderer.helpers.d.ts +1 -0
  64. package/lib/node/components/dynamic-renderer/dynamic-renderer.helpers.js +7 -0
  65. package/lib/node/components/dynamic-renderer/dynamic-renderer.svelte +28 -0
  66. package/lib/node/components/dynamic-renderer/dynamic-renderer.svelte.d.ts +21 -0
  67. package/lib/node/constants/sdk-version.d.ts +1 -1
  68. package/lib/node/constants/sdk-version.js +1 -1
  69. package/lib/node/functions/is-from-trusted-host.d.ts +3 -0
  70. package/lib/node/functions/is-from-trusted-host.js +5 -0
  71. package/lib/node/scripts/init-editing.d.ts +1 -0
  72. package/lib/node/scripts/init-editing.js +6 -1
  73. package/package.json +1 -1
  74. package/src/blocks/button/button.svelte +3 -8
  75. package/src/components/block/block.helpers.ts +0 -8
  76. package/src/components/block/block.svelte +11 -31
  77. package/src/components/block/components/block-wrapper.svelte +18 -46
  78. package/src/components/content/components/enable-editor.svelte +10 -0
  79. package/src/components/content/components/styles.svelte +4 -0
  80. package/src/components/content/content.svelte +2 -0
  81. package/src/components/content-variants/content-variants.svelte +3 -0
  82. package/src/components/content-variants/content-variants.types.ts +5 -0
  83. package/src/components/dynamic-renderer/dynamic-renderer.helpers.ts +7 -0
  84. package/src/components/dynamic-renderer/dynamic-renderer.svelte +43 -0
  85. package/src/constants/sdk-version.ts +1 -1
  86. package/src/functions/is-from-trusted-host.ts +8 -0
  87. package/src/scripts/init-editing.ts +9 -3
@@ -29,16 +29,11 @@ function mitosis_styling(node, vars) {
29
29
  {:else}
30
30
  <button
31
31
  use:mitosis_styling={attributes.style}
32
+ role="button"
32
33
  {...filterAttrs(attributes, "on:", false)}
33
- class={attributes.class + " button"}
34
+ class={`builder-button ${attributes.class}`}
34
35
  use:setAttrs={filterAttrs(attributes, "on:", true)}
35
36
  >
36
37
  {text}
37
38
  </button>
38
- {/if}
39
-
40
- <style>
41
- .button {
42
- all: unset;
43
- }
44
- </style>
39
+ {/if}
@@ -1,7 +1,6 @@
1
1
  import type { BuilderContextInterface, RegisteredComponents } from '../../context/types.js';
2
2
  import type { BuilderBlock } from '../../types/builder-block.js';
3
3
  import type { RepeatData } from './types.js';
4
- export declare const isEmptyHtmlElement: (tagName: unknown) => boolean;
5
4
  export declare const getComponent: ({ block, context, registeredComponents }: {
6
5
  block: BuilderBlock;
7
6
  context: BuilderContextInterface;
@@ -1,12 +1,5 @@
1
1
  import { evaluate } from '../../functions/evaluate/index.js';
2
2
  import { getProcessedBlock } from '../../functions/get-processed-block.js';
3
- /**
4
- * https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
5
- */
6
- const EMPTY_HTML_ELEMENTS = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
7
- export const isEmptyHtmlElement = (tagName) => {
8
- return typeof tagName === 'string' && EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase());
9
- };
10
3
  export const getComponent = ({ block, context, registeredComponents }) => {
11
4
  const componentName = getProcessedBlock({
12
5
  block,
@@ -5,7 +5,7 @@ import "../../functions/extract-text-styles.js";
5
5
  import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
6
6
  import "../../functions/get-block-properties.js";
7
7
  import { getProcessedBlock } from "../../functions/get-processed-block.js";
8
- import { getComponent, getRepeatItemData, isEmptyHtmlElement, } from "./block.helpers.js";
8
+ import { getComponent, getRepeatItemData } from "./block.helpers.js";
9
9
  import BlockStyles from "./components/block-styles.svelte";
10
10
  import BlockWrapper from "./components/block-wrapper.svelte";
11
11
  import ComponentRef from "./components/component-ref/component-ref.svelte";
@@ -91,32 +91,8 @@ let childrenContext = writable($context);
91
91
  <BlockStyles {block} context={$context} />
92
92
 
93
93
  {#if !blockComponent?.()?.noWrap}
94
- {#if isEmptyHtmlElement(Tag())}
95
- <BlockWrapper
96
- Wrapper={Tag()}
97
- block={processedBlock()}
98
- {context}
99
- hasChildren={false}
100
- />
101
- {/if}
102
-
103
- {#if !isEmptyHtmlElement(Tag()) && repeatItem()}
104
- {#each repeatItem() as data, index (index)}
105
- <RepeatedBlock
106
- repeatContext={data.context}
107
- block={data.block}
108
- {registeredComponents}
109
- />
110
- {/each}
111
- {/if}
112
-
113
- {#if !isEmptyHtmlElement(Tag()) && !repeatItem()}
114
- <BlockWrapper
115
- Wrapper={Tag()}
116
- block={processedBlock()}
117
- {context}
118
- hasChildren={true}
119
- >
94
+ {#if !repeatItem()}
95
+ <BlockWrapper Wrapper={Tag()} block={processedBlock()} {context}>
120
96
  <ComponentRef
121
97
  componentRef={componentRefProps().componentRef}
122
98
  componentOptions={componentRefProps().componentOptions}
@@ -136,6 +112,14 @@ let childrenContext = writable($context);
136
112
  />
137
113
  {/each}
138
114
  </BlockWrapper>
115
+ {:else}
116
+ {#each repeatItem() as data, index (index)}
117
+ <RepeatedBlock
118
+ repeatContext={data.context}
119
+ block={data.block}
120
+ {registeredComponents}
121
+ />
122
+ {/each}
139
123
  {/if}
140
124
  {:else}
141
125
  <ComponentRef
@@ -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 { setAttrs } from "../../../blocks/helpers.js";
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
- {#if hasChildren}
23
- <svelte:element
24
- this={Wrapper}
25
- {...getBlockProperties({
26
- block: block,
27
- context: $context,
28
- })}
29
- use:setAttrs={getBlockActions({
30
- block: block,
31
- rootState: $context.rootState,
32
- rootSetState: $context.rootSetState,
33
- localState: $context.localState,
34
- context: $context.context,
35
- stripPrefix: true,
36
- })}
37
- >
38
- <slot />
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"];
@@ -14,6 +14,10 @@ ${getFontCss({
14
14
  customFonts: customFonts,
15
15
  })}
16
16
 
17
+ .builder-button {
18
+ all: unset;
19
+ }
20
+
17
21
  .builder-text > p:first-of-type, .builder-text > .builder-paragraph:first-of-type {
18
22
  margin: 0;
19
23
  }
@@ -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>;
@@ -62,4 +62,8 @@ export interface ContentVariantsPrps {
62
62
  * Additonal props to pass to `blocksWrapper`. Defaults to `{}`.
63
63
  */
64
64
  blocksWrapperProps?: any;
65
+ /**
66
+ * List of hosts to allow editing content from.
67
+ */
68
+ trustedHosts?: string[];
65
69
  }
@@ -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 {};
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.12.1";
1
+ export declare const SDK_VERSION = "0.12.3";
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.12.1";
1
+ export const SDK_VERSION = "0.12.3";
@@ -0,0 +1,3 @@
1
+ export declare function isFromTrustedHost(trustedHosts: string[] | undefined, e: {
2
+ origin: string;
3
+ }): boolean;
@@ -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
+ }
@@ -3,4 +3,5 @@ export declare const setupBrowserForEditing: (options?: {
3
3
  enrich?: boolean;
4
4
  includeRefs?: boolean;
5
5
  locale?: string;
6
+ trustedHosts?: string[];
6
7
  }) => void;
@@ -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', ({ data }) => {
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
  }
@@ -29,16 +29,11 @@ function mitosis_styling(node, vars) {
29
29
  {:else}
30
30
  <button
31
31
  use:mitosis_styling={attributes.style}
32
+ role="button"
32
33
  {...filterAttrs(attributes, "on:", false)}
33
- class={attributes.class + " button"}
34
+ class={`builder-button ${attributes.class}`}
34
35
  use:setAttrs={filterAttrs(attributes, "on:", true)}
35
36
  >
36
37
  {text}
37
38
  </button>
38
- {/if}
39
-
40
- <style>
41
- .button {
42
- all: unset;
43
- }
44
- </style>
39
+ {/if}
@@ -1,7 +1,6 @@
1
1
  import type { BuilderContextInterface, RegisteredComponents } from '../../context/types.js';
2
2
  import type { BuilderBlock } from '../../types/builder-block.js';
3
3
  import type { RepeatData } from './types.js';
4
- export declare const isEmptyHtmlElement: (tagName: unknown) => boolean;
5
4
  export declare const getComponent: ({ block, context, registeredComponents }: {
6
5
  block: BuilderBlock;
7
6
  context: BuilderContextInterface;
@@ -1,12 +1,5 @@
1
1
  import { evaluate } from '../../functions/evaluate/index.js';
2
2
  import { getProcessedBlock } from '../../functions/get-processed-block.js';
3
- /**
4
- * https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
5
- */
6
- const EMPTY_HTML_ELEMENTS = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
7
- export const isEmptyHtmlElement = (tagName) => {
8
- return typeof tagName === 'string' && EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase());
9
- };
10
3
  export const getComponent = ({ block, context, registeredComponents }) => {
11
4
  const componentName = getProcessedBlock({
12
5
  block,
@@ -5,7 +5,7 @@ import "../../functions/extract-text-styles.js";
5
5
  import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
6
6
  import "../../functions/get-block-properties.js";
7
7
  import { getProcessedBlock } from "../../functions/get-processed-block.js";
8
- import { getComponent, getRepeatItemData, isEmptyHtmlElement, } from "./block.helpers.js";
8
+ import { getComponent, getRepeatItemData } from "./block.helpers.js";
9
9
  import BlockStyles from "./components/block-styles.svelte";
10
10
  import BlockWrapper from "./components/block-wrapper.svelte";
11
11
  import ComponentRef from "./components/component-ref/component-ref.svelte";
@@ -91,32 +91,8 @@ let childrenContext = writable($context);
91
91
  <BlockStyles {block} context={$context} />
92
92
 
93
93
  {#if !blockComponent?.()?.noWrap}
94
- {#if isEmptyHtmlElement(Tag())}
95
- <BlockWrapper
96
- Wrapper={Tag()}
97
- block={processedBlock()}
98
- {context}
99
- hasChildren={false}
100
- />
101
- {/if}
102
-
103
- {#if !isEmptyHtmlElement(Tag()) && repeatItem()}
104
- {#each repeatItem() as data, index (index)}
105
- <RepeatedBlock
106
- repeatContext={data.context}
107
- block={data.block}
108
- {registeredComponents}
109
- />
110
- {/each}
111
- {/if}
112
-
113
- {#if !isEmptyHtmlElement(Tag()) && !repeatItem()}
114
- <BlockWrapper
115
- Wrapper={Tag()}
116
- block={processedBlock()}
117
- {context}
118
- hasChildren={true}
119
- >
94
+ {#if !repeatItem()}
95
+ <BlockWrapper Wrapper={Tag()} block={processedBlock()} {context}>
120
96
  <ComponentRef
121
97
  componentRef={componentRefProps().componentRef}
122
98
  componentOptions={componentRefProps().componentOptions}
@@ -136,6 +112,14 @@ let childrenContext = writable($context);
136
112
  />
137
113
  {/each}
138
114
  </BlockWrapper>
115
+ {:else}
116
+ {#each repeatItem() as data, index (index)}
117
+ <RepeatedBlock
118
+ repeatContext={data.context}
119
+ block={data.block}
120
+ {registeredComponents}
121
+ />
122
+ {/each}
139
123
  {/if}
140
124
  {:else}
141
125
  <ComponentRef
@@ -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 { setAttrs } from "../../../blocks/helpers.js";
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
- {#if hasChildren}
23
- <svelte:element
24
- this={Wrapper}
25
- {...getBlockProperties({
26
- block: block,
27
- context: $context,
28
- })}
29
- use:setAttrs={getBlockActions({
30
- block: block,
31
- rootState: $context.rootState,
32
- rootSetState: $context.rootSetState,
33
- localState: $context.localState,
34
- context: $context.context,
35
- stripPrefix: true,
36
- })}
37
- >
38
- <slot />
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>;