react-intlayer 4.1.10 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/cjs/{getEnumeration.cjs → IntlayerNode.cjs} +14 -13
- package/dist/cjs/IntlayerNode.cjs.map +1 -0
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/index.cjs +2 -5
- package/dist/cjs/client/index.cjs.map +1 -1
- package/dist/cjs/client/t.cjs +2 -2
- package/dist/cjs/client/t.cjs.map +1 -1
- package/dist/cjs/client/useContent.cjs +2 -2
- package/dist/cjs/client/useContent.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +3 -3
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +7 -4
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useIntlayerAsync.cjs +3 -4
- package/dist/cjs/client/useIntlayerAsync.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +1 -1
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleCookie.cjs.map +1 -1
- package/dist/cjs/client/useTraduction.cjs +5 -5
- package/dist/cjs/client/useTraduction.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelectorWrapper.cjs +1 -3
- package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs +3 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/renderContentEditor.cjs +5 -4
- package/dist/cjs/editor/renderContentEditor.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs +13 -13
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +10 -29
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/index.cjs +5 -13
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/{getIntlayerAsync.cjs → markdown/MarkdownProvider.cjs} +18 -19
- package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -0
- package/dist/cjs/{server/useTraduction.cjs → markdown/MarkdownRenderer.cjs} +17 -12
- package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -0
- package/dist/cjs/markdown/index.cjs +27 -0
- package/dist/cjs/markdown/index.cjs.map +1 -0
- package/dist/cjs/{getTranslation.cjs → markdown/renderMarkdown.cjs} +13 -16
- package/dist/cjs/markdown/renderMarkdown.cjs.map +1 -0
- package/dist/cjs/plugins.cjs +85 -0
- package/dist/cjs/plugins.cjs.map +1 -0
- package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
- package/dist/cjs/server/index.cjs +2 -8
- package/dist/cjs/server/index.cjs.map +1 -1
- package/dist/cjs/server/t.cjs +5 -3
- package/dist/cjs/server/t.cjs.map +1 -1
- package/dist/cjs/server/useDictionary.cjs +2 -2
- package/dist/cjs/server/useDictionary.cjs.map +1 -1
- package/dist/cjs/server/useIntlayer.cjs +2 -2
- package/dist/cjs/server/useIntlayer.cjs.map +1 -1
- package/dist/esm/IntlayerNode.mjs +16 -0
- package/dist/esm/IntlayerNode.mjs.map +1 -0
- package/dist/esm/UI/ContentSelector.mjs.map +1 -1
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/index.mjs +1 -3
- package/dist/esm/client/index.mjs.map +1 -1
- package/dist/esm/client/t.mjs +1 -1
- package/dist/esm/client/t.mjs.map +1 -1
- package/dist/esm/client/useContent.mjs +3 -3
- package/dist/esm/client/useContent.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +3 -3
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +8 -7
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useIntlayerAsync.mjs +5 -5
- package/dist/esm/client/useIntlayerAsync.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +1 -1
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleCookie.mjs.map +1 -1
- package/dist/esm/client/useTraduction.mjs +3 -3
- package/dist/esm/client/useTraduction.mjs.map +1 -1
- package/dist/esm/editor/ContentSelectorWrapper.mjs +1 -3
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs +3 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
- package/dist/esm/editor/renderContentEditor.mjs +5 -4
- package/dist/esm/editor/renderContentEditor.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs +18 -14
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs +15 -20
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/esm/index.mjs +3 -9
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownProvider.mjs +19 -0
- package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -0
- package/dist/esm/markdown/MarkdownRenderer.mjs +16 -0
- package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -0
- package/dist/esm/markdown/index.mjs +4 -0
- package/dist/esm/markdown/index.mjs.map +1 -0
- package/dist/esm/markdown/renderMarkdown.mjs +11 -0
- package/dist/esm/markdown/renderMarkdown.mjs.map +1 -0
- package/dist/esm/plugins.mjs +61 -0
- package/dist/esm/plugins.mjs.map +1 -0
- package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
- package/dist/esm/server/index.mjs +1 -5
- package/dist/esm/server/index.mjs.map +1 -1
- package/dist/esm/server/t.mjs +4 -2
- package/dist/esm/server/t.mjs.map +1 -1
- package/dist/esm/server/useDictionary.mjs +2 -2
- package/dist/esm/server/useDictionary.mjs.map +1 -1
- package/dist/esm/server/useIntlayer.mjs +2 -4
- package/dist/esm/server/useIntlayer.mjs.map +1 -1
- package/dist/types/IntlayerNode.d.ts +9 -0
- package/dist/types/IntlayerNode.d.ts.map +1 -0
- package/dist/types/UI/ContentSelector.d.ts +1 -1
- package/dist/types/UI/ContentSelector.d.ts.map +1 -1
- package/dist/types/client/IntlayerProvider.d.ts +4 -4
- package/dist/types/client/IntlayerProvider.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +0 -1
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/client/t.d.ts +1 -1
- package/dist/types/client/t.d.ts.map +1 -1
- package/dist/types/client/useContent.d.ts +1 -1
- package/dist/types/client/useDictionary.d.ts +3 -2
- package/dist/types/client/useDictionary.d.ts.map +1 -1
- package/dist/types/client/useIntlayer.d.ts +4 -2
- package/dist/types/client/useIntlayer.d.ts.map +1 -1
- package/dist/types/client/useIntlayerAsync.d.ts +4 -5
- package/dist/types/client/useIntlayerAsync.d.ts.map +1 -1
- package/dist/types/client/useLocale.d.ts +3 -3
- 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 +4 -4
- package/dist/types/client/useLocaleCookie.d.ts.map +1 -1
- package/dist/types/client/useTraduction.d.ts +3 -3
- package/dist/types/client/useTraduction.d.ts.map +1 -1
- package/dist/types/editor/ContentSelectorWrapper.d.ts +2 -8
- package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -1
- package/dist/types/editor/IntlayerEditorProvider.d.ts.map +1 -1
- package/dist/types/editor/renderContentEditor.d.ts +3 -7
- package/dist/types/editor/renderContentEditor.d.ts.map +1 -1
- package/dist/types/getDictionary.d.ts +4 -12
- package/dist/types/getDictionary.d.ts.map +1 -1
- package/dist/types/getIntlayer.d.ts +4 -34
- package/dist/types/getIntlayer.d.ts.map +1 -1
- package/dist/types/index.d.ts +8 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/markdown/MarkdownProvider.d.ts +9 -0
- package/dist/types/markdown/MarkdownProvider.d.ts.map +1 -0
- package/dist/types/markdown/MarkdownRenderer.d.ts +5 -0
- package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -0
- package/dist/types/markdown/index.d.ts +4 -0
- package/dist/types/markdown/index.d.ts.map +1 -0
- package/dist/types/markdown/renderMarkdown.d.ts +3 -0
- package/dist/types/markdown/renderMarkdown.d.ts.map +1 -0
- package/dist/types/plugins.d.ts +48 -0
- package/dist/types/plugins.d.ts.map +1 -0
- package/dist/types/server/IntlayerServerProvider.d.ts +7 -7
- package/dist/types/server/IntlayerServerProvider.d.ts.map +1 -1
- package/dist/types/server/index.d.ts +0 -2
- package/dist/types/server/index.d.ts.map +1 -1
- package/dist/types/server/t.d.ts +20 -4
- package/dist/types/server/t.d.ts.map +1 -1
- package/dist/types/server/useDictionary.d.ts +3 -2
- package/dist/types/server/useDictionary.d.ts.map +1 -1
- package/dist/types/server/useIntlayer.d.ts +3 -2
- package/dist/types/server/useIntlayer.d.ts.map +1 -1
- package/package.json +16 -16
- package/dist/cjs/getEnumeration.cjs.map +0 -1
- package/dist/cjs/getIntlayerAsync.cjs.map +0 -1
- package/dist/cjs/getTranslation.cjs.map +0 -1
- package/dist/cjs/processDictionary/contentDictionary.cjs +0 -17
- package/dist/cjs/processDictionary/contentDictionary.cjs.map +0 -1
- package/dist/cjs/processDictionary/index.cjs +0 -201
- package/dist/cjs/processDictionary/index.cjs.map +0 -1
- package/dist/cjs/recursiveTransformContent.cjs +0 -54
- package/dist/cjs/recursiveTransformContent.cjs.map +0 -1
- package/dist/cjs/server/getLocaleTranslation.cjs +0 -43
- package/dist/cjs/server/getLocaleTranslation.cjs.map +0 -1
- package/dist/cjs/server/useTraduction.cjs.map +0 -1
- package/dist/esm/getEnumeration.mjs +0 -12
- package/dist/esm/getEnumeration.mjs.map +0 -1
- package/dist/esm/getIntlayerAsync.mjs +0 -18
- package/dist/esm/getIntlayerAsync.mjs.map +0 -1
- package/dist/esm/getTranslation.mjs +0 -14
- package/dist/esm/getTranslation.mjs.map +0 -1
- package/dist/esm/processDictionary/contentDictionary.mjs +0 -1
- package/dist/esm/processDictionary/contentDictionary.mjs.map +0 -1
- package/dist/esm/processDictionary/index.mjs +0 -179
- package/dist/esm/processDictionary/index.mjs.map +0 -1
- package/dist/esm/recursiveTransformContent.mjs +0 -32
- package/dist/esm/recursiveTransformContent.mjs.map +0 -1
- package/dist/esm/server/getLocaleTranslation.mjs +0 -19
- package/dist/esm/server/getLocaleTranslation.mjs.map +0 -1
- package/dist/esm/server/useTraduction.mjs +0 -11
- package/dist/esm/server/useTraduction.mjs.map +0 -1
- package/dist/types/getEnumeration.d.ts +0 -31
- package/dist/types/getEnumeration.d.ts.map +0 -1
- package/dist/types/getIntlayerAsync.d.ts +0 -13
- package/dist/types/getIntlayerAsync.d.ts.map +0 -1
- package/dist/types/getTranslation.d.ts +0 -25
- package/dist/types/getTranslation.d.ts.map +0 -1
- package/dist/types/processDictionary/contentDictionary.d.ts +0 -14
- package/dist/types/processDictionary/contentDictionary.d.ts.map +0 -1
- package/dist/types/processDictionary/index.d.ts +0 -9
- package/dist/types/processDictionary/index.d.ts.map +0 -1
- package/dist/types/recursiveTransformContent.d.ts +0 -27
- package/dist/types/recursiveTransformContent.d.ts.map +0 -1
- package/dist/types/server/getLocaleTranslation.d.ts +0 -9
- package/dist/types/server/getLocaleTranslation.d.ts.map +0 -1
- package/dist/types/server/useTraduction.d.ts +0 -24
- package/dist/types/server/useTraduction.d.ts.map +0 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { useLocaleBase } from "./useLocaleBase.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { useTranslation } from "./useTraduction.mjs";
|
|
3
3
|
const useContent = (languageContent) => {
|
|
4
4
|
const { locale } = useLocaleBase();
|
|
5
|
-
const content =
|
|
5
|
+
const content = useTranslation(languageContent);
|
|
6
6
|
return {
|
|
7
7
|
locale,
|
|
8
8
|
content,
|
|
9
|
-
t:
|
|
9
|
+
t: useTranslation
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
12
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useContent.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useLocaleBase } from './useLocaleBase';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useContent.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useLocaleBase } from './useLocaleBase';\nimport { useTranslation } from './useTraduction';\n\n/**\n * On the client side, hook to get the translation content based on the locale\n */\nexport const useContent = <Content>(\n languageContent: LanguageContent<Content>\n) => {\n const { locale } = useLocaleBase();\n\n const content = useTranslation(languageContent);\n\n return {\n locale,\n content,\n t: useTranslation,\n };\n};\n"],"mappings":"AACA,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAKxB,MAAM,aAAa,CACxB,oBACG;AACH,QAAM,EAAE,OAAO,IAAI,cAAc;AAEjC,QAAM,UAAU,eAAe,eAAe;AAE9C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL;AACF;","names":[]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useContext } from "react";
|
|
3
|
-
import { getDictionary } from "../getDictionary.mjs";
|
|
4
3
|
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
5
|
-
|
|
4
|
+
import { getDictionary } from "../getDictionary.mjs";
|
|
5
|
+
const useDictionary = (dictionary, locale) => {
|
|
6
6
|
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
7
7
|
const localeTarget = locale ?? currentLocale;
|
|
8
|
-
return getDictionary(dictionary, localeTarget
|
|
8
|
+
return getDictionary(dictionary, localeTarget);
|
|
9
9
|
};
|
|
10
10
|
export {
|
|
11
11
|
useDictionary
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport type
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { 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?: Locales\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getDictionary(dictionary, localeTarget);\n};\n"],"mappings":";AAIA,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AACtC,SAAS,qBAAqB;AAOvB,MAAM,gBAAgB,CAC3B,YACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,SAAO,cAAc,YAAY,YAAY;AAC/C;","names":[]}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useChangedContent } from "@intlayer/editor-react";
|
|
3
3
|
import { useContext } from "react";
|
|
4
|
-
import { getDictionary } from "../getDictionary.mjs";
|
|
5
|
-
import {
|
|
6
|
-
getIntlayer
|
|
7
|
-
} from "../getIntlayer.mjs";
|
|
8
4
|
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
9
|
-
|
|
5
|
+
import { getDictionary } from "../getDictionary.mjs";
|
|
6
|
+
import { getIntlayer } from "../getIntlayer.mjs";
|
|
7
|
+
const useIntlayer = (key, locale) => {
|
|
10
8
|
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
11
9
|
const { changedContent } = useChangedContent();
|
|
12
10
|
const localeTarget = locale ?? currentLocale;
|
|
13
11
|
if (changedContent?.[key]) {
|
|
14
|
-
return getDictionary(
|
|
12
|
+
return getDictionary(
|
|
13
|
+
changedContent?.[key],
|
|
14
|
+
localeTarget
|
|
15
|
+
);
|
|
15
16
|
}
|
|
16
|
-
return getIntlayer(key, localeTarget
|
|
17
|
+
return getIntlayer(key, localeTarget);
|
|
17
18
|
};
|
|
18
19
|
export {
|
|
19
20
|
useIntlayer
|
|
@@ -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 { getDictionary } from '../getDictionary';\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';\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) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const { changedContent } = useChangedContent();\n const localeTarget = locale ?? currentLocale;\n\n if (changedContent?.[key]) {\n return getDictionary(\n changedContent?.[key] as IntlayerDictionaryTypesConnector[T],\n localeTarget\n );\n }\n\n return getIntlayer(key, localeTarget);\n};\n"],"mappings":";AAGA,SAAS,yBAAyB;AAClC,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AAEtC,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AASrB,MAAM,cAAc,CACzB,KACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,EAAE,eAAe,IAAI,kBAAkB;AAC7C,QAAM,eAAe,UAAU;AAE/B,MAAI,iBAAiB,GAAG,GAAG;AACzB,WAAO;AAAA,MACL,iBAAiB,GAAG;AAAA,MACpB;AAAA,IACF;AAAA,EACF;AAEA,SAAO,YAAY,KAAK,YAAY;AACtC;","names":[]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useContext, useEffect, useMemo, useState } from "react";
|
|
3
|
-
import {
|
|
4
|
-
getIntlayer
|
|
5
|
-
} from "../getIntlayer.mjs";
|
|
6
|
-
import { getIntlayerAsync } from "../getIntlayerAsync.mjs";
|
|
7
3
|
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
4
|
+
import {
|
|
5
|
+
getIntlayer,
|
|
6
|
+
getIntlayerAsync
|
|
7
|
+
} from "@intlayer/core";
|
|
8
8
|
const useIntlayerAsync = (key, locale, isRenderEditor = true) => {
|
|
9
9
|
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
10
10
|
const localeTarget = locale ?? currentLocale;
|
|
11
|
-
const localeDictionary = getIntlayer(key, localeTarget
|
|
11
|
+
const localeDictionary = getIntlayer(key, localeTarget);
|
|
12
12
|
const [distantDictionary, setDistantDictionary] = useState(void 0);
|
|
13
13
|
const [isLoading, setIsLoading] = useState(false);
|
|
14
14
|
useEffect(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useIntlayerAsync.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useContext, useEffect, useMemo, useState } from 'react';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useIntlayerAsync.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useContext, useEffect, useMemo, useState } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport {\n type Dictionary,\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?: Locales | `${Locales}`,\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":";AAGA,SAAS,YAAY,WAAW,SAAS,gBAAgB;AACzD,SAAS,6BAA6B;AACtC;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AAUA,MAAM,mBAAmB,CAC9B,KACA,QACA,iBAAiB,SACd;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAC/B,QAAM,mBAAmB,YAAY,KAAK,YAAY;AACtD,QAAM,CAAC,mBAAmB,oBAAoB,IAAI,SAEhD,MAAS;AACX,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAEhD,YAAU,MAAM;AACd,iBAAa,IAAI;AAEjB,qBAAiB,GAAG,EACjB,KAAK,CAACA,uBAAsB;AAC3B,UAAIA,oBAAmB;AACrB,6BAAqBA,kBAAiB;AAAA,MACxC;AAAA,IACF,CAAC,EACA,QAAQ,MAAM;AACb,mBAAa,KAAK;AAAA,IACpB,CAAC;AAAA,EACL,GAAG,CAAC,CAAC;AAEL,QAAM,aAAa;AAAA,IACjB,MAAM,qBAAqB;AAAA,IAC3B,CAAC,mBAAmB,gBAAgB;AAAA,EACtC;AAEA,SAAO,EAAE,GAAI,YAAuB,UAAU;AAGhD;","names":["distantDictionary"]}
|
|
@@ -25,7 +25,7 @@ const useLocale = ({ onLocaleChange } = {}) => {
|
|
|
25
25
|
const { setLocaleCookie } = useLocaleCookie();
|
|
26
26
|
const setLocale = useCallback(
|
|
27
27
|
(locale2) => {
|
|
28
|
-
if (!availableLocales.includes(locale2)) {
|
|
28
|
+
if (!availableLocales.map(String).includes(locale2)) {
|
|
29
29
|
console.error(`Locale ${locale2} is not available`);
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { type Locales } from '@intlayer/config';\nimport { 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: Locales) => 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: Locales) => {\n if (!availableLocales.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":";AAGA,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAC3B,SAAS,aAAa,kBAAkB;AACxC,SAAS,6BAA6B;AACtC,SAAS,uBAAuB;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,IAAI,iBAAiB,EAAE;AACvB,QAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,iBAAiB,EAAE;AACrB,QAAM,EAAE,QAAQ,WAAW,eAAe,IAAI;AAAA,IAC5C;AAAA,EACF;AACA,QAAM,EAAE,gBAAgB,IAAI,gBAAgB;AAE5C,QAAM,YAAY;AAAA,IAChB,CAACA,
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { type Locales } from '@intlayer/config';\nimport { 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: Locales | `${Locales}`) => 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: Locales | `${Locales}`) => {\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":";AAGA,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAC3B,SAAS,aAAa,kBAAkB;AACxC,SAAS,6BAA6B;AACtC,SAAS,uBAAuB;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,IAAI,iBAAiB,EAAE;AACvB,QAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,iBAAiB,EAAE;AACrB,QAAM,EAAE,QAAQ,WAAW,eAAe,IAAI;AAAA,IAC5C;AAAA,EACF;AACA,QAAM,EAAE,gBAAgB,IAAI,gBAAgB;AAE5C,QAAM,YAAY;AAAA,IAChB,CAACA,YAAmC;AAClC,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 Locales, 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 | Locales\n | undefined;\n\n/**\n * Set the locale cookie\n */\nexport const setLocaleCookie = (locale: Locales) => {\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,SAAuB,wBAAwB;AAC/C,OAAO,aAAa;AAEpB,MAAM,EAAE,WAAW,IAAI,iBAAiB,EAAE;AAE1C,MAAM,mBAA6C;AAAA,EACjD,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AACZ;AAKO,MAAM,eAAe,QAAQ,IAAI,UAAU;
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocaleCookie.ts"],"sourcesContent":["import { type Locales, 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 | Locales\n | `${Locales}`\n | undefined;\n\n/**\n * Set the locale cookie\n */\nexport const setLocaleCookie = (locale: Locales | `${Locales}`) => {\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,SAAuB,wBAAwB;AAC/C,OAAO,aAAa;AAEpB,MAAM,EAAE,WAAW,IAAI,iBAAiB,EAAE;AAE1C,MAAM,mBAA6C;AAAA,EACjD,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AACZ;AAKO,MAAM,eAAe,QAAQ,IAAI,UAAU;AAQ3C,MAAM,kBAAkB,CAAC,WAAmC;AACjE,UAAQ,IAAI,YAAY,QAAQ,gBAAgB;AAClD;AAKO,MAAM,kBAAkB,OAAO;AAAA,EACpC;AAAA,EACA;AACF;","names":[]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { getTranslation } from "@intlayer/core";
|
|
1
2
|
import { useContext } from "react";
|
|
2
|
-
import { getTranslation } from "../getTranslation.mjs";
|
|
3
3
|
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
4
|
-
const
|
|
4
|
+
const useTranslation = (languageContent) => {
|
|
5
5
|
const { locale } = useContext(IntlayerClientContext);
|
|
6
6
|
return getTranslation(languageContent, locale);
|
|
7
7
|
};
|
|
8
8
|
export {
|
|
9
|
-
|
|
9
|
+
useTranslation
|
|
10
10
|
};
|
|
11
11
|
//# sourceMappingURL=useTraduction.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import type
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import { getTranslation, type LanguageContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\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 * ```tsx\n * const content = useTranslation<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 useTranslation = <Content = string>(\n languageContent: LanguageContent<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return getTranslation(languageContent, locale);\n};\n"],"mappings":"AAAA,SAAS,sBAA4C;AACrD,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AAuB/B,MAAM,iBAAiB,CAC5B,oBACY;AACZ,QAAM,EAAE,OAAO,IAAI,WAAW,qBAAqB;AAEnD,SAAO,eAAe,iBAAiB,MAAM;AAC/C;","names":[]}
|
|
@@ -16,7 +16,6 @@ import { ContentSelector } from "../UI/ContentSelector.mjs";
|
|
|
16
16
|
const ContentSelectorWrapperContent = ({
|
|
17
17
|
children,
|
|
18
18
|
dictionaryKey,
|
|
19
|
-
dictionaryPath,
|
|
20
19
|
keyPath,
|
|
21
20
|
...props
|
|
22
21
|
}) => {
|
|
@@ -30,10 +29,9 @@ const ContentSelectorWrapperContent = ({
|
|
|
30
29
|
const handleSelect = useCallback(
|
|
31
30
|
() => setFocusedContent({
|
|
32
31
|
dictionaryKey,
|
|
33
|
-
dictionaryPath,
|
|
34
32
|
keyPath
|
|
35
33
|
}),
|
|
36
|
-
[dictionaryKey,
|
|
34
|
+
[dictionaryKey, keyPath, setFocusedContent]
|
|
37
35
|
);
|
|
38
36
|
const isSelected = useMemo(
|
|
39
37
|
() => (focusedContent?.dictionaryKey === dictionaryKey && (focusedContent?.keyPath?.length ?? 0) > 0 && isSameKeyPath(focusedContent?.keyPath ?? [], keyPath)) ?? false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport {
|
|
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":";AAmEI,SAoBK,UApBL;AAjEJ,SAAyB,qBAAqB;AAC9C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,uBAAuB;AAKhC,MAAM,gCAAiE,CAAC;AAAA,EACtE;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,EAAE,gBAAgB,kBAAkB,IAAI,mBAAmB;AACjE,QAAM,EAAE,sBAAsB,IAAI,wBAAwB;AAE1D,QAAM,cAAc;AAAA,IAClB,MAAM,sBAAsB,eAAe,OAAO;AAAA,IAClD,CAAC,eAAe,SAAS,qBAAqB;AAAA,EAChD;AAEA,QAAM,CAAC,mBAAmB,oBAAoB,IAC5C,SAAoB,QAAQ;AAE9B,QAAM,eAAe;AAAA,IACnB,MACE,kBAAkB;AAAA,MAChB;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,CAAC,eAAe,SAAS,iBAAiB;AAAA,EAC5C;AAEA,QAAM,aAAa;AAAA,IACjB,OACG,gBAAgB,kBAAkB,kBAChC,gBAAgB,SAAS,UAAU,KAAK,KACzC,cAAc,gBAAgB,WAAW,CAAC,GAAG,OAAO,MACtD;AAAA,IACF,CAAC,gBAAgB,OAAO;AAAA,EAC1B;AAEA,YAAU,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,oBAAC,mBAAgB,SAAS,cAAc,aAAa,YAAa,GAAG,OAClE,6BACH;AAEJ;AAEO,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,EAAE,QAAQ,IAAI,iBAAiB;AAErC,MAAI,SAAS;AACX,WACE,oBAAC,iCAA+B,GAAG,OAChC,UACH;AAAA,EAEJ;AAEA,SAAO,gCAAG,UAAS;AACrB;","names":[]}
|
|
@@ -19,7 +19,9 @@ const IntlayerEditorHooksEnabled = () => {
|
|
|
19
19
|
});
|
|
20
20
|
const { setLocaleDictionaries } = useDictionariesRecordActions();
|
|
21
21
|
useEffect(() => {
|
|
22
|
-
setLocaleDictionaries(
|
|
22
|
+
setLocaleDictionaries(
|
|
23
|
+
dictionaries
|
|
24
|
+
);
|
|
23
25
|
}, [setLocaleDictionaries]);
|
|
24
26
|
useIframeClickInterceptor();
|
|
25
27
|
const { setChangedContent } = useChangedContentActions();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n'use client';\n\nimport { IntlayerEventListener } from '@intlayer/api';\nimport { getConfiguration } from '@intlayer/config/client';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\nimport {\n EditorProvider,\n useCrossURLPathState,\n useDictionariesRecordActions,\n useIframeClickInterceptor,\n useEditorEnabled,\n useChangedContentActions,\n} from '@intlayer/editor-react';\nimport { useEffect, type FC, type PropsWithChildren } from 'react';\n\nconst IntlayerEditorHooksEnabled: FC = () => {\n /**\n * URL Messages\n */\n useCrossURLPathState(undefined, {\n receive: false,\n emit: true,\n });\n\n /**\n * Locale Dictionaries Messages\n */\n const { setLocaleDictionaries } = useDictionariesRecordActions();\n\n useEffect(() => {\n setLocaleDictionaries(dictionaries);\n }, [setLocaleDictionaries]);\n\n /**\n * Click Messages\n */\n useIframeClickInterceptor();\n\n /**\n * Hot reloading\n */\n const { setChangedContent } = useChangedContentActions();\n const { editor } = getConfiguration();\n const eventSource = new IntlayerEventListener();\n\n useEffect(() => {\n if (!editor.hotReload) return;\n if (!editor.clientId) return;\n if (!editor.clientSecret) return;\n\n eventSource.initialize();\n\n eventSource.onDictionaryChange = (dictionary) =>\n setChangedContent(dictionary.key, dictionary.content);\n\n return () => eventSource.cleanup();\n }, []);\n\n return <></>;\n};\n\nconst IntlayerEditorHook: FC = () => {\n const { enabled } = useEditorEnabled();\n\n return enabled ? <IntlayerEditorHooksEnabled /> : <></>;\n};\n\nexport const IntlayerEditorProvider: FC<PropsWithChildren> = ({ children }) => {\n const configuration = getConfiguration();\n\n const { editor } = configuration;\n\n return (\n <EditorProvider\n postMessage={(data: any) => {\n if (typeof window === 'undefined') return;\n\n if (editor.applicationURL.length > 0) {\n window?.postMessage(\n data,\n // Use to restrict the origin of the editor for security reasons.\n // Correspond to the current application URL to synchronize the locales states.\n editor.applicationURL\n );\n }\n if (editor.editorURL.length > 0) {\n window.parent?.postMessage(\n data,\n // Use to restrict the origin of the editor for security reasons.\n // Correspond to the editor URL to synchronize the locales states.\n editor.editorURL\n );\n }\n\n if (editor.cmsURL.length > 0) {\n window.parent?.postMessage(\n data,\n // Use to restrict the origin of the CMS for security reasons.\n // Correspond to the CMS URL.\n editor.cmsURL\n );\n }\n }}\n allowedOrigins={[editor.editorURL, editor.cmsURL, editor.applicationURL]}\n mode=\"client\"\n configuration={configuration}\n >\n <IntlayerEditorHook />\n {children}\n </EditorProvider>\n );\n};\n"],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n'use client';\n\nimport { IntlayerEventListener } from '@intlayer/api';\nimport { getConfiguration } from '@intlayer/config/client';\nimport { Dictionary } from '@intlayer/core';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\nimport {\n EditorProvider,\n useCrossURLPathState,\n useDictionariesRecordActions,\n useIframeClickInterceptor,\n useEditorEnabled,\n useChangedContentActions,\n} from '@intlayer/editor-react';\nimport { useEffect, type FC, type PropsWithChildren } from 'react';\n\nconst IntlayerEditorHooksEnabled: FC = () => {\n /**\n * URL Messages\n */\n useCrossURLPathState(undefined, {\n receive: false,\n emit: true,\n });\n\n /**\n * Locale Dictionaries Messages\n */\n const { setLocaleDictionaries } = useDictionariesRecordActions();\n\n useEffect(() => {\n setLocaleDictionaries(\n dictionaries as unknown as Record<string, Dictionary>\n );\n }, [setLocaleDictionaries]);\n\n /**\n * Click Messages\n */\n useIframeClickInterceptor();\n\n /**\n * Hot reloading\n */\n const { setChangedContent } = useChangedContentActions();\n const { editor } = getConfiguration();\n const eventSource = new IntlayerEventListener();\n\n useEffect(() => {\n if (!editor.hotReload) return;\n if (!editor.clientId) return;\n if (!editor.clientSecret) return;\n\n eventSource.initialize();\n\n eventSource.onDictionaryChange = (dictionary) =>\n setChangedContent(dictionary.key, dictionary.content);\n\n return () => eventSource.cleanup();\n }, []);\n\n return <></>;\n};\n\nconst IntlayerEditorHook: FC = () => {\n const { enabled } = useEditorEnabled();\n\n return enabled ? <IntlayerEditorHooksEnabled /> : <></>;\n};\n\nexport const IntlayerEditorProvider: FC<PropsWithChildren> = ({ children }) => {\n const configuration = getConfiguration();\n\n const { editor } = configuration;\n\n return (\n <EditorProvider\n postMessage={(data: any) => {\n if (typeof window === 'undefined') return;\n\n if (editor.applicationURL.length > 0) {\n window?.postMessage(\n data,\n // Use to restrict the origin of the editor for security reasons.\n // Correspond to the current application URL to synchronize the locales states.\n editor.applicationURL\n );\n }\n if (editor.editorURL.length > 0) {\n window.parent?.postMessage(\n data,\n // Use to restrict the origin of the editor for security reasons.\n // Correspond to the editor URL to synchronize the locales states.\n editor.editorURL\n );\n }\n\n if (editor.cmsURL.length > 0) {\n window.parent?.postMessage(\n data,\n // Use to restrict the origin of the CMS for security reasons.\n // Correspond to the CMS URL.\n editor.cmsURL\n );\n }\n }}\n allowedOrigins={[editor.editorURL, editor.cmsURL, editor.applicationURL]}\n mode=\"client\"\n configuration={configuration}\n >\n <IntlayerEditorHook />\n {children}\n </EditorProvider>\n );\n};\n"],"mappings":";AAoES,wBAeL,YAfK;AAhET,SAAS,6BAA6B;AACtC,SAAS,wBAAwB;AAOjC,OAAO,kBAAkB;AACzB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAkD;AAE3D,MAAM,6BAAiC,MAAM;AAI3C,uBAAqB,QAAW;AAAA,IAC9B,SAAS;AAAA,IACT,MAAM;AAAA,EACR,CAAC;AAKD,QAAM,EAAE,sBAAsB,IAAI,6BAA6B;AAE/D,YAAU,MAAM;AACd;AAAA,MACE;AAAA,IACF;AAAA,EACF,GAAG,CAAC,qBAAqB,CAAC;AAK1B,4BAA0B;AAK1B,QAAM,EAAE,kBAAkB,IAAI,yBAAyB;AACvD,QAAM,EAAE,OAAO,IAAI,iBAAiB;AACpC,QAAM,cAAc,IAAI,sBAAsB;AAE9C,YAAU,MAAM;AACd,QAAI,CAAC,OAAO,UAAW;AACvB,QAAI,CAAC,OAAO,SAAU;AACtB,QAAI,CAAC,OAAO,aAAc;AAE1B,gBAAY,WAAW;AAEvB,gBAAY,qBAAqB,CAAC,eAChC,kBAAkB,WAAW,KAAK,WAAW,OAAO;AAEtD,WAAO,MAAM,YAAY,QAAQ;AAAA,EACnC,GAAG,CAAC,CAAC;AAEL,SAAO,gCAAE;AACX;AAEA,MAAM,qBAAyB,MAAM;AACnC,QAAM,EAAE,QAAQ,IAAI,iBAAiB;AAErC,SAAO,UAAU,oBAAC,8BAA2B,IAAK,gCAAE;AACtD;AAEO,MAAM,yBAAgD,CAAC,EAAE,SAAS,MAAM;AAC7E,QAAM,gBAAgB,iBAAiB;AAEvC,QAAM,EAAE,OAAO,IAAI;AAEnB,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAa,CAAC,SAAc;AAC1B,YAAI,OAAO,WAAW,YAAa;AAEnC,YAAI,OAAO,eAAe,SAAS,GAAG;AACpC,kBAAQ;AAAA,YACN;AAAA;AAAA;AAAA,YAGA,OAAO;AAAA,UACT;AAAA,QACF;AACA,YAAI,OAAO,UAAU,SAAS,GAAG;AAC/B,iBAAO,QAAQ;AAAA,YACb;AAAA;AAAA;AAAA,YAGA,OAAO;AAAA,UACT;AAAA,QACF;AAEA,YAAI,OAAO,OAAO,SAAS,GAAG;AAC5B,iBAAO,QAAQ;AAAA,YACb;AAAA;AAAA;AAAA,YAGA,OAAO;AAAA,UACT;AAAA,QACF;AAAA,MACF;AAAA,MACA,gBAAgB,CAAC,OAAO,WAAW,OAAO,QAAQ,OAAO,cAAc;AAAA,MACvE,MAAK;AAAA,MACL;AAAA,MAEA;AAAA,4BAAC,sBAAmB;AAAA,QACnB;AAAA;AAAA;AAAA,EACH;AAEJ;","names":[]}
|
|
@@ -2,10 +2,11 @@ import { jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import {
|
|
3
3
|
ContentSelectorWrapper
|
|
4
4
|
} from "./ContentSelectorWrapper.mjs";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
5
|
+
import { rendererIntlayerNode } from "../IntlayerNode.mjs";
|
|
6
|
+
const renderIntlayerEditor = (props) => rendererIntlayerNode({
|
|
7
|
+
value: props.content,
|
|
8
|
+
children: /* @__PURE__ */ jsx(ContentSelectorWrapper, { ...props, children: props.content })
|
|
9
|
+
});
|
|
9
10
|
export {
|
|
10
11
|
renderIntlayerEditor
|
|
11
12
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/renderContentEditor.tsx"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/renderContentEditor.tsx"],"sourcesContent":["import {\n ContentSelectorWrapper,\n type ContentSelectorWrapperProps,\n} from './ContentSelectorWrapper';\nimport { type NodeProps } from '@intlayer/core';\nimport { IntlayerNode, rendererIntlayerNode } from '../IntlayerNode';\n\nexport type RenderIntlayerEditorProps = Omit<\n ContentSelectorWrapperProps,\n 'children' | 'content'\n> &\n NodeProps;\n\nexport const renderIntlayerEditor = (\n props: RenderIntlayerEditorProps\n): IntlayerNode =>\n rendererIntlayerNode({\n value: props.content,\n children: (\n <ContentSelectorWrapper {...props}>\n {props.content}\n </ContentSelectorWrapper>\n ),\n });\n"],"mappings":"AAmBM;AAnBN;AAAA,EACE;AAAA,OAEK;AAEP,SAAuB,4BAA4B;AAQ5C,MAAM,uBAAuB,CAClC,UAEA,qBAAqB;AAAA,EACnB,OAAO,MAAM;AAAA,EACb,UACE,oBAAC,0BAAwB,GAAG,OACzB,gBAAM,SACT;AAEJ,CAAC;","names":[]}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import { processDictionary } from "./processDictionary/index.mjs";
|
|
2
1
|
import {
|
|
3
|
-
|
|
4
|
-
} from "
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
getDictionary as getDictionaryCore
|
|
3
|
+
} from "@intlayer/core";
|
|
4
|
+
import {
|
|
5
|
+
intlayerNodePlugins,
|
|
6
|
+
markdownPlugin,
|
|
7
|
+
reactNodePlugins
|
|
8
|
+
} from "./plugins.mjs";
|
|
9
|
+
const getDictionary = (dictionary, locale, additionalPlugins) => {
|
|
10
|
+
const plugins = [
|
|
11
|
+
intlayerNodePlugins,
|
|
12
|
+
reactNodePlugins,
|
|
13
|
+
markdownPlugin,
|
|
14
|
+
...additionalPlugins ?? []
|
|
15
|
+
];
|
|
16
|
+
return getDictionaryCore(
|
|
17
|
+
dictionary,
|
|
18
|
+
locale,
|
|
19
|
+
plugins
|
|
16
20
|
);
|
|
17
21
|
};
|
|
18
22
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getDictionary.ts"],"sourcesContent":["
|
|
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 Locales | `${Locales}` = 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":"AACA;AAAA,EAGE,iBAAiB;AAAA,OACZ;AACP;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGA,MAAM,gBAAgB,CAI3B,YACA,QACA,sBACG;AACH,QAAM,UAAqB;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAI,qBAAqB,CAAC;AAAA,EAC5B;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
package/dist/esm/getIntlayer.mjs
CHANGED
|
@@ -1,24 +1,19 @@
|
|
|
1
|
-
import dictionaries from "@intlayer/dictionaries-entry";
|
|
2
|
-
import { processDictionary } from "./processDictionary/index.mjs";
|
|
3
1
|
import {
|
|
4
|
-
|
|
5
|
-
} from "
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return
|
|
19
|
-
result,
|
|
20
|
-
isRenderEditor
|
|
21
|
-
);
|
|
2
|
+
getIntlayer as getIntlayerCore
|
|
3
|
+
} from "@intlayer/core";
|
|
4
|
+
import {
|
|
5
|
+
intlayerNodePlugins,
|
|
6
|
+
markdownPlugin,
|
|
7
|
+
reactNodePlugins
|
|
8
|
+
} from "./plugins.mjs";
|
|
9
|
+
const getIntlayer = (key, locale, additionalPlugins) => {
|
|
10
|
+
const plugins = [
|
|
11
|
+
intlayerNodePlugins,
|
|
12
|
+
reactNodePlugins,
|
|
13
|
+
markdownPlugin,
|
|
14
|
+
...additionalPlugins ?? []
|
|
15
|
+
];
|
|
16
|
+
return getIntlayerCore(key, locale, plugins);
|
|
22
17
|
};
|
|
23
18
|
export {
|
|
24
19
|
getIntlayer
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getIntlayer.ts"],"sourcesContent":["
|
|
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, Locales } from 'intlayer';\n\nexport const getIntlayer = <\n T extends DictionaryKeys,\n L extends Locales | `${Locales}`,\n>(\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":"AAEA;AAAA,EAGE,eAAe;AAAA,OACV;AACP;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGA,MAAM,cAAc,CAIzB,KACA,QACA,sBACG;AACH,QAAM,UAAqB;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAI,qBAAqB,CAAC;AAAA,EAC5B;AAEA,SAAO,gBAAgB,KAAK,QAAQ,OAAO;AAG7C;","names":[]}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getTranslation } from "./getTranslation.mjs";
|
|
2
1
|
import {
|
|
3
2
|
IntlayerProvider,
|
|
4
3
|
IntlayerClientContext,
|
|
@@ -6,7 +5,6 @@ import {
|
|
|
6
5
|
useIntlayerAsync,
|
|
7
6
|
useDictionary,
|
|
8
7
|
useLocale,
|
|
9
|
-
useTraduction,
|
|
10
8
|
useLocaleCookie,
|
|
11
9
|
useIntlayerContext,
|
|
12
10
|
localeCookie,
|
|
@@ -15,15 +13,12 @@ import {
|
|
|
15
13
|
useLocaleBase,
|
|
16
14
|
t
|
|
17
15
|
} from "./client/index.mjs";
|
|
18
|
-
import {
|
|
19
|
-
import { getIntlayer } from "./getIntlayer.mjs";
|
|
16
|
+
import { MarkdownProvider } from "./markdown/index.mjs";
|
|
20
17
|
export {
|
|
21
18
|
IntlayerClientContext,
|
|
22
19
|
IntlayerProvider,
|
|
20
|
+
MarkdownProvider,
|
|
23
21
|
getBrowserLocale,
|
|
24
|
-
getDictionary,
|
|
25
|
-
getIntlayer,
|
|
26
|
-
getTranslation,
|
|
27
22
|
localeCookie,
|
|
28
23
|
setLocaleCookie,
|
|
29
24
|
t,
|
|
@@ -33,7 +28,6 @@ export {
|
|
|
33
28
|
useIntlayerContext,
|
|
34
29
|
useLocale,
|
|
35
30
|
useLocaleBase,
|
|
36
|
-
useLocaleCookie
|
|
37
|
-
useTraduction
|
|
31
|
+
useLocaleCookie
|
|
38
32
|
};
|
|
39
33
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["
|
|
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, S> {}\n}\n\nexport {\n IntlayerProvider,\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":"AAMA;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,wBAAwB;","names":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
useContext
|
|
6
|
+
} from "react";
|
|
7
|
+
const MarkdownContext = createContext({
|
|
8
|
+
renderMarkdown: (markdown) => markdown
|
|
9
|
+
});
|
|
10
|
+
const useMarkdownContext = () => useContext(MarkdownContext);
|
|
11
|
+
const MarkdownProvider = ({
|
|
12
|
+
children,
|
|
13
|
+
renderMarkdown
|
|
14
|
+
}) => /* @__PURE__ */ jsx(MarkdownContext.Provider, { value: { renderMarkdown }, children });
|
|
15
|
+
export {
|
|
16
|
+
MarkdownProvider,
|
|
17
|
+
useMarkdownContext
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=MarkdownProvider.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/markdown/MarkdownProvider.tsx"],"sourcesContent":["'use client';\n\nimport {\n createContext,\n useContext,\n type FC,\n type PropsWithChildren,\n type ReactNode,\n} from 'react';\n\ntype MarkdownContextValue = {\n renderMarkdown: (markdown: string) => ReactNode;\n};\n\ntype MarkdownProviderProps = PropsWithChildren<MarkdownContextValue>;\n\nconst MarkdownContext = createContext<MarkdownContextValue>({\n renderMarkdown: (markdown: string) => markdown,\n});\n\nexport const useMarkdownContext = () => useContext(MarkdownContext);\n\nexport const MarkdownProvider: FC<MarkdownProviderProps> = ({\n children,\n renderMarkdown,\n}) => (\n <MarkdownContext.Provider value={{ renderMarkdown }}>\n {children}\n </MarkdownContext.Provider>\n);\n"],"mappings":";AA0BE;AAxBF;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AAQP,MAAM,kBAAkB,cAAoC;AAAA,EAC1D,gBAAgB,CAAC,aAAqB;AACxC,CAAC;AAEM,MAAM,qBAAqB,MAAM,WAAW,eAAe;AAE3D,MAAM,mBAA8C,CAAC;AAAA,EAC1D;AAAA,EACA;AACF,MACE,oBAAC,gBAAgB,UAAhB,EAAyB,OAAO,EAAE,eAAe,GAC/C,UACH;","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMarkdownContext } from "./MarkdownProvider.mjs";
|
|
3
|
+
import { rendererIntlayerNode } from "../IntlayerNode.mjs";
|
|
4
|
+
const MarkdownRenderer = ({
|
|
5
|
+
markdown
|
|
6
|
+
}) => {
|
|
7
|
+
const { renderMarkdown } = useMarkdownContext();
|
|
8
|
+
return rendererIntlayerNode({
|
|
9
|
+
value: markdown,
|
|
10
|
+
children: renderMarkdown(markdown)
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
MarkdownRenderer
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=MarkdownRenderer.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/markdown/MarkdownRenderer.tsx"],"sourcesContent":["'use client';\n\nimport { FC } from 'react';\nimport { useMarkdownContext } from './MarkdownProvider';\nimport { IntlayerNode, rendererIntlayerNode } from '../IntlayerNode';\n\nexport const MarkdownRenderer: FC<{ markdown: string }> = ({\n markdown,\n}): IntlayerNode => {\n const { renderMarkdown } = useMarkdownContext();\n\n return rendererIntlayerNode({\n value: markdown,\n children: renderMarkdown(markdown),\n });\n};\n"],"mappings":";AAGA,SAAS,0BAA0B;AACnC,SAAuB,4BAA4B;AAE5C,MAAM,mBAA6C,CAAC;AAAA,EACzD;AACF,MAAoB;AAClB,QAAM,EAAE,eAAe,IAAI,mBAAmB;AAE9C,SAAO,qBAAqB;AAAA,IAC1B,OAAO;AAAA,IACP,UAAU,eAAe,QAAQ;AAAA,EACnC,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/markdown/index.ts"],"sourcesContent":["export * from './MarkdownProvider';\nexport * from './MarkdownRenderer';\nexport * from './renderMarkdown';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { rendererIntlayerNode } from "../IntlayerNode.mjs";
|
|
3
|
+
import { MarkdownRenderer } from "./MarkdownRenderer.mjs";
|
|
4
|
+
const renderMarkdown = (markdown) => rendererIntlayerNode({
|
|
5
|
+
value: markdown,
|
|
6
|
+
children: /* @__PURE__ */ jsx(MarkdownRenderer, { markdown })
|
|
7
|
+
});
|
|
8
|
+
export {
|
|
9
|
+
renderMarkdown
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=renderMarkdown.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/markdown/renderMarkdown.tsx"],"sourcesContent":["import { type IntlayerNode, rendererIntlayerNode } from '../IntlayerNode';\nimport { MarkdownRenderer } from './MarkdownRenderer';\n\nexport const renderMarkdown = (markdown: string): IntlayerNode =>\n rendererIntlayerNode({\n value: markdown,\n children: <MarkdownRenderer markdown={markdown} />,\n });\n"],"mappings":"AAMc;AANd,SAA4B,4BAA4B;AACxD,SAAS,wBAAwB;AAE1B,MAAM,iBAAiB,CAAC,aAC7B,qBAAqB;AAAA,EACnB,OAAO;AAAA,EACP,UAAU,oBAAC,oBAAiB,UAAoB;AAClD,CAAC;","names":[]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NodeType
|
|
3
|
+
} from "@intlayer/core";
|
|
4
|
+
import { createElement } from "react";
|
|
5
|
+
import { renderIntlayerEditor } from "./editor/index.mjs";
|
|
6
|
+
import { renderMarkdown } from "./markdown/renderMarkdown.mjs";
|
|
7
|
+
const intlayerNodePlugins = {
|
|
8
|
+
canHandle: (node) => typeof node === "bigint" || typeof node === "string" || typeof node === "number",
|
|
9
|
+
transform: (_node, {
|
|
10
|
+
plugins,
|
|
11
|
+
// Removed to avoid next error - Functions cannot be passed directly to Client Components
|
|
12
|
+
...rest
|
|
13
|
+
}) => renderIntlayerEditor(rest)
|
|
14
|
+
};
|
|
15
|
+
const createReactElement = (element) => {
|
|
16
|
+
if (typeof element === "string") {
|
|
17
|
+
return element;
|
|
18
|
+
}
|
|
19
|
+
const convertChildrenAsArray = (element2) => {
|
|
20
|
+
if (element2?.props && typeof element2.props.children === "object") {
|
|
21
|
+
const childrenResult = [];
|
|
22
|
+
const { children } = element2.props;
|
|
23
|
+
Object.keys(children ?? {}).forEach((key) => {
|
|
24
|
+
childrenResult.push(
|
|
25
|
+
createReactElement((children ?? {})[key])
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
...element2,
|
|
30
|
+
props: { ...element2.props, children: childrenResult }
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
...element2,
|
|
35
|
+
props: { ...element2.props, children: element2.props.children }
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
const fixedElement = convertChildrenAsArray(
|
|
39
|
+
element
|
|
40
|
+
);
|
|
41
|
+
const { type, props } = fixedElement;
|
|
42
|
+
return createElement(
|
|
43
|
+
type ?? "div",
|
|
44
|
+
props,
|
|
45
|
+
...props.children
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
const reactNodePlugins = {
|
|
49
|
+
canHandle: (node) => typeof node === "object" && typeof node.ref !== "undefined" && typeof node.props !== "undefined" && typeof node.key !== "undefined",
|
|
50
|
+
transform: createReactElement
|
|
51
|
+
};
|
|
52
|
+
const markdownPlugin = {
|
|
53
|
+
canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.Markdown,
|
|
54
|
+
transform: (node) => renderMarkdown(node[NodeType.Markdown])
|
|
55
|
+
};
|
|
56
|
+
export {
|
|
57
|
+
intlayerNodePlugins,
|
|
58
|
+
markdownPlugin,
|
|
59
|
+
reactNodePlugins
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=plugins.mjs.map
|
|
@@ -0,0 +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 { type ReactElement, type ReactNode, createElement } from 'react';\nimport { renderIntlayerEditor } from './editor';\nimport type { IntlayerNode } from './IntlayerNode';\nimport { renderMarkdown } from './markdown/renderMarkdown';\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T, _S> = 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, _S> = T extends {\n ref: any;\n props: any;\n key: any;\n}\n ? ReactNode\n : never;\n\n// This function recursively creates React elements from a given JSON-like structure\nconst createReactElement = (element: ReactElement) => {\n if (typeof element === 'string') {\n // If it's a string, simply return it (used for text content)\n return element;\n }\n\n const convertChildrenAsArray = (\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 createReactElement((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\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: createReactElement,\n};\n\n/**\n * MARKDOWN PLUGIN\n */\n\nexport type MarkdownCond<T, _S> = 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, _S> {\n reactNode: ReactNodeCond<T, _S>;\n intlayerNode: IntlayerNodeCond<T, _S>;\n markdown: MarkdownCond<T, _S>;\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":"AACA;AAAA,EAKE;AAAA,OACK;AACP,SAA4C,qBAAqB;AACjE,SAAS,4BAA4B;AAErC,SAAS,sBAAsB;AAWxB,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,MACG,qBAAqB,IAAI;AAChC;AAeA,MAAM,qBAAqB,CAAC,YAA0B;AACpD,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,SAAO;AAAA,IACL,QAAQ;AAAA,IACR;AAAA,IACA,GAAI,MAAM;AAAA,EACZ;AACF;AAGO,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,SAAS;AAAA,EAC1D,WAAW,CAAC,SAA0B,eAAe,KAAK,SAAS,QAAQ,CAAC;AAC9E;","names":["element"]}
|