picocrank 1.8.6 → 1.8.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "picocrank",
3
- "version": "1.8.6",
3
+ "version": "1.8.8",
4
4
  "description": "A set of zero dependency Vue components built on the Femtocrank global CSS theme.",
5
5
  "main": "vite.config.js",
6
6
  "scripts": {
@@ -38,37 +38,4 @@ const props = defineProps({
38
38
  default: "",
39
39
  },
40
40
  });
41
- </script>
42
-
43
- <style scoped>
44
- :slotted(.section-header button).neutral,
45
- :slotted(.section-header .button).neutral
46
- {
47
- background-color: white;
48
- color: #000;
49
- }
50
-
51
- :slotted(.section-header .button:hover).neutral,
52
- :slotted(.section-header .button:hover).neutral
53
- {
54
- background-color: #f0f0f0;
55
- }
56
-
57
- @media (prefers-color-scheme: dark) {
58
- :slotted(.section-header button).neutral,
59
- :slotted(.section-header .button).neutral
60
- {
61
- background-color: #111;
62
- border: 1px solid #222;
63
- color: #fff;
64
- }
65
-
66
- :slotted(.section-header button:hover).neutral,
67
- :slotted(.section-header .button:hover).neutral
68
- {
69
- background-color: #222;
70
- border: 1px solid #333;
71
- color: #fff;
72
- }
73
- }
74
- </style>
41
+ </script>
@@ -19,16 +19,16 @@
19
19
  <!-- Render separator if link is a separator -->
20
20
  <div v-if="link.type === 'separator'" class="separator"></div>
21
21
  <div v-else-if="link.type === 'callback'">
22
- <a href="#" @click.prevent="link.callback()">
22
+ <a href="#" @click.prevent="handleLinkClick(() => link.callback())">
23
23
  <HugeiconsIcon :icon="link.icon" />
24
24
  <span>{{ link.title }}</span>
25
25
  </a>
26
26
  </div>
27
27
  <div v-else-if="link.type === 'html'" v-html="link.html"></div>
28
- <router-link v-else :to="link.path" :class="{ active: isActive(link.path) }">
29
- <HugeiconsIcon :icon="link.icon" />
30
- <span>{{ link.title }}</span>
31
- </router-link>
28
+ <router-link v-else v-bind="link.props || {}" :to="link.to || link.path" :class="{ active: isActive(link) }" @click="handleLinkClick()">
29
+ <HugeiconsIcon :icon="link.icon" />
30
+ <span>{{ link.title }}</span>
31
+ </router-link>
32
32
  </li>
33
33
  </ul>
34
34
  </nav>
@@ -49,22 +49,44 @@ const navigationLinks = ref([])
49
49
  const route = useRoute()
50
50
  const router = useRouter()
51
51
 
52
- function addRouterLink(link, altTitle = null) {
53
- const route = router.getRoutes().find(r => r.name === link)
52
+ /**
53
+ * Add a router link to the sidebar navigation
54
+ * @param {string} link - Route name
55
+ * @param {string|null} altTitle - Optional alternative title
56
+ * @param {object} options - Additional options
57
+ * @param {object} options.params - Route params to pass (e.g., { id: 1 })
58
+ * @param {object} options.props - Props to pass to router-link (e.g., { replace: true, custom: true })
59
+ * @param {object|string} options.to - Override the 'to' prop (if provided, takes precedence over params)
60
+ */
61
+ function addRouterLink(link, altTitle = null, options = {}) {
62
+ const foundRoute = router.getRoutes().find(r => r.name === link)
63
+
64
+ if (!foundRoute) {
65
+ console.warn(`Route "${link}" not found`)
66
+ return
67
+ }
54
68
 
55
- const title = altTitle || route.meta.title || route.name
69
+ const title = altTitle || foundRoute.meta?.title || foundRoute.name
56
70
 
57
- if (route) {
58
- const routeLink = {
59
- name: link,
60
- title: title,
61
- path: route.path,
62
- icon: route.meta.icon || PinIcon,
63
- type: 'route'
64
- }
71
+ // Determine the 'to' value: use options.to if provided, otherwise construct from params, or fall back to path
72
+ let toValue = foundRoute.path
73
+ if (options.to) {
74
+ toValue = options.to
75
+ } else if (options.params) {
76
+ toValue = { name: link, params: options.params }
77
+ }
65
78
 
66
- addNavigationLink(routeLink)
79
+ const routeLink = {
80
+ name: link,
81
+ title: title,
82
+ path: foundRoute.path,
83
+ to: toValue,
84
+ icon: foundRoute.meta?.icon || PinIcon,
85
+ type: 'route',
86
+ props: options.props || {}
67
87
  }
88
+
89
+ addNavigationLink(routeLink)
68
90
  }
69
91
 
70
92
  function addNavigationLink(link) {
@@ -145,8 +167,43 @@ function close() {
145
167
  isStuck.value = false
146
168
  }
147
169
 
148
- function isActive(path) {
149
- return route.path === path
170
+ function isActive(link) {
171
+ // If link has a 'to' object with a name, compare route name and params
172
+ if (link.to && typeof link.to === 'object' && link.to.name) {
173
+ // Compare route names first
174
+ if (route.name !== link.to.name) {
175
+ return false
176
+ }
177
+
178
+ // If params are specified in the link, all specified params must match
179
+ if (link.to.params && Object.keys(link.to.params).length > 0) {
180
+ const linkParams = link.to.params
181
+ const routeParams = route.params
182
+
183
+ // Check if all params in link.to.params match route.params
184
+ for (const key in linkParams) {
185
+ if (String(routeParams[key]) !== String(linkParams[key])) {
186
+ return false
187
+ }
188
+ }
189
+ }
190
+
191
+ // Route name matches, and either no params specified or all params match
192
+ return true
193
+ }
194
+
195
+ // Fall back to path comparison for string paths
196
+ const linkPath = typeof link.to === 'string' ? link.to : link.path
197
+ return route.path === linkPath
198
+ }
199
+
200
+ function handleLinkClick(callback = null) {
201
+ if (callback) {
202
+ callback()
203
+ }
204
+ if (!isStuck.value) {
205
+ close()
206
+ }
150
207
  }
151
208
 
152
209
  defineExpose({
@@ -80,7 +80,6 @@
80
80
  return [...items.value].sort((a, b) => {
81
81
  const av = a[col];
82
82
  const bv = b[col];
83
- console.log("sort values", col, av, bv)
84
83
 
85
84
  if (av === bv) return 0;
86
85
  if (av === null || av === undefined) return 1;
@@ -123,8 +122,6 @@
123
122
  sortBy.value = header.key;
124
123
  sortDir.value = 'asc';
125
124
  }
126
-
127
- console.log(`Sorting by ${sortBy.value} in ${sortDir.value} order`);
128
125
  }
129
126
  </script>
130
127
 
package/vue/views/App.vue CHANGED
@@ -59,9 +59,9 @@
59
59
  sidebar.value.addRouterLink('TableExample')
60
60
  sidebar.value.addRouterLink('CalendarExample')
61
61
  sidebar.value.addSeparator('separator-1');
62
- sidebar.value.addRouterLink('ViewItem', { id: 1 })
62
+ sidebar.value.addRouterLink('ViewItem', 'View Awesome Item', { params: { id: 1 } })
63
63
  sidebar.value.addSeparator('separator-2');
64
- sidebar.value.addCallback('Hello World', helloWorld, { icon: Pin02Icon })
64
+ sidebar.value.addCallback('Callback Example', helloWorld, { icon: Pin02Icon })
65
65
  sidebar.value.addSeparator('separator-3');
66
66
  sidebar.value.addHtml('<h2 style = "padding: 0.75em;">Administration</h2>', { name: 'admin-heading' })
67
67
  sidebar.value.addRouterLink('Admin')