@@ -4,34 +4,53 @@ import { ToolComponentProps } from '@tools/defineTool';
44import ToolTextInput from '@components/input/ToolTextInput' ;
55import ToolTextResult from '@components/result/ToolTextResult' ;
66import { CardExampleType } from '@components/examples/ToolExamples' ;
7+ import { GetGroupsType } from '@components/options/ToolOptions' ;
8+ import CheckboxWithDesc from '@components/options/CheckboxWithDesc' ;
79import { beautifyXml } from './service' ;
810import { InitialValuesType } from './types' ;
911import { useTranslation } from 'react-i18next' ;
1012
11- const initialValues : InitialValuesType = { } ;
13+ const initialValues : InitialValuesType = {
14+ preserveAttributes : true
15+ } ;
1216
1317const exampleCards : CardExampleType < InitialValuesType > [ ] = [
1418 {
1519 title : 'Beautify XML' ,
1620 description : 'Beautify a compact XML string for readability.' ,
1721 sampleText : '<root><item>1</item><item>2</item></root>' ,
1822 sampleResult : `<root>\n <item>1</item>\n <item>2</item>\n</root>` ,
19- sampleOptions : { }
23+ sampleOptions : { preserveAttributes : true }
2024 }
2125] ;
2226
23- export default function XmlBeautifier ( {
24- title,
25- longDescription
26- } : ToolComponentProps ) {
27+ export default function XmlBeautifier ( { title } : ToolComponentProps ) {
2728 const { t } = useTranslation ( 'xml' ) ;
2829 const [ input , setInput ] = useState < string > ( '' ) ;
2930 const [ result , setResult ] = useState < string > ( '' ) ;
3031
31- const compute = ( _values : InitialValuesType , input : string ) => {
32- setResult ( beautifyXml ( input , { } ) ) ;
32+ const compute = ( values : InitialValuesType , input : string ) => {
33+ if ( ! input || input . trim ( ) == '' ) return ;
34+ setResult ( beautifyXml ( input , values ) ) ;
3335 } ;
3436
37+ const getGroups : GetGroupsType < InitialValuesType > | null = ( {
38+ values,
39+ updateField
40+ } ) => [
41+ {
42+ title : t ( 'xmlBeautifier.options.title' ) ,
43+ component : (
44+ < CheckboxWithDesc
45+ checked = { values . preserveAttributes }
46+ onChange = { ( value ) => updateField ( 'preserveAttributes' , value ) }
47+ title = { t ( 'xmlBeautifier.options.preserveAttributesTitle' ) }
48+ description = { t ( 'xmlBeautifier.options.preserveAttributesDesc' ) }
49+ />
50+ )
51+ }
52+ ] ;
53+
3554 return (
3655 < ToolContent
3756 title = { title }
@@ -52,12 +71,12 @@ export default function XmlBeautifier({
5271 }
5372 initialValues = { initialValues }
5473 exampleCards = { exampleCards }
55- getGroups = { null }
74+ getGroups = { getGroups }
5675 setInput = { setInput }
5776 compute = { compute }
5877 toolInfo = { {
59- title : t ( 'xmlBeautifier.toolInfo.title' , { title } ) ,
60- description : longDescription
78+ title : t ( 'xmlBeautifier.toolInfo.title' ) ,
79+ description : t ( 'xmlBeautifier.toolInfo.description' )
6180 } }
6281 />
6382 ) ;
0 commit comments