undo map even if conversion fails

main
Mike Fix 6 years ago
parent 999bbff7fe
commit 3b67c0a846

@ -125,7 +125,7 @@ class Editor extends React.Component {
} }
} }
getCarbonImage({ format, type } = { format: 'png' }) { async getCarbonImage({ format, type } = { format: 'png' }) {
// if safari, get image from api // if safari, get image from api
const isPNG = format !== 'svg' const isPNG = format !== 'svg'
if ( if (
@ -150,7 +150,7 @@ class Editor extends React.Component {
if (isPNG) { if (isPNG) {
node.querySelectorAll('span[role="presentation"]').forEach(node => { node.querySelectorAll('span[role="presentation"]').forEach(node => {
if (node.innerText && node.innerText.match(/%\S\S/)) { if (node.innerText && node.innerText.match(/%\d\S/)) {
map.set(node, node.innerText) map.set(node, node.innerText)
node.innerText = encodeURIComponent(node.innerText) node.innerText = encodeURIComponent(node.innerText)
} }
@ -178,6 +178,7 @@ class Editor extends React.Component {
height height
} }
try {
if (type === 'blob') { if (type === 'blob') {
if (format === 'svg') { if (format === 'svg') {
return domtoimage return domtoimage
@ -188,14 +189,16 @@ class Editor extends React.Component {
.then(data => window.URL.createObjectURL(data)) .then(data => window.URL.createObjectURL(data))
} }
return domtoimage return await domtoimage.toBlob(node, config).then(blob => window.URL.createObjectURL(blob))
.toBlob(node, config)
.then(blob => window.URL.createObjectURL(blob))
.then(undoMap)
} }
// Twitter needs regular dataurls // Twitter needs regular dataurls
return domtoimage.toPng(node, config).then(undoMap) return await domtoimage.toPng(node, config)
} catch (error) {
throw error
} finally {
undoMap()
}
} }
updateSetting(key, value) { updateSetting(key, value) {

Loading…
Cancel
Save