lexical-vue
Version:
An extensible Vue 3 web text-editor based on Lexical.
15 lines (14 loc) • 708 B
JavaScript
import { $isRootTextContentEmptyCurry } from "@lexical/text";
import { readonly, shallowRef, toValue, watchEffect } from "vue";
function useLexicalIsTextContentEmpty(editor, trim) {
const isEmpty = shallowRef(editor.getEditorState().read($isRootTextContentEmptyCurry(editor.isComposing(), toValue(trim))));
watchEffect((onInvalidate)=>{
const unregister = editor.registerUpdateListener(({ editorState })=>{
const isComposing = editor.isComposing();
isEmpty.value = editorState.read($isRootTextContentEmptyCurry(isComposing, toValue(trim)));
});
onInvalidate(unregister);
});
return readonly(isEmpty);
}
export { useLexicalIsTextContentEmpty };