@builder.io/sdk-solid 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/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
 
@@ -10,7 +10,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
10
10
  throw Error('Dynamic require of "' + x + '" is not supported');
11
11
  });
12
12
  var _tmpl$ = /* @__PURE__ */ template(`<a>`);
13
- var _tmpl$2 = /* @__PURE__ */ template(`<button>`);
13
+ var _tmpl$2 = /* @__PURE__ */ template(`<button role=button>`);
14
14
  function Button(props) {
15
15
  return createComponent(Show, {
16
16
  get fallback() {
@@ -18,9 +18,7 @@ function Button(props) {
18
18
  const _el$2 = _tmpl$2();
19
19
  spread(_el$2, mergeProps({
20
20
  get ["class"]() {
21
- return props.attributes.class + " " + css({
22
- all: "unset"
23
- });
21
+ return `builder-button ${props.attributes.class}`;
24
22
  }
25
23
  }, {}, () => props.attributes, {
26
24
  get style() {
@@ -3484,10 +3482,6 @@ function getProcessedBlock({
3484
3482
  }
3485
3483
 
3486
3484
  // 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
3485
  var getComponent = ({
3492
3486
  block,
3493
3487
  context,
@@ -3670,7 +3664,7 @@ function BlockStyles(props) {
3670
3664
  }
3671
3665
  return true;
3672
3666
  }
3673
- function css5() {
3667
+ function css4() {
3674
3668
  const processedBlock = getProcessedBlock({
3675
3669
  block: props.block,
3676
3670
  localState: props.context.localState,
@@ -3707,12 +3701,12 @@ function BlockStyles(props) {
3707
3701
  }
3708
3702
  return createComponent(Show, {
3709
3703
  get when() {
3710
- return memo(() => !!(TARGET !== "reactNative" && css5()))() && canShowBlock();
3704
+ return memo(() => !!(TARGET !== "reactNative" && css4()))() && canShowBlock();
3711
3705
  },
3712
3706
  get children() {
3713
3707
  return createComponent(inlined_styles_default, {
3714
3708
  get styles() {
3715
- return css5();
3709
+ return css4();
3716
3710
  }
3717
3711
  });
3718
3712
  }
@@ -3806,48 +3800,80 @@ function getStyleAttribute(style) {
3806
3800
  }
3807
3801
  }
3808
3802
 
3809
- // src/components/block/components/block-wrapper.tsx
3810
- function BlockWrapper(props) {
3803
+ // src/components/dynamic-renderer/dynamic-renderer.helpers.ts
3804
+ var EMPTY_HTML_ELEMENTS = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]);
3805
+ var isEmptyElement = (tagName) => {
3806
+ return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.has(tagName.toLowerCase());
3807
+ };
3808
+
3809
+ // src/components/dynamic-renderer/dynamic-renderer.tsx
3810
+ function DynamicRenderer(props) {
3811
3811
  return createComponent(Show, {
3812
3812
  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
- }), {
3813
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
3824
3814
  get component() {
3825
- return props.Wrapper;
3815
+ return props.TagName;
3826
3816
  }
3827
3817
  }));
3828
3818
  },
3829
3819
  get when() {
3830
- return props.hasChildren;
3820
+ return !isEmptyElement(props.TagName);
3831
3821
  },
3832
3822
  get children() {
3833
- return createComponent(Dynamic, mergeProps(() => getBlockProperties({
3823
+ return createComponent(Show, {
3824
+ get fallback() {
3825
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
3826
+ get component() {
3827
+ return props.TagName;
3828
+ },
3829
+ get children() {
3830
+ return props.children;
3831
+ }
3832
+ }));
3833
+ },
3834
+ get when() {
3835
+ return typeof props.TagName === "string";
3836
+ },
3837
+ get children() {
3838
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
3839
+ get component() {
3840
+ return props.TagName;
3841
+ },
3842
+ get children() {
3843
+ return props.children;
3844
+ }
3845
+ }));
3846
+ }
3847
+ });
3848
+ }
3849
+ });
3850
+ }
3851
+ var dynamic_renderer_default = DynamicRenderer;
3852
+
3853
+ // src/components/block/components/block-wrapper.tsx
3854
+ function BlockWrapper(props) {
3855
+ return createComponent(dynamic_renderer_default, {
3856
+ get TagName() {
3857
+ return props.Wrapper;
3858
+ },
3859
+ get attributes() {
3860
+ return getBlockProperties({
3834
3861
  block: props.block,
3835
3862
  context: props.context
3836
- }), () => getBlockActions({
3863
+ });
3864
+ },
3865
+ get actionAttributes() {
3866
+ return getBlockActions({
3837
3867
  block: props.block,
3838
3868
  rootState: props.context.rootState,
3839
3869
  rootSetState: props.context.rootSetState,
3840
3870
  localState: props.context.localState,
3841
3871
  context: props.context.context,
3842
3872
  stripPrefix: true
3843
- }), {
3844
- get component() {
3845
- return props.Wrapper;
3846
- },
3847
- get children() {
3848
- return props.children;
3849
- }
3850
- }));
3873
+ });
3874
+ },
3875
+ get children() {
3876
+ return props.children;
3851
3877
  }
3852
3878
  });
3853
3879
  }
@@ -4088,29 +4114,8 @@ function Block(props) {
4088
4114
  return !blockComponent()?.noWrap;
4089
4115
  },
4090
4116
  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() {
4117
+ return createComponent(Show, {
4118
+ get fallback() {
4114
4119
  return createComponent(For, {
4115
4120
  get each() {
4116
4121
  return repeatItem();
@@ -4131,10 +4136,9 @@ function Block(props) {
4131
4136
  });
4132
4137
  }
4133
4138
  });
4134
- }
4135
- }), createComponent(Show, {
4139
+ },
4136
4140
  get when() {
4137
- return memo(() => !!!isEmptyHtmlElement(Tag()))() && !repeatItem();
4141
+ return !repeatItem();
4138
4142
  },
4139
4143
  get children() {
4140
4144
  return createComponent(block_wrapper_default, {
@@ -4147,7 +4151,6 @@ function Block(props) {
4147
4151
  get context() {
4148
4152
  return props.context;
4149
4153
  },
4150
- hasChildren: true,
4151
4154
  get children() {
4152
4155
  return [createComponent(component_ref_default, {
4153
4156
  get componentRef() {
@@ -4197,7 +4200,7 @@ function Block(props) {
4197
4200
  }
4198
4201
  });
4199
4202
  }
4200
- })];
4203
+ });
4201
4204
  }
4202
4205
  })];
4203
4206
  }
@@ -6186,6 +6189,13 @@ async function fetchEntries(options) {
6186
6189
  }
6187
6190
  var getAllContent = fetchEntries;
6188
6191
 
6192
+ // src/functions/is-from-trusted-host.ts
6193
+ var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
6194
+ function isFromTrustedHost(trustedHosts, e) {
6195
+ const url = new URL(e.origin), hostname = url.hostname;
6196
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
6197
+ }
6198
+
6189
6199
  // src/functions/is-previewing.ts
6190
6200
  function isPreviewing() {
6191
6201
  if (!isBrowser()) {
@@ -6434,7 +6444,7 @@ var getInteractionPropertiesForEvent = (event) => {
6434
6444
  };
6435
6445
 
6436
6446
  // src/constants/sdk-version.ts
6437
- var SDK_VERSION = "0.12.1";
6447
+ var SDK_VERSION = "0.12.3";
6438
6448
 
6439
6449
  // src/functions/register.ts
6440
6450
  var registry = {};
@@ -6511,9 +6521,13 @@ var setupBrowserForEditing = (options = {}) => {
6511
6521
  options
6512
6522
  }
6513
6523
  }, "*");
6514
- window.addEventListener("message", ({
6515
- data
6516
- }) => {
6524
+ window.addEventListener("message", (event) => {
6525
+ if (!isFromTrustedHost(options.trustedHosts, event)) {
6526
+ return;
6527
+ }
6528
+ const {
6529
+ data
6530
+ } = event;
6517
6531
  if (!data?.type) {
6518
6532
  return;
6519
6533
  }
@@ -6609,6 +6623,9 @@ function EnableEditor(props) {
6609
6623
  }));
6610
6624
  }
6611
6625
  function processMessage(event) {
6626
+ if (!isFromTrustedHost(props.trustedHosts, event)) {
6627
+ return;
6628
+ }
6612
6629
  const {
6613
6630
  data
6614
6631
  } = event;
@@ -6739,6 +6756,9 @@ function EnableEditor(props) {
6739
6756
  } : {},
6740
6757
  ...props.enrich ? {
6741
6758
  enrich: props.enrich
6759
+ } : {},
6760
+ ...props.trustedHosts ? {
6761
+ trustedHosts: props.trustedHosts
6742
6762
  } : {}
6743
6763
  });
6744
6764
  Object.values(props.builderContextSignal.componentInfos).forEach((registeredComponent) => {
@@ -6935,6 +6955,10 @@ ${getFontCss({
6935
6955
  customFonts: props.customFonts
6936
6956
  })}
6937
6957
 
6958
+ .builder-button {
6959
+ all: unset;
6960
+ }
6961
+
6938
6962
  .builder-text > p:first-of-type, .builder-text > .builder-paragraph:first-of-type {
6939
6963
  margin: 0;
6940
6964
  }
@@ -7106,6 +7130,9 @@ function ContentComponent(props) {
7106
7130
  },
7107
7131
  get contentWrapperProps() {
7108
7132
  return props.contentWrapperProps;
7133
+ },
7134
+ get trustedHosts() {
7135
+ return props.trustedHosts;
7109
7136
  }
7110
7137
  }, {
7111
7138
  setBuilderContextSignal
@@ -7265,6 +7292,9 @@ function ContentVariants(props) {
7265
7292
  },
7266
7293
  get contentWrapperProps() {
7267
7294
  return props.contentWrapperProps;
7295
+ },
7296
+ get trustedHosts() {
7297
+ return props.trustedHosts;
7268
7298
  }
7269
7299
  });
7270
7300
  }
@@ -7319,6 +7349,9 @@ function ContentVariants(props) {
7319
7349
  },
7320
7350
  get contentWrapperProps() {
7321
7351
  return props.contentWrapperProps;
7352
+ },
7353
+ get trustedHosts() {
7354
+ return props.trustedHosts;
7322
7355
  }
7323
7356
  }))];
7324
7357
  }