@intlayer/core 5.0.6 → 5.1.0
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/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs +34 -29
- package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs +1 -1
- package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs +84 -0
- package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs.map +1 -0
- package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs +59 -0
- package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs.map +1 -0
- package/dist/cjs/dictionaryManipulator/{getSectionType.cjs → getNodeType.cjs} +25 -16
- package/dist/cjs/dictionaryManipulator/getNodeType.cjs.map +1 -0
- package/dist/cjs/dictionaryManipulator/index.cjs +9 -3
- package/dist/cjs/dictionaryManipulator/index.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs +79 -0
- package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs.map +1 -0
- package/dist/cjs/interpreter/getContent/deepTransform.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/index.cjs +0 -2
- package/dist/cjs/interpreter/getContent/index.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/plugins.cjs +3 -6
- package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
- package/dist/cjs/interpreter/getDictionary.cjs.map +1 -1
- package/dist/cjs/interpreter/getIntlayer.cjs.map +1 -1
- package/dist/cjs/interpreter/getIntlayerAsync.cjs.map +1 -1
- package/dist/cjs/interpreter/getNesting.cjs.map +1 -1
- package/dist/cjs/interpreter/index.cjs +0 -2
- package/dist/cjs/interpreter/index.cjs.map +1 -1
- package/dist/cjs/localization/getMultilingualUrls.cjs +1 -1
- package/dist/cjs/localization/getMultilingualUrls.cjs.map +1 -1
- package/dist/cjs/localization/getPathWithoutLocale.cjs +5 -1
- package/dist/cjs/localization/getPathWithoutLocale.cjs.map +1 -1
- package/dist/cjs/transpiler/enumeration/enumeration.cjs.map +1 -1
- package/dist/cjs/transpiler/nesting/nesting.cjs.map +1 -1
- package/dist/cjs/transpiler/translation/types.cjs.map +1 -1
- package/dist/cjs/types/dictionary.cjs.map +1 -1
- package/dist/cjs/types/nodeType.cjs +4 -1
- package/dist/cjs/types/nodeType.cjs.map +1 -1
- package/dist/cjs/utils/isValidReactElement.cjs.map +1 -1
- package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs +34 -29
- package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs +1 -1
- package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getDefaultNode.mjs +60 -0
- package/dist/esm/dictionaryManipulator/getDefaultNode.mjs.map +1 -0
- package/dist/esm/dictionaryManipulator/getNodeChildren.mjs +35 -0
- package/dist/esm/dictionaryManipulator/getNodeChildren.mjs.map +1 -0
- package/dist/esm/dictionaryManipulator/getNodeType.mjs +42 -0
- package/dist/esm/dictionaryManipulator/getNodeType.mjs.map +1 -0
- package/dist/esm/dictionaryManipulator/index.mjs +4 -1
- package/dist/esm/dictionaryManipulator/index.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/updateNodeChildren.mjs +55 -0
- package/dist/esm/dictionaryManipulator/updateNodeChildren.mjs.map +1 -0
- package/dist/esm/interpreter/getContent/deepTransform.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/index.mjs +0 -1
- package/dist/esm/interpreter/getContent/index.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/plugins.mjs +3 -6
- package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
- package/dist/esm/interpreter/getDictionary.mjs.map +1 -1
- package/dist/esm/interpreter/getIntlayer.mjs.map +1 -1
- package/dist/esm/interpreter/getIntlayerAsync.mjs.map +1 -1
- package/dist/esm/interpreter/getNesting.mjs.map +1 -1
- package/dist/esm/interpreter/index.mjs +0 -1
- package/dist/esm/interpreter/index.mjs.map +1 -1
- package/dist/esm/localization/getMultilingualUrls.mjs +1 -1
- package/dist/esm/localization/getMultilingualUrls.mjs.map +1 -1
- package/dist/esm/localization/getPathWithoutLocale.mjs +5 -1
- package/dist/esm/localization/getPathWithoutLocale.mjs.map +1 -1
- package/dist/esm/transpiler/enumeration/enumeration.mjs +4 -1
- package/dist/esm/transpiler/enumeration/enumeration.mjs.map +1 -1
- package/dist/esm/transpiler/nesting/nesting.mjs.map +1 -1
- package/dist/esm/types/nodeType.mjs +4 -1
- package/dist/esm/types/nodeType.mjs.map +1 -1
- package/dist/esm/utils/isValidReactElement.mjs.map +1 -1
- package/dist/types/dictionaryManipulator/editDictionaryByKeyPath.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getDefaultNode.d.ts +5 -0
- package/dist/types/dictionaryManipulator/getDefaultNode.d.ts.map +1 -0
- package/dist/types/dictionaryManipulator/getNodeChildren.d.ts +3 -0
- package/dist/types/dictionaryManipulator/getNodeChildren.d.ts.map +1 -0
- package/dist/types/dictionaryManipulator/getNodeType.d.ts +4 -0
- package/dist/types/dictionaryManipulator/getNodeType.d.ts.map +1 -0
- package/dist/types/dictionaryManipulator/index.d.ts +4 -1
- package/dist/types/dictionaryManipulator/index.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/updateNodeChildren.d.ts +3 -0
- package/dist/types/dictionaryManipulator/updateNodeChildren.d.ts.map +1 -0
- package/dist/types/interpreter/getContent/deepTransform.d.ts +1 -1
- package/dist/types/interpreter/getContent/deepTransform.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/index.d.ts +0 -1
- package/dist/types/interpreter/getContent/index.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
- package/dist/types/interpreter/getDictionary.d.ts.map +1 -1
- package/dist/types/interpreter/getIntlayer.d.ts +1 -1
- package/dist/types/interpreter/getIntlayer.d.ts.map +1 -1
- package/dist/types/interpreter/getIntlayerAsync.d.ts.map +1 -1
- package/dist/types/interpreter/getNesting.d.ts +1 -1
- package/dist/types/interpreter/getNesting.d.ts.map +1 -1
- package/dist/types/interpreter/index.d.ts +0 -1
- package/dist/types/interpreter/index.d.ts.map +1 -1
- package/dist/types/localization/getPathWithoutLocale.d.ts.map +1 -1
- package/dist/types/transpiler/enumeration/enumeration.d.ts +1 -1
- package/dist/types/transpiler/enumeration/enumeration.d.ts.map +1 -1
- package/dist/types/transpiler/nesting/nesting.d.ts +1 -1
- package/dist/types/transpiler/nesting/nesting.d.ts.map +1 -1
- package/dist/types/transpiler/translation/translation.d.ts +1 -1
- package/dist/types/transpiler/translation/translation.d.ts.map +1 -1
- package/dist/types/transpiler/translation/types.d.ts +1 -1
- package/dist/types/transpiler/translation/types.d.ts.map +1 -1
- package/dist/types/types/dictionary.d.ts +3 -2
- package/dist/types/types/dictionary.d.ts.map +1 -1
- package/dist/types/types/nodeType.d.ts +5 -2
- package/dist/types/types/nodeType.d.ts.map +1 -1
- package/dist/types/utils/isValidReactElement.d.ts.map +1 -1
- package/package.json +14 -14
- package/dist/cjs/dictionaryManipulator/getSectionType.cjs.map +0 -1
- package/dist/esm/dictionaryManipulator/getSectionType.mjs +0 -33
- package/dist/esm/dictionaryManipulator/getSectionType.mjs.map +0 -1
- package/dist/types/dictionaryManipulator/getSectionType.d.ts +0 -4
- package/dist/types/dictionaryManipulator/getSectionType.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/interpreter/getDictionary.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/interpreter/getDictionary.ts"],"sourcesContent":["import type { Locales, LocalesValues } from '@intlayer/config/client';\nimport type { Dictionary } from '../types';\nimport type { Plugins, NodeProps, DeepTransformContent } from './getContent';\nimport { getContent } from './getContent/getContent';\n\n/**\n * Transforms a dictionary in a single pass, applying each plugin as needed.\n *\n * @param dictionary The dictionary to transform.\n * @param locale The locale to use if your transformers need it (e.g. for translations).\n * @param additionalPlugins An array of NodeTransformer that define how to transform recognized nodes.\n * If omitted, we’ll use a default set of plugins.\n */\nexport const getDictionary = <\n T extends Dictionary,\n L extends LocalesValues = Locales,\n>(\n dictionary: T,\n locale?: L,\n plugins?: Plugins[]\n) => {\n const props: NodeProps = {\n dictionaryKey: dictionary.key,\n dictionaryPath: dictionary.filePath,\n keyPath: [],\n plugins,\n };\n\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n return getContent(\n dictionary.content,\n props,\n locale\n ) as any as DeepTransformContent<T['content']>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAA2B;AAUpB,MAAM,gBAAgB,CAI3B,YACA,QACA,YACG;AACH,QAAM,QAAmB;AAAA,IACvB,eAAe,WAAW;AAAA,IAC1B,gBAAgB,WAAW;AAAA,IAC3B,SAAS,CAAC;AAAA,IACV;AAAA,EACF;AAGA,aAAO;AAAA,IACL,WAAW;AAAA,IACX;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/interpreter/getIntlayer.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/interpreter/getIntlayer.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\n// @ts-ignore intlayer declared for module augmentation\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport type { Dictionary, DictionaryKeys } from '../types';\nimport type { DeepTransformContent, Plugins } from './getContent/plugins';\nimport { getDictionary } from './getDictionary';\n\nexport const getIntlayer = <T extends DictionaryKeys, L extends LocalesValues>(\n key: T,\n locale?: L,\n plugins?: Plugins[]\n) => {\n const dictionary = dictionaries[key as T];\n\n if (!dictionary) {\n throw new Error(`Dictionary ${key as string} not found`, dictionaries);\n }\n\n return getDictionary(\n dictionary as Dictionary,\n locale,\n plugins\n ) as any as DeepTransformContent<\n IntlayerDictionaryTypesConnector[T]['content']\n >;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,gCAAyB;AAKzB,2BAA8B;AAEvB,MAAM,cAAc,CACzB,KACA,QACA,YACG;AACH,QAAM,aAAa,0BAAAA,QAAa,GAAQ;AAExC,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,MAAM,cAAc,GAAa,cAAc,0BAAAA,OAAY;AAAA,EACvE;AAEA,aAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAGF;","names":["dictionaries"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/interpreter/getIntlayerAsync.ts"],"sourcesContent":["import { fetchDistantDictionary } from '@intlayer/api';\nimport type { LocalesValues } from '@intlayer/config/client';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/interpreter/getIntlayerAsync.ts"],"sourcesContent":["import { fetchDistantDictionary } from '@intlayer/api';\nimport type { LocalesValues } from '@intlayer/config/client';\nimport type { DictionaryKeys } from '../types';\nimport type { Plugins } from './getContent';\nimport { getDictionary } from './getDictionary';\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 getIntlayerAsync = async <\n T extends DictionaryKeys,\n L extends LocalesValues,\n>(\n key: T,\n locale?: L,\n plugins?: Plugins[]\n) => {\n const jsonDistantDictionary = await fetchDistantDictionary(key as string);\n\n if (jsonDistantDictionary) {\n return getDictionary(jsonDistantDictionary, locale, plugins);\n }\n\n return null;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAuC;AAIvC,2BAA8B;AAUvB,MAAM,mBAAmB,OAI9B,KACA,QACA,YACG;AACH,QAAM,wBAAwB,UAAM,mCAAuB,GAAa;AAExE,MAAI,uBAAuB;AACzB,eAAO,oCAAc,uBAAuB,QAAQ,OAAO;AAAA,EAC7D;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/interpreter/getNesting.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/interpreter/getNesting.ts"],"sourcesContent":["// @ts-ignore intlayer declared for module augmentation\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport type { ValidDotPathsFor } from '../transpiler';\nimport type { DictionaryKeys } from '../types';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n NodeProps,\n} from './getContent';\nimport { getIntlayer } from './getIntlayer';\n\ntype GetSubPath<T, P> = P extends `${infer K}.${infer Rest}`\n ? K extends keyof T\n ? GetSubPath<T[K], Rest>\n : never\n : P extends keyof T\n ? T[P]\n : T;\n\nexport type GetNestingResult<\n K extends DictionaryKeys,\n P = undefined,\n S = IInterpreterPluginState,\n> = GetSubPath<\n DeepTransformContent<IntlayerDictionaryTypesConnector[K]['content'], S>,\n P\n>;\n\n/**\n * Allow to extract the content of another dictionary.\n *\n * Usage:\n * ```ts\n * const content = getNesting(\"dictionaryKey\", \"path.to.content\");\n * // 'Example content'\n * ```\n */\nexport const getNesting = <K extends DictionaryKeys, P>(\n dictionaryKey: K,\n path?: P extends ValidDotPathsFor<K> ? P : never,\n props?: NodeProps\n): GetNestingResult<K, P> => {\n const dictionary = getIntlayer(dictionaryKey, props?.locale, props?.plugins);\n\n if (typeof path === 'string') {\n const pathArray = (path as string).split('.');\n let current: any = dictionary;\n\n for (const key of pathArray) {\n // Safely traverse down the object using the path\n current = current?.[key];\n // If we cannot find the path, return the whole dictionary as a fallback\n if (current === undefined) {\n return dictionary as any;\n }\n }\n\n return current;\n }\n\n // Default or error handling if path is not a string or otherwise undefined\n return dictionary as any;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,yBAA4B;AA4BrB,MAAM,aAAa,CACxB,eACA,MACA,UAC2B;AAC3B,QAAM,iBAAa,gCAAY,eAAe,OAAO,QAAQ,OAAO,OAAO;AAE3E,MAAI,OAAO,SAAS,UAAU;AAC5B,UAAM,YAAa,KAAgB,MAAM,GAAG;AAC5C,QAAI,UAAe;AAEnB,eAAW,OAAO,WAAW;AAE3B,gBAAU,UAAU,GAAG;AAEvB,UAAI,YAAY,QAAW;AACzB,eAAO;AAAA,MACT;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAGA,SAAO;AACT;","names":[]}
|
|
@@ -18,7 +18,6 @@ module.exports = __toCommonJS(interpreter_exports);
|
|
|
18
18
|
__reExport(interpreter_exports, require('./getContent/index.cjs'), module.exports);
|
|
19
19
|
__reExport(interpreter_exports, require('./getNesting.cjs'), module.exports);
|
|
20
20
|
__reExport(interpreter_exports, require('./getEnumeration.cjs'), module.exports);
|
|
21
|
-
__reExport(interpreter_exports, require('./getEnumeration.cjs'), module.exports);
|
|
22
21
|
__reExport(interpreter_exports, require('./getIntlayer.cjs'), module.exports);
|
|
23
22
|
__reExport(interpreter_exports, require('./getDictionary.cjs'), module.exports);
|
|
24
23
|
__reExport(interpreter_exports, require('./getIntlayerAsync.cjs'), module.exports);
|
|
@@ -29,7 +28,6 @@ __reExport(interpreter_exports, require('./getCondition.cjs'), module.exports);
|
|
|
29
28
|
...require('./getContent/index.cjs'),
|
|
30
29
|
...require('./getNesting.cjs'),
|
|
31
30
|
...require('./getEnumeration.cjs'),
|
|
32
|
-
...require('./getEnumeration.cjs'),
|
|
33
31
|
...require('./getIntlayer.cjs'),
|
|
34
32
|
...require('./getDictionary.cjs'),
|
|
35
33
|
...require('./getIntlayerAsync.cjs'),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/interpreter/index.ts"],"sourcesContent":["export * from './getContent/index';\nexport * from './getNesting';\nexport * from './getEnumeration';\nexport * from './
|
|
1
|
+
{"version":3,"sources":["../../../src/interpreter/index.ts"],"sourcesContent":["export * from './getContent/index';\nexport * from './getNesting';\nexport * from './getEnumeration';\nexport * from './getIntlayer';\nexport * from './getDictionary';\nexport * from './getIntlayerAsync';\nexport * from './getTranslation';\nexport * from './getCondition';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,gCAAc,+BAAd;AACA,gCAAc,yBADd;AAEA,gCAAc,6BAFd;AAGA,gCAAc,0BAHd;AAIA,gCAAc,4BAJd;AAKA,gCAAc,+BALd;AAMA,gCAAc,6BANd;AAOA,gCAAc,2BAPd;","names":[]}
|
|
@@ -22,8 +22,8 @@ __export(getMultilingualUrls_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(getMultilingualUrls_exports);
|
|
24
24
|
var import_client = require("@intlayer/config/client");
|
|
25
|
-
var import_getPathWithoutLocale = require('./getPathWithoutLocale.cjs');
|
|
26
25
|
var import_checkIsURLAbsolute = require('../utils/checkIsURLAbsolute.cjs');
|
|
26
|
+
var import_getPathWithoutLocale = require('./getPathWithoutLocale.cjs');
|
|
27
27
|
const { internationalization, middleware } = (0, import_client.getConfiguration)();
|
|
28
28
|
const { locales: localesDefault, defaultLocale: defaultLocaleDefault } = internationalization;
|
|
29
29
|
const { prefixDefault: prefixDefaultDefault } = middleware;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/localization/getMultilingualUrls.ts"],"sourcesContent":["import { getConfiguration, type LocalesValues } from '@intlayer/config/client';\n// @ts-ignore intlayer declared for module augmentation\nimport type { IConfigLocales } from 'intlayer';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/localization/getMultilingualUrls.ts"],"sourcesContent":["import { getConfiguration, type LocalesValues } from '@intlayer/config/client';\n// @ts-ignore intlayer declared for module augmentation\nimport type { IConfigLocales } from 'intlayer';\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\nimport { getPathWithoutLocale } from './getPathWithoutLocale';\n\n// Destructure necessary configurations\nconst { internationalization, middleware } = getConfiguration();\nconst { locales: localesDefault, defaultLocale: defaultLocaleDefault } =\n internationalization;\nconst { prefixDefault: prefixDefaultDefault } = middleware;\n\n/**\n * Generates multilingual URLs by prefixing the given URL with each supported locale.\n * Handles both absolute and relative URLs appropriately.\n *\n * This function get the locales, default locale, and prefix default from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', false)\n * // Returns { en: '/dashboard', fr: '/fr/dashboard' }\n * getMultilingualUrls('https://example.com/dashboard', ['en', 'fr'], 'en', true)\n * // Returns { en: 'https://example.com/en/dashboard', fr: 'https://example.com/fr/dashboard' }\n * ```\n *\n * @param url - The original URL string to be prefixed with locales.\n * @param locales - Optional array of supported locales. Defaults to `localesDefault`.\n * @param defaultLocale - The default locale. Defaults to `defaultLocaleDefault`.\n * @param prefixDefault - Whether to prefix the default locale. Defaults to `prefixDefaultDefault`.\n * @returns An object mapping each locale to its corresponding multilingual URL.\n */\nexport const getMultilingualUrls = (\n url: string,\n locales: LocalesValues[] = localesDefault,\n defaultLocale: LocalesValues = defaultLocaleDefault,\n prefixDefault: boolean = prefixDefaultDefault\n): IConfigLocales<string> => {\n // Remove any existing locale segment from the URL\n const urlWithoutLocale = getPathWithoutLocale(url, locales);\n\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(urlWithoutLocale);\n\n // Initialize a URL object if the URL is absolute\n // For relative URLs, use a dummy base to leverage the URL API\n const parsedUrl = isAbsoluteUrl\n ? new URL(urlWithoutLocale)\n : new URL(urlWithoutLocale, 'http://example.com');\n\n // Extract the pathname from the parsed URL\n let pathname = parsedUrl.pathname;\n\n // Ensure the pathname starts with a '/'\n if (!pathname.startsWith('/')) {\n pathname = `/${pathname}`;\n }\n\n // Prepare the base URL (protocol + host) if it's absolute\n const baseUrl = isAbsoluteUrl\n ? `${parsedUrl.protocol}//${parsedUrl.host}`\n : '';\n\n // Generate multilingual URLs by iterating over each locale\n const multilingualUrls = locales.reduce<IConfigLocales<string>>(\n (acc, locale) => {\n // Determine if the current locale is the default locale\n const isDefaultLocale = locale.toString() === defaultLocale.toString();\n\n // Decide whether to prefix the default locale based on `prefixDefault`\n const shouldPrefix = prefixDefault || !isDefaultLocale;\n\n // Construct the new pathname with or without the locale prefix\n let localizedPath = shouldPrefix ? `/${locale}${pathname}` : pathname;\n\n if (localizedPath.length > 1 && localizedPath.endsWith('/')) {\n localizedPath = localizedPath.slice(0, -1);\n }\n\n // Combine with the base URL if the original URL was absolute\n const localizedUrl = isAbsoluteUrl\n ? `${baseUrl}${localizedPath}${parsedUrl.search}${parsedUrl.hash}`\n : `${localizedPath}${parsedUrl.search}${parsedUrl.hash}`;\n\n // Assign the constructed URL to the corresponding locale key\n acc[locale as unknown as keyof typeof acc] = localizedUrl;\n\n return acc;\n },\n {} as IConfigLocales<string> // Initialize an empty object\n );\n\n return multilingualUrls;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAqD;AAGrD,gCAAmC;AACnC,kCAAqC;AAGrC,MAAM,EAAE,sBAAsB,WAAW,QAAI,gCAAiB;AAC9D,MAAM,EAAE,SAAS,gBAAgB,eAAe,qBAAqB,IACnE;AACF,MAAM,EAAE,eAAe,qBAAqB,IAAI;AAuBzC,MAAM,sBAAsB,CACjC,KACA,UAA2B,gBAC3B,gBAA+B,sBAC/B,gBAAyB,yBACE;AAE3B,QAAM,uBAAmB,kDAAqB,KAAK,OAAO;AAG1D,QAAM,oBAAgB,8CAAmB,gBAAgB;AAIzD,QAAM,YAAY,gBACd,IAAI,IAAI,gBAAgB,IACxB,IAAI,IAAI,kBAAkB,oBAAoB;AAGlD,MAAI,WAAW,UAAU;AAGzB,MAAI,CAAC,SAAS,WAAW,GAAG,GAAG;AAC7B,eAAW,IAAI,QAAQ;AAAA,EACzB;AAGA,QAAM,UAAU,gBACZ,GAAG,UAAU,QAAQ,KAAK,UAAU,IAAI,KACxC;AAGJ,QAAM,mBAAmB,QAAQ;AAAA,IAC/B,CAAC,KAAK,WAAW;AAEf,YAAM,kBAAkB,OAAO,SAAS,MAAM,cAAc,SAAS;AAGrE,YAAM,eAAe,iBAAiB,CAAC;AAGvC,UAAI,gBAAgB,eAAe,IAAI,MAAM,GAAG,QAAQ,KAAK;AAE7D,UAAI,cAAc,SAAS,KAAK,cAAc,SAAS,GAAG,GAAG;AAC3D,wBAAgB,cAAc,MAAM,GAAG,EAAE;AAAA,MAC3C;AAGA,YAAM,eAAe,gBACjB,GAAG,OAAO,GAAG,aAAa,GAAG,UAAU,MAAM,GAAG,UAAU,IAAI,KAC9D,GAAG,aAAa,GAAG,UAAU,MAAM,GAAG,UAAU,IAAI;AAGxD,UAAI,MAAqC,IAAI;AAE7C,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA;AAAA,EACH;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -27,7 +27,11 @@ const { internationalization } = (0, import_client.getConfiguration)();
|
|
|
27
27
|
const { locales: localesDefault } = internationalization;
|
|
28
28
|
const getPathWithoutLocale = (inputUrl, locales = localesDefault) => {
|
|
29
29
|
const isAbsoluteUrl = (0, import_checkIsURLAbsolute.checkIsURLAbsolute)(inputUrl);
|
|
30
|
-
|
|
30
|
+
let fixedInputUrl = inputUrl;
|
|
31
|
+
if (inputUrl.endsWith("/")) {
|
|
32
|
+
fixedInputUrl = inputUrl.slice(0, -1);
|
|
33
|
+
}
|
|
34
|
+
const url = isAbsoluteUrl ? new URL(fixedInputUrl) : new URL(fixedInputUrl, "http://example.com");
|
|
31
35
|
const pathname = url.pathname;
|
|
32
36
|
if (!pathname.startsWith("/")) {
|
|
33
37
|
url.pathname = `/${pathname}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/localization/getPathWithoutLocale.ts"],"sourcesContent":["import {\n getConfiguration,\n type Locales,\n type LocalesValues,\n} from '@intlayer/config/client';\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\n\nconst { internationalization } = getConfiguration();\nconst { locales: localesDefault } = internationalization;\n\n/**\n * Removes the locale segment from the given URL or pathname if present.\n *\n * This function get the locales from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * getPathWithoutLocale('/en/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/fr/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('dashboard') // Returns 'dashboard'\n * getPathWithoutLocale('https://example.com/en/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/fr/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/dashboard') // Returns 'https://example.com/dashboard'\n * ```\n *\n * @param inputUrl - The complete URL string or pathname to process.\n * @param locales - Optional array of supported locales. Defaults to `localesDefault`.\n * @returns The URL string or pathname without the locale segment.\n */\nexport const getPathWithoutLocale = (\n inputUrl: string,\n locales: LocalesValues[] = localesDefault\n): string => {\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);\n\n // Initialize a URL object if the URL is absolute\n // For relative URLs, use a dummy base to leverage the URL API\n const url = isAbsoluteUrl\n ? new URL(
|
|
1
|
+
{"version":3,"sources":["../../../src/localization/getPathWithoutLocale.ts"],"sourcesContent":["import {\n getConfiguration,\n type Locales,\n type LocalesValues,\n} from '@intlayer/config/client';\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\n\nconst { internationalization } = getConfiguration();\nconst { locales: localesDefault } = internationalization;\n\n/**\n * Removes the locale segment from the given URL or pathname if present.\n *\n * This function get the locales from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * getPathWithoutLocale('/en/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/fr/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('dashboard') // Returns 'dashboard'\n * getPathWithoutLocale('https://example.com/en/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/fr/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/dashboard') // Returns 'https://example.com/dashboard'\n * ```\n *\n * @param inputUrl - The complete URL string or pathname to process.\n * @param locales - Optional array of supported locales. Defaults to `localesDefault`.\n * @returns The URL string or pathname without the locale segment.\n */\nexport const getPathWithoutLocale = (\n inputUrl: string,\n locales: LocalesValues[] = localesDefault\n): string => {\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);\n\n let fixedInputUrl = inputUrl;\n\n if (inputUrl.endsWith('/')) {\n fixedInputUrl = inputUrl.slice(0, -1);\n }\n\n // Initialize a URL object if the URL is absolute\n // For relative URLs, use a dummy base to leverage the URL API\n const url = isAbsoluteUrl\n ? new URL(fixedInputUrl)\n : new URL(fixedInputUrl, 'http://example.com');\n\n const pathname = url.pathname;\n\n // Ensure the pathname starts with '/'\n if (!pathname.startsWith('/')) {\n // If not, return the URL as is\n url.pathname = `/${pathname}`;\n }\n\n // Split the pathname to extract the first segment\n const pathSegments = pathname.split('/');\n const firstSegment = pathSegments[1]; // The segment after the first '/'\n\n // Check if the first segment is a supported locale\n if (locales.includes(firstSegment as Locales)) {\n // Remove the locale segment from the pathname\n pathSegments.splice(1, 1); // Remove the first segment\n\n // Reconstruct the pathname\n const newPathname = pathSegments.join('/') ?? '/';\n url.pathname = newPathname;\n }\n\n if (isAbsoluteUrl) {\n // Return the modified URL as a string\n return url.toString();\n }\n\n // Return the modified URL as a string\n return url.toString().replace('http://example.com', '');\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAIO;AACP,gCAAmC;AAEnC,MAAM,EAAE,qBAAqB,QAAI,gCAAiB;AAClD,MAAM,EAAE,SAAS,eAAe,IAAI;AAuB7B,MAAM,uBAAuB,CAClC,UACA,UAA2B,mBAChB;AAEX,QAAM,oBAAgB,8CAAmB,QAAQ;AAEjD,MAAI,gBAAgB;AAEpB,MAAI,SAAS,SAAS,GAAG,GAAG;AAC1B,oBAAgB,SAAS,MAAM,GAAG,EAAE;AAAA,EACtC;AAIA,QAAM,MAAM,gBACR,IAAI,IAAI,aAAa,IACrB,IAAI,IAAI,eAAe,oBAAoB;AAE/C,QAAM,WAAW,IAAI;AAGrB,MAAI,CAAC,SAAS,WAAW,GAAG,GAAG;AAE7B,QAAI,WAAW,IAAI,QAAQ;AAAA,EAC7B;AAGA,QAAM,eAAe,SAAS,MAAM,GAAG;AACvC,QAAM,eAAe,aAAa,CAAC;AAGnC,MAAI,QAAQ,SAAS,YAAuB,GAAG;AAE7C,iBAAa,OAAO,GAAG,CAAC;AAGxB,UAAM,cAAc,aAAa,KAAK,GAAG,KAAK;AAC9C,QAAI,WAAW;AAAA,EACjB;AAEA,MAAI,eAAe;AAEjB,WAAO,IAAI,SAAS;AAAA,EACtB;AAGA,SAAO,IAAI,SAAS,EAAE,QAAQ,sBAAsB,EAAE;AACxD;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/enumeration/enumeration.ts"],"sourcesContent":["import { formatNodeType
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/enumeration/enumeration.ts"],"sourcesContent":["import {\n type TypedNodeModel,\n formatNodeType,\n NodeType,\n} from '../../types/index';\n\ntype Positif = number | `${number}`;\ntype Negatif = `-${number}`;\ntype Numbers = Positif | Negatif;\n\ntype Equal = Numbers;\ntype EqualString = `=${Numbers}`;\ntype Superior = `>${Numbers}`;\ntype SuperiorOrEqual = `>=${Numbers}`;\ntype Inferior = `<${Numbers}`;\ntype InferiorOrEqual = `<=${Numbers}`;\n\nexport type EnterFormat =\n | Equal\n | EqualString\n | Superior\n | SuperiorOrEqual\n | Inferior\n | InferiorOrEqual;\n\nexport type EnumerationContentState<Content> = Partial<\n Record<EnterFormat, Content>\n> & {\n fallback?: Content;\n};\n\nexport type EnumerationContent<Content = unknown> = TypedNodeModel<\n NodeType.Enumeration,\n EnumerationContentState<Content>\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to pick a content based on a quantity.\n *\n * Usage:\n *\n * ```ts\n * enu({\n * '<=-2.3': 'You have less than -2.3',\n * '<1': 'You have less than one',\n * '2': 'You have two',\n * '>=3': 'You have three or more',\n * });\n * ```\n *\n * > The order of the keys will define the priority of the content.\n *\n */\nconst enumeration = <Content>(content?: EnumerationContentState<Content>) =>\n formatNodeType(NodeType.Enumeration, content);\n\nexport { enumeration as enu };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAIO;AAmDP,MAAM,cAAc,CAAU,gBAC5B,6BAAe,sBAAS,aAAa,OAAO;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/nesting/nesting.ts"],"sourcesContent":["// @ts-ignore intlayer declared for module augmentation\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport type { DictionaryKeys } from '../../types/dictionary';\nimport {\n formatNodeType,\n NodeType,\n type TypedNodeModel,\n} from '../../types/index';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/nesting/nesting.ts"],"sourcesContent":["// @ts-ignore intlayer declared for module augmentation\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport type { DeepTransformContent } from '../../interpreter';\nimport type { DictionaryKeys } from '../../types/dictionary';\nimport {\n formatNodeType,\n NodeType,\n type TypedNodeModel,\n} from '../../types/index';\n\n/**\n * Recursively builds dot-notation strings for all valid paths in T.\n * Example:\n * type X = { a: { b: { c: string }}, d: number };\n * DotPath<X> = \"a\" | \"a.b\" | \"a.b.c\" | \"d\"\n */\nexport type DotPath<T> = T extends object\n ? {\n [K in keyof T & (string | number)]: T[K] extends object\n ? // Either just K, or K + '.' + deeper path\n `${K}` | `${K}.${DotPath<T[K]>}`\n : `${K}`;\n }[keyof T & (string | number)]\n : never;\n\ntype DeepReplace<T, From, To> = T extends From\n ? To\n : T extends object\n ? { [K in keyof T]: DeepReplace<T[K], From, To> }\n : T;\n\n/** Build all valid dot-notation strings for a dictionary entry. */\nexport type ValidDotPathsFor<K extends DictionaryKeys> = DotPath<\n DeepReplace<\n DeepTransformContent<IntlayerDictionaryTypesConnector[K]['content']>,\n // Replace ReactElement type with string\n {\n type: any;\n props: any;\n key: any;\n },\n string\n >\n>;\n\nexport type NestedContentState<K extends DictionaryKeys> = {\n dictionaryKey: K;\n\n /**\n * Path must match existing keys in IntlayerDictionaryTypesConnector[K].\n * Can be either:\n * - \"dot.dot.dot\" format\n */\n path?: ValidDotPathsFor<K>;\n};\n\nexport type NestedContent<K extends DictionaryKeys = never> = TypedNodeModel<\n NodeType.Nested,\n NestedContentState<K>\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to extract the content of another dictionary and nest it in the current dictionary.\n *\n * Usage:\n *\n * ```ts\n * nest(\"dictionaryKey\");\n * nest(\"dictionaryKey\", \"path.to.content\");\n * ```\n *\n * The order of the keys will define the priority of the content.\n *\n */\nconst nesting = <K extends DictionaryKeys>(\n dictionaryKey: K,\n path?: ValidDotPathsFor<K>\n): NestedContent<K> =>\n formatNodeType(NodeType.Nested, {\n dictionaryKey,\n path,\n });\n\nexport { nesting as nest };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,mBAIO;AAoEP,MAAM,UAAU,CACd,eACA,aAEA,6BAAe,sBAAS,QAAQ;AAAA,EAC9B;AAAA,EACA;AACF,CAAC;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/translation/types.ts"],"sourcesContent":["/** @ts-nocheck */\n\nimport type { LocalesValues } from '@intlayer/config/client';\n// @ts-ignore intlayer declared for module augmentation\nimport type { IConfigLocales } from 'intlayer';\nimport { NodeType, TypedNodeModel } from '../../types/index';\n\n/**\n * If module augmented, it will return the configured locales such as Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH | ...\n * If not, it will return never\n */\nexport type ConfigLocales = keyof IConfigLocales<unknown>;\n\n/**\n * Record of locales and content\n *\n * const myVar1: TranslationContentState<string> = {\n * \"en\": \"\",\n * \"fr\": \"\"\n * }\n *\n * const myVar2: TranslationContentState<{age: number, name: string}> = {\n * \"en\": {age: 1, name: \"test\"},\n * \"fr\": {age: 1, name: \"test\"}\n * }\n */\nexport type TranslationContentState<Content = unknown> = {\n [locale in LocalesValues]?: Content;\n};\n\nexport type LanguageContent<Content = unknown> =\n keyof IConfigLocales<unknown> extends never\n ? TranslationContentState<Content> // Fall including all locales as optional\n : IConfigLocales<Content>;\n\nexport type TranslationContent<\n Content = unknown,\n RecordContent extends LanguageContent<Content> = LanguageContent<Content>,\n> = TypedNodeModel<NodeType.Translation, RecordContent>;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/translation/types.ts"],"sourcesContent":["/** @ts-nocheck */\n\nimport type { LocalesValues } from '@intlayer/config/client';\n// @ts-ignore intlayer declared for module augmentation\nimport type { IConfigLocales } from 'intlayer';\nimport type { NodeType, TypedNodeModel } from '../../types/index';\n\n/**\n * If module augmented, it will return the configured locales such as Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH | ...\n * If not, it will return never\n */\nexport type ConfigLocales = keyof IConfigLocales<unknown>;\n\n/**\n * Record of locales and content\n *\n * const myVar1: TranslationContentState<string> = {\n * \"en\": \"\",\n * \"fr\": \"\"\n * }\n *\n * const myVar2: TranslationContentState<{age: number, name: string}> = {\n * \"en\": {age: 1, name: \"test\"},\n * \"fr\": {age: 1, name: \"test\"}\n * }\n */\nexport type TranslationContentState<Content = unknown> = {\n [locale in LocalesValues]?: Content;\n};\n\nexport type LanguageContent<Content = unknown> =\n keyof IConfigLocales<unknown> extends never\n ? TranslationContentState<Content> // Fall including all locales as optional\n : IConfigLocales<Content>;\n\nexport type TranslationContent<\n Content = unknown,\n RecordContent extends LanguageContent<Content> = LanguageContent<Content>,\n> = TypedNodeModel<NodeType.Translation, RecordContent>;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/dictionary.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/types/dictionary.ts"],"sourcesContent":["// @ts-ignore intlayer declared for module augmentation\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport type {\n ConditionContent,\n EnumerationContent,\n MarkdownContent,\n NestedContent,\n TranslationContent,\n} from '../transpiler/index';\n\n/**\n * Provides a fallback to string type if the generic type T is undefined,\n * otherwise returns T. This is useful for handling cases where no keys are found.\n * Example: StringFallback<undefined> -> string; StringFallback<'key'> -> 'key'\n */\nexport type StringFallback<T> = T extends undefined ? 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\ntype BaseNode = number | string | boolean | null | undefined;\n\nexport type TypedNode<NodeType = undefined> =\n | TranslationContent<NodeType>\n | EnumerationContent<NodeType>\n | ConditionContent<NodeType>\n | MarkdownContent\n | NestedContent<DictionaryKeys>;\n\ntype FetchableContentNode<NodeType> = (\n args?: any\n) => ContentNode<NodeType> | Promise<ContentNode<NodeType>>;\n\nexport type ContentNode<\n T = undefined,\n FetchableNode = false,\n NodeType = T extends undefined ? BaseNode : T,\n> =\n | NodeType\n | TypedNode<NodeType>\n | ((args?: any) => ContentNode<NodeType>)\n | (FetchableNode extends true ? FetchableContentNode<NodeType> : undefined);\n\n// Utility types (unchanged)\ntype IsArray<T> = T extends any[] ? true : false;\n\ntype ReplaceContentValueArray<T, FetchableNode> = T extends (infer U)[]\n ? // Allow either a *single* typed node returning the entire array\n // or an array of typed nodes (or scalar nodes).\n ContentNode<T, FetchableNode> | ReplaceContentValue<U, FetchableNode>[]\n : never;\n\ntype ReplaceContentValueObject<T, FetchableNode> = {\n [K in keyof T]: ReplaceContentValue<T[K], FetchableNode>;\n};\n\n// Modified: allow a full ContentNode wrapper OR an object shape when T is an object\ntype ReplaceContentValue<\n NodeType,\n FetchableNode = true,\n> = NodeType extends object\n ? IsArray<NodeType> extends true\n ? ReplaceContentValueArray<NodeType, FetchableNode>\n :\n | ContentNode<NodeType, FetchableNode>\n | ReplaceContentValueObject<NodeType, FetchableNode>\n : ContentNode<NodeType, FetchableNode>;\n\nexport type Dictionary<ContentType = undefined, FetchableNode = false> = {\n $schema?: string;\n key: string;\n title?: string;\n description?: string;\n availableVersions?: string[];\n version?: string;\n filePath?: string;\n tags?: string[];\n content: ContentType extends undefined // Applying the generic to replace ContentValue with Replacement\n ? any\n : ReplaceContentValue<ContentType, FetchableNode> | ContentType;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -28,10 +28,13 @@ var NodeType = /* @__PURE__ */ ((NodeType2) => {
|
|
|
28
28
|
NodeType2["Condition"] = "condition";
|
|
29
29
|
NodeType2["Object"] = "object";
|
|
30
30
|
NodeType2["Array"] = "array";
|
|
31
|
-
NodeType2["Text"] = "text";
|
|
32
31
|
NodeType2["Nested"] = "nested";
|
|
33
32
|
NodeType2["ReactNode"] = "reactNode";
|
|
34
33
|
NodeType2["Markdown"] = "markdown";
|
|
34
|
+
NodeType2["Text"] = "text";
|
|
35
|
+
NodeType2["Number"] = "number";
|
|
36
|
+
NodeType2["Boolean"] = "boolean";
|
|
37
|
+
NodeType2["Unknown"] = "unknown";
|
|
35
38
|
return NodeType2;
|
|
36
39
|
})(NodeType || {});
|
|
37
40
|
const formatNodeType = (nodeType, content) => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/nodeType.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/types/nodeType.ts"],"sourcesContent":["export enum NodeType {\n Translation = 'translation',\n Enumeration = 'enumeration',\n Condition = 'condition',\n Object = 'object',\n Array = 'array',\n Nested = 'nested',\n ReactNode = 'reactNode',\n Markdown = 'markdown',\n Text = 'text',\n Number = 'number',\n Boolean = 'boolean',\n Unknown = 'unknown',\n}\n\nexport type TypedNodeModel<T extends NodeType, Content> = {\n nodeType: T | `${T}`;\n} & {\n [K in T]: Content;\n};\n\nexport const formatNodeType = <T extends NodeType, Content = any>(\n nodeType: T | `${T}`,\n content: Content\n) =>\n ({\n nodeType,\n [nodeType]: content,\n }) as TypedNodeModel<T, Content>;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAK,WAAL,kBAAKA,cAAL;AACL,EAAAA,UAAA,iBAAc;AACd,EAAAA,UAAA,iBAAc;AACd,EAAAA,UAAA,eAAY;AACZ,EAAAA,UAAA,YAAS;AACT,EAAAA,UAAA,WAAQ;AACR,EAAAA,UAAA,YAAS;AACT,EAAAA,UAAA,eAAY;AACZ,EAAAA,UAAA,cAAW;AACX,EAAAA,UAAA,UAAO;AACP,EAAAA,UAAA,YAAS;AACT,EAAAA,UAAA,aAAU;AACV,EAAAA,UAAA,aAAU;AAZA,SAAAA;AAAA,GAAA;AAqBL,MAAM,iBAAiB,CAC5B,UACA,aAEC;AAAA,EACC;AAAA,EACA,CAAC,QAAQ,GAAG;AACd;","names":["NodeType"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/isValidReactElement.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/isValidReactElement.ts"],"sourcesContent":["const REACT_ELEMENT_TYPE = Symbol.for('react.element');\n\n/**\n * Verifies the object is a ReactElement.\n * See https://reactjs.org/docs/react-api.html#isvalidelement\n * @param object\n * @return True if `object` is a ReactElement.\n * @final\n */\n\nexport const isValidElement = (object: any): boolean =>\n typeof object === 'object' &&\n object !== null &&\n object.$$typeof === REACT_ELEMENT_TYPE;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAAM,qBAAqB,OAAO,IAAI,eAAe;AAU9C,MAAM,iBAAiB,CAAC,WAC7B,OAAO,WAAW,YAClB,WAAW,QACX,OAAO,aAAa;","names":[]}
|
|
@@ -3,65 +3,70 @@ const editDictionaryByKeyPath = (dictionaryContent, keyPath, newValue) => {
|
|
|
3
3
|
let currentValue = dictionaryContent;
|
|
4
4
|
let parentValue = null;
|
|
5
5
|
let lastKeys = [];
|
|
6
|
-
for (
|
|
6
|
+
for (let i = 0; i < keyPath.length; i++) {
|
|
7
|
+
const keyObj = keyPath[i];
|
|
7
8
|
parentValue = currentValue;
|
|
8
9
|
if (keyObj.type === NodeType.Object) {
|
|
9
10
|
lastKeys = [keyObj.key];
|
|
10
|
-
if (!currentValue[keyObj.key]) {
|
|
11
|
-
currentValue = {
|
|
12
|
-
...currentValue,
|
|
13
|
-
[keyObj.key]: {}
|
|
14
|
-
};
|
|
11
|
+
if (!currentValue[keyObj.key] || typeof currentValue[keyObj.key] !== "object") {
|
|
12
|
+
currentValue[keyObj.key] = {};
|
|
15
13
|
}
|
|
16
14
|
currentValue = currentValue[keyObj.key];
|
|
17
15
|
} else if (keyObj.type === NodeType.Array) {
|
|
18
16
|
lastKeys = [keyObj.key];
|
|
19
|
-
if (!currentValue[keyObj.key]) {
|
|
17
|
+
if (!currentValue[keyObj.key] || typeof currentValue[keyObj.key] !== "object") {
|
|
20
18
|
currentValue[keyObj.key] = {};
|
|
21
19
|
}
|
|
22
20
|
currentValue = currentValue[keyObj.key];
|
|
23
21
|
} else if (keyObj.type === NodeType.Translation) {
|
|
24
22
|
lastKeys = [NodeType.Translation, keyObj.key];
|
|
25
|
-
if (!currentValue[NodeType.Translation]) {
|
|
26
|
-
currentValue[NodeType.Translation] = {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
23
|
+
if (!currentValue[NodeType.Translation] || typeof currentValue[NodeType.Translation] !== "object") {
|
|
24
|
+
currentValue[NodeType.Translation] = {};
|
|
25
|
+
}
|
|
26
|
+
if (!currentValue[NodeType.Translation][keyObj.key] || typeof currentValue[NodeType.Translation][keyObj.key] !== "object") {
|
|
27
|
+
currentValue[NodeType.Translation][keyObj.key] = {};
|
|
30
28
|
}
|
|
31
29
|
currentValue = currentValue[NodeType.Translation][keyObj.key];
|
|
32
30
|
} else if (keyObj.type === NodeType.Enumeration) {
|
|
33
31
|
lastKeys = [NodeType.Enumeration, keyObj.key];
|
|
34
|
-
if (!currentValue[NodeType.Enumeration]) {
|
|
35
|
-
currentValue[NodeType.Enumeration] = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
32
|
+
if (!currentValue[NodeType.Enumeration] || typeof currentValue[NodeType.Enumeration] !== "object") {
|
|
33
|
+
currentValue[NodeType.Enumeration] = {};
|
|
34
|
+
}
|
|
35
|
+
if (!currentValue[NodeType.Enumeration][keyObj.key] || typeof currentValue[NodeType.Enumeration][keyObj.key] !== "object") {
|
|
36
|
+
currentValue[NodeType.Enumeration][keyObj.key] = {};
|
|
39
37
|
}
|
|
40
38
|
currentValue = currentValue[NodeType.Enumeration][keyObj.key];
|
|
39
|
+
} else if (keyObj.type === NodeType.Condition) {
|
|
40
|
+
lastKeys = [NodeType.Condition, keyObj.key];
|
|
41
|
+
if (!currentValue[NodeType.Condition] || typeof currentValue[NodeType.Condition] !== "object") {
|
|
42
|
+
currentValue[NodeType.Condition] = {};
|
|
43
|
+
}
|
|
44
|
+
if (!currentValue[NodeType.Condition][keyObj.key] || typeof currentValue[NodeType.Condition][keyObj.key] !== "object") {
|
|
45
|
+
currentValue[NodeType.Condition][keyObj.key] = {};
|
|
46
|
+
}
|
|
47
|
+
currentValue = currentValue[NodeType.Condition][keyObj.key];
|
|
41
48
|
} else if (keyObj.type === NodeType.Markdown) {
|
|
42
49
|
lastKeys = [NodeType.Markdown];
|
|
43
|
-
if (!currentValue[NodeType.Markdown]) {
|
|
44
|
-
currentValue[NodeType.Markdown] =
|
|
50
|
+
if (!currentValue[NodeType.Markdown] || typeof currentValue[NodeType.Markdown] !== "object") {
|
|
51
|
+
currentValue[NodeType.Markdown] = "";
|
|
45
52
|
}
|
|
46
53
|
currentValue = currentValue[NodeType.Markdown];
|
|
47
54
|
} else if (keyObj.type === NodeType.Nested) {
|
|
48
55
|
lastKeys = [NodeType.Nested];
|
|
49
|
-
if (!currentValue[NodeType.Nested]) {
|
|
50
|
-
currentValue[NodeType.Nested] =
|
|
56
|
+
if (!currentValue[NodeType.Nested] || typeof currentValue[NodeType.Nested] !== "object") {
|
|
57
|
+
currentValue[NodeType.Nested] = {};
|
|
51
58
|
}
|
|
52
59
|
currentValue = currentValue[NodeType.Nested];
|
|
53
60
|
}
|
|
54
|
-
if (parentValue && lastKeys.length > 0) {
|
|
61
|
+
if (i === keyPath.length - 1 && parentValue && lastKeys.length > 0) {
|
|
62
|
+
let target = parentValue;
|
|
55
63
|
for (const key of lastKeys.slice(0, -1)) {
|
|
56
|
-
|
|
64
|
+
target = target[key];
|
|
57
65
|
}
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
typeof newValue === "undefined"
|
|
61
|
-
) {
|
|
62
|
-
delete parentValue[lastKeys[lastKeys.length - 1]];
|
|
66
|
+
if (typeof newValue === "undefined") {
|
|
67
|
+
delete target[lastKeys[lastKeys.length - 1]];
|
|
63
68
|
} else {
|
|
64
|
-
|
|
69
|
+
target[lastKeys[lastKeys.length - 1]] = newValue;
|
|
65
70
|
}
|
|
66
71
|
}
|
|
67
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/dictionaryManipulator/editDictionaryByKeyPath.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/dictionaryManipulator/editDictionaryByKeyPath.ts"],"sourcesContent":["import { type KeyPath, NodeType } from '../types';\nimport type { ContentNode } from '../types/dictionary';\n\ntype LastKeyType = string | number;\n\nexport const editDictionaryByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[],\n newValue: ContentNode\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKeys: LastKeyType[] = [];\n\n for (let i = 0; i < keyPath.length; i++) {\n const keyObj = keyPath[i];\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object) {\n lastKeys = [keyObj.key];\n if (\n !currentValue[keyObj.key] ||\n typeof currentValue[keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Array) {\n lastKeys = [keyObj.key];\n if (\n !currentValue[keyObj.key] ||\n typeof currentValue[keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n lastKeys = [NodeType.Translation, keyObj.key];\n if (\n !currentValue[NodeType.Translation] ||\n typeof currentValue[NodeType.Translation] !== 'object'\n ) {\n currentValue[NodeType.Translation] = {};\n }\n if (\n !currentValue[NodeType.Translation][keyObj.key] ||\n typeof currentValue[NodeType.Translation][keyObj.key] !== 'object'\n ) {\n currentValue[NodeType.Translation][keyObj.key] = {};\n }\n currentValue = currentValue[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n lastKeys = [NodeType.Enumeration, keyObj.key];\n if (\n !currentValue[NodeType.Enumeration] ||\n typeof currentValue[NodeType.Enumeration] !== 'object'\n ) {\n currentValue[NodeType.Enumeration] = {};\n }\n if (\n !currentValue[NodeType.Enumeration][keyObj.key] ||\n typeof currentValue[NodeType.Enumeration][keyObj.key] !== 'object'\n ) {\n currentValue[NodeType.Enumeration][keyObj.key] = {};\n }\n currentValue = currentValue[NodeType.Enumeration][keyObj.key];\n } else if (keyObj.type === NodeType.Condition) {\n lastKeys = [NodeType.Condition, keyObj.key];\n if (\n !currentValue[NodeType.Condition] ||\n typeof currentValue[NodeType.Condition] !== 'object'\n ) {\n currentValue[NodeType.Condition] = {};\n }\n if (\n !currentValue[NodeType.Condition][keyObj.key] ||\n typeof currentValue[NodeType.Condition][keyObj.key] !== 'object'\n ) {\n currentValue[NodeType.Condition][keyObj.key] = {};\n }\n currentValue = currentValue[NodeType.Condition][keyObj.key];\n } else if (keyObj.type === NodeType.Markdown) {\n lastKeys = [NodeType.Markdown];\n if (\n !currentValue[NodeType.Markdown] ||\n typeof currentValue[NodeType.Markdown] !== 'object'\n ) {\n currentValue[NodeType.Markdown] = '';\n }\n currentValue = currentValue[NodeType.Markdown];\n } else if (keyObj.type === NodeType.Nested) {\n lastKeys = [NodeType.Nested];\n if (\n !currentValue[NodeType.Nested] ||\n typeof currentValue[NodeType.Nested] !== 'object'\n ) {\n currentValue[NodeType.Nested] = {};\n }\n currentValue = currentValue[NodeType.Nested];\n }\n\n // Only update the value when processing the last key in the keyPath.\n if (i === keyPath.length - 1 && parentValue && lastKeys.length > 0) {\n let target = parentValue;\n // Drill down if lastKeys contains more than one key.\n for (const key of lastKeys.slice(0, -1)) {\n target = target[key];\n }\n if (typeof newValue === 'undefined') {\n delete target[lastKeys[lastKeys.length - 1]];\n } else {\n target[lastKeys[lastKeys.length - 1]] = newValue;\n }\n }\n }\n return dictionaryContent;\n};\n"],"mappings":"AAAA,SAAuB,gBAAgB;AAKhC,MAAM,0BAA0B,CACrC,mBACA,SACA,aACgB;AAChB,MAAI,eAAoB;AACxB,MAAI,cAAmB;AACvB,MAAI,WAA0B,CAAC;AAE/B,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,UAAM,SAAS,QAAQ,CAAC;AACxB,kBAAc;AAEd,QAAI,OAAO,SAAS,SAAS,QAAQ;AACnC,iBAAW,CAAC,OAAO,GAAG;AACtB,UACE,CAAC,aAAa,OAAO,GAAG,KACxB,OAAO,aAAa,OAAO,GAAG,MAAM,UACpC;AACA,qBAAa,OAAO,GAAG,IAAI,CAAC;AAAA,MAC9B;AACA,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC,WAAW,OAAO,SAAS,SAAS,OAAO;AACzC,iBAAW,CAAC,OAAO,GAAG;AACtB,UACE,CAAC,aAAa,OAAO,GAAG,KACxB,OAAO,aAAa,OAAO,GAAG,MAAM,UACpC;AACA,qBAAa,OAAO,GAAG,IAAI,CAAC;AAAA,MAC9B;AACA,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,iBAAW,CAAC,SAAS,aAAa,OAAO,GAAG;AAC5C,UACE,CAAC,aAAa,SAAS,WAAW,KAClC,OAAO,aAAa,SAAS,WAAW,MAAM,UAC9C;AACA,qBAAa,SAAS,WAAW,IAAI,CAAC;AAAA,MACxC;AACA,UACE,CAAC,aAAa,SAAS,WAAW,EAAE,OAAO,GAAG,KAC9C,OAAO,aAAa,SAAS,WAAW,EAAE,OAAO,GAAG,MAAM,UAC1D;AACA,qBAAa,SAAS,WAAW,EAAE,OAAO,GAAG,IAAI,CAAC;AAAA,MACpD;AACA,qBAAe,aAAa,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,iBAAW,CAAC,SAAS,aAAa,OAAO,GAAG;AAC5C,UACE,CAAC,aAAa,SAAS,WAAW,KAClC,OAAO,aAAa,SAAS,WAAW,MAAM,UAC9C;AACA,qBAAa,SAAS,WAAW,IAAI,CAAC;AAAA,MACxC;AACA,UACE,CAAC,aAAa,SAAS,WAAW,EAAE,OAAO,GAAG,KAC9C,OAAO,aAAa,SAAS,WAAW,EAAE,OAAO,GAAG,MAAM,UAC1D;AACA,qBAAa,SAAS,WAAW,EAAE,OAAO,GAAG,IAAI,CAAC;AAAA,MACpD;AACA,qBAAe,aAAa,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D,WAAW,OAAO,SAAS,SAAS,WAAW;AAC7C,iBAAW,CAAC,SAAS,WAAW,OAAO,GAAG;AAC1C,UACE,CAAC,aAAa,SAAS,SAAS,KAChC,OAAO,aAAa,SAAS,SAAS,MAAM,UAC5C;AACA,qBAAa,SAAS,SAAS,IAAI,CAAC;AAAA,MACtC;AACA,UACE,CAAC,aAAa,SAAS,SAAS,EAAE,OAAO,GAAG,KAC5C,OAAO,aAAa,SAAS,SAAS,EAAE,OAAO,GAAG,MAAM,UACxD;AACA,qBAAa,SAAS,SAAS,EAAE,OAAO,GAAG,IAAI,CAAC;AAAA,MAClD;AACA,qBAAe,aAAa,SAAS,SAAS,EAAE,OAAO,GAAG;AAAA,IAC5D,WAAW,OAAO,SAAS,SAAS,UAAU;AAC5C,iBAAW,CAAC,SAAS,QAAQ;AAC7B,UACE,CAAC,aAAa,SAAS,QAAQ,KAC/B,OAAO,aAAa,SAAS,QAAQ,MAAM,UAC3C;AACA,qBAAa,SAAS,QAAQ,IAAI;AAAA,MACpC;AACA,qBAAe,aAAa,SAAS,QAAQ;AAAA,IAC/C,WAAW,OAAO,SAAS,SAAS,QAAQ;AAC1C,iBAAW,CAAC,SAAS,MAAM;AAC3B,UACE,CAAC,aAAa,SAAS,MAAM,KAC7B,OAAO,aAAa,SAAS,MAAM,MAAM,UACzC;AACA,qBAAa,SAAS,MAAM,IAAI,CAAC;AAAA,MACnC;AACA,qBAAe,aAAa,SAAS,MAAM;AAAA,IAC7C;AAGA,QAAI,MAAM,QAAQ,SAAS,KAAK,eAAe,SAAS,SAAS,GAAG;AAClE,UAAI,SAAS;AAEb,iBAAW,OAAO,SAAS,MAAM,GAAG,EAAE,GAAG;AACvC,iBAAS,OAAO,GAAG;AAAA,MACrB;AACA,UAAI,OAAO,aAAa,aAAa;AACnC,eAAO,OAAO,SAAS,SAAS,SAAS,CAAC,CAAC;AAAA,MAC7C,OAAO;AACL,eAAO,SAAS,SAAS,SAAS,CAAC,CAAC,IAAI;AAAA,MAC1C;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NodeType } from "../types/index.mjs";
|
|
2
2
|
const getContentNodeByKeyPath = (dictionaryContent, keyPath) => {
|
|
3
|
-
let currentValue =
|
|
3
|
+
let currentValue = structuredClone(dictionaryContent ?? {});
|
|
4
4
|
for (const keyObj of keyPath) {
|
|
5
5
|
if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {
|
|
6
6
|
currentValue = currentValue?.[keyObj.key];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/dictionaryManipulator/getContentNodeByKeyPath.ts"],"sourcesContent":["import { type KeyPath, NodeType } from '../types';\nimport type { ContentNode } from '../types/dictionary';\n\nexport const getContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[]\n): ContentNode => {\n let currentValue: any =
|
|
1
|
+
{"version":3,"sources":["../../../src/dictionaryManipulator/getContentNodeByKeyPath.ts"],"sourcesContent":["import { type KeyPath, NodeType } from '../types';\nimport type { ContentNode } from '../types/dictionary';\n\nexport const getContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[]\n): ContentNode => {\n let currentValue: any = structuredClone(dictionaryContent ?? {});\n\n for (const keyObj of keyPath) {\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n currentValue = currentValue?.[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n currentValue = currentValue?.[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n currentValue = currentValue?.[NodeType.Enumeration][keyObj.key];\n } else if (keyObj.type === NodeType.Condition) {\n currentValue = currentValue[NodeType.Condition];\n } else if (keyObj.type === NodeType.Markdown) {\n currentValue = currentValue[NodeType.Markdown];\n }\n }\n\n return currentValue as ContentNode;\n};\n"],"mappings":"AAAA,SAAuB,gBAAgB;AAGhC,MAAM,0BAA0B,CACrC,mBACA,YACgB;AAChB,MAAI,eAAoB,gBAAgB,qBAAqB,CAAC,CAAC;AAE/D,aAAW,UAAU,SAAS;AAC5B,QAAI,OAAO,SAAS,SAAS,UAAU,OAAO,SAAS,SAAS,OAAO;AACrE,qBAAe,eAAe,OAAO,GAAG;AAAA,IAC1C,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,qBAAe,eAAe,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAChE,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,qBAAe,eAAe,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAChE,WAAW,OAAO,SAAS,SAAS,WAAW;AAC7C,qBAAe,aAAa,SAAS,SAAS;AAAA,IAChD,WAAW,OAAO,SAAS,SAAS,UAAU;AAC5C,qBAAe,aAAa,SAAS,QAAQ;AAAA,IAC/C;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { NodeType } from "../types/index.mjs";
|
|
2
|
+
const getDefaultNode = (nodeType, locales, content) => {
|
|
3
|
+
switch (nodeType) {
|
|
4
|
+
case NodeType.Translation:
|
|
5
|
+
return {
|
|
6
|
+
nodeType: NodeType.Translation,
|
|
7
|
+
[NodeType.Translation]: Object.assign(
|
|
8
|
+
{},
|
|
9
|
+
...locales.map((locale) => ({
|
|
10
|
+
[locale]: content ?? ""
|
|
11
|
+
}))
|
|
12
|
+
)
|
|
13
|
+
};
|
|
14
|
+
case NodeType.Enumeration:
|
|
15
|
+
return {
|
|
16
|
+
nodeType: NodeType.Enumeration,
|
|
17
|
+
[NodeType.Enumeration]: {
|
|
18
|
+
"1": content ?? ""
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
case NodeType.Condition:
|
|
22
|
+
return {
|
|
23
|
+
nodeType: NodeType.Condition,
|
|
24
|
+
[NodeType.Condition]: {
|
|
25
|
+
true: content ?? "",
|
|
26
|
+
false: content ?? ""
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
case NodeType.Nested:
|
|
30
|
+
return {
|
|
31
|
+
nodeType: NodeType.Nested,
|
|
32
|
+
[NodeType.Nested]: {
|
|
33
|
+
dictionaryKey: ""
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
case NodeType.Markdown:
|
|
37
|
+
return {
|
|
38
|
+
nodeType: NodeType.Markdown,
|
|
39
|
+
[NodeType.Markdown]: content ?? ""
|
|
40
|
+
};
|
|
41
|
+
case NodeType.Object:
|
|
42
|
+
return {
|
|
43
|
+
newKey: content ?? ""
|
|
44
|
+
};
|
|
45
|
+
case NodeType.Array:
|
|
46
|
+
return [content ?? ""];
|
|
47
|
+
case NodeType.Text:
|
|
48
|
+
return content ?? "";
|
|
49
|
+
case NodeType.Number:
|
|
50
|
+
return content ?? 0;
|
|
51
|
+
case NodeType.Boolean:
|
|
52
|
+
return content ?? true;
|
|
53
|
+
default:
|
|
54
|
+
return content ?? "";
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
export {
|
|
58
|
+
getDefaultNode
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=getDefaultNode.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/dictionaryManipulator/getDefaultNode.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport type {\n TranslationContent,\n EnumerationContent,\n ConditionContent,\n NestedContent,\n MarkdownContent,\n} from '../transpiler';\nimport { type ContentNode, NodeType } from '../types';\n\nexport const getDefaultNode = (\n nodeType: NodeType,\n locales: LocalesValues[],\n content?: ContentNode\n) => {\n switch (nodeType) {\n case NodeType.Translation:\n return {\n nodeType: NodeType.Translation,\n [NodeType.Translation]: Object.assign(\n {},\n ...locales.map((locale) => ({\n [locale]: content ?? '',\n }))\n ),\n } as TranslationContent<ContentNode>;\n\n case NodeType.Enumeration:\n return {\n nodeType: NodeType.Enumeration,\n [NodeType.Enumeration]: {\n '1': content ?? '',\n },\n } as EnumerationContent<ContentNode>;\n\n case NodeType.Condition:\n return {\n nodeType: NodeType.Condition,\n [NodeType.Condition]: {\n true: content ?? '',\n false: content ?? '',\n },\n } as ConditionContent<ContentNode>;\n\n case NodeType.Nested:\n return {\n nodeType: NodeType.Nested,\n [NodeType.Nested]: {\n dictionaryKey: '',\n },\n } as NestedContent;\n\n case NodeType.Markdown:\n return {\n nodeType: NodeType.Markdown,\n [NodeType.Markdown]: content ?? '',\n } as MarkdownContent;\n\n case NodeType.Object:\n return {\n newKey: content ?? '',\n } as Record<string, ContentNode>;\n\n case NodeType.Array:\n return [content ?? ''] as Record<number, ContentNode>;\n\n case NodeType.Text:\n return content ?? '';\n\n case NodeType.Number:\n return content ?? 0;\n\n case NodeType.Boolean:\n return content ?? true;\n\n default:\n return content ?? '';\n }\n};\n"],"mappings":"AAQA,SAA2B,gBAAgB;AAEpC,MAAM,iBAAiB,CAC5B,UACA,SACA,YACG;AACH,UAAQ,UAAU;AAAA,IAChB,KAAK,SAAS;AACZ,aAAO;AAAA,QACL,UAAU,SAAS;AAAA,QACnB,CAAC,SAAS,WAAW,GAAG,OAAO;AAAA,UAC7B,CAAC;AAAA,UACD,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,YAC1B,CAAC,MAAM,GAAG,WAAW;AAAA,UACvB,EAAE;AAAA,QACJ;AAAA,MACF;AAAA,IAEF,KAAK,SAAS;AACZ,aAAO;AAAA,QACL,UAAU,SAAS;AAAA,QACnB,CAAC,SAAS,WAAW,GAAG;AAAA,UACtB,KAAK,WAAW;AAAA,QAClB;AAAA,MACF;AAAA,IAEF,KAAK,SAAS;AACZ,aAAO;AAAA,QACL,UAAU,SAAS;AAAA,QACnB,CAAC,SAAS,SAAS,GAAG;AAAA,UACpB,MAAM,WAAW;AAAA,UACjB,OAAO,WAAW;AAAA,QACpB;AAAA,MACF;AAAA,IAEF,KAAK,SAAS;AACZ,aAAO;AAAA,QACL,UAAU,SAAS;AAAA,QACnB,CAAC,SAAS,MAAM,GAAG;AAAA,UACjB,eAAe;AAAA,QACjB;AAAA,MACF;AAAA,IAEF,KAAK,SAAS;AACZ,aAAO;AAAA,QACL,UAAU,SAAS;AAAA,QACnB,CAAC,SAAS,QAAQ,GAAG,WAAW;AAAA,MAClC;AAAA,IAEF,KAAK,SAAS;AACZ,aAAO;AAAA,QACL,QAAQ,WAAW;AAAA,MACrB;AAAA,IAEF,KAAK,SAAS;AACZ,aAAO,CAAC,WAAW,EAAE;AAAA,IAEvB,KAAK,SAAS;AACZ,aAAO,WAAW;AAAA,IAEpB,KAAK,SAAS;AACZ,aAAO,WAAW;AAAA,IAEpB,KAAK,SAAS;AACZ,aAAO,WAAW;AAAA,IAEpB;AACE,aAAO,WAAW;AAAA,EACtB;AACF;","names":[]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { NodeType } from "../types/index.mjs";
|
|
2
|
+
const getNodeChildren = (section) => {
|
|
3
|
+
if (typeof section === "string") {
|
|
4
|
+
return section;
|
|
5
|
+
}
|
|
6
|
+
if (typeof section === "number") {
|
|
7
|
+
return section;
|
|
8
|
+
}
|
|
9
|
+
if (typeof section === "boolean") {
|
|
10
|
+
return section;
|
|
11
|
+
}
|
|
12
|
+
if (typeof section?.nodeType === "string") {
|
|
13
|
+
const typedNode = section;
|
|
14
|
+
const content = typedNode[typedNode.nodeType];
|
|
15
|
+
if (typedNode.nodeType === NodeType.Translation || typedNode.nodeType === NodeType.Enumeration || typedNode.nodeType === NodeType.Condition) {
|
|
16
|
+
const firstKey = Object.keys(content)[0];
|
|
17
|
+
return content[firstKey];
|
|
18
|
+
}
|
|
19
|
+
if (typedNode.nodeType === NodeType.Nested) {
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
22
|
+
return content;
|
|
23
|
+
}
|
|
24
|
+
if (!section || typeof section !== "object") {
|
|
25
|
+
return section;
|
|
26
|
+
}
|
|
27
|
+
if (Array.isArray(section)) {
|
|
28
|
+
return section[0];
|
|
29
|
+
}
|
|
30
|
+
return section;
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
getNodeChildren
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=getNodeChildren.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/dictionaryManipulator/getNodeChildren.ts"],"sourcesContent":["import { type ContentNode, type TypedNode, NodeType } from '../types';\n\nexport const getNodeChildren = (section: ContentNode): ContentNode => {\n if (typeof section === 'string') {\n return section;\n }\n if (typeof section === 'number') {\n return section;\n }\n if (typeof section === 'boolean') {\n return section;\n }\n if (typeof (section as TypedNode)?.nodeType === 'string') {\n const typedNode = section as TypedNode;\n const content = typedNode[typedNode.nodeType as keyof TypedNode];\n\n if (\n typedNode.nodeType === NodeType.Translation ||\n typedNode.nodeType === NodeType.Enumeration ||\n typedNode.nodeType === NodeType.Condition\n ) {\n const firstKey = Object.keys(content)[0] as keyof typeof content;\n return content[firstKey] as ContentNode;\n }\n\n if (typedNode.nodeType === NodeType.Nested) {\n return undefined;\n }\n\n return content;\n }\n\n if (!section || typeof section !== 'object') {\n return section;\n }\n\n if (Array.isArray(section)) {\n return (section as ContentNode[])[0];\n }\n\n return section;\n};\n"],"mappings":"AAAA,SAA2C,gBAAgB;AAEpD,MAAM,kBAAkB,CAAC,YAAsC;AACpE,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,EACT;AACA,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,EACT;AACA,MAAI,OAAO,YAAY,WAAW;AAChC,WAAO;AAAA,EACT;AACA,MAAI,OAAQ,SAAuB,aAAa,UAAU;AACxD,UAAM,YAAY;AAClB,UAAM,UAAU,UAAU,UAAU,QAA2B;AAE/D,QACE,UAAU,aAAa,SAAS,eAChC,UAAU,aAAa,SAAS,eAChC,UAAU,aAAa,SAAS,WAChC;AACA,YAAM,WAAW,OAAO,KAAK,OAAO,EAAE,CAAC;AACvC,aAAO,QAAQ,QAAQ;AAAA,IACzB;AAEA,QAAI,UAAU,aAAa,SAAS,QAAQ;AAC1C,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,WAAW,OAAO,YAAY,UAAU;AAC3C,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,WAAQ,QAA0B,CAAC;AAAA,EACrC;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { NodeType } from "../types/index.mjs";
|
|
2
|
+
import { isValidElement } from "../utils/isValidReactElement.mjs";
|
|
3
|
+
const getNodeType = (content) => {
|
|
4
|
+
if (typeof content === "string") {
|
|
5
|
+
return NodeType.Text;
|
|
6
|
+
}
|
|
7
|
+
if (content?.nodeType === NodeType.Translation) {
|
|
8
|
+
return NodeType.Translation;
|
|
9
|
+
}
|
|
10
|
+
if (content?.nodeType === NodeType.Enumeration) {
|
|
11
|
+
return NodeType.Enumeration;
|
|
12
|
+
}
|
|
13
|
+
if (content?.nodeType === NodeType.Condition) {
|
|
14
|
+
return NodeType.Condition;
|
|
15
|
+
}
|
|
16
|
+
if (content?.nodeType === NodeType.Markdown) {
|
|
17
|
+
return NodeType.Markdown;
|
|
18
|
+
}
|
|
19
|
+
if (content?.nodeType === NodeType.Nested) {
|
|
20
|
+
return NodeType.Nested;
|
|
21
|
+
}
|
|
22
|
+
if (Array.isArray(content)) {
|
|
23
|
+
return NodeType.Array;
|
|
24
|
+
}
|
|
25
|
+
if (isValidElement(content)) {
|
|
26
|
+
return NodeType.ReactNode;
|
|
27
|
+
}
|
|
28
|
+
if (typeof content === "number") {
|
|
29
|
+
return NodeType.Number;
|
|
30
|
+
}
|
|
31
|
+
if (typeof content === "boolean") {
|
|
32
|
+
return NodeType.Boolean;
|
|
33
|
+
}
|
|
34
|
+
if (content && typeof content === "object") {
|
|
35
|
+
return NodeType.Object;
|
|
36
|
+
}
|
|
37
|
+
return NodeType.Unknown;
|
|
38
|
+
};
|
|
39
|
+
export {
|
|
40
|
+
getNodeType
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=getNodeType.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/dictionaryManipulator/getNodeType.ts"],"sourcesContent":["import type {\n TranslationContent,\n EnumerationContent,\n ConditionContent,\n MarkdownContent,\n NestedContent,\n} from '../transpiler';\nimport { NodeType, type DictionaryKeys } from '../types';\nimport type { ContentNode } from '../types/dictionary';\nimport { isValidElement } from '../utils/isValidReactElement';\n\nexport const getNodeType = (content: ContentNode): NodeType => {\n if (typeof content === 'string') {\n return NodeType.Text;\n }\n\n if ((content as TranslationContent)?.nodeType === NodeType.Translation) {\n return NodeType.Translation;\n }\n\n if ((content as EnumerationContent)?.nodeType === NodeType.Enumeration) {\n return NodeType.Enumeration;\n }\n\n if ((content as ConditionContent)?.nodeType === NodeType.Condition) {\n return NodeType.Condition;\n }\n\n if ((content as MarkdownContent)?.nodeType === NodeType.Markdown) {\n return NodeType.Markdown;\n }\n\n if (\n (content as NestedContent<DictionaryKeys>)?.nodeType === NodeType.Nested\n ) {\n return NodeType.Nested;\n }\n\n if (Array.isArray(content)) {\n return NodeType.Array;\n }\n\n if (isValidElement(content)) {\n return NodeType.ReactNode;\n }\n\n if (typeof content === 'number') {\n return NodeType.Number;\n }\n\n if (typeof content === 'boolean') {\n return NodeType.Boolean;\n }\n\n if (content && typeof content === 'object') {\n return NodeType.Object;\n }\n\n return NodeType.Unknown;\n};\n"],"mappings":"AAOA,SAAS,gBAAqC;AAE9C,SAAS,sBAAsB;AAExB,MAAM,cAAc,CAAC,YAAmC;AAC7D,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO,SAAS;AAAA,EAClB;AAEA,MAAK,SAAgC,aAAa,SAAS,aAAa;AACtE,WAAO,SAAS;AAAA,EAClB;AAEA,MAAK,SAAgC,aAAa,SAAS,aAAa;AACtE,WAAO,SAAS;AAAA,EAClB;AAEA,MAAK,SAA8B,aAAa,SAAS,WAAW;AAClE,WAAO,SAAS;AAAA,EAClB;AAEA,MAAK,SAA6B,aAAa,SAAS,UAAU;AAChE,WAAO,SAAS;AAAA,EAClB;AAEA,MACG,SAA2C,aAAa,SAAS,QAClE;AACA,WAAO,SAAS;AAAA,EAClB;AAEA,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,WAAO,SAAS;AAAA,EAClB;AAEA,MAAI,eAAe,OAAO,GAAG;AAC3B,WAAO,SAAS;AAAA,EAClB;AAEA,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO,SAAS;AAAA,EAClB;AAEA,MAAI,OAAO,YAAY,WAAW;AAChC,WAAO,SAAS;AAAA,EAClB;AAEA,MAAI,WAAW,OAAO,YAAY,UAAU;AAC1C,WAAO,SAAS;AAAA,EAClB;AAEA,SAAO,SAAS;AAClB;","names":[]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export * from "./editDictionaryByKeyPath.mjs";
|
|
2
2
|
export * from "./getContentNodeByKeyPath.mjs";
|
|
3
|
-
export * from "./
|
|
3
|
+
export * from "./getNodeChildren.mjs";
|
|
4
4
|
export * from "./removeContentNodeByKeyPath.mjs";
|
|
5
5
|
export * from "./renameContentNodeByKeyPath.mjs";
|
|
6
|
+
export * from "./getNodeType.mjs";
|
|
7
|
+
export * from "./updateNodeChildren.mjs";
|
|
8
|
+
export * from "./getDefaultNode.mjs";
|
|
6
9
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/dictionaryManipulator/index.ts"],"sourcesContent":["export * from './editDictionaryByKeyPath';\nexport * from './getContentNodeByKeyPath';\nexport * from './
|
|
1
|
+
{"version":3,"sources":["../../../src/dictionaryManipulator/index.ts"],"sourcesContent":["export * from './editDictionaryByKeyPath';\nexport * from './getContentNodeByKeyPath';\nexport * from './getNodeChildren';\nexport * from './removeContentNodeByKeyPath';\nexport * from './renameContentNodeByKeyPath';\nexport * from './getNodeType';\nexport * from './updateNodeChildren';\nexport * from './getDefaultNode';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|