@m4l/layouts 0.1.3 → 0.1.5

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.
@@ -43,7 +43,6 @@ function ButtonDetail(props) {
43
43
  onClick,
44
44
  description
45
45
  } = props;
46
- console.log("ButtonDetail", masterSelection);
47
46
  return /* @__PURE__ */ jsx(Button, {
48
47
  onClick,
49
48
  variant: "outlined",
@@ -139,7 +138,6 @@ function MasterDetailLayout(props) {
139
138
  return actions;
140
139
  }, [splitActions, moduleActions, isDesktop, viewDetailAction]);
141
140
  const finalComponentsDictionary = useMemo(() => componentsDictionary.concat(getMasterDetailLayoutComponentsDictionary()), [componentsDictionary]);
142
- console.log("MasterDetailLayout Render");
143
141
  return /* @__PURE__ */ jsx(MasterDetailProvider, {
144
142
  children: /* @__PURE__ */ jsx(ModuleLayout, {
145
143
  ref: moduleLayoutRef,
@@ -251,7 +251,6 @@ function Header() {
251
251
  [moduleActions, isDesktop]
252
252
  );
253
253
  const mainActions = useMemo(() => {
254
- console.log("useMemo Header ModuleActions mainActions", isDesktop, moduleActions);
255
254
  return getMainActions(isDesktop, moduleActions);
256
255
  }, [moduleActions, isDesktop]);
257
256
  if (isSkeleton) {
@@ -1,10 +1,9 @@
1
1
  import { Page, CompanyLogo, LanguagePopover, Typography, Image } from "@m4l/components";
2
2
  import { Card, Container, Stack } from "@mui/material";
3
3
  import { styled } from "@mui/material/styles";
4
- import { useModuleDictionary, useFlagsPresent, getLocalStorage, useNetwork, useEnvironment, useFlags, FlagsProvider, ModuleDictionaryProvider, ModuleSkeletonProvider } from "@m4l/core";
4
+ import { useModuleDictionary, useFlagsPresent, FlagsProvider, DomainProvider, ModuleDictionaryProvider, ModuleSkeletonProvider } from "@m4l/core";
5
5
  import { jsx, jsxs } from "react/jsx-runtime";
6
- import { a as useResponsive } from "../../vendor.js";
7
- import { createContext, useState, useEffect } from "react";
6
+ import { a as useResponsive, b as useLocales } from "../../vendor.js";
8
7
  const RootStyle = styled("div")(({
9
8
  theme
10
9
  }) => ({
@@ -75,7 +74,7 @@ const ModuleWrapper = (props) => {
75
74
  getModuleLabel
76
75
  } = useModuleDictionary();
77
76
  const mdUp = useResponsive("up", "md");
78
- const isSkeleton = !useFlagsPresent(["dictionary_loaded", "style_loaded"]);
77
+ const isSkeleton = !useFlagsPresent(["dictionary_loaded"]);
79
78
  return /* @__PURE__ */ jsx(Page, {
80
79
  title: getModuleLabel(),
81
80
  children: /* @__PURE__ */ jsxs(RootStyle, {
@@ -150,66 +149,6 @@ const ModuleWrapper = (props) => {
150
149
  })
151
150
  });
152
151
  };
153
- const initialState = {
154
- moduleId: "",
155
- styleOptions: {
156
- company_logo_small_url: "",
157
- company_logo_normal_url: ""
158
- }
159
- };
160
- const ModuleContext = createContext(initialState);
161
- function ModuleProvider(props) {
162
- const {
163
- children,
164
- moduleId
165
- } = props;
166
- const [styleOptions, setStyleOptions] = useState(getLocalStorage("styleOptions", {
167
- company_logo_small_url: "",
168
- company_logo_normal_url: ""
169
- }));
170
- const {
171
- networkOperation
172
- } = useNetwork();
173
- const {
174
- domain_token
175
- } = useEnvironment();
176
- const {
177
- flags,
178
- addFlag
179
- } = useFlags();
180
- useEffect(() => {
181
- let mounted = true;
182
- if (flags.findIndex((f) => f === "dictionary_loaded") < 0 || flags.findIndex((f) => f === "style_loaded") > -1) {
183
- return;
184
- }
185
- networkOperation({
186
- method: "GET",
187
- endPoint: `style`,
188
- parms: {
189
- domain_token
190
- }
191
- }).then((response) => {
192
- if (mounted) {
193
- console.log("Result - ModuleProvider - Load Style", response);
194
- setStyleOptions({
195
- ...response.data
196
- });
197
- addFlag("style_loaded");
198
- }
199
- }).finally(() => {
200
- });
201
- return function cleanUp() {
202
- mounted = false;
203
- };
204
- }, [flags]);
205
- return /* @__PURE__ */ jsx(ModuleContext.Provider, {
206
- value: {
207
- styleOptions,
208
- moduleId
209
- },
210
- children
211
- });
212
- }
213
152
  const NoAuthModuleLayout = (props) => {
214
153
  const {
215
154
  moduleId,
@@ -218,16 +157,26 @@ const NoAuthModuleLayout = (props) => {
218
157
  componentsDictionary,
219
158
  skeletonFlags
220
159
  } = props;
160
+ const {
161
+ currentLang
162
+ } = useLocales();
163
+ const finalSkeletonFlags = skeletonFlags;
164
+ if (finalSkeletonFlags.findIndex((f) => f === "dictionary_loaded") < 0) {
165
+ finalSkeletonFlags.push("dictionary_loaded");
166
+ }
167
+ if (finalSkeletonFlags.findIndex((f) => f === "domain_loaded") < 0) {
168
+ finalSkeletonFlags.push("domain_loaded");
169
+ }
221
170
  return /* @__PURE__ */ jsx(FlagsProvider, {
222
- children: /* @__PURE__ */ jsx(ModuleDictionaryProvider, {
223
- isAuth: false,
224
- moduleId,
225
- moduleName,
226
- componentsDictionary,
227
- children: /* @__PURE__ */ jsx(ModuleSkeletonProvider, {
228
- flags: skeletonFlags,
229
- children: /* @__PURE__ */ jsx(ModuleProvider, {
230
- moduleId,
171
+ children: /* @__PURE__ */ jsx(DomainProvider, {
172
+ children: /* @__PURE__ */ jsx(ModuleDictionaryProvider, {
173
+ isAuth: false,
174
+ moduleId,
175
+ moduleName,
176
+ componentsDictionary,
177
+ currentLang: currentLang.value,
178
+ children: /* @__PURE__ */ jsx(ModuleSkeletonProvider, {
179
+ flags: finalSkeletonFlags,
231
180
  children: /* @__PURE__ */ jsx(ModuleWrapper, {
232
181
  children
233
182
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m4l/layouts",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "license": "UNLICENSED",
5
5
  "dependencies": {
6
6
  "@m4l/components": "*",
package/vendor.js CHANGED
@@ -2,10 +2,10 @@ import { useTheme } from "@mui/material/styles";
2
2
  import useMediaQuery from "@mui/material/useMediaQuery";
3
3
  import "@mui/material";
4
4
  import "react/jsx-runtime";
5
- import "react";
5
+ import { createContext, useContext } from "react";
6
+ import "@m4l/core";
6
7
  import "@mui/x-date-pickers/AdapterDateFns";
7
8
  import "@mui/x-date-pickers";
8
- import "@m4l/core";
9
9
  import "./layouts/ModuleLayout/index.js";
10
10
  import "@m4l/components";
11
11
  import "./layouts/MasterDetailLayout/index.js";
@@ -35,6 +35,7 @@ function useResponsiveDesktop() {
35
35
  const isDesktop = useResponsive$1("up", "sm");
36
36
  return isDesktop;
37
37
  }
38
+ const LocalesContext = createContext(null);
38
39
  function useResponsive(query, key, start, end) {
39
40
  const theme = useTheme();
40
41
  const mediaUp = useMediaQuery(theme.breakpoints.up(key));
@@ -54,4 +55,10 @@ function useResponsive(query, key, start, end) {
54
55
  return mediaOnly;
55
56
  }
56
57
  }
57
- export { useResponsive as a, useResponsiveDesktop as u };
58
+ const useLocales = () => {
59
+ const context = useContext(LocalesContext);
60
+ if (!context)
61
+ throw new Error("useLocales context must be use inside LocalesProvider");
62
+ return context;
63
+ };
64
+ export { useResponsive as a, useLocales as b, useResponsiveDesktop as u };
@@ -1,5 +0,0 @@
1
- /// <reference types="react" />
2
- import { NoAuthModuleLayoutContextProps, NoAuthModuleLayoutProviderProps } from './types';
3
- declare const ModuleContext: import("react").Context<NoAuthModuleLayoutContextProps>;
4
- declare function ModuleProvider(props: NoAuthModuleLayoutProviderProps): JSX.Element;
5
- export { ModuleProvider, ModuleContext };
@@ -1,12 +0,0 @@
1
- import { ReactNode } from 'react';
2
- export interface DomainStyleOptions {
3
- company_logo_small_url: string;
4
- company_logo_normal_url: string;
5
- }
6
- export interface NoAuthModuleLayoutProviderProps {
7
- moduleId: string;
8
- children: ReactNode;
9
- }
10
- export interface NoAuthModuleLayoutContextProps extends Pick<NoAuthModuleLayoutProviderProps, 'moduleId'> {
11
- styleOptions: DomainStyleOptions;
12
- }