@aatulwork/customform-renderer 1.4.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/README.md +22 -0
- package/dist/index.js +22 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +23 -3
- package/dist/index.mjs.map +1 -1
- package/dist/vite-plugin.js +50 -0
- package/dist/vite-plugin.js.map +1 -0
- package/dist/vite-plugin.mjs +45 -0
- package/dist/vite-plugin.mjs.map +1 -0
- package/package.json +22 -4
package/README.md
CHANGED
|
@@ -52,6 +52,27 @@ const { isReady } = useCKEditor({ autoLoad: true });
|
|
|
52
52
|
|
|
53
53
|
See [CKEditor Setup Guide](#ckeditor-setup) for more details.
|
|
54
54
|
|
|
55
|
+
### Using with Vite
|
|
56
|
+
|
|
57
|
+
**You do not need any Vite config** to use this package. The package ships correct `module` and `exports` so Vite resolves it without aliases.
|
|
58
|
+
|
|
59
|
+
- **Dependencies:** The package installs `@emotion/react`, `@emotion/styled`, and `@mui/system`; you only need to install the [peer dependencies](#peer-dependencies) (React, MUI, react-hook-form, etc.).
|
|
60
|
+
|
|
61
|
+
If you use **SSR** or see module resolution / pre-bundling issues, add the optional plugin (one line):
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
// vite.config.ts
|
|
65
|
+
import { defineConfig } from 'vite';
|
|
66
|
+
import react from '@vitejs/plugin-react';
|
|
67
|
+
import { customformRendererVite } from '@aatulwork/customform-renderer/vite';
|
|
68
|
+
|
|
69
|
+
export default defineConfig({
|
|
70
|
+
plugins: [react(), customformRendererVite()],
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The plugin applies `optimizeDeps.include`, `ssr.noExternal`, and excludes the package’s CKEditor script from pre-bundling. You can pass options: `customformRendererVite({ excludeCkeditorFromOptimize: false })` if you load CKEditor only via a script tag.
|
|
75
|
+
|
|
55
76
|
## Package Exports
|
|
56
77
|
|
|
57
78
|
The package exports the following:
|
|
@@ -63,6 +84,7 @@ The package exports the following:
|
|
|
63
84
|
- **Utils:** `getAllFields`, `normalizeInitialValues`, `transformFormValues`, `getDefaultValue`, `formatFileSize`, `validateFile`, `buildFieldRules`, `normalizeOptions`
|
|
64
85
|
- **CKEditor:** `loadCKEditor`, `isCKEditorAvailable`, `waitForCKEditor`, `useCKEditor`
|
|
65
86
|
- **Default services:** `defaultFileUploadService`, `defaultFormReferenceService`, `defaultApiReferenceService`, `defaultDateFormatterService` (throw if used without override; provide your own via `services`)
|
|
87
|
+
- **Vite:** `customformRendererVite` from `@aatulwork/customform-renderer/vite` (optional plugin for SSR / optimizeDeps)
|
|
66
88
|
|
|
67
89
|
## Quick Start
|
|
68
90
|
|
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: () => {
|
|
@@ -1603,8 +1622,9 @@ var FormRenderer = ({
|
|
|
1603
1622
|
try {
|
|
1604
1623
|
await onSubmit(transformedData);
|
|
1605
1624
|
if (onSuccess) {
|
|
1606
|
-
reset(initialValues || {});
|
|
1607
1625
|
onSuccess();
|
|
1626
|
+
clearErrors();
|
|
1627
|
+
reset(initialValues || {}, { keepErrors: false });
|
|
1608
1628
|
}
|
|
1609
1629
|
} catch (error) {
|
|
1610
1630
|
console.error("Form submission error:", error);
|