@payloadcms/richtext-lexical 3.0.0-canary.9beaa28 → 3.0.0-canary.9de3ffd
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exports/client/bundled.css +1 -1
- package/dist/features/migrations/slateToLexical/converter/converters/link/converter.js +1 -1
- package/dist/features/migrations/slateToLexical/converter/converters/link/converter.js.map +1 -1
- package/dist/field/bundled.css +1 -1
- package/dist/utilities/migrateSlateToLexical/index.d.ts.map +1 -1
- package/dist/utilities/migrateSlateToLexical/index.js +44 -13
- package/dist/utilities/migrateSlateToLexical/index.js.map +1 -1
- package/package.json +10 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utilities/migrateSlateToLexical/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAyC,OAAO,EAAE,MAAM,SAAS,CAAA;AAI7E;;;;;;;;;GASG;AACH,wBAAsB,qBAAqB,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utilities/migrateSlateToLexical/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAyC,OAAO,EAAE,MAAM,SAAS,CAAA;AAI7E;;;;;;;;;GASG;AACH,wBAAsB,qBAAqB,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,iBAoC5E"}
|
|
@@ -13,6 +13,7 @@ export async function migrateSlateToLexical({
|
|
|
13
13
|
payload
|
|
14
14
|
}) {
|
|
15
15
|
const collections = payload.config.collections;
|
|
16
|
+
const errors = [];
|
|
16
17
|
const allLocales = payload.config.localization ? payload.config.localization.localeCodes : [null];
|
|
17
18
|
const totalCollections = collections.length;
|
|
18
19
|
for (const locale of allLocales) {
|
|
@@ -22,6 +23,7 @@ export async function migrateSlateToLexical({
|
|
|
22
23
|
await migrateCollection({
|
|
23
24
|
collection,
|
|
24
25
|
cur: curCollection,
|
|
26
|
+
errors,
|
|
25
27
|
locale,
|
|
26
28
|
max: totalCollections,
|
|
27
29
|
payload
|
|
@@ -29,14 +31,21 @@ export async function migrateSlateToLexical({
|
|
|
29
31
|
}
|
|
30
32
|
for (const global of payload.config.globals) {
|
|
31
33
|
await migrateGlobal({
|
|
34
|
+
errors,
|
|
32
35
|
global,
|
|
33
36
|
locale,
|
|
34
37
|
payload
|
|
35
38
|
});
|
|
36
39
|
}
|
|
37
40
|
}
|
|
41
|
+
if (errors.length) {
|
|
42
|
+
console.error(`Found ${errors.length} errors::`, JSON.stringify(errors, null, 2));
|
|
43
|
+
} else {
|
|
44
|
+
console.log('Migration successful - no errors');
|
|
45
|
+
}
|
|
38
46
|
}
|
|
39
47
|
async function migrateGlobal({
|
|
48
|
+
errors,
|
|
40
49
|
global,
|
|
41
50
|
locale,
|
|
42
51
|
payload
|
|
@@ -45,6 +54,7 @@ async function migrateGlobal({
|
|
|
45
54
|
const document = await payload.findGlobal({
|
|
46
55
|
slug: global.slug,
|
|
47
56
|
depth: 0,
|
|
57
|
+
draft: true,
|
|
48
58
|
locale: locale || undefined,
|
|
49
59
|
overrideAccess: true
|
|
50
60
|
});
|
|
@@ -53,17 +63,27 @@ async function migrateGlobal({
|
|
|
53
63
|
fields: global.fields
|
|
54
64
|
});
|
|
55
65
|
if (found) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
66
|
+
try {
|
|
67
|
+
await payload.updateGlobal({
|
|
68
|
+
slug: global.slug,
|
|
69
|
+
data: document,
|
|
70
|
+
depth: 0,
|
|
71
|
+
draft: document?._status === 'draft',
|
|
72
|
+
locale: locale || undefined
|
|
73
|
+
});
|
|
74
|
+
// Catch it, because some errors were caused by the user previously (e.g. invalid relationships) and will throw an error now, even though they are not related to the migration
|
|
75
|
+
} catch (e) {
|
|
76
|
+
console.log('Error updating global', e, {
|
|
77
|
+
slug: global.slug
|
|
78
|
+
});
|
|
79
|
+
errors.push(e);
|
|
80
|
+
}
|
|
62
81
|
}
|
|
63
82
|
}
|
|
64
83
|
async function migrateCollection({
|
|
65
84
|
collection,
|
|
66
85
|
cur,
|
|
86
|
+
errors,
|
|
67
87
|
locale,
|
|
68
88
|
max,
|
|
69
89
|
payload
|
|
@@ -80,6 +100,7 @@ async function migrateCollection({
|
|
|
80
100
|
const documents = await payload.find({
|
|
81
101
|
collection: collection.slug,
|
|
82
102
|
depth: 0,
|
|
103
|
+
draft: true,
|
|
83
104
|
locale: locale || undefined,
|
|
84
105
|
overrideAccess: true,
|
|
85
106
|
page,
|
|
@@ -93,13 +114,23 @@ async function migrateCollection({
|
|
|
93
114
|
fields: collection.fields
|
|
94
115
|
});
|
|
95
116
|
if (found) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
117
|
+
try {
|
|
118
|
+
await payload.update({
|
|
119
|
+
id: document.id,
|
|
120
|
+
collection: collection.slug,
|
|
121
|
+
data: document,
|
|
122
|
+
depth: 0,
|
|
123
|
+
draft: document?._status === 'draft',
|
|
124
|
+
locale: locale || undefined
|
|
125
|
+
});
|
|
126
|
+
// Catch it, because some errors were caused by the user previously (e.g. invalid relationships) and will throw an error now, even though they are not related to the migration
|
|
127
|
+
} catch (e) {
|
|
128
|
+
errors.push(e);
|
|
129
|
+
console.log('Error updating collection', e, {
|
|
130
|
+
id: document.id,
|
|
131
|
+
slug: collection.slug
|
|
132
|
+
});
|
|
133
|
+
}
|
|
103
134
|
}
|
|
104
135
|
}
|
|
105
136
|
page++;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["migrateDocumentFieldsRecursively","migrateSlateToLexical","payload","collections","config","allLocales","localization","localeCodes","totalCollections","length","locale","curCollection","collection","migrateCollection","cur","max","global","globals","migrateGlobal","console","log","slug","document","findGlobal","depth","undefined","overrideAccess","found","migrateDocument","fields","updateGlobal","data","documentCount","count","totalDocs","page","migrated","documents","find","pagination","docs","id","update"],"sources":["../../../src/utilities/migrateSlateToLexical/index.ts"],"sourcesContent":["import type { CollectionConfig, Field, GlobalConfig, Payload } from 'payload'\n\nimport { migrateDocumentFieldsRecursively } from './migrateDocumentFieldsRecursively.js'\n\n/**\n * This goes through every single collection and field in the payload config, and migrates its data from Slate to Lexical. This does not support sub-fields within slate.\n *\n * It will only translate fields fulfilling all these requirements:\n * - field schema uses lexical editor\n * - lexical editor has SlateToLexicalFeature added\n * - saved field data is in Slate format\n *\n * @param payload\n */\nexport async function migrateSlateToLexical({ payload }: { payload: Payload }) {\n const collections = payload.config.collections\n\n const allLocales = payload.config.localization ? payload.config.localization.localeCodes : [null]\n\n const totalCollections = collections.length\n for (const locale of allLocales) {\n let curCollection = 0\n for (const collection of collections) {\n curCollection++\n await migrateCollection({\n collection,\n cur: curCollection,\n locale,\n max: totalCollections,\n payload,\n })\n }\n for (const global of payload.config.globals) {\n await migrateGlobal({\n global,\n locale,\n payload,\n })\n }\n }\n}\n\nasync function migrateGlobal({\n global,\n locale,\n payload,\n}: {\n global: GlobalConfig\n locale: null | string\n payload: Payload\n}) {\n console.log(`SlateToLexical: ${locale}: Migrating global:`, global.slug)\n\n const document = await payload.findGlobal({\n slug: global.slug,\n depth: 0,\n locale: locale || undefined,\n overrideAccess: true,\n })\n\n const found = migrateDocument({\n document,\n fields: global.fields,\n })\n\n if (found) {\n await payload.updateGlobal({\n
|
|
1
|
+
{"version":3,"file":"index.js","names":["migrateDocumentFieldsRecursively","migrateSlateToLexical","payload","collections","config","errors","allLocales","localization","localeCodes","totalCollections","length","locale","curCollection","collection","migrateCollection","cur","max","global","globals","migrateGlobal","console","error","JSON","stringify","log","slug","document","findGlobal","depth","draft","undefined","overrideAccess","found","migrateDocument","fields","updateGlobal","data","_status","e","push","documentCount","count","totalDocs","page","migrated","documents","find","pagination","docs","id","update"],"sources":["../../../src/utilities/migrateSlateToLexical/index.ts"],"sourcesContent":["import type { CollectionConfig, Field, GlobalConfig, Payload } from 'payload'\n\nimport { migrateDocumentFieldsRecursively } from './migrateDocumentFieldsRecursively.js'\n\n/**\n * This goes through every single collection and field in the payload config, and migrates its data from Slate to Lexical. This does not support sub-fields within slate.\n *\n * It will only translate fields fulfilling all these requirements:\n * - field schema uses lexical editor\n * - lexical editor has SlateToLexicalFeature added\n * - saved field data is in Slate format\n *\n * @param payload\n */\nexport async function migrateSlateToLexical({ payload }: { payload: Payload }) {\n const collections = payload.config.collections\n\n const errors = []\n\n const allLocales = payload.config.localization ? payload.config.localization.localeCodes : [null]\n\n const totalCollections = collections.length\n for (const locale of allLocales) {\n let curCollection = 0\n for (const collection of collections) {\n curCollection++\n await migrateCollection({\n collection,\n cur: curCollection,\n errors,\n locale,\n max: totalCollections,\n payload,\n })\n }\n for (const global of payload.config.globals) {\n await migrateGlobal({\n errors,\n global,\n locale,\n payload,\n })\n }\n }\n\n if (errors.length) {\n console.error(`Found ${errors.length} errors::`, JSON.stringify(errors, null, 2))\n } else {\n console.log('Migration successful - no errors')\n }\n}\n\nasync function migrateGlobal({\n errors,\n global,\n locale,\n payload,\n}: {\n errors: any[]\n global: GlobalConfig\n locale: null | string\n payload: Payload\n}) {\n console.log(`SlateToLexical: ${locale}: Migrating global:`, global.slug)\n\n const document = await payload.findGlobal({\n slug: global.slug,\n depth: 0,\n draft: true,\n locale: locale || undefined,\n overrideAccess: true,\n })\n\n const found = migrateDocument({\n document,\n fields: global.fields,\n })\n\n if (found) {\n try {\n await payload.updateGlobal({\n slug: global.slug,\n data: document,\n depth: 0,\n draft: document?._status === 'draft',\n locale: locale || undefined,\n })\n // Catch it, because some errors were caused by the user previously (e.g. invalid relationships) and will throw an error now, even though they are not related to the migration\n } catch (e) {\n console.log('Error updating global', e, {\n slug: global.slug,\n })\n errors.push(e)\n }\n }\n}\n\nasync function migrateCollection({\n collection,\n cur,\n errors,\n locale,\n max,\n payload,\n}: {\n collection: CollectionConfig\n cur: number\n errors: any[]\n locale: null | string\n max: number\n payload: Payload\n}) {\n console.log(\n `SlateToLexical: ${locale}: Migrating collection:`,\n collection.slug,\n '(' + cur + '/' + max + ')',\n )\n\n const documentCount = (\n await payload.count({\n collection: collection.slug,\n depth: 0,\n locale: locale || undefined,\n })\n ).totalDocs\n\n let page = 1\n let migrated = 0\n\n while (migrated < documentCount) {\n const documents = await payload.find({\n collection: collection.slug,\n depth: 0,\n draft: true,\n locale: locale || undefined,\n overrideAccess: true,\n page,\n pagination: true,\n })\n\n for (const document of documents.docs) {\n migrated++\n console.log(\n `SlateToLexical: ${locale}: Migrating collection:`,\n collection.slug,\n '(' +\n cur +\n '/' +\n max +\n ') - Migrating Document: ' +\n document.id +\n ' (' +\n migrated +\n '/' +\n documentCount +\n ')',\n )\n const found = migrateDocument({\n document,\n fields: collection.fields,\n })\n\n if (found) {\n try {\n await payload.update({\n id: document.id,\n collection: collection.slug,\n data: document,\n depth: 0,\n draft: document?._status === 'draft',\n locale: locale || undefined,\n })\n // Catch it, because some errors were caused by the user previously (e.g. invalid relationships) and will throw an error now, even though they are not related to the migration\n } catch (e) {\n errors.push(e)\n\n console.log('Error updating collection', e, {\n id: document.id,\n slug: collection.slug,\n })\n }\n }\n }\n page++\n }\n}\n\nfunction migrateDocument({\n document,\n fields,\n}: {\n document: Record<string, unknown>\n fields: Field[]\n}): boolean {\n return !!migrateDocumentFieldsRecursively({\n data: document,\n fields,\n found: 0,\n })\n}\n"],"mappings":"AAEA,SAASA,gCAAgC,QAAQ;AAEjD;;;;;;;;;;AAUA,OAAO,eAAeC,sBAAsB;EAAEC;AAAO,CAAwB;EAC3E,MAAMC,WAAA,GAAcD,OAAA,CAAQE,MAAM,CAACD,WAAW;EAE9C,MAAME,MAAA,GAAS,EAAE;EAEjB,MAAMC,UAAA,GAAaJ,OAAA,CAAQE,MAAM,CAACG,YAAY,GAAGL,OAAA,CAAQE,MAAM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mBAAmBb,MAAA,yBAA+B,EAClDE,UAAA,CAAWY,IAAI,EACf,MACEV,GAAA,GACA,MACAC,GAAA,GACA,6BACAU,QAAA,CAASuB,EAAE,GACX,OACAL,QAAA,GACA,MACAJ,aAAA,GACA;MAEJ,MAAMR,KAAA,GAAQC,eAAA,CAAgB;QAC5BP,QAAA;QACAQ,MAAA,EAAQrB,UAAA,CAAWqB;MACrB;MAEA,IAAIF,KAAA,EAAO;QACT,IAAI;UACF,MAAM9B,OAAA,CAAQgD,MAAM,CAAC;YACnBD,EAAA,EAAIvB,QAAA,CAASuB,EAAE;YACfpC,UAAA,EAAYA,UAAA,CAAWY,IAAI;YAC3BW,IAAA,EAAMV,QAAA;YACNE,KAAA,EAAO;YACPC,KAAA,EAAOH,QAAA,EAAUW,OAAA,KAAY;YAC7B1B,MAAA,EAAQA,MAAA,IAAUmB;UACpB;UACA;QACF,EAAE,OAAOQ,CAAA,EAAG;UACVjC,MAAA,CAAOkC,IAAI,CAACD,CAAA;UAEZlB,OAAA,CAAQI,GAAG,CAAC,6BAA6Bc,CAAA,EAAG;YAC1CW,EAAA,EAAIvB,QAAA,CAASuB,EAAE;YACfxB,IAAA,EAAMZ,UAAA,CAAWY;UACnB;QACF;MACF;IACF;IACAkB,IAAA;EACF;AACF;AAEA,SAASV,gBAAgB;EACvBP,QAAQ;EACRQ;AAAM,CAIP;EACC,OAAO,CAAC,CAAClC,gCAAA,CAAiC;IACxCoC,IAAA,EAAMV,QAAA;IACNQ,MAAA;IACAF,KAAA,EAAO;EACT;AACF","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/richtext-lexical",
|
|
3
|
-
"version": "3.0.0-canary.
|
|
3
|
+
"version": "3.0.0-canary.9de3ffd",
|
|
4
4
|
"description": "The officially supported Lexical richtext adapter for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -73,11 +73,11 @@
|
|
|
73
73
|
"esbuild-sass-plugin": "3.3.1",
|
|
74
74
|
"eslint-plugin-react-compiler": "0.0.0-experimental-d0e920e-20240815",
|
|
75
75
|
"swc-plugin-transform-remove-imports": "1.15.0",
|
|
76
|
-
"@payloadcms/
|
|
77
|
-
"@payloadcms/
|
|
78
|
-
"
|
|
79
|
-
"@payloadcms/
|
|
80
|
-
"
|
|
76
|
+
"@payloadcms/eslint-config": "3.0.0-beta.59",
|
|
77
|
+
"@payloadcms/next": "3.0.0-canary.9de3ffd",
|
|
78
|
+
"@payloadcms/translations": "3.0.0-canary.9de3ffd",
|
|
79
|
+
"@payloadcms/ui": "3.0.0-canary.9de3ffd",
|
|
80
|
+
"payload": "3.0.0-canary.9de3ffd"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
83
83
|
"@faceless-ui/modal": "3.0.0-beta.2",
|
|
@@ -95,10 +95,10 @@
|
|
|
95
95
|
"lexical": "0.17.0",
|
|
96
96
|
"react": "^19.0.0 || ^19.0.0-rc-06d0b89e-20240801",
|
|
97
97
|
"react-dom": "^19.0.0 || ^19.0.0-rc-06d0b89e-20240801",
|
|
98
|
-
"@payloadcms/next": "3.0.0-canary.
|
|
99
|
-
"@payloadcms/translations": "3.0.0-canary.
|
|
100
|
-
"@payloadcms/ui": "3.0.0-canary.
|
|
101
|
-
"payload": "3.0.0-canary.
|
|
98
|
+
"@payloadcms/next": "3.0.0-canary.9de3ffd",
|
|
99
|
+
"@payloadcms/translations": "3.0.0-canary.9de3ffd",
|
|
100
|
+
"@payloadcms/ui": "3.0.0-canary.9de3ffd",
|
|
101
|
+
"payload": "3.0.0-canary.9de3ffd"
|
|
102
102
|
},
|
|
103
103
|
"engines": {
|
|
104
104
|
"node": "^18.20.2 || >=20.9.0"
|