Skip to content

Commit

Permalink
Fixes cherry-picked to be included in WordPress 5.3.1 (#18932)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored Dec 5, 2019
1 parent d088ec2 commit f79aef2
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 15 deletions.
12 changes: 6 additions & 6 deletions packages/block-editor/src/components/typewriter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class Typewriter extends Component {
return;
}

const diff = currentCaretRect.y - this.caretRect.y;
const diff = currentCaretRect.top - this.caretRect.top;

if ( diff === 0 ) {
return;
Expand All @@ -148,10 +148,10 @@ class Typewriter extends Component {
scrollContainer.scrollTop;
const scrollContainerY = windowScroll ?
0 :
scrollContainer.getBoundingClientRect().y;
scrollContainer.getBoundingClientRect().top;
const relativeScrollPosition = windowScroll ?
this.caretRect.y / window.innerHeight :
( this.caretRect.y - scrollContainerY ) /
this.caretRect.top / window.innerHeight :
( this.caretRect.top - scrollContainerY ) /
( window.innerHeight - scrollContainerY );

// If the scroll position is at the start, the active editable element
Expand All @@ -178,10 +178,10 @@ class Typewriter extends Component {
// view.
if (
// The caret is under the lower fold.
this.caretRect.y + this.caretRect.height >
this.caretRect.top + this.caretRect.height >
scrollContainerY + scrollContainerHeight ||
// The caret is above the upper fold.
this.caretRect.y < scrollContainerY
this.caretRect.top < scrollContainerY
) {
// Reset the caret position to maintain.
this.caretRect = currentCaretRect;
Expand Down
6 changes: 5 additions & 1 deletion packages/block-library/src/embed/core-embeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,17 @@ export const others = [
patterns: [ /^https?:\/\/cloudup\.com\/.+/i ],
},
{
// Deprecated since CollegeHumor content is now powered by YouTube
name: 'core-embed/collegehumor',
settings: {
title: 'CollegeHumor',
icon: embedVideoIcon,
description: __( 'Embed CollegeHumor content.' ),
supports: {
inserter: false,
},
},
patterns: [ /^https?:\/\/(www\.)?collegehumor\.com\/.+/i ],
patterns: [],
},
{
name: 'core-embed/crowdsignal',
Expand Down
10 changes: 5 additions & 5 deletions packages/core-data/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ export function receiveEmbedPreview( url, preview ) {
* @return {Object} Action object.
*/
export function* editEntityRecord( kind, name, recordId, edits, options = {} ) {
const { transientEdits = {}, mergedEdits = {} } = yield select(
'getEntity',
kind,
name
);
const entity = yield select( 'getEntity', kind, name );
if ( ! entity ) {
throw new Error( `The entity being edited (${ kind }, ${ name }) does not have a loaded config.` );
}
const { transientEdits = {}, mergedEdits = {} } = entity;
const record = yield select( 'getRawEntityRecord', kind, name, recordId );
const editedRecord = yield select(
'getEditedEntityRecord',
Expand Down
7 changes: 5 additions & 2 deletions packages/core-data/src/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,11 @@ export function getEntityRecordEdits( state, kind, name, recordId ) {
*/
export const getEntityRecordNonTransientEdits = createSelector(
( state, kind, name, recordId ) => {
const { transientEdits = {} } = getEntity( state, kind, name );
const edits = getEntityRecordEdits( state, kind, name, recordId ) || [];
const { transientEdits } = getEntity( state, kind, name ) || {};
const edits = getEntityRecordEdits( state, kind, name, recordId ) || {};
if ( ! transientEdits ) {
return edits;
}
return Object.keys( edits ).reduce( ( acc, key ) => {
if ( ! transientEdits[ key ] ) {
acc[ key ] = edits[ key ];
Expand Down
29 changes: 28 additions & 1 deletion packages/core-data/src/test/actions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
/**
* Internal dependencies
*/
import { saveEntityRecord, receiveEntityRecords, receiveUserPermission, receiveAutosaves, receiveCurrentUser } from '../actions';
import {
editEntityRecord,
saveEntityRecord,
receiveEntityRecords,
receiveUserPermission,
receiveAutosaves,
receiveCurrentUser,
} from '../actions';
import { select } from '../controls';

describe( 'editEntityRecord', () => {
it( 'throws when the edited entity does not have a loaded config.', () => {
const entity = { kind: 'someKind', name: 'someName', id: 'someId' };
const fulfillment = editEntityRecord(
entity.kind,
entity.name,
entity.id,
{}
);
expect( fulfillment.next().value ).toEqual(
select( 'getEntity', entity.kind, entity.name )
);
// Don't pass back an entity config.
expect( fulfillment.next.bind( fulfillment ) ).toThrow(
`The entity being edited (${ entity.kind }, ${ entity.name }) does not have a loaded config.`
);
} );
} );

describe( 'saveEntityRecord', () => {
it( 'triggers a POST request for a new record', async () => {
Expand Down
12 changes: 12 additions & 0 deletions packages/core-data/src/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import deepFreeze from 'deep-freeze';
import {
getEntityRecord,
getEntityRecords,
getEntityRecordNonTransientEdits,
getEmbedPreview,
isPreviewEmbedFallback,
canUser,
Expand Down Expand Up @@ -104,6 +105,17 @@ describe( 'getEntityRecords', () => {
} );
} );

describe( 'getEntityRecordNonTransientEdits', () => {
it( 'should return an empty object when the entity does not have a loaded config.', () => {
const state = deepFreeze( {
entities: { config: {}, data: {} },
} );
expect(
getEntityRecordNonTransientEdits( state, 'someKind', 'someName', 'someId' )
).toEqual( {} );
} );
} );

describe( 'getEmbedPreview()', () => {
it( 'returns preview stored for url', () => {
let state = deepFreeze( {
Expand Down

0 comments on commit f79aef2

Please sign in to comment.