fix
This commit is contained in:
@@ -17,23 +17,6 @@ export const ANGULAR_DAMPING = 11;
|
||||
export const TORQUE_TO_ACCELERATION = 0.006;
|
||||
export const SETTLE_ANGULAR_VELOCITY = 1.2;
|
||||
|
||||
const getNodeEnv = () => {
|
||||
if (typeof globalThis === 'undefined') {
|
||||
return undefined;
|
||||
}
|
||||
const proc = globalThis.process;
|
||||
if (!proc || typeof proc !== 'object') {
|
||||
return undefined;
|
||||
}
|
||||
const env = proc.env;
|
||||
if (!env || typeof env !== 'object') {
|
||||
return undefined;
|
||||
}
|
||||
return env.NODE_ENV;
|
||||
};
|
||||
|
||||
const isDevEnvironment = () => getNodeEnv() !== 'production';
|
||||
|
||||
export const applyDomTransform = (
|
||||
node,
|
||||
{
|
||||
@@ -433,17 +416,6 @@ export class WorkspaceEngine {
|
||||
}
|
||||
|
||||
updateConfig({ allowLayoutPersistence, tenantId, viewId }) {
|
||||
if (isDevEnvironment()) {
|
||||
console.log('[desk][config] updateConfig -> received', {
|
||||
allowLayoutPersistence,
|
||||
tenantId,
|
||||
viewId,
|
||||
currentAllow: this.allowLayoutPersistence,
|
||||
currentTenant: this.tenantId,
|
||||
currentView: this.viewId,
|
||||
initialLoadDone: this.initialLoadDone,
|
||||
});
|
||||
}
|
||||
const allowChanged =
|
||||
typeof allowLayoutPersistence === 'boolean'
|
||||
&& allowLayoutPersistence !== this.allowLayoutPersistence;
|
||||
@@ -451,9 +423,6 @@ export class WorkspaceEngine {
|
||||
const viewChanged = viewId !== undefined && viewId !== this.viewId;
|
||||
|
||||
if (!allowChanged && !tenantChanged && !viewChanged) {
|
||||
if (isDevEnvironment()) {
|
||||
console.log('[desk][config] updateConfig -> no changes');
|
||||
}
|
||||
if (
|
||||
this.allowLayoutPersistence
|
||||
&& this.tenantId
|
||||
@@ -461,9 +430,6 @@ export class WorkspaceEngine {
|
||||
&& !this.initialLoadDone
|
||||
&& !this.loadingPersisted
|
||||
) {
|
||||
if (isDevEnvironment()) {
|
||||
console.log('[desk][config] updateConfig -> triggering load for pending persistence');
|
||||
}
|
||||
this.loadPersistedLayout();
|
||||
}
|
||||
return;
|
||||
@@ -480,9 +446,6 @@ export class WorkspaceEngine {
|
||||
}
|
||||
|
||||
if (!this.allowLayoutPersistence) {
|
||||
if (isDevEnvironment()) {
|
||||
console.log('[desk][config] updateConfig -> persistence disabled, clearing state');
|
||||
}
|
||||
this.persistedLayout = new Map();
|
||||
this.layoutDirty = false;
|
||||
this.emit();
|
||||
@@ -490,22 +453,10 @@ export class WorkspaceEngine {
|
||||
}
|
||||
|
||||
if (!this.tenantId || !this.viewId) {
|
||||
if (isDevEnvironment()) {
|
||||
console.log('[desk][config] updateConfig -> missing tenant/view, waiting', {
|
||||
tenantId: this.tenantId,
|
||||
viewId: this.viewId,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.initialLoadDone) {
|
||||
if (isDevEnvironment()) {
|
||||
console.log('[desk][config] updateConfig -> fetching persisted layout', {
|
||||
tenantId: this.tenantId,
|
||||
viewId: this.viewId,
|
||||
});
|
||||
}
|
||||
this.loadPersistedLayout();
|
||||
}
|
||||
}
|
||||
@@ -522,14 +473,6 @@ export class WorkspaceEngine {
|
||||
this.ensureLayoutForItems();
|
||||
}
|
||||
this.recalcVisibleDocIds();
|
||||
if (isDevEnvironment()) {
|
||||
console.log('[desk][config] setItems', {
|
||||
itemCount: this.items.length,
|
||||
canGenerateLayoutImmediately,
|
||||
allowLayoutPersistence: this.allowLayoutPersistence,
|
||||
initialLoadDone: this.initialLoadDone,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setDocumentLookup(map) {
|
||||
@@ -563,14 +506,6 @@ export class WorkspaceEngine {
|
||||
this.ensureLayoutForItems();
|
||||
this.recalcVisibleDocIds();
|
||||
this.emit();
|
||||
if (isDevEnvironment()) {
|
||||
console.log('[desk][config] setCanvasSize', {
|
||||
width,
|
||||
height,
|
||||
allowLayoutPersistence: this.allowLayoutPersistence,
|
||||
initialLoadDone: this.initialLoadDone,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setDraggingId(docId) {
|
||||
@@ -909,31 +844,15 @@ export class WorkspaceEngine {
|
||||
}
|
||||
|
||||
ensureLayoutForItems() {
|
||||
if (this.allowLayoutPersistence && !this.initialLoadDone) {
|
||||
if (isDevEnvironment()) {
|
||||
console.log('[desk][layout] ensureLayoutForItems -> waiting for persisted layout to load');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const persistenceReady = !this.allowLayoutPersistence || !this.tenantId || !this.viewId || this.initialLoadDone;
|
||||
const canvasReady = Boolean(this.canvasSize.width && this.canvasSize.height);
|
||||
const sizesReady = !this.items.some((doc) => !this.ensureDocumentSize(doc));
|
||||
|
||||
if (!persistenceReady) {
|
||||
if (isDevEnvironment()) {
|
||||
console.log('[desk][layout] ensureLayoutForItems -> waiting for persisted layout to load', {
|
||||
allowLayoutPersistence: this.allowLayoutPersistence,
|
||||
initialLoadDone: this.initialLoadDone,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!canvasReady) {
|
||||
if (isDevEnvironment()) {
|
||||
console.log('[desk][layout] ensureLayoutForItems -> canvas missing size', this.canvasSize);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!this.items.length) {
|
||||
@@ -945,9 +864,6 @@ export class WorkspaceEngine {
|
||||
}
|
||||
|
||||
if (!sizesReady) {
|
||||
if (isDevEnvironment()) {
|
||||
console.log('[desk][layout] ensureLayoutForItems -> waiting for document sizes');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -956,11 +872,8 @@ export class WorkspaceEngine {
|
||||
const canvasWidth = this.canvasSize.width || DESK_DEFAULT_CANVAS_WIDTH;
|
||||
const canvasHeight = this.canvasSize.height || DESK_DEFAULT_CANVAS_HEIGHT;
|
||||
const docsNeedingLayout = [];
|
||||
let generatedCount = 0;
|
||||
|
||||
const currentEntries = new Map(this.layout);
|
||||
let persistedAppliedCount = 0;
|
||||
let reusedCurrentCount = 0;
|
||||
|
||||
this.items.forEach((doc) => {
|
||||
if (!doc?.id) {
|
||||
@@ -982,8 +895,6 @@ export class WorkspaceEngine {
|
||||
|
||||
const persisted = this.persistedLayout.get(docKey);
|
||||
const currentEntry = currentEntries.get(docKey) || null;
|
||||
const hasPersisted = Boolean(persisted);
|
||||
const hasCurrent = !hasPersisted && Boolean(currentEntry);
|
||||
let existing = persisted || currentEntry;
|
||||
if (existing) {
|
||||
const defaultCenterX = (minCenterX + maxCenterX) / 2;
|
||||
@@ -996,11 +907,6 @@ export class WorkspaceEngine {
|
||||
const z = existing.z ?? maxZ;
|
||||
maxZ = Math.max(maxZ, z);
|
||||
next.set(docKey, { centerX, centerY, rotation, z, width: docWidth, height: docHeight });
|
||||
if (hasPersisted) {
|
||||
persistedAppliedCount += 1;
|
||||
} else if (hasCurrent) {
|
||||
reusedCurrentCount += 1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1027,31 +933,14 @@ export class WorkspaceEngine {
|
||||
);
|
||||
generatedLayout.forEach((entry, docId) => {
|
||||
next.set(docId, entry);
|
||||
generatedCount += 1;
|
||||
});
|
||||
maxZ = Math.max(maxZ, updatedMaxZ);
|
||||
if (isDevEnvironment()) {
|
||||
console.log('[desk][layout] ensureLayoutForItems -> generated layout for items', {
|
||||
requested: docsNeedingLayout.length,
|
||||
applied: generatedCount,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
this.layout = next;
|
||||
this.zCounter = Math.max(this.zCounter, maxZ);
|
||||
this.syncLayoutSnapshot();
|
||||
this.recalcVisibleDocIds();
|
||||
if (isDevEnvironment()) {
|
||||
console.log('[desk][layout] ensureLayoutForItems -> applied layout', {
|
||||
items: this.items.length,
|
||||
layoutSize: this.layout.size,
|
||||
persistedAppliedCount,
|
||||
reusedCurrentCount,
|
||||
generatedCount,
|
||||
initialLoadDone: this.initialLoadDone,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
recalcVisibleDocIds() {
|
||||
@@ -1222,38 +1111,14 @@ export class WorkspaceEngine {
|
||||
|
||||
async loadPersistedLayout() {
|
||||
if (!this.allowLayoutPersistence || !this.tenantId || !this.viewId) {
|
||||
if (isDevEnvironment()) {
|
||||
console.log('[desk][load] loadPersistedLayout -> aborted, missing config', {
|
||||
allowLayoutPersistence: this.allowLayoutPersistence,
|
||||
tenantId: this.tenantId,
|
||||
viewId: this.viewId,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (this.loadingPersisted || this.initialLoadDone) {
|
||||
if (isDevEnvironment()) {
|
||||
console.log('[desk][load] loadPersistedLayout -> already loading or done', {
|
||||
loadingPersisted: this.loadingPersisted,
|
||||
initialLoadDone: this.initialLoadDone,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.loadingPersisted = true;
|
||||
try {
|
||||
if (isDevEnvironment()) {
|
||||
console.log('[desk][load] loadPersistedLayout -> fetching', {
|
||||
tenantId: this.tenantId,
|
||||
viewId: this.viewId,
|
||||
});
|
||||
}
|
||||
const records = await fetchLayoutRecords({ tenantId: this.tenantId, viewId: this.viewId });
|
||||
if (isDevEnvironment()) {
|
||||
console.log('[desk][load] loadPersistedLayout -> fetched records', {
|
||||
count: records.length,
|
||||
});
|
||||
}
|
||||
const map = new Map();
|
||||
records.forEach((record) => {
|
||||
if (!record || !record.documentId) {
|
||||
@@ -1276,12 +1141,6 @@ export class WorkspaceEngine {
|
||||
this.layoutSnapshot = new Map(this.layout);
|
||||
this.ensureLayoutForItems();
|
||||
this.initialLoadDone = true;
|
||||
if (isDevEnvironment()) {
|
||||
console.log('[desk][load] loadPersistedLayout -> applied persisted layout', {
|
||||
layoutSize: this.layout.size,
|
||||
persistedSize: this.persistedLayout.size,
|
||||
});
|
||||
}
|
||||
this.emit();
|
||||
} catch (error) {
|
||||
console.warn('[desk] Failed to load persisted layout', error);
|
||||
@@ -1292,11 +1151,6 @@ export class WorkspaceEngine {
|
||||
if (!this.layout.size) {
|
||||
this.ensureLayoutForItems();
|
||||
}
|
||||
if (isDevEnvironment()) {
|
||||
console.log('[desk][load] loadPersistedLayout -> fallback to generated layout', {
|
||||
layoutSize: this.layout.size,
|
||||
});
|
||||
}
|
||||
this.emit();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user