@react-fabric/core 1.0.0-beta.21 → 1.0.0-beta.23
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/dist/cjs/components/menu/Menu.js +30 -29
- package/dist/cjs/components/menu/MenuItem.js +20 -12
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/overlays/tooltip/Tooltip.js +1 -1
- package/dist/esm/components/menu/Menu.js +30 -29
- package/dist/esm/components/menu/MenuItem.js +14 -6
- package/dist/esm/index.js +1 -0
- package/dist/esm/overlays/tooltip/Tooltip.js +1 -1
- package/dist/types/index.d.ts +1 -0
- package/package.json +3 -3
- package/src/components/menu/Menu.tsx +43 -40
- package/src/components/menu/MenuItem.tsx +8 -3
- package/src/index.ts +1 -0
- package/src/overlays/tooltip/Tooltip.tsx +1 -1
|
@@ -10,13 +10,12 @@ var react$1 = require('react');
|
|
|
10
10
|
var icons = require('../../types/icons.js');
|
|
11
11
|
var nodeCheck = require('../../utils/nodeCheck.js');
|
|
12
12
|
var MenuItem = require('./MenuItem.js');
|
|
13
|
+
var HotKeyWrapper = require('../../hotkeys/HotKeyWrapper.js');
|
|
13
14
|
var jsxRuntime = require('react/jsx-runtime');
|
|
14
15
|
|
|
15
16
|
var _excluded = ["children", "minimal", "menuClassName", "onClick", "ref"];
|
|
16
17
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
17
18
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
|
-
// FIXME: refactor menu implementation to differentiate between static and floating menus, implement context wrapper for each menu level
|
|
19
|
-
|
|
20
19
|
var MenuComponent = function MenuComponent(_ref) {
|
|
21
20
|
var _refs$domReference$cu, _refs$domReference$cu2;
|
|
22
21
|
var children = _ref.children,
|
|
@@ -165,33 +164,35 @@ var MenuComponent = function MenuComponent(_ref) {
|
|
|
165
164
|
elementsRef: elementsRef,
|
|
166
165
|
labelsRef: labelsRef,
|
|
167
166
|
children: (!isNested || isOpen) && /*#__PURE__*/jsxRuntime.jsxs(Wrapper, _objectSpread(_objectSpread({}, wrapperProps), {}, {
|
|
168
|
-
children: [isNested && /*#__PURE__*/jsxRuntime.jsx(react.FloatingOverlay, {}), /*#__PURE__*/jsxRuntime.jsx(
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
167
|
+
children: [isNested && /*#__PURE__*/jsxRuntime.jsx(react.FloatingOverlay, {}), /*#__PURE__*/jsxRuntime.jsx(HotKeyWrapper.HotKeyWrapper, {
|
|
168
|
+
children: /*#__PURE__*/jsxRuntime.jsx(react.FloatingFocusManager, {
|
|
169
|
+
context: context,
|
|
170
|
+
modal: !isNested,
|
|
171
|
+
initialFocus: isNested ? -1 : 0,
|
|
172
|
+
returnFocus: !isNested,
|
|
173
|
+
children: /*#__PURE__*/jsxRuntime.jsx("div", _objectSpread(_objectSpread({
|
|
174
|
+
className: classNames(menuClassName, "flex flex-col bg-base p-1 menu-list", isNested && "outline shadow-lg rounded-capped max-h-96 overflow-auto scroll-thin z-[var(--z-popover)]"),
|
|
175
|
+
autoFocus: true,
|
|
176
|
+
ref: utilities.mergeRefs(isNested ? refs.setFloating : ref)
|
|
177
|
+
}, getFloatingProps({
|
|
178
|
+
onClick: isNested ? undefined : handleClick
|
|
179
|
+
})), {}, {
|
|
180
|
+
style: !isNested ? rest.style : floatingStyles,
|
|
181
|
+
children: utilities.cloneChildren(children, function (child, index) {
|
|
182
|
+
labelsRef.current[index] = child.props.label;
|
|
183
|
+
return /*#__PURE__*/react$1.cloneElement(child, nodeCheck.nodeCheck(child, MenuItem.MenuItem, Menu, MenuComponent) ? _objectSpread({
|
|
184
|
+
minimal: !isNested && minimal,
|
|
185
|
+
"data-focus": activeIndex === index,
|
|
186
|
+
ref: function ref(el) {
|
|
187
|
+
return elementsRef.current[index] = el;
|
|
188
|
+
}
|
|
189
|
+
}, getItemProps({
|
|
190
|
+
onClick: child.props.onClick,
|
|
191
|
+
tabIndex: activeIndex === index ? 0 : -1
|
|
192
|
+
})) : {});
|
|
193
|
+
})
|
|
194
|
+
}))
|
|
195
|
+
})
|
|
195
196
|
})]
|
|
196
197
|
}))
|
|
197
198
|
})]
|
|
@@ -2,20 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
4
4
|
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
5
|
-
var react = require('@floating-ui/react');
|
|
5
|
+
var react$1 = require('@floating-ui/react');
|
|
6
6
|
var utilities = require('@react-fabric/utilities');
|
|
7
7
|
var classNames = require('classnames');
|
|
8
|
-
var react
|
|
8
|
+
var react = require('react');
|
|
9
|
+
var HotKey = require('../../hotkeys/HotKey.js');
|
|
9
10
|
var HotKeyLabel = require('../../hotkeys/HotKeyLabel.js');
|
|
10
11
|
require('@babel/runtime/helpers/slicedToArray');
|
|
11
12
|
require('react-i18next');
|
|
12
13
|
require('../../hooks/useEffectDebugger.js');
|
|
13
14
|
var jsxRuntime = require('react/jsx-runtime');
|
|
14
|
-
require('../../hotkeys/HotKeyWrapper.js');
|
|
15
15
|
var Tooltip = require('../../overlays/tooltip/Tooltip.js');
|
|
16
16
|
var Badge = require('../badge/Badge.js');
|
|
17
17
|
var Icon = require('../icon/Icon.js');
|
|
18
18
|
require('../../types/icons.js');
|
|
19
|
+
require('../../hotkeys/HotKeyWrapper.js');
|
|
19
20
|
var Menu_module = require('./Menu.module.css');
|
|
20
21
|
|
|
21
22
|
var _excluded = ["as", "label", "color", "className", "icon", "iconBg", "iconColor", "appendLabel", "rtlFlip", "altIcon", "id", "active", "disabled", "onClick", "badge", "hotKey", "minimal", "data-open", "ref"],
|
|
@@ -44,11 +45,12 @@ var MenuItem = function MenuItem(_ref) {
|
|
|
44
45
|
childOpen = _ref["data-open"],
|
|
45
46
|
ref = _ref.ref,
|
|
46
47
|
aria = _objectWithoutProperties(_ref, _excluded);
|
|
47
|
-
var
|
|
48
|
-
var
|
|
48
|
+
var elRef = react.useRef(null);
|
|
49
|
+
var tree = react$1.useFloatingTree();
|
|
50
|
+
var badgeProps = react.useMemo(function () {
|
|
49
51
|
return Badge.getBadgeProps(badge);
|
|
50
52
|
}, [badge]);
|
|
51
|
-
var iconEl = react
|
|
53
|
+
var iconEl = react.useMemo(function () {
|
|
52
54
|
var _path;
|
|
53
55
|
var path = icon;
|
|
54
56
|
if (minimal && !path) {
|
|
@@ -62,7 +64,7 @@ var MenuItem = function MenuItem(_ref) {
|
|
|
62
64
|
rtlFlip: rtlFlip
|
|
63
65
|
});
|
|
64
66
|
}, [icon, iconBg, iconColor, rtlFlip, minimal, label]);
|
|
65
|
-
var Wrapper = react
|
|
67
|
+
var Wrapper = react.useCallback(function (_ref2) {
|
|
66
68
|
var children = _ref2.children,
|
|
67
69
|
rest = _objectWithoutProperties(_ref2, _excluded2);
|
|
68
70
|
return minimal ? /*#__PURE__*/jsxRuntime.jsx(Tooltip.Tooltip, _objectSpread(_objectSpread({
|
|
@@ -71,11 +73,11 @@ var MenuItem = function MenuItem(_ref) {
|
|
|
71
73
|
disabled: childOpen
|
|
72
74
|
}, rest), {}, {
|
|
73
75
|
children: children
|
|
74
|
-
})) : /*#__PURE__*/jsxRuntime.jsx(react
|
|
76
|
+
})) : /*#__PURE__*/jsxRuntime.jsx(react.Fragment, {
|
|
75
77
|
children: children
|
|
76
78
|
});
|
|
77
79
|
}, [minimal, label, childOpen]);
|
|
78
|
-
var menuLabel = react
|
|
80
|
+
var menuLabel = react.useMemo(function () {
|
|
79
81
|
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
80
82
|
className: "flex flex-nowrap text-start items-center",
|
|
81
83
|
children: [iconEl, !minimal && /*#__PURE__*/jsxRuntime.jsx("label", {
|
|
@@ -98,8 +100,8 @@ var MenuItem = function MenuItem(_ref) {
|
|
|
98
100
|
}, [iconEl, minimal, appendLabel, label, badge, badgeProps, hotKey, active]);
|
|
99
101
|
var E = as !== null && as !== void 0 ? as : "button";
|
|
100
102
|
return /*#__PURE__*/jsxRuntime.jsx(Wrapper, _objectSpread(_objectSpread({}, aria), {}, {
|
|
101
|
-
children: /*#__PURE__*/jsxRuntime.
|
|
102
|
-
ref: ref,
|
|
103
|
+
children: /*#__PURE__*/jsxRuntime.jsxs(E, _objectSpread(_objectSpread({
|
|
104
|
+
ref: utilities.mergeRefs(ref, elRef),
|
|
103
105
|
"data-dropdown-dismiss": true,
|
|
104
106
|
"data-color": color,
|
|
105
107
|
className: classNames(Menu_module.menuItem, className, active && Menu_module.active, minimal && Menu_module.minimal, disabled && Menu_module.disabled, "rounded-capped relative max-w-[50vw] my-0.5"),
|
|
@@ -111,7 +113,13 @@ var MenuItem = function MenuItem(_ref) {
|
|
|
111
113
|
(_onClick === null || _onClick === void 0 ? void 0 : _onClick(e)) !== false && (tree === null || tree === void 0 ? void 0 : tree.events.emit("click"));
|
|
112
114
|
}
|
|
113
115
|
}, minimal ? {} : aria), {}, {
|
|
114
|
-
children:
|
|
116
|
+
children: [hotKey && /*#__PURE__*/jsxRuntime.jsx(HotKey.HotKey, {
|
|
117
|
+
keyCombo: hotKey,
|
|
118
|
+
handler: function handler() {
|
|
119
|
+
var _elRef$current, _elRef$current$click;
|
|
120
|
+
return (_elRef$current = elRef.current) === null || _elRef$current === void 0 || (_elRef$current$click = _elRef$current.click) === null || _elRef$current$click === void 0 ? void 0 : _elRef$current$click.call(_elRef$current);
|
|
121
|
+
}
|
|
122
|
+
}), menuLabel]
|
|
115
123
|
}))
|
|
116
124
|
}));
|
|
117
125
|
};
|
package/dist/cjs/index.js
CHANGED
|
@@ -73,6 +73,7 @@ var useResizeObserver = require('./hooks/useResizeObserver.js');
|
|
|
73
73
|
var useStorage = require('./hooks/useStorage.js');
|
|
74
74
|
var HotKey = require('./hotkeys/HotKey.js');
|
|
75
75
|
var HotKeyLabel = require('./hotkeys/HotKeyLabel.js');
|
|
76
|
+
var HotKeyWrapper = require('./hotkeys/HotKeyWrapper.js');
|
|
76
77
|
var Global = require('./context/Global.js');
|
|
77
78
|
|
|
78
79
|
|
|
@@ -158,6 +159,7 @@ exports.useLocalStorage = useStorage.useLocalStorage;
|
|
|
158
159
|
exports.useSessionStorage = useStorage.useSessionStorage;
|
|
159
160
|
exports.HotKey = HotKey.HotKey;
|
|
160
161
|
exports.HotKeyLabel = HotKeyLabel.HotKeyLabel;
|
|
162
|
+
exports.HotKeyWrapper = HotKeyWrapper.HotKeyWrapper;
|
|
161
163
|
exports.ApplicationProvider = Global.ApplicationProvider;
|
|
162
164
|
exports.useApplicationContext = Global.useApplicationContext;
|
|
163
165
|
exports.useGlobals = Global.useGlobals;
|
|
@@ -118,7 +118,7 @@ var Tooltip = function Tooltip(_ref) {
|
|
|
118
118
|
style: floatingStyles
|
|
119
119
|
}, getFloatingProps()), {}, {
|
|
120
120
|
children: [/*#__PURE__*/jsxRuntime.jsx("span", {
|
|
121
|
-
className: classNames("font-medium text-dimmed flex-1", utilities.isString(content) && "whitespace-pre-wrap mixed-lang"),
|
|
121
|
+
className: classNames("font-medium text-dimmed flex-1 break-all", utilities.isString(content) && "whitespace-pre-wrap mixed-lang"),
|
|
122
122
|
children: content
|
|
123
123
|
}), copyEl, /*#__PURE__*/jsxRuntime.jsx(react$1.FloatingArrow, {
|
|
124
124
|
ref: arrowRef,
|
|
@@ -10,13 +10,12 @@ import { useState, useRef, useEffect, useCallback, cloneElement, Fragment } from
|
|
|
10
10
|
import { CoreIcons } from '../../types/icons.js';
|
|
11
11
|
import { nodeCheck } from '../../utils/nodeCheck.js';
|
|
12
12
|
import { MenuItem } from './MenuItem.js';
|
|
13
|
+
import { HotKeyWrapper } from '../../hotkeys/HotKeyWrapper.js';
|
|
13
14
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
14
15
|
|
|
15
16
|
var _excluded = ["children", "minimal", "menuClassName", "onClick", "ref"];
|
|
16
17
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
17
18
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
|
-
// FIXME: refactor menu implementation to differentiate between static and floating menus, implement context wrapper for each menu level
|
|
19
|
-
|
|
20
19
|
var MenuComponent = function MenuComponent(_ref) {
|
|
21
20
|
var _refs$domReference$cu, _refs$domReference$cu2;
|
|
22
21
|
var children = _ref.children,
|
|
@@ -165,33 +164,35 @@ var MenuComponent = function MenuComponent(_ref) {
|
|
|
165
164
|
elementsRef: elementsRef,
|
|
166
165
|
labelsRef: labelsRef,
|
|
167
166
|
children: (!isNested || isOpen) && /*#__PURE__*/jsxs(Wrapper, _objectSpread(_objectSpread({}, wrapperProps), {}, {
|
|
168
|
-
children: [isNested && /*#__PURE__*/jsx(FloatingOverlay, {}), /*#__PURE__*/jsx(
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
167
|
+
children: [isNested && /*#__PURE__*/jsx(FloatingOverlay, {}), /*#__PURE__*/jsx(HotKeyWrapper, {
|
|
168
|
+
children: /*#__PURE__*/jsx(FloatingFocusManager, {
|
|
169
|
+
context: context,
|
|
170
|
+
modal: !isNested,
|
|
171
|
+
initialFocus: isNested ? -1 : 0,
|
|
172
|
+
returnFocus: !isNested,
|
|
173
|
+
children: /*#__PURE__*/jsx("div", _objectSpread(_objectSpread({
|
|
174
|
+
className: classNames(menuClassName, "flex flex-col bg-base p-1 menu-list", isNested && "outline shadow-lg rounded-capped max-h-96 overflow-auto scroll-thin z-[var(--z-popover)]"),
|
|
175
|
+
autoFocus: true,
|
|
176
|
+
ref: mergeRefs(isNested ? refs.setFloating : ref)
|
|
177
|
+
}, getFloatingProps({
|
|
178
|
+
onClick: isNested ? undefined : handleClick
|
|
179
|
+
})), {}, {
|
|
180
|
+
style: !isNested ? rest.style : floatingStyles,
|
|
181
|
+
children: cloneChildren(children, function (child, index) {
|
|
182
|
+
labelsRef.current[index] = child.props.label;
|
|
183
|
+
return /*#__PURE__*/cloneElement(child, nodeCheck(child, MenuItem, Menu, MenuComponent) ? _objectSpread({
|
|
184
|
+
minimal: !isNested && minimal,
|
|
185
|
+
"data-focus": activeIndex === index,
|
|
186
|
+
ref: function ref(el) {
|
|
187
|
+
return elementsRef.current[index] = el;
|
|
188
|
+
}
|
|
189
|
+
}, getItemProps({
|
|
190
|
+
onClick: child.props.onClick,
|
|
191
|
+
tabIndex: activeIndex === index ? 0 : -1
|
|
192
|
+
})) : {});
|
|
193
|
+
})
|
|
194
|
+
}))
|
|
195
|
+
})
|
|
195
196
|
})]
|
|
196
197
|
}))
|
|
197
198
|
})]
|
|
@@ -3,19 +3,20 @@
|
|
|
3
3
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
4
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
5
5
|
import { useFloatingTree } from '@floating-ui/react';
|
|
6
|
-
import { iconToken } from '@react-fabric/utilities';
|
|
6
|
+
import { iconToken, mergeRefs } from '@react-fabric/utilities';
|
|
7
7
|
import classNames from 'classnames';
|
|
8
|
-
import { useMemo, useCallback, Fragment } from 'react';
|
|
8
|
+
import { useRef, useMemo, useCallback, Fragment } from 'react';
|
|
9
|
+
import { HotKey } from '../../hotkeys/HotKey.js';
|
|
9
10
|
import { HotKeyLabel } from '../../hotkeys/HotKeyLabel.js';
|
|
10
11
|
import '@babel/runtime/helpers/slicedToArray';
|
|
11
12
|
import 'react-i18next';
|
|
12
13
|
import '../../hooks/useEffectDebugger.js';
|
|
13
14
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
14
|
-
import '../../hotkeys/HotKeyWrapper.js';
|
|
15
15
|
import { Tooltip } from '../../overlays/tooltip/Tooltip.js';
|
|
16
16
|
import { getBadgeProps, Badge } from '../badge/Badge.js';
|
|
17
17
|
import { Icon } from '../icon/Icon.js';
|
|
18
18
|
import '../../types/icons.js';
|
|
19
|
+
import '../../hotkeys/HotKeyWrapper.js';
|
|
19
20
|
import classes from './Menu.module.css';
|
|
20
21
|
|
|
21
22
|
var _excluded = ["as", "label", "color", "className", "icon", "iconBg", "iconColor", "appendLabel", "rtlFlip", "altIcon", "id", "active", "disabled", "onClick", "badge", "hotKey", "minimal", "data-open", "ref"],
|
|
@@ -44,6 +45,7 @@ var MenuItem = function MenuItem(_ref) {
|
|
|
44
45
|
childOpen = _ref["data-open"],
|
|
45
46
|
ref = _ref.ref,
|
|
46
47
|
aria = _objectWithoutProperties(_ref, _excluded);
|
|
48
|
+
var elRef = useRef(null);
|
|
47
49
|
var tree = useFloatingTree();
|
|
48
50
|
var badgeProps = useMemo(function () {
|
|
49
51
|
return getBadgeProps(badge);
|
|
@@ -98,8 +100,8 @@ var MenuItem = function MenuItem(_ref) {
|
|
|
98
100
|
}, [iconEl, minimal, appendLabel, label, badge, badgeProps, hotKey, active]);
|
|
99
101
|
var E = as !== null && as !== void 0 ? as : "button";
|
|
100
102
|
return /*#__PURE__*/jsx(Wrapper, _objectSpread(_objectSpread({}, aria), {}, {
|
|
101
|
-
children: /*#__PURE__*/
|
|
102
|
-
ref: ref,
|
|
103
|
+
children: /*#__PURE__*/jsxs(E, _objectSpread(_objectSpread({
|
|
104
|
+
ref: mergeRefs(ref, elRef),
|
|
103
105
|
"data-dropdown-dismiss": true,
|
|
104
106
|
"data-color": color,
|
|
105
107
|
className: classNames(classes.menuItem, className, active && classes.active, minimal && classes.minimal, disabled && classes.disabled, "rounded-capped relative max-w-[50vw] my-0.5"),
|
|
@@ -111,7 +113,13 @@ var MenuItem = function MenuItem(_ref) {
|
|
|
111
113
|
(_onClick === null || _onClick === void 0 ? void 0 : _onClick(e)) !== false && (tree === null || tree === void 0 ? void 0 : tree.events.emit("click"));
|
|
112
114
|
}
|
|
113
115
|
}, minimal ? {} : aria), {}, {
|
|
114
|
-
children:
|
|
116
|
+
children: [hotKey && /*#__PURE__*/jsx(HotKey, {
|
|
117
|
+
keyCombo: hotKey,
|
|
118
|
+
handler: function handler() {
|
|
119
|
+
var _elRef$current, _elRef$current$click;
|
|
120
|
+
return (_elRef$current = elRef.current) === null || _elRef$current === void 0 || (_elRef$current$click = _elRef$current.click) === null || _elRef$current$click === void 0 ? void 0 : _elRef$current$click.call(_elRef$current);
|
|
121
|
+
}
|
|
122
|
+
}), menuLabel]
|
|
115
123
|
}))
|
|
116
124
|
}));
|
|
117
125
|
};
|
package/dist/esm/index.js
CHANGED
|
@@ -73,4 +73,5 @@ export { useResizeObserver } from './hooks/useResizeObserver.js';
|
|
|
73
73
|
export { useLocalStorage, useSessionStorage } from './hooks/useStorage.js';
|
|
74
74
|
export { HotKey } from './hotkeys/HotKey.js';
|
|
75
75
|
export { HotKeyLabel } from './hotkeys/HotKeyLabel.js';
|
|
76
|
+
export { HotKeyWrapper } from './hotkeys/HotKeyWrapper.js';
|
|
76
77
|
export { ApplicationProvider, useApplicationContext, useGlobals, useNotificationService } from './context/Global.js';
|
|
@@ -118,7 +118,7 @@ var Tooltip = function Tooltip(_ref) {
|
|
|
118
118
|
style: floatingStyles
|
|
119
119
|
}, getFloatingProps()), {}, {
|
|
120
120
|
children: [/*#__PURE__*/jsx("span", {
|
|
121
|
-
className: classNames("font-medium text-dimmed flex-1", isString(content) && "whitespace-pre-wrap mixed-lang"),
|
|
121
|
+
className: classNames("font-medium text-dimmed flex-1 break-all", isString(content) && "whitespace-pre-wrap mixed-lang"),
|
|
122
122
|
children: content
|
|
123
123
|
}), copyEl, /*#__PURE__*/jsx(FloatingArrow, {
|
|
124
124
|
ref: arrowRef,
|
package/dist/types/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export * from "./hooks/useResizeObserver";
|
|
|
15
15
|
export * from "./hooks/useStorage";
|
|
16
16
|
export { HotKey } from "./hotkeys/HotKey";
|
|
17
17
|
export { HotKeyLabel } from "./hotkeys/HotKeyLabel";
|
|
18
|
+
export { HotKeyWrapper } from "./hotkeys/HotKeyWrapper";
|
|
18
19
|
export { type ModalProps } from "./types";
|
|
19
20
|
export { CoreIcons } from "./types/icons";
|
|
20
21
|
export { ApplicationProvider, useApplicationContext, useGlobals, useNotificationService, } from "./context/Global";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-fabric/core",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.23",
|
|
4
4
|
"description": "RUF: Core package",
|
|
5
5
|
"author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@floating-ui/react": "^0.26.24",
|
|
39
|
-
"@react-fabric/utilities": "^1.0.0-beta.
|
|
39
|
+
"@react-fabric/utilities": "^1.0.0-beta.23",
|
|
40
40
|
"@tailwindcss/container-queries": "^0.1.1",
|
|
41
41
|
"@tailwindcss/forms": "^0.5.7",
|
|
42
42
|
"@tailwindcss/typography": "^0.5.13",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"node": ">=18.12.0",
|
|
57
57
|
"npm": ">=8.19.0"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "96cac942a837ec03886660d398de74b8bcb2dbac"
|
|
60
60
|
}
|
|
@@ -59,6 +59,7 @@ import { CoreIcons } from "../../types/icons";
|
|
|
59
59
|
import { nodeCheck } from "../../utils";
|
|
60
60
|
import { MenuItem } from "./MenuItem";
|
|
61
61
|
import { type MenuProps } from "./types";
|
|
62
|
+
import { HotKeyWrapper } from "../../hotkeys/HotKeyWrapper";
|
|
62
63
|
|
|
63
64
|
// FIXME: refactor menu implementation to differentiate between static and floating menus, implement context wrapper for each menu level
|
|
64
65
|
|
|
@@ -219,47 +220,49 @@ const MenuComponent = ({
|
|
|
219
220
|
{(!isNested || isOpen) && (
|
|
220
221
|
<Wrapper {...wrapperProps}>
|
|
221
222
|
{isNested && <FloatingOverlay />}
|
|
222
|
-
<
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
<div
|
|
229
|
-
className={classNames(
|
|
230
|
-
menuClassName,
|
|
231
|
-
"flex flex-col bg-base p-1 menu-list",
|
|
232
|
-
isNested &&
|
|
233
|
-
"outline shadow-lg rounded-capped max-h-96 overflow-auto scroll-thin z-[var(--z-popover)]",
|
|
234
|
-
)}
|
|
235
|
-
autoFocus
|
|
236
|
-
ref={mergeRefs(isNested ? refs.setFloating : ref)}
|
|
237
|
-
{...getFloatingProps({
|
|
238
|
-
onClick: isNested ? undefined : handleClick,
|
|
239
|
-
})}
|
|
240
|
-
// @ts-expect-error ignore
|
|
241
|
-
{...{ style: !isNested ? rest.style : floatingStyles }}
|
|
223
|
+
<HotKeyWrapper>
|
|
224
|
+
<FloatingFocusManager
|
|
225
|
+
context={context}
|
|
226
|
+
modal={!isNested}
|
|
227
|
+
initialFocus={isNested ? -1 : 0}
|
|
228
|
+
returnFocus={!isNested}
|
|
242
229
|
>
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
230
|
+
<div
|
|
231
|
+
className={classNames(
|
|
232
|
+
menuClassName,
|
|
233
|
+
"flex flex-col bg-base p-1 menu-list",
|
|
234
|
+
isNested &&
|
|
235
|
+
"outline shadow-lg rounded-capped max-h-96 overflow-auto scroll-thin z-[var(--z-popover)]",
|
|
236
|
+
)}
|
|
237
|
+
autoFocus
|
|
238
|
+
ref={mergeRefs(isNested ? refs.setFloating : ref)}
|
|
239
|
+
{...getFloatingProps({
|
|
240
|
+
onClick: isNested ? undefined : handleClick,
|
|
241
|
+
})}
|
|
242
|
+
// @ts-expect-error ignore
|
|
243
|
+
{...{ style: !isNested ? rest.style : floatingStyles }}
|
|
244
|
+
>
|
|
245
|
+
{cloneChildren(children, (child: AnyObject, index) => {
|
|
246
|
+
labelsRef.current[index] = child.props.label;
|
|
247
|
+
return cloneElement(
|
|
248
|
+
child,
|
|
249
|
+
nodeCheck(child, MenuItem, Menu, MenuComponent)
|
|
250
|
+
? {
|
|
251
|
+
minimal: !isNested && minimal,
|
|
252
|
+
"data-focus": activeIndex === index,
|
|
253
|
+
ref: (el: HTMLElement) =>
|
|
254
|
+
(elementsRef.current[index] = el),
|
|
255
|
+
...getItemProps({
|
|
256
|
+
onClick: child.props.onClick,
|
|
257
|
+
tabIndex: activeIndex === index ? 0 : -1,
|
|
258
|
+
}),
|
|
259
|
+
}
|
|
260
|
+
: {},
|
|
261
|
+
);
|
|
262
|
+
})}
|
|
263
|
+
</div>
|
|
264
|
+
</FloatingFocusManager>
|
|
265
|
+
</HotKeyWrapper>
|
|
263
266
|
</Wrapper>
|
|
264
267
|
)}
|
|
265
268
|
</FloatingList>
|
|
@@ -22,9 +22,10 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
import { useFloatingTree } from "@floating-ui/react";
|
|
25
|
-
import { iconToken } from "@react-fabric/utilities";
|
|
25
|
+
import { iconToken, mergeRefs } from "@react-fabric/utilities";
|
|
26
26
|
import classNames from "classnames";
|
|
27
|
-
import { Fragment, useCallback, useMemo } from "react";
|
|
27
|
+
import { Fragment, useCallback, useMemo, useRef } from "react";
|
|
28
|
+
import { HotKey } from "../../hotkeys/HotKey";
|
|
28
29
|
import { HotKeyLabel } from "../../hotkeys/HotKeyLabel";
|
|
29
30
|
import { Tooltip } from "../../overlays";
|
|
30
31
|
import { type PolymorphicProps } from "../../types";
|
|
@@ -58,6 +59,7 @@ export const MenuItem = <Tag extends React.ElementType = "button">({
|
|
|
58
59
|
ref,
|
|
59
60
|
...aria
|
|
60
61
|
}: MenuItemProps & PolymorphicProps<Tag>) => {
|
|
62
|
+
const elRef = useRef<HTMLElement>(null);
|
|
61
63
|
const tree = useFloatingTree();
|
|
62
64
|
const badgeProps = useMemo(() => {
|
|
63
65
|
return getBadgeProps(badge);
|
|
@@ -135,7 +137,7 @@ export const MenuItem = <Tag extends React.ElementType = "button">({
|
|
|
135
137
|
return (
|
|
136
138
|
<Wrapper {...aria}>
|
|
137
139
|
<E
|
|
138
|
-
ref={ref}
|
|
140
|
+
ref={mergeRefs(ref, elRef)}
|
|
139
141
|
data-dropdown-dismiss
|
|
140
142
|
data-color={color}
|
|
141
143
|
className={classNames(
|
|
@@ -155,6 +157,9 @@ export const MenuItem = <Tag extends React.ElementType = "button">({
|
|
|
155
157
|
}}
|
|
156
158
|
{...(minimal ? {} : aria)}
|
|
157
159
|
>
|
|
160
|
+
{hotKey && (
|
|
161
|
+
<HotKey keyCombo={hotKey} handler={() => elRef.current?.click?.()} />
|
|
162
|
+
)}
|
|
158
163
|
{menuLabel}
|
|
159
164
|
</E>
|
|
160
165
|
</Wrapper>
|
package/src/index.ts
CHANGED
|
@@ -40,6 +40,7 @@ export * from "./hooks/useStorage";
|
|
|
40
40
|
|
|
41
41
|
export { HotKey } from "./hotkeys/HotKey";
|
|
42
42
|
export { HotKeyLabel } from "./hotkeys/HotKeyLabel";
|
|
43
|
+
export { HotKeyWrapper } from "./hotkeys/HotKeyWrapper";
|
|
43
44
|
|
|
44
45
|
export { type ModalProps } from "./types";
|
|
45
46
|
export { CoreIcons } from "./types/icons";
|