How to setup/implement Medium type Tooltip menu?

Inside your dispatchTransaction handler, check for tr.selectionSet, e.g.:

pm = new EditorView(domElement, {
  dispatchTransaction: tr => {
    if (tr.selectionSet) {
      // do your thing
   }
})