WordPress/js/dist/viewport.js

540 lines
22 KiB
JavaScript
Raw Normal View History

this["wp"] = this["wp"] || {}; this["wp"]["viewport"] =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // 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 });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "./node_modules/@wordpress/viewport/build-module/index.js");
/******/ })
/************************************************************************/
/******/ ({
/***/ "./node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js":
/*!**********************************************************************!*\
!*** ./node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js ***!
\**********************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _arrayWithoutHoles; });
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
arr2[i] = arr[i];
}
return arr2;
}
}
/***/ }),
/***/ "./node_modules/@babel/runtime/helpers/esm/iterableToArray.js":
/*!********************************************************************!*\
!*** ./node_modules/@babel/runtime/helpers/esm/iterableToArray.js ***!
\********************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _iterableToArray; });
function _iterableToArray(iter) {
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
}
/***/ }),
/***/ "./node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js":
/*!**********************************************************************!*\
!*** ./node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js ***!
\**********************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _nonIterableSpread; });
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance");
}
/***/ }),
/***/ "./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js":
/*!**********************************************************************!*\
!*** ./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js ***!
\**********************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _toConsumableArray; });
/* harmony import */ var _arrayWithoutHoles__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./arrayWithoutHoles */ "./node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js");
/* harmony import */ var _iterableToArray__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./iterableToArray */ "./node_modules/@babel/runtime/helpers/esm/iterableToArray.js");
/* harmony import */ var _nonIterableSpread__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./nonIterableSpread */ "./node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js");
function _toConsumableArray(arr) {
return Object(_arrayWithoutHoles__WEBPACK_IMPORTED_MODULE_0__["default"])(arr) || Object(_iterableToArray__WEBPACK_IMPORTED_MODULE_1__["default"])(arr) || Object(_nonIterableSpread__WEBPACK_IMPORTED_MODULE_2__["default"])();
}
/***/ }),
/***/ "./node_modules/@wordpress/viewport/build-module/if-viewport-matches.js":
/*!******************************************************************************!*\
!*** ./node_modules/@wordpress/viewport/build-module/if-viewport-matches.js ***!
\******************************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/compose */ "@wordpress/compose");
/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_compose__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _with_viewport_match__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./with-viewport-match */ "./node_modules/@wordpress/viewport/build-module/with-viewport-match.js");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
/**
* Higher-order component creator, creating a new component which renders if
* the viewport query is satisfied.
*
* @param {string} query Viewport query.
*
* @see withViewportMatches
*
* @return {Function} Higher-order component.
*/
var ifViewportMatches = function ifViewportMatches(query) {
return Object(_wordpress_compose__WEBPACK_IMPORTED_MODULE_0__["createHigherOrderComponent"])(Object(_wordpress_compose__WEBPACK_IMPORTED_MODULE_0__["compose"])([Object(_with_viewport_match__WEBPACK_IMPORTED_MODULE_1__["default"])({
isViewportMatch: query
}), Object(_wordpress_compose__WEBPACK_IMPORTED_MODULE_0__["ifCondition"])(function (props) {
return props.isViewportMatch;
})]), 'ifViewportMatches');
};
/* harmony default export */ __webpack_exports__["default"] = (ifViewportMatches);
/***/ }),
/***/ "./node_modules/@wordpress/viewport/build-module/index.js":
/*!****************************************************************!*\
!*** ./node_modules/@wordpress/viewport/build-module/index.js ***!
\****************************************************************/
/*! exports provided: ifViewportMatches, withViewportMatch */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash */ "lodash");
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data");
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./store */ "./node_modules/@wordpress/viewport/build-module/store/index.js");
/* harmony import */ var _if_viewport_matches__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./if-viewport-matches */ "./node_modules/@wordpress/viewport/build-module/if-viewport-matches.js");
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ifViewportMatches", function() { return _if_viewport_matches__WEBPACK_IMPORTED_MODULE_3__["default"]; });
/* harmony import */ var _with_viewport_match__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./with-viewport-match */ "./node_modules/@wordpress/viewport/build-module/with-viewport-match.js");
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "withViewportMatch", function() { return _with_viewport_match__WEBPACK_IMPORTED_MODULE_4__["default"]; });
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
/**
* Hash of breakpoint names with pixel width at which it becomes effective.
*
* @see _breakpoints.scss
*
* @type {Object}
*/
var BREAKPOINTS = {
huge: 1440,
wide: 1280,
large: 960,
medium: 782,
small: 600,
mobile: 480
};
/**
* Hash of query operators with corresponding condition for media query.
*
* @type {Object}
*/
var OPERATORS = {
'<': 'max-width',
'>=': 'min-width'
};
/**
* Callback invoked when media query state should be updated. Is invoked a
* maximum of one time per call stack.
*/
var setIsMatching = Object(lodash__WEBPACK_IMPORTED_MODULE_0__["debounce"])(function () {
var values = Object(lodash__WEBPACK_IMPORTED_MODULE_0__["mapValues"])(queries, function (query) {
return query.matches;
});
Object(_wordpress_data__WEBPACK_IMPORTED_MODULE_1__["dispatch"])('core/viewport').setIsMatching(values);
}, {
leading: true
});
/**
* Hash of breakpoint names with generated MediaQueryList for corresponding
* media query.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia
* @see https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList
*
* @type {Object<string,MediaQueryList>}
*/
var queries = Object(lodash__WEBPACK_IMPORTED_MODULE_0__["reduce"])(BREAKPOINTS, function (result, width, name) {
Object(lodash__WEBPACK_IMPORTED_MODULE_0__["forEach"])(OPERATORS, function (condition, operator) {
var list = window.matchMedia("(".concat(condition, ": ").concat(width, "px)"));
list.addListener(setIsMatching);
var key = [operator, name].join(' ');
result[key] = list;
});
return result;
}, {});
window.addEventListener('orientationchange', setIsMatching); // Set initial values
setIsMatching();
/***/ }),
/***/ "./node_modules/@wordpress/viewport/build-module/store/actions.js":
/*!************************************************************************!*\
!*** ./node_modules/@wordpress/viewport/build-module/store/actions.js ***!
\************************************************************************/
/*! exports provided: setIsMatching */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setIsMatching", function() { return setIsMatching; });
/**
* Returns an action object used in signalling that viewport queries have been
* updated. Values are specified as an object of breakpoint query keys where
* value represents whether query matches.
*
* @param {Object} values Breakpoint query matches.
*
* @return {Object} Action object.
*/
function setIsMatching(values) {
return {
type: 'SET_IS_MATCHING',
values: values
};
}
/***/ }),
/***/ "./node_modules/@wordpress/viewport/build-module/store/index.js":
/*!**********************************************************************!*\
!*** ./node_modules/@wordpress/viewport/build-module/store/index.js ***!
\**********************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* 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 */ "./node_modules/@wordpress/viewport/build-module/store/reducer.js");
/* harmony import */ var _actions__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./actions */ "./node_modules/@wordpress/viewport/build-module/store/actions.js");
/* harmony import */ var _selectors__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./selectors */ "./node_modules/@wordpress/viewport/build-module/store/selectors.js");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
/* harmony default export */ __webpack_exports__["default"] = (Object(_wordpress_data__WEBPACK_IMPORTED_MODULE_0__["registerStore"])('core/viewport', {
reducer: _reducer__WEBPACK_IMPORTED_MODULE_1__["default"],
actions: _actions__WEBPACK_IMPORTED_MODULE_2__,
selectors: _selectors__WEBPACK_IMPORTED_MODULE_3__
}));
/***/ }),
/***/ "./node_modules/@wordpress/viewport/build-module/store/reducer.js":
/*!************************************************************************!*\
!*** ./node_modules/@wordpress/viewport/build-module/store/reducer.js ***!
\************************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/**
* Reducer returning the viewport state, as keys of breakpoint queries with
* boolean value representing whether query is matched.
*
* @param {Object} state Current state.
* @param {Object} action Dispatched action.
*
* @return {Object} Updated state.
*/
function reducer() {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var action = arguments.length > 1 ? arguments[1] : undefined;
switch (action.type) {
case 'SET_IS_MATCHING':
return action.values;
}
return state;
}
/* harmony default export */ __webpack_exports__["default"] = (reducer);
/***/ }),
/***/ "./node_modules/@wordpress/viewport/build-module/store/selectors.js":
/*!**************************************************************************!*\
!*** ./node_modules/@wordpress/viewport/build-module/store/selectors.js ***!
\**************************************************************************/
/*! exports provided: isViewportMatch */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isViewportMatch", function() { return isViewportMatch; });
/* harmony import */ var _babel_runtime_helpers_esm_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/esm/toConsumableArray */ "./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js");
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! lodash */ "lodash");
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_1__);
/**
* External dependencies
*/
/**
* Returns true if the viewport matches the given query, or false otherwise.
*
* @param {Object} state Viewport state object.
* @param {string} query Query string. Includes operator and breakpoint name,
* space separated. Operator defaults to >=.
*
* @example
*
* ```js
* isViewportMatch( state, '< huge' );
* isViewPortMatch( state, 'medium' );
* ```
*
* @return {boolean} Whether viewport matches query.
*/
function isViewportMatch(state, query) {
// Pad to _at least_ two elements to take from the right, effectively
// defaulting the left-most value.
var key = Object(lodash__WEBPACK_IMPORTED_MODULE_1__["takeRight"])(['>='].concat(Object(_babel_runtime_helpers_esm_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__["default"])(query.split(' '))), 2).join(' ');
return !!state[key];
}
/***/ }),
/***/ "./node_modules/@wordpress/viewport/build-module/with-viewport-match.js":
/*!******************************************************************************!*\
!*** ./node_modules/@wordpress/viewport/build-module/with-viewport-match.js ***!
\******************************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash */ "lodash");
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/compose */ "@wordpress/compose");
/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_compose__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data");
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_2__);
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
/**
* Higher-order component creator, creating a new component which renders with
* the given prop names, where the value passed to the underlying component is
* the result of the query assigned as the object's value.
*
* @param {Object} queries Object of prop name to viewport query.
*
* @see isViewportMatch
*
* @return {Function} Higher-order component.
*/
var withViewportMatch = function withViewportMatch(queries) {
return Object(_wordpress_compose__WEBPACK_IMPORTED_MODULE_1__["createHigherOrderComponent"])(Object(_wordpress_data__WEBPACK_IMPORTED_MODULE_2__["withSelect"])(function (select) {
return Object(lodash__WEBPACK_IMPORTED_MODULE_0__["mapValues"])(queries, function (query) {
return select('core/viewport').isViewportMatch(query);
});
}), 'withViewportMatch');
};
/* harmony default export */ __webpack_exports__["default"] = (withViewportMatch);
/***/ }),
/***/ "@wordpress/compose":
/*!******************************************!*\
!*** external {"this":["wp","compose"]} ***!
\******************************************/
/*! no static exports found */
/***/ (function(module, exports) {
(function() { module.exports = this["wp"]["compose"]; }());
/***/ }),
/***/ "@wordpress/data":
/*!***************************************!*\
!*** external {"this":["wp","data"]} ***!
\***************************************/
/*! no static exports found */
/***/ (function(module, exports) {
(function() { module.exports = this["wp"]["data"]; }());
/***/ }),
/***/ "lodash":
/*!*************************!*\
!*** external "lodash" ***!
\*************************/
/*! no static exports found */
/***/ (function(module, exports) {
(function() { module.exports = this["lodash"]; }());
/***/ })
/******/ });
//# sourceMappingURL=viewport.js.map