mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-22 20:41:50 +08:00
ce87dcf58e
1. **Major Architectural Change: Schema Management**
- Moved from `workspace.schema` to `store.schema` throughout the codebase
- Removed schema property from Workspace and Doc interfaces
- Added `BlockSchemaExtension` pattern across multiple block types
2. **Block Schema Extensions Added**
- Added new `BlockSchemaExtension` to numerous block types including:
- DataView, Surface, Attachment, Bookmark, Code
- Database, Divider, EdgelessText, Embed blocks (Figma, Github, HTML, etc.)
- Frame, Image, Latex, List, Note, Paragraph
- Root, Surface Reference, Table blocks
3. **Import/Export System Updates**
- Updated import functions to accept `schema` parameter:
- `importHTMLToDoc`
- `importHTMLZip`
- `importMarkdownToDoc`
- `importMarkdownZip`
- `importNotionZip`
- Modified export functions to use new schema pattern
4. **Test Infrastructure Updates**
- Updated test files to use new schema extensions
- Modified test document creation to include schema extensions
- Removed direct schema registration in favor of extensions
5. **Service Layer Changes**
- Updated various services to use `getAFFiNEWorkspaceSchema()`
- Modified transformer initialization to use document schema
- Updated collection initialization patterns
6. **Version Management**
- Removed version-related properties and methods from:
- `WorkspaceMetaImpl`
- `TestMeta`
- `DocImpl`
- Removed `blockVersions` and `workspaceVersion/pageVersion`
7. **Store and Extension Updates**
- Added new store extensions and adapters
- Updated store initialization patterns
- Added new schema-related functionality in store extension
This PR represents a significant architectural shift in how schemas are managed, moving from a workspace-centric to a store-centric approach, while introducing a more extensible block schema system through `BlockSchemaExtension`. The changes touch multiple layers of the application including core functionality, services, testing infrastructure, and import/export capabilities.
103 lines
2.2 KiB
TypeScript
103 lines
2.2 KiB
TypeScript
import type { Column } from '@blocksuite/affine-model';
|
|
import {
|
|
arrayMove,
|
|
insertPositionToIndex,
|
|
type InsertToPosition,
|
|
} from '@blocksuite/affine-shared/utils';
|
|
import type { DataViewDataType } from '@blocksuite/data-view';
|
|
import {
|
|
BlockModel,
|
|
BlockSchemaExtension,
|
|
defineBlockSchema,
|
|
} from '@blocksuite/store';
|
|
|
|
type Props = {
|
|
title: string;
|
|
views: DataViewDataType[];
|
|
columns: Column[];
|
|
cells: Record<string, Record<string, unknown>>;
|
|
};
|
|
|
|
export class DataViewBlockModel extends BlockModel<Props> {
|
|
constructor() {
|
|
super();
|
|
}
|
|
|
|
applyViewsUpdate() {
|
|
this.doc.updateBlock(this, {
|
|
views: this.views,
|
|
});
|
|
}
|
|
|
|
deleteView(id: string) {
|
|
this.doc.captureSync();
|
|
this.doc.transact(() => {
|
|
this.views = this.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];
|
|
if (view) {
|
|
this.views.splice(
|
|
index + 1,
|
|
0,
|
|
JSON.parse(JSON.stringify({ ...view, id: newId }))
|
|
);
|
|
}
|
|
});
|
|
return newId;
|
|
}
|
|
|
|
moveViewTo(id: string, position: InsertToPosition) {
|
|
this.doc.transact(() => {
|
|
this.views = arrayMove(
|
|
this.views,
|
|
v => v.id === id,
|
|
arr => insertPositionToIndex(position, arr)
|
|
);
|
|
});
|
|
this.applyViewsUpdate();
|
|
}
|
|
|
|
updateView(
|
|
id: string,
|
|
update: (data: DataViewDataType) => Partial<DataViewDataType>
|
|
) {
|
|
this.doc.transact(() => {
|
|
this.views = this.views.map(v => {
|
|
if (v.id !== id) {
|
|
return v;
|
|
}
|
|
return { ...v, ...(update(v) as DataViewDataType) };
|
|
});
|
|
});
|
|
this.applyViewsUpdate();
|
|
}
|
|
}
|
|
|
|
export const DataViewBlockSchema = defineBlockSchema({
|
|
flavour: 'affine:data-view',
|
|
props: (): Props => ({
|
|
views: [],
|
|
title: '',
|
|
columns: [],
|
|
cells: {},
|
|
}),
|
|
metadata: {
|
|
role: 'hub',
|
|
version: 1,
|
|
parent: ['affine:note'],
|
|
children: ['affine:paragraph', 'affine:list'],
|
|
},
|
|
toModel: () => {
|
|
return new DataViewBlockModel();
|
|
},
|
|
});
|
|
|
|
export const DataViewBlockSchemaExtension =
|
|
BlockSchemaExtension(DataViewBlockSchema);
|