@payloadcms/richtext-lexical 3.73.0 → 3.74.0-internal.097fb57

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.
Files changed (87) hide show
  1. package/dist/exports/client/Field-OX545XLB.js +2 -0
  2. package/dist/exports/client/Field-OX545XLB.js.map +7 -0
  3. package/dist/exports/client/bundled.css +1 -1
  4. package/dist/exports/client/chunk-3KBZSLPR.js +12 -0
  5. package/dist/exports/client/chunk-3KBZSLPR.js.map +7 -0
  6. package/dist/exports/client/index.d.ts +1 -0
  7. package/dist/exports/client/index.d.ts.map +1 -1
  8. package/dist/exports/client/index.js +20 -20
  9. package/dist/exports/client/index.js.map +3 -3
  10. package/dist/exports/client/internal-client.d.ts +3 -0
  11. package/dist/exports/client/internal-client.d.ts.map +1 -0
  12. package/dist/exports/react/index.d.ts +1 -1
  13. package/dist/exports/react/index.d.ts.map +1 -1
  14. package/dist/exports/react/index.js.map +1 -1
  15. package/dist/features/converters/lexicalToJSX/Component/index.d.ts +2 -14
  16. package/dist/features/converters/lexicalToJSX/Component/index.d.ts.map +1 -1
  17. package/dist/features/converters/lexicalToJSX/Component/index.js +4 -2
  18. package/dist/features/converters/lexicalToJSX/Component/index.js.map +1 -1
  19. package/dist/features/converters/lexicalToJSX/converter/index.d.ts +16 -1
  20. package/dist/features/converters/lexicalToJSX/converter/index.d.ts.map +1 -1
  21. package/dist/features/converters/lexicalToJSX/converter/index.js +76 -4
  22. package/dist/features/converters/lexicalToJSX/converter/index.js.map +1 -1
  23. package/dist/features/converters/lexicalToJSX/converter/types.d.ts +14 -10
  24. package/dist/features/converters/lexicalToJSX/converter/types.d.ts.map +1 -1
  25. package/dist/features/converters/lexicalToJSX/converter/types.js.map +1 -1
  26. package/dist/features/debug/jsxConverter/client/plugin/index.js +1 -1
  27. package/dist/features/debug/jsxConverter/client/plugin/index.js.map +1 -1
  28. package/dist/field/Field.d.ts.map +1 -1
  29. package/dist/field/Field.js +11 -6
  30. package/dist/field/Field.js.map +1 -1
  31. package/dist/field/RichTextViewProvider.d.ts +83 -0
  32. package/dist/field/RichTextViewProvider.d.ts.map +1 -0
  33. package/dist/field/RichTextViewProvider.js +87 -0
  34. package/dist/field/RichTextViewProvider.js.map +1 -0
  35. package/dist/field/ViewSelector.d.ts +4 -0
  36. package/dist/field/ViewSelector.d.ts.map +1 -0
  37. package/dist/field/ViewSelector.js +89 -0
  38. package/dist/field/ViewSelector.js.map +1 -0
  39. package/dist/field/bundled.css +1 -1
  40. package/dist/field/index.d.ts +1 -0
  41. package/dist/field/index.d.ts.map +1 -1
  42. package/dist/field/index.js +47 -29
  43. package/dist/field/index.js.map +1 -1
  44. package/dist/field/rscEntry.d.ts +1 -1
  45. package/dist/field/rscEntry.d.ts.map +1 -1
  46. package/dist/field/rscEntry.js +12 -0
  47. package/dist/field/rscEntry.js.map +1 -1
  48. package/dist/index.d.ts +1 -1
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +3 -1
  51. package/dist/index.js.map +1 -1
  52. package/dist/lexical/LexicalEditor.d.ts.map +1 -1
  53. package/dist/lexical/LexicalEditor.js +2 -1
  54. package/dist/lexical/LexicalEditor.js.map +1 -1
  55. package/dist/lexical/LexicalProvider.d.ts.map +1 -1
  56. package/dist/lexical/LexicalProvider.js +12 -3
  57. package/dist/lexical/LexicalProvider.js.map +1 -1
  58. package/dist/lexical/config/client/sanitize.d.ts +1 -1
  59. package/dist/lexical/config/client/sanitize.d.ts.map +1 -1
  60. package/dist/lexical/config/client/sanitize.js +3 -2
  61. package/dist/lexical/config/client/sanitize.js.map +1 -1
  62. package/dist/lexical/config/types.d.ts +4 -0
  63. package/dist/lexical/config/types.d.ts.map +1 -1
  64. package/dist/lexical/config/types.js.map +1 -1
  65. package/dist/lexical/nodes/index.d.ts +12 -2
  66. package/dist/lexical/nodes/index.d.ts.map +1 -1
  67. package/dist/lexical/nodes/index.js +195 -2
  68. package/dist/lexical/nodes/index.js.map +1 -1
  69. package/dist/lexical/plugins/NodeViewOverridePlugin/index.d.ts +2 -0
  70. package/dist/lexical/plugins/NodeViewOverridePlugin/index.d.ts.map +1 -0
  71. package/dist/lexical/plugins/NodeViewOverridePlugin/index.js +48 -0
  72. package/dist/lexical/plugins/NodeViewOverridePlugin/index.js.map +1 -0
  73. package/dist/types.d.ts +152 -2
  74. package/dist/types.d.ts.map +1 -1
  75. package/dist/types.js.map +1 -1
  76. package/dist/utilities/generateImportMap.d.ts.map +1 -1
  77. package/dist/utilities/generateImportMap.js +1 -0
  78. package/dist/utilities/generateImportMap.js.map +1 -1
  79. package/dist/validate/hasText.d.ts +6 -1
  80. package/dist/validate/hasText.d.ts.map +1 -1
  81. package/dist/validate/hasText.js +10 -4
  82. package/dist/validate/hasText.js.map +1 -1
  83. package/package.json +11 -6
  84. package/dist/exports/client/Field-HJGV32KA.js +0 -2
  85. package/dist/exports/client/Field-HJGV32KA.js.map +0 -7
  86. package/dist/exports/client/chunk-EZX4YW7S.js +0 -12
  87. package/dist/exports/client/chunk-EZX4YW7S.js.map +0 -7
@@ -1 +1 @@
1
- {"version":3,"file":"sanitize.js","names":["deepMerge","sanitizeClientFeatures","features","sanitized","enabledFeatures","enabledFormats","markdownTransformers","nodes","plugins","providers","slashMenu","dynamicGroups","groups","toolbarFixed","toolbarInline","customGroups","forEach","feature","key","sanitizedClientFeatureProps","size","length","concat","enableFormats","push","node","plugin","i","clientProps","Component","position","group","foundGroup","find","sanitizedGroup","items","filter","optionGroup","transformer","allNodes","allTransformers","Object","keys","map","customConfig","sort","a","b","order","sanitizeClientEditorConfig","resolvedClientFeatureMap","lexical","admin","resolvedFeatureMap"],"sources":["../../../../src/lexical/config/client/sanitize.ts"],"sourcesContent":["'use client'\n\nimport type { EditorConfig as LexicalEditorConfig } from 'lexical'\n\nimport { deepMerge } from 'payload/shared'\n\nimport type { ToolbarGroup } from '../../../features/toolbars/types.js'\nimport type {\n ResolvedClientFeatureMap,\n SanitizedClientFeatures,\n} from '../../../features/typesClient.js'\nimport type { LexicalFieldAdminClientProps } from '../../../types.js'\nimport type { SanitizedClientEditorConfig } from '../types.js'\n\nexport const sanitizeClientFeatures = (\n features: ResolvedClientFeatureMap,\n): SanitizedClientFeatures => {\n const sanitized: SanitizedClientFeatures = {\n enabledFeatures: [],\n enabledFormats: [],\n markdownTransformers: [],\n nodes: [],\n plugins: [],\n providers: [],\n slashMenu: {\n dynamicGroups: [],\n groups: [],\n },\n toolbarFixed: {\n groups: [],\n },\n toolbarInline: {\n groups: [],\n },\n }\n\n // Allow customization of groups for toolbarFixed\n let customGroups: Record<string, Partial<ToolbarGroup>> = {}\n features.forEach((feature) => {\n if (feature.key === 'toolbarFixed' && feature.sanitizedClientFeatureProps?.customGroups) {\n customGroups = {\n ...customGroups,\n ...feature.sanitizedClientFeatureProps.customGroups,\n }\n }\n })\n\n if (!features?.size) {\n return sanitized\n }\n\n features.forEach((feature) => {\n if (feature.providers?.length) {\n sanitized.providers = sanitized.providers.concat(feature.providers)\n }\n\n if (feature.enableFormats?.length) {\n sanitized.enabledFormats.push(...feature.enableFormats)\n }\n\n if (feature.nodes?.length) {\n // Important: do not use concat\n for (const node of feature.nodes) {\n sanitized.nodes.push(node)\n }\n }\n if (feature.plugins?.length) {\n feature.plugins.forEach((plugin, i) => {\n sanitized.plugins?.push({\n clientProps: feature.sanitizedClientFeatureProps,\n Component: plugin.Component as any, // Appeases strict: true\n key: feature.key + i,\n position: plugin.position,\n })\n })\n }\n\n if (feature.toolbarInline?.groups?.length) {\n for (const group of feature.toolbarInline.groups) {\n // 1. find the group with the same key or create new one\n let foundGroup = sanitized.toolbarInline.groups.find(\n (sanitizedGroup) => sanitizedGroup.key === group.key,\n )\n if (!foundGroup) {\n foundGroup = {\n ...group,\n items: [],\n }\n } else {\n sanitized.toolbarInline.groups = sanitized.toolbarInline.groups.filter(\n (sanitizedGroup) => sanitizedGroup.key !== group.key,\n )\n }\n\n // 2. Add options to group options array and add to sanitized.slashMenu.groupsWithOptions\n if (group?.items?.length) {\n foundGroup.items = foundGroup.items.concat(group.items)\n }\n sanitized.toolbarInline?.groups.push(foundGroup)\n }\n }\n\n if (feature.toolbarFixed?.groups?.length) {\n for (const group of feature.toolbarFixed.groups) {\n // 1. find the group with the same key or create new one\n let foundGroup = sanitized.toolbarFixed.groups.find(\n (sanitizedGroup) => sanitizedGroup.key === group.key,\n )\n if (!foundGroup) {\n foundGroup = {\n ...group,\n items: [],\n }\n } else {\n sanitized.toolbarFixed.groups = sanitized.toolbarFixed.groups.filter(\n (sanitizedGroup) => sanitizedGroup.key !== group.key,\n )\n }\n\n // 2. Add options to group options array and add to sanitized.slashMenu.groupsWithOptions\n if (group?.items?.length) {\n foundGroup.items = foundGroup.items.concat(group.items)\n }\n sanitized.toolbarFixed?.groups.push(foundGroup)\n }\n }\n\n if (feature.slashMenu?.groups) {\n if (feature.slashMenu.dynamicGroups?.length) {\n sanitized.slashMenu.dynamicGroups = sanitized.slashMenu.dynamicGroups.concat(\n feature.slashMenu.dynamicGroups,\n )\n }\n\n for (const optionGroup of feature.slashMenu.groups) {\n // 1. find the group with the same name or create new one\n let group = sanitized.slashMenu.groups.find((group) => group.key === optionGroup.key)\n if (!group) {\n group = {\n ...optionGroup,\n items: [],\n }\n } else {\n sanitized.slashMenu.groups = sanitized.slashMenu.groups.filter(\n (group) => group.key !== optionGroup.key,\n )\n }\n\n // 2. Add options to group options array and add to sanitized.slashMenu.groupsWithOptions\n if (optionGroup?.items?.length) {\n group.items = group.items.concat(optionGroup.items)\n }\n sanitized.slashMenu.groups.push(group)\n }\n }\n\n if (feature.markdownTransformers?.length) {\n // Important: do not use concat\n for (const transformer of feature.markdownTransformers) {\n if (typeof transformer === 'function') {\n sanitized.markdownTransformers.push(\n transformer({\n allNodes: sanitized.nodes,\n allTransformers: sanitized.markdownTransformers,\n }),\n )\n } else {\n sanitized.markdownTransformers.push(transformer)\n }\n }\n }\n sanitized.enabledFeatures.push(feature.key)\n })\n\n // Apply custom group configurations to toolbarFixed groups\n if (Object.keys(customGroups).length > 0) {\n sanitized.toolbarFixed.groups = sanitized.toolbarFixed.groups.map((group) => {\n const customConfig = customGroups[group.key]\n if (customConfig) {\n return deepMerge(group, customConfig)\n }\n return group\n })\n }\n\n // Sort sanitized.toolbarInline.groups by order property\n sanitized.toolbarInline.groups.sort((a, b) => {\n if (a.order && b.order) {\n return a.order - b.order\n } else if (a.order) {\n return -1\n } else if (b.order) {\n return 1\n } else {\n return 0\n }\n })\n // Sort sanitized.toolbarFixed.groups by order property\n sanitized.toolbarFixed.groups.sort((a, b) => {\n if (a.order && b.order) {\n return a.order - b.order\n } else if (a.order) {\n return -1\n } else if (b.order) {\n return 1\n } else {\n return 0\n }\n })\n\n // Sort sanitized.toolbarInline.groups.[group].entries by order property\n for (const group of sanitized.toolbarInline.groups) {\n group.items.sort((a, b) => {\n if (a.order && b.order) {\n return a.order - b.order\n } else if (a.order) {\n return -1\n } else if (b.order) {\n return 1\n } else {\n return 0\n }\n })\n }\n\n // Sort sanitized.toolbarFixed.groups.[group].entries by order property\n for (const group of sanitized.toolbarFixed.groups) {\n group.items.sort((a, b) => {\n if (a.order && b.order) {\n return a.order - b.order\n } else if (a.order) {\n return -1\n } else if (b.order) {\n return 1\n } else {\n return 0\n }\n })\n }\n\n return sanitized\n}\n\nexport function sanitizeClientEditorConfig(\n resolvedClientFeatureMap: ResolvedClientFeatureMap,\n lexical?: LexicalEditorConfig,\n admin?: LexicalFieldAdminClientProps,\n): SanitizedClientEditorConfig {\n return {\n admin,\n features: sanitizeClientFeatures(resolvedClientFeatureMap),\n lexical: lexical!,\n resolvedFeatureMap: resolvedClientFeatureMap,\n }\n}\n"],"mappings":"AAAA;;AAIA,SAASA,SAAS,QAAQ;AAU1B,OAAO,MAAMC,sBAAA,GACXC,QAAA;EAEA,MAAMC,SAAA,GAAqC;IACzCC,eAAA,EAAiB,EAAE;IACnBC,cAAA,EAAgB,EAAE;IAClBC,oBAAA,EAAsB,EAAE;IACxBC,KAAA,EAAO,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MAC1B,OAAO,IAAIF,CAAA,CAAEE,KAAK,EAAE;QAClB,OAAO,CAAC;MACV,OAAO,IAAID,CAAA,CAAEC,KAAK,EAAE;QAClB,OAAO;MACT,OAAO;QACL,OAAO;MACT;IACF;EACF;EAEA,OAAO7C,SAAA;AACT;AAEA,OAAO,SAAS8C,2BACdC,wBAAkD,EAClDC,OAA6B,EAC7BC,KAAoC;EAEpC,OAAO;IACLA,KAAA;IACAlD,QAAA,EAAUD,sBAAA,CAAuBiD,wBAAA;IACjCC,OAAA,EAASA,OAAA;IACTE,kBAAA,EAAoBH;EACtB;AACF","ignoreList":[]}
1
+ {"version":3,"file":"sanitize.js","names":["deepMerge","sanitizeClientFeatures","features","sanitized","enabledFeatures","enabledFormats","markdownTransformers","nodes","plugins","providers","slashMenu","dynamicGroups","groups","toolbarFixed","toolbarInline","customGroups","forEach","feature","key","sanitizedClientFeatureProps","size","length","concat","enableFormats","push","node","plugin","i","clientProps","Component","position","group","foundGroup","find","sanitizedGroup","items","filter","optionGroup","transformer","allNodes","allTransformers","Object","keys","map","customConfig","sort","a","b","order","sanitizeClientEditorConfig","resolvedClientFeatureMap","lexical","admin","view","resolvedFeatureMap"],"sources":["../../../../src/lexical/config/client/sanitize.ts"],"sourcesContent":["'use client'\n\nimport type { EditorConfig as LexicalEditorConfig } from 'lexical'\n\nimport { deepMerge } from 'payload/shared'\n\nimport type { ToolbarGroup } from '../../../features/toolbars/types.js'\nimport type {\n ResolvedClientFeatureMap,\n SanitizedClientFeatures,\n} from '../../../features/typesClient.js'\nimport type { LexicalFieldAdminClientProps } from '../../../types.js'\nimport type { SanitizedClientEditorConfig } from '../types.js'\n\nexport const sanitizeClientFeatures = (\n features: ResolvedClientFeatureMap,\n): SanitizedClientFeatures => {\n const sanitized: SanitizedClientFeatures = {\n enabledFeatures: [],\n enabledFormats: [],\n markdownTransformers: [],\n nodes: [],\n plugins: [],\n providers: [],\n slashMenu: {\n dynamicGroups: [],\n groups: [],\n },\n toolbarFixed: {\n groups: [],\n },\n toolbarInline: {\n groups: [],\n },\n }\n\n // Allow customization of groups for toolbarFixed\n let customGroups: Record<string, Partial<ToolbarGroup>> = {}\n features.forEach((feature) => {\n if (feature.key === 'toolbarFixed' && feature.sanitizedClientFeatureProps?.customGroups) {\n customGroups = {\n ...customGroups,\n ...feature.sanitizedClientFeatureProps.customGroups,\n }\n }\n })\n\n if (!features?.size) {\n return sanitized\n }\n\n features.forEach((feature) => {\n if (feature.providers?.length) {\n sanitized.providers = sanitized.providers.concat(feature.providers)\n }\n\n if (feature.enableFormats?.length) {\n sanitized.enabledFormats.push(...feature.enableFormats)\n }\n\n if (feature.nodes?.length) {\n // Important: do not use concat\n for (const node of feature.nodes) {\n sanitized.nodes.push(node)\n }\n }\n if (feature.plugins?.length) {\n feature.plugins.forEach((plugin, i) => {\n sanitized.plugins?.push({\n clientProps: feature.sanitizedClientFeatureProps,\n Component: plugin.Component as any, // Appeases strict: true\n key: feature.key + i,\n position: plugin.position,\n })\n })\n }\n\n if (feature.toolbarInline?.groups?.length) {\n for (const group of feature.toolbarInline.groups) {\n // 1. find the group with the same key or create new one\n let foundGroup = sanitized.toolbarInline.groups.find(\n (sanitizedGroup) => sanitizedGroup.key === group.key,\n )\n if (!foundGroup) {\n foundGroup = {\n ...group,\n items: [],\n }\n } else {\n sanitized.toolbarInline.groups = sanitized.toolbarInline.groups.filter(\n (sanitizedGroup) => sanitizedGroup.key !== group.key,\n )\n }\n\n // 2. Add options to group options array and add to sanitized.slashMenu.groupsWithOptions\n if (group?.items?.length) {\n foundGroup.items = foundGroup.items.concat(group.items)\n }\n sanitized.toolbarInline?.groups.push(foundGroup)\n }\n }\n\n if (feature.toolbarFixed?.groups?.length) {\n for (const group of feature.toolbarFixed.groups) {\n // 1. find the group with the same key or create new one\n let foundGroup = sanitized.toolbarFixed.groups.find(\n (sanitizedGroup) => sanitizedGroup.key === group.key,\n )\n if (!foundGroup) {\n foundGroup = {\n ...group,\n items: [],\n }\n } else {\n sanitized.toolbarFixed.groups = sanitized.toolbarFixed.groups.filter(\n (sanitizedGroup) => sanitizedGroup.key !== group.key,\n )\n }\n\n // 2. Add options to group options array and add to sanitized.slashMenu.groupsWithOptions\n if (group?.items?.length) {\n foundGroup.items = foundGroup.items.concat(group.items)\n }\n sanitized.toolbarFixed?.groups.push(foundGroup)\n }\n }\n\n if (feature.slashMenu?.groups) {\n if (feature.slashMenu.dynamicGroups?.length) {\n sanitized.slashMenu.dynamicGroups = sanitized.slashMenu.dynamicGroups.concat(\n feature.slashMenu.dynamicGroups,\n )\n }\n\n for (const optionGroup of feature.slashMenu.groups) {\n // 1. find the group with the same name or create new one\n let group = sanitized.slashMenu.groups.find((group) => group.key === optionGroup.key)\n if (!group) {\n group = {\n ...optionGroup,\n items: [],\n }\n } else {\n sanitized.slashMenu.groups = sanitized.slashMenu.groups.filter(\n (group) => group.key !== optionGroup.key,\n )\n }\n\n // 2. Add options to group options array and add to sanitized.slashMenu.groupsWithOptions\n if (optionGroup?.items?.length) {\n group.items = group.items.concat(optionGroup.items)\n }\n sanitized.slashMenu.groups.push(group)\n }\n }\n\n if (feature.markdownTransformers?.length) {\n // Important: do not use concat\n for (const transformer of feature.markdownTransformers) {\n if (typeof transformer === 'function') {\n sanitized.markdownTransformers.push(\n transformer({\n allNodes: sanitized.nodes,\n allTransformers: sanitized.markdownTransformers,\n }),\n )\n } else {\n sanitized.markdownTransformers.push(transformer)\n }\n }\n }\n sanitized.enabledFeatures.push(feature.key)\n })\n\n // Apply custom group configurations to toolbarFixed groups\n if (Object.keys(customGroups).length > 0) {\n sanitized.toolbarFixed.groups = sanitized.toolbarFixed.groups.map((group) => {\n const customConfig = customGroups[group.key]\n if (customConfig) {\n return deepMerge(group, customConfig)\n }\n return group\n })\n }\n\n // Sort sanitized.toolbarInline.groups by order property\n sanitized.toolbarInline.groups.sort((a, b) => {\n if (a.order && b.order) {\n return a.order - b.order\n } else if (a.order) {\n return -1\n } else if (b.order) {\n return 1\n } else {\n return 0\n }\n })\n // Sort sanitized.toolbarFixed.groups by order property\n sanitized.toolbarFixed.groups.sort((a, b) => {\n if (a.order && b.order) {\n return a.order - b.order\n } else if (a.order) {\n return -1\n } else if (b.order) {\n return 1\n } else {\n return 0\n }\n })\n\n // Sort sanitized.toolbarInline.groups.[group].entries by order property\n for (const group of sanitized.toolbarInline.groups) {\n group.items.sort((a, b) => {\n if (a.order && b.order) {\n return a.order - b.order\n } else if (a.order) {\n return -1\n } else if (b.order) {\n return 1\n } else {\n return 0\n }\n })\n }\n\n // Sort sanitized.toolbarFixed.groups.[group].entries by order property\n for (const group of sanitized.toolbarFixed.groups) {\n group.items.sort((a, b) => {\n if (a.order && b.order) {\n return a.order - b.order\n } else if (a.order) {\n return -1\n } else if (b.order) {\n return 1\n } else {\n return 0\n }\n })\n }\n\n return sanitized\n}\n\nexport function sanitizeClientEditorConfig(\n resolvedClientFeatureMap: ResolvedClientFeatureMap,\n lexical?: LexicalEditorConfig,\n admin?: LexicalFieldAdminClientProps,\n view?: string,\n): SanitizedClientEditorConfig {\n return {\n admin,\n features: sanitizeClientFeatures(resolvedClientFeatureMap),\n lexical: lexical!,\n resolvedFeatureMap: resolvedClientFeatureMap,\n view,\n }\n}\n"],"mappings":"AAAA;;AAIA,SAASA,SAAS,QAAQ;AAU1B,OAAO,MAAMC,sBAAA,GACXC,QAAA;EAEA,MAAMC,SAAA,GAAqC;IACzCC,eAAA,EAAiB,EAAE;IACnBC,cAAA,EAAgB,EAAE;IAClBC,oBAAA,EAAsB,EAAE;IACxBC,KAAA,EAAO,EAAE;IACTC,OAAA,EAAS,EAAE;IACXC,SAAA,EAAW,EAAE;IACbC,SAAA,EAAW;MACTC,aAAA,EAAe,EAAE;MACjBC,MAAA,EAAQ;IACV;IACAC,YAAA,EAAc;MACZD,MAAA,EAAQ;IACV;IACAE,aAAA,EAAe;MACbF,MAAA,EAAQ;IACV;EACF;EAEA;EACA,IAAIG,YAAA,GAAsD,CAAC;EAC3Db,QAAA,CAASc,OAA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ACLD,KAAA;IACAlD,QAAA,EAAUD,sBAAA,CAAuBiD,wBAAA;IACjCC,OAAA,EAASA,OAAA;IACTG,kBAAA,EAAoBJ,wBAAA;IACpBG;EACF;AACF","ignoreList":[]}
@@ -20,5 +20,9 @@ export type SanitizedClientEditorConfig = {
20
20
  features: SanitizedClientFeatures;
21
21
  lexical: LexicalEditorConfig;
22
22
  resolvedFeatureMap: ResolvedClientFeatureMap;
23
+ /**
24
+ * To identify what view this editor config was created for.
25
+ */
26
+ view?: string;
23
27
  };
24
28
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lexical/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAElE,OAAO,KAAK,EACV,qBAAqB,EACrB,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,+BAA+B,CAAA;AACtC,OAAO,KAAK,EACV,qBAAqB,EACrB,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,+BAA+B,CAAA;AACtC,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAA;AAElE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,qBAAqB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,CAAA;IAChD,OAAO,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAA;CAC1C,CAAA;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,QAAQ,EAAE,uBAAuB,CAAA;IACjC,OAAO,EAAE,mBAAmB,GAAG,SAAS,CAAA;IACxC,kBAAkB,EAAE,wBAAwB,CAAA;CAC7C,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,qBAAqB,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAA;IAC3C,OAAO,CAAC,EAAE,mBAAmB,CAAA;CAC9B,C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IAC5C;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../src/lexical/config/types.ts"],"sourcesContent":["import type { EditorConfig as LexicalEditorConfig } from 'lexical'\n\nimport type {\n FeatureProviderClient,\n ResolvedClientFeatureMap,\n SanitizedClientFeatures,\n} from '../../features/typesClient.js'\nimport type {\n FeatureProviderServer,\n ResolvedServerFeatureMap,\n SanitizedServerFeatures,\n} from '../../features/typesServer.js'\nimport type { LexicalFieldAdminClientProps } from '../../types.js'\n\nexport type ServerEditorConfig = {\n features: FeatureProviderServer<any, any, any>[]\n lexical?: LexicalEditorConfig | undefined // If undefined, the default lexical editor config will be used. This can be undefined so that we do not send the default lexical editor config to the client.\n}\n\nexport type SanitizedServerEditorConfig = {\n features: SanitizedServerFeatures\n lexical: LexicalEditorConfig | undefined // If undefined, the default lexical editor config will be used. This can be undefined so that we do not send the default lexical editor config to the client.\n resolvedFeatureMap: ResolvedServerFeatureMap\n}\n\nexport type ClientEditorConfig = {\n features: FeatureProviderClient<any, any>[]\n lexical?: LexicalEditorConfig\n}\n\nexport type SanitizedClientEditorConfig = {\n admin?: LexicalFieldAdminClientProps\n features: SanitizedClientFeatures\n lexical: LexicalEditorConfig\n resolvedFeatureMap: ResolvedClientFeatureMap\n}\n"],"mappings":"AA8BA","ignoreList":[]}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../src/lexical/config/types.ts"],"sourcesContent":["import type { EditorConfig as LexicalEditorConfig } from 'lexical'\n\nimport type {\n FeatureProviderClient,\n ResolvedClientFeatureMap,\n SanitizedClientFeatures,\n} from '../../features/typesClient.js'\nimport type {\n FeatureProviderServer,\n ResolvedServerFeatureMap,\n SanitizedServerFeatures,\n} from '../../features/typesServer.js'\nimport type { LexicalFieldAdminClientProps } from '../../types.js'\n\nexport type ServerEditorConfig = {\n features: FeatureProviderServer<any, any, any>[]\n lexical?: LexicalEditorConfig | undefined // If undefined, the default lexical editor config will be used. This can be undefined so that we do not send the default lexical editor config to the client.\n}\n\nexport type SanitizedServerEditorConfig = {\n features: SanitizedServerFeatures\n lexical: LexicalEditorConfig | undefined // If undefined, the default lexical editor config will be used. This can be undefined so that we do not send the default lexical editor config to the client.\n resolvedFeatureMap: ResolvedServerFeatureMap\n}\n\nexport type ClientEditorConfig = {\n features: FeatureProviderClient<any, any>[]\n lexical?: LexicalEditorConfig\n}\n\nexport type SanitizedClientEditorConfig = {\n admin?: LexicalFieldAdminClientProps\n features: SanitizedClientFeatures\n lexical: LexicalEditorConfig\n resolvedFeatureMap: ResolvedClientFeatureMap\n /**\n * To identify what view this editor config was created for.\n */\n view?: string\n}\n"],"mappings":"AA8BA","ignoreList":[]}
@@ -1,8 +1,18 @@
1
- import type { Klass, LexicalNode, LexicalNodeReplacement } from 'lexical';
1
+ import type { Klass, LexicalEditor, LexicalNode, LexicalNodeReplacement } from 'lexical';
2
2
  import type { NodeWithHooks } from '../../features/typesServer.js';
3
+ import type { LexicalEditorNodeMap } from '../../types.js';
3
4
  import type { SanitizedClientEditorConfig, SanitizedServerEditorConfig } from '../config/types.js';
4
- export declare function getEnabledNodes({ editorConfig, }: {
5
+ /**
6
+ * Register view definitions for an editor
7
+ */
8
+ export declare function registerEditorNodeViews(editor: LexicalEditor, nodeViews: LexicalEditorNodeMap): void;
9
+ /**
10
+ * Clear all view overrides for an editor (restores default rendering)
11
+ */
12
+ export declare function clearEditorNodeViews(editor: LexicalEditor): void;
13
+ export declare function getEnabledNodes({ editorConfig, nodeViews, }: {
5
14
  editorConfig: SanitizedClientEditorConfig | SanitizedServerEditorConfig;
15
+ nodeViews?: LexicalEditorNodeMap;
6
16
  }): Array<Klass<LexicalNode> | LexicalNodeReplacement>;
7
17
  export declare function getEnabledNodesFromServerNodes({ nodes, }: {
8
18
  nodes: Array<Klass<LexicalNode> | LexicalNodeReplacement> | Array<NodeWithHooks>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lexical/nodes/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAEzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AAClE,OAAO,KAAK,EAAE,2BAA2B,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAA;AAElG,wBAAgB,eAAe,CAAC,EAC9B,YAAY,GACb,EAAE;IACD,YAAY,EAAE,2BAA2B,GAAG,2BAA2B,CAAA;CACxE,GAAG,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,sBAAsB,CAAC,CAIrD;AAED,wBAAgB,8BAA8B,CAAC,EAC7C,KAAK,GACN,EAAE;IACD,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,sBAAsB,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,CAAA;CACjF,GAAG,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,sBAAsB,CAAC,CAOrD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lexical/nodes/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,KAAK,EACL,aAAa,EACb,WAAW,EACX,sBAAsB,EACvB,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AAClE,OAAO,KAAK,EAAE,oBAAoB,EAAgB,MAAM,gBAAgB,CAAA;AACxE,OAAO,KAAK,EAAE,2BAA2B,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAA;AAMlG;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,oBAAoB,GAC9B,IAAI,CAsCN;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAEhE;AAoID,wBAAgB,eAAe,CAAC,EAC9B,YAAY,EACZ,SAAS,GACV,EAAE;IACD,YAAY,EAAE,2BAA2B,GAAG,2BAA2B,CAAA;IACvE,SAAS,CAAC,EAAE,oBAAoB,CAAA;CACjC,GAAG,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,sBAAsB,CAAC,CAyCrD;AAED,wBAAgB,8BAA8B,CAAC,EAC7C,KAAK,GACN,EAAE;IACD,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,sBAAsB,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,CAAA;CACjF,GAAG,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,sBAAsB,CAAC,CAOrD"}
@@ -1,9 +1,202 @@
1
+ import React from 'react';
2
+ // Store view definitions for each editor and node type
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ const editorNodeViews = new WeakMap();
5
+ /**
6
+ * Register view definitions for an editor
7
+ */
8
+ export function registerEditorNodeViews(editor, nodeViews) {
9
+ if (!editorNodeViews.has(editor)) {
10
+ editorNodeViews.set(editor, new Map());
11
+ }
12
+ const editorViews = editorNodeViews.get(editor);
13
+ // Register each node type's view
14
+ for (const [nodeType, value] of Object.entries(nodeViews)) {
15
+ if (!value || typeof value !== 'object') {
16
+ continue;
17
+ }
18
+ // Handle blocks specially - store each block type with key 'block:blockType'
19
+ if (nodeType === 'blocks') {
20
+ for (const [blockType, viewDef] of Object.entries(
21
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
+ value)) {
23
+ editorViews.set(`block:${blockType}`, viewDef);
24
+ }
25
+ continue;
26
+ }
27
+ // Handle inlineBlocks specially - store each block type with key 'inlineBlock:blockType'
28
+ if (nodeType === 'inlineBlocks') {
29
+ for (const [blockType, viewDef] of Object.entries(
30
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
+ value)) {
32
+ editorViews.set(`inlineBlock:${blockType}`, viewDef);
33
+ }
34
+ continue;
35
+ }
36
+ // Regular node types
37
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
+ editorViews.set(nodeType, value);
39
+ }
40
+ }
41
+ /**
42
+ * Clear all view overrides for an editor (restores default rendering)
43
+ */
44
+ export function clearEditorNodeViews(editor) {
45
+ editorNodeViews.delete(editor);
46
+ }
47
+ /**
48
+ * Get the view definition for a specific editor and node
49
+ */
50
+ function getEditorNodeView(editor, nodeType,
51
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
+ node) {
53
+ const editorViews = editorNodeViews.get(editor);
54
+ // For block nodes, look up by blockType
55
+ if (nodeType === 'block' && node?.['__fields']?.blockType) {
56
+ const blockType = node['__fields'].blockType;
57
+ return editorViews?.get(`block:${blockType}`);
58
+ }
59
+ // For inlineBlock nodes, look up by blockType
60
+ if (nodeType === 'inlineBlock' && node?.['__fields']?.blockType) {
61
+ const blockType = node['__fields'].blockType;
62
+ return editorViews?.get(`inlineBlock:${blockType}`);
63
+ }
64
+ // Regular node types
65
+ return editorViews?.get(nodeType);
66
+ }
67
+ /**
68
+ * Apply view overrides to a specific node type by modifying its prototype
69
+ * Uses WeakMap to check per-editor at runtime
70
+ */
71
+ function applyNodeOverride({
72
+ node,
73
+ nodeType
74
+ }) {
75
+ if (!('getType' in node) || node.getType() !== nodeType) {
76
+ return;
77
+ }
78
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
79
+ const NodeClass = node;
80
+ // Store original methods if not already stored
81
+ if (!NodeClass.prototype._originalDecorate) {
82
+ NodeClass.prototype._originalDecorate = NodeClass.prototype.decorate;
83
+ }
84
+ if (!NodeClass.prototype._originalCreateDOM) {
85
+ NodeClass.prototype._originalCreateDOM = NodeClass.prototype.createDOM;
86
+ }
87
+ // Override decorate method (for DecoratorNodes)
88
+ if (NodeClass.prototype.decorate && !NodeClass.prototype._decorateOverridden) {
89
+ NodeClass.prototype._decorateOverridden = true;
90
+ const hasCreateDOM = !!NodeClass.prototype.createDOM;
91
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
92
+ NodeClass.prototype.decorate = function (editor, config) {
93
+ const viewDef = getEditorNodeView(editor, nodeType, this);
94
+ if (viewDef) {
95
+ // Priority 1: If Component is provided, use it
96
+ if (viewDef.Component) {
97
+ return viewDef.Component({
98
+ config,
99
+ editor,
100
+ isEditor: true,
101
+ isJSXConverter: false,
102
+ node: this
103
+ });
104
+ }
105
+ // Priority 2: If custom createDOM is provided, use html in decorate
106
+ if (viewDef.createDOM && viewDef.html) {
107
+ const htmlContent = typeof viewDef.html === 'function' ? viewDef.html({
108
+ config,
109
+ editor,
110
+ isEditor: true,
111
+ isJSXConverter: false,
112
+ node: this
113
+ }) : viewDef.html;
114
+ return React.createElement('span', {
115
+ dangerouslySetInnerHTML: {
116
+ __html: htmlContent
117
+ }
118
+ });
119
+ }
120
+ // Priority 3: If only html is provided (no custom createDOM),
121
+ // createDOM will handle it, so decorate returns empty fragment
122
+ if (viewDef.html && hasCreateDOM && !viewDef.createDOM) {
123
+ return React.createElement(React.Fragment);
124
+ }
125
+ }
126
+ // Otherwise use original
127
+ return NodeClass.prototype._originalDecorate.call(this, editor, config);
128
+ };
129
+ }
130
+ // Override createDOM method (for ElementNodes)
131
+ if (NodeClass.prototype.createDOM && !NodeClass.prototype._createDOMOverridden) {
132
+ NodeClass.prototype._createDOMOverridden = true;
133
+ NodeClass.prototype.createDOM = function (config, editor) {
134
+ const viewDef = getEditorNodeView(editor, nodeType, this);
135
+ if (viewDef) {
136
+ // If createDOM is provided, use it
137
+ if (viewDef.createDOM) {
138
+ return viewDef.createDOM({
139
+ config,
140
+ editor,
141
+ node: this
142
+ });
143
+ }
144
+ // If html is provided (as a function or string), create element from it
145
+ if (viewDef.html) {
146
+ const htmlContent = typeof viewDef.html === 'function' ? viewDef.html({
147
+ config,
148
+ editor,
149
+ isEditor: true,
150
+ isJSXConverter: false,
151
+ node: this
152
+ }) : viewDef.html;
153
+ const tempDiv = document.createElement('div');
154
+ tempDiv.innerHTML = htmlContent;
155
+ return tempDiv.firstElementChild || tempDiv;
156
+ }
157
+ }
158
+ // Otherwise use original
159
+ return NodeClass.prototype._originalCreateDOM.call(this, config, editor);
160
+ };
161
+ }
162
+ }
1
163
  export function getEnabledNodes({
2
- editorConfig
164
+ editorConfig,
165
+ nodeViews
3
166
  }) {
4
- return getEnabledNodesFromServerNodes({
167
+ const nodes = getEnabledNodesFromServerNodes({
5
168
  nodes: editorConfig.features.nodes
6
169
  });
170
+ if (nodeViews) {
171
+ // Apply node overrides by modifying prototypes (once globally)
172
+ // The overrides check per-editor at runtime using WeakMap
173
+ const nodeTypesToOverride = new Set();
174
+ for (const [key, value] of Object.entries(nodeViews)) {
175
+ if (!value || typeof value !== 'object') {
176
+ continue;
177
+ }
178
+ // If 'blocks' key exists with content, we need to override 'block' nodes
179
+ if (key === 'blocks' && Object.keys(value).length > 0) {
180
+ nodeTypesToOverride.add('block');
181
+ } else if (key === 'inlineBlocks' && Object.keys(value).length > 0) {
182
+ nodeTypesToOverride.add('inlineBlock');
183
+ } else {
184
+ nodeTypesToOverride.add(key);
185
+ }
186
+ }
187
+ for (const node of nodes) {
188
+ if ('getType' in node) {
189
+ const nodeType = node.getType();
190
+ if (nodeTypesToOverride.has(nodeType)) {
191
+ applyNodeOverride({
192
+ node,
193
+ nodeType
194
+ });
195
+ }
196
+ }
197
+ }
198
+ }
199
+ return nodes;
7
200
  }
8
201
  export function getEnabledNodesFromServerNodes({
9
202
  nodes
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["getEnabledNodes","editorConfig","getEnabledNodesFromServerNodes","nodes","features","map","node"],"sources":["../../../src/lexical/nodes/index.ts"],"sourcesContent":["import type { Klass, LexicalNode, LexicalNodeReplacement } from 'lexical'\n\nimport type { NodeWithHooks } from '../../features/typesServer.js'\nimport type { SanitizedClientEditorConfig, SanitizedServerEditorConfig } from '../config/types.js'\n\nexport function getEnabledNodes({\n editorConfig,\n}: {\n editorConfig: SanitizedClientEditorConfig | SanitizedServerEditorConfig\n}): Array<Klass<LexicalNode> | LexicalNodeReplacement> {\n return getEnabledNodesFromServerNodes({\n nodes: editorConfig.features.nodes,\n })\n}\n\nexport function getEnabledNodesFromServerNodes({\n nodes,\n}: {\n nodes: Array<Klass<LexicalNode> | LexicalNodeReplacement> | Array<NodeWithHooks>\n}): Array<Klass<LexicalNode> | LexicalNodeReplacement> {\n return nodes.map((node) => {\n if ('node' in node) {\n return node.node\n }\n return node\n })\n}\n"],"mappings":"AAKA,OAAO,SAASA,gBAAgB;EAC9BC;AAAY,CAGb;EACC,OAAOC,8BAAA,CAA+B;IACpCC,KAAA,EAAOF,YAAA,CAAaG,QAAQ,CAACD;EAC/B;AACF;AAEA,OAAO,SAASD,+BAA+B;EAC7CC;AAAK,CAGN;EACC,OAAOA,KAAA,CAAME,GAAG,CAAEC,IAAA;IAChB,IAAI,UAAUA,IAAA,EAAM;MAClB,OAAOA,IAAA,CAAKA,IAAI;IAClB;IACA,OAAOA,IAAA;EACT;AACF","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["React","editorNodeViews","WeakMap","registerEditorNodeViews","editor","nodeViews","has","set","Map","editorViews","get","nodeType","value","Object","entries","blockType","viewDef","clearEditorNodeViews","delete","getEditorNodeView","node","applyNodeOverride","getType","NodeClass","prototype","_originalDecorate","decorate","_originalCreateDOM","createDOM","_decorateOverridden","hasCreateDOM","config","Component","isEditor","isJSXConverter","html","htmlContent","createElement","dangerouslySetInnerHTML","__html","Fragment","call","_createDOMOverridden","tempDiv","document","innerHTML","firstElementChild","getEnabledNodes","editorConfig","nodes","getEnabledNodesFromServerNodes","features","nodeTypesToOverride","Set","key","keys","length","add","map"],"sources":["../../../src/lexical/nodes/index.ts"],"sourcesContent":["import type {\n EditorConfig,\n Klass,\n LexicalEditor,\n LexicalNode,\n LexicalNodeReplacement,\n} from 'lexical'\n\nimport React from 'react'\n\nimport type { NodeWithHooks } from '../../features/typesServer.js'\nimport type { LexicalEditorNodeMap, NodeMapValue } from '../../types.js'\nimport type { SanitizedClientEditorConfig, SanitizedServerEditorConfig } from '../config/types.js'\n\n// Store view definitions for each editor and node type\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst editorNodeViews = new WeakMap<LexicalEditor, Map<string, NodeMapValue<any>>>()\n\n/**\n * Register view definitions for an editor\n */\nexport function registerEditorNodeViews(\n editor: LexicalEditor,\n nodeViews: LexicalEditorNodeMap,\n): void {\n if (!editorNodeViews.has(editor)) {\n editorNodeViews.set(editor, new Map())\n }\n const editorViews = editorNodeViews.get(editor)!\n\n // Register each node type's view\n for (const [nodeType, value] of Object.entries(nodeViews)) {\n if (!value || typeof value !== 'object') {\n continue\n }\n\n // Handle blocks specially - store each block type with key 'block:blockType'\n if (nodeType === 'blocks') {\n for (const [blockType, viewDef] of Object.entries(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n value as Record<string, NodeMapValue<any>>,\n )) {\n editorViews.set(`block:${blockType}`, viewDef)\n }\n continue\n }\n\n // Handle inlineBlocks specially - store each block type with key 'inlineBlock:blockType'\n if (nodeType === 'inlineBlocks') {\n for (const [blockType, viewDef] of Object.entries(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n value as Record<string, NodeMapValue<any>>,\n )) {\n editorViews.set(`inlineBlock:${blockType}`, viewDef)\n }\n continue\n }\n\n // Regular node types\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n editorViews.set(nodeType, value as NodeMapValue<any>)\n }\n}\n\n/**\n * Clear all view overrides for an editor (restores default rendering)\n */\nexport function clearEditorNodeViews(editor: LexicalEditor): void {\n editorNodeViews.delete(editor)\n}\n\n/**\n * Get the view definition for a specific editor and node\n */\nfunction getEditorNodeView(\n editor: LexicalEditor,\n nodeType: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n node?: any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): NodeMapValue<any> | undefined {\n const editorViews = editorNodeViews.get(editor)\n\n // For block nodes, look up by blockType\n if (nodeType === 'block' && node?.['__fields']?.blockType) {\n const blockType = node['__fields'].blockType\n return editorViews?.get(`block:${blockType}`)\n }\n\n // For inlineBlock nodes, look up by blockType\n if (nodeType === 'inlineBlock' && node?.['__fields']?.blockType) {\n const blockType = node['__fields'].blockType\n return editorViews?.get(`inlineBlock:${blockType}`)\n }\n\n // Regular node types\n return editorViews?.get(nodeType)\n}\n\n/**\n * Apply view overrides to a specific node type by modifying its prototype\n * Uses WeakMap to check per-editor at runtime\n */\nfunction applyNodeOverride({\n node,\n nodeType,\n}: {\n node: Klass<LexicalNode>\n nodeType: string\n}): void {\n if (!('getType' in node) || node.getType() !== nodeType) {\n return\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const NodeClass = node as any\n\n // Store original methods if not already stored\n if (!NodeClass.prototype._originalDecorate) {\n NodeClass.prototype._originalDecorate = NodeClass.prototype.decorate\n }\n if (!NodeClass.prototype._originalCreateDOM) {\n NodeClass.prototype._originalCreateDOM = NodeClass.prototype.createDOM\n }\n\n // Override decorate method (for DecoratorNodes)\n if (NodeClass.prototype.decorate && !NodeClass.prototype._decorateOverridden) {\n NodeClass.prototype._decorateOverridden = true\n const hasCreateDOM = !!NodeClass.prototype.createDOM\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n NodeClass.prototype.decorate = function (editor: LexicalEditor, config: EditorConfig): any {\n const viewDef = getEditorNodeView(editor, nodeType, this)\n\n if (viewDef) {\n // Priority 1: If Component is provided, use it\n if (viewDef.Component) {\n return viewDef.Component({\n config,\n editor,\n isEditor: true,\n isJSXConverter: false,\n node: this,\n })\n }\n\n // Priority 2: If custom createDOM is provided, use html in decorate\n if (viewDef.createDOM && viewDef.html) {\n const htmlContent =\n typeof viewDef.html === 'function'\n ? viewDef.html({ config, editor, isEditor: true, isJSXConverter: false, node: this })\n : viewDef.html\n return React.createElement('span', {\n dangerouslySetInnerHTML: { __html: htmlContent },\n })\n }\n\n // Priority 3: If only html is provided (no custom createDOM),\n // createDOM will handle it, so decorate returns empty fragment\n if (viewDef.html && hasCreateDOM && !viewDef.createDOM) {\n return React.createElement(React.Fragment)\n }\n }\n\n // Otherwise use original\n return NodeClass.prototype._originalDecorate.call(this, editor, config)\n }\n }\n\n // Override createDOM method (for ElementNodes)\n if (NodeClass.prototype.createDOM && !NodeClass.prototype._createDOMOverridden) {\n NodeClass.prototype._createDOMOverridden = true\n NodeClass.prototype.createDOM = function (\n config: EditorConfig,\n editor: LexicalEditor,\n ): HTMLElement {\n const viewDef = getEditorNodeView(editor, nodeType, this)\n\n if (viewDef) {\n // If createDOM is provided, use it\n if (viewDef.createDOM) {\n return viewDef.createDOM({ config, editor, node: this })\n }\n\n // If html is provided (as a function or string), create element from it\n if (viewDef.html) {\n const htmlContent =\n typeof viewDef.html === 'function'\n ? viewDef.html({ config, editor, isEditor: true, isJSXConverter: false, node: this })\n : viewDef.html\n const tempDiv = document.createElement('div')\n tempDiv.innerHTML = htmlContent\n return (tempDiv.firstElementChild as HTMLElement) || tempDiv\n }\n }\n\n // Otherwise use original\n return NodeClass.prototype._originalCreateDOM.call(this, config, editor)\n }\n }\n}\n\nexport function getEnabledNodes({\n editorConfig,\n nodeViews,\n}: {\n editorConfig: SanitizedClientEditorConfig | SanitizedServerEditorConfig\n nodeViews?: LexicalEditorNodeMap\n}): Array<Klass<LexicalNode> | LexicalNodeReplacement> {\n const nodes = getEnabledNodesFromServerNodes({\n nodes: editorConfig.features.nodes,\n })\n\n if (nodeViews) {\n // Apply node overrides by modifying prototypes (once globally)\n // The overrides check per-editor at runtime using WeakMap\n const nodeTypesToOverride = new Set<string>()\n\n for (const [key, value] of Object.entries(nodeViews)) {\n if (!value || typeof value !== 'object') {\n continue\n }\n\n // If 'blocks' key exists with content, we need to override 'block' nodes\n if (key === 'blocks' && Object.keys(value).length > 0) {\n nodeTypesToOverride.add('block')\n }\n // If 'inlineBlocks' key exists with content, we need to override 'inlineBlock' nodes\n else if (key === 'inlineBlocks' && Object.keys(value).length > 0) {\n nodeTypesToOverride.add('inlineBlock')\n }\n // Regular node types\n else {\n nodeTypesToOverride.add(key)\n }\n }\n\n for (const node of nodes) {\n if ('getType' in node) {\n const nodeType = node.getType()\n\n if (nodeTypesToOverride.has(nodeType)) {\n applyNodeOverride({ node, nodeType })\n }\n }\n }\n }\n\n return nodes\n}\n\nexport function getEnabledNodesFromServerNodes({\n nodes,\n}: {\n nodes: Array<Klass<LexicalNode> | LexicalNodeReplacement> | Array<NodeWithHooks>\n}): Array<Klass<LexicalNode> | LexicalNodeReplacement> {\n return nodes.map((node) => {\n if ('node' in node) {\n return node.node\n }\n return node\n })\n}\n"],"mappings":"AAQA,OAAOA,KAAA,MAAW;AAMlB;AACA;AACA,MAAMC,eAAA,GAAkB,IAAIC,OAAA;AAE5B;;;AAGA,OAAO,SAASC,wBACdC,MAAqB,EACrBC,SAA+B;EAE/B,IAAI,CAACJ,eAAA,CAAgBK,GAAG,CAACF,MAAA,GAAS;IAChCH,eAAA,CAAgBM,GAAG,CAACH,MAAA,EAAQ,IAAII,GAAA;EAClC;EACA,MAAMC,WAAA,GAAcR,eAAA,CAAgBS,GAAG,CAACN,MAAA;EAExC;EACA,KAAK,MAAM,CAACO,QAAA,EAAUC,KAAA,CAAM,IAAIC,MAAA,CAAOC,OAAO,CAACT,SAAA,GAAY;IACzD,IAAI,CAACO,KAAA,IAAS,OAAOA,KAAA,KAAU,UAAU;MACvC;IACF;IAEA;IACA,IAAID,QAAA,KAAa,UAAU;MACzB,KAAK,MAAM,CAACI,SAAA,EAAWC,OAAA,CAAQ,IAAIH,MAAA,CAAOC,OAAO;MAC/C;MACAF,KAAA,GACC;QACDH,WAAA,CAAYF,GAAG,CAAC,SAASQ,SAAA,EAAW,EAAEC,OAAA;MACxC;MACA;IACF;IAEA;IACA,IAAIL,QAAA,KAAa,gBAAgB;MAC/B,KAAK,MAAM,CAACI,SAAA,EAAWC,OAAA,CAAQ,IAAIH,MAAA,CAAOC,OAAO;MAC/C;MACAF,KAAA,GACC;QACDH,WAAA,CAAYF,GAAG,CAAC,eAAeQ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,CAACF;EAC/B;EAEA,IAAI5C,SAAA,EAAW;IACb;IACA;IACA,MAAM+C,mBAAA,GAAsB,IAAIC,GAAA;IAEhC,KAAK,MAAM,CAACC,GAAA,EAAK1C,KAAA,CAAM,IAAIC,MAAA,CAAOC,OAAO,CAACT,SAAA,GAAY;MACpD,IAAI,CAACO,KAAA,IAAS,OAAOA,KAAA,KAAU,UAAU;QACvC;MACF;MAEA;MACA,IAAI0C,GAAA,KAAQ,YAAYzC,MAAA,CAAO0C,IAAI,CAAC3C,KAAA,EAAO4C,MAAM,GAAG,GAAG;QACrDJ,mBAAA,CAAoBK,GAAG,CAAC;MAC1B,OAEK,IAAIH,GAAA,KAAQ,kBAAkBzC,MAAA,CAAO0C,IAAI,CAAC3C,KAAA,EAAO4C,MAAM,GAAG,GAAG;QAChEJ,mBAAA,CAAoBK,GAAG,CAAC;MAC1B,OAEK;QACHL,mBAAA,CAAoBK,GAAG,CAACH,GAAA;MAC1B;IACF;IAEA,KAAK,MAAMlC,IAAA,IAAQ6B,KAAA,EAAO;MACxB,IAAI,aAAa7B,IAAA,EAAM;QACrB,MAAMT,QAAA,GAAWS,IAAA,CAAKE,OAAO;QAE7B,IAAI8B,mBAAA,CAAoB9C,GAAG,CAACK,QAAA,GAAW;UACrCU,iBAAA,CAAkB;YAAED,IAAA;YAAMT;UAAS;QACrC;MACF;IACF;EACF;EAEA,OAAOsC,KAAA;AACT;AAEA,OAAO,SAASC,+BAA+B;EAC7CD;AAAK,CAGN;EACC,OAAOA,KAAA,CAAMS,GAAG,CAAEtC,IAAA;IAChB,IAAI,UAAUA,IAAA,EAAM;MAClB,OAAOA,IAAA,CAAKA,IAAI;IAClB;IACA,OAAOA,IAAA;EACT;AACF","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export declare function NodeViewOverridePlugin(): null;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lexical/plugins/NodeViewOverridePlugin/index.tsx"],"names":[],"mappings":"AAOA,wBAAgB,sBAAsB,IAAI,IAAI,CAsB7C"}
@@ -0,0 +1,48 @@
1
+ 'use client';
2
+
3
+ import { c as _c } from "react/compiler-runtime";
4
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js';
5
+ import { useEffect } from 'react';
6
+ import { useRichTextView } from '../../../field/RichTextViewProvider.js';
7
+ import { clearEditorNodeViews, registerEditorNodeViews } from '../../nodes/index.js';
8
+ export function NodeViewOverridePlugin() {
9
+ const $ = _c(5);
10
+ const [editor] = useLexicalComposerContext();
11
+ const {
12
+ currentView,
13
+ views
14
+ } = useRichTextView();
15
+ let t0;
16
+ let t1;
17
+ if ($[0] !== currentView || $[1] !== editor || $[2] !== views) {
18
+ t0 = () => {
19
+ if (!views) {
20
+ return;
21
+ }
22
+ if (currentView === "default") {
23
+ if (views.default) {
24
+ registerEditorNodeViews(editor, views.default?.nodes);
25
+ } else {
26
+ clearEditorNodeViews(editor);
27
+ }
28
+ } else {
29
+ if (views[currentView]) {
30
+ clearEditorNodeViews(editor);
31
+ registerEditorNodeViews(editor, views[currentView]?.nodes);
32
+ }
33
+ }
34
+ };
35
+ t1 = [editor, views, currentView];
36
+ $[0] = currentView;
37
+ $[1] = editor;
38
+ $[2] = views;
39
+ $[3] = t0;
40
+ $[4] = t1;
41
+ } else {
42
+ t0 = $[3];
43
+ t1 = $[4];
44
+ }
45
+ useEffect(t0, t1);
46
+ return null;
47
+ }
48
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","useEffect","useRichTextView","clearEditorNodeViews","registerEditorNodeViews","NodeViewOverridePlugin","$","editor","currentView","views","t0","t1","default","nodes"],"sources":["../../../../src/lexical/plugins/NodeViewOverridePlugin/index.tsx"],"sourcesContent":["'use client'\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { useEffect } from 'react'\n\nimport { useRichTextView } from '../../../field/RichTextViewProvider.js'\nimport { clearEditorNodeViews, registerEditorNodeViews } from '../../nodes/index.js'\n\nexport function NodeViewOverridePlugin(): null {\n const [editor] = useLexicalComposerContext()\n const { currentView, views } = useRichTextView()\n\n useEffect(() => {\n if (!views) {\n return\n }\n\n if (currentView === 'default') {\n if (views.default) {\n registerEditorNodeViews(editor, views.default?.nodes)\n } else {\n clearEditorNodeViews(editor)\n }\n } else if (views[currentView]) {\n clearEditorNodeViews(editor)\n registerEditorNodeViews(editor, views[currentView]?.nodes)\n }\n }, [editor, views, currentView])\n\n return null\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;AACA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,SAAS,QAAQ;AAE1B,SAASC,eAAe,QAAQ;AAChC,SAASC,oBAAoB,EAAEC,uBAAuB,QAAQ;AAE9D,OAAO,SAAAC,uBAAA;EAAA,MAAAC,CAAA,GAAAP,EAAA;EACL,OAAAQ,MAAA,IAAiBP,yBAAA;EACjB;IAAAQ,WAAA;IAAAC;EAAA,IAA+BP,eAAA;EAAA,IAAAQ,EAAA;EAAA,IAAAC,EAAA;EAAA,IAAAL,CAAA,QAAAE,WAAA,IAAAF,CAAA,QAAAC,MAAA,IAAAD,CAAA,QAAAG,KAAA;IAErBC,EAAA,GAAAA,CAAA;MAAA,KACHD,KAAA;QAAA;MAAA;MAAA,IAIDD,WAAA,KAAgB;QAAA,IACdC,KAAA,CAAAG,OAAA;UACFR,uBAAA,CAAwBG,MAAA,EAAQE,KAAA,CAAAG,OAAA,EAAAC,KAAe;QAAA;UAE/CV,oBAAA,CAAqBI,MAAA;QAAA;MAAA;QAAA,IAEdE,KAAK,CAACD,WAAA;UACfL,oBAAA,CAAqBI,MAAA;UACrBH,uBAAA,CAAwBG,MAAA,EAAQE,KAAK,CAACD,WAAA,GAAAK,KAAc;QAAA;MAAA;IAAA;IAErDF,EAAA,IAACJ,MAAA,EAAQE,KAAA,EAAOD,WAAA;IAAYF,CAAA,MAAAE,WAAA;IAAAF,CAAA,MAAAC,MAAA;IAAAD,CAAA,MAAAG,KAAA;IAAAH,CAAA,MAAAI,EAAA;IAAAJ,CAAA,MAAAK,EAAA;EAAA;IAAAD,EAAA,GAAAJ,CAAA;IAAAK,EAAA,GAAAL,CAAA;EAAA;EAf/BL,SAAA,CAAUS,EAeV,EAAGC,EAA4B;EAAA;AAAA","ignoreList":[]}
package/dist/types.d.ts CHANGED
@@ -1,8 +1,10 @@
1
- import type { EditorConfig as LexicalEditorConfig, SerializedEditorState } from 'lexical';
2
- import type { ClientField, DefaultServerCellComponentProps, LabelFunction, RichTextAdapter, RichTextField, RichTextFieldClient, RichTextFieldClientProps, SanitizedConfig, ServerFieldBase, StaticLabel } from 'payload';
1
+ import type { DecoratorNode, EditorConfig, LexicalEditor, EditorConfig as LexicalEditorConfig, LexicalNode, SerializedEditorState, SerializedLexicalNode } from 'lexical';
2
+ import type { ClientField, DefaultServerCellComponentProps, LabelFunction, PayloadComponent, RichTextAdapter, RichTextField, RichTextFieldClient, RichTextFieldClientProps, SanitizedConfig, ServerFieldBase, StaticLabel } from 'payload';
3
+ import type { JSXConverterArgs } from './features/converters/lexicalToJSX/converter/types.js';
3
4
  import type { BaseClientFeatureProps, FeatureProviderProviderClient } from './features/typesClient.js';
4
5
  import type { FeatureProviderServer } from './features/typesServer.js';
5
6
  import type { SanitizedServerEditorConfig } from './lexical/config/types.js';
7
+ import type { DefaultNodeTypes, SerializedBlockNode, SerializedInlineBlockNode } from './nodeTypes.js';
6
8
  import type { InitialLexicalFormState } from './utilities/buildInitialState.js';
7
9
  export type LexicalFieldAdminProps = {
8
10
  /**
@@ -56,10 +58,156 @@ export type FeaturesInput = (({ defaultFeatures, rootFeatures, }: {
56
58
  */
57
59
  rootFeatures: FeatureProviderServer<any, any, any>[];
58
60
  }) => FeatureProviderServer<any, any, any>[]) | FeatureProviderServer<any, any, any>[];
61
+ type WithinEditorArgs = {
62
+ config: EditorConfig;
63
+ editor: LexicalEditor;
64
+ node: LexicalNode;
65
+ };
66
+ /**
67
+ *
68
+ * @experimental - This API is experimental and may change in a minor release.
69
+ * @internal
70
+ */
71
+ export type NodeMapValue<TNode extends {
72
+ [key: string]: any;
73
+ type?: string;
74
+ } = SerializedLexicalNode> = {
75
+ /**
76
+ * Provide a react component to render the node.
77
+ *
78
+ * **JSX Converter:** Always works. Takes priority over `html`.
79
+ *
80
+ * **Lexical Editor:** Only works for DecoratorNodes (renders in `decorate` method). Takes priority over `html` and `createDOM`.
81
+ */
82
+ Component?: (args: ({
83
+ isEditor: false;
84
+ isJSXConverter: true;
85
+ } & JSXConverterArgs<TNode>) | ({
86
+ isEditor: true;
87
+ isJSXConverter: false;
88
+ node: {
89
+ _originalDecorate?: (editor: LexicalEditor, config: EditorConfig) => React.ReactNode;
90
+ } & DecoratorNode<React.ReactNode>;
91
+ } & Omit<WithinEditorArgs, 'node'>)) => React.ReactNode;
92
+ /**
93
+ * Provide a function to create the DOM element for the node.
94
+ *
95
+ * **JSX Converter:** Not used (only `Component` and `html` work).
96
+ *
97
+ * **Lexical Editor:** Always works (renders in `createDOM` method).
98
+ * - For ElementNodes: This is the standard way to customize rendering.
99
+ * - For DecoratorNodes: When combined with `html`, the DOM gets custom structure while `decorate` renders the `html` content.
100
+ */
101
+ createDOM?: (args: WithinEditorArgs) => HTMLElement;
102
+ /**
103
+ * Provide HTML string or function to render the node.
104
+ *
105
+ * **JSX Converter:** Always works (ignored if `Component` is provided).
106
+ *
107
+ * **Lexical Editor behavior depends on node type:**
108
+ *
109
+ * - **ElementNodes:** `html` is used in `createDOM` to generate the DOM structure.
110
+ *
111
+ * - **DecoratorNodes (have both `createDOM` and `decorate`):**
112
+ * - If only `html` is provided: `createDOM` uses `html` to create DOM, `decorate` returns `null`
113
+ * - If `html` + `Component`: `createDOM` uses `html`, `decorate` uses `Component`
114
+ * - If `html` + `createDOM`: Custom `createDOM` creates structure, `decorate` renders `html` content
115
+ * - If `html` + `Component` + `createDOM`: Custom `createDOM` creates structure, `decorate` uses `Component` (html ignored in editor)
116
+ */
117
+ html?: (args: ({
118
+ isEditor: false;
119
+ isJSXConverter: true;
120
+ } & JSXConverterArgs<TNode>) | ({
121
+ isEditor: true;
122
+ isJSXConverter: false;
123
+ } & WithinEditorArgs)) => string;
124
+ };
125
+ /**
126
+ * @experimental - This API is experimental and may change in a minor release.
127
+ * @internal
128
+ */
129
+ export type LexicalEditorNodeMap<TNodes extends {
130
+ [key: string]: any;
131
+ type?: string;
132
+ } = DefaultNodeTypes | SerializedBlockNode<{
133
+ blockName?: null | string;
134
+ blockType: string;
135
+ }> | SerializedInlineBlockNode<{
136
+ blockName?: null | string;
137
+ blockType: string;
138
+ }>> = {
139
+ [key: string]: {
140
+ [blockSlug: string]: NodeMapValue<any>;
141
+ } | NodeMapValue<any> | undefined;
142
+ } & {
143
+ [nodeType in Exclude<NonNullable<TNodes['type']>, 'block' | 'inlineBlock'>]?: NodeMapValue<Extract<TNodes, {
144
+ type: nodeType;
145
+ }>>;
146
+ } & {
147
+ blocks?: {
148
+ [K in Extract<Extract<TNodes, {
149
+ type: 'block';
150
+ }> extends SerializedBlockNode<infer B> ? B extends {
151
+ blockType: string;
152
+ } ? B['blockType'] : never : never, string>]?: NodeMapValue<Extract<TNodes, {
153
+ type: 'block';
154
+ }> extends SerializedBlockNode<infer B> ? SerializedBlockNode<Extract<B, {
155
+ blockType: K;
156
+ }>> : SerializedBlockNode>;
157
+ };
158
+ inlineBlocks?: {
159
+ [K in Extract<Extract<TNodes, {
160
+ type: 'inlineBlock';
161
+ }> extends SerializedInlineBlockNode<infer B> ? B extends {
162
+ blockType: string;
163
+ } ? B['blockType'] : never : never, string>]?: NodeMapValue<Extract<TNodes, {
164
+ type: 'inlineBlock';
165
+ }> extends SerializedInlineBlockNode<infer B> ? SerializedInlineBlockNode<Extract<B, {
166
+ blockType: K;
167
+ }>> : SerializedInlineBlockNode>;
168
+ };
169
+ unknown?: NodeMapValue<SerializedLexicalNode>;
170
+ };
171
+ /**
172
+ * A map of views, which can be used to render the editor in different ways.
173
+ *
174
+ * In order to override the default view, you can add a `default` key to the map.
175
+ *
176
+ * @experimental - This API is experimental and may change in a minor release.
177
+ * @internal
178
+ */
179
+ export type LexicalEditorViewMap<TNodes extends {
180
+ [key: string]: any;
181
+ type?: string;
182
+ } = DefaultNodeTypes | SerializedBlockNode<{
183
+ blockName?: null | string;
184
+ blockType: string;
185
+ }> | SerializedInlineBlockNode<{
186
+ blockName?: null | string;
187
+ blockType: string;
188
+ }>> = {
189
+ [viewKey: string]: {
190
+ admin?: LexicalFieldAdminClientProps;
191
+ lexical?: LexicalEditorConfig;
192
+ nodes: LexicalEditorNodeMap<TNodes>;
193
+ };
194
+ };
195
+ /**
196
+ * @todo rename to LexicalEditorArgs in 4.0, since these are arguments for the lexicalEditor function
197
+ */
59
198
  export type LexicalEditorProps = {
60
199
  admin?: LexicalFieldAdminProps;
61
200
  features?: FeaturesInput;
62
201
  lexical?: LexicalEditorConfig;
202
+ /**
203
+ * A path to a LexicalEditorViewMap, which can be used to render the editor in different ways.
204
+ *
205
+ * In order to override the default view, you can add a `default` key to the map.
206
+ *
207
+ * @experimental - This API is experimental and may change in a minor release.
208
+ * @internal
209
+ */
210
+ views?: PayloadComponent;
63
211
  };
64
212
  export type LexicalRichTextAdapter = {
65
213
  editorConfig: SanitizedServerEditorConfig;
@@ -96,6 +244,7 @@ export type LexicalRichTextFieldProps = {
96
244
  featureClientSchemaMap: FeatureClientSchemaMap;
97
245
  initialLexicalFormState: InitialLexicalFormState;
98
246
  lexicalEditorConfig: LexicalEditorConfig | undefined;
247
+ views?: LexicalEditorViewMap;
99
248
  } & Pick<ServerFieldBase, 'permissions'> & RichTextFieldClientProps<SerializedEditorState, AdapterProps, object>;
100
249
  export type LexicalRichTextCellProps = DefaultServerCellComponentProps<RichTextFieldClient<SerializedEditorState, AdapterProps, object>, SerializedEditorState>;
101
250
  export type AdapterProps = {
@@ -106,4 +255,5 @@ export type GeneratedFeatureProviderComponent = {
106
255
  clientFeatureProps: BaseClientFeatureProps<object>;
107
256
  };
108
257
  export type LexicalRichTextField = RichTextField<SerializedEditorState, AdapterProps>;
258
+ export {};
109
259
  //# sourceMappingURL=types.d.ts.map