react-intlayer 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/dist/cjs/ContentEditor/ContentEditor.cjs +36 -39
  2. package/dist/cjs/ContentEditor/ContentEditor.d.ts +2 -2
  3. package/dist/cjs/ContentEditor/contentRender.cjs +10 -18
  4. package/dist/cjs/ContentEditor/index.cjs +11 -27
  5. package/dist/cjs/ContentEditor/index.d.ts +3 -3
  6. package/dist/cjs/IntlayerProvider.cjs +37 -0
  7. package/dist/cjs/IntlayerProvider.cjs.map +1 -0
  8. package/dist/cjs/IntlayerProvider.d.ts +9 -0
  9. package/dist/cjs/client/IntlayerClientProvider.cjs +45 -0
  10. package/dist/cjs/client/IntlayerClientProvider.cjs.map +1 -0
  11. package/dist/cjs/client/IntlayerClientProvider.d.ts +24 -0
  12. package/dist/cjs/client/index.cjs +24 -31
  13. package/dist/cjs/client/index.cjs.map +1 -1
  14. package/dist/cjs/client/index.d.ts +10 -19
  15. package/dist/cjs/client/useContent.cjs +11 -16
  16. package/dist/cjs/client/useContent.cjs.map +1 -1
  17. package/dist/cjs/client/useContent.d.ts +10 -8
  18. package/dist/cjs/client/useIntlayer.cjs +11 -18
  19. package/dist/cjs/client/useIntlayer.cjs.map +1 -1
  20. package/dist/cjs/client/useIntlayer.d.ts +8 -3
  21. package/dist/cjs/client/useLocale.cjs +12 -20
  22. package/dist/cjs/client/useLocale.cjs.map +1 -1
  23. package/dist/cjs/client/useLocale.d.ts +8 -5
  24. package/dist/cjs/client/useLocaleCookie.cjs +20 -30
  25. package/dist/cjs/client/useLocaleCookie.cjs.map +1 -1
  26. package/dist/cjs/client/useLocaleCookie.d.ts +12 -3
  27. package/dist/cjs/client/useTraduction.cjs +11 -18
  28. package/dist/cjs/client/useTraduction.cjs.map +1 -1
  29. package/dist/cjs/client/useTraduction.d.ts +22 -4
  30. package/dist/cjs/getEnumeration.cjs +9 -14
  31. package/dist/cjs/getEnumeration.cjs.map +1 -1
  32. package/dist/cjs/getEnumeration.d.ts +27 -5
  33. package/dist/cjs/getTranslation.cjs +9 -14
  34. package/dist/cjs/getTranslation.cjs.map +1 -1
  35. package/dist/cjs/getTranslation.d.ts +23 -6
  36. package/dist/cjs/index.cjs +20 -27
  37. package/dist/cjs/index.cjs.map +1 -1
  38. package/dist/cjs/index.d.ts +11 -20
  39. package/dist/cjs/processDictionary/contentDictionary.d.cjs +4 -8
  40. package/dist/cjs/processDictionary/contentDictionary.d.d.ts +6 -9
  41. package/dist/cjs/processDictionary/index.cjs +15 -17
  42. package/dist/cjs/processDictionary/index.cjs.map +1 -1
  43. package/dist/cjs/processDictionary/index.d.ts +6 -17
  44. package/dist/cjs/server/IntlayerServerProvider.cjs +46 -0
  45. package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -0
  46. package/dist/cjs/server/IntlayerServerProvider.d.ts +37 -0
  47. package/dist/cjs/server/getLocaleTranslation.cjs +12 -19
  48. package/dist/cjs/server/getLocaleTranslation.cjs.map +1 -1
  49. package/dist/cjs/server/getLocaleTranslation.d.ts +8 -7
  50. package/dist/cjs/server/index.cjs +20 -27
  51. package/dist/cjs/server/index.cjs.map +1 -1
  52. package/dist/cjs/server/index.d.ts +9 -13
  53. package/dist/cjs/server/serverContext.cjs +25 -31
  54. package/dist/cjs/server/serverContext.cjs.map +1 -1
  55. package/dist/cjs/server/serverContext.d.ts +16 -24
  56. package/dist/cjs/server/useIntlayer.cjs +12 -21
  57. package/dist/cjs/server/useIntlayer.cjs.map +1 -1
  58. package/dist/cjs/server/useIntlayer.d.ts +8 -3
  59. package/dist/cjs/server/useTraduction.cjs +12 -19
  60. package/dist/cjs/server/useTraduction.cjs.map +1 -1
  61. package/dist/cjs/server/useTraduction.d.ts +22 -4
  62. package/dist/cjs/useIntlayerBase.cjs +22 -31
  63. package/dist/cjs/useIntlayerBase.cjs.map +1 -1
  64. package/dist/cjs/useIntlayerBase.d.ts +7 -18
  65. package/dist/esm/ContentEditor/ContentEditor.d.mts +2 -2
  66. package/dist/esm/ContentEditor/ContentEditor.mjs +38 -29
  67. package/dist/esm/ContentEditor/contentRender.mjs +5 -3
  68. package/dist/esm/ContentEditor/index.d.mts +3 -3
  69. package/dist/esm/ContentEditor/index.mjs +3 -3
  70. package/dist/esm/IntlayerProvider.d.mts +9 -0
  71. package/dist/esm/IntlayerProvider.mjs +17 -0
  72. package/dist/esm/IntlayerProvider.mjs.map +1 -0
  73. package/dist/esm/client/IntlayerClientProvider.d.mts +24 -0
  74. package/dist/esm/client/IntlayerClientProvider.mjs +24 -0
  75. package/dist/esm/client/IntlayerClientProvider.mjs.map +1 -0
  76. package/dist/esm/client/index.d.mts +10 -19
  77. package/dist/esm/client/index.mjs +14 -14
  78. package/dist/esm/client/index.mjs.map +1 -1
  79. package/dist/esm/client/useContent.d.mts +10 -8
  80. package/dist/esm/client/useContent.mjs +7 -5
  81. package/dist/esm/client/useContent.mjs.map +1 -1
  82. package/dist/esm/client/useIntlayer.d.mts +8 -3
  83. package/dist/esm/client/useIntlayer.mjs +9 -5
  84. package/dist/esm/client/useIntlayer.mjs.map +1 -1
  85. package/dist/esm/client/useLocale.d.mts +8 -5
  86. package/dist/esm/client/useLocale.mjs +7 -5
  87. package/dist/esm/client/useLocale.mjs.map +1 -1
  88. package/dist/esm/client/useLocaleCookie.d.mts +12 -3
  89. package/dist/esm/client/useLocaleCookie.mjs +11 -5
  90. package/dist/esm/client/useLocaleCookie.mjs.map +1 -1
  91. package/dist/esm/client/useTraduction.d.mts +22 -4
  92. package/dist/esm/client/useTraduction.mjs +7 -5
  93. package/dist/esm/client/useTraduction.mjs.map +1 -1
  94. package/dist/esm/getEnumeration.d.mts +27 -5
  95. package/dist/esm/getEnumeration.mjs +9 -4
  96. package/dist/esm/getEnumeration.mjs.map +1 -1
  97. package/dist/esm/getTranslation.d.mts +23 -6
  98. package/dist/esm/getTranslation.mjs +8 -4
  99. package/dist/esm/getTranslation.mjs.map +1 -1
  100. package/dist/esm/index.d.mts +11 -20
  101. package/dist/esm/index.mjs +9 -11
  102. package/dist/esm/index.mjs.map +1 -1
  103. package/dist/esm/processDictionary/contentDictionary.d.d.mts +6 -9
  104. package/dist/esm/processDictionary/contentDictionary.d.mjs +1 -1
  105. package/dist/esm/processDictionary/index.d.mts +6 -17
  106. package/dist/esm/processDictionary/index.mjs +25 -9
  107. package/dist/esm/processDictionary/index.mjs.map +1 -1
  108. package/dist/esm/server/IntlayerServerProvider.d.mts +37 -0
  109. package/dist/esm/server/IntlayerServerProvider.mjs +21 -0
  110. package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -0
  111. package/dist/esm/server/getLocaleTranslation.d.mts +8 -7
  112. package/dist/esm/server/getLocaleTranslation.mjs +8 -6
  113. package/dist/esm/server/getLocaleTranslation.mjs.map +1 -1
  114. package/dist/esm/server/index.d.mts +9 -13
  115. package/dist/esm/server/index.mjs +10 -10
  116. package/dist/esm/server/index.mjs.map +1 -1
  117. package/dist/esm/server/serverContext.d.mts +16 -24
  118. package/dist/esm/server/serverContext.mjs +13 -6
  119. package/dist/esm/server/serverContext.mjs.map +1 -1
  120. package/dist/esm/server/useIntlayer.d.mts +8 -3
  121. package/dist/esm/server/useIntlayer.mjs +10 -6
  122. package/dist/esm/server/useIntlayer.mjs.map +1 -1
  123. package/dist/esm/server/useTraduction.d.mts +22 -4
  124. package/dist/esm/server/useTraduction.mjs +8 -6
  125. package/dist/esm/server/useTraduction.mjs.map +1 -1
  126. package/dist/esm/useIntlayerBase.d.mts +7 -18
  127. package/dist/esm/useIntlayerBase.mjs +9 -4
  128. package/dist/esm/useIntlayerBase.mjs.map +1 -1
  129. package/package.json +10 -10
  130. package/src/IntlayerProvider.tsx +24 -0
  131. package/src/client/IntlayerClientProvider.tsx +45 -0
  132. package/src/client/index.ts +5 -5
  133. package/src/client/useContent.ts +3 -0
  134. package/src/client/useIntlayer.ts +7 -2
  135. package/src/client/useLocale.ts +5 -2
  136. package/src/client/useLocaleCookie.ts +9 -1
  137. package/src/client/useTraduction.ts +23 -3
  138. package/src/getEnumeration.ts +25 -0
  139. package/src/getTranslation.ts +21 -1
  140. package/src/index.ts +3 -4
  141. package/src/processDictionary/index.ts +1 -1
  142. package/src/server/IntlayerServerProvider.tsx +39 -0
  143. package/src/server/getLocaleTranslation.ts +5 -2
  144. package/src/server/index.ts +3 -3
  145. package/src/server/serverContext.ts +4 -4
  146. package/src/server/useIntlayer.ts +8 -2
  147. package/src/server/useTraduction.ts +23 -3
  148. package/src/useIntlayerBase.ts +4 -1
  149. package/dist/cjs/LocaleContextProvider.cjs +0 -49
  150. package/dist/cjs/LocaleContextProvider.cjs.map +0 -1
  151. package/dist/cjs/LocaleContextProvider.d.ts +0 -10
  152. package/dist/cjs/client/LocaleClientContextProvider.cjs +0 -54
  153. package/dist/cjs/client/LocaleClientContextProvider.cjs.map +0 -1
  154. package/dist/cjs/client/LocaleClientContextProvider.d.ts +0 -20
  155. package/dist/cjs/server/LocaleServerContextProvider.cjs +0 -49
  156. package/dist/cjs/server/LocaleServerContextProvider.cjs.map +0 -1
  157. package/dist/cjs/server/LocaleServerContextProvider.d.ts +0 -34
  158. package/dist/esm/LocaleContextProvider.d.mts +0 -10
  159. package/dist/esm/LocaleContextProvider.mjs +0 -15
  160. package/dist/esm/LocaleContextProvider.mjs.map +0 -1
  161. package/dist/esm/client/LocaleClientContextProvider.d.mts +0 -20
  162. package/dist/esm/client/LocaleClientContextProvider.mjs +0 -16
  163. package/dist/esm/client/LocaleClientContextProvider.mjs.map +0 -1
  164. package/dist/esm/server/LocaleServerContextProvider.d.mts +0 -34
  165. package/dist/esm/server/LocaleServerContextProvider.mjs +0 -14
  166. package/dist/esm/server/LocaleServerContextProvider.mjs.map +0 -1
  167. package/src/LocaleContextProvider.tsx +0 -26
  168. package/src/client/LocaleClientContextProvider.tsx +0 -35
  169. package/src/server/LocaleServerContextProvider.tsx +0 -24
@@ -8,28 +8,24 @@ var __export = (target, all) => {
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
9
9
  };
10
10
  var __copyProps = (to, from, except, desc) => {
11
- if ((from && typeof from === "object") || typeof from === "function") {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
12
  for (let key of __getOwnPropNames(from))
13
13
  if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, {
15
- get: () => from[key],
16
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
17
- });
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
15
  }
19
16
  return to;
20
17
  };
21
- var __toCommonJS = (mod) =>
22
- __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
19
  var processDictionary_exports = {};
24
20
  __export(processDictionary_exports, {
25
21
  processDictionary: () => processDictionary,
26
- processNode: () => processNode,
22
+ processNode: () => processNode
27
23
  });
28
24
  module.exports = __toCommonJS(processDictionary_exports);
29
25
  var import_client = require("@intlayer/config/client");
30
26
  var import_core = require("@intlayer/core");
31
- var import_getEnumeration = require("../getEnumeration.cjs");
32
- var import_getTranslation = require("../getTranslation.cjs");
27
+ var import_getEnumeration = require('../getEnumeration.cjs');
28
+ var import_getTranslation = require('../getTranslation.cjs');
33
29
  const defaultLocale = import_client.intlayerIntlConfiguration.defaultLocale;
34
30
  const processTranslation = (languageContent, locale) => {
35
31
  const translationResult = (0, import_getTranslation.getTranslation)(
@@ -55,7 +51,10 @@ const processNode = (field, locale) => {
55
51
  return processTranslation(field, locale);
56
52
  }
57
53
  if (field.nodeType === import_core.NodeType.Enumeration) {
58
- return processEnumeration(field, locale);
54
+ return processEnumeration(
55
+ field,
56
+ locale
57
+ );
59
58
  }
60
59
  if (typeof field.type === "undefined") {
61
60
  return processDictionary(field, locale);
@@ -74,9 +73,8 @@ const processDictionary = (content, locale = defaultLocale) => {
74
73
  return content;
75
74
  };
76
75
  // Annotate the CommonJS export names for ESM import in node:
77
- 0 &&
78
- (module.exports = {
79
- processDictionary,
80
- processNode,
81
- });
82
- //# sourceMappingURL=index.cjs.map
76
+ 0 && (module.exports = {
77
+ processDictionary,
78
+ processNode
79
+ });
80
+ //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/processDictionary/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n type Locales,\n intlayerIntlConfiguration,\n} from '@intlayer/config/client';\nimport {\n NodeType,\n type QuantityContent,\n type LanguageContent,\n} from '@intlayer/core';\nimport { getEnumeration } from '../getEnumeration';\nimport { getTranslation } from '../getTranslation';\nimport type {\n Content,\n ContentValue,\n TransformedContent,\n TransformedContentValue,\n} from './contentDictionary';\n\nconst defaultLocale = intlayerIntlConfiguration.defaultLocale;\n\nconst processTranslation = (\n languageContent: LanguageContent<ContentValue>,\n locale: Locales\n): TransformedContent => {\n const translationResult: ContentValue = getTranslation<ContentValue>(\n languageContent,\n locale\n );\n\n return processDictionary(translationResult as Content, locale);\n};\n\nconst processEnumeration = (\n enumerationContent: QuantityContent<ContentValue>,\n locale: Locales\n): TransformedContentValue => {\n return (quantity: number): TransformedContentValue => {\n const enumerationResult: ContentValue = getEnumeration<ContentValue>(\n enumerationContent,\n quantity\n );\n\n //\n return processDictionary(enumerationResult as Content, locale);\n };\n};\n\nexport const processNode = (\n field: ContentValue | undefined,\n locale: Locales\n): TransformedContentValue => {\n if (typeof field !== 'object' || field === null) {\n return field;\n }\n\n if (field.nodeType === NodeType.Translation) {\n return processTranslation(field as LanguageContent<ContentValue>, locale);\n }\n\n if (field.nodeType === NodeType.Enumeration) {\n return processEnumeration(\n field satisfies QuantityContent<ContentValue>,\n locale\n );\n }\n\n if (typeof (field as any).type === 'undefined') {\n return processDictionary(field as Content, locale);\n }\n\n return field as TransformedContentValue;\n};\n\n/**\n * Function to replace the multi lingual content with content in the current locale\n */\nexport const processDictionary = (\n content: Content,\n locale: Locales = defaultLocale\n): TransformedContent => {\n if (content && typeof content === 'object') {\n const result: TransformedContent = {};\n\n // List each key in the content and process it\n for (const key of Object.keys(content)) {\n const field = content[key];\n\n result[key] = processNode(field, locale);\n }\n\n return result;\n }\n\n // If it's a string, number, or function, return it\n return content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAGO;AACP,kBAIO;AACP,4BAA+B;AAC/B,4BAA+B;AAQ/B,MAAM,gBAAgB,wCAA0B;AAEhD,MAAM,qBAAqB,CACzB,iBACA,WACuB;AACvB,QAAM,wBAAkC;AAAA,IACtC;AAAA,IACA;AAAA,EACF;AAEA,SAAO,kBAAkB,mBAA8B,MAAM;AAC/D;AAEA,MAAM,qBAAqB,CACzB,oBACA,WAC4B;AAC5B,SAAO,CAAC,aAA8C;AACpD,UAAM,wBAAkC;AAAA,MACtC;AAAA,MACA;AAAA,IACF;AAGA,WAAO,kBAAkB,mBAA8B,MAAM;AAAA,EAC/D;AACF;AAEO,MAAM,cAAc,CACzB,OACA,WAC4B;AAC5B,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,aAAa,qBAAS,aAAa;AAC3C,WAAO,mBAAmB,OAAwC,MAAM;AAAA,EAC1E;AAEA,MAAI,MAAM,aAAa,qBAAS,aAAa;AAC3C,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,MAAI,OAAQ,MAAc,SAAS,aAAa;AAC9C,WAAO,kBAAkB,OAAkB,MAAM;AAAA,EACnD;AAEA,SAAO;AACT;AAKO,MAAM,oBAAoB,CAC/B,SACA,SAAkB,kBACK;AACvB,MAAI,WAAW,OAAO,YAAY,UAAU;AAC1C,UAAM,SAA6B,CAAC;AAGpC,eAAW,OAAO,OAAO,KAAK,OAAO,GAAG;AACtC,YAAM,QAAQ,QAAQ,GAAG;AAEzB,aAAO,GAAG,IAAI,YAAY,OAAO,MAAM;AAAA,IACzC;AAEA,WAAO;AAAA,EACT;AAGA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/processDictionary/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n type Locales,\n intlayerIntlConfiguration,\n} from '@intlayer/config/client';\nimport {\n NodeType,\n type QuantityContent,\n type LanguageContent,\n} from '@intlayer/core';\nimport { getEnumeration } from '../getEnumeration';\nimport { getTranslation } from '../getTranslation';\nimport type {\n Content,\n ContentValue,\n TransformedContent,\n TransformedContentValue,\n} from './contentDictionary';\n\nconst defaultLocale = intlayerIntlConfiguration.defaultLocale;\n\nconst processTranslation = (\n languageContent: LanguageContent<ContentValue>,\n locale: Locales\n): TransformedContent => {\n const translationResult: ContentValue = getTranslation<ContentValue>(\n languageContent,\n locale\n );\n\n return processDictionary(translationResult as Content, locale);\n};\n\nconst processEnumeration = (\n enumerationContent: QuantityContent<ContentValue>,\n locale: Locales\n): TransformedContentValue => {\n return (quantity: number): TransformedContentValue => {\n const enumerationResult: ContentValue = getEnumeration<ContentValue>(\n enumerationContent,\n quantity\n );\n\n //\n return processDictionary(enumerationResult as Content, locale);\n };\n};\n\nexport const processNode = (\n field: ContentValue | undefined,\n locale: Locales\n): TransformedContentValue => {\n if (typeof field !== 'object' || field === null) {\n return field;\n }\n\n if (field.nodeType === NodeType.Translation) {\n return processTranslation(field as LanguageContent<ContentValue>, locale);\n }\n\n if (field.nodeType === NodeType.Enumeration) {\n return processEnumeration(\n field satisfies QuantityContent<ContentValue>,\n locale\n );\n }\n\n if (typeof (field as any).type === 'undefined') {\n return processDictionary(field as Content, locale);\n }\n\n return field as TransformedContentValue;\n};\n\n/**\n * Function that process a dictionary and return the result to be used in the application.\n */\nexport const processDictionary = (\n content: Content,\n locale: Locales = defaultLocale\n): TransformedContent => {\n if (content && typeof content === 'object') {\n const result: TransformedContent = {};\n\n // List each key in the content and process it\n for (const key of Object.keys(content)) {\n const field = content[key];\n\n result[key] = processNode(field, locale);\n }\n\n return result;\n }\n\n // If it's a string, number, or function, return it\n return content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAGO;AACP,kBAIO;AACP,4BAA+B;AAC/B,4BAA+B;AAQ/B,MAAM,gBAAgB,wCAA0B;AAEhD,MAAM,qBAAqB,CACzB,iBACA,WACuB;AACvB,QAAM,wBAAkC;AAAA,IACtC;AAAA,IACA;AAAA,EACF;AAEA,SAAO,kBAAkB,mBAA8B,MAAM;AAC/D;AAEA,MAAM,qBAAqB,CACzB,oBACA,WAC4B;AAC5B,SAAO,CAAC,aAA8C;AACpD,UAAM,wBAAkC;AAAA,MACtC;AAAA,MACA;AAAA,IACF;AAGA,WAAO,kBAAkB,mBAA8B,MAAM;AAAA,EAC/D;AACF;AAEO,MAAM,cAAc,CACzB,OACA,WAC4B;AAC5B,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,aAAa,qBAAS,aAAa;AAC3C,WAAO,mBAAmB,OAAwC,MAAM;AAAA,EAC1E;AAEA,MAAI,MAAM,aAAa,qBAAS,aAAa;AAC3C,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,MAAI,OAAQ,MAAc,SAAS,aAAa;AAC9C,WAAO,kBAAkB,OAAkB,MAAM;AAAA,EACnD;AAEA,SAAO;AACT;AAKO,MAAM,oBAAoB,CAC/B,SACA,SAAkB,kBACK;AACvB,MAAI,WAAW,OAAO,YAAY,UAAU;AAC1C,UAAM,SAA6B,CAAC;AAGpC,eAAW,OAAO,OAAO,KAAK,OAAO,GAAG;AACtC,YAAM,QAAQ,QAAQ,GAAG;AAEzB,aAAO,GAAG,IAAI,YAAY,OAAO,MAAM;AAAA,IACzC;AAEA,WAAO;AAAA,EACT;AAGA,SAAO;AACT;","names":[]}
@@ -1,22 +1,11 @@
1
- import { Locales } from "@intlayer/config/client";
2
- import {
3
- ContentValue,
4
- TransformedContentValue,
5
- Content,
6
- TransformedContent,
7
- } from "./contentDictionary.d.js";
8
- import "@intlayer/core";
1
+ import { Locales } from '@intlayer/config/client';
2
+ import { ContentValue, TransformedContentValue, Content, TransformedContent } from './contentDictionary.d.js';
3
+ import '@intlayer/core';
9
4
 
10
- declare const processNode: (
11
- field: ContentValue | undefined,
12
- locale: Locales
13
- ) => TransformedContentValue;
5
+ declare const processNode: (field: ContentValue | undefined, locale: Locales) => TransformedContentValue;
14
6
  /**
15
- * Function to replace the multi lingual content with content in the current locale
7
+ * Function that process a dictionary and return the result to be used in the application.
16
8
  */
17
- declare const processDictionary: (
18
- content: Content,
19
- locale?: Locales
20
- ) => TransformedContent;
9
+ declare const processDictionary: (content: Content, locale?: Locales) => TransformedContent;
21
10
 
22
11
  export { processDictionary, processNode };
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var IntlayerServerProvider_exports = {};
20
+ __export(IntlayerServerProvider_exports, {
21
+ IntlayerServerContext: () => IntlayerServerContext,
22
+ IntlayerServerProvider: () => IntlayerServerProvider,
23
+ locale: () => locale,
24
+ useIntlayer: () => useIntlayer
25
+ });
26
+ module.exports = __toCommonJS(IntlayerServerProvider_exports);
27
+ var import_jsx_runtime = require("react/jsx-runtime");
28
+ var import_client = require("@intlayer/config/client");
29
+ var import_serverContext = require('./serverContext.cjs');
30
+ const IntlayerServerContext = (0, import_serverContext.createServerContext)(
31
+ import_client.intlayerIntlConfiguration.defaultLocale
32
+ );
33
+ const useIntlayer = () => (0, import_serverContext.getServerContext)(IntlayerServerContext);
34
+ const locale = (0, import_serverContext.getServerContext)(IntlayerServerContext);
35
+ const IntlayerServerProvider = ({
36
+ children,
37
+ locale: locale2
38
+ }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IntlayerServerContext.Provider, { value: locale2, children });
39
+ // Annotate the CommonJS export names for ESM import in node:
40
+ 0 && (module.exports = {
41
+ IntlayerServerContext,
42
+ IntlayerServerProvider,
43
+ locale,
44
+ useIntlayer
45
+ });
46
+ //# sourceMappingURL=IntlayerServerProvider.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/server/IntlayerServerProvider.tsx"],"sourcesContent":["import {\n type Locales,\n intlayerIntlConfiguration,\n} 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 intlayerIntlConfiguration.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;AAmCE;AAnCF,oBAGO;AAEP,2BAAsD;AAK/C,MAAM,4BAAwB;AAAA,EACnC,wCAA0B;AAC5B;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"]}
@@ -0,0 +1,37 @@
1
+ import * as react from 'react';
2
+ import { PropsWithChildren, FC } from 'react';
3
+ import { Locales } from '@intlayer/config/client';
4
+
5
+ /**
6
+ * Context that store the current locale on the server side
7
+ */
8
+ declare const IntlayerServerContext: {
9
+ Provider: ({ children, value, }: {
10
+ children: react.ReactNode;
11
+ value: Locales;
12
+ }) => react.ReactNode;
13
+ Consumer: ({ children, }: {
14
+ children: (context: Locales | undefined) => react.ReactNode;
15
+ }) => react.ReactNode;
16
+ _storage: () => {
17
+ value: Locales | undefined;
18
+ };
19
+ _defaultValue: Locales | undefined;
20
+ };
21
+ /**
22
+ * Hook that provides the current locale
23
+ */
24
+ declare const useIntlayer: () => Locales | undefined;
25
+ /**
26
+ * Get the current locale
27
+ */
28
+ declare const locale: Locales | undefined;
29
+ type IntlayerServerProviderProps = PropsWithChildren & {
30
+ locale: Locales;
31
+ };
32
+ /**
33
+ * Provider that store the current locale on the server side
34
+ */
35
+ declare const IntlayerServerProvider: FC<IntlayerServerProviderProps>;
36
+
37
+ export { IntlayerServerContext, IntlayerServerProvider, type IntlayerServerProviderProps, locale, useIntlayer };
@@ -8,43 +8,36 @@ var __export = (target, all) => {
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
9
9
  };
10
10
  var __copyProps = (to, from, except, desc) => {
11
- if ((from && typeof from === "object") || typeof from === "function") {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
12
  for (let key of __getOwnPropNames(from))
13
13
  if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, {
15
- get: () => from[key],
16
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
17
- });
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
15
  }
19
16
  return to;
20
17
  };
21
- var __toCommonJS = (mod) =>
22
- __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
19
  var getLocaleTranslation_exports = {};
24
20
  __export(getLocaleTranslation_exports, {
25
- getLocaleTranslation: () => getLocaleTranslation,
21
+ getLocaleTranslation: () => getLocaleTranslation
26
22
  });
27
23
  module.exports = __toCommonJS(getLocaleTranslation_exports);
28
24
  var import_client = require("@intlayer/config/client");
29
25
  var import_core = require("@intlayer/core");
30
- var import_LocaleServerContextProvider = require("./LocaleServerContextProvider.cjs");
31
- var import_serverContext = require("./serverContext.cjs");
26
+ var import_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
27
+ var import_serverContext = require('./serverContext.cjs');
32
28
  const getLocaleTranslation = (languageContent) => {
33
- const locale = (0, import_serverContext.getServerContext)(
34
- import_LocaleServerContextProvider.LocaleServerContext
35
- );
29
+ const locale = (0, import_serverContext.getServerContext)(import_IntlayerServerProvider.IntlayerServerContext);
36
30
  const content = (0, import_core.getTranslationContent)(
37
31
  languageContent,
38
32
  locale ?? import_client.intlayerIntlConfiguration.defaultLocale
39
33
  );
40
34
  return {
41
35
  locale,
42
- content,
36
+ content
43
37
  };
44
38
  };
45
39
  // Annotate the CommonJS export names for ESM import in node:
46
- 0 &&
47
- (module.exports = {
48
- getLocaleTranslation,
49
- });
50
- //# sourceMappingURL=getLocaleTranslation.cjs.map
40
+ 0 && (module.exports = {
41
+ getLocaleTranslation
42
+ });
43
+ //# sourceMappingURL=getLocaleTranslation.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/getLocaleTranslation.ts"],"sourcesContent":["import { intlayerIntlConfiguration } from '@intlayer/config/client';\nimport { type LanguageContent, getTranslationContent } from '@intlayer/core';\nimport { LocaleServerContext } from './LocaleServerContextProvider';\nimport { getServerContext } from './serverContext';\n\nexport const getLocaleTranslation = <Content>(\n languageContent: LanguageContent<Content>\n) => {\n const locale = getServerContext(LocaleServerContext);\n const content = getTranslationContent<Content>(\n languageContent,\n locale ?? intlayerIntlConfiguration.defaultLocale\n );\n\n return {\n locale,\n content,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA0C;AAC1C,kBAA4D;AAC5D,yCAAoC;AACpC,2BAAiC;AAE1B,MAAM,uBAAuB,CAClC,oBACG;AACH,QAAM,aAAS,uCAAiB,sDAAmB;AACnD,QAAM,cAAU;AAAA,IACd;AAAA,IACA,UAAU,wCAA0B;AAAA,EACtC;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/server/getLocaleTranslation.ts"],"sourcesContent":["import { intlayerIntlConfiguration } from '@intlayer/config/client';\nimport { type LanguageContent, getTranslationContent } from '@intlayer/core';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, get the translation content based on the locale\n */\nexport const getLocaleTranslation = <Content>(\n languageContent: LanguageContent<Content>\n) => {\n const locale = getServerContext(IntlayerServerContext);\n const content = getTranslationContent<Content>(\n languageContent,\n locale ?? intlayerIntlConfiguration.defaultLocale\n );\n\n return {\n locale,\n content,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA0C;AAC1C,kBAA4D;AAC5D,oCAAsC;AACtC,2BAAiC;AAK1B,MAAM,uBAAuB,CAClC,oBACG;AACH,QAAM,aAAS,uCAAiB,mDAAqB;AACrD,QAAM,cAAU;AAAA,IACd;AAAA,IACA,UAAU,wCAA0B;AAAA,EACtC;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -1,11 +1,12 @@
1
- import * as _intlayer_config_client from "@intlayer/config/client";
2
- import { LanguageContent } from "@intlayer/core";
1
+ import * as _intlayer_config_client from '@intlayer/config/client';
2
+ import { LanguageContent } from '@intlayer/core';
3
3
 
4
- declare const getLocaleTranslation: <Content>(
5
- languageContent: LanguageContent<Content>
6
- ) => {
7
- locale: _intlayer_config_client.Locales | undefined;
8
- content: Content;
4
+ /**
5
+ * On the server side, get the translation content based on the locale
6
+ */
7
+ declare const getLocaleTranslation: <Content>(languageContent: LanguageContent<Content>) => {
8
+ locale: _intlayer_config_client.Locales | undefined;
9
+ content: Content;
9
10
  };
10
11
 
11
12
  export { getLocaleTranslation };
@@ -8,42 +8,35 @@ var __export = (target, all) => {
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
9
9
  };
10
10
  var __copyProps = (to, from, except, desc) => {
11
- if ((from && typeof from === "object") || typeof from === "function") {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
12
  for (let key of __getOwnPropNames(from))
13
13
  if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, {
15
- get: () => from[key],
16
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
17
- });
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
15
  }
19
16
  return to;
20
17
  };
21
- var __toCommonJS = (mod) =>
22
- __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
19
  var server_exports = {};
24
20
  __export(server_exports, {
25
- LocaleServerContext: () =>
26
- import_LocaleServerContextProvider.LocaleServerContext,
27
- LocaleServerContextProvider: () =>
28
- import_LocaleServerContextProvider.LocaleServerContextProvider,
21
+ IntlayerServer: () => import_IntlayerServerProvider.IntlayerServerContext,
22
+ IntlayerServerProvider: () => import_IntlayerServerProvider.IntlayerServerProvider,
29
23
  getLocaleContent: () => import_getLocaleTranslation.getLocaleTranslation,
30
- locale: () => import_LocaleServerContextProvider.locale,
24
+ locale: () => import_IntlayerServerProvider.locale,
31
25
  useIntlayer: () => import_useIntlayer.useIntlayer,
32
- useTraduction: () => import_useTraduction.useTraduction,
26
+ useTraduction: () => import_useTraduction.useTraduction
33
27
  });
34
28
  module.exports = __toCommonJS(server_exports);
35
- var import_getLocaleTranslation = require("./getLocaleTranslation.cjs");
36
- var import_useTraduction = require("./useTraduction.cjs");
37
- var import_LocaleServerContextProvider = require("./LocaleServerContextProvider.cjs");
38
- var import_useIntlayer = require("./useIntlayer.cjs");
29
+ var import_getLocaleTranslation = require('./getLocaleTranslation.cjs');
30
+ var import_useTraduction = require('./useTraduction.cjs');
31
+ var import_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
32
+ var import_useIntlayer = require('./useIntlayer.cjs');
39
33
  // Annotate the CommonJS export names for ESM import in node:
40
- 0 &&
41
- (module.exports = {
42
- LocaleServerContext,
43
- LocaleServerContextProvider,
44
- getLocaleContent,
45
- locale,
46
- useIntlayer,
47
- useTraduction,
48
- });
49
- //# sourceMappingURL=index.cjs.map
34
+ 0 && (module.exports = {
35
+ IntlayerServer,
36
+ IntlayerServerProvider,
37
+ getLocaleContent,
38
+ locale,
39
+ useIntlayer,
40
+ useTraduction
41
+ });
42
+ //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export { getLocaleTranslation as getLocaleContent } from './getLocaleTranslation';\nexport { useTraduction } from './useTraduction';\nexport {\n LocaleServerContext,\n locale,\n LocaleServerContextProvider,\n} from './LocaleServerContextProvider';\nexport { useIntlayer } from './useIntlayer';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAAyD;AACzD,2BAA8B;AAC9B,yCAIO;AACP,yBAA4B;","names":[]}
1
+ {"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export { getLocaleTranslation as getLocaleContent } from './getLocaleTranslation';\nexport { useTraduction } from './useTraduction';\nexport {\n IntlayerServerContext as IntlayerServer,\n locale,\n IntlayerServerProvider,\n} from './IntlayerServerProvider';\nexport { useIntlayer } from './useIntlayer';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAAyD;AACzD,2BAA8B;AAC9B,oCAIO;AACP,yBAA4B;","names":[]}
@@ -1,13 +1,9 @@
1
- export { getLocaleTranslation as getLocaleContent } from "./getLocaleTranslation.js";
2
- export { useTraduction } from "./useTraduction.js";
3
- export {
4
- LocaleServerContext,
5
- LocaleServerContextProvider,
6
- locale,
7
- } from "./LocaleServerContextProvider.js";
8
- export { useIntlayer } from "./useIntlayer.js";
9
- import "@intlayer/config/client";
10
- import "@intlayer/core";
11
- import "react";
12
- import "../useIntlayerBase.js";
13
- import "intlayer";
1
+ export { getLocaleTranslation as getLocaleContent } from './getLocaleTranslation.js';
2
+ export { useTraduction } from './useTraduction.js';
3
+ export { IntlayerServerContext as IntlayerServer, IntlayerServerProvider, locale } from './IntlayerServerProvider.js';
4
+ export { useIntlayer } from './useIntlayer.js';
5
+ import '@intlayer/config/client';
6
+ import '@intlayer/core';
7
+ import 'react';
8
+ import '../useIntlayerBase.js';
9
+ import 'intlayer';
@@ -10,35 +10,26 @@ var __export = (target, all) => {
10
10
  __defProp(target, name, { get: all[name], enumerable: true });
11
11
  };
12
12
  var __copyProps = (to, from, except, desc) => {
13
- if ((from && typeof from === "object") || typeof from === "function") {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
14
  for (let key of __getOwnPropNames(from))
15
15
  if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, {
17
- get: () => from[key],
18
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
19
- });
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
17
  }
21
18
  return to;
22
19
  };
23
- var __toESM = (mod, isNodeMode, target) => (
24
- (target = mod != null ? __create(__getProtoOf(mod)) : {}),
25
- __copyProps(
26
- // If the importer is in node compatibility mode or this is not an ESM
27
- // file that has been converted to a CommonJS file using a Babel-
28
- // compatible transform (i.e. "__esModule" has not been set), then set
29
- // "default" to the CommonJS "module.exports" for node compatibility.
30
- isNodeMode || !mod || !mod.__esModule
31
- ? __defProp(target, "default", { value: mod, enumerable: true })
32
- : target,
33
- mod
34
- )
35
- );
36
- var __toCommonJS = (mod) =>
37
- __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
29
  var serverContext_exports = {};
39
30
  __export(serverContext_exports, {
40
31
  createServerContext: () => createServerContext,
41
- getServerContext: () => getServerContext,
32
+ getServerContext: () => getServerContext
42
33
  });
43
34
  module.exports = __toCommonJS(serverContext_exports);
44
35
  var import_react = __toESM(require("react"));
@@ -47,7 +38,7 @@ const createServerContext = (defaultValue) => {
47
38
  throwInClient();
48
39
  const cache = import_react.default.cache ?? cacheFallback;
49
40
  const getCache = cache(() => ({
50
- value: void 0,
41
+ value: void 0
51
42
  }));
52
43
  return {
53
44
  Provider: ({ children, value }) => {
@@ -59,12 +50,16 @@ const createServerContext = (defaultValue) => {
59
50
  return children(store ? store.value : defaultValue);
60
51
  },
61
52
  _storage: getCache,
62
- _defaultValue: defaultValue,
53
+ _defaultValue: defaultValue
63
54
  };
64
55
  };
65
- const getServerContext = ({ _storage, _defaultValue }) => {
56
+ const getServerContext = ({
57
+ _storage,
58
+ _defaultValue
59
+ }) => {
66
60
  const store = _storage();
67
- if (!store) return _defaultValue;
61
+ if (!store)
62
+ return _defaultValue;
68
63
  return store.value;
69
64
  };
70
65
  const throwInClient = () => {
@@ -73,9 +68,8 @@ const throwInClient = () => {
73
68
  }
74
69
  };
75
70
  // Annotate the CommonJS export names for ESM import in node:
76
- 0 &&
77
- (module.exports = {
78
- createServerContext,
79
- getServerContext,
80
- });
81
- //# sourceMappingURL=serverContext.cjs.map
71
+ 0 && (module.exports = {
72
+ createServerContext,
73
+ getServerContext
74
+ });
75
+ //# sourceMappingURL=serverContext.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/serverContext.ts"],"sourcesContent":["/**\n * Creates a new datastore for a given server context.\n * Attempts to closely mimic the `createContext` API.\n *\n * @example\n * const LocaleServerContext = createServerContext<string | null>(null);\n *\n * <LocaleServerContext.Provider value={locale}>\n * {children}\n * </LocaleServerContext.Provider>\n */\n\nimport react from 'react';\n\ntype CacheType<T> = () => { value: T | undefined };\n\nconst cacheFallback = () => () => ({ value: undefined });\n\nexport const createServerContext = <T>(defaultValue?: T): ServerContext<T> => {\n throwInClient();\n\n const cache = react.cache<CacheType<T>> ?? cacheFallback;\n\n const getCache = cache(() => ({\n value: undefined,\n }));\n\n return {\n Provider: ({ children, value }) => {\n getCache().value = value;\n return children;\n },\n Consumer: ({ children }) => {\n const store = getCache();\n return children(store ? store.value : defaultValue);\n },\n _storage: getCache,\n _defaultValue: defaultValue,\n };\n};\n\n/**\n * Fetches a value present in a given server context.\n * Attempts to closely mimic the `useContext` API.\n *\n * @example\n * getServerContext(LocaleServerContext);\n */\nexport const getServerContext = <T>({\n _storage,\n _defaultValue,\n}: ServerContext<T>) => {\n // throwInClient();\n const store = _storage();\n if (!store) return _defaultValue;\n return store.value;\n};\n\ntype ServerContext<T> = {\n Provider: ({\n children,\n value,\n }: {\n children: React.ReactNode;\n value: T;\n }) => React.ReactNode;\n Consumer: ({\n children,\n }: {\n children: (context: T | undefined) => React.ReactNode;\n }) => React.ReactNode;\n _storage: () => { value: T | undefined };\n _defaultValue: T | undefined;\n};\n\n/**\n * Throws if called within a client component environment.\n * Useful to help prevent mistakes.\n */\nconst throwInClient = (): void | never => {\n // If window.document is defined we're in a client component\n if (typeof window !== 'undefined') {\n throw new Error(`createServerContext only works in Server Components`);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,mBAAkB;AAIlB,MAAM,gBAAgB,MAAM,OAAO,EAAE,OAAO,OAAU;AAE/C,MAAM,sBAAsB,CAAI,iBAAuC;AAC5E,gBAAc;AAEd,QAAM,QAAQ,aAAAA,QAAM,SAAuB;AAE3C,QAAM,WAAW,MAAM,OAAO;AAAA,IAC5B,OAAO;AAAA,EACT,EAAE;AAEF,SAAO;AAAA,IACL,UAAU,CAAC,EAAE,UAAU,MAAM,MAAM;AACjC,eAAS,EAAE,QAAQ;AACnB,aAAO;AAAA,IACT;AAAA,IACA,UAAU,CAAC,EAAE,SAAS,MAAM;AAC1B,YAAM,QAAQ,SAAS;AACvB,aAAO,SAAS,QAAQ,MAAM,QAAQ,YAAY;AAAA,IACpD;AAAA,IACA,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AACF;AASO,MAAM,mBAAmB,CAAI;AAAA,EAClC;AAAA,EACA;AACF,MAAwB;AAEtB,QAAM,QAAQ,SAAS;AACvB,MAAI,CAAC;AAAO,WAAO;AACnB,SAAO,MAAM;AACf;AAuBA,MAAM,gBAAgB,MAAoB;AAExC,MAAI,OAAO,WAAW,aAAa;AACjC,UAAM,IAAI,MAAM,qDAAqD;AAAA,EACvE;AACF;","names":["react"]}
1
+ {"version":3,"sources":["../../../src/server/serverContext.ts"],"sourcesContent":["/**\n * Creates a new datastore for a given server context.\n * Attempts to closely mimic the `createContext` API.\n *\n * @example\n * const IntlayerServer = createServerContext<string | null>(null);\n *\n * <IntlayerServer.Provider value={locale}>\n * {children}\n * </IntlayerServer.Provider>\n */\n\nimport react from 'react';\n\ntype CacheType<T> = () => { value: T | undefined };\n\nconst cacheFallback = () => () => ({ value: undefined });\n\nexport const createServerContext = <T>(defaultValue?: T): ServerContext<T> => {\n throwInClient();\n\n const cache = react.cache<CacheType<T>> ?? cacheFallback;\n\n const getCache = cache(() => ({\n value: undefined,\n }));\n\n return {\n Provider: ({ children, value }) => {\n getCache().value = value;\n return children;\n },\n Consumer: ({ children }) => {\n const store = getCache();\n return children(store ? store.value : defaultValue);\n },\n _storage: getCache,\n _defaultValue: defaultValue,\n };\n};\n\n/**\n * Fetches a value present in a given server context.\n * Attempts to closely mimic the `useContext` API.\n *\n * @example\n * getServerContext(IntlayerServer);\n */\nexport const getServerContext = <T>({\n _storage,\n _defaultValue,\n}: ServerContext<T>) => {\n // throwInClient();\n const store = _storage();\n if (!store) return _defaultValue;\n return store.value;\n};\n\ntype ServerContext<T> = {\n Provider: ({\n children,\n value,\n }: {\n children: React.ReactNode;\n value: T;\n }) => React.ReactNode;\n Consumer: ({\n children,\n }: {\n children: (context: T | undefined) => React.ReactNode;\n }) => React.ReactNode;\n _storage: () => { value: T | undefined };\n _defaultValue: T | undefined;\n};\n\n/**\n * Throws if called within a client component environment.\n * Useful to help prevent mistakes.\n */\nconst throwInClient = (): void | never => {\n // If window.document is defined we're in a client component\n if (typeof window !== 'undefined') {\n throw new Error(`createServerContext only works in Server Components`);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,mBAAkB;AAIlB,MAAM,gBAAgB,MAAM,OAAO,EAAE,OAAO,OAAU;AAE/C,MAAM,sBAAsB,CAAI,iBAAuC;AAC5E,gBAAc;AAEd,QAAM,QAAQ,aAAAA,QAAM,SAAuB;AAE3C,QAAM,WAAW,MAAM,OAAO;AAAA,IAC5B,OAAO;AAAA,EACT,EAAE;AAEF,SAAO;AAAA,IACL,UAAU,CAAC,EAAE,UAAU,MAAM,MAAM;AACjC,eAAS,EAAE,QAAQ;AACnB,aAAO;AAAA,IACT;AAAA,IACA,UAAU,CAAC,EAAE,SAAS,MAAM;AAC1B,YAAM,QAAQ,SAAS;AACvB,aAAO,SAAS,QAAQ,MAAM,QAAQ,YAAY;AAAA,IACpD;AAAA,IACA,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AACF;AASO,MAAM,mBAAmB,CAAI;AAAA,EAClC;AAAA,EACA;AACF,MAAwB;AAEtB,QAAM,QAAQ,SAAS;AACvB,MAAI,CAAC;AAAO,WAAO;AACnB,SAAO,MAAM;AACf;AAuBA,MAAM,gBAAgB,MAAoB;AAExC,MAAI,OAAO,WAAW,aAAa;AACjC,UAAM,IAAI,MAAM,qDAAqD;AAAA,EACvE;AACF;","names":["react"]}
@@ -3,11 +3,11 @@
3
3
  * Attempts to closely mimic the `createContext` API.
4
4
  *
5
5
  * @example
6
- * const LocaleServerContext = createServerContext<string | null>(null);
6
+ * const IntlayerServer = createServerContext<string | null>(null);
7
7
  *
8
- * <LocaleServerContext.Provider value={locale}>
8
+ * <IntlayerServer.Provider value={locale}>
9
9
  * {children}
10
- * </LocaleServerContext.Provider>
10
+ * </IntlayerServer.Provider>
11
11
  */
12
12
  declare const createServerContext: <T>(defaultValue?: T) => ServerContext<T>;
13
13
  /**
@@ -15,29 +15,21 @@ declare const createServerContext: <T>(defaultValue?: T) => ServerContext<T>;
15
15
  * Attempts to closely mimic the `useContext` API.
16
16
  *
17
17
  * @example
18
- * getServerContext(LocaleServerContext);
18
+ * getServerContext(IntlayerServer);
19
19
  */
20
- declare const getServerContext: <T>({
21
- _storage,
22
- _defaultValue,
23
- }: ServerContext<T>) => T | undefined;
20
+ declare const getServerContext: <T>({ _storage, _defaultValue, }: ServerContext<T>) => T | undefined;
24
21
  type ServerContext<T> = {
25
- Provider: ({
26
- children,
27
- value,
28
- }: {
29
- children: React.ReactNode;
30
- value: T;
31
- }) => React.ReactNode;
32
- Consumer: ({
33
- children,
34
- }: {
35
- children: (context: T | undefined) => React.ReactNode;
36
- }) => React.ReactNode;
37
- _storage: () => {
38
- value: T | undefined;
39
- };
40
- _defaultValue: T | undefined;
22
+ Provider: ({ children, value, }: {
23
+ children: React.ReactNode;
24
+ value: T;
25
+ }) => React.ReactNode;
26
+ Consumer: ({ children, }: {
27
+ children: (context: T | undefined) => React.ReactNode;
28
+ }) => React.ReactNode;
29
+ _storage: () => {
30
+ value: T | undefined;
31
+ };
32
+ _defaultValue: T | undefined;
41
33
  };
42
34
 
43
35
  export { createServerContext, getServerContext };
@@ -8,37 +8,28 @@ var __export = (target, all) => {
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
9
9
  };
10
10
  var __copyProps = (to, from, except, desc) => {
11
- if ((from && typeof from === "object") || typeof from === "function") {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
12
  for (let key of __getOwnPropNames(from))
13
13
  if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, {
15
- get: () => from[key],
16
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
17
- });
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
15
  }
19
16
  return to;
20
17
  };
21
- var __toCommonJS = (mod) =>
22
- __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
19
  var useIntlayer_exports = {};
24
20
  __export(useIntlayer_exports, {
25
- useIntlayer: () => useIntlayer,
21
+ useIntlayer: () => useIntlayer
26
22
  });
27
23
  module.exports = __toCommonJS(useIntlayer_exports);
28
- var import_useIntlayerBase = require("../useIntlayerBase.cjs");
29
- var import_LocaleServerContextProvider = require("./LocaleServerContextProvider.cjs");
30
- var import_serverContext = require("./serverContext.cjs");
24
+ var import_useIntlayerBase = require('../useIntlayerBase.cjs');
25
+ var import_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
26
+ var import_serverContext = require('./serverContext.cjs');
31
27
  const useIntlayer = (id, locale) => {
32
- const localeTarget =
33
- locale ??
34
- (0, import_serverContext.getServerContext)(
35
- import_LocaleServerContextProvider.LocaleServerContext
36
- );
28
+ const localeTarget = locale ?? (0, import_serverContext.getServerContext)(import_IntlayerServerProvider.IntlayerServerContext);
37
29
  return (0, import_useIntlayerBase.useIntlayerBase)(id, localeTarget);
38
30
  };
39
31
  // Annotate the CommonJS export names for ESM import in node:
40
- 0 &&
41
- (module.exports = {
42
- useIntlayer,
43
- });
44
- //# sourceMappingURL=useIntlayer.cjs.map
32
+ 0 && (module.exports = {
33
+ useIntlayer
34
+ });
35
+ //# sourceMappingURL=useIntlayer.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport {\n type DictionaryKeys,\n useIntlayerBase,\n type UseIntlayer,\n} from '../useIntlayerBase';\nimport { LocaleServerContext } from './LocaleServerContextProvider';\nimport { getServerContext } from './serverContext';\n\nexport const useIntlayer: UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => {\n const localeTarget = locale ?? getServerContext<Locales>(LocaleServerContext);\n\n return useIntlayerBase(id, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,6BAIO;AACP,yCAAoC;AACpC,2BAAiC;AAE1B,MAAM,cAA2B,CACtC,IACA,WACG;AACH,QAAM,eAAe,cAAU,uCAA0B,sDAAmB;AAE5E,aAAO,wCAAgB,IAAI,YAAY;AACzC;","names":[]}
1
+ {"version":3,"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport {\n type DictionaryKeys,\n useIntlayerBase,\n type UseIntlayer,\n} from '../useIntlayerBase';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server 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 server context\n */\nexport const useIntlayer: UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => {\n const localeTarget =\n locale ?? getServerContext<Locales>(IntlayerServerContext);\n\n return useIntlayerBase(id, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,6BAIO;AACP,oCAAsC;AACtC,2BAAiC;AAO1B,MAAM,cAA2B,CACtC,IACA,WACG;AACH,QAAM,eACJ,cAAU,uCAA0B,mDAAqB;AAE3D,aAAO,wCAAgB,IAAI,YAAY;AACzC;","names":[]}
@@ -1,7 +1,12 @@
1
- import { UseIntlayer } from "../useIntlayerBase.js";
2
- import "@intlayer/config/client";
3
- import "intlayer";
1
+ import { UseIntlayer } from '../useIntlayerBase.js';
2
+ import '@intlayer/config/client';
3
+ import 'intlayer';
4
4
 
5
+ /**
6
+ * On the server side, Hook that picking one dictionary by its id and return the content
7
+ *
8
+ * If the locale is not provided, it will use the locale from the server context
9
+ */
5
10
  declare const useIntlayer: UseIntlayer;
6
11
 
7
12
  export { useIntlayer };