@senyao-design-system/editor 0.0.3 → 0.0.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/README.md +251 -172
- package/dist/assets/style.css +1 -1
- package/dist/components/Editor.d.ts +4 -8
- package/dist/components/GenericEditor.d.ts +4 -3
- package/dist/components/JSONEditor.d.ts +4 -6
- package/dist/components/SQLEditor.d.ts +3 -7
- package/dist/extensions/index.d.ts +1 -0
- package/dist/extensions/search.d.ts +38 -0
- package/dist/i18n/index.d.ts +1 -0
- package/dist/i18n/search-zh-cn-v2.d.ts +13 -0
- package/dist/i18n/search-zh-cn.d.ts +44 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +16 -16
- package/dist/index.mjs +2398 -1346
- package/dist/types.d.ts +92 -0
- package/package.json +45 -43
- package/dist/types/index.d.ts +0 -115
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Extension } from '../@codemirror/state';
|
|
2
|
+
import { EditorView } from '../@codemirror/view';
|
|
3
|
+
import { CSSProperties } from '../react';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 只读区域定义
|
|
7
|
+
*/
|
|
8
|
+
export interface ReadOnlyRange {
|
|
9
|
+
/** 起始位置 */
|
|
10
|
+
start: number;
|
|
11
|
+
/** 结束位置 */
|
|
12
|
+
end: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 编辑器变更事件
|
|
16
|
+
*/
|
|
17
|
+
export interface EditorChangeEvent {
|
|
18
|
+
/** 当前编辑器的值 */
|
|
19
|
+
value: string;
|
|
20
|
+
/** 只读区域列表 */
|
|
21
|
+
readOnlyRanges: ReadOnlyRange[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 编辑器引用接口
|
|
25
|
+
*/
|
|
26
|
+
export interface EditorRef {
|
|
27
|
+
/** 在光标位置插入文本 */
|
|
28
|
+
insertTextAtCursor: (text: string) => void;
|
|
29
|
+
/** 定位到指定位置 */
|
|
30
|
+
goToPosition: (position: number) => void;
|
|
31
|
+
/** 定位到指定行列 */
|
|
32
|
+
goToLine: (line: number, column?: number) => void;
|
|
33
|
+
/** 获取编辑器视图实例 */
|
|
34
|
+
getEditorView: () => EditorView | undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 基础编辑器属性
|
|
38
|
+
*/
|
|
39
|
+
export interface EditorProps {
|
|
40
|
+
/** 编辑器的值 */
|
|
41
|
+
value?: string;
|
|
42
|
+
/** 值变更回调 */
|
|
43
|
+
onChange?: (event: EditorChangeEvent) => void;
|
|
44
|
+
/** 自定义扩展 */
|
|
45
|
+
extensions?: Extension[];
|
|
46
|
+
/** 编辑器高度 */
|
|
47
|
+
height?: string;
|
|
48
|
+
/** 是否禁用 */
|
|
49
|
+
disabled?: boolean;
|
|
50
|
+
/** 自定义类名 */
|
|
51
|
+
className?: string;
|
|
52
|
+
/** 自定义样式 */
|
|
53
|
+
style?: CSSProperties;
|
|
54
|
+
/** 占位符文本 */
|
|
55
|
+
placeholder?: string;
|
|
56
|
+
/** 是否显示行号 */
|
|
57
|
+
showLineNumbers?: boolean;
|
|
58
|
+
/** 编辑器视图创建时的回调 */
|
|
59
|
+
onEditorViewCreated?: (view: EditorView) => void;
|
|
60
|
+
/** 语言类型(用于通用编辑器) */
|
|
61
|
+
language?: string;
|
|
62
|
+
/** 编辑器界面语言 */
|
|
63
|
+
locale?: 'zh-CN' | 'en-US';
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* SQL 编辑器属性
|
|
67
|
+
*/
|
|
68
|
+
export interface SQLEditorProps extends Omit<EditorProps, 'onChange' | 'value'> {
|
|
69
|
+
/**
|
|
70
|
+
* 编辑器的值
|
|
71
|
+
* 可以是字符串或者 EditorChangeEvent 对象(用于 Ant Design Form 兼容性)
|
|
72
|
+
*/
|
|
73
|
+
value?: string | EditorChangeEvent;
|
|
74
|
+
/**
|
|
75
|
+
* 值变更回调
|
|
76
|
+
* 可以接收 EditorChangeEvent 对象或字符串(用于 Ant Design Form 兼容性)
|
|
77
|
+
*/
|
|
78
|
+
onChange?: (event: EditorChangeEvent | string) => void;
|
|
79
|
+
/** 外部提供的只读区域 */
|
|
80
|
+
readOnlyRanges?: ReadOnlyRange[];
|
|
81
|
+
/** 是否管理只读区域 */
|
|
82
|
+
manageReadOnlyRanges?: boolean;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* JSON 编辑器属性
|
|
86
|
+
*/
|
|
87
|
+
export interface JSONEditorProps extends EditorProps {
|
|
88
|
+
/** 是否启用格式化功能 */
|
|
89
|
+
enableFormatting?: boolean;
|
|
90
|
+
/** 是否启用代码折叠功能 */
|
|
91
|
+
enableCodeFolding?: boolean;
|
|
92
|
+
}
|
package/package.json
CHANGED
|
@@ -1,43 +1,45 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@senyao-design-system/editor",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "A flexible editor component based on CodeMirror",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.mjs",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"files": [
|
|
9
|
-
"dist"
|
|
10
|
-
],
|
|
11
|
-
"scripts": {
|
|
12
|
-
"build": "vite build",
|
|
13
|
-
"dev": "vite build --watch"
|
|
14
|
-
},
|
|
15
|
-
"peerDependencies": {
|
|
16
|
-
"react": "^18.0.0",
|
|
17
|
-
"react-dom": "^18.0.0"
|
|
18
|
-
},
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"@codemirror/autocomplete": "^6.11.1",
|
|
21
|
-
"@codemirror/commands": "^6.3.0",
|
|
22
|
-
"@codemirror/lang-json": "^6.0.1",
|
|
23
|
-
"@codemirror/lang-sql": "^6.5.4",
|
|
24
|
-
"@codemirror/language": "^6.9.3",
|
|
25
|
-
"@codemirror/lint": "^6.4.2",
|
|
26
|
-
"@codemirror/
|
|
27
|
-
"@codemirror/
|
|
28
|
-
"@
|
|
29
|
-
"@
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"@
|
|
34
|
-
"@types/react
|
|
35
|
-
"@
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"vite
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@senyao-design-system/editor",
|
|
3
|
+
"version": "0.0.5",
|
|
4
|
+
"description": "A flexible editor component based on CodeMirror",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "vite build",
|
|
13
|
+
"dev": "vite build --watch"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"react": "^18.0.0",
|
|
17
|
+
"react-dom": "^18.0.0"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@codemirror/autocomplete": "^6.11.1",
|
|
21
|
+
"@codemirror/commands": "^6.3.0",
|
|
22
|
+
"@codemirror/lang-json": "^6.0.1",
|
|
23
|
+
"@codemirror/lang-sql": "^6.5.4",
|
|
24
|
+
"@codemirror/language": "^6.9.3",
|
|
25
|
+
"@codemirror/lint": "^6.4.2",
|
|
26
|
+
"@codemirror/search": "^6.5.4",
|
|
27
|
+
"@codemirror/state": "^6.4.0",
|
|
28
|
+
"@codemirror/view": "^6.22.3",
|
|
29
|
+
"@emotion/react": "^11.11.0",
|
|
30
|
+
"@lezer/highlight": "^1.2.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@emotion/babel-plugin": "^11.11.0",
|
|
34
|
+
"@types/react": "^18.0.0",
|
|
35
|
+
"@types/react-dom": "^18.0.0",
|
|
36
|
+
"@vitejs/plugin-react": "^4.2.1",
|
|
37
|
+
"typescript": "^5.0.0",
|
|
38
|
+
"vite": "^5.0.0",
|
|
39
|
+
"vite-plugin-dts": "^3.6.0"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public",
|
|
43
|
+
"registry": "https://registry.npmjs.org/"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/dist/types/index.d.ts
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { Extension } from '../../@codemirror/state';
|
|
2
|
-
import { EditorView } from '../../@codemirror/view';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 只读区域范围接口
|
|
6
|
-
*/
|
|
7
|
-
export interface ReadOnlyRange {
|
|
8
|
-
/**
|
|
9
|
-
* 开始位置
|
|
10
|
-
*/
|
|
11
|
-
start: number;
|
|
12
|
-
/**
|
|
13
|
-
* 结束位置
|
|
14
|
-
*/
|
|
15
|
-
end: number;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* 编辑器变更事件数据
|
|
19
|
-
*/
|
|
20
|
-
export interface EditorChangeEvent {
|
|
21
|
-
/**
|
|
22
|
-
* 编辑器的新值
|
|
23
|
-
*/
|
|
24
|
-
value: string;
|
|
25
|
-
/**
|
|
26
|
-
* 当前的只读区域范围
|
|
27
|
-
*/
|
|
28
|
-
readOnlyRanges: ReadOnlyRange[];
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* 基础编辑器属性接口
|
|
32
|
-
*/
|
|
33
|
-
export interface BaseEditorProps {
|
|
34
|
-
/**
|
|
35
|
-
* 编辑器的值
|
|
36
|
-
*/
|
|
37
|
-
value: string;
|
|
38
|
-
/**
|
|
39
|
-
* 编辑器值变化时的回调函数
|
|
40
|
-
*/
|
|
41
|
-
onChange?: (event: EditorChangeEvent) => void;
|
|
42
|
-
/**
|
|
43
|
-
* 编辑器高度,默认 '300px'
|
|
44
|
-
*/
|
|
45
|
-
height?: string | number;
|
|
46
|
-
/**
|
|
47
|
-
* 是否禁用编辑器
|
|
48
|
-
*/
|
|
49
|
-
disabled?: boolean;
|
|
50
|
-
/**
|
|
51
|
-
* 编辑器样式类名
|
|
52
|
-
*/
|
|
53
|
-
className?: string;
|
|
54
|
-
/**
|
|
55
|
-
* 编辑器内联样式
|
|
56
|
-
*/
|
|
57
|
-
style?: React.CSSProperties;
|
|
58
|
-
/**
|
|
59
|
-
* 占位文本
|
|
60
|
-
*/
|
|
61
|
-
placeholder?: string;
|
|
62
|
-
/**
|
|
63
|
-
* 是否显示行号,默认为 true
|
|
64
|
-
*/
|
|
65
|
-
showLineNumbers?: boolean;
|
|
66
|
-
/**
|
|
67
|
-
* 编辑器视图创建后的回调
|
|
68
|
-
*/
|
|
69
|
-
onEditorViewCreated?: (view: EditorView) => void;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* 通用编辑器属性接口
|
|
73
|
-
*/
|
|
74
|
-
export interface EditorProps extends BaseEditorProps {
|
|
75
|
-
/**
|
|
76
|
-
* 编辑器扩展
|
|
77
|
-
*/
|
|
78
|
-
extensions?: Extension[];
|
|
79
|
-
/**
|
|
80
|
-
* 编辑器语言
|
|
81
|
-
*/
|
|
82
|
-
language?: string;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* SQL 编辑器属性接口
|
|
86
|
-
*/
|
|
87
|
-
export interface SQLEditorProps extends BaseEditorProps {
|
|
88
|
-
/**
|
|
89
|
-
* SQL 编辑器扩展
|
|
90
|
-
*/
|
|
91
|
-
extensions?: Extension[];
|
|
92
|
-
/**
|
|
93
|
-
* 不可编辑区域范围
|
|
94
|
-
*/
|
|
95
|
-
readOnlyRanges?: ReadOnlyRange[];
|
|
96
|
-
/**
|
|
97
|
-
* 是否内部管理只读区域(默认为true)
|
|
98
|
-
*/
|
|
99
|
-
manageReadOnlyRanges?: boolean;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* JSON 编辑器属性接口
|
|
103
|
-
*/
|
|
104
|
-
export interface JSONEditorProps extends BaseEditorProps {
|
|
105
|
-
/**
|
|
106
|
-
* JSON 编辑器扩展
|
|
107
|
-
*/
|
|
108
|
-
extensions?: Extension[];
|
|
109
|
-
/**
|
|
110
|
-
* 是否启用JSON格式化功能
|
|
111
|
-
* 当为true时,初始加载和按下Alt+F (Mac上为Cmd+Alt+F) 时会自动格式化
|
|
112
|
-
*/
|
|
113
|
-
enableFormatting?: boolean;
|
|
114
|
-
}
|
|
115
|
-
export type { Extension, EditorView };
|