added: ts type checking for js files; updated: custom contextmenu now show only when needed, GUI users must use keyboard shortcuts for cut/copy/paste

This commit is contained in:
Roberto Tonino 2020-08-20 19:41:46 +02:00
parent c51c4789db
commit b063bff64d
4 changed files with 59 additions and 43 deletions

1
.gitignore vendored
View File

@ -3,7 +3,6 @@ __pycache__
.DS_Store .DS_Store
node_modules node_modules
jsconfig.json
# pyinstaller build dirs # pyinstaller build dirs
/dist /dist

File diff suppressed because one or more lines are too long

View File

@ -36,7 +36,7 @@ export default {
const options = { const options = {
cut: { cut: {
label: this.$t('globals.cut'), label: this.$t('globals.cut'),
show: true, show: false,
position: 1, position: 1,
action: () => { action: () => {
document.execCommand('Cut') document.execCommand('Cut')
@ -44,7 +44,7 @@ export default {
}, },
copy: { copy: {
label: this.$t('globals.copy'), label: this.$t('globals.copy'),
show: true, show: false,
position: 2, position: 2,
action: () => { action: () => {
document.execCommand('Copy') document.execCommand('Copy')
@ -55,9 +55,6 @@ export default {
show: false, show: false,
position: 3, position: 3,
action: () => { action: () => {
// navigator.clipboard.writeText(this.generalHref).catch(err => {
// console.error('Link copying failed', err)
// })
copyToClipboard(this.generalHref) copyToClipboard(this.generalHref)
} }
}, },
@ -66,9 +63,6 @@ export default {
show: false, show: false,
position: 4, position: 4,
action: () => { action: () => {
// navigator.clipboard.writeText(this.imgSrc).catch(err => {
// console.error('Image copying failed', err)
// })
copyToClipboard(this.imgSrc) copyToClipboard(this.imgSrc)
} }
}, },
@ -77,20 +71,22 @@ export default {
show: false, show: false,
position: 5, position: 5,
action: () => { action: () => {
// navigator.clipboard.writeText(this.deezerHref).catch(err => {
// console.error('Deezer link copying failed', err)
// })
copyToClipboard(this.deezerHref) copyToClipboard(this.deezerHref)
} }
}, },
paste: { paste: {
label: this.$t('globals.paste'), label: this.$t('globals.paste'),
show: !window.clientMode, show: false,
position: 6, position: 6,
action: () => { action: () => {
navigator.clipboard.readText().then(text => { // Paste does not always work
document.execCommand('insertText', undefined, text) if (clipboard in navigator) {
}) navigator.clipboard.readText().then(text => {
document.execCommand('insertText', undefined, text)
})
} else {
document.execCommand('paste')
}
} }
} }
} }
@ -108,9 +104,13 @@ export default {
return options return options
}, },
// This computed property is used for rendering the options in the wanted order /**
// while keeping the options computed property an Object to make the properties * This computed property is used for rendering the options in the wanted order
// accessible via property name (es this.options.copyLink) * while keeping the options computed property an Object to make the properties
* accessible via property name (es this.options.copyLink)
*
* @return {object[]} Options in order according to position property
*/
sortedOptions() { sortedOptions() {
return Object.values(this.options).sort((first, second) => { return Object.values(this.options).sort((first, second) => {
return first.position < second.position ? -1 : 1 return first.position < second.position ? -1 : 1
@ -123,28 +123,13 @@ export default {
}, },
methods: { methods: {
showMenu(contextMenuEvent) { showMenu(contextMenuEvent) {
contextMenuEvent.preventDefault() // contextMenuEvent.preventDefault()
const { pageX, pageY, target: elementClicked } = contextMenuEvent const { pageX, pageY, target: elementClicked } = contextMenuEvent
const path = generatePath(elementClicked) const path = generatePath(elementClicked)
this.positionMenu(pageX, pageY)
// Show 'Copy Link' option
if (elementClicked.matches('a')) {
this.generalHref = elementClicked.href
this.options.copyLink.show = true
}
// Show 'Copy Image Link' option
if (elementClicked.matches('img')) {
this.imgSrc = elementClicked.src
this.options.copyImageLink.show = true
}
let deezerLink = null let deezerLink = null
// Searching for the first element with a data-link attribute
// let deezerLink = this.searchForDataLink(...)
for (let i = 0; i < path.length; i++) { for (let i = 0; i < path.length; i++) {
if (path[i] == document) break if (path[i] == document) break
@ -154,13 +139,33 @@ export default {
} }
} }
// Show 'Copy Deezer Link' option const isLink = elementClicked.matches('a')
const isImage = elementClicked.matches('img')
const hasDeezerLink = !!deezerLink
if (!isLink && !isImage && !hasDeezerLink) return
contextMenuEvent.preventDefault()
this.menuOpen = true
this.positionMenu(pageX, pageY)
if (isLink) {
// Show 'Copy Link' option
this.generalHref = elementClicked.href
this.options.copyLink.show = true
}
if (isImage) {
// Show 'Copy Image Link' option
this.imgSrc = elementClicked.src
this.options.copyImageLink.show = true
}
if (deezerLink) { if (deezerLink) {
// Show 'Copy Deezer Link' option
this.deezerHref = deezerLink this.deezerHref = deezerLink
this.showDeezerOptions() this.showDeezerOptions()
} }
this.menuOpen = true
}, },
hideMenu() { hideMenu() {
if (!this.menuOpen) return if (!this.menuOpen) return

12
src/jsconfig.json Normal file
View File

@ -0,0 +1,12 @@
{
"compilerOptions": {
"checkJs": true,
"baseUrl": ".",
"paths": {
"@/*": ["./*"],
"@js/*": ["./js/*"],
"@components/*": ["./components/*"]
}
},
"exclude": ["assets/**/*", "styles/**/*"]
}