@happydesigns/ui 0.13.5 → 0.15.0

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.
Files changed (40) hide show
  1. package/README.md +53 -94
  2. package/app/app.config.ts +168 -169
  3. package/app/app.vue +11 -0
  4. package/app/components/article/ArticleGrid.vue +134 -158
  5. package/app/components/article/ArticleGridDate.vue +1 -1
  6. package/app/components/article/ArticleHeaderBody.vue +20 -20
  7. package/app/components/article/ArticleHeadlineMeta.vue +26 -26
  8. package/app/components/article/ArticleList.vue +80 -95
  9. package/app/components/article/ArticlePage.vue +17 -16
  10. package/app/components/footer/FooterColumnHeading.vue +5 -5
  11. package/app/components/footer/FooterColumns.vue +16 -20
  12. package/app/components/footer/FooterCopyright.vue +35 -29
  13. package/app/components/traits/Authors.vue +21 -20
  14. package/app/components/traits/BackButton.vue +15 -26
  15. package/app/components/traits/Category.vue +9 -9
  16. package/app/components/traits/CopyButton.vue +32 -39
  17. package/app/components/traits/Dates.vue +20 -20
  18. package/app/components/traits/Links.vue +17 -17
  19. package/app/components/traits/Location.vue +20 -20
  20. package/app/components/traits/Separator.vue +21 -26
  21. package/app/components/traits/SeparatorButtons.vue +54 -56
  22. package/app/components/traits/Surround.vue +51 -60
  23. package/app/components/traits/Toc.vue +16 -16
  24. package/app/composables/useArticleList.ts +13 -15
  25. package/app/composables/useArticleListQuery.ts +54 -0
  26. package/app/composables/useCategoryBadge.ts +27 -27
  27. package/app/composables/useClipboard.ts +26 -26
  28. package/app/composables/usePageContent.ts +18 -18
  29. package/app/composables/usePageSeo.ts +30 -30
  30. package/app/layouts/article.vue +120 -128
  31. package/app/layouts/content.vue +59 -67
  32. package/app/layouts/default.vue +1 -10
  33. package/app/types/config.ts +13 -6
  34. package/app/utils/resolveUsers.ts +32 -3
  35. package/content.config.ts +6 -6
  36. package/nuxt.config.ts +72 -80
  37. package/package.json +29 -18
  38. package/schemas/collections.ts +46 -46
  39. package/schemas/index.ts +2 -2
  40. package/schemas/traits.ts +90 -90
@@ -1,60 +1,51 @@
1
- <script setup lang="ts" generic="C extends keyof PageCollections = 'article'">
2
- import type { PageCollections } from '@nuxt/content'
3
-
4
- const props = withDefaults(defineProps<{
5
- collection?: C
6
- show?: boolean
7
- prevIcon?: string
8
- nextIcon?: string
9
- fields?: string[]
10
- where?: any[]
11
- order?: { field: string, direction: 'ASC' | 'DESC' } | false
12
- }>(), {
13
- order: undefined,
14
- })
15
-
16
- const { config } = useVariant(() => props.collection || 'article')
17
- const vc = computed(() => config.value as any)
18
-
19
- const resolvedShow = computed(() => props.show ?? vc.value.surround?.show)
20
- const resolvedPrevIcon = computed(() => props.prevIcon ?? vc.value.surround?.prevIcon)
21
- const resolvedNextIcon = computed(() => props.nextIcon ?? vc.value.surround?.nextIcon)
22
-
23
- const route = useRoute()
24
-
25
- const { data: surround } = await useAsyncData(
26
- `surround-${String(props.collection || 'article')}-${route.path}`,
27
- () => {
28
- const colName = (props.collection || 'article') as any
29
- const qc = vc.value.query || {}
30
-
31
- const fields = (props.fields || qc.fields || ['title', 'description', 'status']) as any
32
- const order = props.order !== undefined ? props.order : qc.order
33
- const where = props.where || qc.where || [{ field: 'status', operator: '=', value: 'published' }]
34
-
35
- let query = queryCollectionItemSurroundings(colName, route.path, { fields })
36
-
37
- if (where && Array.isArray(where)) {
38
- where.forEach((filter) => {
39
- query = query.where(filter.field as any, filter.operator, filter.value)
40
- })
41
- }
42
-
43
- if (order) {
44
- query = query.order(order.field as any, order.direction)
45
- }
46
-
47
- return query
48
- },
49
- )
50
- </script>
51
-
52
- <template>
53
- <div v-if="resolvedShow && surround?.length" class="mt-12">
54
- <UContentSurround
55
- :surround="surround"
56
- :prev-icon="resolvedPrevIcon"
57
- :next-icon="resolvedNextIcon"
58
- />
59
- </div>
60
- </template>
1
+ <script setup lang="ts" generic="C extends keyof PageCollections ">
2
+ import type { PageCollections } from '@nuxt/content'
3
+ import type { QueryConfig } from '../../types/config'
4
+
5
+ const props = defineProps<{
6
+ collection: C
7
+ show?: boolean
8
+ prevIcon?: string
9
+ nextIcon?: string
10
+ query?: QueryConfig
11
+ }>()
12
+
13
+ const route = useRoute()
14
+ const collection = computed(() => props.collection || 'article')
15
+ const path = computed(() => route.path)
16
+ const key = computed(() => `surround-${String(collection.value)}-${path.value}`)
17
+
18
+ const { data: surround } = await useAsyncData(
19
+ key,
20
+ () => {
21
+ const colName = collection.value as any
22
+ const qc = props.query || {}
23
+
24
+ const fields = (qc.fields || ['title', 'description', 'status']) as any
25
+ const order = qc.order
26
+ const where = qc.where || [{ field: 'status', operator: '=', value: 'published' }]
27
+
28
+ let query = queryCollectionItemSurroundings(colName, path.value, { fields })
29
+
30
+ where.forEach((filter) => {
31
+ query = query.where(filter.field as any, filter.operator as any, filter.value)
32
+ })
33
+
34
+ if (order) {
35
+ query = query.order(order.field as any, order.direction)
36
+ }
37
+
38
+ return query
39
+ },
40
+ )
41
+ </script>
42
+
43
+ <template>
44
+ <div v-if="show && surround?.some(Boolean)" class="mt-12">
45
+ <UContentSurround
46
+ :surround="surround"
47
+ :prev-icon="prevIcon"
48
+ :next-icon="nextIcon"
49
+ />
50
+ </div>
51
+ </template>
@@ -1,16 +1,16 @@
1
- <script setup lang="ts">
2
- const props = defineProps<{
3
- links?: any[]
4
- title?: string
5
- }>()
6
-
7
- const appConfig = useAppConfig()
8
- </script>
9
-
10
- <template>
11
- <UContentToc
12
- v-if="links?.length"
13
- :links="links"
14
- :title="title || appConfig.app.toc?.title"
15
- />
16
- </template>
1
+ <script setup lang="ts">
2
+ defineProps<{
3
+ links?: any[]
4
+ title?: string
5
+ }>()
6
+
7
+ const appConfig = useAppConfig()
8
+ </script>
9
+
10
+ <template>
11
+ <UContentToc
12
+ v-if="links?.length"
13
+ :links="links"
14
+ :title="title || appConfig.app.toc?.title"
15
+ />
16
+ </template>
@@ -22,6 +22,8 @@ export interface UseArticleListOptions<C extends keyof PageCollections = 'articl
22
22
  sort?: MaybeRefOrGetter<{ field: string, direction: 'ASC' | 'DESC' } | false | undefined>
23
23
  /** Status to filter by. Set to false to disable default status filtering. Defaults to 'published'. */
24
24
  status?: MaybeRefOrGetter<string | false | undefined>
25
+ /** Whether the list should load lazily during client-side navigation. Defaults to false. */
26
+ lazy?: MaybeRefOrGetter<boolean | undefined>
25
27
  }
26
28
 
27
29
  /**
@@ -38,15 +40,13 @@ export function useArticleList<C extends keyof PageCollections = 'article'>(opti
38
40
  const category = computed(() => toValue(options.category))
39
41
  const labelAll = computed(() => toValue(options.labelAll) || config.value.list?.labelAll || 'All')
40
42
 
41
- const queryDefaults = computed(() => config.value.query || {})
42
-
43
43
  const where = computed(() => {
44
44
  const w = toValue(options.where)
45
45
  if (w)
46
46
  return w
47
47
 
48
48
  // Fallback to config where but filter out status if handled separately
49
- return queryDefaults.value.where?.filter(f => f.field !== 'status') || []
49
+ return config.value.query?.where?.filter(f => f.field !== 'status') || []
50
50
  })
51
51
 
52
52
  const sort = computed(() => {
@@ -54,7 +54,7 @@ export function useArticleList<C extends keyof PageCollections = 'article'>(opti
54
54
  if (s !== undefined)
55
55
  return s
56
56
 
57
- return queryDefaults.value.order
57
+ return config.value.query?.order
58
58
  })
59
59
 
60
60
  const status = computed(() => {
@@ -66,7 +66,7 @@ export function useArticleList<C extends keyof PageCollections = 'article'>(opti
66
66
  return s
67
67
 
68
68
  // Try to find status in config where
69
- const statusFilter = queryDefaults.value.where?.find(f => f.field === 'status')
69
+ const statusFilter = config.value.query?.where?.find(f => f.field === 'status')
70
70
  return statusFilter?.value || 'published'
71
71
  })
72
72
 
@@ -117,15 +117,9 @@ export function useArticleList<C extends keyof PageCollections = 'article'>(opti
117
117
  let resolvedBadge: BadgeProps | undefined
118
118
 
119
119
  if (categoryKey) {
120
- const categories = config.value.categories || {}
121
- if (categoryKey in categories) {
122
- resolvedBadge = categories[categoryKey] as BadgeProps
123
- }
124
- else {
125
- resolvedBadge = {
126
- label: categoryKey,
127
- color: 'primary',
128
- }
120
+ resolvedBadge = config.value.categories?.[categoryKey] ?? {
121
+ label: categoryKey,
122
+ color: 'primary',
129
123
  }
130
124
  }
131
125
 
@@ -151,6 +145,10 @@ export function useArticleList<C extends keyof PageCollections = 'article'>(opti
151
145
  total,
152
146
  }
153
147
  }, {
154
- keepPreviousData: true,
148
+ lazy: toValue(options.lazy) ?? false,
149
+ default: () => ({
150
+ articles: [],
151
+ total: 0,
152
+ }),
155
153
  })
156
154
  }
@@ -0,0 +1,54 @@
1
+ interface UseArticleListQueryOptions {
2
+ labelAll: Ref<string>
3
+ fixedCategory?: Ref<string | undefined>
4
+ }
5
+
6
+ /**
7
+ * Manages URL query sync for article list pagination and category filtering.
8
+ * Shared between ArticleList (category tabs) and ArticleGrid (pagination).
9
+ */
10
+ export function useArticleListQuery({ labelAll, fixedCategory }: UseArticleListQueryOptions) {
11
+ const route = useRoute()
12
+
13
+ const page = ref(Number(route.query.page) || 1)
14
+ const selectedCategory = ref(
15
+ fixedCategory?.value || (route.query.category as string) || labelAll.value,
16
+ )
17
+
18
+ // Sync selectedCategory when the fixed prop changes
19
+ watch(
20
+ () => fixedCategory?.value,
21
+ (val) => {
22
+ if (val)
23
+ selectedCategory.value = val
24
+ },
25
+ )
26
+
27
+ function updateQuery({ resetPage = false } = {}) {
28
+ const query: Record<string, string | number> = { ...route.query as Record<string, string> }
29
+
30
+ if (resetPage || page.value === 1)
31
+ delete (query as any).page
32
+ else
33
+ query.page = page.value
34
+
35
+ if (!fixedCategory?.value) {
36
+ if (selectedCategory.value !== labelAll.value)
37
+ query.category = selectedCategory.value
38
+ else
39
+ delete (query as any).category
40
+ }
41
+
42
+ navigateTo({ query })
43
+ }
44
+
45
+ // Sync back on browser navigation
46
+ watch(() => route.query, (newQuery) => {
47
+ page.value = Number(newQuery.page) || 1
48
+ if (!fixedCategory?.value) {
49
+ selectedCategory.value = (newQuery.category as string) || labelAll.value
50
+ }
51
+ })
52
+
53
+ return { page, selectedCategory, updateQuery }
54
+ }
@@ -1,27 +1,27 @@
1
- /**
2
- * Resolves a category badge reactively using the global application configuration.
3
- *
4
- * @param category - The reactive category string to resolve.
5
- * @param collection - The collection to resolve categories for. Defaults to 'article'.
6
- * @returns A computed property containing the resolved badge configuration.
7
- */
8
- export function useCategoryBadge(
9
- category: MaybeRefOrGetter<string | undefined | null>,
10
- collection: MaybeRefOrGetter<string> = 'article',
11
- ) {
12
- const { config } = useVariant(collection)
13
-
14
- return computed(() => {
15
- const categoryKey = toValue(category)
16
- const categories = config.value.categories
17
-
18
- if (categoryKey && categories && categoryKey in categories) {
19
- return categories[categoryKey]
20
- }
21
-
22
- return {
23
- label: categoryKey ?? '',
24
- color: 'primary',
25
- }
26
- })
27
- }
1
+ /**
2
+ * Resolves a category badge reactively using the global application configuration.
3
+ *
4
+ * @param category - The reactive category string to resolve.
5
+ * @param collection - The collection to resolve categories for. Defaults to 'article'.
6
+ * @returns A computed property containing the resolved badge configuration.
7
+ */
8
+ export function useCategoryBadge(
9
+ category: MaybeRefOrGetter<string | undefined | null>,
10
+ collection: MaybeRefOrGetter<string> = 'article',
11
+ ) {
12
+ const { config } = useVariant(collection)
13
+
14
+ return computed(() => {
15
+ const categoryKey = toValue(category)
16
+ const categories = config.value.categories
17
+
18
+ if (categoryKey && categories && categoryKey in categories) {
19
+ return categories[categoryKey]
20
+ }
21
+
22
+ return {
23
+ label: categoryKey ?? '',
24
+ color: 'primary',
25
+ }
26
+ })
27
+ }
@@ -1,26 +1,26 @@
1
- import type { ToastProps } from '#ui/types'
2
- import { useClipboard as _useClipboard } from '@vueuse/core'
3
-
4
- export function useClipboard() {
5
- const { copy: _copy, copied } = _useClipboard()
6
-
7
- const toast = useToast()
8
-
9
- const copy = (source: string, options?: Partial<ToastProps> & { id?: string | number }) => {
10
- _copy(source)
11
- if (options) {
12
- // Check if toast with this ID already exists to prevent spam
13
- if (options.id && toast.toasts.value.some(t => t.id === options.id)) {
14
- toast.update(options.id, options)
15
- }
16
- else {
17
- toast.add(options as any)
18
- }
19
- }
20
- }
21
-
22
- return {
23
- copy,
24
- copied,
25
- }
26
- }
1
+ import type { ToastProps } from '#ui/types'
2
+ import { useClipboard as _useClipboard } from '@vueuse/core'
3
+
4
+ export function useClipboard() {
5
+ const { copy: _copy, copied } = _useClipboard()
6
+
7
+ const toast = useToast()
8
+
9
+ const copy = (source: string, options?: Partial<ToastProps> & { id?: string | number }) => {
10
+ _copy(source)
11
+ if (options) {
12
+ // Check if toast with this ID already exists to prevent spam
13
+ if (options.id && toast.toasts.value.some(t => t.id === options.id)) {
14
+ toast.update(options.id, options)
15
+ }
16
+ else {
17
+ toast.add(options as any)
18
+ }
19
+ }
20
+ }
21
+
22
+ return {
23
+ copy,
24
+ copied,
25
+ }
26
+ }
@@ -1,31 +1,31 @@
1
- import type { Collections } from '@nuxt/content'
2
- import type { AsyncData } from 'nuxt/app'
3
- import type { MaybeRefOrGetter } from 'vue'
4
- import { computed, toValue } from 'vue'
5
-
6
- interface UsePageContentOptions<C extends keyof Collections = 'page'> {
1
+ import type { PageCollections } from '@nuxt/content'
2
+ import type { AsyncData } from 'nuxt/app'
3
+ import type { MaybeRefOrGetter } from 'vue'
4
+ import { computed, toValue } from 'vue'
5
+
6
+ interface UsePageContentOptions<C extends keyof PageCollections = 'page'> {
7
7
  path?: MaybeRefOrGetter<string | undefined>
8
8
  collection?: MaybeRefOrGetter<C>
9
9
  }
10
-
11
- /**
12
- * Composable to fetch content from a Nuxt Content collection.
13
- *
10
+
11
+ /**
12
+ * Composable to fetch content from a Nuxt Content collection.
13
+ *
14
14
  * @param options - Configuration options for fetching content
15
15
  * @param options.path - Optional path to fetch. Defaults to current route path.
16
16
  * @param options.collection - Optional collection to fetch from. Defaults to 'page'.
17
17
  */
18
- export function usePageContent<C extends keyof Collections = 'page', B = object>(
18
+ export function usePageContent<C extends keyof PageCollections = 'page', B = object>(
19
19
  { path, collection }: UsePageContentOptions<C> = {},
20
20
  ) {
21
- const route = useRoute()
22
- const resolvedPath = computed(() => toValue(path) ?? route.path)
23
- const resolvedCollection = computed(() => (toValue(collection) ?? ('page' as C)) as C)
24
- const key = computed(() => `${String(resolvedCollection.value)}:${resolvedPath.value}`)
25
-
26
- const handler = () => queryCollection(resolvedCollection.value as keyof Collections).path(resolvedPath.value).first()
21
+ const route = useRoute()
22
+ const resolvedPath = computed(() => toValue(path) ?? route.path)
23
+ const resolvedCollection = computed(() => (toValue(collection) ?? ('page' as C)) as C)
24
+ const key = computed(() => `${String(resolvedCollection.value)}:${resolvedPath.value}`)
25
+
26
+ const handler = () => queryCollection(resolvedCollection.value as keyof PageCollections).path(resolvedPath.value).first()
27
27
 
28
28
  return useAsyncData(key, handler, {
29
29
  watch: [resolvedPath, resolvedCollection],
30
- }) as unknown as AsyncData<(Collections[C] & B) | null, Error | null>
30
+ }) as unknown as AsyncData<(PageCollections[C] & B) | null, Error | null>
31
31
  }
@@ -1,30 +1,30 @@
1
- import { watchEffect } from 'vue'
2
-
3
- interface SeoRelevantPageData {
4
- seo?: {
5
- title?: string
6
- description?: string
7
- ogTitle?: string
8
- ogDescription?: string
9
- }
10
- title?: string
11
- description?: string
12
- }
13
-
14
- export function usePageSeo(page: Ref<SeoRelevantPageData | null | undefined>) {
15
- watchEffect(() => {
16
- if (page.value) {
17
- const title = page.value.seo?.title || page.value.title
18
- const description = page.value.seo?.description || page.value.description
19
- const ogTitle = page.value.seo?.ogTitle || title
20
- const ogDescription = page.value.seo?.ogDescription || description
21
-
22
- useSeoMeta({
23
- title,
24
- ogTitle,
25
- description,
26
- ogDescription,
27
- })
28
- }
29
- })
30
- }
1
+ import { watchEffect } from 'vue'
2
+
3
+ interface SeoRelevantPageData {
4
+ seo?: {
5
+ title?: string
6
+ description?: string
7
+ ogTitle?: string
8
+ ogDescription?: string
9
+ }
10
+ title?: string
11
+ description?: string
12
+ }
13
+
14
+ export function usePageSeo(page: Ref<SeoRelevantPageData | null | undefined>) {
15
+ watchEffect(() => {
16
+ if (page.value) {
17
+ const title = page.value.seo?.title || page.value.title
18
+ const description = page.value.seo?.description || page.value.description
19
+ const ogTitle = page.value.seo?.ogTitle || title
20
+ const ogDescription = page.value.seo?.ogDescription || description
21
+
22
+ useSeoMeta({
23
+ title,
24
+ ogTitle,
25
+ description,
26
+ ogDescription,
27
+ })
28
+ }
29
+ })
30
+ }