@atlaskit/dropdown-menu 10.1.6 → 11.0.0

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 (215) hide show
  1. package/CHANGELOG.md +147 -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 +106 -0
  30. package/dist/cjs/dropdown-menu-item-group.js +22 -0
  31. package/dist/cjs/dropdown-menu-item.js +65 -0
  32. package/dist/cjs/dropdown-menu.js +193 -0
  33. package/dist/cjs/index.js +18 -26
  34. package/dist/cjs/internal/components/focus-manager.js +59 -0
  35. package/dist/cjs/internal/components/menu-wrapper.js +66 -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 +106 -0
  49. package/dist/cjs/types.js +5 -1
  50. package/dist/cjs/version.json +1 -1
  51. package/dist/es2019/checkbox/dropdown-item-checkbox-group.js +21 -0
  52. package/dist/es2019/checkbox/dropdown-item-checkbox.js +67 -0
  53. package/dist/es2019/dropdown-menu-item-group.js +11 -0
  54. package/dist/es2019/dropdown-menu-item.js +49 -0
  55. package/dist/es2019/dropdown-menu.js +150 -0
  56. package/dist/es2019/index.js +7 -11
  57. package/dist/es2019/internal/components/focus-manager.js +40 -0
  58. package/dist/es2019/internal/components/menu-wrapper.js +44 -0
  59. package/dist/es2019/internal/context/checkbox-group-context.js +6 -0
  60. package/dist/es2019/internal/context/selection-store.js +54 -0
  61. package/dist/es2019/internal/hooks/use-checkbox-state.js +45 -0
  62. package/dist/es2019/internal/hooks/use-radio-state.js +56 -0
  63. package/dist/es2019/internal/hooks/use-register-item-with-focus-manager.js +19 -0
  64. package/dist/es2019/internal/utils/get-icon-colors.js +17 -0
  65. package/dist/es2019/internal/utils/handle-focus.js +48 -0
  66. package/dist/es2019/internal/utils/is-checkbox-item.js +4 -0
  67. package/dist/es2019/internal/utils/is-radio-item.js +4 -0
  68. package/dist/es2019/internal/utils/is-voice-over-supported.js +11 -0
  69. package/dist/es2019/internal/utils/reset-options-in-group.js +7 -0
  70. package/dist/es2019/radio/dropdown-item-radio-group.js +56 -0
  71. package/dist/es2019/radio/dropdown-item-radio.js +67 -0
  72. package/dist/es2019/types.js +1 -0
  73. package/dist/es2019/version.json +1 -1
  74. package/dist/esm/checkbox/dropdown-item-checkbox-group.js +19 -0
  75. package/dist/esm/checkbox/dropdown-item-checkbox.js +80 -0
  76. package/dist/esm/dropdown-menu-item-group.js +11 -0
  77. package/dist/esm/dropdown-menu-item.js +51 -0
  78. package/dist/esm/dropdown-menu.js +166 -0
  79. package/dist/esm/index.js +7 -11
  80. package/dist/esm/internal/components/focus-manager.js +39 -0
  81. package/dist/esm/internal/components/menu-wrapper.js +44 -0
  82. package/dist/esm/internal/context/checkbox-group-context.js +6 -0
  83. package/dist/esm/internal/context/selection-store.js +58 -0
  84. package/dist/esm/internal/hooks/use-checkbox-state.js +55 -0
  85. package/dist/esm/internal/hooks/use-radio-state.js +70 -0
  86. package/dist/esm/internal/hooks/use-register-item-with-focus-manager.js +19 -0
  87. package/dist/esm/internal/utils/get-icon-colors.js +17 -0
  88. package/dist/esm/internal/utils/handle-focus.js +47 -0
  89. package/dist/esm/internal/utils/is-checkbox-item.js +4 -0
  90. package/dist/esm/internal/utils/is-radio-item.js +4 -0
  91. package/dist/esm/internal/utils/is-voice-over-supported.js +15 -0
  92. package/dist/esm/internal/utils/reset-options-in-group.js +13 -0
  93. package/dist/esm/radio/dropdown-item-radio-group.js +66 -0
  94. package/dist/esm/radio/dropdown-item-radio.js +80 -0
  95. package/dist/esm/types.js +1 -0
  96. package/dist/esm/version.json +1 -1
  97. package/dist/types/checkbox/dropdown-item-checkbox-group.d.ts +15 -0
  98. package/dist/types/checkbox/dropdown-item-checkbox.d.ts +12 -0
  99. package/dist/types/dropdown-menu-item-group.d.ts +11 -0
  100. package/dist/types/dropdown-menu-item.d.ts +12 -0
  101. package/dist/types/dropdown-menu.d.ts +12 -0
  102. package/dist/types/index.d.ts +8 -10
  103. package/dist/types/internal/components/focus-manager.d.ts +19 -0
  104. package/dist/types/internal/components/menu-wrapper.d.ts +10 -0
  105. package/dist/types/internal/context/checkbox-group-context.d.ts +5 -0
  106. package/dist/types/internal/context/selection-store.d.ts +27 -0
  107. package/dist/types/internal/hooks/use-checkbox-state.d.ts +14 -0
  108. package/dist/types/internal/hooks/use-radio-state.d.ts +9 -0
  109. package/dist/types/internal/hooks/use-register-item-with-focus-manager.d.ts +4 -0
  110. package/dist/types/internal/utils/get-icon-colors.d.ts +8 -0
  111. package/dist/types/internal/utils/handle-focus.d.ts +2 -0
  112. package/dist/types/internal/utils/is-checkbox-item.d.ts +1 -0
  113. package/dist/types/internal/utils/is-radio-item.d.ts +1 -0
  114. package/dist/types/internal/utils/is-voice-over-supported.d.ts +2 -0
  115. package/dist/types/internal/utils/reset-options-in-group.d.ts +4 -0
  116. package/dist/types/radio/dropdown-item-radio-group.d.ts +25 -0
  117. package/dist/types/radio/dropdown-item-radio.d.ts +12 -0
  118. package/dist/types/types.d.ts +254 -79
  119. package/package.json +41 -23
  120. package/dist/cjs/components/DropdownMenu.js +0 -226
  121. package/dist/cjs/components/DropdownMenuStateless.js +0 -519
  122. package/dist/cjs/components/context/DropdownItemClickManager.js +0 -72
  123. package/dist/cjs/components/context/DropdownItemFocusManager.js +0 -174
  124. package/dist/cjs/components/context/DropdownItemSelectionCache.js +0 -127
  125. package/dist/cjs/components/context/DropdownItemSelectionManager.js +0 -181
  126. package/dist/cjs/components/group/DropdownItemGroup.js +0 -57
  127. package/dist/cjs/components/group/DropdownItemGroupCheckbox.js +0 -16
  128. package/dist/cjs/components/group/DropdownItemGroupRadio.js +0 -16
  129. package/dist/cjs/components/group/ert-group-selection.js +0 -8
  130. package/dist/cjs/components/hoc/withItemSelectionManager.js +0 -62
  131. package/dist/cjs/components/hoc/withToggleInteraction.js +0 -171
  132. package/dist/cjs/components/item/DropdownItem.js +0 -15
  133. package/dist/cjs/components/item/DropdownItemCheckbox.js +0 -24
  134. package/dist/cjs/components/item/DropdownItemRadio.js +0 -24
  135. package/dist/cjs/components/item/ert-item-checkbox.js +0 -8
  136. package/dist/cjs/components/item/ert-item-radio.js +0 -8
  137. package/dist/cjs/components/item/ert-item.js +0 -8
  138. package/dist/cjs/styled/WidthConstrainer.js +0 -29
  139. package/dist/cjs/util/contextNamespace.js +0 -19
  140. package/dist/cjs/util/getDisplayName.js +0 -14
  141. package/dist/cjs/util/keys.js +0 -18
  142. package/dist/cjs/util/safeContextCall.js +0 -27
  143. package/dist/cjs/util/supportsVoiceover.js +0 -17
  144. package/dist/es2019/components/DropdownMenu.js +0 -156
  145. package/dist/es2019/components/DropdownMenuStateless.js +0 -459
  146. package/dist/es2019/components/context/DropdownItemClickManager.js +0 -31
  147. package/dist/es2019/components/context/DropdownItemFocusManager.js +0 -134
  148. package/dist/es2019/components/context/DropdownItemSelectionCache.js +0 -68
  149. package/dist/es2019/components/context/DropdownItemSelectionManager.js +0 -140
  150. package/dist/es2019/components/group/DropdownItemGroup.js +0 -17
  151. package/dist/es2019/components/group/DropdownItemGroupCheckbox.js +0 -3
  152. package/dist/es2019/components/group/DropdownItemGroupRadio.js +0 -3
  153. package/dist/es2019/components/group/ert-group-selection.js +0 -1
  154. package/dist/es2019/components/hoc/withItemSelectionManager.js +0 -20
  155. package/dist/es2019/components/hoc/withToggleInteraction.js +0 -119
  156. package/dist/es2019/components/item/DropdownItem.js +0 -3
  157. package/dist/es2019/components/item/DropdownItemCheckbox.js +0 -5
  158. package/dist/es2019/components/item/DropdownItemRadio.js +0 -5
  159. package/dist/es2019/components/item/ert-item-checkbox.js +0 -1
  160. package/dist/es2019/components/item/ert-item-radio.js +0 -1
  161. package/dist/es2019/components/item/ert-item.js +0 -1
  162. package/dist/es2019/styled/WidthConstrainer.js +0 -6
  163. package/dist/es2019/util/contextNamespace.js +0 -6
  164. package/dist/es2019/util/getDisplayName.js +0 -4
  165. package/dist/es2019/util/keys.js +0 -6
  166. package/dist/es2019/util/safeContextCall.js +0 -10
  167. package/dist/es2019/util/supportsVoiceover.js +0 -5
  168. package/dist/esm/components/DropdownMenu.js +0 -215
  169. package/dist/esm/components/DropdownMenuStateless.js +0 -516
  170. package/dist/esm/components/context/DropdownItemClickManager.js +0 -59
  171. package/dist/esm/components/context/DropdownItemFocusManager.js +0 -164
  172. package/dist/esm/components/context/DropdownItemSelectionCache.js +0 -113
  173. package/dist/esm/components/context/DropdownItemSelectionManager.js +0 -174
  174. package/dist/esm/components/group/DropdownItemGroup.js +0 -43
  175. package/dist/esm/components/group/DropdownItemGroupCheckbox.js +0 -3
  176. package/dist/esm/components/group/DropdownItemGroupRadio.js +0 -3
  177. package/dist/esm/components/group/ert-group-selection.js +0 -1
  178. package/dist/esm/components/hoc/withItemSelectionManager.js +0 -47
  179. package/dist/esm/components/hoc/withToggleInteraction.js +0 -155
  180. package/dist/esm/components/item/DropdownItem.js +0 -3
  181. package/dist/esm/components/item/DropdownItemCheckbox.js +0 -7
  182. package/dist/esm/components/item/DropdownItemRadio.js +0 -7
  183. package/dist/esm/components/item/ert-item-checkbox.js +0 -1
  184. package/dist/esm/components/item/ert-item-radio.js +0 -1
  185. package/dist/esm/components/item/ert-item.js +0 -1
  186. package/dist/esm/styled/WidthConstrainer.js +0 -17
  187. package/dist/esm/util/contextNamespace.js +0 -8
  188. package/dist/esm/util/getDisplayName.js +0 -6
  189. package/dist/esm/util/keys.js +0 -6
  190. package/dist/esm/util/safeContextCall.js +0 -18
  191. package/dist/esm/util/supportsVoiceover.js +0 -9
  192. package/dist/types/components/DropdownMenu.d.ts +0 -36
  193. package/dist/types/components/DropdownMenuStateless.d.ts +0 -82
  194. package/dist/types/components/context/DropdownItemClickManager.d.ts +0 -19
  195. package/dist/types/components/context/DropdownItemFocusManager.d.ts +0 -35
  196. package/dist/types/components/context/DropdownItemSelectionCache.d.ts +0 -31
  197. package/dist/types/components/context/DropdownItemSelectionManager.d.ts +0 -34
  198. package/dist/types/components/group/DropdownItemGroup.d.ts +0 -12
  199. package/dist/types/components/group/DropdownItemGroupCheckbox.d.ts +0 -55
  200. package/dist/types/components/group/DropdownItemGroupRadio.d.ts +0 -55
  201. package/dist/types/components/group/ert-group-selection.d.ts +0 -6
  202. package/dist/types/components/hoc/withItemSelectionManager.d.ts +0 -63
  203. package/dist/types/components/hoc/withToggleInteraction.d.ts +0 -98
  204. package/dist/types/components/item/DropdownItem.d.ts +0 -65
  205. package/dist/types/components/item/DropdownItemCheckbox.d.ts +0 -80
  206. package/dist/types/components/item/DropdownItemRadio.d.ts +0 -80
  207. package/dist/types/components/item/ert-item-checkbox.d.ts +0 -2
  208. package/dist/types/components/item/ert-item-radio.d.ts +0 -2
  209. package/dist/types/components/item/ert-item.d.ts +0 -2
  210. package/dist/types/styled/WidthConstrainer.d.ts +0 -7
  211. package/dist/types/util/contextNamespace.d.ts +0 -4
  212. package/dist/types/util/getDisplayName.d.ts +0 -3
  213. package/dist/types/util/keys.d.ts +0 -6
  214. package/dist/types/util/safeContextCall.d.ts +0 -6
  215. 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 { Date.prototype.toString.call(Reflect.construct(Date, [], 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 { Date.prototype.toString.call(Reflect.construct(Date, [], 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
- // eslint-disable-line react/sort-comp
69
- value: 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 { Date.prototype.toString.call(Reflect.construct(Date, [], 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 { Date.prototype.toString.call(Reflect.construct(Date, [], 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 { Date.prototype.toString.call(Reflect.construct(Date, [], 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;