@builder.io/sdk-svelte 0.0.9-2 → 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 +4 -1
- package/package/functions/get-content/index.d.ts +3 -0
- package/package/functions/get-content/index.js +4 -2
- 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 +4 -2
- package/src/functions/get-content/index.ts +12 -3
- 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
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isBrowser } from '../is-browser.js';
|
|
2
2
|
const BUILDER_SEARCHPARAMS_PREFIX = 'builder.';
|
|
3
|
+
const BUILDER_OPTIONS_PREFIX = 'options.';
|
|
3
4
|
export const convertSearchParamsToQueryObject = (searchParams) => {
|
|
4
5
|
const options = {};
|
|
5
6
|
searchParams.forEach((value, key) => {
|
|
@@ -15,7 +16,9 @@ export const getBuilderSearchParams = (_options) => {
|
|
|
15
16
|
const newOptions = {};
|
|
16
17
|
Object.keys(options).forEach((key) => {
|
|
17
18
|
if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
|
|
18
|
-
const trimmedKey = key
|
|
19
|
+
const trimmedKey = key
|
|
20
|
+
.replace(BUILDER_SEARCHPARAMS_PREFIX, '')
|
|
21
|
+
.replace(BUILDER_OPTIONS_PREFIX, '');
|
|
19
22
|
newOptions[trimmedKey] = options[key];
|
|
20
23
|
}
|
|
21
24
|
});
|
|
@@ -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
|
}
|
|
@@ -6,7 +6,7 @@ export async function getContent(options) {
|
|
|
6
6
|
return (await getAllContent({ ...options, limit: 1 })).results[0] || null;
|
|
7
7
|
}
|
|
8
8
|
export const generateContentUrl = (options) => {
|
|
9
|
-
const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey, includeRefs = true, locale } = options;
|
|
9
|
+
const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey, includeRefs = true, locale, } = options;
|
|
10
10
|
if (!apiKey) {
|
|
11
11
|
throw new Error('Missing API key');
|
|
12
12
|
}
|
|
@@ -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%;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isBrowser } from '../is-browser.js';
|
|
2
2
|
|
|
3
3
|
const BUILDER_SEARCHPARAMS_PREFIX = 'builder.';
|
|
4
|
-
|
|
4
|
+
const BUILDER_OPTIONS_PREFIX = 'options.';
|
|
5
5
|
type QueryObject = Record<string, string | string[]>;
|
|
6
6
|
|
|
7
7
|
export const convertSearchParamsToQueryObject = (
|
|
@@ -25,7 +25,9 @@ export const getBuilderSearchParams = (
|
|
|
25
25
|
const newOptions: QueryObject = {};
|
|
26
26
|
Object.keys(options).forEach((key) => {
|
|
27
27
|
if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
|
|
28
|
-
const trimmedKey = key
|
|
28
|
+
const trimmedKey = key
|
|
29
|
+
.replace(BUILDER_SEARCHPARAMS_PREFIX, '')
|
|
30
|
+
.replace(BUILDER_OPTIONS_PREFIX, '');
|
|
29
31
|
newOptions[trimmedKey] = options[key];
|
|
30
32
|
}
|
|
31
33
|
});
|
|
@@ -24,7 +24,7 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
|
|
|
24
24
|
model,
|
|
25
25
|
apiKey,
|
|
26
26
|
includeRefs = true,
|
|
27
|
-
locale
|
|
27
|
+
locale,
|
|
28
28
|
} = options;
|
|
29
29
|
|
|
30
30
|
if (!apiKey) {
|
|
@@ -32,7 +32,9 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const url = new URL(
|
|
35
|
-
`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${
|
|
35
|
+
`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${
|
|
36
|
+
locale ? `&locale=${locale}` : ''
|
|
37
|
+
}`
|
|
36
38
|
);
|
|
37
39
|
|
|
38
40
|
const queryOptions = {
|
|
@@ -58,6 +60,9 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
|
|
|
58
60
|
return url;
|
|
59
61
|
};
|
|
60
62
|
|
|
63
|
+
/**
|
|
64
|
+
* TO-DO: Handle error responses.
|
|
65
|
+
*/
|
|
61
66
|
interface ContentResponse {
|
|
62
67
|
results: BuilderContent[];
|
|
63
68
|
}
|
|
@@ -73,7 +78,11 @@ export async function getAllContent(
|
|
|
73
78
|
);
|
|
74
79
|
|
|
75
80
|
const canTrack = options.canTrack !== false;
|
|
76
|
-
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
|
+
) {
|
|
77
86
|
for (const item of content.results) {
|
|
78
87
|
await handleABTesting({ item, canTrack });
|
|
79
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
|
}
|