@lingxiteam/ebe-utils 0.2.22 → 0.2.23

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.
Files changed (144) hide show
  1. package/lib/h5public/yarn.lock +7 -8
  2. package/lib/pcpublic/src/components/pcfactory/src/Button/index.tsx +11 -10
  3. package/lib/pcpublic/src/components/pcfactory/src/Card/CardTitle/index.tsx +31 -24
  4. package/lib/pcpublic/src/components/pcfactory/src/Card/index.tsx +32 -14
  5. package/lib/pcpublic/src/components/pcfactory/src/Card/useExtendBtn.tsx +85 -48
  6. package/lib/pcpublic/src/components/pcfactory/src/ChartLine/ChartLine.tsx +24 -6
  7. package/lib/pcpublic/src/components/pcfactory/src/ChartLine/PropsType.ts +31 -5
  8. package/lib/pcpublic/src/components/pcfactory/src/ChartLine/index.tsx +3 -2
  9. package/lib/pcpublic/src/components/pcfactory/src/ChartLine/loader.tsx +1 -1
  10. package/lib/pcpublic/src/components/pcfactory/src/Form/Form.tsx +153 -129
  11. package/lib/pcpublic/src/components/pcfactory/src/Form/index.tsx +2 -5
  12. package/lib/pcpublic/src/components/pcfactory/src/Form/useFormStatus.ts +8 -4
  13. package/lib/pcpublic/src/components/pcfactory/src/LXPieChart/LXPieChart.tsx +15 -3
  14. package/lib/pcpublic/src/components/pcfactory/src/LXPieChart/PropsType.ts +4 -3
  15. package/lib/pcpublic/src/components/pcfactory/src/LXPieChart/index.tsx +1 -1
  16. package/lib/pcpublic/src/components/pcfactory/src/LXPieChart/loader.tsx +1 -1
  17. package/lib/pcpublic/src/components/pcfactory/src/LXRadarChart/LXRadarChat.tsx +18 -4
  18. package/lib/pcpublic/src/components/pcfactory/src/LXRadarChart/PropsType.ts +2 -1
  19. package/lib/pcpublic/src/components/pcfactory/src/LXRadarChart/index.tsx +1 -1
  20. package/lib/pcpublic/src/components/pcfactory/src/LXRadarChart/loader.tsx +1 -1
  21. package/lib/pcpublic/src/components/pcfactory/src/ModalSelect/BaseModalSelect.tsx +7 -2
  22. package/lib/pcpublic/src/components/pcfactory/src/ModalSelect/index.tsx +60 -26
  23. package/lib/pcpublic/src/components/pcfactory/src/RichTextEditor/LcdpUeditorMain.tsx +62 -55
  24. package/lib/pcpublic/src/components/pcfactory/src/RichTextEditor/RichTextEditor.tsx +2 -6
  25. package/lib/pcpublic/src/components/pcfactory/src/RichTextEditor/RichTextEditorMain.tsx +5 -5
  26. package/lib/pcpublic/src/components/pcfactory/src/RichTextEditor/index.tsx +9 -2
  27. package/lib/pcpublic/src/components/pcfactory/src/RichTextEditor/loader.ts +1 -1
  28. package/lib/pcpublic/src/components/pcfactory/src/Select/index.tsx +145 -66
  29. package/lib/pcpublic/src/components/pcfactory/src/Select/selectUtils.ts +13 -9
  30. package/lib/pcpublic/src/components/pcfactory/src/Table/BodyCell/index.tsx +36 -26
  31. package/lib/pcpublic/src/components/pcfactory/src/Table/EditComponent/index.tsx +69 -94
  32. package/lib/pcpublic/src/components/pcfactory/src/Table/FormatCell/GhostTag/index.tsx +12 -5
  33. package/lib/pcpublic/src/components/pcfactory/src/Table/FormatCell/Hyperlink/index.tsx +9 -5
  34. package/lib/pcpublic/src/components/pcfactory/src/Table/FormatCell/PointTag/index.tsx +11 -5
  35. package/lib/pcpublic/src/components/pcfactory/src/Table/FormatCell/PureColourFill/index.tsx +11 -5
  36. package/lib/pcpublic/src/components/pcfactory/src/Table/FormatCell/PureFadeColourTag/index.tsx +14 -7
  37. package/lib/pcpublic/src/components/pcfactory/src/Table/FormatCell/Thumbnail/index.tsx +30 -31
  38. package/lib/pcpublic/src/components/pcfactory/src/Table/FormatCell/index.tsx +89 -41
  39. package/lib/pcpublic/src/components/pcfactory/src/Table/HeaderCell/HeaderCellTitle/index.tsx +25 -12
  40. package/lib/pcpublic/src/components/pcfactory/src/Table/HeaderCell/index.tsx +12 -5
  41. package/lib/pcpublic/src/components/pcfactory/src/Table/OperationCell/PopoverWrapper.tsx +220 -0
  42. package/lib/pcpublic/src/components/pcfactory/src/Table/OperationCell/SingleBtn.tsx +39 -32
  43. package/lib/pcpublic/src/components/pcfactory/src/Table/OperationCell/index.tsx +178 -148
  44. package/lib/pcpublic/src/components/pcfactory/src/Table/Table.tsx +439 -0
  45. package/lib/pcpublic/src/components/pcfactory/src/Table/TableHead/index.tsx +159 -72
  46. package/lib/pcpublic/src/components/pcfactory/src/Table/TableSummaryRow/index.tsx +12 -20
  47. package/lib/pcpublic/src/components/pcfactory/src/Table/constant.ts +3 -0
  48. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/index.ts +4 -4
  49. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useCMDActions.ts +32 -28
  50. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useCheckStrict.ts +44 -57
  51. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useColumns.tsx +306 -276
  52. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useCommon.ts +9 -6
  53. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useDataSource.ts +30 -21
  54. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useExpandable.tsx +33 -27
  55. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useFilter.tsx +84 -77
  56. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useFormatCell.tsx +33 -16
  57. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/usePagination.ts +15 -5
  58. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useRowEdit.ts +33 -33
  59. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useRowMerge.ts +13 -5
  60. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useScroll.ts +94 -28
  61. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useSelection.ts +108 -99
  62. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useSort.ts +8 -5
  63. package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useSummaryCol.ts +27 -43
  64. package/lib/pcpublic/src/components/pcfactory/src/Table/index.tsx +73 -394
  65. package/lib/pcpublic/src/components/pcfactory/src/Table/loader.tsx +15 -0
  66. package/lib/pcpublic/src/components/pcfactory/src/Table/types/OperationCell.d.ts +2 -2
  67. package/lib/pcpublic/src/components/pcfactory/src/Table/types/event.d.ts +12 -8
  68. package/lib/pcpublic/src/components/pcfactory/src/Table/types/headerCell.d.ts +2 -1
  69. package/lib/pcpublic/src/components/pcfactory/src/Table/types/prop.d.ts +24 -11
  70. package/lib/pcpublic/src/components/pcfactory/src/Table/utils/SequenceId.ts +2 -1
  71. package/lib/pcpublic/src/components/pcfactory/src/Table/utils/index.ts +90 -82
  72. package/lib/pcpublic/src/components/pcfactory/src/Table/utils/indexedDBHelper.ts +9 -22
  73. package/lib/pcpublic/src/components/pcfactory/src/Table/utils/translate.ts +59 -0
  74. package/lib/pcpublic/src/components/pcfactory/src/Transfer/Transfer.tsx +644 -0
  75. package/lib/pcpublic/src/components/pcfactory/src/Transfer/index.tsx +49 -637
  76. package/lib/pcpublic/src/components/pcfactory/src/Transfer/loader.tsx +11 -0
  77. package/lib/pcpublic/src/components/pcfactory/src/Tree/TreeEllipsisIcon.tsx +38 -0
  78. package/lib/pcpublic/src/components/pcfactory/src/Tree/TreeNodeMenu/index.tsx +34 -35
  79. package/lib/pcpublic/src/components/pcfactory/src/Tree/index.tsx +213 -149
  80. package/lib/pcpublic/src/components/pcfactory/src/TreeSelect/index.tsx +47 -43
  81. package/lib/pcpublic/src/components/pcfactory/src/TreeTable/TreeTable.tsx +264 -0
  82. package/lib/pcpublic/src/components/pcfactory/src/TreeTable/hooks/index.ts +4 -1
  83. package/lib/pcpublic/src/components/pcfactory/src/TreeTable/hooks/useCMDAction.ts +9 -3
  84. package/lib/pcpublic/src/components/pcfactory/src/TreeTable/hooks/useExpandable.tsx +9 -3
  85. package/lib/pcpublic/src/components/pcfactory/src/TreeTable/index.tsx +52 -191
  86. package/lib/pcpublic/src/components/pcfactory/src/TreeTable/loader.tsx +16 -0
  87. package/lib/pcpublic/src/components/pcfactory/src/assets/index.tsx +34 -0
  88. package/lib/pcpublic/src/components/pcfactory/src/assets/svg/quadrate.tsx +20 -0
  89. package/lib/pcpublic/src/components/pcfactory/src/assets/svg/roundness.tsx +14 -0
  90. package/lib/pcpublic/src/components/pcfactory/src/assets/svg/semicircle.tsx +15 -0
  91. package/lib/pcpublic/src/components/pcfactory/src/assets/svg/verticalLine.tsx +12 -0
  92. package/lib/pcpublic/src/components/pcfactory/src/styles/common.less +17 -0
  93. package/lib/pcpublic/src/components/pcfactory/src/styles/components/Card.less +57 -11
  94. package/lib/pcpublic/src/components/pcfactory/src/styles/components/Form.less +101 -12
  95. package/lib/pcpublic/src/components/pcfactory/src/styles/components/ModalSelect.less +6 -0
  96. package/lib/pcpublic/src/components/pcfactory/src/styles/components/Select.less +70 -6
  97. package/lib/pcpublic/src/components/pcfactory/src/utils/ChannelContainer.tsx +20 -14
  98. package/lib/pcpublic/src/components/pcfactory/src/utils/ChildRender.ts +6 -8
  99. package/lib/pcpublic/src/components/pcfactory/src/utils/CustomModule.tsx +4 -6
  100. package/lib/pcpublic/src/components/pcfactory/src/utils/DummyFormContext.ts +9 -13
  101. package/lib/pcpublic/src/components/pcfactory/src/utils/Empty/empty.tsx +5 -17
  102. package/lib/pcpublic/src/components/pcfactory/src/utils/Empty/index.tsx +3 -3
  103. package/lib/pcpublic/src/components/pcfactory/src/utils/Holidays.ts +11 -39
  104. package/lib/pcpublic/src/components/pcfactory/src/utils/HolidaysFormat.ts +83 -0
  105. package/lib/pcpublic/src/components/pcfactory/src/utils/IdleContainer/index.tsx +47 -0
  106. package/lib/pcpublic/src/components/pcfactory/src/utils/IdleContainer/scheduler.ts +74 -0
  107. package/lib/pcpublic/src/components/pcfactory/src/utils/LoaderHelper.tsx +4 -1
  108. package/lib/pcpublic/src/components/pcfactory/src/utils/Spin/index.tsx +8 -7
  109. package/lib/pcpublic/src/components/pcfactory/src/utils/WithSyncValue.ts +25 -23
  110. package/lib/pcpublic/src/components/pcfactory/src/utils/ahooks/index.ts +10 -7
  111. package/lib/pcpublic/src/components/pcfactory/src/utils/ahooks/useMap.ts +9 -6
  112. package/lib/pcpublic/src/components/pcfactory/src/utils/ahooks/useMemoizedFn.ts +4 -1
  113. package/lib/pcpublic/src/components/pcfactory/src/utils/ahooks/usePersistFn.ts +17 -0
  114. package/lib/pcpublic/src/components/pcfactory/src/utils/ahooks/useSafeState.ts +2 -2
  115. package/lib/pcpublic/src/components/pcfactory/src/utils/ahooks/useSetState.ts +7 -5
  116. package/lib/pcpublic/src/components/pcfactory/src/utils/common.ts +23 -50
  117. package/lib/pcpublic/src/components/pcfactory/src/utils/constant.ts +53 -57
  118. package/lib/pcpublic/src/components/pcfactory/src/utils/dynamicUtils/DynamicContext.tsx +12 -17
  119. package/lib/pcpublic/src/components/pcfactory/src/utils/formUtils/FormContext.tsx +22 -12
  120. package/lib/pcpublic/src/components/pcfactory/src/utils/formUtils/FormFields.tsx +50 -19
  121. package/lib/pcpublic/src/components/pcfactory/src/utils/formUtils/WrapperContainer.tsx +58 -37
  122. package/lib/pcpublic/src/components/pcfactory/src/utils/formUtils/cmdHelper.ts +33 -30
  123. package/lib/pcpublic/src/components/pcfactory/src/utils/formUtils/common.ts +2 -0
  124. package/lib/pcpublic/src/components/pcfactory/src/utils/generatorDisabledCallback.ts +121 -113
  125. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useCommonImperativeHandle.ts +16 -14
  126. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useCompState.tsx +1 -1
  127. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useDataMask.ts +7 -2
  128. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useDoubleClick.ts +3 -1
  129. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useFuncExpExecute.ts +16 -14
  130. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useGetStaticAttrData.ts +9 -3
  131. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useHiddenStyle.ts +4 -5
  132. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useInit.ts +11 -0
  133. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useInitReactQuill.ts +3 -1
  134. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useListenState.ts +1 -0
  135. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useLocale.ts +5 -3
  136. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/usePrintMode.tsx +2 -2
  137. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useRules.ts +1 -1
  138. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useTestHelper.ts +2 -0
  139. package/lib/pcpublic/src/components/pcfactory/src/utils/hooks/useToggleBoolean.ts +8 -4
  140. package/lib/pcpublic/src/components/pcfactory/src/utils/index.ts +10 -10
  141. package/lib/pcpublic/src/components/pcfactory/src/utils/polyfill.js +29 -31
  142. package/lib/pcpublic/src/components/pcfactory/src/utils/renderReadOnly.tsx +29 -26
  143. package/lib/public/public/iconfont.js +1 -0
  144. package/package.json +2 -2
@@ -0,0 +1,83 @@
1
+
2
+ // 该文件由 scripts/generatorHolidays.js 动态生成 请勿手动修改
3
+
4
+ /**
5
+ * 工作日
6
+ */
7
+ export const workdays = [
8
+ '2024-10-12',
9
+ '2024-09-29',
10
+ '2024-09-14',
11
+ '2024-05-11',
12
+ '2024-04-28',
13
+ '2024-04-07',
14
+ '2024-02-18',
15
+ '2024-02-04',
16
+ '2025-01-26',
17
+ '2025-02-08',
18
+ '2025-04-27',
19
+ '2025-09-28',
20
+ '2025-10-11',
21
+ ];
22
+
23
+ /**
24
+ * 节假日
25
+ */
26
+ export const holidays = [
27
+ '2024-10-07',
28
+ '2024-10-06',
29
+ '2024-10-05',
30
+ '2024-10-04',
31
+ '2024-10-03',
32
+ '2024-10-02',
33
+ '2024-10-01',
34
+ '2024-09-17',
35
+ '2024-09-16',
36
+ '2024-09-15',
37
+ '2024-06-10',
38
+ '2024-05-05',
39
+ '2024-05-04',
40
+ '2024-05-03',
41
+ '2024-05-02',
42
+ '2024-05-01',
43
+ '2024-04-06',
44
+ '2024-04-05',
45
+ '2024-04-04',
46
+ '2024-02-17',
47
+ '2024-02-16',
48
+ '2024-02-15',
49
+ '2024-02-14',
50
+ '2024-02-13',
51
+ '2024-02-12',
52
+ '2024-02-11',
53
+ '2024-02-10',
54
+ '2024-01-01',
55
+ '2025-01-01',
56
+ '2025-02-04',
57
+ '2025-02-03',
58
+ '2025-02-02',
59
+ '2025-02-01',
60
+ '2025-01-31',
61
+ '2025-01-30',
62
+ '2025-01-29',
63
+ '2025-01-28',
64
+ '2025-04-06',
65
+ '2025-04-05',
66
+ '2025-04-04',
67
+ '2025-05-05',
68
+ '2025-05-04',
69
+ '2025-05-03',
70
+ '2025-05-02',
71
+ '2025-05-01',
72
+ '2025-06-02',
73
+ '2025-06-01',
74
+ '2025-05-31',
75
+ '2025-10-08',
76
+ '2025-10-07',
77
+ '2025-10-06',
78
+ '2025-10-05',
79
+ '2025-10-04',
80
+ '2025-10-03',
81
+ '2025-10-02',
82
+ '2025-10-01',
83
+ ];
@@ -0,0 +1,47 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { requestHostCallback } from './scheduler';
3
+ import { Spin } from 'antd';
4
+
5
+ const isIE = !!((window as any).ActiveXObject || 'ActiveXObject' in window);
6
+
7
+ export interface IdleContainerProps {
8
+
9
+ /**
10
+ * 仅在 IE 浏览器下才生效,默认 true
11
+ */
12
+ onlyIE?: boolean;
13
+
14
+ /**
15
+ * 加载中动画
16
+ * @returns
17
+ */
18
+ loading?: () => React.ReactNode;
19
+ }
20
+
21
+ const IdleContainer: React.FC<IdleContainerProps> = props => {
22
+ const { onlyIE = true, loading = () => <Spin /> } = props;
23
+ const [renderChild, setRenderChild] = useState(false);
24
+
25
+ useEffect(() => {
26
+ if (!isIE && onlyIE) return () => { };
27
+
28
+ const cancelIdle = requestHostCallback(() => {
29
+ setRenderChild(true);
30
+ });
31
+ return () => {
32
+ cancelIdle();
33
+ };
34
+ }, []);
35
+
36
+ if (!isIE && onlyIE) {
37
+ return <>{props.children}</>;
38
+ }
39
+
40
+ if (!renderChild) {
41
+ return <>{loading()}</>;
42
+ }
43
+
44
+ return <>{props.children}</>;
45
+ };
46
+
47
+ export default IdleContainer;
@@ -0,0 +1,74 @@
1
+ // eslint-disable-next-line import/no-mutable-exports
2
+ let requestHostCallback: (cb: () => void) => () => void = cb => { cb(); return () => { }; };
3
+
4
+ export function isNative(Ctor: any): boolean {
5
+ return typeof Ctor === 'function' && /native code/.test(Ctor.toString());
6
+ }
7
+
8
+ if (
9
+ typeof MessageChannel !== 'undefined' &&
10
+ (isNative(MessageChannel) ||
11
+ // PhantomJS
12
+ MessageChannel.toString() === '[object MessageChannelConstructor]')
13
+ ) {
14
+ requestHostCallback = (cb: () => void) => {
15
+ let scheduledHostCallback: typeof cb | null = cb;
16
+ let isMessageLoopRunning = false;
17
+
18
+ const performWorkUntilDeadline = () => {
19
+ if (scheduledHostCallback !== null) {
20
+ try {
21
+ scheduledHostCallback();
22
+ isMessageLoopRunning = false;
23
+ } catch (error) {
24
+ port.postMessage(null);
25
+ }
26
+ } else {
27
+ isMessageLoopRunning = false;
28
+ }
29
+ };
30
+
31
+ const channel = new MessageChannel();
32
+ const port = channel.port2;
33
+ channel.port1.onmessage = performWorkUntilDeadline;
34
+
35
+ port.postMessage(null);
36
+ if (!isMessageLoopRunning) {
37
+ isMessageLoopRunning = true;
38
+ port.postMessage(null);
39
+ }
40
+
41
+ return () => {
42
+ scheduledHostCallback = null;
43
+ };
44
+ };
45
+ } else if (typeof Promise !== 'undefined' && isNative(Promise)) {
46
+ requestHostCallback = (cb: () => void) => {
47
+ let scheduledHostCallback: typeof cb | null = cb;
48
+ let isMessageLoopRunning = false;
49
+ const p = Promise.resolve();
50
+
51
+ const performWorkUntilDeadline = () => {
52
+ if (scheduledHostCallback !== null) {
53
+ try {
54
+ scheduledHostCallback();
55
+ isMessageLoopRunning = false;
56
+ // eslint-disable-next-line no-empty
57
+ } catch (error) {}
58
+ } else {
59
+ isMessageLoopRunning = false;
60
+ }
61
+ };
62
+
63
+ if (!isMessageLoopRunning) {
64
+ isMessageLoopRunning = true;
65
+ p.then(performWorkUntilDeadline);
66
+ }
67
+
68
+ return () => {
69
+ scheduledHostCallback = null;
70
+ };
71
+ };
72
+ }
73
+
74
+ export { requestHostCallback };
@@ -1,3 +1,4 @@
1
+ import React from 'react';
1
2
  // @ts-ignore
2
3
  import Loadable from 'react-loadable';
3
4
 
@@ -7,7 +8,9 @@ import Loadable from 'react-loadable';
7
8
  */
8
9
  export const LoadingComponennt = (props: any) => {
9
10
  // console.log("加载中组件", props);
10
- return <></>;
11
+ return (
12
+ <></>
13
+ );
11
14
  };
12
15
 
13
16
  const loaderHelper = (loaderRet: any, loading = LoadingComponennt) => {
@@ -1,5 +1,5 @@
1
+ import React, { useMemo } from 'react';
1
2
  import { Spin } from 'antd';
2
- import { useMemo } from 'react';
3
3
  import useCompState from '../hooks/useCompState';
4
4
 
5
5
  interface SpinProps {
@@ -9,11 +9,7 @@ interface SpinProps {
9
9
 
10
10
  const SpinComp = (props: SpinProps) => {
11
11
  const { dataState, tip } = props;
12
- const { stateIcon, stateTip } = useCompState({
13
- dataState,
14
- tip,
15
- type: 'loading',
16
- });
12
+ const { stateIcon, stateTip } = useCompState({ dataState, tip, type: 'loading' });
17
13
 
18
14
  const spinProps = useMemo(() => {
19
15
  const _spinProps: any = {};
@@ -23,7 +19,12 @@ const SpinComp = (props: SpinProps) => {
23
19
  return _spinProps;
24
20
  }, [stateIcon]);
25
21
 
26
- return <Spin {...spinProps} tip={stateTip} />;
22
+ return (
23
+ <Spin
24
+ {...spinProps}
25
+ tip={stateTip}
26
+ />
27
+ );
27
28
  };
28
29
 
29
30
  export default SpinComp;
@@ -23,9 +23,7 @@ export interface SyncValueProps {
23
23
  // 该方法移出SyncValue,避免实际运行时创建过多闭包
24
24
  const equalsObj = (oldData: any, newData: any) => {
25
25
  // 如果其中一边的运算数是undefined,那么不要去跑原型处理等后续方法,可能提高些许性能
26
- if (oldData === undefined || newData === undefined) {
27
- return oldData === newData;
28
- }
26
+ if (oldData === undefined || newData === undefined) return oldData === newData;
29
27
  // 类型为基本类型时,如果相同,则返回true
30
28
  if (oldData === newData) return true;
31
29
  if (
@@ -71,11 +69,11 @@ const SyncValue = forwardRef((props: SyncValueProps) => {
71
69
  const form = useDummyFormContext();
72
70
  const fieldName = useMemo(() => {
73
71
  if (!form?.fieldCompIdMap) return '';
74
- return (Object.values(form?.fieldCompIdMap || {}) as any).find((o: any) => o.compId === compId)?.fieldName;
72
+ return (Object.values(form?.fieldCompIdMap || {}) as any).find((o:any) => o.compId === compId)?.fieldName;
75
73
  }, [compId]);
76
74
  const defaultValue = useMemo(() => {
77
75
  if (!form?.defaultArr) return '';
78
- return (form?.defaultArr || ([] as any)).find((o: any) => o.compId === compId)?.value;
76
+ return (form?.defaultArr || [] as any).find((o:any) => o.compId === compId)?.value;
79
77
  }, [compId]);
80
78
 
81
79
  useEffect(() => {
@@ -98,8 +96,7 @@ const SyncValue = forwardRef((props: SyncValueProps) => {
98
96
  });
99
97
  }
100
98
  const finalMask = form?.dataMaskInst?.[fieldName] ?? isMask?.current;
101
- if (finalMask && dataMaskUtil) {
102
- // 脱敏值
99
+ if (finalMask && dataMaskUtil) { // 脱敏值
103
100
  finalvalue = dataMaskUtil.processDataMaskValue(finalvalue, finalMask);
104
101
  }
105
102
  // 把null值在此处拦截,下放到组件的值不能有null。因为null可能导致部分组件误动作,如Select会把null视为有效值,出现空选项。
@@ -111,14 +108,20 @@ const SyncValue = forwardRef((props: SyncValueProps) => {
111
108
  // 判断now_value 值与当前传入值是否相同,同则不触发onValueRelease
112
109
  const _value = finalvalue;
113
110
  if (Object.prototype.toString.call(getCompPropMapState) === '[object Function]') {
114
- if (!equalsObj(getCompPropMapState!(compId, 'now_value'), _value) && onValueRelease) {
111
+ if (
112
+ !equalsObj(getCompPropMapState!(compId, 'now_value'), _value) &&
113
+ onValueRelease
114
+ ) {
115
115
  if (_value === '') {
116
116
  onValueRelease(undefined);
117
117
  } else {
118
118
  onValueRelease(_value);
119
119
  }
120
120
  }
121
- if (!equalsObj(getCompPropMapState!(compId, 'now_selectedData'), _value) && onSelectedDataRelease) {
121
+ if (
122
+ !equalsObj(getCompPropMapState!(compId, 'now_selectedData'), _value) &&
123
+ onSelectedDataRelease
124
+ ) {
122
125
  if (_value === '' || _value === undefined) {
123
126
  onSelectedDataRelease([]);
124
127
  }
@@ -133,24 +136,24 @@ const SyncValue = forwardRef((props: SyncValueProps) => {
133
136
  if (!props.onChange) {
134
137
  return undefined;
135
138
  }
136
- return (...e) => {
137
- props.onChange!(...e);
138
- if (props.children.props.onChange) {
139
- props.children.props.onChange(...e);
140
- }
141
- };
139
+ return ((...e) => {
140
+ props.onChange!(...e);
141
+ if (props.children.props.onChange) {
142
+ props.children.props.onChange(...e);
143
+ }
144
+ });
142
145
  }, [props.onChange]);
143
146
 
144
147
  collectAction.onBlur = React.useMemo(() => {
145
148
  if (!props.onBlur) {
146
149
  return undefined;
147
150
  }
148
- return (...e) => {
149
- props.onBlur!(...e);
150
- if (props.children.props.onBlur) {
151
- props.children.props.onBlur(...e);
152
- }
153
- };
151
+ return ((...e) => {
152
+ props.onBlur!(...e);
153
+ if (props.children.props.onBlur) {
154
+ props.children.props.onBlur(...e);
155
+ }
156
+ });
154
157
  }, [props.onBlur]);
155
158
 
156
159
  if (!collectAction.onChange) {
@@ -169,8 +172,7 @@ const SyncValue = forwardRef((props: SyncValueProps) => {
169
172
  // 控件只读模式改造
170
173
  if (readOnly && !render) {
171
174
  return renderReadOnly(finalvalue || '--');
172
- }
173
- if (readOnly && typeof render === 'function') {
175
+ } if (readOnly && typeof render === 'function') {
174
176
  return render(finalvalue);
175
177
  }
176
178
  }
@@ -1,12 +1,15 @@
1
- import useCreation from './useCreation';
2
- import { useDeepCompareEffect } from './useDeepCompareEffect';
3
- import useMap from './useMap';
4
- import useMemoizedFn from './useMemoizedFn';
5
1
  import usePrevious from './usePrevious';
6
2
  import useSafeState from './useSafeState';
3
+ import useMemoizedFn from './useMemoizedFn';
4
+ import useUpdateEffect from './useUpdateEffect';
5
+ import { useDeepCompareEffect } from './useDeepCompareEffect';
7
6
  import useSetState, { SetState } from './useSetState';
7
+ import useMap from './useMap';
8
8
  import useUpdate from './useUpdate';
9
- import useUpdateEffect from './useUpdateEffect';
9
+ import useCreation from './useCreation';
10
+ import usePersistFn from './usePersistFn';
10
11
 
11
- export type { SetState };
12
- export { usePrevious, useSafeState, useMemoizedFn, useUpdateEffect, useDeepCompareEffect, useSetState, useMap, useUpdate, useCreation };
12
+ export type {
13
+ SetState,
14
+ };
15
+ export { usePrevious, useSafeState, useMemoizedFn, useUpdateEffect, useDeepCompareEffect, useSetState, useMap, useUpdate, useCreation, usePersistFn };
@@ -1,13 +1,16 @@
1
- import { useCallback, useMemo, useState } from 'react';
1
+ import { useMemo, useState, useCallback } from 'react';
2
2
 
3
3
  function useMap<K, T>(initialValue?: Iterable<readonly [K, T]>) {
4
- const initialMap = useMemo<Map<K, T>>(() => (initialValue === undefined ? new Map() : new Map(initialValue)) as Map<K, T>, []);
4
+ const initialMap = useMemo<Map<K, T>>(
5
+ () => (initialValue === undefined ? new Map() : new Map(initialValue)) as Map<K, T>,
6
+ [],
7
+ );
5
8
  const [map, setMap] = useState(initialMap);
6
9
 
7
10
  const stableActions = useMemo(
8
11
  () => ({
9
12
  set: (key: K, entry: T) => {
10
- setMap(prev => {
13
+ setMap((prev) => {
11
14
  const temp = new Map(prev);
12
15
  temp.set(key, entry);
13
16
  return temp;
@@ -17,7 +20,7 @@ function useMap<K, T>(initialValue?: Iterable<readonly [K, T]>) {
17
20
  setMap(new Map(newMap));
18
21
  },
19
22
  remove: (key: K) => {
20
- setMap(prev => {
23
+ setMap((prev) => {
21
24
  const temp = new Map(prev);
22
25
  temp.delete(key);
23
26
  return temp;
@@ -25,11 +28,11 @@ function useMap<K, T>(initialValue?: Iterable<readonly [K, T]>) {
25
28
  },
26
29
  reset: () => setMap(initialMap),
27
30
  }),
28
- [setMap, initialMap]
31
+ [setMap, initialMap],
29
32
  );
30
33
 
31
34
  const utils = {
32
- get: useCallback(key => map.get(key), [map]),
35
+ get: useCallback((key) => map.get(key), [map]),
33
36
  ...stableActions,
34
37
  };
35
38
 
@@ -2,7 +2,10 @@ import { useMemo, useRef } from 'react';
2
2
 
3
3
  type noop = (this: any, ...args: any[]) => any;
4
4
 
5
- type PickFunction<T extends noop> = (this: ThisParameterType<T>, ...args: Parameters<T>) => ReturnType<T>;
5
+ type PickFunction<T extends noop> = (
6
+ this: ThisParameterType<T>,
7
+ ...args: Parameters<T>
8
+ ) => ReturnType<T>;
6
9
 
7
10
  function useMemoizedFn<T extends noop>(fn: T) {
8
11
  const fnRef = useRef<T>(fn);
@@ -0,0 +1,17 @@
1
+ import { useRef, useCallback } from 'react';
2
+
3
+ const usePersistFn = (fn: any) => {
4
+ const ref = useRef(fn);
5
+ ref.current = fn;
6
+
7
+ const persistFn = useCallback((...args) => {
8
+ if (ref.current) {
9
+ return ref.current.apply(this, args);
10
+ }
11
+ return undefined;
12
+ }, []);
13
+
14
+ return persistFn;
15
+ };
16
+
17
+ export default usePersistFn;
@@ -1,5 +1,5 @@
1
- import type { Dispatch, SetStateAction } from 'react';
2
1
  import { useCallback, useState } from 'react';
2
+ import type { Dispatch, SetStateAction } from 'react';
3
3
  import useUnmountedRef from './useUnmountedRef';
4
4
 
5
5
  function useSafeState<S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>];
@@ -9,7 +9,7 @@ function useSafeState<S = undefined>(): [S | undefined, Dispatch<SetStateAction<
9
9
  function useSafeState<S>(initialState?: S | (() => S)) {
10
10
  const unmountedRef = useUnmountedRef();
11
11
  const [state, setState] = useState(initialState);
12
- const setCurrentState = useCallback(currentState => {
12
+ const setCurrentState = useCallback((currentState) => {
13
13
  /** if component is unmounted, stop update */
14
14
  if (unmountedRef.current) return;
15
15
  setState(currentState);
@@ -1,15 +1,17 @@
1
- import isFunction from 'lodash/isFunction';
2
1
  import { useCallback, useState } from 'react';
2
+ import isFunction from 'lodash/isFunction';
3
3
 
4
4
  export type SetState<S extends Record<string, any>> = <K extends keyof S>(
5
- state: Pick<S, K> | null | ((prevState: Readonly<S>) => Pick<S, K> | S | null)
5
+ state: Pick<S, K> | null | ((prevState: Readonly<S>) => Pick<S, K> | S | null),
6
6
  ) => void;
7
7
 
8
- const useSetState = <S extends Record<string, any>>(initialState: S | (() => S)): [S, SetState<S>] => {
8
+ const useSetState = <S extends Record<string, any>>(
9
+ initialState: S | (() => S),
10
+ ): [S, SetState<S>] => {
9
11
  const [state, setState] = useState<S>(initialState);
10
12
 
11
- const setMergeState = useCallback(patch => {
12
- setState(prevState => {
13
+ const setMergeState = useCallback((patch) => {
14
+ setState((prevState) => {
13
15
  const newState = isFunction(patch) ? patch(prevState) : patch;
14
16
  return newState ? { ...prevState, ...newState } : prevState;
15
17
  });