@builder.io/react 3.0.0 → 3.0.2-0

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 (156) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/dist/builder-react-lite.cjs.js +1 -1
  3. package/dist/builder-react-lite.cjs.js.map +1 -1
  4. package/dist/builder-react-lite.esm.js +1 -1
  5. package/dist/builder-react-lite.esm.js.map +1 -1
  6. package/dist/builder-react.browser.js +1 -1
  7. package/dist/builder-react.browser.js.map +1 -1
  8. package/dist/builder-react.cjs.js +1 -1
  9. package/dist/builder-react.cjs.js.map +1 -1
  10. package/dist/builder-react.unpkg.js +1 -1
  11. package/dist/builder-react.unpkg.js.map +1 -1
  12. package/dist/lib/package.json +3 -3
  13. package/dist/lib/rollup.config.js +23 -29
  14. package/dist/lib/rollup.config.js.map +1 -1
  15. package/dist/lib/src/blocks/Button.js +8 -13
  16. package/dist/lib/src/blocks/Button.js.map +1 -1
  17. package/dist/lib/src/blocks/Columns.js +15 -21
  18. package/dist/lib/src/blocks/Columns.js.map +1 -1
  19. package/dist/lib/src/blocks/CustomCode.js +14 -19
  20. package/dist/lib/src/blocks/CustomCode.js.map +1 -1
  21. package/dist/lib/src/blocks/Embed.js +8 -13
  22. package/dist/lib/src/blocks/Embed.js.map +1 -1
  23. package/dist/lib/src/blocks/Fragment.js +7 -12
  24. package/dist/lib/src/blocks/Fragment.js.map +1 -1
  25. package/dist/lib/src/blocks/Image.js +30 -39
  26. package/dist/lib/src/blocks/Image.js.map +1 -1
  27. package/dist/lib/src/blocks/Mutation.js +10 -17
  28. package/dist/lib/src/blocks/Mutation.js.map +1 -1
  29. package/dist/lib/src/blocks/Router.js +18 -24
  30. package/dist/lib/src/blocks/Router.js.map +1 -1
  31. package/dist/lib/src/blocks/Section.js +9 -15
  32. package/dist/lib/src/blocks/Section.js.map +1 -1
  33. package/dist/lib/src/blocks/Slot.js +10 -14
  34. package/dist/lib/src/blocks/Slot.js.map +1 -1
  35. package/dist/lib/src/blocks/StateProvider.js +9 -14
  36. package/dist/lib/src/blocks/StateProvider.js.map +1 -1
  37. package/dist/lib/src/blocks/Symbol.js +21 -27
  38. package/dist/lib/src/blocks/Symbol.js.map +1 -1
  39. package/dist/lib/src/blocks/Text.js +14 -20
  40. package/dist/lib/src/blocks/Text.js.map +1 -1
  41. package/dist/lib/src/blocks/Video.js +15 -21
  42. package/dist/lib/src/blocks/Video.js.map +1 -1
  43. package/dist/lib/src/blocks/forms/Button.js +6 -11
  44. package/dist/lib/src/blocks/forms/Button.js.map +1 -1
  45. package/dist/lib/src/blocks/forms/Form.js +22 -28
  46. package/dist/lib/src/blocks/forms/Form.js.map +1 -1
  47. package/dist/lib/src/blocks/forms/Input.js +7 -12
  48. package/dist/lib/src/blocks/forms/Input.js.map +1 -1
  49. package/dist/lib/src/blocks/forms/Label.js +9 -14
  50. package/dist/lib/src/blocks/forms/Label.js.map +1 -1
  51. package/dist/lib/src/blocks/forms/Select.js +8 -13
  52. package/dist/lib/src/blocks/forms/Select.js.map +1 -1
  53. package/dist/lib/src/blocks/forms/TextArea.js +6 -11
  54. package/dist/lib/src/blocks/forms/TextArea.js.map +1 -1
  55. package/dist/lib/src/blocks/raw/Img.js +6 -11
  56. package/dist/lib/src/blocks/raw/Img.js.map +1 -1
  57. package/dist/lib/src/blocks/raw/RawText.js +5 -31
  58. package/dist/lib/src/blocks/raw/RawText.js.map +1 -1
  59. package/dist/lib/src/builder-react-lite.js +17 -30
  60. package/dist/lib/src/builder-react-lite.js.map +1 -1
  61. package/dist/lib/src/builder-react.js +44 -98
  62. package/dist/lib/src/builder-react.js.map +1 -1
  63. package/dist/lib/src/components/Link.js +5 -11
  64. package/dist/lib/src/components/Link.js.map +1 -1
  65. package/dist/lib/src/components/builder-block.component.js +46 -52
  66. package/dist/lib/src/components/builder-block.component.js.map +1 -1
  67. package/dist/lib/src/components/builder-blocks.component.js +16 -22
  68. package/dist/lib/src/components/builder-blocks.component.js.map +1 -1
  69. package/dist/lib/src/components/builder-component.component.js +103 -108
  70. package/dist/lib/src/components/builder-component.component.js.map +1 -1
  71. package/dist/lib/src/components/builder-content.component.js +32 -38
  72. package/dist/lib/src/components/builder-content.component.js.map +1 -1
  73. package/dist/lib/src/components/insert-spacer.component.js +11 -17
  74. package/dist/lib/src/components/insert-spacer.component.js.map +1 -1
  75. package/dist/lib/src/components/no-wrap.js +2 -5
  76. package/dist/lib/src/components/no-wrap.js.map +1 -1
  77. package/dist/lib/src/components/variants-provider.component.js +10 -36
  78. package/dist/lib/src/components/variants-provider.component.js.map +1 -1
  79. package/dist/lib/src/constants/device-sizes.constant.js +5 -9
  80. package/dist/lib/src/constants/device-sizes.constant.js.map +1 -1
  81. package/dist/lib/src/decorators/builder-block.decorator.js +3 -7
  82. package/dist/lib/src/decorators/builder-block.decorator.js.map +1 -1
  83. package/dist/lib/src/functions/apply-patch-with-mutation.js +1 -5
  84. package/dist/lib/src/functions/apply-patch-with-mutation.js.map +1 -1
  85. package/dist/lib/src/functions/apply-patch-with-mutation.test.js +4 -6
  86. package/dist/lib/src/functions/apply-patch-with-mutation.test.js.map +1 -1
  87. package/dist/lib/src/functions/block-to-html-string.js +5 -10
  88. package/dist/lib/src/functions/block-to-html-string.js.map +1 -1
  89. package/dist/lib/src/functions/debonce-next-tick.js +3 -7
  90. package/dist/lib/src/functions/debonce-next-tick.js.map +1 -1
  91. package/dist/lib/src/functions/get-builder-pixel.js +1 -5
  92. package/dist/lib/src/functions/get-builder-pixel.js.map +1 -1
  93. package/dist/lib/src/functions/get.js +1 -5
  94. package/dist/lib/src/functions/get.js.map +1 -1
  95. package/dist/lib/src/functions/no-wrap.js +5 -11
  96. package/dist/lib/src/functions/no-wrap.js.map +1 -1
  97. package/dist/lib/src/functions/safe-dynamic-require.js +8 -8
  98. package/dist/lib/src/functions/safe-dynamic-require.js.map +1 -1
  99. package/dist/lib/src/functions/set.js +1 -5
  100. package/dist/lib/src/functions/set.js.map +1 -1
  101. package/dist/lib/src/functions/string-to-function.js +11 -16
  102. package/dist/lib/src/functions/string-to-function.js.map +1 -1
  103. package/dist/lib/src/functions/throttle.js +1 -5
  104. package/dist/lib/src/functions/throttle.js.map +1 -1
  105. package/dist/lib/src/functions/try-eval.js +9 -12
  106. package/dist/lib/src/functions/try-eval.js.map +1 -1
  107. package/dist/lib/src/functions/update-metadata.js +5 -9
  108. package/dist/lib/src/functions/update-metadata.js.map +1 -1
  109. package/dist/lib/src/functions/utils.js +1 -5
  110. package/dist/lib/src/functions/utils.js.map +1 -1
  111. package/dist/lib/src/functions/with-builder.js +3 -7
  112. package/dist/lib/src/functions/with-builder.js.map +1 -1
  113. package/dist/lib/src/functions/with-children.js +7 -13
  114. package/dist/lib/src/functions/with-children.js.map +1 -1
  115. package/dist/lib/src/hooks/useIsPreviewing.js +6 -10
  116. package/dist/lib/src/hooks/useIsPreviewing.js.map +1 -1
  117. package/dist/lib/src/scripts/init-editing.js +2 -4
  118. package/dist/lib/src/scripts/init-editing.js.map +1 -1
  119. package/dist/lib/src/store/builder-async-requests.js +4 -12
  120. package/dist/lib/src/store/builder-async-requests.js.map +1 -1
  121. package/dist/lib/src/store/builder-meta.js +2 -8
  122. package/dist/lib/src/store/builder-meta.js.map +1 -1
  123. package/dist/lib/src/store/builder-store.js +2 -8
  124. package/dist/lib/src/store/builder-store.js.map +1 -1
  125. package/dist/lib/src/to-error.js +1 -5
  126. package/dist/lib/src/to-error.js.map +1 -1
  127. package/dist/lib/test/basic.test.js +49 -74
  128. package/dist/lib/test/basic.test.js.map +1 -1
  129. package/dist/lib/test/functions/render-block.js +3 -8
  130. package/dist/lib/test/functions/render-block.js.map +1 -1
  131. package/dist/lib/test/image.test.js +14 -39
  132. package/dist/lib/test/image.test.js.map +1 -1
  133. package/package.json +6 -5
  134. package/rollup.config.ts +0 -1
  135. package/src/blocks/Button.tsx +1 -0
  136. package/src/blocks/CustomCode.tsx +1 -0
  137. package/src/blocks/Embed.tsx +1 -0
  138. package/src/blocks/Fragment.tsx +1 -0
  139. package/src/blocks/StateProvider.tsx +1 -0
  140. package/src/blocks/forms/Button.tsx +1 -0
  141. package/src/blocks/forms/Input.tsx +1 -0
  142. package/src/blocks/forms/Label.tsx +1 -0
  143. package/src/blocks/forms/Select.tsx +1 -0
  144. package/src/blocks/forms/TextArea.tsx +1 -0
  145. package/src/blocks/raw/Img.tsx +1 -0
  146. package/src/blocks/raw/RawText.tsx +1 -0
  147. package/src/components/Link.tsx +1 -0
  148. package/src/components/builder-component.component.tsx +1 -0
  149. package/src/components/builder-content.component.tsx +1 -0
  150. package/src/components/no-wrap.tsx +1 -0
  151. package/src/components/variants-provider.component.tsx +1 -0
  152. package/src/functions/no-wrap.tsx +1 -0
  153. package/src/functions/try-eval.tsx +1 -0
  154. package/src/functions/with-children.tsx +1 -0
  155. package/dist/builder-react.es5.js +0 -2
  156. package/dist/builder-react.es5.js.map +0 -1
@@ -1,4 +1,4 @@
1
- "use strict";
1
+ 'use client';
2
2
  var __extends = (this && this.__extends) || (function () {
3
3
  var extendStatics = function (d, b) {
4
4
  extendStatics = Object.setPrototypeOf ||
@@ -79,29 +79,24 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
79
79
  }
80
80
  return to.concat(ar || Array.prototype.slice.call(from));
81
81
  };
82
- var __importDefault = (this && this.__importDefault) || function (mod) {
83
- return (mod && mod.__esModule) ? mod : { "default": mod };
84
- };
85
- Object.defineProperty(exports, "__esModule", { value: true });
86
- exports.BuilderComponent = exports.onChange = void 0;
87
- var react_1 = __importDefault(require("react"));
88
- var react_dom_1 = __importDefault(require("react-dom"));
89
- var core_1 = require("@emotion/core");
90
- var builder_content_component_1 = require("./builder-content.component");
91
- var builder_blocks_component_1 = require("./builder-blocks.component");
92
- var sdk_1 = require("@builder.io/sdk");
93
- var builder_store_1 = require("../store/builder-store");
94
- var hash_sum_1 = __importDefault(require("hash-sum"));
95
- var on_change_1 = __importDefault(require("../../lib/on-change"));
96
- exports.onChange = on_change_1.default;
97
- var device_sizes_constant_1 = require("../constants/device-sizes.constant");
98
- var builder_async_requests_1 = require("../store/builder-async-requests");
99
- var debonce_next_tick_1 = require("../functions/debonce-next-tick");
100
- var throttle_1 = require("../functions/throttle");
101
- var builder_meta_1 = require("../store/builder-meta");
102
- var try_eval_1 = require("../functions/try-eval");
103
- var to_error_1 = require("../to-error");
104
- var get_builder_pixel_1 = require("../functions/get-builder-pixel");
82
+ import React from 'react';
83
+ import ReactDOM from 'react-dom';
84
+ import { jsx, css } from '@emotion/core';
85
+ import { BuilderContent, getContentWithInfo } from './builder-content.component';
86
+ import { BuilderBlocks } from './builder-blocks.component';
87
+ import { Builder, builder, Subscription, BehaviorSubject, } from '@builder.io/sdk';
88
+ import { BuilderStoreContext } from '../store/builder-store';
89
+ import hash from 'hash-sum';
90
+ import onChange from '../../lib/on-change';
91
+ export { onChange };
92
+ import { getSizesForBreakpoints } from '../constants/device-sizes.constant';
93
+ import { BuilderAsyncRequestsContext, isRequestInfo, } from '../store/builder-async-requests';
94
+ import { debounceNextTick } from '../functions/debonce-next-tick';
95
+ import { throttle } from '../functions/throttle';
96
+ import { BuilderMetaContext } from '../store/builder-meta';
97
+ import { tryEval } from '../functions/try-eval';
98
+ import { toError } from '../to-error';
99
+ import { getBuilderPixel } from '../functions/get-builder-pixel';
105
100
  function pick(obj) {
106
101
  var keys = [];
107
102
  for (var _i = 1; _i < arguments.length; _i++) {
@@ -133,10 +128,10 @@ var wrapComponent = function (info) {
133
128
  var baseProps = omit.apply(void 0, __spreadArray(__spreadArray([props], inputNames, false), ['attributes'], false));
134
129
  var inputProps = props; // pick(props, ...inputNames);
135
130
  if (info.noWrap) {
136
- return react_1.default.createElement(info.class, __assign({ attributes: baseProps }, inputProps));
131
+ return React.createElement(info.class, __assign({ attributes: baseProps }, inputProps));
137
132
  }
138
- return (react_1.default.createElement(Tag, __assign({}, baseProps),
139
- react_1.default.createElement(info.class, __assign({}, inputProps))));
133
+ return (React.createElement(Tag, __assign({}, baseProps),
134
+ React.createElement(info.class, __assign({}, inputProps))));
140
135
  };
141
136
  };
142
137
  var size = function (thing) { return Object.keys(thing).length; };
@@ -197,13 +192,13 @@ var BuilderComponent = /** @class */ (function (_super) {
197
192
  var _this = this;
198
193
  var _a;
199
194
  _this = _super.call(this, props) || this;
200
- _this.subscriptions = new sdk_1.Subscription();
195
+ _this.subscriptions = new Subscription();
201
196
  // TODO: don't trigger initial one?
202
- _this.onStateChange = new sdk_1.BehaviorSubject(null);
203
- _this.asServer = sdk_1.Builder.isServer;
197
+ _this.onStateChange = new BehaviorSubject(null);
198
+ _this.asServer = Builder.isServer;
204
199
  _this.contentRef = null;
205
200
  _this.styleRef = null;
206
- _this.rootState = sdk_1.Builder.isServer ? {} : (0, on_change_1.default)({}, function () { return _this.updateState(); });
201
+ _this.rootState = Builder.isServer ? {} : onChange({}, function () { return _this.updateState(); });
207
202
  _this.lastJsCode = '';
208
203
  _this.lastHttpRequests = {};
209
204
  _this.httpSubscriptionPerKey = {};
@@ -218,7 +213,7 @@ var BuilderComponent = /** @class */ (function (_super) {
218
213
  if (!data.contentId || data.contentId !== ((_a = _this.useContent) === null || _a === void 0 ? void 0 : _a.id)) {
219
214
  return;
220
215
  }
221
- _this.sizes = (0, device_sizes_constant_1.getSizesForBreakpoints)(data.breakpoints || {});
216
+ _this.sizes = getSizesForBreakpoints(data.breakpoints || {});
222
217
  _this.setState({
223
218
  state: Object.assign(_this.rootState, {
224
219
  deviceSize: _this.deviceSizeState,
@@ -271,7 +266,7 @@ var BuilderComponent = /** @class */ (function (_super) {
271
266
  _this.setState(__assign(__assign({}, _this.state), { updates: ((_this.state && _this.state.updates) || 0) + 1, state: Object.assign(_this.rootState, __assign(__assign({}, _this.state.state), { deviceSize: deviceSize })) }));
272
267
  }
273
268
  };
274
- _this.resizeListener = sdk_1.Builder.isEditing ? (0, throttle_1.throttle)(_this.resizeFn, 200) : debounce(_this.resizeFn, 400);
269
+ _this.resizeListener = Builder.isEditing ? throttle(_this.resizeFn, 200) : debounce(_this.resizeFn, 400);
275
270
  _this.mounted = false;
276
271
  _this.updateState = function (fn) {
277
272
  var state = _this.rootState;
@@ -292,7 +287,7 @@ var BuilderComponent = /** @class */ (function (_super) {
292
287
  };
293
288
  _this.onContentLoaded = function (data, content) {
294
289
  var _a;
295
- if (_this.name === 'page' && sdk_1.Builder.isBrowser) {
290
+ if (_this.name === 'page' && Builder.isBrowser) {
296
291
  if (data) {
297
292
  var title = data.title, pageTitle = data.pageTitle, description = data.description, pageDescription = data.pageDescription;
298
293
  if (title || pageTitle) {
@@ -309,7 +304,7 @@ var BuilderComponent = /** @class */ (function (_super) {
309
304
  }
310
305
  }
311
306
  }
312
- if (sdk_1.Builder.isEditing) {
307
+ if (Builder.isEditing) {
313
308
  _this.notifyStateChange();
314
309
  }
315
310
  if (_this.props.contentLoaded) {
@@ -339,10 +334,10 @@ var BuilderComponent = /** @class */ (function (_super) {
339
334
  }
340
335
  }
341
336
  // TODO: also throttle on edits maybe
342
- if (data && data.jsCode && sdk_1.Builder.isBrowser && !_this.options.codegen) {
337
+ if (data && data.jsCode && Builder.isBrowser && !_this.options.codegen) {
343
338
  // Don't rerun js code when editing and not changed
344
339
  var skip = false;
345
- if (sdk_1.Builder.isEditing) {
340
+ if (Builder.isEditing) {
346
341
  if (_this.lastJsCode === data.jsCode) {
347
342
  skip = true;
348
343
  }
@@ -354,13 +349,13 @@ var BuilderComponent = /** @class */ (function (_super) {
354
349
  var state = _this.state.state;
355
350
  // TODO: real editing method
356
351
  try {
357
- var result = new Function('data', 'ref', 'state', 'update', 'element', 'Builder', 'builder', 'context', data.jsCode)(data, _this, state, _this.state.update, _this.ref, sdk_1.Builder, sdk_1.builder, _this.state.context);
352
+ var result = new Function('data', 'ref', 'state', 'update', 'element', 'Builder', 'builder', 'context', data.jsCode)(data, _this, state, _this.state.update, _this.ref, Builder, builder, _this.state.context);
358
353
  // TODO: allow exports = { } syntax?
359
354
  // TODO: do something with reuslt like view - methods, computed, actions, properties, template, etc etc
360
355
  }
361
356
  catch (err) {
362
- var error = (0, to_error_1.toError)(err);
363
- if (sdk_1.Builder.isBrowser) {
357
+ var error = toError(err);
358
+ if (Builder.isBrowser) {
364
359
  console.warn('Builder custom code error:', error.message, 'in', data.jsCode, error.stack);
365
360
  }
366
361
  else {
@@ -379,10 +374,10 @@ var BuilderComponent = /** @class */ (function (_super) {
379
374
  if (!skip) {
380
375
  var _loop_1 = function (key) {
381
376
  var url = data.httpRequests[key];
382
- if (url && (!_this.data[key] || sdk_1.Builder.isEditing)) {
383
- if (sdk_1.Builder.isBrowser) {
377
+ if (url && (!_this.data[key] || Builder.isEditing)) {
378
+ if (Builder.isBrowser) {
384
379
  var finalUrl_1 = _this.evalExpression(url);
385
- if (sdk_1.Builder.isEditing && _this.lastHttpRequests[key] === finalUrl_1) {
380
+ if (Builder.isEditing && _this.lastHttpRequests[key] === finalUrl_1) {
386
381
  return "continue";
387
382
  }
388
383
  _this.lastHttpRequests[key] = finalUrl_1;
@@ -421,20 +416,20 @@ var BuilderComponent = /** @class */ (function (_super) {
421
416
  if (_content && _content.content) {
422
417
  _content = _content.content;
423
418
  }
424
- _this.sizes = (0, device_sizes_constant_1.getSizesForBreakpoints)(((_a = _content === null || _content === void 0 ? void 0 : _content.meta) === null || _a === void 0 ? void 0 : _a.breakpoints) || {});
419
+ _this.sizes = getSizesForBreakpoints(((_a = _content === null || _content === void 0 ? void 0 : _content.meta) === null || _a === void 0 ? void 0 : _a.breakpoints) || {});
425
420
  // TODO: pass this all the way down - symbols, etc
426
421
  // this.asServer = Boolean(props.hydrate && Builder.isBrowser)
427
422
  _this.state = {
428
423
  // TODO: should change if this prop changes
429
- context: __assign(__assign({}, props.context), { apiKey: sdk_1.builder.apiKey || _this.props.apiKey }),
430
- state: Object.assign(_this.rootState, __assign(__assign(__assign(__assign({}, (_this.inlinedContent && _this.inlinedContent.data && _this.inlinedContent.data.state)), { isBrowser: sdk_1.Builder.isBrowser, isServer: !sdk_1.Builder.isBrowser, _hydrate: props.hydrate, location: _this.locationState, deviceSize: _this.deviceSizeState,
424
+ context: __assign(__assign({}, props.context), { apiKey: builder.apiKey || _this.props.apiKey }),
425
+ state: Object.assign(_this.rootState, __assign(__assign(__assign(__assign({}, (_this.inlinedContent && _this.inlinedContent.data && _this.inlinedContent.data.state)), { isBrowser: Builder.isBrowser, isServer: !Builder.isBrowser, _hydrate: props.hydrate, location: _this.locationState, deviceSize: _this.deviceSizeState,
431
426
  // TODO: will user attributes be ready here?
432
427
  device: _this.device }), _this.getHtmlData()), props.data)),
433
428
  updates: 0,
434
429
  key: 0,
435
430
  update: _this.updateState,
436
431
  };
437
- if (sdk_1.Builder.isBrowser) {
432
+ if (Builder.isBrowser) {
438
433
  var key = _this.props.apiKey;
439
434
  if (key && key !== _this.builder.apiKey) {
440
435
  _this.builder.apiKey = key;
@@ -442,7 +437,7 @@ var BuilderComponent = /** @class */ (function (_super) {
442
437
  if (_this.inlinedContent) {
443
438
  // Sometimes with graphql we get the content as `content.content`
444
439
  var content = _this.inlinedContent.content || _this.inlinedContent;
445
- _this.onContentLoaded(content === null || content === void 0 ? void 0 : content.data, (0, builder_content_component_1.getContentWithInfo)(content));
440
+ _this.onContentLoaded(content === null || content === void 0 ? void 0 : content.data, getContentWithInfo(content));
446
441
  }
447
442
  }
448
443
  return _this;
@@ -481,7 +476,7 @@ var BuilderComponent = /** @class */ (function (_super) {
481
476
  });
482
477
  Object.defineProperty(BuilderComponent.prototype, "builder", {
483
478
  get: function () {
484
- return this.props.builder || sdk_1.builder;
479
+ return this.props.builder || builder;
485
480
  },
486
481
  enumerable: false,
487
482
  configurable: true
@@ -489,7 +484,7 @@ var BuilderComponent = /** @class */ (function (_super) {
489
484
  BuilderComponent.prototype.getHtmlData = function () {
490
485
  var id = (this.inlinedContent && this.inlinedContent.id) || this.props.entry;
491
486
  var script = id &&
492
- sdk_1.Builder.isBrowser &&
487
+ Builder.isBrowser &&
493
488
  document.querySelector("script[data-builder-json=\"".concat(id, "\"],script[data-builder-state=\"").concat(id, "\"]"));
494
489
  if (script) {
495
490
  try {
@@ -521,7 +516,7 @@ var BuilderComponent = /** @class */ (function (_super) {
521
516
  // TODO: trigger state change on screen size change
522
517
  get: function () {
523
518
  // TODO: use context to pass this down on server
524
- return sdk_1.Builder.isBrowser
519
+ return Builder.isBrowser
525
520
  ? this.sizes.getSizeForWidth(window.innerWidth)
526
521
  : sizeMap[this.device] || 'large';
527
522
  },
@@ -576,13 +571,13 @@ var BuilderComponent = /** @class */ (function (_super) {
576
571
  if (el) {
577
572
  el.innerHTML = content;
578
573
  }
579
- else if (!sdk_1.Builder.isEditing) {
574
+ else if (!Builder.isEditing) {
580
575
  keepStyles_1 += match;
581
576
  }
582
577
  return match;
583
578
  });
584
579
  // NextTick? or longer timeout?
585
- sdk_1.Builder.nextTick(function () {
580
+ Builder.nextTick(function () {
586
581
  apiStyles_1.innerHTML = keepStyles_1;
587
582
  });
588
583
  }
@@ -604,16 +599,16 @@ var BuilderComponent = /** @class */ (function (_super) {
604
599
  div.appendChild(element);
605
600
  useEl = div;
606
601
  }
607
- if (sdk_1.Builder.isEditing || (sdk_1.Builder.isBrowser && location.search.includes('builder.preview='))) {
602
+ if (Builder.isEditing || (Builder.isBrowser && location.search.includes('builder.preview='))) {
608
603
  shouldHydrate = false;
609
604
  }
610
605
  if (shouldHydrate && element) {
611
606
  // TODO: maybe hydrate again. Maybe...
612
- var val_1 = react_dom_1.default.render(react_1.default.createElement(BuilderComponent, __assign({}, props)), useEl, useEl.builderRootRef);
607
+ var val_1 = ReactDOM.render(React.createElement(BuilderComponent, __assign({}, props)), useEl, useEl.builderRootRef);
613
608
  useEl.builderRootRef = val_1;
614
609
  return val_1;
615
610
  }
616
- var val = react_dom_1.default.render(react_1.default.createElement(BuilderComponent, __assign({}, props)), useEl, useEl.builderRootRef);
611
+ var val = ReactDOM.render(React.createElement(BuilderComponent, __assign({}, props)), useEl, useEl.builderRootRef);
617
612
  useEl.builderRootRef = val;
618
613
  return val;
619
614
  };
@@ -628,17 +623,17 @@ var BuilderComponent = /** @class */ (function (_super) {
628
623
  state.isServer = false;
629
624
  });
630
625
  }
631
- if (sdk_1.Builder.isIframe) {
626
+ if (Builder.isIframe) {
632
627
  (_a = window.parent) === null || _a === void 0 ? void 0 : _a.postMessage({ type: 'builder.sdkInjected', data: { modelName: this.name } }, '*');
633
628
  }
634
- if (sdk_1.Builder.isBrowser) {
629
+ if (Builder.isBrowser) {
635
630
  // TODO: remove event on unload
636
631
  window.addEventListener('resize', this.resizeListener);
637
- if (sdk_1.Builder.isEditing) {
632
+ if (Builder.isEditing) {
638
633
  window.addEventListener('message', this.messageListener);
639
634
  }
640
- if (sdk_1.Builder.isEditing || sdk_1.Builder.isPreviewing) {
641
- sdk_1.Builder.nextTick(function () {
635
+ if (Builder.isEditing || Builder.isPreviewing) {
636
+ Builder.nextTick(function () {
642
637
  _this.firstLoad = false;
643
638
  _this.reload();
644
639
  });
@@ -654,14 +649,14 @@ var BuilderComponent = /** @class */ (function (_super) {
654
649
  };
655
650
  Object.defineProperty(BuilderComponent.prototype, "isPreviewing", {
656
651
  get: function () {
657
- return ((sdk_1.Builder.isServer || (sdk_1.Builder.isBrowser && sdk_1.Builder.isPreviewing && !this.firstLoad)) &&
658
- sdk_1.builder.previewingModel === this.name);
652
+ return ((Builder.isServer || (Builder.isBrowser && Builder.isPreviewing && !this.firstLoad)) &&
653
+ builder.previewingModel === this.name);
659
654
  },
660
655
  enumerable: false,
661
656
  configurable: true
662
657
  });
663
658
  BuilderComponent.prototype.notifyStateChange = function () {
664
- if (sdk_1.Builder.isServer) {
659
+ if (Builder.isServer) {
665
660
  return;
666
661
  }
667
662
  if (!(this && this.state)) {
@@ -672,7 +667,7 @@ var BuilderComponent = /** @class */ (function (_super) {
672
667
  if (this.props.onStateChange) {
673
668
  this.props.onStateChange(nextState);
674
669
  }
675
- if (sdk_1.Builder.isBrowser) {
670
+ if (Builder.isBrowser) {
676
671
  window.dispatchEvent(new CustomEvent('builder:component:stateChange', {
677
672
  detail: {
678
673
  state: nextState,
@@ -687,7 +682,7 @@ var BuilderComponent = /** @class */ (function (_super) {
687
682
  };
688
683
  Object.defineProperty(BuilderComponent.prototype, "location", {
689
684
  get: function () {
690
- return this.props.location || (sdk_1.Builder.isBrowser ? location : {});
685
+ return this.props.location || (Builder.isBrowser ? location : {});
691
686
  },
692
687
  enumerable: false,
693
688
  configurable: true
@@ -718,7 +713,7 @@ var BuilderComponent = /** @class */ (function (_super) {
718
713
  };
719
714
  BuilderComponent.prototype.componentWillUnmount = function () {
720
715
  this.unsubscribe();
721
- if (sdk_1.Builder.isBrowser) {
716
+ if (Builder.isBrowser) {
722
717
  window.removeEventListener('resize', this.resizeListener);
723
718
  window.removeEventListener('message', this.messageListener);
724
719
  }
@@ -784,7 +779,7 @@ var BuilderComponent = /** @class */ (function (_super) {
784
779
  Object.assign(state, _this.externalState);
785
780
  });
786
781
  }
787
- if (sdk_1.Builder.isEditing) {
782
+ if (Builder.isEditing) {
788
783
  if (this.inlinedContent && prevProps.content !== this.inlinedContent) {
789
784
  this.onContentLoaded(this.inlinedContent.data, this.inlinedContent);
790
785
  }
@@ -835,36 +830,36 @@ var BuilderComponent = /** @class */ (function (_super) {
835
830
  var _this = this;
836
831
  var _a;
837
832
  var content = this.content;
838
- var dataString = sdk_1.Builder.isBrowser &&
833
+ var dataString = Builder.isBrowser &&
839
834
  this.externalState &&
840
835
  size(this.externalState) &&
841
- (0, hash_sum_1.default)(this.externalState);
842
- var key = sdk_1.Builder.isEditing ? this.name : this.props.entry;
843
- if (key && !sdk_1.Builder.isEditing && dataString && dataString.length < 300) {
836
+ hash(this.externalState);
837
+ var key = Builder.isEditing ? this.name : this.props.entry;
838
+ if (key && !Builder.isEditing && dataString && dataString.length < 300) {
844
839
  key += ':' + dataString;
845
840
  }
846
- var WrapComponent = this.props.dataOnly ? react_1.default.Fragment : 'div';
841
+ var WrapComponent = this.props.dataOnly ? React.Fragment : 'div';
847
842
  var contentId = (_a = this.useContent) === null || _a === void 0 ? void 0 : _a.id;
848
843
  return (
849
844
  // TODO: data attributes for model, id, etc?
850
- react_1.default.createElement(WrapComponent, { onClick: function (event) {
845
+ React.createElement(WrapComponent, { onClick: function (event) {
851
846
  // Prevent propagation from the root content component when editing to prevent issues
852
847
  // like client side routing triggering when links are clicked, unless this behavior is
853
848
  // disabled with the stopClickPropagationWhenEditing prop
854
- if (sdk_1.Builder.isEditing &&
849
+ if (Builder.isEditing &&
855
850
  !_this.props.isChild &&
856
851
  !_this.props.stopClickPropagationWhenEditing) {
857
852
  event.stopPropagation();
858
853
  }
859
854
  }, className: "builder-component ".concat(contentId ? "builder-component-".concat(contentId) : ''), "data-name": this.name, "data-source": "Rendered by Builder.io", key: this.state.key, ref: function (ref) { return (_this.ref = ref); } },
860
- react_1.default.createElement(builder_meta_1.BuilderMetaContext.Consumer, null, function (value) { return (react_1.default.createElement(builder_meta_1.BuilderMetaContext.Provider, { value: typeof _this.props.ampMode === 'boolean'
855
+ React.createElement(BuilderMetaContext.Consumer, null, function (value) { return (React.createElement(BuilderMetaContext.Provider, { value: typeof _this.props.ampMode === 'boolean'
861
856
  ? __assign(__assign({}, value), { ampMode: _this.props.ampMode }) : value },
862
- react_1.default.createElement(builder_async_requests_1.BuilderAsyncRequestsContext.Consumer, null, function (value) {
857
+ React.createElement(BuilderAsyncRequestsContext.Consumer, null, function (value) {
863
858
  var _a;
864
859
  _this._asyncRequests = value && value.requests;
865
860
  _this._errors = value && value.errors;
866
861
  _this._logs = value && value.logs;
867
- return (react_1.default.createElement(builder_content_component_1.BuilderContent, { isStatic: _this.props.isStatic || sdk_1.Builder.isStatic, key: ((_a = _this.inlinedContent) === null || _a === void 0 ? void 0 : _a.id) ||
862
+ return (React.createElement(BuilderContent, { isStatic: _this.props.isStatic || Builder.isStatic, key: ((_a = _this.inlinedContent) === null || _a === void 0 ? void 0 : _a.id) ||
868
863
  ('content' in _this.props && !_this.isPreviewing
869
864
  ? 'null-content-prop'
870
865
  : 'no-content-prop'), builder: _this.builder, ref: function (ref) { return (_this.contentRef = ref); },
@@ -885,22 +880,22 @@ var BuilderComponent = /** @class */ (function (_super) {
885
880
  }
886
881
  _this.state.context.builderContent = fullData;
887
882
  }
888
- if (sdk_1.Builder.isBrowser) {
889
- sdk_1.Builder.nextTick(function () {
883
+ if (Builder.isBrowser) {
884
+ Builder.nextTick(function () {
890
885
  _this.checkStyles(data);
891
886
  });
892
887
  }
893
888
  var codegen = _this.options.codegen;
894
889
  if (codegen && !_this.Component && (data === null || data === void 0 ? void 0 : data.blocksJs)) {
895
- var builderComponentNames = Array.from(new Set(sdk_1.Builder.components.map(function (item) { return item.name; })));
896
- var reversedcomponents_1 = sdk_1.Builder.components.slice().reverse();
890
+ var builderComponentNames = Array.from(new Set(Builder.components.map(function (item) { return item.name; })));
891
+ var reversedcomponents_1 = Builder.components.slice().reverse();
897
892
  var builderComponents = builderComponentNames.map(function (name) {
898
893
  return reversedcomponents_1.find(function (item) { return item.class && item.name === name; });
899
894
  });
900
895
  var useBuilderState = function (initialState) {
901
- var _a = react_1.default.useState(0), setTick = _a[1];
902
- var state = react_1.default.useState(function () {
903
- return (0, on_change_1.default)(initialState, function () {
896
+ var _a = React.useState(0), setTick = _a[1];
897
+ var state = React.useState(function () {
898
+ return onChange(initialState, function () {
904
899
  setTick(function (tick) { return tick + 1; });
905
900
  });
906
901
  })[0];
@@ -917,29 +912,29 @@ var BuilderComponent = /** @class */ (function (_super) {
917
912
  'Builder',
918
913
  'builder',
919
914
  'React',
920
- 'useBuilderState'], mappedComponentNames, false), [data.blocksJs], false)))().apply(void 0, __spreadArray([core_1.jsx,
921
- core_1.css,
922
- sdk_1.Builder,
923
- sdk_1.builder,
924
- react_1.default,
915
+ 'useBuilderState'], mappedComponentNames, false), [data.blocksJs], false)))().apply(void 0, __spreadArray([jsx,
916
+ css,
917
+ Builder,
918
+ builder,
919
+ React,
925
920
  useBuilderState], finalizedComponents, false));
926
921
  }
927
922
  var blocks = (data === null || data === void 0 ? void 0 : data.blocks) || [];
928
923
  var hasPixel = blocks.find(function (block) { var _a; return (_a = block.id) === null || _a === void 0 ? void 0 : _a.startsWith('builder-pixel'); });
929
924
  if (data && !hasPixel && blocks.length > 0) {
930
- blocks.push((0, get_builder_pixel_1.getBuilderPixel)(sdk_1.builder.apiKey));
925
+ blocks.push(getBuilderPixel(builder.apiKey));
931
926
  }
932
927
  // TODO: loading option - maybe that is what the children is or component prop
933
928
  // TODO: get rid of all these wrapper divs
934
- return data ? (react_1.default.createElement("div", __assign({ "data-builder-component": _this.name, "data-builder-content-id": fullData.id }, (_this.isPreviewing
929
+ return data ? (React.createElement("div", __assign({ "data-builder-component": _this.name, "data-builder-content-id": fullData.id }, (_this.isPreviewing
935
930
  ? {
936
931
  'data-builder-variation-id': fullData.testVariationId || fullData.variationId || fullData.id,
937
932
  }
938
933
  : {})),
939
- !codegen && _this.getCss(data) && (react_1.default.createElement("style", { ref: function (ref) { return (_this.styleRef = ref); }, className: "builder-custom-styles", dangerouslySetInnerHTML: {
934
+ !codegen && _this.getCss(data) && (React.createElement("style", { ref: function (ref) { return (_this.styleRef = ref); }, className: "builder-custom-styles", dangerouslySetInnerHTML: {
940
935
  __html: _this.getCss(data),
941
936
  } })),
942
- react_1.default.createElement(builder_store_1.BuilderStoreContext.Provider, { value: __assign(__assign({}, _this.state), { rootState: _this.rootState, state: _this.data, content: fullData, renderLink: _this.props.renderLink }) }, codegen && _this.Component ? (react_1.default.createElement(_this.Component, { data: _this.data, context: _this.state.context })) : (react_1.default.createElement(builder_blocks_component_1.BuilderBlocks, { key: String(!!((_a = data === null || data === void 0 ? void 0 : data.blocks) === null || _a === void 0 ? void 0 : _a.length)), emailMode: _this.props.emailMode, fieldName: "blocks", blocks: blocks }))))) : loading ? (react_1.default.createElement("div", { "data-builder-component": _this.name, className: "builder-loading" }, _this.props.children)) : (react_1.default.createElement("div", { "data-builder-component": _this.name, className: "builder-no-content" }));
937
+ React.createElement(BuilderStoreContext.Provider, { value: __assign(__assign({}, _this.state), { rootState: _this.rootState, state: _this.data, content: fullData, renderLink: _this.props.renderLink }) }, codegen && _this.Component ? (React.createElement(_this.Component, { data: _this.data, context: _this.state.context })) : (React.createElement(BuilderBlocks, { key: String(!!((_a = data === null || data === void 0 ? void 0 : data.blocks) === null || _a === void 0 ? void 0 : _a.length)), emailMode: _this.props.emailMode, fieldName: "blocks", blocks: blocks }))))) : loading ? (React.createElement("div", { "data-builder-component": _this.name, className: "builder-loading" }, _this.props.children)) : (React.createElement("div", { "data-builder-component": _this.name, className: "builder-no-content" }));
943
938
  }));
944
939
  }))); })));
945
940
  };
@@ -947,7 +942,7 @@ var BuilderComponent = /** @class */ (function (_super) {
947
942
  var _this = this;
948
943
  var data = this.data;
949
944
  return String(expression).replace(/{{([^}]+)}}/g, function (match, group) {
950
- return (0, try_eval_1.tryEval)(group, data, _this._errors);
945
+ return tryEval(group, data, _this._errors);
951
946
  });
952
947
  };
953
948
  BuilderComponent.prototype.handleRequest = function (propertyName, url) {
@@ -956,7 +951,7 @@ var BuilderComponent = /** @class */ (function (_super) {
956
951
  var _this = this;
957
952
  return __generator(this, function (_a) {
958
953
  // TODO: Builder.isEditing = just checks if iframe and parent page is this.builder.io or localhost:1234
959
- if (sdk_1.Builder.isIframe && fetchCache[url]) {
954
+ if (Builder.isIframe && fetchCache[url]) {
960
955
  this.updateState(function (ctx) {
961
956
  ctx[propertyName] = fetchCache[url];
962
957
  });
@@ -968,7 +963,7 @@ var BuilderComponent = /** @class */ (function (_super) {
968
963
  switch (_a.label) {
969
964
  case 0:
970
965
  requestStart = Date.now();
971
- if (!sdk_1.Builder.isBrowser) {
966
+ if (!Builder.isBrowser) {
972
967
  console.time('Fetch ' + url);
973
968
  }
974
969
  _a.label = 1;
@@ -983,7 +978,7 @@ var BuilderComponent = /** @class */ (function (_super) {
983
978
  return [3 /*break*/, 6];
984
979
  case 4:
985
980
  err_1 = _a.sent();
986
- error = (0, to_error_1.toError)(err_1);
981
+ error = toError(err_1);
987
982
  if (this._errors) {
988
983
  this._errors.push(error);
989
984
  }
@@ -992,7 +987,7 @@ var BuilderComponent = /** @class */ (function (_super) {
992
987
  }
993
988
  return [2 /*return*/];
994
989
  case 5:
995
- if (!sdk_1.Builder.isBrowser) {
990
+ if (!Builder.isBrowser) {
996
991
  console.timeEnd('Fetch ' + url);
997
992
  if (this._logs) {
998
993
  this._logs.push("Fetched ".concat(url, " in ").concat(Date.now() - requestStart, "ms"));
@@ -1001,7 +996,7 @@ var BuilderComponent = /** @class */ (function (_super) {
1001
996
  return [7 /*endfinally*/];
1002
997
  case 6:
1003
998
  if (json) {
1004
- if (sdk_1.Builder.isIframe) {
999
+ if (Builder.isIframe) {
1005
1000
  fetchCache[url] = json;
1006
1001
  }
1007
1002
  // TODO: debounce next tick all of these when there are a bunch
@@ -1014,7 +1009,7 @@ var BuilderComponent = /** @class */ (function (_super) {
1014
1009
  });
1015
1010
  }); };
1016
1011
  existing = this._asyncRequests &&
1017
- this._asyncRequests.find(function (req) { return (0, builder_async_requests_1.isRequestInfo)(req) && req.url === url; });
1012
+ this._asyncRequests.find(function (req) { return isRequestInfo(req) && req.url === url; });
1018
1013
  if (existing) {
1019
1014
  promise_1 = existing.promise;
1020
1015
  promise_1.then(function (json) {
@@ -1027,7 +1022,7 @@ var BuilderComponent = /** @class */ (function (_super) {
1027
1022
  return [2 /*return*/, promise_1];
1028
1023
  }
1029
1024
  promise = request();
1030
- sdk_1.Builder.nextTick(function () {
1025
+ Builder.nextTick(function () {
1031
1026
  if (_this._asyncRequests) {
1032
1027
  _this._asyncRequests.push(promise);
1033
1028
  }
@@ -1039,12 +1034,12 @@ var BuilderComponent = /** @class */ (function (_super) {
1039
1034
  BuilderComponent.prototype.unsubscribe = function () {
1040
1035
  if (this.subscriptions) {
1041
1036
  this.subscriptions.unsubscribe();
1042
- this.subscriptions = new sdk_1.Subscription();
1037
+ this.subscriptions = new Subscription();
1043
1038
  }
1044
1039
  };
1045
1040
  BuilderComponent.prototype.handleBuilderRequest = function (propertyName, optionsString) {
1046
1041
  var _this = this;
1047
- var options = (0, try_eval_1.tryEval)(optionsString, this.data, this._errors);
1042
+ var options = tryEval(optionsString, this.data, this._errors);
1048
1043
  // TODO: this will screw up for multiple bits of data
1049
1044
  if (this.subscriptions) {
1050
1045
  this.unsubscribe();
@@ -1063,15 +1058,15 @@ var BuilderComponent = /** @class */ (function (_super) {
1063
1058
  }
1064
1059
  };
1065
1060
  BuilderComponent.defaults = {
1066
- codegen: Boolean(sdk_1.Builder.isBrowser && location.href.includes('builder.codegen=true')),
1061
+ codegen: Boolean(Builder.isBrowser && location.href.includes('builder.codegen=true')),
1067
1062
  };
1068
1063
  __decorate([
1069
- debonce_next_tick_1.debounceNextTick,
1064
+ debounceNextTick,
1070
1065
  __metadata("design:type", Function),
1071
1066
  __metadata("design:paramtypes", []),
1072
1067
  __metadata("design:returntype", void 0)
1073
1068
  ], BuilderComponent.prototype, "notifyStateChange", null);
1074
1069
  return BuilderComponent;
1075
- }(react_1.default.Component));
1076
- exports.BuilderComponent = BuilderComponent;
1070
+ }(React.Component));
1071
+ export { BuilderComponent };
1077
1072
  //# sourceMappingURL=builder-component.component.js.map