@contentful/field-editor-rich-text 6.4.4 → 6.4.5-canary.0
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.
|
@@ -9,13 +9,58 @@ Object.defineProperty(exports, "createTextPlugin", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _richtexttypes = require("@contentful/rich-text-types");
|
|
12
|
+
const _platecommon = require("@udecode/plate-common");
|
|
13
|
+
const _slate = require("slate");
|
|
12
14
|
const _queries = require("../../internal/queries");
|
|
13
15
|
const _transforms = require("../../internal/transforms");
|
|
14
16
|
function createTextPlugin(restrictedMarks = []) {
|
|
15
17
|
return {
|
|
16
18
|
key: 'TextPlugin',
|
|
17
19
|
handlers: {
|
|
18
|
-
|
|
20
|
+
onKeyDown: (editor)=>(event)=>{
|
|
21
|
+
if ((0, _platecommon.isEditorReadOnly)(editor) || (0, _platecommon.isComposing)(editor) || !(0, _platecommon.hasEditorEditableTarget)(editor, event.target) || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.key !== 'ArrowUp' && event.key !== 'ArrowDown') {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const nativeSelection = (0, _platecommon.getEditorWindow)(editor)?.getSelection();
|
|
25
|
+
if (!nativeSelection?.isCollapsed || typeof nativeSelection.modify !== 'function') {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const before = (0, _platecommon.toSlateRange)(editor, nativeSelection, {
|
|
29
|
+
exactMatch: true,
|
|
30
|
+
suppressThrow: true
|
|
31
|
+
});
|
|
32
|
+
if (!before) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
nativeSelection.modify('move', event.key === 'ArrowUp' ? 'backward' : 'forward', 'line');
|
|
36
|
+
const range = (0, _platecommon.toSlateRange)(editor, nativeSelection, {
|
|
37
|
+
exactMatch: true,
|
|
38
|
+
suppressThrow: true
|
|
39
|
+
});
|
|
40
|
+
if (!range) {
|
|
41
|
+
const previous = (0, _platecommon.toDOMRange)(editor, before);
|
|
42
|
+
if (previous) {
|
|
43
|
+
nativeSelection.setBaseAndExtent(previous.startContainer, previous.startOffset, previous.endContainer, previous.endOffset);
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
(0, _transforms.select)(editor, range);
|
|
49
|
+
return true;
|
|
50
|
+
},
|
|
51
|
+
onMouseUp: (editor)=>(event)=>{
|
|
52
|
+
if (!(0, _platecommon.isEditorReadOnly)(editor) && !(0, _platecommon.isComposing)(editor) && (0, _platecommon.hasEditorEditableTarget)(editor, event.target) && event.button === 0) {
|
|
53
|
+
const nativeSelection = (0, _platecommon.getEditorWindow)(editor)?.getSelection();
|
|
54
|
+
if (nativeSelection?.isCollapsed) {
|
|
55
|
+
const range = (0, _platecommon.toSlateRange)(editor, nativeSelection, {
|
|
56
|
+
exactMatch: true,
|
|
57
|
+
suppressThrow: true
|
|
58
|
+
});
|
|
59
|
+
if (range && (!editor.selection || !_slate.Range.equals(range, editor.selection))) {
|
|
60
|
+
(0, _transforms.select)(editor, range);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
19
64
|
if (!editor.selection) {
|
|
20
65
|
return;
|
|
21
66
|
}
|
|
@@ -1,11 +1,56 @@
|
|
|
1
1
|
import { BLOCKS, TEXT_CONTAINERS } from '@contentful/rich-text-types';
|
|
2
|
+
import { getEditorWindow, hasEditorEditableTarget, isComposing, isEditorReadOnly, toDOMRange, toSlateRange } from '@udecode/plate-common';
|
|
3
|
+
import { Range } from 'slate';
|
|
2
4
|
import { getAboveNode, isAncestorEmpty, getNodeEntries, getPointBefore, isInline, isEndPoint, getPointAfter, isRangeCollapsed, queryNode, isText } from '../../internal/queries';
|
|
3
5
|
import { setSelection, select, removeNodes, splitNodes, unhangRange, unsetNodes } from '../../internal/transforms';
|
|
4
6
|
export function createTextPlugin(restrictedMarks = []) {
|
|
5
7
|
return {
|
|
6
8
|
key: 'TextPlugin',
|
|
7
9
|
handlers: {
|
|
8
|
-
|
|
10
|
+
onKeyDown: (editor)=>(event)=>{
|
|
11
|
+
if (isEditorReadOnly(editor) || isComposing(editor) || !hasEditorEditableTarget(editor, event.target) || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.key !== 'ArrowUp' && event.key !== 'ArrowDown') {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const nativeSelection = getEditorWindow(editor)?.getSelection();
|
|
15
|
+
if (!nativeSelection?.isCollapsed || typeof nativeSelection.modify !== 'function') {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const before = toSlateRange(editor, nativeSelection, {
|
|
19
|
+
exactMatch: true,
|
|
20
|
+
suppressThrow: true
|
|
21
|
+
});
|
|
22
|
+
if (!before) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
nativeSelection.modify('move', event.key === 'ArrowUp' ? 'backward' : 'forward', 'line');
|
|
26
|
+
const range = toSlateRange(editor, nativeSelection, {
|
|
27
|
+
exactMatch: true,
|
|
28
|
+
suppressThrow: true
|
|
29
|
+
});
|
|
30
|
+
if (!range) {
|
|
31
|
+
const previous = toDOMRange(editor, before);
|
|
32
|
+
if (previous) {
|
|
33
|
+
nativeSelection.setBaseAndExtent(previous.startContainer, previous.startOffset, previous.endContainer, previous.endOffset);
|
|
34
|
+
}
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
event.preventDefault();
|
|
38
|
+
select(editor, range);
|
|
39
|
+
return true;
|
|
40
|
+
},
|
|
41
|
+
onMouseUp: (editor)=>(event)=>{
|
|
42
|
+
if (!isEditorReadOnly(editor) && !isComposing(editor) && hasEditorEditableTarget(editor, event.target) && event.button === 0) {
|
|
43
|
+
const nativeSelection = getEditorWindow(editor)?.getSelection();
|
|
44
|
+
if (nativeSelection?.isCollapsed) {
|
|
45
|
+
const range = toSlateRange(editor, nativeSelection, {
|
|
46
|
+
exactMatch: true,
|
|
47
|
+
suppressThrow: true
|
|
48
|
+
});
|
|
49
|
+
if (range && (!editor.selection || !Range.equals(range, editor.selection))) {
|
|
50
|
+
select(editor, range);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
9
54
|
if (!editor.selection) {
|
|
10
55
|
return;
|
|
11
56
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-rich-text",
|
|
3
|
-
"version": "6.4.
|
|
3
|
+
"version": "6.4.5-canary.0+28597084",
|
|
4
4
|
"source": "./src/index.tsx",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -94,5 +94,5 @@
|
|
|
94
94
|
"publishConfig": {
|
|
95
95
|
"registry": "https://npm.pkg.github.com/"
|
|
96
96
|
},
|
|
97
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "2859708405ab4c804e476a86101098495c2e5bac"
|
|
98
98
|
}
|