mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-15 05:37:32 +00:00
refactor(editor): rename store api (#9518)
This commit is contained in:
@@ -60,10 +60,10 @@ export class PageClipboard {
|
||||
this._std.clipboard.use(copy);
|
||||
this._std.clipboard.use(paste);
|
||||
this._std.clipboard.use(
|
||||
replaceIdMiddleware(this._std.doc.collection.idGenerator)
|
||||
replaceIdMiddleware(this._std.doc.workspace.idGenerator)
|
||||
);
|
||||
this._std.clipboard.use(
|
||||
titleMiddleware(this._std.doc.collection.meta.docMetas)
|
||||
titleMiddleware(this._std.doc.workspace.meta.docMetas)
|
||||
);
|
||||
this._std.clipboard.use(defaultImageProxyMiddleware);
|
||||
|
||||
@@ -85,10 +85,10 @@ export class PageClipboard {
|
||||
this._std.clipboard.unuse(copy);
|
||||
this._std.clipboard.unuse(paste);
|
||||
this._std.clipboard.unuse(
|
||||
replaceIdMiddleware(this._std.doc.collection.idGenerator)
|
||||
replaceIdMiddleware(this._std.doc.workspace.idGenerator)
|
||||
);
|
||||
this._std.clipboard.unuse(
|
||||
titleMiddleware(this._std.doc.collection.meta.docMetas)
|
||||
titleMiddleware(this._std.doc.workspace.meta.docMetas)
|
||||
);
|
||||
this._std.clipboard.unuse(defaultImageProxyMiddleware);
|
||||
},
|
||||
|
||||
@@ -370,12 +370,12 @@ export class EdgelessClipboardController extends PageClipboard {
|
||||
const elementsRawData = JSON.parse(mayBeSurfaceDataJson);
|
||||
const { snapshot, blobs } = elementsRawData;
|
||||
const job = new Job({
|
||||
schema: this.std.collection.schema,
|
||||
blobCRUD: this.std.collection.blobSync,
|
||||
schema: this.std.workspace.schema,
|
||||
blobCRUD: this.std.workspace.blobSync,
|
||||
docCRUD: {
|
||||
create: (id: string) => this.std.collection.createDoc({ id }),
|
||||
get: (id: string) => this.std.collection.getDoc(id),
|
||||
delete: (id: string) => this.std.collection.removeDoc(id),
|
||||
create: (id: string) => this.std.workspace.createDoc({ id }),
|
||||
get: (id: string) => this.std.workspace.getDoc(id),
|
||||
delete: (id: string) => this.std.workspace.removeDoc(id),
|
||||
},
|
||||
});
|
||||
const map = job.assetsManager.getAssets();
|
||||
@@ -475,7 +475,7 @@ export class EdgelessClipboardController extends PageClipboard {
|
||||
const { xywh, rotate, sourceId, name, size, type, embed, style } =
|
||||
attachment.props;
|
||||
|
||||
if (!(await this.host.std.collection.blobSync.get(sourceId as string))) {
|
||||
if (!(await this.host.std.workspace.blobSync.get(sourceId as string))) {
|
||||
return null;
|
||||
}
|
||||
const attachmentId = this.crud.addBlock(
|
||||
@@ -741,7 +741,7 @@ export class EdgelessClipboardController extends PageClipboard {
|
||||
const { xywh, rotate, sourceId, size, width, height, caption } =
|
||||
image.props;
|
||||
|
||||
if (!(await this.host.std.collection.blobSync.get(sourceId as string))) {
|
||||
if (!(await this.host.std.workspace.blobSync.get(sourceId as string))) {
|
||||
return null;
|
||||
}
|
||||
return this.crud.addBlock(
|
||||
@@ -1374,12 +1374,12 @@ export async function prepareClipboardData(
|
||||
std: BlockStdScope
|
||||
) {
|
||||
const job = new Job({
|
||||
schema: std.collection.schema,
|
||||
blobCRUD: std.collection.blobSync,
|
||||
schema: std.workspace.schema,
|
||||
blobCRUD: std.workspace.blobSync,
|
||||
docCRUD: {
|
||||
create: (id: string) => std.collection.createDoc({ id }),
|
||||
get: (id: string) => std.collection.getDoc(id),
|
||||
delete: (id: string) => std.collection.removeDoc(id),
|
||||
create: (id: string) => std.workspace.createDoc({ id }),
|
||||
get: (id: string) => std.workspace.getDoc(id),
|
||||
delete: (id: string) => std.workspace.removeDoc(id),
|
||||
},
|
||||
});
|
||||
const selected = await Promise.all(
|
||||
|
||||
@@ -104,7 +104,7 @@ export class FramePreview extends WithDisposable(ShadowlessElement) {
|
||||
}
|
||||
|
||||
private _initPreviewDoc() {
|
||||
this._previewDoc = this._originalDoc.collection.getDoc(
|
||||
this._previewDoc = this._originalDoc.workspace.getDoc(
|
||||
this._originalDoc.id,
|
||||
{
|
||||
query: this._docFilter,
|
||||
@@ -112,7 +112,7 @@ export class FramePreview extends WithDisposable(ShadowlessElement) {
|
||||
}
|
||||
);
|
||||
this.disposables.add(() => {
|
||||
this._originalDoc.blockCollection.clearQuery(this._docFilter);
|
||||
this._originalDoc.doc.clearQuery(this._docFilter);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ export const replaceIdMiddleware = (job: TemplateJob) => {
|
||||
const { blockJson } = data;
|
||||
const newId = regeneratedIdMap.has(blockJson.id)
|
||||
? regeneratedIdMap.get(blockJson.id)!
|
||||
: job.model.doc.collection.idGenerator();
|
||||
: job.model.doc.workspace.idGenerator();
|
||||
|
||||
if (!regeneratedIdMap.has(blockJson.id)) {
|
||||
regeneratedIdMap.set(blockJson.id, newId);
|
||||
@@ -62,7 +62,7 @@ export const replaceIdMiddleware = (job: TemplateJob) => {
|
||||
});
|
||||
|
||||
blockJson.children.forEach(block => {
|
||||
regeneratedIdMap.set(block.id, job.model.doc.collection.idGenerator());
|
||||
regeneratedIdMap.set(block.id, job.model.doc.workspace.idGenerator());
|
||||
});
|
||||
|
||||
defered.forEach(id => {
|
||||
|
||||
@@ -87,12 +87,12 @@ export class TemplateJob {
|
||||
|
||||
constructor({ model, type, middlewares }: TemplateJobConfig) {
|
||||
this.job = new Job({
|
||||
schema: model.doc.collection.schema,
|
||||
blobCRUD: model.doc.collection.blobSync,
|
||||
schema: model.doc.workspace.schema,
|
||||
blobCRUD: model.doc.workspace.blobSync,
|
||||
docCRUD: {
|
||||
create: (id: string) => model.doc.collection.createDoc({ id }),
|
||||
get: (id: string) => model.doc.collection.getDoc(id),
|
||||
delete: (id: string) => model.doc.collection.removeDoc(id),
|
||||
create: (id: string) => model.doc.workspace.createDoc({ id }),
|
||||
get: (id: string) => model.doc.workspace.getDoc(id),
|
||||
delete: (id: string) => model.doc.workspace.removeDoc(id),
|
||||
},
|
||||
middlewares: [],
|
||||
});
|
||||
@@ -317,7 +317,7 @@ export class TemplateJob {
|
||||
to: Y.Map<Y.Map<unknown>>
|
||||
) {
|
||||
const schema =
|
||||
this.model.doc.collection.schema.flavourSchemaMap.get('affine:surface');
|
||||
this.model.doc.workspace.schema.flavourSchemaMap.get('affine:surface');
|
||||
const surfaceTransformer =
|
||||
schema?.transformer?.() as SurfaceBlockTransformer;
|
||||
|
||||
|
||||
@@ -40,12 +40,12 @@ export function getSortedCloneElements(elements: GfxModel[]) {
|
||||
export function prepareCloneData(elements: GfxModel[], std: BlockStdScope) {
|
||||
elements = sortEdgelessElements(elements);
|
||||
const job = new Job({
|
||||
schema: std.collection.schema,
|
||||
blobCRUD: std.collection.blobSync,
|
||||
schema: std.workspace.schema,
|
||||
blobCRUD: std.workspace.blobSync,
|
||||
docCRUD: {
|
||||
create: (id: string) => std.collection.createDoc({ id }),
|
||||
get: (id: string) => std.collection.getDoc(id),
|
||||
delete: (id: string) => std.collection.removeDoc(id),
|
||||
create: (id: string) => std.workspace.createDoc({ id }),
|
||||
get: (id: string) => std.workspace.getDoc(id),
|
||||
delete: (id: string) => std.workspace.removeDoc(id),
|
||||
},
|
||||
});
|
||||
const res = elements.map(element => {
|
||||
|
||||
@@ -501,7 +501,7 @@ export class EdgelessChangeEmbedCardButton extends WithDisposable(LitElement) {
|
||||
get _originalDocInfo(): AliasInfo | undefined {
|
||||
const model = this.model;
|
||||
const doc = isInternalEmbedModel(model)
|
||||
? this.std.collection.getDoc(model.pageId)
|
||||
? this.std.workspace.getDoc(model.pageId)
|
||||
: null;
|
||||
|
||||
if (doc) {
|
||||
@@ -518,7 +518,7 @@ export class EdgelessChangeEmbedCardButton extends WithDisposable(LitElement) {
|
||||
get _originalDocTitle() {
|
||||
const model = this.model;
|
||||
const doc = isInternalEmbedModel(model)
|
||||
? this.std.collection.getDoc(model.pageId)
|
||||
? this.std.workspace.getDoc(model.pageId)
|
||||
: null;
|
||||
|
||||
return doc?.meta?.title || 'Untitled';
|
||||
|
||||
@@ -40,7 +40,7 @@ export function createLinkedDocFromNote(
|
||||
note: NoteBlockModel,
|
||||
docTitle?: string
|
||||
) {
|
||||
const linkedDoc = doc.collection.createDoc({});
|
||||
const linkedDoc = doc.workspace.createDoc({});
|
||||
linkedDoc.load(() => {
|
||||
const rootId = linkedDoc.addBlock('affine:page', {
|
||||
title: new Text(docTitle),
|
||||
@@ -71,7 +71,7 @@ export function createLinkedDocFromEdgelessElements(
|
||||
elements: BlockSuite.EdgelessModel[],
|
||||
docTitle?: string
|
||||
) {
|
||||
const linkedDoc = host.doc.collection.createDoc({});
|
||||
const linkedDoc = host.doc.workspace.createDoc({});
|
||||
linkedDoc.load(() => {
|
||||
const rootId = linkedDoc.addBlock('affine:page', {
|
||||
title: new Text(docTitle),
|
||||
|
||||
@@ -263,7 +263,7 @@ export class EmbedCardToolbar extends WidgetComponent<
|
||||
if (!model) return undefined;
|
||||
|
||||
const doc = isInternalEmbedModel(model)
|
||||
? this.std.collection.getDoc(model.pageId)
|
||||
? this.std.workspace.getDoc(model.pageId)
|
||||
: null;
|
||||
|
||||
if (doc) {
|
||||
@@ -282,7 +282,7 @@ export class EmbedCardToolbar extends WidgetComponent<
|
||||
if (!model) return undefined;
|
||||
|
||||
const doc = isInternalEmbedModel(model)
|
||||
? this.std.collection.getDoc(model.pageId)
|
||||
? this.std.workspace.getDoc(model.pageId)
|
||||
: null;
|
||||
|
||||
return doc?.meta?.title || 'Untitled';
|
||||
|
||||
@@ -275,7 +275,7 @@ const pageToolGroup: KeyboardToolPanelGroup = {
|
||||
.chain()
|
||||
.getSelectedModels()
|
||||
.inline(({ selectedModels }) => {
|
||||
const newDoc = createDefaultDoc(std.doc.collection);
|
||||
const newDoc = createDefaultDoc(std.doc.workspace);
|
||||
if (!selectedModels?.length) return;
|
||||
insertContent(std.host, selectedModels[0], REFERENCE_NODE, {
|
||||
reference: {
|
||||
|
||||
@@ -105,7 +105,7 @@ export function createLinkedDocMenuGroup(
|
||||
inlineEditor: AffineInlineEditor
|
||||
) {
|
||||
const doc = editorHost.doc;
|
||||
const { docMetas } = doc.collection.meta;
|
||||
const { docMetas } = doc.workspace.meta;
|
||||
const filteredDocList = docMetas
|
||||
.filter(({ id }) => id !== doc.id)
|
||||
.filter(({ title }) => isFuzzyMatch(title, query));
|
||||
@@ -164,7 +164,7 @@ export function createNewDocMenuGroup(
|
||||
action: () => {
|
||||
abort();
|
||||
const docName = query;
|
||||
const newDoc = createDefaultDoc(doc.collection, {
|
||||
const newDoc = createDefaultDoc(doc.workspace, {
|
||||
title: docName,
|
||||
});
|
||||
insertLinkedNode({
|
||||
@@ -213,7 +213,7 @@ export function createNewDocMenuGroup(
|
||||
toast(editorHost, message);
|
||||
};
|
||||
showImportModal({
|
||||
collection: doc.collection,
|
||||
collection: doc.workspace,
|
||||
onSuccess,
|
||||
onFail,
|
||||
});
|
||||
|
||||
@@ -194,7 +194,7 @@ export const defaultSlashMenuConfig: SlashMenuConfig = {
|
||||
showWhen: ({ model }) =>
|
||||
model.doc.schema.flavourSchemaMap.has('affine:embed-linked-doc'),
|
||||
action: ({ rootComponent, model }) => {
|
||||
const newDoc = createDefaultDoc(rootComponent.doc.collection);
|
||||
const newDoc = createDefaultDoc(rootComponent.doc.workspace);
|
||||
insertContent(rootComponent.host, model, REFERENCE_NODE, {
|
||||
reference: {
|
||||
type: 'LinkedPage',
|
||||
|
||||
Reference in New Issue
Block a user