plain-design 1.0.0-beta.40 → 1.0.0-beta.41
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/plain-design.commonjs.min.js +2 -2
- package/dist/plain-design.min.js +2 -2
- package/dist/report.html +2 -2
- package/package.json +3 -3
- package/src/packages/components/usePopup/usePopup.tsx +23 -7
- package/src/packages/components/useTooltip/index.tsx +8 -2
- package/src/packages/utils/watchEffectAutoClear.ts +19 -7
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "plain-design",
|
3
|
-
"version": "1.0.0-beta.
|
3
|
+
"version": "1.0.0-beta.41",
|
4
4
|
"description": "",
|
5
5
|
"main": "dist/plain-design.min.js",
|
6
6
|
"module": "dist/plain-design.commonjs.min.js",
|
@@ -34,7 +34,7 @@
|
|
34
34
|
"color": "^4.2.3",
|
35
35
|
"dayjs": "^1.10.4",
|
36
36
|
"plain-icons": "0.0.7",
|
37
|
-
"plain-utils": "0.1.
|
37
|
+
"plain-utils": "0.1.57",
|
38
38
|
"react-flip-move": "^3.0.4",
|
39
39
|
"react-transition-group": "^4.4.1"
|
40
40
|
},
|
@@ -69,7 +69,7 @@
|
|
69
69
|
"fork-ts-checker-webpack-plugin": "^6.2.4",
|
70
70
|
"mini-css-extract-plugin": "^1.4.1",
|
71
71
|
"mockjs": "^1.1.0",
|
72
|
-
"plain-design-composition": "^0.0.
|
72
|
+
"plain-design-composition": "^0.0.186",
|
73
73
|
"postcss": "^8.2.13",
|
74
74
|
"postcss-loader": "^4.2.0",
|
75
75
|
"qs": "^6.10.1",
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import {PopupManager} from "./usePopupManager";
|
2
2
|
import {iPopupManager, iPopupUseOption, nextPopupId} from "./utils/popup.utils";
|
3
3
|
import {onBeforeUnmount, SimpleFunction} from "plain-design-composition";
|
4
|
+
import {toArray} from "plain-utils/utils/toArray";
|
4
5
|
|
5
6
|
export function usePopup() {
|
6
7
|
const popupId = nextPopupId();
|
@@ -20,8 +21,21 @@ export function createPopup(onBeforeUnmount?: (handler: SimpleFunction) => void)
|
|
20
21
|
|
21
22
|
export function _createPopup(popupManager: iPopupManager) {
|
22
23
|
|
24
|
+
/*记录操作过的popup id,在销毁的时候将这些popup option在manager中全部注销*/
|
23
25
|
const idMap = {} as Record<string, boolean>;
|
24
26
|
|
27
|
+
const hide: typeof popupManager.methods.hide = (ids) => {
|
28
|
+
toArray(ids).forEach(id => idMap[id] = true);
|
29
|
+
return popupManager.methods.hide(ids);
|
30
|
+
};
|
31
|
+
const update: typeof popupManager.methods.update = (option) => {
|
32
|
+
idMap[option.id] = true;
|
33
|
+
return popupManager.methods.update(option);
|
34
|
+
};
|
35
|
+
const refresh: typeof popupManager.methods.refresh = (option) => {
|
36
|
+
idMap[option.id] = true;
|
37
|
+
return popupManager.methods.refresh(option);
|
38
|
+
};
|
25
39
|
const show: typeof popupManager.methods.show = (useOption) => {
|
26
40
|
const data = popupManager.methods.show(useOption);
|
27
41
|
idMap[data.option.id] = true;
|
@@ -29,23 +43,25 @@ export function _createPopup(popupManager: iPopupManager) {
|
|
29
43
|
};
|
30
44
|
const toggle = (option: iPopupUseOption) => {
|
31
45
|
if (popupManager.methods.isShow(option)) {
|
32
|
-
|
46
|
+
hide(option.id);
|
33
47
|
} else {
|
34
48
|
show(option);
|
35
49
|
}
|
36
50
|
};
|
37
|
-
const absolute: typeof popupManager.methods.absolute = (
|
38
|
-
const data = popupManager.methods.absolute(
|
51
|
+
const absolute: typeof popupManager.methods.absolute = (absoluteOption) => {
|
52
|
+
const data = popupManager.methods.absolute(absoluteOption);
|
39
53
|
idMap[data.option.id] = true;
|
40
54
|
return data;
|
41
55
|
};
|
42
|
-
const dispose = () => {
|
56
|
+
const dispose = () => {
|
57
|
+
Object.keys(idMap).forEach(id => {popupManager.methods.remove(id);});
|
58
|
+
};
|
43
59
|
|
44
60
|
const $popup = {
|
45
61
|
manager: popupManager,
|
46
|
-
hide
|
47
|
-
update
|
48
|
-
refresh
|
62
|
+
hide,
|
63
|
+
update,
|
64
|
+
refresh,
|
49
65
|
show,
|
50
66
|
toggle,
|
51
67
|
dispose,
|
@@ -149,7 +149,10 @@ export function createTooltip(option: iTooltipServiceOption, popup: iPopupServic
|
|
149
149
|
return { close };
|
150
150
|
})();
|
151
151
|
|
152
|
-
const clear = () => {
|
152
|
+
const clear = () => {
|
153
|
+
effects.clear();
|
154
|
+
popup.dispose();
|
155
|
+
};
|
153
156
|
|
154
157
|
return { referenceEnterHandler, tooltipHandler, clear };
|
155
158
|
}
|
@@ -164,7 +167,10 @@ export function createTooltip(option: iTooltipServiceOption, popup: iPopupServic
|
|
164
167
|
export function useTooltip(option: iTooltipServiceOption) {
|
165
168
|
const popup = usePopup();
|
166
169
|
const val = createTooltip(option, popup);
|
167
|
-
onBeforeUnmount(() => {
|
170
|
+
onBeforeUnmount(() => {
|
171
|
+
val.clear();
|
172
|
+
popup.dispose();
|
173
|
+
});
|
168
174
|
return val;
|
169
175
|
}
|
170
176
|
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import {onBeforeUnmount,
|
1
|
+
import {onBeforeUnmount, watch} from "plain-design-composition";
|
2
|
+
import {createEffects} from "plain-utils/utils/createEffects";
|
2
3
|
|
3
4
|
/**
|
4
5
|
* watch函数封装,支持清理副作用
|
@@ -6,11 +7,22 @@ import {onBeforeUnmount, SimpleFunction, watch} from "plain-design-composition";
|
|
6
7
|
* @date 2022.7.3 13:15
|
7
8
|
*/
|
8
9
|
export function useWatchAutoClear<T>(watcher: () => T, handler: (newVal: T, oldVal: undefined | T) => (() => void)) {
|
9
|
-
let clear: SimpleFunction | null = null;
|
10
|
-
watch(() => watcher(), (newVal, oldVal) => {
|
11
|
-
clear?.();
|
12
|
-
clear = handler(newVal, oldVal);
|
13
|
-
}, { immediate: true });
|
14
10
|
|
15
|
-
|
11
|
+
const { effects: setupEffects } = createEffects();
|
12
|
+
const { effects: watchEffects } = createEffects();
|
13
|
+
|
14
|
+
setupEffects.push(
|
15
|
+
watch(() => watcher(), (newVal, oldVal) => {
|
16
|
+
watchEffects.clear();
|
17
|
+
watchEffects.push(
|
18
|
+
handler(newVal, oldVal)
|
19
|
+
);
|
20
|
+
}, { immediate: true })
|
21
|
+
);
|
22
|
+
|
23
|
+
onBeforeUnmount(() => {
|
24
|
+
setupEffects.clear();
|
25
|
+
watchEffects.clear();
|
26
|
+
});
|
16
27
|
}
|
28
|
+
|