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