mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-05 03:19:52 +08:00
feat(editor): gfx template package (#11480)
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { on } from '@blocksuite/affine-shared/utils';
|
||||
|
||||
export function onClickOutside(target: HTMLElement, fn: () => void) {
|
||||
return on(document, 'click', (evt: MouseEvent) => {
|
||||
if (target.contains(evt.target as Node)) return;
|
||||
|
||||
fn();
|
||||
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
||||
export function cloneDeep<T>(obj: T): T {
|
||||
const seen = new WeakMap();
|
||||
|
||||
const clone = (val: unknown) => {
|
||||
if (typeof val !== 'object' || val === null) return val;
|
||||
if (seen.has(val)) return seen.get(val);
|
||||
|
||||
const copy = Array.isArray(val) ? [] : {};
|
||||
|
||||
seen.set(val, copy);
|
||||
|
||||
Object.keys(val).forEach(key => {
|
||||
// @ts-expect-error deep clone
|
||||
copy[key] = clone(val[key]);
|
||||
});
|
||||
|
||||
return copy;
|
||||
};
|
||||
|
||||
return clone(obj);
|
||||
}
|
||||
Reference in New Issue
Block a user