gt-next 11.0.2 → 11.0.4

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.
Files changed (86) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/condition-store/AsyncConditionStore.d.ts.map +1 -1
  3. package/dist/condition-store/AsyncConditionStore.js +1 -4
  4. package/dist/condition-store/AsyncConditionStore.js.map +1 -1
  5. package/dist/condition-store/AsyncConditionStore.mjs +2 -5
  6. package/dist/condition-store/AsyncConditionStore.mjs.map +1 -1
  7. package/dist/config-dir/props/withGTConfigProps.d.ts +2 -0
  8. package/dist/config-dir/props/withGTConfigProps.d.ts.map +1 -1
  9. package/dist/config-dir/props/withGTConfigProps.js.map +1 -1
  10. package/dist/config-dir/props/withGTConfigProps.mjs.map +1 -1
  11. package/dist/config.d.ts +1 -0
  12. package/dist/config.d.ts.map +1 -1
  13. package/dist/config.js +5 -1
  14. package/dist/config.js.map +1 -1
  15. package/dist/config.mjs +5 -1
  16. package/dist/config.mjs.map +1 -1
  17. package/dist/errors/createErrors.d.ts +3 -1
  18. package/dist/errors/createErrors.d.ts.map +1 -1
  19. package/dist/errors/createErrors.js +23 -5
  20. package/dist/errors/createErrors.js.map +1 -1
  21. package/dist/errors/createErrors.mjs +21 -5
  22. package/dist/errors/createErrors.mjs.map +1 -1
  23. package/dist/errors/ssg.d.ts +1 -0
  24. package/dist/errors/ssg.d.ts.map +1 -1
  25. package/dist/errors/ssg.js +9 -1
  26. package/dist/errors/ssg.js.map +1 -1
  27. package/dist/errors/ssg.mjs +7 -1
  28. package/dist/errors/ssg.mjs.map +1 -1
  29. package/dist/index.client.d.ts +3 -1
  30. package/dist/index.client.d.ts.map +1 -1
  31. package/dist/index.client.js +5 -0
  32. package/dist/index.client.js.map +1 -1
  33. package/dist/index.client.mjs +5 -1
  34. package/dist/index.client.mjs.map +1 -1
  35. package/dist/index.rsc.d.ts +7 -1
  36. package/dist/index.rsc.d.ts.map +1 -1
  37. package/dist/index.rsc.js +8 -0
  38. package/dist/index.rsc.js.map +1 -1
  39. package/dist/index.rsc.mjs +9 -2
  40. package/dist/index.rsc.mjs.map +1 -1
  41. package/dist/index.server.d.ts +2 -0
  42. package/dist/index.server.d.ts.map +1 -1
  43. package/dist/index.server.js +2 -0
  44. package/dist/index.server.js.map +1 -1
  45. package/dist/index.server.mjs +2 -1
  46. package/dist/index.server.mjs.map +1 -1
  47. package/dist/index.types.d.ts +7 -1
  48. package/dist/index.types.d.ts.map +1 -1
  49. package/dist/index.types.js +8 -0
  50. package/dist/index.types.js.map +1 -1
  51. package/dist/index.types.mjs +8 -1
  52. package/dist/index.types.mjs.map +1 -1
  53. package/dist/middleware-dir/createNextMiddleware.d.ts +1 -3
  54. package/dist/middleware-dir/createNextMiddleware.d.ts.map +1 -1
  55. package/dist/middleware-dir/createNextMiddleware.js +4 -9
  56. package/dist/middleware-dir/createNextMiddleware.js.map +1 -1
  57. package/dist/middleware-dir/createNextMiddleware.mjs +5 -10
  58. package/dist/middleware-dir/createNextMiddleware.mjs.map +1 -1
  59. package/dist/middleware-dir/utils.d.ts.map +1 -1
  60. package/dist/middleware-dir/utils.js +2 -4
  61. package/dist/middleware-dir/utils.js.map +1 -1
  62. package/dist/middleware-dir/utils.mjs +2 -4
  63. package/dist/middleware-dir/utils.mjs.map +1 -1
  64. package/dist/pages-dir/parseLocale.d.ts.map +1 -1
  65. package/dist/pages-dir/parseLocale.js +2 -4
  66. package/dist/pages-dir/parseLocale.js.map +1 -1
  67. package/dist/pages-dir/parseLocale.mjs +2 -4
  68. package/dist/pages-dir/parseLocale.mjs.map +1 -1
  69. package/dist/pages-dir/withGTStaticProps.d.ts +18 -0
  70. package/dist/pages-dir/withGTStaticProps.d.ts.map +1 -0
  71. package/dist/pages-dir/withGTStaticProps.js +34 -0
  72. package/dist/pages-dir/withGTStaticProps.js.map +1 -0
  73. package/dist/pages-dir/withGTStaticProps.mjs +32 -0
  74. package/dist/pages-dir/withGTStaticProps.mjs.map +1 -0
  75. package/dist/utils/client-boundary.d.ts.map +1 -1
  76. package/dist/utils/client-boundary.js +3 -1
  77. package/dist/utils/client-boundary.js.map +1 -1
  78. package/dist/utils/client-boundary.mjs +4 -2
  79. package/dist/utils/client-boundary.mjs.map +1 -1
  80. package/dist/utils/pathRegex.d.ts +3 -0
  81. package/dist/utils/pathRegex.d.ts.map +1 -0
  82. package/dist/utils/pathRegex.js +19 -0
  83. package/dist/utils/pathRegex.js.map +1 -0
  84. package/dist/utils/pathRegex.mjs +17 -0
  85. package/dist/utils/pathRegex.mjs.map +1 -0
  86. package/package.json +11 -7
@@ -0,0 +1,18 @@
1
+ import type { GetStaticProps, PreviewData } from 'next';
2
+ import type { ParsedUrlQuery } from 'querystring';
3
+ import { getTranslationsSnapshot } from 'gt-react';
4
+ type TranslationsSnapshot = Awaited<ReturnType<typeof getTranslationsSnapshot>>;
5
+ type GTStaticProps = {
6
+ locale: string;
7
+ translations: TranslationsSnapshot;
8
+ };
9
+ export type WithGTStaticProps<Props extends Record<string, unknown> = Record<string, unknown>> = Props & GTStaticProps;
10
+ /**
11
+ * Wraps a Pages Router getStaticProps() function with locale-specific GT props.
12
+ * Next.js Pages Router locale routing must be configured so getStaticProps()
13
+ * runs once for each locale.
14
+ */
15
+ export declare function withGTStaticProps<Props extends Record<string, unknown> = Record<string, unknown>, Params extends ParsedUrlQuery = ParsedUrlQuery, Preview extends PreviewData = PreviewData>(getStaticProps?: GetStaticProps<Props, Params, Preview>): GetStaticProps<WithGTStaticProps<Props>, Params, Preview>;
16
+ export type WithGTStaticPropsFunction = typeof withGTStaticProps;
17
+ export {};
18
+ //# sourceMappingURL=withGTStaticProps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withGTStaticProps.d.ts","sourceRoot":"","sources":["../../src/pages-dir/withGTStaticProps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAyB,WAAW,EAAE,MAAM,MAAM,CAAC;AAC/E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAGnD,KAAK,oBAAoB,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAAC,CAAC;AAEhF,KAAK,aAAa,GAAG;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,oBAAoB,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAC3B,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC7D,KAAK,GAAG,aAAa,CAAC;AAE1B;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/D,MAAM,SAAS,cAAc,GAAG,cAAc,EAC9C,OAAO,SAAS,WAAW,GAAG,WAAW,EAEzC,cAAc,CAAC,EAAE,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,GACtD,cAAc,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,CA8B3D;AAED,MAAM,MAAM,yBAAyB,GAAG,OAAO,iBAAiB,CAAC"}
@@ -0,0 +1,34 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../_virtual/_rolldown/runtime.js");
3
+ const require_errors_ssg = require("../errors/ssg.js");
4
+ let _generaltranslation_react_core_pure = require("@generaltranslation/react-core/pure");
5
+ let gt_react = require("gt-react");
6
+ //#region src/pages-dir/withGTStaticProps.ts
7
+ /**
8
+ * Wraps a Pages Router getStaticProps() function with locale-specific GT props.
9
+ * Next.js Pages Router locale routing must be configured so getStaticProps()
10
+ * runs once for each locale.
11
+ */
12
+ function withGTStaticProps(getStaticProps) {
13
+ return async (context) => {
14
+ if (!context.locale) throw new Error(require_errors_ssg.withGTStaticPropsLocaleRoutingError);
15
+ const result = getStaticProps ? await getStaticProps(context) : { props: {} };
16
+ if (!("props" in result)) return result;
17
+ const props = await result.props;
18
+ const defaultLocale = (0, _generaltranslation_react_core_pure.getI18nConfig)().getDefaultLocale();
19
+ const locale = context.locale;
20
+ const translations = locale === defaultLocale ? {} : await (0, gt_react.getTranslationsSnapshot)(locale);
21
+ return {
22
+ ...result,
23
+ props: {
24
+ ...props,
25
+ locale,
26
+ translations
27
+ }
28
+ };
29
+ };
30
+ }
31
+ //#endregion
32
+ exports.withGTStaticProps = withGTStaticProps;
33
+
34
+ //# sourceMappingURL=withGTStaticProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withGTStaticProps.js","names":["withGTStaticPropsLocaleRoutingError"],"sources":["../../src/pages-dir/withGTStaticProps.ts"],"sourcesContent":["import type { GetStaticProps, GetStaticPropsContext, PreviewData } from 'next';\nimport type { ParsedUrlQuery } from 'querystring';\nimport { getI18nConfig } from '@generaltranslation/react-core/pure';\nimport { getTranslationsSnapshot } from 'gt-react';\nimport { withGTStaticPropsLocaleRoutingError } from '../errors/ssg';\n\ntype TranslationsSnapshot = Awaited<ReturnType<typeof getTranslationsSnapshot>>;\n\ntype GTStaticProps = {\n locale: string;\n translations: TranslationsSnapshot;\n};\n\nexport type WithGTStaticProps<\n Props extends Record<string, unknown> = Record<string, unknown>,\n> = Props & GTStaticProps;\n\n/**\n * Wraps a Pages Router getStaticProps() function with locale-specific GT props.\n * Next.js Pages Router locale routing must be configured so getStaticProps()\n * runs once for each locale.\n */\nexport function withGTStaticProps<\n Props extends Record<string, unknown> = Record<string, unknown>,\n Params extends ParsedUrlQuery = ParsedUrlQuery,\n Preview extends PreviewData = PreviewData,\n>(\n getStaticProps?: GetStaticProps<Props, Params, Preview>\n): GetStaticProps<WithGTStaticProps<Props>, Params, Preview> {\n return async (context: GetStaticPropsContext<Params, Preview>) => {\n if (!context.locale) {\n throw new Error(withGTStaticPropsLocaleRoutingError);\n }\n\n const result = getStaticProps\n ? await getStaticProps(context)\n : { props: {} as Props };\n\n if (!('props' in result)) {\n return result;\n }\n\n const props = await result.props;\n const i18nConfig = getI18nConfig();\n const defaultLocale = i18nConfig.getDefaultLocale();\n const locale = context.locale;\n const translations =\n locale === defaultLocale ? {} : await getTranslationsSnapshot(locale);\n\n return {\n ...result,\n props: {\n ...props,\n locale,\n translations,\n },\n };\n };\n}\n\nexport type WithGTStaticPropsFunction = typeof withGTStaticProps;\n"],"mappings":";;;;;;;;;;;AAsBA,SAAgB,kBAKd,gBAC2D;AAC3D,QAAO,OAAO,YAAoD;AAChE,MAAI,CAAC,QAAQ,OACX,OAAM,IAAI,MAAMA,mBAAAA,oCAAoC;EAGtD,MAAM,SAAS,iBACX,MAAM,eAAe,QAAQ,GAC7B,EAAE,OAAO,EAAE,EAAW;AAE1B,MAAI,EAAE,WAAW,QACf,QAAO;EAGT,MAAM,QAAQ,MAAM,OAAO;EAE3B,MAAM,iBAAA,GAAA,oCAAA,gBAA0B,CAAC,kBAAkB;EACnD,MAAM,SAAS,QAAQ;EACvB,MAAM,eACJ,WAAW,gBAAgB,EAAE,GAAG,OAAA,GAAA,SAAA,yBAA8B,OAAO;AAEvE,SAAO;GACL,GAAG;GACH,OAAO;IACL,GAAG;IACH;IACA;IACD;GACF"}
@@ -0,0 +1,32 @@
1
+ import { withGTStaticPropsLocaleRoutingError } from "../errors/ssg.mjs";
2
+ import { getI18nConfig } from "@generaltranslation/react-core/pure";
3
+ import { getTranslationsSnapshot } from "gt-react";
4
+ //#region src/pages-dir/withGTStaticProps.ts
5
+ /**
6
+ * Wraps a Pages Router getStaticProps() function with locale-specific GT props.
7
+ * Next.js Pages Router locale routing must be configured so getStaticProps()
8
+ * runs once for each locale.
9
+ */
10
+ function withGTStaticProps(getStaticProps) {
11
+ return async (context) => {
12
+ if (!context.locale) throw new Error(withGTStaticPropsLocaleRoutingError);
13
+ const result = getStaticProps ? await getStaticProps(context) : { props: {} };
14
+ if (!("props" in result)) return result;
15
+ const props = await result.props;
16
+ const defaultLocale = getI18nConfig().getDefaultLocale();
17
+ const locale = context.locale;
18
+ const translations = locale === defaultLocale ? {} : await getTranslationsSnapshot(locale);
19
+ return {
20
+ ...result,
21
+ props: {
22
+ ...props,
23
+ locale,
24
+ translations
25
+ }
26
+ };
27
+ };
28
+ }
29
+ //#endregion
30
+ export { withGTStaticProps };
31
+
32
+ //# sourceMappingURL=withGTStaticProps.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withGTStaticProps.mjs","names":[],"sources":["../../src/pages-dir/withGTStaticProps.ts"],"sourcesContent":["import type { GetStaticProps, GetStaticPropsContext, PreviewData } from 'next';\nimport type { ParsedUrlQuery } from 'querystring';\nimport { getI18nConfig } from '@generaltranslation/react-core/pure';\nimport { getTranslationsSnapshot } from 'gt-react';\nimport { withGTStaticPropsLocaleRoutingError } from '../errors/ssg';\n\ntype TranslationsSnapshot = Awaited<ReturnType<typeof getTranslationsSnapshot>>;\n\ntype GTStaticProps = {\n locale: string;\n translations: TranslationsSnapshot;\n};\n\nexport type WithGTStaticProps<\n Props extends Record<string, unknown> = Record<string, unknown>,\n> = Props & GTStaticProps;\n\n/**\n * Wraps a Pages Router getStaticProps() function with locale-specific GT props.\n * Next.js Pages Router locale routing must be configured so getStaticProps()\n * runs once for each locale.\n */\nexport function withGTStaticProps<\n Props extends Record<string, unknown> = Record<string, unknown>,\n Params extends ParsedUrlQuery = ParsedUrlQuery,\n Preview extends PreviewData = PreviewData,\n>(\n getStaticProps?: GetStaticProps<Props, Params, Preview>\n): GetStaticProps<WithGTStaticProps<Props>, Params, Preview> {\n return async (context: GetStaticPropsContext<Params, Preview>) => {\n if (!context.locale) {\n throw new Error(withGTStaticPropsLocaleRoutingError);\n }\n\n const result = getStaticProps\n ? await getStaticProps(context)\n : { props: {} as Props };\n\n if (!('props' in result)) {\n return result;\n }\n\n const props = await result.props;\n const i18nConfig = getI18nConfig();\n const defaultLocale = i18nConfig.getDefaultLocale();\n const locale = context.locale;\n const translations =\n locale === defaultLocale ? {} : await getTranslationsSnapshot(locale);\n\n return {\n ...result,\n props: {\n ...props,\n locale,\n translations,\n },\n };\n };\n}\n\nexport type WithGTStaticPropsFunction = typeof withGTStaticProps;\n"],"mappings":";;;;;;;;;AAsBA,SAAgB,kBAKd,gBAC2D;AAC3D,QAAO,OAAO,YAAoD;AAChE,MAAI,CAAC,QAAQ,OACX,OAAM,IAAI,MAAM,oCAAoC;EAGtD,MAAM,SAAS,iBACX,MAAM,eAAe,QAAQ,GAC7B,EAAE,OAAO,EAAE,EAAW;AAE1B,MAAI,EAAE,WAAW,QACf,QAAO;EAGT,MAAM,QAAQ,MAAM,OAAO;EAE3B,MAAM,gBADa,eACa,CAAC,kBAAkB;EACnD,MAAM,SAAS,QAAQ;EACvB,MAAM,eACJ,WAAW,gBAAgB,EAAE,GAAG,MAAM,wBAAwB,OAAO;AAEvE,SAAO;GACL,GAAG;GACH,OAAO;IACL,GAAG;IACH;IACA;IACD;GACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"client-boundary.d.ts","sourceRoot":"","sources":["../../src/utils/client-boundary.tsx"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,IAAI,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACnE,OAAO,EAAE,cAAc,IAAI,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAGnE,OAAO,EAAc,KAAK,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAkBlE;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,qBAAqB,2CAS7D"}
1
+ {"version":3,"file":"client-boundary.d.ts","sourceRoot":"","sources":["../../src/utils/client-boundary.tsx"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,IAAI,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACnE,OAAO,EAAE,cAAc,IAAI,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAGnE,OAAO,EAAc,KAAK,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAsBlE;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,qBAAqB,2CAS7D"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  require("../_virtual/_rolldown/runtime.js");
4
4
  const require_utils_cookies = require("./cookies.js");
5
+ const require_utils_pathRegex = require("./pathRegex.js");
5
6
  const require_setup_initGT_client = require("../setup/initGT.client.js");
6
7
  let gt_i18n_internal = require("gt-i18n/internal");
7
8
  let gt_react = require("gt-react");
@@ -9,6 +10,7 @@ let react = require("react");
9
10
  let react_jsx_runtime = require("react/jsx-runtime");
10
11
  let next_navigation_js = require("next/navigation.js");
11
12
  //#region src/utils/client-boundary.tsx
13
+ const pathRegex = require_utils_pathRegex.compilePathRegex(process.env._GENERALTRANSLATION_PATH_REGEX);
12
14
  /**
13
15
  * Only need to initalize client. We know server was already
14
16
  * inialaized by index.rsc.ts. We do not know yet if client
@@ -43,7 +45,7 @@ function usePathCheck({ reloadServer, locale, referrerLocaleCookieName = require
43
45
  document.cookie = `${referrerLocaleCookieName}=${i18nConfig.resolveAliasLocale(locale)};path=/`;
44
46
  const locales = i18nConfig.getLocales();
45
47
  const defaultLocale = i18nConfig.getDefaultLocale();
46
- if (document.cookie.split("; ").find((row) => row.startsWith(`${localeRoutingEnabledCookieName}=`))?.split("=")[1] === "true") {
48
+ if ((0, gt_i18n_internal.getCookieValue)(document.cookie, localeRoutingEnabledCookieName) === "true" && require_utils_pathRegex.pathnameMatchesRegex(pathname, pathRegex)) {
47
49
  const extractedLocale = extractLocale(pathname, i18nConfig) || defaultLocale;
48
50
  let pathLocale = i18nConfig.determineLocale([i18nConfig.isGTServicesEnabled() ? i18nConfig.standardizeLocale(extractedLocale) : extractedLocale, defaultLocale], locales);
49
51
  if (pathLocale) pathLocale = i18nConfig.resolveAliasLocale(pathLocale);
@@ -1 +1 @@
1
- {"version":3,"file":"client-boundary.js","names":["GTProvider","defaultReferrerLocaleCookieName","defaultLocaleRoutingEnabledCookieName"],"sources":["../../src/utils/client-boundary.tsx"],"sourcesContent":["'use client';\n\n/**\n * This is a small boundary for RSC consumption of client components\n * Cannot be consumed through gt-react/index.rsc as deciding btwn\n * gt-react/index.server and gt-react/index.client can only happen\n * here. This matters for GTProvider, but not for LocaleSelector.\n * This pattern is just good to follow for carrying over different\n * behaviors between client and server from gt-react.\n */\n\nexport { LocaleSelector as Client_LocaleSelector } from 'gt-react';\nexport { RegionSelector as Client_RegionSelector } from 'gt-react';\n\nimport { getI18nConfig, I18nConfig } from 'gt-i18n/internal';\nimport { GTProvider, type SharedGTProviderProps } from 'gt-react';\nimport { usePathname, useRouter } from 'next/navigation';\nimport { useCallback, useEffect } from 'react';\nimport { initializeGTClient } from '../setup/initGT.client';\nimport {\n defaultLocaleRoutingEnabledCookieName,\n defaultReferrerLocaleCookieName,\n} from './cookies';\n\n/**\n * Only need to initalize client. We know server was already\n * inialaized by index.rsc.ts. We do not know yet if client\n * has been initialized by index.client.ts.\n */\nif (typeof window !== 'undefined') {\n initializeGTClient();\n}\n\n/**\n * Small wrapper to embed nextjs app router behavior\n */\nexport function Client_GTProvider(props: SharedGTProviderProps) {\n const router = useRouter();\n const reload = useCallback(() => {\n // Reload server components\n router.refresh();\n }, [router]);\n // TODO: when routing is enabled, validate the path matches the locale\n usePathCheck({ reloadServer: reload, locale: props.locale });\n return <GTProvider {...props} _reload={reload} />;\n}\n\n/**\n * Reloads the server components if\n * TODO: optimize this hook\n */\nfunction usePathCheck({\n reloadServer,\n locale,\n referrerLocaleCookieName = defaultReferrerLocaleCookieName,\n localeRoutingEnabledCookieName = defaultLocaleRoutingEnabledCookieName,\n}: {\n reloadServer: () => void;\n locale: string;\n referrerLocaleCookieName?: string;\n localeRoutingEnabledCookieName?: string;\n}) {\n const pathname = usePathname();\n\n useEffect(() => {\n // Track the referrer locale for middleware\n const i18nConfig = getI18nConfig();\n document.cookie = `${referrerLocaleCookieName}=${i18nConfig.resolveAliasLocale(locale)};path=/`;\n\n // Reload the server components if the pathname changes\n const locales = i18nConfig.getLocales();\n const defaultLocale = i18nConfig.getDefaultLocale();\n const middlewareEnabled =\n document.cookie\n .split('; ')\n .find((row) => row.startsWith(`${localeRoutingEnabledCookieName}=`))\n ?.split('=')[1] === 'true';\n if (middlewareEnabled) {\n // Extract locale from pathname\n const extractedLocale =\n extractLocale(pathname, i18nConfig) || defaultLocale;\n let pathLocale = i18nConfig.determineLocale(\n [\n i18nConfig.isGTServicesEnabled()\n ? i18nConfig.standardizeLocale(extractedLocale)\n : extractedLocale,\n defaultLocale,\n ],\n locales\n );\n if (pathLocale) {\n pathLocale = i18nConfig.resolveAliasLocale(pathLocale);\n }\n\n if (pathLocale && locales.includes(pathLocale) && pathLocale !== locale) {\n // clear cookie (avoids infinite loop when there is no middleware)\n document.cookie = `${localeRoutingEnabledCookieName}=;path=/`;\n\n // reload page\n reloadServer();\n }\n }\n }, [\n pathname,\n locale,\n referrerLocaleCookieName,\n localeRoutingEnabledCookieName,\n reloadServer,\n ]);\n}\n\nfunction extractLocale(\n pathname: string,\n i18nConfig: I18nConfig\n): string | null {\n const matches = pathname.match(/^\\/([^/]+)(?:\\/|$)/);\n return matches ? i18nConfig.resolveAliasLocale(matches[1]) : null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA6BA,IAAI,OAAO,WAAW,YACpB,6BAAA,oBAAoB;;;;AAMtB,SAAgB,kBAAkB,OAA8B;CAC9D,MAAM,UAAA,GAAA,mBAAA,YAAoB;CAC1B,MAAM,UAAA,GAAA,MAAA,mBAA2B;AAE/B,SAAO,SAAS;IACf,CAAC,OAAO,CAAC;AAEZ,cAAa;EAAE,cAAc;EAAQ,QAAQ,MAAM;EAAQ,CAAC;AAC5D,QAAO,iBAAA,GAAA,kBAAA,KAACA,SAAAA,YAAD;EAAY,GAAI;EAAO,SAAS;EAAU,CAAA;;;;;;AAOnD,SAAS,aAAa,EACpB,cACA,QACA,2BAA2BC,sBAAAA,iCAC3B,iCAAiCC,sBAAAA,yCAMhC;CACD,MAAM,YAAA,GAAA,mBAAA,cAAwB;AAE9B,EAAA,GAAA,MAAA,iBAAgB;EAEd,MAAM,cAAA,GAAA,iBAAA,gBAA4B;AAClC,WAAS,SAAS,GAAG,yBAAyB,GAAG,WAAW,mBAAmB,OAAO,CAAC;EAGvF,MAAM,UAAU,WAAW,YAAY;EACvC,MAAM,gBAAgB,WAAW,kBAAkB;AAMnD,MAJE,SAAS,OACN,MAAM,KAAK,CACX,MAAM,QAAQ,IAAI,WAAW,GAAG,+BAA+B,GAAG,CAAC,EAClE,MAAM,IAAI,CAAC,OAAO,QACD;GAErB,MAAM,kBACJ,cAAc,UAAU,WAAW,IAAI;GACzC,IAAI,aAAa,WAAW,gBAC1B,CACE,WAAW,qBAAqB,GAC5B,WAAW,kBAAkB,gBAAgB,GAC7C,iBACJ,cACD,EACD,QACD;AACD,OAAI,WACF,cAAa,WAAW,mBAAmB,WAAW;AAGxD,OAAI,cAAc,QAAQ,SAAS,WAAW,IAAI,eAAe,QAAQ;AAEvE,aAAS,SAAS,GAAG,+BAA+B;AAGpD,kBAAc;;;IAGjB;EACD;EACA;EACA;EACA;EACA;EACD,CAAC;;AAGJ,SAAS,cACP,UACA,YACe;CACf,MAAM,UAAU,SAAS,MAAM,qBAAqB;AACpD,QAAO,UAAU,WAAW,mBAAmB,QAAQ,GAAG,GAAG"}
1
+ {"version":3,"file":"client-boundary.js","names":["compilePathRegex","GTProvider","defaultReferrerLocaleCookieName","defaultLocaleRoutingEnabledCookieName","pathnameMatchesRegex"],"sources":["../../src/utils/client-boundary.tsx"],"sourcesContent":["'use client';\n\n/**\n * This is a small boundary for RSC consumption of client components\n * Cannot be consumed through gt-react/index.rsc as deciding btwn\n * gt-react/index.server and gt-react/index.client can only happen\n * here. This matters for GTProvider, but not for LocaleSelector.\n * This pattern is just good to follow for carrying over different\n * behaviors between client and server from gt-react.\n */\n\nexport { LocaleSelector as Client_LocaleSelector } from 'gt-react';\nexport { RegionSelector as Client_RegionSelector } from 'gt-react';\n\nimport { getCookieValue, getI18nConfig, I18nConfig } from 'gt-i18n/internal';\nimport { GTProvider, type SharedGTProviderProps } from 'gt-react';\nimport { usePathname, useRouter } from 'next/navigation';\nimport { useCallback, useEffect } from 'react';\nimport { initializeGTClient } from '../setup/initGT.client';\nimport {\n defaultLocaleRoutingEnabledCookieName,\n defaultReferrerLocaleCookieName,\n} from './cookies';\nimport { compilePathRegex, pathnameMatchesRegex } from './pathRegex';\n\n// withGTConfig exposes this build-time value to both middleware and client code.\nconst pathRegex = compilePathRegex(process.env._GENERALTRANSLATION_PATH_REGEX);\n\n/**\n * Only need to initalize client. We know server was already\n * inialaized by index.rsc.ts. We do not know yet if client\n * has been initialized by index.client.ts.\n */\nif (typeof window !== 'undefined') {\n initializeGTClient();\n}\n\n/**\n * Small wrapper to embed nextjs app router behavior\n */\nexport function Client_GTProvider(props: SharedGTProviderProps) {\n const router = useRouter();\n const reload = useCallback(() => {\n // Reload server components\n router.refresh();\n }, [router]);\n // TODO: when routing is enabled, validate the path matches the locale\n usePathCheck({ reloadServer: reload, locale: props.locale });\n return <GTProvider {...props} _reload={reload} />;\n}\n\n/**\n * Reloads the server components if\n * TODO: optimize this hook\n */\nfunction usePathCheck({\n reloadServer,\n locale,\n referrerLocaleCookieName = defaultReferrerLocaleCookieName,\n localeRoutingEnabledCookieName = defaultLocaleRoutingEnabledCookieName,\n}: {\n reloadServer: () => void;\n locale: string;\n referrerLocaleCookieName?: string;\n localeRoutingEnabledCookieName?: string;\n}) {\n const pathname = usePathname();\n\n useEffect(() => {\n // Track the referrer locale for middleware\n const i18nConfig = getI18nConfig();\n document.cookie = `${referrerLocaleCookieName}=${i18nConfig.resolveAliasLocale(locale)};path=/`;\n\n // Reload the server components if the pathname changes\n const locales = i18nConfig.getLocales();\n const defaultLocale = i18nConfig.getDefaultLocale();\n const middlewareEnabled =\n getCookieValue(document.cookie, localeRoutingEnabledCookieName) ===\n 'true';\n if (middlewareEnabled && pathnameMatchesRegex(pathname, pathRegex)) {\n // Extract locale from pathname\n const extractedLocale =\n extractLocale(pathname, i18nConfig) || defaultLocale;\n let pathLocale = i18nConfig.determineLocale(\n [\n i18nConfig.isGTServicesEnabled()\n ? i18nConfig.standardizeLocale(extractedLocale)\n : extractedLocale,\n defaultLocale,\n ],\n locales\n );\n if (pathLocale) {\n pathLocale = i18nConfig.resolveAliasLocale(pathLocale);\n }\n\n if (pathLocale && locales.includes(pathLocale) && pathLocale !== locale) {\n // clear cookie (avoids infinite loop when there is no middleware)\n document.cookie = `${localeRoutingEnabledCookieName}=;path=/`;\n\n // reload page\n reloadServer();\n }\n }\n }, [\n pathname,\n locale,\n referrerLocaleCookieName,\n localeRoutingEnabledCookieName,\n reloadServer,\n ]);\n}\n\nfunction extractLocale(\n pathname: string,\n i18nConfig: I18nConfig\n): string | null {\n const matches = pathname.match(/^\\/([^/]+)(?:\\/|$)/);\n return matches ? i18nConfig.resolveAliasLocale(matches[1]) : null;\n}\n"],"mappings":";;;;;;;;;;;;AA0BA,MAAM,YAAYA,wBAAAA,iBAAiB,QAAQ,IAAI,+BAA+B;;;;;;AAO9E,IAAI,OAAO,WAAW,YACpB,6BAAA,oBAAoB;;;;AAMtB,SAAgB,kBAAkB,OAA8B;CAC9D,MAAM,UAAA,GAAA,mBAAA,YAAoB;CAC1B,MAAM,UAAA,GAAA,MAAA,mBAA2B;AAE/B,SAAO,SAAS;IACf,CAAC,OAAO,CAAC;AAEZ,cAAa;EAAE,cAAc;EAAQ,QAAQ,MAAM;EAAQ,CAAC;AAC5D,QAAO,iBAAA,GAAA,kBAAA,KAACC,SAAAA,YAAD;EAAY,GAAI;EAAO,SAAS;EAAU,CAAA;;;;;;AAOnD,SAAS,aAAa,EACpB,cACA,QACA,2BAA2BC,sBAAAA,iCAC3B,iCAAiCC,sBAAAA,yCAMhC;CACD,MAAM,YAAA,GAAA,mBAAA,cAAwB;AAE9B,EAAA,GAAA,MAAA,iBAAgB;EAEd,MAAM,cAAA,GAAA,iBAAA,gBAA4B;AAClC,WAAS,SAAS,GAAG,yBAAyB,GAAG,WAAW,mBAAmB,OAAO,CAAC;EAGvF,MAAM,UAAU,WAAW,YAAY;EACvC,MAAM,gBAAgB,WAAW,kBAAkB;AAInD,OAAA,GAAA,iBAAA,gBAFiB,SAAS,QAAQ,+BAA+B,KAC/D,UACuBC,wBAAAA,qBAAqB,UAAU,UAAU,EAAE;GAElE,MAAM,kBACJ,cAAc,UAAU,WAAW,IAAI;GACzC,IAAI,aAAa,WAAW,gBAC1B,CACE,WAAW,qBAAqB,GAC5B,WAAW,kBAAkB,gBAAgB,GAC7C,iBACJ,cACD,EACD,QACD;AACD,OAAI,WACF,cAAa,WAAW,mBAAmB,WAAW;AAGxD,OAAI,cAAc,QAAQ,SAAS,WAAW,IAAI,eAAe,QAAQ;AAEvE,aAAS,SAAS,GAAG,+BAA+B;AAGpD,kBAAc;;;IAGjB;EACD;EACA;EACA;EACA;EACA;EACD,CAAC;;AAGJ,SAAS,cACP,UACA,YACe;CACf,MAAM,UAAU,SAAS,MAAM,qBAAqB;AACpD,QAAO,UAAU,WAAW,mBAAmB,QAAQ,GAAG,GAAG"}
@@ -1,12 +1,14 @@
1
1
  "use client";
2
2
  import { defaultLocaleRoutingEnabledCookieName, defaultReferrerLocaleCookieName } from "./cookies.mjs";
3
+ import { compilePathRegex, pathnameMatchesRegex } from "./pathRegex.mjs";
3
4
  import { initializeGTClient } from "../setup/initGT.client.mjs";
4
- import { getI18nConfig } from "gt-i18n/internal";
5
+ import { getCookieValue, getI18nConfig } from "gt-i18n/internal";
5
6
  import { GTProvider, LocaleSelector as Client_LocaleSelector, RegionSelector as Client_RegionSelector } from "gt-react";
6
7
  import { useCallback, useEffect } from "react";
7
8
  import { jsx } from "react/jsx-runtime";
8
9
  import { usePathname, useRouter } from "next/navigation.js";
9
10
  //#region src/utils/client-boundary.tsx
11
+ const pathRegex = compilePathRegex(process.env._GENERALTRANSLATION_PATH_REGEX);
10
12
  /**
11
13
  * Only need to initalize client. We know server was already
12
14
  * inialaized by index.rsc.ts. We do not know yet if client
@@ -41,7 +43,7 @@ function usePathCheck({ reloadServer, locale, referrerLocaleCookieName = default
41
43
  document.cookie = `${referrerLocaleCookieName}=${i18nConfig.resolveAliasLocale(locale)};path=/`;
42
44
  const locales = i18nConfig.getLocales();
43
45
  const defaultLocale = i18nConfig.getDefaultLocale();
44
- if (document.cookie.split("; ").find((row) => row.startsWith(`${localeRoutingEnabledCookieName}=`))?.split("=")[1] === "true") {
46
+ if (getCookieValue(document.cookie, localeRoutingEnabledCookieName) === "true" && pathnameMatchesRegex(pathname, pathRegex)) {
45
47
  const extractedLocale = extractLocale(pathname, i18nConfig) || defaultLocale;
46
48
  let pathLocale = i18nConfig.determineLocale([i18nConfig.isGTServicesEnabled() ? i18nConfig.standardizeLocale(extractedLocale) : extractedLocale, defaultLocale], locales);
47
49
  if (pathLocale) pathLocale = i18nConfig.resolveAliasLocale(pathLocale);
@@ -1 +1 @@
1
- {"version":3,"file":"client-boundary.mjs","names":[],"sources":["../../src/utils/client-boundary.tsx"],"sourcesContent":["'use client';\n\n/**\n * This is a small boundary for RSC consumption of client components\n * Cannot be consumed through gt-react/index.rsc as deciding btwn\n * gt-react/index.server and gt-react/index.client can only happen\n * here. This matters for GTProvider, but not for LocaleSelector.\n * This pattern is just good to follow for carrying over different\n * behaviors between client and server from gt-react.\n */\n\nexport { LocaleSelector as Client_LocaleSelector } from 'gt-react';\nexport { RegionSelector as Client_RegionSelector } from 'gt-react';\n\nimport { getI18nConfig, I18nConfig } from 'gt-i18n/internal';\nimport { GTProvider, type SharedGTProviderProps } from 'gt-react';\nimport { usePathname, useRouter } from 'next/navigation';\nimport { useCallback, useEffect } from 'react';\nimport { initializeGTClient } from '../setup/initGT.client';\nimport {\n defaultLocaleRoutingEnabledCookieName,\n defaultReferrerLocaleCookieName,\n} from './cookies';\n\n/**\n * Only need to initalize client. We know server was already\n * inialaized by index.rsc.ts. We do not know yet if client\n * has been initialized by index.client.ts.\n */\nif (typeof window !== 'undefined') {\n initializeGTClient();\n}\n\n/**\n * Small wrapper to embed nextjs app router behavior\n */\nexport function Client_GTProvider(props: SharedGTProviderProps) {\n const router = useRouter();\n const reload = useCallback(() => {\n // Reload server components\n router.refresh();\n }, [router]);\n // TODO: when routing is enabled, validate the path matches the locale\n usePathCheck({ reloadServer: reload, locale: props.locale });\n return <GTProvider {...props} _reload={reload} />;\n}\n\n/**\n * Reloads the server components if\n * TODO: optimize this hook\n */\nfunction usePathCheck({\n reloadServer,\n locale,\n referrerLocaleCookieName = defaultReferrerLocaleCookieName,\n localeRoutingEnabledCookieName = defaultLocaleRoutingEnabledCookieName,\n}: {\n reloadServer: () => void;\n locale: string;\n referrerLocaleCookieName?: string;\n localeRoutingEnabledCookieName?: string;\n}) {\n const pathname = usePathname();\n\n useEffect(() => {\n // Track the referrer locale for middleware\n const i18nConfig = getI18nConfig();\n document.cookie = `${referrerLocaleCookieName}=${i18nConfig.resolveAliasLocale(locale)};path=/`;\n\n // Reload the server components if the pathname changes\n const locales = i18nConfig.getLocales();\n const defaultLocale = i18nConfig.getDefaultLocale();\n const middlewareEnabled =\n document.cookie\n .split('; ')\n .find((row) => row.startsWith(`${localeRoutingEnabledCookieName}=`))\n ?.split('=')[1] === 'true';\n if (middlewareEnabled) {\n // Extract locale from pathname\n const extractedLocale =\n extractLocale(pathname, i18nConfig) || defaultLocale;\n let pathLocale = i18nConfig.determineLocale(\n [\n i18nConfig.isGTServicesEnabled()\n ? i18nConfig.standardizeLocale(extractedLocale)\n : extractedLocale,\n defaultLocale,\n ],\n locales\n );\n if (pathLocale) {\n pathLocale = i18nConfig.resolveAliasLocale(pathLocale);\n }\n\n if (pathLocale && locales.includes(pathLocale) && pathLocale !== locale) {\n // clear cookie (avoids infinite loop when there is no middleware)\n document.cookie = `${localeRoutingEnabledCookieName}=;path=/`;\n\n // reload page\n reloadServer();\n }\n }\n }, [\n pathname,\n locale,\n referrerLocaleCookieName,\n localeRoutingEnabledCookieName,\n reloadServer,\n ]);\n}\n\nfunction extractLocale(\n pathname: string,\n i18nConfig: I18nConfig\n): string | null {\n const matches = pathname.match(/^\\/([^/]+)(?:\\/|$)/);\n return matches ? i18nConfig.resolveAliasLocale(matches[1]) : null;\n}\n"],"mappings":";;;;;;;;;;;;;;AA6BA,IAAI,OAAO,WAAW,YACpB,qBAAoB;;;;AAMtB,SAAgB,kBAAkB,OAA8B;CAC9D,MAAM,SAAS,WAAW;CAC1B,MAAM,SAAS,kBAAkB;AAE/B,SAAO,SAAS;IACf,CAAC,OAAO,CAAC;AAEZ,cAAa;EAAE,cAAc;EAAQ,QAAQ,MAAM;EAAQ,CAAC;AAC5D,QAAO,oBAAC,YAAD;EAAY,GAAI;EAAO,SAAS;EAAU,CAAA;;;;;;AAOnD,SAAS,aAAa,EACpB,cACA,QACA,2BAA2B,iCAC3B,iCAAiC,yCAMhC;CACD,MAAM,WAAW,aAAa;AAE9B,iBAAgB;EAEd,MAAM,aAAa,eAAe;AAClC,WAAS,SAAS,GAAG,yBAAyB,GAAG,WAAW,mBAAmB,OAAO,CAAC;EAGvF,MAAM,UAAU,WAAW,YAAY;EACvC,MAAM,gBAAgB,WAAW,kBAAkB;AAMnD,MAJE,SAAS,OACN,MAAM,KAAK,CACX,MAAM,QAAQ,IAAI,WAAW,GAAG,+BAA+B,GAAG,CAAC,EAClE,MAAM,IAAI,CAAC,OAAO,QACD;GAErB,MAAM,kBACJ,cAAc,UAAU,WAAW,IAAI;GACzC,IAAI,aAAa,WAAW,gBAC1B,CACE,WAAW,qBAAqB,GAC5B,WAAW,kBAAkB,gBAAgB,GAC7C,iBACJ,cACD,EACD,QACD;AACD,OAAI,WACF,cAAa,WAAW,mBAAmB,WAAW;AAGxD,OAAI,cAAc,QAAQ,SAAS,WAAW,IAAI,eAAe,QAAQ;AAEvE,aAAS,SAAS,GAAG,+BAA+B;AAGpD,kBAAc;;;IAGjB;EACD;EACA;EACA;EACA;EACA;EACD,CAAC;;AAGJ,SAAS,cACP,UACA,YACe;CACf,MAAM,UAAU,SAAS,MAAM,qBAAqB;AACpD,QAAO,UAAU,WAAW,mBAAmB,QAAQ,GAAG,GAAG"}
1
+ {"version":3,"file":"client-boundary.mjs","names":[],"sources":["../../src/utils/client-boundary.tsx"],"sourcesContent":["'use client';\n\n/**\n * This is a small boundary for RSC consumption of client components\n * Cannot be consumed through gt-react/index.rsc as deciding btwn\n * gt-react/index.server and gt-react/index.client can only happen\n * here. This matters for GTProvider, but not for LocaleSelector.\n * This pattern is just good to follow for carrying over different\n * behaviors between client and server from gt-react.\n */\n\nexport { LocaleSelector as Client_LocaleSelector } from 'gt-react';\nexport { RegionSelector as Client_RegionSelector } from 'gt-react';\n\nimport { getCookieValue, getI18nConfig, I18nConfig } from 'gt-i18n/internal';\nimport { GTProvider, type SharedGTProviderProps } from 'gt-react';\nimport { usePathname, useRouter } from 'next/navigation';\nimport { useCallback, useEffect } from 'react';\nimport { initializeGTClient } from '../setup/initGT.client';\nimport {\n defaultLocaleRoutingEnabledCookieName,\n defaultReferrerLocaleCookieName,\n} from './cookies';\nimport { compilePathRegex, pathnameMatchesRegex } from './pathRegex';\n\n// withGTConfig exposes this build-time value to both middleware and client code.\nconst pathRegex = compilePathRegex(process.env._GENERALTRANSLATION_PATH_REGEX);\n\n/**\n * Only need to initalize client. We know server was already\n * inialaized by index.rsc.ts. We do not know yet if client\n * has been initialized by index.client.ts.\n */\nif (typeof window !== 'undefined') {\n initializeGTClient();\n}\n\n/**\n * Small wrapper to embed nextjs app router behavior\n */\nexport function Client_GTProvider(props: SharedGTProviderProps) {\n const router = useRouter();\n const reload = useCallback(() => {\n // Reload server components\n router.refresh();\n }, [router]);\n // TODO: when routing is enabled, validate the path matches the locale\n usePathCheck({ reloadServer: reload, locale: props.locale });\n return <GTProvider {...props} _reload={reload} />;\n}\n\n/**\n * Reloads the server components if\n * TODO: optimize this hook\n */\nfunction usePathCheck({\n reloadServer,\n locale,\n referrerLocaleCookieName = defaultReferrerLocaleCookieName,\n localeRoutingEnabledCookieName = defaultLocaleRoutingEnabledCookieName,\n}: {\n reloadServer: () => void;\n locale: string;\n referrerLocaleCookieName?: string;\n localeRoutingEnabledCookieName?: string;\n}) {\n const pathname = usePathname();\n\n useEffect(() => {\n // Track the referrer locale for middleware\n const i18nConfig = getI18nConfig();\n document.cookie = `${referrerLocaleCookieName}=${i18nConfig.resolveAliasLocale(locale)};path=/`;\n\n // Reload the server components if the pathname changes\n const locales = i18nConfig.getLocales();\n const defaultLocale = i18nConfig.getDefaultLocale();\n const middlewareEnabled =\n getCookieValue(document.cookie, localeRoutingEnabledCookieName) ===\n 'true';\n if (middlewareEnabled && pathnameMatchesRegex(pathname, pathRegex)) {\n // Extract locale from pathname\n const extractedLocale =\n extractLocale(pathname, i18nConfig) || defaultLocale;\n let pathLocale = i18nConfig.determineLocale(\n [\n i18nConfig.isGTServicesEnabled()\n ? i18nConfig.standardizeLocale(extractedLocale)\n : extractedLocale,\n defaultLocale,\n ],\n locales\n );\n if (pathLocale) {\n pathLocale = i18nConfig.resolveAliasLocale(pathLocale);\n }\n\n if (pathLocale && locales.includes(pathLocale) && pathLocale !== locale) {\n // clear cookie (avoids infinite loop when there is no middleware)\n document.cookie = `${localeRoutingEnabledCookieName}=;path=/`;\n\n // reload page\n reloadServer();\n }\n }\n }, [\n pathname,\n locale,\n referrerLocaleCookieName,\n localeRoutingEnabledCookieName,\n reloadServer,\n ]);\n}\n\nfunction extractLocale(\n pathname: string,\n i18nConfig: I18nConfig\n): string | null {\n const matches = pathname.match(/^\\/([^/]+)(?:\\/|$)/);\n return matches ? i18nConfig.resolveAliasLocale(matches[1]) : null;\n}\n"],"mappings":";;;;;;;;;;AA0BA,MAAM,YAAY,iBAAiB,QAAQ,IAAI,+BAA+B;;;;;;AAO9E,IAAI,OAAO,WAAW,YACpB,qBAAoB;;;;AAMtB,SAAgB,kBAAkB,OAA8B;CAC9D,MAAM,SAAS,WAAW;CAC1B,MAAM,SAAS,kBAAkB;AAE/B,SAAO,SAAS;IACf,CAAC,OAAO,CAAC;AAEZ,cAAa;EAAE,cAAc;EAAQ,QAAQ,MAAM;EAAQ,CAAC;AAC5D,QAAO,oBAAC,YAAD;EAAY,GAAI;EAAO,SAAS;EAAU,CAAA;;;;;;AAOnD,SAAS,aAAa,EACpB,cACA,QACA,2BAA2B,iCAC3B,iCAAiC,yCAMhC;CACD,MAAM,WAAW,aAAa;AAE9B,iBAAgB;EAEd,MAAM,aAAa,eAAe;AAClC,WAAS,SAAS,GAAG,yBAAyB,GAAG,WAAW,mBAAmB,OAAO,CAAC;EAGvF,MAAM,UAAU,WAAW,YAAY;EACvC,MAAM,gBAAgB,WAAW,kBAAkB;AAInD,MAFE,eAAe,SAAS,QAAQ,+BAA+B,KAC/D,UACuB,qBAAqB,UAAU,UAAU,EAAE;GAElE,MAAM,kBACJ,cAAc,UAAU,WAAW,IAAI;GACzC,IAAI,aAAa,WAAW,gBAC1B,CACE,WAAW,qBAAqB,GAC5B,WAAW,kBAAkB,gBAAgB,GAC7C,iBACJ,cACD,EACD,QACD;AACD,OAAI,WACF,cAAa,WAAW,mBAAmB,WAAW;AAGxD,OAAI,cAAc,QAAQ,SAAS,WAAW,IAAI,eAAe,QAAQ;AAEvE,aAAS,SAAS,GAAG,+BAA+B;AAGpD,kBAAc;;;IAGjB;EACD;EACA;EACA;EACA;EACA;EACD,CAAC;;AAGJ,SAAS,cACP,UACA,YACe;CACf,MAAM,UAAU,SAAS,MAAM,qBAAqB;AACpD,QAAO,UAAU,WAAW,mBAAmB,QAAQ,GAAG,GAAG"}
@@ -0,0 +1,3 @@
1
+ export declare function compilePathRegex(pathRegex?: string): RegExp | undefined;
2
+ export declare function pathnameMatchesRegex(pathname: string, pathRegex?: RegExp): boolean;
3
+ //# sourceMappingURL=pathRegex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pathRegex.d.ts","sourceRoot":"","sources":["../../src/utils/pathRegex.ts"],"names":[],"mappings":"AAEA,wBAAgB,gBAAgB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAQvE;AAED,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAET"}
@@ -0,0 +1,19 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_errors_createErrors = require("../errors/createErrors.js");
3
+ //#region src/utils/pathRegex.ts
4
+ function compilePathRegex(pathRegex) {
5
+ if (pathRegex === void 0) return void 0;
6
+ try {
7
+ return new RegExp(pathRegex);
8
+ } catch (error) {
9
+ throw new Error(require_errors_createErrors.createInvalidPathRegexError(pathRegex, error));
10
+ }
11
+ }
12
+ function pathnameMatchesRegex(pathname, pathRegex) {
13
+ return pathRegex?.test(pathname) ?? true;
14
+ }
15
+ //#endregion
16
+ exports.compilePathRegex = compilePathRegex;
17
+ exports.pathnameMatchesRegex = pathnameMatchesRegex;
18
+
19
+ //# sourceMappingURL=pathRegex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pathRegex.js","names":["createInvalidPathRegexError"],"sources":["../../src/utils/pathRegex.ts"],"sourcesContent":["import { createInvalidPathRegexError } from '../errors/createErrors';\n\nexport function compilePathRegex(pathRegex?: string): RegExp | undefined {\n if (pathRegex === undefined) return undefined;\n\n try {\n return new RegExp(pathRegex);\n } catch (error) {\n throw new Error(createInvalidPathRegexError(pathRegex, error));\n }\n}\n\nexport function pathnameMatchesRegex(\n pathname: string,\n pathRegex?: RegExp\n): boolean {\n return pathRegex?.test(pathname) ?? true;\n}\n"],"mappings":";;;AAEA,SAAgB,iBAAiB,WAAwC;AACvE,KAAI,cAAc,KAAA,EAAW,QAAO,KAAA;AAEpC,KAAI;AACF,SAAO,IAAI,OAAO,UAAU;UACrB,OAAO;AACd,QAAM,IAAI,MAAMA,4BAAAA,4BAA4B,WAAW,MAAM,CAAC;;;AAIlE,SAAgB,qBACd,UACA,WACS;AACT,QAAO,WAAW,KAAK,SAAS,IAAI"}
@@ -0,0 +1,17 @@
1
+ import { createInvalidPathRegexError } from "../errors/createErrors.mjs";
2
+ //#region src/utils/pathRegex.ts
3
+ function compilePathRegex(pathRegex) {
4
+ if (pathRegex === void 0) return void 0;
5
+ try {
6
+ return new RegExp(pathRegex);
7
+ } catch (error) {
8
+ throw new Error(createInvalidPathRegexError(pathRegex, error));
9
+ }
10
+ }
11
+ function pathnameMatchesRegex(pathname, pathRegex) {
12
+ return pathRegex?.test(pathname) ?? true;
13
+ }
14
+ //#endregion
15
+ export { compilePathRegex, pathnameMatchesRegex };
16
+
17
+ //# sourceMappingURL=pathRegex.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pathRegex.mjs","names":[],"sources":["../../src/utils/pathRegex.ts"],"sourcesContent":["import { createInvalidPathRegexError } from '../errors/createErrors';\n\nexport function compilePathRegex(pathRegex?: string): RegExp | undefined {\n if (pathRegex === undefined) return undefined;\n\n try {\n return new RegExp(pathRegex);\n } catch (error) {\n throw new Error(createInvalidPathRegexError(pathRegex, error));\n }\n}\n\nexport function pathnameMatchesRegex(\n pathname: string,\n pathRegex?: RegExp\n): boolean {\n return pathRegex?.test(pathname) ?? true;\n}\n"],"mappings":";;AAEA,SAAgB,iBAAiB,WAAwC;AACvE,KAAI,cAAc,KAAA,EAAW,QAAO,KAAA;AAEpC,KAAI;AACF,SAAO,IAAI,OAAO,UAAU;UACrB,OAAO;AACd,QAAM,IAAI,MAAM,4BAA4B,WAAW,MAAM,CAAC;;;AAIlE,SAAgB,qBACd,UACA,WACS;AACT,QAAO,WAAW,KAAK,SAAS,IAAI"}
package/package.json CHANGED
@@ -1,13 +1,19 @@
1
1
  {
2
2
  "name": "gt-next",
3
- "version": "11.0.2",
3
+ "version": "11.0.4",
4
4
  "description": "A Next.js library for automatic internationalization.",
5
5
  "main": "dist/index.server.js",
6
6
  "peerDependencies": {
7
+ "@generaltranslation/compiler": "^1.3.26",
7
8
  "next": ">=13.0.0 <15.2.1 || >15.2.2",
8
9
  "react": ">=16.8.0 <20.0.0",
9
10
  "react-dom": ">=16.8.0 <20.0.0"
10
11
  },
12
+ "peerDependenciesMeta": {
13
+ "@generaltranslation/compiler": {
14
+ "optional": true
15
+ }
16
+ },
11
17
  "files": [
12
18
  "dist",
13
19
  "CHANGELOG.md"
@@ -23,12 +29,10 @@
23
29
  ],
24
30
  "dependencies": {
25
31
  "@generaltranslation/format": "0.1.2",
26
- "@generaltranslation/compiler": "1.3.25",
27
- "@generaltranslation/supported-locales": "2.1.3",
28
- "gt-react": "11.0.2",
29
- "@generaltranslation/react-core": "11.0.2",
30
- "gt-i18n": "1.0.1",
31
- "generaltranslation": "9.0.0"
32
+ "@generaltranslation/react-core": "11.0.4",
33
+ "generaltranslation": "9.0.0",
34
+ "gt-react": "11.0.4",
35
+ "gt-i18n": "1.0.2"
32
36
  },
33
37
  "repository": {
34
38
  "type": "git",