Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/WordPress/gutenberg into …
Browse files Browse the repository at this point in the history
…rnmobile/fix-validation-errorrs-after-block-splitting

* 'master' of https://github.com/WordPress/gutenberg:
  Add some new url helper functions (#10885)
  Components: Avoid SlotFill props destructuring (#10921)
  Update Package Changelogs (#10887)
  chore(release): publish
  Update plugin version to 4.1 RC2. (#10893)
  • Loading branch information
daniloercoli committed Oct 23, 2018
2 parents b98b361 + 898f2f7 commit 45ed0da
Show file tree
Hide file tree
Showing 24 changed files with 158 additions and 27 deletions.
2 changes: 1 addition & 1 deletion gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Gutenberg
* Plugin URI: https://github.com/WordPress/gutenberg
* Description: Printing since 1440. This is the development plugin for the new block editor in core.
* Version: 4.1.0-rc.1
* Version: 4.1.0-rc.2
* Author: Gutenberg Team
*
* @package gutenberg
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gutenberg",
"version": "4.1.0-rc.1",
"version": "4.1.0-rc.2",
"private": true,
"description": "A new WordPress editor experience",
"repository": "git+https://github.com/WordPress/gutenberg.git",
Expand Down
2 changes: 1 addition & 1 deletion packages/api-fetch/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 2.1.0 (Unreleased)
## 2.1.0 (2018-10-22)

- Support `per_page=-1` paginated requests.

Expand Down
2 changes: 1 addition & 1 deletion packages/api-fetch/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/api-fetch",
"version": "2.0.2",
"version": "2.1.0",
"description": "Utility to make WordPress REST API requests.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
6 changes: 6 additions & 0 deletions packages/block-library/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2.1.4 (2018-10-22)

### Bug Fixes

- Video Block: Set correct media types for the poster image.

## 2.1.3 (2018-10-19)

## 2.1.2 (2018-10-18)
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/block-library",
"version": "2.1.3",
"version": "2.1.4",
"description": "Block library for the WordPress editor.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 1 addition & 1 deletion packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 4.2.1 (Unreleased)
## 4.2.1 (2018-10-22)

### Bug Fix

Expand Down
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/components",
"version": "4.2.0",
"version": "4.2.1",
"description": "UI components for WordPress.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
12 changes: 2 additions & 10 deletions packages/components/src/slot-fill/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,10 @@ export { Fill };
export { Provider };

export function createSlotFill( name ) {
const FillComponent = ( { children, ...props } ) => (
<Fill name={ name } { ...props }>
{ children }
</Fill>
);
const FillComponent = ( props ) => <Fill name={ name } { ...props } />;
FillComponent.displayName = name + 'Fill';

const SlotComponent = ( { children, ...props } ) => (
<Slot name={ name } { ...props }>
{ children }
</Slot>
);
const SlotComponent = ( props ) => <Slot name={ name } { ...props } />;
SlotComponent.displayName = name + 'Slot';

return {
Expand Down
2 changes: 2 additions & 0 deletions packages/core-data/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 2.0.6 (2018-10-22)

## 2.0.5 (2018-10-19)

## 2.0.4 (2018-10-18)
Expand Down
2 changes: 1 addition & 1 deletion packages/core-data/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/core-data",
"version": "2.0.5",
"version": "2.0.6",
"description": "Access to and manipulation of core WordPress entities.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-post/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 1.0.4 (Unreleased)
## 1.0.4 (2018-10-22)

## Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion packages/edit-post/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/edit-post",
"version": "1.0.3",
"version": "1.0.4",
"description": "Edit Post module for WordPress.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 5.0.1 (2018-10-22)

## 5.0.0 (2018-10-19)

### Breaking Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/editor",
"version": "5.0.0",
"version": "5.0.1",
"description": "Building blocks for WordPress editors.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 2 additions & 0 deletions packages/list-reusable-blocks/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 1.1.4 (2018-10-22)

## 1.1.3 (2018-10-19)

## 1.1.2 (2018-10-18)
Expand Down
2 changes: 1 addition & 1 deletion packages/list-reusable-blocks/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/list-reusable-blocks",
"version": "1.1.3",
"version": "1.1.4",
"description": "Adding Export/Import support to the reusable blocks listing.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 2 additions & 0 deletions packages/nux/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 2.0.6 (2018-10-22)

## 2.0.5 (2018-10-19)

## 2.0.4 (2018-10-18)
Expand Down
2 changes: 1 addition & 1 deletion packages/nux/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/nux",
"version": "2.0.5",
"version": "2.0.6",
"description": "NUX (New User eXperience) module for WordPress.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
8 changes: 8 additions & 0 deletions packages/url/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 2.2.0 (Unreleased)

### Features

- Added `getQueryArg`.
- Added `hasQueryArg`.
- Added `removeQueryArgs`.

## 2.1.0 (2018-10-16)

### Features
Expand Down
9 changes: 9 additions & 0 deletions packages/url/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ const newURL = addQueryArgs( 'https://google.com', { q: 'test' } ); // https://

// Prepends 'http://' to URLs that are probably mean to have them
const actualURL = prependHTTP( 'wordpress.org' ); // http://wordpress.org

// Gets a single query arg from the given URL.
const foo = getQueryArg( 'https://wordpress.org?foo=bar&bar=baz', 'foo' ); // bar

// Checks whether a URL contains a given query arg.
const hasBar = hasQueryArg( 'https://wordpress.org?foo=bar&bar=baz', 'bar' ); // true

// Removes one or more query args from the given URL.
const newUrl = removeQueryArgs( 'https://wordpress.org?foo=bar&bar=baz&baz=foobar', 'foo', 'bar' ); // https://wordpress.org?baz=foobar
```

<br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
51 changes: 48 additions & 3 deletions packages/url/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export function isURL( url ) {
/**
* Appends arguments to the query string of the url
*
* @param {string} url URL
* @param {Object} args Query Args
* @param {string} url URL
* @param {Object} args Query Args
*
* @return {string} Updated URL
* @return {string} Updated URL
*/
export function addQueryArgs( url, args ) {
const queryStringIndex = url.indexOf( '?' );
Expand All @@ -34,6 +34,51 @@ export function addQueryArgs( url, args ) {
return baseUrl + '?' + stringify( { ...query, ...args } );
}

/**
* Returns a single query argument of the url
*
* @param {string} url URL
* @param {string} arg Query arg name
*
* @return {Array|string} Query arg value.
*/
export function getQueryArg( url, arg ) {
const queryStringIndex = url.indexOf( '?' );
const query = queryStringIndex !== -1 ? parse( url.substr( queryStringIndex + 1 ) ) : {};

return query[ arg ];
}

/**
* Determines whether the URL contains a given query arg.
*
* @param {string} url URL
* @param {string} arg Query arg name
*
* @return {boolean} Whether or not the URL contains the query aeg.
*/
export function hasQueryArg( url, arg ) {
return getQueryArg( url, arg ) !== undefined;
}

/**
* Removes arguments from the query string of the url
*
* @param {string} url URL
* @param {...string} args Query Args
*
* @return {string} Updated URL
*/
export function removeQueryArgs( url, ...args ) {
const queryStringIndex = url.indexOf( '?' );
const query = queryStringIndex !== -1 ? parse( url.substr( queryStringIndex + 1 ) ) : {};
const baseUrl = queryStringIndex !== -1 ? url.substr( 0, queryStringIndex ) : url;

args.forEach( ( arg ) => delete query[ arg ] );

return baseUrl + '?' + stringify( query );
}

/**
* Prepends "http://" to a url, if it looks like something that is meant to be a TLD.
*
Expand Down
63 changes: 63 additions & 0 deletions packages/url/src/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { every } from 'lodash';
import {
isURL,
addQueryArgs,
getQueryArg,
hasQueryArg,
removeQueryArgs,
prependHTTP,
safeDecodeURI,
} from '../';
Expand Down Expand Up @@ -69,6 +72,66 @@ describe( 'addQueryArgs', () => {
} );
} );

describe( 'getQueryArg', () => {
it( 'should get the value of an existing query arg', () => {
const url = 'https://andalouses.example/beach?foo=bar&bar=baz';

expect( getQueryArg( url, 'foo' ) ).toBe( 'bar' );
} );

it( 'should not return a value of an unknown query arg', () => {
const url = 'https://andalouses.example/beach?foo=bar&bar=baz';

expect( getQueryArg( url, 'baz' ) ).toBeUndefined();
} );

it( 'should get the value of an arry query arg', () => {
const url = 'https://andalouses.example/beach?foo[]=bar&foo[]=baz';

expect( getQueryArg( url, 'foo' ) ).toEqual( [ 'bar', 'baz' ] );
} );
} );

describe( 'hasQueryArg', () => {
it( 'should return true for an existing query arg', () => {
const url = 'https://andalouses.example/beach?foo=bar&bar=baz';

expect( hasQueryArg( url, 'foo' ) ).toBeTruthy();
} );

it( 'should return false for an unknown query arg', () => {
const url = 'https://andalouses.example/beach?foo=bar&bar=baz';

expect( hasQueryArg( url, 'baz' ) ).toBeFalsy();
} );

it( 'should return true for an arry query arg', () => {
const url = 'https://andalouses.example/beach?foo[]=bar&foo[]=baz';

expect( hasQueryArg( url, 'foo' ) ).toBeTruthy();
} );
} );

describe( 'removeQueryArgs', () => {
it( 'should not change URL not containing query args', () => {
const url = 'https://andalouses.example/beach?foo=bar&bar=baz';

expect( removeQueryArgs( url, 'baz', 'test' ) ).toEqual( url );
} );

it( 'should remove existing query args', () => {
const url = 'https://andalouses.example/beach?foo=bar&baz=foo&bar=baz';

expect( removeQueryArgs( url, 'foo', 'bar' ) ).toEqual( 'https://andalouses.example/beach?baz=foo' );
} );

it( 'should remove array query arg', () => {
const url = 'https://andalouses.example/beach?foo[]=bar&foo[]=baz&bar=foobar';

expect( removeQueryArgs( url, 'foo' ) ).toEqual( 'https://andalouses.example/beach?bar=foobar' );
} );
} );

describe( 'prependHTTP', () => {
it( 'should prepend http to a domain', () => {
const url = 'wordpress.org';
Expand Down

0 comments on commit 45ed0da

Please sign in to comment.