@zat-design/sisyphus-react 4.3.0-beta.10 → 4.3.0-beta.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.
@@ -77,37 +77,31 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
77
77
  component?: React.ReactNode | ReactiveFunction<any, React.ReactNode>;
78
78
  id?: string;
79
79
  className?: string;
80
- children?: React.ReactNode | ((form: FormInstance<any>) => React.ReactNode);
81
80
  hidden?: boolean;
82
81
  style?: React.CSSProperties;
82
+ children?: React.ReactNode | ((form: FormInstance<any>) => React.ReactNode);
83
83
  onReset?: () => void;
84
84
  prefixCls?: string;
85
85
  rootClassName?: string;
86
- layout?: import("antd/es/form/Form").FormItemLayout;
87
- help?: React.ReactNode;
86
+ status?: "" | "warning" | "error" | "success" | "validating";
88
87
  vertical?: boolean;
89
- preserve?: boolean;
90
- trim?: boolean;
91
- normalize?: (value: any, prevValue: any, allValues: import("@rc-component/form/lib/interface").Store) => any;
92
- htmlFor?: string;
93
- trigger?: string;
94
88
  isView?: boolean;
95
- status?: "" | "warning" | "error" | "success" | "validating";
96
- getValueProps?: ((value: any) => Record<string, unknown>) & ((value: any) => Record<string, unknown>);
97
- desensitization?: [number, number] | ReactiveFunction<any, [number, number]>;
98
- validateTrigger?: string | false | string[];
99
- clearNotShow?: boolean;
100
- labelAlign?: import("antd/es/form/interface").FormLabelAlign;
101
89
  colon?: boolean;
90
+ htmlFor?: string;
91
+ labelAlign?: import("antd/es/form/interface").FormLabelAlign;
102
92
  labelCol?: import("antd").ColProps;
103
- wrapperCol?: import("antd").ColProps;
104
93
  getValueFromEvent?: (...args: import("@rc-component/form/lib/interface").EventArgs) => any;
94
+ normalize?: (value: any, prevValue: any, allValues: import("@rc-component/form/lib/interface").Store) => any;
105
95
  shouldUpdate?: import("@rc-component/form/lib/Field").ShouldUpdate<any>;
96
+ trigger?: string;
97
+ validateTrigger?: string | false | string[];
106
98
  validateDebounce?: number;
107
99
  valuePropName?: string;
100
+ getValueProps?: ((value: any) => Record<string, unknown>) & ((value: any) => Record<string, unknown>);
108
101
  messageVariables?: Record<string, string>;
109
102
  initialValue?: any;
110
103
  onMetaChange?: (meta: import("@rc-component/form/lib/Field").MetaEvent) => void;
104
+ preserve?: boolean;
111
105
  isListField?: boolean;
112
106
  isList?: boolean;
113
107
  noStyle?: boolean;
@@ -115,6 +109,9 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
115
109
  icons: import("antd/es/form/FormItem").FeedbackIcons;
116
110
  };
117
111
  validateStatus?: "" | "warning" | "error" | "success" | "validating";
112
+ layout?: import("antd/es/form/Form").FormItemLayout;
113
+ wrapperCol?: import("antd").ColProps;
114
+ help?: React.ReactNode;
118
115
  fieldId?: string;
119
116
  valueType?: import("../../../render/propsType").ProFormValueType;
120
117
  switchValue?: [any, any];
@@ -124,9 +121,12 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
124
121
  index?: number;
125
122
  }) => string | React.ReactElement<any, any>;
126
123
  viewType?: import("../../../render/propsType").ViewType;
124
+ trim?: boolean;
127
125
  upperCase?: boolean;
128
126
  toISOString?: boolean;
129
127
  toCSTString?: boolean;
128
+ clearNotShow?: boolean;
129
+ desensitization?: [number, number] | ReactiveFunction<any, [number, number]>;
130
130
  name: any;
131
131
  dependencies: any[];
132
132
  tooltip: string | {
@@ -141,7 +141,7 @@ export declare const useFormItemProps: (column: FlexibleGroupColumnType, context
141
141
  * 创建组件属性
142
142
  */
143
143
  export declare const createComponentProps: (column: FlexibleGroupColumnType, formItemProps: any) => {
144
- componentProps: import("lodash").Omit<any, "format" | "clearNotShow" | "valueType" | "switchValue" | "dependNames" | "toISOString" | "toCSTString" | "precision">;
144
+ componentProps: import("lodash").Omit<any, "format" | "valueType" | "switchValue" | "dependNames" | "toISOString" | "toCSTString" | "clearNotShow" | "precision">;
145
145
  formItemTransform: {
146
146
  getValueProps: any;
147
147
  normalize: any;
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ interface EditIconProps {
3
+ onClick: () => void;
4
+ }
5
+ declare const EditIcon: React.FC<EditIconProps>;
6
+ export default EditIcon;
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import ProIcon from "../../../ProIcon";
3
+ import editSvg from "../../../assets/edit.svg";
4
+ import styles from "./index.less";
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ const EditIcon = ({
7
+ onClick
8
+ }) => {
9
+ return /*#__PURE__*/_jsx("span", {
10
+ className: styles['editable-cell-edit-icon'],
11
+ onClick: onClick,
12
+ children: /*#__PURE__*/_jsx(ProIcon, {
13
+ src: editSvg,
14
+ size: "20px",
15
+ buttonIcon: false
16
+ })
17
+ });
18
+ };
19
+ export default EditIcon;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import type { EditableCellProps } from './propsType';
3
+ declare const EditableCell: React.FC<EditableCellProps>;
4
+ export default EditableCell;
@@ -0,0 +1,87 @@
1
+ import _isEqual from "lodash/isEqual";
2
+ import React, { useState, useRef } from 'react';
3
+ import { Form } from 'antd';
4
+ import * as componentMap from "../../../ProForm/components";
5
+ import EditIcon from "./EditIcon";
6
+ import styles from "./index.less";
7
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
8
+ const EditableCell = ({
9
+ value,
10
+ record,
11
+ index,
12
+ dataIndex,
13
+ editConfig,
14
+ displayContent
15
+ }) => {
16
+ const [editing, setEditing] = useState(false);
17
+ const [form] = Form.useForm();
18
+ const snapshotRef = useRef(value);
19
+ const fieldName = Array.isArray(dataIndex) ? dataIndex.join('_') : dataIndex;
20
+ const {
21
+ type = 'Input',
22
+ fieldProps = {},
23
+ rules,
24
+ required,
25
+ valueType
26
+ } = editConfig;
27
+ const {
28
+ onBlur: onBlurCallback,
29
+ ...restFieldProps
30
+ } = fieldProps;
31
+ const Component = componentMap[type] ?? componentMap.Input;
32
+ const handleEditIconClick = () => {
33
+ snapshotRef.current = value;
34
+ form.setFieldsValue({
35
+ [fieldName]: value
36
+ });
37
+ setEditing(true);
38
+ };
39
+ const handleBlur = async () => {
40
+ try {
41
+ const values = await form.validateFields();
42
+ const newValue = values[fieldName];
43
+ if (_isEqual(newValue, snapshotRef.current)) {
44
+ setEditing(false);
45
+ return;
46
+ }
47
+ if (!onBlurCallback) {
48
+ setEditing(false);
49
+ return;
50
+ }
51
+ const result = onBlurCallback(newValue, record, index);
52
+ if (result instanceof Promise) {
53
+ await result;
54
+ }
55
+ setEditing(false);
56
+ } catch {
57
+ // Validation failed - stay in edit mode
58
+ }
59
+ };
60
+ if (!editing) {
61
+ return /*#__PURE__*/_jsxs("span", {
62
+ className: styles['editable-cell-wrapper'],
63
+ children: [/*#__PURE__*/_jsx("span", {
64
+ children: displayContent ?? '-'
65
+ }), /*#__PURE__*/_jsx(EditIcon, {
66
+ onClick: handleEditIconClick
67
+ })]
68
+ });
69
+ }
70
+ return /*#__PURE__*/_jsx(Form, {
71
+ form: form,
72
+ component: false,
73
+ children: /*#__PURE__*/_jsx(Form.Item, {
74
+ name: fieldName,
75
+ rules: rules,
76
+ required: required,
77
+ noStyle: true,
78
+ children: /*#__PURE__*/_jsx(Component, {
79
+ ...restFieldProps,
80
+ valueType: valueType,
81
+ autoFocus: true,
82
+ onBlur: handleBlur
83
+ })
84
+ })
85
+ });
86
+ };
87
+ export default EditableCell;
@@ -0,0 +1,29 @@
1
+ .editable-cell-wrapper {
2
+ display: flex;
3
+ align-items: center;
4
+ width: 100%;
5
+ justify-content: space-between;
6
+ gap: 4px;
7
+ }
8
+
9
+ .editable-cell-edit-icon {
10
+ display: inline-flex;
11
+ align-items: center;
12
+ cursor: pointer;
13
+ visibility: hidden;
14
+ color: rgba(0, 0, 0, 0.65);
15
+ flex-shrink: 0;
16
+
17
+ svg path {
18
+ fill: currentColor !important;
19
+ }
20
+
21
+ &:hover {
22
+ color: var(--zaui-brand, #006aff);
23
+ }
24
+ }
25
+
26
+ td:hover .editable-cell-edit-icon {
27
+ visibility: visible;
28
+ }
29
+
@@ -0,0 +1,10 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { EditTableCellConfig } from '../../propsType';
3
+ export interface EditableCellProps {
4
+ value: any;
5
+ record: any;
6
+ index: number;
7
+ dataIndex: string | string[];
8
+ editConfig: EditTableCellConfig;
9
+ displayContent: ReactNode;
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -16,6 +16,7 @@ import { Space } from 'antd';
16
16
  import { tools } from '@zat-design/utils';
17
17
  import TooltipTitle from "../TooltipTitle";
18
18
  import RenderColumn from "../RenderColumn";
19
+ import EditableCell from "../EditableCell";
19
20
  import { getDecimalDigits, getOriginalValue } from "../../utils";
20
21
  import { isEmpty } from "../../../utils";
21
22
  import getEnumLabel from "../../../ProEnum/utils/getEnumLabel";
@@ -24,7 +25,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
24
25
  const isReactElement = element => /*#__PURE__*/isValidElement(element);
25
26
 
26
27
  // 需要从 otherProps 中排除的属性(不应传递给 RenderColumn)
27
- const EXCLUDED_PROPS = ['key', 'render', 'children', 'onCell', 'onHeaderCell'];
28
+ const EXCLUDED_PROPS = ['key', 'render', 'children', 'onCell', 'onHeaderCell', 'editConfig'];
28
29
 
29
30
  /**
30
31
  * 获取安全的 props(排除 key 等不应通过 spread 传递的属性)
@@ -206,7 +207,7 @@ export const formatColumn = ({
206
207
  };
207
208
 
208
209
  // 自定义 render 处理
209
- if (column?.render) {
210
+ if (column?.render && !column.editConfig) {
210
211
  const originalRender = column.render;
211
212
  column.render = (value, record, index) => {
212
213
  const isFn = _isFunction(originalRender);
@@ -695,6 +696,29 @@ export const formatColumn = ({
695
696
  });
696
697
  };
697
698
  }
699
+ if (column.editConfig) {
700
+ const editConfig = column.editConfig;
701
+ const titleStr = typeof title === 'string' ? title : String(dataIndex ?? '');
702
+ const mergedEditConfig = {
703
+ ...editConfig,
704
+ fieldProps: {
705
+ placeholder: titleStr,
706
+ ...editConfig.fieldProps
707
+ }
708
+ };
709
+ const prevRender = column.render;
710
+ column.render = (value, record, index) => {
711
+ const displayContent = prevRender ? prevRender(value, record, index) : value ?? '-';
712
+ return /*#__PURE__*/_jsx(EditableCell, {
713
+ value: value,
714
+ record: record,
715
+ index: index,
716
+ dataIndex: dataIndex,
717
+ editConfig: mergedEditConfig,
718
+ displayContent: displayContent
719
+ });
720
+ };
721
+ }
698
722
  };
699
723
 
700
724
  /**
@@ -28,3 +28,4 @@ export { default as RenderFooter } from './RenderFooter';
28
28
  * @description 实现表格顶部的标签页切换功能,用于数据分类展示
29
29
  */
30
30
  export { default as RenderTabs } from './RenderTabs';
31
+ export { default as EditableCell } from './EditableCell';
@@ -32,4 +32,5 @@ export { default as RenderFooter } from "./RenderFooter";
32
32
  * 表格标签页组件
33
33
  * @description 实现表格顶部的标签页切换功能,用于数据分类展示
34
34
  */
35
- export { default as RenderTabs } from "./RenderTabs";
35
+ export { default as RenderTabs } from "./RenderTabs";
36
+ export { default as EditableCell } from "./EditableCell";
@@ -4,6 +4,20 @@ import { NamePath } from 'antd/es/form/interface';
4
4
  import { FormInstance } from 'antd/es/form/Form';
5
5
  import { ColumnType, GetRowKey, RowSelectionType } from 'antd/es/table/interface';
6
6
  import type { TabsProps } from 'antd/es/tabs';
7
+ import type { ProFormColumnType } from '../ProForm/components/render/propsType';
8
+ /**
9
+ * 单元格行内编辑时 onBlur 的回调函数类型
10
+ */
11
+ export type TableOnBlurFn = (value: any, record: any, index: number) => void | Promise<void>;
12
+ /**
13
+ * 单元格行内编辑配置
14
+ */
15
+ export type EditTableCellConfig<Values = any> = Omit<ProFormColumnType<Values>, 'name' | 'label' | 'names' | 'fieldProps'> & {
16
+ fieldProps?: {
17
+ onBlur?: TableOnBlurFn;
18
+ [key: string]: any;
19
+ };
20
+ };
7
21
  /**
8
22
  * 合计栏的每列配置参数
9
23
  */
@@ -216,6 +230,12 @@ export interface ProTableColumnType extends Omit<ColumnType<any>, 'dataIndex'> {
216
230
  * @default undefined
217
231
  */
218
232
  scroll?: any;
233
+ /**
234
+ * 行内编辑配置
235
+ * @description 配置后单元格支持点击图标进入编辑态
236
+ * @default undefined
237
+ */
238
+ editConfig?: EditTableCellConfig;
219
239
  }
220
240
  /**
221
241
  * 从数组创建树形结构的选项
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zat-design/sisyphus-react",
3
- "version": "4.3.0-beta.10",
3
+ "version": "4.3.0-beta.11",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "es",