@cloudscape-design/board-components 3.0.51 → 3.0.53
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/board/index.js +1 -0
- package/board/index.js.map +1 -0
- package/board/interfaces.js +1 -0
- package/board/interfaces.js.map +1 -0
- package/board/internal.js +1 -0
- package/board/internal.js.map +1 -0
- package/board/placeholder.js +1 -0
- package/board/placeholder.js.map +1 -0
- package/board/transition.js +1 -0
- package/board/transition.js.map +1 -0
- package/board/utils/announcements.js +1 -0
- package/board/utils/announcements.js.map +1 -0
- package/board/utils/create-transforms.js +1 -0
- package/board/utils/create-transforms.js.map +1 -0
- package/board/utils/events.js +1 -0
- package/board/utils/events.js.map +1 -0
- package/board/utils/get-hovered-rect.js +1 -0
- package/board/utils/get-hovered-rect.js.map +1 -0
- package/board/utils/layout.js +1 -0
- package/board/utils/layout.js.map +1 -0
- package/board/utils/path.js +1 -0
- package/board/utils/path.js.map +1 -0
- package/board-item/header.js +1 -0
- package/board-item/header.js.map +1 -0
- package/board-item/index.js +1 -0
- package/board-item/index.js.map +1 -0
- package/board-item/interfaces.js +1 -0
- package/board-item/interfaces.js.map +1 -0
- package/board-item/internal.js +1 -0
- package/board-item/internal.js.map +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -0
- package/internal/base-component/get-data-attributes.js +1 -0
- package/internal/base-component/get-data-attributes.js.map +1 -0
- package/internal/base-component/use-base-component.js +1 -0
- package/internal/base-component/use-base-component.js.map +1 -0
- package/internal/base-component/use-telemetry.js +1 -0
- package/internal/base-component/use-telemetry.js.map +1 -0
- package/internal/base-component/use-visual-refresh.js +1 -0
- package/internal/base-component/use-visual-refresh.js.map +1 -0
- package/internal/breakpoints.js +1 -0
- package/internal/breakpoints.js.map +1 -0
- package/internal/constants.js +1 -0
- package/internal/constants.js.map +1 -0
- package/internal/debug-tools/converters.js +1 -0
- package/internal/debug-tools/converters.js.map +1 -0
- package/internal/debug-tools/generators.js +1 -0
- package/internal/debug-tools/generators.js.map +1 -0
- package/internal/debug-tools/index.js +1 -0
- package/internal/debug-tools/index.js.map +1 -0
- package/internal/debug-tools/interfaces.js +1 -0
- package/internal/debug-tools/interfaces.js.map +1 -0
- package/internal/debug-tools/parsers.js +1 -0
- package/internal/debug-tools/parsers.js.map +1 -0
- package/internal/dnd-controller/__mocks__/controller.js +1 -0
- package/internal/dnd-controller/__mocks__/controller.js.map +1 -0
- package/internal/dnd-controller/controller.js +1 -0
- package/internal/dnd-controller/controller.js.map +1 -0
- package/internal/dnd-controller/event-emitter.js +1 -0
- package/internal/dnd-controller/event-emitter.js.map +1 -0
- package/internal/dnd-controller/get-hovered-droppables.js +1 -0
- package/internal/dnd-controller/get-hovered-droppables.js.map +1 -0
- package/internal/drag-handle/index.js +1 -0
- package/internal/drag-handle/index.js.map +1 -0
- package/internal/environment.js +1 -1
- package/internal/environment.json +1 -1
- package/internal/global-drag-state-styles/index.js +1 -0
- package/internal/global-drag-state-styles/index.js.map +1 -0
- package/internal/grid/grid.js +1 -0
- package/internal/grid/grid.js.map +1 -0
- package/internal/grid/index.js +1 -0
- package/internal/grid/index.js.map +1 -0
- package/internal/grid/interfaces.js +1 -0
- package/internal/grid/interfaces.js.map +1 -0
- package/internal/grid/item.js +1 -0
- package/internal/grid/item.js.map +1 -0
- package/internal/handle/index.js +1 -0
- package/internal/handle/index.js.map +1 -0
- package/internal/interfaces.js +1 -0
- package/internal/interfaces.js.map +1 -0
- package/internal/item-container/get-collision-rect.js +1 -0
- package/internal/item-container/get-collision-rect.js.map +1 -0
- package/internal/item-container/get-next-droppable.js +1 -0
- package/internal/item-container/get-next-droppable.js.map +1 -0
- package/internal/item-container/index.js +1 -0
- package/internal/item-container/index.js.map +1 -0
- package/internal/layout-engine/engine-cache.js +1 -0
- package/internal/layout-engine/engine-cache.js.map +1 -0
- package/internal/layout-engine/engine-solution.js +1 -0
- package/internal/layout-engine/engine-solution.js.map +1 -0
- package/internal/layout-engine/engine-state.js +1 -0
- package/internal/layout-engine/engine-state.js.map +1 -0
- package/internal/layout-engine/engine-step.js +1 -0
- package/internal/layout-engine/engine-step.js.map +1 -0
- package/internal/layout-engine/engine.js +1 -0
- package/internal/layout-engine/engine.js.map +1 -0
- package/internal/layout-engine/grid.js +1 -0
- package/internal/layout-engine/grid.js.map +1 -0
- package/internal/layout-engine/interfaces.js +1 -0
- package/internal/layout-engine/interfaces.js.map +1 -0
- package/internal/layout-engine/utils.js +1 -0
- package/internal/layout-engine/utils.js.map +1 -0
- package/internal/live-region/index.js +1 -0
- package/internal/live-region/index.js.map +1 -0
- package/internal/manifest.json +1 -1
- package/internal/resize-handle/index.js +1 -0
- package/internal/resize-handle/index.js.map +1 -0
- package/internal/screenreader-grid-navigation/index.js +1 -0
- package/internal/screenreader-grid-navigation/index.js.map +1 -0
- package/internal/screenreader-only/index.js +1 -0
- package/internal/screenreader-only/index.js.map +1 -0
- package/internal/utils/apply-display-name.js +1 -0
- package/internal/utils/apply-display-name.js.map +1 -0
- package/internal/utils/coordinates.js +1 -0
- package/internal/utils/coordinates.js.map +1 -0
- package/internal/utils/events.js +1 -0
- package/internal/utils/events.js.map +1 -0
- package/internal/utils/layout.js +1 -0
- package/internal/utils/layout.js.map +1 -0
- package/internal/utils/position.js +1 -0
- package/internal/utils/position.js.map +1 -0
- package/internal/utils/rects.js +1 -0
- package/internal/utils/rects.js.map +1 -0
- package/internal/utils/screen.js +1 -0
- package/internal/utils/screen.js.map +1 -0
- package/internal/utils/throttle.js +1 -0
- package/internal/utils/throttle.js.map +1 -0
- package/internal/utils/use-auto-scroll.js +1 -0
- package/internal/utils/use-auto-scroll.js.map +1 -0
- package/internal/utils/use-last-interaction.js +1 -0
- package/internal/utils/use-last-interaction.js.map +1 -0
- package/internal/utils/use-merge-refs.js +1 -0
- package/internal/utils/use-merge-refs.js.map +1 -0
- package/internal/utils/zip-arrays.js +1 -0
- package/internal/utils/zip-arrays.js.map +1 -0
- package/items-palette/index.js +1 -0
- package/items-palette/index.js.map +1 -0
- package/items-palette/interfaces.js +1 -0
- package/items-palette/interfaces.js.map +1 -0
- package/items-palette/internal.js +1 -0
- package/items-palette/internal.js.map +1 -0
- package/package.json +32 -1
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +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,e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CAAC,CAAC;QACjC,CAAC;QACD,gBAAgB;YACd,UAAU,CAAC,MAAM,EAAE,CAAC;QACtB,CAAC;QACD,iBAAiB;YACf,UAAU,CAAC,OAAO,EAAE,CAAC;QACvB,CAAC;QACD,OAAO,CAAC,WAAmB,EAAE,kBAAmC;YAC9D,UAAU,CAAC,OAAO,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAC;QACtD,CAAC;QACD,aAAa;YACX,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC;QACpC,CAAC;KACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,EAC3B,MAAM,EACN,OAAO,EACP,UAAU,GAKX;IACC,SAAS,CAAC,GAAG,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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-emitter.js","sourceRoot":"","sources":["../../../../src/internal/dnd-controller/event-emitter.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAMtC,MAAM,OAAO,YAAY;IAAzB;QACU,cAAS,GAAG,IAAI,GAAG,EAA6C,CAAC;IAqB3E,CAAC;IAnBQ,EAAE,CAA6B,KAAY,EAAE,OAAsB;QACxE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YAC9B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;SAC/B;QACD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAEzC,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,SAAS,CAAC,GAAG,CAChB,KAAK,EACL,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,OAAO,CAAC,CAC9D,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;IAES,IAAI,CAA6B,KAAY,EAAE,GAAG,IAA+B;;QACzF,KAAK,MAAM,OAAO,IAAI,MAAA,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,mCAAI,EAAE,EAAE;YACrD,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;SAClB;IACH,CAAC;CACF","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\ntype Listeners<L> = {\n [E in keyof L]: (...args: any[]) => any;\n};\n\nexport class EventEmitter<Events extends Listeners<Events>> {\n private listeners = new Map<keyof Events, Array<Events[keyof Events]>>();\n\n public on<Event extends keyof Events>(event: Event, handler: Events[Event]) {\n if (!this.listeners.has(event)) {\n this.listeners.set(event, []);\n }\n this.listeners.get(event)!.push(handler);\n\n return () => {\n this.listeners.set(\n event,\n this.listeners.get(event)!.filter((item) => item !== handler)\n );\n };\n }\n\n protected emit<Event extends keyof Events>(event: Event, ...data: Parameters<Events[Event]>) {\n for (const handler of this.listeners.get(event) ?? []) {\n handler(...data);\n }\n }\n}\n"]}
|
|
@@ -8,3 +8,4 @@ export function getHoveredDroppables(collisionRect, droppables) {
|
|
|
8
8
|
const bounds = getGridPlacement(collisionRect, droppableRects);
|
|
9
9
|
return droppables.filter((_, index) => isInside(droppableRects[index], bounds)).map(([droppableId]) => droppableId);
|
|
10
10
|
}
|
|
11
|
+
//# sourceMappingURL=get-hovered-droppables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-hovered-droppables.js","sourceRoot":"","sources":["../../../../src/internal/dnd-controller/get-hovered-droppables.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAE3D;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,aAAmB,EAAE,UAA4C;IACpG,MAAM,cAAc,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1F,MAAM,MAAM,GAAG,gBAAgB,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;IAC/D,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC;AACtH,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ItemId } from \"../interfaces\";\nimport { Rect } from \"../interfaces\";\nimport { getGridPlacement, isInside } from \"../utils/rects\";\nimport { getNormalizedElementRect } from \"../utils/screen\";\n\n/**\n * Returns IDs of droppables hovered by the draggable rect.\n */\nexport function getHoveredDroppables(collisionRect: Rect, droppables: readonly [ItemId, HTMLElement][]) {\n const droppableRects = droppables.map(([, element]) => getNormalizedElementRect(element));\n const bounds = getGridPlacement(collisionRect, droppableRects);\n return droppables.filter((_, index) => isInside(droppableRects[index], bounds)).map(([droppableId]) => droppableId);\n}\n"]}
|
|
@@ -10,3 +10,4 @@ function DragHandle({ ariaLabelledBy, ariaDescribedBy, onPointerDown, onKeyDown,
|
|
|
10
10
|
return (_jsx(Handle, { ref: ref, className: clsx(styles.handle, isActive && styles.active), "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, onPointerDown: onPointerDown, onKeyDown: onKeyDown, children: _jsx(Icon, { name: "drag-indicator" }) }));
|
|
11
11
|
}
|
|
12
12
|
export default forwardRef(DragHandle);
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/internal/drag-handle/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,IAAI,MAAM,oCAAoC,CAAC;AACtD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAA6C,UAAU,EAAE,MAAM,OAAO,CAAC;AAE9E,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAUrC,SAAS,UAAU,CACjB,EAAE,cAAc,EAAE,eAAe,EAAE,aAAa,EAAE,SAAS,EAAE,QAAQ,EAAmB,EACxF,GAAoC;IAEpC,OAAO,CACL,KAAC,MAAM,IACL,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,qBACxC,cAAc,sBACb,eAAe,EACjC,aAAa,EAAE,aAAa,EAC5B,SAAS,EAAE,SAAS,YAEpB,KAAC,IAAI,IAAC,IAAI,EAAC,gBAAgB,GAAG,GACvB,CACV,CAAC;AACJ,CAAC;AAED,eAAe,UAAU,CAAC,UAAU,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport Icon from \"@cloudscape-design/components/icon\";\nimport clsx from \"clsx\";\nimport { ForwardedRef, KeyboardEvent, PointerEvent, forwardRef } from \"react\";\n\nimport Handle from \"../handle\";\nimport styles from \"./styles.css.js\";\n\nexport interface DragHandleProps {\n ariaLabelledBy: string;\n ariaDescribedBy: string;\n onPointerDown: (event: PointerEvent) => void;\n onKeyDown: (event: KeyboardEvent) => void;\n isActive: boolean;\n}\n\nfunction DragHandle(\n { ariaLabelledBy, ariaDescribedBy, onPointerDown, onKeyDown, isActive }: DragHandleProps,\n ref: ForwardedRef<HTMLButtonElement>\n) {\n return (\n <Handle\n ref={ref}\n className={clsx(styles.handle, isActive && styles.active)}\n aria-labelledby={ariaLabelledBy}\n aria-describedby={ariaDescribedBy}\n onPointerDown={onPointerDown}\n onKeyDown={onKeyDown}\n >\n <Icon name=\"drag-indicator\" />\n </Handle>\n );\n}\n\nexport default forwardRef(DragHandle);\n"]}
|
package/internal/environment.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/internal/global-drag-state-styles/index.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAmB,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACpF,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAErC,SAAS,WAAW,CAAC,KAAY;IAC/B,MAAM,IAAI,KAAK,CAAC,oBAAoB,GAAG,KAAK,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,KAAK,CAAC,EAAE,SAAS,EAAE,eAAe,EAAmB;IAC5D,QAAQ,SAAS,EAAE;QACjB,KAAK,QAAQ,CAAC;QACd,KAAK,SAAS;YACZ,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC;YACxD,MAAM;QACR,KAAK,QAAQ;YACX,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC,CAAC;YAC1D,MAAM;QACR;YACE,oEAAoE;YACpE,WAAW,CAAC,SAAS,CAAC,CAAC;KAC1B;IAED,IAAI,eAAe,KAAK,SAAS,EAAE;QACjC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC;KAC1D;AACH,CAAC;AAED,SAAS,QAAQ;IACf,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC;AACxH,CAAC;AAED,MAAM,UAAU,wBAAwB;IACtC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACpC,mBAAmB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IACzC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { DragAndDropData, useDragSubscription } from \"../dnd-controller/controller\";\nimport styles from \"./styles.css.js\";\n\nfunction assertNever(value: never) {\n throw new Error(\"Unexpected value: \" + value);\n}\n\nfunction setup({ operation, interactionType }: DragAndDropData) {\n switch (operation) {\n case \"insert\":\n case \"reorder\":\n document.body.classList.add(styles[\"show-grab-cursor\"]);\n break;\n case \"resize\":\n document.body.classList.add(styles[\"show-resize-cursor\"]);\n break;\n default:\n // there will be a type error if not all operation types are handled\n assertNever(operation);\n }\n\n if (interactionType === \"pointer\") {\n document.body.classList.add(styles[\"disable-selection\"]);\n }\n}\n\nfunction teardown() {\n document.body.classList.remove(styles[\"show-grab-cursor\"], styles[\"show-resize-cursor\"], styles[\"disable-selection\"]);\n}\n\nexport function useGlobalDragStateStyles() {\n useDragSubscription(\"start\", setup);\n useDragSubscription(\"discard\", teardown);\n useDragSubscription(\"submit\", teardown);\n}\n"]}
|
package/internal/grid/grid.js
CHANGED
|
@@ -40,3 +40,4 @@ export default function Grid({ layout, children: render, columns }) {
|
|
|
40
40
|
const ref = useMergeRefs(gridRef, containerQueryRef);
|
|
41
41
|
return (_jsx("div", { ref: ref, className: clsx(styles.grid, styles[`grid-${densityMode}`], styles[`columns-${columns}`]), children: zipped.map(([item, children]) => (_jsx(GridItem, { item: item, children: children }, item.id))) }));
|
|
42
42
|
}
|
|
43
|
+
//# sourceMappingURL=grid.js.map
|
|
@@ -0,0 +1 @@
|
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AAe,IAAI,EAAE,IAAI,YAC/B,QAAQ,IADI,IAAI,CAAC,EAAE,CAEX,CACZ,CAAC,GACE,CACP,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useContainerQuery } from \"@cloudscape-design/component-toolkit\";\nimport { useDensityMode } from \"@cloudscape-design/component-toolkit/internal\";\nimport clsx from \"clsx\";\nimport { Children, useRef } from \"react\";\nimport { useMergeRefs } from \"../utils/use-merge-refs\";\nimport { zipTwoArrays } from \"../utils/zip-arrays\";\n\nimport { GridProps } from \"./interfaces\";\nimport GridItem from \"./item\";\nimport styles from \"./styles.css.js\";\n\n/* Matches grid gap in CSS. */\nconst GRID_GAP = {\n comfortable: 20,\n compact: 16,\n};\n\n/* Matches grid-auto-rows in CSS. */\nconst ROWSPAN_HEIGHT = {\n comfortable: 96,\n compact: 76,\n};\n\nexport default function Grid({ layout, children: render, columns }: GridProps) {\n const gridRef = useRef<HTMLDivElement>(null);\n const [gridWidth, containerQueryRef] = useContainerQuery((entry) => entry.contentBoxWidth, []);\n const densityMode = useDensityMode(gridRef);\n const gridGap = GRID_GAP[densityMode];\n const rowspanHeight = ROWSPAN_HEIGHT[densityMode];\n\n // The below getters translate relative grid units into size/offset values in pixels.\n const getWidth = (colspan: number) => {\n colspan = Math.min(columns, colspan);\n const cellWidth = ((gridWidth || 0) - (columns - 1) * gridGap) / columns;\n return colspan * cellWidth + (colspan - 1) * gridGap;\n };\n const getHeight = (rowspan: number) => rowspan * rowspanHeight + (rowspan - 1) * gridGap;\n const getColOffset = (x: number) => getWidth(x) + gridGap;\n const getRowOffset = (y: number) => getHeight(y) + gridGap;\n\n const gridContext = { getWidth, getHeight, getColOffset, getRowOffset };\n const children = render?.(gridContext);\n\n const zipped = zipTwoArrays(layout, Children.toArray(children));\n\n const ref = useMergeRefs(gridRef, containerQueryRef);\n return (\n <div ref={ref} className={clsx(styles.grid, styles[`grid-${densityMode}`], styles[`columns-${columns}`])}>\n {zipped.map(([item, children]) => (\n <GridItem key={item.id} item={item}>\n {children}\n </GridItem>\n ))}\n </div>\n );\n}\n"]}
|
package/internal/grid/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/internal/grid/index.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,QAAQ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport { default as default } from \"./grid\";\nexport type { GridProps } from \"./interfaces\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../src/internal/grid/interfaces.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { ReactNode } from \"react\";\nimport { GridLayoutItem } from \"../interfaces\";\n\nexport interface GridProps {\n layout: GridLayoutItem[];\n columns: number;\n children?: (context: GridContext) => ReactNode;\n}\n\nexport interface GridContext {\n getWidth: (colspan: number) => number;\n getHeight: (rowspan: number) => number;\n getColOffset: (x: number) => number;\n getRowOffset: (y: number) => number;\n}\n"]}
|
package/internal/grid/item.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item.js","sourceRoot":"","sources":["../../../../src/internal/grid/item.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EAAa,IAAI,EAAE,MAAM,OAAO,CAAC;AAExC,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAOrC,MAAM,QAAQ,GAAG,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAiB,EAAE,EAAE;IACrD,gHAAgH;IAChH,OAAO,CACL,cACE,SAAS,EAAE,MAAM,CAAC,UAAU,EAC5B,KAAK,EAAE;YACL,YAAY,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC;YACxB,UAAU,EAAE,QAAQ,IAAI,CAAC,MAAM,EAAE;YACjC,eAAe,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC;YAC3B,aAAa,EAAE,QAAQ,IAAI,CAAC,KAAK,EAAE;SACpC,YAEA,QAAQ,GACL,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,IAAI,CAAC,QAAQ,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { ReactNode, memo } from \"react\";\nimport { GridLayoutItem } from \"../interfaces\";\nimport styles from \"./styles.css.js\";\n\nexport interface GridItemProps {\n item: GridLayoutItem;\n children?: ReactNode;\n}\n\nconst GridItem = ({ children, item }: GridItemProps) => {\n // Grid row start can not be set as part of a CSS class names, since we have a potentially infinite height grid.\n return (\n <div\n className={styles.grid__item}\n style={{\n gridRowStart: item.y + 1,\n gridRowEnd: `span ${item.height}`,\n gridColumnStart: item.x + 1,\n gridColumnEnd: `span ${item.width}`,\n }}\n >\n {children}\n </div>\n );\n};\n\nexport default memo(GridItem);\n"]}
|
package/internal/handle/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/internal/handle/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAoD,UAAU,EAAE,MAAM,OAAO,CAAC;AACrF,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAErC,SAAS,MAAM,CAAC,KAA8C,EAAE,GAAoC;IAClG,SAAS,iBAAiB,CAAC,KAAsC;;QAC/D,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;YACtB,OAAO;SACR;QACD,MAAA,KAAK,CAAC,aAAa,sDAAG,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,OAAO,CACL,oBAAY,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,GAAG,GAAI,CACnH,CAAC;AACJ,CAAC;AAED,eAAe,UAAU,CAAC,MAAM,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport clsx from \"clsx\";\nimport { ButtonHTMLAttributes, ForwardedRef, PointerEvent, forwardRef } from \"react\";\nimport styles from \"./styles.css.js\";\n\nfunction Handle(props: ButtonHTMLAttributes<HTMLButtonElement>, ref: ForwardedRef<HTMLButtonElement>) {\n function handlePointerDown(event: PointerEvent<HTMLButtonElement>) {\n if (event.button !== 0) {\n return;\n }\n props.onPointerDown?.(event);\n }\n\n return (\n <button {...props} onPointerDown={handlePointerDown} className={clsx(styles.handle, props.className)} ref={ref} />\n );\n}\n\nexport default forwardRef(Handle);\n"]}
|
package/internal/interfaces.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/internal/interfaces.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\n// Meta-type to indicate item's ID.\nexport type ItemId = string;\n\nexport type DataFallbackType = Record<string, unknown>;\n\nexport interface BoardItemDefinitionBase<D = DataFallbackType> {\n id: ItemId;\n data: D;\n definition?: {\n minRowSpan?: number;\n minColumnSpan?: number;\n defaultRowSpan?: number;\n defaultColumnSpan?: number;\n };\n}\n\nexport interface BoardItemDefinition<D = DataFallbackType> extends BoardItemDefinitionBase<D> {\n columnOffset?: BoardItemColumnOffset;\n rowSpan?: number;\n columnSpan?: number;\n}\n\nexport interface BoardItemColumnOffset {\n [columns: number]: number;\n}\n\n// Internal grid item representation used for position calculations.\nexport interface GridLayout {\n items: readonly GridLayoutItem[];\n columns: number;\n rows: number;\n}\n\nexport interface GridLayoutItem {\n id: ItemId;\n width: number;\n height: number;\n x: number;\n y: number;\n}\n\nexport interface Rect {\n left: number;\n right: number;\n top: number;\n bottom: number;\n}\n\nexport type Transform = TransformMove | TransformRemove;\nexport interface TransformMove {\n type: \"move\";\n x: number;\n y: number;\n width: number;\n height: number;\n}\nexport interface TransformRemove {\n type: \"remove\";\n}\n\nexport type Direction = \"up\" | \"right\" | \"down\" | \"left\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-collision-rect.js","sourceRoot":"","sources":["../../../../src/internal/item-container/get-collision-rect.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAKtC,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAE3D;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,SAAoB,EACpB,gBAA6B,EAC7B,WAAwB,EACxB,YAAsD;;IAEtD,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,wBAAwB,CAAC,gBAAgB,CAAC,CAAC;IAEhF,QAAQ,SAAS,EAAE;QACjB,KAAK,SAAS;YACZ,OAAO,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,GAAG,KAAK,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC;QACnH,KAAK,QAAQ;YACX,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC;QAC/E,KAAK,QAAQ;YACX,OAAO;gBACL,IAAI,EAAE,WAAW,CAAC,CAAC;gBACnB,GAAG,EAAE,WAAW,CAAC,CAAC;gBAClB,KAAK,EAAE,WAAW,CAAC,CAAC,GAAG,CAAC,MAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,KAAK,mCAAI,KAAK,CAAC;gBACrD,MAAM,EAAE,WAAW,CAAC,CAAC,GAAG,CAAC,MAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,MAAM,mCAAI,MAAM,CAAC;aACzD,CAAC;KACL;AACH,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Operation } from \"../dnd-controller/controller\";\nimport { Rect } from \"../interfaces\";\nimport { Coordinates } from \"../utils/coordinates\";\nimport { getNormalizedElementRect } from \"../utils/screen\";\n\n/**\n * Produces a rect (in coordinates) to represent the draggable item.\n */\nexport function getCollisionRect(\n operation: Operation,\n draggableElement: HTMLElement,\n coordinates: Coordinates,\n sizeOverride: null | { width: number; height: number }\n): Rect {\n const { left, top, width, height } = getNormalizedElementRect(draggableElement);\n\n switch (operation) {\n case \"reorder\":\n return { left: coordinates.x, right: coordinates.x + width, top: coordinates.y, bottom: coordinates.y + height };\n case \"resize\":\n return { left: left, top: top, right: coordinates.x, bottom: coordinates.y };\n case \"insert\":\n return {\n left: coordinates.x,\n top: coordinates.y,\n right: coordinates.x + (sizeOverride?.width ?? width),\n bottom: coordinates.y + (sizeOverride?.height ?? height),\n };\n }\n}\n"]}
|
|
@@ -13,3 +13,4 @@ export function getNextDroppable(draggableElement, droppables, direction) {
|
|
|
13
13
|
const closest = getClosestNeighbor(draggableRect, [...sources.keys()], direction);
|
|
14
14
|
return (_a = sources.get(closest)) !== null && _a !== void 0 ? _a : null;
|
|
15
15
|
}
|
|
16
|
+
//# sourceMappingURL=get-next-droppable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-next-droppable.js","sourceRoot":"","sources":["../../../../src/internal/item-container/get-next-droppable.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAItC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAE3D;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,gBAA6B,EAC7B,UAA0C,EAC1C,SAAoB;;IAEpB,MAAM,aAAa,GAAG,wBAAwB,CAAC,gBAAgB,CAAC,CAAC;IACjE,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IAChG,MAAM,OAAO,GAAG,kBAAkB,CAAC,aAAa,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC;IAClF,OAAO,MAAA,OAAO,CAAC,GAAG,CAAC,OAAkB,CAAC,mCAAI,IAAI,CAAC;AACjD,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Droppable } from \"../dnd-controller/controller\";\nimport { Direction, ItemId } from \"../interfaces\";\nimport { getClosestNeighbor } from \"../utils/rects\";\nimport { getNormalizedElementRect } from \"../utils/screen\";\n\n/**\n * Finds closest droppable to provided draggable element and direction.\n * Returns null if there is no droppable in the given direction.\n */\nexport function getNextDroppable(\n draggableElement: HTMLElement,\n droppables: readonly [ItemId, Droppable][],\n direction: Direction\n): null | ItemId {\n const draggableRect = getNormalizedElementRect(draggableElement);\n const sources = new Map(droppables.map(([id, d]) => [getNormalizedElementRect(d.element), id]));\n const closest = getClosestNeighbor(draggableRect, [...sources.keys()], direction);\n return sources.get(closest as DOMRect) ?? null;\n}\n"]}
|
|
@@ -292,3 +292,4 @@ function ItemContainerComponent({ item, placed, acquired, inTransition, transfor
|
|
|
292
292
|
}, children: childrenRef.current }) }));
|
|
293
293
|
return shouldUsePortal ? _jsx("div", { children: createPortal(content, document.body) }) : content;
|
|
294
294
|
}
|
|
295
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/internal/item-container/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAOL,aAAa,EACb,UAAU,EACV,UAAU,EACV,SAAS,EACT,mBAAmB,EACnB,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAKL,mBAAmB,EACnB,YAAY,GACb,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAqBrC,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAyB,IAAI,CAAC,CAAC;AAEvE,MAAM,UAAU,cAAc;IAC5B,MAAM,GAAG,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IACpC,IAAI,CAAC,GAAG,EAAE;QACR,MAAM,IAAI,KAAK,CA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AAQ;qBACzD;oBACH,CAAC,CAAC,IAAI;aACT,YAEA,WAAW,CAAC,OAAO,GACC,GACnB,CACP,CAAC;IAEF,OAAO,eAAe,CAAC,CAAC,CAAC,wBAAM,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAO,CAAC,CAAC,CAAC,OAAO,CAAC;AACvF,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { CSS as CSSUtil } from \"@dnd-kit/utilities\";\nimport clsx from \"clsx\";\nimport {\n CSSProperties,\n KeyboardEvent,\n ReactNode,\n PointerEvent as ReactPointerEvent,\n Ref,\n RefObject,\n createContext,\n forwardRef,\n useContext,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport {\n DragAndDropData,\n DropTargetContext,\n InteractionType,\n Operation,\n useDragSubscription,\n useDraggable,\n} from \"../dnd-controller/controller\";\nimport { BoardItemDefinitionBase, Direction, ItemId, Transform } from \"../interfaces\";\nimport { Coordinates } from \"../utils/coordinates\";\nimport { getNormalizedElementRect } from \"../utils/screen\";\nimport { throttle } from \"../utils/throttle\";\nimport { getCollisionRect } from \"./get-collision-rect\";\nimport { getNextDroppable } from \"./get-next-droppable\";\nimport styles from \"./styles.css.js\";\n\nexport interface ItemContainerRef {\n focusDragHandle(): void;\n}\n\ninterface ItemContextType {\n isActive: boolean;\n dragHandle: {\n ref: RefObject<HTMLButtonElement>;\n onPointerDown(event: ReactPointerEvent): void;\n onKeyDown(event: KeyboardEvent): void;\n isActive: boolean;\n };\n resizeHandle: null | {\n onPointerDown(event: ReactPointerEvent): void;\n onKeyDown(event: KeyboardEvent): void;\n isActive: boolean;\n };\n}\n\nexport const ItemContext = createContext<ItemContextType | null>(null);\n\nexport function useItemContext() {\n const ctx = useContext(ItemContext);\n if (!ctx) {\n throw new Error(\"Unable to find BoardItem context.\");\n }\n return ctx;\n}\n\ninterface Transition {\n itemId: ItemId;\n operation: Operation;\n interactionType: InteractionType;\n sizeTransform: null | { width: number; height: number };\n positionTransform: null | { x: number; y: number };\n hasDropTarget?: boolean;\n}\n\n/**\n * Defines item's parameters and its relation with the layout.\n *\n * `item` - the unique board item base object to be used in d&d context.\n * `placed` - specifies if the item already belongs to the board.\n * `acquired` - specifies if the item is essentially a copy temporarily acquired by a droppable but not submitted yet.\n * `inTransition` - specifies if the item is currently being moved.\n * `transform` - specifies if the item's position needs to be altered.\n * `getItemSize` - item size getter that takes droppable context as argument.\n * `onKeyMove` - a callback that fires when arrow keys are pressed in drag- or resize handle.\n */\nexport interface ItemContainerProps {\n item: BoardItemDefinitionBase<unknown>;\n placed: boolean;\n acquired: boolean;\n inTransition: boolean;\n transform: Transform | undefined;\n getItemSize: (context: null | DropTargetContext) => {\n width: number;\n minWidth: number;\n maxWidth: number;\n height: number;\n minHeight: number;\n maxHeight: number;\n };\n onKeyMove?(direction: Direction): void;\n children: (hasDropTarget: boolean) => ReactNode;\n}\n\nexport const ItemContainer = forwardRef(ItemContainerComponent);\n\nfunction ItemContainerComponent(\n { item, placed, acquired, inTransition, transform, getItemSize, onKeyMove, children }: ItemContainerProps,\n ref: Ref<ItemContainerRef>\n) {\n const originalSizeRef = useRef({ width: 0, height: 0 });\n const pointerOffsetRef = useRef(new Coordinates({ x: 0, y: 0 }));\n const pointerBoundariesRef = useRef<null | Coordinates>(null);\n const [transition, setTransition] = useState<null | Transition>(null);\n const [isHidden, setIsHidden] = useState(false);\n const muteEventsRef = useRef(false);\n const itemRef = useRef<HTMLDivElement>(null);\n const draggableApi = useDraggable({\n draggableItem: item,\n getCollisionRect: (operation, coordinates, dropTarget) => {\n const sizeOverride = operation === \"insert\" && dropTarget ? getItemSize(dropTarget) : null;\n return getCollisionRect(operation, itemRef.current!, coordinates, sizeOverride);\n },\n });\n\n function updateTransition({\n operation,\n interactionType,\n draggableItem,\n collisionRect,\n coordinates,\n dropTarget,\n }: DragAndDropData) {\n if (item.id === draggableItem.id) {\n const [width, height] = [collisionRect.right - collisionRect.left, collisionRect.bottom - collisionRect.top];\n const pointerOffset = pointerOffsetRef.current;\n\n if (operation === \"resize\") {\n setTransition({\n operation,\n interactionType,\n itemId: draggableItem.id,\n sizeTransform: {\n width: Math.max(getItemSize(null).minWidth, Math.min(getItemSize(null).maxWidth, width - pointerOffset.x)),\n height: Math.max(getItemSize(null).minHeight, height - pointerOffset.y),\n },\n positionTransform: null,\n });\n } else if (operation === \"insert\" || operation === \"reorder\") {\n setTransition({\n operation,\n interactionType,\n itemId: draggableItem.id,\n sizeTransform: dropTarget ? getItemSize(dropTarget) : originalSizeRef.current,\n positionTransform: { x: coordinates.x - pointerOffset.x, y: coordinates.y - pointerOffset.y },\n hasDropTarget: !!dropTarget,\n });\n }\n }\n }\n\n useDragSubscription(\"start\", (detail) => updateTransition(detail));\n useDragSubscription(\"update\", (detail) => updateTransition(detail));\n useDragSubscription(\"submit\", () => {\n setTransition(null);\n setIsHidden(false);\n muteEventsRef.current = false;\n });\n useDragSubscription(\"discard\", () => {\n setTransition(null);\n setIsHidden(false);\n muteEventsRef.current = false;\n });\n\n // During the transition listen to pointer move and pointer up events to update/submit transition.\n const transitionInteractionType = transition?.interactionType ?? null;\n const transitionItemId = transition?.itemId ?? null;\n useEffect(() => {\n const onPointerMove = throttle((event: PointerEvent) => {\n const coordinates = Coordinates.fromEvent(event);\n draggableApi.updateTransition(\n new Coordinates({\n x: Math.max(coordinates.x, pointerBoundariesRef.current?.x ?? Number.NEGATIVE_INFINITY),\n y: Math.max(coordinates.y, pointerBoundariesRef.current?.y ?? Number.NEGATIVE_INFINITY),\n })\n );\n }, 10);\n const onPointerUp = () => {\n onPointerMove.cancel();\n draggableApi.submitTransition();\n };\n\n if (transitionInteractionType === \"pointer\" && transitionItemId === item.id) {\n window.addEventListener(\"pointermove\", onPointerMove);\n window.addEventListener(\"pointerup\", onPointerUp);\n }\n return () => {\n window.removeEventListener(\"pointermove\", onPointerMove);\n window.removeEventListener(\"pointerup\", onPointerUp);\n };\n // draggableApi is not expected to change\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [item.id, transitionInteractionType, transitionItemId]);\n\n useEffect(() => {\n if (transitionInteractionType === \"keyboard\" && transitionItemId === item.id) {\n const onPointerDown = () => draggableApi.submitTransition();\n window.addEventListener(\"pointerdown\", onPointerDown, true);\n return () => {\n window.removeEventListener(\"pointerdown\", onPointerDown, true);\n };\n }\n // draggableApi is not expected to change\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [item.id, transitionInteractionType, transitionItemId]);\n\n function onKeyboardTransitionToggle(operation: \"drag\" | \"resize\") {\n // The acquired item is a copy and does not have the transition state.\n // However, pressing \"Space\" or \"Enter\" on the acquired item must submit the active transition.\n if (acquired) {\n return draggableApi.submitTransition();\n }\n\n // Create new transition if missing.\n if (!transition) {\n const rect = getNormalizedElementRect(itemRef.current!);\n const coordinates = new Coordinates({\n x: operation === \"drag\" ? rect.left : rect.right,\n y: operation === \"drag\" ? rect.top : rect.bottom,\n });\n\n if (operation === \"drag\" && !placed) {\n draggableApi.start(\"insert\", \"keyboard\", coordinates);\n } else if (operation === \"drag\") {\n draggableApi.start(\"reorder\", \"keyboard\", coordinates);\n } else {\n draggableApi.start(\"resize\", \"keyboard\", coordinates);\n }\n }\n // Submit a transition if existing.\n else {\n draggableApi.submitTransition();\n }\n }\n\n function handleInsert(direction: Direction) {\n // Find the closest droppable (in the direction) to the item.\n const droppables = draggableApi.getDroppables();\n const nextDroppable = getNextDroppable(itemRef.current!, droppables, direction);\n\n if (!nextDroppable) {\n // TODO: add announcement\n // Context: the keyboard insertion only works when there is some droppable area in the specified direction.\n // That means that only some arrow keys might work which is confusing for a screen-reader user.\n // Alternatively, we can consider a multi-step insertion where the user would first explicitly select the desired board.\n return;\n }\n\n // Notify the respective droppable of the intention to insert the item in it.\n draggableApi.acquire(nextDroppable, () => children(true));\n setIsHidden(true);\n muteEventsRef.current = true;\n }\n\n function onHandleKeyDown(operation: \"drag\" | \"resize\", event: KeyboardEvent) {\n const canInsert = transition && operation === \"drag\" && !placed;\n const canNavigate = transition || operation === \"drag\";\n\n // The insert is handled by the item and the navigation is delegated to the containing layout.\n const move = (direction: Direction) => {\n if (canInsert) {\n handleInsert(direction);\n } else if (canNavigate) {\n onKeyMove?.(direction);\n }\n };\n\n const discard = () => {\n if (transition || acquired) {\n draggableApi.discardTransition();\n }\n };\n\n switch (event.key) {\n case \"ArrowUp\":\n return move(\"up\");\n case \"ArrowDown\":\n return move(\"down\");\n case \"ArrowLeft\":\n return move(\"left\");\n case \"ArrowRight\":\n return move(\"right\");\n case \" \":\n case \"Enter\":\n return onKeyboardTransitionToggle(operation);\n case \"Escape\":\n return discard();\n }\n }\n\n function onBlur() {\n // When drag- or resize handle on palette or board item loses focus the transition must be submitted with two exceptions:\n // 1. If the last interaction is not \"keyboard\" (the user clicked on another handle issuing a new transition);\n // 2. If the item is acquired by the board (in that case the focus moves to the board item which is expected, palette item is hidden and all events handlers must be muted).\n if (transition && transition.interactionType === \"keyboard\" && !muteEventsRef.current) {\n draggableApi.submitTransition();\n }\n }\n\n function onDragHandlePointerDown(event: ReactPointerEvent) {\n // Calculate the offset between item's top-left corner and the pointer landing position.\n const rect = itemRef.current!.getBoundingClientRect();\n pointerOffsetRef.current = new Coordinates({ x: event.clientX - rect.left, y: event.clientY - rect.top });\n originalSizeRef.current = { width: rect.width, height: rect.height };\n pointerBoundariesRef.current = null;\n\n draggableApi.start(!placed ? \"insert\" : \"reorder\", \"pointer\", Coordinates.fromEvent(event));\n }\n\n function onDragHandleKeyDown(event: KeyboardEvent) {\n onHandleKeyDown(\"drag\", event);\n }\n\n function onResizeHandlePointerDown(event: ReactPointerEvent) {\n // Calculate the offset between item's bottom-right corner and the pointer landing position.\n const rect = itemRef.current!.getBoundingClientRect();\n pointerOffsetRef.current = new Coordinates({ x: event.clientX - rect.right, y: event.clientY - rect.bottom });\n originalSizeRef.current = { width: rect.width, height: rect.height };\n\n // Calculate boundaries below which the cursor cannot move.\n const minWidth = getItemSize(null).minWidth;\n const minHeight = getItemSize(null).minHeight;\n pointerBoundariesRef.current = new Coordinates({\n x: event.clientX - rect.width + minWidth,\n y: event.clientY - rect.height + minHeight,\n });\n\n draggableApi.start(\"resize\", \"pointer\", Coordinates.fromEvent(event));\n }\n\n function onResizeHandleKeyDown(event: KeyboardEvent) {\n onHandleKeyDown(\"resize\", event);\n }\n\n const itemTransitionStyle: CSSProperties = {};\n const itemTransitionClassNames: string[] = [];\n\n if (inTransition) {\n itemTransitionClassNames.push(styles.inTransition);\n }\n\n if (transition && transition.interactionType === \"pointer\") {\n // Adjust the dragged/resized item to the pointer's location.\n itemTransitionClassNames.push(transition.operation === \"resize\" ? styles.resized : styles.dragged);\n itemTransitionStyle.left = transition.positionTransform?.x;\n itemTransitionStyle.top = transition.positionTransform?.y;\n itemTransitionStyle.width = transition.sizeTransform?.width;\n itemTransitionStyle.height = transition.sizeTransform?.height;\n itemTransitionStyle.pointerEvents = \"none\";\n }\n\n if (isHidden) {\n itemTransitionClassNames.push(styles.hidden);\n }\n\n if (transform) {\n // The moved items positions are altered with CSS transform.\n if (transform.type === \"move\") {\n itemTransitionClassNames.push(styles.transformed);\n itemTransitionStyle.transform = CSSUtil.Transform.toString({\n x: transform.x,\n y: transform.y,\n scaleX: 1,\n scaleY: 1,\n });\n itemTransitionStyle.width = transform.width + \"px\";\n itemTransitionStyle.height = transform.height + \"px\";\n }\n // The item is removed from the DOM after animations play.\n // During the animations the removed item is hidden with styles.\n if (transform.type === \"remove\") {\n itemTransitionClassNames.push(styles.removed);\n }\n }\n\n const dragHandleRef = useRef<HTMLButtonElement>(null);\n useImperativeHandle(ref, () => ({\n focusDragHandle: () => dragHandleRef.current?.focus(),\n }));\n\n const isActive = (!!transition && !isHidden) || !!acquired;\n const shouldUsePortal = transition?.operation === \"insert\" && transition?.interactionType === \"pointer\";\n const childrenRef = useRef<ReactNode>(null);\n if (!inTransition || isActive) {\n childrenRef.current = children(!!transition?.hasDropTarget);\n }\n\n const content = (\n <div\n ref={itemRef}\n className={clsx(styles.root, ...itemTransitionClassNames)}\n style={itemTransitionStyle}\n data-item-id={item.id}\n onBlur={onBlur}\n >\n <ItemContext.Provider\n value={{\n isActive,\n dragHandle: {\n ref: dragHandleRef,\n onPointerDown: onDragHandlePointerDown,\n onKeyDown: onDragHandleKeyDown,\n isActive: isActive && transition?.operation === \"reorder\",\n },\n resizeHandle: placed\n ? {\n onPointerDown: onResizeHandlePointerDown,\n onKeyDown: onResizeHandleKeyDown,\n isActive: isActive && transition?.operation === \"resize\",\n }\n : null,\n }}\n >\n {childrenRef.current}\n </ItemContext.Provider>\n </div>\n );\n\n return shouldUsePortal ? <div>{createPortal(content, document.body)}</div> : content;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine-cache.js","sourceRoot":"","sources":["../../../../src/internal/layout-engine/engine-cache.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAKtC;;;;;GAKG;AACH,MAAM,OAAO,qBAAqB;IAKhC,YAAY,KAAwB;QAJ7B,aAAQ,GAAoB,IAAI,CAAC;QAEhC,SAAI,GAAG,IAAI,KAAK,EAAyB,CAAC;QAGhD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,OAAO,CAAC,QAAkB,EAAE,OAAgC;QAC1D,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,IAAI,EAAE;YAChC,IAAI,QAAQ,CAAC,QAAS,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,IAAI,QAAQ,CAAC,QAAS,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,EAAE;gBAC9E,OAAO,QAAQ,CAAC;aACjB;SACF;QAED,MAAM,QAAQ,GAAG,IAAI,qBAAqB,CAAC,OAAO,EAAE,CAAC,CAAC;QACtD,QAAQ,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAC7B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEzB,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Position } from \"../utils/position\";\nimport { LayoutEngineState } from \"./engine-state\";\n\n/**\n * The cache is used to avoid duplicate computations for the same initial state and path.\n * The cache must be invalidated once the items layout has changed e.g. as result of the operation commit.\n * The cache is a tree of nodes with the root node representing the initial state and empty path. The\n * rest of the tree store all previous state computations per path.\n */\nexport class LayoutEngineCacheNode {\n public position: null | Position = null;\n public state: LayoutEngineState;\n private next = new Array<LayoutEngineCacheNode>();\n\n constructor(state: LayoutEngineState) {\n this.state = state;\n }\n\n /**\n * The function takes path position and the callback to compute the corresponding state if not yet cached.\n * It returns the next cache node to take the next path position if available:\n *\n * const root = new LayoutEngineCacheNode(state)\n *\n * const x1y0 = root\n * .matches({ x: 0, y: 0 }, () => compute({ x: 0, y: 0 })) // computes\n * .matches({ x: 1, y: 0 }, () => compute({ x: 1, y: 0 })) // computes\n * .state;\n *\n * const x2y0 = root\n * .matches({ x: 0, y: 0 }, () => compute({ x: 0, y: 0 }))\n * .matches({ x: 1, y: 0 }, () => compute({ x: 1, y: 0 }))\n * .matches({ x: 2, y: 0 }, () => compute({ x: 2, y: 0 })) // computes\n * .state;\n */\n matches(position: Position, compute: () => LayoutEngineState): LayoutEngineCacheNode {\n for (const nextNode of this.next) {\n if (nextNode.position!.x === position.x && nextNode.position!.y === position.y) {\n return nextNode;\n }\n }\n\n const nextNode = new LayoutEngineCacheNode(compute());\n nextNode.position = position;\n this.next.push(nextNode);\n\n return nextNode;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine-solution.js","sourceRoot":"","sources":["../../../../src/internal/layout-engine/engine-solution.ts"],"names":[],"mappings":"AAAA,qEAA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.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Direction, GridLayoutItem, ItemId } from \"../interfaces\";\nimport { Position } from \"../utils/position\";\nimport { Conflicts } from \"./engine-state\";\nimport { LayoutEngineGrid, ReadonlyLayoutEngineGrid } from \"./grid\";\nimport { CommittedMove } from \"./interfaces\";\nimport { checkOppositeDirections, createMove, getMoveOriginalRect, getMoveRect } from \"./utils\";\n\n// All directions in which overlaps can be incrementally resolved.\nconst PRIORITY_DIRECTIONS: readonly Direction[] = [\"down\", \"right\", \"left\", \"up\"];\n\n// A valid but not yet attempted solution is a pair of the layout state so far and the next move to attempt.\n// The minimal solution score (in case the next move will resolve all overlaps) is state.score + nextMove.score.\nexport type MoveSolution = [state: MoveSolutionState, nextMove: CommittedMove];\n\n// The class represents an intermediate layout state used to find the next set of solutions for.\n// The solution is terminal when no overlaps are left and it can become the next layout state if its\n// score is smaller than that of the alternative solutions.\nexport class MoveSolutionState {\n public grid: LayoutEngineGrid;\n public moves: CommittedMove[];\n public moveIndex = 0;\n public conflicts: null | Conflicts;\n public overlaps = new Map<ItemId, ItemId>();\n public score = 0;\n\n constructor(grid: ReadonlyLayoutEngineGrid, moves: readonly CommittedMove[], conflicts: null | Conflicts) {\n this.grid = LayoutEngineGrid.clone(grid);\n this.moves = [...moves];\n this.moveIndex = moves.length;\n this.conflicts = conflicts;\n }\n\n // The solution state needs to be cloned after the move is performed in case there are overlaps left\n // so that the next solutions won't have the shared state to corrupt.\n // The conflicts never change and can be carried over w/o cloning.\n static clone({ grid, moves, moveIndex, conflicts, overlaps, score }: MoveSolutionState) {\n return {\n grid: LayoutEngineGrid.clone(grid),\n moves: [...moves],\n moveIndex,\n conflicts,\n overlaps: new Map([...overlaps]),\n score,\n };\n }\n}\n\n/**\n * Given a solution state finds a set of all possible moves each resolving a particular overlap.\n */\nexport function findNextSolutions(state: MoveSolutionState): MoveSolution[] {\n // For every overlap and direction found a move if exists that resolves the overlap.\n // A pair of the given state and the overlap resolution move is a new solution to try.\n const nextMoveSolutions: MoveSolution[] = [];\n for (const [overlapId, overlapIssuerId] of state.overlaps) {\n for (const moveDirection of PRIORITY_DIRECTIONS) {\n const move = getOverlapMove(state, overlapId, overlapIssuerId, moveDirection);\n if (move !== null) {\n nextMoveSolutions.push([MoveSolutionState.clone(state), move]);\n }\n }\n }\n return nextMoveSolutions;\n}\n\n// Returns an evaluated move to resolve the given overlap in the given direction or null if such move is not possible.\nfunction getOverlapMove(\n state: MoveSolutionState,\n overlapId: ItemId,\n overlapIssuerId: ItemId,\n moveDirection: Direction\n): null | CommittedMove {\n const userItem = state.grid.getItem(state.moves[0].itemId);\n const overlapItem = state.grid.getItem(overlapId);\n const overlapIssuerItem = state.grid.getItem(overlapIssuerId);\n const overlapMove = getMoveForDirection(overlapItem, overlapIssuerItem, moveDirection);\n\n // The move position is outside the grid boundaries.\n if (overlapMove.x < 0 || overlapMove.y < 0 || overlapMove.x + overlapMove.width > state.grid.width) {\n return null;\n }\n\n // Subsequent item overlap moves in the opposite directions do not contribute to solution.\n const prevOverlapMove = getLastSolutionMove(state, overlapItem.id);\n if (prevOverlapMove && checkOppositeDirections(prevOverlapMove.direction, moveDirection)) {\n return null;\n }\n\n const pathOverlaps = getPathOverlaps(state, overlapMove, overlapIssuerItem);\n for (const overlap of pathOverlaps) {\n // Not allowed to intersect with the user-controlled item.\n if (overlap.id === userItem.id) {\n return null;\n }\n // Not allowed to intersect with conflicting items.\n if (state.conflicts?.items.has(overlap.id)) {\n return null;\n }\n // Intersecting with items having unresolved overlaps does not contribute to solution.\n if (state.overlaps.has(overlap.id)) {\n return null;\n }\n }\n\n const lastIssuerMove = getLastSolutionMove(state, overlapIssuerItem.id);\n if (!lastIssuerMove) {\n throw new Error(\"Invariant violation: overlap issuer has no associated moves.\");\n }\n const issuerDirection = lastIssuerMove.direction;\n\n const isSwap = checkIfSwap(overlapMove, lastIssuerMove);\n const isDifferentIssuerDirection = moveDirection !== issuerDirection;\n const isOppositeIssuerDirection = checkOppositeDirections(moveDirection, issuerDirection);\n const userMoveBoundaries = getUserMoveBoundaries(state);\n const moveVector = getSolutionMovesVector(state);\n\n // Swap score penalizes non-swap overlap resolutions in case the direction does not match that of the issuer.\n const swapPenalty = isSwap ? 0 : 20;\n const differentDirectionPenalty = !isSwap && isDifferentIssuerDirection ? 10 : 0;\n const oppositeDirectionPenalty = !isSwap && isOppositeIssuerDirection ? 500 : 0;\n const swapScore = swapPenalty + differentDirectionPenalty + oppositeDirectionPenalty;\n\n // Overlaps score penalizes moves that cause additional overlaps.\n const overlapsScore = pathOverlaps.size * 50;\n\n // Boundaries score penalize movements of items that are outside the area covered by the user move.\n const moveOutsideUserTopPenalty = overlapItem.y + overlapItem.height - 1 < userMoveBoundaries.top ? 500 : 0;\n const moveOutsideUserLeftPenalty = overlapItem.x + overlapItem.width - 1 < userMoveBoundaries.left ? 50 : 0;\n const moveOutsideUserRightPenalty = overlapItem.x > userMoveBoundaries.right ? 50 : 0;\n const boundariesScore = moveOutsideUserTopPenalty + moveOutsideUserLeftPenalty + moveOutsideUserRightPenalty;\n\n // Move vector score penalize movements that are against the common move direction of other items.\n const vectorXPenalty = overlapMove.distanceX * moveVector.x < 0 ? moveVector.x * 2 : 0;\n const vectorYPenalty = overlapMove.distanceY * moveVector.y < 0 ? moveVector.y * 2 : 0;\n const moveVectorScore = vectorXPenalty + vectorYPenalty;\n\n // Score starts from 1 to avoid overlap moves having 0 score which breaks the solutions cache.\n const score = 1 + swapScore + overlapsScore + moveVectorScore + boundariesScore;\n\n return { ...overlapMove, score };\n}\n\n// Retrieves the first possible move for the given direction to resolve the overlap.\nfunction getMoveForDirection(moveTarget: GridLayoutItem, overlap: GridLayoutItem, direction: Direction): CommittedMove {\n switch (direction) {\n case \"up\":\n return createMove(\"OVERLAP\", moveTarget, new Position({ x: moveTarget.x, y: overlap.y - moveTarget.height }));\n case \"down\":\n return createMove(\"OVERLAP\", moveTarget, new Position({ x: moveTarget.x, y: overlap.y + overlap.height }));\n case \"left\":\n return createMove(\"OVERLAP\", moveTarget, new Position({ x: overlap.x - moveTarget.width, y: moveTarget.y }));\n case \"right\":\n return createMove(\"OVERLAP\", moveTarget, new Position({ x: overlap.x + overlap.width, y: moveTarget.y }));\n }\n}\n\n// Retrieves the last move if exists within the given solution.\nfunction getLastSolutionMove(state: MoveSolutionState, itemId: ItemId): null | CommittedMove {\n let lastMove: null | CommittedMove = null;\n for (let i = state.moves.length - 1; i >= state.moveIndex; i--) {\n if (state.moves[i].itemId === itemId) {\n lastMove = state.moves[i];\n break;\n }\n }\n return lastMove;\n}\n\n// Calculates vector as the amount of cell movements to either direction.\n// All moves in one direction are summarized, the opposite moves cancel each other.\n// The vector show in which direction (left / right, up / down) the most overlaps were resolved.\nfunction getSolutionMovesVector(state: MoveSolutionState): { x: number; y: number } {\n const vector = { x: 0, y: 0 };\n for (let i = state.moveIndex; i < state.moves.length; i++) {\n const move = state.moves[i];\n if (move.type === \"OVERLAP\") {\n vector.x += move.distanceX * move.height;\n vector.y += move.distanceY * move.width;\n }\n }\n return vector;\n}\n\n// Finds a rectangle within which the user-controlled item was moved (previous and current positions only).\n// The layout items outside the boundaries are not expected to be disturbed.\nfunction getUserMoveBoundaries(state: MoveSolutionState): { top: number; right: number; bottom: number; left: number } {\n const firstUserMove = state.moves[0];\n const lastUserMove = state.moves[state.moveIndex];\n if (!firstUserMove || !lastUserMove || firstUserMove.itemId !== lastUserMove.itemId) {\n throw new Error(\"Invariant violation: unexpected user move.\");\n }\n const original = getMoveOriginalRect(lastUserMove);\n const current = getMoveRect(lastUserMove);\n return {\n top: Math.min(original.top, current.top),\n right: Math.max(original.right, current.right),\n bottom: Math.max(original.bottom, current.bottom),\n left: Math.min(original.left, current.left),\n };\n}\n\n// Finds all overlaps that the move will cause along its path not considering the original location and original overlap.\nfunction getPathOverlaps(\n state: MoveSolutionState,\n move: CommittedMove,\n overlapIssuerItem: GridLayoutItem\n): Set<GridLayoutItem> {\n const { left, right, top, bottom } = getMoveOriginalRect(move);\n const startX = move.distanceX <= 0 ? move.x : right + 1;\n const endX = move.distanceX < 0 ? left - 1 : right + move.distanceX;\n const startY = move.distanceY <= 0 ? move.y : bottom + 1;\n const endY = move.distanceY < 0 ? top - 1 : bottom + move.distanceY;\n\n const pathOverlaps = new Set(\n state.grid.getOverlaps({\n id: move.itemId,\n x: startX,\n width: 1 + endX - startX,\n y: startY,\n height: 1 + endY - startY,\n })\n );\n pathOverlaps.delete(overlapIssuerItem);\n\n return pathOverlaps;\n}\n\n// Checks if the overlap move is a swap with the user-moved item.\nfunction checkIfSwap(overlapMove: CommittedMove, lastIssuerMove: CommittedMove): boolean {\n if (lastIssuerMove.type !== \"MOVE\") {\n return false;\n }\n if (!checkOppositeDirections(overlapMove.direction, lastIssuerMove.direction)) {\n return false;\n }\n const overlapRect = getMoveOriginalRect(overlapMove);\n const issuerRect = getMoveRect(lastIssuerMove);\n switch (lastIssuerMove.direction) {\n case \"up\":\n return overlapRect.top === issuerRect.top;\n case \"right\":\n return overlapRect.right === issuerRect.right;\n case \"down\":\n return overlapRect.bottom === issuerRect.bottom;\n case \"left\":\n return overlapRect.left === issuerRect.left;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine-state.js","sourceRoot":"","sources":["../../../../src/internal/layout-engine/engine-state.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAMtC;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IAK5B,YAAY,IAAsB,EAAE,QAAQ,IAAI,KAAK,EAAiB,EAAE,YAA8B,IAAI;QACxG,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Direction, ItemId } from \"../interfaces\";\nimport { LayoutEngineGrid, ReadonlyLayoutEngineGrid } from \"./grid\";\nimport { CommittedMove } from \"./interfaces\";\n\n/**\n * The class describes the layout engine state at a particular path step.\n * The state of the last performed step is the command result.\n */\nexport class LayoutEngineState {\n public grid: ReadonlyLayoutEngineGrid;\n public moves: readonly CommittedMove[];\n public conflicts: null | Conflicts;\n\n constructor(grid: LayoutEngineGrid, moves = new Array<CommittedMove>(), conflicts: null | Conflicts = null) {\n this.grid = grid;\n this.moves = moves;\n this.conflicts = conflicts;\n }\n}\n\nexport interface Conflicts {\n items: ReadonlySet<ItemId>;\n direction: Direction;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine-step.js","sourceRoot":"","sources":["../../../../src/internal/layout-engine/engine-step.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAgB,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAIvF,OAAO,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,uFAAuF;AACvF,wFAAwF;AACxF,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAE/B,sFAAsF;AACtF,sGAAsG;AACtG,uCAAuC;AACvC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAE7B;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,WAA8B,EAAE,QAAuB;IACrF,+DAA+D;IAC/D,oHAAoH;IACpH,qHAAqH;IACrH,+EAA+E;IAC/E,MAAM,SAAS,GAAG,aAAa,CAAC,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAEnF,gHAAgH;IAChH,oHAAoH;IACpH,kHAAkH;IAClH,0EAA0E;IAC1E,+GAA+G;IAC/G,MAAM,YAAY,GAA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,CAAC,eAAe,CAAC,CAAC,EAAE;YAC/F,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;SAClC;KACF;AACH,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Position } from \"../utils/position\";\nimport { MoveSolution, MoveSolutionState, findNextSolutions } from \"./engine-solution\";\nimport { Conflicts, LayoutEngineState } from \"./engine-state\";\nimport { ReadonlyLayoutEngineGrid } from \"./grid\";\nimport { CommittedMove } from \"./interfaces\";\nimport { checkItemsIntersection, sortGridItems } from \"./utils\";\nimport { createMove } from \"./utils\";\n\n// The solutions can't be searched for infinitely in case the algorithm can't converge.\n// The safety counter ensures there is going to be user feedback within reasonable time.\nconst MAX_SOLUTION_DEPTH = 100;\n\n// At any given step only a few best solutions are taken to ensure faster convergence.\n// The larger the number the better chance the most optimal solution is found for the given priorities\n// at a cost of more computations made.\nconst NUM_BEST_SOLUTIONS = 5;\n\n/**\n * The function takes the current layout state (item placements from the previous steps and all moves done so far)\n * and a user command increment that describes an item transition by one cell in some direction.\n * The function finds overlapping elements and resolves all overlaps if possible (always possible when no conflicts).\n * The result in an updated state (new item placements, additional moves, and item conflicts if any).\n */\nexport function resolveOverlaps(layoutState: LayoutEngineState, userMove: CommittedMove): LayoutEngineState {\n // For better UX the layout engine is optimized for item swaps.\n // The swapping is only preferred for the user-controlled item and it can only happen when the item overlaps another\n // item past its midpoint. When the overlap is not enough, the underlying item is considered a conflict and it is not\n // allowed to move anywhere. The user command cannot be committed at this step.\n const conflicts = findConflicts(layoutState.grid, layoutState.conflicts, userMove);\n\n // The user moves are always applied as is. When the user-controlled item overlaps with other items and there is\n // no conflict, the type=\"OVERLAP\" moves are performed to settle the grid so that no items overlap with one another.\n // For this type of move multiple solutions are often available. To ensure the best result all solutions are tried\n // and a score is given to each. The solution with the minimal score wins.\n // The process stars from the initial state and the user move. The initial score and the user move score are 0.\n const initialState = new MoveSolutionState(layoutState.grid, layoutState.moves, conflicts);\n const initialSolution: MoveSolution = [initialState, userMove];\n\n // All solutions are guaranteed to have unique move sequences but different move sequences can produce the same result.\n // As it is never expected for one item to be moved over to the same location twice the combination of the item ID,\n // item position, and solution score can uniquely represent the solution.\n // For earlier moves taking a solution from the cache can prevent hundreds of subsequent computations.\n const solutionsCache = new Map<string, MoveSolution>();\n const createCacheKey = ([state, move]: MoveSolution) =>\n `${move.itemId} ${move.x}:${move.y}:${state.score + move.score}`;\n\n let moveSolutions: MoveSolution[] = [initialSolution];\n let bestSolution: null | MoveSolutionState = null;\n let convergenceCounter = MAX_SOLUTION_DEPTH;\n\n // The resolution process continues until there is at least one reasonable solution left.\n // The repetitive, dead-end, and expensive (compared to the best so far) solutions are excluded\n // so that eventually no more variants to try remain.\n // The convergence safety counter ensures the logical errors to not cause an infinite loop.\n while (moveSolutions.length > 0) {\n let nextSolutions: MoveSolution[] = [];\n\n for (let solutionIndex = 0; solutionIndex < Math.min(NUM_BEST_SOLUTIONS, moveSolutions.length); solutionIndex++) {\n const [solutionState, solutionMove] = moveSolutions[solutionIndex];\n\n // Discard the solution before performing the move if its next score is already above the best score found so far.\n if (bestSolution && solutionState.score + solutionMove.score >= bestSolution.score) {\n continue;\n }\n\n // Perform the move by mutating the solution's state: grid, moves, score, etc.\n makeMove(solutionState, solutionMove);\n\n // If no overlaps are left the solution is considered valid and the best so far.\n // The next solutions having the same or higher score will be discarded.\n if (solutionState.overlaps.size === 0) {\n bestSolution = solutionState;\n }\n // Otherwise, the next set of solutions will be considered. There can be up to four solutions per overlap\n // (by the number of possible directions to move).\n else {\n for (const nextSolution of findNextSolutions(solutionState)) {\n const solutionKey = createCacheKey(nextSolution);\n const cachedSolution = solutionsCache.get(solutionKey);\n if (!cachedSolution) {\n nextSolutions.push(nextSolution);\n solutionsCache.set(solutionKey, nextSolution);\n }\n }\n }\n }\n\n // The solutions are ordered by the total score so that the best (so far) solutions are considered first.\n moveSolutions = nextSolutions.sort((s1, s2) => s1[0].score + s1[1].score - (s2[0].score + s2[1].score));\n nextSolutions = [];\n\n // Reaching the convergence counter might indicate an issue with the algorithm as ideally it should converge faster.\n // However, that does not necessarily mean the logical problem and no exception should be thrown.\n // Instead, the current best solution if available applies or a simple solution is offered instead.\n convergenceCounter--;\n if (convergenceCounter <= 0) {\n break;\n }\n }\n\n // If there are conflicts it might not be possible to find a solution as the items are not allowed to\n // overlap with the conflicts. In that case the initial state (with the user move applied) is returned.\n // The user can move the item further to resolve the conflicts which will also unblock the overlaps resolution.\n // Also, the solution might not be found due to the engine constraints. For example, the convergence number might\n // be reached before any solution is found or the number of best solutions constraint can filter the only possible\n // solutions away. In that case the simple solution is returned with all overlapping items pushed to the bottom.\n if (!bestSolution) {\n bestSolution = initialState.conflicts ? initialState : resolveOverlapsDown(initialState);\n }\n\n // After each step unless there are conflicts the type=\"FLOAT\" moves are performed on all items\n // but the user controlled one that can be moved to the top without overlapping with other items.\n return bestSolution.conflicts ? bestSolution : refloatGrid(bestSolution, userMove);\n}\n\n// Resolves overlaps the simple way by pushing all overlapping items to the bottom until none is left.\nfunction resolveOverlapsDown(state: MoveSolutionState): MoveSolutionState {\n // Move overlapping items to the bottom until resolved. Repeat until no overlaps left.\n // This solution always converges because there is always free space at the bottom by design.\n while (state.overlaps.size > 0) {\n const overlaps = sortGridItems([...state.overlaps].map(([overlapId]) => state.grid.getItem(overlapId)));\n for (const overlap of overlaps) {\n let y = overlap.y + 1;\n while (state.grid.getOverlaps({ ...overlap, y }).length > 0) {\n y++;\n }\n makeMove(state, createMove(\"OVERLAP\", overlap, new Position({ x: overlap.x, y })));\n }\n }\n return state;\n}\n\n// Find items that can \"float\" to the top and apply the necessary moves.\nfunction refloatGrid(layoutState: LayoutEngineState, userMove?: CommittedMove): LayoutEngineState {\n const state = new MoveSolutionState(layoutState.grid, layoutState.moves, layoutState.conflicts);\n\n function makeRefloat() {\n let needAnotherRefloat = false;\n\n for (const item of state.grid.items) {\n // The active item is skipped until the operation is committed.\n if (item.id === userMove?.itemId) {\n continue;\n }\n\n let y = item.y - 1;\n let move: null | CommittedMove = null;\n while (y >= 0) {\n const moveAttempt = createMove(\"FLOAT\", item, new Position({ x: item.x, y }));\n if (state.grid.getOverlaps({ id: item.id, ...moveAttempt }).length > 0) {\n break;\n }\n y--;\n move = moveAttempt;\n }\n if (move) {\n makeMove(state, move);\n needAnotherRefloat = true;\n }\n }\n\n if (needAnotherRefloat) {\n makeRefloat();\n }\n }\n\n makeRefloat();\n\n return state;\n}\n\n// Finds items that cannot be resolved at the current step as of being partially overlapped by the user-move item.\nfunction findConflicts(\n grid: ReadonlyLayoutEngineGrid,\n previousConflicts: null | Conflicts,\n userMove: CommittedMove\n): null | Conflicts {\n // The conflicts are only defined for MOVE command type to make swaps possible.\n if (userMove.type !== \"MOVE\") {\n return null;\n }\n // Using existing conflict direction if available so that conflicting items would swap consistently.\n // If only the current direction is considered the multi-item conflicts become difficult to comprehend.\n const direction = previousConflicts?.direction ?? userMove.direction;\n // Conflicts are partial overlaps. When the item is overlapped fully (considering the direction) it is\n // no longer treated as conflict.\n const overlaps = grid.getOverlaps({ ...userMove, id: userMove.itemId });\n const conflicts = overlaps.filter((overlap) => {\n switch (direction) {\n case \"left\":\n return overlap.x < userMove.x;\n case \"right\":\n return overlap.x + overlap.width - 1 > userMove.x + userMove.width - 1;\n case \"up\":\n return overlap.y < userMove.y;\n case \"down\":\n return overlap.y + overlap.height - 1 > userMove.y + userMove.height - 1;\n }\n });\n if (conflicts.length > 0) {\n return { direction, items: new Set(conflicts.map((item) => item.id)) };\n }\n return null;\n}\n\n// Applies given move to the solution state by updating the grid, moves, overlaps, and score.\nfunction makeMove(state: MoveSolutionState, nextMove: CommittedMove): void {\n updateGridWithMove(state, nextMove);\n updateOverlaps(state, nextMove);\n state.moves.push(nextMove);\n state.score += nextMove.score;\n}\n\nfunction updateGridWithMove({ grid }: MoveSolutionState, move: CommittedMove): void {\n switch (move.type) {\n case \"MOVE\":\n case \"OVERLAP\":\n case \"FLOAT\":\n return grid.move(move.itemId, move.x, move.y);\n case \"INSERT\":\n return grid.insert({ id: move.itemId, ...move });\n case \"REMOVE\":\n return grid.remove(move.itemId);\n case \"RESIZE\":\n return grid.resize(move.itemId, move.width, move.height);\n }\n}\n\nfunction updateOverlaps(state: MoveSolutionState, move: CommittedMove) {\n // Find and assign items that will overlap with the moved item after the move is performed\n // unless the overlapping items are considered as conflicts.\n for (const newOverlap of state.grid.getOverlaps({ ...move, id: move.itemId })) {\n if (!state.conflicts?.items.has(newOverlap.id)) {\n state.overlaps.set(newOverlap.id, move.itemId);\n }\n }\n // Remove no longer valid overlaps after the move is performed.\n for (const [overlapId, overlapIssuerId] of state.overlaps) {\n if (!checkItemsIntersection(state.grid.getItem(overlapId), state.grid.getItem(overlapIssuerId))) {\n state.overlaps.delete(overlapId);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../../../src/internal/layout-engine/engine.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAGtC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE5F;;;;;GAKG;AACH,MAAM,OAAO,YAAY;IAIvB,YAAY,MAAkB;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,IAAI,qBAAqB,CAAC,IAAI,iBAAiB,CAAC,IAAI,gBAAgB,CAAC,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iliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { GridLayout, ItemId } from \"../interfaces\";\nimport { Position } from \"../utils/position\";\nimport { LayoutEngineCacheNode } from \"./engine-cache\";\nimport { LayoutEngineState } from \"./engine-state\";\nimport { resolveOverlaps } from \"./engine-step\";\nimport { LayoutEngineGrid } from \"./grid\";\nimport { InsertCommand, LayoutShift, MoveCommand, ResizeCommand } from \"./interfaces\";\nimport { createMove, normalizeMovePath, normalizeResizePath, sortGridItems } from \"./utils\";\n\n/**\n * Layout engine is an abstraction to compute effects of user actions (move, resize, insert, remove).\n * The engine is initialized with the board state and then takes a command to calculate the respective layout shift.\n * Use a single engine instance until the user commits their move to take advantage of the internal cache.\n * Once user move is committed the layout engine needs to be re-initialized with the updated layout state.\n */\nexport class LayoutEngine {\n private layout: GridLayout;\n private cache: LayoutEngineCacheNode;\n\n constructor(layout: GridLayout) {\n this.layout = layout;\n this.cache = new LayoutEngineCacheNode(new LayoutEngineState(new LayoutEngineGrid(layout.items, layout.columns)));\n }\n\n move(moveCommand: MoveCommand, cache = this.cache): LayoutShift {\n // The validation ensures no position in the path is outside the board and updates the path so that all\n // positions are incremental (moving one cell at a time) and no loops are present (no position can occur twice).\n // Removing the loops guarantees that moving back to one of the previous positions including the starting one\n // revives the previous state as is. The same behavior might cause confusion in case the user comes back\n // to a previous position accidentally especially if the move path is long.\n const path = this.validateMovePath({ ...moveCommand }, cache.state);\n\n // The user command is resolved one step at a time. When layout engine is reused withing one transition\n // it is expected that all steps but the last one are already cached.\n for (let stepIndex = 0; stepIndex < path.length; stepIndex++) {\n const item = cache.state.grid.getItem(moveCommand.itemId);\n const move = createMove(\"MOVE\", item, path[stepIndex]);\n cache = cache.matches(path[stepIndex], () => resolveOverlaps(cache.state, move));\n }\n\n return this.getLayoutShift(cache.state);\n }\n\n resize(resizeCommand: ResizeCommand): LayoutShift {\n // The validation ensures no position in the path is outside the board and the width/height are above 0.\n // The resize path is updated so that all positions are incremental (moving one cell at a time) and\n // no loops are present (no position can occur twice).\n // Removing the loops guarantees that moving back to one of the previous positions including the starting one\n // revives the previous state as is. The same behavior might cause confusion in case the user comes back\n // to a previous position accidentally especially if the move path is long.\n const path = this.validateResizePath(resizeCommand, this.cache.state);\n\n // The user command is resolved one step at a time. When layout engine is reused withing one transition\n // it is expected that all steps but the last one are already cached.\n let cache = this.cache;\n for (let stepIndex = 0; stepIndex < path.length; stepIndex++) {\n const resizeTarget = cache.state.grid.getItem(resizeCommand.itemId);\n const width = path[stepIndex].x - resizeTarget.x;\n const height = path[stepIndex].y - resizeTarget.y;\n const move = createMove(\"RESIZE\", resizeTarget, new Position({ x: width, y: height }));\n cache = cache.matches(path[stepIndex], () => resolveOverlaps(cache.state, move));\n }\n\n return this.getLayoutShift(cache.state);\n }\n\n insert({ itemId, width, height, path: [position, ...movePath] }: InsertCommand): LayoutShift {\n // For insert command the new item is injected to the given location first and then it can be moved\n // the same way as the existing item would.\n const insertMove = createMove(\"INSERT\", { id: itemId, x: position.x, y: position.y, width, height }, position);\n const cache = this.cache.matches(position, () => resolveOverlaps(this.cache.state, insertMove));\n\n return this.move({ itemId, path: movePath }, cache);\n }\n\n remove(itemId: ItemId): LayoutShift {\n // The remove command does not define the move path and is not cached. It is expected to be performed only once.\n const { x, y, width, height } = this.cache.state.grid.getItem(itemId);\n const move = createMove(\"REMOVE\", { id: itemId, x, y, width, height }, new Position({ x, y }));\n const state = resolveOverlaps(this.cache.state, move);\n return this.getLayoutShift(state);\n }\n\n private getLayoutShift(state: LayoutEngineState): LayoutShift {\n return {\n current: this.layout,\n next: {\n items: sortGridItems(state.grid.items),\n columns: state.grid.width,\n rows: state.grid.height,\n },\n moves: state.moves,\n conflicts: state.conflicts ? [...state.conflicts.items] : [],\n };\n }\n\n private validateMovePath({ itemId, path }: MoveCommand, state: LayoutEngineState): readonly Position[] {\n const moveTarget = state.grid.getItem(itemId);\n for (const step of path) {\n if (step.x < 0 || step.y < 0 || step.x + moveTarget.width > state.grid.width) {\n throw new Error(\"Invalid move: outside grid.\");\n }\n }\n return normalizeMovePath(new Position({ x: moveTarget.x, y: moveTarget.y }), path);\n }\n\n private validateResizePath({ itemId, path }: ResizeCommand, state: LayoutEngineState): readonly Position[] {\n const resizeTarget = state.grid.getItem(itemId);\n const x = resizeTarget.x + resizeTarget.width;\n const y = resizeTarget.y + resizeTarget.height;\n for (const step of path) {\n if (step.x < 1 || step.y < 1) {\n throw new Error(\"Invalid resize: can't resize to 0.\");\n }\n if (step.x > state.grid.width) {\n throw new Error(\"Invalid resize: outside grid.\");\n }\n }\n return normalizeResizePath(new Position({ x, y }), path);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grid.js","sourceRoot":"","sources":["../../../../src/internal/layout-engine/grid.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAGtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEjD,MAAM,OAAO,wBAAwB;IAMnC,MAAM,CAAC,KAAK,CAAC,IAA8B;QACzC,MAAM,KAAK,GAAG,IAAI,gBAAgB,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QAC1C,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE;YAC9B,MAAM,SAAS,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC;YAC9B,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;YAC7C,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;SAC9B;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,YAAY,KAAgC,EAAE,OAAe;QAfnD,WAAM,GAAG,IAAI,KAAK,EAAkB,CAAC;QACrC,cAAS,GAA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C,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE;YACjE,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;SAC9D;QACD,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YACrC,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;SACrD;QACD,MAAM,SAAS,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC;QAC9B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC5B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAC7D,CAAC;IAED,MAAM,CAAC,MAAc;QACnB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,MAAM,CAAC,CAAC;IACjE,CAAC;CACF","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { GridLayoutItem, ItemId } from \"../interfaces\";\nimport { checkItemsIntersection } from \"./utils\";\n\nexport class ReadonlyLayoutEngineGrid {\n protected _width: number;\n protected _height: number;\n protected _items = new Array<GridLayoutItem>();\n protected _itemsMap = new Map<ItemId, GridLayoutItem>();\n\n static clone(grid: ReadonlyLayoutEngineGrid): LayoutEngineGrid {\n const clone = new LayoutEngineGrid([], 0);\n clone._width = grid._width;\n clone._height = grid._height;\n for (const item of grid._items) {\n const itemClone = { ...item };\n clone._itemsMap.set(itemClone.id, itemClone);\n clone._items.push(itemClone);\n }\n return clone;\n }\n\n constructor(items: readonly GridLayoutItem[], columns: number) {\n this._width = columns;\n this._height = 0;\n\n for (const item of items) {\n if (item.x < 0 || item.y < 0 || item.x + item.width > this._width) {\n throw new Error(\"Invalid grid: items outside the boundaries.\");\n }\n if (item.width < 1 || item.height < 1) {\n throw new Error(\"Invalid grid: items of invalid size.\");\n }\n\n for (const gridItem of this._items) {\n if (checkItemsIntersection(gridItem, item)) {\n throw new Error(\"Invalid grid: items overlap.\");\n }\n }\n\n const itemClone = { ...item };\n this._itemsMap.set(itemClone.id, itemClone);\n this._items.push(itemClone);\n this._height = Math.max(this.height, itemClone.y + itemClone.height);\n }\n }\n\n get width(): number {\n return this._width;\n }\n\n get height(): number {\n return this._height;\n }\n\n get items(): GridLayoutItem[] {\n return this._items;\n }\n\n getItem(itemId: ItemId): GridLayoutItem {\n const item = this._itemsMap.get(itemId);\n if (!item) {\n throw new Error(`Item with id \"${itemId}\" not found in the grid.`);\n }\n return item;\n }\n\n getOverlaps(item: GridLayoutItem): GridLayoutItem[] {\n return this._items.filter((gridItem) => checkItemsIntersection(gridItem, item));\n }\n}\n\nexport class LayoutEngineGrid extends ReadonlyLayoutEngineGrid {\n move(itemId: ItemId, x: number, y: number): void {\n const item = this.getItem(itemId);\n item.x = x;\n item.y = y;\n this._height = Math.max(this.height, item.y + item.height);\n }\n\n resize(itemId: ItemId, width: number, height: number): void {\n const item = this.getItem(itemId);\n item.width = width;\n item.height = height;\n this._height = Math.max(this.height, item.y + item.height);\n }\n\n insert(item: GridLayoutItem): void {\n if (item.x < 0 || item.y < 0 || item.x + item.width > this._width) {\n throw new Error(\"Inserting item is outside the boundaries.\");\n }\n if (item.width < 1 || item.height < 1) {\n throw new Error(\"Inserting item has invalid size.\");\n }\n const itemClone = { ...item };\n this._itemsMap.set(itemClone.id, itemClone);\n this._items.push(itemClone);\n this._height = Math.max(this.height, item.y + item.height);\n }\n\n remove(itemId: ItemId): void {\n this._itemsMap.delete(itemId);\n this._items = this._items.filter((item) => item.id !== itemId);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../src/internal/layout-engine/interfaces.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Direction, GridLayout, ItemId } from \"../interfaces\";\nimport { Position } from \"../utils/position\";\n\nexport interface MoveCommand {\n itemId: ItemId;\n path: readonly Position[];\n}\n\nexport interface ResizeCommand {\n itemId: ItemId;\n path: readonly Position[];\n}\n\nexport interface InsertCommand {\n itemId: ItemId;\n width: number;\n height: number;\n path: readonly Position[];\n}\n\nexport interface CommittedMove {\n itemId: ItemId;\n x: number;\n y: number;\n width: number;\n height: number;\n type: \"MOVE\" | \"RESIZE\" | \"INSERT\" | \"REMOVE\" | \"OVERLAP\" | \"FLOAT\";\n direction: Direction;\n distanceX: number;\n distanceY: number;\n score: number;\n}\n\nexport interface LayoutShift {\n current: GridLayout;\n next: GridLayout;\n moves: readonly CommittedMove[];\n conflicts: readonly ItemId[];\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/internal/layout-engine/utils.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAGtC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAU7C,MAAM,UAAU,aAAa,CAAC,KAAuB;IACnD,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC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C,eAAe,GAAG,CAAC,CAAC,CAAC;AACzC,CAAC;AAED,kDAAkD;AAClD,SAAS,kBAAkB,CAAC,MAAgB,EAAE,IAAyB;IACrE,MAAM,cAAc,GAAe,EAAE,CAAC;IAEtC,IAAI,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC;IACrB,IAAI,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC;IAErB,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE;QACvB,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;QACrC,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;QAErC,KAAK,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,GAAI;YAC7D,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,EAAE;gBAChB,CAAC,IAAI,EAAE,CAAC;aACT;iBAAM;gBACL,CAAC,IAAI,EAAE,CAAC;aACT;YACD,cAAc,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;SAC7C;QAED,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC;QACf,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC;KAChB;IAED,OAAO,cAAc,CAAC;AACxB,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Direction, GridLayoutItem } from \"../interfaces\";\nimport { Position } from \"../utils/position\";\nimport { CommittedMove } from \"./interfaces\";\n\nexport interface Rect {\n left: number;\n right: number;\n top: number;\n bottom: number;\n}\n\nexport function sortGridItems(items: GridLayoutItem[]): readonly GridLayoutItem[] {\n return items.sort((a, b) => (b.y - a.y === 0 ? b.x - a.x : b.y - a.y));\n}\n\nexport function normalizeMovePath(origin: Position, path: readonly Position[]): readonly Position[] {\n path = normalizePathOrigin(origin, path);\n\n // Store last visited indexes per position.\n const positionToLastIndex = new Map<string, number>();\n for (let index = 0; index < path.length; index++) {\n positionToLastIndex.set(`${path[index].x}:${path[index].y}`, index);\n }\n\n // Compose path from last visited indices only.\n const normalizedPath: Position[] = [];\n let index = 0;\n while (index < path.length) {\n const lastVisitedIndex = positionToLastIndex.get(`${path[index].x}:${path[index].y}`)!;\n normalizedPath.push(path[lastVisitedIndex]);\n index = lastVisitedIndex + 1;\n }\n\n return normalizePathSteps(origin, normalizedPath);\n}\n\nexport function normalizeResizePath(origin: Position, path: readonly Position[]): readonly Position[] {\n path = normalizePathOrigin(origin, path);\n\n if (path.length === 0) {\n return [];\n }\n\n const normalizedPath: Position[] = [path[path.length - 1]];\n for (let stepIndex = path.length - 2; stepIndex >= 0; stepIndex--) {\n const prev = normalizedPath[normalizedPath.length - 1];\n const current = path[stepIndex];\n if (current.x < prev.x || current.y < prev.y) {\n normalizedPath.push(current);\n }\n }\n normalizedPath.reverse();\n\n return normalizePathSteps(origin, normalizedPath);\n}\n\nexport function createMove(\n type: CommittedMove[\"type\"],\n item: GridLayoutItem,\n next: Position,\n score = 0\n): CommittedMove {\n const distanceX = type === \"RESIZE\" ? next.x - item.width : next.x - item.x;\n const distanceY = type === \"RESIZE\" ? next.y - item.height : next.y - item.y;\n return {\n type,\n itemId: item.id,\n x: type !== \"RESIZE\" ? next.x : item.x,\n y: type !== \"RESIZE\" ? next.y : item.y,\n width: type === \"RESIZE\" ? next.x : item.width,\n height: type === \"RESIZE\" ? next.y : item.height,\n direction: distanceX > 0 ? \"right\" : distanceX < 0 ? \"left\" : distanceY < 0 ? \"up\" : \"down\",\n distanceX,\n distanceY,\n score,\n };\n}\n\nexport function getMoveOriginalRect(move: CommittedMove): Rect {\n return {\n left: move.x - move.distanceX,\n right: move.x - move.distanceX + move.width - 1,\n top: move.y - move.distanceY,\n bottom: move.y - move.distanceY + move.height - 1,\n };\n}\n\nexport function getMoveRect(move: CommittedMove): Rect {\n return {\n left: move.x,\n right: move.x + move.width - 1,\n top: move.y,\n bottom: move.y + move.height - 1,\n };\n}\n\nexport function checkItemsIntersection(i1: GridLayoutItem, i2: GridLayoutItem): boolean {\n if (i1.id === i2.id) {\n return false;\n }\n return (\n i1.x <= i2.x + i2.width - 1 &&\n i2.x <= i1.x + i1.width - 1 &&\n i1.y <= i2.y + i2.height - 1 &&\n i2.y <= i1.y + i1.height - 1\n );\n}\n\nexport function checkOppositeDirections(d1: Direction, d2: Direction): boolean {\n return (\n (d1 === \"down\" && d2 === \"up\") ||\n (d1 === \"up\" && d2 === \"down\") ||\n (d1 === \"left\" && d2 === \"right\") ||\n (d1 === \"right\" && d2 === \"left\")\n );\n}\n\n// Removes path prefixes that return to the original location.\nfunction normalizePathOrigin(origin: Position, path: readonly Position[]): readonly Position[] {\n let lastOriginIndex = -1;\n for (let i = 0; i < path.length; i++) {\n if (path[i].x === origin.x && path[i].y === origin.y) {\n lastOriginIndex = i;\n }\n }\n return path.slice(lastOriginIndex + 1);\n}\n\n// Ensures path only includes single-length steps.\nfunction normalizePathSteps(origin: Position, path: readonly Position[]): readonly Position[] {\n const normalizedPath: Position[] = [];\n\n let prevX = origin.x;\n let prevY = origin.y;\n\n for (const step of path) {\n const vx = Math.sign(step.x - prevX);\n const vy = Math.sign(step.y - prevY);\n\n for (let x = prevX, y = prevY; x !== step.x || y !== step.y; ) {\n if (x !== step.x) {\n x += vx;\n } else {\n y += vy;\n }\n normalizedPath.push(new Position({ x, y }));\n }\n\n prevX = step.x;\n prevY = step.y;\n }\n\n return normalizedPath;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/internal/live-region/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EAAE,IAAI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EnD,MAAC,gBAAgB,OAAK,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,SAAS,aAC5D,CAAC,OAAO,IAAI,CACX,eAAM,GAAG,EAAE,SAAS,iBAAc,MAAM,YACrC,QAAQ,GACJ,CACR,EAED,eAAM,GAAG,EAAE,SAAS,iBAAc,MAAM,eAAY,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,GAAS,IAC9E,IAClB,CACJ,CAAC;AACJ,CAAC;AAED,oGAAoG;AACpG,oGAAoG;AACpG,0FAA0F;AAC1F,SAAS,gBAAgB,CAAC,IAAiB;IACzC,OAAO,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AAC5D,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { memo, useEffect, useRef } from \"react\";\nimport ScreenreaderOnly, { ScreenreaderOnlyProps } from \"../screenreader-only\";\n\n// The code is copied from https://github.com/cloudscape-design/components/blob/main/src/internal/components/live-region/index.tsx\n\nexport interface LiveRegionProps extends ScreenreaderOnlyProps {\n assertive?: boolean;\n delay?: number;\n visible?: boolean;\n children: React.ReactNode;\n}\n\n/**\n * The live region is hidden in the layout, but visible for screen readers.\n * It's purpose it to announce changes e.g. when custom navigation logic is used.\n *\n * The way live region works differently in different browsers and screen readers and\n * it is recommended to manually test every new implementation.\n *\n * If you notice there are different words being merged together,\n * check if there are text nodes not being wrapped in elements, like:\n * <LiveRegion>\n * {title}\n * <span><Details /></span>\n * </LiveRegion>\n *\n * To fix, wrap \"title\" in an element:\n * <LiveRegion>\n * <span>{title}</span>\n * <span><Details /></span>\n * </LiveRegion>\n *\n * Or create a single text node if possible:\n * <LiveRegion>\n * {`${title} ${details}`}\n * </LiveRegion>\n *\n * The live region is always atomic, because non-atomic regions can be treated by screen readers\n * differently and produce unexpected results. To imitate non-atomic announcements simply use\n * multiple live regions:\n * <>\n * <LiveRegion>{title}</LiveRegion>\n * <LiveRegion><Details /></LiveRegion>\n * </>\n */\nexport default memo(LiveRegion);\n\nfunction LiveRegion({ assertive = false, delay = 10, visible = false, children, ...restProps }: LiveRegionProps) {\n const sourceRef = useRef<HTMLSpanElement>(null);\n const targetRef = useRef<HTMLSpanElement>(null);\n\n /*\n When React state changes, React often produces too many DOM updates, causing NVDA to\n issue many announcements for the same logical event (See https://github.com/nvaccess/nvda/issues/7996).\n The code below imitates a debouncing, scheduling a callback every time new React state\n update is detected. When a callback resolves, it copies content from a muted element\n to the live region, which is recognized by screen readers as an update.\n If the use case requires no announcement to be ignored, use delay = 0, but ensure it\n does not impact the performance. If it does, prefer using a string as children prop.\n */\n useEffect(() => {\n function updateLiveRegion() {\n if (targetRef.current && sourceRef.current) {\n const sourceContent = extractInnerText(sourceRef.current);\n const targetContent = extractInnerText(targetRef.current);\n if (targetContent !== sourceContent) {\n // The aria-atomic does not work properly in Voice Over, causing\n // certain parts of the content to be ignored. To fix that,\n // we assign the source text content as a single node.\n targetRef.current.innerText = sourceContent;\n }\n }\n }\n\n let timeoutId: null | ReturnType<typeof setTimeout>;\n if (delay) {\n timeoutId = setTimeout(updateLiveRegion, delay);\n } else {\n updateLiveRegion();\n }\n\n return () => {\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n };\n });\n\n return (\n <>\n {visible && <span ref={sourceRef}>{children}</span>}\n\n <ScreenreaderOnly {...restProps} className={restProps.className}>\n {!visible && (\n <span ref={sourceRef} aria-hidden=\"true\">\n {children}\n </span>\n )}\n\n <span ref={targetRef} aria-atomic=\"true\" aria-live={assertive ? \"assertive\" : \"polite\"}></span>\n </ScreenreaderOnly>\n </>\n );\n}\n\n// This only extracts text content from the node including all its children which is enough for now.\n// To make it more powerful, it is possible to create a more sophisticated extractor with respect to\n// ARIA properties to ignore aria-hidden nodes and read ARIA labels from the live content.\nfunction extractInnerText(node: HTMLElement) {\n return (node.innerText || \"\").replace(/\\s+/g, \" \").trim();\n}\n"]}
|
package/internal/manifest.json
CHANGED