@@ -14,6 +14,7 @@ import FileSystemFactory from "@Packages/filesystem/factory";
1414import FileSystemParams from "@App/pages/components/FileSystemParams" ;
1515import { blackListSelfCheck } from "@App/pkg/utils/match" ;
1616import { obtainBlackList } from "@App/pkg/utils/utils" ;
17+ import CustomTrans from "@App/pages/components/CustomTrans" ;
1718
1819function Setting ( ) {
1920 const [ syncDelete , setSyncDelete ] = useState < boolean > ( ) ;
@@ -29,6 +30,8 @@ function Setting() {
2930 const [ updateDisableScript , setUpdateDisableScript ] = useState ( false ) ;
3031 const [ silenceUpdateScript , setSilenceUpdateScript ] = useState ( false ) ;
3132 const [ enableEslint , setEnableEslint ] = useState ( false ) ;
33+ const [ editorConfig , setEditorConfig ] = useState ( "" ) ;
34+ const [ editorTypeDefinition , setEditorTypeDefinition ] = useState ( "" ) ;
3235 const [ eslintConfig , setEslintConfig ] = useState ( "" ) ;
3336 const [ blacklist , setBlacklist ] = useState < string > ( "" ) ;
3437 const [ badgeNumberType , setBadgeNumberType ] = useState < "none" | "run_count" | "script_count" > ( "run_count" ) ;
@@ -67,6 +70,8 @@ function Setting() {
6770 systemConfig . getBadgeBackgroundColor ( ) ,
6871 systemConfig . getBadgeTextColor ( ) ,
6972 systemConfig . getScriptMenuDisplayType ( ) ,
73+ systemConfig . getEditorConfig ( ) ,
74+ systemConfig . getEditorTypeDefinition ( ) ,
7075 ] ) . then (
7176 ( [
7277 cloudSync ,
@@ -82,6 +87,8 @@ function Setting() {
8287 badgeBackgroundColor ,
8388 badgeTextColor ,
8489 scriptMenuDisplayType ,
90+ editorConfig ,
91+ editorTypeDefinition ,
8592 ] ) => {
8693 setSyncDelete ( cloudSync . syncDelete ) ;
8794 setSyncScriptStatus ( cloudSync . syncStatus ) ;
@@ -100,6 +107,8 @@ function Setting() {
100107 setBadgeBackgroundColor ( badgeBackgroundColor ) ;
101108 setBadgeTextColor ( badgeTextColor ) ;
102109 setScriptMenuDisplayType ( scriptMenuDisplayType ) ;
110+ setEditorConfig ( editorConfig ) ;
111+ setEditorTypeDefinition ( editorTypeDefinition ) ;
103112 }
104113 ) ;
105114 } ;
@@ -445,14 +454,19 @@ function Setting() {
445454 onChange = { ( v ) => {
446455 setEslintConfig ( v ) ;
447456 } }
448- onBlur = { ( v ) => {
457+ onBlur = { ( ) => {
449458 prettier
450459 . format ( eslintConfig , {
451460 parser : "json" ,
452461 plugins : [ prettierPluginEstree , babel ] ,
453462 } )
454- . then ( ( ) => {
455- systemConfig . setEslintConfig ( v . target . value ) ;
463+ . then ( ( value ) => {
464+ if ( value === "" ) {
465+ Message . success ( t ( "eslint_rules_reset" ) ) ;
466+ } else {
467+ Message . success ( t ( "eslint_rules_saved" ) ) ;
468+ }
469+ systemConfig . setEslintConfig ( value ) ;
456470 } )
457471 . catch ( ( e ) => {
458472 Message . error ( `${ t ( "eslint_config_format_error" ) } : ${ JSON . stringify ( Logger . E ( e ) ) } ` ) ;
@@ -461,6 +475,74 @@ function Setting() {
461475 />
462476 </ div >
463477 ) }
478+ < div >
479+ < div className = "flex items-start justify-between mb-3" >
480+ < span className = "font-medium min-w-20" > { t ( "editor_config" ) } </ span >
481+ < CustomTrans
482+ className = "text-xs max-w-80 text-right ml-6 flex-shrink-0"
483+ i18nKey = "editor_config_description"
484+ />
485+ </ div >
486+ < Input . TextArea
487+ placeholder = { t ( "editor_config" ) ! }
488+ autoSize = { {
489+ minRows : 4 ,
490+ maxRows : 8 ,
491+ } }
492+ value = { editorConfig }
493+ onChange = { ( v ) => {
494+ setEditorConfig ( v ) ;
495+ } }
496+ onBlur = { ( ) => {
497+ prettier
498+ . format ( editorConfig , {
499+ parser : "json" ,
500+ plugins : [ prettierPluginEstree , babel ] ,
501+ } )
502+ . then ( ( value ) => {
503+ if ( value === "" ) {
504+ Message . success ( t ( "editor_config_reset" ) ) ;
505+ } else {
506+ Message . success ( t ( "editor_config_saved" ) ) ;
507+ }
508+ systemConfig . setEditorConfig ( value ) ;
509+ } )
510+ . catch ( ( e ) => {
511+ Message . error ( `${ t ( "editor_config_format_error" ) } : ${ JSON . stringify ( Logger . E ( e ) ) } ` ) ;
512+ } ) ;
513+ } }
514+ />
515+ </ div >
516+ < div >
517+ < div className = "flex items-start justify-between mb-3" >
518+ < span className = "font-medium min-w-20" > { t ( "editor_type_definition" ) } </ span >
519+ < span
520+ className = "text-xs max-w-100 text-right ml-6 flex-shrink-0"
521+ dangerouslySetInnerHTML = { {
522+ __html : t ( "editor_type_definition_description" ) ,
523+ } }
524+ > </ span >
525+ </ div >
526+ < Input . TextArea
527+ placeholder = { t ( "editor_type_definition" ) ! }
528+ autoSize = { {
529+ minRows : 4 ,
530+ maxRows : 8 ,
531+ } }
532+ value = { editorTypeDefinition }
533+ onChange = { ( v ) => {
534+ setEditorTypeDefinition ( v ) ;
535+ } }
536+ onBlur = { ( ) => {
537+ if ( editorTypeDefinition === "" ) {
538+ Message . success ( t ( "editor_type_definition_reset" ) ) ;
539+ } else {
540+ Message . success ( t ( "editor_type_definition_saved" ) ) ;
541+ }
542+ systemConfig . setEditorTypeDefinition ( editorTypeDefinition ) ;
543+ } }
544+ />
545+ </ div >
464546 </ Space >
465547 </ Card >
466548 </ Space >
0 commit comments