@elliemae/ds-shared 2.2.0-alpha.4 → 3.0.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/Animations/BaseAnimation.js +35 -55
- package/cjs/Animations/Grow.js +41 -54
- package/cjs/Animations/GrowRight.js +41 -63
- package/cjs/Animations/GrowVertical.js +7 -47
- package/cjs/CheckableGroup.js +65 -67
- package/cjs/DeferRenderAfterComputation.js +24 -48
- package/cjs/FocusGroup/FocusGrid.js +143 -108
- package/cjs/FocusGroup/FocusGroup.js +147 -88
- package/cjs/FocusGroup/FocusGroupContext.js +11 -38
- package/cjs/FocusGroup/FocusGroupManager.js +47 -56
- package/cjs/FocusGroup/focusGroupManagerHoc.js +42 -52
- package/cjs/FocusGroup/index.js +21 -47
- package/cjs/FocusGroup/useFocusGroupItem.js +51 -59
- package/cjs/FocusGroup/utils/getNextCellPosition.js +27 -47
- package/cjs/GroupContext/Group.js +73 -64
- package/cjs/GroupContext/GroupContext.js +13 -36
- package/cjs/GroupContext/GroupItem.js +21 -39
- package/cjs/GroupContext/index.js +13 -39
- package/cjs/ScrollSync/ScrollSync.js +75 -60
- package/cjs/ScrollSync/ScrollSyncPane.js +60 -52
- package/cjs/ScrollSync/ScrollSyncProvider.js +50 -103
- package/cjs/ScrollSync/index.js +11 -37
- package/cjs/ScrollSync/useScrollSync.js +7 -38
- package/cjs/constants.js +46 -65
- package/cjs/createDataInstance/createInstancePlugin.js +29 -41
- package/cjs/createDataInstance/createInstanceRef.js +71 -66
- package/cjs/createDataInstance/utils.js +100 -76
- package/cjs/defer-render-hoc/index.js +41 -48
- package/cjs/dimsum.config.js +6 -38
- package/cjs/index.js +17 -40
- package/cjs/prop-types.js +49 -106
- package/cjs/react-spring/index.js +14 -28
- package/cjs/react-spring/renderprops.js +14 -28
- package/cjs/toolbar/ToolbarProvider.js +94 -82
- package/cjs/useDataGrid/VolatileRowsListener.js +13 -38
- package/cjs/useDataGrid/index.js +7 -36
- package/cjs/useDataGrid/initColumnDefinition.js +110 -105
- package/cjs/useDataGrid/useDataGrid.js +148 -122
- package/cjs/useDataList/index.js +7 -36
- package/cjs/useDataList/recordIterator.js +18 -42
- package/cjs/useDataList/useDataList.js +83 -74
- package/cjs/utils.js +80 -71
- package/cjs/virtualization/AutoHeightList.js +54 -62
- package/cjs/virtualization/FluidHeightList.js +48 -42
- package/cjs/virtualization/index.js +20 -48
- package/esm/Animations/BaseAnimation.js +29 -26
- package/esm/Animations/Grow.js +35 -25
- package/esm/Animations/GrowRight.js +35 -34
- package/esm/Animations/GrowVertical.js +4 -29
- package/esm/CheckableGroup.js +52 -35
- package/esm/DeferRenderAfterComputation.js +15 -16
- package/esm/FocusGroup/FocusGrid.js +117 -64
- package/esm/FocusGroup/FocusGroup.js +137 -56
- package/esm/FocusGroup/FocusGroupContext.js +5 -9
- package/esm/FocusGroup/FocusGroupManager.js +38 -24
- package/esm/FocusGroup/focusGroupManagerHoc.js +36 -24
- package/esm/FocusGroup/index.js +6 -18
- package/esm/FocusGroup/useFocusGroupItem.js +40 -28
- package/esm/FocusGroup/utils/getNextCellPosition.js +25 -18
- package/esm/GroupContext/Group.js +66 -34
- package/esm/GroupContext/GroupContext.js +5 -7
- package/esm/GroupContext/GroupItem.js +15 -10
- package/esm/GroupContext/index.js +3 -10
- package/esm/ScrollSync/ScrollSync.js +64 -30
- package/esm/ScrollSync/ScrollSyncPane.js +52 -22
- package/esm/ScrollSync/ScrollSyncProvider.js +42 -74
- package/esm/ScrollSync/index.js +2 -8
- package/esm/ScrollSync/useScrollSync.js +5 -9
- package/esm/constants.js +28 -37
- package/esm/createDataInstance/createInstancePlugin.js +23 -12
- package/esm/createDataInstance/createInstanceRef.js +59 -36
- package/esm/createDataInstance/utils.js +85 -48
- package/esm/defer-render-hoc/index.js +31 -17
- package/esm/dimsum.config.js +4 -9
- package/esm/index.js +5 -11
- package/esm/prop-types.js +31 -75
- package/esm/react-spring/index.js +1 -3
- package/esm/react-spring/renderprops.js +1 -3
- package/esm/toolbar/ToolbarProvider.js +74 -45
- package/esm/useDataGrid/VolatileRowsListener.js +11 -9
- package/esm/useDataGrid/index.js +1 -7
- package/esm/useDataGrid/initColumnDefinition.js +94 -78
- package/esm/useDataGrid/useDataGrid.js +99 -82
- package/esm/useDataList/index.js +1 -7
- package/esm/useDataList/recordIterator.js +14 -13
- package/esm/useDataList/useDataList.js +67 -44
- package/esm/utils.js +59 -42
- package/esm/virtualization/AutoHeightList.js +40 -28
- package/esm/virtualization/FluidHeightList.js +38 -14
- package/esm/virtualization/index.js +16 -19
- package/package.json +3 -3
- package/types/Animations/BaseAnimation.d.ts +0 -1
- package/types/Animations/Grow.d.ts +0 -1
- package/types/Animations/GrowRight.d.ts +0 -1
- package/types/CheckableGroup.d.ts +0 -1
- package/types/DeferRenderAfterComputation.d.ts +2 -3
- package/types/FocusGroup/FocusGrid.d.ts +3 -5
- package/types/FocusGroup/FocusGroup.d.ts +1 -3
- package/types/FocusGroup/FocusGroupContext.d.ts +2 -3
- package/types/FocusGroup/FocusGroupManager.d.ts +1 -3
- package/types/FocusGroup/focusGroupManagerHoc.d.ts +1 -3
- package/types/FocusGroup/index.d.ts +6 -6
- package/types/FocusGroup/useFocusGroupItem.d.ts +1 -3
- package/types/FocusGroup/utils/getNextCellPosition.d.ts +1 -3
- package/types/GroupContext/Group.d.ts +0 -1
- package/types/GroupContext/GroupItem.d.ts +0 -1
- package/types/GroupContext/index.d.ts +3 -3
- package/types/ScrollSync/ScrollSync.d.ts +2 -4
- package/types/ScrollSync/ScrollSyncPane.d.ts +2 -2
- package/types/ScrollSync/index.d.ts +2 -2
- package/types/ScrollSync/useScrollSync.d.ts +5 -6
- package/types/createDataInstance/createInstancePlugin.d.ts +1 -2
- package/types/createDataInstance/createInstanceRef.d.ts +1 -3
- package/types/dimsum.config.d.ts +2 -3
- package/types/index.d.ts +2 -2
- package/types/toolbar/ToolbarProvider.d.ts +8 -3
- package/types/useDataGrid/VolatileRowsListener.d.ts +1 -3
- package/types/useDataGrid/index.d.ts +1 -1
- package/types/useDataGrid/initColumnDefinition.d.ts +1 -2
- package/types/useDataGrid/useDataGrid.d.ts +2 -3
- package/types/useDataList/index.d.ts +1 -1
- package/types/useDataList/useDataList.d.ts +2 -3
- package/cjs/Animations/BaseAnimation.js.map +0 -7
- package/cjs/Animations/Grow.js.map +0 -7
- package/cjs/Animations/GrowRight.js.map +0 -7
- package/cjs/Animations/GrowVertical.js.map +0 -7
- package/cjs/CheckableGroup.js.map +0 -7
- package/cjs/DeferRenderAfterComputation.js.map +0 -7
- package/cjs/FocusGroup/FocusGrid.js.map +0 -7
- package/cjs/FocusGroup/FocusGroup.js.map +0 -7
- package/cjs/FocusGroup/FocusGroupContext.js.map +0 -7
- package/cjs/FocusGroup/FocusGroupManager.js.map +0 -7
- package/cjs/FocusGroup/focusGroupManagerHoc.js.map +0 -7
- package/cjs/FocusGroup/index.js.map +0 -7
- package/cjs/FocusGroup/useFocusGroupItem.js.map +0 -7
- package/cjs/FocusGroup/utils/getNextCellPosition.js.map +0 -7
- package/cjs/GroupContext/Group.js.map +0 -7
- package/cjs/GroupContext/GroupContext.js.map +0 -7
- package/cjs/GroupContext/GroupItem.js.map +0 -7
- package/cjs/GroupContext/index.js.map +0 -7
- package/cjs/ScrollSync/ScrollSync.js.map +0 -7
- package/cjs/ScrollSync/ScrollSyncPane.js.map +0 -7
- package/cjs/ScrollSync/ScrollSyncProvider.js.map +0 -7
- package/cjs/ScrollSync/index.js.map +0 -7
- package/cjs/ScrollSync/useScrollSync.js.map +0 -7
- package/cjs/constants.js.map +0 -7
- package/cjs/createDataInstance/createInstancePlugin.js.map +0 -7
- package/cjs/createDataInstance/createInstanceRef.js.map +0 -7
- package/cjs/createDataInstance/utils.js.map +0 -7
- package/cjs/defer-render-hoc/index.js.map +0 -7
- package/cjs/dimsum.config.js.map +0 -7
- package/cjs/index.js.map +0 -7
- package/cjs/prop-types.js.map +0 -7
- package/cjs/react-spring/index.js.map +0 -7
- package/cjs/react-spring/renderprops.js.map +0 -7
- package/cjs/toolbar/ToolbarProvider.js.map +0 -7
- package/cjs/useDataGrid/VolatileRowsListener.js.map +0 -7
- package/cjs/useDataGrid/index.js.map +0 -7
- package/cjs/useDataGrid/initColumnDefinition.js.map +0 -7
- package/cjs/useDataGrid/useDataGrid.js.map +0 -7
- package/cjs/useDataList/index.js.map +0 -7
- package/cjs/useDataList/recordIterator.js.map +0 -7
- package/cjs/useDataList/useDataList.js.map +0 -7
- package/cjs/utils.js.map +0 -7
- package/cjs/virtualization/AutoHeightList.js.map +0 -7
- package/cjs/virtualization/FluidHeightList.js.map +0 -7
- package/cjs/virtualization/index.js.map +0 -7
- package/esm/Animations/BaseAnimation.js.map +0 -7
- package/esm/Animations/Grow.js.map +0 -7
- package/esm/Animations/GrowRight.js.map +0 -7
- package/esm/Animations/GrowVertical.js.map +0 -7
- package/esm/CheckableGroup.js.map +0 -7
- package/esm/DeferRenderAfterComputation.js.map +0 -7
- package/esm/FocusGroup/FocusGrid.js.map +0 -7
- package/esm/FocusGroup/FocusGroup.js.map +0 -7
- package/esm/FocusGroup/FocusGroupContext.js.map +0 -7
- package/esm/FocusGroup/FocusGroupManager.js.map +0 -7
- package/esm/FocusGroup/focusGroupManagerHoc.js.map +0 -7
- package/esm/FocusGroup/index.js.map +0 -7
- package/esm/FocusGroup/useFocusGroupItem.js.map +0 -7
- package/esm/FocusGroup/utils/getNextCellPosition.js.map +0 -7
- package/esm/GroupContext/Group.js.map +0 -7
- package/esm/GroupContext/GroupContext.js.map +0 -7
- package/esm/GroupContext/GroupItem.js.map +0 -7
- package/esm/GroupContext/index.js.map +0 -7
- package/esm/ScrollSync/ScrollSync.js.map +0 -7
- package/esm/ScrollSync/ScrollSyncPane.js.map +0 -7
- package/esm/ScrollSync/ScrollSyncProvider.js.map +0 -7
- package/esm/ScrollSync/index.js.map +0 -7
- package/esm/ScrollSync/useScrollSync.js.map +0 -7
- package/esm/constants.js.map +0 -7
- package/esm/createDataInstance/createInstancePlugin.js.map +0 -7
- package/esm/createDataInstance/createInstanceRef.js.map +0 -7
- package/esm/createDataInstance/utils.js.map +0 -7
- package/esm/defer-render-hoc/index.js.map +0 -7
- package/esm/dimsum.config.js.map +0 -7
- package/esm/index.js.map +0 -7
- package/esm/prop-types.js.map +0 -7
- package/esm/react-spring/index.js.map +0 -7
- package/esm/react-spring/renderprops.js.map +0 -7
- package/esm/toolbar/ToolbarProvider.js.map +0 -7
- package/esm/useDataGrid/VolatileRowsListener.js.map +0 -7
- package/esm/useDataGrid/index.js.map +0 -7
- package/esm/useDataGrid/initColumnDefinition.js.map +0 -7
- package/esm/useDataGrid/useDataGrid.js.map +0 -7
- package/esm/useDataList/index.js.map +0 -7
- package/esm/useDataList/recordIterator.js.map +0 -7
- package/esm/useDataList/useDataList.js.map +0 -7
- package/esm/utils.js.map +0 -7
- package/esm/virtualization/AutoHeightList.js.map +0 -7
- package/esm/virtualization/FluidHeightList.js.map +0 -7
- package/esm/virtualization/index.js.map +0 -7
|
@@ -1,51 +1,86 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
4
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
5
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
6
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
7
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
8
|
+
import 'core-js/modules/esnext.async-iterator.map.js';
|
|
9
|
+
import 'core-js/modules/esnext.iterator.map.js';
|
|
10
|
+
import { get, isFunction } from '@elliemae/ds-utilities';
|
|
11
|
+
import hotkeys from 'hotkeys-js';
|
|
12
|
+
|
|
13
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
14
|
+
|
|
15
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
16
|
const defaultOptions = {
|
|
5
|
-
orientation:
|
|
17
|
+
orientation: 'vertical'
|
|
6
18
|
};
|
|
7
|
-
|
|
19
|
+
|
|
20
|
+
const safeCallAction = function (e, fun) {
|
|
8
21
|
if (isFunction(fun)) {
|
|
9
22
|
e.preventDefault();
|
|
23
|
+
|
|
24
|
+
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
25
|
+
args[_key - 2] = arguments[_key];
|
|
26
|
+
}
|
|
27
|
+
|
|
10
28
|
fun(...args);
|
|
11
29
|
}
|
|
12
30
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
31
|
+
|
|
32
|
+
const registerHotkeys = function () {
|
|
33
|
+
let hotKeys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
34
|
+
let params = arguments.length > 1 ? arguments[1] : undefined;
|
|
35
|
+
let getContainer = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : () => document;
|
|
36
|
+
Object.keys(hotKeys).forEach(hotkey => {
|
|
37
|
+
const {
|
|
38
|
+
options,
|
|
39
|
+
handler,
|
|
40
|
+
allowDocumentHandler = false
|
|
41
|
+
} = hotKeys[hotkey];
|
|
42
|
+
|
|
43
|
+
const parameterizedHandler = e => {
|
|
17
44
|
const handlerParams = isFunction(params) ? params() : params;
|
|
18
|
-
if (!allowDocumentHandler && handlerParams.item !== document.activeElement)
|
|
19
|
-
return;
|
|
45
|
+
if (!allowDocumentHandler && handlerParams.item !== document.activeElement) return;
|
|
20
46
|
e.preventDefault();
|
|
21
47
|
handler(handlerParams);
|
|
22
48
|
};
|
|
23
|
-
|
|
49
|
+
|
|
50
|
+
hotkeys(hotkey, _objectSpread({
|
|
51
|
+
element: getContainer()
|
|
52
|
+
}, options), parameterizedHandler);
|
|
24
53
|
});
|
|
25
54
|
};
|
|
26
|
-
|
|
27
|
-
|
|
55
|
+
|
|
56
|
+
const unregisterHotKeys = function () {
|
|
57
|
+
let hotKeys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
58
|
+
Object.keys(hotKeys).forEach(hotkey => {
|
|
28
59
|
hotkeys.unbind(hotkey);
|
|
29
60
|
});
|
|
30
61
|
};
|
|
62
|
+
|
|
31
63
|
const noop = () => null;
|
|
64
|
+
|
|
32
65
|
class FocusGroup {
|
|
33
|
-
constructor(
|
|
66
|
+
constructor() {
|
|
67
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
34
68
|
this.items = [];
|
|
35
|
-
this.options = {
|
|
36
|
-
const {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
69
|
+
this.options = _objectSpread(_objectSpread({}, defaultOptions), options);
|
|
70
|
+
const {
|
|
71
|
+
orientation
|
|
72
|
+
} = this.options;
|
|
73
|
+
this.keyBindings = _objectSpread({
|
|
74
|
+
ArrowUp: orientation !== 'horizontal' && 'previous',
|
|
75
|
+
ArrowRight: orientation !== 'vertical' && 'next',
|
|
76
|
+
ArrowDown: orientation !== 'horizontal' && 'next',
|
|
77
|
+
ArrowLeft: orientation !== 'vertical' && 'previous',
|
|
78
|
+
Home: 'first',
|
|
79
|
+
End: 'last',
|
|
80
|
+
PageUp: 'first',
|
|
81
|
+
PageDown: 'last',
|
|
82
|
+
Escape: 'exit'
|
|
83
|
+
}, options.keyBindings);
|
|
49
84
|
this.currentFocusedItem = null;
|
|
50
85
|
this.currIndex = null;
|
|
51
86
|
this.mapActions = {
|
|
@@ -67,154 +102,200 @@ class FocusGroup {
|
|
|
67
102
|
this.focusCurrent = this.focusCurrent.bind(this);
|
|
68
103
|
this.getHotKeysParams = this.getHotKeysParams.bind(this);
|
|
69
104
|
}
|
|
105
|
+
|
|
70
106
|
getHotKeysParams() {
|
|
71
107
|
const item = this.currentFocusedItem;
|
|
72
|
-
const {
|
|
108
|
+
const {
|
|
109
|
+
index
|
|
110
|
+
} = get(item, ['dataset'], {});
|
|
73
111
|
return {
|
|
74
112
|
item,
|
|
75
113
|
index
|
|
76
114
|
};
|
|
77
115
|
}
|
|
116
|
+
|
|
78
117
|
activate() {
|
|
79
|
-
const {
|
|
80
|
-
|
|
118
|
+
const {
|
|
119
|
+
getContainer
|
|
120
|
+
} = this.options;
|
|
121
|
+
document.addEventListener('keydown', this.handleKeyDown, true);
|
|
81
122
|
registerHotkeys(this.options.hotKeys, this.getHotKeysParams, getContainer);
|
|
82
123
|
}
|
|
124
|
+
|
|
83
125
|
deactivate() {
|
|
84
|
-
document.removeEventListener(
|
|
126
|
+
document.removeEventListener('keydown', this.handleKeyDown, true);
|
|
85
127
|
unregisterHotKeys(this.options.hotKeys);
|
|
86
128
|
}
|
|
129
|
+
|
|
87
130
|
handleKeyDown(e) {
|
|
88
|
-
if (!this.isGroupActive())
|
|
89
|
-
return;
|
|
131
|
+
if (!this.isGroupActive()) return;
|
|
90
132
|
this.executeActionByEvent(e);
|
|
91
133
|
}
|
|
134
|
+
|
|
92
135
|
executeActionByEvent(e) {
|
|
93
136
|
const actions = Array.isArray(this.keyBindings[e.key]) ? this.keyBindings[e.key] : [this.keyBindings[e.key]];
|
|
94
|
-
return actions.map(
|
|
137
|
+
return actions.map(action => typeof action === 'string' ? safeCallAction(e, this.mapActions[action]) : safeCallAction(e, action));
|
|
95
138
|
}
|
|
96
|
-
|
|
97
|
-
|
|
139
|
+
|
|
140
|
+
register(node) {
|
|
141
|
+
let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
142
|
+
const afterIndex = this.items.findIndex(item => item.compareDocumentPosition(node) === Node.DOCUMENT_POSITION_PRECEDING);
|
|
98
143
|
node.specialOnFocus = props.onFocus || noop;
|
|
99
144
|
node.specialOnBlur = props.onBlur || noop;
|
|
145
|
+
|
|
100
146
|
node.onclick = () => this.focusItem(node);
|
|
147
|
+
|
|
101
148
|
node.onfocus = () => {
|
|
102
149
|
this.focusItem(node);
|
|
103
150
|
};
|
|
151
|
+
|
|
104
152
|
if (afterIndex === -1) {
|
|
105
153
|
this.items.push(node);
|
|
106
154
|
} else {
|
|
107
155
|
this.items.splice(afterIndex, 0, node);
|
|
108
156
|
}
|
|
109
157
|
}
|
|
158
|
+
|
|
110
159
|
unregister(node) {
|
|
111
160
|
const index = this.getItemIndexByNode(node);
|
|
112
|
-
if (index > -1)
|
|
113
|
-
this.items.splice(index, 1);
|
|
161
|
+
if (index > -1) this.items.splice(index, 1);
|
|
114
162
|
}
|
|
163
|
+
|
|
115
164
|
exit() {
|
|
116
|
-
const {
|
|
165
|
+
const {
|
|
166
|
+
onExitFocusGroup
|
|
167
|
+
} = this.options;
|
|
117
168
|
onExitFocusGroup();
|
|
118
169
|
}
|
|
170
|
+
|
|
119
171
|
focusItem(node) {
|
|
120
172
|
if (this.currentFocusedItem && this.currentFocusedItem !== node) {
|
|
121
173
|
this.currentFocusedItem.specialOnBlur();
|
|
122
|
-
this.currentFocusedItem.setAttribute(
|
|
174
|
+
this.currentFocusedItem.setAttribute('tabindex', -1);
|
|
123
175
|
}
|
|
124
|
-
|
|
125
|
-
|
|
176
|
+
|
|
177
|
+
if (!node) return;
|
|
126
178
|
this.currentFocusedItem = node;
|
|
127
|
-
node.setAttribute(
|
|
179
|
+
node.setAttribute('tabindex', 0);
|
|
128
180
|
node.focus();
|
|
129
181
|
node.specialOnFocus();
|
|
130
182
|
}
|
|
183
|
+
|
|
131
184
|
focusNext() {
|
|
132
185
|
const item = this.getNextItem();
|
|
133
186
|
this.focusItem(item);
|
|
134
187
|
}
|
|
188
|
+
|
|
135
189
|
focusByNode(node) {
|
|
136
190
|
const index = this.getItemIndexByNode(node);
|
|
137
191
|
this.focusByIndex(index);
|
|
138
192
|
}
|
|
193
|
+
|
|
139
194
|
focusByIndex(index) {
|
|
140
195
|
const item = this.getItemByIndex(index);
|
|
141
196
|
this.focusItem(item);
|
|
142
197
|
}
|
|
198
|
+
|
|
143
199
|
focusPrevious() {
|
|
144
200
|
const prevItem = this.getPreviousItem();
|
|
145
201
|
this.focusItem(prevItem);
|
|
146
202
|
}
|
|
203
|
+
|
|
147
204
|
focusFirst() {
|
|
148
205
|
const item = this.getFirstItem();
|
|
149
206
|
this.focusItem(item);
|
|
150
207
|
}
|
|
208
|
+
|
|
151
209
|
focusLast() {
|
|
152
210
|
const item = this.getLastItem();
|
|
153
211
|
this.focusItem(item);
|
|
154
212
|
}
|
|
213
|
+
|
|
155
214
|
focusCurrent() {
|
|
156
215
|
this.focusItem(this.currentFocusedItem);
|
|
157
216
|
}
|
|
217
|
+
|
|
158
218
|
focusNextGroup() {
|
|
159
|
-
const {
|
|
219
|
+
const {
|
|
220
|
+
onFocusNextGroup
|
|
221
|
+
} = this.options;
|
|
160
222
|
this.exit();
|
|
161
223
|
onFocusNextGroup();
|
|
162
224
|
}
|
|
225
|
+
|
|
163
226
|
focusPreviousGroup() {
|
|
164
|
-
const {
|
|
227
|
+
const {
|
|
228
|
+
onFocusPreviousGroup
|
|
229
|
+
} = this.options;
|
|
165
230
|
this.exit();
|
|
166
231
|
onFocusPreviousGroup();
|
|
167
232
|
}
|
|
233
|
+
|
|
168
234
|
getNextItem() {
|
|
169
|
-
const {
|
|
235
|
+
const {
|
|
236
|
+
loop
|
|
237
|
+
} = this.options;
|
|
170
238
|
const currentIndex = this.getFocusedIndex();
|
|
171
239
|
const supposedNextIndex = currentIndex + 1;
|
|
240
|
+
|
|
172
241
|
if (!this.checkCanFocusNext(supposedNextIndex)) {
|
|
173
242
|
return loop ? this.getFirstItem() : this.focusNextGroup();
|
|
174
243
|
}
|
|
244
|
+
|
|
175
245
|
return this.getItemByIndex(supposedNextIndex);
|
|
176
246
|
}
|
|
247
|
+
|
|
177
248
|
getPreviousItem() {
|
|
178
|
-
const {
|
|
249
|
+
const {
|
|
250
|
+
loop
|
|
251
|
+
} = this.options;
|
|
179
252
|
const currentIndex = this.getFocusedIndex();
|
|
180
253
|
const supposedPrevIndex = currentIndex - 1;
|
|
254
|
+
|
|
181
255
|
if (!this.checkCanFocusPrev(supposedPrevIndex)) {
|
|
182
256
|
return loop ? this.getLastItem() : this.focusPreviousGroup();
|
|
183
257
|
}
|
|
258
|
+
|
|
184
259
|
return this.getItemByIndex(supposedPrevIndex);
|
|
185
260
|
}
|
|
261
|
+
|
|
186
262
|
checkCanFocusNext(index) {
|
|
187
263
|
return this.items.length > index;
|
|
188
264
|
}
|
|
265
|
+
|
|
189
266
|
checkCanFocusPrev(index) {
|
|
190
267
|
return index >= 0;
|
|
191
268
|
}
|
|
269
|
+
|
|
192
270
|
getItemByIndex(index) {
|
|
193
271
|
return this.items[index];
|
|
194
272
|
}
|
|
273
|
+
|
|
195
274
|
getItemIndexByNode(node) {
|
|
196
|
-
return this.items.findIndex(
|
|
275
|
+
return this.items.findIndex(item => item === node);
|
|
197
276
|
}
|
|
277
|
+
|
|
198
278
|
getFocusedIndex() {
|
|
199
279
|
return this.getItemIndexByNode(document.activeElement);
|
|
200
280
|
}
|
|
281
|
+
|
|
201
282
|
getFocusedItem() {
|
|
202
283
|
const index = this.getFocusedIndex();
|
|
203
284
|
return index > -1 && this.items[index];
|
|
204
285
|
}
|
|
286
|
+
|
|
205
287
|
isGroupActive() {
|
|
206
288
|
return this.getFocusedIndex() !== -1;
|
|
207
289
|
}
|
|
290
|
+
|
|
208
291
|
getFirstItem() {
|
|
209
292
|
return !!this.items.length && this.items[0];
|
|
210
293
|
}
|
|
294
|
+
|
|
211
295
|
getLastItem() {
|
|
212
296
|
return !!this.items.length && this.items[this.items.length - 1];
|
|
213
297
|
}
|
|
298
|
+
|
|
214
299
|
}
|
|
215
|
-
|
|
216
|
-
export {
|
|
217
|
-
FocusGroup,
|
|
218
|
-
FocusGroup_default as default
|
|
219
|
-
};
|
|
220
|
-
//# sourceMappingURL=FocusGroup.js.map
|
|
300
|
+
|
|
301
|
+
export { FocusGroup as default };
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
FocusGroupContext,
|
|
7
|
-
FocusGroupContext_default as default
|
|
8
|
-
};
|
|
9
|
-
//# sourceMappingURL=FocusGroupContext.js.map
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
var FocusGroupContext = /*#__PURE__*/React.createContext();
|
|
4
|
+
|
|
5
|
+
export { FocusGroupContext as default };
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { isFunction } from
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
2
|
+
import { Component } from 'react';
|
|
3
|
+
import { isFunction } from '@elliemae/ds-utilities';
|
|
4
|
+
import FocusGroup from './FocusGroup.js';
|
|
5
|
+
import FocusGroupContext from './FocusGroupContext.js';
|
|
6
|
+
|
|
6
7
|
const noop = () => null;
|
|
8
|
+
|
|
7
9
|
class FocusGroupProvider extends Component {
|
|
8
10
|
constructor(props) {
|
|
9
11
|
super(props);
|
|
@@ -25,58 +27,75 @@ class FocusGroupProvider extends Component {
|
|
|
25
27
|
focusPrevious: this.focusGroup.focusPrevious
|
|
26
28
|
};
|
|
27
29
|
}
|
|
30
|
+
|
|
28
31
|
componentDidMount() {
|
|
29
|
-
const {
|
|
32
|
+
const {
|
|
33
|
+
autoFocusOnMount
|
|
34
|
+
} = this.props;
|
|
30
35
|
this.activate();
|
|
36
|
+
|
|
31
37
|
if (autoFocusOnMount) {
|
|
32
38
|
setTimeout(() => {
|
|
33
39
|
this.actions.focusFirst();
|
|
34
40
|
}, 0);
|
|
35
41
|
}
|
|
36
42
|
}
|
|
43
|
+
|
|
37
44
|
componentWillUnmount() {
|
|
38
45
|
this.deactivate();
|
|
39
46
|
}
|
|
47
|
+
|
|
40
48
|
activate() {
|
|
41
|
-
const {
|
|
49
|
+
const {
|
|
50
|
+
onActivate
|
|
51
|
+
} = this.props;
|
|
42
52
|
this.focusGroup.activate();
|
|
43
53
|
this.activated = true;
|
|
44
|
-
if (isFunction(onActivate))
|
|
45
|
-
onActivate();
|
|
54
|
+
if (isFunction(onActivate)) onActivate();
|
|
46
55
|
}
|
|
56
|
+
|
|
47
57
|
deactivate() {
|
|
48
|
-
const {
|
|
58
|
+
const {
|
|
59
|
+
onExitFocusGroup
|
|
60
|
+
} = this.props;
|
|
49
61
|
this.activated = false;
|
|
50
62
|
this.focusGroup.deactivate();
|
|
63
|
+
|
|
51
64
|
if (isFunction(onExitFocusGroup)) {
|
|
52
65
|
onExitFocusGroup();
|
|
53
66
|
}
|
|
54
67
|
}
|
|
68
|
+
|
|
55
69
|
register(item) {
|
|
56
70
|
this.focusGroup.register(item);
|
|
57
71
|
}
|
|
72
|
+
|
|
58
73
|
unregister(item) {
|
|
59
74
|
this.focusGroup.unregister(item);
|
|
60
75
|
}
|
|
76
|
+
|
|
61
77
|
focusItemByIndex(index) {
|
|
62
|
-
if (!this.activated)
|
|
63
|
-
this.activate();
|
|
78
|
+
if (!this.activated) this.activate();
|
|
64
79
|
setTimeout(() => {
|
|
65
80
|
this.focusGroup.focusByIndex(index);
|
|
66
81
|
}, 200);
|
|
67
82
|
}
|
|
83
|
+
|
|
68
84
|
focusItemByNode(node) {
|
|
69
|
-
if (!this.activated)
|
|
70
|
-
this.activate();
|
|
85
|
+
if (!this.activated) this.activate();
|
|
71
86
|
const index = this.focusGroup.getItemIndexByNode(node);
|
|
72
87
|
this.focusItemByIndex(index);
|
|
73
88
|
}
|
|
89
|
+
|
|
74
90
|
render() {
|
|
75
|
-
const {
|
|
76
|
-
|
|
91
|
+
const {
|
|
92
|
+
children
|
|
93
|
+
} = this.props;
|
|
94
|
+
return /*#__PURE__*/_jsx(FocusGroupContext.Provider, {
|
|
77
95
|
value: this.actions
|
|
78
|
-
}, children);
|
|
96
|
+
}, void 0, children);
|
|
79
97
|
}
|
|
98
|
+
|
|
80
99
|
}
|
|
81
100
|
FocusGroupProvider.defaultProps = {
|
|
82
101
|
exitWhenNoPrevious: false,
|
|
@@ -88,10 +107,5 @@ FocusGroupProvider.defaultProps = {
|
|
|
88
107
|
onFocusNextGroup: noop,
|
|
89
108
|
onFocusGroupSet: noop
|
|
90
109
|
};
|
|
91
|
-
|
|
92
|
-
export {
|
|
93
|
-
FocusGroupProvider as FocusGroupManager,
|
|
94
|
-
FocusGroupProvider,
|
|
95
|
-
FocusGroupManager_default as default
|
|
96
|
-
};
|
|
97
|
-
//# sourceMappingURL=FocusGroupManager.js.map
|
|
110
|
+
|
|
111
|
+
export { FocusGroupProvider as default };
|
|
@@ -1,25 +1,37 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
6
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
7
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
|
|
8
|
+
import 'react';
|
|
9
|
+
import FocusGroupProvider from './FocusGroupManager.js';
|
|
10
|
+
import { jsx } from 'react/jsx-runtime';
|
|
11
|
+
|
|
12
|
+
const _excluded = ["onExitFocusGroup", "onFocusPrevGroup", "focusKeyBindings"];
|
|
13
|
+
|
|
14
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
+
|
|
16
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
|
+
function FocusGroupHoc(WrappedComponent) {
|
|
18
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
19
|
+
return _ref => {
|
|
20
|
+
let {
|
|
21
|
+
onExitFocusGroup,
|
|
22
|
+
onFocusPrevGroup,
|
|
23
|
+
focusKeyBindings
|
|
24
|
+
} = _ref,
|
|
25
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
26
|
+
|
|
27
|
+
return /*#__PURE__*/jsx(FocusGroupProvider, _objectSpread(_objectSpread({
|
|
28
|
+
keyBindings: focusKeyBindings,
|
|
29
|
+
onExitFocusGroup: onExitFocusGroup,
|
|
30
|
+
onFocusPrevGroup: onFocusPrevGroup
|
|
31
|
+
}, options), {}, {
|
|
32
|
+
children: /*#__PURE__*/jsx(WrappedComponent, _objectSpread(_objectSpread({}, props), options))
|
|
33
|
+
}));
|
|
34
|
+
};
|
|
19
35
|
}
|
|
20
|
-
|
|
21
|
-
export {
|
|
22
|
-
FocusGroupHoc,
|
|
23
|
-
focusGroupManagerHoc_default as default
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=focusGroupManagerHoc.js.map
|
|
36
|
+
|
|
37
|
+
export { FocusGroupHoc as default };
|
package/esm/FocusGroup/index.js
CHANGED
|
@@ -1,18 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import { FocusGridProvider, FocusGridContext } from "./FocusGrid";
|
|
8
|
-
export {
|
|
9
|
-
FocusGridProvider as FocusGrid,
|
|
10
|
-
FocusGridContext,
|
|
11
|
-
FocusGroup,
|
|
12
|
-
FocusGroupContext,
|
|
13
|
-
FocusGroupManager,
|
|
14
|
-
FocusGroupHoc as focusGroupManagerHoc,
|
|
15
|
-
useFocusGroupItem,
|
|
16
|
-
useFocusGroupWithState
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { default as FocusGroup } from './FocusGroup.js';
|
|
2
|
+
export { default as FocusGroupContext } from './FocusGroupContext.js';
|
|
3
|
+
export { default as FocusGroupManager } from './FocusGroupManager.js';
|
|
4
|
+
export { default as useFocusGroupItem, useFocusGroupWithState } from './useFocusGroupItem.js';
|
|
5
|
+
export { default as focusGroupManagerHoc } from './focusGroupManagerHoc.js';
|
|
6
|
+
export { default as FocusGrid, FocusGridContext } from './FocusGrid.js';
|
|
@@ -1,38 +1,50 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useContext, useEffect } from
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
|
|
2
|
+
import { useContext, useEffect } from 'react';
|
|
3
|
+
import FocusGroupContext from './FocusGroupContext.js';
|
|
4
|
+
|
|
5
|
+
const _excluded = ["register", "unregister"],
|
|
6
|
+
_excluded2 = ["register", "unregister"];
|
|
7
|
+
function useFocusGroupItem() {
|
|
8
|
+
let ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
9
|
+
let props = arguments.length > 1 ? arguments[1] : undefined;
|
|
10
|
+
|
|
11
|
+
const _ref = useContext(FocusGroupContext) || {},
|
|
12
|
+
{
|
|
13
|
+
register,
|
|
14
|
+
unregister
|
|
15
|
+
} = _ref,
|
|
16
|
+
otherActions = _objectWithoutProperties(_ref, _excluded);
|
|
17
|
+
|
|
6
18
|
useEffect(() => {
|
|
7
|
-
if (ref.current && register)
|
|
8
|
-
register(ref.current, props);
|
|
19
|
+
if (ref.current && register) register(ref.current, props);
|
|
9
20
|
return () => {
|
|
10
|
-
if (ref.current && unregister)
|
|
11
|
-
unregister(ref.current);
|
|
21
|
+
if (ref.current && unregister) unregister(ref.current);
|
|
12
22
|
};
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
|
|
23
|
+
}); // if the focus item is not wrapped with the focus provider then return null
|
|
24
|
+
|
|
25
|
+
if (!register) return {};
|
|
16
26
|
return otherActions;
|
|
17
27
|
}
|
|
18
|
-
const useFocusGroupWithState = (
|
|
19
|
-
|
|
28
|
+
const useFocusGroupWithState = function () {
|
|
29
|
+
let ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
30
|
+
let props = arguments.length > 1 ? arguments[1] : undefined;
|
|
31
|
+
|
|
32
|
+
const _ref2 = useContext(FocusGroupContext) || {},
|
|
33
|
+
{
|
|
34
|
+
register,
|
|
35
|
+
unregister
|
|
36
|
+
} = _ref2,
|
|
37
|
+
otherActions = _objectWithoutProperties(_ref2, _excluded2);
|
|
38
|
+
|
|
20
39
|
useEffect(() => {
|
|
21
|
-
if (ref && register)
|
|
22
|
-
register(ref, props);
|
|
40
|
+
if (ref && register) register(ref, props);
|
|
23
41
|
return () => {
|
|
24
|
-
if (ref && unregister)
|
|
25
|
-
unregister(ref);
|
|
42
|
+
if (ref && unregister) unregister(ref);
|
|
26
43
|
};
|
|
27
|
-
}, [ref]);
|
|
28
|
-
|
|
29
|
-
|
|
44
|
+
}, [ref]); // if the focus item is not wrapped with the focus provider then return null
|
|
45
|
+
|
|
46
|
+
if (!register) return {};
|
|
30
47
|
return otherActions;
|
|
31
48
|
};
|
|
32
|
-
|
|
33
|
-
export {
|
|
34
|
-
useFocusGroupItem_default as default,
|
|
35
|
-
useFocusGroupItem,
|
|
36
|
-
useFocusGroupWithState
|
|
37
|
-
};
|
|
38
|
-
//# sourceMappingURL=useFocusGroupItem.js.map
|
|
49
|
+
|
|
50
|
+
export { useFocusGroupItem as default, useFocusGroupWithState };
|