@builder.io/sdk-svelte 1.0.4 → 1.0.6
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/lib/browser/constants/sdk-version.d.ts +1 -1
- package/lib/browser/constants/sdk-version.js +1 -1
- package/lib/browser/functions/get-builder-search-params/index.d.ts +1 -4
- package/lib/browser/functions/get-builder-search-params/index.js +1 -8
- package/lib/browser/functions/get-content/generate-content-url.js +2 -1
- package/lib/browser/functions/is-editing.d.ts +2 -1
- package/lib/browser/functions/is-editing.js +3 -2
- package/lib/browser/functions/is-previewing.d.ts +2 -1
- package/lib/browser/functions/is-previewing.js +5 -3
- package/lib/browser/helpers/search/search.d.ts +5 -0
- package/lib/browser/helpers/search/search.js +17 -0
- package/lib/browser/index.d.ts +5 -2
- package/lib/browser/index.js +5 -2
- package/lib/edge/constants/sdk-version.d.ts +1 -1
- package/lib/edge/constants/sdk-version.js +1 -1
- package/lib/edge/functions/get-builder-search-params/index.d.ts +1 -4
- package/lib/edge/functions/get-builder-search-params/index.js +1 -8
- package/lib/edge/functions/get-content/generate-content-url.js +2 -1
- package/lib/edge/functions/is-editing.d.ts +2 -1
- package/lib/edge/functions/is-editing.js +3 -2
- package/lib/edge/functions/is-previewing.d.ts +2 -1
- package/lib/edge/functions/is-previewing.js +5 -3
- package/lib/edge/helpers/search/search.d.ts +5 -0
- package/lib/edge/helpers/search/search.js +17 -0
- package/lib/edge/index.d.ts +5 -2
- package/lib/edge/index.js +5 -2
- package/lib/node/constants/sdk-version.d.ts +1 -1
- package/lib/node/constants/sdk-version.js +1 -1
- package/lib/node/functions/get-builder-search-params/index.d.ts +1 -4
- package/lib/node/functions/get-builder-search-params/index.js +1 -8
- package/lib/node/functions/get-content/generate-content-url.js +2 -1
- package/lib/node/functions/is-editing.d.ts +2 -1
- package/lib/node/functions/is-editing.js +3 -2
- package/lib/node/functions/is-previewing.d.ts +2 -1
- package/lib/node/functions/is-previewing.js +5 -3
- package/lib/node/helpers/search/search.d.ts +5 -0
- package/lib/node/helpers/search/search.js +17 -0
- package/lib/node/index.d.ts +5 -2
- package/lib/node/index.js +5 -2
- package/package.json +1 -1
- package/src/constants/sdk-version.ts +1 -1
- package/src/functions/get-builder-search-params/index.ts +3 -10
- package/src/functions/get-content/generate-content-url.ts +2 -1
- package/src/functions/is-editing.ts +3 -2
- package/src/functions/is-previewing.ts +6 -3
- package/src/helpers/search/search.ts +18 -0
- package/src/index.ts +6 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.
|
|
1
|
+
export declare const SDK_VERSION = "1.0.6";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "1.0.
|
|
1
|
+
export const SDK_VERSION = "1.0.6";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
type QueryObject
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
8
|
+
const normalizedSearch = getSearchString(search || window.location.search);
|
|
9
|
+
if (isEditing(normalizedSearch)) {
|
|
8
10
|
return false;
|
|
9
11
|
}
|
|
10
|
-
return Boolean(
|
|
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
|
+
};
|
package/lib/browser/index.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
5
|
-
*
|
|
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/browser/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
|
-
*
|
|
8
|
-
*
|
|
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';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.
|
|
1
|
+
export declare const SDK_VERSION = "1.0.6";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "1.0.
|
|
1
|
+
export const SDK_VERSION = "1.0.6";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
type QueryObject
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
8
|
+
const normalizedSearch = getSearchString(search || window.location.search);
|
|
9
|
+
if (isEditing(normalizedSearch)) {
|
|
8
10
|
return false;
|
|
9
11
|
}
|
|
10
|
-
return Boolean(
|
|
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
|
+
};
|
package/lib/edge/index.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
5
|
-
*
|
|
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
|
-
*
|
|
8
|
-
*
|
|
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';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.
|
|
1
|
+
export declare const SDK_VERSION = "1.0.6";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "1.0.
|
|
1
|
+
export const SDK_VERSION = "1.0.6";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
type QueryObject
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
8
|
+
const normalizedSearch = getSearchString(search || window.location.search);
|
|
9
|
+
if (isEditing(normalizedSearch)) {
|
|
8
10
|
return false;
|
|
9
11
|
}
|
|
10
|
-
return Boolean(
|
|
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
|
+
};
|
package/lib/node/index.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
5
|
-
*
|
|
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
|
-
*
|
|
8
|
-
*
|
|
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 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "1.0.
|
|
1
|
+
export const SDK_VERSION = "1.0.6"
|
|
@@ -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
|
|
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()
|
|
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
|
-
|
|
9
|
+
const normalizedSearch = getSearchString(search || window.location.search);
|
|
10
|
+
if (isEditing(normalizedSearch)) {
|
|
8
11
|
return false;
|
|
9
12
|
}
|
|
10
|
-
return Boolean(
|
|
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
|
-
*
|
|
9
|
-
*
|
|
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'
|