@yuntijs/ui 1.0.0-beta.100 → 1.0.0-beta.102
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.
- package/es/Form/collapse-list/hooks.d.ts +15 -0
- package/es/Form/collapse-list/hooks.js +135 -0
- package/es/Form/collapse-list/index.d.ts +15 -4
- package/es/Form/collapse-list/index.js +96 -36
- package/es/Form/collapse-list/style.js +1 -1
- package/es/Form/collapse-list/utils.d.ts +10 -0
- package/es/Form/collapse-list/utils.js +4 -0
- package/es/JsonViewer/index.d.ts +1 -0
- package/es/JsonViewer/index.js +1 -0
- package/package.json +4 -4
- package/umd/index.min.js +1 -1
- package/umd/index.min.js.map +1 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type FormListOperation } from 'antd';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { FormCollapseListColumn } from '.';
|
|
4
|
+
import { ListFieldValue } from './utils';
|
|
5
|
+
export declare const useFormCollapseListHooks: (name: string, childrenColumnName: string, columns: FormCollapseListColumn[]) => {
|
|
6
|
+
expandedRowKeys: readonly React.Key[];
|
|
7
|
+
setExpandedRowKeys: React.Dispatch<React.SetStateAction<readonly React.Key[]>>;
|
|
8
|
+
fieldsToDataSource: (fields: [ListFieldValue]) => {
|
|
9
|
+
dataSource: ListFieldValue[];
|
|
10
|
+
allExpandRowKeys: React.Key[];
|
|
11
|
+
};
|
|
12
|
+
getFieldPath: (fieldKeyPath: number[], fieldName?: string) => any;
|
|
13
|
+
getFormListOperation: (operation: FormListOperation, record: ListFieldValue) => FormListOperation;
|
|
14
|
+
firstColumnFormItemName: any;
|
|
15
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
5
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
7
|
+
import { Form } from 'antd';
|
|
8
|
+
import { cloneDeep } from 'lodash-es';
|
|
9
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
10
|
+
import { FIELD_KEY_PATH, toRowKey } from "./utils";
|
|
11
|
+
export var useFormCollapseListHooks = function useFormCollapseListHooks(name, childrenColumnName, columns) {
|
|
12
|
+
var _useMemo;
|
|
13
|
+
var form = Form.useFormInstance();
|
|
14
|
+
var _useState = useState([]),
|
|
15
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
16
|
+
expandedRowKeys = _useState2[0],
|
|
17
|
+
setExpandedRowKeys = _useState2[1];
|
|
18
|
+
var firstColumnFormItemName = (_useMemo = useMemo(function () {
|
|
19
|
+
return columns.find(function (item) {
|
|
20
|
+
return !!item.name && !item.noStyle;
|
|
21
|
+
});
|
|
22
|
+
}, [columns])) === null || _useMemo === void 0 ? void 0 : _useMemo.name;
|
|
23
|
+
var fieldsToDataSource = useCallback(function (fields) {
|
|
24
|
+
var allExpandRowKeys = [];
|
|
25
|
+
var _setFieldPath = function _setFieldPath(field, index, path) {
|
|
26
|
+
var item = cloneDeep(field);
|
|
27
|
+
if (!item) {
|
|
28
|
+
item = _defineProperty({}, FIELD_KEY_PATH, []);
|
|
29
|
+
}
|
|
30
|
+
item[FIELD_KEY_PATH] = [].concat(_toConsumableArray(path), [index]);
|
|
31
|
+
if (item[childrenColumnName] && Array.isArray(item[childrenColumnName])) {
|
|
32
|
+
allExpandRowKeys.push(toRowKey(item[FIELD_KEY_PATH]));
|
|
33
|
+
item[childrenColumnName] = item[childrenColumnName].map(function (child, index) {
|
|
34
|
+
return _setFieldPath(child, index, item[FIELD_KEY_PATH]);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return item;
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
dataSource: (fields === null || fields === void 0 ? void 0 : fields.map(function (field, index) {
|
|
41
|
+
return _setFieldPath(field, index, []);
|
|
42
|
+
})) || [],
|
|
43
|
+
allExpandRowKeys: allExpandRowKeys
|
|
44
|
+
};
|
|
45
|
+
}, [childrenColumnName]);
|
|
46
|
+
var getFieldPath = useCallback(function (fieldKeyPath, fieldName) {
|
|
47
|
+
var fieldPath = [];
|
|
48
|
+
var _iterator = _createForOfIteratorHelper(fieldKeyPath.entries()),
|
|
49
|
+
_step;
|
|
50
|
+
try {
|
|
51
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
52
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
53
|
+
index = _step$value[0],
|
|
54
|
+
key = _step$value[1];
|
|
55
|
+
if (index === fieldKeyPath.length - 1) {
|
|
56
|
+
fieldPath.push(key);
|
|
57
|
+
if (fieldName) {
|
|
58
|
+
fieldPath.push(fieldName);
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
fieldPath.push(key, childrenColumnName);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
} catch (err) {
|
|
65
|
+
_iterator.e(err);
|
|
66
|
+
} finally {
|
|
67
|
+
_iterator.f();
|
|
68
|
+
}
|
|
69
|
+
return fieldPath;
|
|
70
|
+
}, [childrenColumnName]);
|
|
71
|
+
var getFormListOperation = useCallback(function (operation, record) {
|
|
72
|
+
var fieldKeyPath = record[FIELD_KEY_PATH];
|
|
73
|
+
return {
|
|
74
|
+
add: function add(defaultValue, insertIndex) {
|
|
75
|
+
var fieldPath = getFieldPath(fieldKeyPath);
|
|
76
|
+
var fieldName = [name].concat(_toConsumableArray(fieldPath), [childrenColumnName]);
|
|
77
|
+
var fieldValue = cloneDeep(form.getFieldValue(fieldName)) || [];
|
|
78
|
+
var index = insertIndex !== null && insertIndex !== void 0 ? insertIndex : fieldValue.length;
|
|
79
|
+
fieldValue.splice(index, 0, defaultValue);
|
|
80
|
+
form.setFieldValue(fieldName, fieldValue);
|
|
81
|
+
if (firstColumnFormItemName) {
|
|
82
|
+
var fileNamePath = [].concat(_toConsumableArray(fieldName), [index, firstColumnFormItemName]);
|
|
83
|
+
// Scroll and focus new item which is just added
|
|
84
|
+
setTimeout(function () {
|
|
85
|
+
form.focusField(fileNamePath);
|
|
86
|
+
}, 200);
|
|
87
|
+
}
|
|
88
|
+
setExpandedRowKeys(_toConsumableArray(new Set([].concat(_toConsumableArray(expandedRowKeys), [toRowKey(fieldKeyPath)]))));
|
|
89
|
+
},
|
|
90
|
+
remove: function remove(index) {
|
|
91
|
+
if (fieldKeyPath.length <= 1) {
|
|
92
|
+
return operation.remove(index);
|
|
93
|
+
}
|
|
94
|
+
var fieldName = [name].concat(_toConsumableArray(getFieldPath(fieldKeyPath).slice(0, -1)));
|
|
95
|
+
var fieldValue = cloneDeep(form.getFieldValue(fieldName)) || [];
|
|
96
|
+
var indexs = [];
|
|
97
|
+
if (Array.isArray(index)) {
|
|
98
|
+
indexs.push.apply(indexs, _toConsumableArray(index));
|
|
99
|
+
} else {
|
|
100
|
+
indexs.push(index);
|
|
101
|
+
}
|
|
102
|
+
var newFieldValue = fieldValue.filter(function (_, _index) {
|
|
103
|
+
return !indexs.includes(_index);
|
|
104
|
+
});
|
|
105
|
+
form.setFieldValue(fieldName, newFieldValue.length > 0 ? newFieldValue : undefined);
|
|
106
|
+
},
|
|
107
|
+
move: function move(from, to) {
|
|
108
|
+
if (fieldKeyPath.length <= 1) {
|
|
109
|
+
return operation.move(from, to);
|
|
110
|
+
}
|
|
111
|
+
var fieldName = [name].concat(_toConsumableArray(getFieldPath(fieldKeyPath).slice(0, -1)));
|
|
112
|
+
var fieldValue = cloneDeep(form.getFieldValue(fieldName)) || [];
|
|
113
|
+
// 检查索引是否有效
|
|
114
|
+
if (from < 0 || to < 0 || from >= fieldValue.length || to >= fieldValue.length) {
|
|
115
|
+
console.warn(new Error('索引超出数组范围'));
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
// 使用数组解构交换两个元素
|
|
119
|
+
var _ref = [fieldValue[to], fieldValue[from]];
|
|
120
|
+
fieldValue[from] = _ref[0];
|
|
121
|
+
fieldValue[to] = _ref[1];
|
|
122
|
+
form.setFieldValue(fieldName, fieldValue);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}, [childrenColumnName, expandedRowKeys, firstColumnFormItemName, form, getFieldPath, name]);
|
|
126
|
+
return {
|
|
127
|
+
expandedRowKeys: expandedRowKeys,
|
|
128
|
+
setExpandedRowKeys: setExpandedRowKeys,
|
|
129
|
+
fieldsToDataSource: fieldsToDataSource,
|
|
130
|
+
getFieldPath: getFieldPath,
|
|
131
|
+
getFormListOperation: getFormListOperation,
|
|
132
|
+
// 首个表单输入列 (用于新增表达后 foucs 等)
|
|
133
|
+
firstColumnFormItemName: firstColumnFormItemName
|
|
134
|
+
};
|
|
135
|
+
};
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import type { FormItemProps,
|
|
1
|
+
import type { FormItemProps, FormListOperation, TableColumnProps } from 'antd';
|
|
2
2
|
import type { FormListProps as AntFormListProps } from 'antd/es/form';
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { CollapseGroupProps } from '../../CollapseGroup';
|
|
5
|
+
import { FieldPath } from './utils';
|
|
5
6
|
export interface FormCollapseListColumnItem extends Omit<FormItemProps, 'dependencies' | 'rules' | 'tooltip' | 'labelAlign' | 'labelCol' | 'colon' | 'children'> {
|
|
6
|
-
render?: (
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
render?: (fieldName: number, index: number, operation: FormListOperation,
|
|
8
|
+
/** 当前 item 的 path */
|
|
9
|
+
fieldPath: FieldPath) => React.ReactElement;
|
|
10
|
+
rules?: FormItemProps['rules'] | ((parentFieldPath: FieldPath, index: number) => FormItemProps['rules']);
|
|
11
|
+
dependencies?: FormItemProps['dependencies'] | ((parentFieldPath: FieldPath, index: number) => FormItemProps['dependencies']);
|
|
9
12
|
}
|
|
10
13
|
export interface FormListOperationAddParams {
|
|
11
14
|
defaultValue?: any;
|
|
@@ -36,5 +39,13 @@ export interface FormCollapseListProps extends Omit<AntFormListProps, 'name' | '
|
|
|
36
39
|
onRemove?: (values: any) => boolean | void | Promise<boolean | void>;
|
|
37
40
|
/** 是否启用表单项删除按钮,默认为启用 */
|
|
38
41
|
fieldRemoveButton?: boolean;
|
|
42
|
+
/** [树形数据] 初始时,是否展开所有行 */
|
|
43
|
+
defaultExpandAllRows?: boolean;
|
|
44
|
+
/** [树形数据] 每层缩进的宽度,以 px 为单位, 默认为 16 */
|
|
45
|
+
indentSize?: number;
|
|
46
|
+
/** [树形数据] 指定树形结构的列名,默认为 children */
|
|
47
|
+
childrenColumnName?: string;
|
|
48
|
+
/** 表格行是否开启 hover 交互, 默认为启用 */
|
|
49
|
+
rowHoverable?: boolean;
|
|
39
50
|
}
|
|
40
51
|
export declare const FormCollapseList: React.FC<FormCollapseListProps>;
|
|
@@ -2,9 +2,9 @@ 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
|
-
var _excluded = ["extra", "expandIcon", "icon", "title", "variant", "defaultActive", "empty", "columns", "disabled", "readOnly", "addOneFieldDefault", "disableRemoveWhenOneField", "maxFileds", "name", "addParams", "className", "onRemove", "fieldRemoveButton", "style"],
|
|
6
|
-
_excluded2 = ["label", "name", "render", "dependencies", "rules", "align", "ellipsis", "fixed", "responsive", "shouldCellUpdate", "width"],
|
|
7
|
-
_excluded3 = ["key"
|
|
5
|
+
var _excluded = ["extra", "expandIcon", "icon", "title", "variant", "defaultActive", "empty", "columns", "disabled", "readOnly", "addOneFieldDefault", "disableRemoveWhenOneField", "maxFileds", "name", "addParams", "className", "onRemove", "fieldRemoveButton", "style", "defaultExpandAllRows", "indentSize", "childrenColumnName", "rowHoverable"],
|
|
6
|
+
_excluded2 = ["label", "name", "render", "dependencies", "rules", "align", "ellipsis", "fixed", "responsive", "shouldCellUpdate", "width", "className"],
|
|
7
|
+
_excluded3 = ["key"];
|
|
8
8
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
9
9
|
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; }
|
|
10
10
|
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; }
|
|
@@ -12,9 +12,11 @@ import { PlusOutlined } from '@ant-design/icons';
|
|
|
12
12
|
import { Icon } from '@lobehub/ui';
|
|
13
13
|
import { Button, Flex, Form, Table, Tooltip } from 'antd';
|
|
14
14
|
import { Trash2 } from 'lucide-react';
|
|
15
|
-
import React, { useCallback, useEffect, useRef } from 'react';
|
|
15
|
+
import React, { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
16
16
|
import { CollapseGroup } from "../../CollapseGroup";
|
|
17
|
+
import { useFormCollapseListHooks } from "./hooks";
|
|
17
18
|
import { useStyles } from "./style";
|
|
19
|
+
import { FIELD_KEY_PATH, toRowKey } from "./utils";
|
|
18
20
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
19
21
|
export var FormCollapseList = function FormCollapseList(_ref) {
|
|
20
22
|
var extra = _ref.extra,
|
|
@@ -39,12 +41,39 @@ export var FormCollapseList = function FormCollapseList(_ref) {
|
|
|
39
41
|
_ref$fieldRemoveButto = _ref.fieldRemoveButton,
|
|
40
42
|
fieldRemoveButton = _ref$fieldRemoveButto === void 0 ? true : _ref$fieldRemoveButto,
|
|
41
43
|
style = _ref.style,
|
|
44
|
+
defaultExpandAllRows = _ref.defaultExpandAllRows,
|
|
45
|
+
_ref$indentSize = _ref.indentSize,
|
|
46
|
+
indentSize = _ref$indentSize === void 0 ? 16 : _ref$indentSize,
|
|
47
|
+
_ref$childrenColumnNa = _ref.childrenColumnName,
|
|
48
|
+
childrenColumnName = _ref$childrenColumnNa === void 0 ? 'children' : _ref$childrenColumnNa,
|
|
49
|
+
_ref$rowHoverable = _ref.rowHoverable,
|
|
50
|
+
rowHoverable = _ref$rowHoverable === void 0 ? true : _ref$rowHoverable,
|
|
42
51
|
formListProps = _objectWithoutProperties(_ref, _excluded);
|
|
43
52
|
var _useStyles = useStyles(),
|
|
53
|
+
cx = _useStyles.cx,
|
|
44
54
|
styles = _useStyles.styles;
|
|
45
55
|
var listAdd = useRef();
|
|
46
56
|
var form = Form.useFormInstance();
|
|
47
57
|
var fieldsWatch = Form.useWatch(name, form);
|
|
58
|
+
var _useFormCollapseListH = useFormCollapseListHooks(name, childrenColumnName, columns),
|
|
59
|
+
expandedRowKeys = _useFormCollapseListH.expandedRowKeys,
|
|
60
|
+
setExpandedRowKeys = _useFormCollapseListH.setExpandedRowKeys,
|
|
61
|
+
fieldsToDataSource = _useFormCollapseListH.fieldsToDataSource,
|
|
62
|
+
getFormListOperation = _useFormCollapseListH.getFormListOperation,
|
|
63
|
+
getFieldPath = _useFormCollapseListH.getFieldPath,
|
|
64
|
+
firstColumnFormItemName = _useFormCollapseListH.firstColumnFormItemName;
|
|
65
|
+
var _useMemo = useMemo(function () {
|
|
66
|
+
return fieldsToDataSource(fieldsWatch);
|
|
67
|
+
}, [fieldsWatch, fieldsToDataSource]),
|
|
68
|
+
dataSource = _useMemo.dataSource;
|
|
69
|
+
useEffect(function () {
|
|
70
|
+
var fields = form.getFieldValue(name);
|
|
71
|
+
var _fieldsToDataSource = fieldsToDataSource(fields),
|
|
72
|
+
allExpandRowKeys = _fieldsToDataSource.allExpandRowKeys;
|
|
73
|
+
if (defaultExpandAllRows) {
|
|
74
|
+
setExpandedRowKeys(allExpandRowKeys);
|
|
75
|
+
}
|
|
76
|
+
}, [defaultExpandAllRows, fieldsToDataSource, form, name, setExpandedRowKeys]);
|
|
48
77
|
var getAddParams = useCallback(function () {
|
|
49
78
|
if (!addParams) {
|
|
50
79
|
return [];
|
|
@@ -61,8 +90,12 @@ export var FormCollapseList = function FormCollapseList(_ref) {
|
|
|
61
90
|
if (addOneFieldDefault && (!(form !== null && form !== void 0 && form.getFieldValue(name)) || (form === null || form === void 0 || (_form$getFieldValue = form.getFieldValue(name)) === null || _form$getFieldValue === void 0 ? void 0 : _form$getFieldValue.length) === 0)) {
|
|
62
91
|
var _listAdd$current;
|
|
63
92
|
(_listAdd$current = listAdd.current) === null || _listAdd$current === void 0 || _listAdd$current.call.apply(_listAdd$current, [listAdd].concat(_toConsumableArray(getAddParams())));
|
|
93
|
+
// Scroll and focus new item which is just added
|
|
94
|
+
setTimeout(function () {
|
|
95
|
+
form.focusField([name, 0, firstColumnFormItemName]);
|
|
96
|
+
}, 200);
|
|
64
97
|
}
|
|
65
|
-
}, [addOneFieldDefault, getAddParams, form, name]);
|
|
98
|
+
}, [addOneFieldDefault, getAddParams, form, name, firstColumnFormItemName]);
|
|
66
99
|
return /*#__PURE__*/_jsx(CollapseGroup, {
|
|
67
100
|
extra: extra === undefined ? name && !readOnly && /*#__PURE__*/_jsx(Tooltip, {
|
|
68
101
|
title: maxFileds && "\u6700\u591A\u6DFB\u52A0 ".concat(maxFileds, " \u9879"),
|
|
@@ -73,6 +106,10 @@ export var FormCollapseList = function FormCollapseList(_ref) {
|
|
|
73
106
|
var _listAdd$current2;
|
|
74
107
|
e.stopPropagation();
|
|
75
108
|
(_listAdd$current2 = listAdd.current) === null || _listAdd$current2 === void 0 || _listAdd$current2.call.apply(_listAdd$current2, [listAdd].concat(_toConsumableArray(getAddParams())));
|
|
109
|
+
// Scroll and focus new item which is just added
|
|
110
|
+
setTimeout(function () {
|
|
111
|
+
form.focusField([name, form.getFieldValue(name).length - 1, firstColumnFormItemName]);
|
|
112
|
+
}, 200);
|
|
76
113
|
},
|
|
77
114
|
size: "small",
|
|
78
115
|
type: "text"
|
|
@@ -88,27 +125,28 @@ export var FormCollapseList = function FormCollapseList(_ref) {
|
|
|
88
125
|
children: name ? /*#__PURE__*/_jsx(Form.List, _objectSpread(_objectSpread({
|
|
89
126
|
name: name
|
|
90
127
|
}, formListProps), {}, {
|
|
91
|
-
children: function children(fields,
|
|
92
|
-
var add =
|
|
93
|
-
remove =
|
|
128
|
+
children: function children(fields, operation) {
|
|
129
|
+
var add = operation.add,
|
|
130
|
+
remove = operation.remove;
|
|
94
131
|
listAdd.current = add;
|
|
95
132
|
|
|
96
133
|
// @Todo: support sort
|
|
97
134
|
return /*#__PURE__*/_jsx(Table, {
|
|
98
135
|
className: styles.list,
|
|
99
|
-
columns: [].concat(_toConsumableArray(columns.map(function (
|
|
100
|
-
var label =
|
|
101
|
-
itemName =
|
|
102
|
-
fieldRender =
|
|
103
|
-
dependencies =
|
|
104
|
-
rules =
|
|
105
|
-
align =
|
|
106
|
-
ellipsis =
|
|
107
|
-
fixed =
|
|
108
|
-
responsive =
|
|
109
|
-
shouldCellUpdate =
|
|
110
|
-
width =
|
|
111
|
-
|
|
136
|
+
columns: [].concat(_toConsumableArray(columns.map(function (_ref2) {
|
|
137
|
+
var label = _ref2.label,
|
|
138
|
+
itemName = _ref2.name,
|
|
139
|
+
fieldRender = _ref2.render,
|
|
140
|
+
dependencies = _ref2.dependencies,
|
|
141
|
+
rules = _ref2.rules,
|
|
142
|
+
align = _ref2.align,
|
|
143
|
+
ellipsis = _ref2.ellipsis,
|
|
144
|
+
fixed = _ref2.fixed,
|
|
145
|
+
responsive = _ref2.responsive,
|
|
146
|
+
shouldCellUpdate = _ref2.shouldCellUpdate,
|
|
147
|
+
width = _ref2.width,
|
|
148
|
+
className = _ref2.className,
|
|
149
|
+
itemProps = _objectWithoutProperties(_ref2, _excluded2);
|
|
112
150
|
return {
|
|
113
151
|
title: label,
|
|
114
152
|
dataIndex: itemName,
|
|
@@ -118,23 +156,26 @@ export var FormCollapseList = function FormCollapseList(_ref) {
|
|
|
118
156
|
responsive: responsive,
|
|
119
157
|
shouldCellUpdate: shouldCellUpdate,
|
|
120
158
|
width: width,
|
|
121
|
-
render: function render(_text,
|
|
122
|
-
var
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
var
|
|
159
|
+
render: function render(_text, record, index) {
|
|
160
|
+
var field = fields[index] || {};
|
|
161
|
+
var fieldName = field.name;
|
|
162
|
+
var fieldKeyPath = record[FIELD_KEY_PATH];
|
|
163
|
+
var fieldPath = getFieldPath(fieldKeyPath);
|
|
164
|
+
var parentFieldPath = fieldPath.slice(0, -1);
|
|
165
|
+
var key = field.key,
|
|
166
|
+
restField = _objectWithoutProperties(field, _excluded3);
|
|
167
|
+
var children = fieldRender === null || fieldRender === void 0 ? void 0 : fieldRender(fieldName !== null && fieldName !== void 0 ? fieldName : fieldKeyPath.at(-1), index, getFormListOperation(operation, record), fieldPath);
|
|
127
168
|
if (!children && !itemProps.noStyle) {
|
|
128
169
|
return /*#__PURE__*/_jsx(Flex, {
|
|
129
170
|
align: "center",
|
|
130
|
-
className: styles.noFormItem,
|
|
171
|
+
className: cx(styles.noFormItem, className),
|
|
131
172
|
children: "\u65E0\u9700\u8BBE\u7F6E"
|
|
132
173
|
});
|
|
133
174
|
}
|
|
134
175
|
if (!itemName) {
|
|
135
176
|
return /*#__PURE__*/_jsx(Flex, {
|
|
136
177
|
align: "center",
|
|
137
|
-
className: styles.noFormItem,
|
|
178
|
+
className: cx(styles.noFormItem, className),
|
|
138
179
|
children: children
|
|
139
180
|
});
|
|
140
181
|
}
|
|
@@ -147,10 +188,14 @@ export var FormCollapseList = function FormCollapseList(_ref) {
|
|
|
147
188
|
chidrenProps.variant = 'borderless';
|
|
148
189
|
chidrenProps.placeholder = '-';
|
|
149
190
|
}
|
|
150
|
-
return /*#__PURE__*/_jsx(Form.Item, _objectSpread(_objectSpread(_objectSpread({
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
191
|
+
return /*#__PURE__*/_jsx(Form.Item, _objectSpread(_objectSpread(_objectSpread({
|
|
192
|
+
className: className
|
|
193
|
+
}, restField), {}, {
|
|
194
|
+
dependencies: typeof dependencies === 'function' ? dependencies(parentFieldPath, index) : dependencies,
|
|
195
|
+
name: getFieldPath(fieldKeyPath, itemName)
|
|
196
|
+
// label={getFieldPath(fieldKeyPath, itemName).join('/')}
|
|
197
|
+
,
|
|
198
|
+
rules: typeof rules === 'function' ? rules(parentFieldPath, index) : rules
|
|
154
199
|
}, itemProps), {}, {
|
|
155
200
|
children: children && /*#__PURE__*/React.cloneElement(children, chidrenProps)
|
|
156
201
|
}), key);
|
|
@@ -160,7 +205,11 @@ export var FormCollapseList = function FormCollapseList(_ref) {
|
|
|
160
205
|
title: '',
|
|
161
206
|
dataIndex: 'del',
|
|
162
207
|
render: function render(_text, _record, index) {
|
|
163
|
-
var
|
|
208
|
+
var field = fields[index];
|
|
209
|
+
if (!field) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
var fieldName = field.name;
|
|
164
213
|
return /*#__PURE__*/_jsx(Form.Item, {
|
|
165
214
|
children: /*#__PURE__*/_jsx(Button, {
|
|
166
215
|
disabled: disabled || disableRemoveWhenOneField && fields.length === 1,
|
|
@@ -192,12 +241,23 @@ export var FormCollapseList = function FormCollapseList(_ref) {
|
|
|
192
241
|
}]).filter(function (c) {
|
|
193
242
|
return !!c;
|
|
194
243
|
}),
|
|
195
|
-
dataSource:
|
|
244
|
+
dataSource: dataSource,
|
|
245
|
+
expandable: {
|
|
246
|
+
expandedRowKeys: expandedRowKeys,
|
|
247
|
+
childrenColumnName: childrenColumnName,
|
|
248
|
+
onExpandedRowsChange: function onExpandedRowsChange(expandedKeys) {
|
|
249
|
+
setExpandedRowKeys(expandedKeys);
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
indentSize: indentSize,
|
|
196
253
|
locale: {
|
|
197
254
|
emptyText: empty
|
|
198
255
|
},
|
|
199
256
|
pagination: false,
|
|
200
|
-
rowHoverable:
|
|
257
|
+
rowHoverable: rowHoverable,
|
|
258
|
+
rowKey: function rowKey(row) {
|
|
259
|
+
return toRowKey(row[FIELD_KEY_PATH]);
|
|
260
|
+
},
|
|
201
261
|
size: "small"
|
|
202
262
|
});
|
|
203
263
|
}
|
|
@@ -7,7 +7,7 @@ export var useStyles = createStyles(function (_ref) {
|
|
|
7
7
|
prefixCls = _ref.prefixCls;
|
|
8
8
|
return {
|
|
9
9
|
empty: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n padding: ", "px ", "px;\n color: ", ";\n "])), token.paddingXS, token.paddingSM, token.colorTextTertiary),
|
|
10
|
-
list: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n &.", "-table-wrapper {\n .", "-table {\n &-thead {\n & > tr > th {\n font-weight: normal;\n color: ", ";\n background-color: unset;\n &::before {\n display: none;\n }\n }\n }\n &-tbody {\n & > tr:last-child {\n & > td {\n border-bottom-color: transparent;\n }\n }\n }\n &-cell {\n vertical-align: top;\n }\n }\n }\n .", "-form {\n &-item {\n margin-bottom: 0;\n }\n }\n "])), prefixCls, prefixCls, token.colorTextTertiary, prefixCls),
|
|
10
|
+
list: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n &.", "-table-wrapper {\n .", "-table {\n &-thead {\n & > tr > th {\n font-weight: normal;\n color: ", ";\n background-color: unset;\n &::before {\n display: none;\n }\n }\n }\n &-tbody {\n & > tr:last-child {\n & > td {\n border-bottom-color: transparent;\n }\n }\n }\n &-cell {\n vertical-align: top;\n .", "-table-row-expand-icon {\n margin-top: ", "px;\n }\n }\n }\n }\n .", "-form {\n &-item {\n margin-bottom: 0;\n }\n }\n "])), prefixCls, prefixCls, token.colorTextTertiary, prefixCls, token.marginXS, prefixCls),
|
|
11
11
|
noFormItem: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n height: ", "px;\n color: ", ";\n "])), token.controlHeight, token.colorTextTertiary)
|
|
12
12
|
};
|
|
13
13
|
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { NamePath } from 'antd/es/form/interface';
|
|
2
|
+
export declare const FIELD_KEY_PATH = "__YUNTI_FORM_COLLAPSE_LIST_FIELD_KEY_PATH";
|
|
3
|
+
export type ListFieldValue<K extends string = 'children'> = {
|
|
4
|
+
[P in K]?: ListFieldValue[];
|
|
5
|
+
} & {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
[FIELD_KEY_PATH]: number[];
|
|
8
|
+
};
|
|
9
|
+
export type FieldPath = NamePath<any>;
|
|
10
|
+
export declare const toRowKey: (keyPath: number[]) => string;
|
package/es/JsonViewer/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import React, { ReactNode } from 'react';
|
|
|
2
2
|
import type { JsonViewProps } from 'react18-json-view';
|
|
3
3
|
import 'react18-json-view/src/dark.css';
|
|
4
4
|
import 'react18-json-view/src/style.css';
|
|
5
|
+
export { stringify } from 'react18-json-view';
|
|
5
6
|
export interface JsonViewerProps extends JsonViewProps {
|
|
6
7
|
/**
|
|
7
8
|
* @description The type of the json block
|
package/es/JsonViewer/index.js
CHANGED
|
@@ -16,6 +16,7 @@ import Typography from "../Typography";
|
|
|
16
16
|
import { useStyles } from "./style";
|
|
17
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
18
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
|
+
export { stringify } from 'react18-json-view';
|
|
19
20
|
var Text = Typography.Text;
|
|
20
21
|
export var JsonViewer = function JsonViewer(_ref) {
|
|
21
22
|
var _ref$type = _ref.type,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yuntijs/ui",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.102",
|
|
4
4
|
"description": "☁️ Yunti UI - an open-source UI component library for building Cloud Native web apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yuntijs",
|
|
@@ -116,13 +116,13 @@
|
|
|
116
116
|
"@types/unist": "^3.0.3",
|
|
117
117
|
"@vitest/coverage-v8": "latest",
|
|
118
118
|
"@yuntijs/lint": "^1.7.0",
|
|
119
|
-
"antd": "^5.23.
|
|
119
|
+
"antd": "^5.23.4",
|
|
120
120
|
"antd-style": "^3.7.1",
|
|
121
121
|
"babel-plugin-antd-style": "latest",
|
|
122
122
|
"commitlint": "^18",
|
|
123
123
|
"dayjs": "^1.11.10",
|
|
124
|
-
"dumi": "^2.4.
|
|
125
|
-
"dumi-theme-yunti": "^1.7.
|
|
124
|
+
"dumi": "^2.4.17",
|
|
125
|
+
"dumi-theme-yunti": "^1.7.3",
|
|
126
126
|
"eslint": "^8.56.0",
|
|
127
127
|
"father": "^4.3.8",
|
|
128
128
|
"husky": "^8",
|