@builder.io/sdk-svelte 0.0.9-3 → 0.0.9
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.
- package/package/--package.json +1 -1
- package/package/blocks/image/image.svelte +15 -7
- package/package/blocks/image/image.svelte.d.ts +2 -1
- package/package/functions/get-builder-search-params/index.js +1 -1
- package/package/functions/get-content/index.d.ts +3 -0
- package/package/functions/get-content/index.js +3 -1
- package/package/functions/get-content/types.d.ts +1 -1
- package/package.json +1 -1
- package/src/blocks/image/image.svelte +15 -7
- package/src/functions/get-builder-search-params/index.ts +1 -1
- package/src/functions/get-content/index.ts +8 -1
- package/src/functions/get-content/types.ts +1 -1
package/package/--package.json
CHANGED
|
@@ -5,11 +5,12 @@ export let image;
|
|
|
5
5
|
export let src;
|
|
6
6
|
export let srcset;
|
|
7
7
|
export let noWebp;
|
|
8
|
+
export let aspectRatio;
|
|
8
9
|
export let altText;
|
|
10
|
+
export let backgroundPosition;
|
|
9
11
|
export let backgroundSize;
|
|
10
12
|
export let className;
|
|
11
13
|
export let sizes;
|
|
12
|
-
export let aspectRatio;
|
|
13
14
|
export let builderBlock;
|
|
14
15
|
export let fitContent;
|
|
15
16
|
function mitosis_styling(node, vars) {
|
|
@@ -50,6 +51,17 @@ $: webpSrcSet = () => {
|
|
|
50
51
|
return "";
|
|
51
52
|
}
|
|
52
53
|
};
|
|
54
|
+
$: aspectRatioCss = () => {
|
|
55
|
+
const aspectRatioStyles = {
|
|
56
|
+
position: "absolute",
|
|
57
|
+
height: "100%",
|
|
58
|
+
width: "100%",
|
|
59
|
+
left: "0px",
|
|
60
|
+
top: "0px",
|
|
61
|
+
};
|
|
62
|
+
const out = aspectRatio ? aspectRatioStyles : undefined;
|
|
63
|
+
return out;
|
|
64
|
+
};
|
|
53
65
|
</script>
|
|
54
66
|
|
|
55
67
|
<picture>
|
|
@@ -58,8 +70,9 @@ $: webpSrcSet = () => {
|
|
|
58
70
|
{/if}
|
|
59
71
|
<img
|
|
60
72
|
use:mitosis_styling={{
|
|
61
|
-
objectPosition:
|
|
73
|
+
objectPosition: backgroundPosition || "center",
|
|
62
74
|
objectFit: backgroundSize || "cover",
|
|
75
|
+
...aspectRatioCss(),
|
|
63
76
|
}}
|
|
64
77
|
loading="lazy"
|
|
65
78
|
alt={altText}
|
|
@@ -97,11 +110,6 @@ $: webpSrcSet = () => {
|
|
|
97
110
|
.img {
|
|
98
111
|
opacity: 1;
|
|
99
112
|
transition: opacity 0.2s ease-in-out;
|
|
100
|
-
position: absolute;
|
|
101
|
-
height: 100%;
|
|
102
|
-
width: 100%;
|
|
103
|
-
top: 0px;
|
|
104
|
-
left: 0px;
|
|
105
113
|
}
|
|
106
114
|
.div {
|
|
107
115
|
width: 100%;
|
|
@@ -25,11 +25,12 @@ declare const __propDef: {
|
|
|
25
25
|
src: ImageProps["src"];
|
|
26
26
|
srcset: ImageProps["srcset"];
|
|
27
27
|
noWebp: ImageProps["noWebp"];
|
|
28
|
+
aspectRatio: ImageProps["aspectRatio"];
|
|
28
29
|
altText: ImageProps["altText"];
|
|
30
|
+
backgroundPosition: ImageProps["backgroundPosition"];
|
|
29
31
|
backgroundSize: ImageProps["backgroundSize"];
|
|
30
32
|
className: ImageProps["className"];
|
|
31
33
|
sizes: ImageProps["sizes"];
|
|
32
|
-
aspectRatio: ImageProps["aspectRatio"];
|
|
33
34
|
builderBlock: ImageProps["builderBlock"];
|
|
34
35
|
fitContent: ImageProps["fitContent"];
|
|
35
36
|
};
|
|
@@ -4,7 +4,7 @@ const BUILDER_OPTIONS_PREFIX = 'options.';
|
|
|
4
4
|
export const convertSearchParamsToQueryObject = (searchParams) => {
|
|
5
5
|
const options = {};
|
|
6
6
|
searchParams.forEach((value, key) => {
|
|
7
|
-
options[key
|
|
7
|
+
options[key] = value;
|
|
8
8
|
});
|
|
9
9
|
return options;
|
|
10
10
|
};
|
|
@@ -2,6 +2,9 @@ import type { BuilderContent } from '../../types/builder-content.js';
|
|
|
2
2
|
export declare type GetContentOptions = import('./types.js').GetContentOptions;
|
|
3
3
|
export declare function getContent(options: GetContentOptions): Promise<BuilderContent | null>;
|
|
4
4
|
export declare const generateContentUrl: (options: GetContentOptions) => URL;
|
|
5
|
+
/**
|
|
6
|
+
* TO-DO: Handle error responses.
|
|
7
|
+
*/
|
|
5
8
|
interface ContentResponse {
|
|
6
9
|
results: BuilderContent[];
|
|
7
10
|
}
|
|
@@ -35,7 +35,9 @@ export async function getAllContent(options) {
|
|
|
35
35
|
const fetch = await getFetch();
|
|
36
36
|
const content = await fetch(url.href).then((res) => res.json());
|
|
37
37
|
const canTrack = options.canTrack !== false;
|
|
38
|
-
if (canTrack
|
|
38
|
+
if (canTrack &&
|
|
39
|
+
// This makes sure we have a non-error response with the results array.
|
|
40
|
+
Array.isArray(content.results)) {
|
|
39
41
|
for (const item of content.results) {
|
|
40
42
|
await handleABTesting({ item, canTrack });
|
|
41
43
|
}
|
|
@@ -33,7 +33,7 @@ export interface GetContentOptions {
|
|
|
33
33
|
*/
|
|
34
34
|
includeRefs?: boolean;
|
|
35
35
|
/**
|
|
36
|
-
* If
|
|
36
|
+
* If provided, the API will auto-resolve localized objects to the value of this `locale` key.
|
|
37
37
|
*/
|
|
38
38
|
locale?: string;
|
|
39
39
|
}
|
package/package.json
CHANGED
|
@@ -28,11 +28,12 @@
|
|
|
28
28
|
export let src: ImageProps["src"];
|
|
29
29
|
export let srcset: ImageProps["srcset"];
|
|
30
30
|
export let noWebp: ImageProps["noWebp"];
|
|
31
|
+
export let aspectRatio: ImageProps["aspectRatio"];
|
|
31
32
|
export let altText: ImageProps["altText"];
|
|
33
|
+
export let backgroundPosition: ImageProps["backgroundPosition"];
|
|
32
34
|
export let backgroundSize: ImageProps["backgroundSize"];
|
|
33
35
|
export let className: ImageProps["className"];
|
|
34
36
|
export let sizes: ImageProps["sizes"];
|
|
35
|
-
export let aspectRatio: ImageProps["aspectRatio"];
|
|
36
37
|
export let builderBlock: ImageProps["builderBlock"];
|
|
37
38
|
export let fitContent: ImageProps["fitContent"];
|
|
38
39
|
|
|
@@ -74,6 +75,17 @@
|
|
|
74
75
|
return "";
|
|
75
76
|
}
|
|
76
77
|
};
|
|
78
|
+
$: aspectRatioCss = () => {
|
|
79
|
+
const aspectRatioStyles = {
|
|
80
|
+
position: "absolute",
|
|
81
|
+
height: "100%",
|
|
82
|
+
width: "100%",
|
|
83
|
+
left: "0px",
|
|
84
|
+
top: "0px",
|
|
85
|
+
};
|
|
86
|
+
const out = aspectRatio ? aspectRatioStyles : undefined;
|
|
87
|
+
return out;
|
|
88
|
+
};
|
|
77
89
|
</script>
|
|
78
90
|
|
|
79
91
|
<picture>
|
|
@@ -82,8 +94,9 @@
|
|
|
82
94
|
{/if}
|
|
83
95
|
<img
|
|
84
96
|
use:mitosis_styling={{
|
|
85
|
-
objectPosition:
|
|
97
|
+
objectPosition: backgroundPosition || "center",
|
|
86
98
|
objectFit: backgroundSize || "cover",
|
|
99
|
+
...aspectRatioCss(),
|
|
87
100
|
}}
|
|
88
101
|
loading="lazy"
|
|
89
102
|
alt={altText}
|
|
@@ -121,11 +134,6 @@
|
|
|
121
134
|
.img {
|
|
122
135
|
opacity: 1;
|
|
123
136
|
transition: opacity 0.2s ease-in-out;
|
|
124
|
-
position: absolute;
|
|
125
|
-
height: 100%;
|
|
126
|
-
width: 100%;
|
|
127
|
-
top: 0px;
|
|
128
|
-
left: 0px;
|
|
129
137
|
}
|
|
130
138
|
.div {
|
|
131
139
|
width: 100%;
|
|
@@ -9,7 +9,7 @@ export const convertSearchParamsToQueryObject = (
|
|
|
9
9
|
): QueryObject => {
|
|
10
10
|
const options: Record<string, string> = {};
|
|
11
11
|
searchParams.forEach((value, key) => {
|
|
12
|
-
options[key
|
|
12
|
+
options[key] = value;
|
|
13
13
|
});
|
|
14
14
|
return options;
|
|
15
15
|
};
|
|
@@ -60,6 +60,9 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
|
|
|
60
60
|
return url;
|
|
61
61
|
};
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* TO-DO: Handle error responses.
|
|
65
|
+
*/
|
|
63
66
|
interface ContentResponse {
|
|
64
67
|
results: BuilderContent[];
|
|
65
68
|
}
|
|
@@ -75,7 +78,11 @@ export async function getAllContent(
|
|
|
75
78
|
);
|
|
76
79
|
|
|
77
80
|
const canTrack = options.canTrack !== false;
|
|
78
|
-
if (
|
|
81
|
+
if (
|
|
82
|
+
canTrack &&
|
|
83
|
+
// This makes sure we have a non-error response with the results array.
|
|
84
|
+
Array.isArray(content.results)
|
|
85
|
+
) {
|
|
79
86
|
for (const item of content.results) {
|
|
80
87
|
await handleABTesting({ item, canTrack });
|
|
81
88
|
}
|
|
@@ -40,7 +40,7 @@ export interface GetContentOptions {
|
|
|
40
40
|
includeRefs?: boolean;
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
-
* If
|
|
43
|
+
* If provided, the API will auto-resolve localized objects to the value of this `locale` key.
|
|
44
44
|
*/
|
|
45
45
|
locale?: string;
|
|
46
46
|
}
|