Skip to content

Commit

Permalink
Merge pull request #71 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 39d1f3d + fad39dc commit dbb584b
Show file tree
Hide file tree
Showing 14 changed files with 2,379 additions and 1,802 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 @@ -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/eslint.config.mjs';
import gloals from 'globals'

export default tseslint.config(
...configs,
{
languageOptions: {
globals: {
...gloals.browser
}
}
}
)
4,028 changes: 2,286 additions & 1,742 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.1",
"rete-area-plugin": "^2.0.0",
"rete-cli": "^1.0.2",
"rete-cli": "~2.0.1",
"rollup-plugin-sass": "^0.6.1",
"ts-node": "^8.0.2",
"typescript": "4.8.4"
Expand Down
12 changes: 6 additions & 6 deletions src/flow/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { BaseSchemes, NodeEditor, Scope } from 'rete'
import { Connection, SocketData } from '../types'

export type Context<Schemes extends BaseSchemes, K extends any[]> = {

Check warning on line 5 in src/flow/base.ts

View workflow job for this annotation

GitHub Actions / release / publish

Unexpected any. Specify a different type

Check warning on line 5 in src/flow/base.ts

View workflow job for this annotation

GitHub Actions / release / publish

Unexpected any. Specify a different type
editor: NodeEditor<Schemes>
scope: Scope<Connection, K>
socketsCache: Map<Element, SocketData>
editor: NodeEditor<Schemes>
scope: Scope<Connection, K>
socketsCache: Map<Element, SocketData>
}
export type EventType = 'up' | 'down'
export type PickParams = { socket: SocketData, event: EventType }

export abstract class Flow<Schemes extends BaseSchemes, K extends any[]> {

Check warning on line 13 in src/flow/base.ts

View workflow job for this annotation

GitHub Actions / release / publish

Unexpected any. Specify a different type

Check warning on line 13 in src/flow/base.ts

View workflow job for this annotation

GitHub Actions / release / publish

Unexpected any. Specify a different type
public abstract pick(params: PickParams, context: Context<Schemes, K>): Promise<void>
public abstract getPickedSocket(): SocketData | undefined
public abstract drop(context: Context<Schemes, K>): void
public abstract pick(params: PickParams, context: Context<Schemes, K>): Promise<void>
public abstract getPickedSocket(): SocketData | undefined
public abstract drop(context: Context<Schemes, K>): void
}
5 changes: 3 additions & 2 deletions src/flow/builtin/bidirect.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/require-await */
import { ClassicScheme, SocketData } from '../../types'
import { Context, Flow, PickParams } from '../base'
import { makeConnection as defaultMakeConnection, State, StateContext } from '../utils'
Expand Down Expand Up @@ -27,7 +28,7 @@ class Picked<Schemes extends ClassicScheme, K extends any[]> extends State<Schem

drop(context: Context<ClassicScheme, K>, socket: SocketData | null = null, created = false): void {
if (this.initial) {

Check warning on line 30 in src/flow/builtin/bidirect.ts

View workflow job for this annotation

GitHub Actions / release / publish

Unnecessary conditional, value is always truthy

Check warning on line 30 in src/flow/builtin/bidirect.ts

View workflow job for this annotation

GitHub Actions / release / publish

Unnecessary conditional, value is always truthy
context.scope.emit({ type: 'connectiondrop', data: { initial: this.initial, socket, created } })
void context.scope.emit({ type: 'connectiondrop', data: { initial: this.initial, socket, created } })
}
this.context.switchTo(new Idle<Schemes, K>(this.params))
}
Expand All @@ -50,7 +51,7 @@ class Idle<Schemes extends ClassicScheme, K extends any[]> extends State<Schemes

drop(context: Context<Schemes, K>, socket: SocketData | null = null, created = false): void {
if (this.initial) {
context.scope.emit({ type: 'connectiondrop', data: { initial: this.initial, socket, created } })
void context.scope.emit({ type: 'connectiondrop', data: { initial: this.initial, socket, created } })
}
delete this.initial
}
Expand Down
25 changes: 17 additions & 8 deletions src/flow/builtin/classic/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/require-await */

import { ClassicScheme, SocketData } from '../../../types'
import { Context, Flow, PickParams } from '../../base'
Expand Down Expand Up @@ -26,13 +27,15 @@ class Picked<Schemes extends ClassicScheme, K extends any[]> extends State<Schem
syncConnections([this.initial, socket], context.editor).commit()
const created = this.params.makeConnection(this.initial, socket, context)

this.drop(context, created ? socket : null, created)
this.drop(context, created
? socket
: null, created)
}
}

drop(context: Context<Schemes, K>, socket: SocketData | null = null, created = false): void {
if (this.initial) {
context.scope.emit({ type: 'connectiondrop', data: { initial: this.initial, socket, created } })
void context.scope.emit({ type: 'connectiondrop', data: { initial: this.initial, socket, created } })
}
this.context.switchTo(new Idle(this.params))
}
Expand All @@ -56,9 +59,9 @@ class PickedExisting<Schemes extends ClassicScheme, K extends any[]> extends Sta
}

async init(context: Context<Schemes, K>) {
context.scope.emit({ type: 'connectionpick', data: { socket: this.outputSocket } }).then(response => {
void context.scope.emit({ type: 'connectionpick', data: { socket: this.outputSocket } }).then(response => {
if (response) {
context.editor.removeConnection(this.connection.id)
void context.editor.removeConnection(this.connection.id)
this.initial = this.outputSocket
} else {
this.drop(context)
Expand All @@ -71,22 +74,28 @@ class PickedExisting<Schemes extends ClassicScheme, K extends any[]> extends Sta
if (this.params.canMakeConnection(this.initial, socket)) {
syncConnections([this.initial, socket], context.editor).commit()
const created = this.params.makeConnection(this.initial, socket, context)
const droppedSocket = created
? socket
: null

this.drop(context, created ? socket : null, created)
this.drop(context, droppedSocket, created)
}
} else if (event === 'down') {
if (this.initial) {
syncConnections([this.initial, socket], context.editor).commit()
const created = this.params.makeConnection(this.initial, socket, context)
const droppedSocket = created
? null
: socket

this.drop(context, created ? socket : null, created)
this.drop(context, droppedSocket, created)
}
}
}

drop(context: Context<Schemes, K>, socket: SocketData | null = null, created = false): void {
if (this.initial) {
context.scope.emit({ type: 'connectiondrop', data: { initial: this.initial, socket, created } })
void context.scope.emit({ type: 'connectiondrop', data: { initial: this.initial, socket, created } })
}
this.context.switchTo(new Idle<Schemes, K>(this.params))
}
Expand Down Expand Up @@ -122,7 +131,7 @@ class Idle<Schemes extends ClassicScheme, K extends any[]> extends State<Schemes

drop(context: Context<Schemes, K>, socket: SocketData | null = null, created = false): void {
if (this.initial) {
context.scope.emit({ type: 'connectiondrop', data: { initial: this.initial, socket, created } })
void context.scope.emit({ type: 'connectiondrop', data: { initial: this.initial, socket, created } })
}
delete this.initial
}
Expand Down
6 changes: 4 additions & 2 deletions src/flow/builtin/classic/sync-connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ function findPort<Schemes extends ClassicScheme>(socket: SocketData, editor: Nod

if (!node) throw new Error('cannot find node')

const list = socket.side === 'input' ? node.inputs : node.outputs
const list = socket.side === 'input'
? node.inputs
: node.outputs

return list[socket.key]
}
Expand Down Expand Up @@ -41,7 +43,7 @@ export function syncConnections<Schemes extends ClassicScheme>(sockets: SocketDa
commit() {
const uniqueIds = Array.from(new Set(connections.map(({ id }) => id)))

uniqueIds.forEach(id => editor.removeConnection(id))
uniqueIds.forEach(id => void editor.removeConnection(id))
}
}
}
6 changes: 4 additions & 2 deletions src/flow/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export function getSourceTarget(initial: SocketData, socket: SocketData) {
const backward = initial.side === 'input' && socket.side === 'output'
const [source, target] = forward
? [initial, socket]
: (backward ? [socket, initial] : [])
: backward
? [socket, initial]
: []

if (source && target) return [source, target]
}
Expand All @@ -38,7 +40,7 @@ export function makeConnection<Schemes extends ClassicScheme, K extends any[]>(i
const [source, target] = getSourceTarget(initial, socket) || [null, null]

if (source && target) {
context.editor.addConnection({
void context.editor.addConnection({
id: getUID(),
source: source.nodeId,
sourceOutput: source.key,
Expand Down
9 changes: 4 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type Requires =
| { type: 'pointermove', data: { position: Position, event: PointerEvent } }
| { type: 'pointerup', data: { position: Position, event: PointerEvent } }
| RenderSignal<'socket', {
nodeId: string,
side: Side,
nodeId: string
side: Side
key: string
}>
| { type: 'unmount', data: { element: HTMLElement } }
Expand Down Expand Up @@ -115,17 +115,16 @@ export class ConnectionPlugin<Schemes extends ClassicScheme, K = Requires> exten
this.editor = this.areaPlugin.parentScope<NodeEditor<Schemes>>(NodeEditor)

const pointerdownSocket = (e: PointerEvent) => {
this.pick(e, 'down')
void this.pick(e, 'down')
}

// eslint-disable-next-line max-statements
this.addPipe(context => {
if (!context || typeof context !== 'object' || !('type' in context)) return context

if (context.type === 'pointermove') {
this.update()
} else if (context.type === 'pointerup') {
this.pick(context.data.event, 'up')
void this.pick(context.data.event, 'up')
} else if (context.type === 'render') {
if (context.data.type === 'socket') {
const { element } = context.data
Expand Down
50 changes: 30 additions & 20 deletions src/pseudoconnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,53 @@ export function createPseudoconnection<Schemes extends ClassicScheme, K>(extra?:
return Boolean(id)
},
mount,
// eslint-disable-next-line complexity
render(areaPlugin: BaseAreaPlugin<Schemes, BaseArea<Schemes> | K>, { x, y }: Position, data: SocketData) {
const isOutput = data.side === 'output'
const pointer = { x: x + (isOutput ? -3 : 3), y } // fix hover of underlying elements
const pointer = {
x: x + (isOutput
? -3
: 3),
y
} // fix hover of underlying elements

if (!id) throw new Error('pseudo connection id wasn\'t generated')

const payload = isOutput ? {
id,
source: data.nodeId,
sourceOutput: data.key,
target: '',
targetInput: '',
...(extra || {})
} : {
id,
target: data.nodeId,
targetInput: data.key,
source: '',
sourceOutput: '',
...(extra || {})
}
const payload = isOutput
? {
id,
source: data.nodeId,
sourceOutput: data.key,
target: '',
targetInput: '',
...extra ?? {}
}
: {
id,
target: data.nodeId,
targetInput: data.key,
source: '',
sourceOutput: '',
...extra ?? {}
}

if (!element) {
const view = areaPlugin.addConnectionView(payload)

element = view.element
}

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!element) return

areaPlugin.emit({
type: 'render', data: {
void areaPlugin.emit({
type: 'render',
data: {
element,
type: 'connection',
payload,
...(isOutput ? { end: pointer } : { start: pointer })
...isOutput
? { end: pointer }
: { start: pointer }
}
})
},
Expand Down
10 changes: 5 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { Flow } from './flow'
export type Position = { x: number, y: number }
export type Side = 'input' | 'output'
export type SocketData = {
element: HTMLElement,
type: 'socket',
nodeId: string,
side: Side,
key: string,
element: HTMLElement
type: 'socket'
nodeId: string
side: Side
key: string
// wrongField: true
}

Expand Down
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 dbb584b

Please sign in to comment.