wwf
2 天以前 a430284aa21e3ae1f0d5654e55b2ad2852519cc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use client'
import type { FC } from 'react'
import React from 'react'
import type { KeyValue } from '../../types'
import KeyValueEdit from './key-value-edit'
 
type Props = {
  readonly: boolean
  nodeId: string
  list: KeyValue[]
  onChange: (newList: KeyValue[]) => void
  onAdd: () => void
  isSupportFile?: boolean
  // toggleKeyValueEdit: () => void
}
 
const KeyValueList: FC<Props> = ({
  readonly,
  nodeId,
  list,
  onChange,
  onAdd,
  isSupportFile,
  // toggleKeyValueEdit,
}) => {
  // const handleBulkValueChange = useCallback((value: string) => {
  //   const newList = value.split('\n').map((item) => {
  //     const [key, value] = item.split(':')
  //     return {
  //       key: key ? key.trim() : '',
  //       value: value ? value.trim() : '',
  //     }
  //   })
  //   onChange(newList)
  // }, [onChange])
 
  // const bulkList = (() => {
  //   const res = list.map((item) => {
  //     if (!item.key && !item.value)
  //       return ''
  //     if (!item.value)
  //       return item.key
  //     return `${item.key}:${item.value}`
  //   }).join('\n')
  //   return res
  // })()
  return <KeyValueEdit
    readonly={readonly}
    nodeId={nodeId}
    list={list}
    onChange={onChange}
    onAdd={onAdd}
    isSupportFile={isSupportFile}
  // onSwitchToBulkEdit={toggleKeyValueEdit}
  />
  // : <BulkEdit
  //   value={bulkList}
  //   onChange={handleBulkValueChange}
  //   onSwitchToKeyValueEdit={toggleKeyValueEdit}
  // />
}
export default React.memo(KeyValueList)