-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
- Loading branch information
Showing
4 changed files
with
215 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
<template> | ||
<div ref="editor" class="viewer__image-editor" /> | ||
</template> | ||
<script> | ||
import FilerobotImageEditor from 'filerobot-image-editor' | ||
import { basename, dirname, extname, join } from 'path' | ||
import client from '../services/DavClient.js' | ||
import logger from '../services/logger.js' | ||
const { TABS, TOOLS } = FilerobotImageEditor | ||
export default { | ||
props: { | ||
filename: { | ||
type: String, | ||
required: true, | ||
}, | ||
mime: { | ||
type: String, | ||
required: true, | ||
}, | ||
src: { | ||
type: String, | ||
required: true, | ||
}, | ||
}, | ||
data() { | ||
return { | ||
imageEditor: null, | ||
} | ||
}, | ||
computed: { | ||
config() { | ||
return { | ||
source: this.src, | ||
defaultSavedImageName: this.defaultSavedImageName, | ||
defaultSavedImageType: this.defaultSavedImageType, | ||
// We use our own translations | ||
useBackendTranslations: false, | ||
// Disable default tool | ||
defaultTabId: TABS.RESIZE, | ||
defaultToolId: TOOLS.RESIZE, | ||
// onBeforeSave: this.onBeforeSave, | ||
onClose: this.onClose, | ||
// onModify: this.onModify, | ||
onSave: this.onSave, | ||
} | ||
}, | ||
defaultSavedImageName() { | ||
return basename(this.src, extname(this.src)) | ||
}, | ||
defaultSavedImageType() { | ||
return extname(this.src).slice(1) || 'jpeg' | ||
}, | ||
}, | ||
mounted() { | ||
this.imageEditor = new FilerobotImageEditor( | ||
this.$refs.editor, | ||
this.config | ||
) | ||
this.imageEditor.render() | ||
}, | ||
beforeDestroy() { | ||
if (this.imageEditor) { | ||
this.imageEditor.terminate() | ||
} | ||
}, | ||
methods: { | ||
onClose(closingReason, haveNotSavedChanges) { | ||
this.$emit('close') | ||
}, | ||
async onSave(imageData) { | ||
const filename = join(dirname(this.filename), imageData.fullName) | ||
logger.debug('Saving image...', { src: this.src, filename, imageData }) | ||
try { | ||
await client.putFileContents(filename, imageData.imageBase64) | ||
logger.info('Edited image saved!') | ||
} catch (error) { | ||
logger.error('Error saving image', { error }) | ||
} | ||
}, | ||
}, | ||
} | ||
</script> | ||
|
||
<style lang="scss"> | ||
.viewer__image-editor { | ||
width: 100%; | ||
height: calc(100% + var(--header-height)); | ||
top: 0; | ||
position: absolute; | ||
z-index: 10100; | ||
} | ||
</style> | ||
<style lang="scss"> | ||
// Make sure the editor and its modals ae above everything | ||
.SfxModal-Wrapper { | ||
z-index: 10101 !important; | ||
} | ||
.SfxPopper-wrapper { | ||
z-index: 10102 !important; | ||
} | ||
// Input styling | ||
.SfxInput-root { | ||
height: auto !important; | ||
padding: 0 !important; | ||
} | ||
.SfxInput-root .SfxInput-Base { | ||
margin: 0 !important; | ||
} | ||
// Select styling | ||
.SfxSelect-root { | ||
padding: 8px !important; | ||
} | ||
// Global buttons | ||
.SfxButton-root { | ||
margin: 0 !important; | ||
} | ||
// Menu items | ||
.SfxMenuItem-root { | ||
height: 44px; | ||
} | ||
// Canvas container | ||
.FIE_canvas-container { | ||
background-color: white !important; | ||
} | ||
// Header buttons | ||
.FIE_topbar-center-options > button, | ||
.FIE_topbar-center-options > label { | ||
margin-left: 6px !important; | ||
} | ||
// Crop preset select button | ||
.FIE_crop-presets-opener-button { | ||
background-color: transparent !important; | ||
border: none !important; | ||
padding: 5px !important; | ||
padding-left: 10px !important; | ||
} | ||
</style> |
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