@electerm/electerm-react 2.8.6 → 2.8.8

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.
@@ -100,7 +100,7 @@ export default function AIConfigForm ({ initialValues, onSubmit, showAIConfig })
100
100
  className='ai-config-form'
101
101
  >
102
102
  <Form.Item label='API URL' required>
103
- <Space.Compact block>
103
+ <Space.Compact className='width-100'>
104
104
  <Form.Item
105
105
  label='API URL'
106
106
  name='baseURLAI'
@@ -7,7 +7,6 @@ import {
7
7
  CloseCircleOutlined
8
8
  } from '@ant-design/icons'
9
9
  import {
10
- Upload,
11
10
  Input,
12
11
  Button,
13
12
  Table,
@@ -28,11 +27,11 @@ import { pick } from 'lodash-es'
28
27
  import { runCmd } from '../terminal/terminal-apis'
29
28
  import deepCopy from 'json-deep-copy'
30
29
  import uid from '../../common/uid'
31
- import { getFilePath } from '../../common/file-drop-utils'
32
30
  import wait from '../../common/wait'
33
31
  import { getFolderFromFilePath } from '../sftp/file-read'
34
32
  import resolveFilePath from '../../common/resolve'
35
33
  import { refsStatic } from '../common/ref'
34
+ import Upload from '../common/upload'
36
35
 
37
36
  const e = window.translate
38
37
 
@@ -407,7 +406,7 @@ export default class BatchOp extends PureComponent {
407
406
  }
408
407
 
409
408
  beforeUpload = async (file) => {
410
- const filePath = getFilePath(file)
409
+ const filePath = file.filePath
411
410
  const text = await window.fs.readFile(filePath)
412
411
  this.setState({
413
412
  text
@@ -4,7 +4,6 @@
4
4
  import {
5
5
  Button,
6
6
  Input,
7
- Upload,
8
7
  AutoComplete,
9
8
  Form,
10
9
  Select
@@ -12,7 +11,7 @@ import {
12
11
  import { formItemLayout } from '../../../common/form-layout'
13
12
  import { uniqBy } from 'lodash-es'
14
13
  import Password from '../../common/password'
15
- import { getFilePath } from '../../../common/file-drop-utils'
14
+ import Upload from '../../common/upload'
16
15
 
17
16
  const { TextArea } = Input
18
17
  const FormItem = Form.Item
@@ -27,12 +26,11 @@ export default function renderAuth (props) {
27
26
  profileFilter = (d) => d
28
27
  } = props
29
28
  const beforeUpload = async (file) => {
30
- const filePath = getFilePath(file)
29
+ const filePath = file.filePath
31
30
  const privateKey = await window.fs.readFile(filePath)
32
31
  form.setFieldsValue({
33
32
  privateKey
34
33
  })
35
- return false
36
34
  }
37
35
  if (authType === 'password') {
38
36
  const opts = {
@@ -18,7 +18,7 @@ export default function renderRunScripts () {
18
18
  <>
19
19
  <Space
20
20
  align='baseline'
21
- block
21
+ className='width-100'
22
22
  key={field.key}
23
23
  >
24
24
  <FormItem
@@ -4,7 +4,6 @@
4
4
  import {
5
5
  Button,
6
6
  Input,
7
- Upload,
8
7
  AutoComplete,
9
8
  Form,
10
9
  Select
@@ -12,7 +11,7 @@ import {
12
11
  import { formItemLayout } from '../../../common/form-layout'
13
12
  import { uniqBy } from 'lodash-es'
14
13
  import Password from '../../common/password'
15
- import { getFilePath } from '../../../common/file-drop-utils'
14
+ import Upload from '../../common/upload'
16
15
 
17
16
  const { TextArea } = Input
18
17
  const FormItem = Form.Item
@@ -27,12 +26,11 @@ export default function renderAuth (props) {
27
26
  profileFilter = (d) => d
28
27
  } = props
29
28
  const commonBeforeUpload = (fieldName) => async (file) => {
30
- const filePath = getFilePath(file)
29
+ const filePath = file.filePath
31
30
  const content = await window.fs.readFile(filePath)
32
31
  form.setFieldsValue({
33
32
  [fieldName]: content
34
33
  })
35
- return false
36
34
  }
37
35
  const renderKeyField = (key, label, desc) => (
38
36
  <FormItem
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Custom Upload component that uses Electron's native file dialog
3
+ * This replaces antd Upload to get absolute file paths instead of browser-based file selection
4
+ */
5
+
6
+ import { PureComponent } from 'react'
7
+ import { getLocalFileInfo } from '../sftp/file-read'
8
+
9
+ /**
10
+ * Open a single file select dialog
11
+ * @returns {Promise<Object|null>} - File object with path info or null if cancelled
12
+ */
13
+ const openFileSelect = async () => {
14
+ const properties = [
15
+ 'openFile',
16
+ 'showHiddenFiles',
17
+ 'noResolveAliases',
18
+ 'treatPackageAsDirectory',
19
+ 'dontAddToRecent'
20
+ ]
21
+ const files = await window.api.openDialog({
22
+ title: 'Choose a file',
23
+ message: 'Choose a file',
24
+ properties
25
+ }).catch(() => false)
26
+ if (!files || !files.length) {
27
+ return null
28
+ }
29
+ const filePath = files[0]
30
+ const stat = await getLocalFileInfo(filePath)
31
+ return { ...stat, filePath, path: filePath }
32
+ }
33
+
34
+ /**
35
+ * Custom Upload component
36
+ * Uses Electron's native file dialog for file selection
37
+ * API compatible with antd Upload for the use cases in this project
38
+ */
39
+ export default class Upload extends PureComponent {
40
+ handleClick = async () => {
41
+ const { beforeUpload, disabled } = this.props
42
+ if (disabled) {
43
+ return
44
+ }
45
+ const file = await openFileSelect()
46
+ if (!file) {
47
+ return
48
+ }
49
+ if (beforeUpload) {
50
+ beforeUpload(file)
51
+ }
52
+ }
53
+
54
+ render () {
55
+ const {
56
+ children,
57
+ className,
58
+ style,
59
+ disabled
60
+ } = this.props
61
+
62
+ return (
63
+ <div
64
+ className={className}
65
+ style={style}
66
+ onClick={this.handleClick}
67
+ role='button'
68
+ tabIndex={disabled ? -1 : 0}
69
+ aria-disabled={disabled}
70
+ >
71
+ {children}
72
+ </div>
73
+ )
74
+ }
75
+ }
@@ -2,13 +2,12 @@ import BookmarkTransport from '../tree-list/bookmark-transport'
2
2
  import download from '../../common/download'
3
3
  import time from '../../common/time'
4
4
  import copy from 'json-deep-copy'
5
- import { getFilePath } from '../../common/file-drop-utils'
6
5
 
7
6
  export default class QmTransport extends BookmarkTransport {
8
7
  name = 'quickCommands'
9
8
  beforeUpload = async (file) => {
10
9
  const { store } = this.props
11
- const filePath = getFilePath(file)
10
+ const filePath = file.filePath
12
11
  const txt = await window.fs.readFile(filePath)
13
12
  try {
14
13
  const arr = JSON.parse(txt)
@@ -20,9 +20,8 @@ export default function renderQm () {
20
20
  return (
21
21
  <Space.Compact
22
22
  align='center'
23
- block
23
+ className='width-100 mg2b'
24
24
  key={field.key}
25
- className='mg2b'
26
25
  >
27
26
  <Space.Addon>{e('delay')}</Space.Addon>
28
27
  <FormItem
@@ -54,6 +54,7 @@ export default function KeywordForm (props) {
54
54
  >
55
55
  <InputConfirm
56
56
  addonBefore={renderBefore(field.name)}
57
+ onChange={handleTrigger}
57
58
  />
58
59
  </FormItem>
59
60
  <Button
@@ -69,7 +70,9 @@ export default function KeywordForm (props) {
69
70
  const { themeConfig } = props
70
71
  return (
71
72
  <FormItem name={[name, 'color']} noStyle>
72
- <Select>
73
+ <Select
74
+ onChange={handleTrigger}
75
+ >
73
76
  {
74
77
  colors.map(color => {
75
78
  const ps = {
@@ -1,13 +1,12 @@
1
1
  import BookmarkTransport from '../tree-list/bookmark-transport'
2
2
  import download from '../../common/download'
3
3
  import time from '../../common/time'
4
- import { getFilePath } from '../../common/file-drop-utils'
5
4
 
6
5
  export default class KeywordsTransport extends BookmarkTransport {
7
6
  name = 'keywords-highlight'
8
7
  beforeUpload = async (file) => {
9
8
  const { store } = this.props
10
- const filePath = getFilePath(file)
9
+ const filePath = file.filePath
11
10
  const txt = await window.fs.readFile(filePath)
12
11
  try {
13
12
  store.setConfig({
@@ -28,6 +27,7 @@ export default class KeywordsTransport extends BookmarkTransport {
28
27
  const { store } = this.props
29
28
  const arr = store.config.keywords || []
30
29
  const txt = JSON.stringify(arr, null, 2)
30
+ console.log(txt, 'txt')
31
31
  const stamp = time(undefined, 'YYYY-MM-DD-HH-mm-ss')
32
32
  download('electerm-' + this.name + '-' + stamp + '.json', txt)
33
33
  }
@@ -7,7 +7,6 @@ import message from '../common/message'
7
7
  import {
8
8
  Select,
9
9
  Switch,
10
- Upload,
11
10
  Button,
12
11
  AutoComplete,
13
12
  Tooltip,
@@ -34,9 +33,9 @@ import KeywordsTransport from './keywords-transport'
34
33
  import fs from '../../common/fs'
35
34
  import uid from '../../common/uid'
36
35
  import createDefaultSessionLogPath from '../../common/default-log-path'
37
- import { getFilePath } from '../../common/file-drop-utils'
38
36
  import TerminalBackgroundConfig from './terminal-bg-config'
39
37
  import NumberConfig from './number-config'
38
+ import Upload from '../common/upload'
40
39
  import './setting.styl'
41
40
 
42
41
  const { Option } = Select
@@ -264,11 +263,9 @@ export default class SettingTerminal extends Component {
264
263
  const after = (
265
264
  <Upload
266
265
  beforeUpload={(file) => {
267
- const filePath = getFilePath(file)
266
+ const filePath = file.filePath
268
267
  this.onChangeValue(filePath, name)
269
- return false
270
268
  }}
271
- showUploadList={false}
272
269
  >
273
270
  <span>{e('chooseFile')}</span>
274
271
  </Upload>
@@ -1,7 +1,6 @@
1
1
  import React, { useState } from 'react'
2
2
  import {
3
3
  AutoComplete,
4
- Upload,
5
4
  Tooltip,
6
5
  Input
7
6
  } from 'antd'
@@ -12,7 +11,7 @@ import {
12
11
  import defaultSettings from '../../common/default-setting'
13
12
  import NumberConfig from './number-config'
14
13
  import TextBgModal from './text-bg-modal.jsx'
15
- import { getFilePath } from '../../common/file-drop-utils'
14
+ import Upload from '../common/upload'
16
15
 
17
16
  const e = window.translate
18
17
 
@@ -33,11 +32,9 @@ export default function TerminalBackgroundConfig ({
33
32
  const after = (
34
33
  <Upload
35
34
  beforeUpload={(file) => {
36
- const filePath = getFilePath(file)
35
+ const filePath = file.filePath
37
36
  onChangeValue(filePath, name)
38
- return false
39
37
  }}
40
- showUploadList={false}
41
38
  >
42
39
  <span>{e('chooseFile')}</span>
43
40
  </Upload>
@@ -4,7 +4,6 @@
4
4
 
5
5
  import {
6
6
  Button,
7
- Upload,
8
7
  Switch,
9
8
  Tooltip
10
9
  } from 'antd'
@@ -13,6 +12,7 @@ import {
13
12
  ExportOutlined,
14
13
  InfoCircleOutlined
15
14
  } from '@ant-design/icons'
15
+ import Upload from '../common/upload'
16
16
 
17
17
  const e = window.translate
18
18
 
@@ -34,6 +34,7 @@ export default function DataTransport (props) {
34
34
  <Upload
35
35
  beforeUpload={store.importAll}
36
36
  fileList={[]}
37
+ className='inline'
37
38
  >
38
39
  <Button
39
40
  icon={<ImportOutlined />}
@@ -69,7 +69,7 @@ export default auto(function WorkspaceSaveModal ({ store }) {
69
69
  width={400}
70
70
  >
71
71
  <div className='pd1y'>
72
- <Space direction='vertical' block>
72
+ <Space direction='vertical' className='width-100'>
73
73
  <Radio.Group
74
74
  value={saveMode}
75
75
  onChange={ev => setSaveMode(ev.target.value)}
@@ -130,7 +130,7 @@ export default class TerminalInfoBase extends Component {
130
130
  terminalInfos
131
131
  } = this.props
132
132
  return (
133
- <Space.Compact block>
133
+ <Space.Compact className='width-100'>
134
134
  {
135
135
  defaults.terminalInfos.map(f => {
136
136
  const type = terminalInfos.includes(f) ? 'primary' : 'default'
@@ -1,5 +1,5 @@
1
1
  import { useRef, useState } from 'react'
2
- import { Button, Input, Upload, Form, Space } from 'antd'
2
+ import { Button, Input, Form, Space } from 'antd'
3
3
  import message from '../common/message'
4
4
  import {
5
5
  convertTheme,
@@ -13,7 +13,7 @@ import generate from '../../common/uid'
13
13
  import Link from '../common/external-link'
14
14
  import InputAutoFocus from '../common/input-auto-focus'
15
15
  import ThemePicker from './theme-editor'
16
- import { getFilePath } from '../../common/file-drop-utils'
16
+ import Upload from '../common/upload'
17
17
  // import './theme-form.styl'
18
18
 
19
19
  const { TextArea } = Input
@@ -154,7 +154,7 @@ export default function ThemeForm (props) {
154
154
  }
155
155
 
156
156
  async function beforeUpload (file) {
157
- const filePath = getFilePath(file)
157
+ const filePath = file.filePath
158
158
  const txt = await window.fs.readFile(filePath)
159
159
  const { name, themeConfig, uiThemeConfig } = convertTheme(txt)
160
160
  const tt = convertThemeToText({
@@ -165,7 +165,6 @@ export default function ThemeForm (props) {
165
165
  themeText: tt
166
166
  })
167
167
  setTxt(tt)
168
- return false
169
168
  }
170
169
 
171
170
  function handleSwitchEditor (e) {
@@ -7,15 +7,15 @@ import {
7
7
  MenuOutlined,
8
8
  EditOutlined
9
9
  } from '@ant-design/icons'
10
- import { Button, Space, Dropdown, Upload } from 'antd'
10
+ import { Button, Space, Dropdown } from 'antd'
11
11
  import copy from 'json-deep-copy'
12
12
  import time from '../../common/time'
13
13
  import { uniq } from 'lodash-es'
14
14
  import { fixBookmarks } from '../../common/db-fix'
15
15
  import download from '../../common/download'
16
- import { getFilePath } from '../../common/file-drop-utils'
17
16
  import delay from '../../common/wait'
18
17
  import { action } from 'manate'
18
+ import Upload from '../common/upload'
19
19
 
20
20
  const e = window.translate
21
21
 
@@ -31,7 +31,7 @@ export default function BookmarkToolbar (props) {
31
31
  } = props
32
32
  const upload = action(async (file) => {
33
33
  const { store } = window
34
- const filePath = getFilePath(file)
34
+ const filePath = file.filePath
35
35
  const txt = await window.fs.readFile(filePath)
36
36
 
37
37
  const content = JSON.parse(txt)
@@ -8,7 +8,8 @@ import {
8
8
  ImportOutlined,
9
9
  EditOutlined
10
10
  } from '@ant-design/icons'
11
- import { Upload, Button, Space } from 'antd'
11
+ import { Button, Space } from 'antd'
12
+ import Upload from '../common/upload'
12
13
 
13
14
  const e = window.translate
14
15
 
@@ -13,7 +13,6 @@ import download from '../common/download'
13
13
  import { fixBookmarks } from '../common/db-fix'
14
14
  import dayjs from 'dayjs'
15
15
  import parseJsonSafe from '../common/parse-json-safe'
16
- import { getFilePath } from '../common/file-drop-utils'
17
16
 
18
17
  const {
19
18
  version: packVer
@@ -418,7 +417,7 @@ export default (Store) => {
418
417
  }
419
418
 
420
419
  Store.prototype.importAll = async function (file) {
421
- const filePath = getFilePath(file)
420
+ const filePath = file.filePath
422
421
  const txt = await window.fs
423
422
  .readFile(filePath)
424
423
  const { store } = window
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@electerm/electerm-react",
3
- "version": "2.8.6",
3
+ "version": "2.8.8",
4
4
  "description": "react components src for electerm",
5
5
  "main": "./client/components/main/main.jsx",
6
6
  "license": "MIT",