zy-react-library 1.0.139 → 1.0.141
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/components/Editor/index.d.ts +29 -0
- package/components/Editor/index.js +99 -0
- package/components/HeaderBack/index.js +2 -0
- package/components/ImportFile/index.js +1 -0
- package/components/Map/MapSelector.js +1 -0
- package/components/Pdf/index.js +1 -0
- package/components/Signature/index.js +1 -0
- package/components/Video/AliPlayer.d.ts +1 -3
- package/components/Video/index.js +2 -0
- package/package.json +3 -1
- package/utils/index.d.ts +5 -0
- package/utils/index.js +10 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Editor as WangEditorInstance } from "@wangeditor/editor";
|
|
2
|
+
import type { ForwardRefExoticComponent, RefAttributes } from "react";
|
|
3
|
+
|
|
4
|
+
export interface EditorProps {
|
|
5
|
+
/** 编辑器内容值 */
|
|
6
|
+
value?: string;
|
|
7
|
+
/** 内容改变回调 */
|
|
8
|
+
onChange?: (html: string) => void;
|
|
9
|
+
/** 是否禁用 */
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface EditorRef {
|
|
14
|
+
/** 获取编辑器实例 */
|
|
15
|
+
getEditorInstance: () => WangEditorInstance | null;
|
|
16
|
+
/** 获取HTML内容 */
|
|
17
|
+
getHtml: () => string | undefined;
|
|
18
|
+
/** 设置HTML内容 */
|
|
19
|
+
setHtml: (value: string) => void;
|
|
20
|
+
/** 获取文本内容 */
|
|
21
|
+
getText: () => string | undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 富文本编辑器组件
|
|
26
|
+
*/
|
|
27
|
+
declare const Editor: ForwardRefExoticComponent<EditorProps & RefAttributes<EditorRef>>;
|
|
28
|
+
|
|
29
|
+
export default Editor;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Editor as ReactEditor, Toolbar } from "@wangeditor/editor-for-react";
|
|
2
|
+
import { forwardRef, useEffect, useImperativeHandle, useState } from "react";
|
|
3
|
+
import { normalizeEmptyHtml } from "../../utils";
|
|
4
|
+
import "@wangeditor/editor/dist/css/style.css";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 富文本编辑器组件
|
|
8
|
+
*/
|
|
9
|
+
const Editor = forwardRef(({
|
|
10
|
+
value,
|
|
11
|
+
onChange,
|
|
12
|
+
disabled,
|
|
13
|
+
}, ref) => {
|
|
14
|
+
const [editor, setEditor] = useState(null);
|
|
15
|
+
|
|
16
|
+
const [html, setHtml] = useState("");
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
setHtml(value);
|
|
20
|
+
}, [value]);
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!editor)
|
|
24
|
+
return;
|
|
25
|
+
if (disabled)
|
|
26
|
+
editor.disable();
|
|
27
|
+
else editor.enable();
|
|
28
|
+
}, [disabled]);
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
return () => {
|
|
32
|
+
if (!editor)
|
|
33
|
+
return;
|
|
34
|
+
editor.destroy();
|
|
35
|
+
setEditor(null);
|
|
36
|
+
};
|
|
37
|
+
}, [editor]);
|
|
38
|
+
|
|
39
|
+
useImperativeHandle(ref, () => ({
|
|
40
|
+
getEditorInstance: () => editor,
|
|
41
|
+
getHtml: () => editor && editor.getHtml(),
|
|
42
|
+
setHtml: (value) => {
|
|
43
|
+
editor && editor.setHtml(value);
|
|
44
|
+
},
|
|
45
|
+
getText: () => editor && editor.getText(),
|
|
46
|
+
}));
|
|
47
|
+
|
|
48
|
+
const handleCreated = (editor) => {
|
|
49
|
+
setEditor(editor);
|
|
50
|
+
if (disabled)
|
|
51
|
+
editor.disable();
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const handleChange = (editor) => {
|
|
55
|
+
setHtml(editor.getHtml());
|
|
56
|
+
onChange?.(normalizeEmptyHtml(editor.getHtml()));
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// 工具栏配置
|
|
60
|
+
const toolbarConfig = {
|
|
61
|
+
excludeKeys: [
|
|
62
|
+
"group-image",
|
|
63
|
+
"group-video",
|
|
64
|
+
"insertLink",
|
|
65
|
+
"emotion",
|
|
66
|
+
"todo",
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// 编辑器配置
|
|
71
|
+
const editorConfig = {
|
|
72
|
+
placeholder: "请输入内容...",
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<>
|
|
77
|
+
<div style={{ border: "1px solid #ccc" }}>
|
|
78
|
+
<Toolbar
|
|
79
|
+
editor={editor}
|
|
80
|
+
defaultConfig={toolbarConfig}
|
|
81
|
+
mode="default"
|
|
82
|
+
style={{ borderBottom: "1px solid #ccc" }}
|
|
83
|
+
/>
|
|
84
|
+
<ReactEditor
|
|
85
|
+
defaultConfig={editorConfig}
|
|
86
|
+
value={html}
|
|
87
|
+
onCreated={handleCreated}
|
|
88
|
+
onChange={handleChange}
|
|
89
|
+
mode="default"
|
|
90
|
+
style={{ height: "500px", overflowY: "hidden" }}
|
|
91
|
+
/>
|
|
92
|
+
</div>
|
|
93
|
+
</>
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
Editor.displayName = "Editor";
|
|
98
|
+
|
|
99
|
+
export default Editor;
|
package/components/Pdf/index.js
CHANGED
|
@@ -35,8 +35,6 @@ export interface AliPlayerRef {
|
|
|
35
35
|
/**
|
|
36
36
|
* 视频播放组件
|
|
37
37
|
*/
|
|
38
|
-
declare const AliPlayer: ForwardRefExoticComponent<
|
|
39
|
-
AliPlayerProps & RefAttributes<AliPlayerRef>
|
|
40
|
-
>;
|
|
38
|
+
declare const AliPlayer: ForwardRefExoticComponent<AliPlayerProps & RefAttributes<AliPlayerRef>>;
|
|
41
39
|
|
|
42
40
|
export default AliPlayer;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zy-react-library",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.141",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "",
|
|
7
7
|
"author": "LiuJiaNan",
|
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
"@ant-design/pro-components": "^2.8.10",
|
|
27
27
|
"@cqsjjb/jjb-common-lib": "latest",
|
|
28
28
|
"@cqsjjb/jjb-react-admin-component": "latest",
|
|
29
|
+
"@wangeditor/editor": "^5.1.23",
|
|
30
|
+
"@wangeditor/editor-for-react": "^1.0.6",
|
|
29
31
|
"ahooks": "^3.9.5",
|
|
30
32
|
"antd": "^5.27.6",
|
|
31
33
|
"dayjs": "^1.11.18",
|
package/utils/index.d.ts
CHANGED
package/utils/index.js
CHANGED
|
@@ -552,6 +552,16 @@ export function dynamicLoadCss(url) {
|
|
|
552
552
|
});
|
|
553
553
|
}
|
|
554
554
|
|
|
555
|
+
/**
|
|
556
|
+
* 是否空html,用于给富文本编辑器使用
|
|
557
|
+
*/
|
|
558
|
+
export function normalizeEmptyHtml(html) {
|
|
559
|
+
if (!html)
|
|
560
|
+
return "";
|
|
561
|
+
const cleaned = html.replace(/\s+/g, "").toLowerCase();
|
|
562
|
+
return cleaned === "<p><br></p>" || cleaned === "<p></p>" || cleaned === "" ? "" : html;
|
|
563
|
+
}
|
|
564
|
+
|
|
555
565
|
/**
|
|
556
566
|
* 获取文件url
|
|
557
567
|
*/
|