@canlooks/can-ui 0.0.12 → 0.0.14

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.
@@ -23,10 +23,10 @@ exports.Flex = (0, react_1.forwardRef)(({ inline, direction = 'row', wrap, gap =
23
23
  });
24
24
  });
25
25
  };
26
- return ((0, jsx_runtime_1.jsx)(transportStyle_1.TransportStyle, { ...props, ref: ref, className: (0, utils_1.classnames)(flex_style_1.classes.root, props.className), style: {
26
+ return ((0, jsx_runtime_1.jsx)(transportStyle_1.TransportStyle, { ...props, ref: ref, className: (0, utils_1.classnames)(flex_style_1.classes.root, props.className), style: (0, utils_1.filterProperties)({
27
27
  display: inline ? 'inline-flex' : 'flex',
28
28
  flexDirection: direction,
29
29
  flexWrap: wrap, columnGap, rowGap, gap,
30
30
  ...props.style
31
- }, children: renderChildren() }));
31
+ }), children: renderChildren() }));
32
32
  });
@@ -3,13 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TransportStyle = void 0;
4
4
  const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
5
  const react_1 = require("react");
6
+ const utils_1 = require("../../utils");
6
7
  exports.TransportStyle = (0, react_1.forwardRef)(({ alignItems, justifyContent, alignSelf, justifySelf, flex, width, minWidth, maxWidth, height, minHeight, maxHeight, lineHeight, paddingTop, paddingRight, paddingBottom, paddingLeft, padding, marginTop, marginRight, marginBottom, marginLeft, margin, overflowX, overflowY, overflow, ...props }, ref) => {
7
- return ((0, jsx_runtime_1.jsx)("div", { ...props, ref: ref, style: {
8
+ return ((0, jsx_runtime_1.jsx)("div", { ...props, ref: ref, style: (0, utils_1.filterProperties)({
8
9
  alignItems, justifyContent, alignSelf, justifySelf, flex,
9
10
  width, minWidth, maxWidth, height, minHeight, maxHeight, lineHeight,
10
- paddingTop, paddingRight, paddingBottom, paddingLeft, padding,
11
- marginTop, marginRight, marginBottom, marginLeft, margin,
12
- overflowX, overflowY, overflow,
11
+ padding, paddingTop, paddingRight, paddingBottom, paddingLeft,
12
+ margin, marginTop, marginRight, marginBottom, marginLeft,
13
+ overflow, overflowX, overflowY,
13
14
  ...props.style
14
- } }));
15
+ }) }));
15
16
  });
@@ -6,6 +6,7 @@ const react_1 = require("react");
6
6
  const waterfall_style_1 = require("./waterfall.style");
7
7
  const utils_1 = require("../../utils");
8
8
  const transportStyle_1 = require("../transportStyle");
9
+ const react_2 = require("@emotion/react");
9
10
  exports.Waterfall = (0, react_1.forwardRef)(({ columnCount = { xs: 4 }, gap = { xs: 0 }, columnGap, rowGap, ...props }, ref) => {
10
11
  columnCount = (0, utils_1.responsiveValue)(columnCount);
11
12
  gap = (0, utils_1.responsiveValue)(gap);
@@ -16,24 +17,35 @@ exports.Waterfall = (0, react_1.forwardRef)(({ columnCount = { xs: 4 }, gap = {
16
17
  items.current = [];
17
18
  const [orders, setOrders] = (0, react_1.useState)();
18
19
  const [containerHeight, setContainerHeight] = (0, react_1.useState)();
20
+ const [maxItemCount, setMaxItemCount] = (0, react_1.useState)();
19
21
  (0, react_1.useEffect)(() => {
22
+ const elements = items.current;
20
23
  const resizeObserver = new ResizeObserver(() => {
21
24
  const heights = Array(columnCountNum).fill(0);
25
+ const counts = Array(columnCountNum).fill(0);
22
26
  const newOrders = [];
23
- items.current.forEach(item => {
27
+ for (let i = 0, { length } = elements; i < length; i++) {
24
28
  const order = heights.indexOf(Math.min(...heights));
25
29
  newOrders.push(order);
26
- heights[order] += item.offsetHeight;
27
- });
30
+ heights[order] += elements[i].offsetHeight;
31
+ counts[order]++;
32
+ }
28
33
  setOrders(newOrders);
29
- setContainerHeight(Math.max(...heights));
30
- });
31
- items.current.forEach(item => {
32
- resizeObserver.observe(item);
34
+ const maxHeight = Math.max(...heights);
35
+ setContainerHeight(maxHeight);
36
+ setMaxItemCount(counts[heights.indexOf(maxHeight)]);
33
37
  });
38
+ for (let i = 0, { length } = elements; i < length; i++) {
39
+ resizeObserver.observe(elements[i]);
40
+ }
34
41
  return () => {
35
42
  resizeObserver.disconnect();
36
43
  };
37
44
  }, [props.children, columnCountNum]);
38
- return ((0, jsx_runtime_1.jsx)(transportStyle_1.TransportStyle, { ...props, ref: ref, css: (0, waterfall_style_1.useStyle)({ columnCount, columnGap, rowGap }), className: (0, utils_1.classnames)(waterfall_style_1.classes.root, props.className), style: containerHeight ? { height: containerHeight } : void 0, children: react_1.Children.map(props.children, (child, i) => (0, jsx_runtime_1.jsx)("div", { ref: r => r && items.current.push(r), className: waterfall_style_1.classes.item, style: { order: orders?.[i] }, children: child }, (0, react_1.isValidElement)(child) ? child.key ?? i : i)) }));
45
+ return ((0, jsx_runtime_1.jsx)(transportStyle_1.TransportStyle, { ...props, ref: ref, css: [
46
+ (0, waterfall_style_1.useStyle)({ columnCount, columnGap, rowGap }),
47
+ (0, react_2.css) `
48
+ height: calc(${containerHeight}px + var(--waterfall-row-gap) * ${maxItemCount});
49
+ `
50
+ ], className: (0, utils_1.classnames)(waterfall_style_1.classes.root, props.className), children: react_1.Children.map(props.children, (child, i) => (0, jsx_runtime_1.jsx)("div", { ref: r => r && items.current.push(r), className: waterfall_style_1.classes.item, style: { order: orders?.[i] }, children: child }, (0, react_1.isValidElement)(child) ? child.key ?? i : i)) }));
39
51
  });
@@ -19,10 +19,12 @@ function useStyle({ columnCount, columnGap, rowGap }) {
19
19
  flex-direction: column;
20
20
  flex-wrap: wrap;
21
21
  column-gap: var(--waterfall-column-gap);
22
+ row-gap: var(--waterfall-row-gap);
23
+ overflow: hidden;
22
24
 
23
25
  .${exports.classes.item} {
24
26
  width: calc((100% - var(--waterfall-column-gap) * (var(--waterfall-columnCount) - 1)) / var(--waterfall-columnCount));
25
- padding-bottom: var(--waterfall-row-gap);
27
+ //padding-bottom: var(--waterfall-row-gap);
26
28
 
27
29
  > img {
28
30
  width: 100%;
@@ -121,3 +121,9 @@ export declare function range(value: number, min?: number, max?: number): number
121
121
  * @param separator
122
122
  */
123
123
  export declare function queryDeep<T extends object = any, U = any>(obj: T, keyPath: Id | Id[], setValue?: (oldValue: any) => U, separator?: string): U;
124
+ /**
125
+ * 过滤对象中值为undefined属性
126
+ * @param obj
127
+ * @param undefinedValue 可传入该值,用于替换undefined以删除其他属性
128
+ */
129
+ export declare function filterProperties<T extends Record<string, any>>(obj: T, undefinedValue?: any): T;
@@ -20,6 +20,7 @@ exports.isChildOf = isChildOf;
20
20
  exports.fineParent = fineParent;
21
21
  exports.range = range;
22
22
  exports.queryDeep = queryDeep;
23
+ exports.filterProperties = filterProperties;
23
24
  /**
24
25
  * 生成最简易的随机ID
25
26
  * @param namespace
@@ -302,3 +303,16 @@ function queryDeep(obj, keyPath, setValue, separator = '.') {
302
303
  }
303
304
  return obj[keyPath];
304
305
  }
306
+ /**
307
+ * 过滤对象中值为undefined属性
308
+ * @param obj
309
+ * @param undefinedValue 可传入该值,用于替换undefined以删除其他属性
310
+ */
311
+ function filterProperties(obj, undefinedValue) {
312
+ for (const k in obj) {
313
+ if (obj[k] === undefinedValue) {
314
+ delete obj[k];
315
+ }
316
+ }
317
+ return obj;
318
+ }
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
2
2
  import { Children, cloneElement, forwardRef, isValidElement } from 'react';
3
3
  import { classes } from './flex.style';
4
- import { classnames } from '../../utils';
4
+ import { classnames, filterProperties } from '../../utils';
5
5
  import { TransportStyle } from '../transportStyle';
6
6
  export const Flex = forwardRef(({ inline, direction = 'row', wrap, gap = 0, columnGap, rowGap, compact, ...props }, ref) => {
7
7
  const renderChildren = () => {
@@ -20,10 +20,10 @@ export const Flex = forwardRef(({ inline, direction = 'row', wrap, gap = 0, colu
20
20
  });
21
21
  });
22
22
  };
23
- return (_jsx(TransportStyle, { ...props, ref: ref, className: classnames(classes.root, props.className), style: {
23
+ return (_jsx(TransportStyle, { ...props, ref: ref, className: classnames(classes.root, props.className), style: filterProperties({
24
24
  display: inline ? 'inline-flex' : 'flex',
25
25
  flexDirection: direction,
26
26
  flexWrap: wrap, columnGap, rowGap, gap,
27
27
  ...props.style
28
- }, children: renderChildren() }));
28
+ }), children: renderChildren() }));
29
29
  });
@@ -1,12 +1,13 @@
1
1
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
2
2
  import { forwardRef } from 'react';
3
+ import { filterProperties } from '../../utils';
3
4
  export const TransportStyle = forwardRef(({ alignItems, justifyContent, alignSelf, justifySelf, flex, width, minWidth, maxWidth, height, minHeight, maxHeight, lineHeight, paddingTop, paddingRight, paddingBottom, paddingLeft, padding, marginTop, marginRight, marginBottom, marginLeft, margin, overflowX, overflowY, overflow, ...props }, ref) => {
4
- return (_jsx("div", { ...props, ref: ref, style: {
5
+ return (_jsx("div", { ...props, ref: ref, style: filterProperties({
5
6
  alignItems, justifyContent, alignSelf, justifySelf, flex,
6
7
  width, minWidth, maxWidth, height, minHeight, maxHeight, lineHeight,
7
- paddingTop, paddingRight, paddingBottom, paddingLeft, padding,
8
- marginTop, marginRight, marginBottom, marginLeft, margin,
9
- overflowX, overflowY, overflow,
8
+ padding, paddingTop, paddingRight, paddingBottom, paddingLeft,
9
+ margin, marginTop, marginRight, marginBottom, marginLeft,
10
+ overflow, overflowX, overflowY,
10
11
  ...props.style
11
- } }));
12
+ }) }));
12
13
  });
@@ -3,6 +3,7 @@ import { Children, forwardRef, isValidElement, useEffect, useRef, useState } fro
3
3
  import { classes, useStyle } from './waterfall.style';
4
4
  import { classnames, responsiveValue, useResponsiveValue } from '../../utils';
5
5
  import { TransportStyle } from '../transportStyle';
6
+ import { css } from '@emotion/react';
6
7
  export const Waterfall = forwardRef(({ columnCount = { xs: 4 }, gap = { xs: 0 }, columnGap, rowGap, ...props }, ref) => {
7
8
  columnCount = responsiveValue(columnCount);
8
9
  gap = responsiveValue(gap);
@@ -13,24 +14,35 @@ export const Waterfall = forwardRef(({ columnCount = { xs: 4 }, gap = { xs: 0 },
13
14
  items.current = [];
14
15
  const [orders, setOrders] = useState();
15
16
  const [containerHeight, setContainerHeight] = useState();
17
+ const [maxItemCount, setMaxItemCount] = useState();
16
18
  useEffect(() => {
19
+ const elements = items.current;
17
20
  const resizeObserver = new ResizeObserver(() => {
18
21
  const heights = Array(columnCountNum).fill(0);
22
+ const counts = Array(columnCountNum).fill(0);
19
23
  const newOrders = [];
20
- items.current.forEach(item => {
24
+ for (let i = 0, { length } = elements; i < length; i++) {
21
25
  const order = heights.indexOf(Math.min(...heights));
22
26
  newOrders.push(order);
23
- heights[order] += item.offsetHeight;
24
- });
27
+ heights[order] += elements[i].offsetHeight;
28
+ counts[order]++;
29
+ }
25
30
  setOrders(newOrders);
26
- setContainerHeight(Math.max(...heights));
27
- });
28
- items.current.forEach(item => {
29
- resizeObserver.observe(item);
31
+ const maxHeight = Math.max(...heights);
32
+ setContainerHeight(maxHeight);
33
+ setMaxItemCount(counts[heights.indexOf(maxHeight)]);
30
34
  });
35
+ for (let i = 0, { length } = elements; i < length; i++) {
36
+ resizeObserver.observe(elements[i]);
37
+ }
31
38
  return () => {
32
39
  resizeObserver.disconnect();
33
40
  };
34
41
  }, [props.children, columnCountNum]);
35
- return (_jsx(TransportStyle, { ...props, ref: ref, css: useStyle({ columnCount, columnGap, rowGap }), className: classnames(classes.root, props.className), style: containerHeight ? { height: containerHeight } : void 0, children: Children.map(props.children, (child, i) => _jsx("div", { ref: r => r && items.current.push(r), className: classes.item, style: { order: orders?.[i] }, children: child }, isValidElement(child) ? child.key ?? i : i)) }));
42
+ return (_jsx(TransportStyle, { ...props, ref: ref, css: [
43
+ useStyle({ columnCount, columnGap, rowGap }),
44
+ css `
45
+ height: calc(${containerHeight}px + var(--waterfall-row-gap) * ${maxItemCount});
46
+ `
47
+ ], className: classnames(classes.root, props.className), children: Children.map(props.children, (child, i) => _jsx("div", { ref: r => r && items.current.push(r), className: classes.item, style: { order: orders?.[i] }, children: child }, isValidElement(child) ? child.key ?? i : i)) }));
36
48
  });
@@ -15,10 +15,12 @@ export function useStyle({ columnCount, columnGap, rowGap }) {
15
15
  flex-direction: column;
16
16
  flex-wrap: wrap;
17
17
  column-gap: var(--waterfall-column-gap);
18
+ row-gap: var(--waterfall-row-gap);
19
+ overflow: hidden;
18
20
 
19
21
  .${classes.item} {
20
22
  width: calc((100% - var(--waterfall-column-gap) * (var(--waterfall-columnCount) - 1)) / var(--waterfall-columnCount));
21
- padding-bottom: var(--waterfall-row-gap);
23
+ //padding-bottom: var(--waterfall-row-gap);
22
24
 
23
25
  > img {
24
26
  width: 100%;
@@ -121,3 +121,9 @@ export declare function range(value: number, min?: number, max?: number): number
121
121
  * @param separator
122
122
  */
123
123
  export declare function queryDeep<T extends object = any, U = any>(obj: T, keyPath: Id | Id[], setValue?: (oldValue: any) => U, separator?: string): U;
124
+ /**
125
+ * 过滤对象中值为undefined属性
126
+ * @param obj
127
+ * @param undefinedValue 可传入该值,用于替换undefined以删除其他属性
128
+ */
129
+ export declare function filterProperties<T extends Record<string, any>>(obj: T, undefinedValue?: any): T;
@@ -280,3 +280,16 @@ export function queryDeep(obj, keyPath, setValue, separator = '.') {
280
280
  }
281
281
  return obj[keyPath];
282
282
  }
283
+ /**
284
+ * 过滤对象中值为undefined属性
285
+ * @param obj
286
+ * @param undefinedValue 可传入该值,用于替换undefined以删除其他属性
287
+ */
288
+ export function filterProperties(obj, undefinedValue) {
289
+ for (const k in obj) {
290
+ if (obj[k] === undefinedValue) {
291
+ delete obj[k];
292
+ }
293
+ }
294
+ return obj;
295
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canlooks/can-ui",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "author": "C.CanLiang <canlooks@gmail.com>",
5
5
  "description": "My ui framework",
6
6
  "license": "MIT",