Skip to content

Commit b92c0e4

Browse files
committed
🏷 Add correct types throughout project.
+ Most significantly, editor actions.
1 parent d27b951 commit b92c0e4

12 files changed

+498
-317
lines changed

src/NeonCore.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ class NeonCore {
8080
* not update the database unless forced.
8181
* @param force - If a database update should be forced.
8282
*/
83-
async initDb (force = false): Promise<{}> {
83+
async initDb (force = false): Promise<boolean> {
8484
// Check for existing manifest
8585
type DbAnnotation = PouchDB.Core.IdMeta & PouchDB.Core.GetMeta & WebAnnotation;
8686
type Doc = PouchDB.Core.IdMeta & PouchDB.Core.GetMeta & { timestamp: string; annotations: string[]};
87-
const response = await new Promise<{}>((resolve, reject): void => {
87+
const response = await new Promise<boolean>((resolve, reject): void => {
8888
this.db.get(this.manifest['@id']).catch(err => {
8989
if (err.name === 'not_found') {
9090
// This is a new document.
@@ -549,14 +549,14 @@ class NeonCore {
549549
}
550550

551551
/** Completely remove the database. */
552-
async deleteDb (): Promise<{}[]> {
552+
async deleteDb (): Promise<void[]> {
553553
type Doc = PouchDB.Core.IdMeta & PouchDB.Core.GetMeta & { timestamp: string; annotations: string[]};
554554
const annotations = await this.db.get(this.manifest['@id'])
555555
.then((doc: Doc) => { return doc.annotations; } );
556556
annotations.push(this.manifest['@id']);
557557

558558
const promises = annotations.map((id) => {
559-
return new Promise(res => {
559+
return new Promise<void>(res => {
560560
this.db.get(id)
561561
.then(doc => { return this.db.remove(doc); })
562562
.then(() => res());

src/NeonView.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class NeonView {
174174
/**
175175
* Deletes the local database of the loaded MEI file(s).
176176
*/
177-
deleteDb (): Promise<{}[]> {
177+
deleteDb (): Promise<void[]> {
178178
return this.core.deleteDb();
179179
}
180180

src/SquareEdit/Grouping.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as Notification from '../utils/Notification';
44
import * as SelectTools from '../utils/SelectTools';
55
import * as SelectOptions from '../SquareEdit/SelectOptions';
66
import NeonView from '../NeonView';
7-
import { EditorAction } from '../Types';
7+
import { EditorAction, SetAction, ToggleLigatureAction } from '../Types';
88
import { removeHandler, deleteButtonHandler } from './SelectOptions';
99

1010

@@ -147,7 +147,7 @@ export function initGroupingListeners (): void {
147147
document.getElementById('toggle-ligature').addEventListener('click', async () => {
148148
const elementIds = getIds();
149149

150-
const editorAction: EditorAction = {
150+
const editorAction: ToggleLigatureAction = {
151151
action: 'toggleLigature',
152152
param: {
153153
elementIds: elementIds

src/SquareEdit/InsertHandler.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import NeonView from '../NeonView';
2-
import { EditorAction } from '../Types';
2+
import { EditorAction, InsertAction } from '../Types';
33
import * as d3 from 'd3';
44

55
/**
@@ -215,7 +215,7 @@ class InsertHandler {
215215
const transformMatrix = (container.getElementsByClassName('system')[0] as SVGGraphicsElement).getScreenCTM();
216216
const cursorpt = pt.matrixTransform(transformMatrix.inverse());
217217

218-
const editorAction: EditorAction = {
218+
const editorAction: InsertAction = {
219219
action: 'insert',
220220
param: {
221221
elementType: this.type,

src/SquareEdit/NeumeTools.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Notification from '../utils/Notification';
22
import NeonView from '../NeonView';
3-
import { EditorAction } from '../Types';
3+
import { EditorAction, SplitNeumeAction } from '../Types';
44

55
/** Handle splitting a neume into two neumes through Verovio. */
66
export class SplitNeumeHandler {
@@ -47,7 +47,7 @@ export class SplitNeumeHandler {
4747
const nc = (evt.target as SVGGElement).parentElement;
4848
const ncId = nc.id;
4949

50-
const editorAction: EditorAction = {
50+
const editorAction: SplitNeumeAction = {
5151
action: 'splitNeume',
5252
param: {
5353
elementId: id,

src/SquareEdit/SelectOptions.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as Notification from '../utils/Notification';
44
import NeonView from '../NeonView';
55
import { SplitStaffHandler } from './StaffTools';
66
import { SplitNeumeHandler } from './NeumeTools';
7-
import { EditorAction } from '../Types';
7+
import { ChainAction, ChangeStaffAction, EditorAction, MergeAction, RemoveAction, SetAction, SetClefAction } from '../Types';
88
import { getStaffBBox } from '../utils/SelectTools';
99

1010
/**
@@ -24,7 +24,7 @@ export function initNeonView (view: NeonView): void {
2424
* @param id - The id of the neume component.
2525
* @returns An action that unsets the inclinatum parameter of a neume component.
2626
*/
27-
export function unsetInclinatumAction (id: string): EditorAction {
27+
export function unsetInclinatumAction (id: string): SetAction {
2828
return {
2929
action: 'set',
3030
param: {
@@ -39,7 +39,7 @@ export function unsetInclinatumAction (id: string): EditorAction {
3939
* @param id - The id of the neume component.
4040
* @returns An action that unsets the virga parameter of a neume component.
4141
*/
42-
export function unsetVirgaAction (id: string): EditorAction {
42+
export function unsetVirgaAction (id: string): SetAction {
4343
return {
4444
action: 'set',
4545
param: {
@@ -54,7 +54,7 @@ export function unsetVirgaAction (id: string): EditorAction {
5454
* @param id - The id of the neume component.
5555
* @returns An action that unsets the reversed virga parameter of a neume component.
5656
*/
57-
export function unsetVirgaReversedAction (id: string): EditorAction {
57+
export function unsetVirgaReversedAction (id: string): SetAction {
5858
return {
5959
action: 'set',
6060
param: {
@@ -69,7 +69,7 @@ export function unsetVirgaReversedAction (id: string): EditorAction {
6969
* @param id - The id of the neume component.
7070
* @returns An action that unsets the liquescent_clockwise parameter of a neume component.
7171
*/
72-
export function unsetLiquescentClockwiseAction (id: string): EditorAction {
72+
export function unsetLiquescentClockwiseAction (id: string): SetAction {
7373
return {
7474
action: 'set',
7575
param: {
@@ -84,7 +84,7 @@ export function unsetLiquescentClockwiseAction (id: string): EditorAction {
8484
* @param id - The id of the neume component.
8585
* @returns An action that unsets the liquescent_anticlockwise parameter of a neume component.
8686
*/
87-
export function unsetLiquescentAnticlockwiseAction (id: string): EditorAction {
87+
export function unsetLiquescentAnticlockwiseAction (id: string): SetAction {
8888
return {
8989
action: 'set',
9090
param: {
@@ -117,7 +117,7 @@ export function endOptionsSelection (): void {
117117
* Function to handle removing elements
118118
*/
119119
export function removeHandler (): void {
120-
const toRemove = [];
120+
const toRemove: RemoveAction[] = [];
121121
const selected = Array.from(document.getElementsByClassName('selected'));
122122
selected.forEach(elem => {
123123
if (elem.classList.contains('syl')) {
@@ -138,7 +138,7 @@ export function removeHandler (): void {
138138
}
139139
);
140140
});
141-
const chainAction: EditorAction = {
141+
const chainAction: ChainAction = {
142142
action: 'chain',
143143
param: toRemove
144144
};
@@ -150,7 +150,7 @@ export function removeHandler (): void {
150150
* Function to handle re-associating elements to the nearest staff
151151
*/
152152
export function changeStaffHandler(): void {
153-
const toChange: EditorAction[] = [];
153+
const toChange: ChangeStaffAction[] = [];
154154
const selected = Array.from(document.getElementsByClassName('selected'));
155155
selected.forEach(elem => {
156156
toChange.push(
@@ -187,7 +187,7 @@ export function insertToSyllableHandler(): void {
187187
}
188188
);
189189
});
190-
const chainAction: EditorAction = {
190+
const chainAction: ChainAction = {
191191
action: 'chain',
192192
param: toInsert
193193
};
@@ -260,7 +260,7 @@ export function triggerNcActions (nc: SVGGraphicsElement): void {
260260
const unsetVirgaReversed = unsetVirgaReversedAction(nc.id);
261261
const unsetLiquescentClockwise = unsetLiquescentClockwiseAction(nc.id);
262262
const unsetLiquescentAnticlockwise = unsetLiquescentAnticlockwiseAction(nc.id);
263-
const setInclinatum = {
263+
const setInclinatum: SetAction = {
264264
action: 'set',
265265
param: {
266266
elementId: nc.id,
@@ -285,7 +285,7 @@ export function triggerNcActions (nc: SVGGraphicsElement): void {
285285
const unsetInclinatum = unsetInclinatumAction(nc.id);
286286
const unsetLiquescentClockwise = unsetLiquescentClockwiseAction(nc.id);
287287
const unsetLiquescentAnticlockwise = unsetLiquescentAnticlockwiseAction(nc.id);
288-
const setVirga = {
288+
const setVirga: SetAction = {
289289
action: 'set',
290290
param: {
291291
elementId: nc.id,
@@ -310,7 +310,7 @@ export function triggerNcActions (nc: SVGGraphicsElement): void {
310310
const unsetVirga = unsetVirgaAction(nc.id);
311311
const unsetLiquescentClockwise = unsetLiquescentClockwiseAction(nc.id);
312312
const unsetLiquescentAnticlockwise = unsetLiquescentAnticlockwiseAction(nc.id);
313-
const setVirgaReversed = {
313+
const setVirgaReversed: SetAction = {
314314
action: 'set',
315315
param: {
316316
elementId: nc.id,
@@ -335,7 +335,7 @@ export function triggerNcActions (nc: SVGGraphicsElement): void {
335335
const unsetVirga = unsetVirgaAction(nc.id);
336336
const unsetVirgaReversed = unsetVirgaReversedAction(nc.id);
337337
const unsetLiquescentAnticlockwise = unsetLiquescentAnticlockwiseAction(nc.id);
338-
const setLiquescentClockwise = {
338+
const setLiquescentClockwise: SetAction = {
339339
action: 'set',
340340
param: {
341341
elementId: nc.id,
@@ -360,7 +360,7 @@ export function triggerNcActions (nc: SVGGraphicsElement): void {
360360
const unsetVirga = unsetVirgaAction(nc.id);
361361
const unsetVirgaReversed = unsetVirgaReversedAction(nc.id);
362362
const unsetLiquescentClockwise = unsetLiquescentClockwiseAction(nc.id);
363-
const setLiquescentAnticlockwise = {
363+
const setLiquescentAnticlockwise: SetAction = {
364364
action: 'set',
365365
param: {
366366
elementId: nc.id,
@@ -575,7 +575,7 @@ export function triggerClefActions (clef: SVGGraphicsElement): void {
575575

576576
document.querySelector('#CClef.dropdown-item')
577577
.addEventListener('click', () => {
578-
const setCClef: EditorAction = {
578+
const setCClef: SetClefAction = {
579579
action: 'setClef',
580580
param: {
581581
elementId: clef.id,
@@ -594,7 +594,7 @@ export function triggerClefActions (clef: SVGGraphicsElement): void {
594594
});
595595
document.querySelector('#FClef.dropdown-item')
596596
.addEventListener('click', () => {
597-
const setFClef: EditorAction = {
597+
const setFClef: SetClefAction = {
598598
action: 'setClef',
599599
param: {
600600
elementId: clef.id,
@@ -677,7 +677,7 @@ export function triggerAccidActions (accid: SVGGraphicsElement): void {
677677

678678
document.querySelector('#ChangeToFlat.dropdown-item')
679679
.addEventListener('click', () => {
680-
const changeToFlat: EditorAction = {
680+
const changeToFlat: SetAction = {
681681
action: 'set',
682682
param: {
683683
elementId: accid.id,

src/SquareEdit/StaffTools.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Notification from '../utils/Notification';
22
import NeonView from '../NeonView';
3-
import { EditorAction } from '../Types';
3+
import { EditorAction, SplitAction } from '../Types';
44
import { selectAll } from '../utils/SelectTools';
55
import DragHandler from '../utils/DragHandler';
66

@@ -56,7 +56,7 @@ export class SplitStaffHandler {
5656
// Find staff point corresponds to if one exists
5757
// TODO
5858

59-
const editorAction: EditorAction = {
59+
const editorAction: SplitAction = {
6060
action: 'split',
6161
param: {
6262
elementId: id,

src/TextEditMode.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import NeonView from './NeonView';
44
import { setSelectHelperObjects, dragSelect, clickSelect } from './utils/Select';
55
import { setGroupingHighlight } from './utils/Color';
66
import { TextEditInterface } from './Interfaces';
7+
import { SetTextAction } from './Types';
78

89
/**
910
* Format a string for prompting the user.
@@ -161,7 +162,7 @@ export default class TextEditMode implements TextEditInterface {
161162
const orig = formatRaw(span.textContent);
162163
const corrected = window.prompt('', orig);
163164
if (corrected !== null && corrected !== orig) {
164-
const editorAction = {
165+
const editorAction: SetTextAction = {
165166
action: 'setText',
166167
param: {
167168
elementId: [...span.classList.entries()].filter(e => e[1] !== 'text-select')[0][1],

0 commit comments

Comments
 (0)