@atlaskit/dropdown-menu 12.18.5 → 12.18.6

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/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @atlaskit/dropdown-menu
2
2
 
3
+ ## 12.18.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [`5ceb889d493ab`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/5ceb889d493ab) -
8
+ Fix issue with Async loading of Dropdown Menu Items
9
+ - [#148281](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/148281)
10
+ [`3c4de48168ffe`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3c4de48168ffe) -
11
+ Update the import path of `useId*` from `@atlaskit/ds-lib`
12
+ - Updated dependencies
13
+
3
14
  ## 12.18.5
4
15
 
5
16
  ### Patch Changes
@@ -8,7 +8,7 @@ exports.default = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
10
  var _react = _interopRequireDefault(require("react"));
11
- var _reactUid = require("@atlaskit/ds-lib/react-uid");
11
+ var _useId = require("@atlaskit/ds-lib/use-id");
12
12
  var _section = _interopRequireDefault(require("@atlaskit/menu/section"));
13
13
  var _groupTitle = _interopRequireDefault(require("../internal/components/group-title"));
14
14
  var _checkboxGroupContext = require("../internal/context/checkbox-group-context");
@@ -29,7 +29,7 @@ var DropdownItemCheckboxGroup = function DropdownItemCheckboxGroup(_ref) {
29
29
  testId = _ref.testId,
30
30
  title = _ref.title,
31
31
  rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
32
- var uid = (0, _reactUid.useId)();
32
+ var uid = (0, _useId.useId)();
33
33
  var titleId = "dropdown-menu-item-checkbox-group-title-".concat(uid);
34
34
  return /*#__PURE__*/_react.default.createElement(_checkboxGroupContext.CheckboxGroupContext.Provider, {
35
35
  value: id
@@ -9,7 +9,7 @@ exports.default = void 0;
9
9
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
10
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
11
11
  var _react = _interopRequireWildcard(require("react"));
12
- var _reactUid = require("@atlaskit/ds-lib/react-uid");
12
+ var _useId = require("@atlaskit/ds-lib/use-id");
13
13
  var _menu = require("@atlaskit/menu");
14
14
  var _groupTitle = _interopRequireDefault(require("./internal/components/group-title"));
15
15
  var _excluded = ["children", "id", "isList", "isScrollable", "title", "testId", "hasSeparator", "overrides"];
@@ -31,7 +31,7 @@ var DropdownMenuItemGroup = /*#__PURE__*/(0, _react.forwardRef)(function (_ref,
31
31
  hasSeparator = _ref.hasSeparator,
32
32
  overrides = _ref.overrides,
33
33
  rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
34
- var uid = (0, _reactUid.useId)();
34
+ var uid = (0, _useId.useId)();
35
35
  var titleId = "dropdown-menu-item-group-title-".concat(uid);
36
36
  return /*#__PURE__*/_react.default.createElement(_menu.Section, (0, _extends2.default)({
37
37
  id: id,
@@ -18,7 +18,7 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
18
18
  *
19
19
  * Context provider which maintains the list of focusable elements and a method to
20
20
  * register new menu items.
21
- * This list drives the keyboard navgation of the menu.
21
+ * This list drives the keyboard navigation of the menu.
22
22
  *
23
23
  */
24
24
  var FocusManagerContext = exports.FocusManagerContext = /*#__PURE__*/(0, _react.createContext)({
@@ -33,15 +33,16 @@ var FocusManager = function FocusManager(_ref) {
33
33
  var children = _ref.children,
34
34
  onClose = _ref.onClose;
35
35
  var menuItemRefs = (0, _react.useRef)([]);
36
+ var registerRefCalls = (0, _react.useRef)(0);
36
37
  var registerRef = (0, _react.useCallback)(function (ref) {
37
- if (ref && !menuItemRefs.current.includes(ref)) {
38
- menuItemRefs.current.push(ref);
39
- }
38
+ return upsertRefAtFirstPosition(ref, menuItemRefs, registerRefCalls);
40
39
  }, []);
41
40
  var _UNSAFE_useLayering = (0, _layering.UNSAFE_useLayering)(),
42
41
  isLayerDisabled = _UNSAFE_useLayering.isLayerDisabled;
43
- // Intentionally rebinding on each render
44
42
  (0, _react.useEffect)(function () {
43
+ // Intentionally reset count on each render
44
+ registerRefCalls.current = 0;
45
+ // Intentionally rebinding on each render
45
46
  return (0, _bindEventListener.bind)(window, {
46
47
  type: 'keydown',
47
48
  listener: (0, _handleFocus.default)(menuItemRefs.current, isLayerDisabled, onClose)
@@ -55,4 +56,37 @@ var FocusManager = function FocusManager(_ref) {
55
56
  value: contextValue
56
57
  }, children);
57
58
  };
59
+
60
+ /**
61
+ * Insert the ref at the call position in the array.
62
+ * If the ref is already in the array, move it to the call position.
63
+ * If the call position is after the current position, ignore the call.
64
+ *
65
+ * @param ref
66
+ * @param menuItemRefs
67
+ * @param registerRefCalls
68
+ */
69
+ function upsertRefAtFirstPosition(ref, menuItemRefs, registerRefCalls) {
70
+ var positionOnCall = registerRefCalls.current++;
71
+
72
+ // Add the ref to the correct position
73
+ if (!menuItemRefs.current.includes(ref)) {
74
+ menuItemRefs.current.splice(positionOnCall, 0, ref);
75
+ return;
76
+ }
77
+ var positionCurrent = menuItemRefs.current.indexOf(ref);
78
+ if (positionOnCall === positionCurrent) {
79
+ // No change needed
80
+ return;
81
+ }
82
+ if (positionOnCall > positionCurrent) {
83
+ // Ignore and so keep the count the same
84
+ registerRefCalls.current--;
85
+ return;
86
+ }
87
+
88
+ // Update the position of the ref in the array
89
+ menuItemRefs.current.splice(positionCurrent, 1);
90
+ menuItemRefs.current.splice(positionOnCall, 0, ref);
91
+ }
58
92
  var _default = exports.default = FocusManager;
@@ -12,7 +12,7 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
12
12
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
13
  var _react = _interopRequireWildcard(require("react"));
14
14
  var _noop = _interopRequireDefault(require("@atlaskit/ds-lib/noop"));
15
- var _reactUid = require("@atlaskit/ds-lib/react-uid");
15
+ var _useId = require("@atlaskit/ds-lib/use-id");
16
16
  var _menu = require("@atlaskit/menu");
17
17
  var _groupTitle = _interopRequireDefault(require("../internal/components/group-title"));
18
18
  var _selectionStore = require("../internal/context/selection-store");
@@ -51,7 +51,7 @@ var DropdownItemRadioGroup = function DropdownItemRadioGroup(_ref) {
51
51
  var _useContext = (0, _react.useContext)(_selectionStore.SelectionStoreContext),
52
52
  setGroupState = _useContext.setGroupState,
53
53
  getGroupState = _useContext.getGroupState;
54
- var uid = (0, _reactUid.useId)();
54
+ var uid = (0, _useId.useId)();
55
55
  var titleId = "dropdown-menu-item-radio-group-title-".concat(uid);
56
56
 
57
57
  /**
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import React from 'react';
3
- import { useId } from '@atlaskit/ds-lib/react-uid';
3
+ import { useId } from '@atlaskit/ds-lib/use-id';
4
4
  import Section from '@atlaskit/menu/section';
5
5
  import GroupTitle from '../internal/components/group-title';
6
6
  import { CheckboxGroupContext } from '../internal/context/checkbox-group-context';
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import React, { forwardRef } from 'react';
3
- import { useId } from '@atlaskit/ds-lib/react-uid';
3
+ import { useId } from '@atlaskit/ds-lib/use-id';
4
4
  import { Section } from '@atlaskit/menu';
5
5
  import GroupTitle from './internal/components/group-title';
6
6
 
@@ -9,7 +9,7 @@ import handleFocus from '../utils/handle-focus';
9
9
  *
10
10
  * Context provider which maintains the list of focusable elements and a method to
11
11
  * register new menu items.
12
- * This list drives the keyboard navgation of the menu.
12
+ * This list drives the keyboard navigation of the menu.
13
13
  *
14
14
  */
15
15
  export const FocusManagerContext = /*#__PURE__*/createContext({
@@ -25,16 +25,15 @@ const FocusManager = ({
25
25
  onClose
26
26
  }) => {
27
27
  const menuItemRefs = useRef([]);
28
- const registerRef = useCallback(ref => {
29
- if (ref && !menuItemRefs.current.includes(ref)) {
30
- menuItemRefs.current.push(ref);
31
- }
32
- }, []);
28
+ const registerRefCalls = useRef(0);
29
+ const registerRef = useCallback(ref => upsertRefAtFirstPosition(ref, menuItemRefs, registerRefCalls), []);
33
30
  const {
34
31
  isLayerDisabled
35
32
  } = UNSAFE_useLayering();
36
- // Intentionally rebinding on each render
37
33
  useEffect(() => {
34
+ // Intentionally reset count on each render
35
+ registerRefCalls.current = 0;
36
+ // Intentionally rebinding on each render
38
37
  return bind(window, {
39
38
  type: 'keydown',
40
39
  listener: handleFocus(menuItemRefs.current, isLayerDisabled, onClose)
@@ -48,4 +47,37 @@ const FocusManager = ({
48
47
  value: contextValue
49
48
  }, children);
50
49
  };
50
+
51
+ /**
52
+ * Insert the ref at the call position in the array.
53
+ * If the ref is already in the array, move it to the call position.
54
+ * If the call position is after the current position, ignore the call.
55
+ *
56
+ * @param ref
57
+ * @param menuItemRefs
58
+ * @param registerRefCalls
59
+ */
60
+ function upsertRefAtFirstPosition(ref, menuItemRefs, registerRefCalls) {
61
+ const positionOnCall = registerRefCalls.current++;
62
+
63
+ // Add the ref to the correct position
64
+ if (!menuItemRefs.current.includes(ref)) {
65
+ menuItemRefs.current.splice(positionOnCall, 0, ref);
66
+ return;
67
+ }
68
+ const positionCurrent = menuItemRefs.current.indexOf(ref);
69
+ if (positionOnCall === positionCurrent) {
70
+ // No change needed
71
+ return;
72
+ }
73
+ if (positionOnCall > positionCurrent) {
74
+ // Ignore and so keep the count the same
75
+ registerRefCalls.current--;
76
+ return;
77
+ }
78
+
79
+ // Update the position of the ref in the array
80
+ menuItemRefs.current.splice(positionCurrent, 1);
81
+ menuItemRefs.current.splice(positionOnCall, 0, ref);
82
+ }
51
83
  export default FocusManager;
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import React, { createContext, useContext, useState } from 'react';
3
3
  import noop from '@atlaskit/ds-lib/noop';
4
- import { useId } from '@atlaskit/ds-lib/react-uid';
4
+ import { useId } from '@atlaskit/ds-lib/use-id';
5
5
  import { Section } from '@atlaskit/menu';
6
6
  import GroupTitle from '../internal/components/group-title';
7
7
  import { SelectionStoreContext } from '../internal/context/selection-store';
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
3
  var _excluded = ["children", "hasSeparator", "id", "isList", "isScrollable", "overrides", "testId", "title"];
4
4
  import React from 'react';
5
- import { useId } from '@atlaskit/ds-lib/react-uid';
5
+ import { useId } from '@atlaskit/ds-lib/use-id';
6
6
  import Section from '@atlaskit/menu/section';
7
7
  import GroupTitle from '../internal/components/group-title';
8
8
  import { CheckboxGroupContext } from '../internal/context/checkbox-group-context';
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
3
  var _excluded = ["children", "id", "isList", "isScrollable", "title", "testId", "hasSeparator", "overrides"];
4
4
  import React, { forwardRef } from 'react';
5
- import { useId } from '@atlaskit/ds-lib/react-uid';
5
+ import { useId } from '@atlaskit/ds-lib/use-id';
6
6
  import { Section } from '@atlaskit/menu';
7
7
  import GroupTitle from './internal/components/group-title';
8
8
 
@@ -9,7 +9,7 @@ import handleFocus from '../utils/handle-focus';
9
9
  *
10
10
  * Context provider which maintains the list of focusable elements and a method to
11
11
  * register new menu items.
12
- * This list drives the keyboard navgation of the menu.
12
+ * This list drives the keyboard navigation of the menu.
13
13
  *
14
14
  */
15
15
  export var FocusManagerContext = /*#__PURE__*/createContext({
@@ -24,15 +24,16 @@ var FocusManager = function FocusManager(_ref) {
24
24
  var children = _ref.children,
25
25
  onClose = _ref.onClose;
26
26
  var menuItemRefs = useRef([]);
27
+ var registerRefCalls = useRef(0);
27
28
  var registerRef = useCallback(function (ref) {
28
- if (ref && !menuItemRefs.current.includes(ref)) {
29
- menuItemRefs.current.push(ref);
30
- }
29
+ return upsertRefAtFirstPosition(ref, menuItemRefs, registerRefCalls);
31
30
  }, []);
32
31
  var _UNSAFE_useLayering = UNSAFE_useLayering(),
33
32
  isLayerDisabled = _UNSAFE_useLayering.isLayerDisabled;
34
- // Intentionally rebinding on each render
35
33
  useEffect(function () {
34
+ // Intentionally reset count on each render
35
+ registerRefCalls.current = 0;
36
+ // Intentionally rebinding on each render
36
37
  return bind(window, {
37
38
  type: 'keydown',
38
39
  listener: handleFocus(menuItemRefs.current, isLayerDisabled, onClose)
@@ -46,4 +47,37 @@ var FocusManager = function FocusManager(_ref) {
46
47
  value: contextValue
47
48
  }, children);
48
49
  };
50
+
51
+ /**
52
+ * Insert the ref at the call position in the array.
53
+ * If the ref is already in the array, move it to the call position.
54
+ * If the call position is after the current position, ignore the call.
55
+ *
56
+ * @param ref
57
+ * @param menuItemRefs
58
+ * @param registerRefCalls
59
+ */
60
+ function upsertRefAtFirstPosition(ref, menuItemRefs, registerRefCalls) {
61
+ var positionOnCall = registerRefCalls.current++;
62
+
63
+ // Add the ref to the correct position
64
+ if (!menuItemRefs.current.includes(ref)) {
65
+ menuItemRefs.current.splice(positionOnCall, 0, ref);
66
+ return;
67
+ }
68
+ var positionCurrent = menuItemRefs.current.indexOf(ref);
69
+ if (positionOnCall === positionCurrent) {
70
+ // No change needed
71
+ return;
72
+ }
73
+ if (positionOnCall > positionCurrent) {
74
+ // Ignore and so keep the count the same
75
+ registerRefCalls.current--;
76
+ return;
77
+ }
78
+
79
+ // Update the position of the ref in the array
80
+ menuItemRefs.current.splice(positionCurrent, 1);
81
+ menuItemRefs.current.splice(positionOnCall, 0, ref);
82
+ }
49
83
  export default FocusManager;
@@ -7,7 +7,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
7
7
  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; }
8
8
  import React, { createContext, useContext, useState } from 'react';
9
9
  import noop from '@atlaskit/ds-lib/noop';
10
- import { useId } from '@atlaskit/ds-lib/react-uid';
10
+ import { useId } from '@atlaskit/ds-lib/use-id';
11
11
  import { Section } from '@atlaskit/menu';
12
12
  import GroupTitle from '../internal/components/group-title';
13
13
  import { SelectionStoreContext } from '../internal/context/selection-store';
@@ -5,7 +5,7 @@ import { type FocusableElement } from '../../types';
5
5
  *
6
6
  * Context provider which maintains the list of focusable elements and a method to
7
7
  * register new menu items.
8
- * This list drives the keyboard navgation of the menu.
8
+ * This list drives the keyboard navigation of the menu.
9
9
  *
10
10
  */
11
11
  export declare const FocusManagerContext: React.Context<{
@@ -5,7 +5,7 @@ import { type FocusableElement } from '../../types';
5
5
  *
6
6
  * Context provider which maintains the list of focusable elements and a method to
7
7
  * register new menu items.
8
- * This list drives the keyboard navgation of the menu.
8
+ * This list drives the keyboard navigation of the menu.
9
9
  *
10
10
  */
11
11
  export declare const FocusManagerContext: React.Context<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/dropdown-menu",
3
- "version": "12.18.5",
3
+ "version": "12.18.6",
4
4
  "description": "A dropdown menu displays a list of actions or options to a user.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -25,7 +25,7 @@
25
25
  "dependencies": {
26
26
  "@atlaskit/button": "^20.2.0",
27
27
  "@atlaskit/codemod-utils": "^4.2.0",
28
- "@atlaskit/ds-lib": "^2.6.0",
28
+ "@atlaskit/ds-lib": "^2.7.0",
29
29
  "@atlaskit/icon": "^22.20.0",
30
30
  "@atlaskit/layering": "^0.5.0",
31
31
  "@atlaskit/menu": "^2.12.0",