@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.
- package/dist/tiptap-core.cjs.js +32 -8
- package/dist/tiptap-core.cjs.js.map +1 -1
- package/dist/tiptap-core.esm.js +32 -8
- package/dist/tiptap-core.esm.js.map +1 -1
- package/dist/tiptap-core.umd.js +32 -8
- package/dist/tiptap-core.umd.js.map +1 -1
- package/package.json +2 -2
- package/src/PasteRule.ts +36 -7
package/dist/tiptap-core.umd.js
CHANGED
|
@@ -2449,21 +2449,45 @@
|
|
|
2449
2449
|
*/
|
|
2450
2450
|
function pasteRulesPlugin(props) {
|
|
2451
2451
|
const { editor, rules } = props;
|
|
2452
|
-
let
|
|
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
|
-
|
|
2456
|
-
|
|
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
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
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
|
-
|
|
2466
|
-
|
|
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
|