@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,445 @@
1
+ import { Component } from '../common/react-subx'
2
+ import Session from './session'
3
+ import { findIndex, pick } from 'lodash-es'
4
+ import classNames from 'classnames'
5
+ import generate from '../../common/uid'
6
+ import copy from 'json-deep-copy'
7
+ import wait from '../../common/wait'
8
+ import Tabs from '../tabs'
9
+ import {
10
+ commonActions,
11
+ tabActions,
12
+ termInitId,
13
+ paneMap,
14
+ statusMap
15
+ } from '../../common/constants'
16
+ import newTerm, { updateCount } from '../../common/new-terminal'
17
+ import keyControlPress from '../../common/key-control-pressed'
18
+ import keyPressed from '../../common/key-pressed'
19
+ import postMsg from '../../common/post-msg'
20
+ import TermSearch from '../terminal/term-search'
21
+ import Footer from '../footer/footer-entry'
22
+ import QuickCommandsFooterBox from '../quick-commands/quick-commands-box'
23
+ import LogoElem from '../common/logo-elem'
24
+ import { Button } from 'antd'
25
+ import toSimpleObj from '../../common/to-simple-obj'
26
+
27
+ const { prefix } = window
28
+ const e = prefix('tabs')
29
+ const c = prefix('control')
30
+
31
+ export default class Sessions extends Component {
32
+ state = {
33
+ tabs: [],
34
+ currentTabId: ''
35
+ }
36
+
37
+ componentDidMount () {
38
+ this.watch()
39
+ this.initShortcuts()
40
+ }
41
+
42
+ initShortcuts () {
43
+ window.addEventListener('keydown', e => {
44
+ if (keyControlPress(e) && keyPressed(e, 'w')) {
45
+ e.stopPropagation()
46
+ if (this.state.tabs.length > 1) {
47
+ this.delTab(
48
+ this.state.currentTabId
49
+ )
50
+ }
51
+ }
52
+ })
53
+ }
54
+
55
+ watch = () => {
56
+ window.addEventListener('message', this.onEvent)
57
+ }
58
+
59
+ updateStoreTabs = (tabs) => {
60
+ postMsg({
61
+ action: commonActions.updateStore,
62
+ func: 'setTabs',
63
+ args: [copy(tabs)]
64
+ })
65
+ }
66
+
67
+ updateStoreCurrentTabId = id => {
68
+ postMsg({
69
+ action: commonActions.updateStore,
70
+ value: id,
71
+ prop: 'currentTabId'
72
+ })
73
+ }
74
+
75
+ getCurrentTab = () => {
76
+ const {
77
+ currentTabId,
78
+ tabs
79
+ } = this.state
80
+ return tabs.find(t => t.id === currentTabId)
81
+ }
82
+
83
+ editTab = (id, update) => {
84
+ this.setState((oldState) => {
85
+ const tabs = copy(oldState.tabs)
86
+ const tab = tabs.find(t => t.id === id)
87
+ if (tab) {
88
+ Object.assign(tab, update)
89
+ }
90
+ this.updateStoreTabs(tabs)
91
+ return {
92
+ tabs
93
+ }
94
+ })
95
+ }
96
+
97
+ addTab = (
98
+ _tab,
99
+ _index
100
+ ) => {
101
+ this.setState((oldState) => {
102
+ const tabs = copy(oldState.tabs)
103
+ const index = typeof _index === 'undefined'
104
+ ? tabs.length
105
+ : _index
106
+ let tab = _tab
107
+ if (!tab) {
108
+ tab = newTerm()
109
+ } else {
110
+ updateCount(tab)
111
+ }
112
+ tabs.splice(index, 0, tab)
113
+ this.updateStoreTabs(tabs)
114
+ this.updateStoreCurrentTabId(tab.id)
115
+ return {
116
+ currentTabId: tab.id,
117
+ tabs
118
+ }
119
+ })
120
+ }
121
+
122
+ delTab = (id) => {
123
+ this.setState((oldState) => {
124
+ const tabs = copy(oldState.tabs)
125
+ const { currentTabId } = oldState
126
+ const up = {}
127
+ if (currentTabId === id) {
128
+ let i = findIndex(tabs, t => {
129
+ return t.id === id
130
+ })
131
+ i = i ? i - 1 : i + 1
132
+ const next = tabs[i] || {}
133
+ up.currentTabId = next.id
134
+ this.updateStoreCurrentTabId(next.id)
135
+ }
136
+ up.tabs = tabs.filter(t => {
137
+ return t.id !== id
138
+ })
139
+ this.updateStoreTabs(up.tabs)
140
+ return up
141
+ })
142
+ }
143
+
144
+ initFirstTab = () => {
145
+ const tab = newTerm()
146
+ tab.terminals = [{
147
+ id: termInitId,
148
+ position: 0
149
+ }]
150
+ this.addTab(tab)
151
+ }
152
+
153
+ processTerminals = (tab) => {
154
+ if (!tab.terminals) {
155
+ return tab
156
+ }
157
+ tab.terminals = tab.terminals.map(t => {
158
+ return {
159
+ ...t,
160
+ stateId: t.id,
161
+ id: generate()
162
+ }
163
+ })
164
+ }
165
+
166
+ reloadTab = async (tabToReload) => {
167
+ this.setState(async oldState => {
168
+ const tab = copy(
169
+ tabToReload
170
+ )
171
+ tab.pane = paneMap.terminal
172
+ this.processTerminals(tab)
173
+ const { id } = tab
174
+ const tabs = copy(oldState.tabs)
175
+ tab.id = generate()
176
+ tab.status = statusMap.processing
177
+ const index = findIndex(tabs, t => t.id === id)
178
+ this.addTab(tab, index)
179
+ await wait(30)
180
+ this.delTab(id)
181
+ })
182
+ }
183
+
184
+ onDuplicateTab = (tabToDup) => {
185
+ this.setState(oldState => {
186
+ const defaultStatus = statusMap.processing
187
+ let tab = copy(tabToDup)
188
+ updateCount(tab)
189
+ this.processTerminals(tab)
190
+ const tabs = copy(oldState.tabs)
191
+ const index = findIndex(
192
+ tabs,
193
+ d => d.id === tab.id
194
+ )
195
+ tab = {
196
+ ...tab,
197
+ status: defaultStatus,
198
+ id: generate(),
199
+ isTransporting: undefined
200
+ }
201
+ tab.pane = paneMap.terminal
202
+ this.addTab(tab, index + 1)
203
+ })
204
+ }
205
+
206
+ onChangeTabId = id => {
207
+ this.updateStoreCurrentTabId(id)
208
+ this.setState({
209
+ currentTabId: id
210
+ }, this.postChange)
211
+ }
212
+
213
+ setTabs = tabs => {
214
+ this.setState({
215
+ tabs
216
+ })
217
+ this.updateStoreTabs(tabs)
218
+ }
219
+
220
+ setOffline = () => {
221
+ this.setState(oldState => {
222
+ const tabs = copy(oldState.tabs)
223
+ .map(t => {
224
+ return {
225
+ ...t,
226
+ status: t.host ? statusMap.error : t.status
227
+ }
228
+ })
229
+ this.updateStoreTabs(tabs)
230
+ return {
231
+ tabs
232
+ }
233
+ })
234
+ }
235
+
236
+ updateTabsStatus = tabIds => {
237
+ this.setState(oldState => {
238
+ const tabs = copy(oldState.tabs).map(d => {
239
+ return {
240
+ ...d,
241
+ isTransporting: tabIds.includes(d.id)
242
+ }
243
+ })
244
+ this.updateStoreTabs(tabs)
245
+ return {
246
+ tabs
247
+ }
248
+ })
249
+ }
250
+
251
+ onEvent = e => {
252
+ const {
253
+ currentTabId,
254
+ action,
255
+ id,
256
+ update,
257
+ tab,
258
+ index,
259
+ tabIds
260
+ } = e.data || {}
261
+ if (
262
+ action === tabActions.changeCurrentTabId &&
263
+ currentTabId &&
264
+ currentTabId !== this.state.currentTabId
265
+ ) {
266
+ this.onChangeTabId(currentTabId)
267
+ } else if (action === tabActions.updateTabs) {
268
+ this.editTab(id, update)
269
+ } else if (action === tabActions.addTab) {
270
+ this.addTab(tab, index)
271
+ } else if (action === tabActions.initFirstTab) {
272
+ this.initFirstTab()
273
+ } else if (action === tabActions.delTab) {
274
+ this.delTab(id)
275
+ } else if (action === tabActions.setAllTabOffline) {
276
+ this.setOffline()
277
+ } else if (action === tabActions.updateTabsStatus) {
278
+ this.updateTabsStatus(tabIds)
279
+ }
280
+ }
281
+
282
+ postChange = () => {
283
+ this.props.store.triggerResize()
284
+ }
285
+
286
+ handleNewTab = () => {
287
+ this.props.store.initFirstTab()
288
+ }
289
+
290
+ handleNewSsh = () => {
291
+ this.props.store.onNewSsh()
292
+ }
293
+
294
+ renderNoSession = () => {
295
+ const props = {
296
+ style: {
297
+ height: this.props.store.height + 'px'
298
+ }
299
+ }
300
+ return (
301
+ <div className='no-sessions electerm-logo-bg' {...props}>
302
+ <Button
303
+ onClick={this.handleNewTab}
304
+ size='large'
305
+ className='mg1r mg1b'
306
+ >
307
+ {e('newTab')}
308
+ </Button>
309
+ <Button
310
+ onClick={this.handleNewSsh}
311
+ size='large'
312
+ className='mg1r mg1b'
313
+ >
314
+ {c('newBookmark')}
315
+ </Button>
316
+ <div className='pd3'>
317
+ <LogoElem />
318
+ </div>
319
+ </div>
320
+ )
321
+ }
322
+
323
+ renderSessions () {
324
+ const {
325
+ store, config
326
+ } = this.props
327
+ const {
328
+ currentTabId,
329
+ tabs
330
+ } = this.state
331
+ if (!tabs.length) {
332
+ return this.renderNoSession()
333
+ }
334
+ return tabs.map((tab) => {
335
+ const { id } = tab
336
+ const cls = classNames(
337
+ `session-wrap session-${id}`,
338
+ {
339
+ 'session-current': id === currentTabId
340
+ }
341
+ )
342
+ const sessProps = {
343
+ currentTabId,
344
+ tab: toSimpleObj(tab),
345
+ ...pick(store, [
346
+ 'height',
347
+ 'width',
348
+ 'activeTerminalId',
349
+ 'pinnedQuickCommandBar',
350
+ 'tabsHeight',
351
+ 'appPath',
352
+ 'topMenuHeight'
353
+ ]),
354
+ config,
355
+ ...pick(this, [
356
+ 'onChangeTabId',
357
+ 'onDuplicateTab',
358
+ 'reloadTab',
359
+ 'delTab',
360
+ 'addTab',
361
+ 'editTab'
362
+ ])
363
+ }
364
+ return (
365
+ <div className={cls} key={id}>
366
+ <Session
367
+ {...sessProps}
368
+ />
369
+ </div>
370
+ )
371
+ })
372
+ }
373
+
374
+ renderTabs = () => {
375
+ const {
376
+ store,
377
+ config
378
+ } = this.props
379
+ const {
380
+ tabs,
381
+ currentTabId
382
+ } = this.state
383
+ const tabsProps = {
384
+ currentTabId,
385
+ config,
386
+ ...pick(store, [
387
+ 'fileOperation',
388
+ 'height',
389
+ 'width',
390
+ 'activeTerminalId',
391
+ 'isMaximized'
392
+ ]),
393
+ tabs,
394
+ ...pick(this, [
395
+ 'setTabs',
396
+ 'onChangeTabId',
397
+ 'onDuplicateTab',
398
+ 'reloadTab',
399
+ 'delTab',
400
+ 'addTab',
401
+ 'editTab'
402
+ ])
403
+ }
404
+ return (
405
+ <Tabs
406
+ key='main-tabs'
407
+ {...tabsProps}
408
+ />
409
+ )
410
+ }
411
+
412
+ renderSessionsWrap = () => {
413
+ return (
414
+ <div className='sessions' key='main-sess'>
415
+ {this.renderSessions()}
416
+ </div>
417
+ )
418
+ }
419
+
420
+ render () {
421
+ const { store } = this.props
422
+ const currentTab = this.getCurrentTab()
423
+ const termProps = {
424
+ currentTab,
425
+ store
426
+ }
427
+ return [
428
+ this.renderTabs(),
429
+ this.renderSessionsWrap(),
430
+ <TermSearch
431
+ key='TermSearch'
432
+ {...termProps}
433
+ />,
434
+ <QuickCommandsFooterBox
435
+ key='QuickCommandsFooterBox'
436
+ store={store}
437
+ />,
438
+ <Footer
439
+ key='Footer'
440
+ store={store}
441
+ currentTab={currentTab}
442
+ />
443
+ ]
444
+ }
445
+ }
@@ -0,0 +1,148 @@
1
+ /**
2
+ * bookmark import/export
3
+ */
4
+
5
+ import { Component } from '../common/react-subx'
6
+ import {
7
+ DownloadOutlined,
8
+ UploadOutlined,
9
+ EditOutlined
10
+ } from '@ant-design/icons'
11
+ import { Upload, Button } from 'antd'
12
+ import download from '../../common/download'
13
+ import time from '../../../app/common/time'
14
+ import copy from 'json-deep-copy'
15
+ import { find, uniq, isEqual } from 'lodash-es'
16
+ import { fixBookmarks } from '../../common/db-fix'
17
+
18
+ const { prefix } = window
19
+ const f = prefix('form')
20
+ const t = prefix('terminalThemes')
21
+ const m = prefix('menu')
22
+
23
+ export default class BookmarkTransport extends Component {
24
+ beforeUpload = async (file) => {
25
+ const { store } = this.props
26
+ const txt = await window.fs.readFile(file.path)
27
+ try {
28
+ const content = JSON.parse(txt)
29
+ const {
30
+ bookmarkGroups: bookmarkGroups1,
31
+ bookmarks: bookmarks1
32
+ } = content
33
+ const bookmarkGroups = copy(store.getBookmarkGroups())
34
+ const bookmarks = copy(store.getBookmarks())
35
+ const bmTree = bookmarks.reduce((p, v) => {
36
+ return {
37
+ ...p,
38
+ [v.id]: v
39
+ }
40
+ }, {})
41
+ const bmgTree = bookmarkGroups.reduce((p, v) => {
42
+ return {
43
+ ...p,
44
+ [v.id]: v
45
+ }
46
+ }, {})
47
+ const add = []
48
+ const dbAdd = []
49
+ const updates = []
50
+ bookmarks1.forEach(bg => {
51
+ if (!bmTree[bg.id]) {
52
+ bookmarks.push(bg)
53
+ add.push(bg)
54
+ dbAdd.push({
55
+ db: 'bookmarks',
56
+ obj: bg
57
+ })
58
+ }
59
+ })
60
+ bookmarkGroups1.forEach(bg => {
61
+ if (!bmgTree[bg.id]) {
62
+ bookmarkGroups.push(bg)
63
+ dbAdd.push({
64
+ db: 'bookmarkGroups',
65
+ obj: bg
66
+ })
67
+ } else {
68
+ const bg1 = find(
69
+ bookmarkGroups,
70
+ b => b.id === bg.id
71
+ )
72
+ const old = copy(bg1.bookmarkIds)
73
+ bg1.bookmarkIds = uniq(
74
+ [
75
+ ...bg1.bookmarkIds,
76
+ ...bg.bookmarkIds
77
+ ]
78
+ )
79
+ if (!isEqual(bg1.bookmarkIds, old)) {
80
+ updates.push({
81
+ id: bg1.id,
82
+ db: 'bookmarkGroups',
83
+ update: {
84
+ bookmarkIds: bg1.bookmarkIds
85
+ }
86
+ })
87
+ }
88
+ }
89
+ })
90
+ store.setBookmarkGroups(bookmarkGroups)
91
+ store.setBookmarks(fixBookmarks(bookmarks))
92
+ store.batchDbAdd(dbAdd)
93
+ store.batchDbUpdate(updates)
94
+ } catch (e) {
95
+ store.onError(e)
96
+ }
97
+ return false
98
+ }
99
+
100
+ handleDownload = () => {
101
+ const { store } = this.props
102
+ const bookmarkGroups = store.getBookmarkGroups()
103
+ const bookmarks = store.getBookmarks()
104
+ const txt = JSON.stringify({
105
+ bookmarkGroups: copy(bookmarkGroups),
106
+ bookmarks: copy(bookmarks)
107
+ }, null, 2)
108
+ const stamp = time(undefined, 'YYYY-MM-DD-HH-mm-ss')
109
+ download('bookmarks-' + stamp + '.json', txt)
110
+ }
111
+
112
+ handleToggleEdit = () => {
113
+ this.props.store.bookmarkSelectMode = true
114
+ }
115
+
116
+ renderEdit () {
117
+ return (
118
+ <Button
119
+ icon={<EditOutlined />}
120
+ onClick={this.handleToggleEdit}
121
+ title={m('edit')}
122
+ key='edit-and-del'
123
+ />
124
+ )
125
+ }
126
+
127
+ render () {
128
+ return [
129
+ this.renderEdit(),
130
+ <Button
131
+ icon={<DownloadOutlined />}
132
+ onClick={this.handleDownload}
133
+ title={t('export')}
134
+ key='export'
135
+ />,
136
+ <Upload
137
+ beforeUpload={this.beforeUpload}
138
+ fileList={[]}
139
+ key='Upload'
140
+ >
141
+ <Button
142
+ icon={<UploadOutlined />}
143
+ title={f('importFromFile')}
144
+ />
145
+ </Upload>
146
+ ]
147
+ }
148
+ }
@@ -0,0 +1,14 @@
1
+ import TreeList from './tree-list'
2
+ import BookmarkTreeDelete from '../bookmark-form/tree-delete'
3
+
4
+ export default function BookmarkTreeList (props) {
5
+ return props.bookmarkSelectMode
6
+ ? (
7
+ <BookmarkTreeDelete
8
+ store={props.store}
9
+ />
10
+ )
11
+ : (
12
+ <TreeList {...props} />
13
+ )
14
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * two column layout, left column fixed with, right column auto width
3
+ */
4
+
5
+ export default function SettingCol (props) {
6
+ return (
7
+ <div className='setting-col'>
8
+ <div className='setting-row setting-row-left'>
9
+ {props.children[0]}
10
+ </div>
11
+ <div
12
+ className='setting-row setting-row-right'
13
+ >
14
+ {props.children[1]}
15
+ </div>
16
+ </div>
17
+ )
18
+ }