@fe-free/core 1.4.5 → 1.4.7
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.tsx +6 -3
- package/src/editor_javascript/index.tsx +1 -0
- package/src/editor_json/index.tsx +1 -1
- package/src/form/form.stories.tsx +54 -30
- package/src/form/index.tsx +8 -39
- package/src/form/pro_form_javascript.tsx +25 -0
- package/src/form/pro_form_json.tsx +25 -0
- package/src/form/pro_form_switch_number.tsx +39 -0
- package/src/index.ts +6 -1
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.7",
|
|
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.7"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@ant-design/pro-components": "^2.8.7",
|
package/src/crud/crud.tsx
CHANGED
|
@@ -89,6 +89,8 @@ function CRUDComponent<
|
|
|
89
89
|
}, []);
|
|
90
90
|
|
|
91
91
|
const newColumns = useMemo(() => {
|
|
92
|
+
const idField = tableProps.rowKey || 'id';
|
|
93
|
+
|
|
92
94
|
const operateColumn = {
|
|
93
95
|
title: '操作',
|
|
94
96
|
fixed: 'right',
|
|
@@ -99,7 +101,7 @@ function CRUDComponent<
|
|
|
99
101
|
{operateColumnProps?.moreOperator && operateColumnProps.moreOperator(record)}
|
|
100
102
|
{actions.includes('read') && (
|
|
101
103
|
<CRUDDetail
|
|
102
|
-
id={record
|
|
104
|
+
id={record[idField]}
|
|
103
105
|
record={record}
|
|
104
106
|
onSuccess={handleReload}
|
|
105
107
|
trigger={<a>{readProps?.operateText || '查看'}</a>}
|
|
@@ -117,7 +119,7 @@ function CRUDComponent<
|
|
|
117
119
|
)}
|
|
118
120
|
{actions.includes('update') && (
|
|
119
121
|
<CRUDDetail
|
|
120
|
-
id={record
|
|
122
|
+
id={record[idField]}
|
|
121
123
|
record={record}
|
|
122
124
|
onSuccess={handleReload}
|
|
123
125
|
trigger={<a>{updateProps?.operateText || '编辑'}</a>}
|
|
@@ -155,9 +157,10 @@ function CRUDComponent<
|
|
|
155
157
|
|
|
156
158
|
return tableProps.columns as TableProps['columns'];
|
|
157
159
|
}, [
|
|
160
|
+
tableProps.rowKey,
|
|
161
|
+
tableProps.columns,
|
|
158
162
|
operateColumnProps,
|
|
159
163
|
actions,
|
|
160
|
-
tableProps.columns,
|
|
161
164
|
handleReload,
|
|
162
165
|
readProps?.operateText,
|
|
163
166
|
readProps?.target,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ProForm } from '@ant-design/pro-components';
|
|
2
|
-
import { ProFormJSON, ProFormJavascript } from '@fe-free/core';
|
|
2
|
+
import { ProFormJSON, ProFormJavascript, ProFormSwitchNumber } from '@fe-free/core';
|
|
3
3
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
4
|
+
import { useState } from 'react';
|
|
4
5
|
|
|
5
6
|
const meta: Meta = {
|
|
6
7
|
title: '@fe-free/core/Form',
|
|
@@ -10,56 +11,79 @@ const meta: Meta = {
|
|
|
10
11
|
export default meta;
|
|
11
12
|
type Story = StoryObj<typeof meta>;
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
function ProFormBase({
|
|
15
|
+
children,
|
|
16
|
+
initialValues,
|
|
17
|
+
}: {
|
|
18
|
+
children: React.ReactNode;
|
|
19
|
+
initialValues?: any;
|
|
20
|
+
}) {
|
|
21
|
+
const [values, setValues] = useState<any>(undefined);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<ProForm
|
|
25
|
+
initialValues={initialValues}
|
|
26
|
+
onValuesChange={(values) => {
|
|
27
|
+
console.log('values', values);
|
|
28
|
+
setValues(values);
|
|
29
|
+
}}
|
|
30
|
+
onFinish={(values) => {
|
|
31
|
+
console.log('values', values);
|
|
32
|
+
}}
|
|
33
|
+
>
|
|
34
|
+
<pre>values: {JSON.stringify(values, null, 2)}</pre>
|
|
35
|
+
{children}
|
|
18
36
|
</ProForm>
|
|
19
|
-
)
|
|
20
|
-
}
|
|
37
|
+
);
|
|
38
|
+
}
|
|
21
39
|
|
|
22
|
-
// ProFormJSON
|
|
23
|
-
export const
|
|
40
|
+
// ProFormJSON 基础示例
|
|
41
|
+
export const ProFormJSONComponent: Story = {
|
|
24
42
|
render: () => (
|
|
25
|
-
<
|
|
43
|
+
<ProFormBase initialValues={{ json: JSON.stringify({ name: 'world' }, null, 2) }}>
|
|
44
|
+
<ProFormJSON name="json" />
|
|
45
|
+
<div>readonly</div>
|
|
26
46
|
<ProFormJSON
|
|
27
47
|
name="json"
|
|
28
48
|
readonly
|
|
29
49
|
initialValue={JSON.stringify({ name: 'world' }, null, 2)}
|
|
30
50
|
fieldProps={{
|
|
31
51
|
mainMenuBar: false,
|
|
52
|
+
readonly: true,
|
|
32
53
|
}}
|
|
33
54
|
/>
|
|
34
|
-
</
|
|
55
|
+
</ProFormBase>
|
|
35
56
|
),
|
|
36
57
|
};
|
|
37
58
|
|
|
38
59
|
// ProFormJavascript 基础示例
|
|
39
|
-
export const
|
|
60
|
+
export const ProFormJavascriptComponent: Story = {
|
|
40
61
|
render: () => (
|
|
41
|
-
<
|
|
42
|
-
|
|
43
|
-
name=
|
|
44
|
-
initialValue={`const name = 'world';
|
|
62
|
+
<ProFormBase
|
|
63
|
+
initialValues={{
|
|
64
|
+
javascript: `const name = 'world';
|
|
45
65
|
console.log('hello', name);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
66
|
+
`,
|
|
67
|
+
}}
|
|
68
|
+
>
|
|
69
|
+
<ProFormJavascript name="javascript" />
|
|
70
|
+
<div>readonly</div>
|
|
71
|
+
<ProFormJavascript name="javascript" readonly />
|
|
72
|
+
</ProFormBase>
|
|
49
73
|
),
|
|
50
74
|
};
|
|
51
75
|
|
|
52
|
-
|
|
53
|
-
export const ProFormJavascriptReadonly: Story = {
|
|
76
|
+
export const ProFormSwitchNumberComponent: Story = {
|
|
54
77
|
render: () => (
|
|
55
|
-
<
|
|
56
|
-
<
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
78
|
+
<ProFormBase>
|
|
79
|
+
<ProFormSwitchNumber name="switchNumber" />
|
|
80
|
+
<ProFormSwitchNumber
|
|
81
|
+
name="switchNumber"
|
|
82
|
+
fieldProps={{
|
|
83
|
+
checkedChildren: '开启',
|
|
84
|
+
unCheckedChildren: '关闭',
|
|
85
|
+
}}
|
|
62
86
|
/>
|
|
63
|
-
</
|
|
87
|
+
</ProFormBase>
|
|
64
88
|
),
|
|
65
89
|
};
|
package/src/form/index.tsx
CHANGED
|
@@ -1,43 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export { ProFormJavascript } from './pro_form_javascript';
|
|
2
|
+
export { ProFormJSON } from './pro_form_json';
|
|
3
|
+
export {
|
|
4
|
+
ProFormSwitchNumber,
|
|
5
|
+
SwitchNumber,
|
|
6
|
+
type SwitchNumberProps,
|
|
7
|
+
} from './pro_form_switch_number';
|
|
5
8
|
import { pinyinMatch } from '@fe-free/tool';
|
|
6
9
|
|
|
7
|
-
function JSONItem(props) {
|
|
8
|
-
return (
|
|
9
|
-
<div style={{ height: '300px' }}>
|
|
10
|
-
<EditorJSON {...props} />
|
|
11
|
-
</div>
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function ProFormJSON(props: ProFormItemProps) {
|
|
16
|
-
const { readonly, fieldProps, ...rest } = props;
|
|
17
|
-
return (
|
|
18
|
-
<ProForm.Item {...rest}>
|
|
19
|
-
<JSONItem readonly={readonly} {...fieldProps} />
|
|
20
|
-
</ProForm.Item>
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function JavascriptItem(props) {
|
|
25
|
-
return (
|
|
26
|
-
<div style={{ height: '300px' }}>
|
|
27
|
-
<EditorJavascript {...props} />
|
|
28
|
-
</div>
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function ProFormJavascript(props: ProFormItemProps) {
|
|
33
|
-
const { readonly, fieldProps, ...rest } = props;
|
|
34
|
-
return (
|
|
35
|
-
<ProForm.Item {...rest}>
|
|
36
|
-
<JavascriptItem readonly={readonly} {...fieldProps} />
|
|
37
|
-
</ProForm.Item>
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
10
|
/** ProFromSelect 搜索相关 props。 支持 1 搜索 2 拼音过滤 */
|
|
42
11
|
const proFormSelectSearchProps = {
|
|
43
12
|
fieldProps: {
|
|
@@ -48,4 +17,4 @@ const proFormSelectSearchProps = {
|
|
|
48
17
|
},
|
|
49
18
|
};
|
|
50
19
|
|
|
51
|
-
export {
|
|
20
|
+
export { proFormSelectSearchProps };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ProFormItemProps } from '@ant-design/pro-components';
|
|
2
|
+
import { ProForm } from '@ant-design/pro-components';
|
|
3
|
+
import type { EditorJavascriptProps } from '../editor_javascript';
|
|
4
|
+
import { EditorJavascript } from '../editor_javascript';
|
|
5
|
+
|
|
6
|
+
function JavascriptItem(props: EditorJavascriptProps) {
|
|
7
|
+
return (
|
|
8
|
+
<div style={{ height: '300px' }}>
|
|
9
|
+
<EditorJavascript {...props} />
|
|
10
|
+
</div>
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function ProFormJavascript(props: ProFormItemProps<EditorJavascriptProps>) {
|
|
15
|
+
/* eslint-disable-next-line */
|
|
16
|
+
const { fieldProps, readonly, ...rest } = props;
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<ProForm.Item {...rest}>
|
|
20
|
+
<JavascriptItem readonly={readonly} {...(fieldProps as EditorJavascriptProps)} />
|
|
21
|
+
</ProForm.Item>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { ProFormJavascript };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ProFormItemProps } from '@ant-design/pro-components';
|
|
2
|
+
import { ProForm } from '@ant-design/pro-components';
|
|
3
|
+
import type { EditorJSONProps } from '../editor_json';
|
|
4
|
+
import { EditorJSON } from '../editor_json';
|
|
5
|
+
|
|
6
|
+
function JSONItem(props: EditorJSONProps) {
|
|
7
|
+
return (
|
|
8
|
+
<div style={{ height: '300px' }}>
|
|
9
|
+
<EditorJSON {...props} />
|
|
10
|
+
</div>
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function ProFormJSON(props: ProFormItemProps<EditorJSONProps>) {
|
|
15
|
+
/* eslint-disable-next-line */
|
|
16
|
+
const { fieldProps, readonly, ...rest } = props;
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<ProForm.Item {...rest}>
|
|
20
|
+
<JSONItem readonly={props.readonly} {...(fieldProps as EditorJSONProps)} />
|
|
21
|
+
</ProForm.Item>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { ProFormJSON };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ProFormItemProps } from '@ant-design/pro-components';
|
|
2
|
+
import { ProForm } from '@ant-design/pro-components';
|
|
3
|
+
import type { SwitchProps } from 'antd';
|
|
4
|
+
import { Switch } from 'antd';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
interface SwitchNumberProps extends Omit<SwitchProps, 'value' | 'onChange'> {
|
|
8
|
+
value: number;
|
|
9
|
+
onChange: (
|
|
10
|
+
value: number,
|
|
11
|
+
event: React.MouseEvent<HTMLButtonElement> | React.KeyboardEvent<HTMLButtonElement>,
|
|
12
|
+
) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function SwitchNumber(props: SwitchNumberProps) {
|
|
16
|
+
return (
|
|
17
|
+
<Switch
|
|
18
|
+
{...props}
|
|
19
|
+
value={props.value ? true : false}
|
|
20
|
+
onChange={(checked, event) => {
|
|
21
|
+
return props.onChange(checked ? 1 : 0, event);
|
|
22
|
+
}}
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function ProFormSwitchNumber(props: ProFormItemProps<SwitchNumberProps>) {
|
|
28
|
+
/* eslint-disable-next-line */
|
|
29
|
+
const { fieldProps, readonly, ...rest } = props;
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<ProForm.Item {...rest}>
|
|
33
|
+
<SwitchNumber {...(fieldProps as SwitchNumberProps)} />
|
|
34
|
+
</ProForm.Item>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { ProFormSwitchNumber, SwitchNumber };
|
|
39
|
+
export type { SwitchNumberProps };
|
package/src/index.ts
CHANGED
|
@@ -17,7 +17,12 @@ export type { EditorLogsProps } from './editor_logs';
|
|
|
17
17
|
export { EditorMarkdown } from './editor_markdown';
|
|
18
18
|
export type { EditorMarkdownProps } from './editor_markdown';
|
|
19
19
|
|
|
20
|
-
export {
|
|
20
|
+
export {
|
|
21
|
+
ProFormJSON,
|
|
22
|
+
ProFormJavascript,
|
|
23
|
+
ProFormSwitchNumber,
|
|
24
|
+
proFormSelectSearchProps,
|
|
25
|
+
} from './form';
|
|
21
26
|
|
|
22
27
|
export { Table } from './table';
|
|
23
28
|
export type { TableProps } from './table';
|