fix(dnd): validate proposed hover destinations
This commit is contained in:
1 parent
c1f4f42b21
commit
8bc8fe85c3
5 files changed
+42
-3
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@wrnexus/block-editor",
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.3",
|
||||
"type": "module",
|
||||
"description": "Hydrated accessible editor runtime for WRNexus block documents.",
|
||||
"exports": {
|
||||
|
||||
@@ -7,6 +7,10 @@ export interface MountedEditor {
|
||||
export interface MountEditorOptions {
|
||||
direction?: "ltr" | "rtl";
|
||||
announce?(announcement: DndAnnouncement): string;
|
||||
canMove?(intent: {
|
||||
nodeIds: string[];
|
||||
to: { parentId: string; slot: string; index: number };
|
||||
}): boolean;
|
||||
onMove(intent: {
|
||||
nodeIds: string[];
|
||||
to: { parentId: string; slot: string; index: number };
|
||||
@@ -37,6 +41,19 @@ export function mountBlockEditor(root: HTMLElement, options: MountEditorOptions)
|
||||
let gesture = 0;
|
||||
const groups = new Map<string, { parentId: string; slot: string }>();
|
||||
manager = createDndManager({
|
||||
accept(ids, location) {
|
||||
const destination = groups.get(String(location.group));
|
||||
return (
|
||||
!destroyed &&
|
||||
generation === currentGeneration &&
|
||||
!!destination &&
|
||||
(options.canMove?.({
|
||||
nodeIds: ids.map(String),
|
||||
to: { ...destination, index: location.index },
|
||||
}) ??
|
||||
true)
|
||||
);
|
||||
},
|
||||
direction:
|
||||
options.direction ?? (view.getComputedStyle(root).direction === "rtl" ? "rtl" : "ltr"),
|
||||
reducedMotion: view.matchMedia("(prefers-reduced-motion: reduce)").matches,
|
||||
|
||||
Reference in new issue
Block a user