@generaltranslation/react-core 11.0.0-odysseus.9 → 11.0.1
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/CHANGELOG.md +249 -0
- package/dist/components/branches/Plural.shared.cjs +1 -1
- package/dist/components/branches/Plural.shared.cjs.map +1 -1
- package/dist/components/branches/Plural.shared.mjs +1 -1
- package/dist/components/branches/Plural.shared.mjs.map +1 -1
- package/dist/components/helpers/InternalLocaleSelector.cjs +1 -1
- package/dist/components/helpers/InternalLocaleSelector.cjs.map +1 -1
- package/dist/components/helpers/InternalLocaleSelector.mjs +1 -1
- package/dist/components/helpers/InternalRegionSelector.cjs +1 -1
- package/dist/components/helpers/InternalRegionSelector.cjs.map +1 -1
- package/dist/components/helpers/InternalRegionSelector.mjs +1 -1
- package/dist/components/translation/T.cjs +1 -1
- package/dist/components/translation/T.cjs.map +1 -1
- package/dist/components/translation/T.mjs +1 -1
- package/dist/components/translation/T.mjs.map +1 -1
- package/dist/components/translation/T.rsc.cjs +1 -1
- package/dist/components/translation/T.rsc.cjs.map +1 -1
- package/dist/components/translation/T.rsc.mjs +1 -1
- package/dist/components/translation/T.rsc.mjs.map +1 -1
- package/dist/components-rsc.cjs +1 -1
- package/dist/components-rsc.d.ts +5 -5
- package/dist/components-rsc.mjs +1 -1
- package/dist/condition-store/singleton-operations.cjs +1 -1
- package/dist/condition-store/singleton-operations.cjs.map +1 -1
- package/dist/condition-store/singleton-operations.d.ts +2 -7
- package/dist/condition-store/singleton-operations.d.ts.map +1 -1
- package/dist/condition-store/singleton-operations.mjs +1 -1
- package/dist/condition-store/singleton-operations.mjs.map +1 -1
- package/dist/context/InternalGTProvider.cjs +1 -1
- package/dist/context/InternalGTProvider.mjs +1 -1
- package/dist/context/context.cjs +1 -1
- package/dist/context/context.cjs.map +1 -1
- package/dist/context/context.mjs +1 -1
- package/dist/context/context.mjs.map +1 -1
- package/dist/functions/translation/t.cjs +1 -1
- package/dist/functions/translation/t.cjs.map +1 -1
- package/dist/functions/translation/t.d.ts.map +1 -1
- package/dist/functions/translation/t.mjs +1 -1
- package/dist/functions/translation/t.mjs.map +1 -1
- package/dist/hooks/condition-store.cjs +1 -1
- package/dist/hooks/condition-store.cjs.map +1 -1
- package/dist/hooks/condition-store.mjs +1 -1
- package/dist/hooks/condition-store.mjs.map +1 -1
- package/dist/hooks/external-store/useSubscribeToTrackedLookups.cjs +2 -0
- package/dist/hooks/external-store/useSubscribeToTrackedLookups.cjs.map +1 -0
- package/dist/hooks/external-store/useSubscribeToTrackedLookups.mjs +2 -0
- package/dist/hooks/external-store/useSubscribeToTrackedLookups.mjs.map +1 -0
- package/dist/hooks/external-store/useTrackedDictionaryObjResolver.cjs +1 -1
- package/dist/hooks/external-store/useTrackedDictionaryObjResolver.cjs.map +1 -1
- package/dist/hooks/external-store/useTrackedDictionaryObjResolver.mjs +1 -1
- package/dist/hooks/external-store/useTrackedDictionaryObjResolver.mjs.map +1 -1
- package/dist/hooks/external-store/useTrackedDictionaryResolver.cjs +1 -1
- package/dist/hooks/external-store/useTrackedDictionaryResolver.cjs.map +1 -1
- package/dist/hooks/external-store/useTrackedDictionaryResolver.mjs +1 -1
- package/dist/hooks/external-store/useTrackedDictionaryResolver.mjs.map +1 -1
- package/dist/hooks/external-store/useTrackedTranslationResolver.cjs +1 -1
- package/dist/hooks/external-store/useTrackedTranslationResolver.cjs.map +1 -1
- package/dist/hooks/external-store/useTrackedTranslationResolver.d.ts.map +1 -1
- package/dist/hooks/external-store/useTrackedTranslationResolver.mjs +1 -1
- package/dist/hooks/external-store/useTrackedTranslationResolver.mjs.map +1 -1
- package/dist/hooks/external-store.cjs +1 -1
- package/dist/hooks/external-store.cjs.map +1 -1
- package/dist/hooks/external-store.mjs +1 -1
- package/dist/hooks/external-store.mjs.map +1 -1
- package/dist/hooks/i18n-config.cjs +1 -1
- package/dist/hooks/i18n-config.mjs +1 -1
- package/dist/hooks/useGT.cjs +1 -1
- package/dist/hooks/useGT.cjs.map +1 -1
- package/dist/hooks/useGT.mjs +1 -1
- package/dist/hooks/useGT.mjs.map +1 -1
- package/dist/hooks/useInternalLocaleSelector.cjs +1 -1
- package/dist/hooks/useInternalLocaleSelector.cjs.map +1 -1
- package/dist/hooks/useInternalLocaleSelector.d.ts +5 -4
- package/dist/hooks/useInternalLocaleSelector.d.ts.map +1 -1
- package/dist/hooks/useInternalLocaleSelector.mjs +1 -1
- package/dist/hooks/useInternalLocaleSelector.mjs.map +1 -1
- package/dist/hooks/useInternalRegionSelector.cjs +1 -1
- package/dist/hooks/useInternalRegionSelector.cjs.map +1 -1
- package/dist/hooks/useInternalRegionSelector.d.ts +9 -8
- package/dist/hooks/useInternalRegionSelector.d.ts.map +1 -1
- package/dist/hooks/useInternalRegionSelector.mjs +1 -1
- package/dist/hooks/useInternalRegionSelector.mjs.map +1 -1
- package/dist/hooks/useMessages.cjs +1 -1
- package/dist/hooks/useMessages.mjs +1 -1
- package/dist/hooks/useTranslations.cjs +1 -1
- package/dist/hooks/useTranslations.mjs +1 -1
- package/dist/hooks/utils/getShouldTranslate.cjs +1 -1
- package/dist/hooks/utils/getShouldTranslate.cjs.map +1 -1
- package/dist/hooks/utils/getShouldTranslate.mjs +1 -1
- package/dist/hooks/utils/getShouldTranslate.mjs.map +1 -1
- package/dist/hooks/utils/missing-translation.cjs +1 -1
- package/dist/hooks/utils/missing-translation.cjs.map +1 -1
- package/dist/hooks/utils/missing-translation.mjs +1 -1
- package/dist/hooks/utils/missing-translation.mjs.map +1 -1
- package/dist/hooks/utils.cjs +1 -1
- package/dist/hooks/utils.cjs.map +1 -1
- package/dist/hooks/utils.d.ts +2 -6
- package/dist/hooks/utils.d.ts.map +1 -1
- package/dist/hooks/utils.mjs +1 -1
- package/dist/hooks/utils.mjs.map +1 -1
- package/dist/hooks.cjs +1 -1
- package/dist/hooks.d.ts +4 -4
- package/dist/hooks.mjs +1 -1
- package/dist/i18n-cache/ReactI18nCache.cjs.map +1 -1
- package/dist/i18n-cache/ReactI18nCache.d.ts +1 -1
- package/dist/i18n-cache/ReactI18nCache.d.ts.map +1 -1
- package/dist/i18n-cache/ReactI18nCache.mjs.map +1 -1
- package/dist/i18n-store/I18nStore.cjs.map +1 -1
- package/dist/i18n-store/I18nStore.d.ts.map +1 -1
- package/dist/i18n-store/I18nStore.mjs.map +1 -1
- package/dist/i18n-store/singleton-operations.cjs +1 -1
- package/dist/i18n-store/singleton-operations.cjs.map +1 -1
- package/dist/i18n-store/singleton-operations.d.ts +2 -4
- package/dist/i18n-store/singleton-operations.d.ts.map +1 -1
- package/dist/i18n-store/singleton-operations.mjs +1 -1
- package/dist/i18n-store/singleton-operations.mjs.map +1 -1
- package/dist/i18n-store/storeTypes.d.ts +2 -1
- package/dist/i18n-store/storeTypes.d.ts.map +1 -1
- package/dist/pure.cjs +1 -1
- package/dist/pure.d.ts +7 -21
- package/dist/pure.mjs +1 -1
- package/dist/setup/i18nConfig.cjs +1 -1
- package/dist/setup/i18nConfig.cjs.map +1 -1
- package/dist/setup/i18nConfig.d.ts +31 -4
- package/dist/setup/i18nConfig.d.ts.map +1 -1
- package/dist/setup/i18nConfig.mjs +1 -1
- package/dist/setup/i18nConfig.mjs.map +1 -1
- package/dist/setup/initializeGTSRA.cjs +1 -1
- package/dist/setup/initializeGTSRA.cjs.map +1 -1
- package/dist/setup/initializeGTSRA.d.ts +2 -2
- package/dist/setup/initializeGTSRA.d.ts.map +1 -1
- package/dist/setup/initializeGTSRA.mjs +1 -1
- package/dist/setup/initializeGTSRA.mjs.map +1 -1
- package/dist/utils/rendering/createRenderPipeline.cjs +1 -1
- package/dist/utils/rendering/createRenderPipeline.cjs.map +1 -1
- package/dist/utils/rendering/createRenderPipeline.d.ts +2 -2
- package/dist/utils/rendering/createRenderPipeline.mjs +1 -1
- package/dist/utils/rendering/createRenderPipeline.mjs.map +1 -1
- package/dist/utils/rendering/renderDefaultChildren.shared.cjs +1 -1
- package/dist/utils/rendering/renderDefaultChildren.shared.cjs.map +1 -1
- package/dist/utils/rendering/renderDefaultChildren.shared.mjs +1 -1
- package/dist/utils/rendering/renderDefaultChildren.shared.mjs.map +1 -1
- package/dist/utils/rendering/renderPipeline.rsc.d.ts +1 -1
- package/dist/utils/rendering/renderPreparedT.shared.cjs +1 -1
- package/dist/utils/rendering/renderPreparedT.shared.cjs.map +1 -1
- package/dist/utils/rendering/renderPreparedT.shared.mjs +1 -1
- package/dist/utils/rendering/renderPreparedT.shared.mjs.map +1 -1
- package/dist/utils/rendering/renderTranslatedChildren.shared.cjs +1 -1
- package/dist/utils/rendering/renderTranslatedChildren.shared.cjs.map +1 -1
- package/dist/utils/rendering/renderTranslatedChildren.shared.mjs +1 -1
- package/dist/utils/rendering/renderTranslatedChildren.shared.mjs.map +1 -1
- package/dist/utils/translation/prepareT.shared.cjs +1 -1
- package/dist/utils/translation/prepareT.shared.cjs.map +1 -1
- package/dist/utils/translation/prepareT.shared.mjs +1 -1
- package/dist/utils/translation/prepareT.shared.mjs.map +1 -1
- package/dist/utils/translation/usePrepareT.cjs +1 -1
- package/dist/utils/translation/usePrepareT.mjs +1 -1
- package/dist/utils/types.d.ts +1 -43
- package/dist/utils/types.d.ts.map +1 -1
- package/package.json +5 -33
- package/dist/cookies.cjs +0 -1
- package/dist/cookies.d.ts +0 -2
- package/dist/cookies.mjs +0 -1
- package/dist/setup/initializeGTSPA.cjs +0 -2
- package/dist/setup/initializeGTSPA.cjs.map +0 -1
- package/dist/setup/initializeGTSPA.d.ts +0 -16
- package/dist/setup/initializeGTSPA.d.ts.map +0 -1
- package/dist/setup/initializeGTSPA.mjs +0 -2
- package/dist/setup/initializeGTSPA.mjs.map +0 -1
- package/dist/utils/cookies.cjs +0 -2
- package/dist/utils/cookies.cjs.map +0 -1
- package/dist/utils/cookies.d.ts +0 -16
- package/dist/utils/cookies.d.ts.map +0 -1
- package/dist/utils/cookies.mjs +0 -2
- package/dist/utils/cookies.mjs.map +0 -1
- package/dist/utils/dictionaries/flattenDictionary.cjs +0 -2
- package/dist/utils/dictionaries/flattenDictionary.cjs.map +0 -1
- package/dist/utils/dictionaries/flattenDictionary.d.ts +0 -15
- package/dist/utils/dictionaries/flattenDictionary.d.ts.map +0 -1
- package/dist/utils/dictionaries/flattenDictionary.mjs +0 -2
- package/dist/utils/dictionaries/flattenDictionary.mjs.map +0 -1
- package/dist/utils/dictionaries/getDictionaryEntry.cjs +0 -2
- package/dist/utils/dictionaries/getDictionaryEntry.cjs.map +0 -1
- package/dist/utils/dictionaries/getDictionaryEntry.d.ts +0 -8
- package/dist/utils/dictionaries/getDictionaryEntry.d.ts.map +0 -1
- package/dist/utils/dictionaries/getDictionaryEntry.mjs +0 -2
- package/dist/utils/dictionaries/getDictionaryEntry.mjs.map +0 -1
- package/dist/utils/dictionaries/getEntryAndMetadata.cjs +0 -2
- package/dist/utils/dictionaries/getEntryAndMetadata.cjs.map +0 -1
- package/dist/utils/dictionaries/getEntryAndMetadata.d.ts +0 -10
- package/dist/utils/dictionaries/getEntryAndMetadata.d.ts.map +0 -1
- package/dist/utils/dictionaries/getEntryAndMetadata.mjs +0 -2
- package/dist/utils/dictionaries/getEntryAndMetadata.mjs.map +0 -1
- package/dist/utils/dictionaries/indexDict.cjs +0 -2
- package/dist/utils/dictionaries/indexDict.cjs.map +0 -1
- package/dist/utils/dictionaries/indexDict.mjs +0 -2
- package/dist/utils/dictionaries/indexDict.mjs.map +0 -1
- package/dist/utils/dictionaries/isDictionaryEntry.cjs +0 -2
- package/dist/utils/dictionaries/isDictionaryEntry.cjs.map +0 -1
- package/dist/utils/dictionaries/isDictionaryEntry.d.ts +0 -12
- package/dist/utils/dictionaries/isDictionaryEntry.d.ts.map +0 -1
- package/dist/utils/dictionaries/isDictionaryEntry.mjs +0 -2
- package/dist/utils/dictionaries/isDictionaryEntry.mjs.map +0 -1
- package/dist/utils/dictionaries/mergeDictionaries.cjs +0 -2
- package/dist/utils/dictionaries/mergeDictionaries.cjs.map +0 -1
- package/dist/utils/dictionaries/mergeDictionaries.d.ts +0 -7
- package/dist/utils/dictionaries/mergeDictionaries.d.ts.map +0 -1
- package/dist/utils/dictionaries/mergeDictionaries.mjs +0 -2
- package/dist/utils/dictionaries/mergeDictionaries.mjs.map +0 -1
- package/dist/utils/internal/addGTIdentifier.d.ts +0 -8
- package/dist/utils/internal/addGTIdentifier.d.ts.map +0 -1
- package/dist/utils/internal/writeChildrenAsObjects.d.ts +0 -14
- package/dist/utils/internal/writeChildrenAsObjects.d.ts.map +0 -1
- package/dist/utils/variables/_getVariableProps.d.ts +0 -13
- package/dist/utils/variables/_getVariableProps.d.ts.map +0 -1
- package/dist/utils/variables/getVariableName.d.ts +0 -12
- package/dist/utils/variables/getVariableName.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRenderPipeline.mjs","names":[],"sources":["../../../src/utils/rendering/createRenderPipeline.ts"],"sourcesContent":["import {\n createRenderVariable,\n type VariableComponents,\n} from './createRenderVariable';\nimport {\n createRenderDefaultChildren,\n type RenderDefaultChildrenArgs,\n} from './renderDefaultChildren.shared';\nimport {\n createRenderTranslatedChildren,\n type RenderTranslatedChildrenArgs,\n} from './renderTranslatedChildren.shared';\nimport {\n createRenderPreparedT,\n type RenderPreparedTParams,\n} from './renderPreparedT.shared';\nimport type { ReactNode } from 'react';\nimport type { RenderVariable } from '../types';\n\n// Factory binding variable components to the shared rendering logic. The\n// renderVariable dependency injection stays internal to this factory: callsites\n// import a pre-instantiated pipeline (renderPipeline for the hook-based\n// variable components, renderPipeline.rsc for the RSC ones) instead of\n// threading renderVariable through every rendering call. This keeps shared\n// rendering code free of static imports of either variable implementation.\n\ntype RenderPipeline = {\n renderVariable: RenderVariable;\n renderDefaultChildren: (args: RenderDefaultChildrenArgs) => ReactNode;\n renderTranslatedChildren: (args: RenderTranslatedChildrenArgs) => ReactNode;\n renderPreparedT: (args: RenderPreparedTParams) => ReactNode;\n};\n\nfunction createRenderPipeline(components: VariableComponents): RenderPipeline {\n const renderVariable = createRenderVariable(components);\n const renderDefaultChildren = createRenderDefaultChildren({ renderVariable });\n const renderTranslatedChildren = createRenderTranslatedChildren({\n renderVariable,\n });\n const renderPreparedT = createRenderPreparedT({
|
|
1
|
+
{"version":3,"file":"createRenderPipeline.mjs","names":[],"sources":["../../../src/utils/rendering/createRenderPipeline.ts"],"sourcesContent":["import {\n createRenderVariable,\n type VariableComponents,\n} from './createRenderVariable';\nimport {\n createRenderDefaultChildren,\n type RenderDefaultChildrenArgs,\n} from './renderDefaultChildren.shared';\nimport {\n createRenderTranslatedChildren,\n type RenderTranslatedChildrenArgs,\n} from './renderTranslatedChildren.shared';\nimport {\n createRenderPreparedT,\n type RenderPreparedTParams,\n} from './renderPreparedT.shared';\nimport type { ReactNode } from 'react';\nimport type { RenderVariable } from '../types';\n\n// Factory binding variable components to the shared rendering logic. The\n// renderVariable dependency injection stays internal to this factory: callsites\n// import a pre-instantiated pipeline (renderPipeline for the hook-based\n// variable components, renderPipeline.rsc for the RSC ones) instead of\n// threading renderVariable through every rendering call. This keeps shared\n// rendering code free of static imports of either variable implementation.\n\ntype RenderPipeline = {\n renderVariable: RenderVariable;\n renderDefaultChildren: (args: RenderDefaultChildrenArgs) => ReactNode;\n renderTranslatedChildren: (args: RenderTranslatedChildrenArgs) => ReactNode;\n renderPreparedT: (args: RenderPreparedTParams) => ReactNode;\n};\n\nfunction createRenderPipeline(components: VariableComponents): RenderPipeline {\n const renderVariable = createRenderVariable(components);\n const renderDefaultChildren = createRenderDefaultChildren({ renderVariable });\n const renderTranslatedChildren = createRenderTranslatedChildren({\n renderVariable,\n });\n const renderPreparedT = createRenderPreparedT({\n renderDefaultChildren,\n renderTranslatedChildren,\n });\n\n return {\n renderVariable,\n renderDefaultChildren,\n renderTranslatedChildren,\n renderPreparedT,\n };\n}\n\n// ===== Exports ===== //\n\nexport { createRenderPipeline };\nexport type { RenderPipeline };\nexport type {\n RenderDefaultChildrenArgs,\n RenderPreparedTParams,\n RenderTranslatedChildrenArgs,\n};\n"],"mappings":"+SAiCA,SAAS,EAAqB,EAAgD,CAC5E,IAAM,EAAiB,EAAqB,EAAW,CACjD,EAAwB,EAA4B,CAAE,iBAAgB,CAAC,CACvE,EAA2B,EAA+B,CAC9D,iBACD,CAAC,CAMF,MAAO,CACL,iBACA,wBACA,2BACA,gBATsB,EAAsB,CAC5C,wBACA,2BACD,CAMgB,CAChB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require(`../../_virtual/_rolldown/runtime.cjs`),t=require(`../
|
|
1
|
+
const e=require(`../../_virtual/_rolldown/runtime.cjs`),t=require(`../variables/_getVariableProps.cjs`),n=require(`./getGTTag.cjs`),r=require(`../plurals/getPluralBranch.cjs`);let i=require(`generaltranslation/internal`),a=require(`react`);a=e.__toESM(a);function o({renderVariable:e}){return function({children:o,defaultLocale:s=i.libraryDefaultLocale,enableI18n:c}){let l=i=>{let o=n.getGTTag(i);if(t.isVariableElementProps(i.props)){let{variableType:n,variableValue:r,variableOptions:a,injectionType:o}=t.getVariableProps(i.props);return e({variableType:n,variableValue:r,variableOptions:a,locales:[s],enableI18n:c,injectionType:o})}if(o?.transformation===`plural`){let e=o.branches||{};return typeof i.props.n==`number`?d(r.getPluralBranch(i.props.n,[s],e)??i.props.children):i.props.children==null?null:d(i.props.children)}if(o?.transformation===`branch`){let{children:e,branch:t}=i.props,n=o.branches||{},r=t==null||t===``?void 0:t.toString();return d(r&&n[r]!==void 0?n[r]:e)}return o?.transformation===`fragment`?a.default.createElement(a.default.Fragment,{key:i.props.key,children:d(i.props.children)}):i.props.children?a.default.cloneElement(i,{...i.props,"data-_gt":void 0,children:d(i.props.children)}):a.default.cloneElement(i,{...i.props,"data-_gt":void 0})},u=e=>a.default.isValidElement(e)?l(e):e,d=e=>Array.isArray(e)?a.default.Children.map(e,u):u(e);return d(o)}}exports.createRenderDefaultChildren=o;
|
|
2
2
|
//# sourceMappingURL=renderDefaultChildren.shared.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderDefaultChildren.shared.cjs","names":["libraryDefaultLocale","getGTTag","isVariableElementProps","getVariableProps","getPluralBranch","React"],"sources":["../../../src/utils/rendering/renderDefaultChildren.shared.ts"],"sourcesContent":["import React, { ReactNode } from 'react';\nimport {\n getVariableProps,\n isVariableElementProps,\n} from '../variables/_getVariableProps';\nimport { libraryDefaultLocale } from 'generaltranslation/internal';\nimport { TaggedChild, TaggedChildren, TaggedElement } from '../types';\nimport { getGTTag } from './getGTTag';\nimport { getPluralBranch } from '../plurals/getPluralBranch';\nimport type { RenderVariable } from '../types';\n\n// Shared implementation: the variable renderer is dependency-injected by a\n// factory so neither code path statically imports the other's variable\n// components. Callsites use the pre-instantiated renderPipeline /\n// renderPipeline.rsc modules instead of importing this directly.\n\ntype RenderDefaultChildrenArgs = {\n children: TaggedChildren;\n defaultLocale: string;\n enableI18n: boolean;\n};\n\nexport type { RenderDefaultChildrenArgs };\n\nfunction createRenderDefaultChildren({\n renderVariable,\n}: {\n renderVariable: RenderVariable;\n}): (args: RenderDefaultChildrenArgs) => React.ReactNode {\n return function renderDefaultChildren({\n children,\n defaultLocale = libraryDefaultLocale,\n enableI18n,\n }: RenderDefaultChildrenArgs): React.ReactNode {\n const handleSingleChildElement = (child: TaggedElement): ReactNode => {\n const generaltranslation = getGTTag(child);\n\n // Variable\n if (isVariableElementProps(child.props)) {\n const { variableType, variableValue, variableOptions, injectionType } =\n getVariableProps(child.props);\n return renderVariable({\n variableType,\n variableValue,\n variableOptions,\n locales: [defaultLocale],\n enableI18n,\n injectionType,\n });\n }\n\n // Plural\n if (generaltranslation?.transformation === 'plural') {\n const branches = generaltranslation.branches || {};\n if (typeof child.props.n !== 'number') {\n return child.props.children != null\n ? handleChildren(child.props.children)\n : null;\n }\n const resolvedBranch = getPluralBranch(\n child.props.n,\n [defaultLocale],\n branches\n );\n return handleChildren(\n (resolvedBranch
|
|
1
|
+
{"version":3,"file":"renderDefaultChildren.shared.cjs","names":["libraryDefaultLocale","getGTTag","isVariableElementProps","getVariableProps","getPluralBranch","React"],"sources":["../../../src/utils/rendering/renderDefaultChildren.shared.ts"],"sourcesContent":["import React, { ReactNode } from 'react';\nimport {\n getVariableProps,\n isVariableElementProps,\n} from '../variables/_getVariableProps';\nimport { libraryDefaultLocale } from 'generaltranslation/internal';\nimport { TaggedChild, TaggedChildren, TaggedElement } from '../types';\nimport { getGTTag } from './getGTTag';\nimport { getPluralBranch } from '../plurals/getPluralBranch';\nimport type { RenderVariable } from '../types';\n\n// Shared implementation: the variable renderer is dependency-injected by a\n// factory so neither code path statically imports the other's variable\n// components. Callsites use the pre-instantiated renderPipeline /\n// renderPipeline.rsc modules instead of importing this directly.\n\ntype RenderDefaultChildrenArgs = {\n children: TaggedChildren;\n defaultLocale: string;\n enableI18n: boolean;\n};\n\nexport type { RenderDefaultChildrenArgs };\n\nfunction createRenderDefaultChildren({\n renderVariable,\n}: {\n renderVariable: RenderVariable;\n}): (args: RenderDefaultChildrenArgs) => React.ReactNode {\n return function renderDefaultChildren({\n children,\n defaultLocale = libraryDefaultLocale,\n enableI18n,\n }: RenderDefaultChildrenArgs): React.ReactNode {\n const handleSingleChildElement = (child: TaggedElement): ReactNode => {\n const generaltranslation = getGTTag(child);\n\n // Variable\n if (isVariableElementProps(child.props)) {\n const { variableType, variableValue, variableOptions, injectionType } =\n getVariableProps(child.props);\n return renderVariable({\n variableType,\n variableValue,\n variableOptions,\n locales: [defaultLocale],\n enableI18n,\n injectionType,\n });\n }\n\n // Plural\n if (generaltranslation?.transformation === 'plural') {\n const branches = generaltranslation.branches || {};\n if (typeof child.props.n !== 'number') {\n return child.props.children != null\n ? handleChildren(child.props.children)\n : null;\n }\n const resolvedBranch = getPluralBranch(\n child.props.n,\n [defaultLocale],\n branches\n );\n return handleChildren(\n (resolvedBranch != null\n ? resolvedBranch\n : child.props.children) as TaggedChildren\n );\n }\n\n // Branch\n if (generaltranslation?.transformation === 'branch') {\n const { children, branch } = child.props;\n const branches = generaltranslation.branches || {};\n const branchKey =\n branch == null || branch === '' ? undefined : branch.toString();\n return handleChildren(\n branchKey && branches[branchKey] !== undefined\n ? branches[branchKey]\n : children\n );\n }\n\n // Fragment\n if (generaltranslation?.transformation === 'fragment') {\n return React.createElement(React.Fragment, {\n key: child.props.key,\n children: handleChildren(child.props.children),\n });\n }\n\n // Default\n if (child.props.children) {\n return React.cloneElement(child, {\n ...child.props,\n 'data-_gt': undefined,\n children: handleChildren(child.props.children) as TaggedChildren,\n });\n }\n return React.cloneElement(child, {\n ...child.props,\n 'data-_gt': undefined,\n });\n };\n\n const handleSingleChild = (child: TaggedChild): ReactNode => {\n if (React.isValidElement(child)) {\n return handleSingleChildElement(child);\n }\n return child;\n };\n\n const handleChildren = (children: TaggedChildren): ReactNode => {\n return Array.isArray(children)\n ? React.Children.map(children, handleSingleChild)\n : handleSingleChild(children);\n };\n\n return handleChildren(children);\n };\n}\n\nexport { createRenderDefaultChildren };\n"],"mappings":"+PAwBA,SAAS,EAA4B,CACnC,kBAGuD,CACvD,OAAO,SAA+B,CACpC,WACA,gBAAgBA,EAAAA,qBAChB,cAC6C,CAC7C,IAAM,EAA4B,GAAoC,CACpE,IAAM,EAAqBC,EAAAA,SAAS,EAAM,CAG1C,GAAIC,EAAAA,uBAAuB,EAAM,MAAM,CAAE,CACvC,GAAM,CAAE,eAAc,gBAAe,kBAAiB,iBACpDC,EAAAA,iBAAiB,EAAM,MAAM,CAC/B,OAAO,EAAe,CACpB,eACA,gBACA,kBACA,QAAS,CAAC,EAAc,CACxB,aACA,gBACD,CAAC,CAIJ,GAAI,GAAoB,iBAAmB,SAAU,CACnD,IAAM,EAAW,EAAmB,UAAY,EAAE,CAWlD,OAVI,OAAO,EAAM,MAAM,GAAM,SAUtB,EALgBC,EAAAA,gBACrB,EAAM,MAAM,EACZ,CAAC,EAAc,CACf,EAGC,EAEG,EAAM,MAAM,SACjB,CAbQ,EAAM,MAAM,UAAY,KAE3B,KADA,EAAe,EAAM,MAAM,SAAS,CAgB5C,GAAI,GAAoB,iBAAmB,SAAU,CACnD,GAAM,CAAE,WAAU,UAAW,EAAM,MAC7B,EAAW,EAAmB,UAAY,EAAE,CAC5C,EACJ,GAAU,MAAQ,IAAW,GAAK,IAAA,GAAY,EAAO,UAAU,CACjE,OAAO,EACL,GAAa,EAAS,KAAe,IAAA,GACjC,EAAS,GACT,EACL,CAmBH,OAfI,GAAoB,iBAAmB,WAClCC,EAAAA,QAAM,cAAcA,EAAAA,QAAM,SAAU,CACzC,IAAK,EAAM,MAAM,IACjB,SAAU,EAAe,EAAM,MAAM,SAAS,CAC/C,CAAC,CAIA,EAAM,MAAM,SACPA,EAAAA,QAAM,aAAa,EAAO,CAC/B,GAAG,EAAM,MACT,WAAY,IAAA,GACZ,SAAU,EAAe,EAAM,MAAM,SAAS,CAC/C,CAAC,CAEGA,EAAAA,QAAM,aAAa,EAAO,CAC/B,GAAG,EAAM,MACT,WAAY,IAAA,GACb,CAAC,EAGE,EAAqB,GACrBA,EAAAA,QAAM,eAAe,EAAM,CACtB,EAAyB,EAAM,CAEjC,EAGH,EAAkB,GACf,MAAM,QAAQ,EAAS,CAC1BA,EAAAA,QAAM,SAAS,IAAI,EAAU,EAAkB,CAC/C,EAAkB,EAAS,CAGjC,OAAO,EAAe,EAAS"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{getVariableProps as e,isVariableElementProps as t}from"../variables/_getVariableProps.mjs";import{getGTTag as n}from"./getGTTag.mjs";import{getPluralBranch as r}from"../plurals/getPluralBranch.mjs";import{libraryDefaultLocale as i}from"generaltranslation/internal";import a from"react";function o({renderVariable:o}){return function({children:s,defaultLocale:c=i,enableI18n:l}){let u=i=>{let s=n(i);if(t(i.props)){let{variableType:t,variableValue:n,variableOptions:r,injectionType:a}=e(i.props);return o({variableType:t,variableValue:n,variableOptions:r,locales:[c],enableI18n:l,injectionType:a})}if(s?.transformation===`plural`){let e=s.branches||{};return typeof i.props.n==`number`?f(r(i.props.n,[c],e)??i.props.children):i.props.children==null?null:f(i.props.children)}if(s?.transformation===`branch`){let{children:e,branch:t}=i.props,n=s.branches||{},r=t==null||t===``?void 0:t.toString();return f(r&&n[r]!==void 0?n[r]:e)}return s?.transformation===`fragment`?a.createElement(a.Fragment,{key:i.props.key,children:f(i.props.children)}):i.props.children?a.cloneElement(i,{...i.props,"data-_gt":void 0,children:f(i.props.children)}):a.cloneElement(i,{...i.props,"data-_gt":void 0})},d=e=>a.isValidElement(e)?u(e):e,f=e=>Array.isArray(e)?a.Children.map(e,d):d(e);return f(s)}}export{o as createRenderDefaultChildren};
|
|
2
2
|
//# sourceMappingURL=renderDefaultChildren.shared.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderDefaultChildren.shared.mjs","names":[],"sources":["../../../src/utils/rendering/renderDefaultChildren.shared.ts"],"sourcesContent":["import React, { ReactNode } from 'react';\nimport {\n getVariableProps,\n isVariableElementProps,\n} from '../variables/_getVariableProps';\nimport { libraryDefaultLocale } from 'generaltranslation/internal';\nimport { TaggedChild, TaggedChildren, TaggedElement } from '../types';\nimport { getGTTag } from './getGTTag';\nimport { getPluralBranch } from '../plurals/getPluralBranch';\nimport type { RenderVariable } from '../types';\n\n// Shared implementation: the variable renderer is dependency-injected by a\n// factory so neither code path statically imports the other's variable\n// components. Callsites use the pre-instantiated renderPipeline /\n// renderPipeline.rsc modules instead of importing this directly.\n\ntype RenderDefaultChildrenArgs = {\n children: TaggedChildren;\n defaultLocale: string;\n enableI18n: boolean;\n};\n\nexport type { RenderDefaultChildrenArgs };\n\nfunction createRenderDefaultChildren({\n renderVariable,\n}: {\n renderVariable: RenderVariable;\n}): (args: RenderDefaultChildrenArgs) => React.ReactNode {\n return function renderDefaultChildren({\n children,\n defaultLocale = libraryDefaultLocale,\n enableI18n,\n }: RenderDefaultChildrenArgs): React.ReactNode {\n const handleSingleChildElement = (child: TaggedElement): ReactNode => {\n const generaltranslation = getGTTag(child);\n\n // Variable\n if (isVariableElementProps(child.props)) {\n const { variableType, variableValue, variableOptions, injectionType } =\n getVariableProps(child.props);\n return renderVariable({\n variableType,\n variableValue,\n variableOptions,\n locales: [defaultLocale],\n enableI18n,\n injectionType,\n });\n }\n\n // Plural\n if (generaltranslation?.transformation === 'plural') {\n const branches = generaltranslation.branches || {};\n if (typeof child.props.n !== 'number') {\n return child.props.children != null\n ? handleChildren(child.props.children)\n : null;\n }\n const resolvedBranch = getPluralBranch(\n child.props.n,\n [defaultLocale],\n branches\n );\n return handleChildren(\n (resolvedBranch
|
|
1
|
+
{"version":3,"file":"renderDefaultChildren.shared.mjs","names":[],"sources":["../../../src/utils/rendering/renderDefaultChildren.shared.ts"],"sourcesContent":["import React, { ReactNode } from 'react';\nimport {\n getVariableProps,\n isVariableElementProps,\n} from '../variables/_getVariableProps';\nimport { libraryDefaultLocale } from 'generaltranslation/internal';\nimport { TaggedChild, TaggedChildren, TaggedElement } from '../types';\nimport { getGTTag } from './getGTTag';\nimport { getPluralBranch } from '../plurals/getPluralBranch';\nimport type { RenderVariable } from '../types';\n\n// Shared implementation: the variable renderer is dependency-injected by a\n// factory so neither code path statically imports the other's variable\n// components. Callsites use the pre-instantiated renderPipeline /\n// renderPipeline.rsc modules instead of importing this directly.\n\ntype RenderDefaultChildrenArgs = {\n children: TaggedChildren;\n defaultLocale: string;\n enableI18n: boolean;\n};\n\nexport type { RenderDefaultChildrenArgs };\n\nfunction createRenderDefaultChildren({\n renderVariable,\n}: {\n renderVariable: RenderVariable;\n}): (args: RenderDefaultChildrenArgs) => React.ReactNode {\n return function renderDefaultChildren({\n children,\n defaultLocale = libraryDefaultLocale,\n enableI18n,\n }: RenderDefaultChildrenArgs): React.ReactNode {\n const handleSingleChildElement = (child: TaggedElement): ReactNode => {\n const generaltranslation = getGTTag(child);\n\n // Variable\n if (isVariableElementProps(child.props)) {\n const { variableType, variableValue, variableOptions, injectionType } =\n getVariableProps(child.props);\n return renderVariable({\n variableType,\n variableValue,\n variableOptions,\n locales: [defaultLocale],\n enableI18n,\n injectionType,\n });\n }\n\n // Plural\n if (generaltranslation?.transformation === 'plural') {\n const branches = generaltranslation.branches || {};\n if (typeof child.props.n !== 'number') {\n return child.props.children != null\n ? handleChildren(child.props.children)\n : null;\n }\n const resolvedBranch = getPluralBranch(\n child.props.n,\n [defaultLocale],\n branches\n );\n return handleChildren(\n (resolvedBranch != null\n ? resolvedBranch\n : child.props.children) as TaggedChildren\n );\n }\n\n // Branch\n if (generaltranslation?.transformation === 'branch') {\n const { children, branch } = child.props;\n const branches = generaltranslation.branches || {};\n const branchKey =\n branch == null || branch === '' ? undefined : branch.toString();\n return handleChildren(\n branchKey && branches[branchKey] !== undefined\n ? branches[branchKey]\n : children\n );\n }\n\n // Fragment\n if (generaltranslation?.transformation === 'fragment') {\n return React.createElement(React.Fragment, {\n key: child.props.key,\n children: handleChildren(child.props.children),\n });\n }\n\n // Default\n if (child.props.children) {\n return React.cloneElement(child, {\n ...child.props,\n 'data-_gt': undefined,\n children: handleChildren(child.props.children) as TaggedChildren,\n });\n }\n return React.cloneElement(child, {\n ...child.props,\n 'data-_gt': undefined,\n });\n };\n\n const handleSingleChild = (child: TaggedChild): ReactNode => {\n if (React.isValidElement(child)) {\n return handleSingleChildElement(child);\n }\n return child;\n };\n\n const handleChildren = (children: TaggedChildren): ReactNode => {\n return Array.isArray(children)\n ? React.Children.map(children, handleSingleChild)\n : handleSingleChild(children);\n };\n\n return handleChildren(children);\n };\n}\n\nexport { createRenderDefaultChildren };\n"],"mappings":"qSAwBA,SAAS,EAA4B,CACnC,kBAGuD,CACvD,OAAO,SAA+B,CACpC,WACA,gBAAgB,EAChB,cAC6C,CAC7C,IAAM,EAA4B,GAAoC,CACpE,IAAM,EAAqB,EAAS,EAAM,CAG1C,GAAI,EAAuB,EAAM,MAAM,CAAE,CACvC,GAAM,CAAE,eAAc,gBAAe,kBAAiB,iBACpD,EAAiB,EAAM,MAAM,CAC/B,OAAO,EAAe,CACpB,eACA,gBACA,kBACA,QAAS,CAAC,EAAc,CACxB,aACA,gBACD,CAAC,CAIJ,GAAI,GAAoB,iBAAmB,SAAU,CACnD,IAAM,EAAW,EAAmB,UAAY,EAAE,CAWlD,OAVI,OAAO,EAAM,MAAM,GAAM,SAUtB,EALgB,EACrB,EAAM,MAAM,EACZ,CAAC,EAAc,CACf,EAGC,EAEG,EAAM,MAAM,SACjB,CAbQ,EAAM,MAAM,UAAY,KAE3B,KADA,EAAe,EAAM,MAAM,SAAS,CAgB5C,GAAI,GAAoB,iBAAmB,SAAU,CACnD,GAAM,CAAE,WAAU,UAAW,EAAM,MAC7B,EAAW,EAAmB,UAAY,EAAE,CAC5C,EACJ,GAAU,MAAQ,IAAW,GAAK,IAAA,GAAY,EAAO,UAAU,CACjE,OAAO,EACL,GAAa,EAAS,KAAe,IAAA,GACjC,EAAS,GACT,EACL,CAmBH,OAfI,GAAoB,iBAAmB,WAClC,EAAM,cAAc,EAAM,SAAU,CACzC,IAAK,EAAM,MAAM,IACjB,SAAU,EAAe,EAAM,MAAM,SAAS,CAC/C,CAAC,CAIA,EAAM,MAAM,SACP,EAAM,aAAa,EAAO,CAC/B,GAAG,EAAM,MACT,WAAY,IAAA,GACZ,SAAU,EAAe,EAAM,MAAM,SAAS,CAC/C,CAAC,CAEG,EAAM,aAAa,EAAO,CAC/B,GAAG,EAAM,MACT,WAAY,IAAA,GACb,CAAC,EAGE,EAAqB,GACrB,EAAM,eAAe,EAAM,CACtB,EAAyB,EAAM,CAEjC,EAGH,EAAkB,GACf,MAAM,QAAQ,EAAS,CAC1B,EAAM,SAAS,IAAI,EAAU,EAAkB,CAC/C,EAAkB,EAAS,CAGjC,OAAO,EAAe,EAAS"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RenderVariable } from "../types.js";
|
|
2
|
-
import { RenderPreparedTParams } from "./renderPreparedT.shared.js";
|
|
3
2
|
import { RenderDefaultChildrenArgs } from "./renderDefaultChildren.shared.js";
|
|
4
3
|
import { RenderTranslatedChildrenArgs } from "./renderTranslatedChildren.shared.js";
|
|
4
|
+
import { RenderPreparedTParams } from "./renderPreparedT.shared.js";
|
|
5
5
|
import * as _$react from "react";
|
|
6
6
|
|
|
7
7
|
//#region src/utils/rendering/renderPipeline.rsc.d.ts
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
function e({renderDefaultChildren:e,renderTranslatedChildren:t}){function n({taggedSourceChildren:e,targetJsxChildren:t,locale:n,defaultLocale:a,enableI18n:o,shouldTranslate:s}){return!s||t==null?r({taggedSourceChildren:e,defaultLocale:a,enableI18n:o}):i({taggedSourceChildren:e,targetJsxChildren:t,locales:[n,a],enableI18n:o})}function r({taggedSourceChildren:t,defaultLocale:n,enableI18n:r}){return e({children:t,defaultLocale:n,enableI18n:r})}function i({taggedSourceChildren:e,targetJsxChildren:n,locales:r,enableI18n:i}){return t({source:e,target:n,locales:r,enableI18n:i})}return n}exports.createRenderPreparedT=e;
|
|
2
2
|
//# sourceMappingURL=renderPreparedT.shared.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderPreparedT.shared.cjs","names":[
|
|
1
|
+
{"version":3,"file":"renderPreparedT.shared.cjs","names":[],"sources":["../../../src/utils/rendering/renderPreparedT.shared.ts"],"sourcesContent":["import type { RenderDefaultChildrenArgs } from './renderDefaultChildren.shared';\nimport type { RenderTranslatedChildrenArgs } from './renderTranslatedChildren.shared';\nimport type { JsxChildren } from 'generaltranslation/types';\nimport type { ReactNode } from 'react';\nimport type { TaggedChildren } from '../types';\n\n// Shared rendering logic. The child renderers are injected so the RSC code path\n// never statically imports the hook-based variable components, and so the\n// pipeline can build them once and share them. This module must stay free of\n// hook/context imports so it can be reached from the components-rsc entrypoint.\n\ntype RenderPreparedTParams = {\n taggedSourceChildren: TaggedChildren;\n targetJsxChildren: JsxChildren | null | undefined;\n locale: string;\n defaultLocale: string;\n enableI18n: boolean;\n shouldTranslate: boolean;\n};\n\nfunction createRenderPreparedT({\n renderDefaultChildren,\n renderTranslatedChildren,\n}: {\n renderDefaultChildren: (args: RenderDefaultChildrenArgs) => ReactNode;\n renderTranslatedChildren: (args: RenderTranslatedChildrenArgs) => ReactNode;\n}): (args: RenderPreparedTParams) => ReactNode {\n function renderPreparedT({\n taggedSourceChildren,\n targetJsxChildren,\n locale,\n defaultLocale,\n enableI18n,\n shouldTranslate,\n }: RenderPreparedTParams): ReactNode {\n if (!shouldTranslate || targetJsxChildren == null) {\n return renderSource({\n taggedSourceChildren,\n defaultLocale,\n enableI18n,\n });\n }\n\n return renderTarget({\n taggedSourceChildren,\n targetJsxChildren,\n locales: [locale, defaultLocale],\n enableI18n,\n });\n }\n\n function renderSource({\n taggedSourceChildren,\n defaultLocale,\n enableI18n,\n }: {\n taggedSourceChildren: TaggedChildren;\n defaultLocale: string;\n enableI18n: boolean;\n }): ReactNode {\n return renderDefaultChildren({\n children: taggedSourceChildren,\n defaultLocale,\n enableI18n,\n });\n }\n\n function renderTarget({\n taggedSourceChildren,\n targetJsxChildren,\n locales,\n enableI18n,\n }: {\n taggedSourceChildren: TaggedChildren;\n targetJsxChildren: JsxChildren;\n locales: string[];\n enableI18n: boolean;\n }): ReactNode {\n return renderTranslatedChildren({\n source: taggedSourceChildren,\n target: targetJsxChildren,\n locales,\n enableI18n,\n });\n }\n\n return renderPreparedT;\n}\n\nexport { createRenderPreparedT };\nexport type { RenderPreparedTParams };\n"],"mappings":"AAoBA,SAAS,EAAsB,CAC7B,wBACA,4BAI6C,CAC7C,SAAS,EAAgB,CACvB,uBACA,oBACA,SACA,gBACA,aACA,mBACmC,CASnC,MARI,CAAC,GAAmB,GAAqB,KACpC,EAAa,CAClB,uBACA,gBACA,aACD,CAAC,CAGG,EAAa,CAClB,uBACA,oBACA,QAAS,CAAC,EAAQ,EAAc,CAChC,aACD,CAAC,CAGJ,SAAS,EAAa,CACpB,uBACA,gBACA,cAKY,CACZ,OAAO,EAAsB,CAC3B,SAAU,EACV,gBACA,aACD,CAAC,CAGJ,SAAS,EAAa,CACpB,uBACA,oBACA,UACA,cAMY,CACZ,OAAO,EAAyB,CAC9B,OAAQ,EACR,OAAQ,EACR,UACA,aACD,CAAC,CAGJ,OAAO"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
function e({renderDefaultChildren:e,renderTranslatedChildren:t}){function n({taggedSourceChildren:e,targetJsxChildren:t,locale:n,defaultLocale:a,enableI18n:o,shouldTranslate:s}){return!s||t==null?r({taggedSourceChildren:e,defaultLocale:a,enableI18n:o}):i({taggedSourceChildren:e,targetJsxChildren:t,locales:[n,a],enableI18n:o})}function r({taggedSourceChildren:t,defaultLocale:n,enableI18n:r}){return e({children:t,defaultLocale:n,enableI18n:r})}function i({taggedSourceChildren:e,targetJsxChildren:n,locales:r,enableI18n:i}){return t({source:e,target:n,locales:r,enableI18n:i})}return n}export{e as createRenderPreparedT};
|
|
2
2
|
//# sourceMappingURL=renderPreparedT.shared.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderPreparedT.shared.mjs","names":[],"sources":["../../../src/utils/rendering/renderPreparedT.shared.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"renderPreparedT.shared.mjs","names":[],"sources":["../../../src/utils/rendering/renderPreparedT.shared.ts"],"sourcesContent":["import type { RenderDefaultChildrenArgs } from './renderDefaultChildren.shared';\nimport type { RenderTranslatedChildrenArgs } from './renderTranslatedChildren.shared';\nimport type { JsxChildren } from 'generaltranslation/types';\nimport type { ReactNode } from 'react';\nimport type { TaggedChildren } from '../types';\n\n// Shared rendering logic. The child renderers are injected so the RSC code path\n// never statically imports the hook-based variable components, and so the\n// pipeline can build them once and share them. This module must stay free of\n// hook/context imports so it can be reached from the components-rsc entrypoint.\n\ntype RenderPreparedTParams = {\n taggedSourceChildren: TaggedChildren;\n targetJsxChildren: JsxChildren | null | undefined;\n locale: string;\n defaultLocale: string;\n enableI18n: boolean;\n shouldTranslate: boolean;\n};\n\nfunction createRenderPreparedT({\n renderDefaultChildren,\n renderTranslatedChildren,\n}: {\n renderDefaultChildren: (args: RenderDefaultChildrenArgs) => ReactNode;\n renderTranslatedChildren: (args: RenderTranslatedChildrenArgs) => ReactNode;\n}): (args: RenderPreparedTParams) => ReactNode {\n function renderPreparedT({\n taggedSourceChildren,\n targetJsxChildren,\n locale,\n defaultLocale,\n enableI18n,\n shouldTranslate,\n }: RenderPreparedTParams): ReactNode {\n if (!shouldTranslate || targetJsxChildren == null) {\n return renderSource({\n taggedSourceChildren,\n defaultLocale,\n enableI18n,\n });\n }\n\n return renderTarget({\n taggedSourceChildren,\n targetJsxChildren,\n locales: [locale, defaultLocale],\n enableI18n,\n });\n }\n\n function renderSource({\n taggedSourceChildren,\n defaultLocale,\n enableI18n,\n }: {\n taggedSourceChildren: TaggedChildren;\n defaultLocale: string;\n enableI18n: boolean;\n }): ReactNode {\n return renderDefaultChildren({\n children: taggedSourceChildren,\n defaultLocale,\n enableI18n,\n });\n }\n\n function renderTarget({\n taggedSourceChildren,\n targetJsxChildren,\n locales,\n enableI18n,\n }: {\n taggedSourceChildren: TaggedChildren;\n targetJsxChildren: JsxChildren;\n locales: string[];\n enableI18n: boolean;\n }): ReactNode {\n return renderTranslatedChildren({\n source: taggedSourceChildren,\n target: targetJsxChildren,\n locales,\n enableI18n,\n });\n }\n\n return renderPreparedT;\n}\n\nexport { createRenderPreparedT };\nexport type { RenderPreparedTParams };\n"],"mappings":"AAoBA,SAAS,EAAsB,CAC7B,wBACA,4BAI6C,CAC7C,SAAS,EAAgB,CACvB,uBACA,oBACA,SACA,gBACA,aACA,mBACmC,CASnC,MARI,CAAC,GAAmB,GAAqB,KACpC,EAAa,CAClB,uBACA,gBACA,aACD,CAAC,CAGG,EAAa,CAClB,uBACA,oBACA,QAAS,CAAC,EAAQ,EAAc,CAChC,aACD,CAAC,CAGJ,SAAS,EAAa,CACpB,uBACA,gBACA,cAKY,CACZ,OAAO,EAAsB,CAC3B,SAAU,EACV,gBACA,aACD,CAAC,CAGJ,SAAS,EAAa,CACpB,uBACA,oBACA,UACA,cAMY,CACZ,OAAO,EAAyB,CAC9B,OAAQ,EACR,OAAQ,EACR,UACA,aACD,CAAC,CAGJ,OAAO"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require(`../../_virtual/_rolldown/runtime.cjs`),t=require(`../
|
|
1
|
+
const e=require(`../../_virtual/_rolldown/runtime.cjs`),t=require(`../variables/_getVariableProps.cjs`),n=require(`./getGTTag.cjs`),r=require(`../plurals/getPluralBranch.cjs`),i=require(`./renderDefaultChildren.shared.cjs`);let a=require(`generaltranslation/internal`),o=require(`react/jsx-runtime`),s=require(`react`);s=e.__toESM(s);let c=require(`@generaltranslation/format/types`);function l({renderVariable:e}){let l=i.createRenderDefaultChildren({renderVariable:e});function u({sourceElement:e,targetElement:t,locales:n=[a.libraryDefaultLocale],enableI18n:i}){let{props:o}=e,u=o[`data-_gt`],f=u?.transformation,p=t.d,m={};if(p&&Object.entries(c.HTML_CONTENT_PROPS).forEach(([e,t])=>{p[e]&&(m[t]=p[e])}),f===`plural`){let a=e.props.n;return typeof a==`number`?d({source:r.getPluralBranch(a,n,u.branches||{})??e.props.children,target:r.getPluralBranch(a,n,t.d?.b||{})??t.c,locales:n,enableI18n:i}):l({children:e,defaultLocale:n[0],enableI18n:i})}if(f===`branch`){let{branch:e,children:r}=o,a=e==null||e===``?void 0:e.toString(),s=u.branches||{},c=t.d?.b||{};return d({source:a&&s[a]!==void 0?s[a]:r,target:a&&c[a]!==void 0?c[a]:t.c,locales:n,enableI18n:i})}return f===`fragment`&&t.c?s.default.createElement(s.default.Fragment,{key:e.props.key,children:d({source:o.children,target:t.c,locales:n,enableI18n:i})}):o?.children&&t?.c?s.default.cloneElement(e,{...o,...m,"data-_gt":void 0,children:d({source:o.children,target:t.c,locales:n,enableI18n:i})}):l({children:e,defaultLocale:n[0],enableI18n:i})}function d({source:r,target:i,locales:c=[a.libraryDefaultLocale],enableI18n:d}){if(i==null&&r)return l({children:r,defaultLocale:c[0],enableI18n:d});if(typeof i==`string`)return i;if(Array.isArray(i)&&!Array.isArray(r)&&r&&(r=[r]),Array.isArray(r)&&Array.isArray(i)){let l={},f={},p={},m=r.filter(e=>{if(s.default.isValidElement(e))if(t.isVariableElementProps(e.props)){let{variableName:n,variableValue:r,variableOptions:i,injectionType:a}=t.getVariableProps(e.props);l[n]=r,f[n]=i,p[n]=a}else return!0;return!1}),h=e=>m.find(t=>{let r=n.getGTTag(t);return r?.id===void 0?!1:r.id===e.i})||m.shift();return i.map((t,n)=>{if(typeof t==`string`)return(0,o.jsx)(s.default.Fragment,{children:t},`string_${n}`);if((0,a.isVariable)(t))return(0,o.jsx)(s.default.Fragment,{children:e({variableType:t.v||`v`,variableValue:l[t.k],variableOptions:f[t.k],locales:c,enableI18n:d,injectionType:p[t.k]||`manual`})},`var_${n}`);let r=h(t);return r?(0,o.jsx)(s.default.Fragment,{children:u({sourceElement:r,targetElement:t,locales:c,enableI18n:d})},`element_${n}`):null})}if(i&&typeof i==`object`&&!Array.isArray(i)){let n=(0,a.isVariable)(i)?`variable`:`element`;if(s.default.isValidElement(r)){if(n===`element`)return u({sourceElement:r,targetElement:i,locales:c,enableI18n:d});if(t.isVariableElementProps(r.props)){let{variableValue:n,variableOptions:i,variableType:a,injectionType:o}=t.getVariableProps(r.props);return e({variableType:a,variableValue:n,variableOptions:i,locales:c,enableI18n:d,injectionType:o})}}}return l({children:r,defaultLocale:c[0],enableI18n:d})}return d}exports.createRenderTranslatedChildren=l;
|
|
2
2
|
//# sourceMappingURL=renderTranslatedChildren.shared.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderTranslatedChildren.shared.cjs","names":["createRenderDefaultChildren","libraryDefaultLocale","HTML_CONTENT_PROPS","getPluralBranch","React","isVariableElementProps","getVariableProps","getGTTag"],"sources":["../../../src/utils/rendering/renderTranslatedChildren.shared.tsx"],"sourcesContent":["import React, { ReactNode } from 'react';\nimport {\n TaggedChildren,\n TaggedElement,\n TranslatedChildren,\n TranslatedElement,\n VariableProps,\n} from '../types';\nimport {\n getVariableProps,\n isVariableElementProps,\n} from '../variables/_getVariableProps';\nimport { createRenderDefaultChildren } from './renderDefaultChildren.shared';\nimport { isVariable, libraryDefaultLocale } from 'generaltranslation/internal';\nimport { getPluralBranch } from '../plurals/getPluralBranch';\nimport {\n HTML_CONTENT_PROPS,\n HtmlContentPropValuesRecord,\n} from '@generaltranslation/format/types';\nimport { getGTTag } from './getGTTag';\nimport type { RenderVariable } from '../types';\n\n// Shared implementation: the variable renderer is dependency-injected by a\n// factory so neither code path statically imports the other's variable\n// components. Callsites use the pre-instantiated renderPipeline /\n// renderPipeline.rsc modules instead of importing this directly.\n\ntype RenderTranslatedChildrenArgs = {\n source: TaggedChildren;\n target: TranslatedChildren;\n locales: string[];\n enableI18n: boolean;\n};\n\nfunction createRenderTranslatedChildren({\n renderVariable,\n}: {\n renderVariable: RenderVariable;\n}): (args: RenderTranslatedChildrenArgs) => ReactNode {\n const renderDefaultChildren = createRenderDefaultChildren({ renderVariable });\n\n function renderTranslatedElement({\n sourceElement,\n targetElement,\n locales = [libraryDefaultLocale],\n enableI18n,\n }: {\n sourceElement: TaggedElement;\n targetElement: TranslatedElement;\n locales: string[];\n enableI18n: boolean;\n }): React.ReactNode {\n // Get props and generaltranslation\n const { props: sourceProps } = sourceElement;\n const sourceGT = sourceProps['data-_gt'];\n const transformation = sourceGT?.transformation;\n\n // Get translated props\n const unprocessedTargetGT = targetElement.d;\n const translatedProps: HtmlContentPropValuesRecord = {};\n if (unprocessedTargetGT) {\n Object.entries(HTML_CONTENT_PROPS).forEach(([minifiedName, fullName]) => {\n if (\n unprocessedTargetGT[minifiedName as keyof typeof HTML_CONTENT_PROPS]\n ) {\n translatedProps[fullName] = unprocessedTargetGT[\n minifiedName as keyof typeof HTML_CONTENT_PROPS\n ] as string;\n }\n });\n }\n\n // plural (choose a branch)\n if (transformation === 'plural') {\n const n = sourceElement.props.n;\n if (typeof n !== 'number') {\n return renderDefaultChildren({\n children: sourceElement,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n const sourceBranches = sourceGT.branches || {};\n const resolvedSourceBranch = getPluralBranch(n, locales, sourceBranches);\n const sourceBranch =\n resolvedSourceBranch !== null\n ? resolvedSourceBranch\n : sourceElement.props.children;\n const targetBranches = targetElement.d?.b || {};\n const resolvedTargetBranch = getPluralBranch(n, locales, targetBranches);\n const targetBranch =\n resolvedTargetBranch !== null ? resolvedTargetBranch : targetElement.c;\n return renderTranslatedChildren({\n source: sourceBranch as TaggedChildren,\n target: targetBranch as TranslatedChildren,\n locales,\n enableI18n,\n });\n }\n\n // branch (choose a branch)\n if (transformation === 'branch') {\n const { branch, children } = sourceProps;\n const branchKey =\n branch == null || branch === '' ? undefined : branch.toString();\n const sourceBranches = sourceGT.branches || {};\n const targetBranches = targetElement.d?.b || {};\n const sourceBranch =\n branchKey && sourceBranches[branchKey] !== undefined\n ? sourceBranches[branchKey]\n : children;\n const targetBranch =\n branchKey && targetBranches[branchKey] !== undefined\n ? targetBranches[branchKey]\n : targetElement.c;\n return renderTranslatedChildren({\n source: sourceBranch as TaggedChildren,\n target: targetBranch as TranslatedChildren,\n locales,\n enableI18n,\n });\n }\n\n // fragment (create a valid fragment)\n if (transformation === 'fragment' && targetElement.c) {\n return React.createElement(React.Fragment, {\n key: sourceElement.props.key,\n children: renderTranslatedChildren({\n source: sourceProps.children as TaggedChildren,\n target: targetElement.c,\n locales,\n enableI18n,\n }) as TaggedChildren,\n });\n }\n\n // other\n if (sourceProps?.children && targetElement?.c) {\n return React.cloneElement(sourceElement, {\n ...sourceProps,\n ...translatedProps,\n 'data-_gt': undefined,\n children: renderTranslatedChildren({\n source: sourceProps.children as TaggedChildren,\n target: targetElement.c,\n locales,\n enableI18n,\n }) as TaggedChildren,\n });\n }\n\n // fallback\n return renderDefaultChildren({\n children: sourceElement,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n\n function renderTranslatedChildren({\n source,\n target,\n locales = [libraryDefaultLocale],\n enableI18n,\n }: RenderTranslatedChildrenArgs): ReactNode {\n // Most straightforward case, return a valid React node\n if ((target === null || typeof target === 'undefined') && source)\n return renderDefaultChildren({\n children: source,\n defaultLocale: locales[0],\n enableI18n,\n });\n if (typeof target === 'string') return target;\n\n // Convert source to an array in case target has multiple children where source only has one\n if (Array.isArray(target) && !Array.isArray(source) && source)\n source = [source];\n\n // Multiple children\n if (Array.isArray(source) && Array.isArray(target)) {\n // Track the variables\n const variables: Record<string, VariableProps['variableValue']> = {};\n const variablesOptions: Record<string, VariableProps['variableOptions']> =\n {};\n const variableInjectionTypes: Record<\n string,\n VariableProps['injectionType']\n > = {};\n\n // Extract source elements\n // Extract variable props\n // Filter out variable elements\n const sourceElements: TaggedElement[] = source.filter(\n (sourceChild): sourceChild is TaggedElement => {\n if (React.isValidElement(sourceChild)) {\n if (isVariableElementProps(sourceChild.props)) {\n const {\n variableName,\n variableValue,\n variableOptions,\n injectionType,\n } = getVariableProps(sourceChild.props);\n variables[variableName] = variableValue;\n variablesOptions[variableName] = variableOptions;\n variableInjectionTypes[variableName] = injectionType;\n } else {\n return true;\n }\n }\n return false;\n }\n );\n\n // TODO: pre-index these to avoid O(n/2) lookups\n const findMatchingSourceElement = (\n targetElement: TranslatedElement\n ): TaggedElement | undefined => {\n return (\n sourceElements.find((sourceChild): sourceChild is TaggedElement => {\n const generaltranslation = getGTTag(sourceChild);\n if (typeof generaltranslation?.id !== 'undefined') {\n const sourceId = generaltranslation.id;\n const targetId = targetElement.i;\n return sourceId === targetId;\n }\n return false;\n }) || sourceElements.shift()\n ); // assumes fixed order, not recommended\n };\n\n // map target to source\n return target.map((targetChild, index) => {\n if (typeof targetChild === 'string')\n return (\n <React.Fragment key={`string_${index}`}>\n {targetChild}\n </React.Fragment>\n );\n\n // Render variable\n if (isVariable(targetChild)) {\n return (\n <React.Fragment key={`var_${index}`}>\n {renderVariable({\n variableType: targetChild.v || 'v',\n variableValue: variables[targetChild.k],\n variableOptions: variablesOptions[targetChild.k],\n locales,\n enableI18n,\n injectionType:\n variableInjectionTypes[targetChild.k] || 'manual',\n })}\n </React.Fragment>\n );\n }\n\n // Render element (targetChild is a TranslatedElement)\n const matchingSourceElement = findMatchingSourceElement(\n targetChild as TranslatedElement\n );\n if (!matchingSourceElement) return null;\n return (\n <React.Fragment key={`element_${index}`}>\n {renderTranslatedElement({\n sourceElement: matchingSourceElement,\n targetElement: targetChild,\n locales,\n enableI18n,\n })}\n </React.Fragment>\n );\n });\n }\n\n // Single child\n if (target && typeof target === 'object' && !Array.isArray(target)) {\n const targetType: 'variable' | 'element' = isVariable(target)\n ? 'variable'\n : 'element';\n\n if (React.isValidElement(source)) {\n if (targetType === 'element') {\n return renderTranslatedElement({\n sourceElement: source,\n targetElement: target as TranslatedElement,\n locales,\n enableI18n,\n });\n }\n\n // Render variable\n if (isVariableElementProps(source.props)) {\n const {\n variableValue,\n variableOptions,\n variableType,\n injectionType,\n } = getVariableProps(source.props);\n return renderVariable({\n variableType,\n variableValue,\n variableOptions,\n locales,\n enableI18n,\n injectionType,\n });\n }\n }\n }\n\n // fallback\n return renderDefaultChildren({\n children: source,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n\n return renderTranslatedChildren;\n}\n\nexport { createRenderTranslatedChildren };\nexport type { RenderTranslatedChildrenArgs };\n"],"mappings":"gYAkCA,SAAS,EAA+B,CACtC,kBAGoD,CACpD,IAAM,EAAwBA,EAAAA,4BAA4B,CAAE,iBAAgB,CAAC,CAE7E,SAAS,EAAwB,CAC/B,gBACA,gBACA,UAAU,CAACC,EAAAA,qBAAqB,CAChC,cAMkB,CAElB,GAAM,CAAE,MAAO,GAAgB,EACzB,EAAW,EAAY,YACvB,EAAiB,GAAU,eAG3B,EAAsB,EAAc,EACpC,EAA+C,EAAE,CAcvD,GAbI,GACF,OAAO,QAAQC,EAAAA,mBAAmB,CAAC,SAAS,CAAC,EAAc,KAAc,CAErE,EAAo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AuB,EAAY,IAAM,SAC5C,CAAC,CACa,CAVI,OAAO,IAUX,CAKrB,IAAM,EAAwB,EAC5B,EACD,CAED,OADK,GAEH,EAAA,EAAA,KAACA,EAAAA,QAAM,SAAP,CAAA,SACG,EAAwB,CACvB,cAAe,EACf,cAAe,EACf,UACA,aACD,CAAC,CACa,CAPI,WAAW,IAOf,CATgB,MAWnC,CAIJ,GAAI,GAAU,OAAO,GAAW,UAAY,CAAC,MAAM,QAAQ,EAAO,CAAE,CAClE,IAAM,GAAA,EAAA,EAAA,YAAgD,EAAO,CACzD,WACA,UAEJ,GAAIA,EAAAA,QAAM,eAAe,EAAO,CAAE,CAChC,GAAI,IAAe,UACjB,OAAO,EAAwB,CAC7B,cAAe,EACf,cAAe,EACf,UACA,aACD,CAAC,CAIJ,GAAIC,EAAAA,uBAAuB,EAAO,MAAM,CAAE,CACxC,GAAM,CACJ,gBACA,kBACA,eACA,iBACEC,EAAAA,iBAAiB,EAAO,MAAM,CAClC,OAAO,EAAe,CACpB,eACA,gBACA,kBACA,UACA,aACA,gBACD,CAAC,GAMR,OAAO,EAAsB,CAC3B,SAAU,EACV,cAAe,EAAQ,GACvB,aACD,CAAC,CAGJ,OAAO"}
|
|
1
|
+
{"version":3,"file":"renderTranslatedChildren.shared.cjs","names":["createRenderDefaultChildren","libraryDefaultLocale","HTML_CONTENT_PROPS","getPluralBranch","React","isVariableElementProps","getVariableProps","getGTTag"],"sources":["../../../src/utils/rendering/renderTranslatedChildren.shared.tsx"],"sourcesContent":["import React, { ReactNode } from 'react';\nimport {\n TaggedChildren,\n TaggedElement,\n TranslatedChildren,\n TranslatedElement,\n VariableProps,\n} from '../types';\nimport {\n getVariableProps,\n isVariableElementProps,\n} from '../variables/_getVariableProps';\nimport { createRenderDefaultChildren } from './renderDefaultChildren.shared';\nimport { isVariable, libraryDefaultLocale } from 'generaltranslation/internal';\nimport { getPluralBranch } from '../plurals/getPluralBranch';\nimport {\n HTML_CONTENT_PROPS,\n HtmlContentPropValuesRecord,\n} from '@generaltranslation/format/types';\nimport { getGTTag } from './getGTTag';\nimport type { RenderVariable } from '../types';\n\n// Shared implementation: the variable renderer is dependency-injected by a\n// factory so neither code path statically imports the other's variable\n// components. Callsites use the pre-instantiated renderPipeline /\n// renderPipeline.rsc modules instead of importing this directly.\n\ntype RenderTranslatedChildrenArgs = {\n source: TaggedChildren;\n target: TranslatedChildren;\n locales: string[];\n enableI18n: boolean;\n};\n\nfunction createRenderTranslatedChildren({\n renderVariable,\n}: {\n renderVariable: RenderVariable;\n}): (args: RenderTranslatedChildrenArgs) => ReactNode {\n const renderDefaultChildren = createRenderDefaultChildren({ renderVariable });\n\n function renderTranslatedElement({\n sourceElement,\n targetElement,\n locales = [libraryDefaultLocale],\n enableI18n,\n }: {\n sourceElement: TaggedElement;\n targetElement: TranslatedElement;\n locales: string[];\n enableI18n: boolean;\n }): React.ReactNode {\n // Get props and generaltranslation\n const { props: sourceProps } = sourceElement;\n const sourceGT = sourceProps['data-_gt'];\n const transformation = sourceGT?.transformation;\n\n // Get translated props\n const unprocessedTargetGT = targetElement.d;\n const translatedProps: HtmlContentPropValuesRecord = {};\n if (unprocessedTargetGT) {\n Object.entries(HTML_CONTENT_PROPS).forEach(([minifiedName, fullName]) => {\n if (\n unprocessedTargetGT[minifiedName as keyof typeof HTML_CONTENT_PROPS]\n ) {\n translatedProps[fullName] = unprocessedTargetGT[\n minifiedName as keyof typeof HTML_CONTENT_PROPS\n ] as string;\n }\n });\n }\n\n // plural (choose a branch)\n if (transformation === 'plural') {\n const n = sourceElement.props.n;\n if (typeof n !== 'number') {\n return renderDefaultChildren({\n children: sourceElement,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n const sourceBranches = sourceGT.branches || {};\n const resolvedSourceBranch = getPluralBranch(n, locales, sourceBranches);\n const sourceBranch =\n resolvedSourceBranch != null\n ? resolvedSourceBranch\n : sourceElement.props.children;\n const targetBranches = targetElement.d?.b || {};\n const resolvedTargetBranch = getPluralBranch(n, locales, targetBranches);\n const targetBranch =\n resolvedTargetBranch != null ? resolvedTargetBranch : targetElement.c;\n return renderTranslatedChildren({\n source: sourceBranch as TaggedChildren,\n target: targetBranch as TranslatedChildren,\n locales,\n enableI18n,\n });\n }\n\n // branch (choose a branch)\n if (transformation === 'branch') {\n const { branch, children } = sourceProps;\n const branchKey =\n branch == null || branch === '' ? undefined : branch.toString();\n const sourceBranches = sourceGT.branches || {};\n const targetBranches = targetElement.d?.b || {};\n const sourceBranch =\n branchKey && sourceBranches[branchKey] !== undefined\n ? sourceBranches[branchKey]\n : children;\n const targetBranch =\n branchKey && targetBranches[branchKey] !== undefined\n ? targetBranches[branchKey]\n : targetElement.c;\n return renderTranslatedChildren({\n source: sourceBranch as TaggedChildren,\n target: targetBranch as TranslatedChildren,\n locales,\n enableI18n,\n });\n }\n\n // fragment (create a valid fragment)\n if (transformation === 'fragment' && targetElement.c) {\n return React.createElement(React.Fragment, {\n key: sourceElement.props.key,\n children: renderTranslatedChildren({\n source: sourceProps.children as TaggedChildren,\n target: targetElement.c,\n locales,\n enableI18n,\n }) as TaggedChildren,\n });\n }\n\n // other\n if (sourceProps?.children && targetElement?.c) {\n return React.cloneElement(sourceElement, {\n ...sourceProps,\n ...translatedProps,\n 'data-_gt': undefined,\n children: renderTranslatedChildren({\n source: sourceProps.children as TaggedChildren,\n target: targetElement.c,\n locales,\n enableI18n,\n }) as TaggedChildren,\n });\n }\n\n // fallback\n return renderDefaultChildren({\n children: sourceElement,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n\n function renderTranslatedChildren({\n source,\n target,\n locales = [libraryDefaultLocale],\n enableI18n,\n }: RenderTranslatedChildrenArgs): ReactNode {\n // Most straightforward case, return a valid React node\n if ((target === null || typeof target === 'undefined') && source)\n return renderDefaultChildren({\n children: source,\n defaultLocale: locales[0],\n enableI18n,\n });\n if (typeof target === 'string') return target;\n\n // Convert source to an array in case target has multiple children where source only has one\n if (Array.isArray(target) && !Array.isArray(source) && source)\n source = [source];\n\n // Multiple children\n if (Array.isArray(source) && Array.isArray(target)) {\n // Track the variables\n const variables: Record<string, VariableProps['variableValue']> = {};\n const variablesOptions: Record<string, VariableProps['variableOptions']> =\n {};\n const variableInjectionTypes: Record<\n string,\n VariableProps['injectionType']\n > = {};\n\n // Extract source elements\n // Extract variable props\n // Filter out variable elements\n const sourceElements: TaggedElement[] = source.filter(\n (sourceChild): sourceChild is TaggedElement => {\n if (React.isValidElement(sourceChild)) {\n if (isVariableElementProps(sourceChild.props)) {\n const {\n variableName,\n variableValue,\n variableOptions,\n injectionType,\n } = getVariableProps(sourceChild.props);\n variables[variableName] = variableValue;\n variablesOptions[variableName] = variableOptions;\n variableInjectionTypes[variableName] = injectionType;\n } else {\n return true;\n }\n }\n return false;\n }\n );\n\n // TODO: pre-index these to avoid O(n/2) lookups\n const findMatchingSourceElement = (\n targetElement: TranslatedElement\n ): TaggedElement | undefined => {\n return (\n sourceElements.find((sourceChild): sourceChild is TaggedElement => {\n const generaltranslation = getGTTag(sourceChild);\n if (typeof generaltranslation?.id !== 'undefined') {\n const sourceId = generaltranslation.id;\n const targetId = targetElement.i;\n return sourceId === targetId;\n }\n return false;\n }) || sourceElements.shift()\n ); // assumes fixed order, not recommended\n };\n\n // map target to source\n return target.map((targetChild, index) => {\n if (typeof targetChild === 'string')\n return (\n <React.Fragment key={`string_${index}`}>\n {targetChild}\n </React.Fragment>\n );\n\n // Render variable\n if (isVariable(targetChild)) {\n return (\n <React.Fragment key={`var_${index}`}>\n {renderVariable({\n variableType: targetChild.v || 'v',\n variableValue: variables[targetChild.k],\n variableOptions: variablesOptions[targetChild.k],\n locales,\n enableI18n,\n injectionType:\n variableInjectionTypes[targetChild.k] || 'manual',\n })}\n </React.Fragment>\n );\n }\n\n // Render element (targetChild is a TranslatedElement)\n const matchingSourceElement = findMatchingSourceElement(\n targetChild as TranslatedElement\n );\n if (!matchingSourceElement) return null;\n return (\n <React.Fragment key={`element_${index}`}>\n {renderTranslatedElement({\n sourceElement: matchingSourceElement,\n targetElement: targetChild,\n locales,\n enableI18n,\n })}\n </React.Fragment>\n );\n });\n }\n\n // Single child\n if (target && typeof target === 'object' && !Array.isArray(target)) {\n const targetType: 'variable' | 'element' = isVariable(target)\n ? 'variable'\n : 'element';\n\n if (React.isValidElement(source)) {\n if (targetType === 'element') {\n return renderTranslatedElement({\n sourceElement: source,\n targetElement: target as TranslatedElement,\n locales,\n enableI18n,\n });\n }\n\n // Render variable\n if (isVariableElementProps(source.props)) {\n const {\n variableValue,\n variableOptions,\n variableType,\n injectionType,\n } = getVariableProps(source.props);\n return renderVariable({\n variableType,\n variableValue,\n variableOptions,\n locales,\n enableI18n,\n injectionType,\n });\n }\n }\n }\n\n // fallback\n return renderDefaultChildren({\n children: source,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n\n return renderTranslatedChildren;\n}\n\nexport { createRenderTranslatedChildren };\nexport type { RenderTranslatedChildrenArgs };\n"],"mappings":"gYAkCA,SAAS,EAA+B,CACtC,kBAGoD,CACpD,IAAM,EAAwBA,EAAAA,4BAA4B,CAAE,iBAAgB,CAAC,CAE7E,SAAS,EAAwB,CAC/B,gBACA,gBACA,UAAU,CAACC,EAAAA,qBAAqB,CAChC,cAMkB,CAElB,GAAM,CAAE,MAAO,GAAgB,EACzB,EAAW,EAAY,YACvB,EAAiB,GAAU,eAG3B,EAAsB,EAAc,EACpC,EAA+C,EAAE,CAcvD,GAbI,GACF,OAAO,QAAQC,EAAAA,mBAAmB,CAAC,SAAS,CAAC,EAAc,KAAc,CAErE,EAAoB,KAEpB,EAAgB,GAAY,EAC1B,KAGJ,CAIA,IAAmB,SAAU,CAC/B,IAAM,EAAI,EAAc,MAAM,EAkB9B,OAjBI,OAAO,GAAM,SAiBV,EAAyB,CAC9B,OAV2BC,EAAAA,gBAAgB,EAAG,EADzB,EAAS,UAAY,EAAE,CAG5C,EAEI,EAAc,MAAM,SAOxB,OAL2BA,EAAAA,gBAAgB,EAAG,EADzB,EAAc,GAAG,GAAK,E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ACA,UAEJ,GAAIA,EAAAA,QAAM,eAAe,EAAO,CAAE,CAChC,GAAI,IAAe,UACjB,OAAO,EAAwB,CAC7B,cAAe,EACf,cAAe,EACf,UACA,aACD,CAAC,CAIJ,GAAIC,EAAAA,uBAAuB,EAAO,MAAM,CAAE,CACxC,GAAM,CACJ,gBACA,kBACA,eACA,iBACEC,EAAAA,iBAAiB,EAAO,MAAM,CAClC,OAAO,EAAe,CACpB,eACA,gBACA,kBACA,UACA,aACA,gBACD,CAAC,GAMR,OAAO,EAAsB,CAC3B,SAAU,EACV,cAAe,EAAQ,GACvB,aACD,CAAC,CAGJ,OAAO"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{getVariableProps as e,isVariableElementProps as t}from"../variables/_getVariableProps.mjs";import{getGTTag as n}from"./getGTTag.mjs";import{getPluralBranch as r}from"../plurals/getPluralBranch.mjs";import{createRenderDefaultChildren as i}from"./renderDefaultChildren.shared.mjs";import{isVariable as a,libraryDefaultLocale as o}from"generaltranslation/internal";import{jsx as s}from"react/jsx-runtime";import c from"react";import{HTML_CONTENT_PROPS as l}from"@generaltranslation/format/types";function u({renderVariable:u}){let d=i({renderVariable:u});function f({sourceElement:e,targetElement:t,locales:n=[o],enableI18n:i}){let{props:a}=e,s=a[`data-_gt`],u=s?.transformation,f=t.d,m={};if(f&&Object.entries(l).forEach(([e,t])=>{f[e]&&(m[t]=f[e])}),u===`plural`){let a=e.props.n;return typeof a==`number`?p({source:r(a,n,s.branches||{})??e.props.children,target:r(a,n,t.d?.b||{})??t.c,locales:n,enableI18n:i}):d({children:e,defaultLocale:n[0],enableI18n:i})}if(u===`branch`){let{branch:e,children:r}=a,o=e==null||e===``?void 0:e.toString(),c=s.branches||{},l=t.d?.b||{};return p({source:o&&c[o]!==void 0?c[o]:r,target:o&&l[o]!==void 0?l[o]:t.c,locales:n,enableI18n:i})}return u===`fragment`&&t.c?c.createElement(c.Fragment,{key:e.props.key,children:p({source:a.children,target:t.c,locales:n,enableI18n:i})}):a?.children&&t?.c?c.cloneElement(e,{...a,...m,"data-_gt":void 0,children:p({source:a.children,target:t.c,locales:n,enableI18n:i})}):d({children:e,defaultLocale:n[0],enableI18n:i})}function p({source:r,target:i,locales:l=[o],enableI18n:p}){if(i==null&&r)return d({children:r,defaultLocale:l[0],enableI18n:p});if(typeof i==`string`)return i;if(Array.isArray(i)&&!Array.isArray(r)&&r&&(r=[r]),Array.isArray(r)&&Array.isArray(i)){let o={},d={},m={},h=r.filter(n=>{if(c.isValidElement(n))if(t(n.props)){let{variableName:t,variableValue:r,variableOptions:i,injectionType:a}=e(n.props);o[t]=r,d[t]=i,m[t]=a}else return!0;return!1}),g=e=>h.find(t=>{let r=n(t);return r?.id===void 0?!1:r.id===e.i})||h.shift();return i.map((e,t)=>{if(typeof e==`string`)return s(c.Fragment,{children:e},`string_${t}`);if(a(e))return s(c.Fragment,{children:u({variableType:e.v||`v`,variableValue:o[e.k],variableOptions:d[e.k],locales:l,enableI18n:p,injectionType:m[e.k]||`manual`})},`var_${t}`);let n=g(e);return n?s(c.Fragment,{children:f({sourceElement:n,targetElement:e,locales:l,enableI18n:p})},`element_${t}`):null})}if(i&&typeof i==`object`&&!Array.isArray(i)){let n=a(i)?`variable`:`element`;if(c.isValidElement(r)){if(n===`element`)return f({sourceElement:r,targetElement:i,locales:l,enableI18n:p});if(t(r.props)){let{variableValue:t,variableOptions:n,variableType:i,injectionType:a}=e(r.props);return u({variableType:i,variableValue:t,variableOptions:n,locales:l,enableI18n:p,injectionType:a})}}}return d({children:r,defaultLocale:l[0],enableI18n:p})}return p}export{u as createRenderTranslatedChildren};
|
|
2
2
|
//# sourceMappingURL=renderTranslatedChildren.shared.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderTranslatedChildren.shared.mjs","names":[],"sources":["../../../src/utils/rendering/renderTranslatedChildren.shared.tsx"],"sourcesContent":["import React, { ReactNode } from 'react';\nimport {\n TaggedChildren,\n TaggedElement,\n TranslatedChildren,\n TranslatedElement,\n VariableProps,\n} from '../types';\nimport {\n getVariableProps,\n isVariableElementProps,\n} from '../variables/_getVariableProps';\nimport { createRenderDefaultChildren } from './renderDefaultChildren.shared';\nimport { isVariable, libraryDefaultLocale } from 'generaltranslation/internal';\nimport { getPluralBranch } from '../plurals/getPluralBranch';\nimport {\n HTML_CONTENT_PROPS,\n HtmlContentPropValuesRecord,\n} from '@generaltranslation/format/types';\nimport { getGTTag } from './getGTTag';\nimport type { RenderVariable } from '../types';\n\n// Shared implementation: the variable renderer is dependency-injected by a\n// factory so neither code path statically imports the other's variable\n// components. Callsites use the pre-instantiated renderPipeline /\n// renderPipeline.rsc modules instead of importing this directly.\n\ntype RenderTranslatedChildrenArgs = {\n source: TaggedChildren;\n target: TranslatedChildren;\n locales: string[];\n enableI18n: boolean;\n};\n\nfunction createRenderTranslatedChildren({\n renderVariable,\n}: {\n renderVariable: RenderVariable;\n}): (args: RenderTranslatedChildrenArgs) => ReactNode {\n const renderDefaultChildren = createRenderDefaultChildren({ renderVariable });\n\n function renderTranslatedElement({\n sourceElement,\n targetElement,\n locales = [libraryDefaultLocale],\n enableI18n,\n }: {\n sourceElement: TaggedElement;\n targetElement: TranslatedElement;\n locales: string[];\n enableI18n: boolean;\n }): React.ReactNode {\n // Get props and generaltranslation\n const { props: sourceProps } = sourceElement;\n const sourceGT = sourceProps['data-_gt'];\n const transformation = sourceGT?.transformation;\n\n // Get translated props\n const unprocessedTargetGT = targetElement.d;\n const translatedProps: HtmlContentPropValuesRecord = {};\n if (unprocessedTargetGT) {\n Object.entries(HTML_CONTENT_PROPS).forEach(([minifiedName, fullName]) => {\n if (\n unprocessedTargetGT[minifiedName as keyof typeof HTML_CONTENT_PROPS]\n ) {\n translatedProps[fullName] = unprocessedTargetGT[\n minifiedName as keyof typeof HTML_CONTENT_PROPS\n ] as string;\n }\n });\n }\n\n // plural (choose a branch)\n if (transformation === 'plural') {\n const n = sourceElement.props.n;\n if (typeof n !== 'number') {\n return renderDefaultChildren({\n children: sourceElement,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n const sourceBranches = sourceGT.branches || {};\n const resolvedSourceBranch = getPluralBranch(n, locales, sourceBranches);\n const sourceBranch =\n resolvedSourceBranch !== null\n ? resolvedSourceBranch\n : sourceElement.props.children;\n const targetBranches = targetElement.d?.b || {};\n const resolvedTargetBranch = getPluralBranch(n, locales, targetBranches);\n const targetBranch =\n resolvedTargetBranch !== null ? resolvedTargetBranch : targetElement.c;\n return renderTranslatedChildren({\n source: sourceBranch as TaggedChildren,\n target: targetBranch as TranslatedChildren,\n locales,\n enableI18n,\n });\n }\n\n // branch (choose a branch)\n if (transformation === 'branch') {\n const { branch, children } = sourceProps;\n const branchKey =\n branch == null || branch === '' ? undefined : branch.toString();\n const sourceBranches = sourceGT.branches || {};\n const targetBranches = targetElement.d?.b || {};\n const sourceBranch =\n branchKey && sourceBranches[branchKey] !== undefined\n ? sourceBranches[branchKey]\n : children;\n const targetBranch =\n branchKey && targetBranches[branchKey] !== undefined\n ? targetBranches[branchKey]\n : targetElement.c;\n return renderTranslatedChildren({\n source: sourceBranch as TaggedChildren,\n target: targetBranch as TranslatedChildren,\n locales,\n enableI18n,\n });\n }\n\n // fragment (create a valid fragment)\n if (transformation === 'fragment' && targetElement.c) {\n return React.createElement(React.Fragment, {\n key: sourceElement.props.key,\n children: renderTranslatedChildren({\n source: sourceProps.children as TaggedChildren,\n target: targetElement.c,\n locales,\n enableI18n,\n }) as TaggedChildren,\n });\n }\n\n // other\n if (sourceProps?.children && targetElement?.c) {\n return React.cloneElement(sourceElement, {\n ...sourceProps,\n ...translatedProps,\n 'data-_gt': undefined,\n children: renderTranslatedChildren({\n source: sourceProps.children as TaggedChildren,\n target: targetElement.c,\n locales,\n enableI18n,\n }) as TaggedChildren,\n });\n }\n\n // fallback\n return renderDefaultChildren({\n children: sourceElement,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n\n function renderTranslatedChildren({\n source,\n target,\n locales = [libraryDefaultLocale],\n enableI18n,\n }: RenderTranslatedChildrenArgs): ReactNode {\n // Most straightforward case, return a valid React node\n if ((target === null || typeof target === 'undefined') && source)\n return renderDefaultChildren({\n children: source,\n defaultLocale: locales[0],\n enableI18n,\n });\n if (typeof target === 'string') return target;\n\n // Convert source to an array in case target has multiple children where source only has one\n if (Array.isArray(target) && !Array.isArray(source) && source)\n source = [source];\n\n // Multiple children\n if (Array.isArray(source) && Array.isArray(target)) {\n // Track the variables\n const variables: Record<string, VariableProps['variableValue']> = {};\n const variablesOptions: Record<string, VariableProps['variableOptions']> =\n {};\n const variableInjectionTypes: Record<\n string,\n VariableProps['injectionType']\n > = {};\n\n // Extract source elements\n // Extract variable props\n // Filter out variable elements\n const sourceElements: TaggedElement[] = source.filter(\n (sourceChild): sourceChild is TaggedElement => {\n if (React.isValidElement(sourceChild)) {\n if (isVariableElementProps(sourceChild.props)) {\n const {\n variableName,\n variableValue,\n variableOptions,\n injectionType,\n } = getVariableProps(sourceChild.props);\n variables[variableName] = variableValue;\n variablesOptions[variableName] = variableOptions;\n variableInjectionTypes[variableName] = injectionType;\n } else {\n return true;\n }\n }\n return false;\n }\n );\n\n // TODO: pre-index these to avoid O(n/2) lookups\n const findMatchingSourceElement = (\n targetElement: TranslatedElement\n ): TaggedElement | undefined => {\n return (\n sourceElements.find((sourceChild): sourceChild is TaggedElement => {\n const generaltranslation = getGTTag(sourceChild);\n if (typeof generaltranslation?.id !== 'undefined') {\n const sourceId = generaltranslation.id;\n const targetId = targetElement.i;\n return sourceId === targetId;\n }\n return false;\n }) || sourceElements.shift()\n ); // assumes fixed order, not recommended\n };\n\n // map target to source\n return target.map((targetChild, index) => {\n if (typeof targetChild === 'string')\n return (\n <React.Fragment key={`string_${index}`}>\n {targetChild}\n </React.Fragment>\n );\n\n // Render variable\n if (isVariable(targetChild)) {\n return (\n <React.Fragment key={`var_${index}`}>\n {renderVariable({\n variableType: targetChild.v || 'v',\n variableValue: variables[targetChild.k],\n variableOptions: variablesOptions[targetChild.k],\n locales,\n enableI18n,\n injectionType:\n variableInjectionTypes[targetChild.k] || 'manual',\n })}\n </React.Fragment>\n );\n }\n\n // Render element (targetChild is a TranslatedElement)\n const matchingSourceElement = findMatchingSourceElement(\n targetChild as TranslatedElement\n );\n if (!matchingSourceElement) return null;\n return (\n <React.Fragment key={`element_${index}`}>\n {renderTranslatedElement({\n sourceElement: matchingSourceElement,\n targetElement: targetChild,\n locales,\n enableI18n,\n })}\n </React.Fragment>\n );\n });\n }\n\n // Single child\n if (target && typeof target === 'object' && !Array.isArray(target)) {\n const targetType: 'variable' | 'element' = isVariable(target)\n ? 'variable'\n : 'element';\n\n if (React.isValidElement(source)) {\n if (targetType === 'element') {\n return renderTranslatedElement({\n sourceElement: source,\n targetElement: target as TranslatedElement,\n locales,\n enableI18n,\n });\n }\n\n // Render variable\n if (isVariableElementProps(source.props)) {\n const {\n variableValue,\n variableOptions,\n variableType,\n injectionType,\n } = getVariableProps(source.props);\n return renderVariable({\n variableType,\n variableValue,\n variableOptions,\n locales,\n enableI18n,\n injectionType,\n });\n }\n }\n }\n\n // fallback\n return renderDefaultChildren({\n children: source,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n\n return renderTranslatedChildren;\n}\n\nexport { createRenderTranslatedChildren };\nexport type { RenderTranslatedChildrenArgs };\n"],"mappings":"ofAkCA,SAAS,EAA+B,CACtC,kBAGoD,CACpD,IAAM,EAAwB,EAA4B,CAAE,iBAAgB,CAAC,CAE7E,SAAS,EAAwB,CAC/B,gBACA,gBACA,UAAU,CAAC,EAAqB,CAChC,cAMkB,CAElB,GAAM,CAAE,MAAO,GAAgB,EACzB,EAAW,EAAY,YACvB,EAAiB,GAAU,eAG3B,EAAsB,EAAc,EACpC,EAA+C,EAAE,CAcvD,GAbI,GACF,OAAO,QAAQ,EAAmB,CAAC,SAAS,CAAC,EAAc,KAAc,CAErE,EAAoB,KAEpB,EAAgB,GAAY,EAC1B,KAGJ,CAIA,IAAm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PI,WAAW,IAOf,CATgB,MAWnC,CAIJ,GAAI,GAAU,OAAO,GAAW,UAAY,CAAC,MAAM,QAAQ,EAAO,CAAE,CAClE,IAAM,EAAqC,EAAW,EAAO,CACzD,WACA,UAEJ,GAAI,EAAM,eAAe,EAAO,CAAE,CAChC,GAAI,IAAe,UACjB,OAAO,EAAwB,CAC7B,cAAe,EACf,cAAe,EACf,UACA,aACD,CAAC,CAIJ,GAAI,EAAuB,EAAO,MAAM,CAAE,CACxC,GAAM,CACJ,gBACA,kBACA,eACA,iBACE,EAAiB,EAAO,MAAM,CAClC,OAAO,EAAe,CACpB,eACA,gBACA,kBACA,UACA,aACA,gBACD,CAAC,GAMR,OAAO,EAAsB,CAC3B,SAAU,EACV,cAAe,EAAQ,GACvB,aACD,CAAC,CAGJ,OAAO"}
|
|
1
|
+
{"version":3,"file":"renderTranslatedChildren.shared.mjs","names":[],"sources":["../../../src/utils/rendering/renderTranslatedChildren.shared.tsx"],"sourcesContent":["import React, { ReactNode } from 'react';\nimport {\n TaggedChildren,\n TaggedElement,\n TranslatedChildren,\n TranslatedElement,\n VariableProps,\n} from '../types';\nimport {\n getVariableProps,\n isVariableElementProps,\n} from '../variables/_getVariableProps';\nimport { createRenderDefaultChildren } from './renderDefaultChildren.shared';\nimport { isVariable, libraryDefaultLocale } from 'generaltranslation/internal';\nimport { getPluralBranch } from '../plurals/getPluralBranch';\nimport {\n HTML_CONTENT_PROPS,\n HtmlContentPropValuesRecord,\n} from '@generaltranslation/format/types';\nimport { getGTTag } from './getGTTag';\nimport type { RenderVariable } from '../types';\n\n// Shared implementation: the variable renderer is dependency-injected by a\n// factory so neither code path statically imports the other's variable\n// components. Callsites use the pre-instantiated renderPipeline /\n// renderPipeline.rsc modules instead of importing this directly.\n\ntype RenderTranslatedChildrenArgs = {\n source: TaggedChildren;\n target: TranslatedChildren;\n locales: string[];\n enableI18n: boolean;\n};\n\nfunction createRenderTranslatedChildren({\n renderVariable,\n}: {\n renderVariable: RenderVariable;\n}): (args: RenderTranslatedChildrenArgs) => ReactNode {\n const renderDefaultChildren = createRenderDefaultChildren({ renderVariable });\n\n function renderTranslatedElement({\n sourceElement,\n targetElement,\n locales = [libraryDefaultLocale],\n enableI18n,\n }: {\n sourceElement: TaggedElement;\n targetElement: TranslatedElement;\n locales: string[];\n enableI18n: boolean;\n }): React.ReactNode {\n // Get props and generaltranslation\n const { props: sourceProps } = sourceElement;\n const sourceGT = sourceProps['data-_gt'];\n const transformation = sourceGT?.transformation;\n\n // Get translated props\n const unprocessedTargetGT = targetElement.d;\n const translatedProps: HtmlContentPropValuesRecord = {};\n if (unprocessedTargetGT) {\n Object.entries(HTML_CONTENT_PROPS).forEach(([minifiedName, fullName]) => {\n if (\n unprocessedTargetGT[minifiedName as keyof typeof HTML_CONTENT_PROPS]\n ) {\n translatedProps[fullName] = unprocessedTargetGT[\n minifiedName as keyof typeof HTML_CONTENT_PROPS\n ] as string;\n }\n });\n }\n\n // plural (choose a branch)\n if (transformation === 'plural') {\n const n = sourceElement.props.n;\n if (typeof n !== 'number') {\n return renderDefaultChildren({\n children: sourceElement,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n const sourceBranches = sourceGT.branches || {};\n const resolvedSourceBranch = getPluralBranch(n, locales, sourceBranches);\n const sourceBranch =\n resolvedSourceBranch != null\n ? resolvedSourceBranch\n : sourceElement.props.children;\n const targetBranches = targetElement.d?.b || {};\n const resolvedTargetBranch = getPluralBranch(n, locales, targetBranches);\n const targetBranch =\n resolvedTargetBranch != null ? resolvedTargetBranch : targetElement.c;\n return renderTranslatedChildren({\n source: sourceBranch as TaggedChildren,\n target: targetBranch as TranslatedChildren,\n locales,\n enableI18n,\n });\n }\n\n // branch (choose a branch)\n if (transformation === 'branch') {\n const { branch, children } = sourceProps;\n const branchKey =\n branch == null || branch === '' ? undefined : branch.toString();\n const sourceBranches = sourceGT.branches || {};\n const targetBranches = targetElement.d?.b || {};\n const sourceBranch =\n branchKey && sourceBranches[branchKey] !== undefined\n ? sourceBranches[branchKey]\n : children;\n const targetBranch =\n branchKey && targetBranches[branchKey] !== undefined\n ? targetBranches[branchKey]\n : targetElement.c;\n return renderTranslatedChildren({\n source: sourceBranch as TaggedChildren,\n target: targetBranch as TranslatedChildren,\n locales,\n enableI18n,\n });\n }\n\n // fragment (create a valid fragment)\n if (transformation === 'fragment' && targetElement.c) {\n return React.createElement(React.Fragment, {\n key: sourceElement.props.key,\n children: renderTranslatedChildren({\n source: sourceProps.children as TaggedChildren,\n target: targetElement.c,\n locales,\n enableI18n,\n }) as TaggedChildren,\n });\n }\n\n // other\n if (sourceProps?.children && targetElement?.c) {\n return React.cloneElement(sourceElement, {\n ...sourceProps,\n ...translatedProps,\n 'data-_gt': undefined,\n children: renderTranslatedChildren({\n source: sourceProps.children as TaggedChildren,\n target: targetElement.c,\n locales,\n enableI18n,\n }) as TaggedChildren,\n });\n }\n\n // fallback\n return renderDefaultChildren({\n children: sourceElement,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n\n function renderTranslatedChildren({\n source,\n target,\n locales = [libraryDefaultLocale],\n enableI18n,\n }: RenderTranslatedChildrenArgs): ReactNode {\n // Most straightforward case, return a valid React node\n if ((target === null || typeof target === 'undefined') && source)\n return renderDefaultChildren({\n children: source,\n defaultLocale: locales[0],\n enableI18n,\n });\n if (typeof target === 'string') return target;\n\n // Convert source to an array in case target has multiple children where source only has one\n if (Array.isArray(target) && !Array.isArray(source) && source)\n source = [source];\n\n // Multiple children\n if (Array.isArray(source) && Array.isArray(target)) {\n // Track the variables\n const variables: Record<string, VariableProps['variableValue']> = {};\n const variablesOptions: Record<string, VariableProps['variableOptions']> =\n {};\n const variableInjectionTypes: Record<\n string,\n VariableProps['injectionType']\n > = {};\n\n // Extract source elements\n // Extract variable props\n // Filter out variable elements\n const sourceElements: TaggedElement[] = source.filter(\n (sourceChild): sourceChild is TaggedElement => {\n if (React.isValidElement(sourceChild)) {\n if (isVariableElementProps(sourceChild.props)) {\n const {\n variableName,\n variableValue,\n variableOptions,\n injectionType,\n } = getVariableProps(sourceChild.props);\n variables[variableName] = variableValue;\n variablesOptions[variableName] = variableOptions;\n variableInjectionTypes[variableName] = injectionType;\n } else {\n return true;\n }\n }\n return false;\n }\n );\n\n // TODO: pre-index these to avoid O(n/2) lookups\n const findMatchingSourceElement = (\n targetElement: TranslatedElement\n ): TaggedElement | undefined => {\n return (\n sourceElements.find((sourceChild): sourceChild is TaggedElement => {\n const generaltranslation = getGTTag(sourceChild);\n if (typeof generaltranslation?.id !== 'undefined') {\n const sourceId = generaltranslation.id;\n const targetId = targetElement.i;\n return sourceId === targetId;\n }\n return false;\n }) || sourceElements.shift()\n ); // assumes fixed order, not recommended\n };\n\n // map target to source\n return target.map((targetChild, index) => {\n if (typeof targetChild === 'string')\n return (\n <React.Fragment key={`string_${index}`}>\n {targetChild}\n </React.Fragment>\n );\n\n // Render variable\n if (isVariable(targetChild)) {\n return (\n <React.Fragment key={`var_${index}`}>\n {renderVariable({\n variableType: targetChild.v || 'v',\n variableValue: variables[targetChild.k],\n variableOptions: variablesOptions[targetChild.k],\n locales,\n enableI18n,\n injectionType:\n variableInjectionTypes[targetChild.k] || 'manual',\n })}\n </React.Fragment>\n );\n }\n\n // Render element (targetChild is a TranslatedElement)\n const matchingSourceElement = findMatchingSourceElement(\n targetChild as TranslatedElement\n );\n if (!matchingSourceElement) return null;\n return (\n <React.Fragment key={`element_${index}`}>\n {renderTranslatedElement({\n sourceElement: matchingSourceElement,\n targetElement: targetChild,\n locales,\n enableI18n,\n })}\n </React.Fragment>\n );\n });\n }\n\n // Single child\n if (target && typeof target === 'object' && !Array.isArray(target)) {\n const targetType: 'variable' | 'element' = isVariable(target)\n ? 'variable'\n : 'element';\n\n if (React.isValidElement(source)) {\n if (targetType === 'element') {\n return renderTranslatedElement({\n sourceElement: source,\n targetElement: target as TranslatedElement,\n locales,\n enableI18n,\n });\n }\n\n // Render variable\n if (isVariableElementProps(source.props)) {\n const {\n variableValue,\n variableOptions,\n variableType,\n injectionType,\n } = getVariableProps(source.props);\n return renderVariable({\n variableType,\n variableValue,\n variableOptions,\n locales,\n enableI18n,\n injectionType,\n });\n }\n }\n }\n\n // fallback\n return renderDefaultChildren({\n children: source,\n defaultLocale: locales[0],\n enableI18n,\n });\n }\n\n return renderTranslatedChildren;\n}\n\nexport { createRenderTranslatedChildren };\nexport type { RenderTranslatedChildrenArgs };\n"],"mappings":"ofAkCA,SAAS,EAA+B,CACtC,kBAGoD,CACpD,IAAM,EAAwB,EAA4B,CAAE,iBAAgB,CAAC,CAE7E,SAAS,EAAwB,CAC/B,gBACA,gBACA,UAAU,CAAC,EAAqB,CAChC,cAMkB,CAElB,GAAM,CAAE,MAAO,GAAgB,EACzB,EAAW,EAAY,YACvB,EAAiB,GAAU,eAG3B,EAAsB,EAAc,EACpC,EAA+C,EAAE,CAcvD,GAbI,GACF,OAAO,QAAQ,EAAmB,CAAC,SAAS,CAAC,EAAc,KAAc,CAErE,EAAoB,KAEpB,EAAgB,GAAY,EAC1B,KAGJ,CAIA,IAAmB,SAAU,CAC/B,IAAM,EAAI,EAAc,MAAM,EAkB9B,OAjBI,OAAO,GAAM,SAiBV,EAAyB,CAC9B,OAV2B,EAAgB,EAAG,EADzB,EAAS,UAAY,EAAE,CAG5C,EAEI,EAAc,MAAM,SAOxB,OAL2B,EAAgB,EAAG,EADzB,EAAc,GAAG,GAAK,EAAE,CAG7C,EAAsD,EAAc,EAIpE,UACA,aACD,CAAC,CArBO,EAAsB,CAC3B,SAAU,EACV,cAAe,EAAQ,GACvB,aACD,CAAC,CAqBN,GAAI,IAAmB,SAAU,CAC/B,GAAM,CAAE,SAAQ,YAAa,EACvB,EACJ,GAAU,MAAQ,IAAW,GAAK,IAAA,GAAY,EAAO,UAAU,CAC3D,EAAiB,EAAS,UAAY,EAAE,CACxC,EAAiB,EAAc,GAAG,GAAK,EAAE,CAS/C,OAAO,EAAyB,CAC9B,OARA,GAAa,EAAe,KAAe,IAAA,GACvC,EAAe,GACf,EAO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,CAMhD,OALW,GAAoB,KAAO,OAK/B,GAJY,EAAmB,KACnB,EAAc,GAIjC,EAAI,EAAe,OAAO,CAKhC,OAAO,EAAO,KAAK,EAAa,IAAU,CACxC,GAAI,OAAO,GAAgB,SACzB,OACE,EAAC,EAAM,SAAP,CAAA,SACG,EACc,CAFI,UAAU,IAEd,CAIrB,GAAI,EAAW,EAAY,CACzB,OACE,EAAC,EAAM,SAAP,CAAA,SACG,EAAe,CACd,aAAc,EAAY,GAAK,IAC/B,cAAe,EAAU,EAAY,GACrC,gBAAiB,EAAiB,EAAY,GAC9C,UACA,aACA,cACE,EAAuB,EAAY,IAAM,SAC5C,CAAC,CACa,CAVI,OAAO,IAUX,CAKrB,IAAM,EAAwB,EAC5B,EACD,CAED,OADK,EAEH,EAAC,EAAM,SAAP,CAAA,SACG,EAAwB,CACvB,cAAe,EACf,cAAe,EACf,UACA,aACD,CAAC,CACa,CAPI,WAAW,IAOf,CATgB,MAWnC,CAIJ,GAAI,GAAU,OAAO,GAAW,UAAY,CAAC,MAAM,QAAQ,EAAO,CAAE,CAClE,IAAM,EAAqC,EAAW,EAAO,CACzD,WACA,UAEJ,GAAI,EAAM,eAAe,EAAO,CAAE,CAChC,GAAI,IAAe,UACjB,OAAO,EAAwB,CAC7B,cAAe,EACf,cAAe,EACf,UACA,aACD,CAAC,CAIJ,GAAI,EAAuB,EAAO,MAAM,CAAE,CACxC,GAAM,CACJ,gBACA,kBACA,eACA,iBACE,EAAiB,EAAO,MAAM,CAClC,OAAO,EAAe,CACpB,eACA,gBACA,kBACA,UACA,aACA,gBACD,CAAC,GAMR,OAAO,EAAsB,CAC3B,SAAU,EACV,cAAe,EAAQ,GACvB,aACD,CAAC,CAGJ,OAAO"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require(`../internal/addGTIdentifier.cjs`),t=require(`../internal/
|
|
1
|
+
const e=require(`../internal/addGTIdentifier.cjs`),t=require(`../internal/removeInjectedT.cjs`),n=require(`../internal/writeChildrenAsObjects.cjs`);function r({sourceChildren:e,params:t,locale:n}){let r=i(e);return{taggedSourceChildren:r,sourceJsxChildren:a(r),targetOptions:o({options:s(t),locale:n})}}function i(n){return e.addGTIdentifier(t.removeInjectedT(n))}function a(e){return n.writeChildrenAsObjects(e)}function o({options:e,locale:t}){return{...e,$locale:t}}function s(e){return{...e,$format:`JSX`,$context:e.$context??e.context,$id:e.$id??e.id,$_hash:e.$_hash??e._hash,$maxChars:e.$maxChars??e.maxChars,$requiresReview:e.$requiresReview??e.requiresReview}}exports.prepareT=r;
|
|
2
2
|
//# sourceMappingURL=prepareT.shared.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareT.shared.cjs","names":["addGTIdentifier","removeInjectedT","writeChildrenAsObjects"],"sources":["../../../src/utils/translation/prepareT.shared.ts"],"sourcesContent":["import { addGTIdentifier } from '../internal/addGTIdentifier';\nimport { removeInjectedT } from '../internal/removeInjectedT';\nimport { writeChildrenAsObjects } from '../internal/writeChildrenAsObjects';\nimport type { JsxTranslationOptions as JsxTranslationOptionsWithSugar } from 'gt-i18n/types';\nimport type { JsxChildren } from 'generaltranslation/types';\nimport type { ReactNode } from 'react';\nimport type { RenderPreparedTParams } from '../rendering/renderPreparedT.shared';\nimport type { TaggedChildren } from '../types';\n\n// Pure preparation logic shared by the hook wrapper (usePrepareT) and the RSC\n// code path. This module must stay free of hook/context imports so it can be\n// reached from the components-rsc entrypoint.\n\ntype StripDollarPrefix<T> = {\n [K in keyof T as K extends `$${infer Rest}` ? Rest : K]: T[K];\n};\n\ntype JsxTranslationOptions = StripDollarPrefix<JsxTranslationOptionsWithSugar> &\n JsxTranslationOptionsWithSugar;\n\ntype PreparedT = {\n taggedSourceChildren: TaggedChildren;\n sourceJsxChildren: JsxChildren;\n targetOptions: JsxTranslationOptionsWithSugar & {\n $format: 'JSX';\n $locale: string;\n };\n};\n\ntype RenderPreparedT = (params: RenderPreparedTParams) => ReactNode;\n\ntype TProps = {\n children: ReactNode;\n _locale?: string;\n _enableI18n?: boolean;\n _renderPreparedT?: RenderPreparedT;\n} & JsxTranslationOptions;\n\ntype ResolvedTProps = TProps & {\n _locale: string;\n _enableI18n: boolean;\n};\n\nfunction prepareT({\n sourceChildren,\n params,\n locale,\n}: {\n sourceChildren: ReactNode;\n params: JsxTranslationOptions;\n locale: string;\n}): PreparedT {\n const taggedSourceChildren = prepareTaggedSourceChildren(sourceChildren);\n const sourceJsxChildren = prepareSourceJsxChildren(taggedSourceChildren);\n const options = normalizeParameters(params);\n const targetOptions = prepareTargetOptions({ options, locale });\n\n return {\n taggedSourceChildren,\n sourceJsxChildren,\n targetOptions,\n };\n}\n\nfunction prepareTaggedSourceChildren(\n sourceChildren: ReactNode\n): TaggedChildren {\n return addGTIdentifier(removeInjectedT(sourceChildren));\n}\n\nfunction prepareSourceJsxChildren(\n taggedSourceChildren: TaggedChildren\n): JsxChildren {\n return writeChildrenAsObjects(taggedSourceChildren);\n}\n\nfunction prepareTargetOptions({\n options,\n locale,\n}: {\n options: JsxTranslationOptionsWithSugar & { $format: 'JSX' };\n locale: string;\n}): JsxTranslationOptionsWithSugar & {\n $format: 'JSX';\n $locale: string;\n} {\n return { ...options, $locale: locale };\n}\n\nfunction normalizeParameters(\n parameters: {\n context?: string;\n id?: string;\n _hash?: string;\n } & JsxTranslationOptions\n): JsxTranslationOptionsWithSugar & { $format: 'JSX' } {\n return {\n ...parameters,\n $format: 'JSX',\n $context: parameters.$context ?? parameters.context,\n $id: parameters.$id ?? parameters.id,\n $_hash: parameters.$_hash ?? parameters._hash,\n };\n}\n\nexport { prepareT };\nexport type {\n JsxTranslationOptions,\n PreparedT,\n RenderPreparedT,\n ResolvedTProps,\n TProps,\n};\n"],"mappings":"oJA2CA,SAAS,EAAS,CAChB,iBACA,SACA,UAKY,CACZ,IAAM,EAAuB,EAA4B,EAAe,CAKxE,MAAO,CACL,uBACA,kBANwB,EAAyB,EAMhC,CACjB,cALoB,EAAqB,CAAE,QAD7B,EAAoB,EACgB,CAAE,SAAQ,CAK/C,CACd,CAGH,SAAS,EACP,EACgB,CAChB,OAAOA,EAAAA,gBAAgBC,EAAAA,gBAAgB,EAAe,CAAC,CAGzD,SAAS,EACP,EACa,CACb,OAAOC,EAAAA,uBAAuB,EAAqB,CAGrD,SAAS,EAAqB,CAC5B,UACA,UAOA,CACA,MAAO,CAAE,GAAG,EAAS,QAAS,EAAQ,CAGxC,SAAS,EACP,EAKqD,CACrD,MAAO,CACL,GAAG,EACH,QAAS,MACT,SAAU,EAAW,UAAY,EAAW,QAC5C,IAAK,EAAW,KAAO,EAAW,GAClC,OAAQ,EAAW,QAAU,EAAW,
|
|
1
|
+
{"version":3,"file":"prepareT.shared.cjs","names":["addGTIdentifier","removeInjectedT","writeChildrenAsObjects"],"sources":["../../../src/utils/translation/prepareT.shared.ts"],"sourcesContent":["import { addGTIdentifier } from '../internal/addGTIdentifier';\nimport { removeInjectedT } from '../internal/removeInjectedT';\nimport { writeChildrenAsObjects } from '../internal/writeChildrenAsObjects';\nimport type { JsxTranslationOptions as JsxTranslationOptionsWithSugar } from 'gt-i18n/types';\nimport type { JsxChildren } from 'generaltranslation/types';\nimport type { ReactNode } from 'react';\nimport type { RenderPreparedTParams } from '../rendering/renderPreparedT.shared';\nimport type { TaggedChildren } from '../types';\n\n// Pure preparation logic shared by the hook wrapper (usePrepareT) and the RSC\n// code path. This module must stay free of hook/context imports so it can be\n// reached from the components-rsc entrypoint.\n\ntype StripDollarPrefix<T> = {\n [K in keyof T as K extends `$${infer Rest}` ? Rest : K]: T[K];\n};\n\ntype JsxTranslationOptions = StripDollarPrefix<JsxTranslationOptionsWithSugar> &\n JsxTranslationOptionsWithSugar;\n\ntype PreparedT = {\n taggedSourceChildren: TaggedChildren;\n sourceJsxChildren: JsxChildren;\n targetOptions: JsxTranslationOptionsWithSugar & {\n $format: 'JSX';\n $locale: string;\n };\n};\n\ntype RenderPreparedT = (params: RenderPreparedTParams) => ReactNode;\n\ntype TProps = {\n children: ReactNode;\n _locale?: string;\n _enableI18n?: boolean;\n _renderPreparedT?: RenderPreparedT;\n} & JsxTranslationOptions;\n\ntype ResolvedTProps = TProps & {\n _locale: string;\n _enableI18n: boolean;\n};\n\nfunction prepareT({\n sourceChildren,\n params,\n locale,\n}: {\n sourceChildren: ReactNode;\n params: JsxTranslationOptions;\n locale: string;\n}): PreparedT {\n const taggedSourceChildren = prepareTaggedSourceChildren(sourceChildren);\n const sourceJsxChildren = prepareSourceJsxChildren(taggedSourceChildren);\n const options = normalizeParameters(params);\n const targetOptions = prepareTargetOptions({ options, locale });\n\n return {\n taggedSourceChildren,\n sourceJsxChildren,\n targetOptions,\n };\n}\n\nfunction prepareTaggedSourceChildren(\n sourceChildren: ReactNode\n): TaggedChildren {\n return addGTIdentifier(removeInjectedT(sourceChildren));\n}\n\nfunction prepareSourceJsxChildren(\n taggedSourceChildren: TaggedChildren\n): JsxChildren {\n return writeChildrenAsObjects(taggedSourceChildren);\n}\n\nfunction prepareTargetOptions({\n options,\n locale,\n}: {\n options: JsxTranslationOptionsWithSugar & { $format: 'JSX' };\n locale: string;\n}): JsxTranslationOptionsWithSugar & {\n $format: 'JSX';\n $locale: string;\n} {\n return { ...options, $locale: locale };\n}\n\nfunction normalizeParameters(\n parameters: {\n context?: string;\n id?: string;\n _hash?: string;\n } & JsxTranslationOptions\n): JsxTranslationOptionsWithSugar & { $format: 'JSX' } {\n return {\n ...parameters,\n $format: 'JSX',\n $context: parameters.$context ?? parameters.context,\n $id: parameters.$id ?? parameters.id,\n $_hash: parameters.$_hash ?? parameters._hash,\n $maxChars: parameters.$maxChars ?? parameters.maxChars,\n $requiresReview: parameters.$requiresReview ?? parameters.requiresReview,\n };\n}\n\nexport { prepareT };\nexport type {\n JsxTranslationOptions,\n PreparedT,\n RenderPreparedT,\n ResolvedTProps,\n TProps,\n};\n"],"mappings":"oJA2CA,SAAS,EAAS,CAChB,iBACA,SACA,UAKY,CACZ,IAAM,EAAuB,EAA4B,EAAe,CAKxE,MAAO,CACL,uBACA,kBANwB,EAAyB,EAMhC,CACjB,cALoB,EAAqB,CAAE,QAD7B,EAAoB,EACgB,CAAE,SAAQ,CAK/C,CACd,CAGH,SAAS,EACP,EACgB,CAChB,OAAOA,EAAAA,gBAAgBC,EAAAA,gBAAgB,EAAe,CAAC,CAGzD,SAAS,EACP,EACa,CACb,OAAOC,EAAAA,uBAAuB,EAAqB,CAGrD,SAAS,EAAqB,CAC5B,UACA,UAOA,CACA,MAAO,CAAE,GAAG,EAAS,QAAS,EAAQ,CAGxC,SAAS,EACP,EAKqD,CACrD,MAAO,CACL,GAAG,EACH,QAAS,MACT,SAAU,EAAW,UAAY,EAAW,QAC5C,IAAK,EAAW,KAAO,EAAW,GAClC,OAAQ,EAAW,QAAU,EAAW,MACxC,UAAW,EAAW,WAAa,EAAW,SAC9C,gBAAiB,EAAW,iBAAmB,EAAW,eAC3D"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{addGTIdentifier as e}from"../internal/addGTIdentifier.mjs";import{
|
|
1
|
+
import{addGTIdentifier as e}from"../internal/addGTIdentifier.mjs";import{removeInjectedT as t}from"../internal/removeInjectedT.mjs";import{writeChildrenAsObjects as n}from"../internal/writeChildrenAsObjects.mjs";function r({sourceChildren:e,params:t,locale:n}){let r=i(e);return{taggedSourceChildren:r,sourceJsxChildren:a(r),targetOptions:o({options:s(t),locale:n})}}function i(n){return e(t(n))}function a(e){return n(e)}function o({options:e,locale:t}){return{...e,$locale:t}}function s(e){return{...e,$format:`JSX`,$context:e.$context??e.context,$id:e.$id??e.id,$_hash:e.$_hash??e._hash,$maxChars:e.$maxChars??e.maxChars,$requiresReview:e.$requiresReview??e.requiresReview}}export{r as prepareT};
|
|
2
2
|
//# sourceMappingURL=prepareT.shared.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareT.shared.mjs","names":[],"sources":["../../../src/utils/translation/prepareT.shared.ts"],"sourcesContent":["import { addGTIdentifier } from '../internal/addGTIdentifier';\nimport { removeInjectedT } from '../internal/removeInjectedT';\nimport { writeChildrenAsObjects } from '../internal/writeChildrenAsObjects';\nimport type { JsxTranslationOptions as JsxTranslationOptionsWithSugar } from 'gt-i18n/types';\nimport type { JsxChildren } from 'generaltranslation/types';\nimport type { ReactNode } from 'react';\nimport type { RenderPreparedTParams } from '../rendering/renderPreparedT.shared';\nimport type { TaggedChildren } from '../types';\n\n// Pure preparation logic shared by the hook wrapper (usePrepareT) and the RSC\n// code path. This module must stay free of hook/context imports so it can be\n// reached from the components-rsc entrypoint.\n\ntype StripDollarPrefix<T> = {\n [K in keyof T as K extends `$${infer Rest}` ? Rest : K]: T[K];\n};\n\ntype JsxTranslationOptions = StripDollarPrefix<JsxTranslationOptionsWithSugar> &\n JsxTranslationOptionsWithSugar;\n\ntype PreparedT = {\n taggedSourceChildren: TaggedChildren;\n sourceJsxChildren: JsxChildren;\n targetOptions: JsxTranslationOptionsWithSugar & {\n $format: 'JSX';\n $locale: string;\n };\n};\n\ntype RenderPreparedT = (params: RenderPreparedTParams) => ReactNode;\n\ntype TProps = {\n children: ReactNode;\n _locale?: string;\n _enableI18n?: boolean;\n _renderPreparedT?: RenderPreparedT;\n} & JsxTranslationOptions;\n\ntype ResolvedTProps = TProps & {\n _locale: string;\n _enableI18n: boolean;\n};\n\nfunction prepareT({\n sourceChildren,\n params,\n locale,\n}: {\n sourceChildren: ReactNode;\n params: JsxTranslationOptions;\n locale: string;\n}): PreparedT {\n const taggedSourceChildren = prepareTaggedSourceChildren(sourceChildren);\n const sourceJsxChildren = prepareSourceJsxChildren(taggedSourceChildren);\n const options = normalizeParameters(params);\n const targetOptions = prepareTargetOptions({ options, locale });\n\n return {\n taggedSourceChildren,\n sourceJsxChildren,\n targetOptions,\n };\n}\n\nfunction prepareTaggedSourceChildren(\n sourceChildren: ReactNode\n): TaggedChildren {\n return addGTIdentifier(removeInjectedT(sourceChildren));\n}\n\nfunction prepareSourceJsxChildren(\n taggedSourceChildren: TaggedChildren\n): JsxChildren {\n return writeChildrenAsObjects(taggedSourceChildren);\n}\n\nfunction prepareTargetOptions({\n options,\n locale,\n}: {\n options: JsxTranslationOptionsWithSugar & { $format: 'JSX' };\n locale: string;\n}): JsxTranslationOptionsWithSugar & {\n $format: 'JSX';\n $locale: string;\n} {\n return { ...options, $locale: locale };\n}\n\nfunction normalizeParameters(\n parameters: {\n context?: string;\n id?: string;\n _hash?: string;\n } & JsxTranslationOptions\n): JsxTranslationOptionsWithSugar & { $format: 'JSX' } {\n return {\n ...parameters,\n $format: 'JSX',\n $context: parameters.$context ?? parameters.context,\n $id: parameters.$id ?? parameters.id,\n $_hash: parameters.$_hash ?? parameters._hash,\n };\n}\n\nexport { prepareT };\nexport type {\n JsxTranslationOptions,\n PreparedT,\n RenderPreparedT,\n ResolvedTProps,\n TProps,\n};\n"],"mappings":"oNA2CA,SAAS,EAAS,CAChB,iBACA,SACA,UAKY,CACZ,IAAM,EAAuB,EAA4B,EAAe,CAKxE,MAAO,CACL,uBACA,kBANwB,EAAyB,EAMhC,CACjB,cALoB,EAAqB,CAAE,QAD7B,EAAoB,EACgB,CAAE,SAAQ,CAK/C,CACd,CAGH,SAAS,EACP,EACgB,CAChB,OAAO,EAAgB,EAAgB,EAAe,CAAC,CAGzD,SAAS,EACP,EACa,CACb,OAAO,EAAuB,EAAqB,CAGrD,SAAS,EAAqB,CAC5B,UACA,UAOA,CACA,MAAO,CAAE,GAAG,EAAS,QAAS,EAAQ,CAGxC,SAAS,EACP,EAKqD,CACrD,MAAO,CACL,GAAG,EACH,QAAS,MACT,SAAU,EAAW,UAAY,EAAW,QAC5C,IAAK,EAAW,KAAO,EAAW,GAClC,OAAQ,EAAW,QAAU,EAAW,
|
|
1
|
+
{"version":3,"file":"prepareT.shared.mjs","names":[],"sources":["../../../src/utils/translation/prepareT.shared.ts"],"sourcesContent":["import { addGTIdentifier } from '../internal/addGTIdentifier';\nimport { removeInjectedT } from '../internal/removeInjectedT';\nimport { writeChildrenAsObjects } from '../internal/writeChildrenAsObjects';\nimport type { JsxTranslationOptions as JsxTranslationOptionsWithSugar } from 'gt-i18n/types';\nimport type { JsxChildren } from 'generaltranslation/types';\nimport type { ReactNode } from 'react';\nimport type { RenderPreparedTParams } from '../rendering/renderPreparedT.shared';\nimport type { TaggedChildren } from '../types';\n\n// Pure preparation logic shared by the hook wrapper (usePrepareT) and the RSC\n// code path. This module must stay free of hook/context imports so it can be\n// reached from the components-rsc entrypoint.\n\ntype StripDollarPrefix<T> = {\n [K in keyof T as K extends `$${infer Rest}` ? Rest : K]: T[K];\n};\n\ntype JsxTranslationOptions = StripDollarPrefix<JsxTranslationOptionsWithSugar> &\n JsxTranslationOptionsWithSugar;\n\ntype PreparedT = {\n taggedSourceChildren: TaggedChildren;\n sourceJsxChildren: JsxChildren;\n targetOptions: JsxTranslationOptionsWithSugar & {\n $format: 'JSX';\n $locale: string;\n };\n};\n\ntype RenderPreparedT = (params: RenderPreparedTParams) => ReactNode;\n\ntype TProps = {\n children: ReactNode;\n _locale?: string;\n _enableI18n?: boolean;\n _renderPreparedT?: RenderPreparedT;\n} & JsxTranslationOptions;\n\ntype ResolvedTProps = TProps & {\n _locale: string;\n _enableI18n: boolean;\n};\n\nfunction prepareT({\n sourceChildren,\n params,\n locale,\n}: {\n sourceChildren: ReactNode;\n params: JsxTranslationOptions;\n locale: string;\n}): PreparedT {\n const taggedSourceChildren = prepareTaggedSourceChildren(sourceChildren);\n const sourceJsxChildren = prepareSourceJsxChildren(taggedSourceChildren);\n const options = normalizeParameters(params);\n const targetOptions = prepareTargetOptions({ options, locale });\n\n return {\n taggedSourceChildren,\n sourceJsxChildren,\n targetOptions,\n };\n}\n\nfunction prepareTaggedSourceChildren(\n sourceChildren: ReactNode\n): TaggedChildren {\n return addGTIdentifier(removeInjectedT(sourceChildren));\n}\n\nfunction prepareSourceJsxChildren(\n taggedSourceChildren: TaggedChildren\n): JsxChildren {\n return writeChildrenAsObjects(taggedSourceChildren);\n}\n\nfunction prepareTargetOptions({\n options,\n locale,\n}: {\n options: JsxTranslationOptionsWithSugar & { $format: 'JSX' };\n locale: string;\n}): JsxTranslationOptionsWithSugar & {\n $format: 'JSX';\n $locale: string;\n} {\n return { ...options, $locale: locale };\n}\n\nfunction normalizeParameters(\n parameters: {\n context?: string;\n id?: string;\n _hash?: string;\n } & JsxTranslationOptions\n): JsxTranslationOptionsWithSugar & { $format: 'JSX' } {\n return {\n ...parameters,\n $format: 'JSX',\n $context: parameters.$context ?? parameters.context,\n $id: parameters.$id ?? parameters.id,\n $_hash: parameters.$_hash ?? parameters._hash,\n $maxChars: parameters.$maxChars ?? parameters.maxChars,\n $requiresReview: parameters.$requiresReview ?? parameters.requiresReview,\n };\n}\n\nexport { prepareT };\nexport type {\n JsxTranslationOptions,\n PreparedT,\n RenderPreparedT,\n ResolvedTProps,\n TProps,\n};\n"],"mappings":"oNA2CA,SAAS,EAAS,CAChB,iBACA,SACA,UAKY,CACZ,IAAM,EAAuB,EAA4B,EAAe,CAKxE,MAAO,CACL,uBACA,kBANwB,EAAyB,EAMhC,CACjB,cALoB,EAAqB,CAAE,QAD7B,EAAoB,EACgB,CAAE,SAAQ,CAK/C,CACd,CAGH,SAAS,EACP,EACgB,CAChB,OAAO,EAAgB,EAAgB,EAAe,CAAC,CAGzD,SAAS,EACP,EACa,CACb,OAAO,EAAuB,EAAqB,CAGrD,SAAS,EAAqB,CAC5B,UACA,UAOA,CACA,MAAO,CAAE,GAAG,EAAS,QAAS,EAAQ,CAGxC,SAAS,EACP,EAKqD,CACrD,MAAO,CACL,GAAG,EACH,QAAS,MACT,SAAU,EAAW,UAAY,EAAW,QAC5C,IAAK,EAAW,KAAO,EAAW,GAClC,OAAQ,EAAW,QAAU,EAAW,MACxC,UAAW,EAAW,WAAa,EAAW,SAC9C,gBAAiB,EAAW,iBAAmB,EAAW,eAC3D"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../hooks/condition-store.cjs`),t=require(`../../hooks/i18n-config.cjs`),n=require(`./prepareT.shared.cjs`);let r=require(`
|
|
1
|
+
require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../hooks/condition-store.cjs`),t=require(`../../hooks/i18n-config.cjs`),n=require(`./prepareT.shared.cjs`);let r=require(`gt-i18n/internal`),i=require(`react`);function a({sourceChildren:a,params:o,_locale:s,_enableI18n:c}){let l=e.useLocale(),u=e.useEnableI18n(),d=t.useDefaultLocale(),f=s??l,p=c??u;return{defaultLocale:d,enableI18n:p,locale:f,shouldTranslate:p&&(0,r.getI18nConfig)().requiresTranslation(f),...(0,i.useMemo)(()=>n.prepareT({sourceChildren:a,params:o,locale:f}),[f,o,a])}}exports.usePrepareT=a;
|
|
2
2
|
//# sourceMappingURL=usePrepareT.cjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useEnableI18n as e,useLocale as t}from"../../hooks/condition-store.mjs";import{useDefaultLocale as n}from"../../hooks/i18n-config.mjs";import{prepareT as r}from"./prepareT.shared.mjs";import{
|
|
1
|
+
import{useEnableI18n as e,useLocale as t}from"../../hooks/condition-store.mjs";import{useDefaultLocale as n}from"../../hooks/i18n-config.mjs";import{prepareT as r}from"./prepareT.shared.mjs";import{getI18nConfig as i}from"gt-i18n/internal";import{useMemo as a}from"react";function o({sourceChildren:o,params:s,_locale:c,_enableI18n:l}){let u=t(),d=e(),f=n(),p=c??u,m=l??d;return{defaultLocale:f,enableI18n:m,locale:p,shouldTranslate:m&&i().requiresTranslation(p),...a(()=>r({sourceChildren:o,params:s,locale:p}),[p,s,o])}}export{o as usePrepareT};
|
|
2
2
|
//# sourceMappingURL=usePrepareT.mjs.map
|
package/dist/utils/types.d.ts
CHANGED
|
@@ -36,29 +36,6 @@ type TranslatedElement = {
|
|
|
36
36
|
};
|
|
37
37
|
type TranslatedChild = TranslatedElement | string | Variable;
|
|
38
38
|
type TranslatedChildren = TranslatedChild | TranslatedChild[];
|
|
39
|
-
type Entry = string;
|
|
40
|
-
type MetaEntry = {
|
|
41
|
-
$context?: string;
|
|
42
|
-
$maxChars?: number;
|
|
43
|
-
$_hash?: string;
|
|
44
|
-
[key: string]: unknown;
|
|
45
|
-
};
|
|
46
|
-
type Metadata = MetaEntry;
|
|
47
|
-
type DictionaryEntry$1 = Entry | [Entry] | [Entry, MetaEntry];
|
|
48
|
-
type Dictionary$1 = {
|
|
49
|
-
[key: string]: Dictionary$1 | DictionaryEntry$1;
|
|
50
|
-
} | (Dictionary$1 | DictionaryEntry$1)[];
|
|
51
|
-
type FlattenedDictionary = {
|
|
52
|
-
[key: string]: DictionaryEntry$1;
|
|
53
|
-
};
|
|
54
|
-
type DictionaryContent = string;
|
|
55
|
-
type DictionaryObject$1 = {
|
|
56
|
-
[id: string]: DictionaryContent;
|
|
57
|
-
};
|
|
58
|
-
type LocalesDictionary = {
|
|
59
|
-
[locale: string]: DictionaryObject$1;
|
|
60
|
-
};
|
|
61
|
-
type CustomLoader = (locale: string) => Promise<unknown>;
|
|
62
39
|
type RelativeTimeFormatOptions = Intl.RelativeTimeFormatOptions & {
|
|
63
40
|
unit?: Intl.RelativeTimeFormatUnit;
|
|
64
41
|
baseDate?: Date;
|
|
@@ -81,26 +58,7 @@ type RenderVariable = ({
|
|
|
81
58
|
locales: string[];
|
|
82
59
|
enableI18n: boolean;
|
|
83
60
|
}) => React.ReactNode;
|
|
84
|
-
type Translations = {
|
|
85
|
-
[hash: string]: TranslatedChildren | null;
|
|
86
|
-
};
|
|
87
61
|
type RenderMethod = 'skeleton' | 'replace' | 'default';
|
|
88
|
-
type _Message = {
|
|
89
|
-
message: string;
|
|
90
|
-
$id?: string;
|
|
91
|
-
$context?: string;
|
|
92
|
-
$maxChars?: number;
|
|
93
|
-
$_hash?: string;
|
|
94
|
-
};
|
|
95
|
-
type _Messages = _Message[];
|
|
96
|
-
type AuthFromEnvParams = {
|
|
97
|
-
projectId?: string;
|
|
98
|
-
devApiKey?: string;
|
|
99
|
-
};
|
|
100
|
-
type AuthFromEnvReturn = {
|
|
101
|
-
projectId: string;
|
|
102
|
-
devApiKey?: string;
|
|
103
|
-
};
|
|
104
62
|
//#endregion
|
|
105
|
-
export {
|
|
63
|
+
export { type GTFunctionType$1 as GTFunctionType, type GTProp, type GTTranslationOptions$1 as GTTranslationOptions, type MFunctionType$1 as MFunctionType, RelativeTimeFormatOptions, RenderMethod, RenderVariable, type RuntimeTranslationOptions, TaggedChildren, TranslatedChildren, VariableProps };
|
|
106
64
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/utils/types.ts"],"mappings":";;;;;;;AAuBA;;KAAY,KAAA;EACV,EAAA;EACA,aAAA,EAAe,aAAA;EACf,cAAA,GAAiB,oBAAA;EACjB,QAAA,GAAW,MAAA,SAAe,cAAA;EAC1B,YAAA,GAAe,4BAAA;AAAA;AAAA,KAEL,kBAAA,GAAqB,MAAA;EAC/B,UAAA,EAAY,KAAA;EACZ,QAAA,GAAW,cAAA;EACX,MAAA;EACA,CAAA;EACA,GAAA,GAAM,KAAA,CAAM,GAAA;AAAA;AAAA,KAEF,aAAA,GAAgB,KAAA,CAAM,YAAA,CAAa,kBAAA;AAAA,KACnC,WAAA,GACR,OAAA,CAAQ,KAAA,CAAM,SAAA,EAAW,KAAA,CAAM,YAAA,IAC/B,aAAA;AAAA,KACQ,cAAA,GAAiB,WAAA,KAAgB,WAAA;;;;AAX7C;;KAoBY,iBAAA;EACV,CAAA;EACA,CAAA,GAAI,MAAA;EACJ,CAAA,GAAI,kBAAA;AAAA;AAAA,KAEM,eAAA,GAAkB,iBAAA,YAA6B,QAAA;AAAA,KAC/C,kBAAA,GAAqB,eAAA,GAAkB,eAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/utils/types.ts"],"mappings":";;;;;;;AAuBA;;KAAY,KAAA;EACV,EAAA;EACA,aAAA,EAAe,a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|
"description": "A pure React library for internationalization",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"react": ">=18.0.0"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@generaltranslation/format": "0.1.2
|
|
15
|
-
"@generaltranslation/supported-locales": "2.1.
|
|
16
|
-
"generaltranslation": "9.0.0
|
|
17
|
-
"gt-i18n": "1.0.
|
|
14
|
+
"@generaltranslation/format": "0.1.2",
|
|
15
|
+
"@generaltranslation/supported-locales": "2.1.3",
|
|
16
|
+
"generaltranslation": "9.0.0",
|
|
17
|
+
"gt-i18n": "1.0.1"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
@@ -52,11 +52,6 @@
|
|
|
52
52
|
"types": "./dist/components-rsc.d.ts",
|
|
53
53
|
"require": "./dist/components-rsc.cjs",
|
|
54
54
|
"import": "./dist/components-rsc.mjs"
|
|
55
|
-
},
|
|
56
|
-
"./cookies": {
|
|
57
|
-
"types": "./dist/cookies.d.ts",
|
|
58
|
-
"require": "./dist/cookies.cjs",
|
|
59
|
-
"import": "./dist/cookies.mjs"
|
|
60
55
|
}
|
|
61
56
|
},
|
|
62
57
|
"typesVersions": {
|
|
@@ -72,29 +67,6 @@
|
|
|
72
67
|
],
|
|
73
68
|
"components-rsc": [
|
|
74
69
|
"./dist/components-rsc.d.ts"
|
|
75
|
-
],
|
|
76
|
-
"cookies": [
|
|
77
|
-
"./dist/cookies.d.ts"
|
|
78
|
-
]
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
"compilerOptions": {
|
|
82
|
-
"baseUrl": ".",
|
|
83
|
-
"paths": {
|
|
84
|
-
"@generaltranslation/react-core/pure": [
|
|
85
|
-
"./dist/pure"
|
|
86
|
-
],
|
|
87
|
-
"@generaltranslation/react-core/hooks": [
|
|
88
|
-
"./dist/hooks"
|
|
89
|
-
],
|
|
90
|
-
"@generaltranslation/react-core/components": [
|
|
91
|
-
"./dist/components"
|
|
92
|
-
],
|
|
93
|
-
"@generaltranslation/react-core/components-rsc": [
|
|
94
|
-
"./dist/components-rsc"
|
|
95
|
-
],
|
|
96
|
-
"@generaltranslation/react-core/cookies": [
|
|
97
|
-
"./dist/cookies"
|
|
98
70
|
]
|
|
99
71
|
}
|
|
100
72
|
},
|
package/dist/cookies.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./utils/cookies.cjs`);exports.defaultEnableI18nCookieName=e.defaultEnableI18nCookieName,exports.defaultLocaleCookieName=e.defaultLocaleCookieName,exports.defaultRegionCookieName=e.defaultRegionCookieName;
|
package/dist/cookies.d.ts
DELETED
package/dist/cookies.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{defaultEnableI18nCookieName as e,defaultLocaleCookieName as t,defaultRegionCookieName as n}from"./utils/cookies.mjs";export{e as defaultEnableI18nCookieName,t as defaultLocaleCookieName,n as defaultRegionCookieName};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../i18n-cache/singleton-operations.cjs`),t=require(`./i18nConfig.cjs`),n=require(`../condition-store/singleton-operations.cjs`),r=require(`../i18n-store/I18nStore.cjs`),i=require(`../i18n-store/singleton-operations.cjs`);let a=require(`gt-i18n/internal`);function o(o){(0,a.setupGTServicesEnabled)(o),t.initializeI18nConfig(o,`SPA`),e.setReactI18nCache(new a.I18nCache(o)),n.setConditionStore(new a.WritableConditionStore(o)),i.setI18nStore(new r.I18nStore)}exports.internalInitializeGTSPA=o;
|
|
2
|
-
//# sourceMappingURL=initializeGTSPA.cjs.map
|