fix #832, floating btns closing, Esc to close confirmation dialog, 0x0 rects disabled (#947)

This commit is contained in:
olekhshch
2024-01-20 23:53:20 +01:00
committed by GitHub
parent f75d1a83a0
commit 9f77e9c63a
6 changed files with 43 additions and 8 deletions

View File

@@ -752,6 +752,7 @@ class EditorStartup {
cs = 'grab'
break
case 'zoom':
case 'shapelib':
cs = 'crosshair'
break
case 'circle':
@@ -779,7 +780,7 @@ class EditorStartup {
cancelTool () {
const mode = this.svgCanvas.getMode()
// list of modes that are currently save to cancel
const modesToCancel = ['zoom', 'rect', 'square', 'circle', 'ellipse', 'line', 'text', 'star', 'polygon', 'eyedropper']
const modesToCancel = ['zoom', 'rect', 'square', 'circle', 'ellipse', 'line', 'text', 'star', 'polygon', 'eyedropper', 'shapelib', 'image']
if (modesToCancel.includes(mode)) {
this.leftPanel.clickSelect()
}

View File

@@ -25,6 +25,13 @@ export class ExplorerButton extends HTMLElement {
this.files = []
this.request = new XMLHttpRequest()
this.imgPath = svgEditor.configObj.curConfig.imgPath
// Closes opened (pressed) lib menu on click on the canvas
const workarea = document.getElementById('workarea')
workarea.addEventListener('click', (e) => {
this.$menu.classList.remove('open')
this.$lib.classList.remove('open-lib')
})
}
/**
@@ -262,8 +269,8 @@ export class ExplorerButton extends HTMLElement {
ev.stopPropagation()
switch (ev.target.nodeName) {
case 'SE-EXPLORERBUTTON':
this.$menu.classList.add('open')
this.$lib.classList.add('open-lib')
this.$menu.classList.toggle('open')
this.$lib.classList.toggle('open-lib')
break
case 'SE-BUTTON':
// change to the current action

View File

@@ -24,6 +24,13 @@ export class FlyingButton extends HTMLElement {
// the last element of the div is the slot
// we retrieve all elements added in the slot (i.e. se-buttons)
this.$elements = this.$menu.lastElementChild.assignedElements()
// Closes opened menu on click
document.addEventListener('click', e => {
if (this.opened) {
this.opened = false
}
})
}
/**

View File

@@ -1,5 +1,5 @@
import PlainAlertDialog from 'elix/src/plain/PlainAlertDialog.js'
import { template } from 'elix/src/base/internal.js'
import { template, keydown } from 'elix/src/base/internal.js'
import { fragmentFrom } from 'elix/src/core/htmlLiterals.js'
/**
@@ -63,6 +63,24 @@ export default class SePlainAlertDialog extends PlainAlertDialog {
)
return result
}
/**
* Tracks if users wants to cancel (close dialog without any changes) with Esc
* if null - seConfirm will use responce.choice
*/
keyChoice = null
get [keydown] () {
/**
* Listens to Esc key to close dialog
*/
return (e) => {
if (e.key === 'Escape') {
this.keyChoice = 'Cancel'
this.close()
}
}
}
}
customElements.define('se-elix-alert-dialog', SePlainAlertDialog)

View File

@@ -6,7 +6,7 @@ const seConfirm = async (text, choices) => {
dialog.choices = (choices === undefined) ? ['Ok', 'Cancel'] : choices
dialog.open()
const response = await dialog.whenClosed()
return response.choice
return dialog.keyChoice ?? response.choice
}
window.seConfirm = seConfirm