@electerm/electerm-react 1.51.21 → 1.60.6

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.
@@ -2,297 +2,9 @@
2
2
  * central state store powered by manate - https://github.com/tylerlong/manate
3
3
  */
4
4
 
5
+ import { StateStore } from './store'
5
6
  import { manage } from 'manate'
6
- import initState from './init-state'
7
- import loadDataExtend from './load-data'
8
- import dbUpgradeExtend from './db-upgrade'
9
- import eventExtend from './event'
10
- import syncExtend from './sync'
11
- import appUpgradeExtend from './app-upgrade'
12
- import bookmarkGroupExtend from './bookmark-group'
13
- import bookmarkExtend from './bookmark'
14
- import commonExtend from './common'
15
- import contextMenuExtend from './context-menu'
16
- import itemExtend from './item'
17
- import quickCommandExtend from './quick-command'
18
- import sessionExtend from './session'
19
- import settingExtend from './setting'
20
- import sidebarExtend from './sidebar'
21
- import sysMenuExtend from './system-menu'
22
- import tabExtend from './tab'
23
- import uiThemeExtend from './ui-theme'
24
- import terminalThemeExtend from './terminal-theme'
25
- import transferHistoryExtend from './transfer-history'
26
- import batchInputHistory from './batch-input-history'
27
- import transferExtend from './transfer-list'
28
- import addressBookmarkExtend from './address-bookmark'
29
- import isColorDark from '../common/is-color-dark'
30
- import { getReverseColor } from '../common/reverse-color'
31
- import { uniq } from 'lodash-es'
32
- import deepCopy from 'json-deep-copy'
33
- import {
34
- settingMap,
35
- paneMap,
36
- settingSyncId,
37
- settingShortcutsId,
38
- settingTerminalId,
39
- terminalSshConfigType
40
- } from '../common/constants'
41
- import getInitItem from '../common/init-setting-item'
42
- import {
43
- theme
44
- } from 'antd'
45
7
 
46
- const e = window.translate
47
-
48
- class Store {
49
- constructor () {
50
- Object.assign(
51
- this,
52
- initState()
53
- )
54
- }
55
-
56
- get width () {
57
- return window.store.innerWidth
58
- }
59
-
60
- get config () {
61
- return deepCopy(window.store._config)
62
- }
63
-
64
- get currentQuickCommands () {
65
- const { currentTab } = this
66
- const { quickCommands } = window.store
67
- const currentTabQuickCommands = (
68
- currentTab.quickCommands || []
69
- ).map((d, i) => {
70
- return {
71
- ...d,
72
- id: 'tab-qm-' + currentTab.id + '#' + i
73
- }
74
- })
75
- return [
76
- ...currentTabQuickCommands,
77
- ...quickCommands
78
- ]
79
- }
80
-
81
- get currentTab () {
82
- const {
83
- activeTabId
84
- } = this
85
- const { tabs } = window.store
86
- const tab = tabs.find(t => t.id === activeTabId)
87
- if (!tab) {
88
- return false
89
- }
90
- return tab
91
- }
92
-
93
- get inActiveTerminal () {
94
- const { store } = window
95
- if (store.showModal) {
96
- return false
97
- }
98
- const {
99
- currentTab
100
- } = store
101
- if (!currentTab) {
102
- return false
103
- }
104
- const {
105
- type,
106
- pane
107
- } = currentTab
108
- if (type === 'rdp' || type === 'vnc' || type === 'web') {
109
- return false
110
- }
111
- return pane === paneMap.ssh ||
112
- pane === paneMap.terminal
113
- }
114
-
115
- get quickCommandTags () {
116
- const { quickCommands } = window.store
117
- return uniq(
118
- quickCommands.reduce((p, q) => {
119
- return [
120
- ...p,
121
- ...(q.labels || [])
122
- ]
123
- }, [])
124
- )
125
- }
126
-
127
- get isTransporting () {
128
- return window.store.tabs.some(t => t.isTransporting)
129
- }
130
-
131
- get transferCount () {
132
- return window.store.fileTransfers.length
133
- }
134
-
135
- get settingSidebarList () {
136
- const {
137
- settingTab
138
- } = this
139
- const arr = window.store.getSidebarList(settingTab)
140
- const initItem = getInitItem(arr, settingTab)
141
- return settingTab === settingMap.history
142
- ? arr
143
- : [
144
- deepCopy(initItem),
145
- ...arr
146
- ]
147
- }
148
-
149
- get termSearchOptions () {
150
- const {
151
- store
152
- } = window
153
- const theme = store.getThemeConfig()
154
- return {
155
- ...window.store._termSearchOptions,
156
- decorations: {
157
- activeMatchBorder: theme.yellow,
158
- activeMatchBackground: theme.selectionBackground,
159
- activeMatchColorOverviewRuler: theme.selectionBackground,
160
- matchBackground: theme.background,
161
- matchOverviewRuler: theme.yellow,
162
- matchBorder: getReverseColor(theme.background)
163
- }
164
- }
165
- }
166
-
167
- get tabTitles () {
168
- return window.store.tabs.map(d => d.title).join('#')
169
- }
170
-
171
- get setting () {
172
- return [
173
- {
174
- id: settingTerminalId,
175
- title: e('terminal')
176
- },
177
- {
178
- id: settingShortcutsId,
179
- title: e('settingShortcuts')
180
- },
181
- {
182
- id: settingSyncId,
183
- title: e('settingSync')
184
- }
185
- ]
186
- }
187
-
188
- get onOperation () {
189
- const {
190
- store
191
- } = window
192
- return store.showModal ||
193
- store.showInfoModal ||
194
- store.showEditor ||
195
- store.showFileModal
196
- }
197
-
198
- get uiThemeConfig () {
199
- const { store } = window
200
- const themeConf = store.getUiThemeConfig()
201
- return {
202
- token: {
203
- borderRadius: 3,
204
- colorPrimary: themeConf.primary,
205
- colorBgBase: themeConf.main,
206
- colorError: themeConf.error,
207
- colorInfo: themeConf.info,
208
- colorSuccess: themeConf.success,
209
- colorWarning: themeConf.warn,
210
- colorTextBase: themeConf.text,
211
- colorLink: themeConf['text-light']
212
- },
213
- algorithm: isColorDark(themeConf.main) ? theme.darkAlgorithm : theme.defaultAlgorithm
214
- }
215
- }
216
-
217
- get bookmarkTree () {
218
- const {
219
- bookmarks
220
- } = window.store
221
- return bookmarks.reduce((p, v) => {
222
- return {
223
- ...p,
224
- [v.id]: v
225
- }
226
- }, {})
227
- }
228
-
229
- hasSshConfig () {
230
- return !!window.store
231
- .bookmarkGroups
232
- .find(b => b.id === terminalSshConfigType)
233
- }
234
-
235
- get bookmarkGroupTree () {
236
- const {
237
- bookmarkGroups
238
- } = window.store
239
- return bookmarkGroups.reduce((p, v) => {
240
- return {
241
- ...p,
242
- [v.id]: v
243
- }
244
- }, {})
245
- }
246
-
247
- get hasOldConnectionHoppingBookmark () {
248
- return window.store.bookmarks.some(b => {
249
- return b.connectionHoppings?.length && !b.hasHopping
250
- })
251
- }
252
- }
253
-
254
- const arrGetterProps = [
255
- 'addressBookmarks',
256
- 'addressBookmarksLocal',
257
- 'bookmarks',
258
- 'bookmarkGroups',
259
- 'profiles',
260
- 'quickCommands',
261
- 'terminalThemes'
262
- ]
263
-
264
- for (const prop of arrGetterProps) {
265
- Object.defineProperty(Store.prototype, prop, {
266
- get: function () {
267
- return JSON.parse(window.store[`_${prop}`] || '[]').filter(d => d)
268
- }
269
- })
270
- }
271
-
272
- loadDataExtend(Store)
273
- eventExtend(Store)
274
- dbUpgradeExtend(Store)
275
- syncExtend(Store)
276
- appUpgradeExtend(Store)
277
- bookmarkGroupExtend(Store)
278
- bookmarkExtend(Store)
279
- commonExtend(Store)
280
- contextMenuExtend(Store)
281
- itemExtend(Store)
282
- quickCommandExtend(Store)
283
- sessionExtend(Store)
284
- settingExtend(Store)
285
- sidebarExtend(Store)
286
- sysMenuExtend(Store)
287
- tabExtend(Store)
288
- terminalThemeExtend(Store)
289
- uiThemeExtend(Store)
290
- transferHistoryExtend(Store)
291
- batchInputHistory(Store)
292
- transferExtend(Store)
293
- addressBookmarkExtend(Store)
294
-
295
- export const StateStore = Store
296
- const store = manage(new Store())
8
+ const store = manage(new StateStore())
297
9
 
298
10
  export default store
@@ -19,6 +19,7 @@ import {
19
19
  dismissDelKeyTipLsKey,
20
20
  qmSortByFrequencyKey,
21
21
  resolutionsLsKey,
22
+ aiChatHistoryKey,
22
23
  splitMap
23
24
  } from '../common/constants'
24
25
  import { buildDefaultThemes } from '../common/terminal-theme'
@@ -76,6 +77,11 @@ export default () => {
76
77
  selectedSessions: [],
77
78
  sessionModalVisible: false,
78
79
 
80
+ // batch input selected tab ids
81
+ _batchInputSelectedTabIds: new Set(),
82
+ showAIConfig: false,
83
+ aiChatHistory: ls.getItemJSON(aiChatHistoryKey, []),
84
+
79
85
  // sftp
80
86
  fileOperation: fileOperationsMap.cp, // cp or mv
81
87
  pauseAllTransfer: false,
@@ -103,6 +109,7 @@ export default () => {
103
109
  activeTabId3: '',
104
110
  terminalInfoProps: {},
105
111
  rightPanelVisible: false,
112
+ rightPanelTab: 'info',
106
113
  rightPanelPinned: false,
107
114
  rightPanelWidth: parseInt(ls.getItem(rightSidebarWidthKey), 10) || 500,
108
115
 
@@ -144,7 +151,6 @@ export default () => {
144
151
  // sidebar
145
152
  openedSideBar: ls.getItem(openedSidebarKey),
146
153
  leftSidebarWidth: parseInt(ls.getItem(leftSidebarWidthKey), 10) || 300,
147
- rightSidebarWidth: parseInt(ls.getItem(rightSidebarWidthKey), 10) || 500,
148
154
  menuOpened: false,
149
155
  pinned: ls.getItem(sidebarPinnedKey) === 'true',
150
156
 
@@ -0,0 +1,298 @@
1
+ /**
2
+ * central state store powered by manate - https://github.com/tylerlong/manate
3
+ */
4
+
5
+ import initState from './init-state'
6
+ import loadDataExtend from './load-data'
7
+ import dbUpgradeExtend from './db-upgrade'
8
+ import eventExtend from './event'
9
+ import syncExtend from './sync'
10
+ import appUpgradeExtend from './app-upgrade'
11
+ import bookmarkGroupExtend from './bookmark-group'
12
+ import bookmarkExtend from './bookmark'
13
+ import commonExtend from './common'
14
+ import contextMenuExtend from './context-menu'
15
+ import itemExtend from './item'
16
+ import quickCommandExtend from './quick-command'
17
+ import sessionExtend from './session'
18
+ import settingExtend from './setting'
19
+ import sidebarExtend from './sidebar'
20
+ import sysMenuExtend from './system-menu'
21
+ import tabExtend from './tab'
22
+ import uiThemeExtend from './ui-theme'
23
+ import terminalThemeExtend from './terminal-theme'
24
+ import transferHistoryExtend from './transfer-history'
25
+ import batchInputHistory from './batch-input-history'
26
+ import transferExtend from './transfer-list'
27
+ import addressBookmarkExtend from './address-bookmark'
28
+ import isColorDark from '../common/is-color-dark'
29
+ import { getReverseColor } from '../common/reverse-color'
30
+ import { uniq } from 'lodash-es'
31
+ import deepCopy from 'json-deep-copy'
32
+ import {
33
+ settingMap,
34
+ paneMap,
35
+ settingSyncId,
36
+ settingShortcutsId,
37
+ settingTerminalId,
38
+ terminalSshConfigType
39
+ } from '../common/constants'
40
+ import getInitItem from '../common/init-setting-item'
41
+ import {
42
+ theme
43
+ } from 'antd'
44
+
45
+ const e = window.translate
46
+
47
+ class Store {
48
+ constructor () {
49
+ Object.assign(
50
+ this,
51
+ initState()
52
+ )
53
+ }
54
+
55
+ get width () {
56
+ return window.store.innerWidth
57
+ }
58
+
59
+ get config () {
60
+ return deepCopy(window.store._config)
61
+ }
62
+
63
+ get currentQuickCommands () {
64
+ const { currentTab } = this
65
+ const { quickCommands } = window.store
66
+ const currentTabQuickCommands = (
67
+ currentTab.quickCommands || []
68
+ ).map((d, i) => {
69
+ return {
70
+ ...d,
71
+ id: 'tab-qm-' + currentTab.id + '#' + i
72
+ }
73
+ })
74
+ return [
75
+ ...currentTabQuickCommands,
76
+ ...quickCommands
77
+ ]
78
+ }
79
+
80
+ get currentTab () {
81
+ const {
82
+ activeTabId
83
+ } = this
84
+ const { tabs } = window.store
85
+ const tab = tabs.find(t => t.id === activeTabId)
86
+ if (!tab) {
87
+ return false
88
+ }
89
+ return tab
90
+ }
91
+
92
+ get batchInputSelectedTabIds () {
93
+ return Array.from(window.store._batchInputSelectedTabIds)
94
+ }
95
+
96
+ get inActiveTerminal () {
97
+ const { store } = window
98
+ if (store.showModal) {
99
+ return false
100
+ }
101
+ const {
102
+ currentTab
103
+ } = store
104
+ if (!currentTab) {
105
+ return false
106
+ }
107
+ const {
108
+ type,
109
+ pane
110
+ } = currentTab
111
+ if (type === 'rdp' || type === 'vnc' || type === 'web') {
112
+ return false
113
+ }
114
+ return pane === paneMap.ssh ||
115
+ pane === paneMap.terminal
116
+ }
117
+
118
+ get quickCommandTags () {
119
+ const { quickCommands } = window.store
120
+ return uniq(
121
+ quickCommands.reduce((p, q) => {
122
+ return [
123
+ ...p,
124
+ ...(q.labels || [])
125
+ ]
126
+ }, [])
127
+ )
128
+ }
129
+
130
+ get isTransporting () {
131
+ return window.store.tabs.some(t => t.isTransporting)
132
+ }
133
+
134
+ get transferCount () {
135
+ return window.store.fileTransfers.length
136
+ }
137
+
138
+ get settingSidebarList () {
139
+ const {
140
+ settingTab
141
+ } = this
142
+ const arr = window.store.getSidebarList(settingTab)
143
+ const initItem = getInitItem(arr, settingTab)
144
+ return settingTab === settingMap.history
145
+ ? arr
146
+ : [
147
+ deepCopy(initItem),
148
+ ...arr
149
+ ]
150
+ }
151
+
152
+ get termSearchOptions () {
153
+ const {
154
+ store
155
+ } = window
156
+ const theme = store.getThemeConfig()
157
+ return {
158
+ ...window.store._termSearchOptions,
159
+ decorations: {
160
+ activeMatchBorder: theme.yellow,
161
+ activeMatchBackground: theme.selectionBackground,
162
+ activeMatchColorOverviewRuler: theme.selectionBackground,
163
+ matchBackground: theme.background,
164
+ matchOverviewRuler: theme.yellow,
165
+ matchBorder: getReverseColor(theme.background)
166
+ }
167
+ }
168
+ }
169
+
170
+ get tabTitles () {
171
+ return window.store.tabs.map(d => d.title).join('#')
172
+ }
173
+
174
+ get setting () {
175
+ return [
176
+ {
177
+ id: settingTerminalId,
178
+ title: e('terminal')
179
+ },
180
+ {
181
+ id: settingShortcutsId,
182
+ title: e('settingShortcuts')
183
+ },
184
+ {
185
+ id: settingSyncId,
186
+ title: e('settingSync')
187
+ }
188
+ ]
189
+ }
190
+
191
+ get onOperation () {
192
+ const {
193
+ store
194
+ } = window
195
+ return store.showModal ||
196
+ store.showInfoModal ||
197
+ store.showEditor ||
198
+ store.showFileModal
199
+ }
200
+
201
+ get uiThemeConfig () {
202
+ const { store } = window
203
+ const themeConf = store.getUiThemeConfig()
204
+ return {
205
+ token: {
206
+ borderRadius: 3,
207
+ colorPrimary: themeConf.primary,
208
+ colorBgBase: themeConf.main,
209
+ colorError: themeConf.error,
210
+ colorInfo: themeConf.info,
211
+ colorSuccess: themeConf.success,
212
+ colorWarning: themeConf.warn,
213
+ colorTextBase: themeConf.text,
214
+ colorLink: themeConf['text-light']
215
+ },
216
+ algorithm: isColorDark(themeConf.main) ? theme.darkAlgorithm : theme.defaultAlgorithm
217
+ }
218
+ }
219
+
220
+ get bookmarkTree () {
221
+ const {
222
+ bookmarks
223
+ } = window.store
224
+ return bookmarks.reduce((p, v) => {
225
+ return {
226
+ ...p,
227
+ [v.id]: v
228
+ }
229
+ }, {})
230
+ }
231
+
232
+ hasSshConfig () {
233
+ return !!window.store
234
+ .bookmarkGroups
235
+ .find(b => b.id === terminalSshConfigType)
236
+ }
237
+
238
+ get bookmarkGroupTree () {
239
+ const {
240
+ bookmarkGroups
241
+ } = window.store
242
+ return bookmarkGroups.reduce((p, v) => {
243
+ return {
244
+ ...p,
245
+ [v.id]: v
246
+ }
247
+ }, {})
248
+ }
249
+
250
+ get hasOldConnectionHoppingBookmark () {
251
+ return window.store.bookmarks.some(b => {
252
+ return b.connectionHoppings?.length && !b.hasHopping
253
+ })
254
+ }
255
+ }
256
+
257
+ const arrGetterProps = [
258
+ 'addressBookmarks',
259
+ 'addressBookmarksLocal',
260
+ 'bookmarks',
261
+ 'bookmarkGroups',
262
+ 'profiles',
263
+ 'quickCommands',
264
+ 'terminalThemes'
265
+ ]
266
+
267
+ for (const prop of arrGetterProps) {
268
+ Object.defineProperty(Store.prototype, prop, {
269
+ get: function () {
270
+ return JSON.parse(window.store[`_${prop}`] || '[]').filter(d => d)
271
+ }
272
+ })
273
+ }
274
+
275
+ loadDataExtend(Store)
276
+ eventExtend(Store)
277
+ dbUpgradeExtend(Store)
278
+ syncExtend(Store)
279
+ appUpgradeExtend(Store)
280
+ bookmarkGroupExtend(Store)
281
+ bookmarkExtend(Store)
282
+ commonExtend(Store)
283
+ contextMenuExtend(Store)
284
+ itemExtend(Store)
285
+ quickCommandExtend(Store)
286
+ sessionExtend(Store)
287
+ settingExtend(Store)
288
+ sidebarExtend(Store)
289
+ sysMenuExtend(Store)
290
+ tabExtend(Store)
291
+ terminalThemeExtend(Store)
292
+ uiThemeExtend(Store)
293
+ transferHistoryExtend(Store)
294
+ batchInputHistory(Store)
295
+ transferExtend(Store)
296
+ addressBookmarkExtend(Store)
297
+
298
+ export const StateStore = Store
@@ -341,7 +341,10 @@ export default Store => {
341
341
 
342
342
  // Find the current tab index and its batch
343
343
  const currentIndex = tabs.findIndex(t => t.id === activeTabId)
344
- if (currentIndex === -1) return // Current tab not found, do nothing
344
+
345
+ if (currentIndex === -1) {
346
+ return // Current tab not found, do nothing
347
+ }
345
348
 
346
349
  const currentBatch = tabs[currentIndex].batch
347
350
 
@@ -363,6 +366,7 @@ export default Store => {
363
366
  // If a valid next tab is found, update the activeTabId
364
367
  if (nextIndex !== -1 && nextIndex !== currentIndex) {
365
368
  store.activeTabId = tabs[nextIndex].id
369
+ store[`activeTabId${currentBatch}`] = tabs[nextIndex].id
366
370
  }
367
371
  }
368
372
 
@@ -492,4 +496,53 @@ export default Store => {
492
496
  }
493
497
  })()
494
498
  }
499
+
500
+ Store.prototype.updateBatchInputSelectedTabIds = function () {
501
+ const { store } = window
502
+ store._batchInputSelectedTabIds = new Set([store.activeTabId])
503
+ }
504
+
505
+ Store.prototype.onSelectBatchInputSelectedTabId = action(function (id) {
506
+ const { store } = window
507
+ const { _batchInputSelectedTabIds } = store
508
+ if (_batchInputSelectedTabIds.has(id)) {
509
+ _batchInputSelectedTabIds.delete(id)
510
+ } else {
511
+ _batchInputSelectedTabIds.add(id)
512
+ }
513
+ if (_batchInputSelectedTabIds.size === 0) {
514
+ _batchInputSelectedTabIds.add(store.activeTabId)
515
+ }
516
+ })
517
+
518
+ Store.prototype.filterBatchInputSelectedTabIds = action(function () {
519
+ const { store } = window
520
+ const { _batchInputSelectedTabIds, tabs } = store
521
+ const validTabIds = new Set(tabs.map(tab => tab.id))
522
+
523
+ // Filter out invalid tab IDs
524
+ for (const id of _batchInputSelectedTabIds) {
525
+ if (!validTabIds.has(id)) {
526
+ _batchInputSelectedTabIds.delete(id)
527
+ }
528
+ }
529
+
530
+ // If no valid tabs are selected, add the active tab
531
+ if (_batchInputSelectedTabIds.size === 0) {
532
+ _batchInputSelectedTabIds.add(store.activeTabId)
533
+ }
534
+ })
535
+
536
+ Store.prototype.selectAllBatchInputTabs = function () {
537
+ const { store } = window
538
+ const { tabs } = store
539
+ store._batchInputSelectedTabIds = new Set(tabs.map(tab => tab.id))
540
+ }
541
+
542
+ Store.prototype.selectNoneBatchInputTabs = action(function () {
543
+ const { store } = window
544
+ store._batchInputSelectedTabIds.clear()
545
+ // Ensure at least the active tab is selected
546
+ store._batchInputSelectedTabIds.add(store.activeTabId)
547
+ })
495
548
  }