tree: add an input for filtering displayed widget by id
This commit is contained in:
parent
9dae9c5c9d
commit
420bd55e7a
6 changed files with 70 additions and 6 deletions
|
|
@ -1,5 +1,10 @@
|
|||
# Changelog
|
||||
|
||||
## next
|
||||
|
||||
- project tree
|
||||
- add an input for filtering displayed widget by id
|
||||
|
||||
## 1.8.2
|
||||
|
||||
- bug fixes
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ module.exports = {
|
|||
if (selector.indexOf(' ') === -1 && selector.indexOf(',') === -1) {
|
||||
if (selector.indexOf('#') === 0 && context === document) {
|
||||
nodes = [document.getElementById(selector.substr(1, selector.length - 1))]
|
||||
} else if (selector.indexOf('.') === 0) {
|
||||
} else if (selector.lastIndexOf('.') === 0) {
|
||||
nodes = context.getElementsByClassName(selector.substr(1, selector.length - 1))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,6 +91,9 @@ module.exports = {
|
|||
state_recallsuccess: 'State recalled',
|
||||
state_sendsuccess: 'State sent',
|
||||
|
||||
// tree
|
||||
tree_filter: 'Filter',
|
||||
|
||||
// misc
|
||||
error: 'Error'
|
||||
|
||||
|
|
|
|||
|
|
@ -90,6 +90,9 @@ module.exports = {
|
|||
state_recallsuccess: 'État de l\'interface restauré',
|
||||
state_sendsuccess: 'État de de l\'interface envoyé',
|
||||
|
||||
// tree
|
||||
tree_filter: 'Filtrer',
|
||||
|
||||
// misc
|
||||
error: 'Erreur'
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ var UiWidget = require('./ui-widget'),
|
|||
doubleClick = require('../events/double-click'),
|
||||
Sortable = require('sortablejs'),
|
||||
morph = require('nanomorph'),
|
||||
locales = require('../locales'),
|
||||
Root, Panel, Matrix, Keyboard, widgetManager,
|
||||
init = false
|
||||
|
||||
|
|
@ -19,6 +20,7 @@ class UiTree extends UiWidget {
|
|||
super(options)
|
||||
|
||||
this.mounted = false
|
||||
this.filter = this.container.appendChild(html`<input class="filter" type="text" placeholder="${locales('tree_filter')}..."/>`)
|
||||
this.list = this.container.appendChild(html`<ol style="--depth: 1"></ol`)
|
||||
this.dragDummy = html`<span></span>`
|
||||
this.deferredUpdateTimeout = null
|
||||
|
|
@ -66,8 +68,15 @@ class UiTree extends UiWidget {
|
|||
})
|
||||
}
|
||||
|
||||
widgetManager.on('prop-changed', (e)=>{
|
||||
console.log(e)
|
||||
this.filter.addEventListener('change', ()=>{
|
||||
this.applyFilter()
|
||||
})
|
||||
var filterTypeTimeout = null
|
||||
this.filter.addEventListener('keydown', ()=>{
|
||||
clearTimeout(filterTypeTimeout)
|
||||
filterTypeTimeout = setTimeout(()=>{
|
||||
this.applyFilter()
|
||||
}, 100)
|
||||
})
|
||||
|
||||
}
|
||||
|
|
@ -134,7 +143,7 @@ class UiTree extends UiWidget {
|
|||
})
|
||||
|
||||
this.mounted = true
|
||||
|
||||
this.applyFilter()
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -207,6 +216,30 @@ class UiTree extends UiWidget {
|
|||
|
||||
}
|
||||
|
||||
applyFilter() {
|
||||
|
||||
var filter = this.filter.value
|
||||
|
||||
if (!filter) {
|
||||
this.list.classList.remove('filter-active')
|
||||
} else {
|
||||
this.list.classList.add('filter-active')
|
||||
|
||||
var show = []
|
||||
DOM.each(this.list, 'li', (element)=>{
|
||||
var match = element.innerText.includes(filter)
|
||||
element.classList.toggle('filter-hide', !match)
|
||||
if (match) show.push(element)
|
||||
})
|
||||
|
||||
DOM.each(this.list, '.container.filter-hide', (element)=>{
|
||||
if (show.some(el=>element.contains(el))) element.classList.remove('filter-hide')
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = UiTree
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@
|
|||
|
||||
|
||||
ol {
|
||||
|
||||
list-style: none;
|
||||
position: relative;
|
||||
padding-left: 16rem;
|
||||
|
|
@ -107,11 +106,32 @@
|
|||
@include pseudo-fill($z: -1);
|
||||
&:after {
|
||||
left: calc(-1 * var(--depth) * 16rem - #{$padding});
|
||||
right: -($padding - 1);
|
||||
right: 1rem;
|
||||
bottom: auto;
|
||||
height: $line-height;
|
||||
opacity: 0.1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
> ol {
|
||||
margin-top: $line-height + 5rem;
|
||||
}
|
||||
|
||||
.filter {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
width: calc(100% + #{$padding});
|
||||
display: block;
|
||||
background: var(--color-background);
|
||||
font-family: $font-mono;
|
||||
line-height: $field-height;
|
||||
padding: 4rem $padding;
|
||||
}
|
||||
|
||||
.filter-active .filter-hide {
|
||||
display:none;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue