@builder.io/sdk-react-nextjs 0.5.5 → 0.5.7
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/dist/blocks/symbol/symbol.helpers.d.ts +1 -1
- package/dist/blocks/symbol/symbol.helpers.js +3 -3
- package/dist/blocks/symbol/symbol.js +2 -2
- package/dist/components/block/block.helpers.js +1 -1
- package/dist/components/blocks/blocks-wrapper.js +2 -2
- package/dist/components/content/components/enable-editor.js +2 -2
- package/dist/constants/sdk-version.d.ts +1 -1
- package/dist/constants/sdk-version.js +1 -1
- package/dist/functions/fetch-builder-props.d.ts +39 -0
- package/dist/functions/fetch-builder-props.js +25 -0
- package/dist/functions/get-content/index.d.ts +20 -3
- package/dist/functions/get-content/index.js +24 -7
- package/dist/functions/get-processed-block.js +1 -1
- package/dist/functions/is-non-node-server.js +1 -1
- package/dist/index-helpers/blocks-exports.d.ts +11 -2
- package/dist/index-helpers/blocks-exports.js +11 -2
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -1
- package/package.json +10 -2
|
@@ -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<any>;
|
|
@@ -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,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import ContentVariants from "../../components/content-variants/content-variants";
|
|
3
|
-
import {
|
|
3
|
+
import { fetchSymbolContent } from "./symbol.helpers.js";
|
|
4
4
|
async function Symbol(props) {
|
|
5
5
|
const className = function className() {
|
|
6
6
|
return [
|
|
@@ -15,7 +15,7 @@ async function Symbol(props) {
|
|
|
15
15
|
.join(" ");
|
|
16
16
|
};
|
|
17
17
|
const contentToUse = (props.symbol?.content ||
|
|
18
|
-
(await
|
|
18
|
+
(await fetchSymbolContent({
|
|
19
19
|
symbol: props.symbol,
|
|
20
20
|
builderContextValue: props.builderContext,
|
|
21
21
|
})));
|
|
@@ -28,8 +28,8 @@ function BlocksWrapper(props) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
return (React.createElement(React.Fragment, null,
|
|
31
|
-
React.createElement("div", { className: className() + " div-
|
|
32
|
-
React.createElement("style", null, `.div-
|
|
31
|
+
React.createElement("div", { className: className() + " div-5285fe33", "builder-path": props.path, "builder-parent-id": props.parent, style: props.styleProp, onClick: (event) => onClick(), onMouseEnter: (event) => onMouseEnter(), onKeyPress: (event) => onClick() }, props.children),
|
|
32
|
+
React.createElement("style", null, `.div-5285fe33 {
|
|
33
33
|
display: flex;
|
|
34
34
|
flex-direction: column;
|
|
35
35
|
align-items: stretch;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { useState, useRef, useEffect } from "react";
|
|
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";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "
|
|
1
|
+
export declare const SDK_VERSION = "0.5.7";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION =
|
|
1
|
+
export const SDK_VERSION = "0.5.7";
|
|
@@ -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>;
|
|
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;
|
|
@@ -2,9 +2,18 @@ export { default as Button } from '../blocks/button/button';
|
|
|
2
2
|
export { default as Columns } from '../blocks/columns/columns';
|
|
3
3
|
export { default as Fragment } from '../blocks/fragment/fragment';
|
|
4
4
|
export { default as Image } from '../blocks/image/image';
|
|
5
|
-
export { default as RenderBlocks } from '../components/blocks/blocks';
|
|
6
5
|
export { default as Section } from '../blocks/section/section';
|
|
7
6
|
export { default as Symbol } from '../blocks/symbol/symbol';
|
|
8
7
|
export { default as Text } from '../blocks/text/text';
|
|
9
8
|
export { default as Video } from '../blocks/video/video';
|
|
10
|
-
|
|
9
|
+
import { default as Blocks } from '../components/blocks/blocks';
|
|
10
|
+
import { default as Content } from '../components/content-variants/content-variants';
|
|
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';
|
|
|
2
2
|
export { default as Columns } from '../blocks/columns/columns';
|
|
3
3
|
export { default as Fragment } from '../blocks/fragment/fragment';
|
|
4
4
|
export { default as Image } from '../blocks/image/image';
|
|
5
|
-
export { default as RenderBlocks } from '../components/blocks/blocks';
|
|
6
5
|
export { default as Section } from '../blocks/section/section';
|
|
7
6
|
export { default as Symbol } from '../blocks/symbol/symbol';
|
|
8
7
|
export { default as Text } from '../blocks/text/text';
|
|
9
8
|
export { default as Video } from '../blocks/video/video';
|
|
10
|
-
|
|
9
|
+
import { default as Blocks } from '../components/blocks/blocks';
|
|
10
|
+
import { default as Content } from '../components/content-variants/content-variants';
|
|
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/dist/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/dist/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-react-nextjs",
|
|
3
3
|
"description": "Builder.io SDK for React",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.7",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
7
7
|
],
|
|
@@ -32,6 +32,14 @@
|
|
|
32
32
|
"nx": {
|
|
33
33
|
"implicitDependencies": [
|
|
34
34
|
"@builder.io/sdks"
|
|
35
|
-
]
|
|
35
|
+
],
|
|
36
|
+
"targets": {
|
|
37
|
+
"build": {
|
|
38
|
+
"dependsOn": [
|
|
39
|
+
"^build:nextjs",
|
|
40
|
+
"^build"
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
}
|
|
36
44
|
}
|
|
37
45
|
}
|