electron-prompt-chi
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -44,89 +44,43 @@ const fs = require('fs'); | ||
try { | ||
promptOptions = JSON.parse(ipcRenderer.sendSync('prompt-get-options:' + promptId)); | ||
} catch (error) { | ||
return promptError(error); | ||
} | ||
try { | ||
promptOptions = JSON.parse(ipcRenderer.sendSync('prompt-get-options:' + promptId)); | ||
} catch (error) { | ||
return promptError(error); | ||
} | ||
if (promptOptions.useHtmlLabel) { | ||
document.getElementById('label').innerHTML = promptOptions.label; | ||
document.getElementById('ok').addEventListener('click', () => promptSubmit()); | ||
document.getElementById('cancel').addEventListener('click', () => promptCancel()); | ||
let dataEl; | ||
if (promptOptions.type === 'input') { | ||
dataEl = document.getElementById('data'); | ||
if (promptOptions.value) { | ||
dataEl.value = promptOptions.value; | ||
} else { | ||
document.getElementById('label').textContent = promptOptions.label; | ||
dataEl.value = ''; | ||
} | ||
try { | ||
if (promptOptions.customStylesheet) { | ||
const customStyleContent = fs.readFileSync(promptOptions.customStylesheet); | ||
if (customStyleContent) { | ||
const customStyle = document.createElement('style'); | ||
customStyle.setAttribute('rel', 'stylesheet'); | ||
customStyle.appendChild(document.createTextNode(customStyleContent)); | ||
document.head.appendChild(customStyle); | ||
} | ||
} | ||
} catch (error) { | ||
return promptError(error); | ||
} | ||
document.getElementById('ok').addEventListener('click', () => promptSubmit()); | ||
document.getElementById('cancel').addEventListener('click', () => promptCancel()); | ||
const dataContainerEl = document.getElementById('data-container'); | ||
let dataEl; | ||
if (promptOptions.type === 'input') { | ||
dataEl = document.createElement('input'); | ||
dataEl.setAttribute('type', 'text'); | ||
if (promptOptions.value) { | ||
dataEl.value = promptOptions.value; | ||
} else { | ||
dataEl.value = ''; | ||
} | ||
if (promptOptions.inputAttrs && typeof (promptOptions.inputAttrs) === 'object') { | ||
for (const k in promptOptions.inputAttrs) { | ||
if (!Object.prototype.hasOwnProperty.call(promptOptions.inputAttrs, k)) { | ||
continue; | ||
} | ||
dataEl.setAttribute(k, promptOptions.inputAttrs[k]); | ||
} | ||
} | ||
dataEl.addEventListener('keyup', e => { | ||
e.which = e.which || e.keyCode; | ||
if (e.which === 13) { | ||
promptSubmit(); | ||
} | ||
if (e.which === 27) { | ||
promptCancel(); | ||
} | ||
}); | ||
} else if (promptOptions.type === 'select') { | ||
dataEl = document.createElement('select'); | ||
let optionEl; | ||
for (const k in promptOptions.selectOptions) { | ||
if (!Object.prototype.hasOwnProperty.call(promptOptions.selectOptions, k)) { | ||
if (promptOptions.inputAttrs && typeof (promptOptions.inputAttrs) === 'object') { | ||
for (const k in promptOptions.inputAttrs) { | ||
if (!Object.prototype.hasOwnProperty.call(promptOptions.inputAttrs, k)) { | ||
continue; | ||
} | ||
optionEl = document.createElement('option'); | ||
optionEl.setAttribute('value', k); | ||
optionEl.textContent = promptOptions.selectOptions[k]; | ||
if (k === promptOptions.value) { | ||
optionEl.setAttribute('selected', 'selected'); | ||
} | ||
dataEl.appendChild(optionEl); | ||
dataEl.setAttribute(k, promptOptions.inputAttrs[k]); | ||
} | ||
} | ||
dataContainerEl.appendChild(dataEl); | ||
dataEl.setAttribute('id', 'data'); | ||
dataEl.focus(); | ||
if (promptOptions.type === 'input') { | ||
dataEl.select(); | ||
dataEl.addEventListener('keyup', e => { | ||
e.which = e.which || e.keyCode; | ||
if (e.which === 13) { | ||
promptSubmit(); | ||
} | ||
if (e.which === 27) { | ||
promptCancel(); | ||
} | ||
}); | ||
} | ||
dataEl.focus(); | ||
}); |
{ | ||
"name": "electron-prompt-chi", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Electron helper to prompt for a value via input or select", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
37020
652
1