@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.
@@ -2455,21 +2455,45 @@ function run(config) {
2455
2455
  */
2456
2456
  function pasteRulesPlugin(props) {
2457
2457
  const { editor, rules } = props;
2458
- let isProseMirrorHTML = false;
2458
+ let dragSourceElement = null;
2459
+ let isPastedFromProseMirror = false;
2460
+ let isDroppedFromProseMirror = false;
2459
2461
  const plugins = rules.map(rule => {
2460
2462
  return new prosemirrorState.Plugin({
2461
- props: {
2462
- handlePaste: (view, event) => {
2463
+ // we register a global drag handler to track the current drag source element
2464
+ view(view) {
2465
+ const handleDragstart = (event) => {
2463
2466
  var _a;
2464
- const html = (_a = event.clipboardData) === null || _a === void 0 ? void 0 : _a.getData('text/html');
2465
- isProseMirrorHTML = !!(html === null || html === void 0 ? void 0 : html.includes('data-pm-slice'));
2466
- return false;
2467
+ dragSourceElement = ((_a = view.dom.parentElement) === null || _a === void 0 ? void 0 : _a.contains(event.target))
2468
+ ? view.dom.parentElement
2469
+ : null;
2470
+ };
2471
+ window.addEventListener('dragstart', handleDragstart);
2472
+ return {
2473
+ destroy() {
2474
+ window.removeEventListener('dragstart', handleDragstart);
2475
+ },
2476
+ };
2477
+ },
2478
+ props: {
2479
+ handleDOMEvents: {
2480
+ drop: view => {
2481
+ isDroppedFromProseMirror = dragSourceElement === view.dom.parentElement;
2482
+ return false;
2483
+ },
2484
+ paste: (view, event) => {
2485
+ var _a;
2486
+ const html = (_a = event.clipboardData) === null || _a === void 0 ? void 0 : _a.getData('text/html');
2487
+ isPastedFromProseMirror = !!(html === null || html === void 0 ? void 0 : html.includes('data-pm-slice'));
2488
+ return false;
2489
+ },
2467
2490
  },
2468
2491
  },
2469
2492
  appendTransaction: (transactions, oldState, state) => {
2470
2493
  const transaction = transactions[0];
2471
- // stop if there is not a paste event
2472
- if (!transaction.getMeta('paste') || isProseMirrorHTML) {
2494
+ const isPaste = transaction.getMeta('uiEvent') === 'paste' && !isPastedFromProseMirror;
2495
+ const isDrop = transaction.getMeta('uiEvent') === 'drop' && !isDroppedFromProseMirror;
2496
+ if (!isPaste && !isDrop) {
2473
2497
  return;
2474
2498
  }
2475
2499
  // stop if there is no changed range