@canlooks/can-ui 0.0.167 → 0.0.169

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 (33) hide show
  1. package/dist/cjs/components/curd/curdColumnConfig.d.ts +4 -4
  2. package/dist/cjs/components/curd/curdColumnConfig.js +3 -3
  3. package/dist/cjs/components/tabs/lineIndicator.d.ts +5 -5
  4. package/dist/cjs/components/tabs/lineIndicator.js +7 -4
  5. package/dist/cjs/components/tabs/tab.d.ts +4 -2
  6. package/dist/cjs/components/tabs/tab.js +21 -12
  7. package/dist/cjs/components/tabs/tabs.js +11 -9
  8. package/dist/cjs/components/tabs/tabs.style.d.ts +1 -0
  9. package/dist/cjs/components/tabs/tabs.style.js +18 -9
  10. package/dist/cjs/components/transitionBase/collapse.d.ts +1 -1
  11. package/dist/cjs/components/transitionBase/collapse.js +41 -30
  12. package/dist/cjs/components/transitionBase/transitionBase.js +7 -2
  13. package/dist/cjs/components/transitionBase/transitionBase.style.d.ts +3 -3
  14. package/dist/cjs/components/transitionBase/transitionBase.style.js +82 -99
  15. package/dist/cjs/utils/curd.d.ts +3 -3
  16. package/dist/cjs/utils/curd.js +3 -21
  17. package/dist/esm/components/curd/curdColumnConfig.d.ts +4 -4
  18. package/dist/esm/components/curd/curdColumnConfig.js +3 -3
  19. package/dist/esm/components/tabs/lineIndicator.d.ts +5 -5
  20. package/dist/esm/components/tabs/lineIndicator.js +7 -4
  21. package/dist/esm/components/tabs/tab.d.ts +4 -2
  22. package/dist/esm/components/tabs/tab.js +22 -13
  23. package/dist/esm/components/tabs/tabs.js +13 -11
  24. package/dist/esm/components/tabs/tabs.style.d.ts +1 -0
  25. package/dist/esm/components/tabs/tabs.style.js +18 -9
  26. package/dist/esm/components/transitionBase/collapse.d.ts +1 -1
  27. package/dist/esm/components/transitionBase/collapse.js +43 -32
  28. package/dist/esm/components/transitionBase/transitionBase.js +9 -4
  29. package/dist/esm/components/transitionBase/transitionBase.style.d.ts +3 -3
  30. package/dist/esm/components/transitionBase/transitionBase.style.js +80 -98
  31. package/dist/esm/utils/curd.d.ts +3 -3
  32. package/dist/esm/utils/curd.js +3 -21
  33. package/package.json +1 -1
@@ -1,60 +1,71 @@
1
1
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
2
- import { useRef, useState } from 'react';
2
+ import { useLayoutEffect, useRef, useState } from 'react';
3
3
  import { TransitionBase } from './transitionBase.js';
4
- import { cloneRef, useStrictEffect } from '../../utils/index.js';
4
+ import { cloneRef, useUpdateEffect } from '../../utils/index.js';
5
5
  export const Collapse = ({ transitionType = 'sweeping', ...props }) => {
6
6
  const Component = transitionType === 'sweeping' ? Sweeping : TransitionBase;
7
7
  return (_jsx(Component, { ...props, _mode: transitionType === 'sweeping' ? '_sweeping' : 'collapse' }));
8
8
  };
9
- const Sweeping = ({ ref, in: _in = false, appear = true, orientation = 'vertical', collapsedSize = 0, ...props }) => {
9
+ const Sweeping = ({ ref, in: _in = false, orientation = 'vertical', collapsedSize = 0, appear = true, ...props }) => {
10
10
  const innerRef = useRef(null);
11
+ const styleProperty = orientation === 'vertical' ? 'height' : 'width';
11
12
  const getCollapsedSize = () => {
12
13
  return typeof collapsedSize === 'function' ? collapsedSize() : collapsedSize;
13
14
  };
14
- const [size, setSize] = useState(() => {
15
- if (_in && !appear) {
16
- return 'auto';
17
- }
18
- return getCollapsedSize();
19
- });
20
- const [isEntered, setIsEntered] = useState(_in && !appear);
21
- const styleProperty = orientation === 'vertical' ? 'height' : 'width';
22
- const expand = () => {
15
+ const [size, setSize] = useState(() => !_in ? getCollapsedSize() : 'auto');
16
+ const getFullSize = () => {
23
17
  const el = innerRef.current;
18
+ let size;
24
19
  if (el) {
25
20
  el.style.transition = 'none';
21
+ const originalSize = el.style[styleProperty];
26
22
  el.style[styleProperty] = 'auto';
27
- const newSize = el[orientation === 'vertical' ? 'offsetHeight' : 'offsetWidth'];
28
- el.style[styleProperty] = size + 'px';
23
+ size = el[orientation === 'vertical' ? 'offsetHeight' : 'offsetWidth'];
24
+ el.style[styleProperty] = originalSize;
29
25
  el.style.transition = '';
26
+ }
27
+ return size;
28
+ };
29
+ const expand = (fromSize) => {
30
+ const fullSize = getFullSize();
31
+ if (typeof fullSize !== 'undefined') {
32
+ if (typeof fromSize !== 'undefined') {
33
+ const el = innerRef.current;
34
+ el.style[styleProperty] = fromSize + 'px';
35
+ }
30
36
  requestAnimationFrame(() => {
31
- setSize(newSize);
37
+ setSize(fullSize);
32
38
  });
33
39
  }
34
40
  };
41
+ const getCurrentSize = () => {
42
+ const el = innerRef.current;
43
+ if (el) {
44
+ return el[orientation === 'vertical' ? 'offsetHeight' : 'offsetWidth'];
45
+ }
46
+ };
35
47
  const collapse = () => {
36
- setIsEntered(false);
37
- requestAnimationFrame(() => {
38
- setSize(getCollapsedSize());
39
- });
48
+ const currentSize = getCurrentSize();
49
+ if (typeof currentSize !== 'undefined') {
50
+ const el = innerRef.current;
51
+ el.style[styleProperty] = currentSize + 'px';
52
+ requestAnimationFrame(() => {
53
+ setSize(getCollapsedSize());
54
+ });
55
+ }
40
56
  };
41
- const mounted = useRef(false);
42
- useStrictEffect(() => {
43
- if (!mounted.current) {
44
- // 首次渲染
45
- mounted.current = true;
46
- if (!appear) {
47
- // 若appear为false,则跳过首次动画
48
- return;
49
- }
57
+ useLayoutEffect(() => {
58
+ if (_in && appear) {
59
+ expand(getCollapsedSize());
50
60
  }
61
+ }, []);
62
+ useUpdateEffect(() => {
51
63
  _in
52
64
  ? expand()
53
65
  : collapse();
54
66
  }, [_in]);
55
- return (_jsx(TransitionBase, { ...props, appear: appear, orientation: orientation, in: _in, ref: cloneRef(ref, innerRef), style: {
56
- [styleProperty]: isEntered ? 'auto' : size,
57
- ...!isEntered && { overflow: 'hidden' },
67
+ return (_jsx(TransitionBase, { ...props, ref: cloneRef(ref, innerRef), in: _in, orientation: orientation, appear: appear, style: {
68
+ [styleProperty]: size,
58
69
  ...props.style
59
- }, onEntered: () => setIsEntered(true) }));
70
+ } }));
60
71
  };
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
2
- import { useRef } from 'react';
2
+ import { useEffect, useRef } from 'react';
3
3
  import { CSSTransition } from 'react-transition-group';
4
- import { classes, fadeStyle, sweepingStyle, useGrowAndCollapseStyle, useSlideStyle, useTransitionBaseStyle } from './transitionBase.style.js';
4
+ import { classes, fadeStyle, useGrowAndCollapseStyle, useSlideStyle, useSweepingStyle, useTransitionBaseStyle } from './transitionBase.style.js';
5
5
  import { clsx, cloneRef } from '../../utils/index.js';
6
6
  export const TransitionBase = (({ ref, component: Component = 'div', orientation = 'vertical', direction = 'down', offset = '100%', timeout = 300, appear = true, _mode, ...props }) => {
7
7
  const cssArr = [
@@ -11,7 +11,7 @@ export const TransitionBase = (({ ref, component: Component = 'div', orientation
11
11
  cssArr.push(fadeStyle);
12
12
  switch (_mode) {
13
13
  case '_sweeping':
14
- cssArr.push(sweepingStyle);
14
+ cssArr.push(useSweepingStyle({ orientation }));
15
15
  break;
16
16
  case 'collapse':
17
17
  case 'grow':
@@ -22,5 +22,10 @@ export const TransitionBase = (({ ref, component: Component = 'div', orientation
22
22
  }
23
23
  }
24
24
  const innerRef = useRef(null);
25
- return (_jsx(CSSTransition, { ...props, css: cssArr, nodeRef: innerRef, className: clsx(classes.root, props.className), timeout: timeout, appear: appear, children: _jsx(Component, { ref: cloneRef(ref, innerRef), children: props.children }) }));
25
+ const initialized = useRef(false);
26
+ useEffect(() => {
27
+ initialized.current = true;
28
+ }, [props.in]);
29
+ const unInitClass = !initialized.current && !props.in && 'exit-done';
30
+ return (_jsx(CSSTransition, { ...props, css: cssArr, nodeRef: innerRef, className: clsx(classes.root, props.className, unInitClass), timeout: timeout, appear: appear, children: _jsx(Component, { ref: cloneRef(ref, innerRef), children: props.children }) }));
26
31
  });
@@ -4,6 +4,6 @@ export declare const classes: {
4
4
  };
5
5
  export declare function useTransitionBaseStyle({ timeout }: Required<Pick<TransitionBaseProps<any>, 'timeout'>>): import("@emotion/utils").SerializedStyles;
6
6
  export declare const fadeStyle: () => import("@emotion/utils").SerializedStyles;
7
- export declare const sweepingStyle: () => import("@emotion/utils").SerializedStyles;
8
- export declare function useGrowAndCollapseStyle({ orientation, _mode }: Required<Pick<TransitionBaseProps<any>, 'orientation' | '_mode'>>): import("@emotion/utils").SerializedStyles;
9
- export declare function useSlideStyle({ direction, offset }: Required<Pick<TransitionBaseProps<any>, 'direction' | 'offset'>>): import("@emotion/utils").SerializedStyles;
7
+ export declare function useSweepingStyle({ orientation }: Required<Pick<TransitionBaseProps, 'orientation'>>): import("@emotion/utils").SerializedStyles;
8
+ export declare function useGrowAndCollapseStyle({ orientation, _mode }: Required<Pick<TransitionBaseProps, 'orientation' | '_mode'>>): import("@emotion/utils").SerializedStyles;
9
+ export declare function useSlideStyle({ direction, offset }: Required<Pick<TransitionBaseProps, 'direction' | 'offset'>>): import("@emotion/utils").SerializedStyles;
@@ -6,6 +6,7 @@ export function useTransitionBaseStyle({ timeout }) {
6
6
  return useCss(() => css `
7
7
  @layer reset {
8
8
  ${timeoutIsNumber ? `transition-duration: ${timeout}ms;` : ''}
9
+
9
10
  &.appear-active {
10
11
  ${!timeoutIsNumber ? `transition-duration: ${timeout.appear}ms;` : ''}
11
12
  }
@@ -22,126 +23,107 @@ export function useTransitionBaseStyle({ timeout }) {
22
23
  }
23
24
  export const fadeStyle = defineCss(({ easing }) => css `
24
25
  @layer reset {
25
- transition-property: opacity;
26
- transition-timing-function: ${easing.easeOut};
27
-
28
- &,
29
26
  &.appear,
30
- &.enter {
27
+ &.exit,
28
+ &.exit-done {
31
29
  opacity: 0;
32
30
  }
33
-
31
+
34
32
  &.appear-active,
35
- &.enter-active,
36
- &.enter-done,
37
- &.exit {
33
+ &.enter,
34
+ &.enter-done {
38
35
  opacity: 1;
39
36
  }
40
37
 
41
- &.exit-active,
42
- &.exit-done {
43
- opacity: 0;
44
- }
45
- }
46
- `);
47
- export const sweepingStyle = defineCss(({ easing }) => css `
48
- @layer reset {
49
- transition-property: opacity, width, height;
50
-
51
38
  &.appear-active,
52
39
  &.enter-active,
53
- &.enter-done {
54
- transition-timing-function: ${easing.easeOut}, ${easing.bounce}, ${easing.bounce};
55
- }
56
-
57
- &.exit-active,
58
- &.exit-done {
40
+ &.exit-active {
41
+ transition-property: opacity;
59
42
  transition-timing-function: ${easing.easeOut};
60
43
  }
61
44
  }
62
45
  `);
46
+ export function useSweepingStyle({ orientation }) {
47
+ return useCss(() => css `
48
+ @layer reset {
49
+ &.appear,
50
+ &.appear-active,
51
+ &.enter-active,
52
+ &.exit,
53
+ &.exit-active,
54
+ &.exit-done {
55
+ overflow: hidden;
56
+ }
57
+
58
+ &.appear-active,
59
+ &.enter-active,
60
+ &.exit-active {
61
+ transition-property: opacity, width, height;
62
+ }
63
+ }
64
+ `, [orientation]);
65
+ }
63
66
  export function useGrowAndCollapseStyle({ orientation, _mode }) {
64
- return useCss(({ easing }) => {
65
- let transformMethod = _mode === 'grow'
66
- ? 'scale'
67
- : orientation === 'vertical'
68
- ? 'scaleY'
69
- : 'scaleX';
70
- return css `
71
- @layer reset {
72
- transition-property: opacity, transform;
73
- ${_mode === 'collapse' ? `transform-origin: ${orientation === 'vertical' ? 'top' : 'left'};` : ''}
74
- &,
75
- &.appear,
76
- &.enter {
77
- transform: ${transformMethod}(0);
78
- }
79
-
80
- &.appear-active,
81
- &.enter-active,
82
- &.enter-done,
83
- &.exit {
84
- transform: scale(1);
85
- }
67
+ let transformMethod = _mode === 'grow'
68
+ ? 'scale'
69
+ : orientation === 'vertical'
70
+ ? 'scaleY'
71
+ : 'scaleX';
72
+ return useCss(() => css `
73
+ @layer reset {
74
+ ${_mode === 'collapse' ? `transform-origin: ${orientation === 'vertical' ? 'top' : 'left'};` : ''}
86
75
 
87
- &.exit-active,
88
- &.exit-done {
89
- transform: ${transformMethod}(0);
90
- }
76
+ transition-property: opacity, transform;
91
77
 
92
- &.appear-active,
93
- &.enter-active {
94
- transition-timing-function: ${easing.easeOut}, ${easing.bounce};
95
- }
78
+ &.appear,
79
+ &.exit,
80
+ &.exit-done {
81
+ transform: ${transformMethod}(0);
82
+ }
96
83
 
97
- &.exit-active {
98
- transition-timing-function: ${easing.easeOut};
99
- }
84
+ &.appear-active,
85
+ &.enter,
86
+ &.enter-done {
87
+ transform: scale(1);
100
88
  }
101
- `;
102
- }, [orientation, _mode]);
89
+
90
+ &.appear-active,
91
+ &.enter-active,
92
+ &.exit-active {
93
+ transition-property: opacity, transform;
94
+ }
95
+ }
96
+ `, [orientation, _mode]);
103
97
  }
104
98
  export function useSlideStyle({ direction, offset }) {
105
- return useCss(({ easing }) => {
106
- const transformMethod = direction === 'up' || direction === 'down' ? 'translateY' : 'translateX';
107
- let offsetValue = typeof offset === 'number' ? `${offset}px` : offset;
108
- if (direction === 'down' || direction === 'right') {
109
- offsetValue = '-' + offsetValue;
110
- }
111
- return css `
112
- @layer reset {
113
- transition-property: opacity, transform;
114
-
115
- &,
116
- &.appear,
117
- &.enter {
118
- pointer-events: none;
119
- transform: ${transformMethod}(${offsetValue});
120
- }
121
-
122
- &.appear-active,
123
- &.enter-active,
124
- &.enter-done,
125
- &.exit {
126
- pointer-events: inherit;
127
- transform: translate(0);
128
- }
99
+ const transformMethod = direction === 'up' || direction === 'down' ? 'translateY' : 'translateX';
100
+ let offsetValue = typeof offset === 'number' ? `${offset}px` : offset;
101
+ if (direction === 'down' || direction === 'right') {
102
+ offsetValue = '-' + offsetValue;
103
+ }
104
+ return useCss(() => css `
105
+ @layer reset {
106
+ transition-property: opacity, transform;
129
107
 
130
- &.exit-active,
131
- &.exit-done {
132
- pointer-events: none;
133
- transform: ${transformMethod}(${offsetValue});
134
- }
108
+ &.appear,
109
+ &.exit,
110
+ &.exit-done {
111
+ pointer-events: none;
112
+ transform: ${transformMethod}(${offsetValue});
113
+ }
135
114
 
136
- &.appear-active,
137
- &.enter-active {
138
- transition-timing-function: ${easing.easeOut}, ${easing.bounce};
139
- }
115
+ &.appear-active,
116
+ &.enter,
117
+ &.enter-done {
118
+ pointer-events: inherit;
119
+ transform: translate(0);
120
+ }
140
121
 
141
- &.exit-active {
142
- transition-timing-function: ${easing.easeOut};
143
- }
122
+ &.appear-active,
123
+ &.enter-active,
124
+ &.exit-active {
125
+ transition-property: opacity, transform;
144
126
  }
145
- `;
146
- }, [direction, offset]);
127
+ }
128
+ `, [direction, offset]);
147
129
  }
@@ -21,7 +21,7 @@ export declare const CONTROL_COLUMN_KEY = "$control";
21
21
  export declare function useCurdColumns<R extends RowType, V extends Id = Id>({ columns, columnConfigurable }: Pick<CurdProps<R, FormValue, V>, 'columns' | 'columnConfigurable'>): {
22
22
  orderedColumns: any[];
23
23
  actualColumns: (symbol | ColumnType<R>)[];
24
- innerVisible: import("react").RefObject<Id[]>;
25
- setInnerVisible: import("react").Dispatch<import("react").SetStateAction<Id[]>>;
26
- setInnerOrder: import("react").Dispatch<import("react").SetStateAction<Id[]>>;
24
+ innerVisible: import("react").RefObject<Id[] | undefined>;
25
+ setInnerVisible: import("react").Dispatch<import("react").SetStateAction<Id[] | undefined>>;
26
+ setInnerOrder: import("react").Dispatch<import("react").SetStateAction<Id[] | undefined>>;
27
27
  };
@@ -63,24 +63,6 @@ export function useCurdColumns({ columns, columnConfigurable }) {
63
63
  columnConfigurable = {};
64
64
  }
65
65
  let { defaultVisible, visible, onVisibleChange, defaultOrder, order, onOrderChange } = columnConfigurable;
66
- if (!defaultVisible || !defaultOrder) {
67
- let hasControlColumn = false;
68
- const defaultKeys = columns?.flatMap((col) => {
69
- if (col.hideInTable) {
70
- return [];
71
- }
72
- if (col._key) {
73
- if (col._key === CONTROL_COLUMN_KEY) {
74
- hasControlColumn = true;
75
- }
76
- return col._key;
77
- }
78
- return [];
79
- }) || [];
80
- !hasControlColumn && defaultKeys.push(CONTROL_COLUMN_KEY);
81
- defaultVisible ||= defaultKeys;
82
- defaultOrder ||= defaultKeys;
83
- }
84
66
  const [innerOrder, setInnerOrder] = useControlled(defaultOrder, order, onOrderChange);
85
67
  const [innerVisible, setInnerVisible] = useControlled(defaultVisible, visible, onVisibleChange);
86
68
  const symbolBoundToNext = useRef(new WeakMap());
@@ -106,7 +88,7 @@ export function useCurdColumns({ columns, columnConfigurable }) {
106
88
  }, [columns]);
107
89
  // 只排序不筛选,用于设置项
108
90
  const orderedColumns = useMemo(() => {
109
- if (!innerOrder.current.length) {
91
+ if (!innerOrder.current?.length) {
110
92
  return pureColumns;
111
93
  }
112
94
  const set = new Set(pureColumns);
@@ -123,12 +105,12 @@ export function useCurdColumns({ columns, columnConfigurable }) {
123
105
  ];
124
106
  }, [innerOrder.current, pureColumns]);
125
107
  const visibleSet = useMemo(() => {
126
- return new Set(innerVisible.current);
108
+ return innerVisible.current && new Set(innerVisible.current);
127
109
  }, [innerVisible.current]);
128
110
  // 筛选表格上可见的列,并将symbol回填
129
111
  const actualColumns = useMemo(() => {
130
112
  return orderedColumns.flatMap(col => {
131
- if (!isUnset(col._key) && visibleSet.has(col._key)) {
113
+ if (!isUnset(col._key) && (!visibleSet || visibleSet.has(col._key))) {
132
114
  const symbolArr = symbolBoundToNext.current.get(col) || [];
133
115
  // 移除DataGrid不需要的属性
134
116
  const { filterInline, filter, form, ...c } = col;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canlooks/can-ui",
3
- "version": "0.0.167",
3
+ "version": "0.0.169",
4
4
  "author": "C.CanLiang <canlooks@gmail.com>",
5
5
  "description": "My ui framework",
6
6
  "license": "MIT",