@builder.io/sdk-svelte 0.0.1-24 → 0.0.1-27

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-svelte",
3
3
  "description": "Builder.io SDK for Svelte",
4
- "version": "0.0.1-24",
4
+ "version": "0.0.1-27",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "src"
@@ -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 srcSetToUse?.()?.match(/builder\.io/) && !noWebp}
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
@@ -57,6 +57,7 @@
57
57
  <RenderContent
58
58
  apiKey={builderContext.apiKey}
59
59
  context={builderContext.context}
60
+ customComponents={Object.values(builderContext.registeredComponents)}
60
61
  data={{
61
62
  ...symbol?.data,
62
63
  ...builderContext.state,
@@ -181,7 +181,9 @@
181
181
  block={data.block}
182
182
  />
183
183
  {/each}
184
- {:else}
184
+ {/if}
185
+
186
+ {#if !repeatItemData()}
185
187
  <RenderComponent {...renderComponentProps()} />
186
188
  {/if}
187
189
 
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
- if (model && previewingModelName() === model) {
211
- const searchParams = new URL(location.href).searchParams;
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
- data-builder-content-id={useContent?.()?.id}
269
+ builder-content-id={useContent?.()?.id}
269
270
  >
270
- {#if (useContent?.()?.data?.cssCode || useContent?.()?.data?.customFonts?.length) && TARGET !== "reactNative"}
271
+ {#if shouldRenderContentStyles()}
271
272
  <RenderContentStyles
272
- cssCode={useContent().data.cssCode}
273
- customFonts={useContent().data.customFonts}
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
- if (options.options) {
60
- const flattened = flatten(options.options);
61
- for (const key in flattened) {
62
- url.searchParams.set(key, String(flattened[key]));
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 flattened = flatten({ query });
70
- for (const key in flattened) {
71
- url.searchParams.set(key, JSON.stringify(flattened[key]));
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
- };