@m4l/graphics 0.1.11 → 0.1.12
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/components/ProgressBarStyle/index.d.ts +2 -1
- package/contexts/HostThemeContext/index.d.ts +1 -1
- package/contexts/LocalesContext/index.3fcfbe02.js +108 -0
- package/contexts/LocalesContext/index.d.ts +1 -1
- package/contexts/{index.a0e7894e.js → index.7975256a.js} +1 -1
- package/hooks/{index.2942e1ab.js → index.c9dba2ff.js} +1 -1
- package/hooks/useLocales/{index.ca679977.js → index.8154a401.js} +1 -1
- package/index.js +3 -3
- package/package.json +1 -1
- package/contexts/LocalesContext/index.ca1e2149.js +0 -111
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare function ProgressBarStyle(): JSX.Element;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { HostThemeProviderProps } from './types';
|
|
3
3
|
declare const HostThemeContext: import("react").Context<import("./types").HostThemeType | null>;
|
|
4
|
-
declare function HostThemeProvider(props: HostThemeProviderProps):
|
|
4
|
+
declare function HostThemeProvider(props: HostThemeProviderProps): JSX.Element;
|
|
5
5
|
export { HostThemeProvider, HostThemeContext };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { createContext as k, useState as _, useCallback as x, useEffect as L } from "react";
|
|
2
|
+
import { AdapterDateFns as F } from "@mui/x-date-pickers/AdapterDateFns";
|
|
3
|
+
import { LocalizationProvider as U } from "@mui/x-date-pickers";
|
|
4
|
+
import { useEnvironment as P, useNetwork as I, useHostTools as j, useLocalStorageWithListener as w, EmitEvents as u } from "@m4l/core";
|
|
5
|
+
import S from "date-fns/locale/en-US";
|
|
6
|
+
import { jsx as g } from "react/jsx-runtime";
|
|
7
|
+
async function B(t, e, o) {
|
|
8
|
+
const s = f(t), r = { ...t };
|
|
9
|
+
let i;
|
|
10
|
+
return s === "es" ? i = (await import("date-fns/locale/es")).default : s === "fr" ? i = (await import("date-fns/locale/fr")).default : s === "en-US" ? i = S : (i = S, r.lang = "en", r.script = void 0, r.region = "US", r.url_icon = `${e}/${o}/frontend/commons/assets/icons/langs/lang_en.svg`, r.name = "English US*"), {
|
|
11
|
+
...r,
|
|
12
|
+
module: i,
|
|
13
|
+
localeString: f(r)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function f(t) {
|
|
17
|
+
let e = t.lang;
|
|
18
|
+
return t.script && t.script !== "" && (e = e + "-" + t.script), t.region && t.region !== "" && (e = e + "-" + t.region), e;
|
|
19
|
+
}
|
|
20
|
+
function y(t) {
|
|
21
|
+
try {
|
|
22
|
+
const e = new Intl.Locale(t);
|
|
23
|
+
return {
|
|
24
|
+
lang: e.language || "",
|
|
25
|
+
script: e.script,
|
|
26
|
+
region: e.region
|
|
27
|
+
};
|
|
28
|
+
} catch {
|
|
29
|
+
return {
|
|
30
|
+
lang: "en",
|
|
31
|
+
script: void 0,
|
|
32
|
+
region: "US"
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const G = k(null);
|
|
37
|
+
function J(t) {
|
|
38
|
+
const {
|
|
39
|
+
children: e,
|
|
40
|
+
isMicroFrontEnd: o,
|
|
41
|
+
localeHost: s,
|
|
42
|
+
getLocaleFromNetwork: r
|
|
43
|
+
} = t;
|
|
44
|
+
if (o && !s)
|
|
45
|
+
throw Error("Must set localeHost in microfrontend");
|
|
46
|
+
if (!o && !r)
|
|
47
|
+
throw Error("Must set getLocaleFromNetwork in host");
|
|
48
|
+
const {
|
|
49
|
+
domain_token: i,
|
|
50
|
+
host_static_assets: v,
|
|
51
|
+
environment_assets: h
|
|
52
|
+
} = P(), {
|
|
53
|
+
networkOperation: C
|
|
54
|
+
} = I(), {
|
|
55
|
+
events_add_listener: N,
|
|
56
|
+
events_remove_listener: T,
|
|
57
|
+
events_emit: H
|
|
58
|
+
} = j(), [a, d] = _(() => {
|
|
59
|
+
if (o)
|
|
60
|
+
return s;
|
|
61
|
+
}), [l, m] = w("localeHost", navigator.language), [M, A] = _(""), p = x((n) => {
|
|
62
|
+
d(n);
|
|
63
|
+
}, []);
|
|
64
|
+
if (L(() => (o && N(u.EMMIT_EVENT_HOST_LOCALE_CHANGE, p), () => {
|
|
65
|
+
o && T(u.EMMIT_EVENT_HOST_LOCALE_CHANGE, p);
|
|
66
|
+
}), []), L(() => {
|
|
67
|
+
let n = !0;
|
|
68
|
+
if (!o && !!r && !(l === M && l !== ""))
|
|
69
|
+
return C({
|
|
70
|
+
method: "POST",
|
|
71
|
+
endPoint: "na/locales",
|
|
72
|
+
data: {
|
|
73
|
+
...y(l),
|
|
74
|
+
domain_token: i
|
|
75
|
+
}
|
|
76
|
+
}).then((E) => {
|
|
77
|
+
n && r(E.data, v, h).then((c) => {
|
|
78
|
+
d(c), A(c.localeString), l !== c.localeString && m(c.localeString), H(u.EMMIT_EVENT_HOST_LOCALE_CHANGE, c);
|
|
79
|
+
});
|
|
80
|
+
}).finally(() => {
|
|
81
|
+
}), function() {
|
|
82
|
+
n = !1;
|
|
83
|
+
};
|
|
84
|
+
}, [l]), !a)
|
|
85
|
+
return /* @__PURE__ */ g("div", {});
|
|
86
|
+
const O = (n) => {
|
|
87
|
+
(n.lang !== a.lang || n.script !== a.script || n.region !== a.region) && m(f(n));
|
|
88
|
+
};
|
|
89
|
+
return /* @__PURE__ */ g(G.Provider, {
|
|
90
|
+
value: {
|
|
91
|
+
currentLocale: a,
|
|
92
|
+
onChangeLocale: O
|
|
93
|
+
},
|
|
94
|
+
children: /* @__PURE__ */ g(U, {
|
|
95
|
+
dateAdapter: F,
|
|
96
|
+
adapterLocale: a.module,
|
|
97
|
+
dateFormats: {
|
|
98
|
+
hours24h: "23"
|
|
99
|
+
},
|
|
100
|
+
children: e
|
|
101
|
+
})
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
export {
|
|
105
|
+
G as L,
|
|
106
|
+
J as a,
|
|
107
|
+
B as g
|
|
108
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { LocalesProviderProps, LocalesContextProps } from './types';
|
|
3
3
|
declare const LocalesContext: import("react").Context<LocalesContextProps | null>;
|
|
4
|
-
declare function LocalesProvider(props: LocalesProviderProps):
|
|
4
|
+
declare function LocalesProvider(props: LocalesProviderProps): JSX.Element;
|
|
5
5
|
export { LocalesProvider, LocalesContext };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useRef as n, useEffect as s, useState as r } from "react";
|
|
2
2
|
import "@mui/material/styles";
|
|
3
3
|
import "@mui/material/useMediaQuery";
|
|
4
|
-
import "../contexts/LocalesContext/index.
|
|
4
|
+
import "../contexts/LocalesContext/index.3fcfbe02.js";
|
|
5
5
|
import "../contexts/HostThemeContext/index.a6a62c70.js";
|
|
6
6
|
function a() {
|
|
7
7
|
const e = n(!0);
|
package/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { P as l } from "./components/ProgressBarStyle/index.fb6fd9ed.js";
|
|
2
|
-
import { L as n, a as c, g as P } from "./contexts/LocalesContext/index.
|
|
2
|
+
import { L as n, a as c, g as P } from "./contexts/LocalesContext/index.3fcfbe02.js";
|
|
3
3
|
import { H as C, a as g } from "./contexts/HostThemeContext/index.a6a62c70.js";
|
|
4
4
|
import { u as L, a as T } from "./hooks/useResponsive/index.fc5e1b4f.js";
|
|
5
|
-
import { u as w, a as O } from "./hooks/index.
|
|
6
|
-
import { u as S } from "./hooks/useLocales/index.
|
|
5
|
+
import { u as w, a as O } from "./hooks/index.c9dba2ff.js";
|
|
6
|
+
import { u as S } from "./hooks/useLocales/index.8154a401.js";
|
|
7
7
|
import { u as F } from "./hooks/useHostTheme/index.1c8e4ad7.js";
|
|
8
8
|
import { d as z } from "./theme/defaultThemeOptions.9b9e7503.js";
|
|
9
9
|
import { c as D, s as G } from "./theme/shadows.bf8dc290.js";
|
package/package.json
CHANGED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { createContext as T, useState as k, useCallback as w, useEffect as E } from "react";
|
|
2
|
-
import { AdapterDateFns as A } from "@mui/x-date-pickers/AdapterDateFns";
|
|
3
|
-
import { LocalizationProvider as F } from "@mui/x-date-pickers";
|
|
4
|
-
import { useEnvironment as O, useNetwork as P, useHostTools as U, useLocalStorage as j, EmitEvents as h, setLocalStorage as x } from "@m4l/core";
|
|
5
|
-
import v from "date-fns/locale/en-US";
|
|
6
|
-
import { jsx as g } from "react/jsx-runtime";
|
|
7
|
-
async function q(o, t, n) {
|
|
8
|
-
const l = u(o), e = { ...o };
|
|
9
|
-
console.log("baseLocale initia", o, t, n);
|
|
10
|
-
let i;
|
|
11
|
-
return l === "es" ? i = (await import("date-fns/locale/es")).default : l === "fr" ? i = (await import("date-fns/locale/fr")).default : l === "en-US" ? i = v : (i = v, e.lang = "en", e.script = void 0, e.region = "US", e.url_icon = `${t}/${n}/frontend/commons/assets/icons/langs/lang_en.svg`, e.name = "English US*"), console.log("getLocale", l, e, i), {
|
|
12
|
-
...e,
|
|
13
|
-
module: i,
|
|
14
|
-
localeString: u(e)
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function u(o) {
|
|
18
|
-
let t = o.lang;
|
|
19
|
-
return o.script && o.script !== "" && (t = t + "-" + o.script), o.region && o.region !== "" && (t = t + "-" + o.region), console.log(
|
|
20
|
-
"joinLocale",
|
|
21
|
-
o.region && o.region !== "",
|
|
22
|
-
o.region,
|
|
23
|
-
t + "-" + o.region,
|
|
24
|
-
t,
|
|
25
|
-
o
|
|
26
|
-
), t;
|
|
27
|
-
}
|
|
28
|
-
function $(o) {
|
|
29
|
-
console.log("splitLocale", o);
|
|
30
|
-
const t = new Intl.Locale(o);
|
|
31
|
-
return {
|
|
32
|
-
lang: t.language || "",
|
|
33
|
-
script: t.script,
|
|
34
|
-
region: t.region
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
const I = T(null);
|
|
38
|
-
function B(o) {
|
|
39
|
-
const {
|
|
40
|
-
children: t,
|
|
41
|
-
isMicroFrontEnd: n,
|
|
42
|
-
localeHost: l,
|
|
43
|
-
getLocaleFromNetwork: e
|
|
44
|
-
} = o;
|
|
45
|
-
if (n && !l)
|
|
46
|
-
throw Error("Must set localeHost in microfrontend");
|
|
47
|
-
if (!n && !e)
|
|
48
|
-
throw Error("Must set getLocaleFromNetwork in host");
|
|
49
|
-
const {
|
|
50
|
-
domain_token: i,
|
|
51
|
-
host_static_assets: f,
|
|
52
|
-
environment_assets: d
|
|
53
|
-
} = O(), {
|
|
54
|
-
networkOperation: S
|
|
55
|
-
} = P(), {
|
|
56
|
-
events_add_listener: L,
|
|
57
|
-
events_remove_listener: H,
|
|
58
|
-
events_emit: C
|
|
59
|
-
} = U(), [s, m] = k(() => {
|
|
60
|
-
if (n)
|
|
61
|
-
return l;
|
|
62
|
-
}), [p, N] = j("localeHost", navigator.language), _ = w((r) => {
|
|
63
|
-
m(r);
|
|
64
|
-
}, []);
|
|
65
|
-
if (E(() => (n && L(h.EMMIT_EVENT_HOST_LOCALE_CHANGE, _), () => {
|
|
66
|
-
n && H("host_theme_change", _);
|
|
67
|
-
}), []), E(() => {
|
|
68
|
-
let r = !0;
|
|
69
|
-
if (!n && !!e)
|
|
70
|
-
return console.log("newLocaleString", `${f}/${d}/frontend/commons/assets/icons/langs/lang_en.svg`), S({
|
|
71
|
-
method: "POST",
|
|
72
|
-
endPoint: "na/locales",
|
|
73
|
-
data: {
|
|
74
|
-
...$(p),
|
|
75
|
-
domain_token: i
|
|
76
|
-
}
|
|
77
|
-
}).then((c) => {
|
|
78
|
-
console.log("Response", c), r && e(c.data, f, d).then((a) => {
|
|
79
|
-
m(a), x("localeHost", a.localeString), console.log("Set localeHost", a.localeString), C(h.EMMIT_EVENT_HOST_LOCALE_CHANGE, a);
|
|
80
|
-
});
|
|
81
|
-
}).finally(() => {
|
|
82
|
-
}), function() {
|
|
83
|
-
r = !1;
|
|
84
|
-
};
|
|
85
|
-
}, [p]), !s)
|
|
86
|
-
return /* @__PURE__ */ g("div", {
|
|
87
|
-
children: "Cargando localeHost"
|
|
88
|
-
});
|
|
89
|
-
const M = (r) => {
|
|
90
|
-
(r.lang !== s.lang || r.script !== s.script || r.region !== s.region) && N(u(r));
|
|
91
|
-
};
|
|
92
|
-
return /* @__PURE__ */ g(I.Provider, {
|
|
93
|
-
value: {
|
|
94
|
-
currentLocale: s,
|
|
95
|
-
onChangeLocale: M
|
|
96
|
-
},
|
|
97
|
-
children: /* @__PURE__ */ g(F, {
|
|
98
|
-
dateAdapter: A,
|
|
99
|
-
adapterLocale: s.module,
|
|
100
|
-
dateFormats: {
|
|
101
|
-
hours24h: "23"
|
|
102
|
-
},
|
|
103
|
-
children: t
|
|
104
|
-
})
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
export {
|
|
108
|
-
I as L,
|
|
109
|
-
B as a,
|
|
110
|
-
q as g
|
|
111
|
-
};
|