@@ -6,6 +6,8 @@ import _uniqWith from 'lodash/uniqWith';
66import _isEqual from 'lodash/isEqual' ;
77import { parsePseudoSymbolicAvailableSymbols , sanitiseInequalityState } from "../../../services/questions" ;
88import { GREEK_LETTERS_MAP } from '../../../services/constants' ;
9+ import { IsaacContentValueOrChildren } from '../../content/IsaacContentValueOrChildren' ;
10+ import { ContentDTO } from '../../../../IsaacApiTypes' ;
911
1012class MenuItem {
1113 public type : string ;
@@ -36,6 +38,7 @@ interface InequalityModalProps {
3638 editorMode ?: string ;
3739 logicSyntax ?: string ;
3840 visible : boolean ;
41+ questionDoc ?: ContentDTO ;
3942}
4043
4144interface InequalityModalState {
@@ -98,6 +101,48 @@ export class InequalityModal extends React.Component<InequalityModalProps> {
98101 private _logFunctionNames = [ "ln" , "log" ] ;
99102
100103 private _chemicalElements = [ "H" , "He" , "Li" , "Be" , "B" , "C" , "N" , "O" , "F" , "Ne" , "Na" , "Mg" , "Al" , "Si" , "P" , "S" , "Cl" , "Ar" , "K" , "Ca" , "Sc" , "Ti" , "V" , "Cr" , "Mn" , "Fe" , "Co" , "Ni" , "Cu" , "Zn" , "Ga" , "Ge" , "As" , "Se" , "Br" , "Kr" , "Rb" , "Sr" , "Y" , "Zr" , "Nb" , "Mo" , "Tc" , "Ru" , "Rh" , "Pd" , "Ag" , "Cd" , "In" , "Sn" , "Sb" , "Te" , "I" , "Xe" , "Cs" , "Ba" , "La" , "Ce" , "Pr" , "Nd" , "Pm" , "Sm" , "Eu" , "Gd" , "Tb" , "Dy" , "Ho" , "Er" , "Tm" , "Yb" , "Lu" , "Hf" , "Ta" , "W" , "Re" , "Os" , "Ir" , "Pt" , "Au" , "Hg" , "Tl" , "Pb" , "Bi" , "Po" , "At" , "Rn" , "Fr" , "Ra" , "Ac" , "Th" , "Pa" , "U" , "Np" , "Pu" , "Am" , "Cm" , "Bk" , "Cf" , "Es" , "Fm" , "Md" , "No" , "Lr" , "Rf" , "Db" , "Sg" , "Bh" , "Hs" , "Mt" , "Ds" , "Rg" , "Cn" , "Nh" , "Fl" , "Mc" , "Lv" , "Ts" , "Og" ] ;
104+ private _chemicalParticles : { [ key : string ] : { type : string ; menu : { label : string ; texLabel : boolean ; className ?: string ; fontSize ?: string } ; properties : object } } = {
105+ alpha : {
106+ type : 'Particle' ,
107+ menu : { label : '\\alpha' , texLabel : true } ,
108+ properties : { particle : 'α' , type : 'alpha' }
109+ } ,
110+ beta : {
111+ type : 'Particle' ,
112+ menu : { label : '\\beta' , texLabel : true } ,
113+ properties : { particle : 'β' , type : 'beta' }
114+ } ,
115+ gamma : {
116+ type : 'Particle' ,
117+ menu : { label : '\\gamma' , texLabel : true } ,
118+ properties : { particle : 'γ' , type : 'gamma' }
119+ } ,
120+ neutrino : {
121+ type : 'Particle' ,
122+ menu : { label : '\\nu' , texLabel : true } ,
123+ properties : { particle : 'ν' , type : 'neutrino' }
124+ } ,
125+ antineutrino : {
126+ type : 'Particle' ,
127+ menu : { label : '\\bar{\\nu}' , texLabel : true } ,
128+ properties : { particle : 'ν̅' , type : 'antineutrino' }
129+ } ,
130+ proton : {
131+ type : 'Particle' ,
132+ menu : { label : '\\text{p}' , texLabel : true } ,
133+ properties : { particle : 'p' , type : 'proton' }
134+ } ,
135+ neutron : {
136+ type : 'Particle' ,
137+ menu : { label : '\\text{n}' , texLabel : true } ,
138+ properties : { particle : 'n' , type : 'neutron' }
139+ } ,
140+ electron : {
141+ type : 'Particle' ,
142+ menu : { label : '\\text{e}' , texLabel : true } ,
143+ properties : { particle : 'e' , type : 'electron' }
144+ }
145+ } ;
101146
102147 private _differentialRegex = / ^ ( D e l t a | d e l t a | d ) \s * (?: \^ ( [ 0 - 9 ] + ) ) ? \s * ( [ a - z A - Z ] + (?: (?: _ | \^ ) .+ ) ? ) / ;
103148 private _availableSymbols ?: string [ ] ;
@@ -283,9 +328,12 @@ export class InequalityModal extends React.Component<InequalityModalProps> {
283328 }
284329 } else {
285330 // Everything else is a letter, unless we are doing chemistry
286- if ( this . props . editorMode === 'chemistry' && / ^ [ A - Z ] / . test ( availableSymbol ) ) {
331+ if ( this . props . editorMode === 'chemistry' ) {
287332 // Available chemical elements
288- customMenuItems . chemicalElements . push ( this . makeChemicalElementMenuItem ( availableSymbol ) ) ;
333+ const item = this . makeChemicalElementMenuItem ( availableSymbol ) ;
334+ if ( item ) {
335+ customMenuItems . chemicalElements . push ( item ) ;
336+ }
289337 } else {
290338 const item = this . makeLetterMenuItem ( availableSymbol ) ;
291339 if ( item ) {
@@ -333,7 +381,7 @@ export class InequalityModal extends React.Component<InequalityModalProps> {
333381 this . setState ( ( prevState : InequalityModalState ) => ( {
334382 menuItems : {
335383 ...prevState . menuItems ,
336- chemicalElements : this . _chemicalElements . map ( element => this . makeChemicalElementMenuItem ( element ) ) ,
384+ chemicalElements : [ ... this . _chemicalElements , ... Object . keys ( this . _chemicalParticles ) ] . map ( element => this . makeChemicalElementMenuItem ( element ) ) ,
337385 }
338386 } ) ) ;
339387 } else {
@@ -478,7 +526,7 @@ export class InequalityModal extends React.Component<InequalityModalProps> {
478526 new MenuItem ( "AbsoluteValue" , { } , { label : '\\small{|x|}' , texLabel : true , className : 'abs' } ) ,
479527 new MenuItem ( "Radix" , { } , { label : '\\small{\\sqrt{x}}' , texLabel : true , className : 'radix sqrt' } ) ,
480528 new MenuItem ( "Relation" , { relation : '=' } , { label : '=' , texLabel : true , className : 'relation equal' } ) ,
481- new MenuItem ( "Relation" , { relation : '<' } , { label : '> ' , texLabel : true , className : 'relation less' } ) ,
529+ new MenuItem ( "Relation" , { relation : '<' } , { label : '< ' , texLabel : true , className : 'relation less' } ) ,
482530 new MenuItem ( "Relation" , { relation : '>' } , { label : '>' , texLabel : true , className : 'relation greater' } ) ,
483531 new MenuItem ( "Relation" , { relation : '<=' } , { label : '\\leq' , texLabel : true , className : 'relation less-or-equal' } ) ,
484532 new MenuItem ( "Relation" , { relation : '>=' } , { label : '\\geq' , texLabel : true , className : 'relation greater-or-equal' } ) ,
@@ -672,7 +720,11 @@ export class InequalityModal extends React.Component<InequalityModalProps> {
672720 }
673721
674722 private makeChemicalElementMenuItem ( symbol : string ) {
675- return new MenuItem ( 'ChemicalElement' , { element : symbol } , { label : `\\text{${ symbol } }` , texLabel : true , className : `chemical-element ${ symbol } ` } ) ;
723+ if ( this . _chemicalElements . includes ( symbol ) ) {
724+ return new MenuItem ( 'ChemicalElement' , { element : symbol } , { label : `\\text{${ symbol } }` , texLabel : true , className : `chemical-element ${ symbol } ` } ) ;
725+ } else if ( this . _chemicalParticles . hasOwnProperty ( symbol ) ) {
726+ return new MenuItem ( 'Particle' , this . _chemicalParticles [ symbol ] . properties , { ...this . _chemicalParticles [ symbol ] . menu , className : `chemical-particle ${ symbol } ` } ) ;
727+ }
676728 }
677729
678730 private makeChemicalStatesMenuItems ( ) {
@@ -802,10 +854,14 @@ export class InequalityModal extends React.Component<InequalityModalProps> {
802854 const trashCanRect = trashCan . getBoundingClientRect ( ) ;
803855 if ( trashCanRect && x >= trashCanRect . left && x <= trashCanRect . right && y >= trashCanRect . top && y <= trashCanRect . bottom ) {
804856 trashCan . classList . add ( 'active' ) ;
805- this . setState ( { trashActive : true } ) ;
857+ if ( ! this . state . trashActive ) {
858+ this . setState ( { trashActive : true } ) ;
859+ }
806860 } else {
807861 trashCan . classList . remove ( 'active' ) ;
808- this . setState ( { trashActive : false } ) ;
862+ if ( this . state . trashActive ) {
863+ this . setState ( { trashActive : false } ) ;
864+ }
809865 }
810866 }
811867
@@ -1105,6 +1161,12 @@ export class InequalityModal extends React.Component<InequalityModalProps> {
11051161 > Centre</ div >
11061162 < div id = "inequality-trash" className = "inequality-ui trash button" > Trash</ div >
11071163 < div className = "beta-badge" > beta</ div >
1164+ { ( this . props . questionDoc ?. value || ( this . props . questionDoc ?. children && this . props . questionDoc ?. children ?. length > 0 ) ) && < div className = "question-reminder" >
1165+ < IsaacContentValueOrChildren value = { this . props . questionDoc . value } encoding = { this . props . questionDoc . encoding } >
1166+ { this . props . questionDoc ?. children }
1167+ </ IsaacContentValueOrChildren >
1168+ </ div > }
1169+ < div className = "orientation-warning" > The Isaac Equation Editor may only be used in landscape mode. Please rotate your device.</ div >
11081170 { menu }
11091171 </ div > ;
11101172 }
0 commit comments