@lexical/react
Version:
This package provides Lexical components and hooks for React applications.
10 lines (8 loc) • 2 kB
JavaScript
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{useLexicalNodeSelection as t}from"@lexical/react/useLexicalNodeSelection";import{addClassNamesToElement as r,mergeRegister as n,removeClassNamesFromElement as o}from"@lexical/utils";import{createCommand as i,DecoratorNode as c,$applyNodeReplacement as u,$getSelection as m,$isNodeSelection as a,CLICK_COMMAND as l,COMMAND_PRIORITY_LOW as s,KEY_DELETE_COMMAND as p,KEY_BACKSPACE_COMMAND as d}from"lexical";import{useCallback as f,useEffect as x}from"react";import{jsx as y}from"react/jsx-runtime";const h=i("INSERT_HORIZONTAL_RULE_COMMAND");function g({nodeKey:i}){const[c]=e(),[u,y,h]=t(i),g=f((e=>{const t=m();return u&&a(t)&&(e.preventDefault(),c.update((()=>{t.getNodes().forEach((e=>{N(e)&&e.remove()}))}))),!1}),[c,u]);return x((()=>n(c.registerCommand(l,(e=>{const t=c.getElementByKey(i);return e.target===t&&(e.shiftKey||h(),y(!u),!0)}),s),c.registerCommand(p,g,s),c.registerCommand(d,g,s))),[h,c,u,i,g,y]),x((()=>{const e=c.getElementByKey(i),t="selected";null!==e&&(u?r(e,t):o(e,t))}),[c,u,i]),null}class O extends c{static getType(){return"horizontalrule"}static clone(e){return new O(e.__key)}static importJSON(e){return E()}static importDOM(){return{hr:()=>({conversion:C,priority:0})}}exportJSON(){return{type:"horizontalrule",version:1}}exportDOM(){return{element:document.createElement("hr")}}createDOM(e){const t=document.createElement("hr");return r(t,e.theme.hr),t}getTextContent(){return"\n"}isInline(){return!1}updateDOM(){return!1}decorate(){return y(g,{nodeKey:this.__key})}}function C(){return{node:E()}}function E(){return u(new O)}function N(e){return e instanceof O}export{E as $createHorizontalRuleNode,N as $isHorizontalRuleNode,O as HorizontalRuleNode,h as INSERT_HORIZONTAL_RULE_COMMAND};