soccerloway / quill-better-table

Module for better table in Quill, more useful features are supported.
MIT License
319 stars 121 forks source link

Right click outside the table throw exception: Cannot read properties of undefined (reading 'getBoundingClientRect') #77

Open rceraline opened 3 years ago

rceraline commented 3 years ago

Hi,

I noticed an error when using the table. Here is the repro steps:

  1. Insert a table
  2. Click inside a cell to activate the table
  3. Right click outside the table

Expected behavior: no error Actual behavior: Cannot read properties of undefined (reading 'getBoundingClientRect')

The scenario can be reproduced here: https://codepen.io/soccerloway/pen/WWJowj

image

tkefauver commented 1 year ago

I had this problem too but didn't realize this was the cause!

I was able to workaround it adding a tunneled 'contextmenu' event listener on window and rejecting the right click if a cell is selected and the mouse point on the click is NOT in the table's <tbody> element's (specifically that element any higher will return the whole block width) bounding client rect. using getBoundingClientRect() and {x: e.clientX, y: e.clientY} for the collision detected.

mattheusbr commented 9 months ago

I solved the problem by adding the line

   if(!cellNode)
        return true;  

After

      const cellNode = path.filter(node => {
        return node.tagName &&
          node.tagName.toUpperCase() === 'TD' &&
          node.getAttribute('data-row')
      })[0]

Inside the Listener

    this.quill.root.addEventListener('contextmenu', (evt) => {