@tiptap/core 2.0.0-beta.163 → 2.0.0-beta.164

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2449,21 +2449,45 @@
2449
2449
  */
2450
2450
  function pasteRulesPlugin(props) {
2451
2451
  const { editor, rules } = props;
2452
- let isProseMirrorHTML = false;
2452
+ let dragSourceElement = null;
2453
+ let isPastedFromProseMirror = false;
2454
+ let isDroppedFromProseMirror = false;
2453
2455
  const plugins = rules.map(rule => {
2454
2456
  return new prosemirrorState.Plugin({
2455
- props: {
2456
- handlePaste: (view, event) => {
2457
+ // we register a global drag handler to track the current drag source element
2458
+ view(view) {
2459
+ const handleDragstart = (event) => {
2457
2460
  var _a;
2458
- const html = (_a = event.clipboardData) === null || _a === void 0 ? void 0 : _a.getData('text/html');
2459
- isProseMirrorHTML = !!(html === null || html === void 0 ? void 0 : html.includes('data-pm-slice'));
2460
- return false;
2461
+ dragSourceElement = ((_a = view.dom.parentElement) === null || _a === void 0 ? void 0 : _a.contains(event.target))
2462
+ ? view.dom.parentElement
2463
+ : null;
2464
+ };
2465
+ window.addEventListener('dragstart', handleDragstart);
2466
+ return {
2467
+ destroy() {
2468
+ window.removeEventListener('dragstart', handleDragstart);
2469
+ },
2470
+ };
2471
+ },
2472
+ props: {
2473
+ handleDOMEvents: {
2474
+ drop: view => {
2475
+ isDroppedFromProseMirror = dragSourceElement === view.dom.parentElement;
2476
+ return false;
2477
+ },
2478
+ paste: (view, event) => {
2479
+ var _a;
2480
+ const html = (_a = event.clipboardData) === null || _a === void 0 ? void 0 : _a.getData('text/html');
2481
+ isPastedFromProseMirror = !!(html === null || html === void 0 ? void 0 : html.includes('data-pm-slice'));
2482
+ return false;
2483
+ },
2461
2484
  },
2462
2485
  },
2463
2486
  appendTransaction: (transactions, oldState, state) => {
2464
2487
  const transaction = transactions[0];
2465
- // stop if there is not a paste event
2466
- if (!transaction.getMeta('paste') || isProseMirrorHTML) {
2488
+ const isPaste = transaction.getMeta('uiEvent') === 'paste' && !isPastedFromProseMirror;
2489
+ const isDrop = transaction.getMeta('uiEvent') === 'drop' && !isDroppedFromProseMirror;
2490
+ if (!isPaste && !isDrop) {
2467
2491
  return;
2468
2492
  }
2469
2493
  // stop if there is no changed range