@generaltranslation/react-core 11.1.7-iris.0 → 11.1.7
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 +6 -14
- package/dist/pure.cjs +1 -1
- package/dist/setup/cookieNames.cjs +2 -0
- package/dist/setup/cookieNames.cjs.map +1 -0
- package/dist/setup/cookieNames.d.ts +20 -2
- package/dist/setup/cookieNames.d.ts.map +1 -0
- package/dist/setup/cookieNames.mjs +2 -1
- package/dist/setup/cookieNames.mjs.map +1 -0
- package/dist/setup/i18nConfig.cjs +1 -1
- package/dist/setup/i18nConfig.cjs.map +1 -1
- package/dist/setup/i18nConfig.mjs +1 -1
- package/dist/setup/i18nConfig.mjs.map +1 -1
- package/dist/utils/rendering/renderPreparedT.shared.cjs.map +1 -1
- package/dist/utils/rendering/renderPreparedT.shared.mjs.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
# @generaltranslation/react-core
|
|
2
2
|
|
|
3
|
-
## 11.1.7
|
|
3
|
+
## 11.1.7
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
- Updated dependencies [f2204b9]
|
|
9
|
-
- Updated dependencies [b05b470]
|
|
10
|
-
- Updated dependencies [5d8b78a]
|
|
11
|
-
- @generaltranslation/format@0.1.5-iris.0
|
|
12
|
-
- generaltranslation@9.1.3-iris.0
|
|
13
|
-
- gt-i18n@1.0.13-iris.0
|
|
7
|
+
- [#2074](https://github.com/generaltranslation/gt/pull/2074) [`240a65e`](https://github.com/generaltranslation/gt/commit/240a65e9305a74cdfd4df07537fb4cfae8a2eac8) Thanks [@eoinest](https://github.com/eoinest)! - Migrate the package license from FSL-1.1-ALv2 to MIT.
|
|
14
8
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
- Updated dependencies [8d376e2]
|
|
20
|
-
- gt-i18n@1.0.12-iris.0
|
|
9
|
+
- Updated dependencies [[`240a65e`](https://github.com/generaltranslation/gt/commit/240a65e9305a74cdfd4df07537fb4cfae8a2eac8)]:
|
|
10
|
+
- @generaltranslation/format@0.1.5
|
|
11
|
+
- generaltranslation@9.1.3
|
|
12
|
+
- gt-i18n@1.0.13
|
|
21
13
|
|
|
22
14
|
## 11.1.6
|
|
23
15
|
|
package/dist/pure.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./hooks/utils/getFormatLocales.cjs`),t=require(`./i18n-cache/singleton-operations.cjs`),n=require(`./functions/helpers/getTranslationsSnapshot.cjs`),r=require(`./setup/
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./hooks/utils/getFormatLocales.cjs`),t=require(`./i18n-cache/singleton-operations.cjs`),n=require(`./functions/helpers/getTranslationsSnapshot.cjs`),r=require(`./setup/cookieNames.cjs`),i=require(`./setup/i18nConfig.cjs`),a=require(`./condition-store/singleton-operations.cjs`),o=require(`./functions/translation/t.cjs`),s=require(`./utils/rendering/createRenderPipeline.cjs`),c=require(`./utils/rendering/getDefaultRenderSettings.cjs`),l=require(`./i18n-cache/ReactI18nCache.cjs`),u=require(`./setup/initializeGTSRA.cjs`),d=require(`./i18n-store/singleton-operations.cjs`),f=require(`./i18n-store/I18nStore.cjs`);let p=require(`gt-i18n`),m=require(`gt-i18n/internal`);exports.I18nStore=f.I18nStore,exports.ReactI18nCache=l.ReactI18nCache,Object.defineProperty(exports,`ReadonlyConditionStore`,{enumerable:!0,get:function(){return m.ReadonlyConditionStore}}),exports.createRenderPipeline=s.createRenderPipeline,Object.defineProperty(exports,`declareVar`,{enumerable:!0,get:function(){return p.declareVar}}),Object.defineProperty(exports,`decodeMsg`,{enumerable:!0,get:function(){return p.decodeMsg}}),Object.defineProperty(exports,`decodeOptions`,{enumerable:!0,get:function(){return p.decodeOptions}}),Object.defineProperty(exports,`decodeVars`,{enumerable:!0,get:function(){return p.decodeVars}}),exports.defaultEnableI18nCookieName=r.defaultEnableI18nCookieName,exports.defaultLocaleCookieName=r.defaultLocaleCookieName,exports.defaultRegionCookieName=r.defaultRegionCookieName,exports.defaultResetLocaleCookieName=r.defaultResetLocaleCookieName,Object.defineProperty(exports,`derive`,{enumerable:!0,get:function(){return p.derive}}),Object.defineProperty(exports,`getDefaultLocale`,{enumerable:!0,get:function(){return p.getDefaultLocale}}),exports.getDefaultRenderSettings=c.getDefaultRenderSettings,exports.getFormatLocales=e.getFormatLocales,exports.getI18nConfig=i.getI18nConfig,Object.defineProperty(exports,`getLocaleProperties`,{enumerable:!0,get:function(){return p.getLocaleProperties}}),Object.defineProperty(exports,`getLocales`,{enumerable:!0,get:function(){return p.getLocales}}),exports.getReactI18nCache=t.getReactI18nCache,exports.getReadonlyConditionStore=a.getConditionStore,exports.getTranslationsSnapshot=n.getTranslationsSnapshot,Object.defineProperty(exports,`getVersionId`,{enumerable:!0,get:function(){return p.getVersionId}}),Object.defineProperty(exports,`gtFallback`,{enumerable:!0,get:function(){return p.gtFallback}}),exports.initializeI18nConfig=i.initializeI18nConfig,exports.internalInitializeGTSRA=u.internalInitializeGTSRA,Object.defineProperty(exports,`mFallback`,{enumerable:!0,get:function(){return p.mFallback}}),Object.defineProperty(exports,`msg`,{enumerable:!0,get:function(){return p.msg}}),Object.defineProperty(exports,`resolveCanonicalLocale`,{enumerable:!0,get:function(){return p.resolveCanonicalLocale}}),exports.setI18nStore=d.setI18nStore,exports.setReactI18nCache=t.setReactI18nCache,exports.t=o.t;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
exports.defaultEnableI18nCookieName=`generaltranslation.enable-i18n`,exports.defaultLocaleCookieName=`generaltranslation.locale`,exports.defaultRegionCookieName=`generaltranslation.region`,exports.defaultResetLocaleCookieName=`generaltranslation.locale-reset`;
|
|
2
|
+
//# sourceMappingURL=cookieNames.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookieNames.cjs","names":[],"sources":["../../src/setup/cookieNames.ts"],"sourcesContent":["// Dependency-free module: these constants are imported by size-constrained\n// consumers (e.g. gt-next's edge middleware), which must not pull in the\n// ReactI18nConfig class or its gt-i18n imports.\n\n/**\n * Cookie name for tracking the user's selected locale.\n */\nexport const defaultLocaleCookieName = 'generaltranslation.locale';\n\n/**\n * Cookie name for tracking the user's selected region.\n */\nexport const defaultRegionCookieName = 'generaltranslation.region';\n\n/**\n * Cookie name for persisting the enableI18n feature flag.\n */\nexport const defaultEnableI18nCookieName = 'generaltranslation.enable-i18n';\n\n/**\n * Cookie name for tracking the locale reset.\n */\nexport const defaultResetLocaleCookieName = 'generaltranslation.locale-reset';\n"],"mappings":""}
|
|
@@ -1,2 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/setup/cookieNames.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Cookie name for tracking the user's selected locale.
|
|
4
|
+
*/
|
|
5
|
+
declare const defaultLocaleCookieName = "generaltranslation.locale";
|
|
6
|
+
/**
|
|
7
|
+
* Cookie name for tracking the user's selected region.
|
|
8
|
+
*/
|
|
9
|
+
declare const defaultRegionCookieName = "generaltranslation.region";
|
|
10
|
+
/**
|
|
11
|
+
* Cookie name for persisting the enableI18n feature flag.
|
|
12
|
+
*/
|
|
13
|
+
declare const defaultEnableI18nCookieName = "generaltranslation.enable-i18n";
|
|
14
|
+
/**
|
|
15
|
+
* Cookie name for tracking the locale reset.
|
|
16
|
+
*/
|
|
17
|
+
declare const defaultResetLocaleCookieName = "generaltranslation.locale-reset";
|
|
18
|
+
//#endregion
|
|
19
|
+
export { defaultEnableI18nCookieName, defaultLocaleCookieName, defaultRegionCookieName, defaultResetLocaleCookieName };
|
|
20
|
+
//# sourceMappingURL=cookieNames.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookieNames.d.ts","names":[],"sources":["../../src/setup/cookieNames.ts"],"mappings":";;AAOA;;cAAa,uBAAA;;;AAKb;cAAa,uBAAA;;;;cAKA,2BAAA;;;;cAKA,4BAAA"}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
const e=`generaltranslation.locale`,t=`generaltranslation.region`,n=`generaltranslation.enable-i18n`,r=`generaltranslation.locale-reset`;export{n as defaultEnableI18nCookieName,e as defaultLocaleCookieName,t as defaultRegionCookieName,r as defaultResetLocaleCookieName};
|
|
2
|
+
//# sourceMappingURL=cookieNames.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookieNames.mjs","names":[],"sources":["../../src/setup/cookieNames.ts"],"sourcesContent":["// Dependency-free module: these constants are imported by size-constrained\n// consumers (e.g. gt-next's edge middleware), which must not pull in the\n// ReactI18nConfig class or its gt-i18n imports.\n\n/**\n * Cookie name for tracking the user's selected locale.\n */\nexport const defaultLocaleCookieName = 'generaltranslation.locale';\n\n/**\n * Cookie name for tracking the user's selected region.\n */\nexport const defaultRegionCookieName = 'generaltranslation.region';\n\n/**\n * Cookie name for persisting the enableI18n feature flag.\n */\nexport const defaultEnableI18nCookieName = 'generaltranslation.enable-i18n';\n\n/**\n * Cookie name for tracking the locale reset.\n */\nexport const defaultResetLocaleCookieName = 'generaltranslation.locale-reset';\n"],"mappings":"AAOA,MAAa,EAA0B,4BAK1B,EAA0B,4BAK1B,EAA8B,iCAK9B,EAA+B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`gt-i18n/internal`),t=require(`generaltranslation/internal`)
|
|
1
|
+
require(`../_virtual/_rolldown/runtime.cjs`),require(`./cookieNames.cjs`);let e=require(`gt-i18n/internal`),t=require(`generaltranslation/internal`);const n=`server-render`,r=Symbol.for(`generaltranslation.react-core.ReactI18nConfig`);var i=class extends e.I18nConfig{renderStrategy;localeCookieName;regionCookieName;enableI18nCookieName;constructor(e={},t=n){super(e),c(t),Object.defineProperty(this,r,{value:!0}),this.renderStrategy=t,this.localeCookieName=e.localeCookieName??`generaltranslation.locale`,this.regionCookieName=e.regionCookieName??`generaltranslation.region`,this.enableI18nCookieName=e.enableI18nCookieName??`generaltranslation.enable-i18n`}getRenderStrategy(){return this.renderStrategy}getLocaleCookieName(){return this.localeCookieName}getRegionCookieName(){return this.regionCookieName}getEnableI18nCookieName(){return this.enableI18nCookieName}isIdTaggingEnabled(){return this.runtimeConfig._tagIds===!0}};function a(){let n=(0,e.getI18nConfig)();if(l(n))return n;throw Error((0,t.createDiagnosticMessage)({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`Cannot read ReactI18nConfig after base I18nConfig setup.`,why:`the internal I18nConfig singleton was initialized without react-core render strategy support`,fix:`Initialize GT through gt-react or @generaltranslation/react-core/pure.`}))}function o(t){(0,e.setI18nConfig)(t)}function s(e={},t=n){let r=new i(e,t);return o(r),r}function c(e){if(!(e===`SPA`||e===`server-render`))throw Error((0,t.createDiagnosticMessage)({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`Invalid React render strategy.`,why:`the render strategy must be "SPA" or "server-render", but received "${String(e)}"`,fix:`Initialize GT through gt-react or pass a valid render strategy.`}))}function l(e){if(e instanceof i)return!0;let t=e;return t[r]===!0&&typeof t.getRenderStrategy==`function`&&typeof t.getLocaleCookieName==`function`&&typeof t.getRegionCookieName==`function`&&typeof t.getEnableI18nCookieName==`function`}exports.getI18nConfig=a,exports.initializeI18nConfig=s;
|
|
2
2
|
//# sourceMappingURL=i18nConfig.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i18nConfig.cjs","names":["I18nConfig"
|
|
1
|
+
{"version":3,"file":"i18nConfig.cjs","names":["I18nConfig"],"sources":["../../src/setup/i18nConfig.ts"],"sourcesContent":["import { createDiagnosticMessage } from 'generaltranslation/internal';\nimport {\n getI18nConfig as getBaseI18nConfig,\n I18nConfig,\n setI18nConfig as setBaseI18nConfig,\n} from 'gt-i18n/internal';\nimport type { I18nConfigParams as BaseI18nConfigParams } from 'gt-i18n/internal/types';\nimport {\n defaultEnableI18nCookieName,\n defaultLocaleCookieName,\n defaultRegionCookieName,\n} from './cookieNames';\n\n/**\n * Helps us distinguish behavior for SPA vs server-rendered apps.\n * - server-rendered apps must use context\n * - SPA apps can synchronously access the locale\n */\nexport type RenderStrategy = 'SPA' | 'server-render';\n\ntype CookieNameConfig = {\n localeCookieName?: string;\n regionCookieName?: string;\n enableI18nCookieName?: string;\n};\n\nexport type ReactI18nConfigParams = BaseI18nConfigParams & CookieNameConfig;\n\nconst defaultRenderStrategy: RenderStrategy = 'server-render';\nconst reactI18nConfigBrand = Symbol.for(\n 'generaltranslation.react-core.ReactI18nConfig'\n);\n\nexport class ReactI18nConfig extends I18nConfig {\n private renderStrategy: RenderStrategy;\n private localeCookieName: string;\n private regionCookieName: string;\n private enableI18nCookieName: string;\n\n constructor(\n params: ReactI18nConfigParams = {},\n renderStrategy: RenderStrategy = defaultRenderStrategy\n ) {\n super(params);\n validateRenderStrategy(renderStrategy);\n Object.defineProperty(this, reactI18nConfigBrand, { value: true });\n this.renderStrategy = renderStrategy;\n this.localeCookieName = params.localeCookieName ?? defaultLocaleCookieName;\n this.regionCookieName = params.regionCookieName ?? defaultRegionCookieName;\n this.enableI18nCookieName =\n params.enableI18nCookieName ?? defaultEnableI18nCookieName;\n }\n\n getRenderStrategy(): RenderStrategy {\n return this.renderStrategy;\n }\n\n getLocaleCookieName(): string {\n return this.localeCookieName;\n }\n\n getRegionCookieName(): string {\n return this.regionCookieName;\n }\n\n getEnableI18nCookieName(): string {\n return this.enableI18nCookieName;\n }\n\n /**\n * Opt-in (`_tagIds`): whether `<T>` output should carry its translation hash as\n * a `data-_gt-hash` attribute for tooling. Requires the literal `true`.\n */\n isIdTaggingEnabled(): boolean {\n return this.runtimeConfig._tagIds === true;\n }\n}\n\nexport function getI18nConfig(): ReactI18nConfig {\n const i18nConfig = getBaseI18nConfig();\n if (isReactI18nConfig(i18nConfig)) {\n return i18nConfig;\n }\n throw new Error(\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'Cannot read ReactI18nConfig after base I18nConfig setup.',\n why: 'the internal I18nConfig singleton was initialized without react-core render strategy support',\n fix: 'Initialize GT through gt-react or @generaltranslation/react-core/pure.',\n })\n );\n}\n\nexport function setI18nConfig(nextI18nConfig: ReactI18nConfig): void {\n setBaseI18nConfig(nextI18nConfig);\n}\n\nexport function initializeI18nConfig(\n params: ReactI18nConfigParams = {},\n renderStrategy: RenderStrategy = defaultRenderStrategy\n): ReactI18nConfig {\n const nextI18nConfig = new ReactI18nConfig(params, renderStrategy);\n setI18nConfig(nextI18nConfig);\n return nextI18nConfig;\n}\n\nfunction validateRenderStrategy(\n renderStrategy: RenderStrategy\n): asserts renderStrategy is RenderStrategy {\n if (renderStrategy === 'SPA' || renderStrategy === 'server-render') return;\n throw new Error(\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'Invalid React render strategy.',\n why: `the render strategy must be \"SPA\" or \"server-render\", but received \"${String(renderStrategy)}\"`,\n fix: 'Initialize GT through gt-react or pass a valid render strategy.',\n })\n );\n}\n\nfunction isReactI18nConfig(\n i18nConfig: I18nConfig\n): i18nConfig is ReactI18nConfig {\n if (i18nConfig instanceof ReactI18nConfig) return true;\n\n const maybeReactI18nConfig = i18nConfig as I18nConfig &\n Record<PropertyKey, unknown>;\n return (\n maybeReactI18nConfig[reactI18nConfigBrand] === true &&\n typeof maybeReactI18nConfig.getRenderStrategy === 'function' &&\n typeof maybeReactI18nConfig.getLocaleCookieName === 'function' &&\n typeof maybeReactI18nConfig.getRegionCookieName === 'function' &&\n typeof maybeReactI18nConfig.getEnableI18nCookieName === 'function'\n );\n}\n"],"mappings":"qJA4BA,MAAM,EAAwC,gBACxC,EAAuB,OAAO,IAClC,gDACD,CAED,IAAa,EAAb,cAAqCA,EAAAA,UAAW,CAC9C,eACA,iBACA,iBACA,qBAEA,YACE,EAAgC,EAAE,CAClC,EAAiC,EACjC,CACA,MAAM,EAAO,CACb,EAAuB,EAAe,CACtC,OAAO,eAAe,KAAM,EAAsB,CAAE,MAAO,GAAM,CAAC,CAClE,KAAK,eAAiB,EACtB,KAAK,iBAAmB,EAAO,kBAAA,4BAC/B,KAAK,iBAAmB,EAAO,kBAAA,4BAC/B,KAAK,qBACH,EAAO,sBAAA,iCAGX,mBAAoC,CAClC,OAAO,KAAK,eAGd,qBAA8B,CAC5B,OAAO,KAAK,iBAGd,qBAA8B,CAC5B,OAAO,KAAK,iBAGd,yBAAkC,CAChC,OAAO,KAAK,qBAOd,oBAA8B,CAC5B,OAAO,KAAK,cAAc,UAAY,KAI1C,SAAgB,GAAiC,CAC/C,IAAM,GAAA,EAAA,EAAA,gBAAgC,CACtC,GAAI,EAAkB,EAAW,CAC/B,OAAO,EAET,MAAU,OAAA,EAAA,EAAA,yBACgB,CACtB,OAAQ,iCACR,SAAU,QACV,aAAc,2DACd,IAAK,+FACL,IAAK,yEACN,CAAC,CACH,CAGH,SAAgB,EAAc,EAAuC,EACnE,EAAA,EAAA,eAAkB,EAAe,CAGnC,SAAgB,EACd,EAAgC,EAAE,CAClC,EAAiC,EAChB,CACjB,IAAM,EAAiB,IAAI,EAAgB,EAAQ,EAAe,CAElE,OADA,EAAc,EAAe,CACtB,EAGT,SAAS,EACP,EAC0C,CACtC,SAAmB,OAAS,IAAmB,iBACnD,MAAU,OAAA,EAAA,EAAA,yBACgB,CACtB,OAAQ,iCACR,SAAU,QACV,aAAc,iCACd,IAAK,uEAAuE,OAAO,EAAe,CAAC,GACnG,IAAK,kEACN,CAAC,CACH,CAGH,SAAS,EACP,EAC+B,CAC/B,GAAI,aAAsB,EAAiB,MAAO,GAElD,IAAM,EAAuB,EAE7B,OACE,EAAqB,KAA0B,IAC/C,OAAO,EAAqB,mBAAsB,YAClD,OAAO,EAAqB,qBAAwB,YACpD,OAAO,EAAqB,qBAAwB,YACpD,OAAO,EAAqB,yBAA4B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import"./cookieNames.mjs";import{I18nConfig as e,getI18nConfig as t,setI18nConfig as n}from"gt-i18n/internal";import{createDiagnosticMessage as r}from"generaltranslation/internal";const i=`server-render`,a=Symbol.for(`generaltranslation.react-core.ReactI18nConfig`);var o=class extends e{renderStrategy;localeCookieName;regionCookieName;enableI18nCookieName;constructor(e={},t=i){super(e),u(t),Object.defineProperty(this,a,{value:!0}),this.renderStrategy=t,this.localeCookieName=e.localeCookieName??`generaltranslation.locale`,this.regionCookieName=e.regionCookieName??`generaltranslation.region`,this.enableI18nCookieName=e.enableI18nCookieName??`generaltranslation.enable-i18n`}getRenderStrategy(){return this.renderStrategy}getLocaleCookieName(){return this.localeCookieName}getRegionCookieName(){return this.regionCookieName}getEnableI18nCookieName(){return this.enableI18nCookieName}isIdTaggingEnabled(){return this.runtimeConfig._tagIds===!0}};function s(){let e=t();if(d(e))return e;throw Error(r({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`Cannot read ReactI18nConfig after base I18nConfig setup.`,why:`the internal I18nConfig singleton was initialized without react-core render strategy support`,fix:`Initialize GT through gt-react or @generaltranslation/react-core/pure.`}))}function c(e){n(e)}function l(e={},t=i){let n=new o(e,t);return c(n),n}function u(e){if(!(e===`SPA`||e===`server-render`))throw Error(r({source:`@generaltranslation/react-core`,severity:`Error`,whatHappened:`Invalid React render strategy.`,why:`the render strategy must be "SPA" or "server-render", but received "${String(e)}"`,fix:`Initialize GT through gt-react or pass a valid render strategy.`}))}function d(e){if(e instanceof o)return!0;let t=e;return t[a]===!0&&typeof t.getRenderStrategy==`function`&&typeof t.getLocaleCookieName==`function`&&typeof t.getRegionCookieName==`function`&&typeof t.getEnableI18nCookieName==`function`}export{s as getI18nConfig,l as initializeI18nConfig};
|
|
2
2
|
//# sourceMappingURL=i18nConfig.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i18nConfig.mjs","names":["getI18nConfig","getBaseI18nConfig","setI18nConfig"],"sources":["../../src/setup/i18nConfig.ts"],"sourcesContent":["import { createDiagnosticMessage } from 'generaltranslation/internal';\nimport {\n getI18nConfig as getBaseI18nConfig,\n I18nConfig,\n setI18nConfig as setBaseI18nConfig,\n} from 'gt-i18n/internal';\nimport type { I18nConfigParams as BaseI18nConfigParams } from 'gt-i18n/internal/types';\nimport {\n defaultEnableI18nCookieName,\n defaultLocaleCookieName,\n defaultRegionCookieName,\n} from './cookieNames';\n\n/**\n * Helps us distinguish behavior for SPA vs server-rendered apps.\n * - server-rendered apps must use context\n * - SPA apps can synchronously access the locale\n */\nexport type RenderStrategy = 'SPA' | 'server-render';\n\ntype CookieNameConfig = {\n localeCookieName?: string;\n regionCookieName?: string;\n enableI18nCookieName?: string;\n};\n\nexport type ReactI18nConfigParams = BaseI18nConfigParams & CookieNameConfig;\n\nconst defaultRenderStrategy: RenderStrategy = 'server-render';\nconst reactI18nConfigBrand = Symbol.for(\n 'generaltranslation.react-core.ReactI18nConfig'\n);\n\nexport class ReactI18nConfig extends I18nConfig {\n private renderStrategy: RenderStrategy;\n private localeCookieName: string;\n private regionCookieName: string;\n private enableI18nCookieName: string;\n\n constructor(\n params: ReactI18nConfigParams = {},\n renderStrategy: RenderStrategy = defaultRenderStrategy\n ) {\n super(params);\n validateRenderStrategy(renderStrategy);\n Object.defineProperty(this, reactI18nConfigBrand, { value: true });\n this.renderStrategy = renderStrategy;\n this.localeCookieName = params.localeCookieName ?? defaultLocaleCookieName;\n this.regionCookieName = params.regionCookieName ?? defaultRegionCookieName;\n this.enableI18nCookieName =\n params.enableI18nCookieName ?? defaultEnableI18nCookieName;\n }\n\n getRenderStrategy(): RenderStrategy {\n return this.renderStrategy;\n }\n\n getLocaleCookieName(): string {\n return this.localeCookieName;\n }\n\n getRegionCookieName(): string {\n return this.regionCookieName;\n }\n\n getEnableI18nCookieName(): string {\n return this.enableI18nCookieName;\n }\n\n /**\n * Opt-in (`_tagIds`): whether `<T>` output should carry its translation hash as\n * a `data-_gt-hash` attribute for tooling. Requires the literal `true`.\n */\n isIdTaggingEnabled(): boolean {\n return this.runtimeConfig._tagIds === true;\n }\n}\n\nexport function getI18nConfig(): ReactI18nConfig {\n const i18nConfig = getBaseI18nConfig();\n if (isReactI18nConfig(i18nConfig)) {\n return i18nConfig;\n }\n throw new Error(\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'Cannot read ReactI18nConfig after base I18nConfig setup.',\n why: 'the internal I18nConfig singleton was initialized without react-core render strategy support',\n fix: 'Initialize GT through gt-react or @generaltranslation/react-core/pure.',\n })\n );\n}\n\nexport function setI18nConfig(nextI18nConfig: ReactI18nConfig): void {\n setBaseI18nConfig(nextI18nConfig);\n}\n\nexport function initializeI18nConfig(\n params: ReactI18nConfigParams = {},\n renderStrategy: RenderStrategy = defaultRenderStrategy\n): ReactI18nConfig {\n const nextI18nConfig = new ReactI18nConfig(params, renderStrategy);\n setI18nConfig(nextI18nConfig);\n return nextI18nConfig;\n}\n\nfunction validateRenderStrategy(\n renderStrategy: RenderStrategy\n): asserts renderStrategy is RenderStrategy {\n if (renderStrategy === 'SPA' || renderStrategy === 'server-render') return;\n throw new Error(\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'Invalid React render strategy.',\n why: `the render strategy must be \"SPA\" or \"server-render\", but received \"${String(renderStrategy)}\"`,\n fix: 'Initialize GT through gt-react or pass a valid render strategy.',\n })\n );\n}\n\nfunction isReactI18nConfig(\n i18nConfig: I18nConfig\n): i18nConfig is ReactI18nConfig {\n if (i18nConfig instanceof ReactI18nConfig) return true;\n\n const maybeReactI18nConfig = i18nConfig as I18nConfig &\n Record<PropertyKey, unknown>;\n return (\n maybeReactI18nConfig[reactI18nConfigBrand] === true &&\n typeof maybeReactI18nConfig.getRenderStrategy === 'function' &&\n typeof maybeReactI18nConfig.getLocaleCookieName === 'function' &&\n typeof maybeReactI18nConfig.getRegionCookieName === 'function' &&\n typeof maybeReactI18nConfig.getEnableI18nCookieName === 'function'\n );\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"i18nConfig.mjs","names":["getI18nConfig","getBaseI18nConfig","setI18nConfig"],"sources":["../../src/setup/i18nConfig.ts"],"sourcesContent":["import { createDiagnosticMessage } from 'generaltranslation/internal';\nimport {\n getI18nConfig as getBaseI18nConfig,\n I18nConfig,\n setI18nConfig as setBaseI18nConfig,\n} from 'gt-i18n/internal';\nimport type { I18nConfigParams as BaseI18nConfigParams } from 'gt-i18n/internal/types';\nimport {\n defaultEnableI18nCookieName,\n defaultLocaleCookieName,\n defaultRegionCookieName,\n} from './cookieNames';\n\n/**\n * Helps us distinguish behavior for SPA vs server-rendered apps.\n * - server-rendered apps must use context\n * - SPA apps can synchronously access the locale\n */\nexport type RenderStrategy = 'SPA' | 'server-render';\n\ntype CookieNameConfig = {\n localeCookieName?: string;\n regionCookieName?: string;\n enableI18nCookieName?: string;\n};\n\nexport type ReactI18nConfigParams = BaseI18nConfigParams & CookieNameConfig;\n\nconst defaultRenderStrategy: RenderStrategy = 'server-render';\nconst reactI18nConfigBrand = Symbol.for(\n 'generaltranslation.react-core.ReactI18nConfig'\n);\n\nexport class ReactI18nConfig extends I18nConfig {\n private renderStrategy: RenderStrategy;\n private localeCookieName: string;\n private regionCookieName: string;\n private enableI18nCookieName: string;\n\n constructor(\n params: ReactI18nConfigParams = {},\n renderStrategy: RenderStrategy = defaultRenderStrategy\n ) {\n super(params);\n validateRenderStrategy(renderStrategy);\n Object.defineProperty(this, reactI18nConfigBrand, { value: true });\n this.renderStrategy = renderStrategy;\n this.localeCookieName = params.localeCookieName ?? defaultLocaleCookieName;\n this.regionCookieName = params.regionCookieName ?? defaultRegionCookieName;\n this.enableI18nCookieName =\n params.enableI18nCookieName ?? defaultEnableI18nCookieName;\n }\n\n getRenderStrategy(): RenderStrategy {\n return this.renderStrategy;\n }\n\n getLocaleCookieName(): string {\n return this.localeCookieName;\n }\n\n getRegionCookieName(): string {\n return this.regionCookieName;\n }\n\n getEnableI18nCookieName(): string {\n return this.enableI18nCookieName;\n }\n\n /**\n * Opt-in (`_tagIds`): whether `<T>` output should carry its translation hash as\n * a `data-_gt-hash` attribute for tooling. Requires the literal `true`.\n */\n isIdTaggingEnabled(): boolean {\n return this.runtimeConfig._tagIds === true;\n }\n}\n\nexport function getI18nConfig(): ReactI18nConfig {\n const i18nConfig = getBaseI18nConfig();\n if (isReactI18nConfig(i18nConfig)) {\n return i18nConfig;\n }\n throw new Error(\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'Cannot read ReactI18nConfig after base I18nConfig setup.',\n why: 'the internal I18nConfig singleton was initialized without react-core render strategy support',\n fix: 'Initialize GT through gt-react or @generaltranslation/react-core/pure.',\n })\n );\n}\n\nexport function setI18nConfig(nextI18nConfig: ReactI18nConfig): void {\n setBaseI18nConfig(nextI18nConfig);\n}\n\nexport function initializeI18nConfig(\n params: ReactI18nConfigParams = {},\n renderStrategy: RenderStrategy = defaultRenderStrategy\n): ReactI18nConfig {\n const nextI18nConfig = new ReactI18nConfig(params, renderStrategy);\n setI18nConfig(nextI18nConfig);\n return nextI18nConfig;\n}\n\nfunction validateRenderStrategy(\n renderStrategy: RenderStrategy\n): asserts renderStrategy is RenderStrategy {\n if (renderStrategy === 'SPA' || renderStrategy === 'server-render') return;\n throw new Error(\n createDiagnosticMessage({\n source: '@generaltranslation/react-core',\n severity: 'Error',\n whatHappened: 'Invalid React render strategy.',\n why: `the render strategy must be \"SPA\" or \"server-render\", but received \"${String(renderStrategy)}\"`,\n fix: 'Initialize GT through gt-react or pass a valid render strategy.',\n })\n );\n}\n\nfunction isReactI18nConfig(\n i18nConfig: I18nConfig\n): i18nConfig is ReactI18nConfig {\n if (i18nConfig instanceof ReactI18nConfig) return true;\n\n const maybeReactI18nConfig = i18nConfig as I18nConfig &\n Record<PropertyKey, unknown>;\n return (\n maybeReactI18nConfig[reactI18nConfigBrand] === true &&\n typeof maybeReactI18nConfig.getRenderStrategy === 'function' &&\n typeof maybeReactI18nConfig.getLocaleCookieName === 'function' &&\n typeof maybeReactI18nConfig.getRegionCookieName === 'function' &&\n typeof maybeReactI18nConfig.getEnableI18nCookieName === 'function'\n );\n}\n"],"mappings":"oLA4BA,MAAM,EAAwC,gBACxC,EAAuB,OAAO,IAClC,gDACD,CAED,IAAa,EAAb,cAAqC,CAAW,CAC9C,eACA,iBACA,iBACA,qBAEA,YACE,EAAgC,EAAE,CAClC,EAAiC,EACjC,CACA,MAAM,EAAO,CACb,EAAuB,EAAe,CACtC,OAAO,eAAe,KAAM,EAAsB,CAAE,MAAO,GAAM,CAAC,CAClE,KAAK,eAAiB,EACtB,KAAK,iBAAmB,EAAO,kBAAA,4BAC/B,KAAK,iBAAmB,EAAO,kBAAA,4BAC/B,KAAK,qBACH,EAAO,sBAAA,iCAGX,mBAAoC,CAClC,OAAO,KAAK,eAGd,qBAA8B,CAC5B,OAAO,KAAK,iBAGd,qBAA8B,CAC5B,OAAO,KAAK,iBAGd,yBAAkC,CAChC,OAAO,KAAK,qBAOd,oBAA8B,CAC5B,OAAO,KAAK,cAAc,UAAY,KAI1C,SAAgBA,GAAiC,CAC/C,IAAM,EAAaC,GAAmB,CACtC,GAAI,EAAkB,EAAW,CAC/B,OAAO,EAET,MAAU,MACR,EAAwB,CACtB,OAAQ,iCACR,SAAU,QACV,aAAc,2DACd,IAAK,+FACL,IAAK,yEACN,CAAC,CACH,CAGH,SAAgBC,EAAc,EAAuC,CACnE,EAAkB,EAAe,CAGnC,SAAgB,EACd,EAAgC,EAAE,CAClC,EAAiC,EAChB,CACjB,IAAM,EAAiB,IAAI,EAAgB,EAAQ,EAAe,CAElE,OADA,EAAc,EAAe,CACtB,EAGT,SAAS,EACP,EAC0C,CACtC,SAAmB,OAAS,IAAmB,iBACnD,MAAU,MACR,EAAwB,CACtB,OAAQ,iCACR,SAAU,QACV,aAAc,iCACd,IAAK,uEAAuE,OAAO,EAAe,CAAC,GACnG,IAAK,kEACN,CAAC,CACH,CAGH,SAAS,EACP,EAC+B,CAC/B,GAAI,aAAsB,EAAiB,MAAO,GAElD,IAAM,EAAuB,EAE7B,OACE,EAAqB,KAA0B,IAC/C,OAAO,EAAqB,mBAAsB,YAClD,OAAO,EAAqB,qBAAwB,YACpD,OAAO,EAAqB,qBAAwB,YACpD,OAAO,EAAqB,yBAA4B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderPreparedT.shared.cjs","names":["Fragment","idTaggingEnabled"],"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 {\n cloneElement,\n createElement,\n Fragment,\n isValidElement,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport type { TaggedChildren } from '../types';\nimport { idTaggingEnabled } from '../translation/resolveTagHash';\n\n// Opt-in id-tagging: when a `hash` is provided, the translation hash is exposed\n// on the DOM as `data-_gt-hash` so tooling can map a rendered node back to its\n// published translation.\n//\n// Span injection is kept to the minimum necessary: when the <T> renders a single\n// host element we put the attribute directly on THAT element (no wrapper), so <T>\n// keeps copying the source 1:1. Only when there is no element to carry it — bare\n// text, a fragment, or a component root — do we inject a layout-neutral span\n// (`display: contents`, so it generates no box and children lay out as before).\n//\n// DOM-only: skipped on React Native (there is no `span`/DOM attribute analog).\n// The rest of this module stays platform-agnostic; this is a runtime guard, not a\n// native import.\nconst TAG_STYLE = { display: 'contents' } as const;\n// Canonical React Native detection (RN sets navigator.product = 'ReactNative').\n// False in the browser AND in Node SSR/RSC, so the span is still emitted server-\n// side (where the harvest reads it).\nconst IS_REACT_NATIVE =\n (globalThis as { navigator?: { product?: string } }).navigator?.product ===\n 'ReactNative';\n\n// Whether a rendered node produces NO DOM — so id-tagging must leave it untouched\n// (wrapping it in a hash span would create an empty <span>, altering :empty/child\n// structure and injecting an invalid span under restricted parents). Covers the\n// scalar non-renderers (null / undefined / booleans / ''), arrays whose every\n// element renders nothing (`items.map(...)` over an empty list, `[null, false]`,\n// nested empties — TaggedChildren accepts arrays), and empty React fragments.\n// NB: 0 and NaN DO render text, so they are intentionally NOT treated as empty.\nfunction rendersNothing(node: ReactNode): boolean {\n if (node == null || typeof node === 'boolean' || node === '') return true;\n if (Array.isArray(node)) return !node.some((n) => !rendersNothing(n));\n if (isValidElement(node) && node.type === Fragment) {\n const children = (node.props as { children?: ReactNode }).children;\n return children == null || rendersNothing(children);\n }\n return false;\n}\n\n// Opt-in id-tagging (powers RRWeb localized replay / in-context tooling): expose\n// the translation hash on the DOM as `data-_gt-hash`. Factored out of the render\n// path so it's clear this whole block is dedicated to id-tagging, not core <T>\n// behavior. Called only when a `hash` was produced (see resolveTagHash).\nfunction applyIdTag(rendered: ReactNode, hash: string): ReactNode {\n // `hash` is only produced when tagging is on, but re-assert the config here so a\n // stray hash can never inject DOM; and never on React Native (no span/DOM attr\n // analog — IS_REACT_NATIVE is checked first so the config isn't read there).\n if (IS_REACT_NATIVE || !idTaggingEnabled()) return rendered;\n // Single host element (e.g. `<T><td>…</td></T>`) → annotate it directly, no\n // wrapper. Valid wherever the element itself is valid — including inside\n // <tr>/<select>/<ul> — and avoids the span entirely.\n if (isValidElement(rendered) && typeof rendered.type === 'string') {\n return cloneElement(rendered as ReactElement<Record<string, unknown>>, {\n 'data-_gt-hash': hash,\n });\n }\n // Output that renders no DOM stays no-DOM: an empty <span data-_gt-hash> would\n // change :empty/child structure and inject an (invalid, under restricted\n // parents) span even for an empty branch.\n if (rendersNothing(rendered)) return rendered;\n // No element to carry the attribute (bare text / fragment / component root) →\n // wrap in a layout-neutral span. This is the only case that injects one.\n return createElement(\n 'span',\n { 'data-_gt-hash': hash, style: TAG_STYLE },\n rendered\n );\n}\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 // The translation hash for this <T> (see resolveTagHash) — the same key the\n // published-translation cache/CDN is keyed by. Set only when id-tagging is\n // enabled; when undefined the output is rendered untouched. Presence of `hash`\n // is the single signal to tag (there is no separate boolean).\n hash?: string;\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 hash,\n }: RenderPreparedTParams): ReactNode {\n const rendered =\n !shouldTranslate || targetJsxChildren == null\n ? renderSource({\n taggedSourceChildren,\n defaultLocale,\n enableI18n,\n })\n : renderTarget({\n taggedSourceChildren,\n targetJsxChildren,\n locales: [locale, defaultLocale],\n enableI18n,\n });\n\n // Opt-in id-tagging is entirely handled by applyIdTag; `hash` presence is the\n // enable signal (produced by resolveTagHash only when tagging is on).\n return hash ? applyIdTag(rendered, hash) : rendered;\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
|
|
1
|
+
{"version":3,"file":"renderPreparedT.shared.cjs","names":["Fragment","idTaggingEnabled"],"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 {\n cloneElement,\n createElement,\n Fragment,\n isValidElement,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport type { TaggedChildren } from '../types';\nimport { idTaggingEnabled } from '../translation/resolveTagHash';\n\n// Opt-in id-tagging: when a `hash` is provided, the translation hash is exposed\n// on the DOM as `data-_gt-hash` so tooling can map a rendered node back to its\n// published translation.\n//\n// Span injection is kept to the minimum necessary: when the <T> renders a single\n// host element we put the attribute directly on THAT element (no wrapper), so <T>\n// keeps copying the source 1:1. Only when there is no element to carry it — bare\n// text, a fragment, or a component root — do we inject a layout-neutral span\n// (`display: contents`, so it generates no box and children lay out as before).\n//\n// DOM-only: skipped on React Native (there is no `span`/DOM attribute analog).\n// The rest of this module stays platform-agnostic; this is a runtime guard, not a\n// native import.\nconst TAG_STYLE = { display: 'contents' } as const;\n// Canonical React Native detection (RN sets navigator.product = 'ReactNative').\n// False in the browser AND in Node SSR/RSC, so the span is still emitted server-\n// side (where the harvest reads it).\nconst IS_REACT_NATIVE =\n (globalThis as { navigator?: { product?: string } }).navigator?.product ===\n 'ReactNative';\n\n// Whether a rendered node produces NO DOM — so id-tagging must leave it untouched\n// (wrapping it in a hash span would create an empty <span>, altering :empty/child\n// structure and injecting an invalid span under restricted parents). Covers the\n// scalar non-renderers (null / undefined / booleans / ''), arrays whose every\n// element renders nothing (`items.map(...)` over an empty list, `[null, false]`,\n// nested empties — TaggedChildren accepts arrays), and empty React fragments.\n// NB: 0 and NaN DO render text, so they are intentionally NOT treated as empty.\nfunction rendersNothing(node: ReactNode): boolean {\n if (node == null || typeof node === 'boolean' || node === '') return true;\n if (Array.isArray(node)) return !node.some((n) => !rendersNothing(n));\n if (isValidElement(node) && node.type === Fragment) {\n const children = (node.props as { children?: ReactNode }).children;\n return children == null || rendersNothing(children);\n }\n return false;\n}\n\n// Opt-in id-tagging (powers RRWeb localized replay / in-context tooling): expose\n// the translation hash on the DOM as `data-_gt-hash`. Factored out of the render\n// path so it's clear this whole block is dedicated to id-tagging, not core <T>\n// behavior. Called only when a `hash` was produced (see resolveTagHash).\nfunction applyIdTag(rendered: ReactNode, hash: string): ReactNode {\n // `hash` is only produced when tagging is on, but re-assert the config here so a\n // stray hash can never inject DOM; and never on React Native (no span/DOM attr\n // analog — IS_REACT_NATIVE is checked first so the config isn't read there).\n if (IS_REACT_NATIVE || !idTaggingEnabled()) return rendered;\n // Single host element (e.g. `<T><td>…</td></T>`) → annotate it directly, no\n // wrapper. Valid wherever the element itself is valid — including inside\n // <tr>/<select>/<ul> — and avoids the span entirely.\n if (isValidElement(rendered) && typeof rendered.type === 'string') {\n return cloneElement(rendered as ReactElement<Record<string, unknown>>, {\n 'data-_gt-hash': hash,\n });\n }\n // Output that renders no DOM stays no-DOM: an empty <span data-_gt-hash> would\n // change :empty/child structure and inject an (invalid, under restricted\n // parents) span even for an empty branch.\n if (rendersNothing(rendered)) return rendered;\n // No element to carry the attribute (bare text / fragment / component root) →\n // wrap in a layout-neutral span. This is the only case that injects one.\n return createElement(\n 'span',\n { 'data-_gt-hash': hash, style: TAG_STYLE },\n rendered\n );\n}\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 // The translation hash for this <T> (see resolveTagHash) — the same key the\n // published-translation cache/CDN is keyed by. Set only when id-tagging is\n // enabled; when undefined the output is rendered untouched. Presence of `hash`\n // is the single signal to tag (there is no separate boolean).\n hash?: string;\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 hash,\n }: RenderPreparedTParams): ReactNode {\n const rendered =\n !shouldTranslate || targetJsxChildren == null\n ? renderSource({\n taggedSourceChildren,\n defaultLocale,\n enableI18n,\n })\n : renderTarget({\n taggedSourceChildren,\n targetJsxChildren,\n locales: [locale, defaultLocale],\n enableI18n,\n });\n\n // Opt-in id-tagging is entirely handled by applyIdTag; `hash` presence is the\n // enable signal (produced by resolveTagHash only when tagging is on).\n return hash ? applyIdTag(rendered, hash) : rendered;\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":"4HA2BA,MAAM,EAAY,CAAE,QAAS,WAAY,CAInC,EACH,WAAoD,WAAW,UAChE,cASF,SAAS,EAAe,EAA0B,CAChD,GAAI,GAAQ,MAAQ,OAAO,GAAS,WAAa,IAAS,GAAI,MAAO,GACrE,GAAI,MAAM,QAAQ,EAAK,CAAE,MAAO,CAAC,EAAK,KAAM,GAAM,CAAC,EAAe,EAAE,CAAC,CACrE,IAAA,EAAA,EAAA,gBAAmB,EAAK,EAAI,EAAK,OAASA,EAAAA,SAAU,CAClD,IAAM,EAAY,EAAK,MAAmC,SAC1D,OAAO,GAAY,MAAQ,EAAe,EAAS,CAErD,MAAO,GAOT,SAAS,EAAW,EAAqB,EAAyB,CAmBhE,OAfI,GAAmB,CAACC,EAAAA,kBAAkB,CAAS,GAInD,EAAA,EAAA,gBAAmB,EAAS,EAAI,OAAO,EAAS,MAAS,UACvD,EAAA,EAAA,cAAoB,EAAmD,CACrE,gBAAiB,EAClB,CAAC,CAKA,EAAe,EAAS,CAAS,GAGrC,EAAA,EAAA,eACE,OACA,CAAE,gBAAiB,EAAM,MAAO,EAAW,CAC3C,EACD,CAsBH,SAAS,EAAsB,CAC7B,wBACA,4BAI6C,CAC7C,SAAS,EAAgB,CACvB,uBACA,oBACA,SACA,gBACA,aACA,kBACA,QACmC,CACnC,IAAM,EACJ,CAAC,GAAmB,GAAqB,KACrC,EAAa,CACX,uBACA,gBACA,aACD,CAAC,CACF,EAAa,CACX,uBACA,oBACA,QAAS,CAAC,EAAQ,EAAc,CAChC,aACD,CAAC,CAIR,OAAO,EAAO,EAAW,EAAU,EAAK,CAAG,EAG7C,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 +1 @@
|
|
|
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 {\n cloneElement,\n createElement,\n Fragment,\n isValidElement,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport type { TaggedChildren } from '../types';\nimport { idTaggingEnabled } from '../translation/resolveTagHash';\n\n// Opt-in id-tagging: when a `hash` is provided, the translation hash is exposed\n// on the DOM as `data-_gt-hash` so tooling can map a rendered node back to its\n// published translation.\n//\n// Span injection is kept to the minimum necessary: when the <T> renders a single\n// host element we put the attribute directly on THAT element (no wrapper), so <T>\n// keeps copying the source 1:1. Only when there is no element to carry it — bare\n// text, a fragment, or a component root — do we inject a layout-neutral span\n// (`display: contents`, so it generates no box and children lay out as before).\n//\n// DOM-only: skipped on React Native (there is no `span`/DOM attribute analog).\n// The rest of this module stays platform-agnostic; this is a runtime guard, not a\n// native import.\nconst TAG_STYLE = { display: 'contents' } as const;\n// Canonical React Native detection (RN sets navigator.product = 'ReactNative').\n// False in the browser AND in Node SSR/RSC, so the span is still emitted server-\n// side (where the harvest reads it).\nconst IS_REACT_NATIVE =\n (globalThis as { navigator?: { product?: string } }).navigator?.product ===\n 'ReactNative';\n\n// Whether a rendered node produces NO DOM — so id-tagging must leave it untouched\n// (wrapping it in a hash span would create an empty <span>, altering :empty/child\n// structure and injecting an invalid span under restricted parents). Covers the\n// scalar non-renderers (null / undefined / booleans / ''), arrays whose every\n// element renders nothing (`items.map(...)` over an empty list, `[null, false]`,\n// nested empties — TaggedChildren accepts arrays), and empty React fragments.\n// NB: 0 and NaN DO render text, so they are intentionally NOT treated as empty.\nfunction rendersNothing(node: ReactNode): boolean {\n if (node == null || typeof node === 'boolean' || node === '') return true;\n if (Array.isArray(node)) return !node.some((n) => !rendersNothing(n));\n if (isValidElement(node) && node.type === Fragment) {\n const children = (node.props as { children?: ReactNode }).children;\n return children == null || rendersNothing(children);\n }\n return false;\n}\n\n// Opt-in id-tagging (powers RRWeb localized replay / in-context tooling): expose\n// the translation hash on the DOM as `data-_gt-hash`. Factored out of the render\n// path so it's clear this whole block is dedicated to id-tagging, not core <T>\n// behavior. Called only when a `hash` was produced (see resolveTagHash).\nfunction applyIdTag(rendered: ReactNode, hash: string): ReactNode {\n // `hash` is only produced when tagging is on, but re-assert the config here so a\n // stray hash can never inject DOM; and never on React Native (no span/DOM attr\n // analog — IS_REACT_NATIVE is checked first so the config isn't read there).\n if (IS_REACT_NATIVE || !idTaggingEnabled()) return rendered;\n // Single host element (e.g. `<T><td>…</td></T>`) → annotate it directly, no\n // wrapper. Valid wherever the element itself is valid — including inside\n // <tr>/<select>/<ul> — and avoids the span entirely.\n if (isValidElement(rendered) && typeof rendered.type === 'string') {\n return cloneElement(rendered as ReactElement<Record<string, unknown>>, {\n 'data-_gt-hash': hash,\n });\n }\n // Output that renders no DOM stays no-DOM: an empty <span data-_gt-hash> would\n // change :empty/child structure and inject an (invalid, under restricted\n // parents) span even for an empty branch.\n if (rendersNothing(rendered)) return rendered;\n // No element to carry the attribute (bare text / fragment / component root) →\n // wrap in a layout-neutral span. This is the only case that injects one.\n return createElement(\n 'span',\n { 'data-_gt-hash': hash, style: TAG_STYLE },\n rendered\n );\n}\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 // The translation hash for this <T> (see resolveTagHash) — the same key the\n // published-translation cache/CDN is keyed by. Set only when id-tagging is\n // enabled; when undefined the output is rendered untouched. Presence of `hash`\n // is the single signal to tag (there is no separate boolean).\n hash?: string;\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 hash,\n }: RenderPreparedTParams): ReactNode {\n const rendered =\n !shouldTranslate || targetJsxChildren == null\n ? renderSource({\n taggedSourceChildren,\n defaultLocale,\n enableI18n,\n })\n : renderTarget({\n taggedSourceChildren,\n targetJsxChildren,\n locales: [locale, defaultLocale],\n enableI18n,\n });\n\n // Opt-in id-tagging is entirely handled by applyIdTag; `hash` presence is the\n // enable signal (produced by resolveTagHash only when tagging is on).\n return hash ? applyIdTag(rendered, hash) : rendered;\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
|
|
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 {\n cloneElement,\n createElement,\n Fragment,\n isValidElement,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport type { TaggedChildren } from '../types';\nimport { idTaggingEnabled } from '../translation/resolveTagHash';\n\n// Opt-in id-tagging: when a `hash` is provided, the translation hash is exposed\n// on the DOM as `data-_gt-hash` so tooling can map a rendered node back to its\n// published translation.\n//\n// Span injection is kept to the minimum necessary: when the <T> renders a single\n// host element we put the attribute directly on THAT element (no wrapper), so <T>\n// keeps copying the source 1:1. Only when there is no element to carry it — bare\n// text, a fragment, or a component root — do we inject a layout-neutral span\n// (`display: contents`, so it generates no box and children lay out as before).\n//\n// DOM-only: skipped on React Native (there is no `span`/DOM attribute analog).\n// The rest of this module stays platform-agnostic; this is a runtime guard, not a\n// native import.\nconst TAG_STYLE = { display: 'contents' } as const;\n// Canonical React Native detection (RN sets navigator.product = 'ReactNative').\n// False in the browser AND in Node SSR/RSC, so the span is still emitted server-\n// side (where the harvest reads it).\nconst IS_REACT_NATIVE =\n (globalThis as { navigator?: { product?: string } }).navigator?.product ===\n 'ReactNative';\n\n// Whether a rendered node produces NO DOM — so id-tagging must leave it untouched\n// (wrapping it in a hash span would create an empty <span>, altering :empty/child\n// structure and injecting an invalid span under restricted parents). Covers the\n// scalar non-renderers (null / undefined / booleans / ''), arrays whose every\n// element renders nothing (`items.map(...)` over an empty list, `[null, false]`,\n// nested empties — TaggedChildren accepts arrays), and empty React fragments.\n// NB: 0 and NaN DO render text, so they are intentionally NOT treated as empty.\nfunction rendersNothing(node: ReactNode): boolean {\n if (node == null || typeof node === 'boolean' || node === '') return true;\n if (Array.isArray(node)) return !node.some((n) => !rendersNothing(n));\n if (isValidElement(node) && node.type === Fragment) {\n const children = (node.props as { children?: ReactNode }).children;\n return children == null || rendersNothing(children);\n }\n return false;\n}\n\n// Opt-in id-tagging (powers RRWeb localized replay / in-context tooling): expose\n// the translation hash on the DOM as `data-_gt-hash`. Factored out of the render\n// path so it's clear this whole block is dedicated to id-tagging, not core <T>\n// behavior. Called only when a `hash` was produced (see resolveTagHash).\nfunction applyIdTag(rendered: ReactNode, hash: string): ReactNode {\n // `hash` is only produced when tagging is on, but re-assert the config here so a\n // stray hash can never inject DOM; and never on React Native (no span/DOM attr\n // analog — IS_REACT_NATIVE is checked first so the config isn't read there).\n if (IS_REACT_NATIVE || !idTaggingEnabled()) return rendered;\n // Single host element (e.g. `<T><td>…</td></T>`) → annotate it directly, no\n // wrapper. Valid wherever the element itself is valid — including inside\n // <tr>/<select>/<ul> — and avoids the span entirely.\n if (isValidElement(rendered) && typeof rendered.type === 'string') {\n return cloneElement(rendered as ReactElement<Record<string, unknown>>, {\n 'data-_gt-hash': hash,\n });\n }\n // Output that renders no DOM stays no-DOM: an empty <span data-_gt-hash> would\n // change :empty/child structure and inject an (invalid, under restricted\n // parents) span even for an empty branch.\n if (rendersNothing(rendered)) return rendered;\n // No element to carry the attribute (bare text / fragment / component root) →\n // wrap in a layout-neutral span. This is the only case that injects one.\n return createElement(\n 'span',\n { 'data-_gt-hash': hash, style: TAG_STYLE },\n rendered\n );\n}\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 // The translation hash for this <T> (see resolveTagHash) — the same key the\n // published-translation cache/CDN is keyed by. Set only when id-tagging is\n // enabled; when undefined the output is rendered untouched. Presence of `hash`\n // is the single signal to tag (there is no separate boolean).\n hash?: string;\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 hash,\n }: RenderPreparedTParams): ReactNode {\n const rendered =\n !shouldTranslate || targetJsxChildren == null\n ? renderSource({\n taggedSourceChildren,\n defaultLocale,\n enableI18n,\n })\n : renderTarget({\n taggedSourceChildren,\n targetJsxChildren,\n locales: [locale, defaultLocale],\n enableI18n,\n });\n\n // Opt-in id-tagging is entirely handled by applyIdTag; `hash` presence is the\n // enable signal (produced by resolveTagHash only when tagging is on).\n return hash ? applyIdTag(rendered, hash) : rendered;\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":"+JA2BA,MAAM,EAAY,CAAE,QAAS,WAAY,CAInC,EACH,WAAoD,WAAW,UAChE,cASF,SAAS,EAAe,EAA0B,CAChD,GAAI,GAAQ,MAAQ,OAAO,GAAS,WAAa,IAAS,GAAI,MAAO,GACrE,GAAI,MAAM,QAAQ,EAAK,CAAE,MAAO,CAAC,EAAK,KAAM,GAAM,CAAC,EAAe,EAAE,CAAC,CACrE,GAAI,EAAe,EAAK,EAAI,EAAK,OAAS,EAAU,CAClD,IAAM,EAAY,EAAK,MAAmC,SAC1D,OAAO,GAAY,MAAQ,EAAe,EAAS,CAErD,MAAO,GAOT,SAAS,EAAW,EAAqB,EAAyB,CAmBhE,OAfI,GAAmB,CAAC,GAAkB,CAAS,EAI/C,EAAe,EAAS,EAAI,OAAO,EAAS,MAAS,SAChD,EAAa,EAAmD,CACrE,gBAAiB,EAClB,CAAC,CAKA,EAAe,EAAS,CAAS,EAG9B,EACL,OACA,CAAE,gBAAiB,EAAM,MAAO,EAAW,CAC3C,EACD,CAsBH,SAAS,EAAsB,CAC7B,wBACA,4BAI6C,CAC7C,SAAS,EAAgB,CACvB,uBACA,oBACA,SACA,gBACA,aACA,kBACA,QACmC,CACnC,IAAM,EACJ,CAAC,GAAmB,GAAqB,KACrC,EAAa,CACX,uBACA,gBACA,aACD,CAAC,CACF,EAAa,CACX,uBACA,oBACA,QAAS,CAAC,EAAQ,EAAc,CAChC,aACD,CAAC,CAIR,OAAO,EAAO,EAAW,EAAU,EAAK,CAAG,EAG7C,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@generaltranslation/react-core",
|
|
3
|
-
"version": "11.1.7
|
|
3
|
+
"version": "11.1.7",
|
|
4
4
|
"description": "A pure React library for internationalization",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
"react": ">=18.0.0"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@generaltranslation/format": "0.1.5
|
|
15
|
-
"generaltranslation": "9.1.3
|
|
16
|
-
"gt-i18n": "1.0.13
|
|
14
|
+
"@generaltranslation/format": "0.1.5",
|
|
15
|
+
"generaltranslation": "9.1.3",
|
|
16
|
+
"gt-i18n": "1.0.13"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|