@yuntijs/ui 1.0.0-beta.99 → 1.1.0-beta.1
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/ChatItem/index.js +6 -2
- package/es/ChatItem/type.d.ts +1 -0
- package/es/ChatMarkdown/MarkdownElements/AntThinking/Component.js +6 -6
- package/es/ChatMarkdown/MarkdownElements/AntThinking/remarkPlugin.js +1 -1
- package/es/ChatMarkdown/utils.js +8 -3
- package/es/CodeEditor/index.d.ts +52 -0
- package/es/CodeEditor/index.js +418 -0
- package/es/CodeEditor/style.d.ts +9 -0
- package/es/CodeEditor/style.js +19 -0
- package/es/CollapseGroup/index.js +20 -4
- package/es/CollapseGroup/style.d.ts +3 -1
- package/es/CollapseGroup/style.js +3 -2
- package/es/Form/collapse-list/FieldsWatcher.d.ts +7 -0
- package/es/Form/collapse-list/FieldsWatcher.js +19 -0
- package/es/Form/collapse-list/hooks.d.ts +20 -0
- package/es/Form/collapse-list/hooks.js +158 -0
- package/es/Form/collapse-list/index.d.ts +19 -6
- package/es/Form/collapse-list/index.js +163 -59
- package/es/Form/collapse-list/style.d.ts +1 -0
- package/es/Form/collapse-list/style.js +4 -3
- 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/es/Mentions/index.d.ts +2 -0
- package/es/Mentions/index.js +17 -2
- package/es/Mentions/plugins/mention-node/component.js +1 -1
- package/es/Mentions/plugins/mention-picker/hooks.js +1 -0
- package/es/Mentions/plugins/mention-picker/index.d.ts +4 -0
- package/es/Mentions/plugins/mention-picker/index.js +49 -12
- package/es/Mentions/plugins/mention-picker/menu-item.js +19 -3
- package/es/Mentions/plugins/mention-picker/style.js +1 -1
- package/es/Mentions/plugins/mention-picker/utils.d.ts +3 -1
- package/es/Mentions/plugins/mention-picker/utils.js +3 -0
- package/es/Mentions/style.d.ts +1 -0
- package/es/Mentions/style.js +4 -4
- package/es/MonacoEditor/base/helper.d.ts +4 -0
- package/es/MonacoEditor/base/helper.js +8 -3
- package/es/MonacoEditor/base/index.d.ts +2 -2
- package/es/MonacoEditor/base/index.js +33 -10
- package/es/MonacoEditor/base/style.js +1 -1
- package/es/MonacoEditor/index.js +1 -1
- package/es/hooks/useHighlight.js +13 -9
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/es/utils/platform.d.ts +1 -0
- package/es/utils/platform.js +1 -0
- package/package.json +5 -5
- package/umd/index.min.js +1 -1
- package/umd/index.min.js.map +1 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
|
|
2
2
|
var _templateObject;
|
|
3
3
|
import { createStyles } from 'antd-style';
|
|
4
|
-
export var useStyles = createStyles(function (_ref) {
|
|
4
|
+
export var useStyles = createStyles(function (_ref, _ref2) {
|
|
5
5
|
var css = _ref.css,
|
|
6
6
|
token = _ref.token,
|
|
7
7
|
prefixCls = _ref.prefixCls;
|
|
8
|
+
var collapsible = _ref2.collapsible;
|
|
8
9
|
return {
|
|
9
|
-
root: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n
|
|
10
|
+
root: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n margin-bottom: ", "px;\n .", "-collapse {\n &-header {\n padding: 0 !important;\n &-text {\n flex: 1 !important;\n padding: ", "px ", "px ", "px\n ", "px;\n & > * {\n font-size: ", "px;\n /* font-weight: unset; */\n }\n }\n }\n &-expand-icon {\n cursor: pointer;\n padding: ", "px 0 ", "px ", "px;\n }\n &-extra {\n padding-right: ", "px;\n }\n &-item > .", "-collapse-content {\n padding: ", "px 0;\n background-color: ", ";\n }\n &-content {\n &-box {\n padding: ", "px ", "px !important;\n }\n }\n }\n "])), token.margin, prefixCls, token.paddingSM, token.paddingSM, token.paddingSM, collapsible === false ? token.paddingSM : 0, token.fontSize, token.padding, token.padding, token.paddingSM, token.paddingSM, prefixCls, token.paddingXXS, token.colorBgContainer, token.paddingXXS, token.padding)
|
|
10
11
|
};
|
|
11
12
|
});
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type FormItemProps, type FormListOperation } from 'antd';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { FormCollapseListColumn } from '.';
|
|
4
|
+
import { ListFieldValue } from './utils';
|
|
5
|
+
export interface FormCollapseListOperation extends FormListOperation {
|
|
6
|
+
update: () => void;
|
|
7
|
+
}
|
|
8
|
+
export declare const useFormCollapseListHooks: (name: FormItemProps['name'], childrenColumnName: string, columns: FormCollapseListColumn[]) => {
|
|
9
|
+
values: ListFieldValue[];
|
|
10
|
+
updateValues: () => void;
|
|
11
|
+
expandedRowKeys: readonly React.Key[];
|
|
12
|
+
setExpandedRowKeys: React.Dispatch<React.SetStateAction<readonly React.Key[]>>;
|
|
13
|
+
fieldValuesToDataSource: (fields: ListFieldValue[]) => {
|
|
14
|
+
dataSource: ListFieldValue[];
|
|
15
|
+
allExpandRowKeys: React.Key[];
|
|
16
|
+
};
|
|
17
|
+
getFieldPath: (fieldKeyPath: number[], fieldName?: string) => any;
|
|
18
|
+
getFormListOperation: (operation: FormListOperation, record: ListFieldValue) => FormCollapseListOperation;
|
|
19
|
+
firstColumnFormItemName: any;
|
|
20
|
+
};
|
|
@@ -0,0 +1,158 @@
|
|
|
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
|
+
values = _useState2[0],
|
|
17
|
+
_setValues = _useState2[1];
|
|
18
|
+
var _useState3 = useState([]),
|
|
19
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
20
|
+
expandedRowKeys = _useState4[0],
|
|
21
|
+
setExpandedRowKeys = _useState4[1];
|
|
22
|
+
var updateValues = useCallback(function () {
|
|
23
|
+
return _setValues(form.getFieldValue(name));
|
|
24
|
+
}, [form, name]);
|
|
25
|
+
var firstColumnFormItemName = (_useMemo = useMemo(function () {
|
|
26
|
+
return columns.find(function (item) {
|
|
27
|
+
return !!item.name && !item.noStyle;
|
|
28
|
+
});
|
|
29
|
+
}, [columns])) === null || _useMemo === void 0 ? void 0 : _useMemo.name;
|
|
30
|
+
var fieldValuesToDataSource = useCallback(function (fields) {
|
|
31
|
+
if (!name) {
|
|
32
|
+
return {
|
|
33
|
+
dataSource: [],
|
|
34
|
+
allExpandRowKeys: []
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
var allExpandRowKeys = [];
|
|
38
|
+
var _setFieldPath = function _setFieldPath(field, index, path) {
|
|
39
|
+
var item = cloneDeep(field);
|
|
40
|
+
if (!item) {
|
|
41
|
+
item = _defineProperty({}, FIELD_KEY_PATH, []);
|
|
42
|
+
}
|
|
43
|
+
item[FIELD_KEY_PATH] = [].concat(_toConsumableArray(path), [index]);
|
|
44
|
+
if (item[childrenColumnName] && Array.isArray(item[childrenColumnName])) {
|
|
45
|
+
allExpandRowKeys.push(toRowKey(item[FIELD_KEY_PATH]));
|
|
46
|
+
item[childrenColumnName] = item[childrenColumnName].map(function (child, index) {
|
|
47
|
+
return _setFieldPath(child, index, item[FIELD_KEY_PATH]);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return item;
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
dataSource: (fields === null || fields === void 0 ? void 0 : fields.map(function (field, index) {
|
|
54
|
+
return _setFieldPath(field, index, []);
|
|
55
|
+
})) || [],
|
|
56
|
+
allExpandRowKeys: allExpandRowKeys
|
|
57
|
+
};
|
|
58
|
+
}, [childrenColumnName, name]);
|
|
59
|
+
var getFieldPath = useCallback(function (fieldKeyPath, fieldName) {
|
|
60
|
+
var fieldPath = [];
|
|
61
|
+
var _iterator = _createForOfIteratorHelper(fieldKeyPath.entries()),
|
|
62
|
+
_step;
|
|
63
|
+
try {
|
|
64
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
65
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
66
|
+
index = _step$value[0],
|
|
67
|
+
key = _step$value[1];
|
|
68
|
+
if (index === fieldKeyPath.length - 1) {
|
|
69
|
+
fieldPath.push(key);
|
|
70
|
+
if (fieldName) {
|
|
71
|
+
fieldPath.push(fieldName);
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
fieldPath.push(key, childrenColumnName);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
} catch (err) {
|
|
78
|
+
_iterator.e(err);
|
|
79
|
+
} finally {
|
|
80
|
+
_iterator.f();
|
|
81
|
+
}
|
|
82
|
+
return fieldPath;
|
|
83
|
+
}, [childrenColumnName]);
|
|
84
|
+
var getFormListOperation = useCallback(function (operation, record) {
|
|
85
|
+
var fieldKeyPath = record[FIELD_KEY_PATH];
|
|
86
|
+
return {
|
|
87
|
+
add: function add(defaultValue, insertIndex) {
|
|
88
|
+
var fieldPath = getFieldPath(fieldKeyPath);
|
|
89
|
+
var fieldName = [name].concat(_toConsumableArray(fieldPath), [childrenColumnName]);
|
|
90
|
+
var fieldValue = cloneDeep(form.getFieldValue(fieldName)) || [];
|
|
91
|
+
var index = insertIndex !== null && insertIndex !== void 0 ? insertIndex : fieldValue.length;
|
|
92
|
+
fieldValue.splice(index, 0, defaultValue);
|
|
93
|
+
form.setFieldValue(fieldName, fieldValue);
|
|
94
|
+
if (firstColumnFormItemName) {
|
|
95
|
+
var fileNamePath = [].concat(_toConsumableArray(fieldName), [index, firstColumnFormItemName]);
|
|
96
|
+
// Scroll and focus new item which is just added
|
|
97
|
+
setTimeout(function () {
|
|
98
|
+
form.focusField(fileNamePath);
|
|
99
|
+
}, 200);
|
|
100
|
+
}
|
|
101
|
+
setExpandedRowKeys(_toConsumableArray(new Set([].concat(_toConsumableArray(expandedRowKeys), [toRowKey(fieldKeyPath)]))));
|
|
102
|
+
updateValues();
|
|
103
|
+
},
|
|
104
|
+
remove: function remove(index) {
|
|
105
|
+
if (fieldKeyPath.length <= 1) {
|
|
106
|
+
operation.remove(index);
|
|
107
|
+
updateValues();
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
var fieldName = [name].concat(_toConsumableArray(getFieldPath(fieldKeyPath).slice(0, -1)));
|
|
111
|
+
var fieldValue = cloneDeep(form.getFieldValue(fieldName)) || [];
|
|
112
|
+
var indexs = [];
|
|
113
|
+
if (Array.isArray(index)) {
|
|
114
|
+
indexs.push.apply(indexs, _toConsumableArray(index));
|
|
115
|
+
} else {
|
|
116
|
+
indexs.push(index);
|
|
117
|
+
}
|
|
118
|
+
var newFieldValue = fieldValue.filter(function (_, _index) {
|
|
119
|
+
return !indexs.includes(_index);
|
|
120
|
+
});
|
|
121
|
+
form.setFieldValue(fieldName, newFieldValue.length > 0 ? newFieldValue : undefined);
|
|
122
|
+
updateValues();
|
|
123
|
+
},
|
|
124
|
+
move: function move(from, to) {
|
|
125
|
+
if (fieldKeyPath.length <= 1) {
|
|
126
|
+
return operation.move(from, to);
|
|
127
|
+
}
|
|
128
|
+
var fieldName = [name].concat(_toConsumableArray(getFieldPath(fieldKeyPath).slice(0, -1)));
|
|
129
|
+
var fieldValue = cloneDeep(form.getFieldValue(fieldName)) || [];
|
|
130
|
+
// 检查索引是否有效
|
|
131
|
+
if (from < 0 || to < 0 || from >= fieldValue.length || to >= fieldValue.length) {
|
|
132
|
+
console.warn(new Error('索引超出数组范围'));
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
// 使用数组解构交换两个元素
|
|
136
|
+
var _ref = [fieldValue[to], fieldValue[from]];
|
|
137
|
+
fieldValue[from] = _ref[0];
|
|
138
|
+
fieldValue[to] = _ref[1];
|
|
139
|
+
form.setFieldValue(fieldName, fieldValue);
|
|
140
|
+
updateValues();
|
|
141
|
+
},
|
|
142
|
+
update: function update() {
|
|
143
|
+
return updateValues();
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}, [childrenColumnName, expandedRowKeys, firstColumnFormItemName, form, getFieldPath, name, updateValues]);
|
|
147
|
+
return {
|
|
148
|
+
values: values,
|
|
149
|
+
updateValues: updateValues,
|
|
150
|
+
expandedRowKeys: expandedRowKeys,
|
|
151
|
+
setExpandedRowKeys: setExpandedRowKeys,
|
|
152
|
+
fieldValuesToDataSource: fieldValuesToDataSource,
|
|
153
|
+
getFieldPath: getFieldPath,
|
|
154
|
+
getFormListOperation: getFormListOperation,
|
|
155
|
+
// 首个表单输入列 (用于新增表达后 foucs 等)
|
|
156
|
+
firstColumnFormItemName: firstColumnFormItemName
|
|
157
|
+
};
|
|
158
|
+
};
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import type { FormItemProps,
|
|
1
|
+
import type { FormItemProps, 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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
import { FormCollapseListOperation } from './hooks';
|
|
6
|
+
import { FieldPath } from './utils';
|
|
7
|
+
interface FormCollapseListColumnItem extends Omit<FormItemProps, 'dependencies' | 'rules' | 'tooltip' | 'labelAlign' | 'labelCol' | 'colon' | 'children'> {
|
|
8
|
+
render?: (fieldName: number, index: number, operation: FormCollapseListOperation,
|
|
9
|
+
/** 当前 item 的 path */
|
|
10
|
+
fieldPath: FieldPath) => React.ReactNode;
|
|
11
|
+
rules?: FormItemProps['rules'] | ((parentFieldPath: FieldPath, index: number) => FormItemProps['rules']);
|
|
12
|
+
dependencies?: FormItemProps['dependencies'] | ((parentFieldPath: FieldPath, index: number) => FormItemProps['dependencies']);
|
|
9
13
|
}
|
|
10
14
|
export interface FormListOperationAddParams {
|
|
11
15
|
defaultValue?: any;
|
|
@@ -13,7 +17,7 @@ export interface FormListOperationAddParams {
|
|
|
13
17
|
}
|
|
14
18
|
export interface FormCollapseListColumn extends FormCollapseListColumnItem, Pick<TableColumnProps<any>, 'align' | 'ellipsis' | 'fixed' | 'responsive' | 'shouldCellUpdate' | 'width'> {
|
|
15
19
|
}
|
|
16
|
-
export interface FormCollapseListProps extends Omit<AntFormListProps, 'name' | 'children'>, Pick<CollapseGroupProps, 'className' | 'extra' | 'expandIcon' | 'icon' | 'title' | 'variant' | 'defaultActive' | 'style'> {
|
|
20
|
+
export interface FormCollapseListProps extends Omit<AntFormListProps, 'name' | 'children'>, Pick<CollapseGroupProps, 'className' | 'collapsible' | 'extra' | 'expandIcon' | 'icon' | 'title' | 'variant' | 'defaultActive' | 'style'> {
|
|
17
21
|
/** 字段名 */
|
|
18
22
|
name?: FormItemProps['name'];
|
|
19
23
|
/** 表单列为空时展示的空内容 */
|
|
@@ -36,5 +40,14 @@ export interface FormCollapseListProps extends Omit<AntFormListProps, 'name' | '
|
|
|
36
40
|
onRemove?: (values: any) => boolean | void | Promise<boolean | void>;
|
|
37
41
|
/** 是否启用表单项删除按钮,默认为启用 */
|
|
38
42
|
fieldRemoveButton?: boolean;
|
|
43
|
+
/** [树形数据] 初始时,是否展开所有行 */
|
|
44
|
+
defaultExpandAllRows?: boolean;
|
|
45
|
+
/** [树形数据] 每层缩进的宽度,以 px 为单位, 默认为 16 */
|
|
46
|
+
indentSize?: number;
|
|
47
|
+
/** [树形数据] 指定树形结构的列名,默认为 children */
|
|
48
|
+
childrenColumnName?: string;
|
|
49
|
+
/** 表格行是否开启 hover 交互, 默认为启用 */
|
|
50
|
+
rowHoverable?: boolean;
|
|
39
51
|
}
|
|
40
52
|
export declare const FormCollapseList: React.FC<FormCollapseListProps>;
|
|
53
|
+
export {};
|
|
@@ -2,9 +2,10 @@ 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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
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"],
|
|
7
|
+
_excluded2 = ["label", "name", "render", "dependencies", "rules", "align", "ellipsis", "fixed", "responsive", "shouldCellUpdate", "width", "className"],
|
|
8
|
+
_excluded3 = ["key"];
|
|
8
9
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
9
10
|
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
11
|
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,12 +13,30 @@ import { PlusOutlined } from '@ant-design/icons';
|
|
|
12
13
|
import { Icon } from '@lobehub/ui';
|
|
13
14
|
import { Button, Flex, Form, Table, Tooltip } from 'antd';
|
|
14
15
|
import { Trash2 } from 'lucide-react';
|
|
15
|
-
import React, { useCallback, useEffect, useRef } from 'react';
|
|
16
|
+
import React, { memo, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
17
|
+
import Typography from "../../Typography";
|
|
16
18
|
import { CollapseGroup } from "../../CollapseGroup";
|
|
19
|
+
import { FormCollapseListFieldsWatcher } from "./FieldsWatcher";
|
|
20
|
+
import { useFormCollapseListHooks } from "./hooks";
|
|
17
21
|
import { useStyles } from "./style";
|
|
22
|
+
import { FIELD_KEY_PATH, toRowKey } from "./utils";
|
|
18
23
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
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
|
+
};
|
|
37
|
+
export var FormCollapseList = /*#__PURE__*/memo(function (_ref) {
|
|
38
|
+
var collapsible = _ref.collapsible,
|
|
39
|
+
extra = _ref.extra,
|
|
21
40
|
expandIcon = _ref.expandIcon,
|
|
22
41
|
icon = _ref.icon,
|
|
23
42
|
title = _ref.title,
|
|
@@ -39,12 +58,51 @@ export var FormCollapseList = function FormCollapseList(_ref) {
|
|
|
39
58
|
_ref$fieldRemoveButto = _ref.fieldRemoveButton,
|
|
40
59
|
fieldRemoveButton = _ref$fieldRemoveButto === void 0 ? true : _ref$fieldRemoveButto,
|
|
41
60
|
style = _ref.style,
|
|
61
|
+
defaultExpandAllRows = _ref.defaultExpandAllRows,
|
|
62
|
+
_ref$indentSize = _ref.indentSize,
|
|
63
|
+
indentSize = _ref$indentSize === void 0 ? 16 : _ref$indentSize,
|
|
64
|
+
_ref$childrenColumnNa = _ref.childrenColumnName,
|
|
65
|
+
childrenColumnName = _ref$childrenColumnNa === void 0 ? 'children' : _ref$childrenColumnNa,
|
|
66
|
+
_ref$rowHoverable = _ref.rowHoverable,
|
|
67
|
+
rowHoverable = _ref$rowHoverable === void 0 ? true : _ref$rowHoverable,
|
|
42
68
|
formListProps = _objectWithoutProperties(_ref, _excluded);
|
|
43
69
|
var _useStyles = useStyles(),
|
|
70
|
+
cx = _useStyles.cx,
|
|
44
71
|
styles = _useStyles.styles;
|
|
45
72
|
var listAdd = useRef();
|
|
46
73
|
var form = Form.useFormInstance();
|
|
47
|
-
var
|
|
74
|
+
var _useFormCollapseListH = useFormCollapseListHooks(name, childrenColumnName, columns),
|
|
75
|
+
values = _useFormCollapseListH.values,
|
|
76
|
+
updateValues = _useFormCollapseListH.updateValues,
|
|
77
|
+
expandedRowKeys = _useFormCollapseListH.expandedRowKeys,
|
|
78
|
+
setExpandedRowKeys = _useFormCollapseListH.setExpandedRowKeys,
|
|
79
|
+
fieldValuesToDataSource = _useFormCollapseListH.fieldValuesToDataSource,
|
|
80
|
+
getFormListOperation = _useFormCollapseListH.getFormListOperation,
|
|
81
|
+
getFieldPath = _useFormCollapseListH.getFieldPath,
|
|
82
|
+
firstColumnFormItemName = _useFormCollapseListH.firstColumnFormItemName;
|
|
83
|
+
var _useMemo = useMemo(function () {
|
|
84
|
+
return fieldValuesToDataSource(values);
|
|
85
|
+
}, [fieldValuesToDataSource, values]),
|
|
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]);
|
|
92
|
+
// 设置初始值以及在 readOnly 变化时更新 values
|
|
93
|
+
useEffect(function () {
|
|
94
|
+
updateValues();
|
|
95
|
+
}, [updateValues, readOnly]);
|
|
96
|
+
|
|
97
|
+
// 设置默认展开的 keys
|
|
98
|
+
useEffect(function () {
|
|
99
|
+
var fields = form.getFieldValue(name);
|
|
100
|
+
var _fieldValuesToDataSou = fieldValuesToDataSource(fields),
|
|
101
|
+
allExpandRowKeys = _fieldValuesToDataSou.allExpandRowKeys;
|
|
102
|
+
if (defaultExpandAllRows) {
|
|
103
|
+
setExpandedRowKeys(allExpandRowKeys);
|
|
104
|
+
}
|
|
105
|
+
}, [defaultExpandAllRows, fieldValuesToDataSource, form, name, setExpandedRowKeys]);
|
|
48
106
|
var getAddParams = useCallback(function () {
|
|
49
107
|
if (!addParams) {
|
|
50
108
|
return [];
|
|
@@ -53,62 +111,80 @@ export var FormCollapseList = function FormCollapseList(_ref) {
|
|
|
53
111
|
return [params.defaultValue, params.insertIndex];
|
|
54
112
|
}, [addParams]);
|
|
55
113
|
var handleOnRemove = useCallback(function (fieldName) {
|
|
56
|
-
var
|
|
57
|
-
return onRemove === null || onRemove === void 0 ? void 0 : onRemove(
|
|
114
|
+
var value = form.getFieldValue([name, fieldName]);
|
|
115
|
+
return onRemove === null || onRemove === void 0 ? void 0 : onRemove(value);
|
|
58
116
|
}, [form, name, onRemove]);
|
|
117
|
+
|
|
118
|
+
// 默认增加一行的处理
|
|
59
119
|
useEffect(function () {
|
|
60
120
|
var _form$getFieldValue;
|
|
61
121
|
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
122
|
var _listAdd$current;
|
|
63
123
|
(_listAdd$current = listAdd.current) === null || _listAdd$current === void 0 || _listAdd$current.call.apply(_listAdd$current, [listAdd].concat(_toConsumableArray(getAddParams())));
|
|
124
|
+
// Scroll and focus new item which is just added
|
|
125
|
+
setTimeout(function () {
|
|
126
|
+
form.focusField([name, 0, firstColumnFormItemName]);
|
|
127
|
+
}, 200);
|
|
64
128
|
}
|
|
65
|
-
}, [addOneFieldDefault, getAddParams, form, name]);
|
|
66
|
-
return /*#__PURE__*/
|
|
129
|
+
}, [addOneFieldDefault, getAddParams, form, name, firstColumnFormItemName, updateValues]);
|
|
130
|
+
return /*#__PURE__*/_jsxs(CollapseGroup, {
|
|
67
131
|
extra: extra === undefined ? name && !readOnly && /*#__PURE__*/_jsx(Tooltip, {
|
|
68
132
|
title: maxFileds && "\u6700\u591A\u6DFB\u52A0 ".concat(maxFileds, " \u9879"),
|
|
69
133
|
children: /*#__PURE__*/_jsx(Button, {
|
|
70
|
-
disabled: disabled || !!(maxFileds && (
|
|
134
|
+
disabled: disabled || !!(maxFileds && (values === null || values === void 0 ? void 0 : values.length) === maxFileds),
|
|
71
135
|
icon: /*#__PURE__*/_jsx(PlusOutlined, {}),
|
|
72
136
|
onClick: function onClick(e) {
|
|
73
137
|
var _listAdd$current2;
|
|
74
138
|
e.stopPropagation();
|
|
75
139
|
(_listAdd$current2 = listAdd.current) === null || _listAdd$current2 === void 0 || _listAdd$current2.call.apply(_listAdd$current2, [listAdd].concat(_toConsumableArray(getAddParams())));
|
|
140
|
+
// Scroll and focus new item which is just added
|
|
141
|
+
setTimeout(function () {
|
|
142
|
+
form.focusField([name, form.getFieldValue(name).length - 1, firstColumnFormItemName]);
|
|
143
|
+
}, 200);
|
|
76
144
|
},
|
|
77
145
|
size: "small",
|
|
78
146
|
type: "text"
|
|
79
147
|
})
|
|
80
148
|
}) : extra,
|
|
81
149
|
className: className,
|
|
150
|
+
collapsible: collapsible,
|
|
82
151
|
expandIcon: expandIcon,
|
|
83
152
|
icon: icon,
|
|
84
153
|
title: title,
|
|
85
154
|
variant: variant,
|
|
86
155
|
defaultActive: defaultActive,
|
|
87
156
|
style: style,
|
|
88
|
-
children:
|
|
157
|
+
children: [!isTreeMode && /*#__PURE__*/_jsx(FormCollapseListFieldsWatcher, {
|
|
158
|
+
name: name,
|
|
159
|
+
update: updateValues
|
|
160
|
+
}), name ? /*#__PURE__*/_jsx(Form.List, _objectSpread(_objectSpread({
|
|
89
161
|
name: name
|
|
90
162
|
}, formListProps), {}, {
|
|
91
|
-
children: function children(fields,
|
|
92
|
-
var add =
|
|
93
|
-
remove =
|
|
94
|
-
listAdd.current =
|
|
163
|
+
children: function children(fields, operation) {
|
|
164
|
+
var add = operation.add,
|
|
165
|
+
remove = operation.remove;
|
|
166
|
+
listAdd.current = function (defaultValue, insertIndex) {
|
|
167
|
+
add(defaultValue, insertIndex);
|
|
168
|
+
updateValues();
|
|
169
|
+
};
|
|
95
170
|
|
|
96
171
|
// @Todo: support sort
|
|
97
172
|
return /*#__PURE__*/_jsx(Table, {
|
|
98
173
|
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
|
-
|
|
174
|
+
columns: [].concat(_toConsumableArray(columns.map(function (_ref2) {
|
|
175
|
+
var label = _ref2.label,
|
|
176
|
+
itemName = _ref2.name,
|
|
177
|
+
fieldRender = _ref2.render,
|
|
178
|
+
dependencies = _ref2.dependencies,
|
|
179
|
+
rules = _ref2.rules,
|
|
180
|
+
align = _ref2.align,
|
|
181
|
+
ellipsis = _ref2.ellipsis,
|
|
182
|
+
fixed = _ref2.fixed,
|
|
183
|
+
responsive = _ref2.responsive,
|
|
184
|
+
shouldCellUpdate = _ref2.shouldCellUpdate,
|
|
185
|
+
width = _ref2.width,
|
|
186
|
+
className = _ref2.className,
|
|
187
|
+
itemProps = _objectWithoutProperties(_ref2, _excluded2);
|
|
112
188
|
return {
|
|
113
189
|
title: label,
|
|
114
190
|
dataIndex: itemName,
|
|
@@ -118,41 +194,53 @@ export var FormCollapseList = function FormCollapseList(_ref) {
|
|
|
118
194
|
responsive: responsive,
|
|
119
195
|
shouldCellUpdate: shouldCellUpdate,
|
|
120
196
|
width: width,
|
|
121
|
-
render: function render(
|
|
122
|
-
var
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
var
|
|
127
|
-
|
|
197
|
+
render: function render(text, record, index) {
|
|
198
|
+
var field = fields[index] || {};
|
|
199
|
+
var fieldName = field.name;
|
|
200
|
+
var fieldKeyPath = record[FIELD_KEY_PATH];
|
|
201
|
+
var fieldPath = [name].concat(_toConsumableArray(getFieldPath(fieldKeyPath)));
|
|
202
|
+
var parentFieldPath = fieldPath.slice(0, -1);
|
|
203
|
+
var key = field.key,
|
|
204
|
+
restField = _objectWithoutProperties(field, _excluded3);
|
|
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);
|
|
206
|
+
if (!itemName) {
|
|
128
207
|
return /*#__PURE__*/_jsx(Flex, {
|
|
129
208
|
align: "center",
|
|
130
|
-
className: styles.noFormItem,
|
|
131
|
-
children:
|
|
209
|
+
className: cx(styles.noFormItem, className),
|
|
210
|
+
children: children
|
|
132
211
|
});
|
|
133
212
|
}
|
|
134
|
-
if (
|
|
213
|
+
if (children !== undefined && _typeof(children) !== 'object') {
|
|
135
214
|
return /*#__PURE__*/_jsx(Flex, {
|
|
136
215
|
align: "center",
|
|
137
|
-
className: styles.noFormItem,
|
|
138
|
-
children: children
|
|
216
|
+
className: cx(styles.noFormItem, className),
|
|
217
|
+
children: children.toString()
|
|
139
218
|
});
|
|
140
219
|
}
|
|
141
|
-
var chidrenProps = {
|
|
142
|
-
|
|
143
|
-
disabled
|
|
144
|
-
}
|
|
220
|
+
var chidrenProps = {};
|
|
221
|
+
if (disabled !== undefined) {
|
|
222
|
+
chidrenProps.disabled = disabled;
|
|
223
|
+
}
|
|
145
224
|
if (readOnly === true) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
225
|
+
return /*#__PURE__*/_jsx(Flex, {
|
|
226
|
+
align: "center",
|
|
227
|
+
className: cx(styles.readOnlyItem, className),
|
|
228
|
+
children: text !== null && text !== void 0 ? text : /*#__PURE__*/_jsx(Text, {
|
|
229
|
+
type: "secondary",
|
|
230
|
+
children: "-"
|
|
231
|
+
})
|
|
232
|
+
});
|
|
149
233
|
}
|
|
150
|
-
return /*#__PURE__*/_jsx(Form.Item, _objectSpread(_objectSpread(_objectSpread({
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
234
|
+
return /*#__PURE__*/_jsx(Form.Item, _objectSpread(_objectSpread(_objectSpread({
|
|
235
|
+
className: className
|
|
236
|
+
}, restField), {}, {
|
|
237
|
+
dependencies: typeof dependencies === 'function' ? dependencies(parentFieldPath, index) : dependencies,
|
|
238
|
+
name: getFieldPath(fieldKeyPath, itemName)
|
|
239
|
+
// label={getFieldPath(fieldKeyPath, itemName).join('/')}
|
|
240
|
+
,
|
|
241
|
+
rules: typeof rules === 'function' ? rules(parentFieldPath, index) : rules
|
|
154
242
|
}, itemProps), {}, {
|
|
155
|
-
children: children
|
|
243
|
+
children: children ? ( /*#__PURE__*/React.cloneElement(children, chidrenProps)) : /*#__PURE__*/_jsx(FieldText, {})
|
|
156
244
|
}), key);
|
|
157
245
|
}
|
|
158
246
|
};
|
|
@@ -160,7 +248,11 @@ export var FormCollapseList = function FormCollapseList(_ref) {
|
|
|
160
248
|
title: '',
|
|
161
249
|
dataIndex: 'del',
|
|
162
250
|
render: function render(_text, _record, index) {
|
|
163
|
-
var
|
|
251
|
+
var field = fields[index];
|
|
252
|
+
if (!field) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
var fieldName = field.name;
|
|
164
256
|
return /*#__PURE__*/_jsx(Form.Item, {
|
|
165
257
|
children: /*#__PURE__*/_jsx(Button, {
|
|
166
258
|
disabled: disabled || disableRemoveWhenOneField && fields.length === 1,
|
|
@@ -178,6 +270,7 @@ export var FormCollapseList = function FormCollapseList(_ref) {
|
|
|
178
270
|
isRemove = _context.sent;
|
|
179
271
|
if (isRemove !== false) {
|
|
180
272
|
remove(fieldName);
|
|
273
|
+
updateValues();
|
|
181
274
|
}
|
|
182
275
|
case 4:
|
|
183
276
|
case "end":
|
|
@@ -192,18 +285,29 @@ export var FormCollapseList = function FormCollapseList(_ref) {
|
|
|
192
285
|
}]).filter(function (c) {
|
|
193
286
|
return !!c;
|
|
194
287
|
}),
|
|
195
|
-
dataSource:
|
|
288
|
+
dataSource: dataSource,
|
|
289
|
+
expandable: {
|
|
290
|
+
expandedRowKeys: expandedRowKeys,
|
|
291
|
+
childrenColumnName: childrenColumnName,
|
|
292
|
+
onExpandedRowsChange: function onExpandedRowsChange(expandedKeys) {
|
|
293
|
+
setExpandedRowKeys(expandedKeys);
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
indentSize: indentSize,
|
|
196
297
|
locale: {
|
|
197
298
|
emptyText: empty
|
|
198
299
|
},
|
|
199
300
|
pagination: false,
|
|
200
|
-
rowHoverable:
|
|
301
|
+
rowHoverable: rowHoverable,
|
|
302
|
+
rowKey: function rowKey(row) {
|
|
303
|
+
return toRowKey(row[FIELD_KEY_PATH]);
|
|
304
|
+
},
|
|
201
305
|
size: "small"
|
|
202
306
|
});
|
|
203
307
|
}
|
|
204
308
|
})) : /*#__PURE__*/_jsx("div", {
|
|
205
309
|
className: styles.empty,
|
|
206
310
|
children: empty
|
|
207
|
-
})
|
|
311
|
+
})]
|
|
208
312
|
});
|
|
209
|
-
};
|
|
313
|
+
});
|
|
@@ -2,4 +2,5 @@ export declare const useStyles: (props?: unknown) => import("antd-style").Return
|
|
|
2
2
|
empty: import("antd-style").SerializedStyles;
|
|
3
3
|
list: import("antd-style").SerializedStyles;
|
|
4
4
|
noFormItem: import("antd-style").SerializedStyles;
|
|
5
|
+
readOnlyItem: import("antd-style").SerializedStyles;
|
|
5
6
|
}>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
|
|
2
|
-
var _templateObject, _templateObject2, _templateObject3;
|
|
2
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4;
|
|
3
3
|
import { createStyles } from 'antd-style';
|
|
4
4
|
export var useStyles = createStyles(function (_ref) {
|
|
5
5
|
var css = _ref.css,
|
|
@@ -7,7 +7,8 @@ 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),
|
|
11
|
-
noFormItem: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n height: ", "px;\n color: ", ";\n "])), token.controlHeight, 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 .", "-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
|
+
noFormItem: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n height: ", "px;\n color: ", ";\n "])), token.controlHeight, token.colorTextTertiary),
|
|
12
|
+
readOnlyItem: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n height: ", "px;\n color: ", ";\n "])), token.controlHeight, token.colorTextBase)
|
|
12
13
|
};
|
|
13
14
|
});
|