@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.
Files changed (273) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +31 -0
  3. package/client/common/auto-complete-data-mapper.js +6 -0
  4. package/client/common/byte-format.js +14 -0
  5. package/client/common/class.js +52 -0
  6. package/client/common/clipboard.js +49 -0
  7. package/client/common/constants.js +308 -0
  8. package/client/common/create-lang-edit-link.js +7 -0
  9. package/client/common/create-title.js +29 -0
  10. package/client/common/db-fix.js +24 -0
  11. package/client/common/db.js +155 -0
  12. package/client/common/download-mirrors.js +10 -0
  13. package/client/common/download.js +16 -0
  14. package/client/common/error-handler.jsx +27 -0
  15. package/client/common/fetch-from-server.js +47 -0
  16. package/client/common/fetch.jsx +71 -0
  17. package/client/common/find-bookmark-group-id.js +15 -0
  18. package/client/common/find-parent.js +30 -0
  19. package/client/common/form-layout.js +27 -0
  20. package/client/common/fs.js +21 -0
  21. package/client/common/get-proxy.js +8 -0
  22. package/client/common/id-with-stamp.js +10 -0
  23. package/client/common/index-sorter.js +4 -0
  24. package/client/common/init-setting-item.js +32 -0
  25. package/client/common/is-absolute-path.js +3 -0
  26. package/client/common/is-ip.js +16 -0
  27. package/client/common/is-valid-path.js +7 -0
  28. package/client/common/key-control-pressed.js +13 -0
  29. package/client/common/key-pressed.js +13 -0
  30. package/client/common/key-shift-pressed.js +7 -0
  31. package/client/common/mode2permission.js +81 -0
  32. package/client/common/new-terminal.js +31 -0
  33. package/client/common/parse-int10.js +3 -0
  34. package/client/common/parse-json-safe.js +11 -0
  35. package/client/common/pass-enc.js +25 -0
  36. package/client/common/post-msg.js +3 -0
  37. package/client/common/pre.js +156 -0
  38. package/client/common/promise-timeout.js +27 -0
  39. package/client/common/resolve.js +31 -0
  40. package/client/common/run-idle.js +1 -0
  41. package/client/common/safe-local-storage.js +35 -0
  42. package/client/common/safe-name.js +19 -0
  43. package/client/common/sftp.js +74 -0
  44. package/client/common/terminal-theme.js +158 -0
  45. package/client/common/test-connection.js +12 -0
  46. package/client/common/time.js +30 -0
  47. package/client/common/to-simple-obj.js +5 -0
  48. package/client/common/track.js +7 -0
  49. package/client/common/transfer.js +76 -0
  50. package/client/common/trzsz.js +62 -0
  51. package/client/common/ui-theme.js +44 -0
  52. package/client/common/uid.js +5 -0
  53. package/client/common/update-check.js +79 -0
  54. package/client/common/upgrade.js +68 -0
  55. package/client/common/wait.js +8 -0
  56. package/client/common/ws.js +161 -0
  57. package/client/components/batch-op/batch-op.jsx +650 -0
  58. package/client/components/bookmark-form/bookmark-form.styl +8 -0
  59. package/client/components/bookmark-form/bookmark-group-tree-format.js +39 -0
  60. package/client/components/bookmark-form/encodes.js +44 -0
  61. package/client/components/bookmark-form/form-ssh-common.jsx +208 -0
  62. package/client/components/bookmark-form/form-tabs.jsx +69 -0
  63. package/client/components/bookmark-form/index.jsx +159 -0
  64. package/client/components/bookmark-form/local-form-ui.jsx +152 -0
  65. package/client/components/bookmark-form/local-form.jsx +16 -0
  66. package/client/components/bookmark-form/proxy.jsx +49 -0
  67. package/client/components/bookmark-form/quick-command-list.jsx +31 -0
  68. package/client/components/bookmark-form/quick-command.jsx +228 -0
  69. package/client/components/bookmark-form/render-auth-ssh.jsx +104 -0
  70. package/client/components/bookmark-form/render-connection-hopping.jsx +229 -0
  71. package/client/components/bookmark-form/render-delayed-scripts.jsx +88 -0
  72. package/client/components/bookmark-form/render-ssh-tunnel.jsx +116 -0
  73. package/client/components/bookmark-form/serial-form-ui.jsx +311 -0
  74. package/client/components/bookmark-form/serial-form.jsx +20 -0
  75. package/client/components/bookmark-form/sftp-enable.jsx +33 -0
  76. package/client/components/bookmark-form/ssh-form-ui.jsx +100 -0
  77. package/client/components/bookmark-form/ssh-form.jsx +348 -0
  78. package/client/components/bookmark-form/telnet-form-ui.jsx +154 -0
  79. package/client/components/bookmark-form/telnet-form.jsx +16 -0
  80. package/client/components/bookmark-form/tree-delete.jsx +87 -0
  81. package/client/components/bookmark-form/use-form-funcs.jsx +50 -0
  82. package/client/components/bookmark-form/use-quick-commands.jsx +83 -0
  83. package/client/components/bookmark-form/use-submit.jsx +77 -0
  84. package/client/components/bookmark-form/use-ui.jsx +82 -0
  85. package/client/components/bookmark-form/x11.jsx +23 -0
  86. package/client/components/common/animate-text.jsx +37 -0
  87. package/client/components/common/animate-text.styl +54 -0
  88. package/client/components/common/external-link.jsx +28 -0
  89. package/client/components/common/help-icon.jsx +25 -0
  90. package/client/components/common/highlight.jsx +23 -0
  91. package/client/components/common/highlight.styl +3 -0
  92. package/client/components/common/input-auto-focus.jsx +68 -0
  93. package/client/components/common/input-confirm.jsx +66 -0
  94. package/client/components/common/logo-elem.jsx +22 -0
  95. package/client/components/common/markdown.jsx +27 -0
  96. package/client/components/common/react-subx.jsx +1 -0
  97. package/client/components/common/resize-wrap.jsx +222 -0
  98. package/client/components/common/resize-wrap.styl +9 -0
  99. package/client/components/common/search.jsx +9 -0
  100. package/client/components/common/show-item.jsx +27 -0
  101. package/client/components/context-menu/boomarks.jsx +15 -0
  102. package/client/components/context-menu/context-menu.jsx +340 -0
  103. package/client/components/context-menu/context-menu.styl +90 -0
  104. package/client/components/context-menu/history.jsx +27 -0
  105. package/client/components/context-menu/icon-holder.jsx +5 -0
  106. package/client/components/context-menu/menu-btn.jsx +224 -0
  107. package/client/components/context-menu/sub-tab-menu.jsx +23 -0
  108. package/client/components/context-menu/tabs.jsx +22 -0
  109. package/client/components/context-menu/zoom.jsx +40 -0
  110. package/client/components/footer/batch-input.jsx +177 -0
  111. package/client/components/footer/footer-entry.jsx +141 -0
  112. package/client/components/footer/footer.styl +47 -0
  113. package/client/components/icons/match-case.jsx +10 -0
  114. package/client/components/icons/match-whole-word.jsx +13 -0
  115. package/client/components/icons/regular-exp.jsx +10 -0
  116. package/client/components/main/css-overwrite.jsx +92 -0
  117. package/client/components/main/error-wrapper.jsx +59 -0
  118. package/client/components/main/index.jsx +11 -0
  119. package/client/components/main/loading.jsx +25 -0
  120. package/client/components/main/main.jsx +149 -0
  121. package/client/components/main/term-fullscreen-control.jsx +21 -0
  122. package/client/components/main/term-fullscreen.styl +27 -0
  123. package/client/components/main/ui-theme.jsx +31 -0
  124. package/client/components/main/upgrade.jsx +351 -0
  125. package/client/components/main/upgrade.styl +27 -0
  126. package/client/components/main/wrapper.styl +41 -0
  127. package/client/components/quick-commands/qm.styl +29 -0
  128. package/client/components/quick-commands/quick-command-item.jsx +36 -0
  129. package/client/components/quick-commands/quick-command-transport-mod.jsx +54 -0
  130. package/client/components/quick-commands/quick-command-transport.jsx +12 -0
  131. package/client/components/quick-commands/quick-commands-box.jsx +233 -0
  132. package/client/components/quick-commands/quick-commands-form-elem.jsx +119 -0
  133. package/client/components/quick-commands/quick-commands-form.jsx +33 -0
  134. package/client/components/quick-commands/quick-commands-list.jsx +128 -0
  135. package/client/components/quick-commands/quick-commands-select.jsx +38 -0
  136. package/client/components/session/session.jsx +533 -0
  137. package/client/components/session/session.styl +53 -0
  138. package/client/components/session/sessions.jsx +445 -0
  139. package/client/components/setting-panel/bookmark-transport.jsx +148 -0
  140. package/client/components/setting-panel/bookmark-tree-list.jsx +14 -0
  141. package/client/components/setting-panel/col.jsx +18 -0
  142. package/client/components/setting-panel/list.jsx +186 -0
  143. package/client/components/setting-panel/list.styl +33 -0
  144. package/client/components/setting-panel/on-tree-drop.js +222 -0
  145. package/client/components/setting-panel/setting-modal.jsx +163 -0
  146. package/client/components/setting-panel/setting-wrap.jsx +37 -0
  147. package/client/components/setting-panel/setting-wrap.styl +52 -0
  148. package/client/components/setting-panel/setting.jsx +858 -0
  149. package/client/components/setting-panel/setting.styl +4 -0
  150. package/client/components/setting-panel/start-session-select.jsx +91 -0
  151. package/client/components/setting-panel/tab-bookmarks.jsx +37 -0
  152. package/client/components/setting-panel/tab-history.jsx +44 -0
  153. package/client/components/setting-panel/tab-quick-commands.jsx +38 -0
  154. package/client/components/setting-panel/tab-settings.jsx +42 -0
  155. package/client/components/setting-panel/tab-themes.jsx +34 -0
  156. package/client/components/setting-panel/tree-list.jsx +978 -0
  157. package/client/components/setting-panel/tree-list.styl +57 -0
  158. package/client/components/setting-sync/data-import.jsx +65 -0
  159. package/client/components/setting-sync/setting-sync-form.jsx +271 -0
  160. package/client/components/setting-sync/setting-sync.jsx +81 -0
  161. package/client/components/setting-sync/sync.styl +7 -0
  162. package/client/components/sftp/address-bar.jsx +139 -0
  163. package/client/components/sftp/address-bookmark-item.jsx +47 -0
  164. package/client/components/sftp/address-bookmark.jsx +81 -0
  165. package/client/components/sftp/address-bookmark.styl +8 -0
  166. package/client/components/sftp/confirm-modal.jsx +184 -0
  167. package/client/components/sftp/file-icon.jsx +22 -0
  168. package/client/components/sftp/file-item.jsx +1226 -0
  169. package/client/components/sftp/file-mode-modal.jsx +205 -0
  170. package/client/components/sftp/file-props-modal.jsx +211 -0
  171. package/client/components/sftp/file-read.js +81 -0
  172. package/client/components/sftp/list-table-ui.jsx +547 -0
  173. package/client/components/sftp/owner-list.js +97 -0
  174. package/client/components/sftp/paged-list.jsx +60 -0
  175. package/client/components/sftp/permission-render.jsx +42 -0
  176. package/client/components/sftp/sftp-entry.jsx +1069 -0
  177. package/client/components/sftp/sftp.styl +217 -0
  178. package/client/components/sftp/transfer-common.js +9 -0
  179. package/client/components/sftp/transfer-conflict.jsx +315 -0
  180. package/client/components/sftp/transfer-speed-format.js +60 -0
  181. package/client/components/sftp/transfer-tag.jsx +40 -0
  182. package/client/components/sftp/transfer-tag.styl +11 -0
  183. package/client/components/sftp/transfer.styl +55 -0
  184. package/client/components/sftp/transport-action.jsx +410 -0
  185. package/client/components/sftp/transport-entry.jsx +108 -0
  186. package/client/components/sftp/transport-types.js +8 -0
  187. package/client/components/sftp/transports-action.jsx +111 -0
  188. package/client/components/sftp/transports-ui.jsx +93 -0
  189. package/client/components/sftp/zip.js +42 -0
  190. package/client/components/sidebar/bookmark-select.jsx +48 -0
  191. package/client/components/sidebar/bookmark.jsx +82 -0
  192. package/client/components/sidebar/history.jsx +66 -0
  193. package/client/components/sidebar/index.jsx +230 -0
  194. package/client/components/sidebar/info-modal.jsx +250 -0
  195. package/client/components/sidebar/info.styl +27 -0
  196. package/client/components/sidebar/side-icon.jsx +25 -0
  197. package/client/components/sidebar/sidebar.styl +128 -0
  198. package/client/components/sidebar/transfer-history-modal.jsx +110 -0
  199. package/client/components/sidebar/transfer-history.styl +3 -0
  200. package/client/components/sidebar/transfer-list-control.jsx +205 -0
  201. package/client/components/sidebar/transfer-list.jsx +55 -0
  202. package/client/components/sidebar/transfer-modal.jsx +76 -0
  203. package/client/components/sidebar/transfer.styl +8 -0
  204. package/client/components/sidebar/transport-ui.jsx +109 -0
  205. package/client/components/tabs/index.jsx +320 -0
  206. package/client/components/tabs/tab.jsx +427 -0
  207. package/client/components/tabs/tabs.styl +220 -0
  208. package/client/components/tabs/window-control.jsx +55 -0
  209. package/client/components/terminal/attach-addon-custom.js +70 -0
  210. package/client/components/terminal/build-ls-term-id.js +5 -0
  211. package/client/components/terminal/index.jsx +1358 -0
  212. package/client/components/terminal/normal-buffer.jsx +33 -0
  213. package/client/components/terminal/term-search.jsx +224 -0
  214. package/client/components/terminal/term-search.styl +15 -0
  215. package/client/components/terminal/terminal-apis.js +31 -0
  216. package/client/components/terminal/terminal-interactive.jsx +148 -0
  217. package/client/components/terminal/terminal.styl +96 -0
  218. package/client/components/terminal/xterm-zmodem.js +48 -0
  219. package/client/components/terminal/zmodem-transfer.jsx +98 -0
  220. package/client/components/terminal/zmodem.styl +14 -0
  221. package/client/components/terminal-info/activity.jsx +54 -0
  222. package/client/components/terminal-info/base.jsx +25 -0
  223. package/client/components/terminal-info/content.jsx +101 -0
  224. package/client/components/terminal-info/data-cols-parser.jsx +50 -0
  225. package/client/components/terminal-info/disk.jsx +29 -0
  226. package/client/components/terminal-info/index.jsx +25 -0
  227. package/client/components/terminal-info/network.jsx +114 -0
  228. package/client/components/terminal-info/resource.jsx +80 -0
  229. package/client/components/terminal-info/run-cmd.jsx +273 -0
  230. package/client/components/terminal-info/terminal-info.styl +29 -0
  231. package/client/components/terminal-info/up.jsx +15 -0
  232. package/client/components/terminal-theme/index.jsx +264 -0
  233. package/client/components/terminal-theme/terminal-theme-list.styl +3 -0
  234. package/client/components/terminal-theme/theme-list.jsx +146 -0
  235. package/client/components/text-editor/text-editor-form.jsx +97 -0
  236. package/client/components/text-editor/text-editor.jsx +182 -0
  237. package/client/css/antd-overwrite.styl +14 -0
  238. package/client/css/basic.styl +38 -0
  239. package/client/css/includes/box.styl +154 -0
  240. package/client/css/includes/font-size.styl +6 -0
  241. package/client/css/includes/index.styl +3 -0
  242. package/client/css/includes/text.styl +31 -0
  243. package/client/css/includes/theme-default.styl +20 -0
  244. package/client/entry/basic.js +58 -0
  245. package/client/entry/index.jsx +15 -0
  246. package/client/entry/worker.js +137 -0
  247. package/client/store/address-bookmark.js +25 -0
  248. package/client/store/app-upgrade.js +23 -0
  249. package/client/store/batch-input-history.js +26 -0
  250. package/client/store/bookmark-group.js +128 -0
  251. package/client/store/bookmark.js +22 -0
  252. package/client/store/common.js +140 -0
  253. package/client/store/context-menu.js +23 -0
  254. package/client/store/db-upgrade.js +43 -0
  255. package/client/store/event.js +70 -0
  256. package/client/store/index.js +335 -0
  257. package/client/store/init-state.js +191 -0
  258. package/client/store/item.js +120 -0
  259. package/client/store/load-data.js +198 -0
  260. package/client/store/quick-command.js +43 -0
  261. package/client/store/session.js +54 -0
  262. package/client/store/setting.js +208 -0
  263. package/client/store/sidebar.js +48 -0
  264. package/client/store/sync.js +390 -0
  265. package/client/store/system-menu.js +120 -0
  266. package/client/store/tab.js +74 -0
  267. package/client/store/terminal-theme.js +116 -0
  268. package/client/store/transfer-history.js +27 -0
  269. package/client/store/transfer-list.js +20 -0
  270. package/client/store/ui-theme.js +71 -0
  271. package/client/store/watch.js +116 -0
  272. package/client/views/index.pug +58 -0
  273. package/package.json +34 -0
@@ -0,0 +1,31 @@
1
+ /**
2
+ * quick command list
3
+ */
4
+
5
+ import { memo } from 'react'
6
+ import QmItem from './quick-command'
7
+
8
+ export default memo(function QMList (props) {
9
+ const { quickCommands, form } = this.props
10
+ return (
11
+ <div className='pd3b mg3b'>
12
+ <QmItem
13
+ form={form}
14
+ item={{}}
15
+ />
16
+ {
17
+ quickCommands.map((item, i) => {
18
+ const k = 'qmitem' + i
19
+ return (
20
+ <QmItem
21
+ form={this.props.form}
22
+ item={item}
23
+ key={k}
24
+ i={i}
25
+ />
26
+ )
27
+ })
28
+ }
29
+ </div>
30
+ )
31
+ })
@@ -0,0 +1,228 @@
1
+ /**
2
+ * quick command list
3
+ */
4
+
5
+ import { PureComponent } from 'react'
6
+ import { CheckOutlined, CloseCircleOutlined, CloseOutlined, EditOutlined } from '@ant-design/icons'
7
+ import {
8
+ Input,
9
+ Col,
10
+ Row,
11
+ message,
12
+ Switch,
13
+ Tooltip,
14
+ Space
15
+ } from 'antd'
16
+ import { settingMap } from '../../common/constants'
17
+ import generate from '../../common/uid'
18
+ import eq from 'fast-deep-equal'
19
+
20
+ const InputGroup = Space.Compact
21
+ const { prefix } = window
22
+ const t = prefix('quickCommands')
23
+
24
+ export default class QuickCommandItem extends PureComponent {
25
+ constructor (props) {
26
+ super(props)
27
+ this.state = {
28
+ edit: !props.item.id,
29
+ item: props.item || {}
30
+ }
31
+ }
32
+
33
+ componentDidUpdate (prevProps) {
34
+ if (!eq(this.props.item, prevProps.item)) {
35
+ this.setState({
36
+ item: this.props.item
37
+ })
38
+ }
39
+ }
40
+
41
+ handleSubmit = () => {
42
+ const {
43
+ name, command, id, inputOnly
44
+ } = this.state.item
45
+ if (!name) {
46
+ return message.warning('name required')
47
+ } else if (!command) {
48
+ return message.warning('command required')
49
+ }
50
+ const quickCommands = this.props.form.getFieldValue(settingMap.quickCommands) || []
51
+ if (id) {
52
+ const qm = quickCommands.find(d => d.id === id)
53
+ if (qm) {
54
+ Object.assign(qm, {
55
+ name, command, inputOnly
56
+ })
57
+ }
58
+ this.setState({
59
+ edit: false
60
+ })
61
+ } else {
62
+ quickCommands.unshift({
63
+ name,
64
+ command,
65
+ inputOnly,
66
+ id: generate()
67
+ })
68
+ this.setState({
69
+ item: {}
70
+ })
71
+ }
72
+ this.props.form.setFieldsValue({
73
+ quickCommands
74
+ })
75
+ }
76
+
77
+ handleDel = () => {
78
+ let quickCommands = this.props.form.getFieldValue(settingMap.quickCommands) || []
79
+ quickCommands = quickCommands.filter(d => {
80
+ return d.id !== this.state.item.id
81
+ })
82
+ this.props.form.setFieldsValue({
83
+ quickCommands
84
+ })
85
+ }
86
+
87
+ handleEdit = () => {
88
+ this.setState({
89
+ edit: true
90
+ })
91
+ }
92
+
93
+ handleCancel = () => {
94
+ this.setState({
95
+ item: this.props.item,
96
+ edit: false
97
+ })
98
+ }
99
+
100
+ renderNew = (item) => {
101
+ return <CheckOutlined className='pointer mg1l' onClick={this.handleSubmit} />
102
+ }
103
+
104
+ renderIcons = (item) => {
105
+ if (!item.id) {
106
+ return this.renderNew(item)
107
+ }
108
+ return (
109
+ <span>
110
+ <CheckOutlined className='pointer mg1x' onClick={this.handleSubmit} />
111
+ <CloseOutlined className='pointer' onClick={this.handleCancel} />
112
+ </span>
113
+ )
114
+ }
115
+
116
+ handleChangeName = e => {
117
+ const v = e.target.value
118
+ this.setState({
119
+ item: {
120
+ ...this.state.item,
121
+ name: v
122
+ }
123
+ })
124
+ }
125
+
126
+ handleChangeCommand = e => {
127
+ const v = e.target.value
128
+ this.setState(old => {
129
+ return {
130
+ item: {
131
+ ...old.item,
132
+ command: v
133
+ }
134
+ }
135
+ })
136
+ }
137
+
138
+ handleChangeInputOnly = v => {
139
+ this.setState(old => {
140
+ return {
141
+ item: {
142
+ ...old.item,
143
+ inputOnly: v
144
+ }
145
+ }
146
+ })
147
+ }
148
+
149
+ renderForm = (item = this.state.item) => {
150
+ return (
151
+ <Row className='mg1t'>
152
+ <Col span={15}>
153
+ <InputGroup>
154
+ <Input
155
+ value={item.name}
156
+ onChange={this.handleChangeName}
157
+ className='width-40'
158
+ title={item.name}
159
+ placeholder={t('quickCommandName')}
160
+ />
161
+ <Input
162
+ value={item.command}
163
+ onChange={this.handleChangeCommand}
164
+ className='width-60'
165
+ placeholder={t('quickCommand')}
166
+ title={item.command}
167
+ />
168
+ </InputGroup>
169
+ </Col>
170
+ <Col span={3}>
171
+ <Tooltip title={t('inputOnly')}>
172
+ <Switch
173
+ checked={!!item.inputOnly}
174
+ onChange={this.handleChangeInputOnly}
175
+ />
176
+ </Tooltip>
177
+ </Col>
178
+ <Col span={6}>
179
+ {this.renderIcons(item)}
180
+ </Col>
181
+ </Row>
182
+ )
183
+ }
184
+
185
+ renderItem = (item = this.state.item) => {
186
+ return (
187
+ <Row className='mg1t'>
188
+ <Col span={15}>
189
+ <InputGroup>
190
+ <Input
191
+ value={item.name}
192
+ readOnly
193
+ className='width-40'
194
+ title={item.name}
195
+ placeholder={t('quickCommandName')}
196
+ />
197
+ <Input
198
+ value={item.command}
199
+ readOnly
200
+ className='width-60'
201
+ title={item.command}
202
+ />
203
+ </InputGroup>
204
+ </Col>
205
+ <Col span={3}>
206
+ <Tooltip title={t('inputOnly')}>
207
+ <Switch
208
+ checked={!!item.inputOnly}
209
+ title={t('inputOnly')}
210
+ readOnly
211
+ />
212
+ </Tooltip>
213
+ </Col>
214
+ <Col span={6}>
215
+ <EditOutlined className='pointer font16 mg1x' onClick={this.handleEdit} />
216
+ <CloseCircleOutlined className='pointer font16' onClick={this.handleDel} />
217
+ </Col>
218
+ </Row>
219
+ )
220
+ }
221
+
222
+ render () {
223
+ if (this.state.edit) {
224
+ return this.renderForm()
225
+ }
226
+ return this.renderItem()
227
+ }
228
+ }
@@ -0,0 +1,104 @@
1
+ /**
2
+ * bookmark form
3
+ */
4
+ import {
5
+ Button,
6
+ Input,
7
+ Upload,
8
+ AutoComplete,
9
+ Form
10
+ } from 'antd'
11
+ import { formItemLayout } from '../../common/form-layout'
12
+ import { uniqBy } from 'lodash-es'
13
+ import './bookmark-form.styl'
14
+
15
+ const { TextArea } = Input
16
+ const FormItem = Form.Item
17
+ const { prefix } = window
18
+ const e = prefix('form')
19
+
20
+ export default function renderAuth (props) {
21
+ const {
22
+ store,
23
+ form,
24
+ authType
25
+ } = props
26
+ if (authType === 'password') {
27
+ const opts = {
28
+ options: uniqBy(
29
+ store.getBookmarks()
30
+ .filter(d => d.password),
31
+ (d) => d.password
32
+ )
33
+ .map(d => {
34
+ return {
35
+ label: `${d.title ? `(${d.title})` : ''}${d.username || ''}:${d.host}-******`,
36
+ value: d.password
37
+ }
38
+ }),
39
+ placeholder: e('password'),
40
+ allowClear: false
41
+ }
42
+ return (
43
+ <FormItem
44
+ {...formItemLayout}
45
+ label={e('password')}
46
+ name='password'
47
+ hasFeedback
48
+ rules={[{
49
+ max: 1024, message: '1024 chars max'
50
+ }]}
51
+ >
52
+ <AutoComplete
53
+ {...opts}
54
+ >
55
+ <Input.Password />
56
+ </AutoComplete>
57
+ </FormItem>
58
+ )
59
+ }
60
+ return [
61
+ <FormItem
62
+ {...formItemLayout}
63
+ label={e('privateKey')}
64
+ hasFeedback
65
+ key='privateKey'
66
+ className='mg1b'
67
+ rules={[{
68
+ max: 13000, message: '13000 chars max'
69
+ }]}
70
+ >
71
+ <FormItem noStyle name='privateKey'>
72
+ <TextArea
73
+ placeholder={e('privateKeyDesc')}
74
+ rows={1}
75
+ />
76
+ </FormItem>
77
+ <Upload
78
+ beforeUpload={file => props.beforeUpload(file, form)}
79
+ fileList={[]}
80
+ >
81
+ <Button
82
+ type='dashed'
83
+ className='mg2b mg1t'
84
+ >
85
+ {e('importFromFile')}
86
+ </Button>
87
+ </Upload>
88
+ </FormItem>,
89
+ <FormItem
90
+ key='passphrase'
91
+ {...formItemLayout}
92
+ label={e('passphrase')}
93
+ name='passphrase'
94
+ hasFeedback
95
+ rules={[{
96
+ max: 1024, message: '1024 chars max'
97
+ }]}
98
+ >
99
+ <Input.Password
100
+ placeholder={e('passphraseDesc')}
101
+ />
102
+ </FormItem>
103
+ ]
104
+ }
@@ -0,0 +1,229 @@
1
+ import {
2
+ Form,
3
+ InputNumber,
4
+ Input,
5
+ Radio,
6
+ Button,
7
+ Table
8
+ } from 'antd'
9
+ import { formItemLayout, tailFormItemLayout } from '../../common/form-layout'
10
+ import {
11
+ MinusCircleFilled,
12
+ PlusOutlined
13
+ } from '@ant-design/icons'
14
+ import RenderAuth from './render-auth-ssh'
15
+ import uid from '../../common/uid'
16
+ import {
17
+ authTypeMap
18
+ } from '../../common/constants'
19
+ import { useState } from 'react'
20
+
21
+ const FormItem = Form.Item
22
+ const RadioButton = Radio.Button
23
+ const RadioGroup = Radio.Group
24
+ const { prefix } = window
25
+ const f = prefix('form')
26
+ const m = prefix('menu')
27
+
28
+ export default function renderConnectionHopping (props) {
29
+ const {
30
+ store,
31
+ form,
32
+ formData
33
+ } = props
34
+ const [formChild] = Form.useForm()
35
+ const [initialValues, editState] = useState({
36
+ port: 22,
37
+ authType: authTypeMap.password
38
+ })
39
+ const [list, setList] = useState(formData.connectionHoppings || [])
40
+ function onChangeAuthType (authType) {
41
+ editState(old => {
42
+ return {
43
+ ...old,
44
+ authType
45
+ }
46
+ })
47
+ }
48
+ function onSubmit () {
49
+ formChild.submit()
50
+ }
51
+ function handleFinish (data) {
52
+ const nd = {
53
+ ...data,
54
+ id: uid()
55
+ }
56
+ const v = [
57
+ ...form.getFieldValue('connectionHoppings'),
58
+ nd
59
+ ]
60
+ form.setFieldsValue({
61
+ connectionHoppings: v
62
+ })
63
+ setList(old => {
64
+ return [
65
+ ...old,
66
+ data
67
+ ]
68
+ })
69
+ formChild.resetFields()
70
+ }
71
+ const authTypes = Object.keys(authTypeMap).map(k => {
72
+ return k
73
+ })
74
+
75
+ function remove (id) {
76
+ setList(old => {
77
+ return old.filter(i => i.id !== id)
78
+ })
79
+ const v = form.getFieldValue('connectionHoppings').filter(i => i.id !== id)
80
+ form.setFieldsValue({
81
+ connectionHoppings: v
82
+ })
83
+ formChild.resetFields()
84
+ }
85
+ const cols = [
86
+ {
87
+ title: 'NO.',
88
+ dataIndex: 'index',
89
+ key: 'index',
90
+ render: (k) => k
91
+ }, {
92
+ title: f('connectionHopping'),
93
+ key: 'connectionHopping',
94
+ render: (k, item) => {
95
+ const pass = item.password ? ':*****' : ''
96
+ const ph = item.passphase ? '(passphase:*****)' : ''
97
+ const pk = item.privateKey ? '(privateKey:*****)' : ''
98
+ return <span>{item.username}{pass}@{item.host}:{item.port}{pk}{ph}</span>
99
+ }
100
+ }, {
101
+ title: m('del'),
102
+ key: 'op',
103
+ dataIndex: 'id',
104
+ render: (id) => {
105
+ return (
106
+ <MinusCircleFilled
107
+ className='pointer'
108
+ onClick={() => remove(id)}
109
+ />
110
+ )
111
+ }
112
+ }
113
+ ]
114
+
115
+ function renderList () {
116
+ return (
117
+ <FormItem {...tailFormItemLayout}>
118
+ <Table
119
+ columns={cols}
120
+ className='mg3b'
121
+ pagination={false}
122
+ size='small'
123
+ dataSource={list.map((d, i) => {
124
+ return {
125
+ ...d,
126
+ index: i + 1
127
+ }
128
+ })}
129
+ />
130
+ </FormItem>
131
+ )
132
+ }
133
+
134
+ return (
135
+ <div>
136
+ <FormItem
137
+ name='connectionHoppings'
138
+ className='hide'
139
+ >
140
+ <Input />
141
+ </FormItem>
142
+ <Form
143
+ form={formChild}
144
+ onFinish={handleFinish}
145
+ initialValues={initialValues}
146
+ >
147
+ {renderList()}
148
+ <FormItem
149
+ {...formItemLayout}
150
+ label={f('host')}
151
+ hasFeedback
152
+ rules={[{
153
+ max: 520, message: '520 chars max'
154
+ }, {
155
+ required: true, message: 'host required'
156
+ }]}
157
+ normalize={props.trim}
158
+ name='host'
159
+ >
160
+ <Input />
161
+ </FormItem>
162
+ <FormItem
163
+ {...formItemLayout}
164
+ label={f('username')}
165
+ hasFeedback
166
+ name='username'
167
+ rules={[{
168
+ max: 128, message: '128 chars max'
169
+ }]}
170
+ normalize={props.trim}
171
+ >
172
+ <Input />
173
+ </FormItem>
174
+ <FormItem
175
+ {...tailFormItemLayout}
176
+ className='mg1b'
177
+ name='authType'
178
+ >
179
+ <RadioGroup
180
+ size='small'
181
+ onChange={onChangeAuthType}
182
+ buttonStyle='solid'
183
+ >
184
+ {
185
+ authTypes.map(t => {
186
+ return (
187
+ <RadioButton value={t} key={t}>
188
+ {f(t)}
189
+ </RadioButton>
190
+ )
191
+ })
192
+ }
193
+ </RadioGroup>
194
+ </FormItem>
195
+ <FormItem
196
+ {...formItemLayout}
197
+ label={f('port')}
198
+ hasFeedback
199
+ name='port'
200
+ rules={[{
201
+ required: true, message: 'port required'
202
+ }]}
203
+ >
204
+ <InputNumber
205
+ placeholder={f('port')}
206
+ min={1}
207
+ max={65535}
208
+ step={1}
209
+ />
210
+ </FormItem>
211
+ <RenderAuth
212
+ form={formChild}
213
+ store={store}
214
+ authType={initialValues.authType}
215
+ />
216
+ <FormItem {...tailFormItemLayout} className='mg60b'>
217
+ <Button
218
+ type='default'
219
+ htmlType='button'
220
+ icon={<PlusOutlined />}
221
+ onClick={onSubmit}
222
+ >
223
+ {f('connectionHopping')}
224
+ </Button>
225
+ </FormItem>
226
+ </Form>
227
+ </div>
228
+ )
229
+ }
@@ -0,0 +1,88 @@
1
+ import {
2
+ Form,
3
+ InputNumber,
4
+ Space,
5
+ Button,
6
+ Input
7
+ } from 'antd'
8
+ import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'
9
+ import { formItemLayout } from '../../common/form-layout'
10
+
11
+ const FormItem = Form.Item
12
+ const FormList = Form.List
13
+ const { prefix } = window
14
+ const e = prefix('form')
15
+
16
+ export default function renderRunScripts () {
17
+ function renderItem (field, i, add, remove) {
18
+ return (
19
+ <Space
20
+ align='center'
21
+ key={field.key}
22
+ >
23
+ <FormItem
24
+ label=''
25
+ name={[field.name, 'delay']}
26
+ required
27
+ >
28
+ <InputNumber
29
+ min={1}
30
+ step={1}
31
+ max={65535}
32
+ addonBefore={e('loginScriptDelay')}
33
+ className='compact-input'
34
+ />
35
+ </FormItem>
36
+ <FormItem
37
+ label=''
38
+ name={[field.name, 'script']}
39
+ required
40
+ className='mg2x'
41
+ >
42
+ <Input.TextArea
43
+ rows={1}
44
+ placeholder={e('loginScript')}
45
+ className='compact-input'
46
+ />
47
+ </FormItem>
48
+ <Button
49
+ icon={<MinusCircleOutlined />}
50
+ onClick={() => remove(field.name)}
51
+ className='mg24b'
52
+ />
53
+ </Space>
54
+ )
55
+ }
56
+
57
+ return [
58
+ <FormItem {...formItemLayout} key='runScripts' label={e('loginScript')}>
59
+ <FormList
60
+ name='runScripts'
61
+ >
62
+ {
63
+ (fields, { add, remove }, { errors }) => {
64
+ return (
65
+ <div>
66
+ {
67
+ fields.map((field, i) => {
68
+ return renderItem(field, i, add, remove)
69
+ })
70
+ }
71
+ <FormItem>
72
+ <Button
73
+ type='dashed'
74
+ onClick={() => add()}
75
+ block
76
+ icon={<PlusOutlined />}
77
+ >
78
+ {e('loginScript')}
79
+ </Button>
80
+ </FormItem>
81
+ </div>
82
+ )
83
+ }
84
+ }
85
+ </FormList>
86
+ </FormItem>
87
+ ]
88
+ }