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.
- package/README.md +5 -5
- package/dist/cjs/cli/react-intlayer.cjs +4 -4
- package/dist/cjs/cli/react-intlayer.cjs.map +1 -1
- package/dist/cjs/client/index.cjs +3 -0
- package/dist/cjs/client/index.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +3 -3
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +3 -3
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useIntlayerAsync.cjs +55 -0
- package/dist/cjs/client/useIntlayerAsync.cjs.map +1 -0
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs +59 -0
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs.map +1 -0
- package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs +5 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/renderContentEditor.cjs +1 -1
- package/dist/cjs/editor/renderContentEditor.cjs.map +1 -1
- package/dist/cjs/{useDictionaryBase.cjs → getDictionary.cjs} +20 -19
- package/dist/cjs/getDictionary.cjs.map +1 -0
- package/dist/cjs/{useIntlayerBase.cjs → getIntlayer.cjs} +13 -11
- package/dist/cjs/getIntlayer.cjs.map +1 -0
- package/dist/cjs/getIntlayerAsync.cjs +42 -0
- package/dist/cjs/getIntlayerAsync.cjs.map +1 -0
- package/dist/cjs/index.cjs +8 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/processDictionary/contentDictionary.cjs.map +1 -1
- package/dist/cjs/processDictionary/index.cjs +13 -13
- package/dist/cjs/processDictionary/index.cjs.map +1 -1
- package/dist/cjs/server/useDictionary.cjs +3 -3
- package/dist/cjs/server/useDictionary.cjs.map +1 -1
- package/dist/cjs/server/useIntlayer.cjs +3 -3
- package/dist/cjs/server/useIntlayer.cjs.map +1 -1
- package/dist/cjs/utils/PoweredByMeta/index.cjs +40 -0
- package/dist/cjs/utils/PoweredByMeta/index.cjs.map +1 -0
- package/dist/esm/cli/react-intlayer.mjs +5 -5
- package/dist/esm/cli/react-intlayer.mjs.map +1 -1
- package/dist/esm/client/index.mjs +2 -0
- package/dist/esm/client/index.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +3 -3
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +4 -4
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useIntlayerAsync.mjs +34 -0
- package/dist/esm/client/useIntlayerAsync.mjs.map +1 -0
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs +36 -0
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs.map +1 -0
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs +6 -2
- package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
- package/dist/esm/editor/renderContentEditor.mjs +1 -1
- package/dist/esm/editor/renderContentEditor.mjs.map +1 -1
- package/dist/esm/{useDictionaryBase.mjs → getDictionary.mjs} +17 -14
- package/dist/esm/getDictionary.mjs.map +1 -0
- package/dist/esm/{useIntlayerBase.mjs → getIntlayer.mjs} +9 -7
- package/dist/esm/getIntlayer.mjs.map +1 -0
- package/dist/esm/getIntlayerAsync.mjs +19 -0
- package/dist/esm/getIntlayerAsync.mjs.map +1 -0
- package/dist/esm/index.mjs +6 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/processDictionary/index.mjs +13 -13
- package/dist/esm/processDictionary/index.mjs.map +1 -1
- package/dist/esm/server/useDictionary.mjs +3 -3
- package/dist/esm/server/useDictionary.mjs.map +1 -1
- package/dist/esm/server/useIntlayer.mjs +4 -4
- package/dist/esm/server/useIntlayer.mjs.map +1 -1
- package/dist/esm/utils/PoweredByMeta/index.mjs +17 -0
- package/dist/esm/utils/PoweredByMeta/index.mjs.map +1 -0
- package/dist/types/client/index.d.ts +1 -0
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/client/useDictionary.d.ts +1 -1
- package/dist/types/client/useDictionary.d.ts.map +1 -1
- package/dist/types/client/useIntlayer.d.ts +2 -2
- package/dist/types/client/useIntlayer.d.ts.map +1 -1
- package/dist/types/client/useIntlayerAsync.d.ts +15 -0
- package/dist/types/client/useIntlayerAsync.d.ts.map +1 -0
- package/dist/types/distantDictionary/fetchDistantDictionary.d.ts +6 -0
- package/dist/types/distantDictionary/fetchDistantDictionary.d.ts.map +1 -0
- package/dist/types/editor/ContentSelectorWrapper.d.ts +1 -1
- package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -1
- package/dist/types/editor/IntlayerEditorProvider.d.ts.map +1 -1
- package/dist/types/editor/renderContentEditor.d.ts +4 -4
- package/dist/types/editor/renderContentEditor.d.ts.map +1 -1
- package/dist/types/getDictionary.d.ts +35 -0
- package/dist/types/getDictionary.d.ts.map +1 -0
- package/dist/types/{useIntlayerBase.d.ts → getIntlayer.d.ts} +6 -10
- package/dist/types/getIntlayer.d.ts.map +1 -0
- package/dist/types/getIntlayerAsync.d.ts +13 -0
- package/dist/types/getIntlayerAsync.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/processDictionary/contentDictionary.d.ts +1 -1
- package/dist/types/processDictionary/contentDictionary.d.ts.map +1 -1
- package/dist/types/processDictionary/index.d.ts +2 -2
- package/dist/types/processDictionary/index.d.ts.map +1 -1
- package/dist/types/server/useDictionary.d.ts +1 -1
- package/dist/types/server/useDictionary.d.ts.map +1 -1
- package/dist/types/server/useIntlayer.d.ts +2 -2
- package/dist/types/server/useIntlayer.d.ts.map +1 -1
- package/dist/types/utils/PoweredByMeta/index.d.ts +3 -0
- package/dist/types/utils/PoweredByMeta/index.d.ts.map +1 -0
- package/package.json +15 -14
- package/dist/cjs/useDictionaryBase.cjs.map +0 -1
- package/dist/cjs/useIntlayerBase.cjs.map +0 -1
- package/dist/esm/useDictionaryBase.mjs.map +0 -1
- package/dist/esm/useIntlayerBase.mjs.map +0 -1
- package/dist/types/useDictionaryBase.d.ts +0 -37
- package/dist/types/useDictionaryBase.d.ts.map +0 -1
- package/dist/types/useIntlayerBase.d.ts.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type Locales } from '@intlayer/config/client';
|
|
2
2
|
import { type KeyPath, type DictionaryValue } from '@intlayer/core';
|
|
3
3
|
import type { TransformedContent, TransformedContentValue } from './contentDictionary';
|
|
4
|
-
export declare const processNode: (field: DictionaryValue | undefined, locale: Locales,
|
|
4
|
+
export declare const processNode: (field: DictionaryValue | undefined, locale: Locales, dictionaryKey: string, dictionaryPath?: string, keyPath?: KeyPath[]) => TransformedContentValue;
|
|
5
5
|
/**
|
|
6
6
|
* Function that process a dictionary and return the result to be used in the application.
|
|
7
7
|
*/
|
|
8
|
-
export declare const processDictionary: (content: DictionaryValue,
|
|
8
|
+
export declare const processDictionary: (content: DictionaryValue, dictionaryKey: string, dictionaryPath?: string, keyPath?: KeyPath[], locale?: Locales) => TransformedContent;
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/processDictionary/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,OAAO,EAAoB,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAKL,KAAK,OAAO,EACZ,KAAK,eAAe,EAIrB,MAAM,gBAAgB,CAAC;AAIxB,OAAO,KAAK,EACV,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,qBAAqB,CAAC;AAoE7B,eAAO,MAAM,WAAW,UACf,eAAe,GAAG,SAAS,UAC1B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/processDictionary/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,OAAO,EAAoB,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAKL,KAAK,OAAO,EACZ,KAAK,eAAe,EAIrB,MAAM,gBAAgB,CAAC;AAIxB,OAAO,KAAK,EACV,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,qBAAqB,CAAC;AAoE7B,eAAO,MAAM,WAAW,UACf,eAAe,GAAG,SAAS,UAC1B,OAAO,iBACA,MAAM,mBACJ,MAAM,YACd,OAAO,EAAE,KACjB,uBAyCF,CAAC;AAyCF;;GAEG;AACH,eAAO,MAAM,iBAAiB,YACnB,eAAe,iBACT,MAAM,mBACJ,MAAM,YACd,OAAO,EAAE,WACV,OAAO,KACd,kBA0EF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.d.ts","sourceRoot":"","sources":["../../../src/server/useDictionary.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"useDictionary.d.ts","sourceRoot":"","sources":["../../../src/server/useDictionary.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAIrE;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,aAS3B,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type UseIntlayerEditable } from '../getIntlayer';
|
|
2
2
|
/**
|
|
3
3
|
* On the server side, Hook that picking one dictionary by its key and return the content
|
|
4
4
|
*
|
|
5
5
|
* If the locale is not provided, it will use the locale from the server context
|
|
6
6
|
*/
|
|
7
|
-
export declare const useIntlayer:
|
|
7
|
+
export declare const useIntlayer: UseIntlayerEditable;
|
|
8
8
|
//# sourceMappingURL=useIntlayer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.d.ts","sourceRoot":"","sources":["../../../src/server/useIntlayer.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,
|
|
1
|
+
{"version":3,"file":"useIntlayer.d.ts","sourceRoot":"","sources":["../../../src/server/useIntlayer.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,gBAAgB,CAAC;AAIxB;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,mBASzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/PoweredByMeta/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,EAAa,MAAM,OAAO,CAAC;AAE3C,eAAO,MAAM,aAAa,EAAE,EAW3B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-intlayer",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Internationalization layer for React applications. Declare your multilingual contant in the same lever than your component. Powered by TypeScript, declaration files.",
|
|
6
6
|
"keywords": [
|
|
@@ -86,16 +86,17 @@
|
|
|
86
86
|
],
|
|
87
87
|
"dependencies": {
|
|
88
88
|
"@craco/craco": "^7.1.0",
|
|
89
|
+
"@intlayer/design-system": "^3.5.4",
|
|
89
90
|
"cross-spawn": "^7.0.6",
|
|
90
91
|
"js-cookie": "^3.0.5",
|
|
91
92
|
"react-cookie": "^7.2.2",
|
|
92
93
|
"vite": "^6.0.3",
|
|
93
94
|
"webpack": "^5.96.1",
|
|
94
|
-
"@intlayer/chokidar": "^3.5.
|
|
95
|
-
"@intlayer/
|
|
96
|
-
"@intlayer/
|
|
97
|
-
"@intlayer/
|
|
98
|
-
"@intlayer/
|
|
95
|
+
"@intlayer/chokidar": "^3.5.5",
|
|
96
|
+
"@intlayer/config": "^3.5.5",
|
|
97
|
+
"@intlayer/dictionaries-entry": "^3.5.5",
|
|
98
|
+
"@intlayer/webpack": "^3.5.5",
|
|
99
|
+
"@intlayer/core": "^3.5.5"
|
|
99
100
|
},
|
|
100
101
|
"devDependencies": {
|
|
101
102
|
"@craco/types": "^7.1.0",
|
|
@@ -113,21 +114,21 @@
|
|
|
113
114
|
"tsc-alias": "^1.8.10",
|
|
114
115
|
"tsup": "^8.3.5",
|
|
115
116
|
"typescript": "^5.7.2",
|
|
116
|
-
"@utils/ts-config-types": "^1.0.4",
|
|
117
|
-
"@utils/ts-config": "^1.0.4",
|
|
118
117
|
"@utils/eslint-config": "^1.0.4",
|
|
118
|
+
"@utils/ts-config": "^1.0.4",
|
|
119
|
+
"@utils/ts-config-types": "^1.0.4",
|
|
119
120
|
"@utils/tsup-config": "^1.0.4"
|
|
120
121
|
},
|
|
121
122
|
"peerDependencies": {
|
|
122
123
|
"react": ">=16.0.0 <19.0.0",
|
|
123
124
|
"react-dom": ">=16.0.0 <19.0.0",
|
|
124
125
|
"vite": ">=4.0.0",
|
|
125
|
-
"@intlayer/
|
|
126
|
-
"@intlayer/
|
|
127
|
-
"@intlayer/
|
|
128
|
-
"@intlayer/
|
|
129
|
-
"intlayer": "^3.5.
|
|
130
|
-
"@intlayer/
|
|
126
|
+
"@intlayer/config": "^3.5.5",
|
|
127
|
+
"@intlayer/chokidar": "^3.5.5",
|
|
128
|
+
"@intlayer/core": "^3.5.5",
|
|
129
|
+
"@intlayer/webpack": "^3.5.5",
|
|
130
|
+
"intlayer": "^3.5.5",
|
|
131
|
+
"@intlayer/dictionaries-entry": "^3.5.5"
|
|
131
132
|
},
|
|
132
133
|
"engines": {
|
|
133
134
|
"node": ">=14.18"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useDictionaryBase.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 { processDictionary } from './processDictionary/index';\nimport { renderIntlayerEditor } from './editor/renderContentEditor';\n\nexport type IntlayerNode<T = string> = ReactNode & {\n value: T;\n};\n\ntype TransformNodeType<T, L extends Locales> = T extends {\n [NodeType.Enumeration]: { '1': any };\n}\n ? (quantity: number) => DeepTransformContent<T[NodeType.Enumeration]['1'], L>\n : T extends {\n [NodeType.Translation]: object;\n }\n ? L extends keyof T[NodeType.Translation]\n ? DeepTransformContent<T[NodeType.Translation][L], L>\n : never\n : T;\n\nexport type DeepTransformContent<T, L extends Locales> = T extends object // Check if the property is an object\n ? T extends (infer U)[] // If it's an array, infer the type of array elements\n ? DeepTransformContent<U, L>[] // Apply DeepTransformContent recursively to each element of the array\n : T extends {\n nodeType: NodeType | string;\n }\n ? TransformNodeType<T, L>\n : T extends { _owner: any; key: any; props: any; ref: any }\n ? ReactNode\n : {\n [K in keyof T]: DeepTransformContent<T[K], L>;\n }\n : T extends undefined\n ? never\n : IntlayerNode<T>;\n\n/**\n * 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 isContentSelectable = false\n): object => {\n if (typeof value === 'function') {\n return (props: any) =>\n recursiveTransformContent(value(props), isContentSelectable);\n } else if (typeof value === 'object') {\n if (typeof value.dictionaryId !== 'undefined') {\n return renderIntlayerEditor(value, isContentSelectable);\n } else if (Array.isArray(value)) {\n return value.map((el) =>\n recursiveTransformContent(el, isContentSelectable)\n );\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, isContentSelectable),\n }),\n {} as object\n );\n }\n\n return value;\n};\n\ntype DataFromDictionary<\n T extends DeclarationContent,\n K extends Locales,\n> = DeepTransformContent<T['content'], K>;\n\nexport type UseDictionary = <T extends DeclarationContent, L extends Locales>(\n dictionary: T,\n locale?: L\n) => DataFromDictionary<T, L>;\n\n// Add description is JSDoc\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 useDictionaryBase: UseDictionary = <\n T extends DeclarationContent,\n L extends Locales,\n>(\n dictionary: T,\n locale?: L,\n isContentSelectable = false\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 isContentSelectable\n ) as DataFromDictionary<T, L>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,mBAA+C;AAC/C,+BAAkC;AAClC,iCAAqC;AAqC9B,MAAM,4BAA4B,CACvC,OACA,sBAAsB,UACX;AACX,MAAI,OAAO,UAAU,YAAY;AAC/B,WAAO,CAAC,UACN,0BAA0B,MAAM,KAAK,GAAG,mBAAmB;AAAA,EAC/D,WAAW,OAAO,UAAU,UAAU;AACpC,QAAI,OAAO,MAAM,iBAAiB,aAAa;AAC7C,iBAAO,iDAAqB,OAAO,mBAAmB;AAAA,IACxD,WAAW,MAAM,QAAQ,KAAK,GAAG;AAC/B,aAAO,MAAM;AAAA,QAAI,CAAC,OAChB,0BAA0B,IAAI,mBAAmB;AAAA,MACnD;AAAA,IACF,eAAW,6BAAe,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,mBAAmB;AAAA,MAC7D;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;AAkBO,MAAM,oBAAmC,CAI9C,YACA,QACA,sBAAsB,UACnB;AACH,QAAM,aAAS;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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useIntlayerBase.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\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 { processDictionary } from './processDictionary/index';\nimport {\n type DeepTransformContent,\n recursiveTransformContent,\n} from './useDictionaryBase';\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\n/**\n * Represents the data type returned by the useIntlayer hook,\n * excluding the 'id' and 'filePath' keys from the dictionary content.\n */\ntype DataFromDictionaryKey<\n T extends DictionaryKeys,\n K extends Locales,\n> = DeepTransformContent<IntlayerDictionaryTypesConnector[T]['content'], K>;\n\n/**\n * Type definition for the useIntlayer hook, which takes a dictionary ID and an optional locale,\n * and returns the deeply transformed dictionary content.\n *\n */\nexport type UseIntlayer = <T extends DictionaryKeys, L extends Locales>(\n key: T,\n locale?: L\n) => DataFromDictionaryKey<T, L>;\n\n/**\n * Hook that picks one dictionary by its ID and returns the content,\n * deeply transformed according to the dictionary structure and metadata.\n */\nexport const useIntlayerBase: UseIntlayer = <\n T extends DictionaryKeys,\n L extends Locales,\n>(\n key: T,\n locale?: L\n) => {\n const dictionary: Dictionary = dictionaries[key as keyof typeof dictionaries];\n\n const result = processDictionary(\n dictionary.content,\n dictionary.key,\n dictionary.filePath,\n [],\n locale\n );\n\n const isContentSelectable = true;\n\n return recursiveTransformContent(\n result,\n isContentSelectable\n ) as DataFromDictionaryKey<T, L>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,gCAAyB;AAEzB,+BAAkC;AAClC,+BAGO;AA+CA,MAAM,kBAA+B,CAI1C,KACA,WACG;AACH,QAAM,aAAyB,0BAAAA,QAAa,GAAgC;AAE5E,QAAM,aAAS;AAAA,IACb,WAAW;AAAA,IACX,WAAW;AAAA,IACX,WAAW;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF;AAEA,QAAM,sBAAsB;AAE5B,aAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":["dictionaries"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useDictionaryBase.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 { processDictionary } from './processDictionary/index';\nimport { renderIntlayerEditor } from './editor/renderContentEditor';\n\nexport type IntlayerNode<T = string> = ReactNode & {\n value: T;\n};\n\ntype TransformNodeType<T, L extends Locales> = T extends {\n [NodeType.Enumeration]: { '1': any };\n}\n ? (quantity: number) => DeepTransformContent<T[NodeType.Enumeration]['1'], L>\n : T extends {\n [NodeType.Translation]: object;\n }\n ? L extends keyof T[NodeType.Translation]\n ? DeepTransformContent<T[NodeType.Translation][L], L>\n : never\n : T;\n\nexport type DeepTransformContent<T, L extends Locales> = T extends object // Check if the property is an object\n ? T extends (infer U)[] // If it's an array, infer the type of array elements\n ? DeepTransformContent<U, L>[] // Apply DeepTransformContent recursively to each element of the array\n : T extends {\n nodeType: NodeType | string;\n }\n ? TransformNodeType<T, L>\n : T extends { _owner: any; key: any; props: any; ref: any }\n ? ReactNode\n : {\n [K in keyof T]: DeepTransformContent<T[K], L>;\n }\n : T extends undefined\n ? never\n : IntlayerNode<T>;\n\n/**\n * 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 isContentSelectable = false\n): object => {\n if (typeof value === 'function') {\n return (props: any) =>\n recursiveTransformContent(value(props), isContentSelectable);\n } else if (typeof value === 'object') {\n if (typeof value.dictionaryId !== 'undefined') {\n return renderIntlayerEditor(value, isContentSelectable);\n } else if (Array.isArray(value)) {\n return value.map((el) =>\n recursiveTransformContent(el, isContentSelectable)\n );\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, isContentSelectable),\n }),\n {} as object\n );\n }\n\n return value;\n};\n\ntype DataFromDictionary<\n T extends DeclarationContent,\n K extends Locales,\n> = DeepTransformContent<T['content'], K>;\n\nexport type UseDictionary = <T extends DeclarationContent, L extends Locales>(\n dictionary: T,\n locale?: L\n) => DataFromDictionary<T, L>;\n\n// Add description is JSDoc\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 useDictionaryBase: UseDictionary = <\n T extends DeclarationContent,\n L extends Locales,\n>(\n dictionary: T,\n locale?: L,\n isContentSelectable = false\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 isContentSelectable\n ) as DataFromDictionary<T, L>;\n};\n"],"mappings":";AAOA,SAAS,sBAAsC;AAC/C,SAAS,yBAAyB;AAClC,SAAS,4BAA4B;AAqC9B,MAAM,4BAA4B,CACvC,OACA,sBAAsB,UACX;AACX,MAAI,OAAO,UAAU,YAAY;AAC/B,WAAO,CAAC,UACN,0BAA0B,MAAM,KAAK,GAAG,mBAAmB;AAAA,EAC/D,WAAW,OAAO,UAAU,UAAU;AACpC,QAAI,OAAO,MAAM,iBAAiB,aAAa;AAC7C,aAAO,qBAAqB,OAAO,mBAAmB;AAAA,IACxD,WAAW,MAAM,QAAQ,KAAK,GAAG;AAC/B,aAAO,MAAM;AAAA,QAAI,CAAC,OAChB,0BAA0B,IAAI,mBAAmB;AAAA,MACnD;AAAA,IACF,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,mBAAmB;AAAA,MAC7D;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;AAkBO,MAAM,oBAAmC,CAI9C,YACA,QACA,sBAAsB,UACnB;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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useIntlayerBase.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\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 { processDictionary } from './processDictionary/index';\nimport {\n type DeepTransformContent,\n recursiveTransformContent,\n} from './useDictionaryBase';\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\n/**\n * Represents the data type returned by the useIntlayer hook,\n * excluding the 'id' and 'filePath' keys from the dictionary content.\n */\ntype DataFromDictionaryKey<\n T extends DictionaryKeys,\n K extends Locales,\n> = DeepTransformContent<IntlayerDictionaryTypesConnector[T]['content'], K>;\n\n/**\n * Type definition for the useIntlayer hook, which takes a dictionary ID and an optional locale,\n * and returns the deeply transformed dictionary content.\n *\n */\nexport type UseIntlayer = <T extends DictionaryKeys, L extends Locales>(\n key: T,\n locale?: L\n) => DataFromDictionaryKey<T, L>;\n\n/**\n * Hook that picks one dictionary by its ID and returns the content,\n * deeply transformed according to the dictionary structure and metadata.\n */\nexport const useIntlayerBase: UseIntlayer = <\n T extends DictionaryKeys,\n L extends Locales,\n>(\n key: T,\n locale?: L\n) => {\n const dictionary: Dictionary = dictionaries[key as keyof typeof dictionaries];\n\n const result = processDictionary(\n dictionary.content,\n dictionary.key,\n dictionary.filePath,\n [],\n locale\n );\n\n const isContentSelectable = true;\n\n return recursiveTransformContent(\n result,\n isContentSelectable\n ) as DataFromDictionaryKey<T, L>;\n};\n"],"mappings":";AAOA,OAAO,kBAAkB;AAEzB,SAAS,yBAAyB;AAClC;AAAA,EAEE;AAAA,OACK;AA+CA,MAAM,kBAA+B,CAI1C,KACA,WACG;AACH,QAAM,aAAyB,aAAa,GAAgC;AAE5E,QAAM,SAAS;AAAA,IACb,WAAW;AAAA,IACX,WAAW;AAAA,IACX,WAAW;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF;AAEA,QAAM,sBAAsB;AAE5B,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { Locales } from '@intlayer/config';
|
|
2
|
-
import type { DeclarationContent, NodeType } from '@intlayer/core';
|
|
3
|
-
import { type ReactNode } from 'react';
|
|
4
|
-
export type IntlayerNode<T = string> = ReactNode & {
|
|
5
|
-
value: T;
|
|
6
|
-
};
|
|
7
|
-
type TransformNodeType<T, L extends Locales> = T extends {
|
|
8
|
-
[NodeType.Enumeration]: {
|
|
9
|
-
'1': any;
|
|
10
|
-
};
|
|
11
|
-
} ? (quantity: number) => DeepTransformContent<T[NodeType.Enumeration]['1'], L> : T extends {
|
|
12
|
-
[NodeType.Translation]: object;
|
|
13
|
-
} ? L extends keyof T[NodeType.Translation] ? DeepTransformContent<T[NodeType.Translation][L], L> : never : T;
|
|
14
|
-
export type DeepTransformContent<T, L extends Locales> = T extends object ? T extends (infer U)[] ? DeepTransformContent<U, L>[] : T extends {
|
|
15
|
-
nodeType: NodeType | string;
|
|
16
|
-
} ? TransformNodeType<T, L> : T extends {
|
|
17
|
-
_owner: any;
|
|
18
|
-
key: any;
|
|
19
|
-
props: any;
|
|
20
|
-
ref: any;
|
|
21
|
-
} ? ReactNode : {
|
|
22
|
-
[K in keyof T]: DeepTransformContent<T[K], L>;
|
|
23
|
-
} : T extends undefined ? never : IntlayerNode<T>;
|
|
24
|
-
/**
|
|
25
|
-
* Go through the object. If a object has a keyPath, render the intlayer editor if editor enabled.
|
|
26
|
-
*/
|
|
27
|
-
export declare const recursiveTransformContent: (value: any, isContentSelectable?: boolean) => object;
|
|
28
|
-
type DataFromDictionary<T extends DeclarationContent, K extends Locales> = DeepTransformContent<T['content'], K>;
|
|
29
|
-
export type UseDictionary = <T extends DeclarationContent, L extends Locales>(dictionary: T, locale?: L) => DataFromDictionary<T, L>;
|
|
30
|
-
/**
|
|
31
|
-
* Hook that picks one dictionary by its id and return the content
|
|
32
|
-
*
|
|
33
|
-
* If the locale is not provided, it will use the locale from the client context
|
|
34
|
-
*/
|
|
35
|
-
export declare const useDictionaryBase: UseDictionary;
|
|
36
|
-
export {};
|
|
37
|
-
//# sourceMappingURL=useDictionaryBase.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryBase.d.ts","sourceRoot":"","sources":["../../src/useDictionaryBase.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EACV,kBAAkB,EAElB,QAAQ,EACT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAIvD,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,MAAM,IAAI,SAAS,GAAG;IACjD,KAAK,EAAE,CAAC,CAAC;CACV,CAAC;AAEF,KAAK,iBAAiB,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,IAAI,CAAC,SAAS;IACvD,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE;QAAE,GAAG,EAAE,GAAG,CAAA;KAAE,CAAC;CACtC,GACG,CAAC,QAAQ,EAAE,MAAM,KAAK,oBAAoB,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAC3E,CAAC,SAAS;IACN,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAChC,GACD,CAAC,SAAS,MAAM,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,GACrC,oBAAoB,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GACnD,KAAK,GACP,CAAC,CAAC;AAER,MAAM,MAAM,oBAAoB,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,IAAI,CAAC,SAAS,MAAM,GACrE,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GACnB,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAC5B,CAAC,SAAS;IACN,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAAC;CAC7B,GACD,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,GACvB,CAAC,SAAS;IAAE,MAAM,EAAE,GAAG,CAAC;IAAC,GAAG,EAAE,GAAG,CAAC;IAAC,KAAK,EAAE,GAAG,CAAC;IAAC,GAAG,EAAE,GAAG,CAAA;CAAE,GACvD,SAAS,GACT;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;CAC9C,GACP,CAAC,SAAS,SAAS,GACjB,KAAK,GACL,YAAY,CAAC,CAAC,CAAC,CAAC;AAEtB;;GAEG;AACH,eAAO,MAAM,yBAAyB,UAC7B,GAAG,oCAET,MAyBF,CAAC;AAEF,KAAK,kBAAkB,CACrB,CAAC,SAAS,kBAAkB,EAC5B,CAAC,SAAS,OAAO,IACf,oBAAoB,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;AAE1C,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,SAAS,kBAAkB,EAAE,CAAC,SAAS,OAAO,EAC1E,UAAU,EAAE,CAAC,EACb,MAAM,CAAC,EAAE,CAAC,KACP,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAG9B;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,aAoB/B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayerBase.d.ts","sourceRoot":"","sources":["../../src/useIntlayerBase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAQhD,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAEjE,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,qBAAqB,CAAC;AAE7B;;;;GAIG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,SAAS,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC;AAE7D;;;;;;;;;;GAUG;AACH,MAAM,MAAM,cAAc,GAAG,cAAc,CACzC,MAAM,gCAAgC,CACvC,CAAC;AAEF;;;GAGG;AACH,KAAK,qBAAqB,CACxB,CAAC,SAAS,cAAc,EACxB,CAAC,SAAS,OAAO,IACf,oBAAoB,CAAC,gCAAgC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;AAE5E;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,SAAS,cAAc,EAAE,CAAC,SAAS,OAAO,EACpE,GAAG,EAAE,CAAC,EACN,MAAM,CAAC,EAAE,CAAC,KACP,qBAAqB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAEjC;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,WAuB7B,CAAC"}
|