@shwfed/nuxt 0.1.51 → 0.1.52

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.51",
4
+ "version": "0.1.52",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -38,6 +38,28 @@ whenever(() => meta_k?.value, () => {
38
38
  });
39
39
  const router = useRouter();
40
40
  setGlobalDslContext(await props.dsl?.pipe(Effect.scoped).pipe(Effect.runPromise) ?? {});
41
+ function toNavigationKey(groupId, itemId) {
42
+ return groupId ? `${groupId}::${itemId}` : `::${itemId}`;
43
+ }
44
+ function findNavigationByKey(navList, key) {
45
+ const parts = key.split("::");
46
+ if (parts.length < 2) return void 0;
47
+ const groupId = parts[0] ?? "";
48
+ const itemId = parts[1] ?? "";
49
+ if (groupId === "") {
50
+ for (const el of navList) {
51
+ if (el.type === "item" && el.id === itemId) return el;
52
+ }
53
+ return void 0;
54
+ }
55
+ for (const el of navList) {
56
+ if (el.type === "group" && el.id === groupId) {
57
+ const child = el.children.find((c) => c.id === itemId);
58
+ return child;
59
+ }
60
+ }
61
+ return void 0;
62
+ }
41
63
  const palette = computed(() => {
42
64
  const items = [];
43
65
  for (const navigation2 of props.navigation ?? []) {
@@ -62,8 +84,8 @@ const palette = computed(() => {
62
84
  external: $dsl.evaluate`${child.external}`(),
63
85
  effect: Effect.sync(function() {
64
86
  if ($dsl.evaluate`${child.external}`() !== true) {
65
- tabs.value.add(child.id);
66
- activeTab.value = child.id;
87
+ tabs.value.add(toNavigationKey(navigation2.id, child.id));
88
+ activeTab.value = toNavigationKey(navigation2.id, child.id);
67
89
  }
68
90
  })
69
91
  }))
@@ -81,8 +103,8 @@ const palette = computed(() => {
81
103
  external: $dsl.evaluate`${navigation2.external}`(),
82
104
  effect: Effect.sync(function() {
83
105
  if ($dsl.evaluate`${navigation2.external}`() !== true) {
84
- tabs.value.add(navigation2.id);
85
- activeTab.value = navigation2.id;
106
+ tabs.value.add(toNavigationKey("", navigation2.id));
107
+ activeTab.value = toNavigationKey("", navigation2.id);
86
108
  }
87
109
  })
88
110
  });
@@ -146,8 +168,8 @@ const navigation = computed(() => {
146
168
  target: child.target,
147
169
  effect: Effect.sync(function() {
148
170
  if ($dsl.evaluate`${child.external}`() !== true) {
149
- tabs.value.add(child.id);
150
- activeTab.value = child.id;
171
+ tabs.value.add(toNavigationKey(navigation2.id, child.id));
172
+ activeTab.value = toNavigationKey(navigation2.id, child.id);
151
173
  router.replace(child.target);
152
174
  }
153
175
  })
@@ -165,8 +187,8 @@ const navigation = computed(() => {
165
187
  target: navigation2.target,
166
188
  effect: Effect.sync(function() {
167
189
  if ($dsl.evaluate`${navigation2.external}`() !== true) {
168
- tabs.value.add(navigation2.id);
169
- activeTab.value = navigation2.id;
190
+ tabs.value.add(toNavigationKey("", navigation2.id));
191
+ activeTab.value = toNavigationKey("", navigation2.id);
170
192
  router.replace(navigation2.target);
171
193
  }
172
194
  })
@@ -219,17 +241,17 @@ const navigationFavorites = useLocalStorage("navigation-favorites", [], {
219
241
  });
220
242
  const navigationFavoritesItems = computed(() => {
221
243
  const items = [];
222
- for (const id of navigationFavorites.value) {
223
- const item = navigation.value.flatMap((item2) => item2.type === "group" ? item2.children : [item2]).find((item2) => item2.id === id);
244
+ for (const key of navigationFavorites.value) {
245
+ const item = findNavigationByKey(navigation.value, key);
224
246
  if (!item) continue;
225
247
  items.push({
226
- id: item.id,
248
+ id: key,
227
249
  title: item.title,
228
250
  icon: item.icon,
229
251
  effect: Effect.sync(function() {
230
252
  if (item.external !== true) {
231
- tabs.value.add(item.id);
232
- activeTab.value = item.id;
253
+ tabs.value.add(key);
254
+ activeTab.value = key;
233
255
  router.replace(item.target);
234
256
  }
235
257
  })
@@ -239,18 +261,18 @@ const navigationFavoritesItems = computed(() => {
239
261
  });
240
262
  const paletteFavorites = computed(() => {
241
263
  const items = [];
242
- for (const id of navigationFavorites.value) {
243
- const item = navigation.value.flatMap((item2) => item2.type === "group" ? item2.children : [item2]).find((item2) => item2.id === id);
264
+ for (const key of navigationFavorites.value) {
265
+ const item = findNavigationByKey(navigation.value, key);
244
266
  if (!item) continue;
245
267
  items.push({
246
- id: item.id,
268
+ id: key,
247
269
  title: item.title,
248
270
  icon: item.icon,
249
271
  external: item.external,
250
272
  effect: Effect.sync(function() {
251
273
  if (item.external !== true) {
252
- tabs.value.add(item.id);
253
- activeTab.value = item.id;
274
+ tabs.value.add(key);
275
+ activeTab.value = key;
254
276
  router.replace(item.target);
255
277
  }
256
278
  })
@@ -523,7 +545,7 @@ const activeTab = useSessionStorage("navigation-active-tab", void 0, {
523
545
  <Collapsible
524
546
  v-if="el.type === 'group'"
525
547
  class="group/collapsible"
526
- :default-open="el.children.some((child) => child.id === activeTab)"
548
+ :default-open="el.children.some((child) => toNavigationKey(el.id, child.id) === activeTab)"
527
549
  as-child
528
550
  >
529
551
  <SidebarMenuItem>
@@ -548,7 +570,7 @@ const activeTab = useSessionStorage("navigation-active-tab", void 0, {
548
570
  >
549
571
  <SidebarMenuSubButton
550
572
  as-child
551
- :is-active="item.id === activeTab"
573
+ :is-active="toNavigationKey(el.id, item.id) === activeTab"
552
574
  >
553
575
  <button
554
576
  type="button"
@@ -563,21 +585,22 @@ const activeTab = useSessionStorage("navigation-active-tab", void 0, {
563
585
  </button>
564
586
  </SidebarMenuSubButton>
565
587
  <SidebarMenuAction
566
- :class="['transition-opacity duration-80 text-yellow-400 -translate-y-1/2', !navigationFavorites.includes(item.id) && 'group-hover/menu-sub-item:opacity-100 opacity-0 ']"
588
+ :class="['transition-opacity duration-80 text-yellow-400 -translate-y-1/2', !navigationFavorites.includes(toNavigationKey(el.id, item.id)) && 'group-hover/menu-sub-item:opacity-100 opacity-0 ']"
567
589
  as-child
568
590
  >
569
591
  <button
570
592
  type="button"
571
593
  @click="() => {
572
- if (navigationFavorites.includes(item.id)) {
573
- navigationFavorites = navigationFavorites.filter((id) => id !== item.id);
594
+ const key = toNavigationKey(el.id, item.id);
595
+ if (navigationFavorites.includes(key)) {
596
+ navigationFavorites = navigationFavorites.filter((id) => id !== key);
574
597
  } else {
575
- navigationFavorites = Array.from(/* @__PURE__ */ new Set([...navigationFavorites, item.id]));
598
+ navigationFavorites = Array.from(/* @__PURE__ */ new Set([...navigationFavorites, key]));
576
599
  }
577
600
  }"
578
601
  >
579
602
  <Icon
580
- v-if="navigationFavorites.includes(item.id)"
603
+ v-if="navigationFavorites.includes(toNavigationKey(el.id, item.id))"
581
604
  icon="fluent:star-20-filled"
582
605
  class="text-yellow-400"
583
606
  />
@@ -607,7 +630,7 @@ const activeTab = useSessionStorage("navigation-active-tab", void 0, {
607
630
  </SidebarContent>
608
631
  </Sidebar>
609
632
  </SidebarProvider>
610
- <main class="flex-1 flex flex-col bg-zinc-100">
633
+ <main class="flex-1 flex flex-col bg-zinc-100 overflow-hidden">
611
634
  <nav class="bg-white p-1 border-b border-zinc-100 h-10 flex items-center justify-start gap-1 overflow-x-hidden cursor-pointer min-w-0">
612
635
  <div
613
636
  v-for="tab in tabs"
@@ -615,20 +638,22 @@ const activeTab = useSessionStorage("navigation-active-tab", void 0, {
615
638
  :class="['border rounded cursor-pointer px-2 py-1 text-sm flex items-center gap-2 truncate', activeTab === tab ? 'text-(--primary) border-(--primary)' : 'text-zinc-500 border-zinc-300 hover:text-zinc-700']"
616
639
  @click="() => {
617
640
  activeTab = tab;
618
- $router.replace(navigation.flatMap((item2) => item2.type === 'group' ? item2.children : [item2]).find((item2) => item2.id === tab)?.target ?? '');
641
+ const item2 = findNavigationByKey(navigation, tab);
642
+ $router.replace(item2?.target ?? '');
619
643
  }"
620
644
  >
621
- {{ navigation.flatMap((item2) => item2.type === "group" ? item2.children : [item2]).find((item2) => item2.id === tab)?.title }}
645
+ {{ findNavigationByKey(navigation, tab)?.title ?? tab ?? "Unknown" }}
622
646
  <button
623
647
  type="button"
624
648
  class="opacity-80 group-hover/tab:opacity-100 transition-opacity cursor-pointer text-zinc-500 hover:text-(--primary) duration-180"
625
649
  @click.stop="() => {
626
650
  if (activeTab === tab) {
627
- const idx = Array.from(tabs).findIndex((tab2) => tab2 === activeTab) - 1;
651
+ const idx = Array.from(tabs).findIndex((t2) => t2 === activeTab) - 1;
628
652
  const previous = Array.from(tabs)[idx];
629
653
  if (previous) {
630
654
  activeTab = previous;
631
- $router.replace(navigation.flatMap((item2) => item2.type === 'group' ? item2.children : [item2]).find((item2) => item2.id === previous)?.target ?? '');
655
+ const item2 = findNavigationByKey(navigation, previous);
656
+ $router.replace(item2?.target ?? '');
632
657
  } else {
633
658
  activeTab = void 0;
634
659
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shwfed/nuxt",
3
- "version": "0.1.51",
3
+ "version": "0.1.52",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "module",