Skip to content

Commit 3362298

Browse files
committed
New features
1 parent 3f1680d commit 3362298

File tree

8 files changed

+162
-42
lines changed

8 files changed

+162
-42
lines changed

dist/main.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

icon.png

-23.2 KB
Loading

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "acode-plugin-packageAdder",
2+
"name": "acode-plugin-moduleAdder",
33
"version": "1.0.0",
4-
"description": "Add Package Plugin For Acode",
4+
"description": "Module Adder Plugin For Acode",
55
"main": "dist/main.js",
66
"scripts": {
77
"start-dev": "node .vscode/start-dev",

plugin.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"id": "acode.plugin.packageAdder",
3-
"name": "Add Package",
2+
"id": "acode.plugin.moduleAdder",
3+
"name": "Module Adder",
44
"type": "free",
55
"main": "dist/main.js",
66
"version": "1.0.0",
77
"readme": "readme.md",
88
"icon": "icon.png",
99
"files": [],
1010
"author": {
11-
"name": "Raunak & David",
11+
"name": "Raunak ",
1212
"email": "[email protected]",
1313
"github": "bajrangCoder"
1414
}

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Add Package
1+
# Module Adder
22

33
Nothing to see here....
44
> Under Development

src/main.js

Lines changed: 99 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@ import style from './style.scss';
33
import tag from 'html-tag-js';
44

55
const loader = acode.require('loader');
6-
6+
const select = acode.require('select');
7+
const cAlert = acode.require('alert');
78

89
class AddPackage {
910

1011
async init($page) {
1112
let command = {
12-
name: "Add Package",
13-
description: "Add Package",
13+
name: "Module Adder",
14+
description: "Module Adder",
1415
exec: this.run.bind(this),
1516
}
1617
editorManager.editor.commands.addCommand(command);
17-
$page.id = 'acode-plugin-packageAdder';
18-
$page.settitle("Add Package");
18+
$page.id = 'acode-plugin-moduleAdder';
19+
$page.settitle("Module Adder");
1920
this.$page = $page;
2021
this.$style = tag('style', {
2122
textContent: style,
@@ -94,30 +95,41 @@ class AddPackage {
9495
field4.append(...[lb4,this.filesList]);
9596
this.$plugPage2.append(headerDiv);
9697
this.$plugPage2.append(mainDiv);
98+
this.footer = tag('div',{
99+
className: "footer",
100+
});
97101
this.$backBtn = tag('button',{
98102
textContent: "Back",
103+
className: "backBtn",
99104
});
100-
this.$plugPage2.append(this.$backBtn);
105+
this.$addLibBtn = tag('button',{
106+
textContent: "Add Library",
107+
className: "addLibBtn",
108+
});
109+
this.footer.append(...[this.$backBtn,this.$addLibBtn]);
110+
this.$plugPage2.append(this.footer);
101111
this.$backBtn.onclick = this.backToPage1.bind(this);
112+
this.$addLibBtn.onclick = this.addLibrary.bind(this);
113+
this.versionSelector.onchange = this.changeVersion.bind(this);
102114
document.head.append(this.$style);
103115
const onhide = this.$page.onhide;
104116
this.$page.onhide = () => {
105-
this.$plugPage2.classList.toggle('hide');
106-
this.$plugPage1.classList.toggle('hide');
117+
this.$plugPage2.classList.add('hide');
118+
this.$plugPage1.classList.add('hide');
107119
}
108120
onhide();
109121
}
110122

111123
async run() {
112-
this.loadLibraries('https://api.cdnjs.com/libraries?fields=filename,description,github&limit=10');
113-
this.$plugPage1.classList.toggle('hide');
114124
this.$page.show();
125+
this.loadLibraries('https://api.cdnjs.com/libraries?fields=filename,description,github&limit=10');
126+
this.$plugPage1.classList.remove('hide');
115127
}
116128

117129
async loadLibraries(url){
118130
try {
119131
this.pkgLists.innerHTML = '';
120-
loader.create('Loading','Fetching data from api');
132+
loader.create('Loading','Fetching data...');
121133
const response = await fetch(url);
122134
let data = await response.json();
123135
loader.destroy();
@@ -152,7 +164,7 @@ class AddPackage {
152164
li.onclick = this.pkgDetails.bind(this,obj.name);
153165
});
154166
} catch (e) {
155-
window.toast(e,5000);
167+
this.closePlugin();
156168
}
157169
}
158170

@@ -165,30 +177,76 @@ class AddPackage {
165177

166178
let url = `https://api.cdnjs.com/libraries/${libNme}?fields=name,author,description,filename,version,versions,repository,license,assets`;
167179
try {
168-
loader.create('Loading','Fetching data from api');
180+
loader.create('Loading','Fetching data...');
169181
const response = await fetch(url);
170182
let data = await response.json();
171183
loader.destroy();
172-
this.$plugPage1.classList.toggle('hide');
173-
this.$plugPage2.classList.toggle('hide');
184+
this.$plugPage1.classList.add('hide');
185+
this.$plugPage2.classList.remove('hide');
174186
this.libName.textContent = data.name;
175187
this.descrTxt.textContent = data.description;
176188
this.lisenceTxt.textContent = data.license;
177189
this.authrTxt.textContent = data.author;
178190

179-
for(let i = 0;i<data.versions.length;i++){
180-
if (data.versions[i] == data.version) {
181-
this.versionSelector.innerHTML += `<option value="${data.versions[i]}" selected>${data.versions[i]}</option>`;
191+
const filteredVersions = data.versions.filter(version => {
192+
return !version.includes('alpha') && !version.includes('beta') && !version.includes('rc') && !version.includes('csp') && !version.includes('migration');
193+
});
194+
let last50 = filteredVersions.slice(-50);
195+
196+
for(let i = 0;i<last50.length;i++){
197+
if (last50[i] == data.version) {
198+
this.versionSelector.innerHTML += `<option value="${last50[i]}" selected>${last50[i]}</option>`;
182199
} else {
183-
this.versionSelector.innerHTML += `<option value="${data.versions[i]}">${data.versions[i]}</option>`;
200+
this.versionSelector.innerHTML += `<option value="${last50[i]}">${last50[i]}</option>`;
184201
}
185202
}
203+
this.filesList.innerHTML ="";
186204
let files = data.assets[0].files;
187205
for(let i = 0;i<files.length;i++){
188-
this.filesList.innerHTML += `<li>${files[i]}</li>`;
206+
const list = tag('li');
207+
const filesCheckBox = tag('input',{
208+
type: "checkbox",
209+
className: "filesCheckBox",
210+
value: files[i],
211+
});
212+
const filesLabel = tag('p',{
213+
textContent: files[i],
214+
className: "filesLabel"
215+
});
216+
list.append(...[filesCheckBox,filesLabel]);
217+
this.filesList.append(list);
218+
}
219+
} catch (e) {
220+
this.closePlugin();
221+
}
222+
}
223+
224+
async changeVersion(){
225+
let pkg_nme = this.libName.textContent;
226+
let selectedVersion = this.versionSelector.value;
227+
228+
let url = `https://api.cdnjs.com/libraries/${pkg_nme}/${selectedVersion}`;
229+
try {
230+
loader.create('Loading','Fetching files...');
231+
const response = await fetch(url);
232+
let data = await response.json();
233+
loader.destroy();
234+
this.filesList.innerHTML = '';
235+
for(let i =0;i<data.files.length;i++){
236+
const list = tag('li');
237+
const filesCheckBox = tag('input',{
238+
type: "checkbox",
239+
className: "filesCheckBox",
240+
value: data.files[i],
241+
});
242+
const filesLabel = tag('p',{
243+
textContent: data.files[i],
244+
});
245+
list.append(...[filesCheckBox,filesLabel]);
246+
this.filesList.append(list);
189247
}
190248
} catch (e) {
191-
window.toast(e,5000);
249+
this.closePlugin();
192250
}
193251
}
194252

@@ -197,10 +255,28 @@ class AddPackage {
197255
this.$plugPage1.classList.toggle('hide');
198256
}
199257

258+
closePlugin(){
259+
this.$page.hide();
260+
cAlert('Error','Connection error, check your internet and Try Again!');
261+
loader.destroy();
262+
}
263+
264+
async addLibrary(){
265+
const addLibTypeSelector = await select('Select Type', ["Api","Download Files"], {default: "Api",});
266+
let filesCheckbox = document.querySelectorAll(".filesCheckBox");
267+
let filesArray = [];
268+
for (var i = 0; i < filesCheckbox.length; i++) {
269+
if (filesCheckbox[i].checked) {
270+
filesArray.push(filesCheckbox[i].value);
271+
}
272+
}
273+
window.toast(filesArray,4000);
274+
}
275+
200276
async destroy() {
201277
let command = {
202-
name: "Add Package",
203-
description: "Add Package",
278+
name: "Module Adder",
279+
description: "Module Adder",
204280
exec: this.run.bind(this),
205281
}
206282
editorManager.editor.commands.removeCommand(command);

src/style.scss

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#acode-plugin-packageAdder{
1+
#acode-plugin-moduleAdder{
22
.hide{
33
display: none;
44
}
@@ -46,6 +46,7 @@
4646
h4{
4747
margin-left: 20px;
4848
font-weight: 500;
49+
font-size: 20px;
4950
}
5051
}
5152
.pkgMain{
@@ -74,13 +75,19 @@
7475
display: flex;
7576
padding: 20px;
7677
h2{
77-
font-size: 25px;
78+
font-size: 20px;
7879
width: 100%;
80+
font-weight: 500;
7981
}
8082
select{
8183
padding: 8px;
8284
margin-left: 10px;
8385
outline: none;
86+
width: 100px;
87+
background: transparent;
88+
color: var(--secondary-text-color);
89+
border: 1px solid var(--primary-color);
90+
box-shadow: 0 2px 4px var(--box-shadow-color);
8491
}
8592
}
8693
.mainDiv{
@@ -89,14 +96,51 @@
8996
margin-bottom: 25px;
9097
label{
9198
font-size: 15px;
92-
color: #eff0f0;
93-
font-weight: 700;
94-
margin-bottom: 20px;
99+
color: var(--border-color);
100+
font-weight: 500;
101+
margin-bottom: 10px;
95102
}
96103
p{
97-
font-size: 18px;
98-
font-weight: 500;
104+
margin-top: 10px;
105+
font-size: 17px;
106+
font-weight: 400;
99107
}
108+
ul {
109+
list-style: none;
110+
li{
111+
display: flex;
112+
margin-top: 10px;
113+
font-size: 17px;
114+
font-weight: 400;
115+
.filesLabel{
116+
width: 100%;
117+
margin-left: 10px;
118+
}
119+
}
120+
}
121+
}
122+
}
123+
.footer{
124+
display: flex;
125+
flex-direction: column;
126+
justify-content: space-between;
127+
margin-top: 15px;
128+
.backBtn{
129+
border: none;
130+
background: var(--primary-color);
131+
color: var(--button-text-color);
132+
padding: 10px;
133+
border-radius: 10px;
134+
font-size: 18px;
135+
margin-bottom: 10px;
136+
}
137+
.addLibBtn{
138+
border: none;
139+
background: var(--button-background-color);
140+
color: var(--button-text-color);
141+
padding: 10px;
142+
border-radius: 10px;
143+
font-size: 18px;
100144
}
101145
}
102146
}

0 commit comments

Comments
 (0)