refactor(editor): remove legacy dnd config (#9291)

This commit is contained in:
Saul-Mirone
2024-12-24 13:59:36 +00:00
parent 052d74896e
commit f5dea2a990
18 changed files with 43 additions and 385 deletions

View File

@@ -8,16 +8,8 @@ import {
EMBED_CARD_MIN_WIDTH,
EMBED_CARD_WIDTH,
} from '@blocksuite/affine-shared/consts';
import {
DocModeProvider,
DragHandleConfigExtension,
} from '@blocksuite/affine-shared/services';
import {
captureEventTarget,
convertDragPreviewDocToEdgeless,
convertDragPreviewEdgelessToDoc,
} from '@blocksuite/affine-shared/utils';
import { type BlockService, isGfxBlockComponent } from '@blocksuite/block-std';
import { DocModeProvider } from '@blocksuite/affine-shared/services';
import type { BlockService } from '@blocksuite/block-std';
import type { GfxCompatibleProps } from '@blocksuite/block-std/gfx';
import type { BlockModel } from '@blocksuite/store';
import type { TemplateResult } from 'lit';
@@ -26,48 +18,6 @@ import { query } from 'lit/decorators.js';
import { classMap } from 'lit/directives/class-map.js';
import { type StyleInfo, styleMap } from 'lit/directives/style-map.js';
export const EmbedDragHandleOption = DragHandleConfigExtension({
flavour: /affine:embed-*/,
edgeless: true,
onDragEnd: props => {
const { state, draggingElements } = props;
if (
draggingElements.length !== 1 ||
draggingElements[0].model.flavour.match(/affine:embed-*/) === null
)
return false;
const blockComponent = draggingElements[0] as EmbedBlockComponent;
const isInSurface = isGfxBlockComponent(blockComponent);
const target = captureEventTarget(state.raw.target);
const isTargetEdgelessContainer =
target?.classList.contains('edgeless-container');
if (isInSurface) {
const style = blockComponent._cardStyle;
const targetStyle =
style === 'vertical' || style === 'cube' ? 'horizontal' : style;
return convertDragPreviewEdgelessToDoc({
blockComponent,
style: targetStyle,
...props,
});
} else if (isTargetEdgelessContainer) {
const style = blockComponent._cardStyle;
return convertDragPreviewDocToEdgeless({
blockComponent,
cssSelector: '.embed-block-container',
width: EMBED_CARD_WIDTH[style],
height: EMBED_CARD_HEIGHT[style],
...props,
});
}
return false;
},
});
export class EmbedBlockComponent<
Model extends BlockModel<GfxCompatibleProps> = BlockModel<GfxCompatibleProps>,
Service extends BlockService = BlockService,

View File

@@ -1,6 +1,5 @@
import type { ExtensionType } from '@blocksuite/block-std';
import { EmbedDragHandleOption } from './common/embed-block-element.js';
import { EmbedFigmaBlockSpec } from './embed-figma-block/index.js';
import { EmbedGithubBlockSpec } from './embed-github-block/index.js';
import { EmbedHtmlBlockSpec } from './embed-html-block/index.js';
@@ -10,7 +9,6 @@ import { EmbedSyncedDocBlockSpec } from './embed-synced-doc-block/index.js';
import { EmbedYoutubeBlockSpec } from './embed-youtube-block/index.js';
export const EmbedExtensions: ExtensionType[] = [
EmbedDragHandleOption,
EmbedFigmaBlockSpec,
EmbedGithubBlockSpec,
EmbedHtmlBlockSpec,

View File

@@ -1,4 +1,5 @@
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

@@ -1,33 +1,6 @@
import { ListBlockSchema } from '@blocksuite/affine-model';
import { DragHandleConfigExtension } from '@blocksuite/affine-shared/services';
import { matchFlavours } from '@blocksuite/affine-shared/utils';
import type { BlockComponent } from '@blocksuite/block-std';
import { BlockService } from '@blocksuite/block-std';
import { correctNumberedListsOrderToPrev } from './commands/utils.js';
export class ListBlockService extends BlockService {
static override readonly flavour = ListBlockSchema.model.flavour;
}
export const ListDragHandleOption = DragHandleConfigExtension({
flavour: ListBlockSchema.model.flavour,
onDragEnd: ({ draggingElements, editorHost }) => {
draggingElements.forEach((el: BlockComponent) => {
const model = el.model;
const doc = el.doc;
if (matchFlavours(model, ['affine:list']) && model.type === 'numbered') {
const next = el.doc.getNext(model);
editorHost.updateComplete
.then(() => {
correctNumberedListsOrderToPrev(doc, model);
if (next) {
correctNumberedListsOrderToPrev(doc, next);
}
})
.catch(console.error);
}
});
return false;
},
});

View File

@@ -9,7 +9,7 @@ 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, ListDragHandleOption } from './list-service.js';
import { ListBlockService } from './list-service.js';
export const ListBlockSpec: ExtensionType[] = [
FlavourExtension('affine:list'),
@@ -18,6 +18,5 @@ export const ListBlockSpec: ExtensionType[] = [
BlockViewExtension('affine:list', literal`affine-list`),
ListKeymapExtension,
ListTextKeymapExtension,
ListDragHandleOption,
ListBlockAdapterExtensions,
].flat();