Skip to content
Closed
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7234cb7
Merge pull request #20788 from Expensify/version-BUILD-C779BAE0-2CD3-…
OSBotify Jun 15, 2023
10ef5c9
Merge pull request #20784 from Expensify/Rory-RevertPodsCache
deetergp Jun 14, 2023
59d9682
Fix merge conflicts
AndrewGable Jun 15, 2023
0481339
Merge pull request #20789 from Expensify/AndrewGable-cherry-pick-stag…
roryabraham Jun 15, 2023
259472c
Merge pull request #20793 from Expensify/version-BUILD-CEEB244C-2777-…
OSBotify Jun 15, 2023
650dd03
Merge pull request #20740 from tienifr/fix/20412
mountiny Jun 15, 2023
7ddf35b
Merge pull request #20795 from Expensify/OSBotify-cherry-pick-staging…
OSBotify Jun 15, 2023
92f8c44
Merge pull request #20876 from Expensify/version-BUILD-134320EE-5E80-…
OSBotify Jun 15, 2023
2dfe139
Merge pull request #20845 from tienifr/fix/20819-wrong-text-color-our…
marcaaron Jun 15, 2023
dbf1a69
Merge pull request #20877 from Expensify/OSBotify-cherry-pick-staging…
OSBotify Jun 15, 2023
13a25c4
Merge branch 'main' into update-staging-from-main
OSBotify Jun 16, 2023
89dcd53
Merge pull request #20927 from Expensify/update-staging-from-main
OSBotify Jun 16, 2023
fc69c71
Merge pull request #21027 from Expensify/version-BUILD-20638381-2BB9-…
OSBotify Jun 19, 2023
cb3ff62
Merge pull request #21023 from Pujan92/fix/20809
MonilBhavsar Jun 19, 2023
c6de102
Merge pull request #21028 from Expensify/OSBotify-cherry-pick-staging…
OSBotify Jun 19, 2023
91739de
Merge pull request #21031 from Expensify/version-BUILD-B5D2281A-F884-…
OSBotify Jun 19, 2023
b158557
Merge pull request #21026 from situchan/fix/20822-avatar-tooltip
Beamanator Jun 19, 2023
4b765fc
Merge pull request #21033 from Expensify/OSBotify-cherry-pick-staging…
OSBotify Jun 19, 2023
b4acae3
Merge pull request #21069 from Expensify/version-BUILD-40E0B04A-5205-…
OSBotify Jun 19, 2023
9b955e9
Merge pull request #20951 from Expensify/yuwen-personalDetailFallback
luacmartins Jun 19, 2023
da0595e
Merge pull request #21071 from Expensify/OSBotify-cherry-pick-staging…
OSBotify Jun 19, 2023
5cd0b4a
Merge pull request #21089 from Expensify/version-BUILD-A386D15B-302A-…
OSBotify Jun 19, 2023
a4417c5
Merge pull request #21029 from Expensify/beaman-fixUserIsTypingIndicator
luacmartins Jun 19, 2023
75d61bd
resolve conflict
luacmartins Jun 20, 2023
5c72389
Merge pull request #21091 from Expensify/OSBotify-cherry-pick-staging…
chiragsalian Jun 20, 2023
c92bef6
Merge pull request #21090 from Expensify/version-BUILD-CA93A922-2674-…
OSBotify Jun 19, 2023
99de0b3
Merge pull request #21072 from fedirjh/Fix-Room-Members
luacmartins Jun 19, 2023
0d951f7
Merge pull request #21093 from Expensify/OSBotify-cherry-pick-staging…
OSBotify Jun 20, 2023
45274da
Merge pull request #21095 from Expensify/version-BUILD-58765BEB-CDC0-…
OSBotify Jun 20, 2023
1608081
Merge pull request #21030 from Expensify/monil-fixMentionsCrash
luacmartins Jun 19, 2023
baba202
Merge pull request #21096 from Expensify/OSBotify-cherry-pick-staging…
OSBotify Jun 20, 2023
86632f0
Ignore html embedded images when pasting into composer.
qispark Jun 20, 2023
e1b2c27
Merge remote-tracking branch 'origin/main' into qispark-composer-past…
qispark Jun 22, 2023
cf1dfbf
Revert changes to package-lock.json
qispark Jun 22, 2023
72a2b96
Merge branch 'Expensify:main' into qispark-composer-paste-ignore-images
qispark Jun 23, 2023
5655a15
Update comment.
qispark Jun 23, 2023
587827c
Refactor for DRY
qispark Jun 23, 2023
8714ea6
Merge branch 'Expensify:main' into qispark-composer-paste-ignore-images
qispark Jun 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 14 additions & 38 deletions src/components/Composer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,16 @@ class Composer extends React.Component {
this.paste(parser.htmlToMarkdown(html));
}

/**
* Paste the plaintext content into Composer.
*
* @param {ClipboardEvent} event
*/
handlePastePlainText(event) {
const plainText = event.clipboardData.getData('text/plain');
this.paste(plainText);
}

/**
* Check the paste event for an attachment, parse the data and call onPasteFile from props with the selected file,
* Otherwise, convert pasted HTML to Markdown and set it on the composer.
Expand All @@ -308,52 +318,18 @@ class Composer extends React.Component {
const domparser = new DOMParser();
const embeddedImages = domparser.parseFromString(pastedHTML, TEXT_HTML).images;

// If HTML has img tag, then fetch images from it.
// If HTML has img tag, then we only paste the plain text. This is because
// fetching the image via fetch triggers a Content-Security-Policy error.
if (embeddedImages.length > 0 && embeddedImages[0].src) {
// If HTML has emoji, then treat this as plain text.
if (embeddedImages[0].dataset && embeddedImages[0].dataset.stringifyType === 'emoji') {
const plainText = event.clipboardData.getData('text/plain');
this.paste(plainText);
return;
}
fetch(embeddedImages[0].src)
.then((response) => {
if (!response.ok) {
throw Error(response.statusText);
}
return response.blob();
})
.then((x) => {
const extension = IMAGE_EXTENSIONS[x.type];
if (!extension) {
throw new Error(this.props.translate('composer.noExtensionFoundForMimeType'));
}

return new File([x], `pasted_image.${extension}`, {});
})
.then(this.props.onPasteFile)
.catch(() => {
const errorDesc = this.props.translate('composer.problemGettingImageYouPasted');
Growl.error(errorDesc);

/*
* Since we intercepted the user-triggered paste event to check for attachments,
* we need to manually set the value and call the `onChangeText` handler.
* Synthetically-triggered paste events do not affect the document's contents.
* See https://developer.mozilla.org/en-US/docs/Web/API/Element/paste_event for more details.
*/
this.handlePastedHTML(pastedHTML);
});
this.handlePastePlainText(event);
return;
}

this.handlePastedHTML(pastedHTML);
return;
}

const plainText = event.clipboardData.getData('text/plain');

this.paste(plainText);
this.handlePastePlainText(event);
}

/**
Expand Down