@aatulwork/customform-renderer 1.5.0 → 1.6.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.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { useMemo, useState, useEffect, useRef, useCallback } from 'react';
2
- import { Controller, useForm } from 'react-hook-form';
2
+ import { Controller, useWatch, useForm } from 'react-hook-form';
3
3
  import { FormControl, FormLabel, TextField as TextField$1, InputLabel, Select, MenuItem, Box, Chip, CircularProgress, OutlinedInput, FormHelperText, FormControlLabel, Checkbox, RadioGroup, Radio, Typography, Switch, Input, useTheme, alpha, useMediaQuery, Tooltip, IconButton, Accordion, AccordionSummary, AccordionDetails, Alert, Stepper, Step, StepLabel, Button, Stack } from '@mui/material';
4
4
  import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
5
5
  import DoubleArrowOutlinedIcon from '@mui/icons-material/DoubleArrowOutlined';
@@ -646,14 +646,31 @@ var CKEditorField = ({ field, control, defaultValue, rules, errors, setValue, fo
646
646
  const theme = useTheme();
647
647
  const formColors = useFormColors(colors);
648
648
  const editorContainerRef = useRef(null);
649
+ const editorInstanceRef = useRef(null);
650
+ const isUserTypingRef = useRef(false);
649
651
  const fileUploadService = services?.fileUpload || defaultFileUploadService;
650
652
  const fileBaseUrl = services?.fileBaseUrl || "";
651
- const licenseKey = services?.ckEditorLicenseKey || "";
653
+ const licenseKey = services?.ckEditorLicenseKey || "GPL";
652
654
  const ckEditorScriptPath = services?.ckEditorScriptPath || "/lib/ckeditor/ckeditor.js";
653
655
  const { isReady: isCKEditorReady, isLoading: isCKEditorLoading, error: ckEditorError } = useCKEditor({
654
656
  scriptPath: ckEditorScriptPath,
655
657
  autoLoad: true
656
658
  });
659
+ const watchedValue = useWatch({
660
+ control,
661
+ name: field.name,
662
+ defaultValue: defaultValue || ""
663
+ });
664
+ useEffect(() => {
665
+ if (editorInstanceRef.current && isCKEditorReady && !isUserTypingRef.current) {
666
+ const currentEditorData = editorInstanceRef.current.getData();
667
+ const formValue = watchedValue || "";
668
+ if (currentEditorData !== formValue) {
669
+ editorInstanceRef.current.setData(formValue);
670
+ }
671
+ }
672
+ isUserTypingRef.current = false;
673
+ }, [watchedValue, isCKEditorReady]);
657
674
  const createCustomUploadAdapter = useCallback((loader) => {
658
675
  return {
659
676
  upload: async () => {
@@ -767,6 +784,7 @@ var CKEditorField = ({ field, control, defaultValue, rules, errors, setValue, fo
767
784
  },
768
785
  data: formField.value || "",
769
786
  onReady: (editor) => {
787
+ editorInstanceRef.current = editor;
770
788
  if (formSchema?.name) {
771
789
  try {
772
790
  const fileRepository = editor.plugins.get("FileRepository");
@@ -790,6 +808,7 @@ var CKEditorField = ({ field, control, defaultValue, rules, errors, setValue, fo
790
808
  },
791
809
  onChange: (_event, editor) => {
792
810
  const data = editor.getData();
811
+ isUserTypingRef.current = true;
793
812
  formField.onChange(data);
794
813
  },
795
814
  onBlur: () => {
@@ -1590,8 +1609,9 @@ var FormRenderer = ({
1590
1609
  try {
1591
1610
  await onSubmit(transformedData);
1592
1611
  if (onSuccess) {
1593
- reset(initialValues || {});
1594
1612
  onSuccess();
1613
+ clearErrors();
1614
+ reset(initialValues || {}, { keepErrors: false });
1595
1615
  }
1596
1616
  } catch (error) {
1597
1617
  console.error("Form submission error:", error);