-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c8d7eb
commit 26d6e90
Showing
8 changed files
with
142 additions
and
59 deletions.
There are no files selected for viewing
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
14 changes: 0 additions & 14 deletions
14
packages/roosterjs-content-model-plugins/lib/imageEdit/utils/getContentModelImage.ts
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
packages/roosterjs-content-model-plugins/lib/imageEdit/utils/getSelectedContentModelImage.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,19 @@ | ||
import { getSelectedSegments } from 'roosterjs-content-model-dom'; | ||
import type { | ||
ReadonlyContentModelImage, | ||
ShallowMutableContentModelDocument, | ||
} from 'roosterjs-content-model-types'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function getSelectedContentModelImage( | ||
model: ShallowMutableContentModelDocument | ||
): ReadonlyContentModelImage | null { | ||
const selectedSegments = getSelectedSegments(model, false /*includeFormatHolder*/); | ||
if (selectedSegments.length == 1 && selectedSegments[0].segmentType == 'Image') { | ||
return selectedSegments[0]; | ||
} | ||
|
||
return null; | ||
} |
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
81 changes: 73 additions & 8 deletions
81
packages/roosterjs-content-model-plugins/test/imageEdit/utils/updateImageEditInfoTest.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 |
---|---|---|
@@ -1,17 +1,82 @@ | ||
import * as updateImageMetadata from 'roosterjs-content-model-dom/lib/modelApi/metadata/updateImageMetadata'; | ||
import { ContentModelDocument } from 'roosterjs-content-model-types'; | ||
import { createImage } from 'roosterjs-content-model-dom'; | ||
import { updateImageEditInfo } from '../../../lib/imageEdit/utils/updateImageEditInfo'; | ||
import { initEditor } from '../../TestHelper'; | ||
import { | ||
getSelectedImageMetadata, | ||
updateImageEditInfo, | ||
} from '../../../lib/imageEdit/utils/updateImageEditInfo'; | ||
|
||
const model: ContentModelDocument = { | ||
blockGroupType: 'Document', | ||
blocks: [ | ||
{ | ||
blockType: 'Paragraph', | ||
segments: [ | ||
{ | ||
segmentType: 'Image', | ||
src: 'test', | ||
format: { | ||
fontFamily: 'Calibri', | ||
fontSize: '11pt', | ||
textColor: 'rgb(0, 0, 0)', | ||
id: 'image_0', | ||
maxWidth: '1800px', | ||
}, | ||
dataset: { | ||
editingInfo: JSON.stringify({ | ||
src: 'test', | ||
}), | ||
}, | ||
isSelectedAsImageSelection: true, | ||
isSelected: true, | ||
}, | ||
], | ||
format: {}, | ||
segmentFormat: { | ||
fontFamily: 'Calibri', | ||
fontSize: '11pt', | ||
textColor: 'rgb(0, 0, 0)', | ||
}, | ||
}, | ||
], | ||
format: { | ||
fontFamily: 'Calibri', | ||
fontSize: '11pt', | ||
textColor: '#000000', | ||
}, | ||
}; | ||
|
||
describe('updateImageEditInfo', () => { | ||
it('get image edit info', () => { | ||
const image = document.createElement('img'); | ||
it('update image edit info', () => { | ||
const updateImageMetadataSpy = spyOn(updateImageMetadata, 'updateImageMetadata'); | ||
const contentModelImage = createImage('test'); | ||
const result = updateImageEditInfo(contentModelImage, image, { | ||
widthPx: 10, | ||
heightPx: 10, | ||
}); | ||
expect(result).toEqual({ | ||
updateImageEditInfo(contentModelImage, { | ||
widthPx: 10, | ||
heightPx: 10, | ||
}); | ||
expect(updateImageMetadataSpy).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('getSelectedImageMetadata', () => { | ||
it('get image edit info', () => { | ||
const editor = initEditor('updateImageEditInfo', [], model); | ||
const image = new Image(10, 10); | ||
const metadata = getSelectedImageMetadata(editor, image); | ||
const expected = { | ||
src: '', | ||
widthPx: 0, | ||
heightPx: 0, | ||
naturalWidth: 0, | ||
naturalHeight: 0, | ||
leftPercent: 0, | ||
rightPercent: 0, | ||
topPercent: 0, | ||
bottomPercent: 0, | ||
angleRad: 0, | ||
editingInfo: '{"src":"test"}', | ||
}; | ||
expect(metadata).toEqual(expected); | ||
}); | ||
}); |