Skip to content

Commit 09db987

Browse files
committed
wip rich text floated images
1 parent 74ca4f1 commit 09db987

6 files changed

Lines changed: 146 additions & 68 deletions

File tree

1.38 MB
Loading

backend/public/images/values.png

3.87 MB
Loading

backend/src/app/(payload)/admin/importMap.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/src/collections/Pages.ts

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,29 @@
1-
import type { CollectionConfig } from 'payload'
1+
import type { Block, CollectionConfig } from 'payload'
22
import { title } from 'process'
33
import { text } from 'stream/consumers'
44

55
const regex = /\s/
66

7-
export const Pages: CollectionConfig = {
8-
slug: 'pages',
9-
access: {
10-
read: () => true,
11-
},
7+
const TextBlock: Block = {
8+
slug: 'Text editor',
9+
imageURL: '/images/textblock.png',
10+
imageAltText: 'A screenshot of what text in a text editor can look like on the website.',
1211
fields: [
1312
{
14-
name: 'title',
15-
type: 'text',
16-
required: true,
17-
unique: true,
18-
},
19-
{
20-
name: 'subtitle',
21-
type: 'text',
22-
required: true,
23-
unique: true,
24-
},
25-
{
26-
name: 'url',
27-
type: 'text',
28-
required: true,
29-
unique: true,
30-
admin: {
31-
description: "The URL, or slug, of this page. For instance, 'title' or 'page-title'. May not contain whitespace."
32-
},
33-
// TODO add validation
34-
},
35-
{
36-
name: 'history',
37-
label: 'Our History',
13+
name: 'text',
3814
type: 'richText',
15+
required: true,
3916
},
40-
{
41-
name: 'mission',
42-
label: 'Our Mission',
43-
type: 'textarea'
44-
},
17+
],
18+
}
19+
20+
const ValuesBlock: Block = {
21+
slug: 'Values section',
22+
imageURL: '/images/values.png',
23+
imageAltText: 'A screenshot of what the values section can look like on the website.',
24+
fields: [
4525
{
4626
name: 'values',
47-
label: 'Our Values',
4827
type: 'array',
4928
admin: {
5029
components: {
@@ -70,6 +49,46 @@ export const Pages: CollectionConfig = {
7049
},
7150
]
7251
},
52+
]
53+
}
54+
55+
export const Pages: CollectionConfig = {
56+
slug: 'pages',
57+
access: {
58+
read: () => true,
59+
},
60+
fields: [
61+
{
62+
name: 'title',
63+
type: 'text',
64+
required: true,
65+
unique: true,
66+
},
67+
{
68+
name: 'subtitle',
69+
type: 'text',
70+
required: true,
71+
unique: true,
72+
},
73+
{
74+
name: 'url',
75+
type: 'text',
76+
required: true,
77+
unique: true,
78+
admin: {
79+
description: "The URL, or slug, of this page. For instance, 'title' or 'page-title'. May not contain whitespace."
80+
},
81+
// TODO add validation
82+
},
83+
{
84+
name: 'sections',
85+
type: 'blocks',
86+
blocks: [
87+
TextBlock,
88+
ValuesBlock,
89+
],
90+
},
91+
7392

7493
],
7594
}

backend/src/payload-types.ts

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -180,29 +180,42 @@ export interface Page {
180180
* The URL, or slug, of this page. For instance, 'title' or 'page-title'. May not contain whitespace.
181181
*/
182182
url: string;
183-
history?: {
184-
root: {
185-
type: string;
186-
children: {
187-
type: any;
188-
version: number;
189-
[k: string]: unknown;
190-
}[];
191-
direction: ('ltr' | 'rtl') | null;
192-
format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | '';
193-
indent: number;
194-
version: number;
195-
};
196-
[k: string]: unknown;
197-
} | null;
198-
mission?: string | null;
199-
values?:
200-
| {
201-
title: string;
202-
description: string;
203-
image: number | Media;
204-
id?: string | null;
205-
}[]
183+
sections?:
184+
| (
185+
| {
186+
text: {
187+
root: {
188+
type: string;
189+
children: {
190+
type: any;
191+
version: number;
192+
[k: string]: unknown;
193+
}[];
194+
direction: ('ltr' | 'rtl') | null;
195+
format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | '';
196+
indent: number;
197+
version: number;
198+
};
199+
[k: string]: unknown;
200+
};
201+
id?: string | null;
202+
blockName?: string | null;
203+
blockType: 'Text editor';
204+
}
205+
| {
206+
values?:
207+
| {
208+
title: string;
209+
description: string;
210+
image: number | Media;
211+
id?: string | null;
212+
}[]
213+
| null;
214+
id?: string | null;
215+
blockName?: string | null;
216+
blockType: 'Values section';
217+
}
218+
)[]
206219
| null;
207220
updatedAt: string;
208221
createdAt: string;
@@ -333,15 +346,30 @@ export interface PagesSelect<T extends boolean = true> {
333346
title?: T;
334347
subtitle?: T;
335348
url?: T;
336-
history?: T;
337-
mission?: T;
338-
values?:
349+
sections?:
339350
| T
340351
| {
341-
title?: T;
342-
description?: T;
343-
image?: T;
344-
id?: T;
352+
'Text editor'?:
353+
| T
354+
| {
355+
text?: T;
356+
id?: T;
357+
blockName?: T;
358+
};
359+
'Values section'?:
360+
| T
361+
| {
362+
values?:
363+
| T
364+
| {
365+
title?: T;
366+
description?: T;
367+
image?: T;
368+
id?: T;
369+
};
370+
id?: T;
371+
blockName?: T;
372+
};
345373
};
346374
updatedAt?: T;
347375
createdAt?: T;

backend/src/payload.config.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { postgresAdapter } from '@payloadcms/db-postgres'
2-
import { lexicalEditor } from '@payloadcms/richtext-lexical'
2+
import { lexicalEditor, BlocksFeature } from '@payloadcms/richtext-lexical'
33
import path from 'path'
44
import { buildConfig } from 'payload'
55
import { fileURLToPath } from 'url'
@@ -36,7 +36,36 @@ export default buildConfig({
3636
},
3737
globals: [Homepage, Nav, Team],
3838
collections: [Users, Media, Pages],
39-
editor: lexicalEditor(),
39+
editor: lexicalEditor({
40+
features: ({defaultFeatures}) => [
41+
...defaultFeatures,
42+
BlocksFeature({
43+
blocks: [
44+
{
45+
slug: 'floatImage',
46+
fields: [
47+
{
48+
name: 'image',
49+
type: 'upload',
50+
relationTo: 'media',
51+
required: true,
52+
},
53+
{
54+
name: 'float',
55+
type: 'select',
56+
options: [
57+
'Center',
58+
'Left',
59+
'Right',
60+
],
61+
defaultValue: 'Left',
62+
}
63+
]
64+
}
65+
]
66+
})
67+
]
68+
}),
4069
secret: process.env.PAYLOAD_SECRET || '',
4170
typescript: {
4271
outputFile: path.resolve(dirname, 'payload-types.ts'),

0 commit comments

Comments
 (0)