@wordpress/block-editor
Version:
76 lines (67 loc) • 2.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = BlockSupportToolsPanel;
var _element = require("@wordpress/element");
var _components = require("@wordpress/components");
var _data = require("@wordpress/data");
var _store = require("../../store");
var _utils = require("../../hooks/utils");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
function BlockSupportToolsPanel({
children,
group,
label
}) {
const {
updateBlockAttributes
} = (0, _data.useDispatch)(_store.store);
const {
getBlockAttributes,
getMultiSelectedBlockClientIds,
getSelectedBlockClientId,
hasMultiSelection
} = (0, _data.useSelect)(_store.store);
const panelId = getSelectedBlockClientId();
const resetAll = (0, _element.useCallback)((resetFilters = []) => {
const newAttributes = {};
const clientIds = hasMultiSelection() ? getMultiSelectedBlockClientIds() : [panelId];
clientIds.forEach(clientId => {
const {
style
} = getBlockAttributes(clientId);
let newBlockAttributes = {
style
};
resetFilters.forEach(resetFilter => {
newBlockAttributes = { ...newBlockAttributes,
...resetFilter(newBlockAttributes)
};
}); // Enforce a cleaned style object.
newBlockAttributes = { ...newBlockAttributes,
style: (0, _utils.cleanEmptyObject)(newBlockAttributes.style)
};
newAttributes[clientId] = newBlockAttributes;
});
updateBlockAttributes(clientIds, newAttributes, true);
}, [getBlockAttributes, getMultiSelectedBlockClientIds, hasMultiSelection, panelId, updateBlockAttributes]);
return (0, _element.createElement)(_components.__experimentalToolsPanel, {
className: `${group}-block-support-panel`,
label: label,
resetAll: resetAll,
key: panelId,
panelId: panelId,
hasInnerWrapper: true,
shouldRenderPlaceholderItems: true // Required to maintain fills ordering.
,
__experimentalFirstVisibleItemClass: "first",
__experimentalLastVisibleItemClass: "last"
}, children);
}
//# sourceMappingURL=block-support-tools-panel.js.map