feat(editor): add editor store (#9584)

This commit is contained in:
Saul-Mirone
2025-01-08 07:47:43 +00:00
parent 0554df6bc2
commit fe727412be
25 changed files with 203 additions and 67 deletions

View File

@@ -24,6 +24,7 @@ import {
type JobMiddleware,
type Query,
type Schema,
Store,
} from '@blocksuite/affine/store';
import { css, html, nothing, type PropertyValues } from 'lit';
import { property, query } from 'lit/decorators.js';
@@ -286,7 +287,7 @@ export class TextRenderer extends WithDisposable(ShadowlessElement) {
this._doc,
html`<div class="ai-answer-text-editor affine-page-viewport">
${new BlockStdScope({
doc: this._doc,
store: new Store({ blocks: this._doc }),
extensions: this.options.extensions ?? CustomPageEditorBlockSpecs,
}).render()}
</div>`

View File

@@ -7,7 +7,7 @@ import {
import { AffineSchemas } from '@blocksuite/affine/blocks/schemas';
import { WithDisposable } from '@blocksuite/affine/global/utils';
import type { Blocks } from '@blocksuite/affine/store';
import { Schema } from '@blocksuite/affine/store';
import { Schema, Store } from '@blocksuite/affine/store';
import { css, html, LitElement, nothing } from 'lit';
import { property, query } from 'lit/decorators.js';
import { createRef, type Ref, ref } from 'lit/directives/ref.js';
@@ -208,7 +208,7 @@ export class AISlidesRenderer extends WithDisposable(LitElement) {
${ref(this._editorContainer)}
>
${new BlockStdScope({
doc: this._doc,
store: new Store({ blocks: this._doc }),
extensions:
SpecProvider.getInstance().getSpec('edgeless:preview').value,
}).render()}

View File

@@ -12,7 +12,7 @@ import {
} from '@blocksuite/affine/blocks';
import type { ServiceProvider } from '@blocksuite/affine/global/di';
import { WithDisposable } from '@blocksuite/affine/global/utils';
import { type Blocks, Job, Schema } from '@blocksuite/affine/store';
import { type Blocks, Job, Schema, Store } from '@blocksuite/affine/store';
import { css, html, LitElement, nothing } from 'lit';
import { property, query } from 'lit/decorators.js';
import { repeat } from 'lit/directives/repeat.js';
@@ -175,7 +175,7 @@ export class MiniMindmapPreview extends WithDisposable(LitElement) {
})}
>
${new BlockStdScope({
doc: this.doc,
store: new Store({ blocks: this.doc }),
extensions: MiniMindmapSpecs,
}).render()}
</div>

View File

@@ -19,7 +19,7 @@ import {
ThemeExtensionIdentifier,
} from '@blocksuite/affine/blocks';
import { Bound } from '@blocksuite/affine/global/utils';
import type { Block, Blocks } from '@blocksuite/affine/store';
import { type Block, type Blocks, Store } from '@blocksuite/affine/store';
import { createSignalFromObservable } from '@blocksuite/affine-shared/utils';
import type { Container } from '@blocksuite/global/di';
import type { Signal } from '@preact/signals-core';
@@ -90,7 +90,7 @@ export const EdgelessSnapshot = (props: Props) => {
if (!doc) return;
const editorHost = new BlockStdScope({
doc,
store: new Store({ blocks: doc }),
extensions: [
...SpecProvider.getInstance().getSpec('edgeless:preview').value,
getThemeExtension(framework),

View File

@@ -7,7 +7,7 @@ import { createPageModeSpecs } from '@affine/core/components/blocksuite/block-su
import type { AffineDNDData } from '@affine/core/types/dnd';
import { BlockStdScope } from '@blocksuite/affine/block-std';
import { DndApiExtensionIdentifier } from '@blocksuite/affine/blocks';
import { type SliceSnapshot } from '@blocksuite/affine/store';
import { type SliceSnapshot, Store } from '@blocksuite/affine/store';
import { Service } from '@toeverything/infra';
import type { DocsService } from '../../doc';
@@ -69,7 +69,7 @@ export class DndService extends Service {
}
const std = new BlockStdScope({
doc,
store: new Store({ blocks: doc }),
extensions: createPageModeSpecs(this.framework),
});
const dndAPI = std.get(DndApiExtensionIdentifier);

View File

@@ -1,7 +1,7 @@
import { DebugLogger } from '@affine/debug';
import { BlockStdScope } from '@blocksuite/affine/block-std';
import { PageEditorBlockSpecs } from '@blocksuite/affine/blocks';
import type { Blocks } from '@blocksuite/affine/store';
import { type Blocks, Store } from '@blocksuite/affine/store';
import { LiveData } from '@toeverything/infra';
import { useMemo } from 'react';
import { Observable } from 'rxjs';
@@ -45,7 +45,7 @@ export function signalToLiveData<T>(
export function createBlockStdScope(doc: Blocks) {
logger.debug('createBlockStdScope', doc.id);
const std = new BlockStdScope({
doc,
store: new Store({ blocks: doc }),
extensions: PageEditorBlockSpecs,
});
return std;