@datarobot/design-system 28.9.2 → 28.10.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/cjs/floating-panel/constants.d.ts +21 -0
- package/cjs/floating-panel/constants.js +94 -0
- package/cjs/floating-panel/draggable-area.d.ts +12 -0
- package/cjs/floating-panel/draggable-area.js +72 -0
- package/cjs/floating-panel/floating-panel-dock-button.d.ts +5 -0
- package/cjs/floating-panel/floating-panel-dock-button.js +37 -0
- package/cjs/floating-panel/floating-panel-drag-handle.d.ts +5 -0
- package/cjs/floating-panel/floating-panel-drag-handle.js +51 -0
- package/cjs/floating-panel/floating-panel-header.d.ts +11 -0
- package/cjs/floating-panel/floating-panel-header.js +46 -0
- package/cjs/floating-panel/floating-panel.d.ts +66 -0
- package/cjs/floating-panel/floating-panel.js +140 -0
- package/cjs/floating-panel/index.d.ts +4 -0
- package/cjs/floating-panel/index.js +19 -0
- package/cjs/floating-panel/types.d.ts +21 -0
- package/cjs/floating-panel/types.js +5 -0
- package/cjs/floating-panel/use-floating-panel-root.d.ts +6 -0
- package/cjs/floating-panel/use-floating-panel-root.js +31 -0
- package/cjs/floating-panel/use-floating-panel-state.d.ts +27 -0
- package/cjs/floating-panel/use-floating-panel-state.js +316 -0
- package/cjs/floating-panel/use-floating-panel.d.ts +4 -0
- package/cjs/floating-panel/use-floating-panel.js +14 -0
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +11 -0
- package/cjs/table-react/hooks/useColumns.js +13 -5
- package/esm/floating-panel/constants.d.ts +21 -0
- package/esm/floating-panel/constants.js +86 -0
- package/esm/floating-panel/draggable-area.d.ts +12 -0
- package/esm/floating-panel/draggable-area.js +65 -0
- package/esm/floating-panel/floating-panel-dock-button.d.ts +5 -0
- package/esm/floating-panel/floating-panel-dock-button.js +30 -0
- package/esm/floating-panel/floating-panel-drag-handle.d.ts +5 -0
- package/esm/floating-panel/floating-panel-drag-handle.js +44 -0
- package/esm/floating-panel/floating-panel-header.d.ts +11 -0
- package/esm/floating-panel/floating-panel-header.js +39 -0
- package/esm/floating-panel/floating-panel.d.ts +66 -0
- package/esm/floating-panel/floating-panel.js +132 -0
- package/esm/floating-panel/index.d.ts +4 -0
- package/esm/floating-panel/index.js +2 -0
- package/esm/floating-panel/types.d.ts +21 -0
- package/esm/floating-panel/types.js +1 -0
- package/esm/floating-panel/use-floating-panel-root.d.ts +6 -0
- package/esm/floating-panel/use-floating-panel-root.js +24 -0
- package/esm/floating-panel/use-floating-panel-state.d.ts +27 -0
- package/esm/floating-panel/use-floating-panel-state.js +310 -0
- package/esm/floating-panel/use-floating-panel.d.ts +4 -0
- package/esm/floating-panel/use-floating-panel.js +9 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/esm/table-react/hooks/useColumns.js +13 -5
- package/floating-panel/package.json +7 -0
- package/js/bundle/bundle.js +1351 -332
- package/js/bundle/bundle.min.js +1 -1
- package/js/bundle/index.d.ts +94 -1
- package/package.json +1 -1
- package/styles/index.css +150 -0
- package/styles/index.min.css +1 -1
- package/styles/themes/alpine-light.css +12 -0
- package/styles/themes/alpine-light.min.css +1 -1
- package/styles/themes/midnight-gray.css +12 -0
- package/styles/themes/midnight-gray.min.css +1 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React, { CSSProperties, Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import { DraggableEvent, FloatingPanelContextType, PanelState } from './types';
|
|
3
|
+
export type UseFloatingPanelHook = {
|
|
4
|
+
style: CSSProperties;
|
|
5
|
+
context: FloatingPanelContextType;
|
|
6
|
+
panelRef: React.MutableRefObject<HTMLDivElement | null>;
|
|
7
|
+
headerRef: React.MutableRefObject<HTMLHeadElement | null>;
|
|
8
|
+
onResize: (event: DraggableEvent) => void;
|
|
9
|
+
onMovementStart: (event: DraggableEvent) => void;
|
|
10
|
+
onResizeEnd: (event: DraggableEvent | string) => void;
|
|
11
|
+
setState: Dispatch<SetStateAction<PanelState>>;
|
|
12
|
+
isDocked: boolean;
|
|
13
|
+
setIsDocked: (docked: boolean) => void;
|
|
14
|
+
getPosition: () => PanelState;
|
|
15
|
+
};
|
|
16
|
+
export type UseFloatingPanelParams = {
|
|
17
|
+
minHeight: number;
|
|
18
|
+
minWidth: number;
|
|
19
|
+
maxWidth: number;
|
|
20
|
+
maxHeight: number;
|
|
21
|
+
isDocked: boolean;
|
|
22
|
+
setIsDocked: Dispatch<SetStateAction<boolean>>;
|
|
23
|
+
initialState?: PanelState;
|
|
24
|
+
containerElement: HTMLElement;
|
|
25
|
+
pageContentElement?: HTMLElement;
|
|
26
|
+
};
|
|
27
|
+
export declare function useFloatingPanelState({ minWidth, minHeight, maxWidth, maxHeight, isDocked: isDockedExternal, setIsDocked: setIsDockedExternal, initialState, containerElement, pageContentElement, }: UseFloatingPanelParams): UseFloatingPanelHook;
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useFloatingPanelState = useFloatingPanelState;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _hooks = require("../hooks");
|
|
9
|
+
var _useFloatingPanelRoot = require("./use-floating-panel-root");
|
|
10
|
+
var _constants = require("./constants");
|
|
11
|
+
const step = 80;
|
|
12
|
+
const dockAreaWidth = 26;
|
|
13
|
+
const delta = {
|
|
14
|
+
[_constants.MOVE_KEYS.UP]: {
|
|
15
|
+
dx: 0,
|
|
16
|
+
dy: -step
|
|
17
|
+
},
|
|
18
|
+
[_constants.MOVE_KEYS.RIGHT]: {
|
|
19
|
+
dx: step,
|
|
20
|
+
dy: 0
|
|
21
|
+
},
|
|
22
|
+
[_constants.MOVE_KEYS.DOWN]: {
|
|
23
|
+
dx: 0,
|
|
24
|
+
dy: step
|
|
25
|
+
},
|
|
26
|
+
[_constants.MOVE_KEYS.LEFT]: {
|
|
27
|
+
dx: -step,
|
|
28
|
+
dy: 0
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
function useFloatingPanelState({
|
|
32
|
+
minWidth,
|
|
33
|
+
minHeight,
|
|
34
|
+
maxWidth,
|
|
35
|
+
maxHeight,
|
|
36
|
+
isDocked: isDockedExternal,
|
|
37
|
+
setIsDocked: setIsDockedExternal,
|
|
38
|
+
initialState,
|
|
39
|
+
containerElement,
|
|
40
|
+
pageContentElement
|
|
41
|
+
}) {
|
|
42
|
+
const [isDocked, setIsDocked] = (0, _react.useState)(isDockedExternal);
|
|
43
|
+
const [isMoving, setIsMoving] = (0, _react.useState)(false);
|
|
44
|
+
const animationRef = (0, _react.useRef)(null);
|
|
45
|
+
const headerRef = (0, _react.useRef)(null);
|
|
46
|
+
const headerHeightRef = (0, _react.useRef)(36);
|
|
47
|
+
const panelRef = (0, _react.useRef)(null);
|
|
48
|
+
const dragStartPositionsRef = (0, _react.useRef)();
|
|
49
|
+
const isDockHighlightedRef = (0, _react.useRef)(false);
|
|
50
|
+
const containerRef = (0, _react.useRef)(containerElement);
|
|
51
|
+
const lastPositionRef = (0, _react.useRef)({
|
|
52
|
+
top: 0,
|
|
53
|
+
left: 0,
|
|
54
|
+
width: 0,
|
|
55
|
+
height: 0
|
|
56
|
+
});
|
|
57
|
+
const [state, setState] = (0, _react.useState)(initialState ? {
|
|
58
|
+
top: initialState.top || lastPositionRef.current.top,
|
|
59
|
+
left: initialState.left || lastPositionRef.current.left,
|
|
60
|
+
width: between(initialState.width || lastPositionRef.current.width, minWidth, maxWidth),
|
|
61
|
+
height: between(initialState.height || lastPositionRef.current.height, minHeight, maxHeight)
|
|
62
|
+
} : {
|
|
63
|
+
top: 0,
|
|
64
|
+
left: 0,
|
|
65
|
+
width: minWidth,
|
|
66
|
+
height: minHeight
|
|
67
|
+
});
|
|
68
|
+
lastPositionRef.current = state;
|
|
69
|
+
containerRef.current = containerElement;
|
|
70
|
+
const style = (0, _react.useMemo)(() => isDocked ? {} : {
|
|
71
|
+
transform: `translate3d(${state.left}px, ${state.top}px, 0px)`,
|
|
72
|
+
width: `${state.width}px`,
|
|
73
|
+
height: `${state.height}px`
|
|
74
|
+
}, [state, isDocked]);
|
|
75
|
+
const onDrag = (0, _react.useCallback)(event => {
|
|
76
|
+
if (animationRef.current) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
animationRef.current = requestAnimationFrame(() => {
|
|
80
|
+
const start = dragStartPositionsRef.current;
|
|
81
|
+
const maxLeft = window.innerWidth - start.width * 0.25;
|
|
82
|
+
const maxTop = window.innerHeight - headerHeightRef.current;
|
|
83
|
+
const nextLeft = event.clientX - (start.mouseX - start.left);
|
|
84
|
+
const nextTop = event.clientY - (start.mouseY - start.top);
|
|
85
|
+
setState(state => {
|
|
86
|
+
const nextState = {
|
|
87
|
+
...state,
|
|
88
|
+
top: between(nextTop, 0, maxTop),
|
|
89
|
+
left: between(nextLeft, 0, maxLeft)
|
|
90
|
+
};
|
|
91
|
+
const nextIsDockHighlighted = isInDockArea(nextState);
|
|
92
|
+
// DOM manipulation, not state
|
|
93
|
+
if (nextIsDockHighlighted !== isDockHighlightedRef.current) {
|
|
94
|
+
toggleDockHighlight(nextIsDockHighlighted, containerRef.current);
|
|
95
|
+
isDockHighlightedRef.current = nextIsDockHighlighted;
|
|
96
|
+
}
|
|
97
|
+
return nextState;
|
|
98
|
+
});
|
|
99
|
+
animationRef.current = null;
|
|
100
|
+
});
|
|
101
|
+
}, []);
|
|
102
|
+
const onMovementStart = (0, _react.useCallback)(event => {
|
|
103
|
+
const element = panelRef.current;
|
|
104
|
+
const header = headerRef.current;
|
|
105
|
+
if (!element || !header) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
headerHeightRef.current = header.getBoundingClientRect().height;
|
|
109
|
+
const mouseX = event.pageX;
|
|
110
|
+
const mouseY = event.pageY;
|
|
111
|
+
dragStartPositionsRef.current = {
|
|
112
|
+
...getPanelStateFromElement(element),
|
|
113
|
+
mouseX,
|
|
114
|
+
mouseY
|
|
115
|
+
};
|
|
116
|
+
lastPositionRef.current = dragStartPositionsRef.current;
|
|
117
|
+
setIsMoving(true);
|
|
118
|
+
}, []);
|
|
119
|
+
const onDragEnd = (0, _react.useCallback)(() => {
|
|
120
|
+
if (isDockHighlightedRef.current) {
|
|
121
|
+
const position = dragStartPositionsRef.current;
|
|
122
|
+
setIsDocked(true);
|
|
123
|
+
setIsDockedExternal(true);
|
|
124
|
+
setState(state => {
|
|
125
|
+
const nextState = {
|
|
126
|
+
...state,
|
|
127
|
+
left: window.innerWidth - position.width - dockAreaWidth * 2
|
|
128
|
+
};
|
|
129
|
+
lastPositionRef.current = nextState;
|
|
130
|
+
return nextState;
|
|
131
|
+
});
|
|
132
|
+
isDockHighlightedRef.current = false;
|
|
133
|
+
toggleDockHighlight(false, containerRef.current);
|
|
134
|
+
}
|
|
135
|
+
setIsMoving(false);
|
|
136
|
+
}, []);
|
|
137
|
+
const onResize = (0, _react.useCallback)(e => {
|
|
138
|
+
if (animationRef.current) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
animationRef.current = requestAnimationFrame(() => {
|
|
142
|
+
const start = dragStartPositionsRef.current;
|
|
143
|
+
const statePatch = {};
|
|
144
|
+
const resize = _constants.resizeHandlesMap.get(e.areaId);
|
|
145
|
+
if (resize?.right) {
|
|
146
|
+
const width = between(start.width + (e.pageX - start.mouseX), minWidth, maxWidth);
|
|
147
|
+
if (width !== start.width) {
|
|
148
|
+
statePatch.width = width;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (resize?.bottom) {
|
|
152
|
+
const height = between(start.height + (e.pageY - start.mouseY), minHeight, maxHeight);
|
|
153
|
+
if (height !== start.height) {
|
|
154
|
+
statePatch.height = height;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (resize?.top) {
|
|
158
|
+
const height = start.height - (e.pageY - start.mouseY);
|
|
159
|
+
const nextTop = start.top + (e.pageY - start.mouseY);
|
|
160
|
+
if (height > minHeight && height <= maxHeight && nextTop > 0) {
|
|
161
|
+
statePatch.height = height;
|
|
162
|
+
statePatch.top = nextTop;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (resize?.left) {
|
|
166
|
+
const width = start.width - (e.pageX - start.mouseX);
|
|
167
|
+
if (width > minWidth && width <= maxWidth) {
|
|
168
|
+
statePatch.width = width;
|
|
169
|
+
statePatch.left = start.left + (e.pageX - start.mouseX);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (Object.keys(statePatch).length) {
|
|
173
|
+
setState(state => ({
|
|
174
|
+
...state,
|
|
175
|
+
...statePatch
|
|
176
|
+
}));
|
|
177
|
+
}
|
|
178
|
+
animationRef.current = null;
|
|
179
|
+
});
|
|
180
|
+
}, [minWidth, minHeight, maxWidth, maxHeight]);
|
|
181
|
+
const onResizeEnd = (0, _react.useCallback)(() => {
|
|
182
|
+
setIsMoving(false);
|
|
183
|
+
}, []);
|
|
184
|
+
const setIsDockedHandler = (0, _react.useCallback)(docked => {
|
|
185
|
+
const element = panelRef.current;
|
|
186
|
+
if (!element || docked === isDocked) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (docked) {
|
|
190
|
+
setIsDocked(true);
|
|
191
|
+
} else {
|
|
192
|
+
setIsDocked(false);
|
|
193
|
+
}
|
|
194
|
+
if (isDockedExternal !== docked) {
|
|
195
|
+
setIsDockedExternal(docked);
|
|
196
|
+
}
|
|
197
|
+
}, [isDockedExternal, isDocked, setIsDockedExternal]);
|
|
198
|
+
const onMoveWithArrows = (0, _react.useCallback)(event => {
|
|
199
|
+
if (!_constants.MOVE_KEYS_VALUES.includes(event.key)) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const element = panelRef.current;
|
|
203
|
+
if (!element) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const dx = delta[event.key].dx;
|
|
207
|
+
const dy = delta[event.key].dy;
|
|
208
|
+
const currentState = getPanelStateFromElement(element);
|
|
209
|
+
const maxLeft = window.innerWidth - currentState.width * 0.25;
|
|
210
|
+
const maxTop = window.innerHeight - headerHeightRef.current;
|
|
211
|
+
const nextLeft = currentState.left + dx;
|
|
212
|
+
const nextTop = currentState.top + dy;
|
|
213
|
+
let shouldDockInsteadOfMove = false;
|
|
214
|
+
const nextState = {
|
|
215
|
+
...state,
|
|
216
|
+
top: between(nextTop, 0, maxTop),
|
|
217
|
+
left: between(nextLeft, 0, maxLeft)
|
|
218
|
+
};
|
|
219
|
+
shouldDockInsteadOfMove = isInDockArea(nextState) !== isDocked;
|
|
220
|
+
if (shouldDockInsteadOfMove) {
|
|
221
|
+
setIsDocked(true);
|
|
222
|
+
setIsDockedExternal(true);
|
|
223
|
+
} else {
|
|
224
|
+
setState(nextState);
|
|
225
|
+
}
|
|
226
|
+
}, [isDocked, state, setIsDockedExternal]);
|
|
227
|
+
const getPosition = (0, _react.useCallback)(() => {
|
|
228
|
+
return lastPositionRef.current;
|
|
229
|
+
}, []);
|
|
230
|
+
(0, _react.useEffect)(() => {
|
|
231
|
+
if (isDockedExternal !== isDocked) {
|
|
232
|
+
setIsDockedHandler(isDockedExternal);
|
|
233
|
+
}
|
|
234
|
+
}, [isDockedExternal]);
|
|
235
|
+
|
|
236
|
+
// update position on window resize
|
|
237
|
+
(0, _react.useEffect)(() => {
|
|
238
|
+
const header = headerRef.current;
|
|
239
|
+
headerHeightRef.current = header.getBoundingClientRect().height;
|
|
240
|
+
const onResizeHandler = () => {
|
|
241
|
+
const start = lastPositionRef.current;
|
|
242
|
+
const maxLeft = window.innerWidth - start.width;
|
|
243
|
+
const maxTop = window.innerHeight - headerHeightRef.current;
|
|
244
|
+
if (start.left > maxLeft || start.top > maxTop) {
|
|
245
|
+
setState(state => ({
|
|
246
|
+
...state,
|
|
247
|
+
top: between(start.top, 0, maxTop),
|
|
248
|
+
left: between(start.left, 0, maxLeft)
|
|
249
|
+
}));
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
window.addEventListener('resize', onResizeHandler);
|
|
253
|
+
return () => {
|
|
254
|
+
window.removeEventListener('resize', onResizeHandler);
|
|
255
|
+
if (animationRef.current) {
|
|
256
|
+
cancelAnimationFrame(animationRef.current);
|
|
257
|
+
animationRef.current = null;
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}, []);
|
|
261
|
+
(0, _hooks.useFocusTrap)(panelRef);
|
|
262
|
+
// update style according to content and header height
|
|
263
|
+
(0, _useFloatingPanelRoot.useFloatingPanelRoot)({
|
|
264
|
+
containerElement,
|
|
265
|
+
pageContentElement
|
|
266
|
+
});
|
|
267
|
+
const context = (0, _react.useMemo)(() => ({
|
|
268
|
+
onDrag,
|
|
269
|
+
onDragStart: onMovementStart,
|
|
270
|
+
onDragEnd,
|
|
271
|
+
onMoveWithArrows,
|
|
272
|
+
isDocked,
|
|
273
|
+
setIsDocked: setIsDockedHandler,
|
|
274
|
+
getPosition,
|
|
275
|
+
isMoving
|
|
276
|
+
}), [isDocked, setIsDockedHandler, onDrag, onDragEnd, onMovementStart, onMoveWithArrows, getPosition, isMoving]);
|
|
277
|
+
const api = {
|
|
278
|
+
style,
|
|
279
|
+
panelRef,
|
|
280
|
+
headerRef,
|
|
281
|
+
onResize,
|
|
282
|
+
onMovementStart,
|
|
283
|
+
onResizeEnd,
|
|
284
|
+
setState,
|
|
285
|
+
context,
|
|
286
|
+
isDocked,
|
|
287
|
+
setIsDocked: setIsDockedHandler,
|
|
288
|
+
getPosition
|
|
289
|
+
};
|
|
290
|
+
return (0, _react.useMemo)(() => api, Object.values(api));
|
|
291
|
+
}
|
|
292
|
+
function getPanelStateFromElement(element) {
|
|
293
|
+
const bbox = element.getBoundingClientRect();
|
|
294
|
+
return {
|
|
295
|
+
width: bbox.width,
|
|
296
|
+
height: bbox.height,
|
|
297
|
+
left: bbox.x,
|
|
298
|
+
top: bbox.y
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
function isInDockArea(panelPosition) {
|
|
302
|
+
return panelPosition.left + panelPosition.width > window.innerWidth - dockAreaWidth;
|
|
303
|
+
}
|
|
304
|
+
function toggleDockHighlight(isDockHighlighted, element) {
|
|
305
|
+
if (!element) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
if (isDockHighlighted) {
|
|
309
|
+
element.classList.add(_constants.HIGHLIGHTED_CLASSNAME);
|
|
310
|
+
} else {
|
|
311
|
+
element.classList.remove(_constants.HIGHLIGHTED_CLASSNAME);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function between(value, min, max) {
|
|
315
|
+
return Math.min(Math.max(value, min), max);
|
|
316
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useFloatingPanel = useFloatingPanel;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _constants = require("./constants");
|
|
9
|
+
/**
|
|
10
|
+
* Use inside the content component for FloatingPanel in order to get access to context
|
|
11
|
+
*/
|
|
12
|
+
function useFloatingPanel() {
|
|
13
|
+
return (0, _react.useContext)(_constants.FloatingPanelContext);
|
|
14
|
+
}
|
package/cjs/index.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export * from './file-upload';
|
|
|
39
39
|
export * from './file-uploader';
|
|
40
40
|
export * from './files-upload-area';
|
|
41
41
|
export * from './filtering-panel';
|
|
42
|
+
export * from './floating-panel';
|
|
42
43
|
export * from './font-awesome-icon';
|
|
43
44
|
export * from './form-field';
|
|
44
45
|
export * from './full-screen-drawer';
|
package/cjs/index.js
CHANGED
|
@@ -454,6 +454,17 @@ Object.keys(_filteringPanel).forEach(function (key) {
|
|
|
454
454
|
}
|
|
455
455
|
});
|
|
456
456
|
});
|
|
457
|
+
var _floatingPanel = require("./floating-panel");
|
|
458
|
+
Object.keys(_floatingPanel).forEach(function (key) {
|
|
459
|
+
if (key === "default" || key === "__esModule") return;
|
|
460
|
+
if (key in exports && exports[key] === _floatingPanel[key]) return;
|
|
461
|
+
Object.defineProperty(exports, key, {
|
|
462
|
+
enumerable: true,
|
|
463
|
+
get: function () {
|
|
464
|
+
return _floatingPanel[key];
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
});
|
|
457
468
|
var _fontAwesomeIcon = require("./font-awesome-icon");
|
|
458
469
|
Object.keys(_fontAwesomeIcon).forEach(function (key) {
|
|
459
470
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -14,14 +14,21 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
|
|
|
14
14
|
function calculateDelta(columns, maxWidth, padding = 0, columnSizing = {}, visibility = {}) {
|
|
15
15
|
// we are interested only in visible columns
|
|
16
16
|
const visibleColumns = columns.filter(({
|
|
17
|
-
accessorKey
|
|
18
|
-
|
|
17
|
+
accessorKey,
|
|
18
|
+
id
|
|
19
|
+
}) => {
|
|
20
|
+
// visibility state uses column ids for setting visibility, and for most cases it's the same as accessorKey
|
|
21
|
+
// but for the case when either 1) user provided an explicit id to the columnDef or 2) accessorKey is a complex get object path like `<object_name>.<object_property_name>`
|
|
22
|
+
// accessorKey would be different from id. Thus we should add a check on columnDef.id here
|
|
23
|
+
const visibilityValue = visibility[id] ?? visibility[accessorKey];
|
|
24
|
+
return visibilityValue !== false;
|
|
25
|
+
});
|
|
19
26
|
// we need to know columns that do have maxSize set, as it will influence how free space is distributed
|
|
20
27
|
const columnsWithMaxSize = visibleColumns.filter(column => !!column.maxSize);
|
|
21
28
|
|
|
22
29
|
// calculation of all current columns width
|
|
23
30
|
const currentWidth = visibleColumns.reduce((acc, current) => {
|
|
24
|
-
const resizeValue = columnSizing[current.accessorKey];
|
|
31
|
+
const resizeValue = columnSizing[current.id] || columnSizing[current.accessorKey];
|
|
25
32
|
const minWidth = current.minSize || _types.COLUMN_SIZE.MIN_WIDTH;
|
|
26
33
|
const resizeWidth = resizeValue ? Math.max(resizeValue, minWidth) : 0;
|
|
27
34
|
const columnSize = Math.max(current.size || _types.COLUMN_SIZE.WIDTH, minWidth);
|
|
@@ -39,8 +46,9 @@ function calculateDelta(columns, maxWidth, padding = 0, columnSizing = {}, visib
|
|
|
39
46
|
// whose size was altered manually by drag-n-drop in UI)
|
|
40
47
|
const notSettedColumns = visibleColumns.filter(({
|
|
41
48
|
size,
|
|
42
|
-
accessorKey
|
|
43
|
-
|
|
49
|
+
accessorKey,
|
|
50
|
+
id
|
|
51
|
+
}) => !size && !(columnSizing[id] || columnSizing[accessorKey]));
|
|
44
52
|
const evenDistribution = delta / notSettedColumns.length;
|
|
45
53
|
|
|
46
54
|
// if there is no max size on any columns - distribute free space evenly across columns
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { FloatingPanelContextType } from './types';
|
|
3
|
+
export declare const FloatingPanelContext: import("react").Context<FloatingPanelContextType>;
|
|
4
|
+
export declare const MOVE_KEYS: {
|
|
5
|
+
readonly UP: "ArrowUp";
|
|
6
|
+
readonly DOWN: "ArrowDown";
|
|
7
|
+
readonly RIGHT: "ArrowRight";
|
|
8
|
+
readonly LEFT: "ArrowLeft";
|
|
9
|
+
};
|
|
10
|
+
export declare const MOVE_KEYS_VALUES: ("ArrowUp" | "ArrowDown" | "ArrowRight" | "ArrowLeft")[];
|
|
11
|
+
export declare const HIGHLIGHTED_CLASSNAME = "highlighted";
|
|
12
|
+
export type ResizeHandle = {
|
|
13
|
+
id: string;
|
|
14
|
+
left: boolean;
|
|
15
|
+
top: boolean;
|
|
16
|
+
bottom: boolean;
|
|
17
|
+
right: boolean;
|
|
18
|
+
};
|
|
19
|
+
export declare const resizeHandles: readonly ResizeHandle[];
|
|
20
|
+
export declare const resizeHandlesMap: Map<string, ResizeHandle>;
|
|
21
|
+
export declare function getHtmlElement(anchorEl: any): HTMLElement | null;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
export const FloatingPanelContext = /*#__PURE__*/createContext({
|
|
3
|
+
onDrag: () => {},
|
|
4
|
+
onDragStart: () => {},
|
|
5
|
+
onDragEnd: () => {},
|
|
6
|
+
isDocked: false,
|
|
7
|
+
isMoving: false,
|
|
8
|
+
setIsDocked: () => {},
|
|
9
|
+
onMoveWithArrows: () => {},
|
|
10
|
+
getPosition: () => ({
|
|
11
|
+
left: 0,
|
|
12
|
+
top: 0,
|
|
13
|
+
width: 0,
|
|
14
|
+
height: 0
|
|
15
|
+
})
|
|
16
|
+
});
|
|
17
|
+
export const MOVE_KEYS = {
|
|
18
|
+
UP: 'ArrowUp',
|
|
19
|
+
DOWN: 'ArrowDown',
|
|
20
|
+
RIGHT: 'ArrowRight',
|
|
21
|
+
LEFT: 'ArrowLeft'
|
|
22
|
+
};
|
|
23
|
+
export const MOVE_KEYS_VALUES = Object.values(MOVE_KEYS);
|
|
24
|
+
export const HIGHLIGHTED_CLASSNAME = 'highlighted';
|
|
25
|
+
export const resizeHandles = [{
|
|
26
|
+
id: 'top-left',
|
|
27
|
+
left: true,
|
|
28
|
+
top: true,
|
|
29
|
+
bottom: false,
|
|
30
|
+
right: false
|
|
31
|
+
}, {
|
|
32
|
+
id: 'top',
|
|
33
|
+
left: false,
|
|
34
|
+
top: true,
|
|
35
|
+
bottom: false,
|
|
36
|
+
right: false
|
|
37
|
+
}, {
|
|
38
|
+
id: 'top-right',
|
|
39
|
+
left: false,
|
|
40
|
+
top: true,
|
|
41
|
+
bottom: false,
|
|
42
|
+
right: true
|
|
43
|
+
}, {
|
|
44
|
+
id: 'right',
|
|
45
|
+
left: false,
|
|
46
|
+
top: false,
|
|
47
|
+
bottom: false,
|
|
48
|
+
right: true
|
|
49
|
+
}, {
|
|
50
|
+
id: 'bottom-right',
|
|
51
|
+
left: false,
|
|
52
|
+
top: false,
|
|
53
|
+
bottom: true,
|
|
54
|
+
right: true
|
|
55
|
+
}, {
|
|
56
|
+
id: 'bottom',
|
|
57
|
+
left: false,
|
|
58
|
+
top: false,
|
|
59
|
+
bottom: true,
|
|
60
|
+
right: false
|
|
61
|
+
}, {
|
|
62
|
+
id: 'bottom-left',
|
|
63
|
+
left: true,
|
|
64
|
+
top: false,
|
|
65
|
+
bottom: true,
|
|
66
|
+
right: false
|
|
67
|
+
}, {
|
|
68
|
+
id: 'left',
|
|
69
|
+
left: true,
|
|
70
|
+
top: false,
|
|
71
|
+
bottom: false,
|
|
72
|
+
right: false
|
|
73
|
+
}];
|
|
74
|
+
export const resizeHandlesMap = new Map(resizeHandles.map(handle => [handle.id, handle]));
|
|
75
|
+
export function getHtmlElement(anchorEl) {
|
|
76
|
+
if (typeof anchorEl === 'function') {
|
|
77
|
+
return anchorEl();
|
|
78
|
+
}
|
|
79
|
+
if (anchorEl?.ref?.current) {
|
|
80
|
+
return anchorEl.ref.current;
|
|
81
|
+
}
|
|
82
|
+
if (anchorEl?.current) {
|
|
83
|
+
return anchorEl.current;
|
|
84
|
+
}
|
|
85
|
+
return anchorEl;
|
|
86
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React, { HTMLAttributes } from 'react';
|
|
2
|
+
import { DraggableEvent } from './types';
|
|
3
|
+
export type DraggableAreaProps = {
|
|
4
|
+
areaId: string;
|
|
5
|
+
className: string;
|
|
6
|
+
onDragStart?: (event: DraggableEvent) => void;
|
|
7
|
+
onDrag: (event: DraggableEvent) => void;
|
|
8
|
+
onDragEnd?: (event: DraggableEvent | string) => void;
|
|
9
|
+
children?: React.ReactNode;
|
|
10
|
+
testId?: string;
|
|
11
|
+
} & Omit<HTMLAttributes<HTMLDivElement>, 'onDragEnd' | 'onDrag' | 'onDragStart'>;
|
|
12
|
+
export declare function DraggableArea({ areaId, testId, className, onDragStart, onDrag, onDragEnd, children, ...props }: DraggableAreaProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
export function DraggableArea({
|
|
4
|
+
areaId,
|
|
5
|
+
testId,
|
|
6
|
+
className,
|
|
7
|
+
onDragStart = () => {},
|
|
8
|
+
onDrag,
|
|
9
|
+
onDragEnd = () => {},
|
|
10
|
+
children = null,
|
|
11
|
+
...props
|
|
12
|
+
}) {
|
|
13
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
14
|
+
const onStart = useCallback(e => {
|
|
15
|
+
const draggableEvent = Object.assign(e, {
|
|
16
|
+
areaId
|
|
17
|
+
});
|
|
18
|
+
e.preventDefault();
|
|
19
|
+
setIsDragging(true);
|
|
20
|
+
onDragStart(draggableEvent);
|
|
21
|
+
}, []);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!isDragging) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
function onDragHandler(e) {
|
|
27
|
+
const draggableEvent = Object.assign(e, {
|
|
28
|
+
areaId
|
|
29
|
+
});
|
|
30
|
+
e.preventDefault();
|
|
31
|
+
onDrag(draggableEvent);
|
|
32
|
+
}
|
|
33
|
+
function onDragEndHandler(e) {
|
|
34
|
+
const draggableEvent = Object.assign(e, {
|
|
35
|
+
areaId
|
|
36
|
+
});
|
|
37
|
+
e.preventDefault();
|
|
38
|
+
removeListeners();
|
|
39
|
+
setIsDragging(false);
|
|
40
|
+
onDragEnd(draggableEvent);
|
|
41
|
+
}
|
|
42
|
+
function onDragBlurHandler() {
|
|
43
|
+
setIsDragging(false);
|
|
44
|
+
onDragEnd(areaId);
|
|
45
|
+
removeListeners();
|
|
46
|
+
}
|
|
47
|
+
window.addEventListener('mousemove', onDragHandler);
|
|
48
|
+
window.addEventListener('mouseup', onDragEndHandler);
|
|
49
|
+
window.addEventListener('blur', onDragBlurHandler);
|
|
50
|
+
function removeListeners() {
|
|
51
|
+
window.removeEventListener('mousemove', onDragHandler);
|
|
52
|
+
window.removeEventListener('mouseup', onDragEndHandler);
|
|
53
|
+
window.removeEventListener('blur', onDragBlurHandler);
|
|
54
|
+
}
|
|
55
|
+
return removeListeners;
|
|
56
|
+
}, [isDragging, onDragStart, onDrag, onDragEnd, areaId]);
|
|
57
|
+
return /*#__PURE__*/_jsx("div", {
|
|
58
|
+
className: className,
|
|
59
|
+
onMouseDown: onStart,
|
|
60
|
+
"test-id": testId,
|
|
61
|
+
role: "none",
|
|
62
|
+
...props,
|
|
63
|
+
children: children
|
|
64
|
+
});
|
|
65
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { faThumbtackSlash } from '@fortawesome/pro-solid-svg-icons/faThumbtackSlash';
|
|
3
|
+
import { faThumbtack } from '@fortawesome/free-solid-svg-icons/faThumbtack';
|
|
4
|
+
import { Button, ACCENT_TYPES } from '../button';
|
|
5
|
+
import { useTranslation } from '../hooks';
|
|
6
|
+
import { FontAwesomeIcon } from '../font-awesome-icon';
|
|
7
|
+
import { TOOLTIP_PLACEMENT_TYPES } from '../tooltip';
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
export function FloatingPanelDockButton({
|
|
10
|
+
isDocked,
|
|
11
|
+
setIsDocked
|
|
12
|
+
}) {
|
|
13
|
+
const {
|
|
14
|
+
t
|
|
15
|
+
} = useTranslation();
|
|
16
|
+
const ariaLabel = isDocked ? t('Unlock from sidebar') : t('Dock to sidebar');
|
|
17
|
+
return /*#__PURE__*/_jsx(Button, {
|
|
18
|
+
testId: "floating-panel-dock-button",
|
|
19
|
+
accentType: ACCENT_TYPES.ROUND_ICON,
|
|
20
|
+
onClick: () => setIsDocked(!isDocked),
|
|
21
|
+
"aria-label": ariaLabel,
|
|
22
|
+
tooltipText: ariaLabel,
|
|
23
|
+
tooltipPlacement: TOOLTIP_PLACEMENT_TYPES.TOP,
|
|
24
|
+
children: isDocked ? /*#__PURE__*/_jsx(FontAwesomeIcon, {
|
|
25
|
+
icon: faThumbtackSlash
|
|
26
|
+
}) : /*#__PURE__*/_jsx(FontAwesomeIcon, {
|
|
27
|
+
icon: faThumbtack
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
}
|