Skip to content

Commit

Permalink
Merge pull request #25 from retejs/add-docs
Browse files Browse the repository at this point in the history
Add docs
  • Loading branch information
Ni55aN authored Jul 14, 2023
2 parents 19eb381 + 30400a4 commit a904b97
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/update-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ name: Update docs
on:
workflow_dispatch:
push:
branches: [ "main" ]
branches: ["main"]

jobs:
pull:
uses: retejs/.github/.github/workflows/update-docs.yml@main
secrets: inherit
with:
filename: '1.rete'
package: rete
filename: "12.rete-dock-plugin"
package: rete-dock-plugin
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
.idea/
.vscode/
dist
docs
13 changes: 10 additions & 3 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion 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 @@ -26,6 +27,7 @@
"rete-area-plugin": "^2.0.0"
},
"devDependencies": {
"@types/node": "^20.4.2",
"rete": "^2.0.1",
"rete-area-plugin": "^2.0.0",
"rete-cli": "^1.0.1",
Expand Down
18 changes: 18 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { Strategy } from './strategy'

export * as DockPresets from './presets'

/**
* Dock plugin. Allows to create nodes from the dock by dragging or clicking.
* @priority 10
* @emits render
*/
export class DockPlugin<Schemes extends BaseSchemes> extends Scope<never, Area2DInherited<Schemes, never>> {
nodes = new Map<() => Schemes['Node'], { preset: Preset, element: HTMLElement }>()
clickStrategy!: Strategy
Expand All @@ -28,6 +33,11 @@ export class DockPlugin<Schemes extends BaseSchemes> extends Scope<never, Area2D
this.dropStrategy = new DropStrategy(editor, area)
}

/**
* Add node to the dock.
* @param create Function that creates node.
* @param index Index of the node in the dock, optional.
*/
add(create: () => Schemes['Node'], index?: number) {
if (!this.presets.length) throw new Error('presets not found')

Expand All @@ -52,6 +62,10 @@ export class DockPlugin<Schemes extends BaseSchemes> extends Scope<never, Area2D
}
}

/**
* Remove node from the dock.
* @param create Function that creates node. Must be the same as in `add` method.
*/
remove(create: () => Schemes['Node']) {
const item = this.nodes.get(create)

Expand All @@ -60,6 +74,10 @@ export class DockPlugin<Schemes extends BaseSchemes> extends Scope<never, Area2D
}
}

/**
* Add preset to the dock plugin.
* @param preset Preset that will manage dock items.
*/
addPreset(preset: Preset) {
this.presets.push(preset)
}
Expand Down
8 changes: 8 additions & 0 deletions src/presets/classic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ function getNodeContainer(size: number, scale: number) {
return element
}

/**
* Classic preset for the dock plugin.
* Creates container for list of nodes and containers each node.
* @param props Preset properties
* @param props.size Size of a node
* @param props.scale Scale of a node
* @param props.area Area plugin instance
*/
export function setup<T>(props: { size?: number, scale?: number, area: AreaPlugin<BaseSchemes, T> }): Preset {
const size = typeof props.size === 'undefined' ? 100 : props.size
const scale = typeof props.scale === 'undefined' ? 0.7 : props.scale
Expand Down
5 changes: 5 additions & 0 deletions src/presets/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
/**
* Presets for the dock plugin
* @module
*/

export * as classic from './classic'

0 comments on commit a904b97

Please sign in to comment.