UNPKG

@wordpress/editor

Version:
53 lines (52 loc) 1.73 kB
// packages/editor/src/dataviews/fields/revisions/revisions-view.tsx import { Button } from "@wordpress/components"; import { useDispatch, useSelect } from "@wordpress/data"; import { _n, sprintf } from "@wordpress/i18n"; import { addQueryArgs } from "@wordpress/url"; import { store as editorStore } from "../../../store/index.mjs"; import { unlock } from "../../../lock-unlock.mjs"; import { jsx } from "react/jsx-runtime"; function RevisionsView() { const { lastRevisionId, revisionsCount, disableVisualRevisions } = useSelect((select) => { const { getCurrentPostLastRevisionId, getCurrentPostRevisionsCount, getEditorSettings } = select(editorStore); return { lastRevisionId: getCurrentPostLastRevisionId(), revisionsCount: getCurrentPostRevisionsCount(), disableVisualRevisions: ( // @ts-expect-error Editor settings are typed as a bare `Object`. !!getEditorSettings().disableVisualRevisions ) }; }, []); const { setCurrentRevisionId } = unlock(useDispatch(editorStore)); const buttonProps = disableVisualRevisions ? { href: addQueryArgs("revision.php", { revision: lastRevisionId }) } : { onClick: () => setCurrentRevisionId(lastRevisionId) }; return /* @__PURE__ */ jsx( Button, { ...buttonProps, variant: "link", text: String(revisionsCount), "aria-label": sprintf( /* translators: %d: number of revisions. */ _n( "Open revisions screen: %d revision", "Open revisions screen: %d revisions", revisionsCount ), revisionsCount ) } ); } export { RevisionsView as default }; //# sourceMappingURL=revisions-view.mjs.map