@builder.io/sdk-react-native 0.0.1-3 → 0.0.1-33

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 (80) hide show
  1. package/package.json +4 -2
  2. package/src/blocks/button.js +66 -24
  3. package/src/blocks/button.lite.tsx +10 -14
  4. package/src/blocks/columns.js +247 -40
  5. package/src/blocks/columns.lite.tsx +8 -13
  6. package/src/blocks/custom-code.js +73 -47
  7. package/src/blocks/custom-code.lite.tsx +12 -16
  8. package/src/blocks/embed.js +66 -47
  9. package/src/blocks/embed.lite.tsx +11 -13
  10. package/src/blocks/form.js +436 -198
  11. package/src/blocks/form.lite.tsx +67 -78
  12. package/src/blocks/fragment.js +21 -0
  13. package/src/blocks/fragment.lite.tsx +11 -0
  14. package/src/blocks/image.js +88 -77
  15. package/src/blocks/image.lite.tsx +45 -14
  16. package/src/blocks/img.js +45 -28
  17. package/src/blocks/img.lite.tsx +7 -7
  18. package/src/blocks/input.js +93 -28
  19. package/src/blocks/input.lite.tsx +5 -9
  20. package/src/blocks/raw-text.js +16 -12
  21. package/src/blocks/raw-text.lite.tsx +3 -3
  22. package/src/blocks/section.js +66 -23
  23. package/src/blocks/section.lite.tsx +5 -5
  24. package/src/blocks/select.js +67 -27
  25. package/src/blocks/select.lite.tsx +9 -11
  26. package/src/blocks/submit-button.js +41 -21
  27. package/src/blocks/submit-button.lite.tsx +4 -4
  28. package/src/blocks/symbol.js +18 -16
  29. package/src/blocks/symbol.lite.tsx +5 -5
  30. package/src/blocks/text.js +72 -16
  31. package/src/blocks/text.lite.tsx +4 -9
  32. package/src/blocks/textarea.js +53 -24
  33. package/src/blocks/textarea.lite.tsx +3 -3
  34. package/src/blocks/video.js +90 -46
  35. package/src/blocks/video.lite.tsx +6 -6
  36. package/src/components/block-styles.js +5 -0
  37. package/src/components/block-styles.lite.tsx +7 -0
  38. package/src/components/error-boundary.js +27 -0
  39. package/src/components/error-boundary.lite.tsx +7 -0
  40. package/src/components/render-block.js +103 -37
  41. package/src/components/render-block.lite.tsx +58 -33
  42. package/src/components/render-blocks.js +59 -35
  43. package/src/components/render-blocks.lite.tsx +20 -16
  44. package/src/components/render-content.js +160 -35
  45. package/src/components/render-content.lite.tsx +140 -37
  46. package/src/constants/device-sizes.js +8 -11
  47. package/src/context/builder.context.js +2 -4
  48. package/src/functions/evaluate.js +17 -9
  49. package/src/functions/get-block-actions.js +9 -10
  50. package/src/functions/get-block-component-options.js +21 -4
  51. package/src/functions/get-block-properties.js +20 -18
  52. package/src/functions/get-block-styles.js +43 -10
  53. package/src/functions/get-block-tag.js +2 -4
  54. package/src/functions/get-content.js +62 -28
  55. package/src/functions/get-content.test.js +56 -0
  56. package/src/functions/get-fetch.js +11 -0
  57. package/src/functions/get-global-this.js +17 -0
  58. package/src/functions/get-processed-block.js +11 -13
  59. package/src/functions/get-processed-block.test.js +14 -14
  60. package/src/functions/get-target.js +3 -5
  61. package/src/functions/if-target.js +1 -3
  62. package/src/functions/is-browser.js +3 -5
  63. package/src/functions/is-editing.js +3 -5
  64. package/src/functions/is-iframe.js +2 -4
  65. package/src/functions/is-previewing.js +13 -0
  66. package/src/functions/is-react-native.js +2 -4
  67. package/src/functions/macro-eval.js +2 -5
  68. package/src/functions/on-change.js +4 -7
  69. package/src/functions/on-change.test.js +10 -10
  70. package/src/functions/previewing-model-name.js +10 -0
  71. package/src/functions/register-component.js +34 -28
  72. package/src/functions/register.js +28 -0
  73. package/src/functions/set-editor-settings.js +14 -0
  74. package/src/functions/set.js +10 -4
  75. package/src/functions/set.test.js +14 -14
  76. package/src/functions/track.js +6 -8
  77. package/src/index.js +17 -14
  78. package/src/scripts/init-editing.js +67 -29
  79. package/src/types/deep-partial.js +1 -0
  80. package/index.js +0 -11
@@ -3,29 +3,62 @@ 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, { enumerable: true, configurable: true, writable: true, value })
9
+ : (obj[key] = value);
7
10
  var __spreadValues = (a, b) => {
8
- for (var prop in b || (b = {}))
9
- if (__hasOwnProp.call(b, prop))
10
- __defNormalProp(a, prop, b[prop]);
11
+ for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
11
12
  if (__getOwnPropSymbols)
12
13
  for (var prop of __getOwnPropSymbols(b)) {
13
- if (__propIsEnum.call(b, prop))
14
- __defNormalProp(a, prop, b[prop]);
14
+ if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
15
15
  }
16
16
  return a;
17
17
  };
18
+ const propertiesThatMustBeNumber = new Set(['lineHeight']);
19
+ const displayValues = new Set(['flex', 'none']);
20
+ const SHOW_WARNINGS = false;
21
+ function validateReactNativeStyles(styles) {
22
+ for (const key in styles) {
23
+ const propertyValue = styles[key];
24
+ if (key === 'display' && !displayValues.has(propertyValue)) {
25
+ if (SHOW_WARNINGS) {
26
+ console.warn(
27
+ `Style value for key "display" must be "flex" or "none" but had ${propertyValue}`
28
+ );
29
+ }
30
+ delete styles[key];
31
+ }
32
+ if (typeof propertyValue === 'string' && propertyValue.match(/^\d/)) {
33
+ const newValue = parseFloat(propertyValue);
34
+ if (!isNaN(newValue)) {
35
+ styles[key] = newValue;
36
+ }
37
+ if (typeof newValue === 'number' && newValue < 0) {
38
+ styles[key] = 0;
39
+ }
40
+ }
41
+ if (propertiesThatMustBeNumber.has(key) && typeof styles[key] !== 'number') {
42
+ if (SHOW_WARNINGS) {
43
+ console.warn(`Style key ${key} must be a number, but had value \`${styles[key]}\``);
44
+ }
45
+ delete styles[key];
46
+ }
47
+ }
48
+ }
18
49
  function getBlockStyles(block) {
19
50
  var _a, _b, _c;
20
- const styles = __spreadValues({}, (_a = block.responsiveStyles) == null ? void 0 : _a.large);
51
+ const styles = __spreadValues(
52
+ __spreadValues({}, (_a = block.responsiveStyles) == null ? void 0 : _a.large),
53
+ block.styles
54
+ );
21
55
  if ((_b = block.responsiveStyles) == null ? void 0 : _b.medium) {
22
56
  Object.assign(styles, block.responsiveStyles.medium);
23
57
  }
24
58
  if ((_c = block.responsiveStyles) == null ? void 0 : _c.small) {
25
59
  Object.assign(styles, block.responsiveStyles.small);
26
60
  }
61
+ validateReactNativeStyles(styles);
27
62
  return styles;
28
63
  }
29
- export {
30
- getBlockStyles
31
- };
64
+ 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 };
@@ -5,60 +5,96 @@ 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, { enumerable: true, configurable: true, writable: true, value })
11
+ : (obj[key] = value);
9
12
  var __spreadValues = (a, b) => {
10
- for (var prop in b || (b = {}))
11
- if (__hasOwnProp.call(b, prop))
12
- __defNormalProp(a, prop, b[prop]);
13
+ for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
13
14
  if (__getOwnPropSymbols)
14
15
  for (var prop of __getOwnPropSymbols(b)) {
15
- if (__propIsEnum.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
16
+ if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
17
17
  }
18
18
  return a;
19
19
  };
20
20
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
21
  var __async = (__this, __arguments, generator) => {
22
22
  return new Promise((resolve, reject) => {
23
- var fulfilled = (value) => {
23
+ var fulfilled = value => {
24
24
  try {
25
25
  step(generator.next(value));
26
26
  } catch (e) {
27
27
  reject(e);
28
28
  }
29
29
  };
30
- var rejected = (value) => {
30
+ var rejected = value => {
31
31
  try {
32
32
  step(generator.throw(value));
33
33
  } catch (e) {
34
34
  reject(e);
35
35
  }
36
36
  };
37
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
+ var step = x =>
38
+ x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
38
39
  step((generator = generator.apply(__this, __arguments)).next());
39
40
  });
40
41
  };
41
- import { isBrowser } from "./is-browser";
42
- import { isReactNative } from "./is-react-native";
43
- if (!(isBrowser() || isReactNative())) {
44
- import("node-fetch");
42
+ import { getFetch } from './get-fetch';
43
+ const fetch = getFetch();
44
+ function flatten(object, path = null, separator = '.') {
45
+ return Object.keys(object).reduce((acc, key) => {
46
+ const value = object[key];
47
+ const newPath = [path, key].filter(Boolean).join(separator);
48
+ const isObject = [
49
+ typeof value === 'object',
50
+ value !== null,
51
+ !(Array.isArray(value) && value.length === 0),
52
+ ].every(Boolean);
53
+ return isObject
54
+ ? __spreadValues(__spreadValues({}, acc), flatten(value, newPath, separator))
55
+ : __spreadProps(__spreadValues({}, acc), { [newPath]: value });
56
+ }, {});
45
57
  }
46
58
  function getContent(options) {
47
59
  return __async(this, null, function* () {
48
- return (yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }))).results[0] || null;
60
+ return (
61
+ (yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }))).results[0] ||
62
+ null
63
+ );
49
64
  });
50
65
  }
51
66
  function getAllContent(options) {
52
67
  return __async(this, null, function* () {
53
68
  const { model, apiKey } = options;
54
- const { limit, testGroups, userAttributes } = __spreadValues({
55
- limit: 1,
56
- userAttributes: null,
57
- testGroups: null
58
- }, options);
59
- const content = yield fetch(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&userAttributes=${JSON.stringify(userAttributes)}`).then((res) => res.json());
69
+ const { limit, testGroups, userAttributes, query } = __spreadValues(
70
+ {
71
+ limit: 1,
72
+ userAttributes: null,
73
+ testGroups: null,
74
+ },
75
+ options
76
+ );
77
+ const url = new URL(
78
+ `https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}`
79
+ );
80
+ if (options.options) {
81
+ const flattened = flatten(options.options);
82
+ for (const key in flattened) {
83
+ url.searchParams.set(key, String(flattened[key]));
84
+ }
85
+ }
86
+ if (userAttributes) {
87
+ url.searchParams.set('userAttributes', JSON.stringify(userAttributes));
88
+ }
89
+ if (query) {
90
+ const flattened = flatten({ query });
91
+ for (const key in flattened) {
92
+ url.searchParams.set(key, JSON.stringify(flattened[key]));
93
+ }
94
+ }
95
+ const content = yield fetch(url.href).then(res => res.json());
60
96
  if (testGroups) {
61
- for (const item of content) {
97
+ for (const item of content.results) {
62
98
  if (item.variations && Object.keys(item.variations).length) {
63
99
  const testGroup = testGroups[item.id];
64
100
  const variationValue = item.variations[testGroup];
@@ -75,19 +111,20 @@ function getAllContent(options) {
75
111
  const testRatio = variation.testRatio;
76
112
  n += testRatio;
77
113
  if (random < n) {
78
- const variationName = variation.name || (variation.id === item.id ? "Default variation" : "");
114
+ const variationName =
115
+ variation.name || (variation.id === item.id ? 'Default variation' : '');
79
116
  set = true;
80
117
  Object.assign(item, {
81
118
  data: variation.data,
82
119
  testVariationId: variation.id,
83
- testVariationName: variationName
120
+ testVariationName: variationName,
84
121
  });
85
122
  }
86
123
  }
87
124
  if (!set) {
88
125
  Object.assign(item, {
89
126
  testVariationId: item.id,
90
- testVariationName: "Default"
127
+ testVariationName: 'Default',
91
128
  });
92
129
  }
93
130
  }
@@ -97,7 +134,4 @@ function getAllContent(options) {
97
134
  return content;
98
135
  });
99
136
  }
100
- export {
101
- getAllContent,
102
- getContent
103
- };
137
+ export { getAllContent, getContent };
@@ -0,0 +1,56 @@
1
+ import * as React from 'react';
2
+ var __async = (__this, __arguments, generator) => {
3
+ return new Promise((resolve, reject) => {
4
+ var fulfilled = value => {
5
+ try {
6
+ step(generator.next(value));
7
+ } catch (e) {
8
+ reject(e);
9
+ }
10
+ };
11
+ var rejected = value => {
12
+ try {
13
+ step(generator.throw(value));
14
+ } catch (e) {
15
+ reject(e);
16
+ }
17
+ };
18
+ var step = x =>
19
+ x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
20
+ step((generator = generator.apply(__this, __arguments)).next());
21
+ });
22
+ };
23
+ import fetchMock from 'jest-fetch-mock';
24
+ fetchMock.enableMocks();
25
+ import { test, beforeEach, expect } from '@jest/globals';
26
+ import { getContent } from './get-content';
27
+ const testKey = 'YJIGb4i01jvw0SRdL5Bt';
28
+ const testModel = 'page';
29
+ const testId = 'c1b81bab59704599b997574eb0736def';
30
+ beforeEach(() => {});
31
+ test.skip('Get content', () =>
32
+ __async(void 0, null, function* () {
33
+ var _a, _b;
34
+ expect(
35
+ (_a = yield getContent({
36
+ apiKey: testKey,
37
+ model: testModel,
38
+ query: {
39
+ id: testId,
40
+ },
41
+ })) == null
42
+ ? void 0
43
+ : _a.id
44
+ ).toEqual(testId);
45
+ expect(
46
+ (_b = yield getContent({
47
+ apiKey: testKey,
48
+ model: testModel,
49
+ userAttributes: {
50
+ urlPath: '/test-page',
51
+ },
52
+ })) == null
53
+ ? void 0
54
+ : _b.id
55
+ ).toEqual(testId);
56
+ }));
@@ -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,21 +5,21 @@ 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, { enumerable: true, configurable: true, writable: true, value })
11
+ : (obj[key] = value);
9
12
  var __spreadValues = (a, b) => {
10
- for (var prop in b || (b = {}))
11
- if (__hasOwnProp.call(b, prop))
12
- __defNormalProp(a, prop, b[prop]);
13
+ for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
13
14
  if (__getOwnPropSymbols)
14
15
  for (var prop of __getOwnPropSymbols(b)) {
15
- if (__propIsEnum.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
16
+ if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
17
17
  }
18
18
  return a;
19
19
  };
20
20
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
- import { evaluate } from "./evaluate";
22
- import { set } from "./set";
21
+ import { evaluate } from './evaluate';
22
+ import { set } from './set';
23
23
  function getProcessedBlock(options) {
24
24
  const { block, state, context } = options;
25
25
  if (!block.bindings) {
@@ -27,19 +27,17 @@ function getProcessedBlock(options) {
27
27
  }
28
28
  const copied = __spreadProps(__spreadValues({}, block), {
29
29
  properties: __spreadValues({}, block.properties),
30
- actions: __spreadValues({}, block.actions)
30
+ actions: __spreadValues({}, block.actions),
31
31
  });
32
32
  for (const binding in block.bindings) {
33
33
  const expression = block.bindings[binding];
34
34
  const value = evaluate({
35
35
  code: expression,
36
36
  state,
37
- context
37
+ context,
38
38
  });
39
39
  set(copied, binding, value);
40
40
  }
41
41
  return copied;
42
42
  }
43
- export {
44
- getProcessedBlock
45
- };
43
+ export { getProcessedBlock };
@@ -1,27 +1,27 @@
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
5
  const block = {
6
6
  properties: {
7
- foo: "bar"
7
+ foo: 'bar',
8
8
  },
9
9
  bindings: {
10
- "properties.foo": '"baz"',
11
- "responsiveStyles.large.zIndex": "1 + 1",
12
- "properties.test": "state.test",
13
- "properties.block": `
10
+ 'properties.foo': '"baz"',
11
+ 'responsiveStyles.large.zIndex': '1 + 1',
12
+ 'properties.test': 'state.test',
13
+ 'properties.block': `
14
14
  const foo = 'bar';
15
15
  return foo;
16
16
  `,
17
- "properties.isEditing": "builder.isEditing"
18
- }
17
+ 'properties.isEditing': 'builder.isEditing',
18
+ },
19
19
  };
20
- const processed = getProcessedBlock({ block, context: {}, state: { test: "hello" } });
20
+ const processed = getProcessedBlock({ block, context: {}, state: { test: 'hello' } });
21
21
  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");
22
+ expect(processed.properties.foo).toEqual('baz');
23
+ expect(processed.properties.test).toEqual('hello');
24
+ expect(processed.properties.block).toEqual('bar');
25
25
  expect(processed.properties.isEditing).toEqual(false);
26
26
  expect(processed.responsiveStyles.large.zIndex).toEqual(2);
27
27
  });
@@ -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,6 @@
1
1
  import * as React from 'react';
2
- import { isReactNative } from "./is-react-native";
2
+ import { isReactNative } from './is-react-native';
3
3
  function isBrowser() {
4
- return typeof window !== "undefined" && typeof document !== "undefined" && !isReactNative();
4
+ return typeof window !== 'undefined' && typeof document !== 'undefined' && !isReactNative();
5
5
  }
6
- export {
7
- isBrowser
8
- };
6
+ export { isBrowser };
@@ -1,8 +1,6 @@
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 isIframe() && window.location.search.indexOf('builder.frameEditing=') !== -1;
5
5
  }
6
- export {
7
- isEditing
8
- };
6
+ 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 typeof navigator === 'object' && navigator.product === 'ReactNative';
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 };
@@ -1,21 +1,21 @@
1
1
  import * as React from 'react';
2
- import { expect, test } from "@jest/globals";
3
- import { onChange } from "./on-change";
4
- test("onChange can observe a shallow change", () => {
2
+ import { expect, test } from '@jest/globals';
3
+ import { onChange } from './on-change';
4
+ test('onChange can observe a shallow change', () => {
5
5
  let changeHappend = false;
6
- const obj = onChange({ foo: "hi" }, () => changeHappend = true);
7
- obj.foo = "yo";
6
+ const obj = onChange({ foo: 'hi' }, () => (changeHappend = true));
7
+ obj.foo = 'yo';
8
8
  expect(changeHappend).toBe(true);
9
9
  });
10
- test("onChange can observe a deep change", () => {
10
+ test('onChange can observe a deep change', () => {
11
11
  let changeHappend = false;
12
- const obj = onChange({ foo: { bar: "hi" } }, () => changeHappend = true);
13
- obj.foo.bar = "yo";
12
+ const obj = onChange({ foo: { bar: 'hi' } }, () => (changeHappend = true));
13
+ obj.foo.bar = 'yo';
14
14
  expect(changeHappend).toBe(true);
15
15
  });
16
- test("Smoke test: callback is not fired if no properties updated", () => {
16
+ test('Smoke test: callback is not fired if no properties updated', () => {
17
17
  let changeHappend = false;
18
- const obj = onChange({ foo: { bar: "hi" } }, () => changeHappend = true);
18
+ const obj = onChange({ foo: { bar: 'hi' } }, () => (changeHappend = true));
19
19
  obj.foo.bar;
20
20
  expect(changeHappend).toBe(false);
21
21
  });
@@ -0,0 +1,10 @@
1
+ import * as React from 'react';
2
+ import { isPreviewing } from './is-previewing';
3
+ function previewingModelName() {
4
+ if (!isPreviewing()) {
5
+ return null;
6
+ }
7
+ const url = new URL(location.href);
8
+ return url.searchParams.get('builder.preview');
9
+ }
10
+ export { previewingModelName };