Skip to content

Commit c85f568

Browse files
committed
Prepared Release v2.1.1
- math tests completed
1 parent 97024c4 commit c85f568

33 files changed

Lines changed: 621 additions & 460 deletions

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ The custom equations dialog with categories tree
9797

9898
## Release Notes
9999

100+
### 2.1.1
101+
102+
- Removed function-less code.
103+
- Minor bug fixes.
104+
- Added unit tests (still under development).
105+
100106
### 2.1.0
101107

102108
**New features**

__mocks__/codeMirrorProxy.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
import { ICodeMirror } from '../src/assets/js/interfaces'
3+
4+
export function codeMirrorFakeProxy(original: ICodeMirror) : ICodeMirror {
5+
let value = "";
6+
7+
let fake = {
8+
getValue : () => value,
9+
replaceSelection : (b: string) => {
10+
//console.info(`replaceSelection: ${b}`);
11+
value = b;
12+
},
13+
getSelection : () => "",
14+
setCursor: (cursor) => { },
15+
getCursor: () => { return { ch: 0 }; },
16+
focus : () => { },
17+
}
18+
19+
return { ...original, ...fake};
20+
}

__mocks__/math.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import './jquery-easyui/jquery.easyui.min'; // ADDED for unit test
22
import { it, expect, describe, vi, beforeEach, afterEach } from 'vitest';
3-
import { IMath } from '../tests/interfaces';
4-
import { container } from '../tests/container';
3+
import { IMath } from '@/js/interfaces';
4+
import { container } from './tests/container';
55

66
/* DID NOT WORK as MOCK
77
*/
@@ -15,14 +15,14 @@ export class MathFormulae implements IMath {
1515
equipWithTooltip(selector: any, text: string, javascript: boolean) { }
1616
inplaceUpdate(selector: any, javascript: boolean) { }
1717
insert(b: any) { }
18-
insertMath(text: string, element: any, multiple: boolean, displayMode: boolean) { };
19-
codeMirror: any { return { }; }
18+
insertMath(text: string, element: any, multiple: boolean, displayMode: boolean) { }
19+
codeMirror: any;
2020
setFocus() { }
2121
updateAnchor(a: any) { }
2222
updateHeaders(selector: string) { }
2323
updateLatexMenu() { }
2424
updateOutput() { }
25-
updateTables() : Promise<void> { return new Promise(); }
25+
updateTables() : Promise<void> { return new Promise<void>(); }
2626
}
2727

2828
// This helps to import symbols in test suite

__mocks__/messager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IMessager } from '@/js/interfaces';
22

3-
export class Messager implements IMessager {
3+
export class MessagerFake implements IMessager {
44
error(msgKey: string, e: any) { }
55
show(titleKey: string, msgKey: string, e?: any) { }
66
}

__mocks__/supplement.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import { inject, injectable } from 'inversify';
2+
import { IMath, mathId, ICodeMirror } from '../src/assets/js/interfaces';
3+
import { ISupplement } from '../tests/interfaces';
4+
5+
export class Supplement implements ISupplement {
6+
math: IMath;
7+
codeMirrorEditor: ICodeMirror;
8+
9+
constructor(
10+
@inject(mathId) math: IMath
11+
) {
12+
this.math = math;
13+
this.codeMirrorEditor = math.codeMirror;
14+
this.initialiseSymbolContent();
15+
}
16+
17+
/**
18+
* The routine equips the entries in the given panel with functionality.
19+
*
20+
* This is:
21+
* - tool tip
22+
* - info line
23+
* - click event
24+
*/
25+
initialiseSymbolContent() {
26+
let vme = this;
27+
/**
28+
* Given an anchor object, determines and returns the included
29+
* LATEX code used as info for tool tip and info line.
30+
*/
31+
function getSymbol(a: any) {
32+
let info: any = beginEndInfo(a);
33+
if (info !== null) return info[0] + info[1];
34+
info = latex(a);
35+
if (info !== null) return info;
36+
return "";
37+
};
38+
39+
/**
40+
* Returns the begin to end info of an anchor.
41+
*/
42+
function beginEndInfo(a: any) {
43+
if (typeof ($(a).attr("lbegin")) != "undefined" && typeof ($(a).attr("lend")) != "undefined")
44+
return [$(a).attr("lbegin"), $(a).attr("lend")];
45+
return null;
46+
};
47+
48+
/**
49+
* Returns the latex info of an anchor.
50+
*/
51+
function latex(a: any) {
52+
if (typeof ($(a).attr("latex")) != "undefined")
53+
return $(a).attr("latex");
54+
return null;
55+
};
56+
57+
$(`a.s`)
58+
.each(function() {
59+
let tt = getSymbol(this);
60+
vme.math.equipWithTooltip($(this), tt, true);
61+
});
62+
$('#test-container').on('click', `a.s`, function(event) {
63+
event.preventDefault();
64+
let info: any = beginEndInfo(this);
65+
if (info !== null) {
66+
const [ a, b ] = info;
67+
vme.tag(a, b);
68+
return;
69+
}
70+
info = latex(this);
71+
if (info !== null) {
72+
vme.insert(info);
73+
}
74+
});
75+
}
76+
77+
78+
/**
79+
* Wrapper of the appropriate Math routine. Inserts a piece of
80+
* math code into the editor and updates the output.
81+
*/
82+
insert(b: string) {
83+
this.math.insert(b);
84+
this.codeMirrorEditor.focus();
85+
}
86+
87+
/**
88+
* Insertion code for formulae with placeholder.
89+
*/
90+
tag(b: any, a: any) {
91+
b = b || null;
92+
a = a || b;
93+
if (!b || !a) { return }
94+
this.codeMirrorEditor.replaceSelection(b + this.codeMirrorEditor.getSelection() + a);
95+
let pos = this.codeMirrorEditor.getCursor();
96+
pos.ch = pos.ch - a.length;
97+
this.codeMirrorEditor.setCursor(pos);
98+
this.math.updateOutput();
99+
this.codeMirrorEditor.focus();
100+
}
101+
102+
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "joplin-plugin-katex-input-helper",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"scripts": {
55
"dist": "webpack --env joplin-plugin-config=buildMain && webpack --env joplin-plugin-config=buildExtraScripts && npm run build-assets-prod && npm run build-docs && webpack --env joplin-plugin-config=createArchive",
66
"prepare": "npm run dist",
77
"updateVersion": "webpack --env joplin-plugin-config=updateVersion",
88
"update": "npm install -g generator-joplin && yo joplin --node-package-manager npm --update --force",
99
"build-docs": "typedoc --options typedoc.json --tsconfig src/assets/tsconfig.json && npm exec --package=@atao60/fse-cli fse copy ./img ./docs/img",
10-
"test": "vitest --root './tests' --run --reporter verbose",
10+
"test": "vitest --root './tests' --run --reporter verbose --no-cache",
1111
"jtest": "jest",
1212
"build-assets": "webpack --config webpack.assets.config.js",
1313
"build-assets-prod": "webpack --config webpack.assets.config.js --env kihmode=production",

src/assets/dialog.html

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,6 @@ <h3>Katex Input Helper</h3>
110110
</div>
111111
</div>
112112
<div id="mTOOLS" class="menus">
113-
<div iconcls="icon-html_off" id="mHTML_MODE" disabled="true">
114-
<span class='rtl-menu-item' locate="HTML_MODE"></span>
115-
</div>
116-
<div class="menu-sep"></div>
117113
<div iconcls="icon-keyboard" id="mKEYBOARD">
118114
<span class='rtl-menu-item' locate="KEYBOARD"></span>
119115
</div>
@@ -208,32 +204,6 @@ <h3>Katex Input Helper</h3>
208204
<input value="" class="keyboardInput" id="tKEYBOARD" />
209205

210206
<div id="innerLayout" data-options="fit:true" class="easyui-layout">
211-
212-
<div id="HTML_TAG" class="north easyui-panel" data-options="region:'north',split:false,noheader:true" disabled="true">
213-
<a href="#" title="Latex" class="easyui-linkbutton easyui-tooltip" id="btHTML_Latex" disabled="true"><strong>$</strong></a>
214-
<a href="#" title="AsciiMath" class="easyui-linkbutton easyui-tooltip" id="btHTML_AsciiMath" disabled="true"><strong>`</strong></a> |
215-
<a href="#" title="span color" class="easyui-linkbutton easyui-tooltip" iconcls="icon-text_color" id="btHTML_TEXTCOLOR"></a>
216-
<a href="#" title="span background-color" class="easyui-linkbutton easyui-tooltip" iconcls="icon-fore_color" id="btHTML_FORECOLOR"></a> |
217-
<a href="#" title="h1" class="easyui-linkbutton easyui-tooltip" iconcls="icon-text_heading_1" id="btHTML_H1"></a>
218-
<a href="#" title="h2" class="easyui-linkbutton easyui-tooltip" iconcls="icon-text_heading_2" id="btHTML_H2"></a>
219-
<a href="#" title="h3" class="easyui-linkbutton easyui-tooltip" iconcls="icon-text_heading_3" id="btHTML_H3"></a> |
220-
<a href="#" title="strong" class="easyui-linkbutton easyui-tooltip" iconcls="icon-text_bold" id="btHTML_STRONG"></a>
221-
<a href="#" title="em" class="easyui-linkbutton easyui-tooltip" iconcls="icon-text_italic" id="btHTML_EM"></a>
222-
<a href="#" title="s" class="easyui-linkbutton easyui-tooltip" iconcls="icon-text_strikethrough" id="btHTML_S"></a>
223-
<a href="#" title="u" class="easyui-linkbutton easyui-tooltip" iconcls="icon-text_underline" id="btHTML_U"></a> |
224-
<a href="#" title="br" class="easyui-linkbutton easyui-tooltip" iconcls="icon-break_line" id="btHTML_BR"></a>
225-
<a href="#" title="p" class="easyui-linkbutton easyui-tooltip" iconcls="icon-text_paragraph" id="btHTML_P"></a>
226-
<a href="#" title="hr" class="easyui-linkbutton easyui-tooltip" iconcls="icon-text_horizontalrule" id="btHTML_HR"></a>
227-
<a href="#" title="p margin-left" class="easyui-linkbutton easyui-tooltip" iconcls="icon-text_indent" id="btHTML_INDENT"></a> |
228-
<a href="#" title="p left" class="easyui-linkbutton easyui-tooltip" iconcls="icon-text_align_left" id="btHTML_LEFT"></a>
229-
<a href="#" title="p center" class="easyui-linkbutton easyui-tooltip" iconcls="icon-text_align_center" id="btHTML_CENTER"></a>
230-
<a href="#" title="p right" class="easyui-linkbutton easyui-tooltip" iconcls="icon-text_align_right" id="btHTML_RIGHT"></a>
231-
<a href="#" title="p justify" class="easyui-linkbutton easyui-tooltip" iconcls="icon-text_align_justify" id="btHTML_JUSTIFY"></a> |
232-
<a href="#" title="ul" class="easyui-linkbutton easyui-tooltip" iconcls="icon-text_list_bullets" id="btHTML_UL"></a>
233-
<a href="#" title="ol" class="easyui-linkbutton easyui-tooltip" iconcls="icon-text_list_numbers" id="btHTML_OL"></a> |
234-
<a href="#" title="a" class="easyui-linkbutton easyui-tooltip" iconcls="icon-link" id="btHTML_A"></a>
235-
<a href="#" title="img" class="easyui-linkbutton easyui-tooltip" iconcls="icon-picture" id="btHTML_IMG"></a>
236-
</div>
237207
<div id="divMathTextInput" class="center easyui-panel" data-options="region:'center',split:false,noheader:true">
238208
<form action="#" method="post" id="formMathTextInput">
239209
<fieldset>
@@ -260,15 +230,18 @@ <h3>Katex Input Helper</h3>
260230

261231
<!-- THIS MAY CAUSE FILE NOT FOUND : replacement see below
262232
<div title="<span information='MATRIX_SYMBOLS' class='rtl-title-withicon'>
263-
<img class='symbol_btn icon-matrix_13_black' src='./icons/blank.gif' width='15' height='20' /> &nbsp;&nbsp;
264-
<img class='symbol_btn icon-matrix_33_black' src='./icons/blank.gif' width='15' height='20' /></span>"
233+
<img class='symbol_btn icon-matrix_13_black' src='icons/blank.gif' width='15' height='20' /> &nbsp;&nbsp;
234+
<img class='symbol_btn icon-matrix_33_black' src='icons/blank.gif' width='15' height='20' /></span>"
265235
id="f_MATRIX_SYMBOLS">
266236
</div>
267237
-->
268238

269-
<div title="<span information='MATRIX_SYMBOLS' class='rtl-title-withicon'><img class='symbol_btn icon-matrix_13_black' width='15' height='20' /> &nbsp;&nbsp; <img class='symbol_btn icon-matrix_33_black' width='15' height='20' /></span>"
239+
<div title="<span information='MATRIX_SYMBOLS' class='rtl-title-withicon'>
240+
<img class='symbol_btn icon-matrix_13_black' width='15' height='20' /> &nbsp;&nbsp;
241+
<img class='symbol_btn icon-matrix_33_black' width='15' height='20' /></span>"
270242
id="f_MATRIX_SYMBOLS">
271243
</div>
244+
272245
<div title="<span information='BRACKET_SYMBOLS' class='rtl-title-withicon'>$(\ )$ &nbsp;&nbsp; $[\ \ ]$ &nbsp;&nbsp; $\|\ \|$ </span>"
273246
id="f_BRACKET_SYMBOLS">
274247
</div>
@@ -294,14 +267,6 @@ <h3>Katex Input Helper</h3>
294267
<label for="persistEquations"><span locate="PERSIST_EQUATIONS"></span></label>
295268
</fieldset>
296269
<hr />
297-
<fieldset>
298-
<legend>
299-
<span locate='SYNTAX'></span>
300-
</legend>
301-
<input type="checkbox" name="encloseType" id="encloseType" disabled />
302-
<label for="encloseType"><span locate='ENCLOSE_ALL_FORMULAS'></span></label>
303-
</fieldset>
304-
<hr />
305270
<fieldset>
306271
<legend>
307272
<span locate='UPDATE'></span>
@@ -316,12 +281,6 @@ <h3>Katex Input Helper</h3>
316281
<label for="autoUpdateTime"><span locate='UPDATE_INTERVAL'></span></label>
317282
</fieldset>
318283
<hr />
319-
<fieldset>
320-
<legend>MathJax</legend>
321-
<input type="checkbox" name="menuMathjaxType" id="menuMathjaxType" disabled />
322-
<label for="menuMathjaxType"><span locate='MATHJAX_MENU'></span></label>
323-
</fieldset>
324-
<hr />
325284
<fieldset>
326285
<legend>
327286
<span locate="RESET"></span>

src/assets/formulas/f_ALL_CHAR_MORE.html

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

22
<table style="border-spacing:0px; border-collapse:collapse; ">
33
<tr style="font-size:115%">
4-
<td><a href="#" class=s abegin="cc(" aend=") " lbegin="\mathscr{" lend="} ">$\mathscr{ABCDEFGHIJKLMNOPKRSTUVWXYZ\ 0123456789}$</a></td>
4+
<td><a href="#" class="s" abegin="cc(" aend=") " lbegin="\mathscr{" lend="} ">$\mathscr{ABCDEFGHIJKLMNOPKRSTUVWXYZ\ 0123456789}$</a></td>
55
</tr>
66
<tr style="font-size:115%">
7-
<td><a href="#" class=s abegin="bbb(" aend=") " lbegin="\mathbb{" lend="} ">$\mathbb{ABCDEFGHIJKLMNOPKRSTUVWXYZ\ 0123456789}$</a></td>
7+
<td><a href="#" class="s" abegin="bbb(" aend=") " lbegin="\mathbb{" lend="} ">$\mathbb{ABCDEFGHIJKLMNOPKRSTUVWXYZ\ 0123456789}$</a></td>
88
</tr>
99
<tr style="font-size:115%">
10-
<td><a href="#" class=s lbegin="\mathrm{" lend="} ">$\mathrm{ABCDEFGHIJKLMNOPKRSTUVWXYZ\ 0123456789}$</a></td>
10+
<td><a href="#" class="s" lbegin="\mathrm{" lend="} ">$\mathrm{ABCDEFGHIJKLMNOPKRSTUVWXYZ\ 0123456789}$</a></td>
1111
</tr>
1212
<tr style="font-size:115%">
1313
<td><a href="#" class=s abegin="sf(" aend=") " lbegin="\mathsf{" lend="} ">$\mathsf{ABCDEFGHIJKLMNOPKRSTUVWXYZ\ 0123456789}$</a></td>

src/assets/js/codeMirrorProxy.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import './jquery-easyui/jquery.easyui.min';
2+
const CodeMirror = (await import('codemirror')).default;
3+
await import('codemirror/mode/stex/stex'); // manual recommendation
4+
5+
import { ICodeMirror } from './interfaces';
6+
7+
export function codeMirrorProxy() : ICodeMirror {
8+
const cm = CodeMirror.fromTextArea($("#mathTextInput")[0] as HTMLTextAreaElement, {
9+
mode: "text/x-latex",
10+
autofocus: true,
11+
showCursorWhenSelecting: true,
12+
lineNumbers: true,
13+
lineWrapping: true,
14+
tabSize: 4,
15+
indentUnit: 4,
16+
indentWithTabs: true,
17+
theme: "default",
18+
inputStyle: "textarea"
19+
});
20+
(cm as ICodeMirror).version = CodeMirror.version;
21+
22+
// PURPOSE of this clause is to overcome the exception in unit test. Mocking did not help.
23+
try {
24+
let panelOptions = $('#divMathTextInput').panel('options');
25+
panelOptions.onResize = function(width: string|number, height: string|number) {
26+
try {
27+
cm.setSize(width, height);
28+
cm.refresh();
29+
} catch(e) { }
30+
};
31+
} catch(e) { console.warn(`Could not apply 'panel' : ${typeof $('#divMathTextInput').panel} : ${e}`); }
32+
33+
return cm;
34+
}

src/assets/js/container.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { Container, ResolutionContext, Factory } from 'inversify';
2+
23
import { IBootLoader, bootLoaderId, katexInputHelperId, IKatexInputHelper, katexInputHelperFactoryId,
34
ILocalizer, localizerId, IMessager, messagerId, platformInfoId,
45
IUtilities, utilitiesId, parametersId, IThemes, themesId, IParser, parserId, IMath, mathId,
56
IPanels, panelsId, dynamicPanelId, informationWindowId, moreDialogId, windowId, matrixWindowId,
6-
dynamicParametersId, panelFactoryId, unicodeWindowId, categoriesTreeId, ICategoriesTree } from './interfaces';
7+
dynamicParametersId, panelFactoryId, unicodeWindowId, categoriesTreeId, ICategoriesTree, asyncId,
8+
codeMirrorId, ICodeMirror } from './interfaces';
9+
710
import { BootLoader } from './bootloader';
811
import { KatexInputHelper } from './dialog';
912
import { ParametersProxy } from './parameters';
@@ -14,9 +17,11 @@ import { ParserExtension } from './parserExtension';
1417
import { MathFormulae } from './math';
1518
import { KIHPanels, KIHPanel, DynamicPanel, MatrixWindow, InformationWindow, KIHMoreDialog, KIHWindow, UnicodeWindow } from './panels';
1619
import { CategoriesTree } from './categoriesTree';
20+
import { codeMirrorProxy } from './codeMirrorProxy';
1721

1822
const container = new Container();
1923

24+
container.bind(asyncId).toConstantValue(true);
2025
container.bind<IBootLoader>(bootLoaderId).to(BootLoader).inSingletonScope();
2126
container.bind<IKatexInputHelper>(katexInputHelperId).to(KatexInputHelper).inSingletonScope();
2227
container.bind(parametersId).toDynamicValue(ParametersProxy).inSingletonScope();
@@ -32,6 +37,10 @@ container
3237
.toFactory((context: ResolutionContext) : () => IKatexInputHelper => {
3338
return () => context.get(katexInputHelperId);
3439
});
40+
container
41+
.bind<ICodeMirror>(codeMirrorId)
42+
.toDynamicValue(codeMirrorProxy)
43+
.inSingletonScope();
3544

3645
container.bind<KIHPanel>(dynamicPanelId).to(DynamicPanel);
3746
container.bind<KIHPanel>(informationWindowId).to(InformationWindow);
@@ -40,7 +49,7 @@ container.bind<KIHPanel>(windowId).to(KIHWindow);
4049
container.bind<KIHPanel>(matrixWindowId).to(MatrixWindow);
4150
container.bind<KIHPanel>(unicodeWindowId).to(UnicodeWindow);
4251

43-
container.bind(categoriesTreeId).to(CategoriesTree).inSingletonScope();
52+
container.bind<ICategoriesTree>(categoriesTreeId).to(CategoriesTree).inSingletonScope();
4453

4554
let allParams: any[] = [ ];
4655
container.bind(dynamicParametersId).toDynamicValue(() => allParams);

0 commit comments

Comments
 (0)