mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-07 01:09:54 +08:00
feat(editor): add editor store (#9584)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { BlockStdScope, ShadowlessElement } from '@blocksuite/block-std';
|
||||
import { EdgelessEditorBlockSpecs, ThemeProvider } from '@blocksuite/blocks';
|
||||
import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
|
||||
import type { Blocks } from '@blocksuite/store';
|
||||
import { type Blocks, Store } from '@blocksuite/store';
|
||||
import { css, html, nothing, type TemplateResult } from 'lit';
|
||||
import { property, state } from 'lit/decorators.js';
|
||||
import { guard } from 'lit/directives/guard.js';
|
||||
@@ -48,8 +48,9 @@ export class EdgelessEditor extends SignalWatcher(
|
||||
this._disposables.add(
|
||||
this.doc.slots.rootAdded.on(() => this.requestUpdate())
|
||||
);
|
||||
const store = new Store({ blocks: this.doc });
|
||||
this.std = new BlockStdScope({
|
||||
doc: this.doc,
|
||||
store,
|
||||
extensions: this.specs,
|
||||
});
|
||||
}
|
||||
@@ -77,8 +78,9 @@ export class EdgelessEditor extends SignalWatcher(
|
||||
) {
|
||||
super.willUpdate(changedProperties);
|
||||
if (changedProperties.has('doc')) {
|
||||
const store = new Store({ blocks: this.doc });
|
||||
this.std = new BlockStdScope({
|
||||
doc: this.doc,
|
||||
store,
|
||||
extensions: this.specs,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,7 +7,12 @@ import {
|
||||
ThemeProvider,
|
||||
} from '@blocksuite/blocks';
|
||||
import { SignalWatcher, Slot, WithDisposable } from '@blocksuite/global/utils';
|
||||
import type { BlockModel, Blocks, ExtensionType } from '@blocksuite/store';
|
||||
import {
|
||||
type BlockModel,
|
||||
type Blocks,
|
||||
type ExtensionType,
|
||||
Store,
|
||||
} from '@blocksuite/store';
|
||||
import { computed, signal } from '@preact/signals-core';
|
||||
import { css, html } from 'lit';
|
||||
import { property } from 'lit/decorators.js';
|
||||
@@ -100,9 +105,13 @@ export class AffineEditorContainer
|
||||
: this._edgelessSpecs.value
|
||||
);
|
||||
|
||||
private readonly _store = computed(() => {
|
||||
return new Store({ blocks: this.doc });
|
||||
});
|
||||
|
||||
private readonly _std = computed(() => {
|
||||
return new BlockStdScope({
|
||||
doc: this.doc,
|
||||
store: this._store.value,
|
||||
extensions: this._specs.value,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
} from '@blocksuite/block-std';
|
||||
import { PageEditorBlockSpecs, ThemeProvider } from '@blocksuite/blocks';
|
||||
import { noop, SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
|
||||
import type { Blocks } from '@blocksuite/store';
|
||||
import { type Blocks, Store } from '@blocksuite/store';
|
||||
import { css, html, nothing } from 'lit';
|
||||
import { property, state } from 'lit/decorators.js';
|
||||
import { guard } from 'lit/directives/guard.js';
|
||||
@@ -59,8 +59,9 @@ export class PageEditor extends SignalWatcher(
|
||||
this._disposables.add(
|
||||
this.doc.slots.rootAdded.on(() => this.requestUpdate())
|
||||
);
|
||||
const store = new Store({ blocks: this.doc });
|
||||
this.std = new BlockStdScope({
|
||||
doc: this.doc,
|
||||
store,
|
||||
extensions: this.specs,
|
||||
});
|
||||
}
|
||||
@@ -93,8 +94,9 @@ export class PageEditor extends SignalWatcher(
|
||||
) {
|
||||
super.willUpdate(changedProperties);
|
||||
if (changedProperties.has('doc')) {
|
||||
const store = new Store({ blocks: this.doc });
|
||||
this.std = new BlockStdScope({
|
||||
doc: this.doc,
|
||||
store,
|
||||
extensions: this.specs,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user