@builder.io/sdk-react-native 0.1.2 → 0.1.4

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 (181) hide show
  1. package/dist/blocks/BaseText.js +40 -0
  2. package/dist/blocks/button/button.js +39 -0
  3. package/dist/blocks/button/component-info.js +42 -0
  4. package/dist/blocks/columns/columns.js +149 -0
  5. package/dist/blocks/columns/component-info.js +244 -0
  6. package/dist/blocks/custom-code/component-info.js +32 -0
  7. package/dist/blocks/custom-code/custom-code.js +76 -0
  8. package/dist/blocks/embed/component-info.js +47 -0
  9. package/dist/blocks/embed/embed.js +67 -0
  10. package/dist/blocks/embed/helpers.js +10 -0
  11. package/dist/blocks/form/component-info.js +263 -0
  12. package/dist/blocks/form/form.js +232 -0
  13. package/dist/blocks/fragment/component-info.js +12 -0
  14. package/dist/blocks/fragment/fragment.js +36 -0
  15. package/dist/blocks/image/component-info.js +152 -0
  16. package/dist/blocks/image/image.helpers.js +49 -0
  17. package/dist/blocks/image/image.js +81 -0
  18. package/dist/blocks/img/component-info.js +21 -0
  19. package/dist/blocks/img/img.js +35 -0
  20. package/dist/blocks/input/component-info.js +75 -0
  21. package/dist/blocks/input/input.js +32 -0
  22. package/dist/blocks/raw-text/component-info.js +17 -0
  23. package/dist/blocks/raw-text/raw-text.js +31 -0
  24. package/dist/blocks/section/component-info.js +50 -0
  25. package/dist/blocks/section/section.js +49 -0
  26. package/dist/blocks/select/component-info.js +60 -0
  27. package/dist/blocks/select/select.js +38 -0
  28. package/dist/blocks/submit-button/component-info.js +29 -0
  29. package/dist/blocks/submit-button/submit-button.js +36 -0
  30. package/dist/blocks/symbol/component-info.js +44 -0
  31. package/dist/blocks/symbol/symbol.js +97 -0
  32. package/dist/blocks/text/component-info.js +25 -0
  33. package/dist/blocks/text/text.js +112 -0
  34. package/dist/blocks/textarea/component-info.js +48 -0
  35. package/dist/blocks/textarea/textarea.js +31 -0
  36. package/dist/blocks/util.js +9 -0
  37. package/dist/blocks/video/component-info.js +107 -0
  38. package/dist/blocks/video/video.js +81 -0
  39. package/dist/components/render-block/block-styles.js +79 -0
  40. package/dist/components/render-block/render-block.helpers.js +109 -0
  41. package/dist/components/render-block/render-block.js +154 -0
  42. package/dist/components/render-block/render-component-with-context.js +45 -0
  43. package/dist/components/render-block/render-component.js +50 -0
  44. package/dist/components/render-block/render-repeated-block.js +45 -0
  45. package/dist/components/render-block/types.js +1 -0
  46. package/dist/components/render-blocks.js +76 -0
  47. package/dist/components/render-content/builder-editing.js +31 -0
  48. package/dist/components/render-content/components/render-styles.js +91 -0
  49. package/dist/components/render-content/index.js +8 -0
  50. package/dist/components/render-content/render-content.js +325 -0
  51. package/dist/components/render-inlined-styles.js +42 -0
  52. package/dist/constants/builder-registered-components.js +46 -0
  53. package/dist/constants/device-sizes.js +49 -0
  54. package/dist/constants/target.js +5 -0
  55. package/dist/context/builder.context.js +13 -0
  56. package/dist/context/types.js +1 -0
  57. package/dist/functions/camel-to-kebab-case.js +5 -0
  58. package/dist/functions/evaluate.js +25 -0
  59. package/dist/functions/event-handler-name.js +8 -0
  60. package/dist/functions/extract-text-styles.js +23 -0
  61. package/dist/functions/fast-clone.js +5 -0
  62. package/dist/functions/get-block-actions-handler.js +12 -0
  63. package/dist/functions/get-block-actions.js +19 -0
  64. package/dist/functions/get-block-component-options.js +29 -0
  65. package/dist/functions/get-block-properties.js +51 -0
  66. package/dist/functions/get-block-tag.js +8 -0
  67. package/dist/functions/get-builder-search-params/fn.test.js +15 -0
  68. package/dist/functions/get-builder-search-params/index.js +39 -0
  69. package/dist/functions/get-content/ab-testing.js +89 -0
  70. package/dist/functions/get-content/generate-content-url.js +44 -0
  71. package/dist/functions/get-content/generate-content-url.test.js +33 -0
  72. package/dist/functions/get-content/index.js +68 -0
  73. package/dist/functions/get-content/types.js +1 -0
  74. package/dist/functions/get-fetch.js +15 -0
  75. package/dist/functions/get-global-this.js +19 -0
  76. package/dist/functions/get-processed-block.js +52 -0
  77. package/dist/functions/get-processed-block.test.js +34 -0
  78. package/dist/functions/get-react-native-block-styles.js +30 -0
  79. package/dist/functions/if-target.js +13 -0
  80. package/dist/functions/is-browser.js +7 -0
  81. package/dist/functions/is-editing.js +8 -0
  82. package/dist/functions/is-iframe.js +8 -0
  83. package/dist/functions/is-previewing.js +15 -0
  84. package/dist/functions/on-change.js +28 -0
  85. package/dist/functions/on-change.test.js +21 -0
  86. package/dist/functions/register-component.js +65 -0
  87. package/dist/functions/register.js +31 -0
  88. package/dist/functions/sanitize-react-native-block-styles.js +71 -0
  89. package/dist/functions/set-editor-settings.js +16 -0
  90. package/dist/functions/set.js +12 -0
  91. package/dist/functions/set.test.js +18 -0
  92. package/dist/functions/track/helpers.js +53 -0
  93. package/dist/functions/track/index.js +124 -0
  94. package/dist/functions/track/interaction.js +51 -0
  95. package/dist/functions/track.js +120 -0
  96. package/dist/functions/transform-block-properties.js +18 -0
  97. package/dist/functions/transform-block.js +38 -0
  98. package/dist/helpers/ab-tests.js +10 -0
  99. package/dist/helpers/cookie.js +70 -0
  100. package/dist/helpers/css.js +33 -0
  101. package/dist/helpers/flatten.js +35 -0
  102. package/dist/helpers/localStorage.js +31 -0
  103. package/dist/helpers/nullable.js +5 -0
  104. package/dist/helpers/sessionId.js +51 -0
  105. package/dist/helpers/time.js +6 -0
  106. package/dist/helpers/url.js +14 -0
  107. package/dist/helpers/url.test.js +23 -0
  108. package/dist/helpers/uuid.js +14 -0
  109. package/dist/helpers/visitorId.js +33 -0
  110. package/dist/index-helpers/blocks-exports.js +22 -0
  111. package/dist/index-helpers/top-of-file.js +3 -0
  112. package/dist/index.js +29 -0
  113. package/dist/scripts/init-editing.js +97 -0
  114. package/dist/types/builder-block.js +1 -0
  115. package/dist/types/builder-content.js +1 -0
  116. package/dist/types/can-track.js +1 -0
  117. package/dist/types/components.js +1 -0
  118. package/dist/types/deep-partial.js +1 -0
  119. package/dist/types/element.js +1 -0
  120. package/dist/types/targets.js +1 -0
  121. package/dist/types/typescript.js +1 -0
  122. package/package.json +13 -5
  123. package/src/blocks/BaseText.jsx +17 -0
  124. package/src/blocks/button/button.jsx +28 -0
  125. package/src/blocks/columns/{columns.js → columns.jsx} +61 -38
  126. package/src/blocks/custom-code/{custom-code.js → custom-code.jsx} +22 -15
  127. package/src/blocks/embed/{embed.js → embed.jsx} +12 -11
  128. package/src/blocks/form/form.jsx +251 -0
  129. package/src/blocks/fragment/fragment.jsx +11 -0
  130. package/src/blocks/image/image.jsx +78 -0
  131. package/src/blocks/img/img.jsx +18 -0
  132. package/src/blocks/input/input.jsx +20 -0
  133. package/src/blocks/raw-text/raw-text.jsx +6 -0
  134. package/src/blocks/section/section.jsx +29 -0
  135. package/src/blocks/select/select.jsx +24 -0
  136. package/src/blocks/submit-button/submit-button.jsx +11 -0
  137. package/src/blocks/symbol/symbol.jsx +86 -0
  138. package/src/blocks/text/text.jsx +100 -0
  139. package/src/blocks/textarea/textarea.jsx +14 -0
  140. package/src/blocks/video/video.jsx +70 -0
  141. package/src/components/render-block/block-styles.jsx +70 -0
  142. package/src/components/render-block/render-block.helpers.js +90 -0
  143. package/src/components/render-block/render-block.jsx +183 -0
  144. package/src/components/render-block/render-component.jsx +45 -0
  145. package/src/components/render-block/render-repeated-block.jsx +22 -0
  146. package/src/components/render-blocks.jsx +86 -0
  147. package/src/components/render-content/builder-editing.jsx +6 -0
  148. package/src/components/render-content/components/{render-styles.js → render-styles.jsx} +22 -15
  149. package/src/components/render-content/index.js +1 -1
  150. package/src/components/render-content/render-content.jsx +373 -0
  151. package/src/components/render-inlined-styles.jsx +29 -0
  152. package/src/constants/builder-registered-components.js +7 -7
  153. package/src/functions/track/helpers.js +50 -0
  154. package/src/functions/{track.js → track/index.js} +10 -6
  155. package/src/functions/track/interaction.js +53 -0
  156. package/src/index-helpers/blocks-exports.js +8 -8
  157. package/src/index.js +1 -1
  158. package/src/blocks/BaseText.js +0 -31
  159. package/src/blocks/button/button.js +0 -36
  160. package/src/blocks/form/form.js +0 -222
  161. package/src/blocks/fragment/fragment.js +0 -9
  162. package/src/blocks/image/image.js +0 -55
  163. package/src/blocks/img/img.js +0 -33
  164. package/src/blocks/input/input.js +0 -36
  165. package/src/blocks/raw-text/raw-text.js +0 -10
  166. package/src/blocks/section/section.js +0 -41
  167. package/src/blocks/select/select.js +0 -37
  168. package/src/blocks/submit-button/submit-button.js +0 -27
  169. package/src/blocks/symbol/symbol.js +0 -73
  170. package/src/blocks/text/text.js +0 -67
  171. package/src/blocks/textarea/textarea.js +0 -32
  172. package/src/blocks/video/video.js +0 -55
  173. package/src/components/render-block/block-styles.js +0 -50
  174. package/src/components/render-block/render-block.js +0 -202
  175. package/src/components/render-block/render-component-with-context.js +0 -35
  176. package/src/components/render-block/render-component.js +0 -35
  177. package/src/components/render-block/render-repeated-block.js +0 -33
  178. package/src/components/render-blocks.js +0 -63
  179. package/src/components/render-content/builder-editing.js +0 -8
  180. package/src/components/render-content/render-content.js +0 -297
  181. package/src/components/render-inlined-styles.js +0 -17
@@ -0,0 +1,91 @@
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 render_inlined_styles_1 = __importDefault(require("../../render-inlined-styles"));
32
+ function RenderContentStyles(props) {
33
+ function getCssFromFont(font) {
34
+ var _a, _b;
35
+ // TODO: compute what font sizes are used and only load those.......
36
+ const family = font.family +
37
+ (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
38
+ const name = family.split(",")[0];
39
+ const url = (_a = font.fileUrl) !== null && _a !== void 0 ? _a : (_b = font === null || font === void 0 ? void 0 : font.files) === null || _b === void 0 ? void 0 : _b.regular;
40
+ let str = "";
41
+ if (url && family && name) {
42
+ str += `
43
+ @font-face {
44
+ font-family: "${family}";
45
+ src: local("${name}"), url('${url}') format('woff2');
46
+ font-display: fallback;
47
+ font-weight: 400;
48
+ }
49
+ `.trim();
50
+ }
51
+ if (font.files) {
52
+ for (const weight in font.files) {
53
+ const isNumber = String(Number(weight)) === weight;
54
+ if (!isNumber) {
55
+ continue;
56
+ }
57
+ // TODO: maybe limit number loaded
58
+ const weightUrl = font.files[weight];
59
+ if (weightUrl && weightUrl !== url) {
60
+ str += `
61
+ @font-face {
62
+ font-family: "${family}";
63
+ src: url('${weightUrl}') format('woff2');
64
+ font-display: fallback;
65
+ font-weight: ${weight};
66
+ }
67
+ `.trim();
68
+ }
69
+ }
70
+ }
71
+ return str;
72
+ }
73
+ function getFontCss({ customFonts }) {
74
+ var _a;
75
+ // TODO: flag for this
76
+ // if (!builder.allowCustomFonts) {
77
+ // return '';
78
+ // }
79
+ // TODO: separate internal data from external
80
+ return ((_a = customFonts === null || customFonts === void 0 ? void 0 : customFonts.map((font) => getCssFromFont(font))) === null || _a === void 0 ? void 0 : _a.join(" ")) || "";
81
+ }
82
+ function injectedStyles() {
83
+ return `
84
+ ${props.cssCode || ""}
85
+ ${getFontCss({
86
+ customFonts: props.customFonts,
87
+ })}`;
88
+ }
89
+ return React.createElement(render_inlined_styles_1.default, { styles: injectedStyles() });
90
+ }
91
+ exports.default = RenderContentStyles;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = void 0;
7
+ const render_content_1 = __importDefault(require("./render-content"));
8
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return render_content_1.default; } });
@@ -0,0 +1,325 @@
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_registered_components_js_1 = require("../../constants/builder-registered-components.js");
33
+ const target_js_1 = require("../../constants/target.js");
34
+ const evaluate_js_1 = require("../../functions/evaluate.js");
35
+ const index_js_1 = require("../../functions/get-content/index.js");
36
+ const get_fetch_js_1 = require("../../functions/get-fetch.js");
37
+ const is_browser_js_1 = require("../../functions/is-browser.js");
38
+ const is_editing_js_1 = require("../../functions/is-editing.js");
39
+ const is_previewing_js_1 = require("../../functions/is-previewing.js");
40
+ const register_component_js_1 = require("../../functions/register-component.js");
41
+ const index_js_2 = require("../../functions/track/index.js");
42
+ const render_blocks_1 = __importDefault(require("../render-blocks"));
43
+ const render_styles_1 = __importDefault(require("./components/render-styles"));
44
+ const builder_context_js_1 = __importDefault(require("../../context/builder.context.js"));
45
+ const init_editing_js_1 = require("../../scripts/init-editing.js");
46
+ const nullable_js_1 = require("../../helpers/nullable.js");
47
+ const interaction_js_1 = require("../../functions/track/interaction.js");
48
+ function RenderContent(props) {
49
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
50
+ const elementRef = (0, react_1.useRef)(null);
51
+ const [forceReRenderCount, setForceReRenderCount] = (0, react_1.useState)(() => 0);
52
+ const [overrideContent, setOverrideContent] = (0, react_1.useState)(() => null);
53
+ function useContent() {
54
+ var _a, _b, _c, _d, _e;
55
+ if (!props.content && !overrideContent) {
56
+ return undefined;
57
+ }
58
+ return {
59
+ ...props.content,
60
+ ...overrideContent,
61
+ data: {
62
+ ...(_a = props.content) === null || _a === void 0 ? void 0 : _a.data,
63
+ ...props.data,
64
+ ...overrideContent === null || overrideContent === void 0 ? void 0 : overrideContent.data,
65
+ },
66
+ meta: {
67
+ ...(_b = props.content) === null || _b === void 0 ? void 0 : _b.meta,
68
+ ...overrideContent === null || overrideContent === void 0 ? void 0 : overrideContent.meta,
69
+ breakpoints: useBreakpoints ||
70
+ ((_c = overrideContent === null || overrideContent === void 0 ? void 0 : overrideContent.meta) === null || _c === void 0 ? void 0 : _c.breakpoints) ||
71
+ ((_e = (_d = props.content) === null || _d === void 0 ? void 0 : _d.meta) === null || _e === void 0 ? void 0 : _e.breakpoints),
72
+ },
73
+ };
74
+ }
75
+ const [update, setUpdate] = (0, react_1.useState)(() => 0);
76
+ const [useBreakpoints, setUseBreakpoints] = (0, react_1.useState)(() => null);
77
+ const [canTrackToUse, setCanTrackToUse] = (0, react_1.useState)(() => (0, nullable_js_1.checkIsDefined)(props.canTrack) ? props.canTrack : true);
78
+ const [overrideState, setOverrideState] = (0, react_1.useState)(() => ({}));
79
+ function contentState() {
80
+ var _a, _b;
81
+ return {
82
+ ...(_b = (_a = props.content) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.state,
83
+ ...props.data,
84
+ ...(props.locale
85
+ ? {
86
+ locale: props.locale,
87
+ }
88
+ : {}),
89
+ ...overrideState,
90
+ };
91
+ }
92
+ const [contextContext, setContextContext] = (0, react_1.useState)(() => props.context || {});
93
+ const [allRegisteredComponents, setAllRegisteredComponents] = (0, react_1.useState)(() => [
94
+ ...(0, builder_registered_components_js_1.getDefaultRegisteredComponents)(),
95
+ // While this `components` object is deprecated, we must maintain support for it.
96
+ // Since users are able to override our default components, we need to make sure that we do not break such
97
+ // existing usage.
98
+ // This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
99
+ // which is the new standard way of providing custom components, and must therefore take precedence.
100
+ ...register_component_js_1.components,
101
+ ...(props.customComponents || []),
102
+ ].reduce((acc, curr) => ({
103
+ ...acc,
104
+ [curr.name]: curr,
105
+ }), {}));
106
+ function processMessage(event) {
107
+ var _a;
108
+ const { data } = event;
109
+ if (data) {
110
+ switch (data.type) {
111
+ case "builder.configureSdk": {
112
+ const messageContent = data.data;
113
+ const { breakpoints, contentId } = messageContent;
114
+ if (!contentId || contentId !== ((_a = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _a === void 0 ? void 0 : _a.id)) {
115
+ return;
116
+ }
117
+ setUseBreakpoints(breakpoints);
118
+ setForceReRenderCount(forceReRenderCount + 1); // This is a hack to force Qwik to re-render.
119
+ break;
120
+ }
121
+ case "builder.contentUpdate": {
122
+ const messageContent = data.data;
123
+ const key = messageContent.key ||
124
+ messageContent.alias ||
125
+ messageContent.entry ||
126
+ messageContent.modelName;
127
+ const contentData = messageContent.data;
128
+ if (key === props.model) {
129
+ setOverrideContent(contentData);
130
+ setForceReRenderCount(forceReRenderCount + 1); // This is a hack to force Qwik to re-render.
131
+ }
132
+ break;
133
+ }
134
+ case "builder.patchUpdates": {
135
+ // TODO
136
+ break;
137
+ }
138
+ }
139
+ }
140
+ }
141
+ function evaluateJsCode() {
142
+ var _a, _b;
143
+ // run any dynamic JS code attached to content
144
+ const jsCode = (_b = (_a = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.jsCode;
145
+ if (jsCode) {
146
+ (0, evaluate_js_1.evaluate)({
147
+ code: jsCode,
148
+ context: contextContext,
149
+ state: contentState(),
150
+ });
151
+ }
152
+ }
153
+ const [httpReqsData, setHttpReqsData] = (0, react_1.useState)(() => ({}));
154
+ const [clicked, setClicked] = (0, react_1.useState)(() => false);
155
+ function onClick(event) {
156
+ var _a, _b;
157
+ if (useContent()) {
158
+ const variationId = (_a = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _a === void 0 ? void 0 : _a.testVariationId;
159
+ const contentId = (_b = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _b === void 0 ? void 0 : _b.id;
160
+ (0, index_js_2._track)({
161
+ type: "click",
162
+ canTrack: canTrackToUse,
163
+ contentId,
164
+ apiKey: props.apiKey,
165
+ variationId: variationId !== contentId ? variationId : undefined,
166
+ ...(0, interaction_js_1.getInteractionPropertiesForEvent)(event),
167
+ unique: !clicked,
168
+ });
169
+ }
170
+ if (!clicked) {
171
+ setClicked(true);
172
+ }
173
+ }
174
+ function evalExpression(expression) {
175
+ return expression.replace(/{{([^}]+)}}/g, (_match, group) => (0, evaluate_js_1.evaluate)({
176
+ code: group,
177
+ context: contextContext,
178
+ state: contentState(),
179
+ }));
180
+ }
181
+ function handleRequest({ url, key }) {
182
+ (0, get_fetch_js_1.fetch)(url)
183
+ .then((response) => response.json())
184
+ .then((json) => {
185
+ const newOverrideState = {
186
+ ...overrideState,
187
+ [key]: json,
188
+ };
189
+ setOverrideState(newOverrideState);
190
+ })
191
+ .catch((err) => {
192
+ console.log("error fetching dynamic data", url, err);
193
+ });
194
+ }
195
+ function runHttpRequests() {
196
+ var _a, _b, _c;
197
+ const requests = (_c = (_b = (_a = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.httpRequests) !== null && _c !== void 0 ? _c : {};
198
+ Object.entries(requests).forEach(([key, url]) => {
199
+ if (url && (!httpReqsData[key] || (0, is_editing_js_1.isEditing)())) {
200
+ const evaluatedUrl = evalExpression(url);
201
+ handleRequest({
202
+ url: evaluatedUrl,
203
+ key,
204
+ });
205
+ }
206
+ });
207
+ }
208
+ function emitStateUpdate() {
209
+ if ((0, is_editing_js_1.isEditing)()) {
210
+ window.dispatchEvent(new CustomEvent("builder:component:stateChange", {
211
+ detail: {
212
+ state: contentState(),
213
+ ref: {
214
+ name: props.model,
215
+ },
216
+ },
217
+ }));
218
+ }
219
+ }
220
+ function shouldRenderContentStyles() {
221
+ var _a, _b, _c, _d, _e;
222
+ return Boolean((((_b = (_a = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.cssCode) ||
223
+ ((_e = (_d = (_c = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.customFonts) === null || _e === void 0 ? void 0 : _e.length)) &&
224
+ target_js_1.TARGET !== "reactNative");
225
+ }
226
+ (0, react_1.useEffect)(() => {
227
+ var _a, _b;
228
+ if (!props.apiKey) {
229
+ console.error("[Builder.io]: No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
230
+ }
231
+ if ((0, is_browser_js_1.isBrowser)()) {
232
+ if ((0, is_editing_js_1.isEditing)()) {
233
+ setForceReRenderCount(forceReRenderCount + 1);
234
+ (0, init_editing_js_1.registerInsertMenu)();
235
+ (0, init_editing_js_1.setupBrowserForEditing)({
236
+ ...(props.locale
237
+ ? {
238
+ locale: props.locale,
239
+ }
240
+ : {}),
241
+ ...(props.includeRefs
242
+ ? {
243
+ includeRefs: props.includeRefs,
244
+ }
245
+ : {}),
246
+ });
247
+ Object.values(allRegisteredComponents).forEach((registeredComponent) => {
248
+ var _a;
249
+ const message = (0, register_component_js_1.createRegisterComponentMessage)(registeredComponent);
250
+ (_a = window.parent) === null || _a === void 0 ? void 0 : _a.postMessage(message, "*");
251
+ });
252
+ window.addEventListener("message", processMessage);
253
+ window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
254
+ }
255
+ if (useContent()) {
256
+ const variationId = (_a = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _a === void 0 ? void 0 : _a.testVariationId;
257
+ const contentId = (_b = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _b === void 0 ? void 0 : _b.id;
258
+ (0, index_js_2._track)({
259
+ type: "impression",
260
+ canTrack: canTrackToUse,
261
+ contentId,
262
+ apiKey: props.apiKey,
263
+ variationId: variationId !== contentId ? variationId : undefined,
264
+ });
265
+ }
266
+ // override normal content in preview mode
267
+ if ((0, is_previewing_js_1.isPreviewing)()) {
268
+ const searchParams = new URL(location.href).searchParams;
269
+ const searchParamPreview = searchParams.get("builder.preview");
270
+ const previewApiKey = searchParams.get("apiKey") || searchParams.get("builder.space");
271
+ /**
272
+ * Make sure that:
273
+ * - the preview model name is the same as the one we're rendering, since there can be multiple models rendered * at the same time, e.g. header/page/footer. * - the API key is the same, since we don't want to preview content from other organizations.
274
+ *
275
+ * TO-DO: should we check that the preview item ID is the same as the initial one being rendered? Or would
276
+ * this break scenarios where the item is not published yet?
277
+ *
278
+ * TO-DO: should we only update the state when there is a change?
279
+ **/
280
+ if (searchParamPreview === props.model &&
281
+ previewApiKey === props.apiKey) {
282
+ (0, index_js_1.getContent)({
283
+ model: props.model,
284
+ apiKey: props.apiKey,
285
+ }).then((content) => {
286
+ if (content) {
287
+ setOverrideContent(content);
288
+ }
289
+ });
290
+ }
291
+ }
292
+ evaluateJsCode();
293
+ runHttpRequests();
294
+ emitStateUpdate();
295
+ }
296
+ }, []);
297
+ (0, react_1.useEffect)(() => {
298
+ evaluateJsCode();
299
+ }, [(_b = (_a = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.jsCode, contentState()]);
300
+ (0, react_1.useEffect)(() => {
301
+ runHttpRequests();
302
+ }, [(_d = (_c = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.httpRequests]);
303
+ (0, react_1.useEffect)(() => {
304
+ emitStateUpdate();
305
+ }, [contentState()]);
306
+ (0, react_1.useEffect)(() => {
307
+ return () => {
308
+ if ((0, is_browser_js_1.isBrowser)()) {
309
+ window.removeEventListener("message", processMessage);
310
+ window.removeEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
311
+ }
312
+ };
313
+ }, []);
314
+ return (React.createElement(builder_context_js_1.default.Provider, { value: {
315
+ content: useContent(),
316
+ state: contentState(),
317
+ context: contextContext,
318
+ apiKey: props.apiKey,
319
+ registeredComponents: allRegisteredComponents,
320
+ } }, useContent() ? (React.createElement(React.Fragment, null,
321
+ React.createElement(react_native_1.View, { ref: elementRef, onClick: (event) => onClick(event), "builder-content-id": (_e = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _e === void 0 ? void 0 : _e.id, "builder-model": props.model },
322
+ shouldRenderContentStyles() ? (React.createElement(render_styles_1.default, { cssCode: (_g = (_f = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.cssCode, customFonts: (_j = (_h = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _h === void 0 ? void 0 : _h.data) === null || _j === void 0 ? void 0 : _j.customFonts })) : null,
323
+ React.createElement(render_blocks_1.default, { blocks: (_l = (_k = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _k === void 0 ? void 0 : _k.data) === null || _l === void 0 ? void 0 : _l.blocks, key: forceReRenderCount })))) : null));
324
+ }
325
+ exports.default = RenderContent;
@@ -0,0 +1,42 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const React = __importStar(require("react"));
27
+ const react_native_1 = require("react-native");
28
+ const target_js_1 = require("../constants/target.js");
29
+ function RenderInlinedStyles(props) {
30
+ function injectedStyleScript() {
31
+ return `<${tag()}>${props.styles}</${tag()}>`;
32
+ }
33
+ function tag() {
34
+ // NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
35
+ // https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
36
+ return "sty" + "le";
37
+ }
38
+ return (React.createElement(React.Fragment, null, target_js_1.TARGET === "svelte" || target_js_1.TARGET === "qwik" ? (React.createElement(React.Fragment, null,
39
+ React.createElement(react_native_1.View, { dangerouslySetInnerHTML: { __html: props.styles } }))) : (React.createElement(react_native_1.View, null,
40
+ React.createElement(react_native_1.Text, null, props.styles)))));
41
+ }
42
+ exports.default = RenderInlinedStyles;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getDefaultRegisteredComponents = void 0;
7
+ var __defProp = Object.defineProperty;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ const button_1 = __importDefault(require("../blocks/button/button"));
24
+ const component_info_1 = require("../blocks/button/component-info");
25
+ const columns_1 = __importDefault(require("../blocks/columns/columns"));
26
+ const component_info_2 = require("../blocks/columns/component-info");
27
+ const component_info_3 = require("../blocks/fragment/component-info");
28
+ const fragment_1 = __importDefault(require("../blocks/fragment/fragment"));
29
+ const component_info_4 = require("../blocks/image/component-info");
30
+ const image_1 = __importDefault(require("../blocks/image/image"));
31
+ const component_info_5 = require("../blocks/section/component-info");
32
+ const section_1 = __importDefault(require("../blocks/section/section"));
33
+ const component_info_6 = require("../blocks/symbol/component-info");
34
+ const symbol_1 = __importDefault(require("../blocks/symbol/symbol"));
35
+ const component_info_7 = require("../blocks/text/component-info");
36
+ const text_1 = __importDefault(require("../blocks/text/text"));
37
+ const getDefaultRegisteredComponents = () => [
38
+ __spreadValues({ component: columns_1.default }, component_info_2.componentInfo),
39
+ __spreadValues({ component: image_1.default }, component_info_4.componentInfo),
40
+ __spreadValues({ component: text_1.default }, component_info_7.componentInfo),
41
+ __spreadValues({ component: symbol_1.default }, component_info_6.componentInfo),
42
+ __spreadValues({ component: button_1.default }, component_info_1.componentInfo),
43
+ __spreadValues({ component: section_1.default }, component_info_5.componentInfo),
44
+ __spreadValues({ component: fragment_1.default }, component_info_3.componentInfo)
45
+ ];
46
+ exports.getDefaultRegisteredComponents = getDefaultRegisteredComponents;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSizesForBreakpoints = exports.getMaxWidthQueryForSize = void 0;
4
+ const fast_clone_1 = require("../functions/fast-clone");
5
+ const SIZES = {
6
+ small: {
7
+ min: 320,
8
+ default: 321,
9
+ max: 640
10
+ },
11
+ medium: {
12
+ min: 641,
13
+ default: 642,
14
+ max: 991
15
+ },
16
+ large: {
17
+ min: 990,
18
+ default: 991,
19
+ max: 1200
20
+ }
21
+ };
22
+ const getMaxWidthQueryForSize = (size, sizeValues = SIZES) => `@media (max-width: ${sizeValues[size].max}px)`;
23
+ exports.getMaxWidthQueryForSize = getMaxWidthQueryForSize;
24
+ const getSizesForBreakpoints = ({ small, medium }) => {
25
+ const newSizes = (0, fast_clone_1.fastClone)(SIZES);
26
+ if (!small || !medium) {
27
+ return newSizes;
28
+ }
29
+ const smallMin = Math.floor(small / 2);
30
+ newSizes.small = {
31
+ max: small,
32
+ min: smallMin,
33
+ default: smallMin + 1
34
+ };
35
+ const mediumMin = newSizes.small.max + 1;
36
+ newSizes.medium = {
37
+ max: medium,
38
+ min: mediumMin,
39
+ default: mediumMin + 1
40
+ };
41
+ const largeMin = newSizes.medium.max + 1;
42
+ newSizes.large = {
43
+ max: 2e3,
44
+ min: largeMin,
45
+ default: largeMin + 1
46
+ };
47
+ return newSizes;
48
+ };
49
+ exports.getSizesForBreakpoints = getSizesForBreakpoints;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TARGET = void 0;
4
+ const TARGET = "reactNative";
5
+ exports.TARGET = TARGET;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = void 0;
4
+ const react_1 = require("react");
5
+ var stdin_default = (0, react_1.createContext)({
6
+ content: null,
7
+ context: {},
8
+ state: {},
9
+ apiKey: null,
10
+ registeredComponents: {},
11
+ inheritedStyles: {}
12
+ });
13
+ exports.default = stdin_default;
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.camelToKebabCase = void 0;
4
+ const camelToKebabCase = (string) => string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
5
+ exports.camelToKebabCase = camelToKebabCase;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.evaluate = void 0;
4
+ const is_browser_js_1 = require("./is-browser.js");
5
+ const is_editing_js_1 = require("./is-editing.js");
6
+ function evaluate({ code, context, state, event, isExpression = true }) {
7
+ if (code === "") {
8
+ console.warn("Skipping evaluation of empty code block.");
9
+ return;
10
+ }
11
+ const builder = {
12
+ isEditing: (0, is_editing_js_1.isEditing)(),
13
+ isBrowser: (0, is_browser_js_1.isBrowser)(),
14
+ isServer: !(0, is_browser_js_1.isBrowser)()
15
+ };
16
+ const useReturn = isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
17
+ const useCode = useReturn ? `return (${code});` : code;
18
+ try {
19
+ return new Function("builder", "Builder", "state", "context", "event", useCode)(builder, builder, state, context, event);
20
+ }
21
+ catch (e) {
22
+ console.warn("Builder custom code error: \n While Evaluating: \n ", useCode, "\n", e);
23
+ }
24
+ }
25
+ exports.evaluate = evaluate;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEventHandlerName = void 0;
4
+ function capitalizeFirstLetter(string) {
5
+ return string.charAt(0).toUpperCase() + string.slice(1);
6
+ }
7
+ const getEventHandlerName = (key) => `on${capitalizeFirstLetter(key)}`;
8
+ exports.getEventHandlerName = getEventHandlerName;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractTextStyles = void 0;
4
+ const TEXT_STYLE_KEYS = [
5
+ "color",
6
+ "whiteSpace",
7
+ "direction",
8
+ "hyphens",
9
+ "overflowWrap"
10
+ ];
11
+ const isTextStyle = (key) => {
12
+ return TEXT_STYLE_KEYS.includes(key) || key.startsWith("font") || key.startsWith("text") || key.startsWith("letter") || key.startsWith("line") || key.startsWith("word") || key.startsWith("writing");
13
+ };
14
+ const extractTextStyles = (styles) => {
15
+ const textStyles = {};
16
+ Object.entries(styles).forEach(([key, value]) => {
17
+ if (isTextStyle(key)) {
18
+ textStyles[key] = value;
19
+ }
20
+ });
21
+ return textStyles;
22
+ };
23
+ exports.extractTextStyles = extractTextStyles;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fastClone = void 0;
4
+ const fastClone = (obj) => JSON.parse(JSON.stringify(obj));
5
+ exports.fastClone = fastClone;