@jetbrains/ring-ui 4.1.0-beta.3 → 4.1.1

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 (234) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +17 -15
  3. package/babel.config.js +3 -2
  4. package/components/alert/alert.js +9 -3
  5. package/components/alert/alert.test.js +21 -48
  6. package/components/alert/container.css +1 -1
  7. package/components/alert/container.test.js +3 -13
  8. package/components/alert-service/alert-service.examples.css +18 -0
  9. package/components/alert-service/alert-service.examples.js +21 -0
  10. package/components/alert-service/alert-service.js +10 -3
  11. package/components/analytics/analytics__fus-plugin.js +3 -3
  12. package/components/analytics/analytics__ga-plugin.js +2 -2
  13. package/components/auth/auth.test.js +14 -7
  14. package/components/auth/auth__core.js +64 -33
  15. package/components/auth-dialog/auth-dialog.css +2 -3
  16. package/components/auth-dialog/auth-dialog.js +4 -1
  17. package/components/auth-dialog/auth-dialog.test.js +3 -19
  18. package/components/avatar/avatar.css +4 -1
  19. package/components/avatar/avatar.examples.js +3 -2
  20. package/components/avatar/avatar.js +34 -6
  21. package/components/avatar/avatar.test.js +20 -17
  22. package/components/avatar/fallback-avatar.js +136 -0
  23. package/components/avatar-editor-ng/avatar-editor-ng.css +2 -2
  24. package/components/avatar-editor-ng/avatar-editor-ng.js +2 -1
  25. package/components/avatar-editor-ng/{avatar-editor-ng.html → avatar-editor-ng__template.js} +2 -2
  26. package/components/badge/badge.test.js +13 -20
  27. package/components/button/button.css +2 -2
  28. package/components/button/button.js +4 -1
  29. package/components/button/button.test.js +32 -33
  30. package/components/button-group/button-group.js +1 -1
  31. package/components/button-group/caption.js +1 -1
  32. package/components/button-ng/button-ng.js +1 -1
  33. package/components/button-set-ng/button-set-ng.js +3 -1
  34. package/components/checkbox/checkbox.css +1 -1
  35. package/components/code/code.js +2 -5
  36. package/components/confirm/confirm.js +1 -0
  37. package/components/confirm-service/confirm-service.js +5 -5
  38. package/components/content-layout/content-layout.css +1 -1
  39. package/components/data-list/data-list.css +1 -1
  40. package/components/date-picker/date-input.js +5 -4
  41. package/components/date-picker/date-picker.css +34 -22
  42. package/components/date-picker/date-picker.js +16 -14
  43. package/components/date-picker/date-popup.js +22 -7
  44. package/components/date-picker/month-names.js +8 -5
  45. package/components/date-picker/month.js +6 -2
  46. package/components/date-picker/weekdays.js +10 -2
  47. package/components/dialog/dialog.examples.js +3 -1
  48. package/components/dialog/dialog.js +10 -5
  49. package/components/dialog/dialog.test.js +1 -1
  50. package/components/dialog/dialog__body-scroll-preventer.js +51 -31
  51. package/components/dialog-ng/dialog-ng.js +10 -10
  52. package/components/dialog-ng/{dialog-ng.html → dialog-ng__template.js} +2 -2
  53. package/components/dropdown/dropdown.examples.js +36 -1
  54. package/components/dropdown/dropdown.test.js +2 -2
  55. package/components/dropdown-menu/dropdown-menu.examples.js +47 -0
  56. package/components/dropdown-menu/dropdown-menu.js +117 -0
  57. package/components/dropdown-menu/dropdown-menu.test.js +76 -0
  58. package/components/error-bubble/error-bubble-legacy.css +1 -1
  59. package/components/error-bubble/error-bubble.css +1 -1
  60. package/components/error-bubble/error-bubble.examples.js +1 -1
  61. package/components/error-page/error-page.css +2 -2
  62. package/components/footer-ng/footer-ng.js +13 -3
  63. package/components/form/form.css +2 -2
  64. package/components/form-ng/form-ng.js +3 -1
  65. package/components/global/global.css +1 -1
  66. package/components/global/theme.js +1 -1
  67. package/components/global/variables.css +8 -1
  68. package/components/grid/grid.css +10 -9
  69. package/components/header/header.css +1 -1
  70. package/components/header/header.examples.js +7 -8
  71. package/components/header/profile.js +10 -11
  72. package/components/http/http.js +1 -1
  73. package/components/icon/icon.css +5 -4
  74. package/components/input/input-legacy.css +7 -7
  75. package/components/island/header.js +2 -2
  76. package/components/island/island.css +8 -3
  77. package/components/island-legacy/island-legacy.css +3 -1
  78. package/components/list/list.js +6 -1
  79. package/components/list/list__custom.js +9 -3
  80. package/components/list/list__item.js +8 -2
  81. package/components/list/list__link.js +2 -1
  82. package/components/loader-inline/loader-inline.css +1 -1
  83. package/components/loader-screen/loader-screen.css +1 -1
  84. package/components/message/message.css +1 -1
  85. package/components/message/message.examples.js +8 -7
  86. package/components/pager/pager.js +5 -3
  87. package/components/permissions/permissions.js +1 -1
  88. package/components/popup/popup.js +1 -1
  89. package/components/popup/popup.test.js +15 -13
  90. package/components/progress-bar/progress-bar.css +1 -1
  91. package/components/progress-bar/progress-bar.examples.js +3 -3
  92. package/components/progress-bar/progress-bar.js +5 -2
  93. package/components/progress-bar/progress-bar.test.js +12 -13
  94. package/components/progress-bar-ng/progress-bar-ng.examples.js +3 -3
  95. package/components/query-assist/query-assist.css +13 -3
  96. package/components/query-assist/query-assist.examples.js +3 -4
  97. package/components/query-assist/query-assist.js +56 -12
  98. package/components/query-assist/query-assist.test.js +37 -5
  99. package/components/save-field-ng/save-field-ng.css +0 -3
  100. package/components/save-field-ng/save-field-ng.js +3 -1
  101. package/components/save-field-ng/{save-field-ng.html → save-field-ng__template.js} +2 -2
  102. package/components/select/select.css +12 -7
  103. package/components/select/select.examples.js +13 -0
  104. package/components/select/select.js +30 -43
  105. package/components/select/select.test.js +4 -5
  106. package/components/select/select__popup.js +1 -0
  107. package/components/shortcuts-hint-ng/shortcuts-hint-ng.css +1 -1
  108. package/components/shortcuts-hint-ng/shortcuts-hint-ng.js +1 -1
  109. package/components/shortcuts-hint-ng/{shortcuts-hint-ng.html → shortcuts-hint-ng__template.js} +2 -2
  110. package/components/sidebar/sidebar.css +1 -0
  111. package/components/sidebar-ng/sidebar-ng.js +6 -2
  112. package/components/sidebar-ng/{sidebar-ng__button.html → sidebar-ng__button-template.js} +2 -2
  113. package/components/sidebar-ng/{sidebar-ng.html → sidebar-ng__template.js} +2 -2
  114. package/components/table/header.js +9 -1
  115. package/components/table/row.js +2 -1
  116. package/components/table/table.css +2 -1
  117. package/components/table-legacy/table-legacy.css +2 -2
  118. package/components/table-legacy/table-legacy__toolbar.css +2 -2
  119. package/components/table-legacy-ng/table-legacy-ng.js +38 -5
  120. package/components/table-legacy-ng/table-legacy-ng__pager.js +7 -1
  121. package/components/tabs/collapsible-tab.js +2 -2
  122. package/components/tabs/collapsible-tabs.js +5 -9
  123. package/components/tabs/tab-link.js +4 -2
  124. package/components/tabs/tabs.css +32 -5
  125. package/components/tabs-ng/tabs-ng.js +4 -2
  126. package/components/tabs-ng/{tabs-ng.html → tabs-ng__template.js} +6 -2
  127. package/components/tag/tag.css +5 -2
  128. package/components/tag/tag.examples.js +3 -0
  129. package/components/tag/tag.js +19 -16
  130. package/components/tags-input/tag-input.examples.js +1 -1
  131. package/components/tags-input/tags-input.js +5 -2
  132. package/components/template-ng/template-ng.js +1 -1
  133. package/components/tooltip/tooltip.js +7 -2
  134. package/components/user-agreement/user-agreement.css +1 -5
  135. package/components/user-agreement/user-agreement.examples.js +7 -6
  136. package/components/user-agreement/user-agreement.js +11 -3
  137. package/package.json +85 -83
  138. package/webpack.config.js +14 -10
  139. package/components/button-set-ng/button-set-ng.html +0 -1
  140. package/components/footer-ng/footer-ng.html +0 -13
  141. package/components/form-ng/form-ng__error-bubble.html +0 -3
  142. package/components/table-legacy-ng/table-legacy-ng.html +0 -4
  143. package/components/table-legacy-ng/table-legacy-ng__column.html +0 -12
  144. package/components/table-legacy-ng/table-legacy-ng__header.html +0 -4
  145. package/components/table-legacy-ng/table-legacy-ng__pager.html +0 -7
  146. package/components/table-legacy-ng/table-legacy-ng__row.html +0 -12
  147. package/components/table-legacy-ng/table-legacy-ng__title.html +0 -9
  148. package/dist/_helpers/_rollupPluginBabelHelpers.js +0 -123
  149. package/dist/_helpers/background-flow.js +0 -232
  150. package/dist/_helpers/badge.js +0 -3
  151. package/dist/_helpers/button.js +0 -145
  152. package/dist/_helpers/clickableLink.js +0 -65
  153. package/dist/_helpers/data-tests.js +0 -15
  154. package/dist/_helpers/disable-hover-hoc.js +0 -407
  155. package/dist/_helpers/dom.js +0 -101
  156. package/dist/_helpers/get-uid.js +0 -15
  157. package/dist/_helpers/linear-function.js +0 -17
  158. package/dist/_helpers/list.js +0 -1327
  159. package/dist/_helpers/logo.js +0 -36
  160. package/dist/_helpers/memoize.js +0 -17
  161. package/dist/_helpers/popup.js +0 -691
  162. package/dist/_helpers/popup.target.js +0 -27
  163. package/dist/_helpers/rerender-hoc.js +0 -49
  164. package/dist/_helpers/schedule-raf.js +0 -31
  165. package/dist/_helpers/sniffer.js +0 -6
  166. package/dist/_helpers/theme.js +0 -40
  167. package/dist/_helpers/url.js +0 -125
  168. package/dist/alert-service.js +0 -149
  169. package/dist/alert.js +0 -284
  170. package/dist/analytics.js +0 -116
  171. package/dist/auth-dialog-service.js +0 -56
  172. package/dist/auth-dialog.js +0 -122
  173. package/dist/auth.js +0 -1744
  174. package/dist/avatar.js +0 -152
  175. package/dist/badge.js +0 -52
  176. package/dist/button-group.js +0 -48
  177. package/dist/button-set.js +0 -27
  178. package/dist/button-toolbar.js +0 -30
  179. package/dist/button.js +0 -12
  180. package/dist/caret.js +0 -262
  181. package/dist/checkbox.js +0 -108
  182. package/dist/confirm-service.js +0 -102
  183. package/dist/confirm.js +0 -113
  184. package/dist/content-layout.js +0 -184
  185. package/dist/contenteditable.js +0 -81
  186. package/dist/data-list.js +0 -466
  187. package/dist/date-picker.js +0 -1398
  188. package/dist/dialog.js +0 -223
  189. package/dist/dropdown.js +0 -250
  190. package/dist/error-bubble.js +0 -56
  191. package/dist/error-message.js +0 -53
  192. package/dist/footer.js +0 -124
  193. package/dist/grid.js +0 -148
  194. package/dist/group.js +0 -34
  195. package/dist/header.js +0 -658
  196. package/dist/heading.js +0 -76
  197. package/dist/http.js +0 -207
  198. package/dist/hub-source.js +0 -130
  199. package/dist/icon.js +0 -211
  200. package/dist/input.js +0 -228
  201. package/dist/island.js +0 -314
  202. package/dist/link.js +0 -117
  203. package/dist/list.js +0 -29
  204. package/dist/loader-inline.js +0 -165
  205. package/dist/loader-screen.js +0 -45
  206. package/dist/loader.js +0 -338
  207. package/dist/login-dialog.js +0 -173
  208. package/dist/logo.js +0 -8
  209. package/dist/message.js +0 -226
  210. package/dist/old-browsers-message.js +0 -129
  211. package/dist/pager.js +0 -325
  212. package/dist/panel.js +0 -34
  213. package/dist/permissions.js +0 -466
  214. package/dist/popup-menu.js +0 -93
  215. package/dist/popup.js +0 -16
  216. package/dist/progress-bar.js +0 -111
  217. package/dist/proxy-attrs.js +0 -19
  218. package/dist/query-assist.js +0 -1081
  219. package/dist/radio.js +0 -112
  220. package/dist/select.js +0 -1920
  221. package/dist/selection.js +0 -213
  222. package/dist/shortcuts.js +0 -307
  223. package/dist/storage.js +0 -373
  224. package/dist/style.css +0 -1
  225. package/dist/tab-trap.js +0 -174
  226. package/dist/table.js +0 -903
  227. package/dist/tabs.js +0 -721
  228. package/dist/tag.js +0 -187
  229. package/dist/tags-input.js +0 -440
  230. package/dist/tags-list.js +0 -91
  231. package/dist/text.js +0 -38
  232. package/dist/toggle.js +0 -80
  233. package/dist/tooltip.js +0 -202
  234. package/dist/user-card.js +0 -218
package/dist/selection.js DELETED
@@ -1,213 +0,0 @@
1
- class Selection {
2
- constructor({
3
- data = [],
4
- selected = new Set(),
5
- focused = null,
6
- getKey = item => item.id,
7
- getChildren = () => [],
8
- isItemSelectable = () => true
9
- } = {}) {
10
- this._rawData = data;
11
- this._getChildren = getChildren;
12
- this._data = this._buildData(data);
13
- this._selected = selected;
14
- this._focused = focused;
15
- this._getKey = getKey;
16
- this._isItemSelectable = isItemSelectable;
17
- }
18
-
19
- _buildData(data) {
20
- return new Set(data);
21
- }
22
-
23
- _buildSelected(data, selected) {
24
- return new Set(selected);
25
- }
26
-
27
- cloneWith({
28
- data,
29
- selected,
30
- focused
31
- }) {
32
- const newData = data || this._rawData;
33
- let newSelected;
34
-
35
- if (data && !selected) {
36
- newSelected = new Set([...this._buildData(newData)].filter(item => [...this._selected].some(it => this._getKey(item) === this._getKey(it))));
37
- newSelected = this._buildSelected(this._buildData(newData), newSelected);
38
- } else if (selected) {
39
- newSelected = selected;
40
- } else {
41
- newSelected = this._selected;
42
- }
43
-
44
- newSelected = new Set([...newSelected].filter(item => this._isItemSelectable(item)));
45
-
46
- const cloneFocus = () => [...this._buildData(data)].filter(item => this._focused && this._getKey(item) === this._getKey(this._focused))[0];
47
-
48
- const newFocused = focused === undefined ? this._focused : focused;
49
- return new this.constructor({
50
- data: newData,
51
- selected: newSelected,
52
- focused: data && !focused ? cloneFocus() : newFocused,
53
- getKey: this._getKey,
54
- getChildren: this._getChildren,
55
- isItemSelectable: this._isItemSelectable
56
- });
57
- }
58
-
59
- focus(value) {
60
- return this.cloneWith({
61
- focused: value
62
- });
63
- }
64
-
65
- moveUp() {
66
- const focused = this._focused;
67
- const data = [...this._data];
68
-
69
- if (!focused) {
70
- return this.cloneWith({
71
- focused: data[data.length - 1]
72
- });
73
- }
74
-
75
- const nextItem = data[data.indexOf(focused) - 1];
76
-
77
- if (nextItem) {
78
- return this.cloneWith({
79
- focused: nextItem
80
- });
81
- }
82
-
83
- return undefined;
84
- }
85
-
86
- moveDown() {
87
- const focused = this._focused;
88
- const data = [...this._data];
89
-
90
- if (!focused) {
91
- return this.cloneWith({
92
- focused: data[0]
93
- });
94
- }
95
-
96
- const nextItem = data[data.indexOf(focused) + 1];
97
-
98
- if (nextItem) {
99
- return this.cloneWith({
100
- focused: nextItem
101
- });
102
- }
103
-
104
- return undefined;
105
- }
106
-
107
- moveStart() {
108
- const data = [...this._data];
109
-
110
- if (data.length) {
111
- return this.cloneWith({
112
- focused: data[0]
113
- });
114
- }
115
-
116
- return undefined;
117
- }
118
-
119
- moveEnd() {
120
- const data = [...this._data];
121
-
122
- if (data.length) {
123
- return this.cloneWith({
124
- focused: data.pop()
125
- });
126
- }
127
-
128
- return undefined;
129
- }
130
-
131
- select(value = this._focused) {
132
- if (!value || !this._isItemSelectable(value)) {
133
- return this;
134
- }
135
-
136
- const selected = new Set(this._selected);
137
- selected.add(value);
138
- return this.cloneWith({
139
- selected
140
- });
141
- }
142
-
143
- deselect(value = this._focused) {
144
- if (!value || !this._isItemSelectable(value)) {
145
- return this;
146
- }
147
-
148
- const selected = new Set(this._selected);
149
- selected.delete(value);
150
- return this.cloneWith({
151
- selected
152
- });
153
- }
154
-
155
- toggleSelection(value = this._focused) {
156
- if (this.isSelected(value)) {
157
- return this.deselect(value);
158
- } else {
159
- return this.select(value);
160
- }
161
- }
162
-
163
- selectAll() {
164
- return this.cloneWith({
165
- selected: [...this._data]
166
- });
167
- }
168
-
169
- resetFocus() {
170
- return this.cloneWith({
171
- focused: null
172
- });
173
- }
174
-
175
- resetSelection() {
176
- return this.cloneWith({
177
- selected: new Set()
178
- });
179
- }
180
-
181
- reset() {
182
- return this.resetFocus().resetSelection();
183
- }
184
-
185
- isFocused(value) {
186
- return this._focused === value;
187
- }
188
-
189
- isSelected(value) {
190
- return this._selected.has(value);
191
- }
192
-
193
- getFocused() {
194
- return this._focused;
195
- }
196
-
197
- getSelected() {
198
- return new Set(this._selected);
199
- }
200
-
201
- getActive() {
202
- if (this._selected.size) {
203
- return new Set(this._selected);
204
- } else if (this._focused) {
205
- return new Set([this._focused]);
206
- } else {
207
- return new Set();
208
- }
209
- }
210
-
211
- }
212
-
213
- export default Selection;
package/dist/shortcuts.js DELETED
@@ -1,307 +0,0 @@
1
- import { b as _defineProperty } from './_helpers/_rollupPluginBabelHelpers.js';
2
- import { PureComponent } from 'react';
3
- import PropTypes from 'prop-types';
4
- import Combokeys from 'combokeys';
5
- import { s as sniffr } from './_helpers/sniffer.js';
6
- import 'sniffr';
7
-
8
- class Shortcuts$1 {
9
- constructor() {
10
- _defineProperty(this, "ALLOW_SHORTCUTS_SELECTOR", '.ring-js-shortcuts');
11
-
12
- _defineProperty(this, "ROOT_SCOPE", {
13
- scopeId: 'ROOT',
14
- options: {}
15
- });
16
-
17
- _defineProperty(this, "_scopes", {});
18
-
19
- _defineProperty(this, "combokeys", new Combokeys(document.documentElement));
20
-
21
- _defineProperty(this, "trigger", combo => this.combokeys.trigger(combo));
22
-
23
- _defineProperty(this, "_dispatcher", (e, key) => {
24
- let currentScope;
25
-
26
- for (let i = this._scopeChain.length - 1; i >= 0; i--) {
27
- const scopeInChain = this._scopeChain[i];
28
- currentScope = this._scopes[scopeInChain.scopeId];
29
-
30
- if (currentScope && currentScope[key]) {
31
- const ret = currentScope[key](e, key, scopeInChain.scopeId); // Fall down in chain when returning true
32
-
33
- if (ret !== true) {
34
- return ret;
35
- }
36
- }
37
-
38
- if (scopeInChain.options.modal) {
39
- return true;
40
- }
41
- }
42
-
43
- return undefined;
44
- });
45
-
46
- _defineProperty(this, "_defaultFilter", (e, element, key) => {
47
- // if the element or its parents have the class "ring-js-shortcuts" then no need to stop
48
- if (element === document || element.matches(this.ALLOW_SHORTCUTS_SELECTOR) || (element.dataset.enabledShortcuts != null ? element.dataset.enabledShortcuts.split(',').includes(key) : element.closest(this.ALLOW_SHORTCUTS_SELECTOR) != null)) {
49
- return false;
50
- } // stop for input, select, and textarea
51
-
52
-
53
- return element.matches('input,select,textarea') || element.contentEditable && element.contentEditable === 'true';
54
- });
55
-
56
- this.setFilter();
57
- this.setScope();
58
- }
59
-
60
- /**
61
- * Binds a handler to a shortcut
62
- *
63
- * @param params.key {string | Array.<string>) Keys to bind
64
- * @param params.handler {Function} Events handle
65
- * @param params.scope {string} Scope (optional)
66
- * @param params.type {string} Event type, will be passed to Combokeys (optional)
67
- */
68
- bind(params) {
69
- if (!(params instanceof Object) || typeof params.handler !== 'function') {
70
- throw new Error('Shortcut handler should exist');
71
- }
72
-
73
- if (!params.scope) {
74
- params.scope = this.ROOT_SCOPE.scopeId;
75
- }
76
-
77
- if (Array.isArray(params.key)) {
78
- for (let i = 0; i < params.key.length; i++) {
79
- this.bind(Object.assign({}, params, {
80
- key: params.key[i]
81
- }));
82
- }
83
-
84
- return;
85
- }
86
-
87
- if (typeof params.key !== 'string') {
88
- throw new Error('Shortcut key should exist');
89
- }
90
-
91
- if (!this._scopes[params.scope]) {
92
- this._scopes[params.scope] = {};
93
- }
94
-
95
- this._scopes[params.scope][params.key] = params.handler;
96
- this.combokeys.bind(params.key, this._dispatcher, this._getKeyboardEventType(params));
97
- }
98
- /**
99
- * Binds a map of shortcuts to handlers with common options
100
- *
101
- * @map {Object) Keys to handlers map
102
- * @options.scope {string} Scope (optional)
103
- * @options.type {string} Event type, will be passed to Combokeys (optional)
104
- */
105
-
106
-
107
- bindMap(map, options) {
108
- if (!(map instanceof Object)) {
109
- throw new Error('Shortcuts map shouldn\'t be empty');
110
- }
111
-
112
- for (const key in map) {
113
- if (map.hasOwnProperty(key)) {
114
- this.bind(Object.assign({}, options || {}, {
115
- key,
116
- handler: map[key]
117
- }));
118
- }
119
- }
120
- }
121
-
122
- unbindScope(scope) {
123
- this._scopes[scope] = null;
124
- }
125
-
126
- getScope() {
127
- return this._scopeChain.slice(1);
128
- }
129
-
130
- hasScope(scopeId) {
131
- return this.indexOfScope(scopeId) !== -1;
132
- }
133
- /**
134
- * Adds a scope to the chain
135
- * @param scopeId id of scope to add
136
- * @param options options for pushing scope
137
- * @param options.modal whether keys should fall through this scope or not.
138
- * Useful for modals or overlays
139
- */
140
-
141
-
142
- pushScope(scopeId, options = {}) {
143
- if (scopeId) {
144
- const position = this.indexOfScope(scopeId);
145
-
146
- if (position !== -1) {
147
- this._scopeChain.splice(position, 1);
148
- }
149
-
150
- this._scopeChain.push(this.wrapScope(scopeId, options));
151
- }
152
- }
153
-
154
- popScope(scopeId) {
155
- if (scopeId) {
156
- const position = this.indexOfScope(scopeId);
157
-
158
- if (position !== -1) {
159
- return this._scopeChain.splice(position, this._scopeChain.length - 1);
160
- }
161
- }
162
-
163
- return undefined;
164
- }
165
-
166
- spliceScope(scopeId) {
167
- if (scopeId) {
168
- const position = this.indexOfScope(scopeId);
169
-
170
- if (position !== -1) {
171
- this._scopeChain.splice(position, 1);
172
- }
173
- }
174
- }
175
-
176
- setScope(scope) {
177
- if (scope) {
178
- let scopeChain;
179
-
180
- if (typeof scope === 'string' || !Array.isArray(scope) && typeof scope === 'object' && scope !== null) {
181
- scopeChain = [scope];
182
- } else {
183
- scopeChain = scope;
184
- }
185
-
186
- if (!Array.isArray(scopeChain)) {
187
- return;
188
- }
189
-
190
- scopeChain = scopeChain.map(scopeItem => {
191
- const isScopeId = typeof scopeItem === 'string';
192
- return isScopeId ? this.wrapScope(scopeItem) : scopeItem;
193
- });
194
- this._scopeChain = [this.ROOT_SCOPE].concat(scopeChain);
195
- } else {
196
- this._scopeChain = [this.ROOT_SCOPE];
197
- }
198
- }
199
-
200
- wrapScope(scopeId, options = {}) {
201
- return {
202
- scopeId,
203
- options
204
- };
205
- }
206
-
207
- hasKey(key, scope) {
208
- return !!(this._scopes[scope] && this._scopes[scope][key]);
209
- }
210
-
211
- _getKeyboardEventType(params) {
212
- if (!params.type && sniffr.os.name === 'windows') {
213
- const isSystemShortcut = params.key.match(/ctrl/i) && params.key.match(/shift/i) && params.key.match(/[0-9]/);
214
- /**
215
- * Windows system shortcuts (ctrl+shift+[0-9] are caught by the OS on 'keydown', so let's use 'keyup'
216
- */
217
-
218
- if (isSystemShortcut) {
219
- return 'keyup';
220
- }
221
- }
222
-
223
- return params.type;
224
- }
225
-
226
- setFilter(fn) {
227
- this.combokeys.stopCallback = typeof fn === 'function' ? fn : this._defaultFilter;
228
- }
229
-
230
- indexOfScope(scopeId) {
231
- return this._scopeChain.findIndex(scope => scope.scopeId === scopeId);
232
- }
233
-
234
- reset() {
235
- this._scopes = {};
236
- this.setScope();
237
- this.combokeys.reset();
238
- }
239
-
240
- }
241
-
242
- var shortcuts = new Shortcuts$1();
243
-
244
- class Shortcuts extends PureComponent {
245
- componentDidMount() {
246
- if (!this.props.disabled) {
247
- this.turnShorcutsOn();
248
- }
249
- }
250
-
251
- componentDidUpdate(prevProps) {
252
- const {
253
- disabled
254
- } = this.props;
255
-
256
- if (!prevProps.disabled && disabled) {
257
- this.turnShorcutsOff();
258
- }
259
-
260
- if (prevProps.disabled && !disabled) {
261
- this.turnShorcutsOn();
262
- }
263
- }
264
-
265
- componentWillUnmount() {
266
- if (!this.props.disabled) {
267
- this.turnShorcutsOff();
268
- }
269
- }
270
-
271
- turnShorcutsOn() {
272
- const {
273
- map,
274
- scope,
275
- options
276
- } = this.props;
277
- shortcuts.bindMap(map, this.props);
278
- shortcuts.pushScope(scope, options);
279
- }
280
-
281
- turnShorcutsOff() {
282
- const {
283
- scope
284
- } = this.props;
285
- shortcuts.unbindScope(scope);
286
- shortcuts.spliceScope(scope);
287
- }
288
-
289
- render() {
290
- return this.props.children || null;
291
- }
292
-
293
- }
294
-
295
- _defineProperty(Shortcuts, "propTypes", {
296
- map: PropTypes.object.isRequired,
297
- scope: PropTypes.string.isRequired,
298
- options: PropTypes.object,
299
- disabled: PropTypes.bool,
300
- children: PropTypes.node
301
- });
302
-
303
- _defineProperty(Shortcuts, "defaultProps", {
304
- options: {}
305
- });
306
-
307
- export default Shortcuts;