@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.cjs.js
CHANGED
|
@@ -2455,21 +2455,45 @@ function run(config) {
|
|
|
2455
2455
|
*/
|
|
2456
2456
|
function pasteRulesPlugin(props) {
|
|
2457
2457
|
const { editor, rules } = props;
|
|
2458
|
-
let
|
|
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
|
-
|
|
2462
|
-
|
|
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
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
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
|
-
|
|
2472
|
-
|
|
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
|