UNPKG

@wordpress/block-editor

Version:
88 lines (86 loc) 3.1 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-styles/utils.js var utils_exports = {}; __export(utils_exports, { getActiveStyle: () => getActiveStyle, getDefaultStyle: () => getDefaultStyle, getRenderedStyles: () => getRenderedStyles, replaceActiveStyle: () => replaceActiveStyle }); module.exports = __toCommonJS(utils_exports); var import_token_list = __toESM(require("@wordpress/token-list")); var import_i18n = require("@wordpress/i18n"); function getActiveStyle(styles, className) { for (const style of new import_token_list.default(className).values()) { if (style.indexOf("is-style-") === -1) { continue; } const potentialStyleName = style.substring(9); const activeStyle = styles?.find( ({ name }) => name === potentialStyleName ); if (activeStyle) { return activeStyle; } } return getDefaultStyle(styles); } function replaceActiveStyle(className, activeStyle, newStyle) { const list = new import_token_list.default(className); if (activeStyle) { list.remove("is-style-" + activeStyle.name); } list.add("is-style-" + newStyle.name); return list.value; } function getRenderedStyles(styles) { if (!styles || styles.length === 0) { return []; } return getDefaultStyle(styles) ? styles : [ { name: "default", label: (0, import_i18n._x)("Default", "block style"), isDefault: true }, ...styles ]; } function getDefaultStyle(styles) { return styles?.find((style) => style.isDefault); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { getActiveStyle, getDefaultStyle, getRenderedStyles, replaceActiveStyle }); //# sourceMappingURL=utils.js.map