diff --git a/.gitignore b/.gitignore index 16c50a3..16d4bcf 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules .vscode/ npm-debug.log dist +docs diff --git a/.npmignore b/.npmignore deleted file mode 100644 index c6dd6e9..0000000 --- a/.npmignore +++ /dev/null @@ -1,4 +0,0 @@ -node_modules -.idea/ -.vscode/ -src \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index feba0d2..96cf2a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rete-connection-plugin", - "version": "2.0.0-beta.15", + "version": "2.0.0-beta.18", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "rete-connection-plugin", - "version": "2.0.0-beta.15", + "version": "2.0.0-beta.18", "license": "MIT", "dependencies": { "@babel/runtime": "^7.21.0" @@ -14,7 +14,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" @@ -3243,6 +3243,12 @@ "node": ">=8" } }, + "node_modules/ansi-sequence-parser": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/ansi-sequence-parser/-/ansi-sequence-parser-1.1.0.tgz", + "integrity": "sha512-lEm8mt52to2fT8GhciPCGeCXACSz2UwIN4X2e2LJSnZ5uAbn2/dsYdOmUXq0AtWS5cpAupysIneExOgH0Vd2TQ==", + "dev": true + }, "node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -6092,6 +6098,12 @@ "node": ">=6" } }, + "node_modules/jsonc-parser": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.2.0.tgz", + "integrity": "sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==", + "dev": true + }, "node_modules/jsonfile": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", @@ -6204,6 +6216,12 @@ "yallist": "^3.0.2" } }, + "node_modules/lunr": { + "version": "2.3.9", + "resolved": "https://registry.npmjs.org/lunr/-/lunr-2.3.9.tgz", + "integrity": "sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow==", + "dev": true + }, "node_modules/make-dir": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz", @@ -6289,6 +6307,18 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/marked": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/marked/-/marked-4.3.0.tgz", + "integrity": "sha512-PRsaiG84bK+AMvxziE/lCFss8juXjNaWzVbN5tXAm4XjeaS9NAHhop+PjQxz2A9h8Q4M/xGmzP8vqNwy6JeK0A==", + "dev": true, + "bin": { + "marked": "bin/marked.js" + }, + "engines": { + "node": ">= 12" + } + }, "node_modules/meow": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/meow/-/meow-9.0.0.tgz", @@ -7669,9 +7699,9 @@ } }, "node_modules/rete-cli": { - "version": "1.0.0-beta.29", - "resolved": "https://registry.npmjs.org/rete-cli/-/rete-cli-1.0.0-beta.29.tgz", - "integrity": "sha512-5ZusghjvbnMDwNtju+EvLtmV5yQuGw0pGHgk7xQRIb/v91UlmKgpFNxHPjsow9cE7CO62pbznnwWn9m+i8vI7A==", + "version": "1.0.0-beta.31", + "resolved": "https://registry.npmjs.org/rete-cli/-/rete-cli-1.0.0-beta.31.tgz", + "integrity": "sha512-Y7Uzfx1fnJW16gTy/CP3IstPe9aLZPlEhjiSLnOnZiVsyYmGPr+KinqKghFkKl2RshajevMY1sXJQaC3Peh2zA==", "dev": true, "dependencies": { "@babel/plugin-transform-runtime": "^7.21.4", @@ -7697,6 +7727,7 @@ "rollup-plugin-terser": "7.0.2", "ts-jest": "29.0.3", "tslib": "2.4.0", + "typedoc": "^0.24.8", "typescript": "4.8.4" }, "bin": { @@ -8031,6 +8062,18 @@ "node": ">=8" } }, + "node_modules/shiki": { + "version": "0.14.3", + "resolved": "https://registry.npmjs.org/shiki/-/shiki-0.14.3.tgz", + "integrity": "sha512-U3S/a+b0KS+UkTyMjoNojvTgrBHjgp7L6ovhFVZsXmBGnVdQ4K4U9oK0z63w538S91ATngv1vXigHCSWOwnr+g==", + "dev": true, + "dependencies": { + "ansi-sequence-parser": "^1.1.0", + "jsonc-parser": "^3.2.0", + "vscode-oniguruma": "^1.7.0", + "vscode-textmate": "^8.0.0" + } + }, "node_modules/signal-exit": { "version": "3.0.7", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", @@ -8621,6 +8664,51 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/typedoc": { + "version": "0.24.8", + "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.24.8.tgz", + "integrity": "sha512-ahJ6Cpcvxwaxfu4KtjA8qZNqS43wYt6JL27wYiIgl1vd38WW/KWX11YuAeZhuz9v+ttrutSsgK+XO1CjL1kA3w==", + "dev": true, + "dependencies": { + "lunr": "^2.3.9", + "marked": "^4.3.0", + "minimatch": "^9.0.0", + "shiki": "^0.14.1" + }, + "bin": { + "typedoc": "bin/typedoc" + }, + "engines": { + "node": ">= 14.14" + }, + "peerDependencies": { + "typescript": "4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x" + } + }, + "node_modules/typedoc/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/typedoc/node_modules/minimatch": { + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", + "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/typescript": { "version": "4.8.4", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz", @@ -8784,6 +8872,18 @@ "spdx-expression-parse": "^3.0.0" } }, + "node_modules/vscode-oniguruma": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/vscode-oniguruma/-/vscode-oniguruma-1.7.0.tgz", + "integrity": "sha512-L9WMGRfrjOhgHSdOYgCt/yRMsXzLDJSL7BPrOZt73gU0iWO4mpqzqQzOz5srxqTvMBaR0XZTSrVWo4j55Rc6cA==", + "dev": true + }, + "node_modules/vscode-textmate": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/vscode-textmate/-/vscode-textmate-8.0.0.tgz", + "integrity": "sha512-AFbieoL7a5LMqcnOF04ji+rpXadgOXnZsxQr//r83kLPr7biP7am3g9zbaZIaBGwBRWeSvoMD4mgPdX3e4NWBg==", + "dev": true + }, "node_modules/walker": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/walker/-/walker-1.0.8.tgz", diff --git a/package.json b/package.json index 45f5adf..e0f0bca 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" diff --git a/src/flow/builtin/bidirect.ts b/src/flow/builtin/bidirect.ts index 4bf96be..cfec6ca 100644 --- a/src/flow/builtin/bidirect.ts +++ b/src/flow/builtin/bidirect.ts @@ -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 = { + /** If true, user can pick a pseudo-connection by clicking on socket, not only by pointerdown */ pickByClick: boolean + /** Custom function to make connection */ makeConnection: (from: SocketData, to: SocketData, context: Context) => boolean | undefined } @@ -51,6 +56,10 @@ class Idle extends State implements StateContext, Flow { currentState!: State diff --git a/src/flow/builtin/classic/index.ts b/src/flow/builtin/classic/index.ts index 6dd39fe..f2645e1 100644 --- a/src/flow/builtin/classic/index.ts +++ b/src/flow/builtin/classic/index.ts @@ -6,8 +6,13 @@ import { } from '../../utils' import { syncConnections } from './sync-connections' +/** + * Classic flow params + */ export type ClassicParams = { + /** Custom function to check if connection can be made */ canMakeConnection: (from: SocketData, to: SocketData) => boolean | undefined + /** Custom function to make connection */ makeConnection: (from: SocketData, to: SocketData, context: Context) => boolean | undefined } @@ -123,6 +128,10 @@ class Idle extends State implements StateContext, Flow { currentState!: State diff --git a/src/index.ts b/src/index.ts index 1aadf2b..b2b0e7e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 extends Scope { presets: Preset[] = [] private areaPlugin!: BaseAreaPlugin> @@ -34,6 +44,10 @@ export class ConnectionPlugin exten super('connection') } + /** + * Add preset to the plugin + * @param preset Preset to add + */ public addPreset(preset: Preset) { this.presets.push(preset) } @@ -56,6 +70,10 @@ export class ConnectionPlugin exten } } + /** + * Drop pseudo-connection if exists + * @emits connectiondrop + */ drop() { const flowContext = { editor: this.editor, scope: this, socketsCache: this.socketsCache } diff --git a/src/presets/classic.ts b/src/presets/classic.ts index 5c3b19d..0d2d384 100644 --- a/src/presets/classic.ts +++ b/src/presets/classic.ts @@ -1,5 +1,8 @@ import { ClassicFlow } from '../flow' +/** + * Classic preset. Uses `ClassicFlow` for managing connections by user + */ export function setup() { return () => new ClassicFlow() } diff --git a/src/presets/index.ts b/src/presets/index.ts index 83198dc..19ef66e 100644 --- a/src/presets/index.ts +++ b/src/presets/index.ts @@ -1 +1,5 @@ +/** + * Built-in presets + * @module + */ export * as classic from './classic' diff --git a/src/pseudoconnection.ts b/src/pseudoconnection.ts index 95d7164..fc3a19e 100644 --- a/src/pseudoconnection.ts +++ b/src/pseudoconnection.ts @@ -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(extra?: Partial) { let element: HTMLElement | null = null let id: string | null = null diff --git a/src/types.ts b/src/types.ts index ddbb7ad..a49a549 100644 --- a/src/types.ts +++ b/src/types.ts @@ -22,8 +22,12 @@ export type ClassicScheme = GetSchemes< Classic.Connection & 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 = (data: SocketData) => Flow | undefined