From a4df0d94cbfece447ed1bdaa242c91fc4cc44ecf Mon Sep 17 00:00:00 2001 From: Damien TUPINIER Date: Fri, 8 Apr 2022 19:18:20 +0200 Subject: [PATCH] Bug with restrictRect and resizable --- .../@interactjs/modifiers/restrict/pointer.ts | 41 +++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/packages/@interactjs/modifiers/restrict/pointer.ts b/packages/@interactjs/modifiers/restrict/pointer.ts index 0a9d8c1c3..386805a5f 100644 --- a/packages/@interactjs/modifiers/restrict/pointer.ts +++ b/packages/@interactjs/modifiers/restrict/pointer.ts @@ -65,7 +65,7 @@ function start ({ rect, startOffset, state, interaction, pageCoords }: ModifierA state.offset = offset } -function set ({ coords, interaction, state }: ModifierArg) { +function set ({ coords, interaction, state, edges }: ModifierArg) { const { options, offset } = state const restriction = getRestrictionRect(options.restriction, interaction, coords) @@ -74,8 +74,43 @@ function set ({ coords, interaction, state }: ModifierArg) { const rect = rectUtils.xywhToTlbr(restriction) - coords.x = Math.max(Math.min(rect.right - offset.right, coords.x), rect.left + offset.left) - coords.y = Math.max(Math.min(rect.bottom - offset.bottom, coords.y), rect.top + offset.top) + // Configure coords X + switch (true) { + // Drag + case edges.left && edges.right: + coords.x = Math.max(Math.min(rect.right - offset.right, coords.x), rect.left + offset.left) + break + // Resize + case edges.left: + coords.x = Math.max(rect.left + offset.left, coords.x) + break + case edges.right: + coords.x = Math.min(rect.right - offset.right, coords.x) + break + // Other + default: + coords.x = Math.max(Math.min(rect.right - offset.right, coords.x), rect.left + offset.left) + break + } + + // Configure coords Y + switch (true) { + // Drag + case edges.top && edges.bottom: + coords.y = Math.max(Math.min(rect.bottom - offset.bottom, coords.y), rect.top + offset.top) + break + // Resize + case edges.top: + coords.y = Math.max(rect.top + offset.top, coords.y) + break + case edges.bottom: + coords.y = Math.min(rect.bottom - offset.bottom, coords.y) + break + // Other + default: + coords.y = Math.max(Math.min(rect.bottom - offset.bottom, coords.y), rect.top + offset.top) + break + } } export function getRestrictionRect (