@splicetree/plugin-selectable 0.1.1 → 0.3.0
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 +18 -0
- package/dist/index.js +18 -5
- package/package.json +2 -2
- package/src/index.ts +15 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @splicetree/plugin-selectable
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 选择行为优化:
|
|
8
|
+
- 普通点击在 multiple: true 时采用单选语义:清空其它选中,仅选中当前节点;若再次点击已选中节点则取消选中。
|
|
9
|
+
- ⌘/Ctrl + 点击 支持多选;Shift + 点击 支持范围选择。
|
|
10
|
+
- 示例已统一接入标准 onClick 事件,避免直接调用 toggleSelect 导致行为不一致。
|
|
11
|
+
|
|
12
|
+
影响与迁移:
|
|
13
|
+
- 若项目依赖旧的“普通点击追加选择”行为,请改为使用 ⌘/Ctrl + 点击 完成多选。
|
|
14
|
+
|
|
15
|
+
## 0.2.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- chore: align pointer/selectable versions with other plugins
|
|
20
|
+
|
|
3
21
|
## 0.1.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
package/dist/index.js
CHANGED
|
@@ -46,9 +46,13 @@ const selectablePlugin = {
|
|
|
46
46
|
if (!ctx.tree.getNode(nodeId)) return;
|
|
47
47
|
const shift = modifiers.shift;
|
|
48
48
|
const multiToggle = multiple && (modifiers.ctrl || modifiers.meta);
|
|
49
|
-
if (shift && lastSelectedKey) selectRange(lastSelectedKey, nodeId);
|
|
49
|
+
if (shift && multiple && lastSelectedKey) selectRange(lastSelectedKey, nodeId);
|
|
50
50
|
else if (multiToggle) toggleSelect(nodeId);
|
|
51
|
-
else
|
|
51
|
+
else {
|
|
52
|
+
const wasSelected = isSelected(nodeId);
|
|
53
|
+
if (multiple) selectedKeys.clear();
|
|
54
|
+
toggleSelect(nodeId, !wasSelected);
|
|
55
|
+
}
|
|
52
56
|
});
|
|
53
57
|
ctx.events.on("input:direction", (p) => {
|
|
54
58
|
const direction = p.direction;
|
|
@@ -66,13 +70,19 @@ const selectablePlugin = {
|
|
|
66
70
|
const parent = node.getParent();
|
|
67
71
|
if (parent) {
|
|
68
72
|
ctx.tree.activeId = parent.id;
|
|
69
|
-
if (!(modifiers.ctrl || modifiers.meta))
|
|
73
|
+
if (!(modifiers.ctrl || modifiers.meta)) {
|
|
74
|
+
if (multiple) selectedKeys.clear();
|
|
75
|
+
toggleSelect(parent.id, true);
|
|
76
|
+
}
|
|
70
77
|
}
|
|
71
78
|
}
|
|
72
79
|
else if (direction === "right") {
|
|
73
80
|
if (node.hasChildren()) {
|
|
74
81
|
node.toggleExpand(true);
|
|
75
|
-
if (!(modifiers.ctrl || modifiers.meta))
|
|
82
|
+
if (!(modifiers.ctrl || modifiers.meta)) {
|
|
83
|
+
if (multiple) selectedKeys.clear();
|
|
84
|
+
toggleSelect(node.id, true);
|
|
85
|
+
}
|
|
76
86
|
}
|
|
77
87
|
}
|
|
78
88
|
return;
|
|
@@ -84,7 +94,10 @@ const selectablePlugin = {
|
|
|
84
94
|
if (!nextId) return;
|
|
85
95
|
ctx.tree.activeId = nextId;
|
|
86
96
|
if (modifiers.shift && multiple && lastSelectedKey) selectRange(lastSelectedKey, nextId);
|
|
87
|
-
else if (!(modifiers.ctrl || modifiers.meta))
|
|
97
|
+
else if (!(modifiers.ctrl || modifiers.meta)) {
|
|
98
|
+
if (multiple) selectedKeys.clear();
|
|
99
|
+
toggleSelect(nextId, true);
|
|
100
|
+
}
|
|
88
101
|
});
|
|
89
102
|
for (const id of defaultSelected) {
|
|
90
103
|
selectedKeys.add(id);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@splicetree/plugin-selectable",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"email": "michael.cocova@gmail.com",
|
|
7
7
|
"name": "Michael Cocova"
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@splicetree/core": "0.
|
|
26
|
+
"@splicetree/core": "0.3.0"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
29
|
"dev": "tsdown --watch",
|
package/src/index.ts
CHANGED
|
@@ -96,12 +96,16 @@ export const selectablePlugin: SpliceTreePlugin = {
|
|
|
96
96
|
}
|
|
97
97
|
const shift = modifiers.shift
|
|
98
98
|
const multiToggle = multiple && (modifiers.ctrl || modifiers.meta)
|
|
99
|
-
if (shift && lastSelectedKey) {
|
|
99
|
+
if (shift && multiple && lastSelectedKey) {
|
|
100
100
|
selectRange(lastSelectedKey, nodeId)
|
|
101
101
|
} else if (multiToggle) {
|
|
102
102
|
toggleSelect(nodeId)
|
|
103
103
|
} else {
|
|
104
|
-
|
|
104
|
+
const wasSelected = isSelected(nodeId)
|
|
105
|
+
if (multiple) {
|
|
106
|
+
selectedKeys.clear()
|
|
107
|
+
}
|
|
108
|
+
toggleSelect(nodeId, !wasSelected)
|
|
105
109
|
}
|
|
106
110
|
})
|
|
107
111
|
|
|
@@ -130,6 +134,9 @@ export const selectablePlugin: SpliceTreePlugin = {
|
|
|
130
134
|
if (parent) {
|
|
131
135
|
ctx.tree.activeId = parent.id
|
|
132
136
|
if (!(modifiers.ctrl || modifiers.meta)) {
|
|
137
|
+
if (multiple) {
|
|
138
|
+
selectedKeys.clear()
|
|
139
|
+
}
|
|
133
140
|
toggleSelect(parent.id, true)
|
|
134
141
|
}
|
|
135
142
|
}
|
|
@@ -138,6 +145,9 @@ export const selectablePlugin: SpliceTreePlugin = {
|
|
|
138
145
|
if (node.hasChildren()) {
|
|
139
146
|
node.toggleExpand(true)
|
|
140
147
|
if (!(modifiers.ctrl || modifiers.meta)) {
|
|
148
|
+
if (multiple) {
|
|
149
|
+
selectedKeys.clear()
|
|
150
|
+
}
|
|
141
151
|
toggleSelect(node.id, true)
|
|
142
152
|
}
|
|
143
153
|
}
|
|
@@ -158,6 +168,9 @@ export const selectablePlugin: SpliceTreePlugin = {
|
|
|
158
168
|
if (modifiers.shift && multiple && lastSelectedKey) {
|
|
159
169
|
selectRange(lastSelectedKey, nextId)
|
|
160
170
|
} else if (!(modifiers.ctrl || modifiers.meta)) {
|
|
171
|
+
if (multiple) {
|
|
172
|
+
selectedKeys.clear()
|
|
173
|
+
}
|
|
161
174
|
toggleSelect(nextId, true)
|
|
162
175
|
}
|
|
163
176
|
})
|