mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-11 15:16:28 +08:00
refactor(editor): move crud to doc (#9479)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type { ExtensionType } from '@blocksuite/block-std';
|
||||
import { createIdentifier } from '@blocksuite/global/di';
|
||||
import { Slot } from '@blocksuite/store';
|
||||
import { Slot } from '@blocksuite/global/utils';
|
||||
|
||||
import type { Viewport } from '../types';
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { ColorScheme } from '@blocksuite/affine-model';
|
||||
import type { Slot } from '@blocksuite/store';
|
||||
import type { Slot } from '@blocksuite/global/utils';
|
||||
import { createContext } from '@lit/context';
|
||||
|
||||
import type { EdgelessToolbarWidget } from './edgeless-toolbar.js';
|
||||
|
||||
@@ -21,8 +21,7 @@ import {
|
||||
import { stopPropagation } from '@blocksuite/affine-shared/utils';
|
||||
import { WidgetComponent } from '@blocksuite/block-std';
|
||||
import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
|
||||
import { debounce } from '@blocksuite/global/utils';
|
||||
import { Slot } from '@blocksuite/store';
|
||||
import { debounce, Slot } from '@blocksuite/global/utils';
|
||||
import { autoPlacement, offset } from '@floating-ui/dom';
|
||||
import { ContextProvider } from '@lit/context';
|
||||
import { computed } from '@preact/signals-core';
|
||||
|
||||
@@ -2,8 +2,11 @@
|
||||
import type { PointerEventState } from '@blocksuite/block-std';
|
||||
import { BaseTool, MouseButton } from '@blocksuite/block-std/gfx';
|
||||
import { IS_MAC } from '@blocksuite/global/env';
|
||||
import { Bound, getCommonBoundWithRotation } from '@blocksuite/global/utils';
|
||||
import { Slot } from '@blocksuite/store';
|
||||
import {
|
||||
Bound,
|
||||
getCommonBoundWithRotation,
|
||||
Slot,
|
||||
} from '@blocksuite/global/utils';
|
||||
|
||||
import {
|
||||
AFFINE_AI_PANEL_WIDGET,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { RootBlockSchema } from '@blocksuite/affine-model';
|
||||
import type { Viewport } from '@blocksuite/affine-shared/types';
|
||||
import { Slot } from '@blocksuite/store';
|
||||
import { Slot } from '@blocksuite/global/utils';
|
||||
|
||||
import { RootService } from '../root-service.js';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export { markdownToMindmap, MiniMindmapPreview } from './mindmap-preview.js';
|
||||
export { MindmapRootBlock } from './mindmap-root-block.js';
|
||||
export { MindmapService } from './minmap-service.js';
|
||||
export { MindmapService } from './mindmap-service.js';
|
||||
export { MindmapSurfaceBlock } from './surface-block.js';
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { RootBlockSchema } from '@blocksuite/affine-model';
|
||||
import { BlockService } from '@blocksuite/block-std';
|
||||
import { Slot } from '@blocksuite/store';
|
||||
import { Slot } from '@blocksuite/global/utils';
|
||||
|
||||
export class MindmapService extends BlockService {
|
||||
static override readonly flavour = RootBlockSchema.model.flavour;
|
||||
@@ -16,7 +16,7 @@ import type { BlockSchema } from '@blocksuite/store';
|
||||
import { literal } from 'lit/static-html.js';
|
||||
import type { z } from 'zod';
|
||||
|
||||
import { MindmapService } from './minmap-service.js';
|
||||
import { MindmapService } from './mindmap-service.js';
|
||||
import { MindmapSurfaceBlockService } from './surface-service.js';
|
||||
|
||||
export const MiniMindmapSpecs: ExtensionType[] = [
|
||||
|
||||
@@ -13,7 +13,7 @@ import type { Bound } from '@blocksuite/global/utils';
|
||||
import { html } from 'lit';
|
||||
import { query } from 'lit/decorators.js';
|
||||
|
||||
import type { MindmapService } from './minmap-service.js';
|
||||
import type { MindmapService } from './mindmap-service.js';
|
||||
|
||||
export class MindmapSurfaceBlock extends BlockComponent<SurfaceBlockModel> {
|
||||
renderer?: CanvasRenderer;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
|
||||
// oxlint-disable-next-line @typescript-eslint/triple-slash-reference
|
||||
/// <reference path="../shim.d.ts" />
|
||||
|
||||
export type { Y };
|
||||
@@ -7,16 +7,9 @@ export * from './reactive/index.js';
|
||||
export * from './schema/index.js';
|
||||
export * from './store/index.js';
|
||||
export * from './transformer/index.js';
|
||||
export {
|
||||
createAutoIncrementIdGenerator,
|
||||
createAutoIncrementIdGeneratorByClientId,
|
||||
type IdGenerator,
|
||||
nanoid,
|
||||
uuidv4,
|
||||
} from './utils/id-generator.js';
|
||||
export { type IdGenerator, nanoid, uuidv4 } from './utils/id-generator.js';
|
||||
export * as Utils from './utils/utils.js';
|
||||
export * from './yjs/index.js';
|
||||
export { Slot } from '@blocksuite/global/utils';
|
||||
|
||||
import type * as Y from 'yjs';
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import type { BlockModel } from '../../schema/base.js';
|
||||
import type { IdGenerator } from '../../utils/id-generator.js';
|
||||
import type { AwarenessStore, BlockSuiteDoc } from '../../yjs/index.js';
|
||||
import type { DocCollection } from '../collection.js';
|
||||
import { DocCRUD } from './crud.js';
|
||||
import { Doc } from './doc.js';
|
||||
import type { YBlock } from './index.js';
|
||||
import type { Query } from './query.js';
|
||||
@@ -45,8 +44,6 @@ export class BlockCollection {
|
||||
|
||||
private readonly _collection: DocCollection;
|
||||
|
||||
private readonly _docCRUD: DocCRUD;
|
||||
|
||||
private readonly _docMap = {
|
||||
undefined: new Map<string, Doc>(),
|
||||
true: new Map<string, Doc>(),
|
||||
@@ -177,10 +174,6 @@ export class BlockCollection {
|
||||
return this._collection;
|
||||
}
|
||||
|
||||
get crud() {
|
||||
return this._docCRUD;
|
||||
}
|
||||
|
||||
get docSync() {
|
||||
return this.collection.docSync;
|
||||
}
|
||||
@@ -241,7 +234,6 @@ export class BlockCollection {
|
||||
this._yBlocks = this._ySpaceDoc.getMap('blocks');
|
||||
this._collection = collection;
|
||||
this._idGenerator = idGenerator;
|
||||
this._docCRUD = new DocCRUD(this._yBlocks, collection.schema);
|
||||
}
|
||||
|
||||
private _getReadonlyKey(readonly?: boolean): 'true' | 'false' | 'undefined' {
|
||||
@@ -344,7 +336,6 @@ export class BlockCollection {
|
||||
|
||||
const doc = new Doc({
|
||||
blockCollection: this,
|
||||
crud: this._docCRUD,
|
||||
schema: this.collection.schema,
|
||||
readonly,
|
||||
query,
|
||||
|
||||
@@ -8,13 +8,12 @@ import { syncBlockProps } from '../../utils/utils.js';
|
||||
import type { BlockOptions } from './block/index.js';
|
||||
import { Block } from './block/index.js';
|
||||
import type { BlockCollection, BlockProps } from './block-collection.js';
|
||||
import type { DocCRUD } from './crud.js';
|
||||
import { DocCRUD } from './crud.js';
|
||||
import { type Query, runQuery } from './query.js';
|
||||
|
||||
type DocOptions = {
|
||||
schema: Schema;
|
||||
blockCollection: BlockCollection;
|
||||
crud: DocCRUD;
|
||||
readonly?: boolean;
|
||||
query?: Query;
|
||||
};
|
||||
@@ -267,7 +266,7 @@ export class Doc {
|
||||
return this._blockCollection.withoutTransact.bind(this._blockCollection);
|
||||
}
|
||||
|
||||
constructor({ schema, blockCollection, crud, readonly, query }: DocOptions) {
|
||||
constructor({ schema, blockCollection, readonly, query }: DocOptions) {
|
||||
this._blockCollection = blockCollection;
|
||||
|
||||
this.slots = {
|
||||
@@ -279,7 +278,7 @@ export class Doc {
|
||||
yBlockUpdated: this._blockCollection.slots.yBlockUpdated,
|
||||
};
|
||||
|
||||
this._crud = crud;
|
||||
this._crud = new DocCRUD(this._yBlocks, blockCollection.schema);
|
||||
this._schema = schema;
|
||||
this._readonly = readonly;
|
||||
if (query) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||
import type {
|
||||
PeekOptions,
|
||||
PeekViewService,
|
||||
@@ -17,8 +16,9 @@ import {
|
||||
type ThemeExtension,
|
||||
toast,
|
||||
} from '@blocksuite/blocks';
|
||||
import { Slot } from '@blocksuite/global/utils';
|
||||
import type { AffineEditorContainer } from '@blocksuite/presets';
|
||||
import { type DocCollection, Slot } from '@blocksuite/store';
|
||||
import { type DocCollection } from '@blocksuite/store';
|
||||
import { signal } from '@preact/signals-core';
|
||||
import type { TemplateResult } from 'lit';
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
PaymentRequiredError,
|
||||
UnauthorizedError,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import { Slot } from '@blocksuite/affine/store';
|
||||
import { Slot } from '@blocksuite/affine/global/utils';
|
||||
import { captureException } from '@sentry/react';
|
||||
|
||||
import type { ChatContextValue } from './chat-panel/chat-context';
|
||||
|
||||
+2
-1
@@ -3,13 +3,14 @@ import {
|
||||
type NoteBlockModel,
|
||||
NoteDisplayMode,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import { Slot } from '@blocksuite/affine/global/utils';
|
||||
import type {
|
||||
AffineEditorContainer,
|
||||
DocTitle,
|
||||
EdgelessEditor,
|
||||
PageEditor,
|
||||
} from '@blocksuite/affine/presets';
|
||||
import { type BlockModel, type Doc, Slot } from '@blocksuite/affine/store';
|
||||
import { type BlockModel, type Doc } from '@blocksuite/affine/store';
|
||||
import clsx from 'clsx';
|
||||
import type React from 'react';
|
||||
import {
|
||||
|
||||
Reference in New Issue
Block a user