-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2fa37b5
Site Editor: add Fullscreen mode
vindl 750ab90
Move FullscreenMode component to block-editor package
vindl 081d4b5
Create edit-site store
vindl 92214a5
Carry over relevant Preferenes tests from edit-post package
vindl 1ce8f0d
Remove obsolete code
vindl 46bd27d
Remove obsolete edit-post package dependency
vindl 9e2b8de
Move style import to block-editor package
vindl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const PREFERENCES_DEFAULTS = { | ||
features: { | ||
fullscreenMode: false, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} ); | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } ); | ||
} ); | ||
} ); | ||
} ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 feel this config should be reused somehow as well, some options:
Options we didn't use anywhere yet but could be good for reusabliity
wp.data.registerStore( 'core/edit-post-full-screen', fullscreenStoreConfig )
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 comment
The 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 comment
The 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)