@m4l/layouts 0.1.39 → 0.1.40

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.
@@ -1,130 +1,160 @@
1
- import { createContext as T, useReducer as y, useEffect as d } from "react";
2
- import { useHostTools as E, useNetwork as S, useEnvironment as v, useLocalStorageWithListener as N, EmitEvents as O, getLocalStorage as w, setLocalStorage as r } from "@m4l/core";
3
- import { jsx as D } from "react/jsx-runtime";
4
- var n = /* @__PURE__ */ ((e) => (e.Initial = "INITIALIZE", e.Login = "LOGIN", e.Logout = "LOGOUT", e))(n || {});
5
- const _ = {
6
- isAuthenticated: !1,
7
- isInitialized: !1,
1
+ import { createContext, useReducer, useEffect } from "react";
2
+ import { useHostTools, useNetwork, useEnvironment, useLocalStorageWithListener, EmitEvents, getLocalStorage, setLocalStorage } from "@m4l/core";
3
+ import { jsx } from "react/jsx-runtime";
4
+ var EnumTypes = /* @__PURE__ */ ((EnumTypes2) => {
5
+ EnumTypes2["Initial"] = "INITIALIZE";
6
+ EnumTypes2["Login"] = "LOGIN";
7
+ EnumTypes2["Logout"] = "LOGOUT";
8
+ return EnumTypes2;
9
+ })(EnumTypes || {});
10
+ const initialState = {
11
+ isAuthenticated: false,
12
+ isInitialized: false,
8
13
  user: null
9
- }, P = (e, t) => {
10
- switch (t.type) {
14
+ };
15
+ const JWTReducer = (state, action) => {
16
+ switch (action.type) {
11
17
  case "INITIALIZE":
12
18
  return {
13
- isAuthenticated: t.payload.isAuthenticated,
14
- isInitialized: !0,
15
- user: t.payload.user
19
+ isAuthenticated: action.payload.isAuthenticated,
20
+ isInitialized: true,
21
+ user: action.payload.user
16
22
  };
17
23
  case "LOGIN":
18
24
  return {
19
- ...e,
20
- isAuthenticated: !0,
21
- user: t.payload.user
25
+ ...state,
26
+ isAuthenticated: true,
27
+ user: action.payload.user
22
28
  };
23
29
  case "LOGOUT":
24
30
  return {
25
- ...e,
26
- isAuthenticated: !1,
31
+ ...state,
32
+ isAuthenticated: false,
27
33
  user: null
28
34
  };
29
35
  default:
30
- return e;
36
+ return state;
31
37
  }
32
- }, x = T(null);
33
- function z(e) {
34
- e({
35
- type: n.Initial,
38
+ };
39
+ const AuthContext = createContext(null);
40
+ function dispatchInitial(dispatch) {
41
+ dispatch({
42
+ type: EnumTypes.Initial,
36
43
  payload: {
37
- isAuthenticated: !1,
44
+ isAuthenticated: false,
38
45
  user: null
39
46
  }
40
47
  });
41
48
  }
42
- function R(e) {
49
+ function AuthProvider(props) {
50
+ const {
51
+ children
52
+ } = props;
53
+ const [state, dispatch] = useReducer(JWTReducer, initialState);
54
+ const {
55
+ events_add_listener
56
+ } = useHostTools();
43
57
  const {
44
- children: t
45
- } = e, [h, s] = y(P, _), {
46
- events_add_listener: I
47
- } = E(), {
48
- networkOperation: u
49
- } = S(), {
50
- domain_token: m
51
- } = v(), [f, l] = N(
58
+ networkOperation
59
+ } = useNetwork();
60
+ const {
61
+ domain_token
62
+ } = useEnvironment();
63
+ const [nextValSession, setNextValSession] = useLocalStorageWithListener(
52
64
  "vSession",
53
65
  new Date().getTime() + ""
54
66
  );
55
- d(() => {
56
- (async () => {
57
- u({
67
+ useEffect(() => {
68
+ const initialize = async () => {
69
+ networkOperation({
58
70
  method: "GET",
59
- endPoint: "auth/login",
71
+ endPoint: `auth/login`,
60
72
  parms: {
61
- user_data: !0
73
+ user_data: true
62
74
  },
63
- checkUnAuthorized: !1
64
- }).then((a) => {
65
- s({
66
- type: n.Initial,
75
+ checkUnAuthorized: false
76
+ }).then((response) => {
77
+ dispatch({
78
+ type: EnumTypes.Initial,
67
79
  payload: {
68
- isAuthenticated: !0,
69
- user: a.user
80
+ isAuthenticated: true,
81
+ user: response.user
70
82
  }
71
- }), w("userData", {
72
- email: a.user.email,
73
- remember: !0
74
- })?.email !== a.user.email && r("userData", {
75
- email: a.user.email
76
- }, !0);
83
+ });
84
+ const useSaved = getLocalStorage("userData", {
85
+ email: response.user.email,
86
+ remember: true
87
+ });
88
+ if (useSaved?.email !== response.user.email) {
89
+ setLocalStorage("userData", {
90
+ email: response.user.email
91
+ }, true);
92
+ }
77
93
  }).catch(() => {
78
- z(s);
94
+ dispatchInitial(dispatch);
79
95
  });
80
- })();
81
- }, [f]);
82
- const g = async (i, a, o) => {
83
- await u({
84
- endPoint: "auth/login",
96
+ };
97
+ initialize();
98
+ }, [nextValSession]);
99
+ const login = async (email, password, remember) => {
100
+ await networkOperation({
101
+ endPoint: `auth/login`,
85
102
  method: "POST",
86
103
  data: {
87
- email: i,
88
- password: a,
89
- domain_token: m
104
+ email,
105
+ password,
106
+ domain_token
107
+ }
108
+ }).then((response) => {
109
+ const user = response.data;
110
+ if (remember) {
111
+ setLocalStorage("userData", {
112
+ email,
113
+ remember
114
+ });
115
+ } else {
116
+ setLocalStorage("userData", {
117
+ email: "",
118
+ remember
119
+ });
90
120
  }
91
- }).then((A) => {
92
- const L = A.data;
93
- o ? r("userData", {
94
- email: i,
95
- remember: o
96
- }) : r("userData", {
97
- email: "",
98
- remember: o
99
- }), s({
100
- type: n.Login,
121
+ dispatch({
122
+ type: EnumTypes.Login,
101
123
  payload: {
102
- user: L
124
+ user
103
125
  }
104
- }), l(new Date().getTime() + "");
126
+ });
127
+ setNextValSession(new Date().getTime() + "");
128
+ });
129
+ };
130
+ const logout = async (isAuthenticated) => {
131
+ if (isAuthenticated) {
132
+ await networkOperation({
133
+ endPoint: `auth/logout`,
134
+ method: "POST"
135
+ });
136
+ }
137
+ dispatch({
138
+ type: EnumTypes.Logout
105
139
  });
106
- }, c = async (i) => {
107
- i && await u({
108
- endPoint: "auth/logout",
109
- method: "POST"
110
- }), s({
111
- type: n.Logout
112
- }), l(new Date().getTime() + "");
113
- }, p = () => {
114
- c(!1);
140
+ setNextValSession(new Date().getTime() + "");
141
+ };
142
+ const onNetserviceUnautorized = () => {
143
+ logout(false);
115
144
  };
116
- return d(() => {
117
- I(O.EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED, p);
118
- }, []), /* @__PURE__ */ D(x.Provider, {
145
+ useEffect(() => {
146
+ events_add_listener(EmitEvents.EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED, onNetserviceUnautorized);
147
+ }, []);
148
+ return /* @__PURE__ */ jsx(AuthContext.Provider, {
119
149
  value: {
120
- ...h,
121
- login: g,
122
- logout: c
150
+ ...state,
151
+ login,
152
+ logout
123
153
  },
124
- children: t
154
+ children
125
155
  });
126
156
  }
127
157
  export {
128
- R as A,
129
- x as a
158
+ AuthProvider as A,
159
+ AuthContext as a
130
160
  };
@@ -1,11 +1,11 @@
1
- import { useContext as o } from "react";
2
- import { a as e } from "../../contexts/AuthContext/index.6f966215.js";
3
- const n = () => {
4
- const t = o(e);
5
- if (!t)
1
+ import { useContext } from "react";
2
+ import { a as AuthContext } from "../../contexts/AuthContext/index.6f966215.js";
3
+ const useAuth = () => {
4
+ const context = useContext(AuthContext);
5
+ if (!context)
6
6
  throw new Error("Auth context must be use inside AuthProvider");
7
- return t;
7
+ return context;
8
8
  };
9
9
  export {
10
- n as u
10
+ useAuth as u
11
11
  };
@@ -1,6 +1,6 @@
1
- import { useContext as t } from "react";
2
- import { M as e } from "../../layouts/MasterDetailLayout/index.bca0fce5.js";
3
- const s = () => t(e);
1
+ import { useContext } from "react";
2
+ import { M as MasterDetailContext } from "../../layouts/MasterDetailLayout/index.bca0fce5.js";
3
+ const useMasterDetail = () => useContext(MasterDetailContext);
4
4
  export {
5
- s as u
5
+ useMasterDetail as u
6
6
  };
@@ -1,11 +1,11 @@
1
- import { useContext as o } from "react";
2
- import { M as t } from "../../layouts/ModuleLayout/index.850f7dcf.js";
3
- const n = () => {
4
- const e = o(t);
5
- if (!e)
1
+ import { useContext } from "react";
2
+ import { M as ModuleContext } from "../../layouts/ModuleLayout/index.850f7dcf.js";
3
+ const useModule = () => {
4
+ const context = useContext(ModuleContext);
5
+ if (!context)
6
6
  throw new Error("useModule context must be use inside ModuleContext");
7
- return e;
7
+ return context;
8
8
  };
9
9
  export {
10
- n as u
10
+ useModule as u
11
11
  };
package/index.js CHANGED
@@ -1,13 +1,13 @@
1
- import { M as f } from "./components/MFIsolationApp/index.e36cf308.js";
2
- import { M as D } from "./components/MFHostApp/index.420c2626.js";
3
- import { B as L } from "./components/BaseModule/index.6309486a.js";
4
- import { a as g, A as h } from "./contexts/AuthContext/index.6f966215.js";
5
- import { a as N, d as B, g as F } from "./layouts/ModuleLayout/index.850f7dcf.js";
6
- import { a as H, d as I, g as P } from "./layouts/MasterDetailLayout/index.bca0fce5.js";
7
- import { N as j, d as k, g as q } from "./layouts/NoAuthModuleLayout/index.eabf38c1.js";
8
- import { u as z } from "./hooks/useMasterDetail/index.927c0c26.js";
9
- import { u as G } from "./hooks/useAuth/index.cb6a3420.js";
10
- import { u as K } from "./hooks/useModule/index.edcd7b28.js";
1
+ import { M } from "./components/MFIsolationApp/index.e36cf308.js";
2
+ import { M as M2 } from "./components/MFHostApp/index.420c2626.js";
3
+ import { B } from "./components/BaseModule/index.6309486a.js";
4
+ import { a, A } from "./contexts/AuthContext/index.6f966215.js";
5
+ import { a as a2, d, g } from "./layouts/ModuleLayout/index.850f7dcf.js";
6
+ import { a as a3, d as d2, g as g2 } from "./layouts/MasterDetailLayout/index.bca0fce5.js";
7
+ import { N, d as d3, g as g3 } from "./layouts/NoAuthModuleLayout/index.eabf38c1.js";
8
+ import { u } from "./hooks/useMasterDetail/index.927c0c26.js";
9
+ import { u as u2 } from "./hooks/useAuth/index.cb6a3420.js";
10
+ import { u as u3 } from "./hooks/useModule/index.edcd7b28.js";
11
11
  import "react";
12
12
  import "react-router-dom";
13
13
  import "react-toastify";
@@ -22,21 +22,21 @@ import "nprogress";
22
22
  import "@m4l/components";
23
23
  import "@mui/material/styles";
24
24
  export {
25
- g as AuthContext,
26
- h as AuthProvider,
27
- L as BaseModule,
28
- D as MFHostApp,
29
- f as MFIsolationApp,
30
- H as MasterDetailLayout,
31
- N as ModuleLayout,
32
- j as NoAuthModuleLayout,
33
- I as defaultMasterDetailDictionary,
34
- B as defaultModuleLayoutDictionary,
35
- k as defaultNoAuthModuleLayoutDictionary,
36
- P as getMasterDetailLayoutComponentsDictionary,
37
- F as getModuleLayoutComponentsDictionary,
38
- q as getNoAuthModuleLayoutComponentsDictionary,
39
- G as useAuth,
40
- z as useMasterDetail,
41
- K as useModule
25
+ a as AuthContext,
26
+ A as AuthProvider,
27
+ B as BaseModule,
28
+ M2 as MFHostApp,
29
+ M as MFIsolationApp,
30
+ a3 as MasterDetailLayout,
31
+ a2 as ModuleLayout,
32
+ N as NoAuthModuleLayout,
33
+ d2 as defaultMasterDetailDictionary,
34
+ d as defaultModuleLayoutDictionary,
35
+ d3 as defaultNoAuthModuleLayoutDictionary,
36
+ g2 as getMasterDetailLayoutComponentsDictionary,
37
+ g as getModuleLayoutComponentsDictionary,
38
+ g3 as getNoAuthModuleLayoutComponentsDictionary,
39
+ u2 as useAuth,
40
+ u as useMasterDetail,
41
+ u3 as useModule
42
42
  };
@@ -1,108 +1,126 @@
1
- import { createContext as w, useState as h, useRef as D, useMemo as m, useCallback as g } from "react";
2
- import { voidFunction as k, useEnvironment as S, useModuleDictionary as $ } from "@m4l/core";
3
- import { WindowBase as z, SplitLayout as P } from "@m4l/components";
4
- import { a as A, g as I } from "../ModuleLayout/index.850f7dcf.js";
5
- import { jsx as c } from "react/jsx-runtime";
6
- import { useResponsiveDesktop as L } from "@m4l/graphics";
7
- const N = {
1
+ import { createContext, useState, useRef, useMemo, useCallback } from "react";
2
+ import { voidFunction, useEnvironment, useModuleDictionary } from "@m4l/core";
3
+ import { WindowBase, SplitLayout } from "@m4l/components";
4
+ import { a as ModuleLayout, g as getModuleLayoutComponentsDictionary } from "../ModuleLayout/index.850f7dcf.js";
5
+ import { jsx } from "react/jsx-runtime";
6
+ import { useResponsiveDesktop } from "@m4l/graphics";
7
+ const initialState = {
8
8
  masterSelection: void 0,
9
- onChangeMasterSelection: k
10
- }, x = w(N);
11
- function R(n) {
9
+ onChangeMasterSelection: voidFunction
10
+ };
11
+ const MasterDetailContext = createContext(initialState);
12
+ function MasterDetailProvider(props) {
12
13
  const {
13
- children: a
14
- } = n, [s, t] = h(void 0);
15
- return /* @__PURE__ */ c(x.Provider, {
14
+ children
15
+ } = props;
16
+ const [masterSelection, setMasterSelection] = useState(void 0);
17
+ return /* @__PURE__ */ jsx(MasterDetailContext.Provider, {
16
18
  value: {
17
- masterSelection: s,
18
- onChangeMasterSelection: t
19
+ masterSelection,
20
+ onChangeMasterSelection: setMasterSelection
19
21
  },
20
- children: a
22
+ children
21
23
  });
22
24
  }
23
- function V(n, a = [], s, t) {
24
- let o = t !== void 0 && t ? [...n] : [s];
25
- return o = a.concat(o), o;
25
+ function getTotalModuleActions(splitActions, moduleActions = [], viewDetailAction, isDesktop) {
26
+ let totalActions = isDesktop !== void 0 && isDesktop ? [...splitActions] : [viewDetailAction];
27
+ totalActions = moduleActions.concat(totalActions);
28
+ return totalActions;
26
29
  }
27
- function T(n) {
30
+ function MasterDetailLayout(props) {
31
+ const {
32
+ moduleId,
33
+ masterComponent,
34
+ detailComponent,
35
+ moduleActions,
36
+ version
37
+ } = props;
28
38
  const {
29
- moduleId: a,
30
- masterComponent: s,
31
- detailComponent: t,
32
- moduleActions: o,
33
- version: M
34
- } = n, {
35
- host_static_assets: l,
36
- environment_assets: i
37
- } = S(), [r, C] = h("vertical"), d = L(), p = D(null), {
38
- getLabel: e
39
- } = $(), v = m(() => [{
40
- urlIcon: `${l}/${i}/frontend/components/masterdetaillayout/assets/icons/split_vertical.svg`,
41
- onClick: () => u("vertical"),
39
+ host_static_assets,
40
+ environment_assets
41
+ } = useEnvironment();
42
+ const [splitPosition, setSplitPosition] = useState("vertical");
43
+ const isDesktop = useResponsiveDesktop();
44
+ const moduleLayoutRef = useRef(null);
45
+ const {
46
+ getLabel
47
+ } = useModuleDictionary();
48
+ const splitActions = useMemo(() => [{
49
+ urlIcon: `${host_static_assets}/${environment_assets}/frontend/components/masterdetaillayout/assets/icons/split_vertical.svg`,
50
+ onClick: () => onChangePostionInternal("vertical"),
42
51
  visibility: "main",
43
- label: e("master_detail_layout.split_vertical"),
52
+ label: getLabel("master_detail_layout.split_vertical"),
44
53
  tag: "vertical",
45
54
  className: "splitactions",
46
- disabled: r === "vertical",
55
+ disabled: splitPosition === "vertical",
47
56
  key: "vertical"
48
57
  }, {
49
- urlIcon: `${l}/${i}/frontend/components/masterdetaillayout/assets/icons/split_horizontal.svg`,
50
- onClick: () => u("horizontal"),
58
+ urlIcon: `${host_static_assets}/${environment_assets}/frontend/components/masterdetaillayout/assets/icons/split_horizontal.svg`,
59
+ onClick: () => onChangePostionInternal("horizontal"),
51
60
  visibility: "main",
52
- label: e("master_detail_layout.split_horizontal"),
61
+ label: getLabel("master_detail_layout.split_horizontal"),
53
62
  tag: "horizontal",
54
63
  className: "splitactions",
55
- disabled: r === "horizontal",
64
+ disabled: splitPosition === "horizontal",
56
65
  key: "horizontal"
57
66
  }, {
58
- urlIcon: `${l}/${i}/frontend/components/masterdetaillayout/assets/icons/no_split.svg`,
59
- onClick: () => u("none"),
67
+ urlIcon: `${host_static_assets}/${environment_assets}/frontend/components/masterdetaillayout/assets/icons/no_split.svg`,
68
+ onClick: () => onChangePostionInternal("none"),
60
69
  visibility: "main",
61
- label: e("master_detail_layout.no_split"),
70
+ label: getLabel("master_detail_layout.no_split"),
62
71
  tag: "none",
63
72
  className: "splitactions",
64
- disabled: r === "none",
73
+ disabled: splitPosition === "none",
65
74
  key: "none"
66
- }], [e, r]), u = g((f) => {
67
- C(f);
68
- }, []), y = g(() => {
69
- p.current?.openModal({
75
+ }], [getLabel, splitPosition]);
76
+ const onChangePostionInternal = useCallback((newPostion) => {
77
+ setSplitPosition(newPostion);
78
+ }, []);
79
+ const onClickViewDetail = useCallback(() => {
80
+ moduleLayoutRef.current?.openModal({
70
81
  initialWidth: 500,
71
82
  initialHeigth: 680,
72
- window: /* @__PURE__ */ c(z, {
73
- urlIcon: `${l}/${i}/frontend/components/masterdetaillayout/assets/icons/view_detail.svg`,
74
- title: e("master_detail_layout.view_detail"),
75
- children: typeof t == "function" ? t({}) : t
83
+ window: /* @__PURE__ */ jsx(WindowBase, {
84
+ urlIcon: `${host_static_assets}/${environment_assets}/frontend/components/masterdetaillayout/assets/icons/view_detail.svg`,
85
+ title: getLabel("master_detail_layout.view_detail"),
86
+ children: typeof detailComponent === "function" ? detailComponent({}) : detailComponent
76
87
  })
77
88
  });
78
- }, [t, e]), _ = m(() => ({
79
- urlIcon: `${l}/${i}/frontend/components/masterdetaillayout/assets/icons/view_detail.svg`,
80
- onClick: y,
81
- disabled: !1,
82
- visibility: "allways",
83
- label: e("master_detail_layout.view_detail"),
84
- tag: "none",
85
- className: "",
86
- key: "detail"
87
- }), [i, y]), b = m(() => V(v, o, _, d), [v, o, d, _]);
88
- return /* @__PURE__ */ c(R, {
89
- children: /* @__PURE__ */ c(A, {
90
- ref: p,
91
- moduleId: a,
92
- moduleActions: b,
93
- version: M,
94
- children: /* @__PURE__ */ c(P, {
95
- splitPosition: d ? r : "none",
96
- firstPart: s,
97
- secondPart: t
89
+ }, [detailComponent, getLabel]);
90
+ const viewDetailAction = useMemo(() => {
91
+ return {
92
+ urlIcon: `${host_static_assets}/${environment_assets}/frontend/components/masterdetaillayout/assets/icons/view_detail.svg`,
93
+ onClick: onClickViewDetail,
94
+ disabled: false,
95
+ visibility: "allways",
96
+ label: getLabel("master_detail_layout.view_detail"),
97
+ tag: "none",
98
+ className: "",
99
+ key: "detail"
100
+ };
101
+ }, [environment_assets, onClickViewDetail]);
102
+ const finalModuleActions = useMemo(() => {
103
+ const actions = getTotalModuleActions(splitActions, moduleActions, viewDetailAction, isDesktop);
104
+ return actions;
105
+ }, [splitActions, moduleActions, isDesktop, viewDetailAction]);
106
+ return /* @__PURE__ */ jsx(MasterDetailProvider, {
107
+ children: /* @__PURE__ */ jsx(ModuleLayout, {
108
+ ref: moduleLayoutRef,
109
+ moduleId,
110
+ moduleActions: finalModuleActions,
111
+ version,
112
+ children: /* @__PURE__ */ jsx(SplitLayout, {
113
+ splitPosition: isDesktop ? splitPosition : "none",
114
+ firstPart: masterComponent,
115
+ secondPart: detailComponent
98
116
  })
99
117
  })
100
118
  });
101
119
  }
102
- function q() {
103
- return ["master_detail_layout"].concat(I());
120
+ function getMasterDetailLayoutComponentsDictionary() {
121
+ return ["master_detail_layout"].concat(getModuleLayoutComponentsDictionary());
104
122
  }
105
- const G = {
123
+ const defaultMasterDetailDictionary = {
106
124
  master_detail_layout: {
107
125
  split_vertical: "Split vertically",
108
126
  split_horizontal: "Split horizontally",
@@ -111,8 +129,8 @@ const G = {
111
129
  }
112
130
  };
113
131
  export {
114
- x as M,
115
- T as a,
116
- G as d,
117
- q as g
132
+ MasterDetailContext as M,
133
+ MasterDetailLayout as a,
134
+ defaultMasterDetailDictionary as d,
135
+ getMasterDetailLayoutComponentsDictionary as g
118
136
  };