Merged in eslint-prettier-config (pull request #53)

Eslint prettier config

* config eslint + manual fixes

* Merge branch 'develop' into eslint-prettier-config

* fixes eslint web2d


Approved-by: Paulo Veiga
This commit is contained in:
Gustavo Fuhr 2022-07-14 03:12:12 +00:00 committed by Paulo Veiga
parent 5ee7448d3c
commit 19353a9423
9 changed files with 144 additions and 136 deletions

View File

@ -22,7 +22,7 @@
"@typescript-eslint"
],
"rules": {
// ignore errores when a line finishes with (setting this value to 0 ignores all errors)
// ignore errors when a line finishes with (setting this value to 0 ignores all errors)
"operator-linebreak": [
"error", "after", {
"overrides": {

View File

@ -33,7 +33,8 @@ class OriginalLayout {
$assert(position, 'position can not be null');
$assert(type, 'type can not be null');
const strategy = type === 'root' ? OriginalLayout.BALANCED_SORTER : OriginalLayout.SYMMETRIC_SORTER;
const strategy =
type === 'root' ? OriginalLayout.BALANCED_SORTER : OriginalLayout.SYMMETRIC_SORTER;
return new Node(id, size, position, strategy);
}
@ -77,7 +78,7 @@ class OriginalLayout {
/** */
layout() {
const roots = this._treeSet.getTreeRoots();
roots.forEach(((node) => {
roots.forEach((node) => {
// Calculate all node heights ...
const sorter = node.getSorter();
@ -85,7 +86,7 @@ class OriginalLayout {
this._layoutChildren(node, heightById);
this._fixOverlapping(node, heightById);
}));
});
}
_layoutChildren(node, heightById) {
@ -117,8 +118,8 @@ class OriginalLayout {
const direction = node.getSorter().getChildDirection(me._treeSet, child);
if (
(direction > 0 && childFreeDisplacement.x < 0)
|| (direction < 0 && childFreeDisplacement.x > 0)
(direction > 0 && childFreeDisplacement.x < 0) ||
(direction < 0 && childFreeDisplacement.x > 0)
) {
child.resetFreeDisplacement();
child.setFreeDisplacement({
@ -145,9 +146,9 @@ class OriginalLayout {
}
// Continue reordering the children nodes ...
children.forEach(((child) => {
children.forEach((child) => {
this._layoutChildren(child, heightById);
}));
});
}
_calculateAlignOffset(node, child, heightById) {
@ -161,12 +162,13 @@ class OriginalLayout {
const childHeight = child.getSize().height;
if (
this._treeSet.isStartOfSubBranch(child)
&& OriginalLayout._branchIsTaller(child, heightById)
this._treeSet.isStartOfSubBranch(child) &&
OriginalLayout._branchIsTaller(child, heightById)
) {
if (this._treeSet.hasSinglePathToSingleLeaf(child)) {
offset = heightById[child.getId()] / 2
- (childHeight + child.getSorter()._getVerticalPadding() * 2) / 2;
offset =
heightById[child.getId()] / 2 -
(childHeight + child.getSorter()._getVerticalPadding() * 2) / 2;
} else {
offset = this._treeSet.isLeaf(child) ? 0 : -(childHeight - nodeHeight) / 2;
}
@ -189,8 +191,7 @@ class OriginalLayout {
static _branchIsTaller(node, heightById) {
return (
heightById[node.getId()]
> node.getSize().height + node.getSorter()._getVerticalPadding() * 2
heightById[node.getId()] > node.getSize().height + node.getSorter()._getVerticalPadding() * 2
);
}
@ -200,9 +201,9 @@ class OriginalLayout {
if (node.isFree()) {
this._shiftBranches(node, heightById);
}
children.forEach(((child) => {
children.forEach((child) => {
this._fixOverlapping(child, heightById);
}));
});
}
_shiftBranches(node, heightById) {
@ -213,27 +214,28 @@ class OriginalLayout {
node.getFreeDisplacement().y,
);
siblingsToShift.forEach(((sibling) => {
const overlappingOccurs = shiftedBranches.some(
((shiftedBranch) => OriginalLayout._branchesOverlap(shiftedBranch, sibling, heightById)),
siblingsToShift.forEach((sibling) => {
/* eslint-disable */
const overlappingOccurs = shiftedBranches.some((shiftedBranch) =>
OriginalLayout._branchesOverlap(shiftedBranch, sibling, heightById),
);
/* eslint-enable */
if (!sibling.isFree() || overlappingOccurs) {
const sAmount = node.getFreeDisplacement().y;
this._treeSet.shiftBranchPosition(sibling, 0, sAmount);
shiftedBranches.push(sibling);
}
}));
});
const branchesToShift = this._treeSet
.getBranchesInVerticalDirection(node, node.getFreeDisplacement().y)
.filter((branch) => !shiftedBranches.includes(branch));
branchesToShift.forEach(((branch) => {
branchesToShift.forEach((branch) => {
const bAmount = node.getFreeDisplacement().y;
this._treeSet.shiftBranchPosition(branch, 0, bAmount);
shiftedBranches.push(branch);
}));
});
}
static _branchesOverlap(branchA, branchB, heightById) {

View File

@ -75,9 +75,7 @@ class BootstrapDialog extends Options {
)}</button>`,
);
footer.append(this.acceptButton);
this.acceptButton
.unbind('click')
.on('click', this.options.onEventData, this.onAcceptClick);
this.acceptButton.unbind('click').on('click', this.options.onEventData, this.onAcceptClick);
}
if (this.options.removeButton) {
this.removeButton = $(

View File

@ -15,7 +15,25 @@
"import/no-extraneous-dependencies": ["warn", {
"packageDir": ["./"],
"devDependencies": ["!cypress/**/*.js"]
}]
}],
// ignore errors when a line finishes with (setting this value to 0 ignores all errors)
"operator-linebreak": [
"error", "after", {
"overrides": {
"+": "ignore",
"-": "ignore",
":": "ignore",
"*": "ignore",
"?": "ignore",
">": "ignore",
"||": "ignore",
"&&": "ignore",
"(": "ignore"
}
}
],
"object-curly-newline": "off",
"indent": "off"
},
"settings": {
"import/resolver": {

View File

@ -76,17 +76,17 @@ class ElementClass {
}
/**
* Allows the registration of event listeners on the event target.
* type
* A string representing the event type to listen for.
* listener
* The object that receives a notification when an event of the
* specified type occurs. This must be an object implementing the
* EventListener interface, or simply a function in JavaScript.
*
* The following events types are supported:
*
*/
* Allows the registration of event listeners on the event target.
* type
* A string representing the event type to listen for.
* listener
* The object that receives a notification when an event of the
* specified type occurs. This must be an object implementing the
* EventListener interface, or simply a function in JavaScript.
*
* The following events types are supported:
*
*/
addEvent(type, listener) {
this.peer.addEvent(type, listener);
}
@ -100,26 +100,26 @@ class ElementClass {
}
/**
*
* Allows the removal of event listeners from the event target.
*
* Parameters:
* type
* A string representing the event type being registered.
* listener
* The listener parameter takes an interface implemented by
* the user which contains the methods to be called when the event occurs.
* This interace will be invoked passing an event as argument and
* the 'this' referece in the function will be the element.
*/
*
* Allows the removal of event listeners from the event target.
*
* Parameters:
* type
* A string representing the event type being registered.
* listener
* The listener parameter takes an interface implemented by
* the user which contains the methods to be called when the event occurs.
* This interace will be invoked passing an event as argument and
* the 'this' referece in the function will be the element.
*/
removeEvent(type, listener) {
this.peer.removeEvent(type, listener);
}
/**
* /*
* Returns element type name.
*/
* /*
* Returns element type name.
*/
// eslint-disable-next-line class-methods-use-this
getType() {
throw new Error(
@ -128,17 +128,17 @@ class ElementClass {
}
/**
* Todo: Doc
*/
* Todo: Doc
*/
getFill() {
return this.peer.getFill();
}
/**
* Used to define the fill element color and element opacity.
* color: Fill color
* opacity: Opacity of the fill. It must be less than 1.
*/
* Used to define the fill element color and element opacity.
* color: Fill color
* opacity: Opacity of the fill. It must be less than 1.
*/
setFill(color, opacity) {
this.peer.setFill(color, opacity);
}
@ -152,21 +152,21 @@ class ElementClass {
}
/*
* Defines the element stroke properties.
* width: stroke width
* style: "solid|dot|dash|dashdot|longdash".
* color: stroke color
* opacity: stroke visibility
*/
* Defines the element stroke properties.
* width: stroke width
* style: "solid|dot|dash|dashdot|longdash".
* color: stroke color
* opacity: stroke visibility
*/
setStroke(width, style, color, opacity) {
if (
style != null
&& style !== undefined
&& style !== 'dash'
&& style !== 'dot'
&& style !== 'solid'
&& style !== 'longdash'
&& style !== 'dashdot'
style != null &&
style !== undefined &&
style !== 'dash' &&
style !== 'dot' &&
style !== 'solid' &&
style !== 'longdash' &&
style !== 'dashdot'
) {
throw new Error(`Unsupported stroke style: '${style}'`);
}
@ -185,13 +185,13 @@ class ElementClass {
}
/**
* All element properties can be setted using either a method
* invocation or attribute invocation.
* key: size, width, height, position, x, y, stroke, strokeWidth, strokeStyle,
* strokeColor, strokeOpacity,
* fill, fillColor, fillOpacity, coordSize, coordSizeWidth, coordSizeHeight,
* coordOrigin, coordOriginX, coordOrigiY
*/
* All element properties can be setted using either a method
* invocation or attribute invocation.
* key: size, width, height, position, x, y, stroke, strokeWidth, strokeStyle,
* strokeColor, strokeOpacity,
* fill, fillColor, fillOpacity, coordSize, coordSizeWidth, coordSizeHeight,
* coordOrigin, coordOriginX, coordOrigiY
*/
setAttribute(key, value) {
const funcName = this._attributeNameToFuncName(key, 'set');
@ -246,10 +246,10 @@ class ElementClass {
}
/**
* Defines the element opacity.
* Parameters:
* opacity: A value between 0 and 1.
*/
* Defines the element opacity.
* Parameters:
* opacity: A value between 0 and 1.
*/
setOpacity(opacity) {
this.peer.setStroke(null, null, null, opacity);
this.peer.setFill(null, opacity);
@ -264,15 +264,15 @@ class ElementClass {
}
/**
* Move the element to the front
*/
* Move the element to the front
*/
moveToFront() {
this.peer.moveToFront();
}
/**
* Move the element to the back
*/
* Move the element to the back
*/
moveToBack() {
this.peer.moveToBack();
}

View File

@ -49,12 +49,7 @@ class ArrowPeer extends ElementPeer {
}
setDashed(isDashed, length, spacing) {
if (
$defined(isDashed)
&& isDashed
&& $defined(length)
&& $defined(spacing)
) {
if ($defined(isDashed) && isDashed && $defined(length) && $defined(spacing)) {
this._native.setAttribute('stroke-dasharray', `${length}${spacing}`);
} else {
this._native.setAttribute('stroke-dasharray', '');
@ -77,10 +72,10 @@ class ArrowPeer extends ElementPeer {
let xp;
let yp;
if (
$defined(this._fromPoint.x)
&& $defined(this._fromPoint.y)
&& $defined(this._controlPoint.x)
&& $defined(this._controlPoint.y)
$defined(this._fromPoint.x) &&
$defined(this._fromPoint.y) &&
$defined(this._controlPoint.x) &&
$defined(this._controlPoint.y)
) {
if (this._controlPoint.y === 0) this._controlPoint.y = 1;
@ -103,10 +98,12 @@ class ArrowPeer extends ElementPeer {
xp *= Math.sign(x3);
yp = x3 === 0 ? l * Math.sign(y3) : mp * xp;
const path = `M${this._fromPoint.x},${this._fromPoint.y} `
+ `L${x + this._fromPoint.x},${y + this._fromPoint.y} M${this._fromPoint.x},${this._fromPoint.y
} `
+ `L${xp + this._fromPoint.x},${yp + this._fromPoint.y}`;
const path =
`M${this._fromPoint.x},${this._fromPoint.y} ` +
`L${x + this._fromPoint.x},${y + this._fromPoint.y} M${this._fromPoint.x},${
this._fromPoint.y
} ` +
`L${xp + this._fromPoint.x},${yp + this._fromPoint.y}`;
this._native.setAttribute('d', path);
}
}

View File

@ -148,19 +148,25 @@ class CurvedLinePeer extends ElementPeer {
}
_updatePath(avoidControlPointFix) {
if (
$defined(this._x1)
&& $defined(this._y1)
&& $defined(this._x2)
&& $defined(this._y2)
) {
if ($defined(this._x1) && $defined(this._y1) && $defined(this._x2) && $defined(this._y2)) {
this._calculateAutoControlPoints(avoidControlPointFix);
const path = `M${this._x1.toFixed(2)},${this._y1.toFixed(2)} C${(this._control1.x + this._x1).toFixed(2)},${this._control1.y + this._y1
} ${(this._control2.x + this._x2).toFixed(2)},${(this._control2.y + this._y2).toFixed(2)} ${(this._x2).toFixed(2)},${(this._y2).toFixed(2)}${this._lineStyle
? ` ${(this._control2.x + this._x2).toFixed(2)},${(this._control2.y + this._y2 + 3).toFixed(2)} ${(this._control1.x + this._x1
).toFixed(2)},${(this._control1.y + this._y1 + 5).toFixed(2)} ${this._x1.toFixed(2)},${(this._y1 + 7).toFixed(2)} Z`
: ''
const path = `M${this._x1.toFixed(2)},${this._y1.toFixed(2)} C${(
this._control1.x + this._x1
).toFixed(2)},${this._control1.y + this._y1} ${(this._control2.x + this._x2).toFixed(2)},${(
this._control2.y + this._y2
).toFixed(2)} ${this._x2.toFixed(2)},${this._y2.toFixed(2)}${
this._lineStyle
? ` ${(this._control2.x + this._x2).toFixed(2)},${(
this._control2.y +
this._y2 +
3
).toFixed(2)} ${(this._control1.x + this._x1).toFixed(2)},${(
this._control1.y +
this._y1 +
5
).toFixed(2)} ${this._x1.toFixed(2)},${(this._y1 + 7).toFixed(2)} Z`
: ''
}`;
this._native.setAttribute('d', path);
}
@ -193,10 +199,7 @@ class CurvedLinePeer extends ElementPeer {
const x2 = tarPos.x + Math.sqrt((l * l) / (1 + m * m)) * fix * -1;
const y2 = m * (x2 - tarPos.x) + tarPos.y;
return [
new Point(-srcPos.x + x1, -srcPos.y + y1),
new Point(-tarPos.x + x2, -tarPos.y + y2),
];
return [new Point(-srcPos.x + x1, -srcPos.y + y1), new Point(-tarPos.x + x2, -tarPos.y + y2)];
}
_calculateAutoControlPoints(avoidControlPointFix) {
@ -206,15 +209,15 @@ class CurvedLinePeer extends ElementPeer {
new Point(this._x2, this._y2),
);
if (
!this._customControlPoint_1
&& !($defined(avoidControlPointFix) && avoidControlPointFix === 0)
!this._customControlPoint_1 &&
!($defined(avoidControlPointFix) && avoidControlPointFix === 0)
) {
this._control1.x = defaultpoints[0].x;
this._control1.y = defaultpoints[0].y;
}
if (
!this._customControlPoint_2
&& !($defined(avoidControlPointFix) && avoidControlPointFix === 1)
!this._customControlPoint_2 &&
!($defined(avoidControlPointFix) && avoidControlPointFix === 1)
) {
this._control2.x = defaultpoints[1].x;
this._control2.y = defaultpoints[1].y;

View File

@ -39,9 +39,11 @@ export const getPosition = (elem) => {
// when a statically positioned element is identified
doc = elem.ownerDocument;
offsetParent = elem.offsetParent || doc.documentElement;
while (offsetParent
&& (offsetParent === doc.body || offsetParent === doc.documentElement)
&& getStyle(offsetParent, 'position') === 'static') {
while (
offsetParent &&
(offsetParent === doc.body || offsetParent === doc.documentElement) &&
getStyle(offsetParent, 'position') === 'static'
) {
offsetParent = offsetParent.parentNode;
}
if (offsetParent && offsetParent !== elem && offsetParent.nodeType === 1) {

View File

@ -28,16 +28,4 @@ import Text from './components/Text';
import Point from './components/Point';
import Image from './components/Image';
export {
Arrow,
CurvedLine,
Elipse,
Group,
Image,
Line,
Point,
PolyLine,
Rect,
Text,
Workspace,
};
export { Arrow, CurvedLine, Elipse, Group, Image, Line, Point, PolyLine, Rect, Text, Workspace };