@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/lib/node/dev.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
  import { createRequire } from 'node:module';
@@ -457,10 +457,6 @@ function getProcessedBlock({
457
457
  }
458
458
 
459
459
  // 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
460
  var getComponent = ({
465
461
  block,
466
462
  context,
@@ -782,48 +778,80 @@ function getStyleAttribute(style) {
782
778
  }
783
779
  }
784
780
 
785
- // src/components/block/components/block-wrapper.tsx
786
- function BlockWrapper(props) {
781
+ // src/components/dynamic-renderer/dynamic-renderer.helpers.ts
782
+ var EMPTY_HTML_ELEMENTS = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]);
783
+ var isEmptyElement = (tagName) => {
784
+ return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.has(tagName.toLowerCase());
785
+ };
786
+
787
+ // src/components/dynamic-renderer/dynamic-renderer.tsx
788
+ function DynamicRenderer(props) {
787
789
  return createComponent(Show, {
788
790
  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
- }), {
791
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
800
792
  get component() {
801
- return props.Wrapper;
793
+ return props.TagName;
802
794
  }
803
795
  }));
804
796
  },
805
797
  get when() {
806
- return props.hasChildren;
798
+ return !isEmptyElement(props.TagName);
807
799
  },
808
800
  get children() {
809
- return createComponent(Dynamic, mergeProps(() => getBlockProperties({
801
+ return createComponent(Show, {
802
+ get fallback() {
803
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
804
+ get component() {
805
+ return props.TagName;
806
+ },
807
+ get children() {
808
+ return props.children;
809
+ }
810
+ }));
811
+ },
812
+ get when() {
813
+ return typeof props.TagName === "string";
814
+ },
815
+ get children() {
816
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
817
+ get component() {
818
+ return props.TagName;
819
+ },
820
+ get children() {
821
+ return props.children;
822
+ }
823
+ }));
824
+ }
825
+ });
826
+ }
827
+ });
828
+ }
829
+ var dynamic_renderer_default = DynamicRenderer;
830
+
831
+ // src/components/block/components/block-wrapper.tsx
832
+ function BlockWrapper(props) {
833
+ return createComponent(dynamic_renderer_default, {
834
+ get TagName() {
835
+ return props.Wrapper;
836
+ },
837
+ get attributes() {
838
+ return getBlockProperties({
810
839
  block: props.block,
811
840
  context: props.context
812
- }), () => getBlockActions({
841
+ });
842
+ },
843
+ get actionAttributes() {
844
+ return getBlockActions({
813
845
  block: props.block,
814
846
  rootState: props.context.rootState,
815
847
  rootSetState: props.context.rootSetState,
816
848
  localState: props.context.localState,
817
849
  context: props.context.context,
818
850
  stripPrefix: true
819
- }), {
820
- get component() {
821
- return props.Wrapper;
822
- },
823
- get children() {
824
- return props.children;
825
- }
826
- }));
851
+ });
852
+ },
853
+ get children() {
854
+ return props.children;
827
855
  }
828
856
  });
829
857
  }
@@ -1064,29 +1092,8 @@ function Block(props) {
1064
1092
  return !blockComponent()?.noWrap;
1065
1093
  },
1066
1094
  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() {
1095
+ return createComponent(Show, {
1096
+ get fallback() {
1090
1097
  return createComponent(For, {
1091
1098
  get each() {
1092
1099
  return repeatItem();
@@ -1107,10 +1114,9 @@ function Block(props) {
1107
1114
  });
1108
1115
  }
1109
1116
  });
1110
- }
1111
- }), createComponent(Show, {
1117
+ },
1112
1118
  get when() {
1113
- return memo(() => !!!isEmptyHtmlElement(Tag()))() && !repeatItem();
1119
+ return !repeatItem();
1114
1120
  },
1115
1121
  get children() {
1116
1122
  return createComponent(block_wrapper_default, {
@@ -1123,7 +1129,6 @@ function Block(props) {
1123
1129
  get context() {
1124
1130
  return props.context;
1125
1131
  },
1126
- hasChildren: true,
1127
1132
  get children() {
1128
1133
  return [createComponent(component_ref_default, {
1129
1134
  get componentRef() {
@@ -1173,7 +1178,7 @@ function Block(props) {
1173
1178
  }
1174
1179
  });
1175
1180
  }
1176
- })];
1181
+ });
1177
1182
  }
1178
1183
  })];
1179
1184
  }
@@ -2499,8 +2504,50 @@ var componentInfo8 = {
2499
2504
  }]
2500
2505
  };
2501
2506
 
2502
- // src/blocks/symbol/component-info.ts
2507
+ // src/blocks/slot/component-info.ts
2503
2508
  var componentInfo9 = {
2509
+ name: "Slot",
2510
+ isRSC: true,
2511
+ description: "Allow child blocks to be inserted into this content when used as a Symbol",
2512
+ docsLink: "https://www.builder.io/c/docs/symbols-with-blocks",
2513
+ image: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F3aad6de36eae43b59b52c85190fdef56",
2514
+ // Maybe wrap this for canHaveChildren so bind children to this hm
2515
+ inputs: [{
2516
+ name: "name",
2517
+ type: "string",
2518
+ required: true,
2519
+ defaultValue: "children"
2520
+ }]
2521
+ };
2522
+ var _tmpl$11 = /* @__PURE__ */ template(`<div>`);
2523
+ function Slot(props) {
2524
+ return (() => {
2525
+ const _el$ = _tmpl$11();
2526
+ _el$.style.setProperty("pointer-events", "auto");
2527
+ spread(_el$, mergeProps(() => !props.builderContext.context?.symbolId && {
2528
+ "builder-slot": props.name
2529
+ }), false, true);
2530
+ insert(_el$, createComponent(blocks_default, {
2531
+ get parent() {
2532
+ return props.builderContext.context?.symbolId;
2533
+ },
2534
+ get path() {
2535
+ return `symbol.data.${props.name}`;
2536
+ },
2537
+ get context() {
2538
+ return props.builderContext;
2539
+ },
2540
+ get blocks() {
2541
+ return props.builderContext.rootState?.[props.name];
2542
+ }
2543
+ }));
2544
+ return _el$;
2545
+ })();
2546
+ }
2547
+ var slot_default = Slot;
2548
+
2549
+ // src/blocks/symbol/component-info.ts
2550
+ var componentInfo10 = {
2504
2551
  name: "Symbol",
2505
2552
  noWrap: true,
2506
2553
  static: true,
@@ -2536,7 +2583,7 @@ var componentInfo9 = {
2536
2583
  };
2537
2584
 
2538
2585
  // src/blocks/text/component-info.ts
2539
- var componentInfo10 = {
2586
+ var componentInfo11 = {
2540
2587
  name: "Text",
2541
2588
  static: true,
2542
2589
  isRSC: true,
@@ -2555,10 +2602,10 @@ var componentInfo10 = {
2555
2602
  textAlign: "center"
2556
2603
  }
2557
2604
  };
2558
- var _tmpl$11 = /* @__PURE__ */ template(`<div class=builder-text>`);
2605
+ var _tmpl$12 = /* @__PURE__ */ template(`<div class=builder-text>`);
2559
2606
  function Text(props) {
2560
2607
  return (() => {
2561
- const _el$ = _tmpl$11();
2608
+ const _el$ = _tmpl$12();
2562
2609
  _el$.style.setProperty("outline", "none");
2563
2610
  effect(() => _el$.innerHTML = props.text?.toString() || "");
2564
2611
  return _el$;
@@ -2567,7 +2614,7 @@ function Text(props) {
2567
2614
  var text_default = Text;
2568
2615
 
2569
2616
  // src/blocks/video/component-info.ts
2570
- var componentInfo11 = {
2617
+ var componentInfo12 = {
2571
2618
  name: "Video",
2572
2619
  canHaveChildren: true,
2573
2620
  defaultStyles: {
@@ -2649,7 +2696,7 @@ var componentInfo11 = {
2649
2696
  advanced: true
2650
2697
  }]
2651
2698
  };
2652
- var _tmpl$12 = /* @__PURE__ */ template(`<source type=video/mp4>`);
2699
+ var _tmpl$13 = /* @__PURE__ */ template(`<source type=video/mp4>`);
2653
2700
  var _tmpl$23 = /* @__PURE__ */ template(`<div>`);
2654
2701
  var _tmpl$33 = /* @__PURE__ */ template(`<div><video class=builder-video>`);
2655
2702
  function Video(props) {
@@ -2712,7 +2759,7 @@ function Video(props) {
2712
2759
  return !props.lazyLoad;
2713
2760
  },
2714
2761
  get children() {
2715
- const _el$3 = _tmpl$12();
2762
+ const _el$3 = _tmpl$13();
2716
2763
  effect(() => setAttribute(_el$3, "src", props.video));
2717
2764
  return _el$3;
2718
2765
  }
@@ -2794,13 +2841,16 @@ var getDefaultRegisteredComponents = () => [{
2794
2841
  ...componentInfo8
2795
2842
  }, {
2796
2843
  component: symbol_default,
2797
- ...componentInfo9
2844
+ ...componentInfo10
2798
2845
  }, {
2799
2846
  component: text_default,
2800
- ...componentInfo10
2847
+ ...componentInfo11
2801
2848
  }, {
2802
2849
  component: video_default,
2803
- ...componentInfo11
2850
+ ...componentInfo12
2851
+ }, {
2852
+ component: slot_default,
2853
+ ...componentInfo9
2804
2854
  }];
2805
2855
 
2806
2856
  // src/functions/register-component.ts
@@ -2871,10 +2921,10 @@ var getUpdateVariantVisibilityScript = ({
2871
2921
  }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
2872
2922
  "${variationId}", "${contentId}", ${isHydrationTarget}
2873
2923
  )`;
2874
- var _tmpl$13 = /* @__PURE__ */ template(`<script>`);
2924
+ var _tmpl$14 = /* @__PURE__ */ template(`<script>`);
2875
2925
  function InlinedScript(props) {
2876
2926
  return (() => {
2877
- const _el$ = _tmpl$13();
2927
+ const _el$ = _tmpl$14();
2878
2928
  effect((_p$) => {
2879
2929
  const _v$ = props.scriptStr, _v$2 = props.id || "";
2880
2930
  _v$ !== _p$._v$ && (_el$.innerHTML = _p$._v$ = _v$);
@@ -3123,6 +3173,13 @@ async function fetchEntries(options) {
3123
3173
  }
3124
3174
  var getAllContent = fetchEntries;
3125
3175
 
3176
+ // src/functions/is-from-trusted-host.ts
3177
+ var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
3178
+ function isFromTrustedHost(trustedHosts, e) {
3179
+ const url = new URL(e.origin), hostname = url.hostname;
3180
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
3181
+ }
3182
+
3126
3183
  // src/functions/is-previewing.ts
3127
3184
  function isPreviewing() {
3128
3185
  if (!isBrowser()) {
@@ -3374,7 +3431,7 @@ var getInteractionPropertiesForEvent = (event) => {
3374
3431
  };
3375
3432
 
3376
3433
  // src/constants/sdk-version.ts
3377
- var SDK_VERSION = "0.12.0";
3434
+ var SDK_VERSION = "0.12.2";
3378
3435
 
3379
3436
  // src/functions/register.ts
3380
3437
  var registry = {};
@@ -3452,9 +3509,13 @@ var setupBrowserForEditing = (options = {}) => {
3452
3509
  options
3453
3510
  }
3454
3511
  }, "*");
3455
- window.addEventListener("message", ({
3456
- data
3457
- }) => {
3512
+ window.addEventListener("message", (event) => {
3513
+ if (!isFromTrustedHost(options.trustedHosts, event)) {
3514
+ return;
3515
+ }
3516
+ const {
3517
+ data
3518
+ } = event;
3458
3519
  if (!data?.type) {
3459
3520
  return;
3460
3521
  }
@@ -3550,6 +3611,9 @@ function EnableEditor(props) {
3550
3611
  }));
3551
3612
  }
3552
3613
  function processMessage(event) {
3614
+ if (!isFromTrustedHost(props.trustedHosts, event)) {
3615
+ return;
3616
+ }
3553
3617
  const {
3554
3618
  data
3555
3619
  } = event;
@@ -3681,6 +3745,9 @@ function EnableEditor(props) {
3681
3745
  } : {},
3682
3746
  ...props.enrich ? {
3683
3747
  enrich: props.enrich
3748
+ } : {},
3749
+ ...props.trustedHosts ? {
3750
+ trustedHosts: props.trustedHosts
3684
3751
  } : {}
3685
3752
  });
3686
3753
  Object.values(props.builderContextSignal.componentInfos).forEach((registeredComponent) => {
@@ -4048,6 +4115,9 @@ function ContentComponent(props) {
4048
4115
  },
4049
4116
  get contentWrapperProps() {
4050
4117
  return props.contentWrapperProps;
4118
+ },
4119
+ get trustedHosts() {
4120
+ return props.trustedHosts;
4051
4121
  }
4052
4122
  }, {
4053
4123
  setBuilderContextSignal
@@ -4207,6 +4277,9 @@ function ContentVariants(props) {
4207
4277
  },
4208
4278
  get contentWrapperProps() {
4209
4279
  return props.contentWrapperProps;
4280
+ },
4281
+ get trustedHosts() {
4282
+ return props.trustedHosts;
4210
4283
  }
4211
4284
  });
4212
4285
  }
@@ -4261,6 +4334,9 @@ function ContentVariants(props) {
4261
4334
  },
4262
4335
  get contentWrapperProps() {
4263
4336
  return props.contentWrapperProps;
4337
+ },
4338
+ get trustedHosts() {
4339
+ return props.trustedHosts;
4264
4340
  }
4265
4341
  }))];
4266
4342
  }
@@ -4291,7 +4367,7 @@ var fetchSymbolContent = async ({
4291
4367
  };
4292
4368
 
4293
4369
  // src/blocks/symbol/symbol.tsx
4294
- var _tmpl$14 = /* @__PURE__ */ template(`<div>`);
4370
+ var _tmpl$15 = /* @__PURE__ */ template(`<div>`);
4295
4371
  function Symbol(props) {
4296
4372
  const [contentToUse, setContentToUse] = createSignal(props.symbol?.content);
4297
4373
  function className() {
@@ -4317,7 +4393,7 @@ function Symbol(props) {
4317
4393
  }
4318
4394
  createEffect(on(() => [props.symbol], onUpdateFn_0));
4319
4395
  return (() => {
4320
- const _el$ = _tmpl$14();
4396
+ const _el$ = _tmpl$15();
4321
4397
  spread(_el$, mergeProps({
4322
4398
  get ["class"]() {
4323
4399
  return className();
@@ -4332,7 +4408,10 @@ function Symbol(props) {
4332
4408
  return props.builderContext.apiKey;
4333
4409
  },
4334
4410
  get context() {
4335
- return props.builderContext.context;
4411
+ return {
4412
+ ...props.builderContext.context,
4413
+ symbolId: props.builderBlock?.id
4414
+ };
4336
4415
  },
4337
4416
  get customComponents() {
4338
4417
  return Object.values(props.builderComponents);