preact-intlayer 9.8.4 → 9.9.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 +1 -0
- package/dist/cjs/client/useDictionaryAsync.cjs +6 -5
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +11 -21
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useLoadDynamic.cjs +9 -21
- package/dist/cjs/client/useLoadDynamic.cjs.map +1 -1
- package/dist/cjs/editor/useEditedContentSource.cjs +31 -0
- package/dist/cjs/editor/useEditedContentSource.cjs.map +1 -0
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs +3 -1
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +7 -6
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +13 -23
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useLoadDynamic.mjs +9 -21
- package/dist/esm/client/useLoadDynamic.mjs.map +1 -1
- package/dist/esm/editor/useEditedContentSource.mjs +30 -0
- package/dist/esm/editor/useEditedContentSource.mjs.map +1 -0
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs +3 -1
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs.map +1 -1
- package/dist/types/client/useDictionaryAsync.d.ts +1 -1
- package/dist/types/client/useDictionaryAsync.d.ts.map +1 -1
- package/dist/types/client/useDictionaryDynamic.d.ts +3 -4
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/client/useLoadDynamic.d.ts +4 -0
- package/dist/types/client/useLoadDynamic.d.ts.map +1 -1
- package/dist/types/editor/useEditedContentSource.d.ts +7 -0
- package/dist/types/editor/useEditedContentSource.d.ts.map +1 -0
- package/dist/types/markdown/MarkdownRendererPlugin.d.ts.map +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -190,6 +190,7 @@ Explore our comprehensive documentation to get started with Intlayer and learn h
|
|
|
190
190
|
<li><a href="https://intlayer.org/doc/environment/vite-and-react" rel=''>Vite + React using Compiler</a></li>
|
|
191
191
|
<li><a href="https://intlayer.org/doc/environment/vite-and-react/react-router-v7" rel=''>React-router-v7</a></li>
|
|
192
192
|
<li><a href="https://intlayer.org/doc/environment/remix-3" rel=''>Remix 3</a></li>
|
|
193
|
+
<li><a href="https://intlayer.org/doc/environment/vinext" rel=''>vinext (Next.js on Vite)</a></li>
|
|
193
194
|
<li><a href="https://intlayer.org/doc/environment/tanstack-start" rel=''>Tanstack start</a>
|
|
194
195
|
<ul>
|
|
195
196
|
<li><a href="https://intlayer.org/doc/environment/tanstack-start/solid" rel=''>Solid</a></li>
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_getDictionary = require("../getDictionary.cjs");
|
|
2
3
|
const require_client_IntlayerProvider = require("./IntlayerProvider.cjs");
|
|
3
|
-
const require_client_useDictionary = require("./useDictionary.cjs");
|
|
4
4
|
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
5
5
|
let preact_hooks = require("preact/hooks");
|
|
6
|
+
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
6
7
|
|
|
7
8
|
// src/client/useDictionaryAsync.ts
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
+
* Hook that loads the locale chunk of a dictionary and returns its content.
|
|
10
11
|
*
|
|
11
12
|
* If the locale is not provided, it will use the locale from the client context
|
|
12
13
|
*/
|
|
13
14
|
const useDictionaryAsync = async (dictionaryPromise, locale) => {
|
|
14
15
|
const { locale: currentLocale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {};
|
|
15
|
-
const localeTarget =
|
|
16
|
-
const dictionary = await (0,
|
|
17
|
-
return
|
|
16
|
+
const localeTarget = locale ?? currentLocale ?? (0, _intlayer_core_interpreter.resolveInterpreterLocale)();
|
|
17
|
+
const dictionary = await (0, _intlayer_core_dictionaryManipulator.loadDynamicDictionary)(dictionaryPromise, localeTarget);
|
|
18
|
+
return require_getDictionary.getDictionary(dictionary, localeTarget);
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
exports.useDictionaryAsync = useDictionaryAsync;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryAsync.cjs","names":["useContext","IntlayerClientContext","
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.cjs","names":["useContext","IntlayerClientContext","resolveInterpreterLocale","loadDynamicDictionary","getDictionary"],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["import { loadDynamicDictionary } from '@intlayer/core/dictionaryManipulator';\nimport { resolveInterpreterLocale } from '@intlayer/core/interpreter';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext } from 'preact/hooks';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Hook that loads the locale chunk of a dictionary and returns its content.\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryAsync = async <const T extends Dictionary>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: LocalesValues\n): Promise<T> => {\n // Read before the first `await`: a hook only runs synchronously in render\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n const localeTarget = locale ?? currentLocale ?? resolveInterpreterLocale();\n\n const dictionary = (await loadDynamicDictionary(\n dictionaryPromise,\n localeTarget\n )) as T;\n\n return getDictionary(dictionary, localeTarget) as any;\n};\n"],"mappings":";;;;;;;;;;;;;AAgBA,MAAa,qBAAqB,OAChC,mBACA,WACe;CAEf,MAAM,EAAE,QAAQ,sBAAkBA,yBAAWC,qDAAqB,KAAK,CAAC;CACxE,MAAM,eAAe,UAAU,qBAAiBC,qDAAyB;CAEzE,MAAM,aAAc,UAAMC,4DACxB,mBACA,YACF;CAEA,OAAOC,oCAAc,YAAY,YAAY;AAC/C"}
|
|
@@ -2,7 +2,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_getDictionary = require("../getDictionary.cjs");
|
|
3
3
|
const require_client_IntlayerProvider = require("./IntlayerProvider.cjs");
|
|
4
4
|
const require_client_useLoadDynamic = require("./useLoadDynamic.cjs");
|
|
5
|
-
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
6
5
|
let preact_hooks = require("preact/hooks");
|
|
7
6
|
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
8
7
|
|
|
@@ -10,39 +9,30 @@ let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryMan
|
|
|
10
9
|
/**
|
|
11
10
|
* Preact hook that lazily loads a dictionary and returns its content.
|
|
12
11
|
*
|
|
13
|
-
* The
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* the selector targets are loaded.
|
|
12
|
+
* The locale, selector, chunk selection and transform are resolved by the
|
|
13
|
+
* shared `resolveDictionaryRead` / `resolveDynamicContent`, so this hook only
|
|
14
|
+
* contributes the provider context and the Suspense cache.
|
|
17
15
|
*
|
|
18
16
|
* If the locale is not provided (directly or through the selector), the client
|
|
19
17
|
* context locale is used.
|
|
20
18
|
*/
|
|
21
19
|
const useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector) => {
|
|
22
20
|
const { locale: currentLocale, variant: contextVariant } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {};
|
|
23
|
-
const
|
|
21
|
+
const dictionaryKey = String(key);
|
|
22
|
+
const { locale, selector } = (0, _intlayer_core_dictionaryManipulator.resolveDictionaryRead)({
|
|
24
23
|
localeOrSelector,
|
|
25
24
|
contextLocale: currentLocale,
|
|
26
25
|
contextVariant,
|
|
27
|
-
dictionaryKey
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
selector: void 0
|
|
31
|
-
};
|
|
32
|
-
const localeTarget = selectorLocale ?? currentLocale ?? (0, _intlayer_core_interpreter.resolveInterpreterLocale)();
|
|
33
|
-
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && (0, _intlayer_core_dictionaryManipulator.isQualifiedDynamicLoaderMap)(dictionaryPromise)) return (0, _intlayer_core_dictionaryManipulator.resolveQualifiedDynamicContent)({
|
|
26
|
+
dictionaryKey
|
|
27
|
+
});
|
|
28
|
+
return (0, _intlayer_core_dictionaryManipulator.resolveDynamicContent)({
|
|
34
29
|
loaderMap: dictionaryPromise,
|
|
35
|
-
key:
|
|
36
|
-
locale
|
|
30
|
+
key: dictionaryKey,
|
|
31
|
+
locale,
|
|
37
32
|
selector,
|
|
38
33
|
loadChunk: (cacheKey, promise) => require_client_useLoadDynamic.useLoadDynamic(cacheKey, promise),
|
|
39
|
-
transform: (dictionary) => require_getDictionary.getDictionary(dictionary,
|
|
34
|
+
transform: (dictionary, argument) => require_getDictionary.getDictionary(dictionary, argument)
|
|
40
35
|
});
|
|
41
|
-
const preloadedDictionary = (0, _intlayer_core_dictionaryManipulator.getPreloadedDictionary)(dictionaryPromise, localeTarget);
|
|
42
|
-
if (preloadedDictionary) return require_getDictionary.getDictionary(preloadedDictionary, localeTarget);
|
|
43
|
-
const plainLoaders = dictionaryPromise;
|
|
44
|
-
const dictionary = require_client_useLoadDynamic.useLoadDynamic(`${String(key)}.${localeTarget}`, plainLoaders[localeTarget]?.());
|
|
45
|
-
return require_getDictionary.getDictionary(dictionary, localeTarget);
|
|
46
36
|
};
|
|
47
37
|
|
|
48
38
|
exports.useDictionaryDynamic = useDictionaryDynamic;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.cjs","names":["useContext","IntlayerClientContext","
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.cjs","names":["useContext","IntlayerClientContext","resolveDictionaryRead","resolveDynamicContent","loadDynamicChunk","getDictionary"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["import {\n type DynamicLoaderMap,\n type QualifiedDynamicLoaderMap,\n resolveDictionaryRead,\n resolveDynamicContent,\n} from '@intlayer/core/dictionaryManipulator';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext } from 'preact/hooks';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n// `useLoadDynamic` is a suspender cache, not a hook — aliased to a non-hook\n// name so it can be invoked in loops / conditionally (collection chunks).\nimport { useLoadDynamic as loadDynamicChunk } from './useLoadDynamic';\n\n/**\n * Preact hook that lazily loads a dictionary and returns its content.\n *\n * The locale, selector, chunk selection and transform are resolved by the\n * shared `resolveDictionaryRead` / `resolveDynamicContent`, so this hook only\n * contributes the provider context and the Suspense cache.\n *\n * If the locale is not provided (directly or through the selector), the client\n * context locale is used.\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const K extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<K> = DeclaredLocales,\n>(\n dictionaryPromise:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: K,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale, variant: contextVariant } =\n useContext(IntlayerClientContext) ?? {};\n\n const dictionaryKey = String(key);\n\n const { locale, selector } = resolveDictionaryRead({\n localeOrSelector,\n contextLocale: currentLocale,\n contextVariant,\n dictionaryKey,\n });\n\n return resolveDynamicContent({\n loaderMap: dictionaryPromise as DynamicLoaderMap,\n key: dictionaryKey,\n locale,\n selector,\n loadChunk: (cacheKey, promise) => loadDynamicChunk(cacheKey, promise),\n transform: (dictionary, argument) => getDictionary(dictionary, argument),\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AA+BA,MAAa,wBAKX,mBAGA,KACA,qBACG;CACH,MAAM,EAAE,QAAQ,eAAe,SAAS,uBACtCA,yBAAWC,qDAAqB,KAAK,CAAC;CAExC,MAAM,gBAAgB,OAAO,GAAG;CAEhC,MAAM,EAAE,QAAQ,iBAAaC,4DAAsB;EACjD;EACA,eAAe;EACf;EACA;CACF,CAAC;CAED,WAAOC,4DAAsB;EAC3B,WAAW;EACX,KAAK;EACL;EACA;EACA,YAAY,UAAU,YAAYC,6CAAiB,UAAU,OAAO;EACpE,YAAY,YAAY,aAAaC,oCAAc,YAAY,QAAQ;CACzE,CAAC;AACH"}
|
|
@@ -1,26 +1,14 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
3
|
+
|
|
2
4
|
// src/client/useLoadDynamic.ts
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
status = "error";
|
|
11
|
-
result = e;
|
|
12
|
-
});
|
|
13
|
-
return { read() {
|
|
14
|
-
if (status === "pending") throw suspender;
|
|
15
|
-
if (status === "error") throw result;
|
|
16
|
-
return result;
|
|
17
|
-
} };
|
|
18
|
-
};
|
|
19
|
-
const cache = /* @__PURE__ */ new Map();
|
|
20
|
-
const useLoadDynamic = (key, promise) => {
|
|
21
|
-
if (!cache.has(key)) cache.set(key, createSuspender(promise));
|
|
22
|
-
return cache.get(key).read();
|
|
23
|
-
};
|
|
5
|
+
/** Chunk cache read by every dynamic dictionary of the page. */
|
|
6
|
+
const chunkCache = (0, _intlayer_core_dictionaryManipulator.createChunkSuspenseCache)();
|
|
7
|
+
/**
|
|
8
|
+
* Reads a chunk the Suspense way: throws while `promise` is pending, then
|
|
9
|
+
* returns its value. Only the first `promise` given for a `key` is used.
|
|
10
|
+
*/
|
|
11
|
+
const useLoadDynamic = (key, promise) => chunkCache.read(key, promise);
|
|
24
12
|
|
|
25
13
|
exports.useLoadDynamic = useLoadDynamic;
|
|
26
14
|
//# sourceMappingURL=useLoadDynamic.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLoadDynamic.cjs","names":[],"sources":["../../../src/client/useLoadDynamic.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"useLoadDynamic.cjs","names":["createChunkSuspenseCache"],"sources":["../../../src/client/useLoadDynamic.ts"],"sourcesContent":["import { createChunkSuspenseCache } from '@intlayer/core/dictionaryManipulator';\n\n/** Chunk cache read by every dynamic dictionary of the page. */\nconst chunkCache = createChunkSuspenseCache();\n\n/**\n * Reads a chunk the Suspense way: throws while `promise` is pending, then\n * returns its value. Only the first `promise` given for a `key` is used.\n */\nexport const useLoadDynamic = <T>(key: string, promise: Promise<T>): T =>\n chunkCache.read(key, promise);\n"],"mappings":";;;;;AAGA,MAAM,iBAAaA,+DAAyB;;;;;AAM5C,MAAa,kBAAqB,KAAa,YAC7C,WAAW,KAAK,KAAK,OAAO"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _intlayer_editor_isEnabled = require("@intlayer/editor/isEnabled");
|
|
3
|
+
let preact_hooks = require("preact/hooks");
|
|
4
|
+
|
|
5
|
+
// src/editor/useEditedContentSource.ts
|
|
6
|
+
/**
|
|
7
|
+
* Returns the source string edited in the visual editor for a markdown / html
|
|
8
|
+
* node, or `undefined` when the node is not edited (or the editor is off).
|
|
9
|
+
*/
|
|
10
|
+
const useEditedContentSource = (dictionaryKey, keyPath) => {
|
|
11
|
+
const [editedSource, setEditedSource] = (0, preact_hooks.useState)();
|
|
12
|
+
const keyPathJson = JSON.stringify(keyPath ?? []);
|
|
13
|
+
(0, preact_hooks.useEffect)(() => {
|
|
14
|
+
if (process.env.INTLAYER_EDITOR_ENABLED === "false" || !_intlayer_editor_isEnabled.isEnabled) return;
|
|
15
|
+
if (!dictionaryKey) return;
|
|
16
|
+
let isStopped = false;
|
|
17
|
+
let unsubscribe = null;
|
|
18
|
+
import("@intlayer/editor").then(({ subscribeToEditedContentSource }) => {
|
|
19
|
+
if (isStopped) return;
|
|
20
|
+
unsubscribe = subscribeToEditedContentSource(dictionaryKey, JSON.parse(keyPathJson), setEditedSource);
|
|
21
|
+
}).catch(() => {});
|
|
22
|
+
return () => {
|
|
23
|
+
isStopped = true;
|
|
24
|
+
unsubscribe?.();
|
|
25
|
+
};
|
|
26
|
+
}, [dictionaryKey, keyPathJson]);
|
|
27
|
+
return editedSource;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
exports.useEditedContentSource = useEditedContentSource;
|
|
31
|
+
//# sourceMappingURL=useEditedContentSource.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEditedContentSource.cjs","names":["useState","isEnabled"],"sources":["../../../src/editor/useEditedContentSource.ts"],"sourcesContent":["import { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport { useEffect, useState } from 'preact/hooks';\n\n/**\n * Returns the source string edited in the visual editor for a markdown / html\n * node, or `undefined` when the node is not edited (or the editor is off).\n */\nexport const useEditedContentSource = (\n dictionaryKey: string | undefined,\n keyPath: KeyPath[] | undefined\n): string | undefined => {\n const [editedSource, setEditedSource] = useState<string | undefined>();\n const keyPathJson = JSON.stringify(keyPath ?? []);\n\n useEffect(() => {\n if (process.env.INTLAYER_EDITOR_ENABLED === 'false' || !isEnabled) return;\n if (!dictionaryKey) return;\n\n let isStopped = false;\n let unsubscribe: (() => void) | null = null;\n\n import('@intlayer/editor')\n .then(({ subscribeToEditedContentSource }) => {\n if (isStopped) return;\n\n unsubscribe = subscribeToEditedContentSource(\n dictionaryKey,\n JSON.parse(keyPathJson) as KeyPath[],\n setEditedSource\n );\n })\n .catch(() => {});\n\n return () => {\n isStopped = true;\n unsubscribe?.();\n };\n }, [dictionaryKey, keyPathJson]);\n\n return editedSource;\n};\n"],"mappings":";;;;;;;;;AAQA,MAAa,0BACX,eACA,YACuB;CACvB,MAAM,CAAC,cAAc,uBAAmBA,uBAA6B;CACrE,MAAM,cAAc,KAAK,UAAU,WAAW,CAAC,CAAC;CAEhD,kCAAgB;EACd,IAAI,QAAQ,IAAI,4BAA4B,WAAW,CAACC,sCAAW;EACnE,IAAI,CAAC,eAAe;EAEpB,IAAI,YAAY;EAChB,IAAI,cAAmC;EAEvC,OAAO,mBAAmB,CACvB,MAAM,EAAE,qCAAqC;GAC5C,IAAI,WAAW;GAEf,cAAc,+BACZ,eACA,KAAK,MAAM,WAAW,GACtB,eACF;EACF,CAAC,CAAC,CACD,YAAY,CAAC,CAAC;EAEjB,aAAa;GACX,YAAY;GACZ,cAAc;EAChB;CACF,GAAG,CAAC,eAAe,WAAW,CAAC;CAE/B,OAAO;AACT"}
|
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
const require_client_useLocale = require("../client/useLocale.cjs");
|
|
5
|
+
const require_editor_useEditedContentSource = require("../editor/useEditedContentSource.cjs");
|
|
5
6
|
const require_markdown_MarkdownProvider = require("./MarkdownProvider.cjs");
|
|
6
7
|
let _intlayer_core_markdown = require("@intlayer/core/markdown");
|
|
7
8
|
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
8
9
|
|
|
9
10
|
// src/markdown/MarkdownRendererPlugin.tsx
|
|
10
11
|
const MarkdownRendererPlugin = (props) => {
|
|
11
|
-
const {
|
|
12
|
+
const { dictionaryKey, keyPath, options, components } = props;
|
|
12
13
|
const context = require_markdown_MarkdownProvider.useMarkdownContext();
|
|
14
|
+
const children = require_editor_useEditedContentSource.useEditedContentSource(dictionaryKey, keyPath) ?? props.children;
|
|
13
15
|
return (context?.renderMarkdown ?? ((md) => md))(children, options, {
|
|
14
16
|
...context?.components ?? {},
|
|
15
17
|
...components ?? {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownRendererPlugin.cjs","names":["useMarkdownContext","useLocale","getMarkdownMetadata","getContentNodeByKeyPath"],"sources":["../../../src/markdown/MarkdownRendererPlugin.tsx"],"sourcesContent":["'use client';\n\nimport { getContentNodeByKeyPath } from '@intlayer/core/dictionaryManipulator';\nimport { getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { ComponentChildren, FunctionComponent } from 'preact';\nimport { useLocale } from '../client/useLocale';\nimport type { HTMLComponents } from '../html/types';\nimport {\n type MarkdownProviderOptions,\n useMarkdownContext,\n} from './MarkdownProvider';\n\ntype MarkdownRendererPluginProps = {\n dictionaryKey: string;\n keyPath: KeyPath[];\n locale?: LocalesValues;\n children: string;\n options?: MarkdownProviderOptions;\n components?: HTMLComponents<'permissive', {}>;\n};\n\nexport const MarkdownRendererPlugin: FunctionComponent<\n MarkdownRendererPluginProps\n> = (props): ComponentChildren => {\n const {
|
|
1
|
+
{"version":3,"file":"MarkdownRendererPlugin.cjs","names":["useMarkdownContext","useEditedContentSource","useLocale","getMarkdownMetadata","getContentNodeByKeyPath"],"sources":["../../../src/markdown/MarkdownRendererPlugin.tsx"],"sourcesContent":["'use client';\n\nimport { getContentNodeByKeyPath } from '@intlayer/core/dictionaryManipulator';\nimport { getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { ComponentChildren, FunctionComponent } from 'preact';\nimport { useLocale } from '../client/useLocale';\nimport { useEditedContentSource } from '../editor/useEditedContentSource';\nimport type { HTMLComponents } from '../html/types';\nimport {\n type MarkdownProviderOptions,\n useMarkdownContext,\n} from './MarkdownProvider';\n\ntype MarkdownRendererPluginProps = {\n dictionaryKey: string;\n keyPath: KeyPath[];\n locale?: LocalesValues;\n children: string;\n options?: MarkdownProviderOptions;\n components?: HTMLComponents<'permissive', {}>;\n};\n\nexport const MarkdownRendererPlugin: FunctionComponent<\n MarkdownRendererPluginProps\n> = (props): ComponentChildren => {\n const { dictionaryKey, keyPath, options, components } = props;\n const context = useMarkdownContext();\n // Live preview of the source edited in the visual editor\n const editedSource = useEditedContentSource(dictionaryKey, keyPath);\n const children = editedSource ?? props.children;\n const renderMarkdown = context?.renderMarkdown ?? ((md) => md);\n\n return renderMarkdown(children, options, {\n ...(context?.components ?? {}),\n ...(components ?? {}),\n }) as ComponentChildren;\n};\n\ntype MarkdownMetadataRendererProps = MarkdownRendererPluginProps & {\n metadataKeyPath: KeyPath[];\n};\n\nexport const MarkdownMetadataRenderer: FunctionComponent<\n MarkdownMetadataRendererProps\n> = ({ children, metadataKeyPath }): ComponentChildren => {\n const { locale: currentLocale } = useLocale();\n\n const metadata = getMarkdownMetadata(children);\n\n const metadataEl = getContentNodeByKeyPath(\n metadata as ContentNode,\n metadataKeyPath,\n currentLocale as any\n );\n\n return metadataEl as ComponentChildren;\n};\n"],"mappings":";;;;;;;;;;AAyBA,MAAa,0BAER,UAA6B;CAChC,MAAM,EAAE,eAAe,SAAS,SAAS,eAAe;CACxD,MAAM,UAAUA,qDAAmB;CAGnC,MAAM,WADeC,6DAAuB,eAAe,OAC/B,KAAK,MAAM;CAGvC,QAFuB,SAAS,oBAAoB,OAAO,IAEtC,CAAC,UAAU,SAAS;EACvC,GAAI,SAAS,cAAc,CAAC;EAC5B,GAAI,cAAc,CAAC;CACrB,CAAC;AACH;AAMA,MAAa,4BAER,EAAE,UAAU,sBAAyC;CACxD,MAAM,EAAE,QAAQ,kBAAkBC,mCAAU;CAE5C,MAAM,eAAWC,6CAAoB,QAAQ;CAQ7C,WANmBC,8DACjB,UACA,iBACA,aAGc;AAClB"}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
+
import { getDictionary as getDictionary$1 } from "../getDictionary.mjs";
|
|
1
2
|
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
2
|
-
import { useDictionary } from "./useDictionary.mjs";
|
|
3
3
|
import { resolveInterpreterLocale } from "@intlayer/core/interpreter";
|
|
4
|
-
import { useContext
|
|
4
|
+
import { useContext } from "preact/hooks";
|
|
5
|
+
import { loadDynamicDictionary } from "@intlayer/core/dictionaryManipulator";
|
|
5
6
|
|
|
6
7
|
// src/client/useDictionaryAsync.ts
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
+
* Hook that loads the locale chunk of a dictionary and returns its content.
|
|
9
10
|
*
|
|
10
11
|
* If the locale is not provided, it will use the locale from the client context
|
|
11
12
|
*/
|
|
12
13
|
const useDictionaryAsync = async (dictionaryPromise, locale) => {
|
|
13
14
|
const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};
|
|
14
|
-
const localeTarget =
|
|
15
|
-
const dictionary = await
|
|
16
|
-
return
|
|
15
|
+
const localeTarget = locale ?? currentLocale ?? resolveInterpreterLocale();
|
|
16
|
+
const dictionary = await loadDynamicDictionary(dictionaryPromise, localeTarget);
|
|
17
|
+
return getDictionary$1(dictionary, localeTarget);
|
|
17
18
|
};
|
|
18
19
|
|
|
19
20
|
export { useDictionaryAsync };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryAsync.mjs","names":[],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["import { resolveInterpreterLocale } from '@intlayer/core/interpreter';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.mjs","names":["getDictionary"],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["import { loadDynamicDictionary } from '@intlayer/core/dictionaryManipulator';\nimport { resolveInterpreterLocale } from '@intlayer/core/interpreter';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext } from 'preact/hooks';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Hook that loads the locale chunk of a dictionary and returns its content.\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryAsync = async <const T extends Dictionary>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: LocalesValues\n): Promise<T> => {\n // Read before the first `await`: a hook only runs synchronously in render\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n const localeTarget = locale ?? currentLocale ?? resolveInterpreterLocale();\n\n const dictionary = (await loadDynamicDictionary(\n dictionaryPromise,\n localeTarget\n )) as T;\n\n return getDictionary(dictionary, localeTarget) as any;\n};\n"],"mappings":";;;;;;;;;;;;AAgBA,MAAa,qBAAqB,OAChC,mBACA,WACe;CAEf,MAAM,EAAE,QAAQ,kBAAkB,WAAW,qBAAqB,KAAK,CAAC;CACxE,MAAM,eAAe,UAAU,iBAAiB,yBAAyB;CAEzE,MAAM,aAAc,MAAM,sBACxB,mBACA,YACF;CAEA,OAAOA,gBAAc,YAAY,YAAY;AAC/C"}
|
|
@@ -1,47 +1,37 @@
|
|
|
1
|
-
import { getDictionary
|
|
1
|
+
import { getDictionary } from "../getDictionary.mjs";
|
|
2
2
|
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
3
3
|
import { useLoadDynamic } from "./useLoadDynamic.mjs";
|
|
4
|
-
import { resolveInterpreterLocale } from "@intlayer/core/interpreter";
|
|
5
4
|
import { useContext } from "preact/hooks";
|
|
6
|
-
import {
|
|
5
|
+
import { resolveDictionaryRead, resolveDynamicContent } from "@intlayer/core/dictionaryManipulator";
|
|
7
6
|
|
|
8
7
|
// src/client/useDictionaryDynamic.ts
|
|
9
8
|
/**
|
|
10
9
|
* Preact hook that lazily loads a dictionary and returns its content.
|
|
11
10
|
*
|
|
12
|
-
* The
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* the selector targets are loaded.
|
|
11
|
+
* The locale, selector, chunk selection and transform are resolved by the
|
|
12
|
+
* shared `resolveDictionaryRead` / `resolveDynamicContent`, so this hook only
|
|
13
|
+
* contributes the provider context and the Suspense cache.
|
|
16
14
|
*
|
|
17
15
|
* If the locale is not provided (directly or through the selector), the client
|
|
18
16
|
* context locale is used.
|
|
19
17
|
*/
|
|
20
18
|
const useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector) => {
|
|
21
19
|
const { locale: currentLocale, variant: contextVariant } = useContext(IntlayerClientContext) ?? {};
|
|
22
|
-
const
|
|
20
|
+
const dictionaryKey = String(key);
|
|
21
|
+
const { locale, selector } = resolveDictionaryRead({
|
|
23
22
|
localeOrSelector,
|
|
24
23
|
contextLocale: currentLocale,
|
|
25
24
|
contextVariant,
|
|
26
|
-
dictionaryKey
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
selector: void 0
|
|
30
|
-
};
|
|
31
|
-
const localeTarget = selectorLocale ?? currentLocale ?? resolveInterpreterLocale();
|
|
32
|
-
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && isQualifiedDynamicLoaderMap(dictionaryPromise)) return resolveQualifiedDynamicContent({
|
|
25
|
+
dictionaryKey
|
|
26
|
+
});
|
|
27
|
+
return resolveDynamicContent({
|
|
33
28
|
loaderMap: dictionaryPromise,
|
|
34
|
-
key:
|
|
35
|
-
locale
|
|
29
|
+
key: dictionaryKey,
|
|
30
|
+
locale,
|
|
36
31
|
selector,
|
|
37
32
|
loadChunk: (cacheKey, promise) => useLoadDynamic(cacheKey, promise),
|
|
38
|
-
transform: (dictionary) => getDictionary
|
|
33
|
+
transform: (dictionary, argument) => getDictionary(dictionary, argument)
|
|
39
34
|
});
|
|
40
|
-
const preloadedDictionary = getPreloadedDictionary(dictionaryPromise, localeTarget);
|
|
41
|
-
if (preloadedDictionary) return getDictionary$1(preloadedDictionary, localeTarget);
|
|
42
|
-
const plainLoaders = dictionaryPromise;
|
|
43
|
-
const dictionary = useLoadDynamic(`${String(key)}.${localeTarget}`, plainLoaders[localeTarget]?.());
|
|
44
|
-
return getDictionary$1(dictionary, localeTarget);
|
|
45
35
|
};
|
|
46
36
|
|
|
47
37
|
export { useDictionaryDynamic };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.mjs","names":["loadDynamicChunk"
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.mjs","names":["loadDynamicChunk"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["import {\n type DynamicLoaderMap,\n type QualifiedDynamicLoaderMap,\n resolveDictionaryRead,\n resolveDynamicContent,\n} from '@intlayer/core/dictionaryManipulator';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext } from 'preact/hooks';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n// `useLoadDynamic` is a suspender cache, not a hook — aliased to a non-hook\n// name so it can be invoked in loops / conditionally (collection chunks).\nimport { useLoadDynamic as loadDynamicChunk } from './useLoadDynamic';\n\n/**\n * Preact hook that lazily loads a dictionary and returns its content.\n *\n * The locale, selector, chunk selection and transform are resolved by the\n * shared `resolveDictionaryRead` / `resolveDynamicContent`, so this hook only\n * contributes the provider context and the Suspense cache.\n *\n * If the locale is not provided (directly or through the selector), the client\n * context locale is used.\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const K extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<K> = DeclaredLocales,\n>(\n dictionaryPromise:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: K,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale, variant: contextVariant } =\n useContext(IntlayerClientContext) ?? {};\n\n const dictionaryKey = String(key);\n\n const { locale, selector } = resolveDictionaryRead({\n localeOrSelector,\n contextLocale: currentLocale,\n contextVariant,\n dictionaryKey,\n });\n\n return resolveDynamicContent({\n loaderMap: dictionaryPromise as DynamicLoaderMap,\n key: dictionaryKey,\n locale,\n selector,\n loadChunk: (cacheKey, promise) => loadDynamicChunk(cacheKey, promise),\n transform: (dictionary, argument) => getDictionary(dictionary, argument),\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AA+BA,MAAa,wBAKX,mBAGA,KACA,qBACG;CACH,MAAM,EAAE,QAAQ,eAAe,SAAS,mBACtC,WAAW,qBAAqB,KAAK,CAAC;CAExC,MAAM,gBAAgB,OAAO,GAAG;CAEhC,MAAM,EAAE,QAAQ,aAAa,sBAAsB;EACjD;EACA,eAAe;EACf;EACA;CACF,CAAC;CAED,OAAO,sBAAsB;EAC3B,WAAW;EACX,KAAK;EACL;EACA;EACA,YAAY,UAAU,YAAYA,eAAiB,UAAU,OAAO;EACpE,YAAY,YAAY,aAAa,cAAc,YAAY,QAAQ;CACzE,CAAC;AACH"}
|
|
@@ -1,25 +1,13 @@
|
|
|
1
|
+
import { createChunkSuspenseCache } from "@intlayer/core/dictionaryManipulator";
|
|
2
|
+
|
|
1
3
|
// src/client/useLoadDynamic.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
status = "error";
|
|
10
|
-
result = e;
|
|
11
|
-
});
|
|
12
|
-
return { read() {
|
|
13
|
-
if (status === "pending") throw suspender;
|
|
14
|
-
if (status === "error") throw result;
|
|
15
|
-
return result;
|
|
16
|
-
} };
|
|
17
|
-
};
|
|
18
|
-
const cache = /* @__PURE__ */ new Map();
|
|
19
|
-
const useLoadDynamic = (key, promise) => {
|
|
20
|
-
if (!cache.has(key)) cache.set(key, createSuspender(promise));
|
|
21
|
-
return cache.get(key).read();
|
|
22
|
-
};
|
|
4
|
+
/** Chunk cache read by every dynamic dictionary of the page. */
|
|
5
|
+
const chunkCache = createChunkSuspenseCache();
|
|
6
|
+
/**
|
|
7
|
+
* Reads a chunk the Suspense way: throws while `promise` is pending, then
|
|
8
|
+
* returns its value. Only the first `promise` given for a `key` is used.
|
|
9
|
+
*/
|
|
10
|
+
const useLoadDynamic = (key, promise) => chunkCache.read(key, promise);
|
|
23
11
|
|
|
24
12
|
export { useLoadDynamic };
|
|
25
13
|
//# sourceMappingURL=useLoadDynamic.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLoadDynamic.mjs","names":[],"sources":["../../../src/client/useLoadDynamic.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"useLoadDynamic.mjs","names":[],"sources":["../../../src/client/useLoadDynamic.ts"],"sourcesContent":["import { createChunkSuspenseCache } from '@intlayer/core/dictionaryManipulator';\n\n/** Chunk cache read by every dynamic dictionary of the page. */\nconst chunkCache = createChunkSuspenseCache();\n\n/**\n * Reads a chunk the Suspense way: throws while `promise` is pending, then\n * returns its value. Only the first `promise` given for a `key` is used.\n */\nexport const useLoadDynamic = <T>(key: string, promise: Promise<T>): T =>\n chunkCache.read(key, promise);\n"],"mappings":";;;;AAGA,MAAM,aAAa,yBAAyB;;;;;AAM5C,MAAa,kBAAqB,KAAa,YAC7C,WAAW,KAAK,KAAK,OAAO"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { isEnabled } from "@intlayer/editor/isEnabled";
|
|
2
|
+
import { useEffect, useState } from "preact/hooks";
|
|
3
|
+
|
|
4
|
+
// src/editor/useEditedContentSource.ts
|
|
5
|
+
/**
|
|
6
|
+
* Returns the source string edited in the visual editor for a markdown / html
|
|
7
|
+
* node, or `undefined` when the node is not edited (or the editor is off).
|
|
8
|
+
*/
|
|
9
|
+
const useEditedContentSource = (dictionaryKey, keyPath) => {
|
|
10
|
+
const [editedSource, setEditedSource] = useState();
|
|
11
|
+
const keyPathJson = JSON.stringify(keyPath ?? []);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (process.env.INTLAYER_EDITOR_ENABLED === "false" || !isEnabled) return;
|
|
14
|
+
if (!dictionaryKey) return;
|
|
15
|
+
let isStopped = false;
|
|
16
|
+
let unsubscribe = null;
|
|
17
|
+
import("@intlayer/editor").then(({ subscribeToEditedContentSource }) => {
|
|
18
|
+
if (isStopped) return;
|
|
19
|
+
unsubscribe = subscribeToEditedContentSource(dictionaryKey, JSON.parse(keyPathJson), setEditedSource);
|
|
20
|
+
}).catch(() => {});
|
|
21
|
+
return () => {
|
|
22
|
+
isStopped = true;
|
|
23
|
+
unsubscribe?.();
|
|
24
|
+
};
|
|
25
|
+
}, [dictionaryKey, keyPathJson]);
|
|
26
|
+
return editedSource;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { useEditedContentSource };
|
|
30
|
+
//# sourceMappingURL=useEditedContentSource.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEditedContentSource.mjs","names":[],"sources":["../../../src/editor/useEditedContentSource.ts"],"sourcesContent":["import { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport { useEffect, useState } from 'preact/hooks';\n\n/**\n * Returns the source string edited in the visual editor for a markdown / html\n * node, or `undefined` when the node is not edited (or the editor is off).\n */\nexport const useEditedContentSource = (\n dictionaryKey: string | undefined,\n keyPath: KeyPath[] | undefined\n): string | undefined => {\n const [editedSource, setEditedSource] = useState<string | undefined>();\n const keyPathJson = JSON.stringify(keyPath ?? []);\n\n useEffect(() => {\n if (process.env.INTLAYER_EDITOR_ENABLED === 'false' || !isEnabled) return;\n if (!dictionaryKey) return;\n\n let isStopped = false;\n let unsubscribe: (() => void) | null = null;\n\n import('@intlayer/editor')\n .then(({ subscribeToEditedContentSource }) => {\n if (isStopped) return;\n\n unsubscribe = subscribeToEditedContentSource(\n dictionaryKey,\n JSON.parse(keyPathJson) as KeyPath[],\n setEditedSource\n );\n })\n .catch(() => {});\n\n return () => {\n isStopped = true;\n unsubscribe?.();\n };\n }, [dictionaryKey, keyPathJson]);\n\n return editedSource;\n};\n"],"mappings":";;;;;;;;AAQA,MAAa,0BACX,eACA,YACuB;CACvB,MAAM,CAAC,cAAc,mBAAmB,SAA6B;CACrE,MAAM,cAAc,KAAK,UAAU,WAAW,CAAC,CAAC;CAEhD,gBAAgB;EACd,IAAI,QAAQ,IAAI,4BAA4B,WAAW,CAAC,WAAW;EACnE,IAAI,CAAC,eAAe;EAEpB,IAAI,YAAY;EAChB,IAAI,cAAmC;EAEvC,OAAO,mBAAmB,CACvB,MAAM,EAAE,qCAAqC;GAC5C,IAAI,WAAW;GAEf,cAAc,+BACZ,eACA,KAAK,MAAM,WAAW,GACtB,eACF;EACF,CAAC,CAAC,CACD,YAAY,CAAC,CAAC;EAEjB,aAAa;GACX,YAAY;GACZ,cAAc;EAChB;CACF,GAAG,CAAC,eAAe,WAAW,CAAC;CAE/B,OAAO;AACT"}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useLocale } from "../client/useLocale.mjs";
|
|
4
|
+
import { useEditedContentSource } from "../editor/useEditedContentSource.mjs";
|
|
4
5
|
import { useMarkdownContext } from "./MarkdownProvider.mjs";
|
|
5
6
|
import { getMarkdownMetadata } from "@intlayer/core/markdown";
|
|
6
7
|
import { getContentNodeByKeyPath } from "@intlayer/core/dictionaryManipulator";
|
|
7
8
|
|
|
8
9
|
// src/markdown/MarkdownRendererPlugin.tsx
|
|
9
10
|
const MarkdownRendererPlugin = (props) => {
|
|
10
|
-
const {
|
|
11
|
+
const { dictionaryKey, keyPath, options, components } = props;
|
|
11
12
|
const context = useMarkdownContext();
|
|
13
|
+
const children = useEditedContentSource(dictionaryKey, keyPath) ?? props.children;
|
|
12
14
|
return (context?.renderMarkdown ?? ((md) => md))(children, options, {
|
|
13
15
|
...context?.components ?? {},
|
|
14
16
|
...components ?? {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownRendererPlugin.mjs","names":[],"sources":["../../../src/markdown/MarkdownRendererPlugin.tsx"],"sourcesContent":["'use client';\n\nimport { getContentNodeByKeyPath } from '@intlayer/core/dictionaryManipulator';\nimport { getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { ComponentChildren, FunctionComponent } from 'preact';\nimport { useLocale } from '../client/useLocale';\nimport type { HTMLComponents } from '../html/types';\nimport {\n type MarkdownProviderOptions,\n useMarkdownContext,\n} from './MarkdownProvider';\n\ntype MarkdownRendererPluginProps = {\n dictionaryKey: string;\n keyPath: KeyPath[];\n locale?: LocalesValues;\n children: string;\n options?: MarkdownProviderOptions;\n components?: HTMLComponents<'permissive', {}>;\n};\n\nexport const MarkdownRendererPlugin: FunctionComponent<\n MarkdownRendererPluginProps\n> = (props): ComponentChildren => {\n const {
|
|
1
|
+
{"version":3,"file":"MarkdownRendererPlugin.mjs","names":[],"sources":["../../../src/markdown/MarkdownRendererPlugin.tsx"],"sourcesContent":["'use client';\n\nimport { getContentNodeByKeyPath } from '@intlayer/core/dictionaryManipulator';\nimport { getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { ComponentChildren, FunctionComponent } from 'preact';\nimport { useLocale } from '../client/useLocale';\nimport { useEditedContentSource } from '../editor/useEditedContentSource';\nimport type { HTMLComponents } from '../html/types';\nimport {\n type MarkdownProviderOptions,\n useMarkdownContext,\n} from './MarkdownProvider';\n\ntype MarkdownRendererPluginProps = {\n dictionaryKey: string;\n keyPath: KeyPath[];\n locale?: LocalesValues;\n children: string;\n options?: MarkdownProviderOptions;\n components?: HTMLComponents<'permissive', {}>;\n};\n\nexport const MarkdownRendererPlugin: FunctionComponent<\n MarkdownRendererPluginProps\n> = (props): ComponentChildren => {\n const { dictionaryKey, keyPath, options, components } = props;\n const context = useMarkdownContext();\n // Live preview of the source edited in the visual editor\n const editedSource = useEditedContentSource(dictionaryKey, keyPath);\n const children = editedSource ?? props.children;\n const renderMarkdown = context?.renderMarkdown ?? ((md) => md);\n\n return renderMarkdown(children, options, {\n ...(context?.components ?? {}),\n ...(components ?? {}),\n }) as ComponentChildren;\n};\n\ntype MarkdownMetadataRendererProps = MarkdownRendererPluginProps & {\n metadataKeyPath: KeyPath[];\n};\n\nexport const MarkdownMetadataRenderer: FunctionComponent<\n MarkdownMetadataRendererProps\n> = ({ children, metadataKeyPath }): ComponentChildren => {\n const { locale: currentLocale } = useLocale();\n\n const metadata = getMarkdownMetadata(children);\n\n const metadataEl = getContentNodeByKeyPath(\n metadata as ContentNode,\n metadataKeyPath,\n currentLocale as any\n );\n\n return metadataEl as ComponentChildren;\n};\n"],"mappings":";;;;;;;;;AAyBA,MAAa,0BAER,UAA6B;CAChC,MAAM,EAAE,eAAe,SAAS,SAAS,eAAe;CACxD,MAAM,UAAU,mBAAmB;CAGnC,MAAM,WADe,uBAAuB,eAAe,OAC/B,KAAK,MAAM;CAGvC,QAFuB,SAAS,oBAAoB,OAAO,IAEtC,CAAC,UAAU,SAAS;EACvC,GAAI,SAAS,cAAc,CAAC;EAC5B,GAAI,cAAc,CAAC;CACrB,CAAC;AACH;AAMA,MAAa,4BAER,EAAE,UAAU,sBAAyC;CACxD,MAAM,EAAE,QAAQ,kBAAkB,UAAU;CAE5C,MAAM,WAAW,oBAAoB,QAAQ;CAQ7C,OANmB,wBACjB,UACA,iBACA,aAGc;AAClB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LocalesValues, StrictModeLocaleMap } from "@intlayer/types/module_augmentation";
|
|
2
2
|
import { Dictionary } from "@intlayer/types/dictionary";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Hook that loads the locale chunk of a dictionary and returns its content.
|
|
5
5
|
*
|
|
6
6
|
* If the locale is not provided, it will use the locale from the client context
|
|
7
7
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryAsync.d.ts","names":[],"sources":["../../../src/client/useDictionaryAsync.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.d.ts","names":[],"sources":["../../../src/client/useDictionaryAsync.ts"],"mappings":";;;;;;;qBAgBa,2BAAkC,UAAU,YAAU,mBAC9C,0BAA0B,QAAQ,KAAG,SAC/C,kBACR,QAAQ"}
|
|
@@ -4,10 +4,9 @@ import { QualifiedDynamicLoaderMap } from "@intlayer/core/dictionaryManipulator"
|
|
|
4
4
|
/**
|
|
5
5
|
* Preact hook that lazily loads a dictionary and returns its content.
|
|
6
6
|
*
|
|
7
|
-
* The
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* the selector targets are loaded.
|
|
7
|
+
* The locale, selector, chunk selection and transform are resolved by the
|
|
8
|
+
* shared `resolveDictionaryRead` / `resolveDynamicContent`, so this hook only
|
|
9
|
+
* contributes the provider context and the Suspense cache.
|
|
11
10
|
*
|
|
12
11
|
* If the locale is not provided (directly or through the selector), the client
|
|
13
12
|
* context locale is used.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.d.ts","names":[],"sources":["../../../src/client/useDictionaryDynamic.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.d.ts","names":[],"sources":["../../../src/client/useDictionaryDynamic.ts"],"mappings":";;;;;;;;;;;;;qBA+Ba,6BACL,UAAU,kBACV,UAAU,sBACV,UAAU,gBAAgB,yBAAyB,KAAK,iBAAe,mBAGzE,0BAA0B,QAAQ,MAClC,2BAAyB,KACxB,GAAC,mBACa"}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads a chunk the Suspense way: throws while `promise` is pending, then
|
|
3
|
+
* returns its value. Only the first `promise` given for a `key` is used.
|
|
4
|
+
*/
|
|
1
5
|
export declare const useLoadDynamic: <T>(key: string, promise: Promise<T>) => T;
|
|
2
6
|
//# sourceMappingURL=useLoadDynamic.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLoadDynamic.d.ts","names":[],"sources":["../../../src/client/useLoadDynamic.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLoadDynamic.d.ts","names":[],"sources":["../../../src/client/useLoadDynamic.ts"],"mappings":";;;;qBASa,iBAAkB,GAAC,aAAa,SAAW,QAAQ,OAAK"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { KeyPath } from "@intlayer/types/keyPath";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the source string edited in the visual editor for a markdown / html
|
|
4
|
+
* node, or `undefined` when the node is not edited (or the editor is off).
|
|
5
|
+
*/
|
|
6
|
+
export declare const useEditedContentSource: (dictionaryKey: string | undefined, keyPath: KeyPath[] | undefined) => string | undefined;
|
|
7
|
+
//# sourceMappingURL=useEditedContentSource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEditedContentSource.d.ts","names":[],"sources":["../../../src/editor/useEditedContentSource.ts"],"mappings":";;;;;qBAQa,yBAAsB,mCACA,SACxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownRendererPlugin.d.ts","names":[],"sources":["../../../src/markdown/MarkdownRendererPlugin.tsx"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"MarkdownRendererPlugin.d.ts","names":[],"sources":["../../../src/markdown/MarkdownRendererPlugin.tsx"],"mappings":";;;;;KAgBK;EACH;EACA,SAAS;EACT,SAAS;EACT;EACA,UAAU;EACV,aAAa;;qBAGF,wBAAwB,kBACnC;KAeG,gCAAgC;EACnC,iBAAiB;;qBAGN,0BAA0B,kBACrC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "preact-intlayer",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.9.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Easily internationalize i18n your Preact applications with type-safe multilingual content management.",
|
|
6
6
|
"keywords": [
|
|
@@ -101,12 +101,12 @@
|
|
|
101
101
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
102
102
|
},
|
|
103
103
|
"dependencies": {
|
|
104
|
-
"@intlayer/api": "9.
|
|
105
|
-
"@intlayer/config": "9.
|
|
106
|
-
"@intlayer/core": "9.
|
|
107
|
-
"@intlayer/editor": "9.
|
|
108
|
-
"@intlayer/engine": "9.
|
|
109
|
-
"@intlayer/types": "9.
|
|
104
|
+
"@intlayer/api": "9.9.0",
|
|
105
|
+
"@intlayer/config": "9.9.0",
|
|
106
|
+
"@intlayer/core": "9.9.0",
|
|
107
|
+
"@intlayer/editor": "9.9.0",
|
|
108
|
+
"@intlayer/engine": "9.9.0",
|
|
109
|
+
"@intlayer/types": "9.9.0"
|
|
110
110
|
},
|
|
111
111
|
"devDependencies": {
|
|
112
112
|
"@types/node": "^26",
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"preact": ">=8.0.0"
|
|
124
124
|
},
|
|
125
125
|
"optionalDependencies": {
|
|
126
|
-
"@intlayer/analytics": "9.
|
|
126
|
+
"@intlayer/analytics": "9.9.0"
|
|
127
127
|
},
|
|
128
128
|
"engines": {
|
|
129
129
|
"node": ">=14.18"
|