Clean up code.

This commit is contained in:
Paulo Gustavo Veiga 2022-11-24 10:40:18 -08:00
parent a82771ec40
commit 5dffa99835
18 changed files with 69 additions and 52 deletions

View File

@ -39,9 +39,11 @@
} }
], ],
"object-curly-newline": "off", "object-curly-newline": "off",
"@typescript-eslint/no-unused-vars": "error",
"no-underscore-dangle": "off", "no-underscore-dangle": "off",
"no-plusplus": "off", "no-plusplus": "off",
"no-param-reassign": "off", "no-param-reassign": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"max-len": [ "max-len": [
1, 1,
300 300
@ -50,8 +52,6 @@
"no-console": "off", "no-console": "off",
// codebase contains many this aliases, fix in the future? // codebase contains many this aliases, fix in the future?
"@typescript-eslint/no-this-alias": "off", "@typescript-eslint/no-this-alias": "off",
// Remove once migration is completed ...
"@typescript-eslint/no-explicit-any": "warn",
"import/extensions": [ "import/extensions": [
"error", "error",
"ignorePackages", "ignorePackages",

View File

@ -1,4 +1,5 @@
declare module '*.svg' { declare module '*.svg' {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const content: any; const content: any;
export default content; export default content;
} }

View File

@ -21,6 +21,7 @@ import { $defined } from '@wisemapping/core-js';
import Shape from './util/Shape'; import Shape from './util/Shape';
import ActionDispatcher from './ActionDispatcher'; import ActionDispatcher from './ActionDispatcher';
import Workspace from './Workspace'; import Workspace from './Workspace';
import PositionType from './PositionType';
class ControlPoint { class ControlPoint {
private control1: Elipse; private control1: Elipse;
@ -37,11 +38,13 @@ class ControlPoint {
private _workspace: Workspace; private _workspace: Workspace;
private _endPoint: any[]; // eslint-disable-next-line no-use-before-define
private _endPoint: PositionType[];
private _orignalCtrlPoint: any; // eslint-disable-next-line no-use-before-define
private _orignalCtrlPoint: PositionType[];
private _controls: any; private _controls: number;
private _mouseMoveFunction: (e: Event) => void; private _mouseMoveFunction: (e: Event) => void;
@ -125,17 +128,20 @@ class ControlPoint {
this._controls[ControlPoint.FROM].x + pos.x, this._controls[ControlPoint.FROM].x + pos.x,
this._controls[ControlPoint.FROM].y + pos.y - 3, this._controls[ControlPoint.FROM].y + pos.y - 3,
); );
this._controlLines[0].setFrom(pos.x, pos.y); this._controlLines[0].setFrom(pos.x, pos.y);
this._controlLines[0].setTo( this._controlLines[0].setTo(
this._controls[ControlPoint.FROM].x + pos.x + 3, this._controls[ControlPoint.FROM].x + pos.x + 3,
this._controls[ControlPoint.FROM].y + pos.y, this._controls[ControlPoint.FROM].y + pos.y,
); );
pos = this._line.getLine().getTo(); pos = this._line.getLine().getTo();
this._controlLines[1].setFrom(pos.x, pos.y); this._controlLines[1].setFrom(pos.x, pos.y);
this._controlLines[1].setTo( this._controlLines[1].setTo(
this._controls[ControlPoint.TO].x + pos.x + 3, this._controls[ControlPoint.TO].x + pos.x + 3,
this._controls[ControlPoint.TO].y + pos.y, this._controls[ControlPoint.TO].y + pos.y,
); );
this._controlPointsController[1].setPosition( this._controlPointsController[1].setPosition(
this._controls[ControlPoint.TO].x + pos.x, this._controls[ControlPoint.TO].x + pos.x,
this._controls[ControlPoint.TO].y + pos.y - 3, this._controls[ControlPoint.TO].y + pos.y - 3,
@ -223,8 +229,8 @@ class ControlPoint {
workspace.append(this._controlLines[1]); workspace.append(this._controlLines[1]);
} }
removeFromWorkspace(workspace: Workspace) { removeFromWorkspace(workspace: Workspace): void {
this._workspace = null; this._workspace!;
workspace.removeChild(this._controlPointsController[0]); workspace.removeChild(this._controlPointsController[0]);
workspace.removeChild(this._controlPointsController[1]); workspace.removeChild(this._controlPointsController[1]);
workspace.removeChild(this._controlLines[0]); workspace.removeChild(this._controlLines[0]);
@ -235,17 +241,17 @@ class ControlPoint {
return this._controls[index]; return this._controls[index];
} }
getOriginalEndPoint(index: number) { getOriginalEndPoint(index: number): PositionType {
return this._endPoint[index]; return this._endPoint[index];
} }
getOriginalCtrlPoint(index: number): ControlPoint { getOriginalCtrlPoint(index: number): PositionType {
return this._orignalCtrlPoint[index]; return this._orignalCtrlPoint[index];
} }
static FROM = 0; private static FROM = 0;
static TO = 1; private static TO = 1;
} }
export default ControlPoint; export default ControlPoint;

View File

@ -81,7 +81,7 @@ class EmojiCharIcon implements Icon {
return this.group.getPosition(); return this.group.getPosition();
} }
addEvent(type: string, fnc: any): void { addEvent(type: string, fnc: () => void): void {
this.element.addEvent(type, fnc); this.element.addEvent(type, fnc);
} }

View File

@ -31,7 +31,7 @@ ORDER_BY_TYPE.set('link', 2);
class IconGroup { class IconGroup {
private _icons: ImageIcon[]; private _icons: ImageIcon[];
private _group: any; private _group: Group;
private _removeTip: IconGroupRemoveTip; private _removeTip: IconGroupRemoveTip;

View File

@ -182,8 +182,8 @@ class Workspace {
const workspace = this._workspace; const workspace = this._workspace;
const divContainer = this._screenManager.getContainer(); const divContainer = this._screenManager.getContainer();
const containerWidth = divContainer.width(); const containerWidth = divContainer.width()!;
const containerHeight = divContainer.height(); const containerHeight = divContainer.height()!;
const newVisibleAreaSize = { width: containerWidth, height: containerHeight }; const newVisibleAreaSize = { width: containerWidth, height: containerHeight };
// - svg must fit container size // - svg must fit container size

View File

@ -28,7 +28,7 @@ class AddFeatureToTopicCommand extends Command {
private _attributes: object; private _attributes: object;
private _featureModel: FeatureModel; private _featureModel: FeatureModel | null;
/* /*
* @classdesc This command class handles do/undo of adding features to topics, e.g. an * @classdesc This command class handles do/undo of adding features to topics, e.g. an
@ -65,7 +65,7 @@ class AddFeatureToTopicCommand extends Command {
undoExecute(commandContext: CommandContext) { undoExecute(commandContext: CommandContext) {
const topic = commandContext.findTopics([this._topicId])[0]; const topic = commandContext.findTopics([this._topicId])[0];
topic.removeFeature(this._featureModel); topic.removeFeature(this._featureModel!);
} }
} }

View File

@ -70,7 +70,7 @@ class AddTopicCommand extends Command {
undoExecute(commandContext: CommandContext) { undoExecute(commandContext: CommandContext) {
// Delete disconnected the nodes. Create a copy of the topics ... // Delete disconnected the nodes. Create a copy of the topics ...
const clonedModel = []; const clonedModel: NodeModel[] = [];
this._models.forEach((model) => { this._models.forEach((model) => {
clonedModel.push(model.clone()); clonedModel.push(model.clone());
}); });

View File

@ -34,7 +34,7 @@ class MoveControlPointCommand extends Command {
private _wasCustom: boolean; private _wasCustom: boolean;
private _endPoint: any; private _endPoint: PositionType;
private _point: number; private _point: number;
@ -52,7 +52,7 @@ class MoveControlPointCommand extends Command {
this._ctrlPointControler = ctrlPointController; this._ctrlPointControler = ctrlPointController;
this._line = ctrlPointController._line; this._line = ctrlPointController._line;
this._controlPoint = { ...this._ctrlPointControler.getControlPoint(point) }; this._controlPoint = { ...this._ctrlPointControler.getControlPoint(point) };
this._oldControlPoint = { ...this._ctrlPointControler.getOriginalCtrlPoint(point) }; this._oldControlPoint = this._ctrlPointControler.getOriginalCtrlPoint(point);
this._originalEndPoint = this._ctrlPointControler.getOriginalEndPoint(point); this._originalEndPoint = this._ctrlPointControler.getOriginalEndPoint(point);
switch (point) { switch (point) {
case 0: case 0:

View File

@ -66,27 +66,30 @@ class SVGExporter extends Exporter {
private _calcualteDimensions(): { minX: number; maxX: number; minY: number; maxY: number } { private _calcualteDimensions(): { minX: number; maxX: number; minY: number; maxY: number } {
// Collect all group elements ... // Collect all group elements ...
const rectElems = Array.from(this.svgElement.querySelectorAll('g>rect')); const rectElems = Array.from(this.svgElement.querySelectorAll('g>rect'));
let result: SizeType = { width: 0, height: 0 };
const translates: SizeType[] = rectElems.map((rect: Element) => { const translates: SizeType[] = rectElems.map((rect: Element) => {
const g = rect.parentElement; const g = rect.parentElement;
const transformStr = g.getAttribute('transform'); const transformStr = g?.getAttribute('transform');
if (transformStr) {
// Looking to parse translate(220.00000,279.00000) scale(1.00000,1.00000) // Looking to parse translate(220.00000,279.00000) scale(1.00000,1.00000)
const match = transformStr.match(SVGExporter.regexpTranslate); const match = transformStr.match(SVGExporter.regexpTranslate);
let result: SizeType = { width: 0, height: 0 };
if (match !== null) { if (match !== null) {
result = { width: Number.parseFloat(match[1]), height: Number.parseFloat(match[2]) }; result = { width: Number.parseFloat(match[1]), height: Number.parseFloat(match[2]) };
// Add rect size ... // Add rect size ...
if (result.width > 0) { const width = rect.getAttribute('width');
const rectWidth = Number.parseFloat(rect.getAttribute('width')); if (result.width > 0 && width) {
const rectWidth = Number.parseFloat(width);
result.width += rectWidth; result.width += rectWidth;
} }
if (result.height > 0) { const height = rect.getAttribute('height');
const rectHeight = Number.parseFloat(rect.getAttribute('height')); if (result.height > 0 && height) {
const rectHeight = Number.parseFloat(height);
result.height += rectHeight; result.height += rectHeight;
} }
} }
}
return result; return result;
}); });

View File

@ -169,7 +169,7 @@ export default class FreemindImporter extends Importer {
} }
// Check for style... // Check for style...
const fontStyle = this.generateFontStyle(freeNode, null); const fontStyle = this.generateFontStyle(freeNode);
if (fontStyle && fontStyle !== ';;;;') wiseTopic.setFontStyle(fontStyle); if (fontStyle && fontStyle !== ';;;;') wiseTopic.setFontStyle(fontStyle);
// Is there any link... // Is there any link...
@ -393,7 +393,7 @@ export default class FreemindImporter extends Importer {
return result; return result;
} }
private generateFontStyle(node: FreemindNode, font: FreemindFont | undefined): string { private generateFontStyle(node: FreemindNode, font?: FreemindFont): string {
const fontStyle: Array<string> = []; const fontStyle: Array<string> = [];
// Font family // Font family
@ -485,6 +485,6 @@ export default class FreemindImporter extends Importer {
private html2Text(content: string): string { private html2Text(content: string): string {
const temporalDivElement = document.createElement('div'); const temporalDivElement = document.createElement('div');
temporalDivElement.innerHTML = content; temporalDivElement.innerHTML = content;
return temporalDivElement.textContent.trim() || temporalDivElement.innerText.trim() || ''; return temporalDivElement.textContent?.trim() || temporalDivElement.innerText.trim() || '';
} }
} }

View File

@ -28,7 +28,12 @@ abstract class ChildrenSorterStrategy {
abstract detach(treeSet: RootedTreeSet, node: Node): void; abstract detach(treeSet: RootedTreeSet, node: Node): void;
abstract predict(treeSet: RootedTreeSet, parent, node: Node | null, position: PositionType); abstract predict(
treeSet: RootedTreeSet,
parent: Node,
node: Node | null,
position: PositionType | null,
);
abstract verify(treeSet: RootedTreeSet, node: Node); abstract verify(treeSet: RootedTreeSet, node: Node);

View File

@ -24,7 +24,7 @@ class Node {
private _id: number; private _id: number;
// eslint-disable-next-line no-use-before-define // eslint-disable-next-line no-use-before-define
_parent: Node; _parent: Node | null;
private _sorter: ChildrenSorterStrategy; private _sorter: ChildrenSorterStrategy;

View File

@ -89,7 +89,7 @@ class RootedTreeSet {
* @throws will throw an error if nodeId is null or undefined * @throws will throw an error if nodeId is null or undefined
* @throws will throw an error if node is not connected * @throws will throw an error if node is not connected
*/ */
disconnect(nodeId: number) { disconnect(nodeId: number): void {
$assert($defined(nodeId), 'nodeId can not be null'); $assert($defined(nodeId), 'nodeId can not be null');
const node = this.find(nodeId); const node = this.find(nodeId);
$assert(node._parent, 'Node is not connected'); $assert(node._parent, 'Node is not connected');
@ -106,11 +106,11 @@ class RootedTreeSet {
* @throws will throw an error if node cannot be found * @throws will throw an error if node cannot be found
* @return node * @return node
*/ */
find(id: number, validate = true): Node { find(id: number, validate = true): Node | null {
$assert($defined(id), 'id can not be null'); $assert($defined(id), 'id can not be null');
const graphs = this._rootNodes; const graphs = this._rootNodes;
let result = null; let result: Node | null = null;
for (let i = 0; i < graphs.length; i++) { for (let i = 0; i < graphs.length; i++) {
const node = graphs[i]; const node = graphs[i];
result = this._find(id, node); result = this._find(id, node);
@ -126,12 +126,12 @@ class RootedTreeSet {
return result; return result;
} }
private _find(id: number, parent: Node): Node { private _find(id: number, parent: Node): Node | null {
if (parent.getId() === id) { if (parent.getId() === id) {
return parent; return parent;
} }
let result = null; let result: Node | null = null;
const children = parent._children; const children = parent._children;
for (let i = 0; i < children.length; i++) { for (let i = 0; i < children.length; i++) {
const child = children[i]; const child = children[i];
@ -192,10 +192,10 @@ class RootedTreeSet {
*/ */
getSiblings(node: Node): Node[] { getSiblings(node: Node): Node[] {
$assert(node, 'node cannot be null'); $assert(node, 'node cannot be null');
if (!$defined(node._parent)) { if (!node._parent) {
return []; return [];
} }
const siblings = node._parent._children.filter((child) => child !== node); const siblings = node._parent?._children.filter((child) => child !== node);
return siblings; return siblings;
} }
@ -241,7 +241,7 @@ class RootedTreeSet {
* @throws will throw an error if node is null or undefined * @throws will throw an error if node is null or undefined
* @return parent * @return parent
*/ */
getParent(node: Node): Node { getParent(node: Node): Node | null {
$assert(node, 'node cannot be null'); $assert(node, 'node cannot be null');
return node._parent; return node._parent;
} }

View File

@ -67,7 +67,7 @@ abstract class IMindmap {
$assert(child, 'Child can not be null.'); $assert(child, 'Child can not be null.');
$assert(parent, 'Child model seems to be already connected'); $assert(parent, 'Child model seems to be already connected');
parent.removeChild(child); parent?.removeChild(child);
this.addBranch(child); this.addBranch(child);
} }

View File

@ -46,7 +46,7 @@ abstract class INodeModel {
abstract getFeatures(): FeatureModel[]; abstract getFeatures(): FeatureModel[];
setId(id?: number): void { setId(id?: number): void {
if (!$defined(id)) { if (id === null || id === undefined) {
const newId = INodeModel._nextUUID(); const newId = INodeModel._nextUUID();
this.putProperty('id', newId); this.putProperty('id', newId);
} else { } else {

View File

@ -15,7 +15,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { $assert } from '@wisemapping/core-js';
import ModelCodeName from './ModelCodeName'; import ModelCodeName from './ModelCodeName';
import Beta2PelaMigrator from './Beta2PelaMigrator'; import Beta2PelaMigrator from './Beta2PelaMigrator';
import Pela2TangoMigrator from './Pela2TangoMigrator'; import Pela2TangoMigrator from './Pela2TangoMigrator';
@ -89,7 +88,9 @@ class XMLSerializerFactory {
result = new migrator(result); result = new migrator(result);
} }
} }
$assert(result, `Cound not find serialized for ${version}`); if (!result) {
throw new Error(`Cound not find serialized for ${version}`);
}
return result; return result;
} }
} }

View File

@ -58,6 +58,7 @@ declare global {
var designer: Designer; var designer: Designer;
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const globalAny: any = global; const globalAny: any = global;
globalAny.jQuery = jquery; globalAny.jQuery = jquery;
// WebComponent registration // WebComponent registration