@vuu-ui/vuu-layout 0.5.4 → 0.5.5
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/README.md +1 -0
- package/cjs/index.js +4 -7379
- package/cjs/index.js.map +7 -0
- package/esm/index.js +20 -0
- package/esm/index.js.map +7 -0
- package/index.css +1 -951
- package/index.css.map +3 -3
- package/package.json +6 -9
- package/src/Component.css +0 -2
- package/src/Component.tsx +0 -20
- package/src/DraggableLayout.css +0 -18
- package/src/DraggableLayout.tsx +0 -29
- package/src/__tests__/flexbox-utils.spec.js +0 -90
- package/src/action-buttons/index.ts +0 -1
- package/src/chest-of-drawers/Chest.css +0 -36
- package/src/chest-of-drawers/Chest.tsx +0 -42
- package/src/chest-of-drawers/Drawer.css +0 -159
- package/src/chest-of-drawers/Drawer.tsx +0 -118
- package/src/chest-of-drawers/index.ts +0 -2
- package/src/common-types.ts +0 -9
- package/src/debug.ts +0 -16
- package/src/dialog/Dialog.css +0 -16
- package/src/dialog/Dialog.tsx +0 -59
- package/src/dialog/index.ts +0 -1
- package/src/drag-drop/BoxModel.ts +0 -546
- package/src/drag-drop/DragState.ts +0 -222
- package/src/drag-drop/Draggable.ts +0 -282
- package/src/drag-drop/DropMenu.css +0 -71
- package/src/drag-drop/DropMenu.tsx +0 -61
- package/src/drag-drop/DropTarget.ts +0 -392
- package/src/drag-drop/DropTargetRenderer.css +0 -40
- package/src/drag-drop/DropTargetRenderer.tsx +0 -279
- package/src/drag-drop/dragDropTypes.ts +0 -49
- package/src/drag-drop/index.ts +0 -4
- package/src/editable-label/EditableLabel.css +0 -28
- package/src/editable-label/EditableLabel.tsx +0 -99
- package/src/editable-label/index.ts +0 -1
- package/src/flexbox/Flexbox.css +0 -45
- package/src/flexbox/Flexbox.tsx +0 -70
- package/src/flexbox/FlexboxLayout.jsx +0 -26
- package/src/flexbox/FluidGrid.css +0 -134
- package/src/flexbox/FluidGrid.tsx +0 -84
- package/src/flexbox/FluidGridLayout.tsx +0 -10
- package/src/flexbox/Splitter.css +0 -140
- package/src/flexbox/Splitter.tsx +0 -135
- package/src/flexbox/flexbox-utils.ts +0 -128
- package/src/flexbox/flexboxTypes.ts +0 -63
- package/src/flexbox/index.ts +0 -4
- package/src/flexbox/useResponsiveSizing.ts +0 -85
- package/src/flexbox/useSplitterResizing.ts +0 -272
- package/src/index.ts +0 -21
- package/src/layout-action.ts +0 -21
- package/src/layout-header/ActionButton.tsx +0 -23
- package/src/layout-header/Header.css +0 -8
- package/src/layout-header/Header.tsx +0 -222
- package/src/layout-header/index.ts +0 -1
- package/src/layout-provider/LayoutProvider.tsx +0 -160
- package/src/layout-provider/LayoutProviderContext.ts +0 -17
- package/src/layout-provider/index.ts +0 -2
- package/src/layout-provider/useLayoutDragDrop.ts +0 -241
- package/src/layout-reducer/flexUtils.ts +0 -281
- package/src/layout-reducer/index.ts +0 -4
- package/src/layout-reducer/insert-layout-element.ts +0 -365
- package/src/layout-reducer/layout-reducer.ts +0 -255
- package/src/layout-reducer/layoutTypes.ts +0 -151
- package/src/layout-reducer/layoutUtils.ts +0 -302
- package/src/layout-reducer/remove-layout-element.ts +0 -240
- package/src/layout-reducer/replace-layout-element.ts +0 -118
- package/src/layout-reducer/resize-flex-children.ts +0 -56
- package/src/layout-reducer/wrap-layout-element.ts +0 -317
- package/src/layout-view/View.css +0 -61
- package/src/layout-view/View.tsx +0 -149
- package/src/layout-view/ViewContext.ts +0 -31
- package/src/layout-view/index.ts +0 -4
- package/src/layout-view/useView.tsx +0 -104
- package/src/layout-view/useViewActionDispatcher.ts +0 -133
- package/src/layout-view/useViewResize.ts +0 -53
- package/src/layout-view/viewTypes.ts +0 -37
- package/src/menu/ContextMenu.css +0 -22
- package/src/menu/ContextMenu.jsx +0 -121
- package/src/menu/MenuList.css +0 -150
- package/src/menu/MenuList.jsx +0 -179
- package/src/menu/aim/aim.js +0 -92
- package/src/menu/aim/corners.js +0 -114
- package/src/menu/aim/point-in-polygon.js +0 -25
- package/src/menu/aim/utils.js +0 -19
- package/src/menu/context-menu-provider.jsx +0 -135
- package/src/menu/index.js +0 -4
- package/src/menu/key-code.js +0 -61
- package/src/menu/list-dom-utils.js +0 -22
- package/src/menu/use-cascade.js +0 -292
- package/src/menu/use-click-away.js +0 -22
- package/src/menu/use-items-with-ids.js +0 -75
- package/src/menu/use-keyboard-navigation.js +0 -162
- package/src/menu/utils.js +0 -5
- package/src/palette/Palette.css +0 -37
- package/src/palette/Palette.tsx +0 -140
- package/src/palette/PaletteSalt.css +0 -9
- package/src/palette/PaletteSalt.tsx +0 -79
- package/src/palette/index.ts +0 -2
- package/src/placeholder/Placeholder.css +0 -10
- package/src/placeholder/Placeholder.tsx +0 -39
- package/src/placeholder/index.ts +0 -1
- package/src/popup/index.js +0 -2
- package/src/popup/popup-provider.js +0 -0
- package/src/popup/popup-service.css +0 -15
- package/src/popup/popup-service.js +0 -281
- package/src/portal/Portal.jsx +0 -50
- package/src/portal/index.ts +0 -3
- package/src/portal/render-portal.jsx +0 -68
- package/src/portal/utils.js +0 -16
- package/src/registry/ComponentRegistry.ts +0 -35
- package/src/registry/index.ts +0 -1
- package/src/responsive/OverflowMenu.css +0 -31
- package/src/responsive/OverflowMenu.jsx +0 -56
- package/src/responsive/breakpoints.ts +0 -62
- package/src/responsive/index.ts +0 -4
- package/src/responsive/measureMinimumNodeSize.ts +0 -23
- package/src/responsive/overflowUtils.js +0 -14
- package/src/responsive/use-breakpoints.ts +0 -100
- package/src/responsive/useOverflowObserver.ts +0 -606
- package/src/responsive/useResizeObserver.ts +0 -154
- package/src/responsive/utils.ts +0 -37
- package/src/stack/Stack.css +0 -39
- package/src/stack/Stack.tsx +0 -161
- package/src/stack/StackLayout.tsx +0 -137
- package/src/stack/index.ts +0 -3
- package/src/stack/stackTypes.ts +0 -19
- package/src/tabs/TabPanel.css +0 -12
- package/src/tabs/TabPanel.tsx +0 -17
- package/src/tabs/index.ts +0 -1
- package/src/tools/config-wrapper/ConfigWrapper.jsx +0 -53
- package/src/tools/config-wrapper/index.js +0 -1
- package/src/tools/devtools-box/layout-configurator.css +0 -112
- package/src/tools/devtools-box/layout-configurator.jsx +0 -369
- package/src/tools/devtools-tree/layout-tree-viewer.css +0 -15
- package/src/tools/devtools-tree/layout-tree-viewer.jsx +0 -36
- package/src/tools/index.js +0 -3
- package/src/use-persistent-state.ts +0 -115
- package/src/utils/apply-handlers.js +0 -15
- package/src/utils/componentFromLayout.tsx +0 -30
- package/src/utils/index.ts +0 -6
- package/src/utils/pathUtils.ts +0 -294
- package/src/utils/propUtils.ts +0 -24
- package/src/utils/refUtils.ts +0 -16
- package/src/utils/styleUtils.ts +0 -14
- package/src/utils/typeOf.ts +0 -22
package/src/menu/aim/aim.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import findCorners, { boundaries } from './corners';
|
|
2
|
-
import pointInPolygon from './point-in-polygon';
|
|
3
|
-
|
|
4
|
-
export function distance(source, target) {
|
|
5
|
-
const a = source.x - target.x;
|
|
6
|
-
const b = source.y - target.y;
|
|
7
|
-
return Math.sqrt(a * a + b * b);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function side(corners) {
|
|
11
|
-
if (corners[0] === 'top-right' && corners[1] === 'bottom-right') return 'right';
|
|
12
|
-
else if (corners[0] === 'top-left' && corners[1] === 'bottom-right') return 'top-right';
|
|
13
|
-
else if (corners[0] === 'top-left' && corners[1] === 'top-right') return 'top';
|
|
14
|
-
else if (corners[0] === 'bottom-left' && corners[1] === 'top-right') return 'top-left';
|
|
15
|
-
else if (corners[0] === 'bottom-left' && corners[1] === 'top-left') return 'left';
|
|
16
|
-
else if (corners[0] === 'bottom-right' && corners[1] === 'top-left') return 'bottom-left';
|
|
17
|
-
else if (corners[0] === 'bottom-right' && corners[1] === 'bottom-left') return 'bottom';
|
|
18
|
-
else if (corners[0] === 'top-right' && corners[1] === 'bottom-left') return 'bottom-right';
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function bullseye(corners, boundaries, mousePosition) {
|
|
22
|
-
switch (side(corners)) {
|
|
23
|
-
case 'right':
|
|
24
|
-
return {
|
|
25
|
-
x: boundaries[0].x,
|
|
26
|
-
y: mousePosition.y
|
|
27
|
-
};
|
|
28
|
-
case 'top-right':
|
|
29
|
-
return {
|
|
30
|
-
x: boundaries[1].x,
|
|
31
|
-
y: boundaries[0].y
|
|
32
|
-
};
|
|
33
|
-
case 'top':
|
|
34
|
-
return {
|
|
35
|
-
x: mousePosition.x,
|
|
36
|
-
y: boundaries[0].y
|
|
37
|
-
};
|
|
38
|
-
case 'top-left':
|
|
39
|
-
return {
|
|
40
|
-
x: boundaries[0].x,
|
|
41
|
-
y: boundaries[1].y
|
|
42
|
-
};
|
|
43
|
-
case 'left':
|
|
44
|
-
return {
|
|
45
|
-
x: boundaries[0].x,
|
|
46
|
-
y: mousePosition.y
|
|
47
|
-
};
|
|
48
|
-
case 'bottom-left':
|
|
49
|
-
return {
|
|
50
|
-
x: boundaries[1].x,
|
|
51
|
-
y: boundaries[0].y
|
|
52
|
-
};
|
|
53
|
-
case 'bottom':
|
|
54
|
-
return {
|
|
55
|
-
x: mousePosition.x,
|
|
56
|
-
y: boundaries[0].y
|
|
57
|
-
};
|
|
58
|
-
case 'bottom-right':
|
|
59
|
-
return {
|
|
60
|
-
x: boundaries[0].x,
|
|
61
|
-
y: boundaries[1].y
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function formatPoints(points) {
|
|
67
|
-
const finalPoints = [];
|
|
68
|
-
for (let i = 0, len = points.length; i < len; ++i) {
|
|
69
|
-
finalPoints.push([points[i].x, points[i].y]);
|
|
70
|
-
}
|
|
71
|
-
return finalPoints;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function aiming(e, mousePosition, prevMousePosition, target, alreadyAiming) {
|
|
75
|
-
if (!prevMousePosition) return false;
|
|
76
|
-
else if (
|
|
77
|
-
!alreadyAiming &&
|
|
78
|
-
mousePosition.x === prevMousePosition.x &&
|
|
79
|
-
mousePosition.y === prevMousePosition.y
|
|
80
|
-
) {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const corners = findCorners(e, target);
|
|
85
|
-
const bound = boundaries(corners, prevMousePosition, target);
|
|
86
|
-
|
|
87
|
-
if (pointInPolygon([mousePosition.x, mousePosition.y], formatPoints(bound))) {
|
|
88
|
-
const dist = Math.round(distance(mousePosition, bullseye(corners, bound, mousePosition)));
|
|
89
|
-
return Math.max(dist, 1);
|
|
90
|
-
}
|
|
91
|
-
return false;
|
|
92
|
-
}
|
package/src/menu/aim/corners.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { distance, bullseye } from './aim';
|
|
2
|
-
|
|
3
|
-
function inside(source, targetMin, targetMax) {
|
|
4
|
-
if (source >= targetMin && source <= targetMax) return 0;
|
|
5
|
-
else if (source > targetMin) return -1;
|
|
6
|
-
else return 1;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function corners(source, target) {
|
|
10
|
-
source = { left: source.pageX, top: source.pageY };
|
|
11
|
-
target = target.getBoundingClientRect();
|
|
12
|
-
|
|
13
|
-
let ver, hor;
|
|
14
|
-
|
|
15
|
-
hor = inside(source.left, target.left, target.left + target.width);
|
|
16
|
-
ver = inside(source.top, target.top, source.top + target.height);
|
|
17
|
-
|
|
18
|
-
if (hor === -1 && ver === -1) return ['top-right', 'bottom-left'];
|
|
19
|
-
if (hor === -1 && ver === 0) return ['top-right', 'bottom-right'];
|
|
20
|
-
if (hor === -1 && ver === 1) return ['top-left', 'bottom-right'];
|
|
21
|
-
|
|
22
|
-
if (hor === 0 && ver === -1) return ['bottom-right', 'bottom-left'];
|
|
23
|
-
if (hor === 0 && ver === 0) return [];
|
|
24
|
-
if (hor === 0 && ver === 1) return ['top-left', 'top-right'];
|
|
25
|
-
|
|
26
|
-
if (hor === 1 && ver === -1) return ['bottom-right', 'top-left'];
|
|
27
|
-
if (hor === 1 && ver === 0) return ['bottom-left', 'top-left'];
|
|
28
|
-
if (hor === 1 && ver === 1) return ['bottom-left', 'top-right'];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function boundaries(corners, source, target, adjustment = false) {
|
|
32
|
-
if (target instanceof HTMLElement || target instanceof SVGElement) {
|
|
33
|
-
target = target.getBoundingClientRect();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (!source) return [];
|
|
37
|
-
else if (source instanceof Event) {
|
|
38
|
-
source = {
|
|
39
|
-
left: source.pageX,
|
|
40
|
-
top: source.pageY
|
|
41
|
-
};
|
|
42
|
-
} else if (source.x) {
|
|
43
|
-
source = {
|
|
44
|
-
left: source.x,
|
|
45
|
-
top: source.y
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
let tolerance = adjustment !== false ? Math.round(adjustment / 10) * 1.5 : 0;
|
|
50
|
-
const position = {
|
|
51
|
-
left: target.left - tolerance,
|
|
52
|
-
top: target.top - tolerance,
|
|
53
|
-
width: target.width + tolerance * 2,
|
|
54
|
-
height: target.height + tolerance * 2
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
var doc = document.documentElement;
|
|
58
|
-
var left = (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0);
|
|
59
|
-
var top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
|
|
60
|
-
|
|
61
|
-
let first = true;
|
|
62
|
-
let positions = [];
|
|
63
|
-
corners.forEach((corner) => {
|
|
64
|
-
switch (corner) {
|
|
65
|
-
case 'top-right':
|
|
66
|
-
if (first) positions.push({ x: target.left + target.width + left, y: target.top + top });
|
|
67
|
-
positions.push({ x: position.left + position.width + left, y: position.top + top });
|
|
68
|
-
if (!first) positions.push({ x: target.left + target.width + left, y: target.top + top });
|
|
69
|
-
break;
|
|
70
|
-
case 'top-left':
|
|
71
|
-
if (first) positions.push({ x: target.left + left, y: target.top + top });
|
|
72
|
-
positions.push({ x: position.left + left, y: position.top + top });
|
|
73
|
-
if (!first) positions.push({ x: target.left + left, y: target.top + top });
|
|
74
|
-
break;
|
|
75
|
-
case 'bottom-right':
|
|
76
|
-
if (first)
|
|
77
|
-
positions.push({
|
|
78
|
-
x: target.left + target.width + left,
|
|
79
|
-
y: target.top + target.height + top
|
|
80
|
-
});
|
|
81
|
-
positions.push({
|
|
82
|
-
x: position.left + position.width + left,
|
|
83
|
-
y: position.top + position.height + top
|
|
84
|
-
});
|
|
85
|
-
if (!first)
|
|
86
|
-
positions.push({
|
|
87
|
-
x: target.left + target.width + left,
|
|
88
|
-
y: target.top + target.height + top
|
|
89
|
-
});
|
|
90
|
-
break;
|
|
91
|
-
case 'bottom-left':
|
|
92
|
-
if (first) positions.push({ x: target.left + left, y: target.top + target.height + top });
|
|
93
|
-
positions.push({ x: position.left + left, y: position.top + position.height + top });
|
|
94
|
-
if (!first) positions.push({ x: target.left + left, y: target.top + target.height + top });
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
97
|
-
if (first) {
|
|
98
|
-
positions.push({ x: source.left, y: source.top });
|
|
99
|
-
}
|
|
100
|
-
first = false;
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
if (adjustment === false) {
|
|
104
|
-
const be = bullseye(corners, positions, { x: source.left, y: source.top });
|
|
105
|
-
if (be) {
|
|
106
|
-
const dist = Math.round(distance({ x: source.left, y: source.top }, be));
|
|
107
|
-
return boundaries(corners, source, target, dist);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return positions;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export default corners;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license MIT
|
|
3
|
-
* @url https://github.com/substack/point-in-polygon
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export default function (point, vs) {
|
|
7
|
-
// ray-casting algorithm based on
|
|
8
|
-
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
|
9
|
-
|
|
10
|
-
var x = point[0],
|
|
11
|
-
y = point[1];
|
|
12
|
-
|
|
13
|
-
var inside = false;
|
|
14
|
-
for (var i = 0, j = vs.length - 1; i < vs.length; j = i++) {
|
|
15
|
-
var xi = vs[i][0],
|
|
16
|
-
yi = vs[i][1];
|
|
17
|
-
var xj = vs[j][0],
|
|
18
|
-
yj = vs[j][1];
|
|
19
|
-
|
|
20
|
-
var intersect = yi > y != yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi;
|
|
21
|
-
if (intersect) inside = !inside;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return inside;
|
|
25
|
-
}
|
package/src/menu/aim/utils.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
function scrollPosition() {
|
|
2
|
-
const scrollTop = document.documentElement.scrollTop
|
|
3
|
-
? document.documentElement.scrollTop
|
|
4
|
-
: document.body.scrollTop;
|
|
5
|
-
const scrollLeft = document.documentElement.scrollLeft
|
|
6
|
-
? document.documentElement.scrollLeft
|
|
7
|
-
: document.body.scrollLeft;
|
|
8
|
-
|
|
9
|
-
return { scrollTop, scrollLeft };
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function mousePosition(event) {
|
|
13
|
-
const sPos = scrollPosition();
|
|
14
|
-
|
|
15
|
-
const x = document.all ? event.clientX + sPos.scrollLeft : event.pageX;
|
|
16
|
-
const y = document.all ? event.clientY + sPos.scrollTop : event.pageY;
|
|
17
|
-
|
|
18
|
-
return { x, y };
|
|
19
|
-
}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import React, { useCallback, useContext, useMemo } from 'react';
|
|
2
|
-
import { PopupService } from '../popup';
|
|
3
|
-
import ContextMenu from './ContextMenu';
|
|
4
|
-
import { MenuItem, MenuItemGroup } from './MenuList';
|
|
5
|
-
|
|
6
|
-
const showContextMenu = (e, menuDescriptors, handleContextMenuAction) => {
|
|
7
|
-
const { clientX: left, clientY: top } = e;
|
|
8
|
-
const menuItems = (menuDescriptors) => {
|
|
9
|
-
const fromDescriptor = ({ children, label, icon, action, options }, i) =>
|
|
10
|
-
children ? (
|
|
11
|
-
<MenuItemGroup key={i} label={label}>
|
|
12
|
-
{children.map(fromDescriptor)}
|
|
13
|
-
</MenuItemGroup>
|
|
14
|
-
) : (
|
|
15
|
-
<MenuItem key={i} action={action} data-icon={icon} options={options}>
|
|
16
|
-
{label}
|
|
17
|
-
</MenuItem>
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
return menuDescriptors.map(fromDescriptor);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const handleClose = (menuId, options) => {
|
|
24
|
-
if (menuId) {
|
|
25
|
-
handleContextMenuAction(menuId, options);
|
|
26
|
-
PopupService.hidePopup();
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const component = (
|
|
31
|
-
<ContextMenu onClose={handleClose} position={{ x: left, y: top }}>
|
|
32
|
-
{menuItems(menuDescriptors)}
|
|
33
|
-
</ContextMenu>
|
|
34
|
-
);
|
|
35
|
-
PopupService.showPopup({ left: 0, top: 0, component });
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const ContextMenuContext = React.createContext(null);
|
|
39
|
-
|
|
40
|
-
const NO_INHERITED_CONTEXT = {
|
|
41
|
-
menuItemDescriptors: []
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
// The menuBuilder will always be supplied by the code that will display the local
|
|
45
|
-
// context menu. It will be passed all configured menu descriptors. It is free to
|
|
46
|
-
// augment, replace or ignore the existing menu descriptors.
|
|
47
|
-
export const useContextMenu = () => {
|
|
48
|
-
const { menuActionHandler, menuBuilders } = useContext(ContextMenuContext);
|
|
49
|
-
|
|
50
|
-
const buildMenuOptions = useCallback((menuBuilders, location, options) => {
|
|
51
|
-
let results = [];
|
|
52
|
-
for (const menuBuilder of menuBuilders) {
|
|
53
|
-
// Maybe we should leave the concatenation to the menuBuilder, then it can control menuItem order
|
|
54
|
-
results = results.concat(menuBuilder(location, options));
|
|
55
|
-
}
|
|
56
|
-
return results;
|
|
57
|
-
}, []);
|
|
58
|
-
|
|
59
|
-
const handleShowContextMenu = (e, location, options) => {
|
|
60
|
-
e.stopPropagation();
|
|
61
|
-
e.preventDefault();
|
|
62
|
-
const menuItemDescriptors = buildMenuOptions(menuBuilders, location, options);
|
|
63
|
-
if (menuItemDescriptors.length) {
|
|
64
|
-
showContextMenu(e, menuItemDescriptors, menuActionHandler);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
return handleShowContextMenu;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const Provider = ({
|
|
72
|
-
children,
|
|
73
|
-
context: { menuBuilders: inheritedMenuBuilders, menuActionHandler: inheritedMenuActionHandler },
|
|
74
|
-
menuActionHandler,
|
|
75
|
-
menuBuilder
|
|
76
|
-
}) => {
|
|
77
|
-
const menuBuilders = useMemo(() => {
|
|
78
|
-
if (inheritedMenuBuilders && menuBuilder) {
|
|
79
|
-
return inheritedMenuBuilders.concat(menuBuilder);
|
|
80
|
-
} else if (menuBuilder) {
|
|
81
|
-
return [menuBuilder];
|
|
82
|
-
} else {
|
|
83
|
-
return inheritedMenuBuilders || [];
|
|
84
|
-
}
|
|
85
|
-
}, [inheritedMenuBuilders, menuBuilder]);
|
|
86
|
-
|
|
87
|
-
const handleMenuAction = useCallback(
|
|
88
|
-
(type, options) => {
|
|
89
|
-
if (menuActionHandler && menuActionHandler(type, options)) {
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (inheritedMenuActionHandler && inheritedMenuActionHandler(type, options)) {
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
[inheritedMenuActionHandler, menuActionHandler]
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
return (
|
|
101
|
-
<ContextMenuContext.Provider
|
|
102
|
-
value={{
|
|
103
|
-
menuActionHandler: handleMenuAction,
|
|
104
|
-
menuBuilders
|
|
105
|
-
}}
|
|
106
|
-
>
|
|
107
|
-
{children}
|
|
108
|
-
</ContextMenuContext.Provider>
|
|
109
|
-
);
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
// Need an option for local menu to override higher-level menu, rather than extend
|
|
113
|
-
export const ContextMenuProvider = ({
|
|
114
|
-
children,
|
|
115
|
-
menuActionHandler,
|
|
116
|
-
menuBuilder,
|
|
117
|
-
menuItemDescriptors,
|
|
118
|
-
label
|
|
119
|
-
}) => {
|
|
120
|
-
return (
|
|
121
|
-
<ContextMenuContext.Consumer>
|
|
122
|
-
{(parentContext) => (
|
|
123
|
-
<Provider
|
|
124
|
-
context={parentContext || NO_INHERITED_CONTEXT}
|
|
125
|
-
label={label}
|
|
126
|
-
menuActionHandler={menuActionHandler}
|
|
127
|
-
menuBuilder={menuBuilder}
|
|
128
|
-
menuItemDescriptors={menuItemDescriptors}
|
|
129
|
-
>
|
|
130
|
-
{children}
|
|
131
|
-
</Provider>
|
|
132
|
-
)}
|
|
133
|
-
</ContextMenuContext.Consumer>
|
|
134
|
-
);
|
|
135
|
-
};
|
package/src/menu/index.js
DELETED
package/src/menu/key-code.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
function union(set1, ...sets) {
|
|
2
|
-
const result = new Set(set1);
|
|
3
|
-
for (let set of sets) {
|
|
4
|
-
for (let element of set) {
|
|
5
|
-
result.add(element);
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
return result;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const ArrowUp = 'ArrowUp';
|
|
12
|
-
export const ArrowDown = 'ArrowDown';
|
|
13
|
-
export const ArrowLeft = 'ArrowLeft';
|
|
14
|
-
export const Backspace = 'Backspace';
|
|
15
|
-
export const ArrowRight = 'ArrowRight';
|
|
16
|
-
export const Enter = 'Enter';
|
|
17
|
-
export const Escape = 'Escape';
|
|
18
|
-
export const Delete = 'Delete';
|
|
19
|
-
|
|
20
|
-
const actionKeys = new Set([Enter, Delete]);
|
|
21
|
-
const focusKeys = new Set(['Tab']);
|
|
22
|
-
// const navigationKeys = new Set(["Home", "End", "ArrowRight", "ArrowLeft","ArrowDown", "ArrowUp"]);
|
|
23
|
-
const arrowLeftRightKeys = new Set(['ArrowRight', 'ArrowLeft']);
|
|
24
|
-
const verticalNavigationKeys = new Set(['Home', 'End', 'ArrowDown', 'ArrowUp']);
|
|
25
|
-
const horizontalNavigationKeys = new Set(['Home', 'End', 'ArrowRight', 'ArrowLeft']);
|
|
26
|
-
const functionKeys = new Set([
|
|
27
|
-
'F1',
|
|
28
|
-
'F2',
|
|
29
|
-
'F3',
|
|
30
|
-
'F4',
|
|
31
|
-
'F5',
|
|
32
|
-
'F6',
|
|
33
|
-
'F7',
|
|
34
|
-
'F8',
|
|
35
|
-
'F9',
|
|
36
|
-
'F10',
|
|
37
|
-
'F11',
|
|
38
|
-
'F12'
|
|
39
|
-
]);
|
|
40
|
-
const specialKeys = union(
|
|
41
|
-
actionKeys,
|
|
42
|
-
horizontalNavigationKeys,
|
|
43
|
-
verticalNavigationKeys,
|
|
44
|
-
arrowLeftRightKeys,
|
|
45
|
-
functionKeys,
|
|
46
|
-
focusKeys
|
|
47
|
-
);
|
|
48
|
-
export const isCharacterKey = (evt) => {
|
|
49
|
-
if (specialKeys.has(evt.key)) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
if (typeof evt.which === 'number' && evt.which > 0) {
|
|
53
|
-
return !evt.ctrlKey && !evt.metaKey && !evt.altKey && evt.which !== 8;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export const isNavigationKey = ({ key }, orientation = 'vertical') => {
|
|
58
|
-
const navigationKeys =
|
|
59
|
-
orientation === 'vertical' ? verticalNavigationKeys : horizontalNavigationKeys;
|
|
60
|
-
return navigationKeys.has(key);
|
|
61
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export const listItemElement = (listEl, listItemIdx) =>
|
|
2
|
-
listEl.querySelector(`:scope > [data-idx="${listItemIdx}"]`);
|
|
3
|
-
|
|
4
|
-
export function listItemIndex(listItemEl) {
|
|
5
|
-
if (listItemEl) {
|
|
6
|
-
let idx = listItemEl.dataset.idx;
|
|
7
|
-
if (idx) {
|
|
8
|
-
return parseInt(idx, 10);
|
|
9
|
-
// eslint-disable-next-line no-cond-assign
|
|
10
|
-
} else if ((idx = listItemEl.ariaPosInSet)) {
|
|
11
|
-
return parseInt(idx, 10) - 1;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const listItemId = (el) => el?.id;
|
|
17
|
-
|
|
18
|
-
export const closestListItem = (el) => el.closest('[data-idx],[aria-posinset]');
|
|
19
|
-
|
|
20
|
-
export const closestListItemId = (el) => listItemId(closestListItem(el));
|
|
21
|
-
|
|
22
|
-
export const closestListItemIndex = (el) => listItemIndex(closestListItem(el));
|