Skip to content

Commit

Permalink
editor: add fragment
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Patil <radialapps@gmail.com>
  • Loading branch information
pulsejet committed Oct 24, 2023
1 parent a30012a commit f7abbce
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/components/viewer/ImageEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
ref="editor"
class="viewer__image-editor top-left fill-block"
:class="{ loading: !imageEditor }"
/>
></div>
</template>

<script lang="ts">
Expand Down Expand Up @@ -193,18 +193,28 @@ export default defineComponent({
const source = await this.getImage();
const config = { ...this.config, source };
// Create the editor
this.imageEditor = new FilerobotImageEditor(div, config);
this.imageEditor.render();
// Handle keyboard
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() {
if (this.imageEditor) {
this.imageEditor.terminate();
}
// Cleanup
this.imageEditor?.terminate();
// Remove keyboard handler
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: {
Expand Down Expand Up @@ -323,10 +333,8 @@ export default defineComponent({
event.stopImmediatePropagation();
// escape key
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();
(document.querySelector('.FIE_topbar-close-button') as HTMLElement).click();
this.close();
}
// ctrl + S = save
Expand All @@ -341,6 +349,12 @@ export default defineComponent({
(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>
Expand Down
1 change: 1 addition & 0 deletions src/services/utils/fragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ enum FragmentType {
selection = 's',
modal = 'm',
sidebar = 'i',
editor = 'e',
}

/** Names of fragments */
Expand Down

0 comments on commit f7abbce

Please sign in to comment.