Lets say I want to show the text of the song on a page with an audio player. Suppose every word is in sync with a song through some playPosition props and clicking every word shall call player.seek() handler. How do I achieve that?
Do I need to send some props when I build ‘doc’ structure through attr: {}?
Do I need to dispatch transactions with my ‘seek’ props?
Or do I need to create new plugin and attach seekHandler in .apply()?
Or do I need to call handleClickOn (which I see is a part of EditorProps interface, but I unfortunately I have no idea what part of the initial setup is using this interface.
How are you modelling the concept of a “word”? Are you using Marks?
As an example, if you do use marks to surround each word, you can then detect the mark via state.selection object and grab the play position. There is probably also an alternate approach to using a NodeView per word with the play position attribute.
How you are getting the play position mapped to particular words is going to define how you solve this problem.
Question though, did you also want the text to highlight or something as the song plays? That is also an interesting, cool idea (although one can argue the value, but it does play nicely with “click to seek” you are proposing here.)
I think the easiest approach might be to register an editor-wide event handler and use posAtCoords to figure out where in the document the mouse click occurred.
You can put each word inside its own node, which I think is more intuitive (since it’ll also the unit of user interaction), and also easier to implement single-word level visual effects like highlighting
or you can use paragraph as the smallest unit, then you can attach the timing info to each paragraph (or the whole song), and have a way to map a given pos to a give time, e.g. some function like fn(pos: number) → time: number