@canlooks/can-ui 0.0.116 → 0.0.117

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.
@@ -40,9 +40,7 @@ const placementToIndex = {
40
40
  exports.SnackbarBase = (0, react_2.memo)(({ methods, useTo, max = useTo === 'message' ? 5 : 4, container, effectContainer }) => {
41
41
  const [stacks, setStacks] = (0, react_2.useState)([]);
42
42
  const timers = (0, react_2.useRef)([]);
43
- (0, react_2.useEffect)(() => () => {
44
- timers.current.forEach(timer => clearTimeout(timer));
45
- }, []);
43
+ const isUnmounted = (0, utils_1.useUnmounted)();
46
44
  const defineMethod = (type) => (props) => new Promise(resolve => {
47
45
  const propsObject = typeof props === 'object' && !(0, react_2.isValidElement)(props)
48
46
  ? props
@@ -51,7 +49,7 @@ exports.SnackbarBase = (0, react_2.memo)(({ methods, useTo, max = useTo === 'mes
51
49
  const index = placementToIndex[placement];
52
50
  let id = (0, utils_1.getEasyID)('snackbar');
53
51
  const onCloseButtonClick = () => {
54
- setStacks(o => {
52
+ !isUnmounted.current && setStacks(o => {
55
53
  o[index] = o[index].filter(s => s.id !== id);
56
54
  return [...o];
57
55
  });
@@ -165,9 +165,9 @@ function useExternalClass(setup, cleanup) {
165
165
  * 用法同{@link useEffect},但StrictMode下不会执行两次
166
166
  */
167
167
  function useStrictEffect(effect, deps) {
168
- const prevDeps = (0, react_1.useRef)(deps);
168
+ const prevDeps = (0, react_1.useRef)(void 0);
169
169
  (0, react_1.useEffect)(() => {
170
- const isDepsChanged = prevDeps.current ? (0, utils_1.arrayShallowEqual)(prevDeps.current, deps) : true;
170
+ const isDepsChanged = prevDeps.current ? !(0, utils_1.arrayShallowEqual)(prevDeps.current, deps) : true;
171
171
  if (isDepsChanged) {
172
172
  prevDeps.current = deps;
173
173
  return effect();
@@ -86,34 +86,36 @@ function sortTreeNodes(props, sortInfo) {
86
86
  }
87
87
  return null;
88
88
  };
89
- pickUp(nodes);
90
- const putDown = (nodes) => {
91
- if (!nodes?.length) {
92
- return false;
93
- }
94
- for (let i = 0, { length } = nodes; i < length; i++) {
95
- const node = nodes[i];
96
- if (node[primaryKey] === destination) {
97
- switch (placement) {
98
- case 'before':
99
- nodes.splice(i, 0, node);
100
- return true;
101
- case 'after':
102
- nodes.splice(i + 1, 0, node);
103
- return true;
104
- default:
105
- node.children ||= [];
106
- node.children.push(node);
107
- return true;
108
- }
89
+ const sourceNode = pickUp(nodes);
90
+ if (sourceNode) {
91
+ const putDown = (nodes) => {
92
+ if (!nodes?.length) {
93
+ return false;
109
94
  }
110
- const foundInChildren = pickUp(node[childrenKey]);
111
- if (foundInChildren) {
112
- return foundInChildren;
95
+ for (let i = 0, { length } = nodes; i < length; i++) {
96
+ const node = nodes[i];
97
+ if (node[primaryKey] === destination) {
98
+ switch (placement) {
99
+ case 'before':
100
+ nodes.splice(i, 0, sourceNode);
101
+ return true;
102
+ case 'after':
103
+ nodes.splice(i + 1, 0, sourceNode);
104
+ return true;
105
+ default:
106
+ node.children ||= [];
107
+ node.children.push(sourceNode);
108
+ return true;
109
+ }
110
+ }
111
+ const foundInChildren = putDown(node[childrenKey]);
112
+ if (foundInChildren) {
113
+ return foundInChildren;
114
+ }
113
115
  }
114
- }
115
- return false;
116
- };
117
- putDown(nodes);
116
+ return false;
117
+ };
118
+ putDown(nodes);
119
+ }
118
120
  return nodes;
119
121
  }
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
2
  import { createElement as _createElement } from "@emotion/react";
3
- import { isValidElement, memo, useEffect, useRef, useState } from 'react';
3
+ import { isValidElement, memo, useRef, useState } from 'react';
4
4
  import { Collapse, Slide } from '../transitionBase';
5
- import { clsx, getEasyID, useColor, useContainer } from '../../utils';
5
+ import { clsx, getEasyID, useColor, useContainer, useUnmounted } from '../../utils';
6
6
  import { classes, style } from './snackbarBase.style';
7
7
  import { TransitionGroup } from 'react-transition-group';
8
8
  import { StatusIcon, statusMapToIconDefinition } from '../status';
@@ -36,9 +36,7 @@ const placementToIndex = {
36
36
  export const SnackbarBase = memo(({ methods, useTo, max = useTo === 'message' ? 5 : 4, container, effectContainer }) => {
37
37
  const [stacks, setStacks] = useState([]);
38
38
  const timers = useRef([]);
39
- useEffect(() => () => {
40
- timers.current.forEach(timer => clearTimeout(timer));
41
- }, []);
39
+ const isUnmounted = useUnmounted();
42
40
  const defineMethod = (type) => (props) => new Promise(resolve => {
43
41
  const propsObject = typeof props === 'object' && !isValidElement(props)
44
42
  ? props
@@ -47,7 +45,7 @@ export const SnackbarBase = memo(({ methods, useTo, max = useTo === 'message' ?
47
45
  const index = placementToIndex[placement];
48
46
  let id = getEasyID('snackbar');
49
47
  const onCloseButtonClick = () => {
50
- setStacks(o => {
48
+ !isUnmounted.current && setStacks(o => {
51
49
  o[index] = o[index].filter(s => s.id !== id);
52
50
  return [...o];
53
51
  });
@@ -151,9 +151,9 @@ export function useExternalClass(setup, cleanup) {
151
151
  * 用法同{@link useEffect},但StrictMode下不会执行两次
152
152
  */
153
153
  export function useStrictEffect(effect, deps) {
154
- const prevDeps = useRef(deps);
154
+ const prevDeps = useRef(void 0);
155
155
  useEffect(() => {
156
- const isDepsChanged = prevDeps.current ? arrayShallowEqual(prevDeps.current, deps) : true;
156
+ const isDepsChanged = prevDeps.current ? !arrayShallowEqual(prevDeps.current, deps) : true;
157
157
  if (isDepsChanged) {
158
158
  prevDeps.current = deps;
159
159
  return effect();
@@ -82,34 +82,36 @@ export function sortTreeNodes(props, sortInfo) {
82
82
  }
83
83
  return null;
84
84
  };
85
- pickUp(nodes);
86
- const putDown = (nodes) => {
87
- if (!nodes?.length) {
88
- return false;
89
- }
90
- for (let i = 0, { length } = nodes; i < length; i++) {
91
- const node = nodes[i];
92
- if (node[primaryKey] === destination) {
93
- switch (placement) {
94
- case 'before':
95
- nodes.splice(i, 0, node);
96
- return true;
97
- case 'after':
98
- nodes.splice(i + 1, 0, node);
99
- return true;
100
- default:
101
- node.children ||= [];
102
- node.children.push(node);
103
- return true;
104
- }
85
+ const sourceNode = pickUp(nodes);
86
+ if (sourceNode) {
87
+ const putDown = (nodes) => {
88
+ if (!nodes?.length) {
89
+ return false;
105
90
  }
106
- const foundInChildren = pickUp(node[childrenKey]);
107
- if (foundInChildren) {
108
- return foundInChildren;
91
+ for (let i = 0, { length } = nodes; i < length; i++) {
92
+ const node = nodes[i];
93
+ if (node[primaryKey] === destination) {
94
+ switch (placement) {
95
+ case 'before':
96
+ nodes.splice(i, 0, sourceNode);
97
+ return true;
98
+ case 'after':
99
+ nodes.splice(i + 1, 0, sourceNode);
100
+ return true;
101
+ default:
102
+ node.children ||= [];
103
+ node.children.push(sourceNode);
104
+ return true;
105
+ }
106
+ }
107
+ const foundInChildren = putDown(node[childrenKey]);
108
+ if (foundInChildren) {
109
+ return foundInChildren;
110
+ }
109
111
  }
110
- }
111
- return false;
112
- };
113
- putDown(nodes);
112
+ return false;
113
+ };
114
+ putDown(nodes);
115
+ }
114
116
  return nodes;
115
117
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canlooks/can-ui",
3
- "version": "0.0.116",
3
+ "version": "0.0.117",
4
4
  "author": "C.CanLiang <canlooks@gmail.com>",
5
5
  "description": "My ui framework",
6
6
  "license": "MIT",