@builder.io/sdk-svelte 0.0.1-20 → 0.0.1-23

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 (40) hide show
  1. package/package.json +1 -1
  2. package/src/blocks/button/button.svelte +17 -48
  3. package/src/blocks/columns/columns.svelte +110 -102
  4. package/src/blocks/columns/component-info.js +25 -1
  5. package/src/blocks/custom-code/custom-code.svelte +59 -61
  6. package/src/blocks/embed/component-info.js +20 -1
  7. package/src/blocks/embed/embed.svelte +38 -56
  8. package/src/blocks/embed/helpers.js +9 -0
  9. package/src/blocks/form/form.svelte +264 -294
  10. package/src/blocks/fragment/fragment.svelte +1 -26
  11. package/src/blocks/image/component-info.js +47 -1
  12. package/src/blocks/image/image.helpers.js +48 -0
  13. package/src/blocks/image/image.svelte +121 -117
  14. package/src/blocks/img/img.svelte +22 -32
  15. package/src/blocks/input/input.svelte +17 -30
  16. package/src/blocks/raw-text/raw-text.svelte +4 -26
  17. package/src/blocks/section/section.svelte +20 -36
  18. package/src/blocks/select/select.svelte +16 -36
  19. package/src/blocks/submit-button/submit-button.svelte +4 -30
  20. package/src/blocks/symbol/symbol.svelte +57 -57
  21. package/src/blocks/text/text.svelte +1 -25
  22. package/src/blocks/textarea/textarea.svelte +5 -29
  23. package/src/blocks/video/video.svelte +35 -43
  24. package/src/components/render-block/block-styles.svelte +49 -59
  25. package/src/components/render-block/render-block.svelte +197 -167
  26. package/src/components/render-block/render-component.svelte +13 -51
  27. package/src/components/render-block/render-repeated-block.svelte +29 -0
  28. package/src/components/render-blocks.svelte +74 -98
  29. package/src/components/render-content/components/render-styles.svelte +42 -62
  30. package/src/components/render-content/render-content.svelte +252 -241
  31. package/src/components/render-inlined-styles.svelte +15 -45
  32. package/src/constants/builder-registered-components.js +4 -1
  33. package/src/context/builder.context.js +7 -1
  34. package/src/functions/convert-style-object.js +6 -0
  35. package/src/functions/get-block-styles.js +6 -3
  36. package/src/functions/get-processed-block.js +15 -8
  37. package/src/functions/get-processed-block.test.js +2 -1
  38. package/src/functions/register-component.js +10 -18
  39. package/src/functions/sanitize-styles.js +5 -0
  40. package/src/functions/fast-clone.js +0 -4
@@ -0,0 +1,48 @@
1
+ function removeProtocol(path) {
2
+ return path.replace(/http(s)?:/, "");
3
+ }
4
+ function updateQueryParam(uri = "", key, value) {
5
+ const re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
6
+ const separator = uri.indexOf("?") !== -1 ? "&" : "?";
7
+ if (uri.match(re)) {
8
+ return uri.replace(re, "$1" + key + "=" + encodeURIComponent(value) + "$2");
9
+ }
10
+ return uri + separator + key + "=" + encodeURIComponent(value);
11
+ }
12
+ function getShopifyImageUrl(src, size) {
13
+ if (!src || !(src == null ? void 0 : src.match(/cdn\.shopify\.com/)) || !size) {
14
+ return src;
15
+ }
16
+ if (size === "master") {
17
+ return removeProtocol(src);
18
+ }
19
+ const match = src.match(/(_\d+x(\d+)?)?(\.(jpg|jpeg|gif|png|bmp|bitmap|tiff|tif)(\?v=\d+)?)/i);
20
+ if (match) {
21
+ const prefix = src.split(match[0]);
22
+ const suffix = match[3];
23
+ const useSize = size.match("x") ? size : `${size}x`;
24
+ return removeProtocol(`${prefix[0]}_${useSize}${suffix}`);
25
+ }
26
+ return null;
27
+ }
28
+ function getSrcSet(url) {
29
+ if (!url) {
30
+ return url;
31
+ }
32
+ const sizes = [100, 200, 400, 800, 1200, 1600, 2e3];
33
+ if (url.match(/builder\.io/)) {
34
+ let srcUrl = url;
35
+ const widthInSrc = Number(url.split("?width=")[1]);
36
+ if (!isNaN(widthInSrc)) {
37
+ srcUrl = `${srcUrl} ${widthInSrc}w`;
38
+ }
39
+ return sizes.filter((size) => size !== widthInSrc).map((size) => `${updateQueryParam(url, "width", size)} ${size}w`).concat([srcUrl]).join(", ");
40
+ }
41
+ if (url.match(/cdn\.shopify\.com/)) {
42
+ return sizes.map((size) => [getShopifyImageUrl(url, `${size}x${size}`), size]).filter(([sizeUrl]) => !!sizeUrl).map(([sizeUrl, size]) => `${sizeUrl} ${size}w`).concat([url]).join(", ");
43
+ }
44
+ return url;
45
+ }
46
+ export {
47
+ getSrcSet
48
+ };
@@ -1,118 +1,122 @@
1
1
  <script>
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
- export let altText;
14
- export let backgroundSize;
15
- export let className;
16
- export let image;
17
- export let srcset;
18
- export let sizes;
19
- export let aspectRatio;
20
- export let fitContent;
21
- export let builderBlock;
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
- </script>
37
-
38
- <div class="div" >
39
-
40
- <picture >
41
-
42
- <img loading="lazy" alt={altText} role={altText ? 'presentation' : undefined} style={{
43
- objectPosition: backgroundSize || 'center',
44
- objectFit: backgroundSize || 'cover'
45
- }} class={'builder-image' + (className ? ' ' + className : '') + 'img'} src={image} srcset={srcset} sizes={sizes} />
46
-
47
-
48
- <source srcset={srcset} />
49
-
50
- </picture>
51
-
52
-
53
-
54
- {#if aspectRatio && !(fitContent && builderBlock?.children?.length) }
55
-
56
-
57
- <div class="builder-image-sizer div-2" style={{
58
- paddingTop: aspectRatio * 100 + '%'
59
- }} ></div>
60
-
61
-
62
-
63
-
64
- {/if}
65
-
66
-
67
-
68
- {#if builderBlock?.children?.length && fitContent }
69
-
70
-
71
- <slot></slot>
72
-
73
-
74
-
75
-
76
- {/if}
77
-
78
-
79
-
80
-
81
- {#if !fitContent }
82
-
83
-
84
- <div class="div-3" >
85
-
86
- <slot></slot>
87
-
88
- </div>
89
-
90
-
91
-
92
-
93
- {/if}
94
-
95
- </div>
96
-
97
- <style>
98
- .div {
99
- position: relative; }.img {
100
- opacity: 1;
101
- transition: opacity 0.2s ease-in-out;
102
- position: absolute;
103
- height: 100%;
104
- width: 100%;
105
- top: 0px;
106
- left: 0px; }.div-2 {
107
- width: 100%;
108
- pointer-events: none;
109
- font-size: 0; }.div-3 {
110
- display: flex;
111
- flex-direction: column;
112
- align-items: stretch;
113
- position: absolute;
114
- top: 0;
115
- left: 0;
116
- width: 100%;
117
- height: 100%; }
118
- </style>
2
+ import { getSrcSet } from "./image.helpers";
3
+
4
+ export let image;
5
+ export let src;
6
+ export let srcset;
7
+ export let noWebp;
8
+ export let altText;
9
+ export let backgroundSize;
10
+ export let className;
11
+ export let sizes;
12
+ export let aspectRatio;
13
+ export let fitContent;
14
+ export let builderBlock;
15
+
16
+ function mitosis_styling(node, vars) {
17
+ Object.entries(vars).forEach(([p, v]) => {
18
+ node.style[p] = v;
19
+ });
20
+ }
21
+
22
+ $: srcSetToUse = () => {
23
+ const imageToUse = image || src;
24
+ const url = imageToUse;
25
+
26
+ if (
27
+ !url || // We can auto add srcset for cdn.builder.io and shopify
28
+ // images, otherwise you can supply this prop manually
29
+ !(url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/))
30
+ ) {
31
+ return srcset;
32
+ }
33
+
34
+ if (srcset && image?.includes("builder.io/api/v1/image")) {
35
+ if (!srcset.includes(image.split("?")[0])) {
36
+ console.debug("Removed given srcset");
37
+ return getSrcSet(url);
38
+ }
39
+ } else if (image && !srcset) {
40
+ return getSrcSet(url);
41
+ }
42
+
43
+ return getSrcSet(url);
44
+ };
45
+ </script>
46
+
47
+ <div class="div">
48
+ <picture>
49
+ {#if srcSetToUse?.()?.match(/builder\.io/) && !noWebp}
50
+ <source
51
+ type="image/webp"
52
+ srcset={srcSetToUse?.()?.replace(/\?/g, "?format=webp&")}
53
+ />
54
+ {/if}
55
+
56
+ <img
57
+ use:mitosis_styling={{
58
+ objectPosition: backgroundSize || "center",
59
+ objectFit: backgroundSize || "cover",
60
+ }}
61
+ loading="lazy"
62
+ alt={altText}
63
+ role={altText ? "presentation" : undefined}
64
+ class={"builder-image" + (className ? " " + className : "") + " img"}
65
+ src={image}
66
+ srcset={srcSetToUse()}
67
+ {sizes}
68
+ />
69
+
70
+ <source srcset={srcSetToUse()} />
71
+ </picture>
72
+
73
+ {#if aspectRatio && !(fitContent && builderBlock?.children?.length)}
74
+ <div
75
+ use:mitosis_styling={{
76
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
77
+ paddingTop: aspectRatio * 100 + "%",
78
+ }}
79
+ class="builder-image-sizer div-2"
80
+ />
81
+ {/if}
82
+
83
+ {#if builderBlock?.children?.length && fitContent}
84
+ <slot />
85
+ {/if}
86
+
87
+ {#if !fitContent}
88
+ <div class="div-3">
89
+ <slot />
90
+ </div>
91
+ {/if}
92
+ </div>
93
+
94
+ <style>
95
+ .div {
96
+ position: relative;
97
+ }
98
+ .img {
99
+ opacity: 1;
100
+ transition: opacity 0.2s ease-in-out;
101
+ position: absolute;
102
+ height: 100%;
103
+ width: 100%;
104
+ top: 0px;
105
+ left: 0px;
106
+ }
107
+ .div-2 {
108
+ width: 100%;
109
+ pointer-events: none;
110
+ font-size: 0;
111
+ }
112
+ .div-3 {
113
+ display: flex;
114
+ flex-direction: column;
115
+ align-items: stretch;
116
+ position: absolute;
117
+ top: 0;
118
+ left: 0;
119
+ width: 100%;
120
+ height: 100%;
121
+ }
122
+ </style>
@@ -1,36 +1,26 @@
1
1
  <script>
2
-
3
-
4
-
5
-
6
- import { isEditing } from '../../functions/is-editing.js';
7
-
8
-
2
+ import { isEditing } from "../../functions/is-editing.js";
9
3
 
10
-
4
+ export let backgroundSize;
5
+ export let backgroundPosition;
6
+ export let attributes;
7
+ export let imgSrc;
8
+ export let altText;
11
9
 
12
-
13
- export let backgroundSize;
14
- export let backgroundPosition;
15
- export let attributes;
16
- export let imgSrc;
17
- export let altText;
18
-
19
-
20
-
10
+ function mitosis_styling(node, vars) {
11
+ Object.entries(vars).forEach(([p, v]) => {
12
+ node.style[p] = v;
13
+ });
14
+ }
15
+ </script>
21
16
 
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
- </script>
32
-
33
- <img {...attributes} style={{
34
- objectFit: backgroundSize || 'cover',
35
- objectPosition: backgroundPosition || 'center'
36
- }} key={isEditing() && imgSrc || 'default-key'} alt={altText} src={imgSrc} />
17
+ <img
18
+ {...attributes}
19
+ use:mitosis_styling={{
20
+ objectFit: backgroundSize || "cover",
21
+ objectPosition: backgroundPosition || "center",
22
+ }}
23
+ key={(isEditing() && imgSrc) || "default-key"}
24
+ alt={altText}
25
+ src={imgSrc}
26
+ />
@@ -1,35 +1,22 @@
1
1
  <script>
2
-
3
-
4
-
5
-
6
- import { isEditing } from '../../functions/is-editing.js';
2
+ import { isEditing } from "../../functions/is-editing.js";
7
3
 
8
-
9
-
10
-
11
-
12
-
13
4
  export let attributes;
14
- export let defaultValue;
15
- export let placeholder;
16
- export let type;
17
- export let name;
18
- export let value;
19
- export let required;
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
5
+ export let defaultValue;
6
+ export let placeholder;
7
+ export let type;
8
+ export let name;
9
+ export let value;
10
+ export let required;
33
11
  </script>
34
12
 
35
- <input {...attributes} key={isEditing() && defaultValue ? defaultValue : 'default-key'} placeholder={placeholder} type={type} name={name} value={value} defaultValue={defaultValue} required={required} />
13
+ <input
14
+ {...attributes}
15
+ key={isEditing() && defaultValue ? defaultValue : "default-key"}
16
+ {placeholder}
17
+ {type}
18
+ {name}
19
+ {value}
20
+ {defaultValue}
21
+ {required}
22
+ />
@@ -1,30 +1,8 @@
1
1
  <script>
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
2
  export let attributes;
14
- export let text;
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
3
+ export let text;
28
4
  </script>
29
5
 
30
- <span class={attributes?.class || attributes?.className} >{@html text || ''}</span>
6
+ <span class={attributes?.class || attributes?.className}
7
+ >{@html text || ""}</span
8
+ >
@@ -1,37 +1,21 @@
1
1
  <script>
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
- export let attributes;
14
- export let maxWidth;
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
- </script>
30
-
31
- <section {...attributes} style={maxWidth && typeof maxWidth === 'number' ? {
32
- maxWidth: maxWidth
33
- } : undefined} >
34
-
35
- <slot></slot>
36
-
37
- </section>
2
+ export let attributes;
3
+ export let maxWidth;
4
+
5
+ function mitosis_styling(node, vars) {
6
+ Object.entries(vars).forEach(([p, v]) => {
7
+ node.style[p] = v;
8
+ });
9
+ }
10
+ </script>
11
+
12
+ <section
13
+ {...attributes}
14
+ use:mitosis_styling={maxWidth && typeof maxWidth === "number"
15
+ ? {
16
+ maxWidth: maxWidth,
17
+ }
18
+ : undefined}
19
+ >
20
+ <slot />
21
+ </section>
@@ -1,41 +1,21 @@
1
1
  <script>
2
-
3
-
4
-
5
-
6
- import { isEditing } from '../../functions/is-editing.js';
2
+ import { isEditing } from "../../functions/is-editing.js";
7
3
 
8
-
9
-
10
-
11
-
12
-
13
4
  export let attributes;
14
- export let value;
15
- export let defaultValue;
16
- export let name;
17
- export let options;
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
5
+ export let value;
6
+ export let defaultValue;
7
+ export let name;
8
+ export let options;
31
9
  </script>
32
10
 
33
- <select {...attributes} value={value} key={isEditing() && defaultValue ? defaultValue : 'default-key'} defaultValue={defaultValue} name={name} >
34
-
35
-
36
- {#each options as option, index }
37
- <option value={option.value} >{option.name || option.value}</option>
38
- {/each}
39
-
40
-
41
- </select>
11
+ <select
12
+ {...attributes}
13
+ {value}
14
+ key={isEditing() && defaultValue ? defaultValue : "default-key"}
15
+ {defaultValue}
16
+ {name}
17
+ >
18
+ {#each options as option, undefined}
19
+ <option value={option.value}>{option.name || option.value}</option>
20
+ {/each}
21
+ </select>
@@ -1,34 +1,8 @@
1
1
  <script>
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
2
  export let attributes;
14
- export let text;
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
3
+ export let text;
28
4
  </script>
29
5
 
30
- <button {...attributes} type="submit" >
31
-
32
- {text}
33
-
34
- </button>
6
+ <button {...attributes} type="submit">
7
+ {text}
8
+ </button>