@aatulwork/customform-renderer 1.5.0 → 1.7.0
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.js +29 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -659,14 +659,31 @@ var CKEditorField = ({ field, control, defaultValue, rules, errors, setValue, fo
|
|
|
659
659
|
const theme = material.useTheme();
|
|
660
660
|
const formColors = useFormColors(colors);
|
|
661
661
|
const editorContainerRef = react.useRef(null);
|
|
662
|
+
const editorInstanceRef = react.useRef(null);
|
|
663
|
+
const isUserTypingRef = react.useRef(false);
|
|
662
664
|
const fileUploadService = services?.fileUpload || defaultFileUploadService;
|
|
663
665
|
const fileBaseUrl = services?.fileBaseUrl || "";
|
|
664
|
-
const licenseKey = services?.ckEditorLicenseKey || "";
|
|
666
|
+
const licenseKey = services?.ckEditorLicenseKey || "GPL";
|
|
665
667
|
const ckEditorScriptPath = services?.ckEditorScriptPath || "/lib/ckeditor/ckeditor.js";
|
|
666
668
|
const { isReady: isCKEditorReady, isLoading: isCKEditorLoading, error: ckEditorError } = useCKEditor({
|
|
667
669
|
scriptPath: ckEditorScriptPath,
|
|
668
670
|
autoLoad: true
|
|
669
671
|
});
|
|
672
|
+
const watchedValue = reactHookForm.useWatch({
|
|
673
|
+
control,
|
|
674
|
+
name: field.name,
|
|
675
|
+
defaultValue: defaultValue || ""
|
|
676
|
+
});
|
|
677
|
+
react.useEffect(() => {
|
|
678
|
+
if (editorInstanceRef.current && isCKEditorReady && !isUserTypingRef.current) {
|
|
679
|
+
const currentEditorData = editorInstanceRef.current.getData();
|
|
680
|
+
const formValue = watchedValue || "";
|
|
681
|
+
if (currentEditorData !== formValue) {
|
|
682
|
+
editorInstanceRef.current.setData(formValue);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
isUserTypingRef.current = false;
|
|
686
|
+
}, [watchedValue, isCKEditorReady]);
|
|
670
687
|
const createCustomUploadAdapter = react.useCallback((loader) => {
|
|
671
688
|
return {
|
|
672
689
|
upload: async () => {
|
|
@@ -780,6 +797,7 @@ var CKEditorField = ({ field, control, defaultValue, rules, errors, setValue, fo
|
|
|
780
797
|
},
|
|
781
798
|
data: formField.value || "",
|
|
782
799
|
onReady: (editor) => {
|
|
800
|
+
editorInstanceRef.current = editor;
|
|
783
801
|
if (formSchema?.name) {
|
|
784
802
|
try {
|
|
785
803
|
const fileRepository = editor.plugins.get("FileRepository");
|
|
@@ -803,6 +821,7 @@ var CKEditorField = ({ field, control, defaultValue, rules, errors, setValue, fo
|
|
|
803
821
|
},
|
|
804
822
|
onChange: (_event, editor) => {
|
|
805
823
|
const data = editor.getData();
|
|
824
|
+
isUserTypingRef.current = true;
|
|
806
825
|
formField.onChange(data);
|
|
807
826
|
},
|
|
808
827
|
onBlur: () => {
|
|
@@ -1602,10 +1621,15 @@ var FormRenderer = ({
|
|
|
1602
1621
|
if (onSubmit) {
|
|
1603
1622
|
try {
|
|
1604
1623
|
await onSubmit(transformedData);
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1624
|
+
clearErrors();
|
|
1625
|
+
reset(initialValues || {}, {
|
|
1626
|
+
keepErrors: false,
|
|
1627
|
+
keepDirty: false,
|
|
1628
|
+
keepTouched: false,
|
|
1629
|
+
keepIsSubmitted: false,
|
|
1630
|
+
keepSubmitCount: false
|
|
1631
|
+
});
|
|
1632
|
+
if (onSuccess) onSuccess();
|
|
1609
1633
|
} catch (error) {
|
|
1610
1634
|
console.error("Form submission error:", error);
|
|
1611
1635
|
let errorMessage = "Form submission failed. Please try again.";
|