@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) • 772 B
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@lexical/react/LexicalComposerContext"),t=require("lexical"),r=require("react"),o=require("@lexical/utils");exports.HighlightPlugin=({highlight:i,initialData:a})=>{const[s]=e.useLexicalComposerContext(),l=r.useRef(!0);return r.useEffect((()=>{i&&a.toLowerCase().indexOf(i.toLowerCase())>-1?(l.current||s.setEditorState(s.parseEditorState(a)),s.update((()=>{o.$dfs().forEach((e=>{if(t.$isTextNode(e.node)&&"text"===e.node.getType()){const r=e.node.getTextContent().toLocaleLowerCase().indexOf(i.toLocaleLowerCase());r>-1&&(e.node.select(r,r+i.length),s.dispatchCommand(t.FORMAT_TEXT_COMMAND,"bold"))}}))}))):l.current||s.setEditorState(s.parseEditorState(a)),l.current=!1}),[s,i,a]),null};