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.
@@ -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;
@@ -32,4 +32,6 @@ function HeaderBack(props) {
32
32
  );
33
33
  }
34
34
 
35
+ HeaderBack.displayName = "HeaderBack";
36
+
35
37
  export default HeaderBack;
@@ -51,6 +51,7 @@ const ImportFile = (props) => {
51
51
  open={visible}
52
52
  onCancel={handleClose}
53
53
  width={600}
54
+ maskClosable={false}
54
55
  footer={[
55
56
  templateUrl && (
56
57
  <Button key="export" onClick={handleExportTemplate}>
@@ -154,6 +154,7 @@ const MapSelector = (props) => {
154
154
  onCancel={handleClose}
155
155
  width={1000}
156
156
  destroyOnHidden={false}
157
+ maskClosable={false}
157
158
  afterClose={handleAfterClose}
158
159
  footer={[
159
160
  <Button key="back" onClick={handleClose}>
@@ -91,6 +91,7 @@ function Pdf(props) {
91
91
  return (
92
92
  <Modal
93
93
  open={visible}
94
+ maskClosable={false}
94
95
  width={pdfWidth + 100}
95
96
  title="PDF预览"
96
97
  onCancel={onCancel}
@@ -60,6 +60,7 @@ function Signature(props) {
60
60
  title="签字"
61
61
  width={800}
62
62
  open={signatureModalOpen}
63
+ maskClosable={false}
63
64
  onCancel={() => setSignatureModalOpen(false)}
64
65
  footer={[
65
66
  <Button key="clear" onClick={() => signatureCanvas.current.clear()}>重签</Button>,
@@ -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;
@@ -85,4 +85,6 @@ const Video = ({
85
85
  return playerElement;
86
86
  };
87
87
 
88
+ Video.displayName = "Video";
89
+
88
90
  export default Video;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zy-react-library",
3
3
  "private": false,
4
- "version": "1.0.139",
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
@@ -342,3 +342,8 @@ export function dynamicLoadJs(url: string): Promise<void>;
342
342
  * 动态加载css资源
343
343
  */
344
344
  export function dynamicLoadCss(url: string): Promise<void>;
345
+
346
+ /**
347
+ * 是否空html,用于给富文本编辑器使用
348
+ */
349
+ export function normalizeEmptyHtml(html: string): string;
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
  */