@wordpress/block-editor
Version:
96 lines (93 loc) • 3.17 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _components = require("@wordpress/components");
var _data = require("@wordpress/data");
var _i18n = require("@wordpress/i18n");
var _groups = _interopRequireDefault(require("../inspector-controls/groups"));
var _inspectorControls = _interopRequireDefault(require("../inspector-controls"));
var _store = require("../../store");
var _utils = require("../global-styles/utils");
var _utils2 = require("../../hooks/utils");
var _jsxRuntime = require("react/jsx-runtime");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
const PositionControlsPanel = () => {
const {
selectedClientIds,
selectedBlocks,
hasPositionAttribute
} = (0, _data.useSelect)(select => {
const {
getBlocksByClientId,
getSelectedBlockClientIds
} = select(_store.store);
const selectedBlockClientIds = getSelectedBlockClientIds();
const _selectedBlocks = getBlocksByClientId(selectedBlockClientIds);
return {
selectedClientIds: selectedBlockClientIds,
selectedBlocks: _selectedBlocks,
hasPositionAttribute: _selectedBlocks?.some(({
attributes
}) => !!attributes?.style?.position?.type)
};
}, []);
const {
updateBlockAttributes
} = (0, _data.useDispatch)(_store.store);
const dropdownMenuProps = (0, _utils.useToolsPanelDropdownMenuProps)();
function resetPosition() {
if (!selectedClientIds?.length || !selectedBlocks?.length) {
return;
}
const attributesByClientId = Object.fromEntries(selectedBlocks?.map(({
clientId,
attributes
}) => [clientId, {
style: (0, _utils2.cleanEmptyObject)({
...attributes?.style,
position: {
...attributes?.style?.position,
type: undefined,
top: undefined,
right: undefined,
bottom: undefined,
left: undefined
}
})
}]));
updateBlockAttributes(selectedClientIds, attributesByClientId, true);
}
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalToolsPanel, {
className: "block-editor-block-inspector__position",
label: (0, _i18n.__)('Position'),
resetAll: resetPosition,
dropdownMenuProps: dropdownMenuProps,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalToolsPanelItem, {
isShownByDefault: hasPositionAttribute,
label: (0, _i18n.__)('Position'),
hasValue: () => hasPositionAttribute,
onDeselect: resetPosition,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_inspectorControls.default.Slot, {
group: "position"
})
})
});
};
const PositionControls = () => {
const fills = (0, _components.__experimentalUseSlotFills)(_groups.default.position.name);
const hasFills = Boolean(fills && fills.length);
if (!hasFills) {
return null;
}
return /*#__PURE__*/(0, _jsxRuntime.jsx)(PositionControlsPanel, {});
};
var _default = exports.default = PositionControls;
//# sourceMappingURL=position-controls-panel.js.map
;