@happydesigns/ui 0.16.0 → 0.17.1

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 (44) hide show
  1. package/README.md +70 -53
  2. package/app/app.config.ts +138 -165
  3. package/app/app.vue +0 -2
  4. package/app/assets/css/styles.css +38 -0
  5. package/app/components/Carousel.vue +33 -0
  6. package/app/components/{content/Snippet.vue → Snippet.vue} +6 -2
  7. package/app/components/article/ArticleGridDate.vue +19 -16
  8. package/app/components/article/ArticleHeaderBody.vue +26 -20
  9. package/app/components/article/ArticleHeadlineMeta.vue +37 -26
  10. package/app/components/article/ArticleList.vue +1 -1
  11. package/app/components/article/ArticlePage.vue +1 -1
  12. package/app/components/footer/FooterColumns.vue +60 -101
  13. package/app/components/search/ContentSearch.client.vue +59 -0
  14. package/app/components/studio/StudioLoginButton.client.vue +11 -3
  15. package/app/components/traits/Category.vue +1 -1
  16. package/app/components/traits/CopyButton.vue +40 -32
  17. package/app/components/traits/Links.vue +21 -17
  18. package/app/components/traits/Surround.vue +5 -6
  19. package/app/components/traits/Toc.vue +18 -16
  20. package/app/composables/useArticleList.ts +29 -27
  21. package/app/composables/useClipboard.ts +48 -26
  22. package/app/composables/useContentSearchData.ts +42 -0
  23. package/app/composables/useNavigationLinks.ts +40 -0
  24. package/app/composables/usePageContent.ts +1 -3
  25. package/app/composables/usePageSeo.ts +7 -15
  26. package/app/internal/pageLayout.ts +7 -0
  27. package/app/layouts/article.vue +137 -120
  28. package/app/layouts/content.vue +63 -59
  29. package/app/types/config.ts +91 -13
  30. package/app/utils/createContentSearchLoader.ts +45 -0
  31. package/app/utils/formatDate.ts +1 -1
  32. package/app/utils/formatDateTime.ts +1 -1
  33. package/app/utils/isNavigationTargetActive.ts +12 -0
  34. package/app/utils/resolveUsers.ts +56 -42
  35. package/nuxt.config.ts +1 -13
  36. package/package.json +35 -10
  37. package/schemas/collections.ts +4 -0
  38. package/schemas/indexes.ts +10 -0
  39. package/server/api/navigation.json.get.ts +11 -0
  40. package/server/api/search.json.get.ts +11 -0
  41. package/server/utils/contentSearch.ts +67 -0
  42. package/shared/types/app-config.d.ts +23 -0
  43. package/app/assets/css/main.css +0 -14
  44. package/app/components/content/Carousel.vue +0 -11
@@ -1,26 +1,48 @@
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
+ type ClipboardToast = Partial<ToastProps> & { id?: string | number }
5
+
6
+ export type ClipboardCopyOptions = ClipboardToast & {
7
+ error?: ClipboardToast
8
+ }
9
+
10
+ export function useClipboard() {
11
+ const { copy: copyToClipboard, copied } = _useClipboard()
12
+ const toast = useToast()
13
+
14
+ function upsertToast(options: ClipboardToast) {
15
+ const { id, ...toastOptions } = options
16
+
17
+ if (id !== undefined && toast.toasts.value.some(toastItem => toastItem.id === id)) {
18
+ toast.update(id, toastOptions)
19
+ return
20
+ }
21
+
22
+ toast.add(id === undefined ? toastOptions : { ...toastOptions, id })
23
+ }
24
+
25
+ const copy = async (source: string, options?: ClipboardCopyOptions): Promise<boolean> => {
26
+ const { error: errorToast, ...successToast } = options ?? {}
27
+
28
+ try {
29
+ await copyToClipboard(source)
30
+
31
+ if (Object.keys(successToast).length > 0)
32
+ upsertToast(successToast)
33
+
34
+ return true
35
+ }
36
+ catch {
37
+ if (errorToast)
38
+ upsertToast(errorToast)
39
+
40
+ return false
41
+ }
42
+ }
43
+
44
+ return {
45
+ copy,
46
+ copied,
47
+ }
48
+ }
@@ -0,0 +1,42 @@
1
+ import type { ContentNavigationItem } from '@nuxt/content'
2
+ import type { ContentSearchFile } from '@nuxt/ui'
3
+ import { createContentSearchLoader } from '../utils/createContentSearchLoader'
4
+
5
+ export interface ContentSearchDataLoaders {
6
+ navigation?: () => Promise<ContentNavigationItem[]>
7
+ files?: () => Promise<ContentSearchFile[]>
8
+ }
9
+
10
+ export function useContentSearchData(loaders: ContentSearchDataLoaders = {}) {
11
+ const navigation = shallowRef<ContentNavigationItem[]>([])
12
+ const files = shallowRef<ContentSearchFile[]>([])
13
+ const status = ref<'idle' | 'pending' | 'success' | 'error'>('idle')
14
+ const error = shallowRef<Error>()
15
+
16
+ const loader = createContentSearchLoader({
17
+ navigation: loaders.navigation ?? (() => $fetch<ContentNavigationItem[]>('/api/navigation.json')),
18
+ files: loaders.files ?? (() => $fetch<ContentSearchFile[]>('/api/search.json')),
19
+ }, {
20
+ pending: () => {
21
+ status.value = 'pending'
22
+ error.value = undefined
23
+ },
24
+ success: (loadedNavigation, loadedFiles) => {
25
+ navigation.value = loadedNavigation
26
+ files.value = loadedFiles
27
+ status.value = 'success'
28
+ },
29
+ error: (cause) => {
30
+ error.value = cause
31
+ status.value = 'error'
32
+ },
33
+ })
34
+
35
+ return {
36
+ navigation,
37
+ files,
38
+ status,
39
+ error,
40
+ load: loader.load,
41
+ }
42
+ }
@@ -0,0 +1,40 @@
1
+ import type { FooterColumn, FooterColumnLink, NavigationMenuItem } from '@nuxt/ui'
2
+ import { createSharedComposable } from '@vueuse/core'
3
+
4
+ function withActiveState<T extends { to?: unknown, children?: T[] }>(items: T[], currentPath: string): T[] {
5
+ return items.map((item) => {
6
+ const children = item.children ? withActiveState(item.children, currentPath) : undefined
7
+
8
+ return {
9
+ ...item,
10
+ ...(children ? { children } : {}),
11
+ active: isNavigationTargetActive(currentPath, item.to)
12
+ || Boolean(children?.some(child => 'active' in child && child.active)),
13
+ }
14
+ })
15
+ }
16
+
17
+ function _useHeaderLinks() {
18
+ const appConfig = useAppConfig()
19
+ const route = useRoute()
20
+ const headerLinks = computed(() => withActiveState(
21
+ (appConfig.app.links.header ?? []) as NavigationMenuItem[],
22
+ route.path,
23
+ ))
24
+
25
+ return { headerLinks }
26
+ }
27
+
28
+ function _useFooterLinks() {
29
+ const appConfig = useAppConfig()
30
+ const route = useRoute()
31
+ const footerLinks = computed(() => ((appConfig.app.links.footer ?? []) as FooterColumn[]).map(column => ({
32
+ ...column,
33
+ children: withActiveState((column.children ?? []) as FooterColumnLink[], route.path),
34
+ })))
35
+
36
+ return { footerLinks }
37
+ }
38
+
39
+ export const useHeaderLinks = import.meta.client ? createSharedComposable(_useHeaderLinks) : _useHeaderLinks
40
+ export const useFooterLinks = import.meta.client ? createSharedComposable(_useFooterLinks) : _useFooterLinks
@@ -25,7 +25,5 @@ export function usePageContent<C extends keyof PageCollections = 'page', B = obj
25
25
 
26
26
  const handler = () => queryCollection(resolvedCollection.value as keyof PageCollections).path(resolvedPath.value).first()
27
27
 
28
- return useAsyncData(key, handler, {
29
- watch: [resolvedPath, resolvedCollection],
30
- }) as unknown as AsyncData<(PageCollections[C] & B) | null, Error | null>
28
+ return useAsyncData(key, handler) as unknown as AsyncData<(PageCollections[C] & B) | null, Error | null>
31
29
  }
@@ -1,5 +1,3 @@
1
- import { watchEffect } from 'vue'
2
-
3
1
  interface SeoRelevantPageData {
4
2
  seo?: {
5
3
  title?: string
@@ -12,19 +10,13 @@ interface SeoRelevantPageData {
12
10
  }
13
11
 
14
12
  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
13
+ const title = () => page.value?.seo?.title || page.value?.title
14
+ const description = () => page.value?.seo?.description || page.value?.description
21
15
 
22
- useSeoMeta({
23
- title,
24
- ogTitle,
25
- description,
26
- ogDescription,
27
- })
28
- }
16
+ useSeoMeta({
17
+ title,
18
+ ogTitle: () => page.value?.seo?.ogTitle || title(),
19
+ description,
20
+ ogDescription: () => page.value?.seo?.ogDescription || description(),
29
21
  })
30
22
  }
@@ -0,0 +1,7 @@
1
+ export function getPageLayoutUi(hasToc: boolean) {
2
+ return {
3
+ root: 'lg:grid-cols-12',
4
+ center: hasToc ? 'lg:col-span-9' : 'lg:col-span-12',
5
+ right: 'lg:col-span-3',
6
+ }
7
+ }
@@ -1,120 +1,137 @@
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
+ <script setup lang="ts" generic="C extends keyof PageCollections = 'article'">
2
+ import type { PageCollections } from '@nuxt/content'
3
+ import type { BreadcrumbItem } from '@nuxt/ui'
4
+ import { getPageLayoutUi } from '../internal/pageLayout'
5
+
6
+ const props = defineProps<{
7
+ path?: string
8
+ collection?: C
9
+ }>()
10
+
11
+ const route = useRoute()
12
+ const collection = computed(() => props.collection ?? 'article')
13
+
14
+ const { data: page } = await usePageContent({
15
+ path: () => props.path,
16
+ collection: () => collection.value,
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
+ const tocEnabled = computed(() => !page.value || !('toc' in page.value) || page.value.toc !== false)
27
+ const renderToc = computed(() => hasToc.value
28
+ && tocEnabled.value
29
+ && Boolean(page.value?.body?.toc?.links?.length))
30
+ const pageUi = computed(() => getPageLayoutUi(renderToc.value))
31
+
32
+ if (!page.value) {
33
+ throw createError({
34
+ statusCode: 404,
35
+ statusMessage: `${collection.value} ${props.path || route.path} not found`,
36
+ fatal: true,
37
+ })
38
+ }
39
+
40
+ usePageSeo(page)
41
+
42
+ const header = computed(() => resolvePageHeader(page.value))
43
+
44
+ const breadcrumbsBase = computed(() => (config.value.breadcrumbs ?? []) as BreadcrumbItem[])
45
+
46
+ const breadcrumbItems = computed(() => {
47
+ const baseItems = breadcrumbsBase.value.map((item, index) => ({
48
+ ...item,
49
+ ...(index === breadcrumbsBase.value.length - 1
50
+ ? { ui: { ...item.ui, separator: 'hidden sm:flex' } }
51
+ : {}),
52
+ }))
53
+
54
+ return [
55
+ ...baseItems,
56
+ {
57
+ label: page.value?.title,
58
+ to: page.value?.path,
59
+ ui: { item: 'hidden sm:flex' },
60
+ },
61
+ ]
62
+ })
63
+
64
+ const backLink = computed(() => {
65
+ const lastBreadcrumb = breadcrumbsBase.value.at(-1)
66
+
67
+ if (!lastBreadcrumb && !config.value?.backButton)
68
+ return null
69
+
70
+ return { ...(lastBreadcrumb ?? {}), ...config.value?.backButton }
71
+ })
72
+ </script>
73
+
74
+ <template>
75
+ <UContainer v-if="page">
76
+ <UPageHeader
77
+ v-if="hasHeader && header"
78
+ v-bind="header"
79
+ :ui="{
80
+ headline: 'all:flex flex-col gap-y-8 items-start',
81
+ wrapper: 'lg:flex-row',
82
+ }"
83
+ >
84
+ <template #headline>
85
+ <UBreadcrumb
86
+ :ui="{ root: 'max-w-full' }"
87
+ :items="breadcrumbItems"
88
+ />
89
+ <HArticleHeadlineMeta :page="page" :collection="collection" />
90
+ </template>
91
+ <HArticleHeaderBody :page="page" :collection="collection">
92
+ <slot name="header" />
93
+ </HArticleHeaderBody>
94
+ </UPageHeader>
95
+
96
+ <UPage :ui="pageUi">
97
+ <UPageBody>
98
+ <slot />
99
+
100
+ <div
101
+ v-if="hasBackButton || hasCopyButton"
102
+ class="all:flex items-center justify-between mt-12"
103
+ >
104
+ <HBackButton
105
+ v-if="hasBackButton && backLink"
106
+ v-bind="backLink"
107
+ />
108
+ <div class="all:flex justify-end items-center gap-1.5 ml-auto">
109
+ <HCopyButton v-if="hasCopyButton" v-bind="config.copyButton" />
110
+ </div>
111
+ </div>
112
+
113
+ <HSeparator
114
+ v-if="hasSeparator"
115
+ :stem="page?.stem"
116
+ :extension="page?.extension"
117
+ v-bind="config.separator"
118
+ />
119
+
120
+ <HSurround
121
+ v-if="hasSurround"
122
+ :collection="collection"
123
+ v-bind="config.surround"
124
+ :query="config.query"
125
+ />
126
+ </UPageBody>
127
+
128
+ <template #right>
129
+ <HToc
130
+ v-if="renderToc"
131
+ :links="page?.body?.toc?.links"
132
+ :title="page?.body?.toc?.title"
133
+ />
134
+ </template>
135
+ </UPage>
136
+ </UContainer>
137
+ </template>
@@ -1,59 +1,63 @@
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
+ <script setup lang="ts" generic="C extends 'page' = 'page'">
2
+ import type { Collections } from '@nuxt/content'
3
+ import { getPageLayoutUi } from '../internal/pageLayout'
4
+
5
+ const {
6
+ path,
7
+ collection = 'page' as C,
8
+ } = defineProps<{
9
+ path?: string
10
+ collection?: C
11
+ }>()
12
+
13
+ const appConfig = useAppConfig()
14
+ const route = useRoute()
15
+
16
+ const { data: page } = await usePageContent<C, Collections['page']>({
17
+ path: () => path,
18
+ collection: () => collection,
19
+ })
20
+
21
+ const { has } = useVariant(collection)
22
+ const hasHeader = has('header')
23
+ const hasToc = has('toc')
24
+
25
+ if (!page.value) {
26
+ throw createError({
27
+ statusCode: 404,
28
+ statusMessage: `${collection} ${path || route.path} not found`,
29
+ fatal: true,
30
+ })
31
+ }
32
+
33
+ usePageSeo(page)
34
+
35
+ const renderToc = computed(() => hasToc.value
36
+ && page.value?.toc !== false
37
+ && Boolean(page.value?.body?.toc?.links?.length))
38
+ const pageUi = computed(() => getPageLayoutUi(renderToc.value))
39
+ const header = computed(() => resolvePageHeader(page.value))
40
+ </script>
41
+
42
+ <template>
43
+ <UContainer v-if="page">
44
+ <UPage :ui="pageUi">
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"
57
+ :links="page.body?.toc?.links"
58
+ :title="page.body?.toc?.title || appConfig.app.toc?.title"
59
+ />
60
+ </template>
61
+ </UPage>
62
+ </UContainer>
63
+ </template>