From 92fb07ca2b70dc74eb854504bced40e0f5249f65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Tue, 20 Feb 2024 14:54:35 +0100 Subject: [PATCH] Sorter allow indication --- .../packages/core/sorter/sorter.controller.ts | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/sorter/sorter.controller.ts b/src/Umbraco.Web.UI.Client/src/packages/core/sorter/sorter.controller.ts index 8401ccfa5d..d41027d667 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/sorter/sorter.controller.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/sorter/sorter.controller.ts @@ -89,9 +89,9 @@ type INTERNAL_UmbSorterConfig = { onContainerChange?: (argument: { item: T; element: ElementType }) => void; onEnd?: (argument: { item: T; element: ElementType }) => void; itemHasNestedContainersResolver?: (element: HTMLElement) => boolean; - onDisallowed?: () => void; - onAllowed?: () => void; - onRequestDrop?: (argument: { item: T }) => boolean | void; + onDisallowed?: (argument: { item: T; element: ElementType }) => void; + onAllowed?: (argument: { item: T; element: ElementType }) => void; + onRequestDrop?: (argument: { item: T }) => boolean; resolveVerticalDirection?: (argument: resolveVerticalDirectionArgs) => void; performItemMove?: (argument: { item: T; newIndex: number; oldIndex: number }) => Promise | boolean; performItemInsert?: (argument: { item: T; newIndex: number }) => Promise | boolean; @@ -113,6 +113,9 @@ export type UmbSorterConfig = */ export class UmbSorterController implements UmbController { // + // The sorter who last indicated that it was okay or not okay to drop here: + static lastIndicationSorter?: UmbSorterController; + // A sorter that is requested to become the next sorter: static originalSorter?: UmbSorterController; static originalIndex?: number; @@ -144,8 +147,6 @@ export class UmbSorterController | null = null; - public get controllerAlias() { // We only support one Sorter Controller pr. Controller Host. return 'umbSorterController'; @@ -756,30 +757,26 @@ export class UmbSorterController; - if (controller.notifyRequestDrop({ item: item }) === true) { - controller.notifyAllowed(); + if (this.notifyRequestDrop({ item: item }) === true) { + this.notifyAllowed(); return true; } - controller.notifyDisallowed(); // This block is not accepted to we will indicate that its not allowed. + this.notifyDisallowed(); // This block is not accepted to we will indicate that its not allowed. return false; - */ - return true; } removeAllowIndication() { // Remove old indication: - if (this.#lastIndicationContainerCtrl !== null) { - this.#lastIndicationContainerCtrl.notifyAllowed(); + if (UmbSorterController.lastIndicationSorter) { + UmbSorterController.lastIndicationSorter.notifyAllowed(); } - this.#lastIndicationContainerCtrl = null; + UmbSorterController.lastIndicationSorter = undefined; } // TODO: Move auto scroll into its own class? @@ -844,12 +841,18 @@ export class UmbSorterController