muffin-admin 3.10.1 → 3.11.0

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.
@@ -6,12 +6,19 @@ import Typography from "@mui/material/Typography";
6
6
  import { AdminContext, AdminUI, AppBar, Layout, localStorageStore, Login, } from "react-admin";
7
7
  import { ConfirmationProvider } from "./common";
8
8
  import { useMuffinAdminOpts } from "./hooks";
9
- import { muffinI18nProvider } from "./i18n";
9
+ import { buildProvider, muffinTranslations } from "./i18n";
10
10
  import { buildAdmin, findBuilder, findIcon, setupAdmin } from "./utils";
11
11
  export function MuffinAdmin(props) {
12
12
  const opts = useMuffinAdminOpts();
13
- const { resources = [], auth, adminProps, apiUrl } = opts;
13
+ const { resources = [], auth, adminProps, apiUrl, locales } = opts;
14
14
  document.title = (adminProps === null || adminProps === void 0 ? void 0 : adminProps.title) || "Muffin Admin";
15
+ const muffinI18nProvider = buildProvider(locales
16
+ ? Object.fromEntries(Object.entries(muffinTranslations).map(([locale, messages]) => [
17
+ locale,
18
+ Object.assign(Object.assign({}, messages), locales[locale]),
19
+ ]))
20
+ : muffinTranslations);
21
+ console.log(999, muffinI18nProvider.getLocale());
15
22
  const { basename, authProvider = findBuilder(["authprovider"])(auth), dataProvider = findBuilder(["dataprovider"])(apiUrl), catchAll, dashboard = findBuilder(["dashboard"]), disableTelemetry, error, i18nProvider = muffinI18nProvider, layout = findBuilder(["layout"]), loading, loginPage = findBuilder(["loginpage"]), authCallbackPage, notification, queryClient, requireAuth = auth.required, store = localStorageStore(), ready, theme, lightTheme, darkTheme, defaultTheme, title = "React Admin", } = props;
16
23
  return (_jsx(AdminContext, { authProvider: authProvider, basename: basename, dataProvider: dataProvider, i18nProvider: i18nProvider, store: store, queryClient: queryClient, theme: theme, lightTheme: lightTheme, darkTheme: darkTheme, defaultTheme: defaultTheme, children: _jsx(ConfirmationProvider, { children: _jsx(AdminUI, { layout: layout, dashboard: dashboard, disableTelemetry: disableTelemetry, catchAll: catchAll, error: error, title: title, loading: loading, loginPage: loginPage, authCallbackPage: authCallbackPage, notification: notification, requireAuth: requireAuth, ready: ready, children: resources === null || resources === void 0 ? void 0 : resources.map(({ name }) => buildAdmin(["resource", name], { name })) }) }) }));
17
24
  }
@@ -1,3 +1,4 @@
1
1
  export * from "./useAction";
2
+ export * from "./useForceUpdate";
2
3
  export * from "./useMuffinAdminOpts";
3
4
  export * from "./useMuffinResourceOpts";
@@ -1,3 +1,4 @@
1
1
  export * from "./useAction";
2
+ export * from "./useForceUpdate";
2
3
  export * from "./useMuffinAdminOpts";
3
4
  export * from "./useMuffinResourceOpts";
@@ -0,0 +1 @@
1
+ export declare function useForceUpdate(): () => void;
@@ -0,0 +1,5 @@
1
+ import { useState } from "react";
2
+ export function useForceUpdate() {
3
+ const [, setTick] = useState(0);
4
+ return () => setTick((tick) => tick + 1);
5
+ }
package/dist/i18n/en.d.ts CHANGED
@@ -1,7 +1,3 @@
1
- declare const muffinEnglishMessages: {
2
- muffin: {
3
- instructions: string;
4
- how_to_use_admin: string;
5
- };
6
- };
1
+ import { TranslationMessages } from "ra-core";
2
+ declare const muffinEnglishMessages: TranslationMessages;
7
3
  export default muffinEnglishMessages;
package/dist/i18n/en.js CHANGED
@@ -1,7 +1,6 @@
1
- const muffinEnglishMessages = {
2
- muffin: {
1
+ import raEnglishMessages from "ra-language-english";
2
+ const muffinEnglishMessages = Object.assign(Object.assign({}, raEnglishMessages), { muffin: {
3
3
  instructions: "Instructions",
4
4
  how_to_use_admin: "How to use Admin?",
5
- },
6
- };
5
+ } });
7
6
  export default muffinEnglishMessages;
@@ -1 +1,3 @@
1
+ export * from "./en";
1
2
  export * from "./provider";
3
+ export * from "./ru";
@@ -1 +1,3 @@
1
+ export * from "./en";
1
2
  export * from "./provider";
3
+ export * from "./ru";
@@ -1 +1,5 @@
1
- export declare const muffinI18nProvider: import("react-admin").I18nProvider;
1
+ export declare const muffinTranslations: {
2
+ en: import("react-admin").TranslationMessages;
3
+ ru: import("react-admin").TranslationMessages;
4
+ };
5
+ export declare const buildProvider: (translations: any) => import("react-admin").I18nProvider;
@@ -1,14 +1,15 @@
1
1
  import polyglotI18nProvider from "ra-i18n-polyglot";
2
- import raEnglishMessages from "ra-language-english";
3
- import raRussianMessages from "ra-language-russian";
4
2
  import { resolveBrowserLocale } from "react-admin";
5
3
  import muffinEnglishMessages from "./en";
6
4
  import muffinRussianMessages from "./ru";
7
- const translations = {
8
- en: Object.assign(Object.assign({}, raEnglishMessages), muffinEnglishMessages),
9
- ru: Object.assign(Object.assign({}, raRussianMessages), muffinRussianMessages),
5
+ export const muffinTranslations = {
6
+ en: muffinEnglishMessages,
7
+ ru: muffinRussianMessages,
8
+ };
9
+ const defaultLocale = "en";
10
+ export const buildProvider = (translations) => {
11
+ return polyglotI18nProvider((locale) => (translations[locale] ? translations[locale] : translations[defaultLocale]), resolveBrowserLocale(), [
12
+ { locale: "en", name: "English" },
13
+ { locale: "ru", name: "Русский" },
14
+ ], { allowMissing: true });
10
15
  };
11
- export const muffinI18nProvider = polyglotI18nProvider((locale) => (translations[locale] ? translations[locale] : translations.en), resolveBrowserLocale(), [
12
- { locale: "en", name: "English" },
13
- { locale: "ru", name: "Русский" },
14
- ], { allowMissing: true });
package/dist/i18n/ru.d.ts CHANGED
@@ -1,7 +1,3 @@
1
- declare const muffinRussianMessages: {
2
- muffin: {
3
- instructions: string;
4
- how_to_use_admin: string;
5
- };
6
- };
1
+ import { TranslationMessages } from "ra-core";
2
+ declare const muffinRussianMessages: TranslationMessages;
7
3
  export default muffinRussianMessages;
package/dist/i18n/ru.js CHANGED
@@ -1,7 +1,6 @@
1
- const muffinRussianMessages = {
2
- muffin: {
1
+ import raRussianMessages from "ra-language-russian";
2
+ const muffinRussianMessages = Object.assign(Object.assign({}, raRussianMessages), { muffin: {
3
3
  instructions: "Инструкции",
4
4
  how_to_use_admin: "Как использовать админку?",
5
- },
6
- };
5
+ } });
7
6
  export default muffinRussianMessages;