Hufe921 / canvas-editor

rich text editor by canvas/svg
https://hufe.club/canvas-editor-docs
MIT License
3.49k stars 510 forks source link

Capture click of a control or element #815

Closed lehno closed 2 hours ago

lehno commented 3 hours ago

What problem does this feature solve?

I created a few custom plugins to show formated data in the editor. I would like to click on it and invoke an external function to open a popup or something else

What does the proposed API look like?

When adding a control, be able to send a function as a click callback or be able to listen to mouse click event and check if click has element with control extension

lehno commented 2 hours ago

    document.addEventListener('click', (evt) => {
      const positionContext = this.editor.command.getPositionContextByEvent(evt);
      if (positionContext?.element?.control?.conceptId === 'mergeField') {
        console.log(positionContext);
      }
    });