@electerm/electerm-react 1.60.29 → 1.60.32
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/client/components/bookmark-form/tree-delete.jsx +2 -5
- package/client/components/sidebar/bookmark-select.jsx +5 -3
- package/client/components/tree-list/tree-expander.jsx +2 -3
- package/client/components/tree-list/tree-list-item.jsx +2 -3
- package/client/components/tree-list/tree-list.jsx +29 -25
- package/client/store/bookmark-group.js +48 -29
- package/package.json +1 -1
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
} from 'antd'
|
|
6
6
|
import { defaultBookmarkGroupId, settingMap } from '../../common/constants'
|
|
7
7
|
import deepCopy from 'json-deep-copy'
|
|
8
|
-
import { action } from 'manate'
|
|
9
8
|
|
|
10
9
|
const e = window.translate
|
|
11
10
|
|
|
@@ -24,10 +23,8 @@ export default class BookmarkTreeDelete extends StartSessionSelect {
|
|
|
24
23
|
checkedKeys
|
|
25
24
|
} = this.props
|
|
26
25
|
const arr = checkedKeys.filter(d => d !== defaultBookmarkGroupId)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
store.delItems(arr, settingMap.bookmarkGroups)
|
|
30
|
-
})
|
|
26
|
+
store.delItems(arr, settingMap.bookmarks)
|
|
27
|
+
store.delItems(arr, settingMap.bookmarkGroups)
|
|
31
28
|
store.checkedKeys = []
|
|
32
29
|
}
|
|
33
30
|
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { auto } from 'manate/react'
|
|
6
6
|
import TreeList from '../tree-list/tree-list'
|
|
7
|
+
import deepCopy from 'json-deep-copy'
|
|
7
8
|
|
|
8
9
|
export default auto(function BookmarkSelect (props) {
|
|
9
10
|
const { store, from } = props
|
|
@@ -11,7 +12,8 @@ export default auto(function BookmarkSelect (props) {
|
|
|
11
12
|
listStyle,
|
|
12
13
|
openedSideBar,
|
|
13
14
|
leftSidebarWidth,
|
|
14
|
-
expandedKeys
|
|
15
|
+
expandedKeys,
|
|
16
|
+
bookmarks
|
|
15
17
|
} = store
|
|
16
18
|
if (from === 'sidebar' && openedSideBar !== 'bookmarks') {
|
|
17
19
|
return null
|
|
@@ -23,7 +25,7 @@ export default auto(function BookmarkSelect (props) {
|
|
|
23
25
|
store.onSelectBookmark(item.id)
|
|
24
26
|
}
|
|
25
27
|
const base = {
|
|
26
|
-
bookmarks:
|
|
28
|
+
bookmarks: deepCopy(bookmarks || []),
|
|
27
29
|
type: 'bookmarks',
|
|
28
30
|
onClickItem,
|
|
29
31
|
listStyle,
|
|
@@ -32,7 +34,7 @@ export default auto(function BookmarkSelect (props) {
|
|
|
32
34
|
const propsTree = {
|
|
33
35
|
...base,
|
|
34
36
|
shouldConfirmDel: true,
|
|
35
|
-
bookmarkGroups: store.getBookmarkGroupsTotal(),
|
|
37
|
+
bookmarkGroups: deepCopy(store.getBookmarkGroupsTotal()),
|
|
36
38
|
expandedKeys,
|
|
37
39
|
leftSidebarWidth,
|
|
38
40
|
bookmarkGroupTree: store.bookmarkGroupTree
|
|
@@ -2,9 +2,8 @@ import {
|
|
|
2
2
|
CaretDownOutlined,
|
|
3
3
|
CaretRightOutlined
|
|
4
4
|
} from '@ant-design/icons'
|
|
5
|
-
import { memo } from 'react'
|
|
6
5
|
|
|
7
|
-
export default
|
|
6
|
+
export default function TreeExpander (props) {
|
|
8
7
|
function onExpand () {
|
|
9
8
|
props.onExpand(group)
|
|
10
9
|
}
|
|
@@ -33,4 +32,4 @@ export default memo(function TreeExpander (props) {
|
|
|
33
32
|
<Icon />
|
|
34
33
|
</div>
|
|
35
34
|
)
|
|
36
|
-
}
|
|
35
|
+
}
|
|
@@ -21,12 +21,11 @@ import {
|
|
|
21
21
|
} from '../../common/constants'
|
|
22
22
|
import highlight from '../common/highlight'
|
|
23
23
|
import uid from '../../common/uid'
|
|
24
|
-
import { memo } from 'react'
|
|
25
24
|
import './tree-list.styl'
|
|
26
25
|
|
|
27
26
|
const e = window.translate
|
|
28
27
|
|
|
29
|
-
export default
|
|
28
|
+
export default function TreeListItem (props) {
|
|
30
29
|
const handleDel = (e) => {
|
|
31
30
|
props.del(props.item, e)
|
|
32
31
|
}
|
|
@@ -254,4 +253,4 @@ export default memo(function TreeListItem (props) {
|
|
|
254
253
|
{renderEditBtn()}
|
|
255
254
|
</div>
|
|
256
255
|
)
|
|
257
|
-
}
|
|
256
|
+
}
|
|
@@ -22,6 +22,7 @@ import NewButtonsGroup from './bookmark-toolbar'
|
|
|
22
22
|
import findBookmarkGroupId from '../../common/find-bookmark-group-id'
|
|
23
23
|
import getInitItem from '../../common/init-setting-item'
|
|
24
24
|
import uid from '../../common/uid'
|
|
25
|
+
import { action } from 'manate'
|
|
25
26
|
import deepEqual from 'fast-deep-equal'
|
|
26
27
|
import './tree-list.styl'
|
|
27
28
|
import TreeExpander from './tree-expander'
|
|
@@ -223,34 +224,37 @@ export default class ItemListTree extends Component {
|
|
|
223
224
|
return
|
|
224
225
|
}
|
|
225
226
|
this.onSubmit = true
|
|
226
|
-
|
|
227
|
+
this.parentId = this.state.parentId
|
|
227
228
|
this.setState({
|
|
228
229
|
showNewBookmarkGroupForm: false,
|
|
229
230
|
parentId: ''
|
|
230
|
-
},
|
|
231
|
-
this.onSubmit = false
|
|
232
|
-
const { bookmarkGroups } = window.store
|
|
233
|
-
const newCat = {
|
|
234
|
-
id: uid(),
|
|
235
|
-
title: this.state.bookmarkGroupTitle,
|
|
236
|
-
level: 2,
|
|
237
|
-
bookmarkIds: []
|
|
238
|
-
}
|
|
239
|
-
bookmarkGroups.unshift(newCat)
|
|
240
|
-
const cat = find(
|
|
241
|
-
bookmarkGroups,
|
|
242
|
-
d => d.id === id
|
|
243
|
-
)
|
|
244
|
-
if (!cat) {
|
|
245
|
-
return
|
|
246
|
-
}
|
|
247
|
-
cat.bookmarkGroupIds = [
|
|
248
|
-
...(cat.bookmarkGroupIds || []),
|
|
249
|
-
newCat.id
|
|
250
|
-
]
|
|
251
|
-
})
|
|
231
|
+
}, this.afterSubmitSub)
|
|
252
232
|
}
|
|
253
233
|
|
|
234
|
+
afterSubmitSub = action(() => {
|
|
235
|
+
const id = this.parentId
|
|
236
|
+
this.onSubmit = false
|
|
237
|
+
const { bookmarkGroups } = window.store
|
|
238
|
+
const newCat = {
|
|
239
|
+
id: uid(),
|
|
240
|
+
title: this.state.bookmarkGroupTitle,
|
|
241
|
+
level: 2,
|
|
242
|
+
bookmarkIds: []
|
|
243
|
+
}
|
|
244
|
+
bookmarkGroups.unshift(newCat)
|
|
245
|
+
const cat = find(
|
|
246
|
+
bookmarkGroups,
|
|
247
|
+
d => d.id === id
|
|
248
|
+
)
|
|
249
|
+
if (!cat) {
|
|
250
|
+
return
|
|
251
|
+
}
|
|
252
|
+
cat.bookmarkGroupIds = [
|
|
253
|
+
...(cat.bookmarkGroupIds || []),
|
|
254
|
+
newCat.id
|
|
255
|
+
]
|
|
256
|
+
})
|
|
257
|
+
|
|
254
258
|
handleNewBookmarkGroup = () => {
|
|
255
259
|
this.setState({
|
|
256
260
|
showNewBookmarkGroupForm: true,
|
|
@@ -391,7 +395,7 @@ export default class ItemListTree extends Component {
|
|
|
391
395
|
target.classList.add('item-dragover')
|
|
392
396
|
}
|
|
393
397
|
|
|
394
|
-
onDrop = e => {
|
|
398
|
+
onDrop = action(e => {
|
|
395
399
|
e.preventDefault()
|
|
396
400
|
const elems = document.querySelectorAll('.tree-item.item-dragover')
|
|
397
401
|
elems.forEach(elem => {
|
|
@@ -533,7 +537,7 @@ export default class ItemListTree extends Component {
|
|
|
533
537
|
item.level = 2
|
|
534
538
|
}
|
|
535
539
|
}
|
|
536
|
-
}
|
|
540
|
+
})
|
|
537
541
|
|
|
538
542
|
editCategory = () => {
|
|
539
543
|
const {
|
|
@@ -47,44 +47,63 @@ export default Store => {
|
|
|
47
47
|
|
|
48
48
|
Store.prototype.delBookmarkGroup = action(function ({ id }) {
|
|
49
49
|
const { store } = window
|
|
50
|
+
|
|
51
|
+
// Cannot delete default group
|
|
50
52
|
if (id === defaultBookmarkGroupId) {
|
|
51
53
|
return
|
|
52
54
|
}
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
55
|
+
|
|
56
|
+
const { bookmarkGroups } = store
|
|
57
|
+
const index = bookmarkGroups.findIndex(bg => bg.id === id)
|
|
58
|
+
|
|
59
|
+
// If group not found, return
|
|
60
|
+
if (index === -1) {
|
|
56
61
|
return
|
|
57
62
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
) {
|
|
64
|
-
|
|
65
|
-
bg
|
|
63
|
+
|
|
64
|
+
const tobeDel = bookmarkGroups[index]
|
|
65
|
+
|
|
66
|
+
// Find parent group
|
|
67
|
+
let parentGroup = null
|
|
68
|
+
if (tobeDel.level === 2) {
|
|
69
|
+
parentGroup = bookmarkGroups.find(bg =>
|
|
70
|
+
(bg.bookmarkGroupIds || []).includes(tobeDel.id)
|
|
66
71
|
)
|
|
67
|
-
groups.push(...childs)
|
|
68
72
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
|
|
74
|
+
// If no parent found, use default group
|
|
75
|
+
if (!parentGroup) {
|
|
76
|
+
parentGroup = bookmarkGroups.find(bg => bg.id === defaultBookmarkGroupId)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Ensure parent group has bookmarkIds and bookmarkGroupIds arrays
|
|
80
|
+
if (!parentGroup.bookmarkIds) {
|
|
81
|
+
parentGroup.bookmarkIds = []
|
|
82
|
+
}
|
|
83
|
+
if (!parentGroup.bookmarkGroupIds) {
|
|
84
|
+
parentGroup.bookmarkGroupIds = []
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Transfer bookmarkIds to parent
|
|
88
|
+
if (tobeDel.bookmarkIds && tobeDel.bookmarkIds.length) {
|
|
89
|
+
parentGroup.bookmarkIds = [
|
|
90
|
+
...new Set([...parentGroup.bookmarkIds, ...tobeDel.bookmarkIds])
|
|
91
|
+
]
|
|
82
92
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
93
|
+
|
|
94
|
+
// Transfer child groups to parent
|
|
95
|
+
if (tobeDel.bookmarkGroupIds && tobeDel.bookmarkGroupIds.length) {
|
|
96
|
+
parentGroup.bookmarkGroupIds = [
|
|
97
|
+
...new Set([...parentGroup.bookmarkGroupIds, ...tobeDel.bookmarkGroupIds])
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Remove the group from bookmarkGroups
|
|
102
|
+
bookmarkGroups.splice(index, 1)
|
|
103
|
+
|
|
104
|
+
// Reset current group if it was deleted
|
|
86
105
|
if (id === store.currentBookmarkGroupId) {
|
|
87
|
-
store.currentBookmarkGroupId =
|
|
106
|
+
store.currentBookmarkGroupId = parentGroup.id
|
|
88
107
|
}
|
|
89
108
|
})
|
|
90
109
|
|