diff --git a/package-lock.json b/package-lock.json index 04c0cad1e4c78..79c6ad6c89a85 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18335,9 +18335,8 @@ "@wordpress/ui-utils": { "version": "file:packages/ui-utils", "requires": { + "@wordpress/compose": "file:packages/compose", "@wordpress/element": "file:packages/element", - "array-move": "^3.0.1", - "copy-to-clipboard": "^3.3.1", "create-emotion": "^10.0.27", "deepmerge": "^4.2.2", "fast-deep-equal": "^3.1.3", @@ -18346,7 +18345,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", diff --git a/packages/ui-utils/README.md b/packages/ui-utils/README.md index c71cfc0623a44..1de67b32073fe 100644 --- a/packages/ui-utils/README.md +++ b/packages/ui-utils/README.md @@ -45,6 +45,16 @@ Moves an array item to a different position. See: +_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. + # **clearSelection** Clears the text selection on screen. diff --git a/packages/ui-utils/package.json b/packages/ui-utils/package.json index 598e5b66b99e2..df6c4221e6d24 100644 --- a/packages/ui-utils/package.json +++ b/packages/ui-utils/package.json @@ -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", @@ -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", diff --git a/packages/ui-utils/src/arrays.js b/packages/ui-utils/src/arrays.js index 3cccc3da2d683..ef4635ebbc94c 100644 --- a/packages/ui-utils/src/arrays.js +++ b/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.