Skip to content

Commit

Permalink
api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ni55aN committed Jul 11, 2023
1 parent c2eb6b0 commit a669679
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
.vscode/
npm-debug.log
dist
docs
4 changes: 0 additions & 4 deletions .npmignore

This file was deleted.

112 changes: 106 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "",
"scripts": {
"build": "rete build -c rete.config.ts",
"lint": "rete lint"
"lint": "rete lint",
"doc": "rete doc"
},
"author": "Vitaliy Stoliarov",
"license": "MIT",
Expand All @@ -28,7 +29,7 @@
"devDependencies": {
"rete": "^2.0.0-beta.9",
"rete-area-plugin": "^2.0.0-beta.12",
"rete-cli": "^1.0.0-beta.29",
"rete-cli": "^1.0.0-beta.31",
"rollup-plugin-sass": "^0.6.1",
"ts-node": "^8.0.2",
"typescript": "4.8.4"
Expand Down
9 changes: 9 additions & 0 deletions src/flow/builtin/bidirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ import { ClassicScheme, SocketData } from '../../types'
import { Context, Flow, PickParams } from '../base'
import { makeConnection as defaultMakeConnection, State, StateContext } from '../utils'

/**
* Bidirect flow params
*/
export type BidirectParams<Schemes extends ClassicScheme> = {
/** 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
}

Expand Down Expand Up @@ -51,6 +56,10 @@ class Idle<Schemes extends ClassicScheme, K extends any[]> extends State<Schemes
}
}

/**
* 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> {
currentState!: State<Schemes, K>

Expand Down
9 changes: 9 additions & 0 deletions src/flow/builtin/classic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ import {
} from '../../utils'
import { syncConnections } from './sync-connections'

/**
* Classic flow params
*/
export type ClassicParams<Schemes extends ClassicScheme> = {
/** Custom function to check if connection can be made */
canMakeConnection: (from: SocketData, to: SocketData) => boolean | undefined
/** Custom function to make connection */
makeConnection: <K extends any[]>(from: SocketData, to: SocketData, context: Context<Schemes, K>) => boolean | undefined
}

Expand Down Expand Up @@ -123,6 +128,10 @@ class Idle<Schemes extends ClassicScheme, K extends any[]> extends State<Schemes
}
}

/**
* Classic flow. User can pick/click a socket and connect it by releasing/clicking on another socket.
* If connection already exists and user clicks on input socket, connection will be removed.
*/
export class ClassicFlow<Schemes extends ClassicScheme, K extends any[]> implements StateContext<Schemes, K>, Flow<Schemes, K> {
currentState!: State<Schemes, K>

Expand Down
18 changes: 18 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ type Requires =
}>
| { type: 'unmount', data: { element: HTMLElement } }

/**
* Connection plugin. Responsible for user interaction with connections (creation, deletion)
* @priority 9
* @emits connectionpick
* @emits connectiondrop
* @listens pointermove
* @listens pointerup
* @listens render
* @listens unmount
*/
export class ConnectionPlugin<Schemes extends ClassicScheme, K = Requires> extends Scope<Connection, [Requires | K]> {
presets: Preset<Schemes>[] = []
private areaPlugin!: BaseAreaPlugin<Schemes, BaseArea<Schemes>>
Expand All @@ -34,6 +44,10 @@ export class ConnectionPlugin<Schemes extends ClassicScheme, K = Requires> exten
super('connection')
}

/**
* Add preset to the plugin
* @param preset Preset to add
*/
public addPreset(preset: Preset<Schemes>) {
this.presets.push(preset)
}
Expand All @@ -56,6 +70,10 @@ export class ConnectionPlugin<Schemes extends ClassicScheme, K = Requires> exten
}
}

/**
* Drop pseudo-connection if exists
* @emits connectiondrop
*/
drop() {
const flowContext = { editor: this.editor, scope: this, socketsCache: this.socketsCache }

Expand Down
3 changes: 3 additions & 0 deletions src/presets/classic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ClassicFlow } from '../flow'

/**
* Classic preset. Uses `ClassicFlow` for managing connections by user
*/
export function setup() {
return () => new ClassicFlow()
}
4 changes: 4 additions & 0 deletions src/presets/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
/**
* Built-in presets
* @module
*/
export * as classic from './classic'
5 changes: 5 additions & 0 deletions src/pseudoconnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { BaseArea, BaseAreaPlugin } from 'rete-area-plugin'

import { ClassicScheme, Position, SocketData } from './types'

/**
* Create pseudoconnection. Used to trigger rendering of connection that is being created by user.
* Has additional `isPseudo` property in payload.
* @param extra Extra payload to add to connection
*/
export function createPseudoconnection<Schemes extends ClassicScheme, K>(extra?: Partial<Schemes['Connection']>) {
let element: HTMLElement | null = null
let id: string | null = null
Expand Down
8 changes: 6 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ export type ClassicScheme = GetSchemes<
Classic.Connection<Classic.Node, Classic.Node> & ConnectionExtra
>

/**
* Signal types produced by ConnectionPlugin instance
* @priority 10
*/
export type Connection =
| { type: 'connectionpick', data: { socket: SocketData } }
| { type: 'connectiondrop', data: { initial: SocketData, socket: SocketData | null, created: boolean } }
| { type: 'connectionpick', data: { socket: SocketData } }
| { type: 'connectiondrop', data: { initial: SocketData, socket: SocketData | null, created: boolean } }

export type Preset<Schemes extends ClassicScheme> = (data: SocketData) => Flow<Schemes, any[]> | undefined

0 comments on commit a669679

Please sign in to comment.