@builder.io/sdk-react-native 0.0.1-6 → 0.0.1-60

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 (131) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +19 -0
  3. package/package.json +6 -4
  4. package/src/blocks/button/button.js +31 -0
  5. package/src/blocks/button/component-info.js +42 -0
  6. package/src/blocks/columns/columns.js +59 -0
  7. package/src/blocks/columns/component-info.js +218 -0
  8. package/src/blocks/custom-code/component-info.js +32 -0
  9. package/src/blocks/{custom-code.lite.tsx → custom-code/custom-code.js} +16 -33
  10. package/src/blocks/embed/component-info.js +25 -0
  11. package/src/blocks/{embed.lite.tsx → embed/embed.js} +16 -31
  12. package/src/blocks/form/component-info.js +263 -0
  13. package/src/blocks/form/form.js +221 -0
  14. package/src/blocks/fragment/component-info.js +12 -0
  15. package/src/blocks/fragment/fragment.js +8 -0
  16. package/src/blocks/{image.js → image/component-info.js} +5 -23
  17. package/src/blocks/image/image.js +41 -0
  18. package/src/blocks/img/component-info.js +21 -0
  19. package/src/blocks/img/img.js +36 -0
  20. package/src/blocks/input/component-info.js +75 -0
  21. package/src/blocks/input/input.js +36 -0
  22. package/src/blocks/raw-text/component-info.js +17 -0
  23. package/src/blocks/raw-text/raw-text.js +10 -0
  24. package/src/blocks/section/component-info.js +50 -0
  25. package/src/blocks/section/section.js +31 -0
  26. package/src/blocks/select/component-info.js +60 -0
  27. package/src/blocks/select/select.js +36 -0
  28. package/src/blocks/submit-button/component-info.js +29 -0
  29. package/src/blocks/submit-button/submit-button.js +29 -0
  30. package/src/blocks/symbol/component-info.js +44 -0
  31. package/src/blocks/symbol/symbol.js +68 -0
  32. package/src/blocks/{text.js → text/component-info.js} +4 -10
  33. package/src/blocks/text/text.js +65 -0
  34. package/src/blocks/textarea/component-info.js +48 -0
  35. package/src/blocks/textarea/textarea.js +32 -0
  36. package/src/blocks/video/component-info.js +107 -0
  37. package/src/blocks/video/video.js +33 -0
  38. package/src/components/render-block/block-styles.js +40 -0
  39. package/src/components/render-block/render-block.helpers.js +24 -0
  40. package/src/components/render-block/render-block.js +171 -0
  41. package/src/components/render-block/render-component.js +33 -0
  42. package/src/components/render-block/render-repeated-block.js +29 -0
  43. package/src/components/render-blocks.js +23 -12
  44. package/src/components/render-content/components/render-styles.js +58 -0
  45. package/src/components/render-content/index.js +5 -0
  46. package/src/components/render-content/render-content.js +254 -0
  47. package/src/components/render-inlined-styles.js +18 -0
  48. package/src/constants/builder-registered-components.js +43 -0
  49. package/src/constants/device-sizes.js +3 -21
  50. package/src/constants/target.js +5 -0
  51. package/src/context/builder.context.js +7 -1
  52. package/src/functions/camel-to-kebab-case.js +5 -0
  53. package/src/functions/convert-style-object.js +7 -0
  54. package/src/functions/evaluate.js +17 -8
  55. package/src/functions/event-handler-name.js +8 -0
  56. package/src/functions/fast-clone.js +5 -0
  57. package/src/functions/get-block-actions.js +14 -13
  58. package/src/functions/get-block-component-options.js +22 -1
  59. package/src/functions/get-block-properties.js +2 -3
  60. package/src/functions/get-block-styles.js +9 -19
  61. package/src/functions/get-builder-search-params/fn.test.js +14 -0
  62. package/src/functions/get-builder-search-params/index.js +23 -0
  63. package/src/functions/get-content/fn.test.js +32 -0
  64. package/src/functions/get-content/index.js +139 -0
  65. package/src/functions/get-fetch.js +35 -0
  66. package/src/functions/get-global-this.js +19 -0
  67. package/src/functions/get-processed-block.js +18 -9
  68. package/src/functions/get-processed-block.test.js +14 -8
  69. package/src/functions/if-target.js +11 -2
  70. package/src/functions/is-browser.js +1 -2
  71. package/src/functions/is-editing.js +1 -1
  72. package/src/functions/is-iframe.js +1 -1
  73. package/src/functions/is-previewing.js +15 -0
  74. package/src/functions/is-react-native.js +1 -1
  75. package/src/functions/on-change.test.js +1 -2
  76. package/src/functions/previewing-model-name.js +12 -0
  77. package/src/functions/register-component.js +31 -13
  78. package/src/functions/register.js +30 -0
  79. package/src/functions/sanitize-styles.js +33 -0
  80. package/src/functions/set-editor-settings.js +16 -0
  81. package/src/functions/set.test.js +1 -2
  82. package/src/functions/track.js +7 -3
  83. package/src/functions/transform-block.js +38 -0
  84. package/src/helpers/css.js +13 -0
  85. package/src/index-helpers/blocks-exports.js +19 -0
  86. package/src/index-helpers/top-of-file.js +2 -0
  87. package/src/index.js +10 -23
  88. package/src/scripts/init-editing.js +73 -49
  89. package/src/types/components.js +1 -0
  90. package/src/types/deep-partial.js +1 -0
  91. package/src/types/element.js +1 -0
  92. package/src/types/targets.js +1 -0
  93. package/src/types/typescript.js +1 -0
  94. package/index.js +0 -11
  95. package/src/blocks/button.js +0 -37
  96. package/src/blocks/button.lite.tsx +0 -29
  97. package/src/blocks/columns.js +0 -42
  98. package/src/blocks/columns.lite.tsx +0 -41
  99. package/src/blocks/custom-code.js +0 -56
  100. package/src/blocks/embed.js +0 -56
  101. package/src/blocks/form.js +0 -229
  102. package/src/blocks/form.lite.tsx +0 -257
  103. package/src/blocks/image.lite.tsx +0 -35
  104. package/src/blocks/img.js +0 -41
  105. package/src/blocks/img.lite.tsx +0 -19
  106. package/src/blocks/input.js +0 -41
  107. package/src/blocks/input.lite.tsx +0 -23
  108. package/src/blocks/raw-text.js +0 -17
  109. package/src/blocks/raw-text.lite.tsx +0 -12
  110. package/src/blocks/section.js +0 -36
  111. package/src/blocks/section.lite.tsx +0 -20
  112. package/src/blocks/select.js +0 -40
  113. package/src/blocks/select.lite.tsx +0 -24
  114. package/src/blocks/submit-button.js +0 -34
  115. package/src/blocks/submit-button.lite.tsx +0 -11
  116. package/src/blocks/symbol.js +0 -20
  117. package/src/blocks/symbol.lite.tsx +0 -20
  118. package/src/blocks/text.lite.tsx +0 -12
  119. package/src/blocks/textarea.js +0 -37
  120. package/src/blocks/textarea.lite.tsx +0 -15
  121. package/src/blocks/video.js +0 -49
  122. package/src/blocks/video.lite.tsx +0 -28
  123. package/src/components/render-block.js +0 -84
  124. package/src/components/render-block.lite.tsx +0 -92
  125. package/src/components/render-blocks.lite.tsx +0 -56
  126. package/src/components/render-content.js +0 -66
  127. package/src/components/render-content.lite.tsx +0 -95
  128. package/src/functions/get-content.js +0 -103
  129. package/src/functions/get-target.js +0 -7
  130. package/src/functions/macro-eval.js +0 -6
  131. package/src/package.json +0 -18
@@ -0,0 +1,254 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __async = (__this, __arguments, generator) => {
21
+ return new Promise((resolve, reject) => {
22
+ var fulfilled = (value) => {
23
+ try {
24
+ step(generator.next(value));
25
+ } catch (e) {
26
+ reject(e);
27
+ }
28
+ };
29
+ var rejected = (value) => {
30
+ try {
31
+ step(generator.throw(value));
32
+ } catch (e) {
33
+ reject(e);
34
+ }
35
+ };
36
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
+ step((generator = generator.apply(__this, __arguments)).next());
38
+ });
39
+ };
40
+ import * as React from "react";
41
+ import { View } from "react-native";
42
+ import { useState, useEffect } from "react";
43
+ import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
44
+ import { TARGET } from "../../constants/target.js";
45
+ import BuilderContext from "../../context/builder.context";
46
+ import { evaluate } from "../../functions/evaluate.js";
47
+ import {
48
+ convertSearchParamsToQueryObject,
49
+ getBuilderSearchParams
50
+ } from "../../functions/get-builder-search-params/index.js";
51
+ import { getContent } from "../../functions/get-content/index.js";
52
+ import { getFetch } from "../../functions/get-fetch.js";
53
+ import { isBrowser } from "../../functions/is-browser.js";
54
+ import { isEditing } from "../../functions/is-editing.js";
55
+ import { isPreviewing } from "../../functions/is-previewing.js";
56
+ import { previewingModelName } from "../../functions/previewing-model-name.js";
57
+ import {
58
+ components,
59
+ createRegisterComponentMessage
60
+ } from "../../functions/register-component.js";
61
+ import { track } from "../../functions/track.js";
62
+ import RenderBlocks from "../render-blocks.js";
63
+ import RenderContentStyles from "./components/render-styles.js";
64
+ function RenderContent(props) {
65
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
66
+ function useContent() {
67
+ var _a2;
68
+ const mergedContent = __spreadProps(__spreadValues(__spreadValues({}, props.content), overrideContent), {
69
+ data: __spreadValues(__spreadValues(__spreadValues({}, (_a2 = props.content) == null ? void 0 : _a2.data), props.data), overrideContent == null ? void 0 : overrideContent.data)
70
+ });
71
+ return mergedContent;
72
+ }
73
+ const [overrideContent, setOverrideContent] = useState(() => null);
74
+ const [update, setUpdate] = useState(() => 0);
75
+ const [overrideState, setOverrideState] = useState(() => ({}));
76
+ function contentState() {
77
+ var _a2, _b2;
78
+ return __spreadValues(__spreadValues(__spreadValues({}, (_b2 = (_a2 = props.content) == null ? void 0 : _a2.data) == null ? void 0 : _b2.state), props.data), overrideState);
79
+ }
80
+ function contextContext() {
81
+ return props.context || {};
82
+ }
83
+ function allRegisteredComponents() {
84
+ const allComponentsArray = [
85
+ ...getDefaultRegisteredComponents(),
86
+ ...components,
87
+ ...props.customComponents || []
88
+ ];
89
+ const allComponents = allComponentsArray.reduce((acc, curr) => __spreadProps(__spreadValues({}, acc), { [curr.name]: curr }), {});
90
+ return allComponents;
91
+ }
92
+ function processMessage(event) {
93
+ const { data } = event;
94
+ if (data) {
95
+ switch (data.type) {
96
+ case "builder.contentUpdate": {
97
+ const messageContent = data.data;
98
+ const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
99
+ const contentData = messageContent.data;
100
+ if (key === props.model) {
101
+ setOverrideContent(contentData);
102
+ }
103
+ break;
104
+ }
105
+ case "builder.patchUpdates": {
106
+ break;
107
+ }
108
+ }
109
+ }
110
+ }
111
+ function evaluateJsCode() {
112
+ var _a2, _b2;
113
+ const jsCode = (_b2 = (_a2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _a2.data) == null ? void 0 : _b2.jsCode;
114
+ if (jsCode) {
115
+ evaluate({
116
+ code: jsCode,
117
+ context: contextContext(),
118
+ state: contentState()
119
+ });
120
+ }
121
+ }
122
+ function httpReqsData() {
123
+ return {};
124
+ }
125
+ function evalExpression(expression) {
126
+ return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
127
+ code: group,
128
+ context: contextContext(),
129
+ state: contentState()
130
+ }));
131
+ }
132
+ function handleRequest({ url, key }) {
133
+ const fetchAndSetState = () => __async(this, null, function* () {
134
+ const fetch = yield getFetch();
135
+ const response = yield fetch(url);
136
+ const json = yield response.json();
137
+ const newOverrideState = __spreadProps(__spreadValues({}, overrideState), { [key]: json });
138
+ setOverrideState(newOverrideState);
139
+ });
140
+ fetchAndSetState();
141
+ }
142
+ function runHttpRequests() {
143
+ var _a2, _b2, _c2;
144
+ const requests = (_c2 = (_b2 = (_a2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _a2.data) == null ? void 0 : _b2.httpRequests) != null ? _c2 : {};
145
+ Object.entries(requests).forEach(([key, url]) => {
146
+ if (url && (!httpReqsData()[key] || isEditing())) {
147
+ const evaluatedUrl = evalExpression(url);
148
+ handleRequest({
149
+ url: evaluatedUrl,
150
+ key
151
+ });
152
+ }
153
+ });
154
+ }
155
+ function emitStateUpdate() {
156
+ if (isEditing()) {
157
+ window.dispatchEvent(new CustomEvent("builder:component:stateChange", {
158
+ detail: {
159
+ state: contentState(),
160
+ ref: {
161
+ name: props.model
162
+ }
163
+ }
164
+ }));
165
+ }
166
+ }
167
+ useEffect(() => {
168
+ if (isBrowser()) {
169
+ if (isEditing()) {
170
+ Object.values(allRegisteredComponents()).forEach((registeredComponent) => {
171
+ var _a2;
172
+ const message = createRegisterComponentMessage(registeredComponent);
173
+ (_a2 = window.parent) == null ? void 0 : _a2.postMessage(message, "*");
174
+ });
175
+ window.addEventListener("message", processMessage);
176
+ window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
177
+ }
178
+ if (useContent()) {
179
+ track("impression", {
180
+ contentId: useContent().id
181
+ });
182
+ }
183
+ if (isPreviewing()) {
184
+ if (props.model && previewingModelName() === props.model) {
185
+ const currentUrl = new URL(location.href);
186
+ const previewApiKey = currentUrl.searchParams.get("apiKey");
187
+ if (previewApiKey) {
188
+ getContent({
189
+ model: props.model,
190
+ apiKey: previewApiKey,
191
+ options: getBuilderSearchParams(convertSearchParamsToQueryObject(currentUrl.searchParams))
192
+ }).then((content) => {
193
+ if (content) {
194
+ setOverrideContent(content);
195
+ }
196
+ });
197
+ }
198
+ }
199
+ }
200
+ evaluateJsCode();
201
+ runHttpRequests();
202
+ emitStateUpdate();
203
+ }
204
+ }, []);
205
+ useEffect(() => {
206
+ evaluateJsCode();
207
+ }, [(_b = (_a = useContent == null ? void 0 : useContent()) == null ? void 0 : _a.data) == null ? void 0 : _b.jsCode]);
208
+ useEffect(() => {
209
+ runHttpRequests();
210
+ }, [(_d = (_c = useContent == null ? void 0 : useContent()) == null ? void 0 : _c.data) == null ? void 0 : _d.httpRequests]);
211
+ useEffect(() => {
212
+ emitStateUpdate();
213
+ }, [contentState()]);
214
+ useEffect(() => {
215
+ return () => {
216
+ if (isBrowser()) {
217
+ window.removeEventListener("message", processMessage);
218
+ window.removeEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
219
+ }
220
+ };
221
+ }, []);
222
+ return /* @__PURE__ */ React.createElement(BuilderContext.Provider, {
223
+ value: {
224
+ get content() {
225
+ return useContent();
226
+ },
227
+ get state() {
228
+ return contentState();
229
+ },
230
+ get context() {
231
+ return contextContext();
232
+ },
233
+ get apiKey() {
234
+ return props.apiKey;
235
+ },
236
+ get registeredComponents() {
237
+ return allRegisteredComponents();
238
+ }
239
+ }
240
+ }, useContent() ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(View, {
241
+ onClick: (event) => track("click", {
242
+ contentId: useContent().id
243
+ }),
244
+ "data-builder-content-id": (_e = useContent == null ? void 0 : useContent()) == null ? void 0 : _e.id
245
+ }, (((_g = (_f = useContent == null ? void 0 : useContent()) == null ? void 0 : _f.data) == null ? void 0 : _g.cssCode) || ((_j = (_i = (_h = useContent == null ? void 0 : useContent()) == null ? void 0 : _h.data) == null ? void 0 : _i.customFonts) == null ? void 0 : _j.length)) && TARGET !== "reactNative" ? /* @__PURE__ */ React.createElement(RenderContentStyles, {
246
+ cssCode: useContent().data.cssCode,
247
+ customFonts: useContent().data.customFonts
248
+ }) : null, /* @__PURE__ */ React.createElement(RenderBlocks, {
249
+ blocks: (_l = (_k = useContent == null ? void 0 : useContent()) == null ? void 0 : _k.data) == null ? void 0 : _l.blocks
250
+ }))) : null);
251
+ }
252
+ export {
253
+ RenderContent as default
254
+ };
@@ -0,0 +1,18 @@
1
+ import * as React from "react";
2
+ import { View, Text } from "react-native";
3
+ import { TARGET } from "../constants/target.js";
4
+ function RenderInlinedStyles(props) {
5
+ function injectedStyleScript() {
6
+ return `<${tagName()}>${props.styles}</${tagName()}>`;
7
+ }
8
+ function tagName() {
9
+ return "style";
10
+ }
11
+ const TagNameRef = tagName();
12
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, TARGET === "svelte" ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(View, {
13
+ dangerouslySetInnerHTML: { __html: injectedStyleScript() }
14
+ })) : /* @__PURE__ */ React.createElement(TagNameRef, null, /* @__PURE__ */ React.createElement(Text, null, props.styles)));
15
+ }
16
+ export {
17
+ RenderInlinedStyles as default
18
+ };
@@ -0,0 +1,43 @@
1
+ import * as React from 'react';
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __spreadValues = (a, b) => {
8
+ for (var prop in b || (b = {}))
9
+ if (__hasOwnProp.call(b, prop))
10
+ __defNormalProp(a, prop, b[prop]);
11
+ if (__getOwnPropSymbols)
12
+ for (var prop of __getOwnPropSymbols(b)) {
13
+ if (__propIsEnum.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ }
16
+ return a;
17
+ };
18
+ import { default as Button } from "../blocks/button/button.js";
19
+ import { componentInfo as buttonComponentInfo } from "../blocks/button/component-info";
20
+ import { default as Columns } from "../blocks/columns/columns.js";
21
+ import { componentInfo as columnsComponentInfo } from "../blocks/columns/component-info";
22
+ import { componentInfo as fragmentComponentInfo } from "../blocks/fragment/component-info";
23
+ import { default as Fragment } from "../blocks/fragment/fragment.js";
24
+ import { componentInfo as imageComponentInfo } from "../blocks/image/component-info";
25
+ import { default as Image } from "../blocks/image/image.js";
26
+ import { componentInfo as sectionComponentInfo } from "../blocks/section/component-info";
27
+ import { default as Section } from "../blocks/section/section.js";
28
+ import { componentInfo as symbolComponentInfo } from "../blocks/symbol/component-info";
29
+ import { default as Symbol } from "../blocks/symbol/symbol.js";
30
+ import { componentInfo as textComponentInfo } from "../blocks/text/component-info";
31
+ import { default as Text } from "../blocks/text/text.js";
32
+ const getDefaultRegisteredComponents = () => [
33
+ __spreadValues({ component: Columns }, columnsComponentInfo),
34
+ __spreadValues({ component: Image }, imageComponentInfo),
35
+ __spreadValues({ component: Text }, textComponentInfo),
36
+ __spreadValues({ component: Symbol }, symbolComponentInfo),
37
+ __spreadValues({ component: Button }, buttonComponentInfo),
38
+ __spreadValues({ component: Section }, sectionComponentInfo),
39
+ __spreadValues({ component: Fragment }, fragmentComponentInfo)
40
+ ];
41
+ export {
42
+ getDefaultRegisteredComponents
43
+ };
@@ -1,11 +1,5 @@
1
1
  import * as React from 'react';
2
- const sizeNames = ["xsmall", "small", "medium", "large"];
3
- const sizes = {
4
- xsmall: {
5
- min: 0,
6
- default: 0,
7
- max: 0
8
- },
2
+ const SIZES = {
9
3
  small: {
10
4
  min: 320,
11
5
  default: 321,
@@ -20,21 +14,9 @@ const sizes = {
20
14
  min: 990,
21
15
  default: 991,
22
16
  max: 1200
23
- },
24
- getWidthForSize(size) {
25
- return this[size].default;
26
- },
27
- getSizeForWidth(width) {
28
- for (const size of sizeNames) {
29
- const value = this[size];
30
- if (width <= value.max) {
31
- return size;
32
- }
33
- }
34
- return "large";
35
17
  }
36
18
  };
19
+ const getMaxWidthQueryForSize = (size) => `@media (max-width: ${SIZES[size].max}px)`;
37
20
  export {
38
- sizeNames,
39
- sizes
21
+ getMaxWidthQueryForSize
40
22
  };
@@ -0,0 +1,5 @@
1
+ import * as React from 'react';
2
+ const TARGET = "reactNative";
3
+ export {
4
+ TARGET
5
+ };
@@ -1,5 +1,11 @@
1
1
  import { createContext } from "react";
2
- var stdin_default = createContext({ content: null, context: {}, state: {} });
2
+ var stdin_default = createContext({
3
+ content: null,
4
+ context: {},
5
+ state: {},
6
+ apiKey: null,
7
+ registeredComponents: {}
8
+ });
3
9
  export {
4
10
  stdin_default as default
5
11
  };
@@ -0,0 +1,5 @@
1
+ import * as React from 'react';
2
+ const camelToKebabCase = (string) => string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
3
+ export {
4
+ camelToKebabCase
5
+ };
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ const convertStyleObject = (obj) => {
3
+ return obj;
4
+ };
5
+ export {
6
+ convertStyleObject
7
+ };
@@ -1,18 +1,27 @@
1
1
  import * as React from 'react';
2
- import { isBrowser } from "./is-browser";
3
- import { isEditing } from "./is-editing";
4
- function evaluate(options) {
5
- const { code } = options;
2
+ import { isBrowser } from "./is-browser.js";
3
+ import { isEditing } from "./is-editing.js";
4
+ function evaluate({
5
+ code,
6
+ context,
7
+ state,
8
+ event
9
+ }) {
10
+ if (code === "") {
11
+ console.warn("Skipping evaluation of empty code block.");
12
+ return;
13
+ }
6
14
  const builder = {
7
15
  isEditing: isEditing(),
8
- isBrowser: isBrowser()
16
+ isBrowser: isBrowser(),
17
+ isServer: !isBrowser()
9
18
  };
10
19
  const useReturn = !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
11
- const useCode = `${useReturn ? `return (${code});` : code}`;
20
+ const useCode = useReturn ? `return (${code});` : code;
12
21
  try {
13
- return new Function("builder", "Builder", "state", "context", "event", useCode)(builder, builder, options.state, options.context, options.event);
22
+ return new Function("builder", "Builder", "state", "context", "event", useCode)(builder, builder, state, context, event);
14
23
  } catch (e) {
15
- console.warn("Builder custom code error", e);
24
+ console.warn("Builder custom code error: ", e);
16
25
  }
17
26
  }
18
27
  export {
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ function capitalizeFirstLetter(string) {
3
+ return string.charAt(0).toUpperCase() + string.slice(1);
4
+ }
5
+ const getEventHandlerName = (key) => `on${capitalizeFirstLetter(key)}`;
6
+ export {
7
+ getEventHandlerName
8
+ };
@@ -0,0 +1,5 @@
1
+ import * as React from 'react';
2
+ const fastClone = (obj) => JSON.parse(JSON.stringify(obj));
3
+ export {
4
+ fastClone
5
+ };
@@ -1,20 +1,21 @@
1
1
  import * as React from 'react';
2
- import { evaluate } from "./evaluate";
3
- function capitalizeFirstLetter(string) {
4
- return string.charAt(0).toUpperCase() + string.slice(1);
5
- }
2
+ import { evaluate } from "./evaluate.js";
3
+ import { getEventHandlerName } from "./event-handler-name.js";
6
4
  function getBlockActions(options) {
5
+ var _a;
7
6
  const obj = {};
8
- if (options.block.actions) {
9
- for (const key in options.block.actions) {
10
- const value = options.block.actions[key];
11
- obj["on" + capitalizeFirstLetter(key)] = (event) => evaluate({
12
- code: value,
13
- context: options.context,
14
- state: options.state,
15
- event
16
- });
7
+ const optionActions = (_a = options.block.actions) != null ? _a : {};
8
+ for (const key in optionActions) {
9
+ if (!optionActions.hasOwnProperty(key)) {
10
+ continue;
17
11
  }
12
+ const value = optionActions[key];
13
+ obj[getEventHandlerName(key)] = (event) => evaluate({
14
+ code: value,
15
+ context: options.context,
16
+ state: options.state,
17
+ event
18
+ });
18
19
  }
19
20
  return obj;
20
21
  }
@@ -1,7 +1,28 @@
1
1
  import * as React from 'react';
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __spreadValues = (a, b) => {
10
+ for (var prop in b || (b = {}))
11
+ if (__hasOwnProp.call(b, prop))
12
+ __defNormalProp(a, prop, b[prop]);
13
+ if (__getOwnPropSymbols)
14
+ for (var prop of __getOwnPropSymbols(b)) {
15
+ if (__propIsEnum.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ }
18
+ return a;
19
+ };
20
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
2
21
  function getBlockComponentOptions(block) {
3
22
  var _a;
4
- return (_a = block.component) == null ? void 0 : _a.options;
23
+ return __spreadProps(__spreadValues(__spreadValues({}, (_a = block.component) == null ? void 0 : _a.options), block.options), {
24
+ builderBlock: block
25
+ });
5
26
  }
6
27
  export {
7
28
  getBlockComponentOptions
@@ -18,13 +18,12 @@ var __spreadValues = (a, b) => {
18
18
  return a;
19
19
  };
20
20
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
+ import { isEditing } from "./is-editing";
21
22
  import { findDOMNode } from "react-dom";
22
- import { isBrowser } from "./is-browser";
23
- import { isReactNative } from "./is-react-native";
24
23
  function getBlockProperties(block) {
25
24
  return __spreadProps(__spreadValues({}, block.properties), {
26
25
  ref: (ref) => {
27
- if (isBrowser() && !isReactNative()) {
26
+ if (isEditing()) {
28
27
  const el = findDOMNode(ref);
29
28
  if (el) {
30
29
  el.setAttribute("builder-id", block.id);
@@ -15,29 +15,19 @@ var __spreadValues = (a, b) => {
15
15
  }
16
16
  return a;
17
17
  };
18
- const propertiesThatMustBeNumber = new Set(["lineHeight"]);
18
+ import { getMaxWidthQueryForSize } from "../constants/device-sizes.js";
19
+ import { convertStyleObject } from "./convert-style-object.js";
20
+ import { sanitizeBlockStyles } from "./sanitize-styles.js";
19
21
  function getBlockStyles(block) {
20
- var _a, _b, _c;
21
- const styles = __spreadValues({}, (_a = block.responsiveStyles) == null ? void 0 : _a.large);
22
+ var _a, _b, _c, _d, _e;
23
+ const styles = __spreadValues(__spreadValues({}, convertStyleObject((_a = block.responsiveStyles) == null ? void 0 : _a.large)), block.styles);
22
24
  if ((_b = block.responsiveStyles) == null ? void 0 : _b.medium) {
23
- Object.assign(styles, block.responsiveStyles.medium);
25
+ styles[getMaxWidthQueryForSize("medium")] = convertStyleObject((_c = block.responsiveStyles) == null ? void 0 : _c.medium);
24
26
  }
25
- if ((_c = block.responsiveStyles) == null ? void 0 : _c.small) {
26
- Object.assign(styles, block.responsiveStyles.small);
27
- }
28
- for (const key in styles) {
29
- const propertyValue = styles[key];
30
- if (typeof propertyValue === "string" && propertyValue.match(/^\d/)) {
31
- const newValue = parseFloat(propertyValue);
32
- if (!isNaN(newValue)) {
33
- styles[key] = newValue;
34
- }
35
- }
36
- if (propertiesThatMustBeNumber.has(key) && typeof styles[key] !== "number") {
37
- console.warn(`Style key ${key} must be a number, but had value \`${styles[key]}\``);
38
- delete styles[key];
39
- }
27
+ if ((_d = block.responsiveStyles) == null ? void 0 : _d.small) {
28
+ styles[getMaxWidthQueryForSize("small")] = convertStyleObject((_e = block.responsiveStyles) == null ? void 0 : _e.small);
40
29
  }
30
+ sanitizeBlockStyles(styles);
41
31
  return styles;
42
32
  }
43
33
  export {
@@ -0,0 +1,14 @@
1
+ import * as React from 'react';
2
+ import { convertSearchParamsToQueryObject, getBuilderSearchParams } from ".";
3
+ const querystring = "someotherValue=jklsjfdal&abc=klfdjklgfds&builder.cachebust=true&builder.preview=page&builder.noCache=true&__builder_editing__=true&builder.overrides.page=037948e52eaf4743afed464f02c70da4&builder.overrides.037948e52eaf4743afed464f02c70da4=037948e52eaf4743afed464f02c70da4&builder.overrides.page%3A%2F=037948e52eaf4743afed464f02c70da4&preview_theme_id=128854393017";
4
+ const url = new URL(`localhost:3000/about-us?${querystring}`);
5
+ describe("Get Builder SearchParams", () => {
6
+ test("correctly converts URLSearchParams to object", () => {
7
+ const output = convertSearchParamsToQueryObject(url.searchParams);
8
+ expect(output).toMatchSnapshot();
9
+ });
10
+ test("correctly extracts all builder params from a query object", () => {
11
+ const output = getBuilderSearchParams(convertSearchParamsToQueryObject(url.searchParams));
12
+ expect(output).toMatchSnapshot();
13
+ });
14
+ });
@@ -0,0 +1,23 @@
1
+ import * as React from 'react';
2
+ const BUILDER_SEARCHPARAMS_PREFIX = "builder.";
3
+ const convertSearchParamsToQueryObject = (searchParams) => {
4
+ const options = {};
5
+ searchParams.forEach((value, key) => {
6
+ options[key] = value;
7
+ });
8
+ return options;
9
+ };
10
+ const getBuilderSearchParams = (options) => {
11
+ const newOptions = {};
12
+ Object.keys(options).forEach((key) => {
13
+ if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
14
+ const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, "");
15
+ newOptions[trimmedKey] = options[key];
16
+ }
17
+ });
18
+ return newOptions;
19
+ };
20
+ export {
21
+ convertSearchParamsToQueryObject,
22
+ getBuilderSearchParams
23
+ };
@@ -0,0 +1,32 @@
1
+ import * as React from 'react';
2
+ import { generateContentUrl } from ".";
3
+ const testKey = "YJIGb4i01jvw0SRdL5Bt";
4
+ const testModel = "page";
5
+ const testId = "c1b81bab59704599b997574eb0736def";
6
+ const options = {
7
+ cachebust: "true",
8
+ noCache: "true",
9
+ "overrides.037948e52eaf4743afed464f02c70da4": "037948e52eaf4743afed464f02c70da4",
10
+ "overrides.page": "037948e52eaf4743afed464f02c70da4",
11
+ "overrides.page:/": "037948e52eaf4743afed464f02c70da4",
12
+ preview: "page"
13
+ };
14
+ describe("Generate Content URL", () => {
15
+ test("generates the proper value for a simple query", () => {
16
+ const output = generateContentUrl({
17
+ apiKey: testKey,
18
+ model: testModel,
19
+ query: { id: testId }
20
+ });
21
+ expect(output).toMatchSnapshot();
22
+ });
23
+ test("Handles overrides correctly", () => {
24
+ const output = generateContentUrl({
25
+ apiKey: testKey,
26
+ model: testModel,
27
+ query: { id: testId },
28
+ options
29
+ });
30
+ expect(output).toMatchSnapshot();
31
+ });
32
+ });