react-intlayer 3.5.3 → 3.5.5

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 (109) hide show
  1. package/README.md +5 -5
  2. package/dist/cjs/cli/react-intlayer.cjs +4 -4
  3. package/dist/cjs/cli/react-intlayer.cjs.map +1 -1
  4. package/dist/cjs/client/index.cjs +3 -0
  5. package/dist/cjs/client/index.cjs.map +1 -1
  6. package/dist/cjs/client/useDictionary.cjs +3 -3
  7. package/dist/cjs/client/useDictionary.cjs.map +1 -1
  8. package/dist/cjs/client/useIntlayer.cjs +3 -3
  9. package/dist/cjs/client/useIntlayer.cjs.map +1 -1
  10. package/dist/cjs/client/useIntlayerAsync.cjs +55 -0
  11. package/dist/cjs/client/useIntlayerAsync.cjs.map +1 -0
  12. package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs +59 -0
  13. package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs.map +1 -0
  14. package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
  15. package/dist/cjs/editor/IntlayerEditorProvider.cjs +5 -1
  16. package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -1
  17. package/dist/cjs/editor/renderContentEditor.cjs +1 -1
  18. package/dist/cjs/editor/renderContentEditor.cjs.map +1 -1
  19. package/dist/cjs/{useDictionaryBase.cjs → getDictionary.cjs} +20 -19
  20. package/dist/cjs/getDictionary.cjs.map +1 -0
  21. package/dist/cjs/{useIntlayerBase.cjs → getIntlayer.cjs} +13 -11
  22. package/dist/cjs/getIntlayer.cjs.map +1 -0
  23. package/dist/cjs/getIntlayerAsync.cjs +42 -0
  24. package/dist/cjs/getIntlayerAsync.cjs.map +1 -0
  25. package/dist/cjs/index.cjs +8 -0
  26. package/dist/cjs/index.cjs.map +1 -1
  27. package/dist/cjs/processDictionary/contentDictionary.cjs.map +1 -1
  28. package/dist/cjs/processDictionary/index.cjs +13 -13
  29. package/dist/cjs/processDictionary/index.cjs.map +1 -1
  30. package/dist/cjs/server/useDictionary.cjs +3 -3
  31. package/dist/cjs/server/useDictionary.cjs.map +1 -1
  32. package/dist/cjs/server/useIntlayer.cjs +3 -3
  33. package/dist/cjs/server/useIntlayer.cjs.map +1 -1
  34. package/dist/cjs/utils/PoweredByMeta/index.cjs +40 -0
  35. package/dist/cjs/utils/PoweredByMeta/index.cjs.map +1 -0
  36. package/dist/esm/cli/react-intlayer.mjs +5 -5
  37. package/dist/esm/cli/react-intlayer.mjs.map +1 -1
  38. package/dist/esm/client/index.mjs +2 -0
  39. package/dist/esm/client/index.mjs.map +1 -1
  40. package/dist/esm/client/useDictionary.mjs +3 -3
  41. package/dist/esm/client/useDictionary.mjs.map +1 -1
  42. package/dist/esm/client/useIntlayer.mjs +4 -4
  43. package/dist/esm/client/useIntlayer.mjs.map +1 -1
  44. package/dist/esm/client/useIntlayerAsync.mjs +34 -0
  45. package/dist/esm/client/useIntlayerAsync.mjs.map +1 -0
  46. package/dist/esm/distantDictionary/fetchDistantDictionary.mjs +36 -0
  47. package/dist/esm/distantDictionary/fetchDistantDictionary.mjs.map +1 -0
  48. package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
  49. package/dist/esm/editor/IntlayerEditorProvider.mjs +6 -2
  50. package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
  51. package/dist/esm/editor/renderContentEditor.mjs +1 -1
  52. package/dist/esm/editor/renderContentEditor.mjs.map +1 -1
  53. package/dist/esm/{useDictionaryBase.mjs → getDictionary.mjs} +17 -14
  54. package/dist/esm/getDictionary.mjs.map +1 -0
  55. package/dist/esm/{useIntlayerBase.mjs → getIntlayer.mjs} +9 -7
  56. package/dist/esm/getIntlayer.mjs.map +1 -0
  57. package/dist/esm/getIntlayerAsync.mjs +19 -0
  58. package/dist/esm/getIntlayerAsync.mjs.map +1 -0
  59. package/dist/esm/index.mjs +6 -0
  60. package/dist/esm/index.mjs.map +1 -1
  61. package/dist/esm/processDictionary/index.mjs +13 -13
  62. package/dist/esm/processDictionary/index.mjs.map +1 -1
  63. package/dist/esm/server/useDictionary.mjs +3 -3
  64. package/dist/esm/server/useDictionary.mjs.map +1 -1
  65. package/dist/esm/server/useIntlayer.mjs +4 -4
  66. package/dist/esm/server/useIntlayer.mjs.map +1 -1
  67. package/dist/esm/utils/PoweredByMeta/index.mjs +17 -0
  68. package/dist/esm/utils/PoweredByMeta/index.mjs.map +1 -0
  69. package/dist/types/client/index.d.ts +1 -0
  70. package/dist/types/client/index.d.ts.map +1 -1
  71. package/dist/types/client/useDictionary.d.ts +1 -1
  72. package/dist/types/client/useDictionary.d.ts.map +1 -1
  73. package/dist/types/client/useIntlayer.d.ts +2 -2
  74. package/dist/types/client/useIntlayer.d.ts.map +1 -1
  75. package/dist/types/client/useIntlayerAsync.d.ts +15 -0
  76. package/dist/types/client/useIntlayerAsync.d.ts.map +1 -0
  77. package/dist/types/distantDictionary/fetchDistantDictionary.d.ts +6 -0
  78. package/dist/types/distantDictionary/fetchDistantDictionary.d.ts.map +1 -0
  79. package/dist/types/editor/ContentSelectorWrapper.d.ts +1 -1
  80. package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -1
  81. package/dist/types/editor/IntlayerEditorProvider.d.ts.map +1 -1
  82. package/dist/types/editor/renderContentEditor.d.ts +4 -4
  83. package/dist/types/editor/renderContentEditor.d.ts.map +1 -1
  84. package/dist/types/getDictionary.d.ts +35 -0
  85. package/dist/types/getDictionary.d.ts.map +1 -0
  86. package/dist/types/{useIntlayerBase.d.ts → getIntlayer.d.ts} +6 -10
  87. package/dist/types/getIntlayer.d.ts.map +1 -0
  88. package/dist/types/getIntlayerAsync.d.ts +13 -0
  89. package/dist/types/getIntlayerAsync.d.ts.map +1 -0
  90. package/dist/types/index.d.ts +4 -2
  91. package/dist/types/index.d.ts.map +1 -1
  92. package/dist/types/processDictionary/contentDictionary.d.ts +1 -1
  93. package/dist/types/processDictionary/contentDictionary.d.ts.map +1 -1
  94. package/dist/types/processDictionary/index.d.ts +2 -2
  95. package/dist/types/processDictionary/index.d.ts.map +1 -1
  96. package/dist/types/server/useDictionary.d.ts +1 -1
  97. package/dist/types/server/useDictionary.d.ts.map +1 -1
  98. package/dist/types/server/useIntlayer.d.ts +2 -2
  99. package/dist/types/server/useIntlayer.d.ts.map +1 -1
  100. package/dist/types/utils/PoweredByMeta/index.d.ts +3 -0
  101. package/dist/types/utils/PoweredByMeta/index.d.ts.map +1 -0
  102. package/package.json +15 -14
  103. package/dist/cjs/useDictionaryBase.cjs.map +0 -1
  104. package/dist/cjs/useIntlayerBase.cjs.map +0 -1
  105. package/dist/esm/useDictionaryBase.mjs.map +0 -1
  106. package/dist/esm/useIntlayerBase.mjs.map +0 -1
  107. package/dist/types/useDictionaryBase.d.ts +0 -37
  108. package/dist/types/useDictionaryBase.d.ts.map +0 -1
  109. package/dist/types/useIntlayerBase.d.ts.map +0 -1
@@ -30,7 +30,7 @@ var import_getTranslation = require('../getTranslation.cjs');
30
30
  const {
31
31
  internationalization: { defaultLocale }
32
32
  } = (0, import_client.getConfiguration)();
33
- const processTranslation = (languageContent, locale, dictionaryId, dictionaryPath, keyPath = []) => {
33
+ const processTranslation = (languageContent, locale, dictionaryKey, dictionaryPath, keyPath = []) => {
34
34
  const translationResult = (0, import_getTranslation.getTranslation)(
35
35
  languageContent,
36
36
  locale
@@ -41,13 +41,13 @@ const processTranslation = (languageContent, locale, dictionaryId, dictionaryPat
41
41
  ];
42
42
  return processDictionary(
43
43
  translationResult,
44
- dictionaryId,
44
+ dictionaryKey,
45
45
  dictionaryPath,
46
46
  resultKeyPath,
47
47
  locale
48
48
  );
49
49
  };
50
- const processEnumeration = (enumerationContent, locale, dictionaryId, dictionaryPath, keyPath = []) => (quantity) => {
50
+ const processEnumeration = (enumerationContent, locale, dictionaryKey, dictionaryPath, keyPath = []) => (quantity) => {
51
51
  const enumerationResult = (0, import_getEnumeration.getEnumeration)(
52
52
  enumerationContent,
53
53
  quantity
@@ -62,20 +62,20 @@ const processEnumeration = (enumerationContent, locale, dictionaryId, dictionary
62
62
  ];
63
63
  return processDictionary(
64
64
  enumerationResult,
65
- dictionaryId,
65
+ dictionaryKey,
66
66
  dictionaryPath,
67
67
  resultKeyPath,
68
68
  locale
69
69
  );
70
70
  };
71
71
  const isReactNode = (node) => typeof node?.key !== "undefined" && typeof node?.props !== "undefined";
72
- const processNode = (field, locale, dictionaryId, dictionaryPath, keyPath = []) => {
72
+ const processNode = (field, locale, dictionaryKey, dictionaryPath, keyPath = []) => {
73
73
  if (typeof field === "object") {
74
74
  if (field.nodeType === import_core.NodeType.Translation) {
75
75
  return processTranslation(
76
76
  field[import_core.NodeType.Translation],
77
77
  locale,
78
- dictionaryId,
78
+ dictionaryKey,
79
79
  dictionaryPath,
80
80
  keyPath
81
81
  );
@@ -84,7 +84,7 @@ const processNode = (field, locale, dictionaryId, dictionaryPath, keyPath = [])
84
84
  return processEnumeration(
85
85
  field[import_core.NodeType.Enumeration],
86
86
  locale,
87
- dictionaryId,
87
+ dictionaryKey,
88
88
  dictionaryPath,
89
89
  keyPath
90
90
  );
@@ -93,7 +93,7 @@ const processNode = (field, locale, dictionaryId, dictionaryPath, keyPath = [])
93
93
  return processDictionary(
94
94
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
95
95
  field,
96
- dictionaryId,
96
+ dictionaryKey,
97
97
  dictionaryPath,
98
98
  keyPath,
99
99
  locale
@@ -125,7 +125,7 @@ const createReactElement = (element) => {
125
125
  return (0, import_react.createElement)(type ?? "div", props, ...props.children);
126
126
  };
127
127
  const traceKeys = ["filePath", "nodeType"];
128
- const processDictionary = (content, dictionaryId, dictionaryPath, keyPath = [], locale = defaultLocale) => {
128
+ const processDictionary = (content, dictionaryKey, dictionaryPath, keyPath = [], locale = defaultLocale) => {
129
129
  if (isReactNode(content)) {
130
130
  return createReactElement(
131
131
  content
@@ -138,7 +138,7 @@ const processDictionary = (content, dictionaryId, dictionaryPath, keyPath = [],
138
138
  return processNode(
139
139
  content,
140
140
  locale,
141
- dictionaryId,
141
+ dictionaryKey,
142
142
  dictionaryPath,
143
143
  keyPath
144
144
  );
@@ -151,7 +151,7 @@ const processDictionary = (content, dictionaryId, dictionaryPath, keyPath = [],
151
151
  return processNode(
152
152
  field,
153
153
  locale,
154
- dictionaryId,
154
+ dictionaryKey,
155
155
  dictionaryPath,
156
156
  resultKeyPath
157
157
  );
@@ -170,7 +170,7 @@ const processDictionary = (content, dictionaryId, dictionaryPath, keyPath = [],
170
170
  const nodeResult = processNode(
171
171
  field,
172
172
  locale,
173
- dictionaryId,
173
+ dictionaryKey,
174
174
  dictionaryPath,
175
175
  resultKeyPath
176
176
  );
@@ -182,7 +182,7 @@ const processDictionary = (content, dictionaryId, dictionaryPath, keyPath = [],
182
182
  return {
183
183
  content,
184
184
  keyPath,
185
- dictionaryId,
185
+ dictionaryKey,
186
186
  dictionaryPath
187
187
  };
188
188
  };
@@ -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 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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\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: 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: NodeType.Array, 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: NodeType.Object, 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: content as TransformedContentValue,\n keyPath,\n dictionaryId,\n dictionaryPath,\n };\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 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 dictionaryKey: 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 dictionaryKey,\n dictionaryPath,\n resultKeyPath,\n locale\n );\n};\n\nconst processEnumeration =\n (\n enumerationContent: QuantityContent<DictionaryValue>,\n locale: Locales,\n dictionaryKey: 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 dictionaryKey,\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 dictionaryKey: 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 dictionaryKey,\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 dictionaryKey,\n dictionaryPath,\n keyPath\n );\n }\n }\n\n return processDictionary(\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n field!,\n dictionaryKey,\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: DictionaryValue,\n dictionaryKey: 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 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 dictionaryKey,\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: NodeType.Array, key },\n ];\n\n return processNode(\n field,\n locale,\n dictionaryKey,\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: NodeType.Object, key },\n ];\n\n const nodeResult = processNode(\n field,\n locale,\n dictionaryKey,\n dictionaryPath,\n resultKeyPath\n );\n\n result[key] = nodeResult;\n }\n }\n\n return result;\n }\n\n return {\n content: content as TransformedContentValue,\n keyPath,\n dictionaryKey,\n dictionaryPath,\n };\n};\n"],"mappings":"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","names":["element"]}
@@ -21,12 +21,12 @@ __export(useDictionary_exports, {
21
21
  useDictionary: () => useDictionary
22
22
  });
23
23
  module.exports = __toCommonJS(useDictionary_exports);
24
- var import_useDictionaryBase = require('../useDictionaryBase.cjs');
24
+ var import_getDictionary = require('../getDictionary.cjs');
25
25
  var import_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
26
26
  var import_serverContext = require('./serverContext.cjs');
27
- const useDictionary = (dictionary, locale) => {
27
+ const useDictionary = (dictionary, locale, isRenderEditor = false) => {
28
28
  const localeTarget = locale ?? (0, import_serverContext.getServerContext)(import_IntlayerServerProvider.IntlayerServerContext);
29
- return (0, import_useDictionaryBase.useDictionaryBase)(dictionary, localeTarget);
29
+ return (0, import_getDictionary.getDictionary)(dictionary, localeTarget, isRenderEditor);
30
30
  };
31
31
  // Annotate the CommonJS export names for ESM import in node:
32
32
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport type { DeclarationContent } from '@intlayer/core';\nimport { useDictionaryBase, type UseDictionary } from '../useDictionaryBase';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionary: UseDictionary = <T extends DeclarationContent>(\n dictionary: T,\n locale?: Locales\n) => {\n const localeTarget =\n locale ?? getServerContext<Locales>(IntlayerServerContext);\n\n return useDictionaryBase(dictionary, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,+BAAsD;AACtD,oCAAsC;AACtC,2BAAiC;AAO1B,MAAM,gBAA+B,CAC1C,YACA,WACG;AACH,QAAM,eACJ,cAAU,uCAA0B,mDAAqB;AAE3D,aAAO,4CAAkB,YAAY,YAAY;AACnD;","names":[]}
1
+ {"version":3,"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport type { DeclarationContent } from '@intlayer/core';\nimport { getDictionary, type UseDictionary } from '../getDictionary';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionary: UseDictionary = <T extends DeclarationContent>(\n dictionary: T,\n locale?: Locales,\n isRenderEditor = false\n) => {\n const localeTarget =\n locale ?? getServerContext<Locales>(IntlayerServerContext);\n\n return getDictionary(dictionary, localeTarget, isRenderEditor);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,2BAAkD;AAClD,oCAAsC;AACtC,2BAAiC;AAO1B,MAAM,gBAA+B,CAC1C,YACA,QACA,iBAAiB,UACd;AACH,QAAM,eACJ,cAAU,uCAA0B,mDAAqB;AAE3D,aAAO,oCAAc,YAAY,cAAc,cAAc;AAC/D;","names":[]}
@@ -21,12 +21,12 @@ __export(useIntlayer_exports, {
21
21
  useIntlayer: () => useIntlayer
22
22
  });
23
23
  module.exports = __toCommonJS(useIntlayer_exports);
24
- var import_useIntlayerBase = require('../useIntlayerBase.cjs');
24
+ var import_getIntlayer = require('../getIntlayer.cjs');
25
25
  var import_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
26
26
  var import_serverContext = require('./serverContext.cjs');
27
- const useIntlayer = (key, locale) => {
27
+ const useIntlayer = (key, locale, isRenderEditor = true) => {
28
28
  const localeTarget = locale ?? (0, import_serverContext.getServerContext)(import_IntlayerServerProvider.IntlayerServerContext);
29
- return (0, import_useIntlayerBase.useIntlayerBase)(key, localeTarget);
29
+ return (0, import_getIntlayer.getIntlayer)(key, localeTarget, isRenderEditor);
30
30
  };
31
31
  // Annotate the CommonJS export names for ESM import in node:
32
32
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport {\n type DictionaryKeys,\n useIntlayerBase,\n type UseIntlayer,\n} from '../useIntlayerBase';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useIntlayer: UseIntlayer = <T extends DictionaryKeys>(\n key: T,\n locale?: Locales\n) => {\n const localeTarget =\n locale ?? getServerContext<Locales>(IntlayerServerContext);\n\n return useIntlayerBase(key, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,6BAIO;AACP,oCAAsC;AACtC,2BAAiC;AAO1B,MAAM,cAA2B,CACtC,KACA,WACG;AACH,QAAM,eACJ,cAAU,uCAA0B,mDAAqB;AAE3D,aAAO,wCAAgB,KAAK,YAAY;AAC1C;","names":[]}
1
+ {"version":3,"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport {\n type DictionaryKeys,\n getIntlayer,\n type UseIntlayerEditable,\n} from '../getIntlayer';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useIntlayer: UseIntlayerEditable = <T extends DictionaryKeys>(\n key: T,\n locale?: Locales,\n isRenderEditor = true\n) => {\n const localeTarget =\n locale ?? getServerContext<Locales>(IntlayerServerContext);\n\n return getIntlayer(key, localeTarget, isRenderEditor);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,yBAIO;AACP,oCAAsC;AACtC,2BAAiC;AAO1B,MAAM,cAAmC,CAC9C,KACA,QACA,iBAAiB,SACd;AACH,QAAM,eACJ,cAAU,uCAA0B,mDAAqB;AAE3D,aAAO,gCAAY,KAAK,cAAc,cAAc;AACtD;","names":[]}
@@ -0,0 +1,40 @@
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 PoweredByMeta_exports = {};
21
+ __export(PoweredByMeta_exports, {
22
+ PoweredByMeta: () => PoweredByMeta
23
+ });
24
+ module.exports = __toCommonJS(PoweredByMeta_exports);
25
+ var import_react = require("react");
26
+ const PoweredByMeta = () => {
27
+ if (process.env.NODE_ENV !== "production") return null;
28
+ (0, import_react.useEffect)(() => {
29
+ const metaTag = document.createElement("meta");
30
+ metaTag.name = "content-powered-by";
31
+ metaTag.content = "Intlayer - https://intlayer.org";
32
+ document.head.appendChild(metaTag);
33
+ }, []);
34
+ return null;
35
+ };
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ PoweredByMeta
39
+ });
40
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/utils/PoweredByMeta/index.ts"],"sourcesContent":["'use client';\n\nimport { type FC, useEffect } from 'react';\n\nexport const PoweredByMeta: FC = () => {\n if (process.env.NODE_ENV !== 'production') return null;\n\n useEffect(() => {\n const metaTag = document.createElement('meta');\n metaTag.name = 'content-powered-by';\n metaTag.content = 'Intlayer - https://intlayer.org';\n document.head.appendChild(metaTag);\n }, []);\n\n return null; // This component does not render anything visible\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAmC;AAE5B,MAAM,gBAAoB,MAAM;AACrC,MAAI,QAAQ,IAAI,aAAa,aAAc,QAAO;AAElD,8BAAU,MAAM;AACd,UAAM,UAAU,SAAS,cAAc,MAAM;AAC7C,YAAQ,OAAO;AACf,YAAQ,UAAU;AAClB,aAAS,KAAK,YAAY,OAAO;AAAA,EACnC,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;","names":[]}
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { ESMxCJSRequire } from "@intlayer/config";
2
+ import { ESMxCJSRequire, appLogger } from "@intlayer/config";
3
3
  import spawn from "cross-spawn";
4
4
  const args = process.argv.slice(2);
5
5
  const scriptIndex = args.findIndex(
@@ -25,13 +25,13 @@ switch (script) {
25
25
  });
26
26
  if (child.signal) {
27
27
  if (child.signal === "SIGKILL") {
28
- console.info(`
28
+ appLogger(`
29
29
  The build failed because the process exited too early.
30
30
  This probably means the system ran out of memory or someone called
31
31
  \`kill -9\` on the process.
32
32
  `);
33
33
  } else if (child.signal === "SIGTERM") {
34
- console.info(`
34
+ appLogger(`
35
35
  The build failed because the process exited too early.
36
36
  Someone might have called \`kill\` or \`killall\`, or the system could
37
37
  be shutting down.
@@ -43,8 +43,8 @@ switch (script) {
43
43
  break;
44
44
  }
45
45
  default:
46
- console.info(`Unknown script "${script}".`);
47
- console.info("Perhaps you need to update craco?");
46
+ appLogger(`Unknown script "${script}".`);
47
+ appLogger("Perhaps you need to update craco?");
48
48
  break;
49
49
  }
50
50
  //# sourceMappingURL=react-intlayer.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/cli/react-intlayer.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * To make the setup easier, we are using craco to override the webpack configuration.\n * This script is used to run the craco scripts with the custom configuration.\n *\n * The script is based on the original craco script from create-react-app.\n */\n\nimport { ESMxCJSRequire } from '@intlayer/config';\nimport spawn from 'cross-spawn';\n\nconst args = process.argv.slice(2);\nconst scriptIndex = args.findIndex(\n (x) => x === 'build' || x === 'start' || x === 'test'\n);\nconst script = scriptIndex === -1 ? args[0] : args[scriptIndex];\n\nswitch (script) {\n case 'build':\n case 'start':\n case 'test': {\n const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];\n const scriptPath = ESMxCJSRequire.resolve(\n `@craco/craco/dist/scripts/${script}`\n );\n\n const scriptArgs = args.slice(scriptIndex + 1);\n const processArgs = nodeArgs\n .concat(scriptPath)\n .concat([\n ...scriptArgs,\n '--config',\n './node_modules/react-intlayer/dist/cjs/craco/craco.config.cjs',\n ]);\n\n const child = spawn.sync('node', processArgs, {\n stdio: 'inherit',\n });\n\n if (child.signal) {\n if (child.signal === 'SIGKILL') {\n console.info(`\n The build failed because the process exited too early.\n This probably means the system ran out of memory or someone called\n \\`kill -9\\` on the process.\n `);\n } else if (child.signal === 'SIGTERM') {\n console.info(`\n The build failed because the process exited too early.\n Someone might have called \\`kill\\` or \\`killall\\`, or the system could\n be shutting down.\n `);\n }\n\n process.exit(1);\n }\n\n process.exit(child.status ?? undefined);\n break;\n }\n default:\n console.info(`Unknown script \"${script}\".`);\n console.info('Perhaps you need to update craco?');\n break;\n}\n"],"mappings":";AASA,SAAS,sBAAsB;AAC/B,OAAO,WAAW;AAElB,MAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AACjC,MAAM,cAAc,KAAK;AAAA,EACvB,CAAC,MAAM,MAAM,WAAW,MAAM,WAAW,MAAM;AACjD;AACA,MAAM,SAAS,gBAAgB,KAAK,KAAK,CAAC,IAAI,KAAK,WAAW;AAE9D,QAAQ,QAAQ;AAAA,EACd,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK,QAAQ;AACX,UAAM,WAAW,cAAc,IAAI,KAAK,MAAM,GAAG,WAAW,IAAI,CAAC;AACjE,UAAM,aAAa,eAAe;AAAA,MAChC,6BAA6B,MAAM;AAAA,IACrC;AAEA,UAAM,aAAa,KAAK,MAAM,cAAc,CAAC;AAC7C,UAAM,cAAc,SACjB,OAAO,UAAU,EACjB,OAAO;AAAA,MACN,GAAG;AAAA,MACH;AAAA,MACA;AAAA,IACF,CAAC;AAEH,UAAM,QAAQ,MAAM,KAAK,QAAQ,aAAa;AAAA,MAC5C,OAAO;AAAA,IACT,CAAC;AAED,QAAI,MAAM,QAAQ;AAChB,UAAI,MAAM,WAAW,WAAW;AAC9B,gBAAQ,KAAK;AAAA;AAAA;AAAA;AAAA,aAIR;AAAA,MACP,WAAW,MAAM,WAAW,WAAW;AACrC,gBAAQ,KAAK;AAAA;AAAA;AAAA;AAAA,aAIR;AAAA,MACP;AAEA,cAAQ,KAAK,CAAC;AAAA,IAChB;AAEA,YAAQ,KAAK,MAAM,UAAU,MAAS;AACtC;AAAA,EACF;AAAA,EACA;AACE,YAAQ,KAAK,mBAAmB,MAAM,IAAI;AAC1C,YAAQ,KAAK,mCAAmC;AAChD;AACJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/cli/react-intlayer.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * To make the setup easier, we are using craco to override the webpack configuration.\n * This script is used to run the craco scripts with the custom configuration.\n *\n * The script is based on the original craco script from create-react-app.\n */\n\nimport { ESMxCJSRequire, appLogger } from '@intlayer/config';\nimport spawn from 'cross-spawn';\n\nconst args = process.argv.slice(2);\nconst scriptIndex = args.findIndex(\n (x) => x === 'build' || x === 'start' || x === 'test'\n);\nconst script = scriptIndex === -1 ? args[0] : args[scriptIndex];\n\nswitch (script) {\n case 'build':\n case 'start':\n case 'test': {\n const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];\n const scriptPath = ESMxCJSRequire.resolve(\n `@craco/craco/dist/scripts/${script}`\n );\n\n const scriptArgs = args.slice(scriptIndex + 1);\n const processArgs = nodeArgs\n .concat(scriptPath)\n .concat([\n ...scriptArgs,\n '--config',\n './node_modules/react-intlayer/dist/cjs/craco/craco.config.cjs',\n ]);\n\n const child = spawn.sync('node', processArgs, {\n stdio: 'inherit',\n });\n\n if (child.signal) {\n if (child.signal === 'SIGKILL') {\n appLogger(`\n The build failed because the process exited too early.\n This probably means the system ran out of memory or someone called\n \\`kill -9\\` on the process.\n `);\n } else if (child.signal === 'SIGTERM') {\n appLogger(`\n The build failed because the process exited too early.\n Someone might have called \\`kill\\` or \\`killall\\`, or the system could\n be shutting down.\n `);\n }\n\n process.exit(1);\n }\n\n process.exit(child.status ?? undefined);\n break;\n }\n default:\n appLogger(`Unknown script \"${script}\".`);\n appLogger('Perhaps you need to update craco?');\n break;\n}\n"],"mappings":";AASA,SAAS,gBAAgB,iBAAiB;AAC1C,OAAO,WAAW;AAElB,MAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AACjC,MAAM,cAAc,KAAK;AAAA,EACvB,CAAC,MAAM,MAAM,WAAW,MAAM,WAAW,MAAM;AACjD;AACA,MAAM,SAAS,gBAAgB,KAAK,KAAK,CAAC,IAAI,KAAK,WAAW;AAE9D,QAAQ,QAAQ;AAAA,EACd,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK,QAAQ;AACX,UAAM,WAAW,cAAc,IAAI,KAAK,MAAM,GAAG,WAAW,IAAI,CAAC;AACjE,UAAM,aAAa,eAAe;AAAA,MAChC,6BAA6B,MAAM;AAAA,IACrC;AAEA,UAAM,aAAa,KAAK,MAAM,cAAc,CAAC;AAC7C,UAAM,cAAc,SACjB,OAAO,UAAU,EACjB,OAAO;AAAA,MACN,GAAG;AAAA,MACH;AAAA,MACA;AAAA,IACF,CAAC;AAEH,UAAM,QAAQ,MAAM,KAAK,QAAQ,aAAa;AAAA,MAC5C,OAAO;AAAA,IACT,CAAC;AAED,QAAI,MAAM,QAAQ;AAChB,UAAI,MAAM,WAAW,WAAW;AAC9B,kBAAU;AAAA;AAAA;AAAA;AAAA,aAIL;AAAA,MACP,WAAW,MAAM,WAAW,WAAW;AACrC,kBAAU;AAAA;AAAA;AAAA;AAAA,aAIL;AAAA,MACP;AAEA,cAAQ,KAAK,CAAC;AAAA,IAChB;AAEA,YAAQ,KAAK,MAAM,UAAU,MAAS;AACtC;AAAA,EACF;AAAA,EACA;AACE,cAAU,mBAAmB,MAAM,IAAI;AACvC,cAAU,mCAAmC;AAC7C;AACJ;","names":[]}
@@ -5,6 +5,7 @@ import {
5
5
  IntlayerProvider
6
6
  } from './IntlayerProvider.mjs';
7
7
  import { useIntlayer } from './useIntlayer.mjs';
8
+ import { useIntlayerAsync } from './useIntlayerAsync.mjs';
8
9
  import { useDictionary } from './useDictionary.mjs';
9
10
  import { useLocaleBase } from './useLocaleBase.mjs';
10
11
  import { useLocale } from './useLocale.mjs';
@@ -25,6 +26,7 @@ export {
25
26
  t,
26
27
  useDictionary,
27
28
  useIntlayer,
29
+ useIntlayerAsync,
28
30
  useIntlayerContext,
29
31
  useLocale,
30
32
  useLocaleBase,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export {\n type IntlayerProviderProps,\n IntlayerClientContext,\n useIntlayerContext,\n IntlayerProvider,\n} from './IntlayerProvider';\nexport { useIntlayer } from './useIntlayer';\nexport { useDictionary } from './useDictionary';\nexport { useLocaleBase } from './useLocaleBase';\nexport { useLocale } from './useLocale';\nexport { useTraduction } from './useTraduction';\nexport {\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n} from './useLocaleCookie';\nexport { getBrowserLocale } from './getBrowserLocale';\nexport { t } from './t';\n"],"mappings":";AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;AACjC,SAAS,SAAS;","names":[]}
1
+ {"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export {\n type IntlayerProviderProps,\n IntlayerClientContext,\n useIntlayerContext,\n IntlayerProvider,\n} from './IntlayerProvider';\nexport { useIntlayer } from './useIntlayer';\nexport { useIntlayerAsync } from './useIntlayerAsync';\nexport { useDictionary } from './useDictionary';\nexport { useLocaleBase } from './useLocaleBase';\nexport { useLocale } from './useLocale';\nexport { useTraduction } from './useTraduction';\nexport {\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n} from './useLocaleCookie';\nexport { getBrowserLocale } from './getBrowserLocale';\nexport { t } from './t';\n"],"mappings":";AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB;AACjC,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;AACjC,SAAS,SAAS;","names":[]}
@@ -1,12 +1,12 @@
1
1
  "use client";
2
2
  import "../chunk-ZD7AOCMD.mjs";
3
3
  import { useContext } from "react";
4
- import { useDictionaryBase } from '../useDictionaryBase.mjs';
4
+ import { getDictionary } from '../getDictionary.mjs';
5
5
  import { IntlayerClientContext } from './IntlayerProvider.mjs';
6
- const useDictionary = (dictionary, locale) => {
6
+ const useDictionary = (dictionary, locale, isRenderEditor = false) => {
7
7
  const { locale: currentLocale } = useContext(IntlayerClientContext);
8
8
  const localeTarget = locale ?? currentLocale;
9
- return useDictionaryBase(dictionary, localeTarget);
9
+ return getDictionary(dictionary, localeTarget, isRenderEditor);
10
10
  };
11
11
  export {
12
12
  useDictionary
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport type { DeclarationContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { useDictionaryBase, type UseDictionary } from '../useDictionaryBase';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionary: UseDictionary = <T extends DeclarationContent>(\n dictionary: T,\n locale?: Locales\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return useDictionaryBase(dictionary, localeTarget);\n};\n"],"mappings":";;AAIA,SAAS,kBAAkB;AAC3B,SAAS,yBAA6C;AACtD,SAAS,6BAA6B;AAO/B,MAAM,gBAA+B,CAC1C,YACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,SAAO,kBAAkB,YAAY,YAAY;AACnD;","names":[]}
1
+ {"version":3,"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport type { DeclarationContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { getDictionary, type UseDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionary: UseDictionary = <T extends DeclarationContent>(\n dictionary: T,\n locale?: Locales,\n isRenderEditor = false\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getDictionary(dictionary, localeTarget, isRenderEditor);\n};\n"],"mappings":";;AAIA,SAAS,kBAAkB;AAC3B,SAAS,qBAAyC;AAClD,SAAS,6BAA6B;AAO/B,MAAM,gBAA+B,CAC1C,YACA,QACA,iBAAiB,UACd;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,SAAO,cAAc,YAAY,cAAc,cAAc;AAC/D;","names":[]}
@@ -2,13 +2,13 @@
2
2
  import "../chunk-ZD7AOCMD.mjs";
3
3
  import { useContext } from "react";
4
4
  import {
5
- useIntlayerBase
6
- } from '../useIntlayerBase.mjs';
5
+ getIntlayer
6
+ } from '../getIntlayer.mjs';
7
7
  import { IntlayerClientContext } from './IntlayerProvider.mjs';
8
- const useIntlayer = (key, locale) => {
8
+ const useIntlayer = (key, locale, isRenderEditor = true) => {
9
9
  const { locale: currentLocale } = useContext(IntlayerClientContext);
10
10
  const localeTarget = locale ?? currentLocale;
11
- return useIntlayerBase(key, localeTarget);
11
+ return getIntlayer(key, localeTarget, isRenderEditor);
12
12
  };
13
13
  export {
14
14
  useIntlayer
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useContext } from 'react';\nimport {\n type DictionaryKeys,\n useIntlayerBase,\n type UseIntlayer,\n} from '../useIntlayerBase';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useIntlayer: UseIntlayer = <T extends DictionaryKeys>(\n key: T,\n locale?: Locales\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return useIntlayerBase(key, localeTarget);\n};\n"],"mappings":";;AAGA,SAAS,kBAAkB;AAC3B;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,6BAA6B;AAO/B,MAAM,cAA2B,CACtC,KACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,SAAO,gBAAgB,KAAK,YAAY;AAC1C;","names":[]}
1
+ {"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useContext } from 'react';\nimport {\n type DictionaryKeys,\n getIntlayer,\n type UseIntlayerEditable,\n} from '../getIntlayer';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useIntlayer: UseIntlayerEditable = <T extends DictionaryKeys>(\n key: T,\n locale?: Locales,\n isRenderEditor = true\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getIntlayer(key, localeTarget, isRenderEditor);\n};\n"],"mappings":";;AAGA,SAAS,kBAAkB;AAC3B;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,6BAA6B;AAO/B,MAAM,cAAmC,CAC9C,KACA,QACA,iBAAiB,SACd;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,SAAO,YAAY,KAAK,cAAc,cAAc;AACtD;","names":[]}
@@ -0,0 +1,34 @@
1
+ "use client";
2
+ import "../chunk-ZD7AOCMD.mjs";
3
+ import { useContext, useEffect, useMemo, useState } from "react";
4
+ import {
5
+ getIntlayer
6
+ } from '../getIntlayer.mjs';
7
+ import { getIntlayerAsync } from '../getIntlayerAsync.mjs';
8
+ import { IntlayerClientContext } from './IntlayerProvider.mjs';
9
+ const useIntlayerAsync = (key, locale, isRenderEditor = true) => {
10
+ const { locale: currentLocale } = useContext(IntlayerClientContext);
11
+ const localeTarget = locale ?? currentLocale;
12
+ const localeDictionary = getIntlayer(key, localeTarget, isRenderEditor);
13
+ const [distantDictionary, setDistantDictionary] = useState(void 0);
14
+ const [isLoading, setIsLoading] = useState(false);
15
+ useEffect(() => {
16
+ setIsLoading(true);
17
+ getIntlayerAsync(key).then((distantDictionary2) => {
18
+ if (distantDictionary2) {
19
+ setDistantDictionary(distantDictionary2);
20
+ }
21
+ }).finally(() => {
22
+ setIsLoading(false);
23
+ });
24
+ }, []);
25
+ const dictionary = useMemo(
26
+ () => distantDictionary ?? localeDictionary,
27
+ [distantDictionary, localeDictionary]
28
+ );
29
+ return { ...dictionary, isLoading };
30
+ };
31
+ export {
32
+ useIntlayerAsync
33
+ };
34
+ //# sourceMappingURL=useIntlayerAsync.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/useIntlayerAsync.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useContext, useEffect, useMemo, useState } from 'react';\nimport {\n DataFromDictionaryKey,\n type DictionaryKeys,\n getIntlayer,\n} from '../getIntlayer';\nimport { getIntlayerAsync } from '../getIntlayerAsync';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\nexport type UseIntlayerAsync = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = true,\n>(\n key: T,\n locale?: L,\n isRenderEditor?: R\n) => DataFromDictionaryKey<T, L, R> & { isLoading: boolean };\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * This hook will prerender the locale dictionary and fetch simultaneously the distant dictionaries to hydrate it.\n *\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useIntlayerAsync: UseIntlayerAsync = <T extends DictionaryKeys>(\n key: T,\n locale?: Locales,\n isRenderEditor = true\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n const localeDictionary = getIntlayer(key, localeTarget, isRenderEditor);\n const [distantDictionary, setDistantDictionary] = useState<\n typeof localeDictionary | null | undefined\n >(undefined);\n const [isLoading, setIsLoading] = useState(false);\n\n useEffect(() => {\n setIsLoading(true);\n\n getIntlayerAsync(key)\n .then((distantDictionary) => {\n if (distantDictionary) {\n setDistantDictionary(distantDictionary);\n }\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, []);\n\n const dictionary = useMemo(\n () => distantDictionary ?? localeDictionary,\n [distantDictionary, localeDictionary]\n );\n\n return { ...dictionary, isLoading };\n};\n"],"mappings":";;AAGA,SAAS,YAAY,WAAW,SAAS,gBAAgB;AACzD;AAAA,EAGE;AAAA,OACK;AACP,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AAoB/B,MAAM,mBAAqC,CAChD,KACA,QACA,iBAAiB,SACd;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAC/B,QAAM,mBAAmB,YAAY,KAAK,cAAc,cAAc;AACtE,QAAM,CAAC,mBAAmB,oBAAoB,IAAI,SAEhD,MAAS;AACX,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAEhD,YAAU,MAAM;AACd,iBAAa,IAAI;AAEjB,qBAAiB,GAAG,EACjB,KAAK,CAACA,uBAAsB;AAC3B,UAAIA,oBAAmB;AACrB,6BAAqBA,kBAAiB;AAAA,MACxC;AAAA,IACF,CAAC,EACA,QAAQ,MAAM;AACb,mBAAa,KAAK;AAAA,IACpB,CAAC;AAAA,EACL,GAAG,CAAC,CAAC;AAEL,QAAM,aAAa;AAAA,IACjB,MAAM,qBAAqB;AAAA,IAC3B,CAAC,mBAAmB,gBAAgB;AAAA,EACtC;AAEA,SAAO,EAAE,GAAG,YAAY,UAAU;AACpC;","names":["distantDictionary"]}
@@ -0,0 +1,36 @@
1
+ import "../chunk-ZD7AOCMD.mjs";
2
+ import { getConfiguration } from "@intlayer/config/client";
3
+ import { getIntlayerAPI } from "@intlayer/design-system/libs";
4
+ const fetchDistantDictionary = async (dictionaryKey) => {
5
+ try {
6
+ const config = getConfiguration();
7
+ const { clientId, clientSecret } = config.editor;
8
+ const intlayerAPI = getIntlayerAPI(void 0, config);
9
+ if (!clientId || !clientSecret) {
10
+ throw new Error(
11
+ "Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project."
12
+ );
13
+ }
14
+ const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();
15
+ const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
16
+ const getDictionaryResult = await intlayerAPI.dictionary.getDictionary(
17
+ dictionaryKey,
18
+ void 0,
19
+ {
20
+ headers: { Authorization: `Bearer ${oAuth2AccessToken}` }
21
+ }
22
+ );
23
+ const distantDictionary = getDictionaryResult.data;
24
+ if (!distantDictionary) {
25
+ throw new Error(`Dictionary ${dictionaryKey} not found on remote`);
26
+ }
27
+ return distantDictionary;
28
+ } catch (error) {
29
+ console.error(error);
30
+ return void 0;
31
+ }
32
+ };
33
+ export {
34
+ fetchDistantDictionary
35
+ };
36
+ //# sourceMappingURL=fetchDistantDictionary.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/distantDictionary/fetchDistantDictionary.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config/client';\n// @ts-ignore @intlayer/design-system not build yet\nimport { getIntlayerAPI } from '@intlayer/design-system/libs';\n\n/**\n * Fetch distant dictionary\n */\nexport const fetchDistantDictionary = async (\n dictionaryKey: string\n): Promise<DictionaryAPI> => {\n try {\n const config = getConfiguration();\n const { clientId, clientSecret } = config.editor;\n const intlayerAPI = getIntlayerAPI(undefined, config);\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n // Fetch the dictionary\n const getDictionaryResult = await intlayerAPI.dictionary.getDictionary(\n dictionaryKey,\n undefined,\n {\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n }\n );\n\n const distantDictionary = getDictionaryResult.data;\n\n if (!distantDictionary) {\n throw new Error(`Dictionary ${dictionaryKey} not found on remote`);\n }\n\n return distantDictionary;\n } catch (error) {\n console.error(error);\n return undefined;\n }\n};\n"],"mappings":";AAEA,SAAS,wBAAwB;AAEjC,SAAS,sBAAsB;AAKxB,MAAM,yBAAyB,OACpC,kBAC2B;AAC3B,MAAI;AACF,UAAM,SAAS,iBAAiB;AAChC,UAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAC1C,UAAM,cAAc,eAAe,QAAW,MAAM;AAEpD,QAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,oBAAoB,MAAM,YAAY,KAAK,qBAAqB;AAEtE,UAAM,oBAAoB,kBAAkB,MAAM;AAGlD,UAAM,sBAAsB,MAAM,YAAY,WAAW;AAAA,MACvD;AAAA,MACA;AAAA,MACA;AAAA,QACE,SAAS,EAAE,eAAe,UAAU,iBAAiB,GAAG;AAAA,MAC1D;AAAA,IACF;AAEA,UAAM,oBAAoB,oBAAoB;AAE9C,QAAI,CAAC,mBAAmB;AACtB,YAAM,IAAI,MAAM,cAAc,aAAa,sBAAsB;AAAA,IACnE;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AACnB,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport { type KeyPath } from '@intlayer/core';\nimport { type FC, type ReactNode } from 'react';\n\nexport type ContentSelectorWrapperProps = {\n children: ReactNode;\n dictionaryId: string;\n dictionaryPath: string;\n keyPath: KeyPath[];\n};\n\nexport const ContentSelectorWrapper: FC<ContentSelectorWrapperProps> = ({\n children,\n}) => <>{children}</>;\n"],"mappings":";;AAcM;AAFC,MAAM,yBAA0D,CAAC;AAAA,EACtE;AACF,MAAM,gCAAG,UAAS;","names":[]}
1
+ {"version":3,"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport { type KeyPath } from '@intlayer/core';\nimport { type FC, type ReactNode } from 'react';\n\nexport type ContentSelectorWrapperProps = {\n children: ReactNode;\n dictionaryKey: string;\n dictionaryPath: string;\n keyPath: KeyPath[];\n};\n\nexport const ContentSelectorWrapper: FC<ContentSelectorWrapperProps> = ({\n children,\n}) => <>{children}</>;\n"],"mappings":";;AAcM;AAFC,MAAM,yBAA0D,CAAC;AAAA,EACtE;AACF,MAAM,gCAAG,UAAS;","names":[]}
@@ -1,7 +1,11 @@
1
1
  import "../chunk-ZD7AOCMD.mjs";
2
- import { jsx } from "react/jsx-runtime";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { PoweredByMeta } from '../utils/PoweredByMeta/index.mjs';
3
4
  import { ContentSelectorProvider } from './ContentSelectorConnector.mjs';
4
- const IntlayerEditorProvider = ({ children }) => /* @__PURE__ */ jsx(ContentSelectorProvider, { children });
5
+ const IntlayerEditorProvider = ({ children }) => /* @__PURE__ */ jsxs(ContentSelectorProvider, { children: [
6
+ /* @__PURE__ */ jsx(PoweredByMeta, {}),
7
+ children
8
+ ] });
5
9
  export {
6
10
  IntlayerEditorProvider
7
11
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["import { FC, PropsWithChildren } from 'react';\nimport { ContentSelectorProvider } from './ContentSelectorConnector';\n\nexport const IntlayerEditorProvider: FC<PropsWithChildren> = ({ children }) => (\n <ContentSelectorProvider>{children}</ContentSelectorProvider>\n);\n"],"mappings":";AAIE;AAHF,SAAS,+BAA+B;AAEjC,MAAM,yBAAgD,CAAC,EAAE,SAAS,MACvE,oBAAC,2BAAyB,UAAS;","names":[]}
1
+ {"version":3,"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["import { FC, PropsWithChildren } from 'react';\nimport { PoweredByMeta } from '../utils/PoweredByMeta/index';\nimport { ContentSelectorProvider } from './ContentSelectorConnector';\n\nexport const IntlayerEditorProvider: FC<PropsWithChildren> = ({ children }) => (\n <ContentSelectorProvider>\n <PoweredByMeta />\n {children}\n </ContentSelectorProvider>\n);\n"],"mappings":";AAKE,SACE,KADF;AAJF,SAAS,qBAAqB;AAC9B,SAAS,+BAA+B;AAEjC,MAAM,yBAAgD,CAAC,EAAE,SAAS,MACvE,qBAAC,2BACC;AAAA,sBAAC,iBAAc;AAAA,EACd;AAAA,GACH;","names":[]}
@@ -15,7 +15,7 @@ const IntlayerEditorElement = ({
15
15
  }
16
16
  return content;
17
17
  };
18
- const renderIntlayerEditor = (data, isContentSelectable) => {
18
+ const renderIntlayerEditor = (data, isContentSelectable = true) => {
19
19
  const Result = /* @__PURE__ */ jsx(
20
20
  IntlayerEditorElement,
21
21
  {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/editor/renderContentEditor.tsx"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\nimport type { KeyPath } from '@intlayer/core';\nimport type { FC, ReactNode } from 'react';\nimport { ContentSelectorConnector } from './ContentSelectorConnector';\n\nconst {\n editor: { enabled },\n} = getConfiguration();\n\nexport type IntlayerEditorElementProps = {\n content: string;\n dictionaryId: string;\n dictionaryPath: string;\n keyPath: KeyPath[];\n isContentSelectable: boolean;\n};\n\nconst IntlayerEditorElement: FC<IntlayerEditorElementProps> = ({\n content,\n isContentSelectable,\n ...props\n}) => {\n if (enabled && isContentSelectable) {\n return (\n <ContentSelectorConnector {...props}>{content}</ContentSelectorConnector>\n );\n }\n return content;\n};\n\nexport type RenderIntlayerEditorResult = ReactNode & { value: string };\n\nexport const renderIntlayerEditor = (\n data: IntlayerEditorElementProps,\n isContentSelectable: boolean\n): RenderIntlayerEditorResult => {\n const Result = (\n <IntlayerEditorElement\n {...data}\n isContentSelectable={isContentSelectable}\n />\n );\n\n return { ...Result, value: data.content };\n};\n"],"mappings":";AAwBM;AAxBN,SAAS,wBAAwB;AAGjC,SAAS,gCAAgC;AAEzC,MAAM;AAAA,EACJ,QAAQ,EAAE,QAAQ;AACpB,IAAI,iBAAiB;AAUrB,MAAM,wBAAwD,CAAC;AAAA,EAC7D;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,MAAI,WAAW,qBAAqB;AAClC,WACE,oBAAC,4BAA0B,GAAG,OAAQ,mBAAQ;AAAA,EAElD;AACA,SAAO;AACT;AAIO,MAAM,uBAAuB,CAClC,MACA,wBAC+B;AAC/B,QAAM,SACJ;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ;AAAA;AAAA,EACF;AAGF,SAAO,EAAE,GAAG,QAAQ,OAAO,KAAK,QAAQ;AAC1C;","names":[]}
1
+ {"version":3,"sources":["../../../src/editor/renderContentEditor.tsx"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\nimport type { KeyPath } from '@intlayer/core';\nimport type { FC, ReactNode } from 'react';\nimport { ContentSelectorConnector } from './ContentSelectorConnector';\n\nconst {\n editor: { enabled },\n} = getConfiguration();\n\nexport type IntlayerEditorElementProps = {\n content: string;\n dictionaryKey: string;\n dictionaryPath: string;\n keyPath: KeyPath[];\n isContentSelectable: boolean;\n};\n\nconst IntlayerEditorElement: FC<IntlayerEditorElementProps> = ({\n content,\n isContentSelectable,\n ...props\n}) => {\n if (enabled && isContentSelectable) {\n return (\n <ContentSelectorConnector {...props}>{content}</ContentSelectorConnector>\n );\n }\n return content;\n};\n\nexport type IntlayerNode<T = string> = ReactNode & {\n value: T;\n};\n\nexport const renderIntlayerEditor = (\n data: IntlayerEditorElementProps,\n isContentSelectable = true\n): IntlayerNode => {\n const Result = (\n <IntlayerEditorElement\n {...data}\n isContentSelectable={isContentSelectable}\n />\n );\n\n return { ...Result, value: data.content };\n};\n"],"mappings":";AAwBM;AAxBN,SAAS,wBAAwB;AAGjC,SAAS,gCAAgC;AAEzC,MAAM;AAAA,EACJ,QAAQ,EAAE,QAAQ;AACpB,IAAI,iBAAiB;AAUrB,MAAM,wBAAwD,CAAC;AAAA,EAC7D;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,MAAI,WAAW,qBAAqB;AAClC,WACE,oBAAC,4BAA0B,GAAG,OAAQ,mBAAQ;AAAA,EAElD;AACA,SAAO;AACT;AAMO,MAAM,uBAAuB,CAClC,MACA,sBAAsB,SACL;AACjB,QAAM,SACJ;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ;AAAA;AAAA,EACF;AAGF,SAAO,EAAE,GAAG,QAAQ,OAAO,KAAK,QAAQ;AAC1C;","names":[]}
@@ -1,31 +1,34 @@
1
1
  import "./chunk-ZD7AOCMD.mjs";
2
2
  import { isValidElement } from "react";
3
+ import {
4
+ renderIntlayerEditor
5
+ } from './editor/renderContentEditor.mjs';
3
6
  import { processDictionary } from './processDictionary/index.mjs';
4
- import { renderIntlayerEditor } from './editor/renderContentEditor.mjs';
5
- const recursiveTransformContent = (value, isContentSelectable = false) => {
7
+ const recursiveTransformContent = (value, isRenderEditor = false) => {
6
8
  if (typeof value === "function") {
7
- return (props) => recursiveTransformContent(value(props), isContentSelectable);
9
+ return (props) => recursiveTransformContent(value(props), isRenderEditor);
8
10
  } else if (typeof value === "object") {
9
- if (typeof value.dictionaryId !== "undefined") {
10
- return renderIntlayerEditor(value, isContentSelectable);
11
+ if (typeof value.dictionaryKey !== "undefined") {
12
+ if (isRenderEditor) {
13
+ return renderIntlayerEditor(value);
14
+ }
15
+ return value.content;
11
16
  } else if (Array.isArray(value)) {
12
- return value.map(
13
- (el) => recursiveTransformContent(el, isContentSelectable)
14
- );
17
+ return value.map((el) => recursiveTransformContent(el, isRenderEditor));
15
18
  } else if (isValidElement(value)) {
16
19
  return value;
17
20
  }
18
21
  return Object.entries(value).reduce(
19
22
  (acc, [key, value2]) => ({
20
23
  ...acc,
21
- [key]: recursiveTransformContent(value2, isContentSelectable)
24
+ [key]: recursiveTransformContent(value2, isRenderEditor)
22
25
  }),
23
26
  {}
24
27
  );
25
28
  }
26
29
  return value;
27
30
  };
28
- const useDictionaryBase = (dictionary, locale, isContentSelectable = false) => {
31
+ const getDictionary = (dictionary, locale, isRenderEditor = false) => {
29
32
  const result = processDictionary(
30
33
  dictionary.content,
31
34
  dictionary.key,
@@ -35,11 +38,11 @@ const useDictionaryBase = (dictionary, locale, isContentSelectable = false) => {
35
38
  );
36
39
  return recursiveTransformContent(
37
40
  result,
38
- isContentSelectable
41
+ isRenderEditor
39
42
  );
40
43
  };
41
44
  export {
42
- recursiveTransformContent,
43
- useDictionaryBase
45
+ getDictionary,
46
+ recursiveTransformContent
44
47
  };
45
- //# sourceMappingURL=useDictionaryBase.mjs.map
48
+ //# sourceMappingURL=getDictionary.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/getDictionary.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Locales } from '@intlayer/config';\nimport type {\n DeclarationContent,\n DictionaryValue,\n NodeType,\n} from '@intlayer/core';\nimport { isValidElement, type ReactNode } from 'react';\nimport {\n type IntlayerNode,\n renderIntlayerEditor,\n} from './editor/renderContentEditor';\nimport { processDictionary } from './processDictionary/index';\n\ntype TransformNodeType<T, L extends Locales, R extends boolean> = T extends {\n [NodeType.Enumeration]: { '1': any };\n}\n ? (\n quantity: number\n ) => DeepTransformContent<T[NodeType.Enumeration]['1'], L, R>\n : T extends {\n [NodeType.Translation]: object;\n }\n ? L extends keyof T[NodeType.Translation]\n ? DeepTransformContent<T[NodeType.Translation][L], L, R>\n : never\n : T;\n\nexport type DeepTransformContent<\n T,\n L extends Locales,\n R extends boolean,\n> = 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, R>[] // Apply DeepTransformContent recursively to each element of the array\n : T extends {\n nodeType: NodeType | string;\n }\n ? TransformNodeType<T, L, R>\n : T extends { _owner: any; key: any; props: any; ref: any }\n ? ReactNode\n : {\n [K in keyof T]: DeepTransformContent<T[K], L, R>;\n }\n : T extends undefined\n ? never\n : R extends true\n ? IntlayerNode<T>\n : T;\n\n/**\n * Go through the object. If a object has a keyPath, render the intlayer editor if editor enabled.\n */\nexport const recursiveTransformContent = (\n value: any,\n isRenderEditor = false\n): object => {\n if (typeof value === 'function') {\n return (props: any) =>\n recursiveTransformContent(value(props), isRenderEditor);\n } else if (typeof value === 'object') {\n if (typeof value.dictionaryKey !== 'undefined') {\n if (isRenderEditor) {\n return renderIntlayerEditor(value);\n }\n return value.content;\n } else if (Array.isArray(value)) {\n return value.map((el) => recursiveTransformContent(el, isRenderEditor));\n } else if (isValidElement(value)) {\n return value;\n }\n\n return Object.entries(value).reduce(\n (acc, [key, value]) => ({\n ...acc,\n [key]: recursiveTransformContent(value, isRenderEditor),\n }),\n {} as object\n );\n }\n\n return value;\n};\n\ntype DataFromDictionary<\n T extends DeclarationContent,\n K extends Locales,\n R extends boolean = false,\n> = DeepTransformContent<T['content'], K, R>;\n\nexport type UseDictionary = <\n T extends DeclarationContent,\n L extends Locales,\n R extends boolean = false,\n>(\n dictionary: T,\n locale?: L,\n isRenderEditor?: R\n) => DataFromDictionary<T, L, R>;\n\n/**\n * Hook that picks one dictionary by its id and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const getDictionary: UseDictionary = <\n T extends DeclarationContent,\n L extends Locales,\n R extends boolean = false,\n>(\n dictionary: T,\n locale?: L,\n isRenderEditor: R = false as R\n) => {\n const result = processDictionary(\n dictionary.content as DictionaryValue,\n dictionary.key,\n dictionary.filePath,\n [],\n locale\n );\n\n return recursiveTransformContent(\n result,\n isRenderEditor\n ) as DataFromDictionary<T, L, R>;\n};\n"],"mappings":";AAOA,SAAS,sBAAsC;AAC/C;AAAA,EAEE;AAAA,OACK;AACP,SAAS,yBAAyB;AAyC3B,MAAM,4BAA4B,CACvC,OACA,iBAAiB,UACN;AACX,MAAI,OAAO,UAAU,YAAY;AAC/B,WAAO,CAAC,UACN,0BAA0B,MAAM,KAAK,GAAG,cAAc;AAAA,EAC1D,WAAW,OAAO,UAAU,UAAU;AACpC,QAAI,OAAO,MAAM,kBAAkB,aAAa;AAC9C,UAAI,gBAAgB;AAClB,eAAO,qBAAqB,KAAK;AAAA,MACnC;AACA,aAAO,MAAM;AAAA,IACf,WAAW,MAAM,QAAQ,KAAK,GAAG;AAC/B,aAAO,MAAM,IAAI,CAAC,OAAO,0BAA0B,IAAI,cAAc,CAAC;AAAA,IACxE,WAAW,eAAe,KAAK,GAAG;AAChC,aAAO;AAAA,IACT;AAEA,WAAO,OAAO,QAAQ,KAAK,EAAE;AAAA,MAC3B,CAAC,KAAK,CAAC,KAAKA,MAAK,OAAO;AAAA,QACtB,GAAG;AAAA,QACH,CAAC,GAAG,GAAG,0BAA0BA,QAAO,cAAc;AAAA,MACxD;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;AAuBO,MAAM,gBAA+B,CAK1C,YACA,QACA,iBAAoB,UACjB;AACH,QAAM,SAAS;AAAA,IACb,WAAW;AAAA,IACX,WAAW;AAAA,IACX,WAAW;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":["value"]}