@builder.io/sdk-svelte 4.0.2 → 4.0.4

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 (46) hide show
  1. package/lib/browser/blocks/custom-code/custom-code.svelte +22 -8
  2. package/lib/browser/blocks/embed/embed.svelte +3 -2
  3. package/lib/browser/blocks/image/component-info.js +4 -0
  4. package/lib/browser/blocks/image/image.svelte +2 -0
  5. package/lib/browser/blocks/image/image.svelte.d.ts +1 -0
  6. package/lib/browser/blocks/image/image.types.d.ts +1 -0
  7. package/lib/browser/components/blocks/blocks-wrapper.svelte +3 -0
  8. package/lib/browser/components/content-variants/helpers.js +2 -1
  9. package/lib/browser/components/content-variants/inlined-fns.d.ts +1 -1
  10. package/lib/browser/components/content-variants/inlined-fns.js +1 -1
  11. package/lib/browser/constants/sdk-version.d.ts +1 -1
  12. package/lib/browser/constants/sdk-version.js +1 -1
  13. package/lib/edge/blocks/custom-code/custom-code.svelte +22 -8
  14. package/lib/edge/blocks/embed/embed.svelte +3 -2
  15. package/lib/edge/blocks/image/component-info.js +4 -0
  16. package/lib/edge/blocks/image/image.svelte +2 -0
  17. package/lib/edge/blocks/image/image.svelte.d.ts +1 -0
  18. package/lib/edge/blocks/image/image.types.d.ts +1 -0
  19. package/lib/edge/components/blocks/blocks-wrapper.svelte +3 -0
  20. package/lib/edge/components/content-variants/helpers.js +2 -1
  21. package/lib/edge/components/content-variants/inlined-fns.d.ts +1 -1
  22. package/lib/edge/components/content-variants/inlined-fns.js +1 -1
  23. package/lib/edge/constants/sdk-version.d.ts +1 -1
  24. package/lib/edge/constants/sdk-version.js +1 -1
  25. package/lib/node/blocks/custom-code/custom-code.svelte +22 -8
  26. package/lib/node/blocks/embed/embed.svelte +3 -2
  27. package/lib/node/blocks/image/component-info.js +4 -0
  28. package/lib/node/blocks/image/image.svelte +2 -0
  29. package/lib/node/blocks/image/image.svelte.d.ts +1 -0
  30. package/lib/node/blocks/image/image.types.d.ts +1 -0
  31. package/lib/node/components/blocks/blocks-wrapper.svelte +3 -0
  32. package/lib/node/components/content-variants/helpers.js +2 -1
  33. package/lib/node/components/content-variants/inlined-fns.d.ts +1 -1
  34. package/lib/node/components/content-variants/inlined-fns.js +1 -1
  35. package/lib/node/constants/sdk-version.d.ts +1 -1
  36. package/lib/node/constants/sdk-version.js +1 -1
  37. package/package.json +1 -1
  38. package/src/blocks/custom-code/custom-code.svelte +33 -10
  39. package/src/blocks/embed/embed.svelte +2 -1
  40. package/src/blocks/image/component-info.ts +4 -0
  41. package/src/blocks/image/image.svelte +2 -0
  42. package/src/blocks/image/image.types.ts +1 -0
  43. package/src/components/blocks/blocks-wrapper.svelte +6 -0
  44. package/src/components/content-variants/helpers.ts +2 -1
  45. package/src/components/content-variants/inlined-fns.ts +1 -1
  46. package/src/constants/sdk-version.ts +1 -1
@@ -1,14 +1,14 @@
1
1
  <script context="module"></script>
2
2
 
3
3
  <script>import { onMount } from "svelte";
4
- export let replaceNodes = undefined;
4
+ import { isEditing } from "../../functions/is-editing";
5
+ import { logger } from "../../helpers/logger";
5
6
  export let code;
6
- let elementRef;
7
- let scriptsInserted = [];
8
- let scriptsRun = [];
9
- onMount(() => {
10
- // TODO: Move this function to standalone one in '@builder.io/utils'
11
- if (!elementRef?.getElementsByTagName || typeof window === "undefined") {
7
+ export let replaceNodes = undefined;
8
+ function runScripts() {
9
+ if (!elementRef ||
10
+ !elementRef?.getElementsByTagName ||
11
+ typeof window === "undefined") {
12
12
  return;
13
13
  }
14
14
  const scripts = elementRef.getElementsByTagName("script");
@@ -38,11 +38,25 @@ onMount(() => {
38
38
  new Function(script.innerText)();
39
39
  }
40
40
  catch (error) {
41
- console.warn("`CustomCode`: Error running script:", error);
41
+ logger.warn("[BUILDER.IO] `CustomCode`: Error running script:", error);
42
42
  }
43
43
  }
44
44
  }
45
+ }
46
+ let elementRef;
47
+ let scriptsInserted = [];
48
+ let scriptsRun = [];
49
+ onMount(() => {
50
+ runScripts();
45
51
  });
52
+ function onUpdateFn_0(..._args) {
53
+ if (isEditing()) {
54
+ setTimeout(() => {
55
+ runScripts();
56
+ }, 0);
57
+ }
58
+ }
59
+ $: onUpdateFn_0(...[code]);
46
60
  </script>
47
61
 
48
62
  <div
@@ -1,6 +1,7 @@
1
1
  <script context="module"></script>
2
2
 
3
- <script>import { isJsScript } from "./helpers";
3
+ <script>import { logger } from "../../helpers/logger";
4
+ import { isJsScript } from "./helpers";
4
5
  export let content;
5
6
  function findAndRunScripts() {
6
7
  if (!elem || !elem.getElementsByTagName)
@@ -21,7 +22,7 @@ function findAndRunScripts() {
21
22
  new Function(script.innerText)();
22
23
  }
23
24
  catch (error) {
24
- console.warn("`Embed`: Error running script:", error);
25
+ logger.warn("[BUILDER.IO] `Embed`: Error running script:", error);
25
26
  }
26
27
  }
27
28
  }
@@ -87,6 +87,10 @@ export const componentInfo = {
87
87
  name: 'altText',
88
88
  type: 'string',
89
89
  helperText: 'Text to display when the user has images off'
90
+ }, {
91
+ name: 'title',
92
+ type: 'string',
93
+ helperText: 'Text to display when hovering over the asset'
90
94
  }, {
91
95
  name: 'height',
92
96
  type: 'number',
@@ -6,6 +6,7 @@ export let noWebp = undefined;
6
6
  export let aspectRatio = undefined;
7
7
  export let highPriority = undefined;
8
8
  export let altText = undefined;
9
+ export let title = undefined;
9
10
  export let backgroundPosition = undefined;
10
11
  export let backgroundSize = undefined;
11
12
  export let className = undefined;
@@ -79,6 +80,7 @@ $: aspectRatioCss = () => {
79
80
  loading={highPriority ? "eager" : "lazy"}
80
81
  fetchpriority={highPriority ? "high" : "auto"}
81
82
  alt={altText}
83
+ {title}
82
84
  role={altText ? undefined : "presentation"}
83
85
  class={"builder-image" + (className ? " " + className : "") + " img"}
84
86
  src={image}
@@ -9,6 +9,7 @@ declare const __propDef: {
9
9
  aspectRatio?: ImageProps["aspectRatio"];
10
10
  highPriority?: ImageProps["highPriority"];
11
11
  altText?: ImageProps["altText"];
12
+ title?: ImageProps["title"];
12
13
  backgroundPosition?: ImageProps["backgroundPosition"];
13
14
  backgroundSize?: ImageProps["backgroundSize"];
14
15
  className?: ImageProps["className"];
@@ -9,6 +9,7 @@ export interface ImageProps {
9
9
  height?: number;
10
10
  width?: number;
11
11
  altText?: string;
12
+ title?: string;
12
13
  backgroundSize?: 'cover' | 'contain';
13
14
  backgroundPosition?: string;
14
15
  srcset?: string;
@@ -59,7 +59,10 @@ $: dataPath = () => {
59
59
  : `${pathPrefix}${path || ""}`;
60
60
  };
61
61
  let blocksWrapperRef;
62
+ let shouldUpdate = false;
62
63
  onMount(() => { });
64
+ function onUpdateFn_0(..._args) { }
65
+ $: onUpdateFn_0(...[blocks]);
63
66
  </script>
64
67
 
65
68
  <svelte:element
@@ -41,6 +41,7 @@ export const checkShouldRenderVariants = ({ canTrack, content }) => {
41
41
  return true;
42
42
  };
43
43
  const getIsHydrationTarget = (target) => target === 'react' || target === 'reactNative';
44
+ const isAngularSDK = TARGET === 'angular';
44
45
  const isHydrationTarget = getIsHydrationTarget(TARGET);
45
46
  export const getInitVariantsFnsScriptString = () => `
46
47
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
@@ -48,7 +49,7 @@ export const getInitVariantsFnsScriptString = () => `
48
49
  `;
49
50
  export const getUpdateCookieAndStylesScript = (variants, contentId) => `
50
51
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME}(
51
- "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}
52
+ "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}, ${isAngularSDK}
52
53
  )`;
53
54
  export const getUpdateVariantVisibilityScript = ({ contentId, variationId }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
54
55
  "${variationId}", "${contentId}", ${isHydrationTarget}
@@ -10,5 +10,5 @@
10
10
  * For more information on how this works,
11
11
  * see our [SSR A/B Test Docs](https://github.com/BuilderIO/builder/tree/main/packages/sdks/docs/SSR_AB_TEST.md)
12
12
  */
13
- export declare const UPDATE_COOKIES_AND_STYLES_SCRIPT = "function updateCookiesAndStyles(contentId, variants, isHydrationTarget) {\n function getAndSetVariantId() {\n function setCookie(name, value, days) {\n let expires = '';\n if (days) {\n const date = new Date();\n date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);\n expires = '; expires=' + date.toUTCString();\n }\n document.cookie = name + '=' + (value || '') + expires + '; path=/' + '; Secure; SameSite=None';\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${contentId}`;\n const variantInCookie = getCookie(cookieName);\n const availableIDs = variants.map(vr => vr.id).concat(contentId);\n if (variantInCookie && availableIDs.includes(variantInCookie)) {\n return variantInCookie;\n }\n let n = 0;\n const random = Math.random();\n for (let i = 0; i < variants.length; i++) {\n const variant = variants[i];\n const testRatio = variant.testRatio;\n n += testRatio;\n if (random < n) {\n setCookie(cookieName, variant.id);\n return variant.id;\n }\n }\n setCookie(cookieName, contentId);\n return contentId;\n }\n const winningVariantId = getAndSetVariantId();\n const styleEl = document.currentScript?.previousElementSibling;\n if (isHydrationTarget) {\n styleEl.remove();\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n } else {\n const newStyleStr = variants.concat({\n id: contentId\n }).filter(variant => variant.id !== winningVariantId).map(value => {\n return `.variant-${value.id} { display: none; }\n `;\n }).join('');\n styleEl.innerHTML = newStyleStr;\n }\n}";
13
+ export declare const UPDATE_COOKIES_AND_STYLES_SCRIPT = "function updateCookiesAndStyles(contentId, variants, isHydrationTarget, isAngularSDK) {\n function getAndSetVariantId() {\n function setCookie(name, value, days) {\n let expires = '';\n if (days) {\n const date = new Date();\n date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);\n expires = '; expires=' + date.toUTCString();\n }\n document.cookie = name + '=' + (value || '') + expires + '; path=/' + '; Secure; SameSite=None';\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${contentId}`;\n const variantInCookie = getCookie(cookieName);\n const availableIDs = variants.map(vr => vr.id).concat(contentId);\n if (variantInCookie && availableIDs.includes(variantInCookie)) {\n return variantInCookie;\n }\n let n = 0;\n const random = Math.random();\n for (let i = 0; i < variants.length; i++) {\n const variant = variants[i];\n const testRatio = variant.testRatio;\n n += testRatio;\n if (random < n) {\n setCookie(cookieName, variant.id);\n return variant.id;\n }\n }\n setCookie(cookieName, contentId);\n return contentId;\n }\n const winningVariantId = getAndSetVariantId();\n let styleEl = document.currentScript?.previousElementSibling;\n if (isAngularSDK) {\n styleEl = document.currentScript?.parentElement?.previousElementSibling?.querySelector('style');\n }\n if (isHydrationTarget) {\n styleEl.remove();\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n } else {\n const newStyleStr = variants.concat({\n id: contentId\n }).filter(variant => variant.id !== winningVariantId).map(value => {\n return `.variant-${value.id} { display: none; }\n `;\n }).join('');\n styleEl.innerHTML = newStyleStr;\n }\n}";
14
14
  export declare const UPDATE_VARIANT_VISIBILITY_SCRIPT = "function updateVariantVisibility(variantContentId, defaultContentId, isHydrationTarget) {\n if (!navigator.cookieEnabled) {\n return;\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${defaultContentId}`;\n const winningVariant = getCookie(cookieName);\n const parentDiv = document.currentScript?.parentElement;\n const isDefaultContent = variantContentId === defaultContentId;\n const isWinningVariant = winningVariant === variantContentId;\n if (isWinningVariant && !isDefaultContent) {\n parentDiv?.removeAttribute('hidden');\n parentDiv?.removeAttribute('aria-hidden');\n } else if (!isWinningVariant && isDefaultContent) {\n parentDiv?.setAttribute('hidden', 'true');\n parentDiv?.setAttribute('aria-hidden', 'true');\n }\n if (isHydrationTarget) {\n if (!isWinningVariant) {\n parentDiv?.remove();\n }\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n }\n return;\n}";
@@ -10,5 +10,5 @@
10
10
  * For more information on how this works,
11
11
  * see our [SSR A/B Test Docs](https://github.com/BuilderIO/builder/tree/main/packages/sdks/docs/SSR_AB_TEST.md)
12
12
  */
13
- export const UPDATE_COOKIES_AND_STYLES_SCRIPT = "function updateCookiesAndStyles(contentId, variants, isHydrationTarget) {\n function getAndSetVariantId() {\n function setCookie(name, value, days) {\n let expires = '';\n if (days) {\n const date = new Date();\n date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);\n expires = '; expires=' + date.toUTCString();\n }\n document.cookie = name + '=' + (value || '') + expires + '; path=/' + '; Secure; SameSite=None';\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${contentId}`;\n const variantInCookie = getCookie(cookieName);\n const availableIDs = variants.map(vr => vr.id).concat(contentId);\n if (variantInCookie && availableIDs.includes(variantInCookie)) {\n return variantInCookie;\n }\n let n = 0;\n const random = Math.random();\n for (let i = 0; i < variants.length; i++) {\n const variant = variants[i];\n const testRatio = variant.testRatio;\n n += testRatio;\n if (random < n) {\n setCookie(cookieName, variant.id);\n return variant.id;\n }\n }\n setCookie(cookieName, contentId);\n return contentId;\n }\n const winningVariantId = getAndSetVariantId();\n const styleEl = document.currentScript?.previousElementSibling;\n if (isHydrationTarget) {\n styleEl.remove();\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n } else {\n const newStyleStr = variants.concat({\n id: contentId\n }).filter(variant => variant.id !== winningVariantId).map(value => {\n return `.variant-${value.id} { display: none; }\n `;\n }).join('');\n styleEl.innerHTML = newStyleStr;\n }\n}";
13
+ export const UPDATE_COOKIES_AND_STYLES_SCRIPT = "function updateCookiesAndStyles(contentId, variants, isHydrationTarget, isAngularSDK) {\n function getAndSetVariantId() {\n function setCookie(name, value, days) {\n let expires = '';\n if (days) {\n const date = new Date();\n date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);\n expires = '; expires=' + date.toUTCString();\n }\n document.cookie = name + '=' + (value || '') + expires + '; path=/' + '; Secure; SameSite=None';\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${contentId}`;\n const variantInCookie = getCookie(cookieName);\n const availableIDs = variants.map(vr => vr.id).concat(contentId);\n if (variantInCookie && availableIDs.includes(variantInCookie)) {\n return variantInCookie;\n }\n let n = 0;\n const random = Math.random();\n for (let i = 0; i < variants.length; i++) {\n const variant = variants[i];\n const testRatio = variant.testRatio;\n n += testRatio;\n if (random < n) {\n setCookie(cookieName, variant.id);\n return variant.id;\n }\n }\n setCookie(cookieName, contentId);\n return contentId;\n }\n const winningVariantId = getAndSetVariantId();\n let styleEl = document.currentScript?.previousElementSibling;\n if (isAngularSDK) {\n styleEl = document.currentScript?.parentElement?.previousElementSibling?.querySelector('style');\n }\n if (isHydrationTarget) {\n styleEl.remove();\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n } else {\n const newStyleStr = variants.concat({\n id: contentId\n }).filter(variant => variant.id !== winningVariantId).map(value => {\n return `.variant-${value.id} { display: none; }\n `;\n }).join('');\n styleEl.innerHTML = newStyleStr;\n }\n}";
14
14
  export const UPDATE_VARIANT_VISIBILITY_SCRIPT = "function updateVariantVisibility(variantContentId, defaultContentId, isHydrationTarget) {\n if (!navigator.cookieEnabled) {\n return;\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${defaultContentId}`;\n const winningVariant = getCookie(cookieName);\n const parentDiv = document.currentScript?.parentElement;\n const isDefaultContent = variantContentId === defaultContentId;\n const isWinningVariant = winningVariant === variantContentId;\n if (isWinningVariant && !isDefaultContent) {\n parentDiv?.removeAttribute('hidden');\n parentDiv?.removeAttribute('aria-hidden');\n } else if (!isWinningVariant && isDefaultContent) {\n parentDiv?.setAttribute('hidden', 'true');\n parentDiv?.setAttribute('aria-hidden', 'true');\n }\n if (isHydrationTarget) {\n if (!isWinningVariant) {\n parentDiv?.remove();\n }\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n }\n return;\n}";
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "4.0.2";
1
+ export declare const SDK_VERSION = "4.0.4";
@@ -1 +1 @@
1
- export const SDK_VERSION = "4.0.2";
1
+ export const SDK_VERSION = "4.0.4";
@@ -1,14 +1,14 @@
1
1
  <script context="module"></script>
2
2
 
3
3
  <script>import { onMount } from "svelte";
4
- export let replaceNodes = undefined;
4
+ import { isEditing } from "../../functions/is-editing";
5
+ import { logger } from "../../helpers/logger";
5
6
  export let code;
6
- let elementRef;
7
- let scriptsInserted = [];
8
- let scriptsRun = [];
9
- onMount(() => {
10
- // TODO: Move this function to standalone one in '@builder.io/utils'
11
- if (!elementRef?.getElementsByTagName || typeof window === "undefined") {
7
+ export let replaceNodes = undefined;
8
+ function runScripts() {
9
+ if (!elementRef ||
10
+ !elementRef?.getElementsByTagName ||
11
+ typeof window === "undefined") {
12
12
  return;
13
13
  }
14
14
  const scripts = elementRef.getElementsByTagName("script");
@@ -38,11 +38,25 @@ onMount(() => {
38
38
  new Function(script.innerText)();
39
39
  }
40
40
  catch (error) {
41
- console.warn("`CustomCode`: Error running script:", error);
41
+ logger.warn("[BUILDER.IO] `CustomCode`: Error running script:", error);
42
42
  }
43
43
  }
44
44
  }
45
+ }
46
+ let elementRef;
47
+ let scriptsInserted = [];
48
+ let scriptsRun = [];
49
+ onMount(() => {
50
+ runScripts();
45
51
  });
52
+ function onUpdateFn_0(..._args) {
53
+ if (isEditing()) {
54
+ setTimeout(() => {
55
+ runScripts();
56
+ }, 0);
57
+ }
58
+ }
59
+ $: onUpdateFn_0(...[code]);
46
60
  </script>
47
61
 
48
62
  <div
@@ -1,6 +1,7 @@
1
1
  <script context="module"></script>
2
2
 
3
- <script>import { isJsScript } from "./helpers";
3
+ <script>import { logger } from "../../helpers/logger";
4
+ import { isJsScript } from "./helpers";
4
5
  export let content;
5
6
  function findAndRunScripts() {
6
7
  if (!elem || !elem.getElementsByTagName)
@@ -21,7 +22,7 @@ function findAndRunScripts() {
21
22
  new Function(script.innerText)();
22
23
  }
23
24
  catch (error) {
24
- console.warn("`Embed`: Error running script:", error);
25
+ logger.warn("[BUILDER.IO] `Embed`: Error running script:", error);
25
26
  }
26
27
  }
27
28
  }
@@ -87,6 +87,10 @@ export const componentInfo = {
87
87
  name: 'altText',
88
88
  type: 'string',
89
89
  helperText: 'Text to display when the user has images off'
90
+ }, {
91
+ name: 'title',
92
+ type: 'string',
93
+ helperText: 'Text to display when hovering over the asset'
90
94
  }, {
91
95
  name: 'height',
92
96
  type: 'number',
@@ -6,6 +6,7 @@ export let noWebp = undefined;
6
6
  export let aspectRatio = undefined;
7
7
  export let highPriority = undefined;
8
8
  export let altText = undefined;
9
+ export let title = undefined;
9
10
  export let backgroundPosition = undefined;
10
11
  export let backgroundSize = undefined;
11
12
  export let className = undefined;
@@ -79,6 +80,7 @@ $: aspectRatioCss = () => {
79
80
  loading={highPriority ? "eager" : "lazy"}
80
81
  fetchpriority={highPriority ? "high" : "auto"}
81
82
  alt={altText}
83
+ {title}
82
84
  role={altText ? undefined : "presentation"}
83
85
  class={"builder-image" + (className ? " " + className : "") + " img"}
84
86
  src={image}
@@ -9,6 +9,7 @@ declare const __propDef: {
9
9
  aspectRatio?: ImageProps["aspectRatio"];
10
10
  highPriority?: ImageProps["highPriority"];
11
11
  altText?: ImageProps["altText"];
12
+ title?: ImageProps["title"];
12
13
  backgroundPosition?: ImageProps["backgroundPosition"];
13
14
  backgroundSize?: ImageProps["backgroundSize"];
14
15
  className?: ImageProps["className"];
@@ -9,6 +9,7 @@ export interface ImageProps {
9
9
  height?: number;
10
10
  width?: number;
11
11
  altText?: string;
12
+ title?: string;
12
13
  backgroundSize?: 'cover' | 'contain';
13
14
  backgroundPosition?: string;
14
15
  srcset?: string;
@@ -59,7 +59,10 @@ $: dataPath = () => {
59
59
  : `${pathPrefix}${path || ""}`;
60
60
  };
61
61
  let blocksWrapperRef;
62
+ let shouldUpdate = false;
62
63
  onMount(() => { });
64
+ function onUpdateFn_0(..._args) { }
65
+ $: onUpdateFn_0(...[blocks]);
63
66
  </script>
64
67
 
65
68
  <svelte:element
@@ -41,6 +41,7 @@ export const checkShouldRenderVariants = ({ canTrack, content }) => {
41
41
  return true;
42
42
  };
43
43
  const getIsHydrationTarget = (target) => target === 'react' || target === 'reactNative';
44
+ const isAngularSDK = TARGET === 'angular';
44
45
  const isHydrationTarget = getIsHydrationTarget(TARGET);
45
46
  export const getInitVariantsFnsScriptString = () => `
46
47
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
@@ -48,7 +49,7 @@ export const getInitVariantsFnsScriptString = () => `
48
49
  `;
49
50
  export const getUpdateCookieAndStylesScript = (variants, contentId) => `
50
51
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME}(
51
- "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}
52
+ "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}, ${isAngularSDK}
52
53
  )`;
53
54
  export const getUpdateVariantVisibilityScript = ({ contentId, variationId }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
54
55
  "${variationId}", "${contentId}", ${isHydrationTarget}
@@ -10,5 +10,5 @@
10
10
  * For more information on how this works,
11
11
  * see our [SSR A/B Test Docs](https://github.com/BuilderIO/builder/tree/main/packages/sdks/docs/SSR_AB_TEST.md)
12
12
  */
13
- export declare const UPDATE_COOKIES_AND_STYLES_SCRIPT = "function updateCookiesAndStyles(contentId, variants, isHydrationTarget) {\n function getAndSetVariantId() {\n function setCookie(name, value, days) {\n let expires = '';\n if (days) {\n const date = new Date();\n date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);\n expires = '; expires=' + date.toUTCString();\n }\n document.cookie = name + '=' + (value || '') + expires + '; path=/' + '; Secure; SameSite=None';\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${contentId}`;\n const variantInCookie = getCookie(cookieName);\n const availableIDs = variants.map(vr => vr.id).concat(contentId);\n if (variantInCookie && availableIDs.includes(variantInCookie)) {\n return variantInCookie;\n }\n let n = 0;\n const random = Math.random();\n for (let i = 0; i < variants.length; i++) {\n const variant = variants[i];\n const testRatio = variant.testRatio;\n n += testRatio;\n if (random < n) {\n setCookie(cookieName, variant.id);\n return variant.id;\n }\n }\n setCookie(cookieName, contentId);\n return contentId;\n }\n const winningVariantId = getAndSetVariantId();\n const styleEl = document.currentScript?.previousElementSibling;\n if (isHydrationTarget) {\n styleEl.remove();\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n } else {\n const newStyleStr = variants.concat({\n id: contentId\n }).filter(variant => variant.id !== winningVariantId).map(value => {\n return `.variant-${value.id} { display: none; }\n `;\n }).join('');\n styleEl.innerHTML = newStyleStr;\n }\n}";
13
+ export declare const UPDATE_COOKIES_AND_STYLES_SCRIPT = "function updateCookiesAndStyles(contentId, variants, isHydrationTarget, isAngularSDK) {\n function getAndSetVariantId() {\n function setCookie(name, value, days) {\n let expires = '';\n if (days) {\n const date = new Date();\n date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);\n expires = '; expires=' + date.toUTCString();\n }\n document.cookie = name + '=' + (value || '') + expires + '; path=/' + '; Secure; SameSite=None';\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${contentId}`;\n const variantInCookie = getCookie(cookieName);\n const availableIDs = variants.map(vr => vr.id).concat(contentId);\n if (variantInCookie && availableIDs.includes(variantInCookie)) {\n return variantInCookie;\n }\n let n = 0;\n const random = Math.random();\n for (let i = 0; i < variants.length; i++) {\n const variant = variants[i];\n const testRatio = variant.testRatio;\n n += testRatio;\n if (random < n) {\n setCookie(cookieName, variant.id);\n return variant.id;\n }\n }\n setCookie(cookieName, contentId);\n return contentId;\n }\n const winningVariantId = getAndSetVariantId();\n let styleEl = document.currentScript?.previousElementSibling;\n if (isAngularSDK) {\n styleEl = document.currentScript?.parentElement?.previousElementSibling?.querySelector('style');\n }\n if (isHydrationTarget) {\n styleEl.remove();\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n } else {\n const newStyleStr = variants.concat({\n id: contentId\n }).filter(variant => variant.id !== winningVariantId).map(value => {\n return `.variant-${value.id} { display: none; }\n `;\n }).join('');\n styleEl.innerHTML = newStyleStr;\n }\n}";
14
14
  export declare const UPDATE_VARIANT_VISIBILITY_SCRIPT = "function updateVariantVisibility(variantContentId, defaultContentId, isHydrationTarget) {\n if (!navigator.cookieEnabled) {\n return;\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${defaultContentId}`;\n const winningVariant = getCookie(cookieName);\n const parentDiv = document.currentScript?.parentElement;\n const isDefaultContent = variantContentId === defaultContentId;\n const isWinningVariant = winningVariant === variantContentId;\n if (isWinningVariant && !isDefaultContent) {\n parentDiv?.removeAttribute('hidden');\n parentDiv?.removeAttribute('aria-hidden');\n } else if (!isWinningVariant && isDefaultContent) {\n parentDiv?.setAttribute('hidden', 'true');\n parentDiv?.setAttribute('aria-hidden', 'true');\n }\n if (isHydrationTarget) {\n if (!isWinningVariant) {\n parentDiv?.remove();\n }\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n }\n return;\n}";
@@ -10,5 +10,5 @@
10
10
  * For more information on how this works,
11
11
  * see our [SSR A/B Test Docs](https://github.com/BuilderIO/builder/tree/main/packages/sdks/docs/SSR_AB_TEST.md)
12
12
  */
13
- export const UPDATE_COOKIES_AND_STYLES_SCRIPT = "function updateCookiesAndStyles(contentId, variants, isHydrationTarget) {\n function getAndSetVariantId() {\n function setCookie(name, value, days) {\n let expires = '';\n if (days) {\n const date = new Date();\n date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);\n expires = '; expires=' + date.toUTCString();\n }\n document.cookie = name + '=' + (value || '') + expires + '; path=/' + '; Secure; SameSite=None';\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${contentId}`;\n const variantInCookie = getCookie(cookieName);\n const availableIDs = variants.map(vr => vr.id).concat(contentId);\n if (variantInCookie && availableIDs.includes(variantInCookie)) {\n return variantInCookie;\n }\n let n = 0;\n const random = Math.random();\n for (let i = 0; i < variants.length; i++) {\n const variant = variants[i];\n const testRatio = variant.testRatio;\n n += testRatio;\n if (random < n) {\n setCookie(cookieName, variant.id);\n return variant.id;\n }\n }\n setCookie(cookieName, contentId);\n return contentId;\n }\n const winningVariantId = getAndSetVariantId();\n const styleEl = document.currentScript?.previousElementSibling;\n if (isHydrationTarget) {\n styleEl.remove();\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n } else {\n const newStyleStr = variants.concat({\n id: contentId\n }).filter(variant => variant.id !== winningVariantId).map(value => {\n return `.variant-${value.id} { display: none; }\n `;\n }).join('');\n styleEl.innerHTML = newStyleStr;\n }\n}";
13
+ export const UPDATE_COOKIES_AND_STYLES_SCRIPT = "function updateCookiesAndStyles(contentId, variants, isHydrationTarget, isAngularSDK) {\n function getAndSetVariantId() {\n function setCookie(name, value, days) {\n let expires = '';\n if (days) {\n const date = new Date();\n date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);\n expires = '; expires=' + date.toUTCString();\n }\n document.cookie = name + '=' + (value || '') + expires + '; path=/' + '; Secure; SameSite=None';\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${contentId}`;\n const variantInCookie = getCookie(cookieName);\n const availableIDs = variants.map(vr => vr.id).concat(contentId);\n if (variantInCookie && availableIDs.includes(variantInCookie)) {\n return variantInCookie;\n }\n let n = 0;\n const random = Math.random();\n for (let i = 0; i < variants.length; i++) {\n const variant = variants[i];\n const testRatio = variant.testRatio;\n n += testRatio;\n if (random < n) {\n setCookie(cookieName, variant.id);\n return variant.id;\n }\n }\n setCookie(cookieName, contentId);\n return contentId;\n }\n const winningVariantId = getAndSetVariantId();\n let styleEl = document.currentScript?.previousElementSibling;\n if (isAngularSDK) {\n styleEl = document.currentScript?.parentElement?.previousElementSibling?.querySelector('style');\n }\n if (isHydrationTarget) {\n styleEl.remove();\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n } else {\n const newStyleStr = variants.concat({\n id: contentId\n }).filter(variant => variant.id !== winningVariantId).map(value => {\n return `.variant-${value.id} { display: none; }\n `;\n }).join('');\n styleEl.innerHTML = newStyleStr;\n }\n}";
14
14
  export const UPDATE_VARIANT_VISIBILITY_SCRIPT = "function updateVariantVisibility(variantContentId, defaultContentId, isHydrationTarget) {\n if (!navigator.cookieEnabled) {\n return;\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${defaultContentId}`;\n const winningVariant = getCookie(cookieName);\n const parentDiv = document.currentScript?.parentElement;\n const isDefaultContent = variantContentId === defaultContentId;\n const isWinningVariant = winningVariant === variantContentId;\n if (isWinningVariant && !isDefaultContent) {\n parentDiv?.removeAttribute('hidden');\n parentDiv?.removeAttribute('aria-hidden');\n } else if (!isWinningVariant && isDefaultContent) {\n parentDiv?.setAttribute('hidden', 'true');\n parentDiv?.setAttribute('aria-hidden', 'true');\n }\n if (isHydrationTarget) {\n if (!isWinningVariant) {\n parentDiv?.remove();\n }\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n }\n return;\n}";
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "4.0.2";
1
+ export declare const SDK_VERSION = "4.0.4";
@@ -1 +1 @@
1
- export const SDK_VERSION = "4.0.2";
1
+ export const SDK_VERSION = "4.0.4";
@@ -1,14 +1,14 @@
1
1
  <script context="module"></script>
2
2
 
3
3
  <script>import { onMount } from "svelte";
4
- export let replaceNodes = undefined;
4
+ import { isEditing } from "../../functions/is-editing";
5
+ import { logger } from "../../helpers/logger";
5
6
  export let code;
6
- let elementRef;
7
- let scriptsInserted = [];
8
- let scriptsRun = [];
9
- onMount(() => {
10
- // TODO: Move this function to standalone one in '@builder.io/utils'
11
- if (!elementRef?.getElementsByTagName || typeof window === "undefined") {
7
+ export let replaceNodes = undefined;
8
+ function runScripts() {
9
+ if (!elementRef ||
10
+ !elementRef?.getElementsByTagName ||
11
+ typeof window === "undefined") {
12
12
  return;
13
13
  }
14
14
  const scripts = elementRef.getElementsByTagName("script");
@@ -38,11 +38,25 @@ onMount(() => {
38
38
  new Function(script.innerText)();
39
39
  }
40
40
  catch (error) {
41
- console.warn("`CustomCode`: Error running script:", error);
41
+ logger.warn("[BUILDER.IO] `CustomCode`: Error running script:", error);
42
42
  }
43
43
  }
44
44
  }
45
+ }
46
+ let elementRef;
47
+ let scriptsInserted = [];
48
+ let scriptsRun = [];
49
+ onMount(() => {
50
+ runScripts();
45
51
  });
52
+ function onUpdateFn_0(..._args) {
53
+ if (isEditing()) {
54
+ setTimeout(() => {
55
+ runScripts();
56
+ }, 0);
57
+ }
58
+ }
59
+ $: onUpdateFn_0(...[code]);
46
60
  </script>
47
61
 
48
62
  <div
@@ -1,6 +1,7 @@
1
1
  <script context="module"></script>
2
2
 
3
- <script>import { isJsScript } from "./helpers";
3
+ <script>import { logger } from "../../helpers/logger";
4
+ import { isJsScript } from "./helpers";
4
5
  export let content;
5
6
  function findAndRunScripts() {
6
7
  if (!elem || !elem.getElementsByTagName)
@@ -21,7 +22,7 @@ function findAndRunScripts() {
21
22
  new Function(script.innerText)();
22
23
  }
23
24
  catch (error) {
24
- console.warn("`Embed`: Error running script:", error);
25
+ logger.warn("[BUILDER.IO] `Embed`: Error running script:", error);
25
26
  }
26
27
  }
27
28
  }
@@ -87,6 +87,10 @@ export const componentInfo = {
87
87
  name: 'altText',
88
88
  type: 'string',
89
89
  helperText: 'Text to display when the user has images off'
90
+ }, {
91
+ name: 'title',
92
+ type: 'string',
93
+ helperText: 'Text to display when hovering over the asset'
90
94
  }, {
91
95
  name: 'height',
92
96
  type: 'number',
@@ -6,6 +6,7 @@ export let noWebp = undefined;
6
6
  export let aspectRatio = undefined;
7
7
  export let highPriority = undefined;
8
8
  export let altText = undefined;
9
+ export let title = undefined;
9
10
  export let backgroundPosition = undefined;
10
11
  export let backgroundSize = undefined;
11
12
  export let className = undefined;
@@ -79,6 +80,7 @@ $: aspectRatioCss = () => {
79
80
  loading={highPriority ? "eager" : "lazy"}
80
81
  fetchpriority={highPriority ? "high" : "auto"}
81
82
  alt={altText}
83
+ {title}
82
84
  role={altText ? undefined : "presentation"}
83
85
  class={"builder-image" + (className ? " " + className : "") + " img"}
84
86
  src={image}
@@ -9,6 +9,7 @@ declare const __propDef: {
9
9
  aspectRatio?: ImageProps["aspectRatio"];
10
10
  highPriority?: ImageProps["highPriority"];
11
11
  altText?: ImageProps["altText"];
12
+ title?: ImageProps["title"];
12
13
  backgroundPosition?: ImageProps["backgroundPosition"];
13
14
  backgroundSize?: ImageProps["backgroundSize"];
14
15
  className?: ImageProps["className"];
@@ -9,6 +9,7 @@ export interface ImageProps {
9
9
  height?: number;
10
10
  width?: number;
11
11
  altText?: string;
12
+ title?: string;
12
13
  backgroundSize?: 'cover' | 'contain';
13
14
  backgroundPosition?: string;
14
15
  srcset?: string;
@@ -59,7 +59,10 @@ $: dataPath = () => {
59
59
  : `${pathPrefix}${path || ""}`;
60
60
  };
61
61
  let blocksWrapperRef;
62
+ let shouldUpdate = false;
62
63
  onMount(() => { });
64
+ function onUpdateFn_0(..._args) { }
65
+ $: onUpdateFn_0(...[blocks]);
63
66
  </script>
64
67
 
65
68
  <svelte:element
@@ -41,6 +41,7 @@ export const checkShouldRenderVariants = ({ canTrack, content }) => {
41
41
  return true;
42
42
  };
43
43
  const getIsHydrationTarget = (target) => target === 'react' || target === 'reactNative';
44
+ const isAngularSDK = TARGET === 'angular';
44
45
  const isHydrationTarget = getIsHydrationTarget(TARGET);
45
46
  export const getInitVariantsFnsScriptString = () => `
46
47
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
@@ -48,7 +49,7 @@ export const getInitVariantsFnsScriptString = () => `
48
49
  `;
49
50
  export const getUpdateCookieAndStylesScript = (variants, contentId) => `
50
51
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME}(
51
- "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}
52
+ "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}, ${isAngularSDK}
52
53
  )`;
53
54
  export const getUpdateVariantVisibilityScript = ({ contentId, variationId }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
54
55
  "${variationId}", "${contentId}", ${isHydrationTarget}
@@ -10,5 +10,5 @@
10
10
  * For more information on how this works,
11
11
  * see our [SSR A/B Test Docs](https://github.com/BuilderIO/builder/tree/main/packages/sdks/docs/SSR_AB_TEST.md)
12
12
  */
13
- export declare const UPDATE_COOKIES_AND_STYLES_SCRIPT = "function updateCookiesAndStyles(contentId, variants, isHydrationTarget) {\n function getAndSetVariantId() {\n function setCookie(name, value, days) {\n let expires = '';\n if (days) {\n const date = new Date();\n date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);\n expires = '; expires=' + date.toUTCString();\n }\n document.cookie = name + '=' + (value || '') + expires + '; path=/' + '; Secure; SameSite=None';\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${contentId}`;\n const variantInCookie = getCookie(cookieName);\n const availableIDs = variants.map(vr => vr.id).concat(contentId);\n if (variantInCookie && availableIDs.includes(variantInCookie)) {\n return variantInCookie;\n }\n let n = 0;\n const random = Math.random();\n for (let i = 0; i < variants.length; i++) {\n const variant = variants[i];\n const testRatio = variant.testRatio;\n n += testRatio;\n if (random < n) {\n setCookie(cookieName, variant.id);\n return variant.id;\n }\n }\n setCookie(cookieName, contentId);\n return contentId;\n }\n const winningVariantId = getAndSetVariantId();\n const styleEl = document.currentScript?.previousElementSibling;\n if (isHydrationTarget) {\n styleEl.remove();\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n } else {\n const newStyleStr = variants.concat({\n id: contentId\n }).filter(variant => variant.id !== winningVariantId).map(value => {\n return `.variant-${value.id} { display: none; }\n `;\n }).join('');\n styleEl.innerHTML = newStyleStr;\n }\n}";
13
+ export declare const UPDATE_COOKIES_AND_STYLES_SCRIPT = "function updateCookiesAndStyles(contentId, variants, isHydrationTarget, isAngularSDK) {\n function getAndSetVariantId() {\n function setCookie(name, value, days) {\n let expires = '';\n if (days) {\n const date = new Date();\n date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);\n expires = '; expires=' + date.toUTCString();\n }\n document.cookie = name + '=' + (value || '') + expires + '; path=/' + '; Secure; SameSite=None';\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${contentId}`;\n const variantInCookie = getCookie(cookieName);\n const availableIDs = variants.map(vr => vr.id).concat(contentId);\n if (variantInCookie && availableIDs.includes(variantInCookie)) {\n return variantInCookie;\n }\n let n = 0;\n const random = Math.random();\n for (let i = 0; i < variants.length; i++) {\n const variant = variants[i];\n const testRatio = variant.testRatio;\n n += testRatio;\n if (random < n) {\n setCookie(cookieName, variant.id);\n return variant.id;\n }\n }\n setCookie(cookieName, contentId);\n return contentId;\n }\n const winningVariantId = getAndSetVariantId();\n let styleEl = document.currentScript?.previousElementSibling;\n if (isAngularSDK) {\n styleEl = document.currentScript?.parentElement?.previousElementSibling?.querySelector('style');\n }\n if (isHydrationTarget) {\n styleEl.remove();\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n } else {\n const newStyleStr = variants.concat({\n id: contentId\n }).filter(variant => variant.id !== winningVariantId).map(value => {\n return `.variant-${value.id} { display: none; }\n `;\n }).join('');\n styleEl.innerHTML = newStyleStr;\n }\n}";
14
14
  export declare const UPDATE_VARIANT_VISIBILITY_SCRIPT = "function updateVariantVisibility(variantContentId, defaultContentId, isHydrationTarget) {\n if (!navigator.cookieEnabled) {\n return;\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${defaultContentId}`;\n const winningVariant = getCookie(cookieName);\n const parentDiv = document.currentScript?.parentElement;\n const isDefaultContent = variantContentId === defaultContentId;\n const isWinningVariant = winningVariant === variantContentId;\n if (isWinningVariant && !isDefaultContent) {\n parentDiv?.removeAttribute('hidden');\n parentDiv?.removeAttribute('aria-hidden');\n } else if (!isWinningVariant && isDefaultContent) {\n parentDiv?.setAttribute('hidden', 'true');\n parentDiv?.setAttribute('aria-hidden', 'true');\n }\n if (isHydrationTarget) {\n if (!isWinningVariant) {\n parentDiv?.remove();\n }\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n }\n return;\n}";
@@ -10,5 +10,5 @@
10
10
  * For more information on how this works,
11
11
  * see our [SSR A/B Test Docs](https://github.com/BuilderIO/builder/tree/main/packages/sdks/docs/SSR_AB_TEST.md)
12
12
  */
13
- export const UPDATE_COOKIES_AND_STYLES_SCRIPT = "function updateCookiesAndStyles(contentId, variants, isHydrationTarget) {\n function getAndSetVariantId() {\n function setCookie(name, value, days) {\n let expires = '';\n if (days) {\n const date = new Date();\n date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);\n expires = '; expires=' + date.toUTCString();\n }\n document.cookie = name + '=' + (value || '') + expires + '; path=/' + '; Secure; SameSite=None';\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${contentId}`;\n const variantInCookie = getCookie(cookieName);\n const availableIDs = variants.map(vr => vr.id).concat(contentId);\n if (variantInCookie && availableIDs.includes(variantInCookie)) {\n return variantInCookie;\n }\n let n = 0;\n const random = Math.random();\n for (let i = 0; i < variants.length; i++) {\n const variant = variants[i];\n const testRatio = variant.testRatio;\n n += testRatio;\n if (random < n) {\n setCookie(cookieName, variant.id);\n return variant.id;\n }\n }\n setCookie(cookieName, contentId);\n return contentId;\n }\n const winningVariantId = getAndSetVariantId();\n const styleEl = document.currentScript?.previousElementSibling;\n if (isHydrationTarget) {\n styleEl.remove();\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n } else {\n const newStyleStr = variants.concat({\n id: contentId\n }).filter(variant => variant.id !== winningVariantId).map(value => {\n return `.variant-${value.id} { display: none; }\n `;\n }).join('');\n styleEl.innerHTML = newStyleStr;\n }\n}";
13
+ export const UPDATE_COOKIES_AND_STYLES_SCRIPT = "function updateCookiesAndStyles(contentId, variants, isHydrationTarget, isAngularSDK) {\n function getAndSetVariantId() {\n function setCookie(name, value, days) {\n let expires = '';\n if (days) {\n const date = new Date();\n date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);\n expires = '; expires=' + date.toUTCString();\n }\n document.cookie = name + '=' + (value || '') + expires + '; path=/' + '; Secure; SameSite=None';\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${contentId}`;\n const variantInCookie = getCookie(cookieName);\n const availableIDs = variants.map(vr => vr.id).concat(contentId);\n if (variantInCookie && availableIDs.includes(variantInCookie)) {\n return variantInCookie;\n }\n let n = 0;\n const random = Math.random();\n for (let i = 0; i < variants.length; i++) {\n const variant = variants[i];\n const testRatio = variant.testRatio;\n n += testRatio;\n if (random < n) {\n setCookie(cookieName, variant.id);\n return variant.id;\n }\n }\n setCookie(cookieName, contentId);\n return contentId;\n }\n const winningVariantId = getAndSetVariantId();\n let styleEl = document.currentScript?.previousElementSibling;\n if (isAngularSDK) {\n styleEl = document.currentScript?.parentElement?.previousElementSibling?.querySelector('style');\n }\n if (isHydrationTarget) {\n styleEl.remove();\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n } else {\n const newStyleStr = variants.concat({\n id: contentId\n }).filter(variant => variant.id !== winningVariantId).map(value => {\n return `.variant-${value.id} { display: none; }\n `;\n }).join('');\n styleEl.innerHTML = newStyleStr;\n }\n}";
14
14
  export const UPDATE_VARIANT_VISIBILITY_SCRIPT = "function updateVariantVisibility(variantContentId, defaultContentId, isHydrationTarget) {\n if (!navigator.cookieEnabled) {\n return;\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${defaultContentId}`;\n const winningVariant = getCookie(cookieName);\n const parentDiv = document.currentScript?.parentElement;\n const isDefaultContent = variantContentId === defaultContentId;\n const isWinningVariant = winningVariant === variantContentId;\n if (isWinningVariant && !isDefaultContent) {\n parentDiv?.removeAttribute('hidden');\n parentDiv?.removeAttribute('aria-hidden');\n } else if (!isWinningVariant && isDefaultContent) {\n parentDiv?.setAttribute('hidden', 'true');\n parentDiv?.setAttribute('aria-hidden', 'true');\n }\n if (isHydrationTarget) {\n if (!isWinningVariant) {\n parentDiv?.remove();\n }\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n }\n return;\n}";
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "4.0.2";
1
+ export declare const SDK_VERSION = "4.0.4";
@@ -1 +1 @@
1
- export const SDK_VERSION = "4.0.2";
1
+ export const SDK_VERSION = "4.0.4";
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": "4.0.2",
4
+ "version": "4.0.4",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "lib",
@@ -8,17 +8,18 @@
8
8
  <script lang="ts">
9
9
  import { onMount } from "svelte";
10
10
 
11
- export let replaceNodes: CustomCodeProps["replaceNodes"] = undefined;
12
- export let code: CustomCodeProps["code"];
13
-
14
- let elementRef;
11
+ import { isEditing } from "../../functions/is-editing";
12
+ import { logger } from "../../helpers/logger";
15
13
 
16
- let scriptsInserted = [];
17
- let scriptsRun = [];
14
+ export let code: CustomCodeProps["code"];
15
+ export let replaceNodes: CustomCodeProps["replaceNodes"] = undefined;
18
16
 
19
- onMount(() => {
20
- // TODO: Move this function to standalone one in '@builder.io/utils'
21
- if (!elementRef?.getElementsByTagName || typeof window === "undefined") {
17
+ function runScripts() {
18
+ if (
19
+ !elementRef ||
20
+ !elementRef?.getElementsByTagName ||
21
+ typeof window === "undefined"
22
+ ) {
22
23
  return;
23
24
  }
24
25
  const scripts = elementRef.getElementsByTagName("script");
@@ -48,11 +49,33 @@
48
49
  scriptsRun.push(script.innerText);
49
50
  new Function(script.innerText)();
50
51
  } catch (error) {
51
- console.warn("`CustomCode`: Error running script:", error);
52
+ logger.warn(
53
+ "[BUILDER.IO] `CustomCode`: Error running script:",
54
+ error
55
+ );
52
56
  }
53
57
  }
54
58
  }
59
+ }
60
+
61
+ let elementRef;
62
+
63
+ let scriptsInserted = [];
64
+ let scriptsRun = [];
65
+
66
+ onMount(() => {
67
+ runScripts();
55
68
  });
69
+
70
+ function onUpdateFn_0(..._args: any[]) {
71
+ if (isEditing()) {
72
+ setTimeout(() => {
73
+ runScripts();
74
+ }, 0);
75
+ }
76
+ }
77
+
78
+ $: onUpdateFn_0(...[code]);
56
79
  </script>
57
80
 
58
81
  <div
@@ -5,6 +5,7 @@
5
5
  </script>
6
6
 
7
7
  <script lang="ts">
8
+ import { logger } from "../../helpers/logger";
8
9
  import { isJsScript } from "./helpers";
9
10
 
10
11
  export let content: EmbedProps["content"];
@@ -25,7 +26,7 @@
25
26
  scriptsRun.push(script.innerText);
26
27
  new Function(script.innerText)();
27
28
  } catch (error) {
28
- console.warn("`Embed`: Error running script:", error);
29
+ logger.warn("[BUILDER.IO] `Embed`: Error running script:", error);
29
30
  }
30
31
  }
31
32
  }
@@ -89,6 +89,10 @@ export const componentInfo: ComponentInfo = {
89
89
  name: 'altText',
90
90
  type: 'string',
91
91
  helperText: 'Text to display when the user has images off'
92
+ }, {
93
+ name: 'title',
94
+ type: 'string',
95
+ helperText: 'Text to display when hovering over the asset'
92
96
  }, {
93
97
  name: 'height',
94
98
  type: 'number',
@@ -9,6 +9,7 @@
9
9
  export let aspectRatio: ImageProps["aspectRatio"] = undefined;
10
10
  export let highPriority: ImageProps["highPriority"] = undefined;
11
11
  export let altText: ImageProps["altText"] = undefined;
12
+ export let title: ImageProps["title"] = undefined;
12
13
  export let backgroundPosition: ImageProps["backgroundPosition"] = undefined;
13
14
  export let backgroundSize: ImageProps["backgroundSize"] = undefined;
14
15
  export let className: ImageProps["className"] = undefined;
@@ -86,6 +87,7 @@
86
87
  loading={highPriority ? "eager" : "lazy"}
87
88
  fetchpriority={highPriority ? "high" : "auto"}
88
89
  alt={altText}
90
+ {title}
89
91
  role={altText ? undefined : "presentation"}
90
92
  class={"builder-image" + (className ? " " + className : "") + " img"}
91
93
  src={image}
@@ -9,6 +9,7 @@ export interface ImageProps {
9
9
  height?: number;
10
10
  width?: number;
11
11
  altText?: string;
12
+ title?: string;
12
13
  backgroundSize?: 'cover' | 'contain';
13
14
  backgroundPosition?: string;
14
15
  srcset?: string;
@@ -90,7 +90,13 @@
90
90
 
91
91
  let blocksWrapperRef;
92
92
 
93
+ let shouldUpdate = false;
94
+
93
95
  onMount(() => {});
96
+
97
+ function onUpdateFn_0(..._args: any[]) {}
98
+
99
+ $: onUpdateFn_0(...[blocks]);
94
100
  </script>
95
101
 
96
102
  <svelte:element
@@ -52,6 +52,7 @@ type VariantData = {
52
52
  testRatio?: number;
53
53
  };
54
54
  const getIsHydrationTarget = (target: Target) => target === 'react' || target === 'reactNative';
55
+ const isAngularSDK = TARGET === 'angular';
55
56
  const isHydrationTarget = getIsHydrationTarget(TARGET);
56
57
  export const getInitVariantsFnsScriptString = () => `
57
58
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
@@ -59,7 +60,7 @@ export const getInitVariantsFnsScriptString = () => `
59
60
  `;
60
61
  export const getUpdateCookieAndStylesScript = (variants: VariantData[], contentId: string) => `
61
62
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME}(
62
- "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}
63
+ "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}, ${isAngularSDK}
63
64
  )`;
64
65
  export const getUpdateVariantVisibilityScript = ({
65
66
  contentId,
@@ -18,5 +18,5 @@ type VariantData = {
18
18
  * see our [SSR A/B Test Docs](https://github.com/BuilderIO/builder/tree/main/packages/sdks/docs/SSR_AB_TEST.md)
19
19
  */
20
20
 
21
- export const UPDATE_COOKIES_AND_STYLES_SCRIPT = "function updateCookiesAndStyles(contentId, variants, isHydrationTarget) {\n function getAndSetVariantId() {\n function setCookie(name, value, days) {\n let expires = '';\n if (days) {\n const date = new Date();\n date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);\n expires = '; expires=' + date.toUTCString();\n }\n document.cookie = name + '=' + (value || '') + expires + '; path=/' + '; Secure; SameSite=None';\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${contentId}`;\n const variantInCookie = getCookie(cookieName);\n const availableIDs = variants.map(vr => vr.id).concat(contentId);\n if (variantInCookie && availableIDs.includes(variantInCookie)) {\n return variantInCookie;\n }\n let n = 0;\n const random = Math.random();\n for (let i = 0; i < variants.length; i++) {\n const variant = variants[i];\n const testRatio = variant.testRatio;\n n += testRatio;\n if (random < n) {\n setCookie(cookieName, variant.id);\n return variant.id;\n }\n }\n setCookie(cookieName, contentId);\n return contentId;\n }\n const winningVariantId = getAndSetVariantId();\n const styleEl = document.currentScript?.previousElementSibling;\n if (isHydrationTarget) {\n styleEl.remove();\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n } else {\n const newStyleStr = variants.concat({\n id: contentId\n }).filter(variant => variant.id !== winningVariantId).map(value => {\n return `.variant-${value.id} { display: none; }\n `;\n }).join('');\n styleEl.innerHTML = newStyleStr;\n }\n}";
21
+ export const UPDATE_COOKIES_AND_STYLES_SCRIPT = "function updateCookiesAndStyles(contentId, variants, isHydrationTarget, isAngularSDK) {\n function getAndSetVariantId() {\n function setCookie(name, value, days) {\n let expires = '';\n if (days) {\n const date = new Date();\n date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);\n expires = '; expires=' + date.toUTCString();\n }\n document.cookie = name + '=' + (value || '') + expires + '; path=/' + '; Secure; SameSite=None';\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${contentId}`;\n const variantInCookie = getCookie(cookieName);\n const availableIDs = variants.map(vr => vr.id).concat(contentId);\n if (variantInCookie && availableIDs.includes(variantInCookie)) {\n return variantInCookie;\n }\n let n = 0;\n const random = Math.random();\n for (let i = 0; i < variants.length; i++) {\n const variant = variants[i];\n const testRatio = variant.testRatio;\n n += testRatio;\n if (random < n) {\n setCookie(cookieName, variant.id);\n return variant.id;\n }\n }\n setCookie(cookieName, contentId);\n return contentId;\n }\n const winningVariantId = getAndSetVariantId();\n let styleEl = document.currentScript?.previousElementSibling;\n if (isAngularSDK) {\n styleEl = document.currentScript?.parentElement?.previousElementSibling?.querySelector('style');\n }\n if (isHydrationTarget) {\n styleEl.remove();\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n } else {\n const newStyleStr = variants.concat({\n id: contentId\n }).filter(variant => variant.id !== winningVariantId).map(value => {\n return `.variant-${value.id} { display: none; }\n `;\n }).join('');\n styleEl.innerHTML = newStyleStr;\n }\n}";
22
22
  export const UPDATE_VARIANT_VISIBILITY_SCRIPT = "function updateVariantVisibility(variantContentId, defaultContentId, isHydrationTarget) {\n if (!navigator.cookieEnabled) {\n return;\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${defaultContentId}`;\n const winningVariant = getCookie(cookieName);\n const parentDiv = document.currentScript?.parentElement;\n const isDefaultContent = variantContentId === defaultContentId;\n const isWinningVariant = winningVariant === variantContentId;\n if (isWinningVariant && !isDefaultContent) {\n parentDiv?.removeAttribute('hidden');\n parentDiv?.removeAttribute('aria-hidden');\n } else if (!isWinningVariant && isDefaultContent) {\n parentDiv?.setAttribute('hidden', 'true');\n parentDiv?.setAttribute('aria-hidden', 'true');\n }\n if (isHydrationTarget) {\n if (!isWinningVariant) {\n parentDiv?.remove();\n }\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n }\n return;\n}";
@@ -1 +1 @@
1
- export const SDK_VERSION = "4.0.2"
1
+ export const SDK_VERSION = "4.0.4"