@happydesigns/ui 0.15.1 → 0.17.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 (46) hide show
  1. package/README.md +64 -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/ArticleGrid.vue +4 -4
  8. package/app/components/article/ArticleGridDate.vue +19 -16
  9. package/app/components/article/ArticleHeaderBody.vue +26 -20
  10. package/app/components/article/ArticleHeadlineMeta.vue +37 -26
  11. package/app/components/article/ArticleList.vue +5 -5
  12. package/app/components/article/ArticlePage.vue +1 -1
  13. package/app/components/footer/FooterColumns.vue +60 -101
  14. package/app/components/search/ContentSearch.client.vue +59 -0
  15. package/app/components/studio/StudioLoginButton.client.vue +11 -3
  16. package/app/components/traits/Category.vue +1 -1
  17. package/app/components/traits/CopyButton.vue +40 -32
  18. package/app/components/traits/Links.vue +21 -17
  19. package/app/components/traits/Surround.vue +6 -7
  20. package/app/components/traits/Toc.vue +18 -16
  21. package/app/composables/useArticleList.ts +37 -46
  22. package/app/composables/useClipboard.ts +48 -26
  23. package/app/composables/useContentSearchData.ts +42 -0
  24. package/app/composables/useNavigationLinks.ts +40 -0
  25. package/app/composables/usePageContent.ts +1 -3
  26. package/app/composables/usePageSeo.ts +7 -15
  27. package/app/internal/pageLayout.ts +7 -0
  28. package/app/layouts/article.vue +137 -120
  29. package/app/layouts/content.vue +63 -59
  30. package/app/types/config.ts +91 -13
  31. package/app/utils/createContentSearchLoader.ts +45 -0
  32. package/app/utils/formatDate.ts +1 -1
  33. package/app/utils/formatDateTime.ts +1 -1
  34. package/app/utils/isNavigationTargetActive.ts +12 -0
  35. package/app/utils/resolveUsers.ts +56 -42
  36. package/nuxt.config.ts +4 -16
  37. package/package.json +17 -9
  38. package/schemas/collections.ts +4 -0
  39. package/schemas/indexes.ts +10 -0
  40. package/schemas/traits.ts +9 -4
  41. package/server/api/navigation.json.get.ts +11 -0
  42. package/server/api/search.json.get.ts +11 -0
  43. package/server/utils/contentSearch.ts +67 -0
  44. package/shared/types/app-config.d.ts +23 -0
  45. package/app/assets/css/main.css +0 -14
  46. package/app/components/content/Carousel.vue +0 -11
@@ -1,26 +1,37 @@
1
- <script setup lang="ts">
2
- import type { PageCollections } from '@nuxt/content'
3
-
4
- const props = defineProps<{
5
- page?: any
6
- collection?: keyof PageCollections
7
- }>()
8
-
9
- const { has } = useVariant(() => props.collection || 'article')
10
-
11
- const showCategory = computed(() => has('category').value && props.page?.category)
12
- const showDates = computed(() => has('dates').value && props.page?.date)
13
- const showLocation = computed(() => has('location').value && props.page?.location?.name)
14
- </script>
15
-
16
- <template>
17
- <div class="all:flex flex-wrap items-center gap-x-3 gap-y-2 text-muted">
18
- <HCategory v-if="showCategory" :category="page?.category" />
19
-
20
- <span v-if="showCategory && showDates" class="all:hidden sm:inline opacity-50">&middot;</span>
21
- <HDates v-if="showDates" :date="page?.date" :date-end="page?.dateEnd" />
22
-
23
- <span v-if="(showCategory || showDates) && showLocation" class="all:hidden sm:inline opacity-50">&middot;</span>
24
- <HLocation v-if="showLocation" :location="page?.location" />
25
- </div>
26
- </template>
1
+ <script setup lang="ts">
2
+ import type { PageCollections } from '@nuxt/content'
3
+
4
+ interface HeadlineMetaPage {
5
+ path?: string
6
+ category?: string
7
+ date?: string
8
+ dateEnd?: string
9
+ location?: {
10
+ name?: string
11
+ url?: string
12
+ }
13
+ }
14
+
15
+ const props = defineProps<{
16
+ page?: HeadlineMetaPage
17
+ collection?: keyof PageCollections
18
+ }>()
19
+
20
+ const { has } = useVariant(() => props.collection || 'article')
21
+
22
+ const showCategory = computed(() => has('category').value && Boolean(props.page?.category))
23
+ const showDates = computed(() => has('dates').value && Boolean(props.page?.date))
24
+ const showLocation = computed(() => has('location').value && Boolean(props.page?.location?.name))
25
+ </script>
26
+
27
+ <template>
28
+ <div class="all:flex flex-wrap items-center gap-x-3 gap-y-2 text-muted">
29
+ <HCategory v-if="showCategory" :category="page?.category" />
30
+
31
+ <span v-if="showCategory && showDates" class="all:hidden sm:inline opacity-50">&middot;</span>
32
+ <HDates v-if="showDates" :date="page?.date" :date-end="page?.dateEnd" />
33
+
34
+ <span v-if="(showCategory || showDates) && showLocation" class="all:hidden sm:inline opacity-50">&middot;</span>
35
+ <HLocation v-if="showLocation" :location="page?.location" />
36
+ </div>
37
+ </template>
@@ -14,13 +14,13 @@ const props = withDefaults(defineProps<{
14
14
  where?: ArticleFilter[]
15
15
  /** Field to sort by. Set to false to disable default sorting. */
16
16
  sort?: { field: string, direction: 'ASC' | 'DESC' } | false
17
- /** Status to filter by. Set to false to disable default status filtering. */
18
- status?: string | false
17
+ /** Whether to return only published entries. Defaults to true. */
18
+ publishedOnly?: boolean
19
19
  /** Optional items per page override */
20
20
  itemsPerPage?: number
21
21
  }>(), {
22
22
  sort: undefined,
23
- status: undefined,
23
+ publishedOnly: true,
24
24
  })
25
25
 
26
26
  /** Resolve the configuration for this collection using the smart merger */
@@ -56,7 +56,7 @@ const categories = computed(() => {
56
56
 
57
57
  <template>
58
58
  <div class="all:flex flex-col gap-8">
59
- <div v-if="!props.category" class="border-b border-gray-200 dark:border-gray-800">
59
+ <div v-if="!props.category" class="border-b border-default">
60
60
  <UNavigationMenu
61
61
  :items="categories"
62
62
  highlight
@@ -69,7 +69,7 @@ const categories = computed(() => {
69
69
  :collection="props.collection"
70
70
  :where="props.where"
71
71
  :sort="props.sort"
72
- :status="props.status"
72
+ :published-only="props.publishedOnly"
73
73
  :items-per-page="props.itemsPerPage"
74
74
  >
75
75
  <template v-for="(_, name) in $slots" #[name]="slotData">
@@ -13,5 +13,5 @@ const { data: page } = await usePageContent({
13
13
  </script>
14
14
 
15
15
  <template>
16
- <ContentRenderer v-if="page" :value="page" />
16
+ <ContentRenderer v-if="page" :value="page" class="h-content" />
17
17
  </template>
@@ -1,101 +1,60 @@
1
- <script setup lang="ts" generic="T extends FooterColumnLink">
2
- import type { FooterColumn, FooterColumnLink, FooterColumnsProps, FooterColumnsSlots, SlotClass } from '@nuxt/ui'
3
- import { useAppConfig } from '#imports'
4
-
5
- interface HFooterColumnProps<T extends FooterColumnLink> extends /* @vue-ignore */ FooterColumnsProps<T> {
6
- lgCols?: number
7
- xlCols?: number
8
- }
9
-
10
- const props = defineProps<HFooterColumnProps<T>>()
11
- const slots = defineSlots<FooterColumnsSlots<T>>()
12
- const appConfig = useAppConfig()
13
-
14
- const footerColumns: FooterColumn<T>[] = props.columns
15
- ?? (appConfig?.app?.links?.footer as FooterColumn<T>[] | undefined)
16
- ?? []
17
-
18
- const leftCount = slots.left ? slots.left({}).length : 0
19
- const centerCount = footerColumns?.length ?? 0
20
- const rightCount = slots.right ? slots.right({}).length : 0
21
-
22
- const lgCount = Math.max(leftCount, centerCount, rightCount)
23
- const totalCount = leftCount + centerCount + rightCount
24
-
25
- function withLayoutClass(base: string, override?: SlotClass): SlotClass {
26
- if (typeof override === 'function')
27
- return defaults => [base, override(defaults)]
28
-
29
- return [base, override]
30
- }
31
-
32
- const ui = computed(() => ({
33
- ...props.ui,
34
- root: withLayoutClass('footer-cols-root all:grid grid-flow-row gap-y-12 gap-x-8', props.ui?.root),
35
- left: withLayoutClass('footer-cols-left', props.ui?.left),
36
- center: withLayoutClass('footer-cols-center', props.ui?.center),
37
- right: withLayoutClass('footer-cols-right', props.ui?.right),
38
- }))
39
- </script>
40
-
41
- <template>
42
- <UFooterColumns
43
- v-bind="props" :columns="footerColumns" :ui="ui"
44
- :style="{
45
- '--cols-sm': 1,
46
- '--cols-lg': props.lgCols ?? lgCount,
47
- '--cols-xl': props.xlCols ?? totalCount,
48
- '--span-left': leftCount,
49
- '--span-center': centerCount,
50
- '--span-right': rightCount,
51
- }"
52
- >
53
- <template v-if="leftCount > 0" #left>
54
- <slot name="left" />
55
- </template>
56
- <template v-if="rightCount > 0" #right>
57
- <slot name="right" />
58
- </template>
59
- </UFooterColumns>
60
- </template>
61
-
62
- <style>
63
- @import "tailwindcss" source("../..");
64
-
65
- .footer-cols-left {
66
- grid-column: span var(--span-left);
67
- }
68
-
69
- .footer-cols-center {
70
- grid-column: span var(--span-center);
71
- }
72
-
73
- .footer-cols-right {
74
- grid-column: span var(--span-right);
75
- }
76
-
77
- .footer-cols-left,
78
- .footer-cols-center,
79
- .footer-cols-right {
80
- display: contents;
81
- }
82
- .footer-cols-root {
83
- grid-template-columns: repeat(var(--cols-sm), minmax(0, 1fr));
84
- }
85
-
86
- @media (min-width: theme(--breakpoint-lg)) {
87
- .footer-cols-root {
88
- grid-template-columns: repeat(var(--cols-lg), minmax(0, 1fr));
89
- }
90
- }
91
-
92
- @media (min-width: theme(--breakpoint-xl)) {
93
- .footer-cols-root {
94
- grid-template-columns: repeat(var(--cols-xl), minmax(0, 1fr));
95
- }
96
- }
97
-
98
- .footer-cols-root p:last-child {
99
- margin-bottom: 0;
100
- }
101
- </style>
1
+ <script setup lang="ts" generic="T extends FooterColumnLink">
2
+ import type { FooterColumn, FooterColumnLink, FooterColumnsProps, FooterColumnsSlots, SlotClass } from '@nuxt/ui'
3
+ import { useAppConfig } from '#imports'
4
+
5
+ interface HFooterColumnProps<T extends FooterColumnLink> extends /* @vue-ignore */ FooterColumnsProps<T> {
6
+ /** Fixed column count from the lg breakpoint. Defaults to responsive auto-fit. */
7
+ lgCols?: number
8
+ /** Fixed column count from the xl breakpoint. Defaults to responsive auto-fit. */
9
+ xlCols?: number
10
+ }
11
+
12
+ const props = defineProps<HFooterColumnProps<T>>()
13
+ const slots = defineSlots<FooterColumnsSlots<T>>()
14
+ const appConfig = useAppConfig()
15
+
16
+ const footerColumns = computed<FooterColumn<T>[]>(() => (
17
+ props.columns
18
+ ?? (appConfig.app.links.footer as FooterColumn<T>[] | undefined)
19
+ ?? []
20
+ ))
21
+
22
+ const hasLeft = Boolean(slots.left)
23
+ const hasRight = Boolean(slots.right)
24
+
25
+ function withLayoutClass(base: string, override?: SlotClass): SlotClass {
26
+ if (typeof override === 'function')
27
+ return defaults => [base, override(defaults)]
28
+
29
+ return [base, override]
30
+ }
31
+
32
+ const ui = computed(() => ({
33
+ ...props.ui,
34
+ root: withLayoutClass('footer-cols-root all:grid grid-flow-row gap-y-12 gap-x-8', props.ui?.root),
35
+ left: withLayoutClass('footer-cols-left', props.ui?.left),
36
+ center: withLayoutClass('footer-cols-center', props.ui?.center),
37
+ right: withLayoutClass('footer-cols-right', props.ui?.right),
38
+ }))
39
+
40
+ const layoutStyle = computed(() => ({
41
+ ...(props.lgCols === undefined ? {} : { '--cols-lg': props.lgCols }),
42
+ ...(props.xlCols === undefined ? {} : { '--cols-xl': props.xlCols }),
43
+ }))
44
+ </script>
45
+
46
+ <template>
47
+ <UFooterColumns
48
+ v-bind="props"
49
+ :columns="footerColumns"
50
+ :ui="ui"
51
+ :style="layoutStyle"
52
+ >
53
+ <template v-if="hasLeft" #left>
54
+ <slot name="left" />
55
+ </template>
56
+ <template v-if="hasRight" #right>
57
+ <slot name="right" />
58
+ </template>
59
+ </UFooterColumns>
60
+ </template>
@@ -0,0 +1,59 @@
1
+ <script setup lang="ts">
2
+ import type { CommandPaletteGroup } from '@nuxt/ui'
3
+
4
+ const appConfig = useAppConfig()
5
+ const { open } = useContentSearch()
6
+ const search = computed(() => appConfig.app.search)
7
+ const searchTerm = ref('')
8
+ const { navigation, files, status, error, load } = useContentSearchData()
9
+
10
+ const groups = computed<CommandPaletteGroup[]>(() => {
11
+ const configuredGroups = search.value.groups ?? []
12
+
13
+ if (!error.value) {
14
+ return configuredGroups
15
+ }
16
+
17
+ return [
18
+ {
19
+ id: 'search-error',
20
+ label: search.value.error?.title,
21
+ ignoreFilter: true,
22
+ items: [
23
+ {
24
+ label: search.value.error?.retryLabel,
25
+ description: search.value.error?.description,
26
+ icon: 'i-lucide-refresh-cw',
27
+ onSelect: () => void load(),
28
+ },
29
+ ],
30
+ },
31
+ ...configuredGroups,
32
+ ]
33
+ })
34
+
35
+ watch(open, (isOpen) => {
36
+ if (isOpen) {
37
+ void load().then(() => {
38
+ if (error.value) {
39
+ console.error('Failed to load the search index.', error.value)
40
+ }
41
+ })
42
+ }
43
+ }, { immediate: true })
44
+ </script>
45
+
46
+ <template>
47
+ <UContentSearch
48
+ v-model:search-term="searchTerm"
49
+ :title="search.title"
50
+ :description="search.description"
51
+ :placeholder="search.placeholder"
52
+ :links="search.links"
53
+ :groups="groups"
54
+ :files="files"
55
+ :navigation="navigation"
56
+ :loading="status === 'pending'"
57
+ :fuse="{ resultLimit: search.resultLimit }"
58
+ />
59
+ </template>
@@ -13,15 +13,23 @@ withDefaults(defineProps<{
13
13
  icon: 'i-lucide-log-in',
14
14
  })
15
15
 
16
- interface StudioSession {
17
- user?: StudioUser | null
16
+ interface StudioSession {
17
+ user?: StudioUser | null
18
+ }
19
+
20
+ interface StudioRuntimeConfig {
21
+ dev?: boolean
22
+ route?: string
18
23
  }
19
24
 
20
25
  const runtimeConfig = useRuntimeConfig()
21
26
  const sessionCheckCookie = useCookie<string | null>('studio-session-check')
22
27
  const sessionUser = ref<StudioUser | null | undefined>()
23
28
 
24
- const studio = computed(() => runtimeConfig.public.studio)
29
+ const studio = computed<StudioRuntimeConfig>(() => {
30
+ const config = runtimeConfig.public.studio
31
+ return config && typeof config === 'object' ? config as StudioRuntimeConfig : {}
32
+ })
25
33
  const studioRoute = computed(() => studio.value.route || '/_studio')
26
34
 
27
35
  onMounted(async () => {
@@ -5,5 +5,5 @@ defineProps<{
5
5
  </script>
6
6
 
7
7
  <template>
8
- <span class="text-primary-500 dark:text-primary-400 font-medium">{{ category }}</span>
8
+ <span class="font-medium text-primary">{{ category }}</span>
9
9
  </template>
@@ -1,32 +1,40 @@
1
- <script setup lang="ts">
2
- const props = defineProps<{
3
- path?: string
4
- icon?: string
5
- label?: string
6
- successIcon?: string
7
- successLabel?: string
8
- }>()
9
-
10
- const { copy } = useClipboard()
11
- const url = useRequestURL()
12
- const route = useRoute()
13
-
14
- function copyLink() {
15
- copy(`${url.origin}${props.path ?? route.path}`, {
16
- id: 'article-copy-link',
17
- title: props.successLabel,
18
- icon: props.successIcon,
19
- })
20
- }
21
- </script>
22
-
23
- <template>
24
- <UButton
25
- :icon="icon"
26
- variant="ghost"
27
- color="neutral"
28
- @click="copyLink"
29
- >
30
- {{ label }}
31
- </UButton>
32
- </template>
1
+ <script setup lang="ts">
2
+ const props = defineProps<{
3
+ path?: string
4
+ icon?: string
5
+ label?: string
6
+ successIcon?: string
7
+ successLabel?: string
8
+ errorIcon?: string
9
+ errorLabel?: string
10
+ }>()
11
+
12
+ const { copy } = useClipboard()
13
+ const url = useRequestURL()
14
+ const route = useRoute()
15
+
16
+ async function copyLink() {
17
+ await copy(`${url.origin}${props.path ?? route.path}`, {
18
+ id: 'article-copy-link',
19
+ title: props.successLabel,
20
+ icon: props.successIcon,
21
+ error: {
22
+ id: 'article-copy-link-error',
23
+ title: props.errorLabel,
24
+ icon: props.errorIcon,
25
+ color: 'error',
26
+ },
27
+ })
28
+ }
29
+ </script>
30
+
31
+ <template>
32
+ <UButton
33
+ :icon="icon"
34
+ variant="ghost"
35
+ color="neutral"
36
+ @click="copyLink"
37
+ >
38
+ {{ label }}
39
+ </UButton>
40
+ </template>
@@ -1,17 +1,21 @@
1
- <script setup lang="ts">
2
- import type { ButtonProps } from '@nuxt/ui'
3
-
4
- defineProps<{
5
- links?: ButtonProps[]
6
- }>()
7
- </script>
8
-
9
- <template>
10
- <UButton
11
- v-for="(link, index) in links"
12
- :key="index"
13
- variant="subtle"
14
- size="sm"
15
- v-bind="link"
16
- />
17
- </template>
1
+ <script setup lang="ts">
2
+ import type { PageCollections } from '@nuxt/content'
3
+ import type { ButtonProps } from '@nuxt/ui'
4
+
5
+ const props = defineProps<{
6
+ links?: PageCollections['event']['links']
7
+ }>()
8
+
9
+ // Nuxt Content preserves the inherited schema shape but widens a few DOM props to unknown.
10
+ const buttonLinks = computed(() => props.links as ButtonProps[] | undefined)
11
+ </script>
12
+
13
+ <template>
14
+ <UButton
15
+ v-for="(link, index) in buttonLinks"
16
+ :key="index"
17
+ variant="subtle"
18
+ size="sm"
19
+ v-bind="link"
20
+ />
21
+ </template>
@@ -11,28 +11,27 @@ const props = defineProps<{
11
11
  }>()
12
12
 
13
13
  const route = useRoute()
14
- const collection = computed(() => props.collection || 'article')
14
+ const collection = computed(() => props.collection)
15
15
  const path = computed(() => route.path)
16
16
  const key = computed(() => `surround-${String(collection.value)}-${path.value}`)
17
17
 
18
18
  const { data: surround } = await useAsyncData(
19
19
  key,
20
20
  () => {
21
- const colName = collection.value as any
22
21
  const qc = props.query || {}
23
22
 
24
- const fields = (qc.fields || ['title', 'description', 'status']) as any
23
+ const fields = (qc.fields || ['title', 'description', 'published']) as Array<keyof PageCollections[C]>
25
24
  const order = qc.order
26
- const where = qc.where || [{ field: 'status', operator: '=', value: 'published' }]
25
+ const where = qc.where || [{ field: 'published', operator: '=', value: true }]
27
26
 
28
- let query = queryCollectionItemSurroundings(colName, path.value, { fields })
27
+ let query = queryCollectionItemSurroundings(collection.value, path.value, { fields })
29
28
 
30
29
  where.forEach((filter) => {
31
- query = query.where(filter.field as any, filter.operator as any, filter.value)
30
+ query = query.where(filter.field, filter.operator, filter.value)
32
31
  })
33
32
 
34
33
  if (order) {
35
- query = query.order(order.field as any, order.direction)
34
+ query = query.order(order.field as keyof PageCollections[C], order.direction)
36
35
  }
37
36
 
38
37
  return query
@@ -1,16 +1,18 @@
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>
1
+ <script setup lang="ts">
2
+ import type { ContentTocLink } from '@nuxt/ui'
3
+
4
+ defineProps<{
5
+ links?: ContentTocLink[]
6
+ title?: string
7
+ }>()
8
+
9
+ const appConfig = useAppConfig()
10
+ </script>
11
+
12
+ <template>
13
+ <UContentToc
14
+ v-if="links?.length"
15
+ :links="links"
16
+ :title="title || appConfig.app.toc?.title"
17
+ />
18
+ </template>