react-intlayer 5.0.1 → 5.0.3
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/IntlayerProvider.cjs +13 -9
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/index.cjs +2 -0
- package/dist/cjs/client/index.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +4 -1
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +1 -4
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useIntlayerAsync.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleCookie.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelectorWrapper.cjs +4 -2
- package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/plugins.cjs +2 -35
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/reactElement/renderReactElement.cjs +62 -0
- package/dist/cjs/reactElement/renderReactElement.cjs.map +1 -0
- package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
- package/dist/cjs/server/t.cjs +1 -3
- package/dist/cjs/server/t.cjs.map +1 -1
- package/dist/cjs/server/useDictionary.cjs +1 -1
- package/dist/cjs/server/useDictionary.cjs.map +1 -1
- package/dist/cjs/server/useIntlayer.cjs +1 -1
- package/dist/cjs/server/useIntlayer.cjs.map +1 -1
- package/dist/esm/client/IntlayerProvider.mjs +12 -9
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/index.mjs +2 -0
- package/dist/esm/client/index.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +4 -1
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +1 -4
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useIntlayerAsync.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleCookie.mjs.map +1 -1
- package/dist/esm/editor/ContentSelectorWrapper.mjs +4 -2
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/plugins.mjs +2 -35
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/reactElement/renderReactElement.mjs +38 -0
- package/dist/esm/reactElement/renderReactElement.mjs.map +1 -0
- package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
- package/dist/esm/server/t.mjs +1 -3
- package/dist/esm/server/t.mjs.map +1 -1
- package/dist/esm/server/useDictionary.mjs +1 -1
- package/dist/esm/server/useDictionary.mjs.map +1 -1
- package/dist/esm/server/useIntlayer.mjs +1 -1
- package/dist/esm/server/useIntlayer.mjs.map +1 -1
- package/dist/types/client/IntlayerProvider.d.ts +12 -6
- package/dist/types/client/IntlayerProvider.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +1 -1
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/client/useContent.d.ts +1 -1
- package/dist/types/client/useDictionary.d.ts +3 -3
- package/dist/types/client/useDictionary.d.ts.map +1 -1
- package/dist/types/client/useIntlayer.d.ts +3 -2
- package/dist/types/client/useIntlayer.d.ts.map +1 -1
- package/dist/types/client/useIntlayerAsync.d.ts +2 -2
- package/dist/types/client/useIntlayerAsync.d.ts.map +1 -1
- package/dist/types/client/useLocale.d.ts +7 -7
- package/dist/types/client/useLocale.d.ts.map +1 -1
- package/dist/types/client/useLocaleBase.d.ts +2 -2
- package/dist/types/client/useLocaleCookie.d.ts +5 -5
- package/dist/types/client/useLocaleCookie.d.ts.map +1 -1
- package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -1
- package/dist/types/getDictionary.d.ts +2 -2
- package/dist/types/getDictionary.d.ts.map +1 -1
- package/dist/types/getIntlayer.d.ts +2 -2
- package/dist/types/getIntlayer.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/plugins.d.ts +8 -8
- package/dist/types/plugins.d.ts.map +1 -1
- package/dist/types/reactElement/renderReactElement.d.ts +3 -0
- package/dist/types/reactElement/renderReactElement.d.ts.map +1 -0
- package/dist/types/server/IntlayerServerProvider.d.ts +8 -8
- package/dist/types/server/IntlayerServerProvider.d.ts.map +1 -1
- package/dist/types/server/t.d.ts +2 -2
- package/dist/types/server/t.d.ts.map +1 -1
- package/dist/types/server/useDictionary.d.ts +2 -2
- package/dist/types/server/useDictionary.d.ts.map +1 -1
- package/dist/types/server/useIntlayer.d.ts +2 -2
- package/dist/types/server/useIntlayer.d.ts.map +1 -1
- package/package.json +15 -15
|
@@ -21,6 +21,7 @@ var IntlayerProvider_exports = {};
|
|
|
21
21
|
__export(IntlayerProvider_exports, {
|
|
22
22
|
IntlayerClientContext: () => IntlayerClientContext,
|
|
23
23
|
IntlayerProvider: () => IntlayerProvider,
|
|
24
|
+
IntlayerProviderContent: () => IntlayerProviderContent,
|
|
24
25
|
useIntlayerContext: () => useIntlayerContext
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(IntlayerProvider_exports);
|
|
@@ -33,13 +34,15 @@ var import_PoweredByMeta = require('./PoweredByMeta.cjs');
|
|
|
33
34
|
var import_useLocaleCookie = require('./useLocaleCookie.cjs');
|
|
34
35
|
const IntlayerClientContext = (0, import_react.createContext)({
|
|
35
36
|
locale: import_useLocaleCookie.localeCookie ?? (0, import_client.getConfiguration)().internationalization.defaultLocale,
|
|
36
|
-
setLocale: () => null
|
|
37
|
+
setLocale: () => null,
|
|
38
|
+
disableEditor: false
|
|
37
39
|
});
|
|
38
40
|
const useIntlayerContext = () => (0, import_react.useContext)(IntlayerClientContext);
|
|
39
41
|
const IntlayerProviderContent = ({
|
|
40
42
|
locale,
|
|
41
43
|
children,
|
|
42
|
-
setLocale: setLocaleProp
|
|
44
|
+
setLocale: setLocaleProp,
|
|
45
|
+
disableEditor
|
|
43
46
|
}) => {
|
|
44
47
|
const { internationalization } = (0, import_client.getConfiguration)();
|
|
45
48
|
const { defaultLocale, locales: availableLocales } = internationalization;
|
|
@@ -50,33 +53,34 @@ const IntlayerProviderContent = ({
|
|
|
50
53
|
const setLocaleBase = (0, import_react.useCallback)(
|
|
51
54
|
(newLocale) => {
|
|
52
55
|
if (currentLocale.toString() === newLocale.toString()) return;
|
|
53
|
-
if (!availableLocales.includes(newLocale)) {
|
|
56
|
+
if (!availableLocales.map(String).includes(newLocale)) {
|
|
54
57
|
console.error(`Locale ${locale} is not available`);
|
|
55
58
|
return;
|
|
56
59
|
}
|
|
57
60
|
setCurrentLocale(newLocale);
|
|
58
61
|
(0, import_useLocaleCookie.setLocaleCookie)(newLocale);
|
|
59
62
|
},
|
|
60
|
-
[availableLocales, currentLocale, locale]
|
|
63
|
+
[availableLocales, currentLocale, locale, setCurrentLocale]
|
|
61
64
|
);
|
|
62
65
|
const setLocale = (0, import_react.useMemo)(
|
|
63
66
|
() => setLocaleProp ?? setLocaleBase,
|
|
64
67
|
[setLocaleProp, setLocaleBase]
|
|
65
68
|
);
|
|
66
69
|
const value = (0, import_react.useMemo)(
|
|
67
|
-
() => ({ locale: currentLocale, setLocale }),
|
|
68
|
-
[currentLocale, setLocale]
|
|
70
|
+
() => ({ locale: currentLocale, setLocale, disableEditor }),
|
|
71
|
+
[currentLocale, setLocale, disableEditor]
|
|
69
72
|
);
|
|
70
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.
|
|
73
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(IntlayerClientContext.Provider, { value, children: [
|
|
71
74
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_PoweredByMeta.PoweredByMeta, {}),
|
|
72
75
|
children
|
|
73
|
-
] })
|
|
76
|
+
] });
|
|
74
77
|
};
|
|
75
|
-
const IntlayerProvider = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_IntlayerEditorProvider.IntlayerEditorProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IntlayerProviderContent, { ...props }) });
|
|
78
|
+
const IntlayerProvider = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_editor_react.ChangedContentProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_IntlayerEditorProvider.IntlayerEditorProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IntlayerProviderContent, { ...props }) }) });
|
|
76
79
|
// Annotate the CommonJS export names for ESM import in node:
|
|
77
80
|
0 && (module.exports = {
|
|
78
81
|
IntlayerClientContext,
|
|
79
82
|
IntlayerProvider,
|
|
83
|
+
IntlayerProviderContent,
|
|
80
84
|
useIntlayerContext
|
|
81
85
|
});
|
|
82
86
|
//# sourceMappingURL=IntlayerProvider.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport { getConfiguration, type
|
|
1
|
+
{"version":3,"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport { getConfiguration, type LocalesValues } from '@intlayer/config/client';\nimport {\n ChangedContentProvider,\n useCrossFrameState,\n} from '@intlayer/editor-react';\nimport {\n type FC,\n type PropsWithChildren,\n createContext,\n useContext,\n useMemo,\n useCallback,\n} from 'react';\nimport { IntlayerEditorProvider } from '../editor/IntlayerEditorProvider';\nimport { PoweredByMeta } from './PoweredByMeta';\nimport { localeCookie, setLocaleCookie } from './useLocaleCookie';\n\ntype IntlayerValue = {\n locale: LocalesValues;\n setLocale: (newLocale: LocalesValues) => void;\n disableEditor?: boolean;\n};\n\n/**\n * Context that store the current locale on the client side\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeCookie ?? getConfiguration().internationalization.defaultLocale,\n setLocale: () => null,\n disableEditor: false,\n});\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\nexport type IntlayerProviderProps = PropsWithChildren & {\n locale?: LocalesValues;\n setLocale?: (locale: LocalesValues) => void;\n disableEditor?: boolean;\n};\n\n/**\n * Provider that store the current locale on the client side\n */\nexport const IntlayerProviderContent: FC<IntlayerProviderProps> = ({\n locale,\n children,\n setLocale: setLocaleProp,\n disableEditor,\n}) => {\n const { internationalization } = getConfiguration();\n const { defaultLocale, locales: availableLocales } = internationalization;\n\n const [currentLocale, setCurrentLocale] = useCrossFrameState(\n 'INTLAYER_CURRENT_LOCALE',\n locale ?? localeCookie ?? defaultLocale\n );\n\n const setLocaleBase = useCallback(\n (newLocale: LocalesValues) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales.map(String).includes(newLocale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale); // Update state\n setLocaleCookie(newLocale); // Optionally set cookie for persistence\n },\n [availableLocales, currentLocale, locale, setCurrentLocale]\n );\n\n const setLocale = useMemo(\n () => setLocaleProp ?? setLocaleBase,\n [setLocaleProp, setLocaleBase]\n );\n\n const value: IntlayerValue = useMemo<IntlayerValue>(\n () => ({ locale: currentLocale, setLocale, disableEditor }),\n [currentLocale, setLocale, disableEditor]\n );\n\n return (\n <IntlayerClientContext.Provider value={value}>\n <PoweredByMeta />\n {children}\n </IntlayerClientContext.Provider>\n );\n};\n\nexport const IntlayerProvider: FC<IntlayerProviderProps> = (props) => (\n <ChangedContentProvider>\n <IntlayerEditorProvider>\n <IntlayerProviderContent {...props} />\n </IntlayerEditorProvider>\n </ChangedContentProvider>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwFI;AAtFJ,oBAAqD;AACrD,0BAGO;AACP,mBAOO;AACP,oCAAuC;AACvC,2BAA8B;AAC9B,6BAA8C;AAWvC,MAAM,4BAAwB,4BAA6B;AAAA,EAChE,QAAQ,2CAAgB,gCAAiB,EAAE,qBAAqB;AAAA,EAChE,WAAW,MAAM;AAAA,EACjB,eAAe;AACjB,CAAC;AAKM,MAAM,qBAAqB,UAAM,yBAAW,qBAAqB;AAWjE,MAAM,0BAAqD,CAAC;AAAA,EACjE;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AACF,MAAM;AACJ,QAAM,EAAE,qBAAqB,QAAI,gCAAiB;AAClD,QAAM,EAAE,eAAe,SAAS,iBAAiB,IAAI;AAErD,QAAM,CAAC,eAAe,gBAAgB,QAAI;AAAA,IACxC;AAAA,IACA,UAAU,uCAAgB;AAAA,EAC5B;AAEA,QAAM,oBAAgB;AAAA,IACpB,CAAC,cAA6B;AAC5B,UAAI,cAAc,SAAS,MAAM,UAAU,SAAS,EAAG;AAEvD,UAAI,CAAC,iBAAiB,IAAI,MAAM,EAAE,SAAS,SAAS,GAAG;AACrD,gBAAQ,MAAM,UAAU,MAAM,mBAAmB;AACjD;AAAA,MACF;AAEA,uBAAiB,SAAS;AAC1B,kDAAgB,SAAS;AAAA,IAC3B;AAAA,IACA,CAAC,kBAAkB,eAAe,QAAQ,gBAAgB;AAAA,EAC5D;AAEA,QAAM,gBAAY;AAAA,IAChB,MAAM,iBAAiB;AAAA,IACvB,CAAC,eAAe,aAAa;AAAA,EAC/B;AAEA,QAAM,YAAuB;AAAA,IAC3B,OAAO,EAAE,QAAQ,eAAe,WAAW,cAAc;AAAA,IACzD,CAAC,eAAe,WAAW,aAAa;AAAA,EAC1C;AAEA,SACE,6CAAC,sBAAsB,UAAtB,EAA+B,OAC9B;AAAA,gDAAC,sCAAc;AAAA,IACd;AAAA,KACH;AAEJ;AAEO,MAAM,mBAA8C,CAAC,UAC1D,4CAAC,8CACC,sDAAC,wDACC,sDAAC,2BAAyB,GAAG,OAAO,GACtC,GACF;","names":[]}
|
|
@@ -20,6 +20,7 @@ var client_exports = {};
|
|
|
20
20
|
__export(client_exports, {
|
|
21
21
|
IntlayerClientContext: () => import_IntlayerProvider.IntlayerClientContext,
|
|
22
22
|
IntlayerProvider: () => import_IntlayerProvider.IntlayerProvider,
|
|
23
|
+
IntlayerProviderContent: () => import_IntlayerProvider.IntlayerProviderContent,
|
|
23
24
|
getBrowserLocale: () => import_getBrowserLocale.getBrowserLocale,
|
|
24
25
|
localeCookie: () => import_useLocaleCookie.localeCookie,
|
|
25
26
|
setLocaleCookie: () => import_useLocaleCookie.setLocaleCookie,
|
|
@@ -46,6 +47,7 @@ var import_t = require('./t.cjs');
|
|
|
46
47
|
0 && (module.exports = {
|
|
47
48
|
IntlayerClientContext,
|
|
48
49
|
IntlayerProvider,
|
|
50
|
+
IntlayerProviderContent,
|
|
49
51
|
getBrowserLocale,
|
|
50
52
|
localeCookie,
|
|
51
53
|
setLocaleCookie,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export {\n type IntlayerProviderProps,\n IntlayerClientContext,\n useIntlayerContext,\n IntlayerProvider,\n} from './IntlayerProvider';\nexport { useIntlayer } from './useIntlayer';\nexport { useIntlayerAsync } from './useIntlayerAsync';\nexport { useDictionary } from './useDictionary';\nexport { useLocaleBase } from './useLocaleBase';\nexport { useLocale } from './useLocale';\nexport {\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n} from './useLocaleCookie';\nexport { getBrowserLocale } from './getBrowserLocale';\nexport { t } from './t';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export {\n type IntlayerProviderProps,\n IntlayerClientContext,\n IntlayerProviderContent,\n useIntlayerContext,\n IntlayerProvider,\n} from './IntlayerProvider';\nexport { useIntlayer } from './useIntlayer';\nexport { useIntlayerAsync } from './useIntlayerAsync';\nexport { useDictionary } from './useDictionary';\nexport { useLocaleBase } from './useLocaleBase';\nexport { useLocale } from './useLocale';\nexport {\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n} from './useLocaleCookie';\nexport { getBrowserLocale } from './getBrowserLocale';\nexport { t } from './t';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAMO;AACP,yBAA4B;AAC5B,8BAAiC;AACjC,2BAA8B;AAC9B,2BAA8B;AAC9B,uBAA0B;AAC1B,6BAIO;AACP,8BAAiC;AACjC,eAAkB;","names":[]}
|
|
@@ -28,7 +28,10 @@ var import_getDictionary = require('../getDictionary.cjs');
|
|
|
28
28
|
const useDictionary = (dictionary, locale) => {
|
|
29
29
|
const { locale: currentLocale } = (0, import_react.useContext)(import_IntlayerProvider.IntlayerClientContext);
|
|
30
30
|
const localeTarget = locale ?? currentLocale;
|
|
31
|
-
return (0, import_getDictionary.getDictionary)(
|
|
31
|
+
return (0, import_getDictionary.getDictionary)(
|
|
32
|
+
dictionary,
|
|
33
|
+
localeTarget
|
|
34
|
+
);
|
|
32
35
|
};
|
|
33
36
|
// Annotate the CommonJS export names for ESM import in node:
|
|
34
37
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n'use client';\n\nimport type { LocalesValues } from '@intlayer/config/client';\nimport { DeepTransformContent, type Dictionary } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { getDictionary } from '../getDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionary = <T extends Dictionary>(\n dictionary: T,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getDictionary<T, LocalesValues>(\n dictionary,\n localeTarget\n ) as any as DeepTransformContent<T['content']>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,mBAA2B;AAC3B,8BAAsC;AACtC,2BAA8B;AAOvB,MAAM,gBAAgB,CAC3B,YACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,QAAI,yBAAW,6CAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,aAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -32,10 +32,7 @@ const useIntlayer = (key, locale) => {
|
|
|
32
32
|
const { changedContent } = (0, import_editor_react.useChangedContent)();
|
|
33
33
|
const localeTarget = locale ?? currentLocale;
|
|
34
34
|
if (changedContent?.[key]) {
|
|
35
|
-
return (0, import_getDictionary.getDictionary)(
|
|
36
|
-
changedContent?.[key],
|
|
37
|
-
localeTarget
|
|
38
|
-
);
|
|
35
|
+
return (0, import_getDictionary.getDictionary)(changedContent?.[key], localeTarget);
|
|
39
36
|
}
|
|
40
37
|
return (0, import_getIntlayer.getIntlayer)(key, localeTarget);
|
|
41
38
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useChangedContent } from '@intlayer/editor-react';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useChangedContent } from '@intlayer/editor-react';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport type { DictionaryKeys } from '@intlayer/core';\nimport { getDictionary } from '../getDictionary';\nimport { getIntlayer } from '../getIntlayer';\n// @ts-ignore intlayer declared for module augmentation\nimport { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport type { DeepTransformContent } from '../plugins';\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useIntlayer = <T extends DictionaryKeys>(\n key: T,\n locale?: Locales\n): DeepTransformContent<IntlayerDictionaryTypesConnector[T]['content']> => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const { changedContent } = useChangedContent();\n const localeTarget = locale ?? currentLocale;\n\n if (changedContent?.[key]) {\n // @ts-ignore\n return getDictionary(changedContent?.[key], localeTarget);\n }\n\n return getIntlayer(key, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAAkC;AAClC,mBAA2B;AAC3B,8BAAsC;AAEtC,2BAA8B;AAC9B,yBAA4B;AAUrB,MAAM,cAAc,CACzB,KACA,WACyE;AACzE,QAAM,EAAE,QAAQ,cAAc,QAAI,yBAAW,6CAAqB;AAClE,QAAM,EAAE,eAAe,QAAI,uCAAkB;AAC7C,QAAM,eAAe,UAAU;AAE/B,MAAI,iBAAiB,GAAG,GAAG;AAEzB,eAAO,oCAAc,iBAAiB,GAAG,GAAG,YAAY;AAAA,EAC1D;AAEA,aAAO,gCAAY,KAAK,YAAY;AACtC;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useIntlayerAsync.ts"],"sourcesContent":["'use client';\n\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useIntlayerAsync.ts"],"sourcesContent":["'use client';\n\nimport type { LocalesValues } from '@intlayer/config/client';\nimport { useContext, useEffect, useMemo, useState } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport {\n type DictionaryKeys,\n getIntlayer,\n getIntlayerAsync,\n} from '@intlayer/core';\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * This hook will prerender the locale dictionary and fetch simultaneously the distant dictionaries to hydrate it.\n *\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useIntlayerAsync = <T extends DictionaryKeys>(\n key: T,\n locale?: LocalesValues,\n isRenderEditor = true\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n const localeDictionary = getIntlayer(key, localeTarget);\n const [distantDictionary, setDistantDictionary] = useState<\n typeof localeDictionary | null | undefined\n >(undefined);\n const [isLoading, setIsLoading] = useState(false);\n\n useEffect(() => {\n setIsLoading(true);\n\n getIntlayerAsync(key)\n .then((distantDictionary) => {\n if (distantDictionary) {\n setDistantDictionary(distantDictionary);\n }\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, []);\n\n const dictionary = useMemo(\n () => distantDictionary ?? localeDictionary,\n [distantDictionary, localeDictionary]\n );\n\n return { ...(dictionary as object), isLoading } as typeof localeDictionary & {\n isLoading: boolean;\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAyD;AACzD,8BAAsC;AACtC,kBAIO;AAUA,MAAM,mBAAmB,CAC9B,KACA,QACA,iBAAiB,SACd;AACH,QAAM,EAAE,QAAQ,cAAc,QAAI,yBAAW,6CAAqB;AAClE,QAAM,eAAe,UAAU;AAC/B,QAAM,uBAAmB,yBAAY,KAAK,YAAY;AACtD,QAAM,CAAC,mBAAmB,oBAAoB,QAAI,uBAEhD,MAAS;AACX,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,KAAK;AAEhD,8BAAU,MAAM;AACd,iBAAa,IAAI;AAEjB,sCAAiB,GAAG,EACjB,KAAK,CAACA,uBAAsB;AAC3B,UAAIA,oBAAmB;AACrB,6BAAqBA,kBAAiB;AAAA,MACxC;AAAA,IACF,CAAC,EACA,QAAQ,MAAM;AACb,mBAAa,KAAK;AAAA,IACpB,CAAC;AAAA,EACL,GAAG,CAAC,CAAC;AAEL,QAAM,iBAAa;AAAA,IACjB,MAAM,qBAAqB;AAAA,IAC3B,CAAC,mBAAmB,gBAAgB;AAAA,EACtC;AAEA,SAAO,EAAE,GAAI,YAAuB,UAAU;AAGhD;","names":["distantDictionary"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { type
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { type LocalesValues, getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useLocaleCookie } from './useLocaleCookie';\n\ntype useLocaleProps = {\n onLocaleChange?: (locale: LocalesValues) => void;\n};\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocale = ({ onLocaleChange }: useLocaleProps = {}) => {\n const {\n /**\n * Prefix default prefix the default locale to the path as other locales.\n *\n * Example with prefixDefault = true and defaultLocale = 'en':\n * path = /en/dashboard or /fr/dashboard\n *\n * Example with prefixDefault = false and defaultLocale = 'en':\n * path = /dashboard or /fr/dashboard\n *\n */\n prefixDefault,\n } = getConfiguration().middleware;\n const { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n const { locale, setLocale: setLocaleState } = useContext(\n IntlayerClientContext\n );\n const { setLocaleCookie } = useLocaleCookie();\n\n const setLocale = useCallback(\n (locale: LocalesValues) => {\n if (!availableLocales.map(String).includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n setLocaleCookie(locale);\n onLocaleChange?.(locale);\n },\n [\n onLocaleChange,\n availableLocales,\n setLocaleState,\n prefixDefault,\n defaultLocale,\n ]\n );\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n localeList, // List of all available locales\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAqD;AACrD,kBAA2B;AAC3B,mBAAwC;AACxC,8BAAsC;AACtC,6BAAgC;AASzB,MAAM,YAAY,CAAC,EAAE,eAAe,IAAoB,CAAC,MAAM;AACpE,QAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAWJ;AAAA,EACF,QAAI,gCAAiB,EAAE;AACvB,QAAM,EAAE,eAAe,SAAS,iBAAiB,QAC/C,gCAAiB,EAAE;AACrB,QAAM,EAAE,QAAQ,WAAW,eAAe,QAAI;AAAA,IAC5C;AAAA,EACF;AACA,QAAM,EAAE,gBAAgB,QAAI,wCAAgB;AAE5C,QAAM,gBAAY;AAAA,IAChB,CAACA,YAA0B;AACzB,UAAI,CAAC,iBAAiB,IAAI,MAAM,EAAE,SAASA,OAAM,GAAG;AAClD,gBAAQ,MAAM,UAAUA,OAAM,mBAAmB;AACjD;AAAA,MACF;AAEA,qBAAeA,OAAM;AACrB,sBAAgBA,OAAM;AACtB,uBAAiBA,OAAM;AAAA,IACzB;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":["locale"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocaleCookie.ts"],"sourcesContent":["import { type
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocaleCookie.ts"],"sourcesContent":["import { type LocalesValues, getConfiguration } from '@intlayer/config/client';\nimport Cookies from 'js-cookie';\n\nconst { cookieName } = getConfiguration().middleware;\n\nconst cookieAttributes: Cookies.CookieAttributes = {\n path: '/',\n expires: undefined,\n domain: undefined,\n secure: false,\n sameSite: 'strict',\n};\n\n/**\n * Get the locale cookie\n */\nexport const localeCookie = Cookies.get(cookieName) as unknown as\n | LocalesValues\n | undefined;\n\n/**\n * Set the locale cookie\n */\nexport const setLocaleCookie = (locale: LocalesValues) => {\n Cookies.set(cookieName, locale, cookieAttributes);\n};\n\n/**\n * Hook that provides the locale cookie and a function to set it\n */\nexport const useLocaleCookie = () => ({\n localeCookie,\n setLocaleCookie,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAqD;AACrD,uBAAoB;AAEpB,MAAM,EAAE,WAAW,QAAI,gCAAiB,EAAE;AAE1C,MAAM,mBAA6C;AAAA,EACjD,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AACZ;AAKO,MAAM,eAAe,iBAAAA,QAAQ,IAAI,UAAU;AAO3C,MAAM,kBAAkB,CAAC,WAA0B;AACxD,mBAAAA,QAAQ,IAAI,YAAY,QAAQ,gBAAgB;AAClD;AAKO,MAAM,kBAAkB,OAAO;AAAA,EACpC;AAAA,EACA;AACF;","names":["Cookies"]}
|
|
@@ -27,6 +27,7 @@ var import_core = require("@intlayer/core");
|
|
|
27
27
|
var import_editor_react = require("@intlayer/editor-react");
|
|
28
28
|
var import_react = require("react");
|
|
29
29
|
var import_ContentSelector = require('../UI/ContentSelector.cjs');
|
|
30
|
+
var import_client = require('../client/index.cjs');
|
|
30
31
|
const ContentSelectorWrapperContent = ({
|
|
31
32
|
children,
|
|
32
33
|
dictionaryKey,
|
|
@@ -49,7 +50,7 @@ const ContentSelectorWrapperContent = ({
|
|
|
49
50
|
);
|
|
50
51
|
const isSelected = (0, import_react.useMemo)(
|
|
51
52
|
() => (focusedContent?.dictionaryKey === dictionaryKey && (focusedContent?.keyPath?.length ?? 0) > 0 && (0, import_core.isSameKeyPath)(focusedContent?.keyPath ?? [], keyPath)) ?? false,
|
|
52
|
-
[focusedContent, keyPath]
|
|
53
|
+
[focusedContent, keyPath, dictionaryKey]
|
|
53
54
|
);
|
|
54
55
|
(0, import_react.useEffect)(() => {
|
|
55
56
|
if (editedValue && typeof editedValue === "string") {
|
|
@@ -65,7 +66,8 @@ const ContentSelectorWrapper = ({
|
|
|
65
66
|
...props
|
|
66
67
|
}) => {
|
|
67
68
|
const { enabled } = (0, import_editor_react.useEditorEnabled)();
|
|
68
|
-
|
|
69
|
+
const { disableEditor } = (0, import_client.useIntlayerContext)();
|
|
70
|
+
if (enabled && !disableEditor) {
|
|
69
71
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ContentSelectorWrapperContent, { ...props, children });
|
|
70
72
|
}
|
|
71
73
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport { type NodeProps, isSameKeyPath } from '@intlayer/core';\nimport {\n useFocusDictionary,\n useEditedContentActions,\n useEditorEnabled,\n} from '@intlayer/editor-react';\nimport {\n useCallback,\n useEffect,\n useState,\n useMemo,\n type FC,\n type ReactNode,\n HTMLAttributes,\n} from 'react';\nimport { ContentSelector } from '../UI/ContentSelector';\n\nexport type ContentSelectorWrapperProps = NodeProps &\n Omit<HTMLAttributes<HTMLDivElement>, 'content'>;\n\nconst ContentSelectorWrapperContent: FC<ContentSelectorWrapperProps> = ({\n children,\n dictionaryKey,\n keyPath,\n ...props\n}) => {\n const { focusedContent, setFocusedContent } = useFocusDictionary();\n const { getEditedContentValue } = useEditedContentActions();\n\n const editedValue = useMemo(\n () => getEditedContentValue(dictionaryKey, keyPath),\n [dictionaryKey, keyPath, getEditedContentValue]\n );\n\n const [displayedChildren, setDisplayedChildren] =\n useState<ReactNode>(children);\n\n const handleSelect = useCallback(\n () =>\n setFocusedContent({\n dictionaryKey,\n keyPath,\n }),\n [dictionaryKey, keyPath, setFocusedContent]\n );\n\n const isSelected = useMemo(\n () =>\n (focusedContent?.dictionaryKey === dictionaryKey &&\n (focusedContent?.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent?.keyPath ?? [], keyPath)) ??\n false,\n [focusedContent, keyPath]\n );\n\n useEffect(() => {\n // Use useEffect to avoid 'Text content does not match server-rendered HTML' error\n if (editedValue && typeof editedValue === 'string') {\n setDisplayedChildren(editedValue);\n } else {\n setDisplayedChildren(children);\n }\n }, [editedValue, focusedContent, children]);\n\n return (\n <ContentSelector onPress={handleSelect} isSelecting={isSelected} {...props}>\n {displayedChildren}\n </ContentSelector>\n );\n};\n\nexport const ContentSelectorWrapper: FC<ContentSelectorWrapperProps> = ({\n children,\n ...props\n}) => {\n const { enabled } = useEditorEnabled();\n\n if (enabled) {\n return (\n <ContentSelectorWrapperContent {...props}>\n {children}\n </ContentSelectorWrapperContent>\n );\n }\n\n return <>{children}</>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport { type NodeProps, isSameKeyPath } from '@intlayer/core';\nimport {\n useFocusDictionary,\n useEditedContentActions,\n useEditorEnabled,\n} from '@intlayer/editor-react';\nimport {\n useCallback,\n useEffect,\n useState,\n useMemo,\n type FC,\n type ReactNode,\n HTMLAttributes,\n} from 'react';\nimport { ContentSelector } from '../UI/ContentSelector';\nimport { useIntlayerContext } from '../client';\n\nexport type ContentSelectorWrapperProps = NodeProps &\n Omit<HTMLAttributes<HTMLDivElement>, 'content'>;\n\nconst ContentSelectorWrapperContent: FC<ContentSelectorWrapperProps> = ({\n children,\n dictionaryKey,\n keyPath,\n ...props\n}) => {\n const { focusedContent, setFocusedContent } = useFocusDictionary();\n const { getEditedContentValue } = useEditedContentActions();\n\n const editedValue = useMemo(\n () => getEditedContentValue(dictionaryKey, keyPath),\n [dictionaryKey, keyPath, getEditedContentValue]\n );\n\n const [displayedChildren, setDisplayedChildren] =\n useState<ReactNode>(children);\n\n const handleSelect = useCallback(\n () =>\n setFocusedContent({\n dictionaryKey,\n keyPath,\n }),\n [dictionaryKey, keyPath, setFocusedContent]\n );\n\n const isSelected = useMemo(\n () =>\n (focusedContent?.dictionaryKey === dictionaryKey &&\n (focusedContent?.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent?.keyPath ?? [], keyPath)) ??\n false,\n [focusedContent, keyPath, dictionaryKey]\n );\n\n useEffect(() => {\n // Use useEffect to avoid 'Text content does not match server-rendered HTML' error\n if (editedValue && typeof editedValue === 'string') {\n setDisplayedChildren(editedValue);\n } else {\n setDisplayedChildren(children);\n }\n }, [editedValue, focusedContent, children]);\n\n return (\n <ContentSelector onPress={handleSelect} isSelecting={isSelected} {...props}>\n {displayedChildren}\n </ContentSelector>\n );\n};\n\nexport const ContentSelectorWrapper: FC<ContentSelectorWrapperProps> = ({\n children,\n ...props\n}) => {\n const { enabled } = useEditorEnabled();\n const { disableEditor } = useIntlayerContext();\n\n if (enabled && !disableEditor) {\n return (\n <ContentSelectorWrapperContent {...props}>\n {children}\n </ContentSelectorWrapperContent>\n );\n }\n\n return <>{children}</>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoEI;AAlEJ,kBAA8C;AAC9C,0BAIO;AACP,mBAQO;AACP,6BAAgC;AAChC,oBAAmC;AAKnC,MAAM,gCAAiE,CAAC;AAAA,EACtE;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,EAAE,gBAAgB,kBAAkB,QAAI,wCAAmB;AACjE,QAAM,EAAE,sBAAsB,QAAI,6CAAwB;AAE1D,QAAM,kBAAc;AAAA,IAClB,MAAM,sBAAsB,eAAe,OAAO;AAAA,IAClD,CAAC,eAAe,SAAS,qBAAqB;AAAA,EAChD;AAEA,QAAM,CAAC,mBAAmB,oBAAoB,QAC5C,uBAAoB,QAAQ;AAE9B,QAAM,mBAAe;AAAA,IACnB,MACE,kBAAkB;AAAA,MAChB;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,CAAC,eAAe,SAAS,iBAAiB;AAAA,EAC5C;AAEA,QAAM,iBAAa;AAAA,IACjB,OACG,gBAAgB,kBAAkB,kBAChC,gBAAgB,SAAS,UAAU,KAAK,SACzC,2BAAc,gBAAgB,WAAW,CAAC,GAAG,OAAO,MACtD;AAAA,IACF,CAAC,gBAAgB,SAAS,aAAa;AAAA,EACzC;AAEA,8BAAU,MAAM;AAEd,QAAI,eAAe,OAAO,gBAAgB,UAAU;AAClD,2BAAqB,WAAW;AAAA,IAClC,OAAO;AACL,2BAAqB,QAAQ;AAAA,IAC/B;AAAA,EACF,GAAG,CAAC,aAAa,gBAAgB,QAAQ,CAAC;AAE1C,SACE,4CAAC,0CAAgB,SAAS,cAAc,aAAa,YAAa,GAAG,OAClE,6BACH;AAEJ;AAEO,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,EAAE,QAAQ,QAAI,sCAAiB;AACrC,QAAM,EAAE,cAAc,QAAI,kCAAmB;AAE7C,MAAI,WAAW,CAAC,eAAe;AAC7B,WACE,4CAAC,iCAA+B,GAAG,OAChC,UACH;AAAA,EAEJ;AAEA,SAAO,2EAAG,UAAS;AACrB;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getDictionary.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n type Dictionary,\n type Plugins,\n getDictionary as getDictionaryCore,\n} from '@intlayer/core';\nimport {\n type DeepTransformContent,\n intlayerNodePlugins,\n markdownPlugin,\n reactNodePlugins,\n} from './plugins';\nimport type { Locales } from '@intlayer/config/client';\n\nexport const getDictionary = <\n T extends Dictionary,\n L extends
|
|
1
|
+
{"version":3,"sources":["../../src/getDictionary.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n type Dictionary,\n type Plugins,\n getDictionary as getDictionaryCore,\n} from '@intlayer/core';\nimport {\n type DeepTransformContent,\n intlayerNodePlugins,\n markdownPlugin,\n reactNodePlugins,\n} from './plugins';\nimport type { Locales, LocalesValues } from '@intlayer/config/client';\n\nexport const getDictionary = <\n T extends Dictionary,\n L extends LocalesValues = Locales,\n>(\n dictionary: T,\n locale?: L,\n additionalPlugins?: Plugins[]\n) => {\n const plugins: Plugins[] = [\n intlayerNodePlugins,\n reactNodePlugins,\n markdownPlugin,\n ...(additionalPlugins ?? []),\n ];\n\n return getDictionaryCore(\n dictionary,\n locale,\n plugins\n ) as any as DeepTransformContent<T['content']>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAIO;AACP,qBAKO;AAGA,MAAM,gBAAgB,CAI3B,YACA,QACA,sBACG;AACH,QAAM,UAAqB;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAI,qBAAqB,CAAC;AAAA,EAC5B;AAEA,aAAO,YAAAA;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["getDictionaryCore"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getIntlayer.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport {\n type DictionaryKeys,\n type Plugins,\n getIntlayer as getIntlayerCore,\n} from '@intlayer/core';\nimport {\n type DeepTransformContent,\n intlayerNodePlugins,\n markdownPlugin,\n reactNodePlugins,\n} from './plugins';\nimport type { IntlayerDictionaryTypesConnector,
|
|
1
|
+
{"version":3,"sources":["../../src/getIntlayer.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport {\n type DictionaryKeys,\n type Plugins,\n getIntlayer as getIntlayerCore,\n} from '@intlayer/core';\nimport {\n type DeepTransformContent,\n intlayerNodePlugins,\n markdownPlugin,\n reactNodePlugins,\n} from './plugins';\nimport type { IntlayerDictionaryTypesConnector, LocalesValues } from 'intlayer';\n\nexport const getIntlayer = <T extends DictionaryKeys, L extends LocalesValues>(\n key: T,\n locale?: L,\n additionalPlugins?: Plugins[]\n) => {\n const plugins: Plugins[] = [\n intlayerNodePlugins,\n reactNodePlugins,\n markdownPlugin,\n ...(additionalPlugins ?? []),\n ];\n\n return getIntlayerCore(key, locale, plugins) as any as DeepTransformContent<\n IntlayerDictionaryTypesConnector[T]['content']\n >;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,kBAIO;AACP,qBAKO;AAGA,MAAM,cAAc,CACzB,KACA,QACA,sBACG;AACH,QAAM,UAAqB;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAI,qBAAqB,CAAC;AAAA,EAC5B;AAEA,aAAO,YAAAA,aAAgB,KAAK,QAAQ,OAAO;AAG7C;","names":["getIntlayerCore"]}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -20,6 +20,7 @@ var index_exports = {};
|
|
|
20
20
|
__export(index_exports, {
|
|
21
21
|
IntlayerClientContext: () => import_client.IntlayerClientContext,
|
|
22
22
|
IntlayerProvider: () => import_client.IntlayerProvider,
|
|
23
|
+
IntlayerProviderContent: () => import_client.IntlayerProviderContent,
|
|
23
24
|
MarkdownProvider: () => import_markdown.MarkdownProvider,
|
|
24
25
|
getBrowserLocale: () => import_client.getBrowserLocale,
|
|
25
26
|
localeCookie: () => import_client.localeCookie,
|
|
@@ -40,6 +41,7 @@ var import_markdown = require('./markdown/index.cjs');
|
|
|
40
41
|
0 && (module.exports = {
|
|
41
42
|
IntlayerClientContext,
|
|
42
43
|
IntlayerProvider,
|
|
44
|
+
IntlayerProviderContent,
|
|
43
45
|
MarkdownProvider,
|
|
44
46
|
getBrowserLocale,
|
|
45
47
|
localeCookie,
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import { IInterpreterPluginReact } from './plugins';\n\ndeclare module '@intlayer/core' {\n interface IInterpreterPlugin<T, S> extends IInterpreterPluginReact<T
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import { IInterpreterPluginReact } from './plugins';\n\ndeclare module '@intlayer/core' {\n interface IInterpreterPlugin<T, S> extends IInterpreterPluginReact<T> {}\n}\n\nexport {\n IntlayerProvider,\n IntlayerProviderContent,\n type IntlayerProviderProps,\n IntlayerClientContext,\n useIntlayer,\n useIntlayerAsync,\n useDictionary,\n useLocale,\n useLocaleCookie,\n useIntlayerContext,\n localeCookie,\n setLocaleCookie,\n getBrowserLocale,\n useLocaleBase,\n t,\n} from './client/index';\nexport { type IntlayerNode } from './IntlayerNode';\nexport { MarkdownProvider } from './markdown/index';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,oBAgBO;AAEP,sBAAiC;","names":[]}
|
package/dist/cjs/plugins.cjs
CHANGED
|
@@ -24,9 +24,9 @@ __export(plugins_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(plugins_exports);
|
|
26
26
|
var import_core = require("@intlayer/core");
|
|
27
|
-
var import_react = require("react");
|
|
28
27
|
var import_editor = require('./editor/index.cjs');
|
|
29
28
|
var import_renderMarkdown = require('./markdown/renderMarkdown.cjs');
|
|
29
|
+
var import_renderReactElement = require('./reactElement/renderReactElement.cjs');
|
|
30
30
|
const intlayerNodePlugins = {
|
|
31
31
|
canHandle: (node) => typeof node === "bigint" || typeof node === "string" || typeof node === "number",
|
|
32
32
|
transform: (_node, {
|
|
@@ -35,42 +35,9 @@ const intlayerNodePlugins = {
|
|
|
35
35
|
...rest
|
|
36
36
|
}) => (0, import_editor.renderIntlayerEditor)(rest)
|
|
37
37
|
};
|
|
38
|
-
const createReactElement = (element) => {
|
|
39
|
-
if (typeof element === "string") {
|
|
40
|
-
return element;
|
|
41
|
-
}
|
|
42
|
-
const convertChildrenAsArray = (element2) => {
|
|
43
|
-
if (element2?.props && typeof element2.props.children === "object") {
|
|
44
|
-
const childrenResult = [];
|
|
45
|
-
const { children } = element2.props;
|
|
46
|
-
Object.keys(children ?? {}).forEach((key) => {
|
|
47
|
-
childrenResult.push(
|
|
48
|
-
createReactElement((children ?? {})[key])
|
|
49
|
-
);
|
|
50
|
-
});
|
|
51
|
-
return {
|
|
52
|
-
...element2,
|
|
53
|
-
props: { ...element2.props, children: childrenResult }
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
return {
|
|
57
|
-
...element2,
|
|
58
|
-
props: { ...element2.props, children: element2.props.children }
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
const fixedElement = convertChildrenAsArray(
|
|
62
|
-
element
|
|
63
|
-
);
|
|
64
|
-
const { type, props } = fixedElement;
|
|
65
|
-
return (0, import_react.createElement)(
|
|
66
|
-
type ?? "div",
|
|
67
|
-
props,
|
|
68
|
-
...props.children
|
|
69
|
-
);
|
|
70
|
-
};
|
|
71
38
|
const reactNodePlugins = {
|
|
72
39
|
canHandle: (node) => typeof node === "object" && typeof node.ref !== "undefined" && typeof node.props !== "undefined" && typeof node.key !== "undefined",
|
|
73
|
-
transform:
|
|
40
|
+
transform: import_renderReactElement.renderReactElement
|
|
74
41
|
};
|
|
75
42
|
const markdownPlugin = {
|
|
76
43
|
canHandle: (node) => typeof node === "object" && node?.nodeType === import_core.NodeType.Markdown,
|
package/dist/cjs/plugins.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n type Plugins,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n type DeepTransformContent as DeepTransformContentCore,\n type MarkdownContent,\n NodeType,\n} from '@intlayer/core';\nimport
|
|
1
|
+
{"version":3,"sources":["../../src/plugins.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/import/no-cycle */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n type Plugins,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n type DeepTransformContent as DeepTransformContentCore,\n type MarkdownContent,\n NodeType,\n} from '@intlayer/core';\nimport type { ReactNode } from 'react';\nimport { renderIntlayerEditor } from './editor';\nimport type { IntlayerNode } from './IntlayerNode';\nimport { renderMarkdown } from './markdown/renderMarkdown';\nimport { renderReactElement } from './reactElement/renderReactElement';\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const intlayerNodePlugins: Plugins = {\n canHandle: (node) =>\n typeof node === 'bigint' ||\n typeof node === 'string' ||\n typeof node === 'number',\n transform: (\n _node,\n {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n }\n ) => renderIntlayerEditor(rest),\n};\n\n/** ---------------------------------------------\n * REACT NODE PLUGIN\n * --------------------------------------------- */\n\nexport type ReactNodeCond<T> = T extends {\n ref: any;\n props: any;\n key: any;\n}\n ? ReactNode\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const reactNodePlugins: Plugins = {\n canHandle: (node) =>\n typeof node === 'object' &&\n typeof node.ref !== 'undefined' &&\n typeof node.props !== 'undefined' &&\n typeof node.key !== 'undefined',\n\n transform: renderReactElement,\n};\n\n/**\n * MARKDOWN PLUGIN\n */\n\nexport type MarkdownCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeType.Markdown]: string;\n}\n ? IntlayerNode<string>\n : never;\n\n/** Markdown plugin. Replaces node with a function that takes quantity => string. */\nexport const markdownPlugin: Plugins = {\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Markdown,\n transform: (node: MarkdownContent) => renderMarkdown(node[NodeType.Markdown]),\n};\n\n/** ---------------------------------------------\n * PLUGINS RESULT\n * --------------------------------------------- */\n\nexport interface IInterpreterPluginReact<T> {\n reactNode: ReactNodeCond<T>;\n intlayerNode: IntlayerNodeCond<T>;\n markdown: MarkdownCond<T>;\n}\n\n/**\n * Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.\n *\n * Otherwise the the `react-intlayer` plugins will override the types of `intlayer` functions.\n */\nexport type IInterpreterPluginState = IInterpreterPluginStateCore & {\n reactNode: true;\n intlayerNode: true;\n markdown: true;\n};\n\nexport type DeepTransformContent<T> = DeepTransformContentCore<\n T,\n IInterpreterPluginState\n>;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,kBAMO;AAEP,oBAAqC;AAErC,4BAA+B;AAC/B,gCAAmC;AAW5B,MAAM,sBAA+B;AAAA,EAC1C,WAAW,CAAC,SACV,OAAO,SAAS,YAChB,OAAO,SAAS,YAChB,OAAO,SAAS;AAAA,EAClB,WAAW,CACT,OACA;AAAA,IACE;AAAA;AAAA,IACA,GAAG;AAAA,EACL,UACG,oCAAqB,IAAI;AAChC;AAeO,MAAM,mBAA4B;AAAA,EACvC,WAAW,CAAC,SACV,OAAO,SAAS,YAChB,OAAO,KAAK,QAAQ,eACpB,OAAO,KAAK,UAAU,eACtB,OAAO,KAAK,QAAQ;AAAA,EAEtB,WAAW;AACb;AAcO,MAAM,iBAA0B;AAAA,EACrC,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,qBAAS;AAAA,EAC1D,WAAW,CAAC,aAA0B,sCAAe,KAAK,qBAAS,QAAQ,CAAC;AAC9E;","names":[]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var renderReactElement_exports = {};
|
|
20
|
+
__export(renderReactElement_exports, {
|
|
21
|
+
renderReactElement: () => renderReactElement
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(renderReactElement_exports);
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
const renderReactElement = (element) => {
|
|
26
|
+
if (typeof element === "string") {
|
|
27
|
+
return element;
|
|
28
|
+
}
|
|
29
|
+
const convertChildrenAsArray = (element2) => {
|
|
30
|
+
if (element2?.props && typeof element2.props.children === "object") {
|
|
31
|
+
const childrenResult = [];
|
|
32
|
+
const { children } = element2.props;
|
|
33
|
+
Object.keys(children ?? {}).forEach((key) => {
|
|
34
|
+
childrenResult.push(
|
|
35
|
+
renderReactElement((children ?? {})[key])
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
...element2,
|
|
40
|
+
props: { ...element2.props, children: childrenResult }
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
...element2,
|
|
45
|
+
props: { ...element2.props, children: element2.props.children }
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
const fixedElement = convertChildrenAsArray(
|
|
49
|
+
element
|
|
50
|
+
);
|
|
51
|
+
const { type, props } = fixedElement;
|
|
52
|
+
return (0, import_react.createElement)(
|
|
53
|
+
type ?? "div",
|
|
54
|
+
props,
|
|
55
|
+
...props.children
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
59
|
+
0 && (module.exports = {
|
|
60
|
+
renderReactElement
|
|
61
|
+
});
|
|
62
|
+
//# sourceMappingURL=renderReactElement.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/reactElement/renderReactElement.ts"],"sourcesContent":["import { type ReactElement, type ReactNode, createElement } from 'react';\n\n// This function recursively creates React elements from a given JSON-like structure\nexport const renderReactElement = (element: ReactElement) => {\n if (typeof element === 'string') {\n // If it's a string, simply return it (used for text content)\n return element;\n }\n\n const convertChildrenAsArray = (\n element: ReactElement<{ children?: ReactNode }>\n ): ReactElement<{ children?: ReactNode }> => {\n if (element?.props && typeof element.props.children === 'object') {\n const childrenResult: ReactNode[] = [];\n const { children } = element.props;\n\n // Create the children elements recursively, if any\n Object.keys(children ?? {}).forEach((key) => {\n childrenResult.push(\n renderReactElement((children ?? {})[key as keyof typeof children])\n );\n });\n\n return {\n ...element,\n props: { ...element.props, children: childrenResult },\n };\n }\n\n return {\n ...element,\n props: { ...element.props, children: element.props.children },\n };\n };\n\n const fixedElement = convertChildrenAsArray(\n element as ReactElement<{ children?: ReactNode }>\n );\n\n const { type, props } = fixedElement;\n\n // Create and return the React element\n return createElement(\n type ?? 'div',\n props,\n ...(props.children as ReactNode[])\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiE;AAG1D,MAAM,qBAAqB,CAAC,YAA0B;AAC3D,MAAI,OAAO,YAAY,UAAU;AAE/B,WAAO;AAAA,EACT;AAEA,QAAM,yBAAyB,CAC7BA,aAC2C;AAC3C,QAAIA,UAAS,SAAS,OAAOA,SAAQ,MAAM,aAAa,UAAU;AAChE,YAAM,iBAA8B,CAAC;AACrC,YAAM,EAAE,SAAS,IAAIA,SAAQ;AAG7B,aAAO,KAAK,YAAY,CAAC,CAAC,EAAE,QAAQ,CAAC,QAAQ;AAC3C,uBAAe;AAAA,UACb,oBAAoB,YAAY,CAAC,GAAG,GAA4B,CAAC;AAAA,QACnE;AAAA,MACF,CAAC;AAED,aAAO;AAAA,QACL,GAAGA;AAAA,QACH,OAAO,EAAE,GAAGA,SAAQ,OAAO,UAAU,eAAe;AAAA,MACtD;AAAA,IACF;AAEA,WAAO;AAAA,MACL,GAAGA;AAAA,MACH,OAAO,EAAE,GAAGA,SAAQ,OAAO,UAAUA,SAAQ,MAAM,SAAS;AAAA,IAC9D;AAAA,EACF;AAEA,QAAM,eAAe;AAAA,IACnB;AAAA,EACF;AAEA,QAAM,EAAE,MAAM,MAAM,IAAI;AAGxB,aAAO;AAAA,IACL,QAAQ;AAAA,IACR;AAAA,IACA,GAAI,MAAM;AAAA,EACZ;AACF;","names":["element"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/IntlayerServerProvider.tsx"],"sourcesContent":["import { type
|
|
1
|
+
{"version":3,"sources":["../../../src/server/IntlayerServerProvider.tsx"],"sourcesContent":["import { type LocalesValues, getConfiguration } from '@intlayer/config/client';\nimport type { FC, PropsWithChildren } from 'react';\nimport { createServerContext, getServerContext } from './serverContext';\n\nconst { defaultLocale } = getConfiguration().internationalization;\n\n/**\n * Context that store the current locale on the server side\n */\nexport const IntlayerServerContext =\n createServerContext<LocalesValues>(defaultLocale);\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayer = () => getServerContext(IntlayerServerContext);\n\n/**\n * Get the current locale\n */\nexport const locale = getServerContext(IntlayerServerContext);\n\nexport type IntlayerServerProviderProps = PropsWithChildren & {\n locale?: LocalesValues;\n};\n\n/**\n * Provider that store the current locale on the server side\n */\nexport const IntlayerServerProvider: FC<IntlayerServerProviderProps> = ({\n children,\n locale = defaultLocale,\n}) => (\n <IntlayerServerContext.Provider value={locale}>\n {children}\n </IntlayerServerContext.Provider>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiCE;AAjCF,oBAAqD;AAErD,2BAAsD;AAEtD,MAAM,EAAE,cAAc,QAAI,gCAAiB,EAAE;AAKtC,MAAM,4BACX,0CAAmC,aAAa;AAK3C,MAAM,cAAc,UAAM,uCAAiB,qBAAqB;AAKhE,MAAM,aAAS,uCAAiB,qBAAqB;AASrD,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA,QAAAA,UAAS;AACX,MACE,4CAAC,sBAAsB,UAAtB,EAA+B,OAAOA,SACpC,UACH;","names":["locale"]}
|
package/dist/cjs/server/t.cjs
CHANGED
|
@@ -25,9 +25,7 @@ var import_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
|
|
|
25
25
|
var import_serverContext = require('./serverContext.cjs');
|
|
26
26
|
var import_core = require("@intlayer/core");
|
|
27
27
|
const t = (multilangContent, locale) => {
|
|
28
|
-
const currentLocale = (0, import_serverContext.getServerContext)(
|
|
29
|
-
import_IntlayerServerProvider.IntlayerServerContext
|
|
30
|
-
);
|
|
28
|
+
const currentLocale = (0, import_serverContext.getServerContext)(import_IntlayerServerProvider.IntlayerServerContext);
|
|
31
29
|
const localeTarget = locale ?? currentLocale;
|
|
32
30
|
return (0, import_core.getTranslation)(multilangContent, localeTarget);
|
|
33
31
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/t.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../../src/server/t.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\nimport { type LanguageContent, getTranslation } from '@intlayer/core';\n\n/**\n * On the server side, hook to get the translation content based on the locale\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```ts\n * const content = t<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const t = <Content = string>(\n multilangContent: LanguageContent<Content>,\n locale?: LocalesValues\n) => {\n const currentLocale = getServerContext<LocalesValues>(IntlayerServerContext);\n const localeTarget = locale ?? currentLocale;\n\n return getTranslation<Content>(multilangContent, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oCAAsC;AACtC,2BAAiC;AACjC,kBAAqD;AAuB9C,MAAM,IAAI,CACf,kBACA,WACG;AACH,QAAM,oBAAgB,uCAAgC,mDAAqB;AAC3E,QAAM,eAAe,UAAU;AAE/B,aAAO,4BAAwB,kBAAkB,YAAY;AAC/D;","names":[]}
|
|
@@ -24,7 +24,7 @@ module.exports = __toCommonJS(useDictionary_exports);
|
|
|
24
24
|
var import_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
|
|
25
25
|
var import_serverContext = require('./serverContext.cjs');
|
|
26
26
|
var import_getDictionary = require('../getDictionary.cjs');
|
|
27
|
-
const useDictionary = (dictionary, locale
|
|
27
|
+
const useDictionary = (dictionary, locale) => {
|
|
28
28
|
const localeTarget = locale ?? (0, import_serverContext.getServerContext)(import_IntlayerServerProvider.IntlayerServerContext);
|
|
29
29
|
return (0, import_getDictionary.getDictionary)(dictionary, localeTarget);
|
|
30
30
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport { type Dictionary } from '@intlayer/core';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\nimport { getDictionary } from '../getDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionary = <T extends Dictionary>(\n dictionary: T,\n locale?: LocalesValues\n) => {\n const localeTarget =\n locale ?? getServerContext<LocalesValues>(IntlayerServerContext);\n\n return getDictionary<T, LocalesValues>(dictionary, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oCAAsC;AACtC,2BAAiC;AACjC,2BAA8B;AAOvB,MAAM,gBAAgB,CAC3B,YACA,WACG;AACH,QAAM,eACJ,cAAU,uCAAgC,mDAAqB;AAEjE,aAAO,oCAAgC,YAAY,YAAY;AACjE;","names":[]}
|
|
@@ -24,7 +24,7 @@ module.exports = __toCommonJS(useIntlayer_exports);
|
|
|
24
24
|
var import_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
|
|
25
25
|
var import_serverContext = require('./serverContext.cjs');
|
|
26
26
|
var import_getIntlayer = require('../getIntlayer.cjs');
|
|
27
|
-
const useIntlayer = (key, locale
|
|
27
|
+
const useIntlayer = (key, locale) => {
|
|
28
28
|
const localeTarget = locale ?? (0, import_serverContext.getServerContext)(import_IntlayerServerProvider.IntlayerServerContext);
|
|
29
29
|
return (0, import_getIntlayer.getIntlayer)(key, localeTarget);
|
|
30
30
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\nimport { type DictionaryKeys } from '@intlayer/core';\nimport { getIntlayer } from '../getIntlayer';\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useIntlayer = <T extends DictionaryKeys, K extends LocalesValues>(\n key: T,\n locale?: K\n) => {\n const localeTarget =\n locale ?? getServerContext<LocalesValues>(IntlayerServerContext);\n\n return getIntlayer(key, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oCAAsC;AACtC,2BAAiC;AAEjC,yBAA4B;AAOrB,MAAM,cAAc,CACzB,KACA,WACG;AACH,QAAM,eACJ,cAAU,uCAAgC,mDAAqB;AAEjE,aAAO,gCAAY,KAAK,YAAY;AACtC;","names":[]}
|
|
@@ -16,13 +16,15 @@ import { PoweredByMeta } from "./PoweredByMeta.mjs";
|
|
|
16
16
|
import { localeCookie, setLocaleCookie } from "./useLocaleCookie.mjs";
|
|
17
17
|
const IntlayerClientContext = createContext({
|
|
18
18
|
locale: localeCookie ?? getConfiguration().internationalization.defaultLocale,
|
|
19
|
-
setLocale: () => null
|
|
19
|
+
setLocale: () => null,
|
|
20
|
+
disableEditor: false
|
|
20
21
|
});
|
|
21
22
|
const useIntlayerContext = () => useContext(IntlayerClientContext);
|
|
22
23
|
const IntlayerProviderContent = ({
|
|
23
24
|
locale,
|
|
24
25
|
children,
|
|
25
|
-
setLocale: setLocaleProp
|
|
26
|
+
setLocale: setLocaleProp,
|
|
27
|
+
disableEditor
|
|
26
28
|
}) => {
|
|
27
29
|
const { internationalization } = getConfiguration();
|
|
28
30
|
const { defaultLocale, locales: availableLocales } = internationalization;
|
|
@@ -33,32 +35,33 @@ const IntlayerProviderContent = ({
|
|
|
33
35
|
const setLocaleBase = useCallback(
|
|
34
36
|
(newLocale) => {
|
|
35
37
|
if (currentLocale.toString() === newLocale.toString()) return;
|
|
36
|
-
if (!availableLocales.includes(newLocale)) {
|
|
38
|
+
if (!availableLocales.map(String).includes(newLocale)) {
|
|
37
39
|
console.error(`Locale ${locale} is not available`);
|
|
38
40
|
return;
|
|
39
41
|
}
|
|
40
42
|
setCurrentLocale(newLocale);
|
|
41
43
|
setLocaleCookie(newLocale);
|
|
42
44
|
},
|
|
43
|
-
[availableLocales, currentLocale, locale]
|
|
45
|
+
[availableLocales, currentLocale, locale, setCurrentLocale]
|
|
44
46
|
);
|
|
45
47
|
const setLocale = useMemo(
|
|
46
48
|
() => setLocaleProp ?? setLocaleBase,
|
|
47
49
|
[setLocaleProp, setLocaleBase]
|
|
48
50
|
);
|
|
49
51
|
const value = useMemo(
|
|
50
|
-
() => ({ locale: currentLocale, setLocale }),
|
|
51
|
-
[currentLocale, setLocale]
|
|
52
|
+
() => ({ locale: currentLocale, setLocale, disableEditor }),
|
|
53
|
+
[currentLocale, setLocale, disableEditor]
|
|
52
54
|
);
|
|
53
|
-
return /* @__PURE__ */
|
|
55
|
+
return /* @__PURE__ */ jsxs(IntlayerClientContext.Provider, { value, children: [
|
|
54
56
|
/* @__PURE__ */ jsx(PoweredByMeta, {}),
|
|
55
57
|
children
|
|
56
|
-
] })
|
|
58
|
+
] });
|
|
57
59
|
};
|
|
58
|
-
const IntlayerProvider = (props) => /* @__PURE__ */ jsx(IntlayerEditorProvider, { children: /* @__PURE__ */ jsx(IntlayerProviderContent, { ...props }) });
|
|
60
|
+
const IntlayerProvider = (props) => /* @__PURE__ */ jsx(ChangedContentProvider, { children: /* @__PURE__ */ jsx(IntlayerEditorProvider, { children: /* @__PURE__ */ jsx(IntlayerProviderContent, { ...props }) }) });
|
|
59
61
|
export {
|
|
60
62
|
IntlayerClientContext,
|
|
61
63
|
IntlayerProvider,
|
|
64
|
+
IntlayerProviderContent,
|
|
62
65
|
useIntlayerContext
|
|
63
66
|
};
|
|
64
67
|
//# sourceMappingURL=IntlayerProvider.mjs.map
|