@tiptap/core 2.0.0-beta.162 → 2.0.0-beta.166
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 +54 -9
- package/dist/tiptap-core.cjs.js.map +1 -1
- package/dist/tiptap-core.esm.js +54 -10
- package/dist/tiptap-core.esm.js.map +1 -1
- package/dist/tiptap-core.umd.js +54 -9
- package/dist/tiptap-core.umd.js.map +1 -1
- package/package.json +2 -2
- package/src/PasteRule.ts +36 -7
- package/src/commands/blur.ts +4 -0
- package/src/commands/insertContentAt.ts +12 -1
- package/src/index.ts +1 -0
- package/src/utilities/escapeForRegEx.ts +4 -0
package/dist/tiptap-core.esm.js
CHANGED
|
@@ -206,8 +206,12 @@ const ClipboardTextSerializer = Extension.create({
|
|
|
206
206
|
|
|
207
207
|
const blur = () => ({ editor, view }) => {
|
|
208
208
|
requestAnimationFrame(() => {
|
|
209
|
+
var _a;
|
|
209
210
|
if (!editor.isDestroyed) {
|
|
210
211
|
view.dom.blur();
|
|
212
|
+
// Browsers should remove the caret on blur but safari does not.
|
|
213
|
+
// See: https://github.com/ueberdosis/tiptap/issues/2405
|
|
214
|
+
(_a = window === null || window === void 0 ? void 0 : window.getSelection()) === null || _a === void 0 ? void 0 : _a.removeAllRanges();
|
|
211
215
|
}
|
|
212
216
|
});
|
|
213
217
|
return true;
|
|
@@ -666,6 +670,7 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
|
|
|
666
670
|
let { from, to } = typeof position === 'number'
|
|
667
671
|
? { from: position, to: position }
|
|
668
672
|
: position;
|
|
673
|
+
let isOnlyTextContent = true;
|
|
669
674
|
let isOnlyBlockContent = true;
|
|
670
675
|
const nodes = isFragment(content)
|
|
671
676
|
? content
|
|
@@ -673,6 +678,9 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
|
|
|
673
678
|
nodes.forEach(node => {
|
|
674
679
|
// check if added node is valid
|
|
675
680
|
node.check();
|
|
681
|
+
isOnlyTextContent = isOnlyTextContent
|
|
682
|
+
? node.isText && node.marks.length === 0
|
|
683
|
+
: false;
|
|
676
684
|
isOnlyBlockContent = isOnlyBlockContent
|
|
677
685
|
? node.isBlock
|
|
678
686
|
: false;
|
|
@@ -692,7 +700,14 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
|
|
|
692
700
|
to += 1;
|
|
693
701
|
}
|
|
694
702
|
}
|
|
695
|
-
|
|
703
|
+
// if there is only plain text we have to use `insertText`
|
|
704
|
+
// because this will keep the current marks
|
|
705
|
+
if (isOnlyTextContent) {
|
|
706
|
+
tr.insertText(value, from, to);
|
|
707
|
+
}
|
|
708
|
+
else {
|
|
709
|
+
tr.replaceWith(from, to, content);
|
|
710
|
+
}
|
|
696
711
|
// set cursor at end of inserted content
|
|
697
712
|
if (options.updateSelection) {
|
|
698
713
|
selectionToInsertionEnd(tr, tr.steps.length - 1, -1);
|
|
@@ -2451,21 +2466,45 @@ function run(config) {
|
|
|
2451
2466
|
*/
|
|
2452
2467
|
function pasteRulesPlugin(props) {
|
|
2453
2468
|
const { editor, rules } = props;
|
|
2454
|
-
let
|
|
2469
|
+
let dragSourceElement = null;
|
|
2470
|
+
let isPastedFromProseMirror = false;
|
|
2471
|
+
let isDroppedFromProseMirror = false;
|
|
2455
2472
|
const plugins = rules.map(rule => {
|
|
2456
2473
|
return new Plugin({
|
|
2457
|
-
|
|
2458
|
-
|
|
2474
|
+
// we register a global drag handler to track the current drag source element
|
|
2475
|
+
view(view) {
|
|
2476
|
+
const handleDragstart = (event) => {
|
|
2459
2477
|
var _a;
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2478
|
+
dragSourceElement = ((_a = view.dom.parentElement) === null || _a === void 0 ? void 0 : _a.contains(event.target))
|
|
2479
|
+
? view.dom.parentElement
|
|
2480
|
+
: null;
|
|
2481
|
+
};
|
|
2482
|
+
window.addEventListener('dragstart', handleDragstart);
|
|
2483
|
+
return {
|
|
2484
|
+
destroy() {
|
|
2485
|
+
window.removeEventListener('dragstart', handleDragstart);
|
|
2486
|
+
},
|
|
2487
|
+
};
|
|
2488
|
+
},
|
|
2489
|
+
props: {
|
|
2490
|
+
handleDOMEvents: {
|
|
2491
|
+
drop: view => {
|
|
2492
|
+
isDroppedFromProseMirror = dragSourceElement === view.dom.parentElement;
|
|
2493
|
+
return false;
|
|
2494
|
+
},
|
|
2495
|
+
paste: (view, event) => {
|
|
2496
|
+
var _a;
|
|
2497
|
+
const html = (_a = event.clipboardData) === null || _a === void 0 ? void 0 : _a.getData('text/html');
|
|
2498
|
+
isPastedFromProseMirror = !!(html === null || html === void 0 ? void 0 : html.includes('data-pm-slice'));
|
|
2499
|
+
return false;
|
|
2500
|
+
},
|
|
2463
2501
|
},
|
|
2464
2502
|
},
|
|
2465
2503
|
appendTransaction: (transactions, oldState, state) => {
|
|
2466
2504
|
const transaction = transactions[0];
|
|
2467
|
-
|
|
2468
|
-
|
|
2505
|
+
const isPaste = transaction.getMeta('uiEvent') === 'paste' && !isPastedFromProseMirror;
|
|
2506
|
+
const isDrop = transaction.getMeta('uiEvent') === 'drop' && !isDroppedFromProseMirror;
|
|
2507
|
+
if (!isPaste && !isDrop) {
|
|
2469
2508
|
return;
|
|
2470
2509
|
}
|
|
2471
2510
|
// stop if there is no changed range
|
|
@@ -4079,6 +4118,11 @@ function textPasteRule(config) {
|
|
|
4079
4118
|
});
|
|
4080
4119
|
}
|
|
4081
4120
|
|
|
4121
|
+
// source: https://stackoverflow.com/a/6969486
|
|
4122
|
+
function escapeForRegEx(string) {
|
|
4123
|
+
return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
4124
|
+
}
|
|
4125
|
+
|
|
4082
4126
|
/**
|
|
4083
4127
|
* Returns a new `Transform` based on all steps of the passed transactions.
|
|
4084
4128
|
*/
|
|
@@ -4322,5 +4366,5 @@ function posToDOMRect(view, from, to) {
|
|
|
4322
4366
|
};
|
|
4323
4367
|
}
|
|
4324
4368
|
|
|
4325
|
-
export { CommandManager, Editor, Extension, InputRule, Mark, Node, NodeView, PasteRule, Tracker, callOrReturn, combineTransactionSteps, defaultBlockAt, extensions, findChildren, findChildrenInRange, findParentNode, findParentNodeClosestToPos, generateHTML, generateJSON, generateText, getAttributes, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarkType, getMarksBetween, getNodeAttributes, getNodeType, getSchema, getText, getTextBetween, inputRulesPlugin, isActive, isList, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isTextSelection, markInputRule, markPasteRule, mergeAttributes, nodeInputRule, pasteRulesPlugin, posToDOMRect, textInputRule, textPasteRule, textblockTypeInputRule, wrappingInputRule };
|
|
4369
|
+
export { CommandManager, Editor, Extension, InputRule, Mark, Node, NodeView, PasteRule, Tracker, callOrReturn, combineTransactionSteps, defaultBlockAt, escapeForRegEx, extensions, findChildren, findChildrenInRange, findParentNode, findParentNodeClosestToPos, generateHTML, generateJSON, generateText, getAttributes, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarkType, getMarksBetween, getNodeAttributes, getNodeType, getSchema, getText, getTextBetween, inputRulesPlugin, isActive, isList, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isTextSelection, markInputRule, markPasteRule, mergeAttributes, nodeInputRule, pasteRulesPlugin, posToDOMRect, textInputRule, textPasteRule, textblockTypeInputRule, wrappingInputRule };
|
|
4326
4370
|
//# sourceMappingURL=tiptap-core.esm.js.map
|