@tiptap/core 2.0.0-beta.161 → 2.0.0-beta.165

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.
@@ -18,6 +18,7 @@ export * from './inputRules/wrappingInputRule';
18
18
  export * from './pasteRules/markPasteRule';
19
19
  export * from './pasteRules/textPasteRule';
20
20
  export * from './utilities/callOrReturn';
21
+ export * from './utilities/escapeForRegEx';
21
22
  export * from './utilities/mergeAttributes';
22
23
  export * from './helpers/combineTransactionSteps';
23
24
  export * from './helpers/defaultBlockAt';
@@ -0,0 +1 @@
1
+ export declare function escapeForRegEx(string: string): string;
@@ -210,8 +210,12 @@ const ClipboardTextSerializer = Extension.create({
210
210
 
211
211
  const blur = () => ({ editor, view }) => {
212
212
  requestAnimationFrame(() => {
213
+ var _a;
213
214
  if (!editor.isDestroyed) {
214
215
  view.dom.blur();
216
+ // Browsers should remove the caret on blur but safari does not.
217
+ // See: https://github.com/ueberdosis/tiptap/issues/2405
218
+ (_a = window === null || window === void 0 ? void 0 : window.getSelection()) === null || _a === void 0 ? void 0 : _a.removeAllRanges();
215
219
  }
216
220
  });
217
221
  return true;
@@ -2455,21 +2459,45 @@ function run(config) {
2455
2459
  */
2456
2460
  function pasteRulesPlugin(props) {
2457
2461
  const { editor, rules } = props;
2458
- let isProseMirrorHTML = false;
2462
+ let dragSourceElement = null;
2463
+ let isPastedFromProseMirror = false;
2464
+ let isDroppedFromProseMirror = false;
2459
2465
  const plugins = rules.map(rule => {
2460
2466
  return new prosemirrorState.Plugin({
2461
- props: {
2462
- handlePaste: (view, event) => {
2467
+ // we register a global drag handler to track the current drag source element
2468
+ view(view) {
2469
+ const handleDragstart = (event) => {
2463
2470
  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;
2471
+ dragSourceElement = ((_a = view.dom.parentElement) === null || _a === void 0 ? void 0 : _a.contains(event.target))
2472
+ ? view.dom.parentElement
2473
+ : null;
2474
+ };
2475
+ window.addEventListener('dragstart', handleDragstart);
2476
+ return {
2477
+ destroy() {
2478
+ window.removeEventListener('dragstart', handleDragstart);
2479
+ },
2480
+ };
2481
+ },
2482
+ props: {
2483
+ handleDOMEvents: {
2484
+ drop: view => {
2485
+ isDroppedFromProseMirror = dragSourceElement === view.dom.parentElement;
2486
+ return false;
2487
+ },
2488
+ paste: (view, event) => {
2489
+ var _a;
2490
+ const html = (_a = event.clipboardData) === null || _a === void 0 ? void 0 : _a.getData('text/html');
2491
+ isPastedFromProseMirror = !!(html === null || html === void 0 ? void 0 : html.includes('data-pm-slice'));
2492
+ return false;
2493
+ },
2467
2494
  },
2468
2495
  },
2469
2496
  appendTransaction: (transactions, oldState, state) => {
2470
2497
  const transaction = transactions[0];
2471
- // stop if there is not a paste event
2472
- if (!transaction.getMeta('paste') || isProseMirrorHTML) {
2498
+ const isPaste = transaction.getMeta('uiEvent') === 'paste' && !isPastedFromProseMirror;
2499
+ const isDrop = transaction.getMeta('uiEvent') === 'drop' && !isDroppedFromProseMirror;
2500
+ if (!isPaste && !isDrop) {
2473
2501
  return;
2474
2502
  }
2475
2503
  // stop if there is no changed range
@@ -4083,6 +4111,11 @@ function textPasteRule(config) {
4083
4111
  });
4084
4112
  }
4085
4113
 
4114
+ // source: https://stackoverflow.com/a/6969486
4115
+ function escapeForRegEx(string) {
4116
+ return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
4117
+ }
4118
+
4086
4119
  /**
4087
4120
  * Returns a new `Transform` based on all steps of the passed transactions.
4088
4121
  */
@@ -4338,6 +4371,7 @@ exports.Tracker = Tracker;
4338
4371
  exports.callOrReturn = callOrReturn;
4339
4372
  exports.combineTransactionSteps = combineTransactionSteps;
4340
4373
  exports.defaultBlockAt = defaultBlockAt;
4374
+ exports.escapeForRegEx = escapeForRegEx;
4341
4375
  exports.extensions = extensions;
4342
4376
  exports.findChildren = findChildren;
4343
4377
  exports.findChildrenInRange = findChildrenInRange;