import EquationEditor from 'equation-editor-react'; import { IReactionDisposer } from 'mobx'; import { observer } from 'mobx-react'; import * as ReactDOM from 'react-dom'; import { Doc } from '../../../../fields/Doc'; import { StrCast } from '../../../../fields/Types'; import './DashFieldView.scss'; import { FormattedTextBox } from './FormattedTextBox'; import React = require('react'); export class EquationView { dom: HTMLDivElement; // container for label and value constructor(node: any, view: any, getPos: any, tbox: FormattedTextBox) { this.dom = document.createElement('div'); this.dom.style.width = node.attrs.width; this.dom.style.height = node.attrs.height; this.dom.style.position = 'relative'; this.dom.style.display = 'inline-block'; this.dom.onmousedown = function (e: any) { e.stopPropagation(); }; ReactDOM.render(, this.dom); (this as any).dom = this.dom; } _editor: EquationEditor | undefined; setEditor = (editor?: EquationEditor) => (this._editor = editor); destroy() { ReactDOM.unmountComponentAtNode(this.dom); } selectNode() { this._editor?.mathField.focus(); } deselectNode() {} } interface IEquationViewInternal { fieldKey: string; tbox: FormattedTextBox; width: number; height: number; setEditor: (editor: EquationEditor | undefined) => void; } @observer export class EquationViewInternal extends React.Component { _reactionDisposer: IReactionDisposer | undefined; _textBoxDoc: Doc; _fieldKey: string; _ref: React.RefObject = React.createRef(); constructor(props: IEquationViewInternal) { super(props); this._fieldKey = this.props.fieldKey; this._textBoxDoc = this.props.tbox.props.Document; } componentWillUnmount() { this._reactionDisposer?.(); } componentDidMount() { this.props.setEditor(this._ref.current ?? undefined); } render() { return (