@builder.io/sdk-react 0.3.1 → 0.4.0
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/sdk/blocks/BaseText.js +1 -1
- package/dist/sdk/blocks/button/button.js +1 -1
- package/dist/sdk/blocks/columns/columns.js +1 -1
- package/dist/sdk/blocks/custom-code/custom-code.js +1 -1
- package/dist/sdk/blocks/embed/embed.js +1 -1
- package/dist/sdk/blocks/fragment/fragment.js +1 -1
- package/dist/sdk/blocks/image/image.js +1 -1
- package/dist/sdk/blocks/img/img.js +1 -1
- package/dist/sdk/blocks/input/input.js +1 -1
- package/dist/sdk/blocks/raw-text/raw-text.js +1 -1
- package/dist/sdk/blocks/section/section.js +1 -1
- package/dist/sdk/blocks/select/select.js +1 -1
- package/dist/sdk/blocks/submit-button/submit-button.js +1 -1
- package/dist/sdk/blocks/symbol/symbol.js +1 -1
- package/dist/sdk/blocks/text/text.js +1 -1
- package/dist/sdk/blocks/textarea/textarea.js +1 -1
- package/dist/sdk/blocks/video/video.js +1 -1
- package/dist/sdk/components/render-block/block-styles.js +1 -1
- package/dist/sdk/components/render-block/render-block.js +7 -8
- package/dist/sdk/components/render-block/render-component.js +2 -3
- package/dist/sdk/components/render-block/render-repeated-block.js +1 -1
- package/dist/sdk/components/render-blocks.js +1 -1
- package/dist/sdk/components/render-content/builder-editing.js +1 -1
- package/dist/sdk/components/render-content/components/render-styles.js +2 -2
- package/dist/sdk/components/render-content/render-content.js +33 -4
- package/dist/sdk/components/render-content/render-content.types.d.ts +11 -2
- package/dist/sdk/components/render-content/wrap-component-ref.d.ts +6 -0
- package/dist/sdk/components/render-content/wrap-component-ref.js +6 -0
- package/dist/sdk/components/render-content-variants/helpers.d.ts +5 -0
- package/dist/sdk/components/render-content-variants/helpers.js +149 -121
- package/dist/sdk/components/render-content-variants/render-content-variants.js +22 -14
- package/dist/sdk/components/render-inlined-styles.d.ts +1 -0
- package/dist/sdk/components/render-inlined-styles.js +2 -13
- package/dist/sdk/constants/sdk-version.d.ts +1 -1
- package/dist/sdk/constants/sdk-version.js +1 -1
- package/dist/sdk/functions/get-content/generate-content-url.js +2 -2
- package/dist/sdk/functions/get-content/generate-content-url.test.js +15 -0
- package/dist/sdk/functions/get-content/index.d.ts +7 -2
- package/dist/sdk/functions/get-content/index.js +43 -20
- package/dist/sdk/functions/get-content/types.d.ts +6 -0
- package/dist/sdk/helpers/ab-tests.d.ts +8 -7
- package/dist/sdk/helpers/ab-tests.js +103 -4
- package/dist/sdk/helpers/cookie.d.ts +7 -3
- package/dist/sdk/helpers/cookie.js +9 -6
- package/dist/sdk/helpers/logger.d.ts +1 -0
- package/dist/sdk/helpers/logger.js +1 -0
- package/dist/sdk/index-helpers/blocks-exports.d.ts +1 -1
- package/dist/sdk/index-helpers/blocks-exports.js +1 -1
- package/dist/sdk/index.d.ts +8 -7
- package/dist/sdk/index.js +6 -7
- package/dist/sdk/scripts/init-editing.d.ts +1 -0
- package/dist/sdk/types/builder-content.d.ts +1 -3
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { useState } from "react";
|
|
4
4
|
import { getBlockActions } from "../../functions/get-block-actions.js";
|
|
@@ -35,7 +35,7 @@ function RenderBlock(props) {
|
|
|
35
35
|
shouldEvaluateBindings: true,
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
|
-
const [
|
|
38
|
+
const [Tag, setTag] = useState(() => props.block.tagName || "div");
|
|
39
39
|
function canShowBlock() {
|
|
40
40
|
if ("hide" in useBlock()) {
|
|
41
41
|
return !useBlock().hide;
|
|
@@ -124,13 +124,12 @@ function RenderBlock(props) {
|
|
|
124
124
|
context: childrenContext(),
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
|
-
const TagRef = tag;
|
|
128
127
|
return (React.createElement(React.Fragment, null, canShowBlock() ? (React.createElement(React.Fragment, null, !component?.noWrap ? (React.createElement(React.Fragment, null,
|
|
129
|
-
isEmptyHtmlElement(
|
|
130
|
-
React.createElement(
|
|
131
|
-
!isEmptyHtmlElement(
|
|
132
|
-
!isEmptyHtmlElement(
|
|
133
|
-
React.createElement(
|
|
128
|
+
isEmptyHtmlElement(Tag) ? (React.createElement(React.Fragment, null,
|
|
129
|
+
React.createElement(Tag, { ...attributes(), ...actions() }))) : null,
|
|
130
|
+
!isEmptyHtmlElement(Tag) && repeatItem() ? (React.createElement(React.Fragment, null, repeatItem()?.map((data, index) => (React.createElement(RenderRepeatedBlock, { key: index, repeatContext: data.context, block: data.block }))))) : null,
|
|
131
|
+
!isEmptyHtmlElement(Tag) && !repeatItem() ? (React.createElement(React.Fragment, null,
|
|
132
|
+
React.createElement(Tag, { ...attributes(), ...actions() },
|
|
134
133
|
React.createElement(RenderComponent, { ...renderComponentProps() }),
|
|
135
134
|
childrenWithoutParentComponent()?.map((child) => (React.createElement(RenderBlock, { key: "render-block-" + child.id, block: child, context: childrenContext() }))),
|
|
136
135
|
childrenWithoutParentComponent()?.map((child) => (React.createElement(BlockStyles, { key: "block-style-" + child.id, block: child, context: childrenContext() })))))) : null)) : (React.createElement(React.Fragment, null,
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import BlockStyles from "./block-styles";
|
|
4
4
|
import RenderBlock from "./render-block";
|
|
5
5
|
function RenderComponent(props) {
|
|
6
|
-
const ComponentRefRef = props.componentRef;
|
|
7
6
|
return (React.createElement(React.Fragment, null, props.componentRef ? (React.createElement(React.Fragment, null,
|
|
8
|
-
React.createElement(
|
|
7
|
+
React.createElement(props.componentRef, { ...props.componentOptions },
|
|
9
8
|
props.blockChildren?.map((child) => (React.createElement(RenderBlock, { key: "render-block-" + child.id, block: child, context: props.context }))),
|
|
10
9
|
props.blockChildren?.map((child) => (React.createElement(BlockStyles, { key: "block-style-" + child.id, block: child, context: props.context })))))) : null));
|
|
11
10
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { useState } from "react";
|
|
4
4
|
import RenderInlinedStyles from "../../render-inlined-styles";
|
|
@@ -26,7 +26,7 @@ ${getFontCss({
|
|
|
26
26
|
text-align: inherit;
|
|
27
27
|
font-family: inherit;
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
`.trim());
|
|
30
30
|
return React.createElement(RenderInlinedStyles, { styles: injectedStyles });
|
|
31
31
|
}
|
|
32
32
|
export default RenderContentStyles;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { useState, useRef, useEffect } from "react";
|
|
4
4
|
import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
|
|
@@ -19,6 +19,8 @@ import { getInteractionPropertiesForEvent } from "../../functions/track/interact
|
|
|
19
19
|
import { getContentInitialValue, getContextStateInitialValue, } from "./render-content.helpers.js";
|
|
20
20
|
import { TARGET } from "../../constants/target.js";
|
|
21
21
|
import { logger } from "../../helpers/logger.js";
|
|
22
|
+
import { getRenderContentScriptString } from "../render-content-variants/helpers.js";
|
|
23
|
+
import { wrapComponentRef } from "./wrap-component-ref.js";
|
|
22
24
|
function RenderContent(props) {
|
|
23
25
|
const elementRef = useRef(null);
|
|
24
26
|
const [forceReRenderCount, setForceReRenderCount] = useState(() => 0);
|
|
@@ -70,9 +72,12 @@ function RenderContent(props) {
|
|
|
70
72
|
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
71
73
|
...components,
|
|
72
74
|
...(props.customComponents || []),
|
|
73
|
-
].reduce((acc, curr) => ({
|
|
75
|
+
].reduce((acc, { component, ...curr }) => ({
|
|
74
76
|
...acc,
|
|
75
|
-
[curr.name]:
|
|
77
|
+
[curr.name]: {
|
|
78
|
+
component: TARGET === "vue3" ? wrapComponentRef(component) : component,
|
|
79
|
+
...curr,
|
|
80
|
+
},
|
|
76
81
|
}), {}));
|
|
77
82
|
function processMessage(event) {
|
|
78
83
|
const { data } = event;
|
|
@@ -190,6 +195,11 @@ function RenderContent(props) {
|
|
|
190
195
|
}));
|
|
191
196
|
}
|
|
192
197
|
}
|
|
198
|
+
const [scriptStr, setScriptStr] = useState(() => getRenderContentScriptString({
|
|
199
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
|
|
200
|
+
contentId: props.content?.id,
|
|
201
|
+
parentContentId: props.parentContentId,
|
|
202
|
+
}));
|
|
193
203
|
useEffect(() => {
|
|
194
204
|
if (!props.apiKey) {
|
|
195
205
|
logger.error("No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
|
|
@@ -209,6 +219,11 @@ function RenderContent(props) {
|
|
|
209
219
|
includeRefs: props.includeRefs,
|
|
210
220
|
}
|
|
211
221
|
: {}),
|
|
222
|
+
...(props.enrich
|
|
223
|
+
? {
|
|
224
|
+
enrich: props.enrich,
|
|
225
|
+
}
|
|
226
|
+
: {}),
|
|
212
227
|
});
|
|
213
228
|
Object.values(allRegisteredComponents).forEach((registeredComponent) => {
|
|
214
229
|
const message = createRegisterComponentMessage(registeredComponent);
|
|
@@ -293,7 +308,21 @@ function RenderContent(props) {
|
|
|
293
308
|
registeredComponents: allRegisteredComponents,
|
|
294
309
|
inheritedStyles: {},
|
|
295
310
|
} }, useContent ? (React.createElement(React.Fragment, null,
|
|
296
|
-
React.createElement("div", { ref: elementRef, onClick: (event) => onClick(event), "builder-content-id": useContent?.id, "builder-model": props.model
|
|
311
|
+
React.createElement("div", { ref: elementRef, onClick: (event) => onClick(event), "builder-content-id": useContent?.id, "builder-model": props.model, ...(TARGET === "reactNative"
|
|
312
|
+
? {
|
|
313
|
+
dataSet: {
|
|
314
|
+
// currently, we can't set the actual ID here. // we don't need it right now, we just need to identify content divs for testing.
|
|
315
|
+
"builder-content-id": "",
|
|
316
|
+
},
|
|
317
|
+
}
|
|
318
|
+
: {}), ...(props.hideContent
|
|
319
|
+
? {
|
|
320
|
+
hidden: true,
|
|
321
|
+
"aria-hidden": true,
|
|
322
|
+
}
|
|
323
|
+
: {}), className: props.classNameProp },
|
|
324
|
+
props.isSsrAbTest ? (React.createElement(React.Fragment, null,
|
|
325
|
+
React.createElement("script", { dangerouslySetInnerHTML: { __html: scriptStr } }))) : null,
|
|
297
326
|
TARGET !== "reactNative" ? (React.createElement(React.Fragment, null,
|
|
298
327
|
React.createElement(RenderContentStyles, { contentId: useContent?.id, cssCode: useContent?.data?.cssCode, customFonts: useContent?.data?.customFonts }))) : null,
|
|
299
328
|
React.createElement(RenderBlocks, { blocks: useContent?.data?.blocks, key: forceReRenderCount })))) : null));
|
|
@@ -2,7 +2,7 @@ import type { BuilderRenderContext, RegisteredComponent, BuilderRenderState } fr
|
|
|
2
2
|
import type { BuilderContent } from '../../types/builder-content';
|
|
3
3
|
import type { Nullable } from '../../types/typescript';
|
|
4
4
|
import type { ApiVersion } from '../../types/api-version';
|
|
5
|
-
export
|
|
5
|
+
export interface RenderContentProps {
|
|
6
6
|
content?: Nullable<BuilderContent>;
|
|
7
7
|
model?: string;
|
|
8
8
|
data?: {
|
|
@@ -14,8 +14,17 @@ export type RenderContentProps = {
|
|
|
14
14
|
customComponents?: RegisteredComponent[];
|
|
15
15
|
canTrack?: boolean;
|
|
16
16
|
locale?: string;
|
|
17
|
+
/** @deprecated use `enrich` instead **/
|
|
17
18
|
includeRefs?: boolean;
|
|
18
|
-
|
|
19
|
+
enrich?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* TO-DO: improve qwik generator to not remap this name for non-HTML tags, then name it `className`
|
|
22
|
+
*/
|
|
23
|
+
classNameProp?: string;
|
|
24
|
+
hideContent?: boolean;
|
|
25
|
+
parentContentId?: string;
|
|
26
|
+
isSsrAbTest?: boolean;
|
|
27
|
+
}
|
|
19
28
|
export interface BuilderComponentStateChange {
|
|
20
29
|
state: BuilderRenderState;
|
|
21
30
|
ref: {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Nullable } from '../../helpers/nullable';
|
|
2
2
|
import type { BuilderContent } from '../../types/builder-content';
|
|
3
|
+
export declare const getVariants: (content: Nullable<BuilderContent>) => import("../../types/builder-content").BuilderContentVariation[];
|
|
3
4
|
export declare const checkShouldRunVariants: ({ canTrack, content, }: {
|
|
4
5
|
canTrack: Nullable<boolean>;
|
|
5
6
|
content: Nullable<BuilderContent>;
|
|
@@ -9,4 +10,8 @@ type VariantData = {
|
|
|
9
10
|
testRatio?: number;
|
|
10
11
|
};
|
|
11
12
|
export declare const getVariantsScriptString: (variants: VariantData[], contentId: string) => string;
|
|
13
|
+
export declare const getRenderContentScriptString: ({ parentContentId, contentId, }: {
|
|
14
|
+
contentId: string;
|
|
15
|
+
parentContentId: string;
|
|
16
|
+
}) => string;
|
|
12
17
|
export {};
|