Skip to content

Commit 0ffb89d

Browse files
authored
Merge pull request #14 from erlendoeien/#13
Fix #13
2 parents 907ea77 + 01c20ce commit 0ffb89d

1 file changed

Lines changed: 26 additions & 16 deletions

File tree

src/MathfieldComponent.tsx

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import 'mathlive/dist/mathlive.core.css';
2-
import 'mathlive/dist/mathlive.css';
3-
import * as React from 'react';
4-
import { makeMathField, MathfieldConfig, Mathfield } from 'mathlive';
1+
import * as React from "react";
2+
import { makeMathField, MathfieldConfig, Mathfield } from "mathlive";
53

64
interface BaseProps {
75
onChange?: (latex: string) => void;
86

9-
/**
7+
/**
108
* The raw options of mathlive's makeMathField.
119
* */
1210
mathfieldConfig?: MathfieldConfig;
@@ -31,20 +29,21 @@ export type Props = ControlledProps | UncontrolledProps;
3129

3230
export function combineConfig(props: Props): MathfieldConfig {
3331
const combinedConfiguration: MathfieldConfig = {
34-
...props.mathfieldConfig
32+
...props.mathfieldConfig,
3533
};
3634

3735
const { onChange } = props;
3836

3937
if (onChange) {
4038
if (props.mathfieldConfig && props.mathfieldConfig.onContentDidChange) {
4139
const fromConfig = props.mathfieldConfig.onContentDidChange;
42-
combinedConfiguration.onContentDidChange = mf => {
40+
combinedConfiguration.onContentDidChange = (mf) => {
4341
onChange(mf.$latex());
4442
fromConfig(mf);
4543
};
4644
} else {
47-
combinedConfiguration.onContentDidChange = mf => onChange(mf.$latex());
45+
combinedConfiguration.onContentDidChange = (mf) =>
46+
onChange(mf.$latex());
4847
}
4948
}
5049

@@ -63,34 +62,45 @@ export class MathfieldComponent extends React.Component<Props> {
6362
}
6463
if (prevProps.latex !== undefined) {
6564
if (this.props.latex === undefined) {
66-
throw new Error("Cannot change from controlled to uncontrolled state!");
65+
throw new Error(
66+
"Cannot change from controlled to uncontrolled state!"
67+
);
6768
}
6869
if (this.props.latex !== prevProps.latex) {
6970
if (this.props.latex === "") {
7071
this.mathfield.$perform("deleteAll");
7172
} else {
72-
this.mathfield.$latex(this.props.latex, { suppressChangeNotifications: true });
73+
this.mathfield.$latex(this.props.latex, {
74+
suppressChangeNotifications: true,
75+
});
7376
}
7477
}
7578
}
7679
}
7780

7881
render() {
79-
return <div ref={instance => this.insertElement = instance} />;
82+
return <div ref={(instance) => (this.insertElement = instance)} />;
8083
}
8184

8285
componentDidMount() {
8386
if (!this.insertElement) {
84-
throw new Error("React did apparently not mount the insert point correctly.");
87+
throw new Error(
88+
"React did apparently not mount the insert point correctly."
89+
);
8590
}
8691

8792
const initialValue = this.props.initialLatex ?? this.props.latex;
88-
89-
this.mathfield = makeMathField(this.insertElement, this.combinedConfiguration);
90-
this.mathfield.$latex(initialValue, { suppressChangeNotifications: true });
93+
94+
this.mathfield = makeMathField(
95+
this.insertElement,
96+
this.combinedConfiguration
97+
);
98+
this.mathfield.$latex(initialValue, {
99+
suppressChangeNotifications: true,
100+
});
91101

92102
if (this.props.mathfieldRef) {
93103
this.props.mathfieldRef(this.mathfield);
94104
}
95105
}
96-
}
106+
}

0 commit comments

Comments
 (0)