mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 22:07:09 +08:00
feat(editor): unify block props api (#10888)
Closes: [BS-2707](https://linear.app/affine-design/issue/BS-2707/统一使用props获取和更新block-prop)
This commit is contained in:
@@ -8,6 +8,6 @@ export const todoMeta = createBlockMeta<ListBlockModel>({
|
||||
return false;
|
||||
}
|
||||
|
||||
return (block.model as ListBlockModel).type === 'todo';
|
||||
return (block.model as ListBlockModel).props.type === 'todo';
|
||||
},
|
||||
});
|
||||
|
||||
@@ -47,7 +47,7 @@ export class BlockQueryDataSource extends DataSourceBase {
|
||||
get properties(): string[] {
|
||||
return [
|
||||
...this.meta.properties.map(v => v.key),
|
||||
...this.block.columns.map(v => v.id),
|
||||
...this.block.props.columns.map(v => v.id),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -107,7 +107,9 @@ export class BlockQueryDataSource extends DataSourceBase {
|
||||
|
||||
private newColumnName() {
|
||||
let i = 1;
|
||||
while (this.block.columns.some(column => column.name === `Column ${i}`)) {
|
||||
while (
|
||||
this.block.props.columns.some(column => column.name === `Column ${i}`)
|
||||
) {
|
||||
i++;
|
||||
}
|
||||
return `Column ${i}`;
|
||||
@@ -116,8 +118,8 @@ export class BlockQueryDataSource extends DataSourceBase {
|
||||
cellValueChange(rowId: string, propertyId: string, value: unknown): void {
|
||||
const viewColumn = this.getViewColumn(propertyId);
|
||||
if (viewColumn) {
|
||||
this.block.cells[rowId] = {
|
||||
...this.block.cells[rowId],
|
||||
this.block.props.cells[rowId] = {
|
||||
...this.block.props.cells[rowId],
|
||||
[propertyId]: value,
|
||||
};
|
||||
return;
|
||||
@@ -133,7 +135,7 @@ export class BlockQueryDataSource extends DataSourceBase {
|
||||
cellValueGet(rowId: string, propertyId: string): unknown {
|
||||
const viewColumn = this.getViewColumn(propertyId);
|
||||
if (viewColumn) {
|
||||
return this.block.cells[rowId]?.[propertyId];
|
||||
return this.block.props.cells[rowId]?.[propertyId];
|
||||
}
|
||||
const block = this.blockMap.get(rowId);
|
||||
if (block) {
|
||||
@@ -143,7 +145,7 @@ export class BlockQueryDataSource extends DataSourceBase {
|
||||
}
|
||||
|
||||
getViewColumn(id: string) {
|
||||
return this.block.columns.find(v => v.id === id);
|
||||
return this.block.props.columns.find(v => v.id === id);
|
||||
}
|
||||
|
||||
listenToDoc(doc: Store) {
|
||||
@@ -174,7 +176,7 @@ export class BlockQueryDataSource extends DataSourceBase {
|
||||
].create(this.newColumnName());
|
||||
|
||||
const id = doc.workspace.idGenerator();
|
||||
if (this.block.columns.some(v => v.id === id)) {
|
||||
if (this.block.props.columns.some(v => v.id === id)) {
|
||||
return id;
|
||||
}
|
||||
doc.transact(() => {
|
||||
@@ -182,8 +184,8 @@ export class BlockQueryDataSource extends DataSourceBase {
|
||||
...column,
|
||||
id,
|
||||
};
|
||||
this.block.columns.splice(
|
||||
insertPositionToIndex(insertToPosition, this.block.columns),
|
||||
this.block.props.columns.splice(
|
||||
insertPositionToIndex(insertToPosition, this.block.props.columns),
|
||||
0,
|
||||
col
|
||||
);
|
||||
@@ -211,9 +213,9 @@ export class BlockQueryDataSource extends DataSourceBase {
|
||||
}
|
||||
|
||||
propertyDelete(_id: string): void {
|
||||
const index = this.block.columns.findIndex(v => v.id === _id);
|
||||
const index = this.block.props.columns.findIndex(v => v.id === _id);
|
||||
if (index >= 0) {
|
||||
this.block.columns.splice(index, 1);
|
||||
this.block.props.columns.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,8 +295,8 @@ export class BlockQueryDataSource extends DataSourceBase {
|
||||
viewColumn.data = result.property;
|
||||
currentCells.forEach((value, i) => {
|
||||
if (value != null || result.cells[i] != null) {
|
||||
this.block.cells[rows[i]] = {
|
||||
...this.block.cells[rows[i]],
|
||||
this.block.props.cells[rows[i]] = {
|
||||
...this.block.props.cells[rows[i]],
|
||||
[propertyId]: result.cells[i],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -96,10 +96,10 @@ export class DataViewBlockComponent extends CaptionedBlockComponent<DataViewBloc
|
||||
options: {
|
||||
items: [
|
||||
menu.input({
|
||||
initialValue: this.model.title,
|
||||
initialValue: this.model.props.title,
|
||||
placeholder: 'Untitled',
|
||||
onChange: text => {
|
||||
this.model.title = text;
|
||||
this.model.props.title = text;
|
||||
},
|
||||
}),
|
||||
menu.action({
|
||||
@@ -158,7 +158,7 @@ export class DataViewBlockComponent extends CaptionedBlockComponent<DataViewBloc
|
||||
return html`
|
||||
<div style="margin-bottom: 16px;display:flex;flex-direction: column">
|
||||
<div style="display:flex;gap:8px;padding: 0 6px;margin-bottom: 8px;">
|
||||
<div>${this.model.title}</div>
|
||||
<div>${this.model.props.title}</div>
|
||||
${this.renderDatabaseOps()}
|
||||
</div>
|
||||
<div
|
||||
|
||||
@@ -25,24 +25,24 @@ export class DataViewBlockModel extends BlockModel<Props> {
|
||||
|
||||
applyViewsUpdate() {
|
||||
this.doc.updateBlock(this, {
|
||||
views: this.views,
|
||||
views: this.props.views,
|
||||
});
|
||||
}
|
||||
|
||||
deleteView(id: string) {
|
||||
this.doc.captureSync();
|
||||
this.doc.transact(() => {
|
||||
this.views = this.views.filter(v => v.id !== id);
|
||||
this.props.views = this.props.views.filter(v => v.id !== id);
|
||||
});
|
||||
}
|
||||
|
||||
duplicateView(id: string): string {
|
||||
const newId = this.doc.workspace.idGenerator();
|
||||
this.doc.transact(() => {
|
||||
const index = this.views.findIndex(v => v.id === id);
|
||||
const view = this.views[index];
|
||||
const index = this.props.views.findIndex(v => v.id === id);
|
||||
const view = this.props.views[index];
|
||||
if (view) {
|
||||
this.views.splice(
|
||||
this.props.views.splice(
|
||||
index + 1,
|
||||
0,
|
||||
JSON.parse(JSON.stringify({ ...view, id: newId }))
|
||||
@@ -54,8 +54,8 @@ export class DataViewBlockModel extends BlockModel<Props> {
|
||||
|
||||
moveViewTo(id: string, position: InsertToPosition) {
|
||||
this.doc.transact(() => {
|
||||
this.views = arrayMove(
|
||||
this.views,
|
||||
this.props.views = arrayMove(
|
||||
this.props.views,
|
||||
v => v.id === id,
|
||||
arr => insertPositionToIndex(position, arr)
|
||||
);
|
||||
@@ -68,7 +68,7 @@ export class DataViewBlockModel extends BlockModel<Props> {
|
||||
update: (data: DataViewDataType) => Partial<DataViewDataType>
|
||||
) {
|
||||
this.doc.transact(() => {
|
||||
this.views = this.views.map(v => {
|
||||
this.props.views = this.props.views.map(v => {
|
||||
if (v.id !== id) {
|
||||
return v;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user