Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add image removing on hover #1872

Merged
merged 3 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions js/editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-files.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-public.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-text.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-text.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-viewer.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/vendors.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/vendors.js.map

Large diffs are not rendered by default.

414 changes: 91 additions & 323 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"tiptap-utils": "^1.13.1",
"vue": "^2.6.14",
"vue-click-outside": "^1.0.7",
"vue-material-design-icons": "^5.0.0",
"vuex": "^3.6.2"
},
"engines": {
Expand All @@ -72,14 +73,14 @@
"@nextcloud/stylelint-config": "^2.1.2",
"@nextcloud/webpack-vue-config": "^4.2.0",
"@vue/test-utils": "^1.3.0",
"@vue/vue2-jest": "^27.0.0-alpha.4",
"babel-core": "^7.0.0-bridge.0",
"cypress": "^9.2.0",
"cypress-file-upload": "^5.0.8",
"jest": "^27.4.7",
"jest-environment-jsdom": "^27.4.6",
"jest-serializer-vue": "^2.0.2",
"regenerator-runtime": "^0.13.9",
"vue-jest": "^3.0.7"
"regenerator-runtime": "^0.13.9"
},
"jest": {
"verbose": true,
Expand All @@ -97,13 +98,16 @@
],
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest"
".*\\.(vue)$": "<rootDir>/node_modules/@vue/vue2-jest"
},
"snapshotSerializers": [
"<rootDir>/node_modules/jest-serializer-vue"
],
"setupFilesAfterEnv": [
"<rootDir>/src/tests/setup.js"
],
"transformIgnorePatterns": [
"/node_modules/(?!vue-material-design-icons)"
]
}
}
52 changes: 48 additions & 4 deletions src/nodes/ImageView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@

<template>
<div class="image" :class="{'icon-loading': !loaded}" :data-src="src">
<div v-if="imageLoaded && isSupportedImage" class="image__view">
<div v-if="imageLoaded && isSupportedImage"
v-click-outside="() => showIcons = false"
class="image__view"
@click="showIcons = true"
@mouseover="showIcons = true"
@mouseleave="showIcons = false">
<transition name="fade">
<img v-show="loaded"
:src="imageUrl"
Expand All @@ -35,6 +40,13 @@
type="text"
:value="alt"
@keyup.enter="updateAlt()">
<div
azul marked this conversation as resolved.
Show resolved Hide resolved
v-if="showIcons"
class="trash-icon"
title="Delete this image"
@click="deleteImage">
<TrashCanIcon />
</div>
</div>
</transition>
</div>
Expand All @@ -45,7 +57,8 @@
<span v-if="!isSupportedImage">{{ alt }}</span>
</a>
</div>
</transition><transition v-if="isSupportedImage" name="fade">
</transition>
<transition v-if="isSupportedImage" name="fade">
<div v-show="loaded" class="image__caption">
<input ref="altInput"
type="text"
Expand All @@ -61,6 +74,8 @@
import path from 'path'
import { generateUrl, generateRemoteUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth'
import ClickOutside from 'vue-click-outside'
import TrashCanIcon from 'vue-material-design-icons/TrashCan.vue'
import store from './../mixins/store'
const imageMimes = [
Expand Down Expand Up @@ -94,15 +109,22 @@ const getQueryVariable = (src, variable) => {
export default {
name: 'ImageView',
components: {
TrashCanIcon,
},
directives: {
ClickOutside,
},
mixins: [
store,
],
props: ['node', 'options', 'updateAttrs', 'view'], // eslint-disable-line
props: ['node', 'options', 'updateAttrs', 'view', 'getPos'], // eslint-disable-line
data() {
return {
imageLoaded: false,
loaded: false,
failed: false,
showIcons: false,
}
},
computed: {
Expand Down Expand Up @@ -267,6 +289,12 @@ export default {
onLoaded() {
this.loaded = true
},
deleteImage() {
const tr = this.view.state.tr
const pos = this.getPos()
tr.delete(pos, pos + this.node.nodeSize)
this.view.dispatch(tr)
},
},
}
</script>
Expand All @@ -280,8 +308,11 @@ export default {
.image__caption {
text-align: center;
color: var(--color-text-lighter);
display: flex;
align-items: center;
justify-content: center;
input[type='text'] {
width: 100%;
max-width: 80%;
border: none;
text-align: center;
}
Expand All @@ -293,6 +324,8 @@ export default {
.image__view {
text-align: center;
position: relative;
img {
max-width: 100%;
}
Expand All @@ -313,4 +346,15 @@ export default {
.fade-enter {
opacity: 0;
}
.trash-icon {
position: absolute;
right: 0;
display: flex;
justify-content: flex-end;
align-items: center;
svg {
cursor: pointer;
}
}
</style>