itsa-react-table 16.7.1 → 16.8.0
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/lib/component.jsx +94 -23
- package/package.json +1 -1
package/lib/component.jsx
CHANGED
|
@@ -450,9 +450,12 @@ class Table extends React.Component {
|
|
|
450
450
|
_blurActiveCell() {
|
|
451
451
|
const instance = this,
|
|
452
452
|
state = instance.state,
|
|
453
|
-
textareaNode = instance['_textarea_'+state.editableRow+'_'+state.editableCol]
|
|
454
|
-
|
|
455
|
-
|
|
453
|
+
textareaNode = instance['_textarea_'+state.editableRow+'_'+state.editableCol],
|
|
454
|
+
componentContainerNode = instance['_component_'+state.editableRow+'_'+state.editableCol],
|
|
455
|
+
componentNode = componentContainerNode && componentContainerNode.itsa_getElement('button'),
|
|
456
|
+
focussableNode = textareaNode || componentNode;
|
|
457
|
+
if (focussableNode && ((document.activeElement===focussableNode) || document.activeElement.contains(focussableNode))) {
|
|
458
|
+
focussableNode.blur();
|
|
456
459
|
}
|
|
457
460
|
}
|
|
458
461
|
|
|
@@ -461,7 +464,9 @@ class Table extends React.Component {
|
|
|
461
464
|
async(() => {
|
|
462
465
|
let length;
|
|
463
466
|
const state = instance.state,
|
|
464
|
-
textareaNode = instance['_textarea_'+state.editableRow+'_'+state.editableCol]
|
|
467
|
+
textareaNode = instance['_textarea_'+state.editableRow+'_'+state.editableCol],
|
|
468
|
+
componentContainerNode = instance['_component_'+state.editableRow+'_'+state.editableCol],
|
|
469
|
+
componentNode = componentContainerNode && componentContainerNode.itsa_getElement('button');
|
|
465
470
|
if (textareaNode && (document.activeElement!==textareaNode)) {
|
|
466
471
|
instance._editValueBeforeEdit = textareaNode.value || '';
|
|
467
472
|
textareaNode.focus();
|
|
@@ -470,6 +475,9 @@ class Table extends React.Component {
|
|
|
470
475
|
textareaNode.setSelectionRange(0, length);
|
|
471
476
|
}
|
|
472
477
|
}
|
|
478
|
+
else if (componentNode) {
|
|
479
|
+
componentNode.focus();
|
|
480
|
+
}
|
|
473
481
|
});
|
|
474
482
|
}
|
|
475
483
|
|
|
@@ -628,6 +636,17 @@ class Table extends React.Component {
|
|
|
628
636
|
key={field} />
|
|
629
637
|
);
|
|
630
638
|
}
|
|
639
|
+
else if (Object.itsa_isObject(value)) {
|
|
640
|
+
return (
|
|
641
|
+
<td
|
|
642
|
+
className={classname}
|
|
643
|
+
data-colid={j}
|
|
644
|
+
key={field}
|
|
645
|
+
ref={node => instance['_component_'+i+'_'+j] = node}>
|
|
646
|
+
{value}
|
|
647
|
+
</td>
|
|
648
|
+
);
|
|
649
|
+
}
|
|
631
650
|
else if (fullEditable || ((editable===true) && (state.editableRow===i) && (state.editableCol===j)) && colIsEditable(j)) {
|
|
632
651
|
classname += EDITABLE_CELL_CLASS_SPACED;
|
|
633
652
|
(typeof value==='number') || value || (value='');
|
|
@@ -690,7 +709,8 @@ class Table extends React.Component {
|
|
|
690
709
|
<td
|
|
691
710
|
className={classname}
|
|
692
711
|
data-colid={j}
|
|
693
|
-
key={field}
|
|
712
|
+
key={field}
|
|
713
|
+
ref={node => instance['_component_'+i+'_'+j] = node}>
|
|
694
714
|
{value}
|
|
695
715
|
</td>
|
|
696
716
|
);
|
|
@@ -716,6 +736,17 @@ class Table extends React.Component {
|
|
|
716
736
|
cellContent = value;
|
|
717
737
|
cells.push((<td className={classname} dangerouslySetInnerHTML={{__html: cellContent}} data-colid={colCount} key={key} />));
|
|
718
738
|
}
|
|
739
|
+
else if (Object.itsa_isObject(value)) {
|
|
740
|
+
return (
|
|
741
|
+
<td
|
|
742
|
+
className={classname}
|
|
743
|
+
data-colid={j}
|
|
744
|
+
key={field}
|
|
745
|
+
ref={node => instance['_component_'+i+'_'+j] = node}>
|
|
746
|
+
{value}
|
|
747
|
+
</td>
|
|
748
|
+
);
|
|
749
|
+
}
|
|
719
750
|
else if (fullEditable || ((editable===true) && (state.editableRow===i) && (state.editableCol===colCount))) {
|
|
720
751
|
classname += EDITABLE_CELL_CLASS_SPACED;
|
|
721
752
|
(typeof value==='number') || value || (value='');
|
|
@@ -766,7 +797,7 @@ class Table extends React.Component {
|
|
|
766
797
|
cells.push((<td className={classname} dangerouslySetInnerHTML={{__html: cellContent}} data-colid={colCount} key={key} />));
|
|
767
798
|
}
|
|
768
799
|
else {
|
|
769
|
-
cells.push((<td className={classname} data-colid={colCount} key={key}>{value}</td>));
|
|
800
|
+
cells.push((<td className={classname} data-colid={colCount} key={key} ref={node => instance['_component_'+i+'_'+j] = node}>{value}</td>));
|
|
770
801
|
}
|
|
771
802
|
}
|
|
772
803
|
});
|
|
@@ -795,8 +826,8 @@ class Table extends React.Component {
|
|
|
795
826
|
}
|
|
796
827
|
|
|
797
828
|
refocus(e) {
|
|
798
|
-
let focusRow, focusCol, match, maxRow, maxCol, firstItem, item, editValue, colChangedByRow,
|
|
799
|
-
prevRowIndex, prevColIndex, field, editDirectionDown, arrowDown, arrowUp;
|
|
829
|
+
let focusRow, focusCol, match, maxRow, maxCol, firstItem, item, editValue, colChangedByRow, isSelectComponent, less,
|
|
830
|
+
prevRowIndex, prevColIndex, field, editDirectionDown, arrowDown, arrowUp, node, trNode, trParentNode, tds, trs;
|
|
800
831
|
const instance = this,
|
|
801
832
|
props = instance.props,
|
|
802
833
|
state = instance.state,
|
|
@@ -825,12 +856,24 @@ class Table extends React.Component {
|
|
|
825
856
|
return;
|
|
826
857
|
}
|
|
827
858
|
}
|
|
859
|
+
|
|
828
860
|
match = (
|
|
829
861
|
(keyCode===9) ||
|
|
830
862
|
(keyCode===13) ||
|
|
831
863
|
(cursorNav && ((keyCode===40) || (keyCode===38))) ||
|
|
832
864
|
(cursorNav && ctrlKey && ((keyCode===37) || (keyCode===39)))
|
|
833
865
|
); // 40=arrowDown, 38=arrowUp
|
|
866
|
+
|
|
867
|
+
// we need to ignore MOVING DOWN in case the focus lies on a button component
|
|
868
|
+
if ((document.activeElement.tagName==='BUTTON') && (keyCode===13)) {
|
|
869
|
+
match = false;
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
isSelectComponent = (document.activeElement.itsa_hasClass('itsa-select') || document.activeElement.itsa_inside('.itsa-select'));
|
|
873
|
+
if (isSelectComponent && ((keyCode===13) || (cursorNav && ((keyCode===38) || (keyCode===40))))) {
|
|
874
|
+
match = false;
|
|
875
|
+
}
|
|
876
|
+
|
|
834
877
|
if (match) {
|
|
835
878
|
e.preventDefault();
|
|
836
879
|
arrowDown = (keyCode===40);
|
|
@@ -843,8 +886,34 @@ class Table extends React.Component {
|
|
|
843
886
|
firstItem = data[0];
|
|
844
887
|
maxCol = firstItem ? firstItem.itsa_size()-1 : 0;
|
|
845
888
|
}
|
|
846
|
-
|
|
847
|
-
|
|
889
|
+
|
|
890
|
+
if (isSelectComponent) {
|
|
891
|
+
// we need to catch editableRow and editableCol because thay are not set
|
|
892
|
+
less = 0;
|
|
893
|
+
if (props.removeableY) {
|
|
894
|
+
less++;
|
|
895
|
+
}
|
|
896
|
+
if (props.extendableY==='full') {
|
|
897
|
+
less++;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
node = document.activeElement;
|
|
901
|
+
while (node && (node.tagName!=='TD')) {
|
|
902
|
+
node = node.parentNode;
|
|
903
|
+
}
|
|
904
|
+
trNode = node.parentNode;
|
|
905
|
+
tds = trNode.childNodes;
|
|
906
|
+
prevColIndex = Array.prototype.indexOf.call(tds, node) - less;
|
|
907
|
+
trParentNode = trNode.parentNode;
|
|
908
|
+
trs = trParentNode.childNodes;
|
|
909
|
+
prevRowIndex = Array.prototype.indexOf.call(trs, trNode);
|
|
910
|
+
}
|
|
911
|
+
else {
|
|
912
|
+
prevRowIndex = state.editableRow;
|
|
913
|
+
prevColIndex = state.editableCol;
|
|
914
|
+
}
|
|
915
|
+
focusRow = prevRowIndex;
|
|
916
|
+
focusCol = prevColIndex;
|
|
848
917
|
|
|
849
918
|
if (((keyCode===9) && shiftKey) || ((keyCode===37) && ctrlKey) || arrowUp) {
|
|
850
919
|
// backwards
|
|
@@ -926,19 +995,21 @@ class Table extends React.Component {
|
|
|
926
995
|
(focusRow>maxRow) && (focusRow=0);
|
|
927
996
|
}
|
|
928
997
|
item = props.data[focusRow];
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
998
|
+
if (item) {
|
|
999
|
+
editValue = hasColumns ? item[retrieveFieldName(columns[focusCol])] : item[retrieveFieldName(instance._columns[focusCol])];
|
|
1000
|
+
this.setState({
|
|
1001
|
+
editableRow: focusRow,
|
|
1002
|
+
editableCol: focusCol,
|
|
1003
|
+
editValue,
|
|
1004
|
+
selectedRangeStart: {
|
|
1005
|
+
x: focusCol,
|
|
1006
|
+
y: focusRow
|
|
1007
|
+
},
|
|
1008
|
+
selectedRange: null
|
|
1009
|
+
});
|
|
1010
|
+
instance._focusActiveCell();
|
|
1011
|
+
implementChanges();
|
|
1012
|
+
}
|
|
942
1013
|
}
|
|
943
1014
|
}
|
|
944
1015
|
|