@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/index.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
 
@@ -3484,10 +3484,6 @@ function getProcessedBlock({
3484
3484
  }
3485
3485
 
3486
3486
  // src/components/block/block.helpers.ts
3487
- var EMPTY_HTML_ELEMENTS = ["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"];
3488
- var isEmptyHtmlElement = (tagName) => {
3489
- return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase());
3490
- };
3491
3487
  var getComponent = ({
3492
3488
  block,
3493
3489
  context,
@@ -3806,48 +3802,80 @@ function getStyleAttribute(style) {
3806
3802
  }
3807
3803
  }
3808
3804
 
3809
- // src/components/block/components/block-wrapper.tsx
3810
- function BlockWrapper(props) {
3805
+ // src/components/dynamic-renderer/dynamic-renderer.helpers.ts
3806
+ var EMPTY_HTML_ELEMENTS = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]);
3807
+ var isEmptyElement = (tagName) => {
3808
+ return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.has(tagName.toLowerCase());
3809
+ };
3810
+
3811
+ // src/components/dynamic-renderer/dynamic-renderer.tsx
3812
+ function DynamicRenderer(props) {
3811
3813
  return createComponent(Show, {
3812
3814
  get fallback() {
3813
- return createComponent(Dynamic, mergeProps(() => getBlockProperties({
3814
- block: props.block,
3815
- context: props.context
3816
- }), () => getBlockActions({
3817
- block: props.block,
3818
- rootState: props.context.rootState,
3819
- rootSetState: props.context.rootSetState,
3820
- localState: props.context.localState,
3821
- context: props.context.context,
3822
- stripPrefix: true
3823
- }), {
3815
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
3824
3816
  get component() {
3825
- return props.Wrapper;
3817
+ return props.TagName;
3826
3818
  }
3827
3819
  }));
3828
3820
  },
3829
3821
  get when() {
3830
- return props.hasChildren;
3822
+ return !isEmptyElement(props.TagName);
3831
3823
  },
3832
3824
  get children() {
3833
- return createComponent(Dynamic, mergeProps(() => getBlockProperties({
3825
+ return createComponent(Show, {
3826
+ get fallback() {
3827
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
3828
+ get component() {
3829
+ return props.TagName;
3830
+ },
3831
+ get children() {
3832
+ return props.children;
3833
+ }
3834
+ }));
3835
+ },
3836
+ get when() {
3837
+ return typeof props.TagName === "string";
3838
+ },
3839
+ get children() {
3840
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
3841
+ get component() {
3842
+ return props.TagName;
3843
+ },
3844
+ get children() {
3845
+ return props.children;
3846
+ }
3847
+ }));
3848
+ }
3849
+ });
3850
+ }
3851
+ });
3852
+ }
3853
+ var dynamic_renderer_default = DynamicRenderer;
3854
+
3855
+ // src/components/block/components/block-wrapper.tsx
3856
+ function BlockWrapper(props) {
3857
+ return createComponent(dynamic_renderer_default, {
3858
+ get TagName() {
3859
+ return props.Wrapper;
3860
+ },
3861
+ get attributes() {
3862
+ return getBlockProperties({
3834
3863
  block: props.block,
3835
3864
  context: props.context
3836
- }), () => getBlockActions({
3865
+ });
3866
+ },
3867
+ get actionAttributes() {
3868
+ return getBlockActions({
3837
3869
  block: props.block,
3838
3870
  rootState: props.context.rootState,
3839
3871
  rootSetState: props.context.rootSetState,
3840
3872
  localState: props.context.localState,
3841
3873
  context: props.context.context,
3842
3874
  stripPrefix: true
3843
- }), {
3844
- get component() {
3845
- return props.Wrapper;
3846
- },
3847
- get children() {
3848
- return props.children;
3849
- }
3850
- }));
3875
+ });
3876
+ },
3877
+ get children() {
3878
+ return props.children;
3851
3879
  }
3852
3880
  });
3853
3881
  }
@@ -4088,29 +4116,8 @@ function Block(props) {
4088
4116
  return !blockComponent()?.noWrap;
4089
4117
  },
4090
4118
  get children() {
4091
- return [createComponent(Show, {
4092
- get when() {
4093
- return isEmptyHtmlElement(Tag());
4094
- },
4095
- get children() {
4096
- return createComponent(block_wrapper_default, {
4097
- get Wrapper() {
4098
- return Tag();
4099
- },
4100
- get block() {
4101
- return processedBlock();
4102
- },
4103
- get context() {
4104
- return props.context;
4105
- },
4106
- hasChildren: false
4107
- });
4108
- }
4109
- }), createComponent(Show, {
4110
- get when() {
4111
- return memo(() => !!!isEmptyHtmlElement(Tag()))() && repeatItem();
4112
- },
4113
- get children() {
4119
+ return createComponent(Show, {
4120
+ get fallback() {
4114
4121
  return createComponent(For, {
4115
4122
  get each() {
4116
4123
  return repeatItem();
@@ -4131,10 +4138,9 @@ function Block(props) {
4131
4138
  });
4132
4139
  }
4133
4140
  });
4134
- }
4135
- }), createComponent(Show, {
4141
+ },
4136
4142
  get when() {
4137
- return memo(() => !!!isEmptyHtmlElement(Tag()))() && !repeatItem();
4143
+ return !repeatItem();
4138
4144
  },
4139
4145
  get children() {
4140
4146
  return createComponent(block_wrapper_default, {
@@ -4147,7 +4153,6 @@ function Block(props) {
4147
4153
  get context() {
4148
4154
  return props.context;
4149
4155
  },
4150
- hasChildren: true,
4151
4156
  get children() {
4152
4157
  return [createComponent(component_ref_default, {
4153
4158
  get componentRef() {
@@ -4197,7 +4202,7 @@ function Block(props) {
4197
4202
  }
4198
4203
  });
4199
4204
  }
4200
- })];
4205
+ });
4201
4206
  }
4202
4207
  })];
4203
4208
  }
@@ -6186,6 +6191,13 @@ async function fetchEntries(options) {
6186
6191
  }
6187
6192
  var getAllContent = fetchEntries;
6188
6193
 
6194
+ // src/functions/is-from-trusted-host.ts
6195
+ var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
6196
+ function isFromTrustedHost(trustedHosts, e) {
6197
+ const url = new URL(e.origin), hostname = url.hostname;
6198
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
6199
+ }
6200
+
6189
6201
  // src/functions/is-previewing.ts
6190
6202
  function isPreviewing() {
6191
6203
  if (!isBrowser()) {
@@ -6434,7 +6446,7 @@ var getInteractionPropertiesForEvent = (event) => {
6434
6446
  };
6435
6447
 
6436
6448
  // src/constants/sdk-version.ts
6437
- var SDK_VERSION = "0.12.1";
6449
+ var SDK_VERSION = "0.12.2";
6438
6450
 
6439
6451
  // src/functions/register.ts
6440
6452
  var registry = {};
@@ -6511,9 +6523,13 @@ var setupBrowserForEditing = (options = {}) => {
6511
6523
  options
6512
6524
  }
6513
6525
  }, "*");
6514
- window.addEventListener("message", ({
6515
- data
6516
- }) => {
6526
+ window.addEventListener("message", (event) => {
6527
+ if (!isFromTrustedHost(options.trustedHosts, event)) {
6528
+ return;
6529
+ }
6530
+ const {
6531
+ data
6532
+ } = event;
6517
6533
  if (!data?.type) {
6518
6534
  return;
6519
6535
  }
@@ -6609,6 +6625,9 @@ function EnableEditor(props) {
6609
6625
  }));
6610
6626
  }
6611
6627
  function processMessage(event) {
6628
+ if (!isFromTrustedHost(props.trustedHosts, event)) {
6629
+ return;
6630
+ }
6612
6631
  const {
6613
6632
  data
6614
6633
  } = event;
@@ -6739,6 +6758,9 @@ function EnableEditor(props) {
6739
6758
  } : {},
6740
6759
  ...props.enrich ? {
6741
6760
  enrich: props.enrich
6761
+ } : {},
6762
+ ...props.trustedHosts ? {
6763
+ trustedHosts: props.trustedHosts
6742
6764
  } : {}
6743
6765
  });
6744
6766
  Object.values(props.builderContextSignal.componentInfos).forEach((registeredComponent) => {
@@ -7106,6 +7128,9 @@ function ContentComponent(props) {
7106
7128
  },
7107
7129
  get contentWrapperProps() {
7108
7130
  return props.contentWrapperProps;
7131
+ },
7132
+ get trustedHosts() {
7133
+ return props.trustedHosts;
7109
7134
  }
7110
7135
  }, {
7111
7136
  setBuilderContextSignal
@@ -7265,6 +7290,9 @@ function ContentVariants(props) {
7265
7290
  },
7266
7291
  get contentWrapperProps() {
7267
7292
  return props.contentWrapperProps;
7293
+ },
7294
+ get trustedHosts() {
7295
+ return props.trustedHosts;
7268
7296
  }
7269
7297
  });
7270
7298
  }
@@ -7319,6 +7347,9 @@ function ContentVariants(props) {
7319
7347
  },
7320
7348
  get contentWrapperProps() {
7321
7349
  return props.contentWrapperProps;
7350
+ },
7351
+ get trustedHosts() {
7352
+ return props.trustedHosts;
7322
7353
  }
7323
7354
  }))];
7324
7355
  }
@@ -3478,10 +3478,6 @@ function getProcessedBlock({
3478
3478
  }
3479
3479
 
3480
3480
  // src/components/block/block.helpers.ts
3481
- var EMPTY_HTML_ELEMENTS = ["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"];
3482
- var isEmptyHtmlElement = (tagName) => {
3483
- return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase());
3484
- };
3485
3481
  var getComponent = ({
3486
3482
  block,
3487
3483
  context,
@@ -3703,10 +3699,6 @@ function BlockStyles(props) {
3703
3699
  }
3704
3700
  var Block_styles_default = BlockStyles;
3705
3701
 
3706
- // src/components/block/components/block-wrapper.tsx
3707
- import { Show as Show3 } from "solid-js";
3708
- import { Dynamic } from "solid-js/web";
3709
-
3710
3702
  // src/functions/event-handler-name.ts
3711
3703
  function capitalizeFirstLetter(string) {
3712
3704
  return string.charAt(0).toUpperCase() + string.slice(1);
@@ -3793,31 +3785,49 @@ function getStyleAttribute(style) {
3793
3785
  }
3794
3786
  }
3795
3787
 
3796
- // src/components/block/components/block-wrapper.tsx
3797
- function BlockWrapper(props) {
3788
+ // src/components/dynamic-renderer/dynamic-renderer.tsx
3789
+ import { Show as Show3 } from "solid-js";
3790
+ import { Dynamic } from "solid-js/web";
3791
+
3792
+ // src/components/dynamic-renderer/dynamic-renderer.helpers.ts
3793
+ var EMPTY_HTML_ELEMENTS = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]);
3794
+ var isEmptyElement = (tagName) => {
3795
+ return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.has(tagName.toLowerCase());
3796
+ };
3797
+
3798
+ // src/components/dynamic-renderer/dynamic-renderer.tsx
3799
+ function DynamicRenderer(props) {
3798
3800
  return <Show3
3799
3801
  fallback={<Dynamic
3800
- {...getBlockProperties({
3801
- block: props.block,
3802
- context: props.context
3803
- })}
3804
- {...getBlockActions({
3805
- block: props.block,
3806
- rootState: props.context.rootState,
3807
- rootSetState: props.context.rootSetState,
3808
- localState: props.context.localState,
3809
- context: props.context.context,
3810
- stripPrefix: true
3811
- })}
3812
- component={props.Wrapper}
3802
+ {...props.attributes}
3803
+ {...props.actionAttributes}
3804
+ component={props.TagName}
3813
3805
  />}
3814
- when={props.hasChildren}
3806
+ when={!isEmptyElement(props.TagName)}
3807
+ ><Show3
3808
+ fallback={<Dynamic
3809
+ {...props.attributes}
3810
+ {...props.actionAttributes}
3811
+ component={props.TagName}
3812
+ >{props.children}</Dynamic>}
3813
+ when={typeof props.TagName === "string"}
3815
3814
  ><Dynamic
3816
- {...getBlockProperties({
3815
+ {...props.attributes}
3816
+ {...props.actionAttributes}
3817
+ component={props.TagName}
3818
+ >{props.children}</Dynamic></Show3></Show3>;
3819
+ }
3820
+ var Dynamic_renderer_default = DynamicRenderer;
3821
+
3822
+ // src/components/block/components/block-wrapper.tsx
3823
+ function BlockWrapper(props) {
3824
+ return <Dynamic_renderer_default
3825
+ TagName={props.Wrapper}
3826
+ attributes={getBlockProperties({
3817
3827
  block: props.block,
3818
3828
  context: props.context
3819
3829
  })}
3820
- {...getBlockActions({
3830
+ actionAttributes={getBlockActions({
3821
3831
  block: props.block,
3822
3832
  rootState: props.context.rootState,
3823
3833
  rootSetState: props.context.rootSetState,
@@ -3825,8 +3835,7 @@ function BlockWrapper(props) {
3825
3835
  context: props.context.context,
3826
3836
  stripPrefix: true
3827
3837
  })}
3828
- component={props.Wrapper}
3829
- >{props.children}</Dynamic></Show3>;
3838
+ >{props.children}</Dynamic_renderer_default>;
3830
3839
  }
3831
3840
  var Block_wrapper_default = BlockWrapper;
3832
3841
 
@@ -4005,14 +4014,8 @@ function Block(props) {
4005
4014
  isInteractive={componentRefProps().isInteractive}
4006
4015
  />}
4007
4016
  when={!blockComponent()?.noWrap}
4008
- >
4009
- <Show5 when={isEmptyHtmlElement(Tag())}><Block_wrapper_default
4010
- Wrapper={Tag()}
4011
- block={processedBlock()}
4012
- context={props.context}
4013
- hasChildren={false}
4014
- /></Show5>
4015
- <Show5 when={!isEmptyHtmlElement(Tag()) && repeatItem()}><For2 each={repeatItem()}>{(data, _index) => {
4017
+ ><Show5
4018
+ fallback={<For2 each={repeatItem()}>{(data, _index) => {
4016
4019
  const index = _index();
4017
4020
  return <Repeated_block_default
4018
4021
  key={index}
@@ -4020,34 +4023,33 @@ function Block(props) {
4020
4023
  block={data.block}
4021
4024
  registeredComponents={props.registeredComponents}
4022
4025
  />;
4023
- }}</For2></Show5>
4024
- <Show5 when={!isEmptyHtmlElement(Tag()) && !repeatItem()}><Block_wrapper_default
4025
- Wrapper={Tag()}
4026
- block={processedBlock()}
4027
- context={props.context}
4028
- hasChildren={true}
4029
- >
4030
- <Component_ref_default
4031
- componentRef={componentRefProps().componentRef}
4032
- componentOptions={componentRefProps().componentOptions}
4033
- blockChildren={componentRefProps().blockChildren}
4034
- context={componentRefProps().context}
4035
- registeredComponents={componentRefProps().registeredComponents}
4036
- builderBlock={componentRefProps().builderBlock}
4037
- includeBlockProps={componentRefProps().includeBlockProps}
4038
- isInteractive={componentRefProps().isInteractive}
4039
- />
4040
- <For2 each={childrenWithoutParentComponent()}>{(child, _index) => {
4041
- const index = _index();
4042
- return <Block
4043
- key={child.id}
4044
- block={child}
4045
- context={childrenContext()}
4046
- registeredComponents={props.registeredComponents}
4047
- />;
4048
- }}</For2>
4049
- </Block_wrapper_default></Show5>
4050
- </Show5>
4026
+ }}</For2>}
4027
+ when={!repeatItem()}
4028
+ ><Block_wrapper_default
4029
+ Wrapper={Tag()}
4030
+ block={processedBlock()}
4031
+ context={props.context}
4032
+ >
4033
+ <Component_ref_default
4034
+ componentRef={componentRefProps().componentRef}
4035
+ componentOptions={componentRefProps().componentOptions}
4036
+ blockChildren={componentRefProps().blockChildren}
4037
+ context={componentRefProps().context}
4038
+ registeredComponents={componentRefProps().registeredComponents}
4039
+ builderBlock={componentRefProps().builderBlock}
4040
+ includeBlockProps={componentRefProps().includeBlockProps}
4041
+ isInteractive={componentRefProps().isInteractive}
4042
+ />
4043
+ <For2 each={childrenWithoutParentComponent()}>{(child, _index) => {
4044
+ const index = _index();
4045
+ return <Block
4046
+ key={child.id}
4047
+ block={child}
4048
+ context={childrenContext()}
4049
+ registeredComponents={props.registeredComponents}
4050
+ />;
4051
+ }}</For2>
4052
+ </Block_wrapper_default></Show5></Show5>
4051
4053
  </Show5>;
4052
4054
  }
4053
4055
  var Block_default = Block;
@@ -5868,6 +5870,13 @@ async function fetchEntries(options) {
5868
5870
  }
5869
5871
  var getAllContent = fetchEntries;
5870
5872
 
5873
+ // src/functions/is-from-trusted-host.ts
5874
+ var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
5875
+ function isFromTrustedHost(trustedHosts, e) {
5876
+ const url = new URL(e.origin), hostname = url.hostname;
5877
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
5878
+ }
5879
+
5871
5880
  // src/functions/is-previewing.ts
5872
5881
  function isPreviewing() {
5873
5882
  if (!isBrowser()) {
@@ -6116,7 +6125,7 @@ var getInteractionPropertiesForEvent = (event) => {
6116
6125
  };
6117
6126
 
6118
6127
  // src/constants/sdk-version.ts
6119
- var SDK_VERSION = "0.12.1";
6128
+ var SDK_VERSION = "0.12.2";
6120
6129
 
6121
6130
  // src/functions/register.ts
6122
6131
  var registry = {};
@@ -6193,9 +6202,13 @@ var setupBrowserForEditing = (options = {}) => {
6193
6202
  options
6194
6203
  }
6195
6204
  }, "*");
6196
- window.addEventListener("message", ({
6197
- data
6198
- }) => {
6205
+ window.addEventListener("message", (event) => {
6206
+ if (!isFromTrustedHost(options.trustedHosts, event)) {
6207
+ return;
6208
+ }
6209
+ const {
6210
+ data
6211
+ } = event;
6199
6212
  if (!data?.type) {
6200
6213
  return;
6201
6214
  }
@@ -6293,6 +6306,9 @@ function EnableEditor(props) {
6293
6306
  }));
6294
6307
  }
6295
6308
  function processMessage(event) {
6309
+ if (!isFromTrustedHost(props.trustedHosts, event)) {
6310
+ return;
6311
+ }
6296
6312
  const { data } = event;
6297
6313
  if (data) {
6298
6314
  switch (data.type) {
@@ -6423,6 +6439,9 @@ function EnableEditor(props) {
6423
6439
  } : {},
6424
6440
  ...props.enrich ? {
6425
6441
  enrich: props.enrich
6442
+ } : {},
6443
+ ...props.trustedHosts ? {
6444
+ trustedHosts: props.trustedHosts
6426
6445
  } : {}
6427
6446
  });
6428
6447
  Object.values(
@@ -6761,6 +6780,7 @@ function ContentComponent(props) {
6761
6780
  builderContextSignal={builderContextSignal()}
6762
6781
  contentWrapper={props.contentWrapper}
6763
6782
  contentWrapperProps={props.contentWrapperProps}
6783
+ trustedHosts={props.trustedHosts}
6764
6784
  {...{
6765
6785
  setBuilderContextSignal
6766
6786
  }}
@@ -6843,6 +6863,7 @@ function ContentVariants(props) {
6843
6863
  blocksWrapperProps={props.blocksWrapperProps}
6844
6864
  contentWrapper={props.contentWrapper}
6845
6865
  contentWrapperProps={props.contentWrapperProps}
6866
+ trustedHosts={props.trustedHosts}
6846
6867
  />;
6847
6868
  }}</For5>
6848
6869
  </Show12>
@@ -6865,6 +6886,7 @@ function ContentVariants(props) {
6865
6886
  blocksWrapperProps={props.blocksWrapperProps}
6866
6887
  contentWrapper={props.contentWrapper}
6867
6888
  contentWrapperProps={props.contentWrapperProps}
6889
+ trustedHosts={props.trustedHosts}
6868
6890
  />
6869
6891
  </>;
6870
6892
  }