@canlooks/can-ui 0.0.51 → 0.0.53
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/dist/cjs/components/curd/curdDialog.js +17 -10
- package/dist/cjs/components/optionsBase/optionsBase.js +1 -3
- package/dist/cjs/utils/curd.d.ts +3 -2
- package/dist/esm/components/curd/curdDialog.js +9 -2
- package/dist/esm/components/optionsBase/optionsBase.js +1 -3
- package/dist/esm/utils/curd.d.ts +3 -2
- package/documentation/dist/assets/{index-Db8Y9DzG.js → index-0lpazctB.js} +97 -97
- package/documentation/dist/index.html +1 -1
- package/package.json +1 -1
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CurdDialog = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
|
-
const react_1 = require("react");
|
|
5
|
+
const react_1 = require("@emotion/react");
|
|
6
|
+
const react_2 = require("react");
|
|
6
7
|
const dialog_1 = require("../dialog");
|
|
7
8
|
const form_1 = require("../form");
|
|
8
9
|
const curd_1 = require("./curd");
|
|
@@ -13,7 +14,7 @@ const curd_style_1 = require("./curd.style");
|
|
|
13
14
|
const pickerDialog_1 = require("../pickerDialog");
|
|
14
15
|
const __1 = require("../..");
|
|
15
16
|
const faCopy_1 = require("@fortawesome/free-regular-svg-icons/faCopy");
|
|
16
|
-
exports.CurdDialog = (0,
|
|
17
|
+
exports.CurdDialog = (0, react_2.memo)(({ ref, onFinish,
|
|
17
18
|
// 继承来的属性
|
|
18
19
|
curdProps, ...props }) => {
|
|
19
20
|
const { columns, postData, copyable, titleKey, formProps, formRef, dataName = '', createName = '添加', updateName = '编辑' } = curdProps;
|
|
@@ -21,8 +22,8 @@ curdProps, ...props }) => {
|
|
|
21
22
|
* ----------------------------------------------------------------
|
|
22
23
|
* ref与promise部分
|
|
23
24
|
*/
|
|
24
|
-
const innerFormRef = (0,
|
|
25
|
-
const resolvers = (0,
|
|
25
|
+
const innerFormRef = (0, react_2.useRef)(null);
|
|
26
|
+
const resolvers = (0, react_2.useRef)(void 0);
|
|
26
27
|
const [innerOpen, setInnerOpen] = (0, utils_1.useControlled)(props.defaultOpen, props.open);
|
|
27
28
|
const closeHandler = (reason) => {
|
|
28
29
|
if (reason === 'confirmed') {
|
|
@@ -35,7 +36,7 @@ curdProps, ...props }) => {
|
|
|
35
36
|
});
|
|
36
37
|
setInnerOpen(false);
|
|
37
38
|
};
|
|
38
|
-
(0,
|
|
39
|
+
(0, react_2.useImperativeHandle)(ref, () => ({
|
|
39
40
|
open(row) {
|
|
40
41
|
innerFormRef.current?.resetForm();
|
|
41
42
|
setInnerOpen(true);
|
|
@@ -48,16 +49,22 @@ curdProps, ...props }) => {
|
|
|
48
49
|
* ----------------------------------------------------------------
|
|
49
50
|
* 表单项
|
|
50
51
|
*/
|
|
51
|
-
const [activeRow, setActiveRow] = (0,
|
|
52
|
+
const [activeRow, setActiveRow] = (0, react_2.useState)();
|
|
52
53
|
const [transforming, setFormValue] = (0, utils_1.useLoading)(async (row) => {
|
|
53
54
|
const formValue = postData && row ? await postData(row) : row;
|
|
54
55
|
formValue && innerFormRef.current?.setFormValue(formValue);
|
|
55
56
|
});
|
|
56
|
-
(0,
|
|
57
|
+
(0, react_2.useEffect)(() => {
|
|
57
58
|
innerOpen.current && setFormValue(activeRow);
|
|
58
59
|
}, [innerOpen.current]); // 依赖innerOpen而不依赖activeRow的原因是,有可能连续两次打开的activeRow是相同的
|
|
59
|
-
const renderedFormItems = (0,
|
|
60
|
-
return (0, utils_1.columnsToFormItem)(columns, activeRow)?.map(
|
|
60
|
+
const renderedFormItems = (0, react_2.useMemo)(() => {
|
|
61
|
+
return (0, utils_1.columnsToFormItem)(columns, activeRow)?.map(col => {
|
|
62
|
+
if ((0, react_2.isValidElement)(col)) {
|
|
63
|
+
return col;
|
|
64
|
+
}
|
|
65
|
+
const { key, ...p } = col;
|
|
66
|
+
return (0, react_1.createElement)(form_1.FormItem, { ...p, key: key });
|
|
67
|
+
});
|
|
61
68
|
}, [columns, activeRow]);
|
|
62
69
|
/**
|
|
63
70
|
* ----------------------------------------------------------------
|
|
@@ -76,7 +83,7 @@ curdProps, ...props }) => {
|
|
|
76
83
|
* ----------------------------------------------------------------
|
|
77
84
|
* 复制
|
|
78
85
|
*/
|
|
79
|
-
const pickerDialogRef = (0,
|
|
86
|
+
const pickerDialogRef = (0, react_2.useRef)(null);
|
|
80
87
|
const copiedHandler = (checked, value, row) => {
|
|
81
88
|
const title = !(0, utils_1.isUnset)(titleKey) ? row[titleKey] : void 0;
|
|
82
89
|
typeof title === 'string'
|
|
@@ -96,9 +96,7 @@ searchValue, selectedValue, onToggleSelected, ...props }) => {
|
|
|
96
96
|
return filteredOptions.map((opt, index) => {
|
|
97
97
|
const value = opt[primaryKey];
|
|
98
98
|
const label = opt[labelKey] ?? value;
|
|
99
|
-
return ((0, jsx_runtime_1.jsx)(menuItem_1.MenuItem, { value: value,
|
|
100
|
-
// 手动传递而不使用{...opt},可避免多余的props挂载上DOM
|
|
101
|
-
size: opt.size, color: opt.color, emphasized: opt.emphasized, disabled: opt.disabled, checkboxProps: opt.checkboxProps, ellipsis: opt.ellipsis, prefix: opt.prefix, suffix: opt.suffix, ...makeProps({
|
|
99
|
+
return ((0, jsx_runtime_1.jsx)(menuItem_1.MenuItem, { value: value, ...opt, ...makeProps({
|
|
102
100
|
opt,
|
|
103
101
|
label,
|
|
104
102
|
value,
|
package/dist/cjs/utils/curd.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
1
2
|
import { CurdColumn, CurdFormItemProps, CurdProps } from '../components/curd';
|
|
2
3
|
import { ColumnType, RowType } from '../components/dataGrid';
|
|
3
4
|
import { Id, Obj } from '../types';
|
|
@@ -6,13 +7,13 @@ import { FormValue } from '../components/form';
|
|
|
6
7
|
* 将Curd的Columns转换为FilterItem
|
|
7
8
|
* @param columns
|
|
8
9
|
*/
|
|
9
|
-
export declare function columnsToFilterItem(columns?: (CurdColumn<any> | symbol)[]): CurdFormItemProps[] | undefined;
|
|
10
|
+
export declare function columnsToFilterItem(columns?: (CurdColumn<any> | symbol)[]): (ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | CurdFormItemProps)[] | undefined;
|
|
10
11
|
/**
|
|
11
12
|
* 将Curd的Columns转换为FormItem
|
|
12
13
|
* @param columns
|
|
13
14
|
* @param row
|
|
14
15
|
*/
|
|
15
|
-
export declare function columnsToFormItem(columns?: (CurdColumn<any> | symbol)[], row?: Obj): CurdFormItemProps[] | undefined;
|
|
16
|
+
export declare function columnsToFormItem(columns?: (CurdColumn<any> | symbol)[], row?: Obj): (ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | CurdFormItemProps)[] | undefined;
|
|
16
17
|
/**
|
|
17
18
|
* 统一处理Columns
|
|
18
19
|
*/
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { createElement as _createElement } from "@emotion/react";
|
|
3
|
+
import { memo, useEffect, useImperativeHandle, useMemo, useRef, useState, isValidElement } from 'react';
|
|
3
4
|
import { Dialog } from '../dialog';
|
|
4
5
|
import { Form, FormItem } from '../form';
|
|
5
6
|
import { Curd } from './curd';
|
|
@@ -54,7 +55,13 @@ curdProps, ...props }) => {
|
|
|
54
55
|
innerOpen.current && setFormValue(activeRow);
|
|
55
56
|
}, [innerOpen.current]); // 依赖innerOpen而不依赖activeRow的原因是,有可能连续两次打开的activeRow是相同的
|
|
56
57
|
const renderedFormItems = useMemo(() => {
|
|
57
|
-
return columnsToFormItem(columns, activeRow)?.map(
|
|
58
|
+
return columnsToFormItem(columns, activeRow)?.map(col => {
|
|
59
|
+
if (isValidElement(col)) {
|
|
60
|
+
return col;
|
|
61
|
+
}
|
|
62
|
+
const { key, ...p } = col;
|
|
63
|
+
return _createElement(FormItem, { ...p, key: key });
|
|
64
|
+
});
|
|
58
65
|
}, [columns, activeRow]);
|
|
59
66
|
/**
|
|
60
67
|
* ----------------------------------------------------------------
|
|
@@ -93,9 +93,7 @@ searchValue, selectedValue, onToggleSelected, ...props }) => {
|
|
|
93
93
|
return filteredOptions.map((opt, index) => {
|
|
94
94
|
const value = opt[primaryKey];
|
|
95
95
|
const label = opt[labelKey] ?? value;
|
|
96
|
-
return (_jsx(MenuItem, { value: value,
|
|
97
|
-
// 手动传递而不使用{...opt},可避免多余的props挂载上DOM
|
|
98
|
-
size: opt.size, color: opt.color, emphasized: opt.emphasized, disabled: opt.disabled, checkboxProps: opt.checkboxProps, ellipsis: opt.ellipsis, prefix: opt.prefix, suffix: opt.suffix, ...makeProps({
|
|
96
|
+
return (_jsx(MenuItem, { value: value, ...opt, ...makeProps({
|
|
99
97
|
opt,
|
|
100
98
|
label,
|
|
101
99
|
value,
|
package/dist/esm/utils/curd.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
1
2
|
import { CurdColumn, CurdFormItemProps, CurdProps } from '../components/curd';
|
|
2
3
|
import { ColumnType, RowType } from '../components/dataGrid';
|
|
3
4
|
import { Id, Obj } from '../types';
|
|
@@ -6,13 +7,13 @@ import { FormValue } from '../components/form';
|
|
|
6
7
|
* 将Curd的Columns转换为FilterItem
|
|
7
8
|
* @param columns
|
|
8
9
|
*/
|
|
9
|
-
export declare function columnsToFilterItem(columns?: (CurdColumn<any> | symbol)[]): CurdFormItemProps[] | undefined;
|
|
10
|
+
export declare function columnsToFilterItem(columns?: (CurdColumn<any> | symbol)[]): (ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | CurdFormItemProps)[] | undefined;
|
|
10
11
|
/**
|
|
11
12
|
* 将Curd的Columns转换为FormItem
|
|
12
13
|
* @param columns
|
|
13
14
|
* @param row
|
|
14
15
|
*/
|
|
15
|
-
export declare function columnsToFormItem(columns?: (CurdColumn<any> | symbol)[], row?: Obj): CurdFormItemProps[] | undefined;
|
|
16
|
+
export declare function columnsToFormItem(columns?: (CurdColumn<any> | symbol)[], row?: Obj): (ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | CurdFormItemProps)[] | undefined;
|
|
16
17
|
/**
|
|
17
18
|
* 统一处理Columns
|
|
18
19
|
*/
|