-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2670 from microsoft/u/juliaroldi/image-edit-opera…
…tions Port Image Edit Operations
- Loading branch information
Showing
75 changed files
with
4,948 additions
and
157 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
demo/scripts/controlsV2/demoButtons/createImageEditButtons.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { ImageEditor } from 'roosterjs-content-model-types'; | ||
import type { RibbonButton } from '../roosterjsReact/ribbon'; | ||
|
||
/** | ||
* @internal | ||
* "Image Crop" button on the format ribbon | ||
*/ | ||
function createImageCropButton(handler: ImageEditor): RibbonButton<'buttonNameCropImage'> { | ||
return { | ||
key: 'buttonNameCropImage', | ||
unlocalizedText: 'Crop Image', | ||
iconName: 'Crop', | ||
isDisabled: formatState => | ||
!formatState.canAddImageAltText || !handler.isOperationAllowed('crop'), | ||
onClick: () => { | ||
handler.cropImage(); | ||
}, | ||
}; | ||
} | ||
|
||
const directions: Record<string, string> = { | ||
left: 'Left', | ||
right: 'Right', | ||
}; | ||
|
||
/** | ||
* @internal | ||
* "Image Rotate" button on the format ribbon | ||
*/ | ||
function createImageRotateButton(handler: ImageEditor): RibbonButton<'buttonNameRotateImage'> { | ||
return { | ||
key: 'buttonNameRotateImage', | ||
unlocalizedText: 'Rotate Image', | ||
iconName: 'Rotate', | ||
dropDownMenu: { | ||
items: directions, | ||
}, | ||
isDisabled: formatState => !formatState.canAddImageAltText, | ||
onClick: (_editor, direction) => { | ||
const rotateDirection = direction as 'left' | 'right'; | ||
const rad = degreeToRad(rotateDirection == 'left' ? 270 : 90); | ||
handler.rotateImage(rad); | ||
}, | ||
}; | ||
} | ||
|
||
const flipDirections: Record<string, string> = { | ||
horizontal: 'horizontal', | ||
vertical: 'vertical', | ||
}; | ||
|
||
/** | ||
* @internal | ||
* "Image Flip" button on the format ribbon | ||
*/ | ||
function createImageFlipButton(handler: ImageEditor): RibbonButton<'buttonNameFlipImage'> { | ||
return { | ||
key: 'buttonNameFlipImage', | ||
unlocalizedText: 'Flip Image', | ||
iconName: 'ImagePixel', | ||
dropDownMenu: { | ||
items: flipDirections, | ||
}, | ||
isDisabled: formatState => !formatState.canAddImageAltText, | ||
onClick: (_editor, flipDirection) => { | ||
handler.flipImage(flipDirection as 'horizontal' | 'vertical'); | ||
}, | ||
}; | ||
} | ||
|
||
export const createImageEditButtons = (handler: ImageEditor) => { | ||
return [ | ||
createImageCropButton(handler), | ||
createImageRotateButton(handler), | ||
createImageFlipButton(handler), | ||
]; | ||
}; | ||
|
||
const degreeToRad = (degree: number) => { | ||
return degree * (Math.PI / 180); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.