@builder.io/sdk-svelte 1.0.4 → 1.0.8

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 (55) hide show
  1. package/lib/browser/components/blocks/blocks.svelte +3 -2
  2. package/lib/browser/components/content/components/enable-editor.svelte +8 -4
  3. package/lib/browser/constants/sdk-version.d.ts +1 -1
  4. package/lib/browser/constants/sdk-version.js +1 -1
  5. package/lib/browser/functions/get-builder-search-params/index.d.ts +1 -4
  6. package/lib/browser/functions/get-builder-search-params/index.js +1 -8
  7. package/lib/browser/functions/get-content/generate-content-url.js +2 -1
  8. package/lib/browser/functions/is-editing.d.ts +2 -1
  9. package/lib/browser/functions/is-editing.js +3 -2
  10. package/lib/browser/functions/is-previewing.d.ts +2 -1
  11. package/lib/browser/functions/is-previewing.js +5 -3
  12. package/lib/browser/helpers/search/search.d.ts +5 -0
  13. package/lib/browser/helpers/search/search.js +17 -0
  14. package/lib/browser/index.d.ts +5 -2
  15. package/lib/browser/index.js +5 -2
  16. package/lib/edge/components/blocks/blocks.svelte +3 -2
  17. package/lib/edge/components/content/components/enable-editor.svelte +8 -4
  18. package/lib/edge/constants/sdk-version.d.ts +1 -1
  19. package/lib/edge/constants/sdk-version.js +1 -1
  20. package/lib/edge/functions/get-builder-search-params/index.d.ts +1 -4
  21. package/lib/edge/functions/get-builder-search-params/index.js +1 -8
  22. package/lib/edge/functions/get-content/generate-content-url.js +2 -1
  23. package/lib/edge/functions/is-editing.d.ts +2 -1
  24. package/lib/edge/functions/is-editing.js +3 -2
  25. package/lib/edge/functions/is-previewing.d.ts +2 -1
  26. package/lib/edge/functions/is-previewing.js +5 -3
  27. package/lib/edge/helpers/search/search.d.ts +5 -0
  28. package/lib/edge/helpers/search/search.js +17 -0
  29. package/lib/edge/index.d.ts +5 -2
  30. package/lib/edge/index.js +5 -2
  31. package/lib/node/components/blocks/blocks.svelte +3 -2
  32. package/lib/node/components/content/components/enable-editor.svelte +8 -4
  33. package/lib/node/constants/sdk-version.d.ts +1 -1
  34. package/lib/node/constants/sdk-version.js +1 -1
  35. package/lib/node/functions/get-builder-search-params/index.d.ts +1 -4
  36. package/lib/node/functions/get-builder-search-params/index.js +1 -8
  37. package/lib/node/functions/get-content/generate-content-url.js +2 -1
  38. package/lib/node/functions/is-editing.d.ts +2 -1
  39. package/lib/node/functions/is-editing.js +3 -2
  40. package/lib/node/functions/is-previewing.d.ts +2 -1
  41. package/lib/node/functions/is-previewing.js +5 -3
  42. package/lib/node/helpers/search/search.d.ts +5 -0
  43. package/lib/node/helpers/search/search.js +17 -0
  44. package/lib/node/index.d.ts +5 -2
  45. package/lib/node/index.js +5 -2
  46. package/package.json +1 -1
  47. package/src/components/blocks/blocks.svelte +3 -2
  48. package/src/components/content/components/enable-editor.svelte +8 -4
  49. package/src/constants/sdk-version.ts +1 -1
  50. package/src/functions/get-builder-search-params/index.ts +3 -10
  51. package/src/functions/get-content/generate-content-url.ts +2 -1
  52. package/src/functions/is-editing.ts +3 -2
  53. package/src/functions/is-previewing.ts +6 -3
  54. package/src/helpers/search/search.ts +18 -0
  55. package/src/index.ts +6 -2
@@ -19,8 +19,9 @@ let componentsContext = getContext(ComponentsContext.key);
19
19
  {parent}
20
20
  {path}
21
21
  {styleProp}
22
- BlocksWrapper={$context?.BlocksWrapper}
23
- BlocksWrapperProps={$context?.BlocksWrapperProps}
22
+ BlocksWrapper={$context?.BlocksWrapper || $builderContext.BlocksWrapper}
23
+ BlocksWrapperProps={$context?.BlocksWrapperProps ||
24
+ $builderContext.BlocksWrapperProps}
24
25
  >
25
26
  {#if blocks}
26
27
  {#each blocks as block (block.id)}
@@ -233,8 +233,10 @@ let httpReqsData = {};
233
233
  let clicked = false;
234
234
  onMount(() => {
235
235
  if (isBrowser()) {
236
- if (isEditing() && elementRef) {
237
- elementRef.dispatchEvent(new CustomEvent("initeditingbldr"));
236
+ if (isEditing()) {
237
+ if (elementRef) {
238
+ elementRef.dispatchEvent(new CustomEvent("initeditingbldr"));
239
+ }
238
240
  }
239
241
  const shouldTrackImpression = $builderContextSignal.content && getDefaultCanTrack(canTrack);
240
242
  if (shouldTrackImpression) {
@@ -250,8 +252,10 @@ onMount(() => {
250
252
  });
251
253
  }
252
254
  // override normal content in preview mode
253
- if (isPreviewing() && elementRef) {
254
- elementRef.dispatchEvent(new CustomEvent("initpreviewingbldr"));
255
+ if (isPreviewing()) {
256
+ if (elementRef) {
257
+ elementRef.dispatchEvent(new CustomEvent("initpreviewingbldr"));
258
+ }
255
259
  }
256
260
  }
257
261
  });
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.4";
1
+ export declare const SDK_VERSION = "1.0.8";
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.4";
1
+ export const SDK_VERSION = "1.0.8";
@@ -1,5 +1,4 @@
1
- type QueryObject = Record<string, string | string[]>;
2
- export declare const convertSearchParamsToQueryObject: (searchParams: URLSearchParams) => QueryObject;
1
+ import type { QueryObject } from '../../helpers/search/search.js';
3
2
  /**
4
3
  * Receives a `URLSearchParams` object or a regular query object, and returns the subset of query params that are
5
4
  * relevant to the Builder SDK.
@@ -8,5 +7,3 @@ export declare const convertSearchParamsToQueryObject: (searchParams: URLSearchP
8
7
  */
9
8
  export declare const getBuilderSearchParams: (_options: QueryObject | URLSearchParams | undefined) => QueryObject;
10
9
  export declare const getBuilderSearchParamsFromWindow: () => QueryObject;
11
- export declare const normalizeSearchParams: (searchParams: QueryObject | URLSearchParams) => QueryObject;
12
- export {};
@@ -1,13 +1,7 @@
1
+ import { normalizeSearchParams } from '../../helpers/search/search.js';
1
2
  import { isBrowser } from '../is-browser.js';
2
3
  const BUILDER_SEARCHPARAMS_PREFIX = 'builder.';
3
4
  const BUILDER_OPTIONS_PREFIX = 'options.';
4
- export const convertSearchParamsToQueryObject = (searchParams) => {
5
- const options = {};
6
- searchParams.forEach((value, key) => {
7
- options[key] = value;
8
- });
9
- return options;
10
- };
11
5
  /**
12
6
  * Receives a `URLSearchParams` object or a regular query object, and returns the subset of query params that are
13
7
  * relevant to the Builder SDK.
@@ -35,4 +29,3 @@ export const getBuilderSearchParamsFromWindow = () => {
35
29
  const searchParams = new URLSearchParams(window.location.search);
36
30
  return getBuilderSearchParams(searchParams);
37
31
  };
38
- export const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
@@ -1,6 +1,7 @@
1
1
  import { flatten } from '../../helpers/flatten.js';
2
+ import { normalizeSearchParams } from '../../helpers/search/search.js';
2
3
  import { DEFAULT_API_VERSION } from '../../types/api-version.js';
3
- import { getBuilderSearchParamsFromWindow, normalizeSearchParams } from '../get-builder-search-params/index.js';
4
+ import { getBuilderSearchParamsFromWindow } from '../get-builder-search-params/index.js';
4
5
  const isPositiveNumber = (thing) => typeof thing === 'number' && !isNaN(thing) && thing >= 0;
5
6
  export const generateContentUrl = (options) => {
6
7
  const { limit = 30, userAttributes, query, model, apiKey, enrich, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished } = options;
@@ -1 +1,2 @@
1
- export declare function isEditing(): boolean;
1
+ import { type Search } from '../helpers/search/search.js';
2
+ export declare function isEditing(search?: Search): boolean;
@@ -1,5 +1,6 @@
1
1
  import { TARGET } from '../constants/target.js';
2
+ import { getSearchString } from '../helpers/search/search.js';
2
3
  import { isIframe } from './is-iframe.js';
3
- export function isEditing() {
4
- return isIframe() && (TARGET === 'reactNative' || window.location.search.indexOf('builder.frameEditing=') !== -1);
4
+ export function isEditing(search) {
5
+ return isIframe() && (TARGET === 'reactNative' || getSearchString(search || window.location.search).indexOf('builder.frameEditing=') !== -1);
5
6
  }
@@ -1 +1,2 @@
1
- export declare function isPreviewing(): boolean;
1
+ import type { Search } from '../helpers/search/search.js';
2
+ export declare function isPreviewing(search?: Search): boolean;
@@ -1,11 +1,13 @@
1
+ import { getSearchString } from '../helpers/search/search.js';
1
2
  import { isBrowser } from './is-browser.js';
2
3
  import { isEditing } from './is-editing.js';
3
- export function isPreviewing() {
4
+ export function isPreviewing(search) {
4
5
  if (!isBrowser()) {
5
6
  return false;
6
7
  }
7
- if (isEditing()) {
8
+ const normalizedSearch = getSearchString(search || window.location.search);
9
+ if (isEditing(normalizedSearch)) {
8
10
  return false;
9
11
  }
10
- return Boolean(location.search.indexOf('builder.preview=') !== -1);
12
+ return Boolean(normalizedSearch.indexOf('builder.preview=') !== -1);
11
13
  }
@@ -0,0 +1,5 @@
1
+ export type QueryObject = Record<string, string | string[]>;
2
+ export declare const convertSearchParamsToQueryObject: (searchParams: URLSearchParams) => QueryObject;
3
+ export declare const normalizeSearchParams: (searchParams: QueryObject | URLSearchParams) => QueryObject;
4
+ export type Search = URLSearchParams | string | QueryObject;
5
+ export declare const getSearchString: (search: Search) => string;
@@ -0,0 +1,17 @@
1
+ export const convertSearchParamsToQueryObject = (searchParams) => {
2
+ const options = {};
3
+ searchParams.forEach((value, key) => {
4
+ options[key] = value;
5
+ });
6
+ return options;
7
+ };
8
+ export const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
9
+ export const getSearchString = (search) => {
10
+ if (typeof search === 'string') {
11
+ return search;
12
+ }
13
+ else if (search instanceof URLSearchParams) {
14
+ return search.toString();
15
+ }
16
+ return new URLSearchParams(search).toString();
17
+ };
@@ -1,7 +1,10 @@
1
1
  export * from './index-helpers/top-of-file.js';
2
+ /**
3
+ * In the React SDK, this file is marked with `use client`.
4
+ */
2
5
  export * from './index-helpers/blocks-exports.js';
3
6
  /**
4
- * We have a separate entry point to the SDKs that guarantees no components are being imported. This is useful
5
- * for React SDK, which would break in the NextJS App directory because the component imports have `use client` in them.
7
+ * In the React SDK, this file is not marked with `use client`, to allow
8
+ * NextJS App Directory to use the SDK helper functions without issues.
6
9
  */
7
10
  export * from './server-index.js';
@@ -1,10 +1,13 @@
1
1
  // ignore prettier formatting for this file because the order of exports is meaningful
2
2
  // prettier-ignore
3
3
  export * from './index-helpers/top-of-file.js';
4
+ /**
5
+ * In the React SDK, this file is marked with `use client`.
6
+ */
4
7
  // prettier-ignore
5
8
  export * from './index-helpers/blocks-exports.js';
6
9
  /**
7
- * We have a separate entry point to the SDKs that guarantees no components are being imported. This is useful
8
- * for React SDK, which would break in the NextJS App directory because the component imports have `use client` in them.
10
+ * In the React SDK, this file is not marked with `use client`, to allow
11
+ * NextJS App Directory to use the SDK helper functions without issues.
9
12
  */
10
13
  export * from './server-index.js';
@@ -19,8 +19,9 @@ let componentsContext = getContext(ComponentsContext.key);
19
19
  {parent}
20
20
  {path}
21
21
  {styleProp}
22
- BlocksWrapper={$context?.BlocksWrapper}
23
- BlocksWrapperProps={$context?.BlocksWrapperProps}
22
+ BlocksWrapper={$context?.BlocksWrapper || $builderContext.BlocksWrapper}
23
+ BlocksWrapperProps={$context?.BlocksWrapperProps ||
24
+ $builderContext.BlocksWrapperProps}
24
25
  >
25
26
  {#if blocks}
26
27
  {#each blocks as block (block.id)}
@@ -233,8 +233,10 @@ let httpReqsData = {};
233
233
  let clicked = false;
234
234
  onMount(() => {
235
235
  if (isBrowser()) {
236
- if (isEditing() && elementRef) {
237
- elementRef.dispatchEvent(new CustomEvent("initeditingbldr"));
236
+ if (isEditing()) {
237
+ if (elementRef) {
238
+ elementRef.dispatchEvent(new CustomEvent("initeditingbldr"));
239
+ }
238
240
  }
239
241
  const shouldTrackImpression = $builderContextSignal.content && getDefaultCanTrack(canTrack);
240
242
  if (shouldTrackImpression) {
@@ -250,8 +252,10 @@ onMount(() => {
250
252
  });
251
253
  }
252
254
  // override normal content in preview mode
253
- if (isPreviewing() && elementRef) {
254
- elementRef.dispatchEvent(new CustomEvent("initpreviewingbldr"));
255
+ if (isPreviewing()) {
256
+ if (elementRef) {
257
+ elementRef.dispatchEvent(new CustomEvent("initpreviewingbldr"));
258
+ }
255
259
  }
256
260
  }
257
261
  });
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.4";
1
+ export declare const SDK_VERSION = "1.0.8";
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.4";
1
+ export const SDK_VERSION = "1.0.8";
@@ -1,5 +1,4 @@
1
- type QueryObject = Record<string, string | string[]>;
2
- export declare const convertSearchParamsToQueryObject: (searchParams: URLSearchParams) => QueryObject;
1
+ import type { QueryObject } from '../../helpers/search/search.js';
3
2
  /**
4
3
  * Receives a `URLSearchParams` object or a regular query object, and returns the subset of query params that are
5
4
  * relevant to the Builder SDK.
@@ -8,5 +7,3 @@ export declare const convertSearchParamsToQueryObject: (searchParams: URLSearchP
8
7
  */
9
8
  export declare const getBuilderSearchParams: (_options: QueryObject | URLSearchParams | undefined) => QueryObject;
10
9
  export declare const getBuilderSearchParamsFromWindow: () => QueryObject;
11
- export declare const normalizeSearchParams: (searchParams: QueryObject | URLSearchParams) => QueryObject;
12
- export {};
@@ -1,13 +1,7 @@
1
+ import { normalizeSearchParams } from '../../helpers/search/search.js';
1
2
  import { isBrowser } from '../is-browser.js';
2
3
  const BUILDER_SEARCHPARAMS_PREFIX = 'builder.';
3
4
  const BUILDER_OPTIONS_PREFIX = 'options.';
4
- export const convertSearchParamsToQueryObject = (searchParams) => {
5
- const options = {};
6
- searchParams.forEach((value, key) => {
7
- options[key] = value;
8
- });
9
- return options;
10
- };
11
5
  /**
12
6
  * Receives a `URLSearchParams` object or a regular query object, and returns the subset of query params that are
13
7
  * relevant to the Builder SDK.
@@ -35,4 +29,3 @@ export const getBuilderSearchParamsFromWindow = () => {
35
29
  const searchParams = new URLSearchParams(window.location.search);
36
30
  return getBuilderSearchParams(searchParams);
37
31
  };
38
- export const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
@@ -1,6 +1,7 @@
1
1
  import { flatten } from '../../helpers/flatten.js';
2
+ import { normalizeSearchParams } from '../../helpers/search/search.js';
2
3
  import { DEFAULT_API_VERSION } from '../../types/api-version.js';
3
- import { getBuilderSearchParamsFromWindow, normalizeSearchParams } from '../get-builder-search-params/index.js';
4
+ import { getBuilderSearchParamsFromWindow } from '../get-builder-search-params/index.js';
4
5
  const isPositiveNumber = (thing) => typeof thing === 'number' && !isNaN(thing) && thing >= 0;
5
6
  export const generateContentUrl = (options) => {
6
7
  const { limit = 30, userAttributes, query, model, apiKey, enrich, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished } = options;
@@ -1 +1,2 @@
1
- export declare function isEditing(): boolean;
1
+ import { type Search } from '../helpers/search/search.js';
2
+ export declare function isEditing(search?: Search): boolean;
@@ -1,5 +1,6 @@
1
1
  import { TARGET } from '../constants/target.js';
2
+ import { getSearchString } from '../helpers/search/search.js';
2
3
  import { isIframe } from './is-iframe.js';
3
- export function isEditing() {
4
- return isIframe() && (TARGET === 'reactNative' || window.location.search.indexOf('builder.frameEditing=') !== -1);
4
+ export function isEditing(search) {
5
+ return isIframe() && (TARGET === 'reactNative' || getSearchString(search || window.location.search).indexOf('builder.frameEditing=') !== -1);
5
6
  }
@@ -1 +1,2 @@
1
- export declare function isPreviewing(): boolean;
1
+ import type { Search } from '../helpers/search/search.js';
2
+ export declare function isPreviewing(search?: Search): boolean;
@@ -1,11 +1,13 @@
1
+ import { getSearchString } from '../helpers/search/search.js';
1
2
  import { isBrowser } from './is-browser.js';
2
3
  import { isEditing } from './is-editing.js';
3
- export function isPreviewing() {
4
+ export function isPreviewing(search) {
4
5
  if (!isBrowser()) {
5
6
  return false;
6
7
  }
7
- if (isEditing()) {
8
+ const normalizedSearch = getSearchString(search || window.location.search);
9
+ if (isEditing(normalizedSearch)) {
8
10
  return false;
9
11
  }
10
- return Boolean(location.search.indexOf('builder.preview=') !== -1);
12
+ return Boolean(normalizedSearch.indexOf('builder.preview=') !== -1);
11
13
  }
@@ -0,0 +1,5 @@
1
+ export type QueryObject = Record<string, string | string[]>;
2
+ export declare const convertSearchParamsToQueryObject: (searchParams: URLSearchParams) => QueryObject;
3
+ export declare const normalizeSearchParams: (searchParams: QueryObject | URLSearchParams) => QueryObject;
4
+ export type Search = URLSearchParams | string | QueryObject;
5
+ export declare const getSearchString: (search: Search) => string;
@@ -0,0 +1,17 @@
1
+ export const convertSearchParamsToQueryObject = (searchParams) => {
2
+ const options = {};
3
+ searchParams.forEach((value, key) => {
4
+ options[key] = value;
5
+ });
6
+ return options;
7
+ };
8
+ export const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
9
+ export const getSearchString = (search) => {
10
+ if (typeof search === 'string') {
11
+ return search;
12
+ }
13
+ else if (search instanceof URLSearchParams) {
14
+ return search.toString();
15
+ }
16
+ return new URLSearchParams(search).toString();
17
+ };
@@ -1,7 +1,10 @@
1
1
  export * from './index-helpers/top-of-file.js';
2
+ /**
3
+ * In the React SDK, this file is marked with `use client`.
4
+ */
2
5
  export * from './index-helpers/blocks-exports.js';
3
6
  /**
4
- * We have a separate entry point to the SDKs that guarantees no components are being imported. This is useful
5
- * for React SDK, which would break in the NextJS App directory because the component imports have `use client` in them.
7
+ * In the React SDK, this file is not marked with `use client`, to allow
8
+ * NextJS App Directory to use the SDK helper functions without issues.
6
9
  */
7
10
  export * from './server-index.js';
package/lib/edge/index.js CHANGED
@@ -1,10 +1,13 @@
1
1
  // ignore prettier formatting for this file because the order of exports is meaningful
2
2
  // prettier-ignore
3
3
  export * from './index-helpers/top-of-file.js';
4
+ /**
5
+ * In the React SDK, this file is marked with `use client`.
6
+ */
4
7
  // prettier-ignore
5
8
  export * from './index-helpers/blocks-exports.js';
6
9
  /**
7
- * We have a separate entry point to the SDKs that guarantees no components are being imported. This is useful
8
- * for React SDK, which would break in the NextJS App directory because the component imports have `use client` in them.
10
+ * In the React SDK, this file is not marked with `use client`, to allow
11
+ * NextJS App Directory to use the SDK helper functions without issues.
9
12
  */
10
13
  export * from './server-index.js';
@@ -19,8 +19,9 @@ let componentsContext = getContext(ComponentsContext.key);
19
19
  {parent}
20
20
  {path}
21
21
  {styleProp}
22
- BlocksWrapper={$context?.BlocksWrapper}
23
- BlocksWrapperProps={$context?.BlocksWrapperProps}
22
+ BlocksWrapper={$context?.BlocksWrapper || $builderContext.BlocksWrapper}
23
+ BlocksWrapperProps={$context?.BlocksWrapperProps ||
24
+ $builderContext.BlocksWrapperProps}
24
25
  >
25
26
  {#if blocks}
26
27
  {#each blocks as block (block.id)}
@@ -233,8 +233,10 @@ let httpReqsData = {};
233
233
  let clicked = false;
234
234
  onMount(() => {
235
235
  if (isBrowser()) {
236
- if (isEditing() && elementRef) {
237
- elementRef.dispatchEvent(new CustomEvent("initeditingbldr"));
236
+ if (isEditing()) {
237
+ if (elementRef) {
238
+ elementRef.dispatchEvent(new CustomEvent("initeditingbldr"));
239
+ }
238
240
  }
239
241
  const shouldTrackImpression = $builderContextSignal.content && getDefaultCanTrack(canTrack);
240
242
  if (shouldTrackImpression) {
@@ -250,8 +252,10 @@ onMount(() => {
250
252
  });
251
253
  }
252
254
  // override normal content in preview mode
253
- if (isPreviewing() && elementRef) {
254
- elementRef.dispatchEvent(new CustomEvent("initpreviewingbldr"));
255
+ if (isPreviewing()) {
256
+ if (elementRef) {
257
+ elementRef.dispatchEvent(new CustomEvent("initpreviewingbldr"));
258
+ }
255
259
  }
256
260
  }
257
261
  });
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.4";
1
+ export declare const SDK_VERSION = "1.0.8";
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.4";
1
+ export const SDK_VERSION = "1.0.8";
@@ -1,5 +1,4 @@
1
- type QueryObject = Record<string, string | string[]>;
2
- export declare const convertSearchParamsToQueryObject: (searchParams: URLSearchParams) => QueryObject;
1
+ import type { QueryObject } from '../../helpers/search/search.js';
3
2
  /**
4
3
  * Receives a `URLSearchParams` object or a regular query object, and returns the subset of query params that are
5
4
  * relevant to the Builder SDK.
@@ -8,5 +7,3 @@ export declare const convertSearchParamsToQueryObject: (searchParams: URLSearchP
8
7
  */
9
8
  export declare const getBuilderSearchParams: (_options: QueryObject | URLSearchParams | undefined) => QueryObject;
10
9
  export declare const getBuilderSearchParamsFromWindow: () => QueryObject;
11
- export declare const normalizeSearchParams: (searchParams: QueryObject | URLSearchParams) => QueryObject;
12
- export {};
@@ -1,13 +1,7 @@
1
+ import { normalizeSearchParams } from '../../helpers/search/search.js';
1
2
  import { isBrowser } from '../is-browser.js';
2
3
  const BUILDER_SEARCHPARAMS_PREFIX = 'builder.';
3
4
  const BUILDER_OPTIONS_PREFIX = 'options.';
4
- export const convertSearchParamsToQueryObject = (searchParams) => {
5
- const options = {};
6
- searchParams.forEach((value, key) => {
7
- options[key] = value;
8
- });
9
- return options;
10
- };
11
5
  /**
12
6
  * Receives a `URLSearchParams` object or a regular query object, and returns the subset of query params that are
13
7
  * relevant to the Builder SDK.
@@ -35,4 +29,3 @@ export const getBuilderSearchParamsFromWindow = () => {
35
29
  const searchParams = new URLSearchParams(window.location.search);
36
30
  return getBuilderSearchParams(searchParams);
37
31
  };
38
- export const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
@@ -1,6 +1,7 @@
1
1
  import { flatten } from '../../helpers/flatten.js';
2
+ import { normalizeSearchParams } from '../../helpers/search/search.js';
2
3
  import { DEFAULT_API_VERSION } from '../../types/api-version.js';
3
- import { getBuilderSearchParamsFromWindow, normalizeSearchParams } from '../get-builder-search-params/index.js';
4
+ import { getBuilderSearchParamsFromWindow } from '../get-builder-search-params/index.js';
4
5
  const isPositiveNumber = (thing) => typeof thing === 'number' && !isNaN(thing) && thing >= 0;
5
6
  export const generateContentUrl = (options) => {
6
7
  const { limit = 30, userAttributes, query, model, apiKey, enrich, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished } = options;
@@ -1 +1,2 @@
1
- export declare function isEditing(): boolean;
1
+ import { type Search } from '../helpers/search/search.js';
2
+ export declare function isEditing(search?: Search): boolean;
@@ -1,5 +1,6 @@
1
1
  import { TARGET } from '../constants/target.js';
2
+ import { getSearchString } from '../helpers/search/search.js';
2
3
  import { isIframe } from './is-iframe.js';
3
- export function isEditing() {
4
- return isIframe() && (TARGET === 'reactNative' || window.location.search.indexOf('builder.frameEditing=') !== -1);
4
+ export function isEditing(search) {
5
+ return isIframe() && (TARGET === 'reactNative' || getSearchString(search || window.location.search).indexOf('builder.frameEditing=') !== -1);
5
6
  }
@@ -1 +1,2 @@
1
- export declare function isPreviewing(): boolean;
1
+ import type { Search } from '../helpers/search/search.js';
2
+ export declare function isPreviewing(search?: Search): boolean;
@@ -1,11 +1,13 @@
1
+ import { getSearchString } from '../helpers/search/search.js';
1
2
  import { isBrowser } from './is-browser.js';
2
3
  import { isEditing } from './is-editing.js';
3
- export function isPreviewing() {
4
+ export function isPreviewing(search) {
4
5
  if (!isBrowser()) {
5
6
  return false;
6
7
  }
7
- if (isEditing()) {
8
+ const normalizedSearch = getSearchString(search || window.location.search);
9
+ if (isEditing(normalizedSearch)) {
8
10
  return false;
9
11
  }
10
- return Boolean(location.search.indexOf('builder.preview=') !== -1);
12
+ return Boolean(normalizedSearch.indexOf('builder.preview=') !== -1);
11
13
  }
@@ -0,0 +1,5 @@
1
+ export type QueryObject = Record<string, string | string[]>;
2
+ export declare const convertSearchParamsToQueryObject: (searchParams: URLSearchParams) => QueryObject;
3
+ export declare const normalizeSearchParams: (searchParams: QueryObject | URLSearchParams) => QueryObject;
4
+ export type Search = URLSearchParams | string | QueryObject;
5
+ export declare const getSearchString: (search: Search) => string;
@@ -0,0 +1,17 @@
1
+ export const convertSearchParamsToQueryObject = (searchParams) => {
2
+ const options = {};
3
+ searchParams.forEach((value, key) => {
4
+ options[key] = value;
5
+ });
6
+ return options;
7
+ };
8
+ export const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
9
+ export const getSearchString = (search) => {
10
+ if (typeof search === 'string') {
11
+ return search;
12
+ }
13
+ else if (search instanceof URLSearchParams) {
14
+ return search.toString();
15
+ }
16
+ return new URLSearchParams(search).toString();
17
+ };
@@ -1,7 +1,10 @@
1
1
  export * from './index-helpers/top-of-file.js';
2
+ /**
3
+ * In the React SDK, this file is marked with `use client`.
4
+ */
2
5
  export * from './index-helpers/blocks-exports.js';
3
6
  /**
4
- * We have a separate entry point to the SDKs that guarantees no components are being imported. This is useful
5
- * for React SDK, which would break in the NextJS App directory because the component imports have `use client` in them.
7
+ * In the React SDK, this file is not marked with `use client`, to allow
8
+ * NextJS App Directory to use the SDK helper functions without issues.
6
9
  */
7
10
  export * from './server-index.js';
package/lib/node/index.js CHANGED
@@ -1,10 +1,13 @@
1
1
  // ignore prettier formatting for this file because the order of exports is meaningful
2
2
  // prettier-ignore
3
3
  export * from './index-helpers/top-of-file.js';
4
+ /**
5
+ * In the React SDK, this file is marked with `use client`.
6
+ */
4
7
  // prettier-ignore
5
8
  export * from './index-helpers/blocks-exports.js';
6
9
  /**
7
- * We have a separate entry point to the SDKs that guarantees no components are being imported. This is useful
8
- * for React SDK, which would break in the NextJS App directory because the component imports have `use client` in them.
10
+ * In the React SDK, this file is not marked with `use client`, to allow
11
+ * NextJS App Directory to use the SDK helper functions without issues.
9
12
  */
10
13
  export * from './server-index.js';
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": "1.0.4",
4
+ "version": "1.0.8",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "lib",
@@ -25,8 +25,9 @@
25
25
  {parent}
26
26
  {path}
27
27
  {styleProp}
28
- BlocksWrapper={$context?.BlocksWrapper}
29
- BlocksWrapperProps={$context?.BlocksWrapperProps}
28
+ BlocksWrapper={$context?.BlocksWrapper || $builderContext.BlocksWrapper}
29
+ BlocksWrapperProps={$context?.BlocksWrapperProps ||
30
+ $builderContext.BlocksWrapperProps}
30
31
  >
31
32
  {#if blocks}
32
33
  {#each blocks as block (block.id)}
@@ -287,8 +287,10 @@
287
287
 
288
288
  onMount(() => {
289
289
  if (isBrowser()) {
290
- if (isEditing() && elementRef) {
291
- elementRef.dispatchEvent(new CustomEvent("initeditingbldr"));
290
+ if (isEditing()) {
291
+ if (elementRef) {
292
+ elementRef.dispatchEvent(new CustomEvent("initeditingbldr"));
293
+ }
292
294
  }
293
295
  const shouldTrackImpression =
294
296
  $builderContextSignal.content && getDefaultCanTrack(canTrack);
@@ -306,8 +308,10 @@
306
308
  }
307
309
 
308
310
  // override normal content in preview mode
309
- if (isPreviewing() && elementRef) {
310
- elementRef.dispatchEvent(new CustomEvent("initpreviewingbldr"));
311
+ if (isPreviewing()) {
312
+ if (elementRef) {
313
+ elementRef.dispatchEvent(new CustomEvent("initpreviewingbldr"));
314
+ }
311
315
  }
312
316
  }
313
317
  });
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.4"
1
+ export const SDK_VERSION = "1.0.8"
@@ -1,14 +1,8 @@
1
+ import type { QueryObject } from '../../helpers/search/search.js';
2
+ import { normalizeSearchParams } from '../../helpers/search/search.js';
1
3
  import { isBrowser } from '../is-browser.js';
2
4
  const BUILDER_SEARCHPARAMS_PREFIX = 'builder.';
3
5
  const BUILDER_OPTIONS_PREFIX = 'options.';
4
- type QueryObject = Record<string, string | string[]>;
5
- export const convertSearchParamsToQueryObject = (searchParams: URLSearchParams): QueryObject => {
6
- const options: Record<string, string> = {};
7
- searchParams.forEach((value, key) => {
8
- options[key] = value;
9
- });
10
- return options;
11
- };
12
6
 
13
7
  /**
14
8
  * Receives a `URLSearchParams` object or a regular query object, and returns the subset of query params that are
@@ -36,5 +30,4 @@ export const getBuilderSearchParamsFromWindow = () => {
36
30
  }
37
31
  const searchParams = new URLSearchParams(window.location.search);
38
32
  return getBuilderSearchParams(searchParams);
39
- };
40
- export const normalizeSearchParams = (searchParams: QueryObject | URLSearchParams): QueryObject => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams
33
+ }
@@ -1,6 +1,7 @@
1
1
  import { flatten } from '../../helpers/flatten.js';
2
+ import { normalizeSearchParams } from '../../helpers/search/search.js';
2
3
  import { DEFAULT_API_VERSION } from '../../types/api-version.js';
3
- import { getBuilderSearchParamsFromWindow, normalizeSearchParams } from '../get-builder-search-params/index.js';
4
+ import { getBuilderSearchParamsFromWindow } from '../get-builder-search-params/index.js';
4
5
  import type { GetContentOptions } from './types.js';
5
6
  const isPositiveNumber = (thing: unknown) => typeof thing === 'number' && !isNaN(thing) && thing >= 0;
6
7
  export const generateContentUrl = (options: GetContentOptions): URL => {
@@ -1,5 +1,6 @@
1
1
  import { TARGET } from '../constants/target.js';
2
+ import { getSearchString, type Search } from '../helpers/search/search.js';
2
3
  import { isIframe } from './is-iframe.js';
3
- export function isEditing(): boolean {
4
- return isIframe() && (TARGET === 'reactNative' || window.location.search.indexOf('builder.frameEditing=') !== -1);
4
+ export function isEditing(search?: Search) {
5
+ return isIframe() && (TARGET === 'reactNative' || getSearchString(search || window.location.search).indexOf('builder.frameEditing=') !== -1);
5
6
  }
@@ -1,11 +1,14 @@
1
+ import type { Search } from '../helpers/search/search.js';
2
+ import { getSearchString } from '../helpers/search/search.js';
1
3
  import { isBrowser } from './is-browser.js';
2
4
  import { isEditing } from './is-editing.js';
3
- export function isPreviewing() {
5
+ export function isPreviewing(search?: Search) {
4
6
  if (!isBrowser()) {
5
7
  return false;
6
8
  }
7
- if (isEditing()) {
9
+ const normalizedSearch = getSearchString(search || window.location.search);
10
+ if (isEditing(normalizedSearch)) {
8
11
  return false;
9
12
  }
10
- return Boolean(location.search.indexOf('builder.preview=') !== -1);
13
+ return Boolean(normalizedSearch.indexOf('builder.preview=') !== -1);
11
14
  }
@@ -0,0 +1,18 @@
1
+ export type QueryObject = Record<string, string | string[]>;
2
+ export const convertSearchParamsToQueryObject = (searchParams: URLSearchParams): QueryObject => {
3
+ const options: Record<string, string> = {};
4
+ searchParams.forEach((value, key) => {
5
+ options[key] = value;
6
+ });
7
+ return options;
8
+ };
9
+ export const normalizeSearchParams = (searchParams: QueryObject | URLSearchParams): QueryObject => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
10
+ export type Search = URLSearchParams | string | QueryObject;
11
+ export const getSearchString = (search: Search): string => {
12
+ if (typeof search === 'string') {
13
+ return search;
14
+ } else if (search instanceof URLSearchParams) {
15
+ return search.toString();
16
+ }
17
+ return new URLSearchParams((search as any)).toString();
18
+ }
package/src/index.ts CHANGED
@@ -1,11 +1,15 @@
1
1
  // ignore prettier formatting for this file because the order of exports is meaningful
2
2
  // prettier-ignore
3
3
  export * from './index-helpers/top-of-file.js';
4
+
5
+ /**
6
+ * In the React SDK, this file is marked with `use client`.
7
+ */
4
8
  // prettier-ignore
5
9
  export * from './index-helpers/blocks-exports.js';
6
10
 
7
11
  /**
8
- * We have a separate entry point to the SDKs that guarantees no components are being imported. This is useful
9
- * for React SDK, which would break in the NextJS App directory because the component imports have `use client` in them.
12
+ * In the React SDK, this file is not marked with `use client`, to allow
13
+ * NextJS App Directory to use the SDK helper functions without issues.
10
14
  */
11
15
  export * from './server-index.js'