@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.esm.js
CHANGED
|
@@ -2451,21 +2451,45 @@ function run(config) {
|
|
|
2451
2451
|
*/
|
|
2452
2452
|
function pasteRulesPlugin(props) {
|
|
2453
2453
|
const { editor, rules } = props;
|
|
2454
|
-
let
|
|
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
|
-
|
|
2458
|
-
|
|
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
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
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
|
-
|
|
2468
|
-
|
|
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
|