@vocab/react 1.1.16-rollup-plugin-20251205045501 → 1.1.17-isolate-rolldown-runtime-20251217033548

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -6,12 +6,16 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
15
19
  }
16
20
  return to;
17
21
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["React"],"sources":["../src/components.tsx"],"sourcesContent":["import type {\n TranslationFile,\n LanguageName,\n ParsedFormatFnByKey,\n ParsedFormatFn,\n} from '@vocab/core';\n\nimport React, {\n type ReactNode,\n useContext,\n useMemo,\n useReducer,\n isValidElement,\n cloneElement,\n useCallback,\n} from 'react';\n\ntype Locale = string;\n\ninterface TranslationsContextValue {\n /**\n * The `language` passed in to your `VocabProvider`\n */\n language: LanguageName;\n /**\n * The `locale` passed in to your `VocabProvider`\n *\n * Please note that this value will be `undefined` if you have not passed a `locale` to your `VocabProvider`.\n * If your languages are named with IETF language tags, you should just use `language` instead of\n * this value, unless you specifically need to access your `locale` override.\n */\n locale?: Locale;\n}\n\nconst TranslationsContext = React.createContext<\n TranslationsContextValue | undefined\n>(undefined);\n\n// Not extending TranslationsContextValue so we can tailor the docs for each prop to be better\n// suited to the provider, rather than for the useLanguage hook\ninterface VocabProviderProps {\n /**\n * The language to load translations for. Must be one of the language names defined in your `vocab.config.js`.\n */\n language: TranslationsContextValue['language'];\n /**\n * A locale override. By default, Vocab will use the `language` as the locale when formatting messages if\n * `locale` is not set. If your languages are named with IETF language tags, you probably don't need to\n * set this value.\n *\n * You may want to override the locale for a specific language if the default formatting for that locale\n * is not desired.\n *\n * @example\n * // Override the locale for th-TH to use the Gregorian calendar instead of the default Buddhist calendar\n * <VocabProvider language=\"th-TH\" locale=\"th-TH-u-ca-gregory\">\n * </App>\n * <VocabProvider />\n */\n locale?: TranslationsContextValue['locale'];\n children: ReactNode;\n}\n\n/**\n * Provides a translation context for your application\n *\n * @example\n * import { VocabProvider } from '@vocab/react';\n *\n * <VocabProvider language=\"en\">\n * <App />\n * <VocabProvider />\n */\nexport const VocabProvider = ({\n children,\n language,\n locale,\n}: VocabProviderProps) => {\n const value = useMemo(() => ({ language, locale }), [language, locale]);\n\n return (\n <TranslationsContext.Provider value={value}>\n {children}\n </TranslationsContext.Provider>\n );\n};\n\n/**\n * @returns The `language` and `locale` values passed in to your `VocabProvider`\n */\nexport const useLanguage = (): TranslationsContextValue => {\n const context = useContext(TranslationsContext);\n if (!context) {\n throw new Error(\n 'Attempted to access translation without Vocab context set. Did you forget to render VocabProvider?',\n );\n }\n if (!context.language) {\n throw new Error(\n 'Attempted to access translation without language set. Did you forget to pass language to VocabProvider?',\n );\n }\n\n return context;\n};\n\nconst SERVER_RENDERING = typeof window === 'undefined';\n\ntype FormatXMLElementReactNodeFn = (parts: ReactNode[]) => ReactNode;\n\ntype MapToReactNodeFunction<Params extends Record<string, any>> = {\n [key in keyof Params]: Params[key] extends ParsedFormatFn\n ? FormatXMLElementReactNodeFn\n : Params[key];\n};\n\ntype TranslateFn<FormatFnByKey extends ParsedFormatFnByKey> = {\n <TranslationKey extends keyof FormatFnByKey>(\n key: TranslationKey,\n params: MapToReactNodeFunction<\n Parameters<FormatFnByKey[TranslationKey]>[0]\n >,\n ): ReturnType<FormatFnByKey[TranslationKey]> extends string\n ? string\n : ReactNode | string | Array<ReactNode | string>;\n <TranslationKey extends keyof FormatFnByKey>(\n key: Parameters<FormatFnByKey[TranslationKey]>[0] extends Record<\n string,\n any\n >\n ? never\n : TranslationKey,\n ): string;\n};\n\nexport function useTranslations<\n Language extends string,\n FormatFnByKey extends ParsedFormatFnByKey,\n>(\n translations: TranslationFile<Language, FormatFnByKey>,\n): {\n ready: boolean;\n t: TranslateFn<FormatFnByKey>;\n} {\n const { language, locale } = useLanguage();\n const [, forceRender] = useReducer((s: number) => s + 1, 0);\n\n const translationsObject = translations.getLoadedMessages(\n language as any,\n locale || language,\n );\n\n let ready = true;\n\n if (!translationsObject) {\n if (SERVER_RENDERING) {\n throw new Error(\n `Translations not synchronously available on server render. Applying translations dynamically server-side is not supported.`,\n );\n }\n\n translations.load(language as any).then(() => {\n forceRender();\n });\n ready = false;\n }\n\n const t = useCallback(\n (key: string, params?: any) => {\n if (!translationsObject) {\n return ' ';\n }\n\n const message = translationsObject?.[key];\n\n if (!message) {\n // eslint-disable-next-line no-console\n console.error(\n `Unable to find translation for key \"${key}\". Possible keys are ${Object.keys(\n translationsObject,\n )\n .map((v) => `\"${v}\"`)\n .join(', ')}`,\n );\n return '';\n }\n\n const result = message.format(params);\n\n if (Array.isArray(result)) {\n for (let i = 0; i < result.length; i++) {\n const item = result[i];\n if (\n typeof item === 'object' &&\n item &&\n !item.key &&\n isValidElement(item)\n ) {\n result[i] = cloneElement(item, { key: `_vocab-${i}` });\n }\n }\n }\n\n return result;\n },\n [translationsObject],\n );\n\n return {\n ready,\n t,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,sBAAsBA,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SAAO;IAET,CAAC,mBAAmB,CACrB;AAED,QAAO;EACL;EACA;EACD"}
1
+ {"version":3,"file":"index.cjs","names":["React"],"sources":["../src/components.tsx"],"sourcesContent":["import type {\n TranslationFile,\n LanguageName,\n ParsedFormatFnByKey,\n ParsedFormatFn,\n} from '@vocab/core';\n\nimport React, {\n type ReactNode,\n useContext,\n useMemo,\n useReducer,\n isValidElement,\n cloneElement,\n useCallback,\n} from 'react';\n\ntype Locale = string;\n\ninterface TranslationsContextValue {\n /**\n * The `language` passed in to your `VocabProvider`\n */\n language: LanguageName;\n /**\n * The `locale` passed in to your `VocabProvider`\n *\n * Please note that this value will be `undefined` if you have not passed a `locale` to your `VocabProvider`.\n * If your languages are named with IETF language tags, you should just use `language` instead of\n * this value, unless you specifically need to access your `locale` override.\n */\n locale?: Locale;\n}\n\nconst TranslationsContext = React.createContext<\n TranslationsContextValue | undefined\n>(undefined);\n\n// Not extending TranslationsContextValue so we can tailor the docs for each prop to be better\n// suited to the provider, rather than for the useLanguage hook\ninterface VocabProviderProps {\n /**\n * The language to load translations for. Must be one of the language names defined in your `vocab.config.js`.\n */\n language: TranslationsContextValue['language'];\n /**\n * A locale override. By default, Vocab will use the `language` as the locale when formatting messages if\n * `locale` is not set. If your languages are named with IETF language tags, you probably don't need to\n * set this value.\n *\n * You may want to override the locale for a specific language if the default formatting for that locale\n * is not desired.\n *\n * @example\n * // Override the locale for th-TH to use the Gregorian calendar instead of the default Buddhist calendar\n * <VocabProvider language=\"th-TH\" locale=\"th-TH-u-ca-gregory\">\n * </App>\n * <VocabProvider />\n */\n locale?: TranslationsContextValue['locale'];\n children: ReactNode;\n}\n\n/**\n * Provides a translation context for your application\n *\n * @example\n * import { VocabProvider } from '@vocab/react';\n *\n * <VocabProvider language=\"en\">\n * <App />\n * <VocabProvider />\n */\nexport const VocabProvider = ({\n children,\n language,\n locale,\n}: VocabProviderProps) => {\n const value = useMemo(() => ({ language, locale }), [language, locale]);\n\n return (\n <TranslationsContext.Provider value={value}>\n {children}\n </TranslationsContext.Provider>\n );\n};\n\n/**\n * @returns The `language` and `locale` values passed in to your `VocabProvider`\n */\nexport const useLanguage = (): TranslationsContextValue => {\n const context = useContext(TranslationsContext);\n if (!context) {\n throw new Error(\n 'Attempted to access translation without Vocab context set. Did you forget to render VocabProvider?',\n );\n }\n if (!context.language) {\n throw new Error(\n 'Attempted to access translation without language set. Did you forget to pass language to VocabProvider?',\n );\n }\n\n return context;\n};\n\nconst SERVER_RENDERING = typeof window === 'undefined';\n\ntype FormatXMLElementReactNodeFn = (parts: ReactNode[]) => ReactNode;\n\ntype MapToReactNodeFunction<Params extends Record<string, any>> = {\n [key in keyof Params]: Params[key] extends ParsedFormatFn\n ? FormatXMLElementReactNodeFn\n : Params[key];\n};\n\ntype TranslateFn<FormatFnByKey extends ParsedFormatFnByKey> = {\n <TranslationKey extends keyof FormatFnByKey>(\n key: TranslationKey,\n params: MapToReactNodeFunction<\n Parameters<FormatFnByKey[TranslationKey]>[0]\n >,\n ): ReturnType<FormatFnByKey[TranslationKey]> extends string\n ? string\n : ReactNode | string | Array<ReactNode | string>;\n <TranslationKey extends keyof FormatFnByKey>(\n key: Parameters<FormatFnByKey[TranslationKey]>[0] extends Record<\n string,\n any\n >\n ? never\n : TranslationKey,\n ): string;\n};\n\nexport function useTranslations<\n Language extends string,\n FormatFnByKey extends ParsedFormatFnByKey,\n>(\n translations: TranslationFile<Language, FormatFnByKey>,\n): {\n ready: boolean;\n t: TranslateFn<FormatFnByKey>;\n} {\n const { language, locale } = useLanguage();\n const [, forceRender] = useReducer((s: number) => s + 1, 0);\n\n const translationsObject = translations.getLoadedMessages(\n language as any,\n locale || language,\n );\n\n let ready = true;\n\n if (!translationsObject) {\n if (SERVER_RENDERING) {\n throw new Error(\n `Translations not synchronously available on server render. Applying translations dynamically server-side is not supported.`,\n );\n }\n\n translations.load(language as any).then(() => {\n forceRender();\n });\n ready = false;\n }\n\n const t = useCallback(\n (key: string, params?: any) => {\n if (!translationsObject) {\n return ' ';\n }\n\n const message = translationsObject?.[key];\n\n if (!message) {\n // eslint-disable-next-line no-console\n console.error(\n `Unable to find translation for key \"${key}\". Possible keys are ${Object.keys(\n translationsObject,\n )\n .map((v) => `\"${v}\"`)\n .join(', ')}`,\n );\n return '';\n }\n\n const result = message.format(params);\n\n if (Array.isArray(result)) {\n for (let i = 0; i < result.length; i++) {\n const item = result[i];\n if (\n typeof item === 'object' &&\n item &&\n !item.key &&\n isValidElement(item)\n ) {\n result[i] = cloneElement(item, { key: `_vocab-${i}` });\n }\n }\n }\n\n return result;\n },\n [translationsObject],\n );\n\n return {\n ready,\n t,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,sBAAsBA,cAAM,cAEhC,OAAU;;;;;;;;;;;AAqCZ,MAAa,iBAAiB,EAC5B,UACA,UACA,aACwB;CACxB,MAAM,kCAAuB;EAAE;EAAU;EAAQ,GAAG,CAAC,UAAU,OAAO,CAAC;AAEvE,QACE,4CAAC,oBAAoB,YAAgB,SAClC,SAC4B;;;;;AAOnC,MAAa,oBAA8C;CACzD,MAAM,gCAAqB,oBAAoB;AAC/C,KAAI,CAAC,QACH,OAAM,IAAI,MACR,qGACD;AAEH,KAAI,CAAC,QAAQ,SACX,OAAM,IAAI,MACR,0GACD;AAGH,QAAO;;AAGT,MAAM,mBAAmB,OAAO,WAAW;AA6B3C,SAAgB,gBAId,cAIA;CACA,MAAM,EAAE,UAAU,WAAW,aAAa;CAC1C,MAAM,GAAG,sCAA2B,MAAc,IAAI,GAAG,EAAE;CAE3D,MAAM,qBAAqB,aAAa,kBACtC,UACA,UAAU,SACX;CAED,IAAI,QAAQ;AAEZ,KAAI,CAAC,oBAAoB;AACvB,MAAI,iBACF,OAAM,IAAI,MACR,6HACD;AAGH,eAAa,KAAK,SAAgB,CAAC,WAAW;AAC5C,gBAAa;IACb;AACF,UAAQ;;CAGV,MAAM,4BACH,KAAa,WAAiB;AAC7B,MAAI,CAAC,mBACH,QAAO;EAGT,MAAM,UAAU,qBAAqB;AAErC,MAAI,CAAC,SAAS;AAEZ,WAAQ,MACN,uCAAuC,IAAI,uBAAuB,OAAO,KACvE,mBACD,CACE,KAAK,MAAM,IAAI,EAAE,GAAG,CACpB,KAAK,KAAK,GACd;AACD,UAAO;;EAGT,MAAM,SAAS,QAAQ,OAAO,OAAO;AAErC,MAAI,MAAM,QAAQ,OAAO,CACvB,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;GACtC,MAAM,OAAO,OAAO;AACpB,OACE,OAAO,SAAS,YAChB,QACA,CAAC,KAAK,iCACS,KAAK,CAEpB,QAAO,6BAAkB,MAAM,EAAE,KAAK,UAAU,KAAK,CAAC;;AAK5D,SAAO;IAET,CAAC,mBAAmB,CACrB;AAED,QAAO;EACL;EACA;EACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vocab/react",
3
- "version": "1.1.16-rollup-plugin-20251205045501",
3
+ "version": "1.1.17-isolate-rolldown-runtime-20251217033548",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/seek-oss/vocab.git",
@@ -11,8 +11,8 @@
11
11
  "types": "./dist/index.d.cts",
12
12
  "exports": {
13
13
  ".": {
14
- "import": "./dist/index.mjs",
15
- "require": "./dist/index.cjs"
14
+ "require": "./dist/index.cjs",
15
+ "import": "./dist/index.mjs"
16
16
  },
17
17
  "./package.json": "./package.json"
18
18
  },
@@ -26,7 +26,7 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "intl-messageformat": "^10.0.0",
29
- "@vocab/core": "^1.7.0-rollup-plugin-20251205045501"
29
+ "@vocab/core": "^1.7.1-isolate-rolldown-runtime-20251217033548"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/react": "^19.1.8",