mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: follow mode (#6848)
Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
This commit is contained in:
parent
88a2b286c7
commit
aad8ab0123
28 changed files with 1039 additions and 138 deletions
|
@ -771,11 +771,21 @@ export const queryFocusableElements = (container: HTMLElement | null) => {
|
|||
|
||||
export const isShallowEqual = <
|
||||
T extends Record<string, any>,
|
||||
I extends keyof T,
|
||||
K extends readonly unknown[],
|
||||
>(
|
||||
objA: T,
|
||||
objB: T,
|
||||
comparators?: Record<I, (a: T[I], b: T[I]) => boolean>,
|
||||
comparators?:
|
||||
| { [key in keyof T]?: (a: T[key], b: T[key]) => boolean }
|
||||
| (keyof T extends K[number]
|
||||
? K extends readonly (keyof T)[]
|
||||
? K
|
||||
: {
|
||||
_error: "keys are either missing or include keys not in compared obj";
|
||||
}
|
||||
: {
|
||||
_error: "keys are either missing or include keys not in compared obj";
|
||||
}),
|
||||
debug = false,
|
||||
) => {
|
||||
const aKeys = Object.keys(objA);
|
||||
|
@ -783,8 +793,29 @@ export const isShallowEqual = <
|
|||
if (aKeys.length !== bKeys.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (comparators && Array.isArray(comparators)) {
|
||||
for (const key of comparators) {
|
||||
const ret = objA[key] === objB[key];
|
||||
if (!ret) {
|
||||
if (debug) {
|
||||
console.info(
|
||||
`%cisShallowEqual: ${key} not equal ->`,
|
||||
"color: #8B4000",
|
||||
objA[key],
|
||||
objB[key],
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return aKeys.every((key) => {
|
||||
const comparator = comparators?.[key as I];
|
||||
const comparator = (
|
||||
comparators as { [key in keyof T]?: (a: T[key], b: T[key]) => boolean }
|
||||
)?.[key as keyof T];
|
||||
const ret = comparator
|
||||
? comparator(objA[key], objB[key])
|
||||
: objA[key] === objB[key];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue