Files
klz-cables.com/.pnpm-store/v10/files/b5/f56244dc116dacecef0d371d273eddd75db6eaee41bfdcb8c7b82b5d75588e0a990494aa698b0906daf7703c52eb0fcef8ed920f3c35284af3c3f94ff25ec3
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

80 lines
2.6 KiB
Plaintext

/**
* 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 } from '@lexical/react/LexicalComposerContext';
import { $isDecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode';
import { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection';
import { mergeRegister, $getNearestBlockElementAncestorOrThrow } from '@lexical/utils';
import { FORMAT_ELEMENT_COMMAND, $getSelection, $isNodeSelection, $getNodeByKey, $isRangeSelection, COMMAND_PRIORITY_LOW, CLICK_COMMAND } from 'lexical';
import { useRef, useEffect } from 'react';
import { jsx } from 'react/jsx-runtime';
/**
* 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.
*
*/
function BlockWithAlignableContents({
children,
format,
nodeKey,
className
}) {
const [editor] = useLexicalComposerContext();
const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey);
const ref = useRef(null);
useEffect(() => {
return mergeRegister(editor.registerCommand(FORMAT_ELEMENT_COMMAND, formatType => {
if (isSelected) {
const selection = $getSelection();
if ($isNodeSelection(selection)) {
const node = $getNodeByKey(nodeKey);
if ($isDecoratorBlockNode(node)) {
node.setFormat(formatType);
}
} else if ($isRangeSelection(selection)) {
const nodes = selection.getNodes();
for (const node of nodes) {
if ($isDecoratorBlockNode(node)) {
node.setFormat(formatType);
} else {
const element = $getNearestBlockElementAncestorOrThrow(node);
element.setFormat(formatType);
}
}
}
return true;
}
return false;
}, COMMAND_PRIORITY_LOW), editor.registerCommand(CLICK_COMMAND, event => {
if (event.target === ref.current) {
event.preventDefault();
if (!event.shiftKey) {
clearSelection();
}
setSelected(!isSelected);
return true;
}
return false;
}, COMMAND_PRIORITY_LOW));
}, [clearSelection, editor, isSelected, nodeKey, setSelected]);
return /*#__PURE__*/jsx("div", {
className: [className.base, isSelected ? className.focus : null].filter(Boolean).join(' '),
ref: ref,
style: {
textAlign: format ? format : undefined
},
children: children
});
}
export { BlockWithAlignableContents };