1- import { Button , Checkbox , Dialog , DialogFooter } from '@blueprintjs/core' ;
1+ import { Button , Dialog , DialogFooter } from '@blueprintjs/core' ;
22import styled from '@emotion/styled' ;
33import type { ACSExportOptions , Spectrum1D } from '@zakodium/nmrium-core' ;
44import type { FormEvent } from 'react' ;
5+ import { useMemo } from 'react' ;
56import {
67 FieldGroupSVGTextStyleFields ,
78 Form ,
@@ -37,12 +38,15 @@ type ExportFormatType = 'IMJA' | 'IMJ' | 'D';
3738type ExportSignalKind = ACSExportOptions [ 'signalKind' ] ;
3839
3940const validationSchema = z . object ( {
40- signalKind : z . enum ( [ 'all' , 'signal' ] ) ,
41- ascending : z . boolean ( ) ,
42- format : z . string ( ) ,
43- couplingFormat : z . string ( ) ,
44- deltaFormat : z . string ( ) ,
45- textStyle : svgTextStyleFieldsSchema ,
41+ acs : z . object ( {
42+ signalKind : z . enum ( [ 'all' , 'signal' ] ) ,
43+ ascending : z . boolean ( ) ,
44+ format : z . string ( ) ,
45+ couplingFormat : z . string ( ) ,
46+ deltaFormat : z . string ( ) ,
47+ textStyle : svgTextStyleFieldsSchema ,
48+ } ) ,
49+ isPublicationStringShown : z . boolean ( ) ,
4650} ) ;
4751
4852const exportOptions : Array < SelectItem < ExportSignalKind > > = [
@@ -100,18 +104,37 @@ function InnerPublicationStringModal(props: InnerPublicationStringModalProps) {
100104 const spectrum = useSpectrum ( ) ;
101105 const { dispatch } = usePreferences ( ) ;
102106 const currentACSOptions = useActiveACSSettings ( ) ;
107+
108+ const defaultValues = useMemo ( ( ) => {
109+ const values = validationSchema . encode ( {
110+ acs : currentACSOptions ,
111+ isPublicationStringShown,
112+ } ) ;
113+
114+ if ( values . acs . textStyle . fontSize === undefined ) {
115+ values . acs . textStyle . fontSize = '12' ;
116+ }
117+
118+ return values ;
119+ } , [ currentACSOptions , isPublicationStringShown ] ) ;
103120 const form = useForm ( {
104- defaultValues : validationSchema . encode ( currentACSOptions ) ,
121+ defaultValues,
105122 validators : { onChange : validationSchema } ,
106123 onSubmit : ( { value } ) => {
107124 assert ( spectrum && isSpectrum1D ( spectrum ) ) ;
108125 const nucleus = spectrum . info . nucleus ;
109126
110- const options = validationSchema . parse ( value ) ;
127+ const parsedValues = validationSchema . parse ( value ) ;
128+ if ( parsedValues . acs . textStyle . fontSize === 12 ) {
129+ parsedValues . acs . textStyle . fontSize = undefined ;
130+ }
111131 dispatch ( {
112132 type : 'CHANGE_EXPORT_ACS_SETTINGS' ,
113- payload : { options, nucleus } ,
133+ payload : { options : parsedValues . acs , nucleus } ,
114134 } ) ;
135+ if ( parsedValues . isPublicationStringShown !== isPublicationStringShown ) {
136+ togglePublicationStringVisibility ( ) ;
137+ }
115138 onClose ( ) ;
116139 } ,
117140 } ) ;
@@ -133,29 +156,29 @@ function InnerPublicationStringModal(props: InnerPublicationStringModalProps) {
133156 >
134157 < Form noValidate onSubmit = { onSubmit } layout = "inline" >
135158 < StyledDialogBody >
136- < form . AppField name = "signalKind" >
159+ < form . AppField name = "acs. signalKind" >
137160 { ( field ) => (
138161 < field . Select label = "Export filter" items = { exportOptions } />
139162 ) }
140163 </ form . AppField >
141- < form . AppField name = "format" >
164+ < form . AppField name = "acs. format" >
142165 { ( field ) => (
143166 < field . Select label = "Export format" items = { exportFormats } />
144167 ) }
145168 </ form . AppField >
146- < form . AppField name = "ascending" >
169+ < form . AppField name = "acs. ascending" >
147170 { ( field ) => < field . Checkbox label = "Ascending order" /> }
148171 </ form . AppField >
149- < form . AppField name = "deltaFormat" >
172+ < form . AppField name = "acs. deltaFormat" >
150173 { ( field ) => < field . Input label = "Delta format" /> }
151174 </ form . AppField >
152- < form . AppField name = "couplingFormat" >
175+ < form . AppField name = "acs. couplingFormat" >
153176 { ( field ) => < field . Input label = "Couplings format" /> }
154177 </ form . AppField >
155178
156179 < FieldGroupSVGTextStyleFields
157180 form = { form }
158- fields = "textStyle"
181+ fields = "acs. textStyle"
159182 label = "Text style"
160183 previewText = "Publication string"
161184 />
@@ -179,11 +202,14 @@ function InnerPublicationStringModal(props: InnerPublicationStringModalProps) {
179202 </ form . SubmitButton >
180203 }
181204 >
182- < PublicationStringCheckbox
183- label = "Show publication string"
184- checked = { isPublicationStringShown }
185- onChange = { togglePublicationStringVisibility }
186- />
205+ < form . AppField name = "isPublicationStringShown" >
206+ { ( field ) => (
207+ < field . Checkbox
208+ label = "Show publication string"
209+ style = { { display : 'inline-block' } }
210+ />
211+ ) }
212+ </ form . AppField >
187213 </ DialogFooter >
188214 </ Form >
189215 </ Dialog >
@@ -197,10 +223,6 @@ const CopyPreviewButton = styled(Button)`
197223 margin-bottom: 5px;
198224` ;
199225
200- const PublicationStringCheckbox = styled ( Checkbox ) `
201- display: inline-block;
202- ` ;
203-
204226interface PublicationStringPreviewProps {
205227 spectrum : Spectrum1D ;
206228 values : z . input < typeof validationSchema > ;
@@ -210,7 +232,7 @@ interface PublicationStringPreviewProps {
210232function PublicationStringPreview ( props : PublicationStringPreviewProps ) {
211233 const { spectrum, values, onCopy } = props ;
212234
213- const acs = validationSchema . parse ( values ) ;
235+ const { acs } = validationSchema . parse ( values ) ;
214236 const value = buildPublicationString ( { spectrum, acs } ) ;
215237
216238 if ( ! value ) return < EmptyText text = "No publication string" /> ;
0 commit comments