refactor(editor): rename store api (#9518)
This commit is contained in:
@@ -6,7 +6,7 @@ import {
|
||||
} from '@blocksuite/blocks';
|
||||
import { WithDisposable } from '@blocksuite/global/utils';
|
||||
import type { AffineEditorContainer } from '@blocksuite/presets';
|
||||
import type { BlockCollection, DocCollection } from '@blocksuite/store';
|
||||
import type { Doc, Workspace } from '@blocksuite/store';
|
||||
import { css, html, nothing } from 'lit';
|
||||
import { customElement, property } from 'lit/decorators.js';
|
||||
import { repeat } from 'lit/directives/repeat.js';
|
||||
@@ -64,23 +64,23 @@ export class DocsPanel extends WithDisposable(ShadowlessElement) {
|
||||
`;
|
||||
|
||||
createDoc = () => {
|
||||
createDocBlock(this.editor.doc.collection);
|
||||
createDocBlock(this.editor.doc.workspace);
|
||||
};
|
||||
|
||||
gotoDoc = (doc: BlockCollection) => {
|
||||
gotoDoc = (doc: Doc) => {
|
||||
const url = this.editor.std
|
||||
.getOptional(GenerateDocUrlProvider)
|
||||
?.generateDocUrl(doc.id);
|
||||
if (url) history.pushState({}, '', url);
|
||||
|
||||
this.editor.doc = doc.getDoc();
|
||||
this.editor.doc = doc.getBlocks();
|
||||
this.editor.doc.load();
|
||||
this.editor.doc.resetHistory();
|
||||
this.requestUpdate();
|
||||
};
|
||||
|
||||
private get collection() {
|
||||
return this.editor.doc.collection;
|
||||
return this.editor.doc.workspace;
|
||||
}
|
||||
|
||||
private get docs() {
|
||||
@@ -110,7 +110,7 @@ export class DocsPanel extends WithDisposable(ShadowlessElement) {
|
||||
});
|
||||
|
||||
this.disposables.add(
|
||||
this.editor.doc.collection.slots.docListUpdated.on(() => {
|
||||
this.editor.doc.workspace.slots.docListUpdated.on(() => {
|
||||
this.requestUpdate();
|
||||
})
|
||||
);
|
||||
@@ -146,7 +146,7 @@ export class DocsPanel extends WithDisposable(ShadowlessElement) {
|
||||
removeModeFromStorage(doc.id);
|
||||
// When delete the current doc, we need to set the editor doc to the first remaining doc
|
||||
if (isDeleteCurrent) {
|
||||
this.editor.doc = this.docs[0].getDoc();
|
||||
this.editor.doc = this.docs[0].getBlocks();
|
||||
}
|
||||
};
|
||||
return html`<div class="doc-item" @click="${click}" style="${style}">
|
||||
@@ -169,7 +169,7 @@ export class DocsPanel extends WithDisposable(ShadowlessElement) {
|
||||
accessor onClose!: () => void;
|
||||
}
|
||||
|
||||
function createDocBlock(collection: DocCollection) {
|
||||
function createDocBlock(collection: Workspace) {
|
||||
const id = collection.idGenerator();
|
||||
createDefaultDoc(collection, { id });
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { DocModeProvider } from '@blocksuite/blocks';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import type { AffineEditorContainer } from '@blocksuite/presets';
|
||||
import type { BlockCollection, Doc, DocCollection } from '@blocksuite/store';
|
||||
import type { Blocks, Doc, Workspace } from '@blocksuite/store';
|
||||
import type { LitElement } from 'lit';
|
||||
|
||||
export function getDocFromUrlParams(collection: DocCollection, url: URL) {
|
||||
let doc: Doc | null = null;
|
||||
export function getDocFromUrlParams(collection: Workspace, url: URL) {
|
||||
let doc: Blocks | null = null;
|
||||
|
||||
const docId = decodeURIComponent(url.hash.slice(1));
|
||||
|
||||
@@ -13,10 +13,9 @@ export function getDocFromUrlParams(collection: DocCollection, url: URL) {
|
||||
doc = collection.getDoc(docId);
|
||||
}
|
||||
if (!doc) {
|
||||
const blockCollection = collection.docs.values().next()
|
||||
.value as BlockCollection;
|
||||
const blockCollection = collection.docs.values().next().value as Doc;
|
||||
assertExists(blockCollection, 'Need to create a doc first');
|
||||
doc = blockCollection.getDoc();
|
||||
doc = blockCollection.getBlocks();
|
||||
}
|
||||
|
||||
doc.load();
|
||||
@@ -41,7 +40,7 @@ export function setDocModeFromUrlParams(
|
||||
}
|
||||
|
||||
export function listenHashChange(
|
||||
collection: DocCollection,
|
||||
collection: Workspace,
|
||||
editor: AffineEditorContainer,
|
||||
panel?: LitElement
|
||||
) {
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
SpecProvider,
|
||||
} from '@blocksuite/blocks';
|
||||
import { AffineEditorContainer } from '@blocksuite/presets';
|
||||
import type { DocCollection } from '@blocksuite/store';
|
||||
import type { Workspace } from '@blocksuite/store';
|
||||
|
||||
import { AttachmentViewerPanel } from '../../_common/components/attachment-viewer-panel.js';
|
||||
import { CollabDebugMenu } from '../../_common/components/collab-debug-menu.js';
|
||||
@@ -36,7 +36,7 @@ import {
|
||||
} from '../../_common/mock-services.js';
|
||||
import { getExampleSpecs } from '../specs-examples/index.js';
|
||||
|
||||
export async function mountDefaultDocEditor(collection: DocCollection) {
|
||||
export async function mountDefaultDocEditor(collection: Workspace) {
|
||||
const app = document.getElementById('app');
|
||||
if (!app) return;
|
||||
|
||||
|
||||
6
blocksuite/playground/apps/env.d.ts
vendored
6
blocksuite/playground/apps/env.d.ts
vendored
@@ -1,7 +1,7 @@
|
||||
import type { EditorHost } from '@blocksuite/block-std';
|
||||
import type { TestUtils } from '@blocksuite/blocks';
|
||||
import type { AffineEditorContainer } from '@blocksuite/presets';
|
||||
import type { BlockSchema, Doc, DocCollection, Job } from '@blocksuite/store';
|
||||
import type { BlockSchema, Blocks, Workspace, Job } from '@blocksuite/store';
|
||||
import type { z } from 'zod';
|
||||
import type * as Y from 'yjs';
|
||||
|
||||
@@ -14,8 +14,8 @@ declare global {
|
||||
|
||||
interface Window {
|
||||
editor: AffineEditorContainer;
|
||||
doc: Doc;
|
||||
collection: DocCollection;
|
||||
doc: Blocks;
|
||||
collection: Workspace;
|
||||
blockSchemas: z.infer<typeof BlockSchema>[];
|
||||
job: Job;
|
||||
Y: typeof Y;
|
||||
|
||||
Reference in New Issue
Block a user