mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
refactor(editor): move database selection into the corresponding view (#9752)
This commit is contained in:
@@ -23,7 +23,6 @@ import {
|
||||
import {
|
||||
createRecordDetail,
|
||||
createUniComponentFromWebComponent,
|
||||
DatabaseSelection,
|
||||
DataView,
|
||||
dataViewCommonStyle,
|
||||
type DataViewInstance,
|
||||
@@ -55,6 +54,7 @@ import { DatabaseBlockDataSource } from './data-source.js';
|
||||
import type { DatabaseBlockService } from './database-service.js';
|
||||
import { BlockRenderer } from './detail-panel/block-renderer.js';
|
||||
import { NoteRenderer } from './detail-panel/note-renderer.js';
|
||||
import { DatabaseSelection } from './selection.js';
|
||||
import { currentViewStorage } from './utils/current-view.js';
|
||||
import { getSingleDocIdFromText } from './utils/title-doc.js';
|
||||
|
||||
|
||||
@@ -13,4 +13,5 @@ export * from './detail-panel/note-renderer';
|
||||
export * from './properties';
|
||||
export * from './properties/rich-text/cell-renderer';
|
||||
export * from './properties/utils';
|
||||
export * from './selection.js';
|
||||
export * from './utils/block-utils';
|
||||
|
||||
76
blocksuite/affine/block-database/src/selection.ts
Normal file
76
blocksuite/affine/block-database/src/selection.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import type { DataViewSelection } from '@blocksuite/data-view';
|
||||
import {
|
||||
KanbanViewSelectionWithTypeSchema,
|
||||
TableViewSelectionWithTypeSchema,
|
||||
} from '@blocksuite/data-view/view-presets';
|
||||
import { BaseSelection, SelectionExtension } from '@blocksuite/store';
|
||||
import { z } from 'zod';
|
||||
|
||||
const ViewSelectionSchema = z.union([
|
||||
TableViewSelectionWithTypeSchema,
|
||||
KanbanViewSelectionWithTypeSchema,
|
||||
]);
|
||||
|
||||
const DatabaseSelectionSchema = z.object({
|
||||
blockId: z.string(),
|
||||
viewSelection: ViewSelectionSchema,
|
||||
});
|
||||
|
||||
export class DatabaseSelection extends BaseSelection {
|
||||
static override group = 'note';
|
||||
|
||||
static override type = 'database';
|
||||
|
||||
readonly viewSelection: DataViewSelection;
|
||||
|
||||
get viewId() {
|
||||
return this.viewSelection.viewId;
|
||||
}
|
||||
|
||||
constructor({
|
||||
blockId,
|
||||
viewSelection,
|
||||
}: {
|
||||
blockId: string;
|
||||
viewSelection: DataViewSelection;
|
||||
}) {
|
||||
super({
|
||||
blockId,
|
||||
});
|
||||
|
||||
this.viewSelection = viewSelection;
|
||||
}
|
||||
|
||||
static override fromJSON(json: Record<string, unknown>): DatabaseSelection {
|
||||
const { blockId, viewSelection } = DatabaseSelectionSchema.parse(json);
|
||||
return new DatabaseSelection({
|
||||
blockId,
|
||||
viewSelection: viewSelection,
|
||||
});
|
||||
}
|
||||
|
||||
override equals(other: BaseSelection): boolean {
|
||||
if (!(other instanceof DatabaseSelection)) {
|
||||
return false;
|
||||
}
|
||||
return this.blockId === other.blockId;
|
||||
}
|
||||
|
||||
override toJSON(): Record<string, unknown> {
|
||||
return {
|
||||
type: 'database',
|
||||
blockId: this.blockId,
|
||||
viewSelection: this.viewSelection,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface Selection {
|
||||
database: typeof DatabaseSelection;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const DatabaseSelectionExtension = SelectionExtension(DatabaseSelection);
|
||||
Reference in New Issue
Block a user