MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / prompt

Function prompt

src/dialogs/prompt.js:24–169  ·  view source on GitHub ↗
(
	message,
	defaultValue,
	type = "text",
	options = {},
)

Source from the content-addressed store, hash-verified

22 */
23
24export default function prompt(
25 message,
26 defaultValue,
27 type = "text",
28 options = {},
29) {
30 // CodeMirror doesn't use commands.exec like ACE, so we store a reference to the editor
31 // to potentially disable keymaps if needed in the future
32 const editor = editorManager.editor;
33 const { capitalize = true } = options;
34
35 return new Promise((resolve) => {
36 const inputType = type === "textarea" ? "textarea" : "input";
37 type = type === "filename" ? "text" : type;
38
39 const messageSpan = tag("span", {
40 textContent: message,
41 className: "message scroll",
42 });
43 const input = tag(inputType, {
44 value: defaultValue,
45 className: "input",
46 placeholder: options.placeholder,
47 autocapitalize: capitalize ? "on" : "off",
48 });
49 const okBtn = tag("button", {
50 type: "submit",
51 textContent: strings.ok,
52 disabled: !defaultValue,
53 onclick: function () {
54 if (options.required && !input.value) {
55 errorMessage.textContent = strings.required;
56 return;
57 }
58 hide();
59 let { value } = input;
60 if (type === "number") value = +value;
61
62 resolve(value);
63 },
64 });
65 const cancelBtn = tag("button", {
66 textContent: strings.cancel,
67 type: "button",
68 onclick: function () {
69 hide();
70 resolve(null);
71 },
72 });
73 const errorMessage = tag("span", {
74 className: "error-msg",
75 });
76 const promptDiv = tag("form", {
77 action: "#",
78 className: "prompt",
79 onsubmit: (e) => {
80 e.preventDefault();
81 if (!okBtn.disabled) {

Callers 13

settingsPage.jsFile · 0.50
fontManager.jsFile · 0.50
onselectFunction · 0.50
addSourceFunction · 0.50
contextMenuHandlerFunction · 0.50
createFunction · 0.50
openInAppBrowserCommandFunction · 0.50
performRenameFunction · 0.50
callbackFunction · 0.50
promptInstallerFunction · 0.50
callbackFunction · 0.50
filterPluginsFunction · 0.50

Calls 9

resolveFunction · 0.85
restoreThemeFunction · 0.85
setInputTypeMethod · 0.80
appendMethod · 0.80
focusMethod · 0.80
hideFunction · 0.70
testFunction · 0.50
preventDefaultMethod · 0.45
selectMethod · 0.45

Tested by

no test coverage detected