File tree Expand file tree Collapse file tree 6 files changed +105
-4
lines changed
richtext-lexical/src/field
ui/src/utilities/buildClientFieldSchemaMap Expand file tree Collapse file tree 6 files changed +105
-4
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,10 @@ export const RscEntryLexicalField: React.FC<
30
30
const path = args . path ?? ( args . clientField as RichTextFieldClient ) . name
31
31
const schemaPath = args . schemaPath ?? path
32
32
33
+ if ( ! ( args ?. clientField as RichTextFieldClient ) ?. name ) {
34
+ throw new Error ( 'Initialized lexical RSC field without a field name' )
35
+ }
36
+
33
37
const { clientFeatures, featureClientSchemaMap } = initLexicalFeatures ( {
34
38
clientFieldSchemaMap : args . clientFieldSchemaMap ,
35
39
fieldSchemaMap : args . fieldSchemaMap ,
Original file line number Diff line number Diff line change 5
5
type ClientField ,
6
6
type ClientFieldSchemaMap ,
7
7
createClientFields ,
8
+ type Field ,
8
9
type FieldSchemaMap ,
9
10
type Payload ,
10
11
} from 'payload'
@@ -108,16 +109,25 @@ export const traverseFields = ({
108
109
109
110
// Now loop through them, convert each entry to a client field and add it to the client schema map
110
111
for ( const [ path , subField ] of richTextFieldSchemaMap . entries ( ) ) {
112
+ // check if fields is the only key in the subField object
113
+ const isFieldsOnly = Object . keys ( subField ) . length === 1 && 'fields' in subField
114
+
111
115
const clientFields = createClientFields ( {
112
116
defaultIDType : payload . config . db . defaultIDType ,
113
117
disableAddingID : true ,
114
- fields : 'fields' in subField ? subField . fields : [ subField ] ,
118
+ fields : isFieldsOnly ? subField . fields : [ subField as Field ] ,
115
119
i18n,
116
120
importMap : payload . importMap ,
117
121
} )
118
- clientSchemaMap . set ( path , {
119
- fields : clientFields ,
120
- } )
122
+
123
+ clientSchemaMap . set (
124
+ path ,
125
+ isFieldsOnly
126
+ ? {
127
+ fields : clientFields ,
128
+ }
129
+ : clientFields [ 0 ] ,
130
+ )
121
131
}
122
132
break
123
133
}
Original file line number Diff line number Diff line change @@ -1174,5 +1174,25 @@ describe('lexicalBlocks', () => {
1174
1174
expect ( height2 ) . toBe ( 74 )
1175
1175
} ) . toPass ( )
1176
1176
} )
1177
+
1178
+ test ( 'ensure nested lexical field displays field label and description' , async ( ) => {
1179
+ // Previously, we had the issue that nested lexical fields did not display the field label and description, as
1180
+ // their client field configs were generated incorrectly on the server.
1181
+ await page . goto ( 'http://localhost:3000/admin/collections/LexicalInBlock?limit=10' )
1182
+ await page . locator ( '.cell-id a' ) . first ( ) . click ( )
1183
+ await page . waitForURL ( `**/collections/LexicalInBlock/**` )
1184
+
1185
+ await expect (
1186
+ page . locator ( '.lexical-block-blockInLexical .render-fields label.field-label' ) ,
1187
+ ) . toHaveText ( 'My Label*' )
1188
+ await expect (
1189
+ page . locator ( '.lexical-block-blockInLexical .render-fields .required' ) ,
1190
+ ) . toHaveText ( '*' )
1191
+ await expect (
1192
+ page . locator (
1193
+ '.lexical-block-blockInLexical .render-fields .field-description-lexicalInBlock' ,
1194
+ ) ,
1195
+ ) . toHaveText ( 'Some Description' )
1196
+ } )
1177
1197
} )
1178
1198
} )
Original file line number Diff line number Diff line change 1
1
import type { CollectionConfig } from 'payload'
2
2
3
+ import { BlocksFeature , lexicalEditor } from '@payloadcms/richtext-lexical'
4
+
3
5
export const LexicalInBlock : CollectionConfig = {
4
6
slug : 'LexicalInBlock' ,
5
7
fields : [
8
+ {
9
+ name : 'content' ,
10
+ type : 'richText' ,
11
+ editor : lexicalEditor ( {
12
+ features : [
13
+ BlocksFeature ( {
14
+ blocks : [
15
+ {
16
+ slug : 'blockInLexical' ,
17
+ fields : [
18
+ {
19
+ name : 'lexicalInBlock' ,
20
+ label : 'My Label' ,
21
+ type : 'richText' ,
22
+ required : true ,
23
+ editor : lexicalEditor ( ) ,
24
+ admin : {
25
+ description : 'Some Description' ,
26
+ } ,
27
+ } ,
28
+ ] ,
29
+ } ,
30
+ ] ,
31
+ } ) ,
32
+ ] ,
33
+ } ) ,
34
+ } ,
6
35
{
7
36
name : 'blocks' ,
8
37
type : 'blocks' ,
Original file line number Diff line number Diff line change @@ -412,6 +412,21 @@ export interface User {
412
412
*/
413
413
export interface LexicalInBlock {
414
414
id : string ;
415
+ content ?: {
416
+ root : {
417
+ type : string ;
418
+ children : {
419
+ type : string ;
420
+ version : number ;
421
+ [ k : string ] : unknown ;
422
+ } [ ] ;
423
+ direction : ( 'ltr' | 'rtl' ) | null ;
424
+ format : 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | '' ;
425
+ indent : number ;
426
+ version : number ;
427
+ } ;
428
+ [ k : string ] : unknown ;
429
+ } | null ;
415
430
blocks ?:
416
431
| {
417
432
lexical ?: {
@@ -2041,6 +2056,7 @@ export interface UsersSelect<T extends boolean = true> {
2041
2056
* via the `definition` "LexicalInBlock_select".
2042
2057
*/
2043
2058
export interface LexicalInBlockSelect < T extends boolean = true > {
2059
+ content ?: T ;
2044
2060
blocks ?:
2045
2061
| T
2046
2062
| {
Original file line number Diff line number Diff line change @@ -481,6 +481,28 @@ export const seed = async (_payload: Payload) => {
481
481
await _payload . create ( {
482
482
collection : 'LexicalInBlock' ,
483
483
data : {
484
+ content : {
485
+ root : {
486
+ children : [
487
+ {
488
+ format : '' ,
489
+ type : 'block' ,
490
+ version : 2 ,
491
+ fields : {
492
+ id : '6773773284be8978db7a498d' ,
493
+ lexicalInBlock : textToLexicalJSON ( { text : 'text' } ) ,
494
+ blockName : '' ,
495
+ blockType : 'blockInLexical' ,
496
+ } ,
497
+ } ,
498
+ ] ,
499
+ direction : null ,
500
+ format : '' ,
501
+ indent : 0 ,
502
+ type : 'root' ,
503
+ version : 1 ,
504
+ } ,
505
+ } ,
484
506
blocks : [
485
507
{
486
508
blockType : 'lexicalInBlock2' ,
You can’t perform that action at this time.
0 commit comments