UNPKG

@wordpress/block-editor

Version:
78 lines (74 loc) 2.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = BlockSupportToolsPanel; var _components = require("@wordpress/components"); var _data = require("@wordpress/data"); var _element = require("@wordpress/element"); var _store = require("../../store"); var _utils = require("../../hooks/utils"); var _utils2 = require("../global-styles/utils"); var _jsxRuntime = require("react/jsx-runtime"); /** * 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 dropdownMenuProps = (0, _utils2.useToolsPanelDropdownMenuProps)(); 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 /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalToolsPanel, { className: `${group}-block-support-panel`, label: label, resetAll: resetAll, panelId: panelId, hasInnerWrapper: true, shouldRenderPlaceholderItems: true // Required to maintain fills ordering. , __experimentalFirstVisibleItemClass: "first", __experimentalLastVisibleItemClass: "last", dropdownMenuProps: dropdownMenuProps, children: children }, panelId); } //# sourceMappingURL=block-support-tools-panel.js.map