UNPKG

@wordpress/block-library

Version:
102 lines (101 loc) • 3.97 kB
import { __ } from "@wordpress/i18n"; import { RangeControl, ToggleControl, __experimentalToolsPanel, __experimentalToolsPanelItem } from "@wordpress/components"; import { InspectorControls } from "@wordpress/block-editor"; import { SelectControl } from "@wordpress/ui"; import { MAX_PREVIEW_HEIGHT, MIN_PREVIEW_HEIGHT } from "./edit.mjs"; import { useToolsPanelDropdownMenuProps } from "../utils/hooks.mjs"; import { Fragment, jsx, jsxs } from "react/jsx-runtime"; // packages/block-library/src/file/inspector.jsx function FileBlockInspector({ hrefs, openInNewWindow, showDownloadButton, changeLinkDestinationOption, changeOpenInNewWindow, changeShowDownloadButton, displayPreview, changeDisplayPreview, previewHeight, changePreviewHeight }) { const { href, textLinkHref, attachmentPage } = hrefs; const dropdownMenuProps = useToolsPanelDropdownMenuProps(); let linkDestinationItems = [{ value: href, label: __("URL") }]; if (attachmentPage) linkDestinationItems = [{ value: href, label: __("Media file") }, { value: attachmentPage, label: __("Attachment page") }]; return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(InspectorControls, { children: [href.endsWith(".pdf") && /* @__PURE__ */ jsxs(__experimentalToolsPanel, { label: __("PDF settings"), resetAll: () => { changeDisplayPreview(true); changePreviewHeight(600); }, dropdownMenuProps, children: [/* @__PURE__ */ jsx(__experimentalToolsPanelItem, { label: __("Show inline embed"), isShownByDefault: true, hasValue: () => !displayPreview, onDeselect: () => changeDisplayPreview(true), children: /* @__PURE__ */ jsx(ToggleControl, { label: __("Show inline embed"), help: displayPreview ? __("Note: Most phone and tablet browsers won't display embedded PDFs.") : null, checked: !!displayPreview, onChange: changeDisplayPreview }) }), displayPreview && /* @__PURE__ */ jsx(__experimentalToolsPanelItem, { label: __("Height in pixels"), isShownByDefault: true, hasValue: () => previewHeight !== 600, onDeselect: () => changePreviewHeight(600), children: /* @__PURE__ */ jsx(RangeControl, { label: __("Height in pixels"), min: MIN_PREVIEW_HEIGHT, max: Math.max(MAX_PREVIEW_HEIGHT, previewHeight), value: previewHeight, onChange: changePreviewHeight }) })] }), /* @__PURE__ */ jsxs(__experimentalToolsPanel, { label: __("Settings"), resetAll: () => { changeLinkDestinationOption(href); changeOpenInNewWindow(false); changeShowDownloadButton(true); }, dropdownMenuProps, children: [ /* @__PURE__ */ jsx(__experimentalToolsPanelItem, { label: __("Link to"), isShownByDefault: true, hasValue: () => textLinkHref !== href, onDeselect: () => changeLinkDestinationOption(href), children: /* @__PURE__ */ jsx(SelectControl, { label: __("Link to"), value: linkDestinationItems.find((item) => item.value === textLinkHref) ?? linkDestinationItems[0], items: linkDestinationItems, onValueChange: (item) => item && changeLinkDestinationOption(item.value) }) }), /* @__PURE__ */ jsx(__experimentalToolsPanelItem, { label: __("Open in new tab"), isShownByDefault: true, hasValue: () => !!openInNewWindow, onDeselect: () => changeOpenInNewWindow(false), children: /* @__PURE__ */ jsx(ToggleControl, { label: __("Open in new tab"), checked: openInNewWindow, onChange: changeOpenInNewWindow }) }), /* @__PURE__ */ jsx(__experimentalToolsPanelItem, { label: __("Show download button"), isShownByDefault: true, hasValue: () => !showDownloadButton, onDeselect: () => changeShowDownloadButton(true), children: /* @__PURE__ */ jsx(ToggleControl, { label: __("Show download button"), checked: showDownloadButton, onChange: changeShowDownloadButton }) }) ] })] }) }); } export { FileBlockInspector as default }; //# sourceMappingURL=inspector.mjs.map