plain-design 1.0.0-beta.40 → 1.0.0-beta.42

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plain-design",
3
- "version": "1.0.0-beta.40",
3
+ "version": "1.0.0-beta.42",
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.56",
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.185",
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",
@@ -36,9 +36,9 @@ export function useManagerTriggerClickOutside({ hooks }: iPopupManager) {
36
36
  { trailing: false }
37
37
  );
38
38
  onMounted(() => {
39
- window.addEventListener('click', onClick, true);
39
+ window.addEventListener('mouseup', onClick, true);
40
40
  });
41
41
  onBeforeUnmount(() => {
42
- window.removeEventListener('click', onClick, true);
42
+ window.removeEventListener('mouseup', onClick, true);
43
43
  });
44
44
  }
@@ -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
- $popup.hide(option.id);
46
+ hide(option.id);
33
47
  } else {
34
48
  show(option);
35
49
  }
36
50
  };
37
- const absolute: typeof popupManager.methods.absolute = (absluteOption) => {
38
- const data = popupManager.methods.absolute(absluteOption);
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 = () => {Object.keys(idMap).forEach(id => {popupManager.methods.remove(id);});};
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: popupManager.methods.hide,
47
- update: popupManager.methods.update,
48
- refresh: popupManager.methods.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 = () => {effects.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(() => {val.clear();});
170
+ onBeforeUnmount(() => {
171
+ val.clear();
172
+ popup.dispose();
173
+ });
168
174
  return val;
169
175
  }
170
176
 
@@ -1,4 +1,5 @@
1
- import {onBeforeUnmount, SimpleFunction, watch} from "plain-design-composition";
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
- onBeforeUnmount(() => clear?.());
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
+