@builder.io/sdk-qwik 0.3.0 → 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,