Change rotation to buttons

pull/175/head
Varun Patil 2022-11-07 04:53:35 -08:00
parent ebdc776237
commit f8e4231cae
1 changed files with 19 additions and 9 deletions

View File

@ -3,7 +3,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { Component, Prop, Emit, Mixins } from "vue-property-decorator"; import { Component, Prop, Mixins } from "vue-property-decorator";
import GlobalMixin from "../mixins/GlobalMixin"; import GlobalMixin from "../mixins/GlobalMixin";
import { basename, dirname, extname, join } from "path"; import { basename, dirname, extname, join } from "path";
@ -11,6 +11,7 @@ import { emit } from "@nextcloud/event-bus";
import { showError, showSuccess } from "@nextcloud/dialogs"; import { showError, showSuccess } from "@nextcloud/dialogs";
import axios from "@nextcloud/axios"; import axios from "@nextcloud/axios";
import FilerobotImageEditor from "filerobot-image-editor"; import FilerobotImageEditor from "filerobot-image-editor";
import { FilerobotImageEditorConfig } from "react-filerobot-image-editor";
import translations from "./ImageEditorTranslations"; import translations from "./ImageEditorTranslations";
@ -26,7 +27,7 @@ export default class ImageEditor extends Mixins(GlobalMixin) {
private imageEditor: FilerobotImageEditor = null; private imageEditor: FilerobotImageEditor = null;
get config() { get config(): FilerobotImageEditorConfig & { theme: any } {
return { return {
source: this.src, source: this.src,
@ -45,13 +46,18 @@ export default class ImageEditor extends Mixins(GlobalMixin) {
// Displayed tabs, disabling watermark // Displayed tabs, disabling watermark
tabsIds: Object.values(TABS) tabsIds: Object.values(TABS)
.filter((tab) => tab !== TABS.WATERMARK) .filter((tab) => tab !== TABS.WATERMARK)
.sort((a: string, b: string) => a.localeCompare(b)), .sort((a: string, b: string) => a.localeCompare(b)) as any[],
// onBeforeSave: this.onBeforeSave, // onBeforeSave: this.onBeforeSave,
onClose: this.onClose, onClose: this.onClose,
// onModify: this.onModify, // onModify: this.onModify,
onSave: this.onSave, onSave: this.onSave,
Rotate: {
angle: 90,
componentType: "buttons",
},
// Translations // Translations
translations, translations,
@ -87,8 +93,12 @@ export default class ImageEditor extends Mixins(GlobalMixin) {
return basename(this.src, extname(this.src)); return basename(this.src, extname(this.src));
} }
get defaultSavedImageType() { get defaultSavedImageType(): "jpeg" | "png" | "webp" {
return extname(this.src).slice(1) || "jpeg"; const mime = extname(this.src).slice(1);
if (["jpeg", "png", "webp"].includes(mime)) {
return mime as any;
}
return "jpeg";
} }
get hasHighContrastEnabled() { get hasHighContrastEnabled() {
@ -149,10 +159,10 @@ export default class ImageEditor extends Mixins(GlobalMixin) {
mimeType, mimeType,
quality, quality,
}: { }: {
fullName: string; fullName?: string;
imageCanvas: HTMLCanvasElement; imageCanvas?: HTMLCanvasElement;
mimeType: string; mimeType?: string;
quality: number; quality?: number;
}): Promise<void> { }): Promise<void> {
const { origin, pathname } = new URL(this.src); const { origin, pathname } = new URL(this.src);
const putUrl = origin + join(dirname(pathname), fullName); const putUrl = origin + join(dirname(pathname), fullName);