@tiptap/core 2.0.0-beta.163 → 2.0.0-beta.167
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/commands/selectTextblockEnd.d.ts +12 -0
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +12 -0
- package/dist/packages/core/src/extensions/commands.d.ts +4 -0
- package/dist/packages/core/src/utilities/isMacOS.d.ts +1 -0
- package/dist/tiptap-core.cjs.js +105 -18
- package/dist/tiptap-core.cjs.js.map +1 -1
- package/dist/tiptap-core.esm.js +106 -19
- package/dist/tiptap-core.esm.js.map +1 -1
- package/dist/tiptap-core.umd.js +105 -18
- package/dist/tiptap-core.umd.js.map +1 -1
- package/package.json +5 -5
- package/src/PasteRule.ts +36 -7
- package/src/commands/blur.ts +4 -0
- package/src/commands/insertContentAt.ts +12 -1
- package/src/commands/keyboardShortcut.ts +3 -3
- package/src/commands/selectTextblockEnd.ts +19 -0
- package/src/commands/selectTextblockStart.ts +19 -0
- package/src/extensions/commands.ts +6 -0
- package/src/extensions/keymap.ts +35 -7
- package/src/utilities/isMacOS.ts +5 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { RawCommands } from '../types';
|
|
2
|
+
declare module '@tiptap/core' {
|
|
3
|
+
interface Commands<ReturnType> {
|
|
4
|
+
selectTextblockEnd: {
|
|
5
|
+
/**
|
|
6
|
+
* Moves the cursor to the end of current text block.
|
|
7
|
+
*/
|
|
8
|
+
selectTextblockEnd: () => ReturnType;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export declare const selectTextblockEnd: RawCommands['selectTextblockEnd'];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { RawCommands } from '../types';
|
|
2
|
+
declare module '@tiptap/core' {
|
|
3
|
+
interface Commands<ReturnType> {
|
|
4
|
+
selectTextblockStart: {
|
|
5
|
+
/**
|
|
6
|
+
* Moves the cursor to the start of current text block.
|
|
7
|
+
*/
|
|
8
|
+
selectTextblockStart: () => ReturnType;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export declare const selectTextblockStart: RawCommands['selectTextblockStart'];
|
|
@@ -28,6 +28,8 @@ import * as selectAll from '../commands/selectAll';
|
|
|
28
28
|
import * as selectNodeBackward from '../commands/selectNodeBackward';
|
|
29
29
|
import * as selectNodeForward from '../commands/selectNodeForward';
|
|
30
30
|
import * as selectParentNode from '../commands/selectParentNode';
|
|
31
|
+
import * as selectTextblockEnd from '../commands/selectTextblockEnd';
|
|
32
|
+
import * as selectTextblockStart from '../commands/selectTextblockStart';
|
|
31
33
|
import * as setContent from '../commands/setContent';
|
|
32
34
|
import * as setMark from '../commands/setMark';
|
|
33
35
|
import * as setMeta from '../commands/setMeta';
|
|
@@ -76,6 +78,8 @@ export { selectAll };
|
|
|
76
78
|
export { selectNodeBackward };
|
|
77
79
|
export { selectNodeForward };
|
|
78
80
|
export { selectParentNode };
|
|
81
|
+
export { selectTextblockEnd };
|
|
82
|
+
export { selectTextblockStart };
|
|
79
83
|
export { setContent };
|
|
80
84
|
export { setMark };
|
|
81
85
|
export { setMeta };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isMacOS(): boolean;
|
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;
|
|
@@ -670,6 +674,7 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
|
|
|
670
674
|
let { from, to } = typeof position === 'number'
|
|
671
675
|
? { from: position, to: position }
|
|
672
676
|
: position;
|
|
677
|
+
let isOnlyTextContent = true;
|
|
673
678
|
let isOnlyBlockContent = true;
|
|
674
679
|
const nodes = isFragment(content)
|
|
675
680
|
? content
|
|
@@ -677,6 +682,9 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
|
|
|
677
682
|
nodes.forEach(node => {
|
|
678
683
|
// check if added node is valid
|
|
679
684
|
node.check();
|
|
685
|
+
isOnlyTextContent = isOnlyTextContent
|
|
686
|
+
? node.isText && node.marks.length === 0
|
|
687
|
+
: false;
|
|
680
688
|
isOnlyBlockContent = isOnlyBlockContent
|
|
681
689
|
? node.isBlock
|
|
682
690
|
: false;
|
|
@@ -696,7 +704,14 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
|
|
|
696
704
|
to += 1;
|
|
697
705
|
}
|
|
698
706
|
}
|
|
699
|
-
|
|
707
|
+
// if there is only plain text we have to use `insertText`
|
|
708
|
+
// because this will keep the current marks
|
|
709
|
+
if (isOnlyTextContent) {
|
|
710
|
+
tr.insertText(value, from, to);
|
|
711
|
+
}
|
|
712
|
+
else {
|
|
713
|
+
tr.replaceWith(from, to, content);
|
|
714
|
+
}
|
|
700
715
|
// set cursor at end of inserted content
|
|
701
716
|
if (options.updateSelection) {
|
|
702
717
|
selectionToInsertionEnd(tr, tr.steps.length - 1, -1);
|
|
@@ -728,7 +743,12 @@ var joinForward$1 = /*#__PURE__*/Object.freeze({
|
|
|
728
743
|
joinForward: joinForward
|
|
729
744
|
});
|
|
730
745
|
|
|
731
|
-
|
|
746
|
+
function isMacOS() {
|
|
747
|
+
return typeof navigator !== 'undefined'
|
|
748
|
+
? /Mac/.test(navigator.platform)
|
|
749
|
+
: false;
|
|
750
|
+
}
|
|
751
|
+
|
|
732
752
|
function normalizeKeyName(name) {
|
|
733
753
|
const parts = name.split(/-(?!$)/);
|
|
734
754
|
let result = parts[parts.length - 1];
|
|
@@ -754,7 +774,7 @@ function normalizeKeyName(name) {
|
|
|
754
774
|
shift = true;
|
|
755
775
|
}
|
|
756
776
|
else if (/^mod$/i.test(mod)) {
|
|
757
|
-
if (
|
|
777
|
+
if (isiOS() || isMacOS()) {
|
|
758
778
|
meta = true;
|
|
759
779
|
}
|
|
760
780
|
else {
|
|
@@ -1006,6 +1026,26 @@ var selectParentNode$1 = /*#__PURE__*/Object.freeze({
|
|
|
1006
1026
|
selectParentNode: selectParentNode
|
|
1007
1027
|
});
|
|
1008
1028
|
|
|
1029
|
+
// @ts-ignore
|
|
1030
|
+
const selectTextblockEnd = () => ({ state, dispatch }) => {
|
|
1031
|
+
return prosemirrorCommands.selectTextblockEnd(state, dispatch);
|
|
1032
|
+
};
|
|
1033
|
+
|
|
1034
|
+
var selectTextblockEnd$1 = /*#__PURE__*/Object.freeze({
|
|
1035
|
+
__proto__: null,
|
|
1036
|
+
selectTextblockEnd: selectTextblockEnd
|
|
1037
|
+
});
|
|
1038
|
+
|
|
1039
|
+
// @ts-ignore
|
|
1040
|
+
const selectTextblockStart = () => ({ state, dispatch }) => {
|
|
1041
|
+
return prosemirrorCommands.selectTextblockStart(state, dispatch);
|
|
1042
|
+
};
|
|
1043
|
+
|
|
1044
|
+
var selectTextblockStart$1 = /*#__PURE__*/Object.freeze({
|
|
1045
|
+
__proto__: null,
|
|
1046
|
+
selectTextblockStart: selectTextblockStart
|
|
1047
|
+
});
|
|
1048
|
+
|
|
1009
1049
|
function createDocument(content, schema, parseOptions = {}) {
|
|
1010
1050
|
return createNodeFromContent(content, schema, { slice: false, parseOptions });
|
|
1011
1051
|
}
|
|
@@ -1804,6 +1844,8 @@ const Commands = Extension.create({
|
|
|
1804
1844
|
...selectNodeBackward$1,
|
|
1805
1845
|
...selectNodeForward$1,
|
|
1806
1846
|
...selectParentNode$1,
|
|
1847
|
+
...selectTextblockEnd$1,
|
|
1848
|
+
...selectTextblockStart$1,
|
|
1807
1849
|
...setContent$1,
|
|
1808
1850
|
...setMark$1,
|
|
1809
1851
|
...setMeta$1,
|
|
@@ -2043,13 +2085,14 @@ const Keymap = Extension.create({
|
|
|
2043
2085
|
() => commands.joinForward(),
|
|
2044
2086
|
() => commands.selectNodeForward(),
|
|
2045
2087
|
]);
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2088
|
+
const handleEnter = () => this.editor.commands.first(({ commands }) => [
|
|
2089
|
+
() => commands.newlineInCode(),
|
|
2090
|
+
() => commands.createParagraphNear(),
|
|
2091
|
+
() => commands.liftEmptyBlock(),
|
|
2092
|
+
() => commands.splitBlock(),
|
|
2093
|
+
]);
|
|
2094
|
+
const baseKeymap = {
|
|
2095
|
+
Enter: handleEnter,
|
|
2053
2096
|
'Mod-Enter': () => this.editor.commands.exitCode(),
|
|
2054
2097
|
Backspace: handleBackspace,
|
|
2055
2098
|
'Mod-Backspace': handleBackspace,
|
|
@@ -2058,6 +2101,26 @@ const Keymap = Extension.create({
|
|
|
2058
2101
|
'Mod-Delete': handleDelete,
|
|
2059
2102
|
'Mod-a': () => this.editor.commands.selectAll(),
|
|
2060
2103
|
};
|
|
2104
|
+
const pcKeymap = {
|
|
2105
|
+
...baseKeymap,
|
|
2106
|
+
Home: () => this.editor.commands.selectTextblockStart(),
|
|
2107
|
+
End: () => this.editor.commands.selectTextblockStart(),
|
|
2108
|
+
};
|
|
2109
|
+
const macKeymap = {
|
|
2110
|
+
...baseKeymap,
|
|
2111
|
+
'Ctrl-h': handleBackspace,
|
|
2112
|
+
'Alt-Backspace': handleBackspace,
|
|
2113
|
+
'Ctrl-d': handleDelete,
|
|
2114
|
+
'Ctrl-Alt-Backspace': handleDelete,
|
|
2115
|
+
'Alt-Delete': handleDelete,
|
|
2116
|
+
'Alt-d': handleDelete,
|
|
2117
|
+
'Ctrl-a': () => this.editor.commands.selectTextblockStart(),
|
|
2118
|
+
'Ctrl-e': () => this.editor.commands.selectTextblockEnd(),
|
|
2119
|
+
};
|
|
2120
|
+
if (isiOS() || isMacOS()) {
|
|
2121
|
+
return macKeymap;
|
|
2122
|
+
}
|
|
2123
|
+
return pcKeymap;
|
|
2061
2124
|
},
|
|
2062
2125
|
addProseMirrorPlugins() {
|
|
2063
2126
|
return [
|
|
@@ -2455,21 +2518,45 @@ function run(config) {
|
|
|
2455
2518
|
*/
|
|
2456
2519
|
function pasteRulesPlugin(props) {
|
|
2457
2520
|
const { editor, rules } = props;
|
|
2458
|
-
let
|
|
2521
|
+
let dragSourceElement = null;
|
|
2522
|
+
let isPastedFromProseMirror = false;
|
|
2523
|
+
let isDroppedFromProseMirror = false;
|
|
2459
2524
|
const plugins = rules.map(rule => {
|
|
2460
2525
|
return new prosemirrorState.Plugin({
|
|
2461
|
-
|
|
2462
|
-
|
|
2526
|
+
// we register a global drag handler to track the current drag source element
|
|
2527
|
+
view(view) {
|
|
2528
|
+
const handleDragstart = (event) => {
|
|
2463
2529
|
var _a;
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2530
|
+
dragSourceElement = ((_a = view.dom.parentElement) === null || _a === void 0 ? void 0 : _a.contains(event.target))
|
|
2531
|
+
? view.dom.parentElement
|
|
2532
|
+
: null;
|
|
2533
|
+
};
|
|
2534
|
+
window.addEventListener('dragstart', handleDragstart);
|
|
2535
|
+
return {
|
|
2536
|
+
destroy() {
|
|
2537
|
+
window.removeEventListener('dragstart', handleDragstart);
|
|
2538
|
+
},
|
|
2539
|
+
};
|
|
2540
|
+
},
|
|
2541
|
+
props: {
|
|
2542
|
+
handleDOMEvents: {
|
|
2543
|
+
drop: view => {
|
|
2544
|
+
isDroppedFromProseMirror = dragSourceElement === view.dom.parentElement;
|
|
2545
|
+
return false;
|
|
2546
|
+
},
|
|
2547
|
+
paste: (view, event) => {
|
|
2548
|
+
var _a;
|
|
2549
|
+
const html = (_a = event.clipboardData) === null || _a === void 0 ? void 0 : _a.getData('text/html');
|
|
2550
|
+
isPastedFromProseMirror = !!(html === null || html === void 0 ? void 0 : html.includes('data-pm-slice'));
|
|
2551
|
+
return false;
|
|
2552
|
+
},
|
|
2467
2553
|
},
|
|
2468
2554
|
},
|
|
2469
2555
|
appendTransaction: (transactions, oldState, state) => {
|
|
2470
2556
|
const transaction = transactions[0];
|
|
2471
|
-
|
|
2472
|
-
|
|
2557
|
+
const isPaste = transaction.getMeta('uiEvent') === 'paste' && !isPastedFromProseMirror;
|
|
2558
|
+
const isDrop = transaction.getMeta('uiEvent') === 'drop' && !isDroppedFromProseMirror;
|
|
2559
|
+
if (!isPaste && !isDrop) {
|
|
2473
2560
|
return;
|
|
2474
2561
|
}
|
|
2475
2562
|
// stop if there is no changed range
|