@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,222 @@
1
+ /**
2
+ * make child component resizable by drag the horizontal or vertical handle
3
+ * // todo: rerender check
4
+ */
5
+
6
+ import React from 'react'
7
+ import PropTypes from 'prop-types'
8
+ import classnames from 'classnames'
9
+ import { isNull, pick, isUndefined } from 'lodash-es'
10
+ import parseInt10 from '../../common/parse-int10'
11
+ import generate from '../../common/uid'
12
+ import memoizeOne from 'memoize-one'
13
+ import {
14
+ terminalSplitDirectionMap,
15
+ minTerminalWidth,
16
+ maxDragMove
17
+ } from '../../common/constants'
18
+ import './resize-wrap.styl'
19
+
20
+ export default class ResizeWrap extends React.Component {
21
+ static propTypes = {
22
+ direction: PropTypes.oneOf(['horizontal', 'vertical']).isRequired,
23
+ children: PropTypes.arrayOf(PropTypes.element).isRequired,
24
+ minWidth: PropTypes.number,
25
+ onEndDrag: PropTypes.func,
26
+ noResizeEvent: PropTypes.bool
27
+ }
28
+
29
+ getChildIds = (props = this.props) => {
30
+ return props.children.map(c => c.props.id)
31
+ }
32
+
33
+ getSplitIds = () => {
34
+ const len = this.props.children.length - 1
35
+ return this.getSplitIdsCache(len)
36
+ }
37
+
38
+ getSplitIdsCache = memoizeOne((len) => {
39
+ return new Array(len)
40
+ .fill(8).map(() => generate())
41
+ })
42
+
43
+ positionProps = [
44
+ 'width',
45
+ 'height',
46
+ 'left',
47
+ 'top'
48
+ ]
49
+
50
+ onDrag = (e) => {
51
+ const dom = e.target
52
+ const prev = dom.previousSibling
53
+ const next = dom.nextSibling
54
+ const { direction } = this.props
55
+ const { startPosition } = this
56
+ if (isNull(e.pageX)) {
57
+ return
58
+ }
59
+ const currentPosition = {
60
+ x: e.pageX,
61
+ y: e.pageY
62
+ }
63
+
64
+ const types = ['dom', 'prev', 'next']
65
+ const doms = [dom, prev, next]
66
+ const styles = doms.map(d => {
67
+ const { style } = d
68
+ const obj = pick(style, this.positionProps)
69
+ return Object.keys(obj).reduce((prev, k) => {
70
+ const v = obj[k]
71
+ return {
72
+ ...prev,
73
+ [k]: isUndefined(v)
74
+ ? v
75
+ : parseInt10(obj[k].replace('px', ''))
76
+ }
77
+ }, {})
78
+ })
79
+ let xDiff = currentPosition.x - startPosition.x
80
+ let yDiff = currentPosition.y - startPosition.y
81
+ if (Math.abs(xDiff) > maxDragMove) {
82
+ return
83
+ }
84
+ const prevStyle = styles[1]
85
+ const nextStyle = styles[2]
86
+ const minW = this.props.minWidth || minTerminalWidth
87
+ if (direction === terminalSplitDirectionMap.vertical) {
88
+ if (yDiff > 0 && yDiff > nextStyle.height - minW) {
89
+ yDiff = nextStyle.height - minW
90
+ } else if (yDiff < 0 && yDiff < -(prevStyle.height - minW)) {
91
+ yDiff = -(prevStyle.height - minW)
92
+ }
93
+ } else {
94
+ if (xDiff > 0 && xDiff > nextStyle.width - minW) {
95
+ xDiff = nextStyle.width - minW
96
+ } else if (xDiff < 0 && xDiff < -(prevStyle.width - minW)) {
97
+ xDiff = -(prevStyle.width - minW)
98
+ }
99
+ }
100
+ doms.forEach((d, i) => {
101
+ this.changePosition(d, direction, xDiff, yDiff, types[i], styles[i])
102
+ })
103
+ this.startPosition = currentPosition
104
+ }
105
+
106
+ onDragStart = (e) => {
107
+ this.startPosition = {
108
+ x: e.pageX,
109
+ y: e.pageY
110
+ }
111
+ }
112
+
113
+ changePosition = (
114
+ dom,
115
+ direction,
116
+ xDiff,
117
+ yDiff,
118
+ type,
119
+ style
120
+ ) => {
121
+ const realHeight = style.height
122
+ const realWidth = style.width
123
+ const realTop = style.top
124
+ const realLeft = style.left
125
+ if (type === 'prev' && direction === terminalSplitDirectionMap.vertical) {
126
+ dom.style.height = (realHeight + yDiff) + 'px'
127
+ } else if (type === 'prev') {
128
+ dom.style.width = (realWidth + xDiff) + 'px'
129
+ } else if (type === 'dom' && direction === terminalSplitDirectionMap.vertical) {
130
+ dom.style.top = (realTop + yDiff) + 'px'
131
+ } else if (type === 'dom') {
132
+ dom.style.left = (realLeft + xDiff) + 'px'
133
+ } else if (type === 'next' && direction === terminalSplitDirectionMap.vertical) {
134
+ dom.style.top = (realTop + yDiff) + 'px'
135
+ dom.style.height = (realHeight - yDiff) + 'px'
136
+ } else {
137
+ dom.style.width = (realWidth - xDiff) + 'px'
138
+ dom.style.left = (realLeft + xDiff) + 'px'
139
+ }
140
+ }
141
+
142
+ onDragEnd = () => {
143
+ const {
144
+ noResizeEvent,
145
+ onDragEnd
146
+ } = this.props
147
+ if (onDragEnd) {
148
+ onDragEnd()
149
+ }
150
+ if (noResizeEvent) {
151
+ return
152
+ }
153
+ window.dispatchEvent(new CustomEvent('resize'))
154
+ }
155
+
156
+ buildHandleComponent = (prevComponent, direction, index, tid) => {
157
+ const zIndex = this.props.children.length + 10
158
+ const cls = classnames(
159
+ `tw-${tid}`,
160
+ 'term-dragger',
161
+ `term-dragger-${index}`,
162
+ `term-dragger-${direction}`
163
+ )
164
+ const { left, top, width, height } = prevComponent.props
165
+ const style = direction === terminalSplitDirectionMap.vertical
166
+ ? {
167
+ left: 0,
168
+ right: 0,
169
+ zIndex,
170
+ top: top + height - 2
171
+ }
172
+ : {
173
+ top: 0,
174
+ bottom: 0,
175
+ zIndex,
176
+ left: left + width - 2
177
+ }
178
+ const props = {
179
+ style,
180
+ ...pick(this, [
181
+ 'onDoubleClick',
182
+ 'onDrag',
183
+ 'onDragStart',
184
+ 'onDragEnd'
185
+ ]),
186
+ className: cls,
187
+ draggable: true
188
+ }
189
+ return (
190
+ <span
191
+ key={tid}
192
+ {...props}
193
+ />
194
+ )
195
+ }
196
+
197
+ render () {
198
+ const {
199
+ children,
200
+ direction
201
+ } = this.props
202
+ const len = children.length
203
+ if (len < 2) {
204
+ return children
205
+ }
206
+ let splitIndex = 0
207
+ const splitIds = this.getSplitIds()
208
+ const newArr = children.reduce((prev, c, i) => {
209
+ let split = null
210
+ if (i !== len - 1) {
211
+ split = this.buildHandleComponent(c, direction, i, splitIds[splitIndex])
212
+ splitIndex++
213
+ }
214
+ return [
215
+ ...prev,
216
+ c,
217
+ split
218
+ ].filter(d => d)
219
+ }, [])
220
+ return newArr
221
+ }
222
+ }
@@ -0,0 +1,9 @@
1
+ .term-dragger
2
+ position absolute
3
+ z-index 1
4
+ .term-dragger-vertical
5
+ cursor ns-resize
6
+ height 5px
7
+ .term-dragger-horizontal
8
+ cursor ew-resize
9
+ width 5px
@@ -0,0 +1,9 @@
1
+ /**
2
+ * common search with clear icon
3
+ */
4
+
5
+ import { Input } from 'antd'
6
+
7
+ const { Search } = Input
8
+
9
+ export default Search
@@ -0,0 +1,27 @@
1
+ /**
2
+ * show item in folder
3
+ * // todo rerender check
4
+ */
5
+
6
+ import { memo } from 'react'
7
+ import { FolderOpenOutlined } from '@ant-design/icons'
8
+ // import { isMac } from '../../common/constants'
9
+ // import fs from '../../common/fs'
10
+
11
+ function onClick (e, href) {
12
+ e.preventDefault()
13
+ window.pre.showItemInFolder(href)
14
+ }
15
+
16
+ export default memo(props => {
17
+ const { to, children = '', ...rest } = props
18
+ return (
19
+ <a
20
+ href={to}
21
+ onClick={e => onClick(e, to)}
22
+ {...rest}
23
+ >
24
+ {children} <FolderOpenOutlined />
25
+ </a>
26
+ )
27
+ })
@@ -0,0 +1,15 @@
1
+ import { Component } from '../common/react-subx'
2
+ import BookmarksList from '../sidebar/bookmark-select'
3
+
4
+ export default class BookmarkSubMenu extends Component {
5
+ render () {
6
+ const { store } = this.props
7
+ return (
8
+ <div className='sub-context-menu bookmarks-sub-context-menu'>
9
+ <BookmarksList
10
+ store={store}
11
+ />
12
+ </div>
13
+ )
14
+ }
15
+ }
@@ -0,0 +1,340 @@
1
+ /**
2
+ * context menu
3
+ */
4
+ import React from 'react'
5
+ import './context-menu.styl'
6
+ import classnames from 'classnames'
7
+ import {
8
+ contextMenuHeight,
9
+ contextMenuPaddingTop,
10
+ contextMenuWidth,
11
+ commonActions
12
+ } from '../../common/constants'
13
+ import {
14
+ Popconfirm
15
+ } from 'antd'
16
+ import postMessage from '../../common/post-msg'
17
+ import { noop } from 'lodash-es'
18
+ import History from './history'
19
+ import Bookmark from './boomarks'
20
+ import Tabs from './tabs'
21
+ import Zoom from './zoom'
22
+ import IconHolder from './icon-holder'
23
+ import {
24
+ CodeOutlined,
25
+ BorderHorizontalOutlined,
26
+ SearchOutlined,
27
+ SelectOutlined,
28
+ SwitcherOutlined,
29
+ CheckOutlined,
30
+ CloudDownloadOutlined,
31
+ CloudUploadOutlined,
32
+ ArrowRightOutlined,
33
+ CheckSquareOutlined,
34
+ CloseCircleOutlined,
35
+ ContainerOutlined,
36
+ CopyOutlined,
37
+ EditOutlined,
38
+ EnterOutlined,
39
+ FileAddOutlined,
40
+ FileExcelOutlined,
41
+ FolderAddOutlined,
42
+ InfoCircleOutlined,
43
+ LockOutlined,
44
+ ReloadOutlined
45
+ } from '@ant-design/icons'
46
+
47
+ const { prefix } = window
48
+ const c = prefix('common')
49
+
50
+ export default class ContextMenu extends React.PureComponent {
51
+ state = {
52
+ items: [],
53
+ id: '',
54
+ pos: {
55
+ left: 0,
56
+ top: 0
57
+ },
58
+ className: 'context-menu'
59
+ }
60
+
61
+ componentDidMount () {
62
+ window.addEventListener('message', e => {
63
+ const {
64
+ type,
65
+ data
66
+ } = e.data || {}
67
+ if (
68
+ type === commonActions.closeContextMenu
69
+ ) {
70
+ this.closeContextMenu()
71
+ } else if (type === commonActions.openContextMenu) {
72
+ this.setOnCloseEvent()
73
+ this.setState(data)
74
+ }
75
+ })
76
+ }
77
+
78
+ setOnCloseEvent = () => {
79
+ const dom = document
80
+ .querySelector('.ant-drawer')
81
+ if (dom) {
82
+ dom.addEventListener('click', this.onTriggerClose)
83
+ }
84
+ document
85
+ .getElementById('outside-context')
86
+ .addEventListener('click', this.onTriggerClose)
87
+ }
88
+
89
+ onTriggerClose = () => {
90
+ this.closeContextMenu()
91
+ const dom = document
92
+ .querySelector('.ant-drawer')
93
+ if (dom) {
94
+ dom.removeEventListener('click', this.onTriggerClose)
95
+ }
96
+ document
97
+ .getElementById('outside-context')
98
+ .removeEventListener('click', this.onTriggerClose)
99
+ }
100
+
101
+ icons = {
102
+ CodeOutlined,
103
+ BorderHorizontalOutlined,
104
+ SearchOutlined,
105
+ SelectOutlined,
106
+ SwitcherOutlined,
107
+ IconHolder,
108
+ CheckOutlined,
109
+ CloudDownloadOutlined,
110
+ CloudUploadOutlined,
111
+ ArrowRightOutlined,
112
+ CheckSquareOutlined,
113
+ CloseCircleOutlined,
114
+ ContainerOutlined,
115
+ CopyOutlined,
116
+ EditOutlined,
117
+ EnterOutlined,
118
+ FileAddOutlined,
119
+ FileExcelOutlined,
120
+ FolderAddOutlined,
121
+ InfoCircleOutlined,
122
+ LockOutlined,
123
+ ReloadOutlined
124
+ }
125
+
126
+ modules = {
127
+ History,
128
+ Bookmark,
129
+ Tabs,
130
+ Zoom
131
+ }
132
+
133
+ closeContextMenu = () => {
134
+ this.setState({
135
+ id: '',
136
+ items: []
137
+ })
138
+ }
139
+
140
+ computePos = () => {
141
+ const {
142
+ pos,
143
+ items
144
+ } = this.state
145
+ const { length } = items
146
+ const count = length
147
+ ? items.filter(c => c.type !== 'hr').length
148
+ : 3
149
+ const countHr = length
150
+ ? items.filter(c => c.type === 'hr').length
151
+ : 3
152
+ let {
153
+ left,
154
+ top
155
+ } = pos
156
+ const {
157
+ topMenuHeight
158
+ } = this.props.store
159
+ const height = count * contextMenuHeight + contextMenuPaddingTop * 2 + countHr * 1
160
+ const maxHeight = Math.max(
161
+ window.innerHeight - topMenuHeight - top,
162
+ top - topMenuHeight
163
+ )
164
+ const shouldScroll = maxHeight < height
165
+ const startTop = top > (window.innerHeight - topMenuHeight) / 2
166
+ const realHeight = Math.min(maxHeight, height)
167
+ if (startTop) {
168
+ top = top - realHeight
169
+ }
170
+ if (window.innerWidth < left + contextMenuWidth + 10) {
171
+ left = left - contextMenuWidth
172
+ }
173
+ return {
174
+ pos: {
175
+ left: left + 'px',
176
+ top: top + 'px',
177
+ height: realHeight + 'px'
178
+ },
179
+ realHeight,
180
+ shouldScroll
181
+ }
182
+ }
183
+
184
+ onClick = (e, item) => {
185
+ const {
186
+ disabled,
187
+ func,
188
+ args,
189
+ noCloseMenu
190
+ } = item
191
+ if (disabled) {
192
+ return
193
+ }
194
+ postMessage({
195
+ action: commonActions.clickContextMenu,
196
+ id: this.state.id,
197
+ args,
198
+ func
199
+ })
200
+ if (!noCloseMenu) {
201
+ this.closeContextMenu()
202
+ }
203
+ }
204
+
205
+ renderSubText = (subText) => {
206
+ return subText
207
+ ? (<span className='context-sub-text'>{subText}</span>)
208
+ : null
209
+ }
210
+
211
+ renderSubMenu = (submenu) => {
212
+ if (!submenu) {
213
+ return
214
+ }
215
+ const Mod = this.modules[submenu]
216
+ return (
217
+ <Mod store={this.props.store} />
218
+ )
219
+ }
220
+
221
+ renderItem = (item, i) => {
222
+ const {
223
+ disabled,
224
+ icon,
225
+ text,
226
+ noAutoClose,
227
+ requireConfirm,
228
+ confirmTitle,
229
+ subText,
230
+ className,
231
+ type,
232
+ module,
233
+ submenu
234
+ } = item
235
+ if (type === 'hr') {
236
+ return <hr />
237
+ }
238
+ const baseCls = 'context-item'
239
+ if (module && this.modules[module]) {
240
+ const Mod = this.modules[module]
241
+ return (
242
+ <div className={baseCls}>
243
+ <Mod store={this.props.store} />
244
+ </div>
245
+ )
246
+ }
247
+ let iconElem = null
248
+ if (icon && this.icons[icon]) {
249
+ const Icon = this.icons[icon]
250
+ iconElem = <Icon />
251
+ }
252
+ const cls = classnames(
253
+ baseCls,
254
+ {
255
+ disabled
256
+ },
257
+ {
258
+ 'no-auto-close-context': noAutoClose
259
+ },
260
+ className,
261
+ {
262
+ 'with-sub-menu': submenu
263
+ }
264
+ )
265
+ const act = requireConfirm || submenu
266
+ ? noop
267
+ : (e) => this.onClick(e, item)
268
+ const unit = (
269
+ <div
270
+ key={`context-item-${i}-${text}`}
271
+ className={cls}
272
+ onClick={act}
273
+ >
274
+ {iconElem}{iconElem ? ' ' : ''}{text}
275
+ {
276
+ this.renderSubText(subText)
277
+ }
278
+ {
279
+ this.renderSubMenu(submenu)
280
+ }
281
+ </div>
282
+ )
283
+ if (!requireConfirm) {
284
+ return unit
285
+ }
286
+ const title = (
287
+ <div className='wordbreak'>{confirmTitle}</div>
288
+ )
289
+ return (
290
+ <Popconfirm
291
+ cancelText={c('cancel')}
292
+ key={`context-item-${i}-${text}`}
293
+ okText={c('ok')}
294
+ title={title}
295
+ onConfirm={(e) => this.onClick(e, item)}
296
+ >
297
+ {unit}
298
+ </Popconfirm>
299
+ )
300
+ }
301
+
302
+ renderItems = () => {
303
+ return this.state.items.map(this.renderItem)
304
+ }
305
+
306
+ render () {
307
+ const { id, className } = this.state
308
+ if (!id) {
309
+ return null
310
+ }
311
+ const {
312
+ pos,
313
+ shouldScroll,
314
+ realHeight
315
+ } = this.computePos()
316
+ const cls = classnames(
317
+ className,
318
+ id ? 'show' : 'hide',
319
+ shouldScroll ? 'scroll' : ''
320
+ )
321
+ const innerProps = {
322
+ className: 'context-menu-inner',
323
+ style: {
324
+ height: (realHeight - contextMenuPaddingTop * 2) + 'px'
325
+ }
326
+ }
327
+ return (
328
+ <div
329
+ className={cls}
330
+ style={pos}
331
+ >
332
+ <div
333
+ {...innerProps}
334
+ >
335
+ {this.renderItems()}
336
+ </div>
337
+ </div>
338
+ )
339
+ }
340
+ }
@@ -0,0 +1,90 @@
1
+ @require '../../css/includes/theme-default'
2
+ .context-menu
3
+ position: absolute
4
+ width 220px
5
+ background main-dark
6
+ box-shadow 0px 0px 3px 3px alpha(main-dark, .35)
7
+ // border 1px solid #222
8
+ padding 10px 0
9
+ z-index 999
10
+ -webkit-app-region no-drag
11
+ color text
12
+ &.scroll
13
+ .context-menu-inner
14
+ overflow-x hidden
15
+ overflow-y scroll
16
+ .context-item
17
+ -webkit-app-region no-drag
18
+ position relative
19
+ color text
20
+ height 28px
21
+ line-height 28px
22
+ padding 0 16px
23
+ &:hover
24
+ background #000
25
+ color #eee
26
+ cursor pointer
27
+ &.disabled
28
+ color alpha(text, .85)
29
+ &:hover
30
+ color #777
31
+ background #333
32
+ cursor not-allowed
33
+
34
+ .context-sub-text
35
+ position absolute
36
+ right 16px
37
+ top 6px
38
+ opacity .65
39
+
40
+ .context-menu
41
+ hr
42
+ margin 0
43
+ border none
44
+ border-bottom 1px solid main-light
45
+ .sub-context-menu
46
+ display none
47
+ width 200px
48
+ position absolute
49
+ left 100%
50
+ top 0
51
+ background main-dark
52
+ box-shadow 0px 0px 3px 3px alpha(main, .35)
53
+ max-height 300px
54
+ overflow-y scroll
55
+ .with-sub-menu
56
+ &:hover
57
+ .sub-context-menu
58
+ display block
59
+ .sub-context-menu-item
60
+ cursor pointer
61
+ padding 10px 16px
62
+ overflow hidden
63
+ white-space nowrap
64
+ text-overflow ellipsis
65
+ &:hover, &.active
66
+ background-color primary
67
+ color contrastColor(primary)
68
+ .bookmarks-sub-context-menu
69
+ width 380px
70
+ padding 20px 10px 10px 20px
71
+
72
+ .menu-control
73
+ width 28px
74
+ height 28px
75
+ border-radius 30px
76
+ color text
77
+ font-size 16px
78
+ text-align center
79
+ display inline-block
80
+ line-height 28px
81
+ cursor pointer
82
+ opacity .6
83
+ &:hover
84
+ opacity 1
85
+ .is-main
86
+ .menu-control
87
+ img
88
+ border 1px solid text-dark
89
+ border-radius 28px
90
+ background #000