aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/EquationBox.tsx
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2024-05-19 01:01:02 -0400
committerbobzel <zzzman@gmail.com>2024-05-19 01:01:02 -0400
commit6e72f969029c22fe797397a6437836a0482260b6 (patch)
treee8ccde75702e557b2226c9069263e1bc3bd21a4b /src/client/views/nodes/EquationBox.tsx
parent5ff0bef5d3c4825aa7210a26c98aae3b24f4a835 (diff)
parent13dc6de0e0099f699ad0d2bb54401e6a0aa25018 (diff)
Merge branch 'restoringEslint' into alyssa-starter
Diffstat (limited to 'src/client/views/nodes/EquationBox.tsx')
-rw-r--r--src/client/views/nodes/EquationBox.tsx40
1 files changed, 25 insertions, 15 deletions
diff --git a/src/client/views/nodes/EquationBox.tsx b/src/client/views/nodes/EquationBox.tsx
index 50d4c7c78..1f5c9b84b 100644
--- a/src/client/views/nodes/EquationBox.tsx
+++ b/src/client/views/nodes/EquationBox.tsx
@@ -1,24 +1,26 @@
+/* eslint-disable jsx-a11y/no-static-element-interactions */
import { action, makeObservable, reaction } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
-import { Id } from '../../../fields/FieldSymbols';
+import { DivHeight, DivWidth } from '../../../ClientUtils';
+import { Doc } from '../../../fields/Doc';
import { NumCast, StrCast } from '../../../fields/Types';
import { TraceMobx } from '../../../fields/util';
+import { DocUtils } from '../../documents/DocUtils';
+import { DocumentType } from '../../documents/DocumentTypes';
import { Docs } from '../../documents/Documents';
import { undoBatch } from '../../util/UndoManager';
import { ViewBoxBaseComponent } from '../DocComponent';
-import { LightboxView } from '../LightboxView';
+import { DocumentView } from './DocumentView';
import './EquationBox.scss';
import { FieldView, FieldViewProps } from './FieldView';
import EquationEditor from './formattedText/EquationEditor';
-import { DivHeight, DivWidth } from '../../../Utils';
@observer
export class EquationBox extends ViewBoxBaseComponent<FieldViewProps>() {
public static LayoutString(fieldKey: string) {
return FieldView.LayoutString(EquationBox, fieldKey);
}
- public static SelectOnLoad: string = '';
_ref: React.RefObject<EquationEditor> = React.createRef();
constructor(props: FieldViewProps) {
@@ -28,12 +30,12 @@ export class EquationBox extends ViewBoxBaseComponent<FieldViewProps>() {
componentDidMount() {
this._props.setContentViewBox?.(this);
- if (EquationBox.SelectOnLoad === this.Document[Id] && (!LightboxView.LightboxDoc || LightboxView.Contains(this.DocumentView?.()))) {
+ if (Doc.SelectOnLoad === this.Document && (!DocumentView.LightboxDoc() || DocumentView.LightboxContains(this.DocumentView?.()))) {
this._props.select(false);
this._ref.current!.mathField.focus();
this.dataDoc.text === 'x' && this._ref.current!.mathField.select();
- EquationBox.SelectOnLoad = '';
+ Doc.SetSelectOnLoad(undefined);
}
reaction(
() => StrCast(this.dataDoc.text),
@@ -42,7 +44,7 @@ export class EquationBox extends ViewBoxBaseComponent<FieldViewProps>() {
this._ref.current!.mathField.latex(text);
}
}
- //{ fireImmediately: true }
+ // { fireImmediately: true }
);
reaction(
() => this._props.isSelected(),
@@ -68,7 +70,7 @@ export class EquationBox extends ViewBoxBaseComponent<FieldViewProps>() {
x: NumCast(this.layoutDoc.x),
y: NumCast(this.layoutDoc.y) + _height + 10,
});
- EquationBox.SelectOnLoad = nextEq[Id];
+ Doc.SetSelectOnLoad(nextEq);
this._props.addDocument?.(nextEq);
e.stopPropagation();
}
@@ -80,13 +82,17 @@ export class EquationBox extends ViewBoxBaseComponent<FieldViewProps>() {
_height: 300,
backgroundColor: 'white',
});
+ const link = DocUtils.MakeLink(this.Document, graph, { link_relationship: 'function', link_description: 'input' });
this._props.addDocument?.(graph);
+ link && this._props.addDocument?.(link);
e.stopPropagation();
}
if (e.key === 'Backspace' && !this.dataDoc.text) this._props.removeDocument?.(this.Document);
};
@undoBatch
- onChange = (str: string) => (this.dataDoc.text = str);
+ onChange = (str: string) => {
+ this.dataDoc.text = str;
+ };
updateSize = () => {
const style = this._ref.current && getComputedStyle(this._ref.current.element.current);
@@ -94,11 +100,10 @@ export class EquationBox extends ViewBoxBaseComponent<FieldViewProps>() {
if (this.layoutDoc._nativeWidth) {
// if equation has been scaled then editing the expression must also edit the native dimensions to keep the aspect ratio
const prevNwidth = NumCast(this.layoutDoc._nativeWidth);
- const prevNheight = NumCast(this.layoutDoc._nativeHeight);
- this.layoutDoc._nativeWidth = Math.max(35, Number(style.width.replace('px', '')));
- this.layoutDoc._nativeHeight = Math.max(25, Number(style.height.replace('px', '')));
+ const newNwidth = (this.layoutDoc._nativeWidth = Math.max(35, Number(style.width.replace('px', ''))));
+ const newNheight = (this.layoutDoc._nativeHeight = Math.max(25, Number(style.height.replace('px', ''))));
this.layoutDoc._width = (NumCast(this.layoutDoc._width) * NumCast(this.layoutDoc._nativeWidth)) / prevNwidth;
- this.layoutDoc._height = (NumCast(this.layoutDoc._height) * NumCast(this.layoutDoc._nativeHeight)) / prevNheight;
+ this.layoutDoc._height = (NumCast(this.layoutDoc._width) * newNheight) / newNwidth;
} else {
this.layoutDoc._width = Math.max(35, Number(style.width.replace('px', '')));
this.layoutDoc._height = Math.max(25, Number(style.height.replace('px', '')));
@@ -110,7 +115,7 @@ export class EquationBox extends ViewBoxBaseComponent<FieldViewProps>() {
const scale = (this._props.NativeDimScaling?.() || 1) * NumCast(this.layoutDoc._freeform_scale, 1);
return (
<div
- ref={r => this.updateSize()}
+ ref={() => this.updateSize()}
className="equationBox-cont"
onPointerDown={e => !e.ctrlKey && e.stopPropagation()}
style={{
@@ -121,8 +126,13 @@ export class EquationBox extends ViewBoxBaseComponent<FieldViewProps>() {
fontSize: StrCast(this.layoutDoc._text_fontSize),
}}
onKeyDown={e => e.stopPropagation()}>
- <EquationEditor ref={this._ref} value={StrCast(this.dataDoc.text, 'x')} spaceBehavesLikeTab={true} onChange={this.onChange} autoCommands="pi theta sqrt sum prod alpha beta gamma rho" autoOperatorNames="sin cos tan" />
+ <EquationEditor ref={this._ref} value={StrCast(this.dataDoc.text, 'x')} spaceBehavesLikeTab onChange={this.onChange} autoCommands="pi theta sqrt sum prod alpha beta gamma rho" autoOperatorNames="sin cos tan" />
</div>
);
}
}
+
+Docs.Prototypes.TemplateMap.set(DocumentType.EQUATION, {
+ layout: { view: EquationBox, dataField: 'text' },
+ options: { acl: '', fontSize: '14px', _layout_reflowHorizontal: true, _layout_reflowVertical: true, _layout_nativeDimEditable: true, layout_hideDecorationTitle: true, systemIcon: 'BsCalculatorFill' }, // systemIcon: 'BsSuperscript' + BsSubscript
+});