@kizmann/nano-ui 0.7.25 → 0.7.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kizmann/nano-ui",
3
- "version": "0.7.25",
3
+ "version": "0.7.26",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "author": "Eduard Kizmann <kizmann@protonmail.ch>",
@@ -316,11 +316,13 @@ export default {
316
316
  {
317
317
  return {
318
318
  uid: UUID(),
319
+ modifier: [],
319
320
  virtuals: [],
320
321
  visible: [],
321
322
  childNodes: {},
322
323
  highlight: [],
323
- firstSelected: null,
324
+ firstSelected: null,
325
+ lastSelected: null,
324
326
  tempCurrent: this.current,
325
327
  tempExpanded: this.expanded,
326
328
  tempSelected: this.selected
@@ -330,6 +332,12 @@ export default {
330
332
  beforeMount()
331
333
  {
332
334
  this.drag = new NDraghandler(this);
335
+
336
+ Dom.find(window).on('keydown',
337
+ this.watchModifierDown, this._uid);
338
+
339
+ Dom.find(window).on('keyup',
340
+ this.watchModifierUp, this._uid);
333
341
  },
334
342
 
335
343
  mounted()
@@ -350,6 +358,7 @@ export default {
350
358
  this.drag.unbindRoot();
351
359
 
352
360
  Dom.find(document).off('keydown', null, this.uid);
361
+ Dom.find(document).off('keyup', null, this.uid);
353
362
  },
354
363
 
355
364
  watch: {
@@ -389,6 +398,16 @@ export default {
389
398
 
390
399
  methods: {
391
400
 
401
+ watchModifierDown(e)
402
+ {
403
+ Arr.add(this.modifier, e.which);
404
+ },
405
+
406
+ watchModifierUp(e)
407
+ {
408
+ Arr.remove(this.modifier, e.which);
409
+ },
410
+
392
411
  watchSelected()
393
412
  {
394
413
  if ( ! this.tempSelected.length ) {
@@ -709,13 +728,45 @@ export default {
709
728
  this.tempSelected;
710
729
  },
711
730
 
731
+ toggleSingleNode(node)
732
+ {
733
+ Arr.toggle(this.tempSelected, this.lastSelected =
734
+ node.value[this.uniqueProp]);
735
+ },
736
+
737
+ toggleRangeNode(node)
738
+ {
739
+ let indexies = [0, -1], reversed = false;
740
+
741
+ if ( ! Any.isEmpty(this.lastSelected) ) {
742
+ indexies[1] = this.getIndex(this.lastSelected);
743
+ }
744
+
745
+ indexies[0] = this.getIndex(node.value[this.uniqueProp]);
746
+
747
+ if ( indexies[1] > indexies[0] ) {
748
+ reversed = true;
749
+ }
750
+
751
+ if ( ! reversed ) {
752
+ indexies = [indexies[1]+1, indexies[0]+1];
753
+ }
754
+
755
+ Arr.each(this.items.slice(indexies[0], indexies[1]), (item, index) => {
756
+ Arr.toggle(this.tempSelected, item[this.uniqueProp]);
757
+ });
758
+
759
+ this.lastSelected = node.value[this.uniqueProp];
760
+ },
761
+
712
762
  selectItem(node)
713
763
  {
714
764
  if ( this.isDisabled(node) ) {
715
765
  return;
716
766
  }
717
767
 
718
- Arr.toggle(this.tempSelected, node.value[this.uniqueProp]);
768
+ ! Arr.has(this.modifier, 16) || this.renderExpand ?
769
+ this.toggleSingleNode(node) : this.toggleRangeNode(node);
719
770
 
720
771
  this.$emit('update:selected', this.tempSelected);
721
772
  },
@@ -734,6 +785,8 @@ export default {
734
785
  return this.$emit('update:selected', this.tempSelected = []);
735
786
  }
736
787
 
788
+ this.lastSelected = null;
789
+
737
790
  this.$emit('update:selected', this.tempSelected = indexies);
738
791
  },
739
792