payload-intl 1.4.4 → 1.4.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"MessagesField.d.ts","sourceRoot":"","sources":["../../src/components/MessagesField.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAGpD,OAAO,KAAK,EAAY,cAAc,EAAE,MAAM,SAAS,CAAC;AAGxD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,EAC5B,MAAM,EACN,YAAY,EACZ,IAAI,GACL,EAAE,oBAAoB,GAAG,kBAAkB,2CAwB3C"}
1
+ {"version":3,"file":"MessagesField.d.ts","sourceRoot":"","sources":["../../src/components/MessagesField.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAGpD,OAAO,KAAK,EAAY,cAAc,EAAE,MAAM,SAAS,CAAC;AAGxD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,EAC5B,MAAM,EACN,YAAY,EACZ,IAAI,GACL,EAAE,oBAAoB,GAAG,kBAAkB,2CAgC3C"}
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { useField } from '@payloadcms/ui';
4
- import { useEffect } from 'react';
4
+ import { useEffect, useRef } from 'react';
5
5
  import { useForm } from 'react-hook-form';
6
6
  import { MessagesTree } from './layout/MessagesTree';
7
7
  /**
@@ -11,14 +11,22 @@ import { MessagesTree } from './layout/MessagesTree';
11
11
  const { value, setValue } = useField({
12
12
  path
13
13
  });
14
+ const lastPushedRef = useRef(value);
14
15
  const form = useForm({
15
16
  values: value,
16
17
  reValidateMode: 'onBlur'
17
18
  });
18
- // When form values change, push back to Payload's field
19
+ // When form values change, push back to Payload's field.
20
+ // Guard against the circular loop: Payload value → useForm syncs → watch
21
+ // fires → setValue → Payload value changes → repeat. Only call setValue
22
+ // when the form produced genuinely new data.
19
23
  useEffect(()=>{
20
24
  const subscription = form.watch((formValues)=>{
21
- setValue(formValues);
25
+ const json = JSON.stringify(formValues);
26
+ if (json !== JSON.stringify(lastPushedRef.current)) {
27
+ lastPushedRef.current = formValues;
28
+ setValue(formValues);
29
+ }
22
30
  });
23
31
  return ()=>subscription.unsubscribe();
24
32
  }, [
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/MessagesField.tsx"],"sourcesContent":["'use client';\n\nimport { useField } from '@payloadcms/ui';\nimport type { JSONFieldClientProps } from 'payload';\nimport { useEffect } from 'react';\nimport { useForm } from 'react-hook-form';\nimport type { Messages, MessagesSchema } from '@/types';\nimport { MessagesTree } from './layout/MessagesTree';\n\nexport interface MessagesFieldProps {\n readonly schema: MessagesSchema;\n readonly hiddenGroups?: string[];\n}\n\n/**\n * Payload JSON field client component that bridges the virtual `_intlMessages`\n * field with the existing MessagesFormProvider / MessagesTree component tree.\n */\nexport function MessagesField({\n schema,\n hiddenGroups,\n path,\n}: JSONFieldClientProps & MessagesFieldProps) {\n const { value, setValue } = useField<Messages>({ path });\n\n const form = useForm<Messages>({\n values: value,\n reValidateMode: 'onBlur',\n });\n\n // When form values change, push back to Payload's field\n useEffect(() => {\n const subscription = form.watch((formValues) => {\n setValue(formValues);\n });\n return () => subscription.unsubscribe();\n }, [form, setValue]);\n\n return (\n <MessagesTree\n control={form.control}\n hiddenGroups={hiddenGroups}\n path=\"\"\n schema={schema}\n />\n );\n}\n"],"names":["useField","useEffect","useForm","MessagesTree","MessagesField","schema","hiddenGroups","path","value","setValue","form","values","reValidateMode","subscription","watch","formValues","unsubscribe","control"],"mappings":"AAAA;;AAEA,SAASA,QAAQ,QAAQ,iBAAiB;AAE1C,SAASC,SAAS,QAAQ,QAAQ;AAClC,SAASC,OAAO,QAAQ,kBAAkB;AAE1C,SAASC,YAAY,QAAQ,wBAAwB;AAOrD;;;CAGC,GACD,OAAO,SAASC,cAAc,EAC5BC,MAAM,EACNC,YAAY,EACZC,IAAI,EACsC;IAC1C,MAAM,EAAEC,KAAK,EAAEC,QAAQ,EAAE,GAAGT,SAAmB;QAAEO;IAAK;IAEtD,MAAMG,OAAOR,QAAkB;QAC7BS,QAAQH;QACRI,gBAAgB;IAClB;IAEA,wDAAwD;IACxDX,UAAU;QACR,MAAMY,eAAeH,KAAKI,KAAK,CAAC,CAACC;YAC/BN,SAASM;QACX;QACA,OAAO,IAAMF,aAAaG,WAAW;IACvC,GAAG;QAACN;QAAMD;KAAS;IAEnB,qBACE,KAACN;QACCc,SAASP,KAAKO,OAAO;QACrBX,cAAcA;QACdC,MAAK;QACLF,QAAQA;;AAGd"}
1
+ {"version":3,"sources":["../../src/components/MessagesField.tsx"],"sourcesContent":["'use client';\n\nimport { useField } from '@payloadcms/ui';\nimport type { JSONFieldClientProps } from 'payload';\nimport { useEffect, useRef } from 'react';\nimport { useForm } from 'react-hook-form';\nimport type { Messages, MessagesSchema } from '@/types';\nimport { MessagesTree } from './layout/MessagesTree';\n\nexport interface MessagesFieldProps {\n readonly schema: MessagesSchema;\n readonly hiddenGroups?: string[];\n}\n\n/**\n * Payload JSON field client component that bridges the virtual `_intlMessages`\n * field with the existing MessagesFormProvider / MessagesTree component tree.\n */\nexport function MessagesField({\n schema,\n hiddenGroups,\n path,\n}: JSONFieldClientProps & MessagesFieldProps) {\n const { value, setValue } = useField<Messages>({ path });\n const lastPushedRef = useRef(value);\n\n const form = useForm<Messages>({\n values: value,\n reValidateMode: 'onBlur',\n });\n\n // When form values change, push back to Payload's field.\n // Guard against the circular loop: Payload value → useForm syncs → watch\n // fires → setValue → Payload value changes → repeat. Only call setValue\n // when the form produced genuinely new data.\n useEffect(() => {\n const subscription = form.watch((formValues) => {\n const json = JSON.stringify(formValues);\n if (json !== JSON.stringify(lastPushedRef.current)) {\n lastPushedRef.current = formValues as Messages;\n setValue(formValues);\n }\n });\n return () => subscription.unsubscribe();\n }, [form, setValue]);\n\n return (\n <MessagesTree\n control={form.control}\n hiddenGroups={hiddenGroups}\n path=\"\"\n schema={schema}\n />\n );\n}\n"],"names":["useField","useEffect","useRef","useForm","MessagesTree","MessagesField","schema","hiddenGroups","path","value","setValue","lastPushedRef","form","values","reValidateMode","subscription","watch","formValues","json","JSON","stringify","current","unsubscribe","control"],"mappings":"AAAA;;AAEA,SAASA,QAAQ,QAAQ,iBAAiB;AAE1C,SAASC,SAAS,EAAEC,MAAM,QAAQ,QAAQ;AAC1C,SAASC,OAAO,QAAQ,kBAAkB;AAE1C,SAASC,YAAY,QAAQ,wBAAwB;AAOrD;;;CAGC,GACD,OAAO,SAASC,cAAc,EAC5BC,MAAM,EACNC,YAAY,EACZC,IAAI,EACsC;IAC1C,MAAM,EAAEC,KAAK,EAAEC,QAAQ,EAAE,GAAGV,SAAmB;QAAEQ;IAAK;IACtD,MAAMG,gBAAgBT,OAAOO;IAE7B,MAAMG,OAAOT,QAAkB;QAC7BU,QAAQJ;QACRK,gBAAgB;IAClB;IAEA,yDAAyD;IACzD,yEAAyE;IACzE,wEAAwE;IACxE,6CAA6C;IAC7Cb,UAAU;QACR,MAAMc,eAAeH,KAAKI,KAAK,CAAC,CAACC;YAC/B,MAAMC,OAAOC,KAAKC,SAAS,CAACH;YAC5B,IAAIC,SAASC,KAAKC,SAAS,CAACT,cAAcU,OAAO,GAAG;gBAClDV,cAAcU,OAAO,GAAGJ;gBACxBP,SAASO;YACX;QACF;QACA,OAAO,IAAMF,aAAaO,WAAW;IACvC,GAAG;QAACV;QAAMF;KAAS;IAEnB,qBACE,KAACN;QACCmB,SAASX,KAAKW,OAAO;QACrBhB,cAAcA;QACdC,MAAK;QACLF,QAAQA;;AAGd"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payload-intl",
3
- "version": "1.4.4",
3
+ "version": "1.4.6",
4
4
  "description": "Payload Plugin for I18N using ICU Messages",
5
5
  "keywords": [
6
6
  "payload",
@@ -53,7 +53,7 @@
53
53
  "lodash-es": "^4.17.21",
54
54
  "react-hook-form": "^7.58.1",
55
55
  "zod": "4.3.5",
56
- "@davincicoding/payload-plugin-kit": "0.0.7"
56
+ "@davincicoding/payload-plugin-kit": "0.1.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@payloadcms/richtext-lexical": "3.72.0",
@@ -87,11 +87,11 @@
87
87
  },
88
88
  "scripts": {
89
89
  "prebuild": "pnpm check:types",
90
- "build": "plugin-build",
90
+ "build": "plugin-kit build",
91
91
  "check:types": "tsc --noEmit",
92
92
  "dev": "next dev dev",
93
- "dev:build": "plugin-build --watch",
94
- "generate:types": "generate-types --opt uploadCollection=uploads",
93
+ "dev:build": "plugin-kit build --watch",
94
+ "generate:types": "plugin-kit generate-types --options uploadCollection=uploads",
95
95
  "lint": "biome check .",
96
96
  "lint:fix": "biome check --write .",
97
97
  "test": "vitest run",