Skip to content

Commit

Permalink
Merge pull request #62 from retejs/docs/typedoc
Browse files Browse the repository at this point in the history
Docs/typedoc
  • Loading branch information
Ni55aN authored Jul 19, 2023
2 parents 4c04df2 + 0381556 commit f6fca36
Show file tree
Hide file tree
Showing 11 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: "7.rete-angular-plugin"
package: rete-angular-plugin
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ testem.log
Thumbs.db

.src
docs
2 changes: 1 addition & 1 deletion package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"build:14": "npm --prefix ng14 run build",
"build:15": "npm --prefix ng15 run build",
"build:16": "npm --prefix ng16 run build",
"postinstall": "npm i --prefix ng12 && npm i --prefix ng13 && npm i --prefix ng14 && npm i --prefix ng15 && npm i --prefix ng16"
"postinstall": "npm i --prefix ng12 && npm i --prefix ng13 && npm i --prefix ng14 && npm i --prefix ng15 && npm i --prefix ng16",
"doc": "rete doc"
},
"author": "Vitaliy Stoliarov",
"license": "MIT",
Expand Down
22 changes: 21 additions & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,35 @@ function getRenderer(): Renderer {
}
}

type Produces<Schemes extends BaseSchemes> =
/**
* Signals that can be emitted by the plugin
* @priority 10
*/
export type Produces<Schemes extends BaseSchemes> =
| { type: 'connectionpath', data: { payload: Schemes['Connection'], path?: string, points: Position[] } }

type Requires<Schemes extends BaseSchemes> =
| RenderSignal<'node', { payload: Schemes['Node'] }>
| RenderSignal<'connection', { payload: Schemes['Connection'], start?: Position, end?: Position }>
| { type: 'unmount', data: { element: HTMLElement } }

/**
* Angular plugin. Renders nodes, connections and other elements using React.
* @priority 9
* @emits connectionpath
* @listens render
* @listens unmount
*/
export class AngularPlugin<Schemes extends BaseSchemes, T = Requires<Schemes>> extends Scope<Produces<Schemes>, [Requires<Schemes> | T]> {
presets: RenderPreset<Schemes, T>[] = []
renderer: Renderer
owners = new WeakMap<HTMLElement, RenderPreset<Schemes, T>>()

/**
* @constructor
* @param params Plugin properties
* @param params.injector Angular's Injector instance
*/
constructor(private params: { injector: Injector }) {
super('angular-render')
this.renderer = getRenderer()
Expand Down Expand Up @@ -137,6 +153,10 @@ export class AngularPlugin<Schemes extends BaseSchemes, T = Requires<Schemes>> e
return
}

/**
* Adds a preset to the plugin.
* @param preset Preset that can render nodes, connections and other elements.
*/
public addPreset<K>(preset: RenderPreset<Schemes, CanAssignSignal<T, K> extends true ? K : 'Cannot apply preset. Provided signals are not compatible'>) {
const local = preset as unknown as RenderPreset<Schemes, T>

Expand Down
3 changes: 3 additions & 0 deletions src/presets/classic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type ClassicProps<Schemes extends ClassicScheme, K> = {
customize?: CustomizationProps<Schemes>
}

/**
* Classic preset for rendering nodes, connections, controls and sockets.
*/
export function setup<Schemes extends ClassicScheme, K extends AngularArea2D<Schemes>>(
props?: ClassicProps<Schemes, K>
): RenderPreset<Schemes, K> {
Expand Down
3 changes: 3 additions & 0 deletions src/presets/context-menu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { ContextMenuRender } from './types';
import { ContextMenuComponent } from './components/menu/menu.component';
import { RenderPreset } from '../types';

/**
* Preset for rendering context menu.
*/
export function setup<Schemes extends BaseSchemes, K extends ContextMenuRender>(props?: { delay?: number }): RenderPreset<Schemes, K> {
const delay = typeof props?.delay === 'undefined' ? 1000 : props.delay

Expand Down
4 changes: 4 additions & 0 deletions src/presets/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Built-in presets, responsible for rendering different parts of the editor.
* @module
*/
export * as classic from './classic'
export * as contextMenu from './context-menu'
export * as minimap from './minimap'
Expand Down
3 changes: 3 additions & 0 deletions src/presets/minimap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { RenderPreset } from '../types';
import { MinimapRender } from './types';
import { MinimapComponent } from './components/minimap/minimap.component';

/**
* Preset for rendering minimap.
*/
export function setup<Schemes extends BaseSchemes, K extends MinimapRender>(props?: { size?: number }): RenderPreset<Schemes, K> {
return {
update(context) {
Expand Down
3 changes: 3 additions & 0 deletions src/presets/reroute/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ type Props = {
pointerdown?: (id: string) => void
}

/**
* Preset for rendering pins.
*/
export function setup<Schemes extends BaseSchemes, K extends PinsRender>(props?: Props): RenderPreset<Schemes, K> {
const getProps = () => ({
menu: props?.contextMenu || (() => null),
Expand Down
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@
"es2018",
"dom"
]
}
},
"include": [
"src"
]
}

0 comments on commit f6fca36

Please sign in to comment.