- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.js
More file actions
Latest commit
153 lines (138 loc) · 4.77 KB
/
Copy pathhandler.js
File metadata and controls
153 lines (138 loc) · 4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
letel_files,el_generate,el_copy,el_download,el_downloadAll,el_input,el_messageHolder,el_messageText,
el_modalButton,el_modalHolder,el_modalClose,el_modalCloseButton,
el_modal_PHP8,el_modal_defaultDB,el_modal_indent,el_modal_generate_database;
letlastInput="";
/** @type {?OutputFile} */
letcurrentFile=null;
/** @type {OutputFile[]|null} */
letlastOutput=null;
letoptions={
PHP8syntax: true,
defaultDB: "UNDEFINED_DATABASE",
generateFiles: {
// "Main.php": true,
"Database.php": true,
},
indent: " ".repeat(4),
};
/** @param {OutputFile} file */
functionaddFileToList(file,color=null){
leti=document.createElement("i");
i.classList.add("fas");
i.classList.add("fa-file-alt");
i.setAttribute("aria-hidden","true");
letspan=document.createElement("span");
span.classList.add("panel-icon");
if(color!==null)span.style.color=color;
span.appendChild(i);
leta=document.createElement("a");
a.classList.add("panel-block");
a.classList.add("is-primary");
a.appendChild(span);
a.appendChild(document.createTextNode(file.name));
a.onclick=()=>showFile(file);
el_files.appendChild(a);
}
/** @param {OutputFile} file */
functionshowFile(file){
if(!el_input.hasAttribute("readonly"))
lastInput=el_input.value;
currentFile=file;
el_input.value=file.content;
el_input.setAttribute("readonly","true");
}
functionshowInput(){
if(!el_input.hasAttribute("readonly"))
return;
currentFile=null;
el_input.removeAttribute("readonly");
el_input.value=lastInput;
}
functionshowError(e){
messageText.innerText=e.message;
messageHolder.style.opacity=1;
}
onload=()=>{
el_files=document.getElementById("files");
el_generate=document.getElementById("generate");
el_download=document.getElementById("download");
el_downloadAll=document.getElementById("downloadAll");
// el_copy = document.getElementById("copy");
el_input=document.getElementById("input");
el_messageHolder=document.getElementById("messageHolder");
el_messageText=document.getElementById("messageText");
el_modalButton=document.getElementById("options");
el_modalHolder=document.getElementById("modal");
el_modalClose=document.getElementById("modalClose");
el_modalCloseButton=document.getElementById("modalCloseButton");
el_modal_PHP8=document.getElementById("modal_PHP8");
el_modal_defaultDB=document.getElementById("modal_defaultDB");
el_modal_indent=document.getElementById("modal_indent");
el_modal_generate_database=document.getElementById("modal_generate_database");
el_generate.onclick=()=>{
generate();
};
// el_copy.onclick = () => {
// el_input.focus();
// el_input.select();
// document.execCommand('copy');
// };
el_download.onclick=()=>{
if(currentFile===null)
return;
saveAs(newBlob([currentFile.content],{type: "text/plain;charset=utf-8"}),currentFile.name);
};
el_downloadAll.onclick=()=>{
if(lastOutput===null)
return;
letzip=JSZip();
for(letfileofObject.values(lastOutput))
zip.file(file.name,file.content);
zip.generateAsync({type:"blob"}).then((blob)=>{
saveAs(blob,"SQL2PHP.zip");
});
};
el_modalButton.onclick=()=>{
el_modalHolder.classList.toggle("is-active");
getSettings();// Called even on open but who cares LULW
};
el_modalClose.onclick=el_modalButton.onclick;
el_modalCloseButton.onclick=el_modalButton.onclick;
};
functiongenerate(){
letinput=el_input.hasAttribute("readonly") ? lastInput : el_input.value;
if(input=="")
return;
letfiles;
try{
files=SQL2PHP(input,options);
}catch(e){
showError(e);
return;
}
el_files.innerHTML="";
for(letfileofObject.values(files))
addFileToList(file);
lastOutput=files;
if(currentFile!==null&¤tFile.nameinfiles)
showFile(files[currentFile.name]);
}
functiongetSettings(){
options.PHP8syntax=el_modal_PHP8.checked;
options.generateFiles["Database.php"]=el_modal_generate_database.checked;
options.defaultDB=el_modal_defaultDB.value;
if(options.defaultDB=="")
options.defaultDB="UNDEFINED_DATABASE";
options.indent=el_modal_indent.value;
if(options.indent=="")
options.indent=" ".repeat(4);
}
functiondrop(e){
e.preventDefault();
letfile=e.dataTransfer.files[0];
if(!file||!("text"infile))return;
file.text().then((x)=>{
el_input.value=x;
generate();
});
}