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

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 (138) 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 +242 -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 +44 -0
  11. package/src/blocks/embed/embed.js +43 -0
  12. package/src/blocks/embed/helpers.js +10 -0
  13. package/src/blocks/form/component-info.js +263 -0
  14. package/src/blocks/form/form.js +221 -0
  15. package/src/blocks/fragment/component-info.js +12 -0
  16. package/src/blocks/fragment/fragment.js +8 -0
  17. package/src/blocks/image/component-info.js +151 -0
  18. package/src/blocks/image/image.helpers.js +49 -0
  19. package/src/blocks/image/image.js +41 -0
  20. package/src/blocks/img/component-info.js +21 -0
  21. package/src/blocks/img/img.js +36 -0
  22. package/src/blocks/input/component-info.js +75 -0
  23. package/src/blocks/input/input.js +36 -0
  24. package/src/blocks/raw-text/component-info.js +17 -0
  25. package/src/blocks/raw-text/raw-text.js +10 -0
  26. package/src/blocks/section/component-info.js +50 -0
  27. package/src/blocks/section/section.js +31 -0
  28. package/src/blocks/select/component-info.js +60 -0
  29. package/src/blocks/select/select.js +36 -0
  30. package/src/blocks/submit-button/component-info.js +29 -0
  31. package/src/blocks/submit-button/submit-button.js +29 -0
  32. package/src/blocks/symbol/component-info.js +44 -0
  33. package/src/blocks/symbol/symbol.js +69 -0
  34. package/src/blocks/{text.js → text/component-info.js} +4 -10
  35. package/src/blocks/text/text.js +65 -0
  36. package/src/blocks/textarea/component-info.js +48 -0
  37. package/src/blocks/textarea/textarea.js +32 -0
  38. package/src/blocks/video/component-info.js +107 -0
  39. package/src/blocks/video/video.js +33 -0
  40. package/src/components/render-block/block-styles.js +40 -0
  41. package/src/components/render-block/render-block.helpers.js +24 -0
  42. package/src/components/render-block/render-block.js +169 -0
  43. package/src/components/render-block/render-component.js +33 -0
  44. package/src/components/render-block/render-repeated-block.js +29 -0
  45. package/src/components/render-blocks.js +23 -12
  46. package/src/components/render-content/components/render-styles.js +58 -0
  47. package/src/components/render-content/index.js +5 -0
  48. package/src/components/render-content/render-content.js +254 -0
  49. package/src/components/render-inlined-styles.js +18 -0
  50. package/src/constants/builder-registered-components.js +43 -0
  51. package/src/constants/device-sizes.js +3 -21
  52. package/src/constants/target.js +5 -0
  53. package/src/context/builder.context.js +7 -1
  54. package/src/functions/camel-to-kebab-case.js +5 -0
  55. package/src/functions/convert-style-object.js +7 -0
  56. package/src/functions/evaluate.js +17 -8
  57. package/src/functions/event-handler-name.js +8 -0
  58. package/src/functions/get-block-actions.js +14 -13
  59. package/src/functions/get-block-component-options.js +22 -1
  60. package/src/functions/get-block-properties.js +2 -3
  61. package/src/functions/get-block-styles.js +9 -19
  62. package/src/functions/get-block-tag.js +1 -1
  63. package/src/functions/get-builder-search-params/fn.test.js +14 -0
  64. package/src/functions/get-builder-search-params/index.js +23 -0
  65. package/src/functions/get-content/ab-testing.js +39 -0
  66. package/src/functions/get-content/fn.test.js +32 -0
  67. package/src/functions/get-content/index.js +94 -0
  68. package/src/functions/get-content/types.js +1 -0
  69. package/src/functions/get-fetch.js +35 -0
  70. package/src/functions/get-global-this.js +19 -0
  71. package/src/functions/get-processed-block.js +18 -9
  72. package/src/functions/get-processed-block.test.js +14 -8
  73. package/src/functions/if-target.js +11 -2
  74. package/src/functions/is-browser.js +1 -2
  75. package/src/functions/is-editing.js +1 -1
  76. package/src/functions/is-iframe.js +1 -1
  77. package/src/functions/is-previewing.js +15 -0
  78. package/src/functions/is-react-native.js +1 -1
  79. package/src/functions/on-change.test.js +1 -2
  80. package/src/functions/previewing-model-name.js +12 -0
  81. package/src/functions/register-component.js +46 -26
  82. package/src/functions/register.js +30 -0
  83. package/src/functions/sanitize-styles.js +33 -0
  84. package/src/functions/set-editor-settings.js +16 -0
  85. package/src/functions/set.test.js +1 -2
  86. package/src/functions/track.js +7 -3
  87. package/src/functions/transform-block.js +38 -0
  88. package/src/helpers/css.js +13 -0
  89. package/src/helpers/flatten.js +35 -0
  90. package/src/index-helpers/blocks-exports.js +19 -0
  91. package/src/index-helpers/top-of-file.js +2 -0
  92. package/src/index.js +10 -23
  93. package/src/scripts/init-editing.js +73 -49
  94. package/src/types/components.js +1 -0
  95. package/src/types/deep-partial.js +1 -0
  96. package/src/types/element.js +1 -0
  97. package/src/types/targets.js +1 -0
  98. package/src/types/typescript.js +1 -0
  99. package/index.js +0 -11
  100. package/src/blocks/button.js +0 -37
  101. package/src/blocks/button.lite.tsx +0 -29
  102. package/src/blocks/columns.js +0 -42
  103. package/src/blocks/columns.lite.tsx +0 -41
  104. package/src/blocks/custom-code.js +0 -56
  105. package/src/blocks/embed.js +0 -56
  106. package/src/blocks/embed.lite.tsx +0 -65
  107. package/src/blocks/form.js +0 -229
  108. package/src/blocks/form.lite.tsx +0 -257
  109. package/src/blocks/image.js +0 -123
  110. package/src/blocks/image.lite.tsx +0 -35
  111. package/src/blocks/img.js +0 -41
  112. package/src/blocks/img.lite.tsx +0 -19
  113. package/src/blocks/input.js +0 -41
  114. package/src/blocks/input.lite.tsx +0 -23
  115. package/src/blocks/raw-text.js +0 -17
  116. package/src/blocks/raw-text.lite.tsx +0 -12
  117. package/src/blocks/section.js +0 -36
  118. package/src/blocks/section.lite.tsx +0 -20
  119. package/src/blocks/select.js +0 -40
  120. package/src/blocks/select.lite.tsx +0 -24
  121. package/src/blocks/submit-button.js +0 -34
  122. package/src/blocks/submit-button.lite.tsx +0 -11
  123. package/src/blocks/symbol.js +0 -20
  124. package/src/blocks/symbol.lite.tsx +0 -20
  125. package/src/blocks/text.lite.tsx +0 -12
  126. package/src/blocks/textarea.js +0 -37
  127. package/src/blocks/textarea.lite.tsx +0 -15
  128. package/src/blocks/video.js +0 -49
  129. package/src/blocks/video.lite.tsx +0 -28
  130. package/src/components/render-block.js +0 -84
  131. package/src/components/render-block.lite.tsx +0 -92
  132. package/src/components/render-blocks.lite.tsx +0 -56
  133. package/src/components/render-content.js +0 -66
  134. package/src/components/render-content.lite.tsx +0 -95
  135. package/src/functions/get-content.js +0 -103
  136. package/src/functions/get-target.js +0 -7
  137. package/src/functions/macro-eval.js +0 -6
  138. package/src/package.json +0 -18
@@ -0,0 +1,39 @@
1
+ import * as React from 'react';
2
+ const handleABTesting = (item, testGroups) => {
3
+ if (item.variations && Object.keys(item.variations).length) {
4
+ const testGroup = item.id ? testGroups[item.id] : void 0;
5
+ const variationValue = testGroup ? item.variations[testGroup] : void 0;
6
+ if (testGroup && variationValue) {
7
+ item.data = variationValue.data;
8
+ item.testVariationId = variationValue.id;
9
+ item.testVariationName = variationValue.name;
10
+ } else {
11
+ let n = 0;
12
+ const random = Math.random();
13
+ let set = false;
14
+ for (const id in item.variations) {
15
+ const variation = item.variations[id];
16
+ const testRatio = variation.testRatio;
17
+ n += testRatio;
18
+ if (random < n) {
19
+ const variationName = variation.name || (variation.id === item.id ? "Default variation" : "");
20
+ set = true;
21
+ Object.assign(item, {
22
+ data: variation.data,
23
+ testVariationId: variation.id,
24
+ testVariationName: variationName
25
+ });
26
+ }
27
+ }
28
+ if (!set) {
29
+ Object.assign(item, {
30
+ testVariationId: item.id,
31
+ testVariationName: "Default"
32
+ });
33
+ }
34
+ }
35
+ }
36
+ };
37
+ export {
38
+ handleABTesting
39
+ };
@@ -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
+ });
@@ -0,0 +1,94 @@
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));
21
+ var __async = (__this, __arguments, generator) => {
22
+ return new Promise((resolve, reject) => {
23
+ var fulfilled = (value) => {
24
+ try {
25
+ step(generator.next(value));
26
+ } catch (e) {
27
+ reject(e);
28
+ }
29
+ };
30
+ var rejected = (value) => {
31
+ try {
32
+ step(generator.throw(value));
33
+ } catch (e) {
34
+ reject(e);
35
+ }
36
+ };
37
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
38
+ step((generator = generator.apply(__this, __arguments)).next());
39
+ });
40
+ };
41
+ import { flatten } from "../../helpers/flatten.js";
42
+ import { getFetch } from "../get-fetch.js";
43
+ import { handleABTesting } from "./ab-testing.js";
44
+ const fetch$ = getFetch();
45
+ function getContent(options) {
46
+ return __async(this, null, function* () {
47
+ return (yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }))).results[0] || null;
48
+ });
49
+ }
50
+ const generateContentUrl = (options) => {
51
+ const {
52
+ limit = 1,
53
+ userAttributes,
54
+ query,
55
+ noTraverse = false,
56
+ model,
57
+ apiKey
58
+ } = options;
59
+ const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}`);
60
+ if (options.options) {
61
+ const flattened = flatten(options.options);
62
+ for (const key in flattened) {
63
+ url.searchParams.set(key, String(flattened[key]));
64
+ }
65
+ }
66
+ if (userAttributes) {
67
+ url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
68
+ }
69
+ if (query) {
70
+ const flattened = flatten({ query });
71
+ for (const key in flattened) {
72
+ url.searchParams.set(key, JSON.stringify(flattened[key]));
73
+ }
74
+ }
75
+ return url;
76
+ };
77
+ function getAllContent(options) {
78
+ return __async(this, null, function* () {
79
+ const url = generateContentUrl(options);
80
+ const fetch = yield fetch$;
81
+ const content = yield fetch(url.href).then((res) => res.json());
82
+ if (options.testGroups) {
83
+ for (const item of content.results) {
84
+ handleABTesting(item, options.testGroups);
85
+ }
86
+ }
87
+ return content;
88
+ });
89
+ }
90
+ export {
91
+ generateContentUrl,
92
+ getAllContent,
93
+ getContent
94
+ };
@@ -0,0 +1 @@
1
+ import * as React from 'react';
@@ -0,0 +1,35 @@
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) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
19
+ step((generator = generator.apply(__this, __arguments)).next());
20
+ });
21
+ };
22
+ import { getGlobalThis } from "./get-global-this.js";
23
+ function getFetch() {
24
+ return __async(this, null, function* () {
25
+ const globalFetch = getGlobalThis().fetch;
26
+ if (typeof globalFetch === "undefined" && typeof global !== "undefined") {
27
+ const nodeFetch = import("node-fetch").then((d) => d.default);
28
+ return nodeFetch;
29
+ }
30
+ return globalFetch;
31
+ });
32
+ }
33
+ export {
34
+ getFetch
35
+ };
@@ -0,0 +1,19 @@
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 {
18
+ getGlobalThis
19
+ };
@@ -18,10 +18,14 @@ var __spreadValues = (a, b) => {
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";
23
- function getProcessedBlock(options) {
24
- const { block, state, context } = options;
21
+ import { evaluate } from "./evaluate.js";
22
+ import { set } from "./set.js";
23
+ import { transformBlock } from "./transform-block.js";
24
+ const evaluateBindings = ({
25
+ block,
26
+ context,
27
+ state
28
+ }) => {
25
29
  if (!block.bindings) {
26
30
  return block;
27
31
  }
@@ -31,14 +35,19 @@ function getProcessedBlock(options) {
31
35
  });
32
36
  for (const binding in block.bindings) {
33
37
  const expression = block.bindings[binding];
34
- const value = evaluate({
35
- code: expression,
36
- state,
37
- context
38
- });
38
+ const value = evaluate({ code: expression, state, context });
39
39
  set(copied, binding, value);
40
40
  }
41
41
  return copied;
42
+ };
43
+ function getProcessedBlock(options) {
44
+ const { state, context } = options;
45
+ const block = transformBlock(options.block);
46
+ if (evaluateBindings) {
47
+ return evaluateBindings({ block, state, context });
48
+ } else {
49
+ return block;
50
+ }
42
51
  }
43
52
  export {
44
53
  getProcessedBlock
@@ -1,8 +1,9 @@
1
1
  import * as React from 'react';
2
- import { expect, test } from "@jest/globals";
3
- import { getProcessedBlock } from "./get-processed-block";
2
+ import { getProcessedBlock } from "./get-processed-block.js";
4
3
  test("Can process bindings", () => {
4
+ var _a, _b, _c, _d, _e, _f;
5
5
  const block = {
6
+ "@type": "@builder.io/sdk:Element",
6
7
  properties: {
7
8
  foo: "bar"
8
9
  },
@@ -17,11 +18,16 @@ test("Can process bindings", () => {
17
18
  "properties.isEditing": "builder.isEditing"
18
19
  }
19
20
  };
20
- const processed = getProcessedBlock({ block, context: {}, state: { test: "hello" } });
21
+ const processed = getProcessedBlock({
22
+ block,
23
+ context: {},
24
+ state: { test: "hello" },
25
+ evaluateBindings: true
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("hello");
30
+ expect((_c = processed.properties) == null ? void 0 : _c.block).toEqual("bar");
31
+ expect((_d = processed.properties) == null ? void 0 : _d.isEditing).toEqual(false);
32
+ expect((_f = (_e = processed.responsiveStyles) == null ? void 0 : _e.large) == null ? void 0 : _f.zIndex).toEqual(2);
27
33
  });
@@ -1,6 +1,15 @@
1
1
  import * as React from 'react';
2
- function ifTarget(target, doThing, elseThing) {
3
- return doThing();
2
+ import { TARGET } from "../constants/target.js";
3
+ function ifTarget({
4
+ targets,
5
+ doThing,
6
+ elseThing
7
+ }) {
8
+ if (TARGET && targets.includes(TARGET)) {
9
+ return doThing();
10
+ } else {
11
+ return elseThing == null ? void 0 : elseThing();
12
+ }
4
13
  }
5
14
  export {
6
15
  ifTarget
@@ -1,7 +1,6 @@
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
5
  export {
7
6
  isBrowser
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { isIframe } from "./is-iframe";
2
+ import { isIframe } from "./is-iframe.js";
3
3
  function isEditing() {
4
4
  return isIframe() && window.location.search.indexOf("builder.frameEditing=") !== -1;
5
5
  }
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { isBrowser } from "./is-browser";
2
+ import { isBrowser } from "./is-browser.js";
3
3
  function isIframe() {
4
4
  return isBrowser() && window.self !== window.top;
5
5
  }
@@ -0,0 +1,15 @@
1
+ import * as React from 'react';
2
+ import { isBrowser } from "./is-browser.js";
3
+ import { isEditing } from "./is-editing.js";
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 {
14
+ isPreviewing
15
+ };
@@ -1,6 +1,6 @@
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
5
  export {
6
6
  isReactNative
@@ -1,6 +1,5 @@
1
1
  import * as React from 'react';
2
- import { expect, test } from "@jest/globals";
3
- import { onChange } from "./on-change";
2
+ import { onChange } from "./on-change.js";
4
3
  test("onChange can observe a shallow change", () => {
5
4
  let changeHappend = false;
6
5
  const obj = onChange({ foo: "hi" }, () => changeHappend = true);
@@ -0,0 +1,12 @@
1
+ import * as React from 'react';
2
+ import { isPreviewing } from "./is-previewing.js";
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 {
11
+ previewingModelName
12
+ };
@@ -18,36 +18,56 @@ var __spreadValues = (a, b) => {
18
18
  return a;
19
19
  };
20
20
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
- import { isBrowser } from "./is-browser";
22
- const components = {};
21
+ var __objRest = (source, exclude) => {
22
+ var target = {};
23
+ for (var prop in source)
24
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
25
+ target[prop] = source[prop];
26
+ if (source != null && __getOwnPropSymbols)
27
+ for (var prop of __getOwnPropSymbols(source)) {
28
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
29
+ target[prop] = source[prop];
30
+ }
31
+ return target;
32
+ };
33
+ const components = [];
23
34
  function registerComponent(component, info) {
24
- var _a;
25
- components[info.name] = { component, info };
26
- if (isBrowser()) {
27
- const sendInfo = prepareComponentInfoToSend(info);
28
- (_a = window.parent) == null ? void 0 : _a.postMessage({
29
- type: "builder.registerComponent",
30
- data: sendInfo
31
- }, "*");
32
- }
35
+ components.push(__spreadValues({ component }, info));
36
+ console.warn("registerComponent is deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.");
37
+ return component;
33
38
  }
34
- function prepareComponentInfoToSend(info) {
35
- return __spreadValues(__spreadValues({}, info), info.inputs && {
36
- inputs: info.inputs.map((input) => {
37
- const keysToConvertFnToString = ["onChange", "showIf"];
38
- for (const key of keysToConvertFnToString) {
39
- if (input[key] && typeof input[key] === "function") {
40
- const fn = input[key];
41
- input = __spreadProps(__spreadValues({}, input), {
42
- [key]: `return (${fn.toString()}).apply(this, arguments)`
43
- });
44
- }
45
- }
46
- return input;
47
- })
39
+ const createRegisterComponentMessage = (_a) => {
40
+ var _b = _a, {
41
+ component: _
42
+ } = _b, info = __objRest(_b, [
43
+ "component"
44
+ ]);
45
+ return {
46
+ type: "builder.registerComponent",
47
+ data: prepareComponentInfoToSend(info)
48
+ };
49
+ };
50
+ const fastClone = (obj) => JSON.parse(JSON.stringify(obj));
51
+ const serializeValue = (value) => typeof value === "function" ? serializeFn(value) : fastClone(value);
52
+ const serializeFn = (fnValue) => {
53
+ const fnStr = fnValue.toString().trim();
54
+ const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(");
55
+ return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
56
+ };
57
+ const prepareComponentInfoToSend = (_c) => {
58
+ var _d = _c, {
59
+ inputs
60
+ } = _d, info = __objRest(_d, [
61
+ "inputs"
62
+ ]);
63
+ return __spreadProps(__spreadValues({}, fastClone(info)), {
64
+ inputs: inputs == null ? void 0 : inputs.map((input) => Object.entries(input).reduce((acc, [key, value]) => __spreadProps(__spreadValues({}, acc), {
65
+ [key]: serializeValue(value)
66
+ }), {}))
48
67
  });
49
- }
68
+ };
50
69
  export {
51
70
  components,
71
+ createRegisterComponentMessage,
52
72
  registerComponent
53
73
  };
@@ -0,0 +1,30 @@
1
+ import * as React from 'react';
2
+ import { isBrowser } from "./is-browser.js";
3
+ const registry = {};
4
+ function register(type, info) {
5
+ let typeList = registry[type];
6
+ if (!typeList) {
7
+ typeList = registry[type] = [];
8
+ }
9
+ typeList.push(info);
10
+ if (isBrowser()) {
11
+ const message = {
12
+ type: "builder.register",
13
+ data: {
14
+ type,
15
+ info
16
+ }
17
+ };
18
+ try {
19
+ parent.postMessage(message, "*");
20
+ if (parent !== window) {
21
+ window.postMessage(message, "*");
22
+ }
23
+ } catch (err) {
24
+ console.debug("Could not postmessage", err);
25
+ }
26
+ }
27
+ }
28
+ export {
29
+ register
30
+ };
@@ -0,0 +1,33 @@
1
+ import * as React from 'react';
2
+ const propertiesThatMustBeNumber = new Set(["lineHeight"]);
3
+ const displayValues = new Set(["flex", "none"]);
4
+ const SHOW_WARNINGS = false;
5
+ const sanitizeBlockStyles = (styles) => {
6
+ for (const key in styles) {
7
+ const propertyValue = styles[key];
8
+ if (key === "display" && !displayValues.has(propertyValue)) {
9
+ if (SHOW_WARNINGS) {
10
+ console.warn(`Style value for key "display" must be "flex" or "none" but had ${propertyValue}`);
11
+ }
12
+ delete styles[key];
13
+ }
14
+ if (typeof propertyValue === "string" && propertyValue.match(/^-?\d/)) {
15
+ const newValue = parseFloat(propertyValue);
16
+ if (!isNaN(newValue)) {
17
+ styles[key] = newValue;
18
+ }
19
+ if (typeof newValue === "number" && newValue < 0) {
20
+ styles[key] = 0;
21
+ }
22
+ }
23
+ if (propertiesThatMustBeNumber.has(key) && typeof styles[key] !== "number") {
24
+ if (SHOW_WARNINGS) {
25
+ console.warn(`Style key ${key} must be a number, but had value \`${styles[key]}\``);
26
+ }
27
+ delete styles[key];
28
+ }
29
+ }
30
+ };
31
+ export {
32
+ sanitizeBlockStyles
33
+ };
@@ -0,0 +1,16 @@
1
+ import * as React from 'react';
2
+ import { isBrowser } from "./is-browser.js";
3
+ const settings = {};
4
+ function setEditorSettings(newSettings) {
5
+ if (isBrowser()) {
6
+ Object.assign(settings, newSettings);
7
+ const message = {
8
+ type: "builder.settingsChange",
9
+ data: settings
10
+ };
11
+ parent.postMessage(message, "*");
12
+ }
13
+ }
14
+ export {
15
+ setEditorSettings
16
+ };
@@ -1,6 +1,5 @@
1
1
  import * as React from 'react';
2
- import { expect, test } from "@jest/globals";
3
- import { set } from "./set";
2
+ import { set } from "./set.js";
4
3
  test("can shallow set a property", () => {
5
4
  const obj = { foo: "bar" };
6
5
  set(obj, "foo", "baz");
@@ -1,8 +1,12 @@
1
1
  import * as React from 'react';
2
- import { isBrowser } from "./is-browser";
3
- import { isReactNative } from "./is-react-native";
2
+ import { TARGET } from "../constants/target.js";
3
+ import { isBrowser } from "./is-browser.js";
4
+ import { isEditing } from "./is-editing.js";
4
5
  function track(event, properties) {
5
- if (!isBrowser() || isReactNative()) {
6
+ if (isEditing()) {
7
+ return;
8
+ }
9
+ if (!(isBrowser() || TARGET === "reactNative")) {
6
10
  return;
7
11
  }
8
12
  return fetch(`https://builder.io/api/v1/track`, {
@@ -0,0 +1,38 @@
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));
21
+ function transformBlock(block) {
22
+ if (block.id.startsWith("builder-pixel-") && !block.component) {
23
+ return __spreadProps(__spreadValues({}, block), {
24
+ component: {
25
+ name: "Image",
26
+ options: {
27
+ image: block.properties.src,
28
+ width: 1,
29
+ height: 1
30
+ }
31
+ }
32
+ });
33
+ }
34
+ return block;
35
+ }
36
+ export {
37
+ transformBlock
38
+ };
@@ -0,0 +1,13 @@
1
+ import * as React from 'react';
2
+ import { camelToKebabCase } from "../functions/camel-to-kebab-case";
3
+ const convertStyleMaptoCSS = (style) => {
4
+ const cssProps = Object.entries(style).map(([key, value]) => {
5
+ if (typeof value === "string") {
6
+ return `${camelToKebabCase(key)}: ${value};`;
7
+ }
8
+ });
9
+ return cssProps.join("\n");
10
+ };
11
+ export {
12
+ convertStyleMaptoCSS
13
+ };