From c90c9c4b3d26baf81583054fc761cbb50fb1a949 Mon Sep 17 00:00:00 2001 From: mohamedsalem401 Date: Tue, 8 Oct 2024 18:57:45 +0300 Subject: [PATCH] Change minimum undroppable dimensions --- .../src/utils/sorter/CanvasComponentNode.ts | 4 ++-- packages/core/src/utils/sorter/Dimension.ts | 17 ++++++----------- .../src/utils/sorter/DropLocationDeterminer.ts | 2 -- .../core/src/utils/sorter/SortableTreeNode.ts | 4 ++-- packages/core/src/utils/sorter/types.ts | 2 +- 5 files changed, 11 insertions(+), 18 deletions(-) diff --git a/packages/core/src/utils/sorter/CanvasComponentNode.ts b/packages/core/src/utils/sorter/CanvasComponentNode.ts index 9c05fc65a..2495e75f2 100644 --- a/packages/core/src/utils/sorter/CanvasComponentNode.ts +++ b/packages/core/src/utils/sorter/CanvasComponentNode.ts @@ -3,8 +3,8 @@ import { BaseComponentNode } from './BaseComponentNode'; export default class CanvasComponentNode extends BaseComponentNode { protected _dropAreaConfig = { ratio: 0.8, - minDroppableDimension: 8, // 5px - maxUndroppableDimension: 15, // 15px + minUndroppableDimension: 1, // In px + maxUndroppableDimension: 15, // In px }; /** * Get the associated view of this component. diff --git a/packages/core/src/utils/sorter/Dimension.ts b/packages/core/src/utils/sorter/Dimension.ts index 0edf9d7fa..dc8b7e284 100644 --- a/packages/core/src/utils/sorter/Dimension.ts +++ b/packages/core/src/utils/sorter/Dimension.ts @@ -134,18 +134,13 @@ export default class Dimension { position: number, config: DroppableZoneConfig, ): { newSize: number; newPosition: number } { - const { ratio, minDroppableDimension, maxUndroppableDimension } = config; + const { ratio, minUndroppableDimension: minUnDroppableDimension, maxUndroppableDimension } = config; - // Calculate the desired new size based on the ratio, ensuring it doesn't go below minDroppable - const minSize = Math.min(size, minDroppableDimension); - let newSize = Math.max(size * ratio, minSize); - - // Adjust the newSize based on maxUndroppable to prevent exceeding the maximum undroppable area - newSize = size - Math.min(size - newSize, maxUndroppableDimension); - - // Calculate the new position by adjusting it by half the reduction - const reduction = size - newSize; - const newPosition = position + reduction / 2; + let undroppableDimension = (size * (1 - ratio)) / 2; + undroppableDimension = Math.max(undroppableDimension, minUnDroppableDimension); + undroppableDimension = Math.min(undroppableDimension, maxUndroppableDimension); + const newSize = size - undroppableDimension * 2; + const newPosition = position + undroppableDimension; return { newSize, newPosition }; } diff --git a/packages/core/src/utils/sorter/DropLocationDeterminer.ts b/packages/core/src/utils/sorter/DropLocationDeterminer.ts index 2e95f1b7e..736573704 100644 --- a/packages/core/src/utils/sorter/DropLocationDeterminer.ts +++ b/packages/core/src/utils/sorter/DropLocationDeterminer.ts @@ -140,8 +140,6 @@ export class DropLocationDeterminer> ext !placeholderDimensions.equals(this.lastMoveData.placeholderDimensions) || placement !== this.lastMoveData.placement; if (placeHolderMoved) { - console.log('🚀 ~ DropLocationDeterminer { protected _dragSource: DragSource; protected _dropAreaConfig: DroppableZoneConfig = { ratio: 1, - minDroppableDimension: Number.MAX_VALUE, - maxUndroppableDimension: 0, + minUndroppableDimension: 0, // In px + maxUndroppableDimension: 0, // In px }; /** The dimensions of the node. */ public nodeDimensions?: Dimension; diff --git a/packages/core/src/utils/sorter/types.ts b/packages/core/src/utils/sorter/types.ts index 06cecf884..fc7e7d38d 100644 --- a/packages/core/src/utils/sorter/types.ts +++ b/packages/core/src/utils/sorter/types.ts @@ -28,7 +28,7 @@ export type Placement = 'inside' | 'before' | 'after'; export type DroppableZoneConfig = { ratio: number; - minDroppableDimension: number; // In px + minUndroppableDimension: number; // In px maxUndroppableDimension: number; // In px };