Fixes: Allow BlockInsert on final block (previously didnt work in Prod)
This commit is contained in:
@ -22,6 +22,8 @@ function findClosestRootNode(value, ev) {
|
|||||||
if (bounds.top > ev.clientY) return previous;
|
if (bounds.top > ev.clientY) return previous;
|
||||||
previous = { node, element, bounds };
|
previous = { node, element, bounds };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return previous;
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
@ -100,10 +102,21 @@ export default class BlockInsert extends Component {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
change
|
change.collapseToStartOf(this.closestRootNode);
|
||||||
.collapseToStartOf(this.closestRootNode)
|
|
||||||
.collapseToEndOfPreviousBlock()
|
// if we're on an empty paragraph then just replace it with the block
|
||||||
.insertBlock({ type: 'block-toolbar', isVoid: true });
|
// toolbar. Otherwise insert the toolbar as an extra Node.
|
||||||
|
if (
|
||||||
|
!this.closestRootNode.text &&
|
||||||
|
this.closestRootNode.type === 'paragraph'
|
||||||
|
) {
|
||||||
|
change.setNodeByKey(this.closestRootNode.key, {
|
||||||
|
type: 'block-toolbar',
|
||||||
|
isVoid: true,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
change.insertBlock({ type: 'block-toolbar', isVoid: true });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
// @flow
|
|
||||||
import ClickablePadding from './ClickablePadding';
|
|
||||||
export default ClickablePadding;
|
|
@ -72,7 +72,7 @@ class BlockToolbar extends Component {
|
|||||||
|
|
||||||
editor.value.document.nodes.forEach(node => {
|
editor.value.document.nodes.forEach(node => {
|
||||||
if (node.type === 'block-toolbar') {
|
if (node.type === 'block-toolbar') {
|
||||||
change.removeNodeByKey(node.key);
|
change.removeNodeByKey(node.key, undefined, { normalize: false });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import InlineCode from './components/InlineCode';
|
import Code from './components/InlineCode';
|
||||||
import { Mark } from 'slate';
|
import { Mark } from 'slate';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@ -13,7 +13,7 @@ export default function renderMark(props: Props) {
|
|||||||
case 'bold':
|
case 'bold':
|
||||||
return <strong>{props.children}</strong>;
|
return <strong>{props.children}</strong>;
|
||||||
case 'code':
|
case 'code':
|
||||||
return <InlineCode>{props.children}</InlineCode>;
|
return <Code>{props.children}</Code>;
|
||||||
case 'italic':
|
case 'italic':
|
||||||
return <em>{props.children}</em>;
|
return <em>{props.children}</em>;
|
||||||
case 'underlined':
|
case 'underlined':
|
||||||
|
@ -24,7 +24,7 @@ const createPlugins = ({ onImageUploadStart, onImageUploadStop }: Options) => {
|
|||||||
collapseTo: 'end',
|
collapseTo: 'end',
|
||||||
}),
|
}),
|
||||||
InsertImages({
|
InsertImages({
|
||||||
extensions: ['png', 'jpg', 'gif'],
|
extensions: ['png', 'jpg', 'gif', 'webp'],
|
||||||
insertImage: (change, file) => {
|
insertImage: (change, file) => {
|
||||||
return change.call(
|
return change.call(
|
||||||
insertImageFile,
|
insertImageFile,
|
||||||
|
@ -131,12 +131,15 @@ export default function MarkdownShortcuts() {
|
|||||||
return change
|
return change
|
||||||
.extendToStartOf(startBlock)
|
.extendToStartOf(startBlock)
|
||||||
.delete()
|
.delete()
|
||||||
.setBlock({
|
.setBlock(
|
||||||
|
{
|
||||||
type: 'horizontal-rule',
|
type: 'horizontal-rule',
|
||||||
isVoid: true,
|
isVoid: true,
|
||||||
})
|
},
|
||||||
.collapseToStartOfNextBlock()
|
{ normalize: false }
|
||||||
.insertBlock('paragraph');
|
)
|
||||||
|
.insertBlock('paragraph')
|
||||||
|
.collapseToStart();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user