tiptap icon indicating copy to clipboard operation
tiptap copied to clipboard

[Bug]: ReferenceError: Can't find variable: DragEvent

Open D-Sketon opened this issue 7 months ago • 6 comments

Which packages did you experience the bug in?

core, react

What Tiptap version are you using?

2.1.11/2.1.12

What’s the bug you are facing?

related PR: https://github.com/ueberdosis/tiptap/pull/4354 I'm using IOS 13.6 and IOS 12.5.7 DragEvent is not supported in Safari and an exception will be thrown when the Editor is created.

What browser are you using?

Safari

Code example

No response

What did you expect to happen?

no error and I can create Editor successfully

Anything to add? (optional)

No response

Did you update your dependencies?

  • [X] Yes, I’ve updated my dependencies to use the latest version of all packages.

Are you sponsoring us?

  • [ ] Yes, I’m a sponsor. 💖

D-Sketon avatar Nov 06 '23 06:11 D-Sketon

i also find this problem, how to resolve it?

Ashster avatar Dec 25 '23 09:12 Ashster

The same problem

aliaszz avatar Jan 17 '24 09:01 aliaszz

We also have this problem.

ejellard avatar Jan 24 '24 15:01 ejellard

We also have this problem

dbousamra avatar Mar 19 '24 06:03 dbousamra

We also have this problem

zenonux avatar May 07 '24 02:05 zenonux

We ended up polyfilling DragEvent and DataTransfer to work around our browser compatibility issues.

drag-event.js:

(() => {
  if (typeof window.DragEvent !== 'undefined') {
    return;
  }

  window.DragEvent = function (type, eventInitDict) {
    eventInitDict = eventInitDict || { bubbles: false, cancelable: false };
    let event = document.createEvent('MouseEvent');
    event.initMouseEvent(
      type,
      eventInitDict.bubbles,
      eventInitDict.cancelable,
      window,
      0,
      eventInitDict.screenX || 0,
      eventInitDict.screenY || 0,
      eventInitDict.clientX || 0,
      eventInitDict.clientY || 0,
      eventInitDict.ctrlKey || false,
      eventInitDict.altKey || false,
      eventInitDict.shiftKey || false,
      eventInitDict.metaKey || false,
      eventInitDict.button || 0,
      eventInitDict.relatedTarget || null
    );
    return event;
  };
})();

data-transfer.js:

(() => {
  if (typeof window.DataTransfer !== 'undefined') {
    return;
  }

  window.DataTransfer = function () {
    this.dropEffect = '';
    this.effectAllowed = '';
    this.files = [];
    this.items = [];
    this.types = [];

    this.setData = function (format, data) {
      this.items.push({ format: format, data: data });
      this.types.push(format);
    };

    this.getData = function (format) {
      for (const item of this.items) {
        if (item.format === format) {
          return item.data;
        }
      }

      return '';
    };

    this.clearData = function (format) {
      if (format) {
        for (let i = 0; i < this.items.length; i++) {
          if (this.items[i].format === format) {
            this.items.splice(i, 1);
            this.types.splice(i, 1);
            i--;
          }
        }
      } else {
        this.items = [];
        this.types = [];
      }
    };
  };
})();

jacobmllr95 avatar May 07 '24 06:05 jacobmllr95