@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.
- package/CHANGELOG.md +13 -0
- package/README.md +17 -15
- package/babel.config.js +3 -2
- package/components/alert/alert.js +9 -3
- package/components/alert/alert.test.js +21 -48
- package/components/alert/container.css +1 -1
- package/components/alert/container.test.js +3 -13
- package/components/alert-service/alert-service.examples.css +18 -0
- package/components/alert-service/alert-service.examples.js +21 -0
- package/components/alert-service/alert-service.js +10 -3
- package/components/analytics/analytics__fus-plugin.js +3 -3
- package/components/analytics/analytics__ga-plugin.js +2 -2
- package/components/auth/auth.test.js +14 -7
- package/components/auth/auth__core.js +64 -33
- package/components/auth-dialog/auth-dialog.css +2 -3
- package/components/auth-dialog/auth-dialog.js +4 -1
- package/components/auth-dialog/auth-dialog.test.js +3 -19
- package/components/avatar/avatar.css +4 -1
- package/components/avatar/avatar.examples.js +3 -2
- package/components/avatar/avatar.js +34 -6
- package/components/avatar/avatar.test.js +20 -17
- package/components/avatar/fallback-avatar.js +136 -0
- package/components/avatar-editor-ng/avatar-editor-ng.css +2 -2
- package/components/avatar-editor-ng/avatar-editor-ng.js +2 -1
- package/components/avatar-editor-ng/{avatar-editor-ng.html → avatar-editor-ng__template.js} +2 -2
- package/components/badge/badge.test.js +13 -20
- package/components/button/button.css +2 -2
- package/components/button/button.js +4 -1
- package/components/button/button.test.js +32 -33
- package/components/button-group/button-group.js +1 -1
- package/components/button-group/caption.js +1 -1
- package/components/button-ng/button-ng.js +1 -1
- package/components/button-set-ng/button-set-ng.js +3 -1
- package/components/checkbox/checkbox.css +1 -1
- package/components/code/code.js +2 -5
- package/components/confirm/confirm.js +1 -0
- package/components/confirm-service/confirm-service.js +5 -5
- package/components/content-layout/content-layout.css +1 -1
- package/components/data-list/data-list.css +1 -1
- package/components/date-picker/date-input.js +5 -4
- package/components/date-picker/date-picker.css +34 -22
- package/components/date-picker/date-picker.js +16 -14
- package/components/date-picker/date-popup.js +22 -7
- package/components/date-picker/month-names.js +8 -5
- package/components/date-picker/month.js +6 -2
- package/components/date-picker/weekdays.js +10 -2
- package/components/dialog/dialog.examples.js +3 -1
- package/components/dialog/dialog.js +10 -5
- package/components/dialog/dialog.test.js +1 -1
- package/components/dialog/dialog__body-scroll-preventer.js +51 -31
- package/components/dialog-ng/dialog-ng.js +10 -10
- package/components/dialog-ng/{dialog-ng.html → dialog-ng__template.js} +2 -2
- package/components/dropdown/dropdown.examples.js +36 -1
- package/components/dropdown/dropdown.test.js +2 -2
- package/components/dropdown-menu/dropdown-menu.examples.js +47 -0
- package/components/dropdown-menu/dropdown-menu.js +117 -0
- package/components/dropdown-menu/dropdown-menu.test.js +76 -0
- package/components/error-bubble/error-bubble-legacy.css +1 -1
- package/components/error-bubble/error-bubble.css +1 -1
- package/components/error-bubble/error-bubble.examples.js +1 -1
- package/components/error-page/error-page.css +2 -2
- package/components/footer-ng/footer-ng.js +13 -3
- package/components/form/form.css +2 -2
- package/components/form-ng/form-ng.js +3 -1
- package/components/global/global.css +1 -1
- package/components/global/theme.js +1 -1
- package/components/global/variables.css +8 -1
- package/components/grid/grid.css +10 -9
- package/components/header/header.css +1 -1
- package/components/header/header.examples.js +7 -8
- package/components/header/profile.js +10 -11
- package/components/http/http.js +1 -1
- package/components/icon/icon.css +5 -4
- package/components/input/input-legacy.css +7 -7
- package/components/island/header.js +2 -2
- package/components/island/island.css +8 -3
- package/components/island-legacy/island-legacy.css +3 -1
- package/components/list/list.js +6 -1
- package/components/list/list__custom.js +9 -3
- package/components/list/list__item.js +8 -2
- package/components/list/list__link.js +2 -1
- package/components/loader-inline/loader-inline.css +1 -1
- package/components/loader-screen/loader-screen.css +1 -1
- package/components/message/message.css +1 -1
- package/components/message/message.examples.js +8 -7
- package/components/pager/pager.js +5 -3
- package/components/permissions/permissions.js +1 -1
- package/components/popup/popup.js +1 -1
- package/components/popup/popup.test.js +15 -13
- package/components/progress-bar/progress-bar.css +1 -1
- package/components/progress-bar/progress-bar.examples.js +3 -3
- package/components/progress-bar/progress-bar.js +5 -2
- package/components/progress-bar/progress-bar.test.js +12 -13
- package/components/progress-bar-ng/progress-bar-ng.examples.js +3 -3
- package/components/query-assist/query-assist.css +13 -3
- package/components/query-assist/query-assist.examples.js +3 -4
- package/components/query-assist/query-assist.js +56 -12
- package/components/query-assist/query-assist.test.js +37 -5
- package/components/save-field-ng/save-field-ng.css +0 -3
- package/components/save-field-ng/save-field-ng.js +3 -1
- package/components/save-field-ng/{save-field-ng.html → save-field-ng__template.js} +2 -2
- package/components/select/select.css +12 -7
- package/components/select/select.examples.js +13 -0
- package/components/select/select.js +30 -43
- package/components/select/select.test.js +4 -5
- package/components/select/select__popup.js +1 -0
- package/components/shortcuts-hint-ng/shortcuts-hint-ng.css +1 -1
- package/components/shortcuts-hint-ng/shortcuts-hint-ng.js +1 -1
- package/components/shortcuts-hint-ng/{shortcuts-hint-ng.html → shortcuts-hint-ng__template.js} +2 -2
- package/components/sidebar/sidebar.css +1 -0
- package/components/sidebar-ng/sidebar-ng.js +6 -2
- package/components/sidebar-ng/{sidebar-ng__button.html → sidebar-ng__button-template.js} +2 -2
- package/components/sidebar-ng/{sidebar-ng.html → sidebar-ng__template.js} +2 -2
- package/components/table/header.js +9 -1
- package/components/table/row.js +2 -1
- package/components/table/table.css +2 -1
- package/components/table-legacy/table-legacy.css +2 -2
- package/components/table-legacy/table-legacy__toolbar.css +2 -2
- package/components/table-legacy-ng/table-legacy-ng.js +38 -5
- package/components/table-legacy-ng/table-legacy-ng__pager.js +7 -1
- package/components/tabs/collapsible-tab.js +2 -2
- package/components/tabs/collapsible-tabs.js +5 -9
- package/components/tabs/tab-link.js +4 -2
- package/components/tabs/tabs.css +32 -5
- package/components/tabs-ng/tabs-ng.js +4 -2
- package/components/tabs-ng/{tabs-ng.html → tabs-ng__template.js} +6 -2
- package/components/tag/tag.css +5 -2
- package/components/tag/tag.examples.js +3 -0
- package/components/tag/tag.js +19 -16
- package/components/tags-input/tag-input.examples.js +1 -1
- package/components/tags-input/tags-input.js +5 -2
- package/components/template-ng/template-ng.js +1 -1
- package/components/tooltip/tooltip.js +7 -2
- package/components/user-agreement/user-agreement.css +1 -5
- package/components/user-agreement/user-agreement.examples.js +7 -6
- package/components/user-agreement/user-agreement.js +11 -3
- package/package.json +85 -83
- package/webpack.config.js +14 -10
- package/components/button-set-ng/button-set-ng.html +0 -1
- package/components/footer-ng/footer-ng.html +0 -13
- package/components/form-ng/form-ng__error-bubble.html +0 -3
- package/components/table-legacy-ng/table-legacy-ng.html +0 -4
- package/components/table-legacy-ng/table-legacy-ng__column.html +0 -12
- package/components/table-legacy-ng/table-legacy-ng__header.html +0 -4
- package/components/table-legacy-ng/table-legacy-ng__pager.html +0 -7
- package/components/table-legacy-ng/table-legacy-ng__row.html +0 -12
- package/components/table-legacy-ng/table-legacy-ng__title.html +0 -9
- package/dist/_helpers/_rollupPluginBabelHelpers.js +0 -123
- package/dist/_helpers/background-flow.js +0 -232
- package/dist/_helpers/badge.js +0 -3
- package/dist/_helpers/button.js +0 -145
- package/dist/_helpers/clickableLink.js +0 -65
- package/dist/_helpers/data-tests.js +0 -15
- package/dist/_helpers/disable-hover-hoc.js +0 -407
- package/dist/_helpers/dom.js +0 -101
- package/dist/_helpers/get-uid.js +0 -15
- package/dist/_helpers/linear-function.js +0 -17
- package/dist/_helpers/list.js +0 -1327
- package/dist/_helpers/logo.js +0 -36
- package/dist/_helpers/memoize.js +0 -17
- package/dist/_helpers/popup.js +0 -691
- package/dist/_helpers/popup.target.js +0 -27
- package/dist/_helpers/rerender-hoc.js +0 -49
- package/dist/_helpers/schedule-raf.js +0 -31
- package/dist/_helpers/sniffer.js +0 -6
- package/dist/_helpers/theme.js +0 -40
- package/dist/_helpers/url.js +0 -125
- package/dist/alert-service.js +0 -149
- package/dist/alert.js +0 -284
- package/dist/analytics.js +0 -116
- package/dist/auth-dialog-service.js +0 -56
- package/dist/auth-dialog.js +0 -122
- package/dist/auth.js +0 -1744
- package/dist/avatar.js +0 -152
- package/dist/badge.js +0 -52
- package/dist/button-group.js +0 -48
- package/dist/button-set.js +0 -27
- package/dist/button-toolbar.js +0 -30
- package/dist/button.js +0 -12
- package/dist/caret.js +0 -262
- package/dist/checkbox.js +0 -108
- package/dist/confirm-service.js +0 -102
- package/dist/confirm.js +0 -113
- package/dist/content-layout.js +0 -184
- package/dist/contenteditable.js +0 -81
- package/dist/data-list.js +0 -466
- package/dist/date-picker.js +0 -1398
- package/dist/dialog.js +0 -223
- package/dist/dropdown.js +0 -250
- package/dist/error-bubble.js +0 -56
- package/dist/error-message.js +0 -53
- package/dist/footer.js +0 -124
- package/dist/grid.js +0 -148
- package/dist/group.js +0 -34
- package/dist/header.js +0 -658
- package/dist/heading.js +0 -76
- package/dist/http.js +0 -207
- package/dist/hub-source.js +0 -130
- package/dist/icon.js +0 -211
- package/dist/input.js +0 -228
- package/dist/island.js +0 -314
- package/dist/link.js +0 -117
- package/dist/list.js +0 -29
- package/dist/loader-inline.js +0 -165
- package/dist/loader-screen.js +0 -45
- package/dist/loader.js +0 -338
- package/dist/login-dialog.js +0 -173
- package/dist/logo.js +0 -8
- package/dist/message.js +0 -226
- package/dist/old-browsers-message.js +0 -129
- package/dist/pager.js +0 -325
- package/dist/panel.js +0 -34
- package/dist/permissions.js +0 -466
- package/dist/popup-menu.js +0 -93
- package/dist/popup.js +0 -16
- package/dist/progress-bar.js +0 -111
- package/dist/proxy-attrs.js +0 -19
- package/dist/query-assist.js +0 -1081
- package/dist/radio.js +0 -112
- package/dist/select.js +0 -1920
- package/dist/selection.js +0 -213
- package/dist/shortcuts.js +0 -307
- package/dist/storage.js +0 -373
- package/dist/style.css +0 -1
- package/dist/tab-trap.js +0 -174
- package/dist/table.js +0 -903
- package/dist/tabs.js +0 -721
- package/dist/tag.js +0 -187
- package/dist/tags-input.js +0 -440
- package/dist/tags-list.js +0 -91
- package/dist/text.js +0 -38
- package/dist/toggle.js +0 -80
- package/dist/tooltip.js +0 -202
- 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;
|