@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/dist/index.d.ts CHANGED
@@ -635,6 +635,10 @@ interface ContentVariantsPrps {
635
635
  * Additonal props to pass to `blocksWrapper`. Defaults to `{}`.
636
636
  */
637
637
  blocksWrapperProps?: any;
638
+ /**
639
+ * List of hosts to allow editing content from.
640
+ */
641
+ trustedHosts?: string[];
638
642
  }
639
643
 
640
644
  type VariantsProviderProps = ContentVariantsPrps & {
@@ -1,10 +1,10 @@
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
 
5
5
  // src/blocks/button/button.tsx
6
6
  var _tmpl$ = /* @__PURE__ */ template(`<a>`);
7
- var _tmpl$2 = /* @__PURE__ */ template(`<button>`);
7
+ var _tmpl$2 = /* @__PURE__ */ template(`<button role=button>`);
8
8
  function Button(props) {
9
9
  return createComponent(Show, {
10
10
  get fallback() {
@@ -12,9 +12,7 @@ function Button(props) {
12
12
  const _el$2 = _tmpl$2();
13
13
  spread(_el$2, mergeProps({
14
14
  get ["class"]() {
15
- return props.attributes.class + " " + css({
16
- all: "unset"
17
- });
15
+ return `builder-button ${props.attributes.class}`;
18
16
  }
19
17
  }, {}, () => props.attributes, {
20
18
  get style() {
@@ -333,10 +331,6 @@ function getProcessedBlock({
333
331
  }
334
332
 
335
333
  // src/components/block/block.helpers.ts
336
- var EMPTY_HTML_ELEMENTS = ["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"];
337
- var isEmptyHtmlElement = (tagName) => {
338
- return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase());
339
- };
340
334
  var getComponent = ({
341
335
  block,
342
336
  context,
@@ -522,7 +516,7 @@ function BlockStyles(props) {
522
516
  }
523
517
  return true;
524
518
  }
525
- function css5() {
519
+ function css4() {
526
520
  const processedBlock = getProcessedBlock({
527
521
  block: props.block,
528
522
  localState: props.context.localState,
@@ -559,12 +553,12 @@ function BlockStyles(props) {
559
553
  }
560
554
  return createComponent(Show, {
561
555
  get when() {
562
- return memo(() => !!(TARGET !== "reactNative" && css5()))() && canShowBlock();
556
+ return memo(() => !!(TARGET !== "reactNative" && css4()))() && canShowBlock();
563
557
  },
564
558
  get children() {
565
559
  return createComponent(inlined_styles_default, {
566
560
  get styles() {
567
- return css5();
561
+ return css4();
568
562
  }
569
563
  });
570
564
  }
@@ -658,48 +652,80 @@ function getStyleAttribute(style) {
658
652
  }
659
653
  }
660
654
 
661
- // src/components/block/components/block-wrapper.tsx
662
- function BlockWrapper(props) {
655
+ // src/components/dynamic-renderer/dynamic-renderer.helpers.ts
656
+ var EMPTY_HTML_ELEMENTS = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]);
657
+ var isEmptyElement = (tagName) => {
658
+ return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.has(tagName.toLowerCase());
659
+ };
660
+
661
+ // src/components/dynamic-renderer/dynamic-renderer.tsx
662
+ function DynamicRenderer(props) {
663
663
  return createComponent(Show, {
664
664
  get fallback() {
665
- return createComponent(Dynamic, mergeProps(() => getBlockProperties({
666
- block: props.block,
667
- context: props.context
668
- }), () => getBlockActions({
669
- block: props.block,
670
- rootState: props.context.rootState,
671
- rootSetState: props.context.rootSetState,
672
- localState: props.context.localState,
673
- context: props.context.context,
674
- stripPrefix: true
675
- }), {
665
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
676
666
  get component() {
677
- return props.Wrapper;
667
+ return props.TagName;
678
668
  }
679
669
  }));
680
670
  },
681
671
  get when() {
682
- return props.hasChildren;
672
+ return !isEmptyElement(props.TagName);
683
673
  },
684
674
  get children() {
685
- return createComponent(Dynamic, mergeProps(() => getBlockProperties({
675
+ return createComponent(Show, {
676
+ get fallback() {
677
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
678
+ get component() {
679
+ return props.TagName;
680
+ },
681
+ get children() {
682
+ return props.children;
683
+ }
684
+ }));
685
+ },
686
+ get when() {
687
+ return typeof props.TagName === "string";
688
+ },
689
+ get children() {
690
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
691
+ get component() {
692
+ return props.TagName;
693
+ },
694
+ get children() {
695
+ return props.children;
696
+ }
697
+ }));
698
+ }
699
+ });
700
+ }
701
+ });
702
+ }
703
+ var dynamic_renderer_default = DynamicRenderer;
704
+
705
+ // src/components/block/components/block-wrapper.tsx
706
+ function BlockWrapper(props) {
707
+ return createComponent(dynamic_renderer_default, {
708
+ get TagName() {
709
+ return props.Wrapper;
710
+ },
711
+ get attributes() {
712
+ return getBlockProperties({
686
713
  block: props.block,
687
714
  context: props.context
688
- }), () => getBlockActions({
715
+ });
716
+ },
717
+ get actionAttributes() {
718
+ return getBlockActions({
689
719
  block: props.block,
690
720
  rootState: props.context.rootState,
691
721
  rootSetState: props.context.rootSetState,
692
722
  localState: props.context.localState,
693
723
  context: props.context.context,
694
724
  stripPrefix: true
695
- }), {
696
- get component() {
697
- return props.Wrapper;
698
- },
699
- get children() {
700
- return props.children;
701
- }
702
- }));
725
+ });
726
+ },
727
+ get children() {
728
+ return props.children;
703
729
  }
704
730
  });
705
731
  }
@@ -940,29 +966,8 @@ function Block(props) {
940
966
  return !blockComponent()?.noWrap;
941
967
  },
942
968
  get children() {
943
- return [createComponent(Show, {
944
- get when() {
945
- return isEmptyHtmlElement(Tag());
946
- },
947
- get children() {
948
- return createComponent(block_wrapper_default, {
949
- get Wrapper() {
950
- return Tag();
951
- },
952
- get block() {
953
- return processedBlock();
954
- },
955
- get context() {
956
- return props.context;
957
- },
958
- hasChildren: false
959
- });
960
- }
961
- }), createComponent(Show, {
962
- get when() {
963
- return memo(() => !!!isEmptyHtmlElement(Tag()))() && repeatItem();
964
- },
965
- get children() {
969
+ return createComponent(Show, {
970
+ get fallback() {
966
971
  return createComponent(For, {
967
972
  get each() {
968
973
  return repeatItem();
@@ -983,10 +988,9 @@ function Block(props) {
983
988
  });
984
989
  }
985
990
  });
986
- }
987
- }), createComponent(Show, {
991
+ },
988
992
  get when() {
989
- return memo(() => !!!isEmptyHtmlElement(Tag()))() && !repeatItem();
993
+ return !repeatItem();
990
994
  },
991
995
  get children() {
992
996
  return createComponent(block_wrapper_default, {
@@ -999,7 +1003,6 @@ function Block(props) {
999
1003
  get context() {
1000
1004
  return props.context;
1001
1005
  },
1002
- hasChildren: true,
1003
1006
  get children() {
1004
1007
  return [createComponent(component_ref_default, {
1005
1008
  get componentRef() {
@@ -1049,7 +1052,7 @@ function Block(props) {
1049
1052
  }
1050
1053
  });
1051
1054
  }
1052
- })];
1055
+ });
1053
1056
  }
1054
1057
  })];
1055
1058
  }
@@ -3044,6 +3047,13 @@ async function fetchEntries(options) {
3044
3047
  }
3045
3048
  var getAllContent = fetchEntries;
3046
3049
 
3050
+ // src/functions/is-from-trusted-host.ts
3051
+ var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
3052
+ function isFromTrustedHost(trustedHosts, e) {
3053
+ const url = new URL(e.origin), hostname = url.hostname;
3054
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
3055
+ }
3056
+
3047
3057
  // src/functions/is-previewing.ts
3048
3058
  function isPreviewing() {
3049
3059
  if (!isBrowser()) {
@@ -3295,7 +3305,7 @@ var getInteractionPropertiesForEvent = (event) => {
3295
3305
  };
3296
3306
 
3297
3307
  // src/constants/sdk-version.ts
3298
- var SDK_VERSION = "0.12.1";
3308
+ var SDK_VERSION = "0.12.3";
3299
3309
 
3300
3310
  // src/functions/register.ts
3301
3311
  var registry = {};
@@ -3373,9 +3383,13 @@ var setupBrowserForEditing = (options = {}) => {
3373
3383
  options
3374
3384
  }
3375
3385
  }, "*");
3376
- window.addEventListener("message", ({
3377
- data
3378
- }) => {
3386
+ window.addEventListener("message", (event) => {
3387
+ if (!isFromTrustedHost(options.trustedHosts, event)) {
3388
+ return;
3389
+ }
3390
+ const {
3391
+ data
3392
+ } = event;
3379
3393
  if (!data?.type) {
3380
3394
  return;
3381
3395
  }
@@ -3471,6 +3485,9 @@ function EnableEditor(props) {
3471
3485
  }));
3472
3486
  }
3473
3487
  function processMessage(event) {
3488
+ if (!isFromTrustedHost(props.trustedHosts, event)) {
3489
+ return;
3490
+ }
3474
3491
  const {
3475
3492
  data
3476
3493
  } = event;
@@ -3602,6 +3619,9 @@ function EnableEditor(props) {
3602
3619
  } : {},
3603
3620
  ...props.enrich ? {
3604
3621
  enrich: props.enrich
3622
+ } : {},
3623
+ ...props.trustedHosts ? {
3624
+ trustedHosts: props.trustedHosts
3605
3625
  } : {}
3606
3626
  });
3607
3627
  Object.values(props.builderContextSignal.componentInfos).forEach((registeredComponent) => {
@@ -3798,6 +3818,10 @@ ${getFontCss({
3798
3818
  customFonts: props.customFonts
3799
3819
  })}
3800
3820
 
3821
+ .builder-button {
3822
+ all: unset;
3823
+ }
3824
+
3801
3825
  .builder-text > p:first-of-type, .builder-text > .builder-paragraph:first-of-type {
3802
3826
  margin: 0;
3803
3827
  }
@@ -3969,6 +3993,9 @@ function ContentComponent(props) {
3969
3993
  },
3970
3994
  get contentWrapperProps() {
3971
3995
  return props.contentWrapperProps;
3996
+ },
3997
+ get trustedHosts() {
3998
+ return props.trustedHosts;
3972
3999
  }
3973
4000
  }, {
3974
4001
  setBuilderContextSignal
@@ -4128,6 +4155,9 @@ function ContentVariants(props) {
4128
4155
  },
4129
4156
  get contentWrapperProps() {
4130
4157
  return props.contentWrapperProps;
4158
+ },
4159
+ get trustedHosts() {
4160
+ return props.trustedHosts;
4131
4161
  }
4132
4162
  });
4133
4163
  }
@@ -4182,6 +4212,9 @@ function ContentVariants(props) {
4182
4212
  },
4183
4213
  get contentWrapperProps() {
4184
4214
  return props.contentWrapperProps;
4215
+ },
4216
+ get trustedHosts() {
4217
+ return props.trustedHosts;
4185
4218
  }
4186
4219
  }))];
4187
4220
  }