Skip to content

Commit

Permalink
extend BaseAreaPlugin by getBoundingBox
Browse files Browse the repository at this point in the history
  • Loading branch information
Ni55aN committed May 17, 2023
1 parent c4d10fb commit c6a1f28
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/extensions/bounding-box.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { BaseSchemes, NodeEditor } from 'rete'

import { AreaPlugin } from '..'
import { BaseAreaPlugin } from '../base'
import { getBoundingBox as getBBox } from '../utils'
import { NodeRef } from './shared/types'
import { getNodesRect } from './shared/utils'

export function getBoundingBox<Schemes extends BaseSchemes, K>(plugin: AreaPlugin<Schemes, K>, nodes: NodeRef<Schemes>[]) {
export function getBoundingBox<Schemes extends BaseSchemes, K>(plugin: BaseAreaPlugin<Schemes, K>, nodes: NodeRef<Schemes>[]) {
const editor = plugin.parentScope<NodeEditor<Schemes>>(NodeEditor)
const list = nodes.map(node => typeof node === 'object' ? node : editor.getNode(node))
const rects = getNodesRect(list, plugin.nodeViews)
Expand Down
5 changes: 2 additions & 3 deletions src/extensions/shared/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { NodeId } from 'rete'

import { BaseAreaPlugin } from '../../base'
import { NodeView } from '../../node-view'
import { SchemesWithSizes } from './types'

export function getNodesRect(nodes: SchemesWithSizes['Node'][], views: Map<NodeId, NodeView>) {
export function getNodesRect<S extends SchemesWithSizes, K>(nodes: S['Node'][], views: BaseAreaPlugin<S, K>['nodeViews']) {
return nodes
.map(node => ({ view: views.get(node.id) as NodeView, node }))
.filter(item => item.view)
Expand Down

0 comments on commit c6a1f28

Please sign in to comment.