@cloudscape-design/board-components 3.0.0
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/Config +23 -0
- package/LICENSE +201 -0
- package/NOTICE +2 -0
- package/README-cloudscape.md +20 -0
- package/README-open-source.md +0 -0
- package/README.md +20 -0
- package/board/index.d.ts +4 -0
- package/board/index.js +11 -0
- package/board/interfaces.d.ts +167 -0
- package/board/interfaces.js +1 -0
- package/board/internal.d.ts +4 -0
- package/board/internal.js +199 -0
- package/board/placeholder.d.ts +10 -0
- package/board/placeholder.js +24 -0
- package/board/styles.css.js +10 -0
- package/board/styles.scoped.css +23 -0
- package/board/styles.selectors.js +11 -0
- package/board/transition.d.ts +50 -0
- package/board/transition.js +211 -0
- package/board/utils/announcements.d.ts +10 -0
- package/board/utils/announcements.js +98 -0
- package/board/utils/create-transforms.d.ts +7 -0
- package/board/utils/create-transforms.js +22 -0
- package/board/utils/events.d.ts +3 -0
- package/board/utils/events.js +14 -0
- package/board/utils/get-hovered-rect.d.ts +10 -0
- package/board/utils/get-hovered-rect.js +19 -0
- package/board/utils/layout.d.ts +19 -0
- package/board/utils/layout.js +77 -0
- package/board/utils/path.d.ts +10 -0
- package/board/utils/path.js +73 -0
- package/board-item/header.d.ts +7 -0
- package/board-item/header.js +8 -0
- package/board-item/index.d.ts +4 -0
- package/board-item/index.js +11 -0
- package/board-item/interfaces.d.ts +42 -0
- package/board-item/interfaces.js +1 -0
- package/board-item/internal.d.ts +4 -0
- package/board-item/internal.js +20 -0
- package/board-item/styles.css.js +15 -0
- package/board-item/styles.scoped.css +41 -0
- package/board-item/styles.selectors.js +16 -0
- package/index.d.ts +6 -0
- package/index.js +5 -0
- package/internal/api-docs/components/board-item.js +68 -0
- package/internal/api-docs/components/board.js +117 -0
- package/internal/api-docs/components/index.js +5 -0
- package/internal/api-docs/components/items-palette.js +58 -0
- package/internal/api-docs/test-utils-doc/dom.js +4 -0
- package/internal/api-docs/test-utils-doc/selectors.js +4 -0
- package/internal/base-component/use-base-component.d.ts +12 -0
- package/internal/base-component/use-base-component.js +16 -0
- package/internal/base-component/use-telemetry.d.ts +1 -0
- package/internal/base-component/use-telemetry.js +9 -0
- package/internal/base-component/use-visual-refresh.d.ts +1 -0
- package/internal/base-component/use-visual-refresh.js +24 -0
- package/internal/breakpoints.d.ts +2 -0
- package/internal/breakpoints.js +18 -0
- package/internal/constants.d.ts +3 -0
- package/internal/constants.js +5 -0
- package/internal/debug-tools/converters.d.ts +4 -0
- package/internal/debug-tools/converters.js +21 -0
- package/internal/debug-tools/generators.d.ts +25 -0
- package/internal/debug-tools/generators.js +258 -0
- package/internal/debug-tools/index.d.ts +8 -0
- package/internal/debug-tools/index.js +10 -0
- package/internal/debug-tools/interfaces.d.ts +2 -0
- package/internal/debug-tools/interfaces.js +3 -0
- package/internal/debug-tools/parsers.d.ts +8 -0
- package/internal/debug-tools/parsers.js +66 -0
- package/internal/dnd-controller/__mocks__/controller.d.ts +13 -0
- package/internal/dnd-controller/__mocks__/controller.js +33 -0
- package/internal/dnd-controller/collision.d.ts +17 -0
- package/internal/dnd-controller/collision.js +32 -0
- package/internal/dnd-controller/controller.d.ts +64 -0
- package/internal/dnd-controller/controller.js +131 -0
- package/internal/dnd-controller/event-emitter.d.ts +9 -0
- package/internal/dnd-controller/event-emitter.js +22 -0
- package/internal/drag-handle/icon.d.ts +4 -0
- package/internal/drag-handle/icon.js +12 -0
- package/internal/drag-handle/index.d.ts +9 -0
- package/internal/drag-handle/index.js +11 -0
- package/internal/drag-handle/styles.css.js +6 -0
- package/internal/drag-handle/styles.scoped.css +7 -0
- package/internal/drag-handle/styles.selectors.js +7 -0
- package/internal/environment.d.ts +4 -0
- package/internal/environment.js +4 -0
- package/internal/generated/styles/tokens.d.ts +0 -0
- package/internal/generated/styles/tokens.js +0 -0
- package/internal/grid/grid.d.ts +3 -0
- package/internal/grid/grid.js +28 -0
- package/internal/grid/index.d.ts +2 -0
- package/internal/grid/index.js +3 -0
- package/internal/grid/interfaces.d.ts +14 -0
- package/internal/grid/interfaces.js +3 -0
- package/internal/grid/item.d.ts +8 -0
- package/internal/grid/item.js +10 -0
- package/internal/grid/styles.css.js +7 -0
- package/internal/grid/styles.scoped.css +221 -0
- package/internal/grid/styles.selectors.js +8 -0
- package/internal/handle/index.d.ts +3 -0
- package/internal/handle/index.js +17 -0
- package/internal/handle/styles.css.js +6 -0
- package/internal/handle/styles.scoped.css +32 -0
- package/internal/handle/styles.selectors.js +7 -0
- package/internal/interfaces.d.ts +50 -0
- package/internal/interfaces.js +3 -0
- package/internal/is-development.d.ts +6 -0
- package/internal/is-development.js +8 -0
- package/internal/item-container/get-next-droppable.d.ts +7 -0
- package/internal/item-container/get-next-droppable.js +15 -0
- package/internal/item-container/index.d.ts +48 -0
- package/internal/item-container/index.js +262 -0
- package/internal/item-container/styles.css.js +12 -0
- package/internal/item-container/styles.scoped.css +33 -0
- package/internal/item-container/styles.selectors.js +13 -0
- package/internal/layout-engine/engine-conflicts.d.ts +4 -0
- package/internal/layout-engine/engine-conflicts.js +53 -0
- package/internal/layout-engine/engine-step.d.ts +5 -0
- package/internal/layout-engine/engine-step.js +307 -0
- package/internal/layout-engine/engine.d.ts +19 -0
- package/internal/layout-engine/engine.js +105 -0
- package/internal/layout-engine/grid.d.ts +28 -0
- package/internal/layout-engine/grid.js +140 -0
- package/internal/layout-engine/interfaces.d.ts +30 -0
- package/internal/layout-engine/interfaces.js +3 -0
- package/internal/layout-engine/utils.d.ts +12 -0
- package/internal/layout-engine/utils.js +79 -0
- package/internal/live-region/index.d.ts +44 -0
- package/internal/live-region/index.js +85 -0
- package/internal/logging.d.ts +1 -0
- package/internal/logging.js +10 -0
- package/internal/manifest.json +3 -0
- package/internal/resize-handle/icon.d.ts +4 -0
- package/internal/resize-handle/icon.js +12 -0
- package/internal/resize-handle/index.d.ts +8 -0
- package/internal/resize-handle/index.js +7 -0
- package/internal/resize-handle/styles.css.js +6 -0
- package/internal/resize-handle/styles.scoped.css +3 -0
- package/internal/resize-handle/styles.selectors.js +7 -0
- package/internal/screenreader-grid-navigation/index.d.ts +22 -0
- package/internal/screenreader-grid-navigation/index.js +42 -0
- package/internal/screenreader-grid-navigation/styles.css.js +7 -0
- package/internal/screenreader-grid-navigation/styles.scoped.css +12 -0
- package/internal/screenreader-grid-navigation/styles.selectors.js +8 -0
- package/internal/screenreader-only/index.d.ts +21 -0
- package/internal/screenreader-only/index.js +23 -0
- package/internal/screenreader-only/styles.css.js +6 -0
- package/internal/screenreader-only/styles.scoped.css +9 -0
- package/internal/screenreader-only/styles.selectors.js +7 -0
- package/internal/utils/apply-display-name.d.ts +1 -0
- package/internal/utils/apply-display-name.js +5 -0
- package/internal/utils/coordinates.d.ts +14 -0
- package/internal/utils/coordinates.js +20 -0
- package/internal/utils/events.d.ts +2 -0
- package/internal/utils/events.js +18 -0
- package/internal/utils/layout.d.ts +18 -0
- package/internal/utils/layout.js +132 -0
- package/internal/utils/position.d.ts +9 -0
- package/internal/utils/position.js +9 -0
- package/internal/utils/rects.d.ts +6 -0
- package/internal/utils/rects.js +76 -0
- package/internal/utils/screen.d.ts +1 -0
- package/internal/utils/screen.js +17 -0
- package/internal/utils/stack-set.d.ts +8 -0
- package/internal/utils/stack-set.js +23 -0
- package/internal/utils/throttle.d.ts +5 -0
- package/internal/utils/throttle.js +51 -0
- package/internal/utils/use-auto-scroll.d.ts +5 -0
- package/internal/utils/use-auto-scroll.js +62 -0
- package/internal/utils/use-last-interaction.d.ts +1 -0
- package/internal/utils/use-last-interaction.js +22 -0
- package/internal/utils/use-merge-refs.d.ts +9 -0
- package/internal/utils/use-merge-refs.js +29 -0
- package/internal/utils/use-stable-event-handler.d.ts +9 -0
- package/internal/utils/use-stable-event-handler.js +19 -0
- package/internal/utils/use-throttled-event-handler.d.ts +1 -0
- package/internal/utils/use-throttled-event-handler.js +11 -0
- package/internal/utils/zip-arrays.d.ts +1 -0
- package/internal/utils/zip-arrays.js +8 -0
- package/items-palette/index.d.ts +4 -0
- package/items-palette/index.js +11 -0
- package/items-palette/interfaces.d.ts +49 -0
- package/items-palette/interfaces.js +3 -0
- package/items-palette/internal.d.ts +4 -0
- package/items-palette/internal.js +73 -0
- package/items-palette/styles.css.js +6 -0
- package/items-palette/styles.scoped.css +3 -0
- package/items-palette/styles.selectors.js +7 -0
- package/package.json +43 -0
- package/test-utils/dom/board/index.d.ts +6 -0
- package/test-utils/dom/board/index.js +15 -0
- package/test-utils/dom/board/index.js.map +1 -0
- package/test-utils/dom/board-item/index.d.ts +10 -0
- package/test-utils/dom/board-item/index.js +33 -0
- package/test-utils/dom/board-item/index.js.map +1 -0
- package/test-utils/dom/index.d.ts +19 -0
- package/test-utils/dom/index.js +41 -0
- package/test-utils/dom/index.js.map +1 -0
- package/test-utils/dom/items-palette/index.d.ts +7 -0
- package/test-utils/dom/items-palette/index.js +18 -0
- package/test-utils/dom/items-palette/index.js.map +1 -0
- package/test-utils/dom/palette-item/index.d.ts +5 -0
- package/test-utils/dom/palette-item/index.js +15 -0
- package/test-utils/dom/palette-item/index.js.map +1 -0
- package/test-utils/selectors/board/index.d.ts +6 -0
- package/test-utils/selectors/board/index.js +15 -0
- package/test-utils/selectors/board/index.js.map +1 -0
- package/test-utils/selectors/board-item/index.d.ts +10 -0
- package/test-utils/selectors/board-item/index.js +33 -0
- package/test-utils/selectors/board-item/index.js.map +1 -0
- package/test-utils/selectors/index.d.ts +19 -0
- package/test-utils/selectors/index.js +41 -0
- package/test-utils/selectors/index.js.map +1 -0
- package/test-utils/selectors/items-palette/index.d.ts +7 -0
- package/test-utils/selectors/items-palette/index.js +18 -0
- package/test-utils/selectors/items-palette/index.js.map +1 -0
- package/test-utils/selectors/palette-item/index.d.ts +5 -0
- package/test-utils/selectors/palette-item/index.js +15 -0
- package/test-utils/selectors/palette-item/index.js.map +1 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
import { CSS as CSSUtil } from "@dnd-kit/utilities";
|
|
5
|
+
import clsx from "clsx";
|
|
6
|
+
import { createContext, forwardRef, useContext, useEffect, useImperativeHandle, useRef, useState, } from "react";
|
|
7
|
+
import { useDragSubscription, useDraggable, } from "../dnd-controller/controller";
|
|
8
|
+
import { Coordinates } from "../utils/coordinates";
|
|
9
|
+
import { getNormalizedElementRect } from "../utils/screen";
|
|
10
|
+
import { useStableEventHandler } from "../utils/use-stable-event-handler";
|
|
11
|
+
import { useThrottledEventHandler } from "../utils/use-throttled-event-handler";
|
|
12
|
+
import { getNextDroppable } from "./get-next-droppable";
|
|
13
|
+
import styles from "./styles.css.js";
|
|
14
|
+
const Context = createContext(null);
|
|
15
|
+
export function useItemContext() {
|
|
16
|
+
const ctx = useContext(Context);
|
|
17
|
+
if (!ctx) {
|
|
18
|
+
throw new Error("Unable to find BoardItem context.");
|
|
19
|
+
}
|
|
20
|
+
return ctx;
|
|
21
|
+
}
|
|
22
|
+
export const ItemContainer = forwardRef(ItemContainerComponent);
|
|
23
|
+
function ItemContainerComponent({ item, placed, acquired, inTransition, transform, getItemSize, onKeyMove, children }, ref) {
|
|
24
|
+
var _a, _b, _c, _d, _e, _f;
|
|
25
|
+
const originalSizeRef = useRef({ width: 0, height: 0 });
|
|
26
|
+
const pointerOffsetRef = useRef(new Coordinates({ x: 0, y: 0 }));
|
|
27
|
+
const pointerBoundariesRef = useRef(null);
|
|
28
|
+
const [transition, setTransition] = useState(null);
|
|
29
|
+
const itemRef = useRef(null);
|
|
30
|
+
const draggableApi = useDraggable({ item, getElement: () => itemRef.current });
|
|
31
|
+
const onPointerMove = useThrottledEventHandler((event) => {
|
|
32
|
+
var _a, _b, _c, _d;
|
|
33
|
+
const coordinates = Coordinates.fromEvent(event);
|
|
34
|
+
draggableApi.updateTransition(new Coordinates({
|
|
35
|
+
x: Math.max(coordinates.x, (_b = (_a = pointerBoundariesRef.current) === null || _a === void 0 ? void 0 : _a.x) !== null && _b !== void 0 ? _b : Number.NEGATIVE_INFINITY),
|
|
36
|
+
y: Math.max(coordinates.y, (_d = (_c = pointerBoundariesRef.current) === null || _c === void 0 ? void 0 : _c.y) !== null && _d !== void 0 ? _d : Number.NEGATIVE_INFINITY),
|
|
37
|
+
}));
|
|
38
|
+
}, 10);
|
|
39
|
+
const onPointerUp = useStableEventHandler(() => {
|
|
40
|
+
onPointerMove.cancel();
|
|
41
|
+
draggableApi.submitTransition();
|
|
42
|
+
});
|
|
43
|
+
function updateTransition({ operation, interactionType, draggableItem, collisionRect, coordinates, dropTarget, }) {
|
|
44
|
+
if (item.id === draggableItem.id) {
|
|
45
|
+
const [width, height] = [collisionRect.right - collisionRect.left, collisionRect.bottom - collisionRect.top];
|
|
46
|
+
const pointerOffset = pointerOffsetRef.current;
|
|
47
|
+
if (operation === "resize") {
|
|
48
|
+
setTransition((transition) => ({
|
|
49
|
+
operation,
|
|
50
|
+
interactionType,
|
|
51
|
+
itemId: draggableItem.id,
|
|
52
|
+
sizeTransform: {
|
|
53
|
+
width: Math.max(getItemSize(null).minWidth, Math.min(getItemSize(null).maxWidth, width - pointerOffset.x)),
|
|
54
|
+
height: Math.max(getItemSize(null).minHeight, height - pointerOffset.y),
|
|
55
|
+
},
|
|
56
|
+
positionTransform: null,
|
|
57
|
+
isBorrowed: !!(transition === null || transition === void 0 ? void 0 : transition.isBorrowed),
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
else if (operation === "insert" || operation === "reorder") {
|
|
61
|
+
setTransition((transition) => ({
|
|
62
|
+
operation,
|
|
63
|
+
interactionType,
|
|
64
|
+
itemId: draggableItem.id,
|
|
65
|
+
sizeTransform: dropTarget ? getItemSize(dropTarget) : originalSizeRef.current,
|
|
66
|
+
positionTransform: { x: coordinates.x - pointerOffset.x, y: coordinates.y - pointerOffset.y },
|
|
67
|
+
isBorrowed: !!(transition === null || transition === void 0 ? void 0 : transition.isBorrowed),
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
useDragSubscription("start", (detail) => updateTransition(detail));
|
|
73
|
+
useDragSubscription("update", (detail) => updateTransition(detail));
|
|
74
|
+
useDragSubscription("submit", () => setTransition(null));
|
|
75
|
+
useDragSubscription("discard", () => setTransition(null));
|
|
76
|
+
useDragSubscription("acquire", (detail) => {
|
|
77
|
+
if (detail.draggableItem.id === item.id) {
|
|
78
|
+
setTransition((transition) => transition && { ...transition, isBorrowed: true });
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
// During the transition listen to pointer move and pointer up events to update/submit transition.
|
|
82
|
+
const transitionInteractionType = (_a = transition === null || transition === void 0 ? void 0 : transition.interactionType) !== null && _a !== void 0 ? _a : null;
|
|
83
|
+
const transitionItemId = (_b = transition === null || transition === void 0 ? void 0 : transition.itemId) !== null && _b !== void 0 ? _b : null;
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (transitionInteractionType === "pointer" && transitionItemId === item.id) {
|
|
86
|
+
window.addEventListener("pointermove", onPointerMove);
|
|
87
|
+
window.addEventListener("pointerup", onPointerUp);
|
|
88
|
+
}
|
|
89
|
+
return () => {
|
|
90
|
+
window.removeEventListener("pointermove", onPointerMove);
|
|
91
|
+
window.removeEventListener("pointerup", onPointerUp);
|
|
92
|
+
};
|
|
93
|
+
}, [item.id, transitionInteractionType, transitionItemId, onPointerMove, onPointerUp]);
|
|
94
|
+
function onKeyboardTransitionToggle(operation) {
|
|
95
|
+
// The acquired item is a copy and does not have the transition state.
|
|
96
|
+
// However, pressing "Space" or "Enter" on the acquired item must submit the active transition.
|
|
97
|
+
if (acquired) {
|
|
98
|
+
return draggableApi.submitTransition();
|
|
99
|
+
}
|
|
100
|
+
// Create new transition if missing.
|
|
101
|
+
if (!transition) {
|
|
102
|
+
const rect = getNormalizedElementRect(itemRef.current);
|
|
103
|
+
const coordinates = new Coordinates({
|
|
104
|
+
x: operation === "drag" ? rect.left : rect.right,
|
|
105
|
+
y: operation === "drag" ? rect.top : rect.bottom,
|
|
106
|
+
});
|
|
107
|
+
if (operation === "drag" && !placed) {
|
|
108
|
+
draggableApi.start("insert", "keyboard", coordinates);
|
|
109
|
+
}
|
|
110
|
+
else if (operation === "drag") {
|
|
111
|
+
draggableApi.start("reorder", "keyboard", coordinates);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
draggableApi.start("resize", "keyboard", coordinates);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// Submit a transition if existing.
|
|
118
|
+
else {
|
|
119
|
+
draggableApi.submitTransition();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function handleInsert(direction) {
|
|
123
|
+
// Find the closest droppable (in the direction) to the item.
|
|
124
|
+
const droppables = draggableApi.getDroppables();
|
|
125
|
+
const nextDroppable = getNextDroppable(itemRef.current, droppables, direction);
|
|
126
|
+
if (!nextDroppable) {
|
|
127
|
+
// TODO: add announcement
|
|
128
|
+
// Context: the keyboard insertion only works when there is some droppable area in the specified direction.
|
|
129
|
+
// That means that only some arrow keys might work which is confusing for a screen-reader user.
|
|
130
|
+
// Alternatively, we can consider a multi-step insertion where the user would first explicitly select the desired board.
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
// Notify the respective droppable of the intention to insert the item in it.
|
|
134
|
+
draggableApi.acquire(nextDroppable);
|
|
135
|
+
}
|
|
136
|
+
function onHandleKeyDown(operation, event) {
|
|
137
|
+
const canInsert = transition && operation === "drag" && !placed;
|
|
138
|
+
const canNavigate = transition || operation === "drag";
|
|
139
|
+
// The insert is handled by the item and the navigation is delegated to the containing layout.
|
|
140
|
+
const move = (direction) => {
|
|
141
|
+
if (canInsert) {
|
|
142
|
+
handleInsert(direction);
|
|
143
|
+
}
|
|
144
|
+
else if (canNavigate) {
|
|
145
|
+
onKeyMove === null || onKeyMove === void 0 ? void 0 : onKeyMove(direction);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
const discard = () => {
|
|
149
|
+
if (transition || acquired) {
|
|
150
|
+
draggableApi.discardTransition();
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
switch (event.key) {
|
|
154
|
+
case "ArrowUp":
|
|
155
|
+
return move("up");
|
|
156
|
+
case "ArrowDown":
|
|
157
|
+
return move("down");
|
|
158
|
+
case "ArrowLeft":
|
|
159
|
+
return move("left");
|
|
160
|
+
case "ArrowRight":
|
|
161
|
+
return move("right");
|
|
162
|
+
case " ":
|
|
163
|
+
case "Enter":
|
|
164
|
+
return onKeyboardTransitionToggle(operation);
|
|
165
|
+
case "Escape":
|
|
166
|
+
return discard();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function onBlur() {
|
|
170
|
+
// When drag- or resize handle loses focus the transition must be discarded with two exceptions:
|
|
171
|
+
// 1. If the last interaction is not "keyboard" (the user clicked on another handle issuing a new transition);
|
|
172
|
+
// 2. If the item is borrowed (in that case the focus moves to the acquired item which is expected).
|
|
173
|
+
if (transition && transition.interactionType === "keyboard" && !transition.isBorrowed) {
|
|
174
|
+
draggableApi.discardTransition();
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function onDragHandlePointerDown(event) {
|
|
178
|
+
// Calculate the offset between item's top-left corner and the pointer landing position.
|
|
179
|
+
const rect = itemRef.current.getBoundingClientRect();
|
|
180
|
+
pointerOffsetRef.current = new Coordinates({ x: event.clientX - rect.left, y: event.clientY - rect.top });
|
|
181
|
+
originalSizeRef.current = { width: rect.width, height: rect.height };
|
|
182
|
+
pointerBoundariesRef.current = null;
|
|
183
|
+
draggableApi.start(!placed ? "insert" : "reorder", "pointer", Coordinates.fromEvent(event));
|
|
184
|
+
}
|
|
185
|
+
function onDragHandleKeyDown(event) {
|
|
186
|
+
onHandleKeyDown("drag", event);
|
|
187
|
+
}
|
|
188
|
+
function onResizeHandlePointerDown(event) {
|
|
189
|
+
// Calculate the offset between item's bottom-right corner and the pointer landing position.
|
|
190
|
+
const rect = itemRef.current.getBoundingClientRect();
|
|
191
|
+
pointerOffsetRef.current = new Coordinates({ x: event.clientX - rect.right, y: event.clientY - rect.bottom });
|
|
192
|
+
originalSizeRef.current = { width: rect.width, height: rect.height };
|
|
193
|
+
// Calculate boundaries below which the cursor cannot move.
|
|
194
|
+
const minWidth = getItemSize(null).minWidth;
|
|
195
|
+
const minHeight = getItemSize(null).minHeight;
|
|
196
|
+
pointerBoundariesRef.current = new Coordinates({
|
|
197
|
+
x: event.clientX - rect.width + minWidth,
|
|
198
|
+
y: event.clientY - rect.height + minHeight,
|
|
199
|
+
});
|
|
200
|
+
draggableApi.start("resize", "pointer", Coordinates.fromEvent(event));
|
|
201
|
+
}
|
|
202
|
+
function onResizeHandleKeyDown(event) {
|
|
203
|
+
onHandleKeyDown("resize", event);
|
|
204
|
+
}
|
|
205
|
+
const itemTransitionStyle = {};
|
|
206
|
+
const itemTransitionClassNames = [];
|
|
207
|
+
if (inTransition) {
|
|
208
|
+
itemTransitionClassNames.push(styles.inTransition);
|
|
209
|
+
}
|
|
210
|
+
if (transition) {
|
|
211
|
+
// Adjust the dragged/resized item to the pointer's location.
|
|
212
|
+
if (transition.interactionType === "pointer") {
|
|
213
|
+
itemTransitionClassNames.push(transition.operation === "resize" ? styles.resized : styles.dragged);
|
|
214
|
+
itemTransitionStyle.left = (_c = transition.positionTransform) === null || _c === void 0 ? void 0 : _c.x;
|
|
215
|
+
itemTransitionStyle.top = (_d = transition.positionTransform) === null || _d === void 0 ? void 0 : _d.y;
|
|
216
|
+
itemTransitionStyle.width = (_e = transition.sizeTransform) === null || _e === void 0 ? void 0 : _e.width;
|
|
217
|
+
itemTransitionStyle.height = (_f = transition.sizeTransform) === null || _f === void 0 ? void 0 : _f.height;
|
|
218
|
+
itemTransitionStyle.pointerEvents = "none";
|
|
219
|
+
}
|
|
220
|
+
// Make the borrowed item dimmed.
|
|
221
|
+
else if (transition.isBorrowed) {
|
|
222
|
+
itemTransitionClassNames.push(styles.borrowed);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (placed && transform) {
|
|
226
|
+
// The moved items positions are altered with CSS transform.
|
|
227
|
+
if (transform.type === "move") {
|
|
228
|
+
itemTransitionClassNames.push(styles.transformed);
|
|
229
|
+
itemTransitionStyle.transform = CSSUtil.Transform.toString({
|
|
230
|
+
x: transform.x,
|
|
231
|
+
y: transform.y,
|
|
232
|
+
scaleX: 1,
|
|
233
|
+
scaleY: 1,
|
|
234
|
+
});
|
|
235
|
+
itemTransitionStyle.width = transform.width + "px";
|
|
236
|
+
itemTransitionStyle.height = transform.height + "px";
|
|
237
|
+
}
|
|
238
|
+
// The item is removed from the DOM after animations play.
|
|
239
|
+
// During the animations the removed item is hidden with styles.
|
|
240
|
+
if (transform.type === "remove") {
|
|
241
|
+
itemTransitionClassNames.push(styles.removed);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const dragHandleRef = useRef(null);
|
|
245
|
+
useImperativeHandle(ref, () => ({
|
|
246
|
+
focusDragHandle: () => { var _a; return (_a = dragHandleRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
|
|
247
|
+
}));
|
|
248
|
+
return (_jsx("div", { ref: itemRef, className: clsx(styles.root, ...itemTransitionClassNames), style: itemTransitionStyle, "data-item-id": item.id, onBlur: onBlur, children: _jsx(Context.Provider, { value: {
|
|
249
|
+
isActive: (!!transition && !transition.isBorrowed) || !!acquired,
|
|
250
|
+
dragHandle: {
|
|
251
|
+
ref: dragHandleRef,
|
|
252
|
+
onPointerDown: onDragHandlePointerDown,
|
|
253
|
+
onKeyDown: onDragHandleKeyDown,
|
|
254
|
+
},
|
|
255
|
+
resizeHandle: placed
|
|
256
|
+
? {
|
|
257
|
+
onPointerDown: onResizeHandlePointerDown,
|
|
258
|
+
onKeyDown: onResizeHandleKeyDown,
|
|
259
|
+
}
|
|
260
|
+
: null,
|
|
261
|
+
}, children: children }) }));
|
|
262
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
import './styles.scoped.css';
|
|
3
|
+
export default {
|
|
4
|
+
"root": "awsui_root_lljvd_udubn_1",
|
|
5
|
+
"inTransition": "awsui_inTransition_lljvd_udubn_7",
|
|
6
|
+
"transformed": "awsui_transformed_lljvd_udubn_12",
|
|
7
|
+
"removed": "awsui_removed_lljvd_udubn_17",
|
|
8
|
+
"dragged": "awsui_dragged_lljvd_udubn_21",
|
|
9
|
+
"resized": "awsui_resized_lljvd_udubn_26",
|
|
10
|
+
"borrowed": "awsui_borrowed_lljvd_udubn_31"
|
|
11
|
+
};
|
|
12
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
.awsui_root_lljvd_udubn_1:not(#\9) {
|
|
2
|
+
touch-action: none;
|
|
3
|
+
position: relative;
|
|
4
|
+
height: 100%;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.awsui_inTransition_lljvd_udubn_7:not(#\9) {
|
|
8
|
+
transition: transform 200ms;
|
|
9
|
+
transition-timing-function: ease;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.awsui_transformed_lljvd_udubn_12:not(#\9) {
|
|
13
|
+
position: absolute;
|
|
14
|
+
z-index: 1;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.awsui_removed_lljvd_udubn_17:not(#\9) {
|
|
18
|
+
display: none;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.awsui_dragged_lljvd_udubn_21:not(#\9) {
|
|
22
|
+
z-index: 5000;
|
|
23
|
+
position: fixed;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.awsui_resized_lljvd_udubn_26:not(#\9) {
|
|
27
|
+
z-index: 5000;
|
|
28
|
+
position: absolute;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.awsui_borrowed_lljvd_udubn_31:not(#\9) {
|
|
32
|
+
opacity: 0.5;
|
|
33
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
// es-module interop with Babel and Typescript
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
module.exports.default = {
|
|
5
|
+
"root": "awsui_root_lljvd_udubn_1",
|
|
6
|
+
"inTransition": "awsui_inTransition_lljvd_udubn_7",
|
|
7
|
+
"transformed": "awsui_transformed_lljvd_udubn_12",
|
|
8
|
+
"removed": "awsui_removed_lljvd_udubn_17",
|
|
9
|
+
"dragged": "awsui_dragged_lljvd_udubn_21",
|
|
10
|
+
"resized": "awsui_resized_lljvd_udubn_26",
|
|
11
|
+
"borrowed": "awsui_borrowed_lljvd_udubn_31"
|
|
12
|
+
};
|
|
13
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// Find items that the active item cannot be moved over with the current move.
|
|
4
|
+
export function findConflicts(move, grid) {
|
|
5
|
+
const conflicts = new Set();
|
|
6
|
+
const moveTarget = grid.getItem(move.itemId);
|
|
7
|
+
const direction = `${move.x - moveTarget.x}:${move.y - moveTarget.y}`;
|
|
8
|
+
switch (direction) {
|
|
9
|
+
case "-1:0": {
|
|
10
|
+
const left = Math.max(0, moveTarget.left - 1);
|
|
11
|
+
for (let y = moveTarget.y; y < moveTarget.y + moveTarget.height; y++) {
|
|
12
|
+
const block = grid.getCellOverlap(left, y, moveTarget.id);
|
|
13
|
+
if (block && block.x < left) {
|
|
14
|
+
conflicts.add(block.id);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
case "1:0": {
|
|
20
|
+
const right = Math.min(grid.width - 1, moveTarget.right + 1);
|
|
21
|
+
for (let y = moveTarget.y; y < moveTarget.y + moveTarget.height; y++) {
|
|
22
|
+
const block = grid.getCellOverlap(right, y, moveTarget.id);
|
|
23
|
+
if (block && block.x + block.width - 1 > right) {
|
|
24
|
+
conflicts.add(block.id);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
case "0:-1": {
|
|
30
|
+
const top = Math.max(0, moveTarget.top - 1);
|
|
31
|
+
for (let x = moveTarget.x; x < moveTarget.x + moveTarget.width; x++) {
|
|
32
|
+
const block = grid.getCellOverlap(x, top, moveTarget.id);
|
|
33
|
+
if (block && block.y < top) {
|
|
34
|
+
conflicts.add(block.id);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
case "0:1": {
|
|
40
|
+
const bottom = moveTarget.bottom + 1;
|
|
41
|
+
for (let x = moveTarget.x; x < moveTarget.x + moveTarget.width; x++) {
|
|
42
|
+
const block = grid.getCellOverlap(x, bottom, moveTarget.id);
|
|
43
|
+
if (block && block.y + block.height - 1 > bottom) {
|
|
44
|
+
conflicts.add(block.id);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
default:
|
|
50
|
+
throw new Error(`Invariant violation: unexpected direction ${direction}.`);
|
|
51
|
+
}
|
|
52
|
+
return conflicts;
|
|
53
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ItemId } from "../interfaces";
|
|
2
|
+
import { LayoutEngineGrid } from "./grid";
|
|
3
|
+
import { CommittedMove } from "./interfaces";
|
|
4
|
+
export declare function resolveOverlaps(userMove: CommittedMove, grid: LayoutEngineGrid, moves: CommittedMove[], conflicts: Set<ItemId>): void;
|
|
5
|
+
export declare function refloatGrid(grid: LayoutEngineGrid, moves: CommittedMove[], conflicts: Set<ItemId>): void;
|