Skip to content

Commit e8d963e

Browse files
authored
Merge pull request #750 from 10up/feature/gutenberg-fullscreen-support
Add better support for the block editor's fullscreen mode
2 parents 8f048e4 + 8d64062 commit e8d963e

File tree

11 files changed

+401
-81
lines changed

11 files changed

+401
-81
lines changed

assets/css/admin-distributed-post.css

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,3 @@
1212
.open-distributor-help {
1313
cursor: pointer;
1414
}
15-
16-
#distributed-to:before {
17-
content: ' ';
18-
display: inline-block;
19-
top: 5px;
20-
padding-right: 25px;
21-
width: 20px;
22-
height: 20px;
23-
background: url(../../assets/img/icon.svg) no-repeat top left;
24-
background-size: contain;
25-
position: relative;
26-
}

assets/css/admin.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,22 @@
1111
font-weight: bold;
1212
font-size: 14px;
1313
}
14+
15+
@media (min-width: 783px) {
16+
body.is-showing-distributor.is-fullscreen-mode #wpadminbar {
17+
display: block;
18+
}
19+
20+
body.is-showing-distributor.is-fullscreen-mode .interface-interface-skeleton {
21+
top: 32px;
22+
}
23+
}
24+
25+
.distributor-panel .components-panel__body-title svg {
26+
height: 20px;
27+
width: 20px;
28+
}
29+
30+
.distributor-toggle {
31+
margin-bottom: 8px;
32+
}

assets/css/gutenberg-syndicated-post.css

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,3 @@ body.dt-linked-post {
5959
#distributed-from a {
6060
vertical-align: top;
6161
}
62-
63-
#distributed-from:before {
64-
content: ' ';
65-
display: inline-block;
66-
top: -1px;
67-
padding-right: 2px;
68-
width: 20px;
69-
height: 20px;
70-
background: url(../../assets/img/icon.svg) no-repeat top left;
71-
background-size: contain;
72-
position: relative;
73-
}

assets/css/push.css

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
@custom-media --small-screen (min-width: 480px);
1111
@custom-media --medium-screen (min-width: 768px);
12+
@custom-media --gutenberg-small-screen (max-width: 782px);
1213

1314
#distributor-push-wrapper,
1415
#wpadminbar #wp-admin-bar-distributor-placeholder > .ab-item {
@@ -47,17 +48,20 @@
4748
display: block;
4849
}
4950

50-
#wp-admin-bar-distributor.hover::before,
51-
#wp-admin-bar-distributor.syncing::before {
51+
#distributor-overlay {
52+
display: none;
5253
position: fixed;
5354
top: 0;
5455
left: 0;
5556
right: 0;
5657
bottom: 0;
57-
background: rgba(0,0,0,0.6);
58-
z-index: -1;
59-
content: '';
60-
pointer-events: none;
58+
background: rgba(0, 0, 0, 0.6);
59+
z-index: 10000;
60+
61+
&.show,
62+
&.syncing {
63+
display: block;
64+
}
6165
}
6266

6367
#wpadminbar #distributor-push-wrapper .inner {
@@ -432,6 +436,12 @@
432436
}
433437
}
434438

439+
.distributor-panel {
440+
@media (--gutenberg-small-screen) {
441+
display: none;
442+
}
443+
}
444+
435445
#distributor-push-wrapper .loader-item,
436446
#distributor-push-wrapper .loader-item *,
437447
#distributor-push-wrapper .loader-item ::after,

assets/js/gutenberg-plugin.js

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
import { wp, dtGutenberg } from 'window';
2+
import PluginIcon from '../img/icon.svg'; // eslint-disable-line no-unused-vars
3+
4+
const { Icon } = wp.components; // eslint-disable-line no-unused-vars
5+
const { select, useSelect } = wp.data;
6+
const { PluginDocumentSettingPanel } = wp.editPost; // eslint-disable-line no-unused-vars
7+
const { __, sprintf } = wp.i18n;
8+
const { registerPlugin } = wp.plugins;
9+
10+
/**
11+
* Add ability to show the admin bar, if needed
12+
*/
13+
const RenderShowAdminBar = () => { // eslint-disable-line no-unused-vars
14+
const bodyClasses = document.body.classList;
15+
const isFullScreenMode = select( 'core/edit-post' ).isFeatureActive( 'fullscreenMode' );
16+
const distributorTopMenu = document.querySelector( '#wp-admin-bar-distributor' );
17+
const distributorAdminItem = document.querySelector( '#wp-admin-bar-distributor > a' );
18+
19+
// Don't show anything if this is a distributed item
20+
if ( 0 !== parseInt( dtGutenberg.syndicationTime ) ) {
21+
return null;
22+
}
23+
24+
if ( ! distributorTopMenu || ! distributorAdminItem ) {
25+
return (
26+
<div className="distributor-toggle">
27+
<span>{ __( 'Refresh page to see distribution options', 'distributor' ) }</span>
28+
</div>
29+
);
30+
}
31+
32+
return (
33+
<div className="distributor-toggle">
34+
<button
35+
className="components-button is-secondary"
36+
type="button"
37+
onClick={ () => {
38+
const mouseEvent = new MouseEvent( 'mouseenter' );
39+
40+
if ( isFullScreenMode ) {
41+
bodyClasses.add( 'is-showing-distributor' );
42+
} else {
43+
bodyClasses.remove( 'is-showing-distributor' );
44+
}
45+
46+
distributorTopMenu.classList.toggle( 'hover' );
47+
distributorAdminItem.dispatchEvent( mouseEvent );
48+
} }
49+
>
50+
{ sprintf( __( 'Distribute %1$s', 'distributor' ), dtGutenberg.postTypeSingular || 'Content' ) }
51+
</button>
52+
</div>
53+
);
54+
};
55+
56+
/**
57+
* Render the draft message
58+
*/
59+
const RenderDraftMessage = () => { // eslint-disable-line no-unused-vars
60+
if ( 0 !== parseInt( dtGutenberg.syndicationTime ) ) {
61+
return null;
62+
}
63+
64+
return (
65+
<p>
66+
{ __( 'Distribution options available once published', 'distributor' ) }
67+
</p>
68+
);
69+
};
70+
71+
/**
72+
* Render the distribution information, if needed
73+
*/
74+
const RenderDistributionInfo = () => { // eslint-disable-line no-unused-vars
75+
if ( 0 < parseInt( dtGutenberg.syndicationCount ) ) {
76+
return <RenderDistributedTo />;
77+
} else if ( 0 !== parseInt( dtGutenberg.syndicationTime ) ) {
78+
return <RenderDistributedFrom />;
79+
}
80+
81+
return null;
82+
};
83+
84+
/**
85+
* Render the distributed to component
86+
*/
87+
const RenderDistributedTo = () => { // eslint-disable-line no-unused-vars
88+
return(
89+
<span id='distributed-to'>
90+
{ sprintf( __( 'Distributed to %1$s connection%2$s.', 'distributor' ),
91+
dtGutenberg.syndicationCount,
92+
'1' === dtGutenberg.syndicationCount ? '' : 's' ) }
93+
</span>
94+
);
95+
};
96+
97+
/**
98+
* Render the distributed from component
99+
*/
100+
const RenderDistributedFrom = () => { // eslint-disable-line no-unused-vars
101+
return(
102+
<span id='distributed-from'>
103+
{ __( 'Distributed on: ', 'distributor' ) }
104+
<strong> { dtGutenberg.syndicationTime } </strong>
105+
</span>
106+
);
107+
};
108+
109+
/**
110+
* Create the Distributor icon
111+
*/
112+
const DistributorIcon = () => (
113+
<Icon
114+
className="components-panel__icon"
115+
icon={ <PluginIcon /> }
116+
size={ 20 }
117+
/>
118+
);
119+
120+
/**
121+
* Add the Distributor panel to Gutenberg
122+
*/
123+
const DistributorPlugin = () => {
124+
// Ensure the user has proper permissions
125+
if ( dtGutenberg.noPermissions && 1 === parseInt( dtGutenberg.noPermissions ) ) {
126+
return null;
127+
}
128+
129+
const postType = useSelect( select => select( 'core/editor' ).getCurrentPostType() );
130+
const postStatus = useSelect( select => select( 'core/editor' ).getCurrentPostAttribute( 'status' ) );
131+
132+
// Ensure we are on a supported post type
133+
if ( dtGutenberg.supportedPostTypes && dtGutenberg.supportedPostTypes[ postType ] === undefined ) {
134+
return null;
135+
}
136+
137+
// If we are on a non-supported post status, change what we show
138+
if ( dtGutenberg.supportedPostStati && ! dtGutenberg.supportedPostStati.includes( postStatus ) ) {
139+
return (
140+
<PluginDocumentSettingPanel
141+
title={ __( 'Distributor', 'distributor' ) }
142+
icon={ DistributorIcon }
143+
className="distributor-panel"
144+
>
145+
<RenderDraftMessage />
146+
<RenderDistributionInfo />
147+
</PluginDocumentSettingPanel>
148+
);
149+
}
150+
151+
return (
152+
<PluginDocumentSettingPanel
153+
title={ __( 'Distributor', 'distributor' ) }
154+
icon={ DistributorIcon }
155+
className="distributor-panel"
156+
>
157+
<RenderShowAdminBar />
158+
<RenderDistributionInfo />
159+
</PluginDocumentSettingPanel>
160+
);
161+
};
162+
163+
registerPlugin( 'distributor-plugin', { render: DistributorPlugin } );

assets/js/gutenberg-status-plugin.js

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)