refactor(editor): cleanup dead code (#9300)

This commit is contained in:
Saul-Mirone
2024-12-25 07:48:00 +00:00
parent 16c59d96d9
commit 7c84545647
17 changed files with 8 additions and 174 deletions

View File

@@ -12,7 +12,6 @@ import type {
import type { listToParagraphCommand } from './commands/list-to-paragraph.js';
import type { splitListCommand } from './commands/split-list.js';
import { ListBlockComponent } from './list-block.js';
import type { ListBlockService } from './list-service.js';
export function effects() {
customElements.define('affine-list', ListBlockComponent);
@@ -20,10 +19,6 @@ export function effects() {
declare global {
namespace BlockSuite {
interface BlockServices {
'affine:list': ListBlockService;
}
interface CommandContext {
listConvertedId?: string;
indentContext?: IndentContext;

View File

@@ -1,5 +1,4 @@
export * from './adapters/index.js';
export { correctNumberedListsOrderToPrev } from './commands/utils';
export * from './list-block.js';
export * from './list-service.js';
export * from './list-spec.js';

View File

@@ -24,14 +24,10 @@ import { classMap } from 'lit/directives/class-map.js';
import { styleMap } from 'lit/directives/style-map.js';
import { correctNumberedListsOrderToPrev } from './commands/utils.js';
import type { ListBlockService } from './list-service.js';
import { listBlockStyles } from './styles.js';
import { getListIcon } from './utils/get-list-icon.js';
export class ListBlockComponent extends CaptionedBlockComponent<
ListBlockModel,
ListBlockService
> {
export class ListBlockComponent extends CaptionedBlockComponent<ListBlockModel> {
static override styles = listBlockStyles;
private _inlineRangeProvider: InlineRangeProvider | null = null;

View File

@@ -1,6 +0,0 @@
import { ListBlockSchema } from '@blocksuite/affine-model';
import { BlockService } from '@blocksuite/block-std';
export class ListBlockService extends BlockService {
static override readonly flavour = ListBlockSchema.model.flavour;
}

View File

@@ -9,11 +9,9 @@ import { literal } from 'lit/static-html.js';
import { ListBlockAdapterExtensions } from './adapters/extension.js';
import { commands } from './commands/index.js';
import { ListKeymapExtension, ListTextKeymapExtension } from './list-keymap.js';
import { ListBlockService } from './list-service.js';
export const ListBlockSpec: ExtensionType[] = [
FlavourExtension('affine:list'),
ListBlockService,
CommandExtension(commands),
BlockViewExtension('affine:list', literal`affine-list`),
ListKeymapExtension,

View File

@@ -5,10 +5,7 @@ import {
} from '@blocksuite/block-std';
import { literal } from 'lit/static-html.js';
import { DataViewBlockService } from './database-service.js';
export const DataViewBlockSpec: ExtensionType[] = [
FlavourExtension('affine:data-view'),
DataViewBlockService,
BlockViewExtension('affine:data-view', literal`affine-data-view`),
];

View File

@@ -1,13 +0,0 @@
import { BlockService } from '@blocksuite/block-std';
import { DatabaseSelection } from '@blocksuite/data-view';
import { DataViewBlockSchema } from './data-view-model.js';
export class DataViewBlockService extends BlockService {
static override readonly flavour = DataViewBlockSchema.model.flavour;
override mounted(): void {
super.mounted();
this.selectionManager.register(DatabaseSelection);
}
}

View File

@@ -271,7 +271,6 @@ import { effects as blockSurfaceRefEffects } from './surface-ref-block/effects.j
import {
EdgelessSurfaceRefBlockComponent,
SurfaceRefBlockComponent,
type SurfaceRefBlockService,
} from './surface-ref-block/index.js';
import { SurfaceRefGenericBlockPortal } from './surface-ref-block/portal/generic-block.js';
import { SurfaceRefNotePortal } from './surface-ref-block/portal/note.js';
@@ -611,7 +610,6 @@ declare global {
'affine:bookmark': BookmarkBlockService;
'affine:database': DatabaseBlockService;
'affine:image': ImageBlockService;
'affine:surface-ref': SurfaceRefBlockService;
}
}
}

View File

@@ -1,6 +1,5 @@
export * from './surface-ref-block.js';
export * from './surface-ref-block-edgeless.js';
export * from './surface-ref-service.js';
export {
EdgelessSurfaceRefBlockSpec,
PageSurfaceRefBlockSpec,

View File

@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import {
type SurfaceBlockModel,
SurfaceElementModel,
@@ -46,7 +45,6 @@ import { styleMap } from 'lit/directives/style-map.js';
import { SpecProvider } from '../_specs/index.js';
import type { EdgelessRootPreviewBlockComponent } from '../root-block/edgeless/edgeless-root-preview-block.js';
import { EdgelessRootService } from '../root-block/index.js';
import type { SurfaceRefBlockService } from './surface-ref-service.js';
import { noContentPlaceholder } from './utils.js';
const REF_LABEL_ICON = {
@@ -66,10 +64,7 @@ const NO_CONTENT_REASON = {
} as Record<string, string>;
@Peekable()
export class SurfaceRefBlockComponent extends BlockComponent<
SurfaceRefBlockModel,
SurfaceRefBlockService
> {
export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockModel> {
static override styles = css`
.affine-surface-ref {
position: relative;
@@ -599,8 +594,6 @@ export class SurfaceRefBlockComponent extends BlockComponent<
if (!this._shouldRender) return;
const service = this.service;
assertExists(service, `Surface ref block must run with its service.`);
this._initHotkey();
this._initSpec();
this._initReferencedModel();

View File

@@ -1,6 +0,0 @@
import { SurfaceRefBlockSchema } from '@blocksuite/affine-model';
import { BlockService } from '@blocksuite/block-std';
export class SurfaceRefBlockService extends BlockService {
static override readonly flavour = SurfaceRefBlockSchema.model.flavour;
}

View File

@@ -8,11 +8,9 @@ import {
import { literal } from 'lit/static-html.js';
import { commands } from './commands.js';
import { SurfaceRefBlockService } from './surface-ref-service.js';
export const PageSurfaceRefBlockSpec: ExtensionType[] = [
FlavourExtension('affine:surface-ref'),
SurfaceRefBlockService,
CommandExtension(commands),
BlockViewExtension('affine:surface-ref', literal`affine-surface-ref`),
WidgetViewMapExtension('affine:surface-ref', {
@@ -22,7 +20,6 @@ export const PageSurfaceRefBlockSpec: ExtensionType[] = [
export const EdgelessSurfaceRefBlockSpec: ExtensionType[] = [
FlavourExtension('affine:surface-ref'),
SurfaceRefBlockService,
BlockViewExtension(
'affine:surface-ref',
literal`affine-edgeless-surface-ref`

View File

@@ -74,7 +74,7 @@ export class WidgetComponent<
super.connectedCallback();
this.std.view.setWidget(this);
this.service.specSlots.widgetConnected.emit({
this.service?.specSlots.widgetConnected.emit({
service: this.service,
component: this,
});
@@ -83,7 +83,7 @@ export class WidgetComponent<
override disconnectedCallback() {
super.disconnectedCallback();
this.std?.view.deleteWidget(this);
this.service.specSlots.widgetDisconnected.emit({
this.service?.specSlots.widgetDisconnected.emit({
service: this.service,
component: this,
});

View File

@@ -1,50 +0,0 @@
import {
BlockFlavourIdentifier,
BlockServiceIdentifier,
type ExtensionType,
StdIdentifier,
} from '@blocksuite/block-std';
import {
AttachmentBlockService,
EdgelessEditorBlockSpecs,
PageEditorBlockSpecs,
} from '@blocksuite/blocks';
class CustomAttachmentBlockService extends AttachmentBlockService {
override mounted(): void {
super.mounted();
this.maxFileSize = 100 * 1000 * 1000; // 100MB
}
}
export function getCustomAttachmentSpecs() {
const pageModeSpecs: ExtensionType[] = [
...PageEditorBlockSpecs,
{
setup: di => {
di.override(
BlockServiceIdentifier('affine:attachment'),
CustomAttachmentBlockService,
[StdIdentifier, BlockFlavourIdentifier('affine:attachment')]
);
},
},
];
const edgelessModeSpecs: ExtensionType[] = [
...EdgelessEditorBlockSpecs,
{
setup: di => {
di.override(
BlockServiceIdentifier('affine:attachment'),
CustomAttachmentBlockService,
[StdIdentifier, BlockFlavourIdentifier('affine:attachment')]
);
},
},
];
return {
pageModeSpecs,
edgelessModeSpecs,
};
}

View File

@@ -3,21 +3,9 @@ import {
PageEditorBlockSpecs,
} from '@blocksuite/blocks';
import { getCustomAttachmentSpecs } from './custom-attachment/custom-attachment.js';
const params = new URLSearchParams(location.search);
export function getExampleSpecs() {
const type = params.get('exampleSpec');
let pageModeSpecs = PageEditorBlockSpecs;
let edgelessModeSpecs = EdgelessEditorBlockSpecs;
if (type === 'attachment') {
const specs = getCustomAttachmentSpecs();
pageModeSpecs = specs.pageModeSpecs;
edgelessModeSpecs = specs.edgelessModeSpecs;
}
const pageModeSpecs = PageEditorBlockSpecs;
const edgelessModeSpecs = EdgelessEditorBlockSpecs;
return {
pageModeSpecs,

View File

@@ -7,6 +7,7 @@ import { AIChatBlockSpec } from '@affine/core/blocksuite/presets/blocks/ai-chat-
import type { ExtensionType } from '@blocksuite/affine/block-std';
import {
AdapterFactoryExtensions,
AttachmentBlockSpec,
BookmarkBlockSpec,
CodeBlockSpec,
DatabaseBlockSpec,
@@ -28,8 +29,6 @@ import {
RichTextExtensions,
} from '@blocksuite/affine/blocks';
import { CustomAttachmentBlockSpec } from './custom/attachment-block';
const CommonBlockSpecs: ExtensionType[] = [
RefNodeSlotsExtension(),
EditPropsStore,
@@ -47,8 +46,8 @@ const CommonBlockSpecs: ExtensionType[] = [
EmbedHtmlBlockSpec,
EmbedSyncedDocBlockSpec,
EmbedLinkedDocBlockSpec,
AttachmentBlockSpec,
// special
CustomAttachmentBlockSpec,
AdapterFactoryExtensions,
].flat();

View File

@@ -1,50 +0,0 @@
import {
BlockFlavourIdentifier,
BlockServiceIdentifier,
type ExtensionType,
StdIdentifier,
} from '@blocksuite/affine/block-std';
import {
AttachmentBlockService,
AttachmentBlockSpec,
ImageBlockService,
} from '@blocksuite/affine/blocks';
// bytes.parse('2GB')
const MAX_FILE_SIZE = 2147483648;
class CustomAttachmentBlockService extends AttachmentBlockService {
override mounted(): void {
// blocksuite default max file size is 10MB, we override it to 2GB
// but the real place to limit blob size is CloudQuotaModal / LocalQuotaModal
this.maxFileSize = MAX_FILE_SIZE;
super.mounted();
}
}
class CustomImageBlockService extends ImageBlockService {
override mounted(): void {
// blocksuite default max file size is 10MB, we override it to 2GB
// but the real place to limit blob size is CloudQuotaModal / LocalQuotaModal
this.maxFileSize = MAX_FILE_SIZE;
super.mounted();
}
}
export const CustomAttachmentBlockSpec: ExtensionType[] = [
...AttachmentBlockSpec,
{
setup: di => {
di.override(
BlockServiceIdentifier('affine:attachment'),
CustomAttachmentBlockService,
[StdIdentifier, BlockFlavourIdentifier('affine:attachment')]
);
di.override(
BlockServiceIdentifier('affine:image'),
CustomImageBlockService,
[StdIdentifier, BlockFlavourIdentifier('affine:image')]
);
},
},
];