@plasmicpkgs/antd 0.0.79 → 0.0.82

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.
@@ -1709,25 +1709,19 @@ function Tabs(props) {
1709
1709
  }));
1710
1710
  }
1711
1711
 
1712
- function AddTab(_ref) {
1713
- var studioOps = _ref.studioOps;
1714
-
1715
- var _React$useState = React.useState(""),
1716
- tabKey = _React$useState[0],
1717
- setTabKey = _React$useState[1];
1718
-
1719
- var appendNewTab = function appendNewTab(tabKey) {
1720
- if (tabKey !== "") {
1721
- studioOps.appendToSlot({
1722
- type: "component",
1723
- name: "AntdTabPane",
1724
- props: {
1725
- key: tabKey
1726
- }
1727
- }, "children");
1712
+ function NavigateTabs(_ref) {
1713
+ var componentProps = _ref.componentProps,
1714
+ studioOps = _ref.studioOps;
1715
+ var tabPanes = [];
1716
+ traverseReactEltTree(componentProps.children, function (elt) {
1717
+ if ((elt == null ? void 0 : elt.type) === rcTabs.TabPane && typeof (elt == null ? void 0 : elt.key) === "string") {
1718
+ tabPanes.push(elt.key);
1728
1719
  }
1729
- };
1730
-
1720
+ });
1721
+ var activeKey = componentProps.activeKey;
1722
+ var currTabPos = activeKey ? tabPanes.findIndex(function (tabKey) {
1723
+ return tabKey === activeKey;
1724
+ }) : 0;
1731
1725
  return React.createElement("div", {
1732
1726
  style: {
1733
1727
  width: "100%",
@@ -1736,18 +1730,35 @@ function AddTab(_ref) {
1736
1730
  gap: "10px",
1737
1731
  justifyContent: "space-between"
1738
1732
  }
1739
- }, React.createElement(antd.Input, {
1740
- placeholder: "Tab key",
1741
- onChange: function onChange(e) {
1742
- return setTabKey(e.target.value);
1733
+ }, React.createElement(antd.Button, {
1734
+ style: {
1735
+ width: "100%"
1743
1736
  },
1744
- value: tabKey
1745
- }), React.createElement(antd.Button, {
1746
1737
  onClick: function onClick() {
1747
- appendNewTab(tabKey);
1748
- setTabKey("");
1738
+ if (tabPanes.length > 0) {
1739
+ var prevTabPos = (currTabPos - 1 + tabPanes.length) % tabPanes.length;
1740
+ studioOps.updateProps({
1741
+ activeKey: tabPanes[prevTabPos]
1742
+ });
1743
+ }
1744
+ }
1745
+ }, "Prev tab"), React.createElement(antd.Button, {
1746
+ style: {
1747
+ width: "100%"
1748
+ },
1749
+ onClick: function onClick() {
1750
+ if (tabPanes.length > 0) {
1751
+ var nextTabPos = (currTabPos + 1) % tabPanes.length;
1752
+ studioOps.updateProps({
1753
+ activeKey: tabPanes[nextTabPos]
1754
+ });
1755
+ }
1749
1756
  }
1750
- }, "Add tab"));
1757
+ }, "Next tab"));
1758
+ }
1759
+
1760
+ function OutlineMessage() {
1761
+ return React.createElement("div", null, "* To re-arrange tab panes, use the Outline panel");
1751
1762
  }
1752
1763
 
1753
1764
  var tabsMeta = {
@@ -1855,14 +1866,53 @@ var tabsMeta = {
1855
1866
  },
1856
1867
  actions: [{
1857
1868
  type: "custom-action",
1858
- control: AddTab
1869
+ control: NavigateTabs
1859
1870
  }, {
1860
1871
  type: "button-action",
1861
- label: "Delete current tab",
1872
+ label: "Add new tab",
1862
1873
  onClick: function onClick(_ref2) {
1863
1874
  var componentProps = _ref2.componentProps,
1864
1875
  studioOps = _ref2.studioOps;
1865
1876
 
1877
+ // Get the first positive integer that isn't already a key
1878
+ var generateNewKey = function generateNewKey() {
1879
+ var keysSet = new Set();
1880
+ traverseReactEltTree(componentProps.children, function (elt) {
1881
+ if ((elt == null ? void 0 : elt.type) === rcTabs.TabPane && typeof (elt == null ? void 0 : elt.key) === "string") {
1882
+ keysSet.add(elt.key);
1883
+ }
1884
+ });
1885
+
1886
+ for (var keyCandidate = 1; keyCandidate <= keysSet.size + 1; keyCandidate++) {
1887
+ var strKey = keyCandidate.toString();
1888
+
1889
+ if (!keysSet.has(strKey)) {
1890
+ return strKey;
1891
+ }
1892
+ }
1893
+
1894
+ return undefined;
1895
+ };
1896
+
1897
+ var tabKey = generateNewKey();
1898
+ studioOps.appendToSlot({
1899
+ type: "component",
1900
+ name: "AntdTabPane",
1901
+ props: {
1902
+ key: tabKey
1903
+ }
1904
+ }, "children");
1905
+ studioOps.updateProps({
1906
+ activeKey: tabKey
1907
+ });
1908
+ }
1909
+ }, {
1910
+ type: "button-action",
1911
+ label: "Delete current tab",
1912
+ onClick: function onClick(_ref3) {
1913
+ var componentProps = _ref3.componentProps,
1914
+ studioOps = _ref3.studioOps;
1915
+
1866
1916
  if (componentProps.activeKey) {
1867
1917
  var tabPanes = [];
1868
1918
  traverseReactEltTree(componentProps.children, function (elt) {
@@ -1870,15 +1920,26 @@ var tabsMeta = {
1870
1920
  tabPanes.push(elt.key);
1871
1921
  }
1872
1922
  });
1873
- var currentTabPos = tabPanes.findIndex(function (tabKey) {
1874
- return tabKey === componentProps.activeKey;
1923
+ var activeKey = componentProps.activeKey;
1924
+ var currTabPos = tabPanes.findIndex(function (tabKey) {
1925
+ return tabKey === activeKey;
1875
1926
  });
1876
1927
 
1877
- if (currentTabPos !== -1) {
1878
- studioOps.removeFromSlotAt(currentTabPos, "children");
1928
+ if (currTabPos !== -1) {
1929
+ studioOps.removeFromSlotAt(currTabPos, "children");
1930
+
1931
+ if (tabPanes.length - 1 > 0) {
1932
+ var prevTabPos = (currTabPos - 1 + tabPanes.length) % tabPanes.length;
1933
+ studioOps.updateProps({
1934
+ activeKey: tabPanes[prevTabPos]
1935
+ });
1936
+ }
1879
1937
  }
1880
1938
  }
1881
1939
  }
1940
+ }, {
1941
+ type: "custom-action",
1942
+ control: OutlineMessage
1882
1943
  }],
1883
1944
  importPath: "@plasmicpkgs/antd/skinny/registerTabs",
1884
1945
  importName: "Tabs"