@builder.io/sdk-svelte 0.5.4 → 0.5.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/package/--package.json +6 -2
- package/package/CHANGELOG.md +8 -0
- package/package/blocks/BaseText.svelte +1 -1
- package/package/blocks/symbol/symbol.helpers.d.ts +1 -1
- package/package/blocks/symbol/symbol.helpers.js +3 -3
- package/package/blocks/symbol/symbol.svelte +2 -2
- package/package/components/block/block.helpers.js +1 -1
- package/package/components/block/components/repeated-block.svelte +1 -1
- package/package/components/blocks/blocks.svelte +2 -2
- package/package/components/content/components/enable-editor.svelte +4 -4
- package/package/components/content/content.svelte +1 -1
- package/package/constants/sdk-version.d.ts +1 -1
- package/package/constants/sdk-version.js +1 -1
- package/package/constants/target.d.ts +1 -1
- package/package/functions/fetch-builder-props.d.ts +39 -0
- package/package/functions/fetch-builder-props.js +25 -0
- package/package/functions/get-content/index.d.ts +20 -3
- package/package/functions/get-content/index.js +24 -7
- package/package/functions/get-processed-block.js +1 -1
- package/package/functions/is-non-node-server.js +1 -1
- package/package/helpers/preview-lru-cache/get.d.ts +2 -1
- package/package/helpers/preview-lru-cache/get.js +2 -6
- package/package/helpers/preview-lru-cache/helpers.d.ts +0 -1
- package/package/helpers/preview-lru-cache/helpers.js +1 -9
- package/package/helpers/preview-lru-cache/init.js +1 -10
- package/package/helpers/preview-lru-cache/set.d.ts +1 -1
- package/package/helpers/preview-lru-cache/set.js +0 -4
- package/package/helpers/preview-lru-cache/types.d.ts +0 -12
- package/package/helpers/preview-lru-cache/types.js +1 -6
- package/package/index-helpers/blocks-exports.d.ts +11 -2
- package/package/index-helpers/blocks-exports.js +11 -2
- package/package/index.d.ts +4 -3
- package/package/index.js +2 -1
- package/package.json +5 -1
- package/src/blocks/BaseText.svelte +1 -1
- package/src/blocks/symbol/symbol.helpers.ts +3 -3
- package/src/blocks/symbol/symbol.svelte +2 -2
- package/src/components/block/block.helpers.ts +1 -1
- package/src/components/block/components/repeated-block.svelte +1 -1
- package/src/components/blocks/blocks.svelte +2 -2
- package/src/components/content/components/enable-editor.svelte +4 -4
- package/src/components/content/content.svelte +1 -1
- package/src/constants/sdk-version.ts +1 -1
- package/src/constants/target.ts +1 -1
- package/src/functions/fetch-builder-props.ts +61 -0
- package/src/functions/get-content/index.ts +29 -8
- package/src/functions/get-processed-block.ts +1 -1
- package/src/functions/is-non-node-server.ts +1 -1
- package/src/helpers/preview-lru-cache/get.ts +3 -7
- package/src/helpers/preview-lru-cache/helpers.ts +0 -9
- package/src/helpers/preview-lru-cache/init.ts +1 -11
- package/src/helpers/preview-lru-cache/set.ts +1 -7
- package/src/helpers/preview-lru-cache/types.ts +0 -12
- package/src/index-helpers/blocks-exports.ts +12 -2
- package/src/index.ts +5 -4
- package/package/functions/if-target.d.ts +0 -7
- package/package/functions/if-target.js +0 -10
- package/src/functions/if-target.ts +0 -19
package/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.5.
|
|
4
|
+
"version": "0.5.6",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"package",
|
|
@@ -107,6 +107,7 @@
|
|
|
107
107
|
"./functions/event-handler-name": "./functions/event-handler-name.js",
|
|
108
108
|
"./functions/extract-text-styles": "./functions/extract-text-styles.js",
|
|
109
109
|
"./functions/fast-clone": "./functions/fast-clone.js",
|
|
110
|
+
"./functions/fetch-builder-props": "./functions/fetch-builder-props.js",
|
|
110
111
|
"./functions/get-block-actions-handler": "./functions/get-block-actions-handler.js",
|
|
111
112
|
"./functions/get-block-actions": "./functions/get-block-actions.js",
|
|
112
113
|
"./functions/get-block-component-options": "./functions/get-block-component-options.js",
|
|
@@ -119,7 +120,6 @@
|
|
|
119
120
|
"./functions/get-global-this": "./functions/get-global-this.js",
|
|
120
121
|
"./functions/get-processed-block": "./functions/get-processed-block.js",
|
|
121
122
|
"./functions/get-react-native-block-styles": "./functions/get-react-native-block-styles.js",
|
|
122
|
-
"./functions/if-target": "./functions/if-target.js",
|
|
123
123
|
"./functions/is-browser": "./functions/is-browser.js",
|
|
124
124
|
"./functions/is-editing": "./functions/is-editing.js",
|
|
125
125
|
"./functions/is-iframe": "./functions/is-iframe.js",
|
|
@@ -190,6 +190,10 @@
|
|
|
190
190
|
],
|
|
191
191
|
"targets": {
|
|
192
192
|
"build": {
|
|
193
|
+
"dependsOn": [
|
|
194
|
+
"^build:svelte",
|
|
195
|
+
"^build"
|
|
196
|
+
],
|
|
193
197
|
"outputs": [
|
|
194
198
|
"{projectRoot}/package"
|
|
195
199
|
]
|
package/package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script context="module"></script>
|
|
2
2
|
|
|
3
3
|
<script>import { getContext } from "svelte";
|
|
4
|
-
import BuilderContext from "../context/builder.context";
|
|
4
|
+
import BuilderContext from "../context/builder.context.js";
|
|
5
5
|
export let text;
|
|
6
6
|
function mitosis_styling(node, vars) {
|
|
7
7
|
Object.entries(vars || {}).forEach(([p, v]) => {
|
|
@@ -8,7 +8,7 @@ export interface SymbolInfo {
|
|
|
8
8
|
inline?: boolean;
|
|
9
9
|
dynamic?: boolean;
|
|
10
10
|
}
|
|
11
|
-
export declare const
|
|
11
|
+
export declare const fetchSymbolContent: ({ builderContextValue, symbol }: {
|
|
12
12
|
symbol: SymbolInfo | undefined;
|
|
13
13
|
builderContextValue: BuilderContextInterface;
|
|
14
14
|
}) => Promise<BuilderContent | null | undefined>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { getContent } from '../../functions/get-content/index.js';
|
|
2
1
|
import { logger } from '../../helpers/logger.js';
|
|
3
|
-
|
|
2
|
+
import { fetchOneEntry } from '../../index.js';
|
|
3
|
+
export const fetchSymbolContent = async ({ builderContextValue, symbol }) => {
|
|
4
4
|
/**
|
|
5
5
|
* If:
|
|
6
6
|
* - we have a symbol prop
|
|
@@ -13,7 +13,7 @@ export const fetchContent = async ({ builderContextValue, symbol }) => {
|
|
|
13
13
|
if (symbol?.model &&
|
|
14
14
|
// This is a hack, we should not need to check for this, but it is needed for Svelte.
|
|
15
15
|
builderContextValue?.apiKey) {
|
|
16
|
-
return
|
|
16
|
+
return fetchOneEntry({
|
|
17
17
|
model: symbol.model,
|
|
18
18
|
apiKey: builderContextValue.apiKey,
|
|
19
19
|
apiVersion: builderContextValue.apiVersion,
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import ContentVariants from "../../components/content-variants/content-variants.svelte";
|
|
5
5
|
import { filterAttrs } from "../helpers.js";
|
|
6
6
|
import { setAttrs } from "../helpers.js";
|
|
7
|
-
import {
|
|
7
|
+
import { fetchSymbolContent } from "./symbol.helpers.js";
|
|
8
8
|
export let js;
|
|
9
9
|
export let attributes;
|
|
10
10
|
export let symbol;
|
|
@@ -14,7 +14,7 @@ export let builderComponents;
|
|
|
14
14
|
function setContent() {
|
|
15
15
|
if (contentToUse)
|
|
16
16
|
return;
|
|
17
|
-
|
|
17
|
+
fetchSymbolContent({
|
|
18
18
|
symbol: symbol,
|
|
19
19
|
builderContextValue: $builderContext,
|
|
20
20
|
}).then((newContent) => {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
<script>import { setContext } from "svelte";
|
|
4
4
|
import { writable } from "svelte/store";
|
|
5
|
-
import BuilderContext from "../../../context/builder.context";
|
|
5
|
+
import BuilderContext from "../../../context/builder.context.js";
|
|
6
6
|
import Block from "../block.svelte";
|
|
7
7
|
export let repeatContext;
|
|
8
8
|
export let block;
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
import BlockStyles from "../block/components/block-styles.svelte";
|
|
5
5
|
import Block from "../block/block.svelte";
|
|
6
6
|
import BlocksWrapper from "./blocks-wrapper.svelte";
|
|
7
|
-
import BuilderContext from "../../context/builder.context";
|
|
8
|
-
import ComponentsContext from "../../context/components.context";
|
|
7
|
+
import BuilderContext from "../../context/builder.context.js";
|
|
8
|
+
import ComponentsContext from "../../context/components.context.js";
|
|
9
9
|
export let blocks;
|
|
10
10
|
export let parent;
|
|
11
11
|
export let path;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
<script context="module"></script>
|
|
2
2
|
|
|
3
3
|
<script>import { onDestroy, onMount, setContext } from "svelte";
|
|
4
|
-
import { evaluate } from "../../../functions/evaluate";
|
|
4
|
+
import { evaluate } from "../../../functions/evaluate/index.js";
|
|
5
5
|
import { fetch } from "../../../functions/get-fetch.js";
|
|
6
6
|
import { isBrowser } from "../../../functions/is-browser.js";
|
|
7
7
|
import { isEditing } from "../../../functions/is-editing.js";
|
|
8
8
|
import { createRegisterComponentMessage } from "../../../functions/register-component.js";
|
|
9
9
|
import { _track } from "../../../functions/track/index.js";
|
|
10
|
-
import builderContext from "../../../context/builder.context";
|
|
10
|
+
import builderContext from "../../../context/builder.context.js";
|
|
11
11
|
import { registerInsertMenu, setupBrowserForEditing, } from "../../../scripts/init-editing.js";
|
|
12
12
|
import { checkIsDefined } from "../../../helpers/nullable.js";
|
|
13
13
|
import { getInteractionPropertiesForEvent } from "../../../functions/track/interaction.js";
|
|
14
14
|
import { logger } from "../../../helpers/logger.js";
|
|
15
|
-
import {
|
|
15
|
+
import { fetchOneEntry } from "../../../functions/get-content/index.js";
|
|
16
16
|
import { isPreviewing } from "../../../functions/is-previewing.js";
|
|
17
17
|
import "../../../helpers/preview-lru-cache/set.js";
|
|
18
18
|
export let canTrack;
|
|
@@ -226,7 +226,7 @@ onMount(() => {
|
|
|
226
226
|
if (searchParamPreviewModel === model &&
|
|
227
227
|
previewApiKey === apiKey &&
|
|
228
228
|
(!content || searchParamPreviewId === content.id)) {
|
|
229
|
-
|
|
229
|
+
fetchOneEntry({
|
|
230
230
|
model: model,
|
|
231
231
|
apiKey: apiKey,
|
|
232
232
|
apiVersion: $builderContextSignal.apiVersion,
|
|
@@ -10,7 +10,7 @@ import { getRenderContentScriptString } from "../content-variants/helpers.js";
|
|
|
10
10
|
import EnableEditor from "./components/enable-editor.svelte";
|
|
11
11
|
import InlinedScript from "../inlined-script.svelte";
|
|
12
12
|
import "./wrap-component-ref.js";
|
|
13
|
-
import ComponentsContext from "../../context/components.context";
|
|
13
|
+
import ComponentsContext from "../../context/components.context.js";
|
|
14
14
|
export let content;
|
|
15
15
|
export let customComponents;
|
|
16
16
|
export let data;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "
|
|
1
|
+
export declare const SDK_VERSION = "0.5.6";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION =
|
|
1
|
+
export const SDK_VERSION = "0.5.6";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** This file should be overriden for each framework. Ideally this would be implemented in Mitosis. */
|
|
2
|
-
export declare const TARGET: import("../types/targets").Target;
|
|
2
|
+
export declare const TARGET: import("../types/targets.js").Target;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ContentVariantsProps } from '../components/content-variants/content-variants.types.js';
|
|
2
|
+
import type { Dictionary } from '../types/typescript.js';
|
|
3
|
+
import type { GetContentOptions } from './get-content/types.js';
|
|
4
|
+
type GetBuilderPropsOptions = (Omit<GetContentOptions, 'model'> & {
|
|
5
|
+
model?: string;
|
|
6
|
+
}) & ({
|
|
7
|
+
/**
|
|
8
|
+
* The current URL path. Used to determine the `urlPath` for targeting content.
|
|
9
|
+
*
|
|
10
|
+
* Cannot be used with `url`.
|
|
11
|
+
*/
|
|
12
|
+
path: string;
|
|
13
|
+
/**
|
|
14
|
+
* The current URL search params. Used to parse the `searchParams` for targeting content.
|
|
15
|
+
*
|
|
16
|
+
* Cannot be used with `url`.
|
|
17
|
+
*/
|
|
18
|
+
searchParams?: URLSearchParams | Dictionary<string | string[]>;
|
|
19
|
+
url?: undefined;
|
|
20
|
+
} | {
|
|
21
|
+
/**
|
|
22
|
+
* The current URL. Used to determine the `urlPath` for targeting content and
|
|
23
|
+
* to parse the `searchParams` for targeting content.
|
|
24
|
+
*
|
|
25
|
+
* Cannot be used with `path` or `searchParams`.
|
|
26
|
+
*/
|
|
27
|
+
url: URL;
|
|
28
|
+
path?: undefined;
|
|
29
|
+
searchParams?: undefined;
|
|
30
|
+
} | {
|
|
31
|
+
url?: undefined;
|
|
32
|
+
path?: undefined;
|
|
33
|
+
searchParams?: undefined;
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* Fetches builder content, and returns it along with sensible defaults for other props that `Content` needs to render.
|
|
37
|
+
*/
|
|
38
|
+
export declare const fetchBuilderProps: (_args: GetBuilderPropsOptions) => Promise<ContentVariantsProps>;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getBuilderSearchParams } from './get-builder-search-params/index.js';
|
|
2
|
+
import { fetchOneEntry } from './get-content/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Fetches builder content, and returns it along with sensible defaults for other props that `Content` needs to render.
|
|
5
|
+
*/
|
|
6
|
+
export const fetchBuilderProps = async (_args) => {
|
|
7
|
+
const urlPath = _args.path || _args.url?.pathname || _args.userAttributes?.urlPath;
|
|
8
|
+
const getContentArgs = {
|
|
9
|
+
..._args,
|
|
10
|
+
apiKey: _args.apiKey,
|
|
11
|
+
model: _args.model || 'page',
|
|
12
|
+
userAttributes: {
|
|
13
|
+
..._args.userAttributes,
|
|
14
|
+
...(urlPath ? {
|
|
15
|
+
urlPath
|
|
16
|
+
} : {})
|
|
17
|
+
},
|
|
18
|
+
options: getBuilderSearchParams(_args.searchParams || _args.url?.searchParams || _args.options)
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
apiKey: getContentArgs.apiKey,
|
|
22
|
+
model: getContentArgs.model,
|
|
23
|
+
content: await fetchOneEntry(getContentArgs)
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
import type { BuilderContent } from '../../types/builder-content.js';
|
|
2
2
|
import type { GetContentOptions } from './types.js';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Returns a the first entry that matches the given options.
|
|
5
|
+
*/
|
|
6
|
+
export declare function fetchOneEntry(options: GetContentOptions): Promise<BuilderContent | null>;
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated
|
|
9
|
+
* Consider using `fetchBuilderProps` instead for easier setup.
|
|
10
|
+
*
|
|
11
|
+
* NOTE: `getContent` was renamed to `fetchOneEntry` and will be removed in a future release.
|
|
12
|
+
*/
|
|
13
|
+
export declare const getContent: typeof fetchOneEntry;
|
|
4
14
|
type ContentResults = {
|
|
5
15
|
results: BuilderContent[];
|
|
6
16
|
};
|
|
7
17
|
/**
|
|
8
18
|
* Exported only for testing purposes. Should not be used directly.
|
|
9
19
|
*/
|
|
10
|
-
export declare const
|
|
11
|
-
|
|
20
|
+
export declare const _processContentResult: (options: GetContentOptions, content: ContentResults, url?: URL) => Promise<ContentResults>;
|
|
21
|
+
/**
|
|
22
|
+
* Returns a paginated array of entries that match the given options.
|
|
23
|
+
*/
|
|
24
|
+
export declare function fetchEntries(options: GetContentOptions): Promise<ContentResults | null>;
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated Use `fetchEntries` instead.
|
|
27
|
+
*/
|
|
28
|
+
export declare const getAllContent: typeof fetchEntries;
|
|
12
29
|
export {};
|
|
@@ -7,8 +7,11 @@ import { fetch } from '../get-fetch.js';
|
|
|
7
7
|
import { isBrowser } from '../is-browser.js';
|
|
8
8
|
import { generateContentUrl } from './generate-content-url.js';
|
|
9
9
|
const checkContentHasResults = (content) => 'results' in content;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Returns a the first entry that matches the given options.
|
|
12
|
+
*/
|
|
13
|
+
export async function fetchOneEntry(options) {
|
|
14
|
+
const allContent = await fetchEntries({
|
|
12
15
|
...options,
|
|
13
16
|
limit: 1
|
|
14
17
|
});
|
|
@@ -17,7 +20,14 @@ export async function getContent(options) {
|
|
|
17
20
|
}
|
|
18
21
|
return null;
|
|
19
22
|
}
|
|
20
|
-
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated
|
|
25
|
+
* Consider using `fetchBuilderProps` instead for easier setup.
|
|
26
|
+
*
|
|
27
|
+
* NOTE: `getContent` was renamed to `fetchOneEntry` and will be removed in a future release.
|
|
28
|
+
*/
|
|
29
|
+
export const getContent = fetchOneEntry;
|
|
30
|
+
const _fetchContent = async (options) => {
|
|
21
31
|
const url = generateContentUrl(options);
|
|
22
32
|
const res = await fetch(url.href);
|
|
23
33
|
const content = await res.json();
|
|
@@ -26,7 +36,7 @@ const fetchContent = async (options) => {
|
|
|
26
36
|
/**
|
|
27
37
|
* Exported only for testing purposes. Should not be used directly.
|
|
28
38
|
*/
|
|
29
|
-
export const
|
|
39
|
+
export const _processContentResult = async (options, content, url = generateContentUrl(options)) => {
|
|
30
40
|
const canTrack = getDefaultCanTrack(options.canTrack);
|
|
31
41
|
const isPreviewing = url.search.includes(`preview=`);
|
|
32
42
|
if (TARGET === 'rsc' && isPreviewing) {
|
|
@@ -62,10 +72,13 @@ export const processContentResult = async (options, content, url = generateConte
|
|
|
62
72
|
}
|
|
63
73
|
return content;
|
|
64
74
|
};
|
|
65
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Returns a paginated array of entries that match the given options.
|
|
77
|
+
*/
|
|
78
|
+
export async function fetchEntries(options) {
|
|
66
79
|
try {
|
|
67
80
|
const url = generateContentUrl(options);
|
|
68
|
-
const content = await
|
|
81
|
+
const content = await _fetchContent(options);
|
|
69
82
|
if (!checkContentHasResults(content)) {
|
|
70
83
|
logger.error('Error fetching data. ', {
|
|
71
84
|
url,
|
|
@@ -74,10 +87,14 @@ export async function getAllContent(options) {
|
|
|
74
87
|
});
|
|
75
88
|
return null;
|
|
76
89
|
}
|
|
77
|
-
return
|
|
90
|
+
return _processContentResult(options, content);
|
|
78
91
|
}
|
|
79
92
|
catch (error) {
|
|
80
93
|
logger.error('Error fetching data. ', error);
|
|
81
94
|
return null;
|
|
82
95
|
}
|
|
83
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* @deprecated Use `fetchEntries` instead.
|
|
99
|
+
*/
|
|
100
|
+
export const getAllContent = fetchEntries;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { BuilderContent } from '../../types/builder-content.js';
|
|
2
|
+
export declare function getPreviewContent(_searchParams: URLSearchParams): BuilderContent | undefined;
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export function getPreviewContent(searchParams) {
|
|
4
|
-
init();
|
|
5
|
-
const id = getIdFromSearchParams(searchParams);
|
|
6
|
-
return typeof id === 'string' ? globalThis._BUILDER_PREVIEW_LRU_CACHE.get(id) : undefined;
|
|
1
|
+
export function getPreviewContent(_searchParams) {
|
|
2
|
+
return undefined;
|
|
7
3
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const getIdFromSearchParams: (searchParams: URLSearchParams) => string | null;
|
|
@@ -1,9 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export const getIdFromSearchParams = (searchParams) => {
|
|
3
|
-
const previewedModel = searchParams.get('preview');
|
|
4
|
-
const previewedId = searchParams.get('overrides.' + previewedModel);
|
|
5
|
-
if (!previewedId) {
|
|
6
|
-
logger.warn('No previewed ID found in search params.');
|
|
7
|
-
}
|
|
8
|
-
return previewedId;
|
|
9
|
-
};
|
|
1
|
+
"use strict";
|
|
@@ -3,13 +3,4 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Note: This logic is only used by the NextJS SDK.
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
export function init() {
|
|
8
|
-
if (!globalThis._BUILDER_PREVIEW_LRU_CACHE) {
|
|
9
|
-
globalThis._BUILDER_PREVIEW_LRU_CACHE = new LRUCache({
|
|
10
|
-
max: 500,
|
|
11
|
-
// how long to live in ms
|
|
12
|
-
ttl: 1000 * 60 * 5
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
}
|
|
6
|
+
export function init() { }
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is an LRU cache to hold preview content on the server-side.
|
|
3
|
-
*
|
|
4
|
-
* Note: This logic is only used by the NextJS SDK.
|
|
5
|
-
*/
|
|
6
|
-
import type { LRUCache } from 'lru-cache';
|
|
7
|
-
import type { BuilderContent } from '../../types/builder-content';
|
|
8
|
-
type BuilderLRUCache = LRUCache<string, BuilderContent>;
|
|
9
|
-
export type GlobalWCache = typeof globalThis & {
|
|
10
|
-
_BUILDER_PREVIEW_LRU_CACHE: BuilderLRUCache;
|
|
11
|
-
};
|
|
12
|
-
export {};
|
|
@@ -2,9 +2,18 @@ export { default as Button } from '../blocks/button/button.svelte';
|
|
|
2
2
|
export { default as Columns } from '../blocks/columns/columns.svelte';
|
|
3
3
|
export { default as Fragment } from '../blocks/fragment/fragment.svelte';
|
|
4
4
|
export { default as Image } from '../blocks/image/image.svelte';
|
|
5
|
-
export { default as RenderBlocks } from '../components/blocks/blocks.svelte';
|
|
6
5
|
export { default as Section } from '../blocks/section/section.svelte';
|
|
7
6
|
export { default as Symbol } from '../blocks/symbol/symbol.svelte';
|
|
8
7
|
export { default as Text } from '../blocks/text/text.svelte';
|
|
9
8
|
export { default as Video } from '../blocks/video/video.svelte';
|
|
10
|
-
|
|
9
|
+
import { default as Blocks } from '../components/blocks/blocks.svelte';
|
|
10
|
+
import { default as Content } from '../components/content-variants/content-variants.svelte';
|
|
11
|
+
export { Blocks, Content };
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Use `Blocks` instead.
|
|
14
|
+
*/
|
|
15
|
+
export declare const RenderBlocks: typeof Blocks;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated Use `Content` instead.
|
|
18
|
+
*/
|
|
19
|
+
export declare const RenderContent: typeof Content;
|
|
@@ -2,9 +2,18 @@ export { default as Button } from '../blocks/button/button.svelte';
|
|
|
2
2
|
export { default as Columns } from '../blocks/columns/columns.svelte';
|
|
3
3
|
export { default as Fragment } from '../blocks/fragment/fragment.svelte';
|
|
4
4
|
export { default as Image } from '../blocks/image/image.svelte';
|
|
5
|
-
export { default as RenderBlocks } from '../components/blocks/blocks.svelte';
|
|
6
5
|
export { default as Section } from '../blocks/section/section.svelte';
|
|
7
6
|
export { default as Symbol } from '../blocks/symbol/symbol.svelte';
|
|
8
7
|
export { default as Text } from '../blocks/text/text.svelte';
|
|
9
8
|
export { default as Video } from '../blocks/video/video.svelte';
|
|
10
|
-
|
|
9
|
+
import { default as Blocks } from '../components/blocks/blocks.svelte';
|
|
10
|
+
import { default as Content } from '../components/content-variants/content-variants.svelte';
|
|
11
|
+
export { Blocks, Content };
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Use `Blocks` instead.
|
|
14
|
+
*/
|
|
15
|
+
export const RenderBlocks = Blocks;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated Use `Content` instead.
|
|
18
|
+
*/
|
|
19
|
+
export const RenderContent = Content;
|
package/package/index.d.ts
CHANGED
|
@@ -7,9 +7,10 @@ export { register } from './functions/register.js';
|
|
|
7
7
|
export type { InsertMenuConfig, InsertMenuItem } from './functions/register.js';
|
|
8
8
|
export { setEditorSettings } from './functions/set-editor-settings.js';
|
|
9
9
|
export type { Settings } from './functions/set-editor-settings.js';
|
|
10
|
-
export { getAllContent, getContent,
|
|
10
|
+
export { fetchEntries, fetchOneEntry, getAllContent, getContent, _processContentResult } from './functions/get-content/index.js';
|
|
11
11
|
export { getBuilderSearchParams } from './functions/get-builder-search-params/index.js';
|
|
12
12
|
export { track } from './functions/track/index.js';
|
|
13
|
-
export type { RegisteredComponent } from './context/types';
|
|
14
|
-
export type { ComponentInfo } from './types/components';
|
|
13
|
+
export type { RegisteredComponent } from './context/types.js';
|
|
14
|
+
export type { ComponentInfo } from './types/components.js';
|
|
15
15
|
export type { ContentProps } from './components/content/content.types.js';
|
|
16
|
+
export { fetchBuilderProps } from './functions/fetch-builder-props.js';
|
package/package/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export { isPreviewing } from './functions/is-previewing.js';
|
|
|
5
5
|
export { createRegisterComponentMessage } from './functions/register-component.js';
|
|
6
6
|
export { register } from './functions/register.js';
|
|
7
7
|
export { setEditorSettings } from './functions/set-editor-settings.js';
|
|
8
|
-
export { getAllContent, getContent,
|
|
8
|
+
export { fetchEntries, fetchOneEntry, getAllContent, getContent, _processContentResult } from './functions/get-content/index.js';
|
|
9
9
|
export { getBuilderSearchParams } from './functions/get-builder-search-params/index.js';
|
|
10
10
|
export { track } from './functions/track/index.js';
|
|
11
|
+
export { fetchBuilderProps } from './functions/fetch-builder-props.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": "0.5.
|
|
4
|
+
"version": "0.5.6",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"package",
|
|
@@ -52,6 +52,10 @@
|
|
|
52
52
|
],
|
|
53
53
|
"targets": {
|
|
54
54
|
"build": {
|
|
55
|
+
"dependsOn": [
|
|
56
|
+
"^build:svelte",
|
|
57
|
+
"^build"
|
|
58
|
+
],
|
|
55
59
|
"outputs": [
|
|
56
60
|
"{projectRoot}/package"
|
|
57
61
|
]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BuilderContextInterface } from '../../context/types.js';
|
|
2
|
-
import { getContent } from '../../functions/get-content/index.js';
|
|
3
2
|
import { logger } from '../../helpers/logger.js';
|
|
3
|
+
import { fetchOneEntry } from '../../index.js';
|
|
4
4
|
import type { BuilderContent } from '../../types/builder-content.js';
|
|
5
5
|
export interface SymbolInfo {
|
|
6
6
|
model?: string;
|
|
@@ -10,7 +10,7 @@ export interface SymbolInfo {
|
|
|
10
10
|
inline?: boolean;
|
|
11
11
|
dynamic?: boolean;
|
|
12
12
|
}
|
|
13
|
-
export const
|
|
13
|
+
export const fetchSymbolContent = async ({
|
|
14
14
|
builderContextValue,
|
|
15
15
|
symbol
|
|
16
16
|
}: {
|
|
@@ -29,7 +29,7 @@ export const fetchContent = async ({
|
|
|
29
29
|
if (symbol?.model &&
|
|
30
30
|
// This is a hack, we should not need to check for this, but it is needed for Svelte.
|
|
31
31
|
builderContextValue?.apiKey) {
|
|
32
|
-
return
|
|
32
|
+
return fetchOneEntry({
|
|
33
33
|
model: symbol.model,
|
|
34
34
|
apiKey: builderContextValue.apiKey,
|
|
35
35
|
apiVersion: builderContextValue.apiVersion,
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
} from "../../types/builder-props.js";
|
|
35
35
|
import { filterAttrs } from "../helpers.js";
|
|
36
36
|
import { setAttrs } from "../helpers.js";
|
|
37
|
-
import {
|
|
37
|
+
import { fetchSymbolContent } from "./symbol.helpers.js";
|
|
38
38
|
import type { Nullable } from "../../types/typescript.js";
|
|
39
39
|
|
|
40
40
|
export let js: PropsWithBuilderData<SymbolProps>["js"];
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
|
|
47
47
|
function setContent() {
|
|
48
48
|
if (contentToUse) return;
|
|
49
|
-
|
|
49
|
+
fetchSymbolContent({
|
|
50
50
|
symbol: symbol,
|
|
51
51
|
builderContextValue: $builderContext,
|
|
52
52
|
}).then((newContent) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BuilderContextInterface, RegisteredComponents } from '../../context/types.js';
|
|
2
|
-
import { evaluate } from '../../functions/evaluate';
|
|
2
|
+
import { evaluate } from '../../functions/evaluate/index.js';
|
|
3
3
|
import { getProcessedBlock } from '../../functions/get-processed-block.js';
|
|
4
4
|
import type { BuilderBlock } from '../../types/builder-block.js';
|
|
5
5
|
import type { RepeatData } from './types.js';
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import { setContext } from "svelte";
|
|
11
11
|
import { writable } from "svelte/store";
|
|
12
12
|
|
|
13
|
-
import BuilderContext from "../../../context/builder.context";
|
|
13
|
+
import BuilderContext from "../../../context/builder.context.js";
|
|
14
14
|
import type {
|
|
15
15
|
BuilderContextInterface,
|
|
16
16
|
RegisteredComponents,
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
BuilderContextInterface,
|
|
17
17
|
RegisteredComponents,
|
|
18
18
|
} from "../../context/types.js";
|
|
19
|
-
import BuilderContext from "../../context/builder.context";
|
|
20
|
-
import ComponentsContext from "../../context/components.context";
|
|
19
|
+
import BuilderContext from "../../context/builder.context.js";
|
|
20
|
+
import ComponentsContext from "../../context/components.context.js";
|
|
21
21
|
import type { Writable } from "svelte/store";
|
|
22
22
|
|
|
23
23
|
export let blocks: BlocksProps["blocks"];
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
import { onDestroy, onMount, setContext } from "svelte";
|
|
14
14
|
|
|
15
15
|
import type { BuilderContextInterface } from "../../../context/types.js";
|
|
16
|
-
import { evaluate } from "../../../functions/evaluate";
|
|
16
|
+
import { evaluate } from "../../../functions/evaluate/index.js";
|
|
17
17
|
import { fetch } from "../../../functions/get-fetch.js";
|
|
18
18
|
import { isBrowser } from "../../../functions/is-browser.js";
|
|
19
19
|
import { isEditing } from "../../../functions/is-editing.js";
|
|
20
20
|
import { createRegisterComponentMessage } from "../../../functions/register-component.js";
|
|
21
21
|
import { _track } from "../../../functions/track/index.js";
|
|
22
|
-
import builderContext from "../../../context/builder.context";
|
|
22
|
+
import builderContext from "../../../context/builder.context.js";
|
|
23
23
|
import {
|
|
24
24
|
registerInsertMenu,
|
|
25
25
|
setupBrowserForEditing,
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
} from "../content.types.js";
|
|
33
33
|
import { logger } from "../../../helpers/logger.js";
|
|
34
34
|
import type { ComponentInfo } from "../../../types/components.js";
|
|
35
|
-
import {
|
|
35
|
+
import { fetchOneEntry } from "../../../functions/get-content/index.js";
|
|
36
36
|
import { isPreviewing } from "../../../functions/is-previewing.js";
|
|
37
37
|
import type { BuilderContent } from "../../../types/builder-content.js";
|
|
38
38
|
import { postPreviewContent } from "../../../helpers/preview-lru-cache/set.js";
|
|
@@ -279,7 +279,7 @@
|
|
|
279
279
|
previewApiKey === apiKey &&
|
|
280
280
|
(!content || searchParamPreviewId === content.id)
|
|
281
281
|
) {
|
|
282
|
-
|
|
282
|
+
fetchOneEntry({
|
|
283
283
|
model: model,
|
|
284
284
|
apiKey: apiKey,
|
|
285
285
|
apiVersion: $builderContextSignal.apiVersion,
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
import { wrapComponentRef } from "./wrap-component-ref.js";
|
|
27
27
|
import type { ComponentInfo } from "../../types/components.js";
|
|
28
28
|
import type { Dictionary } from "../../types/typescript.js";
|
|
29
|
-
import ComponentsContext from "../../context/components.context";
|
|
29
|
+
import ComponentsContext from "../../context/components.context.js";
|
|
30
30
|
|
|
31
31
|
export let content: ContentProps["content"];
|
|
32
32
|
export let customComponents: ContentProps["customComponents"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION =
|
|
1
|
+
export const SDK_VERSION = "0.5.6"
|
package/src/constants/target.ts
CHANGED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { getBuilderSearchParams } from './get-builder-search-params/index.js';
|
|
2
|
+
import type { ContentVariantsProps } from '../components/content-variants/content-variants.types.js';
|
|
3
|
+
import type { Dictionary } from '../types/typescript.js';
|
|
4
|
+
import { fetchOneEntry } from './get-content/index.js';
|
|
5
|
+
import type { GetContentOptions } from './get-content/types.js';
|
|
6
|
+
type GetBuilderPropsOptions = (Omit<GetContentOptions, 'model'> & {
|
|
7
|
+
model?: string;
|
|
8
|
+
}) & ({
|
|
9
|
+
/**
|
|
10
|
+
* The current URL path. Used to determine the `urlPath` for targeting content.
|
|
11
|
+
*
|
|
12
|
+
* Cannot be used with `url`.
|
|
13
|
+
*/
|
|
14
|
+
path: string;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The current URL search params. Used to parse the `searchParams` for targeting content.
|
|
18
|
+
*
|
|
19
|
+
* Cannot be used with `url`.
|
|
20
|
+
*/
|
|
21
|
+
searchParams?: URLSearchParams | Dictionary<string | string[]>;
|
|
22
|
+
url?: undefined;
|
|
23
|
+
} | {
|
|
24
|
+
/**
|
|
25
|
+
* The current URL. Used to determine the `urlPath` for targeting content and
|
|
26
|
+
* to parse the `searchParams` for targeting content.
|
|
27
|
+
*
|
|
28
|
+
* Cannot be used with `path` or `searchParams`.
|
|
29
|
+
*/
|
|
30
|
+
url: URL;
|
|
31
|
+
path?: undefined;
|
|
32
|
+
searchParams?: undefined;
|
|
33
|
+
} | {
|
|
34
|
+
url?: undefined;
|
|
35
|
+
path?: undefined;
|
|
36
|
+
searchParams?: undefined;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Fetches builder content, and returns it along with sensible defaults for other props that `Content` needs to render.
|
|
41
|
+
*/
|
|
42
|
+
export const fetchBuilderProps = async (_args: GetBuilderPropsOptions): Promise<ContentVariantsProps> => {
|
|
43
|
+
const urlPath = _args.path || _args.url?.pathname || _args.userAttributes?.urlPath;
|
|
44
|
+
const getContentArgs: GetContentOptions = {
|
|
45
|
+
..._args,
|
|
46
|
+
apiKey: _args.apiKey,
|
|
47
|
+
model: _args.model || 'page',
|
|
48
|
+
userAttributes: {
|
|
49
|
+
..._args.userAttributes,
|
|
50
|
+
...(urlPath ? {
|
|
51
|
+
urlPath
|
|
52
|
+
} : {})
|
|
53
|
+
},
|
|
54
|
+
options: getBuilderSearchParams(_args.searchParams || _args.url?.searchParams || _args.options)
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
apiKey: getContentArgs.apiKey,
|
|
58
|
+
model: getContentArgs.model,
|
|
59
|
+
content: await fetchOneEntry(getContentArgs)
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -9,8 +9,12 @@ import { isBrowser } from '../is-browser.js';
|
|
|
9
9
|
import { generateContentUrl } from './generate-content-url.js';
|
|
10
10
|
import type { GetContentOptions } from './types.js';
|
|
11
11
|
const checkContentHasResults = (content: ContentResponse): content is ContentResults => 'results' in content;
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Returns a the first entry that matches the given options.
|
|
15
|
+
*/
|
|
16
|
+
export async function fetchOneEntry(options: GetContentOptions): Promise<BuilderContent | null> {
|
|
17
|
+
const allContent = await fetchEntries({
|
|
14
18
|
...options,
|
|
15
19
|
limit: 1
|
|
16
20
|
});
|
|
@@ -19,6 +23,14 @@ export async function getContent(options: GetContentOptions): Promise<BuilderCon
|
|
|
19
23
|
}
|
|
20
24
|
return null;
|
|
21
25
|
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated
|
|
29
|
+
* Consider using `fetchBuilderProps` instead for easier setup.
|
|
30
|
+
*
|
|
31
|
+
* NOTE: `getContent` was renamed to `fetchOneEntry` and will be removed in a future release.
|
|
32
|
+
*/
|
|
33
|
+
export const getContent = fetchOneEntry;
|
|
22
34
|
type ContentResults = {
|
|
23
35
|
results: BuilderContent[];
|
|
24
36
|
};
|
|
@@ -26,7 +38,7 @@ type ContentResponse = ContentResults | {
|
|
|
26
38
|
status: number;
|
|
27
39
|
message: string;
|
|
28
40
|
};
|
|
29
|
-
const
|
|
41
|
+
const _fetchContent = async (options: GetContentOptions) => {
|
|
30
42
|
const url = generateContentUrl(options);
|
|
31
43
|
const res = await fetch(url.href);
|
|
32
44
|
const content = await (res.json() as Promise<ContentResponse>);
|
|
@@ -36,7 +48,7 @@ const fetchContent = async (options: GetContentOptions) => {
|
|
|
36
48
|
/**
|
|
37
49
|
* Exported only for testing purposes. Should not be used directly.
|
|
38
50
|
*/
|
|
39
|
-
export const
|
|
51
|
+
export const _processContentResult = async (options: GetContentOptions, content: ContentResults, url: URL = generateContentUrl(options)) => {
|
|
40
52
|
const canTrack = getDefaultCanTrack(options.canTrack);
|
|
41
53
|
const isPreviewing = url.search.includes(`preview=`);
|
|
42
54
|
if (TARGET === 'rsc' && isPreviewing) {
|
|
@@ -70,10 +82,14 @@ export const processContentResult = async (options: GetContentOptions, content:
|
|
|
70
82
|
}
|
|
71
83
|
return content;
|
|
72
84
|
};
|
|
73
|
-
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Returns a paginated array of entries that match the given options.
|
|
88
|
+
*/
|
|
89
|
+
export async function fetchEntries(options: GetContentOptions) {
|
|
74
90
|
try {
|
|
75
91
|
const url = generateContentUrl(options);
|
|
76
|
-
const content = await
|
|
92
|
+
const content = await _fetchContent(options);
|
|
77
93
|
if (!checkContentHasResults(content)) {
|
|
78
94
|
logger.error('Error fetching data. ', {
|
|
79
95
|
url,
|
|
@@ -82,9 +98,14 @@ export async function getAllContent(options: GetContentOptions) {
|
|
|
82
98
|
});
|
|
83
99
|
return null;
|
|
84
100
|
}
|
|
85
|
-
return
|
|
101
|
+
return _processContentResult(options, content);
|
|
86
102
|
} catch (error) {
|
|
87
103
|
logger.error('Error fetching data. ', error);
|
|
88
104
|
return null;
|
|
89
105
|
}
|
|
90
|
-
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @deprecated Use `fetchEntries` instead.
|
|
110
|
+
*/
|
|
111
|
+
export const getAllContent = fetchEntries
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BuilderContextInterface } from '../context/types.js';
|
|
2
2
|
import type { BuilderBlock } from '../types/builder-block.js';
|
|
3
|
-
import { evaluate } from './evaluate';
|
|
3
|
+
import { evaluate } from './evaluate/index.js';
|
|
4
4
|
import { fastClone } from './fast-clone.js';
|
|
5
5
|
import { set } from './set.js';
|
|
6
6
|
import { transformBlock } from './transform-block.js';
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export function getPreviewContent(searchParams: URLSearchParams) {
|
|
5
|
-
init();
|
|
6
|
-
const id = getIdFromSearchParams(searchParams);
|
|
7
|
-
return typeof id === 'string' ? (globalThis as GlobalWCache)._BUILDER_PREVIEW_LRU_CACHE.get(id) : undefined;
|
|
1
|
+
import type { BuilderContent } from '../../types/builder-content.js';
|
|
2
|
+
export function getPreviewContent(_searchParams: URLSearchParams): BuilderContent | undefined {
|
|
3
|
+
return undefined;
|
|
8
4
|
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { logger } from '../logger';
|
|
2
|
-
export const getIdFromSearchParams = (searchParams: URLSearchParams) => {
|
|
3
|
-
const previewedModel = searchParams.get('preview');
|
|
4
|
-
const previewedId = searchParams.get('overrides.' + previewedModel);
|
|
5
|
-
if (!previewedId) {
|
|
6
|
-
logger.warn('No previewed ID found in search params.');
|
|
7
|
-
}
|
|
8
|
-
return previewedId;
|
|
9
|
-
}
|
|
@@ -4,14 +4,4 @@
|
|
|
4
4
|
* Note: This logic is only used by the NextJS SDK.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
import type { GlobalWCache } from './types';
|
|
9
|
-
export function init() {
|
|
10
|
-
if (!(globalThis as GlobalWCache)._BUILDER_PREVIEW_LRU_CACHE) {
|
|
11
|
-
(globalThis as GlobalWCache)._BUILDER_PREVIEW_LRU_CACHE = new LRUCache({
|
|
12
|
-
max: 500,
|
|
13
|
-
// how long to live in ms
|
|
14
|
-
ttl: 1000 * 60 * 5
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
}
|
|
7
|
+
export function init() {}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type { BuilderContent } from '../../types/builder-content';
|
|
4
|
-
import { init } from './init';
|
|
5
|
-
import type { GlobalWCache } from './types';
|
|
1
|
+
import type { BuilderContent } from '../../types/builder-content.js';
|
|
6
2
|
export async function postPreviewContent({
|
|
7
3
|
key,
|
|
8
4
|
value
|
|
@@ -10,8 +6,6 @@ export async function postPreviewContent({
|
|
|
10
6
|
key: string;
|
|
11
7
|
value: BuilderContent;
|
|
12
8
|
}) {
|
|
13
|
-
init();
|
|
14
|
-
(globalThis as GlobalWCache)._BUILDER_PREVIEW_LRU_CACHE.set(key, value);
|
|
15
9
|
return {
|
|
16
10
|
[key]: value
|
|
17
11
|
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is an LRU cache to hold preview content on the server-side.
|
|
3
|
-
*
|
|
4
|
-
* Note: This logic is only used by the NextJS SDK.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { LRUCache } from 'lru-cache';
|
|
8
|
-
import type { BuilderContent } from '../../types/builder-content';
|
|
9
|
-
type BuilderLRUCache = LRUCache<string, BuilderContent>;
|
|
10
|
-
export type GlobalWCache = typeof globalThis & {
|
|
11
|
-
_BUILDER_PREVIEW_LRU_CACHE: BuilderLRUCache;
|
|
12
|
-
}
|
|
@@ -2,9 +2,19 @@ export { default as Button } from '../blocks/button/button.svelte';
|
|
|
2
2
|
export { default as Columns } from '../blocks/columns/columns.svelte';
|
|
3
3
|
export { default as Fragment } from '../blocks/fragment/fragment.svelte';
|
|
4
4
|
export { default as Image } from '../blocks/image/image.svelte';
|
|
5
|
-
export { default as RenderBlocks } from '../components/blocks/blocks.svelte';
|
|
6
5
|
export { default as Section } from '../blocks/section/section.svelte';
|
|
7
6
|
export { default as Symbol } from '../blocks/symbol/symbol.svelte';
|
|
8
7
|
export { default as Text } from '../blocks/text/text.svelte';
|
|
9
8
|
export { default as Video } from '../blocks/video/video.svelte';
|
|
10
|
-
|
|
9
|
+
import { default as Blocks } from '../components/blocks/blocks.svelte';
|
|
10
|
+
import { default as Content } from '../components/content-variants/content-variants.svelte';
|
|
11
|
+
export { Blocks, Content };
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Use `Blocks` instead.
|
|
15
|
+
*/
|
|
16
|
+
export const RenderBlocks = Blocks;
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Use `Content` instead.
|
|
19
|
+
*/
|
|
20
|
+
export const RenderContent = Content
|
package/src/index.ts
CHANGED
|
@@ -7,9 +7,10 @@ export { register } from './functions/register.js';
|
|
|
7
7
|
export type { InsertMenuConfig, InsertMenuItem } from './functions/register.js';
|
|
8
8
|
export { setEditorSettings } from './functions/set-editor-settings.js';
|
|
9
9
|
export type { Settings } from './functions/set-editor-settings.js';
|
|
10
|
-
export { getAllContent, getContent,
|
|
10
|
+
export { fetchEntries, fetchOneEntry, getAllContent, getContent, _processContentResult } from './functions/get-content/index.js';
|
|
11
11
|
export { getBuilderSearchParams } from './functions/get-builder-search-params/index.js';
|
|
12
12
|
export { track } from './functions/track/index.js';
|
|
13
|
-
export type { RegisteredComponent } from './context/types';
|
|
14
|
-
export type { ComponentInfo } from './types/components';
|
|
15
|
-
export type { ContentProps } from './components/content/content.types.js'
|
|
13
|
+
export type { RegisteredComponent } from './context/types.js';
|
|
14
|
+
export type { ComponentInfo } from './types/components.js';
|
|
15
|
+
export type { ContentProps } from './components/content/content.types.js';
|
|
16
|
+
export { fetchBuilderProps } from './functions/fetch-builder-props.js'
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { TARGET } from '../constants/target.js';
|
|
2
|
-
// TODO: babel compile to include certain code only if the target matches
|
|
3
|
-
export function ifTarget({ targets, doThing, elseThing }) {
|
|
4
|
-
if (TARGET && targets.includes(TARGET)) {
|
|
5
|
-
return doThing();
|
|
6
|
-
}
|
|
7
|
-
else {
|
|
8
|
-
return elseThing?.();
|
|
9
|
-
}
|
|
10
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { TARGET } from '../constants/target.js';
|
|
2
|
-
type Target = import('../types/targets').Target;
|
|
3
|
-
|
|
4
|
-
// TODO: babel compile to include certain code only if the target matches
|
|
5
|
-
export function ifTarget<A, B>({
|
|
6
|
-
targets,
|
|
7
|
-
doThing,
|
|
8
|
-
elseThing
|
|
9
|
-
}: {
|
|
10
|
-
targets: Target[];
|
|
11
|
-
doThing: () => A;
|
|
12
|
-
elseThing?: () => B;
|
|
13
|
-
}) {
|
|
14
|
-
if (TARGET && targets.includes(TARGET)) {
|
|
15
|
-
return doThing();
|
|
16
|
-
} else {
|
|
17
|
-
return elseThing?.();
|
|
18
|
-
}
|
|
19
|
-
}
|