@shwfed/nuxt 0.1.56 → 0.1.58

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shwfed/nuxt",
3
3
  "configKey": "shwfed",
4
- "version": "0.1.56",
4
+ "version": "0.1.58",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -1,6 +1,6 @@
1
1
  <script setup>
2
- import { useHead, useNuxtApp, useRouter, useRuntimeConfig } from "#app";
3
- import { computed, ref } from "vue";
2
+ import { useHead, useNuxtApp, useRoute, useRouter, useRuntimeConfig } from "#app";
3
+ import { computed, onMounted, ref } from "vue";
4
4
  import { CommandDialog, CommandInput, CommandList, CommandGroup, CommandEmpty, CommandItem } from "./ui/command";
5
5
  import { TooltipProvider } from "./ui/tooltip";
6
6
  import { Toaster } from "vue-sonner";
@@ -14,7 +14,12 @@ import { Sidebar, SidebarContent, SidebarGroup, SidebarGroupLabel, SidebarMenu,
14
14
  import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "./ui/collapsible";
15
15
  import Logo from "./logo.vue";
16
16
  const { $dsl } = useNuxtApp();
17
- const config = useRuntimeConfig().public.shwfed;
17
+ const {
18
+ public: {
19
+ shwfed: config
20
+ },
21
+ app
22
+ } = useRuntimeConfig();
18
23
  const props = defineProps({
19
24
  navigation: { type: Array, required: false },
20
25
  commands: { type: Array, required: false },
@@ -39,6 +44,7 @@ whenever(() => meta_k?.value, () => {
39
44
  isCommandOpen.value = !isCommandOpen.value;
40
45
  });
41
46
  const router = useRouter();
47
+ const route = useRoute();
42
48
  setGlobalDslContext(await props.dsl?.pipe(Effect.scoped).pipe(Effect.runPromise) ?? {});
43
49
  function toNavigationKey(groupId, itemId) {
44
50
  return groupId ? `${groupId}::${itemId}` : `::${itemId}`;
@@ -62,6 +68,25 @@ function findNavigationByKey(navList, key) {
62
68
  }
63
69
  return void 0;
64
70
  }
71
+ function normalizePathForMatch(p) {
72
+ const trimmed = p.replace(/\/$/, "");
73
+ return trimmed === "" ? "/" : trimmed;
74
+ }
75
+ function findNavigationKeyByPath(navList, path) {
76
+ const normalized = normalizePathForMatch(path);
77
+ for (const el of navList) {
78
+ if (el.type === "item") {
79
+ if (el.external === true) continue;
80
+ if (normalizePathForMatch(el.target) === normalized) return toNavigationKey("", el.id);
81
+ } else {
82
+ for (const child of el.children) {
83
+ if (child.external === true) continue;
84
+ if (normalizePathForMatch(child.target) === normalized) return toNavigationKey(el.id, child.id);
85
+ }
86
+ }
87
+ }
88
+ return void 0;
89
+ }
65
90
  const palette = computed(() => {
66
91
  const items = [];
67
92
  for (const navigation2 of props.navigation ?? []) {
@@ -288,6 +313,25 @@ const tabs = useSessionStorage("navigation-tabs", /* @__PURE__ */ new Set(), {
288
313
  const activeTab = useSessionStorage("navigation-active-tab", void 0, {
289
314
  writeDefaults: false
290
315
  });
316
+ onMounted(() => {
317
+ const baseRaw = app.baseURL ?? "/";
318
+ const base = baseRaw === "" || baseRaw === "/" ? "/" : baseRaw.replace(/\/*$/, "") + "/";
319
+ const pathOnly = route.fullPath.replace(/\?.*$/, "").replace(/#.*$/, "");
320
+ let pathToMatch;
321
+ if (base === "/") {
322
+ pathToMatch = pathOnly;
323
+ } else if (pathOnly.startsWith(base) || pathOnly === base.slice(0, -1)) {
324
+ const remainder = pathOnly === base.slice(0, -1) ? "/" : pathOnly.slice(base.length) || "/";
325
+ pathToMatch = remainder.startsWith("/") ? remainder : `/${remainder}`;
326
+ } else {
327
+ pathToMatch = route.path;
328
+ }
329
+ const key = findNavigationKeyByPath(navigation.value, pathToMatch);
330
+ if (key !== void 0) {
331
+ tabs.value.add(key);
332
+ activeTab.value = key;
333
+ }
334
+ });
291
335
  useHead({
292
336
  title: () => activeTab.value ? findNavigationByKey(navigation.value, activeTab.value)?.title ?? config.title : config.title
293
337
  });
@@ -649,6 +693,7 @@ useHead({
649
693
  >
650
694
  {{ findNavigationByKey(navigation, tab)?.title ?? tab ?? "Unknown" }}
651
695
  <button
696
+ v-if="tabs.size > 1"
652
697
  type="button"
653
698
  class="opacity-80 group-hover/tab:opacity-100 transition-opacity cursor-pointer text-zinc-500 hover:text-(--primary) duration-180"
654
699
  @click.stop="() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shwfed/nuxt",
3
- "version": "0.1.56",
3
+ "version": "0.1.58",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "module",