UNPKG

2.36 kBJavaScriptView Raw
1import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2import _createClass from "@babel/runtime/helpers/esm/createClass";
3import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
4import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
5import _inherits from "@babel/runtime/helpers/esm/inherits";
6
7/**
8 * WordPress dependencies
9 */
10import { Component } from '@wordpress/element';
11import { withSelect } from '@wordpress/data';
12export var FullscreenMode =
13/*#__PURE__*/
14function (_Component) {
15 _inherits(FullscreenMode, _Component);
16
17 function FullscreenMode() {
18 _classCallCheck(this, FullscreenMode);
19
20 return _possibleConstructorReturn(this, _getPrototypeOf(FullscreenMode).apply(this, arguments));
21 }
22
23 _createClass(FullscreenMode, [{
24 key: "componentDidMount",
25 value: function componentDidMount() {
26 this.isSticky = false;
27 this.sync(); // `is-fullscreen-mode` is set in PHP as a body class by Gutenberg, and this causes
28 // `sticky-menu` to be applied by WordPress and prevents the admin menu being scrolled
29 // even if `is-fullscreen-mode` is then removed. Let's remove `sticky-menu` here as
30 // a consequence of the FullscreenMode setup
31
32 if (document.body.classList.contains('sticky-menu')) {
33 this.isSticky = true;
34 document.body.classList.remove('sticky-menu');
35 }
36 }
37 }, {
38 key: "componentWillUnmount",
39 value: function componentWillUnmount() {
40 if (this.isSticky) {
41 document.body.classList.add('sticky-menu');
42 }
43 }
44 }, {
45 key: "componentDidUpdate",
46 value: function componentDidUpdate(prevProps) {
47 if (this.props.isActive !== prevProps.isActive) {
48 this.sync();
49 }
50 }
51 }, {
52 key: "sync",
53 value: function sync() {
54 var isActive = this.props.isActive;
55
56 if (isActive) {
57 document.body.classList.add('is-fullscreen-mode');
58 } else {
59 document.body.classList.remove('is-fullscreen-mode');
60 }
61 }
62 }, {
63 key: "render",
64 value: function render() {
65 return null;
66 }
67 }]);
68
69 return FullscreenMode;
70}(Component);
71export default withSelect(function (select) {
72 return {
73 isActive: select('core/edit-post').isFeatureActive('fullscreenMode')
74 };
75})(FullscreenMode);
76//# sourceMappingURL=index.js.map
\No newline at end of file