refactor(editor): rename store api (#9518)
This commit is contained in:
@@ -53,7 +53,7 @@ todoMeta.addProperty({
|
||||
metaConfig: propertyPresets.textPropertyConfig,
|
||||
get: block => block.doc.meta?.title ?? '',
|
||||
updated: (block, callback) => {
|
||||
return block.doc.collection.slots.docListUpdated.on(() => {
|
||||
return block.doc.workspace.slots.docListUpdated.on(() => {
|
||||
callback();
|
||||
});
|
||||
},
|
||||
|
||||
@@ -59,7 +59,7 @@ export class BlockQueryDataSource extends DataSourceBase {
|
||||
}
|
||||
|
||||
get workspace() {
|
||||
return this.host.doc.collection;
|
||||
return this.host.doc.workspace;
|
||||
}
|
||||
|
||||
constructor(
|
||||
@@ -73,14 +73,14 @@ export class BlockQueryDataSource extends DataSourceBase {
|
||||
this.columnMetaMap.set(property.metaConfig.type, property.metaConfig);
|
||||
}
|
||||
for (const collection of this.workspace.docs.values()) {
|
||||
for (const block of Object.values(collection.getDoc().blocks.peek())) {
|
||||
for (const block of Object.values(collection.getBlocks().blocks.peek())) {
|
||||
if (this.meta.selector(block)) {
|
||||
this.blockMap.set(block.id, block);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.workspace.docs.forEach(doc => {
|
||||
this.listenToDoc(doc.getDoc());
|
||||
this.listenToDoc(doc.getBlocks());
|
||||
});
|
||||
this.workspace.slots.docCreated.on(id => {
|
||||
const doc = this.workspace.getDoc(id);
|
||||
@@ -167,7 +167,7 @@ export class BlockQueryDataSource extends DataSourceBase {
|
||||
type ?? propertyPresets.multiSelectPropertyConfig.type
|
||||
].create(this.newColumnName());
|
||||
|
||||
const id = doc.collection.idGenerator();
|
||||
const id = doc.workspace.idGenerator();
|
||||
if (this.block.columns.some(v => v.id === id)) {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ export class DataViewBlockModel extends BlockModel<Props> {
|
||||
}
|
||||
|
||||
duplicateView(id: string): string {
|
||||
const newId = this.doc.collection.idGenerator();
|
||||
const newId = this.doc.workspace.idGenerator();
|
||||
this.doc.transact(() => {
|
||||
const index = this.views.findIndex(v => v.id === id);
|
||||
const view = this.views[index];
|
||||
|
||||
@@ -47,7 +47,7 @@ export class NoteRenderer
|
||||
}
|
||||
|
||||
addNote() {
|
||||
const collection = this.host?.std.collection;
|
||||
const collection = this.host?.std.workspace;
|
||||
if (!collection) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ export class LinkCell extends BaseCellRenderer<string> {
|
||||
override render() {
|
||||
const linkText = this.value ?? '';
|
||||
const docName =
|
||||
this.docId && this.std?.collection.getDoc(this.docId)?.meta?.title;
|
||||
this.docId && this.std?.workspace.getDoc(this.docId)?.meta?.title;
|
||||
return html`
|
||||
<div class="affine-database-link" @click="${this._onClick}">
|
||||
${docName
|
||||
|
||||
@@ -19,7 +19,7 @@ export const titlePurePropertyConfig = titleColumnType.modelConfig<Text>({
|
||||
cellToJson: ({ value, dataSource }) => {
|
||||
const host = dataSource.contextGet(HostContextKey);
|
||||
if (host) {
|
||||
const collection = host.std.collection;
|
||||
const collection = host.std.workspace;
|
||||
const deltas = value.deltas$.value;
|
||||
const text = deltas
|
||||
.map(delta => {
|
||||
|
||||
@@ -98,7 +98,7 @@ abstract class BaseTextCell extends BaseCellRenderer<Text> {
|
||||
if (!this.docId$.value) {
|
||||
return this.value;
|
||||
}
|
||||
const doc = this.host?.std.collection.getDoc(this.docId$.value);
|
||||
const doc = this.host?.std.workspace.getDoc(this.docId$.value);
|
||||
const root = doc?.root as RootBlockModel;
|
||||
return root.title;
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@ export function addProperty(
|
||||
id?: string;
|
||||
}
|
||||
): string {
|
||||
const id = column.id ?? model.doc.collection.idGenerator();
|
||||
const id = column.id ?? model.doc.workspace.idGenerator();
|
||||
if (model.columns.some(v => v.id === id)) {
|
||||
return id;
|
||||
}
|
||||
@@ -101,7 +101,7 @@ export function deleteView(model: DatabaseBlockModel, id: string) {
|
||||
}
|
||||
|
||||
export function duplicateView(model: DatabaseBlockModel, id: string): string {
|
||||
const newId = model.doc.collection.idGenerator();
|
||||
const newId = model.doc.workspace.idGenerator();
|
||||
model.doc.transact(() => {
|
||||
const index = model.views.findIndex(v => v.id === id);
|
||||
const view = model.views[index];
|
||||
|
||||
@@ -196,7 +196,7 @@ async function renderNoteContent(
|
||||
mode: 'strict',
|
||||
match: ids.map(id => ({ id, viewType: BlockViewType.Display })),
|
||||
};
|
||||
const previewDoc = doc.blockCollection.getDoc({ query });
|
||||
const previewDoc = doc.doc.getBlocks({ query });
|
||||
const previewSpec = SpecProvider.getInstance().getSpec('page:preview');
|
||||
const previewStd = new BlockStdScope({
|
||||
doc: previewDoc,
|
||||
@@ -405,7 +405,7 @@ export function createLinkedDocFromSlice(
|
||||
docTitle?: string
|
||||
) {
|
||||
// const modelsWithChildren = (list:BlockModel[]):BlockModel[]=>list.flatMap(model=>[model,...modelsWithChildren(model.children)])
|
||||
const linkedDoc = doc.collection.createDoc({});
|
||||
const linkedDoc = doc.workspace.createDoc({});
|
||||
linkedDoc.load(() => {
|
||||
const rootId = linkedDoc.addBlock('affine:page', {
|
||||
title: new Text(docTitle),
|
||||
|
||||
@@ -114,7 +114,7 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
|
||||
};
|
||||
|
||||
private readonly _setDocUpdatedAt = () => {
|
||||
const meta = this.doc.collection.meta.getDocMeta(this.model.pageId);
|
||||
const meta = this.doc.workspace.meta.getDocMeta(this.model.pageId);
|
||||
if (meta) {
|
||||
const date = meta.updatedDate || meta.createDate;
|
||||
this._docUpdatedAt = new Date(date);
|
||||
@@ -241,7 +241,7 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
|
||||
}
|
||||
|
||||
get linkedDoc() {
|
||||
return this.std.collection.getDoc(this.model.pageId);
|
||||
return this.std.workspace.getDoc(this.model.pageId);
|
||||
}
|
||||
|
||||
private _handleDoubleClick(event: MouseEvent) {
|
||||
@@ -296,7 +296,7 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
|
||||
const linkedDoc = this.linkedDoc;
|
||||
if (linkedDoc) {
|
||||
this.disposables.add(
|
||||
linkedDoc.collection.slots.docListUpdated.on(() => {
|
||||
linkedDoc.workspace.slots.docListUpdated.on(() => {
|
||||
this._load().catch(e => {
|
||||
console.error(e);
|
||||
this.isError = true;
|
||||
@@ -329,7 +329,7 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
|
||||
|
||||
this._setDocUpdatedAt();
|
||||
this.disposables.add(
|
||||
this.doc.collection.slots.docListUpdated.on(() => {
|
||||
this.doc.workspace.slots.docListUpdated.on(() => {
|
||||
this._setDocUpdatedAt();
|
||||
})
|
||||
);
|
||||
|
||||
@@ -100,7 +100,7 @@ export class EmbedSyncedDocCard extends WithDisposable(ShadowlessElement) {
|
||||
}
|
||||
|
||||
this.disposables.add(
|
||||
syncedDoc.collection.slots.docListUpdated.on(() => {
|
||||
syncedDoc.workspace.slots.docListUpdated.on(() => {
|
||||
renderLinkedDocInCard(this);
|
||||
})
|
||||
);
|
||||
|
||||
@@ -27,7 +27,7 @@ import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
|
||||
import { assertExists, Bound, getCommonBound } from '@blocksuite/global/utils';
|
||||
import {
|
||||
BlockViewType,
|
||||
type GetDocOptions,
|
||||
type GetBlocksOptions,
|
||||
type Query,
|
||||
Text,
|
||||
} from '@blocksuite/store';
|
||||
@@ -365,9 +365,9 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
|
||||
}
|
||||
|
||||
get syncedDoc() {
|
||||
const options: GetDocOptions = { readonly: true };
|
||||
const options: GetBlocksOptions = { readonly: true };
|
||||
if (this.isPageMode) options.query = this._pageFilter;
|
||||
return this.std.collection.getDoc(this.model.pageId, options);
|
||||
return this.std.workspace.getDoc(this.model.pageId, options);
|
||||
}
|
||||
|
||||
private _checkCycle() {
|
||||
@@ -440,7 +440,7 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
|
||||
}
|
||||
|
||||
private _setDocUpdatedAt() {
|
||||
const meta = this.doc.collection.meta.getDocMeta(this.model.pageId);
|
||||
const meta = this.doc.workspace.meta.getDocMeta(this.model.pageId);
|
||||
if (meta) {
|
||||
const date = meta.updatedDate || meta.createDate;
|
||||
this._docUpdatedAt = new Date(date);
|
||||
@@ -476,7 +476,7 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
|
||||
|
||||
this._setDocUpdatedAt();
|
||||
this.disposables.add(
|
||||
this.doc.collection.slots.docListUpdated.on(() => {
|
||||
this.doc.workspace.slots.docListUpdated.on(() => {
|
||||
this._setDocUpdatedAt();
|
||||
})
|
||||
);
|
||||
|
||||
@@ -55,7 +55,7 @@ export class SurfaceRefNotePortal extends WithDisposable(ShadowlessElement) {
|
||||
|
||||
const doc = this.model.doc;
|
||||
this._disposables.add(() => {
|
||||
doc.blockCollection.clearQuery(query, true);
|
||||
doc.doc.clearQuery(query, true);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ export class SurfaceRefNotePortal extends WithDisposable(ShadowlessElement) {
|
||||
console.error('Query is not set before rendering note preview');
|
||||
return nothing;
|
||||
}
|
||||
const doc = this.model.doc.blockCollection.getDoc({
|
||||
const doc = this.model.doc.doc.getBlocks({
|
||||
query: this.query,
|
||||
readonly: true,
|
||||
});
|
||||
|
||||
@@ -336,8 +336,8 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
||||
];
|
||||
}
|
||||
|
||||
const doc = [...this.std.collection.docs.values()]
|
||||
.map(doc => doc.getDoc())
|
||||
const doc = [...this.std.workspace.docs.values()]
|
||||
.map(doc => doc.getBlocks())
|
||||
.find(
|
||||
doc =>
|
||||
doc.getBlock(this.model.reference) ||
|
||||
@@ -370,7 +370,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
||||
|
||||
this._referencedModel =
|
||||
referencedModel && referencedModel.xywh ? referencedModel : null;
|
||||
this._previewDoc = this.doc.collection.getDoc(docId, {
|
||||
this._previewDoc = this.doc.workspace.getDoc(docId, {
|
||||
readonly: true,
|
||||
});
|
||||
this._referenceXYWH = this._referencedModel?.xywh ?? null;
|
||||
|
||||
@@ -77,7 +77,7 @@ export class AffineReference extends WithDisposable(ShadowlessElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
const refMeta = doc.collection.meta.docMetas.find(
|
||||
const refMeta = doc.workspace.meta.docMetas.find(
|
||||
doc => doc.id === refAttribute.pageId
|
||||
);
|
||||
this.refMeta = refMeta
|
||||
@@ -221,7 +221,7 @@ export class AffineReference extends WithDisposable(ShadowlessElement) {
|
||||
const doc = this.doc;
|
||||
if (doc) {
|
||||
this._disposables.add(
|
||||
doc.collection.slots.docListUpdated.on(() => this._updateRefMeta(doc))
|
||||
doc.workspace.slots.docListUpdated.on(() => this._updateRefMeta(doc))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ function tryConvertToLinkedDoc(std: BlockStdScope, inlineEditor: InlineEditor) {
|
||||
});
|
||||
inlineEditor.setInlineRange({ index: inlineRange.index - 1, length: 0 });
|
||||
|
||||
const doc = createDefaultDoc(std.doc.collection, {
|
||||
const doc = createDefaultDoc(std.doc.workspace, {
|
||||
title: docName,
|
||||
});
|
||||
insertLinkedNode({
|
||||
|
||||
@@ -12,9 +12,9 @@ export class RootBlockModel extends BlockModel<RootBlockProps> {
|
||||
this.doc.slots.rootAdded.on(id => {
|
||||
const model = this.doc.getBlockById(id);
|
||||
if (model instanceof RootBlockModel) {
|
||||
const newDocMeta = this.doc.collection.meta.getDocMeta(model.doc.id);
|
||||
const newDocMeta = this.doc.workspace.meta.getDocMeta(model.doc.id);
|
||||
if (!newDocMeta || newDocMeta.title !== model.title.toString()) {
|
||||
this.doc.collection.meta.setDocMeta(model.doc.id, {
|
||||
this.doc.workspace.meta.setDocMeta(model.doc.id, {
|
||||
title: model.title.toString(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ class PasteTr {
|
||||
op.attributes.link
|
||||
);
|
||||
if (searchResult) {
|
||||
const doc = this.std.collection.getDoc(searchResult.docId);
|
||||
const doc = this.std.workspace.getDoc(searchResult.docId);
|
||||
if (doc) {
|
||||
docId = doc.id;
|
||||
linkToDocId.set(op.attributes.link, doc.id);
|
||||
|
||||
@@ -88,7 +88,7 @@ export class DocDisplayMetaService
|
||||
pageId: string,
|
||||
{ params, title, referenced }: DocDisplayMetaParams = {}
|
||||
): Signal<TemplateResult> {
|
||||
const doc = this.std.collection.getDoc(pageId);
|
||||
const doc = this.std.workspace.getDoc(pageId);
|
||||
|
||||
if (!doc) {
|
||||
return signal(DocDisplayMetaService.icons.deleted);
|
||||
@@ -114,7 +114,7 @@ export class DocDisplayMetaService
|
||||
|
||||
this.disposables.push(disposable);
|
||||
this.disposables.push(
|
||||
this.std.collection.slots.docRemoved
|
||||
this.std.workspace.slots.docRemoved
|
||||
.filter(docId => docId === doc.id)
|
||||
.once(() => {
|
||||
const index = this.disposables.findIndex(d => d === disposable);
|
||||
@@ -152,7 +152,7 @@ export class DocDisplayMetaService
|
||||
}
|
||||
|
||||
title(pageId: string, { title }: DocDisplayMetaParams = {}): Signal<string> {
|
||||
const doc = this.std.collection.getDoc(pageId);
|
||||
const doc = this.std.workspace.getDoc(pageId);
|
||||
|
||||
if (!doc) {
|
||||
return signal(title || 'Deleted doc');
|
||||
@@ -162,13 +162,13 @@ export class DocDisplayMetaService
|
||||
if (!title$) {
|
||||
title$ = signal(doc.meta?.title || 'Untitled');
|
||||
|
||||
const disposable = this.std.collection.slots.docListUpdated.on(() => {
|
||||
const disposable = this.std.workspace.slots.docListUpdated.on(() => {
|
||||
title$!.value = doc.meta?.title || 'Untitled';
|
||||
});
|
||||
|
||||
this.disposables.push(disposable);
|
||||
this.disposables.push(
|
||||
this.std.collection.slots.docRemoved
|
||||
this.std.workspace.slots.docRemoved
|
||||
.filter(docId => docId === doc.id)
|
||||
.once(() => {
|
||||
const index = this.disposables.findIndex(d => d === disposable);
|
||||
|
||||
@@ -54,7 +54,7 @@ export class DNDAPIExtension extends Extension {
|
||||
...snapshot,
|
||||
content: [
|
||||
{
|
||||
id: this.std.collection.idGenerator(),
|
||||
id: this.std.workspace.idGenerator(),
|
||||
type: 'block',
|
||||
flavour,
|
||||
props,
|
||||
|
||||
@@ -79,7 +79,7 @@ export class PreviewHelper {
|
||||
|
||||
const query = this._calculateQuery(selectedIds);
|
||||
|
||||
const doc = this.widget.doc.blockCollection.getDoc({ query });
|
||||
const doc = this.widget.doc.doc.getBlocks({ query });
|
||||
|
||||
const previewSpec = SpecProvider.getInstance().getSpec('page:preview');
|
||||
const previewStd = new BlockStdScope({
|
||||
@@ -96,7 +96,7 @@ export class PreviewHelper {
|
||||
dragPreview = new DragPreview(offset);
|
||||
dragPreview.template = previewTemplate;
|
||||
dragPreview.onRemove = () => {
|
||||
this.widget.doc.blockCollection.clearQuery(query);
|
||||
this.widget.doc.doc.clearQuery(query);
|
||||
};
|
||||
dragPreview.style.width = `${width / this.widget.scaleInNote.peek()}px`;
|
||||
dragPreview.style.transform = `translate(${posX}px, ${posY}px) scale(${this.widget.scaleInNote.peek()})`;
|
||||
|
||||
@@ -10,7 +10,7 @@ export const newIdCrossDoc =
|
||||
samePage = payload.snapshot.pageId === std.doc.id;
|
||||
}
|
||||
if (payload.type === 'block' && !samePage) {
|
||||
payload.snapshot.id = std.collection.idGenerator();
|
||||
payload.snapshot.id = std.workspace.idGenerator();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -18,7 +18,7 @@ export const surfaceRefToEmbed =
|
||||
!std.doc.hasBlock(payload.snapshot.id)
|
||||
) {
|
||||
const id = payload.snapshot.id;
|
||||
payload.snapshot.id = std.collection.idGenerator();
|
||||
payload.snapshot.id = std.workspace.idGenerator();
|
||||
payload.snapshot.flavour = 'affine:embed-linked-doc';
|
||||
payload.snapshot.props = {
|
||||
blockId: id,
|
||||
|
||||
@@ -5,7 +5,7 @@ import { multiPlayersColor } from './color-picker';
|
||||
|
||||
export class RemoteColorManager {
|
||||
private get awarenessStore() {
|
||||
return this.std.doc.collection.awarenessStore;
|
||||
return this.std.doc.workspace.awarenessStore;
|
||||
}
|
||||
|
||||
constructor(readonly std: BlockStdScope) {
|
||||
|
||||
Reference in New Issue
Block a user