Skip to content

Commit a192632

Browse files
authored
feat(richtext-lexical)!: move migration related features to /migrate subpath export in order to decrease module count when those are not used (#7660)
This lowers the module count by 31 modules BREAKING: Migration-related lexical modules are now exported from `@payloadcms/richtext-lexical/migrate` instead of `@payloadcms/richtext-lexical`
1 parent 78e55d6 commit a192632

File tree

5 files changed

+39
-26
lines changed

5 files changed

+39
-26
lines changed

docs/lexical/migration.mdx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ IMPORTANT: This will overwrite all slate data. We recommend doing the following
2020
3. Add the SlateToLexicalFeature (as seen below) first, and test it out by loading up the Admin Panel, to see if the migrator works as expected. You might have to build some custom converters for some fields first in order to convert custom Slate nodes. The SlateToLexicalFeature is where the converters are stored. Only fields with this feature added will be migrated.
2121

2222
```ts
23-
import { migrateSlateToLexical } from '@payloadcms/richtext-lexical'
23+
import { migrateSlateToLexical } from '@payloadcms/richtext-lexical/migrate'
2424

2525
await migrateSlateToLexical({ payload })
2626
```
@@ -34,7 +34,8 @@ Simply add the `SlateToLexicalFeature` to your editor:
3434
```ts
3535
import type { CollectionConfig } from 'payload'
3636

37-
import { SlateToLexicalFeature, lexicalEditor } from '@payloadcms/richtext-lexical'
37+
import { SlateToLexicalFeature } from '@payloadcms/richtext-lexical/migrate'
38+
import { lexicalEditor } from '@payloadcms/richtext-lexical'
3839

3940
const Pages: CollectionConfig = {
4041
slug: 'pages',
@@ -64,8 +65,8 @@ The easy way to solve this: Edit the richText field and save the document! This
6465
If you have custom Slate nodes, create a custom converter for them. Here's the Upload converter as an example:
6566

6667
```ts
67-
import type { SerializedUploadNode } from '../uploadNode.'
68-
import type { SlateNodeConverter } from '@payloadcms/richtext-lexical'
68+
import type { SerializedUploadNode } from '../uploadNode'
69+
import type { SlateNodeConverter } from '@payloadcms/richtext-lexical/migrate'
6970

7071
export const SlateUploadConverter: SlateNodeConverter = {
7172
converter({ slateNode }) {
@@ -95,9 +96,9 @@ When using the `SlateToLexicalFeature`, you can add your custom converters to th
9596
```ts
9697
import type { CollectionConfig } from 'payload'
9798

99+
import { lexicalEditor } from '@payloadcms/richtext-lexical'
98100
import {
99101
SlateToLexicalFeature,
100-
lexicalEditor,
101102
defaultSlateConverters,
102103
} from '@payloadcms/richtext-lexical'
103104

packages/richtext-lexical/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
"types": "./src/exports/client/index.ts",
2424
"default": "./src/exports/client/index.ts"
2525
},
26+
"./migrate": {
27+
"import": "./src/exports/server/migrate.ts",
28+
"types": "./src/exports/server/migrate.ts",
29+
"default": "./src/exports/server/migrate.ts"
30+
},
2631
"./generateComponentMap": "./src/utilities/generateComponentMap.tsx"
2732
},
2833
"main": "./src/index.ts",
@@ -109,6 +114,11 @@
109114
"types": "./dist/exports/client/index.d.ts",
110115
"default": "./dist/exports/client/index.js"
111116
},
117+
"./migrate": {
118+
"import": "./dist/exports/server/migrate.js",
119+
"types": "./dist/exports/server/migrate.d.ts",
120+
"default": "./dist/exports/server/migrate.js"
121+
},
112122
"./generateComponentMap": {
113123
"import": "./dist/utilities/generateComponentMap.js",
114124
"types": "./dist/utilities/generateComponentMap.d.ts",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export { LexicalPluginToLexicalFeature } from '../../features/migrations/lexicalPluginToLexical/feature.server.js'
2+
export { SlateBlockquoteConverter } from '../../features/migrations/slateToLexical/converter/converters/blockquote/converter.js'
3+
export { SlateHeadingConverter } from '../../features/migrations/slateToLexical/converter/converters/heading/converter.js'
4+
export { SlateIndentConverter } from '../../features/migrations/slateToLexical/converter/converters/indent/converter.js'
5+
export { SlateLinkConverter } from '../../features/migrations/slateToLexical/converter/converters/link/converter.js'
6+
export { SlateListItemConverter } from '../../features/migrations/slateToLexical/converter/converters/listItem/converter.js'
7+
export { SlateOrderedListConverter } from '../../features/migrations/slateToLexical/converter/converters/orderedList/converter.js'
8+
export { SlateRelationshipConverter } from '../../features/migrations/slateToLexical/converter/converters/relationship/converter.js'
9+
export { SlateUnknownConverter } from '../../features/migrations/slateToLexical/converter/converters/unknown/converter.js'
10+
export { SlateUnorderedListConverter } from '../../features/migrations/slateToLexical/converter/converters/unorderedList/converter.js'
11+
export { SlateUploadConverter } from '../../features/migrations/slateToLexical/converter/converters/upload/converter.js'
12+
export { defaultSlateConverters } from '../../features/migrations/slateToLexical/converter/defaultConverters.js'
13+
export {
14+
convertSlateNodesToLexical,
15+
convertSlateToLexical,
16+
} from '../../features/migrations/slateToLexical/converter/index.js'
17+
18+
export { SlateToLexicalFeature } from '../../features/migrations/slateToLexical/feature.server.js'
19+
export { migrateSlateToLexical } from '../../utilities/migrateSlateToLexical/index.js'

packages/richtext-lexical/src/index.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -879,28 +879,11 @@ export { LinkFeature, type LinkFeatureServerProps } from './features/link/server
879879
export { ChecklistFeature } from './features/lists/checklist/server/index.js'
880880
export { OrderedListFeature } from './features/lists/orderedList/server/index.js'
881881
export { UnorderedListFeature } from './features/lists/unorderedList/server/index.js'
882-
export { LexicalPluginToLexicalFeature } from './features/migrations/lexicalPluginToLexical/feature.server.js'
883-
export { SlateBlockquoteConverter } from './features/migrations/slateToLexical/converter/converters/blockquote/converter.js'
884-
export { SlateHeadingConverter } from './features/migrations/slateToLexical/converter/converters/heading/converter.js'
885-
export { SlateIndentConverter } from './features/migrations/slateToLexical/converter/converters/indent/converter.js'
886-
export { SlateLinkConverter } from './features/migrations/slateToLexical/converter/converters/link/converter.js'
887-
export { SlateListItemConverter } from './features/migrations/slateToLexical/converter/converters/listItem/converter.js'
888-
export { SlateOrderedListConverter } from './features/migrations/slateToLexical/converter/converters/orderedList/converter.js'
889-
export { SlateRelationshipConverter } from './features/migrations/slateToLexical/converter/converters/relationship/converter.js'
890-
export { SlateUnknownConverter } from './features/migrations/slateToLexical/converter/converters/unknown/converter.js'
891-
export { SlateUnorderedListConverter } from './features/migrations/slateToLexical/converter/converters/unorderedList/converter.js'
892-
export { SlateUploadConverter } from './features/migrations/slateToLexical/converter/converters/upload/converter.js'
893-
export { defaultSlateConverters } from './features/migrations/slateToLexical/converter/defaultConverters.js'
894882

895-
export {
896-
convertSlateNodesToLexical,
897-
convertSlateToLexical,
898-
} from './features/migrations/slateToLexical/converter/index.js'
899883
export type {
900884
SlateNode,
901885
SlateNodeConverter,
902886
} from './features/migrations/slateToLexical/converter/types.js'
903-
export { SlateToLexicalFeature } from './features/migrations/slateToLexical/feature.server.js'
904887

905888
export { ParagraphFeature } from './features/paragraph/server/index.js'
906889
export {
@@ -1009,6 +992,4 @@ export type { LexicalEditorProps, LexicalRichTextAdapter } from './types.js'
1009992
export { createServerFeature } from './utilities/createServerFeature.js'
1010993
export type { FieldsDrawerProps } from './utilities/fieldsDrawer/Drawer.js'
1011994

1012-
export { migrateSlateToLexical } from './utilities/migrateSlateToLexical/index.js'
1013-
1014995
export { upgradeLexicalData } from './utilities/upgradeLexicalData/index.js'

test/fields/collections/LexicalMigrate/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import type { CollectionConfig } from 'payload'
22

33
import {
44
HTMLConverterFeature,
5-
LexicalPluginToLexicalFeature,
65
LinkFeature,
7-
SlateToLexicalFeature,
86
TreeViewFeature,
97
UploadFeature,
108
lexicalEditor,
119
lexicalHTML,
1210
} from '@payloadcms/richtext-lexical'
11+
import {
12+
LexicalPluginToLexicalFeature,
13+
SlateToLexicalFeature,
14+
} from '@payloadcms/richtext-lexical/migrate'
1315

1416
import { lexicalMigrateFieldsSlug } from '../../slugs.js'
1517
import { getSimpleLexicalData } from './data.js'

0 commit comments

Comments
 (0)