@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.
@@ -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.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Builder.io Qwik SDK",
5
5
  "type": "module",
6
6
  "main": "./lib/index.qwik.cjs",
@@ -22,13 +22,10 @@
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"
@@ -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'];
@@ -0,0 +1,3 @@
1
+ import type { RenderComponentProps } from "./render-component";
2
+ export declare const RenderComponentWithContext: import("@builder.io/qwik").Component<RenderComponentProps>;
3
+ export default RenderComponentWithContext;
@@ -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;
@@ -0,0 +1,12 @@
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;
7
+ type VariantData = {
8
+ id: string;
9
+ testRatio?: number;
10
+ };
11
+ export declare const getVariantsScriptString: (variants: VariantData[], contentId: string) => string;
12
+ export {};
@@ -0,0 +1,3 @@
1
+ import { RenderContentProps } from "../render-content/render-content.types";
2
+ export declare const RenderContentVariants: import("@builder.io/qwik").Component<RenderContentProps>;
3
+ export default RenderContentVariants;
@@ -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;
@@ -0,0 +1 @@
1
+ export declare const convertStyleObject: (obj: Partial<CSSStyleDeclaration>) => Partial<CSSStyleDeclaration>;
@@ -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 {};