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

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

View File

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

View File

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

View File

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

View File

@@ -75,7 +75,7 @@ export class BlockStdScope {
}
get doc() {
return this.store.blocks;
return this.store;
}
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 { SurfaceBlockModel } from '../gfx/model/surface/surface-model.js';
export function onSurfaceAdded(
doc: Blocks,
doc: Store,
callback: (model: SurfaceBlockModel | null) => void
) {
let found = false;

View File

@@ -1,5 +1,5 @@
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 { Layer } from '../gfx/layer.js';
@@ -82,7 +82,7 @@ export function isInRange(edges: [GfxModel, GfxModel], target: GfxModel) {
}
export function renderableInEdgeless(
doc: Blocks,
doc: Store,
surface: SurfaceBlockModel,
block: GfxBlockElementModel
) {

View File

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

View File

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

View File

@@ -4,7 +4,7 @@ import {
handleError,
} from '@blocksuite/global/exceptions';
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 { css, LitElement, nothing, type TemplateResult } from 'lit';
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 { ShadowlessElement } from './shadowless-element.js';
export const docContext = createContext<Blocks>('doc');
export const docContext = createContext<Store>('doc');
export const stdContext = createContext<BlockStdScope>('std');
@requiredProperties({
doc: PropTypes.instanceOf(Blocks),
doc: PropTypes.instanceOf(Store),
std: PropTypes.object,
})
export class EditorHost extends SignalWatcher(
@@ -189,7 +189,7 @@ export class EditorHost extends SignalWatcher(
@provide({ context: docContext })
@property({ attribute: false })
accessor doc!: Blocks;
accessor doc!: Store;
@provide({ context: stdContext })
@property({ attribute: false })

View File

@@ -1,5 +1,5 @@
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 { LitElement } from 'lit';
@@ -94,7 +94,7 @@ export class WidgetComponent<
}
@consume({ context: docContext })
private accessor _doc!: Blocks;
private accessor _doc!: Store;
@consume({ context: modelContext })
private accessor _model!: Model;