fix(dnd): validate proposed hover destinations
Quality / quality (ubuntu-latest) (push) Failing after 1s
Quality / quality (windows-latest) (push) Canceled after 0s

This commit is contained in:
Clintchiz committed 2026-09-05 15:09:08 +05:30
1 parent c1f4f42b21
commit 8bc8fe85c3
5 files changed
+42 -3

No files matched your search

+1 -1
View File
@@ -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": {
+17
View File
@@ -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,