lu-lowcode-package-form 0.9.47 → 0.9.56
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 +81973 -46766
- package/dist/style.css +2 -2
- package/package.json +7 -3
- package/src/App.jsx +52 -21
- 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 +21 -9
- package/src/components/field/select/select.jsx +51 -26
- package/src/components/form-container/index.jsx +16 -6
- 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
- package/src/utils/formula.js +1 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
import React, { useEffect, useState } from "react";
|
1
|
+
import React, { useEffect, useState, forwardRef } from "react";
|
2
2
|
|
3
3
|
const FieldLable = ({ value, onChange }) => {
|
4
4
|
const [text, setText] = useState("");
|
@@ -8,15 +8,19 @@ const FieldLable = ({ value, onChange }) => {
|
|
8
8
|
}, [value]);
|
9
9
|
return <>{text}</>
|
10
10
|
}
|
11
|
-
|
12
|
-
|
11
|
+
export function withWrap(Component) {
|
12
|
+
return forwardRef((props, ref) => {
|
13
|
+
return <Component {...props} ref={ref} forwardedRef={ref}/>
|
14
|
+
});
|
15
|
+
}
|
16
|
+
export const BaseWrapper = ({
|
13
17
|
label,
|
14
18
|
higLabel = false,
|
15
19
|
children,
|
16
20
|
prompt,
|
17
21
|
subTable,
|
18
22
|
subTableHead = false,
|
19
|
-
subTableContent=true,
|
23
|
+
subTableContent = true,
|
20
24
|
hidePrompt = false,
|
21
25
|
subTableIndex,
|
22
26
|
addWrapper = true,
|
@@ -24,12 +28,20 @@ export const BaseWrapper = function BaseWrapper({
|
|
24
28
|
readonly,
|
25
29
|
isRequired,
|
26
30
|
...otherProps
|
27
|
-
}) {
|
31
|
+
}) => {
|
32
|
+
React.useImperativeHandle(ref, () => ({
|
33
|
+
handleChange: ( value )=>{
|
34
|
+
console.log("change", otherProps?.onChange)
|
35
|
+
console.log("value", value)
|
36
|
+
otherProps?.onChange(value)
|
37
|
+
},
|
38
|
+
}), []);
|
39
|
+
|
28
40
|
if (!addWrapper) return children;
|
29
41
|
// 不接管只读属性的组件
|
30
|
-
const ignoreReadonly = ["UploadImage","UploadFile","Table","WithMultipleSelect","WithSingleSelect"]
|
31
|
-
if (readonly){
|
32
|
-
console.log("children?.type?.displayName",children?.type?.displayName)
|
42
|
+
const ignoreReadonly = ["UploadImage", "UploadFile", "Table", "WithMultipleSelect", "WithSingleSelect"]
|
43
|
+
if (readonly) {
|
44
|
+
console.log("children?.type?.displayName", children?.type?.displayName)
|
33
45
|
}
|
34
46
|
if (ignoreReadonly.includes(children?.type?.displayName) && readonly) readonly = false
|
35
47
|
const formWarpper = (
|
@@ -55,7 +67,7 @@ export const BaseWrapper = function BaseWrapper({
|
|
55
67
|
{/* <FieldLable value={otherProps?.value} /> */}
|
56
68
|
{children}
|
57
69
|
</div>}
|
58
|
-
|
70
|
+
|
59
71
|
</div>
|
60
72
|
)
|
61
73
|
|
@@ -1,12 +1,12 @@
|
|
1
1
|
import { Select as OriginalSelect, Tree, Input, Button } from "antd";
|
2
2
|
|
3
|
-
import { BaseWrapper } from "../base"
|
4
|
-
import {SearchSelect} from "./search-select"
|
5
|
-
import React, { useEffect, useState } from 'react';
|
3
|
+
import { BaseWrapper, withWrap } from "../base"
|
4
|
+
import { SearchSelect } from "./search-select"
|
5
|
+
import React, { useEffect, useState, forwardRef } from 'react';
|
6
6
|
import TreeSelect from './tree-select'
|
7
7
|
import { EditOutlined } from '@ant-design/icons';
|
8
8
|
|
9
|
-
const Select = ({ request,
|
9
|
+
const Select = ({ request, option_label = "label", option_value = "id", disabledValue, callError, options, addWrapper = true, ...props }) => {
|
10
10
|
// const [firstLoad, setFirstLoad] = React.useState(false)
|
11
11
|
const [nOptions, setNOptions] = React.useState([])
|
12
12
|
useEffect(() => {
|
@@ -71,8 +71,8 @@ const MultipleSelect = ({ onChange, value, ...props }) => {
|
|
71
71
|
* @param {*}
|
72
72
|
* @returns
|
73
73
|
*/
|
74
|
-
const WithSingleSelect = ({ readItemRender, readonly,onChange, value, ...props }) => {
|
75
|
-
|
74
|
+
const WithSingleSelect = ({ readItemRender, readonly, onChange, value, ...props }) => {
|
75
|
+
|
76
76
|
React.useEffect(() => {
|
77
77
|
if (value && typeof value === "string") {
|
78
78
|
try {
|
@@ -85,11 +85,11 @@ const WithSingleSelect = ({ readItemRender, readonly,onChange, value, ...props }
|
|
85
85
|
|
86
86
|
}, [value])
|
87
87
|
if (readonly) return <div className=" fh-8 fflex fitems-center fgap-2">
|
88
|
-
|
88
|
+
{value && value.label && <>{readItemRender && typeof readItemRender === "function" ? readItemRender(value) : <span key={`btn_${value?.value}`}>{value?.label}</span>}</>}
|
89
89
|
</div>
|
90
90
|
return (
|
91
|
-
|
92
|
-
|
91
|
+
<SearchSelect addWrapper={false} {...props} onChange={onChange} value={value} mode="single" className=" fflex-1 foverflow-hidden" />
|
92
|
+
|
93
93
|
)
|
94
94
|
}
|
95
95
|
|
@@ -98,8 +98,8 @@ const WithSingleSelect = ({ readItemRender, readonly,onChange, value, ...props }
|
|
98
98
|
* @param {*}
|
99
99
|
* @returns
|
100
100
|
*/
|
101
|
-
const WithMultipleSelect = ({
|
102
|
-
|
101
|
+
const WithMultipleSelect = ({ readItemRender, readonly, onChange, value, ...props }) => {
|
102
|
+
|
103
103
|
React.useEffect(() => {
|
104
104
|
if (value && typeof value === "string") {
|
105
105
|
try {
|
@@ -112,22 +112,22 @@ const WithMultipleSelect = ({ readItemRender, readonly, onChange, value, ...pro
|
|
112
112
|
|
113
113
|
}, [value])
|
114
114
|
if (readonly) return <div className=" fh-8 fflex fitems-center fgap-2">
|
115
|
-
{Array.isArray(value) && value.map((item,index) => <> {
|
115
|
+
{Array.isArray(value) && value.map((item, index) => <> {
|
116
116
|
readItemRender && typeof readItemRender === "function" ? readItemRender(item) : <span key={`btn_${item?.value}`}>{item?.label}</span>
|
117
117
|
|
118
|
-
}{index<value.length-1? <span className=" ftext-gray-400">,</span> : null}</>)}
|
118
|
+
}{index < value.length - 1 ? <span className=" ftext-gray-400">,</span> : null}</>)}
|
119
119
|
</div>
|
120
120
|
return (
|
121
|
-
<SearchSelect addWrapper={false} {...props} onChange={onChange} value={value} mode="multiple"
|
121
|
+
<SearchSelect addWrapper={false} {...props} onChange={onChange} value={value} mode="multiple" className=" fflex-1 foverflow-hidden" />
|
122
122
|
)
|
123
123
|
}
|
124
124
|
|
125
|
-
// 选择用户组件
|
125
|
+
// 选择用户组件
|
126
126
|
const UserSelect = ({ customComponent: CustomComponent, ...props }) => {
|
127
127
|
if (!CustomComponent) return <BaseWrapper {...props}><Input {...props} /></BaseWrapper>
|
128
128
|
else return <BaseWrapper {...props}><CustomComponent {...props} /></BaseWrapper>
|
129
129
|
}
|
130
|
-
const ArrayTreeSelect = (
|
130
|
+
const ArrayTreeSelect = ({ onChange, value, multiple, ...props }) => {
|
131
131
|
const [nValue, setNValue] = React.useState()
|
132
132
|
useEffect(() => {
|
133
133
|
if (value && typeof value === "string") {
|
@@ -146,28 +146,53 @@ const ArrayTreeSelect = ( {onChange, value, multiple, ...props} )=>{
|
|
146
146
|
setNValue(value)
|
147
147
|
}
|
148
148
|
}, [value])
|
149
|
-
const handleChange = (_value)=>{
|
149
|
+
const handleChange = (_value) => {
|
150
150
|
if (!Array.isArray(_value)) _value = [_value]
|
151
151
|
onChange && typeof onChange == "function" && onChange(_value)
|
152
152
|
}
|
153
153
|
return <TreeSelect {...props} onChange={handleChange} value={nValue} multiple={multiple} />
|
154
154
|
}
|
155
155
|
// 选择部门组件
|
156
|
-
const DeptSelect = ({ FetchDeptList
|
156
|
+
const DeptSelect = ({ FetchDeptList, ...props }) => {
|
157
157
|
return <ArrayTreeSelect {...props} title={"deptName"} request={FetchDeptList} />
|
158
158
|
}
|
159
159
|
// 选择岗位组件
|
160
160
|
const PostSelect = ({ FetchPostList, ...props }) => {
|
161
|
-
return <ArrayTreeSelect {...props} title={"postName"}
|
161
|
+
return <ArrayTreeSelect {...props} title={"postName"} request={FetchPostList} />
|
162
162
|
}
|
163
163
|
|
164
164
|
WithSingleSelect.displayName = "WithSingleSelect"
|
165
165
|
WithMultipleSelect.displayName = "WithMultipleSelect"
|
166
166
|
|
167
|
-
const WithSingleSelectWrapper = (props) => {
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
167
|
+
// const WithSingleSelectWrapper = withWrap(({ ref, ...props }) => <BaseWrapper ref={ref} {...props}><WithSingleSelect {...props} /></BaseWrapper>);
|
168
|
+
// const WithMultipleSelectWrapper = withWrap(({ ref, ...props }) => <BaseWrapper ref={ref} {...props}><WithMultipleSelect {...props} /></BaseWrapper>);
|
169
|
+
|
170
|
+
|
171
|
+
// export class WithSingleSelectClass extends React.PureComponent{
|
172
|
+
// render() {
|
173
|
+
// const { forwardedRef, ...otherProps } = this.props;
|
174
|
+
// return <BaseWrapper {...otherProps} ref={forwardedRef}><WithSingleSelect {...otherProps} /></BaseWrapper>
|
175
|
+
// }
|
176
|
+
// }
|
177
|
+
|
178
|
+
const WithSingleSelectForward = forwardRef((props, ref) => {
|
179
|
+
React.useImperativeHandle(ref, () => ({
|
180
|
+
handleChange: ( value )=>{
|
181
|
+
props?.onChange(value)
|
182
|
+
},
|
183
|
+
}), []);
|
184
|
+
|
185
|
+
return <BaseWrapper {...props} ><WithSingleSelect {...props} /></BaseWrapper>
|
186
|
+
})
|
187
|
+
const WithMultipleSelectForward = forwardRef((props, ref) => {
|
188
|
+
React.useImperativeHandle(ref, () => ({
|
189
|
+
handleChange: ( value )=>{
|
190
|
+
props?.onChange(value)
|
191
|
+
},
|
192
|
+
}), []);
|
193
|
+
|
194
|
+
return <BaseWrapper {...props} ><WithMultipleSelect {...props} /></BaseWrapper>
|
195
|
+
})
|
196
|
+
|
197
|
+
export { WithSingleSelectForward as WithSingleSelect, WithMultipleSelectForward as WithMultipleSelect, MultipleSelect, SingleSelect, Select, UserSelect, DeptSelect, PostSelect };
|
198
|
+
|
@@ -73,7 +73,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
73
73
|
if (props?.withIds)
|
74
74
|
withIds = [...withIds, ...props?.withIds]
|
75
75
|
|
76
|
-
fields.push({ identifier, withIds, component: currentNode });
|
76
|
+
fields.push({ identifier, withIds, component: currentNode,componentName });
|
77
77
|
}
|
78
78
|
|
79
79
|
if (props?.children) {
|
@@ -96,6 +96,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
96
96
|
// })),
|
97
97
|
children: fields.filter(item => item.withIds.some(item => item == identifier)),
|
98
98
|
show: true,
|
99
|
+
componentName: field.componentName
|
99
100
|
});
|
100
101
|
});
|
101
102
|
// console.log("dependencyMap", dependencyMap.current)
|
@@ -121,7 +122,8 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
121
122
|
}
|
122
123
|
if (dependencyMap.current.has(identifier)) {
|
123
124
|
// console.log("dependencyMap.current.get(identifier)",dependencyMap.current.get(identifier))
|
124
|
-
const
|
125
|
+
const dependent = dependencyMap.current.get(identifier)
|
126
|
+
const dependentChildren = dependent.children;
|
125
127
|
// console.log("dependentChildren", dependentChildren)
|
126
128
|
|
127
129
|
dependentChildren.forEach(child => {
|
@@ -130,7 +132,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
130
132
|
}
|
131
133
|
|
132
134
|
if (child.component.props.withFill)
|
133
|
-
handleFieldsWithFill(fieldValues, child, parentIdentifier)
|
135
|
+
handleFieldsWithFill(fieldValues, child, parentIdentifier,dependent?.componentName)
|
134
136
|
|
135
137
|
});
|
136
138
|
}
|
@@ -154,7 +156,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
154
156
|
}
|
155
157
|
// 处理级联数据源
|
156
158
|
// 处理级联填充
|
157
|
-
const handleFieldsWithFill = async (fieldValues, child, parentIdentifier) => {
|
159
|
+
const handleFieldsWithFill = async (fieldValues, child, parentIdentifier,componentName) => {
|
158
160
|
const withFill = child?.component?.props.withFill;
|
159
161
|
const withDataFetch = child?.component?.props.withDataFetch;
|
160
162
|
let withFillIndex = 0
|
@@ -165,9 +167,10 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
165
167
|
withFillIndex = parentIdentifier[parentIdentifier.length - 1]
|
166
168
|
if (childIdentifier.startsWith(`${withFillGroup}.`)) {
|
167
169
|
childIdentifier = [...parentIdentifier, childIdentifier.replace(`${withFillGroup}.`, "")]
|
168
|
-
}
|
170
|
+
}
|
169
171
|
}
|
170
172
|
let withDatas = [];
|
173
|
+
console.log("componentName",componentName)
|
171
174
|
// 先处理依赖数据
|
172
175
|
if (withFill?.withData && withFill?.withData.length > 0 && withDataFetch && typeof withDataFetch === 'function') {
|
173
176
|
for (let index = 0; index < withFill?.withData.length; index++) {
|
@@ -177,7 +180,14 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
177
180
|
params.filter = {}
|
178
181
|
for (let index = 0; index < element.withCondition.length; index++) {
|
179
182
|
const { value: condition_value, column: condition_column } = element.withCondition[index];
|
180
|
-
|
183
|
+
let filter_value = getParamValue(condition_value.group_key, condition_value.field_key, fieldValues, withDatas)
|
184
|
+
if (Array.isArray(filter_value)) {
|
185
|
+
if (Array.isArray(childIdentifier) && filter_value.length > withFillIndex) {
|
186
|
+
filter_value = filter_value[withFillIndex]
|
187
|
+
}
|
188
|
+
}
|
189
|
+
if (componentName == "Field.WithSingleSelect" && filter_value && filter_value?.value) filter_value = filter_value.value
|
190
|
+
params.filter[condition_column.column_name] = filter_value
|
181
191
|
}
|
182
192
|
|
183
193
|
// 访问接口获取数据
|
package/src/components/index.jsx
CHANGED
@@ -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} ;
|