Socket
Socket
Sign inDemoInstall

electron-prompt-chi

Package Overview
Dependencies
2
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

106

lib/page/prompt.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc