feat(editor): merge store and blocks (#9591)

This commit is contained in:
Saul-Mirone
2025-01-08 13:01:19 +00:00
parent a0cba55a5b
commit 5842d45ab1
124 changed files with 362 additions and 414 deletions
@@ -3,9 +3,9 @@ import { nextTick, Slot } from '@blocksuite/global/utils';
import type {
BlockModel,
Blocks,
BlockSchemaType,
DraftModel,
Store,
} from '../model/index.js';
import type { Schema } from '../schema/index.js';
import { AssetsManager } from './assets.js';
@@ -82,7 +82,7 @@ export class Job {
}
};
docToSnapshot = (doc: Blocks): DocSnapshot | undefined => {
docToSnapshot = (doc: Store): DocSnapshot | undefined => {
try {
this._slots.beforeExport.emit({
type: 'page',
@@ -158,7 +158,7 @@ export class Job {
snapshotToBlock = async (
snapshot: BlockSnapshot,
doc: Blocks,
doc: Store,
parent?: string,
index?: number
): Promise<BlockModel | undefined> => {
@@ -174,9 +174,7 @@ export class Job {
}
};
snapshotToDoc = async (
snapshot: DocSnapshot
): Promise<Blocks | undefined> => {
snapshotToDoc = async (snapshot: DocSnapshot): Promise<Store | undefined> => {
try {
this._slots.beforeImport.emit({
type: 'page',
@@ -228,7 +226,7 @@ export class Job {
snapshotToSlice = async (
snapshot: SliceSnapshot,
doc: Blocks,
doc: Store,
parent?: string,
index?: number
): Promise<Slice | undefined> => {
@@ -424,7 +422,7 @@ export class Job {
}
}
private _exportDocMeta(doc: Blocks): DocSnapshot['meta'] {
private _exportDocMeta(doc: Store): DocSnapshot['meta'] {
const docMeta = doc.meta;
if (!docMeta) {
@@ -472,7 +470,7 @@ export class Job {
private async _insertBlockTree(
nodes: DraftBlockTreeNode[],
doc: Blocks,
doc: Store,
parentId?: string,
startIndex?: number,
counter: number = 0
@@ -561,7 +559,7 @@ export class Job {
private async _snapshotToBlock(
snapshot: BlockSnapshot,
doc: Blocks,
doc: Store,
parent?: string,
index?: number
): Promise<BlockModel | null> {
@@ -1,6 +1,6 @@
import type { Slot } from '@blocksuite/global/utils';
import type { Blocks, DraftModel } from '../model/index.js';
import type { DraftModel, Store } from '../model/index.js';
import type { AssetsManager } from './assets.js';
import type { Slice } from './slice.js';
import type {
@@ -37,7 +37,7 @@ export type BeforeExportPayload =
type: 'block';
}
| {
page: Blocks;
page: Store;
type: 'page';
}
| {
@@ -59,7 +59,7 @@ export type FinalPayload =
| {
snapshot: DocSnapshot;
type: 'page';
page: Blocks;
page: Store;
}
| {
snapshot: SliceSnapshot;
@@ -1,4 +1,4 @@
import type { Blocks, DraftModel } from '../model/index.js';
import type { DraftModel, Store } from '../model/index.js';
type SliceData = {
content: DraftModel[];
@@ -21,7 +21,7 @@ export class Slice {
constructor(readonly data: SliceData) {}
static fromModels(doc: Blocks, models: DraftModel[]) {
static fromModels(doc: Store, models: DraftModel[]) {
return new Slice({
content: models,
workspaceId: doc.workspace.id,
@@ -1,6 +1,6 @@
import { z } from 'zod';
import type { Blocks } from '../model/blocks/blocks.js';
import type { Store } from '../model/store/store.js';
import type { DocMeta, DocsPropertiesMeta } from '../model/workspace-meta.js';
export type BlockSnapshot = {
@@ -75,7 +75,7 @@ export interface BlobCRUD {
}
export interface DocCRUD {
create: (id: string) => Blocks;
get: (id: string) => Blocks | null;
create: (id: string) => Store;
get: (id: string) => Store | null;
delete: (id: string) => void;
}