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 #71

Merged
merged 3 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/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 @@ -2,16 +2,16 @@

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 / ci / ci

Unexpected any. Specify a different type

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

View workflow job for this annotation

GitHub Actions / ci / ci

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 / ci / ci

Unexpected any. Specify a different type

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

View workflow job for this annotation

GitHub Actions / ci / ci

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 All @@ -9,10 +10,10 @@
/** If true, user can pick a pseudo-connection by clicking on socket, not only by pointerdown */
pickByClick: boolean
/** Custom function to make connection */
makeConnection: <K extends any[]>(from: SocketData, to: SocketData, context: Context<Schemes, K>) => boolean | undefined

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

View workflow job for this annotation

GitHub Actions / ci / ci

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

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

View workflow job for this annotation

GitHub Actions / ci / ci

Unexpected any. Specify a different type

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

View workflow job for this annotation

GitHub Actions / ci / ci

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

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

View workflow job for this annotation

GitHub Actions / ci / ci

Unexpected any. Specify a different type
}

class Picked<Schemes extends ClassicScheme, K extends any[]> extends State<Schemes, K> {

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

View workflow job for this annotation

GitHub Actions / ci / ci

Unexpected any. Specify a different type

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

View workflow job for this annotation

GitHub Actions / ci / ci

Unexpected any. Specify a different type
constructor(public initial: SocketData, private params: BidirectParams<Schemes>) {
super()
}
Expand All @@ -26,14 +27,14 @@
}

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 / ci / ci

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 / ci / ci

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))
}
}

class Idle<Schemes extends ClassicScheme, K extends any[]> extends State<Schemes, K> {

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

View workflow job for this annotation

GitHub Actions / ci / ci

Unexpected any. Specify a different type

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

View workflow job for this annotation

GitHub Actions / ci / ci

Unexpected any. Specify a different type
constructor(private params: BidirectParams<Schemes>) {
super()
}
Expand All @@ -50,7 +51,7 @@

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 All @@ -60,12 +61,12 @@
* Bidirect flow. User can pick a socket and connect it by releasing mouse button.
* More simple than classic flow, but less functional (can't remove connection by clicking on input socket).
*/
export class BidirectFlow<Schemes extends ClassicScheme, K extends any[]> implements StateContext<Schemes, K>, Flow<Schemes, K> {

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

View workflow job for this annotation

GitHub Actions / ci / ci

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

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

View workflow job for this annotation

GitHub Actions / ci / ci

Unexpected any. Specify a different type

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

View workflow job for this annotation

GitHub Actions / ci / ci

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

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

View workflow job for this annotation

GitHub Actions / ci / ci

Unexpected any. Specify a different type
currentState!: State<Schemes, K>

constructor(params?: Partial<BidirectParams<Schemes>>) {
const pickByClick = Boolean(params?.pickByClick)
const makeConnection = params?.makeConnection || defaultMakeConnection

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

View workflow job for this annotation

GitHub Actions / ci / ci

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator

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

View workflow job for this annotation

GitHub Actions / ci / ci

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator

this.switchTo(new Idle({ pickByClick, makeConnection }))
}
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"]
}
Loading