fix lgtm warnings and other minor fixes
This commit is contained in:
@@ -102,7 +102,7 @@ class Editor extends EditorStartup {
|
||||
{
|
||||
key: ['delete/backspace', true],
|
||||
fn: () => {
|
||||
if (!isNullish(this.selectedElement) || this.multiselected) { this.svgCanvas.deleteSelectedElements() }
|
||||
if (this.selectedElement || this.multiselected) { this.svgCanvas.deleteSelectedElements() }
|
||||
}
|
||||
},
|
||||
{ key: 'a', fn: () => { this.svgCanvas.selectAllInCurrentLayer() } },
|
||||
@@ -489,9 +489,9 @@ class Editor extends EditorStartup {
|
||||
// if this.elems[1] is present, then we have more than one element
|
||||
this.selectedElement = (elems.length === 1 || isNullish(elems[1]) ? elems[0] : null)
|
||||
this.multiselected = (elems.length >= 2 && !isNullish(elems[1]))
|
||||
if (!isNullish(this.selectedElement) && !isNode) {
|
||||
if (this.selectedElement && !isNode) {
|
||||
this.topPanel.update()
|
||||
} // if (!isNullish(elem))
|
||||
} // if (elem)
|
||||
|
||||
// Deal with pathedit mode
|
||||
this.topPanel.togglePathEditMode(isNode, elems)
|
||||
@@ -742,7 +742,7 @@ class Editor extends EditorStartup {
|
||||
* @returns {void}
|
||||
*/
|
||||
cutSelected () {
|
||||
if (!isNullish(this.selectedElement) || this.multiselected) {
|
||||
if (this.selectedElement || this.multiselected) {
|
||||
this.svgCanvas.cutSelectedElements()
|
||||
}
|
||||
}
|
||||
@@ -752,7 +752,7 @@ class Editor extends EditorStartup {
|
||||
* @returns {void}
|
||||
*/
|
||||
copySelected () {
|
||||
if (!isNullish(this.selectedElement) || this.multiselected) {
|
||||
if (this.selectedElement || this.multiselected) {
|
||||
this.svgCanvas.copySelectedElements()
|
||||
}
|
||||
}
|
||||
@@ -774,7 +774,7 @@ class Editor extends EditorStartup {
|
||||
* @returns {void}
|
||||
*/
|
||||
moveUpDownSelected (dir) {
|
||||
if (!isNullish(this.selectedElement)) {
|
||||
if (this.selectedElement) {
|
||||
this.svgCanvas.moveUpDownSelected(dir)
|
||||
}
|
||||
}
|
||||
@@ -785,7 +785,7 @@ class Editor extends EditorStartup {
|
||||
* @returns {void}
|
||||
*/
|
||||
moveSelected (dx, dy) {
|
||||
if (!isNullish(this.selectedElement) || this.multiselected) {
|
||||
if (this.selectedElement || this.multiselected) {
|
||||
if (this.configObj.curConfig.gridSnapping) {
|
||||
// Use grid snap value regardless of zoom level
|
||||
const multi = this.svgCanvas.getZoom() * this.configObj.curConfig.snappingStep
|
||||
@@ -818,7 +818,7 @@ class Editor extends EditorStartup {
|
||||
* @returns {void}
|
||||
*/
|
||||
rotateSelected (cw, step) {
|
||||
if (isNullish(this.selectedElement) || this.multiselected) { return }
|
||||
if (!this.selectedElement || this.multiselected) { return }
|
||||
if (!cw) { step *= -1 }
|
||||
const angle = Number.parseFloat($id('angle').value) + step
|
||||
this.svgCanvas.setRotationAngle(angle)
|
||||
|
||||
@@ -11,14 +11,6 @@ function toFixedNumeric (value, precision) {
|
||||
if (precision === undefined) precision = 0
|
||||
return Math.round(value * (10 ** precision)) / (10 ** precision)
|
||||
}
|
||||
/**
|
||||
* Whether a value is `null` or `undefined`.
|
||||
* @param {any} val
|
||||
* @returns {boolean}
|
||||
*/
|
||||
const isNullish = (val) => {
|
||||
return val === null || val === undefined
|
||||
}
|
||||
/**
|
||||
* Controls for all the input elements for the typing in color values.
|
||||
*/
|
||||
@@ -39,7 +31,7 @@ export default class ColorValuePicker {
|
||||
* @returns {Event|false|void}
|
||||
*/
|
||||
function keyDown (e) {
|
||||
if (e.target.value === '' && e.target !== hex && ((!isNullish(bindedHex) && e.target !== bindedHex) || isNullish(bindedHex))) return undefined
|
||||
if (e.target.value === '' && e.target !== hex && ((bindedHex && e.target !== bindedHex) || !bindedHex)) return undefined
|
||||
if (!validateKey(e)) return e
|
||||
switch (e.target) {
|
||||
case red:
|
||||
@@ -137,8 +129,8 @@ export default class ColorValuePicker {
|
||||
*/
|
||||
function keyUp (e) {
|
||||
if (e.target.value === '' && e.target !== hex &&
|
||||
((!isNullish(bindedHex) && e.target !== bindedHex) ||
|
||||
isNullish(bindedHex))) return undefined
|
||||
((bindedHex && e.target !== bindedHex) ||
|
||||
!bindedHex)) return undefined
|
||||
if (!validateKey(e)) return e
|
||||
switch (e.target) {
|
||||
case red:
|
||||
@@ -181,7 +173,7 @@ export default class ColorValuePicker {
|
||||
break
|
||||
case ahex:
|
||||
ahex.value = ahex.value.replace(/[^a-fA-F\d]/g, '').toLowerCase().substring(0, 2)
|
||||
color.val('a', !isNullish(ahex.value) ? Number.parseInt(ahex.value, 16) : null, e.target)
|
||||
color.val('a', ahex.value ? Number.parseInt(ahex.value, 16) : null, e.target)
|
||||
break
|
||||
}
|
||||
return undefined
|
||||
@@ -192,7 +184,7 @@ export default class ColorValuePicker {
|
||||
* @returns {void}
|
||||
*/
|
||||
function blur (e) {
|
||||
if (!isNullish(color.value)) {
|
||||
if (color.value) {
|
||||
switch (e.target) {
|
||||
case red:
|
||||
color.value = 'r'
|
||||
@@ -274,16 +266,16 @@ export default class ColorValuePicker {
|
||||
*/
|
||||
function colorChanged (ui, context) {
|
||||
const all = ui.val('all')
|
||||
if (context !== red) red.value = (!isNullish(all) ? all.r : '')
|
||||
if (context !== green) green.value = (!isNullish(all) ? all.g : '')
|
||||
if (context !== blue) blue.value = (!isNullish(all) ? all.b : '')
|
||||
if (alpha && context !== alpha) alpha.value = (!isNullish(all) ? toFixedNumeric((all.a * 100) / 255, alphaPrecision) : '')
|
||||
if (context !== hue) hue.value = (!isNullish(all) ? all.h : '')
|
||||
if (context !== saturation) saturation.value = (!isNullish(all) ? all.s : '')
|
||||
if (context !== value) value.value = (!isNullish(all) ? all.v : '')
|
||||
if (context !== hex && ((bindedHex && context !== bindedHex) || !bindedHex)) hex.value = (!isNullish(all) ? all.hex : '')
|
||||
if (bindedHex && context !== bindedHex && context !== hex) bindedHex.value = (!isNullish(all) ? all.hex : '')
|
||||
if (ahex && context !== ahex) ahex.value = (!isNullish(all) ? all.ahex.substring(6) : '')
|
||||
if (context !== red) red.value = (all ? all.r : '')
|
||||
if (context !== green) green.value = (all ? all.g : '')
|
||||
if (context !== blue) blue.value = (all ? all.b : '')
|
||||
if (alpha && context !== alpha) alpha.value = (all ? toFixedNumeric((all.a * 100) / 255, alphaPrecision) : '')
|
||||
if (context !== hue) hue.value = (all ? all.h : '')
|
||||
if (context !== saturation) saturation.value = (all ? all.s : '')
|
||||
if (context !== value) value.value = (all ? all.v : '')
|
||||
if (context !== hex && ((bindedHex && context !== bindedHex) || !bindedHex)) hex.value = (all ? all.hex : '')
|
||||
if (bindedHex && context !== bindedHex && context !== hex) bindedHex.value = (all ? all.hex : '')
|
||||
if (ahex && context !== ahex) ahex.value = (all ? all.ahex.substring(6) : '')
|
||||
}
|
||||
/**
|
||||
* Unbind all events and null objects.
|
||||
|
||||
@@ -1337,34 +1337,34 @@ export function jPickerMethod (elem, options, commitCallback, liveCallback, canc
|
||||
</tr>
|
||||
<tr class="Hue">
|
||||
<td class="Radio"><label title="${i18next.t('config.jpicker_tooltip_hue_radio')}"><input type="radio" value="h"${settings.color.mode === 'h' ? ' checked="checked"' : ''}/>H:</label></td>
|
||||
<td class="Text"><input type="text" maxlength="3" value="${!isNullish(all) ? all.h : ''}" title="${i18next.t('config.jpicker_tooltip_hue_textbox')}"/> °</td>
|
||||
<td class="Text"><input type="text" maxlength="3" value="${all ? all.h : ''}" title="${i18next.t('config.jpicker_tooltip_hue_textbox')}"/> °</td>
|
||||
</tr>
|
||||
<tr class="Saturation">
|
||||
<td class="Radio"><label title="${i18next.t('config.jpicker_tooltip_saturation_radio')}"><input type="radio" value="s"${settings.color.mode === 's' ? ' checked="checked"' : ''}/>S:</label></td>
|
||||
<td class="Text"><input type="text" maxlength="3" value="${!isNullish(all) ? all.s : ''}" title="${i18next.t('config.jpicker_tooltip_saturation_textbox')}"/> %</td>
|
||||
<td class="Text"><input type="text" maxlength="3" value="${all ? all.s : ''}" title="${i18next.t('config.jpicker_tooltip_saturation_textbox')}"/> %</td>
|
||||
</tr>
|
||||
<tr class="Value">
|
||||
<td class="Radio"><label title="${i18next.t('config.jpicker_tooltip_value_radio')}"><input type="radio" value="v"${settings.color.mode === 'v' ? ' checked="checked"' : ''}/>V:</label><br/><br/></td>
|
||||
<td class="Text"><input type="text" maxlength="3" value="${!isNullish(all) ? all.v : ''}" title="${i18next.t('config.jpicker_tooltip_value_textbox')}"/> %<br/><br/></td>
|
||||
<td class="Text"><input type="text" maxlength="3" value="${all ? all.v : ''}" title="${i18next.t('config.jpicker_tooltip_value_textbox')}"/> %<br/><br/></td>
|
||||
</tr>
|
||||
<tr class="Red">
|
||||
<td class="Radio"><label title="${i18next.t('config.jpicker_tooltip_red_radio')}"><input type="radio" value="r"${settings.color.mode === 'r' ? ' checked="checked"' : ''}/>R:</label></td>
|
||||
<td class="Text"><input type="text" maxlength="3" value="${!isNullish(all) ? all.r : ''}" title="${i18next.t('config.jpicker_tooltip_red_textbox')}"/></td>
|
||||
<td class="Text"><input type="text" maxlength="3" value="${all ? all.r : ''}" title="${i18next.t('config.jpicker_tooltip_red_textbox')}"/></td>
|
||||
</tr>
|
||||
<tr class="Green">
|
||||
<td class="Radio"><label title="${i18next.t('config.jpicker_tooltip_green_radio')}"><input type="radio" value="g"${settings.color.mode === 'g' ? ' checked="checked"' : ''}/>G:</label></td>
|
||||
<td class="Text"><input type="text" maxlength="3" value="${!isNullish(all) ? all.g : ''}" title="${i18next.t('config.jpicker_tooltip_green_textbox')}"/></td>
|
||||
<td class="Text"><input type="text" maxlength="3" value="${all ? all.g : ''}" title="${i18next.t('config.jpicker_tooltip_green_textbox')}"/></td>
|
||||
</tr>
|
||||
<tr class="Blue">
|
||||
<td class="Radio"><label title="${i18next.t('config.jpicker_tooltip_blue_radio')}"><input type="radio" value="b"${settings.color.mode === 'b' ? ' checked="checked"' : ''}/>B:</label></td>
|
||||
<td class="Text"><input type="text" maxlength="3" value="${!isNullish(all) ? all.b : ''}" title="${i18next.t('config.jpicker_tooltip_blue_textbox')}"/></td>
|
||||
<td class="Text"><input type="text" maxlength="3" value="${all ? all.b : ''}" title="${i18next.t('config.jpicker_tooltip_blue_textbox')}"/></td>
|
||||
</tr>
|
||||
<tr class="Alpha">
|
||||
<td class="Radio">${win.alphaSupport ? `<label title="${i18next.t('config.jpicker_tooltip_alpha_radio')}"><input type="radio" value="a"${settings.color.mode === 'a' ? ' checked="checked"' : ''}/>A:</label>` : ' '}</td>
|
||||
<td class="Text">${win.alphaSupport ? `<input type="text" maxlength="${3 + win.alphaPrecision}" value="${!isNullish(all) ? toFixedNumeric((all.a * 100) / 255, win.alphaPrecision) : ''}" title="${i18next.t('config.jpicker_tooltip_alpha_textbox')}"/> %` : ' '}</td>
|
||||
<td class="Text">${win.alphaSupport ? `<input type="text" maxlength="${3 + win.alphaPrecision}" value="${all ? toFixedNumeric((all.a * 100) / 255, win.alphaPrecision) : ''}" title="${i18next.t('config.jpicker_tooltip_alpha_textbox')}"/> %` : ' '}</td>
|
||||
</tr>
|
||||
<tr class="Hex">
|
||||
<td colspan="2" class="Text"><label title="${i18next.t('config.jpicker_tooltip_hex_textbox')}">#:<input type="text" maxlength="6" class="Hex" value="${!isNullish(all) ? all.hex : ''}"/></label>${win.alphaSupport ? `<input type="text" maxlength="2" class="AHex" value="${!isNullish(all) ? all.ahex.substring(6) : ''}" title="${i18next.t('config.jpicker_tooltip_hex_alpha')}"/></td>` : ' '}
|
||||
<td colspan="2" class="Text"><label title="${i18next.t('config.jpicker_tooltip_hex_textbox')}">#:<input type="text" maxlength="6" class="Hex" value="${all ? all.hex : ''}"/></label>${win.alphaSupport ? `<input type="text" maxlength="2" class="AHex" value="${all ? all.ahex.substring(6) : ''}" title="${i18next.t('config.jpicker_tooltip_hex_alpha')}"/></td>` : ' '}
|
||||
</tr>
|
||||
</tbody></table>`
|
||||
if (win.expandable) {
|
||||
@@ -1455,7 +1455,7 @@ export function jPickerMethod (elem, options, commitCallback, liveCallback, canc
|
||||
win.expandable && win.bindToInput ? win.input : null,
|
||||
win.alphaPrecision
|
||||
)
|
||||
const hex = !isNullish(all) ? all.hex : null
|
||||
const hex = all ? all.hex : null
|
||||
const preview = tbody.querySelector('#Preview')
|
||||
const button = tbody.querySelector('#Button')
|
||||
activePreview = preview.querySelector('#Active')
|
||||
@@ -1523,7 +1523,7 @@ export function jPickerMethod (elem, options, commitCallback, liveCallback, canc
|
||||
iconColor.style.backgroundColor = (hex && '#' + hex) || 'transparent'
|
||||
iconAlpha = that.icon.querySelector('.Alpha')
|
||||
setImg.call(that, iconAlpha, images.clientPath + 'bar-opacity.png')
|
||||
setAlpha.call(that, iconAlpha, toFixedNumeric(((255 - (!isNullish(all) ? all.a : 0)) * 100) / 255, 4))
|
||||
setAlpha.call(that, iconAlpha, toFixedNumeric(((255 - (all ? all.a : 0)) * 100) / 255, 4))
|
||||
iconImage = that.icon.querySelector('.Image')
|
||||
iconImage.style.backgroundImage = 'url(\'' + images.clientPath + images.picker.file + '\')'
|
||||
iconImage.addEventListener('click', iconImageClicked)
|
||||
@@ -1531,7 +1531,7 @@ export function jPickerMethod (elem, options, commitCallback, liveCallback, canc
|
||||
win.input.style.backgroundColor = (hex && '#' + hex) || 'transparent'
|
||||
win.input.style.color = isNullish(all) || all.v > 75 ? '#000000' : '#ffffff'
|
||||
}
|
||||
const moveBar = tbody.querySelector('.Move')
|
||||
moveBar = tbody.querySelector('.Move')
|
||||
moveBar.addEventListener('mousedown', moveBarMouseDown)
|
||||
color.active.bind(expandableColorChanged)
|
||||
} else {
|
||||
@@ -1658,7 +1658,7 @@ export function jPickerMethod (elem, options, commitCallback, liveCallback, canc
|
||||
let iconColor = null // iconColor for popup icon
|
||||
let iconAlpha = null // iconAlpha for popup icon
|
||||
let iconImage = null // iconImage popup icon
|
||||
const moveBar = null // drag bar
|
||||
let moveBar = null // drag bar
|
||||
Object.assign(that, {
|
||||
// public properties, methods, and callbacks
|
||||
commitCallback, // commitCallback function can be overridden to return the selected color to a method you specify when the user clicks "OK"
|
||||
|
||||
@@ -233,9 +233,7 @@ export default {
|
||||
}
|
||||
// Else fall through
|
||||
default:
|
||||
// TODO: See if there's a way to base64 encode the binary data stream
|
||||
// const str = 'data:;base64,' + svgedit.utilities.encode64(response, true);
|
||||
|
||||
// TODO: See if there's a way to base64 encode the binary data stream
|
||||
// Assume it's raw image data
|
||||
// importImage(str);
|
||||
|
||||
|
||||
@@ -56,11 +56,7 @@ class BottomPanel {
|
||||
break
|
||||
default:
|
||||
{
|
||||
const zoomlevel = Number(value) / 100
|
||||
if (zoomlevel < 0.001) {
|
||||
value = 0.1
|
||||
return
|
||||
}
|
||||
const zoomlevel = Number(value) > 0.1 ? Number(value) > 0.1 : 0.1
|
||||
const zoom = this.editor.svgCanvas.getZoom()
|
||||
const { workarea } = this.editor
|
||||
this.editor.zoomChanged(window, {
|
||||
|
||||
@@ -409,7 +409,7 @@ class TopPanel {
|
||||
'#group'
|
||||
)
|
||||
|
||||
// if (!isNullish(elem))
|
||||
// if (elem)
|
||||
} else if (this.multiselected) {
|
||||
this.displayTool('multiselected_panel')
|
||||
menuItems.setAttribute('enablemenuitems', '#group')
|
||||
|
||||
Reference in New Issue
Block a user