-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Site Editor: add Fullscreen mode #20691
Changes from 6 commits
2fa37b5
750ab90
081d4b5
92214a5
1ce8f0d
46bd27d
9e2b8de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import { render } from '@wordpress/element'; | |
* Internal dependencies | ||
*/ | ||
import './hooks'; | ||
import './store'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel this config should be reused somehow as well, some options:
Options we didn't use anywhere yet but could be good for reusabliity
I don't think it needs to be solved in this PR, but something to think about. cc @aduth if you have thoughts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To clarify, by "config", do you mean the user's general preference of "full site mode" being activated or not, across different implementations of the block editor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes. But not necessarily the persisted preference since the persisted one can be different from screen to other. (just the memory handling of the preference) |
||
import Editor from './components/editor'; | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Returns an action object used to toggle a feature flag. | ||
* | ||
* @param {string} feature Feature name. | ||
* | ||
* @return {Object} Action object. | ||
*/ | ||
export function toggleFeature( feature ) { | ||
return { | ||
type: 'TOGGLE_FEATURE', | ||
feature, | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* The identifier for the data store. | ||
* | ||
* @type {string} | ||
*/ | ||
export const STORE_KEY = 'core/edit-site'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createRegistryControl } from '@wordpress/data'; | ||
|
||
const controls = { | ||
SELECT: createRegistryControl( | ||
( registry ) => ( { storeName, selectorName, args } ) => { | ||
return registry.select( storeName )[ selectorName ]( ...args ); | ||
} | ||
), | ||
}; | ||
|
||
export default controls; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const PREFERENCES_DEFAULTS = { | ||
features: { | ||
fullscreenMode: false, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { registerStore } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import reducer from './reducer'; | ||
import * as actions from './actions'; | ||
import * as selectors from './selectors'; | ||
import controls from './controls'; | ||
import { STORE_KEY } from './constants'; | ||
|
||
const store = registerStore( STORE_KEY, { | ||
reducer, | ||
actions, | ||
selectors, | ||
controls, | ||
persist: [ 'preferences' ], | ||
} ); | ||
|
||
export default store; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { flow } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { combineReducers } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { PREFERENCES_DEFAULTS } from './defaults'; | ||
|
||
/** | ||
* Higher-order reducer creator which provides the given initial state for the | ||
* original reducer. | ||
* | ||
* @param {*} initialState Initial state to provide to reducer. | ||
* | ||
* @return {Function} Higher-order reducer. | ||
*/ | ||
const createWithInitialState = ( initialState ) => ( reducer ) => { | ||
return ( state = initialState, action ) => reducer( state, action ); | ||
}; | ||
|
||
/** | ||
* Reducer returning the user preferences. | ||
* | ||
* @param {Object} state Current state. | ||
* | ||
* @return {Object} Updated state. | ||
*/ | ||
export const preferences = flow( [ | ||
combineReducers, | ||
createWithInitialState( PREFERENCES_DEFAULTS ), | ||
] )( { | ||
features( state, action ) { | ||
if ( action.type === 'TOGGLE_FEATURE' ) { | ||
return { | ||
...state, | ||
[ action.feature ]: ! state[ action.feature ], | ||
}; | ||
} | ||
|
||
return state; | ||
}, | ||
} ); | ||
|
||
export default combineReducers( { | ||
preferences, | ||
} ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { get } from 'lodash'; | ||
|
||
/** | ||
* Returns whether the given feature is enabled or not. | ||
* | ||
* @param {Object} state Global application state. | ||
* @param {string} feature Feature slug. | ||
* | ||
* @return {boolean} Is active. | ||
*/ | ||
export function isFeatureActive( state, feature ) { | ||
return get( state.preferences.features, [ feature ], false ); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { toggleFeature } from '../actions'; | ||
|
||
describe( 'actions', () => { | ||
describe( 'toggleFeature', () => { | ||
it( 'should return TOGGLE_FEATURE action', () => { | ||
const feature = 'name'; | ||
expect( toggleFeature( feature ) ).toEqual( { | ||
type: 'TOGGLE_FEATURE', | ||
feature, | ||
} ); | ||
} ); | ||
} ); | ||
} ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import deepFreeze from 'deep-freeze'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { preferences } from '../reducer'; | ||
import { PREFERENCES_DEFAULTS } from '../defaults'; | ||
|
||
describe( 'state', () => { | ||
describe( 'preferences()', () => { | ||
it( 'should apply all defaults', () => { | ||
const state = preferences( undefined, {} ); | ||
|
||
expect( state ).toEqual( PREFERENCES_DEFAULTS ); | ||
} ); | ||
|
||
it( 'should toggle a feature flag', () => { | ||
const state = preferences( | ||
deepFreeze( { features: { chicken: true } } ), | ||
{ | ||
type: 'TOGGLE_FEATURE', | ||
feature: 'chicken', | ||
} | ||
); | ||
|
||
expect( state.features ).toEqual( { chicken: false } ); | ||
} ); | ||
} ); | ||
} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@youknowriad I'm thinking these styles should probably be moved out of
block-editor
and every editor implementation should be able to specify their own styles whenis-fullscreen-mode
class is added byFullscreenMode
component. Since bothedit-post
andedit-site
are running in the same wp-admin context, we'd probably end up duplicating the code from it, but that might be fine. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the moving, for the global style, maybe it's fine to just pick one as a convention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on our Slack discussion I moved this import to
block-editor
package in 9e2b8de.