@builder.io/sdk-solid 0.12.0 → 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/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,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
 
@@ -333,10 +333,6 @@ function getProcessedBlock({
333
333
  }
334
334
 
335
335
  // 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
336
  var getComponent = ({
341
337
  block,
342
338
  context,
@@ -658,48 +654,80 @@ function getStyleAttribute(style) {
658
654
  }
659
655
  }
660
656
 
661
- // src/components/block/components/block-wrapper.tsx
662
- function BlockWrapper(props) {
657
+ // src/components/dynamic-renderer/dynamic-renderer.helpers.ts
658
+ var EMPTY_HTML_ELEMENTS = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]);
659
+ var isEmptyElement = (tagName) => {
660
+ return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.has(tagName.toLowerCase());
661
+ };
662
+
663
+ // src/components/dynamic-renderer/dynamic-renderer.tsx
664
+ function DynamicRenderer(props) {
663
665
  return createComponent(Show, {
664
666
  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
- }), {
667
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
676
668
  get component() {
677
- return props.Wrapper;
669
+ return props.TagName;
678
670
  }
679
671
  }));
680
672
  },
681
673
  get when() {
682
- return props.hasChildren;
674
+ return !isEmptyElement(props.TagName);
683
675
  },
684
676
  get children() {
685
- return createComponent(Dynamic, mergeProps(() => getBlockProperties({
677
+ return createComponent(Show, {
678
+ get fallback() {
679
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
680
+ get component() {
681
+ return props.TagName;
682
+ },
683
+ get children() {
684
+ return props.children;
685
+ }
686
+ }));
687
+ },
688
+ get when() {
689
+ return typeof props.TagName === "string";
690
+ },
691
+ get children() {
692
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
693
+ get component() {
694
+ return props.TagName;
695
+ },
696
+ get children() {
697
+ return props.children;
698
+ }
699
+ }));
700
+ }
701
+ });
702
+ }
703
+ });
704
+ }
705
+ var dynamic_renderer_default = DynamicRenderer;
706
+
707
+ // src/components/block/components/block-wrapper.tsx
708
+ function BlockWrapper(props) {
709
+ return createComponent(dynamic_renderer_default, {
710
+ get TagName() {
711
+ return props.Wrapper;
712
+ },
713
+ get attributes() {
714
+ return getBlockProperties({
686
715
  block: props.block,
687
716
  context: props.context
688
- }), () => getBlockActions({
717
+ });
718
+ },
719
+ get actionAttributes() {
720
+ return getBlockActions({
689
721
  block: props.block,
690
722
  rootState: props.context.rootState,
691
723
  rootSetState: props.context.rootSetState,
692
724
  localState: props.context.localState,
693
725
  context: props.context.context,
694
726
  stripPrefix: true
695
- }), {
696
- get component() {
697
- return props.Wrapper;
698
- },
699
- get children() {
700
- return props.children;
701
- }
702
- }));
727
+ });
728
+ },
729
+ get children() {
730
+ return props.children;
703
731
  }
704
732
  });
705
733
  }
@@ -940,29 +968,8 @@ function Block(props) {
940
968
  return !blockComponent()?.noWrap;
941
969
  },
942
970
  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() {
971
+ return createComponent(Show, {
972
+ get fallback() {
966
973
  return createComponent(For, {
967
974
  get each() {
968
975
  return repeatItem();
@@ -983,10 +990,9 @@ function Block(props) {
983
990
  });
984
991
  }
985
992
  });
986
- }
987
- }), createComponent(Show, {
993
+ },
988
994
  get when() {
989
- return memo(() => !!!isEmptyHtmlElement(Tag()))() && !repeatItem();
995
+ return !repeatItem();
990
996
  },
991
997
  get children() {
992
998
  return createComponent(block_wrapper_default, {
@@ -999,7 +1005,6 @@ function Block(props) {
999
1005
  get context() {
1000
1006
  return props.context;
1001
1007
  },
1002
- hasChildren: true,
1003
1008
  get children() {
1004
1009
  return [createComponent(component_ref_default, {
1005
1010
  get componentRef() {
@@ -1049,7 +1054,7 @@ function Block(props) {
1049
1054
  }
1050
1055
  });
1051
1056
  }
1052
- })];
1057
+ });
1053
1058
  }
1054
1059
  })];
1055
1060
  }
@@ -2375,8 +2380,50 @@ var componentInfo8 = {
2375
2380
  }]
2376
2381
  };
2377
2382
 
2378
- // src/blocks/symbol/component-info.ts
2383
+ // src/blocks/slot/component-info.ts
2379
2384
  var componentInfo9 = {
2385
+ name: "Slot",
2386
+ isRSC: true,
2387
+ description: "Allow child blocks to be inserted into this content when used as a Symbol",
2388
+ docsLink: "https://www.builder.io/c/docs/symbols-with-blocks",
2389
+ image: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F3aad6de36eae43b59b52c85190fdef56",
2390
+ // Maybe wrap this for canHaveChildren so bind children to this hm
2391
+ inputs: [{
2392
+ name: "name",
2393
+ type: "string",
2394
+ required: true,
2395
+ defaultValue: "children"
2396
+ }]
2397
+ };
2398
+ var _tmpl$11 = /* @__PURE__ */ template(`<div>`);
2399
+ function Slot(props) {
2400
+ return (() => {
2401
+ const _el$ = _tmpl$11();
2402
+ _el$.style.setProperty("pointer-events", "auto");
2403
+ spread(_el$, mergeProps(() => !props.builderContext.context?.symbolId && {
2404
+ "builder-slot": props.name
2405
+ }), false, true);
2406
+ insert(_el$, createComponent(blocks_default, {
2407
+ get parent() {
2408
+ return props.builderContext.context?.symbolId;
2409
+ },
2410
+ get path() {
2411
+ return `symbol.data.${props.name}`;
2412
+ },
2413
+ get context() {
2414
+ return props.builderContext;
2415
+ },
2416
+ get blocks() {
2417
+ return props.builderContext.rootState?.[props.name];
2418
+ }
2419
+ }));
2420
+ return _el$;
2421
+ })();
2422
+ }
2423
+ var slot_default = Slot;
2424
+
2425
+ // src/blocks/symbol/component-info.ts
2426
+ var componentInfo10 = {
2380
2427
  name: "Symbol",
2381
2428
  noWrap: true,
2382
2429
  static: true,
@@ -2412,7 +2459,7 @@ var componentInfo9 = {
2412
2459
  };
2413
2460
 
2414
2461
  // src/blocks/text/component-info.ts
2415
- var componentInfo10 = {
2462
+ var componentInfo11 = {
2416
2463
  name: "Text",
2417
2464
  static: true,
2418
2465
  isRSC: true,
@@ -2431,10 +2478,10 @@ var componentInfo10 = {
2431
2478
  textAlign: "center"
2432
2479
  }
2433
2480
  };
2434
- var _tmpl$11 = /* @__PURE__ */ template(`<div class=builder-text>`);
2481
+ var _tmpl$12 = /* @__PURE__ */ template(`<div class=builder-text>`);
2435
2482
  function Text(props) {
2436
2483
  return (() => {
2437
- const _el$ = _tmpl$11();
2484
+ const _el$ = _tmpl$12();
2438
2485
  _el$.style.setProperty("outline", "none");
2439
2486
  effect(() => _el$.innerHTML = props.text?.toString() || "");
2440
2487
  return _el$;
@@ -2443,7 +2490,7 @@ function Text(props) {
2443
2490
  var text_default = Text;
2444
2491
 
2445
2492
  // src/blocks/video/component-info.ts
2446
- var componentInfo11 = {
2493
+ var componentInfo12 = {
2447
2494
  name: "Video",
2448
2495
  canHaveChildren: true,
2449
2496
  defaultStyles: {
@@ -2525,7 +2572,7 @@ var componentInfo11 = {
2525
2572
  advanced: true
2526
2573
  }]
2527
2574
  };
2528
- var _tmpl$12 = /* @__PURE__ */ template(`<source type=video/mp4>`);
2575
+ var _tmpl$13 = /* @__PURE__ */ template(`<source type=video/mp4>`);
2529
2576
  var _tmpl$23 = /* @__PURE__ */ template(`<div>`);
2530
2577
  var _tmpl$33 = /* @__PURE__ */ template(`<div><video class=builder-video>`);
2531
2578
  function Video(props) {
@@ -2588,7 +2635,7 @@ function Video(props) {
2588
2635
  return !props.lazyLoad;
2589
2636
  },
2590
2637
  get children() {
2591
- const _el$3 = _tmpl$12();
2638
+ const _el$3 = _tmpl$13();
2592
2639
  effect(() => setAttribute(_el$3, "src", props.video));
2593
2640
  return _el$3;
2594
2641
  }
@@ -2670,13 +2717,16 @@ var getDefaultRegisteredComponents = () => [{
2670
2717
  ...componentInfo8
2671
2718
  }, {
2672
2719
  component: symbol_default,
2673
- ...componentInfo9
2720
+ ...componentInfo10
2674
2721
  }, {
2675
2722
  component: text_default,
2676
- ...componentInfo10
2723
+ ...componentInfo11
2677
2724
  }, {
2678
2725
  component: video_default,
2679
- ...componentInfo11
2726
+ ...componentInfo12
2727
+ }, {
2728
+ component: slot_default,
2729
+ ...componentInfo9
2680
2730
  }];
2681
2731
 
2682
2732
  // src/functions/register-component.ts
@@ -2747,10 +2797,10 @@ var getUpdateVariantVisibilityScript = ({
2747
2797
  }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
2748
2798
  "${variationId}", "${contentId}", ${isHydrationTarget}
2749
2799
  )`;
2750
- var _tmpl$13 = /* @__PURE__ */ template(`<script>`);
2800
+ var _tmpl$14 = /* @__PURE__ */ template(`<script>`);
2751
2801
  function InlinedScript(props) {
2752
2802
  return (() => {
2753
- const _el$ = _tmpl$13();
2803
+ const _el$ = _tmpl$14();
2754
2804
  effect((_p$) => {
2755
2805
  const _v$ = props.scriptStr, _v$2 = props.id || "";
2756
2806
  _v$ !== _p$._v$ && (_el$.innerHTML = _p$._v$ = _v$);
@@ -2999,6 +3049,13 @@ async function fetchEntries(options) {
2999
3049
  }
3000
3050
  var getAllContent = fetchEntries;
3001
3051
 
3052
+ // src/functions/is-from-trusted-host.ts
3053
+ var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
3054
+ function isFromTrustedHost(trustedHosts, e) {
3055
+ const url = new URL(e.origin), hostname = url.hostname;
3056
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
3057
+ }
3058
+
3002
3059
  // src/functions/is-previewing.ts
3003
3060
  function isPreviewing() {
3004
3061
  if (!isBrowser()) {
@@ -3250,7 +3307,7 @@ var getInteractionPropertiesForEvent = (event) => {
3250
3307
  };
3251
3308
 
3252
3309
  // src/constants/sdk-version.ts
3253
- var SDK_VERSION = "0.12.0";
3310
+ var SDK_VERSION = "0.12.2";
3254
3311
 
3255
3312
  // src/functions/register.ts
3256
3313
  var registry = {};
@@ -3328,9 +3385,13 @@ var setupBrowserForEditing = (options = {}) => {
3328
3385
  options
3329
3386
  }
3330
3387
  }, "*");
3331
- window.addEventListener("message", ({
3332
- data
3333
- }) => {
3388
+ window.addEventListener("message", (event) => {
3389
+ if (!isFromTrustedHost(options.trustedHosts, event)) {
3390
+ return;
3391
+ }
3392
+ const {
3393
+ data
3394
+ } = event;
3334
3395
  if (!data?.type) {
3335
3396
  return;
3336
3397
  }
@@ -3426,6 +3487,9 @@ function EnableEditor(props) {
3426
3487
  }));
3427
3488
  }
3428
3489
  function processMessage(event) {
3490
+ if (!isFromTrustedHost(props.trustedHosts, event)) {
3491
+ return;
3492
+ }
3429
3493
  const {
3430
3494
  data
3431
3495
  } = event;
@@ -3557,6 +3621,9 @@ function EnableEditor(props) {
3557
3621
  } : {},
3558
3622
  ...props.enrich ? {
3559
3623
  enrich: props.enrich
3624
+ } : {},
3625
+ ...props.trustedHosts ? {
3626
+ trustedHosts: props.trustedHosts
3560
3627
  } : {}
3561
3628
  });
3562
3629
  Object.values(props.builderContextSignal.componentInfos).forEach((registeredComponent) => {
@@ -3924,6 +3991,9 @@ function ContentComponent(props) {
3924
3991
  },
3925
3992
  get contentWrapperProps() {
3926
3993
  return props.contentWrapperProps;
3994
+ },
3995
+ get trustedHosts() {
3996
+ return props.trustedHosts;
3927
3997
  }
3928
3998
  }, {
3929
3999
  setBuilderContextSignal
@@ -4083,6 +4153,9 @@ function ContentVariants(props) {
4083
4153
  },
4084
4154
  get contentWrapperProps() {
4085
4155
  return props.contentWrapperProps;
4156
+ },
4157
+ get trustedHosts() {
4158
+ return props.trustedHosts;
4086
4159
  }
4087
4160
  });
4088
4161
  }
@@ -4137,6 +4210,9 @@ function ContentVariants(props) {
4137
4210
  },
4138
4211
  get contentWrapperProps() {
4139
4212
  return props.contentWrapperProps;
4213
+ },
4214
+ get trustedHosts() {
4215
+ return props.trustedHosts;
4140
4216
  }
4141
4217
  }))];
4142
4218
  }
@@ -4167,7 +4243,7 @@ var fetchSymbolContent = async ({
4167
4243
  };
4168
4244
 
4169
4245
  // src/blocks/symbol/symbol.tsx
4170
- var _tmpl$14 = /* @__PURE__ */ template(`<div>`);
4246
+ var _tmpl$15 = /* @__PURE__ */ template(`<div>`);
4171
4247
  function Symbol(props) {
4172
4248
  const [contentToUse, setContentToUse] = createSignal(props.symbol?.content);
4173
4249
  function className() {
@@ -4193,7 +4269,7 @@ function Symbol(props) {
4193
4269
  }
4194
4270
  createEffect(on(() => [props.symbol], onUpdateFn_0));
4195
4271
  return (() => {
4196
- const _el$ = _tmpl$14();
4272
+ const _el$ = _tmpl$15();
4197
4273
  spread(_el$, mergeProps({
4198
4274
  get ["class"]() {
4199
4275
  return className();
@@ -4208,7 +4284,10 @@ function Symbol(props) {
4208
4284
  return props.builderContext.apiKey;
4209
4285
  },
4210
4286
  get context() {
4211
- return props.builderContext.context;
4287
+ return {
4288
+ ...props.builderContext.context,
4289
+ symbolId: props.builderBlock?.id
4290
+ };
4212
4291
  },
4213
4292
  get customComponents() {
4214
4293
  return Object.values(props.builderComponents);