refactor: centralize selection key helper
This commit is contained in:
parent
19279174e6
commit
e296fc0979
@ -5,6 +5,7 @@ import { Button, Space } from 'antd';
|
|||||||
import type { ResizeHandle } from './types';
|
import type { ResizeHandle } from './types';
|
||||||
import { rectFromPoints } from './geometry';
|
import { rectFromPoints } from './geometry';
|
||||||
import type { ContextMenuState } from './ContextMenu';
|
import type { ContextMenuState } from './ContextMenu';
|
||||||
|
import { selectionKeyOf } from './selection';
|
||||||
|
|
||||||
export interface CanvasProps {
|
export interface CanvasProps {
|
||||||
screen: Screen;
|
screen: Screen;
|
||||||
@ -40,12 +41,6 @@ function isPrimaryButton(e: React.PointerEvent | PointerEvent): boolean {
|
|||||||
return (e as PointerEvent).buttons === 1 || (e as PointerEvent).button === 0;
|
return (e as PointerEvent).buttons === 1 || (e as PointerEvent).button === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectionKeyOf(ids: string[]): string {
|
|
||||||
// Keep stable regardless of selection order.
|
|
||||||
// This avoids false mismatches between context-menu state and reducer state.
|
|
||||||
return [...ids].sort().join('|');
|
|
||||||
}
|
|
||||||
|
|
||||||
export function Canvas(props: CanvasProps) {
|
export function Canvas(props: CanvasProps) {
|
||||||
const ref = useRef<HTMLDivElement | null>(null);
|
const ref = useRef<HTMLDivElement | null>(null);
|
||||||
const [box, setBox] = useState<{ x1: number; y1: number; x2: number; y2: number } | null>(null);
|
const [box, setBox] = useState<{ x1: number; y1: number; x2: number; y2: number } | null>(null);
|
||||||
|
|||||||
@ -1,11 +1,7 @@
|
|||||||
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
||||||
import { Typography } from 'antd';
|
import { Typography } from 'antd';
|
||||||
|
|
||||||
function selectionKeyOf(ids: string[]): string {
|
import { selectionKeyOf } from './selection';
|
||||||
// Keep stable regardless of selection order.
|
|
||||||
// This avoids false mismatches between context-menu state and reducer state.
|
|
||||||
return [...ids].sort().join('|');
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ContextMenuState =
|
export type ContextMenuState =
|
||||||
| {
|
| {
|
||||||
|
|||||||
5
packages/editor/src/editor/selection.ts
Normal file
5
packages/editor/src/editor/selection.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export function selectionKeyOf(ids: string[]): string {
|
||||||
|
// Keep stable regardless of selection order.
|
||||||
|
// This avoids false mismatches between context-menu state and reducer state.
|
||||||
|
return [...ids].sort().join('|');
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user