@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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @fe-free/core
2
2
 
3
+ ## 1.4.13
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: ProFormEditor
8
+ - @fe-free/tool@1.4.13
9
+
10
+ ## 1.4.12
11
+
12
+ ### Patch Changes
13
+
14
+ - feat: crud
15
+ - @fe-free/tool@1.4.12
16
+
3
17
  ## 1.4.11
4
18
 
5
19
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fe-free/core",
3
- "version": "1.4.11",
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.11"
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
- return (
113
- <Space>
114
- {operateColumnProps?.moreOperator && operateColumnProps.moreOperator(record)}
115
- {actions.includes('read') && (
116
- <CRUDDetail
117
- id={record[idField]}
118
- record={record}
119
- onSuccess={handleReload}
120
- trigger={<a>{readProps?.operateText || '查看'}</a>}
121
- action="read"
122
- {...detailProps}
123
- />
124
- )}
125
- {actions.includes('read_detail') && (
126
- <Link to={`./detail/${record[detailIdIndex || 'id']}`} target={readProps?.target}>
127
- {readProps?.operateText || '查看'}
128
- </Link>
129
- )}
130
- {actions.includes('update') && (
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
- {actions.includes('delete') && deleteProps && (
141
- <OperateDelete
142
- name={record[deleteProps.nameIndex]}
143
- desc={deleteProps.desc}
144
- operateText={deleteProps.operateText}
145
- onDelete={getHandleDelete(record)}
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?.operateText,
180
- deleteProps,
214
+ updateProps,
181
215
  getHandleDelete,
182
216
  ]);
183
217
 
@@ -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 || '删除'}
@@ -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
  };
@@ -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="100%"
74
- width="100%"
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: () => (
@@ -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 };
package/src/index.ts CHANGED
@@ -18,6 +18,7 @@ export { EditorMarkdown } from './editor_markdown';
18
18
  export type { EditorMarkdownProps } from './editor_markdown';
19
19
 
20
20
  export {
21
+ ProFormEditor,
21
22
  ProFormJSON,
22
23
  ProFormJavascript,
23
24
  ProFormSwitchNumber,