@fe-free/core 1.2.4 → 1.3.1

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.
@@ -0,0 +1,32 @@
1
+ import { EditorMarkdown } from '@fe-free/core';
2
+ import type { Meta, StoryObj } from '@storybook/react';
3
+ import { useState } from 'react';
4
+
5
+ const meta: Meta<typeof EditorMarkdown> = {
6
+ title: '@fe-free/core/EditorMarkdown',
7
+ component: EditorMarkdown,
8
+ tags: ['autodocs'],
9
+ };
10
+
11
+ export default meta;
12
+ type Story = StoryObj<typeof EditorMarkdown>;
13
+
14
+ // 常规示例
15
+ const BasicDemo = () => {
16
+ const [value] = useState(
17
+ `# hello
18
+
19
+ world
20
+ `,
21
+ );
22
+
23
+ return (
24
+ <div style={{ width: '500px', height: '500px' }}>
25
+ <EditorMarkdown value={value} />
26
+ </div>
27
+ );
28
+ };
29
+
30
+ export const Basic: Story = {
31
+ render: () => <BasicDemo />,
32
+ };
@@ -37,3 +37,4 @@ function EditorMarkdown({ value }: EditorMarkdownProps) {
37
37
  }
38
38
 
39
39
  export { EditorMarkdown };
40
+ export type { EditorMarkdownProps };
@@ -0,0 +1,65 @@
1
+ import { ProForm } from '@ant-design/pro-components';
2
+ import { ProFormJSON, ProFormJavascript } from '@fe-free/core';
3
+ import type { Meta, StoryObj } from '@storybook/react';
4
+
5
+ const meta: Meta = {
6
+ title: '@fe-free/core/Form',
7
+ tags: ['autodocs'],
8
+ };
9
+
10
+ export default meta;
11
+ type Story = StoryObj<typeof meta>;
12
+
13
+ // ProFormJSON 基础示例
14
+ export const ProFormJSONBasic: Story = {
15
+ render: () => (
16
+ <ProForm>
17
+ <ProFormJSON name="json" initialValue={JSON.stringify({ name: 'world' }, null, 2)} />
18
+ </ProForm>
19
+ ),
20
+ };
21
+
22
+ // ProFormJSON 只读示例
23
+ export const ProFormJSONReadonly: Story = {
24
+ render: () => (
25
+ <ProForm>
26
+ <ProFormJSON
27
+ name="json"
28
+ readonly
29
+ initialValue={JSON.stringify({ name: 'world' }, null, 2)}
30
+ fieldProps={{
31
+ mainMenuBar: false,
32
+ }}
33
+ />
34
+ </ProForm>
35
+ ),
36
+ };
37
+
38
+ // ProFormJavascript 基础示例
39
+ export const ProFormJavascriptBasic: Story = {
40
+ render: () => (
41
+ <ProForm>
42
+ <ProFormJavascript
43
+ name="javascript"
44
+ initialValue={`const name = 'world';
45
+ console.log('hello', name);
46
+ `}
47
+ />
48
+ </ProForm>
49
+ ),
50
+ };
51
+
52
+ // ProFormJavascript 只读示例
53
+ export const ProFormJavascriptReadonly: Story = {
54
+ render: () => (
55
+ <ProForm>
56
+ <ProFormJavascript
57
+ name="javascript"
58
+ readonly
59
+ initialValue={`const name = 'world';
60
+ console.log('hello', name);
61
+ `}
62
+ />
63
+ </ProForm>
64
+ ),
65
+ };
package/src/index.ts CHANGED
@@ -1,16 +1,20 @@
1
- export { CRUD, useDelete, OperateDelete, CRUDDetail } from './crud';
2
- export type { CRUDProps, CRUDMethods, CRUDDetailProps } from './crud';
3
-
4
- export { ProFormJSON, ProFormJavascript, proFormSelectSearchProps } from './form';
5
-
6
1
  export { LoadingButton } from './button';
7
2
 
8
- export { Table } from './table';
9
- export type { TableProps } from './table';
3
+ export { CRUD, CRUDDetail, OperateDelete, useDelete } from './crud';
4
+ export type { CRUDDetailProps, CRUDMethods, CRUDProps } from './crud';
10
5
 
11
6
  export { EditorJavascript } from './editor_javascript';
7
+ export type { EditorJavascriptProps } from './editor_javascript';
12
8
  export { EditorJSON } from './editor_json';
13
- export { EditorMarkdown } from './editor_markdown';
9
+ export type { EditorJSONProps } from './editor_json';
14
10
  export { EditorLogs } from './editor_logs';
11
+ export type { EditorLogsProps } from './editor_logs';
12
+ export { EditorMarkdown } from './editor_markdown';
13
+ export type { EditorMarkdownProps } from './editor_markdown';
14
+
15
+ export { ProFormJSON, ProFormJavascript, proFormSelectSearchProps } from './form';
16
+
17
+ export { Table } from './table';
18
+ export type { TableProps } from './table';
15
19
 
16
- export { customValueTypeMap, CustomValueTypeEnum } from './value_type_map';
20
+ export { CustomValueTypeEnum, customValueTypeMap } from './value_type_map';
@@ -1,5 +1,5 @@
1
+ import type { ParamsType, ProTableProps } from '@ant-design/pro-components';
1
2
  import { ProTable } from '@ant-design/pro-components';
2
- import type { ProTableProps, ParamsType } from '@ant-design/pro-components';
3
3
  import { useMemo } from 'react';
4
4
 
5
5
  interface TableProps<DataSource = any, Params = any, ValueType = 'text'>
@@ -10,7 +10,7 @@ interface TableProps<DataSource = any, Params = any, ValueType = 'text'>
10
10
 
11
11
  function Table<
12
12
  DataSource extends Record<string, any> = any,
13
- Params extends ParamsType = ParamsType
13
+ Params extends ParamsType = ParamsType,
14
14
  >(props: TableProps<DataSource, Params>) {
15
15
  const { columns, rowKey = 'id', search, ...rest } = props;
16
16
 
@@ -48,7 +48,7 @@ function Table<
48
48
  scroll={getTableScroll(newColumns)}
49
49
  search={
50
50
  hasSearch && {
51
- layout: 'vertical',
51
+ labelWidth: 'auto',
52
52
  defaultCollapsed: false,
53
53
  ...search,
54
54
  }
@@ -0,0 +1,80 @@
1
+ import type { ProColumns } from '@ant-design/pro-components';
2
+ import { Table } from '@fe-free/core';
3
+ import type { Meta, StoryObj } from '@storybook/react';
4
+ import { fakeData } from '../crud/demo/data';
5
+
6
+ const meta: Meta = {
7
+ title: '@fe-free/core/Table',
8
+ tags: ['autodocs'],
9
+ };
10
+
11
+ export default meta;
12
+ type Story = StoryObj<typeof meta>;
13
+
14
+ // 定义列配置
15
+ const columns: ProColumns[] = [
16
+ {
17
+ title: 'id',
18
+ dataIndex: 'id',
19
+ search: true,
20
+ },
21
+ {
22
+ title: '名字(省略)',
23
+ dataIndex: 'name',
24
+ search: true,
25
+ ellipsis: true,
26
+ },
27
+ {
28
+ title: 'city',
29
+ dataIndex: 'city',
30
+ },
31
+ {
32
+ title: 'area',
33
+ dataIndex: 'area',
34
+ },
35
+ ];
36
+
37
+ export const Basic: Story = {
38
+ render: () => (
39
+ <Table
40
+ rowKey="id"
41
+ columns={columns}
42
+ request={async (params) => {
43
+ console.log(params);
44
+ return {
45
+ data: fakeData,
46
+ success: true,
47
+ total: fakeData.length,
48
+ };
49
+ }}
50
+ />
51
+ ),
52
+ };
53
+
54
+ export const Search: Story = {
55
+ render: () => (
56
+ <Table
57
+ columns={[
58
+ {
59
+ title: 'id',
60
+ dataIndex: 'id',
61
+ },
62
+ {
63
+ title: '名字(省略)',
64
+ dataIndex: 'name',
65
+
66
+ ellipsis: true,
67
+ },
68
+ {
69
+ title: 'city',
70
+ dataIndex: 'city',
71
+ },
72
+ {
73
+ title: 'area',
74
+ dataIndex: 'area',
75
+ },
76
+ ]}
77
+ rowKey="id"
78
+ />
79
+ ),
80
+ };
@@ -6,7 +6,7 @@ export default {
6
6
  export const Default = () => {
7
7
  return (
8
8
  <div>
9
- <div>extends colors</div>
9
+ <div>@fe-free/core 扩展的</div>
10
10
  <div className="flex flex-row gap-2">
11
11
  <span className="text-primary">text-primary</span>
12
12
  <span className="text-secondary">text-secondary</span>
@@ -1,49 +1,20 @@
1
- ---
2
- group: 'core'
3
- toc: content
4
- ---
5
-
6
- # valueTypeMap
7
-
8
- 自定义 valueType
9
-
10
- ## customValueTypeMap
11
-
12
- 配置 customValueTypeMap
13
-
14
- ```tsx | pure
15
- import { customValueTypeMap } from '@fe-free/core';
16
1
  import { ProConfigProvider } from '@ant-design/pro-components';
2
+ import { CRUD, CustomValueTypeEnum, customValueTypeMap } from '@fe-free/core';
3
+ import type { Meta, StoryObj } from '@storybook/react';
4
+ import dayjs from 'dayjs';
5
+ import { range } from 'lodash-es';
17
6
 
18
- const Demo = () => (
19
- <ProConfigProvider valueTypeMap={customValueTypeMap}>
20
- <div>some</div>
21
- </ProConfigProvider>
22
- );
23
-
24
- export default Demo;
25
- ```
26
-
27
- ## CustomValueTypeEnum
28
-
29
- 使用
30
-
31
- ```tsx | pure
32
- enum CustomValueTypeEnum {
33
- /** 渲染时间 + 搜索日期范围 */
34
- CustomDateTimeAndDateRange = 'CustomDateTimeAndDateRange',
35
- /** 渲染日期 + 搜索日期范围 */
36
- CustomDateAndDateRange = 'CustomDateAndDateRange',
37
- /** JSON */
38
- CustomJSON = 'CustomJSON',
39
- }
40
- ```
7
+ const meta: Meta = {
8
+ title: '@fe-free/core/ValueTypeMap',
9
+ component: ProConfigProvider,
10
+ parameters: {
11
+ layout: 'centered',
12
+ },
13
+ tags: ['autodocs'],
14
+ };
41
15
 
42
- ```tsx
43
- import { CRUD, customValueTypeMap, CustomValueTypeEnum } from '@fe-free/core';
44
- import { ProConfigProvider } from '@ant-design/pro-components';
45
- import { range } from 'lodash-es';
46
- import dayjs from 'dayjs';
16
+ export default meta;
17
+ type Story = StoryObj<typeof meta>;
47
18
 
48
19
  async function fakeRequest() {
49
20
  const data = range(5).map((item) => ({
@@ -94,7 +65,7 @@ const Table = () => {
94
65
  search: true,
95
66
  },
96
67
  {
97
- title: '秒数',
68
+ title: '日期 number 秒',
98
69
  dataIndex: 'seconds',
99
70
  valueType: CustomValueTypeEnum.CustomDateAndDateRange,
100
71
  search: true,
@@ -118,11 +89,10 @@ const Table = () => {
118
89
  );
119
90
  };
120
91
 
121
- const Demo = () => (
122
- <ProConfigProvider valueTypeMap={customValueTypeMap}>
123
- <Table />
124
- </ProConfigProvider>
125
- );
126
-
127
- export default Demo;
128
- ```
92
+ export const Default: Story = {
93
+ render: () => (
94
+ <ProConfigProvider valueTypeMap={customValueTypeMap}>
95
+ <Table />
96
+ </ProConfigProvider>
97
+ ),
98
+ };
@@ -1,342 +0,0 @@
1
- import React, { useRef } from 'react';
2
- import type { CRUDProps } from '@fe-free/core';
3
- import { CRUD, proFormSelectSearchProps } from '@fe-free/core';
4
- import { Button } from 'antd';
5
- import { ProForm, ProFormSwitch, ProFormText } from '@ant-design/pro-components';
6
- import {
7
- fakeRequest,
8
- fakeDeleteByRecord,
9
- fakeCreate,
10
- fakeGetByRecord,
11
- fakeUpdateById,
12
- fakeRequestCity,
13
- fakeRequestArea,
14
- levels,
15
- fakeRequestSchool,
16
- } from './data';
17
-
18
- const Normal = () => {
19
- const columns = [
20
- {
21
- title: 'id',
22
- dataIndex: 'id',
23
- search: true,
24
- },
25
- {
26
- title: '名字(省略)',
27
- dataIndex: 'name',
28
- search: true,
29
- ellipsis: true,
30
- },
31
- {
32
- title: 'city',
33
- dataIndex: 'city',
34
- },
35
- {
36
- title: 'area',
37
- dataIndex: 'area',
38
- },
39
- ];
40
-
41
- return (
42
- <CRUD
43
- actions={['create', 'read', 'delete', 'update']}
44
- tableProps={{
45
- columns,
46
- request: fakeRequest,
47
- }}
48
- requestDeleteByRecord={fakeDeleteByRecord}
49
- deleteProps={{
50
- nameIndex: 'name',
51
- }}
52
- detailForm={(formProps) => (
53
- <>
54
- <ProFormText
55
- {...formProps}
56
- name="name"
57
- label="名字"
58
- required
59
- rules={[{ required: true }]}
60
- extra="extra extra extra extra"
61
- />
62
- </>
63
- )}
64
- requestGetByRecord={fakeGetByRecord}
65
- requestCreateByValues={fakeCreate}
66
- requestUpdateById={fakeUpdateById}
67
- />
68
- );
69
- };
70
-
71
- function ReadDetail() {
72
- const columns = [
73
- {
74
- title: 'id',
75
- dataIndex: 'id',
76
- search: true,
77
- },
78
- {
79
- title: '名字',
80
- dataIndex: 'name',
81
- search: true,
82
- },
83
- ];
84
-
85
- return (
86
- <CRUD
87
- actions={['read_detail']}
88
- tableProps={{
89
- columns,
90
- request: fakeRequest,
91
- }}
92
- />
93
- );
94
- }
95
-
96
- function Ref() {
97
- const formRef = useRef<any>();
98
- const [detailFormInstance] = ProForm.useForm();
99
-
100
- // @ts-ignore
101
- window._detailFormInstance = detailFormInstance;
102
-
103
- const name = ProForm.useWatch('name', formRef.current);
104
- const detailName = ProForm.useWatch('name', detailFormInstance);
105
-
106
- // 不知道为啥这里 name 不生效,但是项目里是生效的。先忽略
107
- console.log('useWatch', name, detailName);
108
-
109
- const columns = [
110
- {
111
- title: 'id',
112
- dataIndex: 'id',
113
- search: true,
114
- },
115
- {
116
- title: '名字',
117
- dataIndex: 'name',
118
- search: true,
119
- },
120
- ];
121
-
122
- return (
123
- <CRUD
124
- actions={['create', 'read', 'update']}
125
- tableProps={{
126
- formRef,
127
- columns,
128
- request: fakeRequest,
129
- }}
130
- detailFormInstance={detailFormInstance}
131
- detailForm={(formProps) => (
132
- <>
133
- <ProFormText
134
- {...formProps}
135
- name="name"
136
- label="名字"
137
- required
138
- rules={[{ required: true }]}
139
- initialValue={'default'}
140
- />
141
- <ProFormSwitch {...formProps} name="status" label="开启" initialValue={false} />
142
- </>
143
- )}
144
- requestGetByRecord={fakeGetByRecord}
145
- requestCreateByValues={fakeCreate}
146
- requestUpdateById={fakeUpdateById}
147
- />
148
- );
149
- }
150
-
151
- function ActionRef() {
152
- const ref = useRef<any>();
153
-
154
- const columns = [
155
- {
156
- title: 'id',
157
- dataIndex: 'id',
158
- search: true,
159
- },
160
- {
161
- title: '名字',
162
- dataIndex: 'name',
163
- search: true,
164
- },
165
- ];
166
-
167
- return (
168
- <>
169
- <Button onClick={() => ref.current.getActionRef().current?.reload()}>reload</Button>
170
- <CRUD
171
- ref={ref}
172
- actions={[]}
173
- tableProps={{
174
- columns,
175
- request: fakeRequest,
176
- }}
177
- />
178
- </>
179
- );
180
- }
181
-
182
- function RemoteData() {
183
- const columns: CRUDProps['tableProps']['columns'] = [
184
- {
185
- title: 'id',
186
- dataIndex: 'id',
187
- search: true,
188
- },
189
- {
190
- title: '名字',
191
- dataIndex: 'name',
192
- search: true,
193
- },
194
- {
195
- title: '等级(本地数据)',
196
- dataIndex: 'level',
197
- search: true,
198
- valueEnum: levels,
199
- ...proFormSelectSearchProps,
200
- },
201
- {
202
- title: 'city(远端数据)',
203
- dataIndex: 'city',
204
- search: true,
205
- request: async () => {
206
- console.log('request');
207
- const res = await fakeRequestCity();
208
-
209
- return (
210
- res.map((item) => ({
211
- label: item,
212
- value: item,
213
- })) || []
214
- );
215
- },
216
- ...proFormSelectSearchProps,
217
- },
218
- {
219
- title: 'area(联动 city)',
220
- dataIndex: 'area',
221
- search: true,
222
- request: async (params) => {
223
- console.log('params', params);
224
- const res = await fakeRequestArea(params);
225
-
226
- return (
227
- res.map((item) => ({
228
- label: item,
229
- value: item,
230
- })) || []
231
- );
232
- },
233
- dependencies: ['city'],
234
- ...proFormSelectSearchProps,
235
- },
236
- {
237
- title: '学校(远端数据 label value)',
238
- dataIndex: 'school',
239
- search: true,
240
- valueType: 'select',
241
- request: () => fakeRequestSchool(),
242
- ...proFormSelectSearchProps,
243
- },
244
- ];
245
-
246
- return (
247
- <CRUD
248
- actions={[]}
249
- tableProps={{
250
- columns,
251
- request: fakeRequest,
252
- }}
253
- />
254
- );
255
- }
256
-
257
- function NoSearch() {
258
- const ref = useRef<any>();
259
-
260
- const columns = [
261
- {
262
- title: 'id',
263
- dataIndex: 'id',
264
- },
265
- {
266
- title: '名字',
267
- dataIndex: 'name',
268
- },
269
- ];
270
-
271
- return (
272
- <CRUD
273
- ref={ref}
274
- actions={[]}
275
- tableProps={{
276
- columns,
277
- request: fakeRequest,
278
- }}
279
- />
280
- );
281
- }
282
-
283
- const CustomText = () => {
284
- const columns = [
285
- {
286
- title: 'id',
287
- dataIndex: 'id',
288
- search: true,
289
- },
290
- {
291
- title: '名字',
292
- dataIndex: 'name',
293
- search: true,
294
- ellipsis: true,
295
- },
296
- ];
297
-
298
- return (
299
- <CRUD
300
- actions={['create', 'read', 'delete', 'update']}
301
- tableProps={{
302
- columns,
303
- request: fakeRequest,
304
- }}
305
- operateColumnProps={{
306
- width: 230,
307
- moreOperator: () => <div>custom</div>,
308
- }}
309
- readProps={{
310
- operateText: '查看啦',
311
- }}
312
- requestDeleteByRecord={fakeDeleteByRecord}
313
- deleteProps={{
314
- nameIndex: 'name',
315
- operateText: '删除啦',
316
- }}
317
- detailForm={(formProps) => (
318
- <>
319
- <ProFormText
320
- {...formProps}
321
- name="name"
322
- label="名字"
323
- required
324
- rules={[{ required: true }]}
325
- />
326
- </>
327
- )}
328
- requestGetByRecord={fakeGetByRecord}
329
- requestCreateByValues={fakeCreate}
330
- createProps={{
331
- successText: '新建成功啦',
332
- }}
333
- updateProps={{
334
- operateText: '更新啦',
335
- successText: '更新成功啦',
336
- }}
337
- requestUpdateById={fakeUpdateById}
338
- />
339
- );
340
- };
341
-
342
- export { Normal, ReadDetail, Ref, ActionRef, RemoteData, NoSearch, CustomText };