Skip to content

Commit bcb04a8

Browse files
committed
format code
1 parent 58363c2 commit bcb04a8

File tree

10 files changed

+177
-148
lines changed

10 files changed

+177
-148
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"prettier": {
3131
"printWidth": 80,
32-
"semi": true,
32+
"semi": false,
3333
"singleQuote": true,
3434
"trailingComma": "es5"
3535
},

src/AddItem.tsx

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
1-
import { PlusSquareOutlined } from '@ant-design/icons';
2-
import { Button, Col, Input, Select, Space } from 'antd';
3-
import cloneDeep from 'lodash.clonedeep';
4-
import React from 'react';
5-
import { useContext, useState } from 'react';
6-
import { ConfigContext } from './store';
7-
import { typeList, typeMap } from './util';
1+
import { PlusSquareOutlined } from '@ant-design/icons'
2+
import { Button, Col, Input, Select, Space } from 'antd'
3+
import cloneDeep from 'lodash.clonedeep'
4+
import React from 'react'
5+
import { useContext, useState } from 'react'
6+
import { ConfigContext } from './store'
7+
import { typeList, typeMap } from './util'
88

99
const AddItem = (props: {
10-
uniqueKey: string;
11-
sourceData: any;
12-
deepLevel: number;
10+
uniqueKey: string
11+
sourceData: any
12+
deepLevel: number
1313
}) => {
14-
const { setEditObject, editObject } = useContext(ConfigContext);
15-
const { uniqueKey, sourceData } = props;
16-
const isArray = Array.isArray(sourceData);
17-
const [templateData, setTemplateData] = useState<any>({});
18-
const [showIncreaseMap, setShowIncreaseMap] = useState<any>({});
14+
const { setEditObject, editObject } = useContext(ConfigContext)
15+
const { uniqueKey, sourceData } = props
16+
const isArray = Array.isArray(sourceData)
17+
const [templateData, setTemplateData] = useState<any>({})
18+
const [showIncreaseMap, setShowIncreaseMap] = useState<any>({})
1919
const onClickIncrease = (key: string, value: boolean) => {
20-
showIncreaseMap[key] = value;
21-
templateData[key] = {};
20+
showIncreaseMap[key] = value
21+
templateData[key] = {}
2222
setTemplateData({
2323
...templateData,
24-
});
24+
})
2525
setShowIncreaseMap({
2626
...showIncreaseMap,
27-
});
28-
};
27+
})
28+
}
2929
const changeInputKey = (uniqueKey: string, event: any) => {
30-
templateData[uniqueKey]['key'] = event.target.value;
31-
setTemplateData({ ...templateData });
32-
};
30+
templateData[uniqueKey]['key'] = event.target.value
31+
setTemplateData({ ...templateData })
32+
}
3333
const changeInputValue = (uniqueKey: string, event: any) => {
34-
templateData[uniqueKey]['value'] = event.target.value;
35-
setTemplateData({ ...templateData });
36-
};
34+
templateData[uniqueKey]['value'] = event.target.value
35+
setTemplateData({ ...templateData })
36+
}
3737
const onChangeTempType = (uniqueKey: any, type: any) => {
38-
templateData[uniqueKey]['type'] = type;
39-
templateData[uniqueKey]['value'] = typeMap[type];
38+
templateData[uniqueKey]['type'] = type
39+
templateData[uniqueKey]['value'] = typeMap[type]
4040
setTemplateData({
4141
...templateData,
42-
});
43-
};
42+
})
43+
}
4444
const onConfirmIncrease = (uniqueKey: any, sourceData: any) => {
45-
const { key: aKey, value } = cloneDeep(templateData[uniqueKey]);
45+
const { key: aKey, value } = cloneDeep(templateData[uniqueKey])
4646
if (isArray) {
47-
sourceData.push(value);
47+
sourceData.push(value)
4848
} else {
49-
sourceData[aKey] = value;
49+
sourceData[aKey] = value
5050
}
51-
setEditObject({ ...editObject });
52-
onClickIncrease(uniqueKey, false);
53-
};
51+
setEditObject({ ...editObject })
52+
onClickIncrease(uniqueKey, false)
53+
}
5454
return (
5555
<div className="addItem" key={uniqueKey}>
5656
{showIncreaseMap[uniqueKey] ? (
@@ -115,6 +115,6 @@ const AddItem = (props: {
115115
</Col>
116116
)}
117117
</div>
118-
);
119-
};
120-
export default AddItem;
118+
)
119+
}
120+
export default AddItem

src/ArrayView.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import React from 'react';
2-
import AddItem from './AddItem';
3-
import ToolsView from './Tools';
1+
import React from 'react'
2+
import AddItem from './AddItem'
3+
import ToolsView from './Tools'
44
function ArrayView(props: {
5-
fieldValue: any[];
6-
fieldKey: string;
7-
sourceData: any;
8-
getValue: any;
9-
deepLevel: number;
10-
deepLevelJoin: string;
5+
fieldValue: any[]
6+
fieldKey: string
7+
sourceData: any
8+
getValue: any
9+
deepLevel: number
10+
deepLevelJoin: string
1111
}) {
1212
return (
1313
<div className="blockContent">
1414
<div style={{ marginTop: '10px' }}>
1515
{props.fieldValue.map((item: any, index: number) => {
16-
const uniqueKey = `${props.deepLevelJoin}-${index}`;
16+
const uniqueKey = `${props.deepLevelJoin}-${index}`
1717
return (
1818
<div className="indexLine" key={uniqueKey}>
1919
<span style={{ marginRight: '5px' }}>{index + 1}.</span>
@@ -32,7 +32,7 @@ function ArrayView(props: {
3232
/>
3333
}
3434
</div>
35-
);
35+
)
3636
})}
3737
</div>
3838
<div>
@@ -44,6 +44,6 @@ function ArrayView(props: {
4444
/>
4545
</div>
4646
</div>
47-
);
47+
)
4848
}
49-
export default ArrayView;
49+
export default ArrayView

src/JsonView.tsx

Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,64 @@
1-
import { Input, InputNumber, Select } from 'antd';
2-
import React, { useContext, useEffect } from 'react';
3-
import { getQuoteAddress, getTypeString, typeMap } from './util';
4-
import AddItem from './AddItem';
5-
import { ConfigContext } from './store';
6-
import { JsonEditorProps } from '.';
7-
import ArrayView from './ArrayView';
8-
import ToolsView from './Tools';
1+
import { Input, InputNumber, Select } from 'antd'
2+
import React, { useContext, useEffect } from 'react'
3+
import { getQuoteAddress, getTypeString, typeMap } from './util'
4+
import AddItem from './AddItem'
5+
import { ConfigContext } from './store'
6+
import { JsonEditorProps } from '.'
7+
import ArrayView from './ArrayView'
8+
import ToolsView from './Tools'
99

1010
function JsonView(props: JsonEditorProps) {
11-
const { editObject, setEditObject } = useContext(ConfigContext);
11+
const { editObject, setEditObject } = useContext(ConfigContext)
1212

1313
useEffect(() => {
14-
props.onChange(editObject);
15-
}, [editObject]);
14+
props.onChange(editObject)
15+
}, [editObject])
1616

1717
const syncData = (data: Record<string, any>) => {
18-
setEditObject({ ...data });
19-
};
18+
setEditObject({ ...data })
19+
}
2020

2121
const onClickDelete = (key: string, sourceData: any) => {
2222
if (Array.isArray(sourceData)) {
23-
sourceData.splice(+key, 1);
23+
sourceData.splice(+key, 1)
2424
} else {
25-
Reflect.deleteProperty(sourceData, key);
25+
Reflect.deleteProperty(sourceData, key)
2626
}
27-
syncData(editObject);
28-
};
27+
syncData(editObject)
28+
}
2929

3030
const onChangeType = (type: string, fieldValue: any) => {
31-
const newEditObject = getQuoteAddress(
32-
fieldValue,
33-
typeMap[type],
34-
editObject
35-
);
36-
syncData(newEditObject);
37-
};
31+
const newEditObject = getQuoteAddress(fieldValue, typeMap[type], editObject)
32+
syncData(newEditObject)
33+
}
3834

3935
const onChangeKey = (
4036
event: React.ChangeEvent<HTMLInputElement>,
4137
currentKey: string,
4238
source: Record<string, any>
4339
) => {
44-
const newValue: Record<string, any> = {};
40+
const newValue: Record<string, any> = {}
4541
for (const key in source) {
4642
if (Object.prototype.hasOwnProperty.call(source, key)) {
4743
if (key === currentKey) {
48-
newValue[event.target.value] = source[key];
44+
newValue[event.target.value] = source[key]
4945
} else {
50-
newValue[key] = source[key];
46+
newValue[key] = source[key]
5147
}
5248
}
5349
}
54-
const newTotalData = getQuoteAddress(source, newValue, editObject);
55-
syncData(newTotalData);
56-
};
50+
const newTotalData = getQuoteAddress(source, newValue, editObject)
51+
syncData(newTotalData)
52+
}
5753

5854
const onChangeValue = (
5955
value: any,
6056
key: string,
6157
source: Record<string, any>
6258
) => {
63-
source[key] = value;
64-
syncData(editObject);
65-
};
59+
source[key] = value
60+
syncData(editObject)
61+
}
6662

6763
const getValue = (
6864
fieldValue: any,
@@ -71,7 +67,7 @@ function JsonView(props: JsonEditorProps) {
7167
deepLevel: number,
7268
deepLevelJoin: string
7369
) => {
74-
const thatType = getTypeString(fieldValue);
70+
const thatType = getTypeString(fieldValue)
7571
switch (thatType) {
7672
case 'array':
7773
return (
@@ -86,14 +82,14 @@ function JsonView(props: JsonEditorProps) {
8682
getValue={getValue}
8783
/>
8884
</span>
89-
);
85+
)
9086
case 'object':
9187
return (
9288
<span style={{ marginBottom: '10px' }}>
9389
<b>Object{`{${Object.keys(fieldValue).length}}`}:</b>
9490
{renderJsonConfig(fieldValue, deepLevel + 1, deepLevelJoin)}
9591
</span>
96-
);
92+
)
9793
case 'string':
9894
return (
9995
<Input
@@ -104,7 +100,7 @@ function JsonView(props: JsonEditorProps) {
104100
onChangeValue(event.target.value, fieldKey, sourceData)
105101
}
106102
/>
107-
);
103+
)
108104
case 'null':
109105
case 'number':
110106
return (
@@ -113,17 +109,17 @@ function JsonView(props: JsonEditorProps) {
113109
placeholder={fieldValue}
114110
value={fieldValue}
115111
onChange={(value: number) => {
116-
onChangeValue(value, fieldKey, sourceData);
112+
onChangeValue(value, fieldKey, sourceData)
117113
}}
118114
/>
119-
);
115+
)
120116
case 'boolean':
121117
return (
122118
<Select
123119
style={{ width: '100px' }}
124120
defaultValue={true}
125121
onChange={(value: boolean) => {
126-
onChangeValue(value, fieldKey, sourceData);
122+
onChangeValue(value, fieldKey, sourceData)
127123
}}
128124
>
129125
<Select.Option value={true} label="true">
@@ -133,15 +129,15 @@ function JsonView(props: JsonEditorProps) {
133129
false
134130
</Select.Option>
135131
</Select>
136-
);
132+
)
137133
}
138-
};
134+
}
139135
const renderJsonConfig = (
140136
sourceData: any,
141137
deepLevel: number = 0,
142138
deepLevelJoin: string = `${deepLevel}`
143139
) => {
144-
const keyList = Object.keys(sourceData);
140+
const keyList = Object.keys(sourceData)
145141
if (!keyList.length) {
146142
return (
147143
<div style={{ marginLeft: '20px' }}>
@@ -151,14 +147,14 @@ function JsonView(props: JsonEditorProps) {
151147
sourceData={sourceData}
152148
/>
153149
</div>
154-
);
150+
)
155151
}
156152
return (
157153
<div className="blockContent">
158154
<div style={{ marginTop: '10px' }}>
159155
{keyList.map((fieldKey, index) => {
160-
const uniqueKey = `${deepLevelJoin}-${index}`;
161-
const fieldValue = sourceData[fieldKey];
156+
const uniqueKey = `${deepLevelJoin}-${index}`
157+
const fieldValue = sourceData[fieldKey]
162158
return (
163159
<div key={uniqueKey} className="indexLine">
164160
<span className="jsonKey">
@@ -188,7 +184,7 @@ function JsonView(props: JsonEditorProps) {
188184
}
189185
</span>
190186
</div>
191-
);
187+
)
192188
})}
193189
</div>
194190
<div>
@@ -200,8 +196,8 @@ function JsonView(props: JsonEditorProps) {
200196
/>
201197
</div>
202198
</div>
203-
);
204-
};
199+
)
200+
}
205201

206202
return (
207203
<ConfigContext.Provider
@@ -214,7 +210,7 @@ function JsonView(props: JsonEditorProps) {
214210
>
215211
<div>{renderJsonConfig(editObject)}</div>
216212
</ConfigContext.Provider>
217-
);
213+
)
218214
}
219215

220-
export default JsonView;
216+
export default JsonView

0 commit comments

Comments
 (0)