@builder.io/sdk-solid 0.12.1 → 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/edge/dev.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createComponent, spread, mergeProps, insert, effect, setAttribute, className, style, template, memo, Dynamic, use } from 'solid-js/web';
1
+ import { createComponent, spread, mergeProps, insert, effect, setAttribute, className, style, template, Dynamic, memo, use } from 'solid-js/web';
2
2
  import { createContext, Show, useContext, For, createSignal, onMount, createEffect, on } from 'solid-js';
3
3
  import { css } from 'solid-styled-components';
4
4
 
@@ -3486,10 +3486,6 @@ function getProcessedBlock({
3486
3486
  }
3487
3487
 
3488
3488
  // src/components/block/block.helpers.ts
3489
- var EMPTY_HTML_ELEMENTS = ["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"];
3490
- var isEmptyHtmlElement = (tagName) => {
3491
- return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase());
3492
- };
3493
3489
  var getComponent = ({
3494
3490
  block,
3495
3491
  context,
@@ -3811,48 +3807,80 @@ function getStyleAttribute(style) {
3811
3807
  }
3812
3808
  }
3813
3809
 
3814
- // src/components/block/components/block-wrapper.tsx
3815
- function BlockWrapper(props) {
3810
+ // src/components/dynamic-renderer/dynamic-renderer.helpers.ts
3811
+ var EMPTY_HTML_ELEMENTS = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]);
3812
+ var isEmptyElement = (tagName) => {
3813
+ return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.has(tagName.toLowerCase());
3814
+ };
3815
+
3816
+ // src/components/dynamic-renderer/dynamic-renderer.tsx
3817
+ function DynamicRenderer(props) {
3816
3818
  return createComponent(Show, {
3817
3819
  get fallback() {
3818
- return createComponent(Dynamic, mergeProps(() => getBlockProperties({
3819
- block: props.block,
3820
- context: props.context
3821
- }), () => getBlockActions({
3822
- block: props.block,
3823
- rootState: props.context.rootState,
3824
- rootSetState: props.context.rootSetState,
3825
- localState: props.context.localState,
3826
- context: props.context.context,
3827
- stripPrefix: true
3828
- }), {
3820
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
3829
3821
  get component() {
3830
- return props.Wrapper;
3822
+ return props.TagName;
3831
3823
  }
3832
3824
  }));
3833
3825
  },
3834
3826
  get when() {
3835
- return props.hasChildren;
3827
+ return !isEmptyElement(props.TagName);
3836
3828
  },
3837
3829
  get children() {
3838
- return createComponent(Dynamic, mergeProps(() => getBlockProperties({
3830
+ return createComponent(Show, {
3831
+ get fallback() {
3832
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
3833
+ get component() {
3834
+ return props.TagName;
3835
+ },
3836
+ get children() {
3837
+ return props.children;
3838
+ }
3839
+ }));
3840
+ },
3841
+ get when() {
3842
+ return typeof props.TagName === "string";
3843
+ },
3844
+ get children() {
3845
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
3846
+ get component() {
3847
+ return props.TagName;
3848
+ },
3849
+ get children() {
3850
+ return props.children;
3851
+ }
3852
+ }));
3853
+ }
3854
+ });
3855
+ }
3856
+ });
3857
+ }
3858
+ var dynamic_renderer_default = DynamicRenderer;
3859
+
3860
+ // src/components/block/components/block-wrapper.tsx
3861
+ function BlockWrapper(props) {
3862
+ return createComponent(dynamic_renderer_default, {
3863
+ get TagName() {
3864
+ return props.Wrapper;
3865
+ },
3866
+ get attributes() {
3867
+ return getBlockProperties({
3839
3868
  block: props.block,
3840
3869
  context: props.context
3841
- }), () => getBlockActions({
3870
+ });
3871
+ },
3872
+ get actionAttributes() {
3873
+ return getBlockActions({
3842
3874
  block: props.block,
3843
3875
  rootState: props.context.rootState,
3844
3876
  rootSetState: props.context.rootSetState,
3845
3877
  localState: props.context.localState,
3846
3878
  context: props.context.context,
3847
3879
  stripPrefix: true
3848
- }), {
3849
- get component() {
3850
- return props.Wrapper;
3851
- },
3852
- get children() {
3853
- return props.children;
3854
- }
3855
- }));
3880
+ });
3881
+ },
3882
+ get children() {
3883
+ return props.children;
3856
3884
  }
3857
3885
  });
3858
3886
  }
@@ -4093,29 +4121,8 @@ function Block(props) {
4093
4121
  return !blockComponent()?.noWrap;
4094
4122
  },
4095
4123
  get children() {
4096
- return [createComponent(Show, {
4097
- get when() {
4098
- return isEmptyHtmlElement(Tag());
4099
- },
4100
- get children() {
4101
- return createComponent(block_wrapper_default, {
4102
- get Wrapper() {
4103
- return Tag();
4104
- },
4105
- get block() {
4106
- return processedBlock();
4107
- },
4108
- get context() {
4109
- return props.context;
4110
- },
4111
- hasChildren: false
4112
- });
4113
- }
4114
- }), createComponent(Show, {
4115
- get when() {
4116
- return memo(() => !!!isEmptyHtmlElement(Tag()))() && repeatItem();
4117
- },
4118
- get children() {
4124
+ return createComponent(Show, {
4125
+ get fallback() {
4119
4126
  return createComponent(For, {
4120
4127
  get each() {
4121
4128
  return repeatItem();
@@ -4136,10 +4143,9 @@ function Block(props) {
4136
4143
  });
4137
4144
  }
4138
4145
  });
4139
- }
4140
- }), createComponent(Show, {
4146
+ },
4141
4147
  get when() {
4142
- return memo(() => !!!isEmptyHtmlElement(Tag()))() && !repeatItem();
4148
+ return !repeatItem();
4143
4149
  },
4144
4150
  get children() {
4145
4151
  return createComponent(block_wrapper_default, {
@@ -4152,7 +4158,6 @@ function Block(props) {
4152
4158
  get context() {
4153
4159
  return props.context;
4154
4160
  },
4155
- hasChildren: true,
4156
4161
  get children() {
4157
4162
  return [createComponent(component_ref_default, {
4158
4163
  get componentRef() {
@@ -4202,7 +4207,7 @@ function Block(props) {
4202
4207
  }
4203
4208
  });
4204
4209
  }
4205
- })];
4210
+ });
4206
4211
  }
4207
4212
  })];
4208
4213
  }
@@ -6197,6 +6202,13 @@ async function fetchEntries(options) {
6197
6202
  }
6198
6203
  var getAllContent = fetchEntries;
6199
6204
 
6205
+ // src/functions/is-from-trusted-host.ts
6206
+ var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
6207
+ function isFromTrustedHost(trustedHosts, e) {
6208
+ const url = new URL(e.origin), hostname = url.hostname;
6209
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
6210
+ }
6211
+
6200
6212
  // src/functions/is-previewing.ts
6201
6213
  function isPreviewing() {
6202
6214
  if (!isBrowser()) {
@@ -6448,7 +6460,7 @@ var getInteractionPropertiesForEvent = (event) => {
6448
6460
  };
6449
6461
 
6450
6462
  // src/constants/sdk-version.ts
6451
- var SDK_VERSION = "0.12.1";
6463
+ var SDK_VERSION = "0.12.2";
6452
6464
 
6453
6465
  // src/functions/register.ts
6454
6466
  var registry = {};
@@ -6526,9 +6538,13 @@ var setupBrowserForEditing = (options = {}) => {
6526
6538
  options
6527
6539
  }
6528
6540
  }, "*");
6529
- window.addEventListener("message", ({
6530
- data
6531
- }) => {
6541
+ window.addEventListener("message", (event) => {
6542
+ if (!isFromTrustedHost(options.trustedHosts, event)) {
6543
+ return;
6544
+ }
6545
+ const {
6546
+ data
6547
+ } = event;
6532
6548
  if (!data?.type) {
6533
6549
  return;
6534
6550
  }
@@ -6624,6 +6640,9 @@ function EnableEditor(props) {
6624
6640
  }));
6625
6641
  }
6626
6642
  function processMessage(event) {
6643
+ if (!isFromTrustedHost(props.trustedHosts, event)) {
6644
+ return;
6645
+ }
6627
6646
  const {
6628
6647
  data
6629
6648
  } = event;
@@ -6755,6 +6774,9 @@ function EnableEditor(props) {
6755
6774
  } : {},
6756
6775
  ...props.enrich ? {
6757
6776
  enrich: props.enrich
6777
+ } : {},
6778
+ ...props.trustedHosts ? {
6779
+ trustedHosts: props.trustedHosts
6758
6780
  } : {}
6759
6781
  });
6760
6782
  Object.values(props.builderContextSignal.componentInfos).forEach((registeredComponent) => {
@@ -7122,6 +7144,9 @@ function ContentComponent(props) {
7122
7144
  },
7123
7145
  get contentWrapperProps() {
7124
7146
  return props.contentWrapperProps;
7147
+ },
7148
+ get trustedHosts() {
7149
+ return props.trustedHosts;
7125
7150
  }
7126
7151
  }, {
7127
7152
  setBuilderContextSignal
@@ -7281,6 +7306,9 @@ function ContentVariants(props) {
7281
7306
  },
7282
7307
  get contentWrapperProps() {
7283
7308
  return props.contentWrapperProps;
7309
+ },
7310
+ get trustedHosts() {
7311
+ return props.trustedHosts;
7284
7312
  }
7285
7313
  });
7286
7314
  }
@@ -7335,6 +7363,9 @@ function ContentVariants(props) {
7335
7363
  },
7336
7364
  get contentWrapperProps() {
7337
7365
  return props.contentWrapperProps;
7366
+ },
7367
+ get trustedHosts() {
7368
+ return props.trustedHosts;
7338
7369
  }
7339
7370
  }))];
7340
7371
  }
package/lib/edge/dev.jsx CHANGED
@@ -3480,10 +3480,6 @@ function getProcessedBlock({
3480
3480
  }
3481
3481
 
3482
3482
  // src/components/block/block.helpers.ts
3483
- var EMPTY_HTML_ELEMENTS = ["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"];
3484
- var isEmptyHtmlElement = (tagName) => {
3485
- return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase());
3486
- };
3487
3483
  var getComponent = ({
3488
3484
  block,
3489
3485
  context,
@@ -3708,10 +3704,6 @@ function BlockStyles(props) {
3708
3704
  }
3709
3705
  var Block_styles_default = BlockStyles;
3710
3706
 
3711
- // src/components/block/components/block-wrapper.tsx
3712
- import { Show as Show3 } from "solid-js";
3713
- import { Dynamic } from "solid-js/web";
3714
-
3715
3707
  // src/functions/event-handler-name.ts
3716
3708
  function capitalizeFirstLetter(string) {
3717
3709
  return string.charAt(0).toUpperCase() + string.slice(1);
@@ -3798,31 +3790,49 @@ function getStyleAttribute(style) {
3798
3790
  }
3799
3791
  }
3800
3792
 
3801
- // src/components/block/components/block-wrapper.tsx
3802
- function BlockWrapper(props) {
3793
+ // src/components/dynamic-renderer/dynamic-renderer.tsx
3794
+ import { Show as Show3 } from "solid-js";
3795
+ import { Dynamic } from "solid-js/web";
3796
+
3797
+ // src/components/dynamic-renderer/dynamic-renderer.helpers.ts
3798
+ var EMPTY_HTML_ELEMENTS = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]);
3799
+ var isEmptyElement = (tagName) => {
3800
+ return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.has(tagName.toLowerCase());
3801
+ };
3802
+
3803
+ // src/components/dynamic-renderer/dynamic-renderer.tsx
3804
+ function DynamicRenderer(props) {
3803
3805
  return <Show3
3804
3806
  fallback={<Dynamic
3805
- {...getBlockProperties({
3806
- block: props.block,
3807
- context: props.context
3808
- })}
3809
- {...getBlockActions({
3810
- block: props.block,
3811
- rootState: props.context.rootState,
3812
- rootSetState: props.context.rootSetState,
3813
- localState: props.context.localState,
3814
- context: props.context.context,
3815
- stripPrefix: true
3816
- })}
3817
- component={props.Wrapper}
3807
+ {...props.attributes}
3808
+ {...props.actionAttributes}
3809
+ component={props.TagName}
3818
3810
  />}
3819
- when={props.hasChildren}
3811
+ when={!isEmptyElement(props.TagName)}
3812
+ ><Show3
3813
+ fallback={<Dynamic
3814
+ {...props.attributes}
3815
+ {...props.actionAttributes}
3816
+ component={props.TagName}
3817
+ >{props.children}</Dynamic>}
3818
+ when={typeof props.TagName === "string"}
3820
3819
  ><Dynamic
3821
- {...getBlockProperties({
3820
+ {...props.attributes}
3821
+ {...props.actionAttributes}
3822
+ component={props.TagName}
3823
+ >{props.children}</Dynamic></Show3></Show3>;
3824
+ }
3825
+ var Dynamic_renderer_default = DynamicRenderer;
3826
+
3827
+ // src/components/block/components/block-wrapper.tsx
3828
+ function BlockWrapper(props) {
3829
+ return <Dynamic_renderer_default
3830
+ TagName={props.Wrapper}
3831
+ attributes={getBlockProperties({
3822
3832
  block: props.block,
3823
3833
  context: props.context
3824
3834
  })}
3825
- {...getBlockActions({
3835
+ actionAttributes={getBlockActions({
3826
3836
  block: props.block,
3827
3837
  rootState: props.context.rootState,
3828
3838
  rootSetState: props.context.rootSetState,
@@ -3830,8 +3840,7 @@ function BlockWrapper(props) {
3830
3840
  context: props.context.context,
3831
3841
  stripPrefix: true
3832
3842
  })}
3833
- component={props.Wrapper}
3834
- >{props.children}</Dynamic></Show3>;
3843
+ >{props.children}</Dynamic_renderer_default>;
3835
3844
  }
3836
3845
  var Block_wrapper_default = BlockWrapper;
3837
3846
 
@@ -4010,14 +4019,8 @@ function Block(props) {
4010
4019
  isInteractive={componentRefProps().isInteractive}
4011
4020
  />}
4012
4021
  when={!blockComponent()?.noWrap}
4013
- >
4014
- <Show5 when={isEmptyHtmlElement(Tag())}><Block_wrapper_default
4015
- Wrapper={Tag()}
4016
- block={processedBlock()}
4017
- context={props.context}
4018
- hasChildren={false}
4019
- /></Show5>
4020
- <Show5 when={!isEmptyHtmlElement(Tag()) && repeatItem()}><For2 each={repeatItem()}>{(data, _index) => {
4022
+ ><Show5
4023
+ fallback={<For2 each={repeatItem()}>{(data, _index) => {
4021
4024
  const index = _index();
4022
4025
  return <Repeated_block_default
4023
4026
  key={index}
@@ -4025,34 +4028,33 @@ function Block(props) {
4025
4028
  block={data.block}
4026
4029
  registeredComponents={props.registeredComponents}
4027
4030
  />;
4028
- }}</For2></Show5>
4029
- <Show5 when={!isEmptyHtmlElement(Tag()) && !repeatItem()}><Block_wrapper_default
4030
- Wrapper={Tag()}
4031
- block={processedBlock()}
4032
- context={props.context}
4033
- hasChildren={true}
4034
- >
4035
- <Component_ref_default
4036
- componentRef={componentRefProps().componentRef}
4037
- componentOptions={componentRefProps().componentOptions}
4038
- blockChildren={componentRefProps().blockChildren}
4039
- context={componentRefProps().context}
4040
- registeredComponents={componentRefProps().registeredComponents}
4041
- builderBlock={componentRefProps().builderBlock}
4042
- includeBlockProps={componentRefProps().includeBlockProps}
4043
- isInteractive={componentRefProps().isInteractive}
4044
- />
4045
- <For2 each={childrenWithoutParentComponent()}>{(child, _index) => {
4046
- const index = _index();
4047
- return <Block
4048
- key={child.id}
4049
- block={child}
4050
- context={childrenContext()}
4051
- registeredComponents={props.registeredComponents}
4052
- />;
4053
- }}</For2>
4054
- </Block_wrapper_default></Show5>
4055
- </Show5>
4031
+ }}</For2>}
4032
+ when={!repeatItem()}
4033
+ ><Block_wrapper_default
4034
+ Wrapper={Tag()}
4035
+ block={processedBlock()}
4036
+ context={props.context}
4037
+ >
4038
+ <Component_ref_default
4039
+ componentRef={componentRefProps().componentRef}
4040
+ componentOptions={componentRefProps().componentOptions}
4041
+ blockChildren={componentRefProps().blockChildren}
4042
+ context={componentRefProps().context}
4043
+ registeredComponents={componentRefProps().registeredComponents}
4044
+ builderBlock={componentRefProps().builderBlock}
4045
+ includeBlockProps={componentRefProps().includeBlockProps}
4046
+ isInteractive={componentRefProps().isInteractive}
4047
+ />
4048
+ <For2 each={childrenWithoutParentComponent()}>{(child, _index) => {
4049
+ const index = _index();
4050
+ return <Block
4051
+ key={child.id}
4052
+ block={child}
4053
+ context={childrenContext()}
4054
+ registeredComponents={props.registeredComponents}
4055
+ />;
4056
+ }}</For2>
4057
+ </Block_wrapper_default></Show5></Show5>
4056
4058
  </Show5>;
4057
4059
  }
4058
4060
  var Block_default = Block;
@@ -5879,6 +5881,13 @@ async function fetchEntries(options) {
5879
5881
  }
5880
5882
  var getAllContent = fetchEntries;
5881
5883
 
5884
+ // src/functions/is-from-trusted-host.ts
5885
+ var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
5886
+ function isFromTrustedHost(trustedHosts, e) {
5887
+ const url = new URL(e.origin), hostname = url.hostname;
5888
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
5889
+ }
5890
+
5882
5891
  // src/functions/is-previewing.ts
5883
5892
  function isPreviewing() {
5884
5893
  if (!isBrowser()) {
@@ -6130,7 +6139,7 @@ var getInteractionPropertiesForEvent = (event) => {
6130
6139
  };
6131
6140
 
6132
6141
  // src/constants/sdk-version.ts
6133
- var SDK_VERSION = "0.12.1";
6142
+ var SDK_VERSION = "0.12.2";
6134
6143
 
6135
6144
  // src/functions/register.ts
6136
6145
  var registry = {};
@@ -6208,9 +6217,13 @@ var setupBrowserForEditing = (options = {}) => {
6208
6217
  options
6209
6218
  }
6210
6219
  }, "*");
6211
- window.addEventListener("message", ({
6212
- data
6213
- }) => {
6220
+ window.addEventListener("message", (event) => {
6221
+ if (!isFromTrustedHost(options.trustedHosts, event)) {
6222
+ return;
6223
+ }
6224
+ const {
6225
+ data
6226
+ } = event;
6214
6227
  if (!data?.type) {
6215
6228
  return;
6216
6229
  }
@@ -6308,6 +6321,9 @@ function EnableEditor(props) {
6308
6321
  }));
6309
6322
  }
6310
6323
  function processMessage(event) {
6324
+ if (!isFromTrustedHost(props.trustedHosts, event)) {
6325
+ return;
6326
+ }
6311
6327
  const { data } = event;
6312
6328
  if (data) {
6313
6329
  switch (data.type) {
@@ -6439,6 +6455,9 @@ function EnableEditor(props) {
6439
6455
  } : {},
6440
6456
  ...props.enrich ? {
6441
6457
  enrich: props.enrich
6458
+ } : {},
6459
+ ...props.trustedHosts ? {
6460
+ trustedHosts: props.trustedHosts
6442
6461
  } : {}
6443
6462
  });
6444
6463
  Object.values(
@@ -6777,6 +6796,7 @@ function ContentComponent(props) {
6777
6796
  builderContextSignal={builderContextSignal()}
6778
6797
  contentWrapper={props.contentWrapper}
6779
6798
  contentWrapperProps={props.contentWrapperProps}
6799
+ trustedHosts={props.trustedHosts}
6780
6800
  {...{
6781
6801
  setBuilderContextSignal
6782
6802
  }}
@@ -6859,6 +6879,7 @@ function ContentVariants(props) {
6859
6879
  blocksWrapperProps={props.blocksWrapperProps}
6860
6880
  contentWrapper={props.contentWrapper}
6861
6881
  contentWrapperProps={props.contentWrapperProps}
6882
+ trustedHosts={props.trustedHosts}
6862
6883
  />;
6863
6884
  }}</For5>
6864
6885
  </Show12>
@@ -6881,6 +6902,7 @@ function ContentVariants(props) {
6881
6902
  blocksWrapperProps={props.blocksWrapperProps}
6882
6903
  contentWrapper={props.contentWrapper}
6883
6904
  contentWrapperProps={props.contentWrapperProps}
6905
+ trustedHosts={props.trustedHosts}
6884
6906
  />
6885
6907
  </>;
6886
6908
  }