mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-21 20:16:26 +08:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user