@cloudscape-design/board-components 3.0.59 → 3.0.60
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/internal.js.map +1 -1
- package/board/transition.js.map +1 -1
- package/board/utils/announcements.js.map +1 -1
- package/board/utils/events.js.map +1 -1
- package/board/utils/get-hovered-rect.js.map +1 -1
- package/board/utils/layout.js.map +1 -1
- package/board/utils/path.js.map +1 -1
- package/internal/debug-tools/generators.js.map +1 -1
- package/internal/debug-tools/parsers.js.map +1 -1
- package/internal/dnd-controller/event-emitter.js.map +1 -1
- package/internal/drag-handle/index.js.map +1 -1
- package/internal/environment.js +1 -1
- package/internal/environment.json +1 -1
- package/internal/item-container/get-collision-rect.js.map +1 -1
- package/internal/item-container/get-next-droppable.js.map +1 -1
- package/internal/item-container/index.js.map +1 -1
- package/internal/layout-engine/engine-solution.js.map +1 -1
- package/internal/layout-engine/engine-step.js.map +1 -1
- package/internal/layout-engine/utils.js.map +1 -1
- package/internal/manifest.json +1 -1
- package/internal/utils/layout.js.map +1 -1
- package/internal/utils/rects.js.map +1 -1
- package/internal/utils/use-auto-scroll.js.map +1 -1
- package/package.json +1 -1
package/board/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/board/internal.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAa,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AAEnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAE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CAAC;oCAC3E,QAAQ,EAAE,WAAW,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC;oCACjD,MAAM,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;oCAC9C,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;oCACrD,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC;iCACrD,CAAC,EACF,SAAS,EAAE,UAAU,YAEpB,IAAI,CAAC,EAAE,MAAK,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,EAAE,CAAA,IAAI,mBAAmB;oCAClD,CAAC,CAAC,GAAG,EAAE,CAAC,mBAAmB;oCAC3B,CAAC,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,IAzBnE,IAAI,CAAC,EAAE,CA0BE,CACjB,CAAC;wBACJ,CAAC,CAAC,CAAC;wBAEH,OAAO,QAAQ,CAAC;oBAClB,CAAC,GACI,CACR,CAAC,CAAC,CAAC,CACF,KAAK,CACN,GACG,EAEN,KAAC,UAAU,cAAE,YAAY,GAAc,IACnC,CACP,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport clsx from \"clsx\";\nimport { ReactNode, useEffect, useRef } from \"react\";\nimport { getDataAttributes } from \"../internal/base-component/get-data-attributes\";\nimport { InternalBaseComponentProps } from \"../internal/base-component/use-base-component\";\nimport { useContainerColumns } from \"../internal/breakpoints\";\nimport { TRANSITION_DURATION_MS } from \"../internal/constants\";\nimport { useDragSubscription } from \"../internal/dnd-controller/controller\";\nimport { useGlobalDragStateStyles } from \"../internal/global-drag-state-styles\";\nimport Grid from \"../internal/grid\";\nimport { BoardItemDefinition, BoardItemDefinitionBase, Direction, ItemId, Rect } from \"../internal/interfaces\";\nimport { ItemContainer, ItemContainerRef } from \"../internal/item-container\";\nimport LiveRegion from \"../internal/live-region\";\nimport { ScreenReaderGridNavigation } from \"../internal/screenreader-grid-navigation\";\nimport {\n createPlaceholdersLayout,\n getDefaultColumnSpan,\n getDefaultRowSpan,\n getMinColumnSpan,\n getMinRowSpan,\n interpretItems,\n} from \"../internal/utils/layout\";\nimport { Position } from \"../internal/utils/position\";\nimport { useAutoScroll } from \"../internal/utils/use-auto-scroll\";\nimport { useMergeRefs } from \"../internal/utils/use-merge-refs\";\n\nimport { BoardProps } from \"./interfaces\";\nimport Placeholder from \"./placeholder\";\nimport styles from \"./styles.css.js\";\nimport { selectTransitionRows, useTransition } from \"./transition\";\nimport { announcementToString } from \"./utils/announcements\";\nimport { createTransforms } from \"./utils/create-transforms\";\nimport { createItemsChangeEvent } from \"./utils/events\";\n\nexport function InternalBoard<D>({\n items,\n renderItem,\n onItemsChange,\n empty,\n i18nStrings,\n __internalRootRef,\n ...rest\n}: BoardProps<D> & InternalBaseComponentProps) {\n const containerAccessRef = useRef<HTMLDivElement>(null);\n const [currentColumns, containerQueryRef] = useContainerColumns();\n const containerRef = useMergeRefs(containerAccessRef, containerQueryRef);\n const itemContainerRef = useRef<{ [id: ItemId]: ItemContainerRef }>({});\n\n useGlobalDragStateStyles();\n\n const autoScrollHandlers = useAutoScroll();\n\n const [transitionState, dispatch] = useTransition<D>();\n const transition = transitionState.transition;\n const removeTransition = transitionState.removeTransition;\n const transitionAnnouncement = transitionState.announcement;\n const acquiredItem = transition?.acquiredItem ?? null;\n const acquiredItemElement = transition?.acquiredItemElement;\n\n // Using cached columns from transition to ensure no unexpected changes in the process.\n const columns = transition ? transition.itemsLayout.columns : currentColumns;\n\n // Use previous items while remove transition is in progress.\n items = removeTransition?.items ?? items;\n\n // The acquired item is the one being inserting at the moment but not submitted yet.\n // It needs to be included to the layout to be a part of layout shifts and rendering.\n items = acquiredItem ? [...items, acquiredItem] : items;\n const itemsLayout = interpretItems(items, columns);\n\n const layoutItemById = new Map(itemsLayout.items.map((item) => [item.id, item]));\n const layoutItemIndexById = new Map(itemsLayout.items.map((item, index) => [item.id, index]));\n\n // Items and layout items must maintain the same order visually, in the DOM and in the data\n // to ensure on-change events and tab order work as expected.\n items = [...items].sort((a, b) => (layoutItemIndexById.get(a.id) ?? -1) - (layoutItemIndexById.get(b.id) ?? -1));\n\n // When an item gets acquired or removed the focus needs to be dispatched on the next render.\n const focusNextRenderIndexRef = useRef<null | number>(null);\n const focusNextRenderIdRef = useRef<null | ItemId>(null);\n useEffect(() => {\n const focusTarget = focusNextRenderIdRef.current ?? items[focusNextRenderIndexRef.current ?? -1]?.id;\n if (focusTarget) {\n itemContainerRef.current[focusTarget].focusDragHandle();\n }\n focusNextRenderIndexRef.current = null;\n focusNextRenderIdRef.current = null;\n });\n\n // Submit scheduled removal after a delay to let animations play.\n useEffect(() => {\n if (!removeTransition) {\n return;\n }\n\n const timeoutId = setTimeout(() => {\n dispatch({ type: \"submit\" });\n\n const removedItemIndex = items.findIndex((it) => it.id === removeTransition.removedItem.id);\n const nextIndexToFocus = removedItemIndex !== items.length - 1 ? removedItemIndex : items.length - 2;\n focusNextRenderIndexRef.current = nextIndexToFocus;\n onItemsChange(createItemsChangeEvent(items, removeTransition.layoutShift));\n }, TRANSITION_DURATION_MS);\n\n return () => clearTimeout(timeoutId);\n }, [removeTransition, items, onItemsChange]);\n\n const rows = selectTransitionRows(transitionState) || itemsLayout.rows;\n const placeholdersLayout = createPlaceholdersLayout(rows, itemsLayout.columns);\n\n function isElementOverBoard(rect: Rect) {\n const board = containerAccessRef.current!;\n const boardContains = (target: null | Element) => board === target || board.contains(target);\n return (\n boardContains(document.elementFromPoint(rect.left, rect.top)) ||\n boardContains(document.elementFromPoint(rect.right, rect.top)) ||\n boardContains(document.elementFromPoint(rect.right, rect.bottom)) ||\n boardContains(document.elementFromPoint(rect.left, rect.bottom))\n );\n }\n\n useDragSubscription(\"start\", ({ operation, interactionType, draggableItem, collisionRect, collisionIds }) => {\n dispatch({\n type: \"init\",\n operation,\n interactionType,\n itemsLayout,\n // TODO: resolve any\n // The code only works assuming the board can take any draggable.\n // If draggables can be of different types a check of some sort is required here.\n draggableItem: draggableItem as BoardItemDefinitionBase<any>,\n draggableRect: collisionRect,\n collisionIds: interactionType === \"pointer\" && isElementOverBoard(collisionRect) ? collisionIds : [],\n });\n\n autoScrollHandlers.addPointerEventHandlers();\n });\n\n useDragSubscription(\"update\", ({ interactionType, collisionIds, positionOffset, collisionRect }) => {\n dispatch({\n type: \"update-with-pointer\",\n collisionIds: interactionType === \"pointer\" && isElementOverBoard(collisionRect) ? collisionIds : [],\n positionOffset,\n draggableRect: collisionRect,\n });\n });\n\n useDragSubscription(\"submit\", () => {\n dispatch({ type: \"submit\" });\n\n autoScrollHandlers.removePointerEventHandlers();\n\n if (!transition) {\n throw new Error(\"Invariant violation: no transition.\");\n }\n if (\n !transition.layoutShift ||\n transition.layoutShift.conflicts.length > 0 ||\n transition.layoutShift.moves.length === 0\n ) {\n return null;\n }\n\n // Commit new layout for insert case.\n if (transition.operation === \"insert\") {\n onItemsChange(createItemsChangeEvent([...items, transition.draggableItem], transition.layoutShift));\n }\n // Commit new layout for reorder/resize case.\n else {\n onItemsChange(createItemsChangeEvent(items, transition.layoutShift));\n }\n });\n\n useDragSubscription(\"discard\", () => {\n dispatch({ type: \"discard\" });\n\n autoScrollHandlers.removePointerEventHandlers();\n });\n\n useDragSubscription(\"acquire\", ({ droppableId, draggableItem, renderAcquiredItem }) => {\n const placeholder = placeholdersLayout.items.find((it) => it.id === droppableId);\n\n // If missing then it does not belong to this board.\n if (!placeholder) {\n return;\n }\n\n dispatch({\n type: \"acquire-item\",\n position: new Position({ x: placeholder.x, y: placeholder.y }),\n layoutElement: containerAccessRef.current!,\n acquiredItemElement: renderAcquiredItem(),\n });\n\n focusNextRenderIdRef.current = draggableItem.id;\n });\n\n const removeItemAction = (removedItem: BoardItemDefinition<D>) => {\n dispatch({ type: \"init-remove\", items, itemsLayout, removedItem });\n };\n\n function focusItem(itemId: ItemId) {\n itemContainerRef.current[itemId].focusDragHandle();\n }\n\n function onItemMove(direction: Direction) {\n if (transition) {\n dispatch({ type: \"update-with-keyboard\", direction });\n autoScrollHandlers.scheduleActiveElementScrollIntoView(TRANSITION_DURATION_MS);\n }\n }\n\n const announcement = transitionAnnouncement\n ? announcementToString(transitionAnnouncement, items, i18nStrings, itemsLayout.columns)\n : \"\";\n\n return (\n <div ref={__internalRootRef} {...getDataAttributes(rest)}>\n <ScreenReaderGridNavigation\n items={items}\n itemsLayout={itemsLayout}\n ariaLabel={i18nStrings.navigationAriaLabel}\n ariaDescription={i18nStrings.navigationAriaDescription}\n itemAriaLabel={i18nStrings.navigationItemAriaLabel}\n onActivateItem={focusItem}\n />\n\n <div ref={containerRef} className={clsx(styles.root, { [styles.empty]: rows === 0 })}>\n {rows > 0 ? (\n <Grid columns={itemsLayout.columns} layout={[...placeholdersLayout.items, ...itemsLayout.items]}>\n {(gridContext) => {\n const layoutShift = transition?.layoutShift ?? removeTransition?.layoutShift;\n const transforms = layoutShift ? createTransforms(itemsLayout, layoutShift.moves, gridContext) : {};\n\n // Exclude drag target from transforms.\n if (transition && transition.interactionType === \"pointer\") {\n delete transforms[transition.draggableItem.id];\n }\n\n const children: ReactNode[] = [];\n\n /* Placeholders are rendered even when there is no transition to support the first collisions check. */\n placeholdersLayout.items.forEach((placeholder) =>\n children.push(\n <Placeholder\n key={placeholder.id}\n id={placeholder.id}\n state={transition ? (transition.collisionIds?.has(placeholder.id) ? \"hover\" : \"active\") : \"default\"}\n gridContext={gridContext}\n columns={itemsLayout.columns}\n />\n )\n );\n\n items.forEach((item) => {\n const layoutItem = layoutItemById.get(item.id);\n const isResizing = transition?.operation === \"resize\" && transition?.draggableItem.id === item.id;\n\n const itemSize = layoutItem ?? {\n width: getDefaultColumnSpan(item, itemsLayout.columns),\n height: getDefaultRowSpan(item),\n };\n\n const itemMaxSize =\n isResizing && layoutItem ? { width: itemsLayout.columns - layoutItem.x, height: 999 } : itemSize;\n\n children.push(\n <ItemContainer\n key={item.id}\n ref={(elem) => {\n if (elem) {\n itemContainerRef.current[item.id] = elem;\n } else {\n delete itemContainerRef.current[item.id];\n }\n }}\n item={item}\n transform={transforms[item.id]}\n inTransition={!!transition || !!removeTransition}\n placed={item.id !== acquiredItem?.id}\n acquired={item.id === acquiredItem?.id}\n getItemSize={() => ({\n width: gridContext.getWidth(itemSize.width),\n minWidth: gridContext.getWidth(getMinColumnSpan(item, itemsLayout.columns)),\n maxWidth: gridContext.getWidth(itemMaxSize.width),\n height: gridContext.getHeight(itemSize.height),\n minHeight: gridContext.getHeight(getMinRowSpan(item)),\n maxHeight: gridContext.getHeight(itemMaxSize.height),\n })}\n onKeyMove={onItemMove}\n >\n {item.id === acquiredItem?.id && acquiredItemElement\n ? () => acquiredItemElement\n : () => renderItem(item, { removeItem: () => removeItemAction(item) })}\n </ItemContainer>\n );\n });\n\n return children;\n }}\n </Grid>\n ) : (\n empty\n )}\n </div>\n\n <LiveRegion>{announcement}</LiveRegion>\n </div>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/board/internal.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAa,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AAEnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAChF,OAAO,IAAI,MAAM,kBAAkB,CAAC;AA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C,KAAK,CAAC;oCACjD,MAAM,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;oCAC9C,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;oCACrD,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC;iCACrD,CAAC,EACF,SAAS,EAAE,UAAU,YAEpB,IAAI,CAAC,EAAE,MAAK,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,EAAE,CAAA,IAAI,mBAAmB;oCAClD,CAAC,CAAC,GAAG,EAAE,CAAC,mBAAmB;oCAC3B,CAAC,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,IAzBnE,IAAI,CAAC,EAAE,CA0BE,CACjB,CAAC;wBACJ,CAAC,CAAC,CAAC;wBAEH,OAAO,QAAQ,CAAC;oBAClB,CAAC,GACI,CACR,CAAC,CAAC,CAAC,CACF,KAAK,CACN,GACG,EAEN,KAAC,UAAU,cAAE,YAAY,GAAc,IACnC,CACP,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport clsx from \"clsx\";\nimport { ReactNode, useEffect, useRef } from \"react\";\nimport { getDataAttributes } from \"../internal/base-component/get-data-attributes\";\nimport { InternalBaseComponentProps } from \"../internal/base-component/use-base-component\";\nimport { useContainerColumns } from \"../internal/breakpoints\";\nimport { TRANSITION_DURATION_MS } from \"../internal/constants\";\nimport { useDragSubscription } from \"../internal/dnd-controller/controller\";\nimport { useGlobalDragStateStyles } from \"../internal/global-drag-state-styles\";\nimport Grid from \"../internal/grid\";\nimport { BoardItemDefinition, BoardItemDefinitionBase, Direction, ItemId, Rect } from \"../internal/interfaces\";\nimport { ItemContainer, ItemContainerRef } from \"../internal/item-container\";\nimport LiveRegion from \"../internal/live-region\";\nimport { ScreenReaderGridNavigation } from \"../internal/screenreader-grid-navigation\";\nimport {\n createPlaceholdersLayout,\n getDefaultColumnSpan,\n getDefaultRowSpan,\n getMinColumnSpan,\n getMinRowSpan,\n interpretItems,\n} from \"../internal/utils/layout\";\nimport { Position } from \"../internal/utils/position\";\nimport { useAutoScroll } from \"../internal/utils/use-auto-scroll\";\nimport { useMergeRefs } from \"../internal/utils/use-merge-refs\";\n\nimport { BoardProps } from \"./interfaces\";\nimport Placeholder from \"./placeholder\";\nimport styles from \"./styles.css.js\";\nimport { selectTransitionRows, useTransition } from \"./transition\";\nimport { announcementToString } from \"./utils/announcements\";\nimport { createTransforms } from \"./utils/create-transforms\";\nimport { createItemsChangeEvent } from \"./utils/events\";\n\nexport function InternalBoard<D>({\n items,\n renderItem,\n onItemsChange,\n empty,\n i18nStrings,\n __internalRootRef,\n ...rest\n}: BoardProps<D> & InternalBaseComponentProps) {\n const containerAccessRef = useRef<HTMLDivElement>(null);\n const [currentColumns, containerQueryRef] = useContainerColumns();\n const containerRef = useMergeRefs(containerAccessRef, containerQueryRef);\n const itemContainerRef = useRef<{ [id: ItemId]: ItemContainerRef }>({});\n\n useGlobalDragStateStyles();\n\n const autoScrollHandlers = useAutoScroll();\n\n const [transitionState, dispatch] = useTransition<D>();\n const transition = transitionState.transition;\n const removeTransition = transitionState.removeTransition;\n const transitionAnnouncement = transitionState.announcement;\n const acquiredItem = transition?.acquiredItem ?? null;\n const acquiredItemElement = transition?.acquiredItemElement;\n\n // Using cached columns from transition to ensure no unexpected changes in the process.\n const columns = transition ? transition.itemsLayout.columns : currentColumns;\n\n // Use previous items while remove transition is in progress.\n items = removeTransition?.items ?? items;\n\n // The acquired item is the one being inserting at the moment but not submitted yet.\n // It needs to be included to the layout to be a part of layout shifts and rendering.\n items = acquiredItem ? [...items, acquiredItem] : items;\n const itemsLayout = interpretItems(items, columns);\n\n const layoutItemById = new Map(itemsLayout.items.map((item) => [item.id, item]));\n const layoutItemIndexById = new Map(itemsLayout.items.map((item, index) => [item.id, index]));\n\n // Items and layout items must maintain the same order visually, in the DOM and in the data\n // to ensure on-change events and tab order work as expected.\n items = [...items].sort((a, b) => (layoutItemIndexById.get(a.id) ?? -1) - (layoutItemIndexById.get(b.id) ?? -1));\n\n // When an item gets acquired or removed the focus needs to be dispatched on the next render.\n const focusNextRenderIndexRef = useRef<null | number>(null);\n const focusNextRenderIdRef = useRef<null | ItemId>(null);\n useEffect(() => {\n const focusTarget = focusNextRenderIdRef.current ?? items[focusNextRenderIndexRef.current ?? -1]?.id;\n if (focusTarget) {\n itemContainerRef.current[focusTarget].focusDragHandle();\n }\n focusNextRenderIndexRef.current = null;\n focusNextRenderIdRef.current = null;\n });\n\n // Submit scheduled removal after a delay to let animations play.\n useEffect(() => {\n if (!removeTransition) {\n return;\n }\n\n const timeoutId = setTimeout(() => {\n dispatch({ type: \"submit\" });\n\n const removedItemIndex = items.findIndex((it) => it.id === removeTransition.removedItem.id);\n const nextIndexToFocus = removedItemIndex !== items.length - 1 ? removedItemIndex : items.length - 2;\n focusNextRenderIndexRef.current = nextIndexToFocus;\n onItemsChange(createItemsChangeEvent(items, removeTransition.layoutShift));\n }, TRANSITION_DURATION_MS);\n\n return () => clearTimeout(timeoutId);\n }, [removeTransition, items, onItemsChange]);\n\n const rows = selectTransitionRows(transitionState) || itemsLayout.rows;\n const placeholdersLayout = createPlaceholdersLayout(rows, itemsLayout.columns);\n\n function isElementOverBoard(rect: Rect) {\n const board = containerAccessRef.current!;\n const boardContains = (target: null | Element) => board === target || board.contains(target);\n return (\n boardContains(document.elementFromPoint(rect.left, rect.top)) ||\n boardContains(document.elementFromPoint(rect.right, rect.top)) ||\n boardContains(document.elementFromPoint(rect.right, rect.bottom)) ||\n boardContains(document.elementFromPoint(rect.left, rect.bottom))\n );\n }\n\n useDragSubscription(\"start\", ({ operation, interactionType, draggableItem, collisionRect, collisionIds }) => {\n dispatch({\n type: \"init\",\n operation,\n interactionType,\n itemsLayout,\n // TODO: resolve any\n // The code only works assuming the board can take any draggable.\n // If draggables can be of different types a check of some sort is required here.\n draggableItem: draggableItem as BoardItemDefinitionBase<any>,\n draggableRect: collisionRect,\n collisionIds: interactionType === \"pointer\" && isElementOverBoard(collisionRect) ? collisionIds : [],\n });\n\n autoScrollHandlers.addPointerEventHandlers();\n });\n\n useDragSubscription(\"update\", ({ interactionType, collisionIds, positionOffset, collisionRect }) => {\n dispatch({\n type: \"update-with-pointer\",\n collisionIds: interactionType === \"pointer\" && isElementOverBoard(collisionRect) ? collisionIds : [],\n positionOffset,\n draggableRect: collisionRect,\n });\n });\n\n useDragSubscription(\"submit\", () => {\n dispatch({ type: \"submit\" });\n\n autoScrollHandlers.removePointerEventHandlers();\n\n if (!transition) {\n throw new Error(\"Invariant violation: no transition.\");\n }\n if (\n !transition.layoutShift ||\n transition.layoutShift.conflicts.length > 0 ||\n transition.layoutShift.moves.length === 0\n ) {\n return null;\n }\n\n // Commit new layout for insert case.\n if (transition.operation === \"insert\") {\n onItemsChange(createItemsChangeEvent([...items, transition.draggableItem], transition.layoutShift));\n }\n // Commit new layout for reorder/resize case.\n else {\n onItemsChange(createItemsChangeEvent(items, transition.layoutShift));\n }\n });\n\n useDragSubscription(\"discard\", () => {\n dispatch({ type: \"discard\" });\n\n autoScrollHandlers.removePointerEventHandlers();\n });\n\n useDragSubscription(\"acquire\", ({ droppableId, draggableItem, renderAcquiredItem }) => {\n const placeholder = placeholdersLayout.items.find((it) => it.id === droppableId);\n\n // If missing then it does not belong to this board.\n if (!placeholder) {\n return;\n }\n\n dispatch({\n type: \"acquire-item\",\n position: new Position({ x: placeholder.x, y: placeholder.y }),\n layoutElement: containerAccessRef.current!,\n acquiredItemElement: renderAcquiredItem(),\n });\n\n focusNextRenderIdRef.current = draggableItem.id;\n });\n\n const removeItemAction = (removedItem: BoardItemDefinition<D>) => {\n dispatch({ type: \"init-remove\", items, itemsLayout, removedItem });\n };\n\n function focusItem(itemId: ItemId) {\n itemContainerRef.current[itemId].focusDragHandle();\n }\n\n function onItemMove(direction: Direction) {\n if (transition) {\n dispatch({ type: \"update-with-keyboard\", direction });\n autoScrollHandlers.scheduleActiveElementScrollIntoView(TRANSITION_DURATION_MS);\n }\n }\n\n const announcement = transitionAnnouncement\n ? announcementToString(transitionAnnouncement, items, i18nStrings, itemsLayout.columns)\n : \"\";\n\n return (\n <div ref={__internalRootRef} {...getDataAttributes(rest)}>\n <ScreenReaderGridNavigation\n items={items}\n itemsLayout={itemsLayout}\n ariaLabel={i18nStrings.navigationAriaLabel}\n ariaDescription={i18nStrings.navigationAriaDescription}\n itemAriaLabel={i18nStrings.navigationItemAriaLabel}\n onActivateItem={focusItem}\n />\n\n <div ref={containerRef} className={clsx(styles.root, { [styles.empty]: rows === 0 })}>\n {rows > 0 ? (\n <Grid columns={itemsLayout.columns} layout={[...placeholdersLayout.items, ...itemsLayout.items]}>\n {(gridContext) => {\n const layoutShift = transition?.layoutShift ?? removeTransition?.layoutShift;\n const transforms = layoutShift ? createTransforms(itemsLayout, layoutShift.moves, gridContext) : {};\n\n // Exclude drag target from transforms.\n if (transition && transition.interactionType === \"pointer\") {\n delete transforms[transition.draggableItem.id];\n }\n\n const children: ReactNode[] = [];\n\n /* Placeholders are rendered even when there is no transition to support the first collisions check. */\n placeholdersLayout.items.forEach((placeholder) =>\n children.push(\n <Placeholder\n key={placeholder.id}\n id={placeholder.id}\n state={transition ? (transition.collisionIds?.has(placeholder.id) ? \"hover\" : \"active\") : \"default\"}\n gridContext={gridContext}\n columns={itemsLayout.columns}\n />,\n ),\n );\n\n items.forEach((item) => {\n const layoutItem = layoutItemById.get(item.id);\n const isResizing = transition?.operation === \"resize\" && transition?.draggableItem.id === item.id;\n\n const itemSize = layoutItem ?? {\n width: getDefaultColumnSpan(item, itemsLayout.columns),\n height: getDefaultRowSpan(item),\n };\n\n const itemMaxSize =\n isResizing && layoutItem ? { width: itemsLayout.columns - layoutItem.x, height: 999 } : itemSize;\n\n children.push(\n <ItemContainer\n key={item.id}\n ref={(elem) => {\n if (elem) {\n itemContainerRef.current[item.id] = elem;\n } else {\n delete itemContainerRef.current[item.id];\n }\n }}\n item={item}\n transform={transforms[item.id]}\n inTransition={!!transition || !!removeTransition}\n placed={item.id !== acquiredItem?.id}\n acquired={item.id === acquiredItem?.id}\n getItemSize={() => ({\n width: gridContext.getWidth(itemSize.width),\n minWidth: gridContext.getWidth(getMinColumnSpan(item, itemsLayout.columns)),\n maxWidth: gridContext.getWidth(itemMaxSize.width),\n height: gridContext.getHeight(itemSize.height),\n minHeight: gridContext.getHeight(getMinRowSpan(item)),\n maxHeight: gridContext.getHeight(itemMaxSize.height),\n })}\n onKeyMove={onItemMove}\n >\n {item.id === acquiredItem?.id && acquiredItemElement\n ? () => acquiredItemElement\n : () => renderItem(item, { removeItem: () => removeItemAction(item) })}\n </ItemContainer>,\n );\n });\n\n return children;\n }}\n </Grid>\n ) : (\n empty\n )}\n </div>\n\n <LiveRegion>{announcement}</LiveRegion>\n </div>\n );\n}\n"]}
|
package/board/transition.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transition.js","sourceRoot":"","sources":["../../../src/board/transition.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAuB,UAAU,EAAE,MAAM,OAAO,CAAC;AAGxD,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACpH,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAEtD,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,qB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\"react\";\nimport { InteractionType, Operation } from \"../internal/dnd-controller/controller\";\nimport { BoardItemDefinitionBase, Direction, GridLayout, ItemId, Rect } from \"../internal/interfaces\";\nimport { LayoutEngine } from \"../internal/layout-engine/engine\";\nimport { Coordinates } from \"../internal/utils/coordinates\";\nimport { getDefaultColumnSpan, getDefaultRowSpan, getMinColumnSpan, getMinRowSpan } from \"../internal/utils/layout\";\nimport { Position } from \"../internal/utils/position\";\nimport { BoardProps, RemoveTransition, Transition, TransitionAnnouncement } from \"./interfaces\";\nimport { createOperationAnnouncement } from \"./utils/announcements\";\nimport { getHoveredRect } from \"./utils/get-hovered-rect\";\nimport { getInsertionDirection, getLayoutPlaceholders, getLayoutRows, getLayoutShift } from \"./utils/layout\";\nimport { appendMovePath, appendResizePath } from \"./utils/path\";\n\nexport interface TransitionState<D> {\n transition: null | Transition<D>;\n removeTransition: null | RemoveTransition<D>;\n announcement: null | TransitionAnnouncement;\n}\n\nexport type Action<D> =\n | InitAction<D>\n | InitRemoveAction<D>\n | SubmitAction\n | DiscardAction\n | UpdateWithPointerAction\n | UpdateWithKeyboardAction\n | AcquireItemAction;\n\ninterface InitAction<D> {\n type: \"init\";\n operation: Operation;\n interactionType: InteractionType;\n itemsLayout: GridLayout;\n draggableItem: BoardItemDefinitionBase<D>;\n draggableRect: Rect;\n collisionIds: readonly ItemId[];\n}\ninterface InitRemoveAction<D> {\n type: \"init-remove\";\n items: readonly BoardProps.Item<D>[];\n removedItem: BoardItemDefinitionBase<D>;\n itemsLayout: GridLayout;\n}\ninterface SubmitAction {\n type: \"submit\";\n}\ninterface DiscardAction {\n type: \"discard\";\n}\ninterface UpdateWithPointerAction {\n type: \"update-with-pointer\";\n collisionIds: readonly ItemId[];\n positionOffset: Coordinates;\n draggableRect: Rect;\n}\ninterface UpdateWithKeyboardAction {\n type: \"update-with-keyboard\";\n direction: Direction;\n}\ninterface AcquireItemAction {\n type: \"acquire-item\";\n position: Position;\n layoutElement: HTMLElement;\n acquiredItemElement?: ReactNode;\n}\n\nexport function useTransition<D>(): [TransitionState<D>, Dispatch<Action<D>>] {\n return useReducer(transitionReducer<D>, { transition: null, removeTransition: null, announcement: null });\n}\n\nexport function selectTransitionRows<D>(state: TransitionState<D>) {\n return state.transition ? getLayoutRows(state.transition) : 0;\n}\n\nfunction transitionReducer<D>(state: TransitionState<D>, action: Action<D>): TransitionState<D> {\n switch (action.type) {\n case \"init\":\n return initTransition(action);\n case \"init-remove\":\n return initRemoveTransition(action);\n case \"submit\":\n return submitTransition(state);\n case \"discard\":\n return discardTransition(state);\n case \"update-with-pointer\":\n return updateTransitionWithPointerEvent(state, action);\n case \"update-with-keyboard\":\n return updateTransitionWithKeyboardEvent(state, action);\n case \"acquire-item\":\n return acquireTransitionItem(state, action);\n }\n}\n\nfunction initTransition<D>({\n operation,\n interactionType,\n itemsLayout,\n draggableItem,\n draggableRect,\n collisionIds,\n}: InitAction<D>): TransitionState<D> {\n const transition: Transition<D> = {\n operation,\n interactionType,\n itemsLayout,\n layoutEngine: new LayoutEngine(itemsLayout),\n insertionDirection: null,\n draggableItem,\n draggableRect,\n acquiredItem: null,\n collisionIds: new Set(),\n layoutShift: null,\n path: [],\n };\n\n const placeholdersLayout = getLayoutPlaceholders(transition);\n\n const layoutItem = itemsLayout.items.find((it) => it.id === draggableItem.id);\n\n let path: Position[] = [];\n if (interactionType === \"pointer\" || operation === \"insert\") {\n const collisionRect = getHoveredRect(collisionIds, placeholdersLayout.items);\n const appendPath = operation === \"resize\" ? appendResizePath : appendMovePath;\n path = layoutItem ? appendPath([], collisionRect) : [];\n } else if (layoutItem) {\n path =\n operation === \"resize\"\n ? [new Position({ x: layoutItem.x + layoutItem.width, y: layoutItem.y + layoutItem.height })]\n : [new Position({ x: layoutItem.x, y: layoutItem.y })];\n }\n\n return {\n transition: { ...transition, path },\n removeTransition: null,\n announcement: layoutItem ? { type: \"dnd-started\", item: draggableItem, operation } : null,\n };\n}\n\nfunction initRemoveTransition<D>({ items, removedItem, itemsLayout }: InitRemoveAction<D>): TransitionState<D> {\n const layoutShift = new LayoutEngine(itemsLayout).remove(removedItem.id);\n const removeTransition: RemoveTransition<D> = { items, removedItem, layoutShift };\n return { transition: null, removeTransition, announcement: null };\n}\n\nfunction submitTransition<D>(state: TransitionState<D>): TransitionState<D> {\n const { transition, removeTransition } = state;\n\n if (removeTransition) {\n const disturbed = new Set(removeTransition.layoutShift.moves.map((move) => move.itemId));\n disturbed.delete(removeTransition.removedItem.id);\n return {\n transition: null,\n removeTransition: null,\n announcement: { type: \"item-removed\", item: removeTransition.removedItem, disturbed },\n };\n }\n\n if (!transition) {\n throw new Error(\"Invariant violation: no transition.\");\n }\n\n const { operation, itemsLayout, draggableItem: item, acquiredItem } = transition;\n const itemBelongsToBoard = item.id === acquiredItem?.id || itemsLayout.items.some((it) => it.id === item.id);\n\n return transition.layoutShift?.conflicts.length === 0\n ? {\n transition: null,\n removeTransition: null,\n announcement: itemBelongsToBoard ? { type: \"dnd-committed\", item, operation } : null,\n }\n : {\n transition: null,\n removeTransition: null,\n announcement: itemBelongsToBoard ? { type: \"dnd-discarded\", item, operation } : null,\n };\n}\n\nfunction discardTransition<D>(state: TransitionState<D>): TransitionState<D> {\n const { transition, removeTransition } = state;\n\n if (removeTransition) {\n throw new Error(\"Can't discard remove transition.\");\n }\n\n if (!transition) {\n throw new Error(\"Invariant violation: no transition.\");\n }\n\n const { operation, itemsLayout, draggableItem: item, acquiredItem } = transition;\n const itemBelongsToBoard = item.id === acquiredItem?.id || itemsLayout.items.some((it) => it.id === item.id);\n\n return {\n transition: null,\n removeTransition: null,\n announcement: itemBelongsToBoard ? { type: \"dnd-discarded\", item, operation } : null,\n };\n}\n\nfunction updateTransitionWithPointerEvent<D>(\n state: TransitionState<D>,\n { collisionIds, positionOffset, draggableRect }: UpdateWithPointerAction\n): TransitionState<D> {\n const { transition } = state;\n\n if (!transition) {\n throw new Error(\"Invariant violation: no transition.\");\n }\n\n const layout = transition.layoutShift?.next ?? transition.itemsLayout;\n const layoutItem = layout.items.find((it) => it.id === transition.draggableItem.id);\n const itemWidth = layoutItem ? layoutItem.width : getDefaultColumnSpan(transition.draggableItem, layout.columns);\n const itemHeight = layoutItem ? layoutItem.height : getDefaultRowSpan(transition.draggableItem);\n const itemSize = itemWidth * itemHeight;\n\n const isOutOfBoundaries =\n transition.operation !== \"resize\" ? collisionIds.length < itemSize : collisionIds.length === 0;\n\n if (isOutOfBoundaries) {\n return {\n transition: {\n ...transition,\n draggableRect,\n collisionIds: new Set(),\n layoutShift: null,\n insertionDirection: null,\n },\n removeTransition: null,\n announcement: null,\n };\n }\n\n const placeholdersLayout = getLayoutPlaceholders(transition);\n const collisionRect = getHoveredRect(collisionIds, placeholdersLayout.items);\n const appendPath = transition.operation === \"resize\" ? appendResizePath : appendMovePath;\n const path = appendPath(transition.path, collisionRect);\n\n const insertionDirection = transition.insertionDirection ?? getInsertionDirection(positionOffset);\n const layoutShift = getLayoutShift(transition, path, insertionDirection);\n\n return {\n transition: {\n ...transition,\n draggableRect,\n collisionIds: new Set(collisionIds),\n layoutShift,\n path,\n insertionDirection,\n },\n removeTransition: null,\n announcement: null,\n };\n}\n\nfunction updateTransitionWithKeyboardEvent<D>(\n state: TransitionState<D>,\n { direction }: UpdateWithKeyboardAction\n): TransitionState<D> {\n const { transition } = state;\n\n if (!transition) {\n throw new Error(\"Invariant violation: no transition.\");\n }\n\n const updateManualItemTransition = (transition: Transition<D>, direction: Direction): TransitionState<D> => {\n const xDelta = direction === \"left\" ? -1 : direction === \"right\" ? 1 : 0;\n const yDelta = direction === \"up\" ? -1 : direction === \"down\" ? 1 : 0;\n const lastPosition = transition.path[transition.path.length - 1];\n const nextPosition = new Position({ x: lastPosition.x + xDelta, y: lastPosition.y + yDelta });\n const nextPath = [...transition.path, nextPosition];\n\n // Check resizing below min size.\n const layout = transition.layoutShift?.next ?? transition.itemsLayout;\n const layoutItem = layout.items.find((it) => it.id === transition.draggableItem.id);\n const minWidth = getMinColumnSpan(transition.draggableItem, transition.itemsLayout.columns);\n const minHeight = getMinRowSpan(transition.draggableItem);\n if (\n transition.operation === \"resize\" &&\n layoutItem &&\n (layoutItem.width + xDelta < minWidth || layoutItem.height + yDelta < minHeight)\n ) {\n return state;\n }\n\n try {\n const layoutShift = getLayoutShift(transition, nextPath);\n const nextTransition = { ...transition, layoutShift, path: nextPath };\n return {\n transition: nextTransition,\n removeTransition: null,\n announcement: createOperationAnnouncement(nextTransition, direction),\n };\n } catch (e) {\n // Can't create next layout because the next path is out of bounds.\n return state;\n }\n };\n\n switch (direction) {\n case \"left\":\n return updateManualItemTransition(transition, \"left\");\n case \"right\":\n return updateManualItemTransition(transition, \"right\");\n case \"up\":\n return updateManualItemTransition(transition, \"up\");\n case \"down\":\n return updateManualItemTransition(transition, \"down\");\n }\n}\n\nfunction acquireTransitionItem<D>(\n state: TransitionState<D>,\n { position, layoutElement, acquiredItemElement }: AcquireItemAction\n): TransitionState<D> {\n const { transition } = state;\n\n if (!transition) {\n throw new Error(\"Invariant violation: no transition.\");\n }\n\n const { columns } = transition.itemsLayout;\n\n const layoutRect = layoutElement.getBoundingClientRect();\n const itemRect = transition.draggableRect;\n const offset = new Coordinates({ x: itemRect.left - layoutRect.x, y: itemRect.top - layoutRect.y });\n const insertionDirection = getInsertionDirection(offset);\n\n // Update original insertion position if the item can't fit into the layout by width.\n const width = getDefaultColumnSpan(transition.draggableItem, columns);\n position = new Position({ x: Math.min(columns - width, position.x), y: position.y });\n\n const path = [...transition.path, position];\n\n const layoutShift = getLayoutShift(transition, path, insertionDirection);\n\n // The columnOffset, columnSpan and rowSpan are of no use as of being overridden by the layout shift.\n const acquiredItem = { ...transition.draggableItem, columnOffset: 0, columnSpan: 1, rowSpan: 1 };\n\n const nextTransition: Transition<D> = {\n ...transition,\n collisionIds: new Set(),\n layoutShift,\n path,\n acquiredItem,\n acquiredItemElement,\n };\n return {\n transition: nextTransition,\n removeTransition: null,\n announcement: createOperationAnnouncement(nextTransition, null),\n };\n}\n"]}
|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AqG;IACrG,MAAM,YAAY,GAAG,EAAE,GAAG,UAAU,CAAC,aAAa,EAAE,YAAY,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;IAEjG,MAAM,cAAc,GAAkB;QACpC,GAAG,UAAU;QACb,YAAY,EAAE,IAAI,GAAG,EAAE;QACvB,WAAW;QACX,IAAI;QACJ,YAAY;QACZ,mBAAmB;KACpB,CAAC;IACF,OAAO;QACL,UAAU,EAAE,cAAc;QAC1B,gBAAgB,EAAE,IAAI;QACtB,YAAY,EAAE,2BAA2B,CAAC,cAAc,EAAE,IAAI,CAAC;KAChE,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Dispatch, ReactNode, useReducer } from \"react\";\nimport { InteractionType, Operation } from \"../internal/dnd-controller/controller\";\nimport { BoardItemDefinitionBase, Direction, GridLayout, ItemId, Rect } from \"../internal/interfaces\";\nimport { LayoutEngine } from \"../internal/layout-engine/engine\";\nimport { Coordinates } from \"../internal/utils/coordinates\";\nimport { getDefaultColumnSpan, getDefaultRowSpan, getMinColumnSpan, getMinRowSpan } from \"../internal/utils/layout\";\nimport { Position } from \"../internal/utils/position\";\nimport { BoardProps, RemoveTransition, Transition, TransitionAnnouncement } from \"./interfaces\";\nimport { createOperationAnnouncement } from \"./utils/announcements\";\nimport { getHoveredRect } from \"./utils/get-hovered-rect\";\nimport { getInsertionDirection, getLayoutPlaceholders, getLayoutRows, getLayoutShift } from \"./utils/layout\";\nimport { appendMovePath, appendResizePath } from \"./utils/path\";\n\nexport interface TransitionState<D> {\n transition: null | Transition<D>;\n removeTransition: null | RemoveTransition<D>;\n announcement: null | TransitionAnnouncement;\n}\n\nexport type Action<D> =\n | InitAction<D>\n | InitRemoveAction<D>\n | SubmitAction\n | DiscardAction\n | UpdateWithPointerAction\n | UpdateWithKeyboardAction\n | AcquireItemAction;\n\ninterface InitAction<D> {\n type: \"init\";\n operation: Operation;\n interactionType: InteractionType;\n itemsLayout: GridLayout;\n draggableItem: BoardItemDefinitionBase<D>;\n draggableRect: Rect;\n collisionIds: readonly ItemId[];\n}\ninterface InitRemoveAction<D> {\n type: \"init-remove\";\n items: readonly BoardProps.Item<D>[];\n removedItem: BoardItemDefinitionBase<D>;\n itemsLayout: GridLayout;\n}\ninterface SubmitAction {\n type: \"submit\";\n}\ninterface DiscardAction {\n type: \"discard\";\n}\ninterface UpdateWithPointerAction {\n type: \"update-with-pointer\";\n collisionIds: readonly ItemId[];\n positionOffset: Coordinates;\n draggableRect: Rect;\n}\ninterface UpdateWithKeyboardAction {\n type: \"update-with-keyboard\";\n direction: Direction;\n}\ninterface AcquireItemAction {\n type: \"acquire-item\";\n position: Position;\n layoutElement: HTMLElement;\n acquiredItemElement?: ReactNode;\n}\n\nexport function useTransition<D>(): [TransitionState<D>, Dispatch<Action<D>>] {\n return useReducer(transitionReducer<D>, { transition: null, removeTransition: null, announcement: null });\n}\n\nexport function selectTransitionRows<D>(state: TransitionState<D>) {\n return state.transition ? getLayoutRows(state.transition) : 0;\n}\n\nfunction transitionReducer<D>(state: TransitionState<D>, action: Action<D>): TransitionState<D> {\n switch (action.type) {\n case \"init\":\n return initTransition(action);\n case \"init-remove\":\n return initRemoveTransition(action);\n case \"submit\":\n return submitTransition(state);\n case \"discard\":\n return discardTransition(state);\n case \"update-with-pointer\":\n return updateTransitionWithPointerEvent(state, action);\n case \"update-with-keyboard\":\n return updateTransitionWithKeyboardEvent(state, action);\n case \"acquire-item\":\n return acquireTransitionItem(state, action);\n }\n}\n\nfunction initTransition<D>({\n operation,\n interactionType,\n itemsLayout,\n draggableItem,\n draggableRect,\n collisionIds,\n}: InitAction<D>): TransitionState<D> {\n const transition: Transition<D> = {\n operation,\n interactionType,\n itemsLayout,\n layoutEngine: new LayoutEngine(itemsLayout),\n insertionDirection: null,\n draggableItem,\n draggableRect,\n acquiredItem: null,\n collisionIds: new Set(),\n layoutShift: null,\n path: [],\n };\n\n const placeholdersLayout = getLayoutPlaceholders(transition);\n\n const layoutItem = itemsLayout.items.find((it) => it.id === draggableItem.id);\n\n let path: Position[] = [];\n if (interactionType === \"pointer\" || operation === \"insert\") {\n const collisionRect = getHoveredRect(collisionIds, placeholdersLayout.items);\n const appendPath = operation === \"resize\" ? appendResizePath : appendMovePath;\n path = layoutItem ? appendPath([], collisionRect) : [];\n } else if (layoutItem) {\n path =\n operation === \"resize\"\n ? [new Position({ x: layoutItem.x + layoutItem.width, y: layoutItem.y + layoutItem.height })]\n : [new Position({ x: layoutItem.x, y: layoutItem.y })];\n }\n\n return {\n transition: { ...transition, path },\n removeTransition: null,\n announcement: layoutItem ? { type: \"dnd-started\", item: draggableItem, operation } : null,\n };\n}\n\nfunction initRemoveTransition<D>({ items, removedItem, itemsLayout }: InitRemoveAction<D>): TransitionState<D> {\n const layoutShift = new LayoutEngine(itemsLayout).remove(removedItem.id);\n const removeTransition: RemoveTransition<D> = { items, removedItem, layoutShift };\n return { transition: null, removeTransition, announcement: null };\n}\n\nfunction submitTransition<D>(state: TransitionState<D>): TransitionState<D> {\n const { transition, removeTransition } = state;\n\n if (removeTransition) {\n const disturbed = new Set(removeTransition.layoutShift.moves.map((move) => move.itemId));\n disturbed.delete(removeTransition.removedItem.id);\n return {\n transition: null,\n removeTransition: null,\n announcement: { type: \"item-removed\", item: removeTransition.removedItem, disturbed },\n };\n }\n\n if (!transition) {\n throw new Error(\"Invariant violation: no transition.\");\n }\n\n const { operation, itemsLayout, draggableItem: item, acquiredItem } = transition;\n const itemBelongsToBoard = item.id === acquiredItem?.id || itemsLayout.items.some((it) => it.id === item.id);\n\n return transition.layoutShift?.conflicts.length === 0\n ? {\n transition: null,\n removeTransition: null,\n announcement: itemBelongsToBoard ? { type: \"dnd-committed\", item, operation } : null,\n }\n : {\n transition: null,\n removeTransition: null,\n announcement: itemBelongsToBoard ? { type: \"dnd-discarded\", item, operation } : null,\n };\n}\n\nfunction discardTransition<D>(state: TransitionState<D>): TransitionState<D> {\n const { transition, removeTransition } = state;\n\n if (removeTransition) {\n throw new Error(\"Can't discard remove transition.\");\n }\n\n if (!transition) {\n throw new Error(\"Invariant violation: no transition.\");\n }\n\n const { operation, itemsLayout, draggableItem: item, acquiredItem } = transition;\n const itemBelongsToBoard = item.id === acquiredItem?.id || itemsLayout.items.some((it) => it.id === item.id);\n\n return {\n transition: null,\n removeTransition: null,\n announcement: itemBelongsToBoard ? { type: \"dnd-discarded\", item, operation } : null,\n };\n}\n\nfunction updateTransitionWithPointerEvent<D>(\n state: TransitionState<D>,\n { collisionIds, positionOffset, draggableRect }: UpdateWithPointerAction,\n): TransitionState<D> {\n const { transition } = state;\n\n if (!transition) {\n throw new Error(\"Invariant violation: no transition.\");\n }\n\n const layout = transition.layoutShift?.next ?? transition.itemsLayout;\n const layoutItem = layout.items.find((it) => it.id === transition.draggableItem.id);\n const itemWidth = layoutItem ? layoutItem.width : getDefaultColumnSpan(transition.draggableItem, layout.columns);\n const itemHeight = layoutItem ? layoutItem.height : getDefaultRowSpan(transition.draggableItem);\n const itemSize = itemWidth * itemHeight;\n\n const isOutOfBoundaries =\n transition.operation !== \"resize\" ? collisionIds.length < itemSize : collisionIds.length === 0;\n\n if (isOutOfBoundaries) {\n return {\n transition: {\n ...transition,\n draggableRect,\n collisionIds: new Set(),\n layoutShift: null,\n insertionDirection: null,\n },\n removeTransition: null,\n announcement: null,\n };\n }\n\n const placeholdersLayout = getLayoutPlaceholders(transition);\n const collisionRect = getHoveredRect(collisionIds, placeholdersLayout.items);\n const appendPath = transition.operation === \"resize\" ? appendResizePath : appendMovePath;\n const path = appendPath(transition.path, collisionRect);\n\n const insertionDirection = transition.insertionDirection ?? getInsertionDirection(positionOffset);\n const layoutShift = getLayoutShift(transition, path, insertionDirection);\n\n return {\n transition: {\n ...transition,\n draggableRect,\n collisionIds: new Set(collisionIds),\n layoutShift,\n path,\n insertionDirection,\n },\n removeTransition: null,\n announcement: null,\n };\n}\n\nfunction updateTransitionWithKeyboardEvent<D>(\n state: TransitionState<D>,\n { direction }: UpdateWithKeyboardAction,\n): TransitionState<D> {\n const { transition } = state;\n\n if (!transition) {\n throw new Error(\"Invariant violation: no transition.\");\n }\n\n const updateManualItemTransition = (transition: Transition<D>, direction: Direction): TransitionState<D> => {\n const xDelta = direction === \"left\" ? -1 : direction === \"right\" ? 1 : 0;\n const yDelta = direction === \"up\" ? -1 : direction === \"down\" ? 1 : 0;\n const lastPosition = transition.path[transition.path.length - 1];\n const nextPosition = new Position({ x: lastPosition.x + xDelta, y: lastPosition.y + yDelta });\n const nextPath = [...transition.path, nextPosition];\n\n // Check resizing below min size.\n const layout = transition.layoutShift?.next ?? transition.itemsLayout;\n const layoutItem = layout.items.find((it) => it.id === transition.draggableItem.id);\n const minWidth = getMinColumnSpan(transition.draggableItem, transition.itemsLayout.columns);\n const minHeight = getMinRowSpan(transition.draggableItem);\n if (\n transition.operation === \"resize\" &&\n layoutItem &&\n (layoutItem.width + xDelta < minWidth || layoutItem.height + yDelta < minHeight)\n ) {\n return state;\n }\n\n try {\n const layoutShift = getLayoutShift(transition, nextPath);\n const nextTransition = { ...transition, layoutShift, path: nextPath };\n return {\n transition: nextTransition,\n removeTransition: null,\n announcement: createOperationAnnouncement(nextTransition, direction),\n };\n } catch (e) {\n // Can't create next layout because the next path is out of bounds.\n return state;\n }\n };\n\n switch (direction) {\n case \"left\":\n return updateManualItemTransition(transition, \"left\");\n case \"right\":\n return updateManualItemTransition(transition, \"right\");\n case \"up\":\n return updateManualItemTransition(transition, \"up\");\n case \"down\":\n return updateManualItemTransition(transition, \"down\");\n }\n}\n\nfunction acquireTransitionItem<D>(\n state: TransitionState<D>,\n { position, layoutElement, acquiredItemElement }: AcquireItemAction,\n): TransitionState<D> {\n const { transition } = state;\n\n if (!transition) {\n throw new Error(\"Invariant violation: no transition.\");\n }\n\n const { columns } = transition.itemsLayout;\n\n const layoutRect = layoutElement.getBoundingClientRect();\n const itemRect = transition.draggableRect;\n const offset = new Coordinates({ x: itemRect.left - layoutRect.x, y: itemRect.top - layoutRect.y });\n const insertionDirection = getInsertionDirection(offset);\n\n // Update original insertion position if the item can't fit into the layout by width.\n const width = getDefaultColumnSpan(transition.draggableItem, columns);\n position = new Position({ x: Math.min(columns - width, position.x), y: position.y });\n\n const path = [...transition.path, position];\n\n const layoutShift = getLayoutShift(transition, path, insertionDirection);\n\n // The columnOffset, columnSpan and rowSpan are of no use as of being overridden by the layout shift.\n const acquiredItem = { ...transition.draggableItem, columnOffset: 0, columnSpan: 1, rowSpan: 1 };\n\n const nextTransition: Transition<D> = {\n ...transition,\n collisionIds: new Set(),\n layoutShift,\n path,\n acquiredItem,\n acquiredItemElement,\n };\n return {\n transition: nextTransition,\n removeTransition: null,\n announcement: createOperationAnnouncement(nextTransition, null),\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"announcements.js","sourceRoot":"","sources":["../../../../src/board/utils/announcements.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAGtC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAS9E;;GAEG;AACH,MAAM,UAAU,2BAA2B,CACzC,UAAyB,EACzB,SAA2B;;IAE3B,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,UAAU,CAAC;IAC3D,MAAM,UAAU,GAAG,MAAA,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC,mCAAI,IAAI,CAAC;IAEjG,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO,IAAI,CAAC;KACb;IAED,MAAM,SAAS,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACvC,MAAM,QAAQ,GAAG,MAAA,SAAS,aAAT,SAAS,uBAAT,SA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OAAO,WAAW,CAAC,+BAA+B,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;SACjG;IACH,CAAC;IAED,SAAS,6BAA6B,CAAC,YAAqC;QAC1E,OAAO,WAAW,CAAC,2BAA2B,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC/G,CAAC;IAED,QAAQ,YAAY,CAAC,IAAI,EAAE;QACzB,KAAK,aAAa;YAChB,OAAO,WAAW,CAAC,0BAA0B,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;QACxE,KAAK,YAAY;YACf,OAAO,2BAA2B,CAAC,YAAY,CAAC,CAAC;QACnD,KAAK,eAAe;YAClB,OAAO,WAAW,CAAC,4BAA4B,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;QAC1E,KAAK,eAAe;YAClB,OAAO,WAAW,CAAC,4BAA4B,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;QAC1E,KAAK,cAAc;YACjB,OAAO,6BAA6B,CAAC,YAAY,CAAC,CAAC;KACtD;AACH,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Direction, ItemId } from \"../../internal/interfaces\";\nimport { getMinColumnSpan, getMinRowSpan } from \"../../internal/utils/layout\";\nimport {\n BoardProps,\n DndActionAnnouncement,\n ItemRemovedAnnouncement,\n Transition,\n TransitionAnnouncement,\n} from \"../interfaces\";\n\n/**\n * Creates an announcement object describing the last user move.\n */\nexport function createOperationAnnouncement<D>(\n transition: Transition<D>,\n direction: null | Direction
|
|
1
|
+
{"version":3,"file":"announcements.js","sourceRoot":"","sources":["../../../../src/board/utils/announcements.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAGtC,OAAO,EAAE,gBAAgB,EAAE,aA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AAO,6BAA6B,CAAC,YAAY,CAAC,CAAC;KACtD;AACH,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Direction, ItemId } from \"../../internal/interfaces\";\nimport { getMinColumnSpan, getMinRowSpan } from \"../../internal/utils/layout\";\nimport {\n BoardProps,\n DndActionAnnouncement,\n ItemRemovedAnnouncement,\n Transition,\n TransitionAnnouncement,\n} from \"../interfaces\";\n\n/**\n * Creates an announcement object describing the last user move.\n */\nexport function createOperationAnnouncement<D>(\n transition: Transition<D>,\n direction: null | Direction,\n): null | DndActionAnnouncement {\n const { operation, layoutShift, itemsLayout } = transition;\n const targetItem = itemsLayout.items.find((it) => it.id === transition.draggableItem.id) ?? null;\n\n if (!layoutShift) {\n return null;\n }\n\n const firstMove = layoutShift.moves[0];\n const targetId = firstMove?.itemId ?? targetItem?.id;\n if (!targetId) {\n return null;\n }\n\n const itemMoves = layoutShift.moves.filter((m) => m.itemId === targetId);\n const lastItemMove = itemMoves[itemMoves.length - 1];\n const placement = lastItemMove ?? targetItem;\n\n const conflicts = new Set(layoutShift.conflicts);\n\n const disturbed = new Set(layoutShift.moves.map((move) => move.itemId));\n disturbed.delete(targetId);\n\n return {\n type: \"dnd-action\",\n item: transition.draggableItem,\n operation,\n placement: {\n x: placement.x,\n y: placement.y,\n width: placement.width,\n height: placement.height,\n },\n direction,\n conflicts,\n disturbed,\n };\n}\n\n/**\n * Applies i18nStrings to the announcement object to produce a string for the live region.\n */\nexport function announcementToString<D>(\n announcement: TransitionAnnouncement,\n items: readonly BoardProps.Item<D>[],\n i18nStrings: BoardProps.I18nStrings<D>,\n columns: number,\n): string {\n if (!announcement) {\n return \"\";\n }\n const item = announcement.item as BoardProps.Item<D>;\n\n const toItem = (id: ItemId) => items.find((it) => it?.id === id)!;\n const formatDirection = (direction: null | Direction) => {\n if (!direction) {\n return null;\n }\n return direction === \"left\" || direction === \"right\" ? \"horizontal\" : \"vertical\";\n };\n\n function createDndActionAnnouncement(announcement: DndActionAnnouncement) {\n const placement = announcement.placement;\n const direction = formatDirection(announcement.direction);\n const conflicts = [...announcement.conflicts].map(toItem);\n const disturbed = [...announcement.disturbed].map(toItem);\n\n switch (announcement.operation) {\n case \"reorder\":\n return i18nStrings.liveAnnouncementDndItemReordered({\n item,\n placement,\n direction: direction!,\n conflicts,\n disturbed,\n });\n case \"resize\":\n return i18nStrings.liveAnnouncementDndItemResized({\n item,\n placement,\n direction: direction!,\n isMinimalColumnsReached: placement.width === getMinColumnSpan(item, columns),\n isMinimalRowsReached: placement.height === getMinRowSpan(item),\n conflicts,\n disturbed,\n });\n case \"insert\":\n return i18nStrings.liveAnnouncementDndItemInserted({ item, placement, conflicts, disturbed });\n }\n }\n\n function createItemRemovedAnnouncement(announcement: ItemRemovedAnnouncement) {\n return i18nStrings.liveAnnouncementItemRemoved({ item, disturbed: [...announcement.disturbed].map(toItem) });\n }\n\n switch (announcement.type) {\n case \"dnd-started\":\n return i18nStrings.liveAnnouncementDndStarted(announcement.operation);\n case \"dnd-action\":\n return createDndActionAnnouncement(announcement);\n case \"dnd-committed\":\n return i18nStrings.liveAnnouncementDndCommitted(announcement.operation);\n case \"dnd-discarded\":\n return i18nStrings.liveAnnouncementDndDiscarded(announcement.operation);\n case \"item-removed\":\n return createItemRemovedAnnouncement(announcement);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../../src/board/utils/events.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAGtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAG7D,MAAM,UAAU,sBAAsB,CACpC,KAAoC,EACpC,WAAwB;;IAExB,MAAM,YAAY,GAAG,MAAA,MAAA,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI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C,EAAE,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS;KACnF,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { LayoutShift } from \"../../internal/layout-engine/interfaces\";\nimport { createCustomEvent } from \"../../internal/utils/events\";\nimport { transformItems } from \"../../internal/utils/layout\";\nimport { BoardProps } from \"../interfaces\";\n\nexport function createItemsChangeEvent<D>(\n items: readonly BoardProps.Item<D>[],\n layoutShift: LayoutShift
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../../src/board/utils/events.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAGtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAG7D,MAAM,UAAU,sBAAsB,CACpC,KAAoC,EACpC,WAAwB;;IAExB,MAAM,YAAY,GAAG,MAAA,MAAA,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,0CAAE,MAAM,mCAAI,IAAI,CAAC;IAC9F,MAAM,UAAU,GAAG,MAAA,MAAA,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,0CAAE,MAAM,mCAAI,IAAI,CAAC;IAC1F,MAAM,YAAY,GAAG,MAAA,MAAA,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,0CAAE,MAAM,mCAAI,IAAI,CAAC;IAC9F,MAAM,YAAY,GAAG,MAAA,MAAA,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,0CAAE,MAAM,mCAAI,IAAI,CAAC;IAE9F,MAAM,QAAQ,GAAG,cAAc,CAAC,KAAK,EAAE,WAAW,CAAC,IAAI,EAAE,YAAY,aAAZ,YAAY,cAAZ,YAAY,GAAI,YAAY,CAAC,CAAC;IAEvF,OAAO,iBAAiB,CAAC;QACvB,KAAK,EAAE,QAAQ;QACf,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,YAAY,CAAC;QACxD,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,YAAY,CAAC;QACvD,WAAW,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,YAAY,CAAC;QAC1D,SAAS,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS;KACnF,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { LayoutShift } from \"../../internal/layout-engine/interfaces\";\nimport { createCustomEvent } from \"../../internal/utils/events\";\nimport { transformItems } from \"../../internal/utils/layout\";\nimport { BoardProps } from \"../interfaces\";\n\nexport function createItemsChangeEvent<D>(\n items: readonly BoardProps.Item<D>[],\n layoutShift: LayoutShift,\n): CustomEvent<BoardProps.ItemsChangeDetail<D>> {\n const insertTarget = layoutShift.moves.find((move) => move.type === \"INSERT\")?.itemId ?? null;\n const moveTarget = layoutShift.moves.find((move) => move.type === \"MOVE\")?.itemId ?? null;\n const removeTarget = layoutShift.moves.find((move) => move.type === \"REMOVE\")?.itemId ?? null;\n const resizeTarget = layoutShift.moves.find((move) => move.type === \"RESIZE\")?.itemId ?? null;\n\n const newItems = transformItems(items, layoutShift.next, resizeTarget ?? insertTarget);\n\n return createCustomEvent({\n items: newItems,\n addedItem: newItems.find((it) => it.id === insertTarget),\n removedItem: items.find((it) => it.id === removeTarget),\n resizedItem: newItems.find((it) => it.id === resizeTarget),\n movedItem: !insertTarget ? newItems.find((it) => it.id === moveTarget) : undefined,\n });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-hovered-rect.js","sourceRoot":"","sources":["../../../../src/board/utils/get-hovered-rect.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAItC;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,aAAgC,EAAE,YAAuC;IACtG,MAAM,mBAAmB,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAE,CAAC,CAAC;IAC9F,OAAO,mBAAmB,CAAC,MAAM,CAC/B,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;QACpB,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC;QACpC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;QACtC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC;QAC7D,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC;KAC3D,CAAC,EACF;QACE,GAAG,EAAE,MAAM,CAAC,iBAAiB;QAC7B,IAAI,EAAE,MAAM,CAAC,iBAAiB;QAC9B,MAAM,EAAE,MAAM,CAAC,iBAAiB;QAChC,KAAK,EAAE,MAAM,CAAC,iBAAiB;KAChC,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { GridLayoutItem, ItemId } from \"../../internal/interfaces\";\n\n/**\n * Creates a minimal hovered rectangle (in grid units) that contains all collided placeholders.\n */\nexport function getHoveredRect(collisionsIds: readonly ItemId[], placeholders: readonly GridLayoutItem[]) {\n const hoveredPlaceholders = collisionsIds.map((id) => placeholders.find((p) => p.id === id)!);\n return hoveredPlaceholders.reduce(\n (rect, collision) => ({\n top: Math.min(rect.top, collision.y),\n left: Math.min(rect.left, collision.x),\n bottom: Math.max(rect.bottom, collision.y + collision.height),\n right: Math.max(rect.right, collision.x + collision.width),\n }),\n {\n top: Number.POSITIVE_INFINITY,\n left: Number.POSITIVE_INFINITY,\n bottom: Number.NEGATIVE_INFINITY,\n right: Number.NEGATIVE_INFINITY,\n }
|
|
1
|
+
{"version":3,"file":"get-hovered-rect.js","sourceRoot":"","sources":["../../../../src/board/utils/get-hovered-rect.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAItC;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,aAAgC,EAAE,YAAuC;IACtG,MAAM,mBAAmB,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAE,CAAC,CAAC;IAC9F,OAAO,mBAAmB,CAAC,MAAM,CAC/B,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;QACpB,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC;QACpC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;QACtC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC;QAC7D,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC;KAC3D,CAAC,EACF;QACE,GAAG,EAAE,MAAM,CAAC,iBAAiB;QAC7B,IAAI,EAAE,MAAM,CAAC,iBAAiB;QAC9B,MAAM,EAAE,MAAM,CAAC,iBAAiB;QAChC,KAAK,EAAE,MAAM,CAAC,iBAAiB;KAChC,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { GridLayoutItem, ItemId } from \"../../internal/interfaces\";\n\n/**\n * Creates a minimal hovered rectangle (in grid units) that contains all collided placeholders.\n */\nexport function getHoveredRect(collisionsIds: readonly ItemId[], placeholders: readonly GridLayoutItem[]) {\n const hoveredPlaceholders = collisionsIds.map((id) => placeholders.find((p) => p.id === id)!);\n return hoveredPlaceholders.reduce(\n (rect, collision) => ({\n top: Math.min(rect.top, collision.y),\n left: Math.min(rect.left, collision.x),\n bottom: Math.max(rect.bottom, collision.y + collision.height),\n right: Math.max(rect.right, collision.x + collision.width),\n }),\n {\n top: Number.POSITIVE_INFINITY,\n left: Number.POSITIVE_INFINITY,\n bottom: Number.NEGATIVE_INFINITY,\n right: Number.NEGATIVE_INFINITY,\n },\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layout.js","sourceRoot":"","sources":["../../../../src/board/utils/layout.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAKtC,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AAO,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC;gBACpC,MAAM,EAAE,UAAU,CAAC,aAAa,CAAC,EAAE;gBACnC,KAAK;gBACL,MAAM;gBACN,IAAI,EAAE,sBAAsB,CAAC,IAAI,EAAE,kBAAkB,aAAlB,kBAAkB,cAAlB,kBAAkB,GAAI,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC;aACjF,CAAC,CAAC;KACN;AACH,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Direction } from \"../../internal/interfaces\";\nimport { LayoutShift } from \"../../internal/layout-engine/interfaces\";\nimport { Coordinates } from \"../../internal/utils/coordinates\";\nimport { createPlaceholdersLayout, getDefaultColumnSpan, getDefaultRowSpan } from \"../../internal/utils/layout\";\nimport { Position } from \"../../internal/utils/position\";\nimport { Transition } from \"../interfaces\";\nimport { normalizeInsertionPath } from \"./path\";\n\nexport function getLayoutColumns<D>(transition: Transition<D>) {\n return transition.itemsLayout.columns;\n}\n\n// The rows can be overridden during transition to create more drop targets at the bottom.\nexport function getLayoutRows<D>(transition: Transition<D>) {\n const layout = transition.layoutShift?.next ?? transition.itemsLayout;\n\n const layoutItem = layout.items.find((it) => it.id === transition.draggableItem.id);\n const itemHeight = layoutItem?.height ?? getDefaultRowSpan(transition.draggableItem);\n // Add extra row for resize when already at the bottom.\n if (transition.operation === \"resize\") {\n return Math.max(layout.rows, layoutItem ? layoutItem.y + layoutItem.height + 1 : 0);\n }\n // Add extra row(s) for reorder/insert based on item's height.\n else {\n return Math.max(layout.rows, transition.itemsLayout.rows + itemHeight);\n }\n}\n\nexport function getLayoutPlaceholders<D>(transition: Transition<D>) {\n const rows = getLayoutRows(transition);\n const columns = getLayoutColumns(transition);\n return createPlaceholdersLayout(rows, columns);\n}\n\n/**\n * Retrieves direction from where the inserting item comes.\n */\nexport function getInsertionDirection(cursorOffset: Coordinates): Direction {\n if (cursorOffset.x < 0) {\n return \"right\";\n }\n if (cursorOffset.x > 0) {\n return \"left\";\n }\n if (cursorOffset.y < 0) {\n return \"down\";\n }\n if (cursorOffset.y > 0) {\n return \"up\";\n }\n return \"right\";\n}\n\n/**\n * Applies transition operation (reorder/move/insert) and retrieves an object that describes the updated\n * layout and the moves to be made including and not including items float to top.\n *\n * The layout shift w/o refloat is used for rendering and w/ refloat is used for live announcements.\n */\nexport function getLayoutShift<D>(\n transition: Transition<D>,\n path: readonly Position[],\n insertionDirection?: Direction
|
|
1
|
+
{"version":3,"file":"layout.js","sourceRoot":"","sources":["../../../../src/board/utils/layout.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAKtC,OAAO,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAGhH,OAAO,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAC;AAEhD,MAAM,UAAU,gBAAgB,CAAI,UAAyB;IAC3D,OAAO,UAAU,CAAC,WAAW,CAAC,OAAO,CAAC;AACxC,CAAC;AAED,0FAA0F;AAC1F,MAAM,UAAU,aAAa,CAAI,UAAyB;;IACxD,MAAM,MAAM,GAAG,MAAA,MAAA,UAAU,CAAC,WAAW,0CAAE,IAAI,mCAAI,UAAU,CAAC,WAAW,CAAC;IAEtE,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;IACpF,MAAM,UAAU,GAAG,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,mCAAI,iBAAiB,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IACrF,uDAAuD;IACvD,IAAI,UAAU,CAAC,SAAS,KAAK,QAAQ,EAAE;QACrC,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,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C,UAAU,CAAC,CAAC;IACvC,MAAM,OAAO,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAE7C,QAAQ,UAAU,CAAC,SAAS,EAAE;QAC5B,KAAK,QAAQ;YACX,OAAO,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,aAAa,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QACvF,KAAK,SAAS;YACZ,OAAO,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,aAAa,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QACrF,KAAK,QAAQ;YACX,OAAO,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC;gBACpC,MAAM,EAAE,UAAU,CAAC,aAAa,CAAC,EAAE;gBACnC,KAAK;gBACL,MAAM;gBACN,IAAI,EAAE,sBAAsB,CAAC,IAAI,EAAE,kBAAkB,aAAlB,kBAAkB,cAAlB,kBAAkB,GAAI,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC;aACjF,CAAC,CAAC;KACN;AACH,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Direction } from \"../../internal/interfaces\";\nimport { LayoutShift } from \"../../internal/layout-engine/interfaces\";\nimport { Coordinates } from \"../../internal/utils/coordinates\";\nimport { createPlaceholdersLayout, getDefaultColumnSpan, getDefaultRowSpan } from \"../../internal/utils/layout\";\nimport { Position } from \"../../internal/utils/position\";\nimport { Transition } from \"../interfaces\";\nimport { normalizeInsertionPath } from \"./path\";\n\nexport function getLayoutColumns<D>(transition: Transition<D>) {\n return transition.itemsLayout.columns;\n}\n\n// The rows can be overridden during transition to create more drop targets at the bottom.\nexport function getLayoutRows<D>(transition: Transition<D>) {\n const layout = transition.layoutShift?.next ?? transition.itemsLayout;\n\n const layoutItem = layout.items.find((it) => it.id === transition.draggableItem.id);\n const itemHeight = layoutItem?.height ?? getDefaultRowSpan(transition.draggableItem);\n // Add extra row for resize when already at the bottom.\n if (transition.operation === \"resize\") {\n return Math.max(layout.rows, layoutItem ? layoutItem.y + layoutItem.height + 1 : 0);\n }\n // Add extra row(s) for reorder/insert based on item's height.\n else {\n return Math.max(layout.rows, transition.itemsLayout.rows + itemHeight);\n }\n}\n\nexport function getLayoutPlaceholders<D>(transition: Transition<D>) {\n const rows = getLayoutRows(transition);\n const columns = getLayoutColumns(transition);\n return createPlaceholdersLayout(rows, columns);\n}\n\n/**\n * Retrieves direction from where the inserting item comes.\n */\nexport function getInsertionDirection(cursorOffset: Coordinates): Direction {\n if (cursorOffset.x < 0) {\n return \"right\";\n }\n if (cursorOffset.x > 0) {\n return \"left\";\n }\n if (cursorOffset.y < 0) {\n return \"down\";\n }\n if (cursorOffset.y > 0) {\n return \"up\";\n }\n return \"right\";\n}\n\n/**\n * Applies transition operation (reorder/move/insert) and retrieves an object that describes the updated\n * layout and the moves to be made including and not including items float to top.\n *\n * The layout shift w/o refloat is used for rendering and w/ refloat is used for live announcements.\n */\nexport function getLayoutShift<D>(\n transition: Transition<D>,\n path: readonly Position[],\n insertionDirection?: Direction,\n): null | LayoutShift {\n if (path.length === 0) {\n return null;\n }\n\n const width = getDefaultColumnSpan(transition.draggableItem, getLayoutColumns(transition));\n const height = getDefaultRowSpan(transition.draggableItem);\n const rows = getLayoutRows(transition);\n const columns = getLayoutColumns(transition);\n\n switch (transition.operation) {\n case \"resize\":\n return transition.layoutEngine.resize({ itemId: transition.draggableItem.id, path });\n case \"reorder\":\n return transition.layoutEngine.move({ itemId: transition.draggableItem.id, path });\n case \"insert\":\n return transition.layoutEngine.insert({\n itemId: transition.draggableItem.id,\n width,\n height,\n path: normalizeInsertionPath(path, insertionDirection ?? \"right\", columns, rows),\n });\n }\n}\n"]}
|
package/board/utils/path.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.js","sourceRoot":"","s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C;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Direction } from \"../../internal/interfaces\";\nimport { Rect } from \"../../internal/interfaces\";\nimport { Position } from \"../../internal/utils/position\";\n\n/**\n * The insertion operation is similar to reorder yet the first path entry is treated differently.\n * The normalization removes leading path entries if on the same edge to optimize UX.\n */\nexport function normalizeInsertionPath(\n path: readonly Position[],\n insertionDirection: Direction,\n columns: number,\n rows: number
|
|
1
|
+
{"version":3,"file":"path.js","sourceRoot":"","sources":["../../../../src/board/utils/path.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAEzD;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CACpC,IAAyB,EACzB,kBAA6B,EAC7B,OAAe,EACf,IAAY;IAEZ,IAAI,SAAS,GAAG,CAAC,CAAC,CAAC;IACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACpC,QAAQ,kBAAkB,EAAE;YAC1B,KAAK,MAAM,CAAC,CAAC;gBACX,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE;oBACnB,SAAS,GAAG,CAAC,CAAC;iBACf;gBACD,MAAM;aACP;YACD,KAAK,OAAO,CAAC,CAAC;gBACZ,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,GAAG,CAAC,EAAE;oBAC7B,SAAS,GAAG,CAAC,CAAC;iBACf;gBACD,MAAM;aACP;YACD,KAAK,IAAI,CAAC,CAAC;gBACT,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE;oBACnB,SAAS,GAAG,CAAC,CAAC;iBACf;gBACD,MAAM;aACP;YACD,KAAK,MAAM,CAAC,CAAC;gBACX,IAAI,I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,CAAC,CAAC,IAAI,CAAC,KAAK,YAAY,CAAC,CAAC,EAAE;QACnD,IAAI,EAAE,aAAa,KAAK,GAAG,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SACjD;QACD,IAAI,CAAC,KAAK,YAAY,CAAC,CAAC,EAAE;YACxB,CAAC,IAAI,EAAE,CAAC;SACT;aAAM;YACL,CAAC,IAAI,EAAE,CAAC;SACT;QACD,IAAI,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;KACnC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Direction } from \"../../internal/interfaces\";\nimport { Rect } from \"../../internal/interfaces\";\nimport { Position } from \"../../internal/utils/position\";\n\n/**\n * The insertion operation is similar to reorder yet the first path entry is treated differently.\n * The normalization removes leading path entries if on the same edge to optimize UX.\n */\nexport function normalizeInsertionPath(\n path: readonly Position[],\n insertionDirection: Direction,\n columns: number,\n rows: number,\n): Position[] {\n let edgeIndex = -1;\n for (let i = 0; i < path.length; i++) {\n switch (insertionDirection) {\n case \"left\": {\n if (path[i].x === 0) {\n edgeIndex = i;\n }\n break;\n }\n case \"right\": {\n if (path[i].x === columns - 1) {\n edgeIndex = i;\n }\n break;\n }\n case \"up\": {\n if (path[i].y === 0) {\n edgeIndex = i;\n }\n break;\n }\n case \"down\": {\n if (path[i].y === rows - 1) {\n edgeIndex = i;\n }\n break;\n }\n }\n }\n return path.slice(edgeIndex);\n}\n\nexport function appendMovePath(prevPath: readonly Position[], collisionRect: Rect): Position[] {\n return appendPath(prevPath, new Position({ x: collisionRect.left, y: collisionRect.top }));\n}\n\nexport function appendResizePath(prevPath: readonly Position[], collisionRect: Rect): Position[] {\n return appendPath(prevPath, new Position({ x: collisionRect.right, y: collisionRect.bottom }));\n}\n\n/**\n * The operation path must be strictly incremental (each dx + dy == 1). However, the actual collisions\n * data can have gaps due to pointer events throttling or other factors.\n *\n * The function produces next path from previous path and the target position by incrementally adding steps.\n */\nfunction appendPath(prevPath: readonly Position[], nextPosition: Position): Position[] {\n const path: Array<Position> = [...prevPath];\n const lastPosition = prevPath[prevPath.length - 1];\n\n if (!lastPosition) {\n return [nextPosition];\n }\n\n const vx = Math.sign(nextPosition.x - lastPosition.x);\n const vy = Math.sign(nextPosition.y - lastPosition.y);\n\n let { x, y } = lastPosition;\n let safetyCounter = 0;\n\n while (x !== nextPosition.x || y !== nextPosition.y) {\n if (++safetyCounter === 100) {\n throw new Error(\"Infinite loop in appendPath.\");\n }\n if (x !== nextPosition.x) {\n x += vx;\n } else {\n y += vy;\n }\n path.push(new Position({ x, y }));\n }\n\n return path;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generators.js","sourceRoot":"","sources":["../../../../src/internal/debug-tools/generators.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAItC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC;AAuB7B,MAAM,cAAc,GAAG,4BAA4B,CAAC;AAEpD,MAAM,UAAU,YAAY,CAAC,OAA6B;;IACxD,MAAM,KAAK,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,mCAAI,CAAC,CAAC;IAClC,MAAM,UAAU,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,mCAAI,EAAE,CAAC;IAC7C,MAAM,gBAAgB,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,gBAAgB,mCAAI,IAAI,CAAC;IAC3D,MAAM,iBAAiB,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,iBAAiB,mCAAI,IAAI,CAAC;IAE7D,MAAM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AAC,WAAW,CAAC,CAAC;AACzD,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Direction, GridLayout, GridLayoutItem } from \"../interfaces\";\nimport { InsertCommand, MoveCommand, ResizeCommand } from \"../layout-engine/interfaces\";\nimport { Position } from \"../utils/position\";\nimport { toMatrix } from \".\";\n\nexport type GenerateMoveType = \"any\" | \"vertical\" | \"horizontal\";\n\nexport interface GenerateGridOptions {\n width?: number;\n totalItems?: number;\n averageItemWidth?: number;\n averageItemHeight?: number;\n}\n\nexport interface GenerateGridResizeOptions {\n maxWidthIncrement?: number;\n maxWidthDecrement?: number;\n maxHeightIncrement?: number;\n maxHeightDecrement?: number;\n}\n\nexport interface GenerateGridInsertOptions {\n maxWidth?: number;\n maxHeight?: number;\n}\n\nconst LETTER_INDICES = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\n\nexport function generateGrid(options?: GenerateGridOptions): GridLayout {\n const width = options?.width ?? 6;\n const totalItems = options?.totalItems ?? 20;\n const averageItemWidth = options?.averageItemWidth ?? 1.44;\n const averageItemHeight = options?.averageItemHeight ?? 1.44;\n\n const allowance = {\n horizontal: Math.floor(totalItems * (averageItemWidth - 1)),\n vertical: Math.floor(totalItems * (averageItemHeight - 1)),\n };\n\n const items: GridLayoutItem[] = [...Array(totalItems)].map((_, index) => ({\n id: getGridItemId(index),\n width: 1,\n height: 1,\n y: 0,\n x: 0,\n }));\n\n let selectedAllowance: \"horizontal\" | \"vertical\" = \"horizontal\";\n while (allowance.horizontal > 0 || allowance.vertical > 0) {\n if (allowance.horizontal === 0) {\n selectedAllowance = \"vertical\";\n } else if (allowance.vertical === 0) {\n selectedAllowance = \"horizontal\";\n } else {\n selectedAllowance = selectedAllowance === \"horizontal\" ? \"vertical\" : \"horizontal\";\n }\n\n const index = getRandomIndex(items);\n\n if (selectedAllowance === \"horizontal\") {\n items[index].width = Math.min(width - items[index].x, items[index].width + 1);\n for (let i = 0; i < items[index].height; i++) {\n allowance.horizontal--;\n }\n } else {\n items[index].height++;\n for (let i = 0; i < items[index].width; i++) {\n allowance.vertical--;\n }\n }\n }\n\n const grid: string[][] = [];\n\n for (const item of items) {\n item.x = getRandomOffset(width, item.width);\n\n for (let y = 0; y < grid.length; y++) {\n for (let x = item.x; x < item.x + item.width; x++) {\n if (grid[y][x].trim()) {\n item.y = y + 1;\n break;\n }\n }\n }\n\n for (let y = item.y; y < item.y + item.height; y++) {\n while (grid.length <= y) {\n grid.push([...Array(width)].map(() => \" \"));\n }\n\n for (let x = item.x; x < item.x + item.width; x++) {\n grid[y][x] = item.id;\n }\n }\n }\n\n items.sort((a, b) => (b.y - a.y === 0 ? b.x - a.x : b.y - a.y));\n\n return { items, columns: width, rows: grid.length };\n}\n\nexport function generateMove(grid: GridLayout, type: GenerateMoveType = \"any\"): MoveCommand {\n const textGrid = toMatrix(grid);\n const moveTarget = grid.items[getRandomIndex(grid.items)];\n\n const affordance: [Direction, number][] = [];\n\n if (moveTarget.y > 0) {\n affordance.push([\"up\", moveTarget.y]);\n }\n if (moveTarget.y + moveTarget.height <= textGrid.length) {\n affordance.push([\"down\", 1 + textGrid.length - (moveTarget.y + moveTarget.height)]);\n }\n if (moveTarget.x > 0) {\n affordance.push([\"left\", moveTarget.x]);\n }\n if (moveTarget.x + moveTarget.width < textGrid[0].length) {\n affordance.push([\"right\", textGrid[0].length - (moveTarget.x + moveTarget.width)]);\n }\n\n function swap(type: \"vertical\" | \"horizontal\" | \"any\"): Position {\n const verticalAffordance = affordance.filter(([direction]) => direction === \"up\" || direction === \"down\");\n const horizontalAffordance = affordance.filter(([direction]) => direction === \"left\" || direction === \"right\");\n const chosenAffordance =\n type === \"any\" ? affordance : type === \"vertical\" ? verticalAffordance : horizontalAffordance;\n\n if (chosenAffordance.length === 0) {\n throw new Error(\"Move is not possible\");\n }\n\n const [direction, maxDistance] = chosenAffordance[getRandomIndex(chosenAffordance)];\n const distance = 1 + Math.floor(Math.random() * maxDistance);\n switch (direction) {\n case \"up\":\n return new Position({ y: moveTarget.y - distance, x: moveTarget.x });\n case \"down\":\n return new Position({ y: moveTarget.y + distance, x: moveTarget.x });\n case \"left\":\n return new Position({ y: moveTarget.y, x: moveTarget.x - distance });\n case \"right\":\n return new Position({ y: moveTarget.y, x: moveTarget.x + distance });\n }\n }\n\n function replace(): Position {\n const verticalAffordance = affordance.filter(([direction]) => direction === \"up\" || direction === \"down\");\n const horizontalAffordance = affordance.filter(([direction]) => direction === \"left\" || direction === \"right\");\n\n if (horizontalAffordance.length === 0) {\n throw new Error(\"Move is not possible\");\n }\n\n const [directionVertical, maxDistanceVertical] = verticalAffordance[getRandomIndex(verticalAffordance)];\n const distanceVertical = 1 + Math.floor(Math.random() * maxDistanceVertical);\n\n const [directionHorizontal, maxDistanceHorizontal] = horizontalAffordance[getRandomIndex(horizontalAffordance)];\n const distanceHorizontal = 1 + Math.floor(Math.random() * maxDistanceHorizontal);\n\n switch (`${directionVertical}-${directionHorizontal}`) {\n case \"top-left\":\n return new Position({\n y: moveTarget.y - distanceVertical,\n x: moveTarget.x - distanceHorizontal,\n });\n case \"top-right\":\n return new Position({\n y: moveTarget.y - distanceVertical,\n x: moveTarget.x + distanceHorizontal,\n });\n case \"bottom-left\":\n return new Position({\n y: moveTarget.y + distanceVertical,\n x: moveTarget.x - distanceHorizontal,\n });\n case \"bottom-right\":\n return new Position({\n y: moveTarget.y + distanceVertical,\n x: moveTarget.x + distanceHorizontal,\n });\n }\n\n return new Position({ y: moveTarget.y, x: moveTarget.x });\n }\n\n const position = (() => {\n let repeatCounter = 0;\n while (repeatCounter < 10) {\n try {\n repeatCounter++;\n\n switch (type) {\n case \"vertical\":\n return swap(\"vertical\");\n case \"horizontal\":\n return swap(\"horizontal\");\n case \"any\":\n return Math.random() > 0.5 ? swap(\"any\") : replace();\n }\n } catch {\n // noop\n }\n }\n\n throw new Error(\"Move is not possible\");\n })();\n\n const path = generateRandomPath(new Position({ y: moveTarget.y, x: moveTarget.x }), position);\n\n return { itemId: moveTarget.id, path };\n}\n\nexport function generateResize(grid: GridLayout, options?: GenerateGridResizeOptions): ResizeCommand {\n const maxWidthIncrement = options?.maxHeightIncrement ?? grid.columns - 1;\n const maxWidthDecrement = options?.maxHeightDecrement ?? grid.columns - 1;\n const maxHeightIncrement = options?.maxHeightIncrement ?? Math.floor((grid.items.length - 1) % 2) + 1;\n const maxHeightDecrement = options?.maxHeightDecrement ?? Math.floor((grid.items.length - 1) % 2) + 1;\n\n const resizeTarget = grid.items[getRandomIndex(grid.items)];\n\n let maxWidthDelta = getRandomDirection();\n if (maxWidthDelta === 1 && maxWidthIncrement) {\n maxWidthDelta *= maxWidthIncrement;\n } else if (maxWidthDelta === -1 && maxWidthDecrement) {\n maxWidthDelta *= maxWidthDecrement;\n } else if (maxWidthIncrement) {\n maxWidthDelta = maxWidthIncrement;\n } else {\n maxWidthDelta = -maxWidthDecrement;\n }\n if (resizeTarget.width + maxWidthDelta < 1) {\n maxWidthDelta = -(resizeTarget.width - 1);\n } else if (resizeTarget.x + resizeTarget.width + maxWidthDelta >= grid.columns) {\n maxWidthDelta = grid.columns - (resizeTarget.x + resizeTarget.width);\n }\n const widthDelta = Math.sign(maxWidthDelta) * getRandomInt(0, Math.abs(maxWidthDelta) + 1);\n\n let maxHeightDelta = getRandomDirection();\n if (maxHeightDelta === 1 && maxHeightIncrement) {\n maxHeightDelta *= maxHeightIncrement;\n } else if (maxHeightDelta === -1 && maxHeightDecrement) {\n maxHeightDelta *= maxHeightDecrement;\n } else if (maxHeightIncrement) {\n maxHeightDelta = maxHeightIncrement;\n } else {\n maxHeightDelta = -maxHeightDecrement;\n }\n if (resizeTarget.height + maxHeightDelta < 1) {\n maxHeightDelta = -(resizeTarget.height - 1);\n }\n const heightDelta = Math.sign(maxHeightDelta) * getRandomInt(0, Math.abs(maxHeightDelta) + 1);\n\n const path = generateRandomPath(\n new Position({ x: resizeTarget.x + resizeTarget.width, y: resizeTarget.y + resizeTarget.height }),\n new Position({\n x: resizeTarget.x + resizeTarget.width + widthDelta,\n y: resizeTarget.y + resizeTarget.height + heightDelta,\n })\n );\n\n return { itemId: resizeTarget.id, path };\n}\n\nexport function generateInsert(grid: GridLayout, insertId = \"X\", options?: GenerateGridInsertOptions): InsertCommand {\n const maxWidth = options?.maxWidth ?? grid.columns;\n const maxHeight = options?.maxHeight ?? Math.floor(grid.items.length / 2) + 1;\n\n const textGrid = toMatrix(grid);\n\n const y = getRandomIndex(textGrid);\n const x = getRandomIndex(textGrid[y]);\n const width = getRandomInt(1, Math.max(1, maxWidth + 1 - x));\n const height = getRandomInt(1, maxHeight + 1);\n\n return { itemId: insertId, width, height, path: [new Position({ x, y })] };\n}\n\nexport function generateRandomPath(from: Position, to: Position): Position[] {\n const path = [];\n const directions: [\"y\", \"x\"] = [\"y\", \"x\"];\n\n const last = { ...from };\n while (last.y !== to.y || last.x !== to.x) {\n let direction = directions[getRandomIndex(directions)];\n if (last.y === to.y) {\n direction = \"x\";\n }\n if (last.x === to.x) {\n direction = \"y\";\n }\n last[direction] += to[direction] > from[direction] ? 1 : -1;\n path.push({ ...last });\n }\n\n return path;\n}\n\nfunction getRandomIndex(array: readonly unknown[]): number {\n return Math.floor(Math.random() * array.length);\n}\n\nfunction getRandomOffset(gridWidth: number, itemWidth: number): number {\n return Math.floor(Math.random() * (1 + gridWidth - itemWidth));\n}\n\nfunction getRandomDirection(): number {\n return Math.random() > 0.5 ? 1 : -1;\n}\n\nfunction getRandomInt(from: number, until: number): number {\n return Math.floor(Math.random() * (until - from)) + from;\n}\n\nfunction getGridItemId(index: number): string {\n const letter = LETTER_INDICES[index % LETTER_INDICES.length];\n const letterIndex = Math.floor(index / LETTER_INDICES.length);\n return letter + (letterIndex === 0 ? \"\" : letterIndex);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"generators.js","sourceRoot":"","sources":["../../../../src/internal/debug-tools/generators.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC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zB,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtC,CAAC;AAED,SAAS,YAAY,CAAC,IAAY,EAAE,KAAa;IAC/C,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC;AAC3D,CAAC;AAED,SAAS,aAAa,CAAC,KAAa;IAClC,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;IAC7D,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;IAC9D,OAAO,MAAM,GAAG,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;AACzD,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Direction, GridLayout, GridLayoutItem } from \"../interfaces\";\nimport { InsertCommand, MoveCommand, ResizeCommand } from \"../layout-engine/interfaces\";\nimport { Position } from \"../utils/position\";\nimport { toMatrix } from \".\";\n\nexport type GenerateMoveType = \"any\" | \"vertical\" | \"horizontal\";\n\nexport interface GenerateGridOptions {\n width?: number;\n totalItems?: number;\n averageItemWidth?: number;\n averageItemHeight?: number;\n}\n\nexport interface GenerateGridResizeOptions {\n maxWidthIncrement?: number;\n maxWidthDecrement?: number;\n maxHeightIncrement?: number;\n maxHeightDecrement?: number;\n}\n\nexport interface GenerateGridInsertOptions {\n maxWidth?: number;\n maxHeight?: number;\n}\n\nconst LETTER_INDICES = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\n\nexport function generateGrid(options?: GenerateGridOptions): GridLayout {\n const width = options?.width ?? 6;\n const totalItems = options?.totalItems ?? 20;\n const averageItemWidth = options?.averageItemWidth ?? 1.44;\n const averageItemHeight = options?.averageItemHeight ?? 1.44;\n\n const allowance = {\n horizontal: Math.floor(totalItems * (averageItemWidth - 1)),\n vertical: Math.floor(totalItems * (averageItemHeight - 1)),\n };\n\n const items: GridLayoutItem[] = [...Array(totalItems)].map((_, index) => ({\n id: getGridItemId(index),\n width: 1,\n height: 1,\n y: 0,\n x: 0,\n }));\n\n let selectedAllowance: \"horizontal\" | \"vertical\" = \"horizontal\";\n while (allowance.horizontal > 0 || allowance.vertical > 0) {\n if (allowance.horizontal === 0) {\n selectedAllowance = \"vertical\";\n } else if (allowance.vertical === 0) {\n selectedAllowance = \"horizontal\";\n } else {\n selectedAllowance = selectedAllowance === \"horizontal\" ? \"vertical\" : \"horizontal\";\n }\n\n const index = getRandomIndex(items);\n\n if (selectedAllowance === \"horizontal\") {\n items[index].width = Math.min(width - items[index].x, items[index].width + 1);\n for (let i = 0; i < items[index].height; i++) {\n allowance.horizontal--;\n }\n } else {\n items[index].height++;\n for (let i = 0; i < items[index].width; i++) {\n allowance.vertical--;\n }\n }\n }\n\n const grid: string[][] = [];\n\n for (const item of items) {\n item.x = getRandomOffset(width, item.width);\n\n for (let y = 0; y < grid.length; y++) {\n for (let x = item.x; x < item.x + item.width; x++) {\n if (grid[y][x].trim()) {\n item.y = y + 1;\n break;\n }\n }\n }\n\n for (let y = item.y; y < item.y + item.height; y++) {\n while (grid.length <= y) {\n grid.push([...Array(width)].map(() => \" \"));\n }\n\n for (let x = item.x; x < item.x + item.width; x++) {\n grid[y][x] = item.id;\n }\n }\n }\n\n items.sort((a, b) => (b.y - a.y === 0 ? b.x - a.x : b.y - a.y));\n\n return { items, columns: width, rows: grid.length };\n}\n\nexport function generateMove(grid: GridLayout, type: GenerateMoveType = \"any\"): MoveCommand {\n const textGrid = toMatrix(grid);\n const moveTarget = grid.items[getRandomIndex(grid.items)];\n\n const affordance: [Direction, number][] = [];\n\n if (moveTarget.y > 0) {\n affordance.push([\"up\", moveTarget.y]);\n }\n if (moveTarget.y + moveTarget.height <= textGrid.length) {\n affordance.push([\"down\", 1 + textGrid.length - (moveTarget.y + moveTarget.height)]);\n }\n if (moveTarget.x > 0) {\n affordance.push([\"left\", moveTarget.x]);\n }\n if (moveTarget.x + moveTarget.width < textGrid[0].length) {\n affordance.push([\"right\", textGrid[0].length - (moveTarget.x + moveTarget.width)]);\n }\n\n function swap(type: \"vertical\" | \"horizontal\" | \"any\"): Position {\n const verticalAffordance = affordance.filter(([direction]) => direction === \"up\" || direction === \"down\");\n const horizontalAffordance = affordance.filter(([direction]) => direction === \"left\" || direction === \"right\");\n const chosenAffordance =\n type === \"any\" ? affordance : type === \"vertical\" ? verticalAffordance : horizontalAffordance;\n\n if (chosenAffordance.length === 0) {\n throw new Error(\"Move is not possible\");\n }\n\n const [direction, maxDistance] = chosenAffordance[getRandomIndex(chosenAffordance)];\n const distance = 1 + Math.floor(Math.random() * maxDistance);\n switch (direction) {\n case \"up\":\n return new Position({ y: moveTarget.y - distance, x: moveTarget.x });\n case \"down\":\n return new Position({ y: moveTarget.y + distance, x: moveTarget.x });\n case \"left\":\n return new Position({ y: moveTarget.y, x: moveTarget.x - distance });\n case \"right\":\n return new Position({ y: moveTarget.y, x: moveTarget.x + distance });\n }\n }\n\n function replace(): Position {\n const verticalAffordance = affordance.filter(([direction]) => direction === \"up\" || direction === \"down\");\n const horizontalAffordance = affordance.filter(([direction]) => direction === \"left\" || direction === \"right\");\n\n if (horizontalAffordance.length === 0) {\n throw new Error(\"Move is not possible\");\n }\n\n const [directionVertical, maxDistanceVertical] = verticalAffordance[getRandomIndex(verticalAffordance)];\n const distanceVertical = 1 + Math.floor(Math.random() * maxDistanceVertical);\n\n const [directionHorizontal, maxDistanceHorizontal] = horizontalAffordance[getRandomIndex(horizontalAffordance)];\n const distanceHorizontal = 1 + Math.floor(Math.random() * maxDistanceHorizontal);\n\n switch (`${directionVertical}-${directionHorizontal}`) {\n case \"top-left\":\n return new Position({\n y: moveTarget.y - distanceVertical,\n x: moveTarget.x - distanceHorizontal,\n });\n case \"top-right\":\n return new Position({\n y: moveTarget.y - distanceVertical,\n x: moveTarget.x + distanceHorizontal,\n });\n case \"bottom-left\":\n return new Position({\n y: moveTarget.y + distanceVertical,\n x: moveTarget.x - distanceHorizontal,\n });\n case \"bottom-right\":\n return new Position({\n y: moveTarget.y + distanceVertical,\n x: moveTarget.x + distanceHorizontal,\n });\n }\n\n return new Position({ y: moveTarget.y, x: moveTarget.x });\n }\n\n const position = (() => {\n let repeatCounter = 0;\n while (repeatCounter < 10) {\n try {\n repeatCounter++;\n\n switch (type) {\n case \"vertical\":\n return swap(\"vertical\");\n case \"horizontal\":\n return swap(\"horizontal\");\n case \"any\":\n return Math.random() > 0.5 ? swap(\"any\") : replace();\n }\n } catch {\n // noop\n }\n }\n\n throw new Error(\"Move is not possible\");\n })();\n\n const path = generateRandomPath(new Position({ y: moveTarget.y, x: moveTarget.x }), position);\n\n return { itemId: moveTarget.id, path };\n}\n\nexport function generateResize(grid: GridLayout, options?: GenerateGridResizeOptions): ResizeCommand {\n const maxWidthIncrement = options?.maxHeightIncrement ?? grid.columns - 1;\n const maxWidthDecrement = options?.maxHeightDecrement ?? grid.columns - 1;\n const maxHeightIncrement = options?.maxHeightIncrement ?? Math.floor((grid.items.length - 1) % 2) + 1;\n const maxHeightDecrement = options?.maxHeightDecrement ?? Math.floor((grid.items.length - 1) % 2) + 1;\n\n const resizeTarget = grid.items[getRandomIndex(grid.items)];\n\n let maxWidthDelta = getRandomDirection();\n if (maxWidthDelta === 1 && maxWidthIncrement) {\n maxWidthDelta *= maxWidthIncrement;\n } else if (maxWidthDelta === -1 && maxWidthDecrement) {\n maxWidthDelta *= maxWidthDecrement;\n } else if (maxWidthIncrement) {\n maxWidthDelta = maxWidthIncrement;\n } else {\n maxWidthDelta = -maxWidthDecrement;\n }\n if (resizeTarget.width + maxWidthDelta < 1) {\n maxWidthDelta = -(resizeTarget.width - 1);\n } else if (resizeTarget.x + resizeTarget.width + maxWidthDelta >= grid.columns) {\n maxWidthDelta = grid.columns - (resizeTarget.x + resizeTarget.width);\n }\n const widthDelta = Math.sign(maxWidthDelta) * getRandomInt(0, Math.abs(maxWidthDelta) + 1);\n\n let maxHeightDelta = getRandomDirection();\n if (maxHeightDelta === 1 && maxHeightIncrement) {\n maxHeightDelta *= maxHeightIncrement;\n } else if (maxHeightDelta === -1 && maxHeightDecrement) {\n maxHeightDelta *= maxHeightDecrement;\n } else if (maxHeightIncrement) {\n maxHeightDelta = maxHeightIncrement;\n } else {\n maxHeightDelta = -maxHeightDecrement;\n }\n if (resizeTarget.height + maxHeightDelta < 1) {\n maxHeightDelta = -(resizeTarget.height - 1);\n }\n const heightDelta = Math.sign(maxHeightDelta) * getRandomInt(0, Math.abs(maxHeightDelta) + 1);\n\n const path = generateRandomPath(\n new Position({ x: resizeTarget.x + resizeTarget.width, y: resizeTarget.y + resizeTarget.height }),\n new Position({\n x: resizeTarget.x + resizeTarget.width + widthDelta,\n y: resizeTarget.y + resizeTarget.height + heightDelta,\n }),\n );\n\n return { itemId: resizeTarget.id, path };\n}\n\nexport function generateInsert(grid: GridLayout, insertId = \"X\", options?: GenerateGridInsertOptions): InsertCommand {\n const maxWidth = options?.maxWidth ?? grid.columns;\n const maxHeight = options?.maxHeight ?? Math.floor(grid.items.length / 2) + 1;\n\n const textGrid = toMatrix(grid);\n\n const y = getRandomIndex(textGrid);\n const x = getRandomIndex(textGrid[y]);\n const width = getRandomInt(1, Math.max(1, maxWidth + 1 - x));\n const height = getRandomInt(1, maxHeight + 1);\n\n return { itemId: insertId, width, height, path: [new Position({ x, y })] };\n}\n\nexport function generateRandomPath(from: Position, to: Position): Position[] {\n const path = [];\n const directions: [\"y\", \"x\"] = [\"y\", \"x\"];\n\n const last = { ...from };\n while (last.y !== to.y || last.x !== to.x) {\n let direction = directions[getRandomIndex(directions)];\n if (last.y === to.y) {\n direction = \"x\";\n }\n if (last.x === to.x) {\n direction = \"y\";\n }\n last[direction] += to[direction] > from[direction] ? 1 : -1;\n path.push({ ...last });\n }\n\n return path;\n}\n\nfunction getRandomIndex(array: readonly unknown[]): number {\n return Math.floor(Math.random() * array.length);\n}\n\nfunction getRandomOffset(gridWidth: number, itemWidth: number): number {\n return Math.floor(Math.random() * (1 + gridWidth - itemWidth));\n}\n\nfunction getRandomDirection(): number {\n return Math.random() > 0.5 ? 1 : -1;\n}\n\nfunction getRandomInt(from: number, until: number): number {\n return Math.floor(Math.random() * (until - from)) + from;\n}\n\nfunction getGridItemId(index: number): string {\n const letter = LETTER_INDICES[index % LETTER_INDICES.length];\n const letterIndex = Math.floor(index / LETTER_INDICES.length);\n return letter + (letterIndex === 0 ? \"\" : letterIndex);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parsers.js","sourceRoot":"","sources":["../../../../src/internal/debug-tools/parsers.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAItC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAG7C,MAAM,cAAc,GAAG,4BAA4B,CAAC;AAEpD,MAAM,UAAU,UAAU,CAAC,MAAkB;;IAC3C,MAAM,KAAK,GAAqB,EAAE,CAAC;IACnC,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAEhC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACzC,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;YAE3D,KAAK,MAA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AAC,GAAG,UAAU,CAAC,CAAC,CAAC;IACvC,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;IACvC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC;AACnH,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { GridLayout } from \"../interfaces\";\nimport { GridLayoutItem, ItemId } from \"../interfaces\";\nimport { Position } from \"../utils/position\";\nimport { GridMatrix } from \"./interfaces\";\n\nconst LETTER_INDICES = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\n\nexport function fromMatrix(matrix: GridMatrix): GridLayout {\n const items: GridLayoutItem[] = [];\n const added = new Set<ItemId>();\n\n for (let y = 0; y < matrix.length; y++) {\n for (let x = 0; x < matrix[y].length; x++) {\n const ids = matrix[y][x].split(\"/\").map((id) => id.trim());\n\n for (const id of ids) {\n if (id.trim().length === 0) {\n continue;\n }\n\n if (!added.has(id)) {\n const item = { id, y, x, width: 1, height: 1 };\n\n for (let itemX = x + 1; itemX < matrix[y].length; itemX++) {\n if (matrix[y][itemX] === id) {\n x++;\n item.width++;\n } else {\n break;\n }\n }\n\n for (let itemY = y + 1; itemY < matrix.length; itemY++) {\n if (matrix[itemY][x] === id) {\n item.height++;\n } else {\n break;\n }\n }\n\n items.push(item);\n added.add(id);\n }\n }\n }\n }\n\n return { items, columns: matrix[0]?.length ?? 0, rows: matrix.length };\n}\n\n// Path is defined like \"A1 A2 B2 C2\" where A-C is a column index (A-based) and 1-2 is a row index (1-based).\nexport function fromTextPath(textPath: string, gridArg: GridLayout | GridMatrix) {\n // Parse path.\n const positions = textPath.split(\" \").filter(Boolean);\n const [start, ...rest] = positions.map((pos) => {\n const x = LETTER_INDICES.indexOf(pos[0]);\n const y = parseInt(pos.slice(1)) - 1;\n return { y, x };\n });\n\n // Find move target.\n const grid = Array.isArray(gridArg) ? fromMatrix(gridArg) : gridArg;\n const targets = grid.items.filter(\n (item) => item.y <= start.y && start.y < item.y + item.height && item.x <= start.x && start.x < item.x + item.width
|
|
1
|
+
{"version":3,"file":"parsers.js","sourceRoot":"","sources":["../../../../src/internal/debug-tools/parsers.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAItC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAG7C,MAAM,cAAc,GAAG,4BAA4B,CAAC;AAEpD,MAAM,UAAU,UAAU,CAAC,MAAkB;;IAC3C,MAAM,KAAK,GAAqB,EAAE,CAAC;IACnC,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAEhC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACzC,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;YAE3D,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE;gBACpB,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE;oBAC1B,SAAS;iBACV;gBAED,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;oBAClB,MAAM,IA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,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC;AACnH,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { GridLayout } from \"../interfaces\";\nimport { GridLayoutItem, ItemId } from \"../interfaces\";\nimport { Position } from \"../utils/position\";\nimport { GridMatrix } from \"./interfaces\";\n\nconst LETTER_INDICES = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\n\nexport function fromMatrix(matrix: GridMatrix): GridLayout {\n const items: GridLayoutItem[] = [];\n const added = new Set<ItemId>();\n\n for (let y = 0; y < matrix.length; y++) {\n for (let x = 0; x < matrix[y].length; x++) {\n const ids = matrix[y][x].split(\"/\").map((id) => id.trim());\n\n for (const id of ids) {\n if (id.trim().length === 0) {\n continue;\n }\n\n if (!added.has(id)) {\n const item = { id, y, x, width: 1, height: 1 };\n\n for (let itemX = x + 1; itemX < matrix[y].length; itemX++) {\n if (matrix[y][itemX] === id) {\n x++;\n item.width++;\n } else {\n break;\n }\n }\n\n for (let itemY = y + 1; itemY < matrix.length; itemY++) {\n if (matrix[itemY][x] === id) {\n item.height++;\n } else {\n break;\n }\n }\n\n items.push(item);\n added.add(id);\n }\n }\n }\n }\n\n return { items, columns: matrix[0]?.length ?? 0, rows: matrix.length };\n}\n\n// Path is defined like \"A1 A2 B2 C2\" where A-C is a column index (A-based) and 1-2 is a row index (1-based).\nexport function fromTextPath(textPath: string, gridArg: GridLayout | GridMatrix) {\n // Parse path.\n const positions = textPath.split(\" \").filter(Boolean);\n const [start, ...rest] = positions.map((pos) => {\n const x = LETTER_INDICES.indexOf(pos[0]);\n const y = parseInt(pos.slice(1)) - 1;\n return { y, x };\n });\n\n // Find move target.\n const grid = Array.isArray(gridArg) ? fromMatrix(gridArg) : gridArg;\n const targets = grid.items.filter(\n (item) => item.y <= start.y && start.y < item.y + item.height && item.x <= start.x && start.x < item.x + item.width,\n );\n if (targets.length === 0) {\n throw new Error(\"No move target corresponding given path.\");\n }\n if (targets.length > 1) {\n throw new Error(\"Multiple move targets corresponding given path.\");\n }\n const [moveTarget] = targets;\n\n // Adjust path to target's top-left point.\n const yOffset = start.y - moveTarget.y;\n const xOffset = start.x - moveTarget.x;\n return { itemId: moveTarget.id, path: rest.map(({ y, x }) => new Position({ y: y - yOffset, x: x - xOffset })) };\n}\n"]}
|
|
@@ -1 +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)
|
|
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"]}
|
|
@@ -1 +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
|
|
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
|
@@ -1 +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 }
|
|
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"]}
|
|
@@ -1 +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
|
|
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"]}
|
|
@@ -1 +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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,SAAS,EAAE,qBAAqB;wBAChC,QAAQ,EAAE,QAAQ,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,SAAS,MAAK,QAAQ;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"]}
|
|
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,M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tC,SAAS,EAAE,mBAAmB;oBAC9B,QAAQ,EAAE,QAAQ,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,SAAS,MAAK,SAAS;iBAC1D;gBACD,YAAY,EAAE,MAAM;oBAClB,CAAC,CAAC;wBACE,aAAa,EAAE,yBAAyB;wBACxC,SAAS,EAAE,qBAAqB;wBAChC,QAAQ,EAAE,QAAQ,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,SAAS,MAAK,QAAQ;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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine-solution.js","sourceRoot":"","sources":["../../../../src/internal/layout-engine/engine-solution.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAGtC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,gBAAgB,EAA4B,MAAM,QAAQ,CAAC;AAEpE,OAAO,EAAE,uBAAuB,EAAE,UAAU,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEhG,kEAAkE;AAClE,MAAM,mBAAmB,GAAyB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EA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AM;QACT,MAAM,EAAE,CAAC,GAAG,IAAI,GAAG,MAAM;KAC1B,CAAC,CACH,CAAC;IACF,YAAY,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAEvC,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,iEAAiE;AACjE,SAAS,WAAW,CAAC,WAA0B,EAAE,cAA6B;IAC5E,IAAI,cAAc,CAAC,IAAI,KAAK,MAAM,EAAE;QAClC,OAAO,KAAK,CAAC;KACd;IACD,IAAI,CAAC,uBAAuB,CAAC,WAAW,CAAC,SAAS,EAAE,cAAc,CAAC,SAAS,CAAC,EAAE;QAC7E,OAAO,KAAK,CAAC;KACd;IACD,MAAM,WAAW,GAAG,mBAAmB,CAAC,WAAW,CAAC,CAAC;IACrD,MAAM,UAAU,GAAG,WAAW,CAAC,cAAc,CAAC,CAAC;IAC/C,QAAQ,cAAc,CAAC,SAAS,EAAE;QAChC,KAAK,IAAI;YACP,OAAO,WAAW,CAAC,GAAG,KAAK,UAAU,CAAC,GAAG,CAAC;QAC5C,KAAK,OAAO;YACV,OAAO,WAAW,CAAC,KAAK,KAAK,UAAU,CAAC,KAAK,CAAC;QAChD,KAAK,MAAM;YACT,OAAO,WAAW,CAAC,MAAM,KAAK,UAAU,CAAC,MAAM,CAAC;QAClD,KAAK,MAAM;YACT,OAAO,WAAW,CAAC,IAAI,KAAK,UAAU,CAAC,IAAI,CAAC;KAC/C;AACH,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\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"]}
|
|
1
|
+
{"version":3,"file":"engine-solution.js","sourceRoot":"","sources":["../../../../src/internal/layout-engine/engine-solution.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAGtC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,gBAAgB,EAA4B,MAAM,QAAQ,CAAC;AAEpE,OAAO,EAAE,uBAAuB,EAAE,UAAU,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEhG,kEAAkE;AAClE,MAAM,mBAAmB,GAAyB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AAMlF,gGAAgG;AAChG,oGAAoG;AACpG,2DAA2D;AAC3D,MAAM,OAAO,iBAAiB;IAQ5B,YAAY,IAA8B,EAAE,KAA+B,EAAE,SAA2B;QALjG,cAAS,GAAG,CAAC,CAAC;QAEd,aAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;QACrC,UAAK,GAAG,CAAC,CAAC;QAGf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;QACxB,IAAI,CAAC,SAAS,GAAG,KAA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D,MAAM,WAAW,GAAG,mBAAmB,CAAC,WAAW,CAAC,CAAC;IACrD,MAAM,UAAU,GAAG,WAAW,CAAC,cAAc,CAAC,CAAC;IAC/C,QAAQ,cAAc,CAAC,SAAS,EAAE;QAChC,KAAK,IAAI;YACP,OAAO,WAAW,CAAC,GAAG,KAAK,UAAU,CAAC,GAAG,CAAC;QAC5C,KAAK,OAAO;YACV,OAAO,WAAW,CAAC,KAAK,KAAK,UAAU,CAAC,KAAK,CAAC;QAChD,KAAK,MAAM;YACT,OAAO,WAAW,CAAC,MAAM,KAAK,UAAU,CAAC,MAAM,CAAC;QAClD,KAAK,MAAM;YACT,OAAO,WAAW,CAAC,IAAI,KAAK,UAAU,CAAC,IAAI,CAAC;KAC/C;AACH,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\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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AAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClC,KAAK,QAAQ;YACX,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;KAC5D;AACH,CAAC;AAED,SAAS,cAAc,CAAC,KAAwB,EAAE,IAAmB;;IACnE,0FAA0F;IAC1F,4DAA4D;IAC5D,KAAK,MAAM,UAAU,IAAI,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE;QAC7E,IAAI,CAAC,CAAA,MAAA,KAAK,CAAC,SAAS,0CAAE,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA,EAAE;YAC9C,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;SAChD;KACF;IACD,+DAA+D;IAC/D,KAAK,MAAM,CAAC,SAAS,EAAE,eAAe,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE;QACzD,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,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"]}
|
|
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,GAAG,IAAI,iBAAiB,CAAC,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAC3F,MAAM,eAAe,GAAiB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;IAE/D,uHAAuH;IACvH,mHAAmH;IACnH,yEAAyE;IACzE,sGAAsG;IACtG,MAAM,c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D,KAAK,QAAQ;YACX,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;QACnD,KAAK,QAAQ;YACX,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClC,KAAK,QAAQ;YACX,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;KAC5D;AACH,CAAC;AAED,SAAS,cAAc,CAAC,KAAwB,EAAE,IAAmB;;IACnE,0FAA0F;IAC1F,4DAA4D;IAC5D,KAAK,MAAM,UAAU,IAAI,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE;QAC7E,IAAI,CAAC,CAAA,MAAA,KAAK,CAAC,SAAS,0CAAE,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA,EAAE;YAC9C,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;SAChD;KACF;IACD,+DAA+D;IAC/D,KAAK,MAAM,CAAC,SAAS,EAAE,eAAe,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE;QACzD,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,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"]}
|
|
@@ -1 +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,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAgB,EAAE,IAAyB;IAC3E,IAAI,GAAG,mBAAmB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAEzC,2CAA2C;IAC3C,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAkB,CAAC;IACtD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QAChD,mBAAmB,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,C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,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"]}
|
|
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,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAgB,EAAE,IAAyB;IAC3E,IAAI,GAAG,mBAAmB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAEzC,2CAA2C;IAC3C,MAAM,mBA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AErB,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"]}
|
package/internal/manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layout.js","sourceRoot":"","sources":["../../../../src/internal/utils/layout.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAK1D;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,KAAsB,EAAE,OAAe;IACpE,MAAM,WAAW,GAAqB,EAAE,CAAC;IACzC,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAA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CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { MIN_COL_SPAN, MIN_ROW_SPAN } from \"../constants\";\nimport { BoardItemDefinition, GridLayout, GridLayoutItem, ItemId } from \"../interfaces\";\n\ntype Item<D = unknown> = BoardItemDefinition<D>;\n\n/**\n * The function produces grid layout from board items and given number of columns.\n * The positional data is taken from the items when available or the default placement is used otherwise.\n */\nexport function interpretItems(items: readonly Item[], columns: number): GridLayout {\n const layoutItems: GridLayoutItem[] = [];\n const columnHeights = Array(columns).fill(0);\n\n function getColumnSpan(item: Item): number {\n const minColumnSpan = getMinColumnSpan(item, columns);\n const columnSpan = item.columnSpan ?? getDefaultColumnSpan(item, columns);\n return Math.min(columns, Math.max(minColumnSpan, columnSpan));\n }\n\n function getRowSpan(item: Item): number {\n const minRowSpan = getMinRowSpan(item);\n const rowSpan = item.rowSpan ?? getDefaultRowSpan(item);\n return Math.max(minRowSpan, rowSpan);\n }\n\n function getColumnOffset(item: Item, currentOffset: number): number {\n const columnSpan = getColumnSpan(item);\n const rowSpan = getRowSpan(item);\n const columnOffset = item.columnOffset?.[columns] ?? findOptimalColumnOffset(currentOffset, columnSpan, rowSpan);\n return columnOffset + columnSpan <= columns ? columnOffset : 0;\n }\n\n function findOptimalColumnOffset(currentColumnOffset: number, columnSpan: number, rowSpan: number): number {\n for (let colOffset = currentColumnOffset; colOffset + columnSpan <= columns; colOffset++) {\n if (getRowOffset(colOffset, columnSpan) + rowSpan <= getRowOffset(0, columns)) {\n return colOffset;\n }\n }\n for (let colOffset = 0; colOffset + columnSpan <= columns; colOffset++) {\n if (getRowOffset(colOffset, columnSpan) + rowSpan <= getRowOffset(0, columns)) {\n return colOffset;\n }\n }\n return currentColumnOffset;\n }\n\n function getRowOffset(columnOffset: number, columnSpan: number) {\n let rowOffset = 0;\n for (let col = columnOffset; col < columnOffset + columnSpan; col++) {\n rowOffset = Math.max(rowOffset, columnHeights[col]);\n }\n return rowOffset;\n }\n\n for (let index = 0, columnOffset = 0, rowOffset = 0; index < items.length; index++, rowOffset = 0) {\n const columnSpan = getColumnSpan(items[index]);\n const rowSpan = getRowSpan(items[index]);\n columnOffset = getColumnOffset(items[index], columnOffset);\n rowOffset = getRowOffset(columnOffset, columnSpan);\n\n layoutItems.push({ id: items[index].id, width: columnSpan, height: rowSpan, x: columnOffset, y: rowOffset });\n\n for (let col = columnOffset; col < columnOffset + columnSpan; col++) {\n columnHeights[col] = rowOffset + rowSpan;\n }\n\n columnOffset += columnSpan;\n }\n\n layoutItems.sort(itemComparator);\n\n return { items: layoutItems, columns, rows: getRowOffset(0, columns) };\n}\n\n/**\n * The function produces new items from the current state and updated grid layout.\n * The positional data for the given number of columns is preserved as is while the other layouts are partially invalidated.\n */\nexport function transformItems<D>(\n sourceItems: readonly BoardItemDefinition<D>[],\n gridLayout: GridLayout,\n resizeTarget: null | ItemId\n): readonly BoardItemDefinition<D>[] {\n const itemById = new Map(sourceItems.map((item) => [item.id, item]));\n const getItem = (itemId: ItemId) => {\n const item = itemById.get(itemId);\n if (!item) {\n throw new Error(\"Invariant violation: no matching source item found.\");\n }\n return item;\n };\n\n const sortedLayout = gridLayout.items.slice().sort(itemComparator);\n\n const items: BoardItemDefinition<D>[] = [];\n\n let changeFromIndex = sortedLayout.findIndex(({ id }, index) => id !== sourceItems[index].id || id === resizeTarget);\n changeFromIndex = changeFromIndex !== -1 ? changeFromIndex : sortedLayout.length;\n\n for (let index = 0; index < sortedLayout.length; index++) {\n const { id, x, width, height } = sortedLayout[index];\n\n const item = { ...getItem(id) };\n\n if (index >= changeFromIndex) {\n item.columnOffset = undefined;\n }\n item.columnOffset = { ...item.columnOffset, [gridLayout.columns]: x };\n\n if (item.id === resizeTarget) {\n item.columnSpan = width;\n item.rowSpan = height;\n }\n\n items.push(item);\n }\n\n return items;\n}\n\nexport function createPlaceholdersLayout(rows: number, columns: number): GridLayout {\n const layoutItems: GridLayoutItem[] = [];\n\n for (let row = 0; row < rows; row++) {\n for (let col = 0; col < columns; col++) {\n layoutItems.push({ id: `awsui-placeholder-${row}-${col}`, x: col, y: row, width: 1, height: 1 });\n }\n }\n\n return { items: layoutItems, columns, rows };\n}\n\nexport function getMinColumnSpan(item: Item, columns: number) {\n return Math.min(columns, Math.max(MIN_COL_SPAN, item.definition?.minColumnSpan ?? 0));\n}\n\nexport function getDefaultColumnSpan(item: Item, columns: number) {\n return Math.min(columns, Math.max(getMinColumnSpan(item, columns), item.definition?.defaultColumnSpan ?? 0));\n}\n\nexport function getMinRowSpan(item: Item) {\n return Math.max(MIN_ROW_SPAN, item.definition?.minRowSpan ?? 0);\n}\n\nexport function getDefaultRowSpan(item: Item) {\n return Math.max(getMinRowSpan(item), item.definition?.defaultRowSpan ?? 0);\n}\n\nfunction itemComparator(a: GridLayoutItem, b: GridLayoutItem) {\n if (a.y !== b.y) {\n return a.y > b.y ? 1 : -1;\n }\n return a.x > b.x ? 1 : -1;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"layout.js","sourceRoot":"","sources":["../../../../src/internal/utils/layout.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAK1D;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,KAAsB,EAAE,OAAe;IACpE,MAAM,WAAW,GAAqB,EAAE,CAAC;IACzC,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAE7C,SAAS,aAAa,CAAC,IAAU;;QAC/B,MAAM,aAAa,GAAG,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACtD,MAAM,UAAU,GAAG,MAAA,IAAI,CAAC,UAAU,mCAAI,oBAAoB,CAAC,IAAI,EAAE,OA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AN } from \"../constants\";\nimport { BoardItemDefinition, GridLayout, GridLayoutItem, ItemId } from \"../interfaces\";\n\ntype Item<D = unknown> = BoardItemDefinition<D>;\n\n/**\n * The function produces grid layout from board items and given number of columns.\n * The positional data is taken from the items when available or the default placement is used otherwise.\n */\nexport function interpretItems(items: readonly Item[], columns: number): GridLayout {\n const layoutItems: GridLayoutItem[] = [];\n const columnHeights = Array(columns).fill(0);\n\n function getColumnSpan(item: Item): number {\n const minColumnSpan = getMinColumnSpan(item, columns);\n const columnSpan = item.columnSpan ?? getDefaultColumnSpan(item, columns);\n return Math.min(columns, Math.max(minColumnSpan, columnSpan));\n }\n\n function getRowSpan(item: Item): number {\n const minRowSpan = getMinRowSpan(item);\n const rowSpan = item.rowSpan ?? getDefaultRowSpan(item);\n return Math.max(minRowSpan, rowSpan);\n }\n\n function getColumnOffset(item: Item, currentOffset: number): number {\n const columnSpan = getColumnSpan(item);\n const rowSpan = getRowSpan(item);\n const columnOffset = item.columnOffset?.[columns] ?? findOptimalColumnOffset(currentOffset, columnSpan, rowSpan);\n return columnOffset + columnSpan <= columns ? columnOffset : 0;\n }\n\n function findOptimalColumnOffset(currentColumnOffset: number, columnSpan: number, rowSpan: number): number {\n for (let colOffset = currentColumnOffset; colOffset + columnSpan <= columns; colOffset++) {\n if (getRowOffset(colOffset, columnSpan) + rowSpan <= getRowOffset(0, columns)) {\n return colOffset;\n }\n }\n for (let colOffset = 0; colOffset + columnSpan <= columns; colOffset++) {\n if (getRowOffset(colOffset, columnSpan) + rowSpan <= getRowOffset(0, columns)) {\n return colOffset;\n }\n }\n return currentColumnOffset;\n }\n\n function getRowOffset(columnOffset: number, columnSpan: number) {\n let rowOffset = 0;\n for (let col = columnOffset; col < columnOffset + columnSpan; col++) {\n rowOffset = Math.max(rowOffset, columnHeights[col]);\n }\n return rowOffset;\n }\n\n for (let index = 0, columnOffset = 0, rowOffset = 0; index < items.length; index++, rowOffset = 0) {\n const columnSpan = getColumnSpan(items[index]);\n const rowSpan = getRowSpan(items[index]);\n columnOffset = getColumnOffset(items[index], columnOffset);\n rowOffset = getRowOffset(columnOffset, columnSpan);\n\n layoutItems.push({ id: items[index].id, width: columnSpan, height: rowSpan, x: columnOffset, y: rowOffset });\n\n for (let col = columnOffset; col < columnOffset + columnSpan; col++) {\n columnHeights[col] = rowOffset + rowSpan;\n }\n\n columnOffset += columnSpan;\n }\n\n layoutItems.sort(itemComparator);\n\n return { items: layoutItems, columns, rows: getRowOffset(0, columns) };\n}\n\n/**\n * The function produces new items from the current state and updated grid layout.\n * The positional data for the given number of columns is preserved as is while the other layouts are partially invalidated.\n */\nexport function transformItems<D>(\n sourceItems: readonly BoardItemDefinition<D>[],\n gridLayout: GridLayout,\n resizeTarget: null | ItemId,\n): readonly BoardItemDefinition<D>[] {\n const itemById = new Map(sourceItems.map((item) => [item.id, item]));\n const getItem = (itemId: ItemId) => {\n const item = itemById.get(itemId);\n if (!item) {\n throw new Error(\"Invariant violation: no matching source item found.\");\n }\n return item;\n };\n\n const sortedLayout = gridLayout.items.slice().sort(itemComparator);\n\n const items: BoardItemDefinition<D>[] = [];\n\n let changeFromIndex = sortedLayout.findIndex(({ id }, index) => id !== sourceItems[index].id || id === resizeTarget);\n changeFromIndex = changeFromIndex !== -1 ? changeFromIndex : sortedLayout.length;\n\n for (let index = 0; index < sortedLayout.length; index++) {\n const { id, x, width, height } = sortedLayout[index];\n\n const item = { ...getItem(id) };\n\n if (index >= changeFromIndex) {\n item.columnOffset = undefined;\n }\n item.columnOffset = { ...item.columnOffset, [gridLayout.columns]: x };\n\n if (item.id === resizeTarget) {\n item.columnSpan = width;\n item.rowSpan = height;\n }\n\n items.push(item);\n }\n\n return items;\n}\n\nexport function createPlaceholdersLayout(rows: number, columns: number): GridLayout {\n const layoutItems: GridLayoutItem[] = [];\n\n for (let row = 0; row < rows; row++) {\n for (let col = 0; col < columns; col++) {\n layoutItems.push({ id: `awsui-placeholder-${row}-${col}`, x: col, y: row, width: 1, height: 1 });\n }\n }\n\n return { items: layoutItems, columns, rows };\n}\n\nexport function getMinColumnSpan(item: Item, columns: number) {\n return Math.min(columns, Math.max(MIN_COL_SPAN, item.definition?.minColumnSpan ?? 0));\n}\n\nexport function getDefaultColumnSpan(item: Item, columns: number) {\n return Math.min(columns, Math.max(getMinColumnSpan(item, columns), item.definition?.defaultColumnSpan ?? 0));\n}\n\nexport function getMinRowSpan(item: Item) {\n return Math.max(MIN_ROW_SPAN, item.definition?.minRowSpan ?? 0);\n}\n\nexport function getDefaultRowSpan(item: Item) {\n return Math.max(getMinRowSpan(item), item.definition?.defaultRowSpan ?? 0);\n}\n\nfunction itemComparator(a: GridLayoutItem, b: GridLayoutItem) {\n if (a.y !== b.y) {\n return a.y > b.y ? 1 : -1;\n }\n return a.x > b.x ? 1 : -1;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rects.js","sourceRoot":"","sources":["../../../../src/internal/utils/rects.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAItC,MAAM,UAAU,QAAQ,CAAC,IAAU,EAAE,MAAY;IAC/C,OAAO,CACL,IAAI,CAAC,GAAG,IAAI,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CACjH,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAW,EAAE,KAAW;IACrD,OAAO,mBAAmB,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,KAAW,EAAE,KAAW;IAC1D,IAAI,4BAA4B,GAAG,CAAC,CAAC;IACrC,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,KAAK,E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","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Direction, Rect } from \"../interfaces\";\n\nexport function isInside(rect: Rect, bounds: Rect) {\n return (\n rect.top >= bounds.top && rect.left >= bounds.left && rect.right <= bounds.right && rect.bottom <= bounds.bottom\n );\n}\n\nexport function isIntersecting(rect1: Rect, rect2: Rect) {\n return getIntersectionArea(rect1, rect2) > 0;\n}\n\nexport function getIntersectionArea(rect1: Rect, rect2: Rect) {\n let horizontalIntersectionLength = 0;\n if (rect2.left <= rect1.left && rect1.left <= rect2.right) {\n horizontalIntersectionLength = Math.min(rect1.right, rect2.right) - rect1.left;\n } else if (rect2.left <= rect1.right && rect1.right <= rect2.right) {\n horizontalIntersectionLength = rect1.right - Math.max(rect1.left, rect2.left);\n } else if (rect1.left <= rect2.left && rect2.left <= rect1.right) {\n horizontalIntersectionLength = Math.min(rect1.right, rect2.right) - rect2.left;\n } else if (rect1.left <= rect2.right && rect2.right <= rect1.right) {\n horizontalIntersectionLength = rect2.right - Math.max(rect1.left, rect2.left);\n }\n\n let verticalIntersectionLength = 0;\n if (rect2.top <= rect1.top && rect1.top <= rect2.bottom) {\n verticalIntersectionLength = Math.min(rect1.bottom, rect2.bottom) - rect1.top;\n } else if (rect2.top <= rect1.bottom && rect1.bottom <= rect2.bottom) {\n verticalIntersectionLength = rect1.bottom - Math.max(rect1.top, rect2.top);\n } else if (rect1.top <= rect2.top && rect2.top <= rect1.bottom) {\n verticalIntersectionLength = Math.min(rect1.bottom, rect2.bottom) - rect2.top;\n } else if (rect1.top <= rect2.bottom && rect2.bottom <= rect1.bottom) {\n verticalIntersectionLength = rect2.bottom - Math.max(rect1.top, rect2.top);\n }\n\n return horizontalIntersectionLength * verticalIntersectionLength;\n}\n\nexport function getGridPlacement(target: Rect, grid: readonly Rect[]): Rect {\n function getMinDistance(min: number, current: number, collision: number) {\n const minDistance = Math.abs(min - collision);\n const currentDistance = Math.abs(current - collision);\n return currentDistance < minDistance ? current : min;\n }\n\n let placement = {\n top: Number.POSITIVE_INFINITY,\n left: Number.POSITIVE_INFINITY,\n right: Number.POSITIVE_INFINITY,\n bottom: Number.POSITIVE_INFINITY,\n };\n\n for (const rect of grid) {\n if (isIntersecting(rect, target)) {\n placement = {\n top: getMinDistance(placement.top, rect.top, target.top),\n left: getMinDistance(placement.left, rect.left, target.left),\n right: getMinDistance(placement.right, rect.right, target.right),\n bottom: getMinDistance(placement.bottom, rect.bottom, target.bottom),\n };\n }\n }\n\n return placement;\n}\n\nexport function getClosestNeighbor(target: Rect, sources: readonly Rect[], direction: Direction): null | Rect {\n const getFirst = (rects: Rect[]) => rects[0] ?? null;\n const verticalDiff = (r1: Rect, r2: Rect) => Math.abs(r1.top - target.top) - Math.abs(r2.top - target.top);\n const horizontalDiff = (r1: Rect, r2: Rect) => Math.abs(r1.left - target.left) - Math.abs(r2.left - target.left);\n\n switch (direction) {\n case \"left\":\n return getFirst(\n sources.filter((rect) => rect.right <= target.left).sort((r1, r2) => r2.left - r1.left || verticalDiff(r1, r2))
|
|
1
|
+
{"version":3,"file":"rects.js","sourceRoot":"","sources":["../../../../src/internal/utils/rects.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAItC,MAAM,UAAU,QAAQ,CAAC,IAAU,EAAE,MAAY;IAC/C,OAAO,CACL,IAAI,CAAC,GAAG,IAAI,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CACjH,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAW,EAAE,KAAW;IACrD,OAAO,mBAAmB,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,KAAW,EAAE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AE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,IAAI,cAAc,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAChH,CAAC;KACL;AACH,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Direction, Rect } from \"../interfaces\";\n\nexport function isInside(rect: Rect, bounds: Rect) {\n return (\n rect.top >= bounds.top && rect.left >= bounds.left && rect.right <= bounds.right && rect.bottom <= bounds.bottom\n );\n}\n\nexport function isIntersecting(rect1: Rect, rect2: Rect) {\n return getIntersectionArea(rect1, rect2) > 0;\n}\n\nexport function getIntersectionArea(rect1: Rect, rect2: Rect) {\n let horizontalIntersectionLength = 0;\n if (rect2.left <= rect1.left && rect1.left <= rect2.right) {\n horizontalIntersectionLength = Math.min(rect1.right, rect2.right) - rect1.left;\n } else if (rect2.left <= rect1.right && rect1.right <= rect2.right) {\n horizontalIntersectionLength = rect1.right - Math.max(rect1.left, rect2.left);\n } else if (rect1.left <= rect2.left && rect2.left <= rect1.right) {\n horizontalIntersectionLength = Math.min(rect1.right, rect2.right) - rect2.left;\n } else if (rect1.left <= rect2.right && rect2.right <= rect1.right) {\n horizontalIntersectionLength = rect2.right - Math.max(rect1.left, rect2.left);\n }\n\n let verticalIntersectionLength = 0;\n if (rect2.top <= rect1.top && rect1.top <= rect2.bottom) {\n verticalIntersectionLength = Math.min(rect1.bottom, rect2.bottom) - rect1.top;\n } else if (rect2.top <= rect1.bottom && rect1.bottom <= rect2.bottom) {\n verticalIntersectionLength = rect1.bottom - Math.max(rect1.top, rect2.top);\n } else if (rect1.top <= rect2.top && rect2.top <= rect1.bottom) {\n verticalIntersectionLength = Math.min(rect1.bottom, rect2.bottom) - rect2.top;\n } else if (rect1.top <= rect2.bottom && rect2.bottom <= rect1.bottom) {\n verticalIntersectionLength = rect2.bottom - Math.max(rect1.top, rect2.top);\n }\n\n return horizontalIntersectionLength * verticalIntersectionLength;\n}\n\nexport function getGridPlacement(target: Rect, grid: readonly Rect[]): Rect {\n function getMinDistance(min: number, current: number, collision: number) {\n const minDistance = Math.abs(min - collision);\n const currentDistance = Math.abs(current - collision);\n return currentDistance < minDistance ? current : min;\n }\n\n let placement = {\n top: Number.POSITIVE_INFINITY,\n left: Number.POSITIVE_INFINITY,\n right: Number.POSITIVE_INFINITY,\n bottom: Number.POSITIVE_INFINITY,\n };\n\n for (const rect of grid) {\n if (isIntersecting(rect, target)) {\n placement = {\n top: getMinDistance(placement.top, rect.top, target.top),\n left: getMinDistance(placement.left, rect.left, target.left),\n right: getMinDistance(placement.right, rect.right, target.right),\n bottom: getMinDistance(placement.bottom, rect.bottom, target.bottom),\n };\n }\n }\n\n return placement;\n}\n\nexport function getClosestNeighbor(target: Rect, sources: readonly Rect[], direction: Direction): null | Rect {\n const getFirst = (rects: Rect[]) => rects[0] ?? null;\n const verticalDiff = (r1: Rect, r2: Rect) => Math.abs(r1.top - target.top) - Math.abs(r2.top - target.top);\n const horizontalDiff = (r1: Rect, r2: Rect) => Math.abs(r1.left - target.left) - Math.abs(r2.left - target.left);\n\n switch (direction) {\n case \"left\":\n return getFirst(\n sources.filter((rect) => rect.right <= target.left).sort((r1, r2) => r2.left - r1.left || verticalDiff(r1, r2)),\n );\n case \"right\":\n return getFirst(\n sources.filter((rect) => rect.left >= target.right).sort((r1, r2) => r1.left - r2.left || verticalDiff(r1, r2)),\n );\n case \"up\":\n return getFirst(\n sources.filter((rect) => rect.bottom <= target.top).sort((r1, r2) => r2.top - r1.top || horizontalDiff(r1, r2)),\n );\n case \"down\":\n return getFirst(\n sources.filter((rect) => rect.top >= target.bottom).sort((r1, r2) => r1.top - r2.top || horizontalDiff(r1, r2)),\n );\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-auto-scroll.js","sourceRoot":"","sources":["../../../../src/internal/utils/use-auto-scroll.ts"],"names":[],"m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QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;aACnF;QACH,CAAC,EAAE,KAAK,CAAC,CAAC;IACZ,CAAC,EACD,CAAC,kBAAkB,CAAC,CACrB,CAAC;IAEF,OAAO,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,mCAAmC,EAAE,CAAC;AACtG,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { useLastInteraction } from \"./use-last-interaction\";\n\nexport function useAutoScroll() {\n const [activeAutoScroll, setActiveAutoScroll] = useState<\"up\" | \"down\" | \"none\">(\"none\");\n const scrollIntoViewTimerRef = useRef<null | ReturnType<typeof setTimeout>>(null);\n const getLastInteraction = useLastInteraction();\n\n // Scroll window repeatedly if activeAutoScroll=\"up\" or activeAutoScroll=\"down\".\n useEffect(() => {\n if (activeAutoScroll === \"none\") {\n return;\n }\n const direction = activeAutoScroll === \"up\" ? -1 : 1;\n\n let timer: ReturnType<typeof setTimeout>;\n\n function scrollLoop() {\n timer = setTimeout(() => {\n window.scrollBy({ top: direction * 5 });\n scrollLoop();\n }, 10);\n }\n scrollLoop();\n\n return () => clearTimeout(timer);\n }, [activeAutoScroll]);\n\n const onPointerMove = useCallback((event: PointerEvent) => {\n const autoScrollMargin = 50;\n if (event.clientY > window.innerHeight - autoScrollMargin) {\n setActiveAutoScroll(\"down\");\n } else if (event.clientY < autoScrollMargin) {\n setActiveAutoScroll(\"up\");\n } else {\n setActiveAutoScroll(\"none\");\n }\n }, []);\n\n const onPointerUp = useCallback(() => {\n setActiveAutoScroll(\"none\");\n }, []);\n\n const addPointerEventHandlers = useCallback(() => {\n if (getLastInteraction() === \"pointer\") {\n window.addEventListener(\"pointermove\", onPointerMove);\n window.addEventListener(\"pointerup\", onPointerUp);\n }\n }, [getLastInteraction, onPointerMove, onPointerUp]);\n\n const removePointerEventHandlers = useCallback(() => {\n window.removeEventListener(\"pointermove\", onPointerMove);\n window.removeEventListener(\"pointerup\", onPointerUp);\n }, [onPointerMove, onPointerUp]);\n\n const scheduleActiveElementScrollIntoView = useCallback(\n (delay: number) => {\n scrollIntoViewTimerRef.current && clearTimeout(scrollIntoViewTimerRef.current);\n\n const activeElementBeforeDelay = document.activeElement;\n\n scrollIntoViewTimerRef.current = setTimeout(() => {\n if (\n document.activeElement &&\n document.activeElement === activeElementBeforeDelay &&\n getLastInteraction() === \"keyboard\"\n ) {\n document.activeElement.scrollIntoView?.({ behavior: \"smooth\", block: \"nearest\" });\n }\n }, delay);\n },\n [getLastInteraction]
|
|
1
|
+
{"version":3,"file":"use-auto-scroll.js","sourceRoot":"","sources":["../../../../src/internal/utils/use-auto-scroll.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,MAAM,UAAU,aAAa;IAC3B,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,QAAQ,CAAyB,MAAM,CAAC,CAAC;IACzF,MAAM,sBAAsB,GAAG,MAAM,CAAuC,IAAI,CAAC,CAAC;IAClF,MAAM,kBAAkB,GAAG,kBAAkB,EAAE,CAAC;IAEhD,gFAAgF;IAChF,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,gBAAgB,KAAK,MAAM,EAAE;YAC/B,OAAO;SACR;QACD,MAAM,SAAS,GAAG,gBAAgB,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAErD,IAAI,KAAoC,CAAC;QAEzC,SAAS,UAAU;YACjB,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;gBACtB,MAAM,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,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W,CAAC,CAAC;IACvD,CAAC,EAAE,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC,CAAC;IAEjC,MAAM,mCAAmC,GAAG,WAAW,CACrD,CAAC,KAAa,EAAE,EAAE;QAChB,sBAAsB,CAAC,OAAO,IAAI,YAAY,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC;QAE/E,MAAM,wBAAwB,GAAG,QAAQ,CAAC,aAAa,CAAC;QAExD,sBAAsB,CAAC,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;;YAC/C,IACE,QAAQ,CAAC,aAAa;gBACtB,QAAQ,CAAC,aAAa,KAAK,wBAAwB;gBACnD,kBAAkB,EAAE,KAAK,UAAU,EACnC;gBACA,MAAA,MAAA,QAAQ,CAAC,aAAa,EAAC,cAAc,mDAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;aACnF;QACH,CAAC,EAAE,KAAK,CAAC,CAAC;IACZ,CAAC,EACD,CAAC,kBAAkB,CAAC,CACrB,CAAC;IAEF,OAAO,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,mCAAmC,EAAE,CAAC;AACtG,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { useLastInteraction } from \"./use-last-interaction\";\n\nexport function useAutoScroll() {\n const [activeAutoScroll, setActiveAutoScroll] = useState<\"up\" | \"down\" | \"none\">(\"none\");\n const scrollIntoViewTimerRef = useRef<null | ReturnType<typeof setTimeout>>(null);\n const getLastInteraction = useLastInteraction();\n\n // Scroll window repeatedly if activeAutoScroll=\"up\" or activeAutoScroll=\"down\".\n useEffect(() => {\n if (activeAutoScroll === \"none\") {\n return;\n }\n const direction = activeAutoScroll === \"up\" ? -1 : 1;\n\n let timer: ReturnType<typeof setTimeout>;\n\n function scrollLoop() {\n timer = setTimeout(() => {\n window.scrollBy({ top: direction * 5 });\n scrollLoop();\n }, 10);\n }\n scrollLoop();\n\n return () => clearTimeout(timer);\n }, [activeAutoScroll]);\n\n const onPointerMove = useCallback((event: PointerEvent) => {\n const autoScrollMargin = 50;\n if (event.clientY > window.innerHeight - autoScrollMargin) {\n setActiveAutoScroll(\"down\");\n } else if (event.clientY < autoScrollMargin) {\n setActiveAutoScroll(\"up\");\n } else {\n setActiveAutoScroll(\"none\");\n }\n }, []);\n\n const onPointerUp = useCallback(() => {\n setActiveAutoScroll(\"none\");\n }, []);\n\n const addPointerEventHandlers = useCallback(() => {\n if (getLastInteraction() === \"pointer\") {\n window.addEventListener(\"pointermove\", onPointerMove);\n window.addEventListener(\"pointerup\", onPointerUp);\n }\n }, [getLastInteraction, onPointerMove, onPointerUp]);\n\n const removePointerEventHandlers = useCallback(() => {\n window.removeEventListener(\"pointermove\", onPointerMove);\n window.removeEventListener(\"pointerup\", onPointerUp);\n }, [onPointerMove, onPointerUp]);\n\n const scheduleActiveElementScrollIntoView = useCallback(\n (delay: number) => {\n scrollIntoViewTimerRef.current && clearTimeout(scrollIntoViewTimerRef.current);\n\n const activeElementBeforeDelay = document.activeElement;\n\n scrollIntoViewTimerRef.current = setTimeout(() => {\n if (\n document.activeElement &&\n document.activeElement === activeElementBeforeDelay &&\n getLastInteraction() === \"keyboard\"\n ) {\n document.activeElement.scrollIntoView?.({ behavior: \"smooth\", block: \"nearest\" });\n }\n }, delay);\n },\n [getLastInteraction],\n );\n\n return { addPointerEventHandlers, removePointerEventHandlers, scheduleActiveElementScrollIntoView };\n}\n"]}
|