mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-22 06:37:56 +01:00
Clean up code.
This commit is contained in:
parent
a82771ec40
commit
5dffa99835
@ -39,9 +39,11 @@
|
||||
}
|
||||
],
|
||||
"object-curly-newline": "off",
|
||||
"@typescript-eslint/no-unused-vars": "error",
|
||||
"no-underscore-dangle": "off",
|
||||
"no-plusplus": "off",
|
||||
"no-param-reassign": "off",
|
||||
"@typescript-eslint/no-non-null-assertion": "off",
|
||||
"max-len": [
|
||||
1,
|
||||
300
|
||||
@ -50,8 +52,6 @@
|
||||
"no-console": "off",
|
||||
// codebase contains many this aliases, fix in the future?
|
||||
"@typescript-eslint/no-this-alias": "off",
|
||||
// Remove once migration is completed ...
|
||||
"@typescript-eslint/no-explicit-any": "warn",
|
||||
"import/extensions": [
|
||||
"error",
|
||||
"ignorePackages",
|
||||
|
1
packages/mindplot/src/@types/custom.d.ts
vendored
1
packages/mindplot/src/@types/custom.d.ts
vendored
@ -1,4 +1,5 @@
|
||||
declare module '*.svg' {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const content: any;
|
||||
export default content;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import { $defined } from '@wisemapping/core-js';
|
||||
import Shape from './util/Shape';
|
||||
import ActionDispatcher from './ActionDispatcher';
|
||||
import Workspace from './Workspace';
|
||||
import PositionType from './PositionType';
|
||||
|
||||
class ControlPoint {
|
||||
private control1: Elipse;
|
||||
@ -37,11 +38,13 @@ class ControlPoint {
|
||||
|
||||
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;
|
||||
|
||||
@ -125,17 +128,20 @@ class ControlPoint {
|
||||
this._controls[ControlPoint.FROM].x + pos.x,
|
||||
this._controls[ControlPoint.FROM].y + pos.y - 3,
|
||||
);
|
||||
|
||||
this._controlLines[0].setFrom(pos.x, pos.y);
|
||||
this._controlLines[0].setTo(
|
||||
this._controls[ControlPoint.FROM].x + pos.x + 3,
|
||||
this._controls[ControlPoint.FROM].y + pos.y,
|
||||
);
|
||||
|
||||
pos = this._line.getLine().getTo();
|
||||
this._controlLines[1].setFrom(pos.x, pos.y);
|
||||
this._controlLines[1].setTo(
|
||||
this._controls[ControlPoint.TO].x + pos.x + 3,
|
||||
this._controls[ControlPoint.TO].y + pos.y,
|
||||
);
|
||||
|
||||
this._controlPointsController[1].setPosition(
|
||||
this._controls[ControlPoint.TO].x + pos.x,
|
||||
this._controls[ControlPoint.TO].y + pos.y - 3,
|
||||
@ -223,8 +229,8 @@ class ControlPoint {
|
||||
workspace.append(this._controlLines[1]);
|
||||
}
|
||||
|
||||
removeFromWorkspace(workspace: Workspace) {
|
||||
this._workspace = null;
|
||||
removeFromWorkspace(workspace: Workspace): void {
|
||||
this._workspace!;
|
||||
workspace.removeChild(this._controlPointsController[0]);
|
||||
workspace.removeChild(this._controlPointsController[1]);
|
||||
workspace.removeChild(this._controlLines[0]);
|
||||
@ -235,17 +241,17 @@ class ControlPoint {
|
||||
return this._controls[index];
|
||||
}
|
||||
|
||||
getOriginalEndPoint(index: number) {
|
||||
getOriginalEndPoint(index: number): PositionType {
|
||||
return this._endPoint[index];
|
||||
}
|
||||
|
||||
getOriginalCtrlPoint(index: number): ControlPoint {
|
||||
getOriginalCtrlPoint(index: number): PositionType {
|
||||
return this._orignalCtrlPoint[index];
|
||||
}
|
||||
|
||||
static FROM = 0;
|
||||
private static FROM = 0;
|
||||
|
||||
static TO = 1;
|
||||
private static TO = 1;
|
||||
}
|
||||
|
||||
export default ControlPoint;
|
||||
|
@ -81,7 +81,7 @@ class EmojiCharIcon implements Icon {
|
||||
return this.group.getPosition();
|
||||
}
|
||||
|
||||
addEvent(type: string, fnc: any): void {
|
||||
addEvent(type: string, fnc: () => void): void {
|
||||
this.element.addEvent(type, fnc);
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ ORDER_BY_TYPE.set('link', 2);
|
||||
class IconGroup {
|
||||
private _icons: ImageIcon[];
|
||||
|
||||
private _group: any;
|
||||
private _group: Group;
|
||||
|
||||
private _removeTip: IconGroupRemoveTip;
|
||||
|
||||
|
@ -182,8 +182,8 @@ class Workspace {
|
||||
const workspace = this._workspace;
|
||||
|
||||
const divContainer = this._screenManager.getContainer();
|
||||
const containerWidth = divContainer.width();
|
||||
const containerHeight = divContainer.height();
|
||||
const containerWidth = divContainer.width()!;
|
||||
const containerHeight = divContainer.height()!;
|
||||
const newVisibleAreaSize = { width: containerWidth, height: containerHeight };
|
||||
|
||||
// - svg must fit container size
|
||||
|
@ -28,7 +28,7 @@ class AddFeatureToTopicCommand extends Command {
|
||||
|
||||
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
|
||||
@ -65,7 +65,7 @@ class AddFeatureToTopicCommand extends Command {
|
||||
|
||||
undoExecute(commandContext: CommandContext) {
|
||||
const topic = commandContext.findTopics([this._topicId])[0];
|
||||
topic.removeFeature(this._featureModel);
|
||||
topic.removeFeature(this._featureModel!);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ class AddTopicCommand extends Command {
|
||||
|
||||
undoExecute(commandContext: CommandContext) {
|
||||
// Delete disconnected the nodes. Create a copy of the topics ...
|
||||
const clonedModel = [];
|
||||
const clonedModel: NodeModel[] = [];
|
||||
this._models.forEach((model) => {
|
||||
clonedModel.push(model.clone());
|
||||
});
|
||||
|
@ -34,7 +34,7 @@ class MoveControlPointCommand extends Command {
|
||||
|
||||
private _wasCustom: boolean;
|
||||
|
||||
private _endPoint: any;
|
||||
private _endPoint: PositionType;
|
||||
|
||||
private _point: number;
|
||||
|
||||
@ -52,7 +52,7 @@ class MoveControlPointCommand extends Command {
|
||||
this._ctrlPointControler = ctrlPointController;
|
||||
this._line = ctrlPointController._line;
|
||||
this._controlPoint = { ...this._ctrlPointControler.getControlPoint(point) };
|
||||
this._oldControlPoint = { ...this._ctrlPointControler.getOriginalCtrlPoint(point) };
|
||||
this._oldControlPoint = this._ctrlPointControler.getOriginalCtrlPoint(point);
|
||||
this._originalEndPoint = this._ctrlPointControler.getOriginalEndPoint(point);
|
||||
switch (point) {
|
||||
case 0:
|
||||
|
@ -66,25 +66,28 @@ class SVGExporter extends Exporter {
|
||||
private _calcualteDimensions(): { minX: number; maxX: number; minY: number; maxY: number } {
|
||||
// Collect all group elements ...
|
||||
const rectElems = Array.from(this.svgElement.querySelectorAll('g>rect'));
|
||||
let result: SizeType = { width: 0, height: 0 };
|
||||
const translates: SizeType[] = rectElems.map((rect: Element) => {
|
||||
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)
|
||||
const match = transformStr.match(SVGExporter.regexpTranslate);
|
||||
if (match !== null) {
|
||||
result = { width: Number.parseFloat(match[1]), height: Number.parseFloat(match[2]) };
|
||||
|
||||
// Looking to parse translate(220.00000,279.00000) scale(1.00000,1.00000)
|
||||
const match = transformStr.match(SVGExporter.regexpTranslate);
|
||||
let result: SizeType = { width: 0, height: 0 };
|
||||
if (match !== null) {
|
||||
result = { width: Number.parseFloat(match[1]), height: Number.parseFloat(match[2]) };
|
||||
// Add rect size ...
|
||||
const width = rect.getAttribute('width');
|
||||
if (result.width > 0 && width) {
|
||||
const rectWidth = Number.parseFloat(width);
|
||||
result.width += rectWidth;
|
||||
}
|
||||
|
||||
// Add rect size ...
|
||||
if (result.width > 0) {
|
||||
const rectWidth = Number.parseFloat(rect.getAttribute('width'));
|
||||
result.width += rectWidth;
|
||||
}
|
||||
|
||||
if (result.height > 0) {
|
||||
const rectHeight = Number.parseFloat(rect.getAttribute('height'));
|
||||
result.height += rectHeight;
|
||||
const height = rect.getAttribute('height');
|
||||
if (result.height > 0 && height) {
|
||||
const rectHeight = Number.parseFloat(height);
|
||||
result.height += rectHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -169,7 +169,7 @@ export default class FreemindImporter extends Importer {
|
||||
}
|
||||
|
||||
// Check for style...
|
||||
const fontStyle = this.generateFontStyle(freeNode, null);
|
||||
const fontStyle = this.generateFontStyle(freeNode);
|
||||
if (fontStyle && fontStyle !== ';;;;') wiseTopic.setFontStyle(fontStyle);
|
||||
|
||||
// Is there any link...
|
||||
@ -393,7 +393,7 @@ export default class FreemindImporter extends Importer {
|
||||
return result;
|
||||
}
|
||||
|
||||
private generateFontStyle(node: FreemindNode, font: FreemindFont | undefined): string {
|
||||
private generateFontStyle(node: FreemindNode, font?: FreemindFont): string {
|
||||
const fontStyle: Array<string> = [];
|
||||
|
||||
// Font family
|
||||
@ -485,6 +485,6 @@ export default class FreemindImporter extends Importer {
|
||||
private html2Text(content: string): string {
|
||||
const temporalDivElement = document.createElement('div');
|
||||
temporalDivElement.innerHTML = content;
|
||||
return temporalDivElement.textContent.trim() || temporalDivElement.innerText.trim() || '';
|
||||
return temporalDivElement.textContent?.trim() || temporalDivElement.innerText.trim() || '';
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,12 @@ abstract class ChildrenSorterStrategy {
|
||||
|
||||
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);
|
||||
|
||||
|
@ -24,7 +24,7 @@ class Node {
|
||||
private _id: number;
|
||||
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
_parent: Node;
|
||||
_parent: Node | null;
|
||||
|
||||
private _sorter: ChildrenSorterStrategy;
|
||||
|
||||
|
@ -89,7 +89,7 @@ class RootedTreeSet {
|
||||
* @throws will throw an error if nodeId is null or undefined
|
||||
* @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');
|
||||
const node = this.find(nodeId);
|
||||
$assert(node._parent, 'Node is not connected');
|
||||
@ -106,11 +106,11 @@ class RootedTreeSet {
|
||||
* @throws will throw an error if node cannot be found
|
||||
* @return node
|
||||
*/
|
||||
find(id: number, validate = true): Node {
|
||||
find(id: number, validate = true): Node | null {
|
||||
$assert($defined(id), 'id can not be null');
|
||||
|
||||
const graphs = this._rootNodes;
|
||||
let result = null;
|
||||
let result: Node | null = null;
|
||||
for (let i = 0; i < graphs.length; i++) {
|
||||
const node = graphs[i];
|
||||
result = this._find(id, node);
|
||||
@ -126,12 +126,12 @@ class RootedTreeSet {
|
||||
return result;
|
||||
}
|
||||
|
||||
private _find(id: number, parent: Node): Node {
|
||||
private _find(id: number, parent: Node): Node | null {
|
||||
if (parent.getId() === id) {
|
||||
return parent;
|
||||
}
|
||||
|
||||
let result = null;
|
||||
let result: Node | null = null;
|
||||
const children = parent._children;
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
const child = children[i];
|
||||
@ -192,10 +192,10 @@ class RootedTreeSet {
|
||||
*/
|
||||
getSiblings(node: Node): Node[] {
|
||||
$assert(node, 'node cannot be null');
|
||||
if (!$defined(node._parent)) {
|
||||
if (!node._parent) {
|
||||
return [];
|
||||
}
|
||||
const siblings = node._parent._children.filter((child) => child !== node);
|
||||
const siblings = node._parent?._children.filter((child) => child !== node);
|
||||
return siblings;
|
||||
}
|
||||
|
||||
@ -241,7 +241,7 @@ class RootedTreeSet {
|
||||
* @throws will throw an error if node is null or undefined
|
||||
* @return parent
|
||||
*/
|
||||
getParent(node: Node): Node {
|
||||
getParent(node: Node): Node | null {
|
||||
$assert(node, 'node cannot be null');
|
||||
return node._parent;
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ abstract class IMindmap {
|
||||
$assert(child, 'Child can not be null.');
|
||||
$assert(parent, 'Child model seems to be already connected');
|
||||
|
||||
parent.removeChild(child);
|
||||
parent?.removeChild(child);
|
||||
this.addBranch(child);
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ abstract class INodeModel {
|
||||
abstract getFeatures(): FeatureModel[];
|
||||
|
||||
setId(id?: number): void {
|
||||
if (!$defined(id)) {
|
||||
if (id === null || id === undefined) {
|
||||
const newId = INodeModel._nextUUID();
|
||||
this.putProperty('id', newId);
|
||||
} else {
|
||||
|
@ -15,7 +15,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { $assert } from '@wisemapping/core-js';
|
||||
import ModelCodeName from './ModelCodeName';
|
||||
import Beta2PelaMigrator from './Beta2PelaMigrator';
|
||||
import Pela2TangoMigrator from './Pela2TangoMigrator';
|
||||
@ -89,7 +88,9 @@ class XMLSerializerFactory {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,7 @@ declare global {
|
||||
var designer: Designer;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const globalAny: any = global;
|
||||
globalAny.jQuery = jquery;
|
||||
// WebComponent registration
|
||||
|
Loading…
Reference in New Issue
Block a user