WordPress/wp-includes/js/dist/viewport.js
gziolo 1044eb572a Editor: Sync changes from the Gutenberg plugin 14.1 release
Updated WordPress packages necessary for releasing WordPress 6.1 Beta 1:

- @wordpress/a11y@3.17.1
 - @wordpress/annotations@2.17.2
 - @wordpress/api-fetch@6.14.1
 - @wordpress/autop@3.17.1
 - @wordpress/babel-plugin-import-jsx-pragma@4.0.1
 - @wordpress/babel-plugin-makepot@5.1.1
 - @wordpress/babel-preset-default@7.1.1
 - @wordpress/base-styles@4.8.1
 - @wordpress/blob@3.17.1
 - @wordpress/block-directory@3.15.2
 - @wordpress/block-editor@10.0.2
 - @wordpress/block-library@7.14.2
 - @wordpress/block-serialization-default-parser@4.17.1
 - @wordpress/block-serialization-spec-parser@4.17.1
 - @wordpress/blocks@11.16.2
 - @wordpress/browserslist-config@5.0.1
 - @wordpress/components@21.0.2
 - @wordpress/compose@5.15.2
 - @wordpress/core-data@5.0.2
 - @wordpress/create-block-tutorial-template@2.5.1
 - @wordpress/create-block@4.1.1
 - @wordpress/custom-templated-path-webpack-plugin@2.1.3
 - @wordpress/customize-widgets@3.14.2
 - @wordpress/data-controls@2.17.2
 - @wordpress/data@7.1.2
 - @wordpress/date@4.17.1
 - @wordpress/dependency-extraction-webpack-plugin@4.0.2
 - @wordpress/deprecated@3.17.1
 - @wordpress/docgen@1.26.1
 - @wordpress/dom-ready@3.17.1
 - @wordpress/dom@3.17.2
 - @wordpress/e2e-test-utils@8.1.1
 - @wordpress/e2e-tests@5.1.2
 - @wordpress/edit-post@6.14.2
 - @wordpress/edit-site@4.14.2
 - @wordpress/edit-widgets@4.14.2
 - @wordpress/editor@12.16.2
 - @wordpress/element@4.15.1
 - @wordpress/env@5.2.1
 - @wordpress/escape-html@2.17.1
 - @wordpress/eslint-plugin@13.1.1
 - @wordpress/format-library@3.15.2
 - @wordpress/hooks@3.17.1
 - @wordpress/html-entities@3.17.1
 - @wordpress/i18n@4.17.1
 - @wordpress/icons@9.8.1
 - @wordpress/interface@4.16.2
 - @wordpress/is-shallow-equal@4.17.1
 - @wordpress/jest-console@6.0.1
 - @wordpress/jest-preset-default@9.0.1
 - @wordpress/jest-puppeteer-axe@5.0.1
 - @wordpress/keyboard-shortcuts@3.15.2
 - @wordpress/keycodes@3.17.1
 - @wordpress/lazy-import@1.4.3
 - @wordpress/library-export-default-webpack-plugin@2.3.3
 - @wordpress/list-reusable-blocks@3.15.2
 - @wordpress/media-utils@4.8.1
 - @wordpress/notices@3.17.2
 - @wordpress/npm-package-json-lint-config@4.2.1
 - @wordpress/nux@5.15.2
 - @wordpress/plugins@4.15.2
 - @wordpress/postcss-plugins-preset@4.1.1
 - @wordpress/postcss-themes@5.0.1
 - @wordpress/preferences-persistence@1.9.1
 - @wordpress/preferences@2.9.2
 - @wordpress/prettier-config@2.0.1
 - @wordpress/primitives@3.15.1
 - @wordpress/priority-queue@2.17.2
 - @wordpress/project-management-automation@1.16.1
 - @wordpress/react-i18n@3.15.1
 - @wordpress/readable-js-assets-webpack-plugin@2.0.1
 - @wordpress/redux-routine@4.17.1
 - @wordpress/reusable-blocks@3.15.2
 - @wordpress/rich-text@5.15.2
 - @wordpress/scripts@24.1.2
 - @wordpress/server-side-render@3.15.2
 - @wordpress/shortcode@3.17.1
 - @wordpress/style-engine@1.0.1
 - @wordpress/stylelint-config@21.0.1
 - @wordpress/token-list@2.17.1
 - @wordpress/url@3.18.1
 - @wordpress/viewport@4.15.2
 - @wordpress/warning@2.17.1
 - @wordpress/widgets@2.15.2
 - @wordpress/wordcount@3.17.1


Props bernhard-reiter, cbravobernal, czapla, oandregal, isabel_brison, andrewserong, mciampini.
See #56467.


Built from https://develop.svn.wordpress.org/trunk@54257


git-svn-id: http://core.svn.wordpress.org/trunk@53816 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-20 15:43:29 +00:00

390 lines
11 KiB
JavaScript

/******/ (function() { // webpackBootstrap
/******/ "use strict";
/******/ // The require scope
/******/ var __webpack_require__ = {};
/******/
/************************************************************************/
/******/ /* 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__ = {};
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
"ifViewportMatches": function() { return /* reexport */ if_viewport_matches; },
"store": function() { return /* reexport */ store; },
"withViewportMatch": function() { return /* reexport */ with_viewport_match; }
});
// NAMESPACE OBJECT: ./node_modules/@wordpress/viewport/build-module/store/actions.js
var actions_namespaceObject = {};
__webpack_require__.r(actions_namespaceObject);
__webpack_require__.d(actions_namespaceObject, {
"setIsMatching": function() { return setIsMatching; }
});
// NAMESPACE OBJECT: ./node_modules/@wordpress/viewport/build-module/store/selectors.js
var selectors_namespaceObject = {};
__webpack_require__.r(selectors_namespaceObject);
__webpack_require__.d(selectors_namespaceObject, {
"isViewportMatch": function() { return isViewportMatch; }
});
;// CONCATENATED MODULE: external "lodash"
var external_lodash_namespaceObject = window["lodash"];
;// CONCATENATED MODULE: external ["wp","data"]
var external_wp_data_namespaceObject = window["wp"]["data"];
;// CONCATENATED MODULE: ./node_modules/@wordpress/viewport/build-module/store/reducer.js
/**
* 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() {
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
let action = arguments.length > 1 ? arguments[1] : undefined;
switch (action.type) {
case 'SET_IS_MATCHING':
return action.values;
}
return state;
}
/* harmony default export */ var store_reducer = (reducer);
;// CONCATENATED MODULE: ./node_modules/@wordpress/viewport/build-module/store/actions.js
/**
* 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.
* Ignored from documentation as it is for internal use only.
*
* @ignore
*
* @param {Object} values Breakpoint query matches.
*
* @return {Object} Action object.
*/
function setIsMatching(values) {
return {
type: 'SET_IS_MATCHING',
values
};
}
;// CONCATENATED MODULE: ./node_modules/@wordpress/viewport/build-module/store/selectors.js
/**
* 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
* import { store as viewportStore } from '@wordpress/viewport';
* import { useSelect } from '@wordpress/data';
* import { __ } from '@wordpress/i18n';
* const ExampleComponent = () => {
* const isMobile = useSelect(
* ( select ) => select( viewportStore ).isViewportMatch( '< small' ),
* []
* );
*
* return isMobile ? (
* <div>{ __( 'Mobile' ) }</div>
* ) : (
* <div>{ __( 'Not Mobile' ) }</div>
* );
* };
* ```
*
* @return {boolean} Whether viewport matches query.
*/
function isViewportMatch(state, query) {
// Default to `>=` if no operator is present.
if (query.indexOf(' ') === -1) {
query = '>= ' + query;
}
return !!state[query];
}
;// CONCATENATED MODULE: ./node_modules/@wordpress/viewport/build-module/store/index.js
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
const STORE_NAME = 'core/viewport';
/**
* Store definition for the viewport namespace.
*
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
*
* @type {Object}
*/
const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, {
reducer: store_reducer,
actions: actions_namespaceObject,
selectors: selectors_namespaceObject
});
(0,external_wp_data_namespaceObject.register)(store);
;// CONCATENATED MODULE: ./node_modules/@wordpress/viewport/build-module/listener.js
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
const addDimensionsEventListener = (breakpoints, operators) => {
/**
* Callback invoked when media query state should be updated. Is invoked a
* maximum of one time per call stack.
*/
const setIsMatching = (0,external_lodash_namespaceObject.debounce)(() => {
const values = (0,external_lodash_namespaceObject.mapValues)(queries, query => query.matches);
(0,external_wp_data_namespaceObject.dispatch)(store).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>}
*/
const queries = (0,external_lodash_namespaceObject.reduce)(breakpoints, (result, width, name) => {
Object.entries(operators).forEach(_ref => {
let [operator, condition] = _ref;
const list = window.matchMedia(`(${condition}: ${width}px)`);
list.addListener(setIsMatching);
const key = [operator, name].join(' ');
result[key] = list;
});
return result;
}, {});
window.addEventListener('orientationchange', setIsMatching); // Set initial values.
setIsMatching();
setIsMatching.flush();
};
/* harmony default export */ var listener = (addDimensionsEventListener);
;// CONCATENATED MODULE: external ["wp","compose"]
var external_wp_compose_namespaceObject = window["wp"]["compose"];
;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/extends.js
function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
;// CONCATENATED MODULE: external ["wp","element"]
var external_wp_element_namespaceObject = window["wp"]["element"];
;// CONCATENATED MODULE: ./node_modules/@wordpress/viewport/build-module/with-viewport-match.js
/**
* 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.
*
* @see isViewportMatch
*
* @param {Object} queries Object of prop name to viewport query.
*
* @example
*
* ```jsx
* function MyComponent( { isMobile } ) {
* return (
* <div>Currently: { isMobile ? 'Mobile' : 'Not Mobile' }</div>
* );
* }
*
* MyComponent = withViewportMatch( { isMobile: '< small' } )( MyComponent );
* ```
*
* @return {Function} Higher-order component.
*/
const withViewportMatch = queries => {
const useViewPortQueriesResult = () => (0,external_lodash_namespaceObject.mapValues)(queries, query => {
let [operator, breakpointName] = query.split(' ');
if (breakpointName === undefined) {
breakpointName = operator;
operator = '>=';
} // Hooks should unconditionally execute in the same order,
// we are respecting that as from the static query of the HOC we generate
// a hook that calls other hooks always in the same order (because the query never changes).
// eslint-disable-next-line react-hooks/rules-of-hooks
return (0,external_wp_compose_namespaceObject.useViewportMatch)(breakpointName, operator);
});
return (0,external_wp_compose_namespaceObject.createHigherOrderComponent)(WrappedComponent => {
return (0,external_wp_compose_namespaceObject.pure)(props => {
const queriesResult = useViewPortQueriesResult();
return (0,external_wp_element_namespaceObject.createElement)(WrappedComponent, _extends({}, props, queriesResult));
});
}, 'withViewportMatch');
};
/* harmony default export */ var with_viewport_match = (withViewportMatch);
;// CONCATENATED MODULE: ./node_modules/@wordpress/viewport/build-module/if-viewport-matches.js
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
/**
* Higher-order component creator, creating a new component which renders if
* the viewport query is satisfied.
*
* @see withViewportMatches
*
* @param {string} query Viewport query.
*
* @example
*
* ```jsx
* function MyMobileComponent() {
* return <div>I'm only rendered on mobile viewports!</div>;
* }
*
* MyMobileComponent = ifViewportMatches( '< small' )( MyMobileComponent );
* ```
*
* @return {Function} Higher-order component.
*/
const ifViewportMatches = query => (0,external_wp_compose_namespaceObject.createHigherOrderComponent)((0,external_wp_compose_namespaceObject.compose)([with_viewport_match({
isViewportMatch: query
}), (0,external_wp_compose_namespaceObject.ifCondition)(props => props.isViewportMatch)]), 'ifViewportMatches');
/* harmony default export */ var if_viewport_matches = (ifViewportMatches);
;// CONCATENATED MODULE: ./node_modules/@wordpress/viewport/build-module/index.js
/**
* Internal dependencies
*/
/**
* Hash of breakpoint names with pixel width at which it becomes effective.
*
* @see _breakpoints.scss
*
* @type {Object}
*/
const 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}
*/
const OPERATORS = {
'<': 'max-width',
'>=': 'min-width'
};
listener(BREAKPOINTS, OPERATORS);
(window.wp = window.wp || {}).viewport = __webpack_exports__;
/******/ })()
;