Skip to content

Commit

Permalink
Merge branch 'master' into fix/author-dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Silverstein committed May 21, 2018
2 parents fda66b1 + 4c59823 commit 5a5af62
Show file tree
Hide file tree
Showing 46 changed files with 866 additions and 366 deletions.
2 changes: 1 addition & 1 deletion components/font-size-picker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function MyFontSizePicker() {
return (
<FontSizePicker
fontSizes={ [
{ shortName: 'S', size: 12 }
{ shortName: 'S', size: 12 },
{ shortName: 'M', size: 16 }
] }
fallbackFontSize={ fallbackFontSize }
Expand Down
1 change: 1 addition & 0 deletions core-blocks/cover-image/style.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.wp-block-cover-image {
position: relative;
background-size: cover;
background-position: center center;
min-height: 430px;
width: 100%;
margin: 0 0 1.5em 0;
Expand Down
2 changes: 1 addition & 1 deletion core-blocks/gallery/gallery-image.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* External Depenedencies
* External Dependencies
*/
import classnames from 'classnames';

Expand Down
34 changes: 19 additions & 15 deletions core-blocks/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Component, Fragment } from '@wordpress/element';
import { getBlobByURL, revokeBlobURL, viewPort } from '@wordpress/utils';
import { Component, compose, Fragment } from '@wordpress/element';
import { getBlobByURL, revokeBlobURL } from '@wordpress/utils';
import {
Button,
ButtonGroup,
Expand All @@ -38,6 +38,7 @@ import {
UrlInputButton,
editorMediaUpload,
} from '@wordpress/editor';
import { withViewportMatch } from '@wordpress/viewport';

/**
* Internal dependencies
Expand Down Expand Up @@ -167,7 +168,7 @@ class ImageEdit extends Component {
}

render() {
const { attributes, setAttributes, isSelected, className, maxWidth, toggleSelection } = this.props;
const { attributes, setAttributes, isLargeViewport, isSelected, className, maxWidth, toggleSelection } = this.props;
const { url, alt, caption, align, id, href, width, height } = attributes;

const controls = (
Expand Down Expand Up @@ -218,7 +219,7 @@ class ImageEdit extends Component {
'is-focused': isSelected,
} );

const isResizable = [ 'wide', 'full' ].indexOf( align ) === -1 && ( ! viewPort.isExtraSmall() );
const isResizable = [ 'wide', 'full' ].indexOf( align ) === -1 && isLargeViewport;

const getInspectorControls = ( imageWidth, imageHeight ) => (
<InspectorControls>
Expand Down Expand Up @@ -387,14 +388,17 @@ class ImageEdit extends Component {
}
}

export default withSelect( ( select, props ) => {
const { getMedia } = select( 'core' );
const { getEditorSettings } = select( 'core/editor' );
const { id } = props.attributes;
const { maxWidth } = getEditorSettings();

return {
image: id ? getMedia( id ) : null,
maxWidth,
};
} )( ImageEdit );
export default compose( [
withSelect( ( select, props ) => {
const { getMedia } = select( 'core' );
const { getEditorSettings } = select( 'core/editor' );
const { id } = props.attributes;
const { maxWidth } = getEditorSettings();

return {
image: id ? getMedia( id ) : null,
maxWidth,
};
} ),
withViewportMatch( { isLargeViewport: 'medium' } ),
] )( ImageEdit );
16 changes: 11 additions & 5 deletions core-blocks/paragraph/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,17 @@ class ParagraphBlock extends Component {
} }
onSplit={ insertBlocksAfter ?
( before, after, ...blocks ) => {
setAttributes( { content: before } );
insertBlocksAfter( [
...blocks,
createBlock( 'core/paragraph', { content: after } ),
] );
if ( after ) {
blocks.push( createBlock( name, { content: after } ) );
}

insertBlocksAfter( blocks );

if ( before ) {
setAttributes( { content: before } );
} else {
onReplace( [] );
}
} :
undefined
}
Expand Down
17 changes: 0 additions & 17 deletions core-data/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,6 @@
*/
import { castArray } from 'lodash';

/**
* Returns an action object used in signalling that the request for a given
* data type has been made.
*
* @param {string} dataType Data type requested.
* @param {?string} subType Optional data sub-type.
*
* @return {Object} Action object.
*/
export function setRequested( dataType, subType ) {
return {
type: 'SET_REQUESTED',
dataType,
subType,
};
}

/**
* Returns an action object used in signalling that terms have been received
* for a given taxonomy.
Expand Down
9 changes: 8 additions & 1 deletion core-data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ import * as actions from './actions';
import * as resolvers from './resolvers';
import { default as entities, getMethodName } from './entities';

/**
* The reducer key used by core data in store registration.
*
* @type {string}
*/
export const REDUCER_KEY = 'core';

const createEntityRecordGetter = ( source ) => entities.reduce( ( result, entity ) => {
const { kind, name } = entity;
const methodName = getMethodName( kind, name );
Expand All @@ -22,7 +29,7 @@ const createEntityRecordGetter = ( source ) => entities.reduce( ( result, entity
const entityResolvers = createEntityRecordGetter( resolvers );
const entitySelectors = createEntityRecordGetter( selectors );

const store = registerStore( 'core', {
const store = registerStore( REDUCER_KEY, {
reducer,
actions,
selectors: { ...selectors, ...entitySelectors },
Expand Down
11 changes: 0 additions & 11 deletions core-data/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,6 @@ export function terms( state = {}, action ) {
...state,
[ action.taxonomy ]: action.terms,
};

case 'SET_REQUESTED':
const { dataType, subType: taxonomy } = action;
if ( dataType !== 'terms' || state.hasOwnProperty( taxonomy ) ) {
return state;
}

return {
...state,
[ taxonomy ]: null,
};
}

return state;
Expand Down
2 changes: 0 additions & 2 deletions core-data/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import apiRequest from '@wordpress/api-request';
* Internal dependencies
*/
import {
setRequested,
receiveTerms,
receiveUserQuery,
receiveEntityRecords,
Expand All @@ -21,7 +20,6 @@ import { getEntity } from './entities';
* progress.
*/
export async function* getCategories() {
yield setRequested( 'terms', 'categories' );
const categories = await apiRequest( { path: '/wp/v2/categories?per_page=-1' } );
yield receiveTerms( 'categories', categories );
}
Expand Down
41 changes: 34 additions & 7 deletions core-data/selectors.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
/**
* External dependencies
*/
import createSelector from 'rememo';
import { map } from 'lodash';

/**
* WordPress dependencies
*/
import { select } from '@wordpress/data';

/**
* Internal dependencies
*/
import { REDUCER_KEY } from './';

/**
* Returns true if resolution is in progress for the core selector of the given
* name and arguments.
*
* @param {string} selectorName Core data selector name.
* @param {...*} args Arguments passed to selector.
*
* @return {boolean} Whether resolution is in progress.
*/
function isResolving( selectorName, ...args ) {
return select( 'core/data' ).isResolving( REDUCER_KEY, selectorName, ...args );
}

/**
* Returns all the available terms for the given taxonomy.
*
Expand Down Expand Up @@ -36,7 +60,7 @@ export function getCategories( state ) {
* @return {boolean} Whether a request is in progress for taxonomy's terms.
*/
export function isRequestingTerms( state, taxonomy ) {
return state.terms[ taxonomy ] === null;
return isResolving( 'getTerms', taxonomy );
}

/**
Expand All @@ -47,8 +71,8 @@ export function isRequestingTerms( state, taxonomy ) {
*
* @return {boolean} Whether a request is in progress for categories.
*/
export function isRequestingCategories( state ) {
return isRequestingTerms( state, 'categories' );
export function isRequestingCategories() {
return isResolving( 'getCategories' );
}

/**
Expand All @@ -70,11 +94,14 @@ export function getAuthors( state ) {
*
* @return {Array} Users list.
*/
export function getUserQueryResults( state, queryID ) {
const queryResults = state.users.queries[ queryID ];
export const getUserQueryResults = createSelector(
( state, queryID ) => {
const queryResults = state.users.queries[ queryID ];

return map( queryResults, ( id ) => state.users.byId[ id ] );
}
return map( queryResults, ( id ) => state.users.byId[ id ] );
},
( state, queryID ) => [ state.users.queries[ queryID ], state.users.byId ]
);

/**
* Returns the Entity's record object by key.
Expand Down
39 changes: 0 additions & 39 deletions core-data/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,45 +27,6 @@ describe( 'terms()', () => {
categories: [ { id: 1 } ],
} );
} );

it( 'assigns requested taxonomy to null', () => {
const originalState = deepFreeze( {} );
const state = terms( originalState, {
type: 'SET_REQUESTED',
dataType: 'terms',
subType: 'categories',
} );

expect( state ).toEqual( {
categories: null,
} );
} );

it( 'does not assign requested taxonomy to null if received', () => {
const originalState = deepFreeze( {
categories: [ { id: 1 } ],
} );
const state = terms( originalState, {
type: 'SET_REQUESTED',
dataType: 'terms',
subType: 'categories',
} );

expect( state ).toEqual( {
categories: [ { id: 1 } ],
} );
} );

it( 'does not assign requested taxonomy if not terms data type', () => {
const originalState = deepFreeze( {} );
const state = terms( originalState, {
type: 'SET_REQUESTED',
dataType: 'foo',
subType: 'categories',
} );

expect( state ).toEqual( {} );
} );
} );

describe( 'entities', () => {
Expand Down
4 changes: 1 addition & 3 deletions core-data/test/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import apiRequest from '@wordpress/api-request';
* Internal dependencies
*/
import { getCategories, getEntityRecord } from '../resolvers';
import { setRequested, receiveTerms, receiveEntityRecords } from '../actions';
import { receiveTerms, receiveEntityRecords } from '../actions';

jest.mock( '@wordpress/api-request' );

Expand All @@ -24,8 +24,6 @@ describe( 'getCategories', () => {

it( 'yields with requested terms', async () => {
const fulfillment = getCategories();
const requested = ( await fulfillment.next() ).value;
expect( requested.type ).toBe( setRequested().type );
const received = ( await fulfillment.next() ).value;
expect( received ).toEqual( receiveTerms( 'categories', CATEGORIES ) );
} );
Expand Down
Loading

0 comments on commit 5a5af62

Please sign in to comment.