/**
 * 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{$isDecoratorBlockNode as t}from"@lexical/react/LexicalDecoratorBlockNode";import{useLexicalNodeSelection as r}from"@lexical/react/useLexicalNodeSelection";import{mergeRegister as o,$getNearestBlockElementAncestorOrThrow as i}from"@lexical/utils";import{FORMAT_ELEMENT_COMMAND as l,$getSelection as a,$isNodeSelection as c,$getNodeByKey as m,$isRangeSelection as n,COMMAND_PRIORITY_LOW as s,CLICK_COMMAND as f}from"lexical";import{useRef as u,useEffect as x}from"react";import{jsx as d}from"react/jsx-runtime";function p({children:p,format:g,nodeKey:N,className:C}){const[h]=e(),[v,y,F]=r(N),L=u(null);return x(()=>o(h.registerCommand(l,e=>{if(v){const r=a();if(c(r)){const r=m(N);t(r)&&r.setFormat(e)}else if(n(r)){const o=r.getNodes();for(const r of o)if(t(r))r.setFormat(e);else{i(r).setFormat(e)}}return!0}return!1},s),h.registerCommand(f,e=>e.target===L.current&&(e.preventDefault(),e.shiftKey||F(),y(!v),!0),s)),[F,h,v,N,y]),d("div",{className:[C.base,v?C.focus:null].filter(Boolean).join(" "),ref:L,style:{textAlign:g||void 0},children:p})}export{p as BlockWithAlignableContents};
