@builder.io/sdk-react-native 0.0.1-22 → 0.0.1-26

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.
Files changed (77) hide show
  1. package/package.json +3 -2
  2. package/src/blocks/button.js +66 -24
  3. package/src/blocks/button.lite.tsx +9 -13
  4. package/src/blocks/columns.js +247 -36
  5. package/src/blocks/columns.lite.tsx +7 -7
  6. package/src/blocks/custom-code.js +73 -47
  7. package/src/blocks/custom-code.lite.tsx +12 -16
  8. package/src/blocks/embed.js +66 -47
  9. package/src/blocks/embed.lite.tsx +11 -13
  10. package/src/blocks/form.js +436 -198
  11. package/src/blocks/form.lite.tsx +67 -78
  12. package/src/blocks/fragment.js +16 -11
  13. package/src/blocks/fragment.lite.tsx +8 -5
  14. package/src/blocks/image.js +89 -80
  15. package/src/blocks/image.lite.tsx +44 -13
  16. package/src/blocks/img.js +45 -28
  17. package/src/blocks/img.lite.tsx +7 -7
  18. package/src/blocks/input.js +93 -28
  19. package/src/blocks/input.lite.tsx +5 -9
  20. package/src/blocks/raw-text.js +16 -12
  21. package/src/blocks/raw-text.lite.tsx +3 -3
  22. package/src/blocks/section.js +66 -23
  23. package/src/blocks/section.lite.tsx +4 -4
  24. package/src/blocks/select.js +67 -28
  25. package/src/blocks/select.lite.tsx +6 -10
  26. package/src/blocks/submit-button.js +41 -21
  27. package/src/blocks/submit-button.lite.tsx +3 -3
  28. package/src/blocks/symbol.js +18 -16
  29. package/src/blocks/symbol.lite.tsx +5 -5
  30. package/src/blocks/text.js +29 -27
  31. package/src/blocks/text.lite.tsx +4 -9
  32. package/src/blocks/textarea.js +53 -24
  33. package/src/blocks/textarea.lite.tsx +3 -3
  34. package/src/blocks/video.js +112 -46
  35. package/src/blocks/video.lite.tsx +6 -6
  36. package/src/components/block-styles.js +2 -4
  37. package/src/components/block-styles.lite.tsx +3 -3
  38. package/src/components/error-boundary.js +11 -9
  39. package/src/components/error-boundary.lite.tsx +3 -3
  40. package/src/components/render-block.js +89 -36
  41. package/src/components/render-block.lite.tsx +47 -32
  42. package/src/components/render-blocks.js +56 -32
  43. package/src/components/render-blocks.lite.tsx +16 -16
  44. package/src/components/render-content.js +160 -36
  45. package/src/components/render-content.lite.tsx +139 -39
  46. package/src/constants/device-sizes.js +8 -11
  47. package/src/context/builder.context.js +2 -4
  48. package/src/functions/evaluate.js +17 -9
  49. package/src/functions/get-block-actions.js +9 -10
  50. package/src/functions/get-block-component-options.js +11 -10
  51. package/src/functions/get-block-properties.js +15 -17
  52. package/src/functions/get-block-styles.js +25 -17
  53. package/src/functions/get-block-tag.js +2 -4
  54. package/src/functions/get-content.js +54 -27
  55. package/src/functions/get-fetch.js +11 -0
  56. package/src/functions/get-global-this.js +17 -0
  57. package/src/functions/get-processed-block.js +11 -13
  58. package/src/functions/get-processed-block.test.js +14 -14
  59. package/src/functions/get-target.js +3 -5
  60. package/src/functions/if-target.js +1 -3
  61. package/src/functions/is-browser.js +3 -5
  62. package/src/functions/is-editing.js +3 -5
  63. package/src/functions/is-iframe.js +2 -4
  64. package/src/functions/is-previewing.js +13 -0
  65. package/src/functions/is-react-native.js +2 -4
  66. package/src/functions/macro-eval.js +2 -5
  67. package/src/functions/on-change.js +4 -7
  68. package/src/functions/on-change.test.js +10 -10
  69. package/src/functions/previewing-model-name.js +10 -0
  70. package/src/functions/register-component.js +34 -28
  71. package/src/functions/register.js +8 -10
  72. package/src/functions/set-editor-settings.js +5 -7
  73. package/src/functions/set.js +10 -4
  74. package/src/functions/set.test.js +14 -14
  75. package/src/functions/track.js +6 -8
  76. package/src/index.js +18 -20
  77. package/src/scripts/init-editing.js +65 -31
@@ -1,47 +1,71 @@
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";
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 ? void 0 : _b2.postMessage({
11
- type: "builder.clickEmptyBlocks",
12
- data: {
13
- parentElementId: props.parent,
14
- dataPath: props.path
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 ? void 0 : _b2.postMessage({
23
- type: "builder.hoverEmptyBlocks",
24
- data: {
25
- parentElementId: props.parent,
26
- dataPath: props.path
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(View, {
32
- "builder-path": props.path,
33
- "builder-parent-id": props.parent,
34
- onClick: (event) => onClick,
35
- onMouseEnter: (event) => onMouseEnter,
36
- className: "builder-blocks" + (!((_a = props.blocks) == null ? void 0 : _a.length) ? " no-blocks" : ""),
37
- style: styles.view1
38
- }, props.blocks && /* @__PURE__ */ React.createElement(React.Fragment, null, (_b = props.blocks) == null ? void 0 : _b.map((block) => /* @__PURE__ */ React.createElement(RenderBlock, {
39
- block
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) ? ' no-blocks' : ''),
51
+ style: styles.view1,
52
+ },
53
+ props.blocks
54
+ ? /* @__PURE__ */ React.createElement(
55
+ React.Fragment,
56
+ null,
57
+ (_b = props.blocks) == null
58
+ ? void 0
59
+ : _b.map(block =>
60
+ /* @__PURE__ */ React.createElement(RenderBlock, {
61
+ block,
62
+ })
63
+ )
64
+ )
65
+ : null
66
+ );
41
67
  }
42
68
  const styles = StyleSheet.create({
43
- view1: { display: "flex", flexDirection: "column", alignItems: "stretch" }
69
+ view1: { display: 'flex', flexDirection: 'column', alignItems: 'stretch' },
44
70
  });
45
- export {
46
- RenderBlocks as default
47
- };
71
+ export { RenderBlocks as default };
@@ -1,21 +1,21 @@
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";
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: "builder.clickEmptyBlocks",
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: "builder.hoverEmptyBlocks",
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
  }
@@ -39,22 +39,22 @@ export default function RenderBlocks(props) {
39
39
  <View
40
40
  builder-path={props.path}
41
41
  builder-parent-id={props.parent}
42
- onClick={(event) => onClick}
43
- onMouseEnter={(event) => onMouseEnter}
44
- className={"builder-blocks" + (!props.blocks?.length ? " no-blocks" : "")}
42
+ onClick={event => onClick}
43
+ onMouseEnter={event => onMouseEnter}
44
+ className={'builder-blocks' + (!props.blocks?.length ? ' no-blocks' : '')}
45
45
  style={styles.view1}
46
46
  >
47
- {props.blocks && (
47
+ {props.blocks ? (
48
48
  <>
49
- {props.blocks?.map((block) => (
49
+ {props.blocks?.map(block => (
50
50
  <RenderBlock block={block} />
51
51
  ))}
52
52
  </>
53
- )}
53
+ ) : null}
54
54
  </View>
55
55
  );
56
56
  }
57
57
 
58
58
  const styles = StyleSheet.create({
59
- view1: { display: "flex", flexDirection: "column", alignItems: "stretch" },
59
+ view1: { display: 'flex', flexDirection: 'column', alignItems: 'stretch' },
60
60
  });
@@ -1,13 +1,17 @@
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";
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';
9
13
  function RenderContent(props) {
10
- var _a, _b, _c, _d, _e, _f;
14
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11
15
  function useContent() {
12
16
  return overrideContent || props.content;
13
17
  }
@@ -15,11 +19,55 @@ function RenderContent(props) {
15
19
  const [state, setState] = useState(() => ({}));
16
20
  const [context, setContext] = useState(() => ({}));
17
21
  const [overrideContent, setOverrideContent] = useState(() => null);
22
+ function getCssFromFont(font, data) {
23
+ const family = font.family + (font.kind && !font.kind.includes('#') ? ', ' + font.kind : '');
24
+ const name = family.split(',')[0];
25
+ const url = font.fileUrl ? font.fileUrl : font.files && font.files.regular;
26
+ let str = '';
27
+ if (url && family && name) {
28
+ str += `
29
+ @font-face {
30
+ font-family: "${family}";
31
+ src: local("${name}"), url('${url}') format('woff2');
32
+ font-display: fallback;
33
+ font-weight: 400;
34
+ }
35
+ `.trim();
36
+ }
37
+ if (font.files) {
38
+ for (const weight in font.files) {
39
+ const isNumber = String(Number(weight)) === weight;
40
+ if (!isNumber) {
41
+ continue;
42
+ }
43
+ const weightUrl = font.files[weight];
44
+ if (weightUrl && weightUrl !== url) {
45
+ str += `
46
+ @font-face {
47
+ font-family: "${family}";
48
+ src: url('${weightUrl}') format('woff2');
49
+ font-display: fallback;
50
+ font-weight: ${weight};
51
+ }
52
+ `.trim();
53
+ }
54
+ }
55
+ }
56
+ return str;
57
+ }
58
+ function getFontCss(data) {
59
+ return (
60
+ ((data == null ? void 0 : data.customFonts) &&
61
+ data.customFonts.length &&
62
+ data.customFonts.map(font => this.getCssFromFont(font, data)).join(' ')) ||
63
+ ''
64
+ );
65
+ }
18
66
  function processMessage(event) {
19
67
  const { data } = event;
20
68
  if (data) {
21
69
  switch (data.type) {
22
- case "builder.contentUpdate": {
70
+ case 'builder.contentUpdate': {
23
71
  const key = data.data.key || data.data.alias || data.data.entry || data.data.modelName;
24
72
  const contentData = data.data.data;
25
73
  if (key === props.model) {
@@ -27,7 +75,7 @@ function RenderContent(props) {
27
75
  }
28
76
  break;
29
77
  }
30
- case "builder.patchUpdates": {
78
+ case 'builder.patchUpdates': {
31
79
  break;
32
80
  }
33
81
  }
@@ -35,33 +83,109 @@ function RenderContent(props) {
35
83
  }
36
84
  useEffect(() => {
37
85
  if (isBrowser()) {
38
- window.addEventListener("message", processMessage);
86
+ if (isEditing()) {
87
+ window.addEventListener('message', processMessage);
88
+ }
89
+ if (useContent() && !isEditing()) {
90
+ track('impression', {
91
+ contentId: useContent().id,
92
+ });
93
+ }
94
+ if (isPreviewing()) {
95
+ if (props.model && previewingModelName() === props.model) {
96
+ const options = {};
97
+ const currentUrl = new URL(location.href);
98
+ const apiKey = currentUrl.searchParams.get('apiKey');
99
+ if (apiKey) {
100
+ const builderPrefix = 'builder.';
101
+ currentUrl.searchParams.forEach((value, key) => {
102
+ if (key.startsWith(builderPrefix)) {
103
+ options[key.replace(builderPrefix, '')] = value;
104
+ }
105
+ });
106
+ getContent({
107
+ model: props.model,
108
+ apiKey,
109
+ options,
110
+ }).then(content => {
111
+ if (content) {
112
+ setOverrideContent(content);
113
+ }
114
+ });
115
+ }
116
+ }
117
+ }
39
118
  }
40
119
  }, []);
41
- return /* @__PURE__ */ React.createElement(BuilderContext.Provider, {
42
- value: {
43
- get content() {
44
- return props.content;
120
+ return /* @__PURE__ */ React.createElement(
121
+ BuilderContext.Provider,
122
+ {
123
+ value: {
124
+ get content() {
125
+ return useContent();
126
+ },
127
+ get state() {
128
+ return state;
129
+ },
130
+ get context() {
131
+ return context;
132
+ },
45
133
  },
46
- get state() {
47
- return state;
48
- },
49
- get context() {
50
- return context;
51
- }
52
- }
53
- }, /* @__PURE__ */ React.createElement(View, {
54
- onClick: (event) => {
55
- track("click", {
56
- contentId: props.content.id
57
- });
58
134
  },
59
- "data-builder-content-id": (_a = props.content) == null ? void 0 : _a.id
60
- }, ((_c = (_b = useContent == null ? void 0 : useContent()) == null ? void 0 : _b.data) == null ? void 0 : _c.cssCode) && !isReactNative() && /* @__PURE__ */ React.createElement(View, null, /* @__PURE__ */ React.createElement(Text, null, useContent().data.cssCode)), (_f = (_e = (_d = useContent == null ? void 0 : useContent()) == null ? void 0 : _d.data) == null ? void 0 : _e.blocks) == null ? void 0 : _f.map((block) => /* @__PURE__ */ React.createElement(RenderBlock, {
61
- key: block.id,
62
- block
63
- }))));
135
+ useContent()
136
+ ? /* @__PURE__ */ React.createElement(
137
+ React.Fragment,
138
+ null,
139
+ /* @__PURE__ */ React.createElement(
140
+ View,
141
+ {
142
+ onClick: event => {
143
+ if (!isEditing()) {
144
+ track('click', {
145
+ contentId: useContent().id,
146
+ });
147
+ }
148
+ },
149
+ 'data-builder-content-id':
150
+ (_a = useContent == null ? void 0 : useContent()) == null ? void 0 : _a.id,
151
+ },
152
+ (((_c = (_b = useContent == null ? void 0 : useContent()) == null ? void 0 : _b.data) ==
153
+ null
154
+ ? void 0
155
+ : _c.cssCode) ||
156
+ (((_e =
157
+ (_d = useContent == null ? void 0 : useContent()) == null ? void 0 : _d.data) ==
158
+ null
159
+ ? void 0
160
+ : _e.customFonts) &&
161
+ ((_g =
162
+ (_f = useContent == null ? void 0 : useContent()) == null ? void 0 : _f.data) ==
163
+ null
164
+ ? void 0
165
+ : _g.customFonts.length))) &&
166
+ !isReactNative()
167
+ ? /* @__PURE__ */ React.createElement(
168
+ View,
169
+ null,
170
+ /* @__PURE__ */ React.createElement(Text, null, useContent().data.cssCode),
171
+ /* @__PURE__ */ React.createElement(Text, null, getFontCss(useContent().data))
172
+ )
173
+ : null,
174
+ (_j =
175
+ (_i = (_h = useContent == null ? void 0 : useContent()) == null ? void 0 : _h.data) ==
176
+ null
177
+ ? void 0
178
+ : _i.blocks) == null
179
+ ? void 0
180
+ : _j.map(block =>
181
+ /* @__PURE__ */ React.createElement(RenderBlock, {
182
+ key: block.id,
183
+ block,
184
+ })
185
+ )
186
+ )
187
+ )
188
+ : null
189
+ );
64
190
  }
65
- export {
66
- RenderContent as default
67
- };
191
+ export { RenderContent as default };
@@ -1,13 +1,17 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
- import { useState, useContext, useEffect } from "react";
4
- import { isBrowser } from "../functions/is-browser";
5
- import RenderBlock from "./render-block.lite";
6
- import BuilderContext from "../context/builder.context.lite";
7
- import { track } from "../functions/track";
8
- import { ifTarget } from "../functions/if-target";
9
- import { onChange } from "../functions/on-change";
10
- import { isReactNative } from "../functions/is-react-native";
1
+ import * as React from 'react';
2
+ import { View, StyleSheet, Image, Text } from 'react-native';
3
+ import { useState, useContext, useEffect } from 'react';
4
+ import { isBrowser } from '../functions/is-browser';
5
+ import RenderBlock from './render-block.lite';
6
+ import BuilderContext from '../context/builder.context.lite';
7
+ import { track } from '../functions/track';
8
+ import { ifTarget } from '../functions/if-target';
9
+ import { onChange } from '../functions/on-change';
10
+ import { isReactNative } from '../functions/is-react-native';
11
+ import { isEditing } from '../functions/is-editing';
12
+ import { isPreviewing } from '../functions/is-previewing';
13
+ import { previewingModelName } from '../functions/previewing-model-name';
14
+ import { getContent } from '../functions/get-content';
11
15
 
12
16
  export default function RenderContent(props) {
13
17
  function useContent() {
@@ -22,17 +26,71 @@ export default function RenderContent(props) {
22
26
 
23
27
  const [overrideContent, setOverrideContent] = useState(() => null);
24
28
 
29
+ function getCssFromFont(font, data) {
30
+ // TODO: compute what font sizes are used and only load those.......
31
+ const family = font.family + (font.kind && !font.kind.includes('#') ? ', ' + font.kind : '');
32
+ const name = family.split(',')[0];
33
+ const url = font.fileUrl ? font.fileUrl : font.files && font.files.regular;
34
+ let str = '';
35
+
36
+ if (url && family && name) {
37
+ str += `
38
+ @font-face {
39
+ font-family: "${family}";
40
+ src: local("${name}"), url('${url}') format('woff2');
41
+ font-display: fallback;
42
+ font-weight: 400;
43
+ }
44
+ `.trim();
45
+ }
46
+
47
+ if (font.files) {
48
+ for (const weight in font.files) {
49
+ const isNumber = String(Number(weight)) === weight;
50
+
51
+ if (!isNumber) {
52
+ continue;
53
+ } // TODO: maybe limit number loaded
54
+
55
+ const weightUrl = font.files[weight];
56
+
57
+ if (weightUrl && weightUrl !== url) {
58
+ str += `
59
+ @font-face {
60
+ font-family: "${family}";
61
+ src: url('${weightUrl}') format('woff2');
62
+ font-display: fallback;
63
+ font-weight: ${weight};
64
+ }
65
+ `.trim();
66
+ }
67
+ }
68
+ }
69
+
70
+ return str;
71
+ }
72
+
73
+ function getFontCss(data) {
74
+ // TODO: flag for this
75
+ // if (!this.builder.allowCustomFonts) {
76
+ // return '';
77
+ // }
78
+ // TODO: separate internal data from external
79
+ return (
80
+ (data?.customFonts &&
81
+ data.customFonts.length &&
82
+ data.customFonts.map(font => this.getCssFromFont(font, data)).join(' ')) ||
83
+ ''
84
+ );
85
+ }
86
+
25
87
  function processMessage(event) {
26
88
  const { data } = event;
27
89
 
28
90
  if (data) {
29
91
  switch (data.type) {
30
- case "builder.contentUpdate": {
31
- const key =
32
- data.data.key ||
33
- data.data.alias ||
34
- data.data.entry ||
35
- data.data.modelName;
92
+ case 'builder.contentUpdate': {
93
+ const key = data.data.key || data.data.alias || data.data.entry || data.data.modelName;
36
94
  const contentData = data.data.data; // oof
37
95
 
38
96
  if (key === props.model) {
@@ -42,7 +100,7 @@ export default function RenderContent(props) {
42
100
  break;
43
101
  }
44
102
 
45
- case "builder.patchUpdates": {
103
+ case 'builder.patchUpdates': {
46
104
  // TODO
47
105
  break;
48
106
  }
@@ -52,10 +110,42 @@ export default function RenderContent(props) {
52
110
 
53
111
  useEffect(() => {
54
112
  if (isBrowser()) {
55
- window.addEventListener("message", processMessage); // TODO: run this when content is defined
56
- // track('impression', {
57
- // contentId: props.content!.id,
58
- // });
113
+ if (isEditing()) {
114
+ window.addEventListener('message', processMessage);
115
+ }
116
+
117
+ if (useContent() && !isEditing()) {
118
+ track('impression', {
119
+ contentId: useContent().id,
120
+ });
121
+ }
122
+
123
+ if (isPreviewing()) {
124
+ if (props.model && previewingModelName() === props.model) {
125
+ const options = {};
126
+ const currentUrl = new URL(location.href);
127
+ const apiKey = currentUrl.searchParams.get('apiKey');
128
+
129
+ if (apiKey) {
130
+ const builderPrefix = 'builder.';
131
+ currentUrl.searchParams.forEach((value, key) => {
132
+ if (key.startsWith(builderPrefix)) {
133
+ options[key.replace(builderPrefix, '')] = value;
134
+ }
135
+ }); // TODO: need access to API key
136
+
137
+ getContent({
138
+ model: props.model,
139
+ apiKey,
140
+ options,
141
+ }).then(content => {
142
+ if (content) {
143
+ setOverrideContent(content);
144
+ }
145
+ });
146
+ } // TODO: fetch content and override. Forward all builder.* params
147
+ }
148
+ }
59
149
  }
60
150
  }, []);
61
151
 
@@ -63,7 +153,7 @@ export default function RenderContent(props) {
63
153
  <BuilderContext.Provider
64
154
  value={{
65
155
  get content() {
66
- return props.content;
156
+ return useContent();
67
157
  },
68
158
 
69
159
  get state() {
@@ -75,24 +165,34 @@ export default function RenderContent(props) {
75
165
  },
76
166
  }}
77
167
  >
78
- <View
79
- onClick={(event) => {
80
- track("click", {
81
- contentId: props.content.id,
82
- });
83
- }}
84
- data-builder-content-id={props.content?.id}
85
- >
86
- {useContent?.()?.data?.cssCode && !isReactNative() && (
87
- <View>
88
- <Text>{useContent().data.cssCode}</Text>
89
- </View>
90
- )}
168
+ {useContent() ? (
169
+ <>
170
+ <View
171
+ onClick={event => {
172
+ if (!isEditing()) {
173
+ track('click', {
174
+ contentId: useContent().id,
175
+ });
176
+ }
177
+ }}
178
+ data-builder-content-id={useContent?.()?.id}
179
+ >
180
+ {(useContent?.()?.data?.cssCode ||
181
+ (useContent?.()?.data?.customFonts && useContent?.()?.data?.customFonts.length)) &&
182
+ !isReactNative() ? (
183
+ <View>
184
+ <Text>{useContent().data.cssCode}</Text>
185
+
186
+ <Text>{getFontCss(useContent().data)}</Text>
187
+ </View>
188
+ ) : null}
91
189
 
92
- {useContent?.()?.data?.blocks?.map((block) => (
93
- <RenderBlock key={block.id} block={block} />
94
- ))}
95
- </View>
190
+ {useContent?.()?.data?.blocks?.map(block => (
191
+ <RenderBlock key={block.id} block={block} />
192
+ ))}
193
+ </View>
194
+ </>
195
+ ) : null}
96
196
  </BuilderContext.Provider>
97
197
  );
98
198
  }