UNPKG

@lexical/react

Version:

This package provides Lexical components and hooks for React applications.

11 lines (9 loc) • 1.42 kB
/** * 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{HorizontalRuleNode as e}from"@lexical/extension/HorizontalRuleExtension";export{$isHorizontalRuleNode,INSERT_HORIZONTAL_RULE_COMMAND}from"@lexical/extension/HorizontalRuleExtension";import{useLexicalComposerContext as o}from"@lexical/react/LexicalComposerContext";import{useLexicalNodeSelection as t}from"@lexical/react/useLexicalNodeSelection";import{$applyNodeReplacement as r,mergeRegister as n,CLICK_COMMAND as i,getComposedEventTarget as l,COMMAND_PRIORITY_LOW as c,addClassNamesToElement as s,removeClassNamesFromElement as m}from"lexical";import{useEffect as a}from"react";import{jsx as u}from"react/jsx-runtime";function x({nodeKey:e}){const[r]=o(),[u,x,f]=t(e);return a(()=>n(r.registerCommand(i,o=>{const t=r.getElementByKey(e);return l(o)===t&&(o.shiftKey||f(),x(!u),!0)},c)),[f,r,u,e,x]),a(()=>{const o=r.getElementByKey(e),t=r._config.theme.hrSelected??"selected";null!==o&&(u?s(o,t):m(o,t))},[r,u,e]),null}class f extends e{$config(){return this.config("horizontalrule",{extends:e,importDOM:{hr:()=>({conversion:d,priority:0})}})}decorate(){ return u(x,{nodeKey:this.__key})}}function d(){return{node:p()}}function p(){return r(new f)}export{p as $createHorizontalRuleNode,f as HorizontalRuleNode};