@payloadcms/richtext-lexical 3.0.0-alpha.48 → 3.0.0-alpha.50

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 (109) hide show
  1. package/dist/cell/index.d.ts.map +1 -1
  2. package/dist/cell/index.js +6 -5
  3. package/dist/cell/index.js.map +1 -1
  4. package/dist/field/Field.d.ts +4 -1
  5. package/dist/field/Field.d.ts.map +1 -1
  6. package/dist/field/Field.js +22 -6
  7. package/dist/field/Field.js.map +1 -1
  8. package/dist/field/features/blocks/component/BlockContent.d.ts +4 -2
  9. package/dist/field/features/blocks/component/BlockContent.d.ts.map +1 -1
  10. package/dist/field/features/blocks/component/BlockContent.js +37 -19
  11. package/dist/field/features/blocks/component/BlockContent.js.map +1 -1
  12. package/dist/field/features/blocks/component/FormSavePlugin.d.ts.map +1 -1
  13. package/dist/field/features/blocks/component/FormSavePlugin.js +7 -2
  14. package/dist/field/features/blocks/component/FormSavePlugin.js.map +1 -1
  15. package/dist/field/features/blocks/component/index.d.ts.map +1 -1
  16. package/dist/field/features/blocks/component/index.js +19 -12
  17. package/dist/field/features/blocks/component/index.js.map +1 -1
  18. package/dist/field/features/blocks/component/removeEmptyArrayValues.d.ts +11 -0
  19. package/dist/field/features/blocks/component/removeEmptyArrayValues.d.ts.map +1 -0
  20. package/dist/field/features/blocks/component/removeEmptyArrayValues.js +16 -0
  21. package/dist/field/features/blocks/component/removeEmptyArrayValues.js.map +1 -0
  22. package/dist/field/features/blocks/drawer/index.d.ts.map +1 -1
  23. package/dist/field/features/blocks/drawer/index.js +4 -1
  24. package/dist/field/features/blocks/drawer/index.js.map +1 -1
  25. package/dist/field/features/blocks/feature.client.d.ts +1 -1
  26. package/dist/field/features/blocks/feature.client.d.ts.map +1 -1
  27. package/dist/field/features/blocks/feature.client.js.map +1 -1
  28. package/dist/field/features/blocks/feature.server.d.ts.map +1 -1
  29. package/dist/field/features/blocks/feature.server.js +32 -11
  30. package/dist/field/features/blocks/feature.server.js.map +1 -1
  31. package/dist/field/features/converters/html/field/index.d.ts +1 -1
  32. package/dist/field/features/converters/html/field/index.d.ts.map +1 -1
  33. package/dist/field/features/converters/html/field/index.js.map +1 -1
  34. package/dist/field/features/createClientComponent.d.ts +1 -2
  35. package/dist/field/features/createClientComponent.d.ts.map +1 -1
  36. package/dist/field/features/createFeaturePropComponent.d.ts.map +1 -1
  37. package/dist/field/features/createFeaturePropComponent.js +3 -2
  38. package/dist/field/features/createFeaturePropComponent.js.map +1 -1
  39. package/dist/field/features/link/drawer/index.d.ts.map +1 -1
  40. package/dist/field/features/link/drawer/index.js +20 -10
  41. package/dist/field/features/link/drawer/index.js.map +1 -1
  42. package/dist/field/features/link/plugins/autoLink/index.js +1 -1
  43. package/dist/field/features/link/plugins/autoLink/index.js.map +1 -1
  44. package/dist/field/features/link/plugins/floatingLinkEditor/LinkEditor/index.d.ts.map +1 -1
  45. package/dist/field/features/link/plugins/floatingLinkEditor/LinkEditor/index.js +4 -1
  46. package/dist/field/features/link/plugins/floatingLinkEditor/LinkEditor/index.js.map +1 -1
  47. package/dist/field/features/lists/htmlConverter.js +1 -1
  48. package/dist/field/features/lists/htmlConverter.js.map +1 -1
  49. package/dist/field/features/relationship/drawer/index.js +1 -1
  50. package/dist/field/features/relationship/drawer/index.js.map +1 -1
  51. package/dist/field/features/relationship/feature.client.js +1 -1
  52. package/dist/field/features/relationship/feature.client.js.map +1 -1
  53. package/dist/field/features/relationship/nodes/components/RelationshipComponent.d.ts.map +1 -1
  54. package/dist/field/features/relationship/nodes/components/RelationshipComponent.js +5 -1
  55. package/dist/field/features/relationship/nodes/components/RelationshipComponent.js.map +1 -1
  56. package/dist/field/features/relationship/plugins/index.d.ts.map +1 -1
  57. package/dist/field/features/relationship/plugins/index.js +2 -2
  58. package/dist/field/features/relationship/plugins/index.js.map +1 -1
  59. package/dist/field/features/relationship/utils/EnabledRelationshipsCondition.d.ts.map +1 -1
  60. package/dist/field/features/relationship/utils/EnabledRelationshipsCondition.js +8 -6
  61. package/dist/field/features/relationship/utils/EnabledRelationshipsCondition.js.map +1 -1
  62. package/dist/field/features/upload/component/ExtraFieldsDrawer/index.d.ts +2 -2
  63. package/dist/field/features/upload/component/ExtraFieldsDrawer/index.d.ts.map +1 -1
  64. package/dist/field/features/upload/component/ExtraFieldsDrawer/index.js +21 -9
  65. package/dist/field/features/upload/component/ExtraFieldsDrawer/index.js.map +1 -1
  66. package/dist/field/features/upload/component/index.d.ts.map +1 -1
  67. package/dist/field/features/upload/component/index.js +10 -3
  68. package/dist/field/features/upload/component/index.js.map +1 -1
  69. package/dist/field/features/upload/drawer/index.js +1 -1
  70. package/dist/field/features/upload/drawer/index.js.map +1 -1
  71. package/dist/field/features/upload/nodes/UploadNode.js +2 -2
  72. package/dist/field/features/upload/nodes/UploadNode.js.map +1 -1
  73. package/dist/field/features/upload/plugin/index.d.ts.map +1 -1
  74. package/dist/field/features/upload/plugin/index.js +1 -1
  75. package/dist/field/features/upload/plugin/index.js.map +1 -1
  76. package/dist/field/index.d.ts +1 -1
  77. package/dist/field/index.d.ts.map +1 -1
  78. package/dist/field/index.js +5 -5
  79. package/dist/field/index.js.map +1 -1
  80. package/dist/field/lexical/LexicalProvider.d.ts +1 -1
  81. package/dist/field/lexical/LexicalProvider.d.ts.map +1 -1
  82. package/dist/field/lexical/LexicalProvider.js.map +1 -1
  83. package/dist/field/lexical/config/client/EditorConfigProvider.d.ts +1 -1
  84. package/dist/field/lexical/config/client/EditorConfigProvider.d.ts.map +1 -1
  85. package/dist/field/lexical/config/client/EditorConfigProvider.js.map +1 -1
  86. package/dist/field/lexical/plugins/SlashMenu/index.js +1 -1
  87. package/dist/field/lexical/plugins/SlashMenu/index.js.map +1 -1
  88. package/dist/field/lexical/plugins/handles/AddBlockHandlePlugin/index.scss +1 -3
  89. package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/index.scss +1 -1
  90. package/dist/field/lexical/ui/icons/Add/index.svg +4 -4
  91. package/dist/field/lexical/ui/icons/DraggableBlock/index.svg +8 -8
  92. package/dist/generateComponentMap.d.ts.map +1 -1
  93. package/dist/generateComponentMap.js +5 -3
  94. package/dist/generateComponentMap.js.map +1 -1
  95. package/dist/generateSchemaMap.d.ts.map +1 -1
  96. package/dist/generateSchemaMap.js +2 -1
  97. package/dist/generateSchemaMap.js.map +1 -1
  98. package/dist/index.d.ts +3 -17
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +16 -21
  101. package/dist/index.js.map +1 -1
  102. package/dist/types.d.ts +12 -1
  103. package/dist/types.d.ts.map +1 -1
  104. package/dist/types.js.map +1 -1
  105. package/dist/useLexicalFeature.d.ts.map +1 -1
  106. package/dist/useLexicalFeature.js +3 -3
  107. package/dist/useLexicalFeature.js.map +1 -1
  108. package/package.json +14 -8
  109. package/src/index.ts +419 -0
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cell/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAQnF,OAAO,KAA8B,MAAM,OAAO,CAAA;AAWlD,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC;IAClC,mBAAmB,EAAE,mBAAmB,CAAA;CACzC,CA0JA,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cell/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AASnF,OAAO,KAA8B,MAAM,OAAO,CAAA;AAWlD,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC;IAClC,mBAAmB,EAAE,mBAAmB,CAAA;CACzC,CA0JA,CAAA"}
@@ -1,10 +1,11 @@
1
1
  'use client';
2
- import { createHeadlessEditor } from '@lexical/headless';
3
- import { useTableCell } from '@payloadcms/ui/elements';
4
- import { useFieldPath } from '@payloadcms/ui/forms';
5
- import { useClientFunctions } from '@payloadcms/ui/providers';
2
+ import lexicalHeadlessImport from '@lexical/headless';
3
+ const { createHeadlessEditor } = lexicalHeadlessImport;
6
4
  import lexicalImport from 'lexical';
7
5
  const { $getRoot } = lexicalImport;
6
+ import { useTableCell } from '@payloadcms/ui/elements/Table';
7
+ import { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider';
8
+ import { useClientFunctions } from '@payloadcms/ui/providers/ClientFunction';
8
9
  import React, { useEffect, useState } from 'react';
9
10
  import { defaultEditorLexicalConfig } from '../field/lexical/config/client/default.js';
10
11
  import { loadClientFeatures } from '../field/lexical/config/client/loader.js';
@@ -13,7 +14,7 @@ import { getEnabledNodes } from '../field/lexical/nodes/index.js';
13
14
  export const RichTextCell = (props)=>{
14
15
  const { lexicalEditorConfig } = props;
15
16
  const [preview, setPreview] = React.useState('Loading...');
16
- const { schemaPath } = useFieldPath();
17
+ const { schemaPath } = useFieldProps();
17
18
  const { cellData, richTextComponentMap } = useTableCell();
18
19
  const clientFunctions = useClientFunctions();
19
20
  const [hasLoadedFeatures, setHasLoadedFeatures] = useState(false);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cell/index.tsx"],"sourcesContent":["'use client'\nimport type { EditorConfig as LexicalEditorConfig } from 'lexical/LexicalEditor.js'\n\nimport { createHeadlessEditor } from '@lexical/headless'\nimport { useTableCell } from '@payloadcms/ui/elements'\nimport { useFieldPath } from '@payloadcms/ui/forms'\nimport { useClientFunctions } from '@payloadcms/ui/providers'\nimport lexicalImport from 'lexical'\nconst { $getRoot } = lexicalImport\nimport React, { useEffect, useState } from 'react'\n\nimport type { FeatureProviderClient } from '../field/features/types.js'\nimport type { SanitizedClientEditorConfig } from '../field/lexical/config/types.js'\nimport type { GeneratedFeatureProviderComponent } from '../types.js'\n\nimport { defaultEditorLexicalConfig } from '../field/lexical/config/client/default.js'\nimport { loadClientFeatures } from '../field/lexical/config/client/loader.js'\nimport { sanitizeClientEditorConfig } from '../field/lexical/config/client/sanitize.js'\nimport { getEnabledNodes } from '../field/lexical/nodes/index.js'\n\nexport const RichTextCell: React.FC<{\n lexicalEditorConfig: LexicalEditorConfig\n}> = (props) => {\n const { lexicalEditorConfig } = props\n\n const [preview, setPreview] = React.useState('Loading...')\n const { schemaPath } = useFieldPath()\n\n const { cellData, richTextComponentMap } = useTableCell()\n\n const clientFunctions = useClientFunctions()\n const [hasLoadedFeatures, setHasLoadedFeatures] = useState(false)\n\n const [featureProviders, setFeatureProviders] = useState<FeatureProviderClient<unknown>[]>([])\n\n const [finalSanitizedEditorConfig, setFinalSanitizedEditorConfig] =\n useState<SanitizedClientEditorConfig>(null)\n\n let featureProviderComponents: GeneratedFeatureProviderComponent[] = richTextComponentMap.get(\n 'features',\n ) as GeneratedFeatureProviderComponent[] // TODO: Type better\n // order by order\n featureProviderComponents = featureProviderComponents.sort((a, b) => a.order - b.order)\n\n const featureComponentsWithFeaturesLength =\n Array.from(richTextComponentMap.keys()).filter(\n (key) => key.startsWith(`feature.`) && !key.includes('.fields.'),\n ).length + featureProviderComponents.length\n\n useEffect(() => {\n if (!hasLoadedFeatures) {\n const featureProvidersLocal: FeatureProviderClient<unknown>[] = []\n let featureProvidersAndComponentsLoaded = 0\n\n Object.entries(clientFunctions).forEach(([key, plugin]) => {\n if (key.startsWith(`lexicalFeature.${schemaPath}.`)) {\n if (!key.includes('.components.')) {\n featureProvidersLocal.push(plugin)\n }\n featureProvidersAndComponentsLoaded++\n }\n })\n\n if (featureProvidersAndComponentsLoaded === featureComponentsWithFeaturesLength) {\n setFeatureProviders(featureProvidersLocal)\n setHasLoadedFeatures(true)\n\n /**\n * Loaded feature provided => create the final sanitized editor config\n */\n\n const resolvedClientFeatures = loadClientFeatures({\n clientFunctions,\n schemaPath,\n unSanitizedEditorConfig: {\n features: featureProvidersLocal,\n lexical: lexicalEditorConfig,\n },\n })\n\n setFinalSanitizedEditorConfig(\n sanitizeClientEditorConfig(\n lexicalEditorConfig ? lexicalEditorConfig : defaultEditorLexicalConfig,\n resolvedClientFeatures,\n ),\n )\n }\n }\n }, [\n hasLoadedFeatures,\n clientFunctions,\n schemaPath,\n featureProviderComponents.length,\n featureProviders,\n finalSanitizedEditorConfig,\n lexicalEditorConfig,\n featureComponentsWithFeaturesLength,\n ])\n\n useEffect(() => {\n let dataToUse = cellData\n if (dataToUse == null || !hasLoadedFeatures || !finalSanitizedEditorConfig) {\n setPreview('')\n return\n }\n\n // Transform data through load hooks\n if (finalSanitizedEditorConfig?.features?.hooks?.load?.length) {\n finalSanitizedEditorConfig.features.hooks.load.forEach((hook) => {\n dataToUse = hook({ incomingEditorState: dataToUse })\n })\n }\n\n if (!dataToUse || typeof dataToUse !== 'object') {\n setPreview('')\n return\n }\n\n // If data is from Slate and not Lexical\n if (Array.isArray(dataToUse) && !('root' in dataToUse)) {\n setPreview('')\n return\n }\n\n // If data is from payload-plugin-lexical\n if ('jsonContent' in dataToUse) {\n setPreview('')\n return\n }\n\n // initialize headless editor\n const headlessEditor = createHeadlessEditor({\n namespace: finalSanitizedEditorConfig.lexical.namespace,\n nodes: getEnabledNodes({ editorConfig: finalSanitizedEditorConfig }),\n theme: finalSanitizedEditorConfig.lexical.theme,\n })\n headlessEditor.setEditorState(headlessEditor.parseEditorState(dataToUse))\n\n const textContent =\n headlessEditor.getEditorState().read(() => {\n return $getRoot().getTextContent()\n }) || ''\n\n // Limiting the number of characters shown is done in a CSS rule\n setPreview(textContent)\n }, [cellData, lexicalEditorConfig, hasLoadedFeatures, finalSanitizedEditorConfig])\n\n if (!hasLoadedFeatures) {\n return (\n <React.Fragment>\n {Array.isArray(featureProviderComponents) &&\n featureProviderComponents.map((featureProvider) => {\n // get all components starting with key feature.${FeatureProvider.key}.components.{featureComponentKey}\n const featureComponentKeys = Array.from(richTextComponentMap.keys()).filter((key) =>\n key.startsWith(`feature.${featureProvider.key}.components.`),\n )\n const featureComponents: React.ReactNode[] = featureComponentKeys.map((key) => {\n return richTextComponentMap.get(key)\n })\n\n return (\n <React.Fragment key={featureProvider.key}>\n {featureComponents?.length\n ? featureComponents.map((FeatureComponent) => {\n return FeatureComponent\n })\n : null}\n {featureProvider.ClientComponent}\n </React.Fragment>\n )\n })}\n </React.Fragment>\n )\n }\n\n return <span>{preview}</span>\n}\n"],"names":["createHeadlessEditor","useTableCell","useFieldPath","useClientFunctions","lexicalImport","$getRoot","React","useEffect","useState","defaultEditorLexicalConfig","loadClientFeatures","sanitizeClientEditorConfig","getEnabledNodes","RichTextCell","props","lexicalEditorConfig","preview","setPreview","schemaPath","cellData","richTextComponentMap","clientFunctions","hasLoadedFeatures","setHasLoadedFeatures","featureProviders","setFeatureProviders","finalSanitizedEditorConfig","setFinalSanitizedEditorConfig","featureProviderComponents","get","sort","a","b","order","featureComponentsWithFeaturesLength","Array","from","keys","filter","key","startsWith","includes","length","featureProvidersLocal","featureProvidersAndComponentsLoaded","Object","entries","forEach","plugin","push","resolvedClientFeatures","unSanitizedEditorConfig","features","lexical","dataToUse","hooks","load","hook","incomingEditorState","isArray","headlessEditor","namespace","nodes","editorConfig","theme","setEditorState","parseEditorState","textContent","getEditorState","read","getTextContent","Fragment","map","featureProvider","featureComponentKeys","featureComponents","FeatureComponent","ClientComponent","span"],"mappings":"AAAA;AAGA,SAASA,oBAAoB,QAAQ,oBAAmB;AACxD,SAASC,YAAY,QAAQ,0BAAyB;AACtD,SAASC,YAAY,QAAQ,uBAAsB;AACnD,SAASC,kBAAkB,QAAQ,2BAA0B;AAC7D,OAAOC,mBAAmB,UAAS;AACnC,MAAM,EAAEC,QAAQ,EAAE,GAAGD;AACrB,OAAOE,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAMlD,SAASC,0BAA0B,QAAQ,4CAA2C;AACtF,SAASC,kBAAkB,QAAQ,2CAA0C;AAC7E,SAASC,0BAA0B,QAAQ,6CAA4C;AACvF,SAASC,eAAe,QAAQ,kCAAiC;AAEjE,OAAO,MAAMC,eAER,CAACC;IACJ,MAAM,EAAEC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ACE,oBAAChB,MAAMiE,QAAQ,QACZpC,MAAMwB,OAAO,CAAC/B,8BACbA,0BAA0B4C,GAAG,CAAC,CAACC;YAC7B,uGAAuG;YACvG,MAAMC,uBAAuBvC,MAAMC,IAAI,CAAChB,qBAAqBiB,IAAI,IAAIC,MAAM,CAAC,CAACC,MAC3EA,IAAIC,UAAU,CAAC,CAAC,QAAQ,EAAEiC,gBAAgBlC,GAAG,CAAC,YAAY,CAAC;YAE7D,MAAMoC,oBAAuCD,qBAAqBF,GAAG,CAAC,CAACjC;gBACrE,OAAOnB,qBAAqBS,GAAG,CAACU;YAClC;YAEA,qBACE,oBAACjC,MAAMiE,QAAQ;gBAAChC,KAAKkC,gBAAgBlC,GAAG;eACrCoC,mBAAmBjC,SAChBiC,kBAAkBH,GAAG,CAAC,CAACI;gBACrB,OAAOA;YACT,KACA,MACHH,gBAAgBI,eAAe;QAGtC;IAGR;IAEA,qBAAO,oBAACC,cAAM9D;AAChB,EAAC"}
1
+ {"version":3,"sources":["../../src/cell/index.tsx"],"sourcesContent":["'use client'\nimport type { EditorConfig as LexicalEditorConfig } from 'lexical/LexicalEditor.js'\n\nimport lexicalHeadlessImport from '@lexical/headless'\nconst { createHeadlessEditor } = lexicalHeadlessImport\nimport lexicalImport from 'lexical'\nconst { $getRoot } = lexicalImport\nimport { useTableCell } from '@payloadcms/ui/elements/Table'\nimport { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider'\nimport { useClientFunctions } from '@payloadcms/ui/providers/ClientFunction'\nimport React, { useEffect, useState } from 'react'\n\nimport type { FeatureProviderClient } from '../field/features/types.js'\nimport type { SanitizedClientEditorConfig } from '../field/lexical/config/types.js'\nimport type { GeneratedFeatureProviderComponent } from '../types.js'\n\nimport { defaultEditorLexicalConfig } from '../field/lexical/config/client/default.js'\nimport { loadClientFeatures } from '../field/lexical/config/client/loader.js'\nimport { sanitizeClientEditorConfig } from '../field/lexical/config/client/sanitize.js'\nimport { getEnabledNodes } from '../field/lexical/nodes/index.js'\n\nexport const RichTextCell: React.FC<{\n lexicalEditorConfig: LexicalEditorConfig\n}> = (props) => {\n const { lexicalEditorConfig } = props\n\n const [preview, setPreview] = React.useState('Loading...')\n const { schemaPath } = useFieldProps()\n\n const { cellData, richTextComponentMap } = useTableCell()\n\n const clientFunctions = useClientFunctions()\n const [hasLoadedFeatures, setHasLoadedFeatures] = useState(false)\n\n const [featureProviders, setFeatureProviders] = useState<FeatureProviderClient<unknown>[]>([])\n\n const [finalSanitizedEditorConfig, setFinalSanitizedEditorConfig] =\n useState<SanitizedClientEditorConfig>(null)\n\n let featureProviderComponents: GeneratedFeatureProviderComponent[] = richTextComponentMap.get(\n 'features',\n ) as GeneratedFeatureProviderComponent[] // TODO: Type better\n // order by order\n featureProviderComponents = featureProviderComponents.sort((a, b) => a.order - b.order)\n\n const featureComponentsWithFeaturesLength =\n Array.from(richTextComponentMap.keys()).filter(\n (key) => key.startsWith(`feature.`) && !key.includes('.fields.'),\n ).length + featureProviderComponents.length\n\n useEffect(() => {\n if (!hasLoadedFeatures) {\n const featureProvidersLocal: FeatureProviderClient<unknown>[] = []\n let featureProvidersAndComponentsLoaded = 0\n\n Object.entries(clientFunctions).forEach(([key, plugin]) => {\n if (key.startsWith(`lexicalFeature.${schemaPath}.`)) {\n if (!key.includes('.components.')) {\n featureProvidersLocal.push(plugin)\n }\n featureProvidersAndComponentsLoaded++\n }\n })\n\n if (featureProvidersAndComponentsLoaded === featureComponentsWithFeaturesLength) {\n setFeatureProviders(featureProvidersLocal)\n setHasLoadedFeatures(true)\n\n /**\n * Loaded feature provided => create the final sanitized editor config\n */\n\n const resolvedClientFeatures = loadClientFeatures({\n clientFunctions,\n schemaPath,\n unSanitizedEditorConfig: {\n features: featureProvidersLocal,\n lexical: lexicalEditorConfig,\n },\n })\n\n setFinalSanitizedEditorConfig(\n sanitizeClientEditorConfig(\n lexicalEditorConfig ? lexicalEditorConfig : defaultEditorLexicalConfig,\n resolvedClientFeatures,\n ),\n )\n }\n }\n }, [\n hasLoadedFeatures,\n clientFunctions,\n schemaPath,\n featureProviderComponents.length,\n featureProviders,\n finalSanitizedEditorConfig,\n lexicalEditorConfig,\n featureComponentsWithFeaturesLength,\n ])\n\n useEffect(() => {\n let dataToUse = cellData\n if (dataToUse == null || !hasLoadedFeatures || !finalSanitizedEditorConfig) {\n setPreview('')\n return\n }\n\n // Transform data through load hooks\n if (finalSanitizedEditorConfig?.features?.hooks?.load?.length) {\n finalSanitizedEditorConfig.features.hooks.load.forEach((hook) => {\n dataToUse = hook({ incomingEditorState: dataToUse })\n })\n }\n\n if (!dataToUse || typeof dataToUse !== 'object') {\n setPreview('')\n return\n }\n\n // If data is from Slate and not Lexical\n if (Array.isArray(dataToUse) && !('root' in dataToUse)) {\n setPreview('')\n return\n }\n\n // If data is from payload-plugin-lexical\n if ('jsonContent' in dataToUse) {\n setPreview('')\n return\n }\n\n // initialize headless editor\n const headlessEditor = createHeadlessEditor({\n namespace: finalSanitizedEditorConfig.lexical.namespace,\n nodes: getEnabledNodes({ editorConfig: finalSanitizedEditorConfig }),\n theme: finalSanitizedEditorConfig.lexical.theme,\n })\n headlessEditor.setEditorState(headlessEditor.parseEditorState(dataToUse))\n\n const textContent =\n headlessEditor.getEditorState().read(() => {\n return $getRoot().getTextContent()\n }) || ''\n\n // Limiting the number of characters shown is done in a CSS rule\n setPreview(textContent)\n }, [cellData, lexicalEditorConfig, hasLoadedFeatures, finalSanitizedEditorConfig])\n\n if (!hasLoadedFeatures) {\n return (\n <React.Fragment>\n {Array.isArray(featureProviderComponents) &&\n featureProviderComponents.map((featureProvider) => {\n // get all components starting with key feature.${FeatureProvider.key}.components.{featureComponentKey}\n const featureComponentKeys = Array.from(richTextComponentMap.keys()).filter((key) =>\n key.startsWith(`feature.${featureProvider.key}.components.`),\n )\n const featureComponents: React.ReactNode[] = featureComponentKeys.map((key) => {\n return richTextComponentMap.get(key)\n })\n\n return (\n <React.Fragment key={featureProvider.key}>\n {featureComponents?.length\n ? featureComponents.map((FeatureComponent) => {\n return FeatureComponent\n })\n : null}\n {featureProvider.ClientComponent}\n </React.Fragment>\n )\n })}\n </React.Fragment>\n )\n }\n\n return <span>{preview}</span>\n}\n"],"names":["lexicalHeadlessImport","createHeadlessEditor","lexicalImport","$getRoot","useTableCell","useFieldProps","useClientFunctions","React","useEffect","useState","defaultEditorLexicalConfig","loadClientFeatures","sanitizeClientEditorConfig","getEnabledNodes","RichTextCell","props","lexicalEditorConfig","preview","setPreview","schemaPath","cellData","richTextComponentMap","clientFunctions","hasLoadedFeatures","setHasLoadedFeatures","featureProviders","setFeatureProviders","finalSanitizedEditorConfig","setFinalSanitizedEditorConfig","featureProviderComponents","get","sort","a","b","order","featureComponentsWithFeaturesLength","Array","from","keys","filter","key","startsWith","includes","length","featureProvidersLocal","featureProvidersAndComponentsLoaded","Object","entries","forEach","plugin","push","resolvedClientFeatures","unSanitizedEditorConfig","features","lexical","dataToUse","hooks","load","hook","incomingEditorState","isArray","headlessEditor","namespace","nodes","editorConfig","theme","setEditorState","parseEditorState","textContent","getEditorState","read","getTextContent","Fragment","map","featureProvider","featureComponentKeys","featureComponents","FeatureComponent","ClientComponent","span"],"mappings":"AAAA;AAGA,OAAOA,2BAA2B,oBAAmB;AACrD,MAAM,EAAEC,oBAAoB,EAAE,GAAGD;AACjC,OAAOE,mBAAmB,UAAS;AACnC,MAAM,EAAEC,QAAQ,EAAE,GAAGD;AACrB,SAASE,YAAY,QAAQ,gCAA+B;AAC5D,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,kBAAkB,QAAQ,0CAAyC;AAC5E,OAAOC,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAMlD,SAASC,0BAA0B,QAAQ,4CAA2C;AACtF,SAASC,kBAAkB,QAAQ,2CAA0C;AAC7E,SAASC,0BAA0B,QAAQ,6CAA4C;AACvF,SAASC,eAAe,QAAQ,kCAAiC;AAEjE,OAAO,MAAMC,eAER,CAACC;IACJ,MAAM,EAAEC,mBAA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ChB,MAAMiE,QAAQ,QACZpC,MAAMwB,OAAO,CAAC/B,8BACbA,0BAA0B4C,GAAG,CAAC,CAACC;YAC7B,uGAAuG;YACvG,MAAMC,uBAAuBvC,MAAMC,IAAI,CAAChB,qBAAqBiB,IAAI,IAAIC,MAAM,CAAC,CAACC,MAC3EA,IAAIC,UAAU,CAAC,CAAC,QAAQ,EAAEiC,gBAAgBlC,GAAG,CAAC,YAAY,CAAC;YAE7D,MAAMoC,oBAAuCD,qBAAqBF,GAAG,CAAC,CAACjC;gBACrE,OAAOnB,qBAAqBS,GAAG,CAACU;YAClC;YAEA,qBACE,oBAACjC,MAAMiE,QAAQ;gBAAChC,KAAKkC,gBAAgBlC,GAAG;eACrCoC,mBAAmBjC,SAChBiC,kBAAkBH,GAAG,CAAC,CAACI;gBACrB,OAAOA;YACT,KACA,MACHH,gBAAgBI,eAAe;QAGtC;IAGR;IAEA,qBAAO,oBAACC,cAAM9D;AAChB,EAAC"}
@@ -1,10 +1,13 @@
1
- import { type FormFieldBase } from '@payloadcms/ui';
1
+ import type { FormFieldBase } from '@payloadcms/ui/fields/shared';
2
+ import type { FieldBase } from 'payload/types';
2
3
  import React from 'react';
3
4
  import type { SanitizedClientEditorConfig } from './lexical/config/types.js';
4
5
  import './index.scss';
5
6
  export declare const RichText: React.FC<FormFieldBase & {
6
7
  editorConfig: SanitizedClientEditorConfig;
8
+ label?: FieldBase['label'];
7
9
  name: string;
8
10
  richTextComponentMap: Map<string, React.ReactNode>;
11
+ width?: string;
9
12
  }>;
10
13
  //# sourceMappingURL=Field.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../src/field/Field.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,aAAa,EAAY,MAAM,gBAAgB,CAAA;AAC7D,OAAO,KAAsB,MAAM,OAAO,CAAA;AAG1C,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAA;AAE5E,OAAO,cAAc,CAAA;AAKrB,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAC7B,aAAa,GAAG;IACd,YAAY,EAAE,2BAA2B,CAAA;IACzC,IAAI,EAAE,MAAM,CAAA;IACZ,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,CAAA;CACnD,CAoFF,CAAA"}
1
+ {"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../src/field/Field.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAEjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAQ9C,OAAO,KAAsB,MAAM,OAAO,CAAA;AAG1C,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAA;AAE5E,OAAO,cAAc,CAAA;AA2HrB,eAAO,MAAM,QAAQ;kBApHH,2BAA2B;YACjC,SAAS,CAAC,OAAO,CAAC;UACpB,MAAM;0BACU,IAAI,MAAM,EAAE,MAAM,SAAS,CAAC;YAC1C,MAAM;EAgH8B,CAAA"}
@@ -1,12 +1,17 @@
1
1
  'use client';
2
- import { useField } from '@payloadcms/ui';
2
+ import { FieldDescription } from '@payloadcms/ui/forms/FieldDescription';
3
+ import { FieldError } from '@payloadcms/ui/forms/FieldError';
4
+ import { FieldLabel } from '@payloadcms/ui/forms/FieldLabel';
5
+ import { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider';
6
+ import { useField } from '@payloadcms/ui/forms/useField';
7
+ import { withCondition } from '@payloadcms/ui/forms/withCondition';
3
8
  import React, { useCallback } from 'react';
4
9
  import { ErrorBoundary } from 'react-error-boundary';
5
10
  import './index.scss';
6
11
  import { LexicalProvider } from './lexical/LexicalProvider.js';
7
12
  const baseClass = 'rich-text-lexical';
8
- export const RichText = (props)=>{
9
- const { name, Description, Error, Label, className, editorConfig, path: pathFromProps, readOnly, required, style, validate, width } = props;
13
+ const _RichText = (props)=>{
14
+ const { name, CustomDescription, CustomError, CustomLabel, className, descriptionProps, editorConfig, errorProps, label, labelProps, path: pathFromProps, readOnly, required, style, validate, width } = props;
10
15
  const memoizedValidate = useCallback((value, validationOptions)=>{
11
16
  if (typeof validate === 'function') {
12
17
  return validate(value, {
@@ -22,8 +27,9 @@ export const RichText = (props)=>{
22
27
  validate,
23
28
  required
24
29
  ]);
30
+ const { path: pathFromContext } = useFieldProps();
25
31
  const fieldType = useField({
26
- path: pathFromProps || name,
32
+ path: pathFromContext || pathFromProps || name,
27
33
  validate: memoizedValidate
28
34
  });
29
35
  const { errorMessage, initialValue, path, schemaPath, setValue, showError, value } = fieldType;
@@ -43,7 +49,16 @@ export const RichText = (props)=>{
43
49
  }
44
50
  }, /*#__PURE__*/ React.createElement("div", {
45
51
  className: `${baseClass}__wrap`
46
- }, Error, Label, /*#__PURE__*/ React.createElement(ErrorBoundary, {
52
+ }, /*#__PURE__*/ React.createElement(FieldError, {
53
+ CustomError: CustomError,
54
+ path: path,
55
+ ...errorProps || {}
56
+ }), /*#__PURE__*/ React.createElement(FieldLabel, {
57
+ CustomLabel: CustomLabel,
58
+ label: label,
59
+ required: required,
60
+ ...labelProps || {}
61
+ }), /*#__PURE__*/ React.createElement(ErrorBoundary, {
47
62
  fallbackRender: fallbackRender,
48
63
  onReset: ()=>{}
49
64
  }, /*#__PURE__*/ React.createElement(LexicalProvider, {
@@ -68,7 +83,7 @@ export const RichText = (props)=>{
68
83
  path: path,
69
84
  readOnly: readOnly,
70
85
  value: value
71
- })), Description));
86
+ })), CustomDescription !== undefined ? CustomDescription : /*#__PURE__*/ React.createElement(FieldDescription, descriptionProps || {})));
72
87
  };
73
88
  function fallbackRender({ error }) {
74
89
  // Call resetErrorBoundary() to reset the error boundary and retry the render.
@@ -81,5 +96,6 @@ function fallbackRender({ error }) {
81
96
  }
82
97
  }, error.message));
83
98
  }
99
+ export const RichText = withCondition(_RichText);
84
100
 
85
101
  //# sourceMappingURL=Field.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/field/Field.tsx"],"sourcesContent":["'use client'\nimport type { SerializedEditorState } from 'lexical'\n\nimport { type FormFieldBase, useField } from '@payloadcms/ui'\nimport React, { useCallback } from 'react'\nimport { ErrorBoundary } from 'react-error-boundary'\n\nimport type { SanitizedClientEditorConfig } from './lexical/config/types.js'\n\nimport './index.scss'\nimport { LexicalProvider } from './lexical/LexicalProvider.js'\n\nconst baseClass = 'rich-text-lexical'\n\nexport const RichText: React.FC<\n FormFieldBase & {\n editorConfig: SanitizedClientEditorConfig // With rendered features n stuff\n name: string\n richTextComponentMap: Map<string, React.ReactNode>\n }\n> = (props) => {\n const {\n name,\n Description,\n Error,\n Label,\n className,\n editorConfig,\n path: pathFromProps,\n readOnly,\n required,\n style,\n validate, // Users can pass in client side validation if they WANT to, but it's not required anymore\n width,\n } = props\n\n const memoizedValidate = useCallback(\n (value, validationOptions) => {\n if (typeof validate === 'function') {\n return validate(value, { ...validationOptions, props, required })\n }\n },\n // Important: do not add props to the dependencies array.\n // This would cause an infinite loop and endless re-rendering.\n // Removing props from the dependencies array fixed this issue: https://github.com/payloadcms/payload/issues/3709\n [validate, required],\n )\n\n const fieldType = useField<SerializedEditorState>({\n path: pathFromProps || name,\n validate: memoizedValidate,\n })\n\n const { errorMessage, initialValue, path, schemaPath, setValue, showError, value } = fieldType\n\n const classes = [\n baseClass,\n 'field-type',\n className,\n showError && 'error',\n readOnly && `${baseClass}--read-only`,\n ]\n .filter(Boolean)\n .join(' ')\n\n return (\n <div\n className={classes}\n key={path}\n style={{\n ...style,\n width,\n }}\n >\n <div className={`${baseClass}__wrap`}>\n {Error}\n {Label}\n <ErrorBoundary fallbackRender={fallbackRender} onReset={() => {}}>\n <LexicalProvider\n editorConfig={editorConfig}\n fieldProps={props}\n key={JSON.stringify({ initialValue, path })} // makes sure lexical is completely re-rendered when initialValue changes, bypassing the lexical-internal value memoization. That way, external changes to the form will update the editor. More infos in PR description (https://github.com/payloadcms/payload/pull/5010)\n onChange={(editorState) => {\n let serializedEditorState = editorState.toJSON()\n\n // Transform state through save hooks\n if (editorConfig?.features?.hooks?.save?.length) {\n editorConfig.features.hooks.save.forEach((hook) => {\n serializedEditorState = hook({ incomingEditorState: serializedEditorState })\n })\n }\n\n setValue(serializedEditorState)\n }}\n path={path}\n readOnly={readOnly}\n value={value}\n />\n </ErrorBoundary>\n {Description}\n </div>\n </div>\n )\n}\n\nfunction fallbackRender({ error }): React.ReactElement {\n // Call resetErrorBoundary() to reset the error boundary and retry the render.\n\n return (\n <div className=\"errorBoundary\" role=\"alert\">\n <p>Something went wrong:</p>\n <pre style={{ color: 'red' }}>{error.message}</pre>\n </div>\n )\n}\n"],"names":["useField","React","useCallback","ErrorBoundary","LexicalProvider","baseClass","RichText","props","name","Description","Error","Label","className","editorConfig","path","pathFromProps","readOnly","required","style","validate","width","memoizedValidate","value","validationOptions","fieldType","errorMessage","initialValue","schemaPath","setValue","showError","classes","filter","Boolean","join","div","key","fallbackRender","onReset","fieldProps","JSON","stringify","onChange","editorState","serializedEditorState","toJSON","features","hooks","save","length","forEach","hook","incomingEditorState","error","role","p","pre","color","message"],"mappings":"AAAA;AAGA,SAA6BA,QAAQ,QAAQ,iBAAgB;AAC7D,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAC1C,SAASC,aAAa,QAAQ,uBAAsB;AAIpD,OAAO,eAAc;AACrB,SAASC,eAAe,QAAQ,+BAA8B;AAE9D,MAAMC,YAAY;AAElB,OAAO,MAAMC,WAMT,CAACC;IACH,MAAM,EACJC,IAAI,EACJC,WAAW,EACXC,KAAK,EACLC,KAAK,EACLC,SAAS,EACTC,YAAY,EACZC,MAAMC,aAAa,EACnBC,QAAQ,EACRC,QAAQ,EACRC,KAAK,EACLC,QAAQ,EACRC,KAAK,EACN,GAAGb;IAEJ,MAAMc,mBAAmBnB,YACvB,CAACoB,OAAOC;QACN,IAAI,OAAOJ,aAAa,YAAY;YAClC,OAAOA,SAASG,OAAO;g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E,wCACH,oBAACC;QAAIrC,OAAO;YAAEsC,OAAO;QAAM;OAAIJ,MAAMK,OAAO;AAGlD"}
1
+ {"version":3,"sources":["../../src/field/Field.tsx"],"sourcesContent":["'use client'\nimport type { FormFieldBase } from '@payloadcms/ui/fields/shared'\nimport type { SerializedEditorState } from 'lexical'\nimport type { FieldBase } from 'payload/types'\n\nimport { FieldDescription } from '@payloadcms/ui/forms/FieldDescription'\nimport { FieldError } from '@payloadcms/ui/forms/FieldError'\nimport { FieldLabel } from '@payloadcms/ui/forms/FieldLabel'\nimport { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider'\nimport { useField } from '@payloadcms/ui/forms/useField'\nimport { withCondition } from '@payloadcms/ui/forms/withCondition'\nimport React, { useCallback } from 'react'\nimport { ErrorBoundary } from 'react-error-boundary'\n\nimport type { SanitizedClientEditorConfig } from './lexical/config/types.js'\n\nimport './index.scss'\nimport { LexicalProvider } from './lexical/LexicalProvider.js'\n\nconst baseClass = 'rich-text-lexical'\n\nconst _RichText: React.FC<\n FormFieldBase & {\n editorConfig: SanitizedClientEditorConfig // With rendered features n stuff\n label?: FieldBase['label']\n name: string\n richTextComponentMap: Map<string, React.ReactNode>\n width?: string\n }\n> = (props) => {\n const {\n name,\n CustomDescription,\n CustomError,\n CustomLabel,\n className,\n descriptionProps,\n editorConfig,\n errorProps,\n label,\n labelProps,\n path: pathFromProps,\n readOnly,\n required,\n style,\n validate, // Users can pass in client side validation if they WANT to, but it's not required anymore\n width,\n } = props\n\n const memoizedValidate = useCallback(\n (value, validationOptions) => {\n if (typeof validate === 'function') {\n return validate(value, { ...validationOptions, props, required })\n }\n },\n // Important: do not add props to the dependencies array.\n // This would cause an infinite loop and endless re-rendering.\n // Removing props from the dependencies array fixed this issue: https://github.com/payloadcms/payload/issues/3709\n [validate, required],\n )\n const { path: pathFromContext } = useFieldProps()\n\n const fieldType = useField<SerializedEditorState>({\n path: pathFromContext || pathFromProps || name,\n validate: memoizedValidate,\n })\n\n const { errorMessage, initialValue, path, schemaPath, setValue, showError, value } = fieldType\n\n const classes = [\n baseClass,\n 'field-type',\n className,\n showError && 'error',\n readOnly && `${baseClass}--read-only`,\n ]\n .filter(Boolean)\n .join(' ')\n\n return (\n <div\n className={classes}\n key={path}\n style={{\n ...style,\n width,\n }}\n >\n <div className={`${baseClass}__wrap`}>\n <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} />\n <FieldLabel\n CustomLabel={CustomLabel}\n label={label}\n required={required}\n {...(labelProps || {})}\n />\n <ErrorBoundary fallbackRender={fallbackRender} onReset={() => {}}>\n <LexicalProvider\n editorConfig={editorConfig}\n fieldProps={props}\n key={JSON.stringify({ initialValue, path })} // makes sure lexical is completely re-rendered when initialValue changes, bypassing the lexical-internal value memoization. That way, external changes to the form will update the editor. More infos in PR description (https://github.com/payloadcms/payload/pull/5010)\n onChange={(editorState) => {\n let serializedEditorState = editorState.toJSON()\n\n // Transform state through save hooks\n if (editorConfig?.features?.hooks?.save?.length) {\n editorConfig.features.hooks.save.forEach((hook) => {\n serializedEditorState = hook({ incomingEditorState: serializedEditorState })\n })\n }\n\n setValue(serializedEditorState)\n }}\n path={path}\n readOnly={readOnly}\n value={value}\n />\n </ErrorBoundary>\n {CustomDescription !== undefined ? (\n CustomDescription\n ) : (\n <FieldDescription {...(descriptionProps || {})} />\n )}\n </div>\n </div>\n )\n}\n\nfunction fallbackRender({ error }): React.ReactElement {\n // Call resetErrorBoundary() to reset the error boundary and retry the render.\n\n return (\n <div className=\"errorBoundary\" role=\"alert\">\n <p>Something went wrong:</p>\n <pre style={{ color: 'red' }}>{error.message}</pre>\n </div>\n )\n}\n\nexport const RichText = withCondition(_RichText)\n"],"names":["FieldDescription","FieldError","FieldLabel","useFieldProps","useField","withCondition","React","useCallback","ErrorBoundary","LexicalProvider","baseClass","_RichText","props","name","CustomDescription","CustomError","CustomLabel","className","descriptionProps","editorConfig","errorProps","label","labelProps","path","pathFromProps","readOnly","required","style","validate","width","memoizedValidate","value","validationOptions","pathFromContext","fieldType","errorMessage","initialValue","schemaPath","setValue","showError","classes","filter","Boolean","join","div","key","fallbackRender","onReset","fieldProps","JSON","stringify","onChange","editorState","serializedEditorState","toJSON","features","hooks","save","length","forEach","hook","incomingEditorState","undefined","error","role","p","pre","color","message","RichText"],"mappings":"AAAA;AAKA,SAASA,gBAAgB,QAAQ,wCAAuC;AACxE,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,UAAU,QAAQ,kCAAiC;AAC5D,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,aAAa,QAAQ,qCAAoC;AAClE,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAC1C,SAASC,aAAa,QAAQ,uBAAsB;AAIpD,OAAO,eAAc;AACrB,SAASC,eAAe,QAAQ,+BAA8B;AAE9D,MAAMC,YAAY;AAElB,MAAMC,YAQF,CAACC;IACH,MAAM,EACJC,IAAI,EACJC,iBAAiB,EACjBC,WAAW,EACXC,WAAW,EACXC,SAAS,EACTC,gBAAgB,EAChBC,YAAY,EACZC,UAAU,EACVC,KAAK,EACLC,UAAU,EACVC,MAAMC,aAAa,EACnBC,QAAQ,EACRC,QAAQ,EACRC,KAAK,EACLC,QAAQ,EACRC,KAAK,EACN,GAAGjB;IAEJ,MAAMkB,mBAAmBvB,YACvB,CAACwB,OAAOC;QACN,IAAI,OAAOJ,aAAa,YAAY;YAClC,OAAOA,SAASG,OAAO;gBAAE,GAAGC,iBAAiB;gBAAEpB;gBAAOc;YAAS;QACjE;IACF,GACA,yDAAyD;IACzD,8DAA8D;IAC9D,iHAAiH;IACjH;QAACE;QAAUF;KAAS;IAEtB,MAAM,EAAEH,MAAMU,eAAe,EAAE,GAAG9B;IAElC,MAAM+B,YAAY9B,SAAgC;QAChDmB,MAAMU,mBAAmBT,iBAAiBX;QAC1Ce,UAAUE;IACZ;IAEA,MAAM,EAAEK,YAAY,EAAEC,YAAY,EAAEb,IAAI,EAAEc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;OAAIJ,MAAMK,OAAO;AAGlD;AAEA,OAAO,MAAMC,WAAWhE,cAAcM,WAAU"}
@@ -1,5 +1,5 @@
1
- import type { FieldMap, FormFieldBase } from '@payloadcms/ui';
2
- import type { ReducedBlock } from '@payloadcms/ui/types';
1
+ import type { FormFieldBase } from '@payloadcms/ui/fields/shared';
2
+ import type { FieldMap, ReducedBlock } from '@payloadcms/ui/utilities/buildComponentMap';
3
3
  import React from 'react';
4
4
  import type { SanitizedClientEditorConfig } from '../../../lexical/config/types.js';
5
5
  import type { BlockFields } from '../nodes/BlocksNode.js';
@@ -13,7 +13,9 @@ type Props = {
13
13
  formData: BlockFields;
14
14
  formSchema: FieldMap;
15
15
  nodeKey: string;
16
+ path: string;
16
17
  reducedBlock: ReducedBlock;
18
+ schemaPath: string;
17
19
  };
18
20
  /**
19
21
  * The actual content of the Block. This should be INSIDE a Form component,
@@ -1 +1 @@
1
- {"version":3,"file":"BlockContent.d.ts","sourceRoot":"","sources":["../../../../../src/field/features/blocks/component/BlockContent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAqBxD,OAAO,KAAsB,MAAM,OAAO,CAAA;AAE1C,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAA;AACnF,OAAO,KAAK,EAAE,WAAW,EAAa,MAAM,wBAAwB,CAAA;AAIpE,KAAK,KAAK,GAAG;IACX,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,aAAa,GAAG;QACrB,YAAY,EAAE,2BAA2B,CAAA;QACzC,IAAI,EAAE,MAAM,CAAA;QACZ,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,CAAA;KACnD,CAAA;IACD,QAAQ,EAAE,WAAW,CAAA;IACrB,UAAU,EAAE,QAAQ,CAAA;IACpB,OAAO,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,YAAY,CAAA;CAC3B,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAwLxC,CAAA"}
1
+ {"version":3,"file":"BlockContent.d.ts","sourceRoot":"","sources":["../../../../../src/field/features/blocks/component/BlockContent.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAA;AAYxF,OAAO,KAAsB,MAAM,OAAO,CAAA;AAE1C,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAA;AACnF,OAAO,KAAK,EAAE,WAAW,EAAa,MAAM,wBAAwB,CAAA;AAIpE,KAAK,KAAK,GAAG;IACX,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,aAAa,GAAG;QACrB,YAAY,EAAE,2BAA2B,CAAA;QACzC,IAAI,EAAE,MAAM,CAAA;QACZ,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,CAAA;KACnD,CAAA;IACD,QAAQ,EAAE,WAAW,CAAA;IACrB,UAAU,EAAE,QAAQ,CAAA;IACpB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,YAAY,CAAA;IAC1B,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAyMxC,CAAA"}
@@ -1,11 +1,18 @@
1
1
  import lexicalComposerContextImport from '@lexical/react/LexicalComposerContext.js';
2
2
  const { useLexicalComposerContext } = lexicalComposerContextImport;
3
3
  import { getTranslation } from '@payloadcms/translations';
4
- import { RenderFields } from '@payloadcms/ui';
5
- import { Button, Collapsible, ErrorPill, Pill, SectionTitle, useDocumentInfo, useFormSubmitted, useTranslation } from '@payloadcms/ui';
6
4
  import isDeepEqual from 'deep-equal';
7
5
  import lexicalImport from 'lexical';
8
6
  const { $getNodeByKey } = lexicalImport;
7
+ import { Button } from '@payloadcms/ui/elements/Button';
8
+ import { Collapsible } from '@payloadcms/ui/elements/Collapsible';
9
+ import { ErrorPill } from '@payloadcms/ui/elements/ErrorPill';
10
+ import { Pill } from '@payloadcms/ui/elements/Pill';
11
+ import { SectionTitle } from '@payloadcms/ui/fields/Blocks/SectionTitle';
12
+ import { useFormSubmitted } from '@payloadcms/ui/forms/Form';
13
+ import { RenderFields } from '@payloadcms/ui/forms/RenderFields';
14
+ import { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';
15
+ import { useTranslation } from '@payloadcms/ui/providers/Translation';
9
16
  import React, { useCallback } from 'react';
10
17
  import { FormSavePlugin } from './FormSavePlugin.js';
11
18
  /**
@@ -13,7 +20,7 @@ import { FormSavePlugin } from './FormSavePlugin.js';
13
20
  * scoped to the block. All format operations in here are thus scoped to the block's form, and
14
21
  * not the whole document.
15
22
  */ export const BlockContent = (props)=>{
16
- const { baseClass, field, formData, formSchema, nodeKey, reducedBlock: { labels } } = props;
23
+ const { baseClass, field, formData, formSchema, nodeKey, path, reducedBlock: { labels }, schemaPath } = props;
17
24
  const { i18n } = useTranslation();
18
25
  const [editor] = useLexicalComposerContext();
19
26
  // Used for saving collapsed to preferences (and gettin' it from there again)
@@ -22,12 +29,12 @@ import { FormSavePlugin } from './FormSavePlugin.js';
22
29
  const { getDocPreferences, setDocFieldPreferences } = useDocumentInfo();
23
30
  const [collapsed, setCollapsed] = React.useState(()=>{
24
31
  let initialState = false;
25
- getDocPreferences().then((currentDocPreferences)=>{
32
+ void getDocPreferences().then((currentDocPreferences)=>{
26
33
  const currentFieldPreferences = currentDocPreferences?.fields[field.name];
27
- const collapsedMap = currentFieldPreferences?.collapsed;
28
- if (collapsedMap && collapsedMap[formData.id] !== undefined) {
29
- setCollapsed(collapsedMap[formData.id]);
30
- initialState = collapsedMap[formData.id];
34
+ const collapsedArray = currentFieldPreferences?.collapsed;
35
+ if (collapsedArray && collapsedArray.includes(formData.id)) {
36
+ initialState = true;
37
+ setCollapsed(true);
31
38
  }
32
39
  });
33
40
  return initialState;
@@ -43,7 +50,6 @@ import { FormSavePlugin } from './FormSavePlugin.js';
43
50
  newFormData = {
44
51
  ...newFormData,
45
52
  id: formData.id,
46
- blockName: newFormData.blockName2,
47
53
  blockType: formData.blockType
48
54
  };
49
55
  // Recursively remove all undefined values from even being present in formData, as they will
@@ -94,18 +100,26 @@ import { FormSavePlugin } from './FormSavePlugin.js';
94
100
  hasSubmitted,
95
101
  formData
96
102
  ]);
97
- const onCollapsedChange = useCallback(()=>{
98
- getDocPreferences().then((currentDocPreferences)=>{
103
+ const onCollapsedChange = useCallback((changedCollapsed)=>{
104
+ void getDocPreferences().then((currentDocPreferences)=>{
99
105
  const currentFieldPreferences = currentDocPreferences?.fields[field.name];
100
- const collapsedMap = currentFieldPreferences?.collapsed;
101
- const newCollapsed = collapsedMap && collapsedMap?.size ? collapsedMap : {};
102
- newCollapsed[formData.id] = !collapsed;
106
+ const collapsedArray = currentFieldPreferences?.collapsed;
107
+ const newCollapsed = collapsedArray && collapsedArray?.length ? collapsedArray : [];
108
+ if (changedCollapsed) {
109
+ if (!newCollapsed.includes(formData.id)) {
110
+ newCollapsed.push(formData.id);
111
+ }
112
+ } else {
113
+ if (newCollapsed.includes(formData.id)) {
114
+ newCollapsed.splice(newCollapsed.indexOf(formData.id), 1);
115
+ }
116
+ }
103
117
  setDocFieldPreferences(field.name, {
104
- collapsed: newCollapsed
118
+ collapsed: newCollapsed,
119
+ hello: 'hi'
105
120
  });
106
121
  });
107
122
  }, [
108
- collapsed,
109
123
  getDocPreferences,
110
124
  field.name,
111
125
  setDocFieldPreferences,
@@ -129,7 +143,7 @@ import { FormSavePlugin } from './FormSavePlugin.js';
129
143
  className: `${baseClass}__block-pill ${baseClass}__block-pill-${formData?.blockType}`,
130
144
  pillStyle: "white"
131
145
  }, typeof labels.singular === 'string' ? getTranslation(labels.singular, i18n) : '[Singular Label]'), /*#__PURE__*/ React.createElement(SectionTitle, {
132
- path: "blockName2",
146
+ path: "blockName",
133
147
  readOnly: field?.readOnly
134
148
  }), fieldHasErrors && /*#__PURE__*/ React.createElement(ErrorPill, {
135
149
  count: errorCount,
@@ -149,14 +163,18 @@ import { FormSavePlugin } from './FormSavePlugin.js';
149
163
  })),
150
164
  key: 0,
151
165
  onToggle: (collapsed)=>{
166
+ onCollapsedChange(collapsed);
152
167
  setCollapsed(collapsed);
153
- onCollapsedChange();
154
168
  }
155
169
  }, /*#__PURE__*/ React.createElement(RenderFields, {
156
170
  className: `${baseClass}__fields`,
157
171
  fieldMap: Array.isArray(formSchema) ? formSchema : [],
158
172
  forceRender: true,
159
- margins: "small"
173
+ margins: "small",
174
+ path: "" // Leaving path empty makes it so field values are not prefixed / scoped by the entire schemaPath. e.g. we can access "myField" instead of "someLexicalField.feature.blocks.someArrayB" // TODO: Could there be any implications leaving path different than schemaPath?
175
+ ,
176
+ readOnly: false,
177
+ schemaPath: schemaPath
160
178
  })), /*#__PURE__*/ React.createElement(FormSavePlugin, {
161
179
  onChange: onFormChange
162
180
  }));
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/field/features/blocks/component/BlockContent.tsx"],"sourcesContent":["import type { FieldMap, FormFieldBase } from '@payloadcms/ui'\nimport type { ReducedBlock } from '@payloadcms/ui/types'\nimport type { FormState } from 'payload/types'\nimport type { Data } from 'payload/types'\n\nimport lexicalComposerContextImport from '@lexical/react/LexicalComposerContext.js'\nconst { useLexicalComposerContext } = lexicalComposerContextImport\nimport { getTranslation } from '@payloadcms/translations'\nimport { RenderFields } from '@payloadcms/ui'\nimport {\n Button,\n Collapsible,\n ErrorPill,\n Pill,\n SectionTitle,\n useDocumentInfo,\n useFormSubmitted,\n useTranslation,\n} from '@payloadcms/ui'\nimport isDeepEqual from 'deep-equal'\nimport lexicalImport from 'lexical'\nconst { $getNodeByKey } = lexicalImport\nimport React, { useCallback } from 'react'\n\nimport type { SanitizedClientEditorConfig } from '../../../lexical/config/types.js'\nimport type { BlockFields, BlockNode } from '../nodes/BlocksNode.js'\n\nimport { FormSavePlugin } from './FormSavePlugin.js'\n\ntype Props = {\n baseClass: string\n field: FormFieldBase & {\n editorConfig: SanitizedClientEditorConfig // With rendered features n stuff\n name: string\n richTextComponentMap: Map<string, React.ReactNode>\n }\n formData: BlockFields\n formSchema: FieldMap\n nodeKey: string\n reducedBlock: ReducedBlock\n}\n\n/**\n * The actual content of the Block. This should be INSIDE a Form component,\n * scoped to the block. All format operations in here are thus scoped to the block's form, and\n * not the whole document.\n */\nexport const BlockContent: React.FC<Props> = (props) => {\n const {\n baseClass,\n field,\n formData,\n formSchema,\n nodeKey,\n reducedBlock: { labels },\n } = props\n\n const { i18n } = useTranslation()\n const [editor] = useLexicalComposerContext()\n // Used for saving collapsed to preferences (and gettin' it from there again)\n // Remember, these preferences are scoped to the whole document, not just this form. This\n // is important to consider for the data path used in setDocFieldPreferences\n const { getDocPreferences, setDocFieldPreferences } = useDocumentInfo()\n\n const [collapsed, setCollapsed] = React.useState<boolean>(() => {\n let initialState = false\n\n getDocPreferences().then((currentDocPreferences) => {\n const currentFieldPreferences = currentDocPreferences?.fields[field.name]\n\n const collapsedMap: { [key: string]: boolean } = currentFieldPreferences?.collapsed\n\n if (collapsedMap && collapsedMap[formData.id] !== undefined) {\n setCollapsed(collapsedMap[formData.id])\n initialState = collapsedMap[formData.id]\n }\n })\n return initialState\n })\n const hasSubmitted = useFormSubmitted()\n\n const [errorCount, setErrorCount] = React.useState(0)\n\n const fieldHasErrors = hasSubmitted && errorCount > 0\n\n const classNames = [\n `${baseClass}__row`,\n fieldHasErrors ? `${baseClass}__row--has-errors` : `${baseClass}__row--no-errors`,\n ]\n .filter(Boolean)\n .join(' ')\n\n const onFormChange = useCallback(\n ({\n fullFieldsWithValues,\n newFormData,\n }: {\n fullFieldsWithValues: FormState\n newFormData: Data\n }) => {\n newFormData = {\n ...newFormData,\n id: formData.id,\n blockName: newFormData.blockName2, // TODO: Find a better solution for this. We have to wrap it in blockName2 when using it here, as blockName does not accept or provide any updated values for some reason.\n blockType: formData.blockType,\n }\n\n // Recursively remove all undefined values from even being present in formData, as they will\n // cause isDeepEqual to return false if, for example, formData has a key that fields.data\n // does not have, even if it's undefined.\n // Currently, this happens if a block has another sub-blocks field. Inside formData, that sub-blocks field has an undefined blockName property.\n // Inside of fields.data however, that sub-blocks blockName property does not exist at all.\n function removeUndefinedAndNullRecursively(obj: object) {\n Object.keys(obj).forEach((key) => {\n if (obj[key] && typeof obj[key] === 'object') {\n removeUndefinedAndNullRecursively(obj[key])\n } else if (obj[key] === undefined || obj[key] === null) {\n delete obj[key]\n }\n })\n }\n removeUndefinedAndNullRecursively(newFormData)\n removeUndefinedAndNullRecursively(formData)\n\n // Only update if the data has actually changed. Otherwise, we may be triggering an unnecessary value change,\n // which would trigger the \"Leave without saving\" dialog unnecessarily\n if (!isDeepEqual(formData, newFormData)) {\n // Running this in the next tick in the meantime fixes this issue: https://github.com/payloadcms/payload/issues/4108\n // I don't know why. When this is called immediately, it might focus out of a nested lexical editor field if an update is made there.\n // My hypothesis is that the nested editor might not have fully finished its update cycle yet. By updating in the next tick, we\n // ensure that the nested editor has finished its update cycle before we update the block node.\n setTimeout(() => {\n editor.update(() => {\n const node: BlockNode = $getNodeByKey(nodeKey)\n if (node) {\n node.setFields(newFormData as BlockFields)\n }\n })\n }, 0)\n }\n\n // update error count\n if (hasSubmitted) {\n let rowErrorCount = 0\n for (const formField of Object.values(fullFieldsWithValues)) {\n if (formField?.valid === false) {\n rowErrorCount++\n }\n }\n setErrorCount(rowErrorCount)\n }\n },\n [editor, nodeKey, hasSubmitted, formData],\n )\n\n const onCollapsedChange = useCallback(() => {\n getDocPreferences().then((currentDocPreferences) => {\n const currentFieldPreferences = currentDocPreferences?.fields[field.name]\n\n const collapsedMap: { [key: string]: boolean } = currentFieldPreferences?.collapsed\n\n const newCollapsed: { [key: string]: boolean } =\n collapsedMap && collapsedMap?.size ? collapsedMap : {}\n\n newCollapsed[formData.id] = !collapsed\n\n setDocFieldPreferences(field.name, {\n collapsed: newCollapsed,\n })\n })\n }, [collapsed, getDocPreferences, field.name, setDocFieldPreferences, formData.id])\n\n const removeBlock = useCallback(() => {\n editor.update(() => {\n $getNodeByKey(nodeKey).remove()\n })\n }, [editor, nodeKey])\n\n return (\n <React.Fragment>\n <Collapsible\n className={classNames}\n collapsed={collapsed}\n collapsibleStyle={fieldHasErrors ? 'error' : 'default'}\n header={\n <div className={`${baseClass}__block-header`}>\n <div>\n <Pill\n className={`${baseClass}__block-pill ${baseClass}__block-pill-${formData?.blockType}`}\n pillStyle=\"white\"\n >\n {typeof labels.singular === 'string'\n ? getTranslation(labels.singular, i18n)\n : '[Singular Label]'}\n </Pill>\n <SectionTitle path=\"blockName2\" readOnly={field?.readOnly} />\n {fieldHasErrors && <ErrorPill count={errorCount} i18n={i18n} withMessage />}\n </div>\n {editor.isEditable() && (\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={field?.readOnly}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeBlock()\n }}\n round\n tooltip=\"Remove Block\"\n />\n )}\n </div>\n }\n key={0}\n onToggle={(collapsed) => {\n setCollapsed(collapsed)\n onCollapsedChange()\n }}\n >\n <RenderFields\n className={`${baseClass}__fields`}\n fieldMap={Array.isArray(formSchema) ? formSchema : []}\n forceRender\n margins=\"small\"\n />\n </Collapsible>\n\n <FormSavePlugin onChange={onFormChange} />\n </React.Fragment>\n )\n}\n"],"names":["lexicalComposerContextImport","useLexicalComposerContext","getTranslation","RenderFields","Button","Collapsible","ErrorPill","Pill","SectionTitle","useDocumentInfo","useFormSubmitted","useTranslation","isDeepEqual","lexicalImport","$getNodeByKey","React","useCallback","FormSavePlugin","BlockContent","props","baseClass","field","formData","formSchema","nodeKey","reducedBlock","labels","i18n","editor","getDocPreferences","setDocFieldPreferences","collapsed","setCollapsed","useState","initialState","then","currentDocPreferences","currentFieldPreferences","fields","name","collapsedMap","id","undefined","hasSubmitted","errorCount","setErrorCount","fieldHasErrors","classNames","filter","Boolean","join","onFormChange","fullFieldsWithValues","newFormData","blockName","blockName2","blockType","removeUndefinedAndNullRecursively","obj","Object","keys","forEach","key","setTimeout","update","node","setFields","rowErrorCount","formField","values","valid","onCollapsedChange","newCollapsed","size","removeBlock","remove","Fragment","className","collapsibleStyle","header","div","pillStyle","singular","path","readOnly","count","withMessage","isEditable","buttonStyle","disabled","icon","onClick","e","preventDefault","round","tooltip","onToggle","fieldMap","Array","isArray","forceRender","margins","onChange"],"mappings":"AAKA,OAAOA,kCAAkC,2CAA0C;AACnF,MAAM,EAAEC,yBAAyB,EAAE,GAAGD;AACtC,SAASE,cAAc,QAAQ,2BAA0B;AACzD,SAASC,YAAY,QAAQ,iBAAgB;AAC7C,SACEC,MAAM,EACNC,WAAW,EACXC,SAAS,EACTC,IAAI,EACJC,YAAY,EACZC,eAAe,EACfC,gBAAgB,EAChBC,cAAc,QACT,iBAAgB;AACvB,OAAOC,iBAAiB,aAAY;AACpC,OAAOC,mBAAmB,UAAS;AACnC,MAAM,EAAEC,aAAa,EAAE,GAAGD;AAC1B,OAAOE,SAASC,WAAW,QAAQ,QAAO;AAK1C,SAASC,cAAc,QAAQ,sBAAqB;AAepD;;;;CAIC,GACD,OAAO,MAAMC,eAAgC,CAACC;IAC5C,MAAM,EACJC,SAAS,EACTC,KAAK,EACLC,QAAQ,EACRC,UAAU,EACVC,OAAO,EACPC,cAAc,EAAEC,MAAM,EAAE,EACzB,GAAGP;IAEJ,MAAM,EAAEQ,IAAI,EAAE,GAAGhB;IACjB,MAAM,CAACiB,OAAO,GAAG3B;IACjB,6EAA6E;IAC7E,yFAAyF;IACzF,4EAA4E;IAC5E,MAAM,EAAE4B,iBAAiB,EA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EpB,qBACE,oBAACT,MAAM6D,QAAQ,sBACb,oBAACvE;QACCwE,WAAW9B;QACXhB,WAAWA;QACX+C,kBAAkBhC,iBAAiB,UAAU;QAC7CiC,sBACE,oBAACC;YAAIH,WAAW,CAAC,EAAEzD,UAAU,cAAc,CAAC;yBAC1C,oBAAC4D,2BACC,oBAACzE;YACCsE,WAAW,CAAC,EAAEzD,UAAU,aAAa,EAAEA,UAAU,aAAa,EAAEE,UAAUkC,UAAU,CAAC;YACrFyB,WAAU;WAET,OAAOvD,OAAOwD,QAAQ,KAAK,WACxBhF,eAAewB,OAAOwD,QAAQ,EAAEvD,QAChC,mCAEN,oBAACnB;YAAa2E,MAAK;YAAaC,UAAU/D,OAAO+D;YAChDtC,gCAAkB,oBAACxC;YAAU+E,OAAOzC;YAAYjB,MAAMA;YAAM2D,aAAAA;aAE9D1D,OAAO2D,UAAU,oBAChB,oBAACnF;YACCoF,aAAY;YACZX,WAAW,CAAC,EAAEzD,UAAU,cAAc,CAAC;YACvCqE,UAAUpE,OAAO+D;YACjBM,MAAK;YACLC,SAAS,CAACC;gBACRA,EAAEC,cAAc;gBAChBnB;YACF;YACAoB,OAAAA;YACAC,SAAQ;;QAKhBjC,KAAK;QACLkC,UAAU,CAACjE;YACTC,aAAaD;YACbwC;QACF;qBAEA,oBAACpE;QACC0E,WAAW,CAAC,EAAEzD,UAAU,QAAQ,CAAC;QACjC6E,UAAUC,MAAMC,OAAO,CAAC5E,cAAcA,aAAa,EAAE;QACrD6E,aAAAA;QACAC,SAAQ;uBAIZ,oBAACpF;QAAeqF,UAAUnD;;AAGhC,EAAC"}
1
+ {"version":3,"sources":["../../../../../src/field/features/blocks/component/BlockContent.tsx"],"sourcesContent":["import type { FormState } from 'payload/types'\nimport type { Data } from 'payload/types'\n\nimport lexicalComposerContextImport from '@lexical/react/LexicalComposerContext.js'\nconst { useLexicalComposerContext } = lexicalComposerContextImport\nimport { getTranslation } from '@payloadcms/translations'\nimport isDeepEqual from 'deep-equal'\nimport lexicalImport from 'lexical'\nconst { $getNodeByKey } = lexicalImport\nimport type { FormFieldBase } from '@payloadcms/ui/fields/shared'\nimport type { FieldMap, ReducedBlock } from '@payloadcms/ui/utilities/buildComponentMap'\nimport type { CollapsedPreferences } from 'payload/types'\n\nimport { Button } from '@payloadcms/ui/elements/Button'\nimport { Collapsible } from '@payloadcms/ui/elements/Collapsible'\nimport { ErrorPill } from '@payloadcms/ui/elements/ErrorPill'\nimport { Pill } from '@payloadcms/ui/elements/Pill'\nimport { SectionTitle } from '@payloadcms/ui/fields/Blocks/SectionTitle'\nimport { useFormSubmitted } from '@payloadcms/ui/forms/Form'\nimport { RenderFields } from '@payloadcms/ui/forms/RenderFields'\nimport { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo'\nimport { useTranslation } from '@payloadcms/ui/providers/Translation'\nimport React, { useCallback } from 'react'\n\nimport type { SanitizedClientEditorConfig } from '../../../lexical/config/types.js'\nimport type { BlockFields, BlockNode } from '../nodes/BlocksNode.js'\n\nimport { FormSavePlugin } from './FormSavePlugin.js'\n\ntype Props = {\n baseClass: string\n field: FormFieldBase & {\n editorConfig: SanitizedClientEditorConfig // With rendered features n stuff\n name: string\n richTextComponentMap: Map<string, React.ReactNode>\n }\n formData: BlockFields\n formSchema: FieldMap\n nodeKey: string\n path: string\n reducedBlock: ReducedBlock\n schemaPath: string\n}\n\n/**\n * The actual content of the Block. This should be INSIDE a Form component,\n * scoped to the block. All format operations in here are thus scoped to the block's form, and\n * not the whole document.\n */\nexport const BlockContent: React.FC<Props> = (props) => {\n const {\n baseClass,\n field,\n formData,\n formSchema,\n nodeKey,\n path,\n reducedBlock: { labels },\n schemaPath,\n } = props\n\n const { i18n } = useTranslation()\n const [editor] = useLexicalComposerContext()\n // Used for saving collapsed to preferences (and gettin' it from there again)\n // Remember, these preferences are scoped to the whole document, not just this form. This\n // is important to consider for the data path used in setDocFieldPreferences\n const { getDocPreferences, setDocFieldPreferences } = useDocumentInfo()\n\n const [collapsed, setCollapsed] = React.useState<boolean>(() => {\n let initialState = false\n\n void getDocPreferences().then((currentDocPreferences) => {\n const currentFieldPreferences = currentDocPreferences?.fields[field.name]\n\n const collapsedArray = currentFieldPreferences?.collapsed\n\n if (collapsedArray && collapsedArray.includes(formData.id)) {\n initialState = true\n setCollapsed(true)\n }\n })\n return initialState\n })\n\n const hasSubmitted = useFormSubmitted()\n\n const [errorCount, setErrorCount] = React.useState(0)\n\n const fieldHasErrors = hasSubmitted && errorCount > 0\n\n const classNames = [\n `${baseClass}__row`,\n fieldHasErrors ? `${baseClass}__row--has-errors` : `${baseClass}__row--no-errors`,\n ]\n .filter(Boolean)\n .join(' ')\n\n const onFormChange = useCallback(\n ({\n fullFieldsWithValues,\n newFormData,\n }: {\n fullFieldsWithValues: FormState\n newFormData: Data\n }) => {\n newFormData = {\n ...newFormData,\n id: formData.id,\n blockType: formData.blockType,\n }\n\n // Recursively remove all undefined values from even being present in formData, as they will\n // cause isDeepEqual to return false if, for example, formData has a key that fields.data\n // does not have, even if it's undefined.\n // Currently, this happens if a block has another sub-blocks field. Inside formData, that sub-blocks field has an undefined blockName property.\n // Inside of fields.data however, that sub-blocks blockName property does not exist at all.\n function removeUndefinedAndNullRecursively(obj: object) {\n Object.keys(obj).forEach((key) => {\n if (obj[key] && typeof obj[key] === 'object') {\n removeUndefinedAndNullRecursively(obj[key])\n } else if (obj[key] === undefined || obj[key] === null) {\n delete obj[key]\n }\n })\n }\n removeUndefinedAndNullRecursively(newFormData)\n removeUndefinedAndNullRecursively(formData)\n\n // Only update if the data has actually changed. Otherwise, we may be triggering an unnecessary value change,\n // which would trigger the \"Leave without saving\" dialog unnecessarily\n if (!isDeepEqual(formData, newFormData)) {\n // Running this in the next tick in the meantime fixes this issue: https://github.com/payloadcms/payload/issues/4108\n // I don't know why. When this is called immediately, it might focus out of a nested lexical editor field if an update is made there.\n // My hypothesis is that the nested editor might not have fully finished its update cycle yet. By updating in the next tick, we\n // ensure that the nested editor has finished its update cycle before we update the block node.\n setTimeout(() => {\n editor.update(() => {\n const node: BlockNode = $getNodeByKey(nodeKey)\n if (node) {\n node.setFields(newFormData as BlockFields)\n }\n })\n }, 0)\n }\n\n // update error count\n if (hasSubmitted) {\n let rowErrorCount = 0\n for (const formField of Object.values(fullFieldsWithValues)) {\n if (formField?.valid === false) {\n rowErrorCount++\n }\n }\n setErrorCount(rowErrorCount)\n }\n },\n [editor, nodeKey, hasSubmitted, formData],\n )\n\n const onCollapsedChange = useCallback(\n (changedCollapsed: boolean) => {\n void getDocPreferences().then((currentDocPreferences) => {\n const currentFieldPreferences = currentDocPreferences?.fields[field.name]\n\n const collapsedArray = currentFieldPreferences?.collapsed\n\n const newCollapsed: CollapsedPreferences =\n collapsedArray && collapsedArray?.length ? collapsedArray : []\n\n if (changedCollapsed) {\n if (!newCollapsed.includes(formData.id)) {\n newCollapsed.push(formData.id)\n }\n } else {\n if (newCollapsed.includes(formData.id)) {\n newCollapsed.splice(newCollapsed.indexOf(formData.id), 1)\n }\n }\n\n setDocFieldPreferences(field.name, {\n collapsed: newCollapsed,\n hello: 'hi',\n })\n })\n },\n [getDocPreferences, field.name, setDocFieldPreferences, formData.id],\n )\n\n const removeBlock = useCallback(() => {\n editor.update(() => {\n $getNodeByKey(nodeKey).remove()\n })\n }, [editor, nodeKey])\n\n return (\n <React.Fragment>\n <Collapsible\n className={classNames}\n collapsed={collapsed}\n collapsibleStyle={fieldHasErrors ? 'error' : 'default'}\n header={\n <div className={`${baseClass}__block-header`}>\n <div>\n <Pill\n className={`${baseClass}__block-pill ${baseClass}__block-pill-${formData?.blockType}`}\n pillStyle=\"white\"\n >\n {typeof labels.singular === 'string'\n ? getTranslation(labels.singular, i18n)\n : '[Singular Label]'}\n </Pill>\n <SectionTitle path=\"blockName\" readOnly={field?.readOnly} />\n {fieldHasErrors && <ErrorPill count={errorCount} i18n={i18n} withMessage />}\n </div>\n {editor.isEditable() && (\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={field?.readOnly}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeBlock()\n }}\n round\n tooltip=\"Remove Block\"\n />\n )}\n </div>\n }\n key={0}\n onToggle={(collapsed) => {\n onCollapsedChange(collapsed)\n setCollapsed(collapsed)\n }}\n >\n <RenderFields\n className={`${baseClass}__fields`}\n fieldMap={Array.isArray(formSchema) ? formSchema : []}\n forceRender\n margins=\"small\"\n path=\"\" // Leaving path empty makes it so field values are not prefixed / scoped by the entire schemaPath. e.g. we can access \"myField\" instead of \"someLexicalField.feature.blocks.someArrayB\" // TODO: Could there be any implications leaving path different than schemaPath?\n readOnly={false}\n schemaPath={schemaPath} // Having the correct schemaPath here allows sub-fields (like array > addRow) to run correct form-state calls and retrieve their needed form state from the server\n />\n </Collapsible>\n\n <FormSavePlugin onChange={onFormChange} />\n </React.Fragment>\n )\n}\n"],"names":["lexicalComposerContextImport","useLexicalComposerContext","getTranslation","isDeepEqual","lexicalImport","$getNodeByKey","Button","Collapsible","ErrorPill","Pill","SectionTitle","useFormSubmitted","RenderFields","useDocumentInfo","useTranslation","React","useCallback","FormSavePlugin","BlockContent","props","baseClass","field","formData","formSchema","nodeKey","path","reducedBlock","labels","schemaPath","i18n","editor","getDocPreferences","setDocFieldPreferences","collapsed","setCollapsed","useState","initialState","then","currentDocPreferences","currentFieldPreferences","fields","name","collapsedArray","includes","id","hasSubmitted","errorCount","setErrorCount","fieldHasErrors","classNames","filter","Boolean","join","onFormChange","fullFieldsWithValues","newFormData","blockType","removeUndefinedAndNullRecursively","obj","Object","keys","forEach","key","undefined","setTimeout","update","node","setFields","rowErrorCount","formField","values","valid","onCollapsedChange","changedCollapsed","newCollapsed","length","push","splice","indexOf","hello","removeBlock","remove","Fragment","className","collapsibleStyle","header","div","pillStyle","singular","readOnly","count","withMessage","isEditable","buttonStyle","disabled","icon","onClick","e","preventDefault","round","tooltip","onToggle","fieldMap","Array","isArray","forceRender","margins","onChange"],"mappings":"AAGA,OAAOA,kCAAk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,cAAc,CAAC;yBAC1C,oBAACkE,2BACC,oBAAC7E;YACC0E,WAAW,CAAC,EAAE/D,UAAU,aAAa,EAAEA,UAAU,aAAa,EAAEE,UAAUkC,UAAU,CAAC;YACrF+B,WAAU;WAET,OAAO5D,OAAO6D,QAAQ,KAAK,WACxBtF,eAAeyB,OAAO6D,QAAQ,EAAE3D,QAChC,mCAEN,oBAACnB;YAAae,MAAK;YAAYgE,UAAUpE,OAAOoE;YAC/CzC,gCAAkB,oBAACxC;YAAUkF,OAAO5C;YAAYjB,MAAMA;YAAM8D,aAAAA;aAE9D7D,OAAO8D,UAAU,oBAChB,oBAACtF;YACCuF,aAAY;YACZV,WAAW,CAAC,EAAE/D,UAAU,cAAc,CAAC;YACvC0E,UAAUzE,OAAOoE;YACjBM,MAAK;YACLC,SAAS,CAACC;gBACRA,EAAEC,cAAc;gBAChBlB;YACF;YACAmB,OAAAA;YACAC,SAAQ;;QAKhBtC,KAAK;QACLuC,UAAU,CAACpE;YACTuC,kBAAkBvC;YAClBC,aAAaD;QACf;qBAEA,oBAACrB;QACCuE,WAAW,CAAC,EAAE/D,UAAU,QAAQ,CAAC;QACjCkF,UAAUC,MAAMC,OAAO,CAACjF,cAAcA,aAAa,EAAE;QACrDkF,aAAAA;QACAC,SAAQ;QACRjF,MAAK,GAAG,wQAAwQ;;QAChRgE,UAAU;QACV7D,YAAYA;uBAIhB,oBAACX;QAAe0F,UAAUtD;;AAGhC,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"FormSavePlugin.d.ts","sourceRoot":"","sources":["../../../../../src/field/features/blocks/component/FormSavePlugin.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAK9B,KAAK,KAAK,GAAG;IACX,QAAQ,CAAC,EAAE,CAAC,EACV,oBAAoB,EACpB,WAAW,GACZ,EAAE;QACD,oBAAoB,EAAE,SAAS,CAAA;QAC/B,WAAW,EAAE,IAAI,CAAA;KAClB,KAAK,IAAI,CAAA;CACX,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAgB1C,CAAA"}
1
+ {"version":3,"file":"FormSavePlugin.d.ts","sourceRoot":"","sources":["../../../../../src/field/features/blocks/component/FormSavePlugin.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAQ9B,KAAK,KAAK,GAAG;IACX,QAAQ,CAAC,EAAE,CAAC,EACV,oBAAoB,EACpB,WAAW,GACZ,EAAE;QACD,oBAAoB,EAAE,SAAS,CAAA;QAC/B,WAAW,EAAE,IAAI,CAAA;KAClB,KAAK,IAAI,CAAA;CACX,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAkB1C,CAAA"}
@@ -1,8 +1,13 @@
1
- import { reduceFieldsToValues, useAllFormFields } from '@payloadcms/ui';
1
+ import { useAllFormFields } from '@payloadcms/ui/forms/Form';
2
+ import { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues';
2
3
  import { useEffect } from 'react';
4
+ import { removeEmptyArrayValues } from './removeEmptyArrayValues.js';
3
5
  export const FormSavePlugin = (props)=>{
4
6
  const { onChange } = props;
5
- const [fields, dispatchFields] = useAllFormFields();
7
+ const [_fields] = useAllFormFields();
8
+ const fields = removeEmptyArrayValues({
9
+ fields: _fields
10
+ });
6
11
  // Pass in fields, and indicate if you'd like to "unflatten" field data.
7
12
  // The result below will reflect the data stored in the form at the given time
8
13
  const newFormData = reduceFieldsToValues(fields, true);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/field/features/blocks/component/FormSavePlugin.tsx"],"sourcesContent":["import type { FormState } from 'payload/types'\nimport type { Data } from 'payload/types'\nimport type React from 'react'\n\nimport { reduceFieldsToValues, useAllFormFields } from '@payloadcms/ui'\nimport { useEffect } from 'react'\n\ntype Props = {\n onChange?: ({\n fullFieldsWithValues,\n newFormData,\n }: {\n fullFieldsWithValues: FormState\n newFormData: Data\n }) => void\n}\n\nexport const FormSavePlugin: React.FC<Props> = (props) => {\n const { onChange } = props\n\n const [fields, dispatchFields] = useAllFormFields()\n\n // Pass in fields, and indicate if you'd like to \"unflatten\" field data.\n // The result below will reflect the data stored in the form at the given time\n const newFormData = reduceFieldsToValues(fields, true)\n\n useEffect(() => {\n if (onChange) {\n onChange({ fullFieldsWithValues: fields, newFormData })\n }\n }, [newFormData, onChange, fields])\n\n return null\n}\n"],"names":["reduceFieldsToValues","useAllFormFields","useEffect","FormSavePlugin","props","onChange","fields","dispatchFields","newFormData","fullFieldsWithValues"],"mappings":"AAIA,SAASA,oBAAoB,EAAEC,gBAAgB,QAAQ,iBAAgB;AACvE,SAASC,SAAS,QAAQ,QAAO;AAYjC,OAAO,MAAMC,iBAAkC,CAACC;IAC9C,MAAM,EAAEC,QAAQ,EAAE,GAAGD;IAErB,MAAM,CAACE,QAAQC,eAAe,GAAGN;IAEjC,wEAAwE;IACxE,8EAA8E;IAC9E,MAAMO,cAAcR,qBAAqBM,QAAQ;IAEjDJ,UAAU;QACR,IAAIG,UAAU;YACZA,SAAS;gBAAEI,sBAAsBH;gBAAQE;YAAY;QACvD;IACF,GAAG;QAACA;QAAaH;QAAUC;KAAO;IAElC,OAAO;AACT,EAAC"}
1
+ {"version":3,"sources":["../../../../../src/field/features/blocks/component/FormSavePlugin.tsx"],"sourcesContent":["import type { FormState } from 'payload/types'\nimport type { Data } from 'payload/types'\nimport type React from 'react'\n\nimport { useAllFormFields } from '@payloadcms/ui/forms/Form'\nimport { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues'\nimport { useEffect } from 'react'\n\nimport { removeEmptyArrayValues } from './removeEmptyArrayValues.js'\n\ntype Props = {\n onChange?: ({\n fullFieldsWithValues,\n newFormData,\n }: {\n fullFieldsWithValues: FormState\n newFormData: Data\n }) => void\n}\n\nexport const FormSavePlugin: React.FC<Props> = (props) => {\n const { onChange } = props\n\n const [_fields] = useAllFormFields()\n\n const fields = removeEmptyArrayValues({ fields: _fields })\n\n // Pass in fields, and indicate if you'd like to \"unflatten\" field data.\n // The result below will reflect the data stored in the form at the given time\n const newFormData = reduceFieldsToValues(fields, true)\n\n useEffect(() => {\n if (onChange) {\n onChange({ fullFieldsWithValues: fields, newFormData })\n }\n }, [newFormData, onChange, fields])\n\n return null\n}\n"],"names":["useAllFormFields","reduceFieldsToValues","useEffect","removeEmptyArrayValues","FormSavePlugin","props","onChange","_fields","fields","newFormData","fullFieldsWithValues"],"mappings":"AAIA,SAASA,gBAAgB,QAAQ,4BAA2B;AAC5D,SAASC,oBAAoB,QAAQ,gDAA+C;AACpF,SAASC,SAAS,QAAQ,QAAO;AAEjC,SAASC,sBAAsB,QAAQ,8BAA6B;AAYpE,OAAO,MAAMC,iBAAkC,CAACC;IAC9C,MAAM,EAAEC,QAAQ,EAAE,GAAGD;IAErB,MAAM,CAACE,QAAQ,GAAGP;IAElB,MAAMQ,SAASL,uBAAuB;QAAEK,QAAQD;IAAQ;IAExD,wEAAwE;IACxE,8EAA8E;IAC9E,MAAME,cAAcR,qBAAqBO,QAAQ;IAEjDN,UAAU;QACR,IAAII,UAAU;YACZA,SAAS;gBAAEI,sBAAsBF;gBAAQC;YAAY;QACvD;IACF,GAAG;QAACA;QAAaH;QAAUE;KAAO;IAElC,OAAO;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/features/blocks/component/index.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAoD,MAAM,OAAO,CAAA;AAExE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAazD,OAAO,cAAc,CAAA;AAErB,KAAK,KAAK,GAAG;IACX,qBAAqB,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAE1B,QAAQ,EAAE,WAAW,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,mBAAmB,EAAE,WAAW,CAAA;CACjC,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAuH1C,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/features/blocks/component/index.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAoD,MAAM,OAAO,CAAA;AAExE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAkBzD,OAAO,cAAc,CAAA;AAGrB,KAAK,KAAK,GAAG;IACX,qBAAqB,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAE1B,QAAQ,EAAE,WAAW,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,mBAAmB,EAAE,WAAW,CAAA;CACjC,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAuH1C,CAAA"}
@@ -1,17 +1,23 @@
1
1
  'use client';
2
- import { FieldPathProvider, Form, getFormState, useConfig, useDocumentInfo, useFieldPath, useFormSubmitted } from '@payloadcms/ui';
2
+ import { Form } from '@payloadcms/ui/forms/Form';
3
3
  import React, { useCallback, useEffect, useMemo, useState } from 'react';
4
4
  const baseClass = 'lexical-block';
5
+ import { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider';
6
+ import { useFormSubmitted } from '@payloadcms/ui/forms/Form';
7
+ import { useConfig } from '@payloadcms/ui/providers/Config';
8
+ import { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';
9
+ import { getFormState } from '@payloadcms/ui/utilities/getFormState';
5
10
  import { v4 as uuid } from 'uuid';
6
11
  import { useEditorConfigContext } from '../../../lexical/config/client/EditorConfigProvider.js';
7
12
  import { BlockContent } from './BlockContent.js';
8
13
  import './index.scss';
14
+ import { removeEmptyArrayValues } from './removeEmptyArrayValues.js';
9
15
  export const BlockComponent = (props)=>{
10
16
  const { blockFieldWrapperName, formData, nodeKey } = props;
11
17
  const config = useConfig();
12
18
  const submitted = useFormSubmitted();
13
19
  const { id } = useDocumentInfo();
14
- const { schemaPath } = useFieldPath();
20
+ const { path, schemaPath } = useFieldProps();
15
21
  const { editorConfig, field: parentLexicalRichTextField } = useEditorConfigContext();
16
22
  const [initialState, setInitialState] = useState(false);
17
23
  const { field: { richTextComponentMap } } = useEditorConfigContext();
@@ -35,8 +41,10 @@ export const BlockComponent = (props)=>{
35
41
  ;
36
42
  if (state) {
37
43
  setInitialState({
38
- ...state,
39
- blockName2: {
44
+ ...removeEmptyArrayValues({
45
+ fields: state
46
+ }),
47
+ blockName: {
40
48
  initialValue: '',
41
49
  passesCondition: true,
42
50
  valid: true,
@@ -67,7 +75,7 @@ export const BlockComponent = (props)=>{
67
75
  });
68
76
  return {
69
77
  ...formState,
70
- blockName2: {
78
+ blockName: {
71
79
  initialValue: '',
72
80
  passesCondition: true,
73
81
  valid: true,
@@ -83,11 +91,8 @@ export const BlockComponent = (props)=>{
83
91
  ]);
84
92
  // Memoized Form JSX
85
93
  const formContent = useMemo(()=>{
86
- return reducedBlock && initialState !== false && /*#__PURE__*/ React.createElement(FieldPathProvider, {
87
- path: "",
88
- schemaPath: ""
89
- }, /*#__PURE__*/ React.createElement(Form, {
90
- // @ts-expect-error // TODO: Fix this type. Is this correct?
94
+ return reducedBlock && initialState !== false && /*#__PURE__*/ React.createElement(Form, {
95
+ // @ts-expect-error TODO: Fix this
91
96
  fields: fieldMap,
92
97
  initialState: initialState,
93
98
  onChange: [
@@ -101,8 +106,10 @@ export const BlockComponent = (props)=>{
101
106
  formData: formData,
102
107
  formSchema: Array.isArray(fieldMap) ? fieldMap : [],
103
108
  nodeKey: nodeKey,
104
- reducedBlock: reducedBlock
105
- })));
109
+ path: `${path}.feature.blocks.${formData.blockType}`,
110
+ reducedBlock: reducedBlock,
111
+ schemaPath: schemaFieldsPath
112
+ }));
106
113
  }, [
107
114
  fieldMap,
108
115
  parentLexicalRichTextField,