@m4l/graphics 3.0.3 → 6.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.
Files changed (60) hide show
  1. package/components/GlobalStyles/index.d.ts +0 -1
  2. package/contexts/FormatterContext/index.d.ts +1 -2
  3. package/contexts/FormatterContext/{index-Ch6IW7j8.js → index.js} +1 -1
  4. package/contexts/FormatterContext/types.d.ts +2 -2
  5. package/contexts/HostThemeContext/index.d.ts +1 -2
  6. package/contexts/HostThemeContext/index.js +46 -0
  7. package/contexts/HostThemeContext/types.d.ts +6 -5
  8. package/contexts/LocalesContext/helper.js +35 -0
  9. package/contexts/LocalesContext/index.d.ts +1 -2
  10. package/contexts/LocalesContext/index.js +69 -0
  11. package/contexts/LocalesContext/types.d.ts +4 -4
  12. package/contexts/ResponsiveContainerContext/constants.js +4 -0
  13. package/contexts/ResponsiveContainerContext/index.d.ts +3 -4
  14. package/contexts/ResponsiveContainerContext/index.js +51 -0
  15. package/contexts/ResponsiveContainerContext/store.d.ts +3 -3
  16. package/contexts/ResponsiveContainerContext/store.js +26 -0
  17. package/contexts/ResponsiveContainerContext/types.d.ts +4 -5
  18. package/contexts/ThemeSettingsContext/ThemeSettingsContext.d.ts +4 -5
  19. package/contexts/ThemeSettingsContext/ThemeSettingsContext.js +32 -0
  20. package/contexts/ThemeSettingsContext/constants.js +11 -0
  21. package/contexts/ThemeSettingsContext/index.js +1 -0
  22. package/contexts/ThemeSettingsContext/store.d.ts +2 -2
  23. package/contexts/ThemeSettingsContext/store.js +118 -0
  24. package/contexts/ThemeSettingsContext/types.d.ts +14 -11
  25. package/contexts/index.js +1 -0
  26. package/hooks/index.js +1 -0
  27. package/hooks/useFormatter/index.d.ts +1 -1
  28. package/hooks/useFormatter/index.js +11 -0
  29. package/hooks/useHostTheme/index.d.ts +1 -1
  30. package/hooks/useHostTheme/index.js +11 -0
  31. package/hooks/useIsMobile/{index-Bro0dV28.js → index.js} +5 -5
  32. package/hooks/useIsMountedRef/index.d.ts +1 -2
  33. package/hooks/useIsMountedRef/index.js +13 -0
  34. package/hooks/useLocales/index.d.ts +1 -1
  35. package/hooks/useLocales/index.js +11 -0
  36. package/hooks/useOffSetTop.js +12 -0
  37. package/hooks/useResizeObserver/index.d.ts +1 -2
  38. package/hooks/useResizeObserver/index.js +18 -0
  39. package/hooks/useResponsive/index.js +7 -0
  40. package/hooks/useResponsiveContainer/index.js +12 -0
  41. package/hooks/useThemSettingsStore/index.js +12 -0
  42. package/index.js +44 -35
  43. package/package.json +55 -11
  44. package/utils/anchorEl.d.ts +2 -2
  45. package/utils/anchorEl.js +49 -0
  46. package/utils/index.js +1 -0
  47. package/utils/strings.js +4 -0
  48. package/commonjs-BCz0-aDl.js +0 -9
  49. package/contexts/HostThemeContext/index-BMSwOCtA.js +0 -44
  50. package/contexts/LocalesContext/index-C89UlO0s.js +0 -101
  51. package/contexts/index-DEyJidab.js +0 -262
  52. package/hooks/index-Y3uj_IzK.js +0 -52
  53. package/hooks/useFormatter/index-BBgQ4lJL.js +0 -10
  54. package/hooks/useLocales/index-_thMBNE7.js +0 -10
  55. package/hooks/useResponsive/index-Dki-WJi8.js +0 -16
  56. package/node_modules-BHhXVwYT.js +0 -4569
  57. package/utils/index-DZG6QXjf.js +0 -51
  58. /package/components/{GlobalStyle/index-C3p7OfnO.js → GlobalStyles/index.js} +0 -0
  59. /package/components/{index-l0sNRNKZ.js → index.js} +0 -0
  60. /package/hooks/useFirstRender/{index-B-Q0TTn0.js → index.js} +0 -0
@@ -0,0 +1 @@
1
+
package/hooks/index.js ADDED
@@ -0,0 +1 @@
1
+
@@ -1 +1 @@
1
- export declare const useFormatter: () => import("../..").Formatters;
1
+ export declare const useFormatter: () => import('../..').Formatters;
@@ -0,0 +1,11 @@
1
+ import { useContext as r } from "react";
2
+ import { F as e } from "../../contexts/FormatterContext/index.js";
3
+ const m = () => {
4
+ const t = r(e);
5
+ if (!t)
6
+ throw new Error("useFormatter context must be use inside FormatterProvider");
7
+ return t;
8
+ };
9
+ export {
10
+ m as u
11
+ };
@@ -1 +1 @@
1
- export declare const useHostTheme: () => import("../..").HostThemeType;
1
+ export declare const useHostTheme: () => import('../..').HostThemeType;
@@ -0,0 +1,11 @@
1
+ import { useContext as t } from "react";
2
+ import { H as o } from "../../contexts/HostThemeContext/index.js";
3
+ const m = () => {
4
+ const e = t(o);
5
+ if (!e)
6
+ throw new Error("useHostTheme context must be use inside HostThemeProvider");
7
+ return e;
8
+ };
9
+ export {
10
+ m as u
11
+ };
@@ -1,11 +1,11 @@
1
1
  import { useState as n, useEffect as o } from "react";
2
- import { t as s } from "../../node_modules-BHhXVwYT.js";
3
- const t = () => typeof navigator > "u" ? !1 : /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent), l = () => {
4
- const [i, r] = n(t());
2
+ import s from "lodash/throttle";
3
+ const i = () => typeof navigator > "u" ? !1 : /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent), l = () => {
4
+ const [t, r] = n(i());
5
5
  return o(() => {
6
6
  const e = s(
7
7
  () => {
8
- r(t());
8
+ r(i());
9
9
  },
10
10
  200,
11
11
  {
@@ -15,7 +15,7 @@ const t = () => typeof navigator > "u" ? !1 : /Android|webOS|iPhone|iPad|iPod|Bl
15
15
  return window.addEventListener("resize", e), e(), () => {
16
16
  window.removeEventListener("resize", e), e.cancel();
17
17
  };
18
- }, []), i;
18
+ }, []), t;
19
19
  };
20
20
  export {
21
21
  l as u
@@ -1,2 +1 @@
1
- /// <reference types="react" />
2
- export declare function useIsMountedRef(): import("react").MutableRefObject<boolean>;
1
+ export declare function useIsMountedRef(): import('react').MutableRefObject<boolean>;
@@ -0,0 +1,13 @@
1
+ import { useRef as t, useEffect as u } from "react";
2
+ function s() {
3
+ const e = t(!0);
4
+ return u(
5
+ () => () => {
6
+ e.current = !1;
7
+ },
8
+ []
9
+ ), e;
10
+ }
11
+ export {
12
+ s as u
13
+ };
@@ -1 +1 @@
1
- export declare const useLocales: () => import("../../contexts/LocalesContext/types").LocalesContextProps;
1
+ export declare const useLocales: () => import('../../contexts/LocalesContext/types').LocalesContextProps;
@@ -0,0 +1,11 @@
1
+ import { useContext as o } from "react";
2
+ import { L as t } from "../../contexts/LocalesContext/index.js";
3
+ const n = () => {
4
+ const e = o(t);
5
+ if (!e)
6
+ throw new Error("useLocales context must be use inside LocalesProvider");
7
+ return e;
8
+ };
9
+ export {
10
+ n as u
11
+ };
@@ -0,0 +1,12 @@
1
+ import { useState as s, useEffect as n } from "react";
2
+ function l(t) {
3
+ const [f, e] = s(!1), o = t || 100;
4
+ return n(() => (window.onscroll = () => {
5
+ window.pageYOffset > o ? e(!0) : e(!1);
6
+ }, () => {
7
+ window.onscroll = null;
8
+ }), [o]), f;
9
+ }
10
+ export {
11
+ l as u
12
+ };
@@ -1,3 +1,2 @@
1
- /// <reference types="react" />
2
- export declare function useResizeObserver<T extends HTMLElement>(callback: (target: T, entry: ResizeObserverEntry) => void): import("react").RefObject<T>;
1
+ export declare function useResizeObserver<T extends HTMLElement>(callback: (target: T, entry: ResizeObserverEntry) => void): import('react').RefObject<T>;
3
2
  export default useResizeObserver;
@@ -0,0 +1,18 @@
1
+ import { useRef as u, useLayoutEffect as o } from "react";
2
+ function f(n) {
3
+ const e = u(null);
4
+ return o(() => {
5
+ const r = e?.current;
6
+ if (!r)
7
+ return;
8
+ const t = new ResizeObserver((s) => {
9
+ n(r, s[0]);
10
+ });
11
+ return t.observe(r), () => {
12
+ t.disconnect();
13
+ };
14
+ }, [n, e.current]), e;
15
+ }
16
+ export {
17
+ f as u
18
+ };
@@ -0,0 +1,7 @@
1
+ import { useResponsive as s } from "@m4l/styles";
2
+ function p() {
3
+ return s("up", "sm");
4
+ }
5
+ export {
6
+ p as u
7
+ };
@@ -0,0 +1,12 @@
1
+ import { useContext as r } from "react";
2
+ import { useStore as n } from "zustand";
3
+ import { R as s } from "../../contexts/ResponsiveContainerContext/index.js";
4
+ function a(t, o) {
5
+ const e = r(s);
6
+ if (!e)
7
+ throw new Error("useAreasStore context must be use inside AreasContext");
8
+ return n(e, t, o);
9
+ }
10
+ export {
11
+ a as u
12
+ };
@@ -0,0 +1,12 @@
1
+ import { useContext as r } from "react";
2
+ import { useStore as n } from "zustand";
3
+ import { T as s } from "../../contexts/ThemeSettingsContext/ThemeSettingsContext.js";
4
+ function S(e, o) {
5
+ const t = r(s);
6
+ if (!t)
7
+ throw new Error("useSettingsStore context must be use inside SettignsContext");
8
+ return n(t, e, o);
9
+ }
10
+ export {
11
+ S as u
12
+ };
package/index.js CHANGED
@@ -1,40 +1,49 @@
1
- import { G as s } from "./components/GlobalStyle/index-C3p7OfnO.js";
2
- import { L as r, a, g as i } from "./contexts/LocalesContext/index-C89UlO0s.js";
3
- import { F as m, a as p } from "./contexts/FormatterContext/index-Ch6IW7j8.js";
4
- import { R as x, a as f, T as d, b as l, d as v } from "./contexts/index-DEyJidab.js";
5
- import { H as T, a as g } from "./contexts/HostThemeContext/index-BMSwOCtA.js";
6
- import { u as R } from "./hooks/useFirstRender/index-B-Q0TTn0.js";
7
- import { u as c } from "./hooks/useFormatter/index-BBgQ4lJL.js";
8
- import { b as P, u as b, a as L, c as H, d as k } from "./hooks/index-Y3uj_IzK.js";
9
- import { u as z } from "./hooks/useLocales/index-_thMBNE7.js";
10
- import { u as I, a as M } from "./hooks/useResponsive/index-Dki-WJi8.js";
11
- import { u as y } from "./hooks/useIsMobile/index-Bro0dV28.js";
12
- import { C as D, g as E } from "./utils/index-DZG6QXjf.js";
1
+ import { G as r } from "./components/GlobalStyles/index.js";
2
+ import { g as s } from "./contexts/LocalesContext/helper.js";
3
+ import { F as m, a as p } from "./contexts/FormatterContext/index.js";
4
+ import { L as f, a as i } from "./contexts/LocalesContext/index.js";
5
+ import { R as u, a as l } from "./contexts/ResponsiveContainerContext/index.js";
6
+ import { H as v, a as C } from "./contexts/HostThemeContext/index.js";
7
+ import { d as g } from "./contexts/ThemeSettingsContext/constants.js";
8
+ import { T as R, a as S } from "./contexts/ThemeSettingsContext/ThemeSettingsContext.js";
9
+ import { u as P } from "./hooks/useFirstRender/index.js";
10
+ import { u as L } from "./hooks/useFormatter/index.js";
11
+ import { u as b } from "./hooks/useIsMountedRef/index.js";
12
+ import { u as w } from "./hooks/useLocales/index.js";
13
+ import { u as G } from "./hooks/useResponsiveContainer/index.js";
14
+ import { u as M } from "./hooks/useIsMobile/index.js";
15
+ import { u as y } from "./hooks/useOffSetTop.js";
16
+ import { u as D } from "./hooks/useHostTheme/index.js";
17
+ import { u as N } from "./hooks/useResizeObserver/index.js";
18
+ import { u as j } from "./hooks/useResponsive/index.js";
19
+ import { u as B } from "./hooks/useThemSettingsStore/index.js";
20
+ import { C as K } from "./utils/strings.js";
21
+ import { g as U } from "./utils/anchorEl.js";
13
22
  export {
14
- D as Capitalize,
23
+ K as Capitalize,
15
24
  m as FormatterContext,
16
25
  p as FormatterProvider,
17
- s as GlobalStyles,
18
- T as HostThemeContext,
19
- g as HostThemeProvider,
20
- r as LocalesContext,
21
- a as LocalesProvider,
22
- x as ResponsiveContainerContext,
23
- f as ResponsiveContainerProvider,
24
- d as ThemeSettingsContext,
25
- l as ThemeSettingsProvider,
26
- v as defaultThemeSettings,
27
- E as getAnchorElPositionWindow,
28
- i as getLocaleFromNetwork,
29
- R as useFirstRender,
30
- c as useFormatter,
31
- P as useHostTheme,
32
- y as useIsMobile,
26
+ r as GlobalStyles,
27
+ v as HostThemeContext,
28
+ C as HostThemeProvider,
29
+ f as LocalesContext,
30
+ i as LocalesProvider,
31
+ u as ResponsiveContainerContext,
32
+ l as ResponsiveContainerProvider,
33
+ R as ThemeSettingsContext,
34
+ S as ThemeSettingsProvider,
35
+ g as defaultThemeSettings,
36
+ U as getAnchorElPositionWindow,
37
+ s as getLocaleFromNetwork,
38
+ P as useFirstRender,
39
+ L as useFormatter,
40
+ D as useHostTheme,
41
+ M as useIsMobile,
33
42
  b as useIsMountedRef,
34
- z as useLocales,
35
- L as useOffSetTop,
36
- H as useResizeObserver,
37
- I as useResponsiveContainerStore,
38
- M as useResponsiveDesktop,
39
- k as useThemeSettingsStore
43
+ w as useLocales,
44
+ y as useOffSetTop,
45
+ N as useResizeObserver,
46
+ G as useResponsiveContainerStore,
47
+ j as useResponsiveDesktop,
48
+ B as useThemeSettingsStore
40
49
  };
package/package.json CHANGED
@@ -1,22 +1,65 @@
1
1
  {
2
2
  "name": "@m4l/graphics",
3
- "version": "3.0.3",
3
+ "version": "6.0.1",
4
4
  "license": "UNLICENSED",
5
5
  "author": "M4L Team*",
6
6
  "dependencies": {
7
- "@m4l/core": "^2.0.0",
8
- "@m4l/styles": "^3.0.0",
9
7
  "date-fns": "^2.30.0",
10
- "zustand": "4.3.6",
11
- "immer": "^9.0.21"
8
+ "immer": "^9.0.21",
9
+ "zustand": "4.3.6"
12
10
  },
13
11
  "peerDependencies": {
14
- "@types/react": "^17.0.0 || ^18.0.0",
15
- "react": "^17.0.0 || ^18.0.0",
16
- "react-toastify": "10.0.5",
17
- "lodash.clonedeep": "^4.5.0",
18
- "lodash.debounce": "^4.0.8",
19
- "lodash.throttle": "^4.1.1"
12
+ "@m4l/core": "^2.0.8",
13
+ "@m4l/styles": "^6.4.1",
14
+ "@mui/material": "^5.15.19",
15
+ "@mui/x-date-pickers": "^6.11.1",
16
+ "@types/react": "^18.0.0",
17
+ "lodash.clonedeep": "^4.0.0",
18
+ "lodash.debounce": "^4.0.0",
19
+ "lodash.isstring": "^4.0.0",
20
+ "lodash.merge": "^4.0.0",
21
+ "lodash.throttle": "^4.0.0",
22
+ "react": "^18.0.0",
23
+ "react-toastify": "10.0.5"
24
+ },
25
+ "peerDependenciesMeta": {
26
+ "@mui/material": {
27
+ "optional": true
28
+ },
29
+ "@mui/x-date-pickers": {
30
+ "optional": true
31
+ },
32
+ "lodash.clonedeep": {
33
+ "optional": true
34
+ },
35
+ "lodash.debounce": {
36
+ "optional": true
37
+ },
38
+ "lodash.isstring": {
39
+ "optional": true
40
+ },
41
+ "lodash.merge": {
42
+ "optional": true
43
+ },
44
+ "lodash.throttle": {
45
+ "optional": true
46
+ }
47
+ },
48
+ "resolutions": {
49
+ "eslint": "^9.0.0",
50
+ "react": "^18.0.0",
51
+ "@types/react": "^18.0.0",
52
+ "@types/react-dom": "^18.0.0",
53
+ "react-dom": "^18.0.0",
54
+ "vite": "^5.4.7"
55
+ },
56
+ "overrides": {
57
+ "eslint": "^9.0.0",
58
+ "react": "^18.0.0",
59
+ "@types/react": "^18.0.0",
60
+ "@types/react-dom": "^18.0.0",
61
+ "react-dom": "^18.0.0",
62
+ "vite": "^5.4.7"
20
63
  },
21
64
  "files": [
22
65
  "*"
@@ -33,5 +76,6 @@
33
76
  "engines": {
34
77
  "node": ">=12.0.0"
35
78
  },
79
+ "packageManager": "yarn@4.5.0",
36
80
  "private": false
37
81
  }
@@ -1,4 +1,4 @@
1
- export declare type AnchorEl = HTMLElement | (() => HTMLElement);
1
+ export type AnchorEl = HTMLElement | (() => HTMLElement);
2
2
  export interface AnchorOrigin {
3
3
  vertical: 'top' | 'center' | 'bottom' | number;
4
4
  horizontal: 'left' | 'center' | 'right' | number;
@@ -7,7 +7,7 @@ export interface AnchorPosition {
7
7
  top: number;
8
8
  left: number;
9
9
  }
10
- export declare const getAnchorElPositionWindow: (anchorElement: HTMLElement, newWindowRect: Pick<DOMRect, 'width' | 'height'>, anchorOrigin: AnchorOrigin, transformOrigin: AnchorOrigin, marginThreshold?: number) => {
10
+ export declare const getAnchorElPositionWindow: (anchorElement: HTMLElement, newWindowRect: Pick<DOMRect, "width" | "height">, anchorOrigin: AnchorOrigin, transformOrigin: AnchorOrigin, marginThreshold?: number) => {
11
11
  top: number;
12
12
  left: number;
13
13
  };
@@ -0,0 +1,49 @@
1
+ function a(e, t) {
2
+ let o = 0;
3
+ return typeof t == "number" ? o = t : t === "center" ? o = e.height / 2 : t === "bottom" && (o = e.height), o;
4
+ }
5
+ function b(e, t) {
6
+ let o = 0;
7
+ return typeof t == "number" ? o = t : t === "center" ? o = e.width / 2 : t === "right" && (o = e.width), o;
8
+ }
9
+ function v(e) {
10
+ return typeof e == "function" ? e() : e;
11
+ }
12
+ const w = (e, t) => {
13
+ const f = v(e).getBoundingClientRect();
14
+ return {
15
+ top: f.top + a(f, t.vertical),
16
+ left: f.left + b(f, t.horizontal)
17
+ };
18
+ }, y = (e, t) => ({
19
+ vertical: a(e, t.vertical),
20
+ horizontal: b(e, t.horizontal)
21
+ }), O = (e, t, o, f, i = 16) => {
22
+ const r = w(e, o), l = y(t, f), h = document.getElementById("ContainerAreas")?.getBoundingClientRect() || {
23
+ top: 0,
24
+ left: 0
25
+ };
26
+ let s = r.top - l.vertical, c = r.left - l.horizontal;
27
+ const u = s + t.height, d = c + t.width, g = window, p = g.innerHeight - i, A = g.innerWidth - i;
28
+ if (s < i) {
29
+ const n = s - i;
30
+ s -= n;
31
+ } else if (u > p) {
32
+ const n = u - p;
33
+ s -= n;
34
+ }
35
+ if (c < i) {
36
+ const n = c - i;
37
+ c -= n;
38
+ } else if (d > A) {
39
+ const n = d - A;
40
+ c -= n;
41
+ }
42
+ return {
43
+ top: Math.round(s) - h.top,
44
+ left: Math.round(c) - h.left
45
+ };
46
+ };
47
+ export {
48
+ O as g
49
+ };
package/utils/index.js ADDED
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,4 @@
1
+ const a = (e) => e && e[0].toUpperCase() + e.slice(1) || "";
2
+ export {
3
+ a as C
4
+ };
@@ -1,9 +0,0 @@
1
- import "react";
2
- var l = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
3
- function t(e) {
4
- return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
5
- }
6
- export {
7
- l as c,
8
- t as g
9
- };
@@ -1,44 +0,0 @@
1
- import { jsxs as i, jsx as t } from "react/jsx-runtime";
2
- import { createContext as c, useMemo as h } from "react";
3
- import { CssBaseline as d } from "@mui/material";
4
- import { G as p } from "../../components/GlobalStyle/index-C3p7OfnO.js";
5
- import { createTheme as x, experimental_extendTheme as f, Experimental_CssVarsProvider as u, StyledEngineProvider as T } from "@mui/material/styles";
6
- const v = c(null);
7
- function j(m) {
8
- const { children: l, hostThemeOptions: o, fnComponentsOverrides: n, isMobile: s } = m, a = h(() => {
9
- const e = x({
10
- ...o
11
- }), r = f({
12
- cssVarPrefix: "m4l",
13
- colorSchemes: {
14
- light: e,
15
- finalTheme: e,
16
- dark: e
17
- },
18
- generalSettings: {
19
- isMobile: s
20
- }
21
- });
22
- return r.components = n(r), r;
23
- }, [s]);
24
- return /* @__PURE__ */ i(u, { theme: a, children: [
25
- /* @__PURE__ */ t(p, {}),
26
- /* @__PURE__ */ t(
27
- v.Provider,
28
- {
29
- value: {
30
- hostThemeOptions: o,
31
- fnComponentsOverrides: n
32
- },
33
- children: /* @__PURE__ */ i(T, { injectFirst: !0, children: [
34
- /* @__PURE__ */ t(d, { enableColorScheme: !0 }),
35
- l
36
- ] })
37
- }
38
- )
39
- ] });
40
- }
41
- export {
42
- v as H,
43
- j as a
44
- };
@@ -1,101 +0,0 @@
1
- import { jsx as E } from "react/jsx-runtime";
2
- import { createContext as k, useState as _, useCallback as x, useEffect as L } from "react";
3
- import { AdapterDateFns as F } from "@mui/x-date-pickers/AdapterDateFns";
4
- import { LocalizationProvider as U } from "@mui/x-date-pickers";
5
- import { useEnvironment as P, useNetwork as I, useHostTools as j, useLocalStorageWithListener as w, EmitEvents as u } from "@m4l/core";
6
- import S from "date-fns/locale/en-US";
7
- async function B(t, e, o) {
8
- const s = g(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: g(r)
14
- };
15
- }
16
- function g(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 { children: e, isMicroFrontEnd: o, localeHost: s, getLocaleFromNetwork: r } = t;
39
- if (o && !s)
40
- throw Error("Must set localeHost in microfrontend");
41
- if (!o && !r)
42
- throw Error("Must set getLocaleFromNetwork in host");
43
- const { domain_token: i, host_static_assets: v, environment_assets: h } = P(), { networkOperation: C } = I(), { events_add_listener: N, events_remove_listener: T, events_emit: H } = j(), [a, f] = _(() => {
44
- if (o)
45
- return s;
46
- }), [l, m] = w(
47
- "localeHost",
48
- navigator.language
49
- ), [M, A] = _(""), d = x((n) => {
50
- f(n);
51
- }, []);
52
- if (L(() => (o && N(u.EMMIT_EVENT_HOST_LOCALE_CHANGE, d), () => {
53
- o && T(u.EMMIT_EVENT_HOST_LOCALE_CHANGE, d);
54
- }), []), L(() => {
55
- let n = !0;
56
- if (!o && r && !(l === M && l !== ""))
57
- return C({
58
- method: "POST",
59
- endPoint: "na/locales",
60
- data: { ...y(l), domain_token: i }
61
- }).then((p) => {
62
- n && r(
63
- p.data,
64
- v,
65
- h
66
- ).then((c) => {
67
- f(c), A(c.localeString), l !== c.localeString && m(c.localeString), H(u.EMMIT_EVENT_HOST_LOCALE_CHANGE, c);
68
- });
69
- }).finally(() => {
70
- }), function() {
71
- n = !1;
72
- };
73
- }, [l]), !a)
74
- return null;
75
- const O = (n) => {
76
- (n.lang !== a.lang || n.script !== a.script || n.region !== a.region) && m(g(n));
77
- };
78
- return /* @__PURE__ */ E(
79
- G.Provider,
80
- {
81
- value: {
82
- currentLocale: a,
83
- onChangeLocale: O
84
- },
85
- children: /* @__PURE__ */ E(
86
- U,
87
- {
88
- dateAdapter: F,
89
- adapterLocale: a.module,
90
- dateFormats: { hours24h: "23" },
91
- children: e
92
- }
93
- )
94
- }
95
- );
96
- }
97
- export {
98
- G as L,
99
- J as a,
100
- B as g
101
- };