ketekny-ui-kit 1.0.143 → 1.0.144

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,7 +1,7 @@
1
1
  {
2
2
  "name": "ketekny-ui-kit",
3
3
  "type": "module",
4
- "version": "1.0.143",
4
+ "version": "1.0.144",
5
5
  "description": "A Vue 3 UI component library with Tailwind CSS styling",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -102,8 +102,12 @@ export default {
102
102
  default: null,
103
103
  validator: value => value === null || ['dark', 'light'].includes(value),
104
104
  },
105
+ favorites: {
106
+ type: Array,
107
+ default: null,
108
+ },
105
109
  },
106
- emits: ['select', 'logo-click', 'signin', 'signup', 'signout', 'edit-profile', 'item-click'],
110
+ emits: ['select', 'logo-click', 'signin', 'signup', 'signout', 'edit-profile', 'item-click', 'update:favorites'],
107
111
  data() {
108
112
  return {
109
113
  demoAvatarUrl,
@@ -142,6 +146,9 @@ export default {
142
146
  hasAccount() {
143
147
  return Boolean(this.account)
144
148
  },
149
+ isControlledFavorites() {
150
+ return Array.isArray(this.favorites)
151
+ },
145
152
  accountDisplayName() {
146
153
  if (!this.account) return ''
147
154
  return [this.account.firstName, this.account.lastName].filter(Boolean).join(' ') || 'Account'
@@ -243,12 +250,18 @@ export default {
243
250
  deep: true,
244
251
  immediate: true,
245
252
  },
253
+ favorites: {
254
+ handler() {
255
+ this.syncFavoritesFromMenu()
256
+ },
257
+ deep: true,
258
+ },
246
259
  $route() {
247
260
  this.syncActiveFromMenu()
248
261
  },
249
262
  favoriteIds: {
250
263
  handler(value) {
251
- this.persistFavorites(value)
264
+ if (!this.isControlledFavorites) this.persistFavorites(value)
252
265
  if (!value.size && this.activeMenuTab === 'favorites') this.activeMenuTab = 'all'
253
266
  },
254
267
  deep: false,
@@ -301,19 +314,33 @@ export default {
301
314
  }
302
315
  return ids
303
316
  },
317
+ normalizeFavorite(value) {
318
+ return String(value ?? '').replace(/^\/+/, '').trim()
319
+ },
320
+ favoriteValue(item) {
321
+ const value = item?.link?.to ?? item?.to ?? item?.link?.href ?? item?.href
322
+ return this.normalizeFavorite(typeof value === 'string' ? value : item?.id)
323
+ },
304
324
  syncFavoritesFromMenu() {
305
- const storedFavorites = this.readStoredFavorites()
325
+ const storedFavorites = this.isControlledFavorites ? this.favorites : this.readStoredFavorites()
306
326
  const storedTab = this.readStoredActiveMenuTab()
327
+ const controlledFavorites = new Set(storedFavorites.map(value => this.normalizeFavorite(value)))
307
328
  const discovered = []
308
329
  const collect = (items) => {
309
330
  for (const item of items) {
310
- if (item?.favorite && !item?.children?.length) discovered.push(item.id)
331
+ if (
332
+ !item?.children?.length
333
+ && (this.isControlledFavorites
334
+ ? controlledFavorites.has(this.favoriteValue(item))
335
+ || controlledFavorites.has(this.normalizeFavorite(item?.id))
336
+ : item?.favorite)
337
+ ) discovered.push(item.id)
311
338
  if (item?.children?.length) collect(item.children)
312
339
  }
313
340
  }
314
341
  collect(this.mainMenu)
315
- this.favoriteIds = new Set([...discovered, ...storedFavorites])
316
- if (storedTab === 'favorites' && (this.favoriteIds.size > 0 || discovered.length > 0)) {
342
+ this.favoriteIds = new Set(this.isControlledFavorites ? discovered : [...discovered, ...storedFavorites])
343
+ if (storedTab === 'favorites' && this.favoriteIds.size > 0) {
317
344
  this.activeMenuTab = 'favorites'
318
345
  } else {
319
346
  this.activeMenuTab = 'all'
@@ -444,6 +471,16 @@ export default {
444
471
  if (next.has(item.id)) next.delete(item.id)
445
472
  else next.add(item.id)
446
473
  this.favoriteIds = next
474
+ if (this.isControlledFavorites) {
475
+ const favorites = new Set(this.favorites.map(value => this.normalizeFavorite(value)))
476
+ const value = this.favoriteValue(item)
477
+ if (next.has(item.id)) favorites.add(value)
478
+ else {
479
+ favorites.delete(value)
480
+ favorites.delete(this.normalizeFavorite(item.id))
481
+ }
482
+ this.$emit('update:favorites', Array.from(favorites))
483
+ }
447
484
  if (next.size && this.activeMenuTab !== 'favorites' && this.activeMenuTab !== 'all') {
448
485
  this.activeMenuTab = 'all'
449
486
  }
@@ -16,6 +16,8 @@
16
16
  :account-menu-items="accountMenuItems"
17
17
  :contact-email="contactEmail"
18
18
  :help-url="helpUrl"
19
+ :favorites="favorites"
20
+ @update:favorites="$emit('update:favorites', $event)"
19
21
  @logo-click="handleLogoClick"
20
22
  @signin="handleSignin"
21
23
  @signup="handleSignup"
@@ -118,8 +120,12 @@ export default {
118
120
  default: null,
119
121
  validator: value => value === null || ["dark", "light"].includes(value),
120
122
  },
123
+ favorites: {
124
+ type: Array,
125
+ default: null,
126
+ },
121
127
  },
122
- emits: ["select-menu", "logo-click", "signin", "signup", "signout", "edit-profile", "item-click"],
128
+ emits: ["select-menu", "logo-click", "signin", "signup", "signout", "edit-profile", "item-click", "update:favorites"],
123
129
  data() {
124
130
  return {
125
131
  mobileMenuOpen: false,