UNPKG

lexical-vue

Version:

An extensible Vue 3 web text-editor based on Lexical.

28 lines (27 loc) 1.17 kB
import { $canShowPlaceholderCurry } from "@lexical/text"; import { mergeRegister } from "@lexical/utils"; import { onMounted, onUnmounted, readonly, ref } from "vue"; function canShowPlaceholderFromCurrentEditorState(editor) { const currentCanShowPlaceholder = editor.getEditorState().read($canShowPlaceholderCurry(editor.isComposing())); return currentCanShowPlaceholder; } function useCanShowPlaceholder(editor) { const initialState = editor.getEditorState().read($canShowPlaceholderCurry(editor.isComposing())); const canShowPlaceholder = ref(initialState); function resetCanShowPlaceholder() { const currentCanShowPlaceholder = canShowPlaceholderFromCurrentEditorState(editor); canShowPlaceholder.value = currentCanShowPlaceholder; } onMounted(()=>{ const unregister = mergeRegister(editor.registerUpdateListener(()=>{ resetCanShowPlaceholder(); }), editor.registerEditableListener(()=>{ resetCanShowPlaceholder(); })); onUnmounted(()=>{ unregister(); }); }); return readonly(canShowPlaceholder); } export { useCanShowPlaceholder };