feat(editor): support file column and member column for database block (#10932)

close: BS-2630, BS-2631, BS-2629, BS-2632, BS-2635
This commit is contained in:
zzj3720
2025-03-18 14:51:45 +00:00
parent 321e3449ec
commit 3939cc1c52
34 changed files with 1796 additions and 77 deletions
@@ -1,5 +1,5 @@
import type {
Column,
ColumnDataType,
ColumnUpdater,
DatabaseBlockModel,
} from '@blocksuite/affine-model';
@@ -24,12 +24,11 @@ import { propertyPresets } from '@blocksuite/data-view/property-presets';
import { IS_MOBILE } from '@blocksuite/global/env';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import { type BlockModel } from '@blocksuite/store';
import { computed, type ReadonlySignal } from '@preact/signals-core';
import { computed, type ReadonlySignal, signal } from '@preact/signals-core';
import { getIcon } from './block-icons.js';
import {
databaseBlockAllPropertyMap,
databaseBlockPropertyList,
databaseBlockProperties,
databasePropertyConverts,
} from './properties/index.js';
import {
@@ -53,6 +52,19 @@ import {
} from './views/index.js';
export class DatabaseBlockDataSource extends DataSourceBase {
static externalProperties = signal<PropertyMetaConfig[]>([]);
static propertiesList = computed(() => {
return [
...Object.values(databaseBlockProperties),
...this.externalProperties.value,
];
});
static propertiesMap = computed(() => {
return Object.fromEntries(
this.propertiesList.value.map(v => [v.type, v as PropertyMetaConfig])
);
});
private _batch = 0;
private readonly _model: DatabaseBlockModel;
@@ -108,7 +120,7 @@ export class DatabaseBlockDataSource extends DataSourceBase {
}
allPropertyMetas$ = computed<PropertyMetaConfig<any, any, any, any>[]>(() => {
return databaseBlockPropertyList;
return DatabaseBlockDataSource.propertiesList.value;
});
propertyMetas$ = computed<PropertyMetaConfig[]>(() => {
@@ -153,6 +165,9 @@ export class DatabaseBlockDataSource extends DataSourceBase {
this._runCapture();
const type = this.propertyTypeGet(propertyId);
if (type == null) {
return;
}
const update = this.propertyMetaGet(type)?.config.rawValue.setValue;
const old = this.cellValueGet(rowId, propertyId);
const updateFn =
@@ -185,6 +200,9 @@ export class DatabaseBlockDataSource extends DataSourceBase {
return getIcon(model);
}
const type = this.propertyTypeGet(propertyId);
if (!type) {
return;
}
if (type === 'title') {
const model = this.getModelById(rowId);
return model?.text;
@@ -225,7 +243,7 @@ export class DatabaseBlockDataSource extends DataSourceBase {
protected override getNormalPropertyAndIndex(propertyId: string):
| {
column: Column<Record<string, unknown>>;
column: ColumnDataType<Record<string, unknown>>;
index: number;
}
| undefined {
@@ -247,7 +265,7 @@ export class DatabaseBlockDataSource extends DataSourceBase {
private getPropertyAndIndex(propertyId: string):
| {
column: Column<Record<string, unknown>>;
column: ColumnDataType<Record<string, unknown>>;
index: number;
}
| undefined {
@@ -368,7 +386,7 @@ export class DatabaseBlockDataSource extends DataSourceBase {
}
propertyMetaGet(type: string): PropertyMetaConfig | undefined {
return databaseBlockAllPropertyMap[type];
return DatabaseBlockDataSource.propertiesMap.value[type];
}
propertyNameGet(propertyId: string): string {
@@ -392,13 +410,13 @@ export class DatabaseBlockDataSource extends DataSourceBase {
return false;
}
propertyTypeGet(propertyId: string): string {
propertyTypeGet(propertyId: string): string | undefined {
if (propertyId === 'type') {
return 'image';
}
const result = this.getPropertyAndIndex(propertyId);
if (!result) {
return '';
return;
}
return result.column.type;
}