@contentful/experiences-visual-editor-react 1.39.0-alpha-20250528T1549-bd210e1.0 → 1.39.0-alpha-20250603T1404-5a5eb4e.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/index.js +147 -4
- package/dist/index.js.map +1 -1
- package/dist/renderApp.js +450 -8
- package/dist/renderApp.js.map +1 -1
- package/package.json +4 -4
package/dist/renderApp.js
CHANGED
|
@@ -35291,6 +35291,40 @@ function baseToString(value) {
|
|
|
35291
35291
|
return (result == '0' && (1 / value) == -INFINITY$1) ? '-0' : result;
|
|
35292
35292
|
}
|
|
35293
35293
|
|
|
35294
|
+
/** Used to match a single whitespace character. */
|
|
35295
|
+
var reWhitespace = /\s/;
|
|
35296
|
+
|
|
35297
|
+
/**
|
|
35298
|
+
* Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
|
|
35299
|
+
* character of `string`.
|
|
35300
|
+
*
|
|
35301
|
+
* @private
|
|
35302
|
+
* @param {string} string The string to inspect.
|
|
35303
|
+
* @returns {number} Returns the index of the last non-whitespace character.
|
|
35304
|
+
*/
|
|
35305
|
+
function trimmedEndIndex(string) {
|
|
35306
|
+
var index = string.length;
|
|
35307
|
+
|
|
35308
|
+
while (index-- && reWhitespace.test(string.charAt(index))) {}
|
|
35309
|
+
return index;
|
|
35310
|
+
}
|
|
35311
|
+
|
|
35312
|
+
/** Used to match leading whitespace. */
|
|
35313
|
+
var reTrimStart = /^\s+/;
|
|
35314
|
+
|
|
35315
|
+
/**
|
|
35316
|
+
* The base implementation of `_.trim`.
|
|
35317
|
+
*
|
|
35318
|
+
* @private
|
|
35319
|
+
* @param {string} string The string to trim.
|
|
35320
|
+
* @returns {string} Returns the trimmed string.
|
|
35321
|
+
*/
|
|
35322
|
+
function baseTrim(string) {
|
|
35323
|
+
return string
|
|
35324
|
+
? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')
|
|
35325
|
+
: string;
|
|
35326
|
+
}
|
|
35327
|
+
|
|
35294
35328
|
/**
|
|
35295
35329
|
* Checks if `value` is the
|
|
35296
35330
|
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
|
|
@@ -35321,6 +35355,65 @@ function isObject(value) {
|
|
|
35321
35355
|
return value != null && (type == 'object' || type == 'function');
|
|
35322
35356
|
}
|
|
35323
35357
|
|
|
35358
|
+
/** Used as references for various `Number` constants. */
|
|
35359
|
+
var NAN = 0 / 0;
|
|
35360
|
+
|
|
35361
|
+
/** Used to detect bad signed hexadecimal string values. */
|
|
35362
|
+
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
|
|
35363
|
+
|
|
35364
|
+
/** Used to detect binary string values. */
|
|
35365
|
+
var reIsBinary = /^0b[01]+$/i;
|
|
35366
|
+
|
|
35367
|
+
/** Used to detect octal string values. */
|
|
35368
|
+
var reIsOctal = /^0o[0-7]+$/i;
|
|
35369
|
+
|
|
35370
|
+
/** Built-in method references without a dependency on `root`. */
|
|
35371
|
+
var freeParseInt = parseInt;
|
|
35372
|
+
|
|
35373
|
+
/**
|
|
35374
|
+
* Converts `value` to a number.
|
|
35375
|
+
*
|
|
35376
|
+
* @static
|
|
35377
|
+
* @memberOf _
|
|
35378
|
+
* @since 4.0.0
|
|
35379
|
+
* @category Lang
|
|
35380
|
+
* @param {*} value The value to process.
|
|
35381
|
+
* @returns {number} Returns the number.
|
|
35382
|
+
* @example
|
|
35383
|
+
*
|
|
35384
|
+
* _.toNumber(3.2);
|
|
35385
|
+
* // => 3.2
|
|
35386
|
+
*
|
|
35387
|
+
* _.toNumber(Number.MIN_VALUE);
|
|
35388
|
+
* // => 5e-324
|
|
35389
|
+
*
|
|
35390
|
+
* _.toNumber(Infinity);
|
|
35391
|
+
* // => Infinity
|
|
35392
|
+
*
|
|
35393
|
+
* _.toNumber('3.2');
|
|
35394
|
+
* // => 3.2
|
|
35395
|
+
*/
|
|
35396
|
+
function toNumber(value) {
|
|
35397
|
+
if (typeof value == 'number') {
|
|
35398
|
+
return value;
|
|
35399
|
+
}
|
|
35400
|
+
if (isSymbol(value)) {
|
|
35401
|
+
return NAN;
|
|
35402
|
+
}
|
|
35403
|
+
if (isObject(value)) {
|
|
35404
|
+
var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
|
|
35405
|
+
value = isObject(other) ? (other + '') : other;
|
|
35406
|
+
}
|
|
35407
|
+
if (typeof value != 'string') {
|
|
35408
|
+
return value === 0 ? value : +value;
|
|
35409
|
+
}
|
|
35410
|
+
value = baseTrim(value);
|
|
35411
|
+
var isBinary = reIsBinary.test(value);
|
|
35412
|
+
return (isBinary || reIsOctal.test(value))
|
|
35413
|
+
? freeParseInt(value.slice(2), isBinary ? 2 : 8)
|
|
35414
|
+
: (reIsBadHex.test(value) ? NAN : +value);
|
|
35415
|
+
}
|
|
35416
|
+
|
|
35324
35417
|
/**
|
|
35325
35418
|
* This method returns the first argument it receives.
|
|
35326
35419
|
*
|
|
@@ -35812,7 +35905,7 @@ function copyObject(source, props, object, customizer) {
|
|
|
35812
35905
|
}
|
|
35813
35906
|
|
|
35814
35907
|
/* Built-in method references for those with the same name as other `lodash` methods. */
|
|
35815
|
-
var nativeMax = Math.max;
|
|
35908
|
+
var nativeMax$1 = Math.max;
|
|
35816
35909
|
|
|
35817
35910
|
/**
|
|
35818
35911
|
* A specialized version of `baseRest` which transforms the rest array.
|
|
@@ -35824,11 +35917,11 @@ var nativeMax = Math.max;
|
|
|
35824
35917
|
* @returns {Function} Returns the new function.
|
|
35825
35918
|
*/
|
|
35826
35919
|
function overRest(func, start, transform) {
|
|
35827
|
-
start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
|
|
35920
|
+
start = nativeMax$1(start === undefined ? (func.length - 1) : start, 0);
|
|
35828
35921
|
return function() {
|
|
35829
35922
|
var args = arguments,
|
|
35830
35923
|
index = -1,
|
|
35831
|
-
length = nativeMax(args.length - start, 0),
|
|
35924
|
+
length = nativeMax$1(args.length - start, 0),
|
|
35832
35925
|
array = Array(length);
|
|
35833
35926
|
|
|
35834
35927
|
while (++index < length) {
|
|
@@ -36768,7 +36861,7 @@ MapCache.prototype.has = mapCacheHas;
|
|
|
36768
36861
|
MapCache.prototype.set = mapCacheSet;
|
|
36769
36862
|
|
|
36770
36863
|
/** Error message constants. */
|
|
36771
|
-
var FUNC_ERROR_TEXT = 'Expected a function';
|
|
36864
|
+
var FUNC_ERROR_TEXT$1 = 'Expected a function';
|
|
36772
36865
|
|
|
36773
36866
|
/**
|
|
36774
36867
|
* Creates a function that memoizes the result of `func`. If `resolver` is
|
|
@@ -36816,7 +36909,7 @@ var FUNC_ERROR_TEXT = 'Expected a function';
|
|
|
36816
36909
|
*/
|
|
36817
36910
|
function memoize(func, resolver) {
|
|
36818
36911
|
if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
|
|
36819
|
-
throw new TypeError(FUNC_ERROR_TEXT);
|
|
36912
|
+
throw new TypeError(FUNC_ERROR_TEXT$1);
|
|
36820
36913
|
}
|
|
36821
36914
|
var memoized = function() {
|
|
36822
36915
|
var args = arguments,
|
|
@@ -38433,6 +38526,212 @@ function baseIsEqual(value, other, bitmask, customizer, stack) {
|
|
|
38433
38526
|
return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
|
|
38434
38527
|
}
|
|
38435
38528
|
|
|
38529
|
+
/**
|
|
38530
|
+
* Gets the timestamp of the number of milliseconds that have elapsed since
|
|
38531
|
+
* the Unix epoch (1 January 1970 00:00:00 UTC).
|
|
38532
|
+
*
|
|
38533
|
+
* @static
|
|
38534
|
+
* @memberOf _
|
|
38535
|
+
* @since 2.4.0
|
|
38536
|
+
* @category Date
|
|
38537
|
+
* @returns {number} Returns the timestamp.
|
|
38538
|
+
* @example
|
|
38539
|
+
*
|
|
38540
|
+
* _.defer(function(stamp) {
|
|
38541
|
+
* console.log(_.now() - stamp);
|
|
38542
|
+
* }, _.now());
|
|
38543
|
+
* // => Logs the number of milliseconds it took for the deferred invocation.
|
|
38544
|
+
*/
|
|
38545
|
+
var now = function() {
|
|
38546
|
+
return root.Date.now();
|
|
38547
|
+
};
|
|
38548
|
+
|
|
38549
|
+
/** Error message constants. */
|
|
38550
|
+
var FUNC_ERROR_TEXT = 'Expected a function';
|
|
38551
|
+
|
|
38552
|
+
/* Built-in method references for those with the same name as other `lodash` methods. */
|
|
38553
|
+
var nativeMax = Math.max,
|
|
38554
|
+
nativeMin = Math.min;
|
|
38555
|
+
|
|
38556
|
+
/**
|
|
38557
|
+
* Creates a debounced function that delays invoking `func` until after `wait`
|
|
38558
|
+
* milliseconds have elapsed since the last time the debounced function was
|
|
38559
|
+
* invoked. The debounced function comes with a `cancel` method to cancel
|
|
38560
|
+
* delayed `func` invocations and a `flush` method to immediately invoke them.
|
|
38561
|
+
* Provide `options` to indicate whether `func` should be invoked on the
|
|
38562
|
+
* leading and/or trailing edge of the `wait` timeout. The `func` is invoked
|
|
38563
|
+
* with the last arguments provided to the debounced function. Subsequent
|
|
38564
|
+
* calls to the debounced function return the result of the last `func`
|
|
38565
|
+
* invocation.
|
|
38566
|
+
*
|
|
38567
|
+
* **Note:** If `leading` and `trailing` options are `true`, `func` is
|
|
38568
|
+
* invoked on the trailing edge of the timeout only if the debounced function
|
|
38569
|
+
* is invoked more than once during the `wait` timeout.
|
|
38570
|
+
*
|
|
38571
|
+
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
|
|
38572
|
+
* until to the next tick, similar to `setTimeout` with a timeout of `0`.
|
|
38573
|
+
*
|
|
38574
|
+
* See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
|
|
38575
|
+
* for details over the differences between `_.debounce` and `_.throttle`.
|
|
38576
|
+
*
|
|
38577
|
+
* @static
|
|
38578
|
+
* @memberOf _
|
|
38579
|
+
* @since 0.1.0
|
|
38580
|
+
* @category Function
|
|
38581
|
+
* @param {Function} func The function to debounce.
|
|
38582
|
+
* @param {number} [wait=0] The number of milliseconds to delay.
|
|
38583
|
+
* @param {Object} [options={}] The options object.
|
|
38584
|
+
* @param {boolean} [options.leading=false]
|
|
38585
|
+
* Specify invoking on the leading edge of the timeout.
|
|
38586
|
+
* @param {number} [options.maxWait]
|
|
38587
|
+
* The maximum time `func` is allowed to be delayed before it's invoked.
|
|
38588
|
+
* @param {boolean} [options.trailing=true]
|
|
38589
|
+
* Specify invoking on the trailing edge of the timeout.
|
|
38590
|
+
* @returns {Function} Returns the new debounced function.
|
|
38591
|
+
* @example
|
|
38592
|
+
*
|
|
38593
|
+
* // Avoid costly calculations while the window size is in flux.
|
|
38594
|
+
* jQuery(window).on('resize', _.debounce(calculateLayout, 150));
|
|
38595
|
+
*
|
|
38596
|
+
* // Invoke `sendMail` when clicked, debouncing subsequent calls.
|
|
38597
|
+
* jQuery(element).on('click', _.debounce(sendMail, 300, {
|
|
38598
|
+
* 'leading': true,
|
|
38599
|
+
* 'trailing': false
|
|
38600
|
+
* }));
|
|
38601
|
+
*
|
|
38602
|
+
* // Ensure `batchLog` is invoked once after 1 second of debounced calls.
|
|
38603
|
+
* var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
|
|
38604
|
+
* var source = new EventSource('/stream');
|
|
38605
|
+
* jQuery(source).on('message', debounced);
|
|
38606
|
+
*
|
|
38607
|
+
* // Cancel the trailing debounced invocation.
|
|
38608
|
+
* jQuery(window).on('popstate', debounced.cancel);
|
|
38609
|
+
*/
|
|
38610
|
+
function debounce(func, wait, options) {
|
|
38611
|
+
var lastArgs,
|
|
38612
|
+
lastThis,
|
|
38613
|
+
maxWait,
|
|
38614
|
+
result,
|
|
38615
|
+
timerId,
|
|
38616
|
+
lastCallTime,
|
|
38617
|
+
lastInvokeTime = 0,
|
|
38618
|
+
leading = false,
|
|
38619
|
+
maxing = false,
|
|
38620
|
+
trailing = true;
|
|
38621
|
+
|
|
38622
|
+
if (typeof func != 'function') {
|
|
38623
|
+
throw new TypeError(FUNC_ERROR_TEXT);
|
|
38624
|
+
}
|
|
38625
|
+
wait = toNumber(wait) || 0;
|
|
38626
|
+
if (isObject(options)) {
|
|
38627
|
+
leading = !!options.leading;
|
|
38628
|
+
maxing = 'maxWait' in options;
|
|
38629
|
+
maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
|
|
38630
|
+
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
|
38631
|
+
}
|
|
38632
|
+
|
|
38633
|
+
function invokeFunc(time) {
|
|
38634
|
+
var args = lastArgs,
|
|
38635
|
+
thisArg = lastThis;
|
|
38636
|
+
|
|
38637
|
+
lastArgs = lastThis = undefined;
|
|
38638
|
+
lastInvokeTime = time;
|
|
38639
|
+
result = func.apply(thisArg, args);
|
|
38640
|
+
return result;
|
|
38641
|
+
}
|
|
38642
|
+
|
|
38643
|
+
function leadingEdge(time) {
|
|
38644
|
+
// Reset any `maxWait` timer.
|
|
38645
|
+
lastInvokeTime = time;
|
|
38646
|
+
// Start the timer for the trailing edge.
|
|
38647
|
+
timerId = setTimeout(timerExpired, wait);
|
|
38648
|
+
// Invoke the leading edge.
|
|
38649
|
+
return leading ? invokeFunc(time) : result;
|
|
38650
|
+
}
|
|
38651
|
+
|
|
38652
|
+
function remainingWait(time) {
|
|
38653
|
+
var timeSinceLastCall = time - lastCallTime,
|
|
38654
|
+
timeSinceLastInvoke = time - lastInvokeTime,
|
|
38655
|
+
timeWaiting = wait - timeSinceLastCall;
|
|
38656
|
+
|
|
38657
|
+
return maxing
|
|
38658
|
+
? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
|
|
38659
|
+
: timeWaiting;
|
|
38660
|
+
}
|
|
38661
|
+
|
|
38662
|
+
function shouldInvoke(time) {
|
|
38663
|
+
var timeSinceLastCall = time - lastCallTime,
|
|
38664
|
+
timeSinceLastInvoke = time - lastInvokeTime;
|
|
38665
|
+
|
|
38666
|
+
// Either this is the first call, activity has stopped and we're at the
|
|
38667
|
+
// trailing edge, the system time has gone backwards and we're treating
|
|
38668
|
+
// it as the trailing edge, or we've hit the `maxWait` limit.
|
|
38669
|
+
return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
|
|
38670
|
+
(timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
|
|
38671
|
+
}
|
|
38672
|
+
|
|
38673
|
+
function timerExpired() {
|
|
38674
|
+
var time = now();
|
|
38675
|
+
if (shouldInvoke(time)) {
|
|
38676
|
+
return trailingEdge(time);
|
|
38677
|
+
}
|
|
38678
|
+
// Restart the timer.
|
|
38679
|
+
timerId = setTimeout(timerExpired, remainingWait(time));
|
|
38680
|
+
}
|
|
38681
|
+
|
|
38682
|
+
function trailingEdge(time) {
|
|
38683
|
+
timerId = undefined;
|
|
38684
|
+
|
|
38685
|
+
// Only invoke if we have `lastArgs` which means `func` has been
|
|
38686
|
+
// debounced at least once.
|
|
38687
|
+
if (trailing && lastArgs) {
|
|
38688
|
+
return invokeFunc(time);
|
|
38689
|
+
}
|
|
38690
|
+
lastArgs = lastThis = undefined;
|
|
38691
|
+
return result;
|
|
38692
|
+
}
|
|
38693
|
+
|
|
38694
|
+
function cancel() {
|
|
38695
|
+
if (timerId !== undefined) {
|
|
38696
|
+
clearTimeout(timerId);
|
|
38697
|
+
}
|
|
38698
|
+
lastInvokeTime = 0;
|
|
38699
|
+
lastArgs = lastCallTime = lastThis = timerId = undefined;
|
|
38700
|
+
}
|
|
38701
|
+
|
|
38702
|
+
function flush() {
|
|
38703
|
+
return timerId === undefined ? result : trailingEdge(now());
|
|
38704
|
+
}
|
|
38705
|
+
|
|
38706
|
+
function debounced() {
|
|
38707
|
+
var time = now(),
|
|
38708
|
+
isInvoking = shouldInvoke(time);
|
|
38709
|
+
|
|
38710
|
+
lastArgs = arguments;
|
|
38711
|
+
lastThis = this;
|
|
38712
|
+
lastCallTime = time;
|
|
38713
|
+
|
|
38714
|
+
if (isInvoking) {
|
|
38715
|
+
if (timerId === undefined) {
|
|
38716
|
+
return leadingEdge(lastCallTime);
|
|
38717
|
+
}
|
|
38718
|
+
if (maxing) {
|
|
38719
|
+
// Handle invocations in a tight loop.
|
|
38720
|
+
clearTimeout(timerId);
|
|
38721
|
+
timerId = setTimeout(timerExpired, wait);
|
|
38722
|
+
return invokeFunc(lastCallTime);
|
|
38723
|
+
}
|
|
38724
|
+
}
|
|
38725
|
+
if (timerId === undefined) {
|
|
38726
|
+
timerId = setTimeout(timerExpired, wait);
|
|
38727
|
+
}
|
|
38728
|
+
return result;
|
|
38729
|
+
}
|
|
38730
|
+
debounced.cancel = cancel;
|
|
38731
|
+
debounced.flush = flush;
|
|
38732
|
+
return debounced;
|
|
38733
|
+
}
|
|
38734
|
+
|
|
38436
38735
|
/**
|
|
38437
38736
|
* Gets the last element of `array`.
|
|
38438
38737
|
*
|
|
@@ -38710,6 +39009,7 @@ const OUTGOING_EVENTS = {
|
|
|
38710
39009
|
OutsideCanvasClick: 'outsideCanvasClick',
|
|
38711
39010
|
SDKFeatures: 'sdkFeatures',
|
|
38712
39011
|
RequestEntities: 'REQUEST_ENTITIES',
|
|
39012
|
+
CanvasGeometryUpdated: 'canvasGeometryUpdated',
|
|
38713
39013
|
};
|
|
38714
39014
|
const INCOMING_EVENTS$1 = {
|
|
38715
39015
|
RequestEditorMode: 'requestEditorMode',
|
|
@@ -45243,6 +45543,51 @@ let DebugLogger$1 = class DebugLogger {
|
|
|
45243
45543
|
DebugLogger$1.instance = null;
|
|
45244
45544
|
DebugLogger$1.getInstance();
|
|
45245
45545
|
|
|
45546
|
+
const findOutermostCoordinates = (first, second) => {
|
|
45547
|
+
return {
|
|
45548
|
+
top: Math.min(first.top, second.top),
|
|
45549
|
+
right: Math.max(first.right, second.right),
|
|
45550
|
+
bottom: Math.max(first.bottom, second.bottom),
|
|
45551
|
+
left: Math.min(first.left, second.left),
|
|
45552
|
+
};
|
|
45553
|
+
};
|
|
45554
|
+
const getElementCoordinates = (element) => {
|
|
45555
|
+
const rect = element.getBoundingClientRect();
|
|
45556
|
+
/**
|
|
45557
|
+
* If element does not have children, or element has it's own width or height,
|
|
45558
|
+
* return the element's coordinates.
|
|
45559
|
+
*/
|
|
45560
|
+
if (element.children.length === 0 || rect.width !== 0 || rect.height !== 0) {
|
|
45561
|
+
return rect;
|
|
45562
|
+
}
|
|
45563
|
+
const rects = [];
|
|
45564
|
+
/**
|
|
45565
|
+
* If element has children, or element does not have it's own width and height,
|
|
45566
|
+
* we find the cordinates of the children, and assume the outermost coordinates of the children
|
|
45567
|
+
* as the coordinate of the element.
|
|
45568
|
+
*
|
|
45569
|
+
* E.g child1 => {top: 2, bottom: 3, left: 4, right: 6} & child2 => {top: 1, bottom: 8, left: 12, right: 24}
|
|
45570
|
+
* The final assumed coordinates of the element would be => { top: 1, right: 24, bottom: 8, left: 4 }
|
|
45571
|
+
*/
|
|
45572
|
+
for (const child of element.children) {
|
|
45573
|
+
const childRect = getElementCoordinates(child);
|
|
45574
|
+
if (childRect.width !== 0 || childRect.height !== 0) {
|
|
45575
|
+
const { top, right, bottom, left } = childRect;
|
|
45576
|
+
rects.push({ top, right, bottom, left });
|
|
45577
|
+
}
|
|
45578
|
+
}
|
|
45579
|
+
if (rects.length === 0) {
|
|
45580
|
+
return rect;
|
|
45581
|
+
}
|
|
45582
|
+
const { top, right, bottom, left } = rects.reduce(findOutermostCoordinates);
|
|
45583
|
+
return DOMRect.fromRect({
|
|
45584
|
+
x: left,
|
|
45585
|
+
y: top,
|
|
45586
|
+
height: bottom - top,
|
|
45587
|
+
width: right - left,
|
|
45588
|
+
});
|
|
45589
|
+
};
|
|
45590
|
+
|
|
45246
45591
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45247
45592
|
const isLinkToAsset = (variable) => {
|
|
45248
45593
|
if (!variable)
|
|
@@ -49144,18 +49489,115 @@ const EmptyCanvasMessage = () => {
|
|
|
49144
49489
|
React$1.createElement("span", { className: styles['empty-canvas-label'] }, "Add components to begin")));
|
|
49145
49490
|
};
|
|
49146
49491
|
|
|
49492
|
+
/**
|
|
49493
|
+
* This function gets the element co-ordinates of a specified component in the DOM and its parent
|
|
49494
|
+
* and sends the DOM Rect to the client app.
|
|
49495
|
+
*/
|
|
49496
|
+
const sendCanvasGeometryUpdatedMessage = async (tree, sourceEvent) => {
|
|
49497
|
+
const nodeToCoordinatesMap = {};
|
|
49498
|
+
await waitForAllImagesToBeLoaded();
|
|
49499
|
+
collectNodeCoordinates(tree.root, nodeToCoordinatesMap);
|
|
49500
|
+
sendMessage(OUTGOING_EVENTS.CanvasGeometryUpdated, {
|
|
49501
|
+
size: {
|
|
49502
|
+
width: document.documentElement.scrollWidth,
|
|
49503
|
+
height: document.documentElement.scrollHeight,
|
|
49504
|
+
},
|
|
49505
|
+
nodes: nodeToCoordinatesMap,
|
|
49506
|
+
sourceEvent,
|
|
49507
|
+
});
|
|
49508
|
+
};
|
|
49509
|
+
const collectNodeCoordinates = (node, nodeToCoordinatesMap) => {
|
|
49510
|
+
const selectedElement = document.querySelector(`[data-cf-node-id="${node.data.id}"]`);
|
|
49511
|
+
if (selectedElement) {
|
|
49512
|
+
const rect = getElementCoordinates(selectedElement);
|
|
49513
|
+
nodeToCoordinatesMap[node.data.id] = {
|
|
49514
|
+
coordinates: {
|
|
49515
|
+
x: rect.x + window.scrollX,
|
|
49516
|
+
y: rect.y + window.scrollY,
|
|
49517
|
+
width: rect.width,
|
|
49518
|
+
height: rect.height,
|
|
49519
|
+
},
|
|
49520
|
+
};
|
|
49521
|
+
}
|
|
49522
|
+
node.children.forEach((child) => collectNodeCoordinates(child, nodeToCoordinatesMap));
|
|
49523
|
+
};
|
|
49524
|
+
const waitForAllImagesToBeLoaded = () => {
|
|
49525
|
+
// If the document contains an image, wait for this image to be loaded before collecting & sending all geometry data.
|
|
49526
|
+
const allImageNodes = document.querySelectorAll('img');
|
|
49527
|
+
return Promise.all(Array.from(allImageNodes).map((imageNode) => {
|
|
49528
|
+
if (imageNode.complete) {
|
|
49529
|
+
return Promise.resolve();
|
|
49530
|
+
}
|
|
49531
|
+
return new Promise((resolve, reject) => {
|
|
49532
|
+
const handleImageLoad = (event) => {
|
|
49533
|
+
imageNode.removeEventListener('load', handleImageLoad);
|
|
49534
|
+
imageNode.removeEventListener('error', handleImageLoad);
|
|
49535
|
+
if (event.type === 'error') {
|
|
49536
|
+
console.warn('Image failed to load:', imageNode);
|
|
49537
|
+
reject();
|
|
49538
|
+
}
|
|
49539
|
+
else {
|
|
49540
|
+
resolve();
|
|
49541
|
+
}
|
|
49542
|
+
};
|
|
49543
|
+
imageNode.addEventListener('load', handleImageLoad);
|
|
49544
|
+
imageNode.addEventListener('error', handleImageLoad);
|
|
49545
|
+
});
|
|
49546
|
+
}));
|
|
49547
|
+
};
|
|
49548
|
+
|
|
49549
|
+
const useCanvasGeometryUpdates = ({ tree, rootContainerRef, }) => {
|
|
49550
|
+
const debouncedUpdateGeometry = reactExports.useMemo(() => debounce((tree, sourceEvent) => {
|
|
49551
|
+
// When the DOM changed, we still need to wait for the next frame to ensure that
|
|
49552
|
+
// rendering is complete (e.g. this is required when deleting a node).
|
|
49553
|
+
window.requestAnimationFrame(() => {
|
|
49554
|
+
sendCanvasGeometryUpdatedMessage(tree, sourceEvent);
|
|
49555
|
+
});
|
|
49556
|
+
}, 100, {
|
|
49557
|
+
leading: true,
|
|
49558
|
+
// To be sure, we recalculate it at the end of the frame again. Though, we couldn't
|
|
49559
|
+
// yet show the need for this. So we might be able to drop this later to boost performance.
|
|
49560
|
+
trailing: true,
|
|
49561
|
+
}), []);
|
|
49562
|
+
// Store tree in a ref to avoid the need to deactivate & reactivate the mutation observer
|
|
49563
|
+
// when the tree changes. This is important to avoid missing out on some mutation events.
|
|
49564
|
+
const treeRef = reactExports.useRef(tree);
|
|
49565
|
+
reactExports.useEffect(() => {
|
|
49566
|
+
treeRef.current = tree;
|
|
49567
|
+
}, [tree]);
|
|
49568
|
+
// Handling window resize events
|
|
49569
|
+
reactExports.useEffect(() => {
|
|
49570
|
+
const resizeEventListener = () => debouncedUpdateGeometry(treeRef.current, 'resize');
|
|
49571
|
+
window.addEventListener('resize', resizeEventListener);
|
|
49572
|
+
return () => window.removeEventListener('resize', resizeEventListener);
|
|
49573
|
+
}, [debouncedUpdateGeometry]);
|
|
49574
|
+
// Handling DOM mutations
|
|
49575
|
+
reactExports.useEffect(() => {
|
|
49576
|
+
if (!rootContainerRef.current)
|
|
49577
|
+
return;
|
|
49578
|
+
const observer = new MutationObserver(() => debouncedUpdateGeometry(treeRef.current, 'mutation'));
|
|
49579
|
+
observer.observe(rootContainerRef.current, {
|
|
49580
|
+
childList: true,
|
|
49581
|
+
subtree: true,
|
|
49582
|
+
attributes: true,
|
|
49583
|
+
});
|
|
49584
|
+
return () => observer.disconnect();
|
|
49585
|
+
}, [debouncedUpdateGeometry, rootContainerRef]);
|
|
49586
|
+
};
|
|
49587
|
+
|
|
49147
49588
|
const RootRenderer = () => {
|
|
49589
|
+
const rootContainerRef = reactExports.useRef(null);
|
|
49590
|
+
const tree = useTreeStore((state) => state.tree);
|
|
49591
|
+
useCanvasGeometryUpdates({ tree, rootContainerRef });
|
|
49148
49592
|
useEditorSubscriber();
|
|
49149
49593
|
const breakpoints = useTreeStore((state) => state.breakpoints);
|
|
49150
|
-
const containerRef = reactExports.useRef(null);
|
|
49151
49594
|
const { resolveDesignValue } = useBreakpoints(breakpoints);
|
|
49152
|
-
const tree = useTreeStore((state) => state.tree);
|
|
49153
49595
|
// If the root blockId is defined but not the default string, it is the entry ID
|
|
49154
49596
|
// of the experience/ pattern to properly detect circular dependencies.
|
|
49155
49597
|
const rootBlockId = tree.root.data.blockId ?? ROOT_ID;
|
|
49156
49598
|
const wrappingPatternIds = rootBlockId !== ROOT_ID ? new Set([rootBlockId]) : new Set();
|
|
49157
49599
|
return (React$1.createElement(React$1.Fragment, null,
|
|
49158
|
-
React$1.createElement("div", { "data-ctfl-root": true, className: styles$2.rootContainer, ref:
|
|
49600
|
+
React$1.createElement("div", { "data-ctfl-root": true, className: styles$2.rootContainer, ref: rootContainerRef }, !tree.root.children.length ? (React$1.createElement(EmptyCanvasMessage, null)) : (tree.root.children.map((topLevelChildNode) => (React$1.createElement(EditorBlock, { key: topLevelChildNode.data.id, node: topLevelChildNode, resolveDesignValue: resolveDesignValue, wrappingPatternIds: wrappingPatternIds })))))));
|
|
49159
49601
|
};
|
|
49160
49602
|
|
|
49161
49603
|
const useInitializeEditor = () => {
|