@happydesigns/ui 0.19.0 → 0.19.2

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.
@@ -0,0 +1,54 @@
1
+ <script setup lang="ts" generic="C extends PageCollectionName = 'page'">
2
+ import type { PageCollectionItemBase } from '@nuxt/content'
3
+ import type { PageCollectionName } from '../types/content'
4
+
5
+ defineOptions({ inheritAttrs: false })
6
+
7
+ const {
8
+ collection = 'page' as C,
9
+ path,
10
+ page: suppliedPage,
11
+ } = defineProps<{
12
+ /** Consumer-owned page collection. */
13
+ collection?: C
14
+ /** Route path override. The current route path is used by default. */
15
+ path?: string
16
+ /** Already resolved document, useful when a route needs project-specific side effects. */
17
+ page?: PageCollectionItemBase | null
18
+ }>()
19
+
20
+ const fetched = suppliedPage === undefined
21
+ ? await usePageContent<C>({
22
+ collection: () => collection,
23
+ path: () => path,
24
+ })
25
+ : undefined
26
+
27
+ const page = computed(() => suppliedPage === undefined ? fetched?.data.value : suppliedPage)
28
+
29
+ if (!page.value) {
30
+ throw createError({
31
+ statusCode: 404,
32
+ statusMessage: `${collection} ${path || useRoute().path} not found`,
33
+ fatal: true,
34
+ })
35
+ }
36
+ </script>
37
+
38
+ <template>
39
+ <NuxtLayout
40
+ v-if="page"
41
+ name="content"
42
+ :collection="collection"
43
+ :path="path"
44
+ :page="page"
45
+ >
46
+ <slot :page="page">
47
+ <ContentRenderer
48
+ :value="page"
49
+ class="h-content"
50
+ v-bind="$attrs"
51
+ />
52
+ </slot>
53
+ </NuxtLayout>
54
+ </template>
@@ -0,0 +1,85 @@
1
+ <script setup lang="ts">
2
+ import type { HeaderProps, NavigationMenuItem, NavigationMenuProps } from '@nuxt/ui'
3
+
4
+ type NavigationProps = Omit<NavigationMenuProps, 'items' | 'orientation' | 'modelValue' | 'defaultValue' | 'type'>
5
+
6
+ interface Props extends HeaderProps {
7
+ /** Override the app-config navigation for this header instance. */
8
+ items?: NavigationMenuItem[]
9
+ /** Props forwarded to the desktop navigation menu. */
10
+ navigation?: NavigationProps
11
+ /** Props forwarded to the mobile navigation menu. */
12
+ mobileNavigation?: NavigationProps
13
+ }
14
+
15
+ const props = withDefaults(defineProps<Props>(), {
16
+ autoClose: true,
17
+ toggle: true,
18
+ })
19
+ const open = defineModel<boolean>('open', { default: false })
20
+
21
+ const { headerLinks } = useHeaderLinks()
22
+ const items = computed(() => props.items ?? headerLinks.value)
23
+ const headerProps = computed<HeaderProps>(() => ({
24
+ as: props.as,
25
+ autoClose: props.autoClose,
26
+ class: props.class,
27
+ menu: props.menu,
28
+ mode: props.mode,
29
+ title: props.title,
30
+ to: props.to,
31
+ toggle: props.toggle,
32
+ toggleSide: props.toggleSide,
33
+ ui: props.ui,
34
+ }))
35
+ </script>
36
+
37
+ <template>
38
+ <UHeader v-model:open="open" v-bind="headerProps">
39
+ <template v-if="$slots.left" #left="slotProps">
40
+ <slot name="left" v-bind="slotProps" />
41
+ </template>
42
+
43
+ <template v-if="$slots.title" #title>
44
+ <slot name="title" />
45
+ </template>
46
+
47
+ <slot name="navigation" :items="items">
48
+ <UNavigationMenu
49
+ v-bind="props.navigation"
50
+ :items="items"
51
+ orientation="horizontal"
52
+ />
53
+ </slot>
54
+
55
+ <template v-if="$slots.right" #right>
56
+ <slot name="right" />
57
+ </template>
58
+
59
+ <template #body="slotProps">
60
+ <slot name="body" v-bind="slotProps" :items="items">
61
+ <slot name="body-before" :items="items" />
62
+ <slot name="mobile-navigation" :items="items">
63
+ <UNavigationMenu
64
+ v-bind="props.mobileNavigation"
65
+ :items="items"
66
+ orientation="vertical"
67
+ />
68
+ </slot>
69
+ <slot name="body-after" :items="items" />
70
+ </slot>
71
+ </template>
72
+
73
+ <template v-if="$slots.content" #content="slotProps">
74
+ <slot name="content" v-bind="slotProps" :items="items" />
75
+ </template>
76
+
77
+ <template v-if="$slots.top" #top>
78
+ <slot name="top" />
79
+ </template>
80
+
81
+ <template v-if="$slots.bottom" #bottom>
82
+ <slot name="bottom" />
83
+ </template>
84
+ </UHeader>
85
+ </template>
@@ -1,21 +1,27 @@
1
- <script setup lang="ts" generic="C extends PageCollectionName = 'page'">
2
- import type { PageCollectionName } from '../types/content'
1
+ <script setup lang="ts" generic="C extends PageCollectionName = 'page'">
2
+ import type { PageCollectionItemBase } from '@nuxt/content'
3
+ import type { PageCollectionName } from '../types/content'
3
4
 
4
- const {
5
- path,
6
- collection = 'page' as C,
7
- } = defineProps<{
8
- path?: string
9
- collection?: C
10
- }>()
5
+ const {
6
+ path,
7
+ collection = 'page' as C,
8
+ page: suppliedPage,
9
+ } = defineProps<{
10
+ path?: string
11
+ collection?: C
12
+ page?: PageCollectionItemBase | null
13
+ }>()
11
14
 
12
15
  const appConfig = useAppConfig()
13
16
  const route = useRoute()
14
17
 
15
- const { data: page } = await usePageContent<C>({
16
- path: () => path,
17
- collection: () => collection,
18
- })
18
+ const fetched = suppliedPage === undefined
19
+ ? await usePageContent<C>({
20
+ path: () => path,
21
+ collection: () => collection,
22
+ })
23
+ : undefined
24
+ const page = computed(() => suppliedPage === undefined ? fetched?.data.value : suppliedPage)
19
25
 
20
26
  const variant = computed(() => {
21
27
  if (typeof route.meta.variant === 'string' && route.meta.variant) {
@@ -26,7 +32,7 @@ const variant = computed(() => {
26
32
  return route.meta.layout
27
33
  }
28
34
 
29
- return collection
35
+ return collection as string
30
36
  })
31
37
  const { has } = useVariant(variant)
32
38
  const hasHeader = has('header')
@@ -35,7 +41,7 @@ const hasToc = has('toc')
35
41
  if (!page.value) {
36
42
  throw createError({
37
43
  statusCode: 404,
38
- statusMessage: `${collection} ${path || route.path} not found`,
44
+ statusMessage: `${collection} ${path || route.path} not found`,
39
45
  fatal: true,
40
46
  })
41
47
  }
@@ -0,0 +1,20 @@
1
+ interface ContentRouteLocation {
2
+ path?: string
3
+ fullPath?: string
4
+ }
5
+
6
+ const FILE_PATH_PATTERN = /\/[^/]+\.[0-9a-z]+$/i
7
+
8
+ /**
9
+ * Keeps a catch-all content page away from Nuxt internals, API routes and
10
+ * requests that look like public files.
11
+ */
12
+ export function isContentPageRoute(route: ContentRouteLocation): boolean {
13
+ const path = route.path ?? route.fullPath?.split(/[?#]/, 1)[0] ?? ''
14
+
15
+ if (path.startsWith('/_') || path === '/api' || path.startsWith('/api/')) {
16
+ return false
17
+ }
18
+
19
+ return !FILE_PATH_PATTERN.test(path)
20
+ }
package/nuxt.config.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { variantRegistry } from './schemas/variants'
2
+
1
3
  // https://nuxt.com/docs/api/configuration/nuxt-config
2
4
  export default defineNuxtConfig({
3
5
 
@@ -19,41 +21,7 @@ export default defineNuxtConfig({
19
21
  ],
20
22
 
21
23
  variants: {
22
- registry: {
23
- // Data features — schema only, no config
24
- dates: {},
25
- authors: {},
26
- category: {},
27
- published: {},
28
- header: {},
29
- toc: {},
30
- links: {},
31
- location: {},
32
- layout: {},
33
- separatorButtons: {},
34
-
35
- // UI features — config defined in app.config.ts
36
- user: {},
37
- backButton: {},
38
- copyButton: {},
39
- separator: {},
40
- surround: {},
41
-
42
- // Collection variants — extends chains defined here for graph generation
43
- snippet: {},
44
- article: {
45
- extends: ['dates', 'authors', 'category', 'published', 'header', 'toc', 'surround', 'copyButton', 'separator', 'backButton'],
46
- config: {},
47
- },
48
- event: {
49
- extends: ['dates', 'location', 'category', 'links', 'published', 'header', 'toc', 'surround', 'copyButton', 'separator', 'backButton'],
50
- config: {},
51
- },
52
- content: {
53
- extends: ['layout', 'header', 'toc'],
54
- config: {},
55
- },
56
- },
24
+ registry: variantRegistry,
57
25
  },
58
26
 
59
27
  studio: false,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@happydesigns/ui",
3
3
  "type": "module",
4
- "version": "0.19.0",
4
+ "version": "0.19.2",
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.",
@@ -65,7 +65,7 @@
65
65
  "tailwindcss": "^4.3.2"
66
66
  },
67
67
  "dependencies": {
68
- "@happydesigns/nuxt-variants": "^0.0.6",
68
+ "@happydesigns/nuxt-variants": "^0.1.1",
69
69
  "@iconify-json/heroicons": "^1.2.3",
70
70
  "@iconify-json/lucide": "^1.2.116",
71
71
  "@iconify-json/simple-icons": "^1.2.89",
@@ -1,5 +1,8 @@
1
- import { mergeVariantSchemas } from '@happydesigns/nuxt-variants/schemas'
2
- import { variantSchemas } from './traits'
1
+ import { createVariantSchemaResolver } from '@happydesigns/nuxt-variants/schemas'
2
+ import { variantSchemas } from './traits'
3
+ import { variantRegistry } from './variants'
4
+
5
+ const resolveVariantSchema = createVariantSchemaResolver(variantRegistry, variantSchemas)
3
6
 
4
7
  /**
5
8
  * Source-agnostic schemas for consumer-owned Nuxt Content collections.
@@ -7,9 +10,9 @@ import { variantSchemas } from './traits'
7
10
  * Collection names, sources, prefixes and any project-specific schema fields
8
11
  * intentionally remain in the consuming application's `content.config.ts`.
9
12
  */
10
- export const collectionSchemas = {
11
- content: mergeVariantSchemas(['content'], variantSchemas),
12
- article: mergeVariantSchemas(['article'], variantSchemas),
13
- event: mergeVariantSchemas(['event'], variantSchemas),
14
- user: mergeVariantSchemas(['user'], variantSchemas),
15
- }
13
+ export const collectionSchemas = {
14
+ content: resolveVariantSchema(['content']),
15
+ article: resolveVariantSchema(['article']),
16
+ event: resolveVariantSchema(['event']),
17
+ user: resolveVariantSchema(['user']),
18
+ }
package/schemas/index.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export * from './collections'
2
- export * from './indexes'
3
- export * from './traits'
2
+ export * from './indexes'
3
+ export * from './primitives'
4
+ export * from './traits'
5
+ export * from './variants'
@@ -0,0 +1,19 @@
1
+ import { property } from '@nuxt/content'
2
+ import { z } from 'zod'
3
+
4
+ /** Studio-aware string field for media stored in the consumer application. */
5
+ export const mediaSourceSchema = property(z.string()).editor({ input: 'media' })
6
+
7
+ /** Accessible baseline for content-managed images. Projects can extend it. */
8
+ export const contentImageSchema = z.object({
9
+ src: mediaSourceSchema,
10
+ alt: z.string(),
11
+ })
12
+
13
+ /**
14
+ * Creates a Studio-aware schema that inherits the current Nuxt UI PageSection
15
+ * props while retaining project-specific fields.
16
+ */
17
+ export function createPageSectionSchema<T extends Record<string, z.ZodType>>(shape: T) {
18
+ return property(z.object(shape)).inherit('@nuxt/ui/components/PageSection.vue')
19
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Public variant registry shared by the Nuxt module and schema composition.
3
+ *
4
+ * Keeping the registry in one place guarantees that runtime inheritance and
5
+ * Nuxt Content schemas are derived from the same explicit variant graph.
6
+ */
7
+ export const variantRegistry = {
8
+ // Data features — schema only, no config
9
+ dates: {},
10
+ authors: {},
11
+ category: {},
12
+ published: {},
13
+ header: {},
14
+ toc: {},
15
+ links: {},
16
+ location: {},
17
+ layout: {},
18
+ separatorButtons: {},
19
+
20
+ // UI features — config defined in app.config.ts
21
+ user: {},
22
+ backButton: {},
23
+ copyButton: {},
24
+ separator: {},
25
+ surround: {},
26
+
27
+ // Collection variants — extends chains defined here for graph generation
28
+ snippet: {},
29
+ article: {
30
+ extends: ['dates', 'authors', 'category', 'published', 'header', 'toc', 'surround', 'copyButton', 'separator', 'backButton'],
31
+ config: {},
32
+ },
33
+ event: {
34
+ extends: ['dates', 'location', 'category', 'links', 'published', 'header', 'toc', 'surround', 'copyButton', 'separator', 'backButton'],
35
+ config: {},
36
+ },
37
+ content: {
38
+ extends: ['layout', 'header', 'toc'],
39
+ config: {},
40
+ },
41
+ }