solid-intlayer 9.8.1 → 9.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/LoadingBoundary.cjs +1 -0
- package/dist/cjs/analytics/useAnalytics.cjs +1 -1
- package/dist/cjs/analytics/useExperiment.cjs +1 -1
- package/dist/cjs/client/IntlayerProvider.cjs +1 -1
- package/dist/cjs/client/getBrowserLocale.cjs +1 -1
- package/dist/cjs/client/t.cjs +1 -1
- package/dist/cjs/client/useDictionary.cjs +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +1 -1
- package/dist/cjs/client/useLoadDynamic.cjs +1 -1
- package/dist/cjs/client/useLocale.cjs +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +1 -1
- package/dist/cjs/client/usePathname.cjs +1 -1
- package/dist/cjs/client/useRewriteURL.cjs +1 -1
- package/dist/cjs/client/useTraduction.cjs +1 -1
- package/dist/cjs/editor/useEditor.cjs +1 -1
- package/dist/cjs/getDictionary.cjs +1 -1
- package/dist/cjs/html/HTMLProvider.cjs +1 -1
- package/dist/cjs/html/HTMLRenderer.cjs +1 -1
- package/dist/cjs/markdown/MarkdownProvider.cjs +1 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs +1 -1
- package/dist/cjs/markdown/runtime.cjs +1 -1
- package/dist/cjs/plugins.cjs +1 -1
- package/dist/cjs/server/useDictionary.cjs +1 -1
- package/dist/cjs/solidCompat.cjs +1 -0
- package/dist/cjs/solidElement/renderSolidElement.cjs +1 -1
- package/dist/esm/LoadingBoundary.mjs +12 -0
- package/dist/esm/analytics/useAnalytics.mjs +14 -11
- package/dist/esm/analytics/useExperiment.mjs +5 -4
- package/dist/esm/client/IntlayerProvider.mjs +28 -28
- package/dist/esm/client/getBrowserLocale.mjs +21 -21
- package/dist/esm/client/t.mjs +4 -4
- package/dist/esm/client/useDictionary.mjs +22 -14
- package/dist/esm/client/useDictionaryAsync.mjs +3 -3
- package/dist/esm/client/useDictionaryDynamic.mjs +26 -23
- package/dist/esm/client/useLoadDynamic.mjs +4 -5
- package/dist/esm/client/useLocale.mjs +15 -14
- package/dist/esm/client/useLocaleStorage.mjs +7 -7
- package/dist/esm/client/usePathname.mjs +9 -8
- package/dist/esm/client/useRewriteURL.mjs +6 -6
- package/dist/esm/client/useTraduction.mjs +5 -5
- package/dist/esm/editor/useEditor.mjs +11 -11
- package/dist/esm/getDictionary.mjs +3 -3
- package/dist/esm/html/HTMLProvider.mjs +5 -4
- package/dist/esm/html/HTMLRenderer.mjs +6 -6
- package/dist/esm/markdown/MarkdownProvider.mjs +20 -19
- package/dist/esm/markdown/MarkdownRenderer.mjs +27 -25
- package/dist/esm/markdown/runtime.mjs +8 -13
- package/dist/esm/plugins.mjs +76 -75
- package/dist/esm/server/useDictionary.mjs +9 -6
- package/dist/esm/solidCompat.mjs +48 -0
- package/dist/esm/solidElement/renderSolidElement.mjs +14 -16
- package/dist/rolldown-runtime-BocRIvOZ.js +1 -0
- package/dist/solid/IntlayerNode.jsx +10 -0
- package/dist/solid/LoadingBoundary.jsx +10 -0
- package/dist/solid/analytics/AnalyticsProvider.jsx +11 -0
- package/dist/solid/analytics/exposureSink.js +21 -0
- package/dist/solid/analytics/index.js +5 -0
- package/dist/solid/analytics/useAnalytics.jsx +58 -0
- package/dist/solid/analytics/useConversion.js +24 -0
- package/dist/solid/analytics/useExperiment.js +58 -0
- package/dist/solid/client/IntlayerProvider.jsx +81 -0
- package/dist/solid/client/getBrowserLocale.jsx +113 -0
- package/dist/solid/client/index.js +14 -0
- package/dist/solid/client/t.js +15 -0
- package/dist/solid/client/useContent.js +15 -0
- package/dist/solid/client/useDictionary.js +56 -0
- package/dist/solid/client/useDictionaryAsync.js +17 -0
- package/dist/solid/client/useDictionaryDynamic.js +105 -0
- package/dist/solid/client/useIntlayer.js +55 -0
- package/dist/solid/client/useLoadDynamic.js +134 -0
- package/dist/solid/client/useLocale.js +51 -0
- package/dist/solid/client/useLocaleBase.js +18 -0
- package/dist/solid/client/useLocaleStorage.js +52 -0
- package/dist/solid/client/usePathname.js +40 -0
- package/dist/solid/client/useRewriteURL.js +20 -0
- package/dist/solid/client/useTraduction.js +31 -0
- package/dist/solid/editor/ContentSelector.jsx +9 -0
- package/dist/solid/editor/EditorProvider.jsx +7 -0
- package/dist/solid/editor/useEditor.jsx +37 -0
- package/dist/solid/esm-BS5TZIsL.js +644 -0
- package/dist/solid/format/index.js +10 -0
- package/dist/solid/format/useCompact.js +14 -0
- package/dist/solid/format/useCurrency.js +15 -0
- package/dist/solid/format/useDate.js +24 -0
- package/dist/solid/format/useIntl.js +30 -0
- package/dist/solid/format/useList.js +14 -0
- package/dist/solid/format/useNumber.js +18 -0
- package/dist/solid/format/usePercentage.js +15 -0
- package/dist/solid/format/useRelativeTime.js +15 -0
- package/dist/solid/format/useUnit.js +14 -0
- package/dist/solid/getDictionary.js +16 -0
- package/dist/solid/getIntlayer.js +13 -0
- package/dist/solid/html/HTMLProvider.jsx +16 -0
- package/dist/solid/html/HTMLRenderer.jsx +45 -0
- package/dist/solid/html/index.js +3 -0
- package/dist/solid/html/types.js +0 -0
- package/dist/solid/index.js +21 -0
- package/dist/solid/isEnabled-C5NUhdhZ.js +100 -0
- package/dist/solid/markdown/MarkdownProvider.jsx +38 -0
- package/dist/solid/markdown/MarkdownRenderer.jsx +47 -0
- package/dist/solid/markdown/compiler.jsx +62 -0
- package/dist/solid/markdown/index.js +4 -0
- package/dist/solid/markdown/runtime.jsx +42 -0
- package/dist/solid/plugins.jsx +230 -0
- package/dist/solid/proxyKeys.js +13 -0
- package/dist/solid/server/index.js +1 -0
- package/dist/solid/server/useDictionary.js +29 -0
- package/dist/solid/solidCompat.js +155 -0
- package/dist/solid/solidElement/renderSolidElement.jsx +32 -0
- package/dist/types/LoadingBoundary.d.ts +12 -0
- package/dist/types/client/useDictionaryDynamic.d.ts +1 -1
- package/dist/types/client/useLoadDynamic.d.ts +4 -4
- package/dist/types/client/useLocaleStorage.d.ts +2 -2
- package/dist/types/format/useIntl.d.ts +1 -1
- package/dist/types/getDictionary.d.ts +5 -1
- package/dist/types/html/HTMLProvider.d.ts +1 -1
- package/dist/types/markdown/MarkdownProvider.d.ts +5 -1
- package/dist/types/server/useDictionary.d.ts +6 -6
- package/dist/types/solidCompat.d.ts +92 -0
- package/dist/types/solidElement/renderSolidElement.d.ts +1 -1
- package/package.json +25 -18
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IntlayerClientContext } from "../client/IntlayerProvider.jsx";
|
|
2
|
+
import { useContext } from "solid-js";
|
|
3
|
+
import { date, presets } from "@intlayer/core/formatters";
|
|
4
|
+
// src/format/useDate.ts
|
|
5
|
+
/**
|
|
6
|
+
* Solid client hook that provides a localized date/time formatter.
|
|
7
|
+
*
|
|
8
|
+
* @returns {(date: Date | string | number, options?: DateProps) => string}
|
|
9
|
+
* A function to format dates into localized strings.
|
|
10
|
+
*/
|
|
11
|
+
var useDate = () => {
|
|
12
|
+
const { locale } = useContext(IntlayerClientContext);
|
|
13
|
+
return (...args) => {
|
|
14
|
+
const options = typeof args[1] === "string" ? {
|
|
15
|
+
...presets[args[1]],
|
|
16
|
+
locale: locale()
|
|
17
|
+
} : {
|
|
18
|
+
...args[1],
|
|
19
|
+
locale: args[1]?.locale ?? locale()
|
|
20
|
+
};
|
|
21
|
+
return date(args[0], options);
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export { useDate };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { IntlayerClientContext } from "../client/IntlayerProvider.jsx";
|
|
2
|
+
import { createMemo, useContext } from "solid-js";
|
|
3
|
+
import { bindIntl } from "@intlayer/core/formatters";
|
|
4
|
+
// src/format/useIntl.ts
|
|
5
|
+
/**
|
|
6
|
+
* Solid client hook that provides a locale-bound `Intl` object.
|
|
7
|
+
*
|
|
8
|
+
* It acts exactly like the native `Intl` object, but acts as a proxy to:
|
|
9
|
+
* 1. Inject the current locale automatically if none is provided.
|
|
10
|
+
* 2. Use the performance-optimized `CachedIntl` under the hood.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* const intl = useIntl(); // uses context locale
|
|
15
|
+
*
|
|
16
|
+
* // Standard API, but no need to pass locale as the first argument
|
|
17
|
+
* const formatted = new (intl().NumberFormat)({
|
|
18
|
+
* style: 'currency',
|
|
19
|
+
* currency: 'USD'
|
|
20
|
+
* }).format(123.45);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
var useIntl = (locale) => {
|
|
24
|
+
const context = useContext(IntlayerClientContext);
|
|
25
|
+
return createMemo(() => {
|
|
26
|
+
const currentLocale = locale ?? context.locale();
|
|
27
|
+
return bindIntl(currentLocale);
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
export { useIntl };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useIntlayerContext } from "../client/IntlayerProvider.jsx";
|
|
2
|
+
import { list } from "@intlayer/core/formatters";
|
|
3
|
+
// src/format/useList.ts
|
|
4
|
+
/**
|
|
5
|
+
* Solid client hook that provides a localized list formatter.
|
|
6
|
+
*/
|
|
7
|
+
var useList = () => {
|
|
8
|
+
const { locale } = useIntlayerContext();
|
|
9
|
+
return (...args) => list(args[0], {
|
|
10
|
+
...args[1],
|
|
11
|
+
locale: args[1]?.locale ?? locale()
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
export { useList };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IntlayerClientContext } from "../client/IntlayerProvider.jsx";
|
|
2
|
+
import { useContext } from "solid-js";
|
|
3
|
+
import { number } from "@intlayer/core/formatters";
|
|
4
|
+
// src/format/useNumber.ts
|
|
5
|
+
/**
|
|
6
|
+
* Solid client hook that provides a localized number formatter.
|
|
7
|
+
*
|
|
8
|
+
* @returns {(value: string | number, options?: import("@intlayer/core/formatters").NumberProps) => string}
|
|
9
|
+
* A function to format numbers into localized strings.
|
|
10
|
+
*/
|
|
11
|
+
var useNumber = () => {
|
|
12
|
+
const { locale } = useContext(IntlayerClientContext);
|
|
13
|
+
return (...args) => number(args[0], {
|
|
14
|
+
...args[1],
|
|
15
|
+
locale: args[1]?.locale ?? locale()
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
export { useNumber };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IntlayerClientContext } from "../client/IntlayerProvider.jsx";
|
|
2
|
+
import { useContext } from "solid-js";
|
|
3
|
+
import { percentage } from "@intlayer/core/formatters";
|
|
4
|
+
// src/format/usePercentage.ts
|
|
5
|
+
/**
|
|
6
|
+
* Solid client hook that provides a localized percentage formatter.
|
|
7
|
+
*/
|
|
8
|
+
var usePercentage = () => {
|
|
9
|
+
const { locale } = useContext(IntlayerClientContext);
|
|
10
|
+
return (...args) => percentage(args[0], {
|
|
11
|
+
...args[1],
|
|
12
|
+
locale: args[1]?.locale ?? locale()
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
export { usePercentage };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IntlayerClientContext } from "../client/IntlayerProvider.jsx";
|
|
2
|
+
import { useContext } from "solid-js";
|
|
3
|
+
import { relativeTime } from "@intlayer/core/formatters";
|
|
4
|
+
// src/format/useRelativeTime.ts
|
|
5
|
+
/**
|
|
6
|
+
* Solid client hook that provides a localized relative time formatter.
|
|
7
|
+
*/
|
|
8
|
+
var useRelativeTime = () => {
|
|
9
|
+
const { locale } = useContext(IntlayerClientContext);
|
|
10
|
+
return (...args) => relativeTime(args[0], args[1], {
|
|
11
|
+
...args[2],
|
|
12
|
+
locale: args[2]?.locale ?? locale()
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
export { useRelativeTime };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useIntlayerContext } from "../client/IntlayerProvider.jsx";
|
|
2
|
+
import { units } from "@intlayer/core/formatters";
|
|
3
|
+
// src/format/useUnit.ts
|
|
4
|
+
/**
|
|
5
|
+
* Solid client hook that provides a localized unit formatter.
|
|
6
|
+
*/
|
|
7
|
+
var useUnit = () => {
|
|
8
|
+
const { locale } = useIntlayerContext();
|
|
9
|
+
return (...args) => units(args[0], {
|
|
10
|
+
...args[1],
|
|
11
|
+
locale: args[1]?.locale ?? locale()
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
export { useUnit };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getPlugins } from "./plugins.jsx";
|
|
2
|
+
import { getDictionary as getDictionary$1 } from "@intlayer/core/interpreter";
|
|
3
|
+
// src/getDictionary.ts
|
|
4
|
+
/**
|
|
5
|
+
* Transforms a dictionary (or qualified dictionary group) and returns its
|
|
6
|
+
* content for the given locale or selector (`{ item }`, `{ variant }`,
|
|
7
|
+
* optionally combined with `locale`).
|
|
8
|
+
*
|
|
9
|
+
* `getPluginsForLocale` picks the plugin set; transforms are cached per plugin
|
|
10
|
+
* set, so a dedicated set keeps the result from being shared.
|
|
11
|
+
*/
|
|
12
|
+
var getDictionary = (dictionary, localeOrSelector, getPluginsForLocale = getPlugins) => {
|
|
13
|
+
const locale = typeof localeOrSelector === "object" && localeOrSelector !== null ? localeOrSelector.locale : localeOrSelector;
|
|
14
|
+
return getDictionary$1(dictionary, localeOrSelector, getPluginsForLocale(locale));
|
|
15
|
+
};
|
|
16
|
+
export { getDictionary };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getPlugins } from "./plugins.jsx";
|
|
2
|
+
import { getIntlayer as getIntlayer$1 } from "@intlayer/core/interpreter";
|
|
3
|
+
// src/getIntlayer.ts
|
|
4
|
+
/**
|
|
5
|
+
* Picks one dictionary by its key and returns its content for the given
|
|
6
|
+
* locale or selector (`{ item }`, `{ variant }`,
|
|
7
|
+
* optionally combined with `locale`).
|
|
8
|
+
*/
|
|
9
|
+
var getIntlayer = (key, localeOrSelector) => {
|
|
10
|
+
const locale = typeof localeOrSelector === "object" && localeOrSelector !== null ? localeOrSelector.locale : localeOrSelector;
|
|
11
|
+
return getIntlayer$1(key, localeOrSelector, getPlugins(locale));
|
|
12
|
+
};
|
|
13
|
+
export { getIntlayer };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getContextProvider } from "../solidCompat.js";
|
|
2
|
+
import { createContext, useContext } from "solid-js";
|
|
3
|
+
// src/html/HTMLProvider.tsx
|
|
4
|
+
/**
|
|
5
|
+
* `null` outside a provider. An explicit default keeps `useContext` from
|
|
6
|
+
* throwing on Solid 2, where default-less contexts require a provider.
|
|
7
|
+
*/
|
|
8
|
+
var HTMLContext = createContext(null);
|
|
9
|
+
var HTMLContextProvider = getContextProvider(HTMLContext);
|
|
10
|
+
var useHTMLContext = () => useContext(HTMLContext);
|
|
11
|
+
var HTMLProvider = (props) => {
|
|
12
|
+
return <HTMLContextProvider value={{ components: props.components }}>
|
|
13
|
+
{props.children}
|
|
14
|
+
</HTMLContextProvider>;
|
|
15
|
+
};
|
|
16
|
+
export { HTMLProvider, useHTMLContext };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useHTMLContext } from "./HTMLProvider.jsx";
|
|
2
|
+
import { getHTML } from "@intlayer/core/interpreter";
|
|
3
|
+
import { VOID_HTML_ELEMENTS } from "@intlayer/core/transpiler";
|
|
4
|
+
// src/html/HTMLRenderer.tsx
|
|
5
|
+
/**
|
|
6
|
+
* Renders HTML-like content to JSX with the provided components.
|
|
7
|
+
*
|
|
8
|
+
* This function does not use context from HTMLProvider. Use `useHTMLRenderer`
|
|
9
|
+
* hook if you want to leverage provider context.
|
|
10
|
+
*/
|
|
11
|
+
var renderHTML = (content, { components = {} } = {}) => {
|
|
12
|
+
const userComponents = Object.fromEntries(Object.entries(components).filter(([, Component]) => Component).map(([key, Component]) => [key, (props) => <Dynamic component={Component} {...props} />]));
|
|
13
|
+
const wrappedComponents = new Proxy(userComponents, { get(target, prop) {
|
|
14
|
+
if (typeof prop === "string" && prop in target) return target[prop];
|
|
15
|
+
if (typeof prop === "string" && /^[a-z][a-z0-9]*$/.test(prop)) {
|
|
16
|
+
if (VOID_HTML_ELEMENTS.has(prop)) return ({ children: _children, ...rest }) => <Dynamic component={prop} {...rest} />;
|
|
17
|
+
return (props) => <Dynamic component={prop} {...props} />;
|
|
18
|
+
}
|
|
19
|
+
} });
|
|
20
|
+
return getHTML(content, wrappedComponents);
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Hook that returns a function to render HTML content.
|
|
24
|
+
*
|
|
25
|
+
* This hook considers the configuration from the `HTMLProvider` context if available,
|
|
26
|
+
* falling back to the provided components.
|
|
27
|
+
*/
|
|
28
|
+
var useHTMLRenderer = ({ components } = {}) => {
|
|
29
|
+
const context = useHTMLContext();
|
|
30
|
+
return (content) => {
|
|
31
|
+
return renderHTML(content, { components: {
|
|
32
|
+
...context?.components,
|
|
33
|
+
...components
|
|
34
|
+
} });
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Solid component that renders HTML-like content to JSX.
|
|
39
|
+
*/
|
|
40
|
+
var HTMLRenderer = (props) => {
|
|
41
|
+
const render = useHTMLRenderer({ components: props.components || props.userComponents });
|
|
42
|
+
const content = () => props.children || props.html || "";
|
|
43
|
+
return render(content());
|
|
44
|
+
};
|
|
45
|
+
export { HTMLRenderer, renderHTML, useHTMLRenderer };
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AnalyticsProvider } from "./analytics/AnalyticsProvider.jsx";
|
|
2
|
+
import { useAnalytics } from "./analytics/useAnalytics.jsx";
|
|
3
|
+
import { useConversion } from "./analytics/useConversion.js";
|
|
4
|
+
import { useExperiment } from "./analytics/useExperiment.js";
|
|
5
|
+
import { getBrowserLocale } from "./client/getBrowserLocale.jsx";
|
|
6
|
+
import { IntlayerClientContext, IntlayerProvider, IntlayerProviderContent, useIntlayerContext } from "./client/IntlayerProvider.jsx";
|
|
7
|
+
import { localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage } from "./client/useLocaleStorage.js";
|
|
8
|
+
import { t } from "./client/t.js";
|
|
9
|
+
import { useDictionary } from "./client/useDictionary.js";
|
|
10
|
+
import { useDictionaryAsync } from "./client/useDictionaryAsync.js";
|
|
11
|
+
import { useDictionaryDynamic } from "./client/useDictionaryDynamic.js";
|
|
12
|
+
import { useIntlayer } from "./client/useIntlayer.js";
|
|
13
|
+
import { useLoadDynamic } from "./client/useLoadDynamic.js";
|
|
14
|
+
import { useLocale } from "./client/useLocale.js";
|
|
15
|
+
import { useLocaleBase } from "./client/useLocaleBase.js";
|
|
16
|
+
import { usePathname } from "./client/usePathname.js";
|
|
17
|
+
import { useRewriteURL } from "./client/useRewriteURL.js";
|
|
18
|
+
import { getDictionary } from "./getDictionary.js";
|
|
19
|
+
import { getIntlayer } from "./getIntlayer.js";
|
|
20
|
+
import "./analytics/index.js";
|
|
21
|
+
export { AnalyticsProvider, IntlayerClientContext, IntlayerProvider, IntlayerProviderContent, getBrowserLocale, getDictionary, getIntlayer, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, t, useAnalytics, useConversion, useDictionary, useDictionaryAsync, useDictionaryDynamic, useExperiment, useIntlayer, useIntlayerContext, useLoadDynamic, useLocale, useLocaleBase, useLocaleCookie, useLocaleStorage, usePathname, useRewriteURL };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { analytics, editor } from "@intlayer/config/built";
|
|
2
|
+
// ../@intlayer/analytics/dist/esm/utils/isBot.mjs
|
|
3
|
+
/**
|
|
4
|
+
* Bot / automation detection.
|
|
5
|
+
*
|
|
6
|
+
* Analytics must describe real people. Crawlers, link-preview fetchers, uptime
|
|
7
|
+
* monitors, AI agents and CI browsers (Lighthouse, Playwright, Puppeteer) all
|
|
8
|
+
* execute JavaScript nowadays, so they would otherwise be counted as visitors
|
|
9
|
+
* and inflate page views, content exposures and A/B conversion rates.
|
|
10
|
+
*
|
|
11
|
+
* Everything here is a pure string/environment check — no network, no storage.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* User agents that look like a bot but belong to real user devices, checked
|
|
15
|
+
* before {@link BOT_USER_AGENT_PATTERN}. `CUBOT` is an Android phone brand
|
|
16
|
+
* whose model strings (`CUBOT_X19`) contain the `bot` token.
|
|
17
|
+
*/
|
|
18
|
+
var HUMAN_USER_AGENT_EXCEPTION_PATTERN = /cubot/i;
|
|
19
|
+
/**
|
|
20
|
+
* Matches known non-human user agents. Grouped by family so the list stays
|
|
21
|
+
* reviewable:
|
|
22
|
+
* - generic tokens (`…bot`, `crawler`, `spider`, `scraper`)
|
|
23
|
+
* - HTTP clients used by scripts (curl, wget, requests, axios…)
|
|
24
|
+
* - headless / automation runtimes (Playwright, Puppeteer, Lighthouse…)
|
|
25
|
+
* - search-engine and SEO crawlers
|
|
26
|
+
* - social link-preview fetchers
|
|
27
|
+
* - AI / LLM crawlers and agents
|
|
28
|
+
*/
|
|
29
|
+
var BOT_USER_AGENT_PATTERN = /bot\b|bot[/\-\s]|crawler|crawling|spider|scraper|slurp|archiver|feedfetcher|validator|curl\/|wget\/|python-requests|python-urllib|okhttp|axios\/|node-fetch|got \(|go-http-client|java\/|libwww|httpunit|http_request|apache-httpclient|headless|phantomjs|puppeteer|playwright|selenium|webdriver|cypress|lighthouse|pagespeed|gtmetrix|prerender|pingdom|uptime|statuscake|site24x7|bingpreview|yandex|baiduspider|sogou|exabot|semrush|ahrefs|mj12|dotbot|petalbot|applebot|amazonbot|bytespider|facebookexternalhit|meta-externalagent|embedly|outbrain|quora link preview|skypeuripreview|vkshare|w3c_validator|apis-google|mediapartners|adsbot|storebot-google|google-inspectiontool|google-read-aloud|google-extended|duplexweb-google|gptbot|oai-searchbot|chatgpt-user|perplexity|claudebot|claude-web|anthropic-ai|cohere-ai|ccbot|diffbot|imagesift|omgili|timpi|youbot/i;
|
|
30
|
+
/**
|
|
31
|
+
* Tells whether a user agent string identifies a bot, crawler or automation
|
|
32
|
+
* runtime rather than a human visitor.
|
|
33
|
+
*
|
|
34
|
+
* A missing or empty user agent is treated as a bot: every real browser sends
|
|
35
|
+
* one, so its absence means a script or a forged request.
|
|
36
|
+
*
|
|
37
|
+
* @param userAgent - The raw `User-Agent` string (header or `navigator.userAgent`).
|
|
38
|
+
* @returns `true` when the traffic must not be recorded.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* isBotUserAgent('Mozilla/5.0 (compatible; Googlebot/2.1)'); // true
|
|
42
|
+
* isBotUserAgent('Mozilla/5.0 (Macintosh) Chrome/120'); // false
|
|
43
|
+
*/
|
|
44
|
+
var isBotUserAgent = (userAgent) => {
|
|
45
|
+
if (!userAgent) return true;
|
|
46
|
+
if (HUMAN_USER_AGENT_EXCEPTION_PATTERN.test(userAgent)) return false;
|
|
47
|
+
return BOT_USER_AGENT_PATTERN.test(userAgent);
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Globals injected by automation runtimes. Their mere presence means the page
|
|
51
|
+
* is driven by a script, whatever the user agent claims.
|
|
52
|
+
*/
|
|
53
|
+
var AUTOMATION_GLOBAL_KEYS = [
|
|
54
|
+
"_phantom",
|
|
55
|
+
"__nightmare",
|
|
56
|
+
"callPhantom",
|
|
57
|
+
"__selenium_unwrapped",
|
|
58
|
+
"__webdriver_evaluate",
|
|
59
|
+
"__driver_evaluate",
|
|
60
|
+
"domAutomation",
|
|
61
|
+
"Cypress"
|
|
62
|
+
];
|
|
63
|
+
/**
|
|
64
|
+
* Tells whether the current browser environment is automated, combining the
|
|
65
|
+
* user agent with automation fingerprints (`navigator.webdriver`, runtime
|
|
66
|
+
* globals) that headless browsers spoofing a normal user agent still expose.
|
|
67
|
+
*
|
|
68
|
+
* Always `false` outside a browser (SSR): there is nothing to collect there,
|
|
69
|
+
* and the server must not disable a client that has not run yet.
|
|
70
|
+
*
|
|
71
|
+
* @returns `true` when analytics must stay off for this environment.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* if (isBotEnvironment()) return; // never start the client for a crawler
|
|
75
|
+
*/
|
|
76
|
+
var isBotEnvironment = () => {
|
|
77
|
+
if (typeof navigator === "undefined") return false;
|
|
78
|
+
if (navigator.webdriver === true) return true;
|
|
79
|
+
const automationGlobals = globalThis;
|
|
80
|
+
if (AUTOMATION_GLOBAL_KEYS.some((key) => key in automationGlobals)) return true;
|
|
81
|
+
if (!navigator.userAgent) return false;
|
|
82
|
+
return isBotUserAgent(navigator.userAgent);
|
|
83
|
+
};
|
|
84
|
+
// ../@intlayer/analytics/dist/esm/isEnabled.mjs
|
|
85
|
+
/**
|
|
86
|
+
* Runtime guard mirroring `@intlayer/editor`'s `isEnabled`, but inverted with
|
|
87
|
+
* respect to the iframe: analytics runs for real end users on the **top**
|
|
88
|
+
* window and stays off inside the editor/CMS preview iframe so editor sessions
|
|
89
|
+
* are never counted as traffic.
|
|
90
|
+
*
|
|
91
|
+
* Enabled when:
|
|
92
|
+
* - the bundler did not tree-shake analytics away, and
|
|
93
|
+
* - the user did not opt out (`analytics.enabled === true`, the default), and
|
|
94
|
+
* - a project key is configured (`editor.clientId`), and
|
|
95
|
+
* - we are on the client, and
|
|
96
|
+
* - we are the top window (not embedded in the editor), and
|
|
97
|
+
* - the visitor is not a bot, crawler or automation runtime.
|
|
98
|
+
*/
|
|
99
|
+
var isEnabled = !(process.env.INTLAYER_ANALYTICS_ENABLED === "false") && analytics?.enabled === true && Boolean(editor?.clientId) && typeof window !== "undefined" && window.self === window.top && !isBotEnvironment();
|
|
100
|
+
export { isBotUserAgent as i, BOT_USER_AGENT_PATTERN as n, isBotEnvironment as r, isEnabled as t };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { getContextProvider } from "../solidCompat.js";
|
|
2
|
+
import { compileMarkdown } from "./compiler.jsx";
|
|
3
|
+
import { createContext, useContext } from "solid-js";
|
|
4
|
+
// src/markdown/MarkdownProvider.tsx
|
|
5
|
+
/**
|
|
6
|
+
* `null` outside a provider. An explicit default keeps `useContext` from
|
|
7
|
+
* throwing on Solid 2, where default-less contexts require a provider.
|
|
8
|
+
*/
|
|
9
|
+
var MarkdownContext = createContext(null);
|
|
10
|
+
var MarkdownContextProvider = getContextProvider(MarkdownContext);
|
|
11
|
+
var MarkdownProvider = (props) => {
|
|
12
|
+
const defaultRenderMarkdown = (content, options, componentsOverride, wrapperOverride) => {
|
|
13
|
+
if (props.renderMarkdown) return props.renderMarkdown(content, options, componentsOverride, wrapperOverride);
|
|
14
|
+
const mergedOptions = {
|
|
15
|
+
forceBlock: options?.forceBlock ?? props.forceBlock,
|
|
16
|
+
preserveFrontmatter: options?.preserveFrontmatter ?? props.preserveFrontmatter,
|
|
17
|
+
tagfilter: options?.tagfilter ?? props.tagfilter,
|
|
18
|
+
wrapper: wrapperOverride || props.wrapper,
|
|
19
|
+
components: {
|
|
20
|
+
...props.components,
|
|
21
|
+
...componentsOverride ?? {}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
return compileMarkdown(content, mergedOptions);
|
|
25
|
+
};
|
|
26
|
+
return <MarkdownContextProvider value={{
|
|
27
|
+
components: props.components,
|
|
28
|
+
renderMarkdown: defaultRenderMarkdown
|
|
29
|
+
}}>
|
|
30
|
+
{props.children}
|
|
31
|
+
</MarkdownContextProvider>;
|
|
32
|
+
};
|
|
33
|
+
var useMarkdown = () => {
|
|
34
|
+
const context = useContext(MarkdownContext);
|
|
35
|
+
if (!context) throw new Error("useMarkdown must be used within a MarkdownProvider. To fix this error, wrap your component with <MarkdownProvider>.");
|
|
36
|
+
return context;
|
|
37
|
+
};
|
|
38
|
+
export { MarkdownContext, MarkdownProvider, useMarkdown };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { LoadingBoundary } from "../LoadingBoundary.jsx";
|
|
2
|
+
import { createAsyncValue } from "../solidCompat.js";
|
|
3
|
+
import { compileMarkdown } from "./compiler.jsx";
|
|
4
|
+
import { MarkdownContext, useMarkdown } from "./MarkdownProvider.jsx";
|
|
5
|
+
import { getMarkdownMetadata } from "@intlayer/core/markdown";
|
|
6
|
+
import { createMemo, useContext } from "solid-js";
|
|
7
|
+
import { getContentNodeByKeyPath } from "@intlayer/core/dictionaryManipulator";
|
|
8
|
+
// src/markdown/MarkdownRenderer.tsx
|
|
9
|
+
var renderMarkdown = (content, options = {}) => {
|
|
10
|
+
return compileMarkdown(content, options);
|
|
11
|
+
};
|
|
12
|
+
var useMarkdownRenderer = (options = {}) => {
|
|
13
|
+
const context = useContext(MarkdownContext);
|
|
14
|
+
return (content) => {
|
|
15
|
+
if (context) return context.renderMarkdown(content, {
|
|
16
|
+
forceBlock: options.forceBlock,
|
|
17
|
+
preserveFrontmatter: options.preserveFrontmatter,
|
|
18
|
+
tagfilter: options.tagfilter
|
|
19
|
+
}, options.components, options.wrapper);
|
|
20
|
+
return renderMarkdown(content, options);
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
var MarkdownRenderer = (props) => {
|
|
24
|
+
const context = useContext(MarkdownContext);
|
|
25
|
+
const { renderMarkdown } = useMarkdown();
|
|
26
|
+
const rendered = createAsyncValue(() => [
|
|
27
|
+
props.children,
|
|
28
|
+
props.forceBlock,
|
|
29
|
+
props.preserveFrontmatter,
|
|
30
|
+
props.tagfilter,
|
|
31
|
+
props.components,
|
|
32
|
+
props.wrapper
|
|
33
|
+
], ([content, forceBlock, preserveFrontmatter, tagfilter, components, wrapper]) => renderMarkdown(content, {
|
|
34
|
+
forceBlock,
|
|
35
|
+
preserveFrontmatter,
|
|
36
|
+
tagfilter
|
|
37
|
+
}, {
|
|
38
|
+
...context?.components ?? {},
|
|
39
|
+
...components ?? {}
|
|
40
|
+
}, wrapper));
|
|
41
|
+
return <LoadingBoundary>{rendered()}</LoadingBoundary>;
|
|
42
|
+
};
|
|
43
|
+
var MarkdownMetadataRenderer = (props) => {
|
|
44
|
+
const metadata = createMemo(() => getMarkdownMetadata(props.children));
|
|
45
|
+
return createMemo(() => getContentNodeByKeyPath(metadata(), props.metadataKeyPath))();
|
|
46
|
+
};
|
|
47
|
+
export { MarkdownMetadataRenderer, MarkdownRenderer, renderMarkdown, useMarkdownRenderer };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import solidRuntime from "./runtime.jsx";
|
|
2
|
+
// src/markdown/compiler.tsx
|
|
3
|
+
/**
|
|
4
|
+
* **Step 1 of 2 — parse only (async).**
|
|
5
|
+
* Lazily imports the markdown library (enabling code splitting), then converts
|
|
6
|
+
* a raw markdown string into a `ParsedMarkdown` AST without rendering any Solid
|
|
7
|
+
* JSX. Use this when you need to:
|
|
8
|
+
* - Cache the parsed result and render it several times with different options.
|
|
9
|
+
* - Inspect or transform the AST before rendering.
|
|
10
|
+
* - Defer the render step to a later point.
|
|
11
|
+
*
|
|
12
|
+
* @param markdown - The markdown source string.
|
|
13
|
+
* @param options - Options that affect parsing (sanitizer, slugify, …).
|
|
14
|
+
* @returns A promise resolving to a `ParsedMarkdown` AST.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const ast = await parseMarkdown('# Hello **world**');
|
|
19
|
+
* const element = await compileMarkdown(ast, { forceBlock: true });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
var parseMarkdown = async (markdown = "", options = {}) => {
|
|
23
|
+
const { parseMarkdown: coreParseMarkdown } = await import("@intlayer/core/markdown");
|
|
24
|
+
const { components, namedCodesToUnicode, sanitizer, slugify, ...compilerOptions } = options;
|
|
25
|
+
return coreParseMarkdown(markdown, {
|
|
26
|
+
runtime: solidRuntime,
|
|
27
|
+
components,
|
|
28
|
+
namedCodesToUnicode,
|
|
29
|
+
sanitizer,
|
|
30
|
+
slugify
|
|
31
|
+
}, compilerOptions);
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* **Steps 1 + 2 — parse and render in one shot (async).**
|
|
35
|
+
* Lazily imports the markdown library, then accepts a raw markdown string or a
|
|
36
|
+
* pre-parsed `ParsedMarkdown` AST and returns a Solid JSX element.
|
|
37
|
+
*
|
|
38
|
+
* @param input - Markdown string or pre-parsed AST.
|
|
39
|
+
* @param options - Rendering options (custom components, sanitizer, slugify, …).
|
|
40
|
+
* @returns A promise resolving to a Solid JSX element.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const element = await compileMarkdown('# Hello **world**');
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
var compileMarkdown = async (input = "", options = {}) => {
|
|
48
|
+
if (typeof input === "string") {
|
|
49
|
+
const { compileWithOptions } = await import("@intlayer/core/markdown");
|
|
50
|
+
return compileWithOptions(input, solidRuntime, options);
|
|
51
|
+
}
|
|
52
|
+
const { renderMarkdownAst } = await import("@intlayer/core/markdown");
|
|
53
|
+
const { components, namedCodesToUnicode, sanitizer, slugify, ...compilerOptions } = options;
|
|
54
|
+
return renderMarkdownAst(input, {
|
|
55
|
+
runtime: solidRuntime,
|
|
56
|
+
components,
|
|
57
|
+
namedCodesToUnicode,
|
|
58
|
+
sanitizer,
|
|
59
|
+
slugify
|
|
60
|
+
}, compilerOptions);
|
|
61
|
+
};
|
|
62
|
+
export { compileMarkdown, parseMarkdown };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { compileMarkdown, parseMarkdown } from "./compiler.jsx";
|
|
2
|
+
import { MarkdownContext, MarkdownProvider, useMarkdown } from "./MarkdownProvider.jsx";
|
|
3
|
+
import { MarkdownMetadataRenderer, MarkdownRenderer, renderMarkdown, useMarkdownRenderer } from "./MarkdownRenderer.jsx";
|
|
4
|
+
export { MarkdownContext, MarkdownMetadataRenderer, MarkdownProvider, MarkdownRenderer, compileMarkdown, parseMarkdown, renderMarkdown, useMarkdown, useMarkdownRenderer };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { createComponent } from "solid-js";
|
|
2
|
+
// src/markdown/runtime.tsx
|
|
3
|
+
/**
|
|
4
|
+
* Solid-specific runtime for the markdown processor.
|
|
5
|
+
* Implements the MarkdownRuntime interface using Solid's primitives.
|
|
6
|
+
*/
|
|
7
|
+
var solidRuntime = {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a Solid JSX Element.
|
|
10
|
+
* Uses Solid's `Dynamic` built-in, auto-imported by the JSX compiler.
|
|
11
|
+
*/
|
|
12
|
+
createElement: (type, props, ...children) => {
|
|
13
|
+
return <Dynamic component={type} {...props ?? {}}>
|
|
14
|
+
{children.length === 1 ? children[0] : children}
|
|
15
|
+
</Dynamic>;
|
|
16
|
+
},
|
|
17
|
+
/**
|
|
18
|
+
* Solid doesn't have a built-in cloneElement like React.
|
|
19
|
+
* In the context of markdown rendering, we usually don't need to deep-clone
|
|
20
|
+
* but rather merge props if we're wrapping a result.
|
|
21
|
+
*/
|
|
22
|
+
cloneElement: (element, props) => {
|
|
23
|
+
if (typeof element === "function") return createComponent(element, props);
|
|
24
|
+
return element;
|
|
25
|
+
},
|
|
26
|
+
/**
|
|
27
|
+
* Solid Fragment equivalent.
|
|
28
|
+
* In Solid, a fragment is just an array or a function returning children.
|
|
29
|
+
*/
|
|
30
|
+
Fragment: (props) => props.children,
|
|
31
|
+
/**
|
|
32
|
+
* Solid-specific prop normalization.
|
|
33
|
+
* Solid uses 'class' instead of 'className'.
|
|
34
|
+
*/
|
|
35
|
+
normalizeProps: (_tag, props) => {
|
|
36
|
+
const normalized = {};
|
|
37
|
+
for (const [key, value] of Object.entries(props)) if (key === "className") normalized.class = value;
|
|
38
|
+
else normalized[key] = value;
|
|
39
|
+
return normalized;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
export { solidRuntime as default, solidRuntime };
|