@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/edge/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
 
@@ -3486,10 +3486,6 @@ function getProcessedBlock({
3486
3486
  }
3487
3487
 
3488
3488
  // src/components/block/block.helpers.ts
3489
- var EMPTY_HTML_ELEMENTS = ["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"];
3490
- var isEmptyHtmlElement = (tagName) => {
3491
- return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase());
3492
- };
3493
3489
  var getComponent = ({
3494
3490
  block,
3495
3491
  context,
@@ -3811,48 +3807,80 @@ function getStyleAttribute(style) {
3811
3807
  }
3812
3808
  }
3813
3809
 
3814
- // src/components/block/components/block-wrapper.tsx
3815
- function BlockWrapper(props) {
3810
+ // src/components/dynamic-renderer/dynamic-renderer.helpers.ts
3811
+ var EMPTY_HTML_ELEMENTS = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]);
3812
+ var isEmptyElement = (tagName) => {
3813
+ return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.has(tagName.toLowerCase());
3814
+ };
3815
+
3816
+ // src/components/dynamic-renderer/dynamic-renderer.tsx
3817
+ function DynamicRenderer(props) {
3816
3818
  return createComponent(Show, {
3817
3819
  get fallback() {
3818
- return createComponent(Dynamic, mergeProps(() => getBlockProperties({
3819
- block: props.block,
3820
- context: props.context
3821
- }), () => getBlockActions({
3822
- block: props.block,
3823
- rootState: props.context.rootState,
3824
- rootSetState: props.context.rootSetState,
3825
- localState: props.context.localState,
3826
- context: props.context.context,
3827
- stripPrefix: true
3828
- }), {
3820
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
3829
3821
  get component() {
3830
- return props.Wrapper;
3822
+ return props.TagName;
3831
3823
  }
3832
3824
  }));
3833
3825
  },
3834
3826
  get when() {
3835
- return props.hasChildren;
3827
+ return !isEmptyElement(props.TagName);
3836
3828
  },
3837
3829
  get children() {
3838
- return createComponent(Dynamic, mergeProps(() => getBlockProperties({
3830
+ return createComponent(Show, {
3831
+ get fallback() {
3832
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
3833
+ get component() {
3834
+ return props.TagName;
3835
+ },
3836
+ get children() {
3837
+ return props.children;
3838
+ }
3839
+ }));
3840
+ },
3841
+ get when() {
3842
+ return typeof props.TagName === "string";
3843
+ },
3844
+ get children() {
3845
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
3846
+ get component() {
3847
+ return props.TagName;
3848
+ },
3849
+ get children() {
3850
+ return props.children;
3851
+ }
3852
+ }));
3853
+ }
3854
+ });
3855
+ }
3856
+ });
3857
+ }
3858
+ var dynamic_renderer_default = DynamicRenderer;
3859
+
3860
+ // src/components/block/components/block-wrapper.tsx
3861
+ function BlockWrapper(props) {
3862
+ return createComponent(dynamic_renderer_default, {
3863
+ get TagName() {
3864
+ return props.Wrapper;
3865
+ },
3866
+ get attributes() {
3867
+ return getBlockProperties({
3839
3868
  block: props.block,
3840
3869
  context: props.context
3841
- }), () => getBlockActions({
3870
+ });
3871
+ },
3872
+ get actionAttributes() {
3873
+ return getBlockActions({
3842
3874
  block: props.block,
3843
3875
  rootState: props.context.rootState,
3844
3876
  rootSetState: props.context.rootSetState,
3845
3877
  localState: props.context.localState,
3846
3878
  context: props.context.context,
3847
3879
  stripPrefix: true
3848
- }), {
3849
- get component() {
3850
- return props.Wrapper;
3851
- },
3852
- get children() {
3853
- return props.children;
3854
- }
3855
- }));
3880
+ });
3881
+ },
3882
+ get children() {
3883
+ return props.children;
3856
3884
  }
3857
3885
  });
3858
3886
  }
@@ -4093,29 +4121,8 @@ function Block(props) {
4093
4121
  return !blockComponent()?.noWrap;
4094
4122
  },
4095
4123
  get children() {
4096
- return [createComponent(Show, {
4097
- get when() {
4098
- return isEmptyHtmlElement(Tag());
4099
- },
4100
- get children() {
4101
- return createComponent(block_wrapper_default, {
4102
- get Wrapper() {
4103
- return Tag();
4104
- },
4105
- get block() {
4106
- return processedBlock();
4107
- },
4108
- get context() {
4109
- return props.context;
4110
- },
4111
- hasChildren: false
4112
- });
4113
- }
4114
- }), createComponent(Show, {
4115
- get when() {
4116
- return memo(() => !!!isEmptyHtmlElement(Tag()))() && repeatItem();
4117
- },
4118
- get children() {
4124
+ return createComponent(Show, {
4125
+ get fallback() {
4119
4126
  return createComponent(For, {
4120
4127
  get each() {
4121
4128
  return repeatItem();
@@ -4136,10 +4143,9 @@ function Block(props) {
4136
4143
  });
4137
4144
  }
4138
4145
  });
4139
- }
4140
- }), createComponent(Show, {
4146
+ },
4141
4147
  get when() {
4142
- return memo(() => !!!isEmptyHtmlElement(Tag()))() && !repeatItem();
4148
+ return !repeatItem();
4143
4149
  },
4144
4150
  get children() {
4145
4151
  return createComponent(block_wrapper_default, {
@@ -4152,7 +4158,6 @@ function Block(props) {
4152
4158
  get context() {
4153
4159
  return props.context;
4154
4160
  },
4155
- hasChildren: true,
4156
4161
  get children() {
4157
4162
  return [createComponent(component_ref_default, {
4158
4163
  get componentRef() {
@@ -4202,7 +4207,7 @@ function Block(props) {
4202
4207
  }
4203
4208
  });
4204
4209
  }
4205
- })];
4210
+ });
4206
4211
  }
4207
4212
  })];
4208
4213
  }
@@ -5528,8 +5533,50 @@ var componentInfo8 = {
5528
5533
  }]
5529
5534
  };
5530
5535
 
5531
- // src/blocks/symbol/component-info.ts
5536
+ // src/blocks/slot/component-info.ts
5532
5537
  var componentInfo9 = {
5538
+ name: "Slot",
5539
+ isRSC: true,
5540
+ description: "Allow child blocks to be inserted into this content when used as a Symbol",
5541
+ docsLink: "https://www.builder.io/c/docs/symbols-with-blocks",
5542
+ image: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F3aad6de36eae43b59b52c85190fdef56",
5543
+ // Maybe wrap this for canHaveChildren so bind children to this hm
5544
+ inputs: [{
5545
+ name: "name",
5546
+ type: "string",
5547
+ required: true,
5548
+ defaultValue: "children"
5549
+ }]
5550
+ };
5551
+ var _tmpl$11 = /* @__PURE__ */ template(`<div>`);
5552
+ function Slot(props) {
5553
+ return (() => {
5554
+ const _el$ = _tmpl$11();
5555
+ _el$.style.setProperty("pointer-events", "auto");
5556
+ spread(_el$, mergeProps(() => !props.builderContext.context?.symbolId && {
5557
+ "builder-slot": props.name
5558
+ }), false, true);
5559
+ insert(_el$, createComponent(blocks_default, {
5560
+ get parent() {
5561
+ return props.builderContext.context?.symbolId;
5562
+ },
5563
+ get path() {
5564
+ return `symbol.data.${props.name}`;
5565
+ },
5566
+ get context() {
5567
+ return props.builderContext;
5568
+ },
5569
+ get blocks() {
5570
+ return props.builderContext.rootState?.[props.name];
5571
+ }
5572
+ }));
5573
+ return _el$;
5574
+ })();
5575
+ }
5576
+ var slot_default = Slot;
5577
+
5578
+ // src/blocks/symbol/component-info.ts
5579
+ var componentInfo10 = {
5533
5580
  name: "Symbol",
5534
5581
  noWrap: true,
5535
5582
  static: true,
@@ -5565,7 +5612,7 @@ var componentInfo9 = {
5565
5612
  };
5566
5613
 
5567
5614
  // src/blocks/text/component-info.ts
5568
- var componentInfo10 = {
5615
+ var componentInfo11 = {
5569
5616
  name: "Text",
5570
5617
  static: true,
5571
5618
  isRSC: true,
@@ -5584,10 +5631,10 @@ var componentInfo10 = {
5584
5631
  textAlign: "center"
5585
5632
  }
5586
5633
  };
5587
- var _tmpl$11 = /* @__PURE__ */ template(`<div class=builder-text>`);
5634
+ var _tmpl$12 = /* @__PURE__ */ template(`<div class=builder-text>`);
5588
5635
  function Text(props) {
5589
5636
  return (() => {
5590
- const _el$ = _tmpl$11();
5637
+ const _el$ = _tmpl$12();
5591
5638
  _el$.style.setProperty("outline", "none");
5592
5639
  effect(() => _el$.innerHTML = props.text?.toString() || "");
5593
5640
  return _el$;
@@ -5596,7 +5643,7 @@ function Text(props) {
5596
5643
  var text_default = Text;
5597
5644
 
5598
5645
  // src/blocks/video/component-info.ts
5599
- var componentInfo11 = {
5646
+ var componentInfo12 = {
5600
5647
  name: "Video",
5601
5648
  canHaveChildren: true,
5602
5649
  defaultStyles: {
@@ -5678,7 +5725,7 @@ var componentInfo11 = {
5678
5725
  advanced: true
5679
5726
  }]
5680
5727
  };
5681
- var _tmpl$12 = /* @__PURE__ */ template(`<source type=video/mp4>`);
5728
+ var _tmpl$13 = /* @__PURE__ */ template(`<source type=video/mp4>`);
5682
5729
  var _tmpl$23 = /* @__PURE__ */ template(`<div>`);
5683
5730
  var _tmpl$33 = /* @__PURE__ */ template(`<div><video class=builder-video>`);
5684
5731
  function Video(props) {
@@ -5741,7 +5788,7 @@ function Video(props) {
5741
5788
  return !props.lazyLoad;
5742
5789
  },
5743
5790
  get children() {
5744
- const _el$3 = _tmpl$12();
5791
+ const _el$3 = _tmpl$13();
5745
5792
  effect(() => setAttribute(_el$3, "src", props.video));
5746
5793
  return _el$3;
5747
5794
  }
@@ -5823,13 +5870,16 @@ var getDefaultRegisteredComponents = () => [{
5823
5870
  ...componentInfo8
5824
5871
  }, {
5825
5872
  component: symbol_default,
5826
- ...componentInfo9
5873
+ ...componentInfo10
5827
5874
  }, {
5828
5875
  component: text_default,
5829
- ...componentInfo10
5876
+ ...componentInfo11
5830
5877
  }, {
5831
5878
  component: video_default,
5832
- ...componentInfo11
5879
+ ...componentInfo12
5880
+ }, {
5881
+ component: slot_default,
5882
+ ...componentInfo9
5833
5883
  }];
5834
5884
 
5835
5885
  // src/functions/register-component.ts
@@ -5900,10 +5950,10 @@ var getUpdateVariantVisibilityScript = ({
5900
5950
  }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
5901
5951
  "${variationId}", "${contentId}", ${isHydrationTarget}
5902
5952
  )`;
5903
- var _tmpl$13 = /* @__PURE__ */ template(`<script>`);
5953
+ var _tmpl$14 = /* @__PURE__ */ template(`<script>`);
5904
5954
  function InlinedScript(props) {
5905
5955
  return (() => {
5906
- const _el$ = _tmpl$13();
5956
+ const _el$ = _tmpl$14();
5907
5957
  effect((_p$) => {
5908
5958
  const _v$ = props.scriptStr, _v$2 = props.id || "";
5909
5959
  _v$ !== _p$._v$ && (_el$.innerHTML = _p$._v$ = _v$);
@@ -6152,6 +6202,13 @@ async function fetchEntries(options) {
6152
6202
  }
6153
6203
  var getAllContent = fetchEntries;
6154
6204
 
6205
+ // src/functions/is-from-trusted-host.ts
6206
+ var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
6207
+ function isFromTrustedHost(trustedHosts, e) {
6208
+ const url = new URL(e.origin), hostname = url.hostname;
6209
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
6210
+ }
6211
+
6155
6212
  // src/functions/is-previewing.ts
6156
6213
  function isPreviewing() {
6157
6214
  if (!isBrowser()) {
@@ -6403,7 +6460,7 @@ var getInteractionPropertiesForEvent = (event) => {
6403
6460
  };
6404
6461
 
6405
6462
  // src/constants/sdk-version.ts
6406
- var SDK_VERSION = "0.12.0";
6463
+ var SDK_VERSION = "0.12.2";
6407
6464
 
6408
6465
  // src/functions/register.ts
6409
6466
  var registry = {};
@@ -6481,9 +6538,13 @@ var setupBrowserForEditing = (options = {}) => {
6481
6538
  options
6482
6539
  }
6483
6540
  }, "*");
6484
- window.addEventListener("message", ({
6485
- data
6486
- }) => {
6541
+ window.addEventListener("message", (event) => {
6542
+ if (!isFromTrustedHost(options.trustedHosts, event)) {
6543
+ return;
6544
+ }
6545
+ const {
6546
+ data
6547
+ } = event;
6487
6548
  if (!data?.type) {
6488
6549
  return;
6489
6550
  }
@@ -6579,6 +6640,9 @@ function EnableEditor(props) {
6579
6640
  }));
6580
6641
  }
6581
6642
  function processMessage(event) {
6643
+ if (!isFromTrustedHost(props.trustedHosts, event)) {
6644
+ return;
6645
+ }
6582
6646
  const {
6583
6647
  data
6584
6648
  } = event;
@@ -6710,6 +6774,9 @@ function EnableEditor(props) {
6710
6774
  } : {},
6711
6775
  ...props.enrich ? {
6712
6776
  enrich: props.enrich
6777
+ } : {},
6778
+ ...props.trustedHosts ? {
6779
+ trustedHosts: props.trustedHosts
6713
6780
  } : {}
6714
6781
  });
6715
6782
  Object.values(props.builderContextSignal.componentInfos).forEach((registeredComponent) => {
@@ -7077,6 +7144,9 @@ function ContentComponent(props) {
7077
7144
  },
7078
7145
  get contentWrapperProps() {
7079
7146
  return props.contentWrapperProps;
7147
+ },
7148
+ get trustedHosts() {
7149
+ return props.trustedHosts;
7080
7150
  }
7081
7151
  }, {
7082
7152
  setBuilderContextSignal
@@ -7236,6 +7306,9 @@ function ContentVariants(props) {
7236
7306
  },
7237
7307
  get contentWrapperProps() {
7238
7308
  return props.contentWrapperProps;
7309
+ },
7310
+ get trustedHosts() {
7311
+ return props.trustedHosts;
7239
7312
  }
7240
7313
  });
7241
7314
  }
@@ -7290,6 +7363,9 @@ function ContentVariants(props) {
7290
7363
  },
7291
7364
  get contentWrapperProps() {
7292
7365
  return props.contentWrapperProps;
7366
+ },
7367
+ get trustedHosts() {
7368
+ return props.trustedHosts;
7293
7369
  }
7294
7370
  }))];
7295
7371
  }
@@ -7320,7 +7396,7 @@ var fetchSymbolContent = async ({
7320
7396
  };
7321
7397
 
7322
7398
  // src/blocks/symbol/symbol.tsx
7323
- var _tmpl$14 = /* @__PURE__ */ template(`<div>`);
7399
+ var _tmpl$15 = /* @__PURE__ */ template(`<div>`);
7324
7400
  function Symbol2(props) {
7325
7401
  const [contentToUse, setContentToUse] = createSignal(props.symbol?.content);
7326
7402
  function className() {
@@ -7346,7 +7422,7 @@ function Symbol2(props) {
7346
7422
  }
7347
7423
  createEffect(on(() => [props.symbol], onUpdateFn_0));
7348
7424
  return (() => {
7349
- const _el$ = _tmpl$14();
7425
+ const _el$ = _tmpl$15();
7350
7426
  spread(_el$, mergeProps({
7351
7427
  get ["class"]() {
7352
7428
  return className();
@@ -7361,7 +7437,10 @@ function Symbol2(props) {
7361
7437
  return props.builderContext.apiKey;
7362
7438
  },
7363
7439
  get context() {
7364
- return props.builderContext.context;
7440
+ return {
7441
+ ...props.builderContext.context,
7442
+ symbolId: props.builderBlock?.id
7443
+ };
7365
7444
  },
7366
7445
  get customComponents() {
7367
7446
  return Object.values(props.builderComponents);