Skip to content

Commit cbf4e68

Browse files
committed
feat: integrate textStyle from ACSExportOptions core type
1 parent 2bf8b89 commit cbf4e68

3 files changed

Lines changed: 26 additions & 17 deletions

File tree

src/component/hooks/use_acs_settings.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ const defaultOptions: ACSExportOptions = {
1010
format: 'IMJA',
1111
couplingFormat: '0.00',
1212
deltaFormat: '0.00',
13+
textStyle: {
14+
fill: '#000000',
15+
fontSize: 16,
16+
fontStyle: 'normal',
17+
fontWeight: 'normal',
18+
},
1319
};
1420

1521
export function useACSSettings() {

src/component/modal/PublicationStringModal.tsx

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type ExportSignalKind = ACSExportOptions['signalKind'];
3939
const validationSchema = z.object({
4040
signalKind: z.enum(['all', 'signal']),
4141
ascending: z.boolean(),
42-
format: z.enum(['IMJA', 'IMJ', 'D']),
42+
format: z.string(),
4343
couplingFormat: z.string(),
4444
deltaFormat: z.string(),
4545
textStyle: svgTextStyleFieldsSchema,
@@ -101,23 +101,16 @@ function InnerPublicationStringModal(props: InnerPublicationStringModalProps) {
101101
const { dispatch } = usePreferences();
102102
const currentACSOptions = useACSSettings();
103103
const form = useForm({
104-
defaultValues: {
105-
...currentACSOptions,
106-
textStyle: {
107-
fill: '#000000',
108-
fontSize: '16',
109-
fontStyle: 'normal',
110-
fontWeight: 'normal',
111-
} as z.input<typeof svgTextStyleFieldsSchema>,
112-
},
104+
defaultValues: validationSchema.encode(currentACSOptions),
113105
validators: { onChange: validationSchema },
114106
onSubmit: ({ value }) => {
115107
assert(spectrum && isSpectrum1D(spectrum));
116108
const nucleus = spectrum.info.nucleus;
117109

110+
const options = validationSchema.parse(value);
118111
dispatch({
119112
type: 'CHANGE_EXPORT_ACS_SETTINGS',
120-
payload: { options: value, nucleus },
113+
payload: { options, nucleus },
121114
});
122115
onClose();
123116
},
@@ -169,9 +162,9 @@ function InnerPublicationStringModal(props: InnerPublicationStringModalProps) {
169162

170163
<Body>
171164
<form.Subscribe selector={(s) => s.values}>
172-
{(acs) => (
165+
{(values) => (
173166
<PublicationStringPreview
174-
acs={acs}
167+
values={values}
175168
spectrum={spectrum}
176169
onCopy={onCopyClick}
177170
/>
@@ -210,21 +203,22 @@ const PublicationStringCheckbox = styled(Checkbox)`
210203

211204
interface PublicationStringPreviewProps {
212205
spectrum: Spectrum1D;
213-
acs: ACSExportOptions;
206+
values: z.input<typeof validationSchema>;
214207
onCopy: (value: string) => void;
215208
}
216209

217210
function PublicationStringPreview(props: PublicationStringPreviewProps) {
218-
const { spectrum, acs, onCopy } = props;
211+
const { spectrum, values, onCopy } = props;
219212

213+
const acs = validationSchema.parse(values);
220214
const value = buildPublicationString({ spectrum, acs });
221215

222216
if (!value) return <EmptyText text="No publication string" />;
223217

224218
return (
225219
<>
226220
<CopyPreviewButton onClick={() => onCopy(value)} icon="duplicate" />
227-
{/*eslint-disable-next-line react/no-danger*/}
221+
{/* eslint-disable-next-line react/no-danger */}
228222
<div dangerouslySetInnerHTML={{ __html: value }} />
229223
</>
230224
);

src/component/workspaces/workspaceDefaultProperties.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
import type { WorkspacePreferences } from '@zakodium/nmrium-core';
1+
import type { TextStyle, WorkspacePreferences } from '@zakodium/nmrium-core';
22
import { Filters1D } from 'nmr-processing';
33

44
import { color2D } from '../../data/data2d/Spectrum2D/get2DColor.js';
55

6+
const defaultTextStyle: TextStyle = {
7+
fill: '#000000',
8+
fontSize: 16,
9+
fontStyle: 'normal',
10+
fontWeight: 'normal',
11+
};
12+
613
export const workspaceDefaultProperties: Required<WorkspacePreferences> = {
714
display: {
815
general: {
@@ -267,13 +274,15 @@ export const workspaceDefaultProperties: Required<WorkspacePreferences> = {
267274
format: 'D',
268275
couplingFormat: '0.0',
269276
deltaFormat: '0.0',
277+
textStyle: { ...defaultTextStyle },
270278
},
271279
'1H': {
272280
signalKind: 'signal',
273281
ascending: true,
274282
format: 'IMJA',
275283
couplingFormat: '0.00',
276284
deltaFormat: '0.00',
285+
textStyle: { ...defaultTextStyle },
277286
},
278287
},
279288
defaultMoleculeSettings: {

0 commit comments

Comments
 (0)