@m4l/graphics 0.0.0 → 0.0.1

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.js CHANGED
@@ -31,11 +31,11 @@ var __objRest = (source, exclude) => {
31
31
  };
32
32
  import Box from "@mui/material/Box";
33
33
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
34
- import { IconButton as IconButton$2, Tooltip as Tooltip$1, Accordion as Accordion$2, AccordionSummary, Skeleton as Skeleton$1, AccordionDetails, Popover as Popover$1, Tab as Tab$1, Link as Link$1, Box as Box$1, Typography as Typography$2, Breadcrumbs as Breadcrumbs$3, MenuItem, TablePagination, Button as Button$1, Autocomplete as Autocomplete$1, TextField, CircularProgress, FormControlLabel, Checkbox as Checkbox$1, FormGroup, RadioGroup, Radio as Radio$1, FormHelperText, SvgIcon as SvgIcon$1, InputBase, GlobalStyles, Dialog as Dialog$1, Paper as Paper$2, Fab as Fab$1, Card as Card$1, Stack, Container as Container$5, alpha as alpha$1 } from "@mui/material";
34
+ import { IconButton as IconButton$2, Tooltip as Tooltip$1, Accordion as Accordion$2, AccordionSummary, Skeleton as Skeleton$1, AccordionDetails, Popover as Popover$1, Tab as Tab$1, Link as Link$1, Box as Box$1, Typography as Typography$2, Breadcrumbs as Breadcrumbs$3, MenuItem, TablePagination, Button as Button$1, Autocomplete as Autocomplete$1, TextField, CircularProgress, FormControlLabel, Checkbox as Checkbox$1, FormGroup, RadioGroup, Radio as Radio$1, FormHelperText, SvgIcon as SvgIcon$1, InputBase, GlobalStyles, Dialog as Dialog$1, Paper as Paper$2, Fab as Fab$1, Card as Card$1, Stack, Container as Container$5, CssBaseline as CssBaseline$1, alpha as alpha$1 } from "@mui/material";
35
35
  import * as React from "react";
36
36
  import React__default, { useMemo, useState, createContext, useContext, useCallback, useEffect, Fragment as Fragment$1, Suspense, forwardRef, useRef, useImperativeHandle, useLayoutEffect as useLayoutEffect$1, memo } from "react";
37
- import { useModuleDictionary, useEnvironment, voidFunction, useFlagsPresent, useNetwork, getPropertyByString, useHostTools, useLocalStorage, FlagsProvider, ModuleDictionaryProvider, getLocalStorage, useFlags } from "@m4l/core";
38
- import { styled, alpha, useTheme } from "@mui/material/styles";
37
+ import { useModuleDictionary, useEnvironment, voidFunction, useFlagsPresent, useNetwork, getPropertyByString, useHostTools, useLocalStorage, FlagsProvider, ModuleDictionaryProvider, getLocalStorage, useFlags, EmitEvents } from "@m4l/core";
38
+ import { styled, alpha, useTheme, createTheme, StyledEngineProvider, ThemeProvider } from "@mui/material/styles";
39
39
  import { Link as Link$2, useNavigate } from "react-router-dom";
40
40
  import { LoadingButton as LoadingButton$2 } from "@mui/lab";
41
41
  import { get, set, appendErrors, useFormContext, useFormState, useForm, FormProvider as FormProvider$1, Controller } from "react-hook-form";
@@ -1138,17 +1138,17 @@ function RHFAutocompleteAsync(props) {
1138
1138
  const {
1139
1139
  networkOperation
1140
1140
  } = useNetwork();
1141
- const initialValue = getValues(name);
1142
- const [options, setOptions] = useState(initialValue === null ? [] : [initialValue]);
1141
+ const initialValue2 = getValues(name);
1142
+ const [options, setOptions] = useState(initialValue2 === null ? [] : [initialValue2]);
1143
1143
  const [open, setOpen] = useState(false);
1144
1144
  const [optionsLoaded, setOptionsLoaded] = useState(false);
1145
1145
  const loading = open && !optionsLoaded;
1146
1146
  useEffect(() => {
1147
- if (!optionsLoaded && initialValue) {
1148
- setOptions([initialValue]);
1147
+ if (!optionsLoaded && initialValue2) {
1148
+ setOptions([initialValue2]);
1149
1149
  }
1150
- }, [initialValue, optionsLoaded]);
1151
- console.log("***2022Render RHFAutocompleteAsync", loading, options, initialValue);
1150
+ }, [initialValue2, optionsLoaded]);
1151
+ console.log("***2022Render RHFAutocompleteAsync", loading, options, initialValue2);
1152
1152
  const getOptionLabelLocal = (option) => {
1153
1153
  if (option === void 0 || option === null) {
1154
1154
  return "";
@@ -1212,7 +1212,7 @@ function RHFAutocompleteAsync(props) {
1212
1212
  }) => /* @__PURE__ */ jsx(Autocomplete$1, {
1213
1213
  options,
1214
1214
  getOptionLabel: getOptionLabelLocal,
1215
- defaultValue: initialValue,
1215
+ defaultValue: initialValue2,
1216
1216
  isOptionEqualToValue: isOptionEqualToValueLocal,
1217
1217
  disableClearable: true,
1218
1218
  value: value || null,
@@ -9356,6 +9356,70 @@ const NoAuthModuleLayout = (props) => {
9356
9356
  })
9357
9357
  });
9358
9358
  };
9359
+ const initialValue = {
9360
+ hostThemeOptions: {},
9361
+ fnComponentsOverrides: voidFunction
9362
+ };
9363
+ const HostThemeContext = createContext(initialValue);
9364
+ function HostThemeProvider(props) {
9365
+ const {
9366
+ children,
9367
+ hostThemeOptions,
9368
+ fnComponentsOverrides: fnComponentsOverrides2,
9369
+ isMicroFrontEnd
9370
+ } = props;
9371
+ const [finalThemeOptions, setFinalThemeOptions] = useState(hostThemeOptions);
9372
+ const {
9373
+ events_add_listener,
9374
+ events_remove_listener,
9375
+ events_emit
9376
+ } = useHostTools();
9377
+ const [isFirstTime, setIsFirstTime] = useState(true);
9378
+ const finalTheme = useMemo(() => {
9379
+ const theme = createTheme(finalThemeOptions);
9380
+ theme.components = fnComponentsOverrides2(theme);
9381
+ return theme;
9382
+ }, [finalThemeOptions]);
9383
+ const onUpdateOverrides = useCallback((newThemeOptions) => {
9384
+ console.debug("Emit HostThemeProvider", newThemeOptions);
9385
+ setFinalThemeOptions(newThemeOptions);
9386
+ }, []);
9387
+ useEffect(() => {
9388
+ if (isMicroFrontEnd) {
9389
+ events_add_listener(EmitEvents.EMMIT_EVENT_HOST_THEME_CHANGE, onUpdateOverrides);
9390
+ }
9391
+ return () => {
9392
+ if (isMicroFrontEnd) {
9393
+ console.log("****** REMOVE LISTENER host_theme_change");
9394
+ events_remove_listener("host_theme_change", onUpdateOverrides);
9395
+ }
9396
+ };
9397
+ }, []);
9398
+ useEffect(() => {
9399
+ if (isFirstTime) {
9400
+ setIsFirstTime(false);
9401
+ return;
9402
+ }
9403
+ if (!isMicroFrontEnd) {
9404
+ events_emit(EmitEvents.EMMIT_EVENT_HOST_THEME_CHANGE, hostThemeOptions);
9405
+ }
9406
+ }, [hostThemeOptions]);
9407
+ return /* @__PURE__ */ jsx(HostThemeContext.Provider, {
9408
+ value: {
9409
+ hostThemeOptions: finalThemeOptions,
9410
+ fnComponentsOverrides: fnComponentsOverrides2
9411
+ },
9412
+ children: /* @__PURE__ */ jsx(StyledEngineProvider, {
9413
+ injectFirst: true,
9414
+ children: /* @__PURE__ */ jsxs(ThemeProvider, {
9415
+ theme: finalTheme,
9416
+ children: [/* @__PURE__ */ jsx(CssBaseline$1, {
9417
+ enableColorScheme: true
9418
+ }), children]
9419
+ })
9420
+ })
9421
+ });
9422
+ }
9359
9423
  function useIsMountedRef() {
9360
9424
  const isMounted = useRef(true);
9361
9425
  useEffect(() => () => {
@@ -9380,6 +9444,12 @@ function useOffSetTop(top) {
9380
9444
  }, [isTop]);
9381
9445
  return offsetTop;
9382
9446
  }
9447
+ const useHostTheme = () => {
9448
+ const context = useContext(HostThemeContext);
9449
+ if (!context)
9450
+ throw new Error("useHostTheme context must be use inside HostThemeProvider");
9451
+ return context;
9452
+ };
9383
9453
  function pxToRem(value) {
9384
9454
  return `${value / 16}rem`;
9385
9455
  }
@@ -10989,4 +11059,4 @@ function LoadingButton(theme) {
10989
11059
  function fnComponentsOverrides(theme) {
10990
11060
  return Object.assign(Fab(theme), Tabs(theme), Card(theme), Menu(theme), Link(theme), Input(theme), InputLabel(), Radio(theme), Badge(), List(theme), Table(theme), Paper(theme), Switch(theme), Button(theme), IconButton(theme), Dialog(theme), Avatar(theme), Slider(theme), Drawer(theme), Stepper(theme), Tooltip(theme), Popover(theme), SvgIcon(), Checkbox(theme), DataGrid(theme), Skeleton(theme), Timeline(theme), Backdrop(theme), Progress(theme), Accordion(theme), Typography(theme), Pagination(theme), ButtonGroup(theme), Breadcrumbs(theme), CssBaseline(), Autocomplete(theme), ControlLabel(theme), ToggleButton(theme), LoadingButton(theme));
10991
11061
  }
10992
- export { Accordion$1 as Accordion, BooleanFormatter, BoxIcon, Breadcrumbs$2 as Breadcrumbs, DataGrid$1 as DataGrid, DateFormatter, DialogAnimate, FabButtonAnimate, FormActions, FormProvider, IconButton$1 as IconButton, IconButtonAnimate, LinkWithRoute, Loadable, LoadingButton$1 as LoadingButton, LocalesContext, LocalesProvider, MasterDetailLayout, MenuActions, MenuPopover, ModalContext, ModalDialog, ModalProvider, ModuleLayout, MotionContainer, MotionInView, MotionLazyContainer, NoAuthModuleLayout, NoItemSelected, ObjectLogs, Page, Pager, PaperForm, ProgressBar, ProgressBarStyle, PropertyValue, RHFAutocompleteAsync, RHFCheckbox, RHFMultiCheckbox, RHFRadioGroup, RHFSelect, RHFTextField, Resizeable, ScrollBar, SplitLayout, TRANSITION, Tab, TextAnimate, Typography$1 as Typography, fnComponentsOverrides as default, defaultPagerDictionary, defaultThemeOptions, getGridComponentsDictionary, getNoItemSelectedComponentsDictionary, getObjectLogsComponentsDictionary, getPagerComponentsDictionary, useIsMountedRef, useLocales, useMasterDetail, useModal, useModule, useOffSetTop, usePaginate, useResponsive, useResponsiveDesktop, varBgColor, varBgKenburns, varBgPan, varBounce, varContainer, varFade, varFlip, varHover, varPath, varRotate, varScale, varSlide, varTranEnter, varTranExit, varTranHover, varZoom };
11062
+ export { Accordion$1 as Accordion, BooleanFormatter, BoxIcon, Breadcrumbs$2 as Breadcrumbs, DataGrid$1 as DataGrid, DateFormatter, DialogAnimate, FabButtonAnimate, FormActions, FormProvider, HostThemeContext, HostThemeProvider, IconButton$1 as IconButton, IconButtonAnimate, LinkWithRoute, Loadable, LoadingButton$1 as LoadingButton, LocalesContext, LocalesProvider, MasterDetailLayout, MenuActions, MenuPopover, ModalContext, ModalDialog, ModalProvider, ModuleLayout, MotionContainer, MotionInView, MotionLazyContainer, NoAuthModuleLayout, NoItemSelected, ObjectLogs, Page, Pager, PaperForm, ProgressBar, ProgressBarStyle, PropertyValue, RHFAutocompleteAsync, RHFCheckbox, RHFMultiCheckbox, RHFRadioGroup, RHFSelect, RHFTextField, Resizeable, ScrollBar, SplitLayout, TRANSITION, Tab, TextAnimate, Typography$1 as Typography, fnComponentsOverrides as default, defaultPagerDictionary, defaultThemeOptions, getGridComponentsDictionary, getNoItemSelectedComponentsDictionary, getObjectLogsComponentsDictionary, getPagerComponentsDictionary, useHostTheme, useIsMountedRef, useLocales, useMasterDetail, useModal, useModule, useOffSetTop, usePaginate, useResponsive, useResponsiveDesktop, varBgColor, varBgKenburns, varBgPan, varBounce, varContainer, varFade, varFlip, varHover, varPath, varRotate, varScale, varSlide, varTranEnter, varTranExit, varTranHover, varZoom };
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { HostThemeProviderProps } from './types';
3
+ declare const HostThemeContext: import("react").Context<import("./types").ThemeType>;
4
+ declare function HostThemeProvider(props: HostThemeProviderProps): JSX.Element;
5
+ export { HostThemeProvider, HostThemeContext };
@@ -0,0 +1,12 @@
1
+ import type { ThemeOptions, Theme } from '@mui/material/styles';
2
+ import type { ReactNode } from 'react';
3
+ export declare type EventFunListener = (...args: any[]) => void;
4
+ export interface ThemeType {
5
+ hostThemeOptions: ThemeOptions;
6
+ fnComponentsOverrides: (theme: Theme) => any;
7
+ }
8
+ export interface HostThemeProviderProps extends ThemeType {
9
+ isMicroFrontEnd: boolean;
10
+ children: ReactNode;
11
+ }
12
+ export declare type HostThemeContextType = ThemeType;
@@ -1,3 +1,4 @@
1
1
  export * from './ModalContext';
2
2
  export * from './LocalesContext';
3
+ export * from './HostThemeContext';
3
4
  export { HelmetProvider } from 'react-helmet-async';
@@ -6,4 +6,5 @@ export { useModal } from './useModal';
6
6
  export { useMasterDetail } from './useMasterDetail';
7
7
  export { useLocales } from './useLocales';
8
8
  export { useOffSetTop } from './useOffSetTop';
9
+ export { useHostTheme } from './useHostTheme';
9
10
  export { useFormContext, Controller, useWatch } from 'react-hook-form';
@@ -0,0 +1 @@
1
+ export declare const useHostTheme: () => import("../contexts/HostThemeContext/types").ThemeType;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@m4l/graphics",
3
3
  "private": false,
4
- "version": "0.0.0",
4
+ "version": "0.0.1",
5
5
  "license": "UNLICENSED",
6
6
  "author": "M4L Team",
7
7
  "scripts": {