Fix eslint compilation

This commit is contained in:
Paulo Veiga 2022-01-31 00:05:22 +00:00
parent f91af2220d
commit 391974e727
20 changed files with 114 additions and 150 deletions

View File

@ -67,7 +67,7 @@ const initMindplot = () => {
// Load map from XML file persisted on disk...
const instance = PersistenceManager.getInstance();
const mindmap = instance.load(global.mapId);
const mindmap = instance.load(String(global.mapId));
designer.loadMap(mindmap);
if (global.mindmapLocked) {

View File

@ -28,16 +28,12 @@
"max-len": [1,300],
"class-methods-use-this": "off",
"no-console" : "off",
"no-unused-vars": ["error", { "args": "none" }],
"import/extensions": ["error", {
"ts": "never"
}],
// codebase contains many this aliases, fix in the future?
"@typescript-eslint/no-this-alias": "off",
// no-unused-vars already used
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/ban-ts-comment": "warn",
"import/no-extraneous-dependencies": ["warn", {"packageDir": "./", "devDependencies": false, "optionalDependencies": false, "peerDependencies": false}]
// Remove once migration is completed ...
"@typescript-eslint/no-explicit-any": "warn",
"import/extensions": "warn"
},
"settings": {
"import/resolver": {

View File

@ -27,56 +27,56 @@ import RelationshipModel from './model/RelationshipModel';
import Topic from './Topic';
abstract class ActionDispatcher extends Events {
static _instance: ActionDispatcher;
private static _instance: ActionDispatcher;
constructor(commandContext: CommandContext) {
$assert(commandContext, 'commandContext can not be null');
super();
}
abstract addRelationship(model: RelationshipModel, mindmap: Mindmap);
abstract addRelationship(model: RelationshipModel, mindmap: Mindmap): void;
abstract addTopics(models: NodeModel[], parentTopicId: any[]);
abstract addTopics(models: NodeModel[], parentTopicId: number[]): void;
abstract deleteEntities(topicsIds: number[], relIds: number[]);
abstract deleteEntities(topicsIds: number[], relIds: number[]): void;
abstract dragTopic(topicId: number, position: Point, order: number, parentTopic: Topic);
abstract dragTopic(topicId: number, position: Point, order: number, parentTopic: Topic): void;
abstract moveTopic(topicId: number, position: any);
abstract moveTopic(topicId: number, position: Point): void;
abstract moveControlPoint(ctrlPoint: this, point: any);
abstract moveControlPoint(ctrlPoint: this, point: Point): void;
abstract changeFontFamilyToTopic(topicIds: number[], fontFamily: string);
abstract changeFontFamilyToTopic(topicIds: number[], fontFamily: string): void;
abstract changeFontStyleToTopic(topicsIds: number[]);
abstract changeFontStyleToTopic(topicsIds: number[]): void;
abstract changeFontColorToTopic(topicsIds: number[], color: string);
abstract changeFontColorToTopic(topicsIds: number[], color: string): void;
abstract changeFontSizeToTopic(topicsIds: number[], size: number);
abstract changeFontSizeToTopic(topicsIds: number[], size: number): void;
abstract changeBackgroundColorToTopic(topicsIds: number[], color: string);
abstract changeBackgroundColorToTopic(topicsIds: number[], color: string): void;
abstract changeBorderColorToTopic(topicsIds: number[], color: string);
abstract changeBorderColorToTopic(topicsIds: number[], color: string): void;
abstract changeShapeTypeToTopic(topicsIds: number[], shapeType: string);
abstract changeShapeTypeToTopic(topicsIds: number[], shapeType: string): void;
abstract changeFontWeightToTopic(topicsIds: number[]);
abstract changeFontWeightToTopic(topicsIds: number[]): void;
abstract changeTextToTopic(topicsIds: number[], text: string);
abstract changeTextToTopic(topicsIds: number[], text: string): void;
abstract shrinkBranch(topicsIds: number[], collapse: boolean);
abstract shrinkBranch(topicsIds: number[], collapse: boolean): void;
abstract addFeatureToTopic(topicId: number, type: string, attributes: object);
abstract addFeatureToTopic(topicId: number, type: string, attributes: object): void;
abstract changeFeatureToTopic(topicId: number, featureId: any, attributes: object);
abstract changeFeatureToTopic(topicId: number, featureId: number, attributes: object): void;
abstract removeFeatureFromTopic(topicId: number, featureId: number);
abstract removeFeatureFromTopic(topicId: number, featureId: number): void;
static setInstance = (dispatcher: ActionDispatcher) => {
this._instance = dispatcher;
};
static setInstance = (dispatcher: ActionDispatcher) => {
this._instance = dispatcher;
};
static getInstance = (): ActionDispatcher => ActionDispatcher._instance;
static getInstance = (): ActionDispatcher => ActionDispatcher._instance;
}
export default ActionDispatcher;

View File

@ -151,14 +151,14 @@ class Designer extends Events {
return this._actionDispatcher;
}
// @ts-ignore
addEvent(type: string, listener: any): void {
addEvent(type: string, listener): Events {
if (type === TopicEvent.EDIT || type === TopicEvent.CLICK) {
const editor = TopicEventDispatcher.getInstance();
editor.addEvent(type, listener);
} else {
super.addEvent(type, listener);
}
return this;
}
private _registerMouseEvents() {
@ -186,7 +186,7 @@ class Designer extends Events {
screenManager.addEvent('dblclick', (event: MouseEvent) => {
if (workspace.isWorkspaceEventsEnabled()) {
const mousePos = screenManager.getWorkspaceMousePosition(event);
const centralTopic:CentralTopic = me.getModel()
const centralTopic: CentralTopic = me.getModel()
.getCentralTopic();
const model = me._createChildModel(centralTopic, mousePos);
@ -208,7 +208,7 @@ class Designer extends Events {
dragManager.addEvent('dragging', (event: MouseEvent, dragTopic: DragTopic) => {
dragTopic.updateFreeLayout(event);
if (!dragTopic.isFreeLayoutOn(event)) {
if (!dragTopic.isFreeLayoutOn()) {
// The node is being drag. Is the connection still valid ?
dragConnector.checkConnection(dragTopic);

View File

@ -33,25 +33,14 @@ export function buildDesigner(options: DesignerOptions): Designer {
// Register load events ...
designer = new Designer(options, divContainer);
designer.addEvent('loadSuccess', () => {
// @ts-ignore
window.mindmapLoadReady = true;
globalThis.mindmapLoadReady = true;
console.log('Map loadded successfully');
});
const onerrorFn = (message: string, url, lineNo) => {
// Close loading dialog ...
// @ts-ignore
if (window.waitDialog) {
// @ts-ignore
window.waitDialog.close();
// @ts-ignore
window.waitDialog = null;
}
const onerrorFn = () => {
// Open error dialog only in case of mindmap loading errors. The rest of the error are reported but not display the dialog.
// Remove this in the near future.
// @ts-ignore
if (!window.mindmapLoadReady) {
if (!globalThis.mindmapLoadReady) {
$notifyModal($msg('UNEXPECTED_ERROR_LOADING'));
}
};

View File

@ -210,9 +210,7 @@ class DragTopic {
return this.getConnectedToTopic() != null;
}
isFreeLayoutOn(dragTopic) {
// return this._isFreeLayoutEnabled;
// Disable free layout ...
isFreeLayoutOn() {
return false;
}
}

View File

@ -17,15 +17,17 @@
*/
class Events {
private $events;
constructor() {
this.$events = {};
}
static _removeOn(string) {
static _removeOn(string: string) {
return string.replace(/^on([A-Z])/, (full, first) => first.toLowerCase());
}
addEvent(typeName, fn, internal) {
addEvent(typeName: string, fn?, internal?: boolean): Events {
const type = Events._removeOn(typeName);
// Add function had not been added yet
@ -36,12 +38,11 @@ class Events {
}
// Mark reference ...
// eslint-disable-next-line no-param-reassign
fn.internal = Boolean(internal);
return this;
}
fireEvent(typeName, eventArgs, delay) {
fireEvent(typeName: string, eventArgs?, delay?: boolean): Events {
const type = Events._removeOn(typeName);
const events = this.$events[type];
if (!events) return this;
@ -57,7 +58,7 @@ class Events {
return this;
}
removeEvent(typeName, fn) {
removeEvent(typeName: string, fn?): Events {
const type = Events._removeOn(typeName);
const events = this.$events[type];
if (events && !fn.internal) {

View File

@ -16,24 +16,29 @@
* limitations under the License.
*/
import $ from 'jquery';
import { Mindmap } from '..';
import PersistenceManager from './PersistenceManager';
class LocalStorageManager extends PersistenceManager {
private documentUrl: string;
private forceLoad: boolean;
constructor(documentUrl, forceLoad) {
super();
this.documentUrl = documentUrl;
this.forceLoad = forceLoad;
}
saveMapXml(mapId, mapXml, pref, saveHistory, events) {
saveMapXml(mapId: string, mapXml: string) {
localStorage.setItem(`${mapId}-xml`, mapXml);
}
discardChanges(mapId) {
discardChanges(mapId: string) {
localStorage.removeItem(`${mapId}-xml`);
}
loadMapDom(mapId) {
loadMapDom(mapId: string) {
let xml = localStorage.getItem(`${mapId}-xml`);
if (xml == null || this.forceLoad) {
$.ajax({
@ -58,7 +63,7 @@ class LocalStorageManager extends PersistenceManager {
return $.parseXML(xml);
}
unlockMap(mindmap) {
unlockMap(mindmap: Mindmap) {
// Ignore, no implementation required ...
}
}

View File

@ -17,10 +17,14 @@
* limitations under the License.
*/
import { $assert } from '@wisemapping/core-js';
import { Mindmap } from '..';
import XMLSerializerFactory from './persistence/XMLSerializerFactory';
class PersistenceManager {
save(mindmap, editorProperties, saveHistory, events, sync) {
abstract class PersistenceManager {
// eslint-disable-next-line no-use-before-define
static _instance: PersistenceManager;
save(mindmap: Mindmap, editorProperties, saveHistory: boolean, events, sync: boolean) {
$assert(mindmap, 'mindmap can not be null');
$assert(editorProperties, 'editorProperties can not be null');
@ -36,45 +40,39 @@ class PersistenceManager {
this.saveMapXml(mapId, mapXml, pref, saveHistory, events, sync);
} catch (e) {
console.error(e);
events.onError(this._buildError());
events.onError(e);
}
}
load(mapId) {
load(mapId: string) {
$assert(mapId, 'mapId can not be null');
const domDocument = this.loadMapDom(mapId);
return PersistenceManager.loadFromDom(mapId, domDocument);
}
discardChanges(mapId) {
throw new Error('Method must be implemented');
abstract discardChanges(mapId: string): void;
abstract loadMapDom(mapId: string): Document;
abstract saveMapXml(mapId: string, mapXml, pref, saveHistory, events, sync);
abstract unlockMap(mindmap: Mindmap): void;
static init = (instance: PersistenceManager) => {
this._instance = instance;
};
static getInstance(): PersistenceManager {
return this._instance;
}
loadMapDom(mapId) {
throw new Error('Method must be implemented');
}
static loadFromDom(mapId: string, mapDom: Document) {
$assert(mapId, 'mapId can not be null');
$assert(mapDom, 'mapDom can not be null');
saveMapXml(mapId, mapXml, pref, saveHistory, events, sync) {
throw new Error('Method must be implemented');
}
unlockMap(mindmap) {
throw new Error('Method must be implemented');
const serializer = XMLSerializerFactory.createInstanceFromDocument(mapDom);
return serializer.loadFromDom(mapDom, mapId);
}
}
PersistenceManager.init = (instance) => {
PersistenceManager._instance = instance;
};
PersistenceManager.getInstance = () => PersistenceManager._instance;
PersistenceManager.loadFromDom = function loadFromDom(mapId, mapDom) {
$assert(mapId, 'mapId can not be null');
$assert(mapDom, 'mapDom can not be null');
const serializer = XMLSerializerFactory.createInstanceFromDocument(mapDom);
return serializer.loadFromDom(mapDom, mapId);
};
export default PersistenceManager;

View File

@ -64,11 +64,11 @@ class RESTPersistenceManager extends PersistenceManager {
contentType: 'application/json; charset=utf-8',
async: !sync,
success(successData, textStatus, jqXHRresponseText) {
success(successData) {
persistence.timestamp = successData;
events.onSuccess();
},
error(jqXHR, textStatus, errorThrown) {
error() {
events.onError(persistence._buildError());
},
complete() {
@ -78,7 +78,7 @@ class RESTPersistenceManager extends PersistenceManager {
}
persistence.onSave = false;
},
fail(xhr, textStatus) {
fail(xhr) {
const { responseText } = xhr;
let userMsg = { severity: 'SEVERE', message: $msg('SAVE_COULD_NOT_BE_COMPLETED') };

View File

@ -24,7 +24,7 @@ class ScreenManager {
private _padding: { x: number; y: number; };
private _clickEvents: ((event: UIEvent) => void)[];
private _clickEvents;
private _scale: number;
@ -60,14 +60,13 @@ class ScreenManager {
this._scale = scale;
}
addEvent(eventType: string, listener: any) {
addEvent(eventType: string, listener) {
if (eventType === 'click') this._clickEvents.push(listener);
else this._divContainer.bind(eventType, listener);
}
removeEvent(event: string, listener: any) {
removeEvent(event: string, listener) {
if (event === 'click') {
// @ts-ignore @Todo: needs review ...
this._clickEvents.remove(listener);
} else {
this._divContainer.unbind(event, listener);

View File

@ -23,6 +23,7 @@ class SVGExporter implements Exporter {
private prolog = '<?xml version="1.0" encoding="utf-8" standalone="yes"?>\n';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
constructor(mindmap: Mindmap, svgElement: Element, centerImgage = false) {
this.svgElement = svgElement;
}

View File

@ -17,45 +17,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class ChildrenSorterStrategy {
computeChildrenIdByHeights(treeSet, node) {
throw new Error('Method must be implemented');
}
abstract class ChildrenSorterStrategy {
abstract computeChildrenIdByHeights(treeSet, node);
/** @abstract */
computeOffsets(treeSet, node) {
throw new Error('Method must be implemented');
}
abstract computeOffsets(treeSet, node);
/** @abstract */
insert(treeSet, parent, child, order) {
throw new Error('Method must be implemented');
}
abstract insert(treeSet, parent, child, order);
/** @abstract */
detach(treeSet, node) {
throw new Error('Method must be implemented');
}
abstract detach(treeSet, node);
/** @abstract */
predict(treeSet, parent, node, position, free) {
throw new Error('Method must be implemented');
}
abstract predict(treeSet, parent, node, position, free);
/** @abstract */
verify(treeSet, node) {
throw new Error('Method must be implemented');
}
abstract verify(treeSet, node);
/** @abstract */
getChildDirection(treeSet, node) {
throw new Error('Method must be implemented');
}
abstract getChildDirection(treeSet, node);
/** @abstract */
toString() {
throw new Error('Method must be implemented: print name');
}
abstract toString();
}
export default ChildrenSorterStrategy;

View File

@ -280,7 +280,6 @@ abstract class INodeModel {
parent.removeChild(this);
} else {
// If it has not parent, it must be an isolate topic ...
// @ts-ignore
mindmap.removeBranch(this);
}
}

View File

@ -95,7 +95,7 @@ class Mindmap extends IMindmap {
/**
* @param nodeModel
*/
removeBranch(nodeModel: NodeModel): void {
removeBranch(nodeModel: INodeModel): void {
$assert(nodeModel && nodeModel.isNodeModel(), 'Remove node must be invoked with model objects');
this._branches = this._branches.filter((b) => b !== nodeModel);
}

View File

@ -52,7 +52,7 @@ class NodeModel extends INodeModel {
* @param attributes
* @return {mindplot.model.FeatureModel} the created feature model
*/
createFeature(type: FeatureType, attributes: any): FeatureModel {
createFeature(type: FeatureType, attributes): FeatureModel {
return FeatureModelFactory.createModel(type, attributes);
}

View File

@ -25,7 +25,7 @@ import XMLSerializerTango from './XMLSerializerTango';
import Mindmap from '../model/Mindmap';
import XMLMindmapSerializer from './XMLMindmapSerializer';
const codeToSerializer = [
const codeToSerializer: { codeName: string, serializer, migrator }[] = [
{
codeName: ModelCodeName.BETA,
serializer: XMLSerializerBeta,
@ -86,9 +86,9 @@ class XMLSerializerFactory {
// eslint-disable-next-line new-cap
if (found) result = new (codeToSerializer[i].serializer)();
} else {
const { migrator: Migrator } = codeToSerializer[i];
// @ts-ignore
result = new Migrator(result);
const { migrator } = codeToSerializer[i];
// eslint-disable-next-line new-cap
result = new migrator(result);
}
}
$assert(result, `Cound not find serialized for ${version}`);

View File

@ -36,8 +36,8 @@ import {
} from './components/widget/ToolbarNotifier';
// This hack is required to initialize Bootstrap. In future, this should be removed.
// @ts-ignore
global.jQuery = jquery;
const globalAny: any = global;
globalAny.jQuery = jquery;
require('../../../libraries/bootstrap/js/bootstrap.min');
export {

View File

@ -1,6 +1,3 @@
/* eslint-disable import/no-unresolved */
/* eslint-disable no-undef */
/* eslint-disable vars-on-top */
/*
* Copyright [2021] [wisemapping]
*
@ -31,12 +28,12 @@ import LocalStorageManager from './components/LocalStorageManager';
import DesignerOptionsBuilder from './components/DesignerOptionsBuilder';
// This hack is required to initialize Bootstrap. In future, this should be removed.
// @ts-ignore
global.jQuery = jquery;
const globalAny: any = global;
globalAny.jQuery = jquery;
require('../../../libraries/bootstrap/js/bootstrap.min');
// Configure designer options ...
let persistence:PersistenceManager;
let persistence: PersistenceManager;
if (!global.memoryPersistence && !global.readOnly) {
persistence = new RESTPersistenceManager({
documentUrl: '/c/restful/maps/{id}/document',

View File

@ -17,13 +17,17 @@
"ecmaVersion": 12,
"sourceType": "module"
},
"ignorePatterns": [
"**/packages/mindplot/**/*",
"**/dist/**/*"
],
"plugins": [
"react",
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/explicit-module-boundary-types": "error",
"@typescript-eslint/no-unused-vars": "error"
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/explicit-module-boundary-types": "error",
"@typescript-eslint/no-unused-vars": "error"
}
}
}