- added clean btn for editor and added autoformatter module;
This commit is contained in:
@@ -1,11 +1,19 @@
|
|||||||
import React from 'react';
|
import React, { useRef } from 'react';
|
||||||
import { classNames } from 'primereact/utils';
|
import { classNames } from 'primereact/utils';
|
||||||
import { Controller } from 'react-hook-form';
|
import { Controller } from 'react-hook-form';
|
||||||
|
import Quill from 'quill';
|
||||||
|
import { __ } from '@wordpress/i18n';
|
||||||
|
|
||||||
|
// components
|
||||||
import { Editor } from 'primereact/editor';
|
import { Editor } from 'primereact/editor';
|
||||||
import BlockingOverlay from '../../../BlockingOverlay';
|
import BlockingOverlay from '../../../BlockingOverlay';
|
||||||
|
import { Button } from 'primereact/button';
|
||||||
|
|
||||||
|
const Delta = Quill.import('delta');
|
||||||
|
|
||||||
const Wysiwyg = ({
|
const Wysiwyg = ({
|
||||||
fieldName,
|
fieldName,
|
||||||
|
setDataFn,
|
||||||
label,
|
label,
|
||||||
control,
|
control,
|
||||||
rows = 3,
|
rows = 3,
|
||||||
@@ -16,6 +24,11 @@ const Wysiwyg = ({
|
|||||||
placeholder = '',
|
placeholder = '',
|
||||||
disabled = false
|
disabled = false
|
||||||
}) => {
|
}) => {
|
||||||
|
const editorRef = useRef(null);
|
||||||
|
|
||||||
|
const handleCleanValue = () => {
|
||||||
|
setDataFn(fieldName, '', { shouldValidate: true });
|
||||||
|
};
|
||||||
|
|
||||||
const renderHeader = () => {
|
const renderHeader = () => {
|
||||||
return (
|
return (
|
||||||
@@ -42,6 +55,13 @@ const Wysiwyg = ({
|
|||||||
<label htmlFor={fieldName} className={classNames({ 'p-error': errors[fieldName] })}>
|
<label htmlFor={fieldName} className={classNames({ 'p-error': errors[fieldName] })}>
|
||||||
{label}{config.required || config.isRequired ? <span className="appForm__field--required">*</span> : null}
|
{label}{config.required || config.isRequired ? <span className="appForm__field--required">*</span> : null}
|
||||||
</label>
|
</label>
|
||||||
|
<Button
|
||||||
|
label={__('Cancella testo', 'gepafin')}
|
||||||
|
type="button"
|
||||||
|
severity="warning"
|
||||||
|
outlined
|
||||||
|
onClick={handleCleanValue}
|
||||||
|
/>
|
||||||
<Controller
|
<Controller
|
||||||
name={fieldName}
|
name={fieldName}
|
||||||
control={control}
|
control={control}
|
||||||
@@ -49,10 +69,22 @@ const Wysiwyg = ({
|
|||||||
rules={config}
|
rules={config}
|
||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<Editor
|
<Editor
|
||||||
|
ref={editorRef}
|
||||||
id={field.name}
|
id={field.name}
|
||||||
readOnly={disabled}
|
readOnly={disabled}
|
||||||
{...field}
|
{...field}
|
||||||
headerTemplate={header}
|
headerTemplate={header}
|
||||||
|
modules={{
|
||||||
|
clipboard: {
|
||||||
|
matchers: [
|
||||||
|
[ Node.ELEMENT_NODE, function(node, delta) {
|
||||||
|
console.log('here')
|
||||||
|
const ops = delta.ops.map((op) => ({insert: op.insert}));
|
||||||
|
return new Delta(ops)
|
||||||
|
}]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
onTextChange={(e) => field.onChange(e.htmlValue)}
|
onTextChange={(e) => field.onChange(e.htmlValue)}
|
||||||
style={{ height: 80 * rows }}
|
style={{ height: 80 * rows }}
|
||||||
|
|||||||
Reference in New Issue
Block a user