Merge pull request #440 from madrang/dragNdrop

Drag&Drop Fixes
This commit is contained in:
cmdr2 2022-11-04 09:13:14 +05:30 committed by GitHub
commit c3129a40f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,35 @@
"use strict" // Opt in to a restricted variant of JavaScript "use strict" // Opt in to a restricted variant of JavaScript
function parseBoolean(stringValue) {
if (typeof stringValue === 'boolean') {
return stringValue
}
if (typeof stringValue === 'number') {
return stringValue !== 0
}
if (typeof stringValue !== 'string') {
return false
}
switch(stringValue?.toLowerCase()?.trim()) {
case "true":
case "yes":
case "1":
return true;
case "false":
case "no":
case "0":
case null:
case undefined:
return false;
}
try {
return Boolean(JSON.parse(stringValue));
} catch {
return Boolean(stringValue)
}
}
const TASK_MAPPING = { const TASK_MAPPING = {
prompt: { name: 'Prompt', prompt: { name: 'Prompt',
setUI: (prompt) => { setUI: (prompt) => {
@ -93,15 +123,21 @@ const TASK_MAPPING = {
use_face_correction: { name: 'Use Face Correction', use_face_correction: { name: 'Use Face Correction',
setUI: (use_face_correction) => { setUI: (use_face_correction) => {
useFaceCorrectionField.checked = Boolean(use_face_correction) useFaceCorrectionField.checked = parseBoolean(use_face_correction)
}, },
readUI: () => useFaceCorrectionField.checked, readUI: () => useFaceCorrectionField.checked,
parse: (val) => val parse: (val) => parseBoolean(val)
}, },
use_upscale: { name: 'Use Upscaling', use_upscale: { name: 'Use Upscaling',
setUI: (use_upscale) => { setUI: (use_upscale) => {
useUpscalingField.checked = Boolean(use_upscale) const oldVal = upscaleModelField.value
upscaleModelField.value = use_upscale upscaleModelField.value = use_upscale
if (upscaleModelField.value) { // Is a valid value for the field.
useUpscalingField.checked = true
} else { // Not a valid value, restore the old value and disable the filter.
upscaleModelField.value = oldVal
useUpscalingField.checked = false
}
}, },
readUI: () => (useUpscalingField.checked ? upscaleModelField.value : undefined), readUI: () => (useUpscalingField.checked ? upscaleModelField.value : undefined),
parse: (val) => val parse: (val) => val