UNPKG

@wordpress/block-editor

Version:
127 lines (123 loc) 4.58 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _native = require("@react-navigation/native"); var _reactNative = require("react-native"); var _i18n = require("@wordpress/i18n"); var _icons = require("@wordpress/icons"); var _compose = require("@wordpress/compose"); var _components = require("@wordpress/components"); var _styleNative = _interopRequireDefault(require("./style.native.scss")); var _blockSettings = require("../block-settings"); var _jsxRuntime = require("react/jsx-runtime"); /** * External dependencies */ /** * WordPress dependencies */ /** * Internal dependencies */ const LINK_DESTINATION_NONE = 'none'; const LINK_DESTINATION_MEDIA = 'media'; const LINK_DESTINATION_ATTACHMENT = 'attachment'; const LINK_DESTINATION_CUSTOM = 'custom'; function LinkDestination({ children, isSelected, label, onPress, value, valueStyle }) { const optionIcon = (0, _compose.usePreferredColorSchemeStyle)(_styleNative.default.optionIcon, _styleNative.default.optionIconDark); return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.BottomSheet.Cell, { icon: _icons.check, iconStyle: _reactNative.StyleSheet.flatten([optionIcon, !isSelected && _styleNative.default.unselectedOptionIcon]), label: label, leftAlign: true, onPress: onPress, value: value, valueStyle: valueStyle, separatorType: "leftMargin", children: children }); } function ImageLinkDestinationsScreen(props) { const navigation = (0, _native.useNavigation)(); const route = (0, _native.useRoute)(); const { url = '' } = props; const { inputValue = url, imageUrl, attachmentPageUrl, linkDestination } = route.params || {}; function goToLinkPicker() { navigation.navigate(_blockSettings.blockSettingsScreens.linkPicker, { inputValue: linkDestination === LINK_DESTINATION_CUSTOM ? inputValue : '' }); } const setLinkDestination = newLinkDestination => () => { let newUrl; switch (newLinkDestination) { case LINK_DESTINATION_MEDIA: newUrl = imageUrl; break; case LINK_DESTINATION_ATTACHMENT: newUrl = attachmentPageUrl; break; default: newUrl = ''; break; } navigation.navigate(_blockSettings.blockSettingsScreens.settings, { // The `inputValue` name is reused from LinkPicker, as it helps avoid // bugs from stale values remaining in the React Navigation route // parameters. inputValue: newUrl, // Clear link text value that may be set from LinkPicker. text: '' }); }; return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, { children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.BottomSheet.NavBar, { children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.BottomSheet.NavBar.BackButton, { onPress: navigation.goBack }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.BottomSheet.NavBar.Heading, { children: (0, _i18n.__)('Link To') })] }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.PanelBody, { children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(LinkDestination, { isSelected: linkDestination === LINK_DESTINATION_NONE, label: (0, _i18n.__)('None'), onPress: setLinkDestination(LINK_DESTINATION_NONE) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(LinkDestination, { isSelected: linkDestination === LINK_DESTINATION_MEDIA, label: (0, _i18n.__)('Media File'), onPress: setLinkDestination(LINK_DESTINATION_MEDIA) }), !!attachmentPageUrl && /*#__PURE__*/(0, _jsxRuntime.jsx)(LinkDestination, { isSelected: linkDestination === LINK_DESTINATION_ATTACHMENT, label: (0, _i18n.__)('Attachment Page'), onPress: setLinkDestination(LINK_DESTINATION_ATTACHMENT) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(LinkDestination, { isSelected: linkDestination === LINK_DESTINATION_CUSTOM, label: (0, _i18n.__)('Custom URL'), onPress: goToLinkPicker, value: linkDestination === LINK_DESTINATION_CUSTOM ? inputValue : '', valueStyle: linkDestination === LINK_DESTINATION_CUSTOM ? undefined : _styleNative.default.placeholderTextColor, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.Icon, { icon: _icons.chevronRight }) })] })] }); } var _default = exports.default = ImageLinkDestinationsScreen; //# sourceMappingURL=index.native.js.map