Skip to content

Commit b9fcfa4

Browse files
committed
fix input problem for popups + improve js test server
1 parent 6de84fd commit b9fcfa4

File tree

2 files changed

+16
-30
lines changed

2 files changed

+16
-30
lines changed

src/utils/popups.ts

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,39 +51,25 @@ export class Popup {
5151

5252
/**
5353
* Nota (for prompts):
54-
* - the input only handles characters, "Space" and "Backspace" yet. So the user can't use controls to copy/paste
55-
* strings, etc...
5654
* - if the input value length doesn't belong to the defined interval ([minLength; maxLength]), the button will be
5755
* disabled (by default, the interval is [0;255]).
5856
*/
5957
async getResponse(): Promise<any> {
6058
this.popupElement.style.display = "flex"
6159

62-
if(this.data.type === "show") {
63-
return new Promise((resolve, reject) => {
60+
return new Promise((resolve, reject) => {
61+
if(this.data.type === "show") {
6462
document.querySelector('#cazan-popup-confirm')?.addEventListener(
6563
'click',
6664
() => {
6765
resolve(true)
6866
}
6967
)
70-
})
71-
} else if(this.data.type === "prompt") {
72-
return new Promise((resolve, reject) => {
68+
} else if(this.data.type === "prompt") {
7369
let inputElement: HTMLInputElement = document.querySelector("#cazan-popup-input")!
7470
let confirmBtnElement: HTMLButtonElement = document.querySelector("#cazan-popup-confirm")!
7571

7672
inputElement.addEventListener('keydown', (event: KeyboardEvent) => {
77-
event.preventDefault()
78-
79-
if(event.key === "Backspace") {
80-
inputElement.value = inputElement.value.slice(0, -1)
81-
} else if(event.key === "Space") {
82-
inputElement.value += " "
83-
} else if(event.key.length === 1) {
84-
inputElement.value += event.key
85-
}
86-
8773
if(
8874
inputElement.value.length >= this.data.minLength!
8975
&& inputElement.value.length <= this.data.maxLength!
@@ -108,9 +94,7 @@ export class Popup {
10894
}
10995
}
11096
)
111-
})
112-
} else if(this.data.type === "confirm") {
113-
return new Promise((resolve, reject) => {
97+
} else if(this.data.type === "confirm") {
11498
document.querySelector("#cazan-popup-yes")?.addEventListener(
11599
"click",
116100
() => {
@@ -123,10 +107,8 @@ export class Popup {
123107
resolve(false)
124108
}
125109
)
126-
})
127-
}
128-
129-
return new Promise((resolve, reject) => reject("Type undefined"))
110+
}
111+
})
130112
}
131113

132114
removePopup() {

tests/server.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,21 @@ http.createServer(function (req, res) {
3535
resContentType = 'text/plain'
3636
}
3737

38-
if(PATHS[url]) {
39-
resContent = fs.readFileSync(PATHS[url])
40-
} else {
41-
try {
38+
try {
39+
if(PATHS[url]) {
40+
resContent = fs.readFileSync(PATHS[url])
41+
} else {
4242
resContent = fs.readFileSync(`.${url}`)
43-
} catch (e) {} // file not found
44-
}
43+
}
44+
} catch (e) {} // file not found
4545

4646
if (resContent === '') {
4747
res.writeHead(404, {'Content-Type': 'text/plain'})
4848
res.write('404 Not Found')
49+
50+
if(url === "/cazan.js" || url === "/cazan.min.js") {
51+
console.error("Error: you didn't build Cazan or you didn't build it in /dist/lib. Please execute `yarn run build` or `yarn run release` and relaunch this server.")
52+
}
4953
} else {
5054
res.writeHead(200, {'Content-Type': resContentType})
5155
res.write(resContent)

0 commit comments

Comments
 (0)