@builder.io/sdk-solid 2.0.8 → 2.0.13

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.
@@ -103,7 +103,13 @@ import { createContext as createContext2 } from "solid-js";
103
103
  var components_context_default = createContext2({ registeredComponents: {} });
104
104
 
105
105
  // src/components/block/block.tsx
106
- import { Show as Show4, For as For2, onMount, createMemo as createMemo5 } from "solid-js";
106
+ import {
107
+ Show as Show4,
108
+ For as For2,
109
+ onMount,
110
+ createMemo as createMemo5,
111
+ createSignal as createSignal5
112
+ } from "solid-js";
107
113
 
108
114
  // src/functions/get-block-component-options.ts
109
115
  function getBlockComponentOptions(block) {
@@ -113,6 +119,15 @@ function getBlockComponentOptions(block) {
113
119
  };
114
120
  }
115
121
 
122
+ // src/helpers/omit.ts
123
+ function omit(obj, ...values) {
124
+ const newObject = Object.assign({}, obj);
125
+ for (const key of values) {
126
+ delete newObject[key];
127
+ }
128
+ return newObject;
129
+ }
130
+
116
131
  // src/helpers/logger.ts
117
132
  var MSG_PREFIX = "[Builder.io]: ";
118
133
  var logger = {
@@ -321,6 +336,7 @@ var shouldForceBrowserRuntimeInNode = () => {
321
336
  var chooseBrowserOrServerEval = (args) => isBrowser() || shouldForceBrowserRuntimeInNode() ? runInBrowser(args) : runInBrowser(args);
322
337
 
323
338
  // src/functions/evaluate/evaluate.ts
339
+ var DISABLE_CACHE = true;
324
340
  var EvalCache = class _EvalCache {
325
341
  static cacheLimit = 20;
326
342
  static cache = /* @__PURE__ */ new Map();
@@ -369,7 +385,7 @@ function evaluate({
369
385
  rootState,
370
386
  localState
371
387
  };
372
- if (enableCache) {
388
+ if (enableCache && !DISABLE_CACHE) {
373
389
  const cacheKey = EvalCache.getCacheKey(args);
374
390
  const cachedValue = EvalCache.getCachedValue(cacheKey);
375
391
  if (cachedValue) {
@@ -410,6 +426,53 @@ function transformBlock(block) {
410
426
  }
411
427
 
412
428
  // src/functions/get-processed-block.ts
429
+ function deepCloneWithConditions(obj) {
430
+ if (obj === null || typeof obj !== "object") {
431
+ return obj;
432
+ }
433
+ if (Array.isArray(obj)) {
434
+ return obj.map((item) => deepCloneWithConditions(item));
435
+ }
436
+ if (obj["@type"] === "@builder.io/sdk:Element") {
437
+ return obj;
438
+ }
439
+ const clonedObj = {};
440
+ for (const key in obj) {
441
+ if (key !== "meta" && Object.prototype.hasOwnProperty.call(obj, key)) {
442
+ clonedObj[key] = deepCloneWithConditions(obj[key]);
443
+ }
444
+ }
445
+ return clonedObj;
446
+ }
447
+ var IS_SDK_WITHOUT_CACHED_PROCESSED_BLOCK = ["svelte", "vue", "angular", "qwik", "solid"].includes(TARGET);
448
+ var getCopy = (block) => {
449
+ if (IS_SDK_WITHOUT_CACHED_PROCESSED_BLOCK) {
450
+ const copy = fastClone(block);
451
+ const copied = {
452
+ ...copy,
453
+ properties: {
454
+ ...copy.properties
455
+ },
456
+ actions: {
457
+ ...copy.actions
458
+ }
459
+ };
460
+ return copied;
461
+ } else {
462
+ const copy = deepCloneWithConditions(omit(block, "children", "meta"));
463
+ return {
464
+ ...copy,
465
+ properties: {
466
+ ...copy.properties
467
+ },
468
+ actions: {
469
+ ...copy.actions
470
+ },
471
+ children: block.children,
472
+ meta: block.meta
473
+ };
474
+ }
475
+ };
413
476
  var evaluateBindings = ({
414
477
  block,
415
478
  context,
@@ -420,16 +483,7 @@ var evaluateBindings = ({
420
483
  if (!block.bindings) {
421
484
  return block;
422
485
  }
423
- const copy = fastClone(block);
424
- const copied = {
425
- ...copy,
426
- properties: {
427
- ...copy.properties
428
- },
429
- actions: {
430
- ...copy.actions
431
- }
432
- };
486
+ const copied = getCopy(block);
433
487
  for (const binding in block.bindings) {
434
488
  const expression = block.bindings[binding];
435
489
  const value = evaluate({
@@ -712,17 +766,9 @@ function mapStyleObjToStrIfNeeded(style) {
712
766
  // src/components/block/block.helpers.ts
713
767
  var getComponent = ({
714
768
  block,
715
- context,
716
769
  registeredComponents
717
770
  }) => {
718
- const componentName = getProcessedBlock({
719
- block,
720
- localState: context.localState,
721
- rootState: context.rootState,
722
- rootSetState: context.rootSetState,
723
- context: context.context,
724
- shouldEvaluateBindings: false
725
- }).component?.name;
771
+ const componentName = block.component?.name;
726
772
  if (!componentName) {
727
773
  return null;
728
774
  }
@@ -869,14 +915,7 @@ var Inlined_styles_default = InlinedStyles;
869
915
  // src/components/block/components/block-styles.tsx
870
916
  function BlockStyles(props) {
871
917
  const canShowBlock = createMemo(() => {
872
- const processedBlock = getProcessedBlock({
873
- block: props.block,
874
- localState: props.context.localState,
875
- rootState: props.context.rootState,
876
- rootSetState: props.context.rootSetState,
877
- context: props.context.context,
878
- shouldEvaluateBindings: true
879
- });
918
+ const processedBlock = props.block;
880
919
  if (checkIsDefined(processedBlock.hide)) {
881
920
  return !processedBlock.hide;
882
921
  }
@@ -886,14 +925,7 @@ function BlockStyles(props) {
886
925
  return true;
887
926
  });
888
927
  const css = createMemo(() => {
889
- const processedBlock = getProcessedBlock({
890
- block: props.block,
891
- localState: props.context.localState,
892
- rootState: props.context.rootState,
893
- rootSetState: props.context.rootSetState,
894
- context: props.context.context,
895
- shouldEvaluateBindings: true
896
- });
928
+ const processedBlock = props.block;
897
929
  const styles = processedBlock.responsiveStyles;
898
930
  const content = props.context.content;
899
931
  const sizesWithUpdatedBreakpoints = getSizesForBreakpoints(
@@ -1162,12 +1194,9 @@ var Repeated_block_default = RepeatedBlock;
1162
1194
 
1163
1195
  // src/components/block/block.tsx
1164
1196
  function Block(props) {
1165
- const blockComponent = createMemo5(() => {
1166
- return getComponent({
1167
- block: props.block,
1168
- context: props.context,
1169
- registeredComponents: props.registeredComponents
1170
- });
1197
+ const [_processedBlock, set_processedBlock] = createSignal5({
1198
+ value: null,
1199
+ update: false
1171
1200
  });
1172
1201
  const repeatItem = createMemo5(() => {
1173
1202
  return getRepeatItemData({
@@ -1176,7 +1205,7 @@ function Block(props) {
1176
1205
  });
1177
1206
  });
1178
1207
  const processedBlock = createMemo5(() => {
1179
- return props.block.repeat?.collection ? props.block : getProcessedBlock({
1208
+ const blockToUse = props.block.repeat?.collection ? props.block : getProcessedBlock({
1180
1209
  block: props.block,
1181
1210
  localState: props.context.localState,
1182
1211
  rootState: props.context.rootState,
@@ -1184,6 +1213,13 @@ function Block(props) {
1184
1213
  context: props.context.context,
1185
1214
  shouldEvaluateBindings: true
1186
1215
  });
1216
+ return blockToUse;
1217
+ });
1218
+ const blockComponent = createMemo5(() => {
1219
+ return getComponent({
1220
+ block: processedBlock(),
1221
+ registeredComponents: props.registeredComponents
1222
+ });
1187
1223
  });
1188
1224
  const Tag = createMemo5(() => {
1189
1225
  const shouldUseLink = props.block.tagName === "a" || processedBlock().properties?.href || processedBlock().href;
@@ -1241,9 +1277,24 @@ function Block(props) {
1241
1277
  }
1242
1278
  });
1243
1279
  return <><Show4 when={canShowBlock()}>
1244
- <Block_styles_default block={props.block} context={props.context} />
1280
+ <Block_styles_default
1281
+ block={processedBlock()}
1282
+ context={props.context}
1283
+ />
1245
1284
  <Show4
1246
- fallback={<Component_ref_default
1285
+ fallback={<Show4
1286
+ fallback={<For2 each={repeatItem()}>{(data, _index) => {
1287
+ const index = _index();
1288
+ return <Repeated_block_default
1289
+ key={index}
1290
+ repeatContext={data.context}
1291
+ block={data.block}
1292
+ registeredComponents={props.registeredComponents}
1293
+ linkComponent={props.linkComponent}
1294
+ />;
1295
+ }}</For2>}
1296
+ when={!repeatItem()}
1297
+ ><Component_ref_default
1247
1298
  componentRef={componentRefProps().componentRef}
1248
1299
  componentOptions={componentRefProps().componentOptions}
1249
1300
  blockChildren={componentRefProps().blockChildren}
@@ -1253,7 +1304,7 @@ function Block(props) {
1253
1304
  builderBlock={componentRefProps().builderBlock}
1254
1305
  includeBlockProps={componentRefProps().includeBlockProps}
1255
1306
  isInteractive={componentRefProps().isInteractive}
1256
- />}
1307
+ /></Show4>}
1257
1308
  when={!blockComponent()?.noWrap}
1258
1309
  ><Show4
1259
1310
  fallback={<For2 each={repeatItem()}>{(data, _index) => {
@@ -1299,7 +1350,7 @@ function Block(props) {
1299
1350
  var Block_default = Block;
1300
1351
 
1301
1352
  // src/components/blocks/blocks-wrapper.tsx
1302
- import { createMemo as createMemo6 } from "solid-js";
1353
+ import { onMount as onMount2, createMemo as createMemo6 } from "solid-js";
1303
1354
  import { Dynamic as Dynamic4 } from "solid-js/web";
1304
1355
  function BlocksWrapper(props) {
1305
1356
  const className = createMemo6(() => {
@@ -1333,9 +1384,13 @@ function BlocksWrapper(props) {
1333
1384
  );
1334
1385
  }
1335
1386
  }
1387
+ let blocksWrapperRef;
1388
+ onMount2(() => {
1389
+ });
1336
1390
  return <>
1337
1391
  <Dynamic4
1338
- class={className() + " dynamic-1bb6a3a2"}
1392
+ class={className() + " dynamic-4da8c6f4"}
1393
+ ref={blocksWrapperRef}
1339
1394
  builder-path={props.path}
1340
1395
  builder-parent-id={props.parent}
1341
1396
  {...{}}
@@ -1346,7 +1401,7 @@ function BlocksWrapper(props) {
1346
1401
  {...props.BlocksWrapperProps}
1347
1402
  component={props.BlocksWrapper}
1348
1403
  >{props.children}</Dynamic4>
1349
- <style>{`.dynamic-1bb6a3a2 {
1404
+ <style>{`.dynamic-4da8c6f4 {
1350
1405
  display: flex;
1351
1406
  flex-direction: column;
1352
1407
  align-items: stretch;
@@ -1550,7 +1605,7 @@ function FragmentComponent(props) {
1550
1605
  var fragment_default = FragmentComponent;
1551
1606
 
1552
1607
  // src/blocks/image/image.tsx
1553
- import { Show as Show7, onMount as onMount2, createMemo as createMemo8 } from "solid-js";
1608
+ import { Show as Show7, onMount as onMount3, createMemo as createMemo8 } from "solid-js";
1554
1609
 
1555
1610
  // src/blocks/image/image.helpers.ts
1556
1611
  function removeProtocol(path) {
@@ -1640,7 +1695,7 @@ function Image(props) {
1640
1695
  const out = props.aspectRatio ? aspectRatioStyles : void 0;
1641
1696
  return out;
1642
1697
  });
1643
- onMount2(() => {
1698
+ onMount3(() => {
1644
1699
  });
1645
1700
  return <>
1646
1701
  <>
@@ -1716,10 +1771,10 @@ function SectionComponent(props) {
1716
1771
  var section_default = SectionComponent;
1717
1772
 
1718
1773
  // src/blocks/symbol/symbol.tsx
1719
- import { onMount as onMount6, on as on3, createEffect as createEffect3, createMemo as createMemo20, createSignal as createSignal20 } from "solid-js";
1774
+ import { onMount as onMount7, on as on4, createEffect as createEffect4, createMemo as createMemo20, createSignal as createSignal20 } from "solid-js";
1720
1775
 
1721
1776
  // src/components/content-variants/content-variants.tsx
1722
- import { Show as Show14, For as For9, onMount as onMount5, createSignal as createSignal19, createMemo as createMemo19 } from "solid-js";
1777
+ import { Show as Show14, For as For9, onMount as onMount6, createSignal as createSignal19, createMemo as createMemo19 } from "solid-js";
1723
1778
 
1724
1779
  // src/helpers/url.ts
1725
1780
  var getTopLevelDomain = (host) => {
@@ -2659,7 +2714,8 @@ var componentInfo7 = {
2659
2714
  defaultValue: "children"
2660
2715
  }],
2661
2716
  shouldReceiveBuilderProps: {
2662
- builderContext: true
2717
+ builderContext: true,
2718
+ builderComponents: true
2663
2719
  }
2664
2720
  };
2665
2721
 
@@ -2676,6 +2732,7 @@ function Slot(props) {
2676
2732
  parent={props.builderContext.context?.symbolId}
2677
2733
  path={`symbol.data.${props.name}`}
2678
2734
  context={props.builderContext}
2735
+ registeredComponents={props.builderComponents}
2679
2736
  blocks={props.builderContext.rootState?.[props.name]}
2680
2737
  /></div></>;
2681
2738
  }
@@ -3008,12 +3065,12 @@ var componentInfo11 = {
3008
3065
  };
3009
3066
 
3010
3067
  // src/blocks/custom-code/custom-code.tsx
3011
- import { onMount as onMount3, createSignal as createSignal12 } from "solid-js";
3068
+ import { onMount as onMount4, createSignal as createSignal12 } from "solid-js";
3012
3069
  function CustomCode(props) {
3013
3070
  const [scriptsInserted, setScriptsInserted] = createSignal12([]);
3014
3071
  const [scriptsRun, setScriptsRun] = createSignal12([]);
3015
3072
  let elementRef;
3016
- onMount3(() => {
3073
+ onMount4(() => {
3017
3074
  if (!elementRef?.getElementsByTagName || typeof window === "undefined") {
3018
3075
  return;
3019
3076
  }
@@ -3073,7 +3130,7 @@ var componentInfo12 = {
3073
3130
  };
3074
3131
 
3075
3132
  // src/blocks/embed/embed.tsx
3076
- import { on, createEffect, createMemo as createMemo13, createSignal as createSignal13 } from "solid-js";
3133
+ import { on as on2, createEffect as createEffect2, createMemo as createMemo13, createSignal as createSignal13 } from "solid-js";
3077
3134
 
3078
3135
  // src/blocks/embed/helpers.ts
3079
3136
  var SCRIPT_MIME_TYPES = ["text/javascript", "application/javascript", "application/ecmascript"];
@@ -3115,8 +3172,8 @@ function Embed(props) {
3115
3172
  findAndRunScripts();
3116
3173
  }
3117
3174
  }
3118
- createEffect(
3119
- on(() => [onUpdateFn_0_elem(), onUpdateFn_0_ranInitFn__()], onUpdateFn_0)
3175
+ createEffect2(
3176
+ on2(() => [onUpdateFn_0_elem(), onUpdateFn_0_ranInitFn__()], onUpdateFn_0)
3120
3177
  );
3121
3178
  return <><div class="builder-embed" ref={elem} innerHTML={props.content} /></>;
3122
3179
  }
@@ -4107,14 +4164,14 @@ var getDefaultRegisteredComponents = () => [{
4107
4164
  // src/functions/register-component.ts
4108
4165
  var createRegisterComponentMessage = (info) => ({
4109
4166
  type: "builder.registerComponent",
4110
- data: serializeComponentInfo(info)
4167
+ data: serializeIncludingFunctions(info)
4111
4168
  });
4112
4169
  var serializeFn = (fnValue) => {
4113
4170
  const fnStr = fnValue.toString().trim();
4114
4171
  const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(");
4115
4172
  return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
4116
4173
  };
4117
- function serializeComponentInfo(info) {
4174
+ function serializeIncludingFunctions(info) {
4118
4175
  return JSON.parse(JSON.stringify(info, (key, value) => {
4119
4176
  if (typeof value === "function") {
4120
4177
  return serializeFn(value);
@@ -4182,9 +4239,9 @@ var Inlined_script_default = InlinedScript;
4182
4239
  // src/components/content/components/enable-editor.tsx
4183
4240
  import {
4184
4241
  Show as Show12,
4185
- onMount as onMount4,
4186
- on as on2,
4187
- createEffect as createEffect2,
4242
+ onMount as onMount5,
4243
+ on as on3,
4244
+ createEffect as createEffect3,
4188
4245
  createMemo as createMemo16,
4189
4246
  createSignal as createSignal16
4190
4247
  } from "solid-js";
@@ -4293,7 +4350,7 @@ var generateContentUrl = (options) => {
4293
4350
  locale,
4294
4351
  apiVersion = DEFAULT_API_VERSION,
4295
4352
  fields,
4296
- omit,
4353
+ omit: omit2,
4297
4354
  offset,
4298
4355
  cacheSeconds,
4299
4356
  staleCacheSeconds,
@@ -4316,7 +4373,7 @@ var generateContentUrl = (options) => {
4316
4373
  url.searchParams.set("locale", locale);
4317
4374
  if (enrich)
4318
4375
  url.searchParams.set("enrich", String(enrich));
4319
- url.searchParams.set("omit", omit || "meta.componentsUsed");
4376
+ url.searchParams.set("omit", omit2 || "meta.componentsUsed");
4320
4377
  if (fields) {
4321
4378
  url.searchParams.set("fields", fields);
4322
4379
  }
@@ -4689,11 +4746,14 @@ function isFromTrustedHost(trustedHosts, e) {
4689
4746
  }
4690
4747
 
4691
4748
  // src/constants/sdk-version.ts
4692
- var SDK_VERSION = "2.0.8";
4749
+ var SDK_VERSION = "2.0.13";
4693
4750
 
4694
4751
  // src/functions/register.ts
4695
4752
  var registry = {};
4696
4753
  function register(type, info) {
4754
+ if (type === "plugin") {
4755
+ info = serializeIncludingFunctions(info);
4756
+ }
4697
4757
  let typeList = registry[type];
4698
4758
  if (!typeList) {
4699
4759
  typeList = registry[type] = [];
@@ -5126,7 +5186,7 @@ function EnableEditor(props) {
5126
5186
  }
5127
5187
  }
5128
5188
  let elementRef;
5129
- onMount4(() => {
5189
+ onMount5(() => {
5130
5190
  if (isBrowser()) {
5131
5191
  if (isEditing()) {
5132
5192
  window.addEventListener("message", processMessage);
@@ -5187,7 +5247,7 @@ function EnableEditor(props) {
5187
5247
  }
5188
5248
  }
5189
5249
  });
5190
- onMount4(() => {
5250
+ onMount5(() => {
5191
5251
  if (!props.apiKey) {
5192
5252
  logger.error(
5193
5253
  "No API key provided to `Content` component. This can cause issues. Please provide an API key using the `apiKey` prop."
@@ -5203,13 +5263,13 @@ function EnableEditor(props) {
5203
5263
  mergeNewContent(props.content);
5204
5264
  }
5205
5265
  }
5206
- createEffect2(on2(() => [onUpdateFn_0_props_content()], onUpdateFn_0));
5266
+ createEffect3(on3(() => [onUpdateFn_0_props_content()], onUpdateFn_0));
5207
5267
  const onUpdateFn_1_props_builderContextSignal_content__data__jsCode = createMemo16(() => props.builderContextSignal.content?.data?.jsCode);
5208
5268
  function onUpdateFn_1() {
5209
5269
  evaluateJsCode();
5210
5270
  }
5211
- createEffect2(
5212
- on2(
5271
+ createEffect3(
5272
+ on3(
5213
5273
  () => [onUpdateFn_1_props_builderContextSignal_content__data__jsCode()],
5214
5274
  onUpdateFn_1
5215
5275
  )
@@ -5218,8 +5278,8 @@ function EnableEditor(props) {
5218
5278
  function onUpdateFn_2() {
5219
5279
  runHttpRequests();
5220
5280
  }
5221
- createEffect2(
5222
- on2(
5281
+ createEffect3(
5282
+ on3(
5223
5283
  () => [
5224
5284
  onUpdateFn_2_props_builderContextSignal_content__data__httpRequests()
5225
5285
  ],
@@ -5232,8 +5292,8 @@ function EnableEditor(props) {
5232
5292
  function onUpdateFn_3() {
5233
5293
  emitStateUpdate();
5234
5294
  }
5235
- createEffect2(
5236
- on2(
5295
+ createEffect3(
5296
+ on3(
5237
5297
  () => [onUpdateFn_3_props_builderContextSignal_rootState()],
5238
5298
  onUpdateFn_3
5239
5299
  )
@@ -5244,7 +5304,7 @@ function EnableEditor(props) {
5244
5304
  mergeNewRootState(props.data);
5245
5305
  }
5246
5306
  }
5247
- createEffect2(on2(() => [onUpdateFn_4_props_data()], onUpdateFn_4));
5307
+ createEffect3(on3(() => [onUpdateFn_4_props_data()], onUpdateFn_4));
5248
5308
  const onUpdateFn_5_props_locale = createMemo16(() => props.locale);
5249
5309
  function onUpdateFn_5() {
5250
5310
  if (props.locale) {
@@ -5253,7 +5313,7 @@ function EnableEditor(props) {
5253
5313
  });
5254
5314
  }
5255
5315
  }
5256
- createEffect2(on2(() => [onUpdateFn_5_props_locale()], onUpdateFn_5));
5316
+ createEffect3(on3(() => [onUpdateFn_5_props_locale()], onUpdateFn_5));
5257
5317
  return <><builder_context_default.Provider value={props.builderContextSignal}><Show12 when={props.builderContextSignal.content}><Dynamic5
5258
5318
  class={getWrapperClassName(
5259
5319
  props.content?.testVariationId || props.content?.id
@@ -5355,7 +5415,7 @@ function ContentComponent(props) {
5355
5415
  ...acc,
5356
5416
  [info.name]: {
5357
5417
  component,
5358
- ...serializeComponentInfo(info)
5418
+ ...serializeIncludingFunctions(info)
5359
5419
  }
5360
5420
  }),
5361
5421
  {}
@@ -5389,7 +5449,7 @@ function ContentComponent(props) {
5389
5449
  ].reduce(
5390
5450
  (acc, { component: _, ...info }) => ({
5391
5451
  ...acc,
5392
- [info.name]: serializeComponentInfo(info)
5452
+ [info.name]: serializeIncludingFunctions(info)
5393
5453
  }),
5394
5454
  {}
5395
5455
  ),
@@ -5478,7 +5538,7 @@ function ContentVariants(props) {
5478
5538
  canTrack: getDefaultCanTrack(props.canTrack)
5479
5539
  });
5480
5540
  });
5481
- onMount5(() => {
5541
+ onMount6(() => {
5482
5542
  setShouldRenderVariants(false);
5483
5543
  });
5484
5544
  return <><>
@@ -5606,13 +5666,13 @@ function Symbol(props) {
5606
5666
  }
5607
5667
  });
5608
5668
  }
5609
- onMount6(() => {
5669
+ onMount7(() => {
5610
5670
  });
5611
5671
  const onUpdateFn_0_props_symbol = createMemo20(() => props.symbol);
5612
5672
  function onUpdateFn_0() {
5613
5673
  setContent();
5614
5674
  }
5615
- createEffect3(on3(() => [onUpdateFn_0_props_symbol()], onUpdateFn_0));
5675
+ createEffect4(on4(() => [onUpdateFn_0_props_symbol()], onUpdateFn_0));
5616
5676
  return <><div class={className()} {...{}} {...props.attributes} {...{}}><Content_variants_default
5617
5677
  nonce={props.builderContext.nonce}
5618
5678
  isNestedRender={true}