feat(editor): gfx template package (#11480)

This commit is contained in:
Saul-Mirone
2025-04-06 12:24:13 +00:00
parent 41499c1cd6
commit bb1270061a
35 changed files with 189 additions and 42 deletions
@@ -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);
}