@contentful/experiences-visual-editor-react 1.0.6 → 1.0.7-beta.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 +37 -37
- package/dist/index.js.map +1 -1
- package/dist/renderApp.js +37 -37
- package/dist/renderApp.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -198,6 +198,9 @@ const tryParseMessage = (event) => {
|
|
|
198
198
|
return eventData;
|
|
199
199
|
};
|
|
200
200
|
|
|
201
|
+
// Keep this for backwards compatilibity - deleting this would be a breaking change
|
|
202
|
+
// because existing components on a users experience will have the width value as fill
|
|
203
|
+
// rather than 100%
|
|
201
204
|
const transformFill = (value) => (value === 'fill' ? '100%' : value);
|
|
202
205
|
const transformGridColumn = (span) => {
|
|
203
206
|
if (!span) {
|
|
@@ -368,7 +371,7 @@ const buildCfStyles = ({ cfHorizontalAlignment, cfVerticalAlignment, cfFlexDirec
|
|
|
368
371
|
};
|
|
369
372
|
/**
|
|
370
373
|
* Container/section default behavior:
|
|
371
|
-
* Default height => height: EMPTY_CONTAINER_HEIGHT
|
|
374
|
+
* Default height => height: EMPTY_CONTAINER_HEIGHT
|
|
372
375
|
* If a container component has children => height: 'fit-content'
|
|
373
376
|
*/
|
|
374
377
|
const calculateNodeDefaultHeight = ({ blockId, children, value, }) => {
|
|
@@ -494,7 +497,7 @@ const getOptimizedBackgroundImageAsset = (file, widthStyle, quality = '100%', fo
|
|
|
494
497
|
};
|
|
495
498
|
|
|
496
499
|
const MAX_WIDTH_ALLOWED = 4000;
|
|
497
|
-
const getOptimizedImageAsset = (file, sizes, quality = '100%', format) => {
|
|
500
|
+
const getOptimizedImageAsset = ({ file, sizes, loading, quality = '100%', format, }) => {
|
|
498
501
|
const qualityNumber = Number(quality.replace('%', ''));
|
|
499
502
|
if (!validateParams(file, qualityNumber, format)) ;
|
|
500
503
|
const url = file.url;
|
|
@@ -514,6 +517,7 @@ const getOptimizedImageAsset = (file, sizes, quality = '100%', format) => {
|
|
|
514
517
|
srcSet,
|
|
515
518
|
sizes,
|
|
516
519
|
file,
|
|
520
|
+
loading,
|
|
517
521
|
};
|
|
518
522
|
return optimizedImageAsset;
|
|
519
523
|
};
|
|
@@ -536,7 +540,13 @@ const transformMedia = (asset, variables, resolveDesignValue, variableName, path
|
|
|
536
540
|
return;
|
|
537
541
|
}
|
|
538
542
|
try {
|
|
539
|
-
value = getOptimizedImageAsset(
|
|
543
|
+
value = getOptimizedImageAsset({
|
|
544
|
+
file: asset.fields.file,
|
|
545
|
+
loading: options.loading,
|
|
546
|
+
sizes: options.targetSize,
|
|
547
|
+
quality: options.quality,
|
|
548
|
+
format: options.format,
|
|
549
|
+
});
|
|
540
550
|
return value;
|
|
541
551
|
}
|
|
542
552
|
catch (error) {
|
|
@@ -679,7 +689,7 @@ const builtInStyles = {
|
|
|
679
689
|
type: 'Text',
|
|
680
690
|
group: 'style',
|
|
681
691
|
description: 'The width of the section',
|
|
682
|
-
defaultValue: '
|
|
692
|
+
defaultValue: '100%',
|
|
683
693
|
},
|
|
684
694
|
cfHeight: {
|
|
685
695
|
displayName: 'Height',
|
|
@@ -2166,7 +2176,8 @@ function useDraggablePosition({ draggableId, draggableRef, position }) {
|
|
|
2166
2176
|
const draggingId = useDraggedItemStore((state) => state.onBeforeCaptureId);
|
|
2167
2177
|
const preDragDomRect = useDraggedItemStore((state) => state.domRect);
|
|
2168
2178
|
useEffect(() => {
|
|
2169
|
-
const el = draggableRef?.current
|
|
2179
|
+
const el = draggableRef?.current ??
|
|
2180
|
+
document.querySelector(`[${CTFL_DRAGGING_ELEMENT}][data-cf-node-id="${draggableId}"]`);
|
|
2170
2181
|
if (!isDraggingOnCanvas || draggingId !== draggableId || !el) {
|
|
2171
2182
|
return;
|
|
2172
2183
|
}
|
|
@@ -2540,7 +2551,6 @@ const useComponentProps = ({ node, areEntitiesFetched, resolveDesignValue, rende
|
|
|
2540
2551
|
}),
|
|
2541
2552
|
...(userIsDragging &&
|
|
2542
2553
|
isContentfulStructureComponent(node?.data.blockId) &&
|
|
2543
|
-
node?.data.blockId !== CONTENTFUL_COMPONENTS.divider.id &&
|
|
2544
2554
|
node?.data.blockId !== CONTENTFUL_COMPONENTS.columns.id && {
|
|
2545
2555
|
padding: addExtraDropzonePadding(componentStyles.padding?.toString() || '0 0 0 0'),
|
|
2546
2556
|
}),
|
|
@@ -2568,13 +2578,7 @@ const useComponentProps = ({ node, areEntitiesFetched, resolveDesignValue, rende
|
|
|
2568
2578
|
};
|
|
2569
2579
|
const addExtraDropzonePadding = (padding) => padding
|
|
2570
2580
|
.split(' ')
|
|
2571
|
-
.map((value) => {
|
|
2572
|
-
if (value.endsWith('px')) {
|
|
2573
|
-
const parsedValue = parseInt(value.replace(/px$/, ''), 10);
|
|
2574
|
-
return (parsedValue < DRAG_PADDING ? DRAG_PADDING : parsedValue) + 'px';
|
|
2575
|
-
}
|
|
2576
|
-
return `${DRAG_PADDING}px`;
|
|
2577
|
-
})
|
|
2581
|
+
.map((value) => parseFloat(value) === 0 ? `${DRAG_PADDING}px` : `calc(${value} + ${DRAG_PADDING}px)`)
|
|
2578
2582
|
.join(' ');
|
|
2579
2583
|
|
|
2580
2584
|
var PostMessageMethods;
|
|
@@ -3301,7 +3305,7 @@ const getHitboxStyles = ({ direction, zoneDepth, domRect, scrollY, offsetRect, }
|
|
|
3301
3305
|
return {
|
|
3302
3306
|
width: WIDTH,
|
|
3303
3307
|
height: height - HEIGHT,
|
|
3304
|
-
left: right + offsetWidth
|
|
3308
|
+
left: right + offsetWidth + calcOffsetDepth(zoneDepth) - WIDTH / 2,
|
|
3305
3309
|
top: top + HEIGHT / 2 - scrollY,
|
|
3306
3310
|
zIndex: 100 + zoneDepth,
|
|
3307
3311
|
};
|
|
@@ -3325,7 +3329,7 @@ const getHitboxStyles = ({ direction, zoneDepth, domRect, scrollY, offsetRect, }
|
|
|
3325
3329
|
return {
|
|
3326
3330
|
width: width - DRAGGABLE_WIDTH * 2,
|
|
3327
3331
|
height,
|
|
3328
|
-
left: left +
|
|
3332
|
+
left: left + DRAGGABLE_WIDTH,
|
|
3329
3333
|
top: top - scrollY,
|
|
3330
3334
|
zIndex: 1000 + zoneDepth,
|
|
3331
3335
|
};
|
|
@@ -3340,35 +3344,26 @@ const Hitboxes = ({ zoneId, parentZoneId, isEmptyZone }) => {
|
|
|
3340
3344
|
const isDraggingOnCanvas = useDraggedItemStore((state) => state.isDraggingOnCanvas);
|
|
3341
3345
|
const scrollY = useDraggedItemStore((state) => state.scrollY);
|
|
3342
3346
|
const zoneDepth = useMemo(() => getItemDepthFromNode({ id: parentZoneId }, tree.root), [tree, parentZoneId]);
|
|
3343
|
-
const
|
|
3344
|
-
const
|
|
3347
|
+
const zones = useZoneStore((state) => state.zones);
|
|
3348
|
+
const hoveringZone = useZoneStore((state) => state.hoveringZone);
|
|
3345
3349
|
const isHoveringZone = hoveringZone === zoneId;
|
|
3346
|
-
useEffect(() => {
|
|
3347
|
-
/**
|
|
3348
|
-
* A bit hacky but we need to wait a very small amount
|
|
3349
|
-
* of time to fetch the dom getBoundingClientRect once a
|
|
3350
|
-
* drag starts because we need pre-drag styles like padding
|
|
3351
|
-
* applied before we calculate positions of hitboxes
|
|
3352
|
-
*/
|
|
3353
|
-
setTimeout(() => {
|
|
3354
|
-
setFetchDomRect(Date.now());
|
|
3355
|
-
}, 50);
|
|
3356
|
-
}, [isDraggingOnCanvas]);
|
|
3357
3350
|
const hitboxContainer = useMemo(() => {
|
|
3358
3351
|
return document.querySelector('[data-ctfl-hitboxes]');
|
|
3359
3352
|
}, []);
|
|
3360
3353
|
const domRect = useMemo(() => {
|
|
3354
|
+
if (!isDraggingOnCanvas)
|
|
3355
|
+
return;
|
|
3361
3356
|
return document.querySelector(`[${CTFL_ZONE_ID}="${zoneId}"]`)?.getBoundingClientRect();
|
|
3362
3357
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3363
|
-
}, [zoneId,
|
|
3358
|
+
}, [zoneId, isDraggingOnCanvas]);
|
|
3364
3359
|
// Use the size of the cloned dragging element to offset the position of the hitboxes
|
|
3365
3360
|
// So that when dragging causes a dropzone to expand, the hitboxes will be in the correct position
|
|
3366
3361
|
const offsetRect = useMemo(() => {
|
|
3367
|
-
if (isEmptyZone || !isHoveringZone)
|
|
3362
|
+
if (!isDraggingOnCanvas || isEmptyZone || !isHoveringZone)
|
|
3368
3363
|
return;
|
|
3369
3364
|
return document.querySelector(`[${CTFL_DRAGGING_ELEMENT}]`)?.getBoundingClientRect();
|
|
3370
3365
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3371
|
-
}, [isEmptyZone, isHoveringZone,
|
|
3366
|
+
}, [isEmptyZone, isHoveringZone, isDraggingOnCanvas]);
|
|
3372
3367
|
const zoneDirection = zones[parentZoneId]?.direction || 'vertical';
|
|
3373
3368
|
const isVertical = zoneDirection === 'vertical';
|
|
3374
3369
|
const isRoot = parentZoneId === ROOT_ID;
|
|
@@ -4376,7 +4371,7 @@ function useCanvasInteractions() {
|
|
|
4376
4371
|
return { onAddComponent, onMoveComponent };
|
|
4377
4372
|
}
|
|
4378
4373
|
|
|
4379
|
-
const TestDNDContainer = ({ onDragEnd, onBeforeDragStart, onDragUpdate, children, }) => {
|
|
4374
|
+
const TestDNDContainer = ({ onDragEnd, onBeforeDragStart, onDragStart, onDragUpdate, children, }) => {
|
|
4380
4375
|
const handleDragStart = (event) => {
|
|
4381
4376
|
const draggedItem = event.nativeEvent;
|
|
4382
4377
|
const start = {
|
|
@@ -4386,6 +4381,7 @@ const TestDNDContainer = ({ onDragEnd, onBeforeDragStart, onDragUpdate, children
|
|
|
4386
4381
|
source: draggedItem.source,
|
|
4387
4382
|
};
|
|
4388
4383
|
onBeforeDragStart(start);
|
|
4384
|
+
onDragStart(start, {});
|
|
4389
4385
|
};
|
|
4390
4386
|
const handleDrag = (event) => {
|
|
4391
4387
|
const draggedItem = event.nativeEvent;
|
|
@@ -4425,10 +4421,12 @@ const DNDProvider = ({ children }) => {
|
|
|
4425
4421
|
const selectedNodeId = useEditorStore((state) => state.selectedNodeId);
|
|
4426
4422
|
const prevSelectedNodeId = useRef(null);
|
|
4427
4423
|
const isTestRun = typeof window !== 'undefined' && Object.prototype.hasOwnProperty.call(window, 'Cypress');
|
|
4428
|
-
const
|
|
4424
|
+
const beforeDragStart = ({ source }) => {
|
|
4429
4425
|
prevSelectedNodeId.current = selectedNodeId;
|
|
4430
|
-
//Unselect the current node when dragging and remove the outline
|
|
4426
|
+
// Unselect the current node when dragging and remove the outline
|
|
4431
4427
|
setSelectedNodeId('');
|
|
4428
|
+
// Set dragging state here to make sure that DnD capture phase has completed
|
|
4429
|
+
setDraggingOnCanvas(true);
|
|
4432
4430
|
sendMessage(OUTGOING_EVENTS.ComponentSelected, {
|
|
4433
4431
|
nodeId: '',
|
|
4434
4432
|
});
|
|
@@ -4437,16 +4435,18 @@ const DNDProvider = ({ children }) => {
|
|
|
4437
4435
|
}
|
|
4438
4436
|
};
|
|
4439
4437
|
const beforeCapture = ({ draggableId }) => {
|
|
4440
|
-
setDraggingOnCanvas(true);
|
|
4441
4438
|
setOnBeforeCaptureId(draggableId);
|
|
4442
4439
|
};
|
|
4440
|
+
const dragStart = (start) => {
|
|
4441
|
+
updateItem(start);
|
|
4442
|
+
};
|
|
4443
4443
|
const dragUpdate = (update) => {
|
|
4444
4444
|
updateItem(update);
|
|
4445
4445
|
};
|
|
4446
4446
|
const dragEnd = (dropResult) => {
|
|
4447
4447
|
setDraggingOnCanvas(false);
|
|
4448
4448
|
setOnBeforeCaptureId('');
|
|
4449
|
-
updateItem(
|
|
4449
|
+
updateItem();
|
|
4450
4450
|
SimulateDnD$1.reset();
|
|
4451
4451
|
if (!dropResult.destination) {
|
|
4452
4452
|
if (!draggedItem?.destination) {
|
|
@@ -4479,7 +4479,7 @@ const DNDProvider = ({ children }) => {
|
|
|
4479
4479
|
nodeId: dropResult.draggableId,
|
|
4480
4480
|
});
|
|
4481
4481
|
};
|
|
4482
|
-
return (React.createElement(DragDropContext, { onBeforeCapture: beforeCapture, onDragUpdate: dragUpdate, onBeforeDragStart: dragStart, onDragEnd: dragEnd }, isTestRun ? (React.createElement(TestDNDContainer, { onDragEnd: dragEnd, onBeforeDragStart: dragStart, onDragUpdate: dragUpdate }, children)) : (children)));
|
|
4482
|
+
return (React.createElement(DragDropContext, { onBeforeCapture: beforeCapture, onDragUpdate: dragUpdate, onBeforeDragStart: beforeDragStart, onDragStart: dragStart, onDragEnd: dragEnd }, isTestRun ? (React.createElement(TestDNDContainer, { onDragEnd: dragEnd, onBeforeDragStart: beforeDragStart, onDragStart: dragStart, onDragUpdate: dragUpdate }, children)) : (children)));
|
|
4483
4483
|
};
|
|
4484
4484
|
|
|
4485
4485
|
const RootRenderer = ({ onChange }) => {
|