@payloadcms/richtext-lexical 3.23.0-canary.ec17695 → 3.23.0-canary.f63b80a
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/converters/html/field/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAqD,MAAM,SAAS,CAAA;AAEvF,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAA;AAEtF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAM1D,KAAK,KAAK,GAAG;IACX;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,sBAEnC;IACD,YAAY,EAAE,2BAA2B,CAAA;CAC1C,KAAG,aAAa,EA+ChB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/converters/html/field/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAqD,MAAM,SAAS,CAAA;AAEvF,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAA;AAEtF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAM1D,KAAK,KAAK,GAAG;IACX;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,sBAEnC;IACD,YAAY,EAAE,2BAA2B,CAAA;CAC1C,KAAG,aAAa,EA+ChB,CAAA;AAED,eAAO,MAAM,WAAW,EAAE;AACxB;;;;IAII;AACJ,gBAAgB,EAAE,MAAM,EACxB,KAAK,EAAE,KAAK,KACT,KAwFJ,CAAA"}
|
|
@@ -43,41 +43,6 @@ export const consolidateHTMLConverters = ({
|
|
|
43
43
|
}
|
|
44
44
|
return filteredConverters;
|
|
45
45
|
};
|
|
46
|
-
// find the path of this field, as well as its sibling fields, by looking for this `field` in fields and traversing it recursively
|
|
47
|
-
function findFieldPathAndSiblingFields(fields, path, field, req) {
|
|
48
|
-
for (const curField of fields) {
|
|
49
|
-
if (curField === field) {
|
|
50
|
-
return {
|
|
51
|
-
path: [...path, curField.name],
|
|
52
|
-
siblingFields: fields
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
if ('fields' in curField) {
|
|
56
|
-
const result = findFieldPathAndSiblingFields(curField.fields, 'name' in curField ? [...path, curField.name] : [...path], field);
|
|
57
|
-
if (result) {
|
|
58
|
-
return result;
|
|
59
|
-
}
|
|
60
|
-
} else if ('tabs' in curField) {
|
|
61
|
-
for (const tab of curField.tabs) {
|
|
62
|
-
const result = findFieldPathAndSiblingFields(tab.fields, 'name' in tab ? [...path, tab.name] : [...path], field);
|
|
63
|
-
if (result) {
|
|
64
|
-
return result;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
} else if ('blocks' in curField) {
|
|
68
|
-
for (const _block of curField.blockReferences ?? curField.blocks) {
|
|
69
|
-
const block = typeof _block === 'string' ? req?.payload.blocks[_block] : _block;
|
|
70
|
-
if (block?.fields?.length) {
|
|
71
|
-
const result = findFieldPathAndSiblingFields(block.fields, [...path, curField.name, block.slug], field, req);
|
|
72
|
-
if (result) {
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
46
|
export const lexicalHTML = (lexicalFieldName, props) => {
|
|
82
47
|
const {
|
|
83
48
|
name = 'lexicalHTML',
|
|
@@ -95,25 +60,19 @@ export const lexicalHTML = (lexicalFieldName, props) => {
|
|
|
95
60
|
},
|
|
96
61
|
hooks: {
|
|
97
62
|
afterRead: [async ({
|
|
98
|
-
collection,
|
|
99
63
|
currentDepth,
|
|
100
64
|
depth,
|
|
101
65
|
draft,
|
|
102
66
|
field,
|
|
103
|
-
global,
|
|
104
67
|
overrideAccess,
|
|
105
68
|
req,
|
|
106
69
|
showHiddenFields,
|
|
107
|
-
siblingData
|
|
70
|
+
siblingData,
|
|
71
|
+
siblingFields
|
|
108
72
|
}) => {
|
|
109
|
-
|
|
110
|
-
const foundSiblingFields = findFieldPathAndSiblingFields(fields, [], field, req);
|
|
111
|
-
if (!foundSiblingFields) {
|
|
73
|
+
if (!siblingFields) {
|
|
112
74
|
throw new Error(`Could not find sibling fields of current lexicalHTML field with name ${field?.name}`);
|
|
113
75
|
}
|
|
114
|
-
const {
|
|
115
|
-
siblingFields
|
|
116
|
-
} = foundSiblingFields;
|
|
117
76
|
const lexicalField = siblingFields.find(field => 'name' in field && field.name === lexicalFieldName);
|
|
118
77
|
const lexicalFieldData = siblingData[lexicalFieldName];
|
|
119
78
|
if (!lexicalFieldData) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["defaultHTMLConverters","convertLexicalToHTML","consolidateHTMLConverters","editorConfig","htmlConverterFeature","resolvedFeatureMap","get","htmlConverterFeatureProps","sanitizedServerFeatureProps","defaultConvertersWithConvertersFromFeatures","converter","features","converters","html","push","finalConverters","defaultConverters","foundNodeTypes","filteredConverters","reverse","nodeTypes","length","newConverter","filter","nodeType","includes","findFieldPathAndSiblingFields","fields","path","field","req","curField","name","siblingFields","result","tab","tabs","_block","blockReferences","blocks","block","payload","slug","lexicalHTML","lexicalFieldName","props","hidden","storeInDB","type","admin","editorOptions","language","hooks","afterRead","collection","currentDepth","depth","draft","global","overrideAccess","showHiddenFields","siblingData","foundSiblingFields","Error","lexicalField","find","lexicalFieldData","config","editor","has","data","beforeChange","value"],"sources":["../../../../../src/features/converters/html/field/index.ts"],"sourcesContent":["import type { SerializedEditorState } from 'lexical'\nimport type { Field, FieldAffectingData, PayloadRequest, RichTextField } from 'payload'\n\nimport type { SanitizedServerEditorConfig } from '../../../../lexical/config/types.js'\nimport type { AdapterProps, LexicalRichTextAdapter } from '../../../../types.js'\nimport type { HTMLConverter } from '../converter/types.js'\nimport type { HTMLConverterFeatureProps } from '../index.js'\n\nimport { defaultHTMLConverters } from '../converter/defaultConverters.js'\nimport { convertLexicalToHTML } from '../converter/index.js'\n\ntype Props = {\n /**\n * Whether the lexicalHTML field should be hidden in the admin panel\n *\n * @default true\n */\n hidden?: boolean\n name: string\n /**\n * Whether the HTML should be stored in the database\n *\n * @default false\n */\n storeInDB?: boolean\n}\n\n/**\n * Combines the default HTML converters with HTML converters found in the features, and with HTML converters configured in the htmlConverter feature.\n *\n * @param editorConfig\n */\nexport const consolidateHTMLConverters = ({\n editorConfig,\n}: {\n editorConfig: SanitizedServerEditorConfig\n}): HTMLConverter[] => {\n const htmlConverterFeature = editorConfig.resolvedFeatureMap.get('htmlConverter')\n const htmlConverterFeatureProps: HTMLConverterFeatureProps =\n htmlConverterFeature?.sanitizedServerFeatureProps\n\n const defaultConvertersWithConvertersFromFeatures = [...defaultHTMLConverters]\n\n for (const converter of editorConfig.features.converters.html) {\n defaultConvertersWithConvertersFromFeatures.push(converter)\n }\n\n const finalConverters =\n htmlConverterFeatureProps?.converters &&\n typeof htmlConverterFeatureProps?.converters === 'function'\n ? htmlConverterFeatureProps.converters({\n defaultConverters: defaultConvertersWithConvertersFromFeatures,\n })\n : (htmlConverterFeatureProps?.converters as HTMLConverter[]) ||\n defaultConvertersWithConvertersFromFeatures\n\n // filter converters by nodeTypes. The last converter in the list wins. If there are multiple converters for the same nodeType, the last one will be used and the node types will be removed from\n // previous converters. If previous converters do not have any nodeTypes left, they will be removed from the list.\n // This guarantees that user-added converters which are added after the default ones will always have precedence\n const foundNodeTypes: string[] = []\n const filteredConverters: HTMLConverter[] = []\n for (const converter of finalConverters.reverse()) {\n if (!converter.nodeTypes?.length) {\n continue\n }\n const newConverter: HTMLConverter = {\n converter: converter.converter,\n nodeTypes: [...converter.nodeTypes],\n }\n newConverter.nodeTypes = newConverter.nodeTypes.filter((nodeType) => {\n if (foundNodeTypes.includes(nodeType)) {\n return false\n }\n foundNodeTypes.push(nodeType)\n return true\n })\n\n if (newConverter.nodeTypes.length) {\n filteredConverters.push(newConverter)\n }\n }\n\n return filteredConverters\n}\n\n// find the path of this field, as well as its sibling fields, by looking for this `field` in fields and traversing it recursively\nfunction findFieldPathAndSiblingFields(\n fields: Field[],\n path: string[],\n field: FieldAffectingData,\n req?: PayloadRequest,\n): {\n path: string[]\n siblingFields: Field[]\n} | null {\n for (const curField of fields) {\n if (curField === field) {\n return {\n path: [...path, curField.name],\n siblingFields: fields,\n }\n }\n\n if ('fields' in curField) {\n const result = findFieldPathAndSiblingFields(\n curField.fields,\n 'name' in curField ? [...path, curField.name] : [...path],\n field,\n )\n if (result) {\n return result\n }\n } else if ('tabs' in curField) {\n for (const tab of curField.tabs) {\n const result = findFieldPathAndSiblingFields(\n tab.fields,\n 'name' in tab ? [...path, tab.name] : [...path],\n field,\n )\n if (result) {\n return result\n }\n }\n } else if ('blocks' in curField) {\n for (const _block of curField.blockReferences ?? curField.blocks) {\n const block = typeof _block === 'string' ? req?.payload.blocks[_block] : _block\n\n if (block?.fields?.length) {\n const result = findFieldPathAndSiblingFields(\n block.fields,\n [...path, curField.name, block.slug],\n field,\n req,\n )\n if (result) {\n return result\n }\n }\n }\n }\n }\n\n return null\n}\n\nexport const lexicalHTML: (\n /**\n * A string which matches the lexical field name you want to convert to HTML.\n *\n * This has to be a SIBLING field of this lexicalHTML field - otherwise, it won't be able to find the lexical field.\n **/\n lexicalFieldName: string,\n props: Props,\n) => Field = (lexicalFieldName, props) => {\n const { name = 'lexicalHTML', hidden = true, storeInDB = false } = props\n return {\n name,\n type: 'code',\n admin: {\n editorOptions: {\n language: 'html',\n },\n hidden,\n },\n hooks: {\n afterRead: [\n async ({\n collection,\n currentDepth,\n depth,\n draft,\n field,\n global,\n overrideAccess,\n req,\n showHiddenFields,\n siblingData,\n }) => {\n const fields = collection ? collection.fields : global!.fields\n\n const foundSiblingFields = findFieldPathAndSiblingFields(fields, [], field, req)\n\n if (!foundSiblingFields) {\n throw new Error(\n `Could not find sibling fields of current lexicalHTML field with name ${field?.name}`,\n )\n }\n\n const { siblingFields } = foundSiblingFields\n const lexicalField: RichTextField<SerializedEditorState, AdapterProps> =\n siblingFields.find(\n (field) => 'name' in field && field.name === lexicalFieldName,\n ) as RichTextField<SerializedEditorState, AdapterProps>\n\n const lexicalFieldData: SerializedEditorState = siblingData[lexicalFieldName]\n\n if (!lexicalFieldData) {\n return ''\n }\n\n if (!lexicalField) {\n throw new Error(\n 'You cannot use the lexicalHTML field because the referenced lexical field was not found',\n )\n }\n\n const config = (lexicalField?.editor as LexicalRichTextAdapter)?.editorConfig\n\n if (!config) {\n throw new Error(\n 'The linked lexical field does not have an editorConfig. This is needed for the lexicalHTML field.',\n )\n }\n\n if (!config?.resolvedFeatureMap?.has('htmlConverter')) {\n throw new Error(\n 'You cannot use the lexicalHTML field because the linked lexical field does not have a HTMLConverterFeature',\n )\n }\n\n const finalConverters = consolidateHTMLConverters({\n editorConfig: config,\n })\n\n return await convertLexicalToHTML({\n converters: finalConverters,\n currentDepth,\n data: lexicalFieldData,\n depth,\n draft,\n overrideAccess,\n req,\n showHiddenFields,\n })\n },\n ],\n beforeChange: [\n ({ siblingData, value }) => {\n if (storeInDB) {\n return value\n }\n delete siblingData[name]\n return null\n },\n ],\n },\n }\n}\n"],"mappings":"AAQA,SAASA,qBAAqB,QAAQ;AACtC,SAASC,oBAAoB,QAAQ;AAkBrC;;;;;AAKA,OAAO,MAAMC,yBAAA,GAA4BA,CAAC;EACxCC;AAAY,CAGb;EACC,MAAMC,oBAAA,GAAuBD,YAAA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E,MAAA,EAAQ;UACX,MAAM,IAAIJ,KAAA,CACR;QAEJ;QAEA,IAAI,CAACI,MAAA,EAAQ9D,kBAAA,EAAoBgE,GAAA,CAAI,kBAAkB;UACrD,MAAM,IAAIN,KAAA,CACR;QAEJ;QAEA,MAAMhD,eAAA,GAAkBb,yBAAA,CAA0B;UAChDC,YAAA,EAAcgE;QAChB;QAEA,OAAO,MAAMlE,oBAAA,CAAqB;UAChCW,UAAA,EAAYG,eAAA;UACZwC,YAAA;UACAe,IAAA,EAAMJ,gBAAA;UACNV,KAAA;UACAC,KAAA;UACAE,cAAA;UACA7B,GAAA;UACA8B;QACF;MACF,EACD;MACDW,YAAA,EAAc,CACZ,CAAC;QAAEV,WAAW;QAAEW;MAAK,CAAE;QACrB,IAAIzB,SAAA,EAAW;UACb,OAAOyB,KAAA;QACT;QACA,OAAOX,WAAW,CAAC7B,IAAA,CAAK;QACxB,OAAO;MACT;IAEJ;EACF;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["defaultHTMLConverters","convertLexicalToHTML","consolidateHTMLConverters","editorConfig","htmlConverterFeature","resolvedFeatureMap","get","htmlConverterFeatureProps","sanitizedServerFeatureProps","defaultConvertersWithConvertersFromFeatures","converter","features","converters","html","push","finalConverters","defaultConverters","foundNodeTypes","filteredConverters","reverse","nodeTypes","length","newConverter","filter","nodeType","includes","lexicalHTML","lexicalFieldName","props","name","hidden","storeInDB","type","admin","editorOptions","language","hooks","afterRead","currentDepth","depth","draft","field","overrideAccess","req","showHiddenFields","siblingData","siblingFields","Error","lexicalField","find","lexicalFieldData","config","editor","has","data","beforeChange","value"],"sources":["../../../../../src/features/converters/html/field/index.ts"],"sourcesContent":["import type { SerializedEditorState } from 'lexical'\nimport type { Field, FieldAffectingData, PayloadRequest, RichTextField } from 'payload'\n\nimport type { SanitizedServerEditorConfig } from '../../../../lexical/config/types.js'\nimport type { AdapterProps, LexicalRichTextAdapter } from '../../../../types.js'\nimport type { HTMLConverter } from '../converter/types.js'\nimport type { HTMLConverterFeatureProps } from '../index.js'\n\nimport { defaultHTMLConverters } from '../converter/defaultConverters.js'\nimport { convertLexicalToHTML } from '../converter/index.js'\n\ntype Props = {\n /**\n * Whether the lexicalHTML field should be hidden in the admin panel\n *\n * @default true\n */\n hidden?: boolean\n name: string\n /**\n * Whether the HTML should be stored in the database\n *\n * @default false\n */\n storeInDB?: boolean\n}\n\n/**\n * Combines the default HTML converters with HTML converters found in the features, and with HTML converters configured in the htmlConverter feature.\n *\n * @param editorConfig\n */\nexport const consolidateHTMLConverters = ({\n editorConfig,\n}: {\n editorConfig: SanitizedServerEditorConfig\n}): HTMLConverter[] => {\n const htmlConverterFeature = editorConfig.resolvedFeatureMap.get('htmlConverter')\n const htmlConverterFeatureProps: HTMLConverterFeatureProps =\n htmlConverterFeature?.sanitizedServerFeatureProps\n\n const defaultConvertersWithConvertersFromFeatures = [...defaultHTMLConverters]\n\n for (const converter of editorConfig.features.converters.html) {\n defaultConvertersWithConvertersFromFeatures.push(converter)\n }\n\n const finalConverters =\n htmlConverterFeatureProps?.converters &&\n typeof htmlConverterFeatureProps?.converters === 'function'\n ? htmlConverterFeatureProps.converters({\n defaultConverters: defaultConvertersWithConvertersFromFeatures,\n })\n : (htmlConverterFeatureProps?.converters as HTMLConverter[]) ||\n defaultConvertersWithConvertersFromFeatures\n\n // filter converters by nodeTypes. The last converter in the list wins. If there are multiple converters for the same nodeType, the last one will be used and the node types will be removed from\n // previous converters. If previous converters do not have any nodeTypes left, they will be removed from the list.\n // This guarantees that user-added converters which are added after the default ones will always have precedence\n const foundNodeTypes: string[] = []\n const filteredConverters: HTMLConverter[] = []\n for (const converter of finalConverters.reverse()) {\n if (!converter.nodeTypes?.length) {\n continue\n }\n const newConverter: HTMLConverter = {\n converter: converter.converter,\n nodeTypes: [...converter.nodeTypes],\n }\n newConverter.nodeTypes = newConverter.nodeTypes.filter((nodeType) => {\n if (foundNodeTypes.includes(nodeType)) {\n return false\n }\n foundNodeTypes.push(nodeType)\n return true\n })\n\n if (newConverter.nodeTypes.length) {\n filteredConverters.push(newConverter)\n }\n }\n\n return filteredConverters\n}\n\nexport const lexicalHTML: (\n /**\n * A string which matches the lexical field name you want to convert to HTML.\n *\n * This has to be a SIBLING field of this lexicalHTML field - otherwise, it won't be able to find the lexical field.\n **/\n lexicalFieldName: string,\n props: Props,\n) => Field = (lexicalFieldName, props) => {\n const { name = 'lexicalHTML', hidden = true, storeInDB = false } = props\n return {\n name,\n type: 'code',\n admin: {\n editorOptions: {\n language: 'html',\n },\n hidden,\n },\n hooks: {\n afterRead: [\n async ({\n currentDepth,\n depth,\n draft,\n field,\n overrideAccess,\n req,\n showHiddenFields,\n siblingData,\n siblingFields,\n }) => {\n if (!siblingFields) {\n throw new Error(\n `Could not find sibling fields of current lexicalHTML field with name ${field?.name}`,\n )\n }\n\n const lexicalField: RichTextField<SerializedEditorState, AdapterProps> =\n siblingFields.find(\n (field) => 'name' in field && field.name === lexicalFieldName,\n ) as RichTextField<SerializedEditorState, AdapterProps>\n\n const lexicalFieldData: SerializedEditorState = siblingData[lexicalFieldName]\n\n if (!lexicalFieldData) {\n return ''\n }\n\n if (!lexicalField) {\n throw new Error(\n 'You cannot use the lexicalHTML field because the referenced lexical field was not found',\n )\n }\n\n const config = (lexicalField?.editor as LexicalRichTextAdapter)?.editorConfig\n\n if (!config) {\n throw new Error(\n 'The linked lexical field does not have an editorConfig. This is needed for the lexicalHTML field.',\n )\n }\n\n if (!config?.resolvedFeatureMap?.has('htmlConverter')) {\n throw new Error(\n 'You cannot use the lexicalHTML field because the linked lexical field does not have a HTMLConverterFeature',\n )\n }\n\n const finalConverters = consolidateHTMLConverters({\n editorConfig: config,\n })\n\n return await convertLexicalToHTML({\n converters: finalConverters,\n currentDepth,\n data: lexicalFieldData,\n depth,\n draft,\n overrideAccess,\n req,\n showHiddenFields,\n })\n },\n ],\n beforeChange: [\n ({ siblingData, value }) => {\n if (storeInDB) {\n return value\n }\n delete siblingData[name]\n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YAAA,EAAcgD;QAChB;QAEA,OAAO,MAAMlD,oBAAA,CAAqB;UAChCW,UAAA,EAAYG,eAAA;UACZuB,YAAA;UACAgB,IAAA,EAAMJ,gBAAA;UACNX,KAAA;UACAC,KAAA;UACAE,cAAA;UACAC,GAAA;UACAC;QACF;MACF,EACD;MACDW,YAAA,EAAc,CACZ,CAAC;QAAEV,WAAW;QAAEW;MAAK,CAAE;QACrB,IAAIzB,SAAA,EAAW;UACb,OAAOyB,KAAA;QACT;QACA,OAAOX,WAAW,CAAChB,IAAA,CAAK;QACxB,OAAO;MACT;IAEJ;EACF;AACF","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/richtext-lexical",
|
|
3
|
-
"version": "3.23.0-canary.
|
|
3
|
+
"version": "3.23.0-canary.f63b80a",
|
|
4
4
|
"description": "The officially supported Lexical richtext adapter for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -352,8 +352,8 @@
|
|
|
352
352
|
"react-error-boundary": "4.1.2",
|
|
353
353
|
"ts-essentials": "10.0.3",
|
|
354
354
|
"uuid": "10.0.0",
|
|
355
|
-
"@payloadcms/translations": "3.23.0-canary.
|
|
356
|
-
"@payloadcms/ui": "3.23.0-canary.
|
|
355
|
+
"@payloadcms/translations": "3.23.0-canary.f63b80a",
|
|
356
|
+
"@payloadcms/ui": "3.23.0-canary.f63b80a"
|
|
357
357
|
},
|
|
358
358
|
"devDependencies": {
|
|
359
359
|
"@babel/cli": "7.26.4",
|
|
@@ -374,7 +374,7 @@
|
|
|
374
374
|
"eslint-plugin-react-compiler": "19.0.0-beta-714736e-20250131",
|
|
375
375
|
"swc-plugin-transform-remove-imports": "3.1.0",
|
|
376
376
|
"@payloadcms/eslint-config": "3.9.0",
|
|
377
|
-
"payload": "3.23.0-canary.
|
|
377
|
+
"payload": "3.23.0-canary.f63b80a"
|
|
378
378
|
},
|
|
379
379
|
"peerDependencies": {
|
|
380
380
|
"@faceless-ui/modal": "3.0.0-beta.2",
|
|
@@ -392,8 +392,8 @@
|
|
|
392
392
|
"lexical": "0.21.0",
|
|
393
393
|
"react": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
|
|
394
394
|
"react-dom": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
|
|
395
|
-
"@payloadcms/next": "3.23.0-canary.
|
|
396
|
-
"payload": "3.23.0-canary.
|
|
395
|
+
"@payloadcms/next": "3.23.0-canary.f63b80a",
|
|
396
|
+
"payload": "3.23.0-canary.f63b80a"
|
|
397
397
|
},
|
|
398
398
|
"engines": {
|
|
399
399
|
"node": "^18.20.2 || >=20.9.0"
|