@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.
- package/dist/packages/core/src/index.d.ts +1 -0
- package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +1 -0
- package/dist/tiptap-core.cjs.js +42 -8
- package/dist/tiptap-core.cjs.js.map +1 -1
- package/dist/tiptap-core.esm.js +42 -9
- package/dist/tiptap-core.esm.js.map +1 -1
- package/dist/tiptap-core.umd.js +42 -8
- package/dist/tiptap-core.umd.js.map +1 -1
- package/package.json +3 -2
- package/src/PasteRule.ts +36 -7
- package/src/commands/blur.ts +4 -0
- package/src/index.ts +1 -0
- package/src/utilities/escapeForRegEx.ts +4 -0
|
@@ -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;
|
package/dist/tiptap-core.cjs.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
2462
|
-
|
|
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
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
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
|
-
|
|
2472
|
-
|
|
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;
|