Skip to content

Commit 90d2c45

Browse files
author
ricwilson
committed
feat: enhance documentation for crop utility functions and image crop control methods
1 parent a9b0b8a commit 90d2c45

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

ImageCrop/ImageCrop/components/imageCropControl.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from "react";
2-
import { convertToPixelCrop, Crop, PixelCrop } from "react-image-crop";
2+
import { Crop, PixelCrop } from "react-image-crop";
33
import "react-image-crop/dist/ReactCrop.css";
44
import { usePcfContext } from "../services/pcfContext";
55
import { IImageCropControlProps } from "../types/imageCropTypes";

ImageCrop/ImageCrop/index.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ export class ImageCrop implements ComponentFramework.StandardControl<IInputs, IO
5050
this._reactRoot = ReactDOM.createRoot(this._container);
5151
}
5252

53+
/**
54+
* Returns the output schema for the control, used by Power Apps to validate the shape of output properties.
55+
* This is required for controls with object-typed outputs (e.g., actionOutput).
56+
* @param context The PCF context object
57+
* @returns A promise resolving to the output schema object
58+
*/
5359
public async getOutputSchema(context: ComponentFramework.Context<IInputs>): Promise<Record<string, unknown>> {
5460
return Promise.resolve({
5561
actionOutput: ActionOutputSchema
@@ -74,14 +80,22 @@ export class ImageCrop implements ComponentFramework.StandardControl<IInputs, IO
7480
);
7581
}
7682

77-
// Callback for crop complete
83+
/**
84+
* Callback invoked when a crop operation is completed.
85+
* Sets the crop result and triggers output notification.
86+
* @param results The base64 string of the cropped image
87+
*/
7888
public onCropComplete = (results: string) => {
7989
this._actionCropComplete = true;
8090
this._cropResults = results;
8191
this._notifyOutputChanged();
8292
};
8393

84-
// Callback for drag start
94+
/**
95+
* Callback invoked when a drag operation starts on the crop area.
96+
* Sets the action output to 'dragStart' and pointer coordinates, then notifies output change.
97+
* @param e PointerEvent from the drag start
98+
*/
8599
public onDragStart = (e: PointerEvent) => {
86100
this._actionDragStart = true;
87101
this._actionOutput = {
@@ -92,7 +106,11 @@ export class ImageCrop implements ComponentFramework.StandardControl<IInputs, IO
92106
this._notifyOutputChanged();
93107
};
94108

95-
// Callback for drag end
109+
/**
110+
* Callback invoked when a drag operation ends on the crop area.
111+
* Sets the action output to 'dragEnd' and pointer coordinates, then notifies output change.
112+
* @param e PointerEvent from the drag end
113+
*/
96114
public onDragEnd = (e: PointerEvent) => {
97115
this._actionDragEnd = true;
98116
this._actionOutput = {

ImageCrop/ImageCrop/utils/cropUtils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
/**
2+
* Utility functions for crop calculations in the Image Cropper PCF control.
3+
* Provides helpers for centering and constraining aspect ratio crops.
4+
*/
15
import { Crop, makeAspectCrop, centerCrop } from "react-image-crop";
26

7+
/**
8+
* Calculates a centered crop rectangle with a given aspect ratio, sized to fit within the media dimensions.
9+
* The crop will be 90% of the media width, centered, and constrained to the aspect ratio.
10+
* @param mediaWidth The width of the image or video
11+
* @param mediaHeight The height of the image or video
12+
* @param aspect The desired aspect ratio (width / height)
13+
* @returns A Crop object representing the centered aspect crop
14+
*/
315
export function centerAspectCrop(
416
mediaWidth: number,
517
mediaHeight: number,

0 commit comments

Comments
 (0)