@elliemae/ds-shared 1.57.1-rc.0 → 2.0.0-alpha.11
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/cjs/Animations/BaseAnimation.js +25 -36
- package/cjs/Animations/Grow.js +31 -39
- package/cjs/Animations/GrowRight.js +31 -40
- package/cjs/Animations/GrowVertical.js +3 -2
- package/cjs/CheckableGroup.js +36 -50
- package/cjs/DeferRenderAfterComputation.js +12 -22
- package/cjs/FocusGroup/FocusGrid.js +94 -102
- package/cjs/FocusGroup/FocusGroup.js +215 -270
- package/cjs/FocusGroup/FocusGroupContext.js +1 -2
- package/cjs/FocusGroup/FocusGroupManager.js +88 -124
- package/cjs/FocusGroup/focusGroupManagerHoc.js +24 -29
- package/cjs/FocusGroup/index.js +14 -28
- package/cjs/FocusGroup/useFocusGroupItem.js +24 -27
- package/cjs/FocusGroup/utils/getNextCellPosition.js +14 -16
- package/cjs/GroupContext/Group.js +76 -104
- package/cjs/GroupContext/GroupContext.js +1 -2
- package/cjs/GroupContext/GroupItem.js +10 -11
- package/cjs/GroupContext/index.js +6 -15
- package/cjs/ScrollSync/ScrollSync.js +86 -112
- package/cjs/ScrollSync/ScrollSyncPane.js +49 -92
- package/cjs/ScrollSync/ScrollSyncProvider.js +32 -28
- package/cjs/ScrollSync/index.js +4 -14
- package/cjs/ScrollSync/useScrollSync.js +0 -1
- package/cjs/constants.js +43 -4
- package/cjs/createDataInstance/createInstancePlugin.js +6 -10
- package/cjs/createDataInstance/createInstanceRef.js +34 -42
- package/cjs/createDataInstance/utils.js +42 -76
- package/cjs/defer-render-hoc/index.js +19 -64
- package/cjs/dimsum.config.js +7 -0
- package/cjs/index.js +10 -21
- package/cjs/prop-types.js +59 -0
- package/cjs/react-spring/index.js +3 -6
- package/cjs/react-spring/renderprops.js +3 -6
- package/cjs/toolbar/ToolbarProvider.js +60 -81
- package/cjs/useDataGrid/VolatileRowsListener.js +13 -27
- package/cjs/useDataGrid/index.js +2 -17
- package/cjs/useDataGrid/initColumnDefinition.js +45 -53
- package/cjs/useDataGrid/useDataGrid.js +105 -152
- package/cjs/useDataList/index.js +2 -15
- package/cjs/useDataList/recordIterator.js +7 -11
- package/cjs/useDataList/useDataList.js +42 -63
- package/cjs/utils.js +39 -59
- package/cjs/virtualization/AutoHeightList.js +34 -27
- package/cjs/virtualization/FluidHeightList.js +23 -17
- package/cjs/virtualization/index.js +12 -18
- package/esm/Animations/BaseAnimation.js +24 -35
- package/esm/Animations/Grow.js +29 -37
- package/esm/Animations/GrowRight.js +29 -38
- package/esm/Animations/GrowVertical.js +3 -2
- package/esm/CheckableGroup.js +33 -46
- package/esm/DeferRenderAfterComputation.js +12 -21
- package/esm/FocusGroup/FocusGrid.js +86 -96
- package/esm/FocusGroup/FocusGroup.js +210 -263
- package/esm/FocusGroup/FocusGroupContext.js +0 -1
- package/esm/FocusGroup/FocusGroupManager.js +85 -115
- package/esm/FocusGroup/focusGroupManagerHoc.js +19 -23
- package/esm/FocusGroup/index.js +0 -14
- package/esm/FocusGroup/useFocusGroupItem.js +22 -25
- package/esm/FocusGroup/utils/getNextCellPosition.js +14 -16
- package/esm/GroupContext/Group.js +75 -96
- package/esm/GroupContext/GroupContext.js +1 -2
- package/esm/GroupContext/GroupItem.js +8 -9
- package/esm/GroupContext/index.js +0 -9
- package/esm/ScrollSync/ScrollSync.js +83 -104
- package/esm/ScrollSync/ScrollSyncPane.js +47 -83
- package/esm/ScrollSync/ScrollSyncProvider.js +31 -28
- package/esm/ScrollSync/index.js +0 -10
- package/esm/ScrollSync/useScrollSync.js +0 -1
- package/esm/constants.js +31 -5
- package/esm/createDataInstance/createInstancePlugin.js +5 -8
- package/esm/createDataInstance/createInstanceRef.js +29 -36
- package/esm/createDataInstance/utils.js +40 -74
- package/esm/defer-render-hoc/index.js +19 -57
- package/esm/dimsum.config.js +5 -0
- package/esm/index.js +0 -11
- package/esm/prop-types.js +43 -0
- package/esm/react-spring/index.js +1 -2
- package/esm/react-spring/renderprops.js +1 -2
- package/esm/toolbar/ToolbarProvider.js +55 -75
- package/esm/useDataGrid/VolatileRowsListener.js +12 -24
- package/esm/useDataGrid/index.js +0 -15
- package/esm/useDataGrid/initColumnDefinition.js +38 -45
- package/esm/useDataGrid/useDataGrid.js +85 -131
- package/esm/useDataList/index.js +0 -13
- package/esm/useDataList/recordIterator.js +7 -11
- package/esm/useDataList/useDataList.js +31 -51
- package/esm/utils.js +37 -57
- package/esm/virtualization/AutoHeightList.js +26 -19
- package/esm/virtualization/FluidHeightList.js +20 -14
- package/esm/virtualization/index.js +6 -12
- package/package.json +202 -13
- package/types/Animations/BaseAnimation.d.ts +12 -0
- package/types/Animations/Grow.d.ts +11 -0
- package/types/Animations/GrowRight.d.ts +11 -0
- package/types/Animations/GrowVertical.d.ts +1 -0
- package/types/CheckableGroup.d.ts +20 -0
- package/types/DeferRenderAfterComputation.d.ts +6 -0
- package/types/FocusGroup/FocusGrid.d.ts +10 -0
- package/types/FocusGroup/FocusGroup.d.ts +36 -0
- package/types/FocusGroup/FocusGroupContext.d.ts +3 -0
- package/types/FocusGroup/FocusGroupManager.d.ts +24 -0
- package/types/FocusGroup/focusGroupManagerHoc.d.ts +7 -0
- package/types/FocusGroup/index.d.ts +6 -0
- package/types/FocusGroup/useFocusGroupItem.d.ts +2 -0
- package/types/FocusGroup/utils/getNextCellPosition.d.ts +12 -0
- package/types/GroupContext/Group.d.ts +14 -0
- package/types/GroupContext/GroupContext.d.ts +2 -0
- package/types/GroupContext/GroupItem.d.ts +5 -0
- package/types/GroupContext/index.d.ts +3 -0
- package/types/ScrollSync/ScrollSync.d.ts +21 -0
- package/types/ScrollSync/ScrollSyncPane.d.ts +3 -0
- package/types/ScrollSync/ScrollSyncProvider.d.ts +12 -0
- package/types/ScrollSync/index.d.ts +2 -0
- package/types/ScrollSync/useScrollSync.d.ts +6 -0
- package/types/constants.d.ts +30 -0
- package/types/createDataInstance/createInstancePlugin.d.ts +1 -0
- package/types/createDataInstance/createInstanceRef.d.ts +12 -0
- package/types/createDataInstance/tests/createInstanceRef.test.d.ts +0 -0
- package/types/createDataInstance/utils.d.ts +9 -0
- package/types/dimsum.config.d.ts +4 -0
- package/types/index.d.ts +2 -0
- package/types/prop-types.d.ts +41 -0
- package/types/react-spring/index.d.ts +1 -0
- package/types/react-spring/renderprops.d.ts +1 -0
- package/types/toolbar/ToolbarProvider.d.ts +10 -0
- package/types/useDataGrid/VolatileRowsListener.d.ts +5 -0
- package/types/useDataGrid/index.d.ts +1 -0
- package/types/useDataGrid/initColumnDefinition.d.ts +4 -0
- package/types/useDataGrid/useDataGrid.d.ts +8 -0
- package/types/useDataList/index.d.ts +1 -0
- package/types/useDataList/recordIterator.d.ts +1 -0
- package/types/useDataList/useDataList.d.ts +13 -0
- package/types/utils.d.ts +22 -0
- package/types/virtualization/AutoHeightList.d.ts +2 -0
- package/types/virtualization/FluidHeightList.d.ts +2 -0
- package/types/virtualization/index.d.ts +9 -0
- package/Animations/BaseAnimation/package.json +0 -10
- package/Animations/Grow/package.json +0 -10
- package/Animations/GrowRight/package.json +0 -10
- package/Animations/GrowVertical/package.json +0 -10
- package/CheckableGroup/package.json +0 -10
- package/DeferRenderAfterComputation/package.json +0 -10
- package/FocusGroup/FocusGrid/package.json +0 -10
- package/FocusGroup/FocusGroup/package.json +0 -10
- package/FocusGroup/FocusGroupContext/package.json +0 -10
- package/FocusGroup/FocusGroupManager/package.json +0 -10
- package/FocusGroup/focusGroupManagerHoc/package.json +0 -10
- package/FocusGroup/package.json +0 -10
- package/FocusGroup/useFocusGroupItem/package.json +0 -10
- package/FocusGroup/utils/getNextCellPosition/package.json +0 -10
- package/GroupContext/Group/package.json +0 -10
- package/GroupContext/GroupContext/package.json +0 -10
- package/GroupContext/GroupItem/package.json +0 -10
- package/GroupContext/package.json +0 -10
- package/ScrollSync/ScrollSync/package.json +0 -10
- package/ScrollSync/ScrollSyncPane/package.json +0 -10
- package/ScrollSync/ScrollSyncProvider/package.json +0 -10
- package/ScrollSync/package.json +0 -10
- package/ScrollSync/useScrollSync/package.json +0 -10
- package/cjs/Animations/BaseAnimation.js.map +0 -1
- package/cjs/Animations/Grow.js.map +0 -1
- package/cjs/Animations/GrowRight.js.map +0 -1
- package/cjs/Animations/GrowVertical.js.map +0 -1
- package/cjs/CheckableGroup.js.map +0 -1
- package/cjs/DeferRenderAfterComputation.js.map +0 -1
- package/cjs/FocusGroup/FocusGrid.js.map +0 -1
- package/cjs/FocusGroup/FocusGroup.js.map +0 -1
- package/cjs/FocusGroup/FocusGroupContext.js.map +0 -1
- package/cjs/FocusGroup/FocusGroupManager.js.map +0 -1
- package/cjs/FocusGroup/focusGroupManagerHoc.js.map +0 -1
- package/cjs/FocusGroup/index.js.map +0 -1
- package/cjs/FocusGroup/useFocusGroupItem.js.map +0 -1
- package/cjs/FocusGroup/utils/getNextCellPosition.js.map +0 -1
- package/cjs/GroupContext/Group.js.map +0 -1
- package/cjs/GroupContext/GroupContext.js.map +0 -1
- package/cjs/GroupContext/GroupItem.js.map +0 -1
- package/cjs/GroupContext/index.js.map +0 -1
- package/cjs/ScrollSync/ScrollSync.js.map +0 -1
- package/cjs/ScrollSync/ScrollSyncPane.js.map +0 -1
- package/cjs/ScrollSync/ScrollSyncProvider.js.map +0 -1
- package/cjs/ScrollSync/index.js.map +0 -1
- package/cjs/ScrollSync/useScrollSync.js.map +0 -1
- package/cjs/constants.js.map +0 -1
- package/cjs/createDataInstance/createInstancePlugin.js.map +0 -1
- package/cjs/createDataInstance/createInstanceRef.js.map +0 -1
- package/cjs/createDataInstance/utils.js.map +0 -1
- package/cjs/defer-render-hoc/index.js.map +0 -1
- package/cjs/index.js.map +0 -1
- package/cjs/react-spring/index.js.map +0 -1
- package/cjs/react-spring/renderprops.js.map +0 -1
- package/cjs/toolbar/ToolbarProvider.js.map +0 -1
- package/cjs/useDataGrid/VolatileRowsListener.js.map +0 -1
- package/cjs/useDataGrid/index.js.map +0 -1
- package/cjs/useDataGrid/initColumnDefinition.js.map +0 -1
- package/cjs/useDataGrid/useDataGrid.js.map +0 -1
- package/cjs/useDataList/index.js.map +0 -1
- package/cjs/useDataList/recordIterator.js.map +0 -1
- package/cjs/useDataList/useDataList.js.map +0 -1
- package/cjs/utils.js.map +0 -1
- package/cjs/virtualization/AutoHeightList.js.map +0 -1
- package/cjs/virtualization/FluidHeightList.js.map +0 -1
- package/cjs/virtualization/index.js.map +0 -1
- package/constants/package.json +0 -10
- package/createDataInstance/createInstancePlugin/package.json +0 -10
- package/createDataInstance/createInstanceRef/package.json +0 -10
- package/createDataInstance/utils/package.json +0 -10
- package/defer-render-hoc/package.json +0 -10
- package/esm/Animations/BaseAnimation.js.map +0 -1
- package/esm/Animations/Grow.js.map +0 -1
- package/esm/Animations/GrowRight.js.map +0 -1
- package/esm/Animations/GrowVertical.js.map +0 -1
- package/esm/CheckableGroup.js.map +0 -1
- package/esm/DeferRenderAfterComputation.js.map +0 -1
- package/esm/FocusGroup/FocusGrid.js.map +0 -1
- package/esm/FocusGroup/FocusGroup.js.map +0 -1
- package/esm/FocusGroup/FocusGroupContext.js.map +0 -1
- package/esm/FocusGroup/FocusGroupManager.js.map +0 -1
- package/esm/FocusGroup/focusGroupManagerHoc.js.map +0 -1
- package/esm/FocusGroup/index.js.map +0 -1
- package/esm/FocusGroup/useFocusGroupItem.js.map +0 -1
- package/esm/FocusGroup/utils/getNextCellPosition.js.map +0 -1
- package/esm/GroupContext/Group.js.map +0 -1
- package/esm/GroupContext/GroupContext.js.map +0 -1
- package/esm/GroupContext/GroupItem.js.map +0 -1
- package/esm/GroupContext/index.js.map +0 -1
- package/esm/ScrollSync/ScrollSync.js.map +0 -1
- package/esm/ScrollSync/ScrollSyncPane.js.map +0 -1
- package/esm/ScrollSync/ScrollSyncProvider.js.map +0 -1
- package/esm/ScrollSync/index.js.map +0 -1
- package/esm/ScrollSync/useScrollSync.js.map +0 -1
- package/esm/constants.js.map +0 -1
- package/esm/createDataInstance/createInstancePlugin.js.map +0 -1
- package/esm/createDataInstance/createInstanceRef.js.map +0 -1
- package/esm/createDataInstance/utils.js.map +0 -1
- package/esm/defer-render-hoc/index.js.map +0 -1
- package/esm/index.js.map +0 -1
- package/esm/react-spring/index.js.map +0 -1
- package/esm/react-spring/renderprops.js.map +0 -1
- package/esm/toolbar/ToolbarProvider.js.map +0 -1
- package/esm/useDataGrid/VolatileRowsListener.js.map +0 -1
- package/esm/useDataGrid/index.js.map +0 -1
- package/esm/useDataGrid/initColumnDefinition.js.map +0 -1
- package/esm/useDataGrid/useDataGrid.js.map +0 -1
- package/esm/useDataList/index.js.map +0 -1
- package/esm/useDataList/recordIterator.js.map +0 -1
- package/esm/useDataList/useDataList.js.map +0 -1
- package/esm/utils.js.map +0 -1
- package/esm/virtualization/AutoHeightList.js.map +0 -1
- package/esm/virtualization/FluidHeightList.js.map +0 -1
- package/esm/virtualization/index.js.map +0 -1
- package/react-spring/package.json +0 -10
- package/react-spring/renderprops/package.json +0 -10
- package/toolbar/ToolbarProvider/package.json +0 -10
- package/useDataGrid/VolatileRowsListener/package.json +0 -10
- package/useDataGrid/initColumnDefinition/package.json +0 -10
- package/useDataGrid/package.json +0 -10
- package/useDataGrid/useDataGrid/package.json +0 -10
- package/useDataList/package.json +0 -10
- package/useDataList/recordIterator/package.json +0 -10
- package/useDataList/useDataList/package.json +0 -10
- package/utils/package.json +0 -10
- package/virtualization/AutoHeightList/package.json +0 -10
- package/virtualization/FluidHeightList/package.json +0 -10
- package/virtualization/package.json +0 -10
|
@@ -1,43 +1,32 @@
|
|
|
1
|
-
import _classCallCheck from '@babel/runtime/helpers/esm/classCallCheck';
|
|
2
|
-
import _createClass from '@babel/runtime/helpers/esm/createClass';
|
|
3
1
|
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
4
|
-
import
|
|
2
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
3
|
+
import { get, isFunction } from '@elliemae/ds-utilities/utils';
|
|
5
4
|
import hotkeys from 'hotkeys-js';
|
|
6
5
|
|
|
7
6
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
8
7
|
|
|
9
8
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
10
|
-
|
|
9
|
+
const defaultOptions = {
|
|
11
10
|
orientation: 'vertical'
|
|
12
11
|
};
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
const safeCallAction = (e, fun, ...args) => {
|
|
15
14
|
if (isFunction(fun)) {
|
|
16
15
|
e.preventDefault();
|
|
17
|
-
|
|
18
|
-
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
19
|
-
args[_key - 2] = arguments[_key];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
fun.apply(void 0, args);
|
|
16
|
+
fun(...args);
|
|
23
17
|
}
|
|
24
18
|
};
|
|
25
19
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
_hotKeys$hotkey$allow = _hotKeys$hotkey.allowDocumentHandler,
|
|
37
|
-
allowDocumentHandler = _hotKeys$hotkey$allow === void 0 ? false : _hotKeys$hotkey$allow;
|
|
38
|
-
|
|
39
|
-
var parameterizedHandler = function parameterizedHandler(e) {
|
|
40
|
-
var handlerParams = isFunction(params) ? params() : params;
|
|
20
|
+
const registerHotkeys = (hotKeys = {}, params, getContainer = () => document) => {
|
|
21
|
+
Object.keys(hotKeys).forEach(hotkey => {
|
|
22
|
+
const {
|
|
23
|
+
options,
|
|
24
|
+
handler,
|
|
25
|
+
allowDocumentHandler = false
|
|
26
|
+
} = hotKeys[hotkey];
|
|
27
|
+
|
|
28
|
+
const parameterizedHandler = e => {
|
|
29
|
+
const handlerParams = isFunction(params) ? params() : params;
|
|
41
30
|
if (!allowDocumentHandler && handlerParams.item !== document.activeElement) return;
|
|
42
31
|
e.preventDefault();
|
|
43
32
|
handler(handlerParams);
|
|
@@ -49,27 +38,22 @@ var registerHotkeys = function registerHotkeys() {
|
|
|
49
38
|
});
|
|
50
39
|
};
|
|
51
40
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
Object.keys(hotKeys).forEach(function (hotkey) {
|
|
41
|
+
const unregisterHotKeys = (hotKeys = {}) => {
|
|
42
|
+
Object.keys(hotKeys).forEach(hotkey => {
|
|
55
43
|
hotkeys.unbind(hotkey);
|
|
56
44
|
});
|
|
57
45
|
};
|
|
58
46
|
|
|
59
|
-
|
|
60
|
-
return null;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
var FocusGroup = /*#__PURE__*/function () {
|
|
64
|
-
function FocusGroup() {
|
|
65
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
66
|
-
|
|
67
|
-
_classCallCheck(this, FocusGroup);
|
|
47
|
+
const noop = () => null;
|
|
68
48
|
|
|
49
|
+
class FocusGroup {
|
|
50
|
+
constructor(options = {}) {
|
|
69
51
|
_defineProperty(this, "items", []);
|
|
70
52
|
|
|
71
53
|
this.options = _objectSpread(_objectSpread({}, defaultOptions), options);
|
|
72
|
-
|
|
54
|
+
const {
|
|
55
|
+
orientation
|
|
56
|
+
} = this.options;
|
|
73
57
|
this.keyBindings = _objectSpread({
|
|
74
58
|
ArrowUp: orientation !== 'horizontal' && 'previous',
|
|
75
59
|
ArrowRight: orientation !== 'vertical' && 'next',
|
|
@@ -89,9 +73,7 @@ var FocusGroup = /*#__PURE__*/function () {
|
|
|
89
73
|
first: this.focusFirst.bind(this),
|
|
90
74
|
last: this.focusLast.bind(this),
|
|
91
75
|
exit: this.exit.bind(this),
|
|
92
|
-
enter:
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
76
|
+
enter: () => null
|
|
95
77
|
};
|
|
96
78
|
this.handleKeyDown = this.handleKeyDown.bind(this);
|
|
97
79
|
this.register = this.register.bind(this);
|
|
@@ -105,233 +87,198 @@ var FocusGroup = /*#__PURE__*/function () {
|
|
|
105
87
|
this.getHotKeysParams = this.getHotKeysParams.bind(this);
|
|
106
88
|
}
|
|
107
89
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
90
|
+
getHotKeysParams() {
|
|
91
|
+
const item = this.currentFocusedItem;
|
|
92
|
+
const {
|
|
93
|
+
index
|
|
94
|
+
} = get(item, ['dataset'], {});
|
|
95
|
+
return {
|
|
96
|
+
item,
|
|
97
|
+
index
|
|
98
|
+
};
|
|
99
|
+
}
|
|
112
100
|
|
|
113
|
-
|
|
114
|
-
|
|
101
|
+
activate() {
|
|
102
|
+
const {
|
|
103
|
+
getContainer
|
|
104
|
+
} = this.options;
|
|
105
|
+
document.addEventListener('keydown', this.handleKeyDown, true);
|
|
106
|
+
registerHotkeys(this.options.hotKeys, this.getHotKeysParams, getContainer);
|
|
107
|
+
}
|
|
115
108
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return actions.map(function (action) {
|
|
147
|
-
return typeof action === 'string' ? safeCallAction(e, _this.mapActions[action]) : safeCallAction(e, action);
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
}, {
|
|
151
|
-
key: "register",
|
|
152
|
-
value: function register(node) {
|
|
153
|
-
var _this2 = this;
|
|
154
|
-
|
|
155
|
-
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
156
|
-
var afterIndex = this.items.findIndex(function (item) {
|
|
157
|
-
return item.compareDocumentPosition(node) === Node.DOCUMENT_POSITION_PRECEDING;
|
|
158
|
-
});
|
|
159
|
-
node.specialOnFocus = props.onFocus || noop;
|
|
160
|
-
node.specialOnBlur = props.onBlur || noop;
|
|
161
|
-
|
|
162
|
-
node.onclick = function () {
|
|
163
|
-
return _this2.focusItem(node);
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
node.onfocus = function () {
|
|
167
|
-
_this2.focusItem(node);
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
if (afterIndex === -1) {
|
|
171
|
-
this.items.push(node);
|
|
172
|
-
} else {
|
|
173
|
-
this.items.splice(afterIndex, 0, node);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}, {
|
|
177
|
-
key: "unregister",
|
|
178
|
-
value: function unregister(node) {
|
|
179
|
-
var index = this.getItemIndexByNode(node);
|
|
180
|
-
if (index > -1) this.items.splice(index, 1);
|
|
181
|
-
}
|
|
182
|
-
}, {
|
|
183
|
-
key: "exit",
|
|
184
|
-
value: function exit() {
|
|
185
|
-
var onExitFocusGroup = this.options.onExitFocusGroup;
|
|
186
|
-
onExitFocusGroup();
|
|
187
|
-
}
|
|
188
|
-
}, {
|
|
189
|
-
key: "focusItem",
|
|
190
|
-
value: function focusItem(node) {
|
|
191
|
-
if (this.currentFocusedItem && this.currentFocusedItem !== node) {
|
|
192
|
-
this.currentFocusedItem.specialOnBlur();
|
|
193
|
-
this.currentFocusedItem.setAttribute('tabindex', -1);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (!node) return;
|
|
197
|
-
this.currentFocusedItem = node;
|
|
198
|
-
node.setAttribute('tabindex', 0);
|
|
199
|
-
node.focus();
|
|
200
|
-
node.specialOnFocus();
|
|
201
|
-
}
|
|
202
|
-
}, {
|
|
203
|
-
key: "focusNext",
|
|
204
|
-
value: function focusNext() {
|
|
205
|
-
var item = this.getNextItem();
|
|
206
|
-
this.focusItem(item);
|
|
207
|
-
}
|
|
208
|
-
}, {
|
|
209
|
-
key: "focusByNode",
|
|
210
|
-
value: function focusByNode(node) {
|
|
211
|
-
var index = this.getItemIndexByNode(node);
|
|
212
|
-
this.focusByIndex(index);
|
|
213
|
-
}
|
|
214
|
-
}, {
|
|
215
|
-
key: "focusByIndex",
|
|
216
|
-
value: function focusByIndex(index) {
|
|
217
|
-
var item = this.getItemByIndex(index);
|
|
218
|
-
this.focusItem(item);
|
|
219
|
-
}
|
|
220
|
-
}, {
|
|
221
|
-
key: "focusPrevious",
|
|
222
|
-
value: function focusPrevious() {
|
|
223
|
-
var prevItem = this.getPreviousItem();
|
|
224
|
-
this.focusItem(prevItem);
|
|
225
|
-
}
|
|
226
|
-
}, {
|
|
227
|
-
key: "focusFirst",
|
|
228
|
-
value: function focusFirst() {
|
|
229
|
-
var item = this.getFirstItem();
|
|
230
|
-
this.focusItem(item);
|
|
231
|
-
}
|
|
232
|
-
}, {
|
|
233
|
-
key: "focusLast",
|
|
234
|
-
value: function focusLast() {
|
|
235
|
-
var item = this.getLastItem();
|
|
236
|
-
this.focusItem(item);
|
|
237
|
-
}
|
|
238
|
-
}, {
|
|
239
|
-
key: "focusCurrent",
|
|
240
|
-
value: function focusCurrent() {
|
|
241
|
-
this.focusItem(this.currentFocusedItem);
|
|
242
|
-
}
|
|
243
|
-
}, {
|
|
244
|
-
key: "focusNextGroup",
|
|
245
|
-
value: function focusNextGroup() {
|
|
246
|
-
var onFocusNextGroup = this.options.onFocusNextGroup;
|
|
247
|
-
this.exit();
|
|
248
|
-
onFocusNextGroup();
|
|
249
|
-
}
|
|
250
|
-
}, {
|
|
251
|
-
key: "focusPreviousGroup",
|
|
252
|
-
value: function focusPreviousGroup() {
|
|
253
|
-
var onFocusPreviousGroup = this.options.onFocusPreviousGroup;
|
|
254
|
-
this.exit();
|
|
255
|
-
onFocusPreviousGroup();
|
|
256
|
-
}
|
|
257
|
-
}, {
|
|
258
|
-
key: "getNextItem",
|
|
259
|
-
value: function getNextItem() {
|
|
260
|
-
var loop = this.options.loop;
|
|
261
|
-
var currentIndex = this.getFocusedIndex();
|
|
262
|
-
var supposedNextIndex = currentIndex + 1;
|
|
263
|
-
|
|
264
|
-
if (!this.checkCanFocusNext(supposedNextIndex)) {
|
|
265
|
-
return loop ? this.getFirstItem() : this.focusNextGroup();
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
return this.getItemByIndex(supposedNextIndex);
|
|
269
|
-
}
|
|
270
|
-
}, {
|
|
271
|
-
key: "getPreviousItem",
|
|
272
|
-
value: function getPreviousItem() {
|
|
273
|
-
var loop = this.options.loop;
|
|
274
|
-
var currentIndex = this.getFocusedIndex();
|
|
275
|
-
var supposedPrevIndex = currentIndex - 1;
|
|
276
|
-
|
|
277
|
-
if (!this.checkCanFocusPrev(supposedPrevIndex)) {
|
|
278
|
-
return loop ? this.getLastItem() : this.focusPreviousGroup();
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
return this.getItemByIndex(supposedPrevIndex);
|
|
282
|
-
}
|
|
283
|
-
}, {
|
|
284
|
-
key: "checkCanFocusNext",
|
|
285
|
-
value: function checkCanFocusNext(index) {
|
|
286
|
-
return this.items.length > index;
|
|
287
|
-
}
|
|
288
|
-
}, {
|
|
289
|
-
key: "checkCanFocusPrev",
|
|
290
|
-
value: function checkCanFocusPrev(index) {
|
|
291
|
-
return index >= 0;
|
|
292
|
-
}
|
|
293
|
-
}, {
|
|
294
|
-
key: "getItemByIndex",
|
|
295
|
-
value: function getItemByIndex(index) {
|
|
296
|
-
return this.items[index];
|
|
297
|
-
}
|
|
298
|
-
}, {
|
|
299
|
-
key: "getItemIndexByNode",
|
|
300
|
-
value: function getItemIndexByNode(node) {
|
|
301
|
-
return this.items.findIndex(function (item) {
|
|
302
|
-
return item === node;
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
}, {
|
|
306
|
-
key: "getFocusedIndex",
|
|
307
|
-
value: function getFocusedIndex() {
|
|
308
|
-
return this.getItemIndexByNode(document.activeElement);
|
|
309
|
-
}
|
|
310
|
-
}, {
|
|
311
|
-
key: "getFocusedItem",
|
|
312
|
-
value: function getFocusedItem() {
|
|
313
|
-
var index = this.getFocusedIndex();
|
|
314
|
-
return index > -1 && this.items[index];
|
|
109
|
+
deactivate() {
|
|
110
|
+
document.removeEventListener('keydown', this.handleKeyDown, true);
|
|
111
|
+
unregisterHotKeys(this.options.hotKeys);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
handleKeyDown(e) {
|
|
115
|
+
if (!this.isGroupActive()) return;
|
|
116
|
+
this.executeActionByEvent(e);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
executeActionByEvent(e) {
|
|
120
|
+
const actions = Array.isArray(this.keyBindings[e.key]) ? this.keyBindings[e.key] : [this.keyBindings[e.key]];
|
|
121
|
+
return actions.map(action => typeof action === 'string' ? safeCallAction(e, this.mapActions[action]) : safeCallAction(e, action));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
register(node, props = {}) {
|
|
125
|
+
const afterIndex = this.items.findIndex(item => item.compareDocumentPosition(node) === Node.DOCUMENT_POSITION_PRECEDING);
|
|
126
|
+
node.specialOnFocus = props.onFocus || noop;
|
|
127
|
+
node.specialOnBlur = props.onBlur || noop;
|
|
128
|
+
|
|
129
|
+
node.onclick = () => this.focusItem(node);
|
|
130
|
+
|
|
131
|
+
node.onfocus = () => {
|
|
132
|
+
this.focusItem(node);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
if (afterIndex === -1) {
|
|
136
|
+
this.items.push(node);
|
|
137
|
+
} else {
|
|
138
|
+
this.items.splice(afterIndex, 0, node);
|
|
315
139
|
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
unregister(node) {
|
|
143
|
+
const index = this.getItemIndexByNode(node);
|
|
144
|
+
if (index > -1) this.items.splice(index, 1);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
exit() {
|
|
148
|
+
const {
|
|
149
|
+
onExitFocusGroup
|
|
150
|
+
} = this.options;
|
|
151
|
+
onExitFocusGroup();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
focusItem(node) {
|
|
155
|
+
if (this.currentFocusedItem && this.currentFocusedItem !== node) {
|
|
156
|
+
this.currentFocusedItem.specialOnBlur();
|
|
157
|
+
this.currentFocusedItem.setAttribute('tabindex', -1);
|
|
320
158
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
159
|
+
|
|
160
|
+
if (!node) return;
|
|
161
|
+
this.currentFocusedItem = node;
|
|
162
|
+
node.setAttribute('tabindex', 0);
|
|
163
|
+
node.focus();
|
|
164
|
+
node.specialOnFocus();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
focusNext() {
|
|
168
|
+
const item = this.getNextItem();
|
|
169
|
+
this.focusItem(item);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
focusByNode(node) {
|
|
173
|
+
const index = this.getItemIndexByNode(node);
|
|
174
|
+
this.focusByIndex(index);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
focusByIndex(index) {
|
|
178
|
+
const item = this.getItemByIndex(index);
|
|
179
|
+
this.focusItem(item);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
focusPrevious() {
|
|
183
|
+
const prevItem = this.getPreviousItem();
|
|
184
|
+
this.focusItem(prevItem);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
focusFirst() {
|
|
188
|
+
const item = this.getFirstItem();
|
|
189
|
+
this.focusItem(item);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
focusLast() {
|
|
193
|
+
const item = this.getLastItem();
|
|
194
|
+
this.focusItem(item);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
focusCurrent() {
|
|
198
|
+
this.focusItem(this.currentFocusedItem);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
focusNextGroup() {
|
|
202
|
+
const {
|
|
203
|
+
onFocusNextGroup
|
|
204
|
+
} = this.options;
|
|
205
|
+
this.exit();
|
|
206
|
+
onFocusNextGroup();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
focusPreviousGroup() {
|
|
210
|
+
const {
|
|
211
|
+
onFocusPreviousGroup
|
|
212
|
+
} = this.options;
|
|
213
|
+
this.exit();
|
|
214
|
+
onFocusPreviousGroup();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
getNextItem() {
|
|
218
|
+
const {
|
|
219
|
+
loop
|
|
220
|
+
} = this.options;
|
|
221
|
+
const currentIndex = this.getFocusedIndex();
|
|
222
|
+
const supposedNextIndex = currentIndex + 1;
|
|
223
|
+
|
|
224
|
+
if (!this.checkCanFocusNext(supposedNextIndex)) {
|
|
225
|
+
return loop ? this.getFirstItem() : this.focusNextGroup();
|
|
325
226
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
227
|
+
|
|
228
|
+
return this.getItemByIndex(supposedNextIndex);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
getPreviousItem() {
|
|
232
|
+
const {
|
|
233
|
+
loop
|
|
234
|
+
} = this.options;
|
|
235
|
+
const currentIndex = this.getFocusedIndex();
|
|
236
|
+
const supposedPrevIndex = currentIndex - 1;
|
|
237
|
+
|
|
238
|
+
if (!this.checkCanFocusPrev(supposedPrevIndex)) {
|
|
239
|
+
return loop ? this.getLastItem() : this.focusPreviousGroup();
|
|
330
240
|
}
|
|
331
|
-
}]);
|
|
332
241
|
|
|
333
|
-
|
|
334
|
-
}
|
|
242
|
+
return this.getItemByIndex(supposedPrevIndex);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
checkCanFocusNext(index) {
|
|
246
|
+
return this.items.length > index;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
checkCanFocusPrev(index) {
|
|
250
|
+
return index >= 0;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
getItemByIndex(index) {
|
|
254
|
+
return this.items[index];
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
getItemIndexByNode(node) {
|
|
258
|
+
return this.items.findIndex(item => item === node);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
getFocusedIndex() {
|
|
262
|
+
return this.getItemIndexByNode(document.activeElement);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
getFocusedItem() {
|
|
266
|
+
const index = this.getFocusedIndex();
|
|
267
|
+
return index > -1 && this.items[index];
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
isGroupActive() {
|
|
271
|
+
return this.getFocusedIndex() !== -1;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
getFirstItem() {
|
|
275
|
+
return !!this.items.length && this.items[0];
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
getLastItem() {
|
|
279
|
+
return !!this.items.length && this.items[this.items.length - 1];
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
}
|
|
335
283
|
|
|
336
284
|
export { FocusGroup as default };
|
|
337
|
-
//# sourceMappingURL=FocusGroup.js.map
|