mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00:00
fix: can not drag collapsed heading (#9272)
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
import {
|
||||
ParagraphBlockModel,
|
||||
ParagraphBlockSchema,
|
||||
} from '@blocksuite/affine-model';
|
||||
import { DragHandleConfigExtension } from '@blocksuite/affine-shared/services';
|
||||
import {
|
||||
calculateCollapsedSiblings,
|
||||
captureEventTarget,
|
||||
matchFlavours,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
|
||||
export const ParagraphDragHandleOption = DragHandleConfigExtension({
|
||||
flavour: ParagraphBlockSchema.model.flavour,
|
||||
onDragStart: ({ state, startDragging, anchorBlockId, editorHost }) => {
|
||||
if (!anchorBlockId) return false;
|
||||
|
||||
const element = captureEventTarget(state.raw.target);
|
||||
const dragByHandle = !!element?.closest('affine-drag-handle-widget');
|
||||
if (!dragByHandle) return false;
|
||||
|
||||
const block = editorHost.doc.getBlock(anchorBlockId);
|
||||
if (!block) return false;
|
||||
const model = block.model;
|
||||
if (
|
||||
matchFlavours(model, ['affine:paragraph']) &&
|
||||
model.type.startsWith('h') &&
|
||||
model.collapsed
|
||||
) {
|
||||
const collapsedSiblings = calculateCollapsedSiblings(model).flatMap(
|
||||
sibling => editorHost.view.getBlock(sibling.id) ?? []
|
||||
);
|
||||
const modelElement = editorHost.view.getBlock(anchorBlockId);
|
||||
if (!modelElement) return false;
|
||||
startDragging([modelElement, ...collapsedSiblings], state);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
onDragEnd: ({ draggingElements }) => {
|
||||
draggingElements
|
||||
.filter(el => matchFlavours(el.model, ['affine:paragraph']))
|
||||
.forEach(el => {
|
||||
const model = el.model;
|
||||
if (!(model instanceof ParagraphBlockModel)) return;
|
||||
model.collapsed = false;
|
||||
});
|
||||
|
||||
return false;
|
||||
},
|
||||
});
|
||||
@@ -8,7 +8,6 @@ import { literal } from 'lit/static-html.js';
|
||||
|
||||
import { ParagraphBlockAdapterExtensions } from './adapters/extension.js';
|
||||
import { commands } from './commands/index.js';
|
||||
import { ParagraphDragHandleOption } from './paragraph-drag-extension.js';
|
||||
import {
|
||||
ParagraphKeymapExtension,
|
||||
ParagraphTextKeymapExtension,
|
||||
@@ -22,6 +21,5 @@ export const ParagraphBlockSpec: ExtensionType[] = [
|
||||
BlockViewExtension('affine:paragraph', literal`affine-paragraph`),
|
||||
ParagraphTextKeymapExtension,
|
||||
ParagraphKeymapExtension,
|
||||
ParagraphDragHandleOption,
|
||||
ParagraphBlockAdapterExtensions,
|
||||
].flat();
|
||||
|
||||
Reference in New Issue
Block a user