UNPKG

lexical-vue

Version:

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

33 lines (32 loc) 1.44 kB
import { defineComponent, onMounted, onUnmounted } from "vue"; import { $createHorizontalRuleNode, INSERT_HORIZONTAL_RULE_COMMAND } from "@lexical/extension"; import { $insertNodeToNearestRoot } from "@lexical/utils"; import { $getSelection, $isRangeSelection, COMMAND_PRIORITY_EDITOR } from "lexical"; import { useLexicalComposer } from "./LexicalComposer.vine.js"; const HorizontalRulePlugin = (()=>{ const __vine = defineComponent({ name: 'HorizontalRulePlugin', setup (__props, param) { let { expose: __expose } = param; __expose(); const editor = useLexicalComposer(); onMounted(()=>{ const unregister = editor.registerCommand(INSERT_HORIZONTAL_RULE_COMMAND, ()=>{ const selection = $getSelection(); if (!$isRangeSelection(selection)) return false; const focusNode = selection.focus.getNode(); if (null !== focusNode) { const horizontalRuleNode = $createHorizontalRuleNode(); $insertNodeToNearestRoot(horizontalRuleNode); } return true; }, COMMAND_PRIORITY_EDITOR); onUnmounted(unregister); }); return (_ctx, _cache)=>null; } }); __vine.__vue_vine = true; return __vine; })(); export { HorizontalRulePlugin };