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

View File

@@ -11,7 +11,7 @@ import type { EditorHost } from '@blocksuite/block-std';
import { DataSourceBase, type PropertyMetaConfig } from '@blocksuite/data-view'; import { DataSourceBase, type PropertyMetaConfig } from '@blocksuite/data-view';
import { propertyPresets } from '@blocksuite/data-view/property-presets'; import { propertyPresets } from '@blocksuite/data-view/property-presets';
import { assertExists, Slot } from '@blocksuite/global/utils'; import { assertExists, Slot } from '@blocksuite/global/utils';
import type { Block, Blocks } from '@blocksuite/store'; import type { Block, Store } from '@blocksuite/store';
import type { BlockMeta } from './block-meta/base.js'; import type { BlockMeta } from './block-meta/base.js';
import { blockMetaMap } from './block-meta/index.js'; import { blockMetaMap } from './block-meta/index.js';
@@ -73,14 +73,14 @@ export class BlockQueryDataSource extends DataSourceBase {
this.columnMetaMap.set(property.metaConfig.type, property.metaConfig); this.columnMetaMap.set(property.metaConfig.type, property.metaConfig);
} }
for (const collection of this.workspace.docs.values()) { for (const collection of this.workspace.docs.values()) {
for (const block of Object.values(collection.getBlocks().blocks.peek())) { for (const block of Object.values(collection.getStore().blocks.peek())) {
if (this.meta.selector(block)) { if (this.meta.selector(block)) {
this.blockMap.set(block.id, block); this.blockMap.set(block.id, block);
} }
} }
} }
this.workspace.docs.forEach(doc => { this.workspace.docs.forEach(doc => {
this.listenToDoc(doc.getBlocks()); this.listenToDoc(doc.getStore());
}); });
this.workspace.slots.docCreated.on(id => { this.workspace.slots.docCreated.on(id => {
const doc = this.workspace.getDoc(id); const doc = this.workspace.getDoc(id);
@@ -140,7 +140,7 @@ export class BlockQueryDataSource extends DataSourceBase {
return this.block.columns.find(v => v.id === id); return this.block.columns.find(v => v.id === id);
} }
listenToDoc(doc: Blocks) { listenToDoc(doc: Store) {
this.docDisposeMap.set( this.docDisposeMap.set(
doc.id, doc.id,
doc.slots.blockUpdated.on(v => { doc.slots.blockUpdated.on(v => {

View File

@@ -4,7 +4,7 @@ import {
} from '@blocksuite/affine-model'; } from '@blocksuite/affine-model';
import { BlockService } from '@blocksuite/block-std'; import { BlockService } from '@blocksuite/block-std';
import { viewPresets } from '@blocksuite/data-view/view-presets'; import { viewPresets } from '@blocksuite/data-view/view-presets';
import type { BlockModel, Blocks } from '@blocksuite/store'; import type { BlockModel, Store } from '@blocksuite/store';
import { import {
databaseViewAddView, databaseViewAddView,
@@ -36,7 +36,7 @@ export class DatabaseBlockService extends BlockService {
viewPresets = viewPresets; viewPresets = viewPresets;
initDatabaseBlock( initDatabaseBlock(
doc: Blocks, doc: Store,
model: BlockModel, model: BlockModel,
databaseId: string, databaseId: string,
viewType: string, viewType: string,

View File

@@ -11,12 +11,11 @@ import { BlockStdScope } from '@blocksuite/block-std';
import { assertExists } from '@blocksuite/global/utils'; import { assertExists } from '@blocksuite/global/utils';
import { import {
type BlockModel, type BlockModel,
type Blocks,
type BlockSnapshot, type BlockSnapshot,
type DraftModel, type DraftModel,
type Query, type Query,
Slice, Slice,
Store, type Store,
Text, Text,
} from '@blocksuite/store'; } from '@blocksuite/store';
import { render, type TemplateResult } from 'lit'; import { render, type TemplateResult } from 'lit';
@@ -196,11 +195,10 @@ async function renderNoteContent(
mode: 'strict', mode: 'strict',
match: ids.map(id => ({ id, viewType: 'display' })), match: ids.map(id => ({ id, viewType: 'display' })),
}; };
const previewDoc = doc.doc.getBlocks({ query }); const previewDoc = doc.doc.getStore({ query });
const previewSpec = SpecProvider.getInstance().getSpec('page:preview'); const previewSpec = SpecProvider.getInstance().getSpec('page:preview');
const store = new Store({ blocks: previewDoc });
const previewStd = new BlockStdScope({ const previewStd = new BlockStdScope({
store, store: previewDoc,
extensions: previewSpec.value, extensions: previewSpec.value,
}); });
const previewTemplate = previewStd.render(); const previewTemplate = previewStd.render();
@@ -222,7 +220,7 @@ function filterTextModel(model: BlockModel) {
return false; return false;
} }
export function getNotesFromDoc(doc: Blocks) { export function getNotesFromDoc(doc: Store) {
const notes = doc.root?.children.filter( const notes = doc.root?.children.filter(
child => child =>
matchFlavours(child, ['affine:note']) && matchFlavours(child, ['affine:note']) &&
@@ -236,7 +234,7 @@ export function getNotesFromDoc(doc: Blocks) {
return notes; return notes;
} }
export function isEmptyDoc(doc: Blocks | null, mode: DocMode) { export function isEmptyDoc(doc: Store | null, mode: DocMode) {
if (!doc) { if (!doc) {
return true; return true;
} }
@@ -268,7 +266,7 @@ export function isEmptyNote(note: BlockModel) {
/** /**
* Gets the document content with a max length. * Gets the document content with a max length.
*/ */
export function getDocContentWithMaxLength(doc: Blocks, maxlength = 500) { export function getDocContentWithMaxLength(doc: Store, maxlength = 500) {
const notes = getNotesFromDoc(doc); const notes = getNotesFromDoc(doc);
if (!notes) return; if (!notes) return;
@@ -328,7 +326,7 @@ export function promptDocTitle(std: BlockStdScope, autofill?: string) {
}); });
} }
export function notifyDocCreated(std: BlockStdScope, doc: Blocks) { export function notifyDocCreated(std: BlockStdScope, doc: Store) {
const notification = std.getOptional(NotificationProvider); const notification = std.getOptional(NotificationProvider);
if (!notification) return; if (!notification) return;
@@ -367,7 +365,7 @@ export function notifyDocCreated(std: BlockStdScope, doc: Blocks) {
export async function convertSelectedBlocksToLinkedDoc( export async function convertSelectedBlocksToLinkedDoc(
std: BlockStdScope, std: BlockStdScope,
doc: Blocks, doc: Store,
selectedModels: DraftModel[] | Promise<DraftModel[]>, selectedModels: DraftModel[] | Promise<DraftModel[]>,
docTitle?: string docTitle?: string
) { ) {
@@ -401,7 +399,7 @@ export async function convertSelectedBlocksToLinkedDoc(
export function createLinkedDocFromSlice( export function createLinkedDocFromSlice(
std: BlockStdScope, std: BlockStdScope,
doc: Blocks, doc: Store,
snapshots: BlockSnapshot[], snapshots: BlockSnapshot[],
docTitle?: string docTitle?: string
) { ) {

View File

@@ -10,7 +10,6 @@ import {
} from '@blocksuite/affine-shared/services'; } from '@blocksuite/affine-shared/services';
import { BlockSelection, BlockStdScope } from '@blocksuite/block-std'; import { BlockSelection, BlockStdScope } from '@blocksuite/block-std';
import { Bound } from '@blocksuite/global/utils'; import { Bound } from '@blocksuite/global/utils';
import { Store } from '@blocksuite/store';
import { html, nothing } from 'lit'; import { html, nothing } from 'lit';
import { choose } from 'lit/directives/choose.js'; import { choose } from 'lit/directives/choose.js';
import { classMap } from 'lit/directives/class-map.js'; import { classMap } from 'lit/directives/class-map.js';
@@ -31,8 +30,6 @@ export class EmbedEdgelessSyncedDocBlockComponent extends toEdgelessEmbedBlock(
return html`${nothing}`; return html`${nothing}`;
} }
const store = new Store({ blocks: syncedDoc });
let containerStyleMap = styleMap({ let containerStyleMap = styleMap({
position: 'relative', position: 'relative',
width: '100%', width: '100%',
@@ -70,7 +67,7 @@ export class EmbedEdgelessSyncedDocBlockComponent extends toEdgelessEmbedBlock(
() => html` () => html`
<div class="affine-page-viewport" data-theme=${appTheme}> <div class="affine-page-viewport" data-theme=${appTheme}>
${new BlockStdScope({ ${new BlockStdScope({
store, store: syncedDoc,
extensions: this._buildPreviewSpec('page:preview'), extensions: this._buildPreviewSpec('page:preview'),
}).render()} }).render()}
</div> </div>
@@ -81,7 +78,7 @@ export class EmbedEdgelessSyncedDocBlockComponent extends toEdgelessEmbedBlock(
() => html` () => html`
<div class="affine-edgeless-viewport" data-theme=${edgelessTheme}> <div class="affine-edgeless-viewport" data-theme=${edgelessTheme}>
${new BlockStdScope({ ${new BlockStdScope({
store, store: syncedDoc,
extensions: this._buildPreviewSpec('edgeless:preview'), extensions: this._buildPreviewSpec('edgeless:preview'),
}).render()} }).render()}
</div> </div>

View File

@@ -26,12 +26,7 @@ import {
} from '@blocksuite/block-std'; } from '@blocksuite/block-std';
import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx'; import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
import { assertExists, Bound, getCommonBound } from '@blocksuite/global/utils'; import { assertExists, Bound, getCommonBound } from '@blocksuite/global/utils';
import { import { type GetBlocksOptions, type Query, Text } from '@blocksuite/store';
type GetBlocksOptions,
type Query,
Store,
Text,
} from '@blocksuite/store';
import { computed } from '@preact/signals-core'; import { computed } from '@preact/signals-core';
import { html, nothing, type PropertyValues } from 'lit'; import { html, nothing, type PropertyValues } from 'lit';
import { query, state } from 'lit/decorators.js'; import { query, state } from 'lit/decorators.js';
@@ -156,8 +151,6 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
return html`${nothing}`; return html`${nothing}`;
} }
const store = new Store({ blocks: syncedDoc });
if (isPageMode) { if (isPageMode) {
this.dataset.pageMode = ''; this.dataset.pageMode = '';
} }
@@ -186,7 +179,7 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
() => html` () => html`
<div class="affine-page-viewport" data-theme=${appTheme}> <div class="affine-page-viewport" data-theme=${appTheme}>
${new BlockStdScope({ ${new BlockStdScope({
store, store: syncedDoc,
extensions: this._buildPreviewSpec('page:preview'), extensions: this._buildPreviewSpec('page:preview'),
}).render()} }).render()}
</div> </div>
@@ -197,7 +190,7 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
() => html` () => html`
<div class="affine-edgeless-viewport" data-theme=${edgelessTheme}> <div class="affine-edgeless-viewport" data-theme=${edgelessTheme}>
${new BlockStdScope({ ${new BlockStdScope({
store, store: syncedDoc,
extensions: this._buildPreviewSpec('edgeless:preview'), extensions: this._buildPreviewSpec('edgeless:preview'),
}).render()} }).render()}
</div> </div>

View File

@@ -3,7 +3,7 @@ import {
getNextContinuousNumberedLists, getNextContinuousNumberedLists,
matchFlavours, matchFlavours,
} from '@blocksuite/affine-shared/utils'; } from '@blocksuite/affine-shared/utils';
import type { BlockModel, Blocks } from '@blocksuite/store'; import type { BlockModel, Store } from '@blocksuite/store';
/** /**
* correct target is a numbered list, which is divided into two steps: * correct target is a numbered list, which is divided into two steps:
@@ -12,7 +12,7 @@ import type { BlockModel, Blocks } from '@blocksuite/store';
* 2. find continuous lists starting from the target list and keep their order continuous * 2. find continuous lists starting from the target list and keep their order continuous
*/ */
export function correctNumberedListsOrderToPrev( export function correctNumberedListsOrderToPrev(
doc: Blocks, doc: Store,
modelOrId: BlockModel | string, modelOrId: BlockModel | string,
transact = true transact = true
) { ) {
@@ -58,7 +58,7 @@ export function correctNumberedListsOrderToPrev(
} }
} }
export function correctListOrder(doc: Blocks, model: ListBlockModel) { export function correctListOrder(doc: Store, model: ListBlockModel) {
// old numbered list has no order // old numbered list has no order
if (model.type === 'numbered' && !Number.isInteger(model.order)) { if (model.type === 'numbered' && !Number.isInteger(model.order)) {
correctNumberedListsOrderToPrev(doc, model, false); correctNumberedListsOrderToPrev(doc, model, false);

View File

@@ -18,7 +18,7 @@ import {
ShadowlessElement, ShadowlessElement,
} from '@blocksuite/block-std'; } from '@blocksuite/block-std';
import { deserializeXYWH, WithDisposable } from '@blocksuite/global/utils'; import { deserializeXYWH, WithDisposable } from '@blocksuite/global/utils';
import { type BlockModel, type Query, Store } from '@blocksuite/store'; import { type BlockModel, type Query } from '@blocksuite/store';
import { css, nothing } from 'lit'; import { css, nothing } from 'lit';
import { property } from 'lit/decorators.js'; import { property } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js'; import { styleMap } from 'lit/directives/style-map.js';
@@ -114,14 +114,13 @@ export class SurfaceRefNotePortal extends WithDisposable(ShadowlessElement) {
console.error('Query is not set before rendering note preview'); console.error('Query is not set before rendering note preview');
return nothing; return nothing;
} }
const doc = this.model.doc.doc.getBlocks({ const doc = this.model.doc.doc.getStore({
query: this.query, query: this.query,
readonly: true, readonly: true,
}); });
const store = new Store({ blocks: doc });
const previewSpec = SpecProvider.getInstance().getSpec('page:preview'); const previewSpec = SpecProvider.getInstance().getSpec('page:preview');
return new BlockStdScope({ return new BlockStdScope({
store, store: doc,
extensions: previewSpec.value.slice(), extensions: previewSpec.value.slice(),
}).render(); }).render();
} }

View File

@@ -47,7 +47,7 @@ import {
DisposableGroup, DisposableGroup,
type SerializedXYWH, type SerializedXYWH,
} from '@blocksuite/global/utils'; } from '@blocksuite/global/utils';
import { type Blocks, Store } from '@blocksuite/store'; import { type Store } from '@blocksuite/store';
import { css, html, nothing, type TemplateResult } from 'lit'; import { css, html, nothing, type TemplateResult } from 'lit';
import { query, state } from 'lit/decorators.js'; import { query, state } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js'; import { styleMap } from 'lit/directives/style-map.js';
@@ -240,7 +240,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
} }
`; `;
private _previewDoc: Blocks | null = null; private _previewDoc: Store | null = null;
private readonly _previewSpec = private readonly _previewSpec =
SpecProvider.getInstance().getSpec('edgeless:preview'); SpecProvider.getInstance().getSpec('edgeless:preview');
@@ -339,7 +339,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
} }
const doc = [...this.std.workspace.docs.values()] const doc = [...this.std.workspace.docs.values()]
.map(doc => doc.getBlocks()) .map(doc => doc.getStore())
.find( .find(
doc => doc =>
doc.getBlock(this.model.reference) || doc.getBlock(this.model.reference) ||
@@ -546,9 +546,8 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
if (!this._viewportEditor) { if (!this._viewportEditor) {
if (this._previewDoc) { if (this._previewDoc) {
const store = new Store({ blocks: this._previewDoc });
this._viewportEditor = new BlockStdScope({ this._viewportEditor = new BlockStdScope({
store, store: this._previewDoc,
extensions: _previewSpec, extensions: _previewSpec,
}).render(); }).render();
} else { } else {

View File

@@ -1,8 +1,8 @@
import type { Blocks } from '@blocksuite/store'; import type { Store } from '@blocksuite/store';
import type { SurfaceBlockModel } from '../surface-model'; import type { SurfaceBlockModel } from '../surface-model';
export function getSurfaceBlock(doc: Blocks) { export function getSurfaceBlock(doc: Store) {
const blocks = doc.getBlocksByFlavour('affine:surface'); const blocks = doc.getBlocksByFlavour('affine:surface');
return blocks.length !== 0 ? (blocks[0].model as SurfaceBlockModel) : null; return blocks.length !== 0 ? (blocks[0].model as SurfaceBlockModel) : null;
} }

View File

@@ -8,7 +8,7 @@ import {
stdContext, stdContext,
} from '@blocksuite/block-std'; } from '@blocksuite/block-std';
import { WithDisposable } from '@blocksuite/global/utils'; import { WithDisposable } from '@blocksuite/global/utils';
import type { BlockModel, Blocks } from '@blocksuite/store'; import type { BlockModel, Store } from '@blocksuite/store';
import { Text } from '@blocksuite/store'; import { Text } from '@blocksuite/store';
import { consume } from '@lit/context'; import { consume } from '@lit/context';
import { css, html, nothing } from 'lit'; import { css, html, nothing } from 'lit';
@@ -161,7 +161,7 @@ export class BlockCaptionEditor<
accessor display = false; accessor display = false;
@consume({ context: docContext }) @consume({ context: docContext })
accessor doc!: Blocks; accessor doc!: Store;
@query('.block-caption-editor') @query('.block-caption-editor')
accessor input!: HTMLInputElement; accessor input!: HTMLInputElement;

View File

@@ -26,7 +26,7 @@ import {
ZERO_WIDTH_NON_JOINER, ZERO_WIDTH_NON_JOINER,
ZERO_WIDTH_SPACE, ZERO_WIDTH_SPACE,
} from '@blocksuite/inline'; } from '@blocksuite/inline';
import type { Blocks, DocMeta } from '@blocksuite/store'; import type { DocMeta, Store } from '@blocksuite/store';
import { css, html, nothing } from 'lit'; import { css, html, nothing } from 'lit';
import { property, state } from 'lit/decorators.js'; import { property, state } from 'lit/decorators.js';
import { choose } from 'lit/directives/choose.js'; import { choose } from 'lit/directives/choose.js';
@@ -73,7 +73,7 @@ export class AffineReference extends WithDisposable(ShadowlessElement) {
} }
`; `;
private readonly _updateRefMeta = (doc: Blocks) => { private readonly _updateRefMeta = (doc: Store) => {
const refAttribute = this.delta.attributes?.reference; const refAttribute = this.delta.attributes?.reference;
if (!refAttribute) { if (!refAttribute) {
return; return;

View File

@@ -1,9 +1,9 @@
import type { BlockStdScope, EditorHost } from '@blocksuite/block-std'; import type { BlockStdScope, EditorHost } from '@blocksuite/block-std';
import type { GfxModel } from '@blocksuite/block-std/gfx'; import type { GfxModel } from '@blocksuite/block-std/gfx';
import type { BlockModel, Blocks } from '@blocksuite/store'; import type { BlockModel, Store } from '@blocksuite/store';
export abstract class MenuContext { export abstract class MenuContext {
abstract get doc(): Blocks; abstract get doc(): Store;
get firstElement(): GfxModel | null { get firstElement(): GfxModel | null {
return null; return null;

View File

@@ -11,7 +11,7 @@ import {
LinkedPageIcon, LinkedPageIcon,
PageIcon, PageIcon,
} from '@blocksuite/icons/lit'; } from '@blocksuite/icons/lit';
import type { Blocks } from '@blocksuite/store'; import type { Store } from '@blocksuite/store';
import { computed, type Signal, signal } from '@preact/signals-core'; import { computed, type Signal, signal } from '@preact/signals-core';
import type { TemplateResult } from 'lit'; import type { TemplateResult } from 'lit';
@@ -70,9 +70,9 @@ export class DocDisplayMetaService
readonly disposables: Disposable[] = []; readonly disposables: Disposable[] = [];
readonly iconMap = new WeakMap<Blocks, Signal<TemplateResult>>(); readonly iconMap = new WeakMap<Store, Signal<TemplateResult>>();
readonly titleMap = new WeakMap<Blocks, Signal<string>>(); readonly titleMap = new WeakMap<Store, Signal<string>>();
static override setup(di: Container) { static override setup(di: Container) {
di.addImpl(DocDisplayMetaProvider, this, [StdIdentifier]); di.addImpl(DocDisplayMetaProvider, this, [StdIdentifier]);

View File

@@ -1,4 +1,4 @@
import type { BlockModel, Blocks, DraftModel } from '@blocksuite/store'; import type { BlockModel, DraftModel, Store } from '@blocksuite/store';
import { minimatch } from 'minimatch'; import { minimatch } from 'minimatch';
export function matchFlavours<Key extends (keyof BlockSuite.BlockModels)[]>( export function matchFlavours<Key extends (keyof BlockSuite.BlockModels)[]>(
@@ -14,7 +14,7 @@ export function matchFlavours<Key extends (keyof BlockSuite.BlockModels)[]>(
} }
export function isInsideBlockByFlavour( export function isInsideBlockByFlavour(
doc: Blocks, doc: Store,
block: BlockModel | string, block: BlockModel | string,
flavour: string flavour: string
): boolean { ): boolean {

View File

@@ -1,6 +1,6 @@
import { type NoteBlockModel, NoteDisplayMode } from '@blocksuite/affine-model'; import { type NoteBlockModel, NoteDisplayMode } from '@blocksuite/affine-model';
import type { BlockComponent, EditorHost } from '@blocksuite/block-std'; import type { BlockComponent, EditorHost } from '@blocksuite/block-std';
import type { BlockModel, Blocks } from '@blocksuite/store'; import type { BlockModel, Store } from '@blocksuite/store';
import { matchFlavours } from './checker.js'; import { matchFlavours } from './checker.js';
@@ -41,7 +41,7 @@ export function findNoteBlockModel(model: BlockModel) {
) as NoteBlockModel | null; ) as NoteBlockModel | null;
} }
export function getLastNoteBlock(doc: Blocks) { export function getLastNoteBlock(doc: Store) {
let note: NoteBlockModel | null = null; let note: NoteBlockModel | null = null;
if (!doc.root) return null; if (!doc.root) return null;
const { children } = doc.root; const { children } = doc.root;

View File

@@ -1,6 +1,6 @@
import type { ListBlockModel } from '@blocksuite/affine-model'; import type { ListBlockModel } from '@blocksuite/affine-model';
import type { BlockStdScope } from '@blocksuite/block-std'; import type { BlockStdScope } from '@blocksuite/block-std';
import type { BlockModel, Blocks } from '@blocksuite/store'; import type { BlockModel, Store } from '@blocksuite/store';
import { matchFlavours } from './checker.js'; import { matchFlavours } from './checker.js';
@@ -9,7 +9,7 @@ import { matchFlavours } from './checker.js';
* typically used for updating list numbers. The result not contains the list passed in. * typically used for updating list numbers. The result not contains the list passed in.
*/ */
export function getNextContinuousNumberedLists( export function getNextContinuousNumberedLists(
doc: Blocks, doc: Store,
modelOrId: BlockModel | string modelOrId: BlockModel | string
): ListBlockModel[] { ): ListBlockModel[] {
const model = const model =

View File

@@ -1,9 +1,9 @@
import type { BlockModel, Blocks, Text } from '@blocksuite/store'; import type { BlockModel, Store, Text } from '@blocksuite/store';
export function transformModel( export function transformModel(
model: BlockModel, model: BlockModel,
flavour: BlockSuite.Flavour, flavour: BlockSuite.Flavour,
props?: Parameters<Blocks['addBlock']>[1] props?: Parameters<Store['addBlock']>[1]
) { ) {
const doc = model.doc; const doc = model.doc;
const parent = doc.getParent(model); const parent = doc.getParent(model);

View File

@@ -5,7 +5,7 @@ import {
type DndEventState, type DndEventState,
} from '@blocksuite/block-std'; } from '@blocksuite/block-std';
import { Point } from '@blocksuite/global/utils'; import { Point } from '@blocksuite/global/utils';
import { type BlockViewType, type Query, Store } from '@blocksuite/store'; import { type BlockViewType, type Query } from '@blocksuite/store';
import { DragPreview } from '../components/drag-preview.js'; import { DragPreview } from '../components/drag-preview.js';
import type { AffineDragHandleWidget } from '../drag-handle.js'; import type { AffineDragHandleWidget } from '../drag-handle.js';
@@ -79,10 +79,9 @@ export class PreviewHelper {
const query = this._calculateQuery(selectedIds); const query = this._calculateQuery(selectedIds);
const doc = this.widget.doc.doc.getBlocks({ query }); const store = this.widget.doc.doc.getStore({ query });
const previewSpec = SpecProvider.getInstance().getSpec('page:preview'); const previewSpec = SpecProvider.getInstance().getSpec('page:preview');
const store = new Store({ blocks: doc });
const previewStd = new BlockStdScope({ const previewStd = new BlockStdScope({
store, store,
extensions: previewSpec.value, extensions: previewSpec.value,

View File

@@ -17,7 +17,7 @@ import {
RootBlockSchema, RootBlockSchema,
} from '@blocksuite/affine-model'; } from '@blocksuite/affine-model';
import { propertyModelPresets } from '@blocksuite/data-view/property-pure-presets'; 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 { Schema, Text } from '@blocksuite/store';
import { import {
createAutoIncrementIdGenerator, createAutoIncrementIdGenerator,
@@ -49,7 +49,7 @@ function createTestDoc(docId = 'doc0') {
} }
describe('DatabaseManager', () => { describe('DatabaseManager', () => {
let doc: Blocks; let doc: Store;
let db: DatabaseBlockModel; let db: DatabaseBlockModel;
let rootId: BlockModel['id']; let rootId: BlockModel['id'];

View File

@@ -24,7 +24,7 @@ import type { GfxBlockElementModel } from '@blocksuite/block-std/gfx';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions'; import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import type { IBound } from '@blocksuite/global/utils'; import type { IBound } from '@blocksuite/global/utils';
import { Bound } 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 { import {
getBlockComponentByModel, getBlockComponentByModel,
@@ -109,7 +109,7 @@ export class ExportManager {
await Promise.all(promises); await Promise.all(promises);
}; };
get doc(): Blocks { get doc(): Store {
return this.std.doc; return this.std.doc;
} }

View File

@@ -1,7 +1,7 @@
import { HtmlAdapter } from '@blocksuite/affine-shared/adapters'; import { HtmlAdapter } from '@blocksuite/affine-shared/adapters';
import { Container } from '@blocksuite/global/di'; import { Container } from '@blocksuite/global/di';
import { sha } from '@blocksuite/global/utils'; 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 { extMimeMap, Job } from '@blocksuite/store';
import { defaultBlockHtmlAdapterMatchers } from '../adapters/html/block-matcher.js'; import { defaultBlockHtmlAdapterMatchers } from '../adapters/html/block-matcher.js';
@@ -43,7 +43,7 @@ const provider = container.provider();
* @param doc - The doc to be exported. * @param doc - The doc to be exported.
* @returns A Promise that resolves when the export is complete. * @returns A Promise that resolves when the export is complete.
*/ */
async function exportDoc(doc: Blocks) { async function exportDoc(doc: Store) {
const job = new Job({ const job = new Job({
schema: doc.schema, schema: doc.schema,
blobCRUD: doc.blobSync, blobCRUD: doc.blobSync,

View File

@@ -2,7 +2,7 @@ import { MarkdownAdapter } from '@blocksuite/affine-shared/adapters';
import { Container } from '@blocksuite/global/di'; import { Container } from '@blocksuite/global/di';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions'; import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import { assertExists, sha } from '@blocksuite/global/utils'; 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 { extMimeMap, Job } from '@blocksuite/store';
import { defaultBlockMarkdownAdapterMatchers } from '../adapters/index.js'; import { defaultBlockMarkdownAdapterMatchers } from '../adapters/index.js';
@@ -28,7 +28,7 @@ const container = new Container();
const provider = container.provider(); const provider = container.provider();
type ImportMarkdownToBlockOptions = { type ImportMarkdownToBlockOptions = {
doc: Blocks; doc: Store;
markdown: string; markdown: string;
blockId: string; blockId: string;
}; };
@@ -49,7 +49,7 @@ type ImportMarkdownZipOptions = {
* @param doc The doc to export * @param doc The doc to export
* @returns A Promise that resolves when the export is complete * @returns A Promise that resolves when the export is complete
*/ */
async function exportDoc(doc: Blocks) { async function exportDoc(doc: Store) {
const job = new Job({ const job = new Job({
schema: doc.schema, schema: doc.schema,
blobCRUD: doc.blobSync, blobCRUD: doc.blobSync,

View File

@@ -1,11 +1,11 @@
import { sha } from '@blocksuite/global/utils'; 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 { extMimeMap, getAssetName, Job } from '@blocksuite/store';
import { download, Unzip, Zip } from '../transformers/utils.js'; import { download, Unzip, Zip } from '../transformers/utils.js';
import { replaceIdMiddleware, titleMiddleware } from './middlewares.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 zip = new Zip();
const job = new Job({ const job = new Job({
schema: collection.schema, schema: collection.schema,

View File

@@ -5,7 +5,7 @@ import type {
GroupElementModel, GroupElementModel,
} from '@blocksuite/affine-model'; } from '@blocksuite/affine-model';
import type { Slot } from '@blocksuite/global/utils'; 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. */ /** Common context interface definition for block models. */
@@ -14,7 +14,7 @@ type EditorSlots = {
}; };
export type AbstractEditor = { export type AbstractEditor = {
doc: Blocks; doc: Store;
mode: DocMode; mode: DocMode;
readonly slots: EditorSlots; readonly slots: EditorSlots;
} & HTMLElement; } & HTMLElement;

View File

@@ -9,7 +9,7 @@ import {
} from '@blocksuite/affine-shared/adapters'; } from '@blocksuite/affine-shared/adapters';
import type { BlockComponent, UIEventHandler } from '@blocksuite/block-std'; import type { BlockComponent, UIEventHandler } from '@blocksuite/block-std';
import { DisposableGroup } from '@blocksuite/global/utils'; import { DisposableGroup } from '@blocksuite/global/utils';
import type { Blocks, BlockSnapshot } from '@blocksuite/store'; import type { BlockSnapshot, Store } from '@blocksuite/store';
import { import {
defaultImageProxyMiddleware, defaultImageProxyMiddleware,
@@ -99,7 +99,7 @@ export class PageClipboard {
onBlockSnapshotPaste = async ( onBlockSnapshotPaste = async (
snapshot: BlockSnapshot, snapshot: BlockSnapshot,
doc: Blocks, doc: Store,
parent?: string, parent?: string,
index?: number index?: number
) => { ) => {

View File

@@ -10,7 +10,7 @@ import {
} from '@blocksuite/block-std'; } from '@blocksuite/block-std';
import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx'; import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
import { DisposableGroup, Vec, WithDisposable } from '@blocksuite/global/utils'; 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 { consume } from '@lit/context';
import { css, html, LitElement } from 'lit'; import { css, html, LitElement } from 'lit';
import { property, query } from 'lit/decorators.js'; import { property, query } from 'lit/decorators.js';
@@ -150,7 +150,7 @@ export class EdgelessConnectorHandle extends WithDisposable(LitElement) {
@consume({ @consume({
context: docContext, context: docContext,
}) })
accessor doc!: Blocks; accessor doc!: Store;
@property({ attribute: false }) @property({ attribute: false })
accessor edgeless!: EdgelessRootBlockComponent; accessor edgeless!: EdgelessRootBlockComponent;

View File

@@ -12,7 +12,7 @@ import {
DisposableGroup, DisposableGroup,
WithDisposable, WithDisposable,
} from '@blocksuite/global/utils'; } 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 { css, html, nothing, type PropertyValues } from 'lit';
import { property, query, state } from 'lit/decorators.js'; import { property, query, state } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.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 _frameDisposables: DisposableGroup | null = null;
private _previewDoc: Blocks | null = null; private _previewDoc: Store | null = null;
private readonly _previewSpec = private readonly _previewSpec =
SpecProvider.getInstance().getSpec('edgeless:preview'); SpecProvider.getInstance().getSpec('edgeless:preview');
@@ -155,7 +155,6 @@ export class FramePreview extends WithDisposable(ShadowlessElement) {
private _renderSurfaceContent() { private _renderSurfaceContent() {
if (!this._previewDoc || !this.frame) return nothing; if (!this._previewDoc || !this.frame) return nothing;
const { width, height } = this.frameViewportWH; const { width, height } = this.frameViewportWH;
const store = new Store({ blocks: this._previewDoc });
const _previewSpec = this._previewSpec.value; const _previewSpec = this._previewSpec.value;
return html`<div return html`<div
@@ -173,7 +172,7 @@ export class FramePreview extends WithDisposable(ShadowlessElement) {
})} })}
> >
${new BlockStdScope({ ${new BlockStdScope({
store, store: this._previewDoc,
extensions: _previewSpec, extensions: _previewSpec,
}).render()} }).render()}
</div> </div>

View File

@@ -19,7 +19,7 @@ import {
type IVec, type IVec,
type SerializedXYWH, type SerializedXYWH,
} from '@blocksuite/global/utils'; } from '@blocksuite/global/utils';
import type { Blocks } from '@blocksuite/store'; import type { Store } from '@blocksuite/store';
import { Text } from '@blocksuite/store'; import { Text } from '@blocksuite/store';
import * as Y from 'yjs'; import * as Y from 'yjs';
@@ -463,7 +463,7 @@ export class EdgelessFrameManager extends GfxExtension {
} }
export function getNotesInFrameBound( export function getNotesInFrameBound(
doc: Blocks, doc: Store,
frame: FrameBlockModel, frame: FrameBlockModel,
fullyContained: boolean = true fullyContained: boolean = true
) { ) {
@@ -481,7 +481,7 @@ export function getNotesInFrameBound(
} }
export function getBlocksInFrameBound( export function getBlocksInFrameBound(
doc: Blocks, doc: Store,
model: FrameBlockModel, model: FrameBlockModel,
fullyContained: boolean = true fullyContained: boolean = true
) { ) {

View File

@@ -5,7 +5,7 @@ import { DocModeProvider } from '@blocksuite/affine-shared/services';
import { getBlockProps } from '@blocksuite/affine-shared/utils'; import { getBlockProps } from '@blocksuite/affine-shared/utils';
import type { EditorHost } from '@blocksuite/block-std'; import type { EditorHost } from '@blocksuite/block-std';
import { GfxBlockElementModel } from '@blocksuite/block-std/gfx'; 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 { import {
getElementProps, getElementProps,
@@ -14,11 +14,7 @@ import {
} from '../../../edgeless/utils/clone-utils.js'; } from '../../../edgeless/utils/clone-utils.js';
import { isFrameBlock, isNoteBlock } from '../../../edgeless/utils/query.js'; import { isFrameBlock, isNoteBlock } from '../../../edgeless/utils/query.js';
function addBlocksToDoc( function addBlocksToDoc(targetDoc: Store, model: BlockModel, parentId: string) {
targetDoc: Blocks,
model: BlockModel,
parentId: string
) {
// Add current block to linked doc // Add current block to linked doc
const blockProps = getBlockProps(model); const blockProps = getBlockProps(model);
const newModelId = targetDoc.addBlock( const newModelId = targetDoc.addBlock(
@@ -36,7 +32,7 @@ function addBlocksToDoc(
} }
export function createLinkedDocFromNote( export function createLinkedDocFromNote(
doc: Blocks, doc: Store,
note: NoteBlockModel, note: NoteBlockModel,
docTitle?: string docTitle?: string
) { ) {

View File

@@ -1,5 +1,5 @@
import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils'; import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
import { type Blocks, type ExtensionType, Store } from '@blocksuite/store'; import type { ExtensionType, Store } from '@blocksuite/store';
import { html } from 'lit'; import { html } from 'lit';
import { customElement, property } from 'lit/decorators.js'; import { customElement, property } from 'lit/decorators.js';
@@ -18,9 +18,8 @@ export class TestEditorContainer extends SignalWatcher(
override connectedCallback() { override connectedCallback() {
super.connectedCallback(); super.connectedCallback();
const store = new Store({ blocks: this.doc });
this._std = new BlockStdScope({ this._std = new BlockStdScope({
store, store: this.doc,
extensions: this.specs, extensions: this.specs,
}); });
} }
@@ -32,7 +31,7 @@ export class TestEditorContainer extends SignalWatcher(
} }
@property({ attribute: false }) @property({ attribute: false })
accessor doc!: Blocks; accessor doc!: Store;
@property({ attribute: false }) @property({ attribute: false })
accessor specs: ExtensionType[] = []; accessor specs: ExtensionType[] = [];

View File

@@ -2,11 +2,11 @@ import type { ServiceProvider } from '@blocksuite/global/di';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions'; import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import type { import type {
BaseAdapter, BaseAdapter,
Blocks,
BlockSnapshot, BlockSnapshot,
Job, Job,
JobMiddleware, JobMiddleware,
Slice, Slice,
Store,
} from '@blocksuite/store'; } from '@blocksuite/store';
import DOMPurify from 'dompurify'; import DOMPurify from 'dompurify';
import type { RootContentMap } from 'hast'; import type { RootContentMap } from 'hast';
@@ -110,7 +110,7 @@ export class Clipboard extends LifeCycleWatcher {
private readonly _getSnapshotByPriority = async ( private readonly _getSnapshotByPriority = async (
getItem: (type: string) => string | File[], getItem: (type: string) => string | File[],
doc: Blocks, doc: Store,
parent?: string, parent?: string,
index?: number index?: number
) => { ) => {
@@ -182,7 +182,7 @@ export class Clipboard extends LifeCycleWatcher {
duplicateSlice = async ( duplicateSlice = async (
slice: Slice, slice: Slice,
doc: Blocks, doc: Store,
parent?: string, parent?: string,
index?: number, index?: number,
type = 'BLOCKSUITE/SNAPSHOT' type = 'BLOCKSUITE/SNAPSHOT'
@@ -201,7 +201,7 @@ export class Clipboard extends LifeCycleWatcher {
paste = async ( paste = async (
event: ClipboardEvent, event: ClipboardEvent,
doc: Blocks, doc: Store,
parent?: string, parent?: string,
index?: number index?: number
) => { ) => {
@@ -238,7 +238,7 @@ export class Clipboard extends LifeCycleWatcher {
pasteBlockSnapshot = async ( pasteBlockSnapshot = async (
snapshot: BlockSnapshot, snapshot: BlockSnapshot,
doc: Blocks, doc: Store,
parent?: string, parent?: string,
index?: number index?: number
) => { ) => {

View File

@@ -4,7 +4,7 @@ import {
getBoundWithRotation, getBoundWithRotation,
intersects, intersects,
} from '@blocksuite/global/utils'; } from '@blocksuite/global/utils';
import type { BlockModel, Blocks } from '@blocksuite/store'; import type { BlockModel, Store } from '@blocksuite/store';
import { compare } from '../utils/layer.js'; import { compare } from '../utils/layer.js';
import { GfxBlockElementModel } from './model/gfx-block-model.js'; import { GfxBlockElementModel } from './model/gfx-block-model.js';
@@ -361,7 +361,7 @@ export class GridManager {
this.add(element); this.add(element);
} }
watch(blocks: { doc?: Blocks; surface?: SurfaceBlockModel | null }) { watch(blocks: { doc?: Store; surface?: SurfaceBlockModel | null }) {
const disposables: { dispose: () => void }[] = []; const disposables: { dispose: () => void }[] = [];
const { doc, surface } = blocks; const { doc, surface } = blocks;
const isRenderableBlock = ( const isRenderableBlock = (

View File

@@ -5,7 +5,7 @@ import {
last, last,
Slot, Slot,
} from '@blocksuite/global/utils'; } from '@blocksuite/global/utils';
import type { Blocks } from '@blocksuite/store'; import type { Store } from '@blocksuite/store';
import { generateKeyBetween } from 'fractional-indexing'; import { generateKeyBetween } from 'fractional-indexing';
import { import {
@@ -100,7 +100,7 @@ export class LayerManager {
}; };
constructor( constructor(
private readonly _doc: Blocks, private readonly _doc: Store,
private _surface: SurfaceBlockModel | null, private _surface: SurfaceBlockModel | null,
options: { options: {
watch: boolean; watch: boolean;
@@ -476,7 +476,7 @@ export class LayerManager {
private _reset() { private _reset() {
const elements = ( const elements = (
this._doc this._doc
.getBlocks() .getStore()
.filter( .filter(
model => model =>
model instanceof GfxBlockElementModel && model instanceof GfxBlockElementModel &&
@@ -775,7 +775,7 @@ export class LayerManager {
} }
} }
watch(blocks: { doc?: Blocks; surface: SurfaceBlockModel | null }) { watch(blocks: { doc?: Store; surface: SurfaceBlockModel | null }) {
const { doc, surface } = blocks; const { doc, surface } = blocks;
if (doc) { if (doc) {

View File

@@ -75,7 +75,7 @@ export class BlockStdScope {
} }
get doc() { get doc() {
return this.store.blocks; return this.store;
} }
get clipboard() { get clipboard() {

View File

@@ -1,10 +1,10 @@
import type { Blocks } from '@blocksuite/store'; import type { Store } from '@blocksuite/store';
import { effect } from '@preact/signals-core'; import { effect } from '@preact/signals-core';
import { SurfaceBlockModel } from '../gfx/model/surface/surface-model.js'; import { SurfaceBlockModel } from '../gfx/model/surface/surface-model.js';
export function onSurfaceAdded( export function onSurfaceAdded(
doc: Blocks, doc: Store,
callback: (model: SurfaceBlockModel | null) => void callback: (model: SurfaceBlockModel | null) => void
) { ) {
let found = false; let found = false;

View File

@@ -1,5 +1,5 @@
import { nToLast } from '@blocksuite/global/utils'; import { nToLast } from '@blocksuite/global/utils';
import type { Blocks } from '@blocksuite/store'; import type { Store } from '@blocksuite/store';
import type { GfxLocalElementModel } from '../gfx/index.js'; import type { GfxLocalElementModel } from '../gfx/index.js';
import type { Layer } from '../gfx/layer.js'; import type { Layer } from '../gfx/layer.js';
@@ -82,7 +82,7 @@ export function isInRange(edges: [GfxModel, GfxModel], target: GfxModel) {
} }
export function renderableInEdgeless( export function renderableInEdgeless(
doc: Blocks, doc: Store,
surface: SurfaceBlockModel, surface: SurfaceBlockModel,
block: GfxBlockElementModel block: GfxBlockElementModel
) { ) {

View File

@@ -1,4 +1,4 @@
import type { Blocks } from '@blocksuite/store'; import type { Store } from '@blocksuite/store';
import { import {
type GfxCompatibleInterface, type GfxCompatibleInterface,
@@ -124,16 +124,13 @@ export function isLockedImpl(element: GfxCompatibleInterface): boolean {
return isLockedBySelfImpl(element) || isLockedByAncestorImpl(element); return isLockedBySelfImpl(element) || isLockedByAncestorImpl(element);
} }
export function lockElementImpl(doc: Blocks, element: GfxCompatibleInterface) { export function lockElementImpl(doc: Store, element: GfxCompatibleInterface) {
doc.transact(() => { doc.transact(() => {
element.lockedBySelf = true; element.lockedBySelf = true;
}); });
} }
export function unlockElementImpl( export function unlockElementImpl(doc: Store, element: GfxCompatibleInterface) {
doc: Blocks,
element: GfxCompatibleInterface
) {
doc.transact(() => { doc.transact(() => {
element.lockedBySelf = false; element.lockedBySelf = false;
}); });

View File

@@ -1,6 +1,6 @@
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions'; import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils'; import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
import { type BlockModel, Blocks, type BlockViewType } from '@blocksuite/store'; import { type BlockModel, type BlockViewType, Store } from '@blocksuite/store';
import { consume, provide } from '@lit/context'; import { consume, provide } from '@lit/context';
import { computed } from '@preact/signals-core'; import { computed } from '@preact/signals-core';
import { nothing, type TemplateResult } from 'lit'; import { nothing, type TemplateResult } from 'lit';
@@ -23,7 +23,7 @@ import { ShadowlessElement } from './shadowless-element.js';
import type { WidgetComponent } from './widget-component.js'; import type { WidgetComponent } from './widget-component.js';
@requiredProperties({ @requiredProperties({
doc: PropTypes.instanceOf(Blocks), doc: PropTypes.instanceOf(Store),
std: PropTypes.object, std: PropTypes.object,
widgets: PropTypes.recordOf(PropTypes.object), widgets: PropTypes.recordOf(PropTypes.object),
}) })
@@ -307,7 +307,7 @@ export class BlockComponent<
private accessor _service: Service | null = null; private accessor _service: Service | null = null;
@consume({ context: docContext }) @consume({ context: docContext })
accessor doc!: Blocks; accessor doc!: Store;
@property({ attribute: false }) @property({ attribute: false })
accessor viewType: BlockViewType = 'display'; accessor viewType: BlockViewType = 'display';

View File

@@ -4,7 +4,7 @@ import {
handleError, handleError,
} from '@blocksuite/global/exceptions'; } from '@blocksuite/global/exceptions';
import { SignalWatcher, Slot, WithDisposable } from '@blocksuite/global/utils'; import { SignalWatcher, Slot, WithDisposable } from '@blocksuite/global/utils';
import { type BlockModel, Blocks } from '@blocksuite/store'; import { type BlockModel, Store } from '@blocksuite/store';
import { createContext, provide } from '@lit/context'; import { createContext, provide } from '@lit/context';
import { css, LitElement, nothing, type TemplateResult } from 'lit'; import { css, LitElement, nothing, type TemplateResult } from 'lit';
import { property } from 'lit/decorators.js'; import { property } from 'lit/decorators.js';
@@ -22,11 +22,11 @@ import type { ViewStore } from '../view-store.js';
import { BLOCK_ID_ATTR, WIDGET_ID_ATTR } from './consts.js'; import { BLOCK_ID_ATTR, WIDGET_ID_ATTR } from './consts.js';
import { ShadowlessElement } from './shadowless-element.js'; import { ShadowlessElement } from './shadowless-element.js';
export const docContext = createContext<Blocks>('doc'); export const docContext = createContext<Store>('doc');
export const stdContext = createContext<BlockStdScope>('std'); export const stdContext = createContext<BlockStdScope>('std');
@requiredProperties({ @requiredProperties({
doc: PropTypes.instanceOf(Blocks), doc: PropTypes.instanceOf(Store),
std: PropTypes.object, std: PropTypes.object,
}) })
export class EditorHost extends SignalWatcher( export class EditorHost extends SignalWatcher(
@@ -189,7 +189,7 @@ export class EditorHost extends SignalWatcher(
@provide({ context: docContext }) @provide({ context: docContext })
@property({ attribute: false }) @property({ attribute: false })
accessor doc!: Blocks; accessor doc!: Store;
@provide({ context: stdContext }) @provide({ context: stdContext })
@property({ attribute: false }) @property({ attribute: false })

View File

@@ -1,5 +1,5 @@
import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils'; import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
import type { BlockModel, Blocks } from '@blocksuite/store'; import type { BlockModel, Store } from '@blocksuite/store';
import { consume } from '@lit/context'; import { consume } from '@lit/context';
import { LitElement } from 'lit'; import { LitElement } from 'lit';
@@ -94,7 +94,7 @@ export class WidgetComponent<
} }
@consume({ context: docContext }) @consume({ context: docContext })
private accessor _doc!: Blocks; private accessor _doc!: Store;
@consume({ context: modelContext }) @consume({ context: modelContext })
private accessor _model!: Model; private accessor _model!: Model;

View File

@@ -4,7 +4,7 @@ import type { Slot } from '@blocksuite/global/utils';
import { assert, beforeEach, describe, expect, it, vi } from 'vitest'; import { assert, beforeEach, describe, expect, it, vi } from 'vitest';
import { applyUpdate, type Doc, encodeStateAsUpdate } from 'yjs'; import { applyUpdate, type Doc, encodeStateAsUpdate } from 'yjs';
import type { BlockModel, Blocks, BlockSchemaType, DocMeta } from '../index.js'; import type { BlockModel, BlockSchemaType, DocMeta, Store } from '../index.js';
import { Schema } from '../index.js'; import { Schema } from '../index.js';
import { Text } from '../reactive/text.js'; import { Text } from '../reactive/text.js';
import { createAutoIncrementIdGenerator } from '../test/index.js'; import { createAutoIncrementIdGenerator } from '../test/index.js';
@@ -52,7 +52,7 @@ function waitOnce<T>(slot: Slot<T>) {
return new Promise<T>(resolve => slot.once(val => resolve(val))); return new Promise<T>(resolve => slot.once(val => resolve(val)));
} }
function createRoot(doc: Blocks) { function createRoot(doc: Store) {
doc.addBlock('affine:page'); doc.addBlock('affine:page');
if (!doc.root) throw new Error('root not found'); if (!doc.root) throw new Error('root not found');
return doc.root; return doc.root;

View File

@@ -1,6 +1,6 @@
import { BlockSuiteError } from '@blocksuite/global/exceptions'; import { BlockSuiteError } from '@blocksuite/global/exceptions';
import type { Blocks, DraftModel } from '../model/index.js'; import type { DraftModel, Store } from '../model/index.js';
import type { AssetsManager } from '../transformer/assets.js'; import type { AssetsManager } from '../transformer/assets.js';
import type { Job, Slice } from '../transformer/index.js'; import type { Job, Slice } from '../transformer/index.js';
import type { import type {
@@ -93,7 +93,7 @@ export abstract class BaseAdapter<AdapterTarget = unknown> {
| Promise<FromBlockSnapshotResult<AdapterTarget>> | Promise<FromBlockSnapshotResult<AdapterTarget>>
| FromBlockSnapshotResult<AdapterTarget>; | FromBlockSnapshotResult<AdapterTarget>;
async fromDoc(doc: Blocks) { async fromDoc(doc: Store) {
try { try {
const docSnapshot = this.job.docToSnapshot(doc); const docSnapshot = this.job.docToSnapshot(doc);
if (!docSnapshot) return; if (!docSnapshot) return;
@@ -138,7 +138,7 @@ export abstract class BaseAdapter<AdapterTarget = unknown> {
async toBlock( async toBlock(
payload: ToBlockSnapshotPayload<AdapterTarget>, payload: ToBlockSnapshotPayload<AdapterTarget>,
doc: Blocks, doc: Store,
parent?: string, parent?: string,
index?: number index?: number
) { ) {
@@ -175,7 +175,7 @@ export abstract class BaseAdapter<AdapterTarget = unknown> {
async toSlice( async toSlice(
payload: ToSliceSnapshotPayload<AdapterTarget>, payload: ToSliceSnapshotPayload<AdapterTarget>,
doc: Blocks, doc: Store,
parent?: string, parent?: string,
index?: number index?: number
) { ) {

View File

@@ -1,8 +1,8 @@
import { type Container, createIdentifier } from '@blocksuite/global/di'; import { type Container, createIdentifier } from '@blocksuite/global/di';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions'; import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import { StoreIdentifier } from '../store/identifier'; import type { Store } from '../model/store';
import type { Store } from '../store/store'; import { StoreIdentifier } from '../model/store/identifier';
import { Extension } from './extension'; import { Extension } from './extension';
export const StoreExtensionIdentifier = export const StoreExtensionIdentifier =

View File

@@ -6,7 +6,6 @@ export * from './extension';
export * from './model'; export * from './model';
export * from './reactive'; export * from './reactive';
export * from './schema'; export * from './schema';
export * from './store';
export * from './transformer'; export * from './transformer';
export { type IdGenerator, nanoid, uuidv4 } from './utils/id-generator'; export { type IdGenerator, nanoid, uuidv4 } from './utils/id-generator';
export * from './yjs'; export * from './yjs';

View File

@@ -2,7 +2,7 @@ import { type Disposable, Slot } from '@blocksuite/global/utils';
import { computed, type Signal, signal } from '@preact/signals-core'; import { computed, type Signal, signal } from '@preact/signals-core';
import type { Text } from '../../reactive/index.js'; import type { Text } from '../../reactive/index.js';
import type { Blocks } from '../blocks/blocks.js'; import type { Store } from '../store/store.js';
import type { YBlock } from './types.js'; import type { YBlock } from './types.js';
import type { RoleType } from './zod.js'; import type { RoleType } from './zod.js';
@@ -38,7 +38,7 @@ export class BlockModel<
/** /**
* @deprecated use doc instead * @deprecated use doc instead
*/ */
page!: Blocks; page!: Store;
private readonly _childModels = computed(() => { private readonly _childModels = computed(() => {
const value: BlockModel[] = []; const value: BlockModel[] = [];
@@ -102,7 +102,7 @@ export class BlockModel<
return this.page; return this.page;
} }
set doc(doc: Blocks) { set doc(doc: Store) {
this.page = doc; this.page = doc;
} }

View File

@@ -1,5 +1,5 @@
import type { Schema } from '../../schema/index.js'; import type { Schema } from '../../schema/index.js';
import type { Blocks } from '../blocks/blocks.js'; import type { Store } from '../store/store.js';
import { SyncController } from './sync-controller.js'; import { SyncController } from './sync-controller.js';
import type { BlockOptions, YBlock } from './types.js'; import type { BlockOptions, YBlock } from './types.js';
@@ -37,7 +37,7 @@ export class Block {
constructor( constructor(
readonly schema: Schema, readonly schema: Schema,
readonly yBlock: YBlock, readonly yBlock: YBlock,
readonly doc?: Blocks, readonly doc?: Store,
readonly options: BlockOptions = {} readonly options: BlockOptions = {}
) { ) {
const onChange = !options.onChange const onChange = !options.onChange

View File

@@ -11,7 +11,7 @@ import {
y2Native, y2Native,
} from '../../reactive/index.js'; } from '../../reactive/index.js';
import type { Schema } from '../../schema/schema.js'; import type { Schema } from '../../schema/schema.js';
import type { Blocks } from '../blocks/blocks.js'; import type { Store } from '../store/store.js';
import { BlockModel } from './block-model.js'; import { BlockModel } from './block-model.js';
import type { YBlock } from './types.js'; import type { YBlock } from './types.js';
import { internalPrimitives } from './zod.js'; import { internalPrimitives } from './zod.js';
@@ -104,7 +104,7 @@ export class SyncController {
constructor( constructor(
readonly schema: Schema, readonly schema: Schema,
readonly yBlock: YBlock, readonly yBlock: YBlock,
readonly doc?: Blocks, readonly doc?: Store,
readonly onChange?: (key: string, value: unknown) => void readonly onChange?: (key: string, value: unknown) => void
) { ) {
const { id, flavour, version, yChildren, props } = this._parseYBlock(); const { id, flavour, version, yChildren, props } = this._parseYBlock();

View File

@@ -1,2 +0,0 @@
export * from './blocks.js';
export * from './query.js';

View File

@@ -4,15 +4,12 @@ import type * as Y from 'yjs';
import type { Schema } from '../schema/schema.js'; import type { Schema } from '../schema/schema.js';
import type { AwarenessStore } from '../yjs/awareness.js'; import type { AwarenessStore } from '../yjs/awareness.js';
import type { YBlock } from './block/types.js'; import type { YBlock } from './block/types.js';
import type { Blocks } from './blocks/blocks.js'; import type { Query } from './store/query.js';
import type { Query } from './blocks/query.js'; import type { Store, StoreOptions } from './store/store.js';
import type { Workspace } from './workspace.js'; import type { Workspace } from './workspace.js';
import type { DocMeta } from './workspace-meta.js'; import type { DocMeta } from './workspace-meta.js';
export type GetBlocksOptions = { export type GetBlocksOptions = Omit<StoreOptions, 'schema' | 'doc'>;
query?: Query;
readonly?: boolean;
};
export type CreateBlocksOptions = GetBlocksOptions & { export type CreateBlocksOptions = GetBlocksOptions & {
id?: string; id?: string;
}; };
@@ -53,7 +50,7 @@ export interface Doc {
captureSync(): void; captureSync(): void;
clear(): void; clear(): void;
getBlocks(options?: GetBlocksOptions): Blocks; getStore(options?: GetBlocksOptions): Store;
clearQuery(query: Query, readonly?: boolean): void; clearQuery(query: Query, readonly?: boolean): void;
get loaded(): boolean; get loaded(): boolean;

View File

@@ -1,8 +1,8 @@
import type { BlockModel } from './block/block-model.js'; import type { BlockModel } from './block/block-model.js';
export * from './block/index.js'; export * from './block/index.js';
export * from './blocks/index.js';
export * from './doc.js'; export * from './doc.js';
export * from './store/index.js';
export * from './workspace.js'; export * from './workspace.js';
export * from './workspace-meta.js'; export * from './workspace-meta.js';

View File

@@ -0,0 +1,3 @@
export * from './identifier.js';
export * from './query.js';
export * from './store.js';

View File

@@ -1,7 +1,9 @@
import { Container, type ServiceProvider } from '@blocksuite/global/di';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions'; import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import { type Disposable, Slot } from '@blocksuite/global/utils'; import { type Disposable, Slot } from '@blocksuite/global/utils';
import { signal } from '@preact/signals-core'; import { signal } from '@preact/signals-core';
import type { ExtensionType } from '../../extension/extension.js';
import type { Schema } from '../../schema/index.js'; import type { Schema } from '../../schema/index.js';
import { import {
Block, Block,
@@ -12,17 +14,22 @@ import {
} from '../block/index.js'; } from '../block/index.js';
import type { Doc } from '../doc.js'; import type { Doc } from '../doc.js';
import { DocCRUD } from './crud.js'; import { DocCRUD } from './crud.js';
import { StoreIdentifier } from './identifier.js';
import { type Query, runQuery } from './query.js'; import { type Query, runQuery } from './query.js';
import { syncBlockProps } from './utils.js'; import { syncBlockProps } from './utils.js';
type DocOptions = { export type StoreOptions = {
schema: Schema; schema: Schema;
blockCollection: Doc; doc: Doc;
readonly?: boolean; readonly?: boolean;
query?: Query; query?: Query;
provider?: ServiceProvider;
extensions?: ExtensionType[];
}; };
export class Blocks { export class Store {
private readonly _provider: ServiceProvider;
private readonly _runQuery = (block: Block) => { private readonly _runQuery = (block: Block) => {
runQuery(this._query, block); runQuery(this._query, block);
}; };
@@ -147,6 +154,10 @@ export class Blocks {
return this._doc.awarenessStore; return this._doc.awarenessStore;
} }
get provider() {
return this._provider;
}
get blobSync() { get blobSync() {
return this.workspace.blobSync; return this.workspace.blobSync;
} }
@@ -259,8 +270,24 @@ export class Blocks {
return this._doc.withoutTransact.bind(this._doc); return this._doc.withoutTransact.bind(this._doc);
} }
constructor({ schema, blockCollection, readonly, query }: DocOptions) { constructor({
this._doc = blockCollection; schema,
doc,
readonly,
query,
provider,
extensions,
}: StoreOptions) {
const container = new Container();
container.addImpl(StoreIdentifier, () => this);
const userExtensions = extensions ?? [];
userExtensions.forEach(extension => {
extension.setup(container);
});
this._provider = container.provider(undefined, provider);
this._doc = doc;
this.slots = { this.slots = {
ready: new Slot(), ready: new Slot(),
@@ -271,7 +298,7 @@ export class Blocks {
yBlockUpdated: this._doc.slots.yBlockUpdated, yBlockUpdated: this._doc.slots.yBlockUpdated,
}; };
this._crud = new DocCRUD(this._yBlocks, blockCollection.schema); this._crud = new DocCRUD(this._yBlocks, doc.schema);
this._schema = schema; this._schema = schema;
this._readonly = readonly; this._readonly = readonly;
if (query) { if (query) {
@@ -565,7 +592,7 @@ export class Blocks {
return (this.getBlock(id)?.model ?? null) as Model | null; return (this.getBlock(id)?.model ?? null) as Model | null;
} }
getBlocks() { getStore() {
return Object.values(this._blocks.peek()).map(block => block.model); return Object.values(this._blocks.peek()).map(block => block.model);
} }

View File

@@ -5,8 +5,8 @@ import type * as Y from 'yjs';
import type { Schema } from '../schema/schema.js'; import type { Schema } from '../schema/schema.js';
import type { IdGenerator } from '../utils/id-generator.js'; import type { IdGenerator } from '../utils/id-generator.js';
import type { AwarenessStore } from '../yjs/awareness.js'; import type { AwarenessStore } from '../yjs/awareness.js';
import type { Blocks } from './blocks/blocks.js';
import type { CreateBlocksOptions, Doc, GetBlocksOptions } from './doc.js'; import type { CreateBlocksOptions, Doc, GetBlocksOptions } from './doc.js';
import type { Store } from './store/store.js';
import type { WorkspaceMeta } from './workspace-meta.js'; import type { WorkspaceMeta } from './workspace-meta.js';
export interface Workspace { export interface Workspace {
@@ -26,8 +26,8 @@ export interface Workspace {
docRemoved: Slot<string>; docRemoved: Slot<string>;
}; };
createDoc(options?: CreateBlocksOptions): Blocks; createDoc(options?: CreateBlocksOptions): Store;
getDoc(docId: string, options?: GetBlocksOptions): Blocks | null; getDoc(docId: string, options?: GetBlocksOptions): Store | null;
removeDoc(docId: string): void; removeDoc(docId: string): void;
dispose(): void; dispose(): void;

View File

@@ -1,2 +0,0 @@
export * from './identifier';
export * from './store';

View File

@@ -1,41 +0,0 @@
import { Container, type ServiceProvider } from '@blocksuite/global/di';
import type { Extension, StoreExtension } from '../extension';
import type { Blocks } from '../model';
import { StoreIdentifier } from './identifier';
export interface StoreOptions {
blocks: Blocks;
provider?: ServiceProvider;
extensions?: (typeof Extension | typeof StoreExtension)[];
}
export class Store {
private readonly _blocks: Blocks;
private readonly _provider: ServiceProvider;
get blocks() {
return this._blocks;
}
get provider() {
return this._provider;
}
get awareness() {
return this._blocks.awarenessStore;
}
constructor(options: StoreOptions) {
this._blocks = options.blocks;
const container = new Container();
container.addImpl(StoreIdentifier, () => this);
const userExtensions = options.extensions ?? [];
userExtensions.forEach(extension => {
extension.setup(container);
});
this._provider = container.provider(undefined, options.provider);
}
}

View File

@@ -3,9 +3,9 @@ import { signal } from '@preact/signals-core';
import * as Y from 'yjs'; import * as Y from 'yjs';
import type { YBlock } from '../model/block/types.js'; import type { YBlock } from '../model/block/types.js';
import { Blocks } from '../model/blocks/blocks.js';
import type { Query } from '../model/blocks/query.js';
import type { Doc, GetBlocksOptions, Workspace } from '../model/index.js'; import type { Doc, GetBlocksOptions, Workspace } from '../model/index.js';
import type { Query } from '../model/store/query.js';
import { Store } from '../model/store/store.js';
import type { AwarenessStore } from '../yjs/index.js'; import type { AwarenessStore } from '../yjs/index.js';
type DocOptions = { type DocOptions = {
@@ -25,9 +25,9 @@ export class TestDoc implements Doc {
private readonly _collection: Workspace; private readonly _collection: Workspace;
private readonly _docMap = { private readonly _docMap = {
undefined: new Map<string, Blocks>(), undefined: new Map<string, Store>(),
true: new Map<string, Blocks>(), true: new Map<string, Store>(),
false: new Map<string, Blocks>(), false: new Map<string, Store>(),
}; };
// doc/space container. // doc/space container.
@@ -279,7 +279,7 @@ export class TestDoc implements Doc {
} }
} }
getBlocks({ readonly, query }: GetBlocksOptions = {}) { getStore({ readonly, query, provider, extensions }: GetBlocksOptions = {}) {
const readonlyKey = this._getReadonlyKey(readonly); const readonlyKey = this._getReadonlyKey(readonly);
const key = JSON.stringify(query); const key = JSON.stringify(query);
@@ -288,11 +288,13 @@ export class TestDoc implements Doc {
return this._docMap[readonlyKey].get(key)!; return this._docMap[readonlyKey].get(key)!;
} }
const doc = new Blocks({ const doc = new Store({
blockCollection: this, doc: this,
schema: this.workspace.schema, schema: this.workspace.schema,
readonly, readonly,
query, query,
provider,
extensions,
}); });
this._docMap[readonlyKey].set(key, doc); this._docMap[readonlyKey].set(key, doc);

View File

@@ -17,9 +17,9 @@ import { Awareness } from 'y-protocols/awareness.js';
import * as Y from 'yjs'; import * as Y from 'yjs';
import type { import type {
Blocks,
CreateBlocksOptions, CreateBlocksOptions,
GetBlocksOptions, GetBlocksOptions,
Store,
Workspace, Workspace,
WorkspaceMeta, WorkspaceMeta,
} from '../model/index.js'; } from '../model/index.js';
@@ -205,7 +205,7 @@ export class TestWorkspace implements Workspace {
tags: [], tags: [],
}); });
this.slots.docCreated.emit(docId); this.slots.docCreated.emit(docId);
return this.getDoc(docId, { query, readonly }) as Blocks; return this.getDoc(docId, { query, readonly }) as Store;
} }
dispose() { dispose() {
@@ -227,9 +227,9 @@ export class TestWorkspace implements Workspace {
return space ?? null; return space ?? null;
} }
getDoc(docId: string, options?: GetBlocksOptions): Blocks | null { getDoc(docId: string, options?: GetBlocksOptions): Store | null {
const collection = this.getBlockCollection(docId); const collection = this.getBlockCollection(docId);
return collection?.getBlocks(options) ?? null; return collection?.getStore(options) ?? null;
} }
removeDoc(docId: string) { removeDoc(docId: string) {

View File

@@ -3,9 +3,9 @@ import { nextTick, Slot } from '@blocksuite/global/utils';
import type { import type {
BlockModel, BlockModel,
Blocks,
BlockSchemaType, BlockSchemaType,
DraftModel, DraftModel,
Store,
} from '../model/index.js'; } from '../model/index.js';
import type { Schema } from '../schema/index.js'; import type { Schema } from '../schema/index.js';
import { AssetsManager } from './assets.js'; import { AssetsManager } from './assets.js';
@@ -82,7 +82,7 @@ export class Job {
} }
}; };
docToSnapshot = (doc: Blocks): DocSnapshot | undefined => { docToSnapshot = (doc: Store): DocSnapshot | undefined => {
try { try {
this._slots.beforeExport.emit({ this._slots.beforeExport.emit({
type: 'page', type: 'page',
@@ -158,7 +158,7 @@ export class Job {
snapshotToBlock = async ( snapshotToBlock = async (
snapshot: BlockSnapshot, snapshot: BlockSnapshot,
doc: Blocks, doc: Store,
parent?: string, parent?: string,
index?: number index?: number
): Promise<BlockModel | undefined> => { ): Promise<BlockModel | undefined> => {
@@ -174,9 +174,7 @@ export class Job {
} }
}; };
snapshotToDoc = async ( snapshotToDoc = async (snapshot: DocSnapshot): Promise<Store | undefined> => {
snapshot: DocSnapshot
): Promise<Blocks | undefined> => {
try { try {
this._slots.beforeImport.emit({ this._slots.beforeImport.emit({
type: 'page', type: 'page',
@@ -228,7 +226,7 @@ export class Job {
snapshotToSlice = async ( snapshotToSlice = async (
snapshot: SliceSnapshot, snapshot: SliceSnapshot,
doc: Blocks, doc: Store,
parent?: string, parent?: string,
index?: number index?: number
): Promise<Slice | undefined> => { ): 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; const docMeta = doc.meta;
if (!docMeta) { if (!docMeta) {
@@ -472,7 +470,7 @@ export class Job {
private async _insertBlockTree( private async _insertBlockTree(
nodes: DraftBlockTreeNode[], nodes: DraftBlockTreeNode[],
doc: Blocks, doc: Store,
parentId?: string, parentId?: string,
startIndex?: number, startIndex?: number,
counter: number = 0 counter: number = 0
@@ -561,7 +559,7 @@ export class Job {
private async _snapshotToBlock( private async _snapshotToBlock(
snapshot: BlockSnapshot, snapshot: BlockSnapshot,
doc: Blocks, doc: Store,
parent?: string, parent?: string,
index?: number index?: number
): Promise<BlockModel | null> { ): Promise<BlockModel | null> {

View File

@@ -1,6 +1,6 @@
import type { Slot } from '@blocksuite/global/utils'; 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 { AssetsManager } from './assets.js';
import type { Slice } from './slice.js'; import type { Slice } from './slice.js';
import type { import type {
@@ -37,7 +37,7 @@ export type BeforeExportPayload =
type: 'block'; type: 'block';
} }
| { | {
page: Blocks; page: Store;
type: 'page'; type: 'page';
} }
| { | {
@@ -59,7 +59,7 @@ export type FinalPayload =
| { | {
snapshot: DocSnapshot; snapshot: DocSnapshot;
type: 'page'; type: 'page';
page: Blocks; page: Store;
} }
| { | {
snapshot: SliceSnapshot; snapshot: SliceSnapshot;

View File

@@ -1,4 +1,4 @@
import type { Blocks, DraftModel } from '../model/index.js'; import type { DraftModel, Store } from '../model/index.js';
type SliceData = { type SliceData = {
content: DraftModel[]; content: DraftModel[];
@@ -21,7 +21,7 @@ export class Slice {
constructor(readonly data: SliceData) {} constructor(readonly data: SliceData) {}
static fromModels(doc: Blocks, models: DraftModel[]) { static fromModels(doc: Store, models: DraftModel[]) {
return new Slice({ return new Slice({
content: models, content: models,
workspaceId: doc.workspace.id, workspaceId: doc.workspace.id,

View File

@@ -1,6 +1,6 @@
import { z } from 'zod'; 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'; import type { DocMeta, DocsPropertiesMeta } from '../model/workspace-meta.js';
export type BlockSnapshot = { export type BlockSnapshot = {
@@ -75,7 +75,7 @@ export interface BlobCRUD {
} }
export interface DocCRUD { export interface DocCRUD {
create: (id: string) => Blocks; create: (id: string) => Store;
get: (id: string) => Blocks | null; get: (id: string) => Store | null;
delete: (id: string) => void; delete: (id: string) => void;
} }

View File

@@ -73,7 +73,7 @@ export class DocsPanel extends WithDisposable(ShadowlessElement) {
?.generateDocUrl(doc.id); ?.generateDocUrl(doc.id);
if (url) history.pushState({}, '', url); if (url) history.pushState({}, '', url);
this.editor.doc = doc.getBlocks(); this.editor.doc = doc.getStore();
this.editor.doc.load(); this.editor.doc.load();
this.editor.doc.resetHistory(); this.editor.doc.resetHistory();
this.requestUpdate(); this.requestUpdate();
@@ -146,7 +146,7 @@ export class DocsPanel extends WithDisposable(ShadowlessElement) {
removeModeFromStorage(doc.id); removeModeFromStorage(doc.id);
// When delete the current doc, we need to set the editor doc to the first remaining doc // When delete the current doc, we need to set the editor doc to the first remaining doc
if (isDeleteCurrent) { if (isDeleteCurrent) {
this.editor.doc = this.docs[0].getBlocks(); this.editor.doc = this.docs[0].getStore();
} }
}; };
return html`<div class="doc-item" @click="${click}" style="${style}"> return html`<div class="doc-item" @click="${click}" style="${style}">

View File

@@ -15,7 +15,7 @@ export function getDocFromUrlParams(collection: Workspace, url: URL) {
if (!doc) { if (!doc) {
const blockCollection = collection.docs.values().next().value as Doc; const blockCollection = collection.docs.values().next().value as Doc;
assertExists(blockCollection, 'Need to create a doc first'); assertExists(blockCollection, 'Need to create a doc first');
doc = blockCollection.getBlocks(); doc = blockCollection.getStore();
} }
doc.load(); doc.load();

View File

@@ -5,7 +5,7 @@ import type {
GroupElementModel, GroupElementModel,
NoteBlockModel, NoteBlockModel,
} from '@blocksuite/blocks'; } from '@blocksuite/blocks';
import { type BlockModel, type Blocks } from '@blocksuite/store'; import type { BlockModel, Store } from '@blocksuite/store';
import { beforeEach, describe, expect, test } from 'vitest'; import { beforeEach, describe, expect, test } from 'vitest';
import * as Y from 'yjs'; import * as Y from 'yjs';
@@ -19,7 +19,7 @@ import { setupEditor } from '../utils/setup.js';
let service!: EdgelessRootBlockComponent['service']; let service!: EdgelessRootBlockComponent['service'];
const addNote = (doc: Blocks, props: Record<string, unknown> = {}) => { const addNote = (doc: Store, props: Record<string, unknown> = {}) => {
return _addNote(doc, { return _addNote(doc, {
index: service.layer.generateIndex(), index: service.layer.generateIndex(),
...props, ...props,

View File

@@ -3,11 +3,11 @@ import type {
PageRootBlockComponent, PageRootBlockComponent,
SurfaceBlockComponent, SurfaceBlockComponent,
} from '@blocksuite/blocks'; } from '@blocksuite/blocks';
import type { Blocks } from '@blocksuite/store'; import type { Store } from '@blocksuite/store';
import type { AffineEditorContainer } from '../../index.js'; import type { AffineEditorContainer } from '../../index.js';
export function getSurface(doc: Blocks, editor: AffineEditorContainer) { export function getSurface(doc: Store, editor: AffineEditorContainer) {
const surfaceModel = doc.getBlockByFlavour('affine:surface'); const surfaceModel = doc.getBlockByFlavour('affine:surface');
return editor.host!.view.getBlock( return editor.host!.view.getBlock(
@@ -16,17 +16,17 @@ export function getSurface(doc: Blocks, editor: AffineEditorContainer) {
} }
export function getDocRootBlock( export function getDocRootBlock(
doc: Blocks, doc: Store,
editor: AffineEditorContainer, editor: AffineEditorContainer,
mode: 'page' mode: 'page'
): PageRootBlockComponent; ): PageRootBlockComponent;
export function getDocRootBlock( export function getDocRootBlock(
doc: Blocks, doc: Store,
editor: AffineEditorContainer, editor: AffineEditorContainer,
mode: 'edgeless' mode: 'edgeless'
): EdgelessRootBlockComponent; ): EdgelessRootBlockComponent;
export function getDocRootBlock( export function getDocRootBlock(
doc: Blocks, doc: Store,
editor: AffineEditorContainer, editor: AffineEditorContainer,
_?: 'edgeless' | 'page' _?: 'edgeless' | 'page'
) { ) {
@@ -35,7 +35,7 @@ export function getDocRootBlock(
| PageRootBlockComponent; | PageRootBlockComponent;
} }
export function addNote(doc: Blocks, props: Record<string, any> = {}) { export function addNote(doc: Store, props: Record<string, any> = {}) {
const noteId = doc.addBlock( const noteId = doc.addBlock(
'affine:note', 'affine:note',
{ {

View File

@@ -1,5 +1,5 @@
import { effects as blocksEffects } from '@blocksuite/blocks/effects'; import { effects as blocksEffects } from '@blocksuite/blocks/effects';
import type { Blocks, Job } from '@blocksuite/store'; import type { Job, Store } from '@blocksuite/store';
import { effects } from '../../effects.js'; import { effects } from '../../effects.js';
@@ -59,7 +59,7 @@ async function createEditor(collection: TestWorkspace, mode: DocMode = 'page') {
const app = document.createElement('div'); const app = document.createElement('div');
const blockCollection = collection.docs.values().next().value; const blockCollection = collection.docs.values().next().value;
assertExists(blockCollection, 'Need to create a doc first'); assertExists(blockCollection, 'Need to create a doc first');
const doc = blockCollection.getBlocks(); const doc = blockCollection.getStore();
const editor = new AffineEditorContainer(); const editor = new AffineEditorContainer();
editor.doc = doc; editor.doc = doc;
editor.mode = mode; editor.mode = mode;
@@ -109,12 +109,12 @@ export function cleanup() {
declare global { declare global {
const editor: AffineEditorContainer; const editor: AffineEditorContainer;
const doc: Blocks; const doc: Store;
const collection: TestWorkspace; const collection: TestWorkspace;
const job: Job; const job: Job;
interface Window { interface Window {
editor: AffineEditorContainer; editor: AffineEditorContainer;
doc: Blocks; doc: Store;
job: Job; job: Job;
collection: TestWorkspace; collection: TestWorkspace;
} }

View File

@@ -1,7 +1,7 @@
import { BlockStdScope, ShadowlessElement } from '@blocksuite/block-std'; import { BlockStdScope, ShadowlessElement } from '@blocksuite/block-std';
import { EdgelessEditorBlockSpecs, ThemeProvider } from '@blocksuite/blocks'; import { EdgelessEditorBlockSpecs, ThemeProvider } from '@blocksuite/blocks';
import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils'; import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
import { type Blocks, Store } from '@blocksuite/store'; import type { Store } from '@blocksuite/store';
import { css, html, nothing, type TemplateResult } from 'lit'; import { css, html, nothing, type TemplateResult } from 'lit';
import { property, state } from 'lit/decorators.js'; import { property, state } from 'lit/decorators.js';
import { guard } from 'lit/directives/guard.js'; import { guard } from 'lit/directives/guard.js';
@@ -48,9 +48,8 @@ export class EdgelessEditor extends SignalWatcher(
this._disposables.add( this._disposables.add(
this.doc.slots.rootAdded.on(() => this.requestUpdate()) this.doc.slots.rootAdded.on(() => this.requestUpdate())
); );
const store = new Store({ blocks: this.doc });
this.std = new BlockStdScope({ this.std = new BlockStdScope({
store, store: this.doc,
extensions: this.specs, extensions: this.specs,
}); });
} }
@@ -78,16 +77,15 @@ export class EdgelessEditor extends SignalWatcher(
) { ) {
super.willUpdate(changedProperties); super.willUpdate(changedProperties);
if (changedProperties.has('doc')) { if (changedProperties.has('doc')) {
const store = new Store({ blocks: this.doc });
this.std = new BlockStdScope({ this.std = new BlockStdScope({
store, store: this.doc,
extensions: this.specs, extensions: this.specs,
}); });
} }
} }
@property({ attribute: false }) @property({ attribute: false })
accessor doc!: Blocks; accessor doc!: Store;
@property({ attribute: false }) @property({ attribute: false })
accessor editor!: TemplateResult; accessor editor!: TemplateResult;

View File

@@ -9,9 +9,8 @@ import {
import { SignalWatcher, Slot, WithDisposable } from '@blocksuite/global/utils'; import { SignalWatcher, Slot, WithDisposable } from '@blocksuite/global/utils';
import { import {
type BlockModel, type BlockModel,
type Blocks,
type ExtensionType, type ExtensionType,
Store, type Store,
} from '@blocksuite/store'; } from '@blocksuite/store';
import { computed, signal } from '@preact/signals-core'; import { computed, signal } from '@preact/signals-core';
import { css, html } from 'lit'; import { css, html } from 'lit';
@@ -89,7 +88,7 @@ export class AffineEditorContainer
} }
`; `;
private readonly _doc = signal<Blocks>(); private readonly _doc = signal<Store>();
private readonly _edgelessSpecs = signal<ExtensionType[]>( private readonly _edgelessSpecs = signal<ExtensionType[]>(
EdgelessEditorBlockSpecs EdgelessEditorBlockSpecs
@@ -105,13 +104,9 @@ export class AffineEditorContainer
: this._edgelessSpecs.value : this._edgelessSpecs.value
); );
private readonly _store = computed(() => {
return new Store({ blocks: this.doc });
});
private readonly _std = computed(() => { private readonly _std = computed(() => {
return new BlockStdScope({ return new BlockStdScope({
store: this._store.value, store: this.doc,
extensions: this._specs.value, extensions: this._specs.value,
}); });
}); });
@@ -128,10 +123,10 @@ export class AffineEditorContainer
}; };
get doc() { get doc() {
return this._doc.value as Blocks; return this._doc.value as Store;
} }
set doc(doc: Blocks) { set doc(doc: Store) {
this._doc.value = doc; this._doc.value = doc;
} }

View File

@@ -5,7 +5,7 @@ import {
} from '@blocksuite/block-std'; } from '@blocksuite/block-std';
import { PageEditorBlockSpecs, ThemeProvider } from '@blocksuite/blocks'; import { PageEditorBlockSpecs, ThemeProvider } from '@blocksuite/blocks';
import { noop, SignalWatcher, WithDisposable } from '@blocksuite/global/utils'; import { noop, SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
import { type Blocks, Store } from '@blocksuite/store'; import type { Store } from '@blocksuite/store';
import { css, html, nothing } from 'lit'; import { css, html, nothing } from 'lit';
import { property, state } from 'lit/decorators.js'; import { property, state } from 'lit/decorators.js';
import { guard } from 'lit/directives/guard.js'; import { guard } from 'lit/directives/guard.js';
@@ -59,9 +59,8 @@ export class PageEditor extends SignalWatcher(
this._disposables.add( this._disposables.add(
this.doc.slots.rootAdded.on(() => this.requestUpdate()) this.doc.slots.rootAdded.on(() => this.requestUpdate())
); );
const store = new Store({ blocks: this.doc });
this.std = new BlockStdScope({ this.std = new BlockStdScope({
store, store: this.doc,
extensions: this.specs, extensions: this.specs,
}); });
} }
@@ -94,16 +93,15 @@ export class PageEditor extends SignalWatcher(
) { ) {
super.willUpdate(changedProperties); super.willUpdate(changedProperties);
if (changedProperties.has('doc')) { if (changedProperties.has('doc')) {
const store = new Store({ blocks: this.doc });
this.std = new BlockStdScope({ this.std = new BlockStdScope({
store, store: this.doc,
extensions: this.specs, extensions: this.specs,
}); });
} }
} }
@property({ attribute: false }) @property({ attribute: false })
accessor doc!: Blocks; accessor doc!: Store;
@property({ type: Boolean }) @property({ type: Boolean })
accessor hasViewport = true; accessor hasViewport = true;

View File

@@ -2,7 +2,7 @@ import type { EditorHost } from '@blocksuite/block-std';
import { ShadowlessElement } from '@blocksuite/block-std'; import { ShadowlessElement } from '@blocksuite/block-std';
import type { RichText, RootBlockModel } from '@blocksuite/blocks'; import type { RichText, RootBlockModel } from '@blocksuite/blocks';
import { assertExists, WithDisposable } from '@blocksuite/global/utils'; import { assertExists, WithDisposable } from '@blocksuite/global/utils';
import type { Blocks } from '@blocksuite/store'; import type { Store } from '@blocksuite/store';
import { css, html } from 'lit'; import { css, html } from 'lit';
import { property, query, state } from 'lit/decorators.js'; import { property, query, state } from 'lit/decorators.js';
@@ -175,7 +175,7 @@ export class DocTitle extends WithDisposable(ShadowlessElement) {
private accessor _richTextElement!: RichText; private accessor _richTextElement!: RichText;
@property({ attribute: false }) @property({ attribute: false })
accessor doc!: Blocks; accessor doc!: Store;
} }
export function getDocTitleByEditorHost( export function getDocTitleByEditorHost(

View File

@@ -13,7 +13,7 @@ import {
SignalWatcher, SignalWatcher,
WithDisposable, WithDisposable,
} from '@blocksuite/global/utils'; } from '@blocksuite/global/utils';
import type { Blocks } from '@blocksuite/store'; import type { Store } from '@blocksuite/store';
import { css, html, nothing, type PropertyValues } from 'lit'; import { css, html, nothing, type PropertyValues } from 'lit';
import { property, query, state } from 'lit/decorators.js'; import { property, query, state } from 'lit/decorators.js';
import { keyed } from 'lit/directives/keyed.js'; import { keyed } from 'lit/directives/keyed.js';
@@ -326,7 +326,7 @@ export class FramePanelBody extends SignalWatcher(
} }
} }
private _setDocDisposables(doc: Blocks) { private _setDocDisposables(doc: Store) {
this._clearDocDisposables(); this._clearDocDisposables();
this._docDisposables = new DisposableGroup(); this._docDisposables = new DisposableGroup();
this._docDisposables.add( this._docDisposables.add(

View File

@@ -13,7 +13,7 @@ import {
SignalWatcher, SignalWatcher,
WithDisposable, WithDisposable,
} from '@blocksuite/global/utils'; } from '@blocksuite/global/utils';
import type { Blocks } from '@blocksuite/store'; import type { Store } from '@blocksuite/store';
import { effect, signal } from '@preact/signals-core'; import { effect, signal } from '@preact/signals-core';
import { css, html, LitElement, nothing, type PropertyValues } from 'lit'; import { css, html, LitElement, nothing, type PropertyValues } from 'lit';
import { property, query, state } from 'lit/decorators.js'; import { property, query, state } from 'lit/decorators.js';
@@ -698,7 +698,7 @@ export class OutlinePanelBody extends SignalWatcher(
private accessor _selected: string[] = []; private accessor _selected: string[] = [];
@property({ attribute: false }) @property({ attribute: false })
accessor doc!: Blocks; accessor doc!: Store;
@property({ attribute: false }) @property({ attribute: false })
accessor domHost!: Document | HTMLElement; accessor domHost!: Document | HTMLElement;

View File

@@ -7,7 +7,7 @@ import {
once, once,
} from '@blocksuite/blocks'; } from '@blocksuite/blocks';
import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils'; import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
import type { BlockModel, Blocks } from '@blocksuite/store'; import type { BlockModel, Store } from '@blocksuite/store';
import { baseTheme } from '@toeverything/theme'; import { baseTheme } from '@toeverything/theme';
import { css, html, LitElement, unsafeCSS } from 'lit'; import { css, html, LitElement, unsafeCSS } from 'lit';
import { property, query, state } from 'lit/decorators.js'; import { property, query, state } from 'lit/decorators.js';
@@ -393,7 +393,7 @@ export class OutlineNoteCard extends SignalWatcher(WithDisposable(LitElement)) {
accessor activeHeadingId: string | null = null; accessor activeHeadingId: string | null = null;
@property({ attribute: false }) @property({ attribute: false })
accessor doc!: Blocks; accessor doc!: Store;
@property({ attribute: false }) @property({ attribute: false })
accessor editorMode: 'page' | 'edgeless' = 'page'; accessor editorMode: 'page' | 'edgeless' = 'page';

View File

@@ -1,5 +1,5 @@
import { on, once } from '@blocksuite/blocks'; import { on, once } from '@blocksuite/blocks';
import type { Blocks } from '@blocksuite/store'; import type { Store } from '@blocksuite/store';
import type { OutlinePanelBody } from '../body/outline-panel-body.js'; import type { OutlinePanelBody } from '../body/outline-panel-body.js';
import type { OutlineNoteCard } from '../card/outline-card.js'; import type { OutlineNoteCard } from '../card/outline-card.js';
@@ -15,7 +15,7 @@ export function startDragging(options: {
document: Document; document: Document;
host: Document | HTMLElement; host: Document | HTMLElement;
container: OutlinePanelBody; container: OutlinePanelBody;
doc: Blocks; doc: Store;
}) { }) {
const { const {
document, document,

View File

@@ -5,7 +5,7 @@ import {
type ParagraphBlockModel, type ParagraphBlockModel,
type RootBlockModel, type RootBlockModel,
} from '@blocksuite/blocks'; } from '@blocksuite/blocks';
import type { BlockModel, Blocks } from '@blocksuite/store'; import type { BlockModel, Store } from '@blocksuite/store';
import { headingKeys } from '../config.js'; import { headingKeys } from '../config.js';
@@ -22,7 +22,7 @@ type OutlineNoteItem = {
}; };
export function getNotesFromDoc( export function getNotesFromDoc(
doc: Blocks, doc: Store,
modes: NoteDisplayMode[] modes: NoteDisplayMode[]
): OutlineNoteItem[] { ): OutlineNoteItem[] {
const rootModel = doc.root; const rootModel = doc.root;
@@ -74,7 +74,7 @@ export function getHeadingBlocksFromNote(
} }
export function getHeadingBlocksFromDoc( export function getHeadingBlocksFromDoc(
doc: Blocks, doc: Store,
modes: NoteDisplayMode[], modes: NoteDisplayMode[],
ignoreEmpty = false ignoreEmpty = false
) { ) {

View File

@@ -225,7 +225,7 @@ test.describe('Embed synced doc', () => {
}; };
const doc2Collection = getDocCollection(); const doc2Collection = getDocCollection();
const doc2 = doc2Collection!.getBlocks(); const doc2 = doc2Collection!.getStore();
const [noteBlock] = doc2!.getBlocksByFlavour('affine:note'); const [noteBlock] = doc2!.getBlocksByFlavour('affine:note');
const noteId = noteBlock.id; const noteId = noteBlock.id;

View File

@@ -194,7 +194,7 @@ async function initEmptyEditor({
} }
if (noInit) { if (noInit) {
const firstDoc = collection.docs.values().next().value?.getBlocks() as const firstDoc = collection.docs.values().next().value?.getStore() as
| ReturnType<typeof collection.createDoc> | ReturnType<typeof collection.createDoc>
| undefined; | undefined;
if (firstDoc) { if (firstDoc) {

View File

@@ -5,7 +5,7 @@ import {
type ParagraphProps, type ParagraphProps,
type RootBlockProps, type RootBlockProps,
} from '@blocksuite/affine/blocks'; } from '@blocksuite/affine/blocks';
import { type Blocks, Text } from '@blocksuite/affine/store'; import { type Store, Text } from '@blocksuite/affine/store';
export interface DocProps { export interface DocProps {
page?: Partial<RootBlockProps>; page?: Partial<RootBlockProps>;
@@ -14,7 +14,7 @@ export interface DocProps {
paragraph?: Partial<ParagraphProps>; paragraph?: Partial<ParagraphProps>;
} }
export function initEmptyDoc(doc: Blocks, title?: string) { export function initEmptyDoc(doc: Store, title?: string) {
doc.load(() => { doc.load(() => {
initDocFromProps(doc, { initDocFromProps(doc, {
page: { page: {
@@ -24,7 +24,7 @@ export function initEmptyDoc(doc: Blocks, title?: string) {
}); });
} }
export function initDocFromProps(doc: Blocks, props?: DocProps) { export function initDocFromProps(doc: Store, props?: DocProps) {
doc.load(() => { doc.load(() => {
const pageBlockId = doc.addBlock( const pageBlockId = doc.addBlock(
'affine:page', 'affine:page',

View File

@@ -18,12 +18,11 @@ import {
} from '@blocksuite/affine/blocks'; } from '@blocksuite/affine/blocks';
import { Container, type ServiceProvider } from '@blocksuite/affine/global/di'; import { Container, type ServiceProvider } from '@blocksuite/affine/global/di';
import { WithDisposable } from '@blocksuite/affine/global/utils'; import { WithDisposable } from '@blocksuite/affine/global/utils';
import { import type {
type Blocks, ExtensionType,
type ExtensionType, JobMiddleware,
type JobMiddleware, Query,
type Query, Schema,
type Schema,
Store, Store,
} from '@blocksuite/affine/store'; } from '@blocksuite/affine/store';
import { css, html, nothing, type PropertyValues } from 'lit'; import { css, html, nothing, type PropertyValues } from 'lit';
@@ -174,7 +173,7 @@ export class TextRenderer extends WithDisposable(ShadowlessElement) {
} }
}; };
private _doc: Blocks | null = null; private _doc: Store | null = null;
private readonly _query: Query = { private readonly _query: Query = {
mode: 'strict', mode: 'strict',
@@ -220,7 +219,7 @@ export class TextRenderer extends WithDisposable(ShadowlessElement) {
) )
.then(doc => { .then(doc => {
this.disposeDoc(); this.disposeDoc();
this._doc = doc.doc.getBlocks({ this._doc = doc.doc.getStore({
query: this._query, query: this._query,
}); });
this.disposables.add(() => { this.disposables.add(() => {
@@ -287,7 +286,7 @@ export class TextRenderer extends WithDisposable(ShadowlessElement) {
this._doc, this._doc,
html`<div class="ai-answer-text-editor affine-page-viewport"> html`<div class="ai-answer-text-editor affine-page-viewport">
${new BlockStdScope({ ${new BlockStdScope({
store: new Store({ blocks: this._doc }), store: this._doc,
extensions: this.options.extensions ?? CustomPageEditorBlockSpecs, extensions: this.options.extensions ?? CustomPageEditorBlockSpecs,
}).render()} }).render()}
</div>` </div>`

View File

@@ -17,13 +17,13 @@ import type { ServiceProvider } from '@blocksuite/affine/global/di';
import { assertExists } from '@blocksuite/affine/global/utils'; import { assertExists } from '@blocksuite/affine/global/utils';
import type { import type {
BlockModel, BlockModel,
Blocks,
BlockSnapshot, BlockSnapshot,
DraftModel, DraftModel,
JobMiddleware, JobMiddleware,
Schema, Schema,
Slice, Slice,
SliceSnapshot, SliceSnapshot,
Store,
} from '@blocksuite/affine/store'; } from '@blocksuite/affine/store';
import { Job } from '@blocksuite/affine/store'; import { Job } from '@blocksuite/affine/store';
@@ -166,7 +166,7 @@ export const markdownToSnapshot = async (
export async function insertFromMarkdown( export async function insertFromMarkdown(
host: EditorHost, host: EditorHost,
markdown: string, markdown: string,
doc: Blocks, doc: Store,
parent?: string, parent?: string,
index?: number index?: number
) { ) {
@@ -235,5 +235,5 @@ export async function markDownToDoc(
if (!doc) { if (!doc) {
console.error('Failed to convert markdown to doc'); console.error('Failed to convert markdown to doc');
} }
return doc as Blocks; return doc as Store;
} }

View File

@@ -24,7 +24,7 @@ import {
getCommonBoundWithRotation, getCommonBoundWithRotation,
type SerializedXYWH, type SerializedXYWH,
} from '@blocksuite/affine/global/utils'; } from '@blocksuite/affine/global/utils';
import type { Blocks } from '@blocksuite/affine/store'; import type { Store } from '@blocksuite/affine/store';
import type { TemplateResult } from 'lit'; import type { TemplateResult } from 'lit';
import type { ChatMessage } from '../../../blocks'; import type { ChatMessage } from '../../../blocks';
@@ -101,7 +101,7 @@ export function constructUserInfoWithMessages(
} }
export async function constructRootChatBlockMessages( export async function constructRootChatBlockMessages(
doc: Blocks, doc: Store,
forkSessionId: string forkSessionId: string
) { ) {
// Convert chat messages to AI chat block messages // Convert chat messages to AI chat block messages
@@ -152,7 +152,7 @@ function addAIChatBlock(
const { doc } = host; const { doc } = host;
const surfaceBlock = doc const surfaceBlock = doc
.getBlocks() .getStore()
.find(block => block.flavour === 'affine:surface'); .find(block => block.flavour === 'affine:surface');
if (!surfaceBlock) { if (!surfaceBlock) {
return; return;
@@ -462,7 +462,7 @@ const CREATE_AS_LINKED_DOC = {
const { doc } = host; const { doc } = host;
const surfaceBlock = doc const surfaceBlock = doc
.getBlocks() .getStore()
.find(block => block.flavour === 'affine:surface'); .find(block => block.flavour === 'affine:surface');
if (!surfaceBlock) { if (!surfaceBlock) {
return false; return false;

View File

@@ -236,7 +236,7 @@ function getEdgelessContentBound(host: EditorHost) {
const elements = ( const elements = (
host.doc host.doc
.getBlocks() .getStore()
.filter( .filter(
model => model =>
model instanceof GfxBlockElementModel && model instanceof GfxBlockElementModel &&

View File

@@ -5,7 +5,7 @@ import type { EditorHost } from '@blocksuite/affine/block-std';
import { ShadowlessElement } from '@blocksuite/affine/block-std'; import { ShadowlessElement } from '@blocksuite/affine/block-std';
import { NotificationProvider } from '@blocksuite/affine/blocks'; import { NotificationProvider } from '@blocksuite/affine/blocks';
import { debounce, WithDisposable } from '@blocksuite/affine/global/utils'; import { debounce, WithDisposable } from '@blocksuite/affine/global/utils';
import type { Blocks } from '@blocksuite/affine/store'; import type { Store } from '@blocksuite/affine/store';
import { css, html, type PropertyValues } from 'lit'; import { css, html, type PropertyValues } from 'lit';
import { property, state } from 'lit/decorators.js'; import { property, state } from 'lit/decorators.js';
import { createRef, type Ref, ref } from 'lit/directives/ref.js'; import { createRef, type Ref, ref } from 'lit/directives/ref.js';
@@ -141,7 +141,7 @@ export class ChatPanel extends WithDisposable(ShadowlessElement) {
accessor host!: EditorHost; accessor host!: EditorHost;
@property({ attribute: false }) @property({ attribute: false })
accessor doc!: Blocks; accessor doc!: Store;
@state() @state()
accessor isLoading = false; accessor isLoading = false;

View File

@@ -6,8 +6,7 @@ import {
} from '@blocksuite/affine/blocks'; } from '@blocksuite/affine/blocks';
import { AffineSchemas } from '@blocksuite/affine/blocks/schemas'; import { AffineSchemas } from '@blocksuite/affine/blocks/schemas';
import { WithDisposable } from '@blocksuite/affine/global/utils'; import { WithDisposable } from '@blocksuite/affine/global/utils';
import type { Blocks } from '@blocksuite/affine/store'; import { Schema, type Store } from '@blocksuite/affine/store';
import { Schema, Store } from '@blocksuite/affine/store';
import { css, html, LitElement, nothing } from 'lit'; import { css, html, LitElement, nothing } from 'lit';
import { property, query } from 'lit/decorators.js'; import { property, query } from 'lit/decorators.js';
import { createRef, type Ref, ref } from 'lit/directives/ref.js'; import { createRef, type Ref, ref } from 'lit/directives/ref.js';
@@ -53,7 +52,7 @@ export class AISlidesRenderer extends WithDisposable(LitElement) {
private readonly _editorContainer: Ref<HTMLDivElement> = private readonly _editorContainer: Ref<HTMLDivElement> =
createRef<HTMLDivElement>(); createRef<HTMLDivElement>();
private _doc!: Blocks; private _doc!: Store;
private _docCollection: WorkspaceImpl | null = null; private _docCollection: WorkspaceImpl | null = null;
@@ -208,7 +207,7 @@ export class AISlidesRenderer extends WithDisposable(LitElement) {
${ref(this._editorContainer)} ${ref(this._editorContainer)}
> >
${new BlockStdScope({ ${new BlockStdScope({
store: new Store({ blocks: this._doc }), store: this._doc,
extensions: extensions:
SpecProvider.getInstance().getSpec('edgeless:preview').value, SpecProvider.getInstance().getSpec('edgeless:preview').value,
}).render()} }).render()}

View File

@@ -12,7 +12,7 @@ import {
} from '@blocksuite/affine/blocks'; } from '@blocksuite/affine/blocks';
import type { ServiceProvider } from '@blocksuite/affine/global/di'; import type { ServiceProvider } from '@blocksuite/affine/global/di';
import { WithDisposable } from '@blocksuite/affine/global/utils'; import { WithDisposable } from '@blocksuite/affine/global/utils';
import { type Blocks, Job, Schema, Store } from '@blocksuite/affine/store'; import { Job, Schema, type Store } from '@blocksuite/affine/store';
import { css, html, LitElement, nothing } from 'lit'; import { css, html, LitElement, nothing } from 'lit';
import { property, query } from 'lit/decorators.js'; import { property, query } from 'lit/decorators.js';
import { repeat } from 'lit/directives/repeat.js'; import { repeat } from 'lit/directives/repeat.js';
@@ -79,7 +79,7 @@ export class MiniMindmapPreview extends WithDisposable(LitElement) {
} }
`; `;
doc?: Blocks; doc?: Store;
mindmapId?: string; mindmapId?: string;
@@ -129,7 +129,7 @@ export class MiniMindmapPreview extends WithDisposable(LitElement) {
this.requestUpdate(); this.requestUpdate();
} }
private _toMindmapNode(answer: string, doc: Blocks) { private _toMindmapNode(answer: string, doc: Store) {
return markdownToMindmap(answer, doc, this.host.std.provider); return markdownToMindmap(answer, doc, this.host.std.provider);
} }
@@ -175,7 +175,7 @@ export class MiniMindmapPreview extends WithDisposable(LitElement) {
})} })}
> >
${new BlockStdScope({ ${new BlockStdScope({
store: new Store({ blocks: this.doc }), store: this.doc,
extensions: MiniMindmapSpecs, extensions: MiniMindmapSpecs,
}).render()} }).render()}
</div> </div>
@@ -232,7 +232,7 @@ type Node = {
export const markdownToMindmap = ( export const markdownToMindmap = (
answer: string, answer: string,
doc: Blocks, doc: Store,
provider: ServiceProvider provider: ServiceProvider
) => { ) => {
let result: Node | null = null; let result: Node | null = null;

View File

@@ -155,7 +155,7 @@ export class AIChatBlockPeekView extends LitElement {
const { doc } = this.host; const { doc } = this.host;
// create a new AI chat block // create a new AI chat block
const surfaceBlock = doc const surfaceBlock = doc
.getBlocks() .getStore()
.find(block => block.flavour === 'affine:surface'); .find(block => block.flavour === 'affine:surface');
if (!surfaceBlock) { if (!surfaceBlock) {
return; return;

View File

@@ -11,7 +11,7 @@ import { WorkspaceService } from '@affine/core/modules/workspace';
import { i18nTime, Trans, useI18n } from '@affine/i18n'; import { i18nTime, Trans, useI18n } from '@affine/i18n';
import { track } from '@affine/track'; import { track } from '@affine/track';
import type { DocMode } from '@blocksuite/affine/blocks'; import type { DocMode } from '@blocksuite/affine/blocks';
import type { Blocks, Workspace } from '@blocksuite/affine/store'; import type { Store, Workspace } from '@blocksuite/affine/store';
import { CloseIcon, ToggleRightIcon } from '@blocksuite/icons/rc'; import { CloseIcon, ToggleRightIcon } from '@blocksuite/icons/rc';
import * as Collapsible from '@radix-ui/react-collapsible'; import * as Collapsible from '@radix-ui/react-collapsible';
import type { DialogContentProps } from '@radix-ui/react-dialog'; import type { DialogContentProps } from '@radix-ui/react-dialog';
@@ -87,7 +87,7 @@ const ModalContainer = ({
interface HistoryEditorPreviewProps { interface HistoryEditorPreviewProps {
ts?: string; ts?: string;
historyList: HistoryList; historyList: HistoryList;
snapshotPage?: Blocks; snapshotPage?: Store;
mode: DocMode; mode: DocMode;
onModeChange: (mode: DocMode) => void; onModeChange: (mode: DocMode) => void;
title: string; title: string;

View File

@@ -1,14 +1,14 @@
import { useEnableCloud } from '@affine/core/components/hooks/affine/use-enable-cloud'; import { useEnableCloud } from '@affine/core/components/hooks/affine/use-enable-cloud';
import type { Workspace } from '@affine/core/modules/workspace'; import type { Workspace } from '@affine/core/modules/workspace';
import { track } from '@affine/track'; import { track } from '@affine/track';
import type { Blocks } from '@blocksuite/affine/store'; import type { Store } from '@blocksuite/affine/store';
import { useCallback } from 'react'; import { useCallback } from 'react';
import { ShareMenu } from './share-menu'; import { ShareMenu } from './share-menu';
type SharePageModalProps = { type SharePageModalProps = {
workspace: Workspace; workspace: Workspace;
page: Blocks; page: Store;
}; };
export const SharePageButton = ({ workspace, page }: SharePageModalProps) => { export const SharePageButton = ({ workspace, page }: SharePageModalProps) => {

View File

@@ -4,7 +4,7 @@ import { Menu } from '@affine/component/ui/menu';
import { ShareInfoService } from '@affine/core/modules/share-doc'; import { ShareInfoService } from '@affine/core/modules/share-doc';
import type { WorkspaceMetadata } from '@affine/core/modules/workspace'; import type { WorkspaceMetadata } from '@affine/core/modules/workspace';
import { useI18n } from '@affine/i18n'; import { useI18n } from '@affine/i18n';
import type { Blocks } from '@blocksuite/affine/store'; import type { Store } from '@blocksuite/affine/store';
import { LockIcon, PublishIcon } from '@blocksuite/icons/rc'; import { LockIcon, PublishIcon } from '@blocksuite/icons/rc';
import { useLiveData, useService } from '@toeverything/infra'; import { useLiveData, useService } from '@toeverything/infra';
import { forwardRef, type PropsWithChildren, type Ref, useEffect } from 'react'; import { forwardRef, type PropsWithChildren, type Ref, useEffect } from 'react';
@@ -15,7 +15,7 @@ import { SharePage } from './share-page';
export interface ShareMenuProps extends PropsWithChildren { export interface ShareMenuProps extends PropsWithChildren {
workspaceMetadata: WorkspaceMetadata; workspaceMetadata: WorkspaceMetadata;
currentPage: Blocks; currentPage: Store;
onEnableAffineCloud: () => void; onEnableAffineCloud: () => void;
onOpenShareModal?: (open: boolean) => void; onOpenShareModal?: (open: boolean) => void;
} }

View File

@@ -10,7 +10,7 @@ import type {
EdgelessEditor, EdgelessEditor,
PageEditor, PageEditor,
} from '@blocksuite/affine/presets'; } from '@blocksuite/affine/presets';
import { type BlockModel, type Blocks } from '@blocksuite/affine/store'; import { type BlockModel, type Store } from '@blocksuite/affine/store';
import clsx from 'clsx'; import clsx from 'clsx';
import type React from 'react'; import type React from 'react';
import { import {
@@ -27,7 +27,7 @@ import { BlocksuiteDocEditor, BlocksuiteEdgelessEditor } from './lit-adaper';
import * as styles from './styles.css'; import * as styles from './styles.css';
interface BlocksuiteEditorContainerProps { interface BlocksuiteEditorContainerProps {
page: Blocks; page: Store;
mode: DocMode; mode: DocMode;
shared?: boolean; shared?: boolean;
className?: string; className?: string;
@@ -191,7 +191,7 @@ export const BlocksuiteEditorContainer = forwardRef<
}); });
// copy from '@blocksuite/affine-shared/utils' // copy from '@blocksuite/affine-shared/utils'
export function getLastNoteBlock(doc: Blocks) { export function getLastNoteBlock(doc: Store) {
let note: NoteBlockModel | null = null; let note: NoteBlockModel | null = null;
if (!doc.root) return null; if (!doc.root) return null;
const { children } = doc.root; const { children } = doc.root;

View File

@@ -11,7 +11,7 @@ import {
} from '@blocksuite/affine/blocks'; } from '@blocksuite/affine/blocks';
import { DisposableGroup } from '@blocksuite/affine/global/utils'; import { DisposableGroup } from '@blocksuite/affine/global/utils';
import type { AffineEditorContainer } from '@blocksuite/affine/presets'; import type { AffineEditorContainer } from '@blocksuite/affine/presets';
import type { Blocks } from '@blocksuite/affine/store'; import type { Store } from '@blocksuite/affine/store';
import type { CSSProperties } from 'react'; import type { CSSProperties } from 'react';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
@@ -20,7 +20,7 @@ import { BlocksuiteEditorContainer } from './blocksuite-editor-container';
import { NoPageRootError } from './no-page-error'; import { NoPageRootError } from './no-page-error';
export type EditorProps = { export type EditorProps = {
page: Blocks; page: Store;
mode: DocMode; mode: DocMode;
shared?: boolean; shared?: boolean;
defaultOpenProperty?: DefaultOpenProperty; defaultOpenProperty?: DefaultOpenProperty;

View File

@@ -1,12 +1,12 @@
import { JournalService } from '@affine/core/modules/journal'; import { JournalService } from '@affine/core/modules/journal';
import { i18nTime, useI18n } from '@affine/i18n'; import { i18nTime, useI18n } from '@affine/i18n';
import type { Blocks } from '@blocksuite/affine/store'; import type { Store } from '@blocksuite/affine/store';
import { useLiveData, useService } from '@toeverything/infra'; import { useLiveData, useService } from '@toeverything/infra';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import * as styles from './styles.css'; import * as styles from './styles.css';
export const BlocksuiteEditorJournalDocTitle = ({ page }: { page: Blocks }) => { export const BlocksuiteEditorJournalDocTitle = ({ page }: { page: Store }) => {
const journalService = useService(JournalService); const journalService = useService(JournalService);
const journalDateStr = useLiveData(journalService.journalDate$(page.id)); const journalDateStr = useLiveData(journalService.journalDate$(page.id));
const journalDate = journalDateStr ? dayjs(journalDateStr) : null; const journalDate = journalDateStr ? dayjs(journalDateStr) : null;

View File

@@ -23,7 +23,7 @@ import {
EdgelessEditor, EdgelessEditor,
PageEditor, PageEditor,
} from '@blocksuite/affine/presets'; } from '@blocksuite/affine/presets';
import type { Blocks } from '@blocksuite/affine/store'; import type { Store } from '@blocksuite/affine/store';
import { import {
useFramework, useFramework,
useLiveData, useLiveData,
@@ -86,7 +86,7 @@ const adapted = {
}; };
interface BlocksuiteEditorProps { interface BlocksuiteEditorProps {
page: Blocks; page: Store;
shared?: boolean; shared?: boolean;
defaultOpenProperty?: DefaultOpenProperty; defaultOpenProperty?: DefaultOpenProperty;
} }

View File

@@ -1,11 +1,11 @@
import type { Blocks } from '@blocksuite/affine/store'; import type { Store } from '@blocksuite/affine/store';
import type { Doc as YDoc, Map as YMap } from 'yjs'; import type { Doc as YDoc, Map as YMap } from 'yjs';
/** /**
* TODO(@eyhn): Define error to unexpected state together in the future. * TODO(@eyhn): Define error to unexpected state together in the future.
*/ */
export class NoPageRootError extends Error { export class NoPageRootError extends Error {
constructor(public page: Blocks) { constructor(public page: Store) {
super('Page root not found when render editor!'); super('Page root not found when render editor!');
// Log info to let sentry collect more message // Log info to let sentry collect more message

View File

@@ -2,13 +2,13 @@ import type { WeekDatePickerHandle } from '@affine/component';
import { WeekDatePicker } from '@affine/component'; import { WeekDatePicker } from '@affine/component';
import { useJournalRouteHelper } from '@affine/core/components/hooks/use-journal'; import { useJournalRouteHelper } from '@affine/core/components/hooks/use-journal';
import { JournalService } from '@affine/core/modules/journal'; import { JournalService } from '@affine/core/modules/journal';
import type { Blocks } from '@blocksuite/affine/store'; import type { Store } from '@blocksuite/affine/store';
import { useLiveData, useService } from '@toeverything/infra'; import { useLiveData, useService } from '@toeverything/infra';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { useEffect, useRef, useState } from 'react'; import { useEffect, useRef, useState } from 'react';
export interface JournalWeekDatePickerProps { export interface JournalWeekDatePickerProps {
page: Blocks; page: Store;
} }
const weekStyle = { maxWidth: 800, width: '100%' }; const weekStyle = { maxWidth: 800, width: '100%' };

View File

@@ -22,7 +22,7 @@ import { ViewService } from '@affine/core/modules/workbench/services/view';
import { WorkspaceService } from '@affine/core/modules/workspace'; import { WorkspaceService } from '@affine/core/modules/workspace';
import { useI18n } from '@affine/i18n'; import { useI18n } from '@affine/i18n';
import { track } from '@affine/track'; import { track } from '@affine/track';
import type { Blocks } from '@blocksuite/affine/store'; import type { Store } from '@blocksuite/affine/store';
import { import {
DuplicateIcon, DuplicateIcon,
EdgelessIcon, EdgelessIcon,
@@ -52,7 +52,7 @@ import { HistoryTipsModal } from './history-tips-modal';
type PageMenuProps = { type PageMenuProps = {
rename?: () => void; rename?: () => void;
page: Blocks; page: Store;
isJournal?: boolean; isJournal?: boolean;
containerWidth: number; containerWidth: number;
}; };

Some files were not shown because too many files have changed in this diff Show More