UNPKG

@lexical/react

Version:

This package provides Lexical components and hooks for React applications.

10 lines (8 loc) • 741 B
/** * 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{CAN_USE_DOM as t,HISTORY_MERGE_TAG as r}from"lexical";import{useLayoutEffect as i,useEffect as o}from"react";const n=t?i:o;function a({ignoreHistoryMergeTagChange:t=!0,ignoreSelectionChange:i=!1,onChange:o}){const[a]=e();return n(()=>{if(o)return a.registerUpdateListener(({editorState:e,dirtyElements:n,dirtyLeaves:s,prevEditorState:c,tags:g})=>{i&&0===n.size&&0===s.size||t&&g.has(r)||c.isEmpty()||o(e,a,g)})},[a,t,i,o]),null}export{a as OnChangePlugin};