Skip to content

Commit d1bbc3d

Browse files
committed
fix: required but undefined richtexts lexical check
1 parent 0be2434 commit d1bbc3d

File tree

10 files changed

+2075
-1792
lines changed

10 files changed

+2075
-1792
lines changed

example/cms/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@payloadcms/bundler-webpack": "^1.0.5",
1919
"@payloadcms/db-mongodb": "^1.0.5",
2020
"@payloadcms/richtext-lexical": "^0.1.16",
21+
"@payloadcms/richtext-slate": "^1.0.0",
2122
"dotenv": "^16.3.1",
2223
"express": "^4.17.1"
2324
},

example/cms/src/collections/Posts.ts

+20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { CollectionConfig } from "payload/types";
22
import { Categories } from "./Categories";
33
import { Tags } from "./Tags";
4+
import { slateEditor } from "@payloadcms/richtext-slate";
45

56
export const Posts: CollectionConfig = {
67
slug: "posts",
@@ -54,6 +55,25 @@ export const Posts: CollectionConfig = {
5455
],
5556
defaultValue: 'draft',
5657
},
58+
{
59+
name: "checkParagraph",
60+
type: "checkbox",
61+
defaultValue: false,
62+
},
63+
{
64+
name: 'paragraph',
65+
type: 'richText',
66+
required: true,
67+
editor: slateEditor({
68+
admin: {
69+
elements: ['h2', 'h3'],
70+
leaves: ["italic", "underline", "bold"],
71+
}
72+
}),
73+
admin: {
74+
condition: (data, siblingData, { user }) => siblingData.checkParagraph,
75+
},
76+
},
5777
],
5878
},
5979
],

example/cms/src/payload.config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { webpackBundler } from "@payloadcms/bundler-webpack";
22
import { mongooseAdapter } from "@payloadcms/db-mongodb";
33
import { lexicalEditor } from "@payloadcms/richtext-lexical";
4+
import { slateEditor } from '@payloadcms/richtext-slate';
45
import path from "path";
56
import { buildConfig } from "payload/config";
67
import { visualEditor } from "../../../src";
@@ -51,7 +52,7 @@ export default buildConfig({
5152
db: mongooseAdapter({
5253
url: process.env.MONGODB_URI!,
5354
}),
54-
editor: lexicalEditor({}),
55+
editor: slateEditor({}),
5556
typescript: {
5657
outputFile: path.resolve(__dirname, "types/payload-types.ts"),
5758
},

example/cms/src/server.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ app.get("/", (_, res) => {
1111

1212
// Initialize Payload
1313
payload.init({
14-
secret: process.env.PAYLOAD_SECRET,
15-
mongoURL: process.env.MONGODB_URI,
14+
secret: process.env.PAYLOAD_SECRET || 'SECRET',
1615
express: app,
1716
onInit: () => {
1817
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`)

example/cms/src/types/payload-types.ts

+38
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export interface Config {
2020
kitchenSink: KitchenSink;
2121
};
2222
}
23+
/**
24+
* This interface was referenced by `Config`'s JSON-Schema
25+
* via the `definition` "users".
26+
*/
2327
export interface User {
2428
id: string;
2529
updatedAt: string;
@@ -33,6 +37,10 @@ export interface User {
3337
lockUntil?: string | null;
3438
password: string | null;
3539
}
40+
/**
41+
* This interface was referenced by `Config`'s JSON-Schema
42+
* via the `definition` "posts".
43+
*/
3644
export interface Post {
3745
id: string;
3846
title: string;
@@ -51,23 +59,41 @@ export interface Post {
5159
)[]
5260
| null;
5361
status?: ('draft' | 'published') | null;
62+
checkParagraph?: boolean | null;
63+
paragraph?:
64+
| {
65+
[k: string]: unknown;
66+
}[]
67+
| null;
5468
description?: string | null;
5569
updatedAt: string;
5670
createdAt: string;
5771
_status?: ('draft' | 'published') | null;
5872
}
73+
/**
74+
* This interface was referenced by `Config`'s JSON-Schema
75+
* via the `definition` "categories".
76+
*/
5977
export interface Category {
6078
id: string;
6179
name: string;
6280
updatedAt: string;
6381
createdAt: string;
6482
}
83+
/**
84+
* This interface was referenced by `Config`'s JSON-Schema
85+
* via the `definition` "tags".
86+
*/
6587
export interface Tag {
6688
id: string;
6789
name: string;
6890
updatedAt: string;
6991
createdAt: string;
7092
}
93+
/**
94+
* This interface was referenced by `Config`'s JSON-Schema
95+
* via the `definition` "media".
96+
*/
7197
export interface Medium {
7298
id: string;
7399
updatedAt: string;
@@ -79,6 +105,10 @@ export interface Medium {
79105
width?: number | null;
80106
height?: number | null;
81107
}
108+
/**
109+
* This interface was referenced by `Config`'s JSON-Schema
110+
* via the `definition` "payload-preferences".
111+
*/
82112
export interface PayloadPreference {
83113
id: string;
84114
user: {
@@ -98,13 +128,21 @@ export interface PayloadPreference {
98128
updatedAt: string;
99129
createdAt: string;
100130
}
131+
/**
132+
* This interface was referenced by `Config`'s JSON-Schema
133+
* via the `definition` "payload-migrations".
134+
*/
101135
export interface PayloadMigration {
102136
id: string;
103137
name?: string | null;
104138
batch?: number | null;
105139
updatedAt: string;
106140
createdAt: string;
107141
}
142+
/**
143+
* This interface was referenced by `Config`'s JSON-Schema
144+
* via the `definition` "kitchenSink".
145+
*/
108146
export interface KitchenSink {
109147
id: string;
110148
array: {

0 commit comments

Comments
 (0)