Skip to content

Commit

Permalink
Merge pull request #74 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 361e114 + 31883e0 commit 5dcf64e
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 14 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: "5.rete-context-menu-plugin"
package: rete-context-menu-plugin
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
36 changes: 28 additions & 8 deletions package-lock.json

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

6 changes: 4 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,8 @@
"devDependencies": {
"rete": "^2.0.1",
"rete-area-plugin": "^2.0.0",
"rete-cli": "^1.0.1"
"rete-cli": "^1.0.1",
"typescript": "5.0"
},
"dependencies": {
"@babel/runtime": "^7.21.0"
Expand Down
25 changes: 24 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@ import { Item, Items, Position } from './types'

export * as Presets from './presets'

type Props<Schemes extends BaseSchemes> = {
/**
* Context menu plugin props
* @priority 8
*/
export type Props<Schemes extends BaseSchemes> = {
/** delay before hiding context menu */
delay?: number
/** menu items, can be produced by preset */
items: Items<Schemes>
}
export type RenderMeta = { filled?: boolean }

/**
* Signal types produced by ContextMenuPlugin instance
* @priority 10
*/
export type ContextMenuExtra =
| RenderSignal<'contextmenu', {
items: Item[]
Expand All @@ -23,7 +33,20 @@ type Requires<Schemes extends BaseSchemes> =
| { type: 'unmount', data: { element: HTMLElement } }
| { type: 'pointerdown', data: { position: Position, event: PointerEvent } }

/**
* Plugin for context menu.
* Responsible for initialing rendering of context menu with predefined items.
* @priority 9
* @emits render
* @emits unmount
* @listens unmount
* @listens contextmenu
* @listens pointerdown
*/
export class ContextMenuPlugin<Schemes extends BaseSchemes> extends Scope<never, [Requires<Schemes> | ContextMenuExtra]> {

Check warning on line 46 in src/index.ts

View workflow job for this annotation

GitHub Actions / release / publish

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

Check warning on line 46 in src/index.ts

View workflow job for this annotation

GitHub Actions / release / publish

This line has a length of 122. Maximum allowed is 120
/**
* @param props Properties
*/
constructor(private props: Props<Schemes>) {
super('context-menu')
}
Expand Down
10 changes: 10 additions & 0 deletions src/presets/classic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ import { Item, Items } from '../../types'
import { createItem } from './factory'
import { BSchemes, ItemDefinition } from './types'

/**
* Classic context menu preset.
* Configures nodes/actions items for root and Delete/Clone items for nodes
* @param nodes List of items
* @example Presets.classic.setup([
["Math", [
["Number", () => new NumberNode()],
]]
])
*/
export function setup<Schemes extends BSchemes>(nodes: ItemDefinition<Schemes>[]) {
return <Items<Schemes>>(function (context, plugin) {
const area = plugin.parentScope<BaseAreaPlugin<Schemes, any>>(BaseAreaPlugin)

Check warning on line 20 in src/presets/classic/index.ts

View workflow job for this annotation

GitHub Actions / release / publish

Unexpected any. Specify a different type

Check warning on line 20 in src/presets/classic/index.ts

View workflow job for this annotation

GitHub Actions / release / publish

Unexpected any. Specify a different type
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 that create items for root and node specific context menu.
* @module
*/

export * as classic from './classic'
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { ContextMenuPlugin } from '.'

export type Position = { x: number, y: number }

/**
* Item type of context menu
*/
export type Item = {
label: string
key: string
Expand Down

0 comments on commit 5dcf64e

Please sign in to comment.