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
@@ -4,7 +4,6 @@ import {
4
4
  NodeType,
5
5
  findMatchingCondition
6
6
  } from "@intlayer/core";
7
- import { renderContentEditor } from "intlayer-editor/client";
8
7
  import { createElement } from "react";
9
8
  import { getEnumeration } from '../getEnumeration.mjs';
10
9
  import { getTranslation } from '../getTranslation.mjs';
@@ -28,28 +27,26 @@ const processTranslation = (languageContent, locale, dictionaryId, dictionaryPat
28
27
  locale
29
28
  );
30
29
  };
31
- const processEnumeration = (enumerationContent, locale, dictionaryId, dictionaryPath, keyPath = []) => {
32
- return (quantity) => {
33
- const enumerationResult = getEnumeration(
34
- enumerationContent,
35
- quantity
36
- );
37
- const matchingCondition = findMatchingCondition(
38
- enumerationContent,
39
- quantity
40
- );
41
- const resultKeyPath = [
42
- ...keyPath,
43
- { type: NodeType.Enumeration, key: matchingCondition.toString() }
44
- ];
45
- return processDictionary(
46
- enumerationResult,
47
- dictionaryId,
48
- dictionaryPath,
49
- resultKeyPath,
50
- locale
51
- );
52
- };
30
+ const processEnumeration = (enumerationContent, locale, dictionaryId, dictionaryPath, keyPath = []) => (quantity) => {
31
+ const enumerationResult = getEnumeration(
32
+ enumerationContent,
33
+ quantity
34
+ );
35
+ const matchingCondition = findMatchingCondition(
36
+ enumerationContent,
37
+ quantity
38
+ );
39
+ const resultKeyPath = [
40
+ ...keyPath,
41
+ { type: NodeType.Enumeration, key: matchingCondition.toString() }
42
+ ];
43
+ return processDictionary(
44
+ enumerationResult,
45
+ dictionaryId,
46
+ dictionaryPath,
47
+ resultKeyPath,
48
+ locale
49
+ );
53
50
  };
54
51
  const isReactNode = (node) => typeof node?.key !== "undefined" && typeof node?.props !== "undefined";
55
52
  const processNode = (field, locale, dictionaryId, dictionaryPath, keyPath = []) => {
@@ -106,7 +103,7 @@ const createReactElement = (element) => {
106
103
  const { type, props } = fixedElement;
107
104
  return createElement(type ?? "div", props, ...props.children);
108
105
  };
109
- const traceKeys = ["filePath", "id", "nodeType"];
106
+ const traceKeys = ["filePath", "nodeType"];
110
107
  const processDictionary = (content, dictionaryId, dictionaryPath, keyPath = [], locale = defaultLocale) => {
111
108
  if (isReactNode(content)) {
112
109
  return createReactElement(
@@ -114,40 +111,59 @@ const processDictionary = (content, dictionaryId, dictionaryPath, keyPath = [],
114
111
  );
115
112
  }
116
113
  if (content && typeof content === "object") {
117
- const result = {};
118
- for (const key of Object.keys(content)) {
119
- const field = content[key];
120
- if (traceKeys.includes(key)) {
121
- result[key] = field;
122
- continue;
123
- }
124
- const resultKeyPath = [
125
- ...keyPath,
126
- { type: "ObjectExpression", key }
127
- ];
128
- result[key] = processNode(
129
- field,
130
- locale,
131
- dictionaryId,
132
- dictionaryPath,
133
- resultKeyPath
134
- );
135
- }
136
- return result;
137
- }
138
- if (typeof content === "string") {
139
- try {
140
- return renderContentEditor(
114
+ const isArray = Array.isArray(content);
115
+ let result = {};
116
+ if (typeof content.nodeType !== "undefined") {
117
+ return processNode(
141
118
  content,
119
+ locale,
142
120
  dictionaryId,
143
121
  dictionaryPath,
144
122
  keyPath
145
123
  );
146
- } catch (e) {
147
- return content;
124
+ } else if (isArray) {
125
+ result = content.map((field, key) => {
126
+ const resultKeyPath = [
127
+ ...keyPath,
128
+ { type: "ArrayExpression", key }
129
+ ];
130
+ return processNode(
131
+ field,
132
+ locale,
133
+ dictionaryId,
134
+ dictionaryPath,
135
+ resultKeyPath
136
+ );
137
+ });
138
+ } else {
139
+ for (const key of Object.keys(content)) {
140
+ const field = content[key];
141
+ if (traceKeys.includes(key)) {
142
+ result[key] = field;
143
+ continue;
144
+ }
145
+ const resultKeyPath = [
146
+ ...keyPath,
147
+ { type: "ObjectExpression", key }
148
+ ];
149
+ const nodeResult = processNode(
150
+ field,
151
+ locale,
152
+ dictionaryId,
153
+ dictionaryPath,
154
+ resultKeyPath
155
+ );
156
+ result[key] = nodeResult;
157
+ }
148
158
  }
159
+ return result;
149
160
  }
150
- return content;
161
+ return {
162
+ content,
163
+ keyPath,
164
+ dictionaryId,
165
+ dictionaryPath
166
+ };
151
167
  };
152
168
  export {
153
169
  processDictionary,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/processDictionary/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { type Locales, getConfiguration } from '@intlayer/config/client';\nimport {\n NodeType,\n type QuantityContent,\n type LanguageContent,\n findMatchingCondition,\n type KeyPath,\n} from '@intlayer/core';\nimport { renderContentEditor } from 'intlayer-editor/client';\nimport { type ReactElement, createElement, type ReactNode } from 'react';\nimport { getEnumeration } from '../getEnumeration';\nimport { getTranslation } from '../getTranslation';\nimport type {\n Content,\n ContentValue,\n TransformedContent,\n TransformedContentValue,\n} from './contentDictionary';\n\nconst {\n internationalization: { defaultLocale },\n} = getConfiguration();\n\nconst processTranslation = (\n languageContent: LanguageContent<ContentValue>,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = []\n): TransformedContent => {\n const translationResult: ContentValue = getTranslation<ContentValue>(\n languageContent,\n locale\n );\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Translation, key: locale },\n ];\n\n return processDictionary(\n translationResult as Content,\n dictionaryId,\n dictionaryPath,\n resultKeyPath,\n locale\n );\n};\n\nconst processEnumeration = (\n enumerationContent: QuantityContent<ContentValue>,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = []\n): TransformedContentValue => {\n return (quantity: number): TransformedContentValue => {\n const enumerationResult: ContentValue = getEnumeration<ContentValue>(\n enumerationContent,\n quantity\n );\n\n const matchingCondition = findMatchingCondition(\n enumerationContent,\n quantity\n );\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Enumeration, key: matchingCondition.toString() },\n ];\n\n //\n return processDictionary(\n enumerationResult as Content,\n dictionaryId,\n dictionaryPath,\n resultKeyPath,\n locale\n );\n };\n};\n\nconst isReactNode = (node: Record<string, unknown>): boolean =>\n typeof node?.key !== 'undefined' && typeof node?.props !== 'undefined';\n\nexport const processNode = (\n field: ContentValue | undefined,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = []\n): TransformedContentValue => {\n if (typeof field === 'object') {\n if (field.nodeType === NodeType.Translation) {\n return processTranslation(\n field as LanguageContent<ContentValue>,\n locale,\n dictionaryId,\n dictionaryPath,\n keyPath\n );\n }\n\n if (field.nodeType === NodeType.Enumeration) {\n return processEnumeration(\n field satisfies QuantityContent<ContentValue>,\n locale,\n dictionaryId,\n dictionaryPath,\n keyPath\n );\n }\n }\n\n return processDictionary(\n field as Content,\n dictionaryId,\n dictionaryPath,\n keyPath,\n locale\n );\n};\n\n// This function recursively creates React elements from a given JSON-like structure\nconst createReactElement = (element: ReactElement) => {\n if (typeof element === 'string') {\n // If it's a string, simply return it (used for text content)\n return element;\n }\n\n // Destructure the component properties\n\n const convertChildrenAsArray = (element: ReactElement): ReactElement => {\n if (element?.props && typeof element.props.children === 'object') {\n const childrenResult: ReactNode[] = [];\n const { children } = element.props;\n\n // Create the children elements recursively, if any\n Object.keys(children).forEach((key) => {\n childrenResult.push(createReactElement(children[key]));\n });\n\n return {\n ...element,\n props: { ...element.props, children: childrenResult },\n };\n }\n\n return {\n ...element,\n props: { ...element.props, children: element.props.children },\n };\n };\n\n const fixedElement = convertChildrenAsArray(element);\n\n const { type, props } = fixedElement;\n\n // Create and return the React element\n return createElement(type ?? 'div', props, ...props.children);\n};\n\nconst traceKeys: string[] = ['filePath', 'id', 'nodeType'];\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 dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = [],\n locale: Locales = defaultLocale\n): TransformedContent => {\n // If it's a React element, render it\n if (isReactNode(content)) {\n return createReactElement(\n content as unknown as ReactElement\n ) as unknown as TransformedContent;\n }\n\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 if (traceKeys.includes(key)) {\n result[key] = field as TransformedContentValue;\n continue;\n }\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: 'ObjectExpression', key },\n ];\n\n result[key] = processNode(\n field,\n locale,\n dictionaryId,\n dictionaryPath,\n resultKeyPath\n );\n }\n\n return result;\n }\n\n if (typeof content === 'string') {\n try {\n // renderContentEditor come from intlayer-editor, which is an optional dependency.\n // intlayer-editor should be installed in the project to use the content editor.\n return renderContentEditor(\n content,\n dictionaryId,\n dictionaryPath,\n keyPath\n );\n } catch (e) {\n // If renderContentEditor not available, it will return the content as is.\n return content;\n }\n }\n\n // If it's a string, number, or function, return it\n return content;\n};\n"],"mappings":"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","names":["element"]}
1
+ {"version":3,"sources":["../../../src/processDictionary/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { type Locales, getConfiguration } from '@intlayer/config/client';\nimport {\n NodeType,\n type QuantityContent,\n type LanguageContent,\n findMatchingCondition,\n type KeyPath,\n type Dictionary,\n type DictionaryValue,\n type TranslationContent,\n type EnumerationContent,\n type TypedNode,\n} from '@intlayer/core';\nimport { type ReactElement, createElement, type ReactNode } from 'react';\nimport { getEnumeration } from '../getEnumeration';\nimport { getTranslation } from '../getTranslation';\nimport type {\n TransformedContent,\n TransformedContentValue,\n} from './contentDictionary';\n\nconst {\n internationalization: { defaultLocale },\n} = getConfiguration();\n\nconst processTranslation = (\n languageContent: LanguageContent<DictionaryValue>,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = []\n): TransformedContent => {\n const translationResult: DictionaryValue = getTranslation<DictionaryValue>(\n languageContent,\n locale\n );\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Translation, key: locale },\n ];\n\n return processDictionary(\n translationResult,\n dictionaryId,\n dictionaryPath,\n resultKeyPath,\n locale\n );\n};\n\nconst processEnumeration =\n (\n enumerationContent: QuantityContent<DictionaryValue>,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = []\n ): TransformedContentValue =>\n (quantity: number): TransformedContentValue => {\n const enumerationResult: DictionaryValue = getEnumeration<DictionaryValue>(\n enumerationContent,\n quantity\n );\n\n const matchingCondition = findMatchingCondition(\n enumerationContent,\n quantity\n );\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Enumeration, key: matchingCondition.toString() },\n ];\n\n return processDictionary(\n enumerationResult,\n dictionaryId,\n dictionaryPath,\n resultKeyPath,\n locale\n ) as TransformedContentValue;\n };\n\nconst isReactNode = (node: Record<string, unknown>): boolean =>\n typeof node?.key !== 'undefined' && typeof node?.props !== 'undefined';\n\nexport const processNode = (\n field: DictionaryValue | undefined,\n locale: Locales,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = []\n): TransformedContentValue => {\n if (typeof field === 'object') {\n if (\n (field as TranslationContent<DictionaryValue>).nodeType ===\n NodeType.Translation\n ) {\n return processTranslation(\n field as LanguageContent<DictionaryValue>,\n locale,\n dictionaryId,\n dictionaryPath,\n keyPath\n ) as TransformedContentValue;\n }\n\n if (\n (field as EnumerationContent<DictionaryValue>).nodeType ===\n NodeType.Enumeration\n ) {\n return processEnumeration(\n field as QuantityContent<DictionaryValue>,\n locale,\n dictionaryId,\n dictionaryPath,\n keyPath\n );\n }\n }\n\n return processDictionary(\n field!,\n dictionaryId,\n dictionaryPath,\n keyPath,\n locale\n ) as TransformedContentValue;\n};\n\n// This function recursively creates React elements from a given JSON-like structure\nconst createReactElement = (element: ReactElement) => {\n if (typeof element === 'string') {\n // If it's a string, simply return it (used for text content)\n return element;\n }\n\n // Destructure the component properties\n\n const convertChildrenAsArray = (element: ReactElement): ReactElement => {\n if (element?.props && typeof element.props.children === 'object') {\n const childrenResult: ReactNode[] = [];\n const { children } = element.props;\n\n // Create the children elements recursively, if any\n Object.keys(children).forEach((key) => {\n childrenResult.push(createReactElement(children[key]));\n });\n\n return {\n ...element,\n props: { ...element.props, children: childrenResult },\n };\n }\n\n return {\n ...element,\n props: { ...element.props, children: element.props.children },\n };\n };\n\n const fixedElement = convertChildrenAsArray(element);\n\n const { type, props } = fixedElement;\n\n // Create and return the React element\n return createElement(type ?? 'div', props, ...props.children);\n};\n\nconst traceKeys: string[] = ['filePath', 'nodeType'];\n\n/**\n * Function that process a dictionary and return the result to be used in the application.\n */\nexport const processDictionary = (\n content: Dictionary | DictionaryValue,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[] = [],\n locale: Locales = defaultLocale\n // eslint-disable-next-line sonarjs/cognitive-complexity\n): TransformedContent => {\n // If it's a React element, render it\n if (isReactNode(content as Record<string, unknown>)) {\n return createReactElement(\n content as unknown as ReactElement\n ) as unknown as TransformedContent;\n }\n\n if (content && typeof content === 'object') {\n const isArray = Array.isArray(content);\n\n let result: TransformedContent = {};\n\n if (typeof (content as TypedNode).nodeType !== 'undefined') {\n return processNode(\n content as DictionaryValue,\n locale,\n dictionaryId,\n dictionaryPath,\n keyPath\n ) as TransformedContent;\n } else if (isArray) {\n // Eslint fix because promises are awaited during build stage\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n result = (content as DictionaryValue[]).map((field, key) => {\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: 'ArrayExpression', key },\n ];\n\n return processNode(\n field,\n locale,\n dictionaryId,\n dictionaryPath,\n resultKeyPath\n );\n }) as TransformedContent;\n } else {\n // List each key in the content and process it\n for (const key of Object.keys(content)) {\n const field = content[key as keyof typeof content];\n\n if (traceKeys.includes(key)) {\n result[key] = field as TransformedContentValue;\n continue;\n }\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: 'ObjectExpression', key },\n ];\n\n const nodeResult = processNode(\n field,\n locale,\n dictionaryId,\n dictionaryPath,\n resultKeyPath\n );\n\n result[key] = nodeResult;\n }\n }\n\n return result;\n }\n\n return {\n content,\n keyPath,\n dictionaryId,\n dictionaryPath,\n };\n};\n"],"mappings":"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","names":["element"]}
@@ -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
@@ -2,14 +2,13 @@ import "../chunk-ZNCO4QRF.mjs";
2
2
  import { jsx } from "react/jsx-runtime";
3
3
  import { getConfiguration } from "@intlayer/config/client";
4
4
  import { createServerContext, getServerContext } from './serverContext.mjs';
5
- const IntlayerServerContext = createServerContext(
6
- getConfiguration().internationalization.defaultLocale
7
- );
5
+ const { defaultLocale } = getConfiguration().internationalization;
6
+ const IntlayerServerContext = createServerContext(defaultLocale);
8
7
  const useIntlayer = () => getServerContext(IntlayerServerContext);
9
8
  const locale = getServerContext(IntlayerServerContext);
10
9
  const IntlayerServerProvider = ({
11
10
  children,
12
- locale: locale2
11
+ locale: locale2 = defaultLocale
13
12
  }) => /* @__PURE__ */ jsx(IntlayerServerContext.Provider, { value: locale2, children });
14
13
  export {
15
14
  IntlayerServerContext,
@@ -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":";AAgCE;AAhCF,SAAuB,wBAAwB;AAE/C,SAAS,qBAAqB,wBAAwB;AAK/C,MAAM,wBAAwB;AAAA,EACnC,iBAAiB,EAAE,qBAAqB;AAC1C;AAKO,MAAM,cAAc,MAAM,iBAAiB,qBAAqB;AAKhE,MAAM,SAAS,iBAAiB,qBAAqB;AASrD,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA,QAAAA;AACF,MACE,oBAAC,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":";AAiCE;AAjCF,SAAuB,wBAAwB;AAE/C,SAAS,qBAAqB,wBAAwB;AAEtD,MAAM,EAAE,cAAc,IAAI,iBAAiB,EAAE;AAKtC,MAAM,wBACX,oBAA6B,aAAa;AAKrC,MAAM,cAAc,MAAM,iBAAiB,qBAAqB;AAKhE,MAAM,SAAS,iBAAiB,qBAAqB;AASrD,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA,QAAAA,UAAS;AACX,MACE,oBAAC,sBAAsB,UAAtB,EAA+B,OAAOA,SACpC,UACH;","names":["locale"]}
@@ -6,4 +6,5 @@ import '@intlayer/config/client';
6
6
  import '@intlayer/core';
7
7
  import 'react';
8
8
  import '../useIntlayerBase.mjs';
9
+ import '@intlayer/config';
9
10
  import 'intlayer';
@@ -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 server side, Hook that picking one dictionary by its id and return the content
@@ -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,17 +1,59 @@
1
1
  import "./chunk-ZNCO4QRF.mjs";
2
2
  import dictionaries from "@intlayer/dictionaries-entry";
3
+ import { renderIntlayerEditor } from "intlayer-editor/client";
3
4
  import { processDictionary } from './processDictionary/index.mjs';
5
+ const recursiveTransformContent = (obj) => Object.entries(obj).reduce((acc, [key, value]) => {
6
+ if (typeof value === "object" && typeof value.keyPath !== "undefined" && typeof value.dictionaryId !== "undefined" && typeof value.dictionaryPath !== "undefined") {
7
+ return {
8
+ ...acc,
9
+ [key]: renderIntlayerEditor(value)
10
+ };
11
+ } else if (typeof value === "object" && Array.isArray(value)) {
12
+ return {
13
+ ...acc,
14
+ [key]: value.map(recursiveTransformContent)
15
+ };
16
+ } else if (typeof value === "object") {
17
+ return {
18
+ ...acc,
19
+ [key]: recursiveTransformContent(value)
20
+ };
21
+ }
22
+ return acc;
23
+ }, {});
24
+ const recursiveStringifyContent = (obj) => Object.entries(obj).reduce((acc, [key, value]) => {
25
+ if (typeof value === "object" && typeof value.value !== "undefined") {
26
+ return {
27
+ ...acc,
28
+ [key]: value.value
29
+ };
30
+ } else if (typeof value === "object" && Array.isArray(value)) {
31
+ return {
32
+ ...acc,
33
+ [key]: value.map(recursiveStringifyContent)
34
+ };
35
+ } else if (typeof value === "object") {
36
+ return {
37
+ ...acc,
38
+ [key]: recursiveStringifyContent(value)
39
+ };
40
+ }
41
+ return acc;
42
+ }, {});
4
43
  const useIntlayerBase = (id, locale) => {
5
44
  const dictionary = dictionaries[id];
6
- return processDictionary(
45
+ const result = processDictionary(
7
46
  dictionary,
8
47
  id,
9
48
  dictionary.filePath,
10
49
  [],
11
50
  locale
12
51
  );
52
+ return recursiveTransformContent(result);
13
53
  };
14
54
  export {
55
+ recursiveStringifyContent,
56
+ recursiveTransformContent,
15
57
  useIntlayerBase
16
58
  };
17
59
  //# sourceMappingURL=useIntlayerBase.mjs.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":";AAMA,OAAO,kBAAkB;AAGzB,SAAS,yBAAyB;AAe3B,MAAM,kBAA+B,CAC1C,IACA,WACG;AACH,QAAM,aAAsB,aAAa,EAAE;AAE3C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF;AACF;","names":[]}
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":";AAOA,OAAO,kBAAkB;AAEzB,SAAS,4BAA4B;AAErC,SAAS,yBAAyB;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,GAAG,qBAAqB,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,aAAa,EAAE;AAE9C,QAAM,SAAS;AAAA,IACb;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF;AAEA,SAAO,0BAA0B,MAAM;AACzC;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-intlayer",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "private": false,
5
5
  "description": "Internationalization layer for React applications - Layer of abstraction between the business logic and the data access layer. Manage internationalization in a simple way, through TypeScript, JavaScript or JSON declaration file.",
6
6
  "keywords": [
@@ -67,7 +67,6 @@
67
67
  },
68
68
  "files": [
69
69
  "./dist",
70
- "./src",
71
70
  "./package.json"
72
71
  ],
73
72
  "dependencies": {
@@ -76,12 +75,12 @@
76
75
  "react-cookie": "^7.1.4",
77
76
  "vite": "^5.2.0",
78
77
  "webpack": "^5.91.0",
79
- "@intlayer/chokidar": "^2.0.0",
80
- "@intlayer/core": "^2.0.0",
81
- "@intlayer/config": "^2.0.0",
82
- "@intlayer/webpack": "^2.0.0",
83
- "@intlayer/dictionaries-entry": "^2.0.0",
84
- "intlayer": "^2.0.0"
78
+ "@intlayer/chokidar": "^2.0.1",
79
+ "@intlayer/config": "^2.0.1",
80
+ "@intlayer/core": "^2.0.1",
81
+ "@intlayer/dictionaries-entry": "^2.0.1",
82
+ "@intlayer/webpack": "^2.0.1",
83
+ "intlayer": "^2.0.1"
85
84
  },
86
85
  "devDependencies": {
87
86
  "@craco/types": "^7.1.0",
@@ -100,7 +99,7 @@
100
99
  "peerDependencies": {
101
100
  "react": "^18.2.0",
102
101
  "react-dom": "^18.2.0",
103
- "intlayer-editor": "^2.0.0"
102
+ "intlayer-editor": "^2.1.0"
104
103
  },
105
104
  "peerDependenciesMeta": {
106
105
  "intlayer-editor": {
package/src/index.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  export { getTranslation } from './getTranslation';
2
2
  export {
3
- IntlayerClientProvider,
4
- type IntlayerClientProviderProps,
5
- IntlayerClient,
3
+ IntlayerProvider,
4
+ type IntlayerProviderProps,
5
+ IntlayerClientContext,
6
6
  useIntlayer,
7
7
  useLocale,
8
8
  useTraduction,
@@ -12,3 +12,4 @@ export {
12
12
  getBrowserLocale,
13
13
  useLocaleBase,
14
14
  } from './client/index';
15
+ export { recursiveStringifyContent } from './useIntlayerBase';
@@ -1,37 +0,0 @@
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 IntlayerProvider_exports = {};
20
- __export(IntlayerProvider_exports, {
21
- IntlayerProvider: () => IntlayerProvider
22
- });
23
- module.exports = __toCommonJS(IntlayerProvider_exports);
24
- var import_jsx_runtime = require("react/jsx-runtime");
25
- var import_client = require("@intlayer/config/client");
26
- var import_IntlayerClientProvider = require('./client/IntlayerClientProvider.cjs');
27
- var import_IntlayerServerProvider = require('./server/IntlayerServerProvider.cjs');
28
- const { defaultLocale } = (0, import_client.getConfiguration)().internationalization;
29
- const IntlayerProvider = ({
30
- children,
31
- locale = defaultLocale
32
- }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_IntlayerServerProvider.IntlayerServerProvider, { locale, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_IntlayerClientProvider.IntlayerClientProvider, { locale, children }) });
33
- // Annotate the CommonJS export names for ESM import in node:
34
- 0 && (module.exports = {
35
- IntlayerProvider
36
- });
37
- //# sourceMappingURL=IntlayerProvider.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/IntlayerProvider.tsx"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\nimport type { FC } from 'react';\nimport {\n IntlayerClientProvider,\n type IntlayerClientProviderProps,\n} from './client/IntlayerClientProvider';\nimport {\n IntlayerServerProvider,\n type IntlayerServerProviderProps,\n} from './server/IntlayerServerProvider';\n\nconst { defaultLocale } = getConfiguration().internationalization;\n\ntype IntlayerProviderProps = IntlayerClientProviderProps &\n IntlayerServerProviderProps;\n\nexport const IntlayerProvider: FC<IntlayerProviderProps> = ({\n children,\n locale = defaultLocale,\n}) => (\n <IntlayerServerProvider locale={locale}>\n <IntlayerClientProvider locale={locale}>{children}</IntlayerClientProvider>\n </IntlayerServerProvider>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBI;AArBJ,oBAAiC;AAEjC,oCAGO;AACP,oCAGO;AAEP,MAAM,EAAE,cAAc,QAAI,gCAAiB,EAAE;AAKtC,MAAM,mBAA8C,CAAC;AAAA,EAC1D;AAAA,EACA,SAAS;AACX,MACE,4CAAC,wDAAuB,QACtB,sDAAC,wDAAuB,QAAiB,UAAS,GACpD;","names":[]}
@@ -1,9 +0,0 @@
1
- import { FC } from 'react';
2
- import { IntlayerClientProviderProps } from './client/IntlayerClientProvider.js';
3
- import { IntlayerServerProviderProps } from './server/IntlayerServerProvider.js';
4
- import '@intlayer/config/client';
5
-
6
- type IntlayerProviderProps = IntlayerClientProviderProps & IntlayerServerProviderProps;
7
- declare const IntlayerProvider: FC<IntlayerProviderProps>;
8
-
9
- export { IntlayerProvider };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/client/IntlayerClientProvider.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 IntlayerClientProviderProps = PropsWithChildren & {\n locale?: Locales;\n};\n\n/**\n * Provider that store the current locale on the client side\n */\nexport const IntlayerClientProvider: FC<IntlayerClientProviderProps> = ({\n locale,\n children,\n}) => {\n const { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n\n const [currentLocale, setCurrentLocale] = useState(\n locale ?? localeCookie ?? defaultLocale\n );\n\n const setLocale = 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 value: IntlayerValue = useMemo<IntlayerValue>(\n () => ({ locale: currentLocale, 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":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyEM;AAvEN,oBAA+C;AAC/C,mBAQO;AACP,kCAAqC;AACrC,6BAA8C;AAUvC,MAAM,4BAAwB,4BAA6B;AAAA,EAChE,QAAQ,2CAAgB,gCAAiB,EAAE,qBAAqB;AAAA,EAChE,WAAW,MAAM;AACnB,CAAC;AAKM,MAAM,qBAAqB,UAAM,yBAAW,qBAAqB;AASjE,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA;AACF,MAAM;AACJ,QAAM,EAAE,eAAe,SAAS,iBAAiB,QAC/C,gCAAiB,EAAE;AAErB,QAAM,CAAC,eAAe,gBAAgB,QAAI;AAAA,IACxC,UAAU,uCAAgB;AAAA,EAC5B;AAEA,QAAM,gBAAY;AAAA,IAChB,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,kDAAgB,SAAS;AAAA,IAC3B;AAAA,IACA,CAAC,kBAAkB,eAAe,MAAM;AAAA,EAC1C;AAEA,QAAM,YAAuB;AAAA,IAC3B,OAAO,EAAE,QAAQ,eAAe,UAAU;AAAA,IAC1C,CAAC,eAAe,SAAS;AAAA,EAC3B;AAEA,SACE,4CAAC,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,9 +0,0 @@
1
- import { FC } from 'react';
2
- import { IntlayerClientProviderProps } from './client/IntlayerClientProvider.mjs';
3
- import { IntlayerServerProviderProps } from './server/IntlayerServerProvider.mjs';
4
- import '@intlayer/config/client';
5
-
6
- type IntlayerProviderProps = IntlayerClientProviderProps & IntlayerServerProviderProps;
7
- declare const IntlayerProvider: FC<IntlayerProviderProps>;
8
-
9
- export { IntlayerProvider };
@@ -1,18 +0,0 @@
1
- import "./chunk-ZNCO4QRF.mjs";
2
- import { jsx } from "react/jsx-runtime";
3
- import { getConfiguration } from "@intlayer/config/client";
4
- import {
5
- IntlayerClientProvider
6
- } from './client/IntlayerClientProvider.mjs';
7
- import {
8
- IntlayerServerProvider
9
- } from './server/IntlayerServerProvider.mjs';
10
- const { defaultLocale } = getConfiguration().internationalization;
11
- const IntlayerProvider = ({
12
- children,
13
- locale = defaultLocale
14
- }) => /* @__PURE__ */ jsx(IntlayerServerProvider, { locale, children: /* @__PURE__ */ jsx(IntlayerClientProvider, { locale, children }) });
15
- export {
16
- IntlayerProvider
17
- };
18
- //# sourceMappingURL=IntlayerProvider.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/IntlayerProvider.tsx"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\nimport type { FC } from 'react';\nimport {\n IntlayerClientProvider,\n type IntlayerClientProviderProps,\n} from './client/IntlayerClientProvider';\nimport {\n IntlayerServerProvider,\n type IntlayerServerProviderProps,\n} from './server/IntlayerServerProvider';\n\nconst { defaultLocale } = getConfiguration().internationalization;\n\ntype IntlayerProviderProps = IntlayerClientProviderProps &\n IntlayerServerProviderProps;\n\nexport const IntlayerProvider: FC<IntlayerProviderProps> = ({\n children,\n locale = defaultLocale,\n}) => (\n <IntlayerServerProvider locale={locale}>\n <IntlayerClientProvider locale={locale}>{children}</IntlayerClientProvider>\n </IntlayerServerProvider>\n);\n"],"mappings":";AAqBI;AArBJ,SAAS,wBAAwB;AAEjC;AAAA,EACE;AAAA,OAEK;AACP;AAAA,EACE;AAAA,OAEK;AAEP,MAAM,EAAE,cAAc,IAAI,iBAAiB,EAAE;AAKtC,MAAM,mBAA8C,CAAC;AAAA,EAC1D;AAAA,EACA,SAAS;AACX,MACE,oBAAC,0BAAuB,QACtB,8BAAC,0BAAuB,QAAiB,UAAS,GACpD;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/client/IntlayerClientProvider.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 IntlayerClientProviderProps = PropsWithChildren & {\n locale?: Locales;\n};\n\n/**\n * Provider that store the current locale on the client side\n */\nexport const IntlayerClientProvider: FC<IntlayerClientProviderProps> = ({\n locale,\n children,\n}) => {\n const { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n\n const [currentLocale, setCurrentLocale] = useState(\n locale ?? localeCookie ?? defaultLocale\n );\n\n const setLocale = 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 value: IntlayerValue = useMemo<IntlayerValue>(\n () => ({ locale: currentLocale, 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":";;AAyEM;AAvEN,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;AASjE,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA;AACF,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,YAAY;AAAA,IAChB,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,QAAuB;AAAA,IAC3B,OAAO,EAAE,QAAQ,eAAe,UAAU;AAAA,IAC1C,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,24 +0,0 @@
1
- import { getConfiguration } from '@intlayer/config/client';
2
- import type { FC } from 'react';
3
- import {
4
- IntlayerClientProvider,
5
- type IntlayerClientProviderProps,
6
- } from './client/IntlayerClientProvider';
7
- import {
8
- IntlayerServerProvider,
9
- type IntlayerServerProviderProps,
10
- } from './server/IntlayerServerProvider';
11
-
12
- const { defaultLocale } = getConfiguration().internationalization;
13
-
14
- type IntlayerProviderProps = IntlayerClientProviderProps &
15
- IntlayerServerProviderProps;
16
-
17
- export const IntlayerProvider: FC<IntlayerProviderProps> = ({
18
- children,
19
- locale = defaultLocale,
20
- }) => (
21
- <IntlayerServerProvider locale={locale}>
22
- <IntlayerClientProvider locale={locale}>{children}</IntlayerClientProvider>
23
- </IntlayerServerProvider>
24
- );