@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,128 +1,120 @@
1
- <script setup lang="ts" generic="C extends keyof PageCollections & ('article' | 'event') = 'article'">
2
- import type { PageCollections } from '@nuxt/content'
3
-
4
- const {
5
- path,
6
- collection = 'article' as C,
7
- } = defineProps<{
8
- path?: string
9
- collection?: C
10
- }>()
11
-
12
- const route = useRoute()
13
-
14
- const { data: page } = await usePageContent<C>({
15
- path: () => path,
16
- collection: () => collection,
17
- })
18
-
19
- const { config, has } = useVariant(collection)
20
- const hasHeader = has('header')
21
- const hasBackButton = has('backButton')
22
- const hasCopyButton = has('copyButton')
23
- const hasSeparator = has('separator')
24
- const hasSurround = has('surround')
25
- const hasToc = has('toc')
26
-
27
- if (!page.value) {
28
- throw createError({
29
- statusCode: 404,
30
- statusMessage: `${collection} ${path || route.path} not found`,
31
- fatal: true,
32
- })
33
- }
34
-
35
- usePageSeo(page)
36
-
37
- const header = computed(() => resolvePageHeader(page.value))
38
-
39
- const breadcrumbsBase = computed(() => config.value.breadcrumbs ?? [])
40
-
41
- const breadcrumbItems = computed(() => {
42
- return [
43
- ...breadcrumbsBase.value,
44
- { label: page.value?.title, to: page.value?.path },
45
- ]
46
- })
47
-
48
- const backLink = computed(() => {
49
- const lastBreadcrumb = breadcrumbsBase.value.at(-1)
50
-
51
- if (!lastBreadcrumb && !config.value?.backButton)
52
- return null
53
-
54
- return { ...(lastBreadcrumb ?? {}), ...config.value?.backButton }
55
- })
56
- </script>
57
-
58
- <template>
59
- <div>
60
- <AppHeader />
61
-
62
- <UMain v-if="page">
63
- <UContainer>
64
- <UPageHeader
65
- v-if="hasHeader && header"
66
- v-bind="header"
67
- :ui="{
68
- headline: 'all:flex flex-col gap-y-8 items-start',
69
- wrapper: 'lg:flex-row',
70
- }"
71
- >
72
- <template #headline>
73
- <UBreadcrumb
74
- :ui="{ root: 'max-w-full' }"
75
- :items="breadcrumbItems"
76
- />
77
- <HArticleHeadlineMeta :page="page" :collection="collection" />
78
- </template>
79
- <HArticleHeaderBody :page="page" :collection="collection">
80
- <slot name="header" />
81
- </HArticleHeaderBody>
82
- </UPageHeader>
83
-
84
- <UPage>
85
- <UPageBody>
86
- <slot />
87
-
88
- <div
89
- v-if="hasBackButton || hasCopyButton"
90
- class="all:flex items-center justify-between mt-12"
91
- >
92
- <HBackButton
93
- v-if="hasBackButton && backLink"
94
- :to="backLink.to"
95
- :label="backLink.label"
96
- :icon="backLink.icon"
97
- />
98
- <div class="all:flex justify-end items-center gap-1.5 ml-auto">
99
- <HCopyButton v-if="hasCopyButton" />
100
- </div>
101
- </div>
102
-
103
- <HSeparator
104
- v-if="hasSeparator"
105
- :stem="page?.stem"
106
- :extension="page?.extension"
107
- />
108
-
109
- <HSurround
110
- v-if="hasSurround"
111
- :collection="collection"
112
- />
113
- </UPageBody>
114
-
115
- <template #right>
116
- <HToc
117
- v-if="hasToc && page?.toc !== false"
118
- :links="page?.body?.toc?.links"
119
- :title="page?.body?.toc?.title"
120
- />
121
- </template>
122
- </UPage>
123
- </UContainer>
124
- </UMain>
125
-
126
- <AppFooter />
127
- </div>
128
- </template>
1
+ <script setup lang="ts" generic="C extends keyof PageCollections = 'article'">
2
+ import type { PageCollections } from '@nuxt/content'
3
+
4
+ const props = defineProps<{
5
+ path?: string
6
+ collection?: C
7
+ }>()
8
+
9
+ const route = useRoute()
10
+ const collection = computed(() => props.collection ?? 'article')
11
+
12
+ const { data: page } = await usePageContent({
13
+ path: () => props.path,
14
+ collection: () => collection.value,
15
+ })
16
+
17
+ const { config, has } = useVariant(collection)
18
+ const hasHeader = has('header')
19
+ const hasBackButton = has('backButton')
20
+ const hasCopyButton = has('copyButton')
21
+ const hasSeparator = has('separator')
22
+ const hasSurround = has('surround')
23
+ const hasToc = has('toc')
24
+ const tocEnabled = computed(() => !page.value || !('toc' in page.value) || page.value.toc !== false)
25
+
26
+ if (!page.value) {
27
+ throw createError({
28
+ statusCode: 404,
29
+ statusMessage: `${collection.value} ${props.path || route.path} not found`,
30
+ fatal: true,
31
+ })
32
+ }
33
+
34
+ usePageSeo(page)
35
+
36
+ const header = computed(() => resolvePageHeader(page.value))
37
+
38
+ const breadcrumbsBase = computed(() => config.value.breadcrumbs ?? [])
39
+
40
+ const breadcrumbItems = computed(() => {
41
+ return [
42
+ ...breadcrumbsBase.value,
43
+ { label: page.value?.title, to: page.value?.path },
44
+ ]
45
+ })
46
+
47
+ const backLink = computed(() => {
48
+ const lastBreadcrumb = breadcrumbsBase.value.at(-1)
49
+
50
+ if (!lastBreadcrumb && !config.value?.backButton)
51
+ return null
52
+
53
+ return { ...(lastBreadcrumb ?? {}), ...config.value?.backButton }
54
+ })
55
+ </script>
56
+
57
+ <template>
58
+ <UContainer v-if="page">
59
+ <UPageHeader
60
+ v-if="hasHeader && header"
61
+ v-bind="header"
62
+ :ui="{
63
+ headline: 'all:flex flex-col gap-y-8 items-start',
64
+ wrapper: 'lg:flex-row',
65
+ }"
66
+ >
67
+ <template #headline>
68
+ <UBreadcrumb
69
+ :ui="{ root: 'max-w-full' }"
70
+ :items="breadcrumbItems"
71
+ />
72
+ <HArticleHeadlineMeta :page="page" :collection="collection" />
73
+ </template>
74
+ <HArticleHeaderBody :page="page" :collection="collection">
75
+ <slot name="header" />
76
+ </HArticleHeaderBody>
77
+ </UPageHeader>
78
+
79
+ <UPage>
80
+ <UPageBody>
81
+ <slot />
82
+
83
+ <div
84
+ v-if="hasBackButton || hasCopyButton"
85
+ class="all:flex items-center justify-between mt-12"
86
+ >
87
+ <HBackButton
88
+ v-if="hasBackButton && backLink"
89
+ v-bind="backLink"
90
+ />
91
+ <div class="all:flex justify-end items-center gap-1.5 ml-auto">
92
+ <HCopyButton v-if="hasCopyButton" v-bind="config.copyButton" />
93
+ </div>
94
+ </div>
95
+
96
+ <HSeparator
97
+ v-if="hasSeparator"
98
+ :stem="page?.stem"
99
+ :extension="page?.extension"
100
+ v-bind="config.separator"
101
+ />
102
+
103
+ <HSurround
104
+ v-if="hasSurround"
105
+ :collection="collection"
106
+ v-bind="config.surround"
107
+ :query="config.query"
108
+ />
109
+ </UPageBody>
110
+
111
+ <template #right>
112
+ <HToc
113
+ v-if="hasToc && tocEnabled"
114
+ :links="page?.body?.toc?.links"
115
+ :title="page?.body?.toc?.title"
116
+ />
117
+ </template>
118
+ </UPage>
119
+ </UContainer>
120
+ </template>
@@ -1,67 +1,59 @@
1
- <script setup lang="ts" generic="C extends 'page' = 'page'">
2
- import type { Collections } from '@nuxt/content'
3
-
4
- const {
5
- path,
6
- collection = 'page' as C,
7
- } = defineProps<{
8
- path?: string
9
- collection?: C
10
- }>()
11
-
12
- const appConfig = useAppConfig()
13
- const route = useRoute()
14
-
15
- const { data: page } = await usePageContent<C, Collections['page']>({
16
- path: () => path,
17
- collection: () => collection,
18
- })
19
-
20
- const { has } = useVariant(collection)
21
- const hasHeader = has('header')
22
- const hasToc = has('toc')
23
-
24
- if (!page.value) {
25
- throw createError({
26
- statusCode: 404,
27
- statusMessage: `${collection} ${path || route.path} not found`,
28
- fatal: true,
29
- })
30
- }
31
-
32
- usePageSeo(page)
33
-
34
- const renderToc = computed(() => hasToc.value && page.value?.toc !== false)
35
- const header = computed(() => resolvePageHeader(page.value))
36
- </script>
37
-
38
- <template>
39
- <div>
40
- <AppHeader />
41
-
42
- <UMain v-if="page">
43
- <UContainer>
44
- <UPage>
45
- <UPageHeader
46
- v-if="hasHeader && header"
47
- v-bind="header"
48
- />
49
-
50
- <UPageBody>
51
- <slot />
52
- </UPageBody>
53
-
54
- <template #right>
55
- <UContentToc
56
- v-if="renderToc && page.body?.toc?.links?.length"
57
- :links="page.body.toc.links"
58
- :title="page.body.toc.title || appConfig.app.toc?.title"
59
- />
60
- </template>
61
- </UPage>
62
- </UContainer>
63
- </UMain>
64
-
65
- <AppFooter />
66
- </div>
67
- </template>
1
+ <script setup lang="ts" generic="C extends 'page' = 'page'">
2
+ import type { Collections } from '@nuxt/content'
3
+
4
+ const {
5
+ path,
6
+ collection = 'page' as C,
7
+ } = defineProps<{
8
+ path?: string
9
+ collection?: C
10
+ }>()
11
+
12
+ const appConfig = useAppConfig()
13
+ const route = useRoute()
14
+
15
+ const { data: page } = await usePageContent<C, Collections['page']>({
16
+ path: () => path,
17
+ collection: () => collection,
18
+ })
19
+
20
+ const { has } = useVariant(collection)
21
+ const hasHeader = has('header')
22
+ const hasToc = has('toc')
23
+
24
+ if (!page.value) {
25
+ throw createError({
26
+ statusCode: 404,
27
+ statusMessage: `${collection} ${path || route.path} not found`,
28
+ fatal: true,
29
+ })
30
+ }
31
+
32
+ usePageSeo(page)
33
+
34
+ const renderToc = computed(() => hasToc.value && page.value?.toc !== false)
35
+ const header = computed(() => resolvePageHeader(page.value))
36
+ </script>
37
+
38
+ <template>
39
+ <UContainer v-if="page">
40
+ <UPage>
41
+ <UPageHeader
42
+ v-if="hasHeader && header"
43
+ v-bind="header"
44
+ />
45
+
46
+ <UPageBody>
47
+ <slot />
48
+ </UPageBody>
49
+
50
+ <template #right>
51
+ <UContentToc
52
+ v-if="renderToc && page.body?.toc?.links?.length"
53
+ :links="page.body.toc.links"
54
+ :title="page.body.toc.title || appConfig.app.toc?.title"
55
+ />
56
+ </template>
57
+ </UPage>
58
+ </UContainer>
59
+ </template>
@@ -1,12 +1,3 @@
1
- <script setup lang="ts">
2
- const { data: page } = await usePageContent()
3
- usePageSeo(page)
4
- </script>
5
-
6
1
  <template>
7
- <AppHeader />
8
- <UMain>
9
- <slot />
10
- </UMain>
11
- <AppFooter />
2
+ <slot />
12
3
  </template>
@@ -1,6 +1,13 @@
1
- import type { ButtonProps } from '@nuxt/ui'
2
-
3
- export type ActionButton = ButtonProps & {
4
- /** Built-in type for a dynamic GitHub link (URL resolved from app.meta.github) */
5
- type?: 'github-edit' | 'report-github-issue'
6
- }
1
+ import type { SQLOperator } from '@nuxt/content'
2
+ import type { ButtonProps } from '@nuxt/ui'
3
+
4
+ export type ActionButton = ButtonProps & {
5
+ /** Built-in type for a dynamic GitHub link (URL resolved from app.meta.github) */
6
+ action?: 'github-edit' | 'report-github-issue'
7
+ }
8
+
9
+ export interface QueryConfig {
10
+ fields?: string[]
11
+ where?: { field: string, operator: SQLOperator, value?: unknown }[]
12
+ order?: { field: string, direction: 'ASC' | 'DESC' } | false
13
+ }
@@ -1,16 +1,45 @@
1
+ import type { UserProps } from '@nuxt/ui'
2
+
3
+ interface UserRecord {
4
+ username: string
5
+ name?: UserProps['name']
6
+ description?: UserProps['description']
7
+ to?: UserProps['to']
8
+ avatar?: UserProps['avatar']
9
+ }
10
+
11
+ interface UserQuery {
12
+ where: (field: 'username', operator: 'IN', value: string[]) => UserQuery
13
+ select: (...fields: Array<keyof UserRecord>) => UserQuery
14
+ all: () => Promise<UserRecord[]>
15
+ }
16
+
17
+ /**
18
+ * Removes the internal collection lookup key before passing a profile to Nuxt UI.
19
+ */
20
+ export function toUserProps<T extends { username: string }>(
21
+ user: T,
22
+ extraProps: Partial<UserProps> = {},
23
+ ) {
24
+ const { username: _lookupKey, ...profile } = user
25
+
26
+ return { ...profile, ...extraProps }
27
+ }
28
+
1
29
  /**
2
30
  * Fetches user details from the Nuxt Content user collection.
3
31
  *
4
32
  * @param users - A single username or an array of usernames
5
33
  * @returns A promise resolving to the selected user profiles
6
34
  */
7
- export default async function resolveUsers(users: string | string[], extraProps: Record<string, any> = {}) {
35
+ export default async function resolveUsers(users: string | string[], extraProps: Partial<UserProps> = {}) {
8
36
  const userList = Array.isArray(users) ? users : [users]
9
37
 
10
- const resolved = await queryCollection('user')
38
+ const queryUserCollection = queryCollection as unknown as (collection: 'user') => UserQuery
39
+ const resolved = await queryUserCollection('user')
11
40
  .where('username', 'IN', userList)
12
41
  .select('username', 'name', 'description', 'to', 'avatar')
13
42
  .all()
14
43
 
15
- return resolved.map(user => ({ ...user, ...extraProps }))
44
+ return resolved.map(user => toUserProps(user, extraProps))
16
45
  }
package/content.config.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { defineContentConfig } from '@nuxt/content'
2
- import { collections } from './schemas'
3
-
4
- export default defineContentConfig({
5
- collections,
6
- })
1
+ import { defineContentConfig } from '@nuxt/content'
2
+ import { collections } from './schemas'
3
+
4
+ export default defineContentConfig({
5
+ collections,
6
+ })
package/nuxt.config.ts CHANGED
@@ -1,80 +1,72 @@
1
- import { dirname } from 'node:path'
2
- import { fileURLToPath } from 'node:url'
3
- import { resolve } from 'pathe'
4
-
5
- const currentDir: string = dirname(fileURLToPath(import.meta.url))
6
-
7
- // https://nuxt.com/docs/api/configuration/nuxt-config
8
- export default defineNuxtConfig({
9
-
10
- $meta: {
11
- name: '@happydesigns/ui',
12
- },
13
-
14
- components: [
15
- { path: './components', pathPrefix: false, prefix: 'H' },
16
- ],
17
-
18
- css: [
19
- resolve(currentDir, './app/assets/css/main.css'),
20
- ],
21
-
22
- devtools: { enabled: true },
23
-
24
- modules: [
25
- '@nuxt/eslint',
26
- '@happydesigns/nuxt-variants',
27
- '@nuxt/ui',
28
- '@nuxt/content',
29
- 'nuxt-studio',
30
- ],
31
-
32
- variants: {
33
- registry: {
34
- // Data features — schema only, no config
35
- dates: {},
36
- authors: {},
37
- category: {},
38
- status: {},
39
- header: {},
40
- toc: {},
41
- links: {},
42
- location: {},
43
- layout: {},
44
- separatorButtons: {},
45
-
46
- // UI features — config defined in app.config.ts
47
- user: {},
48
- backButton: {},
49
- copyButton: {},
50
- separator: {},
51
- surround: {},
52
-
53
- // Collection variants — extends chains defined here for graph generation
54
- snippet: {},
55
- article: {
56
- extends: ['dates', 'authors', 'category', 'status', 'header', 'toc', 'surround', 'copyButton', 'separator', 'backButton', 'user'],
57
- config: {},
58
- },
59
- event: {
60
- extends: ['dates', 'location', 'category', 'links', 'status', 'header', 'toc', 'surround', 'copyButton', 'separator', 'backButton', 'user'],
61
- config: {},
62
- },
63
- page: {
64
- extends: ['layout', 'header', 'toc'],
65
- config: {},
66
- },
67
- },
68
- },
69
-
70
- eslint: {
71
- config: {
72
- stylistic: true,
73
- standalone: false,
74
- },
75
- },
76
-
77
- studio: {
78
- dev: true,
79
- },
80
- })
1
+ import { dirname } from 'node:path'
2
+ import { fileURLToPath } from 'node:url'
3
+ import { resolve } from 'pathe'
4
+
5
+ const currentDir: string = dirname(fileURLToPath(import.meta.url))
6
+
7
+ // https://nuxt.com/docs/api/configuration/nuxt-config
8
+ export default defineNuxtConfig({
9
+
10
+ $meta: {
11
+ name: '@happydesigns/ui',
12
+ },
13
+
14
+ components: [
15
+ { path: './components', pathPrefix: false, prefix: 'H' },
16
+ ],
17
+
18
+ css: [
19
+ resolve(currentDir, './app/assets/css/main.css'),
20
+ ],
21
+
22
+ devtools: { enabled: true },
23
+
24
+ modules: [
25
+ '@happydesigns/nuxt-variants',
26
+ '@nuxt/ui',
27
+ '@nuxt/content',
28
+ 'nuxt-studio',
29
+ ],
30
+
31
+ variants: {
32
+ registry: {
33
+ // Data features — schema only, no config
34
+ dates: {},
35
+ authors: {},
36
+ category: {},
37
+ status: {},
38
+ header: {},
39
+ toc: {},
40
+ links: {},
41
+ location: {},
42
+ layout: {},
43
+ separatorButtons: {},
44
+
45
+ // UI features — config defined in app.config.ts
46
+ user: {},
47
+ backButton: {},
48
+ copyButton: {},
49
+ separator: {},
50
+ surround: {},
51
+
52
+ // Collection variants — extends chains defined here for graph generation
53
+ snippet: {},
54
+ article: {
55
+ extends: ['dates', 'authors', 'category', 'status', 'header', 'toc', 'surround', 'copyButton', 'separator', 'backButton', 'user'],
56
+ config: {},
57
+ },
58
+ event: {
59
+ extends: ['dates', 'location', 'category', 'links', 'status', 'header', 'toc', 'surround', 'copyButton', 'separator', 'backButton', 'user'],
60
+ config: {},
61
+ },
62
+ page: {
63
+ extends: ['layout', 'header', 'toc'],
64
+ config: {},
65
+ },
66
+ },
67
+ },
68
+
69
+ studio: {
70
+ dev: true,
71
+ },
72
+ })