UNPKG

@wordpress/block-editor

Version:
72 lines (71 loc) 2.22 kB
// packages/block-editor/src/components/block-quick-navigation/index.js import { useSelect, useDispatch } from "@wordpress/data"; import { Button, __experimentalVStack as VStack, __experimentalTruncate as Truncate, Flex, FlexBlock, FlexItem } from "@wordpress/components"; import { store as blockEditorStore } from "../../store"; import BlockIcon from "../block-icon"; import useBlockDisplayInformation from "../use-block-display-information"; import useBlockDisplayTitle from "../block-title/use-block-display-title"; import { jsx, jsxs } from "react/jsx-runtime"; function BlockQuickNavigation({ clientIds, onSelect }) { if (!clientIds.length) { return null; } return /* @__PURE__ */ jsx(VStack, { spacing: 1, children: clientIds.map((clientId) => /* @__PURE__ */ jsx( BlockQuickNavigationItem, { onSelect, clientId }, clientId )) }); } function BlockQuickNavigationItem({ clientId, onSelect }) { const blockInformation = useBlockDisplayInformation(clientId); const blockTitle = useBlockDisplayTitle({ clientId, context: "list-view" }); const { isSelected } = useSelect( (select) => { const { isBlockSelected, hasSelectedInnerBlock } = select(blockEditorStore); return { isSelected: isBlockSelected(clientId) || hasSelectedInnerBlock( clientId, /* deep: */ true ) }; }, [clientId] ); const { selectBlock } = useDispatch(blockEditorStore); return /* @__PURE__ */ jsx( Button, { __next40pxDefaultSize: true, className: "block-editor-block-quick-navigation__item", isPressed: isSelected, onClick: async () => { await selectBlock(clientId); if (onSelect) { onSelect(clientId); } }, children: /* @__PURE__ */ jsxs(Flex, { children: [ /* @__PURE__ */ jsx(FlexItem, { children: /* @__PURE__ */ jsx(BlockIcon, { icon: blockInformation?.icon }) }), /* @__PURE__ */ jsx(FlexBlock, { style: { textAlign: "left" }, children: /* @__PURE__ */ jsx(Truncate, { children: blockTitle }) }) ] }) } ); } export { BlockQuickNavigation as default }; //# sourceMappingURL=index.js.map