editor: add fragment

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/888/head
Varun Patil 2023-10-24 11:20:32 -07:00
parent a30012a7da
commit f7abbce9de
2 changed files with 22 additions and 7 deletions

View File

@ -4,7 +4,7 @@
ref="editor" ref="editor"
class="viewer__image-editor top-left fill-block" class="viewer__image-editor top-left fill-block"
:class="{ loading: !imageEditor }" :class="{ loading: !imageEditor }"
/> ></div>
</template> </template>
<script lang="ts"> <script lang="ts">
@ -193,18 +193,28 @@ export default defineComponent({
const source = await this.getImage(); const source = await this.getImage();
const config = { ...this.config, source }; const config = { ...this.config, source };
// Create the editor
this.imageEditor = new FilerobotImageEditor(div, config); this.imageEditor = new FilerobotImageEditor(div, config);
this.imageEditor.render(); this.imageEditor.render();
// Handle keyboard // Handle keyboard
window.addEventListener('keydown', this.handleKeydown, true); window.addEventListener('keydown', this.handleKeydown, true);
// Fragment navigation
utils.fragment.push(utils.fragment.types.editor);
utils.bus.on('memories:fragment:pop:editor', this.close);
}, },
beforeDestroy() { beforeDestroy() {
if (this.imageEditor) { // Cleanup
this.imageEditor.terminate(); this.imageEditor?.terminate();
}
// Remove keyboard handler
window.removeEventListener('keydown', this.handleKeydown, true); window.removeEventListener('keydown', this.handleKeydown, true);
// Fragment navigation
utils.fragment.pop(utils.fragment.types.editor);
utils.bus.off('memories:fragment:pop:editor', this.close);
}, },
methods: { methods: {
@ -323,10 +333,8 @@ export default defineComponent({
event.stopImmediatePropagation(); event.stopImmediatePropagation();
// escape key // escape key
if (event.key === 'Escape') { if (event.key === 'Escape') {
// Since we cannot call the closeMethod and know if there
// are unsaved changes, let's fake a close button trigger.
event.preventDefault(); event.preventDefault();
(document.querySelector('.FIE_topbar-close-button') as HTMLElement).click(); this.close();
} }
// ctrl + S = save // ctrl + S = save
@ -341,6 +349,12 @@ export default defineComponent({
(document.querySelector('.FIE_topbar-undo-button') as HTMLElement).click(); (document.querySelector('.FIE_topbar-undo-button') as HTMLElement).click();
} }
}, },
close() {
// Since we cannot call the closeMethod and know if there
// are unsaved changes, let's fake a close button trigger.
(document.querySelector('.FIE_topbar-close-button') as HTMLElement).click();
},
}, },
}); });
</script> </script>

View File

@ -6,6 +6,7 @@ enum FragmentType {
selection = 's', selection = 's',
modal = 'm', modal = 'm',
sidebar = 'i', sidebar = 'i',
editor = 'e',
} }
/** Names of fragments */ /** Names of fragments */