@wordpress/block-library
Version:
Block library for the WordPress editor.
129 lines (128 loc) • 4.63 kB
JavaScript
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { RangeControl, SelectControl, ToggleControl, __experimentalToolsPanel as ToolsPanel, __experimentalToolsPanelItem as ToolsPanelItem } from '@wordpress/components';
import { InspectorControls } from '@wordpress/block-editor';
/**
* Internal dependencies
*/
import { MIN_PREVIEW_HEIGHT, MAX_PREVIEW_HEIGHT } from './edit';
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
export default function FileBlockInspector({
hrefs,
openInNewWindow,
showDownloadButton,
changeLinkDestinationOption,
changeOpenInNewWindow,
changeShowDownloadButton,
displayPreview,
changeDisplayPreview,
previewHeight,
changePreviewHeight
}) {
const {
href,
textLinkHref,
attachmentPage
} = hrefs;
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
let linkDestinationOptions = [{
value: href,
label: __('URL')
}];
if (attachmentPage) {
linkDestinationOptions = [{
value: href,
label: __('Media file')
}, {
value: attachmentPage,
label: __('Attachment page')
}];
}
return /*#__PURE__*/_jsx(_Fragment, {
children: /*#__PURE__*/_jsxs(InspectorControls, {
children: [href.endsWith('.pdf') && /*#__PURE__*/_jsxs(ToolsPanel, {
label: __('PDF settings'),
resetAll: () => {
changeDisplayPreview(true);
changePreviewHeight(600);
},
dropdownMenuProps: dropdownMenuProps,
children: [/*#__PURE__*/_jsx(ToolsPanelItem, {
label: __('Show inline embed'),
isShownByDefault: true,
hasValue: () => !displayPreview,
onDeselect: () => changeDisplayPreview(true),
children: /*#__PURE__*/_jsx(ToggleControl, {
__nextHasNoMarginBottom: true,
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(ToolsPanelItem, {
label: __('Height in pixels'),
isShownByDefault: true,
hasValue: () => previewHeight !== 600,
onDeselect: () => changePreviewHeight(600),
children: /*#__PURE__*/_jsx(RangeControl, {
__nextHasNoMarginBottom: true,
__next40pxDefaultSize: true,
label: __('Height in pixels'),
min: MIN_PREVIEW_HEIGHT,
max: Math.max(MAX_PREVIEW_HEIGHT, previewHeight),
value: previewHeight,
onChange: changePreviewHeight
})
})]
}), /*#__PURE__*/_jsxs(ToolsPanel, {
label: __('Settings'),
resetAll: () => {
changeLinkDestinationOption(href);
changeOpenInNewWindow(false);
changeShowDownloadButton(true);
},
dropdownMenuProps: dropdownMenuProps,
children: [/*#__PURE__*/_jsx(ToolsPanelItem, {
label: __('Link to'),
isShownByDefault: true,
hasValue: () => textLinkHref !== href,
onDeselect: () => changeLinkDestinationOption(href),
children: /*#__PURE__*/_jsx(SelectControl, {
__next40pxDefaultSize: true,
__nextHasNoMarginBottom: true,
label: __('Link to'),
value: textLinkHref,
options: linkDestinationOptions,
onChange: changeLinkDestinationOption
})
}), /*#__PURE__*/_jsx(ToolsPanelItem, {
label: __('Open in new tab'),
isShownByDefault: true,
hasValue: () => !!openInNewWindow,
onDeselect: () => changeOpenInNewWindow(false),
children: /*#__PURE__*/_jsx(ToggleControl, {
__nextHasNoMarginBottom: true,
label: __('Open in new tab'),
checked: openInNewWindow,
onChange: changeOpenInNewWindow
})
}), /*#__PURE__*/_jsx(ToolsPanelItem, {
label: __('Show download button'),
isShownByDefault: true,
hasValue: () => !showDownloadButton,
onDeselect: () => changeShowDownloadButton(true),
children: /*#__PURE__*/_jsx(ToggleControl, {
__nextHasNoMarginBottom: true,
label: __('Show download button'),
checked: showDownloadButton,
onChange: changeShowDownloadButton
})
})]
})]
})
});
}
//# sourceMappingURL=inspector.js.map