@headless-tree/core 1.6.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.js +11 -6
- package/dist/index.mjs +11 -6
- package/package.json +1 -1
- package/src/features/selection/feature.ts +13 -9
- package/src/features/selection/selection.spec.ts +4 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @headless-tree/core
|
|
2
2
|
|
|
3
|
+
## 1.6.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4ddeaf3: Fixed behavior where shift-selecting an item with no previously selected or focused item would multiselect all items from the top to the clicked item. Now, shift-selecting an item with no previously clicked items will only select the clicked item (#176)
|
|
8
|
+
|
|
3
9
|
## 1.6.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/dist/index.js
CHANGED
|
@@ -759,10 +759,15 @@ var selectionFeature = {
|
|
|
759
759
|
const { selectedItems } = tree.getState();
|
|
760
760
|
return selectedItems.includes(itemId);
|
|
761
761
|
},
|
|
762
|
-
selectUpTo: ({ tree, item }, ctrl) => {
|
|
762
|
+
selectUpTo: ({ tree, item, itemId }, ctrl) => {
|
|
763
763
|
const indexA = item.getItemMeta().index;
|
|
764
|
-
const
|
|
765
|
-
|
|
764
|
+
const dataRef = tree.getDataRef();
|
|
765
|
+
if (!dataRef.current.selectUpToAnchorId) {
|
|
766
|
+
dataRef.current.selectUpToAnchorId = itemId;
|
|
767
|
+
tree.setSelectedItems([itemId]);
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
const itemB = tree.getItemInstance(dataRef.current.selectUpToAnchorId);
|
|
766
771
|
const indexB = itemB.getItemMeta().index;
|
|
767
772
|
const [a, b] = indexA < indexB ? [indexA, indexB] : [indexB, indexA];
|
|
768
773
|
const newSelectedItems = tree.getItems().slice(a, b + 1).map((treeItem) => treeItem.getItemMeta().itemId);
|
|
@@ -783,7 +788,7 @@ var selectionFeature = {
|
|
|
783
788
|
item.select();
|
|
784
789
|
}
|
|
785
790
|
},
|
|
786
|
-
getProps: ({ tree, item, prev }) => __spreadProps(__spreadValues({}, prev == null ? void 0 : prev()), {
|
|
791
|
+
getProps: ({ tree, item, itemId, prev }) => __spreadProps(__spreadValues({}, prev == null ? void 0 : prev()), {
|
|
787
792
|
"aria-selected": item.isSelected() ? "true" : "false",
|
|
788
793
|
onClick: (e) => {
|
|
789
794
|
var _a, _b;
|
|
@@ -792,10 +797,10 @@ var selectionFeature = {
|
|
|
792
797
|
} else if (e.ctrlKey || e.metaKey) {
|
|
793
798
|
item.toggleSelect();
|
|
794
799
|
} else {
|
|
795
|
-
tree.setSelectedItems([
|
|
800
|
+
tree.setSelectedItems([itemId]);
|
|
796
801
|
}
|
|
797
802
|
if (!e.shiftKey) {
|
|
798
|
-
tree.getDataRef().current.selectUpToAnchorId =
|
|
803
|
+
tree.getDataRef().current.selectUpToAnchorId = itemId;
|
|
799
804
|
}
|
|
800
805
|
(_b = (_a = prev == null ? void 0 : prev()) == null ? void 0 : _a.onClick) == null ? void 0 : _b.call(_a, e);
|
|
801
806
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -715,10 +715,15 @@ var selectionFeature = {
|
|
|
715
715
|
const { selectedItems } = tree.getState();
|
|
716
716
|
return selectedItems.includes(itemId);
|
|
717
717
|
},
|
|
718
|
-
selectUpTo: ({ tree, item }, ctrl) => {
|
|
718
|
+
selectUpTo: ({ tree, item, itemId }, ctrl) => {
|
|
719
719
|
const indexA = item.getItemMeta().index;
|
|
720
|
-
const
|
|
721
|
-
|
|
720
|
+
const dataRef = tree.getDataRef();
|
|
721
|
+
if (!dataRef.current.selectUpToAnchorId) {
|
|
722
|
+
dataRef.current.selectUpToAnchorId = itemId;
|
|
723
|
+
tree.setSelectedItems([itemId]);
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
const itemB = tree.getItemInstance(dataRef.current.selectUpToAnchorId);
|
|
722
727
|
const indexB = itemB.getItemMeta().index;
|
|
723
728
|
const [a, b] = indexA < indexB ? [indexA, indexB] : [indexB, indexA];
|
|
724
729
|
const newSelectedItems = tree.getItems().slice(a, b + 1).map((treeItem) => treeItem.getItemMeta().itemId);
|
|
@@ -739,7 +744,7 @@ var selectionFeature = {
|
|
|
739
744
|
item.select();
|
|
740
745
|
}
|
|
741
746
|
},
|
|
742
|
-
getProps: ({ tree, item, prev }) => __spreadProps(__spreadValues({}, prev == null ? void 0 : prev()), {
|
|
747
|
+
getProps: ({ tree, item, itemId, prev }) => __spreadProps(__spreadValues({}, prev == null ? void 0 : prev()), {
|
|
743
748
|
"aria-selected": item.isSelected() ? "true" : "false",
|
|
744
749
|
onClick: (e) => {
|
|
745
750
|
var _a, _b;
|
|
@@ -748,10 +753,10 @@ var selectionFeature = {
|
|
|
748
753
|
} else if (e.ctrlKey || e.metaKey) {
|
|
749
754
|
item.toggleSelect();
|
|
750
755
|
} else {
|
|
751
|
-
tree.setSelectedItems([
|
|
756
|
+
tree.setSelectedItems([itemId]);
|
|
752
757
|
}
|
|
753
758
|
if (!e.shiftKey) {
|
|
754
|
-
tree.getDataRef().current.selectUpToAnchorId =
|
|
759
|
+
tree.getDataRef().current.selectUpToAnchorId = itemId;
|
|
755
760
|
}
|
|
756
761
|
(_b = (_a = prev == null ? void 0 : prev()) == null ? void 0 : _a.onClick) == null ? void 0 : _b.call(_a, e);
|
|
757
762
|
}
|
package/package.json
CHANGED
|
@@ -49,13 +49,17 @@ export const selectionFeature: FeatureImplementation = {
|
|
|
49
49
|
return selectedItems.includes(itemId);
|
|
50
50
|
},
|
|
51
51
|
|
|
52
|
-
selectUpTo: ({ tree, item }, ctrl: boolean) => {
|
|
52
|
+
selectUpTo: ({ tree, item, itemId }, ctrl: boolean) => {
|
|
53
53
|
const indexA = item.getItemMeta().index;
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
const dataRef = tree.getDataRef<SelectionDataRef>();
|
|
55
|
+
|
|
56
|
+
if (!dataRef.current.selectUpToAnchorId) {
|
|
57
|
+
dataRef.current.selectUpToAnchorId = itemId;
|
|
58
|
+
tree.setSelectedItems([itemId]);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const itemB = tree.getItemInstance(dataRef.current.selectUpToAnchorId);
|
|
59
63
|
const indexB = itemB.getItemMeta().index;
|
|
60
64
|
const [a, b] = indexA < indexB ? [indexA, indexB] : [indexB, indexA];
|
|
61
65
|
const newSelectedItems = tree
|
|
@@ -83,7 +87,7 @@ export const selectionFeature: FeatureImplementation = {
|
|
|
83
87
|
}
|
|
84
88
|
},
|
|
85
89
|
|
|
86
|
-
getProps: ({ tree, item, prev }) => ({
|
|
90
|
+
getProps: ({ tree, item, itemId, prev }) => ({
|
|
87
91
|
...prev?.(),
|
|
88
92
|
"aria-selected": item.isSelected() ? "true" : "false",
|
|
89
93
|
onClick: (e: MouseEvent) => {
|
|
@@ -92,12 +96,12 @@ export const selectionFeature: FeatureImplementation = {
|
|
|
92
96
|
} else if (e.ctrlKey || e.metaKey) {
|
|
93
97
|
item.toggleSelect();
|
|
94
98
|
} else {
|
|
95
|
-
tree.setSelectedItems([
|
|
99
|
+
tree.setSelectedItems([itemId]);
|
|
96
100
|
}
|
|
97
101
|
|
|
98
102
|
if (!e.shiftKey) {
|
|
99
103
|
tree.getDataRef<SelectionDataRef>().current.selectUpToAnchorId =
|
|
100
|
-
|
|
104
|
+
itemId;
|
|
101
105
|
}
|
|
102
106
|
|
|
103
107
|
prev?.()?.onClick?.(e);
|
|
@@ -176,9 +176,8 @@ describe("core-feature/selections", () => {
|
|
|
176
176
|
|
|
177
177
|
it("should handle selectUpTo without ctrl", () => {
|
|
178
178
|
const setSelectedItems = tree.mockedHandler("setSelectedItems");
|
|
179
|
-
tree.
|
|
180
|
-
tree.
|
|
181
|
-
tree.instance.getItemInstance("x112").setFocused();
|
|
179
|
+
tree.do.ctrlSelectItem("x111");
|
|
180
|
+
tree.do.ctrlSelectItem("x112");
|
|
182
181
|
tree.instance.getItemInstance("x114").selectUpTo(false);
|
|
183
182
|
expect(setSelectedItems).toHaveBeenCalledWith([
|
|
184
183
|
"x112",
|
|
@@ -190,9 +189,8 @@ describe("core-feature/selections", () => {
|
|
|
190
189
|
|
|
191
190
|
it("should handle selectUpTo with ctrl", () => {
|
|
192
191
|
const setSelectedItems = tree.mockedHandler("setSelectedItems");
|
|
193
|
-
tree.
|
|
194
|
-
tree.
|
|
195
|
-
tree.instance.getItemInstance("x112").setFocused();
|
|
192
|
+
tree.do.ctrlSelectItem("x111");
|
|
193
|
+
tree.do.ctrlSelectItem("x112");
|
|
196
194
|
tree.instance.getItemInstance("x114").selectUpTo(true);
|
|
197
195
|
expect(setSelectedItems).toHaveBeenCalledWith([
|
|
198
196
|
"x111",
|