@focus-reactive/payload-plugin-translator 0.1.6 → 0.2.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/client/features/collection-translation-form/model/form-model.d.ts +2 -2
- package/dist/client/features/collection-translation-form/model/form-model.js +13 -10
- package/dist/client/features/translate-document-form/model/form-model.d.ts +2 -2
- package/dist/client/features/translate-document-form/model/form-model.js +13 -10
- package/package.json +5 -10
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { UseFormReturn } from
|
|
2
|
-
import type { FormInput, FormValues } from
|
|
1
|
+
import type { UseFormReturn } from "react-hook-form";
|
|
2
|
+
import type { FormInput, FormValues } from "./schema";
|
|
3
3
|
type UseFormReturn_ = {
|
|
4
4
|
form: UseFormReturn<FormValues>;
|
|
5
5
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import { zodResolver } from
|
|
3
|
-
import { useEffect, useMemo } from
|
|
4
|
-
import { useForm } from
|
|
5
|
-
import { defaultValues } from
|
|
6
|
-
import { validationSchema } from
|
|
1
|
+
"use client";
|
|
2
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
3
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
4
|
+
import { useForm } from "react-hook-form";
|
|
5
|
+
import { defaultValues } from "./constants";
|
|
6
|
+
import { validationSchema } from "./schema";
|
|
7
7
|
export const useCollectionTranslationForm = ({ initialValues, disabled } = {})=>{
|
|
8
8
|
const defaultFormValues = useMemo(()=>({
|
|
9
9
|
...defaultValues,
|
|
@@ -14,15 +14,18 @@ export const useCollectionTranslationForm = ({ initialValues, disabled } = {})=>
|
|
|
14
14
|
const form = useForm({
|
|
15
15
|
defaultValues: defaultFormValues,
|
|
16
16
|
resolver: zodResolver(validationSchema),
|
|
17
|
-
mode:
|
|
17
|
+
mode: "onTouched",
|
|
18
18
|
disabled
|
|
19
19
|
});
|
|
20
|
+
const isFirstRender = useRef(true);
|
|
20
21
|
useEffect(()=>{
|
|
22
|
+
if (isFirstRender.current) {
|
|
23
|
+
isFirstRender.current = false;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
21
26
|
form.reset(defaultFormValues);
|
|
22
27
|
}, [
|
|
23
|
-
defaultFormValues
|
|
24
|
-
form,
|
|
25
|
-
form.reset
|
|
28
|
+
defaultFormValues
|
|
26
29
|
]);
|
|
27
30
|
return {
|
|
28
31
|
form
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { UseFormReturn } from
|
|
2
|
-
import type { FormInput, FormValues } from
|
|
1
|
+
import type { UseFormReturn } from "react-hook-form";
|
|
2
|
+
import type { FormInput, FormValues } from "./schema";
|
|
3
3
|
type UseFormReturn_ = {
|
|
4
4
|
form: UseFormReturn<FormValues>;
|
|
5
5
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import { zodResolver } from
|
|
3
|
-
import { useEffect, useMemo } from
|
|
4
|
-
import { useForm } from
|
|
5
|
-
import { defaultValues } from
|
|
6
|
-
import { validationSchema } from
|
|
1
|
+
"use client";
|
|
2
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
3
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
4
|
+
import { useForm } from "react-hook-form";
|
|
5
|
+
import { defaultValues } from "./constants";
|
|
6
|
+
import { validationSchema } from "./schema";
|
|
7
7
|
export const useTranslateDocumentForm = ({ initialValues, disabled } = {})=>{
|
|
8
8
|
const defaultFormValues = useMemo(()=>({
|
|
9
9
|
...defaultValues,
|
|
@@ -14,15 +14,18 @@ export const useTranslateDocumentForm = ({ initialValues, disabled } = {})=>{
|
|
|
14
14
|
const form = useForm({
|
|
15
15
|
defaultValues: defaultFormValues,
|
|
16
16
|
resolver: zodResolver(validationSchema),
|
|
17
|
-
mode:
|
|
17
|
+
mode: "onTouched",
|
|
18
18
|
disabled
|
|
19
19
|
});
|
|
20
|
+
const isFirstRender = useRef(true);
|
|
20
21
|
useEffect(()=>{
|
|
22
|
+
if (isFirstRender.current) {
|
|
23
|
+
isFirstRender.current = false;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
21
26
|
form.reset(defaultFormValues);
|
|
22
27
|
}, [
|
|
23
|
-
defaultFormValues
|
|
24
|
-
form,
|
|
25
|
-
form.reset
|
|
28
|
+
defaultFormValues
|
|
26
29
|
]);
|
|
27
30
|
return {
|
|
28
31
|
form
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@focus-reactive/payload-plugin-translator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Translation plugin for Payload CMS 3.x. Automatically translate your localized content using any translation provider.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,15 +47,15 @@
|
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "bun run clean && bun run build:swc && bun run build:types && bun run copyfiles",
|
|
49
49
|
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths --ignore '**/*.test.ts' --ignore '**/*.d.ts' --ignore '**/__tests__/**' --ignore '**/__mocks__/**'",
|
|
50
|
-
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
50
|
+
"build:types": "tsc --emitDeclarationOnly --declaration --outDir dist",
|
|
51
51
|
"copyfiles": "copyfiles -u 1 \"src/**/*.scss\" dist",
|
|
52
52
|
"clean": "rm -rf dist",
|
|
53
53
|
"dev": "bun run build:swc -- --watch",
|
|
54
|
-
"lint": "
|
|
55
|
-
"lint:fix": "
|
|
54
|
+
"lint": "ultracite check",
|
|
55
|
+
"lint:fix": "ultracite fix",
|
|
56
56
|
"test": "vitest run",
|
|
57
57
|
"test:watch": "vitest",
|
|
58
|
-
"check-types": "
|
|
58
|
+
"check-types": "tsgo --noEmit"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@payloadcms/richtext-lexical": "^3.76.0",
|
|
@@ -84,14 +84,9 @@
|
|
|
84
84
|
"@types/react": "19.2.9",
|
|
85
85
|
"@vitest/coverage-v8": "3.2.4",
|
|
86
86
|
"copyfiles": "2.4.1",
|
|
87
|
-
"eslint": "9.0.0",
|
|
88
|
-
"eslint-config-prettier": "9.0.0",
|
|
89
|
-
"next": "15.4.11",
|
|
90
87
|
"payload": "3.79.0",
|
|
91
88
|
"react": "19.0.0",
|
|
92
89
|
"typescript": "5.5.2",
|
|
93
|
-
"eslint-plugin-react-hooks": "6.0.0-rc.2",
|
|
94
|
-
"typescript-eslint": "8.0.0",
|
|
95
90
|
"vitest": "3.2.4"
|
|
96
91
|
}
|
|
97
92
|
}
|