@electerm/electerm-react 1.34.30
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/LICENSE +21 -0
- package/README.md +31 -0
- package/client/common/auto-complete-data-mapper.js +6 -0
- package/client/common/byte-format.js +14 -0
- package/client/common/class.js +52 -0
- package/client/common/clipboard.js +49 -0
- package/client/common/constants.js +308 -0
- package/client/common/create-lang-edit-link.js +7 -0
- package/client/common/create-title.js +29 -0
- package/client/common/db-fix.js +24 -0
- package/client/common/db.js +155 -0
- package/client/common/download-mirrors.js +10 -0
- package/client/common/download.js +16 -0
- package/client/common/error-handler.jsx +27 -0
- package/client/common/fetch-from-server.js +47 -0
- package/client/common/fetch.jsx +71 -0
- package/client/common/find-bookmark-group-id.js +15 -0
- package/client/common/find-parent.js +30 -0
- package/client/common/form-layout.js +27 -0
- package/client/common/fs.js +21 -0
- package/client/common/get-proxy.js +8 -0
- package/client/common/id-with-stamp.js +10 -0
- package/client/common/index-sorter.js +4 -0
- package/client/common/init-setting-item.js +32 -0
- package/client/common/is-absolute-path.js +3 -0
- package/client/common/is-ip.js +16 -0
- package/client/common/is-valid-path.js +7 -0
- package/client/common/key-control-pressed.js +13 -0
- package/client/common/key-pressed.js +13 -0
- package/client/common/key-shift-pressed.js +7 -0
- package/client/common/mode2permission.js +81 -0
- package/client/common/new-terminal.js +31 -0
- package/client/common/parse-int10.js +3 -0
- package/client/common/parse-json-safe.js +11 -0
- package/client/common/pass-enc.js +25 -0
- package/client/common/post-msg.js +3 -0
- package/client/common/pre.js +156 -0
- package/client/common/promise-timeout.js +27 -0
- package/client/common/resolve.js +31 -0
- package/client/common/run-idle.js +1 -0
- package/client/common/safe-local-storage.js +35 -0
- package/client/common/safe-name.js +19 -0
- package/client/common/sftp.js +74 -0
- package/client/common/terminal-theme.js +158 -0
- package/client/common/test-connection.js +12 -0
- package/client/common/time.js +30 -0
- package/client/common/to-simple-obj.js +5 -0
- package/client/common/track.js +7 -0
- package/client/common/transfer.js +76 -0
- package/client/common/trzsz.js +62 -0
- package/client/common/ui-theme.js +44 -0
- package/client/common/uid.js +5 -0
- package/client/common/update-check.js +79 -0
- package/client/common/upgrade.js +68 -0
- package/client/common/wait.js +8 -0
- package/client/common/ws.js +161 -0
- package/client/components/batch-op/batch-op.jsx +650 -0
- package/client/components/bookmark-form/bookmark-form.styl +8 -0
- package/client/components/bookmark-form/bookmark-group-tree-format.js +39 -0
- package/client/components/bookmark-form/encodes.js +44 -0
- package/client/components/bookmark-form/form-ssh-common.jsx +208 -0
- package/client/components/bookmark-form/form-tabs.jsx +69 -0
- package/client/components/bookmark-form/index.jsx +159 -0
- package/client/components/bookmark-form/local-form-ui.jsx +152 -0
- package/client/components/bookmark-form/local-form.jsx +16 -0
- package/client/components/bookmark-form/proxy.jsx +49 -0
- package/client/components/bookmark-form/quick-command-list.jsx +31 -0
- package/client/components/bookmark-form/quick-command.jsx +228 -0
- package/client/components/bookmark-form/render-auth-ssh.jsx +104 -0
- package/client/components/bookmark-form/render-connection-hopping.jsx +229 -0
- package/client/components/bookmark-form/render-delayed-scripts.jsx +88 -0
- package/client/components/bookmark-form/render-ssh-tunnel.jsx +116 -0
- package/client/components/bookmark-form/serial-form-ui.jsx +311 -0
- package/client/components/bookmark-form/serial-form.jsx +20 -0
- package/client/components/bookmark-form/sftp-enable.jsx +33 -0
- package/client/components/bookmark-form/ssh-form-ui.jsx +100 -0
- package/client/components/bookmark-form/ssh-form.jsx +348 -0
- package/client/components/bookmark-form/telnet-form-ui.jsx +154 -0
- package/client/components/bookmark-form/telnet-form.jsx +16 -0
- package/client/components/bookmark-form/tree-delete.jsx +87 -0
- package/client/components/bookmark-form/use-form-funcs.jsx +50 -0
- package/client/components/bookmark-form/use-quick-commands.jsx +83 -0
- package/client/components/bookmark-form/use-submit.jsx +77 -0
- package/client/components/bookmark-form/use-ui.jsx +82 -0
- package/client/components/bookmark-form/x11.jsx +23 -0
- package/client/components/common/animate-text.jsx +37 -0
- package/client/components/common/animate-text.styl +54 -0
- package/client/components/common/external-link.jsx +28 -0
- package/client/components/common/help-icon.jsx +25 -0
- package/client/components/common/highlight.jsx +23 -0
- package/client/components/common/highlight.styl +3 -0
- package/client/components/common/input-auto-focus.jsx +68 -0
- package/client/components/common/input-confirm.jsx +66 -0
- package/client/components/common/logo-elem.jsx +22 -0
- package/client/components/common/markdown.jsx +27 -0
- package/client/components/common/react-subx.jsx +1 -0
- package/client/components/common/resize-wrap.jsx +222 -0
- package/client/components/common/resize-wrap.styl +9 -0
- package/client/components/common/search.jsx +9 -0
- package/client/components/common/show-item.jsx +27 -0
- package/client/components/context-menu/boomarks.jsx +15 -0
- package/client/components/context-menu/context-menu.jsx +340 -0
- package/client/components/context-menu/context-menu.styl +90 -0
- package/client/components/context-menu/history.jsx +27 -0
- package/client/components/context-menu/icon-holder.jsx +5 -0
- package/client/components/context-menu/menu-btn.jsx +224 -0
- package/client/components/context-menu/sub-tab-menu.jsx +23 -0
- package/client/components/context-menu/tabs.jsx +22 -0
- package/client/components/context-menu/zoom.jsx +40 -0
- package/client/components/footer/batch-input.jsx +177 -0
- package/client/components/footer/footer-entry.jsx +141 -0
- package/client/components/footer/footer.styl +47 -0
- package/client/components/icons/match-case.jsx +10 -0
- package/client/components/icons/match-whole-word.jsx +13 -0
- package/client/components/icons/regular-exp.jsx +10 -0
- package/client/components/main/css-overwrite.jsx +92 -0
- package/client/components/main/error-wrapper.jsx +59 -0
- package/client/components/main/index.jsx +11 -0
- package/client/components/main/loading.jsx +25 -0
- package/client/components/main/main.jsx +149 -0
- package/client/components/main/term-fullscreen-control.jsx +21 -0
- package/client/components/main/term-fullscreen.styl +27 -0
- package/client/components/main/ui-theme.jsx +31 -0
- package/client/components/main/upgrade.jsx +351 -0
- package/client/components/main/upgrade.styl +27 -0
- package/client/components/main/wrapper.styl +41 -0
- package/client/components/quick-commands/qm.styl +29 -0
- package/client/components/quick-commands/quick-command-item.jsx +36 -0
- package/client/components/quick-commands/quick-command-transport-mod.jsx +54 -0
- package/client/components/quick-commands/quick-command-transport.jsx +12 -0
- package/client/components/quick-commands/quick-commands-box.jsx +233 -0
- package/client/components/quick-commands/quick-commands-form-elem.jsx +119 -0
- package/client/components/quick-commands/quick-commands-form.jsx +33 -0
- package/client/components/quick-commands/quick-commands-list.jsx +128 -0
- package/client/components/quick-commands/quick-commands-select.jsx +38 -0
- package/client/components/session/session.jsx +533 -0
- package/client/components/session/session.styl +53 -0
- package/client/components/session/sessions.jsx +445 -0
- package/client/components/setting-panel/bookmark-transport.jsx +148 -0
- package/client/components/setting-panel/bookmark-tree-list.jsx +14 -0
- package/client/components/setting-panel/col.jsx +18 -0
- package/client/components/setting-panel/list.jsx +186 -0
- package/client/components/setting-panel/list.styl +33 -0
- package/client/components/setting-panel/on-tree-drop.js +222 -0
- package/client/components/setting-panel/setting-modal.jsx +163 -0
- package/client/components/setting-panel/setting-wrap.jsx +37 -0
- package/client/components/setting-panel/setting-wrap.styl +52 -0
- package/client/components/setting-panel/setting.jsx +858 -0
- package/client/components/setting-panel/setting.styl +4 -0
- package/client/components/setting-panel/start-session-select.jsx +91 -0
- package/client/components/setting-panel/tab-bookmarks.jsx +37 -0
- package/client/components/setting-panel/tab-history.jsx +44 -0
- package/client/components/setting-panel/tab-quick-commands.jsx +38 -0
- package/client/components/setting-panel/tab-settings.jsx +42 -0
- package/client/components/setting-panel/tab-themes.jsx +34 -0
- package/client/components/setting-panel/tree-list.jsx +978 -0
- package/client/components/setting-panel/tree-list.styl +57 -0
- package/client/components/setting-sync/data-import.jsx +65 -0
- package/client/components/setting-sync/setting-sync-form.jsx +271 -0
- package/client/components/setting-sync/setting-sync.jsx +81 -0
- package/client/components/setting-sync/sync.styl +7 -0
- package/client/components/sftp/address-bar.jsx +139 -0
- package/client/components/sftp/address-bookmark-item.jsx +47 -0
- package/client/components/sftp/address-bookmark.jsx +81 -0
- package/client/components/sftp/address-bookmark.styl +8 -0
- package/client/components/sftp/confirm-modal.jsx +184 -0
- package/client/components/sftp/file-icon.jsx +22 -0
- package/client/components/sftp/file-item.jsx +1226 -0
- package/client/components/sftp/file-mode-modal.jsx +205 -0
- package/client/components/sftp/file-props-modal.jsx +211 -0
- package/client/components/sftp/file-read.js +81 -0
- package/client/components/sftp/list-table-ui.jsx +547 -0
- package/client/components/sftp/owner-list.js +97 -0
- package/client/components/sftp/paged-list.jsx +60 -0
- package/client/components/sftp/permission-render.jsx +42 -0
- package/client/components/sftp/sftp-entry.jsx +1069 -0
- package/client/components/sftp/sftp.styl +217 -0
- package/client/components/sftp/transfer-common.js +9 -0
- package/client/components/sftp/transfer-conflict.jsx +315 -0
- package/client/components/sftp/transfer-speed-format.js +60 -0
- package/client/components/sftp/transfer-tag.jsx +40 -0
- package/client/components/sftp/transfer-tag.styl +11 -0
- package/client/components/sftp/transfer.styl +55 -0
- package/client/components/sftp/transport-action.jsx +410 -0
- package/client/components/sftp/transport-entry.jsx +108 -0
- package/client/components/sftp/transport-types.js +8 -0
- package/client/components/sftp/transports-action.jsx +111 -0
- package/client/components/sftp/transports-ui.jsx +93 -0
- package/client/components/sftp/zip.js +42 -0
- package/client/components/sidebar/bookmark-select.jsx +48 -0
- package/client/components/sidebar/bookmark.jsx +82 -0
- package/client/components/sidebar/history.jsx +66 -0
- package/client/components/sidebar/index.jsx +230 -0
- package/client/components/sidebar/info-modal.jsx +250 -0
- package/client/components/sidebar/info.styl +27 -0
- package/client/components/sidebar/side-icon.jsx +25 -0
- package/client/components/sidebar/sidebar.styl +128 -0
- package/client/components/sidebar/transfer-history-modal.jsx +110 -0
- package/client/components/sidebar/transfer-history.styl +3 -0
- package/client/components/sidebar/transfer-list-control.jsx +205 -0
- package/client/components/sidebar/transfer-list.jsx +55 -0
- package/client/components/sidebar/transfer-modal.jsx +76 -0
- package/client/components/sidebar/transfer.styl +8 -0
- package/client/components/sidebar/transport-ui.jsx +109 -0
- package/client/components/tabs/index.jsx +320 -0
- package/client/components/tabs/tab.jsx +427 -0
- package/client/components/tabs/tabs.styl +220 -0
- package/client/components/tabs/window-control.jsx +55 -0
- package/client/components/terminal/attach-addon-custom.js +70 -0
- package/client/components/terminal/build-ls-term-id.js +5 -0
- package/client/components/terminal/index.jsx +1358 -0
- package/client/components/terminal/normal-buffer.jsx +33 -0
- package/client/components/terminal/term-search.jsx +224 -0
- package/client/components/terminal/term-search.styl +15 -0
- package/client/components/terminal/terminal-apis.js +31 -0
- package/client/components/terminal/terminal-interactive.jsx +148 -0
- package/client/components/terminal/terminal.styl +96 -0
- package/client/components/terminal/xterm-zmodem.js +48 -0
- package/client/components/terminal/zmodem-transfer.jsx +98 -0
- package/client/components/terminal/zmodem.styl +14 -0
- package/client/components/terminal-info/activity.jsx +54 -0
- package/client/components/terminal-info/base.jsx +25 -0
- package/client/components/terminal-info/content.jsx +101 -0
- package/client/components/terminal-info/data-cols-parser.jsx +50 -0
- package/client/components/terminal-info/disk.jsx +29 -0
- package/client/components/terminal-info/index.jsx +25 -0
- package/client/components/terminal-info/network.jsx +114 -0
- package/client/components/terminal-info/resource.jsx +80 -0
- package/client/components/terminal-info/run-cmd.jsx +273 -0
- package/client/components/terminal-info/terminal-info.styl +29 -0
- package/client/components/terminal-info/up.jsx +15 -0
- package/client/components/terminal-theme/index.jsx +264 -0
- package/client/components/terminal-theme/terminal-theme-list.styl +3 -0
- package/client/components/terminal-theme/theme-list.jsx +146 -0
- package/client/components/text-editor/text-editor-form.jsx +97 -0
- package/client/components/text-editor/text-editor.jsx +182 -0
- package/client/css/antd-overwrite.styl +14 -0
- package/client/css/basic.styl +38 -0
- package/client/css/includes/box.styl +154 -0
- package/client/css/includes/font-size.styl +6 -0
- package/client/css/includes/index.styl +3 -0
- package/client/css/includes/text.styl +31 -0
- package/client/css/includes/theme-default.styl +20 -0
- package/client/entry/basic.js +58 -0
- package/client/entry/index.jsx +15 -0
- package/client/entry/worker.js +137 -0
- package/client/store/address-bookmark.js +25 -0
- package/client/store/app-upgrade.js +23 -0
- package/client/store/batch-input-history.js +26 -0
- package/client/store/bookmark-group.js +128 -0
- package/client/store/bookmark.js +22 -0
- package/client/store/common.js +140 -0
- package/client/store/context-menu.js +23 -0
- package/client/store/db-upgrade.js +43 -0
- package/client/store/event.js +70 -0
- package/client/store/index.js +335 -0
- package/client/store/init-state.js +191 -0
- package/client/store/item.js +120 -0
- package/client/store/load-data.js +198 -0
- package/client/store/quick-command.js +43 -0
- package/client/store/session.js +54 -0
- package/client/store/setting.js +208 -0
- package/client/store/sidebar.js +48 -0
- package/client/store/sync.js +390 -0
- package/client/store/system-menu.js +120 -0
- package/client/store/tab.js +74 -0
- package/client/store/terminal-theme.js +116 -0
- package/client/store/transfer-history.js +27 -0
- package/client/store/transfer-list.js +20 -0
- package/client/store/ui-theme.js +71 -0
- package/client/store/watch.js +116 -0
- package/client/views/index.pug +58 -0
- package/package.json +34 -0
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bookmark form
|
|
3
|
+
*/
|
|
4
|
+
import { PureComponent } from 'react'
|
|
5
|
+
import {
|
|
6
|
+
message
|
|
7
|
+
} from 'antd'
|
|
8
|
+
import { findIndex, uniq, isEqual, pick } from 'lodash-es'
|
|
9
|
+
import copy from 'json-deep-copy'
|
|
10
|
+
import generate from '../../common/uid'
|
|
11
|
+
import {
|
|
12
|
+
settingMap,
|
|
13
|
+
defaultBookmarkGroupId,
|
|
14
|
+
newBookmarkIdPrefix
|
|
15
|
+
} from '../../common/constants'
|
|
16
|
+
import { isValidIP } from '../../common/is-ip'
|
|
17
|
+
import runIdle from '../../common/run-idle'
|
|
18
|
+
import getInitItem from '../../common/init-setting-item'
|
|
19
|
+
import testCon from '../../common/test-connection'
|
|
20
|
+
import FormUi from './ssh-form-ui'
|
|
21
|
+
import findBookmarkGroupId from '../../common/find-bookmark-group-id'
|
|
22
|
+
import newTerm from '../../common/new-terminal'
|
|
23
|
+
|
|
24
|
+
export default class BookmarkForm extends PureComponent {
|
|
25
|
+
state = {
|
|
26
|
+
testing: false,
|
|
27
|
+
dns: ''
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
trim = (v) => {
|
|
31
|
+
return (v || '').replace(/^\s+|\s+$/g, '')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
useIp = (form) => {
|
|
35
|
+
form.setFieldsValue({
|
|
36
|
+
host: this.state.dns
|
|
37
|
+
})
|
|
38
|
+
this.setState({
|
|
39
|
+
dns: ''
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
onPaste = (e, form) => {
|
|
44
|
+
const txt = e.clipboardData.getData('Text')
|
|
45
|
+
// support name:passsword@host:23
|
|
46
|
+
const arr = txt.match(/([^:@]+)(:[^:@]+)?@([^:@]+)(:\d+)?/)
|
|
47
|
+
if (!arr) {
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
const username = arr[1]
|
|
51
|
+
const password = arr[2] ? arr[2].slice(1) : ''
|
|
52
|
+
const host = arr[3]
|
|
53
|
+
const port = arr[4] ? arr[4].slice(1) : ''
|
|
54
|
+
const obj = {
|
|
55
|
+
username,
|
|
56
|
+
host
|
|
57
|
+
}
|
|
58
|
+
if (password) {
|
|
59
|
+
obj.password = password
|
|
60
|
+
}
|
|
61
|
+
if (port) {
|
|
62
|
+
obj.port = port
|
|
63
|
+
}
|
|
64
|
+
setTimeout(() => {
|
|
65
|
+
form.setFieldsValue(obj)
|
|
66
|
+
}, 20)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
onBlur = async (e) => {
|
|
70
|
+
const value = e.target.value.trim()
|
|
71
|
+
const { type } = this.props
|
|
72
|
+
if (
|
|
73
|
+
type !== settingMap.bookmarks ||
|
|
74
|
+
!value ||
|
|
75
|
+
isValidIP(value)
|
|
76
|
+
) {
|
|
77
|
+
return
|
|
78
|
+
}
|
|
79
|
+
const ip = await window.pre.runGlobalAsync('lookup', value)
|
|
80
|
+
.catch(err => {
|
|
81
|
+
log.debug(err)
|
|
82
|
+
})
|
|
83
|
+
this.setState({
|
|
84
|
+
dns: ip || ''
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
getBookmarkGroupId = () => {
|
|
89
|
+
const {
|
|
90
|
+
id
|
|
91
|
+
} = this.props.formData
|
|
92
|
+
const {
|
|
93
|
+
bookmarkGroups,
|
|
94
|
+
currentBookmarkGroupId
|
|
95
|
+
} = this.props
|
|
96
|
+
return id
|
|
97
|
+
? findBookmarkGroupId(bookmarkGroups, id)
|
|
98
|
+
: currentBookmarkGroupId
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
updateBookmarkGroups = (bookmarkGroups, bookmark, categoryId) => {
|
|
102
|
+
let index = findIndex(
|
|
103
|
+
bookmarkGroups,
|
|
104
|
+
bg => bg.id === categoryId
|
|
105
|
+
)
|
|
106
|
+
if (index < 0) {
|
|
107
|
+
index = findIndex(
|
|
108
|
+
bookmarkGroups,
|
|
109
|
+
bg => bg.id === defaultBookmarkGroupId
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
const bid = bookmark.id
|
|
113
|
+
const bg = bookmarkGroups[index]
|
|
114
|
+
const updates = []
|
|
115
|
+
const old = copy(bg.bookmarkIds)
|
|
116
|
+
if (!bg.bookmarkIds.includes(bid)) {
|
|
117
|
+
bg.bookmarkIds.unshift(bid)
|
|
118
|
+
}
|
|
119
|
+
bg.bookmarkIds = uniq(bg.bookmarkIds)
|
|
120
|
+
if (!isEqual(bg.bookmarkIds, old)) {
|
|
121
|
+
updates.push({
|
|
122
|
+
id: bg.id,
|
|
123
|
+
db: 'bookmarkGroups',
|
|
124
|
+
update: {
|
|
125
|
+
bookmarkIds: bg.bookmarkIds
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
bookmarkGroups = bookmarkGroups.map((bg, i) => {
|
|
130
|
+
if (i === index) {
|
|
131
|
+
return bg
|
|
132
|
+
}
|
|
133
|
+
const olde = copy(bg.bookmarkIds)
|
|
134
|
+
bg.bookmarkIds = bg.bookmarkIds.filter(
|
|
135
|
+
g => g !== bid
|
|
136
|
+
)
|
|
137
|
+
if (!isEqual(bg.bookmarkIds, olde)) {
|
|
138
|
+
updates.push({
|
|
139
|
+
id: bg.id,
|
|
140
|
+
db: 'bookmarkGroups',
|
|
141
|
+
update: {
|
|
142
|
+
bookmarkIds: bg.bookmarkIds
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
return bg
|
|
147
|
+
})
|
|
148
|
+
runIdle(() => {
|
|
149
|
+
this.props.store.setBookmarkGroups(
|
|
150
|
+
bookmarkGroups
|
|
151
|
+
)
|
|
152
|
+
})
|
|
153
|
+
runIdle(() => {
|
|
154
|
+
this.props.store.batchDbUpdate(updates)
|
|
155
|
+
})
|
|
156
|
+
message.success('OK', 3)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
submit = (evt, item, type = this.props.type) => {
|
|
160
|
+
if (item.host) {
|
|
161
|
+
item.host = item.host.trim()
|
|
162
|
+
}
|
|
163
|
+
const obj = item
|
|
164
|
+
const { addItem, editItem } = this.props.store
|
|
165
|
+
const categoryId = obj.category
|
|
166
|
+
delete obj.category
|
|
167
|
+
const bookmarkGroups = copy(
|
|
168
|
+
this.props.bookmarkGroups
|
|
169
|
+
)
|
|
170
|
+
if (type === settingMap.history) {
|
|
171
|
+
obj.id = generate()
|
|
172
|
+
runIdle(() => {
|
|
173
|
+
addItem(obj, settingMap.bookmarks)
|
|
174
|
+
})
|
|
175
|
+
this.updateBookmarkGroups(
|
|
176
|
+
bookmarkGroups,
|
|
177
|
+
obj,
|
|
178
|
+
categoryId
|
|
179
|
+
)
|
|
180
|
+
message.success('OK', 3)
|
|
181
|
+
return
|
|
182
|
+
}
|
|
183
|
+
if (!obj.id.startsWith(newBookmarkIdPrefix)) {
|
|
184
|
+
const tar = copy(obj)
|
|
185
|
+
delete tar.id
|
|
186
|
+
runIdle(() => {
|
|
187
|
+
editItem(obj.id, tar, settingMap.bookmarks)
|
|
188
|
+
})
|
|
189
|
+
this.updateBookmarkGroups(
|
|
190
|
+
bookmarkGroups,
|
|
191
|
+
obj,
|
|
192
|
+
categoryId
|
|
193
|
+
)
|
|
194
|
+
if (evt === 'saveAndCreateNew') {
|
|
195
|
+
this.setNewItem()
|
|
196
|
+
}
|
|
197
|
+
} else {
|
|
198
|
+
obj.id = generate()
|
|
199
|
+
if (evt !== 'save' && evt !== 'saveAndCreateNew') {
|
|
200
|
+
runIdle(() => {
|
|
201
|
+
addItem(obj, settingMap.history)
|
|
202
|
+
})
|
|
203
|
+
}
|
|
204
|
+
runIdle(() => {
|
|
205
|
+
addItem(obj, settingMap.bookmarks)
|
|
206
|
+
})
|
|
207
|
+
this.updateBookmarkGroups(
|
|
208
|
+
bookmarkGroups,
|
|
209
|
+
obj,
|
|
210
|
+
categoryId
|
|
211
|
+
)
|
|
212
|
+
this.setNewItem(evt === 'saveAndCreateNew'
|
|
213
|
+
? getInitItem([], settingMap.bookmarks)
|
|
214
|
+
: obj
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
setNewItem = (
|
|
220
|
+
settingItem = getInitItem([],
|
|
221
|
+
settingMap.bookmarks)
|
|
222
|
+
) => {
|
|
223
|
+
const { store } = this.props
|
|
224
|
+
this.props.store.storeAssign({
|
|
225
|
+
autofocustrigger: Date.now()
|
|
226
|
+
})
|
|
227
|
+
store.setSettingItem(settingItem)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
test = async (update) => {
|
|
231
|
+
const options = {
|
|
232
|
+
...this.props.formData,
|
|
233
|
+
...update
|
|
234
|
+
}
|
|
235
|
+
let msg = ''
|
|
236
|
+
this.setState({
|
|
237
|
+
testing: true
|
|
238
|
+
})
|
|
239
|
+
const res = await testCon(options)
|
|
240
|
+
.then(r => r)
|
|
241
|
+
.catch((e) => {
|
|
242
|
+
msg = e.message
|
|
243
|
+
return false
|
|
244
|
+
})
|
|
245
|
+
this.setState({
|
|
246
|
+
testing: false
|
|
247
|
+
})
|
|
248
|
+
if (res) {
|
|
249
|
+
message.success('connection ok')
|
|
250
|
+
} else {
|
|
251
|
+
const err = 'connection fails' +
|
|
252
|
+
(msg ? `: ${msg}` : '')
|
|
253
|
+
message.error(err)
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// reset (form) {
|
|
258
|
+
// form.resetFields()
|
|
259
|
+
// }
|
|
260
|
+
|
|
261
|
+
onSelectProxy = (proxy, form) => {
|
|
262
|
+
const obj = Object.keys(proxy)
|
|
263
|
+
.reduce((prev, c) => {
|
|
264
|
+
return {
|
|
265
|
+
...prev,
|
|
266
|
+
[`proxy.${c}`]: proxy[c]
|
|
267
|
+
}
|
|
268
|
+
}, {})
|
|
269
|
+
form.setFieldsValue(obj)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
handleFinish = (res) => {
|
|
273
|
+
this.handleSubmit('submit', res, false)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
saveAndCreateNew = (res) => {
|
|
277
|
+
this.handleSubmit('saveAndCreateNew', res, false)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
save = (res) => {
|
|
281
|
+
this.handleSubmit('save', res, false)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
testConnection = (res) => {
|
|
285
|
+
this.handleSubmit('test', res, true)
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
connect = (res) => {
|
|
289
|
+
this.handleSubmit('connect', res, false)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
handleSubmit = async (evt, res, isTest = false) => {
|
|
293
|
+
const obj = {
|
|
294
|
+
...this.props.formData,
|
|
295
|
+
...res
|
|
296
|
+
}
|
|
297
|
+
if (isTest) {
|
|
298
|
+
return this.test(obj)
|
|
299
|
+
}
|
|
300
|
+
if (evt && evt !== 'connect') {
|
|
301
|
+
this.submit(evt, obj)
|
|
302
|
+
}
|
|
303
|
+
if (evt !== 'save' && evt !== 'saveAndCreateNew') {
|
|
304
|
+
this.props.store.addTab({
|
|
305
|
+
...copy(obj),
|
|
306
|
+
...newTerm(true)
|
|
307
|
+
})
|
|
308
|
+
this.props.hide()
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
beforeUpload = async (file, form) => {
|
|
313
|
+
const privateKey = await window.fs.readFile(file.path)
|
|
314
|
+
form.setFieldsValue({
|
|
315
|
+
privateKey
|
|
316
|
+
})
|
|
317
|
+
return false
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
getProps = () => {
|
|
321
|
+
const funcs = pick(this, [
|
|
322
|
+
'beforeUpload',
|
|
323
|
+
'handleFinish',
|
|
324
|
+
'testConnection',
|
|
325
|
+
'connect',
|
|
326
|
+
'save',
|
|
327
|
+
'saveAndCreateNew',
|
|
328
|
+
'onSelectProxy',
|
|
329
|
+
'onBlur',
|
|
330
|
+
'onPaste',
|
|
331
|
+
'useIp',
|
|
332
|
+
'trim'
|
|
333
|
+
])
|
|
334
|
+
return {
|
|
335
|
+
...this.state,
|
|
336
|
+
...funcs
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
render () {
|
|
341
|
+
return (
|
|
342
|
+
<FormUi
|
|
343
|
+
{...this.props}
|
|
344
|
+
{...this.getProps()}
|
|
345
|
+
/>
|
|
346
|
+
)
|
|
347
|
+
}
|
|
348
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bookmark form
|
|
3
|
+
*/
|
|
4
|
+
import { useEffect } from 'react'
|
|
5
|
+
import {
|
|
6
|
+
Input,
|
|
7
|
+
Tabs,
|
|
8
|
+
AutoComplete,
|
|
9
|
+
Form
|
|
10
|
+
} from 'antd'
|
|
11
|
+
import {
|
|
12
|
+
newBookmarkIdPrefix,
|
|
13
|
+
terminalTelnetType
|
|
14
|
+
} from '../../common/constants'
|
|
15
|
+
import { formItemLayout } from '../../common/form-layout'
|
|
16
|
+
import findBookmarkGroupId from '../../common/find-bookmark-group-id'
|
|
17
|
+
import defaultSettings from '../../../app/common/default-setting'
|
|
18
|
+
import useSubmit from './use-submit'
|
|
19
|
+
import useUI from './use-ui'
|
|
20
|
+
import useQm from './use-quick-commands'
|
|
21
|
+
import renderCommon from './form-ssh-common'
|
|
22
|
+
import copy from 'json-deep-copy'
|
|
23
|
+
import { defaultsDeep, uniqBy } from 'lodash-es'
|
|
24
|
+
import './bookmark-form.styl'
|
|
25
|
+
|
|
26
|
+
const FormItem = Form.Item
|
|
27
|
+
const { prefix } = window
|
|
28
|
+
const e = prefix('form')
|
|
29
|
+
const s = prefix('setting')
|
|
30
|
+
|
|
31
|
+
export default function TelnetFormUI (props) {
|
|
32
|
+
const [
|
|
33
|
+
form,
|
|
34
|
+
handleFinish,
|
|
35
|
+
submitUi
|
|
36
|
+
] = useSubmit(props)
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if ((props.formData.id || '').startsWith(newBookmarkIdPrefix)) {
|
|
39
|
+
form.setFieldsValue({
|
|
40
|
+
category: props.currentBookmarkGroupId
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
}, [props.currentBookmarkGroupId])
|
|
44
|
+
const qms = useQm(form, props.formData)
|
|
45
|
+
const uis = useUI(props)
|
|
46
|
+
const {
|
|
47
|
+
id = ''
|
|
48
|
+
} = props.formData
|
|
49
|
+
const {
|
|
50
|
+
bookmarkGroups = [],
|
|
51
|
+
currentBookmarkGroupId
|
|
52
|
+
} = props
|
|
53
|
+
const initBookmarkGroupId = !id.startsWith(newBookmarkIdPrefix)
|
|
54
|
+
? findBookmarkGroupId(bookmarkGroups, id)
|
|
55
|
+
: currentBookmarkGroupId
|
|
56
|
+
let initialValues = copy(props.formData)
|
|
57
|
+
const defaultValues = {
|
|
58
|
+
port: 23,
|
|
59
|
+
id: '',
|
|
60
|
+
username: 'root',
|
|
61
|
+
password: 'guest',
|
|
62
|
+
runScripts: [{}],
|
|
63
|
+
term: defaultSettings.terminalType,
|
|
64
|
+
type: terminalTelnetType,
|
|
65
|
+
category: initBookmarkGroupId
|
|
66
|
+
}
|
|
67
|
+
initialValues = defaultsDeep(initialValues, defaultValues)
|
|
68
|
+
function renderAuth () {
|
|
69
|
+
const opts = {
|
|
70
|
+
options: uniqBy(
|
|
71
|
+
props.store.getBookmarks()
|
|
72
|
+
.filter(d => d.password),
|
|
73
|
+
(d) => d.password
|
|
74
|
+
)
|
|
75
|
+
.map(d => {
|
|
76
|
+
return {
|
|
77
|
+
label: `${d.title ? `(${d.title})` : ''}${d.username || ''}:${d.host}-******`,
|
|
78
|
+
value: d.password
|
|
79
|
+
}
|
|
80
|
+
}),
|
|
81
|
+
placeholder: e('password'),
|
|
82
|
+
allowClear: false
|
|
83
|
+
}
|
|
84
|
+
return (
|
|
85
|
+
<FormItem
|
|
86
|
+
{...formItemLayout}
|
|
87
|
+
label={e('password')}
|
|
88
|
+
name='password'
|
|
89
|
+
hasFeedback
|
|
90
|
+
rules={[{
|
|
91
|
+
max: 1024, message: '1024 chars max'
|
|
92
|
+
}]}
|
|
93
|
+
>
|
|
94
|
+
<AutoComplete
|
|
95
|
+
{...opts}
|
|
96
|
+
>
|
|
97
|
+
<Input.Password />
|
|
98
|
+
</AutoComplete>
|
|
99
|
+
</FormItem>
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
const tprops = {
|
|
103
|
+
...props,
|
|
104
|
+
renderAuth,
|
|
105
|
+
form
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function renderTabs () {
|
|
109
|
+
const items = [
|
|
110
|
+
{
|
|
111
|
+
key: 'auth',
|
|
112
|
+
label: e('auth'),
|
|
113
|
+
forceRender: true,
|
|
114
|
+
children: (
|
|
115
|
+
<div>
|
|
116
|
+
{renderCommon(tprops)}
|
|
117
|
+
<FormItem {...formItemLayout} label={e('type')} name='type' className='hide'>
|
|
118
|
+
<Input />
|
|
119
|
+
</FormItem>
|
|
120
|
+
</div>
|
|
121
|
+
)
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
key: 'settings',
|
|
125
|
+
label: s('settings'),
|
|
126
|
+
forceRender: true,
|
|
127
|
+
children: uis
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
key: 'quickCommands',
|
|
131
|
+
label: e('quickCommands'),
|
|
132
|
+
forceRender: true,
|
|
133
|
+
children: qms
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
return (
|
|
137
|
+
<Tabs
|
|
138
|
+
items={items}
|
|
139
|
+
/>
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return (
|
|
144
|
+
<Form
|
|
145
|
+
form={form}
|
|
146
|
+
name='ssh-form'
|
|
147
|
+
onFinish={handleFinish}
|
|
148
|
+
initialValues={initialValues}
|
|
149
|
+
>
|
|
150
|
+
{renderTabs()}
|
|
151
|
+
{submitUi}
|
|
152
|
+
</Form>
|
|
153
|
+
)
|
|
154
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bookmark form
|
|
3
|
+
*/
|
|
4
|
+
import BookmarkForm from './ssh-form'
|
|
5
|
+
import TelnetFormUi from './telnet-form-ui'
|
|
6
|
+
|
|
7
|
+
export default class TelnetForm extends BookmarkForm {
|
|
8
|
+
render () {
|
|
9
|
+
return (
|
|
10
|
+
<TelnetFormUi
|
|
11
|
+
{...this.props}
|
|
12
|
+
{...this.getProps()}
|
|
13
|
+
/>
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import StartSessionSelect from '../setting-panel/start-session-select'
|
|
2
|
+
import {
|
|
3
|
+
Tree,
|
|
4
|
+
Button
|
|
5
|
+
} from 'antd'
|
|
6
|
+
import { defaultBookmarkGroupId, settingMap } from '../../common/constants'
|
|
7
|
+
|
|
8
|
+
const { prefix } = window
|
|
9
|
+
const m = prefix('common')
|
|
10
|
+
|
|
11
|
+
export default class BookmarkTreeDelete extends StartSessionSelect {
|
|
12
|
+
onExpand = (expandedKeys) => {
|
|
13
|
+
window.store.setState(
|
|
14
|
+
'expandedKeys',
|
|
15
|
+
expandedKeys
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
onCheck = (checkedKeys) => {
|
|
20
|
+
window.store.setState(
|
|
21
|
+
'checkedKeys',
|
|
22
|
+
checkedKeys
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
handleDel = () => {
|
|
27
|
+
const { store } = window
|
|
28
|
+
const {
|
|
29
|
+
checkedKeys,
|
|
30
|
+
bookmarks,
|
|
31
|
+
bookmarkGroups
|
|
32
|
+
} = store
|
|
33
|
+
store.setBookmarks(
|
|
34
|
+
bookmarks.filter(f => {
|
|
35
|
+
return !checkedKeys.includes(f.id)
|
|
36
|
+
})
|
|
37
|
+
)
|
|
38
|
+
store.setBookmarkGroups(
|
|
39
|
+
bookmarkGroups.filter(f => {
|
|
40
|
+
return f.id === defaultBookmarkGroupId || !checkedKeys.includes(f.id)
|
|
41
|
+
})
|
|
42
|
+
)
|
|
43
|
+
const arr = checkedKeys.filter(d => d !== defaultBookmarkGroupId)
|
|
44
|
+
store.delItems(arr, settingMap.bookmarks)
|
|
45
|
+
store.delItems(arr, settingMap.bookmarkGroups)
|
|
46
|
+
store.setState('checkedKeys', [])
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
handleCancel = () => {
|
|
50
|
+
const { store } = window
|
|
51
|
+
store.bookmarkSelectMode = false
|
|
52
|
+
store.setState('checkedKeys', [])
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
render () {
|
|
56
|
+
const { store } = this.props
|
|
57
|
+
const rProps = {
|
|
58
|
+
checkable: true,
|
|
59
|
+
autoExpandParent: true,
|
|
60
|
+
onCheck: this.onCheck,
|
|
61
|
+
expandedKeys: store.expandedKeys,
|
|
62
|
+
checkedKeys: store.checkedKeys,
|
|
63
|
+
onExpand: this.onExpand,
|
|
64
|
+
treeData: this.buildData()
|
|
65
|
+
}
|
|
66
|
+
const len = store.checkedKeys.length
|
|
67
|
+
return (
|
|
68
|
+
<div>
|
|
69
|
+
<div className='pd1'>
|
|
70
|
+
<Button
|
|
71
|
+
type='primary'
|
|
72
|
+
disabled={!len}
|
|
73
|
+
onClick={this.handleDel}
|
|
74
|
+
>
|
|
75
|
+
{m('delSelected')} ({len})
|
|
76
|
+
</Button>
|
|
77
|
+
<Button
|
|
78
|
+
onClick={this.handleCancel}
|
|
79
|
+
>
|
|
80
|
+
{m('cancel')}
|
|
81
|
+
</Button>
|
|
82
|
+
</div>
|
|
83
|
+
<Tree {...rProps} />
|
|
84
|
+
</div>
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bookmark form
|
|
3
|
+
*/
|
|
4
|
+
import { useRef } from 'react'
|
|
5
|
+
import {
|
|
6
|
+
Form
|
|
7
|
+
} from 'antd'
|
|
8
|
+
|
|
9
|
+
export default function useFormFuncs (props) {
|
|
10
|
+
const [form] = Form.useForm()
|
|
11
|
+
const action = useRef('submit')
|
|
12
|
+
function save () {
|
|
13
|
+
action.current = 'save'
|
|
14
|
+
form.submit()
|
|
15
|
+
}
|
|
16
|
+
function saveAndCreateNew () {
|
|
17
|
+
action.current = 'saveAndCreateNew'
|
|
18
|
+
form.submit()
|
|
19
|
+
}
|
|
20
|
+
function testConnection () {
|
|
21
|
+
action.current = 'testConnection'
|
|
22
|
+
form.submit()
|
|
23
|
+
}
|
|
24
|
+
function connect () {
|
|
25
|
+
action.current = 'connect'
|
|
26
|
+
form.submit()
|
|
27
|
+
}
|
|
28
|
+
function handleFinish (res) {
|
|
29
|
+
if (action.current === 'save') {
|
|
30
|
+
props.save(res)
|
|
31
|
+
} else if (action.current === 'saveAndCreateNew') {
|
|
32
|
+
props.saveAndCreateNew(res)
|
|
33
|
+
} else if (action.current === 'connect') {
|
|
34
|
+
props.connect(res)
|
|
35
|
+
} else if (action.current === 'testConnection') {
|
|
36
|
+
props.testConnection(res)
|
|
37
|
+
} else {
|
|
38
|
+
props.handleFinish(res)
|
|
39
|
+
}
|
|
40
|
+
action.current = 'submit'
|
|
41
|
+
}
|
|
42
|
+
return [
|
|
43
|
+
form,
|
|
44
|
+
save,
|
|
45
|
+
saveAndCreateNew,
|
|
46
|
+
connect,
|
|
47
|
+
testConnection,
|
|
48
|
+
handleFinish
|
|
49
|
+
]
|
|
50
|
+
}
|