payload-intl 0.1.0 → 0.2.1

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 (55) hide show
  1. package/dist/components/MessageController.js +11 -11
  2. package/dist/components/MessageController.js.map +1 -1
  3. package/dist/components/MessagesForm.d.ts +2 -3
  4. package/dist/components/MessagesForm.js +100 -93
  5. package/dist/components/MessagesForm.js.map +1 -1
  6. package/dist/components/inputs/InputWrapper.js +13 -13
  7. package/dist/components/inputs/InputWrapper.js.map +1 -1
  8. package/dist/components/inputs/LexicalInput.d.ts +19 -0
  9. package/dist/components/inputs/LexicalInput.js +90 -0
  10. package/dist/components/inputs/LexicalInput.js.map +1 -0
  11. package/dist/components/inputs/variables/editors/PluralVariableEditor.js.map +1 -1
  12. package/dist/components/inputs/variables/editors/SelectVariableEditor.js.map +1 -1
  13. package/dist/components/inputs/variables/editors/TagVariableEditor.js.map +1 -1
  14. package/dist/components/inputs/variables/pickers/NumericVariablePicker.js.map +1 -1
  15. package/dist/components/layout/MessageField.js +21 -18
  16. package/dist/components/layout/MessageField.js.map +1 -1
  17. package/dist/components/layout/MessagesTree.js.map +1 -1
  18. package/dist/context/messages-form.d.ts +2 -4
  19. package/dist/context/messages-form.js +10 -11
  20. package/dist/context/messages-form.js.map +1 -1
  21. package/dist/exports/view.d.ts +2 -3
  22. package/dist/exports/view.js +31 -33
  23. package/dist/exports/view.js.map +1 -1
  24. package/dist/index.d.ts +1 -1
  25. package/dist/index.js +40 -23
  26. package/dist/index.js.map +1 -1
  27. package/dist/requests/fetchMessages.js +22 -19
  28. package/dist/requests/fetchMessages.js.map +1 -1
  29. package/dist/styles.css +1 -1
  30. package/dist/types.d.ts +0 -8
  31. package/dist/utils/error-handling.d.ts +1 -0
  32. package/dist/utils/error-handling.js +13 -0
  33. package/dist/utils/error-handling.js.map +1 -0
  34. package/dist/utils/schema.js.map +1 -1
  35. package/dist/utils/validate.d.ts +1 -1
  36. package/dist/utils/validate.js.map +1 -1
  37. package/package.json +24 -34
  38. package/dist/components/inputs/RichTextInput.d.ts +0 -8
  39. package/dist/components/inputs/RichTextInput.js +0 -85
  40. package/dist/components/inputs/RichTextInput.js.map +0 -1
  41. package/dist/components/inputs/toolbar/AlignmentControls.d.ts +0 -5
  42. package/dist/components/inputs/toolbar/AlignmentControls.js +0 -62
  43. package/dist/components/inputs/toolbar/AlignmentControls.js.map +0 -1
  44. package/dist/components/inputs/toolbar/BlockElementSelect.d.ts +0 -5
  45. package/dist/components/inputs/toolbar/BlockElementSelect.js +0 -135
  46. package/dist/components/inputs/toolbar/BlockElementSelect.js.map +0 -1
  47. package/dist/components/inputs/toolbar/LinkEditor.d.ts +0 -58
  48. package/dist/components/inputs/toolbar/LinkEditor.js +0 -242
  49. package/dist/components/inputs/toolbar/LinkEditor.js.map +0 -1
  50. package/dist/components/inputs/toolbar/MarkControls.d.ts +0 -5
  51. package/dist/components/inputs/toolbar/MarkControls.js +0 -48
  52. package/dist/components/inputs/toolbar/MarkControls.js.map +0 -1
  53. package/dist/components/inputs/toolbar/RichTextToolbar.d.ts +0 -6
  54. package/dist/components/inputs/toolbar/RichTextToolbar.js +0 -35
  55. package/dist/components/inputs/toolbar/RichTextToolbar.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"NumericVariablePicker.js","sources":["../../../../../src/components/inputs/variables/pickers/NumericVariablePicker.tsx"],"sourcesContent":["import { ToggleGroup } from \"radix-ui\";\nimport { useEffect, useRef, useState } from \"react\";\n\nimport type { NumberElement, PluralElement } from \"@/types\";\nimport { isNumberElement, isPluralElement } from \"@/utils/guards\";\n\nimport { PluralVariableEditor } from \"../editors/PluralVariableEditor\";\n\nconst NUMERIC_TYPES = [\n \"number\",\n \"plural\",\n // \"selectordinal\"\n] as const;\n\ntype NumericType = (typeof NUMERIC_TYPES)[number];\n\nexport interface NumericVariablePickerProps {\n element: NumberElement | PluralElement;\n onUpdate: (value: string) => void;\n}\n\nexport function NumericVariablePicker({\n element,\n onUpdate,\n}: NumericVariablePickerProps) {\n const [type, setType] = useState<NumericType | undefined>(() => {\n if (isNumberElement(element)) return \"number\";\n if (isPluralElement(element)) return \"plural\";\n return undefined;\n });\n const getValueRef = useRef<{ getValue: () => string }>(null);\n\n useEffect(() => {\n return () => {\n if (!getValueRef.current) return;\n onUpdate(getValueRef.current.getValue());\n };\n }, []);\n\n return (\n <div className=\"\">\n <ToggleGroup.Root\n type=\"single\"\n className=\"flex bg-elevation-100\"\n onValueChange={(value) => setType(value as NumericType)}\n value={type}\n >\n {NUMERIC_TYPES.map((type) => (\n <ToggleGroup.Item\n key={type}\n value={type}\n className=\"flex-1 border-none data-[state=off]:cursor-pointer data-[state=off]:opacity-50 data-[state=off]:hover:opacity-100 data-[state=on]:bg-elevation-800 data-[state=on]:text-elevation-0\"\n >\n {type}\n </ToggleGroup.Item>\n ))}\n </ToggleGroup.Root>\n\n <div className=\"p-3\">\n {type === \"plural\" && (\n <PluralVariableEditor\n variableName={element.value}\n element={isPluralElement(element) ? element : undefined}\n ref={getValueRef}\n />\n )}\n </div>\n </div>\n );\n}\n"],"names":["NUMERIC_TYPES","NumericVariablePicker","element","onUpdate","type","setType","useState","isNumberElement","isPluralElement","getValueRef","useRef","useEffect","jsxs","jsx","ToggleGroup","value","PluralVariableEditor"],"mappings":";;;;;AAQA,MAAMA,IAAgB;AAAA,EACpB;AAAA,EACA;AAAA;AAEF;AASO,SAASC,EAAsB;AAAA,EACpC,SAAAC;AAAA,EACA,UAAAC;AACF,GAA+B;AAC7B,QAAM,CAACC,GAAMC,CAAO,IAAIC,EAAkC,MAAM;AAC9D,QAAIC,EAAgBL,CAAO,EAAG,QAAO;AACrC,QAAIM,EAAgBN,CAAO,EAAG,QAAO;AAAA,EAEvC,CAAC,GACKO,IAAcC,EAAmC,IAAI;AAE3D,SAAAC,EAAU,MACD,MAAM;AACX,IAAKF,EAAY,WACjBN,EAASM,EAAY,QAAQ,UAAU;AAAA,EACzC,GACC,CAAA,CAAE,GAGH,gBAAAG,EAAC,OAAA,EAAI,WAAU,IACb,UAAA;AAAA,IAAA,gBAAAC;AAAA,MAACC,EAAY;AAAA,MAAZ;AAAA,QACC,MAAK;AAAA,QACL,WAAU;AAAA,QACV,eAAe,CAACC,MAAUV,EAAQU,CAAoB;AAAA,QACtD,OAAOX;AAAA,QAEN,UAAAJ,EAAc,IAAI,CAACI,MAClB,gBAAAS;AAAA,UAACC,EAAY;AAAA,UAAZ;AAAA,YAEC,OAAOV;AAAAA,YACP,WAAU;AAAA,YAET,UAAAA;AAAAA,UAAA;AAAA,UAJIA;AAAAA,QAAA,CAMR;AAAA,MAAA;AAAA,IAAA;AAAA,IAGH,gBAAAS,EAAC,OAAA,EAAI,WAAU,OACZ,gBAAS,YACR,gBAAAA;AAAA,MAACG;AAAA,MAAA;AAAA,QACC,cAAcd,EAAQ;AAAA,QACtB,SAASM,EAAgBN,CAAO,IAAIA,IAAU;AAAA,QAC9C,KAAKO;AAAA,MAAA;AAAA,IAAA,EACP,CAEJ;AAAA,EAAA,GACF;AAEJ;"}
1
+ {"version":3,"file":"NumericVariablePicker.js","sources":["../../../../../src/components/inputs/variables/pickers/NumericVariablePicker.tsx"],"sourcesContent":["import type { NumberElement, PluralElement } from \"@/types\";\nimport { ToggleGroup } from \"radix-ui\";\nimport { useEffect, useRef, useState } from \"react\";\n\nimport { isNumberElement, isPluralElement } from \"@/utils/guards\";\n\nimport { PluralVariableEditor } from \"../editors/PluralVariableEditor\";\n\nconst NUMERIC_TYPES = [\n \"number\",\n \"plural\",\n // \"selectordinal\"\n] as const;\n\ntype NumericType = (typeof NUMERIC_TYPES)[number];\n\nexport interface NumericVariablePickerProps {\n element: NumberElement | PluralElement;\n onUpdate: (value: string) => void;\n}\n\nexport function NumericVariablePicker({\n element,\n onUpdate,\n}: NumericVariablePickerProps) {\n const [type, setType] = useState<NumericType | undefined>(() => {\n if (isNumberElement(element)) return \"number\";\n if (isPluralElement(element)) return \"plural\";\n return undefined;\n });\n const getValueRef = useRef<{ getValue: () => string }>(null);\n\n useEffect(() => {\n return () => {\n if (!getValueRef.current) return;\n onUpdate(getValueRef.current.getValue());\n };\n }, []);\n\n return (\n <div className=\"\">\n <ToggleGroup.Root\n type=\"single\"\n className=\"flex bg-elevation-100\"\n onValueChange={(value) => setType(value as NumericType)}\n value={type}\n >\n {NUMERIC_TYPES.map((type) => (\n <ToggleGroup.Item\n key={type}\n value={type}\n className=\"flex-1 border-none data-[state=off]:cursor-pointer data-[state=off]:opacity-50 data-[state=off]:hover:opacity-100 data-[state=on]:bg-elevation-800 data-[state=on]:text-elevation-0\"\n >\n {type}\n </ToggleGroup.Item>\n ))}\n </ToggleGroup.Root>\n\n <div className=\"p-3\">\n {type === \"plural\" && (\n <PluralVariableEditor\n variableName={element.value}\n element={isPluralElement(element) ? element : undefined}\n ref={getValueRef}\n />\n )}\n </div>\n </div>\n );\n}\n"],"names":["NUMERIC_TYPES","NumericVariablePicker","element","onUpdate","type","setType","useState","isNumberElement","isPluralElement","getValueRef","useRef","useEffect","jsxs","jsx","ToggleGroup","value","PluralVariableEditor"],"mappings":";;;;;AAQA,MAAMA,IAAgB;AAAA,EACpB;AAAA,EACA;AAAA;AAEF;AASO,SAASC,EAAsB;AAAA,EACpC,SAAAC;AAAA,EACA,UAAAC;AACF,GAA+B;AAC7B,QAAM,CAACC,GAAMC,CAAO,IAAIC,EAAkC,MAAM;AAC9D,QAAIC,EAAgBL,CAAO,EAAG,QAAO;AACrC,QAAIM,EAAgBN,CAAO,EAAG,QAAO;AAAA,EAEvC,CAAC,GACKO,IAAcC,EAAmC,IAAI;AAE3D,SAAAC,EAAU,MACD,MAAM;AACX,IAAKF,EAAY,WACjBN,EAASM,EAAY,QAAQ,UAAU;AAAA,EACzC,GACC,CAAA,CAAE,GAGH,gBAAAG,EAAC,OAAA,EAAI,WAAU,IACb,UAAA;AAAA,IAAA,gBAAAC;AAAA,MAACC,EAAY;AAAA,MAAZ;AAAA,QACC,MAAK;AAAA,QACL,WAAU;AAAA,QACV,eAAe,CAACC,MAAUV,EAAQU,CAAoB;AAAA,QACtD,OAAOX;AAAA,QAEN,UAAAJ,EAAc,IAAI,CAACI,MAClB,gBAAAS;AAAA,UAACC,EAAY;AAAA,UAAZ;AAAA,YAEC,OAAOV;AAAAA,YACP,WAAU;AAAA,YAET,UAAAA;AAAAA,UAAA;AAAA,UAJIA;AAAAA,QAAA,CAMR;AAAA,MAAA;AAAA,IAAA;AAAA,IAGH,gBAAAS,EAAC,OAAA,EAAI,WAAU,OACZ,gBAAS,YACR,gBAAAA;AAAA,MAACG;AAAA,MAAA;AAAA,QACC,cAAcd,EAAQ;AAAA,QACtB,SAASM,EAAgBN,CAAO,IAAIA,IAAU;AAAA,QAC9C,KAAKO;AAAA,MAAA;AAAA,IAAA,EACP,CAEJ;AAAA,EAAA,GACF;AAEJ;"}
@@ -1,24 +1,24 @@
1
- import { jsxs as c, jsx as a } from "react/jsx-runtime";
2
- import { useMemo as n } from "react";
3
- import { useMessagesForm as v } from "../../context/messages-form.js";
4
- import { cn as d } from "../../utils/cn.js";
5
- import { parseMessageSchema as f } from "../../utils/schema.js";
1
+ import { jsxs as f, jsx as i } from "react/jsx-runtime";
2
+ import { useMemo as p } from "react";
3
+ import { useMessagesForm as d } from "../../context/messages-form.js";
4
+ import { cn as n } from "../../utils/cn.js";
5
+ import { parseMessageSchema as v } from "../../utils/schema.js";
6
6
  import { createValidator as x } from "../../utils/validate.js";
7
- import { MessageController as p } from "../MessageController.js";
7
+ import { MessageController as c } from "../MessageController.js";
8
8
  function w({
9
- schema: i,
9
+ schema: o,
10
10
  messageKey: s,
11
11
  path: t,
12
12
  className: l
13
13
  }) {
14
- const { locales: r } = v(), e = n(() => f(i), [i]), m = n(
14
+ const { locales: r } = d(), e = p(() => v(o), [o]), m = p(
15
15
  () => x(e.variables),
16
16
  [e.variables]
17
17
  );
18
- return /* @__PURE__ */ c("div", { className: d("", l), children: [
19
- e.description && /* @__PURE__ */ a("p", { children: e.description }),
20
- r.length === 1 ? /* @__PURE__ */ a(
21
- p,
18
+ return /* @__PURE__ */ f("div", { className: n("", l), children: [
19
+ e.description && /* @__PURE__ */ i("p", { children: e.description }),
20
+ r.length === 1 ? /* @__PURE__ */ i(
21
+ c,
22
22
  {
23
23
  className: l,
24
24
  type: e.type,
@@ -27,18 +27,21 @@ function w({
27
27
  name: [r[0], t, s].join("."),
28
28
  validate: m
29
29
  }
30
- ) : /* @__PURE__ */ a("div", { className: "-mx-3 flex min-w-0 gap-4 overflow-x-auto overscroll-x-none px-3", children: r.map((o) => /* @__PURE__ */ a(
31
- p,
30
+ ) : /* @__PURE__ */ i("div", { className: n("-mx-3 flex min-w-0 gap-4 px-3", {
31
+ "overflow-x-auto": e.type === "icu",
32
+ "flex-col": e.type === "rich"
33
+ }), children: r.map((a) => /* @__PURE__ */ i(
34
+ c,
32
35
  {
33
36
  className: "flex-1",
34
37
  type: e.type,
35
- label: o.toUpperCase(),
36
- locale: o,
38
+ label: a.toUpperCase(),
39
+ locale: a,
37
40
  variables: e.variables,
38
- name: [o, t, s].join("."),
41
+ name: [a, t, s].join("."),
39
42
  validate: m
40
43
  },
41
- o
44
+ a
42
45
  )) })
43
46
  ] });
44
47
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MessageField.js","sources":["../../../src/components/layout/MessageField.tsx"],"sourcesContent":["import type { MessageSchema } from \"@/types\";\nimport { useMemo } from \"react\";\n\nimport { useMessagesForm } from \"@/context/messages-form\";\nimport { cn } from \"@/utils/cn\";\nimport { toWords } from \"@/utils/format\";\nimport { parseMessageSchema } from \"@/utils/schema\";\nimport { createValidator } from \"@/utils/validate\";\n\nimport { MessageController } from \"../MessageController\";\n\ninterface MessageFieldProps {\n schema: MessageSchema;\n messageKey: string;\n path: string;\n className?: string;\n}\n\nexport function MessageField({\n schema,\n messageKey,\n path,\n className,\n}: MessageFieldProps): React.ReactNode {\n const { locales } = useMessagesForm();\n\n const config = useMemo(() => parseMessageSchema(schema), [schema]);\n\n const validator = useMemo(\n () => createValidator(config.variables),\n [config.variables],\n );\n\n return (\n <div className={cn(\"\", className)}>\n {config.description && <p>{config.description}</p>}\n\n {locales.length === 1 ? (\n <MessageController\n className={className}\n type={config.type}\n variables={config.variables}\n locale={locales[0]}\n name={[locales[0], path, messageKey].join(\".\")}\n validate={validator}\n />\n ) : (\n <div className=\"-mx-3 flex min-w-0 gap-4 overflow-x-auto overscroll-x-none px-3\">\n {locales.map((locale) => (\n <MessageController\n key={locale}\n className=\"flex-1\"\n type={config.type}\n label={locale.toUpperCase()}\n locale={locale}\n variables={config.variables}\n name={[locale, path, messageKey].join(\".\")}\n validate={validator}\n />\n ))}\n </div>\n )}\n </div>\n );\n}\n"],"names":["MessageField","schema","messageKey","path","className","locales","useMessagesForm","config","useMemo","parseMessageSchema","validator","createValidator","cn","jsx","MessageController","locale"],"mappings":";;;;;;;AAkBO,SAASA,EAAa;AAAA,EAC3B,QAAAC;AAAA,EACA,YAAAC;AAAA,EACA,MAAAC;AAAA,EACA,WAAAC;AACF,GAAuC;AACrC,QAAM,EAAE,SAAAC,EAAA,IAAYC,EAAA,GAEdC,IAASC,EAAQ,MAAMC,EAAmBR,CAAM,GAAG,CAACA,CAAM,CAAC,GAE3DS,IAAYF;AAAA,IAChB,MAAMG,EAAgBJ,EAAO,SAAS;AAAA,IACtC,CAACA,EAAO,SAAS;AAAA,EAAA;AAGnB,2BACG,OAAA,EAAI,WAAWK,EAAG,IAAIR,CAAS,GAC7B,UAAA;AAAA,IAAAG,EAAO,eAAe,gBAAAM,EAAC,KAAA,EAAG,UAAAN,EAAO,aAAY;AAAA,IAE7CF,EAAQ,WAAW,IAClB,gBAAAQ;AAAA,MAACC;AAAA,MAAA;AAAA,QACC,WAAAV;AAAA,QACA,MAAMG,EAAO;AAAA,QACb,WAAWA,EAAO;AAAA,QAClB,QAAQF,EAAQ,CAAC;AAAA,QACjB,MAAM,CAACA,EAAQ,CAAC,GAAGF,GAAMD,CAAU,EAAE,KAAK,GAAG;AAAA,QAC7C,UAAUQ;AAAA,MAAA;AAAA,IAAA,sBAGX,OAAA,EAAI,WAAU,mEACZ,UAAAL,EAAQ,IAAI,CAACU,MACZ,gBAAAF;AAAA,MAACC;AAAA,MAAA;AAAA,QAEC,WAAU;AAAA,QACV,MAAMP,EAAO;AAAA,QACb,OAAOQ,EAAO,YAAA;AAAA,QACd,QAAAA;AAAA,QACA,WAAWR,EAAO;AAAA,QAClB,MAAM,CAACQ,GAAQZ,GAAMD,CAAU,EAAE,KAAK,GAAG;AAAA,QACzC,UAAUQ;AAAA,MAAA;AAAA,MAPLK;AAAA,IAAA,CASR,EAAA,CACH;AAAA,EAAA,GAEJ;AAEJ;"}
1
+ {"version":3,"file":"MessageField.js","sources":["../../../src/components/layout/MessageField.tsx"],"sourcesContent":["import type { MessageSchema } from \"@/types\";\nimport { useMemo } from \"react\";\n\nimport { useMessagesForm } from \"@/context/messages-form\";\nimport { cn } from \"@/utils/cn\";\nimport { toWords } from \"@/utils/format\";\nimport { parseMessageSchema } from \"@/utils/schema\";\nimport { createValidator } from \"@/utils/validate\";\n\nimport { LexicalInput } from \"../inputs/LexicalInput\";\nimport { MessageController } from \"../MessageController\";\n\ninterface MessageFieldProps {\n schema: MessageSchema;\n messageKey: string;\n path: string;\n className?: string;\n}\n\nexport function MessageField({\n schema,\n messageKey,\n path,\n className,\n}: MessageFieldProps): React.ReactNode {\n const { locales } = useMessagesForm();\n\n const config = useMemo(() => parseMessageSchema(schema), [schema]);\n\n const validator = useMemo(\n () => createValidator(config.variables),\n [config.variables],\n );\n\n return (\n <div className={cn(\"\", className)}>\n {config.description && <p>{config.description}</p>}\n\n {locales.length === 1 ? (\n <MessageController\n className={className}\n type={config.type}\n variables={config.variables}\n locale={locales[0]}\n name={[locales[0], path, messageKey].join(\".\")}\n validate={validator}\n />\n ) : (\n <div className={cn(\"-mx-3 flex min-w-0 gap-4 px-3\", {\n \"overflow-x-auto\": config.type === \"icu\",\n \"flex-col\": config.type === \"rich\",\n })}>\n {locales.map((locale) => (\n <MessageController\n key={locale}\n className=\"flex-1\"\n type={config.type}\n label={locale.toUpperCase()}\n locale={locale}\n variables={config.variables}\n name={[locale, path, messageKey].join(\".\")}\n validate={validator}\n />\n ))}\n </div>\n )}\n </div>\n );\n}\n"],"names":["MessageField","schema","messageKey","path","className","locales","useMessagesForm","config","useMemo","parseMessageSchema","validator","createValidator","cn","jsx","MessageController","locale"],"mappings":";;;;;;;AAmBO,SAASA,EAAa;AAAA,EAC3B,QAAAC;AAAA,EACA,YAAAC;AAAA,EACA,MAAAC;AAAA,EACA,WAAAC;AACF,GAAuC;AACrC,QAAM,EAAE,SAAAC,EAAA,IAAYC,EAAA,GAEdC,IAASC,EAAQ,MAAMC,EAAmBR,CAAM,GAAG,CAACA,CAAM,CAAC,GAE3DS,IAAYF;AAAA,IAChB,MAAMG,EAAgBJ,EAAO,SAAS;AAAA,IACtC,CAACA,EAAO,SAAS;AAAA,EAAA;AAGnB,2BACG,OAAA,EAAI,WAAWK,EAAG,IAAIR,CAAS,GAC7B,UAAA;AAAA,IAAAG,EAAO,eAAe,gBAAAM,EAAC,KAAA,EAAG,UAAAN,EAAO,aAAY;AAAA,IAE7CF,EAAQ,WAAW,IAClB,gBAAAQ;AAAA,MAACC;AAAA,MAAA;AAAA,QACC,WAAAV;AAAA,QACA,MAAMG,EAAO;AAAA,QACb,WAAWA,EAAO;AAAA,QAClB,QAAQF,EAAQ,CAAC;AAAA,QACjB,MAAM,CAACA,EAAQ,CAAC,GAAGF,GAAMD,CAAU,EAAE,KAAK,GAAG;AAAA,QAC7C,UAAUQ;AAAA,MAAA;AAAA,IAAA,IAGZ,gBAAAG,EAAC,OAAA,EAAI,WAAWD,EAAG,iCAAiC;AAAA,MAClD,mBAAmBL,EAAO,SAAS;AAAA,MACnC,YAAYA,EAAO,SAAS;AAAA,IAAA,CAC7B,GACE,UAAAF,EAAQ,IAAI,CAACU,MACZ,gBAAAF;AAAA,MAACC;AAAA,MAAA;AAAA,QAEC,WAAU;AAAA,QACV,MAAMP,EAAO;AAAA,QACb,OAAOQ,EAAO,YAAA;AAAA,QACd,QAAAA;AAAA,QACA,WAAWR,EAAO;AAAA,QAClB,MAAM,CAACQ,GAAQZ,GAAMD,CAAU,EAAE,KAAK,GAAG;AAAA,QACzC,UAAUQ;AAAA,MAAA;AAAA,MAPLK;AAAA,IAAA,CASR,EAAA,CACH;AAAA,EAAA,GAEJ;AAEJ;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MessagesTree.js","sources":["../../../src/components/layout/MessagesTree.tsx"],"sourcesContent":["import type { Messages } from \"@/types\";\nimport { Collapsible } from \"@payloadcms/ui\";\nimport { get } from \"lodash-es\";\nimport { useCallback } from \"react\";\nimport { useFormState } from \"react-hook-form\";\n\nimport { useMessagesForm } from \"@/context/messages-form\";\nimport { cn } from \"@/utils/cn\";\nimport { toWords } from \"@/utils/format\";\n\nimport { MessageField } from \"./MessageField\";\n\ninterface MessagesTreeProps {\n path: string;\n nestingLevel: number;\n schema: Messages;\n className?: string;\n}\n\n// TODO fix sticky position on single locale form\n\nexport function MessagesTree({\n path,\n schema,\n nestingLevel = 0,\n className,\n}: MessagesTreeProps): React.ReactNode {\n const { control, locales } = useMessagesForm();\n const { errors } = useFormState({ control });\n\n const hasErrors = useCallback(\n (key: string) => {\n return locales.some(\n (locale) => get(errors, [locale, path, key].join(\".\")) !== undefined,\n );\n },\n [errors, locales, path],\n );\n\n return (\n <div className={cn(\"grid gap-6\", className)}>\n {Object.entries(schema).map(([key, value]) => (\n <div\n key={key}\n className=\"grid min-w-0\"\n style={\n {\n [\"--nesting-level\"]: nestingLevel,\n } as React.CSSProperties\n }\n >\n <Collapsible\n className=\"messages-tree-collapsible min-w-0\"\n header={\n <span\n className={cn(\"text-xl\", {\n \"text-error\": hasErrors(key),\n })}\n >\n {toWords(key)}\n </span>\n }\n >\n {typeof value === \"string\" ? (\n <MessageField\n className=\"min-w-0\"\n schema={value}\n key={key}\n messageKey={key}\n path={path}\n />\n ) : (\n <MessagesTree\n nestingLevel={nestingLevel + 1}\n path={[path, key].join(\".\")}\n schema={value}\n />\n )}\n </Collapsible>\n </div>\n ))}\n </div>\n );\n}\n"],"names":["MessagesTree","path","schema","nestingLevel","className","control","locales","useMessagesForm","errors","useFormState","hasErrors","useCallback","key","locale","get","cn","value","jsx","Collapsible","MessageField"],"mappings":";;;;;;;;;AAqBO,SAASA,EAAa;AAAA,EAC3B,MAAAC;AAAA,EACA,QAAAC;AAAA,EACA,cAAAC,IAAe;AAAA,EACf,WAAAC;AACF,GAAuC;AACrC,QAAM,EAAE,SAAAC,GAAS,SAAAC,EAAA,IAAYC,EAAA,GACvB,EAAE,QAAAC,EAAA,IAAWC,EAAa,EAAE,SAAAJ,GAAS,GAErCK,IAAYC;AAAA,IAChB,CAACC,MACQN,EAAQ;AAAA,MACb,CAACO,MAAWC,EAAIN,GAAQ,CAACK,GAAQZ,GAAMW,CAAG,EAAE,KAAK,GAAG,CAAC,MAAM;AAAA,IAAA;AAAA,IAG/D,CAACJ,GAAQF,GAASL,CAAI;AAAA,EAAA;AAGxB,2BACG,OAAA,EAAI,WAAWc,EAAG,cAAcX,CAAS,GACvC,UAAA,OAAO,QAAQF,CAAM,EAAE,IAAI,CAAC,CAACU,GAAKI,CAAK,MACtC,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MAEC,WAAU;AAAA,MACV,OACE;AAAA,QACG,mBAAoBd;AAAA,MAAA;AAAA,MAIzB,UAAA,gBAAAc;AAAA,QAACC;AAAA,QAAA;AAAA,UACC,WAAU;AAAA,UACV,QACE,gBAAAD;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,WAAWF,EAAG,WAAW;AAAA,gBACvB,cAAcL,EAAUE,CAAG;AAAA,cAAA,CAC5B;AAAA,cAEA,YAAQA,CAAG;AAAA,YAAA;AAAA,UAAA;AAAA,UAIf,UAAA,OAAOI,KAAU,WAChB,gBAAAC;AAAA,YAACE;AAAA,YAAA;AAAA,cACC,WAAU;AAAA,cACV,QAAQH;AAAA,cAER,YAAYJ;AAAA,cACZ,MAAAX;AAAA,YAAA;AAAA,YAFKW;AAAA,UAAA,IAKP,gBAAAK;AAAA,YAACjB;AAAA,YAAA;AAAA,cACC,cAAcG,IAAe;AAAA,cAC7B,MAAM,CAACF,GAAMW,CAAG,EAAE,KAAK,GAAG;AAAA,cAC1B,QAAQI;AAAA,YAAA;AAAA,UAAA;AAAA,QACV;AAAA,MAAA;AAAA,IAEJ;AAAA,IAnCKJ;AAAA,EAAA,CAqCR,GACH;AAEJ;"}
1
+ {"version":3,"file":"MessagesTree.js","sources":["../../../src/components/layout/MessagesTree.tsx"],"sourcesContent":["import type { Messages } from \"@/types\";\nimport { Collapsible } from \"@payloadcms/ui\";\nimport { get } from \"lodash-es\";\nimport { useCallback } from \"react\";\nimport { useFormState } from \"react-hook-form\";\n\nimport { useMessagesForm } from \"@/context/messages-form\";\nimport { cn } from \"@/utils/cn\";\nimport { toWords } from \"@/utils/format\";\n\nimport { LexicalInput } from \"../inputs/LexicalInput\";\nimport { MessageField } from \"./MessageField\";\n\ninterface MessagesTreeProps {\n path: string;\n nestingLevel: number;\n schema: Messages;\n className?: string;\n}\n\n// TODO fix sticky position on single locale form\n\nexport function MessagesTree({\n path,\n schema,\n nestingLevel = 0,\n className,\n}: MessagesTreeProps): React.ReactNode {\n const { control, locales } = useMessagesForm();\n const { errors } = useFormState({ control });\n\n const hasErrors = useCallback(\n (key: string) => {\n return locales.some(\n (locale) => get(errors, [locale, path, key].join(\".\")) !== undefined,\n );\n },\n [errors, locales, path],\n );\n\n return (\n <div className={cn(\"grid gap-6\", className)}>\n {Object.entries(schema).map(([key, value]) => (\n <div\n key={key}\n className=\"grid min-w-0\"\n style={\n {\n [\"--nesting-level\"]: nestingLevel,\n } as React.CSSProperties\n }\n >\n <Collapsible\n className=\"messages-tree-collapsible min-w-0\"\n header={\n <span\n className={cn(\"text-xl\", {\n \"text-error\": hasErrors(key),\n })}\n >\n {toWords(key)}\n </span>\n }\n >\n {typeof value === \"string\" ? (\n <MessageField\n className=\"min-w-0\"\n schema={value}\n key={key}\n messageKey={key}\n path={path}\n />\n ) : (\n <MessagesTree\n nestingLevel={nestingLevel + 1}\n path={[path, key].join(\".\")}\n schema={value}\n />\n )}\n </Collapsible>\n </div>\n ))}\n </div>\n );\n}\n"],"names":["MessagesTree","path","schema","nestingLevel","className","control","locales","useMessagesForm","errors","useFormState","hasErrors","useCallback","key","locale","get","cn","value","jsx","Collapsible","MessageField"],"mappings":";;;;;;;;;AAsBO,SAASA,EAAa;AAAA,EAC3B,MAAAC;AAAA,EACA,QAAAC;AAAA,EACA,cAAAC,IAAe;AAAA,EACf,WAAAC;AACF,GAAuC;AACrC,QAAM,EAAE,SAAAC,GAAS,SAAAC,EAAA,IAAYC,EAAA,GACvB,EAAE,QAAAC,EAAA,IAAWC,EAAa,EAAE,SAAAJ,GAAS,GAErCK,IAAYC;AAAA,IAChB,CAACC,MACQN,EAAQ;AAAA,MACb,CAACO,MAAWC,EAAIN,GAAQ,CAACK,GAAQZ,GAAMW,CAAG,EAAE,KAAK,GAAG,CAAC,MAAM;AAAA,IAAA;AAAA,IAG/D,CAACJ,GAAQF,GAASL,CAAI;AAAA,EAAA;AAGxB,2BACG,OAAA,EAAI,WAAWc,EAAG,cAAcX,CAAS,GACvC,UAAA,OAAO,QAAQF,CAAM,EAAE,IAAI,CAAC,CAACU,GAAKI,CAAK,MACtC,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MAEC,WAAU;AAAA,MACV,OACE;AAAA,QACG,mBAAoBd;AAAA,MAAA;AAAA,MAIzB,UAAA,gBAAAc;AAAA,QAACC;AAAA,QAAA;AAAA,UACC,WAAU;AAAA,UACV,QACE,gBAAAD;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,WAAWF,EAAG,WAAW;AAAA,gBACvB,cAAcL,EAAUE,CAAG;AAAA,cAAA,CAC5B;AAAA,cAEA,YAAQA,CAAG;AAAA,YAAA;AAAA,UAAA;AAAA,UAIf,UAAA,OAAOI,KAAU,WAChB,gBAAAC;AAAA,YAACE;AAAA,YAAA;AAAA,cACC,WAAU;AAAA,cACV,QAAQH;AAAA,cAER,YAAYJ;AAAA,cACZ,MAAAX;AAAA,YAAA;AAAA,YAFKW;AAAA,UAAA,IAKP,gBAAAK;AAAA,YAACjB;AAAA,YAAA;AAAA,cACC,cAAcG,IAAe;AAAA,cAC7B,MAAM,CAACF,GAAMW,CAAG,EAAE,KAAK,GAAG;AAAA,cAC1B,QAAQI;AAAA,YAAA;AAAA,UAAA;AAAA,QACV;AAAA,MAAA;AAAA,IAEJ;AAAA,IAnCKJ;AAAA,EAAA,CAqCR,GACH;AAEJ;"}
@@ -1,12 +1,11 @@
1
- import { Locales, Messages, RichTextEditorOptions, Translations } from '../types.ts';
1
+ import { Locales, Messages, Translations } from '../types.ts';
2
2
  import { UseFormReturn } from 'react-hook-form';
3
3
  export type FormValues = Translations<Messages>;
4
4
  interface MessagesFormProviderProps {
5
5
  locales: Locales;
6
6
  form: UseFormReturn<FormValues>;
7
- richTextEditorOptions?: RichTextEditorOptions;
8
7
  }
9
- export declare function MessagesFormProvider({ locales, form, richTextEditorOptions, children, }: React.PropsWithChildren<MessagesFormProviderProps>): import("react/jsx-runtime").JSX.Element;
8
+ export declare function MessagesFormProvider({ locales, form, children, }: React.PropsWithChildren<MessagesFormProviderProps>): import("react/jsx-runtime").JSX.Element;
10
9
  export declare const useMessagesForm: () => {
11
10
  watch: import('react-hook-form').UseFormWatch<FormValues>;
12
11
  getValues: import('react-hook-form').UseFormGetValues<FormValues>;
@@ -25,6 +24,5 @@ export declare const useMessagesForm: () => {
25
24
  setFocus: import('react-hook-form').UseFormSetFocus<FormValues>;
26
25
  subscribe: import('react-hook-form').UseFormSubscribe<FormValues>;
27
26
  locales: Locales;
28
- richTextEditorOptions?: RichTextEditorOptions;
29
27
  };
30
28
  export {};
@@ -1,27 +1,26 @@
1
1
  "use client";
2
2
  import { jsx as r } from "react/jsx-runtime";
3
- import { createContext as m, useContext as c } from "react";
4
- import { FormProvider as i, useFormContext as u } from "react-hook-form";
5
- const t = m({
3
+ import { createContext as n, use as m } from "react";
4
+ import { FormProvider as c, useFormContext as i } from "react-hook-form";
5
+ const t = n({
6
6
  locales: ["en"]
7
7
  });
8
- function l({
8
+ function f({
9
9
  locales: e,
10
10
  form: o,
11
- richTextEditorOptions: s,
12
- children: n
11
+ children: s
13
12
  }) {
14
- return /* @__PURE__ */ r(t.Provider, { value: { locales: e, richTextEditorOptions: s }, children: /* @__PURE__ */ r(i, { ...o, children: n }) });
13
+ return /* @__PURE__ */ r(t, { value: { locales: e }, children: /* @__PURE__ */ r(c, { ...o, children: s }) });
15
14
  }
16
- const F = () => {
17
- const e = c(t), o = u();
15
+ const l = () => {
16
+ const e = m(t), o = i();
18
17
  return {
19
18
  ...e,
20
19
  ...o
21
20
  };
22
21
  };
23
22
  export {
24
- l as MessagesFormProvider,
25
- F as useMessagesForm
23
+ f as MessagesFormProvider,
24
+ l as useMessagesForm
26
25
  };
27
26
  //# sourceMappingURL=messages-form.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"messages-form.js","sources":["../../src/context/messages-form.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n Locales,\n Messages,\n RichTextEditorOptions,\n Translations,\n} from \"@/types\";\nimport type { UseFormReturn } from \"react-hook-form\";\nimport { createContext, useContext } from \"react\";\nimport { FormProvider, useFormContext } from \"react-hook-form\";\n\nexport type FormValues = Translations<Messages>;\n\nconst MessagesFormContext = createContext<{\n locales: Locales;\n richTextEditorOptions?: RichTextEditorOptions;\n}>({\n locales: [\"en\"],\n});\n\ninterface MessagesFormProviderProps {\n locales: Locales;\n form: UseFormReturn<FormValues>;\n richTextEditorOptions?: RichTextEditorOptions;\n}\n\nexport function MessagesFormProvider({\n locales,\n form,\n richTextEditorOptions,\n children,\n}: React.PropsWithChildren<MessagesFormProviderProps>) {\n return (\n <MessagesFormContext.Provider value={{ locales, richTextEditorOptions }}>\n <FormProvider {...form}>{children}</FormProvider>\n </MessagesFormContext.Provider>\n );\n}\n\nexport const useMessagesForm = () => {\n const context = useContext(MessagesFormContext);\n const form = useFormContext<FormValues>();\n return {\n ...context,\n ...form,\n };\n};\n"],"names":["MessagesFormContext","createContext","MessagesFormProvider","locales","form","richTextEditorOptions","children","jsx","FormProvider","useMessagesForm","context","useContext","useFormContext"],"mappings":";;;;AAcA,MAAMA,IAAsBC,EAGzB;AAAA,EACD,SAAS,CAAC,IAAI;AAChB,CAAC;AAQM,SAASC,EAAqB;AAAA,EACnC,SAAAC;AAAA,EACA,MAAAC;AAAA,EACA,uBAAAC;AAAA,EACA,UAAAC;AACF,GAAuD;AACrD,SACE,gBAAAC,EAACP,EAAoB,UAApB,EAA6B,OAAO,EAAE,SAAAG,GAAS,uBAAAE,EAAA,GAC9C,UAAA,gBAAAE,EAACC,GAAA,EAAc,GAAGJ,GAAO,UAAAE,GAAS,GACpC;AAEJ;AAEO,MAAMG,IAAkB,MAAM;AACnC,QAAMC,IAAUC,EAAWX,CAAmB,GACxCI,IAAOQ,EAAA;AACb,SAAO;AAAA,IACL,GAAGF;AAAA,IACH,GAAGN;AAAA,EAAA;AAEP;"}
1
+ {"version":3,"file":"messages-form.js","sources":["../../src/context/messages-form.tsx"],"sourcesContent":["\"use client\";\n\nimport type { Locales, Messages, Translations } from \"@/types\";\nimport type { UseFormReturn } from \"react-hook-form\";\nimport { createContext, use } from \"react\";\nimport { FormProvider, useFormContext } from \"react-hook-form\";\n\nexport type FormValues = Translations<Messages>;\n\nconst MessagesFormContext = createContext<{\n locales: Locales;\n}>({\n locales: [\"en\"],\n});\n\ninterface MessagesFormProviderProps {\n locales: Locales;\n form: UseFormReturn<FormValues>;\n}\n\nexport function MessagesFormProvider({\n locales,\n form,\n children,\n}: React.PropsWithChildren<MessagesFormProviderProps>) {\n return (\n <MessagesFormContext value={{ locales }}>\n <FormProvider {...form}>{children}</FormProvider>\n </MessagesFormContext>\n );\n}\n\nexport const useMessagesForm = () => {\n const context = use(MessagesFormContext);\n const form = useFormContext<FormValues>();\n return {\n ...context,\n ...form,\n };\n};\n"],"names":["MessagesFormContext","createContext","MessagesFormProvider","locales","form","children","jsx","FormProvider","useMessagesForm","context","use","useFormContext"],"mappings":";;;;AASA,MAAMA,IAAsBC,EAEzB;AAAA,EACD,SAAS,CAAC,IAAI;AAChB,CAAC;AAOM,SAASC,EAAqB;AAAA,EACnC,SAAAC;AAAA,EACA,MAAAC;AAAA,EACA,UAAAC;AACF,GAAuD;AACrD,SACE,gBAAAC,EAACN,GAAA,EAAoB,OAAO,EAAE,SAAAG,EAAA,GAC5B,UAAA,gBAAAG,EAACC,GAAA,EAAc,GAAGH,GAAO,UAAAC,EAAA,CAAS,EAAA,CACpC;AAEJ;AAEO,MAAMG,IAAkB,MAAM;AACnC,QAAMC,IAAUC,EAAIV,CAAmB,GACjCI,IAAOO,EAAA;AACb,SAAO;AAAA,IACL,GAAGF;AAAA,IACH,GAAGL;AAAA,EAAA;AAEP;"}
@@ -1,10 +1,9 @@
1
- import { Locales, Messages, MessagesGuard, RichTextEditorOptions } from '../types.ts';
1
+ import { Locales, Messages, MessagesGuard } from '../types.ts';
2
2
  import { AdminViewServerProps } from 'payload';
3
3
  export interface MessagesViewProps {
4
4
  locales: Locales;
5
5
  schema: Messages;
6
6
  tabs: boolean | undefined;
7
7
  access: MessagesGuard;
8
- richTextEditorOptions?: RichTextEditorOptions;
9
8
  }
10
- export declare function MessagesView({ access, initPageResult, locales, params, payload, schema, searchParams, tabs, richTextEditorOptions, }: AdminViewServerProps & MessagesViewProps): Promise<import("react/jsx-runtime").JSX.Element>;
9
+ export declare function MessagesView({ access, initPageResult, locales, params, payload, schema, searchParams, tabs, }: AdminViewServerProps & MessagesViewProps): Promise<import("react/jsx-runtime").JSX.Element>;
@@ -1,59 +1,57 @@
1
- import { jsxs as d, jsx as o } from "react/jsx-runtime";
2
- import h from "path";
3
- import { DefaultTemplate as g } from "@payloadcms/next/templates";
1
+ import { jsxs as g, jsx as i } from "react/jsx-runtime";
2
+ import { DefaultTemplate as h } from "@payloadcms/next/templates";
4
3
  import { Gutter as u } from "@payloadcms/ui";
5
4
  import { redirect as v, RedirectType as A } from "next/navigation";
6
5
  import { Toaster as M } from "sonner";
7
- import { sanitizeMessages as j } from "../utils/sanitize.js";
8
- import { MessagesForm as q } from "../components/MessagesForm.js";
9
- import { fetchMessages as w } from "../requests/fetchMessages.js";
10
- async function F({
11
- access: m,
6
+ import { sanitizeMessages as q } from "../utils/sanitize.js";
7
+ import { MessagesForm as w } from "../components/MessagesForm.js";
8
+ import { fetchMessages as x } from "../requests/fetchMessages.js";
9
+ async function z({
10
+ access: c,
12
11
  initPageResult: e,
13
- locales: i,
12
+ locales: t,
14
13
  params: p,
15
- payload: s,
16
- schema: t,
17
- searchParams: c,
18
- tabs: f = !1,
19
- richTextEditorOptions: a
14
+ payload: r,
15
+ schema: n,
16
+ searchParams: f,
17
+ tabs: a = !1
20
18
  }) {
21
- await m(e.req) || v(s.getAdminURL(), A.replace);
22
- const n = {};
23
- for (const r of i) {
24
- const l = await w(s, r);
25
- n[r] = j(t, l);
19
+ const o = r.getAPIURL(), l = o.endsWith("/") ? `${o}intl-plugin` : `${o}/intl-plugin`;
20
+ await c(e.req) || v(r.getAdminURL(), A.replace);
21
+ const m = {};
22
+ for (const s of t) {
23
+ const d = await x(r, s);
24
+ m[s] = q(n, d);
26
25
  }
27
- return /* @__PURE__ */ d(
28
- g,
26
+ return /* @__PURE__ */ g(
27
+ h,
29
28
  {
30
29
  i18n: e.req.i18n,
31
30
  locale: e.locale,
32
31
  params: p,
33
32
  payload: e.req.payload,
34
33
  permissions: e.permissions,
35
- searchParams: c,
34
+ searchParams: f,
36
35
  user: e.req.user || void 0,
37
- viewActions: s.config.admin.components.actions.filter((r) => typeof r != "object" ? !0 : r.exportName !== "MessagesLink"),
36
+ viewActions: r.config.admin.components.actions.filter((s) => typeof s != "object" ? !0 : s.exportName !== "MessagesLink"),
38
37
  visibleEntities: e.visibleEntities,
39
38
  children: [
40
- /* @__PURE__ */ o(u, { children: /* @__PURE__ */ o(
41
- q,
39
+ /* @__PURE__ */ i(u, { children: /* @__PURE__ */ i(
40
+ w,
42
41
  {
43
- locales: i,
44
- schema: t,
45
- tabs: f,
46
- values: n,
47
- endpointUrl: h.join(s.getAPIURL(), "intl-plugin"),
48
- richTextEditorOptions: a
42
+ locales: t,
43
+ schema: n,
44
+ tabs: a,
45
+ values: m,
46
+ endpointUrl: l
49
47
  }
50
48
  ) }),
51
- /* @__PURE__ */ o(M, { position: "top-right" })
49
+ /* @__PURE__ */ i(M, { position: "top-right" })
52
50
  ]
53
51
  }
54
52
  );
55
53
  }
56
54
  export {
57
- F as MessagesView
55
+ z as MessagesView
58
56
  };
59
57
  //# sourceMappingURL=view.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"view.js","sources":["../../src/exports/view.tsx"],"sourcesContent":["import path from \"path\";\nimport type {\n DeepPartial,\n Locales,\n Messages,\n MessagesGuard,\n RichTextEditorOptions,\n Translations,\n} from \"@/types\";\nimport type { AdminViewServerProps } from \"payload\";\nimport { DefaultTemplate } from \"@payloadcms/next/templates\";\nimport { Gutter } from \"@payloadcms/ui\";\nimport { redirect, RedirectType } from \"next/navigation\";\nimport { Toaster } from \"sonner\";\n\nimport { sanitizeMessages } from \"@/utils/sanitize\";\n\nimport { MessagesForm } from \"../components/MessagesForm\";\nimport { fetchMessages } from \"../requests/fetchMessages\";\n\nexport interface MessagesViewProps {\n locales: Locales;\n schema: Messages;\n tabs: boolean | undefined;\n access: MessagesGuard;\n richTextEditorOptions?: RichTextEditorOptions;\n}\n\nexport async function MessagesView({\n access,\n initPageResult,\n locales,\n params,\n payload,\n schema,\n searchParams,\n tabs = false,\n richTextEditorOptions,\n}: AdminViewServerProps & MessagesViewProps) {\n const hasAccess = await access(initPageResult.req);\n if (!hasAccess) redirect(payload.getAdminURL(), RedirectType.replace);\n\n const translations: Translations<DeepPartial<Messages>> = {};\n\n for (const locale of locales) {\n const messages = await fetchMessages(payload, locale);\n translations[locale] = sanitizeMessages(schema, messages);\n }\n return (\n <DefaultTemplate\n i18n={initPageResult.req.i18n}\n locale={initPageResult.locale}\n params={params}\n payload={initPageResult.req.payload}\n permissions={initPageResult.permissions}\n searchParams={searchParams}\n user={initPageResult.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={initPageResult.visibleEntities}\n >\n <Gutter>\n <MessagesForm\n locales={locales}\n schema={schema}\n tabs={tabs}\n values={translations}\n endpointUrl={path.join(payload.getAPIURL(), \"intl-plugin\")}\n richTextEditorOptions={richTextEditorOptions}\n />\n </Gutter>\n <Toaster position=\"top-right\" />\n </DefaultTemplate>\n );\n}\n"],"names":["MessagesView","access","initPageResult","locales","params","payload","schema","searchParams","tabs","richTextEditorOptions","redirect","RedirectType","translations","locale","messages","fetchMessages","sanitizeMessages","jsxs","DefaultTemplate","action","jsx","Gutter","MessagesForm","path","Toaster"],"mappings":";;;;;;;;;AA4BA,eAAsBA,EAAa;AAAA,EACjC,QAAAC;AAAA,EACA,gBAAAC;AAAA,EACA,SAAAC;AAAA,EACA,QAAAC;AAAA,EACA,SAAAC;AAAA,EACA,QAAAC;AAAA,EACA,cAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,uBAAAC;AACF,GAA6C;AAE3C,EADkB,MAAMR,EAAOC,EAAe,GAAG,KACjCQ,EAASL,EAAQ,YAAA,GAAeM,EAAa,OAAO;AAEpE,QAAMC,IAAoD,CAAA;AAE1D,aAAWC,KAAUV,GAAS;AAC5B,UAAMW,IAAW,MAAMC,EAAcV,GAASQ,CAAM;AACpD,IAAAD,EAAaC,CAAM,IAAIG,EAAiBV,GAAQQ,CAAQ;AAAA,EAC1D;AACA,SACE,gBAAAG;AAAA,IAACC;AAAA,IAAA;AAAA,MACC,MAAMhB,EAAe,IAAI;AAAA,MACzB,QAAQA,EAAe;AAAA,MACvB,QAAAE;AAAA,MACA,SAASF,EAAe,IAAI;AAAA,MAC5B,aAAaA,EAAe;AAAA,MAC5B,cAAAK;AAAA,MACA,MAAML,EAAe,IAAI,QAAQ;AAAA,MACjC,aAAaG,EAAQ,OAAO,MAAM,WAAW,QAAQ,OAAO,CAACc,MACvD,OAAOA,KAAW,WACb,KAEFA,EAAO,eAAe,cAC9B;AAAA,MACD,iBAAiBjB,EAAe;AAAA,MAEhC,UAAA;AAAA,QAAA,gBAAAkB,EAACC,GAAA,EACC,UAAA,gBAAAD;AAAA,UAACE;AAAA,UAAA;AAAA,YACC,SAAAnB;AAAA,YACA,QAAAG;AAAA,YACA,MAAAE;AAAA,YACA,QAAQI;AAAA,YACR,aAAaW,EAAK,KAAKlB,EAAQ,UAAA,GAAa,aAAa;AAAA,YACzD,uBAAAI;AAAA,UAAA;AAAA,QAAA,GAEJ;AAAA,QACA,gBAAAW,EAACI,GAAA,EAAQ,UAAS,YAAA,CAAY;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGpC;"}
1
+ {"version":3,"file":"view.js","sources":["../../src/exports/view.tsx"],"sourcesContent":["import type {\n DeepPartial,\n Locales,\n Messages,\n MessagesGuard,\n Translations,\n} from \"@/types\";\nimport type { AdminViewServerProps } from \"payload\";\nimport { DefaultTemplate } from \"@payloadcms/next/templates\";\nimport { Gutter } from \"@payloadcms/ui\";\nimport { redirect, RedirectType } from \"next/navigation\";\nimport { Toaster } from \"sonner\";\n\nimport { sanitizeMessages } from \"@/utils/sanitize\";\n\nimport { MessagesForm } from \"../components/MessagesForm\";\nimport { fetchMessages } from \"../requests/fetchMessages\";\n\nexport interface MessagesViewProps {\n locales: Locales;\n schema: Messages;\n tabs: boolean | undefined;\n access: MessagesGuard;\n}\n\nexport async function MessagesView({\n access,\n initPageResult,\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(initPageResult.req);\n if (!hasAccess) redirect(payload.getAdminURL(), RedirectType.replace);\n\n const translations: Translations<DeepPartial<Messages>> = {};\n\n for (const locale of locales) {\n const messages = await fetchMessages(payload, locale);\n translations[locale] = sanitizeMessages(schema, messages);\n }\n return (\n <DefaultTemplate\n i18n={initPageResult.req.i18n}\n locale={initPageResult.locale}\n params={params}\n payload={initPageResult.req.payload}\n permissions={initPageResult.permissions}\n searchParams={searchParams}\n user={initPageResult.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={initPageResult.visibleEntities}\n >\n <Gutter>\n <MessagesForm\n locales={locales}\n schema={schema}\n tabs={tabs}\n values={translations}\n endpointUrl={endpointUrl}\n />\n </Gutter>\n <Toaster position=\"top-right\" />\n </DefaultTemplate>\n );\n}\n"],"names":["MessagesView","access","initPageResult","locales","params","payload","schema","searchParams","tabs","apiUrl","endpointUrl","redirect","RedirectType","translations","locale","messages","fetchMessages","sanitizeMessages","jsxs","DefaultTemplate","action","jsx","Gutter","MessagesForm","Toaster"],"mappings":";;;;;;;;AAyBA,eAAsBA,EAAa;AAAA,EACjC,QAAAC;AAAA,EACA,gBAAAC;AAAA,EACA,SAAAC;AAAA,EACA,QAAAC;AAAA,EACA,SAAAC;AAAA,EACA,QAAAC;AAAA,EACA,cAAAC;AAAA,EACA,MAAAC,IAAO;AACT,GAA6C;AAC3C,QAAMC,IAASJ,EAAQ,UAAA,GACjBK,IAAcD,EAAO,SAAS,GAAG,IACnC,GAAGA,CAAM,gBACT,GAAGA,CAAM;AAGb,EADkB,MAAMR,EAAOC,EAAe,GAAG,KACjCS,EAASN,EAAQ,YAAA,GAAeO,EAAa,OAAO;AAEpE,QAAMC,IAAoD,CAAA;AAE1D,aAAWC,KAAUX,GAAS;AAC5B,UAAMY,IAAW,MAAMC,EAAcX,GAASS,CAAM;AACpD,IAAAD,EAAaC,CAAM,IAAIG,EAAiBX,GAAQS,CAAQ;AAAA,EAC1D;AACA,SACE,gBAAAG;AAAA,IAACC;AAAA,IAAA;AAAA,MACC,MAAMjB,EAAe,IAAI;AAAA,MACzB,QAAQA,EAAe;AAAA,MACvB,QAAAE;AAAA,MACA,SAASF,EAAe,IAAI;AAAA,MAC5B,aAAaA,EAAe;AAAA,MAC5B,cAAAK;AAAA,MACA,MAAML,EAAe,IAAI,QAAQ;AAAA,MACjC,aAAaG,EAAQ,OAAO,MAAM,WAAW,QAAQ,OAAO,CAACe,MACvD,OAAOA,KAAW,WACb,KAEFA,EAAO,eAAe,cAC9B;AAAA,MACD,iBAAiBlB,EAAe;AAAA,MAEhC,UAAA;AAAA,QAAA,gBAAAmB,EAACC,GAAA,EACC,UAAA,gBAAAD;AAAA,UAACE;AAAA,UAAA;AAAA,YACC,SAAApB;AAAA,YACA,QAAAG;AAAA,YACA,MAAAE;AAAA,YACA,QAAQK;AAAA,YACR,aAAAH;AAAA,UAAA;AAAA,QAAA,GAEJ;AAAA,QACA,gBAAAW,EAACG,GAAA,EAAQ,UAAS,YAAA,CAAY;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGpC;"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from 'payload';
2
2
  import { MessagesPluginConfig } from './types.ts';
3
- export declare const intlPlugin: ({ schema, tabs, collectionSlug, hooks, editorAccess, richTextEditorOptions, }: MessagesPluginConfig) => Plugin;
3
+ export declare const intlPlugin: ({ schema, tabs, collectionSlug, hooks, editorAccess, }: MessagesPluginConfig) => Plugin;
4
4
  export { fetchMessages } from './requests/fetchMessages';
5
5
  export type { MessagesPluginConfig, MessagesSchema, Messages, } from './types.ts';
package/dist/index.js CHANGED
@@ -1,17 +1,21 @@
1
1
  /* empty css */
2
- import { getMessagesEndpoint as r } from "./endpoints/get-messages.js";
3
- import { setMessagesEndpoint as p } from "./endpoints/set-messages.js";
4
- import { getSupportedLocales as l, attachPluginContext as m } from "./utils/config.js";
5
- import { fetchMessages as w } from "./requests/fetchMessages.js";
6
- const y = ({
2
+ import { lexicalEditor as m } from "@payloadcms/richtext-lexical";
3
+ import { getMessagesEndpoint as o } from "./endpoints/get-messages.js";
4
+ import { setMessagesEndpoint as i } from "./endpoints/set-messages.js";
5
+ import { getSupportedLocales as u, attachPluginContext as c } from "./utils/config.js";
6
+ import { fetchMessages as C } from "./requests/fetchMessages.js";
7
+ const M = ({
7
8
  schema: s,
8
9
  tabs: a,
9
10
  collectionSlug: t = "messages",
10
- hooks: n,
11
- editorAccess: o = (e) => e.user !== null,
12
- richTextEditorOptions: i
11
+ hooks: r,
12
+ editorAccess: n = (e) => e.user !== null
13
13
  }) => (e) => {
14
- const d = l(e.localization);
14
+ const p = u(e.localization);
15
+ if (!e.serverURL)
16
+ throw new Error(
17
+ "serverURL is required in your payload.config.ts file for payload-intl to work."
18
+ );
15
19
  return e.admin ??= {}, e.admin.components ??= {}, e.admin.components.actions ??= [], e.admin.components.actions.push({
16
20
  exportName: "MessagesLink",
17
21
  path: "payload-intl/rsc#MessagesLink"
@@ -21,17 +25,30 @@ const y = ({
21
25
  Component: {
22
26
  path: "payload-intl/rsc#MessagesView",
23
27
  serverProps: {
24
- access: o,
25
- locales: d,
28
+ access: n,
29
+ locales: p,
26
30
  schema: s,
27
- tabs: a,
28
- richTextEditorOptions: i
31
+ tabs: a
29
32
  }
30
33
  },
31
34
  path: "/intl"
32
35
  }
33
- }, m(e, {
36
+ }, c(e, {
34
37
  collectionSlug: t
38
+ }), e.globals ??= [], e.globals.push({
39
+ slug: "intl-plugin",
40
+ fields: [
41
+ {
42
+ name: "editorTemplate",
43
+ type: "richText",
44
+ editor: m({
45
+ features: ({ defaultFeatures: l }) => l.filter(
46
+ ({ key: d }) => !["relationship", "upload"].includes(d)
47
+ )
48
+ }),
49
+ admin: { hidden: !0 }
50
+ }
51
+ ]
35
52
  }), e.collections ??= [], e.collections.push({
36
53
  slug: t,
37
54
  admin: {
@@ -40,7 +57,7 @@ const y = ({
40
57
  access: {
41
58
  read: () => !0
42
59
  },
43
- endpoints: [p, r],
60
+ endpoints: [i, o],
44
61
  fields: [
45
62
  {
46
63
  name: "locale",
@@ -48,7 +65,7 @@ const y = ({
48
65
  required: !0
49
66
  }
50
67
  ],
51
- hooks: u(n),
68
+ hooks: h(r),
52
69
  indexes: [
53
70
  {
54
71
  fields: ["locale"]
@@ -57,23 +74,23 @@ const y = ({
57
74
  upload: {
58
75
  mimeTypes: ["application/json"]
59
76
  }
60
- }), e.endpoints ??= [], e.endpoints.push(r), e.endpoints.push(p), e;
61
- }, u = (s) => {
77
+ }), e.endpoints ??= [], e.endpoints.push(o), e.endpoints.push(i), e;
78
+ }, h = (s) => {
62
79
  if (!s)
63
80
  return;
64
81
  const { afterUpdate: a, ...t } = s;
65
82
  if (!a)
66
83
  return t;
67
- const n = async ({ operation: o }) => {
68
- o === "update" && await a();
84
+ const r = async ({ operation: n }) => {
85
+ n === "update" && await a();
69
86
  };
70
87
  return {
71
88
  ...t,
72
- afterChange: [...t.afterChange ?? [], n]
89
+ afterChange: [...t.afterChange ?? [], r]
73
90
  };
74
91
  };
75
92
  export {
76
- w as fetchMessages,
77
- y as intlPlugin
93
+ C as fetchMessages,
94
+ M as intlPlugin
78
95
  };
79
96
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import \"./styles.css\";\n\nimport type {\n CollectionAfterChangeHook,\n CollectionConfig,\n LocalizationConfig,\n Plugin,\n} from \"payload\";\n\nimport type { MessagesViewProps } from \"./exports/view\";\nimport type { Locales, MessagesPluginConfig } from \"./types.ts\";\nimport { getMessagesEndpoint } from \"./endpoints/get-messages\";\nimport { setMessagesEndpoint } from \"./endpoints/set-messages\";\nimport { attachPluginContext, getSupportedLocales } from \"./utils/config\";\n\nexport const intlPlugin =\n ({\n schema,\n tabs,\n collectionSlug = \"messages\",\n hooks,\n editorAccess = (req) => req.user !== null,\n richTextEditorOptions,\n }: MessagesPluginConfig): Plugin =>\n (config) => {\n const locales = getSupportedLocales(config.localization);\n\n config.admin ??= {};\n config.admin.components ??= {};\n config.admin.components.actions ??= [];\n config.admin.components.actions.push({\n exportName: \"MessagesLink\",\n path: \"payload-intl/rsc#MessagesLink\",\n });\n\n config.admin.components.views = {\n ...config.admin.components.views,\n intl: {\n Component: {\n path: \"payload-intl/rsc#MessagesView\",\n serverProps: {\n access: editorAccess,\n locales,\n schema,\n tabs,\n richTextEditorOptions,\n } satisfies MessagesViewProps,\n },\n path: \"/intl\",\n },\n };\n\n attachPluginContext(config, {\n collectionSlug,\n });\n\n config.collections ??= [];\n config.collections.push({\n slug: collectionSlug,\n admin: {\n hidden: true,\n },\n access: {\n read: () => true,\n },\n endpoints: [setMessagesEndpoint, getMessagesEndpoint],\n fields: [\n {\n name: \"locale\",\n type: \"text\",\n required: true,\n },\n ],\n hooks: createHooks(hooks),\n indexes: [\n {\n fields: [\"locale\"],\n },\n ],\n upload: {\n mimeTypes: [\"application/json\"],\n },\n });\n\n config.endpoints ??= [];\n config.endpoints.push(getMessagesEndpoint);\n config.endpoints.push(setMessagesEndpoint);\n\n return config;\n };\n\nexport { fetchMessages } from \"./requests/fetchMessages\";\n\nexport type {\n MessagesPluginConfig,\n MessagesSchema,\n Messages,\n} from \"./types.ts\";\n\nconst createHooks = (\n hooks: MessagesPluginConfig[\"hooks\"],\n): CollectionConfig[\"hooks\"] => {\n if (!hooks) {\n return undefined;\n }\n const { afterUpdate, ...rest } = hooks;\n if (!afterUpdate) {\n return rest;\n }\n\n const afterUpdateHook: CollectionAfterChangeHook = async ({ operation }) => {\n if (operation === \"update\") {\n await afterUpdate();\n }\n return;\n };\n return {\n ...rest,\n afterChange: [...(rest.afterChange ?? []), afterUpdateHook],\n };\n};\n"],"names":["intlPlugin","schema","tabs","collectionSlug","hooks","editorAccess","req","richTextEditorOptions","config","locales","getSupportedLocales","attachPluginContext","setMessagesEndpoint","getMessagesEndpoint","createHooks","afterUpdate","rest","afterUpdateHook","operation"],"mappings":";;;;;AAeO,MAAMA,IACX,CAAC;AAAA,EACC,QAAAC;AAAA,EACA,MAAAC;AAAA,EACA,gBAAAC,IAAiB;AAAA,EACjB,OAAAC;AAAA,EACA,cAAAC,IAAe,CAACC,MAAQA,EAAI,SAAS;AAAA,EACrC,uBAAAC;AACF,MACA,CAACC,MAAW;AACV,QAAMC,IAAUC,EAAoBF,EAAO,YAAY;AAEvD,SAAAA,EAAO,UAAU,CAAA,GACjBA,EAAO,MAAM,eAAe,CAAA,GAC5BA,EAAO,MAAM,WAAW,YAAY,CAAA,GACpCA,EAAO,MAAM,WAAW,QAAQ,KAAK;AAAA,IACnC,YAAY;AAAA,IACZ,MAAM;AAAA,EAAA,CACP,GAEDA,EAAO,MAAM,WAAW,QAAQ;AAAA,IAC9B,GAAGA,EAAO,MAAM,WAAW;AAAA,IAC3B,MAAM;AAAA,MACJ,WAAW;AAAA,QACT,MAAM;AAAA,QACN,aAAa;AAAA,UACX,QAAQH;AAAA,UACR,SAAAI;AAAA,UACA,QAAAR;AAAA,UACA,MAAAC;AAAA,UACA,uBAAAK;AAAA,QAAA;AAAA,MACF;AAAA,MAEF,MAAM;AAAA,IAAA;AAAA,EACR,GAGFI,EAAoBH,GAAQ;AAAA,IAC1B,gBAAAL;AAAA,EAAA,CACD,GAEDK,EAAO,gBAAgB,CAAA,GACvBA,EAAO,YAAY,KAAK;AAAA,IACtB,MAAML;AAAA,IACN,OAAO;AAAA,MACL,QAAQ;AAAA,IAAA;AAAA,IAEV,QAAQ;AAAA,MACN,MAAM,MAAM;AAAA,IAAA;AAAA,IAEd,WAAW,CAACS,GAAqBC,CAAmB;AAAA,IACpD,QAAQ;AAAA,MACN;AAAA,QACE,MAAM;AAAA,QACN,MAAM;AAAA,QACN,UAAU;AAAA,MAAA;AAAA,IACZ;AAAA,IAEF,OAAOC,EAAYV,CAAK;AAAA,IACxB,SAAS;AAAA,MACP;AAAA,QACE,QAAQ,CAAC,QAAQ;AAAA,MAAA;AAAA,IACnB;AAAA,IAEF,QAAQ;AAAA,MACN,WAAW,CAAC,kBAAkB;AAAA,IAAA;AAAA,EAChC,CACD,GAEDI,EAAO,cAAc,CAAA,GACrBA,EAAO,UAAU,KAAKK,CAAmB,GACzCL,EAAO,UAAU,KAAKI,CAAmB,GAElCJ;AACT,GAUIM,IAAc,CAClBV,MAC8B;AAC9B,MAAI,CAACA;AACH;AAEF,QAAM,EAAE,aAAAW,GAAa,GAAGC,EAAA,IAASZ;AACjC,MAAI,CAACW;AACH,WAAOC;AAGT,QAAMC,IAA6C,OAAO,EAAE,WAAAC,QAAgB;AAC1E,IAAIA,MAAc,YAChB,MAAMH,EAAA;AAAA,EAGV;AACA,SAAO;AAAA,IACL,GAAGC;AAAA,IACH,aAAa,CAAC,GAAIA,EAAK,eAAe,CAAA,GAAKC,CAAe;AAAA,EAAA;AAE9D;"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import \"./styles.css\";\n\nimport type {\n CollectionAfterChangeHook,\n CollectionConfig,\n Plugin,\n} from \"payload\";\nimport { lexicalEditor } from \"@payloadcms/richtext-lexical\";\n\nimport type { MessagesViewProps } from \"./exports/view\";\nimport type { MessagesPluginConfig } from \"./types.ts\";\nimport { getMessagesEndpoint } from \"./endpoints/get-messages\";\nimport { setMessagesEndpoint } from \"./endpoints/set-messages\";\nimport { attachPluginContext, getSupportedLocales } from \"./utils/config\";\n\nexport const intlPlugin =\n ({\n schema,\n tabs,\n collectionSlug = \"messages\",\n hooks,\n editorAccess = (req) => req.user !== null,\n }: MessagesPluginConfig): Plugin =>\n (config) => {\n const locales = getSupportedLocales(config.localization);\n\n if (!config.serverURL) {\n throw new Error(\n \"serverURL is required in your payload.config.ts file for payload-intl to work.\",\n );\n }\n\n config.admin ??= {};\n config.admin.components ??= {};\n config.admin.components.actions ??= [];\n config.admin.components.actions.push({\n exportName: \"MessagesLink\",\n path: \"payload-intl/rsc#MessagesLink\",\n });\n\n config.admin.components.views = {\n ...config.admin.components.views,\n intl: {\n Component: {\n path: \"payload-intl/rsc#MessagesView\",\n serverProps: {\n access: editorAccess,\n locales,\n schema,\n tabs,\n } satisfies MessagesViewProps,\n },\n path: \"/intl\",\n },\n };\n\n attachPluginContext(config, {\n collectionSlug,\n });\n config.globals ??= [];\n config.globals.push({\n slug: \"intl-plugin\",\n fields: [\n {\n name: \"editorTemplate\",\n type: \"richText\",\n editor: lexicalEditor({\n features: ({ defaultFeatures }) =>\n defaultFeatures.filter(\n ({ key }) => ![\"relationship\", \"upload\"].includes(key),\n ),\n }),\n admin: { hidden: true },\n },\n ],\n });\n\n config.collections ??= [];\n config.collections.push({\n slug: collectionSlug,\n admin: {\n hidden: true,\n },\n access: {\n read: () => true,\n },\n endpoints: [setMessagesEndpoint, getMessagesEndpoint],\n fields: [\n {\n name: \"locale\",\n type: \"text\",\n required: true,\n },\n ],\n hooks: createHooks(hooks),\n indexes: [\n {\n fields: [\"locale\"],\n },\n ],\n upload: {\n mimeTypes: [\"application/json\"],\n },\n });\n\n config.endpoints ??= [];\n config.endpoints.push(getMessagesEndpoint);\n config.endpoints.push(setMessagesEndpoint);\n\n return config;\n };\n\nexport { fetchMessages } from \"./requests/fetchMessages\";\n\nexport type {\n MessagesPluginConfig,\n MessagesSchema,\n Messages,\n} from \"./types.ts\";\n\nconst createHooks = (\n hooks: MessagesPluginConfig[\"hooks\"],\n): CollectionConfig[\"hooks\"] => {\n if (!hooks) {\n return undefined;\n }\n const { afterUpdate, ...rest } = hooks;\n if (!afterUpdate) {\n return rest;\n }\n\n const afterUpdateHook: CollectionAfterChangeHook = async ({ operation }) => {\n if (operation === \"update\") {\n await afterUpdate();\n }\n return;\n };\n return {\n ...rest,\n afterChange: [...(rest.afterChange ?? []), afterUpdateHook],\n };\n};\n"],"names":["intlPlugin","schema","tabs","collectionSlug","hooks","editorAccess","req","config","locales","getSupportedLocales","attachPluginContext","lexicalEditor","defaultFeatures","key","setMessagesEndpoint","getMessagesEndpoint","createHooks","afterUpdate","rest","afterUpdateHook","operation"],"mappings":";;;;;;AAeO,MAAMA,IACX,CAAC;AAAA,EACC,QAAAC;AAAA,EACA,MAAAC;AAAA,EACA,gBAAAC,IAAiB;AAAA,EACjB,OAAAC;AAAA,EACA,cAAAC,IAAe,CAACC,MAAQA,EAAI,SAAS;AACvC,MACA,CAACC,MAAW;AACV,QAAMC,IAAUC,EAAoBF,EAAO,YAAY;AAEvD,MAAI,CAACA,EAAO;AACV,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAIJ,SAAAA,EAAO,UAAU,CAAA,GACjBA,EAAO,MAAM,eAAe,CAAA,GAC5BA,EAAO,MAAM,WAAW,YAAY,CAAA,GACpCA,EAAO,MAAM,WAAW,QAAQ,KAAK;AAAA,IACnC,YAAY;AAAA,IACZ,MAAM;AAAA,EAAA,CACP,GAEDA,EAAO,MAAM,WAAW,QAAQ;AAAA,IAC9B,GAAGA,EAAO,MAAM,WAAW;AAAA,IAC3B,MAAM;AAAA,MACJ,WAAW;AAAA,QACT,MAAM;AAAA,QACN,aAAa;AAAA,UACX,QAAQF;AAAA,UACR,SAAAG;AAAA,UACA,QAAAP;AAAA,UACA,MAAAC;AAAA,QAAA;AAAA,MACF;AAAA,MAEF,MAAM;AAAA,IAAA;AAAA,EACR,GAGFQ,EAAoBH,GAAQ;AAAA,IAC1B,gBAAAJ;AAAA,EAAA,CACD,GACDI,EAAO,YAAY,CAAA,GACnBA,EAAO,QAAQ,KAAK;AAAA,IAClB,MAAM;AAAA,IACN,QAAQ;AAAA,MACN;AAAA,QACE,MAAM;AAAA,QACN,MAAM;AAAA,QACN,QAAQI,EAAc;AAAA,UACpB,UAAU,CAAC,EAAE,iBAAAC,EAAA,MACXA,EAAgB;AAAA,YACd,CAAC,EAAE,KAAAC,EAAA,MAAU,CAAC,CAAC,gBAAgB,QAAQ,EAAE,SAASA,CAAG;AAAA,UAAA;AAAA,QACvD,CACH;AAAA,QACD,OAAO,EAAE,QAAQ,GAAA;AAAA,MAAK;AAAA,IACxB;AAAA,EACF,CACD,GAEDN,EAAO,gBAAgB,CAAA,GACvBA,EAAO,YAAY,KAAK;AAAA,IACtB,MAAMJ;AAAA,IACN,OAAO;AAAA,MACL,QAAQ;AAAA,IAAA;AAAA,IAEV,QAAQ;AAAA,MACN,MAAM,MAAM;AAAA,IAAA;AAAA,IAEd,WAAW,CAACW,GAAqBC,CAAmB;AAAA,IACpD,QAAQ;AAAA,MACN;AAAA,QACE,MAAM;AAAA,QACN,MAAM;AAAA,QACN,UAAU;AAAA,MAAA;AAAA,IACZ;AAAA,IAEF,OAAOC,EAAYZ,CAAK;AAAA,IACxB,SAAS;AAAA,MACP;AAAA,QACE,QAAQ,CAAC,QAAQ;AAAA,MAAA;AAAA,IACnB;AAAA,IAEF,QAAQ;AAAA,MACN,WAAW,CAAC,kBAAkB;AAAA,IAAA;AAAA,EAChC,CACD,GAEDG,EAAO,cAAc,CAAA,GACrBA,EAAO,UAAU,KAAKQ,CAAmB,GACzCR,EAAO,UAAU,KAAKO,CAAmB,GAElCP;AACT,GAUIS,IAAc,CAClBZ,MAC8B;AAC9B,MAAI,CAACA;AACH;AAEF,QAAM,EAAE,aAAAa,GAAa,GAAGC,EAAA,IAASd;AACjC,MAAI,CAACa;AACH,WAAOC;AAGT,QAAMC,IAA6C,OAAO,EAAE,WAAAC,QAAgB;AAC1E,IAAIA,MAAc,YAChB,MAAMH,EAAA;AAAA,EAGV;AACA,SAAO;AAAA,IACL,GAAGC;AAAA,IACH,aAAa,CAAC,GAAIA,EAAK,eAAe,CAAA,GAAKC,CAAe;AAAA,EAAA;AAE9D;"}
@@ -1,29 +1,32 @@
1
- import { getPluginContext as s } from "../utils/config.js";
2
- async function a(n, e) {
1
+ import { getPluginContext as i } from "../utils/config.js";
2
+ import { getErrorMessage as c } from "../utils/error-handling.js";
3
+ async function l(r, o) {
4
+ if (!r.config.serverURL)
5
+ throw new Error(
6
+ "serverURL is required in your payload.config.ts file for payload-intl to work."
7
+ );
3
8
  const {
4
- docs: [r]
5
- } = await n.find({
6
- collection: s(n.config).collectionSlug,
7
- where: { locale: { equals: e } }
9
+ docs: [t]
10
+ } = await r.find({
11
+ collection: i(r.config).collectionSlug,
12
+ where: { locale: { equals: o } }
8
13
  });
9
- if (!r)
10
- return console.warn(`No messages found for locale ${e}`), {};
11
- const { url: o } = r, t = await fetch(o);
12
- if (!t.ok)
14
+ if (!t)
15
+ return console.warn(`No messages found for locale ${o}`), {};
16
+ const { url: n } = t, e = await fetch(n);
17
+ if (!e.ok) {
18
+ const s = await c(e);
13
19
  throw new Error(
14
- `Could not fetch messages for locale "${e}": The page returned an error.
15
-
16
- ${o}`
20
+ `Could not fetch messages for locale "${o}": ${s}`
17
21
  );
18
- if (t.headers.get("content-type") !== "application/json")
22
+ }
23
+ if (e.headers.get("content-type") !== "application/json")
19
24
  throw new Error(
20
- `Could not fetch messages for locale "${e}": The page did not return a JSON file.
21
-
22
- ${o}`
25
+ `Could not fetch messages for locale "${o}": The page did not return a JSON file.`
23
26
  );
24
- return await t.json();
27
+ return await e.json();
25
28
  }
26
29
  export {
27
- a as fetchMessages
30
+ l as fetchMessages
28
31
  };
29
32
  //# sourceMappingURL=fetchMessages.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetchMessages.js","sources":["../../src/requests/fetchMessages.ts"],"sourcesContent":["import type { BasePayload } from \"payload\";\n\nimport { getPluginContext } from \"@/utils/config\";\n\nimport type { Messages } from \"../types\";\n\nexport async function fetchMessages(\n payload: BasePayload,\n locale: string,\n): Promise<Messages> {\n const {\n docs: [doc],\n } = await payload.find({\n collection: getPluginContext(payload.config).collectionSlug,\n where: { locale: { equals: locale } },\n });\n\n if (!doc) {\n console.warn(`No messages found for locale ${locale}`);\n return {};\n }\n\n const { url } = doc as unknown as { url: string };\n\n const response = await fetch(url);\n\n if (!response.ok) {\n throw new Error(\n `Could not fetch messages for locale \"${locale}\": The page returned an error.\\n\\n${url}`,\n );\n }\n\n if (response.headers.get(\"content-type\") !== \"application/json\") {\n throw new Error(\n `Could not fetch messages for locale \"${locale}\": The page did not return a JSON file.\\n\\n${url}`,\n );\n }\n\n return await response.json();\n}\n"],"names":["fetchMessages","payload","locale","doc","getPluginContext","url","response"],"mappings":";AAMA,eAAsBA,EACpBC,GACAC,GACmB;AACnB,QAAM;AAAA,IACJ,MAAM,CAACC,CAAG;AAAA,EAAA,IACR,MAAMF,EAAQ,KAAK;AAAA,IACrB,YAAYG,EAAiBH,EAAQ,MAAM,EAAE;AAAA,IAC7C,OAAO,EAAE,QAAQ,EAAE,QAAQC,IAAO;AAAA,EAAE,CACrC;AAED,MAAI,CAACC;AACH,mBAAQ,KAAK,gCAAgCD,CAAM,EAAE,GAC9C,CAAA;AAGT,QAAM,EAAE,KAAAG,MAAQF,GAEVG,IAAW,MAAM,MAAMD,CAAG;AAEhC,MAAI,CAACC,EAAS;AACZ,UAAM,IAAI;AAAA,MACR,wCAAwCJ,CAAM;AAAA;AAAA,EAAqCG,CAAG;AAAA,IAAA;AAI1F,MAAIC,EAAS,QAAQ,IAAI,cAAc,MAAM;AAC3C,UAAM,IAAI;AAAA,MACR,wCAAwCJ,CAAM;AAAA;AAAA,EAA8CG,CAAG;AAAA,IAAA;AAInG,SAAO,MAAMC,EAAS,KAAA;AACxB;"}
1
+ {"version":3,"file":"fetchMessages.js","sources":["../../src/requests/fetchMessages.ts"],"sourcesContent":["import type { BasePayload } from \"payload\";\n\nimport { getPluginContext } from \"@/utils/config\";\nimport { getErrorMessage } from \"@/utils/error-handling\";\n\nimport type { Messages } from \"../types\";\n\nexport async function fetchMessages(\n payload: BasePayload,\n locale: string,\n): Promise<Messages> {\n if (!payload.config.serverURL) {\n throw new Error(\n \"serverURL is required in your payload.config.ts file for payload-intl to work.\",\n );\n }\n\n const {\n docs: [doc],\n } = await payload.find({\n collection: getPluginContext(payload.config).collectionSlug,\n where: { locale: { equals: locale } },\n });\n\n if (!doc) {\n console.warn(`No messages found for locale ${locale}`);\n return {};\n }\n\n const { url } = doc as unknown as { url: string };\n\n const response = await fetch(url);\n\n if (!response.ok) {\n const error = await getErrorMessage(response);\n throw new Error(\n `Could not fetch messages for locale \"${locale}\": ${error}`,\n );\n }\n\n if (response.headers.get(\"content-type\") !== \"application/json\") {\n throw new Error(\n `Could not fetch messages for locale \"${locale}\": The page did not return a JSON file.`,\n );\n }\n\n return await response.json();\n}\n\n/*\ntry {\n const response = await fetch(endpointUrl, {\n method: \"PUT\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(changes),\n });\n\n if (!response.ok) {\n const error = await response.json().catch(() => ({}));\n throw new Error(\n \"message\" in error ? error.message : \"Unknown error\"\n );\n }\n\n form.reset(currentValues);\n toast.success(\"Saved\", { id: toastId });\n } catch (error) {\n toast.error(\n `Failed to save: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n { id: toastId },\n );\n }\n };\n\n*/\n"],"names":["fetchMessages","payload","locale","doc","getPluginContext","url","response","error","getErrorMessage"],"mappings":";;AAOA,eAAsBA,EACpBC,GACAC,GACmB;AACnB,MAAI,CAACD,EAAQ,OAAO;AAClB,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAIJ,QAAM;AAAA,IACJ,MAAM,CAACE,CAAG;AAAA,EAAA,IACR,MAAMF,EAAQ,KAAK;AAAA,IACrB,YAAYG,EAAiBH,EAAQ,MAAM,EAAE;AAAA,IAC7C,OAAO,EAAE,QAAQ,EAAE,QAAQC,IAAO;AAAA,EAAE,CACrC;AAED,MAAI,CAACC;AACH,mBAAQ,KAAK,gCAAgCD,CAAM,EAAE,GAC9C,CAAA;AAGT,QAAM,EAAE,KAAAG,MAAQF,GAEVG,IAAW,MAAM,MAAMD,CAAG;AAEhC,MAAI,CAACC,EAAS,IAAI;AAChB,UAAMC,IAAQ,MAAMC,EAAgBF,CAAQ;AAC5C,UAAM,IAAI;AAAA,MACR,wCAAwCJ,CAAM,MAAMK,CAAK;AAAA,IAAA;AAAA,EAE7D;AAEA,MAAID,EAAS,QAAQ,IAAI,cAAc,MAAM;AAC3C,UAAM,IAAI;AAAA,MACR,wCAAwCJ,CAAM;AAAA,IAAA;AAIlD,SAAO,MAAMI,EAAS,KAAA;AACxB;"}