lu-lowcode-package-form 0.9.46 → 0.9.48
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/dist/index.cjs.js +1266 -292
- package/dist/index.es.js +81954 -46769
- package/dist/style.css +2 -2
- package/package.json +7 -3
- package/src/App.jsx +8 -2
- package/src/components/editor/index.jsx +3 -1
- package/src/components/editor/wang-demo.jsx +66 -0
- package/src/components/editor/wang.jsx +11 -17
- package/src/components/editor/wang2.jsx +30 -0
- package/src/components/field/base.jsx +16 -9
- package/src/components/field/select/select.jsx +10 -7
- package/src/components/index.jsx +3 -1
- package/src/components/wangEditor/index.jsx +167 -0
- package/src/components/wangEditor/menu/custom-menu.jsx +23 -0
- package/src/components/wangEditorNext/index.jsx +62 -0
@@ -0,0 +1,167 @@
|
|
1
|
+
/**
|
2
|
+
* @description React wangEditor usage
|
3
|
+
* @author wangfupeng
|
4
|
+
*/
|
5
|
+
|
6
|
+
import React, { useState, useEffect } from 'react'
|
7
|
+
import '@wangeditor/editor/dist/css/style.css'
|
8
|
+
import { Editor, Toolbar } from '@wangeditor/editor-for-react'
|
9
|
+
import { Boot } from '@wangeditor/editor'
|
10
|
+
import { DomEditor } from '@wangeditor/editor'
|
11
|
+
import CustomMenu from "./menu/custom-menu"
|
12
|
+
import { Modal } from 'antd'
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
let setSize = null;
|
17
|
+
let setRotation = null;
|
18
|
+
|
19
|
+
const printSizeConf = {
|
20
|
+
key: 'printSize',
|
21
|
+
factory() {
|
22
|
+
return new CustomMenu("纸张大小", (editor, value) => {
|
23
|
+
typeof setSize === 'function' && setSize(editor, value)
|
24
|
+
})
|
25
|
+
}
|
26
|
+
}
|
27
|
+
const printRotationConf = {
|
28
|
+
key: 'printRotation',
|
29
|
+
factory() {
|
30
|
+
return new CustomMenu("纸张方向", (editor, value) => {
|
31
|
+
typeof setRotation === 'function' && setRotation(editor, value)
|
32
|
+
})
|
33
|
+
}
|
34
|
+
}
|
35
|
+
const formParamsConf = {
|
36
|
+
key: 'formParams',
|
37
|
+
factory() {
|
38
|
+
return new CustomMenu("表单参数", (editor, value) => {
|
39
|
+
typeof setRotation === 'function' && setRotation(editor, value)
|
40
|
+
})
|
41
|
+
}
|
42
|
+
}
|
43
|
+
Boot.registerMenu(printSizeConf)
|
44
|
+
Boot.registerMenu(printRotationConf)
|
45
|
+
Boot.registerMenu(formParamsConf)
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
const WangEditor = () => {
|
50
|
+
|
51
|
+
const [showEdit, setShowEdit] = useState(false)
|
52
|
+
const [modalTitle, setModalTitle] = useState('纸张大小')
|
53
|
+
const [editor, setEditor] = useState(null) // 存储 editor 实例
|
54
|
+
const [html, setHtml] = useState('<p>hello</p>')
|
55
|
+
setSize = (editor, value) => {
|
56
|
+
setModalTitle('设置纸张大小')
|
57
|
+
setShowEdit(true)
|
58
|
+
}
|
59
|
+
setRotation = (editor, value) => {
|
60
|
+
setModalTitle('设置纸张方向')
|
61
|
+
setShowEdit(true)
|
62
|
+
|
63
|
+
}
|
64
|
+
// 模拟 ajax 请求,异步设置 html
|
65
|
+
useEffect(() => {
|
66
|
+
|
67
|
+
}, [])
|
68
|
+
useEffect(() => {
|
69
|
+
if (editor) {
|
70
|
+
|
71
|
+
console.log("editor.menus ////",editor.menus)
|
72
|
+
editor.on('before-delete', (type, range) => {
|
73
|
+
console.log('before-delete', type, range);
|
74
|
+
const selection = window.getSelection();
|
75
|
+
const anchorNode = selection.anchorNode;
|
76
|
+
if (anchorNode && anchorNode.parentNode.tagName === 'A') {
|
77
|
+
const aNode = anchorNode.parentNode;
|
78
|
+
const parent = aNode.parentNode;
|
79
|
+
if (parent && (parent.tagName === 'P' || parent.tagName === 'DIV')) {
|
80
|
+
// 移除整个 <a> 标签
|
81
|
+
parent.removeChild(aNode);
|
82
|
+
// 更新编辑器的内容
|
83
|
+
editor.txt.html(parent.innerHTML);
|
84
|
+
return false; // 阻止默认的删除行为
|
85
|
+
}
|
86
|
+
}
|
87
|
+
});
|
88
|
+
|
89
|
+
const toolbar = DomEditor.getToolbar(editor)
|
90
|
+
|
91
|
+
const curToolbarConfig = toolbar.getConfig()
|
92
|
+
console.log(curToolbarConfig.toolbarKeys)
|
93
|
+
}
|
94
|
+
}, [editor])
|
95
|
+
const handleWithOk = () => {
|
96
|
+
|
97
|
+
}
|
98
|
+
const toolbarConfig = {
|
99
|
+
insertKeys: {
|
100
|
+
index: 0,
|
101
|
+
keys: ['formParams' ,'printSize', 'printRotation','|' ], // show menu in toolbar
|
102
|
+
},
|
103
|
+
excludeKeys : [
|
104
|
+
'fullScreen' ,"insertLink"
|
105
|
+
],
|
106
|
+
hoverbar :{
|
107
|
+
table:['insertTable', 'deleteTable', 'insertRowUp', 'insertRowDown', 'insertColLeft', 'insertColRight','formParams' ]
|
108
|
+
}
|
109
|
+
}
|
110
|
+
const editorConfig = {
|
111
|
+
placeholder: '请输入内容...',
|
112
|
+
}
|
113
|
+
|
114
|
+
// 及时销毁 editor
|
115
|
+
useEffect(() => {
|
116
|
+
return () => {
|
117
|
+
if (editor == null) return
|
118
|
+
editor.destroy()
|
119
|
+
setEditor(null)
|
120
|
+
}
|
121
|
+
}, [editor])
|
122
|
+
|
123
|
+
function insertText() {
|
124
|
+
if (editor == null) return
|
125
|
+
editor.insertText(' hello ')
|
126
|
+
}
|
127
|
+
|
128
|
+
function printHtml() {
|
129
|
+
if (editor == null) return
|
130
|
+
console.log(editor.getHtml())
|
131
|
+
}
|
132
|
+
|
133
|
+
return (
|
134
|
+
<>
|
135
|
+
<div className='fflex fflex-col fitems-center fgap-y-2'>
|
136
|
+
<div className='fflex fgap-2 fborder-b'>
|
137
|
+
<div className='fflex-1 '> <Toolbar
|
138
|
+
editor={editor}
|
139
|
+
defaultConfig={toolbarConfig}
|
140
|
+
mode="default"
|
141
|
+
/></div>
|
142
|
+
</div>
|
143
|
+
<div className=' frounded fshadow-lg fw-[960px] fborder fborder-gray-100 '>
|
144
|
+
<Editor
|
145
|
+
defaultConfig={editorConfig}
|
146
|
+
value={html}
|
147
|
+
onCreated={setEditor}
|
148
|
+
onChange={editor => setHtml(editor.getHtml())}
|
149
|
+
mode="default"
|
150
|
+
style={{ height: '500px' }}
|
151
|
+
/></div>
|
152
|
+
</div>
|
153
|
+
<Modal
|
154
|
+
destroyOnClose={true}
|
155
|
+
width={500}
|
156
|
+
title={modalTitle}
|
157
|
+
open={showEdit}
|
158
|
+
onCancel={() => setShowEdit(false)}
|
159
|
+
onOk={handleWithOk}
|
160
|
+
>
|
161
|
+
111111111111
|
162
|
+
</Modal>
|
163
|
+
</>
|
164
|
+
)
|
165
|
+
}
|
166
|
+
|
167
|
+
export { WangEditor }
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
class CustomMenu {
|
3
|
+
constructor(title, handleClick) {
|
4
|
+
this.title = title
|
5
|
+
this.tag = 'button'
|
6
|
+
this.handleClick = handleClick
|
7
|
+
}
|
8
|
+
|
9
|
+
getValue(editor) {
|
10
|
+
return 'A4'
|
11
|
+
}
|
12
|
+
isActive(editor) {
|
13
|
+
return false // or true
|
14
|
+
}
|
15
|
+
isDisabled(editor) {
|
16
|
+
return false // or true
|
17
|
+
}
|
18
|
+
exec(editor, value) {
|
19
|
+
typeof this.handleClick === 'function' && this.handleClick(editor,value)
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
export default CustomMenu
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
2
|
+
import '@wangeditor-next/editor/dist/css/style.css';
|
3
|
+
import { Editor, Toolbar } from '@wangeditor-next/editor-for-react';
|
4
|
+
|
5
|
+
function WangEditorNext() {
|
6
|
+
const [editor, setEditor] = useState(null); // 存储 editor 实例
|
7
|
+
const [html, setHtml] = useState('<p>hello</p>');
|
8
|
+
|
9
|
+
// 模拟 ajax 请求,异步设置 html
|
10
|
+
useEffect(() => {
|
11
|
+
setTimeout(() => {
|
12
|
+
setHtml('<p>hello <strong>world</strong>.</p>\n<p><br></p>');
|
13
|
+
}, 1500);
|
14
|
+
}, []);
|
15
|
+
|
16
|
+
const toolbarConfig = {};
|
17
|
+
const editorConfig = {
|
18
|
+
placeholder: '请输入内容...',
|
19
|
+
};
|
20
|
+
|
21
|
+
// 及时销毁 editor
|
22
|
+
useEffect(() => {
|
23
|
+
return () => {
|
24
|
+
if (editor == null) return;
|
25
|
+
editor.destroy();
|
26
|
+
setEditor(null);
|
27
|
+
};
|
28
|
+
}, [editor]);
|
29
|
+
|
30
|
+
function insertText() {
|
31
|
+
if (editor == null) return;
|
32
|
+
editor.insertText(' hello ');
|
33
|
+
}
|
34
|
+
|
35
|
+
function printHtml() {
|
36
|
+
if (editor == null) return;
|
37
|
+
console.log(editor.getHtml());
|
38
|
+
}
|
39
|
+
|
40
|
+
return (
|
41
|
+
<>
|
42
|
+
<div style={{ border: '1px solid #ccc', zIndex: 100, marginTop: '15px' }}>
|
43
|
+
<Toolbar
|
44
|
+
editor={editor}
|
45
|
+
defaultConfig={toolbarConfig}
|
46
|
+
mode="default"
|
47
|
+
style={{ borderBottom: '1px solid #ccc' }}
|
48
|
+
/>
|
49
|
+
<Editor
|
50
|
+
defaultConfig={editorConfig}
|
51
|
+
value={html}
|
52
|
+
onCreated={setEditor}
|
53
|
+
onChange={(editor) => setHtml(editor.getHtml())}
|
54
|
+
mode="default"
|
55
|
+
style={{ height: '500px' }}
|
56
|
+
/>
|
57
|
+
</div>
|
58
|
+
</>
|
59
|
+
);
|
60
|
+
}
|
61
|
+
|
62
|
+
export {WangEditorNext} ;
|