Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolving the issue of the draggable extension not working in the editor #5570

Merged
merged 2 commits into from Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions ui/packages/editor/docs/extension.md
Expand Up @@ -379,12 +379,14 @@ export interface DraggableItem {
slice,
insertPos,
node,
selection,
}: {
view: EditorView;
event: DragEvent;
slice: Slice;
insertPos: number;
node: Node;
selection: Selection;
}) => boolean | void;
allowPropagationDownward?: boolean; // 是否允许拖拽事件向内部传播,
}
Expand Down
8 changes: 5 additions & 3 deletions ui/packages/editor/src/extensions/draggable/index.ts
Expand Up @@ -470,11 +470,12 @@ const Draggable = Extension.create({
const pos = view.posAtCoords(coords);
if (!pos || !pos.pos) return false;

const nodePos = pos.inside > -1 ? pos.inside : pos.pos;

const nodeDom =
view.nodeDOM(pos.pos) ||
view.domAtPos(pos.pos)?.node ||
view.nodeDOM(nodePos) ||
view.domAtPos(nodePos)?.node ||
event.target;

if (!nodeDom) {
hideDragHandleDOM();
return false;
Expand Down Expand Up @@ -555,6 +556,7 @@ const Draggable = Extension.create({
slice,
insertPos,
node: activeNode?.node as Node,
selection: activeSelection,
});
if (typeof handleDrop === "boolean") {
isDisableDrop = handleDrop;
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/editor/src/types/index.ts
Expand Up @@ -5,6 +5,7 @@ import type {
Slice,
EditorState,
EditorView,
Selection,
} from "@/tiptap/pm";
import type { Component } from "vue";
export interface ToolbarItem {
Expand Down Expand Up @@ -120,12 +121,14 @@ export interface DraggableItem {
slice,
insertPos,
node,
selection,
}: {
view: EditorView;
event: DragEvent;
slice: Slice;
insertPos: number;
node: Node;
selection: Selection;
}) => boolean | void;
// allow drag-and-drop query propagation downward
allowPropagationDownward?: boolean;
Expand Down