@fe-free/core 1.4.11 → 1.4.13
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/CHANGELOG.md +14 -0
- package/package.json +2 -2
- package/src/crud/crud.stories.tsx +14 -0
- package/src/crud/crud.tsx +65 -31
- package/src/crud/crud_delete.tsx +6 -1
- package/src/crud/types.tsx +8 -3
- package/src/editor/index.tsx +7 -2
- package/src/form/form.stories.tsx +15 -1
- package/src/form/index.tsx +2 -0
- package/src/form/pro_form_editor.tsx +21 -0
- package/src/index.ts +1 -0
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fe-free/core",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.13",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"author": "",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"react-syntax-highlighter": "^15.5.0",
|
|
36
36
|
"vanilla-jsoneditor": "^0.23.1",
|
|
37
37
|
"zustand": "^4.5.4",
|
|
38
|
-
"@fe-free/tool": "1.4.
|
|
38
|
+
"@fe-free/tool": "1.4.13"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@ant-design/pro-components": "^2.8.7",
|
|
@@ -186,6 +186,12 @@ export const MoreCustom: Story = {
|
|
|
186
186
|
requestDeleteByRecord={fakeDeleteByRecord}
|
|
187
187
|
deleteProps={{
|
|
188
188
|
nameIndex: 'name',
|
|
189
|
+
operateIsDisabled: (record) => {
|
|
190
|
+
if (record.id % 3) {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
return true;
|
|
194
|
+
},
|
|
189
195
|
}}
|
|
190
196
|
detailForm={() => (
|
|
191
197
|
<>
|
|
@@ -201,6 +207,14 @@ export const MoreCustom: Story = {
|
|
|
201
207
|
requestGetByRecord={fakeGetByRecord}
|
|
202
208
|
requestCreateByValues={fakeCreate}
|
|
203
209
|
requestUpdateById={fakeUpdateById}
|
|
210
|
+
updateProps={{
|
|
211
|
+
operateIsDisabled: (record) => {
|
|
212
|
+
if (record.id % 3) {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
return true;
|
|
216
|
+
},
|
|
217
|
+
}}
|
|
204
218
|
/>
|
|
205
219
|
);
|
|
206
220
|
},
|
package/src/crud/crud.tsx
CHANGED
|
@@ -109,42 +109,76 @@ function CRUDComponent<
|
|
|
109
109
|
fixed: 'right',
|
|
110
110
|
width: operateColumnProps?.width || 120,
|
|
111
111
|
render: function (_, record) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
112
|
+
const btns: React.ReactNode[] = [];
|
|
113
|
+
|
|
114
|
+
if (actions.includes('read')) {
|
|
115
|
+
btns.push(
|
|
116
|
+
<CRUDDetail
|
|
117
|
+
key="read"
|
|
118
|
+
id={record[idField]}
|
|
119
|
+
record={record}
|
|
120
|
+
onSuccess={handleReload}
|
|
121
|
+
trigger={<a>{readProps?.operateText || '查看'}</a>}
|
|
122
|
+
action="read"
|
|
123
|
+
{...detailProps}
|
|
124
|
+
/>,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (actions.includes('read_detail')) {
|
|
129
|
+
btns.push(
|
|
130
|
+
<Link
|
|
131
|
+
key="read_detail"
|
|
132
|
+
to={`./detail/${record[detailIdIndex || 'id']}`}
|
|
133
|
+
target={readProps?.target}
|
|
134
|
+
>
|
|
135
|
+
{readProps?.operateText || '查看'}
|
|
136
|
+
</Link>,
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (actions.includes('update')) {
|
|
141
|
+
const disabled = updateProps?.operateIsDisabled?.(record) || false;
|
|
142
|
+
|
|
143
|
+
if (disabled) {
|
|
144
|
+
btns.push(
|
|
145
|
+
<a key="update" disabled>
|
|
146
|
+
{updateProps?.operateText || '编辑'}
|
|
147
|
+
</a>,
|
|
148
|
+
);
|
|
149
|
+
} else {
|
|
150
|
+
btns.push(
|
|
131
151
|
<CRUDDetail
|
|
152
|
+
key="update"
|
|
132
153
|
id={record[idField]}
|
|
133
154
|
record={record}
|
|
134
155
|
onSuccess={handleReload}
|
|
135
156
|
trigger={<a>{updateProps?.operateText || '编辑'}</a>}
|
|
136
157
|
action="update"
|
|
137
158
|
{...detailProps}
|
|
138
|
-
|
|
139
|
-
)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
159
|
+
/>,
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (actions.includes('delete') && deleteProps) {
|
|
165
|
+
const disabled = deleteProps?.operateIsDisabled?.(record) || false;
|
|
166
|
+
btns.push(
|
|
167
|
+
<OperateDelete
|
|
168
|
+
key="delete"
|
|
169
|
+
name={record[deleteProps.nameIndex]}
|
|
170
|
+
desc={deleteProps.desc}
|
|
171
|
+
operateText={deleteProps.operateText}
|
|
172
|
+
disabled={disabled}
|
|
173
|
+
onDelete={getHandleDelete(record)}
|
|
174
|
+
/>,
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return (
|
|
179
|
+
<Space>
|
|
180
|
+
{operateColumnProps?.moreOperator && operateColumnProps.moreOperator(record)}
|
|
181
|
+
{btns}
|
|
148
182
|
{operateColumnProps?.moreOperatorAfter && operateColumnProps.moreOperatorAfter(record)}
|
|
149
183
|
</Space>
|
|
150
184
|
);
|
|
@@ -171,13 +205,13 @@ function CRUDComponent<
|
|
|
171
205
|
tableProps.columns,
|
|
172
206
|
operateColumnProps,
|
|
173
207
|
actions,
|
|
208
|
+
deleteProps,
|
|
174
209
|
handleReload,
|
|
175
210
|
readProps?.operateText,
|
|
176
211
|
readProps?.target,
|
|
177
212
|
detailProps,
|
|
178
213
|
detailIdIndex,
|
|
179
|
-
updateProps
|
|
180
|
-
deleteProps,
|
|
214
|
+
updateProps,
|
|
181
215
|
getHandleDelete,
|
|
182
216
|
]);
|
|
183
217
|
|
package/src/crud/crud_delete.tsx
CHANGED
|
@@ -6,6 +6,7 @@ interface Params {
|
|
|
6
6
|
desc?: string;
|
|
7
7
|
operateText?: string;
|
|
8
8
|
onDelete: () => Promise<any>;
|
|
9
|
+
disabled?: boolean;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
function useDelete(params: Params) {
|
|
@@ -34,9 +35,13 @@ function useDelete(params: Params) {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
function OperateDelete(props: Params) {
|
|
37
|
-
const { name, desc, onDelete, operateText } = props;
|
|
38
|
+
const { name, desc, onDelete, operateText, disabled } = props;
|
|
38
39
|
const { doDelete } = useDelete({ name, desc, onDelete, operateText });
|
|
39
40
|
|
|
41
|
+
if (disabled) {
|
|
42
|
+
return <a disabled>{operateText || '删除'}</a>;
|
|
43
|
+
}
|
|
44
|
+
|
|
40
45
|
return (
|
|
41
46
|
<a style={{ color: 'red' }} onClick={doDelete}>
|
|
42
47
|
{operateText || '删除'}
|
package/src/crud/types.tsx
CHANGED
|
@@ -77,8 +77,10 @@ interface CRUDProps<DataSource = any, Key = string> {
|
|
|
77
77
|
/** @deprecated 请使用 requestUpdateByValues 替代 */
|
|
78
78
|
requestUpdateById?: (values: Partial<DataSource>) => Promise<false | void>;
|
|
79
79
|
updateProps?: {
|
|
80
|
-
/**
|
|
80
|
+
/** 文本“编辑” */
|
|
81
81
|
operateText?: string;
|
|
82
|
+
/** ”编辑”是否禁用 */
|
|
83
|
+
operateIsDisabled?: (record: DataSource) => boolean;
|
|
82
84
|
/** 保存按钮文本 */
|
|
83
85
|
submitText?: string;
|
|
84
86
|
/** 重置按钮文本 */
|
|
@@ -93,12 +95,15 @@ interface CRUDProps<DataSource = any, Key = string> {
|
|
|
93
95
|
requestDeleteByRecord?: (record: DataSource) => Promise<void>;
|
|
94
96
|
/** 删除相关 */
|
|
95
97
|
deleteProps?: {
|
|
98
|
+
/** 文本“删除” */
|
|
99
|
+
operateText?: string;
|
|
100
|
+
/** “删除”是否禁用 */
|
|
101
|
+
operateIsDisabled?: (record: DataSource) => boolean;
|
|
96
102
|
/** 显示名称索引 */
|
|
97
103
|
nameIndex: keyof DataSource;
|
|
98
104
|
/** 删除确认描述 */
|
|
99
105
|
desc?: string;
|
|
100
|
-
|
|
101
|
-
operateText?: string;
|
|
106
|
+
|
|
102
107
|
/** 成功文案 */
|
|
103
108
|
successText?: string | (() => string);
|
|
104
109
|
};
|
package/src/editor/index.tsx
CHANGED
|
@@ -15,6 +15,9 @@ interface EditorProps {
|
|
|
15
15
|
readOnly?: boolean;
|
|
16
16
|
editable?: boolean;
|
|
17
17
|
|
|
18
|
+
height?: string;
|
|
19
|
+
width?: string;
|
|
20
|
+
|
|
18
21
|
// 不对外
|
|
19
22
|
theme?: ReactCodeMirrorProps['theme'];
|
|
20
23
|
extensions?: ReactCodeMirrorProps['extensions'];
|
|
@@ -29,6 +32,8 @@ function Editor(props: EditorProps) {
|
|
|
29
32
|
editable,
|
|
30
33
|
autoFocus,
|
|
31
34
|
placeholder,
|
|
35
|
+
height,
|
|
36
|
+
width,
|
|
32
37
|
theme,
|
|
33
38
|
extensions: originExtensions,
|
|
34
39
|
} = props;
|
|
@@ -70,8 +75,8 @@ function Editor(props: EditorProps) {
|
|
|
70
75
|
return (
|
|
71
76
|
<CodeMirror
|
|
72
77
|
className="w-full h-full"
|
|
73
|
-
height=
|
|
74
|
-
width=
|
|
78
|
+
height={height || '100%'}
|
|
79
|
+
width={width || '100%'}
|
|
75
80
|
value={value}
|
|
76
81
|
onChange={handleChange}
|
|
77
82
|
extensions={extensions}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ProForm } from '@ant-design/pro-components';
|
|
2
|
-
import { ProFormJSON, ProFormJavascript, ProFormSwitchNumber } from '@fe-free/core';
|
|
2
|
+
import { ProFormEditor, ProFormJSON, ProFormJavascript, ProFormSwitchNumber } from '@fe-free/core';
|
|
3
3
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
4
4
|
import { useState } from 'react';
|
|
5
5
|
|
|
@@ -37,6 +37,20 @@ function ProFormBase({
|
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
export const ProFormEditorComponent: Story = {
|
|
41
|
+
render: () => (
|
|
42
|
+
<ProFormBase
|
|
43
|
+
initialValues={{
|
|
44
|
+
code: `const name = 'world';
|
|
45
|
+
console.log('hello', name);
|
|
46
|
+
`,
|
|
47
|
+
}}
|
|
48
|
+
>
|
|
49
|
+
<ProFormEditor name="code" fieldProps={{ language: 'javascript', height: '50vh' }} />
|
|
50
|
+
</ProFormBase>
|
|
51
|
+
),
|
|
52
|
+
};
|
|
53
|
+
|
|
40
54
|
// ProFormJSON 基础示例
|
|
41
55
|
export const ProFormJSONComponent: Story = {
|
|
42
56
|
render: () => (
|
package/src/form/index.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { ProFormEditor } from './pro_form_editor';
|
|
1
2
|
export { ProFormJavascript } from './pro_form_javascript';
|
|
2
3
|
export { ProFormJSON } from './pro_form_json';
|
|
3
4
|
export {
|
|
@@ -5,6 +6,7 @@ export {
|
|
|
5
6
|
SwitchNumber,
|
|
6
7
|
type SwitchNumberProps,
|
|
7
8
|
} from './pro_form_switch_number';
|
|
9
|
+
|
|
8
10
|
import { pinyinMatch } from '@fe-free/tool';
|
|
9
11
|
|
|
10
12
|
/** ProFromSelect 搜索相关 props。 支持 1 搜索 2 拼音过滤 */
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ProFormItemProps } from '@ant-design/pro-components';
|
|
2
|
+
import { ProForm } from '@ant-design/pro-components';
|
|
3
|
+
import type { EditorProps } from '../editor';
|
|
4
|
+
import { Editor } from '../editor';
|
|
5
|
+
|
|
6
|
+
function EditorItem(props: EditorProps) {
|
|
7
|
+
return <Editor height="300px" {...props} />;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function ProFormEditor(props: ProFormItemProps<EditorProps>) {
|
|
11
|
+
/* eslint-disable-next-line */
|
|
12
|
+
const { fieldProps, readonly, ...rest } = props;
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<ProForm.Item {...rest}>
|
|
16
|
+
<EditorItem readOnly={readonly} {...(fieldProps as EditorProps)} />
|
|
17
|
+
</ProForm.Item>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { ProFormEditor };
|