@electerm/electerm-react 1.35.0 → 1.36.1

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,7 +2,7 @@ import { Component } from 'react'
2
2
  import ZmodemTransfer from './zmodem-transfer'
3
3
  import { handleErr } from '../../common/fetch'
4
4
  import generate from '../../common/uid'
5
- import { isEqual, pick, debounce } from 'lodash-es'
5
+ import { isEqual, pick, debounce, throttle } from 'lodash-es'
6
6
  import postMessage from '../../common/post-msg'
7
7
  import clone from '../../common/to-simple-obj'
8
8
  import runIdle from '../../common/run-idle'
@@ -51,6 +51,7 @@ import NormalBuffer from './normal-buffer'
51
51
  import { createTerm, resizeTerm } from './terminal-apis'
52
52
  import createLsId from './build-ls-term-id'
53
53
  import { shortcutExtend, shortcutDescExtend } from '../shortcuts/shortcut-handler.js'
54
+ import { KeywordHighlighterAddon } from './highlight-addon.js'
54
55
 
55
56
  const { prefix } = window
56
57
  const e = prefix('ssh')
@@ -255,12 +256,12 @@ class Term extends Component {
255
256
  this.openNormalBuffer()
256
257
  }
257
258
 
258
- prevTabShortcut = debounce((e) => {
259
+ prevTabShortcut = throttle((e) => {
259
260
  e.stopPropagation()
260
261
  window.store.clickPrevTab()
261
262
  }, 300)
262
263
 
263
- nextTabShortcut = debounce((e) => {
264
+ nextTabShortcut = throttle((e) => {
264
265
  e.stopPropagation()
265
266
  window.store.clickNextTab()
266
267
  }, 300)
@@ -820,10 +821,6 @@ class Term extends Component {
820
821
  term.onData(this.onData)
821
822
  this.term = term
822
823
  term.attachCustomKeyEventHandler(this.handleKeyboardEvent.bind(this))
823
- term.onKey(this.onKey)
824
- // if (host && !password && !privateKey) {
825
- // return this.promote()
826
- // }
827
824
  await this.remoteInit(term)
828
825
  }
829
826
 
@@ -905,7 +902,13 @@ class Term extends Component {
905
902
  })
906
903
  const { cols, rows } = term
907
904
  const { config } = this.props
908
- const { host, port, tokenElecterm, server = '' } = config
905
+ const {
906
+ host,
907
+ port,
908
+ tokenElecterm,
909
+ keywords = [],
910
+ server = ''
911
+ } = config
909
912
  const { sessionId, terminalIndex, id, logName } = this.props
910
913
  const tab = deepCopy(this.props.tab || {})
911
914
  const {
@@ -1025,47 +1028,15 @@ class Term extends Component {
1025
1028
  noTerminalWriteOutsideSession: true
1026
1029
  }, this)
1027
1030
  }
1028
-
1029
- // this.decoder = new TextDecoder(encode)
1030
- if (displayRaw) {
1031
- const oldWrite = term.write
1032
- const th = this
1033
- term.write = function (data) {
1034
- // let str = ''
1035
- // if (typeof data === 'object') {
1036
- // if (data instanceof ArrayBuffer) {
1037
- // str = th.decoder.decode(data)
1038
- // oldWrite.call(term, th.escape(str))
1039
- // } else {
1040
- // const fileReader = new FileReader()
1041
- // fileReader.addEventListener('load', () => {
1042
- // str = th.decoder.decode(fileReader.result)
1043
- // oldWrite.call(term, th.escape(str))
1044
- // })
1045
- // fileReader.readAsArrayBuffer(new window.Blob([data]))
1046
- // }
1047
- // } else if (typeof data === 'string') {
1048
- // oldWrite.call(term, th.escape(data))
1049
- // } else {
1050
- // throw Error(`Cannot handle ${typeof data} websocket message.`)
1051
- // }
1052
- oldWrite.call(term, th.escape(data))
1053
- }
1054
- }
1031
+ term.displayRaw = displayRaw
1032
+ term.loadAddon(
1033
+ new KeywordHighlighterAddon(keywords)
1034
+ )
1055
1035
  this.term = term
1056
1036
  window.store.triggerResize()
1057
1037
  }
1058
1038
 
1059
- escape = str => {
1060
- return str.replace(/\\x1B/g, '\\x1B')
1061
- .replace(/\033/g, '\\033')
1062
- }
1063
-
1064
- onKey = (key, e) => {
1065
- // log.log('onKey', key, e)
1066
- }
1067
-
1068
- onResize = debounce(() => {
1039
+ onResize = throttle(() => {
1069
1040
  const cid = this.props.currentTabId
1070
1041
  const tid = this.props.tab?.id
1071
1042
  if (
@@ -35,7 +35,8 @@ import {
35
35
  sidebarPanelWidth,
36
36
  paneMap,
37
37
  settingSyncId,
38
- settingShortcutsId
38
+ settingShortcutsId,
39
+ settingTerminalId
39
40
  } from '../common/constants'
40
41
  import getInitItem from '../common/init-setting-item'
41
42
  import {
@@ -45,6 +46,7 @@ import {
45
46
  const { prefix } = window
46
47
  const ss = prefix('settingSync')
47
48
  const s = prefix('setting')
49
+ const sss = prefix('ssh')
48
50
 
49
51
  function getReverseColor (hex) {
50
52
  // Check if the input is a valid hex color code
@@ -248,12 +250,16 @@ class Store {
248
250
  get setting () {
249
251
  return [
250
252
  {
251
- id: settingSyncId,
252
- title: ss('settingSync')
253
+ id: settingTerminalId,
254
+ title: sss('terminal')
253
255
  },
254
256
  {
255
257
  id: settingShortcutsId,
256
258
  title: s('settingShortcuts')
259
+ },
260
+ {
261
+ id: settingSyncId,
262
+ title: ss('settingSync')
257
263
  }
258
264
  ]
259
265
  }
@@ -11,6 +11,7 @@ import copy from 'json-deep-copy'
11
11
  import {
12
12
  settingMap,
13
13
  settingCommonId,
14
+ settingSyncId,
14
15
  modals
15
16
  } from '../common/constants'
16
17
  import { buildNewTheme } from '../common/terminal-theme'
@@ -150,7 +151,7 @@ export default Store => {
150
151
  store.storeAssign({
151
152
  settingTab: settingMap.setting
152
153
  })
153
- store.setSettingItem(copy(store.setting[0]))
154
+ store.setSettingItem(copy(store.setting.find(d => d.id === settingSyncId)))
154
155
  store.openSettingModal()
155
156
  }
156
157
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@electerm/electerm-react",
3
- "version": "1.35.0",
3
+ "version": "1.36.1",
4
4
  "description": "react components src for electerm",
5
5
  "main": "./client/components/main/main.jsx",
6
6
  "license": "MIT",
@@ -1,51 +0,0 @@
1
- export default () => {
2
- return [
3
- {
4
- name: 'app_closeCurrentTab',
5
- shortcut: 'ctrl+w',
6
- shortcutMac: 'ctrl+w'
7
- },
8
- {
9
- name: 'app_prevTab',
10
- shortcut: 'ctrl+shift+tab',
11
- shortcutMac: 'ctrl+shift+tab'
12
- },
13
- {
14
- name: 'app_nextTab',
15
- shortcut: 'ctrl+tab',
16
- shortcutMac: 'ctrl+tab'
17
- },
18
- {
19
- name: 'terminal_clear',
20
- shortcut: 'ctrl+l,ctrl+shift+l',
21
- shortcutMac: 'meta+l'
22
- },
23
- {
24
- name: 'terminal_selectAll',
25
- shortcut: 'ctrl+a,ctrl+shift+a',
26
- shortcutMac: 'meta+a',
27
- readonly: true
28
- },
29
- {
30
- name: 'terminal_copy',
31
- shortcut: 'ctrl+c,ctrl+shift+c',
32
- shortcutMac: 'meta+c',
33
- readonly: true
34
- },
35
- {
36
- name: 'terminal_search',
37
- shortcut: 'ctrl+shift+f',
38
- shortcutMac: 'meta+f'
39
- },
40
- {
41
- name: 'terminal_pasteSelected',
42
- shortcut: 'alt+insert',
43
- shortcutMac: 'alt+insert'
44
- },
45
- {
46
- name: 'terminal_showNormalBuffer',
47
- shortcut: 'ctrl+ArrowUp',
48
- shortcutMac: 'meta+ArrowUp'
49
- }
50
- ]
51
- }