Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/extensions/selectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { BaseArea, BaseAreaPlugin } from '../base'

type Schemes = GetSchemes<BaseSchemes['Node'] & { selected?: boolean }, any>

Check warning on line 5 in src/extensions/selectable.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Unexpected any. Specify a different type

Check warning on line 5 in src/extensions/selectable.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Unexpected any. Specify a different type

/**
* Selector's accumulate function, activated when the ctrl key is pressed
Expand Down Expand Up @@ -31,7 +31,12 @@
}
}

export type SelectorEntity = { label: string, id: string, unselect(): void | Promise<void>, translate(dx: number, dy: number): void }
export type SelectorEntity = {
label: string
id: string
unselect(): void | Promise<void>
translate(dx: number, dy: number): void | Promise<void>
}

/**
* Selector class. Used to collect selected entities (nodes, connections, etc.) and synchronize them (select, unselect, translate, etc.).
Expand Down Expand Up @@ -64,8 +69,8 @@
await Promise.all([...Array.from(this.entities.values())].map(item => this.remove(item)))
}

translate(dx: number, dy: number) {
this.entities.forEach(item => !this.isPicked(item) && item.translate(dx, dy))
async translate(dx: number, dy: number) {
await Promise.all(Array.from(this.entities.values()).map(item => !this.isPicked(item) && item.translate(dx, dy)))
}

pick(entity: Pick<E, 'label' | 'id'>) {
Expand Down Expand Up @@ -109,9 +114,9 @@
* @listens pointermove
* @listens pointerup
*/
export function selectableNodes<T>(base: BaseAreaPlugin<Schemes, T>, core: Selectable, options: { accumulating: Accumulating }) {

Check warning on line 117 in src/extensions/selectable.ts

View workflow job for this annotation

GitHub Actions / ci / ci

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

Check warning on line 117 in src/extensions/selectable.ts

View workflow job for this annotation

GitHub Actions / ci / ci

This line has a length of 129. Maximum allowed is 120
let editor: null | NodeEditor<Schemes> = null
const area = base as BaseAreaPlugin<Schemes, BaseArea<Schemes>>

Check warning on line 119 in src/extensions/selectable.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The 'base as BaseAreaPlugin<Schemes, BaseArea<Schemes>>' has unsafe 'as' type assertion

Check warning on line 119 in src/extensions/selectable.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The 'base as BaseAreaPlugin<Schemes, BaseArea<Schemes>>' has unsafe 'as' type assertion
const getEditor = () => editor || (editor = area.parentScope<NodeEditor<Schemes>>(NodeEditor))

let twitch: null | number = 0
Expand Down Expand Up @@ -142,12 +147,12 @@
await core.add({
label: 'node',
id: node.id,
translate(dx, dy) {
async translate(dx, dy) {
const view = area.nodeViews.get(node.id)
const current = view?.position

if (current) {
void view.translate(current.x + dx, current.y + dy)
await view.translate(current.x + dx, current.y + dy)
}
},
unselect() {
Expand Down Expand Up @@ -180,7 +185,7 @@
const dx = position.x - previous.x
const dy = position.y - previous.y

if (core.isPicked({ id, label: 'node' })) core.translate(dx, dy)
if (core.isPicked({ id, label: 'node' })) await core.translate(dx, dy)
} else if (context.type === 'pointerdown') {
twitch = 0
} else if (context.type === 'pointermove') {
Expand Down
Loading