mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-25 14:28:51 +08:00
fix(editor): data in the database will be completely overwritten in some cases (#10318)
This commit is contained in:
@@ -34,8 +34,6 @@ import {
|
|||||||
} from './properties/index.js';
|
} from './properties/index.js';
|
||||||
import {
|
import {
|
||||||
addProperty,
|
addProperty,
|
||||||
applyCellsUpdate,
|
|
||||||
applyPropertyUpdate,
|
|
||||||
copyCellsByProperty,
|
copyCellsByProperty,
|
||||||
deleteRows,
|
deleteRows,
|
||||||
deleteView,
|
deleteView,
|
||||||
@@ -169,7 +167,6 @@ export class DatabaseBlockDataSource extends DataSourceBase {
|
|||||||
columnId: propertyId,
|
columnId: propertyId,
|
||||||
value: newValue,
|
value: newValue,
|
||||||
});
|
});
|
||||||
applyCellsUpdate(this._model);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,7 +196,6 @@ export class DatabaseBlockDataSource extends DataSourceBase {
|
|||||||
insertToPosition,
|
insertToPosition,
|
||||||
property.create(this.newPropertyName())
|
property.create(this.newPropertyName())
|
||||||
);
|
);
|
||||||
applyPropertyUpdate(this._model);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,7 +279,6 @@ export class DatabaseBlockDataSource extends DataSourceBase {
|
|||||||
propertyDataSet(propertyId: string, data: Record<string, unknown>): void {
|
propertyDataSet(propertyId: string, data: Record<string, unknown>): void {
|
||||||
this._runCapture();
|
this._runCapture();
|
||||||
this.updateProperty(propertyId, () => ({ data }));
|
this.updateProperty(propertyId, () => ({ data }));
|
||||||
applyPropertyUpdate(this._model);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
propertyDataTypeGet(propertyId: string): TypeInstance | undefined {
|
propertyDataTypeGet(propertyId: string): TypeInstance | undefined {
|
||||||
@@ -337,7 +332,6 @@ export class DatabaseBlockDataSource extends DataSourceBase {
|
|||||||
schema
|
schema
|
||||||
);
|
);
|
||||||
copyCellsByProperty(this._model, copyId, id);
|
copyCellsByProperty(this._model, copyId, id);
|
||||||
applyPropertyUpdate(this._model);
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,7 +360,6 @@ export class DatabaseBlockDataSource extends DataSourceBase {
|
|||||||
propertyNameSet(propertyId: string, name: string): void {
|
propertyNameSet(propertyId: string, name: string): void {
|
||||||
this.doc.captureSync();
|
this.doc.captureSync();
|
||||||
this.updateProperty(propertyId, () => ({ name }));
|
this.updateProperty(propertyId, () => ({ name }));
|
||||||
applyPropertyUpdate(this._model);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override propertyReadonlyGet(propertyId: string): boolean {
|
override propertyReadonlyGet(propertyId: string): boolean {
|
||||||
@@ -421,7 +414,6 @@ export class DatabaseBlockDataSource extends DataSourceBase {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
updateCells(this._model, propertyId, cells);
|
updateCells(this._model, propertyId, cells);
|
||||||
applyPropertyUpdate(this._model);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rowAdd(insertPosition: InsertToPosition | number): string {
|
rowAdd(insertPosition: InsertToPosition | number): string {
|
||||||
|
|||||||
@@ -37,24 +37,6 @@ export function addProperty(
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function applyCellsUpdate(model: DatabaseBlockModel) {
|
|
||||||
model.doc.updateBlock(model, {
|
|
||||||
cells: model.cells,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function applyPropertyUpdate(model: DatabaseBlockModel) {
|
|
||||||
model.doc.updateBlock(model, {
|
|
||||||
columns: model.columns,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function applyViewsUpdate(model: DatabaseBlockModel) {
|
|
||||||
model.doc.updateBlock(model, {
|
|
||||||
views: model.views,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function copyCellsByProperty(
|
export function copyCellsByProperty(
|
||||||
model: DatabaseBlockModel,
|
model: DatabaseBlockModel,
|
||||||
fromId: Column['id'],
|
fromId: Column['id'],
|
||||||
@@ -156,7 +138,6 @@ export function moveViewTo(
|
|||||||
arr => insertPositionToIndex(position, arr)
|
arr => insertPositionToIndex(position, arr)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
applyViewsUpdate(model);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateCell(
|
export function updateCell(
|
||||||
@@ -255,6 +236,5 @@ export const updateView = <ViewData extends ViewBasicDataType>(
|
|||||||
return { ...v, ...update(v as ViewData) };
|
return { ...v, ...update(v as ViewData) };
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
applyViewsUpdate(model);
|
|
||||||
};
|
};
|
||||||
export const DATABASE_CONVERT_WHITE_LIST = ['affine:list', 'affine:paragraph'];
|
export const DATABASE_CONVERT_WHITE_LIST = ['affine:list', 'affine:paragraph'];
|
||||||
|
|||||||
Reference in New Issue
Block a user