@yuntijs/ui 1.0.0-beta.109 → 1.0.0-beta.110

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.
@@ -0,0 +1,7 @@
1
+ import { type FormItemProps } from 'antd';
2
+ import React from 'react';
3
+ import { FormCollapseListOperation } from './hooks';
4
+ export interface FormCollapseListFieldsWatcherProps extends Pick<FormCollapseListOperation, 'update'> {
5
+ name: FormItemProps['name'];
6
+ }
7
+ export declare const FormCollapseListFieldsWatcher: React.FC<FormCollapseListFieldsWatcherProps>;
@@ -0,0 +1,19 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import { Form } from 'antd';
3
+ import { memo, useEffect, useState } from 'react';
4
+ export var FormCollapseListFieldsWatcher = /*#__PURE__*/memo(function (_ref) {
5
+ var name = _ref.name,
6
+ update = _ref.update;
7
+ var rows = Form.useWatch(name);
8
+ var _useState = useState(0),
9
+ _useState2 = _slicedToArray(_useState, 2),
10
+ preRowsCount = _useState2[0],
11
+ setPreRowsCount = _useState2[1];
12
+ useEffect(function () {
13
+ if ((rows === null || rows === void 0 ? void 0 : rows.length) !== preRowsCount) {
14
+ update();
15
+ setPreRowsCount(rows === null || rows === void 0 ? void 0 : rows.length);
16
+ }
17
+ }, [preRowsCount, rows, update]);
18
+ return null;
19
+ });
@@ -1,11 +1,11 @@
1
- import { type FormListOperation } from 'antd';
1
+ import { type FormItemProps, type FormListOperation } from 'antd';
2
2
  import React from 'react';
3
3
  import type { FormCollapseListColumn } from '.';
4
4
  import { ListFieldValue } from './utils';
5
5
  export interface FormCollapseListOperation extends FormListOperation {
6
6
  update: () => void;
7
7
  }
8
- export declare const useFormCollapseListHooks: (name: string, childrenColumnName: string, columns: FormCollapseListColumn[]) => {
8
+ export declare const useFormCollapseListHooks: (name: FormItemProps['name'], childrenColumnName: string, columns: FormCollapseListColumn[]) => {
9
9
  values: ListFieldValue[];
10
10
  updateValues: () => void;
11
11
  expandedRowKeys: readonly React.Key[];
@@ -7,7 +7,7 @@ import { FieldPath } from './utils';
7
7
  interface FormCollapseListColumnItem extends Omit<FormItemProps, 'dependencies' | 'rules' | 'tooltip' | 'labelAlign' | 'labelCol' | 'colon' | 'children'> {
8
8
  render?: (fieldName: number, index: number, operation: FormCollapseListOperation,
9
9
  /** 当前 item 的 path */
10
- fieldPath: FieldPath) => React.ReactElement;
10
+ fieldPath: FieldPath) => React.ReactNode;
11
11
  rules?: FormItemProps['rules'] | ((parentFieldPath: FieldPath, index: number) => FormItemProps['rules']);
12
12
  dependencies?: FormItemProps['dependencies'] | ((parentFieldPath: FieldPath, index: number) => FormItemProps['dependencies']);
13
13
  }
@@ -2,6 +2,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
2
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
3
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
4
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
5
6
  var _excluded = ["collapsible", "extra", "expandIcon", "icon", "title", "variant", "defaultActive", "empty", "columns", "disabled", "readOnly", "addOneFieldDefault", "disableRemoveWhenOneField", "maxFileds", "name", "addParams", "className", "onRemove", "fieldRemoveButton", "style", "defaultExpandAllRows", "indentSize", "childrenColumnName", "rowHoverable"],
6
7
  _excluded2 = ["label", "name", "render", "dependencies", "rules", "align", "ellipsis", "fixed", "responsive", "shouldCellUpdate", "width", "className"],
7
8
  _excluded3 = ["key"];
@@ -15,11 +16,24 @@ import { Trash2 } from 'lucide-react';
15
16
  import React, { memo, useCallback, useEffect, useMemo, useRef } from 'react';
16
17
  import Typography from "../../Typography";
17
18
  import { CollapseGroup } from "../../CollapseGroup";
19
+ import { FormCollapseListFieldsWatcher } from "./FieldsWatcher";
18
20
  import { useFormCollapseListHooks } from "./hooks";
19
21
  import { useStyles } from "./style";
20
22
  import { FIELD_KEY_PATH, toRowKey } from "./utils";
21
23
  import { jsx as _jsx } from "react/jsx-runtime";
24
+ import { jsxs as _jsxs } from "react/jsx-runtime";
22
25
  var Text = Typography.Text;
26
+ var FieldText = function FieldText(props) {
27
+ var id = props.id,
28
+ value = props.value;
29
+ if (_typeof(value) === 'object') {
30
+ console.warn("".concat(id, " => ").concat(value));
31
+ return '-';
32
+ }
33
+ return /*#__PURE__*/_jsx("span", {
34
+ children: value
35
+ });
36
+ };
23
37
  export var FormCollapseList = /*#__PURE__*/memo(function (_ref) {
24
38
  var collapsible = _ref.collapsible,
25
39
  extra = _ref.extra,
@@ -70,6 +84,11 @@ export var FormCollapseList = /*#__PURE__*/memo(function (_ref) {
70
84
  return fieldValuesToDataSource(values);
71
85
  }, [fieldValuesToDataSource, values]),
72
86
  dataSource = _useMemo.dataSource;
87
+ var isTreeMode = useMemo(function () {
88
+ return dataSource === null || dataSource === void 0 ? void 0 : dataSource.some(function (d) {
89
+ return d[childrenColumnName];
90
+ });
91
+ }, [childrenColumnName, dataSource]);
73
92
  // 设置初始值以及在 readOnly 变化时更新 values
74
93
  useEffect(function () {
75
94
  updateValues();
@@ -108,7 +127,7 @@ export var FormCollapseList = /*#__PURE__*/memo(function (_ref) {
108
127
  }, 200);
109
128
  }
110
129
  }, [addOneFieldDefault, getAddParams, form, name, firstColumnFormItemName, updateValues]);
111
- return /*#__PURE__*/_jsx(CollapseGroup, {
130
+ return /*#__PURE__*/_jsxs(CollapseGroup, {
112
131
  extra: extra === undefined ? name && !readOnly && /*#__PURE__*/_jsx(Tooltip, {
113
132
  title: maxFileds && "\u6700\u591A\u6DFB\u52A0 ".concat(maxFileds, " \u9879"),
114
133
  children: /*#__PURE__*/_jsx(Button, {
@@ -135,7 +154,10 @@ export var FormCollapseList = /*#__PURE__*/memo(function (_ref) {
135
154
  variant: variant,
136
155
  defaultActive: defaultActive,
137
156
  style: style,
138
- children: name ? /*#__PURE__*/_jsx(Form.List, _objectSpread(_objectSpread({
157
+ children: [!isTreeMode && /*#__PURE__*/_jsx(FormCollapseListFieldsWatcher, {
158
+ name: name,
159
+ update: updateValues
160
+ }), name ? /*#__PURE__*/_jsx(Form.List, _objectSpread(_objectSpread({
139
161
  name: name
140
162
  }, formListProps), {}, {
141
163
  children: function children(fields, operation) {
@@ -181,18 +203,18 @@ export var FormCollapseList = /*#__PURE__*/memo(function (_ref) {
181
203
  var key = field.key,
182
204
  restField = _objectWithoutProperties(field, _excluded3);
183
205
  var children = fieldRender === null || fieldRender === void 0 ? void 0 : fieldRender(fieldName !== null && fieldName !== void 0 ? fieldName : fieldKeyPath.at(-1), index, getFormListOperation(operation, record), fieldPath);
184
- if (!children && !itemProps.noStyle) {
206
+ if (!itemName) {
185
207
  return /*#__PURE__*/_jsx(Flex, {
186
208
  align: "center",
187
209
  className: cx(styles.noFormItem, className),
188
- children: "\u65E0\u9700\u8BBE\u7F6E"
210
+ children: children
189
211
  });
190
212
  }
191
- if (!itemName) {
213
+ if (children !== undefined && _typeof(children) !== 'object') {
192
214
  return /*#__PURE__*/_jsx(Flex, {
193
215
  align: "center",
194
216
  className: cx(styles.noFormItem, className),
195
- children: children
217
+ children: children.toString()
196
218
  });
197
219
  }
198
220
  var chidrenProps = {};
@@ -218,7 +240,7 @@ export var FormCollapseList = /*#__PURE__*/memo(function (_ref) {
218
240
  ,
219
241
  rules: typeof rules === 'function' ? rules(parentFieldPath, index) : rules
220
242
  }, itemProps), {}, {
221
- children: children && /*#__PURE__*/React.cloneElement(children, chidrenProps)
243
+ children: children ? ( /*#__PURE__*/React.cloneElement(children, chidrenProps)) : /*#__PURE__*/_jsx(FieldText, {})
222
244
  }), key);
223
245
  }
224
246
  };
@@ -286,6 +308,6 @@ export var FormCollapseList = /*#__PURE__*/memo(function (_ref) {
286
308
  })) : /*#__PURE__*/_jsx("div", {
287
309
  className: styles.empty,
288
310
  children: empty
289
- })
311
+ })]
290
312
  });
291
313
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuntijs/ui",
3
- "version": "1.0.0-beta.109",
3
+ "version": "1.0.0-beta.110",
4
4
  "description": "☁️ Yunti UI - an open-source UI component library for building Cloud Native web apps",
5
5
  "keywords": [
6
6
  "yuntijs",