@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,233 @@
1
+ /**
2
+ * quick commands footer selection wrap
3
+ */
4
+
5
+ import { Component } from '../common/react-subx'
6
+ import { isWin, quickCommandLabelsLsKey } from '../../common/constants'
7
+ import { find, sortBy } from 'lodash-es'
8
+ import { Button, Input, Select, Space } from 'antd'
9
+ import * as ls from '../../common/safe-local-storage'
10
+ import copy from 'json-deep-copy'
11
+ import CmdItem from './quick-command-item'
12
+ import {
13
+ EditOutlined,
14
+ CloseCircleOutlined,
15
+ PushpinOutlined
16
+ } from '@ant-design/icons'
17
+ import classNames from 'classnames'
18
+ import './qm.styl'
19
+
20
+ const { prefix } = window
21
+ const e = prefix('quickCommands')
22
+ const addQuickCommands = 'addQuickCommands'
23
+ const { Option } = Select
24
+
25
+ export default class QuickCommandsFooterBox extends Component {
26
+ state = {
27
+ keyword: '',
28
+ labels: ls.getItemJSON(quickCommandLabelsLsKey, [])
29
+ }
30
+
31
+ handleMouseLeave = () => {
32
+ this.timer = setTimeout(() => {
33
+ this.toggle(false)
34
+ }, 500)
35
+ }
36
+
37
+ handleMouseEnter = () => {
38
+ clearTimeout(this.timer)
39
+ }
40
+
41
+ toggle = (openQuickCommandBar) => {
42
+ this.props.store.openQuickCommandBar = openQuickCommandBar
43
+ }
44
+
45
+ handleTogglePinned = () => {
46
+ this.props.store.pinnedQuickCommandBar = !this.props.store.pinnedQuickCommandBar
47
+ }
48
+
49
+ handleSelect = (id) => {
50
+ const {
51
+ store
52
+ } = this.props
53
+ if (id === addQuickCommands) {
54
+ store.handleOpenQuickCommandsSetting()
55
+ } else {
56
+ const qm = find(
57
+ this.props.store.currentQuickCommands,
58
+ a => a.id === id
59
+ )
60
+ if (qm && qm.command) {
61
+ const { runQuickCommand } = this.props.store
62
+ const realCmd = isWin
63
+ ? qm.command.replace(/\n/g, '\n\r')
64
+ : qm.command
65
+ runQuickCommand(realCmd, qm.inputOnly)
66
+ store.editQuickCommand(qm.id, {
67
+ clickCount: ((qm.clickCount || 0) + 1)
68
+ })
69
+ }
70
+ }
71
+ }
72
+
73
+ handleClose = () => {
74
+ this.props.store.pinnedQuickCommandBar = false
75
+ this.props.store.openQuickCommandBar = false
76
+ }
77
+
78
+ handleChange = e => {
79
+ this.setState({
80
+ keyword: e.target.value
81
+ })
82
+ }
83
+
84
+ handleChangeLabels = (v) => {
85
+ ls.setItemJSON(quickCommandLabelsLsKey, v)
86
+ this.setState({
87
+ labels: v
88
+ })
89
+ }
90
+
91
+ filterFunc = (v, opt) => {
92
+ const c = opt.props.children.toLowerCase()
93
+ const m = opt.props.cmd.toLowerCase()
94
+ const vv = v.toLowerCase()
95
+ return c.includes(vv) || m.includes(vv)
96
+ }
97
+
98
+ renderNoCmd = () => {
99
+ return (
100
+ <div className='pd1'>
101
+ <Button
102
+ type='primary'
103
+ onClick={this.props.store.handleOpenQuickCommandsSetting}
104
+ >
105
+ {e(addQuickCommands)}
106
+ </Button>
107
+ </div>
108
+ )
109
+ }
110
+
111
+ renderItem = (item) => {
112
+ return (
113
+ <CmdItem
114
+ item={item}
115
+ key={item.id}
116
+ onSelect={this.handleSelect}
117
+ />
118
+ )
119
+ }
120
+
121
+ renderTag = tag => {
122
+ return (
123
+ <Option
124
+ value={tag}
125
+ key={'tag-' + tag}
126
+ >
127
+ {tag}
128
+ </Option>
129
+ )
130
+ }
131
+
132
+ sortArray (array, keyword, labels) {
133
+ return sortBy(array, [
134
+ // First, sort by the keyword match
135
+ (obj) => !(keyword && obj.name.toLowerCase().includes(keyword)),
136
+ // Then, sort by the label match
137
+ (obj) => !labels.some((label) => obj.labels.includes(label)),
138
+ // Finally, sort by the clickCount
139
+ (obj) => -(obj.clickCount || 0)
140
+ ])
141
+ }
142
+
143
+ render () {
144
+ const {
145
+ openQuickCommandBar,
146
+ pinnedQuickCommandBar
147
+ } = this.props.store
148
+ if (!openQuickCommandBar && !pinnedQuickCommandBar) {
149
+ return null
150
+ }
151
+ const all = copy(this.props.store.currentQuickCommands)
152
+ if (!all.length) {
153
+ return this.renderNoCmd()
154
+ }
155
+ const keyword = this.state.keyword.toLowerCase()
156
+ const { labels } = this.state
157
+ const filtered = this.sortArray(all, keyword, labels)
158
+ .map(d => {
159
+ return {
160
+ ...d,
161
+ nameMatch: keyword && d.name.toLowerCase().includes(keyword),
162
+ labelMatch: labels.some((label) => d.labels.includes(label))
163
+ }
164
+ })
165
+ const sprops = {
166
+ value: labels,
167
+ mode: 'multiple',
168
+ onChange: this.handleChangeLabels,
169
+ placeholder: e('labels'),
170
+ className: 'iblock',
171
+ style: {
172
+ minWidth: '100px'
173
+ }
174
+ }
175
+ const tp = pinnedQuickCommandBar
176
+ ? 'primary'
177
+ : 'ghost'
178
+ const cls = classNames(
179
+ 'qm-list-wrap',
180
+ { 'fil-label': !!this.state.labels.length },
181
+ { 'fil-keyword': !!keyword }
182
+ )
183
+ return (
184
+ <div
185
+ className='qm-wrap-tooltip'
186
+ onMouseLeave={this.handleMouseLeave}
187
+ onMouseEnter={this.handleMouseEnter}
188
+ >
189
+ <div className='pd2'>
190
+ <div className='pd2b fix'>
191
+ <span className='fleft'>
192
+ <Input.Search
193
+ value={this.state.keyword}
194
+ onChange={this.handleChange}
195
+ placeholder=''
196
+ className='iblock'
197
+ />
198
+ </span>
199
+ <span className='fleft mg1l'>
200
+ <Select
201
+ {...sprops}
202
+ >
203
+ {this.props.store.quickCommandTags.map(
204
+ this.renderTag
205
+ )}
206
+ </Select>
207
+ </span>
208
+ <span className='fright'>
209
+ <Space.Compact>
210
+ <Button
211
+ onClick={this.handleTogglePinned}
212
+ icon={<PushpinOutlined />}
213
+ type={tp}
214
+ />
215
+ <Button
216
+ onClick={this.props.store.handleOpenQuickCommandsSetting}
217
+ icon={<EditOutlined />}
218
+ />
219
+ <Button
220
+ onClick={this.handleClose}
221
+ icon={<CloseCircleOutlined />}
222
+ />
223
+ </Space.Compact>
224
+ </span>
225
+ </div>
226
+ <div className={cls}>
227
+ {filtered.map(this.renderItem)}
228
+ </div>
229
+ </div>
230
+ </div>
231
+ )
232
+ }
233
+ }
@@ -0,0 +1,119 @@
1
+ import { Button, Input, Switch, Form, message, Select } from 'antd'
2
+ import copy from 'json-deep-copy'
3
+ import generate from '../../common/uid'
4
+ import InputAutoFocus from '../common/input-auto-focus'
5
+ const { TextArea } = Input
6
+ const FormItem = Form.Item
7
+ const { Option } = Select
8
+ const { prefix } = window
9
+ const e = prefix('form')
10
+ const t = prefix('quickCommands')
11
+ const s = prefix('setting')
12
+
13
+ export default function QuickCommandForm (props) {
14
+ const [form] = Form.useForm()
15
+ const { autofocustrigger, quickCommandTags = [] } = props.store
16
+ async function handleSubmit (res) {
17
+ const { formData } = props
18
+ const {
19
+ name,
20
+ command,
21
+ inputOnly,
22
+ labels
23
+ } = res
24
+ const update = copy({
25
+ name,
26
+ command,
27
+ inputOnly,
28
+ labels
29
+ })
30
+ const update1 = {
31
+ ...update,
32
+ id: generate()
33
+ }
34
+ if (formData.id) {
35
+ props.store.editQuickCommand(formData.id, update)
36
+ } else {
37
+ props.store.addQuickCommand(update1)
38
+ props.store.setSettingItem({
39
+ id: '',
40
+ name: t('newQuickCommand')
41
+ })
42
+ }
43
+ message.success(s('saved'))
44
+ }
45
+ const initialValues = props.formData
46
+ if (!initialValues.labels) {
47
+ initialValues.labels = []
48
+ }
49
+ return (
50
+ <Form
51
+ form={form}
52
+ onFinish={handleSubmit}
53
+ className='form-wrap pd2l'
54
+ layout='vertical'
55
+ initialValues={initialValues}
56
+ >
57
+ <FormItem
58
+ label={t('quickCommandName')}
59
+ rules={[{
60
+ max: 60, message: '60 chars max'
61
+ }, {
62
+ required: true, message: 'name required'
63
+ }]}
64
+ hasFeedback
65
+ name='name'
66
+ >
67
+ <InputAutoFocus
68
+ selectall='yes'
69
+ autofocustrigger={autofocustrigger}
70
+ />
71
+ </FormItem>
72
+ <FormItem
73
+ name='command'
74
+ label={t('quickCommand')}
75
+ rules={[{
76
+ max: 5000, message: '5000 chars max'
77
+ }, {
78
+ required: true, message: 'command required'
79
+ }]}
80
+ >
81
+ <TextArea rows={3} />
82
+ </FormItem>
83
+ <FormItem
84
+ name='labels'
85
+ label={t('label')}
86
+ >
87
+ <Select
88
+ mode='tags'
89
+ >
90
+ {
91
+ quickCommandTags.map(q => {
92
+ return (
93
+ <Option value={q} key={'qmt-' + q}>
94
+ {q}
95
+ </Option>
96
+ )
97
+ })
98
+ }
99
+ </Select>
100
+ </FormItem>
101
+ <FormItem
102
+ label={t('inputOnly')}
103
+ name='inputOnly'
104
+ valuePropName='checked'
105
+ >
106
+ <Switch />
107
+ </FormItem>
108
+ <FormItem>
109
+ <p>
110
+ <Button
111
+ type='dashed'
112
+ htmlType='submit'
113
+ >{e('save')}
114
+ </Button>
115
+ </p>
116
+ </FormItem>
117
+ </Form>
118
+ )
119
+ }
@@ -0,0 +1,33 @@
1
+ import { PureComponent } from 'react'
2
+ import QuickCommandForm from './quick-commands-form-elem'
3
+ import { LoadingOutlined } from '@ant-design/icons'
4
+
5
+ export default class QuickCommandFormIndex extends PureComponent {
6
+ state = {
7
+ ready: false
8
+ }
9
+
10
+ componentDidMount () {
11
+ this.timer = setTimeout(() => {
12
+ this.setState({
13
+ ready: true
14
+ })
15
+ }, 200)
16
+ }
17
+
18
+ componentWillUnmount () {
19
+ clearTimeout(this.timer)
20
+ }
21
+
22
+ render () {
23
+ const { ready } = this.state
24
+ if (!ready) {
25
+ return (
26
+ <div className='pd3 aligncenter'>
27
+ <LoadingOutlined />
28
+ </div>
29
+ )
30
+ }
31
+ return <QuickCommandForm {...this.props} />
32
+ }
33
+ }
@@ -0,0 +1,128 @@
1
+ /**
2
+ * quick command list render
3
+ */
4
+
5
+ import List from '../setting-panel/list'
6
+ import { PlusOutlined } from '@ant-design/icons'
7
+ import { Select } from 'antd'
8
+ import classnames from 'classnames'
9
+ import highlight from '../common/highlight'
10
+ import QmTransport from './quick-command-transport'
11
+
12
+ const { Option } = Select
13
+ const { prefix } = window
14
+ const q = prefix('quickCommands')
15
+
16
+ export default class QuickCommandsList extends List {
17
+ del = (item, e) => {
18
+ e.stopPropagation()
19
+ this.props.store.delQuickCommand(item)
20
+ }
21
+
22
+ onClickItem = (item) => {
23
+ this.props.onClickItem(item)
24
+ }
25
+
26
+ handleChange = v => {
27
+ this.setState({
28
+ labels: v
29
+ })
30
+ }
31
+
32
+ getLabels = () => {
33
+ return this.props.store.quickCommandTags
34
+ }
35
+
36
+ renderItem = (item, i) => {
37
+ const { activeItemId } = this.props
38
+ const { name, id } = item
39
+ const cls = classnames(
40
+ 'item-list-unit theme-item',
41
+ {
42
+ active: activeItemId === id
43
+ }
44
+ )
45
+ let title = name
46
+ title = highlight(
47
+ title,
48
+ this.state.keyword
49
+ )
50
+ return (
51
+ <div
52
+ key={i + id}
53
+ className={cls}
54
+ onClick={() => this.onClickItem(item)}
55
+ >
56
+ <div className='elli pd1y pd2x' title={name}>
57
+ {
58
+ !id
59
+ ? <PlusOutlined className='mg1r' />
60
+ : null
61
+ }
62
+ {title}
63
+ </div>
64
+ {this.renderDelBtn(item)}
65
+ </div>
66
+ )
67
+ }
68
+
69
+ renderTransport = () => {
70
+ return (
71
+ <QmTransport
72
+ store={this.props.store}
73
+ />
74
+ )
75
+ }
76
+
77
+ renderLabels = () => {
78
+ const arr = this.getLabels()
79
+ const props = {
80
+ placeholder: q('labels'),
81
+ mode: 'multiple',
82
+ value: this.state.labels,
83
+ onChange: this.handleChange,
84
+ style: {
85
+ width: '100%'
86
+ }
87
+ }
88
+ return (
89
+ <div className='pd1b'>
90
+ <Select
91
+ {...props}
92
+ >
93
+ {
94
+ arr.map(b => {
95
+ return (
96
+ <Option
97
+ key={'qml-' + b}
98
+ value={b}
99
+ >
100
+ {b}
101
+ </Option>
102
+ )
103
+ })
104
+ }
105
+ </Select>
106
+ </div>
107
+ )
108
+ }
109
+
110
+ filter = list => {
111
+ const { keyword, labels } = this.state
112
+ const f = keyword
113
+ ? list.filter((item) => {
114
+ const n = (item.name || '').toLowerCase()
115
+ const c = (item.command || '').toLowerCase()
116
+ const k = keyword.toLowerCase()
117
+ return n.includes(k) || c.includes(k)
118
+ })
119
+ : list
120
+ return labels.length
121
+ ? f.filter(d => {
122
+ return labels.some(label => {
123
+ return (d.labels || []).includes(label)
124
+ })
125
+ })
126
+ : f
127
+ }
128
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * quick commands footer selection
3
+ */
4
+
5
+ import { PureComponent } from 'react'
6
+ import { Button } from 'antd'
7
+ import './qm.styl'
8
+
9
+ const { prefix } = window
10
+ const e = prefix('quickCommands')
11
+
12
+ export default class QuickCommandsFooter extends PureComponent {
13
+ handleOpen = () => {
14
+ this.timer = setTimeout(this.act, 500)
15
+ }
16
+
17
+ act = () => {
18
+ window.store.openQuickCommandBar = true
19
+ }
20
+
21
+ handleMouseLeave = () => {
22
+ clearTimeout(this.timer)
23
+ }
24
+
25
+ render () {
26
+ return (
27
+ <div className='fleft relative'>
28
+ <Button
29
+ size='small'
30
+ onMouseEnter={this.handleOpen}
31
+ onMouseLeave={this.handleMouseLeave}
32
+ >
33
+ {e('quickCommands')}
34
+ </Button>
35
+ </div>
36
+ )
37
+ }
38
+ }