UNPKG

@wordpress/block-editor

Version:
128 lines (126 loc) 5.2 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/block-editor/src/components/block-toolbar/switch-section-style.js var switch_section_style_exports = {}; __export(switch_section_style_exports, { default: () => switch_section_style_default }); module.exports = __toCommonJS(switch_section_style_exports); var import_components = require("@wordpress/components"); var import_i18n = require("@wordpress/i18n"); var import_data = require("@wordpress/data"); var import_use_styles_for_block = __toESM(require("../block-styles/use-styles-for-block")); var import_utils = require("../block-styles/utils"); var import_store = require("../../store"); var import_private_keys = require("../../store/private-keys"); var import_block_style_variation = require("../../hooks/block-style-variation"); var import_jsx_runtime = require("react/jsx-runtime"); var styleIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( import_components.SVG, { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", "aria-hidden": "true", focusable: "false", children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Path, { d: "M17.2 10.9c-.5-1-1.2-2.1-2.1-3.2-.6-.9-1.3-1.7-2.1-2.6L12 4l-1 1.1c-.6.9-1.3 1.7-2 2.6-.8 1.2-1.5 2.3-2 3.2-.6 1.2-1 2.2-1 3 0 3.4 2.7 6.1 6.1 6.1s6.1-2.7 6.1-6.1c0-.8-.3-1.8-1-3z" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.Path, { stroke: "currentColor", strokeWidth: "1.5", d: "M17.2 10.9c-.5-1-1.2-2.1-2.1-3.2-.6-.9-1.3-1.7-2.1-2.6L12 4l-1 1.1c-.6.9-1.3 1.7-2 2.6-.8 1.2-1.5 2.3-2 3.2-.6 1.2-1 2.2-1 3 0 3.4 2.7 6.1 6.1 6.1s6.1-2.7 6.1-6.1c0-.8-.3-1.8-1-3z" } ) ] } ); function SwitchSectionStyle({ clientId }) { const { stylesToRender, activeStyle, className } = (0, import_use_styles_for_block.default)({ clientId }); const { updateBlockAttributes } = (0, import_data.useDispatch)(import_store.store); const { globalSettings, globalStyles, blockName } = (0, import_data.useSelect)( (select) => { const settings = select(import_store.store).getSettings(); return { globalSettings: settings.__experimentalFeatures, globalStyles: settings[import_private_keys.globalStylesDataKey], blockName: select(import_store.store).getBlockName(clientId) }; }, [clientId] ); const activeStyleBackground = activeStyle?.name ? (0, import_block_style_variation.getVariationStylesWithRefValues)( { settings: globalSettings, styles: globalStyles }, blockName, activeStyle.name )?.color?.background : void 0; if (!stylesToRender || stylesToRender.length === 0) { return null; } const handleStyleSwitch = () => { const currentIndex = stylesToRender.findIndex( (style) => style.name === activeStyle.name ); const nextIndex = (currentIndex + 1) % stylesToRender.length; const nextStyle = stylesToRender[nextIndex]; const styleClassName = (0, import_utils.replaceActiveStyle)( className, activeStyle, nextStyle ); updateBlockAttributes(clientId, { className: styleClassName }); }; return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.ToolbarGroup, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.ToolbarButton, { onClick: handleStyleSwitch, label: (0, import_i18n.__)("Shuffle styles"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_components.Icon, { icon: styleIcon, style: { fill: activeStyleBackground || "transparent" } } ) } ) }); } var switch_section_style_default = SwitchSectionStyle; //# sourceMappingURL=switch-section-style.js.map