@payloadcms/richtext-lexical 3.0.0-canary.cf66341 → 3.0.0-canary.d894ac7
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.
|
@@ -53,20 +53,12 @@ async function migrateGlobal({
|
|
|
53
53
|
fields: global.fields
|
|
54
54
|
});
|
|
55
55
|
if (found) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
});
|
|
63
|
-
// 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
|
|
64
|
-
} catch (e) {
|
|
65
|
-
console.log('Error updating global', e, {
|
|
66
|
-
id: document.id,
|
|
67
|
-
slug: global.slug
|
|
68
|
-
});
|
|
69
|
-
}
|
|
56
|
+
await payload.updateGlobal({
|
|
57
|
+
slug: global.slug,
|
|
58
|
+
data: document,
|
|
59
|
+
depth: 0,
|
|
60
|
+
locale: locale || undefined
|
|
61
|
+
});
|
|
70
62
|
}
|
|
71
63
|
}
|
|
72
64
|
async function migrateCollection({
|
|
@@ -101,21 +93,13 @@ async function migrateCollection({
|
|
|
101
93
|
fields: collection.fields
|
|
102
94
|
});
|
|
103
95
|
if (found) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
});
|
|
112
|
-
// 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
|
|
113
|
-
} catch (e) {
|
|
114
|
-
console.log('Error updating collection', e, {
|
|
115
|
-
id: document.id,
|
|
116
|
-
slug: collection.slug
|
|
117
|
-
});
|
|
118
|
-
}
|
|
96
|
+
await payload.update({
|
|
97
|
+
id: document.id,
|
|
98
|
+
collection: collection.slug,
|
|
99
|
+
data: document,
|
|
100
|
+
depth: 0,
|
|
101
|
+
locale: locale || undefined
|
|
102
|
+
});
|
|
119
103
|
}
|
|
120
104
|
}
|
|
121
105
|
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","
|
|
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 slug: global.slug,\n data: document,\n depth: 0,\n locale: locale || undefined,\n })\n }\n}\n\nasync function migrateCollection({\n collection,\n cur,\n locale,\n max,\n payload,\n}: {\n collection: CollectionConfig\n cur: number\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 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 await payload.update({\n id: document.id,\n collection: collection.slug,\n data: document,\n depth: 0,\n locale: locale || undefined,\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,UAAA,GAAaH,OAAA,CAAQE,MAAM,CAACE,YAAY,GAAGJ,OAAA,CAAQE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EACvBN,QAAQ;EACRO;AAAM,CAIP;EACC,OAAO,CAAC,CAAC7B,gCAAA,CAAiC;IACxC+B,IAAA,EAAMT,QAAA;IACNO,MAAA;IACAF,KAAA,EAAO;EACT;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validate/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAA2B,MAAM,SAAS,CAAA;AAC7E,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEtD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAA;AAI7E,eAAO,MAAM,mBAAmB,sBAE7B;IACD,YAAY,EAAE,2BAA2B,CAAA;CAC1C,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validate/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAA2B,MAAM,SAAS,CAAA;AAC7E,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEtD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAA;AAI7E,eAAO,MAAM,mBAAmB,sBAE7B;IACD,YAAY,EAAE,2BAA2B,CAAA;CAC1C,8GA6CA,CAAA"}
|
package/dist/validate/index.js
CHANGED
|
@@ -10,23 +10,8 @@ export const richTextValidateHOC = ({
|
|
|
10
10
|
required
|
|
11
11
|
} = options;
|
|
12
12
|
if (required) {
|
|
13
|
-
const hasChildren =
|
|
14
|
-
|
|
15
|
-
if (value?.root?.children?.length === 1) {
|
|
16
|
-
if (value?.root?.children[0]?.type === 'paragraph') {
|
|
17
|
-
const paragraphNode = value?.root?.children[0];
|
|
18
|
-
if (paragraphNode?.children?.length === 0) {
|
|
19
|
-
hasOnlyEmptyParagraph = true;
|
|
20
|
-
} else if (paragraphNode?.children?.length === 1) {
|
|
21
|
-
const paragraphNodeChild = paragraphNode?.children[0];
|
|
22
|
-
if (paragraphNodeChild.type === 'text') {
|
|
23
|
-
if (!paragraphNodeChild?.['text']?.length) {
|
|
24
|
-
hasOnlyEmptyParagraph = true;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
13
|
+
const hasChildren = value?.root?.children?.length;
|
|
14
|
+
const hasOnlyEmptyParagraph = value?.root?.children?.length === 1 && value?.root?.children[0]?.type === 'paragraph' && value?.root?.children[0]?.children?.length === 0 || value?.root?.children[0]?.children?.length === 1 && value?.root?.children[0]?.children[0]?.type === 'text' && value?.root?.children[0]?.children[0]?.['text'] === '';
|
|
30
15
|
if (!hasChildren || hasOnlyEmptyParagraph) {
|
|
31
16
|
return t('validation:required');
|
|
32
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["validateNodes","richTextValidateHOC","editorConfig","richTextValidate","value","options","req","t","required","hasChildren","root","children","length","hasOnlyEmptyParagraph","type","
|
|
1
|
+
{"version":3,"file":"index.js","names":["validateNodes","richTextValidateHOC","editorConfig","richTextValidate","value","options","req","t","required","hasChildren","root","children","length","hasOnlyEmptyParagraph","type","rootNodes","Array","isArray","nodeValidations","features","validations","nodes","validation"],"sources":["../../src/validate/index.ts"],"sourcesContent":["import type { SerializedEditorState, SerializedParagraphNode } from 'lexical'\nimport type { RichTextField, Validate } from 'payload'\n\nimport type { SanitizedServerEditorConfig } from '../lexical/config/types.js'\n\nimport { validateNodes } from './validateNodes.js'\n\nexport const richTextValidateHOC = ({\n editorConfig,\n}: {\n editorConfig: SanitizedServerEditorConfig\n}) => {\n const richTextValidate: Validate<SerializedEditorState, unknown, unknown, RichTextField> = async (\n value,\n options,\n ) => {\n const {\n req: { t },\n required,\n } = options\n\n if (required) {\n const hasChildren = value?.root?.children?.length\n\n const hasOnlyEmptyParagraph =\n (value?.root?.children?.length === 1 &&\n value?.root?.children[0]?.type === 'paragraph' &&\n (value?.root?.children[0] as SerializedParagraphNode)?.children?.length === 0) ||\n ((value?.root?.children[0] as SerializedParagraphNode)?.children?.length === 1 &&\n (value?.root?.children[0] as SerializedParagraphNode)?.children[0]?.type === 'text' &&\n (value?.root?.children[0] as SerializedParagraphNode)?.children[0]?.['text'] === '')\n\n if (!hasChildren || hasOnlyEmptyParagraph) {\n return t('validation:required')\n }\n }\n\n // Traverse through nodes and validate them. Just like a node can hook into the population process (e.g. link or relationship nodes),\n // they can also hook into the validation process. E.g. a block node probably has fields with validation rules.\n\n const rootNodes = value?.root?.children\n if (rootNodes && Array.isArray(rootNodes) && rootNodes?.length) {\n return await validateNodes({\n nodeValidations: editorConfig.features.validations,\n nodes: rootNodes,\n validation: {\n options,\n value,\n },\n })\n }\n\n return true\n }\n\n return richTextValidate\n}\n"],"mappings":"AAKA,SAASA,aAAa,QAAQ;AAE9B,OAAO,MAAMC,mBAAA,GAAsBA,CAAC;EAClCC;AAAY,CAGb;EACC,MAAMC,gBAAA,GAAqF,MAAAA,CACzFC,KAAA,EACAC,OAAA;IAEA,MAAM;MACJC,GAAA,EAAK;QAAEC;MAAC,CAAE;MACVC;IAAQ,CACT,GAAGH,OAAA;IAEJ,IAAIG,QAAA,EAAU;MACZ,MAAMC,WAAA,GAAcL,KAAA,EAAOM,IAAA,EAAMC,QAAA,EAAUC,MAAA;MAE3C,MAAMC,qBAAA,GACJT,KAAC,EAAOM,IAAA,EAAMC,QAAA,EAAUC,MAAA,KAAW,KACjCR,KAAA,EAAOM,IAAA,EAAMC,QAAQ,CAAC,EAAE,EAAEG,IAAA,KAAS,eACnCV,KAAC,EAAOM,IAAA,EAAMC,QAAQ,CAAC,EAAE,EAA8BA,QAAA,EAAUC,MAAA,KAAW,KAC7ER,KAAC,EAAOM,IAAA,EAAMC,QAAQ,CAAC,EAAE,EAA8BA,QAAA,EAAUC,MAAA,KAAW,KAC3ER,KAAC,EAAOM,IAAA,EAAMC,QAAQ,CAAC,EAAE,EAA8BA,QAAQ,CAAC,EAAE,EAAEG,IAAA,KAAS,UAC7EV,KAAC,EAAOM,IAAA,EAAMC,QAAQ,CAAC,EAAE,EAA8BA,QAAQ,CAAC,EAAE,GAAG,OAAO,KAAK;MAErF,IAAI,CAACF,WAAA,IAAeI,qBAAA,EAAuB;QACzC,OAAON,CAAA,CAAE;MACX;IACF;IAEA;IACA;IAEA,MAAMQ,SAAA,GAAYX,KAAA,EAAOM,IAAA,EAAMC,QAAA;IAC/B,IAAII,SAAA,IAAaC,KAAA,CAAMC,OAAO,CAACF,SAAA,KAAcA,SAAA,EAAWH,MAAA,EAAQ;MAC9D,OAAO,MAAMZ,aAAA,CAAc;QACzBkB,eAAA,EAAiBhB,YAAA,CAAaiB,QAAQ,CAACC,WAAW;QAClDC,KAAA,EAAON,SAAA;QACPO,UAAA,EAAY;UACVjB,OAAA;UACAD;QACF;MACF;IACF;IAEA,OAAO;EACT;EAEA,OAAOD,gBAAA;AACT","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.d894ac7",
|
|
4
4
|
"description": "The officially supported Lexical richtext adapter for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -74,10 +74,10 @@
|
|
|
74
74
|
"eslint-plugin-react-compiler": "0.0.0-experimental-d0e920e-20240815",
|
|
75
75
|
"swc-plugin-transform-remove-imports": "1.15.0",
|
|
76
76
|
"@payloadcms/eslint-config": "3.0.0-beta.59",
|
|
77
|
-
"@payloadcms/next": "3.0.0-canary.
|
|
78
|
-
"@payloadcms/
|
|
79
|
-
"@payloadcms/
|
|
80
|
-
"payload": "3.0.0-canary.
|
|
77
|
+
"@payloadcms/next": "3.0.0-canary.d894ac7",
|
|
78
|
+
"@payloadcms/ui": "3.0.0-canary.d894ac7",
|
|
79
|
+
"@payloadcms/translations": "3.0.0-canary.d894ac7",
|
|
80
|
+
"payload": "3.0.0-canary.d894ac7"
|
|
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.d894ac7",
|
|
99
|
+
"@payloadcms/translations": "3.0.0-canary.d894ac7",
|
|
100
|
+
"@payloadcms/ui": "3.0.0-canary.d894ac7",
|
|
101
|
+
"payload": "3.0.0-canary.d894ac7"
|
|
102
102
|
},
|
|
103
103
|
"engines": {
|
|
104
104
|
"node": "^18.20.2 || >=20.9.0"
|