@m4l/graphics 0.1.10 → 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.
@@ -0,0 +1,50 @@
1
+ import { createContext as H, useState as E, useMemo as v, useCallback as M, useEffect as c } from "react";
2
+ import { CssBaseline as C } from "@mui/material";
3
+ import { createTheme as O, StyledEngineProvider as N, ThemeProvider as S } from "@mui/material/styles";
4
+ import { useHostTools as x, EmitEvents as o } from "@m4l/core";
5
+ import { jsx as n, jsxs as F } from "react/jsx-runtime";
6
+ const I = H(null);
7
+ function b(l) {
8
+ const {
9
+ children: h,
10
+ hostThemeOptions: t,
11
+ fnComponentsOverrides: i,
12
+ isMicroFrontEnd: s
13
+ } = l, [r, m] = E(t), {
14
+ events_add_listener: a,
15
+ events_remove_listener: _,
16
+ events_emit: f
17
+ } = x(), [d, u] = E(!0), p = v(() => {
18
+ const e = O(r);
19
+ return e.components = i(e), e;
20
+ }, [r]), T = M((e) => {
21
+ m(e);
22
+ }, []);
23
+ return c(() => (s && a(o.EMMIT_EVENT_HOST_THEME_CHANGE, T), () => {
24
+ s && _(o.EMMIT_EVENT_HOST_THEME_CHANGE, T);
25
+ }), []), c(() => {
26
+ if (d) {
27
+ u(!1);
28
+ return;
29
+ }
30
+ s || (m(t), f(o.EMMIT_EVENT_HOST_THEME_CHANGE, t));
31
+ }, [t]), /* @__PURE__ */ n(I.Provider, {
32
+ value: {
33
+ hostThemeOptions: r,
34
+ fnComponentsOverrides: i
35
+ },
36
+ children: /* @__PURE__ */ n(N, {
37
+ injectFirst: !0,
38
+ children: /* @__PURE__ */ F(S, {
39
+ theme: p,
40
+ children: [/* @__PURE__ */ n(C, {
41
+ enableColorScheme: !0
42
+ }), h]
43
+ })
44
+ })
45
+ });
46
+ }
47
+ export {
48
+ I as H,
49
+ b as a
50
+ };
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { HostThemeProviderProps } from './types';
3
- declare const HostThemeContext: import("react").Context<import("./types").HostThemeType>;
3
+ declare const HostThemeContext: import("react").Context<import("./types").HostThemeType | null>;
4
4
  declare function HostThemeProvider(props: HostThemeProviderProps): JSX.Element;
5
5
  export { HostThemeProvider, HostThemeContext };
@@ -0,0 +1,4 @@
1
+ import { BaseLocale, LocaleType, NetworkLocaleType } from './types';
2
+ export declare function getLocaleFromNetwork(locale: NetworkLocaleType, host_static_assets: string, environment_assets: string): Promise<LocaleType>;
3
+ export declare function joinLocale(baseLocale: BaseLocale): string;
4
+ export declare function splitLocale(locale: string): BaseLocale;
@@ -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,19 +1,5 @@
1
- import { ReactNode } from 'react';
2
- import type { Locale } from 'date-fns';
3
- export declare type LangType = {
4
- label: string;
5
- value: string;
6
- locale: Locale;
7
- icon: string;
8
- };
9
- export declare type LocalesContextProps = {
10
- currentLang: LangType;
11
- onChangeLang: (newlang: string) => void;
12
- allLang: Array<LangType>;
13
- };
1
+ /// <reference types="react" />
2
+ import { LocalesProviderProps, LocalesContextProps } from './types';
14
3
  declare const LocalesContext: import("react").Context<LocalesContextProps | null>;
15
- declare type LocalesProviderProps = {
16
- children: ReactNode;
17
- };
18
- declare function LocalesProvider({ children }: LocalesProviderProps): JSX.Element;
4
+ declare function LocalesProvider(props: LocalesProviderProps): JSX.Element;
19
5
  export { LocalesProvider, LocalesContext };
@@ -0,0 +1,26 @@
1
+ import { ReactNode } from 'react';
2
+ import type { Locale } from 'date-fns';
3
+ export declare type SupportedLocales = 'en-US' | 'es' | 'fr';
4
+ export interface BaseLocale {
5
+ lang: string;
6
+ script?: string;
7
+ region?: string;
8
+ }
9
+ export interface NetworkLocaleType extends BaseLocale {
10
+ name: string;
11
+ url_icon: string;
12
+ }
13
+ export interface LocaleType extends NetworkLocaleType {
14
+ module: Locale;
15
+ localeString: string;
16
+ }
17
+ export declare type LocalesProviderProps = {
18
+ isMicroFrontEnd: boolean;
19
+ localeHost?: LocaleType;
20
+ getLocaleFromNetwork?: (locale: NetworkLocaleType, host_static_assets: string, environment_assets: string) => Promise<LocaleType>;
21
+ children: ReactNode;
22
+ };
23
+ export declare type LocalesContextProps = {
24
+ currentLocale?: LocaleType;
25
+ onChangeLocale: (newLocaleString: BaseLocale) => void;
26
+ };
@@ -0,0 +1,3 @@
1
+ import "./LocalesContext/index.3fcfbe02.js";
2
+ import "date-fns/locale/en-US";
3
+ import "./HostThemeContext/index.a6a62c70.js";
@@ -1,2 +1,4 @@
1
1
  export * from './LocalesContext';
2
+ export type { NetworkLocaleType, LocaleType } from './LocalesContext/types';
3
+ export { getLocaleFromNetwork } from './LocalesContext/helper';
2
4
  export * from './HostThemeContext';
@@ -1,8 +1,8 @@
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.c10c0bb5.js";
5
- import "../contexts/HostThemeContext/index.c6db12d4.js";
4
+ import "../contexts/LocalesContext/index.3fcfbe02.js";
5
+ import "../contexts/HostThemeContext/index.a6a62c70.js";
6
6
  function a() {
7
7
  const e = n(!0);
8
8
  return s(
@@ -1,5 +1,5 @@
1
1
  import { useContext as t } from "react";
2
- import { H as o } from "../../contexts/HostThemeContext/index.c6db12d4.js";
2
+ import { H as o } from "../../contexts/HostThemeContext/index.a6a62c70.js";
3
3
  const m = () => {
4
4
  const e = t(o);
5
5
  if (!e)
@@ -1,5 +1,5 @@
1
1
  import { useContext as o } from "react";
2
- import { L as t } from "../../contexts/LocalesContext/index.c10c0bb5.js";
2
+ import { L as t } from "../../contexts/LocalesContext/index.3fcfbe02.js";
3
3
  const n = () => {
4
4
  const e = o(t);
5
5
  if (!e)
@@ -1 +1 @@
1
- export declare const useLocales: () => import("../../contexts/LocalesContext").LocalesContextProps;
1
+ export declare const useLocales: () => import("../../contexts/LocalesContext/types").LocalesContextProps;
package/index.js CHANGED
@@ -1,47 +1,46 @@
1
- import { P as n } from "./components/ProgressBarStyle/index.fb6fd9ed.js";
2
- import { L as P, a as h } from "./contexts/LocalesContext/index.c10c0bb5.js";
3
- import { H as v, a as T } from "./contexts/HostThemeContext/index.c6db12d4.js";
4
- import { u as L, a as g } from "./hooks/useResponsive/index.fc5e1b4f.js";
5
- import { u as R, a as S } from "./hooks/index.9ec64bcf.js";
6
- import { u as k } from "./hooks/useLocales/index.680b143a.js";
7
- import { u as z } from "./hooks/useHostTheme/index.b3063684.js";
8
- import { d as D } from "./theme/defaultThemeOptions.9b9e7503.js";
9
- import { c as G, s as I } from "./theme/shadows.bf8dc290.js";
10
- import { p as V } from "./theme/palette.2baf72f5.js";
11
- import { C as j, a as q, c as A, d as E, g as J } from "./utils/index.d8b24456.js";
12
- import { f as N } from "./theme/overrides.7958c0ab.js";
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.3fcfbe02.js";
3
+ import { H as C, a as g } from "./contexts/HostThemeContext/index.a6a62c70.js";
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.c9dba2ff.js";
6
+ import { u as S } from "./hooks/useLocales/index.8154a401.js";
7
+ import { u as F } from "./hooks/useHostTheme/index.1c8e4ad7.js";
8
+ import { d as z } from "./theme/defaultThemeOptions.9b9e7503.js";
9
+ import { c as D, s as G } from "./theme/shadows.bf8dc290.js";
10
+ import { p as M } from "./theme/palette.2baf72f5.js";
11
+ import { C as V, a as b, c as j, d as q, g as A } from "./utils/index.d8b24456.js";
12
+ import { f as J } from "./theme/overrides.7958c0ab.js";
13
13
  import "@mui/material/styles";
14
14
  import "@mui/material";
15
15
  import "react/jsx-runtime";
16
16
  import "react";
17
17
  import "@mui/x-date-pickers/AdapterDateFns";
18
18
  import "@mui/x-date-pickers";
19
- import "date-fns/locale/es";
20
- import "date-fns/locale/fr";
21
- import "date-fns/locale/en-US";
22
19
  import "@m4l/core";
20
+ import "date-fns/locale/en-US";
23
21
  import "@mui/material/useMediaQuery";
24
22
  import "./theme/typography.f5eadf47.js";
25
23
  export {
26
- j as Capitalize,
27
- q as GetFontValue,
28
- v as HostThemeContext,
29
- T as HostThemeProvider,
30
- P as LocalesContext,
31
- h as LocalesProvider,
32
- n as ProgressBarStyle,
33
- A as colorPresets,
34
- G as customShadows,
35
- E as defaultPreset,
36
- D as defaultThemeOptions,
37
- N as fnComponentsOverrides,
38
- J as getColorPresets,
39
- V as palette,
40
- I as shadows,
41
- z as useHostTheme,
42
- R as useIsMountedRef,
43
- k as useLocales,
44
- S as useOffSetTop,
24
+ V as Capitalize,
25
+ b as GetFontValue,
26
+ C as HostThemeContext,
27
+ g as HostThemeProvider,
28
+ n as LocalesContext,
29
+ c as LocalesProvider,
30
+ l as ProgressBarStyle,
31
+ j as colorPresets,
32
+ D as customShadows,
33
+ q as defaultPreset,
34
+ z as defaultThemeOptions,
35
+ J as fnComponentsOverrides,
36
+ A as getColorPresets,
37
+ P as getLocaleFromNetwork,
38
+ M as palette,
39
+ G as shadows,
40
+ F as useHostTheme,
41
+ w as useIsMountedRef,
42
+ S as useLocales,
43
+ O as useOffSetTop,
45
44
  L as useResponsive,
46
- g as useResponsiveDesktop
45
+ T as useResponsiveDesktop
47
46
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m4l/graphics",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "license": "UNLICENSED",
5
5
  "author": "M4L Team",
6
6
  "dependencies": {
@@ -1,53 +0,0 @@
1
- import { createContext as v, useState as c, useMemo as H, useCallback as O, useEffect as h } from "react";
2
- import { CssBaseline as C } from "@mui/material";
3
- import { createTheme as M, StyledEngineProvider as F, ThemeProvider as x } from "@mui/material/styles";
4
- import { voidFunction as S, useHostTools as N, EmitEvents as T } from "@m4l/core";
5
- import { jsx as n, jsxs as P } from "react/jsx-runtime";
6
- const j = {
7
- hostThemeOptions: {},
8
- fnComponentsOverrides: S
9
- }, I = v(j);
10
- function k(a) {
11
- const {
12
- children: l,
13
- hostThemeOptions: t,
14
- fnComponentsOverrides: r,
15
- isMicroFrontEnd: o
16
- } = a, [s, i] = c(t), {
17
- events_add_listener: d,
18
- events_remove_listener: f,
19
- events_emit: E
20
- } = N(), [u, p] = c(!0), _ = H(() => {
21
- const e = M(s);
22
- return e.components = r(e), e;
23
- }, [s]), m = O((e) => {
24
- i(e);
25
- }, []);
26
- return h(() => (o && d(T.EMMIT_EVENT_HOST_THEME_CHANGE, m), () => {
27
- o && f("host_theme_change", m);
28
- }), []), h(() => {
29
- if (u) {
30
- p(!1);
31
- return;
32
- }
33
- o || (i(t), E(T.EMMIT_EVENT_HOST_THEME_CHANGE, t));
34
- }, [t]), /* @__PURE__ */ n(I.Provider, {
35
- value: {
36
- hostThemeOptions: s,
37
- fnComponentsOverrides: r
38
- },
39
- children: /* @__PURE__ */ n(F, {
40
- injectFirst: !0,
41
- children: /* @__PURE__ */ P(x, {
42
- theme: _,
43
- children: [/* @__PURE__ */ n(C, {
44
- enableColorScheme: !0
45
- }), l]
46
- })
47
- })
48
- });
49
- }
50
- export {
51
- I as H,
52
- k as a
53
- };
@@ -1,53 +0,0 @@
1
- import { createContext as f, useMemo as u, useState as L } from "react";
2
- import { AdapterDateFns as d } from "@mui/x-date-pickers/AdapterDateFns";
3
- import { LocalizationProvider as v } from "@mui/x-date-pickers";
4
- import p from "date-fns/locale/es";
5
- import h from "date-fns/locale/fr";
6
- import S from "date-fns/locale/en-US";
7
- import { useLocalStorage as _, useEnvironment as $ } from "@m4l/core";
8
- import { jsx as t } from "react/jsx-runtime";
9
- const x = f(null);
10
- function D({
11
- children: r
12
- }) {
13
- const [l, c] = _("langStorage", "en"), {
14
- host_static_assets: a,
15
- environment_assets: n
16
- } = $(), o = u(() => [{
17
- label: "English",
18
- value: "en",
19
- locale: S,
20
- icon: `${a}/${n}/frontend/commons/assets/icons/langs/lang_en.svg`
21
- }, {
22
- label: "Espa\xF1ol",
23
- value: "es",
24
- locale: p,
25
- icon: `${a}/${n}/frontend/commons/assets/icons/langs/lang_es.svg`
26
- }, {
27
- label: "French",
28
- value: "fr",
29
- locale: h,
30
- icon: `${a}/${n}/frontend/commons/assets/icons/langs/lang_fr.svg`
31
- }], []), [s, i] = L(o.find((e) => e.value === l) || o[0]), m = (e) => {
32
- c(e), i(o.find((g) => g.value === e) || o[0]);
33
- };
34
- return /* @__PURE__ */ t(x.Provider, {
35
- value: {
36
- currentLang: s,
37
- onChangeLang: m,
38
- allLang: o
39
- },
40
- children: /* @__PURE__ */ t(v, {
41
- dateAdapter: d,
42
- adapterLocale: s.locale,
43
- dateFormats: {
44
- hours24h: "23"
45
- },
46
- children: r
47
- })
48
- });
49
- }
50
- export {
51
- x as L,
52
- D as a
53
- };
@@ -1,2 +0,0 @@
1
- import "./LocalesContext/index.c10c0bb5.js";
2
- import "./HostThemeContext/index.c6db12d4.js";