payload-intl 1.2.5 → 1.3.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 +4 -8
- package/dist/components/MessageFormField.d.ts +1 -2
- package/dist/components/MessageFormField.d.ts.map +1 -1
- package/dist/components/MessageFormField.js +1 -2
- package/dist/components/MessageFormField.js.map +1 -1
- package/dist/components/MessagesLink.js +1 -1
- package/dist/components/MessagesLink.js.map +1 -1
- package/dist/components/MessagesView.js +1 -1
- package/dist/components/MessagesView.js.map +1 -1
- package/dist/components/inputs/FieldWrapper.d.ts +1 -2
- package/dist/components/inputs/FieldWrapper.d.ts.map +1 -1
- package/dist/components/inputs/FieldWrapper.js +1 -1
- package/dist/components/inputs/FieldWrapper.js.map +1 -1
- package/dist/components/inputs/LexicalInput.d.ts +1 -1
- package/dist/components/inputs/LexicalInput.d.ts.map +1 -1
- package/dist/components/inputs/LexicalInput.js +1 -2
- package/dist/components/inputs/LexicalInput.js.map +1 -1
- package/dist/components/inputs/MessageInput.d.ts +1 -1
- package/dist/components/inputs/MessageInput.d.ts.map +1 -1
- package/dist/components/inputs/MessageInput.js +1 -2
- package/dist/components/inputs/MessageInput.js.map +1 -1
- package/dist/const.d.ts +13 -5
- package/dist/const.d.ts.map +1 -1
- package/dist/const.js +9 -9
- package/dist/const.js.map +1 -1
- package/dist/endpoints/set-messages.d.ts.map +1 -1
- package/dist/endpoints/set-messages.js +73 -31
- package/dist/endpoints/set-messages.js.map +1 -1
- package/dist/entities.d.ts +1 -1
- package/dist/entities.d.ts.map +1 -1
- package/dist/entities.js +13 -9
- package/dist/entities.js.map +1 -1
- package/dist/index.d.ts +13 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -25
- package/dist/index.js.map +1 -1
- package/dist/payload-types.d.ts +4 -0
- package/dist/payload-types.d.ts.map +1 -1
- package/dist/requests/fetchMessages.d.ts +1 -4
- package/dist/requests/fetchMessages.d.ts.map +1 -1
- package/dist/requests/fetchMessages.js +36 -7
- package/dist/requests/fetchMessages.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/config.d.ts +1 -9
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +0 -10
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/guards.d.ts +0 -1
- package/dist/utils/guards.d.ts.map +1 -1
- package/dist/utils/guards.js +0 -3
- package/dist/utils/guards.js.map +1 -1
- package/dist/utils/icu-tranform.d.ts.map +1 -1
- package/dist/utils/icu-tranform.js +1 -1
- package/dist/utils/icu-tranform.js.map +1 -1
- package/package.json +9 -8
- package/dist/endpoints/get-messages.d.ts +0 -3
- package/dist/endpoints/get-messages.d.ts.map +0 -1
- package/dist/endpoints/get-messages.js +0 -7
- package/dist/endpoints/get-messages.js.map +0 -1
- package/dist/internals/index.d.ts +0 -30
- package/dist/internals/index.d.ts.map +0 -1
- package/dist/internals/index.js +0 -81
- package/dist/internals/index.js.map +0 -1
- package/dist/internals/procedure.d.ts +0 -34
- package/dist/internals/procedure.d.ts.map +0 -1
- package/dist/internals/procedure.js +0 -111
- package/dist/internals/procedure.js.map +0 -1
- package/dist/internals/urls.d.ts +0 -11
- package/dist/internals/urls.d.ts.map +0 -1
- package/dist/internals/urls.js +0 -23
- package/dist/internals/urls.js.map +0 -1
- package/dist/internals/utils.d.ts +0 -8
- package/dist/internals/utils.d.ts.map +0 -1
- package/dist/internals/utils.js +0 -57
- package/dist/internals/utils.js.map +0 -1
- package/dist/requests/fetchMessageFromAPI.d.ts +0 -10
- package/dist/requests/fetchMessageFromAPI.d.ts.map +0 -1
- package/dist/requests/fetchMessageFromAPI.js +0 -15
- package/dist/requests/fetchMessageFromAPI.js.map +0 -1
- package/dist/requests/fetchMessageFromPayload.d.ts +0 -3
- package/dist/requests/fetchMessageFromPayload.d.ts.map +0 -1
- package/dist/requests/fetchMessageFromPayload.js +0 -29
- package/dist/requests/fetchMessageFromPayload.js.map +0 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ Define your message keys as a typed schema using ICU MessageFormat syntax, then
|
|
|
15
15
|
- **Schema-driven** — define message keys and templates in a typed schema with automatic validation.
|
|
16
16
|
- **Rich editor UI** — message editor with variable chips, autocompletion, and inline ICU element editors.
|
|
17
17
|
- **JSON import** — bulk-import translations from JSON files directly in the admin UI.
|
|
18
|
-
- **Flexible
|
|
18
|
+
- **Flexible storage** — store translations as JSON in the database (default) or as uploaded files for CDN hosting.
|
|
19
19
|
|
|
20
20
|
## Installation
|
|
21
21
|
|
|
@@ -59,14 +59,7 @@ Fetch messages in your application:
|
|
|
59
59
|
```ts
|
|
60
60
|
import { fetchMessages } from "payload-intl";
|
|
61
61
|
|
|
62
|
-
// Server-side — pass the Payload instance directly
|
|
63
62
|
const messages = await fetchMessages(payload, "en");
|
|
64
|
-
|
|
65
|
-
// Client-side — pass a config object to fetch from the REST API
|
|
66
|
-
const messages = await fetchMessages(
|
|
67
|
-
{ serverUrl: "http://localhost:3000" },
|
|
68
|
-
"en",
|
|
69
|
-
);
|
|
70
63
|
```
|
|
71
64
|
|
|
72
65
|
### Options
|
|
@@ -77,6 +70,9 @@ const messages = await fetchMessages(
|
|
|
77
70
|
| `collectionSlug` | `string` | `'messages'` | Slug of the collection used to store translation files. |
|
|
78
71
|
| `editorAccess` | `(req: PayloadRequest) => boolean \| Promise<boolean>` | `(req) => req.user !== null` | Access control function that determines who can edit messages. |
|
|
79
72
|
| `hooks` | `MessagesHooks` | `{}` | Collection hooks. Extends Payload's collection hooks with an additional `afterUpdate` callback fired when translations are saved. |
|
|
73
|
+
| `storage` | `'db' \| 'upload'` | `'db'` | `'db'` stores translations as JSON in the database. `'upload'` stores them as uploaded `.json` files for CDN/static hosting. |
|
|
74
|
+
|
|
75
|
+
> **Note:** Switching between storage strategies on an existing deployment is not yet supported automatically. When the database schema changes (e.g. dropping upload columns), the migration data is lost before the app can read it. A safe migration path will be provided in a future release. For now, export your translations before switching strategies.
|
|
80
76
|
| `tabs` | `boolean` | `false` | When enabled, top-level keys in the schema are rendered as tabs in the admin UI. |
|
|
81
77
|
|
|
82
78
|
## Contributing
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Locale, TemplateVariable } from '../types';
|
|
2
2
|
import type { MessageValidator } from '../utils/validate';
|
|
3
3
|
interface MessageFormFieldProps {
|
|
4
|
-
label?: string;
|
|
5
4
|
locale: Locale;
|
|
6
5
|
name: string;
|
|
7
6
|
className?: string;
|
|
@@ -10,6 +9,6 @@ interface MessageFormFieldProps {
|
|
|
10
9
|
multiline?: boolean;
|
|
11
10
|
reference?: string;
|
|
12
11
|
}
|
|
13
|
-
export declare function MessageFormField({ name, variables,
|
|
12
|
+
export declare function MessageFormField({ name, variables, locale, validate, className, multiline, reference, }: MessageFormFieldProps): React.ReactNode;
|
|
14
13
|
export {};
|
|
15
14
|
//# sourceMappingURL=MessageFormField.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageFormField.d.ts","sourceRoot":"","sources":["../../src/components/MessageFormField.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAIzD,UAAU,qBAAqB;IAC7B,
|
|
1
|
+
{"version":3,"file":"MessageFormField.d.ts","sourceRoot":"","sources":["../../src/components/MessageFormField.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAIzD,UAAU,qBAAqB;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,gBAAgB,EAAE,CAAC;IAC9B,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,gBAAgB,CAAC,EAC/B,IAAI,EACJ,SAAS,EACT,MAAM,EACN,QAAQ,EACR,SAAS,EACT,SAAS,EACT,SAAS,GACV,EAAE,qBAAqB,GAAG,KAAK,CAAC,SAAS,CA0BzC"}
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { Controller } from 'react-hook-form';
|
|
3
3
|
import { useMessagesForm } from '../components/MessagesFormProvider';
|
|
4
4
|
import { MessageInput } from './inputs/MessageInput';
|
|
5
|
-
export function MessageFormField({ name, variables,
|
|
5
|
+
export function MessageFormField({ name, variables, locale, validate, className, multiline, reference }) {
|
|
6
6
|
const { control } = useMessagesForm();
|
|
7
7
|
return /*#__PURE__*/ _jsx(Controller, {
|
|
8
8
|
control: control,
|
|
@@ -10,7 +10,6 @@ export function MessageFormField({ name, variables, label, locale, validate, cla
|
|
|
10
10
|
render: ({ field, fieldState })=>/*#__PURE__*/ _jsx(MessageInput, {
|
|
11
11
|
className: className,
|
|
12
12
|
error: fieldState.error,
|
|
13
|
-
label: label,
|
|
14
13
|
lang: locale,
|
|
15
14
|
multiline: multiline,
|
|
16
15
|
onBlur: field.onBlur,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/MessageFormField.tsx"],"sourcesContent":["import { Controller } from 'react-hook-form';\nimport { useMessagesForm } from '@/components/MessagesFormProvider';\nimport type { Locale, TemplateVariable } from '@/types';\nimport type { MessageValidator } from '@/utils/validate';\n\nimport { MessageInput } from './inputs/MessageInput';\n\ninterface MessageFormFieldProps {\n
|
|
1
|
+
{"version":3,"sources":["../../src/components/MessageFormField.tsx"],"sourcesContent":["import { Controller } from 'react-hook-form';\nimport { useMessagesForm } from '@/components/MessagesFormProvider';\nimport type { Locale, TemplateVariable } from '@/types';\nimport type { MessageValidator } from '@/utils/validate';\n\nimport { MessageInput } from './inputs/MessageInput';\n\ninterface MessageFormFieldProps {\n locale: Locale;\n name: string;\n className?: string;\n variables: TemplateVariable[];\n validate: MessageValidator;\n multiline?: boolean;\n reference?: string;\n}\n\nexport function MessageFormField({\n name,\n variables,\n locale,\n validate,\n className,\n multiline,\n reference,\n}: MessageFormFieldProps): React.ReactNode {\n const { control } = useMessagesForm();\n\n return (\n <Controller\n control={control}\n name={name}\n render={({ field, fieldState }) => (\n <MessageInput\n className={className}\n error={fieldState.error}\n lang={locale}\n multiline={multiline}\n onBlur={field.onBlur}\n onChange={field.onChange}\n reference={reference}\n value={(field.value as unknown as string) || ''}\n variables={variables}\n />\n )}\n rules={{\n required: true,\n validate,\n }}\n />\n );\n}\n"],"names":["Controller","useMessagesForm","MessageInput","MessageFormField","name","variables","locale","validate","className","multiline","reference","control","render","field","fieldState","error","lang","onBlur","onChange","value","rules","required"],"mappings":";AAAA,SAASA,UAAU,QAAQ,kBAAkB;AAC7C,SAASC,eAAe,QAAQ,oCAAoC;AAIpE,SAASC,YAAY,QAAQ,wBAAwB;AAYrD,OAAO,SAASC,iBAAiB,EAC/BC,IAAI,EACJC,SAAS,EACTC,MAAM,EACNC,QAAQ,EACRC,SAAS,EACTC,SAAS,EACTC,SAAS,EACa;IACtB,MAAM,EAAEC,OAAO,EAAE,GAAGV;IAEpB,qBACE,KAACD;QACCW,SAASA;QACTP,MAAMA;QACNQ,QAAQ,CAAC,EAAEC,KAAK,EAAEC,UAAU,EAAE,iBAC5B,KAACZ;gBACCM,WAAWA;gBACXO,OAAOD,WAAWC,KAAK;gBACvBC,MAAMV;gBACNG,WAAWA;gBACXQ,QAAQJ,MAAMI,MAAM;gBACpBC,UAAUL,MAAMK,QAAQ;gBACxBR,WAAWA;gBACXS,OAAO,AAACN,MAAMM,KAAK,IAA0B;gBAC7Cd,WAAWA;;QAGfe,OAAO;YACLC,UAAU;YACVd;QACF;;AAGN"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { getAdminURL } from '@davincicoding/payload-plugin-kit';
|
|
2
3
|
import { Button } from '@payloadcms/ui';
|
|
3
|
-
import { getAdminURL } from '../internals/index.js';
|
|
4
4
|
import { IconWorld } from '@tabler/icons-react';
|
|
5
5
|
export async function MessagesLink({ access = ()=>true, req }) {
|
|
6
6
|
const hasAccess = await access(req);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/MessagesLink.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/components/MessagesLink.tsx"],"sourcesContent":["import { getAdminURL } from '@davincicoding/payload-plugin-kit';\nimport { Button } from '@payloadcms/ui';\nimport { IconWorld } from '@tabler/icons-react';\nimport type { PayloadRequest } from 'payload';\nimport type { MessagesGuard } from '@/types';\n\nexport interface MessagesLinkProps {\n access?: MessagesGuard;\n req: PayloadRequest;\n}\n\nexport async function MessagesLink({\n access = () => true,\n req,\n}: MessagesLinkProps) {\n const hasAccess = await access(req);\n if (!hasAccess) return null;\n\n return (\n <Button\n buttonStyle=\"tab\"\n el=\"link\"\n to={getAdminURL({ req, path: '/intl' })}\n >\n <IconWorld size={20} strokeWidth={1.5} />\n </Button>\n );\n}\n"],"names":["getAdminURL","Button","IconWorld","MessagesLink","access","req","hasAccess","buttonStyle","el","to","path","size","strokeWidth"],"mappings":";AAAA,SAASA,WAAW,QAAQ,oCAAoC;AAChE,SAASC,MAAM,QAAQ,iBAAiB;AACxC,SAASC,SAAS,QAAQ,sBAAsB;AAShD,OAAO,eAAeC,aAAa,EACjCC,SAAS,IAAM,IAAI,EACnBC,GAAG,EACe;IAClB,MAAMC,YAAY,MAAMF,OAAOC;IAC/B,IAAI,CAACC,WAAW,OAAO;IAEvB,qBACE,KAACL;QACCM,aAAY;QACZC,IAAG;QACHC,IAAIT,YAAY;YAAEK;YAAKK,MAAM;QAAQ;kBAErC,cAAA,KAACR;YAAUS,MAAM;YAAIC,aAAa;;;AAGxC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { getAdminURL } from '@davincicoding/payload-plugin-kit';
|
|
2
3
|
import { DefaultTemplate } from '@payloadcms/next/templates';
|
|
3
4
|
import { Gutter } from '@payloadcms/ui';
|
|
4
|
-
import { getAdminURL } from '../internals/index.js';
|
|
5
5
|
import { RedirectType, redirect } from 'next/navigation';
|
|
6
6
|
import { sanitizeMessages } from '../utils/sanitize';
|
|
7
7
|
import { fetchMessages } from '../requests/fetchMessages';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/MessagesView.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/components/MessagesView.tsx"],"sourcesContent":["import { getAdminURL } from '@davincicoding/payload-plugin-kit';\nimport { DefaultTemplate } from '@payloadcms/next/templates';\nimport { Gutter } from '@payloadcms/ui';\nimport { RedirectType, redirect } from 'next/navigation';\nimport type { AdminViewServerProps } from 'payload';\nimport type {\n DeepPartial,\n Locale,\n Messages,\n MessagesGuard,\n Translations,\n} from '@/types';\nimport { sanitizeMessages } from '@/utils/sanitize';\nimport { fetchMessages } from '../requests/fetchMessages';\nimport { MessagesForm } from './MessagesForm';\n\nexport interface MessagesViewProps {\n locales: Locale[];\n schema: Messages;\n tabs: boolean | undefined;\n access: MessagesGuard;\n}\n\nexport async function MessagesView({\n access,\n initPageResult: { req, locale, permissions, visibleEntities },\n locales,\n params,\n payload,\n schema,\n searchParams,\n tabs = false,\n}: AdminViewServerProps & MessagesViewProps) {\n const apiUrl = payload.getAPIURL();\n const endpointUrl = apiUrl.endsWith('/')\n ? `${apiUrl}intl-plugin`\n : `${apiUrl}/intl-plugin`;\n\n const hasAccess = await access(req);\n if (!hasAccess) redirect(getAdminURL({ req }), RedirectType.replace);\n\n if (!payload.config.localization) {\n return null;\n }\n const defaultLocale = payload.config.localization.defaultLocale;\n const activeLocale =\n typeof locale === 'string' ? locale : (locale?.code ?? defaultLocale);\n\n const translations: Translations<DeepPartial<Messages>> = {};\n\n for (const loc of locales) {\n const messages = await fetchMessages(payload, loc);\n\n translations[loc] = sanitizeMessages(schema, messages, {\n useSchemaDefaults: loc === defaultLocale,\n });\n }\n\n return (\n <DefaultTemplate\n i18n={req.i18n}\n locale={locale}\n params={params}\n payload={req.payload}\n permissions={permissions}\n searchParams={searchParams}\n user={req.user || undefined}\n viewActions={payload.config.admin.components.actions.filter((action) => {\n if (typeof action !== 'object') {\n return true;\n }\n return action.exportName !== 'MessagesLink';\n })}\n visibleEntities={visibleEntities}\n >\n <Gutter>\n <MessagesForm\n activeLocale={activeLocale}\n defaultLocale={defaultLocale}\n endpointUrl={endpointUrl}\n locales={locales}\n schema={schema}\n tabs={tabs}\n values={translations}\n />\n </Gutter>\n </DefaultTemplate>\n );\n}\n"],"names":["getAdminURL","DefaultTemplate","Gutter","RedirectType","redirect","sanitizeMessages","fetchMessages","MessagesForm","MessagesView","access","initPageResult","req","locale","permissions","visibleEntities","locales","params","payload","schema","searchParams","tabs","apiUrl","getAPIURL","endpointUrl","endsWith","hasAccess","replace","config","localization","defaultLocale","activeLocale","code","translations","loc","messages","useSchemaDefaults","i18n","user","undefined","viewActions","admin","components","actions","filter","action","exportName","values"],"mappings":";AAAA,SAASA,WAAW,QAAQ,oCAAoC;AAChE,SAASC,eAAe,QAAQ,6BAA6B;AAC7D,SAASC,MAAM,QAAQ,iBAAiB;AACxC,SAASC,YAAY,EAAEC,QAAQ,QAAQ,kBAAkB;AASzD,SAASC,gBAAgB,QAAQ,mBAAmB;AACpD,SAASC,aAAa,QAAQ,4BAA4B;AAC1D,SAASC,YAAY,QAAQ,iBAAiB;AAS9C,OAAO,eAAeC,aAAa,EACjCC,MAAM,EACNC,gBAAgB,EAAEC,GAAG,EAAEC,MAAM,EAAEC,WAAW,EAAEC,eAAe,EAA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QAAQd;;;;AAKlB"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { FieldError } from 'react-hook-form';
|
|
2
2
|
export interface FieldWrapperProps {
|
|
3
|
-
label?: string;
|
|
4
3
|
error: FieldError | undefined;
|
|
5
4
|
className?: string;
|
|
6
5
|
reference?: string;
|
|
7
6
|
}
|
|
8
|
-
export declare function FieldWrapper({
|
|
7
|
+
export declare function FieldWrapper({ error, reference, className, children, }: React.PropsWithChildren<FieldWrapperProps>): import("react/jsx-runtime").JSX.Element;
|
|
9
8
|
//# sourceMappingURL=FieldWrapper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldWrapper.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/FieldWrapper.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FieldWrapper.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/FieldWrapper.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAKlD,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,UAAU,GAAG,SAAS,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,SAAS,EACT,SAAS,EACT,QAAQ,GACT,EAAE,KAAK,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,2CAa5C"}
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
import styles from './FieldWrapper.module.css';
|
|
4
4
|
import { ReferencePopover } from './ReferencePopover';
|
|
5
|
-
export function FieldWrapper({
|
|
5
|
+
export function FieldWrapper({ error, reference, className, children }) {
|
|
6
6
|
return /*#__PURE__*/ _jsxs("div", {
|
|
7
7
|
className: clsx(styles.wrapper, className),
|
|
8
8
|
children: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/inputs/FieldWrapper.tsx"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../src/components/inputs/FieldWrapper.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport type { FieldError } from 'react-hook-form';\n\nimport styles from './FieldWrapper.module.css';\nimport { ReferencePopover } from './ReferencePopover';\n\nexport interface FieldWrapperProps {\n error: FieldError | undefined;\n className?: string;\n reference?: string;\n}\n\nexport function FieldWrapper({\n error,\n reference,\n className,\n children,\n}: React.PropsWithChildren<FieldWrapperProps>) {\n return (\n <div className={clsx(styles.wrapper, className)}>\n <ReferencePopover reference={reference}>\n <fieldset\n className={clsx(styles.fieldset, error && styles.fieldsetError)}\n >\n {children}\n </fieldset>\n </ReferencePopover>\n {error?.message && <p className={styles.errorMessage}>{error.message}</p>}\n </div>\n );\n}\n"],"names":["clsx","styles","ReferencePopover","FieldWrapper","error","reference","className","children","div","wrapper","fieldset","fieldsetError","message","p","errorMessage"],"mappings":";AAAA,OAAOA,UAAU,OAAO;AAGxB,OAAOC,YAAY,4BAA4B;AAC/C,SAASC,gBAAgB,QAAQ,qBAAqB;AAQtD,OAAO,SAASC,aAAa,EAC3BC,KAAK,EACLC,SAAS,EACTC,SAAS,EACTC,QAAQ,EACmC;IAC3C,qBACE,MAACC;QAAIF,WAAWN,KAAKC,OAAOQ,OAAO,EAAEH;;0BACnC,KAACJ;gBAAiBG,WAAWA;0BAC3B,cAAA,KAACK;oBACCJ,WAAWN,KAAKC,OAAOS,QAAQ,EAAEN,SAASH,OAAOU,aAAa;8BAE7DJ;;;YAGJH,OAAOQ,yBAAW,KAACC;gBAAEP,WAAWL,OAAOa,YAAY;0BAAGV,MAAMQ,OAAO;;;;AAG1E"}
|
|
@@ -5,5 +5,5 @@ export interface LexicalInputProps extends FieldWrapperProps {
|
|
|
5
5
|
onChange: (value: string) => void;
|
|
6
6
|
onBlur: () => void;
|
|
7
7
|
}
|
|
8
|
-
export declare function LexicalInput({ error,
|
|
8
|
+
export declare function LexicalInput({ error, value, onChange, className, }: LexicalInputProps): React.ReactNode;
|
|
9
9
|
//# sourceMappingURL=LexicalInput.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LexicalInput.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/LexicalInput.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGxD,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,KAAK,EACL,
|
|
1
|
+
{"version":3,"file":"LexicalInput.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/LexicalInput.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGxD,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,KAAK,EACL,QAAQ,EACR,SAAS,GACV,EAAE,iBAAiB,GAAG,KAAK,CAAC,SAAS,CAoBrC"}
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { RenderLexical } from '@payloadcms/richtext-lexical/client';
|
|
3
3
|
import { useHtmlLexicalAdapter } from '../hooks/useHtmlLexicalAdapter';
|
|
4
4
|
import { FieldWrapper } from './FieldWrapper';
|
|
5
|
-
export function LexicalInput({ error,
|
|
5
|
+
export function LexicalInput({ error, value, onChange, className }) {
|
|
6
6
|
const editor = useHtmlLexicalAdapter({
|
|
7
7
|
html: value,
|
|
8
8
|
onChange
|
|
@@ -10,7 +10,6 @@ export function LexicalInput({ error, label, value, onChange, className }) {
|
|
|
10
10
|
return /*#__PURE__*/ _jsx(FieldWrapper, {
|
|
11
11
|
className: className,
|
|
12
12
|
error: error,
|
|
13
|
-
label: label,
|
|
14
13
|
children: /*#__PURE__*/ _jsx(RenderLexical, {
|
|
15
14
|
field: {
|
|
16
15
|
name: 'myCustomEditor',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/inputs/LexicalInput.tsx"],"sourcesContent":["import { RenderLexical } from '@payloadcms/richtext-lexical/client';\nimport type { SerializedEditorState } from '@payloadcms/richtext-lexical/lexical';\nimport { useHtmlLexicalAdapter } from '../hooks/useHtmlLexicalAdapter';\nimport type { FieldWrapperProps } from './FieldWrapper';\nimport { FieldWrapper } from './FieldWrapper';\n\nexport interface LexicalInputProps extends FieldWrapperProps {\n lang: string;\n value: string;\n onChange: (value: string) => void;\n onBlur: () => void;\n}\n\nexport function LexicalInput({\n error,\n
|
|
1
|
+
{"version":3,"sources":["../../../src/components/inputs/LexicalInput.tsx"],"sourcesContent":["import { RenderLexical } from '@payloadcms/richtext-lexical/client';\nimport type { SerializedEditorState } from '@payloadcms/richtext-lexical/lexical';\nimport { useHtmlLexicalAdapter } from '../hooks/useHtmlLexicalAdapter';\nimport type { FieldWrapperProps } from './FieldWrapper';\nimport { FieldWrapper } from './FieldWrapper';\n\nexport interface LexicalInputProps extends FieldWrapperProps {\n lang: string;\n value: string;\n onChange: (value: string) => void;\n onBlur: () => void;\n}\n\nexport function LexicalInput({\n error,\n value,\n onChange,\n className,\n}: LexicalInputProps): React.ReactNode {\n const editor = useHtmlLexicalAdapter({\n html: value,\n onChange,\n });\n\n return (\n <FieldWrapper className={className} error={error}>\n <RenderLexical\n field={{\n name: 'myCustomEditor',\n label: false,\n type: 'richText',\n }}\n schemaPath=\"global.intl-plugin.editorTemplate\"\n setValue={(val) => editor.setValue(val as SerializedEditorState)}\n value={editor.value}\n />\n </FieldWrapper>\n );\n}\n"],"names":["RenderLexical","useHtmlLexicalAdapter","FieldWrapper","LexicalInput","error","value","onChange","className","editor","html","field","name","label","type","schemaPath","setValue","val"],"mappings":";AAAA,SAASA,aAAa,QAAQ,sCAAsC;AAEpE,SAASC,qBAAqB,QAAQ,iCAAiC;AAEvE,SAASC,YAAY,QAAQ,iBAAiB;AAS9C,OAAO,SAASC,aAAa,EAC3BC,KAAK,EACLC,KAAK,EACLC,QAAQ,EACRC,SAAS,EACS;IAClB,MAAMC,SAASP,sBAAsB;QACnCQ,MAAMJ;QACNC;IACF;IAEA,qBACE,KAACJ;QAAaK,WAAWA;QAAWH,OAAOA;kBACzC,cAAA,KAACJ;YACCU,OAAO;gBACLC,MAAM;gBACNC,OAAO;gBACPC,MAAM;YACR;YACAC,YAAW;YACXC,UAAU,CAACC,MAAQR,OAAOO,QAAQ,CAACC;YACnCX,OAAOG,OAAOH,KAAK;;;AAI3B"}
|
|
@@ -10,5 +10,5 @@ export interface MessageInputProps extends FieldWrapperProps {
|
|
|
10
10
|
multiline?: boolean;
|
|
11
11
|
reference?: string;
|
|
12
12
|
}
|
|
13
|
-
export declare function MessageInput({
|
|
13
|
+
export declare function MessageInput({ value, lang, error, variables, onChange, onBlur, className, multiline, reference, }: MessageInputProps): import("react/jsx-runtime").JSX.Element;
|
|
14
14
|
//# sourceMappingURL=MessageInput.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageInput.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/MessageInput.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAShD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AA2BxD,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC1D,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,gBAAgB,EAAE,CAAC;IAC9B,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,
|
|
1
|
+
{"version":3,"file":"MessageInput.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/MessageInput.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAShD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AA2BxD,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC1D,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,gBAAgB,EAAE,CAAC;IAC9B,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,IAAI,EACJ,KAAK,EACL,SAAS,EACT,QAAQ,EACR,MAAM,EACN,SAAS,EACT,SAAS,EACT,SAAS,GACV,EAAE,iBAAiB,2CAkFnB"}
|
|
@@ -35,7 +35,7 @@ function SyncValuePlugin({ value }) {
|
|
|
35
35
|
]);
|
|
36
36
|
return null;
|
|
37
37
|
}
|
|
38
|
-
export function MessageInput({
|
|
38
|
+
export function MessageInput({ value, lang, error, variables, onChange, onBlur, className, multiline, reference }) {
|
|
39
39
|
const handleChange = useCallback((editorState)=>{
|
|
40
40
|
editorState.read(()=>{
|
|
41
41
|
onChange($getRoot().getTextContent());
|
|
@@ -77,7 +77,6 @@ export function MessageInput({ label, value, lang, error, variables, onChange, o
|
|
|
77
77
|
return /*#__PURE__*/ _jsx(FieldWrapper, {
|
|
78
78
|
className: className,
|
|
79
79
|
error: error,
|
|
80
|
-
label: label,
|
|
81
80
|
reference: reference,
|
|
82
81
|
children: /*#__PURE__*/ _jsx(LexicalComposer, {
|
|
83
82
|
initialConfig: initialConfig,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/inputs/MessageInput.tsx"],"sourcesContent":["'use client';\n\nimport type { EditorState } from '@payloadcms/richtext-lexical/lexical';\nimport { $getRoot } from '@payloadcms/richtext-lexical/lexical';\nimport { LexicalComposer } from '@payloadcms/richtext-lexical/lexical/react/LexicalComposer';\nimport { useLexicalComposerContext } from '@payloadcms/richtext-lexical/lexical/react/LexicalComposerContext';\nimport { ContentEditable } from '@payloadcms/richtext-lexical/lexical/react/LexicalContentEditable';\nimport { LexicalErrorBoundary } from '@payloadcms/richtext-lexical/lexical/react/LexicalErrorBoundary';\nimport { HistoryPlugin } from '@payloadcms/richtext-lexical/lexical/react/LexicalHistoryPlugin';\nimport { OnChangePlugin } from '@payloadcms/richtext-lexical/lexical/react/LexicalOnChangePlugin';\nimport { PlainTextPlugin } from '@payloadcms/richtext-lexical/lexical/react/LexicalPlainTextPlugin';\nimport clsx from 'clsx';\nimport {\n BeautifulMentionNode,\n BeautifulMentionsPlugin,\n} from 'lexical-beautiful-mentions';\nimport { useCallback, useEffect, useMemo } from 'react';\nimport type { TemplateVariable } from '@/types';\n\nimport { formatVariableLabel } from '@/utils/format';\nimport { isTagElement } from '@/utils/guards';\nimport {\n parseIcuToLexicalState,\n serializeICUMessage,\n} from '@/utils/icu-tranform';\n\nimport type { FieldWrapperProps } from './FieldWrapper';\nimport { FieldWrapper } from './FieldWrapper';\nimport styles from './MessageInput.module.css';\nimport { SingleLinePlugin } from './SingleLinePlugin';\nimport { VariableMentionNode } from './variables/VariableNode';\nimport { MentionMenu, MentionMenuItem } from './variables/VariableSuggestion';\n\nfunction SyncValuePlugin({ value }: { value: string }) {\n const [editor] = useLexicalComposerContext();\n\n useEffect(() => {\n const currentText = editor\n .getEditorState()\n .read(() => $getRoot().getTextContent());\n if (value !== currentText) {\n queueMicrotask(() => {\n const newState = editor.parseEditorState(\n JSON.stringify(parseIcuToLexicalState(value)),\n );\n editor.setEditorState(newState);\n });\n }\n }, [value, editor]);\n\n return null;\n}\n\nexport interface MessageInputProps extends FieldWrapperProps {\n value: string;\n lang: string;\n variables: TemplateVariable[];\n onChange: (value: string) => void;\n onBlur: () => void;\n readOnly?: boolean;\n multiline?: boolean;\n reference?: string;\n}\n\nexport function MessageInput({\n
|
|
1
|
+
{"version":3,"sources":["../../../src/components/inputs/MessageInput.tsx"],"sourcesContent":["'use client';\n\nimport type { EditorState } from '@payloadcms/richtext-lexical/lexical';\nimport { $getRoot } from '@payloadcms/richtext-lexical/lexical';\nimport { LexicalComposer } from '@payloadcms/richtext-lexical/lexical/react/LexicalComposer';\nimport { useLexicalComposerContext } from '@payloadcms/richtext-lexical/lexical/react/LexicalComposerContext';\nimport { ContentEditable } from '@payloadcms/richtext-lexical/lexical/react/LexicalContentEditable';\nimport { LexicalErrorBoundary } from '@payloadcms/richtext-lexical/lexical/react/LexicalErrorBoundary';\nimport { HistoryPlugin } from '@payloadcms/richtext-lexical/lexical/react/LexicalHistoryPlugin';\nimport { OnChangePlugin } from '@payloadcms/richtext-lexical/lexical/react/LexicalOnChangePlugin';\nimport { PlainTextPlugin } from '@payloadcms/richtext-lexical/lexical/react/LexicalPlainTextPlugin';\nimport clsx from 'clsx';\nimport {\n BeautifulMentionNode,\n BeautifulMentionsPlugin,\n} from 'lexical-beautiful-mentions';\nimport { useCallback, useEffect, useMemo } from 'react';\nimport type { TemplateVariable } from '@/types';\n\nimport { formatVariableLabel } from '@/utils/format';\nimport { isTagElement } from '@/utils/guards';\nimport {\n parseIcuToLexicalState,\n serializeICUMessage,\n} from '@/utils/icu-tranform';\n\nimport type { FieldWrapperProps } from './FieldWrapper';\nimport { FieldWrapper } from './FieldWrapper';\nimport styles from './MessageInput.module.css';\nimport { SingleLinePlugin } from './SingleLinePlugin';\nimport { VariableMentionNode } from './variables/VariableNode';\nimport { MentionMenu, MentionMenuItem } from './variables/VariableSuggestion';\n\nfunction SyncValuePlugin({ value }: { value: string }) {\n const [editor] = useLexicalComposerContext();\n\n useEffect(() => {\n const currentText = editor\n .getEditorState()\n .read(() => $getRoot().getTextContent());\n if (value !== currentText) {\n queueMicrotask(() => {\n const newState = editor.parseEditorState(\n JSON.stringify(parseIcuToLexicalState(value)),\n );\n editor.setEditorState(newState);\n });\n }\n }, [value, editor]);\n\n return null;\n}\n\nexport interface MessageInputProps extends FieldWrapperProps {\n value: string;\n lang: string;\n variables: TemplateVariable[];\n onChange: (value: string) => void;\n onBlur: () => void;\n readOnly?: boolean;\n multiline?: boolean;\n reference?: string;\n}\n\nexport function MessageInput({\n value,\n lang,\n error,\n variables,\n onChange,\n onBlur,\n className,\n multiline,\n reference,\n}: MessageInputProps) {\n const handleChange = useCallback(\n (editorState: EditorState) => {\n editorState.read(() => {\n onChange($getRoot().getTextContent());\n });\n },\n [onChange],\n );\n\n const mentionItems = useMemo(() => {\n const toItem = (v: TemplateVariable) => ({\n value: v.value,\n label: formatVariableLabel(v),\n icu: serializeICUMessage([v]),\n });\n\n return {\n '@': variables.map(toItem),\n '{': variables.filter((v) => !isTagElement(v)).map(toItem),\n '<': variables.filter((v) => isTagElement(v)).map(toItem),\n };\n }, [variables]);\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: LexicalComposer only reads initialConfig on mount\n const initialConfig = useMemo(\n () => ({\n namespace: 'ICUMessageEditor',\n nodes: [\n VariableMentionNode,\n {\n replace: BeautifulMentionNode,\n with: (node: BeautifulMentionNode) =>\n new VariableMentionNode(\n node.getTrigger(),\n node.getValue(),\n node.getData(),\n ),\n withKlass: VariableMentionNode,\n },\n ],\n editorState: JSON.stringify(parseIcuToLexicalState(value)),\n editable: true,\n onError: console.error,\n }),\n [],\n );\n\n return (\n <FieldWrapper className={className} error={error} reference={reference}>\n <LexicalComposer initialConfig={initialConfig}>\n <div\n className={clsx(styles.editor, multiline && styles.multiline)}\n lang={lang}\n >\n <PlainTextPlugin\n contentEditable={\n <ContentEditable\n className={clsx(\n styles.contentEditable,\n error && styles.contentEditableError,\n )}\n onBlur={onBlur}\n />\n }\n ErrorBoundary={LexicalErrorBoundary}\n />\n {multiline && <SingleLinePlugin />}\n <SyncValuePlugin value={value} />\n <OnChangePlugin onChange={handleChange} />\n <HistoryPlugin />\n\n <BeautifulMentionsPlugin\n items={mentionItems}\n menuAnchorClassName={styles.menuAnchor}\n menuComponent={MentionMenu}\n menuItemComponent={MentionMenuItem}\n />\n </div>\n </LexicalComposer>\n </FieldWrapper>\n );\n}\n"],"names":["$getRoot","LexicalComposer","useLexicalComposerContext","ContentEditable","LexicalErrorBoundary","HistoryPlugin","OnChangePlugin","PlainTextPlugin","clsx","BeautifulMentionNode","BeautifulMentionsPlugin","useCallback","useEffect","useMemo","formatVariableLabel","isTagElement","parseIcuToLexicalState","serializeICUMessage","FieldWrapper","styles","SingleLinePlugin","VariableMentionNode","MentionMenu","MentionMenuItem","SyncValuePlugin","value","editor","currentText","getEditorState","read","getTextContent","queueMicrotask","newState","parseEditorState","JSON","stringify","setEditorState","MessageInput","lang","error","variables","onChange","onBlur","className","multiline","reference","handleChange","editorState","mentionItems","toItem","v","label","icu","map","filter","initialConfig","namespace","nodes","replace","with","node","getTrigger","getValue","getData","withKlass","editable","onError","console","div","contentEditable","contentEditableError","ErrorBoundary","items","menuAnchorClassName","menuAnchor","menuCompon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wBAGZ6B,eAAenE;;oBAEhBwC,2BAAa,KAACxB;kCACf,KAACI;wBAAgBC,OAAOA;;kCACxB,KAACnB;wBAAemC,UAAUK;;kCAC1B,KAACzC;kCAED,KAACK;wBACC8D,OAAOxB;wBACPyB,qBAAqBtD,OAAOuD,UAAU;wBACtCC,eAAerD;wBACfsD,mBAAmBrD;;;;;;AAM/B"}
|
package/dist/const.d.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
export declare const PLUGIN_CONTEXT: {
|
|
2
|
+
set: (config: import("payload").Config, context: {
|
|
3
|
+
collectionSlug: string;
|
|
4
|
+
storage: "db" | "upload";
|
|
5
|
+
}) => void;
|
|
6
|
+
get: (config: {
|
|
7
|
+
custom?: Record<string, unknown>;
|
|
8
|
+
}) => {
|
|
9
|
+
collectionSlug: string;
|
|
10
|
+
storage: "db" | "upload";
|
|
11
|
+
} | null;
|
|
12
|
+
};
|
|
2
13
|
export declare const ENDPOINTS: {
|
|
3
|
-
|
|
4
|
-
locale: string;
|
|
5
|
-
}, Messages>;
|
|
6
|
-
setMessages: import("./internals/index.js").Procedure<void, {
|
|
14
|
+
setMessages: import("@davincicoding/payload-plugin-kit").Procedure<void, {
|
|
7
15
|
success: boolean;
|
|
8
16
|
}>;
|
|
9
17
|
};
|
package/dist/const.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../src/const.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../src/const.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,cAAc;;;;;;cAcqP,CAAC;;;;;CARhR,CAAC;AAEF,eAAO,MAAM,SAAS;;iBAIE,OAAO;;CAC9B,CAAC"}
|
package/dist/const.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { defineProcedure } from '
|
|
2
|
-
import { z } from 'zod';
|
|
1
|
+
import { createPluginContext, defineProcedure } from '@davincicoding/payload-plugin-kit';
|
|
2
|
+
import { z } from 'zod/v4-mini';
|
|
3
|
+
export const PLUGIN_CONTEXT = createPluginContext('payload-intl', z.object({
|
|
4
|
+
collectionSlug: z.string(),
|
|
5
|
+
storage: z.enum([
|
|
6
|
+
'db',
|
|
7
|
+
'upload'
|
|
8
|
+
])
|
|
9
|
+
}));
|
|
3
10
|
export const ENDPOINTS = {
|
|
4
|
-
getMessages: defineProcedure({
|
|
5
|
-
path: '/intl-plugin/:locale',
|
|
6
|
-
method: 'get',
|
|
7
|
-
input: z.object({
|
|
8
|
-
locale: z.string()
|
|
9
|
-
})
|
|
10
|
-
}).returns(),
|
|
11
11
|
setMessages: defineProcedure({
|
|
12
12
|
path: '/intl-plugin',
|
|
13
13
|
method: 'put'
|
package/dist/const.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/const.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../src/const.ts"],"sourcesContent":["import {\n createPluginContext,\n defineProcedure,\n} from '@davincicoding/payload-plugin-kit';\nimport { z } from 'zod/v4-mini';\n\nexport const PLUGIN_CONTEXT = createPluginContext(\n 'payload-intl',\n z.object({\n collectionSlug: z.string(),\n storage: z.enum(['db', 'upload']),\n }),\n);\n\nexport const ENDPOINTS = {\n setMessages: defineProcedure({\n path: '/intl-plugin',\n method: 'put',\n }).returns<{ success: boolean }>(),\n};\n"],"names":["createPluginContext","defineProcedure","z","PLUGIN_CONTEXT","object","collectionSlug","string","storage","enum","ENDPOINTS","setMessages","path","method","returns"],"mappings":"AAAA,SACEA,mBAAmB,EACnBC,eAAe,QACV,oCAAoC;AAC3C,SAASC,CAAC,QAAQ,cAAc;AAEhC,OAAO,MAAMC,iBAAiBH,oBAC5B,gBACAE,EAAEE,MAAM,CAAC;IACPC,gBAAgBH,EAAEI,MAAM;IACxBC,SAASL,EAAEM,IAAI,CAAC;QAAC;QAAM;KAAS;AAClC,IACA;AAEF,OAAO,MAAMC,YAAY;IACvBC,aAAaT,gBAAgB;QAC3BU,MAAM;QACNC,QAAQ;IACV,GAAGC,OAAO;AACZ,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set-messages.d.ts","sourceRoot":"","sources":["../../src/endpoints/set-messages.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"set-messages.d.ts","sourceRoot":"","sources":["../../src/endpoints/set-messages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAwB,MAAM,SAAS,CAAC;AAK9D,eAAO,MAAM,mBAAmB,EAAE,QA8EjC,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { uncaughtSwitchCase } from '@davincicoding/payload-plugin-kit';
|
|
2
|
+
import { ENDPOINTS, PLUGIN_CONTEXT } from '../const';
|
|
3
|
+
import { getSupportedLocales } from '../utils/config';
|
|
3
4
|
export const setMessagesEndpoint = ENDPOINTS.setMessages.endpoint(async (req)=>{
|
|
4
5
|
const { user } = await req.payload.auth({
|
|
5
6
|
headers: req.headers
|
|
@@ -20,39 +21,80 @@ export const setMessagesEndpoint = ENDPOINTS.setMessages.endpoint(async (req)=>{
|
|
|
20
21
|
});
|
|
21
22
|
}
|
|
22
23
|
const supportedLocales = getSupportedLocales(req.payload.config.localization);
|
|
23
|
-
const
|
|
24
|
+
const ctx = PLUGIN_CONTEXT.get(req.payload.config);
|
|
25
|
+
if (!ctx) {
|
|
26
|
+
return Response.json({
|
|
27
|
+
error: 'Plugin not configured'
|
|
28
|
+
}, {
|
|
29
|
+
status: 500
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const { collectionSlug, storage } = ctx;
|
|
24
33
|
for (const locale of supportedLocales){
|
|
25
34
|
const messages = data[locale];
|
|
26
35
|
if (!messages) continue;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
switch(storage){
|
|
37
|
+
case 'db':
|
|
38
|
+
{
|
|
39
|
+
const { docs } = await req.payload.update({
|
|
40
|
+
collection: ctx.collectionSlug,
|
|
41
|
+
data: {
|
|
42
|
+
data: messages
|
|
43
|
+
},
|
|
44
|
+
where: {
|
|
45
|
+
locale: {
|
|
46
|
+
equals: locale
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
if (docs.length === 0) {
|
|
51
|
+
await req.payload.create({
|
|
52
|
+
collection: ctx.collectionSlug,
|
|
53
|
+
data: {
|
|
54
|
+
locale,
|
|
55
|
+
data: messages
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
break;
|
|
45
60
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
case 'upload':
|
|
62
|
+
{
|
|
63
|
+
const rawFile = new File([
|
|
64
|
+
JSON.stringify(messages)
|
|
65
|
+
], `${locale}-${Date.now()}.json`, {
|
|
66
|
+
type: 'application/json'
|
|
67
|
+
});
|
|
68
|
+
const file = {
|
|
69
|
+
name: rawFile.name,
|
|
70
|
+
data: Buffer.from(await rawFile.arrayBuffer()),
|
|
71
|
+
mimetype: rawFile.type,
|
|
72
|
+
size: rawFile.size
|
|
73
|
+
};
|
|
74
|
+
const { docs } = await req.payload.update({
|
|
75
|
+
collection: collectionSlug,
|
|
76
|
+
data: {},
|
|
77
|
+
file,
|
|
78
|
+
where: {
|
|
79
|
+
locale: {
|
|
80
|
+
equals: locale
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
if (docs.length === 0) {
|
|
85
|
+
await req.payload.create({
|
|
86
|
+
collection: collectionSlug,
|
|
87
|
+
data: {
|
|
88
|
+
locale,
|
|
89
|
+
data: null
|
|
90
|
+
},
|
|
91
|
+
file
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
default:
|
|
97
|
+
return uncaughtSwitchCase(storage);
|
|
56
98
|
}
|
|
57
99
|
}
|
|
58
100
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/endpoints/set-messages.ts"],"sourcesContent":["import type { Endpoint, File, PayloadRequest } from 'payload';\nimport { ENDPOINTS } from '@/const';\nimport type { Messages, Translations } from '@/types';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/endpoints/set-messages.ts"],"sourcesContent":["import { uncaughtSwitchCase } from '@davincicoding/payload-plugin-kit';\nimport type { Endpoint, File, PayloadRequest } from 'payload';\nimport { ENDPOINTS, PLUGIN_CONTEXT } from '@/const';\nimport type { Messages, Translations } from '@/types';\nimport { getSupportedLocales } from '@/utils/config';\n\nexport const setMessagesEndpoint: Endpoint = ENDPOINTS.setMessages.endpoint(\n async (req: PayloadRequest) => {\n const { user } = await req.payload.auth({ headers: req.headers });\n if (!user) {\n return Response.json({ error: 'Unauthorized' }, { status: 401 });\n }\n\n const data = (await req.json?.()) as Translations<Messages> | undefined;\n if (!data) {\n return Response.json({ error: 'No data provided' }, { status: 400 });\n }\n\n const supportedLocales = getSupportedLocales(\n req.payload.config.localization,\n );\n const ctx = PLUGIN_CONTEXT.get(req.payload.config);\n if (!ctx) {\n return Response.json({ error: 'Plugin not configured' }, { status: 500 });\n }\n const { collectionSlug, storage } = ctx;\n\n for (const locale of supportedLocales) {\n const messages = data[locale];\n if (!messages) continue;\n\n switch (storage) {\n case 'db': {\n const { docs } = await req.payload.update({\n collection: ctx.collectionSlug as 'messages',\n data: { data: messages },\n where: { locale: { equals: locale } },\n });\n if (docs.length === 0) {\n await req.payload.create({\n collection: ctx.collectionSlug as 'messages',\n data: { locale, data: messages },\n });\n }\n break;\n }\n case 'upload': {\n const rawFile = new File(\n [JSON.stringify(messages)],\n `${locale}-${Date.now()}.json`,\n {\n type: 'application/json',\n },\n );\n\n const file: File = {\n name: rawFile.name,\n data: Buffer.from(await rawFile.arrayBuffer()),\n mimetype: rawFile.type,\n size: rawFile.size,\n };\n\n const { docs } = await req.payload.update({\n collection: collectionSlug as 'messages',\n data: {},\n file,\n where: { locale: { equals: locale } },\n });\n if (docs.length === 0) {\n await req.payload.create({\n collection: collectionSlug as 'messages',\n data: { locale, data: null },\n file,\n });\n }\n break;\n }\n default:\n return uncaughtSwitchCase(storage);\n }\n }\n\n return { success: true };\n },\n);\n"],"names":["uncaughtSwitchCase","ENDPOINTS","PLUGIN_CONTEXT","getSupportedLocales","setMessagesEndpoint","setMessages","endpoint","req","user","payload","auth","headers","Response","json","error","status","data","supportedLocales","config","localization","ctx","get","collectionSlug","storage","locale","messages","docs","update","collection","where","equals","length","create","rawFile","File","JSON","stringify","Date","now","type","file","name","Buffer","from","arrayBuffer","mimetype","size","success"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,oCAAoC;AAEvE,SAASC,SAAS,EAAEC,cAAc,QAAQ,UAAU;AAEpD,SAASC,mBAAmB,QAAQ,iBAAiB;AAErD,OAAO,MAAMC,sBAAgCH,UAAUI,WAAW,CAACC,QAAQ,CACzE,OAAOC;IACL,MAAM,EAAEC,IAAI,EAAE,GAAG,MAAMD,IAAIE,OAAO,CAACC,IAAI,CAAC;QAAEC,SAASJ,IAAII,OAAO;IAAC;IAC/D,IAAI,CAACH,MAAM;QACT,OAAOI,SAASC,IAAI,CAAC;YAAEC,OAAO;QAAe,GAAG;YAAEC,QAAQ;QAAI;IAChE;IAEA,MAAMC,OAAQ,MAAMT,IAAIM,IAAI;IAC5B,IAAI,CAACG,MAAM;QACT,OAAOJ,SAASC,IAAI,CAAC;YAA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BAEA,MAAM,EAAEpB,IAAI,EAAE,GAAG,MAAMnB,IAAIE,OAAO,CAACkB,MAAM,CAAC;wBACxCC,YAAYN;wBACZN,MAAM,CAAC;wBACPwB;wBACAX,OAAO;4BAAEL,QAAQ;gCAAEM,QAAQN;4BAAO;wBAAE;oBACtC;oBACA,IAAIE,KAAKK,MAAM,KAAK,GAAG;wBACrB,MAAMxB,IAAIE,OAAO,CAACuB,MAAM,CAAC;4BACvBJ,YAAYN;4BACZN,MAAM;gCAAEQ;gCAAQR,MAAM;4BAAK;4BAC3BwB;wBACF;oBACF;oBACA;gBACF;YACA;gBACE,OAAOxC,mBAAmBuB;QAC9B;IACF;IAEA,OAAO;QAAEwB,SAAS;IAAK;AACzB,GACA"}
|
package/dist/entities.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ResolvedPluginOptions } from './types';
|
|
2
|
-
export declare const Messages: (options: ResolvedPluginOptions<"hooks"> & {
|
|
2
|
+
export declare const Messages: (options: ResolvedPluginOptions<"storage" | "hooks"> & {
|
|
3
3
|
slug: string;
|
|
4
4
|
}) => import("payload").CollectionConfig;
|
|
5
5
|
//# sourceMappingURL=entities.d.ts.map
|
package/dist/entities.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../src/entities.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../src/entities.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAErD,eAAO,MAAM,QAAQ;;wCAgClB,CAAC"}
|
package/dist/entities.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { createCollectionConfigFactory } from '
|
|
2
|
-
import { getMessagesEndpoint } from './endpoints/get-messages';
|
|
1
|
+
import { createCollectionConfigFactory } from '@davincicoding/payload-plugin-kit';
|
|
3
2
|
import { setMessagesEndpoint } from './endpoints/set-messages';
|
|
4
3
|
import { createHooks } from './hooks';
|
|
5
|
-
export const Messages = createCollectionConfigFactory(({ hooks })=>({
|
|
4
|
+
export const Messages = createCollectionConfigFactory(({ hooks, storage })=>({
|
|
6
5
|
admin: {
|
|
7
6
|
hidden: true
|
|
8
7
|
},
|
|
@@ -10,14 +9,17 @@ export const Messages = createCollectionConfigFactory(({ hooks })=>({
|
|
|
10
9
|
read: ()=>true
|
|
11
10
|
},
|
|
12
11
|
endpoints: [
|
|
13
|
-
setMessagesEndpoint
|
|
14
|
-
getMessagesEndpoint
|
|
12
|
+
setMessagesEndpoint
|
|
15
13
|
],
|
|
16
14
|
fields: [
|
|
17
15
|
{
|
|
18
16
|
name: 'locale',
|
|
19
17
|
type: 'text',
|
|
20
18
|
required: true
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'data',
|
|
22
|
+
type: 'json'
|
|
21
23
|
}
|
|
22
24
|
],
|
|
23
25
|
hooks: createHooks(hooks),
|
|
@@ -28,10 +30,12 @@ export const Messages = createCollectionConfigFactory(({ hooks })=>({
|
|
|
28
30
|
]
|
|
29
31
|
}
|
|
30
32
|
],
|
|
31
|
-
upload
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
...storage === 'upload' && {
|
|
34
|
+
upload: {
|
|
35
|
+
mimeTypes: [
|
|
36
|
+
'application/json'
|
|
37
|
+
]
|
|
38
|
+
}
|
|
35
39
|
}
|
|
36
40
|
}));
|
|
37
41
|
|