react-intlayer 2.0.0 → 2.0.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 (101) hide show
  1. package/dist/cjs/client/ContentEditionLayout.cjs +6 -2
  2. package/dist/cjs/client/ContentEditionLayout.cjs.map +1 -1
  3. package/dist/cjs/client/{IntlayerClientProvider.cjs → IntlayerProvider.cjs} +11 -9
  4. package/dist/cjs/client/IntlayerProvider.cjs.map +1 -0
  5. package/dist/cjs/client/{IntlayerClientProvider.d.ts → IntlayerProvider.d.ts} +4 -3
  6. package/dist/cjs/client/index.cjs +6 -6
  7. package/dist/cjs/client/index.cjs.map +1 -1
  8. package/dist/cjs/client/index.d.ts +2 -1
  9. package/dist/cjs/client/useIntlayer.cjs +2 -2
  10. package/dist/cjs/client/useIntlayer.cjs.map +1 -1
  11. package/dist/cjs/client/useIntlayer.d.ts +2 -1
  12. package/dist/cjs/client/useLocale.cjs +2 -2
  13. package/dist/cjs/client/useLocale.cjs.map +1 -1
  14. package/dist/cjs/client/useLocaleBase.cjs +2 -2
  15. package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
  16. package/dist/cjs/client/useTraduction.cjs +2 -2
  17. package/dist/cjs/client/useTraduction.cjs.map +1 -1
  18. package/dist/cjs/index.cjs +7 -4
  19. package/dist/cjs/index.cjs.map +1 -1
  20. package/dist/cjs/index.d.ts +3 -2
  21. package/dist/cjs/processDictionary/contentDictionary.cjs.map +1 -1
  22. package/dist/cjs/processDictionary/contentDictionary.d.ts +9 -9
  23. package/dist/cjs/processDictionary/index.cjs +67 -51
  24. package/dist/cjs/processDictionary/index.cjs.map +1 -1
  25. package/dist/cjs/processDictionary/index.d.ts +4 -4
  26. package/dist/cjs/server/IntlayerServerProvider.cjs +3 -4
  27. package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
  28. package/dist/cjs/server/IntlayerServerProvider.d.ts +1 -1
  29. package/dist/cjs/server/index.d.ts +1 -0
  30. package/dist/cjs/server/useIntlayer.d.ts +2 -1
  31. package/dist/cjs/useIntlayerBase.cjs +45 -1
  32. package/dist/cjs/useIntlayerBase.cjs.map +1 -1
  33. package/dist/cjs/useIntlayerBase.d.ts +51 -4
  34. package/dist/esm/client/ContentEditionLayout.mjs +5 -1
  35. package/dist/esm/client/ContentEditionLayout.mjs.map +1 -1
  36. package/dist/esm/client/{IntlayerClientProvider.d.mts → IntlayerProvider.d.mts} +4 -3
  37. package/dist/esm/client/{IntlayerClientProvider.mjs → IntlayerProvider.mjs} +7 -5
  38. package/dist/esm/client/IntlayerProvider.mjs.map +1 -0
  39. package/dist/esm/client/index.d.mts +2 -1
  40. package/dist/esm/client/index.mjs +4 -4
  41. package/dist/esm/client/index.mjs.map +1 -1
  42. package/dist/esm/client/useIntlayer.d.mts +2 -1
  43. package/dist/esm/client/useIntlayer.mjs +1 -1
  44. package/dist/esm/client/useIntlayer.mjs.map +1 -1
  45. package/dist/esm/client/useLocale.mjs +1 -1
  46. package/dist/esm/client/useLocale.mjs.map +1 -1
  47. package/dist/esm/client/useLocaleBase.mjs +1 -1
  48. package/dist/esm/client/useLocaleBase.mjs.map +1 -1
  49. package/dist/esm/client/useTraduction.mjs +1 -1
  50. package/dist/esm/client/useTraduction.mjs.map +1 -1
  51. package/dist/esm/index.d.mts +3 -2
  52. package/dist/esm/index.mjs +6 -4
  53. package/dist/esm/index.mjs.map +1 -1
  54. package/dist/esm/processDictionary/contentDictionary.d.mts +9 -9
  55. package/dist/esm/processDictionary/index.d.mts +4 -4
  56. package/dist/esm/processDictionary/index.mjs +67 -51
  57. package/dist/esm/processDictionary/index.mjs.map +1 -1
  58. package/dist/esm/server/IntlayerServerProvider.d.mts +1 -1
  59. package/dist/esm/server/IntlayerServerProvider.mjs +3 -4
  60. package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
  61. package/dist/esm/server/index.d.mts +1 -0
  62. package/dist/esm/server/useIntlayer.d.mts +2 -1
  63. package/dist/esm/useIntlayerBase.d.mts +51 -4
  64. package/dist/esm/useIntlayerBase.mjs +43 -1
  65. package/dist/esm/useIntlayerBase.mjs.map +1 -1
  66. package/package.json +8 -9
  67. package/src/index.ts +4 -3
  68. package/dist/cjs/IntlayerProvider.cjs +0 -37
  69. package/dist/cjs/IntlayerProvider.cjs.map +0 -1
  70. package/dist/cjs/IntlayerProvider.d.ts +0 -9
  71. package/dist/cjs/client/IntlayerClientProvider.cjs.map +0 -1
  72. package/dist/esm/IntlayerProvider.d.mts +0 -9
  73. package/dist/esm/IntlayerProvider.mjs +0 -18
  74. package/dist/esm/IntlayerProvider.mjs.map +0 -1
  75. package/dist/esm/client/IntlayerClientProvider.mjs.map +0 -1
  76. package/src/IntlayerProvider.tsx +0 -24
  77. package/src/cli/react-intlayer.ts +0 -60
  78. package/src/client/ContentEditionLayout.tsx +0 -15
  79. package/src/client/IntlayerClientProvider.tsx +0 -83
  80. package/src/client/getBrowserLocale.tsx +0 -192
  81. package/src/client/index.ts +0 -16
  82. package/src/client/useContent.ts +0 -20
  83. package/src/client/useIntlayer.ts +0 -25
  84. package/src/client/useLocale.ts +0 -23
  85. package/src/client/useLocaleBase.ts +0 -24
  86. package/src/client/useLocaleCookie.ts +0 -32
  87. package/src/client/useTraduction.ts +0 -33
  88. package/src/craco/craco.config.ts +0 -11
  89. package/src/craco/intlayerCracoPlugin.ts +0 -89
  90. package/src/getEnumeration.ts +0 -41
  91. package/src/getTranslation.ts +0 -37
  92. package/src/processDictionary/contentDictionary.ts +0 -28
  93. package/src/processDictionary/index.ts +0 -231
  94. package/src/server/IntlayerServerProvider.tsx +0 -36
  95. package/src/server/getLocaleTranslation.ts +0 -22
  96. package/src/server/index.ts +0 -8
  97. package/src/server/serverContext.ts +0 -85
  98. package/src/server/useIntlayer.ts +0 -23
  99. package/src/server/useTraduction.ts +0 -34
  100. package/src/useIntlayerBase.ts +0 -38
  101. package/src/vite/intlayerPlugin.ts +0 -59
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/IntlayerServerProvider.tsx"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport type { FC, PropsWithChildren } from 'react';\nimport { createServerContext, getServerContext } from './serverContext';\n\n/**\n * Context that store the current locale on the server side\n */\nexport const IntlayerServerContext = createServerContext<Locales>(\n getConfiguration().internationalization.defaultLocale\n);\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayer = () => getServerContext(IntlayerServerContext);\n\n/**\n * Get the current locale\n */\nexport const locale = getServerContext(IntlayerServerContext);\n\nexport type IntlayerServerProviderProps = PropsWithChildren & {\n locale: Locales;\n};\n\n/**\n * Provider that store the current locale on the server side\n */\nexport const IntlayerServerProvider: FC<IntlayerServerProviderProps> = ({\n children,\n locale,\n}) => (\n <IntlayerServerContext.Provider value={locale}>\n {children}\n </IntlayerServerContext.Provider>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgCE;AAhCF,oBAA+C;AAE/C,2BAAsD;AAK/C,MAAM,4BAAwB;AAAA,MACnC,gCAAiB,EAAE,qBAAqB;AAC1C;AAKO,MAAM,cAAc,UAAM,uCAAiB,qBAAqB;AAKhE,MAAM,aAAS,uCAAiB,qBAAqB;AASrD,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA,QAAAA;AACF,MACE,4CAAC,sBAAsB,UAAtB,EAA+B,OAAOA,SACpC,UACH;","names":["locale"]}
1
+ {"version":3,"sources":["../../../src/server/IntlayerServerProvider.tsx"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport type { FC, PropsWithChildren } from 'react';\nimport { createServerContext, getServerContext } from './serverContext';\n\nconst { defaultLocale } = getConfiguration().internationalization;\n\n/**\n * Context that store the current locale on the server side\n */\nexport const IntlayerServerContext =\n createServerContext<Locales>(defaultLocale);\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayer = () => getServerContext(IntlayerServerContext);\n\n/**\n * Get the current locale\n */\nexport const locale = getServerContext(IntlayerServerContext);\n\nexport type IntlayerServerProviderProps = PropsWithChildren & {\n locale?: Locales;\n};\n\n/**\n * Provider that store the current locale on the server side\n */\nexport const IntlayerServerProvider: FC<IntlayerServerProviderProps> = ({\n children,\n locale = defaultLocale,\n}) => (\n <IntlayerServerContext.Provider value={locale}>\n {children}\n </IntlayerServerContext.Provider>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiCE;AAjCF,oBAA+C;AAE/C,2BAAsD;AAEtD,MAAM,EAAE,cAAc,QAAI,gCAAiB,EAAE;AAKtC,MAAM,4BACX,0CAA6B,aAAa;AAKrC,MAAM,cAAc,UAAM,uCAAiB,qBAAqB;AAKhE,MAAM,aAAS,uCAAiB,qBAAqB;AASrD,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA,QAAAA,UAAS;AACX,MACE,4CAAC,sBAAsB,UAAtB,EAA+B,OAAOA,SACpC,UACH;","names":["locale"]}
@@ -27,7 +27,7 @@ declare const useIntlayer: () => Locales | undefined;
27
27
  */
28
28
  declare const locale: Locales | undefined;
29
29
  type IntlayerServerProviderProps = PropsWithChildren & {
30
- locale: Locales;
30
+ locale?: Locales;
31
31
  };
32
32
  /**
33
33
  * Provider that store the current locale on the server side
@@ -6,4 +6,5 @@ import '@intlayer/config/client';
6
6
  import '@intlayer/core';
7
7
  import 'react';
8
8
  import '../useIntlayerBase.js';
9
+ import '@intlayer/config';
9
10
  import 'intlayer';
@@ -1,6 +1,7 @@
1
1
  import { UseIntlayer } from '../useIntlayerBase.js';
2
- import '@intlayer/config/client';
2
+ import '@intlayer/config';
3
3
  import 'intlayer';
4
+ import 'react';
4
5
 
5
6
  /**
6
7
  * On the server side, Hook that picking one dictionary by its id and return the content
@@ -28,23 +28,67 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var useIntlayerBase_exports = {};
30
30
  __export(useIntlayerBase_exports, {
31
+ recursiveStringifyContent: () => recursiveStringifyContent,
32
+ recursiveTransformContent: () => recursiveTransformContent,
31
33
  useIntlayerBase: () => useIntlayerBase
32
34
  });
33
35
  module.exports = __toCommonJS(useIntlayerBase_exports);
34
36
  var import_dictionaries_entry = __toESM(require("@intlayer/dictionaries-entry"));
37
+ var import_client = require("intlayer-editor/client");
35
38
  var import_processDictionary = require('./processDictionary/index.cjs');
39
+ const recursiveTransformContent = (obj) => Object.entries(obj).reduce((acc, [key, value]) => {
40
+ if (typeof value === "object" && typeof value.keyPath !== "undefined" && typeof value.dictionaryId !== "undefined" && typeof value.dictionaryPath !== "undefined") {
41
+ return {
42
+ ...acc,
43
+ [key]: (0, import_client.renderIntlayerEditor)(value)
44
+ };
45
+ } else if (typeof value === "object" && Array.isArray(value)) {
46
+ return {
47
+ ...acc,
48
+ [key]: value.map(recursiveTransformContent)
49
+ };
50
+ } else if (typeof value === "object") {
51
+ return {
52
+ ...acc,
53
+ [key]: recursiveTransformContent(value)
54
+ };
55
+ }
56
+ return acc;
57
+ }, {});
58
+ const recursiveStringifyContent = (obj) => Object.entries(obj).reduce((acc, [key, value]) => {
59
+ if (typeof value === "object" && typeof value.value !== "undefined") {
60
+ return {
61
+ ...acc,
62
+ [key]: value.value
63
+ };
64
+ } else if (typeof value === "object" && Array.isArray(value)) {
65
+ return {
66
+ ...acc,
67
+ [key]: value.map(recursiveStringifyContent)
68
+ };
69
+ } else if (typeof value === "object") {
70
+ return {
71
+ ...acc,
72
+ [key]: recursiveStringifyContent(value)
73
+ };
74
+ }
75
+ return acc;
76
+ }, {});
36
77
  const useIntlayerBase = (id, locale) => {
37
78
  const dictionary = import_dictionaries_entry.default[id];
38
- return (0, import_processDictionary.processDictionary)(
79
+ const result = (0, import_processDictionary.processDictionary)(
39
80
  dictionary,
40
81
  id,
41
82
  dictionary.filePath,
42
83
  [],
43
84
  locale
44
85
  );
86
+ return recursiveTransformContent(result);
45
87
  };
46
88
  // Annotate the CommonJS export names for ESM import in node:
47
89
  0 && (module.exports = {
90
+ recursiveStringifyContent,
91
+ recursiveTransformContent,
48
92
  useIntlayerBase
49
93
  });
50
94
  //# sourceMappingURL=useIntlayerBase.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/useIntlayerBase.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport type { Content } from './processDictionary/contentDictionary';\nimport { processDictionary } from './processDictionary/index';\n\nexport type StringFallback<T> = T extends never ? string : T; // If no keys are found, return string to disable error, and accept any string as dictionary key\nexport type DictionaryKeys = StringFallback<\n keyof IntlayerDictionaryTypesConnector\n>;\n\nexport type UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => IntlayerDictionaryTypesConnector[T];\n\n/**\n * Hook that picking one dictionary by its id and return the content.\n */\nexport const useIntlayerBase: UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => {\n const dictionary: Content = dictionaries[id];\n\n return processDictionary(\n dictionary,\n id,\n dictionary.filePath as string,\n [],\n locale\n ) as IntlayerDictionaryTypesConnector[T];\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,gCAAyB;AAGzB,+BAAkC;AAe3B,MAAM,kBAA+B,CAC1C,IACA,WACG;AACH,QAAM,aAAsB,0BAAAA,QAAa,EAAE;AAE3C,aAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF;AACF;","names":["dictionaries"]}
1
+ {"version":3,"sources":["../../src/useIntlayerBase.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport type { Dictionary } from '@intlayer/core';\nimport dictionaries from '@intlayer/dictionaries-entry';\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport { renderIntlayerEditor } from 'intlayer-editor/client';\nimport type { ReactNode } from 'react';\nimport { processDictionary } from './processDictionary/index';\n\n/**\n * Provides a fallback to string type if the generic type T is never,\n * otherwise returns T. This is useful for handling cases where no keys are found.\n * Example: StringFallback<never> -> string; StringFallback<'key'> -> 'key'\n */\nexport type StringFallback<T> = T extends never ? string : T; // If no keys are found, return string to disable error, and accept any string as dictionary key\n\n/**\n * Represents the keys of the IntlayerDictionaryTypesConnector,\n * ensuring they are valid dictionary keys or fallback to string if none exist.\n *\n * Example:\n * ```ts\n * DictionaryKeys -> 'key1' | 'key2'\n * // or if IntlayerDictionaryTypesConnector is not defined,\n * DictionaryKeys -> string\n * ```\n */\nexport type DictionaryKeys = StringFallback<\n keyof IntlayerDictionaryTypesConnector\n>;\n\nexport type IntlayerNode = ReactNode & {\n value: string;\n};\n\ntype DeepTransformContent<T> = T extends object\n ? {\n [K in keyof T]: DeepTransformContent<T[K]>;\n }\n : IntlayerNode;\n\n/**\n * Excludes the 'id' and 'filePath' keys from the dictionary content,\n * as they are not part of the IntlayerDictionaryTypesConnector type.\n */\ntype ExcludeIntlayerUtilsKeys<T> = Omit<T, 'id' | 'filePath'>;\n\n/**\n * Represents the data type returned by the useIntlayer hook,\n * excluding the 'id' and 'filePath' keys from the dictionary content.\n */\ntype Data<T extends DictionaryKeys> = ExcludeIntlayerUtilsKeys<\n DeepTransformContent<IntlayerDictionaryTypesConnector[T]>\n>;\n\n/**\n * Parcourt the object. If a object has a keyPath, render the intlayer editor if editor enabled.\n */\nexport const recursiveTransformContent = (obj: object): object =>\n Object.entries(obj).reduce((acc, [key, value]) => {\n if (\n typeof value === 'object' &&\n typeof value.keyPath !== 'undefined' &&\n typeof value.dictionaryId !== 'undefined' &&\n typeof value.dictionaryPath !== 'undefined'\n ) {\n return {\n ...acc,\n [key]: renderIntlayerEditor(value),\n };\n } else if (typeof value === 'object' && Array.isArray(value)) {\n return {\n ...acc,\n [key]: value.map(recursiveTransformContent),\n };\n } else if (typeof value === 'object') {\n return {\n ...acc,\n [key]: recursiveTransformContent(value),\n };\n }\n\n return acc;\n }, {});\n\ntype DeepStrinfifyContent<T> =\n T extends React.ComponentType<unknown>\n ? string\n : T extends object\n ? {\n [K in keyof T]: DeepStrinfifyContent<T[K]>;\n }\n : T;\n\nexport const recursiveStringifyContent = <T extends object>(\n obj: T\n): DeepStrinfifyContent<T> =>\n Object.entries(obj).reduce((acc, [key, value]) => {\n if (typeof value === 'object' && typeof value.value !== 'undefined') {\n return {\n ...acc,\n [key]: value.value,\n };\n } else if (typeof value === 'object' && Array.isArray(value)) {\n return {\n ...acc,\n [key]: value.map(recursiveStringifyContent),\n };\n } else if (typeof value === 'object') {\n return {\n ...acc,\n [key]: recursiveStringifyContent(value),\n };\n }\n\n return acc;\n }, {}) as DeepStrinfifyContent<T>;\n\n/**\n * Type definition for the useIntlayer hook, which takes a dictionary ID and an optional locale,\n * and returns the deeply transformed dictionary content.\n *\n */\nexport type UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => Data<T>;\n\n/**\n * Hook that picks one dictionary by its ID and returns the content,\n * deeply transformed according to the dictionary structure and metadata.\n */\nexport const useIntlayerBase: UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => {\n const dictionary: Dictionary = dictionaries[id];\n\n const result = processDictionary(\n dictionary,\n id,\n dictionary.filePath,\n [],\n locale\n ) as object;\n\n return recursiveTransformContent(result) as Data<T>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,gCAAyB;AAEzB,oBAAqC;AAErC,+BAAkC;AAmD3B,MAAM,4BAA4B,CAAC,QACxC,OAAO,QAAQ,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM;AAChD,MACE,OAAO,UAAU,YACjB,OAAO,MAAM,YAAY,eACzB,OAAO,MAAM,iBAAiB,eAC9B,OAAO,MAAM,mBAAmB,aAChC;AACA,WAAO;AAAA,MACL,GAAG;AAAA,MACH,CAAC,GAAG,OAAG,oCAAqB,KAAK;AAAA,IACnC;AAAA,EACF,WAAW,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAAG;AAC5D,WAAO;AAAA,MACL,GAAG;AAAA,MACH,CAAC,GAAG,GAAG,MAAM,IAAI,yBAAyB;AAAA,IAC5C;AAAA,EACF,WAAW,OAAO,UAAU,UAAU;AACpC,WAAO;AAAA,MACL,GAAG;AAAA,MACH,CAAC,GAAG,GAAG,0BAA0B,KAAK;AAAA,IACxC;AAAA,EACF;AAEA,SAAO;AACT,GAAG,CAAC,CAAC;AAWA,MAAM,4BAA4B,CACvC,QAEA,OAAO,QAAQ,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM;AAChD,MAAI,OAAO,UAAU,YAAY,OAAO,MAAM,UAAU,aAAa;AACnE,WAAO;AAAA,MACL,GAAG;AAAA,MACH,CAAC,GAAG,GAAG,MAAM;AAAA,IACf;AAAA,EACF,WAAW,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAAG;AAC5D,WAAO;AAAA,MACL,GAAG;AAAA,MACH,CAAC,GAAG,GAAG,MAAM,IAAI,yBAAyB;AAAA,IAC5C;AAAA,EACF,WAAW,OAAO,UAAU,UAAU;AACpC,WAAO;AAAA,MACL,GAAG;AAAA,MACH,CAAC,GAAG,GAAG,0BAA0B,KAAK;AAAA,IACxC;AAAA,EACF;AAEA,SAAO;AACT,GAAG,CAAC,CAAC;AAgBA,MAAM,kBAA+B,CAC1C,IACA,WACG;AACH,QAAM,aAAyB,0BAAAA,QAAa,EAAE;AAE9C,QAAM,aAAS;AAAA,IACb;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF;AAEA,SAAO,0BAA0B,MAAM;AACzC;","names":["dictionaries"]}
@@ -1,12 +1,59 @@
1
- import { Locales } from '@intlayer/config/client';
1
+ import { Locales } from '@intlayer/config';
2
2
  import { IntlayerDictionaryTypesConnector } from 'intlayer';
3
+ import { ReactNode } from 'react';
3
4
 
5
+ /**
6
+ * Provides a fallback to string type if the generic type T is never,
7
+ * otherwise returns T. This is useful for handling cases where no keys are found.
8
+ * Example: StringFallback<never> -> string; StringFallback<'key'> -> 'key'
9
+ */
4
10
  type StringFallback<T> = T extends never ? string : T;
11
+ /**
12
+ * Represents the keys of the IntlayerDictionaryTypesConnector,
13
+ * ensuring they are valid dictionary keys or fallback to string if none exist.
14
+ *
15
+ * Example:
16
+ * ```ts
17
+ * DictionaryKeys -> 'key1' | 'key2'
18
+ * // or if IntlayerDictionaryTypesConnector is not defined,
19
+ * DictionaryKeys -> string
20
+ * ```
21
+ */
5
22
  type DictionaryKeys = StringFallback<keyof IntlayerDictionaryTypesConnector>;
6
- type UseIntlayer = <T extends DictionaryKeys>(id: T, locale?: Locales) => IntlayerDictionaryTypesConnector[T];
23
+ type IntlayerNode = ReactNode & {
24
+ value: string;
25
+ };
26
+ type DeepTransformContent<T> = T extends object ? {
27
+ [K in keyof T]: DeepTransformContent<T[K]>;
28
+ } : IntlayerNode;
29
+ /**
30
+ * Excludes the 'id' and 'filePath' keys from the dictionary content,
31
+ * as they are not part of the IntlayerDictionaryTypesConnector type.
32
+ */
33
+ type ExcludeIntlayerUtilsKeys<T> = Omit<T, 'id' | 'filePath'>;
34
+ /**
35
+ * Represents the data type returned by the useIntlayer hook,
36
+ * excluding the 'id' and 'filePath' keys from the dictionary content.
37
+ */
38
+ type Data<T extends DictionaryKeys> = ExcludeIntlayerUtilsKeys<DeepTransformContent<IntlayerDictionaryTypesConnector[T]>>;
39
+ /**
40
+ * Parcourt the object. If a object has a keyPath, render the intlayer editor if editor enabled.
41
+ */
42
+ declare const recursiveTransformContent: (obj: object) => object;
43
+ type DeepStrinfifyContent<T> = T extends React.ComponentType<unknown> ? string : T extends object ? {
44
+ [K in keyof T]: DeepStrinfifyContent<T[K]>;
45
+ } : T;
46
+ declare const recursiveStringifyContent: <T extends object>(obj: T) => DeepStrinfifyContent<T>;
47
+ /**
48
+ * Type definition for the useIntlayer hook, which takes a dictionary ID and an optional locale,
49
+ * and returns the deeply transformed dictionary content.
50
+ *
51
+ */
52
+ type UseIntlayer = <T extends DictionaryKeys>(id: T, locale?: Locales) => Data<T>;
7
53
  /**
8
- * Hook that picking one dictionary by its id and return the content.
54
+ * Hook that picks one dictionary by its ID and returns the content,
55
+ * deeply transformed according to the dictionary structure and metadata.
9
56
  */
10
57
  declare const useIntlayerBase: UseIntlayer;
11
58
 
12
- export { type DictionaryKeys, type StringFallback, type UseIntlayer, useIntlayerBase };
59
+ export { type DictionaryKeys, type IntlayerNode, type StringFallback, type UseIntlayer, recursiveStringifyContent, recursiveTransformContent, useIntlayerBase };
@@ -1,10 +1,14 @@
1
1
  import "../chunk-ZNCO4QRF.mjs";
2
2
  import { Fragment, jsx } from "react/jsx-runtime";
3
+ import { getConfiguration } from "@intlayer/config/client";
3
4
  import {
4
5
  ContentEditionLayout as ContentEditionLayoutBase
5
6
  } from "intlayer-editor/client";
7
+ const {
8
+ editor: { enabled }
9
+ } = getConfiguration();
6
10
  const BlankLayout = ({ children }) => /* @__PURE__ */ jsx(Fragment, { children });
7
- const ContentEditionLayout = typeof ContentEditionLayoutBase === "undefined" ? BlankLayout : ContentEditionLayoutBase;
11
+ const ContentEditionLayout = typeof ContentEditionLayoutBase === "undefined" || !enabled ? BlankLayout : ContentEditionLayoutBase;
8
12
  export {
9
13
  ContentEditionLayout
10
14
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/ContentEditionLayout.tsx"],"sourcesContent":["import {\n ContentEditionLayout as ContentEditionLayoutBase,\n type ContentEditionLayoutProps,\n} from 'intlayer-editor/client';\nimport type { FC } from 'react';\n\nconst BlankLayout: FC<ContentEditionLayoutProps> = ({ children }) => (\n <>{children}</>\n);\n\n// intlayer-editor is an optional dependency. If it's not installed, return the blank layout\nexport const ContentEditionLayout: FC<ContentEditionLayoutProps> =\n typeof ContentEditionLayoutBase === 'undefined'\n ? BlankLayout\n : (ContentEditionLayoutBase as typeof ContentEditionLayout);\n"],"mappings":";AAOE;AAPF;AAAA,EACE,wBAAwB;AAAA,OAEnB;AAGP,MAAM,cAA6C,CAAC,EAAE,SAAS,MAC7D,gCAAG,UAAS;AAIP,MAAM,uBACX,OAAO,6BAA6B,cAChC,cACC;","names":[]}
1
+ {"version":3,"sources":["../../../src/client/ContentEditionLayout.tsx"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\nimport {\n ContentEditionLayout as ContentEditionLayoutBase,\n type ContentEditionLayoutProps,\n} from 'intlayer-editor/client';\nimport type { FC } from 'react';\n\nconst {\n editor: { enabled },\n} = getConfiguration();\n\nconst BlankLayout: FC<ContentEditionLayoutProps> = ({ children }) => (\n <>{children}</>\n);\n\n// intlayer-editor is an optional dependency. If it's not installed, return the blank layout\nexport const ContentEditionLayout: FC<ContentEditionLayoutProps> =\n typeof ContentEditionLayoutBase === 'undefined' || !enabled\n ? BlankLayout\n : ContentEditionLayoutBase;\n"],"mappings":";AAYE;AAZF,SAAS,wBAAwB;AACjC;AAAA,EACE,wBAAwB;AAAA,OAEnB;AAGP,MAAM;AAAA,EACJ,QAAQ,EAAE,QAAQ;AACpB,IAAI,iBAAiB;AAErB,MAAM,cAA6C,CAAC,EAAE,SAAS,MAC7D,gCAAG,UAAS;AAIP,MAAM,uBACX,OAAO,6BAA6B,eAAe,CAAC,UAChD,cACA;","names":[]}
@@ -14,12 +14,13 @@ declare const IntlayerClientContext: react.Context<IntlayerValue>;
14
14
  * Hook that provides the current locale
15
15
  */
16
16
  declare const useIntlayerContext: () => IntlayerValue;
17
- type IntlayerClientProviderProps = PropsWithChildren & {
17
+ type IntlayerProviderProps = PropsWithChildren & {
18
18
  locale?: Locales;
19
+ setLocale?: (locale: Locales) => void;
19
20
  };
20
21
  /**
21
22
  * Provider that store the current locale on the client side
22
23
  */
23
- declare const IntlayerClientProvider: FC<IntlayerClientProviderProps>;
24
+ declare const IntlayerProvider: FC<IntlayerProviderProps>;
24
25
 
25
- export { IntlayerClientContext, IntlayerClientProvider, type IntlayerClientProviderProps, useIntlayerContext };
26
+ export { IntlayerClientContext, IntlayerProvider, type IntlayerProviderProps, useIntlayerContext };
@@ -16,15 +16,16 @@ const IntlayerClientContext = createContext({
16
16
  setLocale: () => null
17
17
  });
18
18
  const useIntlayerContext = () => useContext(IntlayerClientContext);
19
- const IntlayerClientProvider = ({
19
+ const IntlayerProvider = ({
20
20
  locale,
21
- children
21
+ children,
22
+ setLocale: setLocaleProp
22
23
  }) => {
23
24
  const { defaultLocale, locales: availableLocales } = getConfiguration().internationalization;
24
25
  const [currentLocale, setCurrentLocale] = useState(
25
26
  locale ?? localeCookie ?? defaultLocale
26
27
  );
27
- const setLocale = useCallback(
28
+ const setLocaleBase = useCallback(
28
29
  (newLocale) => {
29
30
  if (currentLocale.toString() === newLocale.toString())
30
31
  return;
@@ -37,6 +38,7 @@ const IntlayerClientProvider = ({
37
38
  },
38
39
  [availableLocales, currentLocale, locale]
39
40
  );
41
+ const setLocale = setLocaleProp ?? setLocaleBase;
40
42
  const value = useMemo(
41
43
  () => ({ locale: currentLocale, setLocale }),
42
44
  [currentLocale, setLocale]
@@ -53,7 +55,7 @@ const IntlayerClientProvider = ({
53
55
  };
54
56
  export {
55
57
  IntlayerClientContext,
56
- IntlayerClientProvider,
58
+ IntlayerProvider,
57
59
  useIntlayerContext
58
60
  };
59
- //# sourceMappingURL=IntlayerClientProvider.mjs.map
61
+ //# sourceMappingURL=IntlayerProvider.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport { getConfiguration, type Locales } from '@intlayer/config/client';\nimport {\n type PropsWithChildren,\n createContext,\n useContext,\n useMemo,\n type FC,\n useState,\n useCallback,\n} from 'react';\nimport { ContentEditionLayout } from './ContentEditionLayout';\nimport { localeCookie, setLocaleCookie } from './useLocaleCookie';\n\ntype IntlayerValue = {\n locale: Locales;\n setLocale: (newLocale: Locales) => void;\n};\n\n/**\n * Context that store the current locale on the client side\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeCookie ?? getConfiguration().internationalization.defaultLocale,\n setLocale: () => null,\n});\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\nexport type IntlayerProviderProps = PropsWithChildren & {\n locale?: Locales;\n setLocale?: (locale: Locales) => void;\n};\n\n/**\n * Provider that store the current locale on the client side\n */\nexport const IntlayerProvider: FC<IntlayerProviderProps> = ({\n locale,\n children,\n setLocale: setLocaleProp,\n}) => {\n const { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n\n const [currentLocale, setCurrentLocale] = useState(\n locale ?? localeCookie ?? defaultLocale\n );\n\n const setLocaleBase = useCallback(\n (newLocale: Locales) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales.includes(newLocale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale); // Update state\n setLocaleCookie(newLocale); // Optionally set cookie for persistence\n },\n [availableLocales, currentLocale, locale]\n );\n\n const setLocale = setLocaleProp ?? setLocaleBase;\n\n const value: IntlayerValue = useMemo<IntlayerValue>(\n () => ({ locale: currentLocale, setLocale: setLocale }),\n [currentLocale, setLocale]\n );\n\n return (\n <IntlayerClientContext.Provider value={value}>\n <ContentEditionLayout\n locale={currentLocale}\n setLocale={setLocale}\n localeList={availableLocales}\n >\n {children}\n </ContentEditionLayout>\n </IntlayerClientContext.Provider>\n );\n};\n"],"mappings":";;AA6EM;AA3EN,SAAS,wBAAsC;AAC/C;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AACP,SAAS,4BAA4B;AACrC,SAAS,cAAc,uBAAuB;AAUvC,MAAM,wBAAwB,cAA6B;AAAA,EAChE,QAAQ,gBAAgB,iBAAiB,EAAE,qBAAqB;AAAA,EAChE,WAAW,MAAM;AACnB,CAAC;AAKM,MAAM,qBAAqB,MAAM,WAAW,qBAAqB;AAUjE,MAAM,mBAA8C,CAAC;AAAA,EAC1D;AAAA,EACA;AAAA,EACA,WAAW;AACb,MAAM;AACJ,QAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,iBAAiB,EAAE;AAErB,QAAM,CAAC,eAAe,gBAAgB,IAAI;AAAA,IACxC,UAAU,gBAAgB;AAAA,EAC5B;AAEA,QAAM,gBAAgB;AAAA,IACpB,CAAC,cAAuB;AACtB,UAAI,cAAc,SAAS,MAAM,UAAU,SAAS;AAAG;AAEvD,UAAI,CAAC,iBAAiB,SAAS,SAAS,GAAG;AACzC,gBAAQ,MAAM,UAAU,MAAM,mBAAmB;AACjD;AAAA,MACF;AAEA,uBAAiB,SAAS;AAC1B,sBAAgB,SAAS;AAAA,IAC3B;AAAA,IACA,CAAC,kBAAkB,eAAe,MAAM;AAAA,EAC1C;AAEA,QAAM,YAAY,iBAAiB;AAEnC,QAAM,QAAuB;AAAA,IAC3B,OAAO,EAAE,QAAQ,eAAe,UAAqB;AAAA,IACrD,CAAC,eAAe,SAAS;AAAA,EAC3B;AAEA,SACE,oBAAC,sBAAsB,UAAtB,EAA+B,OAC9B;AAAA,IAAC;AAAA;AAAA,MACC,QAAQ;AAAA,MACR;AAAA,MACA,YAAY;AAAA,MAEX;AAAA;AAAA,EACH,GACF;AAEJ;","names":[]}
@@ -1,4 +1,4 @@
1
- export { IntlayerClientContext as IntlayerClient, IntlayerClientProvider, IntlayerClientProviderProps, useIntlayerContext } from './IntlayerClientProvider.mjs';
1
+ export { IntlayerClientContext, IntlayerProvider, IntlayerProviderProps, useIntlayerContext } from './IntlayerProvider.mjs';
2
2
  export { useIntlayer } from './useIntlayer.mjs';
3
3
  export { useLocaleBase } from './useLocaleBase.mjs';
4
4
  export { useLocale } from './useLocale.mjs';
@@ -8,5 +8,6 @@ export { getBrowserLocale } from './getBrowserLocale.mjs';
8
8
  import 'react';
9
9
  import '@intlayer/config/client';
10
10
  import '../useIntlayerBase.mjs';
11
+ import '@intlayer/config';
11
12
  import 'intlayer';
12
13
  import '@intlayer/core';
@@ -2,8 +2,8 @@ import "../chunk-ZNCO4QRF.mjs";
2
2
  import {
3
3
  IntlayerClientContext,
4
4
  useIntlayerContext,
5
- IntlayerClientProvider
6
- } from './IntlayerClientProvider.mjs';
5
+ IntlayerProvider
6
+ } from './IntlayerProvider.mjs';
7
7
  import { useIntlayer } from './useIntlayer.mjs';
8
8
  import { useLocaleBase } from './useLocaleBase.mjs';
9
9
  import { useLocale } from './useLocale.mjs';
@@ -15,8 +15,8 @@ import {
15
15
  } from './useLocaleCookie.mjs';
16
16
  import { getBrowserLocale } from './getBrowserLocale.mjs';
17
17
  export {
18
- IntlayerClientContext as IntlayerClient,
19
- IntlayerClientProvider,
18
+ IntlayerClientContext,
19
+ IntlayerProvider,
20
20
  getBrowserLocale,
21
21
  localeCookie,
22
22
  setLocaleCookie,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export type { IntlayerClientProviderProps } from './IntlayerClientProvider';\nexport {\n IntlayerClientContext as IntlayerClient,\n useIntlayerContext,\n IntlayerClientProvider,\n} from './IntlayerClientProvider';\nexport { useIntlayer } from './useIntlayer';\nexport { useLocaleBase } from './useLocaleBase';\nexport { useLocale } from './useLocale';\nexport { useTraduction } from './useTraduction';\nexport {\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n} from './useLocaleCookie';\nexport { getBrowserLocale } from './getBrowserLocale';\n"],"mappings":";AACA;AAAA,EAC2B;AAAA,EACzB;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;","names":[]}
1
+ {"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export {\n type IntlayerProviderProps,\n IntlayerClientContext,\n useIntlayerContext,\n IntlayerProvider,\n} from './IntlayerProvider';\nexport { useIntlayer } from './useIntlayer';\nexport { useLocaleBase } from './useLocaleBase';\nexport { useLocale } from './useLocale';\nexport { useTraduction } from './useTraduction';\nexport {\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n} from './useLocaleCookie';\nexport { getBrowserLocale } from './getBrowserLocale';\n"],"mappings":";AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;","names":[]}
@@ -1,6 +1,7 @@
1
1
  import { UseIntlayer } from '../useIntlayerBase.mjs';
2
- import '@intlayer/config/client';
2
+ import '@intlayer/config';
3
3
  import 'intlayer';
4
+ import 'react';
4
5
 
5
6
  /**
6
7
  * On the client side, Hook that picking one dictionary by its id and return the content
@@ -4,7 +4,7 @@ import { useContext } from "react";
4
4
  import {
5
5
  useIntlayerBase
6
6
  } from '../useIntlayerBase.mjs';
7
- import { IntlayerClientContext } from './IntlayerClientProvider.mjs';
7
+ import { IntlayerClientContext } from './IntlayerProvider.mjs';
8
8
  const useIntlayer = (id, locale) => {
9
9
  const { locale: currentLocale } = useContext(IntlayerClientContext);
10
10
  const localeTarget = locale ?? currentLocale;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useContext } from 'react';\nimport {\n type DictionaryKeys,\n useIntlayerBase,\n type UseIntlayer,\n} from '../useIntlayerBase';\nimport { IntlayerClientContext } from './IntlayerClientProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useIntlayer: UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return useIntlayerBase(id, localeTarget);\n};\n"],"mappings":";;AAGA,SAAS,kBAAkB;AAC3B;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,6BAA6B;AAO/B,MAAM,cAA2B,CACtC,IACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,SAAO,gBAAgB,IAAI,YAAY;AACzC;","names":[]}
1
+ {"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useContext } from 'react';\nimport {\n type DictionaryKeys,\n useIntlayerBase,\n type UseIntlayer,\n} from '../useIntlayerBase';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useIntlayer: UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return useIntlayerBase(id, localeTarget);\n};\n"],"mappings":";;AAGA,SAAS,kBAAkB;AAC3B;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,6BAA6B;AAO/B,MAAM,cAA2B,CACtC,IACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,SAAO,gBAAgB,IAAI,YAAY;AACzC;","names":[]}
@@ -3,7 +3,7 @@ import "../chunk-ZNCO4QRF.mjs";
3
3
  import { getConfiguration } from "@intlayer/config/client";
4
4
  import { localeList } from "@intlayer/core";
5
5
  import { useContext } from "react";
6
- import { IntlayerClientContext } from './IntlayerClientProvider.mjs';
6
+ import { IntlayerClientContext } from './IntlayerProvider.mjs';
7
7
  const useLocale = () => {
8
8
  const { defaultLocale, locales: availableLocales } = getConfiguration().internationalization;
9
9
  const { locale, setLocale } = useContext(IntlayerClientContext);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerClientProvider';\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocale = () => {\n const { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n const { locale, setLocale } = useContext(IntlayerClientContext);\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n localeList, // List of all available locales\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;AAEA,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AAK/B,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,iBAAiB,EAAE;AACrB,QAAM,EAAE,QAAQ,UAAU,IAAI,WAAW,qBAAqB;AAE9D,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocale = () => {\n const { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n const { locale, setLocale } = useContext(IntlayerClientContext);\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n localeList, // List of all available locales\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;AAEA,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AAK/B,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,iBAAiB,EAAE;AACrB,QAAM,EAAE,QAAQ,UAAU,IAAI,WAAW,qBAAqB;AAE9D,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
@@ -3,7 +3,7 @@ import "../chunk-ZNCO4QRF.mjs";
3
3
  import { getConfiguration } from "@intlayer/config/client";
4
4
  import { localeList } from "@intlayer/core";
5
5
  import { useContext } from "react";
6
- import { IntlayerClientContext } from './IntlayerClientProvider.mjs';
6
+ import { IntlayerClientContext } from './IntlayerProvider.mjs';
7
7
  const { defaultLocale, locales: availableLocales } = getConfiguration().internationalization;
8
8
  const useLocaleBase = () => {
9
9
  const { locale, setLocale } = useContext(IntlayerClientContext);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerClientProvider';\n\nconst { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocaleBase = () => {\n const { locale, setLocale } = useContext(IntlayerClientContext);\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n localeList, // List of all available locales\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;AAEA,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AAEtC,MAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,iBAAiB,EAAE;AAKd,MAAM,gBAAgB,MAAM;AACjC,QAAM,EAAE,QAAQ,UAAU,IAAI,WAAW,qBAAqB;AAE9D,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\nconst { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocaleBase = () => {\n const { locale, setLocale } = useContext(IntlayerClientContext);\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n localeList, // List of all available locales\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;AAEA,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AAEtC,MAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,iBAAiB,EAAE;AAKd,MAAM,gBAAgB,MAAM;AACjC,QAAM,EAAE,QAAQ,UAAU,IAAI,WAAW,qBAAqB;AAE9D,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
@@ -1,7 +1,7 @@
1
1
  import "../chunk-ZNCO4QRF.mjs";
2
2
  import { useContext } from "react";
3
3
  import { getTranslation } from '../getTranslation.mjs';
4
- import { IntlayerClientContext } from './IntlayerClientProvider.mjs';
4
+ import { IntlayerClientContext } from './IntlayerProvider.mjs';
5
5
  const useTraduction = (languageContent) => {
6
6
  const { locale } = useContext(IntlayerClientContext);
7
7
  return getTranslation(languageContent, locale);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { getTranslation } from '../getTranslation';\nimport { IntlayerClientContext } from './IntlayerClientProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```tsx\n * const content = useTraduction<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const useTraduction = <Content = string>(\n languageContent: LanguageContent<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return getTranslation(languageContent, locale);\n};\n"],"mappings":";AACA,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AAuB/B,MAAM,gBAAgB,CAC3B,oBACY;AACZ,QAAM,EAAE,OAAO,IAAI,WAAW,qBAAqB;AAEnD,SAAO,eAAe,iBAAiB,MAAM;AAC/C;","names":[]}
1
+ {"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { getTranslation } from '../getTranslation';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```tsx\n * const content = useTraduction<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const useTraduction = <Content = string>(\n languageContent: LanguageContent<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return getTranslation(languageContent, locale);\n};\n"],"mappings":";AACA,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AAuB/B,MAAM,gBAAgB,CAC3B,oBACY;AACZ,QAAM,EAAE,OAAO,IAAI,WAAW,qBAAqB;AAEnD,SAAO,eAAe,iBAAiB,MAAM;AAC/C;","names":[]}
@@ -1,13 +1,14 @@
1
1
  export { getTranslation } from './getTranslation.mjs';
2
- export { IntlayerClientContext as IntlayerClient, IntlayerClientProvider, IntlayerClientProviderProps } from './client/IntlayerClientProvider.mjs';
2
+ export { IntlayerClientContext, IntlayerProvider, IntlayerProviderProps } from './client/IntlayerProvider.mjs';
3
3
  export { useIntlayer } from './client/useIntlayer.mjs';
4
4
  export { useLocaleBase } from './client/useLocaleBase.mjs';
5
5
  export { useLocale } from './client/useLocale.mjs';
6
6
  export { useTraduction } from './client/useTraduction.mjs';
7
7
  export { localeCookie, setLocaleCookie, useLocaleCookie } from './client/useLocaleCookie.mjs';
8
8
  export { getBrowserLocale } from './client/getBrowserLocale.mjs';
9
+ export { recursiveStringifyContent } from './useIntlayerBase.mjs';
9
10
  import '@intlayer/config/client';
10
11
  import '@intlayer/core';
11
12
  import 'react';
12
- import './useIntlayerBase.mjs';
13
+ import '@intlayer/config';
13
14
  import 'intlayer';
@@ -1,8 +1,8 @@
1
1
  import "./chunk-ZNCO4QRF.mjs";
2
2
  import { getTranslation } from './getTranslation.mjs';
3
3
  import {
4
- IntlayerClientProvider,
5
- IntlayerClient,
4
+ IntlayerProvider,
5
+ IntlayerClientContext,
6
6
  useIntlayer,
7
7
  useLocale,
8
8
  useTraduction,
@@ -12,12 +12,14 @@ import {
12
12
  getBrowserLocale,
13
13
  useLocaleBase
14
14
  } from './client/index.mjs';
15
+ import { recursiveStringifyContent } from './useIntlayerBase.mjs';
15
16
  export {
16
- IntlayerClient,
17
- IntlayerClientProvider,
17
+ IntlayerClientContext,
18
+ IntlayerProvider,
18
19
  getBrowserLocale,
19
20
  getTranslation,
20
21
  localeCookie,
22
+ recursiveStringifyContent,
21
23
  setLocaleCookie,
22
24
  useIntlayer,
23
25
  useLocale,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { getTranslation } from './getTranslation';\nexport {\n IntlayerClientProvider,\n type IntlayerClientProviderProps,\n IntlayerClient,\n useIntlayer,\n useLocale,\n useTraduction,\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n getBrowserLocale,\n useLocaleBase,\n} from './client/index';\n"],"mappings":";AAAA,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { getTranslation } from './getTranslation';\nexport {\n IntlayerProvider,\n type IntlayerProviderProps,\n IntlayerClientContext,\n useIntlayer,\n useLocale,\n useTraduction,\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n getBrowserLocale,\n useLocaleBase,\n} from './client/index';\nexport { recursiveStringifyContent } from './useIntlayerBase';\n"],"mappings":";AAAA,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iCAAiC;","names":[]}
@@ -1,16 +1,16 @@
1
- import { TranslationContent } from '@intlayer/core';
1
+ import { KeyPath, Locales } from '@intlayer/core';
2
2
  import { ReactNode } from 'react';
3
3
 
4
- type ContentValue = string | {
5
- [key: string]: ContentValue;
6
- } | TranslationContent<unknown>;
7
- type Content = Record<string, ContentValue | undefined>;
8
4
  type TransformedContentValue = string | ReactNode | {
9
5
  [key: string]: TransformedContentValue;
10
6
  } | undefined | ((quantity: number) => TransformedContentValue);
11
- type TransformedContent = Record<string, TransformedContentValue | undefined> | ReactNode;
12
- type ContentDictionary = Content & {
13
- id: string;
7
+ type TransformedContentObject = {
8
+ dictionaryId: string;
9
+ dictionaryPath: string;
10
+ keyPath: KeyPath[];
11
+ locale: Locales;
12
+ content: TransformedContentValue | TransformedContentValue[] | undefined;
14
13
  };
14
+ type TransformedContent = Record<string, TransformedContentValue | TransformedContentValue[] | TransformedContentObject | undefined> | ReactNode;
15
15
 
16
- export type { Content, ContentDictionary, ContentValue, TransformedContent, TransformedContentValue };
16
+ export type { TransformedContent, TransformedContentObject, TransformedContentValue };
@@ -1,12 +1,12 @@
1
1
  import { Locales } from '@intlayer/config/client';
2
- import { KeyPath } from '@intlayer/core';
3
- import { ContentValue, TransformedContentValue, Content, TransformedContent } from './contentDictionary.mjs';
2
+ import { DictionaryValue, KeyPath, Dictionary } from '@intlayer/core';
3
+ import { TransformedContentValue, TransformedContent } from './contentDictionary.mjs';
4
4
  import 'react';
5
5
 
6
- declare const processNode: (field: ContentValue | undefined, locale: Locales, dictionaryId: string, dictionaryPath: string, keyPath?: KeyPath[]) => TransformedContentValue;
6
+ declare const processNode: (field: DictionaryValue | undefined, locale: Locales, dictionaryId: string, dictionaryPath: string, keyPath?: KeyPath[]) => TransformedContentValue;
7
7
  /**
8
8
  * Function that process a dictionary and return the result to be used in the application.
9
9
  */
10
- declare const processDictionary: (content: Content, dictionaryId: string, dictionaryPath: string, keyPath?: KeyPath[], locale?: Locales) => TransformedContent;
10
+ declare const processDictionary: (content: Dictionary | DictionaryValue, dictionaryId: string, dictionaryPath: string, keyPath?: KeyPath[], locale?: Locales) => TransformedContent;
11
11
 
12
12
  export { processDictionary, processNode };