@onehat/ui 0.3.230 → 0.3.232
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/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useState, useEffect, useMemo, } from 'react';
|
|
2
2
|
import {
|
|
3
|
+
Box,
|
|
3
4
|
Icon,
|
|
4
5
|
Pressable,
|
|
5
6
|
Row,
|
|
@@ -41,6 +42,7 @@ export default function GridHeaderRow(props) {
|
|
|
41
42
|
gridRef,
|
|
42
43
|
isHovered,
|
|
43
44
|
isInlineEditorShown,
|
|
45
|
+
areRowsDragSource,
|
|
44
46
|
} = props,
|
|
45
47
|
styles = UiGlobals.styles,
|
|
46
48
|
sortFn = Repository && Repository.getSortFn(),
|
|
@@ -442,6 +444,12 @@ export default function GridHeaderRow(props) {
|
|
|
442
444
|
/>}
|
|
443
445
|
</Pressable>;
|
|
444
446
|
});
|
|
447
|
+
if (areRowsDragSource) {
|
|
448
|
+
headerColumns.unshift(<Box
|
|
449
|
+
key="spacer"
|
|
450
|
+
w={3}
|
|
451
|
+
/>);
|
|
452
|
+
}
|
|
445
453
|
if (!hideNavColumn) {
|
|
446
454
|
headerColumns.push(<AngleRight
|
|
447
455
|
key="AngleRight"
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { useState, useEffect, } from 'react';
|
|
1
|
+
import { useState, useEffect, useRef, } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
SELECTION_MODE_SINGLE,
|
|
4
4
|
SELECTION_MODE_MULTI,
|
|
5
5
|
SELECT_UP,
|
|
6
6
|
SELECT_DOWN,
|
|
7
7
|
} from '../../Constants/Selection.js';
|
|
8
|
+
import useForceUpdate from '../../Hooks/useForceUpdate.js';
|
|
8
9
|
import inArray from '../../Functions/inArray.js';
|
|
9
10
|
import _ from 'lodash';
|
|
10
11
|
|
|
@@ -46,20 +47,22 @@ export default function withSelection(WrappedComponent) {
|
|
|
46
47
|
} = props,
|
|
47
48
|
usesWithValue = !!setValue,
|
|
48
49
|
initialSelection = selection || defaultSelection || [],
|
|
49
|
-
|
|
50
|
+
forceUpdate = useForceUpdate(),
|
|
51
|
+
localSelection = useRef(initialSelection),
|
|
50
52
|
[isReady, setIsReady] = useState(selection || false), // if selection is already defined, or value is not null and we don't need to load repository, it's ready
|
|
51
53
|
setSelection = (selection) => {
|
|
52
|
-
if (_.isEqual(selection, localSelection)) {
|
|
54
|
+
if (_.isEqual(selection, localSelection.current)) {
|
|
53
55
|
return;
|
|
54
56
|
}
|
|
55
57
|
|
|
56
|
-
|
|
58
|
+
localSelection.current = selection;
|
|
57
59
|
if (onChangeSelection) {
|
|
58
60
|
onChangeSelection(selection);
|
|
59
61
|
}
|
|
60
62
|
if (fireEvent) {
|
|
61
63
|
fireEvent('changeSelection', selection);
|
|
62
64
|
}
|
|
65
|
+
forceUpdate();
|
|
63
66
|
},
|
|
64
67
|
selectNext = () => {
|
|
65
68
|
selectDirection(SELECT_DOWN);
|
|
@@ -91,23 +94,21 @@ export default function withSelection(WrappedComponent) {
|
|
|
91
94
|
},
|
|
92
95
|
addToSelection = (item) => {
|
|
93
96
|
let newSelection = [];
|
|
94
|
-
newSelection = _.clone(localSelection); // so we get a new object, so descendants rerender
|
|
97
|
+
newSelection = _.clone(localSelection.current); // so we get a new object, so descendants rerender
|
|
95
98
|
newSelection.push(item);
|
|
96
99
|
setSelection(newSelection);
|
|
97
100
|
},
|
|
98
101
|
removeFromSelection = (item) => {
|
|
99
102
|
let newSelection = [];
|
|
100
103
|
if (Repository) {
|
|
101
|
-
newSelection = _.remove(localSelection, (sel) => sel !== item);
|
|
104
|
+
newSelection = _.remove(localSelection.current, (sel) => sel !== item);
|
|
102
105
|
} else {
|
|
103
|
-
newSelection = _.remove(localSelection, (sel) => sel[idIx] !== item[idIx]);
|
|
106
|
+
newSelection = _.remove(localSelection.current, (sel) => sel[idIx] !== item[idIx]);
|
|
104
107
|
}
|
|
105
108
|
setSelection(newSelection);
|
|
106
109
|
},
|
|
107
110
|
deselectAll = () => {
|
|
108
|
-
|
|
109
|
-
setSelection([]);
|
|
110
|
-
}
|
|
111
|
+
setSelection([]);
|
|
111
112
|
},
|
|
112
113
|
getMaxMinSelectionIndices = () => {
|
|
113
114
|
let items,
|
|
@@ -134,9 +135,9 @@ export default function withSelection(WrappedComponent) {
|
|
|
134
135
|
selectRangeTo = (item) => {
|
|
135
136
|
// Select above max or below min to this one
|
|
136
137
|
const
|
|
137
|
-
currentSelectionLength = localSelection.length,
|
|
138
|
+
currentSelectionLength = localSelection.current.length,
|
|
138
139
|
index = getIndexOfSelectedItem(item);
|
|
139
|
-
let newSelection = _.clone(localSelection); // so we get a new object, so descendants rerender
|
|
140
|
+
let newSelection = _.clone(localSelection.current); // so we get a new object, so descendants rerender
|
|
140
141
|
|
|
141
142
|
if (currentSelectionLength) {
|
|
142
143
|
const { items, max, min, } = getMaxMinSelectionIndices();
|
|
@@ -163,10 +164,10 @@ export default function withSelection(WrappedComponent) {
|
|
|
163
164
|
},
|
|
164
165
|
isInSelection = (item) => {
|
|
165
166
|
if (Repository) {
|
|
166
|
-
return inArray(item, localSelection);
|
|
167
|
+
return inArray(item, localSelection.current);
|
|
167
168
|
}
|
|
168
169
|
|
|
169
|
-
const found = _.find(localSelection, (selectedItem) => {
|
|
170
|
+
const found = _.find(localSelection.current, (selectedItem) => {
|
|
170
171
|
return selectedItem[idIx] === item[idIx];
|
|
171
172
|
});
|
|
172
173
|
return !!found;
|
|
@@ -188,10 +189,10 @@ export default function withSelection(WrappedComponent) {
|
|
|
188
189
|
return found;
|
|
189
190
|
},
|
|
190
191
|
getIdsFromLocalSelection = () => {
|
|
191
|
-
if (!localSelection[0]) {
|
|
192
|
+
if (!localSelection.current[0]) {
|
|
192
193
|
return null;
|
|
193
194
|
}
|
|
194
|
-
const values = _.map(localSelection, (item) => {
|
|
195
|
+
const values = _.map(localSelection.current, (item) => {
|
|
195
196
|
if (Repository) {
|
|
196
197
|
return item.id;
|
|
197
198
|
}
|
|
@@ -202,7 +203,7 @@ export default function withSelection(WrappedComponent) {
|
|
|
202
203
|
}
|
|
203
204
|
return values;
|
|
204
205
|
},
|
|
205
|
-
|
|
206
|
+
getDisplayValuesFromSelection = (selection) => {
|
|
206
207
|
if (!selection[0]) {
|
|
207
208
|
return '';
|
|
208
209
|
}
|
|
@@ -275,11 +276,21 @@ export default function withSelection(WrappedComponent) {
|
|
|
275
276
|
}
|
|
276
277
|
}
|
|
277
278
|
|
|
278
|
-
if (!_.isEqual(newSelection, localSelection)) {
|
|
279
|
+
if (!_.isEqual(newSelection, localSelection.current)) {
|
|
279
280
|
setSelection(newSelection);
|
|
280
281
|
}
|
|
281
282
|
};
|
|
282
283
|
|
|
284
|
+
if (Repository) {
|
|
285
|
+
useEffect(() => {
|
|
286
|
+
// clear the selection when Repository loads
|
|
287
|
+
Repository.on('load', deselectAll);
|
|
288
|
+
return () => {
|
|
289
|
+
Repository.off('load', deselectAll);
|
|
290
|
+
};
|
|
291
|
+
}, []);
|
|
292
|
+
}
|
|
293
|
+
|
|
283
294
|
useEffect(() => {
|
|
284
295
|
|
|
285
296
|
(async () => {
|
|
@@ -317,7 +328,7 @@ export default function withSelection(WrappedComponent) {
|
|
|
317
328
|
}, [value]);
|
|
318
329
|
|
|
319
330
|
if (self) {
|
|
320
|
-
self.selection = localSelection;
|
|
331
|
+
self.selection = localSelection.current;
|
|
321
332
|
self.setSelection = setSelection;
|
|
322
333
|
self.selectNext = selectNext;
|
|
323
334
|
self.selectPrev = selectPrev;
|
|
@@ -327,7 +338,7 @@ export default function withSelection(WrappedComponent) {
|
|
|
327
338
|
self.selectRangeTo = selectRangeTo;
|
|
328
339
|
self.isInSelection = isInSelection;
|
|
329
340
|
self.getIdsFromLocalSelection = getIdsFromLocalSelection;
|
|
330
|
-
self.getDisplayValuesFromSelection =
|
|
341
|
+
self.getDisplayValuesFromSelection = getDisplayValuesFromSelection;
|
|
331
342
|
}
|
|
332
343
|
|
|
333
344
|
if (usesWithValue) {
|
|
@@ -357,7 +368,7 @@ export default function withSelection(WrappedComponent) {
|
|
|
357
368
|
return <WrappedComponent
|
|
358
369
|
{...props}
|
|
359
370
|
disableWithSelection={false}
|
|
360
|
-
selection={localSelection}
|
|
371
|
+
selection={localSelection.current}
|
|
361
372
|
setSelection={setSelection}
|
|
362
373
|
selectionMode={selectionMode}
|
|
363
374
|
selectNext={selectNext}
|
|
@@ -368,7 +379,7 @@ export default function withSelection(WrappedComponent) {
|
|
|
368
379
|
selectRangeTo={selectRangeTo}
|
|
369
380
|
isInSelection={isInSelection}
|
|
370
381
|
getIdsFromSelection={getIdsFromLocalSelection}
|
|
371
|
-
getDisplayValuesFromSelection={
|
|
382
|
+
getDisplayValuesFromSelection={getDisplayValuesFromSelection}
|
|
372
383
|
/>;
|
|
373
384
|
};
|
|
374
385
|
}
|