2021-06-23 14:39:14 +00:00
|
|
|
import { Data } from 'types'
|
2021-06-24 08:18:14 +00:00
|
|
|
import { getSelectedIds } from 'utils'
|
2021-06-23 14:39:14 +00:00
|
|
|
|
2021-06-24 12:34:43 +00:00
|
|
|
export const rectangleId = '1f6c251c-e12e-40b4-8dd2-c1847d80b72f'
|
|
|
|
export const arrowId = '5ca167d7-54de-47c9-aa8f-86affa25e44d'
|
|
|
|
|
2021-06-23 12:46:16 +00:00
|
|
|
interface PointerOptions {
|
|
|
|
id?: string
|
|
|
|
x?: number
|
|
|
|
y?: number
|
|
|
|
shiftKey?: boolean
|
|
|
|
altKey?: boolean
|
2021-06-23 14:39:14 +00:00
|
|
|
ctrlKey?: boolean
|
2021-06-23 12:46:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function point(
|
|
|
|
options: PointerOptions = {} as PointerOptions
|
|
|
|
): PointerEvent {
|
|
|
|
const {
|
|
|
|
id = '1',
|
|
|
|
x = 0,
|
|
|
|
y = 0,
|
|
|
|
shiftKey = false,
|
|
|
|
altKey = false,
|
2021-06-23 14:39:14 +00:00
|
|
|
ctrlKey = false,
|
2021-06-23 12:46:16 +00:00
|
|
|
} = options
|
|
|
|
|
|
|
|
return {
|
|
|
|
shiftKey,
|
|
|
|
altKey,
|
2021-06-23 14:39:14 +00:00
|
|
|
ctrlKey,
|
2021-06-23 12:46:16 +00:00
|
|
|
pointerId: id,
|
|
|
|
clientX: x,
|
|
|
|
clientY: y,
|
|
|
|
} as any
|
|
|
|
}
|
2021-06-23 14:39:14 +00:00
|
|
|
|
|
|
|
export function idsAreSelected(
|
|
|
|
data: Data,
|
|
|
|
ids: string[],
|
|
|
|
strict = true
|
|
|
|
): boolean {
|
|
|
|
const selectedIds = getSelectedIds(data)
|
|
|
|
return (
|
|
|
|
(strict ? selectedIds.size === ids.length : true) &&
|
|
|
|
ids.every((id) => selectedIds.has(id))
|
|
|
|
)
|
|
|
|
}
|
2021-06-25 10:28:52 +00:00
|
|
|
|
|
|
|
export async function asyncDelay<T>(fn: () => T): Promise<T> {
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
setTimeout(() => {
|
|
|
|
resolve(fn())
|
|
|
|
}, 100)
|
|
|
|
})
|
|
|
|
}
|