import {isObject} from '../../utils/helpers' /** * The helper applies transforms added via user input to the incoming props. * * @remarks * A user's values can come attached with a `transforms` key which can contain a lookup that associates certain value keys with further augmentation. For example, if a user has selected an asset for asset field named `socialImage` and then applied a custom crop to it, the `transforms` object would contain a `socialImage` key with data for the crop. This `applyTransforms `helper will detect the presence of this transform and apply it to the top-level `socialImage` value. The template component does not need to handle any conditional logic for cropped images to be displayed. * * @param obj - the object of data that may contain transforms * @returns the object of data with transforms applied, if any are supplied * @internal */ export const applyTransforms = (obj: T): T => { const transforms = obj.transforms ? Object.entries(obj.transforms) : [] transforms.forEach(([key, transform]) => { const initialValue = obj[key] if (isObject(initialValue) && isObject(transform)) { obj[key] = { ...initialValue, ...transform, } } }) return obj }