@builder.io/sdk-react-nextjs 0.4.6-0 → 0.5.1
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/README.md +32 -44
- package/dist/blocks/button/button.d.ts +1 -2
- package/dist/blocks/button/button.js +2 -2
- package/dist/blocks/columns/columns.js +6 -6
- package/dist/blocks/embed/component-info.js +2 -1
- package/dist/blocks/image/component-info.js +2 -1
- package/dist/blocks/image/image.js +8 -7
- package/dist/blocks/img/img.d.ts +1 -2
- package/dist/blocks/section/section.d.ts +1 -2
- package/dist/blocks/symbol/symbol.d.ts +2 -4
- package/dist/blocks/symbol/symbol.helpers.js +2 -1
- package/dist/blocks/symbol/symbol.js +3 -3
- package/dist/blocks/video/video.js +4 -1
- package/dist/components/block/block.helpers.js +5 -3
- package/dist/components/block/block.js +4 -4
- package/dist/components/block/components/block-styles.js +1 -1
- package/dist/components/block/components/block-wrapper.d.ts +1 -2
- package/dist/components/block/components/component-ref/component-ref.helpers.d.ts +1 -1
- package/dist/components/block/components/component-ref/component-ref.helpers.js +2 -1
- package/dist/components/block/components/component-ref/component-ref.js +3 -3
- package/dist/components/block/components/repeated-block.js +1 -1
- package/dist/components/blocks/blocks.d.ts +3 -3
- package/dist/components/blocks/blocks.js +3 -3
- package/dist/components/content/components/enable-editor.js +1 -1
- package/dist/components/content/components/styles.helpers.js +4 -2
- package/dist/components/content/components/styles.js +1 -1
- package/dist/components/content/content.helpers.js +10 -5
- package/dist/components/content/content.js +6 -4
- package/dist/components/content-variants/content-variants.js +3 -3
- package/dist/components/content-variants/helpers.js +2 -1
- package/dist/constants/builder-registered-components.js +11 -11
- package/dist/constants/sdk-version.d.ts +1 -1
- package/dist/constants/sdk-version.js +1 -1
- package/dist/context/components.context.d.ts +3 -0
- package/dist/context/components.context.js +2 -0
- package/dist/functions/evaluate/evaluate.d.ts +10 -0
- package/dist/functions/evaluate/evaluate.js +70 -0
- package/dist/functions/evaluate/index.d.ts +1 -0
- package/dist/functions/evaluate/index.js +1 -0
- package/dist/functions/evaluate/interpreter.d.ts +2 -0
- package/dist/functions/evaluate/interpreter.js +3853 -0
- package/dist/functions/evaluate/non-node-runtime.d.ts +2 -0
- package/dist/functions/evaluate/non-node-runtime.js +84 -0
- package/dist/functions/evaluate/types.d.ts +10 -0
- package/dist/functions/evaluate/types.js +1 -0
- package/dist/functions/extract-text-styles.js +2 -1
- package/dist/functions/get-block-actions-handler.js +1 -1
- package/dist/functions/get-block-component-options.js +4 -2
- package/dist/functions/get-block-properties.js +2 -1
- package/dist/functions/get-content/generate-content-url.js +2 -1
- package/dist/functions/get-content/index.d.ts +1 -5
- package/dist/functions/get-content/index.js +4 -3
- package/dist/functions/get-processed-block.js +7 -4
- package/dist/functions/get-react-native-block-styles.js +1 -0
- package/dist/functions/is-non-node-server.d.ts +4 -0
- package/dist/functions/is-non-node-server.js +8 -0
- package/dist/functions/register-component.js +8 -4
- package/dist/functions/sanitize-react-native-block-styles.js +6 -3
- package/dist/functions/track/helpers.js +2 -1
- package/dist/functions/track/index.js +4 -2
- package/dist/functions/transform-block.js +1 -0
- package/dist/helpers/ab-tests.js +12 -6
- package/dist/helpers/cookie.js +2 -1
- package/dist/helpers/flatten.js +4 -2
- package/dist/helpers/preview-lru-cache/init.d.ts +5 -0
- package/dist/helpers/preview-lru-cache/types.js +5 -0
- package/dist/index-helpers/blocks-exports.d.ts +10 -10
- package/dist/index-helpers/blocks-exports.js +10 -10
- package/dist/scripts/init-editing.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# Builder.io React SDK
|
|
1
|
+
# Builder.io React NextJS SDK (BETA)
|
|
2
2
|
|
|
3
|
-
This is the
|
|
3
|
+
This is the Builder NextJS SDK, `@builder.io/sdk-react-nextjs`. It is intended to be used _only_ with NextJS's app directory, and has hard dependencies on NextJS-specific functionality that only works in the app directory.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
If you are using NextJS's pages directory, use the [React gen2 SDK](../react/) in Beta, or the stable React gen1 SDK [here](../../../react/) (i.e. `builder.io/react`).
|
|
6
6
|
|
|
7
7
|
## API Reference
|
|
8
8
|
|
|
@@ -10,8 +10,6 @@ To use the SDK, you need to:
|
|
|
10
10
|
|
|
11
11
|
- fetch the builder data using `getContent`: you can see how to use it here https://www.builder.io/c/docs/content-api, and how it differs from the React V1 SDK's `builder.get()` function.
|
|
12
12
|
|
|
13
|
-
NOTE: if you are using the SDK in next v13's app directory, you will have to import `getContent` from @builder.io/sdk-react/server`. this is a special import that guarantees you don't import any client components with your data fetching.
|
|
14
|
-
|
|
15
13
|
- pass that data to the `RenderContent` component, along with the following properties:
|
|
16
14
|
|
|
17
15
|
```ts
|
|
@@ -29,40 +27,35 @@ type RenderContentProps = {
|
|
|
29
27
|
};
|
|
30
28
|
```
|
|
31
29
|
|
|
32
|
-
Here is a simplified example showing how you would use both:
|
|
30
|
+
Here is a simplified example showing how you would use both. This needs to be created created with the name `app/[[...slug]]/page.tsx`, so it catches all routes:
|
|
33
31
|
|
|
34
32
|
```tsx
|
|
35
|
-
import {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
apiKey={BUILDER_PUBLIC_API_KEY}
|
|
62
|
-
/>
|
|
63
|
-
) : (
|
|
64
|
-
<div>Content Not Found</div>
|
|
65
|
-
);
|
|
33
|
+
import {
|
|
34
|
+
RenderContent,
|
|
35
|
+
getBuilderSearchParams,
|
|
36
|
+
getContent,
|
|
37
|
+
} from '@builder.io/sdk-react-nextjs';
|
|
38
|
+
|
|
39
|
+
interface MyPageProps {
|
|
40
|
+
params: {
|
|
41
|
+
slug: string[];
|
|
42
|
+
};
|
|
43
|
+
searchParams: Record<string, string>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const apiKey = 'YOUR_API_KEY_HERE';
|
|
47
|
+
|
|
48
|
+
export default async function Page(props: MyPageProps) {
|
|
49
|
+
const urlPath = '/' + (props.params?.slug?.join('/') || '');
|
|
50
|
+
|
|
51
|
+
const content = await getContent({
|
|
52
|
+
model: 'page',
|
|
53
|
+
apiKey,
|
|
54
|
+
options: getBuilderSearchParams(props.searchParams),
|
|
55
|
+
userAttributes: { urlPath },
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return <RenderContent content={content} model="page" apiKey={apiKey} />;
|
|
66
59
|
}
|
|
67
60
|
```
|
|
68
61
|
|
|
@@ -79,14 +72,9 @@ To check the status of the SDK, look at [these tables](../../README.md#feature-i
|
|
|
79
72
|
## Getting Started
|
|
80
73
|
|
|
81
74
|
```
|
|
82
|
-
npm install @builder.io/sdk-react
|
|
75
|
+
npm install @builder.io/sdk-react-nextjs
|
|
83
76
|
```
|
|
84
77
|
|
|
85
78
|
## Examples
|
|
86
79
|
|
|
87
|
-
- [
|
|
88
|
-
- [Next.js + app dir](../../../../examples/next-app-directory)
|
|
89
|
-
|
|
90
|
-
## Fetch
|
|
91
|
-
|
|
92
|
-
This Package uses fetch. See [these docs](https://github.com/BuilderIO/this-package-uses-fetch/blob/main/README.md) for more information.
|
|
80
|
+
- [Next.js SDK](../../../../examples/next-js-sdk-gen-2-experimental-app-directory)
|
|
@@ -4,8 +4,8 @@ function Button(props) {
|
|
|
4
4
|
return (React.createElement(React.Fragment, null,
|
|
5
5
|
props.link ? (React.createElement(React.Fragment, null,
|
|
6
6
|
React.createElement("a", { role: "button", ...props.attributes, href: props.link, target: props.openLinkInNewTab ? "_blank" : undefined }, props.text))) : (React.createElement(React.Fragment, null,
|
|
7
|
-
React.createElement("button", { ...props.attributes, style: props.attributes.style, className: props.attributes.className + " button-
|
|
8
|
-
React.createElement("style", null, `.button-
|
|
7
|
+
React.createElement("button", { ...props.attributes, style: props.attributes.style, className: props.attributes.className + " button-7267e9c6" }, props.text))),
|
|
8
|
+
React.createElement("style", null, `.button-7267e9c6 {
|
|
9
9
|
all: unset;
|
|
10
10
|
}`)));
|
|
11
11
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import Blocks from "../../components/blocks/blocks
|
|
2
|
+
import Blocks from "../../components/blocks/blocks";
|
|
3
3
|
import { getSizesForBreakpoints } from "../../constants/device-sizes.js";
|
|
4
|
-
import InlinedStyles from "../../components/inlined-styles
|
|
4
|
+
import InlinedStyles from "../../components/inlined-styles";
|
|
5
5
|
import { TARGET } from "../../constants/target.js";
|
|
6
6
|
function Columns(props) {
|
|
7
7
|
const gutterSize = typeof props.space === "number" ? props.space || 0 : 20;
|
|
@@ -100,17 +100,17 @@ function Columns(props) {
|
|
|
100
100
|
};
|
|
101
101
|
return (React.createElement(React.Fragment, null,
|
|
102
102
|
React.createElement("div", { className: `builder-columns ${props.builderBlock.id}-breakpoints` +
|
|
103
|
-
" div-
|
|
103
|
+
" div-3ec60680", style: columnsCssVars() },
|
|
104
104
|
TARGET !== "reactNative" ? (React.createElement(React.Fragment, null,
|
|
105
105
|
React.createElement(InlinedStyles, { styles: columnsStyles() }))) : null,
|
|
106
|
-
props.columns?.map((column, index) => (React.createElement("div", { className: "builder-column div-
|
|
106
|
+
props.columns?.map((column, index) => (React.createElement("div", { className: "builder-column div-3ec60680-2", style: columnCssVars(index), key: index },
|
|
107
107
|
React.createElement(Blocks, { blocks: column.blocks, path: `component.options.columns.${index}.blocks`, parent: props.builderBlock.id, styleProp: {
|
|
108
108
|
flexGrow: "1",
|
|
109
109
|
}, context: props.builderContext, registeredComponents: props.builderComponents }))))),
|
|
110
|
-
React.createElement("style", null, `.div-
|
|
110
|
+
React.createElement("style", null, `.div-3ec60680 {
|
|
111
111
|
display: flex;
|
|
112
112
|
line-height: normal;
|
|
113
|
-
}.div-
|
|
113
|
+
}.div-3ec60680-2 {
|
|
114
114
|
display: flex;
|
|
115
115
|
flex-direction: column;
|
|
116
116
|
align-items: stretch;
|
|
@@ -10,7 +10,8 @@ export const componentInfo = {
|
|
|
10
10
|
onChange: (options) => {
|
|
11
11
|
const url = options.get('url');
|
|
12
12
|
if (url) {
|
|
13
|
-
options.set('content', 'Loading...');
|
|
13
|
+
options.set('content', 'Loading...');
|
|
14
|
+
// TODO: get this out of here!
|
|
14
15
|
const apiKey = 'ae0e60e78201a3f2b0de4b';
|
|
15
16
|
return fetch(`https://iframe.ly/api/iframely?url=${url}&api_key=${apiKey}`).then(res => res.json()).then(data => {
|
|
16
17
|
if (options.get('url') === url) {
|
|
@@ -44,7 +44,8 @@ export const componentInfo = {
|
|
|
44
44
|
return Math.round(num * 1000) / 1000;
|
|
45
45
|
}
|
|
46
46
|
const value = options.get('image');
|
|
47
|
-
const aspectRatio = options.get('aspectRatio');
|
|
47
|
+
const aspectRatio = options.get('aspectRatio');
|
|
48
|
+
// For SVG images - don't render as webp, keep them as SVG
|
|
48
49
|
fetch(value).then(res => res.blob()).then(blob => {
|
|
49
50
|
if (blob.type.includes('svg')) {
|
|
50
51
|
options.set('noWebp', true);
|
|
@@ -5,7 +5,8 @@ function Image(props) {
|
|
|
5
5
|
function srcSetToUse() {
|
|
6
6
|
const imageToUse = props.image || props.src;
|
|
7
7
|
const url = imageToUse;
|
|
8
|
-
if (!url ||
|
|
8
|
+
if (!url ||
|
|
9
|
+
// We can auto add srcset for cdn.builder.io and shopify
|
|
9
10
|
// images, otherwise you can supply this prop manually
|
|
10
11
|
!(url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/))) {
|
|
11
12
|
return props.srcset;
|
|
@@ -51,23 +52,23 @@ function Image(props) {
|
|
|
51
52
|
...aspectRatioCss(),
|
|
52
53
|
}, className: "builder-image" +
|
|
53
54
|
(props.className ? " " + props.className : "") +
|
|
54
|
-
" img-
|
|
55
|
+
" img-7c5f6b46", src: props.image, srcSet: srcSetToUse(), sizes: props.sizes })),
|
|
55
56
|
props.aspectRatio &&
|
|
56
57
|
!(props.builderBlock?.children?.length && props.fitContent) ? (React.createElement(React.Fragment, null,
|
|
57
|
-
React.createElement("div", { className: "builder-image-sizer div-
|
|
58
|
+
React.createElement("div", { className: "builder-image-sizer div-7c5f6b46", style: {
|
|
58
59
|
paddingTop: props.aspectRatio * 100 + "%",
|
|
59
60
|
} }))) : null,
|
|
60
61
|
props.builderBlock?.children?.length && props.fitContent ? (React.createElement(React.Fragment, null, props.children)) : null,
|
|
61
62
|
!props.fitContent && props.children ? (React.createElement(React.Fragment, null,
|
|
62
|
-
React.createElement("div", { className: "div-
|
|
63
|
-
React.createElement("style", null, `.img-
|
|
63
|
+
React.createElement("div", { className: "div-7c5f6b46-2" }, props.children))) : null),
|
|
64
|
+
React.createElement("style", null, `.img-7c5f6b46 {
|
|
64
65
|
opacity: 1;
|
|
65
66
|
transition: opacity 0.2s ease-in-out;
|
|
66
|
-
}.div-
|
|
67
|
+
}.div-7c5f6b46 {
|
|
67
68
|
width: 100%;
|
|
68
69
|
pointer-events: none;
|
|
69
70
|
font-size: 0;
|
|
70
|
-
}.div-
|
|
71
|
+
}.div-7c5f6b46-2 {
|
|
71
72
|
display: flex;
|
|
72
73
|
flex-direction: column;
|
|
73
74
|
align-items: stretch;
|
package/dist/blocks/img/img.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This import is used by the Svelte SDK. Do not remove.
|
|
3
|
-
*/
|
|
4
|
-
export interface SymbolInfo {
|
|
3
|
+
*/ export interface SymbolInfo {
|
|
5
4
|
model?: string;
|
|
6
5
|
entry?: string;
|
|
7
6
|
data?: any;
|
|
@@ -11,8 +10,7 @@ export interface SymbolInfo {
|
|
|
11
10
|
}
|
|
12
11
|
/**
|
|
13
12
|
* This import is used by the Svelte SDK. Do not remove.
|
|
14
|
-
*/
|
|
15
|
-
export interface SymbolProps extends BuilderComponentsProp {
|
|
13
|
+
*/ export interface SymbolProps extends BuilderComponentsProp {
|
|
16
14
|
symbol?: SymbolInfo;
|
|
17
15
|
dataOnly?: boolean;
|
|
18
16
|
dynamic?: boolean;
|
|
@@ -10,7 +10,8 @@ export const fetchContent = async ({ builderContextValue, symbol }) => {
|
|
|
10
10
|
*
|
|
11
11
|
* then we want to re-fetch the symbol content.
|
|
12
12
|
*/
|
|
13
|
-
if (symbol?.model &&
|
|
13
|
+
if (symbol?.model &&
|
|
14
|
+
// This is a hack, we should not need to check for this, but it is needed for Svelte.
|
|
14
15
|
builderContextValue?.apiKey) {
|
|
15
16
|
return getContent({
|
|
16
17
|
model: symbol.model,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import ContentVariants from "../../components/content-variants/content-variants
|
|
2
|
+
import ContentVariants from "../../components/content-variants/content-variants";
|
|
3
3
|
import { fetchContent } from "./symbol.helpers.js";
|
|
4
4
|
async function Symbol(props) {
|
|
5
5
|
const className = function className() {
|
|
@@ -14,11 +14,11 @@ async function Symbol(props) {
|
|
|
14
14
|
.filter(Boolean)
|
|
15
15
|
.join(" ");
|
|
16
16
|
};
|
|
17
|
-
const contentToUse = props.symbol?.content ||
|
|
17
|
+
const contentToUse = (props.symbol?.content ||
|
|
18
18
|
(await fetchContent({
|
|
19
19
|
symbol: props.symbol,
|
|
20
20
|
builderContextValue: props.builderContext,
|
|
21
|
-
}));
|
|
21
|
+
})));
|
|
22
22
|
return (React.createElement("div", { ...props.attributes, className: className() },
|
|
23
23
|
React.createElement(ContentVariants, { __isNestedRender: true, apiVersion: props.builderContext.apiVersion, apiKey: props.builderContext.apiKey, context: props.builderContext.context, customComponents: Object.values(props.builderComponents), data: {
|
|
24
24
|
...props.symbol?.data,
|
|
@@ -31,7 +31,10 @@ function Video(props) {
|
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
function spreadProps() {
|
|
34
|
-
return {
|
|
34
|
+
return {
|
|
35
|
+
...props.attributes,
|
|
36
|
+
...videoProps(),
|
|
37
|
+
};
|
|
35
38
|
}
|
|
36
39
|
return (React.createElement("video", { ...spreadProps(), preload: props.preload || "metadata", style: {
|
|
37
40
|
width: "100%",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { evaluate } from '../../functions/evaluate
|
|
1
|
+
import { evaluate } from '../../functions/evaluate';
|
|
2
2
|
import { getProcessedBlock } from '../../functions/get-processed-block.js';
|
|
3
3
|
/**
|
|
4
4
|
* https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
|
|
@@ -53,8 +53,10 @@ export const getRepeatItemData = ({ block, context }) => {
|
|
|
53
53
|
const collectionName = repeat.collection.split('.').pop();
|
|
54
54
|
const itemNameToUse = repeat.itemName || (collectionName ? collectionName + 'Item' : 'item');
|
|
55
55
|
const repeatArray = itemsArray.map((item, index) => ({
|
|
56
|
-
context: {
|
|
57
|
-
|
|
56
|
+
context: {
|
|
57
|
+
...context,
|
|
58
|
+
localState: {
|
|
59
|
+
...context.localState,
|
|
58
60
|
$index: index,
|
|
59
61
|
$item: item,
|
|
60
62
|
[itemNameToUse]: item,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
|
|
3
3
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
4
|
-
import BlockStyles from "./components/block-styles
|
|
4
|
+
import BlockStyles from "./components/block-styles";
|
|
5
5
|
import { getComponent, getRepeatItemData, isEmptyHtmlElement, } from "./block.helpers.js";
|
|
6
|
-
import RepeatedBlock from "./components/repeated-block
|
|
7
|
-
import ComponentRef from "./components/component-ref/component-ref
|
|
8
|
-
import BlockWrapper from "./components/block-wrapper
|
|
6
|
+
import RepeatedBlock from "./components/repeated-block";
|
|
7
|
+
import ComponentRef from "./components/component-ref/component-ref";
|
|
8
|
+
import BlockWrapper from "./components/block-wrapper";
|
|
9
9
|
function Block(props) {
|
|
10
10
|
const blockComponent = function blockComponent() {
|
|
11
11
|
return getComponent({
|
|
@@ -6,7 +6,7 @@ import { TARGET } from "../../../constants/target.js";
|
|
|
6
6
|
import { getProcessedBlock } from "../../../functions/get-processed-block.js";
|
|
7
7
|
import { createCssClass } from "../../../helpers/css.js";
|
|
8
8
|
import { checkIsDefined } from "../../../helpers/nullable.js";
|
|
9
|
-
import InlinedStyles from "../../inlined-styles
|
|
9
|
+
import InlinedStyles from "../../inlined-styles";
|
|
10
10
|
function BlockStyles(props) {
|
|
11
11
|
const [processedBlock, setProcessedBlock] = useState(() => getProcessedBlock({
|
|
12
12
|
block: props.block,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BuilderContextInterface, RegisteredComponents } from '../../../../context/types.js';
|
|
2
2
|
import type { BuilderBlock } from '../../../../types/builder-block.js';
|
|
3
3
|
import type { PropsWithBuilderData } from '../../../../types/builder-props.js';
|
|
4
|
-
import type { InteractiveElementProps } from '../interactive-element
|
|
4
|
+
import type { InteractiveElementProps } from '../interactive-element';
|
|
5
5
|
type ComponentOptions = PropsWithBuilderData<{
|
|
6
6
|
[index: string]: any;
|
|
7
7
|
attributes?: {
|
|
@@ -6,7 +6,8 @@ export const getWrapperProps = ({ componentOptions, builderBlock, context, compo
|
|
|
6
6
|
context,
|
|
7
7
|
wrapperProps: componentOptions
|
|
8
8
|
};
|
|
9
|
-
return isInteractive ? interactiveElementProps : {
|
|
9
|
+
return isInteractive ? interactiveElementProps : {
|
|
10
|
+
...componentOptions,
|
|
10
11
|
/**
|
|
11
12
|
* If `noWrap` is set to `true`, then the block's props/attributes are provided to the
|
|
12
13
|
* component itself directly. Otherwise, they are provided to the wrapper element.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import BlockStyles from "../block-styles
|
|
3
|
-
import Block from "../../block
|
|
4
|
-
import InteractiveElement from "../interactive-element
|
|
2
|
+
import BlockStyles from "../block-styles";
|
|
3
|
+
import Block from "../../block";
|
|
4
|
+
import InteractiveElement from "../interactive-element";
|
|
5
5
|
import { getWrapperProps } from "./component-ref.helpers.js";
|
|
6
6
|
function ComponentRef(props) {
|
|
7
7
|
const Wrapper = props.isInteractive ? InteractiveElement : props.componentRef;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import Block from "../block
|
|
2
|
+
import Block from "../block";
|
|
3
3
|
function RepeatedBlock(props) {
|
|
4
4
|
const store = props.repeatContext;
|
|
5
5
|
return (React.createElement(Block, { block: props.block, context: store, registeredComponents: props.registeredComponents }));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export type BlocksProps = Partial<BlocksWrapperProps> & {
|
|
2
|
-
context
|
|
3
|
-
registeredComponents
|
|
2
|
+
context?: BuilderContextInterface;
|
|
3
|
+
registeredComponents?: RegisteredComponents;
|
|
4
4
|
};
|
|
5
|
-
import type { BlocksWrapperProps } from "./blocks-wrapper
|
|
5
|
+
import type { BlocksWrapperProps } from "./blocks-wrapper";
|
|
6
6
|
import type { BuilderContextInterface, RegisteredComponents } from "../../context/types.js";
|
|
7
7
|
declare function Blocks(props: BlocksProps): JSX.Element;
|
|
8
8
|
export default Blocks;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import BlockStyles from "../block/components/block-styles
|
|
3
|
-
import Block from "../block/block
|
|
4
|
-
import BlocksWrapper from "./blocks-wrapper
|
|
2
|
+
import BlockStyles from "../block/components/block-styles";
|
|
3
|
+
import Block from "../block/block";
|
|
4
|
+
import BlocksWrapper from "./blocks-wrapper";
|
|
5
5
|
function Blocks(props) {
|
|
6
6
|
return (React.createElement(BlocksWrapper, { blocks: props.blocks, parent: props.parent, path: props.path, styleProp: props.styleProp },
|
|
7
7
|
props.blocks ? (React.createElement(React.Fragment, null, props.blocks?.map((block) => (React.createElement(Block, { key: "render-block-" + block.id, block: block, context: props.context, registeredComponents: props.registeredComponents }))))) : null,
|
|
@@ -1,7 +1,7 @@
|
|
|
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";
|
|
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";
|
|
@@ -19,7 +19,8 @@ font-weight: 400;
|
|
|
19
19
|
const isNumber = String(Number(weight)) === weight;
|
|
20
20
|
if (!isNumber) {
|
|
21
21
|
continue;
|
|
22
|
-
}
|
|
22
|
+
}
|
|
23
|
+
// TODO: maybe limit number loaded
|
|
23
24
|
const weightUrl = font.files[weight];
|
|
24
25
|
if (weightUrl && weightUrl !== url) {
|
|
25
26
|
str += `
|
|
@@ -49,7 +50,8 @@ export const getCss = ({ cssCode, contentId }) => {
|
|
|
49
50
|
}
|
|
50
51
|
if (!contentId) {
|
|
51
52
|
return cssCode;
|
|
52
|
-
}
|
|
53
|
+
}
|
|
54
|
+
// Allow using `&` in custom CSS code like @emotion
|
|
53
55
|
// E.g. `& .foobar { ... }` to scope CSS
|
|
54
56
|
// TODO: handle if '&' is within a string like `content: "&"`
|
|
55
57
|
return cssCode?.replace(/&/g, `div[builder-content-id="${contentId}"]`) || '';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import InlinedStyles from "../../inlined-styles
|
|
2
|
+
import InlinedStyles from "../../inlined-styles";
|
|
3
3
|
import { getCss } from "./styles.helpers.js";
|
|
4
4
|
import { getFontCss } from "./styles.helpers.js";
|
|
5
5
|
function ContentStyles(props) {
|
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
export const getContextStateInitialValue = ({ content, data, locale }) => {
|
|
2
|
-
const defaultValues = {};
|
|
2
|
+
const defaultValues = {};
|
|
3
|
+
// set default values for content state inputs
|
|
3
4
|
content?.data?.inputs?.forEach(input => {
|
|
4
5
|
if (input.name && input.defaultValue !== undefined && content?.data?.state && content.data.state[input.name] === undefined) {
|
|
5
6
|
defaultValues[input.name] = input.defaultValue;
|
|
6
7
|
}
|
|
7
8
|
});
|
|
8
|
-
const stateToUse = {
|
|
9
|
+
const stateToUse = {
|
|
10
|
+
...content?.data?.state,
|
|
9
11
|
...data,
|
|
10
12
|
...(locale ? {
|
|
11
13
|
locale
|
|
12
14
|
} : {})
|
|
13
15
|
};
|
|
14
|
-
return {
|
|
16
|
+
return {
|
|
17
|
+
...defaultValues,
|
|
15
18
|
...stateToUse
|
|
16
19
|
};
|
|
17
20
|
};
|
|
18
21
|
export const getContentInitialValue = ({ content, data }) => {
|
|
19
|
-
return !content ? undefined : {
|
|
20
|
-
|
|
22
|
+
return !content ? undefined : {
|
|
23
|
+
...content,
|
|
24
|
+
data: {
|
|
25
|
+
...content?.data,
|
|
21
26
|
...data
|
|
22
27
|
},
|
|
23
28
|
meta: content?.meta
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
|
|
3
3
|
import { components, serializeComponentInfo, } from "../../functions/register-component.js";
|
|
4
|
-
import Blocks from "../blocks/blocks
|
|
5
|
-
import ContentStyles from "./components/styles
|
|
4
|
+
import Blocks from "../blocks/blocks";
|
|
5
|
+
import ContentStyles from "./components/styles";
|
|
6
6
|
import { getContentInitialValue, getContextStateInitialValue, } from "./content.helpers.js";
|
|
7
7
|
import { TARGET } from "../../constants/target.js";
|
|
8
8
|
import { getRenderContentScriptString } from "../content-variants/helpers.js";
|
|
9
|
-
import EnableEditor from "./components/enable-editor
|
|
10
|
-
import InlinedScript from "../inlined-script
|
|
9
|
+
import EnableEditor from "./components/enable-editor";
|
|
10
|
+
import InlinedScript from "../inlined-script";
|
|
11
11
|
function ContentComponent(props) {
|
|
12
12
|
const scriptStr = getRenderContentScriptString({
|
|
13
13
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
|
|
@@ -20,6 +20,7 @@ function ContentComponent(props) {
|
|
|
20
20
|
};
|
|
21
21
|
const registeredComponents = [
|
|
22
22
|
...getDefaultRegisteredComponents(),
|
|
23
|
+
// While this `components` object is deprecated, we must maintain support for it.
|
|
23
24
|
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
24
25
|
// existing usage.
|
|
25
26
|
// This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
|
|
@@ -50,6 +51,7 @@ function ContentComponent(props) {
|
|
|
50
51
|
apiVersion: props.apiVersion,
|
|
51
52
|
componentInfos: [
|
|
52
53
|
...getDefaultRegisteredComponents(),
|
|
54
|
+
// While this `components` object is deprecated, we must maintain support for it.
|
|
53
55
|
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
54
56
|
// existing usage.
|
|
55
57
|
// This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { checkShouldRunVariants, getScriptString, getVariants, getVariantsScriptString, } from "./helpers.js";
|
|
3
|
-
import ContentComponent from "../content/content
|
|
3
|
+
import ContentComponent from "../content/content";
|
|
4
4
|
import { getDefaultCanTrack } from "../../helpers/canTrack.js";
|
|
5
|
-
import InlinedStyles from "../inlined-styles
|
|
5
|
+
import InlinedStyles from "../inlined-styles";
|
|
6
6
|
import { handleABTestingSync } from "../../helpers/ab-tests.js";
|
|
7
|
-
import InlinedScript from "../inlined-script
|
|
7
|
+
import InlinedScript from "../inlined-script";
|
|
8
8
|
import { TARGET } from "../../constants/target.js";
|
|
9
9
|
function ContentVariants(props) {
|
|
10
10
|
const shouldRenderVariants = checkShouldRunVariants({
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TARGET } from '../../constants/target.js';
|
|
2
2
|
import { isBrowser } from '../../functions/is-browser.js';
|
|
3
|
-
export const getVariants = (content) => Object.values(content?.variations || {}).map(variant => ({
|
|
3
|
+
export const getVariants = (content) => Object.values(content?.variations || {}).map(variant => ({
|
|
4
|
+
...variant,
|
|
4
5
|
testVariationId: variant.id,
|
|
5
6
|
id: content?.id
|
|
6
7
|
}));
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { default as Button } from '../blocks/button/button
|
|
1
|
+
import { default as Button } from '../blocks/button/button';
|
|
2
2
|
import { componentInfo as buttonComponentInfo } from '../blocks/button/component-info.js';
|
|
3
|
-
import { default as Columns } from '../blocks/columns/columns
|
|
3
|
+
import { default as Columns } from '../blocks/columns/columns';
|
|
4
4
|
import { componentInfo as columnsComponentInfo } from '../blocks/columns/component-info.js';
|
|
5
5
|
import { componentInfo as fragmentComponentInfo } from '../blocks/fragment/component-info.js';
|
|
6
|
-
import { default as Fragment } from '../blocks/fragment/fragment
|
|
6
|
+
import { default as Fragment } from '../blocks/fragment/fragment';
|
|
7
7
|
import { componentInfo as imageComponentInfo } from '../blocks/image/component-info.js';
|
|
8
|
-
import { default as Image } from '../blocks/image/image
|
|
8
|
+
import { default as Image } from '../blocks/image/image';
|
|
9
9
|
import { componentInfo as sectionComponentInfo } from '../blocks/section/component-info.js';
|
|
10
|
-
import { default as Section } from '../blocks/section/section
|
|
10
|
+
import { default as Section } from '../blocks/section/section';
|
|
11
11
|
import { componentInfo as symbolComponentInfo } from '../blocks/symbol/component-info.js';
|
|
12
|
-
import { default as Symbol } from '../blocks/symbol/symbol
|
|
12
|
+
import { default as Symbol } from '../blocks/symbol/symbol';
|
|
13
13
|
import { componentInfo as textComponentInfo } from '../blocks/text/component-info.js';
|
|
14
|
-
import { default as Text } from '../blocks/text/text
|
|
14
|
+
import { default as Text } from '../blocks/text/text';
|
|
15
15
|
import { componentInfo as videoComponentInfo } from '../blocks/video/component-info.js';
|
|
16
|
-
import { default as Video } from '../blocks/video/video
|
|
16
|
+
import { default as Video } from '../blocks/video/video';
|
|
17
17
|
import { componentInfo as embedComponentInfo } from '../blocks/embed/component-info.js';
|
|
18
|
-
import { default as embed } from '../blocks/embed/embed
|
|
19
|
-
import { default as Img } from '../blocks/img/img
|
|
18
|
+
import { default as embed } from '../blocks/embed/embed';
|
|
19
|
+
import { default as Img } from '../blocks/img/img';
|
|
20
20
|
import { componentInfo as imgComponentInfo } from '../blocks/img/component-info.js';
|
|
21
|
-
import { default as customCode } from '../blocks/custom-code/custom-code
|
|
21
|
+
import { default as customCode } from '../blocks/custom-code/custom-code';
|
|
22
22
|
import { componentInfo as customCodeInfo } from '../blocks/custom-code/component-info.js';
|
|
23
23
|
/**
|
|
24
24
|
* Returns a list of all registered components.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.
|
|
1
|
+
export declare const SDK_VERSION = "0.5.1";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.
|
|
1
|
+
export const SDK_VERSION = "0.5.1";
|