mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-22 08:47:10 +08:00
refactor(editor): cleanup dead code (#9300)
This commit is contained in:
@@ -12,7 +12,6 @@ import type {
|
|||||||
import type { listToParagraphCommand } from './commands/list-to-paragraph.js';
|
import type { listToParagraphCommand } from './commands/list-to-paragraph.js';
|
||||||
import type { splitListCommand } from './commands/split-list.js';
|
import type { splitListCommand } from './commands/split-list.js';
|
||||||
import { ListBlockComponent } from './list-block.js';
|
import { ListBlockComponent } from './list-block.js';
|
||||||
import type { ListBlockService } from './list-service.js';
|
|
||||||
|
|
||||||
export function effects() {
|
export function effects() {
|
||||||
customElements.define('affine-list', ListBlockComponent);
|
customElements.define('affine-list', ListBlockComponent);
|
||||||
@@ -20,10 +19,6 @@ export function effects() {
|
|||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
namespace BlockSuite {
|
namespace BlockSuite {
|
||||||
interface BlockServices {
|
|
||||||
'affine:list': ListBlockService;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CommandContext {
|
interface CommandContext {
|
||||||
listConvertedId?: string;
|
listConvertedId?: string;
|
||||||
indentContext?: IndentContext;
|
indentContext?: IndentContext;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
export * from './adapters/index.js';
|
export * from './adapters/index.js';
|
||||||
export { correctNumberedListsOrderToPrev } from './commands/utils';
|
export { correctNumberedListsOrderToPrev } from './commands/utils';
|
||||||
export * from './list-block.js';
|
export * from './list-block.js';
|
||||||
export * from './list-service.js';
|
|
||||||
export * from './list-spec.js';
|
export * from './list-spec.js';
|
||||||
|
|||||||
@@ -24,14 +24,10 @@ import { classMap } from 'lit/directives/class-map.js';
|
|||||||
import { styleMap } from 'lit/directives/style-map.js';
|
import { styleMap } from 'lit/directives/style-map.js';
|
||||||
|
|
||||||
import { correctNumberedListsOrderToPrev } from './commands/utils.js';
|
import { correctNumberedListsOrderToPrev } from './commands/utils.js';
|
||||||
import type { ListBlockService } from './list-service.js';
|
|
||||||
import { listBlockStyles } from './styles.js';
|
import { listBlockStyles } from './styles.js';
|
||||||
import { getListIcon } from './utils/get-list-icon.js';
|
import { getListIcon } from './utils/get-list-icon.js';
|
||||||
|
|
||||||
export class ListBlockComponent extends CaptionedBlockComponent<
|
export class ListBlockComponent extends CaptionedBlockComponent<ListBlockModel> {
|
||||||
ListBlockModel,
|
|
||||||
ListBlockService
|
|
||||||
> {
|
|
||||||
static override styles = listBlockStyles;
|
static override styles = listBlockStyles;
|
||||||
|
|
||||||
private _inlineRangeProvider: InlineRangeProvider | null = null;
|
private _inlineRangeProvider: InlineRangeProvider | null = null;
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -9,11 +9,9 @@ import { literal } from 'lit/static-html.js';
|
|||||||
import { ListBlockAdapterExtensions } from './adapters/extension.js';
|
import { ListBlockAdapterExtensions } from './adapters/extension.js';
|
||||||
import { commands } from './commands/index.js';
|
import { commands } from './commands/index.js';
|
||||||
import { ListKeymapExtension, ListTextKeymapExtension } from './list-keymap.js';
|
import { ListKeymapExtension, ListTextKeymapExtension } from './list-keymap.js';
|
||||||
import { ListBlockService } from './list-service.js';
|
|
||||||
|
|
||||||
export const ListBlockSpec: ExtensionType[] = [
|
export const ListBlockSpec: ExtensionType[] = [
|
||||||
FlavourExtension('affine:list'),
|
FlavourExtension('affine:list'),
|
||||||
ListBlockService,
|
|
||||||
CommandExtension(commands),
|
CommandExtension(commands),
|
||||||
BlockViewExtension('affine:list', literal`affine-list`),
|
BlockViewExtension('affine:list', literal`affine-list`),
|
||||||
ListKeymapExtension,
|
ListKeymapExtension,
|
||||||
|
|||||||
@@ -5,10 +5,7 @@ import {
|
|||||||
} from '@blocksuite/block-std';
|
} from '@blocksuite/block-std';
|
||||||
import { literal } from 'lit/static-html.js';
|
import { literal } from 'lit/static-html.js';
|
||||||
|
|
||||||
import { DataViewBlockService } from './database-service.js';
|
|
||||||
|
|
||||||
export const DataViewBlockSpec: ExtensionType[] = [
|
export const DataViewBlockSpec: ExtensionType[] = [
|
||||||
FlavourExtension('affine:data-view'),
|
FlavourExtension('affine:data-view'),
|
||||||
DataViewBlockService,
|
|
||||||
BlockViewExtension('affine:data-view', literal`affine-data-view`),
|
BlockViewExtension('affine:data-view', literal`affine-data-view`),
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -271,7 +271,6 @@ import { effects as blockSurfaceRefEffects } from './surface-ref-block/effects.j
|
|||||||
import {
|
import {
|
||||||
EdgelessSurfaceRefBlockComponent,
|
EdgelessSurfaceRefBlockComponent,
|
||||||
SurfaceRefBlockComponent,
|
SurfaceRefBlockComponent,
|
||||||
type SurfaceRefBlockService,
|
|
||||||
} from './surface-ref-block/index.js';
|
} from './surface-ref-block/index.js';
|
||||||
import { SurfaceRefGenericBlockPortal } from './surface-ref-block/portal/generic-block.js';
|
import { SurfaceRefGenericBlockPortal } from './surface-ref-block/portal/generic-block.js';
|
||||||
import { SurfaceRefNotePortal } from './surface-ref-block/portal/note.js';
|
import { SurfaceRefNotePortal } from './surface-ref-block/portal/note.js';
|
||||||
@@ -611,7 +610,6 @@ declare global {
|
|||||||
'affine:bookmark': BookmarkBlockService;
|
'affine:bookmark': BookmarkBlockService;
|
||||||
'affine:database': DatabaseBlockService;
|
'affine:database': DatabaseBlockService;
|
||||||
'affine:image': ImageBlockService;
|
'affine:image': ImageBlockService;
|
||||||
'affine:surface-ref': SurfaceRefBlockService;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
export * from './surface-ref-block.js';
|
export * from './surface-ref-block.js';
|
||||||
export * from './surface-ref-block-edgeless.js';
|
export * from './surface-ref-block-edgeless.js';
|
||||||
export * from './surface-ref-service.js';
|
|
||||||
export {
|
export {
|
||||||
EdgelessSurfaceRefBlockSpec,
|
EdgelessSurfaceRefBlockSpec,
|
||||||
PageSurfaceRefBlockSpec,
|
PageSurfaceRefBlockSpec,
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
||||||
import {
|
import {
|
||||||
type SurfaceBlockModel,
|
type SurfaceBlockModel,
|
||||||
SurfaceElementModel,
|
SurfaceElementModel,
|
||||||
@@ -46,7 +45,6 @@ import { styleMap } from 'lit/directives/style-map.js';
|
|||||||
import { SpecProvider } from '../_specs/index.js';
|
import { SpecProvider } from '../_specs/index.js';
|
||||||
import type { EdgelessRootPreviewBlockComponent } from '../root-block/edgeless/edgeless-root-preview-block.js';
|
import type { EdgelessRootPreviewBlockComponent } from '../root-block/edgeless/edgeless-root-preview-block.js';
|
||||||
import { EdgelessRootService } from '../root-block/index.js';
|
import { EdgelessRootService } from '../root-block/index.js';
|
||||||
import type { SurfaceRefBlockService } from './surface-ref-service.js';
|
|
||||||
import { noContentPlaceholder } from './utils.js';
|
import { noContentPlaceholder } from './utils.js';
|
||||||
|
|
||||||
const REF_LABEL_ICON = {
|
const REF_LABEL_ICON = {
|
||||||
@@ -66,10 +64,7 @@ const NO_CONTENT_REASON = {
|
|||||||
} as Record<string, string>;
|
} as Record<string, string>;
|
||||||
|
|
||||||
@Peekable()
|
@Peekable()
|
||||||
export class SurfaceRefBlockComponent extends BlockComponent<
|
export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockModel> {
|
||||||
SurfaceRefBlockModel,
|
|
||||||
SurfaceRefBlockService
|
|
||||||
> {
|
|
||||||
static override styles = css`
|
static override styles = css`
|
||||||
.affine-surface-ref {
|
.affine-surface-ref {
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -599,8 +594,6 @@ export class SurfaceRefBlockComponent extends BlockComponent<
|
|||||||
|
|
||||||
if (!this._shouldRender) return;
|
if (!this._shouldRender) return;
|
||||||
|
|
||||||
const service = this.service;
|
|
||||||
assertExists(service, `Surface ref block must run with its service.`);
|
|
||||||
this._initHotkey();
|
this._initHotkey();
|
||||||
this._initSpec();
|
this._initSpec();
|
||||||
this._initReferencedModel();
|
this._initReferencedModel();
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -8,11 +8,9 @@ import {
|
|||||||
import { literal } from 'lit/static-html.js';
|
import { literal } from 'lit/static-html.js';
|
||||||
|
|
||||||
import { commands } from './commands.js';
|
import { commands } from './commands.js';
|
||||||
import { SurfaceRefBlockService } from './surface-ref-service.js';
|
|
||||||
|
|
||||||
export const PageSurfaceRefBlockSpec: ExtensionType[] = [
|
export const PageSurfaceRefBlockSpec: ExtensionType[] = [
|
||||||
FlavourExtension('affine:surface-ref'),
|
FlavourExtension('affine:surface-ref'),
|
||||||
SurfaceRefBlockService,
|
|
||||||
CommandExtension(commands),
|
CommandExtension(commands),
|
||||||
BlockViewExtension('affine:surface-ref', literal`affine-surface-ref`),
|
BlockViewExtension('affine:surface-ref', literal`affine-surface-ref`),
|
||||||
WidgetViewMapExtension('affine:surface-ref', {
|
WidgetViewMapExtension('affine:surface-ref', {
|
||||||
@@ -22,7 +20,6 @@ export const PageSurfaceRefBlockSpec: ExtensionType[] = [
|
|||||||
|
|
||||||
export const EdgelessSurfaceRefBlockSpec: ExtensionType[] = [
|
export const EdgelessSurfaceRefBlockSpec: ExtensionType[] = [
|
||||||
FlavourExtension('affine:surface-ref'),
|
FlavourExtension('affine:surface-ref'),
|
||||||
SurfaceRefBlockService,
|
|
||||||
BlockViewExtension(
|
BlockViewExtension(
|
||||||
'affine:surface-ref',
|
'affine:surface-ref',
|
||||||
literal`affine-edgeless-surface-ref`
|
literal`affine-edgeless-surface-ref`
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ export class WidgetComponent<
|
|||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
this.std.view.setWidget(this);
|
this.std.view.setWidget(this);
|
||||||
|
|
||||||
this.service.specSlots.widgetConnected.emit({
|
this.service?.specSlots.widgetConnected.emit({
|
||||||
service: this.service,
|
service: this.service,
|
||||||
component: this,
|
component: this,
|
||||||
});
|
});
|
||||||
@@ -83,7 +83,7 @@ export class WidgetComponent<
|
|||||||
override disconnectedCallback() {
|
override disconnectedCallback() {
|
||||||
super.disconnectedCallback();
|
super.disconnectedCallback();
|
||||||
this.std?.view.deleteWidget(this);
|
this.std?.view.deleteWidget(this);
|
||||||
this.service.specSlots.widgetDisconnected.emit({
|
this.service?.specSlots.widgetDisconnected.emit({
|
||||||
service: this.service,
|
service: this.service,
|
||||||
component: this,
|
component: this,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -3,21 +3,9 @@ import {
|
|||||||
PageEditorBlockSpecs,
|
PageEditorBlockSpecs,
|
||||||
} from '@blocksuite/blocks';
|
} from '@blocksuite/blocks';
|
||||||
|
|
||||||
import { getCustomAttachmentSpecs } from './custom-attachment/custom-attachment.js';
|
|
||||||
|
|
||||||
const params = new URLSearchParams(location.search);
|
|
||||||
|
|
||||||
export function getExampleSpecs() {
|
export function getExampleSpecs() {
|
||||||
const type = params.get('exampleSpec');
|
const pageModeSpecs = PageEditorBlockSpecs;
|
||||||
|
const edgelessModeSpecs = EdgelessEditorBlockSpecs;
|
||||||
let pageModeSpecs = PageEditorBlockSpecs;
|
|
||||||
let edgelessModeSpecs = EdgelessEditorBlockSpecs;
|
|
||||||
|
|
||||||
if (type === 'attachment') {
|
|
||||||
const specs = getCustomAttachmentSpecs();
|
|
||||||
pageModeSpecs = specs.pageModeSpecs;
|
|
||||||
edgelessModeSpecs = specs.edgelessModeSpecs;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pageModeSpecs,
|
pageModeSpecs,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { AIChatBlockSpec } from '@affine/core/blocksuite/presets/blocks/ai-chat-
|
|||||||
import type { ExtensionType } from '@blocksuite/affine/block-std';
|
import type { ExtensionType } from '@blocksuite/affine/block-std';
|
||||||
import {
|
import {
|
||||||
AdapterFactoryExtensions,
|
AdapterFactoryExtensions,
|
||||||
|
AttachmentBlockSpec,
|
||||||
BookmarkBlockSpec,
|
BookmarkBlockSpec,
|
||||||
CodeBlockSpec,
|
CodeBlockSpec,
|
||||||
DatabaseBlockSpec,
|
DatabaseBlockSpec,
|
||||||
@@ -28,8 +29,6 @@ import {
|
|||||||
RichTextExtensions,
|
RichTextExtensions,
|
||||||
} from '@blocksuite/affine/blocks';
|
} from '@blocksuite/affine/blocks';
|
||||||
|
|
||||||
import { CustomAttachmentBlockSpec } from './custom/attachment-block';
|
|
||||||
|
|
||||||
const CommonBlockSpecs: ExtensionType[] = [
|
const CommonBlockSpecs: ExtensionType[] = [
|
||||||
RefNodeSlotsExtension(),
|
RefNodeSlotsExtension(),
|
||||||
EditPropsStore,
|
EditPropsStore,
|
||||||
@@ -47,8 +46,8 @@ const CommonBlockSpecs: ExtensionType[] = [
|
|||||||
EmbedHtmlBlockSpec,
|
EmbedHtmlBlockSpec,
|
||||||
EmbedSyncedDocBlockSpec,
|
EmbedSyncedDocBlockSpec,
|
||||||
EmbedLinkedDocBlockSpec,
|
EmbedLinkedDocBlockSpec,
|
||||||
|
AttachmentBlockSpec,
|
||||||
// special
|
// special
|
||||||
CustomAttachmentBlockSpec,
|
|
||||||
AdapterFactoryExtensions,
|
AdapterFactoryExtensions,
|
||||||
].flat();
|
].flat();
|
||||||
|
|
||||||
|
|||||||
@@ -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')]
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
Reference in New Issue
Block a user