react-intlayer 1.2.1 → 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 (143) hide show
  1. package/dist/cjs/{ContentEditor/contentRender.cjs → client/ContentEditionLayout.cjs} +13 -14
  2. package/dist/cjs/client/ContentEditionLayout.cjs.map +1 -0
  3. package/dist/cjs/client/ContentEditionLayout.d.ts +6 -0
  4. package/dist/cjs/client/{IntlayerClientProvider.cjs → IntlayerProvider.cjs} +21 -10
  5. package/dist/cjs/client/IntlayerProvider.cjs.map +1 -0
  6. package/dist/{esm/client/IntlayerClientProvider.d.mts → cjs/client/IntlayerProvider.d.ts} +4 -3
  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 +2 -1
  10. package/dist/cjs/client/useContent.d.ts +1 -2
  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 +2 -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/useTraduction.cjs +2 -2
  19. package/dist/cjs/client/useTraduction.cjs.map +1 -1
  20. package/dist/cjs/getEnumeration.cjs +0 -4
  21. package/dist/cjs/getEnumeration.cjs.map +1 -1
  22. package/dist/cjs/getTranslation.cjs +0 -4
  23. package/dist/cjs/getTranslation.cjs.map +1 -1
  24. package/dist/cjs/index.cjs +7 -4
  25. package/dist/cjs/index.cjs.map +1 -1
  26. package/dist/cjs/index.d.ts +3 -2
  27. package/dist/cjs/processDictionary/{contentDictionary.d.cjs → contentDictionary.cjs} +3 -3
  28. package/dist/cjs/processDictionary/contentDictionary.cjs.map +1 -0
  29. package/dist/cjs/processDictionary/contentDictionary.d.ts +16 -0
  30. package/dist/cjs/processDictionary/index.cjs +114 -33
  31. package/dist/cjs/processDictionary/index.cjs.map +1 -1
  32. package/dist/cjs/processDictionary/index.d.ts +5 -4
  33. package/dist/cjs/server/IntlayerServerProvider.cjs +3 -4
  34. package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
  35. package/dist/cjs/server/IntlayerServerProvider.d.ts +1 -1
  36. package/dist/cjs/server/index.d.ts +1 -0
  37. package/dist/cjs/server/useIntlayer.d.ts +2 -1
  38. package/dist/cjs/useIntlayerBase.cjs +48 -1
  39. package/dist/cjs/useIntlayerBase.cjs.map +1 -1
  40. package/dist/cjs/useIntlayerBase.d.ts +51 -4
  41. package/dist/cjs/vite/intlayerPlugin.cjs +1 -1
  42. package/dist/cjs/vite/intlayerPlugin.cjs.map +1 -1
  43. package/dist/esm/client/ContentEditionLayout.d.mts +6 -0
  44. package/dist/esm/client/ContentEditionLayout.mjs +15 -0
  45. package/dist/esm/client/ContentEditionLayout.mjs.map +1 -0
  46. package/dist/{cjs/client/IntlayerClientProvider.d.ts → esm/client/IntlayerProvider.d.mts} +4 -3
  47. package/dist/esm/client/{IntlayerClientProvider.mjs → IntlayerProvider.mjs} +17 -6
  48. package/dist/esm/client/IntlayerProvider.mjs.map +1 -0
  49. package/dist/esm/client/index.d.mts +2 -1
  50. package/dist/esm/client/index.mjs +4 -4
  51. package/dist/esm/client/index.mjs.map +1 -1
  52. package/dist/esm/client/useContent.d.mts +1 -2
  53. package/dist/esm/client/useIntlayer.d.mts +2 -1
  54. package/dist/esm/client/useIntlayer.mjs +1 -1
  55. package/dist/esm/client/useIntlayer.mjs.map +1 -1
  56. package/dist/esm/client/useLocale.mjs +1 -1
  57. package/dist/esm/client/useLocale.mjs.map +1 -1
  58. package/dist/esm/client/useLocaleBase.mjs +1 -1
  59. package/dist/esm/client/useLocaleBase.mjs.map +1 -1
  60. package/dist/esm/client/useTraduction.mjs +1 -1
  61. package/dist/esm/client/useTraduction.mjs.map +1 -1
  62. package/dist/esm/getEnumeration.mjs +0 -4
  63. package/dist/esm/getEnumeration.mjs.map +1 -1
  64. package/dist/esm/getTranslation.mjs +0 -4
  65. package/dist/esm/getTranslation.mjs.map +1 -1
  66. package/dist/esm/index.d.mts +3 -2
  67. package/dist/esm/index.mjs +6 -4
  68. package/dist/esm/index.mjs.map +1 -1
  69. package/dist/esm/processDictionary/contentDictionary.d.mts +16 -0
  70. package/dist/esm/processDictionary/contentDictionary.mjs +1 -0
  71. package/dist/esm/processDictionary/index.d.mts +5 -4
  72. package/dist/esm/processDictionary/index.mjs +116 -34
  73. package/dist/esm/processDictionary/index.mjs.map +1 -1
  74. package/dist/esm/server/IntlayerServerProvider.d.mts +1 -1
  75. package/dist/esm/server/IntlayerServerProvider.mjs +3 -4
  76. package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
  77. package/dist/esm/server/index.d.mts +1 -0
  78. package/dist/esm/server/useIntlayer.d.mts +2 -1
  79. package/dist/esm/useIntlayerBase.d.mts +51 -4
  80. package/dist/esm/useIntlayerBase.mjs +46 -1
  81. package/dist/esm/useIntlayerBase.mjs.map +1 -1
  82. package/dist/esm/vite/intlayerPlugin.mjs +1 -1
  83. package/dist/esm/vite/intlayerPlugin.mjs.map +1 -1
  84. package/package.json +14 -9
  85. package/src/index.ts +4 -3
  86. package/dist/cjs/ContentEditor/ContentEditor.cjs +0 -110
  87. package/dist/cjs/ContentEditor/ContentEditor.cjs.map +0 -1
  88. package/dist/cjs/ContentEditor/ContentEditor.d.ts +0 -8
  89. package/dist/cjs/ContentEditor/contentRender.cjs.map +0 -1
  90. package/dist/cjs/ContentEditor/contentRender.d.ts +0 -3
  91. package/dist/cjs/ContentEditor/index.cjs +0 -25
  92. package/dist/cjs/ContentEditor/index.cjs.map +0 -1
  93. package/dist/cjs/ContentEditor/index.d.ts +0 -3
  94. package/dist/cjs/IntlayerProvider.cjs +0 -37
  95. package/dist/cjs/IntlayerProvider.cjs.map +0 -1
  96. package/dist/cjs/IntlayerProvider.d.ts +0 -9
  97. package/dist/cjs/client/IntlayerClientProvider.cjs.map +0 -1
  98. package/dist/cjs/processDictionary/contentDictionary.d.cjs.map +0 -1
  99. package/dist/cjs/processDictionary/contentDictionary.d.d.ts +0 -29
  100. package/dist/esm/ContentEditor/ContentEditor.d.mts +0 -8
  101. package/dist/esm/ContentEditor/ContentEditor.mjs +0 -92
  102. package/dist/esm/ContentEditor/ContentEditor.mjs.map +0 -1
  103. package/dist/esm/ContentEditor/contentRender.d.mts +0 -3
  104. package/dist/esm/ContentEditor/contentRender.mjs +0 -14
  105. package/dist/esm/ContentEditor/contentRender.mjs.map +0 -1
  106. package/dist/esm/ContentEditor/index.d.mts +0 -3
  107. package/dist/esm/ContentEditor/index.mjs +0 -3
  108. package/dist/esm/ContentEditor/index.mjs.map +0 -1
  109. package/dist/esm/IntlayerProvider.d.mts +0 -9
  110. package/dist/esm/IntlayerProvider.mjs +0 -18
  111. package/dist/esm/IntlayerProvider.mjs.map +0 -1
  112. package/dist/esm/client/IntlayerClientProvider.mjs.map +0 -1
  113. package/dist/esm/processDictionary/contentDictionary.d.d.mts +0 -29
  114. package/dist/esm/processDictionary/contentDictionary.d.mjs +0 -1
  115. package/src/ContentEditor/ContentEditor.tsx +0 -116
  116. package/src/ContentEditor/contentRender.tsx +0 -11
  117. package/src/ContentEditor/index.tsx +0 -2
  118. package/src/IntlayerProvider.tsx +0 -24
  119. package/src/cli/react-intlayer.ts +0 -60
  120. package/src/client/IntlayerClientProvider.tsx +0 -76
  121. package/src/client/getBrowserLocale.tsx +0 -192
  122. package/src/client/index.ts +0 -16
  123. package/src/client/useContent.ts +0 -20
  124. package/src/client/useIntlayer.ts +0 -25
  125. package/src/client/useLocale.ts +0 -23
  126. package/src/client/useLocaleBase.ts +0 -24
  127. package/src/client/useLocaleCookie.ts +0 -32
  128. package/src/client/useTraduction.ts +0 -33
  129. package/src/craco/craco.config.ts +0 -11
  130. package/src/craco/intlayerCracoPlugin.ts +0 -89
  131. package/src/getEnumeration.ts +0 -46
  132. package/src/getTranslation.ts +0 -42
  133. package/src/processDictionary/contentDictionary.d.ts +0 -27
  134. package/src/processDictionary/index.ts +0 -144
  135. package/src/server/IntlayerServerProvider.tsx +0 -36
  136. package/src/server/getLocaleTranslation.ts +0 -22
  137. package/src/server/index.ts +0 -8
  138. package/src/server/serverContext.ts +0 -85
  139. package/src/server/useIntlayer.ts +0 -23
  140. package/src/server/useTraduction.ts +0 -34
  141. package/src/useIntlayerBase.ts +0 -35
  142. package/src/vite/intlayerPlugin.ts +0 -59
  143. /package/dist/esm/processDictionary/{contentDictionary.d.mjs.map → contentDictionary.mjs.map} +0 -0
@@ -1,14 +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,
47
+ id,
48
+ dictionary.filePath,
49
+ [],
8
50
  locale
9
51
  );
52
+ return recursiveTransformContent(result);
10
53
  };
11
54
  export {
55
+ recursiveStringifyContent,
56
+ recursiveTransformContent,
12
57
  useIntlayerBase
13
58
  };
14
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 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,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":[]}
@@ -27,7 +27,7 @@ const intLayerPlugin = (_pluginOptions = {}) => ({
27
27
  persistent: import.meta.env === "development"
28
28
  });
29
29
  },
30
- configureServer: (server) => {
30
+ configureServer: () => {
31
31
  }
32
32
  });
33
33
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/vite/intlayerPlugin.ts"],"sourcesContent":["import { join, relative, resolve } from 'path';\nimport { watch } from '@intlayer/chokidar';\nimport { getConfiguration, formatEnvVariable } from '@intlayer/config';\nimport { loadEnv, type Plugin } from 'vite';\n\n// Plugin options type definition\ntype PluginOptions = {\n // Custom options for your plugin, if any\n};\n\n/**\n *\n * A Vite plugin that integrates IntLayer configuration into the build process\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intLayerPlugin() ],\n * });\n * ```\n * */\nexport const intLayerPlugin = (_pluginOptions: PluginOptions = {}): Plugin => ({\n name: 'vite-intlayer-plugin',\n\n config: (config, { mode }) => {\n const intlayerConfig = getConfiguration();\n\n // Set all configuration values as environment variables\n const env = formatEnvVariable('vite');\n\n process.env = { ...process.env, ...loadEnv(mode, process.cwd()), ...env };\n\n const { mainDir, baseDir } = intlayerConfig.content;\n const dictionariesPath = join(mainDir, 'dictionaries.mjs');\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n\n // Update Vite's resolve alias\n config.resolve = {\n ...config.resolve,\n alias: {\n ...config.resolve?.alias,\n '@intlayer/dictionaries-entry': resolve(relativeDictionariesPath),\n },\n };\n\n return config;\n },\n\n buildStart: () => {\n // Code to run when Vite build starts\n watch({\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n persistent: (import.meta as any).env === 'development',\n });\n },\n configureServer: (server) => {\n // Custom server configuration, if needed\n },\n});\n"],"mappings":";AAAA,SAAS,MAAM,UAAU,eAAe;AACxC,SAAS,aAAa;AACtB,SAAS,kBAAkB,yBAAyB;AACpD,SAAS,eAA4B;AAkB9B,MAAM,iBAAiB,CAAC,iBAAgC,CAAC,OAAe;AAAA,EAC7E,MAAM;AAAA,EAEN,QAAQ,CAAC,QAAQ,EAAE,KAAK,MAAM;AAC5B,UAAM,iBAAiB,iBAAiB;AAGxC,UAAM,MAAM,kBAAkB,MAAM;AAEpC,YAAQ,MAAM,EAAE,GAAG,QAAQ,KAAK,GAAG,QAAQ,MAAM,QAAQ,IAAI,CAAC,GAAG,GAAG,IAAI;AAExE,UAAM,EAAE,SAAS,QAAQ,IAAI,eAAe;AAC5C,UAAM,mBAAmB,KAAK,SAAS,kBAAkB;AACzD,UAAM,2BAA2B,SAAS,SAAS,gBAAgB;AAGnE,WAAO,UAAU;AAAA,MACf,GAAG,OAAO;AAAA,MACV,OAAO;AAAA,QACL,GAAG,OAAO,SAAS;AAAA,QACnB,gCAAgC,QAAQ,wBAAwB;AAAA,MAClE;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,MAAM;AAEhB,UAAM;AAAA;AAAA,MAEJ,YAAa,YAAoB,QAAQ;AAAA,IAC3C,CAAC;AAAA,EACH;AAAA,EACA,iBAAiB,CAAC,WAAW;AAAA,EAE7B;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/vite/intlayerPlugin.ts"],"sourcesContent":["import { join, relative, resolve } from 'path';\nimport { watch } from '@intlayer/chokidar';\nimport { getConfiguration, formatEnvVariable } from '@intlayer/config';\nimport { loadEnv, type Plugin } from 'vite';\n\n// Plugin options type definition\ntype PluginOptions = {\n // Custom options for your plugin, if any\n};\n\n/**\n *\n * A Vite plugin that integrates IntLayer configuration into the build process\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intLayerPlugin() ],\n * });\n * ```\n * */\nexport const intLayerPlugin = (_pluginOptions: PluginOptions = {}): Plugin => ({\n name: 'vite-intlayer-plugin',\n\n config: (config, { mode }) => {\n const intlayerConfig = getConfiguration();\n\n // Set all configuration values as environment variables\n const env = formatEnvVariable('vite');\n\n process.env = { ...process.env, ...loadEnv(mode, process.cwd()), ...env };\n\n const { mainDir, baseDir } = intlayerConfig.content;\n const dictionariesPath = join(mainDir, 'dictionaries.mjs');\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n\n // Update Vite's resolve alias\n config.resolve = {\n ...config.resolve,\n alias: {\n ...config.resolve?.alias,\n '@intlayer/dictionaries-entry': resolve(relativeDictionariesPath),\n },\n };\n\n return config;\n },\n\n buildStart: () => {\n // Code to run when Vite build starts\n watch({\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n persistent: (import.meta as any).env === 'development',\n });\n },\n configureServer: () => {\n // Custom server configuration, if needed\n },\n});\n"],"mappings":";AAAA,SAAS,MAAM,UAAU,eAAe;AACxC,SAAS,aAAa;AACtB,SAAS,kBAAkB,yBAAyB;AACpD,SAAS,eAA4B;AAkB9B,MAAM,iBAAiB,CAAC,iBAAgC,CAAC,OAAe;AAAA,EAC7E,MAAM;AAAA,EAEN,QAAQ,CAAC,QAAQ,EAAE,KAAK,MAAM;AAC5B,UAAM,iBAAiB,iBAAiB;AAGxC,UAAM,MAAM,kBAAkB,MAAM;AAEpC,YAAQ,MAAM,EAAE,GAAG,QAAQ,KAAK,GAAG,QAAQ,MAAM,QAAQ,IAAI,CAAC,GAAG,GAAG,IAAI;AAExE,UAAM,EAAE,SAAS,QAAQ,IAAI,eAAe;AAC5C,UAAM,mBAAmB,KAAK,SAAS,kBAAkB;AACzD,UAAM,2BAA2B,SAAS,SAAS,gBAAgB;AAGnE,WAAO,UAAU;AAAA,MACf,GAAG,OAAO;AAAA,MACV,OAAO;AAAA,QACL,GAAG,OAAO,SAAS;AAAA,QACnB,gCAAgC,QAAQ,wBAAwB;AAAA,MAClE;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,MAAM;AAEhB,UAAM;AAAA;AAAA,MAEJ,YAAa,YAAoB,QAAQ;AAAA,IAC3C,CAAC;AAAA,EACH;AAAA,EACA,iBAAiB,MAAM;AAAA,EAEvB;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-intlayer",
3
- "version": "1.2.1",
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": "^1.2.1",
80
- "@intlayer/config": "^1.2.1",
81
- "@intlayer/core": "^1.2.1",
82
- "@intlayer/dictionaries-entry": "^1.2.1",
83
- "@intlayer/webpack": "^1.2.1",
84
- "intlayer": "^1.2.1"
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",
@@ -99,7 +98,13 @@
99
98
  },
100
99
  "peerDependencies": {
101
100
  "react": "^18.2.0",
102
- "react-dom": "^18.2.0"
101
+ "react-dom": "^18.2.0",
102
+ "intlayer-editor": "^2.1.0"
103
+ },
104
+ "peerDependenciesMeta": {
105
+ "intlayer-editor": {
106
+ "optional": true
107
+ }
103
108
  },
104
109
  "engines": {
105
110
  "node": ">=14.18"
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,110 +0,0 @@
1
- "use strict";
2
- "use client";
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var ContentEditor_exports = {};
21
- __export(ContentEditor_exports, {
22
- ContentEditor: () => ContentEditor
23
- });
24
- module.exports = __toCommonJS(ContentEditor_exports);
25
- var import_jsx_runtime = require("react/jsx-runtime");
26
- var import_react = require("react");
27
- const PRESS_DETECT_DURATION = 500;
28
- const ContentEditor = ({ children }) => {
29
- const divRef = (0, import_react.useRef)(null);
30
- const [isEditing, setIsEditing] = (0, import_react.useState)(false);
31
- const pressTimerRef = (0, import_react.useRef)(null);
32
- const handleOnLongPress = () => {
33
- setIsEditing(true);
34
- };
35
- const startPressTimer = () => {
36
- pressTimerRef.current = setTimeout(() => {
37
- handleOnLongPress();
38
- }, PRESS_DETECT_DURATION);
39
- };
40
- const clearPressTimer = () => {
41
- if (pressTimerRef.current) {
42
- clearTimeout(pressTimerRef.current);
43
- pressTimerRef.current = null;
44
- }
45
- };
46
- const handleMouseDown = () => {
47
- clearPressTimer();
48
- startPressTimer();
49
- };
50
- const handleMouseUp = () => {
51
- clearPressTimer();
52
- };
53
- const handleClickOutside = (0, import_react.useCallback)(
54
- (event) => {
55
- if (divRef.current && !divRef.current.contains(event.target)) {
56
- setIsEditing(false);
57
- }
58
- },
59
- [divRef]
60
- );
61
- (0, import_react.useEffect)(() => {
62
- document.addEventListener("mousedown", handleClickOutside);
63
- return () => {
64
- document.removeEventListener("mousedown", handleClickOutside);
65
- clearPressTimer();
66
- };
67
- }, [handleClickOutside]);
68
- const handleOnClick = (e) => {
69
- if (isEditing) {
70
- e.preventDefault();
71
- e.stopPropagation();
72
- }
73
- };
74
- const handleOnBlur = () => {
75
- setIsEditing(false);
76
- };
77
- const onContentChange = (_e) => {
78
- };
79
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
80
- "div",
81
- {
82
- role: "textbox",
83
- tabIndex: 0,
84
- onKeyUp: () => null,
85
- contentEditable: isEditing,
86
- onInput: onContentChange,
87
- onClick: handleOnClick,
88
- onMouseDown: handleMouseDown,
89
- onMouseUp: handleMouseUp,
90
- onMouseLeave: handleMouseUp,
91
- onTouchStart: handleMouseDown,
92
- onTouchEnd: handleMouseUp,
93
- onTouchCancel: handleMouseUp,
94
- onBlur: handleOnBlur,
95
- suppressContentEditableWarning: true,
96
- style: isEditing ? {
97
- backgroundColor: "transparent",
98
- cursor: "text",
99
- display: "inline"
100
- } : { cursor: "pointer", display: "inline" },
101
- ref: divRef,
102
- children
103
- }
104
- );
105
- };
106
- // Annotate the CommonJS export names for ESM import in node:
107
- 0 && (module.exports = {
108
- ContentEditor
109
- });
110
- //# sourceMappingURL=ContentEditor.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/ContentEditor/ContentEditor.tsx"],"sourcesContent":["'use client';\n\nimport {\n useEffect,\n useState,\n useRef,\n useCallback,\n type FC,\n type MouseEventHandler,\n} from 'react';\n\ntype ContentEditorProps = {\n children?: string;\n};\n\nconst PRESS_DETECT_DURATION = 500;\n\nexport const ContentEditor: FC<ContentEditorProps> = ({ children }) => {\n const divRef = useRef<HTMLDivElement>(null);\n const [isEditing, setIsEditing] = useState(false);\n const pressTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n const handleOnLongPress = () => {\n setIsEditing(true);\n };\n\n const startPressTimer = () => {\n pressTimerRef.current = setTimeout(() => {\n handleOnLongPress();\n }, PRESS_DETECT_DURATION);\n };\n\n const clearPressTimer = () => {\n if (pressTimerRef.current) {\n clearTimeout(pressTimerRef.current);\n pressTimerRef.current = null;\n }\n };\n\n const handleMouseDown = () => {\n clearPressTimer(); // Ensure any previous timer is cleared\n startPressTimer();\n };\n\n const handleMouseUp = () => {\n clearPressTimer();\n };\n\n // Use useCallback to ensure the function identity remains stable\n const handleClickOutside = useCallback(\n (event: MouseEvent) => {\n if (divRef.current && !divRef.current.contains(event.target as Node)) {\n setIsEditing(false);\n }\n },\n [divRef]\n );\n\n useEffect(() => {\n // Attach click outside listener\n document.addEventListener('mousedown', handleClickOutside);\n\n return () => {\n // Cleanup\n document.removeEventListener('mousedown', handleClickOutside);\n clearPressTimer(); // Ensure to clear the timer when component unmounts\n };\n }, [handleClickOutside]);\n\n const handleOnClick: MouseEventHandler<HTMLDivElement> = (e) => {\n if (isEditing) {\n e.preventDefault();\n e.stopPropagation();\n }\n };\n\n const handleOnBlur = () => {\n // Stop editing when the element loses focus\n setIsEditing(false);\n };\n\n const onContentChange = (_e: React.FormEvent<HTMLDivElement>) => {\n // console.log(e.currentTarget.textContent);\n };\n\n return (\n <div\n role=\"textbox\"\n tabIndex={0}\n onKeyUp={() => null}\n contentEditable={isEditing}\n onInput={onContentChange}\n onClick={handleOnClick}\n onMouseDown={handleMouseDown}\n onMouseUp={handleMouseUp}\n onMouseLeave={handleMouseUp}\n onTouchStart={handleMouseDown}\n onTouchEnd={handleMouseUp}\n onTouchCancel={handleMouseUp}\n onBlur={handleOnBlur}\n suppressContentEditableWarning={true} // To suppress the warning for controlled components\n style={\n isEditing\n ? {\n backgroundColor: 'transparent',\n cursor: 'text',\n display: 'inline',\n }\n : { cursor: 'pointer', display: 'inline' }\n }\n ref={divRef}\n >\n {children}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAsFI;AApFJ,mBAOO;AAMP,MAAM,wBAAwB;AAEvB,MAAM,gBAAwC,CAAC,EAAE,SAAS,MAAM;AACrE,QAAM,aAAS,qBAAuB,IAAI;AAC1C,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,KAAK;AAChD,QAAM,oBAAgB,qBAA6C,IAAI;AAEvE,QAAM,oBAAoB,MAAM;AAC9B,iBAAa,IAAI;AAAA,EACnB;AAEA,QAAM,kBAAkB,MAAM;AAC5B,kBAAc,UAAU,WAAW,MAAM;AACvC,wBAAkB;AAAA,IACpB,GAAG,qBAAqB;AAAA,EAC1B;AAEA,QAAM,kBAAkB,MAAM;AAC5B,QAAI,cAAc,SAAS;AACzB,mBAAa,cAAc,OAAO;AAClC,oBAAc,UAAU;AAAA,IAC1B;AAAA,EACF;AAEA,QAAM,kBAAkB,MAAM;AAC5B,oBAAgB;AAChB,oBAAgB;AAAA,EAClB;AAEA,QAAM,gBAAgB,MAAM;AAC1B,oBAAgB;AAAA,EAClB;AAGA,QAAM,yBAAqB;AAAA,IACzB,CAAC,UAAsB;AACrB,UAAI,OAAO,WAAW,CAAC,OAAO,QAAQ,SAAS,MAAM,MAAc,GAAG;AACpE,qBAAa,KAAK;AAAA,MACpB;AAAA,IACF;AAAA,IACA,CAAC,MAAM;AAAA,EACT;AAEA,8BAAU,MAAM;AAEd,aAAS,iBAAiB,aAAa,kBAAkB;AAEzD,WAAO,MAAM;AAEX,eAAS,oBAAoB,aAAa,kBAAkB;AAC5D,sBAAgB;AAAA,IAClB;AAAA,EACF,GAAG,CAAC,kBAAkB,CAAC;AAEvB,QAAM,gBAAmD,CAAC,MAAM;AAC9D,QAAI,WAAW;AACb,QAAE,eAAe;AACjB,QAAE,gBAAgB;AAAA,IACpB;AAAA,EACF;AAEA,QAAM,eAAe,MAAM;AAEzB,iBAAa,KAAK;AAAA,EACpB;AAEA,QAAM,kBAAkB,CAAC,OAAwC;AAAA,EAEjE;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,MAAK;AAAA,MACL,UAAU;AAAA,MACV,SAAS,MAAM;AAAA,MACf,iBAAiB;AAAA,MACjB,SAAS;AAAA,MACT,SAAS;AAAA,MACT,aAAa;AAAA,MACb,WAAW;AAAA,MACX,cAAc;AAAA,MACd,cAAc;AAAA,MACd,YAAY;AAAA,MACZ,eAAe;AAAA,MACf,QAAQ;AAAA,MACR,gCAAgC;AAAA,MAChC,OACE,YACI;AAAA,QACE,iBAAiB;AAAA,QACjB,QAAQ;AAAA,QACR,SAAS;AAAA,MACX,IACA,EAAE,QAAQ,WAAW,SAAS,SAAS;AAAA,MAE7C,KAAK;AAAA,MAEJ;AAAA;AAAA,EACH;AAEJ;","names":[]}
@@ -1,8 +0,0 @@
1
- import { FC } from 'react';
2
-
3
- type ContentEditorProps = {
4
- children?: string;
5
- };
6
- declare const ContentEditor: FC<ContentEditorProps>;
7
-
8
- export { ContentEditor };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/ContentEditor/contentRender.tsx"],"sourcesContent":["import { ContentEditor } from './ContentEditor';\n\nexport const contentRender = (content: string) => {\n const isEditable = process.env.NODE_ENV === 'development';\n\n if (isEditable && ContentEditor) {\n return (<ContentEditor>{content}</ContentEditor>) as unknown as string;\n }\n\n return content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMY;AANZ,2BAA8B;AAEvB,MAAM,gBAAgB,CAAC,YAAoB;AAChD,QAAM,aAAa,QAAQ,IAAI,aAAa;AAE5C,MAAI,cAAc,oCAAe;AAC/B,WAAQ,4CAAC,sCAAe,mBAAQ;AAAA,EAClC;AAEA,SAAO;AACT;","names":[]}
@@ -1,3 +0,0 @@
1
- declare const contentRender: (content: string) => string;
2
-
3
- export { contentRender };
@@ -1,25 +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 __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
- var ContentEditor_exports = {};
17
- module.exports = __toCommonJS(ContentEditor_exports);
18
- __reExport(ContentEditor_exports, require('./ContentEditor.cjs'), module.exports);
19
- __reExport(ContentEditor_exports, require('./contentRender.cjs'), module.exports);
20
- // Annotate the CommonJS export names for ESM import in node:
21
- 0 && (module.exports = {
22
- ...require('./ContentEditor.cjs'),
23
- ...require('./contentRender.cjs')
24
- });
25
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/ContentEditor/index.tsx"],"sourcesContent":["export * from './ContentEditor';\nexport * from './contentRender';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,kCAAc,4BAAd;AACA,kCAAc,4BADd;","names":[]}
@@ -1,3 +0,0 @@
1
- export { ContentEditor } from './ContentEditor.js';
2
- export { contentRender } from './contentRender.js';
3
- import 'react';
@@ -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 { 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 {children}\n </IntlayerClientContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuEI;AArEJ,oBAA+C;AAC/C,mBAQO;AACP,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,OAC7B,UACH;AAEJ;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/processDictionary/contentDictionary.d.ts"],"sourcesContent":["import { type TranslationContent } from '@intlayer/core';\n\nexport type ContentValue =\n | string\n | {\n [key: string]: ContentValue;\n }\n | TranslationContent<unknown>;\n\nexport type Content = Record<string, ContentValue | undefined>;\n\nexport type TransformedContentValue =\n | string\n | {\n [key: string]: TransformedContentValue;\n }\n | undefined\n | ((quantity: number) => TransformedContentValue);\n\nexport type TransformedContent = Record<\n string,\n TransformedContentValue | undefined\n>;\n\nexport type ContentDictionary = Content & {\n id: string;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,29 +0,0 @@
1
- import { TranslationContent } from '@intlayer/core';
2
-
3
- type ContentValue =
4
- | string
5
- | {
6
- [key: string]: ContentValue;
7
- }
8
- | TranslationContent<unknown>;
9
-
10
- type Content = Record<string, ContentValue | undefined>;
11
-
12
- type TransformedContentValue =
13
- | string
14
- | {
15
- [key: string]: TransformedContentValue;
16
- }
17
- | undefined
18
- | ((quantity: number) => TransformedContentValue);
19
-
20
- type TransformedContent = Record<
21
- string,
22
- TransformedContentValue | undefined
23
- >;
24
-
25
- type ContentDictionary = Content & {
26
- id: string;
27
- };
28
-
29
- export type { Content, ContentDictionary, ContentValue, TransformedContent, TransformedContentValue };
@@ -1,8 +0,0 @@
1
- import { FC } from 'react';
2
-
3
- type ContentEditorProps = {
4
- children?: string;
5
- };
6
- declare const ContentEditor: FC<ContentEditorProps>;
7
-
8
- export { ContentEditor };
@@ -1,92 +0,0 @@
1
- "use client";
2
- import "../chunk-ZNCO4QRF.mjs";
3
- import { jsx } from "react/jsx-runtime";
4
- import {
5
- useEffect,
6
- useState,
7
- useRef,
8
- useCallback
9
- } from "react";
10
- const PRESS_DETECT_DURATION = 500;
11
- const ContentEditor = ({ children }) => {
12
- const divRef = useRef(null);
13
- const [isEditing, setIsEditing] = useState(false);
14
- const pressTimerRef = useRef(null);
15
- const handleOnLongPress = () => {
16
- setIsEditing(true);
17
- };
18
- const startPressTimer = () => {
19
- pressTimerRef.current = setTimeout(() => {
20
- handleOnLongPress();
21
- }, PRESS_DETECT_DURATION);
22
- };
23
- const clearPressTimer = () => {
24
- if (pressTimerRef.current) {
25
- clearTimeout(pressTimerRef.current);
26
- pressTimerRef.current = null;
27
- }
28
- };
29
- const handleMouseDown = () => {
30
- clearPressTimer();
31
- startPressTimer();
32
- };
33
- const handleMouseUp = () => {
34
- clearPressTimer();
35
- };
36
- const handleClickOutside = useCallback(
37
- (event) => {
38
- if (divRef.current && !divRef.current.contains(event.target)) {
39
- setIsEditing(false);
40
- }
41
- },
42
- [divRef]
43
- );
44
- useEffect(() => {
45
- document.addEventListener("mousedown", handleClickOutside);
46
- return () => {
47
- document.removeEventListener("mousedown", handleClickOutside);
48
- clearPressTimer();
49
- };
50
- }, [handleClickOutside]);
51
- const handleOnClick = (e) => {
52
- if (isEditing) {
53
- e.preventDefault();
54
- e.stopPropagation();
55
- }
56
- };
57
- const handleOnBlur = () => {
58
- setIsEditing(false);
59
- };
60
- const onContentChange = (_e) => {
61
- };
62
- return /* @__PURE__ */ jsx(
63
- "div",
64
- {
65
- role: "textbox",
66
- tabIndex: 0,
67
- onKeyUp: () => null,
68
- contentEditable: isEditing,
69
- onInput: onContentChange,
70
- onClick: handleOnClick,
71
- onMouseDown: handleMouseDown,
72
- onMouseUp: handleMouseUp,
73
- onMouseLeave: handleMouseUp,
74
- onTouchStart: handleMouseDown,
75
- onTouchEnd: handleMouseUp,
76
- onTouchCancel: handleMouseUp,
77
- onBlur: handleOnBlur,
78
- suppressContentEditableWarning: true,
79
- style: isEditing ? {
80
- backgroundColor: "transparent",
81
- cursor: "text",
82
- display: "inline"
83
- } : { cursor: "pointer", display: "inline" },
84
- ref: divRef,
85
- children
86
- }
87
- );
88
- };
89
- export {
90
- ContentEditor
91
- };
92
- //# sourceMappingURL=ContentEditor.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/ContentEditor/ContentEditor.tsx"],"sourcesContent":["'use client';\n\nimport {\n useEffect,\n useState,\n useRef,\n useCallback,\n type FC,\n type MouseEventHandler,\n} from 'react';\n\ntype ContentEditorProps = {\n children?: string;\n};\n\nconst PRESS_DETECT_DURATION = 500;\n\nexport const ContentEditor: FC<ContentEditorProps> = ({ children }) => {\n const divRef = useRef<HTMLDivElement>(null);\n const [isEditing, setIsEditing] = useState(false);\n const pressTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n const handleOnLongPress = () => {\n setIsEditing(true);\n };\n\n const startPressTimer = () => {\n pressTimerRef.current = setTimeout(() => {\n handleOnLongPress();\n }, PRESS_DETECT_DURATION);\n };\n\n const clearPressTimer = () => {\n if (pressTimerRef.current) {\n clearTimeout(pressTimerRef.current);\n pressTimerRef.current = null;\n }\n };\n\n const handleMouseDown = () => {\n clearPressTimer(); // Ensure any previous timer is cleared\n startPressTimer();\n };\n\n const handleMouseUp = () => {\n clearPressTimer();\n };\n\n // Use useCallback to ensure the function identity remains stable\n const handleClickOutside = useCallback(\n (event: MouseEvent) => {\n if (divRef.current && !divRef.current.contains(event.target as Node)) {\n setIsEditing(false);\n }\n },\n [divRef]\n );\n\n useEffect(() => {\n // Attach click outside listener\n document.addEventListener('mousedown', handleClickOutside);\n\n return () => {\n // Cleanup\n document.removeEventListener('mousedown', handleClickOutside);\n clearPressTimer(); // Ensure to clear the timer when component unmounts\n };\n }, [handleClickOutside]);\n\n const handleOnClick: MouseEventHandler<HTMLDivElement> = (e) => {\n if (isEditing) {\n e.preventDefault();\n e.stopPropagation();\n }\n };\n\n const handleOnBlur = () => {\n // Stop editing when the element loses focus\n setIsEditing(false);\n };\n\n const onContentChange = (_e: React.FormEvent<HTMLDivElement>) => {\n // console.log(e.currentTarget.textContent);\n };\n\n return (\n <div\n role=\"textbox\"\n tabIndex={0}\n onKeyUp={() => null}\n contentEditable={isEditing}\n onInput={onContentChange}\n onClick={handleOnClick}\n onMouseDown={handleMouseDown}\n onMouseUp={handleMouseUp}\n onMouseLeave={handleMouseUp}\n onTouchStart={handleMouseDown}\n onTouchEnd={handleMouseUp}\n onTouchCancel={handleMouseUp}\n onBlur={handleOnBlur}\n suppressContentEditableWarning={true} // To suppress the warning for controlled components\n style={\n isEditing\n ? {\n backgroundColor: 'transparent',\n cursor: 'text',\n display: 'inline',\n }\n : { cursor: 'pointer', display: 'inline' }\n }\n ref={divRef}\n >\n {children}\n </div>\n );\n};\n"],"mappings":";;AAsFI;AApFJ;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAMP,MAAM,wBAAwB;AAEvB,MAAM,gBAAwC,CAAC,EAAE,SAAS,MAAM;AACrE,QAAM,SAAS,OAAuB,IAAI;AAC1C,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAChD,QAAM,gBAAgB,OAA6C,IAAI;AAEvE,QAAM,oBAAoB,MAAM;AAC9B,iBAAa,IAAI;AAAA,EACnB;AAEA,QAAM,kBAAkB,MAAM;AAC5B,kBAAc,UAAU,WAAW,MAAM;AACvC,wBAAkB;AAAA,IACpB,GAAG,qBAAqB;AAAA,EAC1B;AAEA,QAAM,kBAAkB,MAAM;AAC5B,QAAI,cAAc,SAAS;AACzB,mBAAa,cAAc,OAAO;AAClC,oBAAc,UAAU;AAAA,IAC1B;AAAA,EACF;AAEA,QAAM,kBAAkB,MAAM;AAC5B,oBAAgB;AAChB,oBAAgB;AAAA,EAClB;AAEA,QAAM,gBAAgB,MAAM;AAC1B,oBAAgB;AAAA,EAClB;AAGA,QAAM,qBAAqB;AAAA,IACzB,CAAC,UAAsB;AACrB,UAAI,OAAO,WAAW,CAAC,OAAO,QAAQ,SAAS,MAAM,MAAc,GAAG;AACpE,qBAAa,KAAK;AAAA,MACpB;AAAA,IACF;AAAA,IACA,CAAC,MAAM;AAAA,EACT;AAEA,YAAU,MAAM;AAEd,aAAS,iBAAiB,aAAa,kBAAkB;AAEzD,WAAO,MAAM;AAEX,eAAS,oBAAoB,aAAa,kBAAkB;AAC5D,sBAAgB;AAAA,IAClB;AAAA,EACF,GAAG,CAAC,kBAAkB,CAAC;AAEvB,QAAM,gBAAmD,CAAC,MAAM;AAC9D,QAAI,WAAW;AACb,QAAE,eAAe;AACjB,QAAE,gBAAgB;AAAA,IACpB;AAAA,EACF;AAEA,QAAM,eAAe,MAAM;AAEzB,iBAAa,KAAK;AAAA,EACpB;AAEA,QAAM,kBAAkB,CAAC,OAAwC;AAAA,EAEjE;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,MAAK;AAAA,MACL,UAAU;AAAA,MACV,SAAS,MAAM;AAAA,MACf,iBAAiB;AAAA,MACjB,SAAS;AAAA,MACT,SAAS;AAAA,MACT,aAAa;AAAA,MACb,WAAW;AAAA,MACX,cAAc;AAAA,MACd,cAAc;AAAA,MACd,YAAY;AAAA,MACZ,eAAe;AAAA,MACf,QAAQ;AAAA,MACR,gCAAgC;AAAA,MAChC,OACE,YACI;AAAA,QACE,iBAAiB;AAAA,QACjB,QAAQ;AAAA,QACR,SAAS;AAAA,MACX,IACA,EAAE,QAAQ,WAAW,SAAS,SAAS;AAAA,MAE7C,KAAK;AAAA,MAEJ;AAAA;AAAA,EACH;AAEJ;","names":[]}
@@ -1,3 +0,0 @@
1
- declare const contentRender: (content: string) => string;
2
-
3
- export { contentRender };
@@ -1,14 +0,0 @@
1
- import "../chunk-ZNCO4QRF.mjs";
2
- import { jsx } from "react/jsx-runtime";
3
- import { ContentEditor } from './ContentEditor.mjs';
4
- const contentRender = (content) => {
5
- const isEditable = process.env.NODE_ENV === "development";
6
- if (isEditable && ContentEditor) {
7
- return /* @__PURE__ */ jsx(ContentEditor, { children: content });
8
- }
9
- return content;
10
- };
11
- export {
12
- contentRender
13
- };
14
- //# sourceMappingURL=contentRender.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/ContentEditor/contentRender.tsx"],"sourcesContent":["import { ContentEditor } from './ContentEditor';\n\nexport const contentRender = (content: string) => {\n const isEditable = process.env.NODE_ENV === 'development';\n\n if (isEditable && ContentEditor) {\n return (<ContentEditor>{content}</ContentEditor>) as unknown as string;\n }\n\n return content;\n};\n"],"mappings":";AAMY;AANZ,SAAS,qBAAqB;AAEvB,MAAM,gBAAgB,CAAC,YAAoB;AAChD,QAAM,aAAa,QAAQ,IAAI,aAAa;AAE5C,MAAI,cAAc,eAAe;AAC/B,WAAQ,oBAAC,iBAAe,mBAAQ;AAAA,EAClC;AAEA,SAAO;AACT;","names":[]}
@@ -1,3 +0,0 @@
1
- export { ContentEditor } from './ContentEditor.mjs';
2
- export { contentRender } from './contentRender.mjs';
3
- import 'react';
@@ -1,3 +0,0 @@
1
- export * from './ContentEditor.mjs';
2
- export * from './contentRender.mjs';
3
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/ContentEditor/index.tsx"],"sourcesContent":["export * from './ContentEditor';\nexport * from './contentRender';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","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":[]}