preact-intlayer 8.4.3 → 8.4.5
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/IntlayerNode.cjs +16 -1
- package/dist/cjs/IntlayerNode.cjs.map +1 -1
- package/dist/cjs/UI/ContentSelector.cjs +96 -1
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/cjs/client/IntlayerProvider.cjs +88 -1
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -0
- package/dist/cjs/client/format/index.cjs +18 -1
- package/dist/cjs/client/format/useCompact.cjs +27 -1
- package/dist/cjs/client/format/useCompact.cjs.map +1 -1
- package/dist/cjs/client/format/useCurrency.cjs +41 -1
- package/dist/cjs/client/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/client/format/useDate.cjs +43 -1
- package/dist/cjs/client/format/useDate.cjs.map +1 -1
- package/dist/cjs/client/format/useIntl.cjs +33 -1
- package/dist/cjs/client/format/useIntl.cjs.map +1 -1
- package/dist/cjs/client/format/useList.cjs +38 -1
- package/dist/cjs/client/format/useList.cjs.map +1 -1
- package/dist/cjs/client/format/useNumber.cjs +39 -1
- package/dist/cjs/client/format/useNumber.cjs.map +1 -1
- package/dist/cjs/client/format/usePercentage.cjs +35 -1
- package/dist/cjs/client/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/client/format/useRelativeTime.cjs +35 -1
- package/dist/cjs/client/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/client/format/useUnit.cjs +34 -1
- package/dist/cjs/client/format/useUnit.cjs.map +1 -1
- package/dist/cjs/client/index.cjs +32 -1
- package/dist/cjs/client/t.cjs +19 -1
- package/dist/cjs/client/t.cjs.map +1 -1
- package/dist/cjs/client/useContent.cjs +19 -1
- package/dist/cjs/client/useContent.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +25 -1
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +22 -1
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +21 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +40 -1
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLoadDynamic.cjs +27 -1
- package/dist/cjs/client/useLoadDynamic.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +54 -1
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleBase.cjs +24 -1
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +59 -1
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
- package/dist/cjs/client/useTraduction.cjs +35 -1
- package/dist/cjs/client/useTraduction.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelector.cjs +24 -1
- package/dist/cjs/editor/ContentSelector.cjs.map +1 -1
- package/dist/cjs/editor/EditorProvider.cjs +12 -1
- package/dist/cjs/editor/EditorProvider.cjs.map +1 -0
- package/dist/cjs/editor/useEditor.cjs +38 -1
- package/dist/cjs/editor/useEditor.cjs.map +1 -0
- package/dist/cjs/getDictionary.cjs +10 -1
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +10 -1
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/html/HTMLProvider.cjs +17 -1
- package/dist/cjs/html/HTMLProvider.cjs.map +1 -1
- package/dist/cjs/html/HTMLRenderer.cjs +54 -1
- package/dist/cjs/html/HTMLRenderer.cjs.map +1 -1
- package/dist/cjs/html/index.cjs +10 -1
- package/dist/cjs/index.cjs +57 -1
- package/dist/cjs/markdown/MarkdownProvider.cjs +54 -1
- package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs +77 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs +26 -1
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs.map +1 -1
- package/dist/cjs/markdown/compiler.cjs +24 -1
- package/dist/cjs/markdown/compiler.cjs.map +1 -1
- package/dist/cjs/markdown/index.cjs +23 -1
- package/dist/cjs/markdown/runtime.cjs +18 -1
- package/dist/cjs/markdown/runtime.cjs.map +1 -1
- package/dist/cjs/plugins.cjs +222 -1
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/preactElement/renderPreactElement.cjs +42 -1
- package/dist/cjs/preactElement/renderPreactElement.cjs.map +1 -1
- package/dist/esm/IntlayerNode.mjs +14 -1
- package/dist/esm/IntlayerNode.mjs.map +1 -1
- package/dist/esm/UI/ContentSelector.mjs +94 -1
- package/dist/esm/UI/ContentSelector.mjs.map +1 -1
- package/dist/esm/client/IntlayerProvider.mjs +82 -1
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -0
- package/dist/esm/client/format/index.mjs +10 -1
- package/dist/esm/client/format/useCompact.mjs +25 -1
- package/dist/esm/client/format/useCompact.mjs.map +1 -1
- package/dist/esm/client/format/useCurrency.mjs +39 -1
- package/dist/esm/client/format/useCurrency.mjs.map +1 -1
- package/dist/esm/client/format/useDate.mjs +41 -1
- package/dist/esm/client/format/useDate.mjs.map +1 -1
- package/dist/esm/client/format/useIntl.mjs +31 -1
- package/dist/esm/client/format/useIntl.mjs.map +1 -1
- package/dist/esm/client/format/useList.mjs +36 -1
- package/dist/esm/client/format/useList.mjs.map +1 -1
- package/dist/esm/client/format/useNumber.mjs +37 -1
- package/dist/esm/client/format/useNumber.mjs.map +1 -1
- package/dist/esm/client/format/usePercentage.mjs +33 -1
- package/dist/esm/client/format/usePercentage.mjs.map +1 -1
- package/dist/esm/client/format/useRelativeTime.mjs +33 -1
- package/dist/esm/client/format/useRelativeTime.mjs.map +1 -1
- package/dist/esm/client/format/useUnit.mjs +32 -1
- package/dist/esm/client/format/useUnit.mjs.map +1 -1
- package/dist/esm/client/index.mjs +13 -1
- package/dist/esm/client/t.mjs +17 -1
- package/dist/esm/client/t.mjs.map +1 -1
- package/dist/esm/client/useContent.mjs +18 -1
- package/dist/esm/client/useContent.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +23 -1
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +19 -1
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +19 -1
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +38 -1
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLoadDynamic.mjs +25 -1
- package/dist/esm/client/useLoadDynamic.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +51 -1
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleBase.mjs +21 -1
- package/dist/esm/client/useLocaleBase.mjs.map +1 -1
- package/dist/esm/client/useLocaleStorage.mjs +52 -1
- package/dist/esm/client/useLocaleStorage.mjs.map +1 -1
- package/dist/esm/client/useTraduction.mjs +33 -1
- package/dist/esm/client/useTraduction.mjs.map +1 -1
- package/dist/esm/editor/ContentSelector.mjs +22 -1
- package/dist/esm/editor/ContentSelector.mjs.map +1 -1
- package/dist/esm/editor/EditorProvider.mjs +11 -1
- package/dist/esm/editor/EditorProvider.mjs.map +1 -0
- package/dist/esm/editor/useEditor.mjs +36 -1
- package/dist/esm/editor/useEditor.mjs.map +1 -0
- package/dist/esm/getDictionary.mjs +8 -1
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs +8 -1
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/esm/html/HTMLProvider.mjs +14 -1
- package/dist/esm/html/HTMLProvider.mjs.map +1 -1
- package/dist/esm/html/HTMLRenderer.mjs +49 -1
- package/dist/esm/html/HTMLRenderer.mjs.map +1 -1
- package/dist/esm/html/index.mjs +4 -1
- package/dist/esm/index.mjs +22 -1
- package/dist/esm/markdown/MarkdownProvider.mjs +51 -1
- package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRenderer.mjs +73 -1
- package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs +23 -1
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs.map +1 -1
- package/dist/esm/markdown/compiler.mjs +17 -1
- package/dist/esm/markdown/compiler.mjs.map +1 -1
- package/dist/esm/markdown/index.mjs +7 -1
- package/dist/esm/markdown/runtime.mjs +15 -1
- package/dist/esm/markdown/runtime.mjs.map +1 -1
- package/dist/esm/plugins.mjs +212 -1
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/preactElement/renderPreactElement.mjs +40 -1
- package/dist/esm/preactElement/renderPreactElement.mjs.map +1 -1
- package/dist/types/IntlayerNode.d.ts +23 -2
- package/dist/types/IntlayerNode.d.ts.map +1 -0
- package/dist/types/client/IntlayerProvider.d.ts +53 -2
- package/dist/types/client/IntlayerProvider.d.ts.map +1 -0
- package/dist/types/client/format/useIntl.d.ts +26 -2
- package/dist/types/client/format/useIntl.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +11 -11
- package/dist/types/client/t.d.ts +13 -2
- package/dist/types/client/t.d.ts.map +1 -0
- package/dist/types/client/useDictionary.d.ts +16 -2
- package/dist/types/client/useDictionary.d.ts.map +1 -0
- package/dist/types/client/useDictionaryAsync.d.ts +13 -2
- package/dist/types/client/useDictionaryAsync.d.ts.map +1 -0
- package/dist/types/client/useDictionaryDynamic.d.ts +16 -2
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -0
- package/dist/types/client/useIntlayer.d.ts +28 -2
- package/dist/types/client/useIntlayer.d.ts.map +1 -0
- package/dist/types/client/useLoadDynamic.d.ts +5 -2
- package/dist/types/client/useLoadDynamic.d.ts.map +1 -0
- package/dist/types/client/useLocale.d.ts +43 -2
- package/dist/types/client/useLocale.d.ts.map +1 -0
- package/dist/types/client/useLocaleBase.d.ts +16 -2
- package/dist/types/client/useLocaleBase.d.ts.map +1 -0
- package/dist/types/client/useLocaleStorage.d.ts +45 -2
- package/dist/types/client/useLocaleStorage.d.ts.map +1 -0
- package/dist/types/getDictionary.d.ts +1 -1
- package/dist/types/getIntlayer.d.ts +1 -1
- package/dist/types/html/HTMLProvider.d.ts +18 -2
- package/dist/types/html/HTMLProvider.d.ts.map +1 -0
- package/dist/types/html/HTMLRenderer.d.ts +61 -2
- package/dist/types/html/HTMLRenderer.d.ts.map +1 -0
- package/dist/types/html/index.d.ts +2 -2
- package/dist/types/html/types.d.ts +38 -2
- package/dist/types/html/types.d.ts.map +1 -0
- package/dist/types/index.d.ts +19 -19
- package/dist/types/markdown/MarkdownProvider.d.ts +52 -2
- package/dist/types/markdown/MarkdownProvider.d.ts.map +1 -0
- package/dist/types/markdown/MarkdownRenderer.d.ts +61 -2
- package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -0
- package/dist/types/markdown/MarkdownRendererPlugin.d.ts +23 -2
- package/dist/types/markdown/MarkdownRendererPlugin.d.ts.map +1 -0
- package/dist/types/markdown/compiler.d.ts +14 -2
- package/dist/types/markdown/compiler.d.ts.map +1 -0
- package/dist/types/markdown/index.d.ts +5 -5
- package/dist/types/markdown/runtime.d.ts +10 -2
- package/dist/types/markdown/runtime.d.ts.map +1 -0
- package/dist/types/plugins.d.ts +96 -2
- package/dist/types/plugins.d.ts.map +1 -0
- package/package.json +7 -7
- package/dist/cjs/IntlayerProvider-sM1gzsx7.cjs +0 -2
- package/dist/cjs/IntlayerProvider-sM1gzsx7.cjs.map +0 -1
- package/dist/esm/IntlayerProvider-ClOcEK3A.mjs +0 -2
- package/dist/esm/IntlayerProvider-ClOcEK3A.mjs.map +0 -1
- package/dist/types/HTMLProvider-8sO8DU8H.d.ts +0 -18
- package/dist/types/HTMLProvider-8sO8DU8H.d.ts.map +0 -1
- package/dist/types/HTMLRenderer-NNa_9oMD.d.ts +0 -61
- package/dist/types/HTMLRenderer-NNa_9oMD.d.ts.map +0 -1
- package/dist/types/IntlayerNode-CIzFHYnC.d.ts +0 -23
- package/dist/types/IntlayerNode-CIzFHYnC.d.ts.map +0 -1
- package/dist/types/IntlayerProvider-aV596OL4.d.ts +0 -53
- package/dist/types/IntlayerProvider-aV596OL4.d.ts.map +0 -1
- package/dist/types/MarkdownProvider-chUIO05u.d.ts +0 -52
- package/dist/types/MarkdownProvider-chUIO05u.d.ts.map +0 -1
- package/dist/types/MarkdownRenderer-BMhuurZW.d.ts +0 -61
- package/dist/types/MarkdownRenderer-BMhuurZW.d.ts.map +0 -1
- package/dist/types/MarkdownRendererPlugin-DFRVdHCA.d.ts +0 -23
- package/dist/types/MarkdownRendererPlugin-DFRVdHCA.d.ts.map +0 -1
- package/dist/types/compiler-BB0gAVbe.d.ts +0 -14
- package/dist/types/compiler-BB0gAVbe.d.ts.map +0 -1
- package/dist/types/plugins-D6OB94dO.d.ts +0 -95
- package/dist/types/plugins-D6OB94dO.d.ts.map +0 -1
- package/dist/types/runtime-BMHAtT-R.d.ts +0 -10
- package/dist/types/runtime-BMHAtT-R.d.ts.map +0 -1
- package/dist/types/t-CalXqnSB.d.ts +0 -13
- package/dist/types/t-CalXqnSB.d.ts.map +0 -1
- package/dist/types/types-B3Kzdco6.d.ts +0 -38
- package/dist/types/types-B3Kzdco6.d.ts.map +0 -1
- package/dist/types/useDictionary-cjQAc1l1.d.ts +0 -16
- package/dist/types/useDictionary-cjQAc1l1.d.ts.map +0 -1
- package/dist/types/useDictionaryAsync-CDCcBnXn.d.ts +0 -13
- package/dist/types/useDictionaryAsync-CDCcBnXn.d.ts.map +0 -1
- package/dist/types/useDictionaryDynamic-BQgaM0vp.d.ts +0 -16
- package/dist/types/useDictionaryDynamic-BQgaM0vp.d.ts.map +0 -1
- package/dist/types/useIntl-DfzrSGu4.d.ts +0 -26
- package/dist/types/useIntl-DfzrSGu4.d.ts.map +0 -1
- package/dist/types/useIntlayer-BINmW9T1.d.ts +0 -28
- package/dist/types/useIntlayer-BINmW9T1.d.ts.map +0 -1
- package/dist/types/useLoadDynamic-DFXHehpF.d.ts +0 -5
- package/dist/types/useLoadDynamic-DFXHehpF.d.ts.map +0 -1
- package/dist/types/useLocale-BDQ4yLc5.d.ts +0 -43
- package/dist/types/useLocale-BDQ4yLc5.d.ts.map +0 -1
- package/dist/types/useLocaleBase-1L1RLyXD.d.ts +0 -16
- package/dist/types/useLocaleBase-1L1RLyXD.d.ts.map +0 -1
- package/dist/types/useLocaleStorage-BwH9gqN5.d.ts +0 -45
- package/dist/types/useLocaleStorage-BwH9gqN5.d.ts.map +0 -1
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let preact = require("preact");
|
|
4
|
+
|
|
5
|
+
//#region src/IntlayerNode.tsx
|
|
6
|
+
const renderIntlayerNode = ({ children, value, additionalProps }) => {
|
|
7
|
+
const element = (0, preact.isValidElement)(children) ? children : (0, preact.h)(preact.Fragment, {}, children);
|
|
8
|
+
return new Proxy(element, { get(target, prop, receiver) {
|
|
9
|
+
if (prop === "value") return value;
|
|
10
|
+
if (additionalProps && Object.keys(additionalProps).includes(prop)) return additionalProps[prop];
|
|
11
|
+
return Reflect.get(target, prop, receiver);
|
|
12
|
+
} });
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.renderIntlayerNode = renderIntlayerNode;
|
|
2
17
|
//# sourceMappingURL=IntlayerNode.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerNode.cjs","names":["Fragment"],"sources":["../../src/IntlayerNode.tsx"],"sourcesContent":["import type { NodeProps } from '@intlayer/core/interpreter';\nimport type { ResolvedEditor } from '@intlayer/types/module_augmentation';\nimport {\n type ComponentChildren,\n Fragment,\n h,\n isValidElement,\n type VNode,\n} from 'preact';\n\nexport type IntlayerNode<\n T = NodeProps['children'],\n AdditionalProps = {},\n> = ResolvedEditor<T, VNode> & {\n value: T;\n} & AdditionalProps;\n\ntype RenderIntlayerNodeProps<T> = {\n value: T;\n children: ComponentChildren;\n additionalProps?: { [key: string]: any };\n};\n\nexport const renderIntlayerNode = <\n T extends number | string | boolean | undefined | null,\n>({\n children,\n value,\n additionalProps,\n}: RenderIntlayerNodeProps<T>): IntlayerNode<T> => {\n // If children is not a valid VNode, wrap it in a fragment\n const element: VNode<any> = isValidElement(children)\n ? children\n : h(Fragment, {}, children);\n\n // Return a Proxy that pretends to be the original element\n // but also has a .value getter.\n return new Proxy(element as VNode, {\n get(target, prop, receiver) {\n if (prop === 'value') {\n return value;\n }\n\n if (\n additionalProps &&\n Object.keys(additionalProps).includes(prop as string)\n ) {\n return additionalProps[prop as keyof typeof additionalProps];\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as IntlayerNode<T>;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"IntlayerNode.cjs","names":["Fragment"],"sources":["../../src/IntlayerNode.tsx"],"sourcesContent":["import type { NodeProps } from '@intlayer/core/interpreter';\nimport type { ResolvedEditor } from '@intlayer/types/module_augmentation';\nimport {\n type ComponentChildren,\n Fragment,\n h,\n isValidElement,\n type VNode,\n} from 'preact';\n\nexport type IntlayerNode<\n T = NodeProps['children'],\n AdditionalProps = {},\n> = ResolvedEditor<T, VNode> & {\n value: T;\n} & AdditionalProps;\n\ntype RenderIntlayerNodeProps<T> = {\n value: T;\n children: ComponentChildren;\n additionalProps?: { [key: string]: any };\n};\n\nexport const renderIntlayerNode = <\n T extends number | string | boolean | undefined | null,\n>({\n children,\n value,\n additionalProps,\n}: RenderIntlayerNodeProps<T>): IntlayerNode<T> => {\n // If children is not a valid VNode, wrap it in a fragment\n const element: VNode<any> = isValidElement(children)\n ? children\n : h(Fragment, {}, children);\n\n // Return a Proxy that pretends to be the original element\n // but also has a .value getter.\n return new Proxy(element as VNode, {\n get(target, prop, receiver) {\n if (prop === 'value') {\n return value;\n }\n\n if (\n additionalProps &&\n Object.keys(additionalProps).includes(prop as string)\n ) {\n return additionalProps[prop as keyof typeof additionalProps];\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as IntlayerNode<T>;\n};\n"],"mappings":";;;;;AAuBA,MAAa,sBAEX,EACA,UACA,OACA,sBACiD;CAEjD,MAAM,qCAAqC,SAAS,GAChD,yBACEA,iBAAU,EAAE,EAAE,SAAS;AAI7B,QAAO,IAAI,MAAM,SAAkB,EACjC,IAAI,QAAQ,MAAM,UAAU;AAC1B,MAAI,SAAS,QACX,QAAO;AAGT,MACE,mBACA,OAAO,KAAK,gBAAgB,CAAC,SAAS,KAAe,CAErD,QAAO,gBAAgB;AAGzB,SAAO,QAAQ,IAAI,QAAQ,MAAM,SAAS;IAE7C,CAAC"}
|
|
@@ -1,2 +1,97 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let preact_hooks = require("preact/hooks");
|
|
4
|
+
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
5
|
+
|
|
6
|
+
//#region src/UI/ContentSelector.tsx
|
|
7
|
+
const DEFAULT_PRESS_DETECT_DURATION = 250;
|
|
8
|
+
const ContentSelector = ({ children, onPress: onSelect, onHover, onUnhover, onClickOutside: onUnselect, pressDuration = DEFAULT_PRESS_DETECT_DURATION, isSelecting: isSelectingProp, ...props }) => {
|
|
9
|
+
const divRef = (0, preact_hooks.useRef)(null);
|
|
10
|
+
const [isHovered, setIsHovered] = (0, preact_hooks.useState)(false);
|
|
11
|
+
const [isSelectingState, setIsSelectingState] = (0, preact_hooks.useState)(isSelectingProp);
|
|
12
|
+
const pressTimerRef = (0, preact_hooks.useRef)(null);
|
|
13
|
+
const isChildrenString = typeof children === "string";
|
|
14
|
+
const handleOnLongPress = () => {
|
|
15
|
+
setIsSelectingState(true);
|
|
16
|
+
onSelect();
|
|
17
|
+
};
|
|
18
|
+
const startPressTimer = () => {
|
|
19
|
+
pressTimerRef.current = setTimeout(() => {
|
|
20
|
+
handleOnLongPress();
|
|
21
|
+
}, pressDuration);
|
|
22
|
+
};
|
|
23
|
+
const clearPressTimer = () => {
|
|
24
|
+
if (pressTimerRef.current) {
|
|
25
|
+
clearTimeout(pressTimerRef.current);
|
|
26
|
+
pressTimerRef.current = null;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const handleMouseDown = () => {
|
|
30
|
+
clearPressTimer();
|
|
31
|
+
startPressTimer();
|
|
32
|
+
};
|
|
33
|
+
const handleMouseEnter = () => {
|
|
34
|
+
setIsHovered(true);
|
|
35
|
+
onHover?.();
|
|
36
|
+
};
|
|
37
|
+
const handleMouseUp = () => {
|
|
38
|
+
if (isHovered) {
|
|
39
|
+
setIsHovered(false);
|
|
40
|
+
onUnhover?.();
|
|
41
|
+
}
|
|
42
|
+
clearPressTimer();
|
|
43
|
+
};
|
|
44
|
+
const handleClickOutside = (0, preact_hooks.useCallback)((event) => {
|
|
45
|
+
if (divRef.current && !divRef.current.contains(event.target)) {
|
|
46
|
+
setIsSelectingState(false);
|
|
47
|
+
onUnselect?.();
|
|
48
|
+
}
|
|
49
|
+
}, [onUnselect]);
|
|
50
|
+
(0, preact_hooks.useEffect)(() => {
|
|
51
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
52
|
+
return () => {
|
|
53
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
54
|
+
};
|
|
55
|
+
}, [handleClickOutside]);
|
|
56
|
+
const handleOnClick = (e) => {
|
|
57
|
+
if (isSelectingState) {
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
e.stopPropagation();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const handleOnBlur = () => {
|
|
63
|
+
setIsSelectingState(false);
|
|
64
|
+
};
|
|
65
|
+
return /* @__PURE__ */ (0, preact_jsx_runtime.jsx)("span", {
|
|
66
|
+
style: {
|
|
67
|
+
display: isChildrenString ? "inline" : "inline-block",
|
|
68
|
+
cursor: "pointer",
|
|
69
|
+
userSelect: "none",
|
|
70
|
+
borderRadius: "0.375rem",
|
|
71
|
+
outlineWidth: "2px",
|
|
72
|
+
outlineOffset: "4px",
|
|
73
|
+
outlineStyle: "solid",
|
|
74
|
+
outlineColor: isSelectingProp || isSelectingState || isHovered ? "inherit" : "transparent",
|
|
75
|
+
transition: "all 100ms 50ms ease-in-out"
|
|
76
|
+
},
|
|
77
|
+
role: "button",
|
|
78
|
+
tabIndex: 0,
|
|
79
|
+
onKeyUp: () => null,
|
|
80
|
+
onClick: handleOnClick,
|
|
81
|
+
onMouseDown: handleMouseDown,
|
|
82
|
+
onMouseUp: handleMouseUp,
|
|
83
|
+
onMouseLeave: handleMouseUp,
|
|
84
|
+
onTouchStart: handleMouseDown,
|
|
85
|
+
onTouchEnd: handleMouseUp,
|
|
86
|
+
onTouchCancel: handleMouseUp,
|
|
87
|
+
onBlur: handleOnBlur,
|
|
88
|
+
onMouseEnter: handleMouseEnter,
|
|
89
|
+
ref: divRef,
|
|
90
|
+
...props,
|
|
91
|
+
children
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
exports.ContentSelector = ContentSelector;
|
|
2
97
|
//# sourceMappingURL=ContentSelector.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSelector.cjs","names":[],"sources":["../../../src/UI/ContentSelector.tsx"],"sourcesContent":["import type { FunctionalComponent, JSX } from 'preact';\nimport { useCallback, useEffect, useRef, useState } from 'preact/hooks';\n\nconst DEFAULT_PRESS_DETECT_DURATION = 250;\n\ntype ContentSelectorProps = {\n onPress: () => void;\n onHover?: () => void;\n onUnhover?: () => void;\n onClickOutside?: () => void;\n pressDuration?: number;\n isSelecting?: boolean;\n} & Omit<JSX.HTMLAttributes<HTMLDivElement>, 'content'>;\n\nexport const ContentSelector: FunctionalComponent<ContentSelectorProps> = ({\n children,\n onPress: onSelect,\n onHover,\n onUnhover,\n onClickOutside: onUnselect,\n pressDuration = DEFAULT_PRESS_DETECT_DURATION,\n isSelecting: isSelectingProp,\n ...props\n}) => {\n const divRef = useRef<HTMLDivElement>(null);\n const [isHovered, setIsHovered] = useState(false);\n const [isSelectingState, setIsSelectingState] = useState(isSelectingProp);\n const pressTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const isChildrenString = typeof children === 'string';\n\n const handleOnLongPress = () => {\n setIsSelectingState(true);\n onSelect();\n };\n\n const startPressTimer = () => {\n pressTimerRef.current = setTimeout(() => {\n handleOnLongPress();\n }, pressDuration);\n };\n\n const clearPressTimer = () => {\n if (pressTimerRef.current) {\n clearTimeout(pressTimerRef.current);\n pressTimerRef.current = null;\n }\n };\n\n const handleMouseDown = () => {\n clearPressTimer(); // Ensure any previous timer is cleared\n startPressTimer();\n };\n\n const handleMouseEnter = () => {\n setIsHovered(true);\n onHover?.();\n };\n\n const handleMouseUp = () => {\n if (isHovered) {\n setIsHovered(false);\n onUnhover?.();\n }\n clearPressTimer();\n };\n\n // Use useCallback to ensure the function identity remains stable\n const handleClickOutside = useCallback(\n (event: MouseEvent) => {\n if (divRef.current && !divRef.current.contains(event.target as Node)) {\n setIsSelectingState(false);\n onUnselect?.();\n }\n },\n [onUnselect]\n );\n\n useEffect(() => {\n // Attach click outside listener\n document.addEventListener('mousedown', handleClickOutside);\n\n return () => {\n // Cleanup\n document.removeEventListener('mousedown', handleClickOutside);\n // clearPressTimer(); // Ensure to clear the timer when component unmounts\n };\n }, [handleClickOutside]);\n\n const handleOnClick: JSX.MouseEventHandler<HTMLDivElement> = (e) => {\n if (isSelectingState) {\n e.preventDefault();\n e.stopPropagation();\n }\n };\n\n const handleOnBlur = () => {\n // Stop editing when the element loses focus\n setIsSelectingState(false);\n };\n\n return (\n <span\n style={{\n display: isChildrenString ? 'inline' : 'inline-block',\n cursor: 'pointer',\n userSelect: 'none',\n borderRadius: '0.375rem',\n outlineWidth: '2px',\n outlineOffset: '4px',\n outlineStyle: 'solid',\n outlineColor:\n isSelectingProp || isSelectingState || isHovered\n ? 'inherit'\n : 'transparent',\n transition: 'all 100ms 50ms ease-in-out',\n }}\n role=\"button\"\n tabIndex={0}\n onKeyUp={() => null}\n onClick={handleOnClick}\n onMouseDown={handleMouseDown}\n onMouseUp={handleMouseUp}\n onMouseLeave={handleMouseUp}\n onTouchStart={handleMouseDown}\n onTouchEnd={handleMouseUp}\n onTouchCancel={handleMouseUp}\n onBlur={handleOnBlur}\n onMouseEnter={handleMouseEnter}\n ref={divRef}\n {...props}\n >\n {children}\n </span>\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ContentSelector.cjs","names":[],"sources":["../../../src/UI/ContentSelector.tsx"],"sourcesContent":["import type { FunctionalComponent, JSX } from 'preact';\nimport { useCallback, useEffect, useRef, useState } from 'preact/hooks';\n\nconst DEFAULT_PRESS_DETECT_DURATION = 250;\n\ntype ContentSelectorProps = {\n onPress: () => void;\n onHover?: () => void;\n onUnhover?: () => void;\n onClickOutside?: () => void;\n pressDuration?: number;\n isSelecting?: boolean;\n} & Omit<JSX.HTMLAttributes<HTMLDivElement>, 'content'>;\n\nexport const ContentSelector: FunctionalComponent<ContentSelectorProps> = ({\n children,\n onPress: onSelect,\n onHover,\n onUnhover,\n onClickOutside: onUnselect,\n pressDuration = DEFAULT_PRESS_DETECT_DURATION,\n isSelecting: isSelectingProp,\n ...props\n}) => {\n const divRef = useRef<HTMLDivElement>(null);\n const [isHovered, setIsHovered] = useState(false);\n const [isSelectingState, setIsSelectingState] = useState(isSelectingProp);\n const pressTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const isChildrenString = typeof children === 'string';\n\n const handleOnLongPress = () => {\n setIsSelectingState(true);\n onSelect();\n };\n\n const startPressTimer = () => {\n pressTimerRef.current = setTimeout(() => {\n handleOnLongPress();\n }, pressDuration);\n };\n\n const clearPressTimer = () => {\n if (pressTimerRef.current) {\n clearTimeout(pressTimerRef.current);\n pressTimerRef.current = null;\n }\n };\n\n const handleMouseDown = () => {\n clearPressTimer(); // Ensure any previous timer is cleared\n startPressTimer();\n };\n\n const handleMouseEnter = () => {\n setIsHovered(true);\n onHover?.();\n };\n\n const handleMouseUp = () => {\n if (isHovered) {\n setIsHovered(false);\n onUnhover?.();\n }\n clearPressTimer();\n };\n\n // Use useCallback to ensure the function identity remains stable\n const handleClickOutside = useCallback(\n (event: MouseEvent) => {\n if (divRef.current && !divRef.current.contains(event.target as Node)) {\n setIsSelectingState(false);\n onUnselect?.();\n }\n },\n [onUnselect]\n );\n\n useEffect(() => {\n // Attach click outside listener\n document.addEventListener('mousedown', handleClickOutside);\n\n return () => {\n // Cleanup\n document.removeEventListener('mousedown', handleClickOutside);\n // clearPressTimer(); // Ensure to clear the timer when component unmounts\n };\n }, [handleClickOutside]);\n\n const handleOnClick: JSX.MouseEventHandler<HTMLDivElement> = (e) => {\n if (isSelectingState) {\n e.preventDefault();\n e.stopPropagation();\n }\n };\n\n const handleOnBlur = () => {\n // Stop editing when the element loses focus\n setIsSelectingState(false);\n };\n\n return (\n <span\n style={{\n display: isChildrenString ? 'inline' : 'inline-block',\n cursor: 'pointer',\n userSelect: 'none',\n borderRadius: '0.375rem',\n outlineWidth: '2px',\n outlineOffset: '4px',\n outlineStyle: 'solid',\n outlineColor:\n isSelectingProp || isSelectingState || isHovered\n ? 'inherit'\n : 'transparent',\n transition: 'all 100ms 50ms ease-in-out',\n }}\n role=\"button\"\n tabIndex={0}\n onKeyUp={() => null}\n onClick={handleOnClick}\n onMouseDown={handleMouseDown}\n onMouseUp={handleMouseUp}\n onMouseLeave={handleMouseUp}\n onTouchStart={handleMouseDown}\n onTouchEnd={handleMouseUp}\n onTouchCancel={handleMouseUp}\n onBlur={handleOnBlur}\n onMouseEnter={handleMouseEnter}\n ref={divRef}\n {...props}\n >\n {children}\n </span>\n );\n};\n"],"mappings":";;;;;;AAGA,MAAM,gCAAgC;AAWtC,MAAa,mBAA8D,EACzE,UACA,SAAS,UACT,SACA,WACA,gBAAgB,YAChB,gBAAgB,+BAChB,aAAa,iBACb,GAAG,YACC;CACJ,MAAM,kCAAgC,KAAK;CAC3C,MAAM,CAAC,WAAW,2CAAyB,MAAM;CACjD,MAAM,CAAC,kBAAkB,kDAAgC,gBAAgB;CACzE,MAAM,yCAA6D,KAAK;CACxE,MAAM,mBAAmB,OAAO,aAAa;CAE7C,MAAM,0BAA0B;AAC9B,sBAAoB,KAAK;AACzB,YAAU;;CAGZ,MAAM,wBAAwB;AAC5B,gBAAc,UAAU,iBAAiB;AACvC,sBAAmB;KAClB,cAAc;;CAGnB,MAAM,wBAAwB;AAC5B,MAAI,cAAc,SAAS;AACzB,gBAAa,cAAc,QAAQ;AACnC,iBAAc,UAAU;;;CAI5B,MAAM,wBAAwB;AAC5B,mBAAiB;AACjB,mBAAiB;;CAGnB,MAAM,yBAAyB;AAC7B,eAAa,KAAK;AAClB,aAAW;;CAGb,MAAM,sBAAsB;AAC1B,MAAI,WAAW;AACb,gBAAa,MAAM;AACnB,gBAAa;;AAEf,mBAAiB;;CAInB,MAAM,oDACH,UAAsB;AACrB,MAAI,OAAO,WAAW,CAAC,OAAO,QAAQ,SAAS,MAAM,OAAe,EAAE;AACpE,uBAAoB,MAAM;AAC1B,iBAAc;;IAGlB,CAAC,WAAW,CACb;AAED,mCAAgB;AAEd,WAAS,iBAAiB,aAAa,mBAAmB;AAE1D,eAAa;AAEX,YAAS,oBAAoB,aAAa,mBAAmB;;IAG9D,CAAC,mBAAmB,CAAC;CAExB,MAAM,iBAAwD,MAAM;AAClE,MAAI,kBAAkB;AACpB,KAAE,gBAAgB;AAClB,KAAE,iBAAiB;;;CAIvB,MAAM,qBAAqB;AAEzB,sBAAoB,MAAM;;AAG5B,QACE,4CAAC,QAAD;EACE,OAAO;GACL,SAAS,mBAAmB,WAAW;GACvC,QAAQ;GACR,YAAY;GACZ,cAAc;GACd,cAAc;GACd,eAAe;GACf,cAAc;GACd,cACE,mBAAmB,oBAAoB,YACnC,YACA;GACN,YAAY;GACb;EACD,MAAK;EACL,UAAU;EACV,eAAe;EACf,SAAS;EACT,aAAa;EACb,WAAW;EACX,cAAc;EACd,cAAc;EACd,YAAY;EACZ,eAAe;EACf,QAAQ;EACR,cAAc;EACd,KAAK;EACL,GAAI;EAEH;EACI"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
|
|
29
|
+
exports.__toESM = __toESM;
|
|
@@ -1 +1,88 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_editor_EditorProvider = require('../editor/EditorProvider.cjs');
|
|
4
|
+
const require_client_useLocaleStorage = require('./useLocaleStorage.cjs');
|
|
5
|
+
let _intlayer_config_built = require("@intlayer/config/built");
|
|
6
|
+
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
7
|
+
let preact = require("preact");
|
|
8
|
+
let preact_hooks = require("preact/hooks");
|
|
9
|
+
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
10
|
+
let _intlayer_core_localization = require("@intlayer/core/localization");
|
|
11
|
+
|
|
12
|
+
//#region src/client/IntlayerProvider.tsx
|
|
13
|
+
/**
|
|
14
|
+
* Context that store the current locale on the client side
|
|
15
|
+
*/
|
|
16
|
+
const IntlayerClientContext = (0, preact.createContext)({
|
|
17
|
+
locale: require_client_useLocaleStorage.localeInStorage ?? _intlayer_config_built.default?.internationalization?.defaultLocale,
|
|
18
|
+
setLocale: () => null
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Hook that provides the current locale
|
|
22
|
+
*/
|
|
23
|
+
const useIntlayerContext = () => (0, preact_hooks.useContext)(IntlayerClientContext);
|
|
24
|
+
/**
|
|
25
|
+
* Provider that store the current locale on the client side
|
|
26
|
+
*/
|
|
27
|
+
const IntlayerProviderContent = ({ locale: localeProp, defaultLocale: defaultLocaleProp, children, setLocale: setLocaleProp, isCookieEnabled }) => {
|
|
28
|
+
const { internationalization } = _intlayer_config_built.default ?? {};
|
|
29
|
+
const { defaultLocale: defaultLocaleConfig, locales: availableLocales } = internationalization ?? {};
|
|
30
|
+
const [currentLocale, setCurrentLocale] = (0, preact_hooks.useState)(localeProp ?? require_client_useLocaleStorage.localeInStorage ?? defaultLocaleProp ?? defaultLocaleConfig);
|
|
31
|
+
(0, preact_hooks.useEffect)(() => {
|
|
32
|
+
if (localeProp && localeProp !== currentLocale) setCurrentLocale(localeProp);
|
|
33
|
+
}, [
|
|
34
|
+
localeProp,
|
|
35
|
+
currentLocale,
|
|
36
|
+
setCurrentLocale
|
|
37
|
+
]);
|
|
38
|
+
const setLocaleBase = (newLocale) => {
|
|
39
|
+
if (currentLocale.toString() === newLocale.toString()) return;
|
|
40
|
+
if (!availableLocales?.map(String).includes(newLocale)) {
|
|
41
|
+
console.error(`Locale ${newLocale} is not available`);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
setCurrentLocale(newLocale);
|
|
45
|
+
require_client_useLocaleStorage.setLocaleInStorage(newLocale, isCookieEnabled ?? true);
|
|
46
|
+
};
|
|
47
|
+
const setLocale = setLocaleProp ?? setLocaleBase;
|
|
48
|
+
const resolvedLocale = (0, _intlayer_core_localization.localeResolver)(localeProp ?? currentLocale);
|
|
49
|
+
return /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(IntlayerClientContext.Provider, {
|
|
50
|
+
value: {
|
|
51
|
+
locale: resolvedLocale,
|
|
52
|
+
setLocale,
|
|
53
|
+
isCookieEnabled
|
|
54
|
+
},
|
|
55
|
+
children
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Main provider for Intlayer in Preact applications.
|
|
60
|
+
*
|
|
61
|
+
* It provides the Intlayer context to your application, allowing the use
|
|
62
|
+
* of hooks like `useIntlayer` and `useLocale`.
|
|
63
|
+
*
|
|
64
|
+
* @param props - The provider props.
|
|
65
|
+
* @returns The provider component.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```tsx
|
|
69
|
+
* import { IntlayerProvider } from 'preact-intlayer';
|
|
70
|
+
*
|
|
71
|
+
* const App = () => (
|
|
72
|
+
* <IntlayerProvider>
|
|
73
|
+
* <MyComponent />
|
|
74
|
+
* </IntlayerProvider>
|
|
75
|
+
* );
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
const IntlayerProvider = ({ children, ...props }) => /* @__PURE__ */ (0, preact_jsx_runtime.jsxs)(IntlayerProviderContent, {
|
|
79
|
+
...props,
|
|
80
|
+
children: [/* @__PURE__ */ (0, preact_jsx_runtime.jsx)(require_editor_EditorProvider.EditorProvider, {}), children]
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
//#endregion
|
|
84
|
+
exports.IntlayerClientContext = IntlayerClientContext;
|
|
85
|
+
exports.IntlayerProvider = IntlayerProvider;
|
|
86
|
+
exports.IntlayerProviderContent = IntlayerProviderContent;
|
|
87
|
+
exports.useIntlayerContext = useIntlayerContext;
|
|
88
|
+
//# sourceMappingURL=IntlayerProvider.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntlayerProvider.cjs","names":["localeInStorage","configuration","EditorProvider"],"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { localeResolver } from '@intlayer/core/localization';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport {\n type ComponentChild,\n createContext,\n type FunctionComponent,\n} from 'preact';\nimport { useContext, useEffect, useState } from 'preact/hooks';\nimport { EditorProvider } from '../editor/EditorProvider';\nimport { localeInStorage, setLocaleInStorage } from './useLocaleStorage';\n\ntype IntlayerValue = {\n locale: LocalesValues;\n setLocale: (newLocale: LocalesValues) => void;\n isCookieEnabled?: boolean;\n};\n\n/**\n * Context that store the current locale on the client side\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeInStorage ?? configuration?.internationalization?.defaultLocale,\n setLocale: () => null,\n});\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\nexport type IntlayerProviderProps = {\n children?: ComponentChild;\n locale?: LocalesValues;\n defaultLocale?: LocalesValues;\n setLocale?: (locale: LocalesValues) => void;\n isCookieEnabled?: boolean;\n};\n\n/**\n * Provider that store the current locale on the client side\n */\nexport const IntlayerProviderContent: FunctionComponent<\n IntlayerProviderProps\n> = ({\n locale: localeProp,\n defaultLocale: defaultLocaleProp,\n children,\n setLocale: setLocaleProp,\n isCookieEnabled,\n}) => {\n const { internationalization } = configuration ?? {};\n const { defaultLocale: defaultLocaleConfig, locales: availableLocales } =\n internationalization ?? {};\n\n const defaultLocale =\n localeProp ?? localeInStorage ?? defaultLocaleProp ?? defaultLocaleConfig;\n\n const [currentLocale, setCurrentLocale] = useState<LocalesValues>(\n defaultLocale as LocalesValues\n );\n\n useEffect(() => {\n if (localeProp && localeProp !== currentLocale) {\n setCurrentLocale(localeProp);\n }\n }, [localeProp, currentLocale, setCurrentLocale]);\n\n const setLocaleBase = (newLocale: LocalesValues) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales?.map(String).includes(newLocale)) {\n console.error(`Locale ${newLocale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale); // Update state\n setLocaleInStorage(newLocale, isCookieEnabled ?? true); // Optionally set cookie for persistence\n };\n\n const setLocale = setLocaleProp ?? setLocaleBase;\n\n const resolvedLocale = localeResolver(localeProp ?? currentLocale);\n\n return (\n <IntlayerClientContext.Provider\n value={{\n locale: resolvedLocale,\n setLocale,\n isCookieEnabled,\n }}\n >\n {children}\n </IntlayerClientContext.Provider>\n );\n};\n\n/**\n * Main provider for Intlayer in Preact applications.\n *\n * It provides the Intlayer context to your application, allowing the use\n * of hooks like `useIntlayer` and `useLocale`.\n *\n * @param props - The provider props.\n * @returns The provider component.\n *\n * @example\n * ```tsx\n * import { IntlayerProvider } from 'preact-intlayer';\n *\n * const App = () => (\n * <IntlayerProvider>\n * <MyComponent />\n * </IntlayerProvider>\n * );\n * ```\n */\nexport const IntlayerProvider: FunctionComponent<IntlayerProviderProps> = ({\n children,\n ...props\n}) => (\n <IntlayerProviderContent {...props}>\n <EditorProvider />\n {children}\n </IntlayerProviderContent>\n);\n"],"mappings":";;;;;;;;;;;;;;;AAqBA,MAAa,kDAAqD;CAChE,QAAQA,mDAAmBC,gCAAe,sBAAsB;CAChE,iBAAiB;CAClB,CAAC;;;;AAKF,MAAa,wDAAsC,sBAAsB;;;;AAazE,MAAa,2BAER,EACH,QAAQ,YACR,eAAe,mBACf,UACA,WAAW,eACX,sBACI;CACJ,MAAM,EAAE,yBAAyBA,kCAAiB,EAAE;CACpD,MAAM,EAAE,eAAe,qBAAqB,SAAS,qBACnD,wBAAwB,EAAE;CAK5B,MAAM,CAAC,eAAe,+CAFpB,cAAcD,mDAAmB,qBAAqB,oBAIvD;AAED,mCAAgB;AACd,MAAI,cAAc,eAAe,cAC/B,kBAAiB,WAAW;IAE7B;EAAC;EAAY;EAAe;EAAiB,CAAC;CAEjD,MAAM,iBAAiB,cAA6B;AAClD,MAAI,cAAc,UAAU,KAAK,UAAU,UAAU,CAAE;AAEvD,MAAI,CAAC,kBAAkB,IAAI,OAAO,CAAC,SAAS,UAAU,EAAE;AACtD,WAAQ,MAAM,UAAU,UAAU,mBAAmB;AACrD;;AAGF,mBAAiB,UAAU;AAC3B,qDAAmB,WAAW,mBAAmB,KAAK;;CAGxD,MAAM,YAAY,iBAAiB;CAEnC,MAAM,iEAAgC,cAAc,cAAc;AAElE,QACE,4CAAC,sBAAsB,UAAvB;EACE,OAAO;GACL,QAAQ;GACR;GACA;GACD;EAEA;EAC8B;;;;;;;;;;;;;;;;;;;;;;AAwBrC,MAAa,oBAA8D,EACzE,UACA,GAAG,YAEH,6CAAC,yBAAD;CAAyB,GAAI;WAA7B,CACE,4CAACE,8CAAD,EAAkB,GACjB,SACuB"}
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_client_format_useUnit = require('./useUnit.cjs');
|
|
3
|
+
const require_client_format_useDate = require('./useDate.cjs');
|
|
4
|
+
const require_client_format_useNumber = require('./useNumber.cjs');
|
|
5
|
+
const require_client_format_useRelativeTime = require('./useRelativeTime.cjs');
|
|
6
|
+
const require_client_format_useCompact = require('./useCompact.cjs');
|
|
7
|
+
const require_client_format_useList = require('./useList.cjs');
|
|
8
|
+
const require_client_format_usePercentage = require('./usePercentage.cjs');
|
|
9
|
+
const require_client_format_useCurrency = require('./useCurrency.cjs');
|
|
10
|
+
|
|
11
|
+
exports.useCompact = require_client_format_useCompact.useCompact;
|
|
12
|
+
exports.useCurrency = require_client_format_useCurrency.useCurrency;
|
|
13
|
+
exports.useDate = require_client_format_useDate.useDate;
|
|
14
|
+
exports.useList = require_client_format_useList.useList;
|
|
15
|
+
exports.useNumber = require_client_format_useNumber.useNumber;
|
|
16
|
+
exports.usePercentage = require_client_format_usePercentage.usePercentage;
|
|
17
|
+
exports.useRelativeTime = require_client_format_useRelativeTime.useRelativeTime;
|
|
18
|
+
exports.useUnit = require_client_format_useUnit.useUnit;
|
|
@@ -1,2 +1,28 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_client_IntlayerProvider = require('../IntlayerProvider.cjs');
|
|
4
|
+
let preact_hooks = require("preact/hooks");
|
|
5
|
+
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
6
|
+
|
|
7
|
+
//#region src/client/format/useCompact.ts
|
|
8
|
+
/**
|
|
9
|
+
* React client hook that provides a compact number formatter
|
|
10
|
+
* bound to the current application locale.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* const formatCompact = useCompact();
|
|
15
|
+
* formatCompact(1500); // "1.5K"
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
const useCompact = () => {
|
|
19
|
+
const { locale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
20
|
+
return (0, preact_hooks.useCallback)((...args) => (0, _intlayer_core_formatters.compact)(args[0], {
|
|
21
|
+
...args[1],
|
|
22
|
+
locale: args[1]?.locale ?? locale
|
|
23
|
+
}), [locale]);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
exports.useCompact = useCompact;
|
|
2
28
|
//# sourceMappingURL=useCompact.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCompact.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useCompact.ts"],"sourcesContent":["import { compact } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a compact number formatter\n * bound to the current application locale.\n *\n * @example\n * ```tsx\n * const formatCompact = useCompact();\n * formatCompact(1500); // \"1.5K\"\n * ```\n */\nexport const useCompact = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof compact>) =>\n compact(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useCompact.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useCompact.ts"],"sourcesContent":["import { compact } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a compact number formatter\n * bound to the current application locale.\n *\n * @example\n * ```tsx\n * const formatCompact = useCompact();\n * formatCompact(1500); // \"1.5K\"\n * ```\n */\nexport const useCompact = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof compact>) =>\n compact(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAcA,MAAa,mBAAmB;CAC9B,MAAM,EAAE,wCAAsBA,sDAAsB;AAEpD,uCACG,GAAG,gDACM,KAAK,IAAI;EACf,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC,EACJ,CAAC,OAAO,CACT"}
|
|
@@ -1,2 +1,42 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_client_IntlayerProvider = require('../IntlayerProvider.cjs');
|
|
4
|
+
let preact_hooks = require("preact/hooks");
|
|
5
|
+
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
6
|
+
|
|
7
|
+
//#region src/client/format/useCurrency.ts
|
|
8
|
+
/**
|
|
9
|
+
* React client hook that provides a currency formatter
|
|
10
|
+
* bound to the current application locale.
|
|
11
|
+
*
|
|
12
|
+
* @returns {(value: string | number, options?: CurrencyProps) => string}
|
|
13
|
+
* A function to format numbers into localized currency strings.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* const formatCurrency = useCurrency();
|
|
18
|
+
*
|
|
19
|
+
* formatCurrency(1500, { currency: "USD" });
|
|
20
|
+
* // "$1,500.00"
|
|
21
|
+
*
|
|
22
|
+
* formatCurrency(1500, { currency: "EUR", locale: "de-DE" });
|
|
23
|
+
* // "1.500,00 €"
|
|
24
|
+
*
|
|
25
|
+
* formatCurrency(9876543.21, {
|
|
26
|
+
* currency: "JPY",
|
|
27
|
+
* fractionDigits: 0,
|
|
28
|
+
* });
|
|
29
|
+
* // "¥9,876,543"
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
const useCurrency = () => {
|
|
33
|
+
const { locale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
34
|
+
return (0, preact_hooks.useCallback)((...args) => (0, _intlayer_core_formatters.currency)(args[0], {
|
|
35
|
+
...args[1],
|
|
36
|
+
locale: args[1]?.locale ?? locale
|
|
37
|
+
}), [locale]);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
exports.useCurrency = useCurrency;
|
|
2
42
|
//# sourceMappingURL=useCurrency.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCurrency.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useCurrency.ts"],"sourcesContent":["import { currency } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a currency formatter\n * bound to the current application locale.\n *\n * @returns {(value: string | number, options?: CurrencyProps) => string}\n * A function to format numbers into localized currency strings.\n *\n * @example\n * ```tsx\n * const formatCurrency = useCurrency();\n *\n * formatCurrency(1500, { currency: \"USD\" });\n * // \"$1,500.00\"\n *\n * formatCurrency(1500, { currency: \"EUR\", locale: \"de-DE\" });\n * // \"1.500,00 €\"\n *\n * formatCurrency(9876543.21, {\n * currency: \"JPY\",\n * fractionDigits: 0,\n * });\n * // \"¥9,876,543\"\n * ```\n */\nexport const useCurrency = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof currency>) =>\n currency(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useCurrency.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useCurrency.ts"],"sourcesContent":["import { currency } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a currency formatter\n * bound to the current application locale.\n *\n * @returns {(value: string | number, options?: CurrencyProps) => string}\n * A function to format numbers into localized currency strings.\n *\n * @example\n * ```tsx\n * const formatCurrency = useCurrency();\n *\n * formatCurrency(1500, { currency: \"USD\" });\n * // \"$1,500.00\"\n *\n * formatCurrency(1500, { currency: \"EUR\", locale: \"de-DE\" });\n * // \"1.500,00 €\"\n *\n * formatCurrency(9876543.21, {\n * currency: \"JPY\",\n * fractionDigits: 0,\n * });\n * // \"¥9,876,543\"\n * ```\n */\nexport const useCurrency = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof currency>) =>\n currency(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAa,oBAAoB;CAC/B,MAAM,EAAE,wCAAsBA,sDAAsB;AAEpD,uCACG,GAAG,iDACO,KAAK,IAAI;EAChB,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC,EACJ,CAAC,OAAO,CACT"}
|
|
@@ -1,2 +1,44 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_client_IntlayerProvider = require('../IntlayerProvider.cjs');
|
|
4
|
+
let preact_hooks = require("preact/hooks");
|
|
5
|
+
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
6
|
+
|
|
7
|
+
//#region src/client/format/useDate.ts
|
|
8
|
+
/**
|
|
9
|
+
* React client hook that provides a localized date/time formatter
|
|
10
|
+
* bound to the current application locale.
|
|
11
|
+
*
|
|
12
|
+
* @returns {(date: Date | string | number, options?: DateProps) => string}
|
|
13
|
+
* A function to format dates or timestamps into localized date/time strings.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* const formatDate = useDate();
|
|
18
|
+
*
|
|
19
|
+
* formatDate(new Date("2025-01-01"));
|
|
20
|
+
* // "Jan 1, 2025"
|
|
21
|
+
*
|
|
22
|
+
* formatDate("2025-01-01T15:30:00Z", {
|
|
23
|
+
* dateStyle: "full",
|
|
24
|
+
* timeStyle: "short",
|
|
25
|
+
* });
|
|
26
|
+
* // "Wednesday, January 1, 2025 at 3:30 PM"
|
|
27
|
+
*
|
|
28
|
+
* formatDate(1735689600000, { locale: "fr-FR", dateStyle: "long" });
|
|
29
|
+
* // "1 janvier 2025"
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @see createDate
|
|
33
|
+
*/
|
|
34
|
+
const useDate = () => {
|
|
35
|
+
const { locale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
36
|
+
return (...args) => (0, _intlayer_core_formatters.date)(args[0], {
|
|
37
|
+
...args[1],
|
|
38
|
+
locale: args[1]?.locale ?? locale
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
exports.useDate = useDate;
|
|
2
44
|
//# sourceMappingURL=useDate.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDate.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useDate.ts"],"sourcesContent":["import { date } from '@intlayer/core/formatters';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a localized date/time formatter\n * bound to the current application locale.\n *\n * @returns {(date: Date | string | number, options?: DateProps) => string}\n * A function to format dates or timestamps into localized date/time strings.\n *\n * @example\n * ```tsx\n * const formatDate = useDate();\n *\n * formatDate(new Date(\"2025-01-01\"));\n * // \"Jan 1, 2025\"\n *\n * formatDate(\"2025-01-01T15:30:00Z\", {\n * dateStyle: \"full\",\n * timeStyle: \"short\",\n * });\n * // \"Wednesday, January 1, 2025 at 3:30 PM\"\n *\n * formatDate(1735689600000, { locale: \"fr-FR\", dateStyle: \"long\" });\n * // \"1 janvier 2025\"\n * ```\n *\n * @see createDate\n */\nexport const useDate = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return (...args: Parameters<typeof date>) =>\n date(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDate.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useDate.ts"],"sourcesContent":["import { date } from '@intlayer/core/formatters';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a localized date/time formatter\n * bound to the current application locale.\n *\n * @returns {(date: Date | string | number, options?: DateProps) => string}\n * A function to format dates or timestamps into localized date/time strings.\n *\n * @example\n * ```tsx\n * const formatDate = useDate();\n *\n * formatDate(new Date(\"2025-01-01\"));\n * // \"Jan 1, 2025\"\n *\n * formatDate(\"2025-01-01T15:30:00Z\", {\n * dateStyle: \"full\",\n * timeStyle: \"short\",\n * });\n * // \"Wednesday, January 1, 2025 at 3:30 PM\"\n *\n * formatDate(1735689600000, { locale: \"fr-FR\", dateStyle: \"long\" });\n * // \"1 janvier 2025\"\n * ```\n *\n * @see createDate\n */\nexport const useDate = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return (...args: Parameters<typeof date>) =>\n date(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAa,gBAAgB;CAC3B,MAAM,EAAE,wCAAsBA,sDAAsB;AAEpD,SAAQ,GAAG,6CACJ,KAAK,IAAI;EACZ,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC"}
|
|
@@ -1,2 +1,34 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_client_IntlayerProvider = require('../IntlayerProvider.cjs');
|
|
4
|
+
let preact_hooks = require("preact/hooks");
|
|
5
|
+
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
6
|
+
|
|
7
|
+
//#region src/client/format/useIntl.ts
|
|
8
|
+
/**
|
|
9
|
+
* Preact client hook that provides a locale-bound `Intl` object.
|
|
10
|
+
*
|
|
11
|
+
* It acts exactly like the native `Intl` object, but acts as a proxy to:
|
|
12
|
+
* 1. Inject the current locale automatically if none is provided.
|
|
13
|
+
* 2. Use the performance-optimized `CachedIntl` under the hood.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* const intl = useIntl(); // uses context locale
|
|
18
|
+
*
|
|
19
|
+
* // Standard API, but no need to pass locale as the first argument
|
|
20
|
+
* const formatted = new intl.NumberFormat({
|
|
21
|
+
* style: 'currency',
|
|
22
|
+
* currency: 'USD'
|
|
23
|
+
* }).format(123.45);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
const useIntl = (locale) => {
|
|
27
|
+
const { locale: contextLocale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
28
|
+
const currentLocale = locale ?? contextLocale;
|
|
29
|
+
return (0, preact_hooks.useMemo)(() => (0, _intlayer_core_formatters.bindIntl)(currentLocale), [currentLocale]);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
exports.useIntl = useIntl;
|
|
2
34
|
//# sourceMappingURL=useIntl.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntl.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useIntl.ts"],"sourcesContent":["import { bindIntl, type WrappedIntl } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * Preact client hook that provides a locale-bound `Intl` object.\n *\n * It acts exactly like the native `Intl` object, but acts as a proxy to:\n * 1. Inject the current locale automatically if none is provided.\n * 2. Use the performance-optimized `CachedIntl` under the hood.\n *\n * @example\n * ```tsx\n * const intl = useIntl(); // uses context locale\n *\n * // Standard API, but no need to pass locale as the first argument\n * const formatted = new intl.NumberFormat({\n * style: 'currency',\n * currency: 'USD'\n * }).format(123.45);\n * ```\n */\nexport const useIntl = (locale?: LocalesValues) => {\n const { locale: contextLocale } = useContext(IntlayerClientContext);\n const currentLocale = locale ?? contextLocale;\n\n return useMemo<WrappedIntl>(() => bindIntl(currentLocale), [currentLocale]);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useIntl.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useIntl.ts"],"sourcesContent":["import { bindIntl, type WrappedIntl } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * Preact client hook that provides a locale-bound `Intl` object.\n *\n * It acts exactly like the native `Intl` object, but acts as a proxy to:\n * 1. Inject the current locale automatically if none is provided.\n * 2. Use the performance-optimized `CachedIntl` under the hood.\n *\n * @example\n * ```tsx\n * const intl = useIntl(); // uses context locale\n *\n * // Standard API, but no need to pass locale as the first argument\n * const formatted = new intl.NumberFormat({\n * style: 'currency',\n * currency: 'USD'\n * }).format(123.45);\n * ```\n */\nexport const useIntl = (locale?: LocalesValues) => {\n const { locale: contextLocale } = useContext(IntlayerClientContext);\n const currentLocale = locale ?? contextLocale;\n\n return useMemo<WrappedIntl>(() => bindIntl(currentLocale), [currentLocale]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,WAAW,WAA2B;CACjD,MAAM,EAAE,QAAQ,+CAA6BA,sDAAsB;CACnE,MAAM,gBAAgB,UAAU;AAEhC,gFAA2C,cAAc,EAAE,CAAC,cAAc,CAAC"}
|
|
@@ -1,2 +1,39 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_client_IntlayerProvider = require('../IntlayerProvider.cjs');
|
|
4
|
+
let preact_hooks = require("preact/hooks");
|
|
5
|
+
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
6
|
+
|
|
7
|
+
//#region src/client/format/useList.ts
|
|
8
|
+
/**
|
|
9
|
+
* React client hook that provides a list formatter
|
|
10
|
+
* bound to the current application locale.
|
|
11
|
+
*
|
|
12
|
+
* @returns {(values: (string | number)[], options?: ListProps) => string}
|
|
13
|
+
* A function to format arrays into localized list strings.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* const formatList = useList();
|
|
18
|
+
*
|
|
19
|
+
* formatList(['apple', 'banana', 'orange']);
|
|
20
|
+
* // "apple, banana, and orange"
|
|
21
|
+
*
|
|
22
|
+
* formatList(['red', 'green', 'blue'], { type: 'disjunction' });
|
|
23
|
+
* // "red, green, or blue"
|
|
24
|
+
*
|
|
25
|
+
* formatList([1, 2, 3], { type: 'unit', locale: 'de-DE' });
|
|
26
|
+
* // "1, 2 und 3"
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
const useList = () => {
|
|
30
|
+
const { locale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
31
|
+
return (0, preact_hooks.useCallback)((...args) => (0, _intlayer_core_formatters.list)(args[0], {
|
|
32
|
+
...args[1],
|
|
33
|
+
locale: args[1]?.locale ?? locale
|
|
34
|
+
}), [locale]);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.useList = useList;
|
|
2
39
|
//# sourceMappingURL=useList.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useList.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useList.ts"],"sourcesContent":["import { list } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a list formatter\n * bound to the current application locale.\n *\n * @returns {(values: (string | number)[], options?: ListProps) => string}\n * A function to format arrays into localized list strings.\n *\n * @example\n * ```tsx\n * const formatList = useList();\n *\n * formatList(['apple', 'banana', 'orange']);\n * // \"apple, banana, and orange\"\n *\n * formatList(['red', 'green', 'blue'], { type: 'disjunction' });\n * // \"red, green, or blue\"\n *\n * formatList([1, 2, 3], { type: 'unit', locale: 'de-DE' });\n * // \"1, 2 und 3\"\n * ```\n */\nexport const useList = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof list>) =>\n list(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useList.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useList.ts"],"sourcesContent":["import { list } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a list formatter\n * bound to the current application locale.\n *\n * @returns {(values: (string | number)[], options?: ListProps) => string}\n * A function to format arrays into localized list strings.\n *\n * @example\n * ```tsx\n * const formatList = useList();\n *\n * formatList(['apple', 'banana', 'orange']);\n * // \"apple, banana, and orange\"\n *\n * formatList(['red', 'green', 'blue'], { type: 'disjunction' });\n * // \"red, green, or blue\"\n *\n * formatList([1, 2, 3], { type: 'unit', locale: 'de-DE' });\n * // \"1, 2 und 3\"\n * ```\n */\nexport const useList = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof list>) =>\n list(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,MAAa,gBAAgB;CAC3B,MAAM,EAAE,wCAAsBA,sDAAsB;AAEpD,uCACG,GAAG,6CACG,KAAK,IAAI;EACZ,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC,EACJ,CAAC,OAAO,CACT"}
|
|
@@ -1,2 +1,40 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_client_IntlayerProvider = require('../IntlayerProvider.cjs');
|
|
4
|
+
let preact_hooks = require("preact/hooks");
|
|
5
|
+
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
6
|
+
|
|
7
|
+
//#region src/client/format/useNumber.ts
|
|
8
|
+
/**
|
|
9
|
+
* React client hook that provides a localized number formatter.
|
|
10
|
+
*
|
|
11
|
+
* Uses the current locale from {@link useLocaleBase} and returns
|
|
12
|
+
* a function that can be used to format numbers consistently
|
|
13
|
+
* according to the user's locale.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* const formatNumber = useNumber();
|
|
18
|
+
*
|
|
19
|
+
* formatNumber(12345);
|
|
20
|
+
* // e.g. "12,345" (en-US)
|
|
21
|
+
* // e.g. "12 345" (fr-FR)
|
|
22
|
+
*
|
|
23
|
+
* formatNumber(0.75, { style: "percent" });
|
|
24
|
+
* // e.g. "75%"
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @returns {(value: string | number, options?: import("../createNumber").NumberProps) => string}
|
|
28
|
+
* A number formatting function bound to the active locale.
|
|
29
|
+
*/
|
|
30
|
+
const useNumber = () => {
|
|
31
|
+
const { locale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
32
|
+
return (0, preact_hooks.useCallback)((...args) => (0, _intlayer_core_formatters.number)(args[0], {
|
|
33
|
+
...args[1],
|
|
34
|
+
locale: args[1]?.locale ?? locale
|
|
35
|
+
}), [locale]);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
exports.useNumber = useNumber;
|
|
2
40
|
//# sourceMappingURL=useNumber.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNumber.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useNumber.ts"],"sourcesContent":["import { number } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a localized number formatter.\n *\n * Uses the current locale from {@link useLocaleBase} and returns\n * a function that can be used to format numbers consistently\n * according to the user's locale.\n *\n * @example\n * ```tsx\n * const formatNumber = useNumber();\n *\n * formatNumber(12345);\n * // e.g. \"12,345\" (en-US)\n * // e.g. \"12 345\" (fr-FR)\n *\n * formatNumber(0.75, { style: \"percent\" });\n * // e.g. \"75%\"\n * ```\n *\n * @returns {(value: string | number, options?: import(\"../createNumber\").NumberProps) => string}\n * A number formatting function bound to the active locale.\n */\nexport const useNumber = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof number>) =>\n number(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useNumber.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useNumber.ts"],"sourcesContent":["import { number } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a localized number formatter.\n *\n * Uses the current locale from {@link useLocaleBase} and returns\n * a function that can be used to format numbers consistently\n * according to the user's locale.\n *\n * @example\n * ```tsx\n * const formatNumber = useNumber();\n *\n * formatNumber(12345);\n * // e.g. \"12,345\" (en-US)\n * // e.g. \"12 345\" (fr-FR)\n *\n * formatNumber(0.75, { style: \"percent\" });\n * // e.g. \"75%\"\n * ```\n *\n * @returns {(value: string | number, options?: import(\"../createNumber\").NumberProps) => string}\n * A number formatting function bound to the active locale.\n */\nexport const useNumber = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof number>) =>\n number(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,kBAAkB;CAC7B,MAAM,EAAE,wCAAsBA,sDAAsB;AAEpD,uCACG,GAAG,+CACK,KAAK,IAAI;EACd,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC,EACJ,CAAC,OAAO,CACT"}
|