@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,139 @@
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 { getFetch } from "../get-fetch.js";
42
+ const fetch$ = getFetch();
43
+ function flatten(object, path = null, separator = ".") {
44
+ return Object.keys(object).reduce((acc, key) => {
45
+ const value = object[key];
46
+ const newPath = [path, key].filter(Boolean).join(separator);
47
+ const isObject = [
48
+ typeof value === "object",
49
+ value !== null,
50
+ !(Array.isArray(value) && value.length === 0)
51
+ ].every(Boolean);
52
+ return isObject ? __spreadValues(__spreadValues({}, acc), flatten(value, newPath, separator)) : __spreadProps(__spreadValues({}, acc), { [newPath]: value });
53
+ }, {});
54
+ }
55
+ function getContent(options) {
56
+ return __async(this, null, function* () {
57
+ return (yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }))).results[0] || null;
58
+ });
59
+ }
60
+ const generateContentUrl = (options) => {
61
+ const {
62
+ limit = 1,
63
+ userAttributes,
64
+ query,
65
+ noTraverse = false,
66
+ model,
67
+ apiKey
68
+ } = options;
69
+ const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}`);
70
+ if (options.options) {
71
+ const flattened = flatten(options.options);
72
+ for (const key in flattened) {
73
+ url.searchParams.set(key, String(flattened[key]));
74
+ }
75
+ }
76
+ if (userAttributes) {
77
+ url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
78
+ }
79
+ if (query) {
80
+ const flattened = flatten({ query });
81
+ for (const key in flattened) {
82
+ url.searchParams.set(key, JSON.stringify(flattened[key]));
83
+ }
84
+ }
85
+ return url;
86
+ };
87
+ const handleABTesting = (content, testGroups) => {
88
+ for (const item of content.results) {
89
+ if (item.variations && Object.keys(item.variations).length) {
90
+ const testGroup = testGroups[item.id];
91
+ const variationValue = item.variations[testGroup];
92
+ if (testGroup && variationValue) {
93
+ item.data = variationValue.data;
94
+ item.testVariationId = variationValue.id;
95
+ item.testVariationName = variationValue.name;
96
+ } else {
97
+ let n = 0;
98
+ const random = Math.random();
99
+ let set = false;
100
+ for (const id in item.variations) {
101
+ const variation = item.variations[id];
102
+ const testRatio = variation.testRatio;
103
+ n += testRatio;
104
+ if (random < n) {
105
+ const variationName = variation.name || (variation.id === item.id ? "Default variation" : "");
106
+ set = true;
107
+ Object.assign(item, {
108
+ data: variation.data,
109
+ testVariationId: variation.id,
110
+ testVariationName: variationName
111
+ });
112
+ }
113
+ }
114
+ if (!set) {
115
+ Object.assign(item, {
116
+ testVariationId: item.id,
117
+ testVariationName: "Default"
118
+ });
119
+ }
120
+ }
121
+ }
122
+ }
123
+ };
124
+ function getAllContent(options) {
125
+ return __async(this, null, function* () {
126
+ const url = generateContentUrl(options);
127
+ const fetch = yield fetch$;
128
+ const content = yield fetch(url.href).then((res) => res.json());
129
+ if (options.testGroups) {
130
+ handleABTesting(content, options.testGroups);
131
+ }
132
+ return content;
133
+ });
134
+ }
135
+ export {
136
+ generateContentUrl,
137
+ getAllContent,
138
+ getContent
139
+ };
@@ -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,26 +18,43 @@ 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
+ import { fastClone } from "./fast-clone.js";
34
+ const components = [];
23
35
  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
- }
36
+ components.push(__spreadValues({ component }, info));
37
+ console.warn("registerComponent is deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.");
38
+ return component;
33
39
  }
40
+ const createRegisterComponentMessage = (_a) => {
41
+ var _b = _a, {
42
+ component
43
+ } = _b, info = __objRest(_b, [
44
+ "component"
45
+ ]);
46
+ return {
47
+ type: "builder.registerComponent",
48
+ data: prepareComponentInfoToSend(fastClone(info))
49
+ };
50
+ };
34
51
  function prepareComponentInfoToSend(info) {
35
52
  return __spreadValues(__spreadValues({}, info), info.inputs && {
36
53
  inputs: info.inputs.map((input) => {
37
54
  const keysToConvertFnToString = ["onChange", "showIf"];
38
55
  for (const key of keysToConvertFnToString) {
39
- if (input[key] && typeof input[key] === "function") {
40
- const fn = input[key];
56
+ const fn = input[key];
57
+ if (fn && typeof fn === "function") {
41
58
  input = __spreadProps(__spreadValues({}, input), {
42
59
  [key]: `return (${fn.toString()}).apply(this, arguments)`
43
60
  });
@@ -49,5 +66,6 @@ function prepareComponentInfoToSend(info) {
49
66
  }
50
67
  export {
51
68
  components,
69
+ createRegisterComponentMessage,
52
70
  registerComponent
53
71
  };
@@ -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
+ };
@@ -0,0 +1,19 @@
1
+ import * as React from 'react';
2
+ import { default as default2 } from "../blocks/columns/columns.js";
3
+ import { default as default3 } from "../blocks/image/image.js";
4
+ import { default as default4 } from "../blocks/text/text.js";
5
+ import { default as default5 } from "../blocks/symbol/symbol.js";
6
+ import { default as default6 } from "../blocks/button/button.js";
7
+ import { default as default7 } from "../blocks/section/section.js";
8
+ import { default as default8 } from "../blocks/fragment/fragment.js";
9
+ import { default as default9 } from "../components/render-content/render-content.js";
10
+ export {
11
+ default6 as Button,
12
+ default2 as Columns,
13
+ default8 as Fragment,
14
+ default3 as Image,
15
+ default9 as RenderContent,
16
+ default7 as Section,
17
+ default5 as Symbol,
18
+ default4 as Text
19
+ };
@@ -0,0 +1,2 @@
1
+ import * as React from 'react';
2
+ import "react-native-url-polyfill/auto";
package/src/index.js CHANGED
@@ -1,24 +1,11 @@
1
1
  import * as React from 'react';
2
- import { isEditing } from "./functions/is-editing";
3
- if (isEditing()) {
4
- import("./scripts/init-editing");
5
- }
6
- import { default as default2 } from "./blocks/columns";
7
- import { default as default3 } from "./blocks/image";
8
- import { default as default4 } from "./blocks/text";
9
- import { default as default5 } from "./blocks/video";
10
- import { default as default6 } from "./blocks/symbol";
11
- import { default as default7 } from "./blocks/button";
12
- import { default as default8 } from "./blocks/section";
13
- import { default as default9 } from "./components/render-content";
14
- export * from "./functions/register-component";
15
- export {
16
- default7 as Button,
17
- default2 as Columns,
18
- default3 as Image,
19
- default9 as RenderContent,
20
- default8 as Section,
21
- default6 as Symbol,
22
- default4 as Text,
23
- default5 as Video
24
- };
2
+ import "./index-helpers/top-of-file.js";
3
+ import "./scripts/init-editing.js";
4
+ export * from "./index-helpers/blocks-exports.js";
5
+ export * from "./functions/is-editing.js";
6
+ export * from "./functions/is-previewing.js";
7
+ export * from "./functions/register-component.js";
8
+ export * from "./functions/register.js";
9
+ export * from "./functions/set-editor-settings.js";
10
+ export * from "./functions/get-content/index.js";
11
+ export * from "./functions/get-builder-search-params/index.js";