@builder.io/sdk-react-native 0.0.1-4 → 0.0.1-49

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 (90) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +15 -0
  3. package/package.json +6 -4
  4. package/src/blocks/button.js +73 -24
  5. package/src/blocks/button.lite.tsx +10 -14
  6. package/src/blocks/columns.js +286 -40
  7. package/src/blocks/columns.lite.tsx +43 -20
  8. package/src/blocks/custom-code.js +74 -47
  9. package/src/blocks/custom-code.lite.tsx +11 -19
  10. package/src/blocks/embed.js +68 -47
  11. package/src/blocks/embed.lite.tsx +11 -15
  12. package/src/blocks/form.js +490 -198
  13. package/src/blocks/form.lite.tsx +54 -58
  14. package/src/blocks/fragment.js +21 -0
  15. package/src/blocks/fragment.lite.tsx +10 -0
  16. package/src/blocks/image.js +125 -83
  17. package/src/blocks/image.lite.tsx +46 -14
  18. package/src/blocks/img.js +51 -28
  19. package/src/blocks/img.lite.tsx +6 -7
  20. package/src/blocks/input.js +100 -28
  21. package/src/blocks/input.lite.tsx +4 -7
  22. package/src/blocks/raw-text.js +12 -12
  23. package/src/blocks/raw-text.lite.tsx +3 -9
  24. package/src/blocks/section.js +71 -23
  25. package/src/blocks/section.lite.tsx +4 -5
  26. package/src/blocks/select.js +78 -27
  27. package/src/blocks/select.lite.tsx +8 -9
  28. package/src/blocks/submit-button.js +47 -21
  29. package/src/blocks/submit-button.lite.tsx +3 -4
  30. package/src/blocks/symbol.js +16 -16
  31. package/src/blocks/symbol.lite.tsx +6 -6
  32. package/src/blocks/text.js +85 -16
  33. package/src/blocks/text.lite.tsx +3 -9
  34. package/src/blocks/textarea.js +60 -24
  35. package/src/blocks/textarea.lite.tsx +2 -3
  36. package/src/blocks/video.js +97 -46
  37. package/src/blocks/video.lite.tsx +5 -6
  38. package/src/components/block-styles.js +5 -0
  39. package/src/components/block-styles.lite.tsx +6 -0
  40. package/src/components/error-boundary.js +27 -0
  41. package/src/components/error-boundary.lite.tsx +6 -0
  42. package/src/components/render-block.js +119 -39
  43. package/src/components/render-block.lite.tsx +76 -36
  44. package/src/components/render-blocks.js +65 -32
  45. package/src/components/render-blocks.lite.tsx +25 -16
  46. package/src/components/render-content.js +190 -36
  47. package/src/components/render-content.lite.tsx +143 -32
  48. package/src/constants/device-sizes.js +8 -11
  49. package/src/context/builder.context.js +2 -4
  50. package/src/functions/evaluate.js +18 -9
  51. package/src/functions/event-handler-name.js +6 -0
  52. package/src/functions/get-block-actions.js +13 -13
  53. package/src/functions/get-block-component-options.js +27 -4
  54. package/src/functions/get-block-properties.js +23 -16
  55. package/src/functions/get-block-styles.js +56 -9
  56. package/src/functions/get-block-tag.js +2 -4
  57. package/src/functions/get-builder-search-params/fn.test.js +18 -0
  58. package/src/functions/get-builder-search-params/index.js +20 -0
  59. package/src/functions/get-content/fn.test.js +34 -0
  60. package/src/functions/get-content/index.js +156 -0
  61. package/src/functions/get-fetch.js +11 -0
  62. package/src/functions/get-global-this.js +17 -0
  63. package/src/functions/get-processed-block.js +19 -13
  64. package/src/functions/get-processed-block.test.js +32 -16
  65. package/src/functions/get-target.js +3 -5
  66. package/src/functions/if-target.js +1 -3
  67. package/src/functions/is-browser.js +2 -5
  68. package/src/functions/is-editing.js +5 -5
  69. package/src/functions/is-iframe.js +2 -4
  70. package/src/functions/is-previewing.js +13 -0
  71. package/src/functions/is-react-native.js +2 -4
  72. package/src/functions/macro-eval.js +2 -5
  73. package/src/functions/on-change.js +4 -7
  74. package/src/functions/on-change.test.js +10 -10
  75. package/src/functions/previewing-model-name.js +10 -0
  76. package/src/functions/register-component.js +39 -27
  77. package/src/functions/register.js +28 -0
  78. package/src/functions/set-editor-settings.js +14 -0
  79. package/src/functions/set.js +14 -5
  80. package/src/functions/set.test.js +14 -14
  81. package/src/functions/track.js +7 -9
  82. package/src/functions/transform-block.js +42 -0
  83. package/src/index-helpers/blocks-exports.js +19 -0
  84. package/src/index-helpers/top-of-file.js +2 -0
  85. package/src/index.js +10 -21
  86. package/src/scripts/init-editing.js +67 -29
  87. package/src/types/deep-partial.js +1 -0
  88. package/index.js +0 -11
  89. package/src/functions/get-content.js +0 -103
  90. package/src/package.json +0 -18
@@ -5,35 +5,42 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
5
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
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;
8
+ var __defNormalProp = (obj, key, value) =>
9
+ key in obj
10
+ ? __defProp(obj, key, {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value,
15
+ })
16
+ : (obj[key] = value);
9
17
  var __spreadValues = (a, b) => {
10
18
  for (var prop in b || (b = {}))
11
- if (__hasOwnProp.call(b, prop))
12
- __defNormalProp(a, prop, b[prop]);
19
+ if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
13
20
  if (__getOwnPropSymbols)
14
21
  for (var prop of __getOwnPropSymbols(b)) {
15
- if (__propIsEnum.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
22
+ if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
17
23
  }
18
24
  return a;
19
25
  };
20
26
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
- import { findDOMNode } from "react-dom";
27
+ import { findDOMNode } from 'react-dom';
28
+ import { isEditing } from './is-editing';
22
29
  function getBlockProperties(block) {
23
30
  return __spreadProps(__spreadValues({}, block.properties), {
24
31
  ref: (ref) => {
25
- const el = findDOMNode(ref);
26
- if (el) {
27
- el.setAttribute("builder-id", block.id);
28
- el.classList.add(block.id);
32
+ if (isEditing()) {
33
+ const el = findDOMNode(ref);
34
+ if (el) {
35
+ el.setAttribute('builder-id', block.id);
36
+ el.classList.add(block.id);
37
+ }
29
38
  }
30
39
  },
31
40
  dataSet: {
32
- "builder-id": block.id,
33
- class: [block.id, "builder-block", block.class].filter(Boolean).join(" ")
34
- }
41
+ 'builder-id': block.id,
42
+ class: [block.id, 'builder-block', block.class].filter(Boolean).join(' '),
43
+ },
35
44
  });
36
45
  }
37
- export {
38
- getBlockProperties
39
- };
46
+ export { getBlockProperties };
@@ -3,29 +3,76 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
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;
6
+ var __defNormalProp = (obj, key, value) =>
7
+ key in obj
8
+ ? __defProp(obj, key, {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value,
13
+ })
14
+ : (obj[key] = value);
7
15
  var __spreadValues = (a, b) => {
8
16
  for (var prop in b || (b = {}))
9
- if (__hasOwnProp.call(b, prop))
10
- __defNormalProp(a, prop, b[prop]);
17
+ if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
11
18
  if (__getOwnPropSymbols)
12
19
  for (var prop of __getOwnPropSymbols(b)) {
13
- if (__propIsEnum.call(b, prop))
14
- __defNormalProp(a, prop, b[prop]);
20
+ if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
15
21
  }
16
22
  return a;
17
23
  };
24
+ const propertiesThatMustBeNumber = new Set(['lineHeight']);
25
+ const displayValues = new Set(['flex', 'none']);
26
+ const SHOW_WARNINGS = false;
27
+ function validateReactNativeStyles(styles) {
28
+ for (const key in styles) {
29
+ const propertyValue = styles[key];
30
+ if (key === 'display' && !displayValues.has(propertyValue)) {
31
+ if (SHOW_WARNINGS) {
32
+ console.warn(
33
+ `Style value for key "display" must be "flex" or "none" but had ${propertyValue}`
34
+ );
35
+ }
36
+ delete styles[key];
37
+ }
38
+ if (typeof propertyValue === 'string' && propertyValue.match(/^\-?\d/)) {
39
+ const newValue = parseFloat(propertyValue);
40
+ if (!isNaN(newValue)) {
41
+ styles[key] = newValue;
42
+ }
43
+ if (typeof newValue === 'number' && newValue < 0) {
44
+ styles[key] = 0;
45
+ }
46
+ }
47
+ if (
48
+ propertiesThatMustBeNumber.has(key) &&
49
+ typeof styles[key] !== 'number'
50
+ ) {
51
+ if (SHOW_WARNINGS) {
52
+ console.warn(
53
+ `Style key ${key} must be a number, but had value \`${styles[key]}\``
54
+ );
55
+ }
56
+ delete styles[key];
57
+ }
58
+ }
59
+ }
18
60
  function getBlockStyles(block) {
19
61
  var _a, _b, _c;
20
- const styles = __spreadValues({}, (_a = block.responsiveStyles) == null ? void 0 : _a.large);
62
+ const styles = __spreadValues(
63
+ __spreadValues(
64
+ {},
65
+ (_a = block.responsiveStyles) == null ? void 0 : _a.large
66
+ ),
67
+ block.styles
68
+ );
21
69
  if ((_b = block.responsiveStyles) == null ? void 0 : _b.medium) {
22
70
  Object.assign(styles, block.responsiveStyles.medium);
23
71
  }
24
72
  if ((_c = block.responsiveStyles) == null ? void 0 : _c.small) {
25
73
  Object.assign(styles, block.responsiveStyles.small);
26
74
  }
75
+ validateReactNativeStyles(styles);
27
76
  return styles;
28
77
  }
29
- export {
30
- getBlockStyles
31
- };
78
+ export { getBlockStyles };
@@ -1,8 +1,6 @@
1
1
  import * as React from 'react';
2
- import { View } from "react-native";
2
+ import { View } from 'react-native';
3
3
  function getBlockTag(block) {
4
4
  return View;
5
5
  }
6
- export {
7
- getBlockTag
8
- };
6
+ export { getBlockTag };
@@ -0,0 +1,18 @@
1
+ import * as React from 'react';
2
+ import { describe, test, expect } from '@jest/globals';
3
+ import { getBuilderSearchParams, convertSearchParamsToQueryObject } from '.';
4
+ const querystring =
5
+ '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';
6
+ const url = new URL(`localhost:3000/about-us?${querystring}`);
7
+ describe('Get Builder SearchParams', () => {
8
+ test('correctly converts URLSearchParams to object', () => {
9
+ const output = convertSearchParamsToQueryObject(url.searchParams);
10
+ expect(output).toMatchSnapshot();
11
+ });
12
+ test('correctly extracts all builder params from a query object', () => {
13
+ const output = getBuilderSearchParams(
14
+ convertSearchParamsToQueryObject(url.searchParams)
15
+ );
16
+ expect(output).toMatchSnapshot();
17
+ });
18
+ });
@@ -0,0 +1,20 @@
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 { convertSearchParamsToQueryObject, getBuilderSearchParams };
@@ -0,0 +1,34 @@
1
+ import * as React from 'react';
2
+ import { describe, test, expect } from '@jest/globals';
3
+ import { generateContentUrl } from '.';
4
+ const testKey = 'YJIGb4i01jvw0SRdL5Bt';
5
+ const testModel = 'page';
6
+ const testId = 'c1b81bab59704599b997574eb0736def';
7
+ const options = {
8
+ cachebust: 'true',
9
+ noCache: 'true',
10
+ 'overrides.037948e52eaf4743afed464f02c70da4':
11
+ '037948e52eaf4743afed464f02c70da4',
12
+ 'overrides.page': '037948e52eaf4743afed464f02c70da4',
13
+ 'overrides.page:/': '037948e52eaf4743afed464f02c70da4',
14
+ preview: 'page',
15
+ };
16
+ describe('Generate Content URL', () => {
17
+ test('generates the proper value for a simple query', () => {
18
+ const output = generateContentUrl({
19
+ apiKey: testKey,
20
+ model: testModel,
21
+ query: { id: testId },
22
+ });
23
+ expect(output).toMatchSnapshot();
24
+ });
25
+ test('Handles overrides correctly', () => {
26
+ const output = generateContentUrl({
27
+ apiKey: testKey,
28
+ model: testModel,
29
+ query: { id: testId },
30
+ options,
31
+ });
32
+ expect(output).toMatchSnapshot();
33
+ });
34
+ });
@@ -0,0 +1,156 @@
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) =>
9
+ key in obj
10
+ ? __defProp(obj, key, {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value,
15
+ })
16
+ : (obj[key] = value);
17
+ var __spreadValues = (a, b) => {
18
+ for (var prop in b || (b = {}))
19
+ if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
20
+ if (__getOwnPropSymbols)
21
+ for (var prop of __getOwnPropSymbols(b)) {
22
+ if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
23
+ }
24
+ return a;
25
+ };
26
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
27
+ var __async = (__this, __arguments, generator) => {
28
+ return new Promise((resolve, reject) => {
29
+ var fulfilled = (value) => {
30
+ try {
31
+ step(generator.next(value));
32
+ } catch (e) {
33
+ reject(e);
34
+ }
35
+ };
36
+ var rejected = (value) => {
37
+ try {
38
+ step(generator.throw(value));
39
+ } catch (e) {
40
+ reject(e);
41
+ }
42
+ };
43
+ var step = (x) =>
44
+ x.done
45
+ ? resolve(x.value)
46
+ : Promise.resolve(x.value).then(fulfilled, rejected);
47
+ step((generator = generator.apply(__this, __arguments)).next());
48
+ });
49
+ };
50
+ import { getFetch } from '../get-fetch';
51
+ const fetch = getFetch();
52
+ function flatten(object, path = null, separator = '.') {
53
+ return Object.keys(object).reduce((acc, key) => {
54
+ const value = object[key];
55
+ const newPath = [path, key].filter(Boolean).join(separator);
56
+ const isObject = [
57
+ typeof value === 'object',
58
+ value !== null,
59
+ !(Array.isArray(value) && value.length === 0),
60
+ ].every(Boolean);
61
+ return isObject
62
+ ? __spreadValues(
63
+ __spreadValues({}, acc),
64
+ flatten(value, newPath, separator)
65
+ )
66
+ : __spreadProps(__spreadValues({}, acc), { [newPath]: value });
67
+ }, {});
68
+ }
69
+ function getContent(options) {
70
+ return __async(this, null, function* () {
71
+ return (
72
+ (yield getAllContent(
73
+ __spreadProps(__spreadValues({}, options), { limit: 1 })
74
+ )).results[0] || null
75
+ );
76
+ });
77
+ }
78
+ const generateContentUrl = (options) => {
79
+ const {
80
+ limit = 1,
81
+ userAttributes,
82
+ query,
83
+ noTraverse = false,
84
+ model,
85
+ apiKey,
86
+ } = options;
87
+ const url = new URL(
88
+ `https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}`
89
+ );
90
+ if (options.options) {
91
+ const flattened = flatten(options.options);
92
+ for (const key in flattened) {
93
+ url.searchParams.set(key, String(flattened[key]));
94
+ }
95
+ }
96
+ if (userAttributes) {
97
+ url.searchParams.set('userAttributes', JSON.stringify(userAttributes));
98
+ }
99
+ if (query) {
100
+ const flattened = flatten({ query });
101
+ for (const key in flattened) {
102
+ url.searchParams.set(key, JSON.stringify(flattened[key]));
103
+ }
104
+ }
105
+ return url;
106
+ };
107
+ const handleABTesting = (content, testGroups) => {
108
+ for (const item of content.results) {
109
+ if (item.variations && Object.keys(item.variations).length) {
110
+ const testGroup = testGroups[item.id];
111
+ const variationValue = item.variations[testGroup];
112
+ if (testGroup && variationValue) {
113
+ item.data = variationValue.data;
114
+ item.testVariationId = variationValue.id;
115
+ item.testVariationName = variationValue.name;
116
+ } else {
117
+ let n = 0;
118
+ const random = Math.random();
119
+ let set = false;
120
+ for (const id in item.variations) {
121
+ const variation = item.variations[id];
122
+ const testRatio = variation.testRatio;
123
+ n += testRatio;
124
+ if (random < n) {
125
+ const variationName =
126
+ variation.name ||
127
+ (variation.id === item.id ? 'Default variation' : '');
128
+ set = true;
129
+ Object.assign(item, {
130
+ data: variation.data,
131
+ testVariationId: variation.id,
132
+ testVariationName: variationName,
133
+ });
134
+ }
135
+ }
136
+ if (!set) {
137
+ Object.assign(item, {
138
+ testVariationId: item.id,
139
+ testVariationName: 'Default',
140
+ });
141
+ }
142
+ }
143
+ }
144
+ }
145
+ };
146
+ function getAllContent(options) {
147
+ return __async(this, null, function* () {
148
+ const url = generateContentUrl(options);
149
+ const content = yield fetch(url.href).then((res) => res.json());
150
+ if (options.testGroups) {
151
+ handleABTesting(content, options.testGroups);
152
+ }
153
+ return content;
154
+ });
155
+ }
156
+ export { generateContentUrl, getAllContent, getContent };
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+ import { getGlobalThis } from './get-global-this';
3
+ function getFetch() {
4
+ let fetch = getGlobalThis().fetch;
5
+ if (typeof fetch === 'undefined' && typeof global !== 'undefined') {
6
+ const _require = eval('require');
7
+ fetch = _require('node-fetch');
8
+ }
9
+ return fetch;
10
+ }
11
+ export { getFetch };
@@ -0,0 +1,17 @@
1
+ import * as React from 'react';
2
+ function getGlobalThis() {
3
+ if (typeof globalThis !== 'undefined') {
4
+ return globalThis;
5
+ }
6
+ if (typeof window !== 'undefined') {
7
+ return window;
8
+ }
9
+ if (typeof global !== 'undefined') {
10
+ return global;
11
+ }
12
+ if (typeof self !== 'undefined') {
13
+ return self;
14
+ }
15
+ return null;
16
+ }
17
+ export { getGlobalThis };
@@ -5,41 +5,47 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
5
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
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;
8
+ var __defNormalProp = (obj, key, value) =>
9
+ key in obj
10
+ ? __defProp(obj, key, {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value,
15
+ })
16
+ : (obj[key] = value);
9
17
  var __spreadValues = (a, b) => {
10
18
  for (var prop in b || (b = {}))
11
- if (__hasOwnProp.call(b, prop))
12
- __defNormalProp(a, prop, b[prop]);
19
+ if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
13
20
  if (__getOwnPropSymbols)
14
21
  for (var prop of __getOwnPropSymbols(b)) {
15
- if (__propIsEnum.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
22
+ if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
17
23
  }
18
24
  return a;
19
25
  };
20
26
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
- import { evaluate } from "./evaluate";
22
- import { set } from "./set";
27
+ import { evaluate } from './evaluate';
28
+ import { set } from './set';
29
+ import { transformBlock } from './transform-block';
23
30
  function getProcessedBlock(options) {
24
- const { block, state, context } = options;
31
+ const { state, context } = options;
32
+ const block = transformBlock(options.block);
25
33
  if (!block.bindings) {
26
34
  return block;
27
35
  }
28
36
  const copied = __spreadProps(__spreadValues({}, block), {
29
37
  properties: __spreadValues({}, block.properties),
30
- actions: __spreadValues({}, block.actions)
38
+ actions: __spreadValues({}, block.actions),
31
39
  });
32
40
  for (const binding in block.bindings) {
33
41
  const expression = block.bindings[binding];
34
42
  const value = evaluate({
35
43
  code: expression,
36
44
  state,
37
- context
45
+ context,
38
46
  });
39
47
  set(copied, binding, value);
40
48
  }
41
49
  return copied;
42
50
  }
43
- export {
44
- getProcessedBlock
45
- };
51
+ export { getProcessedBlock };
@@ -1,27 +1,43 @@
1
1
  import * as React from 'react';
2
- import { expect, test } from "@jest/globals";
3
- import { getProcessedBlock } from "./get-processed-block";
4
- test("Can process bindings", () => {
2
+ import { expect, test } from '@jest/globals';
3
+ import { getProcessedBlock } from './get-processed-block';
4
+ test('Can process bindings', () => {
5
+ var _a, _b, _c, _d, _e, _f;
5
6
  const block = {
7
+ '@type': '@builder.io/sdk:Element',
6
8
  properties: {
7
- foo: "bar"
9
+ foo: 'bar',
8
10
  },
9
11
  bindings: {
10
- "properties.foo": '"baz"',
11
- "responsiveStyles.large.zIndex": "1 + 1",
12
- "properties.test": "state.test",
13
- "properties.block": `
12
+ 'properties.foo': '"baz"',
13
+ 'responsiveStyles.large.zIndex': '1 + 1',
14
+ 'properties.test': 'state.test',
15
+ 'properties.block': `
14
16
  const foo = 'bar';
15
17
  return foo;
16
18
  `,
17
- "properties.isEditing": "builder.isEditing"
18
- }
19
+ 'properties.isEditing': 'builder.isEditing',
20
+ },
19
21
  };
20
- const processed = getProcessedBlock({ block, context: {}, state: { test: "hello" } });
22
+ const processed = getProcessedBlock({
23
+ block,
24
+ context: {},
25
+ state: { test: 'hello' },
26
+ });
21
27
  expect(processed).not.toEqual(block);
22
- expect(processed.properties.foo).toEqual("baz");
23
- expect(processed.properties.test).toEqual("hello");
24
- expect(processed.properties.block).toEqual("bar");
25
- expect(processed.properties.isEditing).toEqual(false);
26
- expect(processed.responsiveStyles.large.zIndex).toEqual(2);
28
+ expect((_a = processed.properties) == null ? void 0 : _a.foo).toEqual('baz');
29
+ expect((_b = processed.properties) == null ? void 0 : _b.test).toEqual(
30
+ 'hello'
31
+ );
32
+ expect((_c = processed.properties) == null ? void 0 : _c.block).toEqual(
33
+ 'bar'
34
+ );
35
+ expect((_d = processed.properties) == null ? void 0 : _d.isEditing).toEqual(
36
+ false
37
+ );
38
+ expect(
39
+ (_f = (_e = processed.responsiveStyles) == null ? void 0 : _e.large) == null
40
+ ? void 0
41
+ : _f.zIndex
42
+ ).toEqual(2);
27
43
  });
@@ -1,7 +1,5 @@
1
1
  import * as React from 'react';
2
- function getTarget() {
3
- return "reactNative";
2
+ function getTarget(_) {
3
+ return 'reactNative';
4
4
  }
5
- export {
6
- getTarget
7
- };
5
+ export { getTarget };
@@ -2,6 +2,4 @@ import * as React from 'react';
2
2
  function ifTarget(target, doThing, elseThing) {
3
3
  return doThing();
4
4
  }
5
- export {
6
- ifTarget
7
- };
5
+ export { ifTarget };
@@ -1,8 +1,5 @@
1
1
  import * as React from 'react';
2
- import { isReactNative } from "./is-react-native";
3
2
  function isBrowser() {
4
- return typeof window !== "undefined" && typeof document !== "undefined" && !isReactNative();
3
+ return typeof window !== 'undefined' && typeof document !== 'undefined';
5
4
  }
6
- export {
7
- isBrowser
8
- };
5
+ export { isBrowser };
@@ -1,8 +1,8 @@
1
1
  import * as React from 'react';
2
- import { isIframe } from "./is-iframe";
2
+ import { isIframe } from './is-iframe';
3
3
  function isEditing() {
4
- return isIframe() && window.location.search.indexOf("builder.frameEditing=") !== -1;
4
+ return (
5
+ isIframe() && window.location.search.indexOf('builder.frameEditing=') !== -1
6
+ );
5
7
  }
6
- export {
7
- isEditing
8
- };
8
+ export { isEditing };
@@ -1,8 +1,6 @@
1
1
  import * as React from 'react';
2
- import { isBrowser } from "./is-browser";
2
+ import { isBrowser } from './is-browser';
3
3
  function isIframe() {
4
4
  return isBrowser() && window.self !== window.top;
5
5
  }
6
- export {
7
- isIframe
8
- };
6
+ export { isIframe };
@@ -0,0 +1,13 @@
1
+ import * as React from 'react';
2
+ import { isBrowser } from './is-browser';
3
+ import { isEditing } from './is-editing';
4
+ function isPreviewing() {
5
+ if (!isBrowser()) {
6
+ return false;
7
+ }
8
+ if (isEditing()) {
9
+ return false;
10
+ }
11
+ return Boolean(location.search.indexOf('builder.preview=') !== -1);
12
+ }
13
+ export { isPreviewing };
@@ -1,7 +1,5 @@
1
1
  import * as React from 'react';
2
2
  function isReactNative() {
3
- return typeof navigator === "object" && navigator.product === "ReactNative";
3
+ return true;
4
4
  }
5
- export {
6
- isReactNative
7
- };
5
+ export { isReactNative };
@@ -1,6 +1,3 @@
1
1
  import * as React from 'react';
2
- function macroEval(items, string) {
3
- }
4
- export {
5
- macroEval
6
- };
2
+ function macroEval(items, string) {}
3
+ export { macroEval };
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- const onChangeProxySymbol = Symbol("onChangeProxySymbol");
2
+ const onChangeProxySymbol = Symbol('onChangeProxySymbol');
3
3
  function onChange(obj, cb) {
4
4
  return new Proxy(obj, {
5
5
  get(target, key) {
@@ -7,7 +7,7 @@ function onChange(obj, cb) {
7
7
  return true;
8
8
  }
9
9
  const value = Reflect.get(target, key);
10
- if (value && typeof value === "object") {
10
+ if (value && typeof value === 'object') {
11
11
  if (value[onChangeProxySymbol]) {
12
12
  return value;
13
13
  }
@@ -19,10 +19,7 @@ function onChange(obj, cb) {
19
19
  const returnValue = Reflect.set(target, key, value);
20
20
  cb();
21
21
  return returnValue;
22
- }
22
+ },
23
23
  });
24
24
  }
25
- export {
26
- onChange,
27
- onChangeProxySymbol
28
- };
25
+ export { onChange, onChangeProxySymbol };