@fe-free/core 1.4.4 → 1.4.6
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/demo/data.tsx +3 -3
- package/src/editor_javascript/index.tsx +1 -0
- package/src/editor_json/index.tsx +1 -1
- package/src/form/form.stories.tsx +48 -31
- package/src/form/form_switch_number.tsx +40 -0
- package/src/form/index.tsx +4 -39
- package/src/form/pro_form_javascript.tsx +26 -0
- package/src/form/pro_form_json.tsx +26 -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.6",
|
|
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.6"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@ant-design/pro-components": "^2.8.7",
|
package/src/crud/demo/data.tsx
CHANGED
|
@@ -86,7 +86,7 @@ async function fakeDeleteByRecord(record) {
|
|
|
86
86
|
|
|
87
87
|
fakeData = fakeData.filter((item) => item.id !== record.id);
|
|
88
88
|
|
|
89
|
-
return Promise.resolve(
|
|
89
|
+
return Promise.resolve();
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
async function fakeGetByRecord(record) {
|
|
@@ -107,7 +107,7 @@ async function fakeCreate(params) {
|
|
|
107
107
|
...params,
|
|
108
108
|
});
|
|
109
109
|
|
|
110
|
-
return Promise.resolve(
|
|
110
|
+
return Promise.resolve();
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
async function fakeUpdateById(params) {
|
|
@@ -123,7 +123,7 @@ async function fakeUpdateById(params) {
|
|
|
123
123
|
return item;
|
|
124
124
|
});
|
|
125
125
|
|
|
126
|
-
return Promise.resolve(
|
|
126
|
+
return Promise.resolve();
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
function fakeRequestCity(): Promise<string[]> {
|
|
@@ -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,72 @@ 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
|
-
readonly
|
|
59
|
-
initialValue={`const name = 'world';
|
|
60
|
-
console.log('hello', name);
|
|
61
|
-
`}
|
|
62
|
-
/>
|
|
63
|
-
</ProForm>
|
|
78
|
+
<ProFormBase>
|
|
79
|
+
<ProFormSwitchNumber name="switchNumber" />
|
|
80
|
+
</ProFormBase>
|
|
64
81
|
),
|
|
65
82
|
};
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
// 没搞明白 cacheFormSwr, proFieldKey, onBlur,先这样处理
|
|
29
|
+
/* eslint-disable-next-line */
|
|
30
|
+
const { fieldProps, readonly, ...rest } = props;
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<ProForm.Item {...rest}>
|
|
34
|
+
<SwitchNumber {...(fieldProps as SwitchNumberProps)} />
|
|
35
|
+
</ProForm.Item>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { ProFormSwitchNumber, SwitchNumber };
|
|
40
|
+
export type { SwitchNumberProps };
|
package/src/form/index.tsx
CHANGED
|
@@ -1,43 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { EditorJavascript } from '../editor_javascript';
|
|
1
|
+
export { ProFormSwitchNumber, SwitchNumber, type SwitchNumberProps } from './form_switch_number';
|
|
2
|
+
export { ProFormJavascript } from './pro_form_javascript';
|
|
3
|
+
export { ProFormJSON } from './pro_form_json';
|
|
5
4
|
import { pinyinMatch } from '@fe-free/tool';
|
|
6
5
|
|
|
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
6
|
/** ProFromSelect 搜索相关 props。 支持 1 搜索 2 拼音过滤 */
|
|
42
7
|
const proFormSelectSearchProps = {
|
|
43
8
|
fieldProps: {
|
|
@@ -48,4 +13,4 @@ const proFormSelectSearchProps = {
|
|
|
48
13
|
},
|
|
49
14
|
};
|
|
50
15
|
|
|
51
|
-
export {
|
|
16
|
+
export { proFormSelectSearchProps };
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
// 没搞明白 cacheFormSwr, proFieldKey, onBlur,先这样处理
|
|
16
|
+
/* eslint-disable-next-line */
|
|
17
|
+
const { fieldProps, readonly, ...rest } = props;
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<ProForm.Item {...rest}>
|
|
21
|
+
<JavascriptItem readonly={readonly} {...(fieldProps as EditorJavascriptProps)} />
|
|
22
|
+
</ProForm.Item>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { ProFormJavascript };
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
// 没搞明白 cacheFormSwr, proFieldKey, onBlur,先这样处理
|
|
16
|
+
/* eslint-disable-next-line */
|
|
17
|
+
const { fieldProps, readonly, ...rest } = props;
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<ProForm.Item {...rest}>
|
|
21
|
+
<JSONItem readonly={props.readonly} {...(fieldProps as EditorJSONProps)} />
|
|
22
|
+
</ProForm.Item>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { ProFormJSON };
|
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';
|