@shwfed/nuxt 0.1.71 → 0.1.73
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/dist/module.json
CHANGED
|
@@ -18,7 +18,8 @@ import { useFavorite } from "../composables/useFavorite";
|
|
|
18
18
|
import { useNavigationTabs } from "../composables/useNavigationTabs";
|
|
19
19
|
import { commandActionSchema, executeCommandAction } from "../utils/command";
|
|
20
20
|
import { createPaletteItemValue, normalizeCommandsForPalette, splitNavigationForPalette } from "../utils/command-palette";
|
|
21
|
-
import {
|
|
21
|
+
import { resolveNavigationTitle } from "../utils/navigation-title";
|
|
22
|
+
import { isRouteActive } from "../utils/route";
|
|
22
23
|
import { applyRootNavigationFallback } from "../utils/sidebar-fallback";
|
|
23
24
|
const { $dsl, $logout, $md, $api, $toast } = useNuxtApp();
|
|
24
25
|
const { t } = useI18n();
|
|
@@ -50,23 +51,24 @@ const { start: startProfileCloseTimer, stop: stopProfileCloseTimer } = useTimeou
|
|
|
50
51
|
const { meta_k } = useMagicKeys();
|
|
51
52
|
whenever(() => meta_k?.value, () => ui.isCommandPaletteOpen = !ui.isCommandPaletteOpen);
|
|
52
53
|
setGlobalDslContext(await props.dsl?.pipe(Effect.scoped).pipe(Effect.runPromise) ?? {});
|
|
54
|
+
const navigationItem = z.object({
|
|
55
|
+
id: z.union([z.string(), z.number()]),
|
|
56
|
+
title: z.string(),
|
|
57
|
+
icon: z.string().optional(),
|
|
58
|
+
route: z.string(),
|
|
59
|
+
keywords: z.array(z.string()).optional()
|
|
60
|
+
});
|
|
61
|
+
const navigationGroup = z.object({
|
|
62
|
+
id: z.union([z.string(), z.number()]),
|
|
63
|
+
title: z.string(),
|
|
64
|
+
icon: z.string().optional(),
|
|
65
|
+
children: z.array(navigationItem)
|
|
66
|
+
});
|
|
67
|
+
const navigationEntry = z.union([navigationGroup, navigationItem]);
|
|
53
68
|
const navigationItems = computed(() => {
|
|
54
|
-
const item = z.object({
|
|
55
|
-
id: z.union([z.string(), z.number()]),
|
|
56
|
-
title: z.string(),
|
|
57
|
-
icon: z.string().optional(),
|
|
58
|
-
route: z.string(),
|
|
59
|
-
keywords: z.array(z.string()).optional()
|
|
60
|
-
});
|
|
61
|
-
const group = z.object({
|
|
62
|
-
id: z.union([z.string(), z.number()]),
|
|
63
|
-
title: z.string(),
|
|
64
|
-
icon: z.string().optional(),
|
|
65
|
-
children: z.array(item)
|
|
66
|
-
});
|
|
67
69
|
try {
|
|
68
70
|
const result = $dsl.evaluate`${config.sidebar.menus}`();
|
|
69
|
-
return z.array(
|
|
71
|
+
return z.array(navigationEntry).parse(result);
|
|
70
72
|
} catch {
|
|
71
73
|
return [];
|
|
72
74
|
}
|
|
@@ -79,22 +81,7 @@ const {
|
|
|
79
81
|
} = useFavorite("navigation", navigationItems);
|
|
80
82
|
const isNavigationItemActive = (itemRoute) => isRouteActive(route.path, itemRoute);
|
|
81
83
|
const getTabLabel = (tab) => {
|
|
82
|
-
|
|
83
|
-
for (const group of navigations.value) {
|
|
84
|
-
if ("children" in group) {
|
|
85
|
-
const matchedChild = group.children.find((child) => {
|
|
86
|
-
if (!("route" in child))
|
|
87
|
-
return false;
|
|
88
|
-
return normalizeRoutePath(child.route) === normalizedTab;
|
|
89
|
-
});
|
|
90
|
-
if (matchedChild)
|
|
91
|
-
return matchedChild.title;
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
if (normalizeRoutePath(group.route) === normalizedTab)
|
|
95
|
-
return group.title;
|
|
96
|
-
}
|
|
97
|
-
return normalizedTab;
|
|
84
|
+
return resolveNavigationTitle(navigationItems.value, tab);
|
|
98
85
|
};
|
|
99
86
|
const activeTabLabel = computed(() => {
|
|
100
87
|
if (active.value === void 0)
|
|
@@ -187,6 +174,18 @@ const profileCommands = computed(() => {
|
|
|
187
174
|
return [];
|
|
188
175
|
}
|
|
189
176
|
});
|
|
177
|
+
const isBodyInit = (value) => {
|
|
178
|
+
return typeof value === "string" || value instanceof Blob || value instanceof ArrayBuffer || ArrayBuffer.isView(value) || value instanceof FormData || value instanceof URLSearchParams || value instanceof ReadableStream;
|
|
179
|
+
};
|
|
180
|
+
const toApiRequestBody = (value) => {
|
|
181
|
+
if (value === void 0 || value === null)
|
|
182
|
+
return value;
|
|
183
|
+
if (isBodyInit(value))
|
|
184
|
+
return value;
|
|
185
|
+
if (typeof value === "object")
|
|
186
|
+
return value;
|
|
187
|
+
return void 0;
|
|
188
|
+
};
|
|
190
189
|
const executeCommandEffect = async (effect) => {
|
|
191
190
|
if (effect === void 0)
|
|
192
191
|
return false;
|
|
@@ -203,7 +202,7 @@ const executeCommandEffect = async (effect) => {
|
|
|
203
202
|
logout: $logout,
|
|
204
203
|
request: async (requestAction) => $api(requestAction.url, {
|
|
205
204
|
method: requestAction.method,
|
|
206
|
-
body: requestAction.body,
|
|
205
|
+
body: toApiRequestBody(requestAction.body),
|
|
207
206
|
query: requestAction.query,
|
|
208
207
|
headers: requestAction.headers
|
|
209
208
|
})
|
|
@@ -221,7 +220,14 @@ const executeProfileCommand = async (effect) => {
|
|
|
221
220
|
if (effect === void 0 || await executeCommandEffect(effect))
|
|
222
221
|
ui.isProfileDropdownOpen = false;
|
|
223
222
|
};
|
|
224
|
-
const
|
|
223
|
+
const normalizedNavigationForPalette = computed(() => {
|
|
224
|
+
try {
|
|
225
|
+
return z.array(navigationEntry).parse(navigations.value);
|
|
226
|
+
} catch {
|
|
227
|
+
return navigationItems.value;
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
const paletteNavigation = computed(() => splitNavigationForPalette(normalizedNavigationForPalette.value));
|
|
225
231
|
const favoriteRoutesForPalette = computed(() => paletteNavigation.value.favoriteRoutes);
|
|
226
232
|
const navigationForPalette = computed(() => paletteNavigation.value.navigationEntries);
|
|
227
233
|
const commandForPalette = computed(() => normalizeCommandsForPalette(profileCommands.value));
|
|
@@ -20,6 +20,31 @@ export function useFavorite(key, items) {
|
|
|
20
20
|
const [id, of] = key2.split("::");
|
|
21
21
|
return [id, of];
|
|
22
22
|
};
|
|
23
|
+
if (key === "navigation" && typeof window !== "undefined" && typeof localStorage !== "undefined") {
|
|
24
|
+
const legacyStorageKey = "navigation-favorites";
|
|
25
|
+
const rawLegacy = localStorage.getItem(legacyStorageKey);
|
|
26
|
+
if (rawLegacy !== null) {
|
|
27
|
+
try {
|
|
28
|
+
const parsedLegacy = JSON.parse(rawLegacy);
|
|
29
|
+
if (Array.isArray(parsedLegacy)) {
|
|
30
|
+
const next = new Set(memo.value);
|
|
31
|
+
for (const entry of parsedLegacy) {
|
|
32
|
+
if (typeof entry !== "string") {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const [groupId, itemId, extra] = entry.split("::");
|
|
36
|
+
if (extra !== void 0 || groupId === void 0 || itemId === void 0 || groupId === "" || itemId === "") {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
next.add(`${itemId}::${groupId}`);
|
|
40
|
+
}
|
|
41
|
+
memo.value = next;
|
|
42
|
+
localStorage.removeItem(legacyStorageKey);
|
|
43
|
+
}
|
|
44
|
+
} catch {
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
23
48
|
return {
|
|
24
49
|
favorite: (item, of) => {
|
|
25
50
|
memo.value = new Set(memo.value).add(keyed(item, of));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type NavigationLeaf = Readonly<{
|
|
2
|
+
title: string;
|
|
3
|
+
route: string;
|
|
4
|
+
}>;
|
|
5
|
+
type NavigationGroup = Readonly<{
|
|
6
|
+
children: Array<NavigationLeaf>;
|
|
7
|
+
}>;
|
|
8
|
+
type NavigationEntry = NavigationLeaf | NavigationGroup;
|
|
9
|
+
export declare function resolveNavigationTitle(entries: Array<NavigationEntry>, path: string): string;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isRouteActive, normalizeRoutePath } from "./route.js";
|
|
2
|
+
export function resolveNavigationTitle(entries, path) {
|
|
3
|
+
const normalizedPath = normalizeRoutePath(path);
|
|
4
|
+
let bestTitle;
|
|
5
|
+
let bestRouteLength = -1;
|
|
6
|
+
for (const entry of entries) {
|
|
7
|
+
if ("children" in entry) {
|
|
8
|
+
for (const child of entry.children) {
|
|
9
|
+
const normalizedRoute2 = normalizeRoutePath(child.route);
|
|
10
|
+
if (!isRouteActive(normalizedPath, normalizedRoute2))
|
|
11
|
+
continue;
|
|
12
|
+
if (normalizedRoute2.length <= bestRouteLength)
|
|
13
|
+
continue;
|
|
14
|
+
bestRouteLength = normalizedRoute2.length;
|
|
15
|
+
bestTitle = child.title;
|
|
16
|
+
}
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const normalizedRoute = normalizeRoutePath(entry.route);
|
|
20
|
+
if (!isRouteActive(normalizedPath, normalizedRoute))
|
|
21
|
+
continue;
|
|
22
|
+
if (normalizedRoute.length <= bestRouteLength)
|
|
23
|
+
continue;
|
|
24
|
+
bestRouteLength = normalizedRoute.length;
|
|
25
|
+
bestTitle = entry.title;
|
|
26
|
+
}
|
|
27
|
+
return bestTitle ?? normalizedPath;
|
|
28
|
+
}
|