Skip to content

Commit

Permalink
Move createSimpleElement to wordpress/element
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Jun 27, 2018
1 parent db6c40f commit 1634a05
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 24 deletions.
1 change: 0 additions & 1 deletion blocks/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export {
} from './registration';
export {
isUnmodifiedDefaultBlock,
createSimpleElement,
} from './utils';
export {
doBlocksMatchTemplate,
Expand Down
4 changes: 2 additions & 2 deletions blocks/api/matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { nodeListToReact, nodeToReact } from 'dom-react';
export { attr, prop, html, text, query } from 'hpq';

/**
* Internal dependencies
* WordPress dependencies
*/
import { createSimpleElement } from './utils';
import { createSimpleElement } from '@wordpress/element';

export const children = ( selector ) => {
return ( domNode ) => {
Expand Down
18 changes: 0 additions & 18 deletions blocks/api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,3 @@ export function normalizeIconObject( icon ) {
}
return icon;
}

/**
* Creates a simplified element representation.
*
* @param {string} type
* @param {Object} props
* @param {Array?} children
*
* @return {Object} Element.
*/
export function createSimpleElement( type, props, ...children ) {
return {
type, props: {
...omit( props, [ 'key' ] ),
children,
},
};
}
3 changes: 1 addition & 2 deletions editor/components/rich-text/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { nodeListToReact } from 'dom-react';
/**
* WordPress dependencies
*/
import { renderToString } from '@wordpress/element';
import { createSimpleElement } from '@wordpress/blocks';
import { renderToString, createSimpleElement } from '@wordpress/element';

/**
* Transforms a WP Element to its corresponding HTML string.
Expand Down
2 changes: 1 addition & 1 deletion editor/components/rich-text/test/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { shallow } from 'enzyme';
/**
* WordPress dependencies
*/
import { createSimpleElement } from '@wordpress/blocks';
import { createSimpleElement } from '@wordpress/element';

/**
* Internal dependencies
Expand Down
19 changes: 19 additions & 0 deletions packages/element/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
flowRight,
isString,
upperFirst,
omit,
} from 'lodash';

/**
Expand All @@ -45,6 +46,24 @@ import serialize from './serialize';
*/
export { createElement };

/**
* Creates a simplified element representation.
*
* @param {string} type
* @param {Object} props
* @param {Array?} children
*
* @return {Object} Element.
*/
export function createSimpleElement( type, props, ...children ) {
return {
type, props: {
...omit( props, [ 'key' ] ),
children,
},
};
}

/**
* Returns an object tracking a reference to a rendered element via its
* `current` property as either a DOMElement or Element, dependent upon the
Expand Down

0 comments on commit 1634a05

Please sign in to comment.