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
+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(