angular-intlayer 9.0.0-canary.1 → 9.0.0-canary.10
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/client/index.cjs +3 -1
- package/dist/cjs/client/useDictionary.cjs +1 -1
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +2 -2
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +1 -1
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/usePathname.cjs +53 -0
- package/dist/cjs/client/usePathname.cjs.map +1 -0
- package/dist/cjs/editor/useEditor.cjs +1 -1
- package/dist/cjs/editor/useEditor.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs +1 -1
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +1 -1
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/index.cjs +3 -1
- package/dist/cjs/plugins.cjs +8 -8
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/webpack/mergeConfig.cjs +5 -3
- package/dist/cjs/webpack/mergeConfig.cjs.map +1 -1
- package/dist/esm/_virtual/_rolldown/runtime.mjs +8 -0
- package/dist/esm/client/index.mjs +2 -1
- package/dist/esm/client/useDictionary.mjs +1 -1
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +2 -2
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +1 -1
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/usePathname.mjs +51 -0
- package/dist/esm/client/usePathname.mjs.map +1 -0
- package/dist/esm/editor/useEditor.mjs +1 -1
- package/dist/esm/editor/useEditor.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs +1 -1
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs +1 -1
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/esm/index.mjs +2 -1
- package/dist/esm/plugins.mjs +8 -8
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/webpack/mergeConfig.mjs +6 -3
- package/dist/esm/webpack/mergeConfig.mjs.map +1 -1
- package/dist/types/client/index.d.ts +2 -1
- package/dist/types/client/useDictionaryDynamic.d.ts +1 -1
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/client/usePathname.d.ts +36 -0
- package/dist/types/client/usePathname.d.ts.map +1 -0
- package/dist/types/getDictionary.d.ts +1 -1
- package/dist/types/getDictionary.d.ts.map +1 -1
- package/dist/types/getIntlayer.d.ts +1 -1
- package/dist/types/getIntlayer.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/webpack/mergeConfig.d.ts +3 -1
- package/dist/types/webpack/mergeConfig.d.ts.map +1 -1
- package/package.json +13 -10
|
@@ -7,6 +7,7 @@ const require_client_useLoadDynamic = require('./useLoadDynamic.cjs');
|
|
|
7
7
|
const require_client_useDictionaryDynamic = require('./useDictionaryDynamic.cjs');
|
|
8
8
|
const require_client_useIntlayer = require('./useIntlayer.cjs');
|
|
9
9
|
const require_client_useLocale = require('./useLocale.cjs');
|
|
10
|
+
const require_client_usePathname = require('./usePathname.cjs');
|
|
10
11
|
|
|
11
12
|
exports.INTLAYER_TOKEN = require_client_intlayerToken.INTLAYER_TOKEN;
|
|
12
13
|
exports.IntlayerProvider = require_client_intlayerToken.IntlayerProvider;
|
|
@@ -19,4 +20,5 @@ exports.useDictionaryAsync = require_client_useDictionaryAsync.useDictionaryAsyn
|
|
|
19
20
|
exports.useDictionaryDynamic = require_client_useDictionaryDynamic.useDictionaryDynamic;
|
|
20
21
|
exports.useIntlayer = require_client_useIntlayer.useIntlayer;
|
|
21
22
|
exports.useLoadDynamic = require_client_useLoadDynamic.useLoadDynamic;
|
|
22
|
-
exports.useLocale = require_client_useLocale.useLocale;
|
|
23
|
+
exports.useLocale = require_client_useLocale.useLocale;
|
|
24
|
+
exports.usePathname = require_client_usePathname.usePathname;
|
|
@@ -11,7 +11,7 @@ let _angular_core = require("@angular/core");
|
|
|
11
11
|
*/
|
|
12
12
|
const useDictionary = (dictionary, localeOrSelector) => {
|
|
13
13
|
const intlayer = (0, _angular_core.inject)(require_client_intlayerToken.INTLAYER_TOKEN);
|
|
14
|
-
const isSelector = typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
14
|
+
const isSelector = process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
15
15
|
return (0, _angular_core.computed)(() => {
|
|
16
16
|
const currentLocale = intlayer?.locale();
|
|
17
17
|
if (isSelector) return require_getDictionary.getDictionary(dictionary, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.cjs","names":["INTLAYER_TOKEN","getDictionary"],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import { computed, inject, type Signal } from '@angular/core';\nimport type {\n Dictionary,\n DictionarySelector,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport type { DeepTransformContent } from '../plugins';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\n\n/**\n * Angular hook that transforms a dictionary (or qualified dictionary group)\n * and returns its reactive content for the given locale or selector.\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n): Signal<\n DeepTransformContent<\n ResolveQualifiedDictionaryContent<T, A>,\n ExtractSelectorLocale<A>\n >\n> => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n const isSelector =\n typeof localeOrSelector === 'object'
|
|
1
|
+
{"version":3,"file":"useDictionary.cjs","names":["INTLAYER_TOKEN","getDictionary"],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import { computed, inject, type Signal } from '@angular/core';\nimport type {\n Dictionary,\n DictionarySelector,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport type { DeepTransformContent } from '../plugins';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\n\n/**\n * Angular hook that transforms a dictionary (or qualified dictionary group)\n * and returns its reactive content for the given locale or selector.\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n): Signal<\n DeepTransformContent<\n ResolveQualifiedDictionaryContent<T, A>,\n ExtractSelectorLocale<A>\n >\n> => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n const isSelector =\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&\n typeof localeOrSelector === 'object' &&\n localeOrSelector !== null;\n\n /** a *stable* reactive dictionary object */\n const content = computed(() => {\n const currentLocale = intlayer?.locale();\n\n if (isSelector) {\n return getDictionary(dictionary, {\n ...localeOrSelector,\n locale: localeOrSelector.locale ?? currentLocale,\n } as A) as any;\n }\n\n return getDictionary(\n dictionary,\n (localeOrSelector ?? currentLocale) as A\n ) as any;\n });\n\n return content; // all consumers keep full reactivity\n};\n"],"mappings":";;;;;;;;;;;AAqBA,MAAa,iBAMX,YACA,qBAMG;CACH,MAAM,qCAAoCA,4CAAe;CAEzD,MAAM,aACJ,QAAQ,IAAI,iCAAiC,WAC7C,OAAO,qBAAqB,YAC5B,qBAAqB;AAmBvB,0CAhB+B;EAC7B,MAAM,gBAAgB,UAAU,QAAQ;AAExC,MAAI,WACF,QAAOC,oCAAc,YAAY;GAC/B,GAAG;GACH,QAAQ,iBAAiB,UAAU;GACpC,CAAM;AAGT,SAAOA,oCACL,YACC,oBAAoB,cACtB;GAGW"}
|
|
@@ -15,7 +15,7 @@ let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryMan
|
|
|
15
15
|
* Lazily loads a dictionary (plain or qualified) and returns its reactive
|
|
16
16
|
* content.
|
|
17
17
|
*
|
|
18
|
-
* For a qualified loader map (collection / variant
|
|
18
|
+
* For a qualified loader map (collection / variant, possibly
|
|
19
19
|
* combined), only the chunk(s) the selector targets are loaded. For a plain
|
|
20
20
|
* loader map, the locale chunk is loaded.
|
|
21
21
|
*
|
|
@@ -24,7 +24,7 @@ let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryMan
|
|
|
24
24
|
*/
|
|
25
25
|
const useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector) => {
|
|
26
26
|
const intlayer = (0, _angular_core.inject)(require_client_intlayerToken.INTLAYER_TOKEN);
|
|
27
|
-
if ((0, _intlayer_core_dictionaryManipulator.isQualifiedDynamicLoaderMap)(dictionaryPromise)) {
|
|
27
|
+
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && (0, _intlayer_core_dictionaryManipulator.isQualifiedDynamicLoaderMap)(dictionaryPromise)) {
|
|
28
28
|
const { locale: selectorLocale, selector } = (0, _intlayer_core_dictionaryManipulator.parseDictionarySelector)(localeOrSelector);
|
|
29
29
|
const localeTarget = selectorLocale ?? intlayer?.locale() ?? _intlayer_config_built.internationalization.defaultLocale;
|
|
30
30
|
const container = (0, _angular_core.signal)(void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.cjs","names":["INTLAYER_TOKEN","internationalization","getDictionary","useDictionary","useLoadDynamic"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport { computed, inject, signal } from '@angular/core';\nimport { internationalization } from '@intlayer/config/built';\nimport {\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveQualifiedDynamicContentAsync,\n} from '@intlayer/core/dictionaryManipulator';\nimport type {
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.cjs","names":["INTLAYER_TOKEN","internationalization","getDictionary","useDictionary","useLoadDynamic"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport { computed, inject, signal } from '@angular/core';\nimport { internationalization } from '@intlayer/config/built';\nimport {\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveQualifiedDynamicContentAsync,\n} from '@intlayer/core/dictionaryManipulator';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * Lazily loads a dictionary (plain or qualified) and returns its reactive\n * content.\n *\n * For a qualified loader map (collection / variant, possibly\n * combined), only the chunk(s) the selector targets are loaded. For a plain\n * loader map, the locale chunk is loaded.\n *\n * If the locale is not provided (directly or through the selector), it will use\n * the locale from the client context.\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const K extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<K> = LocalesValues,\n>(\n dictionaryPromise:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: K,\n localeOrSelector?: A\n) => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n if (\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&\n isQualifiedDynamicLoaderMap(dictionaryPromise)\n ) {\n const { locale: selectorLocale, selector } =\n parseDictionarySelector<LocalesValues>(localeOrSelector);\n\n const localeTarget =\n selectorLocale ??\n intlayer?.locale() ??\n internationalization.defaultLocale;\n\n const container = signal<unknown>(undefined);\n\n resolveQualifiedDynamicContentAsync({\n loaderMap: dictionaryPromise,\n key: String(key),\n locale: localeTarget,\n selector,\n transform: (dictionary) => getDictionary(dictionary, localeTarget),\n }).then((resolved) => container.set(resolved));\n\n return computed(() => container() as any);\n }\n\n const locale =\n typeof localeOrSelector === 'string'\n ? (localeOrSelector as LocalesValues)\n : undefined;\n\n const localeTarget = computed(\n () => locale ?? intlayer?.locale() ?? internationalization.defaultLocale\n );\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget()}`,\n (dictionaryPromise as any)[localeTarget()]?.()\n ) as T;\n\n return useDictionary(dictionary, localeTarget() as any);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAa,wBAKX,mBAGA,KACA,qBACG;CACH,MAAM,qCAAoCA,4CAAe;AAEzD,KACE,QAAQ,IAAI,iCAAiC,iFACjB,kBAAkB,EAC9C;EACA,MAAM,EAAE,QAAQ,gBAAgB,+EACS,iBAAiB;EAE1D,MAAM,eACJ,kBACA,UAAU,QAAQ,IAClBC,4CAAqB;EAEvB,MAAM,sCAA4B,OAAU;AAE5C,gFAAoC;GAClC,WAAW;GACX,KAAK,OAAO,IAAI;GAChB,QAAQ;GACR;GACA,YAAY,eAAeC,oCAAc,YAAY,aAAa;GACnE,CAAC,CAAC,MAAM,aAAa,UAAU,IAAI,SAAS,CAAC;AAE9C,2CAAsB,WAAW,CAAQ;;CAG3C,MAAM,SACJ,OAAO,qBAAqB,WACvB,mBACD;CAEN,MAAM,iDACE,UAAU,UAAU,QAAQ,IAAID,4CAAqB,cAC5D;AAOD,QAAOE,2CALYC,6CACjB,GAAG,OAAO,IAAI,CAAC,GAAG,cAAc,IAC/B,kBAA0B,cAAc,KAAK,CAGjB,EAAE,cAAc,CAAQ"}
|
|
@@ -34,7 +34,7 @@ const isUpdatableNode = (val) => !!val && typeof val === "object" && typeof val.
|
|
|
34
34
|
*/
|
|
35
35
|
const useIntlayer = (key, localeOrSelector) => {
|
|
36
36
|
const intlayer = (0, _angular_core.inject)(require_client_intlayerToken.INTLAYER_TOKEN);
|
|
37
|
-
const isSelector = typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
37
|
+
const isSelector = process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
38
38
|
return (0, _angular_core.computed)(() => {
|
|
39
39
|
const currentLocale = intlayer.locale();
|
|
40
40
|
if (isSelector) return require_getIntlayer.getIntlayer(key, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.cjs","names":["INTLAYER_TOKEN","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import { computed, inject, type Signal } from '@angular/core';\nimport type { DictionarySelector } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n DictionarySelectorForKey,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\n\n/** guard utility - true only for objects generated by `renderIntlayerNode()` */\nexport const isUpdatableNode = (\n val: unknown\n): val is { __update: (n: unknown) => void } =>\n !!val &&\n typeof val === 'object' &&\n typeof (val as any).__update === 'function';\n\n/**\n * Angular hook that picks one dictionary by its key and returns its reactive content.\n *\n * It utilizes Angular signals to provide deep reactivity, ensuring your components\n * update automatically when the locale changes.\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param locale - Optional locale to override the current context locale.\n * @returns The transformed dictionary content.\n *\n * @example\n * ```ts\n * import { Component } from '@angular/core';\n * import { useIntlayer } from 'angular-intlayer';\n *\n * @Component({\n * standalone: true,\n * selector: 'app-my-component',\n * template: `<div>{{ content().myField.value }}</div>`,\n * })\n * export class MyComponent {\n * content = useIntlayer('my-dictionary-key');\n * }\n * ```\n */\nexport const useIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n): Signal<\n DeepTransformContent<DictionaryRegistryResult<T, A>, ExtractSelectorLocale<A>>\n> => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN)!;\n\n const isSelector =\n typeof localeOrSelector === 'object'
|
|
1
|
+
{"version":3,"file":"useIntlayer.cjs","names":["INTLAYER_TOKEN","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import { computed, inject, type Signal } from '@angular/core';\nimport type { DictionarySelector } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n DictionarySelectorForKey,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\n\n/** guard utility - true only for objects generated by `renderIntlayerNode()` */\nexport const isUpdatableNode = (\n val: unknown\n): val is { __update: (n: unknown) => void } =>\n !!val &&\n typeof val === 'object' &&\n typeof (val as any).__update === 'function';\n\n/**\n * Angular hook that picks one dictionary by its key and returns its reactive content.\n *\n * It utilizes Angular signals to provide deep reactivity, ensuring your components\n * update automatically when the locale changes.\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param locale - Optional locale to override the current context locale.\n * @returns The transformed dictionary content.\n *\n * @example\n * ```ts\n * import { Component } from '@angular/core';\n * import { useIntlayer } from 'angular-intlayer';\n *\n * @Component({\n * standalone: true,\n * selector: 'app-my-component',\n * template: `<div>{{ content().myField.value }}</div>`,\n * })\n * export class MyComponent {\n * content = useIntlayer('my-dictionary-key');\n * }\n * ```\n */\nexport const useIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n): Signal<\n DeepTransformContent<DictionaryRegistryResult<T, A>, ExtractSelectorLocale<A>>\n> => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN)!;\n\n const isSelector =\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&\n typeof localeOrSelector === 'object' &&\n localeOrSelector !== null;\n\n /** a *stable* reactive dictionary object */\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n const content = computed(() => {\n const currentLocale = intlayer.locale();\n\n if (isSelector) {\n return getIntlayer(key, {\n ...localeOrSelector,\n locale: localeOrSelector.locale ?? currentLocale,\n } as A) as any;\n }\n\n return getIntlayer(key, (localeOrSelector ?? currentLocale) as A) as any;\n });\n\n return content; // all consumers keep full reactivity\n};\n"],"mappings":";;;;;;;;AAeA,MAAa,mBACX,QAEA,CAAC,CAAC,OACF,OAAO,QAAQ,YACf,OAAQ,IAAY,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BnC,MAAa,eAIX,KACA,qBAGG;CACH,MAAM,qCAAoCA,4CAAe;CAEzD,MAAM,aACJ,QAAQ,IAAI,iCAAiC,WAC7C,OAAO,qBAAqB,YAC5B,qBAAqB;AAiBvB,0CAb+B;EAC7B,MAAM,gBAAgB,SAAS,QAAQ;AAEvC,MAAI,WACF,QAAOC,gCAAY,KAAK;GACtB,GAAG;GACH,QAAQ,iBAAiB,UAAU;GACpC,CAAM;AAGT,SAAOA,gCAAY,KAAM,oBAAoB,cAAoB;GAGrD"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let _angular_core = require("@angular/core");
|
|
4
|
+
let _intlayer_core_localization = require("@intlayer/core/localization");
|
|
5
|
+
|
|
6
|
+
//#region src/client/usePathname.ts
|
|
7
|
+
/**
|
|
8
|
+
* Angular hook that returns a signal containing the current pathname with
|
|
9
|
+
* the locale segment removed.
|
|
10
|
+
*
|
|
11
|
+
* Reacts to browser back/forward navigation via the `popstate` event.
|
|
12
|
+
* Uses `DestroyRef` to clean up the event listener when the component is destroyed.
|
|
13
|
+
* Falls back to an empty string during server-side rendering.
|
|
14
|
+
*
|
|
15
|
+
* @returns A signal containing the current pathname without the locale prefix.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { Component } from '@angular/core';
|
|
20
|
+
* import { usePathname } from 'angular-intlayer';
|
|
21
|
+
*
|
|
22
|
+
* @Component({
|
|
23
|
+
* standalone: true,
|
|
24
|
+
* selector: 'app-nav-item',
|
|
25
|
+
* template: `
|
|
26
|
+
* <a [class.active]="pathname() === '/dashboard'" href="/dashboard">
|
|
27
|
+
* Dashboard
|
|
28
|
+
* </a>
|
|
29
|
+
* `,
|
|
30
|
+
* })
|
|
31
|
+
* export class NavItem {
|
|
32
|
+
* readonly pathname = usePathname();
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
const usePathname = () => {
|
|
37
|
+
const destroyRef = (0, _angular_core.inject)(_angular_core.DestroyRef);
|
|
38
|
+
const rawPathname = (0, _angular_core.signal)(typeof window !== "undefined" ? window.location.pathname : "");
|
|
39
|
+
if (typeof window !== "undefined") {
|
|
40
|
+
const handleLocationChange = () => {
|
|
41
|
+
rawPathname.set(window.location.pathname);
|
|
42
|
+
};
|
|
43
|
+
window.addEventListener("popstate", handleLocationChange);
|
|
44
|
+
destroyRef.onDestroy(() => {
|
|
45
|
+
window.removeEventListener("popstate", handleLocationChange);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return (0, _angular_core.computed)(() => (0, _intlayer_core_localization.getPathWithoutLocale)(rawPathname()));
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
exports.usePathname = usePathname;
|
|
53
|
+
//# sourceMappingURL=usePathname.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePathname.cjs","names":["DestroyRef"],"sources":["../../../src/client/usePathname.ts"],"sourcesContent":["import {\n computed,\n DestroyRef,\n inject,\n type Signal,\n signal,\n} from '@angular/core';\nimport { getPathWithoutLocale } from '@intlayer/core/localization';\n\n/**\n * Angular hook that returns a signal containing the current pathname with\n * the locale segment removed.\n *\n * Reacts to browser back/forward navigation via the `popstate` event.\n * Uses `DestroyRef` to clean up the event listener when the component is destroyed.\n * Falls back to an empty string during server-side rendering.\n *\n * @returns A signal containing the current pathname without the locale prefix.\n *\n * @example\n * ```ts\n * import { Component } from '@angular/core';\n * import { usePathname } from 'angular-intlayer';\n *\n * @Component({\n * standalone: true,\n * selector: 'app-nav-item',\n * template: `\n * <a [class.active]=\"pathname() === '/dashboard'\" href=\"/dashboard\">\n * Dashboard\n * </a>\n * `,\n * })\n * export class NavItem {\n * readonly pathname = usePathname();\n * }\n * ```\n */\nexport const usePathname = (): Signal<string> => {\n const destroyRef = inject(DestroyRef);\n\n const rawPathname = signal<string>(\n typeof window !== 'undefined' ? window.location.pathname : ''\n );\n\n if (typeof window !== 'undefined') {\n const handleLocationChange = (): void => {\n rawPathname.set(window.location.pathname);\n };\n\n window.addEventListener('popstate', handleLocationChange);\n\n destroyRef.onDestroy(() => {\n window.removeEventListener('popstate', handleLocationChange);\n });\n }\n\n return computed(() => getPathWithoutLocale(rawPathname()));\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,oBAAoC;CAC/C,MAAM,uCAAoBA,yBAAW;CAErC,MAAM,wCACJ,OAAO,WAAW,cAAc,OAAO,SAAS,WAAW,GAC5D;AAED,KAAI,OAAO,WAAW,aAAa;EACjC,MAAM,6BAAmC;AACvC,eAAY,IAAI,OAAO,SAAS,SAAS;;AAG3C,SAAO,iBAAiB,YAAY,qBAAqB;AAEzD,aAAW,gBAAgB;AACzB,UAAO,oBAAoB,YAAY,qBAAqB;IAC5D;;AAGJ,gGAA2C,aAAa,CAAC,CAAC"}
|
|
@@ -18,7 +18,7 @@ let _intlayer_editor_isEnabled = require("@intlayer/editor/isEnabled");
|
|
|
18
18
|
* so it still works when called directly from a component.
|
|
19
19
|
*/
|
|
20
20
|
const useEditor = (client) => {
|
|
21
|
-
if (process.env
|
|
21
|
+
if (process.env.INTLAYER_EDITOR_ENABLED === "false" || !_intlayer_editor_isEnabled.isEnabled) return;
|
|
22
22
|
const destroyRef = (0, _angular_core.inject)(_angular_core.DestroyRef, { optional: true });
|
|
23
23
|
const injector = (0, _angular_core.inject)(_angular_core.Injector);
|
|
24
24
|
const resolvedClient = client ?? (0, _angular_core.inject)(require_client_intlayerToken.INTLAYER_TOKEN, { optional: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEditor.cjs","names":["isEnabled","DestroyRef","Injector","INTLAYER_TOKEN"],"sources":["../../../src/editor/useEditor.ts"],"sourcesContent":["import {\n DestroyRef,\n effect,\n Injector,\n inject,\n provideAppInitializer,\n runInInjectionContext,\n signal,\n} from '@angular/core';\nimport type { EditorStateManager } from '@intlayer/editor';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { Locale } from '@intlayer/types/allLocales';\n// Import from the standalone token file to avoid a circular dependency:\n// installIntlayer.ts → useEditor.ts → ../client → installIntlayer.ts\nimport { INTLAYER_TOKEN, type IntlayerProvider } from '../client/intlayerToken';\n\n/**\n * Initialises the Intlayer editor client singleton when the editor is enabled.\n * Syncs the current locale from the provided Intlayer client into the editor\n * manager so the editor always knows which locale the app is displaying.\n *\n * Must be called inside an Angular injection context (e.g. a component\n * constructor, `provideAppInitializer`, or `runInInjectionContext`).\n *\n * @param client - The IntlayerProvider instance to sync locale from.\n * When omitted the function injects `INTLAYER_TOKEN` from the DI tree,\n * so it still works when called directly from a component.\n */\nexport const useEditor = (client?: IntlayerProvider | null): void => {\n if (process.env
|
|
1
|
+
{"version":3,"file":"useEditor.cjs","names":["isEnabled","DestroyRef","Injector","INTLAYER_TOKEN"],"sources":["../../../src/editor/useEditor.ts"],"sourcesContent":["import {\n DestroyRef,\n effect,\n Injector,\n inject,\n provideAppInitializer,\n runInInjectionContext,\n signal,\n} from '@angular/core';\nimport type { EditorStateManager } from '@intlayer/editor';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { Locale } from '@intlayer/types/allLocales';\n// Import from the standalone token file to avoid a circular dependency:\n// installIntlayer.ts → useEditor.ts → ../client → installIntlayer.ts\nimport { INTLAYER_TOKEN, type IntlayerProvider } from '../client/intlayerToken';\n\n/**\n * Initialises the Intlayer editor client singleton when the editor is enabled.\n * Syncs the current locale from the provided Intlayer client into the editor\n * manager so the editor always knows which locale the app is displaying.\n *\n * Must be called inside an Angular injection context (e.g. a component\n * constructor, `provideAppInitializer`, or `runInInjectionContext`).\n *\n * @param client - The IntlayerProvider instance to sync locale from.\n * When omitted the function injects `INTLAYER_TOKEN` from the DI tree,\n * so it still works when called directly from a component.\n */\nexport const useEditor = (client?: IntlayerProvider | null): void => {\n if (process.env.INTLAYER_EDITOR_ENABLED === 'false' || !isEnabled) return;\n\n const destroyRef = inject(DestroyRef, { optional: true });\n const injector = inject(Injector);\n\n // Resolve the client: use the passed-in reference or fall back to injection.\n const resolvedClient =\n client ??\n inject<IntlayerProvider>(INTLAYER_TOKEN, { optional: true } as any);\n\n // `manager` signal is set once the async import resolves.\n // Using a signal lets an `effect()` react to it becoming available.\n const manager = signal<EditorStateManager | null>(null);\n\n // Guard: prevents the async callback from acting after the view is destroyed.\n let stopped = false;\n\n // Initialise the editor client\n import('@intlayer/editor').then(({ initEditorClient }) => {\n if (stopped) return;\n manager.set(initEditorClient());\n });\n\n // Keep the editor locale in sync with the Angular locale signal\n const effectRef = runInInjectionContext(injector, () =>\n effect(() => {\n const m = manager();\n const locale = resolvedClient?.locale();\n if (m && locale) m.currentLocale.set(locale as Locale);\n })\n );\n\n // Tear down on destroy\n destroyRef?.onDestroy(() => {\n stopped = true;\n effectRef.destroy();\n manager.set(null);\n import('@intlayer/editor').then(({ stopEditorClient }) => {\n stopEditorClient();\n });\n });\n};\n\n/**\n * Angular provider that wires `useEditor` into the application initialisation\n * phase via `provideAppInitializer`.\n *\n * `provideIntlayer()` already calls this internally, so you only need this\n * function when you want to manage providers individually.\n *\n * @example\n * ```ts\n * // app.config.ts\n * import { provideIntlayer, provideIntlayerEditor } from 'angular-intlayer';\n *\n * export const appConfig: ApplicationConfig = {\n * providers: [provideIntlayer(), provideIntlayerEditor()],\n * };\n * ```\n */\nexport const provideIntlayerEditor = (client?: IntlayerProvider | null) =>\n provideAppInitializer(() => useEditor(client));\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA4BA,MAAa,aAAa,WAA2C;AACnE,KAAI,QAAQ,IAAI,4BAA4B,WAAW,CAACA,qCAAW;CAEnE,MAAM,uCAAoBC,0BAAY,EAAE,UAAU,MAAM,CAAC;CACzD,MAAM,qCAAkBC,uBAAS;CAGjC,MAAM,iBACJ,oCACyBC,6CAAgB,EAAE,UAAU,MAAM,CAAQ;CAIrE,MAAM,oCAA4C,KAAK;CAGvD,IAAI,UAAU;AAGd,QAAO,oBAAoB,MAAM,EAAE,uBAAuB;AACxD,MAAI,QAAS;AACb,UAAQ,IAAI,kBAAkB,CAAC;GAC/B;CAGF,MAAM,qDAAkC,gDACzB;EACX,MAAM,IAAI,SAAS;EACnB,MAAM,SAAS,gBAAgB,QAAQ;AACvC,MAAI,KAAK,OAAQ,GAAE,cAAc,IAAI,OAAiB;GACtD,CACH;AAGD,aAAY,gBAAgB;AAC1B,YAAU;AACV,YAAU,SAAS;AACnB,UAAQ,IAAI,KAAK;AACjB,SAAO,oBAAoB,MAAM,EAAE,uBAAuB;AACxD,qBAAkB;IAClB;GACF;;;;;;;;;;;;;;;;;;;AAoBJ,MAAa,yBAAyB,0DACR,UAAU,OAAO,CAAC"}
|
|
@@ -7,7 +7,7 @@ let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
|
7
7
|
/**
|
|
8
8
|
* Transforms a dictionary (or qualified dictionary group) and returns its
|
|
9
9
|
* content for the given locale or selector (`{ item }`, `{ variant }`,
|
|
10
|
-
*
|
|
10
|
+
* optionally combined with `locale`).
|
|
11
11
|
*/
|
|
12
12
|
const getDictionary = (dictionary, localeOrSelector) => {
|
|
13
13
|
return (0, _intlayer_core_interpreter.getDictionary)(dictionary, localeOrSelector, require_plugins.getPlugins(typeof localeOrSelector === "object" && localeOrSelector !== null ? localeOrSelector.locale : localeOrSelector));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDictionary.cjs","names":["getPlugins"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import { getDictionary as getDictionaryCore } from '@intlayer/core/interpreter';\nimport type {\n Dictionary,\n
|
|
1
|
+
{"version":3,"file":"getDictionary.cjs","names":["getPlugins"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import { getDictionary as getDictionaryCore } from '@intlayer/core/interpreter';\nimport type {\n Dictionary,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\n/**\n * Transforms a dictionary (or qualified dictionary group) and returns its\n * content for the given locale or selector (`{ item }`, `{ variant }`,\n * optionally combined with `locale`).\n */\nexport const getDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n): DeepTransformContent<\n ResolveQualifiedDictionaryContent<T, A>,\n ExtractSelectorLocale<A>\n> => {\n const locale = (\n typeof localeOrSelector === 'object' && localeOrSelector !== null\n ? localeOrSelector.locale\n : localeOrSelector\n ) as LocalesValues | undefined;\n\n return getDictionaryCore(\n dictionary,\n localeOrSelector,\n getPlugins(locale)\n ) as any;\n};\n"],"mappings":";;;;;;;;;;;AAmBA,MAAa,iBAMX,YACA,qBAIG;AAOH,sDACE,YACA,kBACAA,2BARA,OAAO,qBAAqB,YAAY,qBAAqB,OACzD,iBAAiB,SACjB,iBAMc,CACnB"}
|
package/dist/cjs/getIntlayer.cjs
CHANGED
|
@@ -6,7 +6,7 @@ let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
|
6
6
|
//#region src/getIntlayer.ts
|
|
7
7
|
/**
|
|
8
8
|
* Picks one dictionary by its key and returns its content for the given
|
|
9
|
-
* locale or selector (`{ item }`, `{ variant }`,
|
|
9
|
+
* locale or selector (`{ item }`, `{ variant }`,
|
|
10
10
|
* optionally combined with `locale`).
|
|
11
11
|
*/
|
|
12
12
|
const getIntlayer = (key, localeOrSelector) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIntlayer.cjs","names":["getPlugins"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore } from '@intlayer/core/interpreter';\nimport type {
|
|
1
|
+
{"version":3,"file":"getIntlayer.cjs","names":["getPlugins"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore } from '@intlayer/core/interpreter';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n DictionarySelectorForKey,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\n/**\n * Picks one dictionary by its key and returns its content for the given\n * locale or selector (`{ item }`, `{ variant }`,\n * optionally combined with `locale`).\n */\nexport const getIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n): DeepTransformContent<\n DictionaryRegistryResult<T, A>,\n ExtractSelectorLocale<A>\n> => {\n const locale = (\n typeof localeOrSelector === 'object' && localeOrSelector !== null\n ? localeOrSelector.locale\n : localeOrSelector\n ) as LocalesValues | undefined;\n\n return getIntlayerCore(key, localeOrSelector, getPlugins(locale)) as any;\n};\n"],"mappings":";;;;;;;;;;;AAgBA,MAAa,eAIX,KACA,qBAIG;AAOH,oDAAuB,KAAK,kBAAkBA,2BAL5C,OAAO,qBAAqB,YAAY,qBAAqB,OACzD,iBAAiB,SACjB,iBAG0D,CAAC"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -10,6 +10,7 @@ const require_client_useLoadDynamic = require('./client/useLoadDynamic.cjs');
|
|
|
10
10
|
const require_client_useDictionaryDynamic = require('./client/useDictionaryDynamic.cjs');
|
|
11
11
|
const require_client_useIntlayer = require('./client/useIntlayer.cjs');
|
|
12
12
|
const require_client_useLocale = require('./client/useLocale.cjs');
|
|
13
|
+
const require_client_usePathname = require('./client/usePathname.cjs');
|
|
13
14
|
const require_UI_IntlayerNode_component = require('./UI/IntlayerNode.component.cjs');
|
|
14
15
|
|
|
15
16
|
exports.INTLAYER_TOKEN = require_client_intlayerToken.INTLAYER_TOKEN;
|
|
@@ -37,4 +38,5 @@ exports.useDictionaryAsync = require_client_useDictionaryAsync.useDictionaryAsyn
|
|
|
37
38
|
exports.useDictionaryDynamic = require_client_useDictionaryDynamic.useDictionaryDynamic;
|
|
38
39
|
exports.useIntlayer = require_client_useIntlayer.useIntlayer;
|
|
39
40
|
exports.useLoadDynamic = require_client_useLoadDynamic.useLoadDynamic;
|
|
40
|
-
exports.useLocale = require_client_useLocale.useLocale;
|
|
41
|
+
exports.useLocale = require_client_useLocale.useLocale;
|
|
42
|
+
exports.usePathname = require_client_usePathname.usePathname;
|
package/dist/cjs/plugins.cjs
CHANGED
|
@@ -10,7 +10,7 @@ _intlayer_types_nodeType = require_runtime.__toESM(_intlayer_types_nodeType);
|
|
|
10
10
|
|
|
11
11
|
//#region src/plugins.ts
|
|
12
12
|
let _markdownInstall = null;
|
|
13
|
-
if (process.env
|
|
13
|
+
if (process.env.INTLAYER_NODE_TYPE_MARKDOWN !== "false" || process.env.INTLAYER_NODE_TYPE_HTML !== "false") Promise.resolve().then(() => require("./markdown/installIntlayerMarkdown.cjs")).then((m) => {
|
|
14
14
|
_markdownInstall = m;
|
|
15
15
|
});
|
|
16
16
|
/** ---------------------------------------------
|
|
@@ -44,7 +44,7 @@ const intlayerNodePlugins = {
|
|
|
44
44
|
...rest,
|
|
45
45
|
value: children,
|
|
46
46
|
children: () => ({
|
|
47
|
-
component: process.env
|
|
47
|
+
component: process.env.INTLAYER_EDITOR_ENABLED === "false" || !_intlayer_config_built.editor.enabled ? children : require_editor_ContentSelector_component.ContentSelectorWrapperComponent,
|
|
48
48
|
props: {
|
|
49
49
|
dictionaryKey: rest.dictionaryKey,
|
|
50
50
|
keyPath: rest.keyPath
|
|
@@ -54,7 +54,7 @@ const intlayerNodePlugins = {
|
|
|
54
54
|
})
|
|
55
55
|
};
|
|
56
56
|
/** Markdown string plugin. Replaces string node with a component that render the markdown. */
|
|
57
|
-
const markdownStringPlugin = process.env
|
|
57
|
+
const markdownStringPlugin = process.env.INTLAYER_NODE_TYPE_MARKDOWN === "false" ? _intlayer_core_interpreter.fallbackPlugin : {
|
|
58
58
|
id: "markdown-string-plugin",
|
|
59
59
|
canHandle: (node) => typeof node === "string",
|
|
60
60
|
transform: (node, props, deepTransformNode) => {
|
|
@@ -75,7 +75,7 @@ const markdownStringPlugin = process.env["INTLAYER_NODE_TYPE_MARKDOWN"] === "fal
|
|
|
75
75
|
const render = (components) => require_renderIntlayerNode.renderIntlayerNode({
|
|
76
76
|
...rest,
|
|
77
77
|
value: node,
|
|
78
|
-
children: process.env
|
|
78
|
+
children: process.env.INTLAYER_EDITOR_ENABLED === "false" || !_intlayer_config_built.editor.enabled ? () => {
|
|
79
79
|
const { renderMarkdown } = _markdownInstall?.useMarkdown() ?? { renderMarkdown: () => node };
|
|
80
80
|
return renderMarkdown(node, components);
|
|
81
81
|
} : () => ({
|
|
@@ -117,7 +117,7 @@ const markdownStringPlugin = process.env["INTLAYER_NODE_TYPE_MARKDOWN"] === "fal
|
|
|
117
117
|
return createProxy(render());
|
|
118
118
|
}
|
|
119
119
|
};
|
|
120
|
-
const markdownPlugin = process.env
|
|
120
|
+
const markdownPlugin = process.env.INTLAYER_NODE_TYPE_MARKDOWN === "false" ? _intlayer_core_interpreter.fallbackPlugin : {
|
|
121
121
|
id: "markdown-plugin",
|
|
122
122
|
canHandle: (node) => typeof node === "object" && node?.nodeType === _intlayer_types_nodeType.MARKDOWN,
|
|
123
123
|
transform: (node, props, deepTransformNode) => {
|
|
@@ -132,7 +132,7 @@ const markdownPlugin = process.env["INTLAYER_NODE_TYPE_MARKDOWN"] === "false" ?
|
|
|
132
132
|
}
|
|
133
133
|
};
|
|
134
134
|
/** HTML plugin. Replaces node with a function that takes components => IntlayerNode. */
|
|
135
|
-
const htmlPlugin = process.env
|
|
135
|
+
const htmlPlugin = process.env.INTLAYER_NODE_TYPE_HTML === "false" ? _intlayer_core_interpreter.fallbackPlugin : {
|
|
136
136
|
id: "html-plugin",
|
|
137
137
|
canHandle: (node) => typeof node === "object" && node?.nodeType === _intlayer_types_nodeType.HTML,
|
|
138
138
|
transform: (node, props) => {
|
|
@@ -141,7 +141,7 @@ const htmlPlugin = process.env["INTLAYER_NODE_TYPE_HTML"] === "false" ? _intlaye
|
|
|
141
141
|
const render = (userComponents) => require_renderIntlayerNode.renderIntlayerNode({
|
|
142
142
|
...rest,
|
|
143
143
|
value: html,
|
|
144
|
-
children: process.env
|
|
144
|
+
children: process.env.INTLAYER_EDITOR_ENABLED === "false" || !_intlayer_config_built.editor.enabled ? html : () => ({
|
|
145
145
|
component: require_editor_ContentSelector_component.ContentSelectorWrapperComponent,
|
|
146
146
|
props: {
|
|
147
147
|
dictionaryKey: rest.dictionaryKey,
|
|
@@ -177,7 +177,7 @@ const htmlPlugin = process.env["INTLAYER_NODE_TYPE_HTML"] === "false" ? _intlaye
|
|
|
177
177
|
return createProxy(render());
|
|
178
178
|
}
|
|
179
179
|
};
|
|
180
|
-
const insertionPlugin = process.env
|
|
180
|
+
const insertionPlugin = process.env.INTLAYER_NODE_TYPE_INSERTION === "false" ? _intlayer_core_interpreter.fallbackPlugin : {
|
|
181
181
|
id: "insertion-plugin",
|
|
182
182
|
canHandle: (node) => typeof node === "object" && node?.nodeType === _intlayer_types_nodeType.INSERTION,
|
|
183
183
|
transform: (node, props) => {
|
package/dist/cjs/plugins.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.cjs","names":["renderIntlayerNode","editor","ContentSelectorWrapperComponent","fallbackPlugin","compile","NodeTypes","internationalization","enumerationPlugin","conditionPlugin","filePlugin","genderPlugin"],"sources":["../../src/plugins.ts"],"sourcesContent":["import { editor, internationalization } from '@intlayer/config/built';\nimport {\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n fallbackPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n nestedPlugin,\n type Plugins,\n pluralPlugin,\n translationPlugin,\n} from '@intlayer/core/interpreter';\nimport type { MarkdownContent } from '@intlayer/core/markdown';\nimport { compile, getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type { HTMLContent, InsertionContent } from '@intlayer/core/transpiler';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport { ContentSelectorWrapperComponent } from './editor/ContentSelector.component';\nimport { renderIntlayerNode } from './renderIntlayerNode';\n\nlet _markdownInstall: {\n htmlRuntime: any;\n useMarkdown: () => { renderMarkdown: (s: string, components?: any) => any };\n} | null = null;\nif (\n process.env['INTLAYER_NODE_TYPE_MARKDOWN'] !== 'false' ||\n process.env['INTLAYER_NODE_TYPE_HTML'] !== 'false'\n) {\n void import('./markdown/installIntlayerMarkdown').then((m) => {\n _markdownInstall = m as any;\n });\n}\n\n/** ---------------------------------------------\n * UTILS\n * --------------------------------------------- */\n\nconst createRuntimeWithOverides = (baseRuntime: any, overrides: any) => ({\n ...baseRuntime,\n createElement: (tag: string, props: any, ...children: any[]) => {\n const override = overrides?.[tag];\n\n if (override) {\n const newProps = { ...props, ...override };\n\n // Merge class attributes intelligently\n const originalClass = props?.class || props?.className;\n const overrideClass = override.class || override.className;\n\n if (originalClass && overrideClass) {\n newProps.class = `${originalClass} ${overrideClass}`;\n newProps.className = undefined;\n }\n\n return baseRuntime.createElement(tag, newProps, ...children);\n }\n\n return baseRuntime.createElement(tag, props, ...children);\n },\n});\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\nexport interface IntlayerNode<T, P = {}> {\n value: T;\n children?: any;\n additionalProps?: P;\n}\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const intlayerNodePlugins: Plugins = {\n id: 'intlayer-node-plugin',\n canHandle: (node) =>\n typeof node === 'bigint' ||\n typeof node === 'string' ||\n typeof node === 'number',\n transform: (_node, { children, ...rest }) =>\n renderIntlayerNode({\n ...rest,\n value: children,\n children: () => ({\n component:\n process.env['INTLAYER_EDITOR_ENABLED'] === 'false' || !editor.enabled\n ? children\n : ContentSelectorWrapperComponent,\n props: {\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n },\n children: children,\n }),\n }),\n};\n\n/**\n * MARKDOWN PLUGIN\n */\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<string, { metadata: DeepTransformContent<string> }>\n : never;\n\n/** Markdown string plugin. Replaces string node with a component that render the markdown. */\nexport const markdownStringPlugin: Plugins =\n process.env['INTLAYER_NODE_TYPE_MARKDOWN'] === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, props, deepTransformNode) => {\n const {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n } = props;\n\n const metadata = getMarkdownMetadata(node) ?? {};\n\n const metadataPlugins: Plugins = {\n id: 'markdown-metadata-plugin',\n canHandle: (metadataNode) =>\n typeof metadataNode === 'string' ||\n typeof metadataNode === 'number' ||\n typeof metadataNode === 'boolean' ||\n !metadataNode,\n transform: (metadataNode, props) =>\n renderIntlayerNode({\n ...props,\n value: metadataNode,\n children: node,\n }),\n };\n\n // Transform metadata while keeping the same structure\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n const render = (components?: any) =>\n renderIntlayerNode({\n ...rest,\n value: node,\n children:\n process.env['INTLAYER_EDITOR_ENABLED'] === 'false' ||\n !editor.enabled\n ? () => {\n const { renderMarkdown } =\n _markdownInstall?.useMarkdown() ?? {\n renderMarkdown: () => node,\n };\n return renderMarkdown(node, components);\n }\n : () => ({\n component: ContentSelectorWrapperComponent,\n props: {\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n ...components,\n },\n children: () => {\n const { renderMarkdown } =\n _markdownInstall?.useMarkdown() ?? {\n renderMarkdown: () => node,\n };\n return renderMarkdown(node, components);\n },\n }),\n additionalProps: {\n metadata: metadataNodes,\n },\n });\n\n const createProxy = (element: any, components?: any) =>\n new Proxy(element, {\n get(target, prop, receiver) {\n if (prop === 'value') {\n return node;\n }\n if (prop === 'metadata') {\n return metadataNodes;\n }\n\n if (prop === 'toString') {\n return () => {\n const htmlRuntime = _markdownInstall?.htmlRuntime;\n if (!htmlRuntime || !compile) return node;\n const runtime = components\n ? createRuntimeWithOverides(htmlRuntime, components)\n : htmlRuntime;\n return compile(node, { runtime }) as string;\n };\n }\n\n if (prop === Symbol.toPrimitive) {\n return () => {\n const htmlRuntime = _markdownInstall?.htmlRuntime;\n if (!htmlRuntime || !compile) return node;\n const runtime = components\n ? createRuntimeWithOverides(htmlRuntime, components)\n : htmlRuntime;\n return compile(node, { runtime }) as string;\n };\n }\n\n if (prop === 'use') {\n return (newComponents?: any) => {\n const mergedComponents = {\n ...components,\n ...newComponents,\n };\n return createProxy(\n render(mergedComponents),\n mergedComponents\n );\n };\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n\n return createProxy(render() as any);\n },\n };\n\nexport type MarkdownCond<T, _S, _L extends LocalesValues> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.MARKDOWN]: infer M;\n tags?: infer U;\n metadata?: infer V;\n}\n ? IntlayerNode<\n M,\n {\n use: (components?: Record<keyof U, any>) => any;\n metadata: DeepTransformContent<V>;\n }\n >\n : never;\n\nexport const markdownPlugin: Plugins =\n process.env['INTLAYER_NODE_TYPE_MARKDOWN'] === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.MARKDOWN,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.MARKDOWN,\n },\n ];\n\n const children = node[NodeTypes.MARKDOWN];\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [markdownStringPlugin, ...(props.plugins ?? [])],\n });\n },\n };\n\n/** ---------------------------------------------\n * HTML PLUGIN\n * --------------------------------------------- */\n\n/**\n * HTML conditional type.\n *\n * This ensures type safety:\n * - `html('<div>Hello <CustomComponent /></div>').use({ CustomComponent: ... })` - optional but typed\n */\nexport type HTMLPluginCond<T, _S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.HTML]: infer I;\n tags?: infer U;\n}\n ? IntlayerNode<\n I,\n {\n use: (components?: Record<keyof U, any>) => any;\n }\n >\n : never;\n\n/** HTML plugin. Replaces node with a function that takes components => IntlayerNode. */\nexport const htmlPlugin: Plugins =\n process.env['INTLAYER_NODE_TYPE_HTML'] === 'false'\n ? fallbackPlugin\n : {\n id: 'html-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.HTML,\n\n transform: (node: HTMLContent<string>, props) => {\n const html = node[NodeTypes.HTML];\n const { plugins, ...rest } = props;\n\n // Type-safe render function that accepts properly typed components\n const render = (userComponents?: any) =>\n renderIntlayerNode({\n ...rest,\n value: html,\n children:\n process.env['INTLAYER_EDITOR_ENABLED'] === 'false' ||\n !editor.enabled\n ? html\n : () => ({\n component: ContentSelectorWrapperComponent,\n props: {\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n ...userComponents,\n },\n children: html,\n }),\n });\n\n const createProxy = (element: any, components?: any) =>\n new Proxy(element, {\n get(target, prop, receiver) {\n if (prop === 'value') {\n return html;\n }\n\n if (prop === 'toString') {\n return () => {\n if (\n !components ||\n (typeof components === 'object' &&\n Object.keys(components).length === 0)\n ) {\n return String(html);\n }\n const htmlRuntime = _markdownInstall?.htmlRuntime;\n if (!htmlRuntime || !compile) return String(html);\n const runtime = createRuntimeWithOverides(\n htmlRuntime,\n components\n );\n return compile(html, { runtime }) as string;\n };\n }\n\n if (prop === Symbol.toPrimitive) {\n return () => {\n if (\n !components ||\n (typeof components === 'object' &&\n Object.keys(components).length === 0)\n ) {\n return String(html);\n }\n const htmlRuntime = _markdownInstall?.htmlRuntime;\n if (!htmlRuntime || !compile) return String(html);\n const runtime = createRuntimeWithOverides(\n htmlRuntime,\n components\n );\n return compile(html, { runtime }) as string;\n };\n }\n\n if (prop === 'use') {\n // Return a properly typed function based on custom components\n return (userComponents?: any) => {\n const mergedComponents = {\n ...components,\n ...userComponents,\n };\n return createProxy(\n render(mergedComponents),\n mergedComponents\n );\n };\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n\n return createProxy(render() as any);\n },\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\n/**\n * Insertion conditional type.\n */\nexport type InsertionPluginCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer _I;\n}\n ? (args: Record<string, string | number>) => string\n : never;\n\nexport const insertionPlugin: Plugins =\n process.env['INTLAYER_NODE_TYPE_INSERTION'] === 'false'\n ? fallbackPlugin\n : {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.INSERTION,\n transform: (node: InsertionContent, props) => {\n const { plugins, ...rest } = props;\n\n // Return a function that performs the interpolation\n const render = (args: Record<string, string | number> = {}) => {\n let text = node[NodeTypes.INSERTION] as string;\n if (args) {\n Object.entries(args).forEach(([key, value]) => {\n text = text.replace(\n new RegExp(`{{\\\\s*${key}\\\\s*}}`, 'g'),\n String(value)\n );\n });\n }\n return text;\n };\n\n return renderIntlayerNode({\n ...rest,\n value: render as any,\n children: render,\n });\n },\n };\n\nexport interface IInterpreterPluginAngular<T, S, L extends LocalesValues> {\n angularIntlayerNode: IntlayerNodeCond<T>;\n angularMarkdown: MarkdownCond<T, S, L>;\n angularHtml: HTMLPluginCond<T, S, L>;\n angularInsertion: InsertionPluginCond<T>;\n}\n\n/**\n * Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.\n *\n * Otherwise the the `angular-intlayer` plugins will override the types of `intlayer` functions.\n */\nexport type IInterpreterPluginState = Omit<\n IInterpreterPluginStateCore,\n 'insertion' // Remove insertion type from core package\n> & {\n angularIntlayerNode: true;\n angularMarkdown: true;\n angularHtml: true;\n angularInsertion: true;\n};\n\nexport type DeepTransformContent<\n T,\n L extends LocalesValues = DeclaredLocales,\n> = DeepTransformContentCore<T, IInterpreterPluginState, L>;\n\nconst pluginsCache = new Map<string, Plugins[]>();\n\n/**\n * Get the plugins array for Angular content transformation.\n * This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.\n */\nexport const getPlugins = (\n locale?: LocalesValues,\n fallback: boolean = true\n): Plugins[] => {\n const currentLocale = locale ?? internationalization.defaultLocale;\n const cacheKey = `${currentLocale}_${fallback}`;\n\n if (pluginsCache.has(cacheKey)) {\n return pluginsCache.get(cacheKey)!;\n }\n\n const plugins = [\n translationPlugin(\n locale ?? internationalization.defaultLocale,\n fallback ? internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n pluralPlugin(locale ?? internationalization.defaultLocale),\n conditionPlugin,\n nestedPlugin(locale ?? internationalization.defaultLocale),\n filePlugin,\n genderPlugin,\n intlayerNodePlugins,\n markdownPlugin,\n htmlPlugin,\n insertionPlugin,\n ] as Plugins[];\n\n pluginsCache.set(cacheKey, plugins);\n\n return plugins;\n};\n"],"mappings":";;;;;;;;;;;AA2BA,IAAI,mBAGO;AACX,IACE,QAAQ,IAAI,mCAAmC,WAC/C,QAAQ,IAAI,+BAA+B,QAE3C,sCAAK,2CAA6C,MAAM,MAAM;AAC5D,oBAAmB;EACnB;;;;AAOJ,MAAM,6BAA6B,aAAkB,eAAoB;CACvE,GAAG;CACH,gBAAgB,KAAa,OAAY,GAAG,aAAoB;EAC9D,MAAM,WAAW,YAAY;AAE7B,MAAI,UAAU;GACZ,MAAM,WAAW;IAAE,GAAG;IAAO,GAAG;IAAU;GAG1C,MAAM,gBAAgB,OAAO,SAAS,OAAO;GAC7C,MAAM,gBAAgB,SAAS,SAAS,SAAS;AAEjD,OAAI,iBAAiB,eAAe;AAClC,aAAS,QAAQ,GAAG,cAAc,GAAG;AACrC,aAAS,YAAY;;AAGvB,UAAO,YAAY,cAAc,KAAK,UAAU,GAAG,SAAS;;AAG9D,SAAO,YAAY,cAAc,KAAK,OAAO,GAAG,SAAS;;CAE5D;;AAiBD,MAAa,sBAA+B;CAC1C,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAChB,O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J,YAAY,SACV,OAAO,SAAS,YAAY,MAAM,aAAaE,yBAAU;CAC3D,YAAY,MAAwB,UAAU;EAC5C,MAAM,EAAE,SAAS,GAAG,SAAS;EAG7B,MAAM,UAAU,OAAwC,EAAE,KAAK;GAC7D,IAAI,OAAO,KAAKA,yBAAU;AAC1B,OAAI,KACF,QAAO,QAAQ,KAAK,CAAC,SAAS,CAAC,KAAK,WAAW;AAC7C,WAAO,KAAK,QACV,IAAI,OAAO,SAAS,IAAI,SAAS,IAAI,EACrC,OAAO,MAAM,CACd;KACD;AAEJ,UAAO;;AAGT,SAAOL,8CAAmB;GACxB,GAAG;GACH,OAAO;GACP,UAAU;GACX,CAAC;;CAEL;AA6BP,MAAM,+BAAe,IAAI,KAAwB;;;;;AAMjD,MAAa,cACX,QACA,WAAoB,SACN;CAEd,MAAM,WAAW,GADK,UAAUM,4CAAqB,cACnB,GAAG;AAErC,KAAI,aAAa,IAAI,SAAS,CAC5B,QAAO,aAAa,IAAI,SAAS;CAGnC,MAAM,UAAU;oDAEZ,UAAUA,4CAAqB,eAC/B,WAAWA,4CAAqB,gBAAgB,OACjD;EACDC;+CACa,UAAUD,4CAAqB,cAAc;EAC1DE;+CACa,UAAUF,4CAAqB,cAAc;EAC1DG;EACAC;EACA;EACA;EACA;EACA;EACD;AAED,cAAa,IAAI,UAAU,QAAQ;AAEnC,QAAO"}
|
|
1
|
+
{"version":3,"file":"plugins.cjs","names":["renderIntlayerNode","editor","ContentSelectorWrapperComponent","fallbackPlugin","compile","NodeTypes","internationalization","enumerationPlugin","conditionPlugin","filePlugin","genderPlugin"],"sources":["../../src/plugins.ts"],"sourcesContent":["import { editor, internationalization } from '@intlayer/config/built';\nimport {\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n fallbackPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n nestedPlugin,\n type Plugins,\n pluralPlugin,\n translationPlugin,\n} from '@intlayer/core/interpreter';\nimport type { MarkdownContent } from '@intlayer/core/markdown';\nimport { compile, getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type { HTMLContent, InsertionContent } from '@intlayer/core/transpiler';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport { ContentSelectorWrapperComponent } from './editor/ContentSelector.component';\nimport { renderIntlayerNode } from './renderIntlayerNode';\n\nlet _markdownInstall: {\n htmlRuntime: any;\n useMarkdown: () => { renderMarkdown: (s: string, components?: any) => any };\n} | null = null;\nif (\n process.env.INTLAYER_NODE_TYPE_MARKDOWN !== 'false' ||\n process.env.INTLAYER_NODE_TYPE_HTML !== 'false'\n) {\n void import('./markdown/installIntlayerMarkdown').then((m) => {\n _markdownInstall = m as any;\n });\n}\n\n/** ---------------------------------------------\n * UTILS\n * --------------------------------------------- */\n\nconst createRuntimeWithOverides = (baseRuntime: any, overrides: any) => ({\n ...baseRuntime,\n createElement: (tag: string, props: any, ...children: any[]) => {\n const override = overrides?.[tag];\n\n if (override) {\n const newProps = { ...props, ...override };\n\n // Merge class attributes intelligently\n const originalClass = props?.class || props?.className;\n const overrideClass = override.class || override.className;\n\n if (originalClass && overrideClass) {\n newProps.class = `${originalClass} ${overrideClass}`;\n newProps.className = undefined;\n }\n\n return baseRuntime.createElement(tag, newProps, ...children);\n }\n\n return baseRuntime.createElement(tag, props, ...children);\n },\n});\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\nexport interface IntlayerNode<T, P = {}> {\n value: T;\n children?: any;\n additionalProps?: P;\n}\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const intlayerNodePlugins: Plugins = {\n id: 'intlayer-node-plugin',\n canHandle: (node) =>\n typeof node === 'bigint' ||\n typeof node === 'string' ||\n typeof node === 'number',\n transform: (_node, { children, ...rest }) =>\n renderIntlayerNode({\n ...rest,\n value: children,\n children: () => ({\n component:\n process.env.INTLAYER_EDITOR_ENABLED === 'false' || !editor.enabled\n ? children\n : ContentSelectorWrapperComponent,\n props: {\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n },\n children: children,\n }),\n }),\n};\n\n/**\n * MARKDOWN PLUGIN\n */\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<string, { metadata: DeepTransformContent<string> }>\n : never;\n\n/** Markdown string plugin. Replaces string node with a component that render the markdown. */\nexport const markdownStringPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, props, deepTransformNode) => {\n const {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n } = props;\n\n const metadata = getMarkdownMetadata(node) ?? {};\n\n const metadataPlugins: Plugins = {\n id: 'markdown-metadata-plugin',\n canHandle: (metadataNode) =>\n typeof metadataNode === 'string' ||\n typeof metadataNode === 'number' ||\n typeof metadataNode === 'boolean' ||\n !metadataNode,\n transform: (metadataNode, props) =>\n renderIntlayerNode({\n ...props,\n value: metadataNode,\n children: node,\n }),\n };\n\n // Transform metadata while keeping the same structure\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n const render = (components?: any) =>\n renderIntlayerNode({\n ...rest,\n value: node,\n children:\n process.env.INTLAYER_EDITOR_ENABLED === 'false' ||\n !editor.enabled\n ? () => {\n const { renderMarkdown } =\n _markdownInstall?.useMarkdown() ?? {\n renderMarkdown: () => node,\n };\n return renderMarkdown(node, components);\n }\n : () => ({\n component: ContentSelectorWrapperComponent,\n props: {\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n ...components,\n },\n children: () => {\n const { renderMarkdown } =\n _markdownInstall?.useMarkdown() ?? {\n renderMarkdown: () => node,\n };\n return renderMarkdown(node, components);\n },\n }),\n additionalProps: {\n metadata: metadataNodes,\n },\n });\n\n const createProxy = (element: any, components?: any) =>\n new Proxy(element, {\n get(target, prop, receiver) {\n if (prop === 'value') {\n return node;\n }\n if (prop === 'metadata') {\n return metadataNodes;\n }\n\n if (prop === 'toString') {\n return () => {\n const htmlRuntime = _markdownInstall?.htmlRuntime;\n if (!htmlRuntime || !compile) return node;\n const runtime = components\n ? createRuntimeWithOverides(htmlRuntime, components)\n : htmlRuntime;\n return compile(node, { runtime }) as string;\n };\n }\n\n if (prop === Symbol.toPrimitive) {\n return () => {\n const htmlRuntime = _markdownInstall?.htmlRuntime;\n if (!htmlRuntime || !compile) return node;\n const runtime = components\n ? createRuntimeWithOverides(htmlRuntime, components)\n : htmlRuntime;\n return compile(node, { runtime }) as string;\n };\n }\n\n if (prop === 'use') {\n return (newComponents?: any) => {\n const mergedComponents = {\n ...components,\n ...newComponents,\n };\n return createProxy(\n render(mergedComponents),\n mergedComponents\n );\n };\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n\n return createProxy(render() as any);\n },\n };\n\nexport type MarkdownCond<T, _S, _L extends LocalesValues> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.MARKDOWN]: infer M;\n tags?: infer U;\n metadata?: infer V;\n}\n ? IntlayerNode<\n M,\n {\n use: (components?: Record<keyof U, any>) => any;\n metadata: DeepTransformContent<V>;\n }\n >\n : never;\n\nexport const markdownPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.MARKDOWN,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.MARKDOWN,\n },\n ];\n\n const children = node[NodeTypes.MARKDOWN];\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [markdownStringPlugin, ...(props.plugins ?? [])],\n });\n },\n };\n\n/** ---------------------------------------------\n * HTML PLUGIN\n * --------------------------------------------- */\n\n/**\n * HTML conditional type.\n *\n * This ensures type safety:\n * - `html('<div>Hello <CustomComponent /></div>').use({ CustomComponent: ... })` - optional but typed\n */\nexport type HTMLPluginCond<T, _S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.HTML]: infer I;\n tags?: infer U;\n}\n ? IntlayerNode<\n I,\n {\n use: (components?: Record<keyof U, any>) => any;\n }\n >\n : never;\n\n/** HTML plugin. Replaces node with a function that takes components => IntlayerNode. */\nexport const htmlPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_HTML === 'false'\n ? fallbackPlugin\n : {\n id: 'html-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.HTML,\n\n transform: (node: HTMLContent<string>, props) => {\n const html = node[NodeTypes.HTML];\n const { plugins, ...rest } = props;\n\n // Type-safe render function that accepts properly typed components\n const render = (userComponents?: any) =>\n renderIntlayerNode({\n ...rest,\n value: html,\n children:\n process.env.INTLAYER_EDITOR_ENABLED === 'false' ||\n !editor.enabled\n ? html\n : () => ({\n component: ContentSelectorWrapperComponent,\n props: {\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n ...userComponents,\n },\n children: html,\n }),\n });\n\n const createProxy = (element: any, components?: any) =>\n new Proxy(element, {\n get(target, prop, receiver) {\n if (prop === 'value') {\n return html;\n }\n\n if (prop === 'toString') {\n return () => {\n if (\n !components ||\n (typeof components === 'object' &&\n Object.keys(components).length === 0)\n ) {\n return String(html);\n }\n const htmlRuntime = _markdownInstall?.htmlRuntime;\n if (!htmlRuntime || !compile) return String(html);\n const runtime = createRuntimeWithOverides(\n htmlRuntime,\n components\n );\n return compile(html, { runtime }) as string;\n };\n }\n\n if (prop === Symbol.toPrimitive) {\n return () => {\n if (\n !components ||\n (typeof components === 'object' &&\n Object.keys(components).length === 0)\n ) {\n return String(html);\n }\n const htmlRuntime = _markdownInstall?.htmlRuntime;\n if (!htmlRuntime || !compile) return String(html);\n const runtime = createRuntimeWithOverides(\n htmlRuntime,\n components\n );\n return compile(html, { runtime }) as string;\n };\n }\n\n if (prop === 'use') {\n // Return a properly typed function based on custom components\n return (userComponents?: any) => {\n const mergedComponents = {\n ...components,\n ...userComponents,\n };\n return createProxy(\n render(mergedComponents),\n mergedComponents\n );\n };\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n\n return createProxy(render() as any);\n },\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\n/**\n * Insertion conditional type.\n */\nexport type InsertionPluginCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer _I;\n}\n ? (args: Record<string, string | number>) => string\n : never;\n\nexport const insertionPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_INSERTION === 'false'\n ? fallbackPlugin\n : {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.INSERTION,\n transform: (node: InsertionContent, props) => {\n const { plugins, ...rest } = props;\n\n // Return a function that performs the interpolation\n const render = (args: Record<string, string | number> = {}) => {\n let text = node[NodeTypes.INSERTION] as string;\n if (args) {\n Object.entries(args).forEach(([key, value]) => {\n text = text.replace(\n new RegExp(`{{\\\\s*${key}\\\\s*}}`, 'g'),\n String(value)\n );\n });\n }\n return text;\n };\n\n return renderIntlayerNode({\n ...rest,\n value: render as any,\n children: render,\n });\n },\n };\n\nexport interface IInterpreterPluginAngular<T, S, L extends LocalesValues> {\n angularIntlayerNode: IntlayerNodeCond<T>;\n angularMarkdown: MarkdownCond<T, S, L>;\n angularHtml: HTMLPluginCond<T, S, L>;\n angularInsertion: InsertionPluginCond<T>;\n}\n\n/**\n * Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.\n *\n * Otherwise the the `angular-intlayer` plugins will override the types of `intlayer` functions.\n */\nexport type IInterpreterPluginState = Omit<\n IInterpreterPluginStateCore,\n 'insertion' // Remove insertion type from core package\n> & {\n angularIntlayerNode: true;\n angularMarkdown: true;\n angularHtml: true;\n angularInsertion: true;\n};\n\nexport type DeepTransformContent<\n T,\n L extends LocalesValues = DeclaredLocales,\n> = DeepTransformContentCore<T, IInterpreterPluginState, L>;\n\nconst pluginsCache = new Map<string, Plugins[]>();\n\n/**\n * Get the plugins array for Angular content transformation.\n * This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.\n */\nexport const getPlugins = (\n locale?: LocalesValues,\n fallback: boolean = true\n): Plugins[] => {\n const currentLocale = locale ?? internationalization.defaultLocale;\n const cacheKey = `${currentLocale}_${fallback}`;\n\n if (pluginsCache.has(cacheKey)) {\n return pluginsCache.get(cacheKey)!;\n }\n\n const plugins = [\n translationPlugin(\n locale ?? internationalization.defaultLocale,\n fallback ? internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n pluralPlugin(locale ?? internationalization.defaultLocale),\n conditionPlugin,\n nestedPlugin(locale ?? internationalization.defaultLocale),\n filePlugin,\n genderPlugin,\n intlayerNodePlugins,\n markdownPlugin,\n htmlPlugin,\n insertionPlugin,\n ] as Plugins[];\n\n pluginsCache.set(cacheKey, plugins);\n\n return plugins;\n};\n"],"mappings":";;;;;;;;;;;AA2BA,IAAI,mBAGO;AACX,IACE,QAAQ,IAAI,gCAAgC,WAC5C,QAAQ,IAAI,4BAA4B,QAExC,sCAAK,2CAA6C,MAAM,MAAM;AAC5D,oBAAmB;EACnB;;;;AAOJ,MAAM,6BAA6B,aAAkB,eAAoB;CACvE,GAAG;CACH,gBAAgB,KAAa,OAAY,GAAG,aAAoB;EAC9D,MAAM,WAAW,YAAY;AAE7B,MAAI,UAAU;GACZ,MAAM,WAAW;IAAE,GAAG;IAAO,GAAG;IAAU;GAG1C,MAAM,gBAAgB,O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{ value: 'Module' });
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let node_module = require("node:module");
|
|
3
4
|
let node_path = require("node:path");
|
|
4
5
|
let _intlayer_config_node = require("@intlayer/config/node");
|
|
5
6
|
let _intlayer_config_utils = require("@intlayer/config/utils");
|
|
@@ -7,6 +8,7 @@ let _intlayer_webpack = require("@intlayer/webpack");
|
|
|
7
8
|
let defu = require("defu");
|
|
8
9
|
|
|
9
10
|
//#region src/webpack/mergeConfig.ts
|
|
11
|
+
const _require = typeof require !== "undefined" ? require : (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
10
12
|
const mergeConfig = (baseConfig) => {
|
|
11
13
|
const intlayerConfig = (0, _intlayer_config_node.getConfiguration)();
|
|
12
14
|
return (0, defu.defu)({
|
|
@@ -30,10 +32,10 @@ const mergeConfig = (baseConfig) => {
|
|
|
30
32
|
type: "javascript/auto",
|
|
31
33
|
enforce: "pre",
|
|
32
34
|
use: {
|
|
33
|
-
loader: "babel-loader",
|
|
35
|
+
loader: _require.resolve("babel-loader"),
|
|
34
36
|
options: {
|
|
35
|
-
presets: [["@babel/preset-env", { modules: "commonjs" }]],
|
|
36
|
-
plugins: [["@babel/plugin-syntax-import-attributes", { deprecatedAssert: true }]]
|
|
37
|
+
presets: [[_require.resolve("@babel/preset-env"), { modules: "commonjs" }]],
|
|
38
|
+
plugins: [[_require.resolve("@babel/plugin-syntax-import-attributes"), { deprecatedAssert: true }]]
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
}] },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeConfig.cjs","names":["IntlayerPlugin"],"sources":["../../../src/webpack/mergeConfig.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { getAlias } from '@intlayer/config/utils';\nimport { IntlayerPlugin } from '@intlayer/webpack'; // adjust path if needed\nimport { defu } from 'defu';\n\nexport const mergeConfig = (\n baseConfig: import('webpack').Configuration\n): import('webpack').Configuration => {\n const intlayerConfig = getConfiguration();\n\n const config = {\n resolve: {\n alias: getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => resolve(value), // get absolute path\n }),\n },\n externals: {\n esbuild: 'esbuild',\n module: 'module',\n fs: 'fs',\n chokidar: 'chokidar',\n fsevents: 'fsevents',\n },\n module: {\n rules: [\n {\n test: /\\.node$/,\n loader: 'node-loader',\n },\n\n // Fix `import _48DQ2FD8DPGT8SPgqAmt from '../dictionary/app.json' with { type: 'json' };` syntax\n {\n test: /\\.mjs$/,\n include: [/[\\\\/]\\.intlayer[\\\\/]/],\n type: 'javascript/auto',\n enforce: 'pre',\n use: {\n loader: 'babel-loader',\n options: {\n presets: [['@babel/preset-env'
|
|
1
|
+
{"version":3,"file":"mergeConfig.cjs","names":["IntlayerPlugin"],"sources":["../../../src/webpack/mergeConfig.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { resolve } from 'node:path';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { getAlias } from '@intlayer/config/utils';\nimport { IntlayerPlugin } from '@intlayer/webpack'; // adjust path if needed\nimport { defu } from 'defu';\n\nconst _require =\n typeof require !== 'undefined' ? require : createRequire(import.meta.url);\nexport const mergeConfig = (\n baseConfig: import('webpack').Configuration\n): import('webpack').Configuration => {\n const intlayerConfig = getConfiguration();\n\n const config = {\n resolve: {\n alias: getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => resolve(value), // get absolute path\n }),\n },\n externals: {\n esbuild: 'esbuild',\n module: 'module',\n fs: 'fs',\n chokidar: 'chokidar',\n fsevents: 'fsevents',\n },\n module: {\n rules: [\n {\n test: /\\.node$/,\n loader: 'node-loader',\n },\n\n // Fix `import _48DQ2FD8DPGT8SPgqAmt from '../dictionary/app.json' with { type: 'json' };` syntax\n {\n test: /\\.mjs$/,\n include: [/[\\\\/]\\.intlayer[\\\\/]/],\n type: 'javascript/auto',\n enforce: 'pre',\n use: {\n loader: _require.resolve('babel-loader'),\n options: {\n presets: [\n [\n _require.resolve('@babel/preset-env'),\n { modules: 'commonjs' },\n ],\n ],\n plugins: [\n [\n _require.resolve('@babel/plugin-syntax-import-attributes'),\n { deprecatedAssert: true },\n ],\n ],\n },\n },\n },\n ],\n },\n plugins: [new IntlayerPlugin(intlayerConfig)],\n };\n\n return defu(config, baseConfig) as import('webpack').Configuration;\n};\n"],"mappings":";;;;;;;;;;AAOA,MAAM,WACJ,OAAO,YAAY,cAAc,uFAAwC;AAC3E,MAAa,eACX,eACoC;CACpC,MAAM,8DAAmC;AAoDzC,uBAAY;EAjDV,SAAS,EACP,4CAAgB;GACd,eAAe;GACf,YAAY,iCAA0B,MAAM;GAC7C,CAAC,EACH;EACD,WAAW;GACT,SAAS;GACT,QAAQ;GACR,IAAI;GACJ,UAAU;GACV,UAAU;GACX;EACD,QAAQ,EACN,OAAO,CACL;GACE,MAAM;GACN,QAAQ;GACT,EAGD;GACE,MAAM;GACN,SAAS,CAAC,uBAAuB;GACjC,MAAM;GACN,SAAS;GACT,KAAK;IACH,QAAQ,SAAS,QAAQ,eAAe;IACxC,SAAS;KACP,SAAS,CACP,CACE,SAAS,QAAQ,oBAAoB,EACrC,EAAE,SAAS,YAAY,CACxB,CACF;KACD,SAAS,CACP,CACE,SAAS,QAAQ,yCAAyC,EAC1D,EAAE,kBAAkB,MAAM,CAC3B,CACF;KACF;IACF;GACF,CACF,EACF;EACD,SAAS,CAAC,IAAIA,iCAAe,eAAe,CAAC;EAG7B,EAAE,WAAW"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
|
|
3
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
4
|
+
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { __require };
|
|
@@ -6,5 +6,6 @@ import { useLoadDynamic } from "./useLoadDynamic.mjs";
|
|
|
6
6
|
import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
|
|
7
7
|
import { isUpdatableNode, useIntlayer } from "./useIntlayer.mjs";
|
|
8
8
|
import { useLocale } from "./useLocale.mjs";
|
|
9
|
+
import { usePathname } from "./usePathname.mjs";
|
|
9
10
|
|
|
10
|
-
export { INTLAYER_TOKEN, IntlayerProvider, createIntlayerClient, installIntlayer, isUpdatableNode, provideIntlayer, useDictionary, useDictionaryAsync, useDictionaryDynamic, useIntlayer, useLoadDynamic, useLocale };
|
|
11
|
+
export { INTLAYER_TOKEN, IntlayerProvider, createIntlayerClient, installIntlayer, isUpdatableNode, provideIntlayer, useDictionary, useDictionaryAsync, useDictionaryDynamic, useIntlayer, useLoadDynamic, useLocale, usePathname };
|
|
@@ -9,7 +9,7 @@ import { computed, inject } from "@angular/core";
|
|
|
9
9
|
*/
|
|
10
10
|
const useDictionary = (dictionary, localeOrSelector) => {
|
|
11
11
|
const intlayer = inject(INTLAYER_TOKEN);
|
|
12
|
-
const isSelector = typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
12
|
+
const isSelector = process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
13
13
|
return computed(() => {
|
|
14
14
|
const currentLocale = intlayer?.locale();
|
|
15
15
|
if (isSelector) return getDictionary(dictionary, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import { computed, inject, type Signal } from '@angular/core';\nimport type {\n Dictionary,\n DictionarySelector,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport type { DeepTransformContent } from '../plugins';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\n\n/**\n * Angular hook that transforms a dictionary (or qualified dictionary group)\n * and returns its reactive content for the given locale or selector.\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n): Signal<\n DeepTransformContent<\n ResolveQualifiedDictionaryContent<T, A>,\n ExtractSelectorLocale<A>\n >\n> => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n const isSelector =\n typeof localeOrSelector === 'object'
|
|
1
|
+
{"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import { computed, inject, type Signal } from '@angular/core';\nimport type {\n Dictionary,\n DictionarySelector,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport type { DeepTransformContent } from '../plugins';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\n\n/**\n * Angular hook that transforms a dictionary (or qualified dictionary group)\n * and returns its reactive content for the given locale or selector.\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n): Signal<\n DeepTransformContent<\n ResolveQualifiedDictionaryContent<T, A>,\n ExtractSelectorLocale<A>\n >\n> => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n const isSelector =\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&\n typeof localeOrSelector === 'object' &&\n localeOrSelector !== null;\n\n /** a *stable* reactive dictionary object */\n const content = computed(() => {\n const currentLocale = intlayer?.locale();\n\n if (isSelector) {\n return getDictionary(dictionary, {\n ...localeOrSelector,\n locale: localeOrSelector.locale ?? currentLocale,\n } as A) as any;\n }\n\n return getDictionary(\n dictionary,\n (localeOrSelector ?? currentLocale) as A\n ) as any;\n });\n\n return content; // all consumers keep full reactivity\n};\n"],"mappings":";;;;;;;;;AAqBA,MAAa,iBAMX,YACA,qBAMG;CACH,MAAM,WAAW,OAAyB,eAAe;CAEzD,MAAM,aACJ,QAAQ,IAAI,iCAAiC,WAC7C,OAAO,qBAAqB,YAC5B,qBAAqB;AAmBvB,QAhBgB,eAAe;EAC7B,MAAM,gBAAgB,UAAU,QAAQ;AAExC,MAAI,WACF,QAAO,cAAc,YAAY;GAC/B,GAAG;GACH,QAAQ,iBAAiB,UAAU;GACpC,CAAM;AAGT,SAAO,cACL,YACC,oBAAoB,cACtB;GAGW"}
|
|
@@ -13,7 +13,7 @@ import { isQualifiedDynamicLoaderMap, parseDictionarySelector, resolveQualifiedD
|
|
|
13
13
|
* Lazily loads a dictionary (plain or qualified) and returns its reactive
|
|
14
14
|
* content.
|
|
15
15
|
*
|
|
16
|
-
* For a qualified loader map (collection / variant
|
|
16
|
+
* For a qualified loader map (collection / variant, possibly
|
|
17
17
|
* combined), only the chunk(s) the selector targets are loaded. For a plain
|
|
18
18
|
* loader map, the locale chunk is loaded.
|
|
19
19
|
*
|
|
@@ -22,7 +22,7 @@ import { isQualifiedDynamicLoaderMap, parseDictionarySelector, resolveQualifiedD
|
|
|
22
22
|
*/
|
|
23
23
|
const useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector) => {
|
|
24
24
|
const intlayer = inject(INTLAYER_TOKEN);
|
|
25
|
-
if (isQualifiedDynamicLoaderMap(dictionaryPromise)) {
|
|
25
|
+
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && isQualifiedDynamicLoaderMap(dictionaryPromise)) {
|
|
26
26
|
const { locale: selectorLocale, selector } = parseDictionarySelector(localeOrSelector);
|
|
27
27
|
const localeTarget = selectorLocale ?? intlayer?.locale() ?? internationalization.defaultLocale;
|
|
28
28
|
const container = signal(void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.mjs","names":[],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport { computed, inject, signal } from '@angular/core';\nimport { internationalization } from '@intlayer/config/built';\nimport {\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveQualifiedDynamicContentAsync,\n} from '@intlayer/core/dictionaryManipulator';\nimport type {
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.mjs","names":[],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport { computed, inject, signal } from '@angular/core';\nimport { internationalization } from '@intlayer/config/built';\nimport {\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveQualifiedDynamicContentAsync,\n} from '@intlayer/core/dictionaryManipulator';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * Lazily loads a dictionary (plain or qualified) and returns its reactive\n * content.\n *\n * For a qualified loader map (collection / variant, possibly\n * combined), only the chunk(s) the selector targets are loaded. For a plain\n * loader map, the locale chunk is loaded.\n *\n * If the locale is not provided (directly or through the selector), it will use\n * the locale from the client context.\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const K extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<K> = LocalesValues,\n>(\n dictionaryPromise:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: K,\n localeOrSelector?: A\n) => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n if (\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&\n isQualifiedDynamicLoaderMap(dictionaryPromise)\n ) {\n const { locale: selectorLocale, selector } =\n parseDictionarySelector<LocalesValues>(localeOrSelector);\n\n const localeTarget =\n selectorLocale ??\n intlayer?.locale() ??\n internationalization.defaultLocale;\n\n const container = signal<unknown>(undefined);\n\n resolveQualifiedDynamicContentAsync({\n loaderMap: dictionaryPromise,\n key: String(key),\n locale: localeTarget,\n selector,\n transform: (dictionary) => getDictionary(dictionary, localeTarget),\n }).then((resolved) => container.set(resolved));\n\n return computed(() => container() as any);\n }\n\n const locale =\n typeof localeOrSelector === 'string'\n ? (localeOrSelector as LocalesValues)\n : undefined;\n\n const localeTarget = computed(\n () => locale ?? intlayer?.locale() ?? internationalization.defaultLocale\n );\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget()}`,\n (dictionaryPromise as any)[localeTarget()]?.()\n ) as T;\n\n return useDictionary(dictionary, localeTarget() as any);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAa,wBAKX,mBAGA,KACA,qBACG;CACH,MAAM,WAAW,OAAyB,eAAe;AAEzD,KACE,QAAQ,IAAI,iCAAiC,WAC7C,4BAA4B,kBAAkB,EAC9C;EACA,MAAM,EAAE,QAAQ,gBAAgB,aAC9B,wBAAuC,iBAAiB;EAE1D,MAAM,eACJ,kBACA,UAAU,QAAQ,IAClB,qBAAqB;EAEvB,MAAM,YAAY,OAAgB,OAAU;AAE5C,sCAAoC;GAClC,WAAW;GACX,KAAK,OAAO,IAAI;GAChB,QAAQ;GACR;GACA,YAAY,eAAe,cAAc,YAAY,aAAa;GACnE,CAAC,CAAC,MAAM,aAAa,UAAU,IAAI,SAAS,CAAC;AAE9C,SAAO,eAAe,WAAW,CAAQ;;CAG3C,MAAM,SACJ,OAAO,qBAAqB,WACvB,mBACD;CAEN,MAAM,eAAe,eACb,UAAU,UAAU,QAAQ,IAAI,qBAAqB,cAC5D;AAOD,QAAO,cALY,eACjB,GAAG,OAAO,IAAI,CAAC,GAAG,cAAc,IAC/B,kBAA0B,cAAc,KAAK,CAGjB,EAAE,cAAc,CAAQ"}
|
|
@@ -32,7 +32,7 @@ const isUpdatableNode = (val) => !!val && typeof val === "object" && typeof val.
|
|
|
32
32
|
*/
|
|
33
33
|
const useIntlayer = (key, localeOrSelector) => {
|
|
34
34
|
const intlayer = inject(INTLAYER_TOKEN);
|
|
35
|
-
const isSelector = typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
35
|
+
const isSelector = process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
36
36
|
return computed(() => {
|
|
37
37
|
const currentLocale = intlayer.locale();
|
|
38
38
|
if (isSelector) return getIntlayer(key, {
|