Skip to content

Commit 56d15e7

Browse files
committed
Dependency injection completed to nearly final state.
1 parent 455398a commit 56d15e7

11 files changed

Lines changed: 273 additions & 211 deletions

File tree

src/assets/js/bootLoader.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ import { FileHandler } from './fileHandling';
2121
import { CategoriesTree } from './categoriesTree';
2222
import { DynamicPanel } from './panels';
2323

24-
import { injectable } from 'inversify';
25-
import { container } from './container';
26-
import { IBootLoader, IKatexInputHelper, katexInputHelperId } from './interfaces';
24+
import { injectable, inject, Factory } from 'inversify';
25+
import { IBootLoader, IKatexInputHelper, katexInputHelperFactoryId } from './interfaces';
2726

2827
/**
2928
* The boot loader of the Katex Input Helper.
@@ -34,12 +33,18 @@ import { IBootLoader, IKatexInputHelper, katexInputHelperId } from './interfaces
3433
export class BootLoader implements IBootLoader {
3534

3635
baseLocation = null;
36+
factory: Factory<IKatexInputHelper> = null;
3737
vme: IKatexInputHelper = null;
3838
katex = null;
3939

4040
/**
4141
* Constructor.
4242
*/
43+
constructor(
44+
@inject(katexInputHelperFactoryId) factory
45+
) {
46+
this.factory = factory;
47+
}
4348

4449
/**
4550
* Converts a method with given signature and callback to a Promise returning method.
@@ -119,7 +124,7 @@ export class BootLoader implements IBootLoader {
119124
*/
120125
async initApp() {
121126
try {
122-
this.vme = container.get(katexInputHelperId);
127+
this.vme = this.factory();
123128
window.vme = this.vme; // prevents garbage collection?
124129
await this.vme.initialise();
125130
$('#myContainer').layout({fit: true});

src/assets/js/categoriesTree.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { Observable } from "./patterns/observable";
2+
import { injectable } from 'inversify';
3+
import { ICategoriesTree } from './interfaces';
24

35
/**
46
* Manages the Categories Tree.
57
*
68
* The Leafs of the tree refer to a set of equations and constitute the categories.
79
* The Folders constitute super categories.
810
*/
9-
export class CategoriesTree {
11+
@injectable() export class CategoriesTree implements ICategoriesTree {
1012

1113
data = null;
1214
treeSelector = "";

src/assets/js/container.ts

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { Container } from 'inversify';
2-
import { IBootLoader, bootLoaderId, katexInputHelperId, localizerId, messagerId, platformInfoId, utilitiesId, parametersId, themesId, parserId, mathId, panelsId } from './interfaces';
1+
import { Container, ResolutionContext, Factory } from 'inversify';
2+
import { IBootLoader, bootLoaderId, katexInputHelperId, IKatexInputHelper, katexInputHelperFactoryId,
3+
ILocalizer, localizerId, IMessager, messagerId, platformInfoId,
4+
IUtilities, utilitiesId, parametersId, IThemes, themesId, IParser, parserId, IMath, mathId,
5+
IPanels, panelsId, dynamicPanelId, informationWindowId, moreDialogId, windowId, matrixWindowId,
6+
dynamicParametersId, panelFactoryId, unicodeWindowId, categoriesTreeId, ICategoriesTree } from './interfaces';
37
import { BootLoader } from './bootloader';
48
import { KatexInputHelper } from './dialog';
59
import { ParametersProxy } from './parameters';
@@ -8,20 +12,54 @@ import { Messager, Utilities } from './helpers';
812
import { Themes } from './themes';
913
import { ParserExtension } from './parserExtension';
1014
import { MathFormulae } from './math';
11-
import { KIHPanels } from './panels';
15+
import { KIHPanels, KIHPanel, DynamicPanel, MatrixWindow, InformationWindow, KIHMoreDialog, KIHWindow, UnicodeWindow } from './panels';
16+
import { CategoriesTree } from './categoriesTree';
1217

13-
export const container = new Container();
18+
const container = new Container();
1419

15-
container.bind(bootLoaderId).to(BootLoader).inSingletonScope();
16-
container.bind(katexInputHelperId).to(KatexInputHelper).inSingletonScope();
20+
container.bind<IBootLoader>(bootLoaderId).to(BootLoader).inSingletonScope();
21+
container.bind<IKatexInputHelper>(katexInputHelperId).to(KatexInputHelper).inSingletonScope();
1722
container.bind(parametersId).toDynamicValue(ParametersProxy).inSingletonScope();
18-
container.bind(localizerId).to(Localizer).inSingletonScope();
19-
container.bind(messagerId).to(Messager).inSingletonScope();
20-
container.bind(utilitiesId).to(Utilities).inSingletonScope();
21-
container.bind(themesId).to(Themes).inSingletonScope();
22-
container.bind(parserId).to(ParserExtension).inSingletonScope();
23-
container.bind(mathId).to(MathFormulae).inSingletonScope();
24-
container.bind(panelsId).to(KIHPanels).inSingletonScope();
23+
container.bind<ILocalizer>(localizerId).to(Localizer).inSingletonScope();
24+
container.bind<IMessager>(messagerId).to(Messager).inSingletonScope();
25+
container.bind<IUtilities>(utilitiesId).to(Utilities).inSingletonScope();
26+
container.bind<IThemes>(themesId).to(Themes).inSingletonScope();
27+
container.bind<IParser>(parserId).to(ParserExtension).inSingletonScope();
28+
container.bind<IMath>(mathId).to(MathFormulae).inSingletonScope();
29+
container.bind<IPanels>(panelsId).to(KIHPanels).inSingletonScope();
30+
container
31+
.bind<Factory<IKatexInputHelper>>(katexInputHelperFactoryId)
32+
.toFactory((context: ResolutionContext) : () => IKatexInputHelper => {
33+
return () => context.get(katexInputHelperId);
34+
});
35+
36+
container.bind<KIHPanel>(dynamicPanelId).to(DynamicPanel);
37+
container.bind<KIHPanel>(informationWindowId).to(InformationWindow);
38+
container.bind<KIHPanel>(moreDialogId).to(KIHMoreDialog);
39+
container.bind<KIHPanel>(windowId).to(KIHWindow);
40+
container.bind<KIHPanel>(matrixWindowId).to(MatrixWindow);
41+
container.bind<KIHPanel>(unicodeWindowId).to(UnicodeWindow);
42+
43+
container.bind(categoriesTreeId).to(CategoriesTree).inSingletonScope();
44+
45+
let allParams: any[] = [ ];
46+
container.bind(dynamicParametersId).toDynamicValue(() => allParams);
47+
48+
container
49+
.bind<Factory<KIHPanel>>(panelFactoryId)
50+
.toFactory((context: ResolutionContext) : (...p: any) => KIHPanel => {
51+
return (wndId: any, id: string, parent: any, ...params: any) => {
52+
const math = context.get(mathId);
53+
const localizer = context.get(localizerId);
54+
const parameters = context.get(parametersId);
55+
const messager = context.get(messagerId);
56+
const parser = context.get(parserId);
57+
allParams = [];
58+
allParams.push(math, localizer, parameters, messager, parser, id, parent, ...params);
59+
return context.get<KIHPanel>(wndId);
60+
};
61+
});
62+
2563

2664
const bootLoader: IBootLoader = container.get(bootLoaderId);
2765
container.bind(platformInfoId).toDynamicValue(bootLoader.platformInfo.bind(bootLoader));

src/assets/js/definitions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,8 @@ interface HTMLElement {
5656
interface Document {
5757
createEventObject?: any;
5858
formMATRIX?: any;
59+
}
60+
61+
interface EditorFromTextArea {
62+
version?: string;
5963
}

src/assets/js/dialog.ts

Lines changed: 24 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import './dialog.css' assert { type: 'css' };
22

3-
const CodeMirror = (await import('codemirror')).default;
4-
await import('codemirror/mode/stex/stex'); // manual recommendation
5-
63
import { VKI_init } from './keyboard/keyboard';
7-
import { DynamicPanel, KIHMoreDialog, KIHWindow, UnicodeWindow, MatrixWindow, InformationWindow } from "./panels";
84
import { FileHandler } from "./fileHandling";
95

106
import { inject } from 'inversify';
@@ -17,8 +13,8 @@ import {
1713
parametersId,
1814
IThemes, themesId,
1915
IParser, parserId,
20-
IMath, mathId,
21-
IPanels, panelsId } from './interfaces';
16+
IMath, mathId, ICodeMirror,
17+
IPanels, panelsId, matrixWindowId, unicodeWindowId, informationWindowId, moreDialogId, windowId, dynamicPanelId } from './interfaces';
2218

2319
let console: any;
2420
if (window.console) console = window.console; else console = { log: function(msg) { }, error: function(msg) { } };
@@ -134,7 +130,7 @@ export class KatexInputHelper implements IKatexInputHelper {
134130
windowIsOpenning = false;
135131
textareaIgnore = false;
136132
textareaID = null;
137-
codeMirrorEditor = null;
133+
codeMirrorEditor: ICodeMirror = null;
138134
codeMirrorTheme = '';
139135
platformInfo = null;
140136
symbolPanelsLoaded = [];
@@ -157,16 +153,16 @@ export class KatexInputHelper implements IKatexInputHelper {
157153
location = "";
158154
documentations = null;
159155
localizer: ILocalizer = null;
160-
themes = null;
161-
math = null;
156+
themes: IThemes = null;
157+
math: IMath = null;
162158
parameters = null;
163-
utilities = null;
164-
messager = null;
159+
utilities: IUtilities = null;
160+
messager: IMessager = null;
165161
panels: IPanels = null;
166162
useEasyLoader = true;
167163
baseLocation = "";
168164
fromContextMenu = false;
169-
parser: any = null;
165+
parser: IParser = null;
170166
mathTextInput: any = null;
171167
mathVisualOutput: any = null;
172168
VKI_show: any = null;
@@ -221,7 +217,8 @@ export class KatexInputHelper implements IKatexInputHelper {
221217
this.utilities = utilities;
222218
this.themes = themes;
223219
this.parser = parser;
224-
this.math = math; // code mirror per method injection
220+
this.math = math;
221+
this.codeMirrorEditor = math.codeMirror;
225222
this.panels = panels;
226223
this.documentations = new Documentations(false, this.baseLocation);
227224

@@ -406,27 +403,12 @@ export class KatexInputHelper implements IKatexInputHelper {
406403
* - change handler -> auto update of formula
407404
* - context menu binding
408405
*/
409-
async initialiseCodeMirror() {
406+
initialiseCodeMirror() {
410407
let vme = this;
411-
vme.codeMirrorEditor = CodeMirror.fromTextArea($("#mathTextInput")[0] as HTMLTextAreaElement, {
412-
mode: vme.encloseAllFormula ? "text/html" : "text/x-latex",
413-
autofocus: true,
414-
showCursorWhenSelecting: true,
415-
lineNumbers: true,
416-
lineWrapping: true,
417-
// Unknown property
418-
//styleActiveLine: true,
419-
//matchBrackets: true,
420-
//autoCloseBrackets: true,
421-
//autoCloseTags: vme.encloseAllFormula ? true : false,
422-
//tabMode: "indent",
423-
tabSize: 4,
424-
indentUnit: 4,
425-
indentWithTabs: true,
426-
theme: "default",
427-
inputStyle: vme.platformInfo.isMobile ? 'contenteditable' : 'textarea'
428-
});
429-
vme.codeMirrorEditor.on("change", function() { vme.autoUpdateOutput(); });
408+
const codeMirrorEditor = this.codeMirrorEditor;
409+
const option = vme.platformInfo.isMobile ? 'contenteditable' : 'textarea';
410+
codeMirrorEditor.setOption('inputStyle', option);
411+
codeMirrorEditor.on("change", function() { vme.autoUpdateOutput(); });
430412

431413
if(!vme.platformInfo.isMobile) {
432414
/* The context menu appears but throws on click or mouse move afterwards:
@@ -436,16 +418,6 @@ export class KatexInputHelper implements IKatexInputHelper {
436418
} else {
437419
$('.CodeMirror').css('fontSize', '1.3em');
438420
}
439-
440-
this.math.setEditorInstance(this.codeMirrorEditor);
441-
442-
let panelOptions = $('#divMathTextInput').panel('options');
443-
panelOptions.onResize = function(width: string|number, height: string|number) {
444-
try {
445-
vme.codeMirrorEditor.setSize(width, height);
446-
vme.codeMirrorEditor.refresh();
447-
} catch(e) { }
448-
};
449421
}
450422

451423
/**
@@ -539,7 +511,7 @@ export class KatexInputHelper implements IKatexInputHelper {
539511
case "mEDITOR_PARAMETERS": await vme.openWindow('wEDITOR_PARAMETERS'); break;
540512
case "mSTYLE_CHOISE": await vme.openWindow('wSTYLE_CHOISE'); break;
541513
case "mLANGUAGE_CHOISE": await vme.openWindow('wLANGUAGE_CHOISE'); break;
542-
case "mMATRIX": vme.panels.showWindowGeneric(MatrixWindow, 'wMATRIX', 3, 3); break;
514+
case "mMATRIX": vme.showMatrixWindow(3, 3); break;
543515
case "mCOMMUTATIVE_DIAGRAM": await vme.initialiseUImoreDialogs("f_COMMUTATIVE_DIAGRAM"); break;
544516
case "mCHEMICAL_FORMULAE": await vme.initialiseUImoreDialogs("f_CHEMICAL_FORMULAE"); break;
545517
case "mSAVE_EQUATION": vme.saveEquationFile(); break;
@@ -548,7 +520,7 @@ export class KatexInputHelper implements IKatexInputHelper {
548520
// No longer functional
549521
//case "mMATH_ML": vme.viewMathML(vme.mathVisualOutput.id); break;
550522
// TODO: complete transfer of functionality to Panels
551-
case "mUNICODES_LIST": await vme.panels.showWindowGeneric(UnicodeWindow, 'wUNICODES_LIST', vme.initialiseSymbolContent.bind(vme)); break;
523+
case "mUNICODES_LIST": await vme.panels.showWindowDI(unicodeWindowId, 'wUNICODES_LIST', vme.initialiseSymbolContent.bind(vme)); break;
552524
case "mLATEX_CODES_LIST": await vme.openWindow('wLATEX_CODES_LIST'); await vme.initialiseLatexMathjaxCodesList(); break;
553525
case "mLANG_RESSOURCE_LIST": await vme.openWindow('wLANGUAGE_LIST'); await vme.initialiseLangRessourcesList(); break;
554526
case "mLATEX_DOCUMENTATION": vme.documentations.showLatexDocumentation(); break;
@@ -565,7 +537,7 @@ export class KatexInputHelper implements IKatexInputHelper {
565537
case "f_FR_CHAR":
566538
case "f_BBB_CHAR": await vme.initialiseUImoreDialogs(item.target.id); break;
567539
case "mEQUATION": await vme.initialiseUImoreDialogs("f_EQUATION"); break;
568-
case "mCUSTOM_EQUATIONS": await vme.panels.showWindowGeneric(DynamicPanel, 'wf_CUSTOM_EQUATIONS_MORE', vme.math); break;
540+
case "mCUSTOM_EQUATIONS": await vme.panels.showWindowDI(dynamicPanelId, 'wf_CUSTOM_EQUATIONS_MORE', vme.math); break;
569541
case "mHORIZONTAL_SPACING": await vme.initialiseUImoreDialogs("f_HORIZONTAL_SPACING"); break;
570542
case "mVERTICAL_SPACING": await vme.initialiseUImoreDialogs("f_VERTICAL_SPACING"); break;
571543
case "mSPECIAL_CHARACTER": await vme.initialiseUImoreDialogs("f_SPECIAL_CHARACTER"); break;
@@ -667,7 +639,7 @@ export class KatexInputHelper implements IKatexInputHelper {
667639
* @param numTab - number (index) of the tab (0..3)
668640
*/
669641
async openInformationTab(numTab: number) {
670-
this.panels.showWindowGeneric(InformationWindow, 'wINFORMATIONS', numTab);
642+
this.panels.showWindowDI(informationWindowId, 'wINFORMATIONS', numTab);
671643
}
672644

673645
/**
@@ -678,7 +650,7 @@ export class KatexInputHelper implements IKatexInputHelper {
678650
async initialiseUImoreDialogs(fPanelID: string) {
679651
let vme = this;
680652
let fPanelMoreID = 'w' + fPanelID + '_MORE';
681-
await vme.panels.showWindowGeneric(KIHMoreDialog, fPanelMoreID, vme.initialiseSymbolContent.bind(vme));
653+
await vme.panels.showWindowDI(moreDialogId, fPanelMoreID, vme.initialiseSymbolContent.bind(vme));
682654
}
683655

684656
/**
@@ -689,7 +661,7 @@ export class KatexInputHelper implements IKatexInputHelper {
689661
* @param id - the HTML id of the window
690662
*/
691663
async openWindow(id: string) {
692-
await this.panels.showWindowGeneric(KIHWindow, id);
664+
await this.panels.showWindowDI(windowId, id);
693665
}
694666

695667
/**
@@ -858,7 +830,7 @@ export class KatexInputHelper implements IKatexInputHelper {
858830
* @param cols - the number of matrix columns
859831
*/
860832
showMatrixWindow(rows: number, cols: number) {
861-
this.panels.showWindowGeneric(MatrixWindow, 'wMATRIX', rows, cols);
833+
this.panels.showWindowDI(matrixWindowId, 'wMATRIX', rows, cols);
862834
}
863835

864836
/**
@@ -1227,7 +1199,7 @@ export class KatexInputHelper implements IKatexInputHelper {
12271199
});
12281200
let p = $(accordionID).accordion('getSelected');
12291201
if (p) { p.panel('collapse', false); }
1230-
this.math.updateHeaders();
1202+
this.math.updateHeaders("");
12311203
}
12321204

12331205
/**
@@ -1332,7 +1304,7 @@ export class KatexInputHelper implements IKatexInputHelper {
13321304
<table class="inline-table">
13331305
<tr><td><b> ${vme.versions.version} </b></td><td><b>Katex Input Helper / Visual Math Editor</b>, (This software)</td></tr>
13341306
<tr><td> ${vme.versions.katexVersion} </td><td>Katex</td></tr>
1335-
<tr><td> ${CodeMirror.version} </td><td>Code Mirror</td></tr>
1307+
<tr><td> ${vme.codeMirrorEditor.version} </td><td>Code Mirror</td></tr>
13361308
<tr><td> ${vme.versions.VKI_version} </td><td>Virtual Keyboard</td></tr>
13371309
<tr><td> ${$.fn.jquery} </td><td>Jquery</td></tr>
13381310
<tr><td> ${vme.versions.easyuiVersion} </td><td>Jquery Easyui</td></tr>

0 commit comments

Comments
 (0)