@focus-reactive/payload-plugin-translator 0.5.1 → 0.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.
Files changed (64) hide show
  1. package/README.md +46 -8
  2. package/dist/client/entities/translation/api/mutations/useTranslateField.d.ts +22 -0
  3. package/dist/client/entities/translation/api/mutations/useTranslateField.js +31 -0
  4. package/dist/client/features/collection-translation-form/ui/CollectionTranslationForm.d.ts +3 -3
  5. package/dist/client/features/collection-translation-form/ui/CollectionTranslationForm.js +15 -13
  6. package/dist/client/features/collection-translation-popup/ui/CollectionTranslationPopup.d.ts +2 -2
  7. package/dist/client/features/collection-translation-popup/ui/CollectionTranslationPopup.js +10 -10
  8. package/dist/client/features/open-document-translation-popup/ui/OpenDocumentTranslationPopup.d.ts +1 -1
  9. package/dist/client/features/open-document-translation-popup/ui/OpenDocumentTranslationPopup.js +9 -9
  10. package/dist/client/features/translate-document-form/ui/DocumentTranslationForm.d.ts +2 -2
  11. package/dist/client/features/translate-document-form/ui/DocumentTranslationForm.js +10 -8
  12. package/dist/client/shared/lib/assets/icons/SendIcon.d.ts +1 -0
  13. package/dist/client/shared/lib/assets/icons/SendIcon.js +17 -0
  14. package/dist/client/shared/ui/Button/Button.d.ts +2 -1
  15. package/dist/client/shared/ui/Button/Button.js +1 -1
  16. package/dist/client/shared/ui/Button/styles.module.scss +26 -3
  17. package/dist/client/widgets/translate-field-control/index.d.ts +1 -0
  18. package/dist/client/widgets/translate-field-control/index.js +3 -0
  19. package/dist/client/widgets/translate-field-control/ui/TranslateFieldControl.d.ts +26 -0
  20. package/dist/client/widgets/translate-field-control/ui/TranslateFieldControl.export.d.ts +13 -0
  21. package/dist/client/widgets/translate-field-control/ui/TranslateFieldControl.export.js +14 -0
  22. package/dist/client/widgets/translate-field-control/ui/TranslateFieldControl.js +204 -0
  23. package/dist/client/widgets/translate-field-control/ui/styles.module.scss +48 -0
  24. package/dist/field-actions.d.ts +25 -0
  25. package/dist/field-actions.js +23 -0
  26. package/dist/field-config.d.ts +26 -26
  27. package/dist/field-config.js +14 -37
  28. package/dist/index.d.ts +1 -1
  29. package/dist/index.js +1 -1
  30. package/dist/plugin.d.ts +1 -1
  31. package/dist/plugin.js +3 -1
  32. package/dist/server/features/translate-field/handler.d.ts +17 -0
  33. package/dist/server/features/translate-field/handler.js +85 -0
  34. package/dist/server/features/translate-field/index.d.ts +6 -0
  35. package/dist/server/features/translate-field/index.js +5 -0
  36. package/dist/server/features/translate-field/model.d.ts +62 -0
  37. package/dist/server/features/translate-field/model.js +26 -0
  38. package/dist/server/features/translate-field/resolveFieldSubtree.d.ts +15 -7
  39. package/dist/server/features/translate-field/resolveFieldSubtree.js +14 -8
  40. package/dist/server/features/translate-field/route.d.ts +12 -0
  41. package/dist/server/features/translate-field/route.js +18 -0
  42. package/dist/server/modules/translation-levels/PluginConfigBuilder.d.ts +6 -0
  43. package/dist/server/modules/translation-levels/PluginConfigBuilder.js +4 -0
  44. package/dist/server/modules/translation-levels/fieldLevel.d.ts +23 -0
  45. package/dist/server/modules/translation-levels/fieldLevel.js +37 -0
  46. package/dist/server/modules/translation-levels/index.d.ts +1 -0
  47. package/dist/server/modules/translation-levels/index.js +1 -0
  48. package/dist/server/modules/translation-levels/types.d.ts +6 -1
  49. package/dist/server/modules/translation-levels/types.js +0 -1
  50. package/dist/server/modules/translation-pipeline/stages/data-reconciler/DataReconciler.js +10 -4
  51. package/dist/server/modules/translation-pipeline/stages/data-reconciler/DataReconciler.stage.d.ts +1 -1
  52. package/dist/server/modules/translation-pipeline/stages/data-reconciler/DataReconciler.stage.js +1 -1
  53. package/dist/server/modules/translation-pipeline/stages/field-collector/FieldChunkCollector.d.ts +5 -0
  54. package/dist/server/modules/translation-pipeline/stages/field-collector/FieldChunkCollector.js +13 -4
  55. package/dist/server/modules/translation-providers/OpenAITranslation.provider.d.ts +17 -0
  56. package/dist/server/modules/translation-providers/OpenAITranslation.provider.js +8 -2
  57. package/dist/server/shared/field-config/types.js +1 -1
  58. package/dist/server/shared/field-traversal/findFieldByPath.d.ts +25 -10
  59. package/dist/server/shared/field-traversal/findFieldByPath.js +59 -14
  60. package/dist/server/shared/field-traversal/index.d.ts +1 -1
  61. package/dist/server/shared/field-traversal/index.js +1 -1
  62. package/dist/server/shared/field-traversal/kernel.d.ts +22 -0
  63. package/dist/server/shared/field-traversal/kernel.js +27 -0
  64. package/package.json +2 -2
package/README.md CHANGED
@@ -91,8 +91,9 @@ The `levels` option controls which translation surfaces the plugin exposes. Each
91
91
 
92
92
  - `documentLevel()` — a **Translate** popup on the document edit view (translate one document).
93
93
  - `collectionLevel()` — a **bulk dashboard** on the collection list view (translate many at once).
94
+ - `fieldLevel()` — a synchronous **single-field** endpoint (`POST {basePath}/field`) that translates one field from a chosen source locale, with no persistence. _(Since v0.6.0.)_
94
95
 
95
- Both run through the configured `runner` (async Payload Jobs by default, or synchronous via `createSyncRunner()`) and share the same translation REST API.
96
+ `documentLevel` and `collectionLevel` run through the configured `runner` (async Payload Jobs by default, or synchronous via `createSyncRunner()`) and share the same translation REST API. `fieldLevel` is always synchronous and uses no runner.
96
97
 
97
98
  ```typescript
98
99
  import { translatorPlugin, documentLevel, collectionLevel, createOpenAIProvider, createPayloadJobsRunner } from "@focus-reactive/payload-plugin-translator";
@@ -107,18 +108,55 @@ translatorPlugin({
107
108
  });
108
109
  ```
109
110
 
110
- Omit `levels` for the default `[documentLevel(), collectionLevel()]`, which is identical to the previous behaviour — so adopting this option is non-breaking. A synchronous `fieldLevel()` (in-place field translation) is planned for a later release.
111
+ Omit `levels` for the default `[documentLevel(), collectionLevel()]`, which is identical to the previous behaviour — so adopting this option is non-breaking.
112
+
113
+ #### Field-level translation
114
+
115
+ _Since v0.6.0._
116
+
117
+ `fieldLevel` adds a per-field **Translate** control. Two steps:
118
+
119
+ 1. Add `fieldLevel()` to `levels` (registers the endpoint).
120
+ 2. Wrap the fields that should get a control with `withFieldTranslation(field)`.
121
+
122
+ ```typescript
123
+ import { translatorPlugin, documentLevel, fieldLevel, withFieldTranslation } from "@focus-reactive/payload-plugin-translator";
124
+
125
+ // In a collection:
126
+ const Posts = {
127
+ slug: "posts",
128
+ fields: [withFieldTranslation({ name: "title", type: "text", localized: true })],
129
+ };
130
+
131
+ // In the plugin:
132
+ translatorPlugin({
133
+ collections: [Posts],
134
+ translationProvider: createOpenAIProvider({ apiKey: process.env.OPENAI_API_KEY }),
135
+ runner: createPayloadJobsRunner(),
136
+ levels: [documentLevel(), fieldLevel()],
137
+ });
138
+ ```
139
+
140
+ The control is an icon button (rendered just above the input) that opens a compact popup showing the translation **direction** — a source-locale `Select`, an arrow, then the **current locale** (the fixed target): `en → fr`. You pick the **source** locale; the **target is always the locale you're editing**. The server reads the source locale's _saved_ value and translates it into the current locale, so the control needs a **saved document** (it's disabled on new documents). The source defaults to your Payload `defaultLocale` when that isn't the current locale, otherwise you choose it explicitly.
141
+
142
+ > This is intentionally the reverse of the document/collection level (which translates _from_ the current locale _to_ chosen targets): the field control pulls content _into_ the locale you're standing in.
143
+
144
+ The translated value is written straight back to form state — no save, no queue — and an **Undo** restores the previous value. Wrapping for a control is allowed on **`text`, `textarea`, and `richText`** fields (a compile error on other types — pass `{ exclude: true }` for those). For `richText` the Lexical editor is re-mounted with the translated content. Fields **inside blocks** are supported too: the server reads the source document's `blockType` to resolve the right block schema. Needs a **saved document** (the source value is read from it), so the control is hidden while creating a new document. The endpoint itself (`POST {basePath}/field`) is also usable directly by custom clients.
145
+
146
+ > **Localized `blocks`/`array` containers.** Per-field translation works when the **container is not localized** — the block/array structure is then shared across locales and only the leaf values differ per locale (wrap the leaves, not the container). If a `blocks`/`array` field is itself `localized`, each locale has an independent structure (different order/content), so a field inside it can't be matched to the source locale by position — the control no-ops with a notice asking you to translate the whole document instead. (Whole-document translation handles this case by matching elements by `id`.)
111
147
 
112
148
  ### OpenAIProviderConfig
113
149
 
114
150
  Configuration for `createOpenAIProvider()`.
115
151
 
116
- | Property | Type | Required | Default | Description |
117
- | -------------- | ------------------------- | -------- | --------------- | ------------------------------------------ |
118
- | `apiKey` | `string` | Yes | — | OpenAI API key |
119
- | `model` | `string \| ChatModel` | No | `'gpt-4o'` | OpenAI model to use for translation |
120
- | `systemPrompt` | `SystemPromptBuilder` | No | Built-in prompt | Custom function to build the system prompt |
121
- | `dryRun` | `boolean \| DryRunConfig` | No | `false` | Simulate translations without API calls |
152
+ | Property | Type | Required | Default | Description |
153
+ | -------------- | ------------------------- | -------- | -------------------- | ---------------------------------------------------------------------------------------------------------------------- |
154
+ | `apiKey` | `string` | Yes | — | OpenAI API key |
155
+ | `model` | `string \| ChatModel` | No | `'gpt-4o'` | OpenAI model to use for translation |
156
+ | `systemPrompt` | `SystemPromptBuilder` | No | Built-in prompt | Custom function to build the system prompt |
157
+ | `dryRun` | `boolean \| DryRunConfig` | No | `false` | Simulate translations without API calls |
158
+ | `timeout` | `number` | No | SDK default (10 min) | Per-request timeout in ms. A job blocks on this call, so the 10-min SDK default is usually too long. _(Since v0.6.0.)_ |
159
+ | `maxRetries` | `number` | No | SDK default (2) | Max automatic retries on transient errors (429/5xx/network). `0` disables. _(Since v0.6.0.)_ |
122
160
 
123
161
  ```typescript
124
162
  createOpenAIProvider({
@@ -0,0 +1,22 @@
1
+ import type { FieldTranslationResult } from "../../../../../server/features/translate-field";
2
+ type Variables = {
3
+ collectionSlug: string;
4
+ fieldPath: string;
5
+ targetLng: string;
6
+ /** Source locale to translate from — the server reads its saved value. */
7
+ sourceLng: string;
8
+ /** Saved document id the source value is read from. */
9
+ docId: string | number;
10
+ };
11
+ /**
12
+ * Calls the synchronous field-translation endpoint (POST {basePath}/field).
13
+ * Returns the discriminated result; no cache invalidation — the caller writes
14
+ * the value straight to form state, nothing is persisted.
15
+ *
16
+ * From-locale only: the server reads the field's value from the saved document (`docId`) in
17
+ * `sourceLng` and translates it into the active locale.
18
+ */
19
+ export declare function useTranslateField(): import("@tanstack/react-query").UseMutationResult<{
20
+ data: FieldTranslationResult;
21
+ }, Error, Variables, unknown>;
22
+ export {};
@@ -0,0 +1,31 @@
1
+ import { useMutation } from "@tanstack/react-query";
2
+ import { ofetch } from "ofetch";
3
+ import { useTranslateKitConfig } from "../../../../app/config";
4
+ import { handleNextApiError } from "../../../../shared/lib/errors/handleApiError";
5
+ /**
6
+ * Calls the synchronous field-translation endpoint (POST {basePath}/field).
7
+ * Returns the discriminated result; no cache invalidation — the caller writes
8
+ * the value straight to form state, nothing is persisted.
9
+ *
10
+ * From-locale only: the server reads the field's value from the saved document (`docId`) in
11
+ * `sourceLng` and translates it into the active locale.
12
+ */ export function useTranslateField() {
13
+ const { basePath } = useTranslateKitConfig();
14
+ return useMutation({
15
+ mutationKey: [
16
+ "translate-field"
17
+ ],
18
+ mutationFn: (variables)=>handleNextApiError(()=>ofetch(`/api${basePath}/field`, {
19
+ method: "post",
20
+ body: {
21
+ collection_slug: variables.collectionSlug,
22
+ field_path: variables.fieldPath,
23
+ target_lng: variables.targetLng,
24
+ source_lng: variables.sourceLng,
25
+ doc_id: variables.docId
26
+ }
27
+ }))
28
+ });
29
+ }
30
+
31
+ //# sourceMappingURL=useTranslateField.js.map
@@ -1,10 +1,10 @@
1
- import type { UseFormReturn } from 'react-hook-form';
2
- import type { FormValues } from '../model/schema';
1
+ import type { UseFormReturn } from "react-hook-form";
2
+ import type { FormValues } from "../model/schema";
3
3
  type CollectionTranslationFormProps = {
4
4
  form: UseFormReturn<FormValues>;
5
5
  onSubmit: (values: FormValues) => Promise<void>;
6
6
  selectedCount: number;
7
7
  hasDrafts: boolean;
8
8
  };
9
- export declare function CollectionTranslationForm({ form, onSubmit, selectedCount, hasDrafts, }: CollectionTranslationFormProps): import("react/jsx-runtime").JSX.Element;
9
+ export declare function CollectionTranslationForm({ form, onSubmit, selectedCount, hasDrafts }: CollectionTranslationFormProps): import("react/jsx-runtime").JSX.Element;
10
10
  export {};
@@ -1,11 +1,12 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { FormProvider } from 'react-hook-form';
3
- import Button from '../../../shared/ui/Button';
4
- import FormSelectLocale from '../../../shared/ui/form/FormSelectLocale';
5
- import { FormSelectStrategy } from '../../../shared/ui/form/FormSelectStrategy';
6
- import { FormCheckboxPublish } from '../../../shared/ui/form/FormCheckboxPublish';
7
- import { FORM_FIELDS } from '../model/constants';
8
- import styles from './styles.module.scss';
2
+ import { FormProvider } from "react-hook-form";
3
+ import { SendIcon } from "../../../shared/lib/assets/icons/SendIcon";
4
+ import Button from "../../../shared/ui/Button";
5
+ import FormSelectLocale from "../../../shared/ui/form/FormSelectLocale";
6
+ import { FormSelectStrategy } from "../../../shared/ui/form/FormSelectStrategy";
7
+ import { FormCheckboxPublish } from "../../../shared/ui/form/FormCheckboxPublish";
8
+ import { FORM_FIELDS } from "../model/constants";
9
+ import styles from "./styles.module.scss";
9
10
  export function CollectionTranslationForm({ form, onSubmit, selectedCount, hasDrafts }) {
10
11
  return /*#__PURE__*/ _jsx(FormProvider, {
11
12
  ...form,
@@ -16,24 +17,24 @@ export function CollectionTranslationForm({ form, onSubmit, selectedCount, hasDr
16
17
  className: styles.row,
17
18
  children: [
18
19
  /*#__PURE__*/ _jsxs("div", {
19
- className: styles['locale-group'],
20
+ className: styles["locale-group"],
20
21
  children: [
21
22
  /*#__PURE__*/ _jsx(FormSelectLocale, {
22
23
  label: "From",
23
- className: styles['select-locale-field'],
24
+ className: styles["select-locale-field"],
24
25
  size: "md",
25
26
  name: FORM_FIELDS.SOURCE_LNG
26
27
  }),
27
28
  /*#__PURE__*/ _jsx(FormSelectLocale, {
28
29
  label: "To",
29
- className: styles['select-locale-field'],
30
+ className: styles["select-locale-field"],
30
31
  size: "md",
31
32
  name: FORM_FIELDS.TARGET_LNG
32
33
  })
33
34
  ]
34
35
  }),
35
36
  /*#__PURE__*/ _jsx(FormSelectStrategy, {
36
- className: styles['strategy-field'],
37
+ className: styles["strategy-field"],
37
38
  name: FORM_FIELDS.STRATEGY,
38
39
  size: "md"
39
40
  })
@@ -49,12 +50,13 @@ export function CollectionTranslationForm({ form, onSubmit, selectedCount, hasDr
49
50
  /*#__PURE__*/ _jsx(Button, {
50
51
  $variant: "filled",
51
52
  disabled: form.formState.isSubmitting || selectedCount === 0,
52
- className: styles['submit-button'],
53
+ className: styles["submit-button"],
53
54
  onClick: form.handleSubmit(onSubmit),
54
55
  type: "submit",
55
56
  $size: "md",
56
57
  $isLoading: form.formState.isSubmitting,
57
- children: selectedCount ? `Queue ${selectedCount} translations` : 'Queue translations'
58
+ $startContent: /*#__PURE__*/ _jsx(SendIcon, {}),
59
+ children: selectedCount ? `Queue ${selectedCount} translations` : "Queue translations"
58
60
  })
59
61
  ]
60
62
  })
@@ -1,7 +1,7 @@
1
- import type { PropsWithChildren } from 'react';
1
+ import type { PropsWithChildren } from "react";
2
2
  type CollectionTranslationPopupProps = PropsWithChildren<{
3
3
  translationInProgress: boolean;
4
4
  selectedCount: number;
5
5
  }>;
6
- declare function CollectionTranslationPopup({ children, translationInProgress, selectedCount, }: CollectionTranslationPopupProps): import("react/jsx-runtime").JSX.Element;
6
+ declare function CollectionTranslationPopup({ children, translationInProgress, selectedCount }: CollectionTranslationPopupProps): import("react/jsx-runtime").JSX.Element;
7
7
  export default CollectionTranslationPopup;
@@ -1,11 +1,11 @@
1
- 'use client';
1
+ "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
- import { LanguageTranslateIcon } from '../../../shared/lib/assets/icons/LanguageTranslateIcon';
4
- import { useToggle } from '../../../shared/lib/utils/react/useToggle';
5
- import Button from '../../../shared/ui/Button';
6
- import ColorIndicator from '../../../shared/ui/ColorIndicator';
7
- import Popup from '../../../shared/ui/Popup';
8
- import styles from './styles.module.scss';
3
+ import { LanguageTranslateIcon } from "../../../shared/lib/assets/icons/LanguageTranslateIcon";
4
+ import { useToggle } from "../../../shared/lib/utils/react/useToggle";
5
+ import Button from "../../../shared/ui/Button";
6
+ import ColorIndicator from "../../../shared/ui/ColorIndicator";
7
+ import Popup from "../../../shared/ui/Popup";
8
+ import styles from "./styles.module.scss";
9
9
  function CollectionTranslationPopup({ children, translationInProgress, selectedCount }) {
10
10
  const [isPopupOpen, popupOpen] = useToggle();
11
11
  return /*#__PURE__*/ _jsx(Popup, {
@@ -13,8 +13,8 @@ function CollectionTranslationPopup({ children, translationInProgress, selectedC
13
13
  onOpenChange: popupOpen.setValue,
14
14
  $trigger: /*#__PURE__*/ _jsxs(Button, {
15
15
  $size: "md",
16
- $variant: "filled",
17
- className: styles['popup-trigger-button'],
16
+ $variant: "outlined-light",
17
+ className: styles["popup-trigger-button"],
18
18
  "aria-label": "Open translation options",
19
19
  onClick: popupOpen.setTrue,
20
20
  children: [
@@ -38,7 +38,7 @@ function CollectionTranslationPopup({ children, translationInProgress, selectedC
38
38
  }),
39
39
  open: isPopupOpen,
40
40
  children: /*#__PURE__*/ _jsx("div", {
41
- className: styles['popup-content'],
41
+ className: styles["popup-content"],
42
42
  children: children
43
43
  })
44
44
  });
@@ -1,4 +1,4 @@
1
- import type { ReactNode } from 'react';
1
+ import type { ReactNode } from "react";
2
2
  type OpenDocumentTranslationPopupProps = {
3
3
  isLoading?: boolean;
4
4
  children: (props: {
@@ -1,10 +1,10 @@
1
- 'use client';
1
+ "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { LanguageTranslateIcon } from '../../../shared/lib/assets/icons/LanguageTranslateIcon';
4
- import { useToggle } from '../../../shared/lib/utils/react/useToggle';
5
- import Button from '../../../shared/ui/Button';
6
- import Popup from '../../../shared/ui/Popup';
7
- import styles from './styles.module.scss';
3
+ import { LanguageTranslateIcon } from "../../../shared/lib/assets/icons/LanguageTranslateIcon";
4
+ import { useToggle } from "../../../shared/lib/utils/react/useToggle";
5
+ import Button from "../../../shared/ui/Button";
6
+ import Popup from "../../../shared/ui/Popup";
7
+ import styles from "./styles.module.scss";
8
8
  function OpenDocumentTranslationPopup({ children, isLoading }) {
9
9
  const [isPopupOpen, popupOpen] = useToggle();
10
10
  return /*#__PURE__*/ _jsx(Popup, {
@@ -12,9 +12,9 @@ function OpenDocumentTranslationPopup({ children, isLoading }) {
12
12
  onOpenChange: popupOpen.setValue,
13
13
  $trigger: /*#__PURE__*/ _jsx(Button, {
14
14
  $size: "md",
15
- $variant: "filled",
15
+ $variant: "outlined-light",
16
16
  $isIconButton: true,
17
- className: styles['popup-trigger-button'],
17
+ className: styles["popup-trigger-button"],
18
18
  "aria-label": "Open translation options",
19
19
  onClick: popupOpen.setTrue,
20
20
  disabled: isLoading,
@@ -23,7 +23,7 @@ function OpenDocumentTranslationPopup({ children, isLoading }) {
23
23
  }),
24
24
  open: isPopupOpen,
25
25
  children: /*#__PURE__*/ _jsx("div", {
26
- className: styles['popup-content'],
26
+ className: styles["popup-content"],
27
27
  children: children({
28
28
  close: popupOpen.setFalse
29
29
  })
@@ -1,5 +1,5 @@
1
- import type { UseFormReturn } from 'react-hook-form';
2
- import type { FormValues } from '../model/schema';
1
+ import type { UseFormReturn } from "react-hook-form";
2
+ import type { FormValues } from "../model/schema";
3
3
  type DocumentTranslationFormProps = {
4
4
  form: UseFormReturn<FormValues>;
5
5
  onSubmit: (values: FormValues) => Promise<void>;
@@ -1,11 +1,12 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { FormProvider } from 'react-hook-form';
3
- import Button from '../../../shared/ui/Button';
4
- import FormSelectLocale from '../../../shared/ui/form/FormSelectLocale';
5
- import { FormSelectStrategy } from '../../../shared/ui/form/FormSelectStrategy';
6
- import { FormCheckboxPublish } from '../../../shared/ui/form/FormCheckboxPublish';
7
- import { FORM_FIELDS } from '../model/constants';
8
- import styles from './styles.module.scss';
2
+ import { FormProvider } from "react-hook-form";
3
+ import { SendIcon } from "../../../shared/lib/assets/icons/SendIcon";
4
+ import Button from "../../../shared/ui/Button";
5
+ import FormSelectLocale from "../../../shared/ui/form/FormSelectLocale";
6
+ import { FormSelectStrategy } from "../../../shared/ui/form/FormSelectStrategy";
7
+ import { FormCheckboxPublish } from "../../../shared/ui/form/FormCheckboxPublish";
8
+ import { FORM_FIELDS } from "../model/constants";
9
+ import styles from "./styles.module.scss";
9
10
  export function DocumentTranslationForm({ form, onSubmit, hasDrafts }) {
10
11
  return /*#__PURE__*/ _jsx(FormProvider, {
11
12
  ...form,
@@ -42,11 +43,12 @@ export function DocumentTranslationForm({ form, onSubmit, hasDrafts }) {
42
43
  /*#__PURE__*/ _jsx(Button, {
43
44
  $variant: "filled",
44
45
  disabled: form.formState.isSubmitting,
45
- className: styles['submit-button'],
46
+ className: styles["submit-button"],
46
47
  onClick: form.handleSubmit(onSubmit),
47
48
  type: "submit",
48
49
  $size: "lg",
49
50
  $isLoading: form.formState.isSubmitting,
51
+ $startContent: /*#__PURE__*/ _jsx(SendIcon, {}),
50
52
  children: "Queue Translation"
51
53
  })
52
54
  ]
@@ -0,0 +1 @@
1
+ export declare const SendIcon: () => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export const SendIcon = ()=>/*#__PURE__*/ _jsx("svg", {
3
+ width: "1em",
4
+ height: "1em",
5
+ viewBox: "0 0 24 24",
6
+ fill: "none",
7
+ xmlns: "http://www.w3.org/2000/svg",
8
+ children: /*#__PURE__*/ _jsx("path", {
9
+ d: "M10.3009 13.6949L20.102 3.89742M10.5795 14.1355L12.8019 18.5804C13.339 19.6545 13.6075 20.1916 13.9458 20.3356C14.2394 20.4606 14.575 20.4379 14.8492 20.2747C15.1651 20.0866 15.3591 19.5183 15.7472 18.3818L19.9463 6.08434C20.2845 5.09409 20.4535 4.59896 20.3378 4.27142C20.2371 3.98648 20.013 3.76234 19.7281 3.66167C19.4005 3.54595 18.9054 3.71502 17.9151 4.05315L5.61763 8.2523C4.48114 8.64037 3.91289 8.83441 3.72478 9.15032C3.56153 9.42447 3.53891 9.76007 3.66389 10.0536C3.80791 10.3919 4.34498 10.6605 5.41912 11.1975L9.86397 13.42C10.041 13.5085 10.1295 13.5527 10.2061 13.6118C10.2742 13.6643 10.3352 13.7253 10.3876 13.7933C10.4468 13.87 10.491 13.9585 10.5795 14.1355Z",
10
+ stroke: "currentColor",
11
+ strokeWidth: "2",
12
+ strokeLinecap: "round",
13
+ strokeLinejoin: "round"
14
+ })
15
+ });
16
+
17
+ //# sourceMappingURL=SendIcon.js.map
@@ -1,7 +1,8 @@
1
1
  import type { ComponentPropsWithRef, ReactNode } from "react";
2
2
  type ButtonProps = ComponentPropsWithRef<"button"> & {
3
3
  $fullWidth?: boolean;
4
- $variant?: "outlined" | "filled" | "unstyled" | "transparent" | "light";
4
+ $variant?: "outlined" | "outlined-light" | "filled" | "unstyled" | "transparent" | "light";
5
+ /** Leading content (e.g. an icon) before children. Hidden while `$isLoading` — the spinner replaces it. */
5
6
  $startContent?: ReactNode;
6
7
  $size?: "sm" | "md" | "lg";
7
8
  $isLoading?: boolean;
@@ -32,7 +32,7 @@ const Button = /*#__PURE__*/ forwardRef(function Button({ className = "", childr
32
32
  ref: ref,
33
33
  className: buttonClassName,
34
34
  children: [
35
- $startContent && /*#__PURE__*/ _jsx("div", {
35
+ !$isLoading && $startContent && /*#__PURE__*/ _jsx("div", {
36
36
  className: styles["start-content"],
37
37
  children: $startContent
38
38
  }),
@@ -26,18 +26,41 @@
26
26
  margin-right: calc(var(--base) / 2);
27
27
  }
28
28
 
29
+ /* Mirrors Payload's `.btn--style-secondary` (@payloadcms/ui Button): transparent fill, a
30
+ theme-elevation-800 border (faint + low-contrast in the dark admin theme), text in theme-text. */
29
31
  .outlined {
32
+ color: var(--theme-text);
33
+ border: 1px solid var(--theme-elevation-800);
34
+
35
+ &:hover:not(:disabled),
36
+ &:focus {
37
+ color: var(--theme-elevation-600);
38
+ border-color: var(--theme-elevation-400);
39
+ }
40
+
41
+ &:disabled {
42
+ cursor: not-allowed;
43
+ color: var(--theme-elevation-200);
44
+ border-color: var(--theme-elevation-200);
45
+ }
46
+ }
47
+
48
+ /* A muted outlined: transparent fill + a faint elev-200 border (Payload's subtle/dashed border
49
+ weight) instead of secondary's strong elev-800. For low-emphasis triggers that should sit
50
+ quietly next to other plugins' admin buttons. */
51
+ .outlined-light {
52
+ color: var(--theme-text);
30
53
  border: 1px solid var(--theme-elevation-200);
31
54
 
32
55
  &:hover:not(:disabled),
33
56
  &:focus {
34
- border-color: var(--theme-elevation-100);
57
+ border-color: var(--theme-elevation-300);
35
58
  }
36
59
 
37
60
  &:disabled {
38
61
  cursor: not-allowed;
39
- background-color: var(--theme-elevation-200);
40
- color: var(--theme-elevation-800);
62
+ color: var(--theme-elevation-200);
63
+ border-color: var(--theme-elevation-150);
41
64
  }
42
65
  }
43
66
 
@@ -0,0 +1 @@
1
+ export { TranslateFieldControlExport } from "./ui/TranslateFieldControl.export";
@@ -0,0 +1,3 @@
1
+ export { TranslateFieldControlExport } from "./ui/TranslateFieldControl.export";
2
+
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Per-field Translate control, injected into the field's `admin.components.beforeInput`.
3
+ * The trigger is an icon button; clicking it opens a compact popup that reuses the plugin's
4
+ * recognizable `source → target` direction pattern (as on the document/collection level):
5
+ * a small **source** locale `Select`, an arrow, then the **current** locale (the target).
6
+ *
7
+ * **Direction.** The target is *always* the locale the user is editing (`useLocale()`) — never
8
+ * derived from the picker; only the **source** is chosen. This is the reverse of the
9
+ * document/collection level (translate *from* the current locale *to* a chosen target): here we
10
+ * pull content *into* where the user stands. Deliberate, and field-level only for now.
11
+ *
12
+ * The source is an explicit locale (no "auto-detect": the field reads the chosen locale's *saved*
13
+ * value, so it needs a saved document — the control is **hidden entirely while creating** a new
14
+ * one). It defaults to Payload's configured `defaultLocale` when
15
+ * that isn't the current locale, otherwise the user picks. On success the result is written back
16
+ * (see {@link writeFieldValue}) and an **Undo** restores the previous value. Field `value` + `path`
17
+ * come from `useField()` via the field path context (`beforeInput` renders inside it — no `path`
18
+ * prop).
19
+ *
20
+ * **Write-back** is one path for every supported field type: a form `UPDATE` bumping both `value`
21
+ * and `initialValue`. A Lexical (`richText`) editor owns its state and only re-reads on
22
+ * `initialValue` change, so it re-mounts with the new content; `text` / `textarea` inputs just
23
+ * re-render from `value`. So no per-type flag is needed.
24
+ */
25
+ declare const TranslateFieldControl: () => import("react/jsx-runtime").JSX.Element | null;
26
+ export default TranslateFieldControl;
@@ -0,0 +1,13 @@
1
+ import type { RawPayloadComponentExport } from "../../../shared/types/PayloadComponentExport";
2
+ /**
3
+ * Import-map reference to the per-field Translate control. Appended to a field's
4
+ * `admin.components.beforeInput` by `withFieldTranslation(field)`, so it renders just above the
5
+ * input as an icon button that opens the translate popup.
6
+ *
7
+ * No props: the control reads everything from client context (field value/path via `useField()`,
8
+ * locale via `useLocale`, document via `useDocumentInfo`, available locales via `useConfig`) and
9
+ * writes back uniformly via a form `UPDATE` (works for text/textarea and richText alike).
10
+ */
11
+ export declare class TranslateFieldControlExport implements RawPayloadComponentExport {
12
+ path: string;
13
+ }
@@ -0,0 +1,14 @@
1
+ import { clientComponentPath } from "../../../shared/utils/componentPath";
2
+ /**
3
+ * Import-map reference to the per-field Translate control. Appended to a field's
4
+ * `admin.components.beforeInput` by `withFieldTranslation(field)`, so it renders just above the
5
+ * input as an icon button that opens the translate popup.
6
+ *
7
+ * No props: the control reads everything from client context (field value/path via `useField()`,
8
+ * locale via `useLocale`, document via `useDocumentInfo`, available locales via `useConfig`) and
9
+ * writes back uniformly via a form `UPDATE` (works for text/textarea and richText alike).
10
+ */ export class TranslateFieldControlExport {
11
+ path = clientComponentPath("widgets/translate-field-control/ui/TranslateFieldControl");
12
+ }
13
+
14
+ //# sourceMappingURL=TranslateFieldControl.export.js.map