@delmaredigital/payload-puck 0.3.0 → 0.3.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 (2) hide show
  1. package/README.md +178 -29
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -12,6 +12,7 @@ A PayloadCMS plugin for integrating [Puck](https://puckeditor.com) visual page b
12
12
  - [Core Concepts](#core-concepts)
13
13
  - [Components](#components)
14
14
  - [Custom Fields](#custom-fields)
15
+ - [Building Custom Components](#building-custom-components)
15
16
  - [Theming](#theming)
16
17
  - [Layouts](#layouts)
17
18
  - [Page-Tree Integration](#page-tree-integration)
@@ -172,6 +173,8 @@ export default async function Page({
172
173
 
173
174
  ### Tailwind Typography (Required)
174
175
 
176
+ > Required only if using the RichText component.
177
+
175
178
  The RichText component uses `@tailwindcss/typography`:
176
179
 
177
180
  ```bash
@@ -194,6 +197,8 @@ module.exports = {
194
197
 
195
198
  ### Package Scanning (Required)
196
199
 
200
+ > Required if your project uses Tailwind CSS. Ensures component classes are included in your build.
201
+
197
202
  Tell Tailwind to scan the plugin's components:
198
203
 
199
204
  **Tailwind v4:**
@@ -213,9 +218,11 @@ module.exports = {
213
218
  }
214
219
  ```
215
220
 
216
- ### Theme CSS Variables
221
+ ### Theme CSS Variables (Optional)
222
+
223
+ > Optional - the plugin includes sensible defaults. Define these only to customize colors in rendered content (links, borders, etc).
217
224
 
218
- The plugin uses [shadcn/ui](https://ui.shadcn.com)-style CSS variables. If you don't use shadcn/ui, define these in your CSS:
225
+ The plugin uses [shadcn/ui](https://ui.shadcn.com)-style CSS variables. If you don't use shadcn/ui and want to customize colors, define these in your CSS:
219
226
 
220
227
  ```css
221
228
  :root {
@@ -369,6 +376,155 @@ import {
369
376
 
370
377
  ---
371
378
 
379
+ ## Building Custom Components
380
+
381
+ The plugin exports individual component configs and field factories for building custom Puck configurations.
382
+
383
+ ### Cherry-Picking Components
384
+
385
+ Import only the components you need:
386
+
387
+ ```typescript
388
+ import {
389
+ SectionConfig,
390
+ HeadingConfig,
391
+ TextConfig,
392
+ ImageConfig,
393
+ ButtonConfig,
394
+ } from '@delmaredigital/payload-puck/components'
395
+
396
+ export const puckConfig: Config = {
397
+ components: {
398
+ Section: SectionConfig,
399
+ Heading: HeadingConfig,
400
+ Text: TextConfig,
401
+ Image: ImageConfig,
402
+ Button: ButtonConfig,
403
+ },
404
+ categories: {
405
+ layout: { components: ['Section'] },
406
+ content: { components: ['Heading', 'Text', 'Image', 'Button'] },
407
+ },
408
+ }
409
+ ```
410
+
411
+ ### Using Field Factories
412
+
413
+ Build custom components with pre-built fields:
414
+
415
+ ```typescript
416
+ import type { ComponentConfig } from '@measured/puck'
417
+ import {
418
+ createMediaField,
419
+ createBackgroundField,
420
+ createPaddingField,
421
+ backgroundValueToCSS,
422
+ paddingValueToCSS,
423
+ } from '@delmaredigital/payload-puck/fields'
424
+
425
+ export const HeroConfig: ComponentConfig = {
426
+ label: 'Hero',
427
+ fields: {
428
+ image: createMediaField({ label: 'Background Image' }),
429
+ overlay: createBackgroundField({ label: 'Overlay' }),
430
+ padding: createPaddingField({ label: 'Padding' }),
431
+ },
432
+ defaultProps: {
433
+ image: null,
434
+ overlay: null,
435
+ padding: { top: 80, bottom: 80, left: 24, right: 24, unit: 'px', linked: false },
436
+ },
437
+ render: ({ image, overlay, padding }) => (
438
+ <section
439
+ style={{
440
+ background: backgroundValueToCSS(overlay),
441
+ padding: paddingValueToCSS(padding),
442
+ }}
443
+ >
444
+ {/* Hero content */}
445
+ </section>
446
+ ),
447
+ }
448
+ ```
449
+
450
+ ### Server vs Editor Variants
451
+
452
+ For `PageRenderer` (frontend), components need server-safe configs without React hooks:
453
+
454
+ ```typescript
455
+ // Import server variants for PageRenderer
456
+ import {
457
+ SectionServerConfig,
458
+ HeadingServerConfig,
459
+ TextServerConfig,
460
+ } from '@delmaredigital/payload-puck/components'
461
+
462
+ <PageRenderer config={{ components: { Section: SectionServerConfig, ... } }} data={page.puckData} />
463
+ ```
464
+
465
+ For custom components, create two files:
466
+ - `MyComponent.tsx` - Full editor version with fields and interactivity
467
+ - `MyComponent.server.tsx` - Server-safe version (no hooks, no 'use client')
468
+
469
+ ### Extending Built-in Configs
470
+
471
+ Use `extendConfig()` to add custom components:
472
+
473
+ ```typescript
474
+ import { extendConfig, fullConfig } from '@delmaredigital/payload-puck/config/editor'
475
+ import { HeroConfig } from './components/Hero'
476
+
477
+ export const puckConfig = extendConfig({
478
+ base: fullConfig,
479
+ components: {
480
+ Hero: HeroConfig,
481
+ },
482
+ categories: {
483
+ custom: { title: 'Custom', components: ['Hero'] },
484
+ },
485
+ })
486
+ ```
487
+
488
+ > **Note:** Use `fullConfig` from `/config/editor` for extending the editor. For server-side rendering, use `baseConfig` from `/config`.
489
+
490
+ ### Available Field Factories
491
+
492
+ | Factory | Description |
493
+ |---------|-------------|
494
+ | `createMediaField()` | Payload media library picker |
495
+ | `createBackgroundField()` | Solid, gradient, or image backgrounds |
496
+ | `createColorPickerField()` | Color picker with opacity |
497
+ | `createPaddingField()` | Visual padding editor |
498
+ | `createMarginField()` | Visual margin editor |
499
+ | `createBorderField()` | Border styling |
500
+ | `createDimensionsField()` | Width/height constraints |
501
+ | `createAnimationField()` | Entrance animations |
502
+ | `createAlignmentField()` | Text alignment |
503
+ | `createTiptapField()` | Inline rich text editor |
504
+
505
+ ### CSS Helper Functions
506
+
507
+ Convert field values to CSS:
508
+
509
+ ```typescript
510
+ import {
511
+ backgroundValueToCSS,
512
+ paddingValueToCSS,
513
+ marginValueToCSS,
514
+ borderValueToCSS,
515
+ dimensionsValueToCSS,
516
+ colorValueToCSS,
517
+ } from '@delmaredigital/payload-puck/fields'
518
+
519
+ const style = {
520
+ background: backgroundValueToCSS(props.background),
521
+ padding: paddingValueToCSS(props.padding),
522
+ ...dimensionsValueToCSS(props.dimensions),
523
+ }
524
+ ```
525
+
526
+ ---
527
+
372
528
  ## Theming
373
529
 
374
530
  Customize button styles, color presets, and focus rings:
@@ -392,6 +548,18 @@ import { ThemeProvider } from '@delmaredigital/payload-puck/theme'
392
548
  </ThemeProvider>
393
549
  ```
394
550
 
551
+ Access theme values in custom components with `useTheme()`:
552
+
553
+ ```typescript
554
+ import { useTheme } from '@delmaredigital/payload-puck/theme'
555
+
556
+ function CustomButton({ variant }) {
557
+ const theme = useTheme()
558
+ const classes = theme.buttonVariants[variant]?.classes
559
+ return <button className={classes}>...</button>
560
+ }
561
+ ```
562
+
395
563
  ---
396
564
 
397
565
  ## Layouts
@@ -585,36 +753,17 @@ createPuckPlugin({
585
753
 
586
754
  ### Custom API Routes (Advanced)
587
755
 
588
- If you need custom API route handling beyond the built-in endpoints, you can disable automatic endpoints and create your own:
756
+ The built-in endpoints handle most use cases. Only disable them if you need custom authentication or middleware.
589
757
 
590
- ```typescript
591
- // payload.config.ts
592
- createPuckPlugin({
593
- enableEndpoints: false, // Disable built-in endpoints
594
- })
595
- ```
758
+ If needed, three route factories are available:
596
759
 
597
- Then create custom routes using the provided factories:
760
+ | Factory | Route Pattern | Methods |
761
+ |---------|---------------|---------|
762
+ | `createPuckApiRoutes` | `/api/puck/[collection]` | GET (list), POST (create) |
763
+ | `createPuckApiRoutesWithId` | `/api/puck/[collection]/[id]` | GET, PATCH, DELETE |
764
+ | `createPuckApiRoutesVersions` | `/api/puck/[collection]/[id]/versions` | GET, POST (restore) |
598
765
 
599
- ```typescript
600
- // app/api/puck/[collection]/route.ts
601
- import { createPuckApiRoutes } from '@delmaredigital/payload-puck/api'
602
- import { getPayload } from 'payload'
603
- import config from '@payload-config'
604
- import { headers } from 'next/headers'
605
-
606
- export const { GET, POST } = createPuckApiRoutes({
607
- payloadConfig: config,
608
- auth: {
609
- authenticate: async (request) => {
610
- const payload = await getPayload({ config })
611
- const { user } = await payload.auth({ headers: await headers() })
612
- if (!user) return { authenticated: false }
613
- return { authenticated: true, user: { id: user.id } }
614
- },
615
- },
616
- })
617
- ```
766
+ See the JSDoc in `@delmaredigital/payload-puck/api` for usage examples.
618
767
 
619
768
  ---
620
769
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delmaredigital/payload-puck",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Puck visual page builder plugin for Payload CMS",
5
5
  "type": "module",
6
6
  "license": "MIT",