@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/node/dev.js CHANGED
@@ -1,11 +1,11 @@
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
  import { createRequire } from 'node:module';
5
5
 
6
6
  // src/blocks/button/button.tsx
7
7
  var _tmpl$ = /* @__PURE__ */ template(`<a>`);
8
- var _tmpl$2 = /* @__PURE__ */ template(`<button>`);
8
+ var _tmpl$2 = /* @__PURE__ */ template(`<button role=button>`);
9
9
  function Button(props) {
10
10
  return createComponent(Show, {
11
11
  get fallback() {
@@ -13,9 +13,7 @@ function Button(props) {
13
13
  const _el$2 = _tmpl$2();
14
14
  spread(_el$2, mergeProps({
15
15
  get ["class"]() {
16
- return props.attributes.class + " " + css({
17
- all: "unset"
18
- });
16
+ return `builder-button ${props.attributes.class}`;
19
17
  }
20
18
  }, {}, () => props.attributes, {
21
19
  get style() {
@@ -457,10 +455,6 @@ function getProcessedBlock({
457
455
  }
458
456
 
459
457
  // src/components/block/block.helpers.ts
460
- var EMPTY_HTML_ELEMENTS = ["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"];
461
- var isEmptyHtmlElement = (tagName) => {
462
- return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase());
463
- };
464
458
  var getComponent = ({
465
459
  block,
466
460
  context,
@@ -646,7 +640,7 @@ function BlockStyles(props) {
646
640
  }
647
641
  return true;
648
642
  }
649
- function css5() {
643
+ function css4() {
650
644
  const processedBlock = getProcessedBlock({
651
645
  block: props.block,
652
646
  localState: props.context.localState,
@@ -683,12 +677,12 @@ function BlockStyles(props) {
683
677
  }
684
678
  return createComponent(Show, {
685
679
  get when() {
686
- return memo(() => !!(TARGET !== "reactNative" && css5()))() && canShowBlock();
680
+ return memo(() => !!(TARGET !== "reactNative" && css4()))() && canShowBlock();
687
681
  },
688
682
  get children() {
689
683
  return createComponent(inlined_styles_default, {
690
684
  get styles() {
691
- return css5();
685
+ return css4();
692
686
  }
693
687
  });
694
688
  }
@@ -782,48 +776,80 @@ function getStyleAttribute(style) {
782
776
  }
783
777
  }
784
778
 
785
- // src/components/block/components/block-wrapper.tsx
786
- function BlockWrapper(props) {
779
+ // src/components/dynamic-renderer/dynamic-renderer.helpers.ts
780
+ var EMPTY_HTML_ELEMENTS = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]);
781
+ var isEmptyElement = (tagName) => {
782
+ return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.has(tagName.toLowerCase());
783
+ };
784
+
785
+ // src/components/dynamic-renderer/dynamic-renderer.tsx
786
+ function DynamicRenderer(props) {
787
787
  return createComponent(Show, {
788
788
  get fallback() {
789
- return createComponent(Dynamic, mergeProps(() => getBlockProperties({
790
- block: props.block,
791
- context: props.context
792
- }), () => getBlockActions({
793
- block: props.block,
794
- rootState: props.context.rootState,
795
- rootSetState: props.context.rootSetState,
796
- localState: props.context.localState,
797
- context: props.context.context,
798
- stripPrefix: true
799
- }), {
789
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
800
790
  get component() {
801
- return props.Wrapper;
791
+ return props.TagName;
802
792
  }
803
793
  }));
804
794
  },
805
795
  get when() {
806
- return props.hasChildren;
796
+ return !isEmptyElement(props.TagName);
807
797
  },
808
798
  get children() {
809
- return createComponent(Dynamic, mergeProps(() => getBlockProperties({
799
+ return createComponent(Show, {
800
+ get fallback() {
801
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
802
+ get component() {
803
+ return props.TagName;
804
+ },
805
+ get children() {
806
+ return props.children;
807
+ }
808
+ }));
809
+ },
810
+ get when() {
811
+ return typeof props.TagName === "string";
812
+ },
813
+ get children() {
814
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
815
+ get component() {
816
+ return props.TagName;
817
+ },
818
+ get children() {
819
+ return props.children;
820
+ }
821
+ }));
822
+ }
823
+ });
824
+ }
825
+ });
826
+ }
827
+ var dynamic_renderer_default = DynamicRenderer;
828
+
829
+ // src/components/block/components/block-wrapper.tsx
830
+ function BlockWrapper(props) {
831
+ return createComponent(dynamic_renderer_default, {
832
+ get TagName() {
833
+ return props.Wrapper;
834
+ },
835
+ get attributes() {
836
+ return getBlockProperties({
810
837
  block: props.block,
811
838
  context: props.context
812
- }), () => getBlockActions({
839
+ });
840
+ },
841
+ get actionAttributes() {
842
+ return getBlockActions({
813
843
  block: props.block,
814
844
  rootState: props.context.rootState,
815
845
  rootSetState: props.context.rootSetState,
816
846
  localState: props.context.localState,
817
847
  context: props.context.context,
818
848
  stripPrefix: true
819
- }), {
820
- get component() {
821
- return props.Wrapper;
822
- },
823
- get children() {
824
- return props.children;
825
- }
826
- }));
849
+ });
850
+ },
851
+ get children() {
852
+ return props.children;
827
853
  }
828
854
  });
829
855
  }
@@ -1064,29 +1090,8 @@ function Block(props) {
1064
1090
  return !blockComponent()?.noWrap;
1065
1091
  },
1066
1092
  get children() {
1067
- return [createComponent(Show, {
1068
- get when() {
1069
- return isEmptyHtmlElement(Tag());
1070
- },
1071
- get children() {
1072
- return createComponent(block_wrapper_default, {
1073
- get Wrapper() {
1074
- return Tag();
1075
- },
1076
- get block() {
1077
- return processedBlock();
1078
- },
1079
- get context() {
1080
- return props.context;
1081
- },
1082
- hasChildren: false
1083
- });
1084
- }
1085
- }), createComponent(Show, {
1086
- get when() {
1087
- return memo(() => !!!isEmptyHtmlElement(Tag()))() && repeatItem();
1088
- },
1089
- get children() {
1093
+ return createComponent(Show, {
1094
+ get fallback() {
1090
1095
  return createComponent(For, {
1091
1096
  get each() {
1092
1097
  return repeatItem();
@@ -1107,10 +1112,9 @@ function Block(props) {
1107
1112
  });
1108
1113
  }
1109
1114
  });
1110
- }
1111
- }), createComponent(Show, {
1115
+ },
1112
1116
  get when() {
1113
- return memo(() => !!!isEmptyHtmlElement(Tag()))() && !repeatItem();
1117
+ return !repeatItem();
1114
1118
  },
1115
1119
  get children() {
1116
1120
  return createComponent(block_wrapper_default, {
@@ -1123,7 +1127,6 @@ function Block(props) {
1123
1127
  get context() {
1124
1128
  return props.context;
1125
1129
  },
1126
- hasChildren: true,
1127
1130
  get children() {
1128
1131
  return [createComponent(component_ref_default, {
1129
1132
  get componentRef() {
@@ -1173,7 +1176,7 @@ function Block(props) {
1173
1176
  }
1174
1177
  });
1175
1178
  }
1176
- })];
1179
+ });
1177
1180
  }
1178
1181
  })];
1179
1182
  }
@@ -3168,6 +3171,13 @@ async function fetchEntries(options) {
3168
3171
  }
3169
3172
  var getAllContent = fetchEntries;
3170
3173
 
3174
+ // src/functions/is-from-trusted-host.ts
3175
+ var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
3176
+ function isFromTrustedHost(trustedHosts, e) {
3177
+ const url = new URL(e.origin), hostname = url.hostname;
3178
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
3179
+ }
3180
+
3171
3181
  // src/functions/is-previewing.ts
3172
3182
  function isPreviewing() {
3173
3183
  if (!isBrowser()) {
@@ -3419,7 +3429,7 @@ var getInteractionPropertiesForEvent = (event) => {
3419
3429
  };
3420
3430
 
3421
3431
  // src/constants/sdk-version.ts
3422
- var SDK_VERSION = "0.12.1";
3432
+ var SDK_VERSION = "0.12.3";
3423
3433
 
3424
3434
  // src/functions/register.ts
3425
3435
  var registry = {};
@@ -3497,9 +3507,13 @@ var setupBrowserForEditing = (options = {}) => {
3497
3507
  options
3498
3508
  }
3499
3509
  }, "*");
3500
- window.addEventListener("message", ({
3501
- data
3502
- }) => {
3510
+ window.addEventListener("message", (event) => {
3511
+ if (!isFromTrustedHost(options.trustedHosts, event)) {
3512
+ return;
3513
+ }
3514
+ const {
3515
+ data
3516
+ } = event;
3503
3517
  if (!data?.type) {
3504
3518
  return;
3505
3519
  }
@@ -3595,6 +3609,9 @@ function EnableEditor(props) {
3595
3609
  }));
3596
3610
  }
3597
3611
  function processMessage(event) {
3612
+ if (!isFromTrustedHost(props.trustedHosts, event)) {
3613
+ return;
3614
+ }
3598
3615
  const {
3599
3616
  data
3600
3617
  } = event;
@@ -3726,6 +3743,9 @@ function EnableEditor(props) {
3726
3743
  } : {},
3727
3744
  ...props.enrich ? {
3728
3745
  enrich: props.enrich
3746
+ } : {},
3747
+ ...props.trustedHosts ? {
3748
+ trustedHosts: props.trustedHosts
3729
3749
  } : {}
3730
3750
  });
3731
3751
  Object.values(props.builderContextSignal.componentInfos).forEach((registeredComponent) => {
@@ -3922,6 +3942,10 @@ ${getFontCss({
3922
3942
  customFonts: props.customFonts
3923
3943
  })}
3924
3944
 
3945
+ .builder-button {
3946
+ all: unset;
3947
+ }
3948
+
3925
3949
  .builder-text > p:first-of-type, .builder-text > .builder-paragraph:first-of-type {
3926
3950
  margin: 0;
3927
3951
  }
@@ -4093,6 +4117,9 @@ function ContentComponent(props) {
4093
4117
  },
4094
4118
  get contentWrapperProps() {
4095
4119
  return props.contentWrapperProps;
4120
+ },
4121
+ get trustedHosts() {
4122
+ return props.trustedHosts;
4096
4123
  }
4097
4124
  }, {
4098
4125
  setBuilderContextSignal
@@ -4252,6 +4279,9 @@ function ContentVariants(props) {
4252
4279
  },
4253
4280
  get contentWrapperProps() {
4254
4281
  return props.contentWrapperProps;
4282
+ },
4283
+ get trustedHosts() {
4284
+ return props.trustedHosts;
4255
4285
  }
4256
4286
  });
4257
4287
  }
@@ -4306,6 +4336,9 @@ function ContentVariants(props) {
4306
4336
  },
4307
4337
  get contentWrapperProps() {
4308
4338
  return props.contentWrapperProps;
4339
+ },
4340
+ get trustedHosts() {
4341
+ return props.trustedHosts;
4309
4342
  }
4310
4343
  }))];
4311
4344
  }