lexical-vue
Version:
An extensible Vue 3 web text-editor based on Lexical.
11 lines (10 loc) • 511 B
JavaScript
import { createEmptyHistoryState, registerHistory } from "@lexical/history";
import { computed, toValue, watchEffect } from "vue";
function useHistory(editor, externalHistoryState, delay) {
const historyState = computed(()=>toValue(externalHistoryState) || createEmptyHistoryState());
watchEffect((onInvalidate)=>{
const unregisterListener = registerHistory(toValue(editor), historyState.value, toValue(delay) || 1000);
onInvalidate(unregisterListener);
});
}
export { useHistory };