@ccs-ui/rc-pro 1.0.7-rc.12 → 1.0.7-rc.13

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.
@@ -1,20 +1,33 @@
1
+ import { TabPaneProps } from 'antd';
1
2
  import { Store } from 'antd/es/form/interface';
2
3
  import { Location } from 'history';
3
- import { Tab } from 'rc-tabs/lib/interface';
4
4
  import React from 'react';
5
- import { CcsUserDetailType } from '..';
6
- interface TabProps {
5
+ import { CcsUserDetailType, RecordType } from '..';
6
+ type CcsTabsChangeProps = {
7
+ /** 当前激活tab面板的key */
8
+ activeKey?: string;
9
+ /** 启用tab keys */
10
+ enableKeys?: string[];
11
+ /** 禁用tab keys */
12
+ disableKeys?: string[];
13
+ /** tab间传递的参数 */
14
+ options?: RecordType;
15
+ };
16
+ export type CcsTabProps = Omit<TabPaneProps, 'tab'> & {
17
+ key: string;
18
+ label: React.ReactNode;
19
+ };
20
+ interface CcsTabsContextType {
7
21
  /** 当前激活tab面板的key */
8
22
  activeKey: string;
9
- /** Tabs items */
10
- items: Tab[];
11
23
  /** tab间传递的参数 */
12
- option: any;
13
- }
14
- interface TabsContextType extends TabProps {
15
- option: any;
24
+ options: RecordType;
25
+ /** 添加tab */
26
+ onAddTabs: (tab: CcsTabProps | CcsTabProps[]) => void;
27
+ /** 移除tab */
28
+ onRemoveTabs: (key: string | string[]) => void;
16
29
  /** 改变tab间传递的参数 */
17
- onChange: (tab: Partial<TabProps>) => void;
30
+ onTabChange: (tab: CcsTabsChangeProps) => void;
18
31
  }
19
32
  type PageContextType = {
20
33
  /** ID */
@@ -41,6 +54,6 @@ interface FnContextType<T = Store> {
41
54
  declare const GlobalContext: React.Context<GlobalContextType>;
42
55
  declare const DrawerAndModalContext: React.Context<FnContextType<any>>;
43
56
  declare const PageContext: React.Context<PageContextType>;
44
- declare const TabsContext: React.Context<TabsContextType>;
45
- export type { TabProps, FnContextType, TabsContextType, GlobalContextPropsType, };
57
+ declare const TabsContext: React.Context<CcsTabsContextType>;
58
+ export type { FnContextType, CcsTabsContextType, CcsTabsChangeProps, GlobalContextPropsType, };
46
59
  export { TabsContext, PageContext, GlobalContext, DrawerAndModalContext };
@@ -2,10 +2,5 @@ import React, { createContext } from 'react';
2
2
  var GlobalContext = /*#__PURE__*/createContext({});
3
3
  var DrawerAndModalContext = /*#__PURE__*/createContext({});
4
4
  var PageContext = /*#__PURE__*/createContext({});
5
- var TabsContext = /*#__PURE__*/React.createContext({
6
- items: [],
7
- activeKey: '',
8
- option: {},
9
- onChange: function onChange() {}
10
- });
5
+ var TabsContext = /*#__PURE__*/React.createContext({});
11
6
  export { TabsContext, PageContext, GlobalContext, DrawerAndModalContext };
@@ -1,2 +1,2 @@
1
- declare const useTabs: () => import("../context").TabsContextType;
1
+ declare const useTabs: () => import("../context").CcsTabsContextType;
2
2
  export default useTabs;
@@ -1,13 +1,3 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
7
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
8
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
10
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
11
1
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
12
2
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
13
3
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -15,6 +5,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
15
5
  function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
16
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
17
7
  import { useUpdateEffect } from 'ahooks';
8
+ import update from 'immutability-helper';
18
9
  import React, { cloneElement, useState } from 'react';
19
10
  import { TabsContext } from "../context";
20
11
  import "./index.less";
@@ -26,10 +17,12 @@ export default (function (_ref) {
26
17
  items = _ref2$items === void 0 ? [] : _ref2$items,
27
18
  activeKey = _ref2.activeKey,
28
19
  defaultActiveKey = _ref2.defaultActiveKey;
29
- var _useState = useState({
30
- activeKey: defaultActiveKey || (items[0] || {}).key,
31
- items: items || [],
32
- option: {}
20
+ var _useState = useState(function () {
21
+ return {
22
+ activeKey: defaultActiveKey || (items[0] || {}).key,
23
+ items: items || [],
24
+ options: {}
25
+ };
33
26
  }),
34
27
  _useState2 = _slicedToArray(_useState, 2),
35
28
  tabsProps = _useState2[0],
@@ -37,8 +30,10 @@ export default (function (_ref) {
37
30
 
38
31
  // items 发生改变
39
32
  useUpdateEffect(function () {
40
- setTabsProps(_objectSpread(_objectSpread({}, tabsProps), {}, {
41
- items: items
33
+ setTabsProps(update(tabsProps, {
34
+ items: {
35
+ $set: items
36
+ }
42
37
  }));
43
38
  }, [children === null || children === void 0 ? void 0 : (_children$items = children.items) === null || _children$items === void 0 ? void 0 : _children$items.map(function (t) {
44
39
  return t.key;
@@ -52,26 +47,99 @@ export default (function (_ref) {
52
47
  if (!activeKey) {
53
48
  addOptions.activeKey = tabsProps.activeKey;
54
49
  addOptions.onChange = function (key) {
55
- setTabsProps(_objectSpread(_objectSpread({}, tabsProps), {}, {
56
- activeKey: key
50
+ setTabsProps(update(tabsProps, {
51
+ activeKey: {
52
+ $set: key
53
+ }
57
54
  }));
58
55
  };
59
56
  }
57
+
58
+ // hooks改变状态
59
+ var onHooksChange = function onHooksChange(e) {
60
+ var key = e.activeKey,
61
+ _e$enableKeys = e.enableKeys,
62
+ enableKeys = _e$enableKeys === void 0 ? [] : _e$enableKeys,
63
+ _e$disableKeys = e.disableKeys,
64
+ disableKeys = _e$disableKeys === void 0 ? [] : _e$disableKeys,
65
+ options = e.options;
66
+ var updateParams = {};
67
+
68
+ // 更新activeKey
69
+ if (!!key) {
70
+ updateParams.activeKey = {
71
+ $set: key
72
+ };
73
+ }
74
+
75
+ // 更新禁用或启用tab
76
+ if (enableKeys.length || disableKeys.length) {
77
+ var _tabsProps$items;
78
+ var newItem = {};
79
+ (_tabsProps$items = tabsProps.items) === null || _tabsProps$items === void 0 ? void 0 : _tabsProps$items.forEach(function (item, index) {
80
+ if (enableKeys.includes(item.key)) {
81
+ newItem[index] = {
82
+ disabled: {
83
+ $set: false
84
+ }
85
+ };
86
+ } else if (disableKeys.includes(item.key)) {
87
+ newItem[index] = {
88
+ disabled: {
89
+ $set: true
90
+ }
91
+ };
92
+ }
93
+ });
94
+ updateParams.items = newItem;
95
+ }
96
+
97
+ // 更新options
98
+ if (options) {
99
+ updateParams.options = {
100
+ $set: options
101
+ };
102
+ }
103
+ setTabsProps(update(tabsProps, updateParams));
104
+ };
105
+
106
+ // remove tabs
107
+ var onRemoveTabs = function onRemoveTabs(key) {
108
+ var _tabsProps$items2;
109
+ var curKey = key;
110
+ if (typeof key === 'string') {
111
+ curKey = [key];
112
+ }
113
+ var removeItems = [];
114
+ (_tabsProps$items2 = tabsProps.items) === null || _tabsProps$items2 === void 0 ? void 0 : _tabsProps$items2.forEach(function (item, index) {
115
+ if (curKey.includes(item.key)) {
116
+ removeItems.push([index, 1]);
117
+ }
118
+ });
119
+ setTabsProps(update(tabsProps, {
120
+ items: {
121
+ $splice: removeItems
122
+ }
123
+ }));
124
+ };
125
+
126
+ // add tabs
127
+ var onAddTabs = function onAddTabs() {
128
+ var tabs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
129
+ var isArray = Array.isArray(tabs);
130
+ setTabsProps(update(tabsProps, {
131
+ items: {
132
+ $push: isArray ? tabs : [tabs]
133
+ }
134
+ }));
135
+ };
60
136
  return children ? /*#__PURE__*/React.createElement(TabsContext.Provider, {
61
137
  value: {
62
138
  activeKey: tabsProps.activeKey,
63
- items: tabsProps.items,
64
- option: tabsProps.option,
65
- onChange: function onChange(e) {
66
- return setTabsProps(function (state) {
67
- if (e.items) {
68
- return _objectSpread(_objectSpread(_objectSpread({}, state), e), {}, {
69
- items: _toConsumableArray(e.items || [])
70
- });
71
- }
72
- return _objectSpread(_objectSpread({}, state), e);
73
- });
74
- }
139
+ options: tabsProps.options,
140
+ onTabChange: onHooksChange,
141
+ onRemoveTabs: onRemoveTabs,
142
+ onAddTabs: onAddTabs
75
143
  }
76
144
  }, /*#__PURE__*/cloneElement(children, addOptions)) : /*#__PURE__*/React.createElement(React.Fragment, null);
77
145
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ccs-ui/rc-pro",
3
- "version": "1.0.7-rc.12",
3
+ "version": "1.0.7-rc.13",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "es/index.js",
@@ -53,6 +53,7 @@
53
53
  "antd-img-crop": "^4.12.2",
54
54
  "classnames": "^2.3.2",
55
55
  "dayjs": "^1.11.7",
56
+ "immutability-helper": "^3.1.1",
56
57
  "js-base64": "^3.7.5",
57
58
  "localforage": "^1.10.0",
58
59
  "lodash": "^4.17.21",