UNPKG

@wordpress/blocks

Version:
180 lines (178 loc) 6.22 kB
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/blocks/src/store/private-selectors.js var private_selectors_exports = {}; __export(private_selectors_exports, { getAllBlockBindingsSources: () => getAllBlockBindingsSources, getBlockBindingsSource: () => getBlockBindingsSource, getBootstrappedBlockType: () => getBootstrappedBlockType, getSupportedStyles: () => getSupportedStyles, getUnprocessedBlockTypes: () => getUnprocessedBlockTypes, hasContentRoleAttribute: () => hasContentRoleAttribute }); module.exports = __toCommonJS(private_selectors_exports); var import_data = require("@wordpress/data"); var import_deprecated = __toESM(require("@wordpress/deprecated")); var import_selectors = require("./selectors"); var import_utils = require("./utils"); var import_constants = require("../api/constants"); var ROOT_BLOCK_SUPPORTS = [ "background", "backgroundColor", "color", "linkColor", "captionColor", "buttonColor", "headingColor", "fontFamily", "fontSize", "fontStyle", "fontWeight", "lineHeight", "padding", "contentSize", "wideSize", "blockGap", "textDecoration", "textTransform", "letterSpacing" ]; function filterElementBlockSupports(blockSupports, name, element) { return blockSupports.filter((support) => { if (support === "fontSize" && element === "heading") { return false; } if (support === "textDecoration" && !name && element !== "link") { return false; } if (support === "textTransform" && !name && !(["heading", "h1", "h2", "h3", "h4", "h5", "h6"].includes( element ) || element === "button" || element === "caption" || element === "text")) { return false; } if (support === "letterSpacing" && !name && !(["heading", "h1", "h2", "h3", "h4", "h5", "h6"].includes( element ) || element === "button" || element === "caption" || element === "text")) { return false; } if (support === "textColumns" && !name) { return false; } return true; }); } var getSupportedStyles = (0, import_data.createSelector)( (state, name, element) => { if (!name) { return filterElementBlockSupports( ROOT_BLOCK_SUPPORTS, name, element ); } const blockType = (0, import_selectors.getBlockType)(state, name); if (!blockType) { return []; } const supportKeys = []; if (blockType?.supports?.spacing?.blockGap) { supportKeys.push("blockGap"); } if (blockType?.supports?.shadow) { supportKeys.push("shadow"); } Object.keys(import_constants.__EXPERIMENTAL_STYLE_PROPERTY).forEach((styleName) => { if (!import_constants.__EXPERIMENTAL_STYLE_PROPERTY[styleName].support) { return; } if (import_constants.__EXPERIMENTAL_STYLE_PROPERTY[styleName].requiresOptOut) { if (import_constants.__EXPERIMENTAL_STYLE_PROPERTY[styleName].support[0] in blockType.supports && (0, import_utils.getValueFromObjectPath)( blockType.supports, import_constants.__EXPERIMENTAL_STYLE_PROPERTY[styleName].support ) !== false) { supportKeys.push(styleName); return; } } if ((0, import_utils.getValueFromObjectPath)( blockType.supports, import_constants.__EXPERIMENTAL_STYLE_PROPERTY[styleName].support, false )) { supportKeys.push(styleName); } }); return filterElementBlockSupports(supportKeys, name, element); }, (state, name) => [state.blockTypes[name]] ); function getBootstrappedBlockType(state, name) { return state.bootstrappedBlockTypes[name]; } function getUnprocessedBlockTypes(state) { return state.unprocessedBlockTypes; } function getAllBlockBindingsSources(state) { return state.blockBindingsSources; } function getBlockBindingsSource(state, sourceName) { return state.blockBindingsSources[sourceName]; } var hasContentRoleAttribute = (state, blockTypeName) => { const blockType = (0, import_selectors.getBlockType)(state, blockTypeName); if (!blockType) { return false; } return Object.values(blockType.attributes).some( ({ role, __experimentalRole }) => { if (role === "content") { return true; } if (__experimentalRole === "content") { (0, import_deprecated.default)("__experimentalRole attribute", { since: "6.7", version: "6.8", alternative: "role attribute", hint: `Check the block.json of the ${blockTypeName} block.` }); return true; } return false; } ); }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { getAllBlockBindingsSources, getBlockBindingsSource, getBootstrappedBlockType, getSupportedStyles, getUnprocessedBlockTypes, hasContentRoleAttribute }); //# sourceMappingURL=private-selectors.js.map