@nextbridgehq/payload-block-builder 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 NEXTBRIDGE LIMITED
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # Payload Block Builder
2
+
3
+
4
+ A visual block builder plugin for Payload v3. Design your content blocks through a drag-and-drop UI, store the schemas in your database, and let editors build pages without waiting on a developer every time something needs to change.
5
+
6
+ ## Use cases
7
+
8
+ - **Dynamic landing pages:** Let editors compose pages from a library of blocks (hero, features, testimonials, CTA) without any code changes.
9
+ - **Multi-tenant platforms:** Each tenant can have its own block definitions without touching shared config or triggering redeployments.
10
+ - **Marketing teams:** Give marketing full control to create, update, and reorder blocks on any page, any time.
11
+ - **Evolving content schemas:** Roll out new block versions without breaking content that was built against older ones.
12
+ - **Headless frontends:** Fetch structured block data from the Payload API and render it with any framework.
13
+
14
+ ## Quick start
15
+
16
+ 1. Install the plugin:
17
+
18
+ ```bash
19
+ npm install @nextbridgehq/payload-block-builder
20
+ ```
21
+
22
+ 2. Add the plugin to your `payload.config.ts`:
23
+
24
+ ```ts
25
+ import { dynamicBlocksPlugin } from '@nextbridgehq/payload-block-builder'
26
+
27
+ export default buildConfig({
28
+ plugins: [
29
+ dynamicBlocksPlugin({
30
+ collections: ['pages', 'posts'],
31
+ }),
32
+ ],
33
+ })
34
+ ```
35
+
36
+ 3. Create a page in your Next.js app to host the builder UI:
37
+
38
+ ```tsx
39
+ // app/block-builder/page.tsx
40
+ import { BuilderShell } from '@nextbridgehq/payload-block-builder/client'
41
+ import '@nextbridgehq/payload-block-builder/builder.css'
42
+
43
+ export default function BlockBuilderPage() {
44
+ return <BuilderShell />
45
+ }
46
+ ```
47
+
48
+ 4. If you're on a SQL database, run the migration:
49
+
50
+ ```bash
51
+ npx payload migrate:create
52
+ npx payload migrate:run
53
+ ```
54
+
55
+ MongoDB users can skip this step.
56
+
57
+ Visit `/block-builder` in your browser and you're in.
58
+
59
+ ## Usage
60
+
61
+ ### Creating a block
62
+
63
+ 1. Open `/block-builder` in your browser.
64
+ 2. Click "Add Block" and give it a name and slug.
65
+ 3. Drag fields from the panel on the right onto the canvas.
66
+ 4. Configure each field (label, name, required, options, etc.).
67
+ 5. Hit Publish. The block is saved to your database and a version snapshot is created.
68
+
69
+ ### Using blocks in a collection
70
+
71
+ Any collection you listed in `collections` gets a new "DB Layout" tab in the Payload admin. Editors can:
72
+
73
+ 1. Click "Add Row" to add a block.
74
+ 2. Select a block definition and the version of its schema to use.
75
+ 3. Fill in the fields. They render dynamically based on the selected schema.
76
+ 4. Reorder, hide, or add anchor IDs to individual blocks.
77
+ 5. Save the document as normal.
78
+
79
+ ### Reading block data on the frontend
80
+
81
+ ```ts
82
+ const res = await fetch('/api/pages/my-page?depth=2')
83
+ const page = await res.json()
84
+
85
+ for (const block of page.dbLayout) {
86
+ const type = block.blockDefinition.slug // e.g. "hero"
87
+ const fields = block.data // { heading: '...', image: '...', ... }
88
+ const isHidden = block.hidden
89
+ }
90
+ ```
91
+
92
+ From there it's just a switch or a component map. Render each block type however you like.
93
+
94
+ ## Options
95
+
96
+ ```ts
97
+ dynamicBlocksPlugin({
98
+ enabled?: boolean // disable without removing. Default: true
99
+ collections?: string[] // which collection slugs get the DB Layout tab. Default: []
100
+ fieldName?: string // name of the layout array field. Default: 'dbLayout'
101
+ tabLabel?: string // label shown on the tab in the admin. Default: 'DB Layout'
102
+ })
103
+ ```
104
+
105
+ ## How it works
106
+
107
+ - **Block definitions** are stored in a `block-definitions` collection. Each document is a named block type with a slug, labels, and a list of field definitions.
108
+ - **Versions** are stored in a `block-definition-versions` collection. Every time you publish a block in the builder, a snapshot of its current schema is saved as a new version.
109
+ - **Documents** in your opted-in collections store a reference to the exact block version they were built against, so updating a block's schema later won't break existing content.
110
+ - **The DB Layout tab** is injected automatically on each collection you list. It renders a dynamic array field where editors pick a block and version, and the field data UI adjusts to match the selected schema.
111
+ - **Four internal API endpoints** power the builder UI and the `BlockDataField` admin component. You don't need to call them yourself.
112
+
113
+ ## Requirements
114
+
115
+ - Payload v3
116
+ - Next.js 14+
117
+ - Any Payload-supported database (PostgreSQL, MongoDB, SQLite)