For full control building a custom material picker might be easier than customizing the built-in one.
To detect object clicks you can use onNodeTypeClicked, see: GitHub - shapespark/shapespark-viewer-api: JavaScript API for interacting with the Shapespark 3D scene..
To detect material clicks you can use onMaterialClicked, see: 'findmaterial' script doesn’t work.,,, ㅜ - #2 by kamil, provided that the material is marked as editable, see: GitHub - shapespark/shapespark-viewer-api: JavaScript API for interacting with the Shapespark 3D scene.
To change a material on an object you can use setMaterialForMesh, see: How to emulate the Material picker via the API