@builder.io/sdk-qwik 0.2.3 → 0.3.1

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.
@@ -88,7 +88,7 @@ const getSizesForBreakpoints = ({ small, medium }) => {
88
88
  };
89
89
  return newSizes;
90
90
  };
91
- function evaluate({ code, context, state, event, isExpression = true }) {
91
+ function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
92
92
  if (code === "") {
93
93
  console.warn("Skipping evaluation of empty code block.");
94
94
  return;
@@ -101,11 +101,29 @@ function evaluate({ code, context, state, event, isExpression = true }) {
101
101
  const useReturn = isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
102
102
  const useCode = useReturn ? `return (${code});` : code;
103
103
  try {
104
- return new Function("builder", "Builder", "state", "context", "event", useCode)(builder, builder, state, context, event);
104
+ return new Function("builder", "Builder", "state", "context", "event", useCode)(builder, builder, flattenState(rootState, localState, rootSetState), context, event);
105
105
  } catch (e) {
106
106
  console.warn("Builder custom code error: \n While Evaluating: \n ", useCode, "\n", e);
107
107
  }
108
108
  }
109
+ function flattenState(rootState, localState, rootSetState) {
110
+ if (rootState === localState)
111
+ throw new Error("rootState === localState");
112
+ return new Proxy(rootState, {
113
+ get: (_, prop) => {
114
+ if (localState && prop in localState)
115
+ return localState[prop];
116
+ return rootState[prop];
117
+ },
118
+ set: (_, prop, value) => {
119
+ if (localState && prop in localState)
120
+ throw new Error("Writing to local state is not allowed as it is read-only.");
121
+ rootState[prop] = value;
122
+ rootSetState?.(rootState);
123
+ return true;
124
+ }
125
+ });
126
+ }
109
127
  const set = (obj, _path, value) => {
110
128
  if (Object(obj) !== obj)
111
129
  return obj;
@@ -116,7 +134,7 @@ const set = (obj, _path, value) => {
116
134
  function transformBlock(block) {
117
135
  return block;
118
136
  }
119
- const evaluateBindings = ({ block, context, state }) => {
137
+ const evaluateBindings = ({ block, context, localState, rootState, rootSetState }) => {
120
138
  if (!block.bindings)
121
139
  return block;
122
140
  const copy = fastClone(block);
@@ -133,19 +151,23 @@ const evaluateBindings = ({ block, context, state }) => {
133
151
  const expression = block.bindings[binding];
134
152
  const value = evaluate({
135
153
  code: expression,
136
- state,
154
+ localState,
155
+ rootState,
156
+ rootSetState,
137
157
  context
138
158
  });
139
159
  set(copied, binding, value);
140
160
  }
141
161
  return copied;
142
162
  };
143
- function getProcessedBlock({ block, context, shouldEvaluateBindings, state }) {
163
+ function getProcessedBlock({ block, context, shouldEvaluateBindings, localState, rootState, rootSetState }) {
144
164
  const transformedBlock = transformBlock(block);
145
165
  if (shouldEvaluateBindings)
146
166
  return evaluateBindings({
147
167
  block: transformedBlock,
148
- state,
168
+ localState,
169
+ rootState,
170
+ rootSetState,
149
171
  context
150
172
  });
151
173
  else
@@ -199,7 +221,9 @@ const BlockStyles = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlin
199
221
  const [props2] = qwik.useLexicalScope();
200
222
  return getProcessedBlock({
201
223
  block: props2.block,
202
- state: props2.context.state,
224
+ localState: props2.context.localState,
225
+ rootState: props2.context.rootState,
226
+ rootSetState: props2.context.rootSetState,
203
227
  context: props2.context.context,
204
228
  shouldEvaluateBindings: true
205
229
  });
@@ -273,7 +297,9 @@ function createEventHandler(value, options) {
273
297
  return evaluate({
274
298
  code: value2,
275
299
  context: options2.context,
276
- state: options2.state,
300
+ localState: options2.localState,
301
+ rootState: options2.rootState,
302
+ rootSetState: options2.rootSetState,
277
303
  event
278
304
  });
279
305
  }, "createEventHandler_7wCAiJVliNE", [
@@ -360,7 +386,9 @@ const isEmptyHtmlElement = (tagName) => {
360
386
  const getComponent = ({ block, context }) => {
361
387
  const componentName = getProcessedBlock({
362
388
  block,
363
- state: context.state,
389
+ localState: context.localState,
390
+ rootState: context.rootState,
391
+ rootSetState: context.rootSetState,
364
392
  context: context.context,
365
393
  shouldEvaluateBindings: false
366
394
  }).component?.name;
@@ -381,7 +409,9 @@ const getRepeatItemData = ({ block, context }) => {
381
409
  return void 0;
382
410
  const itemsArray = evaluate({
383
411
  code: repeat.collection,
384
- state: context.state,
412
+ localState: context.localState,
413
+ rootState: context.rootState,
414
+ rootSetState: context.rootSetState,
385
415
  context: context.context
386
416
  });
387
417
  if (!Array.isArray(itemsArray))
@@ -391,8 +421,8 @@ const getRepeatItemData = ({ block, context }) => {
391
421
  const repeatArray = itemsArray.map((item, index) => ({
392
422
  context: {
393
423
  ...context,
394
- state: {
395
- ...context.state,
424
+ localState: {
425
+ ...context.localState,
396
426
  $index: index,
397
427
  $item: item,
398
428
  [itemNameToUse]: item,
@@ -403,20 +433,6 @@ const getRepeatItemData = ({ block, context }) => {
403
433
  }));
404
434
  return repeatArray;
405
435
  };
406
- const getProxyState = (context) => {
407
- if (typeof Proxy === "undefined") {
408
- console.error("no Proxy available in this environment, cannot proxy state.");
409
- return context.state;
410
- }
411
- const useState = new Proxy(context.state, {
412
- set: (obj, prop, value) => {
413
- obj[prop] = value;
414
- context.setState?.(obj);
415
- return true;
416
- }
417
- });
418
- return useState;
419
- };
420
436
  const RenderComponent = (props) => {
421
437
  return /* @__PURE__ */ qwik._jsxC(jsxRuntime.Fragment, {
422
438
  children: props.componentRef ? /* @__PURE__ */ qwik._jsxC(props.componentRef, {
@@ -451,7 +467,9 @@ const RenderComponent = (props) => {
451
467
  const RenderRepeatedBlock = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl((props) => {
452
468
  qwik.useContextProvider(builderContext, qwik.useStore({
453
469
  content: props.repeatContext.content,
454
- state: props.repeatContext.state,
470
+ localState: props.repeatContext.localState,
471
+ rootState: props.repeatContext.rootState,
472
+ rootSetState: props.repeatContext.rootSetState,
455
473
  context: props.repeatContext.context,
456
474
  apiKey: props.repeatContext.apiKey,
457
475
  registeredComponents: props.repeatContext.registeredComponents,
@@ -478,7 +496,6 @@ const RenderRepeatedBlock = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qw
478
496
  const RenderBlock = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl((props) => {
479
497
  qwik._jsxBranch();
480
498
  const state = qwik.useStore({
481
- proxyState: getProxyState(props.context),
482
499
  tag: props.block.tagName || "div"
483
500
  });
484
501
  const component = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
@@ -490,26 +507,28 @@ const RenderBlock = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlin
490
507
  }, "RenderBlock_component_component_useComputed_qb7DMTJ9XGY", [
491
508
  props
492
509
  ]));
493
- const repeatItemData = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
510
+ const repeatItem = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
494
511
  const [props2] = qwik.useLexicalScope();
495
512
  return getRepeatItemData({
496
513
  block: props2.block,
497
514
  context: props2.context
498
515
  });
499
- }, "RenderBlock_component_repeatItemData_useComputed_Q2wkGRsY3KE", [
516
+ }, "RenderBlock_component_repeatItem_useComputed_NslhinGDzrU", [
500
517
  props
501
518
  ]));
502
519
  const useBlock = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
503
- const [props2, repeatItemData2] = qwik.useLexicalScope();
504
- return repeatItemData2.value ? props2.block : getProcessedBlock({
520
+ const [props2, repeatItem2] = qwik.useLexicalScope();
521
+ return repeatItem2.value ? props2.block : getProcessedBlock({
505
522
  block: props2.block,
506
- state: props2.context.state,
523
+ localState: props2.context.localState,
524
+ rootState: props2.context.rootState,
525
+ rootSetState: props2.context.rootSetState,
507
526
  context: props2.context.context,
508
527
  shouldEvaluateBindings: true
509
528
  });
510
529
  }, "RenderBlock_component_useBlock_useComputed_4ZTSqMpaluI", [
511
530
  props,
512
- repeatItemData
531
+ repeatItem
513
532
  ]));
514
533
  const canShowBlock = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
515
534
  const [useBlock2] = qwik.useLexicalScope();
@@ -522,15 +541,16 @@ const RenderBlock = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlin
522
541
  useBlock
523
542
  ]));
524
543
  const actions = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
525
- const [props2, state2, useBlock2] = qwik.useLexicalScope();
544
+ const [props2, useBlock2] = qwik.useLexicalScope();
526
545
  return getBlockActions({
527
546
  block: useBlock2.value,
528
- state: props2.context.state,
547
+ rootState: props2.context.rootState,
548
+ rootSetState: props2.context.rootSetState,
549
+ localState: props2.context.localState,
529
550
  context: props2.context.context
530
551
  });
531
552
  }, "RenderBlock_component_actions_useComputed_AOTwdXfwCqY", [
532
553
  props,
533
- state,
534
554
  useBlock
535
555
  ]));
536
556
  const attributes = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
@@ -545,12 +565,12 @@ const RenderBlock = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlin
545
565
  useBlock
546
566
  ]));
547
567
  const childrenWithoutParentComponent = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
548
- const [component2, repeatItemData2, useBlock2] = qwik.useLexicalScope();
549
- const shouldRenderChildrenOutsideRef = !component2.value?.component && !repeatItemData2.value;
568
+ const [component2, repeatItem2, useBlock2] = qwik.useLexicalScope();
569
+ const shouldRenderChildrenOutsideRef = !component2.value?.component && !repeatItem2.value;
550
570
  return shouldRenderChildrenOutsideRef ? useBlock2.value.children ?? [] : [];
551
571
  }, "RenderBlock_component_childrenWithoutParentComponent_useComputed_l4hT2V9liQc", [
552
572
  component,
553
- repeatItemData,
573
+ repeatItem,
554
574
  useBlock
555
575
  ]));
556
576
  const childrenContext = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
@@ -561,10 +581,11 @@ const RenderBlock = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlin
561
581
  return {
562
582
  apiKey: props2.context.apiKey,
563
583
  apiVersion: props2.context.apiVersion,
564
- state: props2.context.state,
584
+ localState: props2.context.localState,
585
+ rootState: props2.context.rootState,
586
+ rootSetState: props2.context.rootSetState,
565
587
  content: props2.context.content,
566
588
  context: props2.context.context,
567
- setState: props2.context.setState,
568
589
  registeredComponents: props2.context.registeredComponents,
569
590
  inheritedStyles: getInheritedTextStyles()
570
591
  };
@@ -603,7 +624,7 @@ const RenderBlock = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlin
603
624
  ...attributes.value,
604
625
  ...actions.value
605
626
  }, 0, "9d_0") : null,
606
- !isEmptyHtmlElement(state.tag) && repeatItemData.value ? (repeatItemData.value || []).map(function(data, index) {
627
+ !isEmptyHtmlElement(state.tag) && repeatItem.value ? (repeatItem.value || []).map(function(data, index) {
607
628
  return /* @__PURE__ */ qwik._jsxC(RenderRepeatedBlock, {
608
629
  get repeatContext() {
609
630
  return data.context;
@@ -617,7 +638,7 @@ const RenderBlock = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlin
617
638
  }
618
639
  }, 3, index);
619
640
  }) : null,
620
- !isEmptyHtmlElement(state.tag) && !repeatItemData.value ? /* @__PURE__ */ qwik._jsxC(state.tag, {
641
+ !isEmptyHtmlElement(state.tag) && !repeatItem.value ? /* @__PURE__ */ qwik._jsxC(state.tag, {
621
642
  ...attributes.value,
622
643
  ...actions.value,
623
644
  children: [
@@ -760,26 +781,28 @@ const getMobileStyle = function getMobileStyle2(props, state, builderContext2, {
760
781
  return state.stackAt === "never" ? desktopStyle : stackedStyle;
761
782
  };
762
783
  const columnCssVars = function columnCssVars2(props, state, builderContext2, index) {
763
- index === 0 ? 0 : state.gutterSize;
784
+ const gutter = index === 0 ? 0 : state.gutterSize;
764
785
  const width = getColumnCssWidth(props, state, builderContext2, index);
765
- const gutterPixels = `${state.gutterSize}px`;
786
+ const gutterPixels = `${gutter}px`;
787
+ const mobileWidth = "100%";
788
+ const mobileMarginLeft = 0;
766
789
  return {
767
790
  width,
768
791
  "margin-left": gutterPixels,
769
792
  "--column-width-mobile": getMobileStyle(props, state, builderContext2, {
770
- stackedStyle: "100%",
793
+ stackedStyle: mobileWidth,
771
794
  desktopStyle: width
772
795
  }),
773
796
  "--column-margin-left-mobile": getMobileStyle(props, state, builderContext2, {
774
- stackedStyle: 0,
797
+ stackedStyle: mobileMarginLeft,
775
798
  desktopStyle: gutterPixels
776
799
  }),
777
800
  "--column-width-tablet": getTabletStyle(props, state, builderContext2, {
778
- stackedStyle: "100%",
801
+ stackedStyle: mobileWidth,
779
802
  desktopStyle: width
780
803
  }),
781
804
  "--column-margin-left-tablet": getTabletStyle(props, state, builderContext2, {
782
- stackedStyle: 0,
805
+ stackedStyle: mobileMarginLeft,
783
806
  desktopStyle: gutterPixels
784
807
  })
785
808
  };
@@ -962,16 +985,17 @@ const Image = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl(
962
985
  const srcSetToUse = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
963
986
  const [props2] = qwik.useLexicalScope();
964
987
  const imageToUse = props2.image || props2.src;
965
- if (!imageToUse || !(imageToUse.match(/builder\.io/) || imageToUse.match(/cdn\.shopify\.com/)))
988
+ const url = imageToUse;
989
+ if (!url || !(url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/)))
966
990
  return props2.srcset;
967
991
  if (props2.srcset && props2.image?.includes("builder.io/api/v1/image")) {
968
992
  if (!props2.srcset.includes(props2.image.split("?")[0])) {
969
993
  console.debug("Removed given srcset");
970
- return getSrcSet(imageToUse);
994
+ return getSrcSet(url);
971
995
  }
972
996
  } else if (props2.image && !props2.srcset)
973
- return getSrcSet(imageToUse);
974
- return getSrcSet(imageToUse);
997
+ return getSrcSet(url);
998
+ return getSrcSet(url);
975
999
  }, "Image_component_srcSetToUse_useComputed_TZMibf9Gpvw", [
976
1000
  props
977
1001
  ]));
@@ -1388,6 +1412,7 @@ const componentInfo$7 = {
1388
1412
  required: true,
1389
1413
  defaultValue: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F72c80f114dc149019051b6852a9e3b7a",
1390
1414
  onChange: serializeFn((options) => {
1415
+ const DEFAULT_ASPECT_RATIO = 0.7041;
1391
1416
  options.delete("srcset");
1392
1417
  options.delete("noWebp");
1393
1418
  function loadImage(url, timeout = 6e4) {
@@ -1418,10 +1443,10 @@ const componentInfo$7 = {
1418
1443
  if (blob.type.includes("svg"))
1419
1444
  options.set("noWebp", true);
1420
1445
  });
1421
- if (value && (!aspectRatio || aspectRatio === 0.7041))
1446
+ if (value && (!aspectRatio || aspectRatio === DEFAULT_ASPECT_RATIO))
1422
1447
  return loadImage(value).then((img) => {
1423
1448
  const possiblyUpdatedAspectRatio = options.get("aspectRatio");
1424
- if (options.get("image") === value && (!possiblyUpdatedAspectRatio || possiblyUpdatedAspectRatio === 0.7041)) {
1449
+ if (options.get("image") === value && (!possiblyUpdatedAspectRatio || possiblyUpdatedAspectRatio === DEFAULT_ASPECT_RATIO)) {
1425
1450
  if (img.width && img.height) {
1426
1451
  options.set("aspectRatio", round2(img.height / img.width));
1427
1452
  options.set("height", img.height);
@@ -1612,10 +1637,11 @@ const componentInfo$5 = {
1612
1637
  }
1613
1638
  ]
1614
1639
  };
1640
+ const MSG_PREFIX = "[Builder.io]: ";
1615
1641
  const logger = {
1616
- log: (...message) => console.log("[Builder.io]: ", ...message),
1617
- error: (...message) => console.error("[Builder.io]: ", ...message),
1618
- warn: (...message) => console.warn("[Builder.io]: ", ...message)
1642
+ log: (...message) => console.log(MSG_PREFIX, ...message),
1643
+ error: (...message) => console.error(MSG_PREFIX, ...message),
1644
+ warn: (...message) => console.warn(MSG_PREFIX, ...message)
1619
1645
  };
1620
1646
  function getGlobalThis() {
1621
1647
  if (typeof globalThis !== "undefined")
@@ -1713,7 +1739,8 @@ const setCookie = async ({ name, value, expires, canTrack }) => {
1713
1739
  console.warn("[COOKIE] SET error: ", err);
1714
1740
  }
1715
1741
  };
1716
- const getContentTestKey = (id) => `${"builderio.variations"}.${id}`;
1742
+ const BUILDER_STORE_PREFIX = "builderio.variations";
1743
+ const getContentTestKey = (id) => `${BUILDER_STORE_PREFIX}.${id}`;
1717
1744
  const getContentVariationCookie = ({ contentId, canTrack }) => getCookie({
1718
1745
  name: getContentTestKey(contentId),
1719
1746
  canTrack
@@ -1808,6 +1835,8 @@ function flatten(object, path = null, separator = ".") {
1808
1835
  };
1809
1836
  }, {});
1810
1837
  }
1838
+ const BUILDER_SEARCHPARAMS_PREFIX = "builder.";
1839
+ const BUILDER_OPTIONS_PREFIX = "options.";
1811
1840
  const convertSearchParamsToQueryObject = (searchParams) => {
1812
1841
  const options = {};
1813
1842
  searchParams.forEach((value, key) => {
@@ -1821,8 +1850,8 @@ const getBuilderSearchParams = (_options) => {
1821
1850
  const options = normalizeSearchParams(_options);
1822
1851
  const newOptions = {};
1823
1852
  Object.keys(options).forEach((key) => {
1824
- if (key.startsWith("builder.")) {
1825
- const trimmedKey = key.replace("builder.", "").replace("options.", "");
1853
+ if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
1854
+ const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, "").replace(BUILDER_OPTIONS_PREFIX, "");
1826
1855
  newOptions[trimmedKey] = options[key];
1827
1856
  }
1828
1857
  });
@@ -1967,7 +1996,7 @@ const Symbol$1 = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQ
1967
1996
  get data() {
1968
1997
  return {
1969
1998
  ...props.symbol?.data,
1970
- ...builderContext$1.state,
1999
+ ...builderContext$1.localState,
1971
2000
  ...state.contentToUse?.data?.state
1972
2001
  };
1973
2002
  },
@@ -1992,13 +2021,13 @@ const Symbol$1 = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQ
1992
2021
  ], "Object.values(p0.registeredComponents)"),
1993
2022
  data: qwik._fnSignal((p0, p1, p2) => ({
1994
2023
  ...p1.symbol?.data,
1995
- ...p0.state,
2024
+ ...p0.localState,
1996
2025
  ...p2.contentToUse?.data?.state
1997
2026
  }), [
1998
2027
  builderContext$1,
1999
2028
  props,
2000
2029
  state
2001
- ], "{...p1.symbol?.data,...p0.state,...p2.contentToUse?.data?.state}"),
2030
+ ], "{...p1.symbol?.data,...p0.localState,...p2.contentToUse?.data?.state}"),
2002
2031
  model: qwik._fnSignal((p0) => p0.symbol?.model, [
2003
2032
  props
2004
2033
  ], "p0.symbol?.model"),
@@ -2225,7 +2254,8 @@ const componentInfo$2 = {
2225
2254
  const url = options.get("url");
2226
2255
  if (url) {
2227
2256
  options.set("content", "Loading...");
2228
- return fetch(`https://iframe.ly/api/iframely?url=${url}&api_key=${"ae0e60e78201a3f2b0de4b"}`).then((res) => res.json()).then((data) => {
2257
+ const apiKey = "ae0e60e78201a3f2b0de4b";
2258
+ return fetch(`https://iframe.ly/api/iframely?url=${url}&api_key=${apiKey}`).then((res) => res.json()).then((data) => {
2229
2259
  if (options.get("url") === url) {
2230
2260
  if (data.html)
2231
2261
  options.set("content", data.html);
@@ -2509,11 +2539,12 @@ function uuidv4() {
2509
2539
  function uuid() {
2510
2540
  return uuidv4().replace(/-/g, "");
2511
2541
  }
2542
+ const SESSION_LOCAL_STORAGE_KEY = "builderSessionId";
2512
2543
  const getSessionId = async ({ canTrack }) => {
2513
2544
  if (!canTrack)
2514
2545
  return void 0;
2515
2546
  const sessionId = await getCookie({
2516
- name: "builderSessionId",
2547
+ name: SESSION_LOCAL_STORAGE_KEY,
2517
2548
  canTrack
2518
2549
  });
2519
2550
  if (checkIsDefined(sessionId))
@@ -2529,7 +2560,7 @@ const getSessionId = async ({ canTrack }) => {
2529
2560
  };
2530
2561
  const createSessionId = () => uuid();
2531
2562
  const setSessionId = ({ id, canTrack }) => setCookie({
2532
- name: "builderSessionId",
2563
+ name: SESSION_LOCAL_STORAGE_KEY,
2533
2564
  value: id,
2534
2565
  canTrack
2535
2566
  });
@@ -2552,11 +2583,12 @@ const setLocalStorageItem = ({ key, canTrack, value }) => {
2552
2583
  console.debug("[LocalStorage] SET error: ", err);
2553
2584
  }
2554
2585
  };
2586
+ const VISITOR_LOCAL_STORAGE_KEY = "builderVisitorId";
2555
2587
  const getVisitorId = ({ canTrack }) => {
2556
2588
  if (!canTrack)
2557
2589
  return void 0;
2558
2590
  const visitorId = getLocalStorageItem({
2559
- key: "builderVisitorId",
2591
+ key: VISITOR_LOCAL_STORAGE_KEY,
2560
2592
  canTrack
2561
2593
  });
2562
2594
  if (checkIsDefined(visitorId))
@@ -2572,7 +2604,7 @@ const getVisitorId = ({ canTrack }) => {
2572
2604
  };
2573
2605
  const createVisitorId = () => uuid();
2574
2606
  const setVisitorId = ({ id, canTrack }) => setLocalStorageItem({
2575
- key: "builderVisitorId",
2607
+ key: VISITOR_LOCAL_STORAGE_KEY,
2576
2608
  value: id,
2577
2609
  canTrack
2578
2610
  });
@@ -2730,6 +2762,7 @@ const getInteractionPropertiesForEvent = (event) => {
2730
2762
  }
2731
2763
  };
2732
2764
  };
2765
+ const SDK_VERSION = "0.3.1";
2733
2766
  const registry = {};
2734
2767
  function register(type, info) {
2735
2768
  let typeList = registry[type];
@@ -2797,6 +2830,7 @@ const setupBrowserForEditing = (options = {}) => {
2797
2830
  type: "builder.sdkInfo",
2798
2831
  data: {
2799
2832
  target: TARGET,
2833
+ version: SDK_VERSION,
2800
2834
  supportsPatchUpdates: false,
2801
2835
  supportsAddBlockScoping: true,
2802
2836
  supportsCustomBreakpoints: true
@@ -2986,8 +3020,8 @@ const setBreakpoints = function setBreakpoints2(props, state, elementRef, breakp
2986
3020
  }
2987
3021
  };
2988
3022
  };
2989
- const setContextState = function setContextState2(props, state, elementRef, newState) {
2990
- state.contentState = newState;
3023
+ const contentSetState = function contentSetState2(props, state, elementRef, newRootState) {
3024
+ state.contentState = newRootState;
2991
3025
  };
2992
3026
  const processMessage = function processMessage2(props, state, elementRef, event) {
2993
3027
  const { data } = event;
@@ -3021,7 +3055,9 @@ const evaluateJsCode = function evaluateJsCode2(props, state, elementRef) {
3021
3055
  evaluate({
3022
3056
  code: jsCode,
3023
3057
  context: props.context || {},
3024
- state: state.contentState
3058
+ localState: void 0,
3059
+ rootState: state.contentState,
3060
+ rootSetState: contentSetState.bind(null, props, state, elementRef)
3025
3061
  });
3026
3062
  };
3027
3063
  const onClick = function onClick22(props, state, elementRef, event) {
@@ -3045,7 +3081,9 @@ const evalExpression = function evalExpression2(props, state, elementRef, expres
3045
3081
  return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
3046
3082
  code: group,
3047
3083
  context: props.context || {},
3048
- state: state.contentState
3084
+ localState: void 0,
3085
+ rootState: state.contentState,
3086
+ rootSetState: contentSetState.bind(null, props, state, elementRef)
3049
3087
  }));
3050
3088
  };
3051
3089
  const handleRequest = function handleRequest2(props, state, elementRef, { url, key }) {
@@ -3054,7 +3092,7 @@ const handleRequest = function handleRequest2(props, state, elementRef, { url, k
3054
3092
  ...state.contentState,
3055
3093
  [key]: json
3056
3094
  };
3057
- setContextState(props, state, elementRef, newState);
3095
+ contentSetState(props, state, elementRef, newState);
3058
3096
  }).catch((err) => {
3059
3097
  console.error("error fetching dynamic data", url, err);
3060
3098
  });
@@ -3114,7 +3152,9 @@ const RenderContent = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inl
3114
3152
  });
3115
3153
  qwik.useContextProvider(builderContext, qwik.useStore({
3116
3154
  content: state.useContent,
3117
- state: state.contentState,
3155
+ localState: void 0,
3156
+ rootState: state.contentState,
3157
+ rootSetState: void 0,
3118
3158
  context: props.context || {},
3119
3159
  apiKey: props.apiKey,
3120
3160
  apiVersion: props.apiVersion,
@@ -3170,7 +3210,7 @@ const RenderContent = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inl
3170
3210
  mergeNewContent(props2, state2, elementRef2, content);
3171
3211
  });
3172
3212
  }
3173
- evaluateJsCode(props2, state2);
3213
+ evaluateJsCode(props2, state2, elementRef2);
3174
3214
  runHttpRequests(props2, state2, elementRef2);
3175
3215
  emitStateUpdate(props2, state2);
3176
3216
  }
@@ -3193,7 +3233,7 @@ const RenderContent = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inl
3193
3233
  const [elementRef2, props2, state2] = qwik.useLexicalScope();
3194
3234
  track2(() => state2.useContent?.data?.jsCode);
3195
3235
  track2(() => state2.contentState);
3196
- evaluateJsCode(props2, state2);
3236
+ evaluateJsCode(props2, state2, elementRef2);
3197
3237
  }, "RenderContent_component_useTask_1_X59YMGOetns", [
3198
3238
  elementRef,
3199
3239
  props,
@@ -86,7 +86,7 @@ const getSizesForBreakpoints = ({ small, medium }) => {
86
86
  };
87
87
  return newSizes;
88
88
  };
89
- function evaluate({ code, context, state, event, isExpression = true }) {
89
+ function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
90
90
  if (code === "") {
91
91
  console.warn("Skipping evaluation of empty code block.");
92
92
  return;
@@ -99,11 +99,29 @@ function evaluate({ code, context, state, event, isExpression = true }) {
99
99
  const useReturn = isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
100
100
  const useCode = useReturn ? `return (${code});` : code;
101
101
  try {
102
- return new Function("builder", "Builder", "state", "context", "event", useCode)(builder, builder, state, context, event);
102
+ return new Function("builder", "Builder", "state", "context", "event", useCode)(builder, builder, flattenState(rootState, localState, rootSetState), context, event);
103
103
  } catch (e) {
104
104
  console.warn("Builder custom code error: \n While Evaluating: \n ", useCode, "\n", e);
105
105
  }
106
106
  }
107
+ function flattenState(rootState, localState, rootSetState) {
108
+ if (rootState === localState)
109
+ throw new Error("rootState === localState");
110
+ return new Proxy(rootState, {
111
+ get: (_, prop) => {
112
+ if (localState && prop in localState)
113
+ return localState[prop];
114
+ return rootState[prop];
115
+ },
116
+ set: (_, prop, value) => {
117
+ if (localState && prop in localState)
118
+ throw new Error("Writing to local state is not allowed as it is read-only.");
119
+ rootState[prop] = value;
120
+ rootSetState?.(rootState);
121
+ return true;
122
+ }
123
+ });
124
+ }
107
125
  const set = (obj, _path, value) => {
108
126
  if (Object(obj) !== obj)
109
127
  return obj;
@@ -114,7 +132,7 @@ const set = (obj, _path, value) => {
114
132
  function transformBlock(block) {
115
133
  return block;
116
134
  }
117
- const evaluateBindings = ({ block, context, state }) => {
135
+ const evaluateBindings = ({ block, context, localState, rootState, rootSetState }) => {
118
136
  if (!block.bindings)
119
137
  return block;
120
138
  const copy = fastClone(block);
@@ -131,19 +149,23 @@ const evaluateBindings = ({ block, context, state }) => {
131
149
  const expression = block.bindings[binding];
132
150
  const value = evaluate({
133
151
  code: expression,
134
- state,
152
+ localState,
153
+ rootState,
154
+ rootSetState,
135
155
  context
136
156
  });
137
157
  set(copied, binding, value);
138
158
  }
139
159
  return copied;
140
160
  };
141
- function getProcessedBlock({ block, context, shouldEvaluateBindings, state }) {
161
+ function getProcessedBlock({ block, context, shouldEvaluateBindings, localState, rootState, rootSetState }) {
142
162
  const transformedBlock = transformBlock(block);
143
163
  if (shouldEvaluateBindings)
144
164
  return evaluateBindings({
145
165
  block: transformedBlock,
146
- state,
166
+ localState,
167
+ rootState,
168
+ rootSetState,
147
169
  context
148
170
  });
149
171
  else
@@ -197,7 +219,9 @@ const BlockStyles = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((pro
197
219
  const [props2] = useLexicalScope();
198
220
  return getProcessedBlock({
199
221
  block: props2.block,
200
- state: props2.context.state,
222
+ localState: props2.context.localState,
223
+ rootState: props2.context.rootState,
224
+ rootSetState: props2.context.rootSetState,
201
225
  context: props2.context.context,
202
226
  shouldEvaluateBindings: true
203
227
  });
@@ -271,7 +295,9 @@ function createEventHandler(value, options) {
271
295
  return evaluate({
272
296
  code: value2,
273
297
  context: options2.context,
274
- state: options2.state,
298
+ localState: options2.localState,
299
+ rootState: options2.rootState,
300
+ rootSetState: options2.rootSetState,
275
301
  event
276
302
  });
277
303
  }, "createEventHandler_7wCAiJVliNE", [
@@ -358,7 +384,9 @@ const isEmptyHtmlElement = (tagName) => {
358
384
  const getComponent = ({ block, context }) => {
359
385
  const componentName = getProcessedBlock({
360
386
  block,
361
- state: context.state,
387
+ localState: context.localState,
388
+ rootState: context.rootState,
389
+ rootSetState: context.rootSetState,
362
390
  context: context.context,
363
391
  shouldEvaluateBindings: false
364
392
  }).component?.name;
@@ -379,7 +407,9 @@ const getRepeatItemData = ({ block, context }) => {
379
407
  return void 0;
380
408
  const itemsArray = evaluate({
381
409
  code: repeat.collection,
382
- state: context.state,
410
+ localState: context.localState,
411
+ rootState: context.rootState,
412
+ rootSetState: context.rootSetState,
383
413
  context: context.context
384
414
  });
385
415
  if (!Array.isArray(itemsArray))
@@ -389,8 +419,8 @@ const getRepeatItemData = ({ block, context }) => {
389
419
  const repeatArray = itemsArray.map((item, index) => ({
390
420
  context: {
391
421
  ...context,
392
- state: {
393
- ...context.state,
422
+ localState: {
423
+ ...context.localState,
394
424
  $index: index,
395
425
  $item: item,
396
426
  [itemNameToUse]: item,
@@ -401,20 +431,6 @@ const getRepeatItemData = ({ block, context }) => {
401
431
  }));
402
432
  return repeatArray;
403
433
  };
404
- const getProxyState = (context) => {
405
- if (typeof Proxy === "undefined") {
406
- console.error("no Proxy available in this environment, cannot proxy state.");
407
- return context.state;
408
- }
409
- const useState = new Proxy(context.state, {
410
- set: (obj, prop, value) => {
411
- obj[prop] = value;
412
- context.setState?.(obj);
413
- return true;
414
- }
415
- });
416
- return useState;
417
- };
418
434
  const RenderComponent = (props) => {
419
435
  return /* @__PURE__ */ _jsxC(Fragment, {
420
436
  children: props.componentRef ? /* @__PURE__ */ _jsxC(props.componentRef, {
@@ -449,7 +465,9 @@ const RenderComponent = (props) => {
449
465
  const RenderRepeatedBlock = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props) => {
450
466
  useContextProvider(builderContext, useStore({
451
467
  content: props.repeatContext.content,
452
- state: props.repeatContext.state,
468
+ localState: props.repeatContext.localState,
469
+ rootState: props.repeatContext.rootState,
470
+ rootSetState: props.repeatContext.rootSetState,
453
471
  context: props.repeatContext.context,
454
472
  apiKey: props.repeatContext.apiKey,
455
473
  registeredComponents: props.repeatContext.registeredComponents,
@@ -476,7 +494,6 @@ const RenderRepeatedBlock = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlined
476
494
  const RenderBlock = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props) => {
477
495
  _jsxBranch();
478
496
  const state = useStore({
479
- proxyState: getProxyState(props.context),
480
497
  tag: props.block.tagName || "div"
481
498
  });
482
499
  const component = useComputedQrl(/* @__PURE__ */ inlinedQrl(() => {
@@ -488,26 +505,28 @@ const RenderBlock = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((pro
488
505
  }, "RenderBlock_component_component_useComputed_qb7DMTJ9XGY", [
489
506
  props
490
507
  ]));
491
- const repeatItemData = useComputedQrl(/* @__PURE__ */ inlinedQrl(() => {
508
+ const repeatItem = useComputedQrl(/* @__PURE__ */ inlinedQrl(() => {
492
509
  const [props2] = useLexicalScope();
493
510
  return getRepeatItemData({
494
511
  block: props2.block,
495
512
  context: props2.context
496
513
  });
497
- }, "RenderBlock_component_repeatItemData_useComputed_Q2wkGRsY3KE", [
514
+ }, "RenderBlock_component_repeatItem_useComputed_NslhinGDzrU", [
498
515
  props
499
516
  ]));
500
517
  const useBlock = useComputedQrl(/* @__PURE__ */ inlinedQrl(() => {
501
- const [props2, repeatItemData2] = useLexicalScope();
502
- return repeatItemData2.value ? props2.block : getProcessedBlock({
518
+ const [props2, repeatItem2] = useLexicalScope();
519
+ return repeatItem2.value ? props2.block : getProcessedBlock({
503
520
  block: props2.block,
504
- state: props2.context.state,
521
+ localState: props2.context.localState,
522
+ rootState: props2.context.rootState,
523
+ rootSetState: props2.context.rootSetState,
505
524
  context: props2.context.context,
506
525
  shouldEvaluateBindings: true
507
526
  });
508
527
  }, "RenderBlock_component_useBlock_useComputed_4ZTSqMpaluI", [
509
528
  props,
510
- repeatItemData
529
+ repeatItem
511
530
  ]));
512
531
  const canShowBlock = useComputedQrl(/* @__PURE__ */ inlinedQrl(() => {
513
532
  const [useBlock2] = useLexicalScope();
@@ -520,15 +539,16 @@ const RenderBlock = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((pro
520
539
  useBlock
521
540
  ]));
522
541
  const actions = useComputedQrl(/* @__PURE__ */ inlinedQrl(() => {
523
- const [props2, state2, useBlock2] = useLexicalScope();
542
+ const [props2, useBlock2] = useLexicalScope();
524
543
  return getBlockActions({
525
544
  block: useBlock2.value,
526
- state: props2.context.state,
545
+ rootState: props2.context.rootState,
546
+ rootSetState: props2.context.rootSetState,
547
+ localState: props2.context.localState,
527
548
  context: props2.context.context
528
549
  });
529
550
  }, "RenderBlock_component_actions_useComputed_AOTwdXfwCqY", [
530
551
  props,
531
- state,
532
552
  useBlock
533
553
  ]));
534
554
  const attributes = useComputedQrl(/* @__PURE__ */ inlinedQrl(() => {
@@ -543,12 +563,12 @@ const RenderBlock = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((pro
543
563
  useBlock
544
564
  ]));
545
565
  const childrenWithoutParentComponent = useComputedQrl(/* @__PURE__ */ inlinedQrl(() => {
546
- const [component2, repeatItemData2, useBlock2] = useLexicalScope();
547
- const shouldRenderChildrenOutsideRef = !component2.value?.component && !repeatItemData2.value;
566
+ const [component2, repeatItem2, useBlock2] = useLexicalScope();
567
+ const shouldRenderChildrenOutsideRef = !component2.value?.component && !repeatItem2.value;
548
568
  return shouldRenderChildrenOutsideRef ? useBlock2.value.children ?? [] : [];
549
569
  }, "RenderBlock_component_childrenWithoutParentComponent_useComputed_l4hT2V9liQc", [
550
570
  component,
551
- repeatItemData,
571
+ repeatItem,
552
572
  useBlock
553
573
  ]));
554
574
  const childrenContext = useComputedQrl(/* @__PURE__ */ inlinedQrl(() => {
@@ -559,10 +579,11 @@ const RenderBlock = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((pro
559
579
  return {
560
580
  apiKey: props2.context.apiKey,
561
581
  apiVersion: props2.context.apiVersion,
562
- state: props2.context.state,
582
+ localState: props2.context.localState,
583
+ rootState: props2.context.rootState,
584
+ rootSetState: props2.context.rootSetState,
563
585
  content: props2.context.content,
564
586
  context: props2.context.context,
565
- setState: props2.context.setState,
566
587
  registeredComponents: props2.context.registeredComponents,
567
588
  inheritedStyles: getInheritedTextStyles()
568
589
  };
@@ -601,7 +622,7 @@ const RenderBlock = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((pro
601
622
  ...attributes.value,
602
623
  ...actions.value
603
624
  }, 0, "9d_0") : null,
604
- !isEmptyHtmlElement(state.tag) && repeatItemData.value ? (repeatItemData.value || []).map(function(data, index) {
625
+ !isEmptyHtmlElement(state.tag) && repeatItem.value ? (repeatItem.value || []).map(function(data, index) {
605
626
  return /* @__PURE__ */ _jsxC(RenderRepeatedBlock, {
606
627
  get repeatContext() {
607
628
  return data.context;
@@ -615,7 +636,7 @@ const RenderBlock = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((pro
615
636
  }
616
637
  }, 3, index);
617
638
  }) : null,
618
- !isEmptyHtmlElement(state.tag) && !repeatItemData.value ? /* @__PURE__ */ _jsxC(state.tag, {
639
+ !isEmptyHtmlElement(state.tag) && !repeatItem.value ? /* @__PURE__ */ _jsxC(state.tag, {
619
640
  ...attributes.value,
620
641
  ...actions.value,
621
642
  children: [
@@ -758,26 +779,28 @@ const getMobileStyle = function getMobileStyle2(props, state, builderContext2, {
758
779
  return state.stackAt === "never" ? desktopStyle : stackedStyle;
759
780
  };
760
781
  const columnCssVars = function columnCssVars2(props, state, builderContext2, index) {
761
- index === 0 ? 0 : state.gutterSize;
782
+ const gutter = index === 0 ? 0 : state.gutterSize;
762
783
  const width = getColumnCssWidth(props, state, builderContext2, index);
763
- const gutterPixels = `${state.gutterSize}px`;
784
+ const gutterPixels = `${gutter}px`;
785
+ const mobileWidth = "100%";
786
+ const mobileMarginLeft = 0;
764
787
  return {
765
788
  width,
766
789
  "margin-left": gutterPixels,
767
790
  "--column-width-mobile": getMobileStyle(props, state, builderContext2, {
768
- stackedStyle: "100%",
791
+ stackedStyle: mobileWidth,
769
792
  desktopStyle: width
770
793
  }),
771
794
  "--column-margin-left-mobile": getMobileStyle(props, state, builderContext2, {
772
- stackedStyle: 0,
795
+ stackedStyle: mobileMarginLeft,
773
796
  desktopStyle: gutterPixels
774
797
  }),
775
798
  "--column-width-tablet": getTabletStyle(props, state, builderContext2, {
776
- stackedStyle: "100%",
799
+ stackedStyle: mobileWidth,
777
800
  desktopStyle: width
778
801
  }),
779
802
  "--column-margin-left-tablet": getTabletStyle(props, state, builderContext2, {
780
- stackedStyle: 0,
803
+ stackedStyle: mobileMarginLeft,
781
804
  desktopStyle: gutterPixels
782
805
  })
783
806
  };
@@ -960,16 +983,17 @@ const Image = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props) =>
960
983
  const srcSetToUse = useComputedQrl(/* @__PURE__ */ inlinedQrl(() => {
961
984
  const [props2] = useLexicalScope();
962
985
  const imageToUse = props2.image || props2.src;
963
- if (!imageToUse || !(imageToUse.match(/builder\.io/) || imageToUse.match(/cdn\.shopify\.com/)))
986
+ const url = imageToUse;
987
+ if (!url || !(url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/)))
964
988
  return props2.srcset;
965
989
  if (props2.srcset && props2.image?.includes("builder.io/api/v1/image")) {
966
990
  if (!props2.srcset.includes(props2.image.split("?")[0])) {
967
991
  console.debug("Removed given srcset");
968
- return getSrcSet(imageToUse);
992
+ return getSrcSet(url);
969
993
  }
970
994
  } else if (props2.image && !props2.srcset)
971
- return getSrcSet(imageToUse);
972
- return getSrcSet(imageToUse);
995
+ return getSrcSet(url);
996
+ return getSrcSet(url);
973
997
  }, "Image_component_srcSetToUse_useComputed_TZMibf9Gpvw", [
974
998
  props
975
999
  ]));
@@ -1386,6 +1410,7 @@ const componentInfo$7 = {
1386
1410
  required: true,
1387
1411
  defaultValue: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F72c80f114dc149019051b6852a9e3b7a",
1388
1412
  onChange: serializeFn((options) => {
1413
+ const DEFAULT_ASPECT_RATIO = 0.7041;
1389
1414
  options.delete("srcset");
1390
1415
  options.delete("noWebp");
1391
1416
  function loadImage(url, timeout = 6e4) {
@@ -1416,10 +1441,10 @@ const componentInfo$7 = {
1416
1441
  if (blob.type.includes("svg"))
1417
1442
  options.set("noWebp", true);
1418
1443
  });
1419
- if (value && (!aspectRatio || aspectRatio === 0.7041))
1444
+ if (value && (!aspectRatio || aspectRatio === DEFAULT_ASPECT_RATIO))
1420
1445
  return loadImage(value).then((img) => {
1421
1446
  const possiblyUpdatedAspectRatio = options.get("aspectRatio");
1422
- if (options.get("image") === value && (!possiblyUpdatedAspectRatio || possiblyUpdatedAspectRatio === 0.7041)) {
1447
+ if (options.get("image") === value && (!possiblyUpdatedAspectRatio || possiblyUpdatedAspectRatio === DEFAULT_ASPECT_RATIO)) {
1423
1448
  if (img.width && img.height) {
1424
1449
  options.set("aspectRatio", round2(img.height / img.width));
1425
1450
  options.set("height", img.height);
@@ -1610,10 +1635,11 @@ const componentInfo$5 = {
1610
1635
  }
1611
1636
  ]
1612
1637
  };
1638
+ const MSG_PREFIX = "[Builder.io]: ";
1613
1639
  const logger = {
1614
- log: (...message) => console.log("[Builder.io]: ", ...message),
1615
- error: (...message) => console.error("[Builder.io]: ", ...message),
1616
- warn: (...message) => console.warn("[Builder.io]: ", ...message)
1640
+ log: (...message) => console.log(MSG_PREFIX, ...message),
1641
+ error: (...message) => console.error(MSG_PREFIX, ...message),
1642
+ warn: (...message) => console.warn(MSG_PREFIX, ...message)
1617
1643
  };
1618
1644
  function getGlobalThis() {
1619
1645
  if (typeof globalThis !== "undefined")
@@ -1711,7 +1737,8 @@ const setCookie = async ({ name, value, expires, canTrack }) => {
1711
1737
  console.warn("[COOKIE] SET error: ", err);
1712
1738
  }
1713
1739
  };
1714
- const getContentTestKey = (id) => `${"builderio.variations"}.${id}`;
1740
+ const BUILDER_STORE_PREFIX = "builderio.variations";
1741
+ const getContentTestKey = (id) => `${BUILDER_STORE_PREFIX}.${id}`;
1715
1742
  const getContentVariationCookie = ({ contentId, canTrack }) => getCookie({
1716
1743
  name: getContentTestKey(contentId),
1717
1744
  canTrack
@@ -1806,6 +1833,8 @@ function flatten(object, path = null, separator = ".") {
1806
1833
  };
1807
1834
  }, {});
1808
1835
  }
1836
+ const BUILDER_SEARCHPARAMS_PREFIX = "builder.";
1837
+ const BUILDER_OPTIONS_PREFIX = "options.";
1809
1838
  const convertSearchParamsToQueryObject = (searchParams) => {
1810
1839
  const options = {};
1811
1840
  searchParams.forEach((value, key) => {
@@ -1819,8 +1848,8 @@ const getBuilderSearchParams = (_options) => {
1819
1848
  const options = normalizeSearchParams(_options);
1820
1849
  const newOptions = {};
1821
1850
  Object.keys(options).forEach((key) => {
1822
- if (key.startsWith("builder.")) {
1823
- const trimmedKey = key.replace("builder.", "").replace("options.", "");
1851
+ if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
1852
+ const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, "").replace(BUILDER_OPTIONS_PREFIX, "");
1824
1853
  newOptions[trimmedKey] = options[key];
1825
1854
  }
1826
1855
  });
@@ -1965,7 +1994,7 @@ const Symbol$1 = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props)
1965
1994
  get data() {
1966
1995
  return {
1967
1996
  ...props.symbol?.data,
1968
- ...builderContext$1.state,
1997
+ ...builderContext$1.localState,
1969
1998
  ...state.contentToUse?.data?.state
1970
1999
  };
1971
2000
  },
@@ -1990,13 +2019,13 @@ const Symbol$1 = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props)
1990
2019
  ], "Object.values(p0.registeredComponents)"),
1991
2020
  data: _fnSignal((p0, p1, p2) => ({
1992
2021
  ...p1.symbol?.data,
1993
- ...p0.state,
2022
+ ...p0.localState,
1994
2023
  ...p2.contentToUse?.data?.state
1995
2024
  }), [
1996
2025
  builderContext$1,
1997
2026
  props,
1998
2027
  state
1999
- ], "{...p1.symbol?.data,...p0.state,...p2.contentToUse?.data?.state}"),
2028
+ ], "{...p1.symbol?.data,...p0.localState,...p2.contentToUse?.data?.state}"),
2000
2029
  model: _fnSignal((p0) => p0.symbol?.model, [
2001
2030
  props
2002
2031
  ], "p0.symbol?.model"),
@@ -2223,7 +2252,8 @@ const componentInfo$2 = {
2223
2252
  const url = options.get("url");
2224
2253
  if (url) {
2225
2254
  options.set("content", "Loading...");
2226
- return fetch(`https://iframe.ly/api/iframely?url=${url}&api_key=${"ae0e60e78201a3f2b0de4b"}`).then((res) => res.json()).then((data) => {
2255
+ const apiKey = "ae0e60e78201a3f2b0de4b";
2256
+ return fetch(`https://iframe.ly/api/iframely?url=${url}&api_key=${apiKey}`).then((res) => res.json()).then((data) => {
2227
2257
  if (options.get("url") === url) {
2228
2258
  if (data.html)
2229
2259
  options.set("content", data.html);
@@ -2507,11 +2537,12 @@ function uuidv4() {
2507
2537
  function uuid() {
2508
2538
  return uuidv4().replace(/-/g, "");
2509
2539
  }
2540
+ const SESSION_LOCAL_STORAGE_KEY = "builderSessionId";
2510
2541
  const getSessionId = async ({ canTrack }) => {
2511
2542
  if (!canTrack)
2512
2543
  return void 0;
2513
2544
  const sessionId = await getCookie({
2514
- name: "builderSessionId",
2545
+ name: SESSION_LOCAL_STORAGE_KEY,
2515
2546
  canTrack
2516
2547
  });
2517
2548
  if (checkIsDefined(sessionId))
@@ -2527,7 +2558,7 @@ const getSessionId = async ({ canTrack }) => {
2527
2558
  };
2528
2559
  const createSessionId = () => uuid();
2529
2560
  const setSessionId = ({ id, canTrack }) => setCookie({
2530
- name: "builderSessionId",
2561
+ name: SESSION_LOCAL_STORAGE_KEY,
2531
2562
  value: id,
2532
2563
  canTrack
2533
2564
  });
@@ -2550,11 +2581,12 @@ const setLocalStorageItem = ({ key, canTrack, value }) => {
2550
2581
  console.debug("[LocalStorage] SET error: ", err);
2551
2582
  }
2552
2583
  };
2584
+ const VISITOR_LOCAL_STORAGE_KEY = "builderVisitorId";
2553
2585
  const getVisitorId = ({ canTrack }) => {
2554
2586
  if (!canTrack)
2555
2587
  return void 0;
2556
2588
  const visitorId = getLocalStorageItem({
2557
- key: "builderVisitorId",
2589
+ key: VISITOR_LOCAL_STORAGE_KEY,
2558
2590
  canTrack
2559
2591
  });
2560
2592
  if (checkIsDefined(visitorId))
@@ -2570,7 +2602,7 @@ const getVisitorId = ({ canTrack }) => {
2570
2602
  };
2571
2603
  const createVisitorId = () => uuid();
2572
2604
  const setVisitorId = ({ id, canTrack }) => setLocalStorageItem({
2573
- key: "builderVisitorId",
2605
+ key: VISITOR_LOCAL_STORAGE_KEY,
2574
2606
  value: id,
2575
2607
  canTrack
2576
2608
  });
@@ -2728,6 +2760,7 @@ const getInteractionPropertiesForEvent = (event) => {
2728
2760
  }
2729
2761
  };
2730
2762
  };
2763
+ const SDK_VERSION = "0.3.1";
2731
2764
  const registry = {};
2732
2765
  function register(type, info) {
2733
2766
  let typeList = registry[type];
@@ -2795,6 +2828,7 @@ const setupBrowserForEditing = (options = {}) => {
2795
2828
  type: "builder.sdkInfo",
2796
2829
  data: {
2797
2830
  target: TARGET,
2831
+ version: SDK_VERSION,
2798
2832
  supportsPatchUpdates: false,
2799
2833
  supportsAddBlockScoping: true,
2800
2834
  supportsCustomBreakpoints: true
@@ -2984,8 +3018,8 @@ const setBreakpoints = function setBreakpoints2(props, state, elementRef, breakp
2984
3018
  }
2985
3019
  };
2986
3020
  };
2987
- const setContextState = function setContextState2(props, state, elementRef, newState) {
2988
- state.contentState = newState;
3021
+ const contentSetState = function contentSetState2(props, state, elementRef, newRootState) {
3022
+ state.contentState = newRootState;
2989
3023
  };
2990
3024
  const processMessage = function processMessage2(props, state, elementRef, event) {
2991
3025
  const { data } = event;
@@ -3019,7 +3053,9 @@ const evaluateJsCode = function evaluateJsCode2(props, state, elementRef) {
3019
3053
  evaluate({
3020
3054
  code: jsCode,
3021
3055
  context: props.context || {},
3022
- state: state.contentState
3056
+ localState: void 0,
3057
+ rootState: state.contentState,
3058
+ rootSetState: contentSetState.bind(null, props, state, elementRef)
3023
3059
  });
3024
3060
  };
3025
3061
  const onClick = function onClick22(props, state, elementRef, event) {
@@ -3043,7 +3079,9 @@ const evalExpression = function evalExpression2(props, state, elementRef, expres
3043
3079
  return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
3044
3080
  code: group,
3045
3081
  context: props.context || {},
3046
- state: state.contentState
3082
+ localState: void 0,
3083
+ rootState: state.contentState,
3084
+ rootSetState: contentSetState.bind(null, props, state, elementRef)
3047
3085
  }));
3048
3086
  };
3049
3087
  const handleRequest = function handleRequest2(props, state, elementRef, { url, key }) {
@@ -3052,7 +3090,7 @@ const handleRequest = function handleRequest2(props, state, elementRef, { url, k
3052
3090
  ...state.contentState,
3053
3091
  [key]: json
3054
3092
  };
3055
- setContextState(props, state, elementRef, newState);
3093
+ contentSetState(props, state, elementRef, newState);
3056
3094
  }).catch((err) => {
3057
3095
  console.error("error fetching dynamic data", url, err);
3058
3096
  });
@@ -3112,7 +3150,9 @@ const RenderContent = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((p
3112
3150
  });
3113
3151
  useContextProvider(builderContext, useStore({
3114
3152
  content: state.useContent,
3115
- state: state.contentState,
3153
+ localState: void 0,
3154
+ rootState: state.contentState,
3155
+ rootSetState: void 0,
3116
3156
  context: props.context || {},
3117
3157
  apiKey: props.apiKey,
3118
3158
  apiVersion: props.apiVersion,
@@ -3168,7 +3208,7 @@ const RenderContent = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((p
3168
3208
  mergeNewContent(props2, state2, elementRef2, content);
3169
3209
  });
3170
3210
  }
3171
- evaluateJsCode(props2, state2);
3211
+ evaluateJsCode(props2, state2, elementRef2);
3172
3212
  runHttpRequests(props2, state2, elementRef2);
3173
3213
  emitStateUpdate(props2, state2);
3174
3214
  }
@@ -3191,7 +3231,7 @@ const RenderContent = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((p
3191
3231
  const [elementRef2, props2, state2] = useLexicalScope();
3192
3232
  track2(() => state2.useContent?.data?.jsCode);
3193
3233
  track2(() => state2.contentState);
3194
- evaluateJsCode(props2, state2);
3234
+ evaluateJsCode(props2, state2, elementRef2);
3195
3235
  }, "RenderContent_component_useTask_1_X59YMGOetns", [
3196
3236
  elementRef,
3197
3237
  props,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-qwik",
3
- "version": "0.2.3",
3
+ "version": "0.3.1",
4
4
  "description": "Builder.io Qwik SDK",
5
5
  "type": "module",
6
6
  "main": "./lib/index.qwik.cjs",
@@ -22,18 +22,15 @@
22
22
  },
23
23
  "scripts": {
24
24
  "typecheck": "tsc --noEmit",
25
- "build": "tsc && vite build --mode lib",
26
- "release:patch": "yarn run build && npm version patch && npm publish",
27
- "release:minor": "yarn run build && npm version minor && npm publish",
28
- "release:dev": "yarn run build && npm version prerelease && npm publish --tag dev"
25
+ "build": "tsc && vite build --mode lib"
29
26
  },
30
27
  "devDependencies": {
31
- "@builder.io/qwik": "^0.101.0",
28
+ "@builder.io/qwik": "^1.0.0",
32
29
  "@types/node": "latest",
33
30
  "typescript": "^4",
34
31
  "vite": "^3.0.4"
35
32
  },
36
33
  "peerDependencies": {
37
- "@builder.io/qwik": ">=0.13.3"
34
+ "@builder.io/qwik": ">=1.0.0"
38
35
  }
39
36
  }
@@ -10,4 +10,3 @@ export declare const getRepeatItemData: ({ block, context, }: {
10
10
  block: BuilderBlock;
11
11
  context: BuilderContextInterface;
12
12
  }) => RepeatData[] | undefined;
13
- export declare const getProxyState: (context: BuilderContextInterface) => BuilderContextInterface['state'];
@@ -3,7 +3,7 @@ import { Breakpoints, BuilderContent } from "../../types/builder-content.js";
3
3
  import { RenderContentProps } from "./render-content.types.js";
4
4
  export declare const mergeNewContent: (props: any, state: any, elementRef: any, newContent: BuilderContent) => void;
5
5
  export declare const setBreakpoints: (props: any, state: any, elementRef: any, breakpoints: Breakpoints) => void;
6
- export declare const setContextState: (props: any, state: any, elementRef: any, newState: BuilderRenderState) => void;
6
+ export declare const contentSetState: (props: any, state: any, elementRef: any, newRootState: BuilderRenderState) => void;
7
7
  export declare const processMessage: (props: any, state: any, elementRef: any, event: MessageEvent) => void;
8
8
  export declare const evaluateJsCode: (props: any, state: any, elementRef: any) => void;
9
9
  export declare const onClick: (props: any, state: any, elementRef: any, event: any) => void;
@@ -1,3 +1,9 @@
1
+ import type { Nullable } from '../../helpers/nullable';
2
+ import type { BuilderContent } from '../../types/builder-content';
3
+ export declare const checkShouldRunVariants: ({ canTrack, content, }: {
4
+ canTrack: Nullable<boolean>;
5
+ content: Nullable<BuilderContent>;
6
+ }) => boolean;
1
7
  type VariantData = {
2
8
  id: string;
3
9
  testRatio?: number;
@@ -0,0 +1 @@
1
+ export declare const SDK_VERSION = "0.3.1";
@@ -11,8 +11,23 @@ export type BuilderRenderContext = Record<string, unknown>;
11
11
  export interface BuilderContextInterface {
12
12
  content: Nullable<BuilderContent>;
13
13
  context: BuilderRenderContext;
14
- state: BuilderRenderState;
15
- setState?: (state: BuilderRenderState) => void;
14
+ /**
15
+ * The state of the application.
16
+ *
17
+ * NOTE: see `localState` below to understand how it is different from `rootState`.
18
+ */
19
+ rootState: BuilderRenderState;
20
+ /**
21
+ * Some frameworks have a `setState` function which needs to be invoked to notify
22
+ * the framework of state change. (other frameworks don't in which case it is `undefined')
23
+ */
24
+ rootSetState: ((rootState: BuilderRenderState) => void) | undefined;
25
+ /**
26
+ * The local state of the current component. This is different from `rootState` in that
27
+ * it can be a child state created by a repeater containing local state.
28
+ * The `rootState` is where all of the state mutations are actually stored.
29
+ */
30
+ localState: BuilderRenderState | undefined;
16
31
  apiKey: string | null;
17
32
  apiVersion: ApiVersion | undefined;
18
33
  registeredComponents: RegisteredComponents;
@@ -1,6 +1,7 @@
1
- import type { BuilderContextInterface } from '../context/types.js';
2
- export declare function evaluate({ code, context, state, event, isExpression, }: {
1
+ import type { BuilderContextInterface, BuilderRenderState } from '../context/types.js';
2
+ export declare function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression, }: {
3
3
  code: string;
4
4
  event?: Event;
5
5
  isExpression?: boolean;
6
- } & Pick<BuilderContextInterface, 'state' | 'context'>): any;
6
+ } & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): any;
7
+ export declare function flattenState(rootState: Record<string | symbol, any>, localState: Record<string | symbol, any> | undefined, rootSetState: ((rootState: BuilderRenderState) => void) | undefined): BuilderRenderState;
@@ -0,0 +1 @@
1
+ export {};
@@ -2,4 +2,4 @@ import type { BuilderContextInterface } from '../context/types.js';
2
2
  import type { BuilderBlock } from '../types/builder-block.js';
3
3
  export declare function createEventHandler(value: string, options: {
4
4
  block: BuilderBlock;
5
- } & Pick<BuilderContextInterface, 'state' | 'context'>): (event: Event) => any;
5
+ } & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): (event: Event) => any;
@@ -5,5 +5,5 @@ type Actions = {
5
5
  };
6
6
  export declare function getBlockActions(options: {
7
7
  block: BuilderBlock;
8
- } & Pick<BuilderContextInterface, 'state' | 'context'>): Actions;
8
+ } & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): Actions;
9
9
  export {};
@@ -1,10 +1,10 @@
1
1
  import type { BuilderContextInterface } from '../context/types.js';
2
2
  import type { BuilderBlock } from '../types/builder-block.js';
3
- export declare function getProcessedBlock({ block, context, shouldEvaluateBindings, state, }: {
3
+ export declare function getProcessedBlock({ block, context, shouldEvaluateBindings, localState, rootState, rootSetState, }: {
4
4
  block: BuilderBlock;
5
5
  /**
6
6
  * In some cases, we want to avoid evaluating bindings and only want framework-specific block transformation. It is
7
7
  * also sometimes too early to consider bindings, e.g. when we might be looking at a repeated block.
8
8
  */
9
9
  shouldEvaluateBindings: boolean;
10
- } & Pick<BuilderContextInterface, 'state' | 'context'>): BuilderBlock;
10
+ } & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): BuilderBlock;
@@ -0,0 +1 @@
1
+ export declare const getDefaultCanTrack: (canTrack?: boolean) => boolean;