@builder.io/sdk-qwik 0.14.6 → 0.14.8

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.
@@ -211,7 +211,7 @@ function flattenState({ rootState, localState, rootSetState }) {
211
211
  if (localState && prop in localState)
212
212
  return localState[prop];
213
213
  const val = target[prop];
214
- if (typeof val === "object")
214
+ if (typeof val === "object" && val !== null)
215
215
  return flattenState({
216
216
  rootState: val,
217
217
  localState: void 0,
@@ -253,10 +253,34 @@ const shouldForceBrowserRuntimeInNode = () => {
253
253
  return false;
254
254
  };
255
255
  const chooseBrowserOrServerEval = (args) => build.isBrowser || shouldForceBrowserRuntimeInNode() ? runInBrowser(args) : runInBrowser(args);
256
- function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
256
+ const _EvalCache = class _EvalCache2 {
257
+ static getCacheKey(args) {
258
+ return JSON.stringify({
259
+ ...args,
260
+ // replace the event with a random number to break cache
261
+ // thats because we can't serialize the event object due to circular refs in DOM node refs.
262
+ event: args.event ? Math.random() : void 0
263
+ });
264
+ }
265
+ static getCachedValue(key) {
266
+ const cachedVal = _EvalCache2.cache.get(key);
267
+ return cachedVal;
268
+ }
269
+ static setCachedValue(key, value) {
270
+ if (_EvalCache2.cache.size > 20)
271
+ _EvalCache2.cache.delete(_EvalCache2.cache.keys().next().value);
272
+ _EvalCache2.cache.set(key, {
273
+ value
274
+ });
275
+ }
276
+ };
277
+ _EvalCache.cacheLimit = 20;
278
+ _EvalCache.cache = /* @__PURE__ */ new Map();
279
+ let EvalCache = _EvalCache;
280
+ function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true, enableCache }) {
257
281
  if (code === "") {
258
282
  logger.warn("Skipping evaluation of empty code block.");
259
- return;
283
+ return void 0;
260
284
  }
261
285
  const args = {
262
286
  code: parseCode(code, {
@@ -269,8 +293,19 @@ function evaluate({ code, context, localState, rootState, rootSetState, event, i
269
293
  rootState,
270
294
  localState
271
295
  };
296
+ if (enableCache) {
297
+ const cacheKey = EvalCache.getCacheKey(args);
298
+ const cachedValue = EvalCache.getCachedValue(cacheKey);
299
+ if (cachedValue)
300
+ return cachedValue.value;
301
+ }
272
302
  try {
273
- return chooseBrowserOrServerEval(args);
303
+ const newEval = chooseBrowserOrServerEval(args);
304
+ if (enableCache) {
305
+ const cacheKey = EvalCache.getCacheKey(args);
306
+ EvalCache.setCachedValue(cacheKey, newEval);
307
+ }
308
+ return newEval;
274
309
  } catch (e) {
275
310
  logger.error("Failed code evaluation: " + e.message, {
276
311
  code
@@ -309,7 +344,8 @@ const evaluateBindings = ({ block, context, localState, rootState, rootSetState
309
344
  localState,
310
345
  rootState,
311
346
  rootSetState,
312
- context
347
+ context,
348
+ enableCache: true
313
349
  });
314
350
  set(copied, binding, value);
315
351
  }
@@ -523,6 +559,51 @@ function bindScrollInViewAnimation(animation) {
523
559
  immediateOnScroll();
524
560
  });
525
561
  }
562
+ const camelToKebabCase = (string) => string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
563
+ const convertStyleMapToCSSArray = (style) => {
564
+ const cssProps = Object.entries(style).map(([key, value]) => {
565
+ if (typeof value === "string")
566
+ return `${camelToKebabCase(key)}: ${value};`;
567
+ else
568
+ return void 0;
569
+ });
570
+ return cssProps.filter(checkIsDefined);
571
+ };
572
+ const convertStyleMapToCSS = (style) => convertStyleMapToCSSArray(style).join("\n");
573
+ const createCssClass = ({ mediaQuery, className, styles }) => {
574
+ const cssClass = `.${className} {
575
+ ${convertStyleMapToCSS(styles)}
576
+ }`;
577
+ if (mediaQuery)
578
+ return `${mediaQuery} {
579
+ ${cssClass}
580
+ }`;
581
+ else
582
+ return cssClass;
583
+ };
584
+ function transformStyleProperty({ style }) {
585
+ return style;
586
+ }
587
+ const getStyle = ({ block, context }) => {
588
+ return mapStyleObjToStrIfNeeded(transformStyleProperty({
589
+ style: block.style || {},
590
+ context,
591
+ block
592
+ }));
593
+ };
594
+ function mapStyleObjToStrIfNeeded(style) {
595
+ switch (TARGET) {
596
+ case "svelte":
597
+ case "vue":
598
+ case "solid":
599
+ return convertStyleMapToCSSArray(style).join(" ");
600
+ case "qwik":
601
+ case "reactNative":
602
+ case "react":
603
+ case "rsc":
604
+ return style;
605
+ }
606
+ }
526
607
  const getComponent = ({ block, context, registeredComponents }) => {
527
608
  var _a;
528
609
  const componentName = (_a = getProcessedBlock({
@@ -553,7 +634,8 @@ const getRepeatItemData = ({ block, context }) => {
553
634
  localState: context.localState,
554
635
  rootState: context.rootState,
555
636
  rootSetState: context.rootSetState,
556
- context: context.context
637
+ context: context.context,
638
+ enableCache: true
557
639
  });
558
640
  if (!Array.isArray(itemsArray))
559
641
  return void 0;
@@ -617,28 +699,6 @@ const getSizesForBreakpoints = ({ small, medium }) => {
617
699
  };
618
700
  return newSizes;
619
701
  };
620
- const camelToKebabCase = (string) => string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
621
- const convertStyleMapToCSSArray = (style) => {
622
- const cssProps = Object.entries(style).map(([key, value]) => {
623
- if (typeof value === "string")
624
- return `${camelToKebabCase(key)}: ${value};`;
625
- else
626
- return void 0;
627
- });
628
- return cssProps.filter(checkIsDefined);
629
- };
630
- const convertStyleMapToCSS = (style) => convertStyleMapToCSSArray(style).join("\n");
631
- const createCssClass = ({ mediaQuery, className, styles }) => {
632
- const cssClass = `.${className} {
633
- ${convertStyleMapToCSS(styles)}
634
- }`;
635
- if (mediaQuery)
636
- return `${mediaQuery} {
637
- ${cssClass}
638
- }`;
639
- else
640
- return cssClass;
641
- };
642
702
  const InlinedStyles = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl((props) => {
643
703
  return /* @__PURE__ */ qwik._jsxQ("style", null, {
644
704
  dangerouslySetInnerHTML: qwik._fnSignal((p0) => p0.styles, [
@@ -737,7 +797,8 @@ function createEventHandler(value, options) {
737
797
  localState: options2.localState,
738
798
  rootState: options2.rootState,
739
799
  rootSetState: options2.rootSetState,
740
- event
800
+ event,
801
+ enableCache: true
741
802
  });
742
803
  }, "createEventHandler_7wCAiJVliNE", [
743
804
  options,
@@ -765,29 +826,6 @@ function getBlockActions(options) {
765
826
  }
766
827
  return obj;
767
828
  }
768
- function transformStyleProperty({ style }) {
769
- return style;
770
- }
771
- const getStyle = ({ block, context }) => {
772
- return mapStyleObjToStrIfNeeded(transformStyleProperty({
773
- style: block.style || {},
774
- context,
775
- block
776
- }));
777
- };
778
- function mapStyleObjToStrIfNeeded(style) {
779
- switch (TARGET) {
780
- case "svelte":
781
- case "vue":
782
- case "solid":
783
- return convertStyleMapToCSSArray(style).join(" ");
784
- case "qwik":
785
- case "reactNative":
786
- case "react":
787
- case "rsc":
788
- return style;
789
- }
790
- }
791
829
  function transformBlockProperties({ properties }) {
792
830
  return properties;
793
831
  }
@@ -967,9 +1005,6 @@ const RepeatedBlock = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inl
967
1005
  const Block = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl((props) => {
968
1006
  var _a;
969
1007
  qwik._jsxBranch();
970
- const state = qwik.useStore({
971
- childrenContext: props.context
972
- });
973
1008
  const blockComponent = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
974
1009
  const [props2] = qwik.useLexicalScope();
975
1010
  return getComponent({
@@ -1042,7 +1077,7 @@ const Block = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl(
1042
1077
  ]));
1043
1078
  const componentRefProps = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
1044
1079
  var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1045
- const [blockComponent2, processedBlock2, props2, state2] = qwik.useLexicalScope();
1080
+ const [blockComponent2, processedBlock2, props2] = qwik.useLexicalScope();
1046
1081
  return {
1047
1082
  blockChildren: processedBlock2.value.children ?? [],
1048
1083
  componentRef: (_a2 = blockComponent2.value) == null ? void 0 : _a2.component,
@@ -1056,7 +1091,7 @@ const Block = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl(
1056
1091
  builderComponents: props2.registeredComponents
1057
1092
  } : {}
1058
1093
  },
1059
- context: state2.childrenContext,
1094
+ context: props2.context,
1060
1095
  linkComponent: props2.linkComponent,
1061
1096
  registeredComponents: props2.registeredComponents,
1062
1097
  builderBlock: processedBlock2.value,
@@ -1066,8 +1101,7 @@ const Block = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl(
1066
1101
  }, "Block_component_componentRefProps_useComputed_Ikbl8VO04ho", [
1067
1102
  blockComponent,
1068
1103
  processedBlock,
1069
- props,
1070
- state
1104
+ props
1071
1105
  ]));
1072
1106
  qwik.useVisibleTaskQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
1073
1107
  const [processedBlock2] = qwik.useLexicalScope();
@@ -1175,19 +1209,19 @@ const Block = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl(
1175
1209
  (childrenWithoutParentComponent.value || []).map((child) => {
1176
1210
  return /* @__PURE__ */ qwik._jsxC(Block, {
1177
1211
  block: child,
1178
- get context() {
1179
- return state.childrenContext;
1180
- },
1181
1212
  get registeredComponents() {
1182
1213
  return props.registeredComponents;
1183
1214
  },
1184
1215
  get linkComponent() {
1185
1216
  return props.linkComponent;
1186
1217
  },
1218
+ get context() {
1219
+ return props.context;
1220
+ },
1187
1221
  [qwik._IMMUTABLE]: {
1188
- context: qwik._fnSignal((p0) => p0.childrenContext, [
1189
- state
1190
- ], "p0.childrenContext"),
1222
+ context: qwik._fnSignal((p0) => p0.context, [
1223
+ props
1224
+ ], "p0.context"),
1191
1225
  linkComponent: qwik._fnSignal((p0) => p0.linkComponent, [
1192
1226
  props
1193
1227
  ], "p0.linkComponent"),
@@ -4360,7 +4394,7 @@ function isFromTrustedHost(trustedHosts, e) {
4360
4394
  const url = new URL(e.origin), hostname = url.hostname;
4361
4395
  return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
4362
4396
  }
4363
- const SDK_VERSION = "0.14.6";
4397
+ const SDK_VERSION = "0.14.8";
4364
4398
  const registry = {};
4365
4399
  function register(type, info) {
4366
4400
  let typeList = registry[type];
@@ -4609,7 +4643,11 @@ const evaluateJsCode = function evaluateJsCode2(props, state, elementRef) {
4609
4643
  context: props.context || {},
4610
4644
  localState: void 0,
4611
4645
  rootState: props.builderContextSignal.rootState,
4612
- rootSetState: props.builderContextSignal.rootSetState
4646
+ rootSetState: props.builderContextSignal.rootSetState,
4647
+ /**
4648
+ * We don't want to cache the result of the JS code, since it's arbitrary side effect code.
4649
+ */
4650
+ enableCache: false
4613
4651
  });
4614
4652
  };
4615
4653
  const onClick = function onClick22(props, state, elementRef, event) {
@@ -4631,13 +4669,14 @@ const onClick = function onClick22(props, state, elementRef, event) {
4631
4669
  state.clicked = true;
4632
4670
  };
4633
4671
  const evalExpression = function evalExpression2(props, state, elementRef, expression) {
4634
- return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
4672
+ return expression.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
4635
4673
  code: group,
4636
4674
  context: props.context || {},
4637
4675
  localState: void 0,
4638
4676
  rootState: props.builderContextSignal.rootState,
4639
- rootSetState: props.builderContextSignal.rootSetState
4640
- }));
4677
+ rootSetState: props.builderContextSignal.rootSetState,
4678
+ enableCache: true
4679
+ })));
4641
4680
  };
4642
4681
  const handleRequest = function handleRequest2(props, state, elementRef, { url, key }) {
4643
4682
  fetch$1(url).then((response) => response.json()).then((json) => {
@@ -4919,17 +4958,7 @@ const getCss = ({ cssCode, contentId }) => {
4919
4958
  return cssCode;
4920
4959
  return (cssCode == null ? void 0 : cssCode.replace(/&/g, `div[builder-content-id="${contentId}"]`)) || "";
4921
4960
  };
4922
- const ContentStyles = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl((props) => {
4923
- const state = qwik.useStore({
4924
- injectedStyles: `
4925
- ${getCss({
4926
- cssCode: props.cssCode,
4927
- contentId: props.contentId
4928
- })}
4929
- ${getFontCss({
4930
- customFonts: props.customFonts
4931
- })}
4932
-
4961
+ const DEFAULT_STYLES = `
4933
4962
  .builder-button {
4934
4963
  all: unset;
4935
4964
  }
@@ -4946,6 +4975,21 @@ ${getFontCss({
4946
4975
  text-align: inherit;
4947
4976
  font-family: inherit;
4948
4977
  }
4978
+ `;
4979
+ const getDefaultStyles = (isNested) => {
4980
+ return !isNested ? DEFAULT_STYLES : "";
4981
+ };
4982
+ const ContentStyles = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl((props) => {
4983
+ const state = qwik.useStore({
4984
+ injectedStyles: `
4985
+ ${getCss({
4986
+ cssCode: props.cssCode,
4987
+ contentId: props.contentId
4988
+ })}
4989
+ ${getFontCss({
4990
+ customFonts: props.customFonts
4991
+ })}
4992
+ ${getDefaultStyles(props.isNestedRender)}
4949
4993
  `.trim()
4950
4994
  });
4951
4995
  return /* @__PURE__ */ qwik._jsxC(InlinedStyles, {
@@ -5093,6 +5137,9 @@ const ContentComponent = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.
5093
5137
  }
5094
5138
  }, 3, "LQ_0") : null,
5095
5139
  /* @__PURE__ */ qwik._jsxC(ContentStyles, {
5140
+ get isNestedRender() {
5141
+ return props.isNestedRender;
5142
+ },
5096
5143
  get contentId() {
5097
5144
  var _a2;
5098
5145
  return (_a2 = state.builderContextSignal.content) == null ? void 0 : _a2.id;
@@ -5123,7 +5170,10 @@ const ContentComponent = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.
5123
5170
  return (_b2 = (_a2 = p0.builderContextSignal.content) == null ? void 0 : _a2.data) == null ? void 0 : _b2.customFonts;
5124
5171
  }, [
5125
5172
  state
5126
- ], "p0.builderContextSignal.content?.data?.customFonts")
5173
+ ], "p0.builderContextSignal.content?.data?.customFonts"),
5174
+ isNestedRender: qwik._fnSignal((p0) => p0.isNestedRender, [
5175
+ props
5176
+ ], "p0.isNestedRender")
5127
5177
  }
5128
5178
  }, 3, "LQ_1"),
5129
5179
  /* @__PURE__ */ qwik._jsxC(Blocks, {
@@ -5245,7 +5295,7 @@ const ContentVariants = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.i
5245
5295
  ]));
5246
5296
  return /* @__PURE__ */ qwik._jsxC(qwik.Fragment, {
5247
5297
  children: [
5248
- !props.__isNestedRender && TARGET !== "reactNative" ? /* @__PURE__ */ qwik._jsxC(InlinedScript, {
5298
+ !props.isNestedRender && TARGET !== "reactNative" ? /* @__PURE__ */ qwik._jsxC(InlinedScript, {
5249
5299
  get scriptStr() {
5250
5300
  return getScriptString();
5251
5301
  },
@@ -5287,6 +5337,9 @@ const ContentVariants = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.i
5287
5337
  }, 3, "XM_2"),
5288
5338
  (getVariants(props.content) || []).map((variant) => {
5289
5339
  return /* @__PURE__ */ qwik._jsxC(ContentComponent, {
5340
+ get isNestedRender() {
5341
+ return props.isNestedRender;
5342
+ },
5290
5343
  content: variant,
5291
5344
  showContent: false,
5292
5345
  get model() {
@@ -5371,6 +5424,9 @@ const ContentVariants = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.i
5371
5424
  enrich: qwik._fnSignal((p0) => p0.enrich, [
5372
5425
  props
5373
5426
  ], "p0.enrich"),
5427
+ isNestedRender: qwik._fnSignal((p0) => p0.isNestedRender, [
5428
+ props
5429
+ ], "p0.isNestedRender"),
5374
5430
  isSsrAbTest: qwik._fnSignal((p0) => p0.shouldRenderVariants, [
5375
5431
  state
5376
5432
  ], "p0.shouldRenderVariants"),
@@ -5393,6 +5449,9 @@ const ContentVariants = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.i
5393
5449
  ]
5394
5450
  }, 1, "XM_3") : null,
5395
5451
  /* @__PURE__ */ qwik._jsxC(ContentComponent, {
5452
+ get isNestedRender() {
5453
+ return props.isNestedRender;
5454
+ },
5396
5455
  get content() {
5397
5456
  return defaultContent.value;
5398
5457
  },
@@ -5482,6 +5541,9 @@ const ContentVariants = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.i
5482
5541
  enrich: qwik._fnSignal((p0) => p0.enrich, [
5483
5542
  props
5484
5543
  ], "p0.enrich"),
5544
+ isNestedRender: qwik._fnSignal((p0) => p0.isNestedRender, [
5545
+ props
5546
+ ], "p0.isNestedRender"),
5485
5547
  isSsrAbTest: qwik._fnSignal((p0) => p0.shouldRenderVariants, [
5486
5548
  state
5487
5549
  ], "p0.shouldRenderVariants"),
@@ -5560,6 +5622,7 @@ const Symbol$1 = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQ
5560
5622
  return /* @__PURE__ */ qwik._jsxS("div", {
5561
5623
  ...props.attributes,
5562
5624
  children: /* @__PURE__ */ qwik._jsxC(ContentVariants, {
5625
+ isNestedRender: true,
5563
5626
  get apiVersion() {
5564
5627
  return props.builderContext.apiVersion;
5565
5628
  },
@@ -5631,6 +5694,7 @@ const Symbol$1 = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQ
5631
5694
  props,
5632
5695
  state
5633
5696
  ], "{...p0.symbol?.data,...p0.builderContext.localState,...p1.contentToUse?.data?.state}"),
5697
+ isNestedRender: qwik._IMMUTABLE,
5634
5698
  linkComponent: qwik._fnSignal((p0) => p0.builderLinkComponent, [
5635
5699
  props
5636
5700
  ], "p0.builderLinkComponent"),