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