@wordpress/block-editor
Version:
95 lines (89 loc) • 2.9 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _reactNative = require("react-native");
var _blockEditor = require("@wordpress/block-editor");
var _compose = require("@wordpress/compose");
var _data = require("@wordpress/data");
var _blocks = require("@wordpress/blocks");
var _styles = _interopRequireDefault(require("./styles.scss"));
var _store = require("../../store");
var _jsxRuntime = require("react/jsx-runtime");
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
const BlockCaption = ({
accessible,
accessibilityLabelCreator,
onBlur,
onChange,
onFocus,
isSelected,
shouldDisplay,
text,
insertBlocksAfter
}) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
style: [_styles.default.container, shouldDisplay && _styles.default.padding],
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.Caption, {
accessibilityLabelCreator: accessibilityLabelCreator,
accessible: accessible,
isSelected: isSelected,
onBlur: onBlur,
onChange: onChange,
onFocus: onFocus,
shouldDisplay: shouldDisplay,
value: text,
insertBlocksAfter: insertBlocksAfter
})
});
var _default = exports.default = (0, _compose.compose)([(0, _data.withSelect)((select, {
clientId
}) => {
const {
getBlockAttributes,
getSelectedBlockClientId,
getBlockName,
getBlockRootClientId
} = select(_store.store);
const {
caption
} = getBlockAttributes(clientId) || {};
const isBlockSelected = getSelectedBlockClientId() === clientId;
// Detect whether the block is an inner block by checking if it has a parent block.
// getBlockRootClientId() will return an empty string for all top-level blocks.
// If the block is an inner block, its parent may explicitly hide child block controls.
// See: https://github.com/wordpress-mobile/gutenberg-mobile/pull/4256
const parentId = getBlockRootClientId(clientId);
const parentBlockName = getBlockName(parentId);
const hideCaption = (0, _blocks.hasBlockSupport)(parentBlockName, '__experimentalHideChildBlockControls', false);
// We'll render the caption so that the soft keyboard is not forced to close on Android
// but still hide it by setting its display style to none. See wordpress-mobile/gutenberg-mobile#1221
const shouldDisplay = !hideCaption && (!_blockEditor.RichText.isEmpty(caption) > 0 || isBlockSelected);
return {
shouldDisplay,
text: caption
};
}), (0, _data.withDispatch)((dispatch, {
clientId
}) => {
const {
updateBlockAttributes
} = dispatch(_store.store);
return {
onChange: caption => {
updateBlockAttributes(clientId, {
caption
});
}
};
})])(BlockCaption);
//# sourceMappingURL=index.native.js.map
;