mamba-layout 0.2.0 → 0.3.0

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,99 +1,100 @@
1
- import { ref as o, onActivated as j, onMounted as k, onUnmounted as H, watch as A } from "vue";
2
- import { useRoute as N } from "vue-router";
3
- import { createContext as O } from "../../utils/createContext.js";
4
- import { replaceName as W, tname as $, getRouteLastVisibleParentMenu as U } from "../../utils/repoUtils.js";
5
- import { useSetting as V } from "./useSetting.js";
6
- const [Q, q] = O("LayoutRoot");
1
+ import { ref as o, onActivated as K, onMounted as N, onUnmounted as W, watch as y } from "vue";
2
+ import { useRoute as j } from "vue-router";
3
+ import { createContext as k } from "../../utils/createContext.js";
4
+ import { replaceName as z, tname as B, getRouteLastVisibleParentMenu as D } from "../../utils/repoUtils.js";
5
+ import { useSetting as H } from "./useSetting.js";
6
+ const U = 1024, [Q, V] = k("LayoutRoot");
7
7
  function X() {
8
- const s = N(), h = o([]), r = o(), I = o(), c = o(""), i = o(""), M = o(""), m = V(), C = o(!0), E = o(!1), B = o(), d = () => {
8
+ const s = j(), h = o([]), r = o(), C = o(), u = o(""), i = o(""), L = o(""), m = H(), M = o(!0), I = o(!1), O = o(), v = () => {
9
9
  var t;
10
- return ((t = m.value.menus) == null ? void 0 : t.filter((v) => {
10
+ return ((t = m.value.menus) == null ? void 0 : t.filter((d) => {
11
11
  var n;
12
- return ((n = v.meta) == null ? void 0 : n.appId) == i.value;
12
+ return ((n = d.meta) == null ? void 0 : n.appId) == i.value;
13
13
  })) || [];
14
- }, b = (t, v, n = 0, f) => {
15
- var P, x, R, L;
16
- const l = f ? [...f] : [], p = [], w = [];
14
+ }, b = (t, d, n = 0, f) => {
15
+ var x, w, R, E;
16
+ const l = f ? [...f] : [], p = [], P = [];
17
17
  for (const e in t) {
18
18
  [...l], t[e];
19
- const a = ((P = s.meta) == null ? void 0 : P.parent) || s.path, u = ((x = t[e].path) == null ? void 0 : x.replace(/\/:(\w+)/g, "/([^/]+)")) || "", T = new RegExp(`^${u}$`);
20
- a == t[e].path ? p.push({ index: e, item: t[e] }) : T.test(a) && w.push({ index: e, item: t[e] });
19
+ const a = ((x = s.meta) == null ? void 0 : x.parent) || s.path, c = ((w = t[e].path) == null ? void 0 : w.replace(/\/:(\w+)/g, "/([^/]+)")) || "", $ = new RegExp(`^${c}$`);
20
+ a == t[e].path ? p.push({ index: e, item: t[e] }) : $.test(a) && P.push({ index: e, item: t[e] });
21
21
  }
22
- const g = p.length > 0 ? p : w;
22
+ const g = p.length > 0 ? p : P;
23
23
  if (g.length > 0) {
24
24
  const e = g[0], a = [...l];
25
25
  a[n] = e.item, r.value = {
26
26
  ...e.item,
27
27
  paths: a.slice(0, n + 1)
28
- }, i.value = ((R = e.item.meta) == null ? void 0 : R.appId) || "", I.value = v;
28
+ }, i.value = ((R = e.item.meta) == null ? void 0 : R.appId) || "", C.value = d;
29
29
  }
30
30
  for (const e in t)
31
- if (t[e].children && ((L = t[e].children) != null && L.length)) {
32
- const a = t[e].children || [], u = [...l];
33
- u[n] = t[e], b(a, t[e], n + 1, u);
31
+ if (t[e].children && ((E = t[e].children) != null && E.length)) {
32
+ const a = t[e].children || [], c = [...l];
33
+ c[n] = t[e], b(a, t[e], n + 1, c);
34
34
  }
35
- M.value = s.meta.parentPath || U(
35
+ L.value = s.meta.parentPath || D(
36
36
  s.path.toLowerCase(),
37
37
  m.value.menus || []
38
38
  ) || s.path;
39
- }, y = () => {
40
- var f, l, p, w, g, P, x, R, L, e;
39
+ }, A = () => {
40
+ var f, l, p, P, g, x, w, R, E, e;
41
41
  b(m.value.menus || []), i.value || (i.value = ((p = (l = (f = m.value.menus) == null ? void 0 : f.find(
42
42
  (a) => {
43
- var u;
44
- return (u = a.path) == null ? void 0 : u.startsWith(c.value);
43
+ var c;
44
+ return (c = a.path) == null ? void 0 : c.startsWith(u.value);
45
45
  }
46
46
  )) == null ? void 0 : l.meta) == null ? void 0 : p.appId) || "");
47
- const t = ((w = r.value) == null ? void 0 : w.paths) || [], v = W(
48
- $(((P = (g = r.value) == null ? void 0 : g.meta) == null ? void 0 : P.translations) || {}, "name")
49
- ), n = ((x = r.value) == null ? void 0 : x.path) == ((R = t[1]) == null ? void 0 : R.path) ? "" : W($(((e = (L = t[1]) == null ? void 0 : L.meta) == null ? void 0 : e.translations) || {}, "name"));
50
- document.title = v + (n ? ` - ${n}` : "");
51
- }, z = () => {
52
- c.value = "/" + (s.path.split("/").filter(Boolean).shift() || ""), y(), h.value = d();
47
+ const t = ((P = r.value) == null ? void 0 : P.paths) || [], d = z(
48
+ B(((x = (g = r.value) == null ? void 0 : g.meta) == null ? void 0 : x.translations) || {}, "name")
49
+ ), n = ((w = r.value) == null ? void 0 : w.path) == ((R = t[1]) == null ? void 0 : R.path) ? "" : z(B(((e = (E = t[1]) == null ? void 0 : E.meta) == null ? void 0 : e.translations) || {}, "name"));
50
+ document.title = d + (n ? ` - ${n}` : "");
51
+ }, T = () => {
52
+ u.value = "/" + (s.path.split("/").filter(Boolean).shift() || ""), A(), h.value = v();
53
53
  };
54
- z(), j(() => {
55
- z();
54
+ T(), K(() => {
55
+ T();
56
56
  });
57
57
  const S = () => {
58
- E.value = window.innerWidth < 1024, C.value = window.innerWidth > 1024;
58
+ const t = window.innerWidth < U;
59
+ I.value = t, M.value = !t;
59
60
  };
60
- return S(), k(() => {
61
+ return S(), N(() => {
61
62
  window.addEventListener("resize", S);
62
- }), H(() => {
63
+ }), W(() => {
63
64
  window.removeEventListener("resize", S);
64
- }), A(
65
- () => c.value,
66
- () => void (h.value = d())
67
- ), A(
65
+ }), y(
66
+ () => u.value,
67
+ () => void (h.value = v())
68
+ ), y(
68
69
  () => [s.path, m.value.menus],
69
70
  () => {
70
- M.value = "", r.value = void 0, c.value = "/" + (s.path.split("/").filter(Boolean).shift() || ""), y(), h.value = d(), E.value && (C.value = !1);
71
+ L.value = "", r.value = void 0, u.value = "/" + (s.path.split("/").filter(Boolean).shift() || ""), A(), h.value = v(), I.value && (M.value = !1);
71
72
  }
72
- ), q({
73
+ ), V({
73
74
  menus: h,
74
75
  currentEndRoute: r,
75
- currentTabPath: c,
76
+ currentTabPath: u,
76
77
  currentAppId: i,
77
- defaultParentActive: M,
78
- sideOpen: C,
79
- isMobile: E,
80
- getMenus: d,
81
- currentEndParentRoute: I
78
+ defaultParentActive: L,
79
+ sideOpen: M,
80
+ isMobile: I,
81
+ getMenus: v,
82
+ currentEndParentRoute: C
82
83
  }), {
83
84
  menus: h,
84
85
  currentEndRoute: r,
85
- currentTabPath: c,
86
+ currentTabPath: u,
86
87
  currentAppId: i,
87
- defaultParentActive: M,
88
- sideOpen: C,
89
- isMobile: E,
90
- getMenus: d,
91
- currentEndParentRoute: I,
92
- leftScrollRef: B
88
+ defaultParentActive: L,
89
+ sideOpen: M,
90
+ isMobile: I,
91
+ getMenus: v,
92
+ currentEndParentRoute: C,
93
+ leftScrollRef: O
93
94
  };
94
95
  }
95
96
  export {
96
97
  Q as injectLayoutContext,
97
- q as provideLayoutContext,
98
+ V as provideLayoutContext,
98
99
  X as useStateHook
99
100
  };