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