@electerm/electerm-react 1.50.46 → 1.50.59

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.
@@ -76,6 +76,18 @@ export default function LocalFormUi (props) {
76
76
  hasFeedback
77
77
  name='url'
78
78
  required
79
+ rules={[
80
+ {
81
+ required: true,
82
+ message: e('Please input URL')
83
+ },
84
+ {
85
+ validator: (_, value) =>
86
+ !value || value.startsWith('http://') || value.startsWith('https://')
87
+ ? Promise.resolve()
88
+ : Promise.reject(new Error(e('URL must start with http:// or https://')))
89
+ }
90
+ ]}
79
91
  >
80
92
  <Input />
81
93
  </FormItem>
@@ -98,6 +110,13 @@ export default function LocalFormUi (props) {
98
110
  showSearch
99
111
  />
100
112
  </FormItem>
113
+ <FormItem
114
+ {...formItemLayout}
115
+ label={e('useragent')}
116
+ name='useragent'
117
+ >
118
+ <Input />
119
+ </FormItem>
101
120
  <FormItem
102
121
  {...formItemLayout}
103
122
  label='type'
@@ -5,7 +5,6 @@ import { findIndex, pick } from 'lodash-es'
5
5
  import classNames from 'classnames'
6
6
  import generate from '../../common/id-with-stamp'
7
7
  import copy from 'json-deep-copy'
8
- import wait from '../../common/wait.js'
9
8
  import Tabs from '../tabs/index.jsx'
10
9
  import {
11
10
  tabActions,
@@ -146,7 +145,7 @@ class Sessions extends Component {
146
145
  })
147
146
  }
148
147
 
149
- addTab = (_tab, _index) => {
148
+ addTab = (_tab, _index, callback) => {
150
149
  this.setState((oldState) => {
151
150
  const tabs = copy(oldState.tabs)
152
151
  const index = typeof _index === 'undefined'
@@ -167,6 +166,9 @@ class Sessions extends Component {
167
166
  }, () => {
168
167
  this.updateStoreTabs(this.state.tabs)
169
168
  this.updateStoreCurrentTabId(this.state.currentTabId)
169
+ if (callback) {
170
+ callback()
171
+ }
170
172
  })
171
173
  }
172
174
 
@@ -207,42 +209,38 @@ class Sessions extends Component {
207
209
  window.store.currentTabId = this.state.currentTabId
208
210
  }
209
211
 
210
- reloadTab = async (tabToReload) => {
211
- this.setState(async oldState => {
212
- const tab = copy(
213
- tabToReload
214
- )
215
- tab.pane = paneMap.terminal
216
- const { id } = tab
217
- const tabs = copy(oldState.tabs)
218
- tab.id = generate()
219
- tab.status = statusMap.processing
220
- const index = findIndex(tabs, t => t.id === id)
221
- this.addTab(tab, index)
222
- await wait(30)
212
+ reloadTab = (tabToReload) => {
213
+ const tab = copy(
214
+ tabToReload
215
+ )
216
+ tab.pane = paneMap.terminal
217
+ const { id } = tab
218
+ const { tabs } = this.state
219
+ tab.id = generate()
220
+ tab.status = statusMap.processing
221
+ const index = findIndex(tabs, t => t.id === id)
222
+ this.addTab(tab, index, () => {
223
223
  this.delTab(id)
224
224
  })
225
225
  }
226
226
 
227
227
  onDuplicateTab = (tabToDup) => {
228
- this.setState(oldState => {
229
- const defaultStatus = statusMap.processing
230
- let tab = copy(tabToDup)
231
- updateCount(tab)
232
- const tabs = copy(oldState.tabs)
233
- const index = findIndex(
234
- tabs,
235
- d => d.id === tab.id
236
- )
237
- tab = {
238
- ...tab,
239
- status: defaultStatus,
240
- id: generate(),
241
- isTransporting: undefined
242
- }
243
- tab.pane = paneMap.terminal
244
- this.addTab(tab, index + 1)
245
- })
228
+ const defaultStatus = statusMap.processing
229
+ let tab = copy(tabToDup)
230
+ updateCount(tab)
231
+ const tabs = copy(this.state.tabs)
232
+ const index = findIndex(
233
+ tabs,
234
+ d => d.id === tab.id
235
+ )
236
+ tab = {
237
+ ...tab,
238
+ status: defaultStatus,
239
+ id: generate(),
240
+ isTransporting: undefined
241
+ }
242
+ tab.pane = paneMap.terminal
243
+ this.addTab(tab, index + 1)
246
244
  }
247
245
 
248
246
  onChangeTabId = id => {
@@ -1,4 +1,5 @@
1
1
  import AddressBar from './address-bar'
2
+ // import React, { useEffect } from 'react'
2
3
 
3
4
  export default function WebSession (props) {
4
5
  const {
@@ -7,8 +8,10 @@ export default function WebSession (props) {
7
8
  height,
8
9
  reloadTab
9
10
  } = props
11
+ const urlRegex = /^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?$/i
12
+ const url = urlRegex.test(tab.url) ? tab.url : 'https://' + tab.url
10
13
  const addrProps = {
11
- url: tab.url,
14
+ url,
12
15
  title: tab.title,
13
16
  description: tab.description,
14
17
  onOpen: () => {
@@ -20,22 +23,62 @@ export default function WebSession (props) {
20
23
  )
21
24
  }
22
25
  }
23
- const viewProps = {
24
- src: tab.url,
25
- style: {
26
- width: (width - 10) + 'px',
27
- height: (height - 12) + 'px'
28
- },
29
- disableblinkfeatures: 'true',
30
- disablewebsecurity: 'true'
26
+
27
+ // TODO: 支持自定义Header和Cookie
28
+ // useEffect(() => {
29
+ // const webview = document.querySelector('webview')
30
+ // if (webview) {
31
+ // // 添加事件监听,输出所有的事件
32
+ // webview.addEventListener('did-start-loading', (e) => {
33
+ // console.log('did-start-loading', e)
34
+ // })
35
+ // }
36
+ // }, []);
37
+
38
+ // 打开webview的开发者工具
39
+ // useEffect(() => {
40
+ // const webview = document.querySelector('webview')
41
+ // if (webview) {
42
+ // webview.addEventListener('dom-ready', () => {
43
+ // webview.openDevTools()
44
+ // })
45
+ // }
46
+ // }, [])
47
+
48
+ function renderView () {
49
+ if (window.et.isWebApp) {
50
+ const iframeProps = {
51
+ src: url,
52
+ style: {
53
+ width: (width - 10) + 'px',
54
+ height: (height - 12) + 'px'
55
+ }
56
+ }
57
+ return (
58
+ <iframe {...iframeProps} />
59
+ )
60
+ }
61
+ const viewProps = {
62
+ src: url,
63
+ style: {
64
+ width: (width - 10) + 'px',
65
+ height: (height - 12) + 'px'
66
+ },
67
+ disableblinkfeatures: 'true',
68
+ disablewebsecurity: 'true',
69
+ allowpopups: 'true',
70
+ useragent: tab.useragent || 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
71
+ }
72
+ return (
73
+ <webview {...viewProps} />
74
+ )
31
75
  }
76
+
32
77
  return (
33
78
  <div className='web-session-wrap'>
34
79
  <AddressBar {...addrProps} />
35
80
  <div className='pd1'>
36
- <webview
37
- {...viewProps}
38
- />
81
+ {renderView()}
39
82
  </div>
40
83
  </div>
41
84
  )
@@ -1,7 +1,7 @@
1
1
  import { createRoot } from 'react-dom/client'
2
2
  import 'antd/dist/reset.css'
3
3
  import '@xterm/xterm/css/xterm.css'
4
- import '../common/trzsz'
4
+ import '../common/trzsz.js'
5
5
  import 'firacode/distr/fira_code.css'
6
6
  import Main from '../components/main/index.jsx'
7
7
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@electerm/electerm-react",
3
- "version": "1.50.46",
3
+ "version": "1.50.59",
4
4
  "description": "react components src for electerm",
5
5
  "main": "./client/components/main/main.jsx",
6
6
  "license": "MIT",