@pisell/private-materials 6.11.55 → 6.11.56

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.
@@ -11,6 +11,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
11
11
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
12
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
13
  import { useReducer, useCallback, useEffect, useRef } from 'react';
14
+ import { useMemoizedFn } from 'ahooks';
14
15
 
15
16
  // 状态接口
16
17
 
@@ -65,28 +66,30 @@ export var useListState = function useListState(_ref) {
65
66
  // 用 ref 追踪最新的 activeTab,避免将 state.activeTab 加入 useEffect 依赖导致循环触发
66
67
  var activeTabRef = useRef(initialState.activeTab);
67
68
  activeTabRef.current = state.activeTab;
68
- useEffect(function () {
69
- debugger;
70
- if (!isTreeTab) {
71
- setActiveTab(['0']);
72
- return;
69
+
70
+ /** 判断当前 activeTab 的首层 key 是否仍存在于 tabItems 中 */
71
+ var isActiveTabValid = useMemoizedFn(function (items) {
72
+ var current = activeTabRef.current;
73
+ var key = Array.isArray(current) ? current[0] : current;
74
+ return !!key && items.some(function (tab) {
75
+ return tab.key == key;
76
+ });
77
+ });
78
+
79
+ /** 根据 tabItems 计算默认的 activeTab */
80
+ var getDefaultTab = useMemoizedFn(function (items, tree) {
81
+ var _items$;
82
+ if (!tree) return ['0'];
83
+ var defaultTab = [items[0].key];
84
+ if (((_items$ = items[0]) === null || _items$ === void 0 || (_items$ = _items$.children) === null || _items$ === void 0 ? void 0 : _items$.length) > 0) {
85
+ defaultTab.push('0');
73
86
  }
74
- if (tabStyle === 'switch' && tabItems.length > 0) {
75
- var _tabItems$;
76
- // 取当前 activeTab 的首层 key 判断是否仍存在于新的 tabItems 中
77
- var currentActive = activeTabRef.current;
78
- var currentActiveKey = Array.isArray(currentActive) ? currentActive[0] : currentActive;
79
- var isCurrentTabStillValid = currentActiveKey && tabItems.some(function (tab) {
80
- return tab.key == currentActiveKey;
81
- });
82
- if (isCurrentTabStillValid) {
83
- return;
84
- }
85
- var defaultTab = [tabItems[0].key];
86
- if (((_tabItems$ = tabItems[0]) === null || _tabItems$ === void 0 || (_tabItems$ = _tabItems$.children) === null || _tabItems$ === void 0 ? void 0 : _tabItems$.length) > 0) {
87
- defaultTab.push('0');
88
- }
89
- setActiveTab(defaultTab);
87
+ return defaultTab;
88
+ });
89
+ useEffect(function () {
90
+ if (!isTreeTab || tabStyle === 'switch' && tabItems.length > 0) {
91
+ if (isActiveTabValid(tabItems)) return;
92
+ setActiveTab(getDefaultTab(tabItems, isTreeTab));
90
93
  }
91
94
  }, [tabItems, isTreeTab]);
92
95
 
@@ -23,6 +23,7 @@ __export(useListState_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(useListState_exports);
25
25
  var import_react = require("react");
26
+ var import_ahooks = require("ahooks");
26
27
  function listStateReducer(state, action) {
27
28
  switch (action.type) {
28
29
  case "SET_ACTIVE_TAB":
@@ -53,25 +54,24 @@ var useListState = ({
53
54
  const [state, dispatch] = (0, import_react.useReducer)(listStateReducer, initialState);
54
55
  const activeTabRef = (0, import_react.useRef)(initialState.activeTab);
55
56
  activeTabRef.current = state.activeTab;
56
- (0, import_react.useEffect)(() => {
57
+ const isActiveTabValid = (0, import_ahooks.useMemoizedFn)((items) => {
58
+ const current = activeTabRef.current;
59
+ const key = Array.isArray(current) ? current[0] : current;
60
+ return !!key && items.some((tab) => tab.key == key);
61
+ });
62
+ const getDefaultTab = (0, import_ahooks.useMemoizedFn)((items, tree) => {
57
63
  var _a, _b;
58
- debugger;
59
- if (!isTreeTab) {
60
- setActiveTab(["0"]);
61
- return;
64
+ if (!tree) return ["0"];
65
+ const defaultTab = [items[0].key];
66
+ if (((_b = (_a = items[0]) == null ? void 0 : _a.children) == null ? void 0 : _b.length) > 0) {
67
+ defaultTab.push("0");
62
68
  }
63
- if (tabStyle === "switch" && tabItems.length > 0) {
64
- const currentActive = activeTabRef.current;
65
- const currentActiveKey = Array.isArray(currentActive) ? currentActive[0] : currentActive;
66
- const isCurrentTabStillValid = currentActiveKey && tabItems.some((tab) => tab.key == currentActiveKey);
67
- if (isCurrentTabStillValid) {
68
- return;
69
- }
70
- const defaultTab = [tabItems[0].key];
71
- if (((_b = (_a = tabItems[0]) == null ? void 0 : _a.children) == null ? void 0 : _b.length) > 0) {
72
- defaultTab.push("0");
73
- }
74
- setActiveTab(defaultTab);
69
+ return defaultTab;
70
+ });
71
+ (0, import_react.useEffect)(() => {
72
+ if (!isTreeTab || tabStyle === "switch" && tabItems.length > 0) {
73
+ if (isActiveTabValid(tabItems)) return;
74
+ setActiveTab(getDefaultTab(tabItems, isTreeTab));
75
75
  }
76
76
  }, [tabItems, isTreeTab]);
77
77
  const actualCurrentPage = externalCurrentPage || state.currentPage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/private-materials",
3
- "version": "6.11.55",
3
+ "version": "6.11.56",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -1,5 +0,0 @@
1
- import React from 'react';
2
- import './List.less';
3
- import { ListProps, BaseListItem } from './types';
4
- declare const _default: React.ForwardRefExoticComponent<ListProps<BaseListItem> & React.RefAttributes<any>>;
5
- export default _default;
@@ -1,23 +0,0 @@
1
- import React from 'react';
2
- import { ProductDisplayConfig, ProductDisplayPresetKey } from './components/ProductDisplayAdapter/types';
3
- import './index.less';
4
- export declare const ticketBookingInitialState: any;
5
- interface TicketBookingProps {
6
- productExtensionType: string[];
7
- bookingConfigParams: Record<string, any>;
8
- isShowMenuBar?: boolean;
9
- onPrerenderComplete?: () => void;
10
- isShowTimeBar?: boolean;
11
- isShowFloatButtons?: boolean;
12
- productDisplayConfig?: ProductDisplayPresetKey | ProductDisplayConfig;
13
- isActive?: boolean;
14
- rulesHooks?: any;
15
- businessCode?: string;
16
- storeRef?: React.MutableRefObject<any>;
17
- /** 是否是弹窗编辑模式(由 TicketBookingDialog 传入) */
18
- isEditTicketMode?: boolean;
19
- /** 编辑模式下的初始 store 状态,会在 store 创建时合并进去 */
20
- editModeInitialState?: Record<string, any>;
21
- }
22
- declare const _default: (props: TicketBookingProps) => React.JSX.Element;
23
- export default _default;
@@ -1,5 +0,0 @@
1
- import React from 'react';
2
- import './List.less';
3
- import { ListProps, BaseListItem } from './types';
4
- declare const _default: React.ForwardRefExoticComponent<ListProps<BaseListItem> & React.RefAttributes<any>>;
5
- export default _default;
@@ -1,23 +0,0 @@
1
- import React from 'react';
2
- import { ProductDisplayConfig, ProductDisplayPresetKey } from './components/ProductDisplayAdapter/types';
3
- import './index.less';
4
- export declare const ticketBookingInitialState: any;
5
- interface TicketBookingProps {
6
- productExtensionType: string[];
7
- bookingConfigParams: Record<string, any>;
8
- isShowMenuBar?: boolean;
9
- onPrerenderComplete?: () => void;
10
- isShowTimeBar?: boolean;
11
- isShowFloatButtons?: boolean;
12
- productDisplayConfig?: ProductDisplayPresetKey | ProductDisplayConfig;
13
- isActive?: boolean;
14
- rulesHooks?: any;
15
- businessCode?: string;
16
- storeRef?: React.MutableRefObject<any>;
17
- /** 是否是弹窗编辑模式(由 TicketBookingDialog 传入) */
18
- isEditTicketMode?: boolean;
19
- /** 编辑模式下的初始 store 状态,会在 store 创建时合并进去 */
20
- editModeInitialState?: Record<string, any>;
21
- }
22
- declare const _default: (props: TicketBookingProps) => React.JSX.Element;
23
- export default _default;