mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
feat(editor): add editor store (#9584)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
|
||||
import type { Blocks, ExtensionType } from '@blocksuite/store';
|
||||
import { type Blocks, type ExtensionType, Store } from '@blocksuite/store';
|
||||
import { html } from 'lit';
|
||||
import { customElement, property } from 'lit/decorators.js';
|
||||
|
||||
@@ -18,8 +18,9 @@ export class TestEditorContainer extends SignalWatcher(
|
||||
|
||||
override connectedCallback() {
|
||||
super.connectedCallback();
|
||||
const store = new Store({ blocks: this.doc });
|
||||
this._std = new BlockStdScope({
|
||||
doc: this.doc,
|
||||
store,
|
||||
extensions: this.specs,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import type { ServiceProvider } from '@blocksuite/global/di';
|
||||
import { Container } from '@blocksuite/global/di';
|
||||
import { Container, type ServiceProvider } from '@blocksuite/global/di';
|
||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||
import {
|
||||
type Blocks,
|
||||
type ExtensionType,
|
||||
Job,
|
||||
type JobMiddleware,
|
||||
type Store,
|
||||
} from '@blocksuite/store';
|
||||
|
||||
import { Clipboard } from '../clipboard/index.js';
|
||||
@@ -36,7 +35,7 @@ import { EditorHost } from '../view/element/index.js';
|
||||
import { ViewStore } from '../view/view-store.js';
|
||||
|
||||
export interface BlockStdOptions {
|
||||
doc: Blocks;
|
||||
store: Store;
|
||||
extensions: ExtensionType[];
|
||||
}
|
||||
|
||||
@@ -65,7 +64,7 @@ export class BlockStdScope {
|
||||
|
||||
readonly container: Container;
|
||||
|
||||
readonly doc: Blocks;
|
||||
readonly store: Store;
|
||||
|
||||
readonly provider: ServiceProvider;
|
||||
|
||||
@@ -75,6 +74,10 @@ export class BlockStdScope {
|
||||
return this.provider.getAll(LifeCycleWatcherIdentifier);
|
||||
}
|
||||
|
||||
get doc() {
|
||||
return this.store.blocks;
|
||||
}
|
||||
|
||||
get clipboard() {
|
||||
return this.get(Clipboard);
|
||||
}
|
||||
@@ -122,7 +125,7 @@ export class BlockStdScope {
|
||||
'Host is not ready to use, the `render` method should be called first'
|
||||
);
|
||||
};
|
||||
this.doc = options.doc;
|
||||
this.store = options.store;
|
||||
this.userExtensions = options.extensions;
|
||||
this.container = new Container();
|
||||
this.container.addImpl(StdIdentifier, () => this);
|
||||
@@ -137,7 +140,7 @@ export class BlockStdScope {
|
||||
ext.setup(container);
|
||||
});
|
||||
|
||||
this.provider = this.container.provider();
|
||||
this.provider = this.container.provider(undefined, this.store.provider);
|
||||
|
||||
this._lifeCycleWatchers.forEach(watcher => {
|
||||
watcher.created.call(watcher);
|
||||
|
||||
Reference in New Issue
Block a user