@builder.io/sdk-react-native 0.4.1 → 0.4.3
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/BaseText.d.ts +6 -0
- package/dist/blocks/button/button.d.ts +9 -0
- package/dist/blocks/button/component-info.d.ts +2 -0
- package/dist/blocks/columns/columns.d.ts +16 -0
- package/dist/blocks/columns/component-info.d.ts +2 -0
- package/dist/blocks/custom-code/component-info.d.ts +2 -0
- package/dist/blocks/custom-code/custom-code.d.ts +5 -0
- package/dist/blocks/embed/component-info.d.ts +2 -0
- package/dist/blocks/embed/embed.d.ts +5 -0
- package/dist/blocks/embed/helpers.d.ts +1 -0
- package/dist/blocks/form/component-info.d.ts +2 -0
- package/dist/blocks/form/form.d.ts +28 -0
- package/dist/blocks/fragment/component-info.d.ts +2 -0
- package/dist/blocks/fragment/fragment.d.ts +8 -0
- package/dist/blocks/image/component-info.d.ts +2 -0
- package/dist/blocks/image/image.d.ts +17 -0
- package/dist/blocks/image/image.helpers.d.ts +1 -0
- package/dist/blocks/img/component-info.d.ts +2 -0
- package/dist/blocks/img/component-info.js +1 -1
- package/dist/blocks/img/img.d.ts +11 -0
- package/dist/blocks/input/component-info.d.ts +2 -0
- package/dist/blocks/input/input.d.ts +12 -0
- package/dist/blocks/raw-text/component-info.d.ts +2 -0
- package/dist/blocks/raw-text/raw-text.d.ts +5 -0
- package/dist/blocks/section/component-info.d.ts +2 -0
- package/dist/blocks/section/section.d.ts +9 -0
- package/dist/blocks/select/component-info.d.ts +2 -0
- package/dist/blocks/select/select.d.ts +13 -0
- package/dist/blocks/submit-button/component-info.d.ts +2 -0
- package/dist/blocks/submit-button/submit-button.d.ts +7 -0
- package/dist/blocks/symbol/component-info.d.ts +2 -0
- package/dist/blocks/symbol/symbol.d.ts +21 -0
- package/dist/blocks/text/component-info.d.ts +2 -0
- package/dist/blocks/text/text.d.ts +7 -0
- package/dist/blocks/textarea/component-info.d.ts +2 -0
- package/dist/blocks/textarea/textarea.d.ts +10 -0
- package/dist/blocks/util.d.ts +4 -0
- package/dist/blocks/video/component-info.d.ts +2 -0
- package/dist/blocks/video/video.d.ts +31 -0
- package/dist/components/render-block/block-styles.d.ts +9 -0
- package/dist/components/render-block/render-block.d.ts +9 -0
- package/dist/components/render-block/render-block.helpers.d.ts +12 -0
- package/dist/components/render-block/render-block.js +18 -26
- package/dist/components/render-block/render-component.d.ts +17 -0
- package/dist/components/render-block/render-repeated-block.d.ts +9 -0
- package/dist/components/render-block/render-repeated-block.js +3 -12
- package/dist/components/render-block/types.d.ts +6 -0
- package/dist/components/render-blocks.d.ts +10 -0
- package/dist/components/render-blocks.js +1 -1
- package/dist/components/render-content/builder-editing.d.ts +3 -0
- package/dist/components/render-content/components/render-styles.d.ts +9 -0
- package/dist/components/render-content/components/render-styles.helpers.d.ts +15 -0
- package/dist/components/render-content/index.d.ts +1 -0
- package/dist/components/render-content/render-content.d.ts +4 -0
- package/dist/components/render-content/render-content.helpers.d.ts +7 -0
- package/dist/components/render-content/render-content.js +77 -71
- package/dist/components/render-content/render-content.types.d.ts +38 -0
- package/dist/components/render-content/wrap-component-ref.d.ts +6 -0
- package/dist/components/render-content-variants/helpers.d.ts +17 -0
- package/dist/components/render-content-variants/helpers.js +3 -1
- package/dist/components/render-content-variants/render-content-variants.d.ts +5 -0
- package/dist/components/render-inlined-styles.d.ts +7 -0
- package/dist/constants/builder-registered-components.d.ts +6 -0
- package/dist/constants/device-sizes.d.ts +13 -0
- package/dist/constants/sdk-version.d.ts +1 -0
- package/dist/constants/sdk-version.js +1 -1
- package/dist/constants/target.d.ts +3 -0
- package/dist/context/builder.context.d.ts +3 -0
- package/dist/context/types.d.ts +35 -0
- package/dist/functions/camel-to-kebab-case.d.ts +1 -0
- package/dist/functions/evaluate.d.ts +7 -0
- package/dist/functions/evaluate.test.d.ts +1 -0
- package/dist/functions/event-handler-name.d.ts +1 -0
- package/dist/functions/extract-text-styles.d.ts +4 -0
- package/dist/functions/fast-clone.d.ts +4 -0
- package/dist/functions/get-block-actions-handler.d.ts +8 -0
- package/dist/functions/get-block-actions.d.ts +9 -0
- package/dist/functions/get-block-component-options.d.ts +2 -0
- package/dist/functions/get-block-properties.d.ts +2 -0
- package/dist/functions/get-builder-search-params/fn.test.d.ts +1 -0
- package/dist/functions/get-builder-search-params/index.d.ts +12 -0
- package/dist/functions/get-content/generate-content-url.d.ts +2 -0
- package/dist/functions/get-content/generate-content-url.test.d.ts +1 -0
- package/dist/functions/get-content/index.d.ts +16 -0
- package/dist/functions/get-content/types.d.ts +51 -0
- package/dist/functions/get-fetch.d.ts +1 -0
- package/dist/functions/get-processed-block.d.ts +10 -0
- package/dist/functions/get-processed-block.test.d.ts +1 -0
- package/dist/functions/get-react-native-block-styles.d.ts +7 -0
- package/dist/functions/if-target.d.ts +7 -0
- package/dist/functions/is-browser.d.ts +1 -0
- package/dist/functions/is-editing.d.ts +1 -0
- package/dist/functions/is-iframe.d.ts +1 -0
- package/dist/functions/is-previewing.d.ts +1 -0
- package/dist/functions/on-change.d.ts +7 -0
- package/dist/functions/on-change.test.d.ts +1 -0
- package/dist/functions/register-component.d.ts +14 -0
- package/dist/functions/register.d.ts +16 -0
- package/dist/functions/sanitize-react-native-block-styles.d.ts +3 -0
- package/dist/functions/set-editor-settings.d.ts +4 -0
- package/dist/functions/set.d.ts +7 -0
- package/dist/functions/set.test.d.ts +1 -0
- package/dist/functions/track/helpers.d.ts +5 -0
- package/dist/functions/track/index.d.ts +51 -0
- package/dist/functions/track/interaction.d.ts +13 -0
- package/dist/functions/transform-block-properties.d.ts +3 -0
- package/dist/functions/transform-block.d.ts +2 -0
- package/dist/helpers/ab-tests.d.ts +9 -0
- package/dist/helpers/canTrack.d.ts +1 -0
- package/dist/helpers/cookie.d.ts +9 -0
- package/dist/helpers/css.d.ts +7 -0
- package/dist/helpers/flatten.d.ts +6 -0
- package/dist/helpers/localStorage.d.ts +9 -0
- package/dist/helpers/logger.d.ts +6 -0
- package/dist/helpers/nullable.d.ts +2 -0
- package/dist/helpers/sessionId.d.ts +6 -0
- package/dist/helpers/time.d.ts +1 -0
- package/dist/helpers/url.d.ts +6 -0
- package/dist/helpers/url.test.d.ts +1 -0
- package/dist/helpers/uuid.d.ts +8 -0
- package/dist/helpers/visitorId.d.ts +6 -0
- package/dist/index-helpers/blocks-exports.d.ts +8 -0
- package/dist/index-helpers/top-of-file.d.ts +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/scripts/init-editing.d.ts +6 -0
- package/dist/types/api-version.d.ts +2 -0
- package/dist/types/builder-block.d.ts +66 -0
- package/dist/types/builder-content.d.ts +44 -0
- package/dist/types/can-track.d.ts +3 -0
- package/dist/types/components.d.ts +105 -0
- package/dist/types/deep-partial.d.ts +3 -0
- package/dist/types/element.d.ts +59 -0
- package/dist/types/input.d.ts +121 -0
- package/dist/types/targets.d.ts +3 -0
- package/dist/types/typescript.d.ts +5 -0
- package/package.json +1 -1
- package/src/blocks/img/component-info.js +1 -1
- package/src/components/render-block/render-block.jsx +21 -29
- package/src/components/render-block/render-repeated-block.jsx +5 -15
- package/src/components/render-blocks.jsx +1 -0
- package/src/components/render-content/render-content.jsx +77 -85
- package/src/components/render-content-variants/helpers.js +3 -1
- package/src/constants/sdk-version.js +1 -1
- package/dist/components/render-block/render-component-with-context.js +0 -45
- package/dist/functions/get-block-tag.js +0 -8
- package/dist/functions/get-content/ab-testing.js +0 -89
- package/dist/functions/track.js +0 -120
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export interface Input {
|
|
2
|
+
/** This is the name of the component prop this input represents */
|
|
3
|
+
name: string;
|
|
4
|
+
/** A friendlier name to show in the UI if the component prop name is not ideal for end users */
|
|
5
|
+
friendlyName?: string;
|
|
6
|
+
/** @hidden @deprecated */
|
|
7
|
+
description?: string;
|
|
8
|
+
/** A default value to use */
|
|
9
|
+
defaultValue?: any;
|
|
10
|
+
/**
|
|
11
|
+
* The type of input to use, such as 'text'
|
|
12
|
+
*
|
|
13
|
+
* See all available inputs [here](https://www.builder.io/c/docs/custom-react-components#input-types)
|
|
14
|
+
* and you can create your own custom input types and associated editor UIs with [plugins](https://www.builder.io/c/docs/extending/plugins)
|
|
15
|
+
*/
|
|
16
|
+
type: string;
|
|
17
|
+
/** Is this input mandatory or not */
|
|
18
|
+
required?: boolean;
|
|
19
|
+
/** @hidden */
|
|
20
|
+
autoFocus?: boolean;
|
|
21
|
+
subFields?: Input[];
|
|
22
|
+
/**
|
|
23
|
+
* Additional text to render in the UI to give guidance on how to use this
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```js
|
|
27
|
+
* helperText: 'Be sure to use a proper URL, starting with "https://"'
|
|
28
|
+
* 111
|
|
29
|
+
*/
|
|
30
|
+
helperText?: string;
|
|
31
|
+
/** @hidden */
|
|
32
|
+
allowedFileTypes?: string[];
|
|
33
|
+
/** @hidden */
|
|
34
|
+
imageHeight?: number;
|
|
35
|
+
/** @hidden */
|
|
36
|
+
imageWidth?: number;
|
|
37
|
+
/** @hidden */
|
|
38
|
+
mediaHeight?: number;
|
|
39
|
+
/** @hidden */
|
|
40
|
+
mediaWidth?: number;
|
|
41
|
+
/** @hidden */
|
|
42
|
+
hideFromUI?: boolean;
|
|
43
|
+
/** @hidden */
|
|
44
|
+
modelId?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Number field type validation maximum accepted input
|
|
47
|
+
*/
|
|
48
|
+
max?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Number field type validation minimum accepted input
|
|
51
|
+
*/
|
|
52
|
+
min?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Number field type step size when using arrows
|
|
55
|
+
*/
|
|
56
|
+
step?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Set this to `true` to show the editor for this input when
|
|
59
|
+
* children of this component are selected. This is useful for things
|
|
60
|
+
* like Tabs, such that users may not always select the Tabs component
|
|
61
|
+
* directly but will still be looking for how to add additional tabs
|
|
62
|
+
*/
|
|
63
|
+
broadcast?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Set this to `true` to show the editor for this input when
|
|
66
|
+
* group locked parents of this component are selected. This is useful
|
|
67
|
+
* to bubble up important inputs for locked groups, like text and images
|
|
68
|
+
*/
|
|
69
|
+
bubble?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Set this to `true` if you want this component to be translatable
|
|
72
|
+
*/
|
|
73
|
+
localized?: boolean;
|
|
74
|
+
/** @hidden */
|
|
75
|
+
options?: {
|
|
76
|
+
[key: string]: any;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* For "text" input type, specifying an enum will show a dropdown of options instead
|
|
80
|
+
*/
|
|
81
|
+
enum?: string[] | {
|
|
82
|
+
label: string;
|
|
83
|
+
value: any;
|
|
84
|
+
helperText?: string;
|
|
85
|
+
}[];
|
|
86
|
+
/** Regex field validation for all string types (text, longText, html, url, etc) */
|
|
87
|
+
regex?: {
|
|
88
|
+
/** pattern to test, like "^\/[a-z]$" */
|
|
89
|
+
pattern: string;
|
|
90
|
+
/** flags for the RegExp constructor, e.g. "gi" */
|
|
91
|
+
options?: string;
|
|
92
|
+
/**
|
|
93
|
+
* Friendly message to display to end-users if the regex fails, e.g.
|
|
94
|
+
* "You must use a relative url starting with '/...' "
|
|
95
|
+
*/
|
|
96
|
+
message: string;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Set this to `true` to put this under the "show more" section of
|
|
100
|
+
* the options editor. Useful for things that are more advanced
|
|
101
|
+
* or more rarely used and don't need to be too prominent
|
|
102
|
+
*/
|
|
103
|
+
advanced?: boolean;
|
|
104
|
+
/** @hidden */
|
|
105
|
+
/** @hidden */
|
|
106
|
+
code?: boolean;
|
|
107
|
+
/** @hidden */
|
|
108
|
+
richText?: boolean;
|
|
109
|
+
/** @hidden */
|
|
110
|
+
showIf?: ((options: Map<string, any>) => boolean) | string;
|
|
111
|
+
/** @hidden */
|
|
112
|
+
copyOnAdd?: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Use optionally with inputs of type `reference`. Restricts the content entry picker to a specific model by name.
|
|
115
|
+
*/
|
|
116
|
+
model?: string;
|
|
117
|
+
valueType?: {
|
|
118
|
+
type?: string;
|
|
119
|
+
};
|
|
120
|
+
onChange?: ((options: Map<string, any>) => void | Promise<void>) | string;
|
|
121
|
+
}
|
package/package.json
CHANGED
|
@@ -103,32 +103,6 @@ function RenderBlock(props) {
|
|
|
103
103
|
return shouldRenderChildrenOutsideRef ? useBlock().children ?? [] : [];
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
function childrenContext() {
|
|
107
|
-
const getInheritedTextStyles = () => {
|
|
108
|
-
if (TARGET !== "reactNative") {
|
|
109
|
-
return {};
|
|
110
|
-
}
|
|
111
|
-
return extractTextStyles(
|
|
112
|
-
getReactNativeBlockStyles({
|
|
113
|
-
block: useBlock(),
|
|
114
|
-
context: props.context,
|
|
115
|
-
blockStyles: attributes().style,
|
|
116
|
-
})
|
|
117
|
-
);
|
|
118
|
-
};
|
|
119
|
-
return {
|
|
120
|
-
apiKey: props.context.apiKey,
|
|
121
|
-
apiVersion: props.context.apiVersion,
|
|
122
|
-
localState: props.context.localState,
|
|
123
|
-
rootState: props.context.rootState,
|
|
124
|
-
rootSetState: props.context.rootSetState,
|
|
125
|
-
content: props.context.content,
|
|
126
|
-
context: props.context.context,
|
|
127
|
-
registeredComponents: props.context.registeredComponents,
|
|
128
|
-
inheritedStyles: getInheritedTextStyles(),
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
106
|
function renderComponentProps() {
|
|
133
107
|
return {
|
|
134
108
|
blockChildren: useBlock().children ?? [],
|
|
@@ -148,10 +122,28 @@ function RenderBlock(props) {
|
|
|
148
122
|
},
|
|
149
123
|
}),
|
|
150
124
|
},
|
|
151
|
-
context: childrenContext
|
|
125
|
+
context: childrenContext,
|
|
152
126
|
};
|
|
153
127
|
}
|
|
154
128
|
|
|
129
|
+
const [childrenContext, setChildrenContext] = useState(() => ({
|
|
130
|
+
apiKey: props.context.apiKey,
|
|
131
|
+
apiVersion: props.context.apiVersion,
|
|
132
|
+
localState: props.context.localState,
|
|
133
|
+
rootState: props.context.rootState,
|
|
134
|
+
rootSetState: props.context.rootSetState,
|
|
135
|
+
content: props.context.content,
|
|
136
|
+
context: props.context.context,
|
|
137
|
+
registeredComponents: props.context.registeredComponents,
|
|
138
|
+
inheritedStyles: extractTextStyles(
|
|
139
|
+
getReactNativeBlockStyles({
|
|
140
|
+
block: useBlock(),
|
|
141
|
+
context: props.context,
|
|
142
|
+
blockStyles: attributes().style,
|
|
143
|
+
})
|
|
144
|
+
),
|
|
145
|
+
}));
|
|
146
|
+
|
|
155
147
|
return (
|
|
156
148
|
<>
|
|
157
149
|
{canShowBlock() ? (
|
|
@@ -183,7 +175,7 @@ function RenderBlock(props) {
|
|
|
183
175
|
<RenderBlock
|
|
184
176
|
key={"render-block-" + child.id}
|
|
185
177
|
block={child}
|
|
186
|
-
context={childrenContext
|
|
178
|
+
context={childrenContext}
|
|
187
179
|
/>
|
|
188
180
|
))}
|
|
189
181
|
|
|
@@ -191,7 +183,7 @@ function RenderBlock(props) {
|
|
|
191
183
|
<BlockStyles
|
|
192
184
|
key={"block-style-" + child.id}
|
|
193
185
|
block={child}
|
|
194
|
-
context={childrenContext
|
|
186
|
+
context={childrenContext}
|
|
195
187
|
/>
|
|
196
188
|
))}
|
|
197
189
|
</Tag>
|
|
@@ -8,26 +8,16 @@ import {
|
|
|
8
8
|
Image,
|
|
9
9
|
Text,
|
|
10
10
|
} from "react-native";
|
|
11
|
-
import { useContext } from "react";
|
|
11
|
+
import { useState, useContext } from "react";
|
|
12
12
|
import BuilderContext from "../../context/builder.context.js";
|
|
13
13
|
import RenderBlock from "./render-block";
|
|
14
14
|
|
|
15
15
|
function RenderRepeatedBlock(props) {
|
|
16
|
+
const [store, setStore] = useState(() => props.repeatContext);
|
|
17
|
+
|
|
16
18
|
return (
|
|
17
|
-
<BuilderContext.Provider
|
|
18
|
-
|
|
19
|
-
content: props.repeatContext.content,
|
|
20
|
-
localState: props.repeatContext.localState,
|
|
21
|
-
rootState: props.repeatContext.rootState,
|
|
22
|
-
rootSetState: props.repeatContext.rootSetState,
|
|
23
|
-
context: props.repeatContext.context,
|
|
24
|
-
apiKey: props.repeatContext.apiKey,
|
|
25
|
-
registeredComponents: props.repeatContext.registeredComponents,
|
|
26
|
-
inheritedStyles: props.repeatContext.inheritedStyles,
|
|
27
|
-
apiVersion: props.repeatContext.apiVersion,
|
|
28
|
-
}}
|
|
29
|
-
>
|
|
30
|
-
<RenderBlock block={props.block} context={props.repeatContext} />
|
|
19
|
+
<BuilderContext.Provider value={store}>
|
|
20
|
+
<RenderBlock block={props.block} context={store} />
|
|
31
21
|
</BuilderContext.Provider>
|
|
32
22
|
);
|
|
33
23
|
}
|
|
@@ -45,38 +45,32 @@ function RenderContent(props) {
|
|
|
45
45
|
|
|
46
46
|
const [overrideContent, setOverrideContent] = useState(() => null);
|
|
47
47
|
|
|
48
|
-
const [useContent, setUseContent] = useState(() =>
|
|
49
|
-
getContentInitialValue({
|
|
50
|
-
content: props.content,
|
|
51
|
-
data: props.data,
|
|
52
|
-
})
|
|
53
|
-
);
|
|
54
|
-
|
|
55
48
|
function mergeNewContent(newContent) {
|
|
56
|
-
|
|
57
|
-
...
|
|
49
|
+
builderContextSignal.content = {
|
|
50
|
+
...builderContextSignal.content,
|
|
58
51
|
...newContent,
|
|
59
52
|
data: {
|
|
60
|
-
...
|
|
53
|
+
...builderContextSignal.content?.data,
|
|
61
54
|
...newContent?.data,
|
|
62
55
|
},
|
|
63
56
|
meta: {
|
|
64
|
-
...
|
|
57
|
+
...builderContextSignal.content?.meta,
|
|
65
58
|
...newContent?.meta,
|
|
66
59
|
breakpoints:
|
|
67
|
-
newContent?.meta?.breakpoints ||
|
|
60
|
+
newContent?.meta?.breakpoints ||
|
|
61
|
+
builderContextSignal.content?.meta?.breakpoints,
|
|
68
62
|
},
|
|
69
|
-
}
|
|
63
|
+
};
|
|
70
64
|
}
|
|
71
65
|
|
|
72
66
|
function setBreakpoints(breakpoints) {
|
|
73
|
-
|
|
74
|
-
...
|
|
67
|
+
builderContextSignal.content = {
|
|
68
|
+
...builderContextSignal.content,
|
|
75
69
|
meta: {
|
|
76
|
-
...
|
|
70
|
+
...builderContextSignal.content?.meta,
|
|
77
71
|
breakpoints,
|
|
78
72
|
},
|
|
79
|
-
}
|
|
73
|
+
};
|
|
80
74
|
}
|
|
81
75
|
|
|
82
76
|
const [update, setUpdate] = useState(() => 0);
|
|
@@ -85,41 +79,10 @@ function RenderContent(props) {
|
|
|
85
79
|
checkIsDefined(props.canTrack) ? props.canTrack : true
|
|
86
80
|
);
|
|
87
81
|
|
|
88
|
-
const [contentState, setContentState] = useState(() =>
|
|
89
|
-
getContextStateInitialValue({
|
|
90
|
-
content: props.content,
|
|
91
|
-
data: props.data,
|
|
92
|
-
locale: props.locale,
|
|
93
|
-
})
|
|
94
|
-
);
|
|
95
|
-
|
|
96
82
|
function contentSetState(newRootState) {
|
|
97
|
-
|
|
83
|
+
builderContextSignal.rootState = newRootState;
|
|
98
84
|
}
|
|
99
85
|
|
|
100
|
-
const [allRegisteredComponents, setAllRegisteredComponents] = useState(() =>
|
|
101
|
-
[
|
|
102
|
-
...getDefaultRegisteredComponents(),
|
|
103
|
-
// While this `components` object is deprecated, we must maintain support for it.
|
|
104
|
-
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
105
|
-
// existing usage.
|
|
106
|
-
// This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
|
|
107
|
-
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
108
|
-
...components,
|
|
109
|
-
...(props.customComponents || []),
|
|
110
|
-
].reduce(
|
|
111
|
-
(acc, { component, ...curr }) => ({
|
|
112
|
-
...acc,
|
|
113
|
-
[curr.name]: {
|
|
114
|
-
component:
|
|
115
|
-
TARGET === "vue3" ? wrapComponentRef(component) : component,
|
|
116
|
-
...curr,
|
|
117
|
-
},
|
|
118
|
-
}),
|
|
119
|
-
{}
|
|
120
|
-
)
|
|
121
|
-
);
|
|
122
|
-
|
|
123
86
|
function processMessage(event) {
|
|
124
87
|
const { data } = event;
|
|
125
88
|
if (data) {
|
|
@@ -127,7 +90,7 @@ function RenderContent(props) {
|
|
|
127
90
|
case "builder.configureSdk": {
|
|
128
91
|
const messageContent = data.data;
|
|
129
92
|
const { breakpoints, contentId } = messageContent;
|
|
130
|
-
if (!contentId || contentId !==
|
|
93
|
+
if (!contentId || contentId !== builderContextSignal.content?.id) {
|
|
131
94
|
return;
|
|
132
95
|
}
|
|
133
96
|
if (breakpoints) {
|
|
@@ -161,13 +124,13 @@ function RenderContent(props) {
|
|
|
161
124
|
|
|
162
125
|
function evaluateJsCode() {
|
|
163
126
|
// run any dynamic JS code attached to content
|
|
164
|
-
const jsCode =
|
|
127
|
+
const jsCode = builderContextSignal.content?.data?.jsCode;
|
|
165
128
|
if (jsCode) {
|
|
166
129
|
evaluate({
|
|
167
130
|
code: jsCode,
|
|
168
131
|
context: props.context || {},
|
|
169
132
|
localState: undefined,
|
|
170
|
-
rootState:
|
|
133
|
+
rootState: builderContextSignal.rootState,
|
|
171
134
|
rootSetState: contentSetState,
|
|
172
135
|
});
|
|
173
136
|
}
|
|
@@ -178,9 +141,9 @@ function RenderContent(props) {
|
|
|
178
141
|
const [clicked, setClicked] = useState(() => false);
|
|
179
142
|
|
|
180
143
|
function onClick(event) {
|
|
181
|
-
if (
|
|
182
|
-
const variationId =
|
|
183
|
-
const contentId =
|
|
144
|
+
if (builderContextSignal.content) {
|
|
145
|
+
const variationId = builderContextSignal.content?.testVariationId;
|
|
146
|
+
const contentId = builderContextSignal.content?.id;
|
|
184
147
|
_track({
|
|
185
148
|
type: "click",
|
|
186
149
|
canTrack: canTrackToUse,
|
|
@@ -202,7 +165,7 @@ function RenderContent(props) {
|
|
|
202
165
|
code: group,
|
|
203
166
|
context: props.context || {},
|
|
204
167
|
localState: undefined,
|
|
205
|
-
rootState:
|
|
168
|
+
rootState: builderContextSignal.rootState,
|
|
206
169
|
rootSetState: contentSetState,
|
|
207
170
|
})
|
|
208
171
|
);
|
|
@@ -213,7 +176,7 @@ function RenderContent(props) {
|
|
|
213
176
|
.then((response) => response.json())
|
|
214
177
|
.then((json) => {
|
|
215
178
|
const newState = {
|
|
216
|
-
...
|
|
179
|
+
...builderContextSignal.rootState,
|
|
217
180
|
[key]: json,
|
|
218
181
|
};
|
|
219
182
|
contentSetState(newState);
|
|
@@ -224,7 +187,7 @@ function RenderContent(props) {
|
|
|
224
187
|
}
|
|
225
188
|
|
|
226
189
|
function runHttpRequests() {
|
|
227
|
-
const requests =
|
|
190
|
+
const requests = builderContextSignal.content?.data?.httpRequests ?? {};
|
|
228
191
|
Object.entries(requests).forEach(([key, url]) => {
|
|
229
192
|
if (url && (!httpReqsData[key] || isEditing())) {
|
|
230
193
|
const evaluatedUrl = evalExpression(url);
|
|
@@ -241,7 +204,7 @@ function RenderContent(props) {
|
|
|
241
204
|
window.dispatchEvent(
|
|
242
205
|
new CustomEvent("builder:component:stateChange", {
|
|
243
206
|
detail: {
|
|
244
|
-
state:
|
|
207
|
+
state: builderContextSignal.rootState,
|
|
245
208
|
ref: {
|
|
246
209
|
name: props.model,
|
|
247
210
|
},
|
|
@@ -259,6 +222,44 @@ function RenderContent(props) {
|
|
|
259
222
|
})
|
|
260
223
|
);
|
|
261
224
|
|
|
225
|
+
const [builderContextSignal, setBuilderContextSignal] = useState(() => ({
|
|
226
|
+
content: getContentInitialValue({
|
|
227
|
+
content: props.content,
|
|
228
|
+
data: props.data,
|
|
229
|
+
}),
|
|
230
|
+
localState: undefined,
|
|
231
|
+
rootState: getContextStateInitialValue({
|
|
232
|
+
content: props.content,
|
|
233
|
+
data: props.data,
|
|
234
|
+
locale: props.locale,
|
|
235
|
+
}),
|
|
236
|
+
rootSetState: contentSetState,
|
|
237
|
+
context: props.context || {},
|
|
238
|
+
apiKey: props.apiKey,
|
|
239
|
+
apiVersion: props.apiVersion,
|
|
240
|
+
registeredComponents: [
|
|
241
|
+
...getDefaultRegisteredComponents(),
|
|
242
|
+
// While this `components` object is deprecated, we must maintain support for it.
|
|
243
|
+
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
244
|
+
// existing usage.
|
|
245
|
+
// This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
|
|
246
|
+
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
247
|
+
...components,
|
|
248
|
+
...(props.customComponents || []),
|
|
249
|
+
].reduce(
|
|
250
|
+
(acc, { component, ...curr }) => ({
|
|
251
|
+
...acc,
|
|
252
|
+
[curr.name]: {
|
|
253
|
+
component:
|
|
254
|
+
TARGET === "vue3" ? wrapComponentRef(component) : component,
|
|
255
|
+
...curr,
|
|
256
|
+
},
|
|
257
|
+
}),
|
|
258
|
+
{}
|
|
259
|
+
),
|
|
260
|
+
inheritedStyles: {},
|
|
261
|
+
}));
|
|
262
|
+
|
|
262
263
|
useEffect(() => {
|
|
263
264
|
if (!props.apiKey) {
|
|
264
265
|
logger.error(
|
|
@@ -286,7 +287,7 @@ function RenderContent(props) {
|
|
|
286
287
|
}
|
|
287
288
|
: {}),
|
|
288
289
|
});
|
|
289
|
-
Object.values(
|
|
290
|
+
Object.values(builderContextSignal.registeredComponents).forEach(
|
|
290
291
|
(registeredComponent) => {
|
|
291
292
|
const message = createRegisterComponentMessage(registeredComponent);
|
|
292
293
|
window.parent?.postMessage(message, "*");
|
|
@@ -298,9 +299,9 @@ function RenderContent(props) {
|
|
|
298
299
|
emitStateUpdate
|
|
299
300
|
);
|
|
300
301
|
}
|
|
301
|
-
if (
|
|
302
|
-
const variationId =
|
|
303
|
-
const contentId =
|
|
302
|
+
if (builderContextSignal.content) {
|
|
303
|
+
const variationId = builderContextSignal.content?.testVariationId;
|
|
304
|
+
const contentId = builderContextSignal.content?.id;
|
|
304
305
|
_track({
|
|
305
306
|
type: "impression",
|
|
306
307
|
canTrack: canTrackToUse,
|
|
@@ -356,13 +357,16 @@ function RenderContent(props) {
|
|
|
356
357
|
}, [props.content]);
|
|
357
358
|
useEffect(() => {
|
|
358
359
|
evaluateJsCode();
|
|
359
|
-
}, [
|
|
360
|
+
}, [
|
|
361
|
+
builderContextSignal.content?.data?.jsCode,
|
|
362
|
+
builderContextSignal.rootState,
|
|
363
|
+
]);
|
|
360
364
|
useEffect(() => {
|
|
361
365
|
runHttpRequests();
|
|
362
|
-
}, [
|
|
366
|
+
}, [builderContextSignal.content?.data?.httpRequests]);
|
|
363
367
|
useEffect(() => {
|
|
364
368
|
emitStateUpdate();
|
|
365
|
-
}, [
|
|
369
|
+
}, [builderContextSignal.rootState]);
|
|
366
370
|
|
|
367
371
|
useEffect(() => {
|
|
368
372
|
return () => {
|
|
@@ -377,25 +381,13 @@ function RenderContent(props) {
|
|
|
377
381
|
}, []);
|
|
378
382
|
|
|
379
383
|
return (
|
|
380
|
-
<builderContext.Provider
|
|
381
|
-
|
|
382
|
-
content: useContent,
|
|
383
|
-
localState: undefined,
|
|
384
|
-
rootState: contentState,
|
|
385
|
-
rootSetState: TARGET === "qwik" ? undefined : contentSetState,
|
|
386
|
-
context: props.context || {},
|
|
387
|
-
apiKey: props.apiKey,
|
|
388
|
-
apiVersion: props.apiVersion,
|
|
389
|
-
registeredComponents: allRegisteredComponents,
|
|
390
|
-
inheritedStyles: {},
|
|
391
|
-
}}
|
|
392
|
-
>
|
|
393
|
-
{useContent ? (
|
|
384
|
+
<builderContext.Provider value={builderContextSignal}>
|
|
385
|
+
{builderContextSignal.content ? (
|
|
394
386
|
<>
|
|
395
387
|
<ScrollView
|
|
396
388
|
ref={elementRef}
|
|
397
389
|
onClick={(event) => onClick(event)}
|
|
398
|
-
builder-content-id={
|
|
390
|
+
builder-content-id={builderContextSignal.content?.id}
|
|
399
391
|
builder-model={props.model}
|
|
400
392
|
{...(TARGET === "reactNative"
|
|
401
393
|
? {
|
|
@@ -421,15 +413,15 @@ function RenderContent(props) {
|
|
|
421
413
|
{TARGET !== "reactNative" ? (
|
|
422
414
|
<>
|
|
423
415
|
<RenderContentStyles
|
|
424
|
-
contentId={
|
|
425
|
-
cssCode={
|
|
426
|
-
customFonts={
|
|
416
|
+
contentId={builderContextSignal.content?.id}
|
|
417
|
+
cssCode={builderContextSignal.content?.data?.cssCode}
|
|
418
|
+
customFonts={builderContextSignal.content?.data?.customFonts}
|
|
427
419
|
/>
|
|
428
420
|
</>
|
|
429
421
|
) : null}
|
|
430
422
|
|
|
431
423
|
<RenderBlocks
|
|
432
|
-
blocks={
|
|
424
|
+
blocks={builderContextSignal.content?.data?.blocks}
|
|
433
425
|
key={forceReRenderCount}
|
|
434
426
|
/>
|
|
435
427
|
</ScrollView>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TARGET } from "../../constants/target";
|
|
1
2
|
import { isBrowser } from "../../functions/is-browser";
|
|
2
3
|
const getVariants = (content) => Object.values((content == null ? void 0 : content.variations) || {});
|
|
3
4
|
const checkShouldRunVariants = ({
|
|
@@ -112,7 +113,8 @@ function bldrCntntScrpt(variantContentId, defaultContentId, isHydrationTarget2)
|
|
|
112
113
|
}
|
|
113
114
|
return;
|
|
114
115
|
}
|
|
115
|
-
const
|
|
116
|
+
const getIsHydrationTarget = (target) => target === "react" || target === "reactNative" || target === "vue3" || target === "vue2";
|
|
117
|
+
const isHydrationTarget = getIsHydrationTarget(TARGET);
|
|
116
118
|
const AB_TEST_FN_NAME = "bldrAbTest";
|
|
117
119
|
const CONTENT_FN_NAME = "bldrCntntScrpt";
|
|
118
120
|
const getVariantsScriptString = (variants, contentId) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.4.
|
|
1
|
+
export const SDK_VERSION = "0.4.3"
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const React = __importStar(require("react"));
|
|
30
|
-
const react_native_1 = require("react-native");
|
|
31
|
-
const react_1 = require("react");
|
|
32
|
-
const builder_context_js_1 = __importDefault(require("../../context/builder.context.js"));
|
|
33
|
-
const render_component_js_1 = __importDefault(require("./render-component.js"));
|
|
34
|
-
function RenderComponentWithContext(props) {
|
|
35
|
-
return (React.createElement(builder_context_js_1.default.Provider, { value: {
|
|
36
|
-
content: props.context.content,
|
|
37
|
-
state: props.context.state,
|
|
38
|
-
context: props.context.context,
|
|
39
|
-
apiKey: props.context.apiKey,
|
|
40
|
-
registeredComponents: props.context.registeredComponents,
|
|
41
|
-
inheritedStyles: props.context.inheritedStyles,
|
|
42
|
-
} },
|
|
43
|
-
React.createElement(render_component_js_1.default, { componentRef: props.componentRef, componentOptions: props.componentOptions, blockChildren: props.blockChildren, context: props.context })));
|
|
44
|
-
}
|
|
45
|
-
exports.default = RenderComponentWithContext;
|