This commit is contained in:
2025-11-14 02:35:17 +01:00
parent 6f4ff68062
commit a3c5494bf7
53 changed files with 269 additions and 340 deletions
+1 -8
View File
@@ -419,14 +419,7 @@ const DesktopWorkspace: React.FC<DesktopWorkspaceProps> = ({
commitSize();
if (typeof window.ResizeObserver === 'undefined') {
window.addEventListener('resize', commitSize);
return () => {
window.removeEventListener('resize', commitSize);
};
}
const observer = new window.ResizeObserver(commitSize);
const observer = new ResizeObserver(commitSize);
observer.observe(container);
return () => observer.disconnect();
}, [engine]);
+1 -7
View File
@@ -10,13 +10,7 @@ const openDatabase = (): Promise<IDBDatabase> => {
}
currentDbPromise.value = new Promise((resolve, reject) => {
const dbApi = typeof window !== 'undefined' ? window.indexedDB : null;
if (!dbApi) {
reject(new Error('IndexedDB not available'));
return;
}
const request = dbApi.open(DB_NAME, DB_VERSION);
const request = window.indexedDB.open(DB_NAME, DB_VERSION);
request.onupgradeneeded = () => {
const db = request.result;
@@ -141,7 +141,7 @@ export const useDeskTagInteractions = ({
const { x: pointerX, y: pointerY } = getPointerPosition(event, { fallbackToPage: false });
const { clone, offsetX, offsetY } = createDragPreview(event.currentTarget, pointerX, pointerY) || {};
if (clone && typeof event.dataTransfer.setDragImage === 'function') {
if (clone) {
event.dataTransfer.setDragImage(clone, offsetX || 0, offsetY || 0);
}
+1 -5
View File
@@ -165,13 +165,9 @@ const getEventTargetElement = (event?: PointerEventLike | null): Element | null
if (!event) {
return null;
}
const ElementCtor = typeof window !== 'undefined' ? window.Element : null;
if (!ElementCtor) {
return null;
}
const nativeEvent = 'nativeEvent' in event ? (event as ReactPointerEvent).nativeEvent : null;
const candidate = (event.target as Element | null) || (nativeEvent ? (nativeEvent.target as Element | null) : null);
return candidate instanceof ElementCtor ? candidate : null;
return candidate instanceof Element ? candidate : null;
};
const useDocumentDrag = (options: UseDocumentDragOptions) => {
+15 -20
View File
@@ -618,7 +618,7 @@ export class WorkspaceEngine {
updateConfig({ allowLayoutPersistence, tenantId, viewId }: WorkspaceEngineOptions): void {
const allowChanged =
typeof allowLayoutPersistence === 'boolean'
allowLayoutPersistence !== undefined
&& allowLayoutPersistence !== this.allowLayoutPersistence;
const tenantChanged = tenantId !== undefined && tenantId !== this.tenantId;
const viewChanged = viewId !== undefined && viewId !== this.viewId;
@@ -682,15 +682,11 @@ export class WorkspaceEngine {
}
setEnsureDocumentSize(fn: EnsureDocumentSize): void {
if (typeof fn === 'function') {
this.ensureDocumentSize = fn;
}
this.ensureDocumentSize = fn;
}
setResolveBaseMetrics(fn: ResolveBaseMetrics): void {
if (typeof fn === 'function') {
this.resolveBaseMetrics = fn;
}
this.resolveBaseMetrics = fn;
}
setItemRefs(ref: ItemRefs | null | undefined): void {
@@ -782,18 +778,14 @@ export class WorkspaceEngine {
updateLayoutEntry(
docId: string | number | null,
updater:
| LayoutEntry
| null
| undefined
| ((previous: LayoutEntry | null) => LayoutEntry | null | undefined),
updater: (previous: LayoutEntry | null) => LayoutEntry | null | undefined,
): void {
if (docId == null) {
return;
}
const key = String(docId);
const previous = this.layout.get(key) || null;
const next = typeof updater === 'function' ? updater(previous) : updater;
const next = updater(previous);
if (!next) {
this.layout.delete(key);
} else {
@@ -939,7 +931,9 @@ export class WorkspaceEngine {
let angularVelocity = simulationState.angularVelocity + torqueAcceleration * dt;
angularVelocity = clamp(angularVelocity, -MAX_ANGULAR_VELOCITY, MAX_ANGULAR_VELOCITY);
const dampingConstant = typeof dampingOverride === 'number' ? dampingOverride : ANGULAR_DAMPING;
const dampingConstant = Number.isFinite(dampingOverride)
? Number(dampingOverride)
: ANGULAR_DAMPING;
const dampingFactor = Math.exp(-dampingConstant * dt);
angularVelocity *= dampingFactor;
@@ -1154,8 +1148,12 @@ export class WorkspaceEngine {
if (existing) {
const defaultCenterX = (minCenterX + maxCenterX) / 2;
const defaultCenterY = (minCenterY + maxCenterY) / 2;
const prevCenterX = typeof existing.centerX === 'number' ? existing.centerX : defaultCenterX;
const prevCenterY = typeof existing.centerY === 'number' ? existing.centerY : defaultCenterY;
const prevCenterX = Number.isFinite(existing.centerX)
? Number(existing.centerX)
: defaultCenterX;
const prevCenterY = Number.isFinite(existing.centerY)
? Number(existing.centerY)
: defaultCenterY;
const centerX = clamp(prevCenterX, minCenterX, maxCenterX);
const centerY = clamp(prevCenterY, minCenterY, maxCenterY);
const rotation = existing.rotation ?? 0;
@@ -1201,9 +1199,6 @@ export class WorkspaceEngine {
recalcVisibleDocIds(): void {
const ensureSize = this.ensureDocumentSize;
if (typeof ensureSize !== 'function') {
return;
}
const layoutMap = this.layout;
const canvasWidth = this.canvasSize.width || DESK_DEFAULT_CANVAS_WIDTH;
@@ -1418,7 +1413,7 @@ export const useWorkspaceSnapshot = (
useSyncExternalStoreHook: UseSyncExternalStoreHook,
): WorkspaceSnapshot => {
const useSyncExternalStore = useSyncExternalStoreHook;
if (typeof useSyncExternalStore !== 'function') {
if (!useSyncExternalStore) {
throw new Error('useWorkspaceSnapshot requires useSyncExternalStore hook');
}
return useSyncExternalStore(