mirror of
https://github.com/chinchang/web-maker.git
synced 2025-08-25 14:11:04 +02:00
add loader and polish library autocompletion
This commit is contained in:
@@ -172,10 +172,10 @@
|
|||||||
<div class="modal__content" id="app">
|
<div class="modal__content" id="app">
|
||||||
<h1>Add Library</h1>
|
<h1>Add Library</h1>
|
||||||
<h3>JavaScript</h3>
|
<h3>JavaScript</h3>
|
||||||
<textarea id="js-external-js" class="full-width" id="" cols="30" rows="5" placeholder="Put each library in new line"></textarea>
|
<textarea id="js-external-js" class="full-width" id="" cols="30" rows="5" placeholder="Start typing name of a library. Put each library in new line"></textarea>
|
||||||
|
|
||||||
<h3>CSS</h3>
|
<h3>CSS</h3>
|
||||||
<textarea id="js-external-css" class="full-width" id="" cols="30" rows="5" placeholder="Put each library in new line"></textarea>
|
<textarea id="js-external-css" class="full-width" id="" cols="30" rows="5" placeholder="Start typing name of a library. Put each library in new line"></textarea>
|
||||||
|
|
||||||
<div style="margin-top:20px;">
|
<div style="margin-top:20px;">
|
||||||
Choose from popular libraries:
|
Choose from popular libraries:
|
||||||
|
@@ -554,6 +554,32 @@ li.CodeMirror-hint-active {
|
|||||||
top: 2px;
|
top: 2px;
|
||||||
left: 2px;
|
left: 2px;
|
||||||
}
|
}
|
||||||
|
.loader,
|
||||||
|
.loader:after {
|
||||||
|
border-radius: 50%;
|
||||||
|
width: 3em;
|
||||||
|
height: 3em;
|
||||||
|
}
|
||||||
|
.loader {
|
||||||
|
font-size: 5px;
|
||||||
|
position: relative;
|
||||||
|
text-indent: -9999em;
|
||||||
|
border-top: 1.1em solid rgba(118,57,229, 0.2);
|
||||||
|
border-right: 1.1em solid rgba(118,57,229, 0.2);
|
||||||
|
border-bottom: 1.1em solid rgba(118,57,229, 0.2);
|
||||||
|
border-left: 1.1em solid #7639e5;
|
||||||
|
transform: translateZ(0);
|
||||||
|
animation: load8 1.1s infinite linear;
|
||||||
|
}
|
||||||
|
@keyframes load8 {
|
||||||
|
0% {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.btn-group {
|
.btn-group {
|
||||||
position: relative;
|
position: relative;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
@@ -566,12 +592,13 @@ li.CodeMirror-hint-active {
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
min-width: 200px;
|
min-width: 200px;
|
||||||
display: block;
|
display: block;
|
||||||
|
font-size: 0.88rem;
|
||||||
list-style: none;
|
list-style: none;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
transition: 0.25s ease;
|
transition: transform 0.25s ease;
|
||||||
transform: translateY(10px);
|
transform: translateY(10px);
|
||||||
z-index: 5;
|
z-index: 5;
|
||||||
background: white;
|
background: white;
|
||||||
@@ -591,7 +618,8 @@ li.CodeMirror-hint-active {
|
|||||||
border-bottom: 1px solid rgba(0,0,0,0.05);
|
border-bottom: 1px solid rgba(0,0,0,0.05);
|
||||||
}
|
}
|
||||||
|
|
||||||
.open .dropdown__menu {
|
.open > .dropdown__menu,
|
||||||
|
.dropdown__menu.is-open {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
visibility: visible;
|
visibility: visible;
|
||||||
transform: translateY(0);
|
transform: translateY(0);
|
||||||
@@ -680,9 +708,16 @@ li.CodeMirror-hint-active {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.autocomplete-dropdown {
|
.autocomplete-dropdown {
|
||||||
border-bottom-left-radius: 0;
|
border-top-left-radius: 0;
|
||||||
border-bottom-right-radius: 0;
|
border-top-right-radius: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
max-height: 200px;
|
max-height: 200px;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
|
border: 1px solid rgba(0,0,0,0.5);
|
||||||
|
z-index: 2001;
|
||||||
|
}
|
||||||
|
.autocomplete__loader {
|
||||||
|
position: absolute;
|
||||||
|
right: 10px;
|
||||||
|
bottom: 10px;
|
||||||
}
|
}
|
@@ -19,9 +19,25 @@
|
|||||||
this.list.classList.add('autocomplete-dropdown');
|
this.list.classList.add('autocomplete-dropdown');
|
||||||
wrap.insertBefore(this.list, null);
|
wrap.insertBefore(this.list, null);
|
||||||
|
|
||||||
|
this.loader = document.createElement('div');
|
||||||
|
this.loader.classList.add('loader');
|
||||||
|
this.loader.classList.add('autocomplete__loader');
|
||||||
|
this.loader.style.display = 'none';
|
||||||
|
wrap.insertBefore(this.loader, null);
|
||||||
|
|
||||||
|
// after list is insrted into the DOM, we put it in the body
|
||||||
|
// fixed at same position
|
||||||
|
setTimeout(() => {
|
||||||
|
requestIdleCallback(() => {
|
||||||
|
document.body.appendChild(this.list);
|
||||||
|
this.list.style.position = 'fixed';
|
||||||
|
});
|
||||||
|
},100);
|
||||||
|
|
||||||
this.t.addEventListener('input', e => this.onInput(e));
|
this.t.addEventListener('input', e => this.onInput(e));
|
||||||
this.t.addEventListener('keydown', e => this.onKeyDown(e));
|
this.t.addEventListener('keydown', e => this.onKeyDown(e));
|
||||||
this.t.addEventListener('blur', e => this.closeSuggestions())
|
this.t.addEventListener('blur', e => this.closeSuggestions());
|
||||||
|
this.list.addEventListener('mousedown', e => this.onListMouseDown(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
get currentLineNumber() {
|
get currentLineNumber() {
|
||||||
@@ -32,7 +48,7 @@
|
|||||||
return this.t.value.split('\n')[line - 1];
|
return this.t.value.split('\n')[line - 1];
|
||||||
}
|
}
|
||||||
closeSuggestions() {
|
closeSuggestions() {
|
||||||
this.list.parentElement.classList.remove('open');
|
this.list.classList.remove('is-open');
|
||||||
this.isShowingSuggestions = false;
|
this.isShowingSuggestions = false;
|
||||||
}
|
}
|
||||||
getList(input) {
|
getList(input) {
|
||||||
@@ -63,9 +79,12 @@
|
|||||||
onInput() {
|
onInput() {
|
||||||
var currentLine = this.currentLine;
|
var currentLine = this.currentLine;
|
||||||
if (currentLine) {
|
if (currentLine) {
|
||||||
|
if (currentLine.indexOf('/') !== -1 || currentLine.match(/https*:\/\//)) { return; }
|
||||||
clearTimeout(this.timeout);
|
clearTimeout(this.timeout);
|
||||||
this.timeout = setTimeout(() => {
|
this.timeout = setTimeout(() => {
|
||||||
|
this.loader.style.display = 'block';
|
||||||
this.getList(currentLine).then(arr => {
|
this.getList(currentLine).then(arr => {
|
||||||
|
this.loader.style.display = 'none';
|
||||||
if (!arr.length) {
|
if (!arr.length) {
|
||||||
this.closeSuggestions();
|
this.closeSuggestions();
|
||||||
return;
|
return;
|
||||||
@@ -77,13 +96,21 @@
|
|||||||
for (var i = 0; i < Math.min(arr.length, 10); i++) {
|
for (var i = 0; i < Math.min(arr.length, 10); i++) {
|
||||||
this.list.innerHTML += `<li data-url="${arr[i].latest}"><a>${arr[i].name}</a></li>`;
|
this.list.innerHTML += `<li data-url="${arr[i].latest}"><a>${arr[i].name}</a></li>`;
|
||||||
}
|
}
|
||||||
this.list.parentElement.classList.add('open');
|
|
||||||
this.isShowingSuggestions = true;
|
this.isShowingSuggestions = true;
|
||||||
|
if (!this.textareaBounds) {
|
||||||
|
this.textareaBounds = this.t.getBoundingClientRect();
|
||||||
|
this.list.style.top = this.textareaBounds.bottom + 'px';
|
||||||
|
this.list.style.left = this.textareaBounds.left + 'px';
|
||||||
|
this.list.style.width = this.textareaBounds.width + 'px';
|
||||||
|
}
|
||||||
|
this.list.classList.add('is-open');
|
||||||
});
|
});
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onKeyDown(event) {
|
onKeyDown(event) {
|
||||||
|
if (!this.isShowingSuggestions) { return; }
|
||||||
|
|
||||||
if (event.keyCode === 27) {
|
if (event.keyCode === 27) {
|
||||||
this.closeSuggestions();
|
this.closeSuggestions();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
@@ -112,6 +139,13 @@
|
|||||||
this.closeSuggestions();
|
this.closeSuggestions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
onListMouseDown(event) {
|
||||||
|
var target = event.target;
|
||||||
|
if (target.parentElement.dataset.url) {
|
||||||
|
this.replaceCurrentLine(target.parentElement.dataset.url)
|
||||||
|
this.closeSuggestions();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.TextareaAutoComplete = TextareaAutoComplete;
|
window.TextareaAutoComplete = TextareaAutoComplete;
|
||||||
|
Reference in New Issue
Block a user