@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.
Files changed (147) hide show
  1. package/README.md +1 -0
  2. package/cjs/index.js +4 -7379
  3. package/cjs/index.js.map +7 -0
  4. package/esm/index.js +20 -0
  5. package/esm/index.js.map +7 -0
  6. package/index.css +1 -951
  7. package/index.css.map +3 -3
  8. package/package.json +6 -9
  9. package/src/Component.css +0 -2
  10. package/src/Component.tsx +0 -20
  11. package/src/DraggableLayout.css +0 -18
  12. package/src/DraggableLayout.tsx +0 -29
  13. package/src/__tests__/flexbox-utils.spec.js +0 -90
  14. package/src/action-buttons/index.ts +0 -1
  15. package/src/chest-of-drawers/Chest.css +0 -36
  16. package/src/chest-of-drawers/Chest.tsx +0 -42
  17. package/src/chest-of-drawers/Drawer.css +0 -159
  18. package/src/chest-of-drawers/Drawer.tsx +0 -118
  19. package/src/chest-of-drawers/index.ts +0 -2
  20. package/src/common-types.ts +0 -9
  21. package/src/debug.ts +0 -16
  22. package/src/dialog/Dialog.css +0 -16
  23. package/src/dialog/Dialog.tsx +0 -59
  24. package/src/dialog/index.ts +0 -1
  25. package/src/drag-drop/BoxModel.ts +0 -546
  26. package/src/drag-drop/DragState.ts +0 -222
  27. package/src/drag-drop/Draggable.ts +0 -282
  28. package/src/drag-drop/DropMenu.css +0 -71
  29. package/src/drag-drop/DropMenu.tsx +0 -61
  30. package/src/drag-drop/DropTarget.ts +0 -392
  31. package/src/drag-drop/DropTargetRenderer.css +0 -40
  32. package/src/drag-drop/DropTargetRenderer.tsx +0 -279
  33. package/src/drag-drop/dragDropTypes.ts +0 -49
  34. package/src/drag-drop/index.ts +0 -4
  35. package/src/editable-label/EditableLabel.css +0 -28
  36. package/src/editable-label/EditableLabel.tsx +0 -99
  37. package/src/editable-label/index.ts +0 -1
  38. package/src/flexbox/Flexbox.css +0 -45
  39. package/src/flexbox/Flexbox.tsx +0 -70
  40. package/src/flexbox/FlexboxLayout.jsx +0 -26
  41. package/src/flexbox/FluidGrid.css +0 -134
  42. package/src/flexbox/FluidGrid.tsx +0 -84
  43. package/src/flexbox/FluidGridLayout.tsx +0 -10
  44. package/src/flexbox/Splitter.css +0 -140
  45. package/src/flexbox/Splitter.tsx +0 -135
  46. package/src/flexbox/flexbox-utils.ts +0 -128
  47. package/src/flexbox/flexboxTypes.ts +0 -63
  48. package/src/flexbox/index.ts +0 -4
  49. package/src/flexbox/useResponsiveSizing.ts +0 -85
  50. package/src/flexbox/useSplitterResizing.ts +0 -272
  51. package/src/index.ts +0 -21
  52. package/src/layout-action.ts +0 -21
  53. package/src/layout-header/ActionButton.tsx +0 -23
  54. package/src/layout-header/Header.css +0 -8
  55. package/src/layout-header/Header.tsx +0 -222
  56. package/src/layout-header/index.ts +0 -1
  57. package/src/layout-provider/LayoutProvider.tsx +0 -160
  58. package/src/layout-provider/LayoutProviderContext.ts +0 -17
  59. package/src/layout-provider/index.ts +0 -2
  60. package/src/layout-provider/useLayoutDragDrop.ts +0 -241
  61. package/src/layout-reducer/flexUtils.ts +0 -281
  62. package/src/layout-reducer/index.ts +0 -4
  63. package/src/layout-reducer/insert-layout-element.ts +0 -365
  64. package/src/layout-reducer/layout-reducer.ts +0 -255
  65. package/src/layout-reducer/layoutTypes.ts +0 -151
  66. package/src/layout-reducer/layoutUtils.ts +0 -302
  67. package/src/layout-reducer/remove-layout-element.ts +0 -240
  68. package/src/layout-reducer/replace-layout-element.ts +0 -118
  69. package/src/layout-reducer/resize-flex-children.ts +0 -56
  70. package/src/layout-reducer/wrap-layout-element.ts +0 -317
  71. package/src/layout-view/View.css +0 -61
  72. package/src/layout-view/View.tsx +0 -149
  73. package/src/layout-view/ViewContext.ts +0 -31
  74. package/src/layout-view/index.ts +0 -4
  75. package/src/layout-view/useView.tsx +0 -104
  76. package/src/layout-view/useViewActionDispatcher.ts +0 -133
  77. package/src/layout-view/useViewResize.ts +0 -53
  78. package/src/layout-view/viewTypes.ts +0 -37
  79. package/src/menu/ContextMenu.css +0 -22
  80. package/src/menu/ContextMenu.jsx +0 -121
  81. package/src/menu/MenuList.css +0 -150
  82. package/src/menu/MenuList.jsx +0 -179
  83. package/src/menu/aim/aim.js +0 -92
  84. package/src/menu/aim/corners.js +0 -114
  85. package/src/menu/aim/point-in-polygon.js +0 -25
  86. package/src/menu/aim/utils.js +0 -19
  87. package/src/menu/context-menu-provider.jsx +0 -135
  88. package/src/menu/index.js +0 -4
  89. package/src/menu/key-code.js +0 -61
  90. package/src/menu/list-dom-utils.js +0 -22
  91. package/src/menu/use-cascade.js +0 -292
  92. package/src/menu/use-click-away.js +0 -22
  93. package/src/menu/use-items-with-ids.js +0 -75
  94. package/src/menu/use-keyboard-navigation.js +0 -162
  95. package/src/menu/utils.js +0 -5
  96. package/src/palette/Palette.css +0 -37
  97. package/src/palette/Palette.tsx +0 -140
  98. package/src/palette/PaletteSalt.css +0 -9
  99. package/src/palette/PaletteSalt.tsx +0 -79
  100. package/src/palette/index.ts +0 -2
  101. package/src/placeholder/Placeholder.css +0 -10
  102. package/src/placeholder/Placeholder.tsx +0 -39
  103. package/src/placeholder/index.ts +0 -1
  104. package/src/popup/index.js +0 -2
  105. package/src/popup/popup-provider.js +0 -0
  106. package/src/popup/popup-service.css +0 -15
  107. package/src/popup/popup-service.js +0 -281
  108. package/src/portal/Portal.jsx +0 -50
  109. package/src/portal/index.ts +0 -3
  110. package/src/portal/render-portal.jsx +0 -68
  111. package/src/portal/utils.js +0 -16
  112. package/src/registry/ComponentRegistry.ts +0 -35
  113. package/src/registry/index.ts +0 -1
  114. package/src/responsive/OverflowMenu.css +0 -31
  115. package/src/responsive/OverflowMenu.jsx +0 -56
  116. package/src/responsive/breakpoints.ts +0 -62
  117. package/src/responsive/index.ts +0 -4
  118. package/src/responsive/measureMinimumNodeSize.ts +0 -23
  119. package/src/responsive/overflowUtils.js +0 -14
  120. package/src/responsive/use-breakpoints.ts +0 -100
  121. package/src/responsive/useOverflowObserver.ts +0 -606
  122. package/src/responsive/useResizeObserver.ts +0 -154
  123. package/src/responsive/utils.ts +0 -37
  124. package/src/stack/Stack.css +0 -39
  125. package/src/stack/Stack.tsx +0 -161
  126. package/src/stack/StackLayout.tsx +0 -137
  127. package/src/stack/index.ts +0 -3
  128. package/src/stack/stackTypes.ts +0 -19
  129. package/src/tabs/TabPanel.css +0 -12
  130. package/src/tabs/TabPanel.tsx +0 -17
  131. package/src/tabs/index.ts +0 -1
  132. package/src/tools/config-wrapper/ConfigWrapper.jsx +0 -53
  133. package/src/tools/config-wrapper/index.js +0 -1
  134. package/src/tools/devtools-box/layout-configurator.css +0 -112
  135. package/src/tools/devtools-box/layout-configurator.jsx +0 -369
  136. package/src/tools/devtools-tree/layout-tree-viewer.css +0 -15
  137. package/src/tools/devtools-tree/layout-tree-viewer.jsx +0 -36
  138. package/src/tools/index.js +0 -3
  139. package/src/use-persistent-state.ts +0 -115
  140. package/src/utils/apply-handlers.js +0 -15
  141. package/src/utils/componentFromLayout.tsx +0 -30
  142. package/src/utils/index.ts +0 -6
  143. package/src/utils/pathUtils.ts +0 -294
  144. package/src/utils/propUtils.ts +0 -24
  145. package/src/utils/refUtils.ts +0 -16
  146. package/src/utils/styleUtils.ts +0 -14
  147. package/src/utils/typeOf.ts +0 -22
@@ -1,292 +0,0 @@
1
- import { useCallback, useMemo, useRef, useState } from "react";
2
-
3
- import { closestListItem, listItemIndex } from "./list-dom-utils";
4
- // import {mousePosition} from './aim/utils';
5
- // import {aiming} from './aim/aim';
6
-
7
- const nudge = (menus, distance, pos) => {
8
- return menus.map((m, i) =>
9
- i === menus.length - 1
10
- ? {
11
- ...m,
12
- [pos]: m[pos] - distance,
13
- }
14
- : m
15
- );
16
- };
17
- const nudgeLeft = (menus, distance) => nudge(menus, distance, "left");
18
- const nudgeUp = (menus, distance) => nudge(menus, distance, "top");
19
-
20
- const flipSides = (id, menus) => {
21
- const [parentMenu, menu] = menus.slice(-2);
22
- const el = document.getElementById(`${id}-${menu.id}`);
23
- const { width } = el.getBoundingClientRect();
24
- return menus.map((m) =>
25
- m === menu
26
- ? {
27
- ...m,
28
- left: parentMenu.left - (width - 2),
29
- }
30
- : m
31
- );
32
- };
33
-
34
- const closedNode = (el) =>
35
- el.ariaHasPopup === "true" && el.ariaExpanded !== "true";
36
- const getPosition = (el, openMenus) => {
37
- const [{ left, top: menuTop }] = openMenus.slice(-1);
38
- // const {top, right, bottom, left} = el.getBoundingClientRect();
39
- // this will not work for MenuList within window, we need the
40
- // const {offsetLeft: left, offsetTop: menuTop} = el.closest('.hwMenuList');
41
- const { offsetWidth: width, offsetTop: top } = el;
42
- return { left: left + width, top: top + menuTop };
43
- };
44
-
45
- export const getItemId = (id) => {
46
- let pos = id.lastIndexOf("-");
47
- return pos === -1 ? id : id.slice(pos + 1);
48
- };
49
-
50
- export const getMenuId = (id) => {
51
- const itemId = getItemId(id);
52
- const pos = itemId.lastIndexOf(".");
53
- return pos > -1 ? itemId.slice(0, pos) : "root";
54
- };
55
-
56
- const getMenuDepth = (id) => {
57
- let count = 0,
58
- pos = id.indexOf(".", 0);
59
- while (pos !== -1) {
60
- count += 1;
61
- pos = id.indexOf(".", pos + 1);
62
- }
63
- return count;
64
- };
65
- const identifyItem = (el) => [
66
- getMenuId(el.id),
67
- getItemId(el.id),
68
- el.ariaHasPopup === "true",
69
- el.ariaExpanded === "true",
70
- getMenuDepth(el.id),
71
- ];
72
-
73
- export const useCascade = ({
74
- id,
75
- onActivate,
76
- onMouseEnterItem,
77
- position: { x: posX, y: posY },
78
- }) => {
79
- const [, forceRefresh] = useState({});
80
- const openMenus = useRef([{ id: "root", left: posX, top: posY }]);
81
-
82
- const setOpenMenus = useCallback((menus) => {
83
- openMenus.current = menus;
84
- forceRefresh({});
85
- }, []);
86
-
87
- const menuOpenPendingTimeout = useRef(null);
88
- const menuClosePendingTimeout = useRef(null);
89
- const menuState = useRef({ root: "no-popup" });
90
- const prevLevel = useRef(0);
91
-
92
- // const prevAim = useRef({mousePos: null, distance: true});
93
-
94
- const openMenu = useCallback(
95
- (menuId = "root", itemId = null, listItemEl = null) => {
96
- if (menuId === "root" && itemId === null) {
97
- setOpenMenus([{ id: "root", left: posX, top: posY }]);
98
- } else {
99
- menuState.current[menuId] = "popup-open";
100
- const doc = listItemEl ? listItemEl.ownerDocument : document;
101
- const el = doc.getElementById(`${id}-${menuId}-${itemId}`);
102
- const { left, top } = getPosition(el, openMenus.current);
103
- setOpenMenus(openMenus.current.concat({ id: itemId, left, top }));
104
- }
105
- },
106
- [id, posX, posY, setOpenMenus]
107
- );
108
-
109
- const closeMenu = useCallback(
110
- (menuId) => {
111
- if (menuId === "root") {
112
- setOpenMenus([]);
113
- } else {
114
- setOpenMenus(openMenus.current.slice(0, -1));
115
- }
116
- },
117
- [setOpenMenus]
118
- );
119
-
120
- const closeMenus = useCallback(
121
- (menuId, itemId) => {
122
- const menus = openMenus.current.slice();
123
- let { id: lastMenuId } = menus[menus.length - 1];
124
- while (menus.length > 1 && !itemId.startsWith(lastMenuId)) {
125
- const parentMenuId = getMenuId(lastMenuId);
126
- menus.pop();
127
- menuState.current[lastMenuId] = "no-popup";
128
- menuState.current[parentMenuId] = "no-popup";
129
- ({ id: lastMenuId } = menus[menus.length - 1]);
130
- }
131
- if (menus.length < openMenus.current.length) {
132
- setOpenMenus(menus);
133
- }
134
- },
135
- [setOpenMenus]
136
- );
137
-
138
- const scheduleOpen = useCallback(
139
- (menuId, itemId, listItemEl) => {
140
- if (menuOpenPendingTimeout.current) {
141
- clearTimeout(menuOpenPendingTimeout.current);
142
- }
143
- menuOpenPendingTimeout.current = setTimeout(() => {
144
- console.log(`scheduleOpen timed out opening ${itemId}`);
145
- closeMenus(menuId, itemId);
146
- menuState.current[menuId] = "popup-open";
147
- menuState.current[itemId] = "no-popup";
148
- openMenu(menuId, itemId, listItemEl);
149
- }, 400);
150
- },
151
- [closeMenus, openMenu]
152
- );
153
-
154
- const scheduleClose = useCallback(
155
- (openMenuId, menuId, itemId) => {
156
- console.log(
157
- `scheduleClose openMenuId ${openMenuId} menuId ${menuId} itemId ${itemId}`
158
- );
159
- menuState.current[openMenuId] = "pending-close";
160
- menuClosePendingTimeout.current = setTimeout(() => {
161
- closeMenus(menuId, itemId);
162
- }, 400);
163
- },
164
- [closeMenus]
165
- );
166
-
167
- const handleRender = useCallback(() => {
168
- const { current: menus } = openMenus;
169
- const [menu] = menus.slice(-1);
170
- const el = document.getElementById(`${id}-${menu.id}`);
171
- if (el) {
172
- const { right, bottom } = el.getBoundingClientRect();
173
- const { clientHeight, clientWidth } = document.body;
174
- if (right > clientWidth) {
175
- const newMenus =
176
- menus.length > 1
177
- ? flipSides(id, menus)
178
- : nudgeLeft(menus, right - clientWidth);
179
- setOpenMenus(newMenus);
180
- } else if (bottom > clientHeight) {
181
- const newMenus = nudgeUp(menus, bottom - clientHeight);
182
- setOpenMenus(newMenus);
183
- }
184
- }
185
- }, [id, setOpenMenus]);
186
-
187
- const listItemProps = useMemo(
188
- () => ({
189
- onMouseEnter: (evt) => {
190
- const listItemEl = closestListItem(evt.target);
191
- const [menuId, itemId, isGroup, isOpen, level] =
192
- identifyItem(listItemEl);
193
- const sameLevel = prevLevel.current === level;
194
- const {
195
- current: { [menuId]: state },
196
- } = menuState;
197
- prevLevel.current = level;
198
-
199
- // console.log(
200
- // `%conMouseEnter #${menuId}[${itemId}] @${level}
201
- // isGroup ${isGroup} isOpen ${isOpen}
202
- // openMenus [${openMenus.current.join(',')}]
203
- // state='${JSON.stringify(menuState.current)}`,
204
- // 'color: green; font-weight: bold;'
205
- // );
206
-
207
- if (state === "no-popup" && isGroup) {
208
- // Shouldn;t we always set this ?
209
- menuState.current[menuId] = "popup-pending";
210
- scheduleOpen(menuId, itemId, listItemEl);
211
- } else if (state === "popup-pending" && !isGroup) {
212
- menuState.current[menuId] = "no-popup";
213
- clearTimeout(menuOpenPendingTimeout.current);
214
- menuOpenPendingTimeout.current = null;
215
- } else if (state === "popup-pending" && isGroup) {
216
- clearTimeout(menuOpenPendingTimeout.current);
217
- scheduleOpen(menuId, itemId, listItemEl);
218
- } else if (state === "popup-open") {
219
- const [{ id: parentMenuId }, { id: openMenuId }] =
220
- openMenus.current.slice(-2);
221
- if (
222
- parentMenuId === menuId &&
223
- menuState.current[openMenuId] !== "pending-close" &&
224
- sameLevel
225
- ) {
226
- scheduleClose(openMenuId, menuId, itemId);
227
- if (isGroup && !isOpen) {
228
- scheduleOpen(menuId, itemId, listItemEl);
229
- }
230
- } else if (
231
- parentMenuId === menuId &&
232
- isGroup &&
233
- itemId !== openMenuId &&
234
- menuState.current[openMenuId] === "pending-close"
235
- ) {
236
- // if there is already an item queued for opening cancel it
237
- scheduleOpen(menuId, itemId, listItemEl);
238
- } else if (isGroup) {
239
- closeMenus(menuId, itemId);
240
- scheduleOpen(menuId, itemId, listItemEl);
241
- } else if (
242
- !(menuState.current[openMenuId] === "pending-close" && sameLevel)
243
- ) {
244
- closeMenus(menuId, itemId);
245
- }
246
- }
247
-
248
- if (state === "pending-close") {
249
- if (menuOpenPendingTimeout.current) {
250
- clearTimeout(menuOpenPendingTimeout.current);
251
- menuOpenPendingTimeout.current = null;
252
- }
253
- clearTimeout(menuClosePendingTimeout.current);
254
- menuClosePendingTimeout.current = null;
255
- menuState.current[menuId] = "popup-open";
256
- }
257
-
258
- onMouseEnterItem(evt, itemId);
259
- },
260
-
261
- onClick: (evt) => {
262
- const listItemEl = closestListItem(evt.target);
263
- const idx = listItemIndex(listItemEl);
264
- if (closedNode(listItemEl).ariaHasPopup === "true") {
265
- if (listItemEl.ariaExpanded !== "true") {
266
- openMenu(idx);
267
- } else {
268
- // do nothing
269
- }
270
- } else {
271
- onActivate(getItemId(listItemEl.id));
272
- }
273
- },
274
- }),
275
- [
276
- closeMenus,
277
- onActivate,
278
- onMouseEnterItem,
279
- openMenu,
280
- scheduleClose,
281
- scheduleOpen,
282
- ]
283
- );
284
-
285
- return {
286
- closeMenu,
287
- handleRender,
288
- listItemProps,
289
- openMenu,
290
- openMenus: openMenus.current,
291
- };
292
- };
@@ -1,22 +0,0 @@
1
- import { useEffect } from 'react';
2
-
3
- export const useClickAway = ({ containerClassName, isOpen, onClose }) => {
4
- useEffect(() => {
5
- const clickHandler = isOpen
6
- ? (evt) => {
7
- const container = evt.target.closest(`.${containerClassName}`);
8
- if (container === null) {
9
- onClose('root');
10
- }
11
- }
12
- : null;
13
-
14
- document.body.addEventListener('click', clickHandler, true);
15
-
16
- return () => {
17
- if (clickHandler) {
18
- document.body.removeEventListener('click', clickHandler, true);
19
- }
20
- };
21
- }, [containerClassName, isOpen, onClose]);
22
- };
@@ -1,75 +0,0 @@
1
- import React, { useCallback, useMemo } from "react";
2
- import { MenuItemGroup, Separator } from "./MenuList";
3
-
4
- export const isMenuItemGroup = (child) =>
5
- child.type === MenuItemGroup || !!child.props["data-group"];
6
-
7
- export const useItemsWithIds = (sourceProp, childrenProp) => {
8
- const normalizeChildren = useCallback(() => {
9
- if (childrenProp === undefined) {
10
- return;
11
- }
12
-
13
- const collectChildren = (
14
- children,
15
- path = "root",
16
- menus = {},
17
- actions = {}
18
- ) => {
19
- const list = (menus[path] = []);
20
- let idx = 0;
21
- let hasSeparator = false;
22
-
23
- React.Children.forEach(children, (child) => {
24
- if (child.type === Separator) {
25
- hasSeparator = true;
26
- } else {
27
- const group = isMenuItemGroup(child);
28
- const childPath = path === "root" ? `${idx}` : `${path}.${idx}`;
29
- const {
30
- props: { action, options },
31
- } = child;
32
- const [childWithId, grandChildren] = assignId(
33
- child,
34
- childPath,
35
- group,
36
- hasSeparator
37
- );
38
- list.push(childWithId);
39
- if (grandChildren) {
40
- collectChildren(grandChildren, childPath, menus, actions);
41
- } else {
42
- actions[childPath] = { action, options };
43
- }
44
- idx += 1;
45
- hasSeparator = false;
46
- }
47
- });
48
- return [menus, actions];
49
- };
50
-
51
- const assignId = (child, path, group, hasSeparator = false) => {
52
- const {
53
- props: { children },
54
- } = child;
55
- return [
56
- React.cloneElement(child, {
57
- hasSeparator,
58
- id: `${path}`,
59
- key: path,
60
- children: group ? undefined : children,
61
- }),
62
- group ? children : undefined,
63
- ];
64
- };
65
-
66
- return collectChildren(childrenProp);
67
- }, [childrenProp]);
68
-
69
- const [children, actions] = useMemo(
70
- () => normalizeChildren(),
71
- [normalizeChildren]
72
- );
73
-
74
- return [children, actions];
75
- };
@@ -1,162 +0,0 @@
1
- import { useCallback, useRef, useState } from "react";
2
- import { hasPopup, isRoot } from "./utils";
3
- import { applyHandlers } from "../utils/apply-handlers";
4
- import { isNavigationKey } from "./key-code";
5
-
6
- // we need a way to set highlightedIdx when selection changes
7
- export const useKeyboardNavigation = (
8
- {
9
- autoHighlightFirstItem = false,
10
- count,
11
- highlightedIdx: highlightedIdxProp,
12
- onActivate,
13
- onHighlight,
14
- onKeyDown,
15
- onCloseMenu,
16
- onOpenMenu,
17
- },
18
- ...additionalHandlers
19
- ) => {
20
- // const prevCount = useRef(count);
21
- const highlightedIndexRef = useRef(
22
- highlightedIdxProp ?? autoHighlightFirstItem ? 0 : -1
23
- );
24
- const [, forceRefresh] = useState(null);
25
- const controlledHighlighting = highlightedIdxProp !== undefined;
26
-
27
- // count will not work for this, as it will change when we expand collapse groups
28
- // if (count !== prevCount.current) {
29
- // prevCount.current = count;
30
- // if (highlightedIndexRef.current !== -1){
31
- // highlightedIndexRef.current = autoHighlightFirstItem ? 0 : -1;
32
- // }
33
- // }
34
-
35
- const setHighlightedIndex = useCallback(
36
- (idx) => {
37
- highlightedIndexRef.current = idx;
38
- onHighlight && onHighlight(idx);
39
- applyHandlers(additionalHandlers, "onHighlight", idx);
40
- forceRefresh({});
41
- },
42
- [additionalHandlers, onHighlight]
43
- );
44
-
45
- // does this belong here or should it be a method passed in?
46
- const keyBoardNavigation = useRef(true);
47
- const ignoreFocus = useRef(false);
48
- const setIgnoreFocus = (value) => (ignoreFocus.current = value);
49
-
50
- const hiliteItemAtIndex = useCallback(
51
- (idx) => {
52
- if (idx !== highlightedIndexRef.current) {
53
- if (!controlledHighlighting) {
54
- setHighlightedIndex(idx);
55
- }
56
- }
57
- },
58
- [controlledHighlighting, setHighlightedIndex]
59
- );
60
-
61
- const highlightedIdx = controlledHighlighting
62
- ? highlightedIdxProp
63
- : highlightedIndexRef.current;
64
-
65
- const listProps = {
66
- onFocus: () => {
67
- if (highlightedIdx === -1) {
68
- setHighlightedIndex(0);
69
- }
70
- },
71
- onKeyDown: (e) => {
72
- if (isNavigationKey(e)) {
73
- e.preventDefault();
74
- e.stopPropagation();
75
- keyBoardNavigation.current = true;
76
- navigateChildldItems(e);
77
- } else if (
78
- (e.key === "ArrowRight" || e.key === "Enter") &&
79
- hasPopup(e.target, highlightedIdx)
80
- ) {
81
- onOpenMenu(highlightedIdx);
82
- } else if (e.key === "ArrowLeft" && !isRoot(e.target)) {
83
- onCloseMenu(highlightedIdx);
84
- } else if (e.key === "Enter") {
85
- onActivate && onActivate(highlightedIdx);
86
- }
87
- // Is there any harm in allowing other keyDown Handlers to fire ?
88
- // TODO this is out of date - use additionalHandlers
89
- if (Array.isArray(onKeyDown)) {
90
- for (let handleEvent of onKeyDown) {
91
- if (e.isPropagationStopped()) {
92
- break;
93
- }
94
- handleEvent(e);
95
- }
96
- } else if (onKeyDown && !e.isPropagationStopped()) {
97
- onKeyDown(e);
98
- }
99
-
100
- applyHandlers(additionalHandlers, "onKeyDown", e);
101
- },
102
- onMouseDownCapture: () => {
103
- keyBoardNavigation.current = false;
104
- setIgnoreFocus(true);
105
- },
106
-
107
- // onMouseEnter would seem less expensive but it misses some cases
108
- onMouseMove: () => {
109
- if (keyBoardNavigation.current) {
110
- keyBoardNavigation.current = false;
111
- }
112
- },
113
- onMouseLeave: () => {
114
- // label === 'ParsedInput' && console.log(`%c[useKeyboardNavigationHook]<${label}> onMouseLeave`,'color:brown')
115
- keyBoardNavigation.current = true;
116
- setIgnoreFocus(false);
117
- hiliteItemAtIndex(-1);
118
- },
119
- };
120
-
121
- const navigateChildldItems = (e) => {
122
- const nextIdx = nextItemIdx(count, e.key, highlightedIndexRef.current);
123
- if (nextIdx !== highlightedIndexRef.current) {
124
- hiliteItemAtIndex(nextIdx);
125
- applyHandlers(additionalHandlers, "onKeyboardNavigation", e, nextIdx);
126
- }
127
- };
128
-
129
- // label === 'ParsedInput' && console.log(`%cuseNavigationHook<${label}>
130
- // highlightedIdxProp= ${highlightedIdxProp},
131
- // highlightedIndexRef= ${highlightedIndexRef.current},
132
- // %chighlightedIdx= ${highlightedIdx}`, 'color: brown','color: brown;font-weight: bold;')
133
-
134
- return {
135
- focusVisible: keyBoardNavigation.current ? highlightedIdx : -1,
136
- controlledHighlighting,
137
- highlightedIdx,
138
- hiliteItemAtIndex,
139
- keyBoardNavigation,
140
- listProps,
141
- setIgnoreFocus,
142
- };
143
- };
144
-
145
- // need to be able to accommodate disabled items
146
- function nextItemIdx(count, key, idx) {
147
- if (key === "Up") {
148
- if (idx > 0) {
149
- return idx - 1;
150
- } else {
151
- return idx;
152
- }
153
- } else {
154
- if (idx === null) {
155
- return 0;
156
- } else if (idx === count - 1) {
157
- return idx;
158
- } else {
159
- return idx + 1;
160
- }
161
- }
162
- }
package/src/menu/utils.js DELETED
@@ -1,5 +0,0 @@
1
- export const isRoot = (el) => el.closest(`[data-root='true']`) !== null;
2
-
3
- export const hasPopup = (el, idx) =>
4
- (el.ariaHasPopup === 'true' && el.dataset?.idx === `${idx}`) ||
5
- el.querySelector(`:scope > [data-idx='${idx}'][aria-haspopup='true']`) !== null;
@@ -1,37 +0,0 @@
1
- .vuuPalette {
2
- }
3
-
4
- .vuuPalette-horizontal {
5
- align-items: center;
6
- display: flex;
7
- }
8
-
9
- .vuuPalette .vuuComponentIcon {
10
- }
11
-
12
- .vuuPaletteItem {
13
- --vuu-icon-color: var(--salt-separable-primary-background);
14
- --vuu-icon-inset: calc(50% - 12px) auto auto -3px;
15
- --vuu-icon-svg: var(--svg-grab-handle);
16
- --vuu-icon-height: 24px;
17
- --vuu-icon-width: 24px;
18
- padding-left: 20px;
19
- }
20
-
21
- .vuuPaletteItem[data-icon]:after {
22
- --height: var(--vuu-icon-height, var(--vuu-icon-size, 12px));
23
- --width: var(--vuu-icon-width, var(--vuu-icon-size, 12px));
24
-
25
- content: "";
26
- background-color: var(--vuu-icon-color, black);
27
- height: var(--height);
28
- inset: var(--vuu-icon-inset,0 auto 0 0);
29
- mask: var(--vuu-icon-svg) center center/var(--width) var(--height) no-repeat;
30
- -webkit-mask: var(--vuu-icon-svg) center center/var(--width) var(--height) no-repeat;
31
- position: absolute;
32
- width: var(--width);
33
- }
34
-
35
- .vuuSimpleDraggableWrapper > .vuuPaletteItem {
36
- --vuu-icon-color: var(--salt-selectable-foreground);
37
- }