blocks-dusted 0.1.8 → 0.1.9

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blocks-dusted",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Manifest-driven CLI for installing reusable Payload CMS blocks.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,4 +1,3 @@
1
- import { writeFile } from 'node:fs/promises'
2
1
  import { copySharedFiles, copyTemplateFiles, backupExistingDestination, plannedBackupPath } from '../installers/copyTemplateFiles.js'
3
2
  import { checkDependencies } from '../installers/installDependencies.js'
4
3
  import { checkRequirements } from '../installers/checkRequirements.js'
@@ -9,11 +8,7 @@ import { packageRoot } from '../utils/paths.js'
9
8
  import { fileExists, validateTargetProject } from '../utils/project.js'
10
9
 
11
10
  const SUPPORTED_HEADERS = new Set(['HeaderDD02'])
12
- const ACTIVE_HEADER_FILES = [
13
- 'src/Header/config.ts',
14
- 'src/Header/Nav/index.tsx',
15
- 'src/Header/RowLabel.tsx',
16
- ]
11
+ const ACTIVE_HEADER_DIRECTORY = 'src/Header'
17
12
 
18
13
  export async function addHeader({ headerName, targetDirectory = process.cwd(), dryRun = false }) {
19
14
  if (!headerName) throw new Error('A header name is required. Example: blocks-dusted header add HeaderDD02 --dry-run')
@@ -31,30 +26,17 @@ export async function addHeader({ headerName, targetDirectory = process.cwd(), d
31
26
  throw new Error(`Required project files are missing:\n${missingRequired.map(formatMissingRequirement).join('\n')}`)
32
27
  }
33
28
 
34
- const activeFileChecks = await Promise.all(
35
- ACTIVE_HEADER_FILES.map(async (path) => ({ path, exists: await fileExists(`${targetDirectory}/${path}`) })),
36
- )
37
- const missingActive = activeFileChecks.filter((check) => !check.exists)
38
- if (missingActive.length > 0) {
39
- throw new Error(`Active Header files are missing:\n${missingActive.map((check) => `- ${check.path}`).join('\n')}`)
40
- }
41
-
42
- const destinationBackupPath = checks.collisions.destinationExists
43
- ? await plannedBackupPath({ destinationPath: checks.collisions.destinationPath, targetDirectory })
29
+ const activeHeaderExists = await fileExists(`${targetDirectory}/${ACTIVE_HEADER_DIRECTORY}`)
30
+ const activeHeaderBackupPath = activeHeaderExists
31
+ ? await plannedBackupPath({ destinationPath: ACTIVE_HEADER_DIRECTORY, targetDirectory })
44
32
  : null
45
- const activeBackups = await Promise.all(
46
- ACTIVE_HEADER_FILES.map(async (path) => ({
47
- path,
48
- backupPath: await plannedBackupPath({ destinationPath: path, targetDirectory }),
49
- })),
50
- )
51
33
 
52
34
  heading('Header workflow')
53
35
  info(`Name: ${manifest.name}`)
54
36
  info(`Target directory: ${targetDirectory}`)
55
37
  info(`Payload config: ${project.payloadConfigPath}`)
56
38
  info(`Source template path: ${templateDirectory}`)
57
- info(`Target install path: ${checks.collisions.destinationPath}`)
39
+ info(`Active Header path: ${ACTIVE_HEADER_DIRECTORY}`)
58
40
 
59
41
  heading(dryRun ? 'Files that would be installed' : 'Files to install')
60
42
  for (const file of manifest.files) item(`${file.from} -> ${file.to}`)
@@ -73,17 +55,13 @@ export async function addHeader({ headerName, targetDirectory = process.cwd(), d
73
55
  }
74
56
  if (dependencyChecks.missing.length > 0) item(`Install command: ${installCommandText(dependencyChecks.packageManager, dependencyChecks.missing)}`)
75
57
 
76
- heading('Active Header backups')
77
- for (const backup of activeBackups) {
78
- item(dryRun ? `Would back up ${backup.path} to ${backup.backupPath}` : `Will back up ${backup.path} to ${backup.backupPath}`)
79
- }
80
- if (destinationBackupPath) {
81
- item(dryRun ? `Would back up ${checks.collisions.destinationPath} to ${destinationBackupPath}` : `Will back up ${checks.collisions.destinationPath} to ${destinationBackupPath}`)
82
- }
58
+ heading('Active Header backup')
59
+ if (activeHeaderBackupPath) item(dryRun ? `Would back up ${ACTIVE_HEADER_DIRECTORY} to ${activeHeaderBackupPath}` : `Will back up ${ACTIVE_HEADER_DIRECTORY} to ${activeHeaderBackupPath}`)
60
+ else item('No existing src/Header directory found; a new active Header will be installed.')
83
61
 
84
- heading('Activation patches')
85
- item('Patch src/Header/Nav/index.tsx to render HeaderDD02')
86
- item('Patch src/Header/config.ts to expose HeaderDD02 fields and preserve legacy navItems as hidden data')
62
+ heading('Activation')
63
+ item('Install a complete active src/Header replacement wired to HeaderDD02.')
64
+ item('The previous Header folder is preserved as src/Header.bak, src/Header.bak.1, or the next available backup path.')
87
65
 
88
66
  if (dryRun) {
89
67
  const sharedResults = await copySharedFiles({ manifest, packageRoot, targetDirectory, dryRun: true })
@@ -95,17 +73,8 @@ export async function addHeader({ headerName, targetDirectory = process.cwd(), d
95
73
  }
96
74
 
97
75
  const sharedResults = await copySharedFiles({ manifest, packageRoot, targetDirectory })
98
-
99
- if (checks.collisions.destinationExists) {
100
- await backupExistingDestination({ destinationPath: checks.collisions.destinationPath, targetDirectory })
101
- }
102
- for (const file of ACTIVE_HEADER_FILES) {
103
- await backupExistingDestination({ destinationPath: file, targetDirectory })
104
- }
105
-
76
+ if (activeHeaderExists) await backupExistingDestination({ destinationPath: ACTIVE_HEADER_DIRECTORY, targetDirectory })
106
77
  const copiedFiles = await copyTemplateFiles({ manifest, templateDirectory, targetDirectory })
107
- await writeFile(`${targetDirectory}/src/Header/Nav/index.tsx`, renderHeaderNav())
108
- await writeFile(`${targetDirectory}/src/Header/config.ts`, renderHeaderConfig())
109
78
 
110
79
  heading('Copied files')
111
80
  copiedFiles.forEach((file) => item(file))
@@ -122,14 +91,6 @@ export async function addHeader({ headerName, targetDirectory = process.cwd(), d
122
91
  info('Header workflow complete.')
123
92
  }
124
93
 
125
- function renderHeaderNav() {
126
- return `import React from 'react'\n\nimport type { Header as HeaderType } from '@/payload-types'\n\nimport HeaderDD02 from '@/Header/variants/HeaderDD02'\n\nexport const HeaderNav: React.FC<{ data: HeaderType }> = ({ data }) => {\n return <HeaderDD02 data={data} />\n}\n`
127
- }
128
-
129
- function renderHeaderConfig() {
130
- return `import type { GlobalConfig } from 'payload'\n\nimport { iconPicker } from '@/fields/lucide-icon-picker/field'\nimport { link } from '@/fields/link'\nimport { HeaderDD02 } from '@/Header/variants/HeaderDD02/config'\nimport { revalidateHeader } from './hooks/revalidateHeader'\n\nexport const Header: GlobalConfig = {\n slug: 'header',\n access: {\n read: () => true,\n update: () => true,\n },\n fields: [\n {\n name: 'variant',\n label: 'Variant',\n type: 'select',\n defaultValue: 'header02',\n options: [{ label: 'Header DD 02', value: 'header02' }],\n admin: {\n position: 'sidebar',\n },\n },\n {\n name: 'header02',\n type: 'group',\n fields: HeaderDD02,\n },\n {\n name: 'navItems',\n type: 'array',\n admin: {\n hidden: true,\n description: 'Legacy starter Header navItems retained so existing stored header data is not discarded.',\n },\n fields: [\n link({ appearances: false }),\n iconPicker({\n name: 'icon',\n required: false,\n description: 'Legacy optional icon to display with the navigation item',\n }),\n ],\n },\n ],\n hooks: {\n afterChange: [revalidateHeader],\n },\n}\n`
131
- }
132
-
133
94
  function formatMissingRequirement(check) {
134
95
  const resolution = check.resolution ? `\n Resolve: ${check.resolution}` : ''
135
96
  return `- ${check.path}: ${check.reason}${resolution}`
@@ -142,4 +103,4 @@ function formatDependency(dependency) {
142
103
  function installCommandText(packageManager, dependencies) {
143
104
  const command = packageManager === 'yarn' ? ['yarn', 'add'] : packageManager === 'bun' ? ['bun', 'add'] : packageManager === 'npm' ? ['npm', 'install'] : ['pnpm', 'add']
144
105
  return [...command, ...dependencies.map(formatDependency)].join(' ')
145
- }
106
+ }
@@ -0,0 +1,9 @@
1
+ 'use client'
2
+
3
+ import type { Header as HeaderType } from '@/payload-types'
4
+
5
+ import { HeaderNav } from './Nav'
6
+
7
+ export const HeaderClient: React.FC<{ data: HeaderType }> = ({ data }) => {
8
+ return <HeaderNav data={data} />
9
+ }
@@ -0,0 +1,10 @@
1
+ import type { Header as HeaderType } from '@/payload-types'
2
+ import { getCachedGlobal } from '@/utilities/getGlobals'
3
+
4
+ import { HeaderClient } from './Component.client'
5
+
6
+ export async function Header() {
7
+ const headerData = (await getCachedGlobal('header', 1)()) as HeaderType | null
8
+
9
+ return <HeaderClient data={headerData ?? ({} as HeaderType)} />
10
+ }
@@ -0,0 +1,33 @@
1
+ import type { GlobalConfig } from 'payload'
2
+
3
+ import { HeaderDD02 } from '@/Header/variants/HeaderDD02/config'
4
+
5
+ import { revalidateHeader } from './hooks/revalidateHeader'
6
+
7
+ export const Header: GlobalConfig = {
8
+ slug: 'header',
9
+ access: {
10
+ read: () => true,
11
+ update: () => true,
12
+ },
13
+ fields: [
14
+ {
15
+ name: 'variant',
16
+ label: 'Variant',
17
+ type: 'select',
18
+ defaultValue: 'header02',
19
+ options: [{ label: 'Header DD 02', value: 'header02' }],
20
+ admin: {
21
+ position: 'sidebar',
22
+ },
23
+ },
24
+ {
25
+ name: 'header02',
26
+ type: 'group',
27
+ fields: HeaderDD02,
28
+ },
29
+ ],
30
+ hooks: {
31
+ afterChange: [revalidateHeader],
32
+ },
33
+ }
@@ -0,0 +1,9 @@
1
+ 'use client'
2
+
3
+ import type { Header as HeaderType } from '@/payload-types'
4
+
5
+ import HeaderDD02 from '@/Header/variants/HeaderDD02'
6
+
7
+ export const HeaderNav: React.FC<{ data: HeaderType }> = ({ data }) => {
8
+ return <HeaderDD02 data={data} />
9
+ }
@@ -4,48 +4,55 @@ HeaderDD02 is the exported Header02 implementation from DesignsDustedv3.
4
4
 
5
5
  This header uses the shared `defaultLexical` editor standard from `@/fields/defaultLexical`. Project-specific Lexical blocks are intentionally not bundled. The nested `BlocksFeature` uses an empty `blocks` array so each target project can register only the blocks it requires.
6
6
 
7
+ The header workflow backs up the active `src/Header` folder before installing a complete replacement Header shell wired directly to `HeaderDD02`.
8
+
7
9
  Included files:
8
10
 
9
- - `index.tsx` for the HeaderDD02 desktop runtime.
10
- - `MobileBottomNav/index.tsx` because Header02 imports it directly.
11
- - `config.ts` for the Header02 field structure adapted to `HeaderDD02` and `defaultLexical`.
12
- - `RowLabel.tsx` because the Header02 config references `/Header/RowLabel.tsx#RowLabel` for Payload admin array labels.
11
+ - `Component.tsx` for the active server Header component.
12
+ - `Component.client.tsx` for the active client Header wrapper.
13
+ - `Nav/index.tsx` to render `HeaderDD02` directly.
14
+ - `config.ts` for the active Payload Header global.
15
+ - `hooks/revalidateHeader.ts` for Header global revalidation.
16
+ - `RowLabel.tsx` for Payload admin array labels.
17
+ - `variants/HeaderDD02/index.tsx` for the HeaderDD02 desktop runtime.
18
+ - `variants/HeaderDD02/MobileBottomNav/index.tsx` because Header02 imports it directly.
19
+ - `variants/HeaderDD02/config.ts` for the Header02 field structure adapted to `HeaderDD02` and `defaultLexical`.
13
20
 
14
21
  Not included:
15
22
 
16
23
  - Header01 and Header03 implementations.
17
- - The parent multi-variant Header shell.
18
24
  - Source project Lexical blocks: `AnimatedText`, `ButtonWithIcon`, `CounterBlock`, and `MediaBlock`.
19
25
 
20
- Before activating this header in an existing project, inspect the current Header global schema and stored Header data. The template installer copies files and backs up the `HeaderDD02` destination folder when it already exists, but it does not automatically replace the active Header global or inspect database content.
26
+ Removed source Lexical block imports: `@/blocks/AnimatedText/config`, `@/blocks/ButtonWithIcon/config`, `@/blocks/CounterBlock/config`, `@/blocks/MediaBlock/config`.
27
+
28
+ Before activating this header in an existing project, inspect the current Header global schema and stored Header data. The header workflow preserves the old active Header folder as `src/Header.bak`, `src/Header.bak.1`, or the next available backup path. It does not rewrite stored rich text data or run destructive migrations.
21
29
 
22
30
  ## AI handover prompt
23
31
 
24
32
  ```prompt
25
- Review the newly installed HeaderDD02 files and integrate them into this project
33
+ Review the newly installed HeaderDD02 files in this project
26
34
 
27
35
  Do not assume the source project architecture matches this repository.
28
36
 
29
37
  Tasks:
30
38
 
31
- 1. Inspect the current Header component, Payload Header global, frontend layout, fields, utilities, generated types and styling conventions.
32
- 2. Resolve HeaderDD02 imports against the current project.
39
+ 1. Inspect the active Header component, Payload Header global, frontend layout, fields, utilities, generated types and styling conventions.
40
+ 2. Confirm `src/Header/Component.tsx`, `src/Header/Component.client.tsx`, `src/Header/Nav/index.tsx`, and `src/Header/config.ts` now point to HeaderDD02.
33
41
  3. Reuse existing project utilities and fields where appropriate.
34
- 4. Adapt HeaderDD02 config to the current Header global without deleting or destructively renaming existing database-backed fields.
42
+ 4. Confirm the active Header global has not created a duplicate Header registration.
35
43
  5. Keep the shared defaultLexical standard.
36
44
  6. Keep BlocksFeature({ blocks: [] }).
37
- 7. Integrate the component into the existing header render flow.
38
- 8. Preserve the existing layout, providers, transitions and mobile behaviour.
39
- 9. Add any required CSS variables or utility classes using the current project's styling system.
40
- 10. Report every file modified and any manual content migration required.
45
+ 7. Preserve layout, providers, transitions and mobile behaviour that are intentionally kept by the target project.
46
+ 8. Add any required CSS variables or utility classes using the current project's styling system.
47
+ 9. Report every file modified and any manual content migration required.
41
48
 
42
49
  Do not modify database records automatically.
43
50
  Do not run destructive migrations.
44
- Do not remove the existing header until the replacement is verified.
51
+ Do not delete the backup folder until the replacement is verified.
45
52
  ```
46
53
 
47
54
  ## Bundled shared UI primitives
48
55
 
49
56
  HeaderDD02 includes shared templates for `src/components/ui/navigation-menu.tsx`, `src/components/animate-ui/components/animate/tooltip.tsx`, `src/components/animate-ui/primitives/animate/tooltip.tsx`, `src/components/animate-ui/primitives/animate/slot.tsx`, and `src/lib/get-strict-context.tsx`. The installer copies them only when missing and preserves existing target files.
50
57
 
51
- If package dependencies are missing, run the install command printed by the CLI, for example `pnpm add @radix-ui/react-navigation-menu class-variance-authority motion @floating-ui/react`.
58
+ If package dependencies are missing, run the install command printed by the CLI, for example `pnpm add @radix-ui/react-navigation-menu class-variance-authority motion @floating-ui/react`.
@@ -0,0 +1,11 @@
1
+ import type { GlobalAfterChangeHook } from 'payload'
2
+ import { revalidateTag } from 'next/cache'
3
+
4
+ export const revalidateHeader: GlobalAfterChangeHook = ({ doc, req: { payload, context } }) => {
5
+ if (!context.disableRevalidate) {
6
+ payload.logger.info('Revalidating header')
7
+ revalidateTag('global_header')
8
+ }
9
+
10
+ return doc
11
+ }
@@ -17,15 +17,33 @@
17
17
  "@/blocks/CounterBlock/config",
18
18
  "@/blocks/MediaBlock/config"
19
19
  ],
20
- "excludedHeaderFiles": [
21
- "src/Header/Component.tsx",
22
- "src/Header/Component.client.tsx",
23
- "src/Header/config.ts",
24
- "src/Header/Nav/index.tsx",
25
- "src/Header/hooks/revalidateHeader.ts"
26
- ]
20
+ "excludedHeaderFiles": []
27
21
  },
28
22
  "files": [
23
+ {
24
+ "from": "Component.tsx",
25
+ "to": "src/Header/Component.tsx"
26
+ },
27
+ {
28
+ "from": "Component.client.tsx",
29
+ "to": "src/Header/Component.client.tsx"
30
+ },
31
+ {
32
+ "from": "Header.config.ts",
33
+ "to": "src/Header/config.ts"
34
+ },
35
+ {
36
+ "from": "Nav/index.tsx",
37
+ "to": "src/Header/Nav/index.tsx"
38
+ },
39
+ {
40
+ "from": "hooks/revalidateHeader.ts",
41
+ "to": "src/Header/hooks/revalidateHeader.ts"
42
+ },
43
+ {
44
+ "from": "RowLabel.tsx",
45
+ "to": "src/Header/RowLabel.tsx"
46
+ },
29
47
  {
30
48
  "from": "index.tsx",
31
49
  "to": "src/Header/variants/HeaderDD02/index.tsx"
@@ -38,10 +56,6 @@
38
56
  "from": "config.ts",
39
57
  "to": "src/Header/variants/HeaderDD02/config.ts"
40
58
  },
41
- {
42
- "from": "RowLabel.tsx",
43
- "to": "src/Header/RowLabel.tsx"
44
- },
45
59
  {
46
60
  "from": "README.md",
47
61
  "to": "src/Header/variants/HeaderDD02/README.md"
@@ -90,6 +104,10 @@
90
104
  {
91
105
  "path": "src/utilities/ui.ts",
92
106
  "reason": "HeaderDD02 uses cn from @/utilities/ui."
107
+ },
108
+ {
109
+ "path": "src/utilities/getGlobals.ts",
110
+ "reason": "The active Header server component fetches the Payload header global through getCachedGlobal."
93
111
  }
94
112
  ],
95
113
  "collectionRegistration": {
@@ -101,8 +119,7 @@
101
119
  "manual": [
102
120
  "This header uses the shared `defaultLexical` editor standard from `@/fields/defaultLexical`. Project-specific Lexical blocks are intentionally not bundled. The nested `BlocksFeature` uses an empty `blocks` array so each target project can register only the blocks it requires.",
103
121
  "Removed source Lexical block imports: `@/blocks/AnimatedText/config`, `@/blocks/ButtonWithIcon/config`, `@/blocks/CounterBlock/config`, `@/blocks/MediaBlock/config`.",
104
- "HeaderDD02 installs the Header02 runtime component, MobileBottomNav, Header02 field config, and the RowLabel admin helper only. Header01 and Header03 are not bundled.",
105
- "This component template does not yet patch an existing active Header global, replace Header/Component.tsx, or inspect database-stored Header content automatically. Review the existing Header global before activation and back up active files before wiring the variant into the target project.",
122
+ "HeaderDD02 header workflow backs up the existing active src/Header folder, then installs a complete replacement Header shell wired directly to HeaderDD02. Header01 and Header03 are not bundled.",
106
123
  "Inspect any existing target Header richText data before replacing an active Header schema. Do not apply the empty nested blocks extension point to stored content that already depends on registered block node types.",
107
124
  "Verify the target `src/fields/defaultLexical.ts` exports a compatible `defaultLexical` helper that accepts `defaultLexical({ features: [] })` and does not inject unrelated project-specific blocks.",
108
125
  "Wire `HeaderDD02` into the target Header global or render it directly after confirming the target project will not render two headers.",
@@ -111,8 +128,7 @@
111
128
  "manualSteps": [
112
129
  "This header uses the shared `defaultLexical` editor standard from `@/fields/defaultLexical`. Project-specific Lexical blocks are intentionally not bundled. The nested `BlocksFeature` uses an empty `blocks` array so each target project can register only the blocks it requires.",
113
130
  "Removed source Lexical block imports: `@/blocks/AnimatedText/config`, `@/blocks/ButtonWithIcon/config`, `@/blocks/CounterBlock/config`, `@/blocks/MediaBlock/config`.",
114
- "HeaderDD02 installs the Header02 runtime component, MobileBottomNav, Header02 field config, and the RowLabel admin helper only. Header01 and Header03 are not bundled.",
115
- "This component template does not yet patch an existing active Header global, replace Header/Component.tsx, or inspect database-stored Header content automatically. Review the existing Header global before activation and back up active files before wiring the variant into the target project.",
131
+ "HeaderDD02 header workflow backs up the existing active src/Header folder, then installs a complete replacement Header shell wired directly to HeaderDD02. Header01 and Header03 are not bundled.",
116
132
  "Inspect any existing target Header richText data before replacing an active Header schema. Do not apply the empty nested blocks extension point to stored content that already depends on registered block node types.",
117
133
  "Verify the target `src/fields/defaultLexical.ts` exports a compatible `defaultLexical` helper that accepts `defaultLexical({ features: [] })` and does not inject unrelated project-specific blocks.",
118
134
  "Wire `HeaderDD02` into the target Header global or render it directly after confirming the target project will not render two headers.",
@@ -121,7 +137,7 @@
121
137
  "notes": [
122
138
  "Converted from DesignsDustedv3 Header02 after tracing Header/variants/Header02/index.tsx and its direct imports.",
123
139
  "Header02 styling is inline Tailwind class usage plus style jsx global blocks in index.tsx and MobileBottomNav/index.tsx; no separate Header02 stylesheet was imported.",
124
- "Parent Header files were audited but excluded because the reusable export targets Header02 only, not the multi-variant app header shell.",
140
+ "The header workflow now installs active Component.tsx, Component.client.tsx, config.ts, Nav, RowLabel, and revalidateHeader files so the installed header is wired into the project immediately.",
125
141
  "NavigationMenu and animate-ui tooltip primitives are bundled as shared files because HeaderDD02 imports them directly."
126
142
  ],
127
143
  "backupExistingDestination": true,