@fe-free/core 1.3.3 → 1.3.5

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.3.5
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: editor
8
+ - @fe-free/tool@1.3.5
9
+
10
+ ## 1.3.4
11
+
12
+ ### Patch Changes
13
+
14
+ - feat: crud
15
+ - @fe-free/tool@1.3.4
16
+
3
17
  ## 1.3.3
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.3.3",
3
+ "version": "1.3.5",
4
4
  "description": "",
5
5
  "main": "./src/index.ts",
6
6
  "author": "",
@@ -12,11 +12,18 @@
12
12
  "dependencies": {
13
13
  "@ant-design/icons": "^5.2.6",
14
14
  "@ant-design/plots": "^2.2.5",
15
+ "@codemirror/lang-html": "^6.4.9",
16
+ "@codemirror/lang-javascript": "^6.2.4",
17
+ "@codemirror/lang-json": "^6.0.1",
18
+ "@codemirror/lang-markdown": "^6.3.2",
19
+ "@codemirror/lang-python": "^6.2.1",
20
+ "@codemirror/lang-sql": "^6.8.0",
21
+ "@codemirror/lang-xml": "^6.1.0",
15
22
  "@codemirror/language": "^6.10.3",
16
23
  "@codemirror/view": "^6.33.0",
17
24
  "@lezer/highlight": "^1.2.1",
18
- "@uiw/codemirror-themes": "^4.23.2",
19
- "@uiw/react-codemirror": "^4.23.2",
25
+ "@uiw/codemirror-themes": "^4.23.12",
26
+ "@uiw/react-codemirror": "^4.23.12",
20
27
  "ace-builds": "^1.33.1",
21
28
  "ahooks": "^3.7.8",
22
29
  "axios": "^1.6.5",
@@ -29,7 +36,7 @@
29
36
  "react-syntax-highlighter": "^15.5.0",
30
37
  "vanilla-jsoneditor": "^0.23.1",
31
38
  "zustand": "^4.5.4",
32
- "@fe-free/tool": "1.3.3"
39
+ "@fe-free/tool": "1.3.5"
33
40
  },
34
41
  "peerDependencies": {
35
42
  "@ant-design/pro-components": "^2.8.7",
package/src/crud/crud.tsx CHANGED
@@ -106,7 +106,10 @@ function CRUDComponent<
106
106
  />
107
107
  )}
108
108
  {actions.includes('read_detail') && (
109
- <a href={`./detail/${record[detailIdIndex || 'id']}`} target={readProps?.target}>
109
+ <a
110
+ href={`${window.location.pathname}/detail/${record[detailIdIndex || 'id']}`}
111
+ target={readProps?.target}
112
+ >
110
113
  {readProps?.operateText || '查看'}
111
114
  </a>
112
115
  )}
@@ -166,6 +169,7 @@ function CRUDComponent<
166
169
  const toolBarRender = useCallback(
167
170
  (...args) =>
168
171
  [
172
+ <div key="placeholder" />,
169
173
  // @ts-ignore
170
174
  ...(tableProps.toolBarRender ? tableProps.toolBarRender(...args) : []),
171
175
  actions.includes('create') && (
@@ -8,3 +8,9 @@
8
8
  }
9
9
  }
10
10
  }
11
+
12
+ .crud-of-simple {
13
+ .ant-pro-table-list-toolbar {
14
+ border-bottom: 1px solid #f0f0f0;
15
+ }
16
+ }
@@ -9,15 +9,16 @@ import type { TableProps } from '../table';
9
9
  * update 编辑
10
10
  * delete 删除
11
11
  */
12
- type CrudAction = 'create' | 'read' | 'read_detail' | 'update' | 'delete';
12
+ type CRUDAction = 'create' | 'read' | 'read_detail' | 'update' | 'delete';
13
13
 
14
14
  interface CRUDProps<DataSource = any, Key = string> {
15
- actions: CrudAction[];
15
+ /** 操作类型 */
16
+ actions: CRUDAction[];
16
17
 
17
18
  // *** 表单 ***
18
19
 
19
- /** 弹窗表单 */
20
- detailForm?: (formProps: { readonly: boolean }, info: { action: CrudAction }) => ReactNode;
20
+ /** 弹窗表单,action 为 read update 时需要传递 */
21
+ detailForm?: (formProps: { readonly: boolean }, info: { action: CRUDAction }) => ReactNode;
21
22
  /** detailForm 的 formRef */
22
23
  detailFormInstance?: ProFormInstance;
23
24
 
@@ -7,12 +7,18 @@ function useTips<DataSource, Key>(props: CRUDProps<DataSource, Key>) {
7
7
  if (!props.requestCreateByValues) {
8
8
  console.warn('actions 包含 create 时,需要传递 requestCreateByValues');
9
9
  }
10
+ if (!props.detailForm) {
11
+ console.warn('actions 包含 create 时,需要传递 detailForm');
12
+ }
10
13
  }
11
14
 
12
15
  if (props.actions.includes('read')) {
13
16
  if (!props.requestGetByRecord) {
14
17
  console.warn('actions 包含 read 时,需要传递 requestGetByRecord');
15
18
  }
19
+ if (!props.detailForm) {
20
+ console.warn('actions 包含 read 时,需要传递 detailForm');
21
+ }
16
22
  }
17
23
 
18
24
  if (props.actions.includes('update')) {
@@ -21,6 +27,9 @@ function useTips<DataSource, Key>(props: CRUDProps<DataSource, Key>) {
21
27
  'actions 包含 update 时,需要传递 requestGetByRecord 和 requestUpdateByValues',
22
28
  );
23
29
  }
30
+ if (!props.detailForm) {
31
+ console.warn('actions 包含 update 时,需要传递 detailForm');
32
+ }
24
33
  }
25
34
 
26
35
  if (props.actions.includes('delete')) {
@@ -0,0 +1,108 @@
1
+ import type { EditorProps } from '@fe-free/core';
2
+ import { Editor } from '@fe-free/core';
3
+ import type { Meta, StoryObj } from '@storybook/react';
4
+ import { useState } from 'react';
5
+
6
+ const meta: Meta<typeof Editor> = {
7
+ title: '@fe-free/core/Editor',
8
+ component: Editor,
9
+ tags: ['autodocs'],
10
+ };
11
+
12
+ export default meta;
13
+ type Story = StoryObj<typeof Editor>;
14
+
15
+ const BasicDemo = (props: EditorProps) => {
16
+ const [value, setValue] = useState(props.value || '');
17
+
18
+ return (
19
+ <div style={{ width: '500px', height: '500px' }}>
20
+ <Editor {...props} value={value} onChange={setValue} />
21
+ </div>
22
+ );
23
+ };
24
+
25
+ // 基础用法
26
+ export const Basic: Story = {
27
+ args: {
28
+ value: 'hello world!',
29
+ },
30
+ render: (props) => <BasicDemo {...props} />,
31
+ };
32
+
33
+ // 只读模式
34
+ export const ReadOnly: Story = {
35
+ args: {
36
+ value: 'hello world!',
37
+ readOnly: true,
38
+ },
39
+ render: (props) => <BasicDemo {...props} />,
40
+ };
41
+
42
+ // 不可编辑模式
43
+ export const Editable: Story = {
44
+ args: {
45
+ value: 'hello world!',
46
+ editable: false,
47
+ },
48
+ render: (props) => <BasicDemo {...props} />,
49
+ };
50
+
51
+ // 自动聚焦
52
+ export const AutoFocus: Story = {
53
+ args: {
54
+ value: '',
55
+ autoFocus: true,
56
+ },
57
+ render: (props) => <BasicDemo {...props} />,
58
+ };
59
+
60
+ export const Javascript: Story = {
61
+ args: {
62
+ language: 'javascript',
63
+ value: 'console.log("Hello, World!")',
64
+ },
65
+ render: (props) => <BasicDemo {...props} />,
66
+ };
67
+
68
+ export const Python: Story = {
69
+ args: {
70
+ language: 'python',
71
+ value: `def fibonacci(n):
72
+ if n <= 1:
73
+ return n
74
+ else:
75
+ return fibonacci(n-1) + fibonacci(n-2)
76
+
77
+ # 测试斐波那契数列
78
+ for i in range(10):
79
+ print(f"fibonacci({i}) = {fibonacci(i)}")`,
80
+ },
81
+ render: (props) => <BasicDemo {...props} />,
82
+ };
83
+
84
+ export const JSON: Story = {
85
+ args: {
86
+ language: 'json',
87
+ value: '{"action": "hello", "data": "world"}',
88
+ },
89
+ render: (props) => <BasicDemo {...props} />,
90
+ };
91
+
92
+ export const Markdown: Story = {
93
+ args: {
94
+ language: 'markdown',
95
+ value: `# Hello, World!
96
+
97
+ This is a markdown file.
98
+
99
+ ## Title2
100
+
101
+ ### Title 3
102
+
103
+ - Item 1
104
+ - Item 2
105
+ - Item 3`,
106
+ },
107
+ render: (props) => <BasicDemo {...props} />,
108
+ };
@@ -0,0 +1,89 @@
1
+ import { javascript } from '@codemirror/lang-javascript';
2
+ import { json } from '@codemirror/lang-json';
3
+ import { markdown } from '@codemirror/lang-markdown';
4
+ import { python } from '@codemirror/lang-python';
5
+ import type { ReactCodeMirrorProps } from '@uiw/react-codemirror';
6
+ import CodeMirror from '@uiw/react-codemirror';
7
+ import { useCallback, useMemo } from 'react';
8
+
9
+ interface EditorProps {
10
+ language?: 'javascript' | 'python' | 'json' | 'markdown';
11
+ value?: string;
12
+ onChange?: (value: string) => void;
13
+ autoFocus?: boolean;
14
+ placeholder?: string;
15
+ readOnly?: boolean;
16
+ editable?: boolean;
17
+
18
+ // 不对外
19
+ theme?: ReactCodeMirrorProps['theme'];
20
+ extensions?: ReactCodeMirrorProps['extensions'];
21
+ }
22
+
23
+ function Editor(props: EditorProps) {
24
+ const {
25
+ language,
26
+ value,
27
+ onChange,
28
+ readOnly,
29
+ editable,
30
+ autoFocus,
31
+ placeholder,
32
+ theme,
33
+ extensions: originExtensions,
34
+ } = props;
35
+
36
+ const extensions = useMemo(() => {
37
+ const result: ReactCodeMirrorProps['extensions'] = [];
38
+
39
+ if (originExtensions) {
40
+ result.push(...originExtensions);
41
+ }
42
+
43
+ switch (language) {
44
+ case 'javascript':
45
+ result.push(javascript());
46
+ break;
47
+ case 'python':
48
+ result.push(python());
49
+ break;
50
+ case 'json':
51
+ result.push(json());
52
+ break;
53
+ case 'markdown':
54
+ result.push(markdown());
55
+ break;
56
+ default:
57
+ break;
58
+ }
59
+
60
+ return result;
61
+ }, [language, originExtensions]);
62
+
63
+ const handleChange = useCallback(
64
+ (value: string) => {
65
+ onChange?.(value);
66
+ },
67
+ [onChange],
68
+ );
69
+
70
+ return (
71
+ <CodeMirror
72
+ className="w-full h-full"
73
+ height="100%"
74
+ width="100%"
75
+ value={value}
76
+ onChange={handleChange}
77
+ extensions={extensions}
78
+ editable={editable}
79
+ readOnly={readOnly}
80
+ autoFocus={autoFocus}
81
+ placeholder={placeholder}
82
+ // 不对外
83
+ theme={theme}
84
+ />
85
+ );
86
+ }
87
+
88
+ export { Editor };
89
+ export type { EditorProps };
@@ -44,4 +44,9 @@ export const Basic: Story = {
44
44
  },
45
45
  ],
46
46
  },
47
+ render: (props) => (
48
+ <div style={{ width: '500px', height: '500px' }}>
49
+ <EditorLogs {...props} />
50
+ </div>
51
+ ),
47
52
  };
@@ -1,8 +1,8 @@
1
1
  import { StreamLanguage } from '@codemirror/language';
2
2
  import { tags as t } from '@lezer/highlight';
3
3
  import { createTheme } from '@uiw/codemirror-themes';
4
- import CodeMirror from '@uiw/react-codemirror';
5
4
  import React from 'react';
5
+ import { Editor } from '../editor';
6
6
 
7
7
  interface EditorLogsProps {
8
8
  logs: {
@@ -55,14 +55,7 @@ const EditorLogs: React.FC<EditorLogsProps> = ({ logs }) => {
55
55
  });
56
56
 
57
57
  return (
58
- <CodeMirror
59
- value={formattedLogs}
60
- theme={myTheme}
61
- extensions={logExtension}
62
- editable={false}
63
- height="400px"
64
- style={{ overflowY: 'auto' }}
65
- />
58
+ <Editor value={formattedLogs} theme={myTheme} extensions={logExtension} editable={false} />
66
59
  );
67
60
  };
68
61
 
package/src/index.ts CHANGED
@@ -3,6 +3,8 @@ export { LoadingButton } from './button';
3
3
  export { CRUD, CRUDDetail, CRUDOfSimple, OperateDelete, useDelete } from './crud';
4
4
  export type { CRUDDetailProps, CRUDMethods, CRUDOfSimpleProps, CRUDProps } from './crud';
5
5
 
6
+ export { Editor } from './editor';
7
+ export type { EditorProps } from './editor';
6
8
  export { EditorJavascript } from './editor_javascript';
7
9
  export type { EditorJavascriptProps } from './editor_javascript';
8
10
  export { EditorJSON } from './editor_json';