@fe-free/core 2.5.3 → 2.5.4

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,12 @@
1
1
  # @fe-free/core
2
2
 
3
+ ## 2.5.4
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: curd
8
+ - @fe-free/tool@2.5.4
9
+
3
10
  ## 2.5.3
4
11
 
5
12
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fe-free/core",
3
- "version": "2.5.3",
3
+ "version": "2.5.4",
4
4
  "description": "",
5
5
  "main": "./src/index.ts",
6
6
  "author": "",
@@ -41,7 +41,7 @@
41
41
  "remark-gfm": "^4.0.1",
42
42
  "vanilla-jsoneditor": "^0.23.1",
43
43
  "zustand": "^4.5.4",
44
- "@fe-free/tool": "2.5.3"
44
+ "@fe-free/tool": "2.5.4"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@ant-design/pro-components": "2.8.9",
@@ -20,7 +20,6 @@ export default meta;
20
20
 
21
21
  const handleError = (event) => {
22
22
  console.log('global error', event);
23
- alert('global error');
24
23
  };
25
24
 
26
25
  window.addEventListener('error', handleError);
@@ -7,6 +7,15 @@ const meta: Meta<typeof CRUDOfSimple> = {
7
7
  title: '@fe-free/core/CRUDOfSimple',
8
8
  component: CRUDOfSimple,
9
9
  tags: ['autodocs'],
10
+ decorators: [
11
+ (Story) => {
12
+ return (
13
+ <div className="c-border h-[500px] w-[300px] overflow-x-auto">
14
+ <Story />
15
+ </div>
16
+ );
17
+ },
18
+ ],
10
19
  };
11
20
 
12
21
  export default meta;
@@ -0,0 +1,90 @@
1
+ import { ProFormText } from '@ant-design/pro-components';
2
+ import { CRUDOfPure } from '@fe-free/core';
3
+ import type { Meta, StoryObj } from '@storybook/react-vite';
4
+ import { Button } from 'antd';
5
+ import { fakeCreate, fakeDeleteByRecord, fakeRequest } from '../crud/demo/data';
6
+
7
+ const meta: Meta<typeof CRUDOfPure> = {
8
+ title: '@fe-free/core/CRUDOfPure',
9
+ component: CRUDOfPure,
10
+ tags: ['autodocs'],
11
+ parameters: {
12
+ docs: {
13
+ description: {
14
+ component: `
15
+ CRUDOfPure 组件。(更简洁的 CRUD 组件)
16
+ - 隐藏 label
17
+ - 搜索表单按钮一行
18
+ - 移除卡片布局
19
+ `,
20
+ },
21
+ },
22
+ },
23
+ };
24
+
25
+ export default meta;
26
+ type Story = StoryObj<typeof CRUDOfPure>;
27
+
28
+ // 基础用法
29
+ export const Normal: Story = {
30
+ render: () => {
31
+ const columns = [
32
+ {
33
+ title: 'id',
34
+ dataIndex: 'id',
35
+ search: true,
36
+ },
37
+ {
38
+ title: '名字(省略)',
39
+ dataIndex: 'name',
40
+ search: true,
41
+ ellipsis: true,
42
+ },
43
+ {
44
+ title: 'city',
45
+ dataIndex: 'city',
46
+ },
47
+ {
48
+ title: 'area',
49
+ dataIndex: 'area',
50
+ },
51
+ ];
52
+
53
+ return (
54
+ <CRUDOfPure
55
+ actions={['delete']}
56
+ tableProps={{
57
+ columns,
58
+ request: fakeRequest,
59
+ pagination: false,
60
+ search: {
61
+ optionRender: (_, __, dom) => {
62
+ return [
63
+ ...dom,
64
+ <Button key="1" type="primary" className="ml-2">
65
+ 额外的按钮
66
+ </Button>,
67
+ ];
68
+ },
69
+ },
70
+ }}
71
+ requestDeleteByRecord={fakeDeleteByRecord}
72
+ deleteProps={{
73
+ nameIndex: 'id',
74
+ }}
75
+ detailForm={() => (
76
+ <>
77
+ <ProFormText
78
+ name="name"
79
+ label="名字"
80
+ required
81
+ rules={[{ required: true }]}
82
+ extra="extra extra extra extra"
83
+ />
84
+ </>
85
+ )}
86
+ requestCreateByValues={fakeCreate}
87
+ />
88
+ );
89
+ },
90
+ };
@@ -0,0 +1,59 @@
1
+ import classNames from 'classnames';
2
+ import { forwardRef } from 'react';
3
+ import type { CRUDMethods, CRUDProps } from '../crud';
4
+ import { CRUD } from '../crud';
5
+ import './style.scss';
6
+
7
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
8
+ interface CRUDOfPureProps<
9
+ DataSource extends Record<string, any> = any,
10
+ Key extends string | number = string,
11
+ > extends CRUDProps<DataSource, Key> {
12
+ // nothing
13
+ }
14
+
15
+ function CRUDOfPureComponent(props: CRUDOfPureProps, ref: React.ForwardedRef<CRUDMethods>) {
16
+ const newColumns = props.tableProps.columns?.map((column) => {
17
+ if (column.search) {
18
+ return {
19
+ ...column,
20
+ // 隐藏 label
21
+ formItemProps: {
22
+ label: '',
23
+ ...column.formItemProps,
24
+ },
25
+ // 设置 placeholder
26
+ fieldProps: {
27
+ placeholder:
28
+ column.valueType === 'select' ? `请选择${column.title}` : `请输入${column.title}`,
29
+ ...column.fieldProps,
30
+ },
31
+ };
32
+ }
33
+ return column;
34
+ });
35
+
36
+ return (
37
+ <div className={classNames('fec-crud-of-pure')}>
38
+ <CRUD
39
+ ref={ref}
40
+ {...props}
41
+ tableProps={{
42
+ cardBordered: false,
43
+ ...props.tableProps,
44
+ columns: newColumns,
45
+ }}
46
+ />
47
+ </div>
48
+ );
49
+ }
50
+
51
+ const CRUDOfPure = forwardRef(CRUDOfPureComponent) as <
52
+ DataSource extends Record<string, any> = any,
53
+ Key extends string | number = string,
54
+ >(
55
+ props: CRUDOfPureProps<DataSource, Key> & { ref?: React.ForwardedRef<CRUDMethods> },
56
+ ) => JSX.Element;
57
+
58
+ export { CRUDOfPure };
59
+ export type { CRUDOfPureProps };
@@ -0,0 +1,46 @@
1
+ .fec-crud-of-pure {
2
+ .ant-pro-table .ant-pro-table-search {
3
+ margin-block-end: 0;
4
+ }
5
+
6
+ .ant-pro-query-filter.ant-pro-query-filter {
7
+ padding: 8px 16px;
8
+ }
9
+
10
+ .ant-pro-card .ant-pro-card-body {
11
+ padding-inline: 16px;
12
+ }
13
+
14
+ .ant-pro-query-filter-container {
15
+ .ant-col.ant-col-6,
16
+ .ant-col.ant-col-8,
17
+ .ant-col.ant-col-12 {
18
+ flex: none !important;
19
+ min-width: 150px !important;
20
+ }
21
+
22
+ .ant-col.ant-col-offset-6,
23
+ .ant-col.ant-col-offset-8,
24
+ .ant-col.ant-col-offset-12,
25
+ .ant-col.ant-col-offset-16,
26
+ .ant-col.ant-col-offset-24 {
27
+ margin-inline-start: 0 !important;
28
+ }
29
+
30
+ .ant-pro-query-filter-actions {
31
+ // 可能有问题
32
+ .ant-form-item-label {
33
+ display: none;
34
+ }
35
+ }
36
+
37
+ .ant-pro-query-filter-collapse-button {
38
+ display: none;
39
+ }
40
+ }
41
+
42
+ .ant-pro-table-list-toolbar-container {
43
+ padding-block: 0;
44
+ padding-block-end: 8px;
45
+ }
46
+ }
package/src/index.ts CHANGED
@@ -8,6 +8,8 @@ export type { CopyProps } from './copy';
8
8
  export { CoreApp } from './core_app';
9
9
  export { CRUD, CRUDDetail, CRUDOfSimple, OperateDelete, useDelete } from './crud';
10
10
  export type { CRUDDetailProps, CRUDMethods, CRUDOfSimpleProps, CRUDProps } from './crud';
11
+ export { CRUDOfPure } from './crud_of_pure';
12
+ export type { CRUDOfPureProps } from './crud_of_pure';
11
13
  export { Editor } from './editor';
12
14
  export type { EditorProps } from './editor';
13
15
  export { EditorJSON } from './editor_json';