@10up/block-components
Version:
10up Components built for the WordPress Block Editor.
292 lines (267 loc) • 9.29 kB
JavaScript
/******/ (function() { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ "./stores/icons/actions.ts":
/*!*********************************!*\
!*** ./stores/icons/actions.ts ***!
\*********************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ registerIconSet: function() { return /* binding */ registerIconSet; },
/* harmony export */ removeIconSet: function() { return /* binding */ removeIconSet; }
/* harmony export */ });
/**
* Returns an action object used in signalling that new block styles have been added.
*
* @param {object} iconSet icon set.
*
* @returns {object} Action object.
*/
function registerIconSet(iconSet) {
return {
type: 'REGISTER_ICON_SET',
iconSet
};
}
/**
* Returns an action object used in signalling that block styles have been removed.
*
* @param {string} name Icon Set name.
*
* @returns {object} Action object.
*/
function removeIconSet(name) {
return {
type: 'REMOVE_ICON_SET',
name
};
}
/***/ }),
/***/ "./stores/icons/reducer.ts":
/*!*********************************!*\
!*** ./stores/icons/reducer.ts ***!
\*********************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": function() { return /* binding */ reducer; }
/* harmony export */ });
/* eslint-disable default-param-last */
/*
* Reducer managing the block style variations.
*/
function reducer(state = {
iconSets: {}
}, action) {
switch (action.type) {
case 'REGISTER_ICON_SET':
return {
...state,
iconSets: {
...state.iconSets,
[action.iconSet.name]: action.iconSet
}
};
case 'REMOVE_ICON_SET':
// eslint-disable-next-line no-prototype-builtins
if (state.iconSets.hasOwnProperty(action.name)) {
const newState = {
...state
};
delete newState.iconSets[action.name];
return newState;
}
return state;
default:
return state;
}
}
/***/ }),
/***/ "./stores/icons/selectors.ts":
/*!***********************************!*\
!*** ./stores/icons/selectors.ts ***!
\***********************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ getIcon: function() { return /* binding */ getIcon; },
/* harmony export */ getIconSet: function() { return /* binding */ getIconSet; },
/* harmony export */ getIconSets: function() { return /* binding */ getIconSets; },
/* harmony export */ getIcons: function() { return /* binding */ getIcons; }
/* harmony export */ });
/* eslint-disable no-prototype-builtins */
/**
* Returns all icons sets
*
* @param {object} state Data state.
*
* @returns {Array?} Icon Sets.
*/
function getIconSets(state) {
const {
iconSets
} = state;
return Object.values(iconSets);
}
/**
* Returns an Icon Set by its name
*
* @param {object} state Data state.
* @param {string} name Name of the Icon Set.
*
* @returns {object?} Icon Set.
*/
function getIconSet(state, name) {
const {
iconSets
} = state;
const iconSet = iconSets[name] ?? [];
return iconSet;
}
/**
* Returns an icon of an icon set by its name
*
* @param {object} state Data state.
* @param {string} name Name of the Icon Set.
*
* @returns {Array?} List of Icons.
*/
function getIcons(state, name) {
const {
iconSets
} = state;
return iconSets?.hasOwnProperty(name) ? iconSets[name]?.icons ?? [] : [];
}
/**
* Returns an icon of an icon set by its name
*
* @param {object} state Data state.
* @param {string} name Name of the Icon Set.
* @param {string} iconName Name of the iconName.
*
* @returns {object?} Icon.
*/
function getIcon(state, name, iconName) {
const {
iconSets
} = state;
return iconSets?.hasOwnProperty(name) ? iconSets[name]?.icons?.find(item => item.name === iconName) ?? [] : undefined;
}
/***/ }),
/***/ "@wordpress/data":
/*!**********************************!*\
!*** external "@wordpress/data" ***!
\**********************************/
/***/ (function(module) {
module.exports = require("@wordpress/data");
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat get default export */
/******/ !function() {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function() { return module['default']; } :
/******/ function() { return module; };
/******/ __webpack_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ }();
/******/
/******/ /* webpack/runtime/define property getters */
/******/ !function() {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = function(exports, definition) {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ }();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ !function() {
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
/******/ }();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ !function() {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ }();
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
!function() {
/*!*******************************!*\
!*** ./stores/icons/index.ts ***!
\*******************************/
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ store: function() { return /* binding */ store; }
/* harmony export */ });
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data");
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _reducer__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./reducer */ "./stores/icons/reducer.ts");
/* harmony import */ var _selectors__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./selectors */ "./stores/icons/selectors.ts");
/* harmony import */ var _actions__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./actions */ "./stores/icons/actions.ts");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
const STORE_NAME = 'tenup/icons';
/**
* Store definition for the icons namespace.
*
* @type {object}
*/
const store = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.createReduxStore)(STORE_NAME, {
reducer: _reducer__WEBPACK_IMPORTED_MODULE_1__["default"],
selectors: _selectors__WEBPACK_IMPORTED_MODULE_2__,
actions: _actions__WEBPACK_IMPORTED_MODULE_3__
});
const hasStore = !!(0,_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.select)(STORE_NAME);
if (!hasStore) {
(0,_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.register)(store);
}
}();
module.exports = __webpack_exports__;
/******/ })()
;
//# sourceMappingURL=index.js.map