@builder.io/sdk-svelte 1.0.15 → 1.0.17

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.
Files changed (53) hide show
  1. package/lib/browser/blocks/columns/columns.svelte +1 -1
  2. package/lib/browser/components/block/components/block-styles.svelte +1 -1
  3. package/lib/browser/components/content/components/enable-editor.svelte +31 -31
  4. package/lib/browser/components/content/components/styles.svelte +1 -1
  5. package/lib/browser/components/content/content.svelte +1 -1
  6. package/lib/browser/components/content-variants/content-variants.svelte +9 -6
  7. package/lib/browser/components/content-variants/helpers.d.ts +1 -1
  8. package/lib/browser/components/content-variants/helpers.js +1 -1
  9. package/lib/browser/components/inlined-script.svelte +2 -2
  10. package/lib/browser/components/inlined-script.svelte.d.ts +2 -2
  11. package/lib/browser/components/inlined-styles.svelte +2 -2
  12. package/lib/browser/components/inlined-styles.svelte.d.ts +2 -2
  13. package/lib/browser/constants/sdk-version.d.ts +1 -1
  14. package/lib/browser/constants/sdk-version.js +1 -1
  15. package/lib/edge/blocks/columns/columns.svelte +1 -1
  16. package/lib/edge/components/block/components/block-styles.svelte +1 -1
  17. package/lib/edge/components/content/components/enable-editor.svelte +31 -31
  18. package/lib/edge/components/content/components/styles.svelte +1 -1
  19. package/lib/edge/components/content/content.svelte +1 -1
  20. package/lib/edge/components/content-variants/content-variants.svelte +9 -6
  21. package/lib/edge/components/content-variants/helpers.d.ts +1 -1
  22. package/lib/edge/components/content-variants/helpers.js +1 -1
  23. package/lib/edge/components/inlined-script.svelte +2 -2
  24. package/lib/edge/components/inlined-script.svelte.d.ts +2 -2
  25. package/lib/edge/components/inlined-styles.svelte +2 -2
  26. package/lib/edge/components/inlined-styles.svelte.d.ts +2 -2
  27. package/lib/edge/constants/sdk-version.d.ts +1 -1
  28. package/lib/edge/constants/sdk-version.js +1 -1
  29. package/lib/node/blocks/columns/columns.svelte +1 -1
  30. package/lib/node/components/block/components/block-styles.svelte +1 -1
  31. package/lib/node/components/content/components/enable-editor.svelte +31 -31
  32. package/lib/node/components/content/components/styles.svelte +1 -1
  33. package/lib/node/components/content/content.svelte +1 -1
  34. package/lib/node/components/content-variants/content-variants.svelte +9 -6
  35. package/lib/node/components/content-variants/helpers.d.ts +1 -1
  36. package/lib/node/components/content-variants/helpers.js +1 -1
  37. package/lib/node/components/inlined-script.svelte +2 -2
  38. package/lib/node/components/inlined-script.svelte.d.ts +2 -2
  39. package/lib/node/components/inlined-styles.svelte +2 -2
  40. package/lib/node/components/inlined-styles.svelte.d.ts +2 -2
  41. package/lib/node/constants/sdk-version.d.ts +1 -1
  42. package/lib/node/constants/sdk-version.js +1 -1
  43. package/package.json +1 -1
  44. package/src/blocks/columns/columns.svelte +1 -1
  45. package/src/components/block/components/block-styles.svelte +1 -1
  46. package/src/components/content/components/enable-editor.svelte +34 -35
  47. package/src/components/content/components/styles.svelte +1 -1
  48. package/src/components/content/content.svelte +1 -1
  49. package/src/components/content-variants/content-variants.svelte +9 -6
  50. package/src/components/content-variants/helpers.ts +1 -1
  51. package/src/components/inlined-script.svelte +3 -3
  52. package/src/components/inlined-styles.svelte +3 -3
  53. package/src/constants/sdk-version.ts +1 -1
@@ -129,7 +129,7 @@ let flexDir = stackColumnsAt === "never"
129
129
  {...{}}
130
130
  >
131
131
  {#if TARGET !== "reactNative"}
132
- <InlinedStyles styles={columnsStyles()} />
132
+ <InlinedStyles id="builderio-columns" styles={columnsStyles()} />
133
133
  {/if}
134
134
  {#each columns as column, index (index)}
135
135
  <DynamicRenderer
@@ -70,5 +70,5 @@ $: css = () => {
70
70
  </script>
71
71
 
72
72
  {#if TARGET !== "reactNative" && css() && canShowBlock()}
73
- <InlinedStyles styles={css()} />
73
+ <InlinedStyles id="builderio-block" styles={css()} />
74
74
  {/if}
@@ -122,41 +122,40 @@ function onClick(event) {
122
122
  clicked = true;
123
123
  }
124
124
  }
125
- function evalExpression(expression) {
126
- return expression.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
127
- code: group,
128
- context: context || {},
129
- localState: undefined,
130
- rootState: $builderContextSignal.rootState,
131
- rootSetState: $builderContextSignal.rootSetState,
132
- enableCache: true,
133
- })));
134
- }
135
- function handleRequest({ url, key }) {
136
- fetch(url)
137
- .then((response) => response.json())
138
- .then((json) => {
139
- const newState = {
140
- ...$builderContextSignal.rootState,
141
- [key]: json,
142
- };
143
- $builderContextSignal.rootSetState?.(newState);
144
- httpReqsData[key] = true;
145
- })
146
- .catch((err) => {
147
- console.error("error fetching dynamic data", url, err);
148
- });
149
- }
150
125
  function runHttpRequests() {
151
126
  const requests = $builderContextSignal.content?.data?.httpRequests ?? {};
152
127
  Object.entries(requests).forEach(([key, url]) => {
153
- if (url && (!httpReqsData[key] || isEditing())) {
154
- const evaluatedUrl = evalExpression(url);
155
- handleRequest({
156
- url: evaluatedUrl,
157
- key,
128
+ if (!url)
129
+ return;
130
+ // request already in progress
131
+ if (httpReqsPending[key])
132
+ return;
133
+ // request already completed, and not in edit mode
134
+ if (httpReqsData[key] && !isEditing())
135
+ return;
136
+ httpReqsPending[key] = true;
137
+ const evaluatedUrl = url.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
138
+ code: group,
139
+ context: context || {},
140
+ localState: undefined,
141
+ rootState: $builderContextSignal.rootState,
142
+ rootSetState: $builderContextSignal.rootSetState,
143
+ enableCache: true,
144
+ })));
145
+ fetch(evaluatedUrl)
146
+ .then((response) => response.json())
147
+ .then((json) => {
148
+ mergeNewRootState({
149
+ [key]: json,
158
150
  });
159
- }
151
+ httpReqsData[key] = true;
152
+ })
153
+ .catch((err) => {
154
+ console.error("error fetching dynamic data", url, err);
155
+ })
156
+ .finally(() => {
157
+ httpReqsPending[key] = false;
158
+ });
160
159
  });
161
160
  }
162
161
  function emitStateUpdate() {
@@ -228,6 +227,7 @@ function elementRef_onInitpreviewingbldr(event) {
228
227
  let elementRef;
229
228
  let ContentWrapper = contentWrapper || "div";
230
229
  let httpReqsData = {};
230
+ let httpReqsPending = {};
231
231
  let clicked = false;
232
232
  onMount(() => {
233
233
  if (isBrowser()) {
@@ -18,4 +18,4 @@ ${getDefaultStyles(isNestedRender)}
18
18
  `.trim();
19
19
  </script>
20
20
 
21
- <InlinedStyles styles={injectedStyles} />
21
+ <InlinedStyles id="builderio-content" styles={injectedStyles} />
@@ -98,7 +98,7 @@ setContext(ComponentsContext.key, {
98
98
  {...{}}
99
99
  >
100
100
  {#if isSsrAbTest}
101
- <InlinedScript {scriptStr} />
101
+ <InlinedScript id="builderio-variant-visibility" {scriptStr} />
102
102
  {/if}
103
103
  {#if TARGET !== "reactNative"}
104
104
  <ContentStyles
@@ -7,7 +7,7 @@ import { getDefaultCanTrack } from "../../helpers/canTrack.js";
7
7
  import ContentComponent from "../content/content.svelte";
8
8
  import InlinedScript from "../inlined-script.svelte";
9
9
  import InlinedStyles from "../inlined-styles.svelte";
10
- import { checkShouldRenderVariants, getScriptString, getUpdateCookieAndStylesScript, getVariants, } from "./helpers.js";
10
+ import { checkShouldRenderVariants, getInitVariantsFnsScriptString, getUpdateCookieAndStylesScript, getVariants, } from "./helpers.js";
11
11
  export let canTrack = undefined;
12
12
  export let content = undefined;
13
13
  export let isNestedRender = undefined;
@@ -60,15 +60,18 @@ onMount(() => {
60
60
  </script>
61
61
 
62
62
  {#if !isNestedRender && TARGET !== "reactNative"}
63
- <InlinedScript scriptStr={getScriptString()} />
63
+ <InlinedScript
64
+ id="builderio-init-variants-fns"
65
+ scriptStr={getInitVariantsFnsScriptString()}
66
+ />
64
67
  {/if}
65
68
 
66
69
  {#if shouldRenderVariants}
67
- <InlinedStyles
68
- id={`variants-styles-${content?.id}`}
69
- styles={hideVariantsStyleString()}
70
+ <InlinedStyles id="builderio-variants" styles={hideVariantsStyleString()} />
71
+ <InlinedScript
72
+ id="builderio-variants-visibility"
73
+ scriptStr={updateCookieAndStylesScriptStr()}
70
74
  />
71
- <InlinedScript scriptStr={updateCookieAndStylesScriptStr()} />
72
75
 
73
76
  {#each getVariants(content) as variant (variant.testVariationId)}
74
77
  <ContentComponent
@@ -32,7 +32,7 @@ type VariantData = {
32
32
  id: string;
33
33
  testRatio?: number;
34
34
  };
35
- export declare const getScriptString: () => string;
35
+ export declare const getInitVariantsFnsScriptString: () => string;
36
36
  export declare const getUpdateCookieAndStylesScript: (variants: VariantData[], contentId: string) => string;
37
37
  export declare const getUpdateVariantVisibilityScript: ({ contentId, variationId }: {
38
38
  variationId: string;
@@ -41,7 +41,7 @@ export const checkShouldRenderVariants = ({ canTrack, content }) => {
41
41
  };
42
42
  const getIsHydrationTarget = (target) => target === 'react' || target === 'reactNative';
43
43
  const isHydrationTarget = getIsHydrationTarget(TARGET);
44
- export const getScriptString = () => `
44
+ export const getInitVariantsFnsScriptString = () => `
45
45
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
46
46
  window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
47
47
  `;
@@ -1,7 +1,7 @@
1
1
  <script context="module"></script>
2
2
 
3
3
  <script>export let scriptStr;
4
- export let id = undefined;
4
+ export let id;
5
5
  </script>
6
6
 
7
- {@html `<script id=${id || ""}>${scriptStr}</script>`}
7
+ {@html `<script data-id=${id}>${scriptStr}</script>`}
@@ -1,12 +1,12 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  interface Props {
3
3
  scriptStr: string;
4
- id?: string;
4
+ id: string;
5
5
  }
6
6
  declare const __propDef: {
7
7
  props: {
8
8
  scriptStr: Props["scriptStr"];
9
- id?: Props["id"];
9
+ id: Props["id"];
10
10
  };
11
11
  events: {
12
12
  [evt: string]: CustomEvent<any>;
@@ -1,7 +1,7 @@
1
1
  <script context="module"></script>
2
2
 
3
3
  <script>export let styles;
4
- export let id = undefined;
4
+ export let id;
5
5
  </script>
6
6
 
7
- {@html `<${"style"} id=${id} >${styles}<${"/style"}>`}
7
+ {@html `<${"style"} data-id=${id} >${styles}<${"/style"}>`}
@@ -1,12 +1,12 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  interface Props {
3
3
  styles: string;
4
- id?: string;
4
+ id: string;
5
5
  }
6
6
  declare const __propDef: {
7
7
  props: {
8
8
  styles: Props["styles"];
9
- id?: Props["id"];
9
+ id: Props["id"];
10
10
  };
11
11
  events: {
12
12
  [evt: string]: CustomEvent<any>;
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.15";
1
+ export declare const SDK_VERSION = "1.0.17";
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.15";
1
+ export const SDK_VERSION = "1.0.17";
@@ -129,7 +129,7 @@ let flexDir = stackColumnsAt === "never"
129
129
  {...{}}
130
130
  >
131
131
  {#if TARGET !== "reactNative"}
132
- <InlinedStyles styles={columnsStyles()} />
132
+ <InlinedStyles id="builderio-columns" styles={columnsStyles()} />
133
133
  {/if}
134
134
  {#each columns as column, index (index)}
135
135
  <DynamicRenderer
@@ -70,5 +70,5 @@ $: css = () => {
70
70
  </script>
71
71
 
72
72
  {#if TARGET !== "reactNative" && css() && canShowBlock()}
73
- <InlinedStyles styles={css()} />
73
+ <InlinedStyles id="builderio-block" styles={css()} />
74
74
  {/if}
@@ -122,41 +122,40 @@ function onClick(event) {
122
122
  clicked = true;
123
123
  }
124
124
  }
125
- function evalExpression(expression) {
126
- return expression.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
127
- code: group,
128
- context: context || {},
129
- localState: undefined,
130
- rootState: $builderContextSignal.rootState,
131
- rootSetState: $builderContextSignal.rootSetState,
132
- enableCache: true,
133
- })));
134
- }
135
- function handleRequest({ url, key }) {
136
- fetch(url)
137
- .then((response) => response.json())
138
- .then((json) => {
139
- const newState = {
140
- ...$builderContextSignal.rootState,
141
- [key]: json,
142
- };
143
- $builderContextSignal.rootSetState?.(newState);
144
- httpReqsData[key] = true;
145
- })
146
- .catch((err) => {
147
- console.error("error fetching dynamic data", url, err);
148
- });
149
- }
150
125
  function runHttpRequests() {
151
126
  const requests = $builderContextSignal.content?.data?.httpRequests ?? {};
152
127
  Object.entries(requests).forEach(([key, url]) => {
153
- if (url && (!httpReqsData[key] || isEditing())) {
154
- const evaluatedUrl = evalExpression(url);
155
- handleRequest({
156
- url: evaluatedUrl,
157
- key,
128
+ if (!url)
129
+ return;
130
+ // request already in progress
131
+ if (httpReqsPending[key])
132
+ return;
133
+ // request already completed, and not in edit mode
134
+ if (httpReqsData[key] && !isEditing())
135
+ return;
136
+ httpReqsPending[key] = true;
137
+ const evaluatedUrl = url.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
138
+ code: group,
139
+ context: context || {},
140
+ localState: undefined,
141
+ rootState: $builderContextSignal.rootState,
142
+ rootSetState: $builderContextSignal.rootSetState,
143
+ enableCache: true,
144
+ })));
145
+ fetch(evaluatedUrl)
146
+ .then((response) => response.json())
147
+ .then((json) => {
148
+ mergeNewRootState({
149
+ [key]: json,
158
150
  });
159
- }
151
+ httpReqsData[key] = true;
152
+ })
153
+ .catch((err) => {
154
+ console.error("error fetching dynamic data", url, err);
155
+ })
156
+ .finally(() => {
157
+ httpReqsPending[key] = false;
158
+ });
160
159
  });
161
160
  }
162
161
  function emitStateUpdate() {
@@ -228,6 +227,7 @@ function elementRef_onInitpreviewingbldr(event) {
228
227
  let elementRef;
229
228
  let ContentWrapper = contentWrapper || "div";
230
229
  let httpReqsData = {};
230
+ let httpReqsPending = {};
231
231
  let clicked = false;
232
232
  onMount(() => {
233
233
  if (isBrowser()) {
@@ -18,4 +18,4 @@ ${getDefaultStyles(isNestedRender)}
18
18
  `.trim();
19
19
  </script>
20
20
 
21
- <InlinedStyles styles={injectedStyles} />
21
+ <InlinedStyles id="builderio-content" styles={injectedStyles} />
@@ -98,7 +98,7 @@ setContext(ComponentsContext.key, {
98
98
  {...{}}
99
99
  >
100
100
  {#if isSsrAbTest}
101
- <InlinedScript {scriptStr} />
101
+ <InlinedScript id="builderio-variant-visibility" {scriptStr} />
102
102
  {/if}
103
103
  {#if TARGET !== "reactNative"}
104
104
  <ContentStyles
@@ -7,7 +7,7 @@ import { getDefaultCanTrack } from "../../helpers/canTrack.js";
7
7
  import ContentComponent from "../content/content.svelte";
8
8
  import InlinedScript from "../inlined-script.svelte";
9
9
  import InlinedStyles from "../inlined-styles.svelte";
10
- import { checkShouldRenderVariants, getScriptString, getUpdateCookieAndStylesScript, getVariants, } from "./helpers.js";
10
+ import { checkShouldRenderVariants, getInitVariantsFnsScriptString, getUpdateCookieAndStylesScript, getVariants, } from "./helpers.js";
11
11
  export let canTrack = undefined;
12
12
  export let content = undefined;
13
13
  export let isNestedRender = undefined;
@@ -60,15 +60,18 @@ onMount(() => {
60
60
  </script>
61
61
 
62
62
  {#if !isNestedRender && TARGET !== "reactNative"}
63
- <InlinedScript scriptStr={getScriptString()} />
63
+ <InlinedScript
64
+ id="builderio-init-variants-fns"
65
+ scriptStr={getInitVariantsFnsScriptString()}
66
+ />
64
67
  {/if}
65
68
 
66
69
  {#if shouldRenderVariants}
67
- <InlinedStyles
68
- id={`variants-styles-${content?.id}`}
69
- styles={hideVariantsStyleString()}
70
+ <InlinedStyles id="builderio-variants" styles={hideVariantsStyleString()} />
71
+ <InlinedScript
72
+ id="builderio-variants-visibility"
73
+ scriptStr={updateCookieAndStylesScriptStr()}
70
74
  />
71
- <InlinedScript scriptStr={updateCookieAndStylesScriptStr()} />
72
75
 
73
76
  {#each getVariants(content) as variant (variant.testVariationId)}
74
77
  <ContentComponent
@@ -32,7 +32,7 @@ type VariantData = {
32
32
  id: string;
33
33
  testRatio?: number;
34
34
  };
35
- export declare const getScriptString: () => string;
35
+ export declare const getInitVariantsFnsScriptString: () => string;
36
36
  export declare const getUpdateCookieAndStylesScript: (variants: VariantData[], contentId: string) => string;
37
37
  export declare const getUpdateVariantVisibilityScript: ({ contentId, variationId }: {
38
38
  variationId: string;
@@ -41,7 +41,7 @@ export const checkShouldRenderVariants = ({ canTrack, content }) => {
41
41
  };
42
42
  const getIsHydrationTarget = (target) => target === 'react' || target === 'reactNative';
43
43
  const isHydrationTarget = getIsHydrationTarget(TARGET);
44
- export const getScriptString = () => `
44
+ export const getInitVariantsFnsScriptString = () => `
45
45
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
46
46
  window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
47
47
  `;
@@ -1,7 +1,7 @@
1
1
  <script context="module"></script>
2
2
 
3
3
  <script>export let scriptStr;
4
- export let id = undefined;
4
+ export let id;
5
5
  </script>
6
6
 
7
- {@html `<script id=${id || ""}>${scriptStr}</script>`}
7
+ {@html `<script data-id=${id}>${scriptStr}</script>`}
@@ -1,12 +1,12 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  interface Props {
3
3
  scriptStr: string;
4
- id?: string;
4
+ id: string;
5
5
  }
6
6
  declare const __propDef: {
7
7
  props: {
8
8
  scriptStr: Props["scriptStr"];
9
- id?: Props["id"];
9
+ id: Props["id"];
10
10
  };
11
11
  events: {
12
12
  [evt: string]: CustomEvent<any>;
@@ -1,7 +1,7 @@
1
1
  <script context="module"></script>
2
2
 
3
3
  <script>export let styles;
4
- export let id = undefined;
4
+ export let id;
5
5
  </script>
6
6
 
7
- {@html `<${"style"} id=${id} >${styles}<${"/style"}>`}
7
+ {@html `<${"style"} data-id=${id} >${styles}<${"/style"}>`}
@@ -1,12 +1,12 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  interface Props {
3
3
  styles: string;
4
- id?: string;
4
+ id: string;
5
5
  }
6
6
  declare const __propDef: {
7
7
  props: {
8
8
  styles: Props["styles"];
9
- id?: Props["id"];
9
+ id: Props["id"];
10
10
  };
11
11
  events: {
12
12
  [evt: string]: CustomEvent<any>;
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.15";
1
+ export declare const SDK_VERSION = "1.0.17";
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.15";
1
+ export const SDK_VERSION = "1.0.17";
@@ -129,7 +129,7 @@ let flexDir = stackColumnsAt === "never"
129
129
  {...{}}
130
130
  >
131
131
  {#if TARGET !== "reactNative"}
132
- <InlinedStyles styles={columnsStyles()} />
132
+ <InlinedStyles id="builderio-columns" styles={columnsStyles()} />
133
133
  {/if}
134
134
  {#each columns as column, index (index)}
135
135
  <DynamicRenderer
@@ -70,5 +70,5 @@ $: css = () => {
70
70
  </script>
71
71
 
72
72
  {#if TARGET !== "reactNative" && css() && canShowBlock()}
73
- <InlinedStyles styles={css()} />
73
+ <InlinedStyles id="builderio-block" styles={css()} />
74
74
  {/if}
@@ -122,41 +122,40 @@ function onClick(event) {
122
122
  clicked = true;
123
123
  }
124
124
  }
125
- function evalExpression(expression) {
126
- return expression.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
127
- code: group,
128
- context: context || {},
129
- localState: undefined,
130
- rootState: $builderContextSignal.rootState,
131
- rootSetState: $builderContextSignal.rootSetState,
132
- enableCache: true,
133
- })));
134
- }
135
- function handleRequest({ url, key }) {
136
- fetch(url)
137
- .then((response) => response.json())
138
- .then((json) => {
139
- const newState = {
140
- ...$builderContextSignal.rootState,
141
- [key]: json,
142
- };
143
- $builderContextSignal.rootSetState?.(newState);
144
- httpReqsData[key] = true;
145
- })
146
- .catch((err) => {
147
- console.error("error fetching dynamic data", url, err);
148
- });
149
- }
150
125
  function runHttpRequests() {
151
126
  const requests = $builderContextSignal.content?.data?.httpRequests ?? {};
152
127
  Object.entries(requests).forEach(([key, url]) => {
153
- if (url && (!httpReqsData[key] || isEditing())) {
154
- const evaluatedUrl = evalExpression(url);
155
- handleRequest({
156
- url: evaluatedUrl,
157
- key,
128
+ if (!url)
129
+ return;
130
+ // request already in progress
131
+ if (httpReqsPending[key])
132
+ return;
133
+ // request already completed, and not in edit mode
134
+ if (httpReqsData[key] && !isEditing())
135
+ return;
136
+ httpReqsPending[key] = true;
137
+ const evaluatedUrl = url.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
138
+ code: group,
139
+ context: context || {},
140
+ localState: undefined,
141
+ rootState: $builderContextSignal.rootState,
142
+ rootSetState: $builderContextSignal.rootSetState,
143
+ enableCache: true,
144
+ })));
145
+ fetch(evaluatedUrl)
146
+ .then((response) => response.json())
147
+ .then((json) => {
148
+ mergeNewRootState({
149
+ [key]: json,
158
150
  });
159
- }
151
+ httpReqsData[key] = true;
152
+ })
153
+ .catch((err) => {
154
+ console.error("error fetching dynamic data", url, err);
155
+ })
156
+ .finally(() => {
157
+ httpReqsPending[key] = false;
158
+ });
160
159
  });
161
160
  }
162
161
  function emitStateUpdate() {
@@ -228,6 +227,7 @@ function elementRef_onInitpreviewingbldr(event) {
228
227
  let elementRef;
229
228
  let ContentWrapper = contentWrapper || "div";
230
229
  let httpReqsData = {};
230
+ let httpReqsPending = {};
231
231
  let clicked = false;
232
232
  onMount(() => {
233
233
  if (isBrowser()) {
@@ -18,4 +18,4 @@ ${getDefaultStyles(isNestedRender)}
18
18
  `.trim();
19
19
  </script>
20
20
 
21
- <InlinedStyles styles={injectedStyles} />
21
+ <InlinedStyles id="builderio-content" styles={injectedStyles} />
@@ -98,7 +98,7 @@ setContext(ComponentsContext.key, {
98
98
  {...{}}
99
99
  >
100
100
  {#if isSsrAbTest}
101
- <InlinedScript {scriptStr} />
101
+ <InlinedScript id="builderio-variant-visibility" {scriptStr} />
102
102
  {/if}
103
103
  {#if TARGET !== "reactNative"}
104
104
  <ContentStyles
@@ -7,7 +7,7 @@ import { getDefaultCanTrack } from "../../helpers/canTrack.js";
7
7
  import ContentComponent from "../content/content.svelte";
8
8
  import InlinedScript from "../inlined-script.svelte";
9
9
  import InlinedStyles from "../inlined-styles.svelte";
10
- import { checkShouldRenderVariants, getScriptString, getUpdateCookieAndStylesScript, getVariants, } from "./helpers.js";
10
+ import { checkShouldRenderVariants, getInitVariantsFnsScriptString, getUpdateCookieAndStylesScript, getVariants, } from "./helpers.js";
11
11
  export let canTrack = undefined;
12
12
  export let content = undefined;
13
13
  export let isNestedRender = undefined;
@@ -60,15 +60,18 @@ onMount(() => {
60
60
  </script>
61
61
 
62
62
  {#if !isNestedRender && TARGET !== "reactNative"}
63
- <InlinedScript scriptStr={getScriptString()} />
63
+ <InlinedScript
64
+ id="builderio-init-variants-fns"
65
+ scriptStr={getInitVariantsFnsScriptString()}
66
+ />
64
67
  {/if}
65
68
 
66
69
  {#if shouldRenderVariants}
67
- <InlinedStyles
68
- id={`variants-styles-${content?.id}`}
69
- styles={hideVariantsStyleString()}
70
+ <InlinedStyles id="builderio-variants" styles={hideVariantsStyleString()} />
71
+ <InlinedScript
72
+ id="builderio-variants-visibility"
73
+ scriptStr={updateCookieAndStylesScriptStr()}
70
74
  />
71
- <InlinedScript scriptStr={updateCookieAndStylesScriptStr()} />
72
75
 
73
76
  {#each getVariants(content) as variant (variant.testVariationId)}
74
77
  <ContentComponent
@@ -32,7 +32,7 @@ type VariantData = {
32
32
  id: string;
33
33
  testRatio?: number;
34
34
  };
35
- export declare const getScriptString: () => string;
35
+ export declare const getInitVariantsFnsScriptString: () => string;
36
36
  export declare const getUpdateCookieAndStylesScript: (variants: VariantData[], contentId: string) => string;
37
37
  export declare const getUpdateVariantVisibilityScript: ({ contentId, variationId }: {
38
38
  variationId: string;
@@ -41,7 +41,7 @@ export const checkShouldRenderVariants = ({ canTrack, content }) => {
41
41
  };
42
42
  const getIsHydrationTarget = (target) => target === 'react' || target === 'reactNative';
43
43
  const isHydrationTarget = getIsHydrationTarget(TARGET);
44
- export const getScriptString = () => `
44
+ export const getInitVariantsFnsScriptString = () => `
45
45
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
46
46
  window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
47
47
  `;
@@ -1,7 +1,7 @@
1
1
  <script context="module"></script>
2
2
 
3
3
  <script>export let scriptStr;
4
- export let id = undefined;
4
+ export let id;
5
5
  </script>
6
6
 
7
- {@html `<script id=${id || ""}>${scriptStr}</script>`}
7
+ {@html `<script data-id=${id}>${scriptStr}</script>`}
@@ -1,12 +1,12 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  interface Props {
3
3
  scriptStr: string;
4
- id?: string;
4
+ id: string;
5
5
  }
6
6
  declare const __propDef: {
7
7
  props: {
8
8
  scriptStr: Props["scriptStr"];
9
- id?: Props["id"];
9
+ id: Props["id"];
10
10
  };
11
11
  events: {
12
12
  [evt: string]: CustomEvent<any>;
@@ -1,7 +1,7 @@
1
1
  <script context="module"></script>
2
2
 
3
3
  <script>export let styles;
4
- export let id = undefined;
4
+ export let id;
5
5
  </script>
6
6
 
7
- {@html `<${"style"} id=${id} >${styles}<${"/style"}>`}
7
+ {@html `<${"style"} data-id=${id} >${styles}<${"/style"}>`}
@@ -1,12 +1,12 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  interface Props {
3
3
  styles: string;
4
- id?: string;
4
+ id: string;
5
5
  }
6
6
  declare const __propDef: {
7
7
  props: {
8
8
  styles: Props["styles"];
9
- id?: Props["id"];
9
+ id: Props["id"];
10
10
  };
11
11
  events: {
12
12
  [evt: string]: CustomEvent<any>;
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.15";
1
+ export declare const SDK_VERSION = "1.0.17";
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.15";
1
+ export const SDK_VERSION = "1.0.17";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-svelte",
3
3
  "description": "Builder.io SDK for Svelte",
4
- "version": "1.0.15",
4
+ "version": "1.0.17",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "lib",
@@ -155,7 +155,7 @@
155
155
  {...{}}
156
156
  >
157
157
  {#if TARGET !== "reactNative"}
158
- <InlinedStyles styles={columnsStyles()} />
158
+ <InlinedStyles id="builderio-columns" styles={columnsStyles()} />
159
159
  {/if}
160
160
  {#each columns as column, index (index)}
161
161
  <DynamicRenderer
@@ -91,5 +91,5 @@
91
91
  </script>
92
92
 
93
93
  {#if TARGET !== "reactNative" && css() && canShowBlock()}
94
- <InlinedStyles styles={css()} />
94
+ <InlinedStyles id="builderio-block" styles={css()} />
95
95
  {/if}
@@ -154,47 +154,45 @@
154
154
  clicked = true;
155
155
  }
156
156
  }
157
- function evalExpression(expression: string) {
158
- return expression.replace(/{{([^}]+)}}/g, (_match, group) =>
159
- String(
160
- evaluate({
161
- code: group,
162
- context: context || {},
163
- localState: undefined,
164
- rootState: $builderContextSignal.rootState,
165
- rootSetState: $builderContextSignal.rootSetState,
166
- enableCache: true,
167
- })
168
- )
169
- );
170
- }
171
- function handleRequest({ url, key }: { key: string; url: string }) {
172
- fetch(url)
173
- .then((response) => response.json())
174
- .then((json) => {
175
- const newState = {
176
- ...$builderContextSignal.rootState,
177
- [key]: json,
178
- };
179
- $builderContextSignal.rootSetState?.(newState);
180
- httpReqsData[key] = true;
181
- })
182
- .catch((err) => {
183
- console.error("error fetching dynamic data", url, err);
184
- });
185
- }
186
157
  function runHttpRequests() {
187
158
  const requests: {
188
159
  [key: string]: string;
189
160
  } = $builderContextSignal.content?.data?.httpRequests ?? {};
190
161
  Object.entries(requests).forEach(([key, url]) => {
191
- if (url && (!httpReqsData[key] || isEditing())) {
192
- const evaluatedUrl = evalExpression(url);
193
- handleRequest({
194
- url: evaluatedUrl,
195
- key,
162
+ if (!url) return;
163
+
164
+ // request already in progress
165
+ if (httpReqsPending[key]) return;
166
+
167
+ // request already completed, and not in edit mode
168
+ if (httpReqsData[key] && !isEditing()) return;
169
+ httpReqsPending[key] = true;
170
+ const evaluatedUrl = url.replace(/{{([^}]+)}}/g, (_match, group) =>
171
+ String(
172
+ evaluate({
173
+ code: group,
174
+ context: context || {},
175
+ localState: undefined,
176
+ rootState: $builderContextSignal.rootState,
177
+ rootSetState: $builderContextSignal.rootSetState,
178
+ enableCache: true,
179
+ })
180
+ )
181
+ );
182
+ fetch(evaluatedUrl)
183
+ .then((response) => response.json())
184
+ .then((json) => {
185
+ mergeNewRootState({
186
+ [key]: json,
187
+ });
188
+ httpReqsData[key] = true;
189
+ })
190
+ .catch((err) => {
191
+ console.error("error fetching dynamic data", url, err);
192
+ })
193
+ .finally(() => {
194
+ httpReqsPending[key] = false;
196
195
  });
197
- }
198
196
  });
199
197
  }
200
198
  function emitStateUpdate() {
@@ -284,6 +282,7 @@
284
282
 
285
283
  let ContentWrapper = contentWrapper || "div";
286
284
  let httpReqsData = {};
285
+ let httpReqsPending = {};
287
286
  let clicked = false;
288
287
 
289
288
  onMount(() => {
@@ -29,4 +29,4 @@ ${getDefaultStyles(isNestedRender)}
29
29
  `.trim();
30
30
  </script>
31
31
 
32
- <InlinedStyles styles={injectedStyles} />
32
+ <InlinedStyles id="builderio-content" styles={injectedStyles} />
@@ -122,7 +122,7 @@
122
122
  {...{}}
123
123
  >
124
124
  {#if isSsrAbTest}
125
- <InlinedScript {scriptStr} />
125
+ <InlinedScript id="builderio-variant-visibility" {scriptStr} />
126
126
  {/if}
127
127
  {#if TARGET !== "reactNative"}
128
128
  <ContentStyles
@@ -19,7 +19,7 @@
19
19
  import type { ContentVariantsPrps } from "./content-variants.types.js";
20
20
  import {
21
21
  checkShouldRenderVariants,
22
- getScriptString,
22
+ getInitVariantsFnsScriptString,
23
23
  getUpdateCookieAndStylesScript,
24
24
  getVariants,
25
25
  } from "./helpers.js";
@@ -87,15 +87,18 @@
87
87
  </script>
88
88
 
89
89
  {#if !isNestedRender && TARGET !== "reactNative"}
90
- <InlinedScript scriptStr={getScriptString()} />
90
+ <InlinedScript
91
+ id="builderio-init-variants-fns"
92
+ scriptStr={getInitVariantsFnsScriptString()}
93
+ />
91
94
  {/if}
92
95
 
93
96
  {#if shouldRenderVariants}
94
- <InlinedStyles
95
- id={`variants-styles-${content?.id}`}
96
- styles={hideVariantsStyleString()}
97
+ <InlinedStyles id="builderio-variants" styles={hideVariantsStyleString()} />
98
+ <InlinedScript
99
+ id="builderio-variants-visibility"
100
+ scriptStr={updateCookieAndStylesScriptStr()}
97
101
  />
98
- <InlinedScript scriptStr={updateCookieAndStylesScriptStr()} />
99
102
 
100
103
  {#each getVariants(content) as variant (variant.testVariationId)}
101
104
  <ContentComponent
@@ -52,7 +52,7 @@ type VariantData = {
52
52
  };
53
53
  const getIsHydrationTarget = (target: Target) => target === 'react' || target === 'reactNative';
54
54
  const isHydrationTarget = getIsHydrationTarget(TARGET);
55
- export const getScriptString = () => `
55
+ export const getInitVariantsFnsScriptString = () => `
56
56
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
57
57
  window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
58
58
  `;
@@ -1,13 +1,13 @@
1
1
  <script context="module" lang="ts">
2
2
  interface Props {
3
3
  scriptStr: string;
4
- id?: string;
4
+ id: string;
5
5
  }
6
6
  </script>
7
7
 
8
8
  <script lang="ts">
9
9
  export let scriptStr: Props["scriptStr"];
10
- export let id: Props["id"] = undefined;
10
+ export let id: Props["id"];
11
11
  </script>
12
12
 
13
- {@html `<script id=${id || ""}>${scriptStr}</script>`}
13
+ {@html `<script data-id=${id}>${scriptStr}</script>`}
@@ -1,13 +1,13 @@
1
1
  <script context="module" lang="ts">
2
2
  interface Props {
3
3
  styles: string;
4
- id?: string;
4
+ id: string;
5
5
  }
6
6
  </script>
7
7
 
8
8
  <script lang="ts">
9
9
  export let styles: Props["styles"];
10
- export let id: Props["id"] = undefined;
10
+ export let id: Props["id"];
11
11
  </script>
12
12
 
13
- {@html `<${"style"} id=${id} >${styles}<${"/style"}>`}
13
+ {@html `<${"style"} data-id=${id} >${styles}<${"/style"}>`}
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.15"
1
+ export const SDK_VERSION = "1.0.17"