-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lexical): support lexical rich text (#140)
* feat(lexical): support lexical rich text * style(*): cleanup
- Loading branch information
1 parent
9ebaf89
commit 4921e4d
Showing
13 changed files
with
1,549 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { CollectionConfig } from "payload/types"; | ||
import { lexicalEditorWithBlocks } from "./fields/lexicalEditorWithBlocks"; | ||
|
||
const Policies: CollectionConfig = { | ||
slug: "policies", | ||
admin: { | ||
defaultColumns: ["title", "author", "category", "tags", "status"], | ||
useAsTitle: "title", | ||
}, | ||
access: { | ||
read: () => true, | ||
}, | ||
fields: [ | ||
{ | ||
name: "title", | ||
type: "text", | ||
localized: true, | ||
}, | ||
lexicalEditorWithBlocks, | ||
] | ||
} | ||
|
||
export default Policies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { RichTextField } from 'payload/types'; | ||
import { BlocksFeature, BoldTextFeature, lexicalEditor, LinkFeature, SlateToLexicalFeature } from '@payloadcms/richtext-lexical' | ||
|
||
export const lexicalEditorWithBlocks: RichTextField = { | ||
name: 'content', | ||
type: 'richText', | ||
localized: true, | ||
editor: lexicalEditor({ | ||
features: ({ defaultFeatures }) => [ | ||
...defaultFeatures, | ||
SlateToLexicalFeature(), | ||
BlocksFeature({ | ||
blocks: [ | ||
{ | ||
slug: 'highlight', | ||
imageAltText: 'Text', | ||
fields: [ | ||
{ | ||
name: "heading", | ||
type: "group", | ||
fields: [ | ||
{ | ||
name: 'title', | ||
type: 'text', | ||
localized: true, | ||
}, | ||
{ | ||
name: 'preTitle', | ||
type: 'text', | ||
localized: true, | ||
}, | ||
] | ||
}, | ||
{ | ||
name: "color", | ||
type: "select", | ||
options: [ | ||
'gray', | ||
'yellow', | ||
'green' | ||
], | ||
admin: { | ||
isClearable: true, | ||
}, | ||
}, | ||
{ | ||
name: 'content', | ||
type: 'richText', | ||
localized: false, | ||
editor: lexicalEditor({ | ||
features: () => [ | ||
BoldTextFeature(), | ||
LinkFeature({}), | ||
] | ||
}), | ||
}, | ||
] | ||
} | ||
], | ||
}) | ||
], | ||
}), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
236 changes: 236 additions & 0 deletions
236
dev/src/lib/tests/fields/lexical-editor-with-blocks.fixture.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,236 @@ | ||
import { Policy } from "../../payload-types" | ||
|
||
export const fixture = { | ||
"root": { | ||
"type": "root", | ||
"format": "", | ||
"indent": 0, | ||
"version": 1, | ||
"children": [ | ||
{ | ||
"children": [ | ||
{ | ||
"detail": 0, | ||
"format": 0, | ||
"mode": "normal", | ||
"style": "", | ||
"text": "Lexical editor content", | ||
"type": "text", | ||
"version": 1 | ||
} | ||
], | ||
"direction": "ltr", | ||
"format": "", | ||
"indent": 0, | ||
"type": "heading", | ||
"version": 1, | ||
"tag": "h2" | ||
}, | ||
{ | ||
"children": [ | ||
{ | ||
"detail": 0, | ||
"format": 0, | ||
"mode": "normal", | ||
"style": "", | ||
"text": "This is editable ", | ||
"type": "text", | ||
"version": 1 | ||
}, | ||
{ | ||
"detail": 0, | ||
"format": 1, | ||
"mode": "normal", | ||
"style": "", | ||
"text": "rich", | ||
"type": "text", | ||
"version": 1 | ||
}, | ||
{ | ||
"detail": 0, | ||
"format": 0, | ||
"mode": "normal", | ||
"style": "", | ||
"text": " text, ", | ||
"type": "text", | ||
"version": 1 | ||
}, | ||
{ | ||
"detail": 0, | ||
"format": 2, | ||
"mode": "normal", | ||
"style": "", | ||
"text": "much", | ||
"type": "text", | ||
"version": 1 | ||
}, | ||
{ | ||
"detail": 0, | ||
"format": 0, | ||
"mode": "normal", | ||
"style": "", | ||
"text": " better than a ", | ||
"type": "text", | ||
"version": 1 | ||
}, | ||
{ | ||
"detail": 0, | ||
"format": 16, | ||
"mode": "normal", | ||
"style": "", | ||
"text": "<textarea>", | ||
"type": "text", | ||
"version": 1 | ||
}, | ||
{ | ||
"detail": 0, | ||
"format": 0, | ||
"mode": "normal", | ||
"style": "", | ||
"text": "!", | ||
"type": "text", | ||
"version": 1 | ||
} | ||
], | ||
"direction": "ltr", | ||
"format": "", | ||
"indent": 0, | ||
"type": "paragraph", | ||
"version": 1 | ||
}, | ||
{ | ||
"children": [ | ||
{ | ||
"detail": 0, | ||
"format": 0, | ||
"mode": "normal", | ||
"style": "", | ||
"text": "Since it's rich text, you can do things like turn a selection of text ", | ||
"type": "text", | ||
"version": 1 | ||
}, | ||
{ | ||
"detail": 0, | ||
"format": 1, | ||
"mode": "normal", | ||
"style": "", | ||
"text": "bold", | ||
"type": "text", | ||
"version": 1 | ||
}, | ||
{ | ||
"detail": 0, | ||
"format": 0, | ||
"mode": "normal", | ||
"style": "", | ||
"text": ", or add a semantically rendered block quote in the middle of the page, like this:", | ||
"type": "text", | ||
"version": 1 | ||
} | ||
], | ||
"direction": "ltr", | ||
"format": "", | ||
"indent": 0, | ||
"type": "paragraph", | ||
"version": 1 | ||
}, | ||
{ | ||
"children": [ | ||
{ | ||
"detail": 0, | ||
"format": 0, | ||
"mode": "normal", | ||
"style": "", | ||
"text": "A wise quote.", | ||
"type": "text", | ||
"version": 1 | ||
} | ||
], | ||
"direction": "ltr", | ||
"format": "", | ||
"indent": 0, | ||
"type": "quote", | ||
"version": 1 | ||
}, | ||
{ | ||
"children": [ | ||
{ | ||
"detail": 0, | ||
"format": 0, | ||
"mode": "normal", | ||
"style": "", | ||
"text": "Try it out for yourself!", | ||
"type": "text", | ||
"version": 1 | ||
} | ||
], | ||
"direction": "ltr", | ||
"format": "center", | ||
"indent": 0, | ||
"type": "paragraph", | ||
"version": 1 | ||
}, | ||
{ | ||
"children": [], | ||
"direction": null, | ||
"format": "", | ||
"indent": 0, | ||
"type": "paragraph", | ||
"version": 1 | ||
}, | ||
{ | ||
"format": "", | ||
"type": "block", | ||
"version": 2, | ||
"fields": { | ||
"id": "6582d48f2037fb3ca72ed2cf", | ||
"blockName": "", | ||
"blockType": "highlight", | ||
"color": "gray", | ||
"content": { | ||
"root": { | ||
"type": "root", | ||
"format": "", | ||
"indent": 0, | ||
"version": 1, | ||
"children": [ | ||
{ | ||
"children": [ | ||
{ | ||
"detail": 0, | ||
"format": 0, | ||
"mode": "normal", | ||
"style": "", | ||
"text": "More lexical content inside a custom block.", | ||
"type": "text", | ||
"version": 1 | ||
} | ||
], | ||
"direction": "ltr", | ||
"format": "", | ||
"indent": 0, | ||
"type": "paragraph", | ||
"version": 1 | ||
} | ||
], | ||
"direction": "ltr" | ||
} | ||
}, | ||
"heading": { | ||
"title": "Highlight", | ||
"preTitle": "Custom block" | ||
} | ||
} | ||
}, | ||
{ | ||
"children": [], | ||
"direction": null, | ||
"format": "", | ||
"indent": 0, | ||
"type": "paragraph", | ||
"version": 1 | ||
} | ||
], | ||
"direction": "ltr" | ||
} | ||
} as Policy['content'] |
Oops, something went wrong.