retejs / connection-plugin

https://retejs.org
MIT License
15 stars 36 forks source link

Custom Connection class #64

Open Fi1osof opened 7 months ago

Fi1osof commented 7 months ago

Now editor.addConnection passed pure data:

    context.editor.addConnection({
      id: getUID(),
      source: source.nodeId,
      sourceOutput: source.key,
      target: target.nodeId,
      targetInput: target.key
    })

But we can use cusom Connection class, f.e.: https://github.com/Ni55aN/allmatter/blob/main/src/editor/connections/index.ts

import { ClassicPreset } from 'rete'
import { Node } from '../types';

export class Connection<A extends Node, B extends Node> extends ClassicPreset.Connection<A, B> { }

https://github.com/Ni55aN/allmatter/blob/main/src/editor/import-export.ts#L81-L83

      const conn = new Connection(source, c.sourceOutput, target, c.targetInput);

      await di.editor.addConnection(conn);

I want to have ability to provide connection class resolver (middleware) like this

  render.addPreset(Presets.classic.setup({
    customize: {
      control(data) {
        if (data.payload instanceof ColorPicker) return ColorPickerUI
        if (data.payload instanceof Preview) return PreviewUI
        return Presets.classic.InputControl as any
      },
    }
  }));

Thanks!

Ni55aN commented 7 months ago

https://github.com/retejs/rete/issues/633#issuecomment-1611264335

rete-js[bot] commented 5 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.