mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-24 09:52:49 +08:00
refactor(editor): cleanup dead code (#11893)
This commit is contained in:
@@ -1,14 +1,7 @@
|
||||
import { Container } from '@blocksuite/global/di';
|
||||
|
||||
import {
|
||||
registerBlockSpecs,
|
||||
registerStoreSpecs,
|
||||
} from '../../extensions/register';
|
||||
import { testStoreExtensions } from './store';
|
||||
|
||||
registerStoreSpecs();
|
||||
registerBlockSpecs();
|
||||
|
||||
export function getProvider() {
|
||||
const container = new Container();
|
||||
const exts = testStoreExtensions;
|
||||
|
||||
@@ -63,8 +63,6 @@ import { effects as widgetToolbarEffects } from '@blocksuite/affine-widget-toolb
|
||||
import { effects as dataViewEffects } from '@blocksuite/data-view/effects';
|
||||
import { effects as stdEffects } from '@blocksuite/std/effects';
|
||||
|
||||
import { registerBlockSpecs } from './extensions';
|
||||
|
||||
export declare const _GLOBAL_:
|
||||
| typeof stdEffects
|
||||
| typeof dataViewEffects
|
||||
@@ -113,7 +111,6 @@ export declare const _GLOBAL_:
|
||||
| typeof fragmentOutlineEffects;
|
||||
|
||||
export function effects() {
|
||||
registerBlockSpecs();
|
||||
stdEffects();
|
||||
|
||||
dataViewEffects();
|
||||
|
||||
@@ -2,4 +2,3 @@ export * from './common';
|
||||
export * from './editor-specs';
|
||||
export * from './legacy-store';
|
||||
export * from './preview-specs';
|
||||
export * from './register';
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
import { SpecProvider } from '@blocksuite/affine-shared/utils';
|
||||
|
||||
import {
|
||||
EdgelessEditorBlockSpecs,
|
||||
PageEditorBlockSpecs,
|
||||
} from './editor-specs.js';
|
||||
import { StoreExtensions } from './legacy-store.js';
|
||||
import {
|
||||
PreviewEdgelessEditorBlockSpecs,
|
||||
PreviewPageEditorBlockSpecs,
|
||||
} from './preview-specs.js';
|
||||
|
||||
export function registerStoreSpecs() {
|
||||
SpecProvider._.addSpec('store', StoreExtensions);
|
||||
}
|
||||
|
||||
export function registerBlockSpecs() {
|
||||
SpecProvider._.addSpec('page', PageEditorBlockSpecs);
|
||||
SpecProvider._.addSpec('edgeless', EdgelessEditorBlockSpecs);
|
||||
SpecProvider._.addSpec('preview:page', PreviewPageEditorBlockSpecs);
|
||||
SpecProvider._.addSpec('preview:edgeless', PreviewEdgelessEditorBlockSpecs);
|
||||
}
|
||||
@@ -20,7 +20,6 @@ export * from './print-to-pdf';
|
||||
export * from './reference';
|
||||
export * from './reordering';
|
||||
export * from './signal';
|
||||
export * from './spec';
|
||||
export * from './string';
|
||||
export * from './title';
|
||||
export * from './url';
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from './spec-builder.js';
|
||||
export * from './spec-provider.js';
|
||||
@@ -1,39 +0,0 @@
|
||||
import type { ExtensionType } from '@blocksuite/store';
|
||||
|
||||
export class SpecBuilder {
|
||||
private _value: ExtensionType[];
|
||||
|
||||
get value() {
|
||||
return this._value;
|
||||
}
|
||||
|
||||
constructor(spec: ExtensionType[]) {
|
||||
this._value = [...spec];
|
||||
}
|
||||
|
||||
extend(extensions: ExtensionType[]) {
|
||||
this._value = [...this._value, ...extensions];
|
||||
return this;
|
||||
}
|
||||
|
||||
omit(target: ExtensionType) {
|
||||
this._value = this._value.filter(extension => extension !== target);
|
||||
return this;
|
||||
}
|
||||
|
||||
hasAll(target: ExtensionType[]) {
|
||||
return target.every(t => this._value.includes(t));
|
||||
}
|
||||
|
||||
hasOneOf(target: ExtensionType[]) {
|
||||
return target.some(t => this._value.includes(t));
|
||||
}
|
||||
|
||||
replace(target: ExtensionType[], newExtension: ExtensionType[]) {
|
||||
this._value = [
|
||||
...this._value.filter(extension => !target.includes(extension)),
|
||||
...newExtension,
|
||||
];
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
import { BlockSuiteError } from '@blocksuite/global/exceptions';
|
||||
import type { ExtensionType } from '@blocksuite/store';
|
||||
|
||||
import { SpecBuilder } from './spec-builder.js';
|
||||
|
||||
type SpecId =
|
||||
| 'store'
|
||||
| 'page'
|
||||
| 'edgeless'
|
||||
| 'preview:page'
|
||||
| 'preview:edgeless';
|
||||
|
||||
export class SpecProvider {
|
||||
static instance: SpecProvider;
|
||||
|
||||
private readonly specMap = new Map<SpecId, ExtensionType[]>();
|
||||
|
||||
private constructor() {}
|
||||
|
||||
static get _() {
|
||||
if (!SpecProvider.instance) {
|
||||
SpecProvider.instance = new SpecProvider();
|
||||
}
|
||||
return SpecProvider.instance;
|
||||
}
|
||||
|
||||
addSpec(id: SpecId, spec: ExtensionType[]) {
|
||||
if (!this.specMap.has(id)) {
|
||||
this.specMap.set(id, spec);
|
||||
}
|
||||
}
|
||||
|
||||
clearSpec(id: SpecId) {
|
||||
this.specMap.delete(id);
|
||||
}
|
||||
|
||||
extendSpec(id: SpecId, newSpec: ExtensionType[]) {
|
||||
const existingSpec = this.specMap.get(id);
|
||||
if (!existingSpec) {
|
||||
console.error(`Spec not found for ${id}`);
|
||||
return;
|
||||
}
|
||||
this.specMap.set(id, [...existingSpec, ...newSpec]);
|
||||
}
|
||||
|
||||
getSpec(id: SpecId) {
|
||||
const spec = this.specMap.get(id);
|
||||
if (!spec) {
|
||||
throw new BlockSuiteError(
|
||||
BlockSuiteError.ErrorCode.ValueNotExists,
|
||||
`Spec not found for ${id}`
|
||||
);
|
||||
}
|
||||
return new SpecBuilder(spec);
|
||||
}
|
||||
|
||||
hasSpec(id: SpecId) {
|
||||
return this.specMap.has(id);
|
||||
}
|
||||
|
||||
omitSpec(id: SpecId, targetSpec: ExtensionType) {
|
||||
const existingSpec = this.specMap.get(id);
|
||||
if (!existingSpec) {
|
||||
console.error(`Spec not found for ${id}`);
|
||||
return;
|
||||
}
|
||||
|
||||
this.specMap.set(
|
||||
id,
|
||||
existingSpec.filter(spec => spec !== targetSpec)
|
||||
);
|
||||
}
|
||||
|
||||
replaceSpec(id: SpecId, targetSpec: ExtensionType, newSpec: ExtensionType) {
|
||||
const existingSpec = this.specMap.get(id);
|
||||
if (!existingSpec) {
|
||||
console.error(`Spec not found for ${id}`);
|
||||
return;
|
||||
}
|
||||
|
||||
this.specMap.set(
|
||||
id,
|
||||
existingSpec.map(spec => (spec === targetSpec ? newSpec : spec))
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user