fix: super improvements (#1995)

* feat(super): autolink selection with cmd + k

* feat: super note importer

* feat: handle html import

* fix: ignore load change event emitted by on change plugin
This commit is contained in:
Mo
2022-11-11 12:24:46 -06:00
committed by GitHub
parent 731e9df1af
commit da6f36f34c
18 changed files with 294 additions and 51 deletions

View File

@@ -36,7 +36,7 @@ const BlockDragEnabled = false;
type BlocksEditorProps = {
onChange: (value: string, preview: string) => void;
className?: string;
children: React.ReactNode;
children?: React.ReactNode;
previewLength: number;
spellcheck?: boolean;
};
@@ -48,8 +48,14 @@ export const BlocksEditor: FunctionComponent<BlocksEditorProps> = ({
previewLength,
spellcheck,
}) => {
const [didIgnoreFirstChange, setDidIgnoreFirstChange] = useState(false);
const handleChange = useCallback(
(editorState: EditorState, _editor: LexicalEditor) => {
if (!didIgnoreFirstChange) {
setDidIgnoreFirstChange(true);
return;
}
editorState.read(() => {
const childrenNodes = $getRoot().getAllTextNodes().slice(0, 2);
let previewText = '';
@@ -65,7 +71,7 @@ export const BlocksEditor: FunctionComponent<BlocksEditorProps> = ({
onChange(stringifiedEditorState, previewText);
});
},
[onChange],
[onChange, didIgnoreFirstChange],
);
const [floatingAnchorElem, setFloatingAnchorElem] =

View File

@@ -7,17 +7,19 @@ import {Klass, LexicalNode} from 'lexical';
type BlocksEditorComposerProps = {
initialValue: string;
children: React.ReactNode;
nodes: Array<Klass<LexicalNode>>;
nodes?: Array<Klass<LexicalNode>>;
readonly?: boolean;
};
export const BlocksEditorComposer: FunctionComponent<
BlocksEditorComposerProps
> = ({initialValue, children, nodes}) => {
> = ({initialValue, children, readonly, nodes = []}) => {
return (
<LexicalComposer
initialConfig={{
namespace: 'BlocksEditor',
theme: BlocksEditorTheme,
editable: !readonly,
onError: (error: Error) => console.error(error),
editorState:
initialValue && initialValue.length > 0 ? initialValue : undefined,