ebaoferc 0.1.9 → 0.1.11

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.
@@ -1,7 +1,7 @@
1
1
  import { ColProps, RowProps } from 'antd';
2
2
  import { PropsWithChildren } from 'react';
3
3
  export declare const Gutter: [number, number];
4
- export default function (props: PropsWithChildren<{
4
+ export default function FlexRowCol(props: PropsWithChildren<{
5
5
  colProps?: ColProps;
6
6
  width?: number;
7
7
  maxColCount?: number;
@@ -1,5 +1,5 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- var _excluded = ["colProps", "width", "maxColCount", "gutter", "collapsedLineCount", "collapsed", "lineCountChange"];
2
+ var _excluded = ["colProps", "width", "maxColCount", "gutter", "collapsedLineCount", "collapsed", "lineCountChange", "children"];
3
3
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
4
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
5
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
@@ -9,11 +9,12 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
9
9
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
10
10
  import { useSize } from 'ahooks';
11
11
  import { Col, Row } from 'antd';
12
- import React, { Children, isValidElement, useEffect, useRef } from 'react';
12
+ import React, { Children, isValidElement, useEffect, useMemo, useRef } from 'react';
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
14
  export var Gutter = [24, 0];
15
- export default function (props) {
16
- var _Children$map;
15
+
16
+ // FlexRowCol 组件用于创建一个灵活的行列布局
17
+ export default function FlexRowCol(props) {
17
18
  var _props$colProps = props.colProps,
18
19
  colProps = _props$colProps === void 0 ? {
19
20
  span: 12
@@ -26,61 +27,65 @@ export default function (props) {
26
27
  _props$collapsedLineC = props.collapsedLineCount,
27
28
  collapsedLineCount = _props$collapsedLineC === void 0 ? Number.POSITIVE_INFINITY : _props$collapsedLineC,
28
29
  _props$collapsed = props.collapsed,
29
- collapsed = _props$collapsed === void 0 ? false : _props$collapsed,
30
+ collapsed = _props$collapsed === void 0 ? true : _props$collapsed,
30
31
  lineCountChange = props.lineCountChange,
32
+ children = props.children,
31
33
  rest = _objectWithoutProperties(props, _excluded);
34
+
35
+ // 使用 ref 和 useSize 钩子获取容器宽度
32
36
  var ref = useRef(null);
33
37
  var size = useSize(ref);
38
+ // 使用 useMemo 计算布局,避免不必要的重复计算
39
+ var _useMemo = useMemo(function () {
40
+ var gapX = (gutter === null || gutter === void 0 ? void 0 : gutter[0]) || 0;
41
+ var itemWidth = width + gapX;
42
+ var containerWidth = (size === null || size === void 0 ? void 0 : size.width) || 0;
34
43
 
35
- // 横向间隔
36
- var gapX = (gutter === null || gutter === void 0 ? void 0 : gutter[0]) || 0;
37
-
38
- // 包含间隔的宽度
39
- var itemWidth = width + gapX;
44
+ // 计算每行可容纳的列数
45
+ var preColCount = Math.floor(containerWidth / itemWidth);
46
+ var colCount = maxColCount && preColCount > maxColCount ? maxColCount : preColCount;
40
47
 
41
- // 预估一行能放下的列数
42
- var preColCount = Math.floor(((size === null || size === void 0 ? void 0 : size.width) || 0) / itemWidth);
43
- // 实际一行放的列数
44
- var colCount = maxColCount && preColCount > maxColCount ? maxColCount : preColCount;
48
+ // 计算每列的 span 值
49
+ var span = Math.floor(24 / colCount);
50
+ var _colProps = _objectSpread(_objectSpread({}, colProps), {}, {
51
+ span: span > 24 ? 24 : span
52
+ });
53
+ var count = 0;
54
+ // 处理子元素,计算 hidden 属性
55
+ var processedChildren = Children.toArray(children).filter(function (child) {
56
+ return /*#__PURE__*/isValidElement(child) && !child.props.hidden;
57
+ }).map(function (child, index) {
58
+ if (! /*#__PURE__*/isValidElement(child)) return child;
59
+ count++;
60
+ var childColProps = child.props.colProps || _colProps;
61
+ var hidden = collapsed && index >= colCount * collapsedLineCount;
62
+ return /*#__PURE__*/_jsx(Col, _objectSpread(_objectSpread({}, childColProps), {}, {
63
+ children: /*#__PURE__*/React.cloneElement(child, {
64
+ hidden: hidden
65
+ })
66
+ }), child.key || count);
67
+ });
45
68
 
46
- // 展示的个数
47
- var renderItemCount = ((_Children$map = Children.map(props.children, function (child) {
48
- if ( /*#__PURE__*/isValidElement(child) && !child.props.hidden) {
49
- return child;
50
- }
51
- })) === null || _Children$map === void 0 ? void 0 : _Children$map.length) || 0;
52
-
53
- // 行数
54
- var lineCount = colCount && Math.ceil(renderItemCount / colCount);
69
+ // 计算行数
70
+ var lineCount = Math.ceil(count / (colCount || 1));
71
+ return {
72
+ lineCount: lineCount,
73
+ processedChildren: processedChildren
74
+ };
75
+ }, [size, width, maxColCount, gutter, collapsedLineCount, collapsed, colProps, children]),
76
+ lineCount = _useMemo.lineCount,
77
+ processedChildren = _useMemo.processedChildren;
55
78
 
56
- // 根据一行能放下的个数,计算每个子元素的宽度
57
- var span = Math.floor(24 / colCount);
58
- var count = 0;
59
- var _colProps = _objectSpread(_objectSpread({}, colProps), {}, {
60
- span: span > 24 ? 24 : span
61
- });
79
+ // 当行数变化时,调用 lineCountChange 回调
62
80
  useEffect(function () {
63
- lineCountChange === null || lineCountChange === void 0 || lineCountChange(lineCount);
64
- }, [lineCount]);
81
+ if (size !== null && size !== void 0 && size.width) {
82
+ lineCountChange === null || lineCountChange === void 0 || lineCountChange(lineCount);
83
+ }
84
+ }, [lineCount, lineCountChange, size === null || size === void 0 ? void 0 : size.width]);
65
85
  return /*#__PURE__*/_jsx(Row, _objectSpread(_objectSpread({
66
86
  gutter: gutter
67
87
  }, rest), {}, {
68
88
  ref: ref,
69
- children: Children.map(props.children, function (child) {
70
- if (! /*#__PURE__*/isValidElement(child)) {
71
- return child;
72
- }
73
- if (child.props.hidden) {
74
- return child;
75
- }
76
- var childColProps = child.props.colProps || _colProps;
77
- count++;
78
- var hidden = count > colCount * collapsedLineCount && collapsed;
79
- return /*#__PURE__*/_jsx(Col, _objectSpread(_objectSpread({}, childColProps), {}, {
80
- children: /*#__PURE__*/React.cloneElement(child, _objectSpread(_objectSpread({}, child.props), {}, {
81
- hidden: hidden
82
- }))
83
- }));
84
- })
89
+ children: size ? processedChildren : null
85
90
  }));
86
91
  }
@@ -1,9 +1,9 @@
1
- .custom-filter-card-container-wrapper {
2
- .ant-pro-card-body {
3
- padding-bottom: 0 !important;
4
- }
5
-
6
- .ant-form-item {
7
- margin-bottom: 16px;
8
- }
9
- }
1
+ .custom-filter-card-container-wrapper {
2
+ .ant-pro-card-body {
3
+ padding-bottom: 0 !important;
4
+ }
5
+
6
+ .ant-form-item {
7
+ margin-bottom: 16px;
8
+ }
9
+ }
@@ -17,7 +17,7 @@ import { DownOutlined } from '@ant-design/icons';
17
17
  import { ProForm } from '@ant-design/pro-components';
18
18
  import { Button, Form } from 'antd';
19
19
  import classNames from 'classnames';
20
- import React from 'react';
20
+ import React, { useCallback, useState } from 'react';
21
21
  import FlexRowCol from "../FlexRowCol";
22
22
  import "./index.less";
23
23
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -35,25 +35,28 @@ export default function StyledQueryFilter(props) {
35
35
  var _Form$useForm = Form.useForm(form),
36
36
  _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
37
37
  _form = _Form$useForm2[0];
38
- var _React$useState = React.useState(false),
39
- _React$useState2 = _slicedToArray(_React$useState, 2),
40
- collapsed = _React$useState2[0],
41
- setCollapsed = _React$useState2[1];
42
- var _React$useState3 = React.useState(1),
43
- _React$useState4 = _slicedToArray(_React$useState3, 2),
44
- lineCount = _React$useState4[0],
45
- setLineCount = _React$useState4[1];
38
+ var _useState = useState(false),
39
+ _useState2 = _slicedToArray(_useState, 2),
40
+ collapsed = _useState2[0],
41
+ setCollapsed = _useState2[1];
42
+ var _useState3 = useState(false),
43
+ _useState4 = _slicedToArray(_useState3, 2),
44
+ showExpandButton = _useState4[0],
45
+ setShowExpandButton = _useState4[1];
46
46
  if (labelWidth) {
47
47
  rest.labelCol = {
48
48
  flex: "0 0 ".concat(labelWidth, "px")
49
49
  };
50
50
  }
51
- function reset(e) {
51
+ var reset = function reset(e) {
52
52
  _form.resetFields();
53
53
  if (onReset) {
54
- onReset(e);
54
+ onReset(e); // 类型断言,因为 onReset 可能期望 FormEvent
55
55
  }
56
- }
56
+ };
57
+ var handleLineCountChange = useCallback(function (count) {
58
+ setShowExpandButton(count > collapsedLineCount);
59
+ }, [collapsedLineCount]);
57
60
  return /*#__PURE__*/_jsxs("div", {
58
61
  className: "custom-styled-query-filter",
59
62
  children: [/*#__PURE__*/_jsx(ProForm, _objectSpread(_objectSpread({
@@ -66,14 +69,7 @@ export default function StyledQueryFilter(props) {
66
69
  children: /*#__PURE__*/_jsx(FlexRowCol, {
67
70
  collapsed: collapsed,
68
71
  collapsedLineCount: collapsedLineCount,
69
- lineCountChange: function lineCountChange(lineCount) {
70
- setLineCount(lineCount);
71
- if (lineCount > collapsedLineCount) {
72
- setCollapsed(true);
73
- } else {
74
- setCollapsed(false);
75
- }
76
- },
72
+ lineCountChange: handleLineCountChange,
77
73
  width: itemWith,
78
74
  children: children
79
75
  })
@@ -91,25 +87,13 @@ export default function StyledQueryFilter(props) {
91
87
  },
92
88
  children: "\u67E5\u8BE2"
93
89
  })]
94
- }), lineCount > collapsedLineCount && /*#__PURE__*/_jsx("div", {
95
- children: collapsed ? /*#__PURE__*/_jsxs(Button, {
96
- type: "link",
97
- onClick: function onClick() {
98
- return setCollapsed(false);
99
- },
100
- children: ["\u5C55\u5F00", /*#__PURE__*/_jsx(DownOutlined, {
101
- style: {
102
- marginInlineStart: '0.5em',
103
- transition: '0.3s all',
104
- transform: "rotate(".concat(collapsed ? 0 : 0.5, "turn)")
105
- }
106
- })]
107
- }) : /*#__PURE__*/_jsxs(Button, {
90
+ }), showExpandButton && /*#__PURE__*/_jsx("div", {
91
+ children: /*#__PURE__*/_jsxs(Button, {
108
92
  type: "link",
109
93
  onClick: function onClick() {
110
- return setCollapsed(true);
94
+ return setCollapsed(!collapsed);
111
95
  },
112
- children: ["\u6536\u8D77", /*#__PURE__*/_jsx(DownOutlined, {
96
+ children: [collapsed ? '展开' : '收起', /*#__PURE__*/_jsx(DownOutlined, {
113
97
  style: {
114
98
  marginInlineStart: '0.5em',
115
99
  transition: '0.3s all',
@@ -1,34 +1,34 @@
1
- .custom-styled-query-filter {
2
- display: flex;
3
- justify-content: space-between;
4
- column-gap: 16px;
5
-
6
- &__form {
7
- flex: 1;
8
- }
9
-
10
- &__right {
11
- display: flex;
12
- flex-direction: column;
13
- justify-content: space-between;
14
- align-items: flex-end;
15
-
16
- .ant-btn-link {
17
- padding-right: 0;
18
- margin-bottom: 28px;
19
- }
20
- }
21
-
22
- &__submitter {
23
- display: flex;
24
- column-gap: 8px;
25
- }
26
-
27
- .ant-form-item-no-colon {
28
- margin-right: 10px;
29
-
30
- &::after {
31
- display: none;
32
- }
33
- }
34
- }
1
+ .custom-styled-query-filter {
2
+ display: flex;
3
+ justify-content: space-between;
4
+ column-gap: 16px;
5
+
6
+ &__form {
7
+ flex: 1;
8
+ }
9
+
10
+ &__right {
11
+ display: flex;
12
+ flex-direction: column;
13
+ justify-content: space-between;
14
+ align-items: flex-end;
15
+
16
+ .ant-btn-link {
17
+ padding-right: 0;
18
+ margin-bottom: 28px;
19
+ }
20
+ }
21
+
22
+ &__submitter {
23
+ display: flex;
24
+ column-gap: 8px;
25
+ }
26
+
27
+ .ant-form-item-no-colon {
28
+ margin-right: 10px;
29
+
30
+ &::after {
31
+ display: none;
32
+ }
33
+ }
34
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ebaoferc",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",