Skip to content

Commit

Permalink
Merge pull request #23 from retejs/new-linter
Browse files Browse the repository at this point in the history
fix: update cli and fix linting errors
  • Loading branch information
Ni55aN authored Aug 30, 2024
2 parents f2c510d + 2bebbc2 commit 1b0ce23
Show file tree
Hide file tree
Showing 10 changed files with 2,099 additions and 1,672 deletions.
6 changes: 0 additions & 6 deletions .eslintrc

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ npm-debug.log
dist
yarn.lock
docs
/coverage
.rete-cli
.sonar
6 changes: 6 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import configs from 'rete-cli/configs/eslint.mjs';
import tseslint from 'typescript-eslint'

export default tseslint.config(
...configs,
)
3,691 changes: 2,050 additions & 1,641 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@
"d3-shape": "^3.0.0",
"rete": "^2.0.1",
"rete-area-plugin": "^2.0.0",
"rete-cli": "^1.0.2",
"rete-render-utils": "^2.0.0",
"typescript": "4.8.4"
"rete-cli": "~2.0.1",
"rete-render-utils": "^2.0.0"
},
"dependencies": {
"@babel/runtime": "^7.21.0"
Expand Down
30 changes: 19 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,32 @@ export class ConnectionPathPlugin<Schemes extends BaseSchemes, K> extends Scope<

if (context.type === 'connectionpath') {
const { points, payload } = context.data
const curve = this.props?.curve ? this.props.curve(payload) : curveBundle.beta(0.9)
const transformer = this.props?.transformer ? this.props.transformer(payload) : Transformers.classic({})
const curve = this.props?.curve
? this.props.curve(payload)
: curveBundle.beta(0.9)
const transformer = this.props?.transformer
? this.props.transformer(payload)
: Transformers.classic({})
const factory = new PathFactory(curve)
const transformedPoints = transformer(points)
const path = factory.getData(transformedPoints)

const p = document.createElementNS('http://www.w3.org/2000/svg', 'path')

p.setAttribute('d', path || classicConnectionPath(transformedPoints as [Position, Position], 0.3))
p.setAttribute('d', path ?? classicConnectionPath(transformedPoints as [Position, Position], 0.3))

Check warning on line 66 in src/index.ts

View workflow job for this annotation

GitHub Actions / release / publish

The 'transformedPoints as [Position, Position]' has unsafe 'as' type assertion

Check warning on line 66 in src/index.ts

View workflow job for this annotation

GitHub Actions / release / publish

The 'transformedPoints as [Position, Position]' has unsafe 'as' type assertion

this.transforms.set(payload.id, getTransformAlong(p, -15))
this.updateArrow(payload)

return path ? {
...context,
data: {
...context.data,
path
return path
? {
...context,
data: {
...context.data,
path
}
}
} : context
: context
}
if (context.type === 'connectionremoved') {
const { id } = context.data
Expand Down Expand Up @@ -109,7 +115,9 @@ export class ConnectionPathPlugin<Schemes extends BaseSchemes, K> extends Scope<
const data = this.props.arrow(c)

if (!data) return null
const { color = 'steelblue', marker = 'M-5,-10 L-5,10 L20,0 z' } = data === true ? {} : data
const { color = 'steelblue', marker = 'M-5,-10 L-5,10 L20,0 z' } = data === true
? {}
: data

return { color, marker }
}
Expand All @@ -125,6 +133,6 @@ export class ConnectionPathPlugin<Schemes extends BaseSchemes, K> extends Scope<
data.marker.setAttribute('fill', color)
data.marker.setAttribute('d', marker)

data.marker.setAttribute('transform', this.transforms.get(c.id) || '')
data.marker.setAttribute('transform', this.transforms.get(c.id) ?? '')
}
}
2 changes: 1 addition & 1 deletion src/path-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export class PathFactory {
.y(d => d[1])
.curve(this.curve)

return getPath(points.map(p => ([p.x, p.y])))
return getPath(points.map(p => [p.x, p.y]))
}
}
20 changes: 14 additions & 6 deletions src/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Position, Transformer } from './types'
* @throws Error if number of points is not equal to 2
*/
export const linear = (): Transformer => {
return (points) => {
return points => {
if (points.length !== 2) throw new Error('number of points should be equal to 2')
const [start, end] = points

Expand All @@ -32,17 +32,25 @@ export const classic = (options: { vertical?: boolean, curvature?: number }): Tr
function add(a: Position, b: Position) {
return { x: a.x + b.x, y: a.y + b.y }
}
return (points) => {
return points => {
if (points.length !== 2) throw new Error('number of points should be equal to 2')

const [start, end] = points
const xDistance = Math.abs(start.x - end.x)
const yDistance = Math.abs(start.y - end.y)
const crossDistance = vertical ? xDistance : yDistance
const alongDistance = vertical ? yDistance : xDistance
const crossDistance = vertical
? xDistance
: yDistance
const alongDistance = vertical
? yDistance
: xDistance
const offset = Math.max(crossDistance / 2, alongDistance) * curvature
const startOffset = vertical ? { x: 0, y: offset } : { y: 0, x: offset }
const endOffset = vertical ? { x: 0, y: -offset } : { y: 0, x: -offset }
const startOffset = vertical
? { x: 0, y: offset }
: { y: 0, x: offset }
const endOffset = vertical
? { x: 0, y: -offset }
: { y: 0, x: -offset }

return [start, add(start, startOffset), add(end, endOffset), end]
}
Expand Down
4 changes: 3 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export function getTransformAlong(path: SVGPathElement, offset: number, delta =
const length = path.getTotalLength() * delta
const p1 = path.getPointAtLength(length + offset)
const p2 = path.getPointAtLength(length)
const angle = 180 + (needRotate ? getAngle(p1, p2) : 0)
const angle = 180 + (needRotate
? getAngle(p1, p2)
: 0)

return `translate(${p1.x}, ${p1.y}) rotate(${angle})`
}
4 changes: 1 addition & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"compilerOptions": {
"strict": true
},
"extends": "rete-cli/configs/tsconfig.json",
"include": ["src"]
}

0 comments on commit 1b0ce23

Please sign in to comment.