UNPKG

@lexical/react

Version:

This package provides Lexical components and hooks for React applications.

11 lines (9 loc) • 1.44 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{useLexicalCommandsLog as e,TreeView as t,generateContent as a}from"@lexical/devtools-core";import{CAN_USE_DOM as r,mergeRegister as l}from"lexical";import*as o from"react";import{useLayoutEffect as i,useEffect as s,useState as n}from"react";import{jsx as m}from"react/jsx-runtime";const c=r?i:s;function d({treeTypeButtonClassName:r,timeTravelButtonClassName:i,timeTravelPanelSliderClassName:d,timeTravelPanelButtonClassName:u,timeTravelPanelClassName:C,viewClassName:N,editor:f,customPrintNode:v}){const E=/*#__PURE__*/o.createRef(),[T,p]=n(f.getEditorState()),S=e(f);c(()=>(p(f.getEditorState()),l(f.registerUpdateListener(({editorState:e})=>{p(e)}),f.registerEditableListener(()=>{p(f.getEditorState())}))),[f]),s(()=>{const e=E.current;if(null!==e)return e.__lexicalEditor=f,()=>{e.__lexicalEditor=null}},[f,E]); return m(t,{treeTypeButtonClassName:r,timeTravelButtonClassName:i,timeTravelPanelSliderClassName:d,timeTravelPanelButtonClassName:u,viewClassName:N,timeTravelPanelClassName:C,setEditorReadOnly:e=>{const t=f.getRootElement();null!=t&&(t.contentEditable=e?"false":"true")},editorState:T,setEditorState:e=>f.setEditorState(e),generateContent:async function(e){return a(f,S,e,v)},ref:E,commandsLog:S})}export{d as TreeView};