@nexusui/components
Version:
These are custom components specially-developed for NexusUI applications. They will make your life easier by giving you out-of-the-box implementations for various high-level UI elements that you can drop directly into your application.
2 lines (1 loc) • 743 B
JavaScript
import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{$isTextNode as e,FORMAT_TEXT_COMMAND as o}from"lexical";import{useRef as r,useEffect as a}from"react";import{$dfs as i}from"@lexical/utils";const n=({highlight:n,initialData:c})=>{const[l]=t(),s=r(!0);return a((()=>{n&&c.toLowerCase().indexOf(n.toLowerCase())>-1?(s.current||l.setEditorState(l.parseEditorState(c)),l.update((()=>{i().forEach((t=>{if(e(t.node)&&"text"===t.node.getType()){const e=t.node.getTextContent().toLocaleLowerCase().indexOf(n.toLocaleLowerCase());e>-1&&(t.node.select(e,e+n.length),l.dispatchCommand(o,"bold"))}}))}))):s.current||l.setEditorState(l.parseEditorState(c)),s.current=!1}),[l,n,c]),null};export{n as HighlightPlugin};