@inventreedb/ui 1.4.1 → 1.4.2

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 CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  This file contains historical changelog information for the InvenTree UI components library.
4
4
 
5
+ ### 1.4.2 - June 2026
6
+
7
+ Fixes a bug in the `LocalizedComponent` function
8
+
5
9
  ### 1.4.1 - June 2026
6
10
 
7
11
  ### HMR Support
@@ -1,9 +1,11 @@
1
+ import { I18n } from '@lingui/core';
1
2
  /**
2
3
  * Wrapper function for a plugin-defined component which needs to support dynamic locale loading.
3
4
  *
4
5
  * This is primarily designed for usage by the InvenTree plugin creator tool
5
6
  */
6
- export default function LocalizedComponent({ locale, children }: {
7
+ export default function LocalizedComponent({ i18n, locale, children }: {
8
+ i18n: I18n;
7
9
  locale: string;
8
10
  children: React.ReactNode;
9
11
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,6 +1,5 @@
1
1
  import __variableDynamicImportRuntimeHelper from "../_virtual/dynamic-import-helper.js";
2
2
  import { j as jsxRuntimeExports } from "../_virtual/jsx-runtime.js";
3
- const i18n = window["LinguiCore"].i18n;
4
3
  const I18nProvider = window["LinguiReact"].I18nProvider;
5
4
  const Skeleton = window["MantineCore"].Skeleton;
6
5
  const useEffect = window["React"].useEffect;
@@ -14,7 +13,7 @@ async function tryLoadLocale(locale) {
14
13
  return null;
15
14
  }
16
15
  }
17
- async function loadPluginLocale(locale) {
16
+ async function loadPluginLocale(i18n, locale) {
18
17
  let messages = null;
19
18
  messages = await tryLoadLocale(locale);
20
19
  if (!messages && locale.includes("-")) {
@@ -39,16 +38,17 @@ async function loadPluginLocale(locale) {
39
38
  }
40
39
  }
41
40
  function LocalizedComponent({
41
+ i18n,
42
42
  locale,
43
43
  children
44
44
  }) {
45
45
  const [loaded, setLoaded] = useState(false);
46
46
  useEffect(() => {
47
47
  setLoaded(false);
48
- loadPluginLocale(locale).then(() => {
48
+ loadPluginLocale(i18n, locale).then(() => {
49
49
  setLoaded(true);
50
50
  });
51
- }, [locale]);
51
+ }, [i18n, locale]);
52
52
  return loaded ? /* @__PURE__ */ jsxRuntimeExports.jsx(I18nProvider, { i18n, children }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Skeleton, { w: "100%", animate: true });
53
53
  }
54
54
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"LocalizedComponent.js","sources":["../../lib/plugin/LocalizedComponent.tsx"],"sourcesContent":["import { i18n } from '@lingui/core';\nimport { I18nProvider } from '@lingui/react';\nimport { Skeleton } from '@mantine/core';\nimport { useEffect, useState } from 'react';\n\n/**\n * Attempt to load the locale file for the given locale, returning null if it fails\n */\nasync function tryLoadLocale(locale: string): Promise<any> {\n try {\n const messages = await import(`./locales/${locale}/messages.ts`);\n return messages;\n } catch (error) {\n console.warn(`Failed to load locale ${locale}`);\n return null;\n }\n}\n\n/**\n * Helper function to dynamically load frontend translations,\n * based on the provided locale.\n */\nasync function loadPluginLocale(locale: string) {\n let messages = null;\n\n // Find the most specific locale file possible, with fallbacks to less specific locales if necessary\n messages = await tryLoadLocale(locale);\n\n if (!messages && locale.includes('-')) {\n const fallbackLocale = locale.split('-')[0];\n console.debug(\n `Locale ${locale} not found, trying fallback locale ${fallbackLocale}`\n );\n messages = await tryLoadLocale(fallbackLocale);\n }\n\n if (!messages && locale.includes('_')) {\n const fallbackLocale = locale.split('_')[0];\n console.debug(\n `Locale ${locale} not found, trying fallback locale ${fallbackLocale}`\n );\n messages = await tryLoadLocale(fallbackLocale);\n }\n\n if (!messages && locale !== 'en') {\n console.debug(`Locale ${locale} not found, trying fallback locale en`);\n messages = await tryLoadLocale('en');\n }\n\n if (messages?.messages) {\n i18n.load(locale, messages.messages);\n i18n.activate(locale);\n } else {\n console.error(`Failed to load any locale for ${locale}`);\n }\n}\n\n/**\n * Wrapper function for a plugin-defined component which needs to support dynamic locale loading.\n *\n * This is primarily designed for usage by the InvenTree plugin creator tool\n */\nexport default function LocalizedComponent({\n locale,\n children\n}: {\n locale: string;\n children: React.ReactNode;\n}) {\n const [loaded, setLoaded] = useState(false);\n\n // Reload the component when the locale changes\n useEffect(() => {\n setLoaded(false);\n loadPluginLocale(locale).then(() => {\n setLoaded(true);\n });\n }, [locale]);\n\n return loaded ? (\n <I18nProvider i18n={i18n}>{children}</I18nProvider>\n ) : (\n <Skeleton w='100%' animate />\n );\n}\n"],"names":["tryLoadLocale","locale","messages","error","console","warn","loadPluginLocale","includes","fallbackLocale","split","debug","i18n","load","activate","LocalizedComponent","children","loaded","setLoaded","useState","useEffect","then","jsx"],"mappings":";;AAAA,MAAA,OAAA,OAAA,YAAA,EAAA;AACA,MAAA,eAAA,OAAA,aAAA,EAAA;AACA,MAAA,WAAA,OAAA,aAAA,EAAA;AACA,MAAA,YAAA,OAAA,OAAA,EAAA;;AAKA,eAAeA,cAAcC,QAA8B;AACzD,MAAI;AACF,UAAMC,WAAW,MAAM,wEAAA,aAAA,MAAA,gBAAA,CAAA;AACvB,WAAOA;AAAAA,EACT,SAASC,OAAO;AACdC,YAAQC,KAAK,yBAAyBJ,MAAM,EAAE;AAC9C,WAAO;AAAA,EACT;AACF;AAMA,eAAeK,iBAAiBL,QAAgB;AAC9C,MAAIC,WAAW;AAGfA,aAAW,MAAMF,cAAcC,MAAM;AAErC,MAAI,CAACC,YAAYD,OAAOM,SAAS,GAAG,GAAG;AACrC,UAAMC,iBAAiBP,OAAOQ,MAAM,GAAG,EAAE,CAAC;AAC1CL,YAAQM,MACN,UAAUT,MAAM,sCAAsCO,cAAc,EACtE;AACAN,eAAW,MAAMF,cAAcQ,cAAc;AAAA,EAC/C;AAEA,MAAI,CAACN,YAAYD,OAAOM,SAAS,GAAG,GAAG;AACrC,UAAMC,iBAAiBP,OAAOQ,MAAM,GAAG,EAAE,CAAC;AAC1CL,YAAQM,MACN,UAAUT,MAAM,sCAAsCO,cAAc,EACtE;AACAN,eAAW,MAAMF,cAAcQ,cAAc;AAAA,EAC/C;AAEA,MAAI,CAACN,YAAYD,WAAW,MAAM;AAChCG,YAAQM,MAAM,UAAUT,MAAM,uCAAuC;AACrEC,eAAW,MAAMF,cAAc,IAAI;AAAA,EACrC;AAEA,MAAIE,qCAAUA,UAAU;AACtBS,SAAKC,KAAKX,QAAQC,SAASA,QAAQ;AACnCS,SAAKE,SAASZ,MAAM;AAAA,EACtB,OAAO;AACLG,YAAQD,MAAM,iCAAiCF,MAAM,EAAE;AAAA,EACzD;AACF;AAOA,SAAwBa,mBAAmB;AAAA,EACzCb;AAAAA,EACAc;AAIF,GAAG;AACD,QAAM,CAACC,QAAQC,SAAS,IAAIC,SAAS,KAAK;AAG1CC,YAAU,MAAM;AACdF,cAAU,KAAK;AACfX,qBAAiBL,MAAM,EAAEmB,KAAK,MAAM;AAClCH,gBAAU,IAAI;AAAA,IAChB,CAAC;AAAA,EACH,GAAG,CAAChB,MAAM,CAAC;AAEX,SAAOe,SACLK,kCAAAA,IAAC,cAAA,EAAa,MAAaN,SAAAA,CAAS,IAEpCM,kCAAAA,IAAC,UAAA,EAAS,GAAE,QAAO,SAAO,KAAA,CAAA;AAE9B;"}
1
+ {"version":3,"file":"LocalizedComponent.js","sources":["../../lib/plugin/LocalizedComponent.tsx"],"sourcesContent":["import { I18n } from '@lingui/core';\nimport { I18nProvider } from '@lingui/react';\nimport { Skeleton } from '@mantine/core';\nimport { useEffect, useState } from 'react';\n\n/**\n * Attempt to load the locale file for the given locale, returning null if it fails\n */\nasync function tryLoadLocale(locale: string): Promise<any> {\n try {\n const messages = await import(`./locales/${locale}/messages.ts`);\n return messages;\n } catch (error) {\n console.warn(`Failed to load locale ${locale}`);\n return null;\n }\n}\n\n/**\n * Helper function to dynamically load frontend translations,\n * based on the provided locale.\n */\nasync function loadPluginLocale(i18n: I18n, locale: string) {\n let messages = null;\n\n // Find the most specific locale file possible, with fallbacks to less specific locales if necessary\n messages = await tryLoadLocale(locale);\n\n if (!messages && locale.includes('-')) {\n const fallbackLocale = locale.split('-')[0];\n console.debug(\n `Locale ${locale} not found, trying fallback locale ${fallbackLocale}`\n );\n messages = await tryLoadLocale(fallbackLocale);\n }\n\n if (!messages && locale.includes('_')) {\n const fallbackLocale = locale.split('_')[0];\n console.debug(\n `Locale ${locale} not found, trying fallback locale ${fallbackLocale}`\n );\n messages = await tryLoadLocale(fallbackLocale);\n }\n\n if (!messages && locale !== 'en') {\n console.debug(`Locale ${locale} not found, trying fallback locale en`);\n messages = await tryLoadLocale('en');\n }\n\n if (messages?.messages) {\n i18n.load(locale, messages.messages);\n i18n.activate(locale);\n } else {\n console.error(`Failed to load any locale for ${locale}`);\n }\n}\n\n/**\n * Wrapper function for a plugin-defined component which needs to support dynamic locale loading.\n *\n * This is primarily designed for usage by the InvenTree plugin creator tool\n */\nexport default function LocalizedComponent({\n i18n,\n locale,\n children\n}: {\n i18n: I18n;\n locale: string;\n children: React.ReactNode;\n}) {\n const [loaded, setLoaded] = useState(false);\n\n // Reload the component when the locale changes\n useEffect(() => {\n setLoaded(false);\n loadPluginLocale(i18n, locale).then(() => {\n setLoaded(true);\n });\n }, [i18n, locale]);\n\n return loaded ? (\n <I18nProvider i18n={i18n}>{children}</I18nProvider>\n ) : (\n <Skeleton w='100%' animate />\n );\n}\n"],"names":["tryLoadLocale","locale","messages","error","console","warn","loadPluginLocale","i18n","includes","fallbackLocale","split","debug","load","activate","LocalizedComponent","children","loaded","setLoaded","useState","useEffect","then","jsx"],"mappings":";;AACA,MAAA,eAAA,OAAA,aAAA,EAAA;AACA,MAAA,WAAA,OAAA,aAAA,EAAA;AACA,MAAA,YAAA,OAAA,OAAA,EAAA;;AAKA,eAAeA,cAAcC,QAA8B;AACzD,MAAI;AACF,UAAMC,WAAW,MAAM,wEAAA,aAAA,MAAA,gBAAA,CAAA;AACvB,WAAOA;AAAAA,EACT,SAASC,OAAO;AACdC,YAAQC,KAAK,yBAAyBJ,MAAM,EAAE;AAC9C,WAAO;AAAA,EACT;AACF;AAMA,eAAeK,iBA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1,4 @@
1
- const INVENTREE_PLUGIN_VERSION = "1.4.1";
1
+ const INVENTREE_PLUGIN_VERSION = "1.4.2";
2
2
  const INVENTREE_REACT_VERSION = "19.2.4";
3
3
  const INVENTREE_REACT_DOM_VERSION = (
4
4
  // @ts-ignore
@@ -1,4 +1,4 @@
1
- import { i18n } from '@lingui/core';
1
+ import { I18n } from '@lingui/core';
2
2
  import { I18nProvider } from '@lingui/react';
3
3
  import { Skeleton } from '@mantine/core';
4
4
  import { useEffect, useState } from 'react';
@@ -20,7 +20,7 @@ async function tryLoadLocale(locale: string): Promise<any> {
20
20
  * Helper function to dynamically load frontend translations,
21
21
  * based on the provided locale.
22
22
  */
23
- async function loadPluginLocale(locale: string) {
23
+ async function loadPluginLocale(i18n: I18n, locale: string) {
24
24
  let messages = null;
25
25
 
26
26
  // Find the most specific locale file possible, with fallbacks to less specific locales if necessary
@@ -61,9 +61,11 @@ async function loadPluginLocale(locale: string) {
61
61
  * This is primarily designed for usage by the InvenTree plugin creator tool
62
62
  */
63
63
  export default function LocalizedComponent({
64
+ i18n,
64
65
  locale,
65
66
  children
66
67
  }: {
68
+ i18n: I18n;
67
69
  locale: string;
68
70
  children: React.ReactNode;
69
71
  }) {
@@ -72,10 +74,10 @@ export default function LocalizedComponent({
72
74
  // Reload the component when the locale changes
73
75
  useEffect(() => {
74
76
  setLoaded(false);
75
- loadPluginLocale(locale).then(() => {
77
+ loadPluginLocale(i18n, locale).then(() => {
76
78
  setLoaded(true);
77
79
  });
78
- }, [locale]);
80
+ }, [i18n, locale]);
79
81
 
80
82
  return loaded ? (
81
83
  <I18nProvider i18n={i18n}>{children}</I18nProvider>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@inventreedb/ui",
3
3
  "description": "UI components for the InvenTree project",
4
- "version": "1.4.1",
4
+ "version": "1.4.2",
5
5
  "private": false,
6
6
  "type": "module",
7
7
  "license": "MIT",