@vitrosoftware/common-ui-ts 1.1.242 → 1.1.243

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/dist/index.js CHANGED
@@ -21442,6 +21442,7 @@ var TableViewServiceImpl = /*#__PURE__*/function () {
21442
21442
  this.visibleColumnList = [];
21443
21443
  this.disabledActionList = [];
21444
21444
  this.disabledColumnList = [];
21445
+ this.isExpanding = false;
21445
21446
  this.grid = grid;
21446
21447
  this.id = grid.id;
21447
21448
  this.grid.Source.Upload.Format = this.gridChangesFormat;
@@ -61681,32 +61682,72 @@ var styles$v = {"vitro-tab-button-group":"_tab-button-group_vitro-tab-button-gro
61681
61682
  var CSS_CLASS_ACTIVE = 'active';
61682
61683
  var CSS_CLASS_TAB_BUTTON_GROUP = 'vitro-tab-button-group';
61683
61684
  var CSS_CLASS_TAB_BUTTON_GROUP_CONTENT = 'vitro-tab-button-group-content';
61685
+ var ELEMENT_CANVAS$1 = 'canvas';
61686
+ var CANVAS_CONTEXT$1 = '2d';
61684
61687
  var TabButtonGroup = function TabButtonGroup(props) {
61685
61688
  var _useState = React.useState([]),
61686
61689
  tabList = _useState[0],
61687
61690
  setTabList = _useState[1];
61688
- var _useState2 = React.useState(),
61689
- activeItem = _useState2[0],
61690
- setActiveItem = _useState2[1];
61691
- var _useState3 = React.useState(),
61692
- activeItemTabBtn = _useState3[0],
61693
- setActiveItemTabBtn = _useState3[1];
61694
- var _useState4 = React.useState(0),
61695
- width = _useState4[0],
61696
- setWidth = _useState4[1];
61691
+ var _useState2 = React.useState(props.itemList.length),
61692
+ overflowIndex = _useState2[0],
61693
+ setOverflowIndex = _useState2[1];
61694
+ var _useState3 = React.useState(props.activeItem || CTRL.EMPTY),
61695
+ activeItem = _useState3[0],
61696
+ setActiveItem = _useState3[1];
61697
+ var _useState4 = React.useState(),
61698
+ activeItemTabBtn = _useState4[0],
61699
+ setActiveItemTabBtn = _useState4[1];
61700
+ var _useState5 = React.useState(0),
61701
+ width = _useState5[0],
61702
+ setWidth = _useState5[1];
61703
+ var resizeTimeout = React.useMemo(function () {
61704
+ return {
61705
+ id: null
61706
+ };
61707
+ }, []);
61697
61708
  var ref = React.useRef(null);
61698
61709
  var overflowTabList = [];
61699
- var tabMinWidth = 120;
61700
61710
  var resizeObserver = new window.ResizeObserver(function (entries) {
61701
61711
  for (var _iterator = _createForOfIteratorHelperLoose(entries), _step; !(_step = _iterator()).done;) {
61702
61712
  var entry = _step.value;
61703
61713
  if (ref.current && entry.target === ref.current) {
61704
- if (!width || props.wrap) {
61705
- setWidth(ref.current.offsetWidth);
61714
+ if (props.wrap) {
61715
+ if (resizeTimeout.id) {
61716
+ clearTimeout(resizeTimeout.id);
61717
+ }
61718
+ resizeTimeout.id = setTimeout(function () {
61719
+ var _ref$current;
61720
+ resizeTimeout.id = null;
61721
+ setWidth(((_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.offsetWidth) || 0);
61722
+ }, 200);
61706
61723
  }
61707
61724
  }
61708
61725
  }
61709
61726
  });
61727
+ React.useEffect(function () {
61728
+ if (width) {
61729
+ setOverflowIndex(getOverflowIndex(width));
61730
+ } else {
61731
+ setOverflowIndex(tabList.length);
61732
+ }
61733
+ }, [width]);
61734
+ var getOverflowIndex = function getOverflowIndex(width) {
61735
+ var scrollWidth = (activeItemTabBtn === null || activeItemTabBtn === void 0 ? void 0 : activeItemTabBtn.width) || 0;
61736
+ for (var _iterator2 = _createForOfIteratorHelperLoose(tabList.entries()), _step2; !(_step2 = _iterator2()).done;) {
61737
+ var _step2$value = _step2.value,
61738
+ index = _step2$value[0],
61739
+ item = _step2$value[1];
61740
+ if (item.id === (activeItemTabBtn === null || activeItemTabBtn === void 0 ? void 0 : activeItemTabBtn.id)) {
61741
+ continue;
61742
+ }
61743
+ if (scrollWidth + item.width < width) {
61744
+ scrollWidth += item.width;
61745
+ } else {
61746
+ return index;
61747
+ }
61748
+ }
61749
+ return tabList.length;
61750
+ };
61710
61751
  React.useEffect(function () {
61711
61752
  if (ref.current) {
61712
61753
  resizeObserver.observe(ref.current);
@@ -61719,62 +61760,35 @@ var TabButtonGroup = function TabButtonGroup(props) {
61719
61760
  }, []);
61720
61761
  React.useEffect(function () {
61721
61762
  if (props.itemList) {
61722
- var list = props.itemList.map(function (item, index) {
61723
- return _extends({}, item, {
61724
- index: index
61725
- });
61726
- });
61727
- var isActiveItemChanged = props.activeItem != activeItem;
61728
- setTabList(list);
61729
- setActiveItem(props.activeItem);
61730
- if (props.activeItem) {
61731
- var itemTabBtn = tabList.find(function (item) {
61732
- return item.id === props.activeItem;
61733
- });
61734
- if (itemTabBtn) {
61735
- if (isActiveItemChanged) {
61736
- var overflowItem = overflowTabList.find(function (item) {
61737
- return item.index === itemTabBtn.index;
61738
- });
61739
- if (overflowItem) {
61740
- setActiveItemTabBtn(overflowItem);
61741
- } else {
61742
- setActiveItemTabBtn(null);
61743
- }
61744
- }
61745
- } else {
61746
- setActiveItemTabBtn(null);
61747
- }
61748
- } else {
61749
- setActiveItemTabBtn(null);
61750
- }
61763
+ setTabList(getItemList(props.itemList));
61751
61764
  }
61752
61765
  }, [props.itemList]);
61753
61766
  React.useEffect(function () {
61754
- var isActiveItemChanged = props.activeItem != activeItem;
61755
- setActiveItem(props.activeItem);
61756
61767
  if (props.activeItem) {
61757
- var itemTabBtn = tabList.find(function (item) {
61758
- return item.id === props.activeItem;
61759
- });
61760
- if (itemTabBtn) {
61761
- if (isActiveItemChanged) {
61762
- var overflowItem = overflowTabList.find(function (item) {
61763
- return item.index === itemTabBtn.index;
61764
- });
61765
- if (overflowItem) {
61766
- setActiveItemTabBtn(overflowItem);
61767
- } else {
61768
- setActiveItemTabBtn(null);
61769
- }
61770
- }
61771
- } else {
61772
- setActiveItemTabBtn(null);
61773
- }
61774
- } else {
61775
- setActiveItemTabBtn(null);
61768
+ setActiveItem(props.activeItem);
61776
61769
  }
61777
61770
  }, [props.activeItem]);
61771
+ var getItemList = function getItemList(itemList) {
61772
+ if (ref.current) {
61773
+ var canvas = document.createElement(ELEMENT_CANVAS$1);
61774
+ var font = window.getComputedStyle(ref.current).font;
61775
+ var newItemList = itemList.map(function (item, index) {
61776
+ return _extends({}, item, {
61777
+ width: getTextWidth(item.text, canvas, font),
61778
+ index: index
61779
+ });
61780
+ });
61781
+ return newItemList;
61782
+ }
61783
+ return itemList;
61784
+ };
61785
+ var getTextWidth = function getTextWidth(text, canvas, font) {
61786
+ var context = canvas.getContext(CANVAS_CONTEXT$1);
61787
+ context.font = font;
61788
+ var _context$measureText = context.measureText(text),
61789
+ width = _context$measureText.width;
61790
+ return width + 24;
61791
+ };
61778
61792
  var setButtonActive = function setButtonActive(index) {
61779
61793
  var overflowItem = overflowTabList.find(function (item) {
61780
61794
  return item.index === index;
@@ -61804,21 +61818,13 @@ var TabButtonGroup = function TabButtonGroup(props) {
61804
61818
  }
61805
61819
  });
61806
61820
  };
61807
- var getWidth = function getWidth() {
61808
- var count = tabList.length - overflowTabList.length;
61809
- var _width = width - count * 16;
61810
- return _width >= tabMinWidth ? _width : tabMinWidth;
61811
- };
61812
61821
  return React__default.createElement("div", {
61813
61822
  className: styles$v[CSS_CLASS_TAB_BUTTON_GROUP]
61814
61823
  }, React__default.createElement("div", {
61815
61824
  className: styles$v[CSS_CLASS_TAB_BUTTON_GROUP_CONTENT],
61816
61825
  ref: ref
61817
61826
  }, tabList.map(function (item, index) {
61818
- if ((activeItemTabBtn ? index + 2 : index + 1) * tabMinWidth < getWidth() || !props.wrap) {
61819
- if (activeItemTabBtn && activeItemTabBtn.index === index) {
61820
- setActiveItemTabBtn(null);
61821
- }
61827
+ if (index < overflowIndex || !props.wrap || activeItemTabBtn && activeItemTabBtn.index === index) {
61822
61828
  return getTabButton(item, index);
61823
61829
  }
61824
61830
  if (activeItemTabBtn && activeItemTabBtn.index === index) {
@@ -61826,15 +61832,9 @@ var TabButtonGroup = function TabButtonGroup(props) {
61826
61832
  }
61827
61833
  overflowTabList.push(item);
61828
61834
  return null;
61829
- }), activeItemTabBtn && React__default.createElement(Button$1, {
61830
- key: activeItemTabBtn.id,
61831
- className: styles$v[CSS_CLASS_ACTIVE],
61832
- text: activeItemTabBtn.text,
61833
- onClick: function onClick() {}
61834
61835
  }), tabList && props.wrap && React__default.createElement(OverflowButton, {
61835
61836
  list: overflowTabList,
61836
61837
  offset: tabList.length - overflowTabList.length,
61837
- width: width,
61838
61838
  onSelect: setButtonActive
61839
61839
  })));
61840
61840
  };
@@ -66969,7 +66969,7 @@ var Viewer = function Viewer(props) {
66969
66969
  };
66970
66970
 
66971
66971
  var name = "@vitrosoftware/common-ui-ts";
66972
- var version$1 = "1.1.242";
66972
+ var version$1 = "1.1.243";
66973
66973
  var description = "vitro software common ui ts";
66974
66974
  var author = "";
66975
66975
  var license = "MIT";