@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.
@@ -126,6 +126,15 @@ function getBlockComponentOptions(block) {
126
126
  };
127
127
  }
128
128
 
129
+ // src/helpers/omit.ts
130
+ function omit(obj, ...values) {
131
+ const newObject = Object.assign({}, obj);
132
+ for (const key of values) {
133
+ delete newObject[key];
134
+ }
135
+ return newObject;
136
+ }
137
+
129
138
  // src/helpers/logger.ts
130
139
  var logger = {
131
140
  log: (...message) => void 0,
@@ -332,6 +341,7 @@ var shouldForceBrowserRuntimeInNode = () => {
332
341
  var chooseBrowserOrServerEval = (args) => isBrowser() || shouldForceBrowserRuntimeInNode() ? runInBrowser(args) : runInBrowser(args);
333
342
 
334
343
  // src/functions/evaluate/evaluate.ts
344
+ var DISABLE_CACHE = true;
335
345
  var EvalCache = class _EvalCache {
336
346
  static cacheLimit = 20;
337
347
  static cache = /* @__PURE__ */ new Map();
@@ -380,7 +390,7 @@ function evaluate({
380
390
  rootState,
381
391
  localState
382
392
  };
383
- if (enableCache) {
393
+ if (enableCache && !DISABLE_CACHE) {
384
394
  const cacheKey = EvalCache.getCacheKey(args);
385
395
  const cachedValue = EvalCache.getCachedValue(cacheKey);
386
396
  if (cachedValue) {
@@ -421,6 +431,53 @@ function transformBlock(block) {
421
431
  }
422
432
 
423
433
  // src/functions/get-processed-block.ts
434
+ function deepCloneWithConditions(obj) {
435
+ if (obj === null || typeof obj !== "object") {
436
+ return obj;
437
+ }
438
+ if (Array.isArray(obj)) {
439
+ return obj.map((item) => deepCloneWithConditions(item));
440
+ }
441
+ if (obj["@type"] === "@builder.io/sdk:Element") {
442
+ return obj;
443
+ }
444
+ const clonedObj = {};
445
+ for (const key in obj) {
446
+ if (key !== "meta" && Object.prototype.hasOwnProperty.call(obj, key)) {
447
+ clonedObj[key] = deepCloneWithConditions(obj[key]);
448
+ }
449
+ }
450
+ return clonedObj;
451
+ }
452
+ var IS_SDK_WITHOUT_CACHED_PROCESSED_BLOCK = ["svelte", "vue", "angular", "qwik", "solid"].includes(TARGET);
453
+ var getCopy = (block) => {
454
+ if (IS_SDK_WITHOUT_CACHED_PROCESSED_BLOCK) {
455
+ const copy = fastClone(block);
456
+ const copied = {
457
+ ...copy,
458
+ properties: {
459
+ ...copy.properties
460
+ },
461
+ actions: {
462
+ ...copy.actions
463
+ }
464
+ };
465
+ return copied;
466
+ } else {
467
+ const copy = deepCloneWithConditions(omit(block, "children", "meta"));
468
+ return {
469
+ ...copy,
470
+ properties: {
471
+ ...copy.properties
472
+ },
473
+ actions: {
474
+ ...copy.actions
475
+ },
476
+ children: block.children,
477
+ meta: block.meta
478
+ };
479
+ }
480
+ };
424
481
  var evaluateBindings = ({
425
482
  block,
426
483
  context,
@@ -431,16 +488,7 @@ var evaluateBindings = ({
431
488
  if (!block.bindings) {
432
489
  return block;
433
490
  }
434
- const copy = fastClone(block);
435
- const copied = {
436
- ...copy,
437
- properties: {
438
- ...copy.properties
439
- },
440
- actions: {
441
- ...copy.actions
442
- }
443
- };
491
+ const copied = getCopy(block);
444
492
  for (const binding in block.bindings) {
445
493
  const expression = block.bindings[binding];
446
494
  const value = evaluate({
@@ -722,17 +770,9 @@ function mapStyleObjToStrIfNeeded(style) {
722
770
  // src/components/block/block.helpers.ts
723
771
  var getComponent = ({
724
772
  block,
725
- context,
726
773
  registeredComponents
727
774
  }) => {
728
- const componentName = getProcessedBlock({
729
- block,
730
- localState: context.localState,
731
- rootState: context.rootState,
732
- rootSetState: context.rootSetState,
733
- context: context.context,
734
- shouldEvaluateBindings: false
735
- }).component?.name;
775
+ const componentName = block.component?.name;
736
776
  if (!componentName) {
737
777
  return null;
738
778
  }
@@ -882,14 +922,7 @@ var inlined_styles_default = InlinedStyles;
882
922
  // src/components/block/components/block-styles.tsx
883
923
  function BlockStyles(props) {
884
924
  const canShowBlock = createMemo(() => {
885
- const processedBlock = getProcessedBlock({
886
- block: props.block,
887
- localState: props.context.localState,
888
- rootState: props.context.rootState,
889
- rootSetState: props.context.rootSetState,
890
- context: props.context.context,
891
- shouldEvaluateBindings: true
892
- });
925
+ const processedBlock = props.block;
893
926
  if (checkIsDefined(processedBlock.hide)) {
894
927
  return !processedBlock.hide;
895
928
  }
@@ -899,14 +932,7 @@ function BlockStyles(props) {
899
932
  return true;
900
933
  });
901
934
  const css = createMemo(() => {
902
- const processedBlock = getProcessedBlock({
903
- block: props.block,
904
- localState: props.context.localState,
905
- rootState: props.context.rootState,
906
- rootSetState: props.context.rootSetState,
907
- context: props.context.context,
908
- shouldEvaluateBindings: true
909
- });
935
+ const processedBlock = props.block;
910
936
  const styles = processedBlock.responsiveStyles;
911
937
  const content = props.context.content;
912
938
  const sizesWithUpdatedBreakpoints = getSizesForBreakpoints(content?.meta?.breakpoints || {});
@@ -1212,12 +1238,9 @@ var repeated_block_default = RepeatedBlock;
1212
1238
 
1213
1239
  // src/components/block/block.tsx
1214
1240
  function Block(props) {
1215
- const blockComponent = createMemo(() => {
1216
- return getComponent({
1217
- block: props.block,
1218
- context: props.context,
1219
- registeredComponents: props.registeredComponents
1220
- });
1241
+ createSignal({
1242
+ value: null,
1243
+ update: false
1221
1244
  });
1222
1245
  const repeatItem = createMemo(() => {
1223
1246
  return getRepeatItemData({
@@ -1226,7 +1249,7 @@ function Block(props) {
1226
1249
  });
1227
1250
  });
1228
1251
  const processedBlock = createMemo(() => {
1229
- return props.block.repeat?.collection ? props.block : getProcessedBlock({
1252
+ const blockToUse = props.block.repeat?.collection ? props.block : getProcessedBlock({
1230
1253
  block: props.block,
1231
1254
  localState: props.context.localState,
1232
1255
  rootState: props.context.rootState,
@@ -1234,6 +1257,13 @@ function Block(props) {
1234
1257
  context: props.context.context,
1235
1258
  shouldEvaluateBindings: true
1236
1259
  });
1260
+ return blockToUse;
1261
+ });
1262
+ const blockComponent = createMemo(() => {
1263
+ return getComponent({
1264
+ block: processedBlock(),
1265
+ registeredComponents: props.registeredComponents
1266
+ });
1237
1267
  });
1238
1268
  const Tag = createMemo(() => {
1239
1269
  const shouldUseLink = props.block.tagName === "a" || processedBlock().properties?.href || processedBlock().href;
@@ -1292,40 +1322,72 @@ function Block(props) {
1292
1322
  get children() {
1293
1323
  return [createComponent(block_styles_default, {
1294
1324
  get block() {
1295
- return props.block;
1325
+ return processedBlock();
1296
1326
  },
1297
1327
  get context() {
1298
1328
  return props.context;
1299
1329
  }
1300
1330
  }), createComponent(Show, {
1301
1331
  get fallback() {
1302
- return createComponent(component_ref_default, {
1303
- get componentRef() {
1304
- return componentRefProps().componentRef;
1305
- },
1306
- get componentOptions() {
1307
- return componentRefProps().componentOptions;
1308
- },
1309
- get blockChildren() {
1310
- return componentRefProps().blockChildren;
1311
- },
1312
- get context() {
1313
- return componentRefProps().context;
1314
- },
1315
- get registeredComponents() {
1316
- return componentRefProps().registeredComponents;
1317
- },
1318
- get linkComponent() {
1319
- return componentRefProps().linkComponent;
1320
- },
1321
- get builderBlock() {
1322
- return componentRefProps().builderBlock;
1332
+ return createComponent(Show, {
1333
+ get fallback() {
1334
+ return createComponent(For, {
1335
+ get each() {
1336
+ return repeatItem();
1337
+ },
1338
+ children: (data, _index) => {
1339
+ const index = _index();
1340
+ return createComponent(repeated_block_default, {
1341
+ key: index,
1342
+ get repeatContext() {
1343
+ return data.context;
1344
+ },
1345
+ get block() {
1346
+ return data.block;
1347
+ },
1348
+ get registeredComponents() {
1349
+ return props.registeredComponents;
1350
+ },
1351
+ get linkComponent() {
1352
+ return props.linkComponent;
1353
+ }
1354
+ });
1355
+ }
1356
+ });
1323
1357
  },
1324
- get includeBlockProps() {
1325
- return componentRefProps().includeBlockProps;
1358
+ get when() {
1359
+ return !repeatItem();
1326
1360
  },
1327
- get isInteractive() {
1328
- return componentRefProps().isInteractive;
1361
+ get children() {
1362
+ return createComponent(component_ref_default, {
1363
+ get componentRef() {
1364
+ return componentRefProps().componentRef;
1365
+ },
1366
+ get componentOptions() {
1367
+ return componentRefProps().componentOptions;
1368
+ },
1369
+ get blockChildren() {
1370
+ return componentRefProps().blockChildren;
1371
+ },
1372
+ get context() {
1373
+ return componentRefProps().context;
1374
+ },
1375
+ get registeredComponents() {
1376
+ return componentRefProps().registeredComponents;
1377
+ },
1378
+ get linkComponent() {
1379
+ return componentRefProps().linkComponent;
1380
+ },
1381
+ get builderBlock() {
1382
+ return componentRefProps().builderBlock;
1383
+ },
1384
+ get includeBlockProps() {
1385
+ return componentRefProps().includeBlockProps;
1386
+ },
1387
+ get isInteractive() {
1388
+ return componentRefProps().isInteractive;
1389
+ }
1390
+ });
1329
1391
  }
1330
1392
  });
1331
1393
  },
@@ -1435,7 +1497,7 @@ function Block(props) {
1435
1497
  });
1436
1498
  }
1437
1499
  var block_default = Block;
1438
- var _tmpl$2 = /* @__PURE__ */ template(`<style>.dynamic-1bb6a3a2 {
1500
+ var _tmpl$2 = /* @__PURE__ */ template(`<style>.dynamic-4da8c6f4 {
1439
1501
  display: flex;
1440
1502
  flex-direction: column;
1441
1503
  align-items: stretch;
@@ -1466,9 +1528,16 @@ function BlocksWrapper(props) {
1466
1528
  }, "*");
1467
1529
  }
1468
1530
  }
1531
+ let blocksWrapperRef;
1532
+ onMount(() => {
1533
+ });
1469
1534
  return [createComponent(Dynamic, mergeProps({
1470
1535
  get ["class"]() {
1471
- return className() + " dynamic-1bb6a3a2";
1536
+ return className() + " dynamic-4da8c6f4";
1537
+ },
1538
+ ref(r$) {
1539
+ const _ref$ = blocksWrapperRef;
1540
+ typeof _ref$ === "function" ? _ref$(r$) : blocksWrapperRef = r$;
1472
1541
  },
1473
1542
  get ["builder-path"]() {
1474
1543
  return props.path;
@@ -2930,7 +2999,8 @@ var componentInfo7 = {
2930
2999
  defaultValue: "children"
2931
3000
  }],
2932
3001
  shouldReceiveBuilderProps: {
2933
- builderContext: true
3002
+ builderContext: true,
3003
+ builderComponents: true
2934
3004
  }
2935
3005
  };
2936
3006
  var _tmpl$8 = /* @__PURE__ */ template(`<div>`);
@@ -2951,6 +3021,9 @@ function Slot(props) {
2951
3021
  get context() {
2952
3022
  return props.builderContext;
2953
3023
  },
3024
+ get registeredComponents() {
3025
+ return props.builderComponents;
3026
+ },
2954
3027
  get blocks() {
2955
3028
  return props.builderContext.rootState?.[props.name];
2956
3029
  }
@@ -4582,14 +4655,14 @@ var getDefaultRegisteredComponents = () => [{
4582
4655
  // src/functions/register-component.ts
4583
4656
  var createRegisterComponentMessage = (info) => ({
4584
4657
  type: "builder.registerComponent",
4585
- data: serializeComponentInfo(info)
4658
+ data: serializeIncludingFunctions(info)
4586
4659
  });
4587
4660
  var serializeFn = (fnValue) => {
4588
4661
  const fnStr = fnValue.toString().trim();
4589
4662
  const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(");
4590
4663
  return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
4591
4664
  };
4592
- function serializeComponentInfo(info) {
4665
+ function serializeIncludingFunctions(info) {
4593
4666
  return JSON.parse(JSON.stringify(info, (key, value) => {
4594
4667
  if (typeof value === "function") {
4595
4668
  return serializeFn(value);
@@ -4764,7 +4837,7 @@ var generateContentUrl = (options) => {
4764
4837
  locale,
4765
4838
  apiVersion = DEFAULT_API_VERSION,
4766
4839
  fields,
4767
- omit,
4840
+ omit: omit2,
4768
4841
  offset,
4769
4842
  cacheSeconds,
4770
4843
  staleCacheSeconds,
@@ -4787,7 +4860,7 @@ var generateContentUrl = (options) => {
4787
4860
  url.searchParams.set("locale", locale);
4788
4861
  if (enrich)
4789
4862
  url.searchParams.set("enrich", String(enrich));
4790
- url.searchParams.set("omit", omit || "meta.componentsUsed");
4863
+ url.searchParams.set("omit", omit2 || "meta.componentsUsed");
4791
4864
  if (fields) {
4792
4865
  url.searchParams.set("fields", fields);
4793
4866
  }
@@ -5157,11 +5230,14 @@ function isFromTrustedHost(trustedHosts, e) {
5157
5230
  }
5158
5231
 
5159
5232
  // src/constants/sdk-version.ts
5160
- var SDK_VERSION = "2.0.8";
5233
+ var SDK_VERSION = "2.0.13";
5161
5234
 
5162
5235
  // src/functions/register.ts
5163
5236
  var registry = {};
5164
5237
  function register(type, info) {
5238
+ if (type === "plugin") {
5239
+ info = serializeIncludingFunctions(info);
5240
+ }
5165
5241
  let typeList = registry[type];
5166
5242
  if (!typeList) {
5167
5243
  typeList = registry[type] = [];
@@ -5805,7 +5881,7 @@ function ContentComponent(props) {
5805
5881
  ...acc,
5806
5882
  [info.name]: {
5807
5883
  component,
5808
- ...serializeComponentInfo(info)
5884
+ ...serializeIncludingFunctions(info)
5809
5885
  }
5810
5886
  }), {}));
5811
5887
  const [builderContextSignal, setBuilderContextSignal] = createSignal({
@@ -5837,7 +5913,7 @@ function ContentComponent(props) {
5837
5913
  ...info
5838
5914
  }) => ({
5839
5915
  ...acc,
5840
- [info.name]: serializeComponentInfo(info)
5916
+ [info.name]: serializeIncludingFunctions(info)
5841
5917
  }), {}),
5842
5918
  inheritedStyles: {},
5843
5919
  BlocksWrapper: props.blocksWrapper || "div",