@teachinglab/omd 0.3.5 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/omdEquation.js +59 -32
- package/src/omdString.js +1 -1
package/package.json
CHANGED
package/src/omdEquation.js
CHANGED
|
@@ -42,42 +42,69 @@ export class omdEquation extends omdMetaExpression
|
|
|
42
42
|
|
|
43
43
|
loadFromJSON( data )
|
|
44
44
|
{
|
|
45
|
-
|
|
45
|
+
// If explicit left/right JSON provided, build them according to their omdType
|
|
46
|
+
if ( typeof data.leftExpression != "undefined" && data.leftExpression )
|
|
46
47
|
{
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.
|
|
59
|
-
|
|
48
|
+
const left = data.leftExpression;
|
|
49
|
+
if ( left.omdType == "expression" ) this.leftExpression = new omdExpression();
|
|
50
|
+
else if ( left.omdType == "number" ) this.leftExpression = new omdNumber();
|
|
51
|
+
else if ( left.omdType == "variable" ) this.leftExpression = new omdVariable();
|
|
52
|
+
else if ( left.omdType == "term" ) this.leftExpression = new omdTerm();
|
|
53
|
+
else if ( left.omdType == "string" || typeof left == 'string' ) this.leftExpression = new omdString( typeof left == 'string' ? left : left.name || '' );
|
|
54
|
+
|
|
55
|
+
if (this.leftExpression && typeof this.leftExpression.loadFromJSON === 'function' && left && typeof left === 'object') {
|
|
56
|
+
this.leftExpression.loadFromJSON( left );
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (this.leftExpression) {
|
|
60
|
+
this.leftHolder.removeAllChildren();
|
|
61
|
+
this.leftHolder.addChild( this.leftExpression );
|
|
62
|
+
}
|
|
60
63
|
}
|
|
61
|
-
|
|
64
|
+
|
|
65
|
+
if ( typeof data.rightExpression != "undefined" && data.rightExpression )
|
|
62
66
|
{
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
this.
|
|
75
|
-
|
|
67
|
+
const right = data.rightExpression;
|
|
68
|
+
if ( right.omdType == "expression" ) this.rightExpression = new omdExpression();
|
|
69
|
+
else if ( right.omdType == "number" ) this.rightExpression = new omdNumber();
|
|
70
|
+
else if ( right.omdType == "variable" ) this.rightExpression = new omdVariable();
|
|
71
|
+
else if ( right.omdType == "term" ) this.rightExpression = new omdTerm();
|
|
72
|
+
else if ( right.omdType == "string" || typeof right == 'string' ) this.rightExpression = new omdString( typeof right == 'string' ? right : right.name || '' );
|
|
73
|
+
|
|
74
|
+
if (this.rightExpression && typeof this.rightExpression.loadFromJSON === 'function' && right && typeof right === 'object') {
|
|
75
|
+
this.rightExpression.loadFromJSON( right );
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (this.rightExpression) {
|
|
79
|
+
this.rightHolder.removeAllChildren();
|
|
80
|
+
this.rightHolder.addChild( this.rightExpression );
|
|
81
|
+
}
|
|
76
82
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this.leftExpression.
|
|
80
|
-
|
|
83
|
+
|
|
84
|
+
// If no structured left/right provided but an `equation` string exists, parse it into simple string nodes
|
|
85
|
+
if ( (!this.leftExpression || !this.rightExpression) && typeof data.equation === 'string' ) {
|
|
86
|
+
const eq = data.equation || '';
|
|
87
|
+
const parts = eq.split('=');
|
|
88
|
+
const leftStr = (parts[0] || '').trim();
|
|
89
|
+
const rightStr = (parts[1] || '').trim();
|
|
90
|
+
|
|
91
|
+
if (!this.leftExpression) this.leftExpression = new omdString(leftStr || '');
|
|
92
|
+
if (!this.rightExpression) this.rightExpression = new omdString(rightStr || '');
|
|
93
|
+
|
|
94
|
+
if (this.leftExpression) {
|
|
95
|
+
this.leftHolder.removeAllChildren();
|
|
96
|
+
this.leftHolder.addChild(this.leftExpression);
|
|
97
|
+
}
|
|
98
|
+
if (this.rightExpression) {
|
|
99
|
+
this.rightHolder.removeAllChildren();
|
|
100
|
+
this.rightHolder.addChild(this.rightExpression);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Guarded calls to hide backgrounds only when components exist
|
|
105
|
+
if (this.equalSign && typeof this.equalSign.hideBackgroundByDefault === 'function') this.equalSign.hideBackgroundByDefault();
|
|
106
|
+
if (this.leftExpression && typeof this.leftExpression.hideBackgroundByDefault === 'function') this.leftExpression.hideBackgroundByDefault();
|
|
107
|
+
if (this.rightExpression && typeof this.rightExpression.hideBackgroundByDefault === 'function') this.rightExpression.hideBackgroundByDefault();
|
|
81
108
|
|
|
82
109
|
this.centerEquation = false;
|
|
83
110
|
this.updateLayout();
|
package/src/omdString.js
CHANGED