Skip to content

Commit

Permalink
fix: fix targetGroups' compare condition
Browse files Browse the repository at this point in the history
  • Loading branch information
daybrush committed Dec 14, 2022
1 parent 4bc6ef5 commit 959a9f0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
17 changes: 14 additions & 3 deletions packages/react-moveable/src/MoveableGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { MIN_NUM, MAX_NUM, TINY_NUM } from "./consts";
import {
getAbsolutePosesByState, equals, unset, rotatePosesInfo,
convertTransformOriginArray,
isDeepArrayEquals,
} from "./utils";
import { minus, plus } from "@scena/matrix";
import { getIntersectionPointsByConstants, getMinMaxs } from "overlap-area";
Expand Down Expand Up @@ -220,6 +221,7 @@ class MoveableGroup extends MoveableManager<GroupableProps> {
public moveables: MoveableManager[] = [];
public transformOrigin = "50% 50%";
public renderGroupRects: GroupRect[] = [];
private _targetGroups: MoveableTargetGroupsType = [];
private _hasFirstTargets = false;

public componentDidMount() {
Expand All @@ -246,9 +248,10 @@ class MoveableGroup extends MoveableManager<GroupableProps> {
const moveables = this.moveables;
const target = state.target! || props.target!;
const checkeds = moveables.map(moveable => ({ finded: false, manager: moveable }));
const targetGroups = this.props.targetGroups || [];
const moveableGroups = findMoveableGroups(
checkeds,
this.props.targetGroups || [],
targetGroups,
);

moveableGroups.push(...checkeds.filter(({ finded }) => !finded).map(({ manager }) => manager));
Expand Down Expand Up @@ -310,6 +313,8 @@ class MoveableGroup extends MoveableManager<GroupableProps> {
this.scale = [1, 1];
}


this._targetGroups = targetGroups;
this.renderGroupRects = renderGroupRects;
const transformOrigin = this.transformOrigin;
const rotation = this.rotation;
Expand Down Expand Up @@ -436,10 +441,16 @@ class MoveableGroup extends MoveableManager<GroupableProps> {
if (isContainerChanged) {
state.container = props.container;
}
const { added, changed, removed } = this.differ.update(props.targets!);
const targets = props.targets!;
const { added, changed, removed } = this.differ.update(targets);
const isTargetChanged = added.length || removed.length;

if (isContainerChanged || isTargetChanged || changed.length) {
if (
isContainerChanged
|| isTargetChanged
|| changed.length
|| targets.length && isDeepArrayEquals(this._targetGroups, props.targetGroups || [])
) {
this.updateRect();
this._hasFirstTargets = true;
}
Expand Down
5 changes: 3 additions & 2 deletions packages/react-moveable/src/ables/Clippable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ export default {
customClipPath,
defaultClipPath,
clipArea, zoom,
groupable,
} = moveable.props;
const {
target, width, height, allMatrix, is3d, left, top,
Expand All @@ -328,7 +329,7 @@ export default {
rotation: rotationRad,
} = moveable.getState();

if (!target) {
if (!target || groupable) {
return [];
}

Expand Down Expand Up @@ -503,7 +504,7 @@ export default {
return this.dragControlStart(moveable, e);
},
drag(moveable: MoveableManagerInterface<ClippableProps, ClippableState>, e: any) {
return this.dragControl(moveable, {...e, isDragTarget: true });
return this.dragControl(moveable, { ...e, isDragTarget: true });
},
dragEnd(moveable: MoveableManagerInterface<ClippableProps, ClippableState>, e: any) {
return this.dragControlEnd(moveable, e);
Expand Down
16 changes: 16 additions & 0 deletions packages/react-moveable/src/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1618,3 +1618,19 @@ export function rotatePosesInfo(poses: number[][], origin: number[], rad: number
result: nextPoses.map(pos => plus(pos, origin)),
};
}



export function isDeepArrayEquals(arr1: any[], arr2: any[]): boolean {
return arr1.length === arr2.length && arr1.every((value1, i) => {
const value2 = arr2[i];
const isArray1 = isArray(value1);
const isArray2 = isArray(value2);
if (isArray1 && isArray2) {
return isDeepArrayEquals(value1, value2);
} else if (!isArray1 && !isArray2) {
return value1 === value2;
}
return false;
});
}

0 comments on commit 959a9f0

Please sign in to comment.