Skip to content

Commit

Permalink
Update dependencies and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Q committed Dec 4, 2020
1 parent a6f06c5 commit 965f83d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
4 changes: 1 addition & 3 deletions package-lock.json

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

10 changes: 10 additions & 0 deletions packages/ui-utils/README.md
Expand Up @@ -45,6 +45,16 @@ Moves an array item to a different position.
See:
<https://github.com/sindresorhus/array-move#readme>

_Parameters_

- _array_ `Array`: The array containing the items to move.
- _from_ `number`: The source index.
- _to_ `number`: The destination index.

_Returns_

- `Array`: The updated array.

<a name="clearSelection" href="#clearSelection">#</a> **clearSelection**

Clears the text selection on screen.
Expand Down
2 changes: 0 additions & 2 deletions packages/ui-utils/package.json
Expand Up @@ -26,7 +26,6 @@
"dependencies": {
"@wordpress/compose": "file:../compose",
"@wordpress/element": "file:../element",
"array-move": "^3.0.1",
"create-emotion": "^10.0.27",
"deepmerge": "^4.2.2",
"fast-deep-equal": "^3.1.3",
Expand All @@ -35,7 +34,6 @@
"lodash": "^4.17.19",
"memize": "^1.1.0",
"react-merge-refs": "^1.1.0",
"react-resize-aware": "^3.0.1",
"reakit-warning": "^0.5.5",
"tinycolor2": "^1.4.1",
"use-enhanced-state": "^0.0.12",
Expand Down
23 changes: 22 additions & 1 deletion packages/ui-utils/src/arrays.js
@@ -1,10 +1,31 @@
function arrayMoveMutate( array, from, to ) {
const startIndex = from < 0 ? array.length + from : from;

if ( startIndex >= 0 && startIndex < array.length ) {
const endIndex = to < 0 ? array.length + to : to;

const [ item ] = array.splice( from, 1 );
array.splice( endIndex, 0, item );
}
}

/**
* Moves an array item to a different position.
*
* See:
* https://github.com/sindresorhus/array-move#readme
*
* @param {Array} array The array containing the items to move.
* @param {number} from The source index.
* @param {number} to The destination index.
*
* @return {Array} The updated array.
*/
export { default as arrayMove } from 'array-move';
export function arrayMove( array, from, to ) {
array = [ ...array ];
arrayMoveMutate( array, from, to );
return array;
}

/**
* Creates an array prefilled with an amount.
Expand Down

0 comments on commit 965f83d

Please sign in to comment.