Skip to content

Commit

Permalink
feat: Add exception tag list for global drag handle
Browse files Browse the repository at this point in the history
  • Loading branch information
HanCiHu committed Aug 25, 2024
1 parent 12b02d1 commit 445016b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export interface GlobalDragHandleOptions {
* If handle element is found, that element will be used as drag handle. If not, a default handle will be created
*/
dragHandleSelector?: string;

/**
* except tag for drag handle
*/
exceptTag: string[];
}
function absoluteRect(node: Element) {
const data = node.getBoundingClientRect();
Expand Down Expand Up @@ -143,7 +148,10 @@ export function DragHandlePlugin(

// if inline node is selected, e.g mention -> go to the parent node to select the whole node
// if table row is selected, go to the parent node to select the whole node
if ((selection as NodeSelection).node.type.isInline || (selection as NodeSelection).node.type.name === 'tableRow') {
if (
(selection as NodeSelection).node.type.isInline ||
(selection as NodeSelection).node.type.name === 'tableRow'
) {
let $pos = view.state.doc.resolve(selection.from);
selection = NodeSelection.create(view.state.doc, $pos.before());
}
Expand Down Expand Up @@ -265,10 +273,11 @@ export function DragHandlePlugin(
});

const notDragging = node?.closest('.not-draggable');
const exceptTags = options.exceptTag.concat(['ol', 'ul']).join(', ');

if (
!(node instanceof Element) ||
node.matches('ul, ol') ||
node.matches(exceptTags) ||
notDragging
) {
hideDragHandle();
Expand Down Expand Up @@ -359,6 +368,7 @@ const GlobalDragHandle = Extension.create({
return {
dragHandleWidth: 20,
scrollTreshold: 100,
exceptTag: ['ul', 'ol'],
};
},

Expand All @@ -369,6 +379,7 @@ const GlobalDragHandle = Extension.create({
dragHandleWidth: this.options.dragHandleWidth,
scrollTreshold: this.options.scrollTreshold,
dragHandleSelector: this.options.dragHandleSelector,
exceptTag: this.options.exceptTag,
}),
];
},
Expand Down

0 comments on commit 445016b

Please sign in to comment.