Skip to content

Commit d4f1add

Browse files
feat(richtext-lexical): mdx support (#9160)
Supports bi-directional import/export between MDX <=> Lexical. JSX will be mapped to lexical blocks back and forth. This will allow editing our mdx docs in payload while keeping mdx as the source of truth --------- Co-authored-by: Germán Jabloñski <43938777+GermanJablo@users.noreply.github.com>
1 parent 324af8a commit d4f1add

File tree

79 files changed

+7547
-311
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+7547
-311
lines changed

docs/admin/overview.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ The following options are available:
177177

178178
<Banner type="success">
179179
<strong>Tip:</strong>
180-
You can easily add _new_ routes to the Admin Panel through [Custom Endpoints](../rest-api/overview#custom-endpoints) and [Custom Views](./views).
180+
You can easily add _new_ routes to the Admin Panel through [Custom Endpoints](../rest-api/overview#custom-endpoints) and [Custom Views](./views).
181181
</Banner>
182182

183183
#### Customizing Root-level Routes

docs/lexical/converters.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,7 @@ This has been taken from the [lexical serialization & deserialization docs](http
334334
Convert markdown content to the Lexical editor format with the following:
335335

336336
```ts
337-
import { $convertFromMarkdownString } from '@lexical/markdown'
338-
import { sanitizeServerEditorConfig } from '@payloadcms/richtext-lexical'
337+
import { sanitizeServerEditorConfig, $convertFromMarkdownString } from '@payloadcms/richtext-lexical'
339338

340339
const yourSanitizedEditorConfig = sanitizeServerEditorConfig(yourEditorConfig, payloadConfig) // <= your editor config & Payload Config here
341340
const markdown = `# Hello World`

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const rootParserOptions = {
2828
ecmaVersion: 'latest',
2929
projectService: {
3030
maximumDefaultProjectFileMatchCount_THIS_WILL_SLOW_DOWN_LINTING: 40,
31-
allowDefaultProject: ['scripts/*.ts', '*.js', '*.mjs', '*.spec.ts', '*.d.ts'],
31+
allowDefaultProject: ['scripts/*.ts', '*.js', '*.mjs', '*.d.ts'],
3232
},
3333
}
3434

packages/next/src/layouts/Root/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ let checkedDependencies = false
4040
export const RootLayout = async ({
4141
children,
4242
config: configPromise,
43+
importMap,
4344
serverFunction,
4445
}: {
4546
readonly children: React.ReactNode
@@ -136,6 +137,7 @@ export const RootLayout = async ({
136137
const clientConfig = await getClientConfig({
137138
config,
138139
i18n,
140+
importMap,
139141
})
140142

141143
return (

packages/next/src/utilities/getClientConfig.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import type { I18nClient } from '@payloadcms/translations'
2-
import type { ClientConfig, SanitizedConfig } from 'payload'
2+
import type { ClientConfig, ImportMap, SanitizedConfig } from 'payload'
33

44
import { createClientConfig } from 'payload'
55
import { cache } from 'react'
66

77
export const getClientConfig = cache(
8-
async (args: { config: SanitizedConfig; i18n: I18nClient }): Promise<ClientConfig> => {
9-
const { config, i18n } = args
8+
async (args: {
9+
config: SanitizedConfig
10+
i18n: I18nClient
11+
importMap: ImportMap
12+
}): Promise<ClientConfig> => {
13+
const { config, i18n, importMap } = args
1014

1115
const clientConfig = createClientConfig({
1216
config,
1317
i18n,
18+
importMap,
1419
})
1520

1621
return Promise.resolve(clientConfig)

packages/next/src/views/Document/handleServerFunction.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
Data,
55
DocumentPreferences,
66
FormState,
7+
ImportMap,
78
PayloadRequest,
89
SanitizedConfig,
910
VisibleEntities,
@@ -23,8 +24,9 @@ if (!cachedClientConfig) {
2324
export const getClientConfig = (args: {
2425
config: SanitizedConfig
2526
i18n: I18nClient
27+
importMap: ImportMap
2628
}): ClientConfig => {
27-
const { config, i18n } = args
29+
const { config, i18n, importMap } = args
2830

2931
if (cachedClientConfig && process.env.NODE_ENV !== 'development') {
3032
return cachedClientConfig
@@ -33,6 +35,7 @@ export const getClientConfig = (args: {
3335
cachedClientConfig = createClientConfig({
3436
config,
3537
i18n,
38+
importMap,
3639
})
3740

3841
return cachedClientConfig
@@ -112,6 +115,7 @@ export const renderDocumentHandler = async (args: {
112115
const clientConfig = getClientConfig({
113116
config,
114117
i18n,
118+
importMap: req.payload.importMap,
115119
})
116120

117121
let preferences: DocumentPreferences

packages/next/src/views/List/handleServerFunction.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { I18nClient } from '@payloadcms/translations'
22
import type { ListPreferences } from '@payloadcms/ui'
33
import type {
44
ClientConfig,
5+
ImportMap,
56
ListQuery,
67
PayloadRequest,
78
SanitizedConfig,
@@ -22,8 +23,9 @@ if (!cachedClientConfig) {
2223
export const getClientConfig = (args: {
2324
config: SanitizedConfig
2425
i18n: I18nClient
26+
importMap: ImportMap
2527
}): ClientConfig => {
26-
const { config, i18n } = args
28+
const { config, i18n, importMap } = args
2729

2830
if (cachedClientConfig && process.env.NODE_ENV !== 'development') {
2931
return cachedClientConfig
@@ -32,6 +34,7 @@ export const getClientConfig = (args: {
3234
cachedClientConfig = createClientConfig({
3335
config,
3436
i18n,
37+
importMap,
3538
})
3639

3740
return cachedClientConfig
@@ -114,6 +117,7 @@ export const renderListHandler = async (args: {
114117
const clientConfig = getClientConfig({
115118
config,
116119
i18n,
120+
importMap: payload.importMap,
117121
})
118122

119123
const preferencesKey = `${collectionSlug}-list`

packages/next/src/views/Root/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export const RootPage = async ({
124124
const clientConfig = await getClientConfig({
125125
config,
126126
i18n: initPageResult?.req.i18n,
127+
importMap,
127128
})
128129

129130
const RenderedView = (
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { PayloadComponent } from '../../config/types.js'
2+
import type { ImportMap } from './index.js'
3+
4+
import { parsePayloadComponent } from './parsePayloadComponent.js'
5+
6+
export const getFromImportMap = <TOutput>(args: {
7+
importMap: ImportMap
8+
PayloadComponent: PayloadComponent
9+
schemaPath?: string
10+
silent?: boolean
11+
}): TOutput => {
12+
const { importMap, PayloadComponent, schemaPath, silent } = args
13+
14+
const { exportName, path } = parsePayloadComponent(PayloadComponent)
15+
16+
const key = path + '#' + exportName
17+
18+
const importMapEntry = importMap[key]
19+
20+
if (!importMapEntry && !silent) {
21+
// eslint-disable-next-line no-console
22+
console.error(
23+
`getFromImportMap: PayloadComponent not found in importMap`,
24+
{
25+
key,
26+
PayloadComponent,
27+
schemaPath,
28+
},
29+
'You may need to run the `payload generate:importmap` command to generate the importMap ahead of runtime.',
30+
)
31+
}
32+
33+
return importMapEntry
34+
}

packages/payload/src/bin/generateImportMap/iterateConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-unused-expressions */
12
import type { AdminViewConfig } from '../../admin/views/types.js'
23
import type { SanitizedConfig } from '../../config/types.js'
34
import type { AddToImportMap, Imports, InternalImportMap } from './index.js'

0 commit comments

Comments
 (0)