react-intlayer 8.1.2 → 8.1.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/IntlayerNode.cjs +1 -17
- package/dist/cjs/IntlayerNode.cjs.map +1 -1
- package/dist/cjs/UI/ContentSelector.cjs +1 -96
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -29
- package/dist/cjs/client/IntlayerProvider.cjs +1 -92
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/format/index.cjs +1 -20
- package/dist/cjs/client/format/useCompact.cjs +1 -29
- package/dist/cjs/client/format/useCompact.cjs.map +1 -1
- package/dist/cjs/client/format/useCurrency.cjs +1 -43
- package/dist/cjs/client/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/client/format/useDate.cjs +1 -45
- package/dist/cjs/client/format/useDate.cjs.map +1 -1
- package/dist/cjs/client/format/useIntl.cjs +1 -45
- package/dist/cjs/client/format/useIntl.cjs.map +1 -1
- package/dist/cjs/client/format/useList.cjs +1 -40
- package/dist/cjs/client/format/useList.cjs.map +1 -1
- package/dist/cjs/client/format/useNumber.cjs +1 -41
- package/dist/cjs/client/format/useNumber.cjs.map +1 -1
- package/dist/cjs/client/format/usePercentage.cjs +1 -37
- package/dist/cjs/client/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/client/format/useRelativeTime.cjs +1 -37
- package/dist/cjs/client/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/client/format/useUnit.cjs +1 -36
- package/dist/cjs/client/format/useUnit.cjs.map +1 -1
- package/dist/cjs/client/index.cjs +1 -34
- package/dist/cjs/client/t.cjs +1 -40
- package/dist/cjs/client/t.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +1 -27
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +1 -24
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +1 -25
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useI18n.cjs +1 -45
- package/dist/cjs/client/useI18n.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +1 -42
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLoadDynamic.cjs +1 -27
- package/dist/cjs/client/useLoadDynamic.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +1 -60
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleBase.cjs +1 -26
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +1 -61
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
- package/dist/cjs/client/useRewriteURL.cjs +1 -42
- package/dist/cjs/client/useRewriteURL.cjs.map +1 -1
- package/dist/cjs/client/useTraduction.cjs +1 -35
- package/dist/cjs/client/useTraduction.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelectorWrapper.cjs +1 -55
- package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs +1 -61
- package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/index.cjs +1 -4
- package/dist/cjs/editor/useEditedContentRenderer.cjs +1 -40
- package/dist/cjs/editor/useEditedContentRenderer.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs +1 -19
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +1 -19
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/html/HTMLProvider.cjs +1 -18
- package/dist/cjs/html/HTMLProvider.cjs.map +1 -1
- package/dist/cjs/html/HTMLRenderer.cjs +1 -59
- package/dist/cjs/html/HTMLRenderer.cjs.map +1 -1
- package/dist/cjs/html/HTMLRendererPlugin.cjs +1 -36
- package/dist/cjs/html/HTMLRendererPlugin.cjs.map +1 -1
- package/dist/cjs/html/index.cjs +1 -12
- package/dist/cjs/index.cjs +1 -52
- package/dist/cjs/markdown/MarkdownProvider.cjs +1 -77
- package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs +1 -199
- package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs +1 -33
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs.map +1 -1
- package/dist/cjs/markdown/index.cjs +1 -25
- package/dist/cjs/markdown/processor.cjs +1 -66
- package/dist/cjs/markdown/processor.cjs.map +1 -1
- package/dist/cjs/markdown/runtime.cjs +1 -43
- package/dist/cjs/markdown/runtime.cjs.map +1 -1
- package/dist/cjs/plugins.cjs +1 -179
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/reactElement/renderReactElement.cjs +1 -52
- package/dist/cjs/reactElement/renderReactElement.cjs.map +1 -1
- package/dist/cjs/server/IntlayerServerProvider.cjs +1 -34
- package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
- package/dist/cjs/server/format/index.cjs +1 -18
- package/dist/cjs/server/format/useCompact.cjs +1 -27
- package/dist/cjs/server/format/useCompact.cjs.map +1 -1
- package/dist/cjs/server/format/useCurrency.cjs +1 -38
- package/dist/cjs/server/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/server/format/useDate.cjs +1 -43
- package/dist/cjs/server/format/useDate.cjs.map +1 -1
- package/dist/cjs/server/format/useIntl.cjs +1 -44
- package/dist/cjs/server/format/useIntl.cjs.map +1 -1
- package/dist/cjs/server/format/useList.cjs +1 -35
- package/dist/cjs/server/format/useList.cjs.map +1 -1
- package/dist/cjs/server/format/useNumber.cjs +1 -39
- package/dist/cjs/server/format/useNumber.cjs.map +1 -1
- package/dist/cjs/server/format/usePercentage.cjs +1 -35
- package/dist/cjs/server/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/server/format/useRelativeTime.cjs +1 -35
- package/dist/cjs/server/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/server/format/useUnit.cjs +1 -34
- package/dist/cjs/server/format/useUnit.cjs.map +1 -1
- package/dist/cjs/server/index.cjs +1 -24
- package/dist/cjs/server/serverContext.cjs +1 -58
- package/dist/cjs/server/serverContext.cjs.map +1 -1
- package/dist/cjs/server/t.cjs +1 -35
- package/dist/cjs/server/t.cjs.map +1 -1
- package/dist/cjs/server/useDictionary.cjs +1 -17
- package/dist/cjs/server/useDictionary.cjs.map +1 -1
- package/dist/cjs/server/useDictionaryAsync.cjs +1 -21
- package/dist/cjs/server/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/server/useDictionaryDynamic.cjs +1 -22
- package/dist/cjs/server/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/server/useI18n.cjs +1 -38
- package/dist/cjs/server/useI18n.cjs.map +1 -1
- package/dist/cjs/server/useIntlayer.cjs +1 -17
- package/dist/cjs/server/useIntlayer.cjs.map +1 -1
- package/dist/cjs/server/useLoadDynamic.cjs +1 -14
- package/dist/cjs/server/useLoadDynamic.cjs.map +1 -1
- package/dist/cjs/server/useLocale.cjs +1 -24
- package/dist/cjs/server/useLocale.cjs.map +1 -1
- package/dist/esm/IntlayerNode.mjs +1 -15
- package/dist/esm/IntlayerNode.mjs.map +1 -1
- package/dist/esm/UI/ContentSelector.mjs +1 -94
- package/dist/esm/UI/ContentSelector.mjs.map +1 -1
- package/dist/esm/client/IntlayerProvider.mjs +1 -86
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/format/index.mjs +1 -11
- package/dist/esm/client/format/useCompact.mjs +1 -27
- package/dist/esm/client/format/useCompact.mjs.map +1 -1
- package/dist/esm/client/format/useCurrency.mjs +1 -41
- package/dist/esm/client/format/useCurrency.mjs.map +1 -1
- package/dist/esm/client/format/useDate.mjs +1 -43
- package/dist/esm/client/format/useDate.mjs.map +1 -1
- package/dist/esm/client/format/useIntl.mjs +1 -43
- package/dist/esm/client/format/useIntl.mjs.map +1 -1
- package/dist/esm/client/format/useList.mjs +1 -38
- package/dist/esm/client/format/useList.mjs.map +1 -1
- package/dist/esm/client/format/useNumber.mjs +1 -39
- package/dist/esm/client/format/useNumber.mjs.map +1 -1
- package/dist/esm/client/format/usePercentage.mjs +1 -35
- package/dist/esm/client/format/usePercentage.mjs.map +1 -1
- package/dist/esm/client/format/useRelativeTime.mjs +1 -35
- package/dist/esm/client/format/useRelativeTime.mjs.map +1 -1
- package/dist/esm/client/format/useUnit.mjs +1 -34
- package/dist/esm/client/format/useUnit.mjs.map +1 -1
- package/dist/esm/client/index.mjs +1 -14
- package/dist/esm/client/t.mjs +1 -38
- package/dist/esm/client/t.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +1 -25
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +1 -21
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +1 -22
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useI18n.mjs +1 -43
- package/dist/esm/client/useI18n.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +1 -40
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLoadDynamic.mjs +1 -25
- package/dist/esm/client/useLoadDynamic.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +1 -57
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleBase.mjs +1 -23
- package/dist/esm/client/useLocaleBase.mjs.map +1 -1
- package/dist/esm/client/useLocaleStorage.mjs +1 -54
- package/dist/esm/client/useLocaleStorage.mjs.map +1 -1
- package/dist/esm/client/useRewriteURL.mjs +1 -39
- package/dist/esm/client/useRewriteURL.mjs.map +1 -1
- package/dist/esm/client/useTraduction.mjs +1 -33
- package/dist/esm/client/useTraduction.mjs.map +1 -1
- package/dist/esm/editor/ContentSelectorWrapper.mjs +1 -53
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs +1 -58
- package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
- package/dist/esm/editor/index.mjs +1 -3
- package/dist/esm/editor/useEditedContentRenderer.mjs +1 -37
- package/dist/esm/editor/useEditedContentRenderer.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs +1 -17
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs +1 -17
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/esm/html/HTMLProvider.mjs +1 -15
- package/dist/esm/html/HTMLProvider.mjs.map +1 -1
- package/dist/esm/html/HTMLRenderer.mjs +1 -54
- package/dist/esm/html/HTMLRenderer.mjs.map +1 -1
- package/dist/esm/html/HTMLRendererPlugin.mjs +1 -34
- package/dist/esm/html/HTMLRendererPlugin.mjs.map +1 -1
- package/dist/esm/html/index.mjs +1 -5
- package/dist/esm/index.mjs +1 -21
- package/dist/esm/markdown/MarkdownProvider.mjs +1 -74
- package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRenderer.mjs +1 -195
- package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs +1 -30
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs.map +1 -1
- package/dist/esm/markdown/index.mjs +1 -7
- package/dist/esm/markdown/processor.mjs +1 -58
- package/dist/esm/markdown/processor.mjs.map +1 -1
- package/dist/esm/markdown/runtime.mjs +1 -39
- package/dist/esm/markdown/runtime.mjs.map +1 -1
- package/dist/esm/plugins.mjs +1 -172
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/reactElement/renderReactElement.mjs +1 -50
- package/dist/esm/reactElement/renderReactElement.mjs.map +1 -1
- package/dist/esm/server/IntlayerServerProvider.mjs +1 -28
- package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
- package/dist/esm/server/format/index.mjs +1 -10
- package/dist/esm/server/format/useCompact.mjs +1 -25
- package/dist/esm/server/format/useCompact.mjs.map +1 -1
- package/dist/esm/server/format/useCurrency.mjs +1 -36
- package/dist/esm/server/format/useCurrency.mjs.map +1 -1
- package/dist/esm/server/format/useDate.mjs +1 -41
- package/dist/esm/server/format/useDate.mjs.map +1 -1
- package/dist/esm/server/format/useIntl.mjs +1 -41
- package/dist/esm/server/format/useIntl.mjs.map +1 -1
- package/dist/esm/server/format/useList.mjs +1 -33
- package/dist/esm/server/format/useList.mjs.map +1 -1
- package/dist/esm/server/format/useNumber.mjs +1 -37
- package/dist/esm/server/format/useNumber.mjs.map +1 -1
- package/dist/esm/server/format/usePercentage.mjs +1 -33
- package/dist/esm/server/format/usePercentage.mjs.map +1 -1
- package/dist/esm/server/format/useRelativeTime.mjs +1 -33
- package/dist/esm/server/format/useRelativeTime.mjs.map +1 -1
- package/dist/esm/server/format/useUnit.mjs +1 -32
- package/dist/esm/server/format/useUnit.mjs.map +1 -1
- package/dist/esm/server/index.mjs +1 -12
- package/dist/esm/server/serverContext.mjs +1 -54
- package/dist/esm/server/serverContext.mjs.map +1 -1
- package/dist/esm/server/t.mjs +1 -33
- package/dist/esm/server/t.mjs.map +1 -1
- package/dist/esm/server/useDictionary.mjs +1 -16
- package/dist/esm/server/useDictionary.mjs.map +1 -1
- package/dist/esm/server/useDictionaryAsync.mjs +1 -18
- package/dist/esm/server/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/server/useDictionaryDynamic.mjs +1 -19
- package/dist/esm/server/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/server/useI18n.mjs +1 -37
- package/dist/esm/server/useI18n.mjs.map +1 -1
- package/dist/esm/server/useIntlayer.mjs +1 -16
- package/dist/esm/server/useIntlayer.mjs.map +1 -1
- package/dist/esm/server/useLoadDynamic.mjs +1 -11
- package/dist/esm/server/useLoadDynamic.mjs.map +1 -1
- package/dist/esm/server/useLocale.mjs +1 -21
- package/dist/esm/server/useLocale.mjs.map +1 -1
- package/dist/types/IntlayerNode.d.ts +1 -1
- package/dist/types/client/format/useDate.d.ts +1 -1
- package/dist/types/client/useDictionary.d.ts +2 -2
- package/dist/types/client/useDictionary.d.ts.map +1 -1
- package/dist/types/client/useDictionaryDynamic.d.ts +2 -2
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/client/useI18n.d.ts +3 -3
- package/dist/types/client/useI18n.d.ts.map +1 -1
- package/dist/types/client/useIntlayer.d.ts +2 -2
- package/dist/types/client/useIntlayer.d.ts.map +1 -1
- package/dist/types/editor/ContentSelectorWrapper.d.ts +1 -1
- package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -1
- package/dist/types/getDictionary.d.ts +1 -1
- package/dist/types/getIntlayer.d.ts +1 -1
- package/dist/types/getIntlayer.d.ts.map +1 -1
- package/dist/types/html/HTMLComponentTypes.d.ts +1 -1
- package/dist/types/html/HTMLRenderer.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/markdown/MarkdownRendererPlugin.d.ts.map +1 -1
- package/dist/types/markdown/processor.d.ts +1 -1
- package/dist/types/markdown/runtime.d.ts +1 -1
- package/dist/types/plugins.d.ts +1 -1
- package/dist/types/plugins.d.ts.map +1 -1
- package/dist/types/server/format/useCompact.d.ts +1 -1
- package/dist/types/server/format/useCurrency.d.ts +1 -1
- package/dist/types/server/format/useDate.d.ts +1 -1
- package/dist/types/server/format/useList.d.ts +1 -1
- package/dist/types/server/format/useNumber.d.ts +1 -1
- package/dist/types/server/format/usePercentage.d.ts +1 -1
- package/dist/types/server/format/useRelativeTime.d.ts +1 -1
- package/dist/types/server/format/useUnit.d.ts +1 -1
- package/dist/types/server/useDictionary.d.ts +2 -2
- package/dist/types/server/useDictionary.d.ts.map +1 -1
- package/dist/types/server/useDictionaryAsync.d.ts +2 -2
- package/dist/types/server/useDictionaryAsync.d.ts.map +1 -1
- package/dist/types/server/useDictionaryDynamic.d.ts +2 -2
- package/dist/types/server/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/server/useI18n.d.ts +3 -3
- package/dist/types/server/useI18n.d.ts.map +1 -1
- package/dist/types/server/useIntlayer.d.ts +2 -2
- package/dist/types/server/useIntlayer.d.ts.map +1 -1
- package/package.json +9 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverContext.cjs","names":[],"sources":["../../../src/server/serverContext.tsx"],"sourcesContent":["/**\n * Creates a new datastore for a given server context.\n * Attempts to closely mimic the `createContext` API.\n *\n * @example\n * const IntlayerServer = createServerContext<string | null>(null);\n *\n * <IntlayerServer value={locale}>\n * {children}\n * </IntlayerServer>\n */\nimport react, { type FC, type PropsWithChildren, type ReactNode } from 'react';\n\ntype CacheType<T> = () => { value: T | undefined };\n\nconst cacheFallback = () => () => ({ value: undefined });\n\nexport const createServerContext = <T,>(defaultValue?: T): ServerContext<T> => {\n throwInClient();\n\n /** @ts-ignore remove error Property 'cache' does not exist on type 'typeof React'. */\n const cache = react.cache<CacheType<T>> ?? cacheFallback;\n\n const getCache = cache(() => ({\n value: undefined,\n }));\n\n const Provider: FC<PropsWithChildren<{ value?: T }>> = ({\n children,\n value,\n }) => {\n getCache().value = value;\n return children;\n };\n\n const ServerContext = Provider as ServerContext<T>;\n ServerContext.Provider = Provider;\n ServerContext.Consumer = (props) => {\n const store = getCache();\n return props.children(store ? store.value : defaultValue);\n };\n ServerContext._storage = getCache;\n ServerContext._defaultValue = defaultValue;\n\n return ServerContext;\n};\n\n/**\n * Fetches a value present in a given server context.\n * Attempts to closely mimic the `useContext` API.\n *\n * @example\n * getServerContext(IntlayerServer);\n */\nexport const getServerContext = <T,>({\n _storage,\n _defaultValue,\n}: ServerContext<T>) => {\n // throwInClient();\n const store = _storage();\n if (!store) return _defaultValue;\n return store.value;\n};\n\ntype ServerContext<T> = FC<PropsWithChildren<{ value?: T }>> & {\n Provider: FC<PropsWithChildren<{ value?: T }>>;\n Consumer: FC<\n PropsWithChildren<{ children: (context: T | undefined) => ReactNode }>\n >;\n _storage: () => { value: T | undefined };\n _defaultValue: T | undefined;\n};\n\n/**\n * Throws if called within a client component environment.\n * Useful to help prevent mistakes.\n */\nconst throwInClient = (): undefined | never => {\n // If window.document is defined we're in a client component\n if (typeof window !== 'undefined') {\n throw new Error(`createServerContext only works in Server Components`);\n }\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"serverContext.cjs","names":[],"sources":["../../../src/server/serverContext.tsx"],"sourcesContent":["/**\n * Creates a new datastore for a given server context.\n * Attempts to closely mimic the `createContext` API.\n *\n * @example\n * const IntlayerServer = createServerContext<string | null>(null);\n *\n * <IntlayerServer value={locale}>\n * {children}\n * </IntlayerServer>\n */\nimport react, { type FC, type PropsWithChildren, type ReactNode } from 'react';\n\ntype CacheType<T> = () => { value: T | undefined };\n\nconst cacheFallback = () => () => ({ value: undefined });\n\nexport const createServerContext = <T,>(defaultValue?: T): ServerContext<T> => {\n throwInClient();\n\n /** @ts-ignore remove error Property 'cache' does not exist on type 'typeof React'. */\n const cache = react.cache<CacheType<T>> ?? cacheFallback;\n\n const getCache = cache(() => ({\n value: undefined,\n }));\n\n const Provider: FC<PropsWithChildren<{ value?: T }>> = ({\n children,\n value,\n }) => {\n getCache().value = value;\n return children;\n };\n\n const ServerContext = Provider as ServerContext<T>;\n ServerContext.Provider = Provider;\n ServerContext.Consumer = (props) => {\n const store = getCache();\n return props.children(store ? store.value : defaultValue);\n };\n ServerContext._storage = getCache;\n ServerContext._defaultValue = defaultValue;\n\n return ServerContext;\n};\n\n/**\n * Fetches a value present in a given server context.\n * Attempts to closely mimic the `useContext` API.\n *\n * @example\n * getServerContext(IntlayerServer);\n */\nexport const getServerContext = <T,>({\n _storage,\n _defaultValue,\n}: ServerContext<T>) => {\n // throwInClient();\n const store = _storage();\n if (!store) return _defaultValue;\n return store.value;\n};\n\ntype ServerContext<T> = FC<PropsWithChildren<{ value?: T }>> & {\n Provider: FC<PropsWithChildren<{ value?: T }>>;\n Consumer: FC<\n PropsWithChildren<{ children: (context: T | undefined) => ReactNode }>\n >;\n _storage: () => { value: T | undefined };\n _defaultValue: T | undefined;\n};\n\n/**\n * Throws if called within a client component environment.\n * Useful to help prevent mistakes.\n */\nconst throwInClient = (): undefined | never => {\n // If window.document is defined we're in a client component\n if (typeof window !== 'undefined') {\n throw new Error(`createServerContext only works in Server Components`);\n }\n};\n"],"mappings":"8JAeA,MAAM,WAA6B,CAAE,MAAO,IAAA,GAAW,EAE1C,EAA2B,GAAuC,CAC7E,GAAe,CAKf,IAAM,GAFQ,EAAA,QAAM,OAAuB,QAEb,CAC5B,MAAO,IAAA,GACR,EAAE,CAEG,GAAkD,CACtD,WACA,YAEA,GAAU,CAAC,MAAQ,EACZ,GAGH,EAAgB,EAStB,MARA,GAAc,SAAW,EACzB,EAAc,SAAY,GAAU,CAClC,IAAM,EAAQ,GAAU,CACxB,OAAO,EAAM,SAAS,EAAQ,EAAM,MAAQ,EAAa,EAE3D,EAAc,SAAW,EACzB,EAAc,cAAgB,EAEvB,GAUI,GAAwB,CACnC,WACA,mBACsB,CAEtB,IAAM,EAAQ,GAAU,CAExB,OADK,EACE,EAAM,MADM,GAiBf,MAAyC,CAE7C,GAAI,OAAO,OAAW,IACpB,MAAU,MAAM,sDAAsD"}
|
package/dist/cjs/server/t.cjs
CHANGED
|
@@ -1,36 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
const require_server_serverContext = require('./serverContext.cjs');
|
|
4
|
-
const require_server_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
|
|
5
|
-
let _intlayer_core = require("@intlayer/core");
|
|
6
|
-
|
|
7
|
-
//#region src/server/t.ts
|
|
8
|
-
/**
|
|
9
|
-
* On the server side, hook to get the translation content based on the locale
|
|
10
|
-
*
|
|
11
|
-
* If not locale found, it will return the content related to the default locale.
|
|
12
|
-
*
|
|
13
|
-
* Return either the content editor, or the content itself depending on the configuration.
|
|
14
|
-
*
|
|
15
|
-
* Usage:
|
|
16
|
-
*
|
|
17
|
-
* ```ts
|
|
18
|
-
* const content = t<string>({
|
|
19
|
-
* en: 'Hello',
|
|
20
|
-
* fr: 'Bonjour',
|
|
21
|
-
* }, 'fr');
|
|
22
|
-
* // 'Bonjour'
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* Using TypeScript:
|
|
26
|
-
* - this function will require each locale to be defined if defined in the project configuration.
|
|
27
|
-
* - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
|
|
28
|
-
*/
|
|
29
|
-
const t = (multilangContent, locale) => {
|
|
30
|
-
const currentLocale = require_server_serverContext.getServerContext(require_server_IntlayerServerProvider.IntlayerServerContext);
|
|
31
|
-
return (0, _intlayer_core.getTranslation)(multilangContent, locale ?? currentLocale);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
//#endregion
|
|
35
|
-
exports.t = t;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./serverContext.cjs`),t=require(`./IntlayerServerProvider.cjs`);let n=require(`@intlayer/core/interpreter`);const r=(r,i)=>{let a=e.getServerContext(t.IntlayerServerContext);return(0,n.getTranslation)(r,i??a)};exports.t=r;
|
|
36
2
|
//# sourceMappingURL=t.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"t.cjs","names":["getServerContext","IntlayerServerContext"],"sources":["../../../src/server/t.ts"],"sourcesContent":["import { getTranslation } from '@intlayer/core';\nimport type { LocalesValues, StrictModeLocaleMap } from '@intlayer/types';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, hook to get the translation content based on the locale\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```ts\n * const content = t<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const t = <Content = string>(\n multilangContent: StrictModeLocaleMap<Content>,\n locale?: LocalesValues\n) => {\n const currentLocale = getServerContext<LocalesValues>(IntlayerServerContext);\n const localeTarget = locale ?? currentLocale;\n\n return getTranslation<Content>(multilangContent, localeTarget);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"t.cjs","names":["getServerContext","IntlayerServerContext"],"sources":["../../../src/server/t.ts"],"sourcesContent":["import { getTranslation } from '@intlayer/core/interpreter';\nimport type { LocalesValues, StrictModeLocaleMap } from '@intlayer/types';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, hook to get the translation content based on the locale\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```ts\n * const content = t<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const t = <Content = string>(\n multilangContent: StrictModeLocaleMap<Content>,\n locale?: LocalesValues\n) => {\n const currentLocale = getServerContext<LocalesValues>(IntlayerServerContext);\n const localeTarget = locale ?? currentLocale;\n\n return getTranslation<Content>(multilangContent, localeTarget);\n};\n"],"mappings":"6OA0BA,MAAa,GACX,EACA,IACG,CACH,IAAM,EAAgBA,EAAAA,iBAAgCC,EAAAA,sBAAsB,CAG5E,OAAA,EAAA,EAAA,gBAA+B,EAFV,GAAU,EAE+B"}
|
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_getDictionary = require('../getDictionary.cjs');
|
|
3
|
-
const require_server_serverContext = require('./serverContext.cjs');
|
|
4
|
-
const require_server_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
|
|
5
|
-
|
|
6
|
-
//#region src/server/useDictionary.ts
|
|
7
|
-
/**
|
|
8
|
-
* On the server side, Hook that transform a dictionary and return the content
|
|
9
|
-
*
|
|
10
|
-
* If the locale is not provided, it will use the locale from the server context
|
|
11
|
-
*/
|
|
12
|
-
const useDictionary = (dictionary, locale) => {
|
|
13
|
-
return require_getDictionary.getDictionary(dictionary, locale ?? require_server_serverContext.getServerContext(require_server_IntlayerServerProvider.IntlayerServerContext));
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
//#endregion
|
|
17
|
-
exports.useDictionary = useDictionary;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../getDictionary.cjs`),t=require(`./serverContext.cjs`),n=require(`./IntlayerServerProvider.cjs`),r=(r,i)=>e.getDictionary(r,i??t.getServerContext(n.IntlayerServerContext));exports.useDictionary=r;
|
|
18
2
|
//# sourceMappingURL=useDictionary.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.cjs","names":["getDictionary","getServerContext","IntlayerServerContext"],"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n) => {\n const localeTarget =\n locale ?? getServerContext<LocalesValues>(IntlayerServerContext);\n\n return getDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDictionary.cjs","names":["getDictionary","getServerContext","IntlayerServerContext"],"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n) => {\n const localeTarget =\n locale ?? getServerContext<LocalesValues>(IntlayerServerContext);\n\n return getDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":"sLAca,GAIX,EACA,IAKOA,EAAAA,cAAoB,EAFzB,GAAUC,EAAAA,iBAAgCC,EAAAA,sBAAsB,CAET"}
|
|
@@ -1,22 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
const require_server_serverContext = require('./serverContext.cjs');
|
|
4
|
-
const require_server_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
|
|
5
|
-
const require_server_useDictionary = require('./useDictionary.cjs');
|
|
6
|
-
let _intlayer_config_built = require("@intlayer/config/built");
|
|
7
|
-
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
8
|
-
|
|
9
|
-
//#region src/server/useDictionaryAsync.ts
|
|
10
|
-
/**
|
|
11
|
-
* On the server side, Hook that transform a dictionary and return the content
|
|
12
|
-
*
|
|
13
|
-
* If the locale is not provided, it will use the locale from the server context
|
|
14
|
-
*/
|
|
15
|
-
const useDictionaryAsync = async (dictionaryPromise, locale) => {
|
|
16
|
-
const localeTarget = locale ?? require_server_serverContext.getServerContext(require_server_IntlayerServerProvider.IntlayerServerContext) ?? _intlayer_config_built.default?.internationalization.defaultLocale;
|
|
17
|
-
return require_server_useDictionary.useDictionary(await dictionaryPromise[localeTarget]?.(), localeTarget);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
//#endregion
|
|
21
|
-
exports.useDictionaryAsync = useDictionaryAsync;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`./serverContext.cjs`),n=require(`./IntlayerServerProvider.cjs`),r=require(`./useDictionary.cjs`);let i=require(`@intlayer/config/built`);i=e.__toESM(i);const a=async(e,a)=>{let o=a??t.getServerContext(n.IntlayerServerContext)??i.default?.internationalization.defaultLocale;return r.useDictionary(await e[o]?.(),o)};exports.useDictionaryAsync=a;
|
|
22
2
|
//# sourceMappingURL=useDictionaryAsync.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryAsync.cjs","names":["getServerContext","IntlayerServerContext","configuration","useDictionary"],"sources":["../../../src/server/useDictionaryAsync.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\nimport { useDictionary } from './useDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionaryAsync = async <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: L\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n configuration?.internationalization.defaultLocale;\n\n const dictionary = await (dictionaryPromise as any)[localeTarget]?.();\n\n return useDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.cjs","names":["getServerContext","IntlayerServerContext","configuration","useDictionary"],"sources":["../../../src/server/useDictionaryAsync.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\nimport { useDictionary } from './useDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionaryAsync = async <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: L\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n configuration?.internationalization.defaultLocale;\n\n const dictionary = await (dictionaryPromise as any)[localeTarget]?.();\n\n return useDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":"2RAgBA,MAAa,EAAqB,MAIhC,EACA,IACG,CACH,IAAM,EACJ,GACAA,EAAAA,iBAAgCC,EAAAA,sBAAsB,EACtDC,EAAAA,SAAe,qBAAqB,cAItC,OAAOC,EAAAA,cAFY,MAAO,EAA0B,MAAiB,CAE9B,EAAkB"}
|
|
@@ -1,23 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
const require_server_serverContext = require('./serverContext.cjs');
|
|
4
|
-
const require_server_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
|
|
5
|
-
const require_server_useDictionary = require('./useDictionary.cjs');
|
|
6
|
-
const require_server_useLoadDynamic = require('./useLoadDynamic.cjs');
|
|
7
|
-
let _intlayer_config_built = require("@intlayer/config/built");
|
|
8
|
-
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
9
|
-
|
|
10
|
-
//#region src/server/useDictionaryDynamic.ts
|
|
11
|
-
/**
|
|
12
|
-
* On the server side, Hook that transform a dictionary and return the content
|
|
13
|
-
*
|
|
14
|
-
* If the locale is not provided, it will use the locale from the server context
|
|
15
|
-
*/
|
|
16
|
-
const useDictionaryDynamic = (dictionaryPromise, key, locale) => {
|
|
17
|
-
const localeTarget = locale ?? require_server_serverContext.getServerContext(require_server_IntlayerServerProvider.IntlayerServerContext) ?? _intlayer_config_built.default?.internationalization.defaultLocale;
|
|
18
|
-
return require_server_useDictionary.useDictionary(require_server_useLoadDynamic.useLoadDynamic(`${String(key)}.${localeTarget}`, dictionaryPromise[localeTarget]?.()), localeTarget);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
//#endregion
|
|
22
|
-
exports.useDictionaryDynamic = useDictionaryDynamic;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`./serverContext.cjs`),n=require(`./IntlayerServerProvider.cjs`),r=require(`./useDictionary.cjs`),i=require(`./useLoadDynamic.cjs`);let a=require(`@intlayer/config/built`);a=e.__toESM(a);const o=(e,o,s)=>{let c=s??t.getServerContext(n.IntlayerServerContext)??a.default?.internationalization.defaultLocale;return r.useDictionary(i.useLoadDynamic(`${String(o)}.${c}`,e[c]?.()),c)};exports.useDictionaryDynamic=o;
|
|
23
2
|
//# sourceMappingURL=useDictionaryDynamic.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.cjs","names":["getServerContext","IntlayerServerContext","configuration","useDictionary","useLoadDynamic"],"sources":["../../../src/server/useDictionaryDynamic.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: string,\n locale?: L\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n configuration?.internationalization.defaultLocale;\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget}`,\n (dictionaryPromise as any)[localeTarget]?.()\n );\n\n return useDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.cjs","names":["getServerContext","IntlayerServerContext","configuration","useDictionary","useLoadDynamic"],"sources":["../../../src/server/useDictionaryDynamic.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: string,\n locale?: L\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n configuration?.internationalization.defaultLocale;\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget}`,\n (dictionaryPromise as any)[localeTarget]?.()\n );\n\n return useDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":"6TAiBA,MAAa,GAIX,EACA,EACA,IACG,CACH,IAAM,EACJ,GACAA,EAAAA,iBAAgCC,EAAAA,sBAAsB,EACtDC,EAAAA,SAAe,qBAAqB,cAOtC,OAAOC,EAAAA,cALYC,EAAAA,eACjB,GAAG,OAAO,EAAI,CAAC,GAAG,IACjB,EAA0B,MAAiB,CAC7C,CAEsC,EAAkB"}
|
|
@@ -1,39 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_getIntlayer = require('../getIntlayer.cjs');
|
|
3
|
-
const require_server_serverContext = require('./serverContext.cjs');
|
|
4
|
-
const require_server_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
|
|
5
|
-
|
|
6
|
-
//#region src/server/useI18n.ts
|
|
7
|
-
/**
|
|
8
|
-
* Hook that provides a translation function `t()` for accessing nested content by key.
|
|
9
|
-
* This hook mimics the pattern found in libraries like i18next, next-intl, and vue-i18n.
|
|
10
|
-
*
|
|
11
|
-
* @param namespace - The dictionary key to scope translations to
|
|
12
|
-
* @param locale - Optional locale override. If not provided, uses the current context locale
|
|
13
|
-
* @returns A translation function `t(key)` that returns the translated content for the given key
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```tsx
|
|
17
|
-
* const t = useI18n('IndexPage');
|
|
18
|
-
* const title = t('title'); // Returns translated string for 'IndexPage.title'
|
|
19
|
-
* const nestedContent = t('section.subtitle'); // Returns 'IndexPage.section.subtitle'
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
const useI18n = (namespace, locale) => {
|
|
23
|
-
const dictionaryContent = require_getIntlayer.getIntlayer(namespace, locale ?? require_server_serverContext.getServerContext(require_server_IntlayerServerProvider.IntlayerServerContext));
|
|
24
|
-
const t = (path) => {
|
|
25
|
-
if (!path) return dictionaryContent;
|
|
26
|
-
const pathArray = path.split(".");
|
|
27
|
-
let current = dictionaryContent;
|
|
28
|
-
for (const key of pathArray) {
|
|
29
|
-
current = current?.[key];
|
|
30
|
-
if (current === void 0) return dictionaryContent;
|
|
31
|
-
}
|
|
32
|
-
return current;
|
|
33
|
-
};
|
|
34
|
-
return t;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
//#endregion
|
|
38
|
-
exports.useI18n = useI18n;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../getIntlayer.cjs`),t=require(`./serverContext.cjs`),n=require(`./IntlayerServerProvider.cjs`),r=(r,i)=>{let a=e.getIntlayer(r,i??t.getServerContext(n.IntlayerServerContext));return e=>{if(!e)return a;let t=e.split(`.`),n=a;for(let e of t)if(n=n?.[e],n===void 0)return a;return n}};exports.useI18n=r;
|
|
39
2
|
//# sourceMappingURL=useI18n.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useI18n.cjs","names":["getIntlayer","getServerContext","IntlayerServerContext"],"sources":["../../../src/server/useI18n.ts"],"sourcesContent":["import type { ValidDotPathsFor } from '@intlayer/core';\nimport type {\n DictionaryKeys,\n DictionaryRegistryContent,\n GetSubPath,\n LocalesValues,\n} from '@intlayer/types';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * Hook that provides a translation function `t()` for accessing nested content by key.\n * This hook mimics the pattern found in libraries like i18next, next-intl, and vue-i18n.\n *\n * @param namespace - The dictionary key to scope translations to\n * @param locale - Optional locale override. If not provided, uses the current context locale\n * @returns A translation function `t(key)` that returns the translated content for the given key\n *\n * @example\n * ```tsx\n * const t = useI18n('IndexPage');\n * const title = t('title'); // Returns translated string for 'IndexPage.title'\n * const nestedContent = t('section.subtitle'); // Returns 'IndexPage.section.subtitle'\n * ```\n */\nexport const useI18n = <T extends DictionaryKeys>(\n namespace: T,\n locale?: LocalesValues\n) => {\n const localeTarget =\n locale ?? getServerContext<LocalesValues>(IntlayerServerContext);\n\n // Get the dictionary content for the namespace\n const dictionaryContent = getIntlayer(namespace, localeTarget);\n\n // Return the translation function\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n const t = <P extends ValidDotPathsFor<T>>(\n path: P\n ): GetSubPath<DeepTransformContent<DictionaryRegistryContent<T>>, P> => {\n if (!path) {\n return dictionaryContent as any;\n }\n\n const pathArray = (path as string).split('.');\n let current: any = dictionaryContent;\n\n for (const key of pathArray) {\n current = current?.[key];\n if (current === undefined) {\n // Return the whole dictionary as fallback if path is not found\n return dictionaryContent as any;\n }\n }\n\n return current;\n };\n\n return t;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useI18n.cjs","names":["getIntlayer","getServerContext","IntlayerServerContext"],"sources":["../../../src/server/useI18n.ts"],"sourcesContent":["import type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type {\n DictionaryKeys,\n DictionaryRegistryContent,\n GetSubPath,\n LocalesValues,\n} from '@intlayer/types';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * Hook that provides a translation function `t()` for accessing nested content by key.\n * This hook mimics the pattern found in libraries like i18next, next-intl, and vue-i18n.\n *\n * @param namespace - The dictionary key to scope translations to\n * @param locale - Optional locale override. If not provided, uses the current context locale\n * @returns A translation function `t(key)` that returns the translated content for the given key\n *\n * @example\n * ```tsx\n * const t = useI18n('IndexPage');\n * const title = t('title'); // Returns translated string for 'IndexPage.title'\n * const nestedContent = t('section.subtitle'); // Returns 'IndexPage.section.subtitle'\n * ```\n */\nexport const useI18n = <T extends DictionaryKeys>(\n namespace: T,\n locale?: LocalesValues\n) => {\n const localeTarget =\n locale ?? getServerContext<LocalesValues>(IntlayerServerContext);\n\n // Get the dictionary content for the namespace\n const dictionaryContent = getIntlayer(namespace, localeTarget);\n\n // Return the translation function\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n const t = <P extends ValidDotPathsFor<T>>(\n path: P\n ): GetSubPath<DeepTransformContent<DictionaryRegistryContent<T>>, P> => {\n if (!path) {\n return dictionaryContent as any;\n }\n\n const pathArray = (path as string).split('.');\n let current: any = dictionaryContent;\n\n for (const key of pathArray) {\n current = current?.[key];\n if (current === undefined) {\n // Return the whole dictionary as fallback if path is not found\n return dictionaryContent as any;\n }\n }\n\n return current;\n };\n\n return t;\n};\n"],"mappings":"oLA2Ba,GACX,EACA,IACG,CAKH,IAAM,EAAoBA,EAAAA,YAAY,EAHpC,GAAUC,EAAAA,iBAAgCC,EAAAA,sBAAsB,CAGJ,CAyB9D,MApBE,IACsE,CACtE,GAAI,CAAC,EACH,OAAO,EAGT,IAAM,EAAa,EAAgB,MAAM,IAAI,CACzC,EAAe,EAEnB,IAAK,IAAM,KAAO,EAEhB,GADA,EAAU,IAAU,GAChB,IAAY,IAAA,GAEd,OAAO,EAIX,OAAO"}
|
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_getIntlayer = require('../getIntlayer.cjs');
|
|
3
|
-
const require_server_serverContext = require('./serverContext.cjs');
|
|
4
|
-
const require_server_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
|
|
5
|
-
|
|
6
|
-
//#region src/server/useIntlayer.ts
|
|
7
|
-
/**
|
|
8
|
-
* On the server side, Hook that picking one dictionary by its key and return the content
|
|
9
|
-
*
|
|
10
|
-
* If the locale is not provided, it will use the locale from the server context
|
|
11
|
-
*/
|
|
12
|
-
const useIntlayer = (key, locale) => {
|
|
13
|
-
return require_getIntlayer.getIntlayer(key, locale ?? require_server_serverContext.getServerContext(require_server_IntlayerServerProvider.IntlayerServerContext));
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
//#endregion
|
|
17
|
-
exports.useIntlayer = useIntlayer;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../getIntlayer.cjs`),t=require(`./serverContext.cjs`),n=require(`./IntlayerServerProvider.cjs`),r=(r,i)=>e.getIntlayer(r,i??t.getServerContext(n.IntlayerServerContext));exports.useIntlayer=r;
|
|
18
2
|
//# sourceMappingURL=useIntlayer.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.cjs","names":["getIntlayer","getServerContext","IntlayerServerContext"],"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type { DictionaryKeys, LocalesValues } from '@intlayer/types';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useIntlayer = <T extends DictionaryKeys, L extends LocalesValues>(\n key: T,\n locale?: L\n) => {\n const localeTarget =\n locale ?? getServerContext<LocalesValues>(IntlayerServerContext);\n\n return getIntlayer<T, L>(key, localeTarget as L);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useIntlayer.cjs","names":["getIntlayer","getServerContext","IntlayerServerContext"],"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type { DictionaryKeys, LocalesValues } from '@intlayer/types';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useIntlayer = <T extends DictionaryKeys, L extends LocalesValues>(\n key: T,\n locale?: L\n) => {\n const localeTarget =\n locale ?? getServerContext<LocalesValues>(IntlayerServerContext);\n\n return getIntlayer<T, L>(key, localeTarget as L);\n};\n"],"mappings":"oLAUa,GACX,EACA,IAKOA,EAAAA,YAAkB,EAFvB,GAAUC,EAAAA,iBAAgCC,EAAAA,sBAAsB,CAElB"}
|
|
@@ -1,15 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
let react = require("react");
|
|
4
|
-
react = require_runtime.__toESM(react);
|
|
5
|
-
|
|
6
|
-
//#region src/server/useLoadDynamic.ts
|
|
7
|
-
const useLoadDynamic = (_key, promise) => {
|
|
8
|
-
/** @ts-ignore remove error Property 'cache' does not exist on type 'typeof React'. */
|
|
9
|
-
const cachedPromise = react.default.cache(async () => await promise)();
|
|
10
|
-
return react.default.use(cachedPromise);
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
//#endregion
|
|
14
|
-
exports.useLoadDynamic = useLoadDynamic;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`);let t=require(`react`);t=e.__toESM(t);const n=(e,n)=>{let r=t.default.cache(async()=>await n)();return t.default.use(r)};exports.useLoadDynamic=n;
|
|
15
2
|
//# sourceMappingURL=useLoadDynamic.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLoadDynamic.cjs","names":[],"sources":["../../../src/server/useLoadDynamic.ts"],"sourcesContent":["import react from 'react';\n\nexport const useLoadDynamic = <T>(_key: string, promise: Promise<T>): T => {\n /** @ts-ignore remove error Property 'cache' does not exist on type 'typeof React'. */\n const cachedPromise = react.cache(async () => await promise)();\n\n /** @ts-ignore remove error Property 'use' does not exist on type 'typeof React'. */\n const dictionary = react.use(cachedPromise);\n\n return dictionary;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLoadDynamic.cjs","names":[],"sources":["../../../src/server/useLoadDynamic.ts"],"sourcesContent":["import react from 'react';\n\nexport const useLoadDynamic = <T>(_key: string, promise: Promise<T>): T => {\n /** @ts-ignore remove error Property 'cache' does not exist on type 'typeof React'. */\n const cachedPromise = react.cache(async () => await promise)();\n\n /** @ts-ignore remove error Property 'use' does not exist on type 'typeof React'. */\n const dictionary = react.use(cachedPromise);\n\n return dictionary;\n};\n"],"mappings":"8JAEA,MAAa,GAAqB,EAAc,IAA2B,CAEzE,IAAM,EAAgB,EAAA,QAAM,MAAM,SAAY,MAAM,EAAQ,EAAE,CAK9D,OAFmB,EAAA,QAAM,IAAI,EAAc"}
|
|
@@ -1,25 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
const require_server_serverContext = require('./serverContext.cjs');
|
|
4
|
-
const require_server_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
|
|
5
|
-
let _intlayer_config_built = require("@intlayer/config/built");
|
|
6
|
-
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
7
|
-
|
|
8
|
-
//#region src/server/useLocale.ts
|
|
9
|
-
/**
|
|
10
|
-
* On the server side, Hook that picking one dictionary by its key and return the content
|
|
11
|
-
*
|
|
12
|
-
* If the locale is not provided, it will use the locale from the server context
|
|
13
|
-
*/
|
|
14
|
-
const useLocale = () => {
|
|
15
|
-
const { defaultLocale, locales: availableLocales } = _intlayer_config_built.default?.internationalization ?? {};
|
|
16
|
-
return {
|
|
17
|
-
locale: require_server_serverContext.getServerContext(require_server_IntlayerServerProvider.IntlayerServerContext) ?? defaultLocale,
|
|
18
|
-
defaultLocale,
|
|
19
|
-
availableLocales
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
exports.useLocale = useLocale;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`./serverContext.cjs`),n=require(`./IntlayerServerProvider.cjs`);let r=require(`@intlayer/config/built`);r=e.__toESM(r);const i=()=>{let{defaultLocale:e,locales:i}=r.default?.internationalization??{};return{locale:t.getServerContext(n.IntlayerServerContext)??e,defaultLocale:e,availableLocales:i}};exports.useLocale=i;
|
|
25
2
|
//# sourceMappingURL=useLocale.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.cjs","names":["configuration","getServerContext","IntlayerServerContext"],"sources":["../../../src/server/useLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { DeclaredLocales } from '@intlayer/types';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\ntype UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n};\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useLocale = (): UseLocaleResult => {\n const { defaultLocale, locales: availableLocales } =\n configuration?.internationalization ?? {};\n\n const locale = (getServerContext(IntlayerServerContext) ??\n defaultLocale) as DeclaredLocales;\n\n return { locale, defaultLocale, availableLocales };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocale.cjs","names":["configuration","getServerContext","IntlayerServerContext"],"sources":["../../../src/server/useLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { DeclaredLocales } from '@intlayer/types';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\ntype UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n};\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useLocale = (): UseLocaleResult => {\n const { defaultLocale, locales: availableLocales } =\n configuration?.internationalization ?? {};\n\n const locale = (getServerContext(IntlayerServerContext) ??\n defaultLocale) as DeclaredLocales;\n\n return { locale, defaultLocale, availableLocales };\n};\n"],"mappings":"0PAgBA,MAAa,MAAmC,CAC9C,GAAM,CAAE,gBAAe,QAAS,GAC9BA,EAAAA,SAAe,sBAAwB,EAAE,CAK3C,MAAO,CAAE,OAHOC,EAAAA,iBAAiBC,EAAAA,sBAAsB,EACrD,EAEe,gBAAe,mBAAkB"}
|
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
3
|
-
|
|
4
|
-
//#region src/IntlayerNode.tsx
|
|
5
|
-
const renderIntlayerNode = ({ children, value, additionalProps }) => {
|
|
6
|
-
const element = isValidElement(children) ? children : /* @__PURE__ */ jsx(Fragment$1, { children });
|
|
7
|
-
return new Proxy(element, { get(target, prop, receiver) {
|
|
8
|
-
if (prop === "value") return value;
|
|
9
|
-
if (additionalProps && Object.keys(additionalProps).includes(prop)) return additionalProps[prop];
|
|
10
|
-
return Reflect.get(target, prop, receiver);
|
|
11
|
-
} });
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
//#endregion
|
|
15
|
-
export { renderIntlayerNode };
|
|
1
|
+
import{isValidElement as e}from"react";import{Fragment as t,jsx as n}from"react/jsx-runtime";const r=({children:r,value:i,additionalProps:a})=>{let o=e(r)?r:n(t,{children:r});return new Proxy(o,{get(e,t,n){return t===`value`?i:a&&Object.keys(a).includes(t)?a[t]:Reflect.get(e,t,n)}})};export{r as renderIntlayerNode};
|
|
16
2
|
//# sourceMappingURL=IntlayerNode.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerNode.mjs","names":[],"sources":["../../src/IntlayerNode.tsx"],"sourcesContent":["import type { NodeProps } from '@intlayer/core';\nimport {\n isValidElement,\n type PropsWithChildren,\n type ReactElement,\n type ReactNode,\n} from 'react';\n\nexport type IntlayerNode<\n T = NodeProps['children'],\n AdditionalProps = Record<string, never>,\n> = ReactNode & {\n value: T;\n} & AdditionalProps;\n\ntype RenderIntlayerNodeProps<T> = PropsWithChildren<{\n value: T;\n children: ReactNode;\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 ReactElement, wrap it in a fragment\n const element: ReactElement<any> = isValidElement(children) ? (\n children\n ) : (\n <>{children}</>\n );\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 ReactElement, {\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.mjs","names":[],"sources":["../../src/IntlayerNode.tsx"],"sourcesContent":["import type { NodeProps } from '@intlayer/core/interpreter';\nimport {\n isValidElement,\n type PropsWithChildren,\n type ReactElement,\n type ReactNode,\n} from 'react';\n\nexport type IntlayerNode<\n T = NodeProps['children'],\n AdditionalProps = Record<string, never>,\n> = ReactNode & {\n value: T;\n} & AdditionalProps;\n\ntype RenderIntlayerNodeProps<T> = PropsWithChildren<{\n value: T;\n children: ReactNode;\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 ReactElement, wrap it in a fragment\n const element: ReactElement<any> = isValidElement(children) ? (\n children\n ) : (\n <>{children}</>\n );\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 ReactElement, {\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":"6FAqBA,MAAa,GAEX,CACA,WACA,QACA,qBACiD,CAEjD,IAAM,EAA6B,EAAe,EAAS,CACzD,EAEA,EAAA,EAAA,CAAG,WAAA,CAAY,CAKjB,OAAO,IAAI,MAAM,EAAyB,CACxC,IAAI,EAAQ,EAAM,EAAU,CAY1B,OAXI,IAAS,QACJ,EAIP,GACA,OAAO,KAAK,EAAgB,CAAC,SAAS,EAAe,CAE9C,EAAgB,GAGlB,QAAQ,IAAI,EAAQ,EAAM,EAAS,EAE7C,CAAC"}
|
|
@@ -1,95 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
|
-
import { jsx } from "react/jsx-runtime";
|
|
5
|
-
|
|
6
|
-
//#region src/UI/ContentSelector.tsx
|
|
7
|
-
const DEFAULT_PRESS_DETECT_DURATION = 250;
|
|
8
|
-
const ContentSelector = ({ children, onPress, onHover, onUnhover, onClickOutside: onUnselect, pressDuration = DEFAULT_PRESS_DETECT_DURATION, isSelecting: isSelectingProp, ...props }) => {
|
|
9
|
-
const divRef = useRef(null);
|
|
10
|
-
const [isHovered, setIsHovered] = useState(false);
|
|
11
|
-
const [isSelectingState, setIsSelectingState] = useState(isSelectingProp);
|
|
12
|
-
const pressTimerRef = useRef(null);
|
|
13
|
-
const isChildrenString = typeof children === "string";
|
|
14
|
-
const handleOnLongPress = () => {
|
|
15
|
-
setIsSelectingState(true);
|
|
16
|
-
onPress();
|
|
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
|
-
onUnhover?.();
|
|
39
|
-
setIsHovered(false);
|
|
40
|
-
clearPressTimer();
|
|
41
|
-
};
|
|
42
|
-
const handleClickOutside = useCallback((event) => {
|
|
43
|
-
if (divRef.current && !divRef.current.contains(event.target)) {
|
|
44
|
-
setIsSelectingState(false);
|
|
45
|
-
onUnselect?.();
|
|
46
|
-
}
|
|
47
|
-
}, [onUnselect]);
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
document.addEventListener("mousedown", handleClickOutside);
|
|
50
|
-
return () => {
|
|
51
|
-
document.removeEventListener("mousedown", handleClickOutside);
|
|
52
|
-
};
|
|
53
|
-
}, [handleClickOutside]);
|
|
54
|
-
const handleOnClick = (e) => {
|
|
55
|
-
if (isSelectingState) {
|
|
56
|
-
e.preventDefault();
|
|
57
|
-
e.stopPropagation();
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
const handleOnBlur = () => {
|
|
61
|
-
setIsSelectingState(false);
|
|
62
|
-
};
|
|
63
|
-
return /* @__PURE__ */ jsx("span", {
|
|
64
|
-
style: {
|
|
65
|
-
display: isChildrenString ? "inline" : "inline-block",
|
|
66
|
-
cursor: "pointer",
|
|
67
|
-
userSelect: "none",
|
|
68
|
-
borderRadius: "0.375rem",
|
|
69
|
-
outlineWidth: "2px",
|
|
70
|
-
outlineOffset: "4px",
|
|
71
|
-
outlineStyle: "solid",
|
|
72
|
-
outlineColor: isSelectingProp || isSelectingState || isHovered ? "inherit" : "transparent",
|
|
73
|
-
transition: "all 100ms 50ms ease-in-out"
|
|
74
|
-
},
|
|
75
|
-
role: "button",
|
|
76
|
-
tabIndex: 0,
|
|
77
|
-
onKeyUp: () => null,
|
|
78
|
-
onClick: handleOnClick,
|
|
79
|
-
onMouseDown: handleMouseDown,
|
|
80
|
-
onMouseUp: handleMouseUp,
|
|
81
|
-
onMouseLeave: handleMouseUp,
|
|
82
|
-
onTouchStart: handleMouseDown,
|
|
83
|
-
onTouchEnd: handleMouseUp,
|
|
84
|
-
onTouchCancel: handleMouseUp,
|
|
85
|
-
onBlur: handleOnBlur,
|
|
86
|
-
onMouseEnter: handleMouseEnter,
|
|
87
|
-
ref: divRef,
|
|
88
|
-
...props,
|
|
89
|
-
children
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
//#endregion
|
|
94
|
-
export { ContentSelector };
|
|
1
|
+
"use client";import{useCallback as e,useEffect as t,useRef as n,useState as r}from"react";import{jsx as i}from"react/jsx-runtime";const a=({children:a,onPress:o,onHover:s,onUnhover:c,onClickOutside:l,pressDuration:u=250,isSelecting:d,...f})=>{let p=n(null),[m,h]=r(!1),[g,_]=r(d),v=n(null),y=typeof a==`string`,b=()=>{_(!0),o()},x=()=>{v.current=setTimeout(()=>{b()},u)},S=()=>{v.current&&=(clearTimeout(v.current),null)},C=()=>{S(),x()},w=()=>{h(!0),s?.()},T=()=>{c?.(),h(!1),S()},E=e(e=>{p.current&&!p.current.contains(e.target)&&(_(!1),l?.())},[l]);return t(()=>(document.addEventListener(`mousedown`,E),()=>{document.removeEventListener(`mousedown`,E)}),[E]),i(`span`,{style:{display:y?`inline`:`inline-block`,cursor:`pointer`,userSelect:`none`,borderRadius:`0.375rem`,outlineWidth:`2px`,outlineOffset:`4px`,outlineStyle:`solid`,outlineColor:d||g||m?`inherit`:`transparent`,transition:`all 100ms 50ms ease-in-out`},role:`button`,tabIndex:0,onKeyUp:()=>null,onClick:e=>{g&&(e.preventDefault(),e.stopPropagation())},onMouseDown:C,onMouseUp:T,onMouseLeave:T,onTouchStart:C,onTouchEnd:T,onTouchCancel:T,onBlur:()=>{_(!1)},onMouseEnter:w,ref:p,...f,children:a})};export{a as ContentSelector};
|
|
95
2
|
//# sourceMappingURL=ContentSelector.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSelector.mjs","names":[],"sources":["../../../src/UI/ContentSelector.tsx"],"sourcesContent":["'use client';\n\nimport {\n type FC,\n type HTMLAttributes,\n type MouseEventHandler,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from 'react';\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<HTMLAttributes<HTMLDivElement>, 'content'>;\n\nexport const ContentSelector: FC<ContentSelectorProps> = ({\n children,\n onPress,\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 onPress();\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 onUnhover?.();\n setIsHovered(false);\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: 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.mjs","names":[],"sources":["../../../src/UI/ContentSelector.tsx"],"sourcesContent":["'use client';\n\nimport {\n type FC,\n type HTMLAttributes,\n type MouseEventHandler,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from 'react';\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<HTMLAttributes<HTMLDivElement>, 'content'>;\n\nexport const ContentSelector: FC<ContentSelectorProps> = ({\n children,\n onPress,\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 onPress();\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 onUnhover?.();\n setIsHovered(false);\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: 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":"kIAYA,MAWa,GAA6C,CACxD,WACA,UACA,UACA,YACA,eAAgB,EAChB,gBAAgB,IAChB,YAAa,EACb,GAAG,KACC,CACJ,IAAM,EAAS,EAAuB,KAAK,CACrC,CAAC,EAAW,GAAgB,EAAS,GAAM,CAC3C,CAAC,EAAkB,GAAuB,EAAS,EAAgB,CACnE,EAAgB,EAA6C,KAAK,CAClE,EAAmB,OAAO,GAAa,SAEvC,MAA0B,CAC9B,EAAoB,GAAK,CACzB,GAAS,EAGL,MAAwB,CAC5B,EAAc,QAAU,eAAiB,CACvC,GAAmB,EAClB,EAAc,EAGb,MAAwB,CAC5B,AAEE,EAAc,WADd,aAAa,EAAc,QAAQ,CACX,OAItB,MAAwB,CAC5B,GAAiB,CACjB,GAAiB,EAGb,MAAyB,CAC7B,EAAa,GAAK,CAClB,KAAW,EAGP,MAAsB,CAC1B,KAAa,CACb,EAAa,GAAM,CACnB,GAAiB,EAIb,EAAqB,EACxB,GAAsB,CACjB,EAAO,SAAW,CAAC,EAAO,QAAQ,SAAS,EAAM,OAAe,GAClE,EAAoB,GAAM,CAC1B,KAAc,GAGlB,CAAC,EAAW,CACb,CAyBD,OAvBA,OAEE,SAAS,iBAAiB,YAAa,EAAmB,KAE7C,CAEX,SAAS,oBAAoB,YAAa,EAAmB,GAG9D,CAAC,EAAmB,CAAC,CAetB,EAAC,OAAA,CACC,MAAO,CACL,QAAS,EAAmB,SAAW,eACvC,OAAQ,UACR,WAAY,OACZ,aAAc,WACd,aAAc,MACd,cAAe,MACf,aAAc,QACd,aACE,GAAmB,GAAoB,EACnC,UACA,cACN,WAAY,6BACb,CACD,KAAK,SACL,SAAU,EACV,YAAe,KACf,QA/BsD,GAAM,CAC1D,IACF,EAAE,gBAAgB,CAClB,EAAE,iBAAiB,GA6BnB,YAAa,EACb,UAAW,EACX,aAAc,EACd,aAAc,EACd,WAAY,EACZ,cAAe,EACf,WA/BuB,CAEzB,EAAoB,GAAM,EA8BxB,aAAc,EACd,IAAK,EACL,GAAI,EAEH,YACI"}
|
|
@@ -1,87 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { IntlayerEditorProvider } from "../editor/IntlayerEditorProvider.mjs";
|
|
4
|
-
import { localeInStorage, setLocaleInStorage as setLocaleInStorage$1 } from "./useLocaleStorage.mjs";
|
|
5
|
-
import { createContext, useContext, useEffect } from "react";
|
|
6
|
-
import { jsx } from "react/jsx-runtime";
|
|
7
|
-
import { localeResolver } from "@intlayer/core";
|
|
8
|
-
import { MessageKey, useCrossFrameState } from "@intlayer/editor-react";
|
|
9
|
-
import configuration from "@intlayer/config/built";
|
|
10
|
-
|
|
11
|
-
//#region src/client/IntlayerProvider.tsx
|
|
12
|
-
/**
|
|
13
|
-
* Context that stores the current locale on the client side.
|
|
14
|
-
*/
|
|
15
|
-
const IntlayerClientContext = createContext({
|
|
16
|
-
locale: localeInStorage ?? configuration?.internationalization?.defaultLocale,
|
|
17
|
-
setLocale: () => null,
|
|
18
|
-
isCookieEnabled: true,
|
|
19
|
-
disableEditor: false
|
|
20
|
-
});
|
|
21
|
-
/**
|
|
22
|
-
* Hook that provides the current Intlayer client context.
|
|
23
|
-
*
|
|
24
|
-
* @returns The current Intlayer context values.
|
|
25
|
-
*/
|
|
26
|
-
const useIntlayerContext = () => useContext(IntlayerClientContext);
|
|
27
|
-
/**
|
|
28
|
-
* Provider that stores the current locale on the client side.
|
|
29
|
-
*
|
|
30
|
-
* This component is focused on content delivery without the editor features.
|
|
31
|
-
*
|
|
32
|
-
* @param props - The provider props.
|
|
33
|
-
* @returns The provider component.
|
|
34
|
-
*/
|
|
35
|
-
const IntlayerProviderContent = ({ locale: localeProp, defaultLocale: defaultLocaleProp, children, setLocale: setLocaleProp, disableEditor, isCookieEnabled }) => {
|
|
36
|
-
const { internationalization } = configuration ?? {};
|
|
37
|
-
const { locales: availableLocales, defaultLocale: defaultLocaleConfig } = internationalization ?? {};
|
|
38
|
-
const initialLocale = localeProp ?? localeInStorage ?? defaultLocaleProp ?? defaultLocaleConfig;
|
|
39
|
-
const [currentLocale, setCurrentLocale] = useCrossFrameState(MessageKey.INTLAYER_CURRENT_LOCALE, initialLocale);
|
|
40
|
-
useEffect(() => {
|
|
41
|
-
if (localeProp && localeProp !== currentLocale) setCurrentLocale(localeProp);
|
|
42
|
-
}, [localeProp]);
|
|
43
|
-
const setLocaleBase = (newLocale) => {
|
|
44
|
-
if (currentLocale.toString() === newLocale.toString()) return;
|
|
45
|
-
if (!availableLocales?.map(String).includes(newLocale)) {
|
|
46
|
-
console.error(`Locale ${newLocale} is not available`);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
setCurrentLocale(newLocale);
|
|
50
|
-
setLocaleInStorage$1(newLocale, isCookieEnabled);
|
|
51
|
-
};
|
|
52
|
-
const setLocale = setLocaleProp ?? setLocaleBase;
|
|
53
|
-
const resolvedLocale = localeResolver(currentLocale);
|
|
54
|
-
return /* @__PURE__ */ jsx(IntlayerClientContext.Provider, {
|
|
55
|
-
value: {
|
|
56
|
-
locale: resolvedLocale,
|
|
57
|
-
setLocale,
|
|
58
|
-
disableEditor
|
|
59
|
-
},
|
|
60
|
-
children
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
/**
|
|
64
|
-
* Main provider for Intlayer in React applications.
|
|
65
|
-
*
|
|
66
|
-
* It includes the editor provider by default, allowing for live content editing
|
|
67
|
-
* if configured.
|
|
68
|
-
*
|
|
69
|
-
* @param props - The provider props.
|
|
70
|
-
* @returns The provider component with editor support.
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* ```tsx
|
|
74
|
-
* import { IntlayerProvider } from 'react-intlayer';
|
|
75
|
-
*
|
|
76
|
-
* const App = () => (
|
|
77
|
-
* <IntlayerProvider>
|
|
78
|
-
* <MyComponent />
|
|
79
|
-
* </IntlayerProvider>
|
|
80
|
-
* );
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
const IntlayerProvider = (props) => /* @__PURE__ */ jsx(IntlayerEditorProvider, { children: /* @__PURE__ */ jsx(IntlayerProviderContent, { ...props }) });
|
|
84
|
-
|
|
85
|
-
//#endregion
|
|
86
|
-
export { IntlayerClientContext, IntlayerProvider, IntlayerProviderContent, useIntlayerContext };
|
|
1
|
+
"use client";import{IntlayerEditorProvider as e}from"../editor/IntlayerEditorProvider.mjs";import{localeInStorage as t,setLocaleInStorage as n}from"./useLocaleStorage.mjs";import{createContext as r,useContext as i,useEffect as a}from"react";import{jsx as o}from"react/jsx-runtime";import{MessageKey as s,useCrossFrameState as c}from"@intlayer/editor-react";import l from"@intlayer/config/built";import{localeResolver as u}from"@intlayer/core/localization";const d=r({locale:t??l?.internationalization?.defaultLocale,setLocale:()=>null,isCookieEnabled:!0,disableEditor:!1}),f=()=>i(d),p=({locale:e,defaultLocale:r,children:i,setLocale:f,disableEditor:p,isCookieEnabled:m})=>{let{internationalization:h}=l??{},{locales:g,defaultLocale:_}=h??{},v=e??t??r??_,[y,b]=c(s.INTLAYER_CURRENT_LOCALE,v);a(()=>{e&&e!==y&&b(e)},[e]);let x=f??(e=>{if(y.toString()!==e.toString()){if(!g?.map(String).includes(e)){console.error(`Locale ${e} is not available`);return}b(e),n(e,m)}}),S=u(y);return o(d.Provider,{value:{locale:S,setLocale:x,disableEditor:p},children:i})},m=t=>o(e,{children:o(p,{...t})});export{d as IntlayerClientContext,m as IntlayerProvider,p as IntlayerProviderContent,f as useIntlayerContext};
|
|
87
2
|
//# sourceMappingURL=IntlayerProvider.mjs.map
|