@wordpress/edit-post
Version:
Edit Post module for WordPress.
76 lines (69 loc) • 2.36 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/esm/inherits";
/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { withSelect } from '@wordpress/data';
export var FullscreenMode =
/*#__PURE__*/
function (_Component) {
_inherits(FullscreenMode, _Component);
function FullscreenMode() {
_classCallCheck(this, FullscreenMode);
return _possibleConstructorReturn(this, _getPrototypeOf(FullscreenMode).apply(this, arguments));
}
_createClass(FullscreenMode, [{
key: "componentDidMount",
value: function componentDidMount() {
this.isSticky = false;
this.sync(); // `is-fullscreen-mode` is set in PHP as a body class by Gutenberg, and this causes
// `sticky-menu` to be applied by WordPress and prevents the admin menu being scrolled
// even if `is-fullscreen-mode` is then removed. Let's remove `sticky-menu` here as
// a consequence of the FullscreenMode setup
if (document.body.classList.contains('sticky-menu')) {
this.isSticky = true;
document.body.classList.remove('sticky-menu');
}
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
if (this.isSticky) {
document.body.classList.add('sticky-menu');
}
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps) {
if (this.props.isActive !== prevProps.isActive) {
this.sync();
}
}
}, {
key: "sync",
value: function sync() {
var isActive = this.props.isActive;
if (isActive) {
document.body.classList.add('is-fullscreen-mode');
} else {
document.body.classList.remove('is-fullscreen-mode');
}
}
}, {
key: "render",
value: function render() {
return null;
}
}]);
return FullscreenMode;
}(Component);
export default withSelect(function (select) {
return {
isActive: select('core/edit-post').isFeatureActive('fullscreenMode')
};
})(FullscreenMode);
//# sourceMappingURL=index.js.map