Skip to content

Commit bcd8f04

Browse files
committed
feat(richtext): use own querynode
1 parent 3c5c3e6 commit bcd8f04

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

packages/decap-cms-widget-richtext/src/RichtextControl/VisualEditor.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import ListElement from './components/Element/ListElement';
3838
import { markdownToSlate, slateToMarkdown } from '../serializers';
3939
import LinkElement from './components/Element/LinkElement';
4040
import BlockquoteElement from './components/Element/BlockquoteElement';
41-
import createBlockquoteExtPlugin from './plugins/createBlockquoteExitBreak';
41+
import createBlockquoteExtPlugin from './plugins/createBlockquoteExtPlugin';
4242

4343
function visualEditorStyles({ minimal }) {
4444
return `
@@ -64,7 +64,6 @@ const emptyValue = [
6464
];
6565

6666
export default function VisualEditor({ t, field, className, isDisabled, onChange, ...props }) {
67-
console.log('plff', createBlockquotePlugin())
6867
const plugins = createPlugins(
6968
[
7069
createParagraphPlugin(),
Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
isAncestorEmpty,
66
unwrapNodes,
77
isFirstChild,
8+
isSelectionAtBlockStart,
89
} from '@udecode/plate-common';
910
import { ELEMENT_BLOCKQUOTE } from '@udecode/plate-block-quote';
1011

@@ -15,6 +16,14 @@ function isWithinBlockquote(editor, entry) {
1516
return blockAbove?.[0]?.type === ELEMENT_BLOCKQUOTE;
1617
}
1718

19+
function queryNode(editor, entry, { empty, first, start }) {
20+
return (
21+
(!empty || isAncestorEmpty(editor, entry[0])) &&
22+
(!first || isFirstChild(entry[1])) &&
23+
(!start || isSelectionAtBlockStart(editor))
24+
);
25+
}
26+
1827
function unwrap(editor) {
1928
unwrapNodes(editor, { split: true, match: n => n.type === ELEMENT_BLOCKQUOTE });
2029
return true;
@@ -27,12 +36,11 @@ function onKeyDownBlockquoteExitBreak(editor, { options: { rules } }) {
2736
const entry = getBlockAbove(editor);
2837
if (!entry) return;
2938

30-
rules.forEach(({ hotkey, isFirstParagraph }) => {
39+
rules.forEach(({ hotkey, query }) => {
3140
if (
3241
isHotkey(hotkey, event) &&
33-
isAncestorEmpty(editor, entry[0]) &&
3442
isWithinBlockquote(editor, entry) &&
35-
(!isFirstParagraph || isFirstChild(entry[1])) &&
43+
queryNode(editor, entry, query) &&
3644
unwrap(editor)
3745
) {
3846
event.preventDefault();
@@ -48,7 +56,10 @@ const createBlockquoteExtPlugin = createPluginFactory({
4856
onKeyDown: onKeyDownBlockquoteExitBreak,
4957
},
5058
options: {
51-
rules: [{ hotkey: 'enter' }, { hotkey: 'backspace', isFirstParagraph: true }],
59+
rules: [
60+
{ hotkey: 'enter', query: { empty: true } },
61+
{ hotkey: 'backspace', query: { first: true, start: true } },
62+
],
5263
},
5364
});
5465

0 commit comments

Comments
 (0)