@builder.io/sdk-svelte 0.0.1-25 → 0.0.1-28
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.json +1 -1
- package/src/blocks/image/image.svelte +10 -5
- package/src/blocks/video/video.svelte +36 -10
- package/src/components/render-block/render-block.svelte +3 -1
- package/src/components/render-block/types.js +0 -0
- package/src/components/render-content/render-content.svelte +15 -14
- package/src/functions/get-builder-search-params/index.js +12 -1
- package/src/functions/get-content/index.js +11 -8
- package/src/functions/previewing-model-name.js +0 -11
package/package.json
CHANGED
|
@@ -42,15 +42,20 @@
|
|
|
42
42
|
|
|
43
43
|
return getSrcSet(url);
|
|
44
44
|
};
|
|
45
|
+
|
|
46
|
+
$: webpSrcSet = () => {
|
|
47
|
+
if (srcSetToUse?.()?.match(/builder\.io/) && !noWebp) {
|
|
48
|
+
return srcSetToUse().replace(/\?/g, "?format=webp&");
|
|
49
|
+
} else {
|
|
50
|
+
return "";
|
|
51
|
+
}
|
|
52
|
+
};
|
|
45
53
|
</script>
|
|
46
54
|
|
|
47
55
|
<div class="div">
|
|
48
56
|
<picture>
|
|
49
|
-
{#if
|
|
50
|
-
<source
|
|
51
|
-
type="image/webp"
|
|
52
|
-
srcset={srcSetToUse?.()?.replace(/\?/g, "?format=webp&")}
|
|
53
|
-
/>
|
|
57
|
+
{#if webpSrcSet()}
|
|
58
|
+
<source type="image/webp" srcset={webpSrcSet()} />
|
|
54
59
|
{/if}
|
|
55
60
|
|
|
56
61
|
<img
|
|
@@ -1,23 +1,54 @@
|
|
|
1
1
|
<script>
|
|
2
|
+
export let autoPlay;
|
|
3
|
+
export let muted;
|
|
4
|
+
export let controls;
|
|
5
|
+
export let loop;
|
|
6
|
+
export let playsInline;
|
|
2
7
|
export let attributes;
|
|
3
8
|
export let fit;
|
|
4
9
|
export let position;
|
|
5
10
|
export let video;
|
|
6
11
|
export let posterImage;
|
|
7
|
-
export let autoPlay;
|
|
8
|
-
export let muted;
|
|
9
|
-
export let controls;
|
|
10
|
-
export let loop;
|
|
11
12
|
|
|
12
13
|
function mitosis_styling(node, vars) {
|
|
13
14
|
Object.entries(vars).forEach(([p, v]) => {
|
|
14
15
|
node.style[p] = v;
|
|
15
16
|
});
|
|
16
17
|
}
|
|
18
|
+
|
|
19
|
+
$: videoProps = () => {
|
|
20
|
+
return {
|
|
21
|
+
...(autoPlay === true
|
|
22
|
+
? {
|
|
23
|
+
autoPlay: true,
|
|
24
|
+
}
|
|
25
|
+
: {}),
|
|
26
|
+
...(muted === true
|
|
27
|
+
? {
|
|
28
|
+
muted: true,
|
|
29
|
+
}
|
|
30
|
+
: {}),
|
|
31
|
+
...(controls === true
|
|
32
|
+
? {
|
|
33
|
+
controls: true,
|
|
34
|
+
}
|
|
35
|
+
: {}),
|
|
36
|
+
...(loop === true
|
|
37
|
+
? {
|
|
38
|
+
loop: true,
|
|
39
|
+
}
|
|
40
|
+
: {}),
|
|
41
|
+
...(playsInline === true
|
|
42
|
+
? {
|
|
43
|
+
playsInline: true,
|
|
44
|
+
}
|
|
45
|
+
: {}),
|
|
46
|
+
};
|
|
47
|
+
};
|
|
17
48
|
</script>
|
|
18
49
|
|
|
19
50
|
<video
|
|
20
|
-
{...
|
|
51
|
+
{...videoProps()}
|
|
21
52
|
use:mitosis_styling={{
|
|
22
53
|
width: "100%",
|
|
23
54
|
height: "100%",
|
|
@@ -28,11 +59,6 @@
|
|
|
28
59
|
// not have the video overflow
|
|
29
60
|
borderRadius: 1,
|
|
30
61
|
}}
|
|
31
|
-
preload="none"
|
|
32
62
|
src={video || "no-src"}
|
|
33
63
|
poster={posterImage}
|
|
34
|
-
{autoPlay}
|
|
35
|
-
{muted}
|
|
36
|
-
{controls}
|
|
37
|
-
{loop}
|
|
38
64
|
/>
|
|
File without changes
|
|
@@ -7,16 +7,11 @@
|
|
|
7
7
|
import { TARGET } from "../../constants/target.js";
|
|
8
8
|
import BuilderContext from "../../context/builder.context";
|
|
9
9
|
import { evaluate } from "../../functions/evaluate.js";
|
|
10
|
-
import {
|
|
11
|
-
convertSearchParamsToQueryObject,
|
|
12
|
-
getBuilderSearchParams,
|
|
13
|
-
} from "../../functions/get-builder-search-params/index.js";
|
|
14
10
|
import { getContent } from "../../functions/get-content/index.js";
|
|
15
11
|
import { getFetch } from "../../functions/get-fetch.js";
|
|
16
12
|
import { isBrowser } from "../../functions/is-browser.js";
|
|
17
13
|
import { isEditing } from "../../functions/is-editing.js";
|
|
18
14
|
import { isPreviewing } from "../../functions/is-previewing.js";
|
|
19
|
-
import { previewingModelName } from "../../functions/previewing-model-name.js";
|
|
20
15
|
import {
|
|
21
16
|
components,
|
|
22
17
|
createRegisterComponentMessage,
|
|
@@ -163,6 +158,14 @@
|
|
|
163
158
|
return {};
|
|
164
159
|
};
|
|
165
160
|
|
|
161
|
+
$: shouldRenderContentStyles = () => {
|
|
162
|
+
return Boolean(
|
|
163
|
+
(useContent?.()?.data?.cssCode ||
|
|
164
|
+
useContent?.()?.data?.customFonts?.length) &&
|
|
165
|
+
TARGET !== "reactNative"
|
|
166
|
+
);
|
|
167
|
+
};
|
|
168
|
+
|
|
166
169
|
setContext(BuilderContext.key, {
|
|
167
170
|
get content() {
|
|
168
171
|
return useContent();
|
|
@@ -207,8 +210,9 @@
|
|
|
207
210
|
} // override normal content in preview mode
|
|
208
211
|
|
|
209
212
|
if (isPreviewing()) {
|
|
210
|
-
|
|
211
|
-
|
|
213
|
+
const searchParams = new URL(location.href).searchParams;
|
|
214
|
+
|
|
215
|
+
if (model && searchParams.get("builder.preview") === model) {
|
|
212
216
|
const previewApiKey =
|
|
213
217
|
searchParams.get("apiKey") || searchParams.get("builder.space");
|
|
214
218
|
|
|
@@ -216,9 +220,6 @@
|
|
|
216
220
|
getContent({
|
|
217
221
|
model: model,
|
|
218
222
|
apiKey: previewApiKey,
|
|
219
|
-
options: getBuilderSearchParams(
|
|
220
|
-
convertSearchParamsToQueryObject(searchParams)
|
|
221
|
-
),
|
|
222
223
|
}).then((content) => {
|
|
223
224
|
if (content) {
|
|
224
225
|
overrideContent = content;
|
|
@@ -265,12 +266,12 @@
|
|
|
265
266
|
contentId: useContent().id,
|
|
266
267
|
});
|
|
267
268
|
}}
|
|
268
|
-
|
|
269
|
+
builder-content-id={useContent?.()?.id}
|
|
269
270
|
>
|
|
270
|
-
{#if (
|
|
271
|
+
{#if shouldRenderContentStyles()}
|
|
271
272
|
<RenderContentStyles
|
|
272
|
-
cssCode={useContent()
|
|
273
|
-
customFonts={useContent()
|
|
273
|
+
cssCode={useContent?.()?.data?.cssCode}
|
|
274
|
+
customFonts={useContent?.()?.data?.customFonts}
|
|
274
275
|
/>
|
|
275
276
|
{/if}
|
|
276
277
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isBrowser } from "../is-browser";
|
|
1
2
|
const BUILDER_SEARCHPARAMS_PREFIX = "builder.";
|
|
2
3
|
const convertSearchParamsToQueryObject = (searchParams) => {
|
|
3
4
|
const options = {};
|
|
@@ -16,7 +17,17 @@ const getBuilderSearchParams = (options) => {
|
|
|
16
17
|
});
|
|
17
18
|
return newOptions;
|
|
18
19
|
};
|
|
20
|
+
const getBuilderSearchParamsFromWindow = () => {
|
|
21
|
+
if (!isBrowser()) {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
25
|
+
return getBuilderSearchParams(convertSearchParamsToQueryObject(searchParams));
|
|
26
|
+
};
|
|
27
|
+
const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
|
|
19
28
|
export {
|
|
20
29
|
convertSearchParamsToQueryObject,
|
|
21
|
-
getBuilderSearchParams
|
|
30
|
+
getBuilderSearchParams,
|
|
31
|
+
getBuilderSearchParamsFromWindow,
|
|
32
|
+
normalizeSearchParams
|
|
22
33
|
};
|
|
@@ -38,6 +38,10 @@ var __async = (__this, __arguments, generator) => {
|
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
40
|
import { flatten } from "../../helpers/flatten.js";
|
|
41
|
+
import {
|
|
42
|
+
getBuilderSearchParamsFromWindow,
|
|
43
|
+
normalizeSearchParams
|
|
44
|
+
} from "../get-builder-search-params/index.js";
|
|
41
45
|
import { getFetch } from "../get-fetch.js";
|
|
42
46
|
import { handleABTesting } from "./ab-testing.js";
|
|
43
47
|
const fetch$ = getFetch();
|
|
@@ -56,19 +60,18 @@ const generateContentUrl = (options) => {
|
|
|
56
60
|
apiKey
|
|
57
61
|
} = options;
|
|
58
62
|
const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}`);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
63
|
+
const queryOptions = __spreadValues(__spreadValues({}, getBuilderSearchParamsFromWindow()), normalizeSearchParams(options.options || {}));
|
|
64
|
+
const flattened = flatten(queryOptions);
|
|
65
|
+
for (const key in flattened) {
|
|
66
|
+
url.searchParams.set(key, String(flattened[key]));
|
|
64
67
|
}
|
|
65
68
|
if (userAttributes) {
|
|
66
69
|
url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
|
|
67
70
|
}
|
|
68
71
|
if (query) {
|
|
69
|
-
const
|
|
70
|
-
for (const key in
|
|
71
|
-
url.searchParams.set(key, JSON.stringify(
|
|
72
|
+
const flattened2 = flatten({ query });
|
|
73
|
+
for (const key in flattened2) {
|
|
74
|
+
url.searchParams.set(key, JSON.stringify(flattened2[key]));
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
77
|
return url;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { isPreviewing } from "./is-previewing.js";
|
|
2
|
-
function previewingModelName() {
|
|
3
|
-
if (!isPreviewing()) {
|
|
4
|
-
return null;
|
|
5
|
-
}
|
|
6
|
-
const url = new URL(location.href);
|
|
7
|
-
return url.searchParams.get("builder.preview");
|
|
8
|
-
}
|
|
9
|
-
export {
|
|
10
|
-
previewingModelName
|
|
11
|
-
};
|