@builder.io/sdk-react-native 0.0.1-35 → 0.0.1-36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/blocks/button.js +73 -22
- package/src/blocks/button.lite.tsx +5 -4
- package/src/blocks/columns.js +258 -36
- package/src/blocks/columns.lite.tsx +6 -6
- package/src/blocks/custom-code.js +76 -47
- package/src/blocks/custom-code.lite.tsx +12 -12
- package/src/blocks/embed.js +69 -47
- package/src/blocks/embed.lite.tsx +11 -11
- package/src/blocks/form.js +491 -195
- package/src/blocks/form.lite.tsx +49 -49
- package/src/blocks/fragment.js +16 -8
- package/src/blocks/fragment.lite.tsx +3 -3
- package/src/blocks/image.js +88 -80
- package/src/blocks/image.lite.tsx +16 -14
- package/src/blocks/img.js +51 -28
- package/src/blocks/img.lite.tsx +7 -7
- package/src/blocks/input.js +100 -28
- package/src/blocks/input.lite.tsx +5 -5
- package/src/blocks/raw-text.js +16 -12
- package/src/blocks/raw-text.lite.tsx +3 -3
- package/src/blocks/section.js +71 -23
- package/src/blocks/section.lite.tsx +4 -4
- package/src/blocks/select.js +78 -28
- package/src/blocks/select.lite.tsx +5 -5
- package/src/blocks/submit-button.js +47 -21
- package/src/blocks/submit-button.lite.tsx +3 -3
- package/src/blocks/symbol.js +18 -16
- package/src/blocks/symbol.lite.tsx +5 -5
- package/src/blocks/text.js +41 -26
- package/src/blocks/text.lite.tsx +4 -4
- package/src/blocks/textarea.js +60 -24
- package/src/blocks/textarea.lite.tsx +3 -3
- package/src/blocks/video.js +72 -60
- package/src/blocks/video.lite.tsx +6 -6
- package/src/components/block-styles.js +2 -4
- package/src/components/block-styles.lite.tsx +3 -3
- package/src/components/error-boundary.js +11 -9
- package/src/components/error-boundary.lite.tsx +3 -3
- package/src/components/render-block.js +104 -43
- package/src/components/render-block.lite.tsx +13 -13
- package/src/components/render-blocks.js +58 -32
- package/src/components/render-blocks.lite.tsx +11 -11
- package/src/components/render-content.js +124 -52
- package/src/components/render-content.lite.tsx +27 -27
- package/src/constants/device-sizes.js +8 -11
- package/src/context/builder.context.js +2 -4
- package/src/functions/evaluate.js +18 -9
- package/src/functions/get-block-actions.js +9 -10
- package/src/functions/get-block-component-options.js +16 -9
- package/src/functions/get-block-properties.js +19 -15
- package/src/functions/get-block-styles.js +34 -17
- package/src/functions/get-block-tag.js +2 -4
- package/src/functions/get-content.js +48 -26
- package/src/functions/get-content.test.js +37 -26
- package/src/functions/get-fetch.js +5 -7
- package/src/functions/get-global-this.js +5 -7
- package/src/functions/get-processed-block.js +16 -12
- package/src/functions/get-processed-block.test.js +18 -14
- package/src/functions/get-target.js +2 -4
- package/src/functions/if-target.js +1 -3
- package/src/functions/is-browser.js +7 -5
- package/src/functions/is-editing.js +5 -5
- package/src/functions/is-iframe.js +2 -4
- package/src/functions/is-previewing.js +4 -6
- package/src/functions/is-react-native.js +2 -4
- package/src/functions/macro-eval.js +2 -5
- package/src/functions/on-change.js +4 -7
- package/src/functions/on-change.test.js +10 -10
- package/src/functions/previewing-model-name.js +3 -5
- package/src/functions/register-component.js +38 -27
- package/src/functions/register.js +8 -10
- package/src/functions/set-editor-settings.js +5 -7
- package/src/functions/set.js +14 -5
- package/src/functions/set.test.js +14 -14
- package/src/functions/track.js +6 -8
- package/src/index.js +15 -14
- package/src/scripts/init-editing.js +64 -40
|
@@ -4,40 +4,48 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
|
4
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) =>
|
|
7
|
+
var __defNormalProp = (obj, key, value) =>
|
|
8
|
+
key in obj
|
|
9
|
+
? __defProp(obj, key, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value,
|
|
14
|
+
})
|
|
15
|
+
: (obj[key] = value);
|
|
8
16
|
var __spreadValues = (a, b) => {
|
|
9
17
|
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
12
19
|
if (__getOwnPropSymbols)
|
|
13
20
|
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
16
22
|
}
|
|
17
23
|
return a;
|
|
18
24
|
};
|
|
19
25
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
import * as React from
|
|
21
|
-
import { useContext } from
|
|
22
|
-
import { getBlockComponentOptions } from
|
|
23
|
-
import { getBlockProperties } from
|
|
24
|
-
import { getBlockStyles } from
|
|
25
|
-
import { getBlockTag } from
|
|
26
|
-
import { components } from
|
|
27
|
-
import BuilderContext from
|
|
28
|
-
import { getBlockActions } from
|
|
29
|
-
import { getProcessedBlock } from
|
|
30
|
-
import BlockStyles from
|
|
31
|
-
import RenderBlocks from
|
|
26
|
+
import * as React from 'react';
|
|
27
|
+
import { useContext } from 'react';
|
|
28
|
+
import { getBlockComponentOptions } from '../functions/get-block-component-options';
|
|
29
|
+
import { getBlockProperties } from '../functions/get-block-properties';
|
|
30
|
+
import { getBlockStyles } from '../functions/get-block-styles';
|
|
31
|
+
import { getBlockTag } from '../functions/get-block-tag';
|
|
32
|
+
import { components } from '../functions/register-component';
|
|
33
|
+
import BuilderContext from '../context/builder.context';
|
|
34
|
+
import { getBlockActions } from '../functions/get-block-actions';
|
|
35
|
+
import { getProcessedBlock } from '../functions/get-processed-block';
|
|
36
|
+
import BlockStyles from './block-styles';
|
|
37
|
+
import RenderBlocks from './render-blocks';
|
|
32
38
|
function RenderBlock(props) {
|
|
33
39
|
var _a, _b, _c;
|
|
34
40
|
function component() {
|
|
35
41
|
var _a2, _b2;
|
|
36
|
-
const componentName =
|
|
42
|
+
const componentName =
|
|
43
|
+
(_a2 = useBlock().component) == null ? void 0 : _a2.name;
|
|
37
44
|
if (!componentName) {
|
|
38
45
|
return null;
|
|
39
46
|
}
|
|
40
|
-
const ref =
|
|
47
|
+
const ref =
|
|
48
|
+
components[(_b2 = useBlock().component) == null ? void 0 : _b2.name];
|
|
41
49
|
if (componentName && !ref) {
|
|
42
50
|
console.warn(`
|
|
43
51
|
Could not find a registered component named "${componentName}".
|
|
@@ -47,11 +55,15 @@ function RenderBlock(props) {
|
|
|
47
55
|
}
|
|
48
56
|
function componentInfo() {
|
|
49
57
|
var _a2;
|
|
50
|
-
return (_a2 = component == null ? void 0 : component()) == null
|
|
58
|
+
return (_a2 = component == null ? void 0 : component()) == null
|
|
59
|
+
? void 0
|
|
60
|
+
: _a2.info;
|
|
51
61
|
}
|
|
52
62
|
function componentRef() {
|
|
53
63
|
var _a2;
|
|
54
|
-
return (_a2 = component == null ? void 0 : component()) == null
|
|
64
|
+
return (_a2 = component == null ? void 0 : component()) == null
|
|
65
|
+
? void 0
|
|
66
|
+
: _a2.component;
|
|
55
67
|
}
|
|
56
68
|
function tagName() {
|
|
57
69
|
return getBlockTag(useBlock());
|
|
@@ -63,14 +75,14 @@ function RenderBlock(props) {
|
|
|
63
75
|
return getProcessedBlock({
|
|
64
76
|
block: props.block,
|
|
65
77
|
state: builderContext.state,
|
|
66
|
-
context: builderContext.context
|
|
78
|
+
context: builderContext.context,
|
|
67
79
|
});
|
|
68
80
|
}
|
|
69
81
|
function actions() {
|
|
70
82
|
return getBlockActions({
|
|
71
83
|
block: useBlock(),
|
|
72
84
|
state: builderContext.state,
|
|
73
|
-
context: builderContext.context
|
|
85
|
+
context: builderContext.context,
|
|
74
86
|
});
|
|
75
87
|
}
|
|
76
88
|
function css() {
|
|
@@ -82,24 +94,73 @@ function RenderBlock(props) {
|
|
|
82
94
|
const builderContext = useContext(BuilderContext);
|
|
83
95
|
const ComponentRefRef = componentRef();
|
|
84
96
|
const TagNameRef = tagName();
|
|
85
|
-
return /* @__PURE__ */ React.createElement(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
return /* @__PURE__ */ React.createElement(
|
|
98
|
+
React.Fragment,
|
|
99
|
+
null,
|
|
100
|
+
!((_a = componentInfo == null ? void 0 : componentInfo()) == null
|
|
101
|
+
? void 0
|
|
102
|
+
: _a.noWrap)
|
|
103
|
+
? /* @__PURE__ */ React.createElement(
|
|
104
|
+
React.Fragment,
|
|
105
|
+
null,
|
|
106
|
+
/* @__PURE__ */ React.createElement(
|
|
107
|
+
TagNameRef,
|
|
108
|
+
__spreadProps(__spreadValues({}, properties()), {
|
|
109
|
+
style: css(),
|
|
110
|
+
}),
|
|
111
|
+
/* @__PURE__ */ React.createElement(BlockStyles, {
|
|
112
|
+
block: useBlock(),
|
|
113
|
+
}),
|
|
114
|
+
componentRef()
|
|
115
|
+
? /* @__PURE__ */ React.createElement(
|
|
116
|
+
ComponentRefRef,
|
|
117
|
+
__spreadProps(__spreadValues({}, componentOptions()), {
|
|
118
|
+
builderBlock: useBlock(),
|
|
119
|
+
}),
|
|
120
|
+
useBlock().children
|
|
121
|
+
? /* @__PURE__ */ React.createElement(
|
|
122
|
+
React.Fragment,
|
|
123
|
+
null,
|
|
124
|
+
/* @__PURE__ */ React.createElement(RenderBlocks, {
|
|
125
|
+
path: 'children',
|
|
126
|
+
blocks: useBlock().children,
|
|
127
|
+
})
|
|
128
|
+
)
|
|
129
|
+
: null
|
|
130
|
+
)
|
|
131
|
+
: null,
|
|
132
|
+
!componentRef() && useBlock().children && useBlock().children.length
|
|
133
|
+
? /* @__PURE__ */ React.createElement(
|
|
134
|
+
React.Fragment,
|
|
135
|
+
null,
|
|
136
|
+
(_b = useBlock().children) == null
|
|
137
|
+
? void 0
|
|
138
|
+
: _b.map((child) =>
|
|
139
|
+
/* @__PURE__ */ React.createElement(RenderBlock, {
|
|
140
|
+
block: child,
|
|
141
|
+
})
|
|
142
|
+
)
|
|
143
|
+
)
|
|
144
|
+
: null
|
|
145
|
+
)
|
|
146
|
+
)
|
|
147
|
+
: /* @__PURE__ */ React.createElement(
|
|
148
|
+
ComponentRefRef,
|
|
149
|
+
__spreadProps(
|
|
150
|
+
__spreadValues(
|
|
151
|
+
{},
|
|
152
|
+
(_c = componentInfo == null ? void 0 : componentInfo()) == null
|
|
153
|
+
? void 0
|
|
154
|
+
: _c.options
|
|
155
|
+
),
|
|
156
|
+
{
|
|
157
|
+
attributes: properties(),
|
|
158
|
+
builderBlock: useBlock(),
|
|
159
|
+
style: css(),
|
|
160
|
+
children: useBlock().children,
|
|
161
|
+
}
|
|
162
|
+
)
|
|
163
|
+
)
|
|
164
|
+
);
|
|
102
165
|
}
|
|
103
|
-
export {
|
|
104
|
-
RenderBlock as default
|
|
105
|
-
};
|
|
166
|
+
export { RenderBlock as default };
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { View, StyleSheet, Image, Text } from
|
|
3
|
-
import { useState, useContext } from
|
|
4
|
-
import { getBlockComponentOptions } from
|
|
5
|
-
import { getBlockProperties } from
|
|
6
|
-
import { getBlockStyles } from
|
|
7
|
-
import { getBlockTag } from
|
|
8
|
-
import { components } from
|
|
9
|
-
import BuilderContext from
|
|
10
|
-
import { getBlockActions } from
|
|
11
|
-
import { getProcessedBlock } from
|
|
12
|
-
import BlockStyles from
|
|
13
|
-
import RenderBlocks from
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { View, StyleSheet, Image, Text } from 'react-native';
|
|
3
|
+
import { useState, useContext } from 'react';
|
|
4
|
+
import { getBlockComponentOptions } from '../functions/get-block-component-options';
|
|
5
|
+
import { getBlockProperties } from '../functions/get-block-properties';
|
|
6
|
+
import { getBlockStyles } from '../functions/get-block-styles';
|
|
7
|
+
import { getBlockTag } from '../functions/get-block-tag';
|
|
8
|
+
import { components } from '../functions/register-component';
|
|
9
|
+
import BuilderContext from '../context/builder.context.lite';
|
|
10
|
+
import { getBlockActions } from '../functions/get-block-actions';
|
|
11
|
+
import { getProcessedBlock } from '../functions/get-processed-block';
|
|
12
|
+
import BlockStyles from './block-styles.lite';
|
|
13
|
+
import RenderBlocks from './render-blocks.lite';
|
|
14
14
|
|
|
15
15
|
export default function RenderBlock(props) {
|
|
16
16
|
function component() {
|
|
@@ -1,47 +1,73 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { View, StyleSheet } from
|
|
3
|
-
import { isEditing } from
|
|
4
|
-
import RenderBlock from
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { View, StyleSheet } from 'react-native';
|
|
3
|
+
import { isEditing } from '../functions/is-editing';
|
|
4
|
+
import RenderBlock from './render-block';
|
|
5
5
|
function RenderBlocks(props) {
|
|
6
6
|
var _a, _b;
|
|
7
7
|
function onClick() {
|
|
8
8
|
var _a2, _b2;
|
|
9
9
|
if (isEditing() && !((_a2 = props.blocks) == null ? void 0 : _a2.length)) {
|
|
10
|
-
(_b2 = window.parent) == null
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
(_b2 = window.parent) == null
|
|
11
|
+
? void 0
|
|
12
|
+
: _b2.postMessage(
|
|
13
|
+
{
|
|
14
|
+
type: 'builder.clickEmptyBlocks',
|
|
15
|
+
data: {
|
|
16
|
+
parentElementId: props.parent,
|
|
17
|
+
dataPath: props.path,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
'*'
|
|
21
|
+
);
|
|
17
22
|
}
|
|
18
23
|
}
|
|
19
24
|
function onMouseEnter() {
|
|
20
25
|
var _a2, _b2;
|
|
21
26
|
if (isEditing() && !((_a2 = props.blocks) == null ? void 0 : _a2.length)) {
|
|
22
|
-
(_b2 = window.parent) == null
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
(_b2 = window.parent) == null
|
|
28
|
+
? void 0
|
|
29
|
+
: _b2.postMessage(
|
|
30
|
+
{
|
|
31
|
+
type: 'builder.hoverEmptyBlocks',
|
|
32
|
+
data: {
|
|
33
|
+
parentElementId: props.parent,
|
|
34
|
+
dataPath: props.path,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
'*'
|
|
38
|
+
);
|
|
29
39
|
}
|
|
30
40
|
}
|
|
31
|
-
return /* @__PURE__ */ React.createElement(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
return /* @__PURE__ */ React.createElement(
|
|
42
|
+
View,
|
|
43
|
+
{
|
|
44
|
+
'builder-path': props.path,
|
|
45
|
+
'builder-parent-id': props.parent,
|
|
46
|
+
onClick: (event) => onClick,
|
|
47
|
+
onMouseEnter: (event) => onMouseEnter,
|
|
48
|
+
className:
|
|
49
|
+
'builder-blocks' +
|
|
50
|
+
(!((_a = props.blocks) == null ? void 0 : _a.length)
|
|
51
|
+
? ' no-blocks'
|
|
52
|
+
: ''),
|
|
53
|
+
style: styles.view1,
|
|
54
|
+
},
|
|
55
|
+
props.blocks
|
|
56
|
+
? /* @__PURE__ */ React.createElement(
|
|
57
|
+
React.Fragment,
|
|
58
|
+
null,
|
|
59
|
+
(_b = props.blocks) == null
|
|
60
|
+
? void 0
|
|
61
|
+
: _b.map((block) =>
|
|
62
|
+
/* @__PURE__ */ React.createElement(RenderBlock, {
|
|
63
|
+
block,
|
|
64
|
+
})
|
|
65
|
+
)
|
|
66
|
+
)
|
|
67
|
+
: null
|
|
68
|
+
);
|
|
41
69
|
}
|
|
42
70
|
const styles = StyleSheet.create({
|
|
43
|
-
view1: { display:
|
|
71
|
+
view1: { display: 'flex', flexDirection: 'column', alignItems: 'stretch' },
|
|
44
72
|
});
|
|
45
|
-
export {
|
|
46
|
-
RenderBlocks as default
|
|
47
|
-
};
|
|
73
|
+
export { RenderBlocks as default };
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { View, StyleSheet, Image, Text } from
|
|
3
|
-
import { useState, useContext } from
|
|
4
|
-
import { isEditing } from
|
|
5
|
-
import RenderBlock from
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { View, StyleSheet, Image, Text } from 'react-native';
|
|
3
|
+
import { useState, useContext } from 'react';
|
|
4
|
+
import { isEditing } from '../functions/is-editing';
|
|
5
|
+
import RenderBlock from './render-block.lite';
|
|
6
6
|
|
|
7
7
|
export default function RenderBlocks(props) {
|
|
8
8
|
function onClick() {
|
|
9
9
|
if (isEditing() && !props.blocks?.length) {
|
|
10
10
|
window.parent?.postMessage(
|
|
11
11
|
{
|
|
12
|
-
type:
|
|
12
|
+
type: 'builder.clickEmptyBlocks',
|
|
13
13
|
data: {
|
|
14
14
|
parentElementId: props.parent,
|
|
15
15
|
dataPath: props.path,
|
|
16
16
|
},
|
|
17
17
|
},
|
|
18
|
-
|
|
18
|
+
'*'
|
|
19
19
|
);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -24,13 +24,13 @@ export default function RenderBlocks(props) {
|
|
|
24
24
|
if (isEditing() && !props.blocks?.length) {
|
|
25
25
|
window.parent?.postMessage(
|
|
26
26
|
{
|
|
27
|
-
type:
|
|
27
|
+
type: 'builder.hoverEmptyBlocks',
|
|
28
28
|
data: {
|
|
29
29
|
parentElementId: props.parent,
|
|
30
30
|
dataPath: props.path,
|
|
31
31
|
},
|
|
32
32
|
},
|
|
33
|
-
|
|
33
|
+
'*'
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -41,7 +41,7 @@ export default function RenderBlocks(props) {
|
|
|
41
41
|
builder-parent-id={props.parent}
|
|
42
42
|
onClick={(event) => onClick}
|
|
43
43
|
onMouseEnter={(event) => onMouseEnter}
|
|
44
|
-
className={
|
|
44
|
+
className={'builder-blocks' + (!props.blocks?.length ? ' no-blocks' : '')}
|
|
45
45
|
style={styles.view1}
|
|
46
46
|
>
|
|
47
47
|
{props.blocks ? (
|
|
@@ -56,5 +56,5 @@ export default function RenderBlocks(props) {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
const styles = StyleSheet.create({
|
|
59
|
-
view1: { display:
|
|
59
|
+
view1: { display: 'flex', flexDirection: 'column', alignItems: 'stretch' },
|
|
60
60
|
});
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { View, Text } from
|
|
3
|
-
import { useState, useEffect } from
|
|
4
|
-
import { isBrowser } from
|
|
5
|
-
import RenderBlock from
|
|
6
|
-
import BuilderContext from
|
|
7
|
-
import { track } from
|
|
8
|
-
import { isReactNative } from
|
|
9
|
-
import { isEditing } from
|
|
10
|
-
import { isPreviewing } from
|
|
11
|
-
import { previewingModelName } from
|
|
12
|
-
import { getContent } from
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { View, Text } from 'react-native';
|
|
3
|
+
import { useState, useEffect } from 'react';
|
|
4
|
+
import { isBrowser } from '../functions/is-browser';
|
|
5
|
+
import RenderBlock from './render-block';
|
|
6
|
+
import BuilderContext from '../context/builder.context';
|
|
7
|
+
import { track } from '../functions/track';
|
|
8
|
+
import { isReactNative } from '../functions/is-react-native';
|
|
9
|
+
import { isEditing } from '../functions/is-editing';
|
|
10
|
+
import { isPreviewing } from '../functions/is-previewing';
|
|
11
|
+
import { previewingModelName } from '../functions/previewing-model-name';
|
|
12
|
+
import { getContent } from '../functions/get-content';
|
|
13
13
|
function RenderContent(props) {
|
|
14
14
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
15
15
|
function useContent() {
|
|
@@ -20,10 +20,12 @@ function RenderContent(props) {
|
|
|
20
20
|
const [context, setContext] = useState(() => ({}));
|
|
21
21
|
const [overrideContent, setOverrideContent] = useState(() => null);
|
|
22
22
|
function getCssFromFont(font, data) {
|
|
23
|
-
const family =
|
|
24
|
-
|
|
23
|
+
const family =
|
|
24
|
+
font.family +
|
|
25
|
+
(font.kind && !font.kind.includes('#') ? ', ' + font.kind : '');
|
|
26
|
+
const name = family.split(',')[0];
|
|
25
27
|
const url = font.fileUrl ? font.fileUrl : font.files && font.files.regular;
|
|
26
|
-
let str =
|
|
28
|
+
let str = '';
|
|
27
29
|
if (url && family && name) {
|
|
28
30
|
str += `
|
|
29
31
|
@font-face {
|
|
@@ -56,21 +58,32 @@ function RenderContent(props) {
|
|
|
56
58
|
return str;
|
|
57
59
|
}
|
|
58
60
|
function getFontCss(data) {
|
|
59
|
-
return (
|
|
61
|
+
return (
|
|
62
|
+
((data == null ? void 0 : data.customFonts) &&
|
|
63
|
+
data.customFonts.length &&
|
|
64
|
+
data.customFonts
|
|
65
|
+
.map((font) => this.getCssFromFont(font, data))
|
|
66
|
+
.join(' ')) ||
|
|
67
|
+
''
|
|
68
|
+
);
|
|
60
69
|
}
|
|
61
70
|
function processMessage(event) {
|
|
62
71
|
const { data } = event;
|
|
63
72
|
if (data) {
|
|
64
73
|
switch (data.type) {
|
|
65
|
-
case
|
|
66
|
-
const key =
|
|
74
|
+
case 'builder.contentUpdate': {
|
|
75
|
+
const key =
|
|
76
|
+
data.data.key ||
|
|
77
|
+
data.data.alias ||
|
|
78
|
+
data.data.entry ||
|
|
79
|
+
data.data.modelName;
|
|
67
80
|
const contentData = data.data.data;
|
|
68
81
|
if (key === props.model) {
|
|
69
82
|
setOverrideContent(contentData);
|
|
70
83
|
}
|
|
71
84
|
break;
|
|
72
85
|
}
|
|
73
|
-
case
|
|
86
|
+
case 'builder.patchUpdates': {
|
|
74
87
|
break;
|
|
75
88
|
}
|
|
76
89
|
}
|
|
@@ -79,29 +92,29 @@ function RenderContent(props) {
|
|
|
79
92
|
useEffect(() => {
|
|
80
93
|
if (isBrowser()) {
|
|
81
94
|
if (isEditing()) {
|
|
82
|
-
window.addEventListener(
|
|
95
|
+
window.addEventListener('message', processMessage);
|
|
83
96
|
}
|
|
84
97
|
if (useContent() && !isEditing()) {
|
|
85
|
-
track(
|
|
86
|
-
contentId: useContent().id
|
|
98
|
+
track('impression', {
|
|
99
|
+
contentId: useContent().id,
|
|
87
100
|
});
|
|
88
101
|
}
|
|
89
102
|
if (isPreviewing()) {
|
|
90
103
|
if (props.model && previewingModelName() === props.model) {
|
|
91
104
|
const options = {};
|
|
92
105
|
const currentUrl = new URL(location.href);
|
|
93
|
-
const apiKey = currentUrl.searchParams.get(
|
|
106
|
+
const apiKey = currentUrl.searchParams.get('apiKey');
|
|
94
107
|
if (apiKey) {
|
|
95
|
-
const builderPrefix =
|
|
108
|
+
const builderPrefix = 'builder.';
|
|
96
109
|
currentUrl.searchParams.forEach((value, key) => {
|
|
97
110
|
if (key.startsWith(builderPrefix)) {
|
|
98
|
-
options[key.replace(builderPrefix,
|
|
111
|
+
options[key.replace(builderPrefix, '')] = value;
|
|
99
112
|
}
|
|
100
113
|
});
|
|
101
114
|
getContent({
|
|
102
115
|
model: props.model,
|
|
103
116
|
apiKey,
|
|
104
|
-
options
|
|
117
|
+
options,
|
|
105
118
|
}).then((content) => {
|
|
106
119
|
if (content) {
|
|
107
120
|
setOverrideContent(content);
|
|
@@ -112,32 +125,91 @@ function RenderContent(props) {
|
|
|
112
125
|
}
|
|
113
126
|
}
|
|
114
127
|
}, []);
|
|
115
|
-
return /* @__PURE__ */ React.createElement(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
128
|
+
return /* @__PURE__ */ React.createElement(
|
|
129
|
+
BuilderContext.Provider,
|
|
130
|
+
{
|
|
131
|
+
value: {
|
|
132
|
+
get content() {
|
|
133
|
+
return useContent();
|
|
134
|
+
},
|
|
135
|
+
get state() {
|
|
136
|
+
return state;
|
|
137
|
+
},
|
|
138
|
+
get context() {
|
|
139
|
+
return context;
|
|
140
|
+
},
|
|
119
141
|
},
|
|
120
|
-
get state() {
|
|
121
|
-
return state;
|
|
122
|
-
},
|
|
123
|
-
get context() {
|
|
124
|
-
return context;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}, useContent() ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(View, {
|
|
128
|
-
onClick: (event) => {
|
|
129
|
-
if (!isEditing()) {
|
|
130
|
-
track("click", {
|
|
131
|
-
contentId: useContent().id
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
142
|
},
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
143
|
+
useContent()
|
|
144
|
+
? /* @__PURE__ */ React.createElement(
|
|
145
|
+
React.Fragment,
|
|
146
|
+
null,
|
|
147
|
+
/* @__PURE__ */ React.createElement(
|
|
148
|
+
View,
|
|
149
|
+
{
|
|
150
|
+
onClick: (event) => {
|
|
151
|
+
if (!isEditing()) {
|
|
152
|
+
track('click', {
|
|
153
|
+
contentId: useContent().id,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
'data-builder-content-id':
|
|
158
|
+
(_a = useContent == null ? void 0 : useContent()) == null
|
|
159
|
+
? void 0
|
|
160
|
+
: _a.id,
|
|
161
|
+
},
|
|
162
|
+
(((_c =
|
|
163
|
+
(_b = useContent == null ? void 0 : useContent()) == null
|
|
164
|
+
? void 0
|
|
165
|
+
: _b.data) == null
|
|
166
|
+
? void 0
|
|
167
|
+
: _c.cssCode) ||
|
|
168
|
+
(((_e =
|
|
169
|
+
(_d = useContent == null ? void 0 : useContent()) == null
|
|
170
|
+
? void 0
|
|
171
|
+
: _d.data) == null
|
|
172
|
+
? void 0
|
|
173
|
+
: _e.customFonts) &&
|
|
174
|
+
((_g =
|
|
175
|
+
(_f = useContent == null ? void 0 : useContent()) == null
|
|
176
|
+
? void 0
|
|
177
|
+
: _f.data) == null
|
|
178
|
+
? void 0
|
|
179
|
+
: _g.customFonts.length))) &&
|
|
180
|
+
!isReactNative()
|
|
181
|
+
? /* @__PURE__ */ React.createElement(
|
|
182
|
+
View,
|
|
183
|
+
null,
|
|
184
|
+
/* @__PURE__ */ React.createElement(
|
|
185
|
+
Text,
|
|
186
|
+
null,
|
|
187
|
+
useContent().data.cssCode
|
|
188
|
+
),
|
|
189
|
+
/* @__PURE__ */ React.createElement(
|
|
190
|
+
Text,
|
|
191
|
+
null,
|
|
192
|
+
getFontCss(useContent().data)
|
|
193
|
+
)
|
|
194
|
+
)
|
|
195
|
+
: null,
|
|
196
|
+
(_j =
|
|
197
|
+
(_i =
|
|
198
|
+
(_h = useContent == null ? void 0 : useContent()) == null
|
|
199
|
+
? void 0
|
|
200
|
+
: _h.data) == null
|
|
201
|
+
? void 0
|
|
202
|
+
: _i.blocks) == null
|
|
203
|
+
? void 0
|
|
204
|
+
: _j.map((block) =>
|
|
205
|
+
/* @__PURE__ */ React.createElement(RenderBlock, {
|
|
206
|
+
key: block.id,
|
|
207
|
+
block,
|
|
208
|
+
})
|
|
209
|
+
)
|
|
210
|
+
)
|
|
211
|
+
)
|
|
212
|
+
: null
|
|
213
|
+
);
|
|
140
214
|
}
|
|
141
|
-
export {
|
|
142
|
-
RenderContent as default
|
|
143
|
-
};
|
|
215
|
+
export { RenderContent as default };
|