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" "@typescript-eslint"
], ],
"rules": { "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": [ "operator-linebreak": [
"error", "after", { "error", "after", {
"overrides": { "overrides": {

View File

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

View File

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

View File

@ -15,7 +15,25 @@
"import/no-extraneous-dependencies": ["warn", { "import/no-extraneous-dependencies": ["warn", {
"packageDir": ["./"], "packageDir": ["./"],
"devDependencies": ["!cypress/**/*.js"] "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": { "settings": {
"import/resolver": { "import/resolver": {

View File

@ -160,13 +160,13 @@ class ElementClass {
*/ */
setStroke(width, style, color, opacity) { setStroke(width, style, color, opacity) {
if ( if (
style != null style != null &&
&& style !== undefined style !== undefined &&
&& style !== 'dash' style !== 'dash' &&
&& style !== 'dot' style !== 'dot' &&
&& style !== 'solid' style !== 'solid' &&
&& style !== 'longdash' style !== 'longdash' &&
&& style !== 'dashdot' style !== 'dashdot'
) { ) {
throw new Error(`Unsupported stroke style: '${style}'`); throw new Error(`Unsupported stroke style: '${style}'`);
} }

View File

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

View File

@ -148,18 +148,24 @@ class CurvedLinePeer extends ElementPeer {
} }
_updatePath(avoidControlPointFix) { _updatePath(avoidControlPointFix) {
if ( if ($defined(this._x1) && $defined(this._y1) && $defined(this._x2) && $defined(this._y2)) {
$defined(this._x1)
&& $defined(this._y1)
&& $defined(this._x2)
&& $defined(this._y2)
) {
this._calculateAutoControlPoints(avoidControlPointFix); 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 const path = `M${this._x1.toFixed(2)},${this._y1.toFixed(2)} C${(
} ${(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._control1.x + this._x1
? ` ${(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} ${(this._control2.x + this._x2).toFixed(2)},${(
).toFixed(2)},${(this._control1.y + this._y1 + 5).toFixed(2)} ${this._x1.toFixed(2)},${(this._y1 + 7).toFixed(2)} Z` 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); 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 x2 = tarPos.x + Math.sqrt((l * l) / (1 + m * m)) * fix * -1;
const y2 = m * (x2 - tarPos.x) + tarPos.y; const y2 = m * (x2 - tarPos.x) + tarPos.y;
return [ return [new Point(-srcPos.x + x1, -srcPos.y + y1), new Point(-tarPos.x + x2, -tarPos.y + y2)];
new Point(-srcPos.x + x1, -srcPos.y + y1),
new Point(-tarPos.x + x2, -tarPos.y + y2),
];
} }
_calculateAutoControlPoints(avoidControlPointFix) { _calculateAutoControlPoints(avoidControlPointFix) {
@ -206,15 +209,15 @@ class CurvedLinePeer extends ElementPeer {
new Point(this._x2, this._y2), new Point(this._x2, this._y2),
); );
if ( if (
!this._customControlPoint_1 !this._customControlPoint_1 &&
&& !($defined(avoidControlPointFix) && avoidControlPointFix === 0) !($defined(avoidControlPointFix) && avoidControlPointFix === 0)
) { ) {
this._control1.x = defaultpoints[0].x; this._control1.x = defaultpoints[0].x;
this._control1.y = defaultpoints[0].y; this._control1.y = defaultpoints[0].y;
} }
if ( if (
!this._customControlPoint_2 !this._customControlPoint_2 &&
&& !($defined(avoidControlPointFix) && avoidControlPointFix === 1) !($defined(avoidControlPointFix) && avoidControlPointFix === 1)
) { ) {
this._control2.x = defaultpoints[1].x; this._control2.x = defaultpoints[1].x;
this._control2.y = defaultpoints[1].y; this._control2.y = defaultpoints[1].y;

View File

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

View File

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