@elliemae/ds-shared 2.2.1 → 2.3.0-alpha.4
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 +55 -35
- package/cjs/Animations/BaseAnimation.js.map +7 -0
- package/cjs/Animations/Grow.js +54 -41
- package/cjs/Animations/Grow.js.map +7 -0
- package/cjs/Animations/GrowRight.js +63 -41
- package/cjs/Animations/GrowRight.js.map +7 -0
- package/cjs/Animations/GrowVertical.js +47 -7
- package/cjs/Animations/GrowVertical.js.map +7 -0
- package/cjs/CheckableGroup.js +67 -65
- package/cjs/CheckableGroup.js.map +7 -0
- package/cjs/DeferRenderAfterComputation.js +48 -24
- package/cjs/DeferRenderAfterComputation.js.map +7 -0
- package/cjs/FocusGroup/FocusGrid.js +108 -143
- package/cjs/FocusGroup/FocusGrid.js.map +7 -0
- package/cjs/FocusGroup/FocusGroup.js +88 -147
- package/cjs/FocusGroup/FocusGroup.js.map +7 -0
- package/cjs/FocusGroup/FocusGroupContext.js +38 -11
- package/cjs/FocusGroup/FocusGroupContext.js.map +7 -0
- package/cjs/FocusGroup/FocusGroupManager.js +56 -47
- package/cjs/FocusGroup/FocusGroupManager.js.map +7 -0
- package/cjs/FocusGroup/focusGroupManagerHoc.js +52 -42
- package/cjs/FocusGroup/focusGroupManagerHoc.js.map +7 -0
- package/cjs/FocusGroup/index.js +47 -21
- package/cjs/FocusGroup/index.js.map +7 -0
- package/cjs/FocusGroup/useFocusGroupItem.js +59 -51
- package/cjs/FocusGroup/useFocusGroupItem.js.map +7 -0
- package/cjs/FocusGroup/utils/getNextCellPosition.js +47 -27
- package/cjs/FocusGroup/utils/getNextCellPosition.js.map +7 -0
- package/cjs/GroupContext/Group.js +64 -73
- package/cjs/GroupContext/Group.js.map +7 -0
- package/cjs/GroupContext/GroupContext.js +36 -13
- package/cjs/GroupContext/GroupContext.js.map +7 -0
- package/cjs/GroupContext/GroupItem.js +39 -21
- package/cjs/GroupContext/GroupItem.js.map +7 -0
- package/cjs/GroupContext/index.js +39 -13
- package/cjs/GroupContext/index.js.map +7 -0
- package/cjs/ScrollSync/ScrollSync.js +60 -75
- package/cjs/ScrollSync/ScrollSync.js.map +7 -0
- package/cjs/ScrollSync/ScrollSyncPane.js +52 -60
- package/cjs/ScrollSync/ScrollSyncPane.js.map +7 -0
- package/cjs/ScrollSync/ScrollSyncProvider.js +103 -50
- package/cjs/ScrollSync/ScrollSyncProvider.js.map +7 -0
- package/cjs/ScrollSync/index.js +37 -11
- package/cjs/ScrollSync/index.js.map +7 -0
- package/cjs/ScrollSync/useScrollSync.js +38 -7
- package/cjs/ScrollSync/useScrollSync.js.map +7 -0
- package/cjs/constants.js +65 -46
- package/cjs/constants.js.map +7 -0
- package/cjs/createDataInstance/createInstancePlugin.js +41 -29
- package/cjs/createDataInstance/createInstancePlugin.js.map +7 -0
- package/cjs/createDataInstance/createInstanceRef.js +66 -71
- package/cjs/createDataInstance/createInstanceRef.js.map +7 -0
- package/cjs/createDataInstance/utils.js +76 -100
- package/cjs/createDataInstance/utils.js.map +7 -0
- package/cjs/defer-render-hoc/index.js +48 -41
- package/cjs/defer-render-hoc/index.js.map +7 -0
- package/cjs/dimsum.config.js +38 -6
- package/cjs/dimsum.config.js.map +7 -0
- package/cjs/index.js +40 -17
- package/cjs/index.js.map +7 -0
- package/cjs/prop-types.js +106 -49
- package/cjs/prop-types.js.map +7 -0
- package/cjs/react-spring/index.js +28 -14
- package/cjs/react-spring/index.js.map +7 -0
- package/cjs/react-spring/renderprops.js +28 -14
- package/cjs/react-spring/renderprops.js.map +7 -0
- package/cjs/toolbar/ToolbarProvider.js +82 -94
- package/cjs/toolbar/ToolbarProvider.js.map +7 -0
- package/cjs/useDataGrid/VolatileRowsListener.js +38 -13
- package/cjs/useDataGrid/VolatileRowsListener.js.map +7 -0
- package/cjs/useDataGrid/index.js +36 -7
- package/cjs/useDataGrid/index.js.map +7 -0
- package/cjs/useDataGrid/initColumnDefinition.js +105 -110
- package/cjs/useDataGrid/initColumnDefinition.js.map +7 -0
- package/cjs/useDataGrid/useDataGrid.js +122 -148
- package/cjs/useDataGrid/useDataGrid.js.map +7 -0
- package/cjs/useDataList/index.js +36 -7
- package/cjs/useDataList/index.js.map +7 -0
- package/cjs/useDataList/recordIterator.js +42 -18
- package/cjs/useDataList/recordIterator.js.map +7 -0
- package/cjs/useDataList/useDataList.js +74 -83
- package/cjs/useDataList/useDataList.js.map +7 -0
- package/cjs/utils.js +71 -80
- package/cjs/utils.js.map +7 -0
- package/cjs/virtualization/AutoHeightList.js +62 -54
- package/cjs/virtualization/AutoHeightList.js.map +7 -0
- package/cjs/virtualization/FluidHeightList.js +42 -48
- package/cjs/virtualization/FluidHeightList.js.map +7 -0
- package/cjs/virtualization/index.js +48 -20
- package/cjs/virtualization/index.js.map +7 -0
- package/esm/Animations/BaseAnimation.js +26 -29
- package/esm/Animations/BaseAnimation.js.map +7 -0
- package/esm/Animations/Grow.js +25 -35
- package/esm/Animations/Grow.js.map +7 -0
- package/esm/Animations/GrowRight.js +34 -35
- package/esm/Animations/GrowRight.js.map +7 -0
- package/esm/Animations/GrowVertical.js +29 -4
- package/esm/Animations/GrowVertical.js.map +7 -0
- package/esm/CheckableGroup.js +35 -52
- package/esm/CheckableGroup.js.map +7 -0
- package/esm/DeferRenderAfterComputation.js +16 -15
- package/esm/DeferRenderAfterComputation.js.map +7 -0
- package/esm/FocusGroup/FocusGrid.js +64 -117
- package/esm/FocusGroup/FocusGrid.js.map +7 -0
- package/esm/FocusGroup/FocusGroup.js +56 -137
- package/esm/FocusGroup/FocusGroup.js.map +7 -0
- package/esm/FocusGroup/FocusGroupContext.js +9 -5
- package/esm/FocusGroup/FocusGroupContext.js.map +7 -0
- package/esm/FocusGroup/FocusGroupManager.js +24 -38
- package/esm/FocusGroup/FocusGroupManager.js.map +7 -0
- package/esm/FocusGroup/focusGroupManagerHoc.js +24 -36
- package/esm/FocusGroup/focusGroupManagerHoc.js.map +7 -0
- package/esm/FocusGroup/index.js +18 -6
- package/esm/FocusGroup/index.js.map +7 -0
- package/esm/FocusGroup/useFocusGroupItem.js +28 -40
- package/esm/FocusGroup/useFocusGroupItem.js.map +7 -0
- package/esm/FocusGroup/utils/getNextCellPosition.js +18 -25
- package/esm/FocusGroup/utils/getNextCellPosition.js.map +7 -0
- package/esm/GroupContext/Group.js +34 -66
- package/esm/GroupContext/Group.js.map +7 -0
- package/esm/GroupContext/GroupContext.js +7 -5
- package/esm/GroupContext/GroupContext.js.map +7 -0
- package/esm/GroupContext/GroupItem.js +10 -15
- package/esm/GroupContext/GroupItem.js.map +7 -0
- package/esm/GroupContext/index.js +10 -3
- package/esm/GroupContext/index.js.map +7 -0
- package/esm/ScrollSync/ScrollSync.js +30 -64
- package/esm/ScrollSync/ScrollSync.js.map +7 -0
- package/esm/ScrollSync/ScrollSyncPane.js +22 -52
- package/esm/ScrollSync/ScrollSyncPane.js.map +7 -0
- package/esm/ScrollSync/ScrollSyncProvider.js +74 -42
- package/esm/ScrollSync/ScrollSyncProvider.js.map +7 -0
- package/esm/ScrollSync/index.js +8 -2
- package/esm/ScrollSync/index.js.map +7 -0
- package/esm/ScrollSync/useScrollSync.js +9 -5
- package/esm/ScrollSync/useScrollSync.js.map +7 -0
- package/esm/constants.js +37 -28
- package/esm/constants.js.map +7 -0
- package/esm/createDataInstance/createInstancePlugin.js +12 -23
- package/esm/createDataInstance/createInstancePlugin.js.map +7 -0
- package/esm/createDataInstance/createInstanceRef.js +36 -59
- package/esm/createDataInstance/createInstanceRef.js.map +7 -0
- package/esm/createDataInstance/utils.js +48 -85
- package/esm/createDataInstance/utils.js.map +7 -0
- package/esm/defer-render-hoc/index.js +17 -31
- package/esm/defer-render-hoc/index.js.map +7 -0
- package/esm/dimsum.config.js +9 -4
- package/esm/dimsum.config.js.map +7 -0
- package/esm/index.js +11 -5
- package/esm/index.js.map +7 -0
- package/esm/prop-types.js +75 -31
- package/esm/prop-types.js.map +7 -0
- package/esm/react-spring/index.js +3 -1
- package/esm/react-spring/index.js.map +7 -0
- package/esm/react-spring/renderprops.js +3 -1
- package/esm/react-spring/renderprops.js.map +7 -0
- package/esm/toolbar/ToolbarProvider.js +45 -74
- package/esm/toolbar/ToolbarProvider.js.map +7 -0
- package/esm/useDataGrid/VolatileRowsListener.js +9 -11
- package/esm/useDataGrid/VolatileRowsListener.js.map +7 -0
- package/esm/useDataGrid/index.js +7 -1
- package/esm/useDataGrid/index.js.map +7 -0
- package/esm/useDataGrid/initColumnDefinition.js +78 -94
- package/esm/useDataGrid/initColumnDefinition.js.map +7 -0
- package/esm/useDataGrid/useDataGrid.js +82 -99
- package/esm/useDataGrid/useDataGrid.js.map +7 -0
- package/esm/useDataList/index.js +7 -1
- package/esm/useDataList/index.js.map +7 -0
- package/esm/useDataList/recordIterator.js +13 -14
- package/esm/useDataList/recordIterator.js.map +7 -0
- package/esm/useDataList/useDataList.js +44 -67
- package/esm/useDataList/useDataList.js.map +7 -0
- package/esm/utils.js +42 -59
- package/esm/utils.js.map +7 -0
- package/esm/virtualization/AutoHeightList.js +28 -40
- package/esm/virtualization/AutoHeightList.js.map +7 -0
- package/esm/virtualization/FluidHeightList.js +14 -38
- package/esm/virtualization/FluidHeightList.js.map +7 -0
- package/esm/virtualization/index.js +19 -16
- package/esm/virtualization/index.js.map +7 -0
- package/package.json +3 -3
- package/types/Animations/BaseAnimation.d.ts +1 -0
- package/types/Animations/Grow.d.ts +1 -0
- package/types/Animations/GrowRight.d.ts +1 -0
- package/types/CheckableGroup.d.ts +1 -0
- package/types/DeferRenderAfterComputation.d.ts +3 -2
- package/types/FocusGroup/FocusGrid.d.ts +5 -3
- package/types/FocusGroup/FocusGroup.d.ts +3 -1
- package/types/FocusGroup/FocusGroupContext.d.ts +3 -2
- package/types/FocusGroup/FocusGroupManager.d.ts +3 -1
- package/types/FocusGroup/focusGroupManagerHoc.d.ts +3 -1
- package/types/FocusGroup/index.d.ts +6 -6
- package/types/FocusGroup/useFocusGroupItem.d.ts +3 -1
- package/types/FocusGroup/utils/getNextCellPosition.d.ts +3 -1
- package/types/GroupContext/Group.d.ts +1 -0
- package/types/GroupContext/GroupItem.d.ts +1 -0
- package/types/GroupContext/index.d.ts +3 -3
- package/types/ScrollSync/ScrollSync.d.ts +4 -2
- package/types/ScrollSync/ScrollSyncPane.d.ts +2 -2
- package/types/ScrollSync/index.d.ts +2 -2
- package/types/ScrollSync/useScrollSync.d.ts +6 -5
- package/types/createDataInstance/createInstancePlugin.d.ts +2 -1
- package/types/createDataInstance/createInstanceRef.d.ts +3 -1
- package/types/dimsum.config.d.ts +3 -2
- package/types/index.d.ts +2 -2
- package/types/toolbar/ToolbarProvider.d.ts +3 -8
- package/types/useDataGrid/VolatileRowsListener.d.ts +3 -1
- package/types/useDataGrid/index.d.ts +1 -1
- package/types/useDataGrid/initColumnDefinition.d.ts +2 -1
- package/types/useDataGrid/useDataGrid.d.ts +3 -2
- package/types/useDataList/index.d.ts +1 -1
- package/types/useDataList/useDataList.d.ts +3 -2
|
@@ -1,61 +1,49 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
function useDataGrid(_ref) {
|
|
32
|
-
let {
|
|
33
|
-
uuid: uuidProp,
|
|
34
|
-
plugins: pluginsFromProps,
|
|
35
|
-
rows,
|
|
36
|
-
columns,
|
|
37
|
-
renderers = {}
|
|
38
|
-
} = _ref,
|
|
39
|
-
props = _objectWithoutProperties(_ref, _excluded);
|
|
40
|
-
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import {
|
|
3
|
+
cloneDeep,
|
|
4
|
+
compose,
|
|
5
|
+
isEqual,
|
|
6
|
+
isObject,
|
|
7
|
+
setRef,
|
|
8
|
+
usePrevious,
|
|
9
|
+
useDerivedStateFromProps
|
|
10
|
+
} from "@elliemae/ds-utilities";
|
|
11
|
+
import { useMemo, useRef, useState } from "react";
|
|
12
|
+
import { v4 as uuidv4 } from "uuid";
|
|
13
|
+
import * as resolve from "table-resolver";
|
|
14
|
+
import { initColumnDefinition } from "./initColumnDefinition";
|
|
15
|
+
import {
|
|
16
|
+
applyDecorators,
|
|
17
|
+
decorateColumns,
|
|
18
|
+
reducePropsGetter
|
|
19
|
+
} from "../createDataInstance/utils";
|
|
20
|
+
import { VolatileRowsListener } from "./VolatileRowsListener";
|
|
21
|
+
import { isInternetExplorer } from "../utils";
|
|
22
|
+
const IS_INTERNET_EXPLORER = isInternetExplorer();
|
|
23
|
+
const useDataGrid = ({
|
|
24
|
+
uuid: uuidProp,
|
|
25
|
+
plugins: pluginsFromProps,
|
|
26
|
+
rows,
|
|
27
|
+
columns,
|
|
28
|
+
renderers = {},
|
|
29
|
+
...props
|
|
30
|
+
}) => {
|
|
41
31
|
const plugins = pluginsFromProps;
|
|
42
32
|
const instance = useRef();
|
|
43
33
|
const tableRef = useRef();
|
|
44
34
|
const headerRef = useRef();
|
|
45
35
|
const bodyRef = useRef();
|
|
46
36
|
const bodyInnerRef = useRef();
|
|
47
|
-
const [uuid] = useState(uuidProp || (() =>
|
|
37
|
+
const [uuid] = useState(uuidProp || (() => uuidv4()));
|
|
48
38
|
const [hasScroll, setHasScroll] = useState(false);
|
|
49
39
|
const [isRowDragging, setIsRowDragging] = useState(false);
|
|
50
40
|
const isScrolling = useRef();
|
|
51
|
-
const shouldRefocus = useRef();
|
|
52
|
-
|
|
53
|
-
const [RowsObserver] = useState(() => new VolatileRowsListener()); // todo move this with rows composition
|
|
54
|
-
|
|
41
|
+
const shouldRefocus = useRef();
|
|
42
|
+
const [RowsObserver] = useState(() => new VolatileRowsListener());
|
|
55
43
|
const [originalRows, updateRows] = useDerivedStateFromProps(rows, {
|
|
56
44
|
onUpdate: resolve.resolve({
|
|
57
45
|
columns,
|
|
58
|
-
method: extra => compose(resolve.byFunction(
|
|
46
|
+
method: (extra) => compose(resolve.byFunction("valueTransformation")(extra), resolve.nested(extra))
|
|
59
47
|
}),
|
|
60
48
|
updateOnStateChange: true
|
|
61
49
|
});
|
|
@@ -85,11 +73,9 @@ function useDataGrid(_ref) {
|
|
|
85
73
|
updateRows
|
|
86
74
|
},
|
|
87
75
|
updateRows,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
disableEvents: () => document.body.style.pointerEvents = 'none',
|
|
92
|
-
observeRows: observer => RowsObserver.observe(observer),
|
|
76
|
+
enableEvents: () => document.body.style.pointerEvents = IS_INTERNET_EXPLORER ? "" : null,
|
|
77
|
+
disableEvents: () => document.body.style.pointerEvents = "none",
|
|
78
|
+
observeRows: (observer) => RowsObserver.observe(observer),
|
|
93
79
|
hotKeys: {},
|
|
94
80
|
shouldRefocus,
|
|
95
81
|
isScrolling,
|
|
@@ -98,21 +84,20 @@ function useDataGrid(_ref) {
|
|
|
98
84
|
isRowDragging,
|
|
99
85
|
plugins
|
|
100
86
|
};
|
|
101
|
-
|
|
102
87
|
instance.current.getState = () => instance.current.state;
|
|
103
|
-
|
|
104
88
|
instance.current.getInstance = () => instance.current;
|
|
105
|
-
|
|
106
89
|
const defaultDecorators = {
|
|
107
90
|
decorateGrid: [],
|
|
108
91
|
registerStateHook: [],
|
|
109
92
|
registerHotKeys: [],
|
|
110
93
|
decorateColumn: [],
|
|
111
|
-
decorateColumns: [
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
94
|
+
decorateColumns: [
|
|
95
|
+
(cols) => cols.map((col) => initColumnDefinition({
|
|
96
|
+
useTextTruncation: col.useTextTruncation,
|
|
97
|
+
wrapText: props.wrapText,
|
|
98
|
+
normalize: props.normalizeDataKeys
|
|
99
|
+
})(col))
|
|
100
|
+
],
|
|
116
101
|
decorateRenderers: [],
|
|
117
102
|
getRowProps: [],
|
|
118
103
|
getHeaderRowProps: [],
|
|
@@ -122,51 +107,45 @@ function useDataGrid(_ref) {
|
|
|
122
107
|
composeRows: []
|
|
123
108
|
};
|
|
124
109
|
const decorators = useMemo(() => {
|
|
125
|
-
let nextDecorators = defaultDecorators;
|
|
126
|
-
|
|
127
|
-
plugins.forEach(plugin => nextDecorators = plugin(nextDecorators));
|
|
110
|
+
let nextDecorators = defaultDecorators;
|
|
111
|
+
plugins.forEach((plugin) => nextDecorators = plugin(nextDecorators));
|
|
128
112
|
return nextDecorators;
|
|
129
113
|
}, [plugins]);
|
|
130
|
-
instance.current = decorators.decorateGrid.reduce((nextInstance, decorator) =>
|
|
114
|
+
instance.current = decorators.decorateGrid.reduce((nextInstance, decorator) => ({
|
|
115
|
+
...nextInstance,
|
|
116
|
+
...decorator(instance.current)
|
|
117
|
+
}), instance.current);
|
|
131
118
|
instance.current = decorators.registerStateHook.reduce((nextInstance, decorator) => {
|
|
132
|
-
const {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
119
|
+
const { state, actions } = decorator(instance.current);
|
|
120
|
+
return {
|
|
121
|
+
...nextInstance,
|
|
122
|
+
state: {
|
|
123
|
+
...nextInstance.state,
|
|
124
|
+
...state
|
|
125
|
+
},
|
|
126
|
+
actions: {
|
|
127
|
+
...nextInstance.actions,
|
|
128
|
+
...actions
|
|
129
|
+
}
|
|
130
|
+
};
|
|
140
131
|
}, instance.current);
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
handler,
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return _objectSpread(_objectSpread({}, nextInstance), {}, {
|
|
149
|
-
hotKeys: _objectSpread(_objectSpread({}, nextInstance.hotKeys), {}, {
|
|
150
|
-
[key]: {
|
|
151
|
-
handler,
|
|
152
|
-
options
|
|
153
|
-
}
|
|
154
|
-
})
|
|
155
|
-
});
|
|
156
|
-
};
|
|
157
|
-
|
|
132
|
+
const reduceHotKey = (nextInstance, { key, handler, options }) => ({
|
|
133
|
+
...nextInstance,
|
|
134
|
+
hotKeys: {
|
|
135
|
+
...nextInstance.hotKeys,
|
|
136
|
+
[key]: { handler, options }
|
|
137
|
+
}
|
|
138
|
+
});
|
|
158
139
|
instance.current = decorators.registerHotKeys.reduce((nextInstance, decorator) => {
|
|
159
140
|
const hotKeys = decorator(nextInstance);
|
|
160
|
-
|
|
161
141
|
if (Array.isArray(hotKeys)) {
|
|
162
142
|
return hotKeys.reduce(reduceHotKey, nextInstance);
|
|
163
143
|
}
|
|
164
|
-
|
|
165
144
|
return reduceHotKey(nextInstance, hotKeys);
|
|
166
145
|
}, instance.current);
|
|
167
146
|
instance.current.decoratedRenderers = applyDecorators(instance.current.decoratedRenderers, decorators.decorateRenderers, instance.current);
|
|
168
147
|
instance.current.decoratedColumns = useMemo(() => {
|
|
169
|
-
const visibleColumns = cloneDeep(columns).filter(column => typeof column.visible ===
|
|
148
|
+
const visibleColumns = cloneDeep(columns).filter((column) => typeof column.visible === "undefined" || column.visible);
|
|
170
149
|
return visibleColumns.length ? decorateColumns(visibleColumns, decorators, instance.current) : [];
|
|
171
150
|
}, [columns]);
|
|
172
151
|
instance.current.getBodyProps = reducePropsGetter(decorators.getBodyProps, instance.current);
|
|
@@ -178,17 +157,21 @@ function useDataGrid(_ref) {
|
|
|
178
157
|
RowsObserver.notify(instance.current.composedRows);
|
|
179
158
|
const currentShouldRefocus = instance.current.shouldRefocus.current;
|
|
180
159
|
const prevState = usePrevious(instance.current.state);
|
|
181
|
-
|
|
182
160
|
if (isObject(currentShouldRefocus) && currentShouldRefocus.forced) {
|
|
183
161
|
instance.current.shouldRefocus.current = currentShouldRefocus.value;
|
|
184
162
|
} else {
|
|
185
163
|
instance.current.shouldRefocus.current = !isEqual(prevState, instance.current.state);
|
|
186
164
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
return
|
|
165
|
+
if (props.instanceRef)
|
|
166
|
+
setRef(props.instanceRef, instance.current);
|
|
167
|
+
return {
|
|
168
|
+
...instance.current,
|
|
190
169
|
decorators
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
export {
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
var useDataGrid_default = useDataGrid;
|
|
173
|
+
export {
|
|
174
|
+
useDataGrid_default as default,
|
|
175
|
+
useDataGrid
|
|
176
|
+
};
|
|
177
|
+
//# sourceMappingURL=useDataGrid.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/useDataGrid/useDataGrid.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-lines */\nimport {\n cloneDeep,\n compose,\n isEqual,\n isObject,\n setRef, \n usePrevious, \n useDerivedStateFromProps \n} from '@elliemae/ds-utilities';\nimport { useMemo, useRef, useState } from 'react';\nimport { v4 as uuidv4 } from 'uuid';\nimport * as resolve from 'table-resolver';\nimport { initColumnDefinition } from './initColumnDefinition';\nimport {\n applyDecorators,\n decorateColumns,\n reducePropsGetter,\n} from '../createDataInstance/utils';\nimport { VolatileRowsListener } from './VolatileRowsListener';\nimport { isInternetExplorer } from '../utils';\n\nconst IS_INTERNET_EXPLORER = isInternetExplorer();\n\n// TODO: Reuse createDataInstance for the grid the same\n// way as the list does ex: packages/ds-shared/src/useDataList/useDataList.js\n// eslint-disable-next-line max-statements\nexport const useDataGrid = ({\n uuid: uuidProp,\n plugins: pluginsFromProps,\n rows,\n columns,\n renderers = {},\n ...props\n}) => {\n const plugins = pluginsFromProps;\n const instance = useRef();\n const tableRef = useRef();\n const headerRef = useRef();\n const bodyRef = useRef();\n const bodyInnerRef = useRef();\n const [uuid] = useState(uuidProp || (() => uuidv4()));\n const [hasScroll, setHasScroll] = useState(false);\n const [isRowDragging, setIsRowDragging] = useState(false);\n const isScrolling = useRef();\n const shouldRefocus = useRef(); // todo: we probably need a plugin for focus related stuff\n const [RowsObserver] = useState(() => new VolatileRowsListener());\n\n // todo move this with rows composition\n const [originalRows, updateRows] = useDerivedStateFromProps(rows, {\n onUpdate: resolve.resolve({\n columns,\n method: (extra) =>\n compose(\n resolve.byFunction('valueTransformation')(extra),\n resolve.nested(extra),\n ),\n }),\n updateOnStateChange: true,\n });\n\n instance.current = {\n decoratedRenderers: cloneDeep(renderers),\n decoratedColumns: columns,\n columns,\n rows,\n composedRows: originalRows,\n getRowProps: [],\n getHeaderRowProps: [],\n getBodyProps: [],\n getTableProps: [],\n effects: [],\n uuid,\n props,\n refs: {\n table: tableRef,\n body: bodyRef,\n header: headerRef,\n innerBody: bodyInnerRef,\n },\n state: {\n hasScroll,\n },\n actions: {\n updateRows,\n },\n updateRows,\n // eslint-disable-next-line no-return-assign\n enableEvents: () =>\n (document.body.style.pointerEvents = IS_INTERNET_EXPLORER ? '' : null),\n // eslint-disable-next-line no-return-assign\n disableEvents: () => (document.body.style.pointerEvents = 'none'),\n observeRows: (observer) => RowsObserver.observe(observer),\n hotKeys: {},\n shouldRefocus,\n isScrolling,\n setHasScroll,\n setIsRowDragging,\n isRowDragging,\n plugins,\n };\n instance.current.getState = () => instance.current.state;\n instance.current.getInstance = () => instance.current;\n\n const defaultDecorators = {\n decorateGrid: [],\n registerStateHook: [],\n registerHotKeys: [],\n decorateColumn: [],\n decorateColumns: [\n (cols) =>\n cols.map((col) =>\n initColumnDefinition({\n useTextTruncation: col.useTextTruncation,\n wrapText: props.wrapText,\n normalize: props.normalizeDataKeys,\n })(col),\n ),\n ],\n decorateRenderers: [],\n getRowProps: [],\n getHeaderRowProps: [],\n getBodyProps: [],\n getTableProps: [],\n getHeaderProps: [],\n composeRows: [],\n };\n\n const decorators = useMemo(() => {\n let nextDecorators = defaultDecorators;\n // eslint-disable-next-line no-return-assign\n plugins.forEach((plugin) => (nextDecorators = plugin(nextDecorators)));\n return nextDecorators;\n }, [plugins]);\n\n instance.current = decorators.decorateGrid.reduce(\n (nextInstance, decorator) => ({\n ...nextInstance,\n ...decorator(instance.current),\n }),\n instance.current,\n );\n\n instance.current = decorators.registerStateHook.reduce(\n (nextInstance, decorator) => {\n const { state, actions } = decorator(instance.current);\n return {\n ...nextInstance,\n state: {\n ...nextInstance.state,\n ...state,\n },\n actions: {\n ...nextInstance.actions,\n ...actions,\n },\n };\n },\n instance.current,\n );\n\n const reduceHotKey = (nextInstance, { key, handler, options }) => ({\n ...nextInstance,\n hotKeys: {\n ...nextInstance.hotKeys,\n [key]: { handler, options },\n },\n });\n instance.current = decorators.registerHotKeys.reduce(\n (nextInstance, decorator) => {\n const hotKeys = decorator(nextInstance);\n if (Array.isArray(hotKeys)) {\n return hotKeys.reduce(reduceHotKey, nextInstance);\n }\n return reduceHotKey(nextInstance, hotKeys);\n },\n instance.current,\n );\n\n instance.current.decoratedRenderers = applyDecorators(\n instance.current.decoratedRenderers,\n decorators.decorateRenderers,\n instance.current,\n );\n\n instance.current.decoratedColumns = useMemo(() => {\n const visibleColumns = cloneDeep(columns).filter(\n (column) => typeof column.visible === 'undefined' || column.visible,\n );\n return visibleColumns.length\n ? decorateColumns(visibleColumns, decorators, instance.current)\n : [];\n }, [columns]);\n\n instance.current.getBodyProps = reducePropsGetter(\n decorators.getBodyProps,\n instance.current,\n );\n instance.current.getHeaderProps = reducePropsGetter(\n decorators.getHeaderProps,\n instance.current,\n );\n instance.current.getRowProps = reducePropsGetter(\n decorators.getRowProps,\n instance.current,\n );\n instance.current.getHeaderRowProps = reducePropsGetter(\n decorators.getHeaderRowProps,\n instance.current,\n );\n instance.current.getTableProps = reducePropsGetter(\n decorators.getTableProps,\n instance.current,\n );\n\n instance.current.composedRows = decorators.composeRows.reduce(\n (nextRows, getter) => getter(nextRows, instance.current),\n instance.current.composedRows,\n );\n\n RowsObserver.notify(instance.current.composedRows);\n\n const currentShouldRefocus = instance.current.shouldRefocus.current;\n const prevState = usePrevious(instance.current.state);\n if (isObject(currentShouldRefocus) && currentShouldRefocus.forced) {\n instance.current.shouldRefocus.current = currentShouldRefocus.value;\n } else {\n instance.current.shouldRefocus.current = !isEqual(\n prevState,\n instance.current.state,\n );\n }\n\n if (props.instanceRef) setRef(props.instanceRef, instance.current);\n\n return {\n ...instance.current,\n decorators,\n };\n};\n\nexport default useDataGrid;\n\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/esm/useDataList/index.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/useDataList/index.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export { default, default as useDataList } from './useDataList';\n"],
|
|
5
|
+
"mappings": "AAAA;ACAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,27 +1,26 @@
|
|
|
1
|
+
import * as React from "react";
|
|
1
2
|
const defaultStrategy = () => {
|
|
2
|
-
throw Error(
|
|
3
|
+
throw Error("Implement an iterator strategy for record iterator");
|
|
3
4
|
};
|
|
4
|
-
|
|
5
|
-
function recordIterator(records) {
|
|
6
|
-
let strategy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultStrategy;
|
|
7
|
-
let decorators = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
8
|
-
let instance = arguments.length > 3 ? arguments[3] : undefined;
|
|
5
|
+
function recordIterator(records, strategy = defaultStrategy, decorators = [], instance) {
|
|
9
6
|
const nextRows = [];
|
|
10
7
|
strategy({
|
|
11
8
|
data: records,
|
|
12
|
-
cb: row => {
|
|
13
|
-
let nextRow = row;
|
|
14
|
-
|
|
9
|
+
cb: (row) => {
|
|
10
|
+
let nextRow = row;
|
|
15
11
|
for (let i = 0; i < decorators.length; i++) {
|
|
16
12
|
nextRow = decorators[i](nextRow, instance);
|
|
17
|
-
if (!nextRow)
|
|
13
|
+
if (!nextRow)
|
|
14
|
+
break;
|
|
18
15
|
}
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
if (nextRow)
|
|
17
|
+
nextRows.push(nextRow);
|
|
21
18
|
},
|
|
22
19
|
instance
|
|
23
20
|
});
|
|
24
21
|
return nextRows;
|
|
25
22
|
}
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
export {
|
|
24
|
+
recordIterator
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=recordIterator.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/useDataList/recordIterator.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "const defaultStrategy = () => {\n throw Error('Implement an iterator strategy for record iterator');\n};\n\nexport function recordIterator(\n records,\n strategy = defaultStrategy,\n decorators = [],\n instance,\n) {\n const nextRows = [];\n\n strategy({\n data: records,\n cb: row => {\n let nextRow = row;\n\n // eslint-disable-next-line no-loops/no-loops,no-plusplus\n for (let i = 0; i < decorators.length; i++) {\n nextRow = decorators[i](nextRow, instance);\n if (!nextRow) break;\n }\n\n if (nextRow) nextRows.push(nextRow);\n },\n instance,\n });\n\n return nextRows;\n}\n"],
|
|
5
|
+
"mappings": "AAAA;ACAA,MAAM,kBAAkB,MAAM;AAC5B,QAAM,MAAM;AAAA;AAGP,wBACL,SACA,WAAW,iBACX,aAAa,IACb,UACA;AACA,QAAM,WAAW;AAEjB,WAAS;AAAA,IACP,MAAM;AAAA,IACN,IAAI,SAAO;AACT,UAAI,UAAU;AAGd,eAAS,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;AAC1C,kBAAU,WAAW,GAAG,SAAS;AACjC,YAAI,CAAC;AAAS;AAAA;AAGhB,UAAI;AAAS,iBAAS,KAAK;AAAA;AAAA,IAE7B;AAAA;AAGF,SAAO;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,90 +1,67 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import get from 'lodash/get';
|
|
14
|
-
import { reducePropsGetter, composeFormatters } from '../createDataInstance/utils.js';
|
|
15
|
-
import { recordIterator } from './recordIterator.js';
|
|
16
|
-
import createDataInstanceRef from '../createDataInstance/createInstanceRef.js';
|
|
17
|
-
|
|
18
|
-
const _excluded = ["data", "plugins", "renderers", "itemRenderer", "customDecorators"];
|
|
19
|
-
|
|
20
|
-
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; }
|
|
21
|
-
|
|
22
|
-
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; }
|
|
23
|
-
const getItemLabel = function (record) {
|
|
24
|
-
let nameKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'name';
|
|
25
|
-
return get(record, ['data', nameKey]);
|
|
26
|
-
};
|
|
27
|
-
const getItemChildren = function (record) {
|
|
28
|
-
let childrenKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'children';
|
|
29
|
-
return get(record, ['data', childrenKey]);
|
|
30
|
-
};
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useMemo, useRef } from "react";
|
|
3
|
+
import { setRef } from "@elliemae/ds-utilities";
|
|
4
|
+
import get from "lodash/get";
|
|
5
|
+
import {
|
|
6
|
+
composeFormatters,
|
|
7
|
+
reducePropsGetter
|
|
8
|
+
} from "../createDataInstance/utils";
|
|
9
|
+
import { recordIterator } from "./recordIterator";
|
|
10
|
+
import { createDataInstanceRef } from "../createDataInstance/createInstanceRef";
|
|
11
|
+
const getItemLabel = (record, nameKey = "name") => get(record, ["data", nameKey]);
|
|
12
|
+
const getItemChildren = (record, childrenKey = "children") => get(record, ["data", childrenKey]);
|
|
31
13
|
const listRenderers = {
|
|
32
|
-
list:
|
|
33
|
-
item:
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
} = _ref,
|
|
44
|
-
props = _objectWithoutProperties(_ref, _excluded);
|
|
45
|
-
|
|
14
|
+
list: "ul",
|
|
15
|
+
item: "li"
|
|
16
|
+
};
|
|
17
|
+
const useDataList = ({
|
|
18
|
+
data = [],
|
|
19
|
+
plugins = [],
|
|
20
|
+
renderers = listRenderers,
|
|
21
|
+
itemRenderer = [],
|
|
22
|
+
customDecorators,
|
|
23
|
+
...props
|
|
24
|
+
}) => {
|
|
46
25
|
const listRef = useRef();
|
|
47
|
-
const {
|
|
48
|
-
instance,
|
|
49
|
-
decorators
|
|
50
|
-
} = createDataInstanceRef(_objectSpread({
|
|
26
|
+
const { instance, decorators } = createDataInstanceRef({
|
|
51
27
|
data,
|
|
52
28
|
renderers,
|
|
53
29
|
plugins,
|
|
54
|
-
customDecorators:
|
|
30
|
+
customDecorators: {
|
|
31
|
+
...customDecorators,
|
|
55
32
|
recordIterator,
|
|
56
33
|
getListProps: [],
|
|
57
34
|
getItemProps: [],
|
|
58
35
|
itemRenderer: [...itemRenderer],
|
|
59
|
-
// components reduce to compose item content
|
|
60
36
|
record: [],
|
|
61
37
|
records: []
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
38
|
+
},
|
|
39
|
+
...props
|
|
40
|
+
});
|
|
65
41
|
instance.current.getListRef = () => listRef;
|
|
66
|
-
|
|
67
|
-
instance.current.setListRef = ref => {
|
|
42
|
+
instance.current.setListRef = (ref) => {
|
|
68
43
|
listRef.current = ref;
|
|
69
44
|
};
|
|
70
|
-
|
|
71
|
-
instance.current.
|
|
72
|
-
|
|
73
|
-
instance.current.getItemChildren = record => getItemChildren(record, props.childrenKey);
|
|
74
|
-
|
|
45
|
+
instance.current.getItemLabel = (record) => getItemLabel(record, props.nameKey);
|
|
46
|
+
instance.current.getItemChildren = (record) => getItemChildren(record, props.childrenKey);
|
|
75
47
|
instance.current.decorators = decorators;
|
|
76
48
|
instance.current.getListProps = reducePropsGetter(decorators.getListProps, instance.current);
|
|
77
49
|
instance.current.getItemProps = reducePropsGetter(decorators.getItemProps, instance.current);
|
|
78
50
|
instance.current.itemRenderer = composeFormatters(instance.current.decorators.itemRenderer, instance.current);
|
|
79
51
|
instance.current.records = useMemo(() => {
|
|
80
|
-
|
|
81
|
-
let nextRecords = recordIterator(data, instance.current.decorators.recordIterator, decorators.record, instance.current); // compose all records
|
|
82
|
-
|
|
52
|
+
let nextRecords = recordIterator(data, instance.current.decorators.recordIterator, decorators.record, instance.current);
|
|
83
53
|
nextRecords = decorators.records.reduce((nextRows, getter) => getter(nextRows, instance.current), nextRecords);
|
|
84
54
|
return nextRecords;
|
|
85
55
|
});
|
|
86
|
-
if (props.instanceRef)
|
|
56
|
+
if (props.instanceRef)
|
|
57
|
+
setRef(props.instanceRef, instance.current);
|
|
87
58
|
return instance.current;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export {
|
|
59
|
+
};
|
|
60
|
+
var useDataList_default = useDataList;
|
|
61
|
+
export {
|
|
62
|
+
useDataList_default as default,
|
|
63
|
+
getItemChildren,
|
|
64
|
+
getItemLabel,
|
|
65
|
+
useDataList
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=useDataList.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/useDataList/useDataList.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useMemo, useRef } from 'react';\nimport { setRef } from '@elliemae/ds-utilities';\nimport get from 'lodash/get';\nimport {\n composeFormatters,\n reducePropsGetter,\n} from '../createDataInstance/utils';\nimport { recordIterator } from './recordIterator';\nimport { createDataInstanceRef } from '../createDataInstance/createInstanceRef';\n\nexport const getItemLabel = (record, nameKey = 'name') =>\n get(record, ['data', nameKey]);\nexport const getItemChildren = (record, childrenKey = 'children') =>\n get(record, ['data', childrenKey]);\n\nconst listRenderers = {\n list: 'ul',\n item: 'li',\n};\n\n// todo: check if a plugin is a LIST plugin rather than GRID\nexport const useDataList = ({\n data = [],\n plugins = [],\n renderers = listRenderers,\n itemRenderer = [],\n customDecorators,\n ...props\n}) => {\n const listRef = useRef();\n const { instance, decorators } = createDataInstanceRef({\n data,\n renderers,\n plugins,\n customDecorators: {\n ...customDecorators,\n recordIterator,\n getListProps: [],\n getItemProps: [],\n itemRenderer: [...itemRenderer], // components reduce to compose item content\n record: [],\n records: [],\n },\n ...props,\n });\n instance.current.getListRef = () => listRef;\n instance.current.setListRef = (ref) => {\n listRef.current = ref;\n };\n instance.current.getItemLabel = (record) =>\n getItemLabel(record, props.nameKey);\n instance.current.getItemChildren = (record) =>\n getItemChildren(record, props.childrenKey);\n\n instance.current.decorators = decorators;\n instance.current.getListProps = reducePropsGetter(\n decorators.getListProps,\n instance.current,\n );\n instance.current.getItemProps = reducePropsGetter(\n decorators.getItemProps,\n instance.current,\n );\n instance.current.itemRenderer = composeFormatters(\n instance.current.decorators.itemRenderer,\n instance.current,\n );\n\n instance.current.records = useMemo(() => {\n // record iterator TREE / Simple\n let nextRecords = recordIterator(\n data,\n instance.current.decorators.recordIterator,\n decorators.record,\n instance.current,\n );\n\n // compose all records\n nextRecords = decorators.records.reduce(\n (nextRows, getter) => getter(nextRows, instance.current),\n nextRecords,\n );\n\n return nextRecords;\n });\n\n if (props.instanceRef) setRef(props.instanceRef, instance.current);\n\n return instance.current;\n};\n\nexport default useDataList;\n"],
|
|
5
|
+
"mappings": "AAAA;ACAA;AACA;AACA;AACA;AAAA;AAAA;AAAA;AAIA;AACA;AAEO,MAAM,eAAe,CAAC,QAAQ,UAAU,WAC7C,IAAI,QAAQ,CAAC,QAAQ;AAChB,MAAM,kBAAkB,CAAC,QAAQ,cAAc,eACpD,IAAI,QAAQ,CAAC,QAAQ;AAEvB,MAAM,gBAAgB;AAAA,EACpB,MAAM;AAAA,EACN,MAAM;AAAA;AAID,MAAM,cAAc,CAAC;AAAA,EAC1B,OAAO;AAAA,EACP,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,eAAe;AAAA,EACf;AAAA,KACG;AAAA,MACC;AACJ,QAAM,UAAU;AAChB,QAAM,EAAE,UAAU,eAAe,sBAAsB;AAAA,IACrD;AAAA,IACA;AAAA,IACA;AAAA,IACA,kBAAkB;AAAA,SACb;AAAA,MACH;AAAA,MACA,cAAc;AAAA,MACd,cAAc;AAAA,MACd,cAAc,CAAC,GAAG;AAAA,MAClB,QAAQ;AAAA,MACR,SAAS;AAAA;AAAA,OAER;AAAA;AAEL,WAAS,QAAQ,aAAa,MAAM;AACpC,WAAS,QAAQ,aAAa,CAAC,QAAQ;AACrC,YAAQ,UAAU;AAAA;AAEpB,WAAS,QAAQ,eAAe,CAAC,WAC/B,aAAa,QAAQ,MAAM;AAC7B,WAAS,QAAQ,kBAAkB,CAAC,WAClC,gBAAgB,QAAQ,MAAM;AAEhC,WAAS,QAAQ,aAAa;AAC9B,WAAS,QAAQ,eAAe,kBAC9B,WAAW,cACX,SAAS;AAEX,WAAS,QAAQ,eAAe,kBAC9B,WAAW,cACX,SAAS;AAEX,WAAS,QAAQ,eAAe,kBAC9B,SAAS,QAAQ,WAAW,cAC5B,SAAS;AAGX,WAAS,QAAQ,UAAU,QAAQ,MAAM;AAEvC,QAAI,cAAc,eAChB,MACA,SAAS,QAAQ,WAAW,gBAC5B,WAAW,QACX,SAAS;AAIX,kBAAc,WAAW,QAAQ,OAC/B,CAAC,UAAU,WAAW,OAAO,UAAU,SAAS,UAChD;AAGF,WAAO;AAAA;AAGT,MAAI,MAAM;AAAa,WAAO,MAAM,aAAa,SAAS;AAE1D,SAAO,SAAS;AAAA;AAGlB,IAAO,sBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/esm/utils.js
CHANGED
|
@@ -1,81 +1,51 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
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; }
|
|
11
|
-
|
|
12
|
-
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; }
|
|
13
|
-
|
|
14
|
-
/* eslint-disable no-cond-assign */
|
|
15
|
-
const objectType = obj => Object.prototype.toString.call(obj).slice(8, -1);
|
|
16
|
-
const isDefined = param => typeof param !== 'undefined';
|
|
17
|
-
const isUndefined = param => typeof param === 'undefined';
|
|
18
|
-
const isFunction = param => typeof param === 'function';
|
|
19
|
-
const isNumber = param => typeof param === 'number' && !isNaN(param); // eslint-disable-line
|
|
20
|
-
|
|
21
|
-
const isString = str => objectType(str) === 'String';
|
|
22
|
-
const isArray = arr => objectType(arr) === 'Array';
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
const objectType = (obj) => Object.prototype.toString.call(obj).slice(8, -1);
|
|
3
|
+
const isDefined = (param) => typeof param !== "undefined";
|
|
4
|
+
const isUndefined = (param) => typeof param === "undefined";
|
|
5
|
+
const isFunction = (param) => typeof param === "function";
|
|
6
|
+
const isNumber = (param) => typeof param === "number" && !isNaN(param);
|
|
7
|
+
const isString = (str) => objectType(str) === "String";
|
|
8
|
+
const isArray = (arr) => objectType(arr) === "Array";
|
|
23
9
|
const closest = (target, selector) => {
|
|
24
|
-
// closest(e.target, '.field')
|
|
25
10
|
while (target) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (target.msMatchesSelector && target.msMatchesSelector(selector))
|
|
29
|
-
|
|
11
|
+
if (target.matches && target.matches(selector))
|
|
12
|
+
return target;
|
|
13
|
+
if (target.msMatchesSelector && target.msMatchesSelector(selector))
|
|
14
|
+
return target;
|
|
30
15
|
target = target.parentNode;
|
|
31
16
|
}
|
|
32
|
-
|
|
33
17
|
return null;
|
|
34
18
|
};
|
|
35
|
-
const getOffsetRect = elem => {
|
|
36
|
-
// (1)
|
|
19
|
+
const getOffsetRect = (elem) => {
|
|
37
20
|
const box = elem.getBoundingClientRect();
|
|
38
|
-
const {
|
|
39
|
-
body,
|
|
40
|
-
documentElement
|
|
41
|
-
} = document; // (2)
|
|
42
|
-
|
|
21
|
+
const { body, documentElement } = document;
|
|
43
22
|
const scrollTop = window.pageYOffset || documentElement.scrollTop || body.scrollTop;
|
|
44
|
-
const scrollLeft = window.pageXOffset || documentElement.scrollLeft || body.scrollLeft;
|
|
45
|
-
|
|
23
|
+
const scrollLeft = window.pageXOffset || documentElement.scrollLeft || body.scrollLeft;
|
|
46
24
|
const clientTop = documentElement.clientTop || body.clientTop || 0;
|
|
47
|
-
const clientLeft = documentElement.clientLeft || body.clientLeft || 0;
|
|
48
|
-
|
|
25
|
+
const clientLeft = documentElement.clientLeft || body.clientLeft || 0;
|
|
49
26
|
const top = box.top + scrollTop - clientTop;
|
|
50
27
|
const left = box.left + scrollLeft - clientLeft;
|
|
51
|
-
return {
|
|
52
|
-
top: Math.round(top),
|
|
53
|
-
left: Math.round(left)
|
|
54
|
-
};
|
|
28
|
+
return { top: Math.round(top), left: Math.round(left) };
|
|
55
29
|
};
|
|
56
|
-
const getTotalScroll = elem => {
|
|
30
|
+
const getTotalScroll = (elem) => {
|
|
57
31
|
let top = 0;
|
|
58
|
-
let left = 0;
|
|
59
|
-
|
|
32
|
+
let left = 0;
|
|
60
33
|
while (elem = elem.parentNode) {
|
|
61
34
|
top += elem.scrollTop || 0;
|
|
62
35
|
left += elem.scrollLeft || 0;
|
|
63
36
|
}
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
top,
|
|
67
|
-
left
|
|
68
|
-
};
|
|
37
|
+
return { top, left };
|
|
69
38
|
};
|
|
70
39
|
const getTransformProps = (x, y) => ({
|
|
71
|
-
transform:
|
|
40
|
+
transform: `translate(${x}px, ${y}px)`
|
|
72
41
|
});
|
|
73
|
-
const listWithChildren = (list, childrenProp) => list.map(item =>
|
|
42
|
+
const listWithChildren = (list, childrenProp) => list.map((item) => ({
|
|
43
|
+
...item,
|
|
74
44
|
[childrenProp]: item[childrenProp] ? listWithChildren(item[childrenProp], childrenProp) : []
|
|
75
45
|
}));
|
|
76
46
|
const getAllNonEmptyNodesIds = (items, childrenProp) => {
|
|
77
47
|
let childrenIds = [];
|
|
78
|
-
const ids = items.filter(item => item[childrenProp].length).map(item => {
|
|
48
|
+
const ids = items.filter((item) => item[childrenProp].length).map((item) => {
|
|
79
49
|
childrenIds = childrenIds.concat(getAllNonEmptyNodesIds(item[childrenProp], childrenProp));
|
|
80
50
|
return item.id;
|
|
81
51
|
});
|
|
@@ -83,13 +53,26 @@ const getAllNonEmptyNodesIds = (items, childrenProp) => {
|
|
|
83
53
|
};
|
|
84
54
|
const isInternetExplorer = () => {
|
|
85
55
|
const ua = window.navigator.userAgent;
|
|
86
|
-
const msie = ua.indexOf(
|
|
87
|
-
|
|
56
|
+
const msie = ua.indexOf("MSIE ");
|
|
88
57
|
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv:11\./)) {
|
|
89
58
|
return true;
|
|
90
59
|
}
|
|
91
|
-
|
|
92
60
|
return false;
|
|
93
61
|
};
|
|
94
|
-
|
|
95
|
-
|
|
62
|
+
export {
|
|
63
|
+
closest,
|
|
64
|
+
getAllNonEmptyNodesIds,
|
|
65
|
+
getOffsetRect,
|
|
66
|
+
getTotalScroll,
|
|
67
|
+
getTransformProps,
|
|
68
|
+
isArray,
|
|
69
|
+
isDefined,
|
|
70
|
+
isFunction,
|
|
71
|
+
isInternetExplorer,
|
|
72
|
+
isNumber,
|
|
73
|
+
isString,
|
|
74
|
+
isUndefined,
|
|
75
|
+
listWithChildren,
|
|
76
|
+
objectType
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=utils.js.map
|