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

@@ -18,7 +18,7 @@ import {
ShadowlessElement,
} from '@blocksuite/block-std';
import { deserializeXYWH, WithDisposable } from '@blocksuite/global/utils';
import { type BlockModel, type Query } from '@blocksuite/store';
import { type BlockModel, type Query, Store } from '@blocksuite/store';
import { css, nothing } from 'lit';
import { property } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js';
@@ -118,9 +118,10 @@ export class SurfaceRefNotePortal extends WithDisposable(ShadowlessElement) {
query: this.query,
readonly: true,
});
const store = new Store({ blocks: doc });
const previewSpec = SpecProvider.getInstance().getSpec('page:preview');
return new BlockStdScope({
doc,
store,
extensions: previewSpec.value.slice(),
}).render();
}

View File

@@ -47,7 +47,7 @@ import {
DisposableGroup,
type SerializedXYWH,
} 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 { query, state } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js';
@@ -545,10 +545,15 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
const _previewSpec = this._previewSpec.value;
if (!this._viewportEditor) {
this._viewportEditor = new BlockStdScope({
doc: this._previewDoc!,
extensions: _previewSpec,
}).render();
if (this._previewDoc) {
const store = new Store({ blocks: this._previewDoc });
this._viewportEditor = new BlockStdScope({
store,
extensions: _previewSpec,
}).render();
} else {
console.error('Preview doc is not found');
}
}
return html`<div class="ref-content">