@cloudscape-design/board-components 3.0.58 → 3.0.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/internal/dnd-controller/__mocks__/controller.d.ts +3 -1
- package/internal/dnd-controller/__mocks__/controller.js +4 -0
- package/internal/dnd-controller/__mocks__/controller.js.map +1 -1
- package/internal/dnd-controller/controller.d.ts +1 -1
- package/internal/dnd-controller/controller.js.map +1 -1
- package/internal/environment.js +1 -1
- package/internal/environment.json +1 -1
- package/internal/manifest.json +1 -1
- package/package.json +1 -1
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { DragAndDropData, DragAndDropEvents } from "../controller";
|
|
1
|
+
import { AcquireData, DragAndDropData, DragAndDropEvents } from "../controller";
|
|
2
2
|
import { EventEmitter } from "../event-emitter";
|
|
3
3
|
declare class MockController extends EventEmitter<DragAndDropEvents> {
|
|
4
4
|
start(event: DragAndDropData): void;
|
|
5
5
|
update(event: DragAndDropData): void;
|
|
6
6
|
submit(): void;
|
|
7
7
|
discard(): void;
|
|
8
|
+
acquire(event: AcquireData): void;
|
|
8
9
|
}
|
|
9
10
|
export declare const mockController: MockController;
|
|
10
11
|
export declare function useDragSubscription<K extends keyof DragAndDropEvents>(event: K, handler: DragAndDropEvents[K]): void;
|
|
11
12
|
export declare const mockDraggable: any;
|
|
12
13
|
export declare function useDraggable(): any;
|
|
14
|
+
export declare function useDroppable(): void;
|
|
13
15
|
export {};
|
|
@@ -16,6 +16,9 @@ class MockController extends EventEmitter {
|
|
|
16
16
|
discard() {
|
|
17
17
|
this.emit("discard");
|
|
18
18
|
}
|
|
19
|
+
acquire(event) {
|
|
20
|
+
this.emit("acquire", event);
|
|
21
|
+
}
|
|
19
22
|
}
|
|
20
23
|
export const mockController = new MockController();
|
|
21
24
|
export function useDragSubscription(event, handler) {
|
|
@@ -31,4 +34,5 @@ export const mockDraggable = {
|
|
|
31
34
|
export function useDraggable() {
|
|
32
35
|
return mockDraggable;
|
|
33
36
|
}
|
|
37
|
+
export function useDroppable() { }
|
|
34
38
|
//# sourceMappingURL=controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../../src/internal/dnd-controller/__mocks__/controller.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,MAAM,cAAe,SAAQ,YAA+B;IACnD,KAAK,CAAC,KAAsB;QACjC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;IAEM,MAAM,CAAC,KAAsB;QAClC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;IAEM,MAAM;QACX,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtB,CAAC;IAEM,OAAO;QACZ,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACvB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC;AAEnD,MAAM,UAAU,mBAAmB,CAAoC,KAAQ,EAAE,OAA6B;IAC5G,SAAS,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE;IACd,gBAAgB,EAAE,EAAE,CAAC,EAAE,EAAE;IACzB,gBAAgB,EAAE,EAAE,CAAC,EAAE,EAAE;IACzB,iBAAiB,EAAE,EAAE,CAAC,EAAE,EAAE;IAC1B,aAAa,EAAE,EAAE,CAAC,EAAE,EAAE;CAChB,CAAC;AAET,MAAM,UAAU,YAAY;IAC1B,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useEffect } from \"react\";\nimport { vi } from \"vitest\";\nimport { DragAndDropData, DragAndDropEvents } from \"../controller\";\nimport { EventEmitter } from \"../event-emitter\";\n\nclass MockController extends EventEmitter<DragAndDropEvents> {\n public start(event: DragAndDropData) {\n this.emit(\"start\", event);\n }\n\n public update(event: DragAndDropData) {\n this.emit(\"update\", event);\n }\n\n public submit() {\n this.emit(\"submit\");\n }\n\n public discard() {\n this.emit(\"discard\");\n }\n}\n\nexport const mockController = new MockController();\n\nexport function useDragSubscription<K extends keyof DragAndDropEvents>(event: K, handler: DragAndDropEvents[K]) {\n useEffect(() => mockController.on(event, handler), [event, handler]);\n}\n\nexport const mockDraggable = {\n start: vi.fn(),\n updateTransition: vi.fn(),\n submitTransition: vi.fn(),\n discardTransition: vi.fn(),\n getDroppables: vi.fn(),\n} as any;\n\nexport function useDraggable() {\n return mockDraggable;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../../src/internal/dnd-controller/__mocks__/controller.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,MAAM,cAAe,SAAQ,YAA+B;IACnD,KAAK,CAAC,KAAsB;QACjC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;IAEM,MAAM,CAAC,KAAsB;QAClC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;IAEM,MAAM;QACX,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtB,CAAC;IAEM,OAAO;QACZ,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACvB,CAAC;IAEM,OAAO,CAAC,KAAkB;QAC/B,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC9B,CAAC;CACF;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC;AAEnD,MAAM,UAAU,mBAAmB,CAAoC,KAAQ,EAAE,OAA6B;IAC5G,SAAS,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE;IACd,gBAAgB,EAAE,EAAE,CAAC,EAAE,EAAE;IACzB,gBAAgB,EAAE,EAAE,CAAC,EAAE,EAAE;IACzB,iBAAiB,EAAE,EAAE,CAAC,EAAE,EAAE;IAC1B,aAAa,EAAE,EAAE,CAAC,EAAE,EAAE;CAChB,CAAC;AAET,MAAM,UAAU,YAAY;IAC1B,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,YAAY,KAAI,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useEffect } from \"react\";\nimport { vi } from \"vitest\";\nimport { AcquireData, DragAndDropData, DragAndDropEvents } from \"../controller\";\nimport { EventEmitter } from \"../event-emitter\";\n\nclass MockController extends EventEmitter<DragAndDropEvents> {\n public start(event: DragAndDropData) {\n this.emit(\"start\", event);\n }\n\n public update(event: DragAndDropData) {\n this.emit(\"update\", event);\n }\n\n public submit() {\n this.emit(\"submit\");\n }\n\n public discard() {\n this.emit(\"discard\");\n }\n\n public acquire(event: AcquireData) {\n this.emit(\"acquire\", event);\n }\n}\n\nexport const mockController = new MockController();\n\nexport function useDragSubscription<K extends keyof DragAndDropEvents>(event: K, handler: DragAndDropEvents[K]) {\n useEffect(() => mockController.on(event, handler), [event, handler]);\n}\n\nexport const mockDraggable = {\n start: vi.fn(),\n updateTransition: vi.fn(),\n submitTransition: vi.fn(),\n discardTransition: vi.fn(),\n getDroppables: vi.fn(),\n} as any;\n\nexport function useDraggable() {\n return mockDraggable;\n}\n\nexport function useDroppable() {}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../src/internal/dnd-controller/controller.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AAClF,OAAO,EAAa,SAAS,EAAE,MAAM,OAAO,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAwDhE,MAAM,qBAAsB,SAAQ,YAA+B;IAAnE;;QACU,eAAU,GAAG,IAAI,GAAG,EAAqB,CAAC;QAC1C,eAAU,GAAsB,IAAI,CAAC;IAgG/C,CAAC;IA9FC;;;;OAIG;IACI,KAAK,CAAC,UAAsB;QACjC,IAAI,CAAC,UAAU,GAAG,EAAE,GAAG,UAAU,EAAE,CAAC;QACpC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAC3E,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,WAAwB;QACpC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC,CAAC;IA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,EAAE;QACb,UAAU,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;QACvD,OAAO,GAAG,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IAClD,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;AACpC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { useStableCallback } from \"@cloudscape-design/component-toolkit/internal\";\nimport { ReactNode, useEffect } from \"react\";\nimport { BoardItemDefinitionBase, ItemId, Rect } from \"../interfaces\";\nimport { Coordinates } from \"../utils/coordinates\";\nimport { EventEmitter } from \"./event-emitter\";\nimport { getHoveredDroppables } from \"./get-hovered-droppables\";\n\ntype Item = BoardItemDefinitionBase<unknown>;\n\nexport type Operation = \"reorder\" | \"resize\" | \"insert\";\n\nexport type InteractionType = \"pointer\" | \"keyboard\";\n\n/**\n * Represents the relations between droppables and draggables.\n *\n * The `scale` function transforms draggable's width/height in relative units\n * to the absolute width/height in pixels the droppable expects.\n */\nexport interface DropTargetContext {\n scale: (item: Item, size?: { width: number; height: number }) => { width: number; height: number };\n}\n\nexport interface DragAndDropData {\n operation: Operation;\n interactionType: InteractionType;\n draggableItem: Item;\n collisionRect: Rect;\n positionOffset: Coordinates;\n coordinates: Coordinates;\n collisionIds: ItemId[];\n dropTarget: null | DropTargetContext;\n}\n\nexport interface Droppable {\n element: HTMLElement;\n context: DropTargetContext;\n}\n\ninterface AcquireData {\n droppableId: ItemId;\n draggableItem: Item;\n renderAcquiredItem: () => ReactNode;\n}\n\nexport interface DragAndDropEvents {\n start: (data: DragAndDropData) => void;\n update: (data: DragAndDropData) => void;\n submit: () => void;\n discard: () => void;\n acquire: (data: AcquireData) => void;\n}\n\ninterface Transition {\n operation: Operation;\n interactionType: InteractionType;\n draggableItem: Item;\n getCollisionRect: (operation: Operation, coordinates: Coordinates, dropTarget: null | DropTargetContext) => Rect;\n startCoordinates: Coordinates;\n}\n\nclass DragAndDropController extends EventEmitter<DragAndDropEvents> {\n private droppables = new Map<ItemId, Droppable>();\n private transition: null | Transition = null;\n\n /**\n * Inits a drag transition and issues a \"start\" event.\n *\n * The method overrides the previous transition if exists (w/o a cancellation event)!\n */\n public start(transition: Transition) {\n this.transition = { ...transition };\n this.emit(\"start\", this.getDragAndDropData(transition.startCoordinates));\n }\n\n /**\n * Updates current transition with given coordinates and issues an \"update\" event.\n */\n public update(coordinates: Coordinates) {\n this.emit(\"update\", this.getDragAndDropData(coordinates));\n }\n\n /**\n * Removes transition and issues a \"submit\" event.\n */\n public submit() {\n this.emit(\"submit\");\n this.transition = null;\n }\n\n /**\n * Removes transition and issues a \"discard\" event.\n */\n public discard() {\n this.emit(\"discard\");\n this.transition = null;\n }\n\n /**\n * Issues an \"acquire\" event to notify the current transition draggable is acquired by the given droppable.\n */\n public acquire(droppableId: ItemId, renderAcquiredItem: () => ReactNode) {\n if (!this.transition) {\n throw new Error(\"Invariant violation: no transition present for acquire.\");\n }\n this.emit(\"acquire\", { droppableId, draggableItem: this.transition.draggableItem, renderAcquiredItem });\n }\n\n /**\n * Registers a droppable used for collisions check, acquire, and dropTarget provision.\n */\n public addDroppable(id: ItemId, context: DropTargetContext, element: HTMLElement) {\n this.droppables.set(id, { element, context });\n }\n\n /**\n * Un-registers the droppable - use it when component unmounts.\n */\n public removeDroppable(id: ItemId) {\n this.droppables.delete(id);\n }\n\n /**\n * Retrieves all registered droppables to run a manual match against.\n */\n public getDroppables() {\n return [...this.droppables.entries()];\n }\n\n private getDragAndDropData(coordinates: Coordinates): DragAndDropData {\n if (!this.transition) {\n throw new Error(\"Invariant violation: no transition present for interaction.\");\n }\n const positionOffset = Coordinates.cursorOffset(coordinates, this.transition.startCoordinates);\n const collisionRect = this.getCollisionRect(this.transition, coordinates);\n const { collisionIds, dropTarget } = this.getCollisions(collisionRect);\n return { ...this.transition, positionOffset, coordinates, collisionRect, collisionIds, dropTarget };\n }\n\n private getCollisionRect(transition: Transition, coordinates: Coordinates) {\n const originalCollisionRect = transition.getCollisionRect(transition.operation, coordinates, null);\n const { dropTarget } = this.getCollisions(originalCollisionRect);\n return transition.getCollisionRect(transition.operation, coordinates, dropTarget);\n }\n\n private getCollisions(collisionRect: Rect) {\n const droppableEntries = [...this.droppables.entries()];\n const droppableElements: [ItemId, HTMLElement][] = droppableEntries.map(([id, entry]) => [id, entry.element]);\n const collisionIds = getHoveredDroppables(collisionRect, droppableElements);\n if (collisionIds.length === 0) {\n return { collisionIds, dropTarget: null };\n }\n\n const matchedDroppable = droppableEntries.find(([id]) => id === collisionIds[0]);\n if (!matchedDroppable) {\n throw new Error(\"Invariant violation: no droppable matches collision.\");\n }\n return { collisionIds, dropTarget: matchedDroppable[1].context };\n }\n}\n\n// Controller is a singleton and is shared between all d&d elements.\nconst controller = new DragAndDropController();\n\nexport function useDragSubscription<K extends keyof DragAndDropEvents>(event: K, handler: DragAndDropEvents[K]) {\n const stableHandler = useStableCallback(handler);\n useEffect(() => controller.on(event, stableHandler), [event, stableHandler]);\n}\n\nexport function useDraggable({\n draggableItem,\n getCollisionRect,\n}: {\n draggableItem: Item;\n getCollisionRect: (operation: Operation, coordinates: Coordinates, dropTarget: null | DropTargetContext) => Rect;\n}) {\n return {\n start(operation: Operation, interactionType: InteractionType, startCoordinates: Coordinates) {\n controller.start({ operation, interactionType, draggableItem, getCollisionRect, startCoordinates });\n },\n updateTransition(coordinates: Coordinates) {\n controller.update(coordinates);\n },\n submitTransition() {\n controller.submit();\n },\n discardTransition() {\n controller.discard();\n },\n acquire(droppableId: ItemId, renderAcquiredItem: () => ReactNode) {\n controller.acquire(droppableId, renderAcquiredItem);\n },\n getDroppables() {\n return controller.getDroppables();\n },\n };\n}\n\nexport function useDroppable({\n itemId,\n context,\n getElement,\n}: {\n itemId: ItemId;\n context: DropTargetContext;\n getElement: () => HTMLElement;\n}) {\n useEffect(() => {\n controller.addDroppable(itemId, context, getElement());\n return () => controller.removeDroppable(itemId);\n }, [itemId, context, getElement]);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../src/internal/dnd-controller/controller.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AAClF,OAAO,EAAa,SAAS,EAAE,MAAM,OAAO,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAwDhE,MAAM,qBAAsB,SAAQ,YAA+B;IAAnE;;QACU,eAAU,GAAG,IAAI,GAAG,EAAqB,CAAC;QAC1C,eAAU,GAAsB,IAAI,CAAC;IAgG/C,CAAC;IA9FC;;;;OAIG;IACI,KAAK,CAAC,UAAsB;QACjC,IAAI,CAAC,UAAU,GAAG,EAAE,GAAG,UAAU,EAAE,CAAC;QACpC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAC3E,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,WAAwB;QACpC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED;;OAEG;IACI,MAAM;QACX,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACpB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IACzB,CAAC;IAED;;OAEG;IACI,OAAO;QACZ,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IACzB,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,W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// SPDX-License-Identifier: Apache-2.0\nimport { useStableCallback } from \"@cloudscape-design/component-toolkit/internal\";\nimport { ReactNode, useEffect } from \"react\";\nimport { BoardItemDefinitionBase, ItemId, Rect } from \"../interfaces\";\nimport { Coordinates } from \"../utils/coordinates\";\nimport { EventEmitter } from \"./event-emitter\";\nimport { getHoveredDroppables } from \"./get-hovered-droppables\";\n\ntype Item = BoardItemDefinitionBase<unknown>;\n\nexport type Operation = \"reorder\" | \"resize\" | \"insert\";\n\nexport type InteractionType = \"pointer\" | \"keyboard\";\n\n/**\n * Represents the relations between droppables and draggables.\n *\n * The `scale` function transforms draggable's width/height in relative units\n * to the absolute width/height in pixels the droppable expects.\n */\nexport interface DropTargetContext {\n scale: (item: Item, size?: { width: number; height: number }) => { width: number; height: number };\n}\n\nexport interface DragAndDropData {\n operation: Operation;\n interactionType: InteractionType;\n draggableItem: Item;\n collisionRect: Rect;\n positionOffset: Coordinates;\n coordinates: Coordinates;\n collisionIds: ItemId[];\n dropTarget: null | DropTargetContext;\n}\n\nexport interface Droppable {\n element: HTMLElement;\n context: DropTargetContext;\n}\n\nexport interface AcquireData {\n droppableId: ItemId;\n draggableItem: Item;\n renderAcquiredItem: () => ReactNode;\n}\n\nexport interface DragAndDropEvents {\n start: (data: DragAndDropData) => void;\n update: (data: DragAndDropData) => void;\n submit: () => void;\n discard: () => void;\n acquire: (data: AcquireData) => void;\n}\n\ninterface Transition {\n operation: Operation;\n interactionType: InteractionType;\n draggableItem: Item;\n getCollisionRect: (operation: Operation, coordinates: Coordinates, dropTarget: null | DropTargetContext) => Rect;\n startCoordinates: Coordinates;\n}\n\nclass DragAndDropController extends EventEmitter<DragAndDropEvents> {\n private droppables = new Map<ItemId, Droppable>();\n private transition: null | Transition = null;\n\n /**\n * Inits a drag transition and issues a \"start\" event.\n *\n * The method overrides the previous transition if exists (w/o a cancellation event)!\n */\n public start(transition: Transition) {\n this.transition = { ...transition };\n this.emit(\"start\", this.getDragAndDropData(transition.startCoordinates));\n }\n\n /**\n * Updates current transition with given coordinates and issues an \"update\" event.\n */\n public update(coordinates: Coordinates) {\n this.emit(\"update\", this.getDragAndDropData(coordinates));\n }\n\n /**\n * Removes transition and issues a \"submit\" event.\n */\n public submit() {\n this.emit(\"submit\");\n this.transition = null;\n }\n\n /**\n * Removes transition and issues a \"discard\" event.\n */\n public discard() {\n this.emit(\"discard\");\n this.transition = null;\n }\n\n /**\n * Issues an \"acquire\" event to notify the current transition draggable is acquired by the given droppable.\n */\n public acquire(droppableId: ItemId, renderAcquiredItem: () => ReactNode) {\n if (!this.transition) {\n throw new Error(\"Invariant violation: no transition present for acquire.\");\n }\n this.emit(\"acquire\", { droppableId, draggableItem: this.transition.draggableItem, renderAcquiredItem });\n }\n\n /**\n * Registers a droppable used for collisions check, acquire, and dropTarget provision.\n */\n public addDroppable(id: ItemId, context: DropTargetContext, element: HTMLElement) {\n this.droppables.set(id, { element, context });\n }\n\n /**\n * Un-registers the droppable - use it when component unmounts.\n */\n public removeDroppable(id: ItemId) {\n this.droppables.delete(id);\n }\n\n /**\n * Retrieves all registered droppables to run a manual match against.\n */\n public getDroppables() {\n return [...this.droppables.entries()];\n }\n\n private getDragAndDropData(coordinates: Coordinates): DragAndDropData {\n if (!this.transition) {\n throw new Error(\"Invariant violation: no transition present for interaction.\");\n }\n const positionOffset = Coordinates.cursorOffset(coordinates, this.transition.startCoordinates);\n const collisionRect = this.getCollisionRect(this.transition, coordinates);\n const { collisionIds, dropTarget } = this.getCollisions(collisionRect);\n return { ...this.transition, positionOffset, coordinates, collisionRect, collisionIds, dropTarget };\n }\n\n private getCollisionRect(transition: Transition, coordinates: Coordinates) {\n const originalCollisionRect = transition.getCollisionRect(transition.operation, coordinates, null);\n const { dropTarget } = this.getCollisions(originalCollisionRect);\n return transition.getCollisionRect(transition.operation, coordinates, dropTarget);\n }\n\n private getCollisions(collisionRect: Rect) {\n const droppableEntries = [...this.droppables.entries()];\n const droppableElements: [ItemId, HTMLElement][] = droppableEntries.map(([id, entry]) => [id, entry.element]);\n const collisionIds = getHoveredDroppables(collisionRect, droppableElements);\n if (collisionIds.length === 0) {\n return { collisionIds, dropTarget: null };\n }\n\n const matchedDroppable = droppableEntries.find(([id]) => id === collisionIds[0]);\n if (!matchedDroppable) {\n throw new Error(\"Invariant violation: no droppable matches collision.\");\n }\n return { collisionIds, dropTarget: matchedDroppable[1].context };\n }\n}\n\n// Controller is a singleton and is shared between all d&d elements.\nconst controller = new DragAndDropController();\n\nexport function useDragSubscription<K extends keyof DragAndDropEvents>(event: K, handler: DragAndDropEvents[K]) {\n const stableHandler = useStableCallback(handler);\n useEffect(() => controller.on(event, stableHandler), [event, stableHandler]);\n}\n\nexport function useDraggable({\n draggableItem,\n getCollisionRect,\n}: {\n draggableItem: Item;\n getCollisionRect: (operation: Operation, coordinates: Coordinates, dropTarget: null | DropTargetContext) => Rect;\n}) {\n return {\n start(operation: Operation, interactionType: InteractionType, startCoordinates: Coordinates) {\n controller.start({ operation, interactionType, draggableItem, getCollisionRect, startCoordinates });\n },\n updateTransition(coordinates: Coordinates) {\n controller.update(coordinates);\n },\n submitTransition() {\n controller.submit();\n },\n discardTransition() {\n controller.discard();\n },\n acquire(droppableId: ItemId, renderAcquiredItem: () => ReactNode) {\n controller.acquire(droppableId, renderAcquiredItem);\n },\n getDroppables() {\n return controller.getDroppables();\n },\n };\n}\n\nexport function useDroppable({\n itemId,\n context,\n getElement,\n}: {\n itemId: ItemId;\n context: DropTargetContext;\n getElement: () => HTMLElement;\n}) {\n useEffect(() => {\n controller.addDroppable(itemId, context, getElement());\n return () => controller.removeDroppable(itemId);\n }, [itemId, context, getElement]);\n}\n"]}
|
package/internal/environment.js
CHANGED
package/internal/manifest.json
CHANGED