feat(editor): type safe draft model and transformer (#10486)

This commit is contained in:
Saul-Mirone
2025-02-27 09:19:49 +00:00
parent 272d41e32d
commit 4c736bc190
15 changed files with 125 additions and 48 deletions

View File

@@ -1,6 +1,11 @@
import { BlockSuiteError } from '@blocksuite/global/exceptions';
import type { DraftModel, Store } from '../model/index.js';
import {
BlockModel,
type DraftModel,
type Store,
toDraftModel,
} from '../model/index.js';
import type { AssetsManager } from '../transformer/assets.js';
import type { Slice, Transformer } from '../transformer/index.js';
import type {
@@ -72,9 +77,11 @@ export abstract class BaseAdapter<AdapterTarget = unknown> {
this.job = job;
}
async fromBlock(model: DraftModel) {
async fromBlock(model: BlockModel | DraftModel) {
try {
const blockSnapshot = this.job.blockToSnapshot(model);
const draftModel =
model instanceof BlockModel ? toDraftModel(model) : model;
const blockSnapshot = this.job.blockToSnapshot(draftModel);
if (!blockSnapshot) return;
return await this.fromBlockSnapshot({
snapshot: blockSnapshot,