@atlaskit/dropdown-menu 10.1.8 → 11.0.2

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 (211) hide show
  1. package/CHANGELOG.md +148 -0
  2. package/__perf__/default.tsx +1 -1
  3. package/__perf__/dropdown-menu.tsx +216 -0
  4. package/codemods/11.0.0-lite-mode.tsx +39 -0
  5. package/codemods/__tests__/11.0.0-lite-mode.test.tsx +48 -0
  6. package/codemods/__tests__/convert-position.test.tsx +88 -0
  7. package/codemods/__tests__/convert-triggerType.test.tsx +100 -0
  8. package/codemods/__tests__/deprecate-items.test.tsx +108 -0
  9. package/codemods/__tests__/deprecate-onItemActivated.test.tsx +108 -0
  10. package/codemods/__tests__/deprecate-onPositioned.test.tsx +108 -0
  11. package/codemods/__tests__/deprecate-shouldFitContainer.tsx +108 -0
  12. package/codemods/__tests__/rename-imports.tsx +136 -0
  13. package/codemods/__tests__/replace-position-to-placement.test.tsx +84 -0
  14. package/codemods/__tests__/replace-shouldAllowMultipleLine.test.tsx +122 -0
  15. package/codemods/__tests__/update-component-callsites.tsx +66 -0
  16. package/codemods/migrates/convert-trigger-type.tsx +57 -0
  17. package/codemods/migrates/deprecate-items.tsx +9 -0
  18. package/codemods/migrates/deprecate-onItemActivated.tsx +9 -0
  19. package/codemods/migrates/deprecate-onPositioned.tsx +9 -0
  20. package/codemods/migrates/deprecate-shouldFitContainer.tsx +9 -0
  21. package/codemods/migrates/rename-imports.tsx +22 -0
  22. package/codemods/migrates/replace-position-to-placement.tsx +38 -0
  23. package/codemods/migrates/replace-shouldAllowMultiline.tsx +47 -0
  24. package/codemods/migrates/update-component-callsites.tsx +13 -0
  25. package/codemods/utils/convert-position.tsx +24 -0
  26. package/codemods/utils/create-rename-import.tsx +41 -0
  27. package/codemods/utils/create-update-callsite.tsx +32 -0
  28. package/dist/cjs/checkbox/dropdown-item-checkbox-group.js +31 -0
  29. package/dist/cjs/checkbox/dropdown-item-checkbox.js +108 -0
  30. package/dist/cjs/dropdown-menu-item-group.js +22 -0
  31. package/dist/cjs/dropdown-menu-item.js +67 -0
  32. package/dist/cjs/dropdown-menu.js +194 -0
  33. package/dist/cjs/index.js +21 -29
  34. package/dist/cjs/{components/item/DropdownItemRadio.js → internal/components/focus-manager.js} +40 -9
  35. package/dist/cjs/internal/components/menu-wrapper.js +68 -0
  36. package/dist/cjs/internal/context/checkbox-group-context.js +14 -0
  37. package/dist/cjs/internal/context/selection-store.js +76 -0
  38. package/dist/cjs/internal/hooks/use-checkbox-state.js +68 -0
  39. package/dist/cjs/internal/hooks/use-radio-state.js +84 -0
  40. package/dist/cjs/internal/hooks/use-register-item-with-focus-manager.js +29 -0
  41. package/dist/cjs/internal/utils/get-icon-colors.js +25 -0
  42. package/dist/cjs/internal/utils/handle-focus.js +58 -0
  43. package/dist/cjs/internal/utils/is-checkbox-item.js +11 -0
  44. package/dist/cjs/internal/utils/is-radio-item.js +11 -0
  45. package/dist/cjs/internal/utils/is-voice-over-supported.js +23 -0
  46. package/dist/cjs/internal/utils/reset-options-in-group.js +23 -0
  47. package/dist/cjs/radio/dropdown-item-radio-group.js +89 -0
  48. package/dist/cjs/radio/dropdown-item-radio.js +108 -0
  49. package/dist/cjs/version.json +1 -1
  50. package/dist/es2019/checkbox/dropdown-item-checkbox-group.js +21 -0
  51. package/dist/es2019/checkbox/dropdown-item-checkbox.js +67 -0
  52. package/dist/es2019/dropdown-menu-item-group.js +11 -0
  53. package/dist/es2019/dropdown-menu-item.js +49 -0
  54. package/dist/es2019/dropdown-menu.js +151 -0
  55. package/dist/es2019/index.js +7 -11
  56. package/dist/es2019/internal/components/focus-manager.js +40 -0
  57. package/dist/es2019/internal/components/menu-wrapper.js +44 -0
  58. package/dist/es2019/internal/context/checkbox-group-context.js +6 -0
  59. package/dist/es2019/internal/context/selection-store.js +54 -0
  60. package/dist/es2019/internal/hooks/use-checkbox-state.js +45 -0
  61. package/dist/es2019/internal/hooks/use-radio-state.js +56 -0
  62. package/dist/es2019/internal/hooks/use-register-item-with-focus-manager.js +19 -0
  63. package/dist/es2019/internal/utils/get-icon-colors.js +17 -0
  64. package/dist/es2019/internal/utils/handle-focus.js +48 -0
  65. package/dist/es2019/internal/utils/is-checkbox-item.js +4 -0
  66. package/dist/es2019/internal/utils/is-radio-item.js +4 -0
  67. package/dist/es2019/internal/utils/is-voice-over-supported.js +11 -0
  68. package/dist/es2019/internal/utils/reset-options-in-group.js +7 -0
  69. package/dist/es2019/radio/dropdown-item-radio-group.js +56 -0
  70. package/dist/es2019/radio/dropdown-item-radio.js +67 -0
  71. package/dist/es2019/version.json +1 -1
  72. package/dist/esm/checkbox/dropdown-item-checkbox-group.js +19 -0
  73. package/dist/esm/checkbox/dropdown-item-checkbox.js +81 -0
  74. package/dist/esm/dropdown-menu-item-group.js +11 -0
  75. package/dist/esm/dropdown-menu-item.js +52 -0
  76. package/dist/esm/dropdown-menu.js +168 -0
  77. package/dist/esm/index.js +7 -11
  78. package/dist/esm/internal/components/focus-manager.js +39 -0
  79. package/dist/esm/internal/components/menu-wrapper.js +45 -0
  80. package/dist/esm/internal/context/checkbox-group-context.js +6 -0
  81. package/dist/esm/internal/context/selection-store.js +58 -0
  82. package/dist/esm/internal/hooks/use-checkbox-state.js +55 -0
  83. package/dist/esm/internal/hooks/use-radio-state.js +70 -0
  84. package/dist/esm/internal/hooks/use-register-item-with-focus-manager.js +19 -0
  85. package/dist/esm/internal/utils/get-icon-colors.js +17 -0
  86. package/dist/esm/internal/utils/handle-focus.js +47 -0
  87. package/dist/esm/internal/utils/is-checkbox-item.js +4 -0
  88. package/dist/esm/internal/utils/is-radio-item.js +4 -0
  89. package/dist/esm/internal/utils/is-voice-over-supported.js +15 -0
  90. package/dist/esm/internal/utils/reset-options-in-group.js +13 -0
  91. package/dist/esm/radio/dropdown-item-radio-group.js +66 -0
  92. package/dist/esm/radio/dropdown-item-radio.js +81 -0
  93. package/dist/esm/version.json +1 -1
  94. package/dist/types/checkbox/dropdown-item-checkbox-group.d.ts +16 -0
  95. package/dist/types/checkbox/dropdown-item-checkbox.d.ts +13 -0
  96. package/dist/types/dropdown-menu-item-group.d.ts +11 -0
  97. package/dist/types/dropdown-menu-item.d.ts +13 -0
  98. package/dist/types/dropdown-menu.d.ts +13 -0
  99. package/dist/types/index.d.ts +8 -10
  100. package/dist/types/internal/components/focus-manager.d.ts +19 -0
  101. package/dist/types/internal/components/menu-wrapper.d.ts +11 -0
  102. package/dist/types/internal/context/checkbox-group-context.d.ts +5 -0
  103. package/dist/types/internal/context/selection-store.d.ts +27 -0
  104. package/dist/types/internal/hooks/use-checkbox-state.d.ts +14 -0
  105. package/dist/types/internal/hooks/use-radio-state.d.ts +9 -0
  106. package/dist/types/internal/hooks/use-register-item-with-focus-manager.d.ts +4 -0
  107. package/dist/types/internal/utils/get-icon-colors.d.ts +8 -0
  108. package/dist/types/internal/utils/handle-focus.d.ts +2 -0
  109. package/dist/types/internal/utils/is-checkbox-item.d.ts +1 -0
  110. package/dist/types/internal/utils/is-radio-item.d.ts +1 -0
  111. package/dist/types/internal/utils/is-voice-over-supported.d.ts +2 -0
  112. package/dist/types/internal/utils/reset-options-in-group.d.ts +4 -0
  113. package/dist/types/radio/dropdown-item-radio-group.d.ts +25 -0
  114. package/dist/types/radio/dropdown-item-radio.d.ts +13 -0
  115. package/dist/types/types.d.ts +254 -79
  116. package/package.json +39 -23
  117. package/dist/cjs/components/DropdownMenu.js +0 -230
  118. package/dist/cjs/components/DropdownMenuStateless.js +0 -523
  119. package/dist/cjs/components/context/DropdownItemClickManager.js +0 -72
  120. package/dist/cjs/components/context/DropdownItemFocusManager.js +0 -178
  121. package/dist/cjs/components/context/DropdownItemSelectionCache.js +0 -131
  122. package/dist/cjs/components/context/DropdownItemSelectionManager.js +0 -185
  123. package/dist/cjs/components/group/DropdownItemGroup.js +0 -61
  124. package/dist/cjs/components/group/DropdownItemGroupCheckbox.js +0 -16
  125. package/dist/cjs/components/group/DropdownItemGroupRadio.js +0 -16
  126. package/dist/cjs/components/group/ert-group-selection.js +0 -8
  127. package/dist/cjs/components/hoc/withItemSelectionManager.js +0 -66
  128. package/dist/cjs/components/hoc/withToggleInteraction.js +0 -175
  129. package/dist/cjs/components/item/DropdownItem.js +0 -19
  130. package/dist/cjs/components/item/DropdownItemCheckbox.js +0 -28
  131. package/dist/cjs/components/item/ert-item-checkbox.js +0 -8
  132. package/dist/cjs/components/item/ert-item-radio.js +0 -8
  133. package/dist/cjs/components/item/ert-item.js +0 -8
  134. package/dist/cjs/styled/WidthConstrainer.js +0 -21
  135. package/dist/cjs/util/contextNamespace.js +0 -19
  136. package/dist/cjs/util/getDisplayName.js +0 -14
  137. package/dist/cjs/util/keys.js +0 -18
  138. package/dist/cjs/util/safeContextCall.js +0 -27
  139. package/dist/cjs/util/supportsVoiceover.js +0 -17
  140. package/dist/es2019/components/DropdownMenu.js +0 -156
  141. package/dist/es2019/components/DropdownMenuStateless.js +0 -459
  142. package/dist/es2019/components/context/DropdownItemClickManager.js +0 -31
  143. package/dist/es2019/components/context/DropdownItemFocusManager.js +0 -134
  144. package/dist/es2019/components/context/DropdownItemSelectionCache.js +0 -68
  145. package/dist/es2019/components/context/DropdownItemSelectionManager.js +0 -140
  146. package/dist/es2019/components/group/DropdownItemGroup.js +0 -17
  147. package/dist/es2019/components/group/DropdownItemGroupCheckbox.js +0 -3
  148. package/dist/es2019/components/group/DropdownItemGroupRadio.js +0 -3
  149. package/dist/es2019/components/group/ert-group-selection.js +0 -1
  150. package/dist/es2019/components/hoc/withItemSelectionManager.js +0 -20
  151. package/dist/es2019/components/hoc/withToggleInteraction.js +0 -119
  152. package/dist/es2019/components/item/DropdownItem.js +0 -3
  153. package/dist/es2019/components/item/DropdownItemCheckbox.js +0 -5
  154. package/dist/es2019/components/item/DropdownItemRadio.js +0 -5
  155. package/dist/es2019/components/item/ert-item-checkbox.js +0 -1
  156. package/dist/es2019/components/item/ert-item-radio.js +0 -1
  157. package/dist/es2019/components/item/ert-item.js +0 -1
  158. package/dist/es2019/styled/WidthConstrainer.js +0 -6
  159. package/dist/es2019/util/contextNamespace.js +0 -6
  160. package/dist/es2019/util/getDisplayName.js +0 -4
  161. package/dist/es2019/util/keys.js +0 -6
  162. package/dist/es2019/util/safeContextCall.js +0 -10
  163. package/dist/es2019/util/supportsVoiceover.js +0 -5
  164. package/dist/esm/components/DropdownMenu.js +0 -215
  165. package/dist/esm/components/DropdownMenuStateless.js +0 -516
  166. package/dist/esm/components/context/DropdownItemClickManager.js +0 -59
  167. package/dist/esm/components/context/DropdownItemFocusManager.js +0 -164
  168. package/dist/esm/components/context/DropdownItemSelectionCache.js +0 -113
  169. package/dist/esm/components/context/DropdownItemSelectionManager.js +0 -174
  170. package/dist/esm/components/group/DropdownItemGroup.js +0 -43
  171. package/dist/esm/components/group/DropdownItemGroupCheckbox.js +0 -3
  172. package/dist/esm/components/group/DropdownItemGroupRadio.js +0 -3
  173. package/dist/esm/components/group/ert-group-selection.js +0 -1
  174. package/dist/esm/components/hoc/withItemSelectionManager.js +0 -47
  175. package/dist/esm/components/hoc/withToggleInteraction.js +0 -155
  176. package/dist/esm/components/item/DropdownItem.js +0 -3
  177. package/dist/esm/components/item/DropdownItemCheckbox.js +0 -7
  178. package/dist/esm/components/item/DropdownItemRadio.js +0 -7
  179. package/dist/esm/components/item/ert-item-checkbox.js +0 -1
  180. package/dist/esm/components/item/ert-item-radio.js +0 -1
  181. package/dist/esm/components/item/ert-item.js +0 -1
  182. package/dist/esm/styled/WidthConstrainer.js +0 -9
  183. package/dist/esm/util/contextNamespace.js +0 -8
  184. package/dist/esm/util/getDisplayName.js +0 -6
  185. package/dist/esm/util/keys.js +0 -6
  186. package/dist/esm/util/safeContextCall.js +0 -18
  187. package/dist/esm/util/supportsVoiceover.js +0 -9
  188. package/dist/types/components/DropdownMenu.d.ts +0 -36
  189. package/dist/types/components/DropdownMenuStateless.d.ts +0 -82
  190. package/dist/types/components/context/DropdownItemClickManager.d.ts +0 -19
  191. package/dist/types/components/context/DropdownItemFocusManager.d.ts +0 -35
  192. package/dist/types/components/context/DropdownItemSelectionCache.d.ts +0 -31
  193. package/dist/types/components/context/DropdownItemSelectionManager.d.ts +0 -34
  194. package/dist/types/components/group/DropdownItemGroup.d.ts +0 -12
  195. package/dist/types/components/group/DropdownItemGroupCheckbox.d.ts +0 -55
  196. package/dist/types/components/group/DropdownItemGroupRadio.d.ts +0 -55
  197. package/dist/types/components/group/ert-group-selection.d.ts +0 -6
  198. package/dist/types/components/hoc/withItemSelectionManager.d.ts +0 -63
  199. package/dist/types/components/hoc/withToggleInteraction.d.ts +0 -98
  200. package/dist/types/components/item/DropdownItem.d.ts +0 -65
  201. package/dist/types/components/item/DropdownItemCheckbox.d.ts +0 -80
  202. package/dist/types/components/item/DropdownItemRadio.d.ts +0 -80
  203. package/dist/types/components/item/ert-item-checkbox.d.ts +0 -2
  204. package/dist/types/components/item/ert-item-radio.d.ts +0 -2
  205. package/dist/types/components/item/ert-item.d.ts +0 -2
  206. package/dist/types/styled/WidthConstrainer.d.ts +0 -7
  207. package/dist/types/util/contextNamespace.d.ts +0 -4
  208. package/dist/types/util/getDisplayName.d.ts +0 -3
  209. package/dist/types/util/keys.d.ts +0 -6
  210. package/dist/types/util/safeContextCall.d.ts +0 -6
  211. package/dist/types/util/supportsVoiceover.d.ts +0 -2
@@ -1,164 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
4
- import _inherits from "@babel/runtime/helpers/inherits";
5
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
-
9
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
10
-
11
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
12
-
13
- import React, { Component } from 'react';
14
- import PropTypes from 'prop-types';
15
- import { focusManagerContext } from '../../util/contextNamespace';
16
- import { KEY_DOWN, KEY_TAB, KEY_UP } from '../../util/keys';
17
-
18
- var DropdownItemFocusManager = /*#__PURE__*/function (_Component) {
19
- _inherits(DropdownItemFocusManager, _Component);
20
-
21
- var _super = _createSuper(DropdownItemFocusManager);
22
-
23
- function DropdownItemFocusManager() {
24
- var _this;
25
-
26
- _classCallCheck(this, DropdownItemFocusManager);
27
-
28
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
29
- args[_key] = arguments[_key];
30
- }
31
-
32
- _this = _super.call.apply(_super, [this].concat(args));
33
-
34
- _defineProperty(_assertThisInitialized(_this), "registeredItems", []);
35
-
36
- _defineProperty(_assertThisInitialized(_this), "handleItemRegistered", function (itemId, itemNode) {
37
- _this.registeredItems.push({
38
- itemId: itemId,
39
- itemNode: itemNode
40
- });
41
-
42
- if (_this.props.autoFocus && _this.registeredItems.length === 1) {
43
- _this.focusedItemId = itemId;
44
- itemNode.focus();
45
- }
46
- });
47
-
48
- _defineProperty(_assertThisInitialized(_this), "handleItemDeregistered", function (itemId) {
49
- _this.registeredItems = _this.registeredItems.filter(function (item) {
50
- return item.itemId !== itemId;
51
- });
52
- });
53
-
54
- _defineProperty(_assertThisInitialized(_this), "handleItemFocused", function (itemId) {
55
- _this.focusedItemId = itemId;
56
- });
57
-
58
- _defineProperty(_assertThisInitialized(_this), "handleItemUpdated", function (itemId, itemNode) {
59
- var matchingIndex = -1;
60
-
61
- for (var i = 0; i < _this.registeredItems.length; i++) {
62
- if (_this.registeredItems[i].itemId === itemId) {
63
- matchingIndex = i;
64
- break;
65
- }
66
- }
67
-
68
- if (matchingIndex === -1) {
69
- _this.handleItemRegistered(itemId, itemNode);
70
-
71
- return;
72
- }
73
-
74
- _this.registeredItems[matchingIndex].itemNode = itemNode;
75
-
76
- if (_this.focusedItemIndex() === matchingIndex) {
77
- itemNode.focus();
78
- }
79
- });
80
-
81
- _defineProperty(_assertThisInitialized(_this), "focusedItemIndex", function () {
82
- var _assertThisInitialize = _assertThisInitialized(_this),
83
- focusedItemId = _assertThisInitialize.focusedItemId,
84
- registeredItems = _assertThisInitialize.registeredItems;
85
-
86
- for (var i = 0; i < registeredItems.length; i++) {
87
- if (registeredItems[i].itemId === focusedItemId) {
88
- return i;
89
- }
90
- }
91
-
92
- return -1;
93
- });
94
-
95
- _defineProperty(_assertThisInitialized(_this), "handleKeyboard", function (event) {
96
- var key = event.key,
97
- shiftKey = event.shiftKey;
98
-
99
- var focusedItemIndex = _this.focusedItemIndex();
100
-
101
- if (key === KEY_UP || key === KEY_DOWN) {
102
- // We prevent default here to avoid page scrolling when up/down
103
- // pressed while dropdown is focused.
104
- event.preventDefault();
105
-
106
- if (focusedItemIndex < 0) {
107
- return;
108
- }
109
-
110
- var nextItemIndex = key === KEY_UP ? Math.max(0, focusedItemIndex - 1) : Math.min(_this.registeredItems.length - 1, focusedItemIndex + 1);
111
-
112
- _this.registeredItems[nextItemIndex].itemNode.focus();
113
- }
114
-
115
- if (key === KEY_TAB) {
116
- if (!shiftKey && focusedItemIndex === _this.registeredItems.length - 1) {
117
- if (_this.props.close) {
118
- _this.props.close({
119
- event: event,
120
- source: 'keydown'
121
- });
122
- }
123
- }
124
-
125
- if (shiftKey && focusedItemIndex === 0) {
126
- if (_this.props.close) {
127
- _this.props.close({
128
- event: event,
129
- source: 'keydown'
130
- });
131
- }
132
- }
133
- }
134
- });
135
-
136
- return _this;
137
- }
138
-
139
- _createClass(DropdownItemFocusManager, [{
140
- key: "getChildContext",
141
- value: function getChildContext() {
142
- return _defineProperty({}, focusManagerContext, {
143
- itemFocused: this.handleItemFocused,
144
- registerItem: this.handleItemRegistered,
145
- deregisterItem: this.handleItemDeregistered,
146
- updateItem: this.handleItemUpdated
147
- });
148
- }
149
- }, {
150
- key: "render",
151
- value: function render() {
152
- // eslint-disable-next-line jsx-a11y/no-static-element-interactions
153
- return /*#__PURE__*/React.createElement("div", {
154
- onKeyDown: this.handleKeyboard
155
- }, this.props.children);
156
- }
157
- }]);
158
-
159
- return DropdownItemFocusManager;
160
- }(Component);
161
-
162
- _defineProperty(DropdownItemFocusManager, "childContextTypes", _defineProperty({}, focusManagerContext, PropTypes.object));
163
-
164
- export { DropdownItemFocusManager as default };
@@ -1,113 +0,0 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/createClass";
4
- import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
5
- import _inherits from "@babel/runtime/helpers/inherits";
6
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
7
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
8
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
9
-
10
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
11
-
12
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
13
-
14
- import React, { Component } from 'react';
15
- import find from 'array-find';
16
- import PropTypes from 'prop-types';
17
- import { selectionCacheContext } from '../../util/contextNamespace';
18
-
19
- var isItemInList = function isItemInList(itemList, itemId, groupId) {
20
- return Boolean(find(itemList, function (item) {
21
- return item.id === itemId && item.groupId === groupId;
22
- }));
23
- };
24
-
25
- var DropdownItemSelectionCache = /*#__PURE__*/function (_Component) {
26
- _inherits(DropdownItemSelectionCache, _Component);
27
-
28
- var _super = _createSuper(DropdownItemSelectionCache);
29
-
30
- function DropdownItemSelectionCache() {
31
- var _this;
32
-
33
- _classCallCheck(this, DropdownItemSelectionCache);
34
-
35
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
36
- args[_key] = arguments[_key];
37
- }
38
-
39
- _this = _super.call.apply(_super, [this].concat(args));
40
-
41
- _defineProperty(_assertThisInitialized(_this), "state", {
42
- lastCacheUpdate: 0
43
- });
44
-
45
- _defineProperty(_assertThisInitialized(_this), "selectedItems", []);
46
-
47
- _defineProperty(_assertThisInitialized(_this), "alreadyDefaultedItems", []);
48
-
49
- _defineProperty(_assertThisInitialized(_this), "handleItemSelectionsChanged", function (groupId, newGroupSelections) {
50
- var newSelectedItems = [].concat(_toConsumableArray(_this.selectedItems.filter(function (item) {
51
- return item.groupId !== groupId;
52
- })), _toConsumableArray(newGroupSelections));
53
- _this.selectedItems = newSelectedItems; // We store selectedItems in an instance variable (this.selectedItems) instead of state,
54
- // because if multiple children update the cache at the same time it causes unexpected
55
- // behaviour due to the asynchronous behaviour of setState. So we need to trigger setState
56
- // with a different value to cause the children to be updated with their new selection values.
57
-
58
- _this.setState({
59
- lastCacheUpdate: Date.now()
60
- });
61
- });
62
-
63
- return _this;
64
- }
65
-
66
- _createClass(DropdownItemSelectionCache, [{
67
- key: "getChildContext",
68
- value: // eslint-disable-line react/sort-comp
69
- function getChildContext() {
70
- var _this2 = this;
71
-
72
- return _defineProperty({}, selectionCacheContext, {
73
- // This function returns true/false describing whether the supplied navigation item
74
- // (which must have a unique item and group ID) is currently selected - this is used
75
- // by radio and checkbox dropdown items to retreive their 'selected' state when they
76
- // re-mount, which happens when the dropdown is closed and then re-opened.
77
- isItemSelected: function isItemSelected(groupId, itemId) {
78
- return isItemInList(_this2.selectedItems, itemId, groupId);
79
- },
80
- itemsInGroup: function itemsInGroup(groupId) {
81
- return _this2.selectedItems.filter(function (item) {
82
- return item.groupId === groupId;
83
- });
84
- },
85
- itemSelectionsChanged: this.handleItemSelectionsChanged,
86
- hasItemAlreadyHadDefaultSelectedApplied: function hasItemAlreadyHadDefaultSelectedApplied(groupId, itemId) {
87
- return isItemInList(_this2.alreadyDefaultedItems, itemId, groupId);
88
- },
89
- markItemAsDefaultApplied: function markItemAsDefaultApplied(groupId, itemId) {
90
- _this2.alreadyDefaultedItems.push({
91
- id: itemId,
92
- groupId: groupId
93
- });
94
- }
95
- });
96
- }
97
- }, {
98
- key: "render",
99
- value: function render() {
100
- return /*#__PURE__*/React.createElement("div", null, this.props.children);
101
- }
102
- }]);
103
-
104
- return DropdownItemSelectionCache;
105
- }(Component);
106
-
107
- _defineProperty(DropdownItemSelectionCache, "childContextTypes", _defineProperty({}, selectionCacheContext, PropTypes.shape({
108
- isItemSelected: PropTypes.func,
109
- itemsInGroup: PropTypes.func,
110
- itemSelectionsChanged: PropTypes.func
111
- })));
112
-
113
- export { DropdownItemSelectionCache as default };
@@ -1,174 +0,0 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/createClass";
4
- import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
5
- import _inherits from "@babel/runtime/helpers/inherits";
6
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
7
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
8
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
9
-
10
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
11
-
12
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
13
-
14
- import React, { Component } from 'react';
15
- import PropTypes from 'prop-types';
16
- import { selectionCacheContext, selectionManagerContext } from '../../util/contextNamespace';
17
-
18
- var DropdownItemSelectionManager = /*#__PURE__*/function (_Component) {
19
- _inherits(DropdownItemSelectionManager, _Component);
20
-
21
- var _super = _createSuper(DropdownItemSelectionManager);
22
-
23
- function DropdownItemSelectionManager() {
24
- var _this;
25
-
26
- _classCallCheck(this, DropdownItemSelectionManager);
27
-
28
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
29
- args[_key] = arguments[_key];
30
- }
31
-
32
- _this = _super.call.apply(_super, [this].concat(args));
33
-
34
- _defineProperty(_assertThisInitialized(_this), "setItemSelected", function (itemId, isSelected, defaultSelected) {
35
- var _this$props = _this.props,
36
- behavior = _this$props.behavior,
37
- groupId = _this$props.groupId;
38
-
39
- var setSelected = function setSelected(finalBool) {
40
- if (behavior === 'checkbox' || behavior === 'menuitemcheckbox') {
41
- _this.setCheckboxItemSelected(itemId, finalBool);
42
- } else if (behavior === 'radio' || behavior === 'menuitemradio') {
43
- _this.setRadioItemSelected(itemId, finalBool);
44
- }
45
- }; // If a radio or checkbox item has defaultSelected set on it, that it will try to set its
46
- // selected state to true each time it mounts (which happens whenever the dropdown is re-
47
- // opened by the user. The following check makes sure that the defaultSelected behaviour
48
- // only applies on the first mount of the radio/checkbox.
49
-
50
-
51
- if (typeof isSelected === 'boolean') {
52
- // If isSelected is explicitly provided, set it to that
53
- setSelected(isSelected);
54
- } else if (defaultSelected) {
55
- if (!_this.hasAlreadyAppliedDefaultSelected(itemId)) {
56
- // If using defaultSelected and this is first mount, select the item
57
- setSelected(true);
58
-
59
- _this.context[selectionCacheContext].markItemAsDefaultApplied(groupId, itemId);
60
- } else {
61
- // If using defaultSelected and not first mount, set isSelected to cached value
62
- setSelected(_this.isItemSelectedInCache(itemId));
63
- }
64
- } else {
65
- setSelected(_this.isItemSelectedInCache(itemId));
66
- }
67
- });
68
-
69
- _defineProperty(_assertThisInitialized(_this), "setCheckboxItemSelected", function (itemId, isSelected) {
70
- var cache = _this.context[selectionCacheContext];
71
- var alreadySelected = cache.itemsInGroup(_this.props.groupId);
72
- var isAlreadySelected = cache.isItemSelected(_this.props.groupId, itemId);
73
-
74
- if (isSelected && !isAlreadySelected) {
75
- _this.updateCacheContextWithSelections([].concat(_toConsumableArray(alreadySelected), [{
76
- id: itemId,
77
- groupId: _this.props.groupId
78
- }]));
79
- } else if (!isSelected && isAlreadySelected) {
80
- var withoutCurrentItem = alreadySelected.filter(function (item) {
81
- return item.id !== itemId;
82
- });
83
-
84
- _this.updateCacheContextWithSelections(withoutCurrentItem);
85
- }
86
- });
87
-
88
- _defineProperty(_assertThisInitialized(_this), "setRadioItemSelected", function (itemId, isSelected) {
89
- var cache = _this.context[selectionCacheContext];
90
- var isAlreadySelected = cache.isItemSelected(_this.props.groupId, itemId);
91
-
92
- if (isAlreadySelected && !isSelected) {
93
- _this.updateCacheContextWithSelections([]);
94
- } else if (!isAlreadySelected && isSelected) {
95
- _this.updateCacheContextWithSelections([{
96
- id: itemId,
97
- groupId: _this.props.groupId
98
- }]);
99
- }
100
- });
101
-
102
- _defineProperty(_assertThisInitialized(_this), "isItemSelectedInCache", function (itemId) {
103
- return _this.context[selectionCacheContext].isItemSelected(_this.props.groupId, itemId);
104
- });
105
-
106
- _defineProperty(_assertThisInitialized(_this), "handleItemClicked", function (clickedItemId) {
107
- var behavior = _this.props.behavior;
108
-
109
- if (behavior === 'checkbox' || behavior === 'menuitemcheckbox') {
110
- _this.handleCheckboxItemClicked(clickedItemId);
111
- } else if (behavior === 'radio' || behavior === 'menuitemradio') {
112
- _this.handleRadioItemClicked(clickedItemId);
113
- }
114
- });
115
-
116
- _defineProperty(_assertThisInitialized(_this), "hasAlreadyAppliedDefaultSelected", function (itemId) {
117
- return _this.context[selectionCacheContext].hasItemAlreadyHadDefaultSelectedApplied(_this.props.groupId, itemId);
118
- });
119
-
120
- _defineProperty(_assertThisInitialized(_this), "handleCheckboxItemClicked", function (clickedItemId) {
121
- var cache = _this.context[selectionCacheContext];
122
- var itemsInGroup = cache.itemsInGroup(_this.props.groupId);
123
- var newSelections = cache.isItemSelected(_this.props.groupId, clickedItemId) ? itemsInGroup.filter(function (item) {
124
- return item.id !== clickedItemId;
125
- }) : [].concat(_toConsumableArray(itemsInGroup), [{
126
- id: clickedItemId,
127
- groupId: _this.props.groupId
128
- }]);
129
-
130
- _this.updateCacheContextWithSelections(newSelections);
131
- });
132
-
133
- _defineProperty(_assertThisInitialized(_this), "handleRadioItemClicked", function (clickedItemId) {
134
- _this.updateCacheContextWithSelections([{
135
- id: clickedItemId,
136
- groupId: _this.props.groupId
137
- }]);
138
- });
139
-
140
- _defineProperty(_assertThisInitialized(_this), "updateCacheContextWithSelections", function (itemSelections) {
141
- _this.context[selectionCacheContext].itemSelectionsChanged(_this.props.groupId, itemSelections);
142
- });
143
-
144
- return _this;
145
- }
146
-
147
- _createClass(DropdownItemSelectionManager, [{
148
- key: "getChildContext",
149
- value: function getChildContext() {
150
- var _this2 = this;
151
-
152
- return _defineProperty({}, selectionManagerContext, {
153
- isItemSelected: function isItemSelected(itemId) {
154
- return _this2.context[selectionCacheContext].isItemSelected(_this2.props.groupId, itemId);
155
- },
156
- itemClicked: this.handleItemClicked,
157
- setItemSelected: this.setItemSelected
158
- });
159
- }
160
- }, {
161
- key: "render",
162
- value: function render() {
163
- return /*#__PURE__*/React.createElement("div", null, this.props.children);
164
- }
165
- }]);
166
-
167
- return DropdownItemSelectionManager;
168
- }(Component);
169
-
170
- _defineProperty(DropdownItemSelectionManager, "childContextTypes", _defineProperty({}, selectionManagerContext, PropTypes.object));
171
-
172
- _defineProperty(DropdownItemSelectionManager, "contextTypes", _defineProperty({}, selectionCacheContext, PropTypes.object.isRequired));
173
-
174
- export { DropdownItemSelectionManager as default };
@@ -1,43 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _inherits from "@babel/runtime/helpers/inherits";
4
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
-
7
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
8
-
9
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
10
-
11
- import React, { Component } from 'react';
12
- import { ItemGroup } from '@atlaskit/item';
13
-
14
- var DropdownItemGroup = /*#__PURE__*/function (_Component) {
15
- _inherits(DropdownItemGroup, _Component);
16
-
17
- var _super = _createSuper(DropdownItemGroup);
18
-
19
- function DropdownItemGroup() {
20
- _classCallCheck(this, DropdownItemGroup);
21
-
22
- return _super.apply(this, arguments);
23
- }
24
-
25
- _createClass(DropdownItemGroup, [{
26
- key: "render",
27
- value: function render() {
28
- var _this$props = this.props,
29
- children = _this$props.children,
30
- elemAfter = _this$props.elemAfter,
31
- title = _this$props.title;
32
- return /*#__PURE__*/React.createElement(ItemGroup, {
33
- elemAfter: elemAfter,
34
- title: title,
35
- role: "menu"
36
- }, children);
37
- }
38
- }]);
39
-
40
- return DropdownItemGroup;
41
- }(Component);
42
-
43
- export { DropdownItemGroup as default };
@@ -1,3 +0,0 @@
1
- import withItemSelectionManager from '../hoc/withItemSelectionManager';
2
- import DropdownItemGroup from './DropdownItemGroup';
3
- export default withItemSelectionManager(DropdownItemGroup, 'checkbox');
@@ -1,3 +0,0 @@
1
- import withItemSelectionManager from '../hoc/withItemSelectionManager';
2
- import DropdownItemGroup from './DropdownItemGroup';
3
- export default withItemSelectionManager(DropdownItemGroup, 'radio');
@@ -1 +0,0 @@
1
- export default function (_) {}
@@ -1,47 +0,0 @@
1
- import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/createClass";
4
- import _inherits from "@babel/runtime/helpers/inherits";
5
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
-
8
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
9
-
10
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
11
-
12
- import React, { Component } from 'react';
13
- import DropdownItemSelectionManager from '../context/DropdownItemSelectionManager';
14
-
15
- // HOC that typically wraps @atlaskit/item/ItemGroup
16
- var withDropdownItemSelectionManager = function withDropdownItemSelectionManager(WrappedComponent, selectionBehavior) {
17
- return /*#__PURE__*/function (_Component) {
18
- _inherits(WithDropdownItemSelectionManager, _Component);
19
-
20
- var _super = _createSuper(WithDropdownItemSelectionManager);
21
-
22
- function WithDropdownItemSelectionManager() {
23
- _classCallCheck(this, WithDropdownItemSelectionManager);
24
-
25
- return _super.apply(this, arguments);
26
- }
27
-
28
- _createClass(WithDropdownItemSelectionManager, [{
29
- key: "render",
30
- value: function render() {
31
- var _this$props = this.props,
32
- children = _this$props.children,
33
- id = _this$props.id,
34
- otherProps = _objectWithoutProperties(_this$props, ["children", "id"]);
35
-
36
- return /*#__PURE__*/React.createElement(WrappedComponent, otherProps, /*#__PURE__*/React.createElement(DropdownItemSelectionManager, {
37
- groupId: id,
38
- behavior: selectionBehavior
39
- }, children));
40
- }
41
- }]);
42
-
43
- return WithDropdownItemSelectionManager;
44
- }(Component);
45
- };
46
-
47
- export default withDropdownItemSelectionManager;