@tiptap/core 2.0.0-beta.165 → 2.0.0-beta.169
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 +70 -16
- package/dist/tiptap-core.cjs.js.map +1 -1
- package/dist/tiptap-core.esm.js +71 -17
- package/dist/tiptap-core.esm.js.map +1 -1
- package/dist/tiptap-core.umd.js +70 -16
- package/dist/tiptap-core.umd.js.map +1 -1
- package/package.json +5 -5
- 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/helpers/injectExtensionAttributesToParseRule.ts +14 -20
- 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
|
@@ -674,6 +674,7 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
|
|
|
674
674
|
let { from, to } = typeof position === 'number'
|
|
675
675
|
? { from: position, to: position }
|
|
676
676
|
: position;
|
|
677
|
+
let isOnlyTextContent = true;
|
|
677
678
|
let isOnlyBlockContent = true;
|
|
678
679
|
const nodes = isFragment(content)
|
|
679
680
|
? content
|
|
@@ -681,6 +682,9 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
|
|
|
681
682
|
nodes.forEach(node => {
|
|
682
683
|
// check if added node is valid
|
|
683
684
|
node.check();
|
|
685
|
+
isOnlyTextContent = isOnlyTextContent
|
|
686
|
+
? node.isText && node.marks.length === 0
|
|
687
|
+
: false;
|
|
684
688
|
isOnlyBlockContent = isOnlyBlockContent
|
|
685
689
|
? node.isBlock
|
|
686
690
|
: false;
|
|
@@ -700,7 +704,14 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
|
|
|
700
704
|
to += 1;
|
|
701
705
|
}
|
|
702
706
|
}
|
|
703
|
-
|
|
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
|
+
}
|
|
704
715
|
// set cursor at end of inserted content
|
|
705
716
|
if (options.updateSelection) {
|
|
706
717
|
selectionToInsertionEnd(tr, tr.steps.length - 1, -1);
|
|
@@ -732,7 +743,12 @@ var joinForward$1 = /*#__PURE__*/Object.freeze({
|
|
|
732
743
|
joinForward: joinForward
|
|
733
744
|
});
|
|
734
745
|
|
|
735
|
-
|
|
746
|
+
function isMacOS() {
|
|
747
|
+
return typeof navigator !== 'undefined'
|
|
748
|
+
? /Mac/.test(navigator.platform)
|
|
749
|
+
: false;
|
|
750
|
+
}
|
|
751
|
+
|
|
736
752
|
function normalizeKeyName(name) {
|
|
737
753
|
const parts = name.split(/-(?!$)/);
|
|
738
754
|
let result = parts[parts.length - 1];
|
|
@@ -758,7 +774,7 @@ function normalizeKeyName(name) {
|
|
|
758
774
|
shift = true;
|
|
759
775
|
}
|
|
760
776
|
else if (/^mod$/i.test(mod)) {
|
|
761
|
-
if (
|
|
777
|
+
if (isiOS() || isMacOS()) {
|
|
762
778
|
meta = true;
|
|
763
779
|
}
|
|
764
780
|
else {
|
|
@@ -1010,6 +1026,26 @@ var selectParentNode$1 = /*#__PURE__*/Object.freeze({
|
|
|
1010
1026
|
selectParentNode: selectParentNode
|
|
1011
1027
|
});
|
|
1012
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
|
+
|
|
1013
1049
|
function createDocument(content, schema, parseOptions = {}) {
|
|
1014
1050
|
return createNodeFromContent(content, schema, { slice: false, parseOptions });
|
|
1015
1051
|
}
|
|
@@ -1808,6 +1844,8 @@ const Commands = Extension.create({
|
|
|
1808
1844
|
...selectNodeBackward$1,
|
|
1809
1845
|
...selectNodeForward$1,
|
|
1810
1846
|
...selectParentNode$1,
|
|
1847
|
+
...selectTextblockEnd$1,
|
|
1848
|
+
...selectTextblockStart$1,
|
|
1811
1849
|
...setContent$1,
|
|
1812
1850
|
...setMark$1,
|
|
1813
1851
|
...setMeta$1,
|
|
@@ -2047,13 +2085,14 @@ const Keymap = Extension.create({
|
|
|
2047
2085
|
() => commands.joinForward(),
|
|
2048
2086
|
() => commands.selectNodeForward(),
|
|
2049
2087
|
]);
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
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,
|
|
2057
2096
|
'Mod-Enter': () => this.editor.commands.exitCode(),
|
|
2058
2097
|
Backspace: handleBackspace,
|
|
2059
2098
|
'Mod-Backspace': handleBackspace,
|
|
@@ -2062,6 +2101,26 @@ const Keymap = Extension.create({
|
|
|
2062
2101
|
'Mod-Delete': handleDelete,
|
|
2063
2102
|
'Mod-a': () => this.editor.commands.selectAll(),
|
|
2064
2103
|
};
|
|
2104
|
+
const pcKeymap = {
|
|
2105
|
+
...baseKeymap,
|
|
2106
|
+
Home: () => this.editor.commands.selectTextblockStart(),
|
|
2107
|
+
End: () => this.editor.commands.selectTextblockEnd(),
|
|
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;
|
|
2065
2124
|
},
|
|
2066
2125
|
addProseMirrorPlugins() {
|
|
2067
2126
|
return [
|
|
@@ -2681,15 +2740,10 @@ function injectExtensionAttributesToParseRule(parseRule, extensionAttributes) {
|
|
|
2681
2740
|
if (oldAttributes === false) {
|
|
2682
2741
|
return false;
|
|
2683
2742
|
}
|
|
2684
|
-
const newAttributes = extensionAttributes
|
|
2685
|
-
.filter(item => item.attribute.rendered)
|
|
2686
|
-
.reduce((items, item) => {
|
|
2743
|
+
const newAttributes = extensionAttributes.reduce((items, item) => {
|
|
2687
2744
|
const value = item.attribute.parseHTML
|
|
2688
2745
|
? item.attribute.parseHTML(node)
|
|
2689
2746
|
: fromString(node.getAttribute(item.name));
|
|
2690
|
-
if (isObject(value)) {
|
|
2691
|
-
console.warn(`[tiptap warn]: BREAKING CHANGE: "parseHTML" for your attribute "${item.name}" returns an object but should return the value itself. If this is expected you can ignore this message. This warning will be removed in one of the next releases. Further information: https://github.com/ueberdosis/tiptap/issues/1863`);
|
|
2692
|
-
}
|
|
2693
2747
|
if (value === null || value === undefined) {
|
|
2694
2748
|
return items;
|
|
2695
2749
|
}
|