feat(editor): merge store and blocks (#9591)
This commit is contained in:
@@ -17,7 +17,7 @@ import {
|
||||
RootBlockSchema,
|
||||
} from '@blocksuite/affine-model';
|
||||
import { propertyModelPresets } from '@blocksuite/data-view/property-pure-presets';
|
||||
import type { BlockModel, Blocks } from '@blocksuite/store';
|
||||
import type { BlockModel, Store } from '@blocksuite/store';
|
||||
import { Schema, Text } from '@blocksuite/store';
|
||||
import {
|
||||
createAutoIncrementIdGenerator,
|
||||
@@ -49,7 +49,7 @@ function createTestDoc(docId = 'doc0') {
|
||||
}
|
||||
|
||||
describe('DatabaseManager', () => {
|
||||
let doc: Blocks;
|
||||
let doc: Store;
|
||||
let db: DatabaseBlockModel;
|
||||
|
||||
let rootId: BlockModel['id'];
|
||||
|
||||
@@ -24,7 +24,7 @@ import type { GfxBlockElementModel } from '@blocksuite/block-std/gfx';
|
||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||
import type { IBound } from '@blocksuite/global/utils';
|
||||
import { Bound } from '@blocksuite/global/utils';
|
||||
import type { Blocks, ExtensionType } from '@blocksuite/store';
|
||||
import type { ExtensionType, Store } from '@blocksuite/store';
|
||||
|
||||
import {
|
||||
getBlockComponentByModel,
|
||||
@@ -109,7 +109,7 @@ export class ExportManager {
|
||||
await Promise.all(promises);
|
||||
};
|
||||
|
||||
get doc(): Blocks {
|
||||
get doc(): Store {
|
||||
return this.std.doc;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { HtmlAdapter } from '@blocksuite/affine-shared/adapters';
|
||||
import { Container } from '@blocksuite/global/di';
|
||||
import { sha } from '@blocksuite/global/utils';
|
||||
import type { Blocks, Workspace } from '@blocksuite/store';
|
||||
import type { Store, Workspace } from '@blocksuite/store';
|
||||
import { extMimeMap, Job } from '@blocksuite/store';
|
||||
|
||||
import { defaultBlockHtmlAdapterMatchers } from '../adapters/html/block-matcher.js';
|
||||
@@ -43,7 +43,7 @@ const provider = container.provider();
|
||||
* @param doc - The doc to be exported.
|
||||
* @returns A Promise that resolves when the export is complete.
|
||||
*/
|
||||
async function exportDoc(doc: Blocks) {
|
||||
async function exportDoc(doc: Store) {
|
||||
const job = new Job({
|
||||
schema: doc.schema,
|
||||
blobCRUD: doc.blobSync,
|
||||
|
||||
@@ -2,7 +2,7 @@ import { MarkdownAdapter } from '@blocksuite/affine-shared/adapters';
|
||||
import { Container } from '@blocksuite/global/di';
|
||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||
import { assertExists, sha } from '@blocksuite/global/utils';
|
||||
import type { Blocks, Workspace } from '@blocksuite/store';
|
||||
import type { Store, Workspace } from '@blocksuite/store';
|
||||
import { extMimeMap, Job } from '@blocksuite/store';
|
||||
|
||||
import { defaultBlockMarkdownAdapterMatchers } from '../adapters/index.js';
|
||||
@@ -28,7 +28,7 @@ const container = new Container();
|
||||
const provider = container.provider();
|
||||
|
||||
type ImportMarkdownToBlockOptions = {
|
||||
doc: Blocks;
|
||||
doc: Store;
|
||||
markdown: string;
|
||||
blockId: string;
|
||||
};
|
||||
@@ -49,7 +49,7 @@ type ImportMarkdownZipOptions = {
|
||||
* @param doc The doc to export
|
||||
* @returns A Promise that resolves when the export is complete
|
||||
*/
|
||||
async function exportDoc(doc: Blocks) {
|
||||
async function exportDoc(doc: Store) {
|
||||
const job = new Job({
|
||||
schema: doc.schema,
|
||||
blobCRUD: doc.blobSync,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { sha } from '@blocksuite/global/utils';
|
||||
import type { Blocks, DocSnapshot, Workspace } from '@blocksuite/store';
|
||||
import type { DocSnapshot, Store, Workspace } from '@blocksuite/store';
|
||||
import { extMimeMap, getAssetName, Job } from '@blocksuite/store';
|
||||
|
||||
import { download, Unzip, Zip } from '../transformers/utils.js';
|
||||
import { replaceIdMiddleware, titleMiddleware } from './middlewares.js';
|
||||
|
||||
async function exportDocs(collection: Workspace, docs: Blocks[]) {
|
||||
async function exportDocs(collection: Workspace, docs: Store[]) {
|
||||
const zip = new Zip();
|
||||
const job = new Job({
|
||||
schema: collection.schema,
|
||||
|
||||
@@ -5,7 +5,7 @@ import type {
|
||||
GroupElementModel,
|
||||
} from '@blocksuite/affine-model';
|
||||
import type { Slot } from '@blocksuite/global/utils';
|
||||
import type { Blocks } from '@blocksuite/store';
|
||||
import type { Store } from '@blocksuite/store';
|
||||
|
||||
/** Common context interface definition for block models. */
|
||||
|
||||
@@ -14,7 +14,7 @@ type EditorSlots = {
|
||||
};
|
||||
|
||||
export type AbstractEditor = {
|
||||
doc: Blocks;
|
||||
doc: Store;
|
||||
mode: DocMode;
|
||||
readonly slots: EditorSlots;
|
||||
} & HTMLElement;
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
} from '@blocksuite/affine-shared/adapters';
|
||||
import type { BlockComponent, UIEventHandler } from '@blocksuite/block-std';
|
||||
import { DisposableGroup } from '@blocksuite/global/utils';
|
||||
import type { Blocks, BlockSnapshot } from '@blocksuite/store';
|
||||
import type { BlockSnapshot, Store } from '@blocksuite/store';
|
||||
|
||||
import {
|
||||
defaultImageProxyMiddleware,
|
||||
@@ -99,7 +99,7 @@ export class PageClipboard {
|
||||
|
||||
onBlockSnapshotPaste = async (
|
||||
snapshot: BlockSnapshot,
|
||||
doc: Blocks,
|
||||
doc: Store,
|
||||
parent?: string,
|
||||
index?: number
|
||||
) => {
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
} from '@blocksuite/block-std';
|
||||
import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
|
||||
import { DisposableGroup, Vec, WithDisposable } from '@blocksuite/global/utils';
|
||||
import type { Blocks } from '@blocksuite/store';
|
||||
import type { Store } from '@blocksuite/store';
|
||||
import { consume } from '@lit/context';
|
||||
import { css, html, LitElement } from 'lit';
|
||||
import { property, query } from 'lit/decorators.js';
|
||||
@@ -150,7 +150,7 @@ export class EdgelessConnectorHandle extends WithDisposable(LitElement) {
|
||||
@consume({
|
||||
context: docContext,
|
||||
})
|
||||
accessor doc!: Blocks;
|
||||
accessor doc!: Store;
|
||||
|
||||
@property({ attribute: false })
|
||||
accessor edgeless!: EdgelessRootBlockComponent;
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
DisposableGroup,
|
||||
WithDisposable,
|
||||
} from '@blocksuite/global/utils';
|
||||
import { type Blocks, type Query, Store } from '@blocksuite/store';
|
||||
import { type Query, type Store } from '@blocksuite/store';
|
||||
import { css, html, nothing, type PropertyValues } from 'lit';
|
||||
import { property, query, state } from 'lit/decorators.js';
|
||||
import { styleMap } from 'lit/directives/style-map.js';
|
||||
@@ -78,7 +78,7 @@ export class FramePreview extends WithDisposable(ShadowlessElement) {
|
||||
|
||||
private _frameDisposables: DisposableGroup | null = null;
|
||||
|
||||
private _previewDoc: Blocks | null = null;
|
||||
private _previewDoc: Store | null = null;
|
||||
|
||||
private readonly _previewSpec =
|
||||
SpecProvider.getInstance().getSpec('edgeless:preview');
|
||||
@@ -155,7 +155,6 @@ export class FramePreview extends WithDisposable(ShadowlessElement) {
|
||||
private _renderSurfaceContent() {
|
||||
if (!this._previewDoc || !this.frame) return nothing;
|
||||
const { width, height } = this.frameViewportWH;
|
||||
const store = new Store({ blocks: this._previewDoc });
|
||||
|
||||
const _previewSpec = this._previewSpec.value;
|
||||
return html`<div
|
||||
@@ -173,7 +172,7 @@ export class FramePreview extends WithDisposable(ShadowlessElement) {
|
||||
})}
|
||||
>
|
||||
${new BlockStdScope({
|
||||
store,
|
||||
store: this._previewDoc,
|
||||
extensions: _previewSpec,
|
||||
}).render()}
|
||||
</div>
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
type IVec,
|
||||
type SerializedXYWH,
|
||||
} from '@blocksuite/global/utils';
|
||||
import type { Blocks } from '@blocksuite/store';
|
||||
import type { Store } from '@blocksuite/store';
|
||||
import { Text } from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
@@ -463,7 +463,7 @@ export class EdgelessFrameManager extends GfxExtension {
|
||||
}
|
||||
|
||||
export function getNotesInFrameBound(
|
||||
doc: Blocks,
|
||||
doc: Store,
|
||||
frame: FrameBlockModel,
|
||||
fullyContained: boolean = true
|
||||
) {
|
||||
@@ -481,7 +481,7 @@ export function getNotesInFrameBound(
|
||||
}
|
||||
|
||||
export function getBlocksInFrameBound(
|
||||
doc: Blocks,
|
||||
doc: Store,
|
||||
model: FrameBlockModel,
|
||||
fullyContained: boolean = true
|
||||
) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { DocModeProvider } from '@blocksuite/affine-shared/services';
|
||||
import { getBlockProps } from '@blocksuite/affine-shared/utils';
|
||||
import type { EditorHost } from '@blocksuite/block-std';
|
||||
import { GfxBlockElementModel } from '@blocksuite/block-std/gfx';
|
||||
import { type BlockModel, type Blocks, Text } from '@blocksuite/store';
|
||||
import { type BlockModel, type Store, Text } from '@blocksuite/store';
|
||||
|
||||
import {
|
||||
getElementProps,
|
||||
@@ -14,11 +14,7 @@ import {
|
||||
} from '../../../edgeless/utils/clone-utils.js';
|
||||
import { isFrameBlock, isNoteBlock } from '../../../edgeless/utils/query.js';
|
||||
|
||||
function addBlocksToDoc(
|
||||
targetDoc: Blocks,
|
||||
model: BlockModel,
|
||||
parentId: string
|
||||
) {
|
||||
function addBlocksToDoc(targetDoc: Store, model: BlockModel, parentId: string) {
|
||||
// Add current block to linked doc
|
||||
const blockProps = getBlockProps(model);
|
||||
const newModelId = targetDoc.addBlock(
|
||||
@@ -36,7 +32,7 @@ function addBlocksToDoc(
|
||||
}
|
||||
|
||||
export function createLinkedDocFromNote(
|
||||
doc: Blocks,
|
||||
doc: Store,
|
||||
note: NoteBlockModel,
|
||||
docTitle?: string
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user