Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update cli and fix linting errors #6

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -4,3 +4,6 @@ node_modules
npm-debug.log
dist
docs
/coverage
.rete-cli
.sonar
14 changes: 14 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import tseslint from 'typescript-eslint';
import configs from 'rete-cli/configs/eslint.mjs';
import gloals from 'globals'

export default tseslint.config(
...configs,
{
languageOptions: {
globals: {
...gloals.browser
}
}
}
)
3,714 changes: 2,092 additions & 1,622 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
"rete-area-plugin": "^2.0.0"
},
"devDependencies": {
"globals": "^15.9.0",
"rete": "^2.0.0",
"rete-area-plugin": "^2.0.0",
"rete-cli": "^1.0.2",
"rete-cli": "~2.0.1",
"typescript": "4.8.4"
},
"dependencies": {
Expand Down
4 changes: 3 additions & 1 deletion src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export function classicConnectionPath(points: [Position, Position], curvature: n
*/
export function loopConnectionPath(points: [Position, Position], curvature: number, size: number) {
const [{ x: x1, y: y1 }, { x: x2, y: y2 }] = points
const k = y2 > y1 ? 1 : -1
const k = y2 > y1
? 1
: -1
const scale = size + Math.abs(x1 - x2) / (size / 2)
const middleX = (x1 + x2) / 2
const middleY = y1 - k * scale
Expand Down
2 changes: 1 addition & 1 deletion src/sockets-position/base-socket-position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @listens nodetranslated
* @listens noderesized
*/
export abstract class BaseSocketPosition<Schemes extends BaseSchemes, K> implements SocketPositionWatcher<Scope<never, [K]>> {

Check warning on line 24 in src/sockets-position/base-socket-position.ts

View workflow job for this annotation

GitHub Actions / ci / ci

This line has a length of 126. Maximum allowed is 120

Check warning on line 24 in src/sockets-position/base-socket-position.ts

View workflow job for this annotation

GitHub Actions / ci / ci

This line has a length of 126. Maximum allowed is 120
sockets = new SocketsPositionsStorage()
emitter = new EventEmitter<ListenerData>()
area: BaseAreaPlugin<Schemes, ExpectArea2DExtra<Schemes>> | null = null
Expand All @@ -44,7 +44,7 @@
if (!scope.hasParent()) return
this.area = scope.parentScope<BaseAreaPlugin<Schemes, ExpectArea2DExtra<Schemes>>>(BaseAreaPlugin)

// eslint-disable-next-line max-statements, complexity
// eslint-disable-next-line max-statements
this.area.addPipe(async context => {
if (context.type === 'rendered' && context.data.type === 'socket') {
const { nodeId, key, side, element } = context.data
Expand Down
6 changes: 4 additions & 2 deletions src/sockets-position/dom-socket-position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ export class DOMSocketPosition<Schemes extends BaseSchemes, K> extends BaseSocke
if (!view?.element) return null
const position = await getElementCenter(element, view.element)

if (this.props?.offset) return this.props?.offset(position, nodeId, side, key)
if (this.props?.offset) return this.props.offset(position, nodeId, side, key)

return {
x: position.x + 12 * (side === 'input' ? -1 : 1),
x: position.x + 12 * (side === 'input'
? -1
: 1),
y: position.y
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/sockets-position/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ export class SocketsPositionsStorage {
'Probably it was not unmounted correctly'
].join(' '), data)

return found.pop()?.position || null
return found.pop()?.position ?? null
}

add(data: SocketPayload) {
const existing = this.elements.get(data.element)

this.elements.set(data.element, existing ? [
...existing.filter(n => !(n.nodeId === data.nodeId && n.key === data.key && n.side === data.side)), data
] : [data])
this.elements.set(data.element, existing
? [
...existing.filter(n => !(n.nodeId === data.nodeId && n.key === data.key && n.side === data.side)), data
]
: [data])
}

remove(element: SocketPayload['element']) {
Expand Down
24 changes: 13 additions & 11 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
/* eslint-disable max-statements */

/**
* Calculates the center coordinates of a child element relative to a parent element.
* @async
* @param child The child element whose center coordinates need to be calculated.
* @param parent The parent element relative to which the child element's center is calculated.
* @returns Position of the child element's center
* @throws Error if the child element has a null offsetParent.
*/
* Calculates the center coordinates of a child element relative to a parent element.
* @async
* @param child The child element whose center coordinates need to be calculated.
* @param parent The parent element relative to which the child element's center is calculated.
* @returns Position of the child element's center
* @throws Error if the child element has a null offsetParent.
*/
export async function getElementCenter(child: HTMLElement, parent: HTMLElement) {
while (!child.offsetParent) {
await new Promise((res) => setTimeout(res, 0))
await new Promise(res => setTimeout(res, 0))
}

let x = child.offsetLeft
let y = child.offsetTop
let currentElement = child.offsetParent as HTMLElement | null

Check warning on line 18 in src/utils.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The 'child.offsetParent as HTMLElement | null' has unsafe 'as' type assertion

Check warning on line 18 in src/utils.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The 'child.offsetParent as HTMLElement | null' has unsafe 'as' type assertion

if (!currentElement) throw new Error('child has null offsetParent')

while (currentElement !== null && currentElement !== parent) {
x += currentElement.offsetLeft + currentElement.clientLeft
y += currentElement.offsetTop + currentElement.clientTop
currentElement = currentElement.offsetParent as HTMLElement | null

Check warning on line 25 in src/utils.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The 'currentElement.offsetParent as HTMLElement | null' has unsafe 'as' type assertion

Check warning on line 25 in src/utils.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The 'currentElement.offsetParent as HTMLElement | null' has unsafe 'as' type assertion
}
const width = child.offsetWidth
const height = child.offsetHeight

return {
x: (x + width / 2),
y: (y + height / 2)
x: x + width / 2,
y: y + height / 2
}
}
export class EventEmitter<T> {
listeners = new Set<(data: T) => void>()

emit(data: T) {
this.listeners.forEach(listener => listener(data))
this.listeners.forEach(listener => {
listener(data)
})
}

listen(handler: (data: T) => void) {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "rete-cli/configs/tsconfig.json",
"compilerOptions": {
"strict": true,
"lib": [
"DOM"
]
Expand Down
Loading