Skip to content

Commit 0771877

Browse files
committed
Intermediate commit
- install sample branch for Custom Equations - refactorings - Release v1.0.10 prepared
1 parent a15a8c8 commit 0771877

12 files changed

Lines changed: 375 additions & 71 deletions

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ The custom equations dialog with categories tree
9999

100100
## Release Notes
101101

102+
### 1.0.10
103+
104+
- Fixed a lot of warnings in HTML.
105+
- Bug fix: 2 of the diagrams in CD dialog did not render properly.
106+
- Bug fix: a tool tip in the CD dialog did not show up properly.
107+
- Improvement: the tool tip handling was unified, all tool tips use *Themes* now.
108+
102109
### 1.0.9
103110

104111
- Bug fix: A bug caused a circular reference during JSON conversion.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "joplin-plugin-katex-input-helper",
3-
"version": "1.0.9",
3+
"version": "1.0.10",
44
"scripts": {
55
"dist": "webpack --env joplin-plugin-config=buildMain && webpack --env joplin-plugin-config=buildExtraScripts && webpack --env joplin-plugin-config=createArchive",
66
"prepare": "npm run dist",

src/assets/formulas/f_COMMUTATIVE_DIAGRAM_MORE.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
<table style="border-spacing:0px; border-collapse:collapse; ">
33
<tr style="font-size:115%">
4-
<td><a style=text-align:left href="#" class=s latex="\begin{CD}
4+
<td><a style="text-align:left" href="#" class="s" latex="\begin{CD}
55
A @>a>> B\\
66
@VVbV @VVcV\\
77
C @>d>> D
@@ -15,10 +15,10 @@
1515
</a></td>
1616
</tr>
1717
<tr style="font-size:115%">
18-
<td><a style=text-align:left href="" class=s latex="\begin{CD}
18+
<td><a style="text-align:left" href="#" class="s" latex="\begin{CD}
1919
A @>a>b> B\\
2020
@VlVrV @AlArA\\
21-
C @<a<b< D
21+
C @&lt;a&lt;b&lt; D
2222
\end{CD} ">
2323
$$\begin{CD}
2424
A @>a>b> B\\
@@ -29,7 +29,7 @@
2929
</a></td>
3030
</tr>
3131
<tr style="font-size:115%">
32-
<td><a style=text-align:left href="#" class=s latex="\begin{CD}
32+
<td><a style="text-align:left" href="#" class="s" latex="\begin{CD}
3333
A @<<< B @>>> C\\
3434
@. @| @AAA\\
3535
@. D @= E
@@ -43,7 +43,7 @@
4343
</a></td>
4444
</tr>
4545
<tr style="font-size:115%">
46-
<td><a style=text-align:left href="#" class=s latex="\begin{CD}
46+
<td><a style="text-align:left" href="#" class="s" latex="\begin{CD}
4747
A @>>> B @>{\text{very long label}}>> C \\
4848
@VVV @VVV @VVV \\
4949
D @>>> E @>{\rlap{\scriptstyle{\ \ \ \text{shorter}}}\phantom{\text{very long label}}}>> F
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
{
2+
"text": "Categories",
3+
"state": "open",
4+
"selected": "/Categories/Default",
5+
"children": [
6+
{
7+
"text": "Mathematical",
8+
"state": "open",
9+
"children": [
10+
{
11+
"text": "Calculus",
12+
"attributes": {
13+
"equations": []
14+
},
15+
"state": "open",
16+
"children": []
17+
}
18+
]
19+
},
20+
{
21+
"text": "Physical",
22+
"state": "closed",
23+
"children": []
24+
},
25+
{
26+
"text": "Samples",
27+
"state": "open",
28+
"children": [
29+
{
30+
"text": "Mathematical",
31+
"state": "open",
32+
"children": [
33+
{
34+
"text": "Algebra",
35+
"attributes": {
36+
"equations": []
37+
},
38+
"state": "open",
39+
"children": []
40+
},
41+
{
42+
"text": "Calculus",
43+
"attributes": {
44+
"equations": []
45+
},
46+
"state": "open",
47+
"children": []
48+
},
49+
{
50+
"text": "Topology",
51+
"attributes": {
52+
"equations": []
53+
},
54+
"state": "open",
55+
"children": []
56+
}
57+
]
58+
},
59+
{
60+
"text": "Physical",
61+
"state": "open",
62+
"children": [
63+
{
64+
"text": "Elektrodynamic",
65+
"attributes": {
66+
"equations": [
67+
[
68+
"Amperes law",
69+
"\\nabla \\times \\vec{\\mathbf{B}} - \\frac{1}{c} \\frac{\\partial\\vec{\\mathbf{E}}}{\\partial t} = \\frac{4\\pi}{c}\\vec{\\mathbf{j}} "
70+
],
71+
[
72+
"Gauss's law",
73+
"\\nabla \\cdot \\vec{\\mathbf{E}} = 4 \\pi \\rho "
74+
],
75+
[
76+
"Gauss's law for magnetism",
77+
"\\nabla \\cdot \\vec{\\mathbf{B}} = 0 "
78+
],
79+
[
80+
"Maxwell-Faraday equation",
81+
"\\nabla \\times \\vec{\\mathbf{E}} + \\frac{1}{c} \\frac{\\partial\\vec{\\mathbf{B}}}{\\partial t} = \\vec{\\mathbf{0}} "
82+
]
83+
]
84+
},
85+
"state": "open",
86+
"children": []
87+
},
88+
{
89+
"text": "Mechanic",
90+
"attributes": {
91+
"equations": [
92+
[
93+
"Newton's first law",
94+
"\\sum{\\vec{F} } = \\vec{0} \\Rightarrow \\frac{d\\vec{v}}{dt} = 0 "
95+
],
96+
[
97+
"Newton's second law",
98+
"\\vec{F} = \\frac{d \\vec{p}}{dt} = m \\frac{d \\vec{v}}{dt} = m \\vec{a} "
99+
],
100+
[
101+
"Newton's third law",
102+
"\\vec{F}_A = - \\vec{F}_B "
103+
]
104+
]
105+
},
106+
"state": "open",
107+
"children": []
108+
},
109+
{
110+
"text": "Quantum",
111+
"attributes": {
112+
"equations": [
113+
[
114+
"Schrödinger",
115+
"\\frac{\\hat{\\vec{\\mathbf{p}}}^2}{2m}\\left| \\Psi (t)\\right\\rangle + V(\\hat{\\vec{\\mathbf{r}}},t)\\left| \\Psi (t) \\right\\rangle=i \\hbar {d\\over dt} \\left| \\Psi (t) \\right\\rangle"
116+
]
117+
]
118+
},
119+
"state": "open",
120+
"children": []
121+
},
122+
{
123+
"text": "Relativity",
124+
"attributes": {
125+
"equations": [
126+
[
127+
"Mass-energy equivalence",
128+
"E = mc^2 "
129+
]
130+
]
131+
},
132+
"state": "open",
133+
"children": []
134+
},
135+
{
136+
"text": "Thermodynamic",
137+
"attributes": {
138+
"equations": [
139+
[
140+
"First law of thermodynamics",
141+
"dU = \\delta Q - \\delta W "
142+
],
143+
[
144+
"Second law of thermodynamics",
145+
"dS = \\frac{\\delta Q}{T} "
146+
],
147+
[
148+
"Third law of thermodynamics",
149+
"S = k_B \\ln{\\Omega}"
150+
]
151+
]
152+
},
153+
"state": "open",
154+
"children": []
155+
}
156+
]
157+
}
158+
]
159+
},
160+
{
161+
"text": "Default",
162+
"attributes": {
163+
"equations": [
164+
[
165+
"Latex",
166+
" \\LaTeX"
167+
],
168+
[
169+
"Integral",
170+
"\\int_{a}^{b}{f(x)dx }"
171+
]
172+
]
173+
},
174+
"state": "open",
175+
"children": []
176+
}
177+
]
178+
}

src/assets/js/categoriesTree.js

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ class CategoriesTree {
3939
return this._tree;
4040
}
4141

42+
/**
43+
* @abstract The Custom Equations setter.
44+
*
45+
* The whole data set, JSON compatible, with categories and equations.
46+
* This variant adds also some Sample data.
47+
*
48+
* @async the async variant with Promise contract
49+
*/
50+
async setCustomEquations(value) {
51+
var converted = this.convert(value);
52+
converted = await this.addSamples(converted);
53+
this.data = this.getCustomEquationsProxy(converted);
54+
this.initialise(); // it is essential to invoke it here before currentEquations
55+
}
56+
4257
/**
4358
* @abstract The Custom Equations setter.
4459
*
@@ -62,7 +77,6 @@ class CategoriesTree {
6277
/** @abstract Use this construct to make copies
6378
*/
6479
getCustomEquationsProxy(data) {
65-
var inst = this;
6680
var rows = null;
6781
rows = [ data ];
6882
return _proxy(rows);
@@ -71,7 +85,7 @@ class CategoriesTree {
7185
* @abstract Copy a single node with relevant data.
7286
*/
7387
function _copy(from) {
74-
var keys = ['text', 'state', 'attributes', 'selected'];
88+
var keys = ['text', 'state', 'attributes', 'selected', 'haveSamples'];
7589
var to = { };
7690
for (var key of Object.keys(from)) {
7791
if (keys.includes(key)) {
@@ -513,6 +527,59 @@ class CategoriesTree {
513527
}]
514528
};
515529
}
530+
531+
/**
532+
* @abstract Adds a Samples branch to the Categories tree.
533+
*
534+
* This routine secures against repeated insertions.
535+
*
536+
* @param from - the Categories (Custom Equations) tree as from JSON
537+
* @result the changed tree with added Samples
538+
*/
539+
async addSamples(from) {
540+
541+
/**
542+
* Searches from a given start node down the hierarchy until node with text is found.
543+
*/
544+
function getSamplesNode(node, text) {
545+
546+
return _traverse(node.children);
547+
548+
function _traverse(nodes) {
549+
for (var node of nodes) {
550+
if (node.text === text) {
551+
return node;
552+
}
553+
var children = node.children;
554+
if (children && children.length) {
555+
var found = _traverse(children);
556+
if (found) {
557+
return found;
558+
}
559+
}
560+
}
561+
return undefined;
562+
}
563+
}
564+
565+
/**
566+
* @abstract Loads a JSON file and returns the object.
567+
*/
568+
async function loadSamples() {
569+
570+
var response = await fetch('formulas/sampleEquations.json');
571+
return await response.json();
572+
}
573+
574+
if (!from.haveSamples && !getSamplesNode(from, "Samples")) {
575+
576+
var samples = await loadSamples();
577+
samples = getSamplesNode(samples, "Samples");
578+
from.children.push(samples)
579+
from.haveSamples = true;
580+
}
581+
return from;
582+
}
516583

517584
/**
518585
* @abstract Sort routine. Sorts the whole category tree.
@@ -618,7 +685,6 @@ class CategoriesTree {
618685
function _traverse(nodes, ...args) {
619686
for (var node of nodes) {
620687
inst.findNode(node);
621-
// console.debug(`Traversing : row : ${node.text}, state : ${node.state}, isLeaf : ${inst.tree.tree('isLeaf', node.target)} `);
622688
func(node, ...args);
623689
var children = node.children;
624690
if (children && children.length) {

src/assets/js/dialog.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,3 +354,12 @@ h3 {
354354
.katex {
355355
pointer-events: none;
356356
}
357+
358+
/* THERE IS NO ACTION ON THIS
359+
*/
360+
.tooltip {
361+
background-color: 'lightyellow'!;
362+
border-color: 'red';
363+
width: 500;
364+
z-index: 500000!;
365+
}

src/assets/js/dialog.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class Documentations {
107107
*/
108108
class KatexInputHelper {
109109

110-
version = "1.0.7";
110+
version = "1.0.10";
111111
codeType = 'Latex';
112112
saveOptionInCookies = false;
113113
isBuild = false;
@@ -1525,12 +1525,11 @@ class KatexInputHelper {
15251525
if (typeof ($(a).attr("latex")) != "undefined")
15261526
return $(a).attr("latex");
15271527
}
1528-
15291528
$(`#${fPanelID} a.s`)
1530-
.addClass("easyui-tooltip")
1531-
.attr("title", function(index, attr) { return getSymbol(this); })
1532-
.mouseover(function(event) { $("#divInformation").html(getSymbol(this)); })
1533-
.mouseout(function(event) { $("#divInformation").html("&nbsp;"); })
1529+
.each(function() {
1530+
var tt = getSymbol(this);
1531+
vme.math.equipWithTooltip($(this), tt, true);
1532+
})
15341533
.click(function(event) {
15351534
event.preventDefault();
15361535
var info = beginEndInfo(this);
@@ -1600,7 +1599,7 @@ class KatexInputHelper {
16001599

16011600
// updates exactly 2 dialogs (see selectors)
16021601
// TODO: necessary and additional ones required?
1603-
vme.math.inplaceUpdate('#tEQUATION div a.s[latex], #mSPECIAL_CHARACTER div a.s[latex]'); // where and when to do that
1602+
vme.math.inplaceUpdate('#tEQUATION div a.s[latex], #mSPECIAL_CHARACTER div a.s[latex]', true); // where and when to do that
16041603
}
16051604

16061605
/**

0 commit comments

Comments
 (0)