@happydesigns/ui 0.18.0 → 0.19.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.
@@ -1,70 +1,70 @@
1
- <script setup lang="ts" generic="C extends keyof PageCollections = 'page'">
2
- import type { Collections, PageCollections } 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 variant = computed(() => {
21
- if (typeof route.meta.variant === 'string' && route.meta.variant) {
22
- return route.meta.variant
23
- }
24
-
25
- if (typeof route.meta.layout === 'string' && route.meta.layout) {
26
- return route.meta.layout
27
- }
28
-
29
- return collection
30
- })
31
- const { has } = useVariant(variant)
32
- const hasHeader = has('header')
33
- const hasToc = has('toc')
34
-
35
- if (!page.value) {
36
- throw createError({
37
- statusCode: 404,
38
- statusMessage: `${collection} ${path || route.path} not found`,
39
- fatal: true,
40
- })
41
- }
42
-
43
- usePageSeo(page)
44
-
45
- const tocEnabled = computed(() => !page.value || !('toc' in page.value) || page.value.toc !== false)
46
- const showTocSidebar = computed(() => hasToc.value && tocEnabled.value)
47
- const header = computed(() => resolvePageHeader(page.value))
48
- </script>
49
-
50
- <template>
51
- <UContainer v-if="page">
52
- <UPage>
53
- <UPageHeader
54
- v-if="hasHeader && header"
55
- v-bind="header"
56
- />
57
-
58
- <UPageBody>
59
- <slot />
60
- </UPageBody>
61
-
62
- <template v-if="showTocSidebar" #right>
63
- <UContentToc
64
- :links="page.body?.toc?.links"
65
- :title="page.body?.toc?.title || appConfig.app.toc?.title"
66
- />
67
- </template>
68
- </UPage>
69
- </UContainer>
70
- </template>
1
+ <script setup lang="ts" generic="C extends PageCollectionName = 'page'">
2
+ import type { PageCollectionName } from '../types/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>({
16
+ path: () => path,
17
+ collection: () => collection,
18
+ })
19
+
20
+ const variant = computed(() => {
21
+ if (typeof route.meta.variant === 'string' && route.meta.variant) {
22
+ return route.meta.variant
23
+ }
24
+
25
+ if (typeof route.meta.layout === 'string' && route.meta.layout) {
26
+ return route.meta.layout
27
+ }
28
+
29
+ return collection
30
+ })
31
+ const { has } = useVariant(variant)
32
+ const hasHeader = has('header')
33
+ const hasToc = has('toc')
34
+
35
+ if (!page.value) {
36
+ throw createError({
37
+ statusCode: 404,
38
+ statusMessage: `${collection} ${path || route.path} not found`,
39
+ fatal: true,
40
+ })
41
+ }
42
+
43
+ usePageSeo(page)
44
+
45
+ const tocEnabled = computed(() => !page.value || !('toc' in page.value) || page.value.toc !== false)
46
+ const showTocSidebar = computed(() => hasToc.value && tocEnabled.value)
47
+ const header = computed(() => resolvePageHeader(page.value))
48
+ </script>
49
+
50
+ <template>
51
+ <UContainer v-if="page">
52
+ <UPage>
53
+ <UPageHeader
54
+ v-if="hasHeader && header"
55
+ v-bind="header"
56
+ />
57
+
58
+ <UPageBody>
59
+ <slot />
60
+ </UPageBody>
61
+
62
+ <template v-if="showTocSidebar" #right>
63
+ <UContentToc
64
+ :links="page.body?.toc?.links"
65
+ :title="page.body?.toc?.title || appConfig.app.toc?.title"
66
+ />
67
+ </template>
68
+ </UPage>
69
+ </UContainer>
70
+ </template>
@@ -1,91 +1,96 @@
1
- import type { PageCollections, SQLOperator } from '@nuxt/content'
2
- import type { ButtonProps, CommandPaletteGroup, ContentSearchLink, FooterColumn, NavigationMenuItem } 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
- }
14
- export interface SearchCollectionConfig {
15
- /** Page collection included in both generated search indexes. */
16
- name: keyof PageCollections & string
17
- /** Filters applied before navigation and search sections are generated. */
18
- where?: QueryConfig['where']
19
- /** Optional stable ordering for generated entries. */
20
- order?: QueryConfig['order']
21
- }
22
-
23
- export interface SearchConfig {
24
- title?: string
25
- description?: string
26
- placeholder?: string
27
- resultLimit?: number
28
- links?: ContentSearchLink[]
29
- groups?: CommandPaletteGroup[]
30
- /** Shared-cache policy for dynamic search endpoints. Set to false to disable caching. */
31
- cache?: false | {
32
- /** CDN/proxy cache lifetime in seconds. Browser responses always revalidate. */
33
- sharedMaxAge?: number
34
- /** Time in seconds a shared cache may serve stale data while refreshing. */
35
- staleWhileRevalidate?: number
36
- }
37
- error?: {
38
- title?: string
39
- description?: string
40
- retryLabel?: string
41
- }
42
- /** Opt-in page collections exposed by the generated public search indexes. */
43
- collections?: SearchCollectionConfig[]
44
- }
45
- /**
46
- * Consumer-owned app config fields can be added through declaration merging.
47
- *
48
- * @example
49
- * declare module '@happydesigns/ui/types' {
50
- * interface HAppConfigExtensions {
51
- * contact?: { email?: string }
52
- * }
53
- * }
54
- */
55
- export interface HAppConfigExtensions {}
56
-
57
- export interface HAppConfigInput extends HAppConfigExtensions {
58
- meta?: {
59
- copyright?: {
60
- copyrightYear?: number
61
- copyrightHolder?: string
62
- copyrightHomepage?: string
63
- }
64
- socials?: ButtonProps[]
65
- github?: {
66
- repo?: string
67
- branch?: string
68
- dir?: string
69
- }
70
- }
71
- links?: {
72
- header?: NavigationMenuItem[]
73
- footer?: FooterColumn[]
74
- }
75
- search?: SearchConfig
76
- toc?: { title?: string }
77
- icons?: Record<string, string>
78
- date?: {
79
- locale?: string
80
- options?: Intl.DateTimeFormatOptions
81
- datetimeOptions?: Intl.DateTimeFormatOptions
82
- }
83
- }
84
- export interface HAppConfig extends HAppConfigInput {
85
- meta: NonNullable<HAppConfigInput['meta']>
86
- links: NonNullable<HAppConfigInput['links']>
87
- search: SearchConfig
88
- toc: NonNullable<HAppConfigInput['toc']>
89
- icons: Record<string, string>
90
- date: NonNullable<HAppConfigInput['date']>
91
- }
1
+ import type { SQLOperator } from '@nuxt/content'
2
+ import type { ButtonProps, CommandPaletteGroup, ContentSearchLink, FooterColumn, NavigationMenuItem } from '@nuxt/ui'
3
+ import type { CollectionName, PageCollectionName } from './content'
4
+
5
+ export type { CollectionName, ContentLink, PageCollectionName } from './content'
6
+
7
+ export type ActionButton = ButtonProps & {
8
+ /** Built-in type for a dynamic GitHub link (URL resolved from app.meta.github) */
9
+ action?: 'github-edit' | 'report-github-issue'
10
+ }
11
+
12
+ export interface QueryConfig {
13
+ fields?: string[]
14
+ where?: { field: string, operator: SQLOperator, value?: unknown }[]
15
+ order?: { field: string, direction: 'ASC' | 'DESC' } | false
16
+ }
17
+ export interface SearchCollectionConfig {
18
+ /** Page collection included in both generated search indexes. */
19
+ name: PageCollectionName
20
+ /** Filters applied before navigation and search sections are generated. */
21
+ where?: QueryConfig['where']
22
+ /** Optional stable ordering for generated entries. */
23
+ order?: QueryConfig['order']
24
+ }
25
+
26
+ export interface SearchConfig {
27
+ title?: string
28
+ description?: string
29
+ placeholder?: string
30
+ resultLimit?: number
31
+ links?: ContentSearchLink[]
32
+ groups?: CommandPaletteGroup[]
33
+ /** Shared-cache policy for dynamic search endpoints. Set to false to disable caching. */
34
+ cache?: false | {
35
+ /** CDN/proxy cache lifetime in seconds. Browser responses always revalidate. */
36
+ sharedMaxAge?: number
37
+ /** Time in seconds a shared cache may serve stale data while refreshing. */
38
+ staleWhileRevalidate?: number
39
+ }
40
+ error?: {
41
+ title?: string
42
+ description?: string
43
+ retryLabel?: string
44
+ }
45
+ /** Opt-in page collections exposed by the generated public search indexes. */
46
+ collections?: SearchCollectionConfig[]
47
+ }
48
+ /**
49
+ * Consumer-owned app config fields can be added through declaration merging.
50
+ *
51
+ * @example
52
+ * declare module '@happydesigns/ui/types' {
53
+ * interface HAppConfigExtensions {
54
+ * contact?: { email?: string }
55
+ * }
56
+ * }
57
+ */
58
+ export interface HAppConfigExtensions {}
59
+
60
+ export interface HAppConfigInput extends HAppConfigExtensions {
61
+ meta?: {
62
+ copyright?: {
63
+ copyrightYear?: number
64
+ copyrightHolder?: string
65
+ copyrightHomepage?: string
66
+ }
67
+ socials?: ButtonProps[]
68
+ github?: {
69
+ repo?: string
70
+ branch?: string
71
+ dir?: string
72
+ }
73
+ }
74
+ links?: {
75
+ header?: NavigationMenuItem[]
76
+ footer?: FooterColumn[]
77
+ }
78
+ search?: SearchConfig
79
+ content?: { userCollection?: CollectionName }
80
+ toc?: { title?: string }
81
+ icons?: Record<string, string>
82
+ date?: {
83
+ locale?: string
84
+ options?: Intl.DateTimeFormatOptions
85
+ datetimeOptions?: Intl.DateTimeFormatOptions
86
+ }
87
+ }
88
+ export interface HAppConfig extends HAppConfigInput {
89
+ meta: NonNullable<HAppConfigInput['meta']>
90
+ links: NonNullable<HAppConfigInput['links']>
91
+ search: SearchConfig
92
+ content: NonNullable<HAppConfigInput['content']>
93
+ toc: NonNullable<HAppConfigInput['toc']>
94
+ icons: Record<string, string>
95
+ date: NonNullable<HAppConfigInput['date']>
96
+ }
@@ -0,0 +1,14 @@
1
+ import type { Collections, PageCollections } from '@nuxt/content'
2
+ import type { ButtonProps } from '@nuxt/ui'
3
+
4
+ /** Preserves autocomplete for generated names while allowing runtime-defined collections. */
5
+ type ExtensibleName<T extends string> = T | (string & Record<never, never>)
6
+
7
+ /** Any generated collection name, with an escape hatch for runtime configuration. */
8
+ export type CollectionName = ExtensibleName<Extract<keyof Collections, string>>
9
+
10
+ /** Any generated page collection name, with an escape hatch for runtime configuration. */
11
+ export type PageCollectionName = ExtensibleName<Extract<keyof PageCollections, string>>
12
+
13
+ /** Serializable link data passed directly to Nuxt UI's Button component. */
14
+ export type ContentLink = ButtonProps
@@ -1,59 +1,60 @@
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']
1
+ import type { CollectionItemBase, CollectionQueryBuilder, Collections } from '@nuxt/content'
2
+ import type { UserProps } from '@nuxt/ui'
3
+ import type { CollectionName } from '../types/content'
4
+
5
+ interface UserRecord extends CollectionItemBase {
6
+ username: string
7
+ name?: UserProps['name']
8
+ description?: UserProps['description']
9
+ to?: UserProps['to']
10
+ avatar?: UserProps['avatar']
11
+ }
12
+
13
+ export type ResolvedUser = Omit<UserRecord, 'username'> & Partial<UserProps>
14
+
15
+ /** Removes the internal lookup key before passing a profile to Nuxt UI. */
16
+ export function toUserProps<T extends { username: string }>(
17
+ user: T,
18
+ extraProps: Partial<UserProps> = {},
19
+ ): Omit<T, 'username'> & Partial<UserProps> {
20
+ const { username: _lookupKey, ...profile } = user
21
+
22
+ return { ...profile, ...extraProps }
9
23
  }
10
24
 
11
- export type ResolvedUser = Omit<UserRecord, 'username'> & Partial<UserProps>
12
-
13
- /**
14
- * Removes the internal collection lookup key before passing a profile to Nuxt UI.
15
- */
16
- export function toUserProps<T extends { username: string }>(
17
- user: T,
18
- extraProps: Partial<UserProps> = {},
19
- ): Omit<T, 'username'> & Partial<UserProps> {
20
- const { username: _lookupKey, ...profile } = user
21
-
22
- return { ...profile, ...extraProps }
23
- }
24
-
25
- /**
26
- * Fetches user details once and keeps the lookup key available for callers
27
- * that need to associate a profile with several content entries.
28
- */
29
- export async function resolveUserMap(users: string[], extraProps: Partial<UserProps> = {}) {
30
- const uniqueUsers = [...new Set(users)]
31
-
32
- if (uniqueUsers.length === 0)
25
+ /** Fetches user details from the consumer-configured collection. */
26
+ export async function resolveUserMap(
27
+ users: string[],
28
+ extraProps: Partial<UserProps> = {},
29
+ collection: CollectionName = 'user',
30
+ ) {
31
+ const uniqueUsers = [...new Set(users)]
32
+
33
+ if (uniqueUsers.length === 0)
33
34
  return new Map<string, ResolvedUser>()
34
35
 
35
- const resolved = await queryCollection('user')
36
- .where('username', 'IN', uniqueUsers)
37
- .select('username', 'name', 'description', 'to', 'avatar')
38
- .all()
39
-
40
- return new Map(resolved.map(user => [user.username, toUserProps(user, extraProps)]))
41
- }
42
-
43
- /**
44
- * Fetches user details from the Nuxt Content user collection.
45
- *
46
- * The returned profiles follow the requested username order. Unknown users are omitted.
47
- *
48
- * @param users - A single username or an array of usernames
49
- * @returns A promise resolving to the selected user profiles
50
- */
51
- export default async function resolveUsers(users: string | string[], extraProps: Partial<UserProps> = {}) {
52
- const userList = Array.isArray(users) ? users : [users]
53
- const resolved = await resolveUserMap(userList, extraProps)
54
-
55
- return userList.flatMap((username) => {
56
- const user = resolved.get(username)
57
- return user ? [user] : []
58
- })
59
- }
36
+ const query = queryCollection(collection as keyof Collections) as unknown as CollectionQueryBuilder<UserRecord>
37
+ const resolved = await query
38
+ .where('username', 'IN', uniqueUsers)
39
+ .select('username', 'name', 'description', 'to', 'avatar')
40
+ .all()
41
+
42
+ return new Map(resolved.map(user => [user.username, toUserProps(user, extraProps)]))
43
+ }
44
+
45
+ /**
46
+ * Fetches user details in the requested username order. Unknown users are omitted.
47
+ */
48
+ export default async function resolveUsers(
49
+ users: string | string[],
50
+ extraProps: Partial<UserProps> = {},
51
+ collection: CollectionName = 'user',
52
+ ) {
53
+ const userList = Array.isArray(users) ? users : [users]
54
+ const resolved = await resolveUserMap(userList, extraProps, collection)
55
+
56
+ return userList.flatMap((username) => {
57
+ const user = resolved.get(username)
58
+ return user ? [user] : []
59
+ })
60
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@happydesigns/ui",
3
3
  "type": "module",
4
- "version": "0.18.0",
4
+ "version": "0.19.0",
5
5
  "private": false,
6
6
  "packageManager": "pnpm@11.11.0",
7
7
  "description": "A reusable Nuxt foundation for content-driven happydesigns websites and applications.",
@@ -32,7 +32,6 @@
32
32
  "main": "./nuxt.config.ts",
33
33
  "files": [
34
34
  "app",
35
- "content.config.ts",
36
35
  "nuxt.config.ts",
37
36
  "schemas",
38
37
  "server",
@@ -93,4 +92,4 @@
93
92
  "resolutions": {
94
93
  "@happydesigns/ui": "workspace:*"
95
94
  }
96
- }
95
+ }
@@ -1,50 +1,15 @@
1
1
  import { mergeVariantSchemas } from '@happydesigns/nuxt-variants/schemas'
2
- import { defineCollection } from '@nuxt/content'
3
- import { articleCollectionIndexes, userCollectionIndexes } from './indexes'
4
2
  import { variantSchemas } from './traits'
5
3
 
6
- export const collections = {
7
- snippet: defineCollection({
8
- type: 'page',
9
- source: {
10
- include: 'snippets/**/*.{md,yaml}',
11
- prefix: '/snippets',
12
- },
13
- }),
14
-
15
- article: defineCollection({
16
- type: 'page',
17
- source: {
18
- include: 'articles/**/*.{md,yaml}',
19
- prefix: '/articles',
20
- },
21
- schema: mergeVariantSchemas(['article'], variantSchemas),
22
- indexes: articleCollectionIndexes,
23
- }),
24
-
25
- event: defineCollection({
26
- type: 'page',
27
- source: {
28
- include: 'events/**/*.{md,yaml}',
29
- prefix: '/events',
30
- },
31
- schema: mergeVariantSchemas(['event'], variantSchemas),
32
- indexes: articleCollectionIndexes,
33
- }),
34
-
35
- page: defineCollection({
36
- type: 'page',
37
- source: {
38
- include: 'pages/**/*.{md,yaml}',
39
- prefix: '/',
40
- },
41
- schema: mergeVariantSchemas(['content'], variantSchemas),
42
- }),
43
-
44
- user: defineCollection({
45
- type: 'data',
46
- source: 'users/**/*.{md,yaml}',
47
- schema: mergeVariantSchemas(['user'], variantSchemas),
48
- indexes: userCollectionIndexes,
49
- }),
4
+ /**
5
+ * Source-agnostic schemas for consumer-owned Nuxt Content collections.
6
+ *
7
+ * Collection names, sources, prefixes and any project-specific schema fields
8
+ * intentionally remain in the consuming application's `content.config.ts`.
9
+ */
10
+ export const collectionSchemas = {
11
+ content: mergeVariantSchemas(['content'], variantSchemas),
12
+ article: mergeVariantSchemas(['article'], variantSchemas),
13
+ event: mergeVariantSchemas(['event'], variantSchemas),
14
+ user: mergeVariantSchemas(['user'], variantSchemas),
50
15
  }
package/schemas/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './collections'
2
+ export * from './indexes'
2
3
  export * from './traits'