Support explicit empty slot drop zones in shared editor
Quality / quality (ubuntu-latest) (push) Failing after 22s
Quality / quality (windows-latest) (push) Canceled after 0s

This commit is contained in:
Clintchiz committed 2026-09-05 16:28:11 +05:30
1 parent 7110e1a7f1
commit 0f8d10eb91
7 files changed
+100 -11

No files matched your search

+32 -3
View File
@@ -36,8 +36,9 @@ function fixture(overrides: Partial<DndManagerOptions> = {}) {
const create = new Function(
"DragDropManager",
"Sortable",
"Droppable",
compiled + ";return createDndManager;",
)(Backend, Sortable);
)(Backend, Sortable, Sortable);
const manager: DndManager = create({
onMoveIntent: () => true,
announce: (event: DndAnnouncement) => announcements.push(event),
@@ -54,8 +55,8 @@ function fixture(overrides: Partial<DndManagerOptions> = {}) {
announcements,
instances,
start: (id: string) => listeners.dragstart!(event(id)),
end: (id: string) => listeners.dragend!(event(id)),
over: (target: { group: string; index: number }) => {
end: (id: string, target?: { id: string }) => listeners.dragend!({ ...event(id), operation: { ...event(id).operation, target } }),
over: (target: { id?: string; group?: string; index?: number }) => {
let prevented = false;
listeners.dragover!({
...event("first"),
@@ -93,6 +94,34 @@ test("late drop resolution cannot clear or announce a newer gesture", async () =
]);
});
test("empty drop zones use explicit locations for acceptance and commit", async () => {
const commits: unknown[] = [];
const f = fixture({ accept: (_ids, to) => to.group === "empty", onMoveIntent: intent => { commits.push(intent.to); } });
const registration = { id: "zone", group: "empty", index: 0, element: {} as HTMLElement };
const cleanup = f.manager.registerDropZone(registration);
f.start("block");
expect(f.over({ id: "zone" })).toBe(false);
expect(f.announcements.at(-1)?.location).toEqual({ group: "empty", index: 0 });
await f.end("block", { id: "zone" });
expect(commits).toEqual([{ group: "empty", index: 0 }]);
expect(() => f.manager.registerSortable(registration)).toThrow("Duplicate");
cleanup();
f.manager.registerDropZone(registration);
cleanup();
expect(() => f.manager.registerDropZone(registration)).toThrow("Duplicate");
f.manager.destroy(); f.manager.destroy();
expect(f.instances.map(instance => instance.destroyed)).toEqual([1, 1]);
expect(() => f.manager.registerDropZone(registration)).toThrow("destruction");
});
test("invalid drop zone indices are rejected before backend registration", () => {
const f = fixture();
for (const index of [-1, 0.5, Infinity, Number.MAX_SAFE_INTEGER + 1]) {
expect(() => f.manager.registerDropZone({ id: "zone", group: "empty", index, element: {} as HTMLElement })).toThrow("index");
}
expect(f.instances).toEqual([]);
});
test("hover acceptance checks the proposed target instead of the source's old group", () => {
const f = fixture({ accept: (_ids, to) => to.group === "allowed" });
f.start("first");