react-intlayer 2.0.0 → 2.0.2

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 (125) hide show
  1. package/dist/cjs/client/ContentEditionLayout.cjs.map +1 -1
  2. package/dist/cjs/client/{IntlayerClientProvider.cjs → IntlayerProvider.cjs} +14 -11
  3. package/dist/cjs/client/IntlayerProvider.cjs.map +1 -0
  4. package/dist/cjs/client/{IntlayerClientProvider.d.ts → IntlayerProvider.d.ts} +5 -3
  5. package/dist/cjs/client/getBrowserLocale.cjs +7 -14
  6. package/dist/cjs/client/getBrowserLocale.cjs.map +1 -1
  7. package/dist/cjs/client/index.cjs +6 -6
  8. package/dist/cjs/client/index.cjs.map +1 -1
  9. package/dist/cjs/client/index.d.ts +3 -2
  10. package/dist/cjs/client/useContent.d.ts +1 -1
  11. package/dist/cjs/client/useIntlayer.cjs +2 -2
  12. package/dist/cjs/client/useIntlayer.cjs.map +1 -1
  13. package/dist/cjs/client/useIntlayer.d.ts +3 -1
  14. package/dist/cjs/client/useLocale.cjs +2 -2
  15. package/dist/cjs/client/useLocale.cjs.map +1 -1
  16. package/dist/cjs/client/useLocaleBase.cjs +2 -2
  17. package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
  18. package/dist/cjs/client/useLocaleCookie.cjs.map +1 -1
  19. package/dist/cjs/client/useTraduction.cjs +2 -2
  20. package/dist/cjs/client/useTraduction.cjs.map +1 -1
  21. package/dist/cjs/index.cjs +4 -4
  22. package/dist/cjs/index.cjs.map +1 -1
  23. package/dist/cjs/index.d.ts +3 -2
  24. package/dist/cjs/processDictionary/contentDictionary.cjs.map +1 -1
  25. package/dist/cjs/processDictionary/contentDictionary.d.ts +9 -9
  26. package/dist/cjs/processDictionary/index.cjs +69 -53
  27. package/dist/cjs/processDictionary/index.cjs.map +1 -1
  28. package/dist/cjs/processDictionary/index.d.ts +4 -4
  29. package/dist/cjs/server/IntlayerServerProvider.cjs +3 -4
  30. package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
  31. package/dist/cjs/server/IntlayerServerProvider.d.ts +6 -7
  32. package/dist/cjs/server/index.d.ts +1 -0
  33. package/dist/cjs/server/serverContext.cjs +1 -2
  34. package/dist/cjs/server/serverContext.cjs.map +1 -1
  35. package/dist/cjs/server/useIntlayer.d.ts +3 -1
  36. package/dist/cjs/useIntlayerBase.cjs +26 -1
  37. package/dist/cjs/useIntlayerBase.cjs.map +1 -1
  38. package/dist/cjs/useIntlayerBase.d.ts +62 -4
  39. package/dist/esm/{chunk-ZNCO4QRF.mjs → chunk-ZD7AOCMD.mjs} +1 -1
  40. package/dist/esm/client/ContentEditionLayout.mjs +1 -1
  41. package/dist/esm/client/ContentEditionLayout.mjs.map +1 -1
  42. package/dist/esm/client/{IntlayerClientProvider.d.mts → IntlayerProvider.d.mts} +5 -3
  43. package/dist/esm/client/{IntlayerClientProvider.mjs → IntlayerProvider.mjs} +11 -8
  44. package/dist/esm/client/IntlayerProvider.mjs.map +1 -0
  45. package/dist/esm/client/getBrowserLocale.mjs +8 -15
  46. package/dist/esm/client/getBrowserLocale.mjs.map +1 -1
  47. package/dist/esm/client/index.d.mts +3 -2
  48. package/dist/esm/client/index.mjs +5 -5
  49. package/dist/esm/client/index.mjs.map +1 -1
  50. package/dist/esm/client/useContent.d.mts +1 -1
  51. package/dist/esm/client/useContent.mjs +1 -1
  52. package/dist/esm/client/useIntlayer.d.mts +3 -1
  53. package/dist/esm/client/useIntlayer.mjs +2 -2
  54. package/dist/esm/client/useIntlayer.mjs.map +1 -1
  55. package/dist/esm/client/useLocale.mjs +2 -2
  56. package/dist/esm/client/useLocale.mjs.map +1 -1
  57. package/dist/esm/client/useLocaleBase.mjs +2 -2
  58. package/dist/esm/client/useLocaleBase.mjs.map +1 -1
  59. package/dist/esm/client/useLocaleCookie.mjs +1 -1
  60. package/dist/esm/client/useLocaleCookie.mjs.map +1 -1
  61. package/dist/esm/client/useTraduction.mjs +2 -2
  62. package/dist/esm/client/useTraduction.mjs.map +1 -1
  63. package/dist/esm/craco/craco.config.mjs +1 -1
  64. package/dist/esm/craco/intlayerCracoPlugin.mjs +1 -1
  65. package/dist/esm/getEnumeration.mjs +1 -1
  66. package/dist/esm/getTranslation.mjs +1 -1
  67. package/dist/esm/index.d.mts +3 -2
  68. package/dist/esm/index.mjs +5 -5
  69. package/dist/esm/index.mjs.map +1 -1
  70. package/dist/esm/processDictionary/contentDictionary.d.mts +9 -9
  71. package/dist/esm/processDictionary/index.d.mts +4 -4
  72. package/dist/esm/processDictionary/index.mjs +70 -54
  73. package/dist/esm/processDictionary/index.mjs.map +1 -1
  74. package/dist/esm/server/IntlayerServerProvider.d.mts +6 -7
  75. package/dist/esm/server/IntlayerServerProvider.mjs +4 -5
  76. package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
  77. package/dist/esm/server/getLocaleTranslation.mjs +1 -1
  78. package/dist/esm/server/index.d.mts +1 -0
  79. package/dist/esm/server/index.mjs +1 -1
  80. package/dist/esm/server/serverContext.mjs +2 -3
  81. package/dist/esm/server/serverContext.mjs.map +1 -1
  82. package/dist/esm/server/useIntlayer.d.mts +3 -1
  83. package/dist/esm/server/useIntlayer.mjs +1 -1
  84. package/dist/esm/server/useTraduction.mjs +1 -1
  85. package/dist/esm/useIntlayerBase.d.mts +62 -4
  86. package/dist/esm/useIntlayerBase.mjs +26 -2
  87. package/dist/esm/useIntlayerBase.mjs.map +1 -1
  88. package/dist/esm/vite/intlayerPlugin.mjs +1 -1
  89. package/package.json +18 -19
  90. package/src/index.ts +4 -3
  91. package/dist/cjs/IntlayerProvider.cjs +0 -37
  92. package/dist/cjs/IntlayerProvider.cjs.map +0 -1
  93. package/dist/cjs/IntlayerProvider.d.ts +0 -9
  94. package/dist/cjs/client/IntlayerClientProvider.cjs.map +0 -1
  95. package/dist/esm/IntlayerProvider.d.mts +0 -9
  96. package/dist/esm/IntlayerProvider.mjs +0 -18
  97. package/dist/esm/IntlayerProvider.mjs.map +0 -1
  98. package/dist/esm/client/IntlayerClientProvider.mjs.map +0 -1
  99. package/src/IntlayerProvider.tsx +0 -24
  100. package/src/cli/react-intlayer.ts +0 -60
  101. package/src/client/ContentEditionLayout.tsx +0 -15
  102. package/src/client/IntlayerClientProvider.tsx +0 -83
  103. package/src/client/getBrowserLocale.tsx +0 -192
  104. package/src/client/index.ts +0 -16
  105. package/src/client/useContent.ts +0 -20
  106. package/src/client/useIntlayer.ts +0 -25
  107. package/src/client/useLocale.ts +0 -23
  108. package/src/client/useLocaleBase.ts +0 -24
  109. package/src/client/useLocaleCookie.ts +0 -32
  110. package/src/client/useTraduction.ts +0 -33
  111. package/src/craco/craco.config.ts +0 -11
  112. package/src/craco/intlayerCracoPlugin.ts +0 -89
  113. package/src/getEnumeration.ts +0 -41
  114. package/src/getTranslation.ts +0 -37
  115. package/src/processDictionary/contentDictionary.ts +0 -28
  116. package/src/processDictionary/index.ts +0 -231
  117. package/src/server/IntlayerServerProvider.tsx +0 -36
  118. package/src/server/getLocaleTranslation.ts +0 -22
  119. package/src/server/index.ts +0 -8
  120. package/src/server/serverContext.ts +0 -85
  121. package/src/server/useIntlayer.ts +0 -23
  122. package/src/server/useTraduction.ts +0 -34
  123. package/src/useIntlayerBase.ts +0 -38
  124. package/src/vite/intlayerPlugin.ts +0 -59
  125. /package/dist/esm/{chunk-ZNCO4QRF.mjs.map → chunk-ZD7AOCMD.mjs.map} +0 -0
@@ -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[\n NodeType.Translation as keyof typeof field\n ] 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[\n NodeType.Enumeration as keyof typeof field\n ] 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 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"]}
@@ -1,18 +1,17 @@
1
- import * as react from 'react';
2
- import { PropsWithChildren, FC } from 'react';
3
1
  import { Locales } from '@intlayer/config/client';
2
+ import { PropsWithChildren, FC } from 'react';
4
3
 
5
4
  /**
6
5
  * Context that store the current locale on the server side
7
6
  */
8
7
  declare const IntlayerServerContext: {
9
8
  Provider: ({ children, value, }: {
10
- children: react.ReactNode;
9
+ children: React.ReactNode;
11
10
  value: Locales;
12
- }) => react.ReactNode;
11
+ }) => React.ReactNode;
13
12
  Consumer: ({ children, }: {
14
- children: (context: Locales | undefined) => react.ReactNode;
15
- }) => react.ReactNode;
13
+ children: (context: Locales | undefined) => React.ReactNode;
14
+ }) => React.ReactNode;
16
15
  _storage: () => {
17
16
  value: Locales | undefined;
18
17
  };
@@ -27,7 +26,7 @@ declare const useIntlayer: () => Locales | undefined;
27
26
  */
28
27
  declare const locale: Locales | undefined;
29
28
  type IntlayerServerProviderProps = PropsWithChildren & {
30
- locale: Locales;
29
+ locale?: Locales;
31
30
  };
32
31
  /**
33
32
  * Provider that store the current locale on the server side
@@ -1,15 +1,14 @@
1
- import "../chunk-ZNCO4QRF.mjs";
1
+ import "../chunk-ZD7AOCMD.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"]}
@@ -1,4 +1,4 @@
1
- import "../chunk-ZNCO4QRF.mjs";
1
+ import "../chunk-ZD7AOCMD.mjs";
2
2
  import { getConfiguration } from "@intlayer/config/client";
3
3
  import { getTranslationContent } from "@intlayer/core";
4
4
  import { IntlayerServerContext } from './IntlayerServerProvider.mjs';
@@ -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,4 +1,4 @@
1
- import "../chunk-ZNCO4QRF.mjs";
1
+ import "../chunk-ZD7AOCMD.mjs";
2
2
  import { getLocaleTranslation } from './getLocaleTranslation.mjs';
3
3
  import { useTraduction } from './useTraduction.mjs';
4
4
  import {
@@ -1,4 +1,4 @@
1
- import "../chunk-ZNCO4QRF.mjs";
1
+ import "../chunk-ZD7AOCMD.mjs";
2
2
  import react from "react";
3
3
  const cacheFallback = () => () => ({ value: void 0 });
4
4
  const createServerContext = (defaultValue) => {
@@ -25,8 +25,7 @@ const getServerContext = ({
25
25
  _defaultValue
26
26
  }) => {
27
27
  const store = _storage();
28
- if (!store)
29
- return _defaultValue;
28
+ if (!store) return _defaultValue;
30
29
  return store.value;
31
30
  };
32
31
  const throwInClient = () => {
@@ -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 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":";AAYA,OAAO,WAAW;AAIlB,MAAM,gBAAgB,MAAM,OAAO,EAAE,OAAO,OAAU;AAE/C,MAAM,sBAAsB,CAAI,iBAAuC;AAC5E,gBAAc;AAEd,QAAM,QAAQ,MAAM,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":[]}
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":";AAYA,OAAO,WAAW;AAIlB,MAAM,gBAAgB,MAAM,OAAO,EAAE,OAAO,OAAU;AAE/C,MAAM,sBAAsB,CAAI,iBAAuC;AAC5E,gBAAc;AAEd,QAAM,QAAQ,MAAM,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,MAAO,QAAO;AACnB,SAAO,MAAM;AACf;AAuBA,MAAM,gBAAgB,MAAoB;AAExC,MAAI,OAAO,WAAW,aAAa;AACjC,UAAM,IAAI,MAAM,qDAAqD;AAAA,EACvE;AACF;","names":[]}
@@ -1,6 +1,8 @@
1
1
  import { UseIntlayer } from '../useIntlayerBase.mjs';
2
- import '@intlayer/config/client';
2
+ import '@intlayer/config';
3
+ import '@intlayer/core';
3
4
  import 'intlayer';
5
+ import 'react';
4
6
 
5
7
  /**
6
8
  * On the server side, Hook that picking one dictionary by its id and return the content
@@ -1,4 +1,4 @@
1
- import "../chunk-ZNCO4QRF.mjs";
1
+ import "../chunk-ZD7AOCMD.mjs";
2
2
  import {
3
3
  useIntlayerBase
4
4
  } from '../useIntlayerBase.mjs';
@@ -1,4 +1,4 @@
1
- import "../chunk-ZNCO4QRF.mjs";
1
+ import "../chunk-ZD7AOCMD.mjs";
2
2
  import { getTranslation } from '../getTranslation.mjs';
3
3
  import { IntlayerServerContext } from './IntlayerServerProvider.mjs';
4
4
  import { getServerContext } from './serverContext.mjs';
@@ -1,12 +1,70 @@
1
- import { Locales } from '@intlayer/config/client';
1
+ import { Locales } from '@intlayer/config';
2
+ import { NodeType } from '@intlayer/core';
2
3
  import { IntlayerDictionaryTypesConnector } from 'intlayer';
4
+ import { ReactNode } from 'react';
3
5
 
6
+ /**
7
+ * Provides a fallback to string type if the generic type T is never,
8
+ * otherwise returns T. This is useful for handling cases where no keys are found.
9
+ * Example: StringFallback<never> -> string; StringFallback<'key'> -> 'key'
10
+ */
4
11
  type StringFallback<T> = T extends never ? string : T;
12
+ /**
13
+ * Represents the keys of the IntlayerDictionaryTypesConnector,
14
+ * ensuring they are valid dictionary keys or fallback to string if none exist.
15
+ *
16
+ * Example:
17
+ * ```ts
18
+ * DictionaryKeys -> 'key1' | 'key2'
19
+ * // or if IntlayerDictionaryTypesConnector is not defined,
20
+ * DictionaryKeys -> string
21
+ * ```
22
+ */
5
23
  type DictionaryKeys = StringFallback<keyof IntlayerDictionaryTypesConnector>;
6
- type UseIntlayer = <T extends DictionaryKeys>(id: T, locale?: Locales) => IntlayerDictionaryTypesConnector[T];
24
+ type IntlayerNode<T = string> = ReactNode & {
25
+ value: T;
26
+ };
27
+ type TransformNodeType<T, L extends Locales> = T extends {
28
+ [NodeType.Enumeration]: {
29
+ '1': any;
30
+ };
31
+ } ? (quantity: number) => DeepTransformContent<T[NodeType.Enumeration]['1'], L> : T extends {
32
+ [NodeType.Translation]: object;
33
+ } ? L extends keyof T[NodeType.Translation] ? DeepTransformContent<T[NodeType.Translation][L], L> : never : T;
34
+ type DeepTransformContent<T, L extends Locales> = T extends object ? T extends (infer U)[] ? DeepTransformContent<U, L>[] : T extends {
35
+ nodeType: NodeType | string;
36
+ } ? TransformNodeType<T, L> : T extends {
37
+ _owner: any;
38
+ key: any;
39
+ props: any;
40
+ ref: any;
41
+ } ? ReactNode : {
42
+ [K in keyof T]: DeepTransformContent<T[K], L>;
43
+ } : T extends undefined ? never : IntlayerNode<T>;
44
+ /**
45
+ * Excludes the 'id' and 'filePath' keys from the dictionary content,
46
+ * as they are not part of the IntlayerDictionaryTypesConnector type.
47
+ */
48
+ type ExcludeIntlayerUtilsKeys<T> = Omit<T, 'id' | 'filePath'>;
49
+ /**
50
+ * Represents the data type returned by the useIntlayer hook,
51
+ * excluding the 'id' and 'filePath' keys from the dictionary content.
52
+ */
53
+ type Data<T extends DictionaryKeys, K extends Locales> = ExcludeIntlayerUtilsKeys<DeepTransformContent<IntlayerDictionaryTypesConnector[T], K>>;
54
+ /**
55
+ * Parcourt the object. If a object has a keyPath, render the intlayer editor if editor enabled.
56
+ */
57
+ declare const recursiveTransformContent: (value: any) => object;
58
+ /**
59
+ * Type definition for the useIntlayer hook, which takes a dictionary ID and an optional locale,
60
+ * and returns the deeply transformed dictionary content.
61
+ *
62
+ */
63
+ type UseIntlayer = <T extends DictionaryKeys, L extends Locales>(id: T, locale?: L) => Data<T, L>;
7
64
  /**
8
- * Hook that picking one dictionary by its id and return the content.
65
+ * Hook that picks one dictionary by its ID and returns the content,
66
+ * deeply transformed according to the dictionary structure and metadata.
9
67
  */
10
68
  declare const useIntlayerBase: UseIntlayer;
11
69
 
12
- export { type DictionaryKeys, type StringFallback, type UseIntlayer, useIntlayerBase };
70
+ export { type DictionaryKeys, type IntlayerNode, type StringFallback, type UseIntlayer, recursiveTransformContent, useIntlayerBase };
@@ -1,17 +1,41 @@
1
- import "./chunk-ZNCO4QRF.mjs";
1
+ import "./chunk-ZD7AOCMD.mjs";
2
2
  import dictionaries from "@intlayer/dictionaries-entry";
3
+ import { renderIntlayerEditor } from "intlayer-editor/client";
4
+ import { isValidElement } from "react";
3
5
  import { processDictionary } from './processDictionary/index.mjs';
6
+ const recursiveTransformContent = (value) => {
7
+ if (typeof value === "function") {
8
+ return (props) => recursiveTransformContent(value(props));
9
+ } else if (typeof value === "object" && typeof value.keyPath !== "undefined" && typeof value.dictionaryId !== "undefined" && typeof value.dictionaryPath !== "undefined") {
10
+ return renderIntlayerEditor(value);
11
+ } else if (typeof value === "object" && Array.isArray(value)) {
12
+ return value.map(recursiveTransformContent);
13
+ } else if (typeof value === "object" && isValidElement(value)) {
14
+ return value;
15
+ } else if (typeof value === "object") {
16
+ return Object.entries(value).reduce(
17
+ (acc, [key, value2]) => ({
18
+ ...acc,
19
+ [key]: recursiveTransformContent(value2)
20
+ }),
21
+ {}
22
+ );
23
+ }
24
+ return value.value;
25
+ };
4
26
  const useIntlayerBase = (id, locale) => {
5
27
  const dictionary = dictionaries[id];
6
- return processDictionary(
28
+ const result = processDictionary(
7
29
  dictionary,
8
30
  id,
9
31
  dictionary.filePath,
10
32
  [],
11
33
  locale
12
34
  );
35
+ return recursiveTransformContent(result);
13
36
  };
14
37
  export {
38
+ recursiveTransformContent,
15
39
  useIntlayerBase
16
40
  };
17
41
  //# 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":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport 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, NodeType } from '@intlayer/core';\nimport dictionaries from '@intlayer/dictionaries-entry';\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport { renderIntlayerEditor } from 'intlayer-editor/client';\nimport { isValidElement, 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<T = string> = ReactNode & {\n value: T;\n};\n\ntype TransformNodeType<T, L extends Locales> = T extends {\n [NodeType.Enumeration]: { '1': any };\n}\n ? (quantity: number) => DeepTransformContent<T[NodeType.Enumeration]['1'], L>\n : T extends {\n [NodeType.Translation]: object;\n }\n ? L extends keyof T[NodeType.Translation]\n ? DeepTransformContent<T[NodeType.Translation][L], L> // DeepTransformContent<T[L], L>\n : never\n : T;\n\ntype DeepTransformContent<T, L extends Locales> = T extends object // Check if the property is an object\n ? T extends (infer U)[] // If it's an array, infer the type of array elements\n ? DeepTransformContent<U, L>[] // Apply DeepTransformContent recursively to each element of the array\n : T extends {\n nodeType: NodeType | string;\n }\n ? TransformNodeType<T, L>\n : T extends { _owner: any; key: any; props: any; ref: any }\n ? ReactNode\n : {\n [K in keyof T]: DeepTransformContent<T[K], L>;\n }\n : T extends undefined\n ? never\n : IntlayerNode<T>;\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<\n T extends DictionaryKeys,\n K extends Locales,\n> = ExcludeIntlayerUtilsKeys<\n DeepTransformContent<IntlayerDictionaryTypesConnector[T], K>\n>;\n\n/**\n * Parcourt the object. If a object has a keyPath, render the intlayer editor if editor enabled.\n */\nexport const recursiveTransformContent = (value: any): object => {\n if (typeof value === 'function') {\n return (props: any) => recursiveTransformContent(value(props));\n } else if (\n typeof value === 'object' &&\n typeof value.keyPath !== 'undefined' &&\n typeof value.dictionaryId !== 'undefined' &&\n typeof value.dictionaryPath !== 'undefined'\n ) {\n return renderIntlayerEditor(value);\n } else if (typeof value === 'object' && Array.isArray(value)) {\n return value.map(recursiveTransformContent);\n } else if (typeof value === 'object' && isValidElement(value)) {\n return value;\n } else if (typeof value === 'object') {\n return Object.entries(value).reduce(\n (acc, [key, value]) => ({\n ...acc,\n [key]: recursiveTransformContent(value),\n }),\n {} as object\n );\n }\n\n return value.value;\n};\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, L extends Locales>(\n id: T,\n locale?: L\n) => Data<T, L>;\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 = <\n T extends DictionaryKeys,\n L extends Locales,\n>(\n id: T,\n locale?: L\n) => {\n const dictionary: Dictionary = dictionaries[id as keyof typeof dictionaries];\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, L>;\n};\n"],"mappings":";AAQA,OAAO,kBAAkB;AAEzB,SAAS,4BAA4B;AACrC,SAAS,sBAAsC;AAC/C,SAAS,yBAAyB;AA4E3B,MAAM,4BAA4B,CAAC,UAAuB;AAC/D,MAAI,OAAO,UAAU,YAAY;AAC/B,WAAO,CAAC,UAAe,0BAA0B,MAAM,KAAK,CAAC;AAAA,EAC/D,WACE,OAAO,UAAU,YACjB,OAAO,MAAM,YAAY,eACzB,OAAO,MAAM,iBAAiB,eAC9B,OAAO,MAAM,mBAAmB,aAChC;AACA,WAAO,qBAAqB,KAAK;AAAA,EACnC,WAAW,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAAG;AAC5D,WAAO,MAAM,IAAI,yBAAyB;AAAA,EAC5C,WAAW,OAAO,UAAU,YAAY,eAAe,KAAK,GAAG;AAC7D,WAAO;AAAA,EACT,WAAW,OAAO,UAAU,UAAU;AACpC,WAAO,OAAO,QAAQ,KAAK,EAAE;AAAA,MAC3B,CAAC,KAAK,CAAC,KAAKA,MAAK,OAAO;AAAA,QACtB,GAAG;AAAA,QACH,CAAC,GAAG,GAAG,0BAA0BA,MAAK;AAAA,MACxC;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO,MAAM;AACf;AAgBO,MAAM,kBAA+B,CAI1C,IACA,WACG;AACH,QAAM,aAAyB,aAAa,EAA+B;AAE3E,QAAM,SAAS;AAAA,IACb;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF;AAEA,SAAO,0BAA0B,MAAM;AACzC;","names":["value"]}
@@ -1,4 +1,4 @@
1
- import "../chunk-ZNCO4QRF.mjs";
1
+ import "../chunk-ZD7AOCMD.mjs";
2
2
  import { join, relative, resolve } from "path";
3
3
  import { watch } from "@intlayer/chokidar";
4
4
  import { getConfiguration, formatEnvVariable } from "@intlayer/config";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-intlayer",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
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,40 +67,39 @@
67
67
  },
68
68
  "files": [
69
69
  "./dist",
70
- "./src",
71
70
  "./package.json"
72
71
  ],
73
72
  "dependencies": {
74
73
  "cross-spawn": "^7.0.3",
75
74
  "js-cookie": "^3.0.5",
76
75
  "react-cookie": "^7.1.4",
77
- "vite": "^5.2.0",
78
- "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"
76
+ "vite": "^5.3.1",
77
+ "webpack": "^5.92.1",
78
+ "@intlayer/config": "^2.0.2",
79
+ "@intlayer/chokidar": "^2.0.2",
80
+ "@intlayer/core": "^2.0.2",
81
+ "@intlayer/webpack": "^2.0.2",
82
+ "intlayer": "^2.0.2",
83
+ "@intlayer/dictionaries-entry": "^2.0.2"
85
84
  },
86
85
  "devDependencies": {
87
86
  "@craco/types": "^7.1.0",
88
87
  "@types/cross-spawn": "^6.0.6",
89
88
  "@types/js-cookie": "^3.0.6",
90
- "@types/node": "^20.12.7",
91
- "@types/react": "^18.2.79",
92
- "react": "^18.2.0",
93
- "react-dom": "^18.2.0",
89
+ "@types/node": "^20.14.9",
90
+ "@types/react": "^18.3.3",
91
+ "react": "^18.3.1",
92
+ "react-dom": "^18.3.1",
94
93
  "rimraf": "5.0.5",
95
- "tsup": "^8.0.2",
96
- "typescript": "^5.4.5",
97
- "@utils/eslint-config": "^1.0.1",
98
- "@utils/ts-config": "^1.0.1"
94
+ "tsup": "^8.1.0",
95
+ "typescript": "^5.5.2",
96
+ "@utils/eslint-config": "^1.0.2",
97
+ "@utils/ts-config": "^1.0.2"
99
98
  },
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.1"
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 type { IntlayerNode } 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
- );
@@ -1,60 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * To make the setup easier, we are using craco to override the webpack configuration.
5
- * This script is used to run the craco scripts with the custom configuration.
6
- *
7
- * The script is based on the original craco script from create-react-app.
8
- */
9
-
10
- import spawn from 'cross-spawn';
11
-
12
- const args = process.argv.slice(2);
13
- const scriptIndex = args.findIndex(
14
- (x) => x === 'build' || x === 'start' || x === 'test'
15
- );
16
- const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
17
-
18
- switch (script) {
19
- case 'build':
20
- case 'start':
21
- case 'test': {
22
- const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
23
- const scriptPath = require.resolve(`@craco/craco/dist/scripts/${script}`);
24
- const scriptArgs = args.slice(scriptIndex + 1);
25
- const processArgs = nodeArgs
26
- .concat(scriptPath)
27
- .concat([
28
- ...scriptArgs,
29
- '--config',
30
- './node_modules/react-intlayer/dist/cjs/craco/craco.config.cjs',
31
- ]);
32
-
33
- const child = spawn.sync('node', processArgs, { stdio: 'inherit' });
34
-
35
- if (child.signal) {
36
- if (child.signal === 'SIGKILL') {
37
- console.info(`
38
- The build failed because the process exited too early.
39
- This probably means the system ran out of memory or someone called
40
- \`kill -9\` on the process.
41
- `);
42
- } else if (child.signal === 'SIGTERM') {
43
- console.info(`
44
- The build failed because the process exited too early.
45
- Someone might have called \`kill\` or \`killall\`, or the system could
46
- be shutting down.
47
- `);
48
- }
49
-
50
- process.exit(1);
51
- }
52
-
53
- process.exit(child.status ?? undefined);
54
- break;
55
- }
56
- default:
57
- console.info(`Unknown script "${script}".`);
58
- console.info('Perhaps you need to update craco?');
59
- break;
60
- }