@payloadcms/richtext-lexical 3.0.0-beta.73 → 3.0.0-beta.75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exports/client/Field-5GGTGCKC.js +2 -0
- package/dist/exports/client/Field-5GGTGCKC.js.map +7 -0
- package/dist/exports/client/bundled.css +1 -1
- package/dist/exports/client/index.js +7 -7
- package/dist/exports/client/index.js.map +4 -4
- package/dist/features/blockquote/feature.server.d.ts.map +1 -1
- package/dist/features/blockquote/feature.server.js +5 -2
- package/dist/features/blockquote/feature.server.js.map +1 -1
- package/dist/features/blocks/validate.d.ts.map +1 -1
- package/dist/features/blocks/validate.js +2 -1
- package/dist/features/blocks/validate.js.map +1 -1
- package/dist/features/converters/html/converter/converters/paragraph.d.ts.map +1 -1
- package/dist/features/converters/html/converter/converters/paragraph.js +5 -2
- package/dist/features/converters/html/converter/converters/paragraph.js.map +1 -1
- package/dist/features/converters/html/converter/index.d.ts +8 -2
- package/dist/features/converters/html/converter/index.d.ts.map +1 -1
- package/dist/features/converters/html/converter/index.js +14 -5
- package/dist/features/converters/html/converter/index.js.map +1 -1
- package/dist/features/converters/html/converter/types.d.ts +5 -2
- package/dist/features/converters/html/converter/types.d.ts.map +1 -1
- package/dist/features/converters/html/converter/types.js.map +1 -1
- package/dist/features/converters/html/feature.server.d.ts +2 -2
- package/dist/features/converters/html/feature.server.d.ts.map +1 -1
- package/dist/features/converters/html/feature.server.js.map +1 -1
- package/dist/features/converters/html/field/index.d.ts.map +1 -1
- package/dist/features/converters/html/field/index.js +5 -2
- package/dist/features/converters/html/field/index.js.map +1 -1
- package/dist/features/experimental_table/feature.client.d.ts.map +1 -1
- package/dist/features/experimental_table/feature.client.js +5 -0
- package/dist/features/experimental_table/feature.client.js.map +1 -1
- package/dist/features/experimental_table/feature.server.d.ts +11 -0
- package/dist/features/experimental_table/feature.server.d.ts.map +1 -1
- package/dist/features/experimental_table/feature.server.js +79 -6
- package/dist/features/experimental_table/feature.server.js.map +1 -1
- package/dist/features/experimental_table/plugins/TableActionMenuPlugin/index.d.ts.map +1 -1
- package/dist/features/experimental_table/plugins/TableActionMenuPlugin/index.js +2 -0
- package/dist/features/experimental_table/plugins/TableActionMenuPlugin/index.js.map +1 -1
- package/dist/features/experimental_table/plugins/TableCellResizerPlugin/index.d.ts +0 -1
- package/dist/features/experimental_table/plugins/TableCellResizerPlugin/index.d.ts.map +1 -1
- package/dist/features/experimental_table/plugins/TableCellResizerPlugin/index.js +13 -8
- package/dist/features/experimental_table/plugins/TableCellResizerPlugin/index.js.map +1 -1
- package/dist/features/experimental_table/plugins/TableHoverActionsPlugin/index.d.ts +12 -0
- package/dist/features/experimental_table/plugins/TableHoverActionsPlugin/index.d.ts.map +1 -0
- package/dist/features/experimental_table/plugins/TableHoverActionsPlugin/index.js +181 -0
- package/dist/features/experimental_table/plugins/TableHoverActionsPlugin/index.js.map +1 -0
- package/dist/features/experimental_table/utils/debounce.d.ts +61 -0
- package/dist/features/experimental_table/utils/debounce.d.ts.map +1 -0
- package/dist/features/experimental_table/utils/debounce.js +202 -0
- package/dist/features/experimental_table/utils/debounce.js.map +1 -0
- package/dist/features/experimental_table/utils/useDebounce.d.ts +6 -0
- package/dist/features/experimental_table/utils/useDebounce.d.ts.map +1 -0
- package/dist/features/experimental_table/utils/useDebounce.js +18 -0
- package/dist/features/experimental_table/utils/useDebounce.js.map +1 -0
- package/dist/features/heading/feature.server.d.ts.map +1 -1
- package/dist/features/heading/feature.server.js +5 -2
- package/dist/features/heading/feature.server.js.map +1 -1
- package/dist/features/link/feature.server.d.ts.map +1 -1
- package/dist/features/link/feature.server.js +10 -4
- package/dist/features/link/feature.server.js.map +1 -1
- package/dist/features/link/plugins/autoLink/index.d.ts.map +1 -1
- package/dist/features/link/plugins/autoLink/index.js +19 -6
- package/dist/features/link/plugins/autoLink/index.js.map +1 -1
- package/dist/features/link/validate.d.ts.map +1 -1
- package/dist/features/link/validate.js +2 -1
- package/dist/features/link/validate.js.map +1 -1
- package/dist/features/lists/htmlConverter.d.ts.map +1 -1
- package/dist/features/lists/htmlConverter.js +10 -4
- package/dist/features/lists/htmlConverter.js.map +1 -1
- package/dist/features/migrations/slateToLexical/converter/index.d.ts.map +1 -1
- package/dist/features/migrations/slateToLexical/converter/index.js +1 -0
- package/dist/features/migrations/slateToLexical/converter/index.js.map +1 -1
- package/dist/features/typesServer.d.ts +2 -1
- package/dist/features/typesServer.d.ts.map +1 -1
- package/dist/features/typesServer.js.map +1 -1
- package/dist/features/upload/feature.server.js +4 -4
- package/dist/features/upload/feature.server.js.map +1 -1
- package/dist/features/upload/validate.d.ts.map +1 -1
- package/dist/features/upload/validate.js +1 -0
- package/dist/features/upload/validate.js.map +1 -1
- package/dist/field/Field.d.ts.map +1 -1
- package/dist/field/Field.js +8 -7
- package/dist/field/Field.js.map +1 -1
- package/dist/field/index.js +8 -8
- package/dist/lexical/LexicalEditor.d.ts.map +1 -1
- package/dist/lexical/LexicalEditor.js +0 -6
- package/dist/lexical/LexicalEditor.js.map +1 -1
- package/dist/lexical/ui/ContentEditable.d.ts.map +1 -1
- package/dist/lexical/ui/ContentEditable.js +8 -1
- package/dist/lexical/ui/ContentEditable.js.map +1 -1
- package/dist/lexical/ui/icons/Table/index.d.ts.map +1 -1
- package/dist/lexical/ui/icons/Table/index.js +1 -0
- package/dist/lexical/ui/icons/Table/index.js.map +1 -1
- package/dist/lexical/ui/icons/Upload/index.js +1 -1
- package/dist/lexical/ui/icons/Upload/index.js.map +1 -1
- package/dist/nodeTypes.d.ts +3 -1
- package/dist/nodeTypes.d.ts.map +1 -1
- package/dist/nodeTypes.js.map +1 -1
- package/dist/populateGraphQL/defaultValue.d.ts.map +1 -1
- package/dist/populateGraphQL/defaultValue.js +1 -0
- package/dist/populateGraphQL/defaultValue.js.map +1 -1
- package/dist/utilities/generateComponentMap.d.ts.map +1 -1
- package/dist/utilities/generateComponentMap.js +3 -1
- package/dist/utilities/generateComponentMap.js.map +1 -1
- package/package.json +33 -33
- package/dist/exports/client/Field-YNHIDK3D.js +0 -2
- package/dist/exports/client/Field-YNHIDK3D.js.map +0 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/features/upload/feature.server.ts"],"sourcesContent":["import type {\n CollectionSlug,\n Config,\n Field,\n FileData,\n FileSize,\n Payload,\n TypeWithID,\n} from 'payload'\n\nimport { sanitizeFields } from 'payload'\n\nimport type { UploadFeaturePropsClient } from './feature.client.js'\n\n// eslint-disable-next-line payload/no-imports-from-exports-dir\nimport { UploadFeatureClient } from '../../exports/client/index.js'\nimport { populate } from '../../populateGraphQL/populate.js'\nimport { createServerFeature } from '../../utilities/createServerFeature.js'\nimport { createNode } from '../typeUtilities.js'\nimport { uploadPopulationPromiseHOC } from './graphQLPopulationPromise.js'\nimport { i18n } from './i18n.js'\nimport { UploadNode } from './nodes/UploadNode.js'\nimport { uploadValidation } from './validate.js'\n\nexport type UploadFeatureProps = {\n collections?: {\n [collection: CollectionSlug]: {\n fields: Field[]\n }\n }\n /**\n * Sets a maximum population depth for this upload (not the fields for this upload), regardless of the remaining depth when the respective field is reached.\n * This behaves exactly like the maxDepth properties of relationship and upload fields.\n *\n * {@link https://payloadcms.com/docs/getting-started/concepts#field-level-max-depth}\n */\n maxDepth?: number\n}\n\n/**\n * Get the absolute URL for an upload URL by potentially prepending the serverURL\n */\nfunction getAbsoluteURL(url: string, payload: Payload): string {\n return url?.startsWith('http') ? url : (payload?.config?.serverURL || '') + url\n}\n\nexport const UploadFeature = createServerFeature<\n UploadFeatureProps,\n UploadFeatureProps,\n UploadFeaturePropsClient\n>({\n feature: async ({ config: _config, isRoot, props }) => {\n if (!props) {\n props = { collections: {} }\n }\n\n const clientProps: UploadFeaturePropsClient = {\n collections: {},\n }\n if (props.collections) {\n for (const collection in props.collections) {\n clientProps.collections[collection] = {\n hasExtraFields: props.collections[collection].fields.length >= 1,\n }\n }\n }\n\n const validRelationships = _config.collections.map((c) => c.slug) || []\n\n for (const collection in props.collections) {\n if (props.collections[collection].fields?.length) {\n props.collections[collection].fields = await sanitizeFields({\n config: _config as unknown as Config,\n fields: props.collections[collection].fields,\n requireFieldLevelRichTextEditor: isRoot,\n validRelationships,\n })\n }\n }\n\n return {\n ClientFeature: UploadFeatureClient,\n clientFeatureProps: clientProps,\n generateSchemaMap: ({ props }) => {\n if (!props?.collections) return null\n\n const schemaMap = new Map<string, Field[]>()\n\n for (const collection in props.collections) {\n if (props.collections[collection].fields?.length) {\n schemaMap.set(collection, props.collections[collection].fields)\n }\n }\n\n return schemaMap\n },\n i18n,\n nodes: [\n createNode({\n converters: {\n html: {\n converter: async ({ node, req }) => {\n // @ts-expect-error\n const id = node?.value?.id || node?.value // for backwards-compatibility\n\n if (req?.payload) {\n const uploadDocument: {\n value?: FileData & TypeWithID\n } = {}\n\n try {\n await populate({\n id,\n collectionSlug: node.relationTo,\n currentDepth: 0,\n data: uploadDocument,\n depth: 1,\n draft: false,\n key: 'value',\n overrideAccess: false,\n req,\n showHiddenFields: false,\n })\n } catch (ignored) {\n // eslint-disable-next-line no-console\n console.error(\n 'Lexical upload node HTML converter: error fetching upload file',\n ignored,\n 'Node:',\n node,\n )\n return `<img />`\n }\n\n const url = getAbsoluteURL(uploadDocument?.value?.url, req?.payload)\n\n /**\n * If the upload is not an image, return a link to the upload\n */\n if (!uploadDocument?.value?.mimeType?.startsWith('image')) {\n return `<a href=\"${url}\" rel=\"noopener noreferrer\">${uploadDocument.value?.filename}</a>`\n }\n\n /**\n * If the upload is a simple image with no different sizes, return a simple img tag\n */\n if (\n !uploadDocument?.value?.sizes ||\n !Object.keys(uploadDocument?.value?.sizes).length\n ) {\n return `<img src=\"${url}\" alt=\"${uploadDocument?.value?.filename}\" width=\"${uploadDocument?.value?.width}\" height=\"${uploadDocument?.value?.height}\"/>`\n }\n\n /**\n * If the upload is an image with different sizes, return a picture element\n */\n let pictureHTML = '<picture>'\n\n // Iterate through each size in the data.sizes object\n for (const size in uploadDocument.value?.sizes) {\n const imageSize: {\n url?: string\n } & FileSize = uploadDocument.value?.sizes[size]\n\n // Skip if any property of the size object is null\n if (\n !imageSize.width ||\n !imageSize.height ||\n !imageSize.mimeType ||\n !imageSize.filesize ||\n !imageSize.filename ||\n !imageSize.url\n ) {\n continue\n }\n const imageSizeURL = getAbsoluteURL(imageSize?.url, req?.payload)\n\n pictureHTML += `<source srcset=\"${imageSizeURL}\" media=\"(max-width: ${imageSize.width}px)\" type=\"${imageSize.mimeType}\">`\n }\n\n // Add the default img tag\n pictureHTML += `<img src=\"${url}\" alt=\"Image\" width=\"${uploadDocument.value?.width}\" height=\"${uploadDocument.value?.height}\">`\n pictureHTML += '</picture>'\n return pictureHTML\n } else {\n return `<img src=\"${id}\" />`\n }\n },\n nodeTypes: [UploadNode.getType()],\n },\n },\n getSubFields: ({ node, req }) => {\n const collection = req.payload.collections[node?.relationTo]\n\n if (collection) {\n const collectionFieldSchema = props?.collections?.[node?.relationTo]?.fields\n\n if (Array.isArray(collectionFieldSchema)) {\n if (!collectionFieldSchema?.length) {\n return null\n }\n return collectionFieldSchema\n }\n }\n return null\n },\n getSubFieldsData: ({ node }) => {\n return node?.fields\n },\n graphQLPopulationPromises: [uploadPopulationPromiseHOC(props)],\n hooks: {\n afterRead: [\n ({\n currentDepth,\n depth,\n draft,\n node,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n }) => {\n if (!node?.value) {\n return node\n }\n const collection = req.payload.collections[node?.relationTo]\n\n if (!collection) {\n return node\n }\n // @ts-expect-error\n const id = node?.value?.id || node?.value // for backwards-compatibility\n\n const populateDepth =\n props?.maxDepth !== undefined && props?.maxDepth < depth ? props?.maxDepth : depth\n\n populationPromises.push(\n populate({\n id,\n collectionSlug: collection.config.slug,\n currentDepth,\n data: node,\n depth: populateDepth,\n draft,\n key: 'value',\n overrideAccess,\n req,\n showHiddenFields,\n }),\n )\n\n return node\n },\n ],\n },\n node: UploadNode,\n validations: [uploadValidation(props)],\n }),\n ],\n sanitizedServerFeatureProps: props,\n }\n },\n key: 'upload',\n})\n"],"names":["sanitizeFields","UploadFeatureClient","populate","createServerFeature","createNode","uploadPopulationPromiseHOC","i18n","UploadNode","uploadValidation","getAbsoluteURL","url","payload","startsWith","config","serverURL","UploadFeature","feature","_config","isRoot","props","collections","clientProps","collection","hasExtraFields","fields","length","validRelationships","map","c","slug","requireFieldLevelRichTextEditor","ClientFeature","clientFeatureProps","generateSchemaMap","schemaMap","Map","set","nodes","converters","html","converter","node","req","id","value","uploadDocument","collectionSlug","relationTo","currentDepth","data","depth","draft","key","overrideAccess","showHiddenFields","ignored","console","error","mimeType","filename","sizes","Object","keys","width","height","pictureHTML","size","imageSize","filesize","imageSizeURL","nodeTypes","getType","getSubFields","collectionFieldSchema","Array","isArray","getSubFieldsData","graphQLPopulationPromises","hooks","afterRead","populationPromises","populateDepth","maxDepth","undefined","push","validations","sanitizedServerFeatureProps"],"mappings":"AAUA,SAASA,cAAc,QAAQ,UAAS;AAIxC,+DAA+D;AAC/D,SAASC,mBAAmB,QAAQ,gCAA+B;AACnE,SAASC,QAAQ,QAAQ,oCAAmC;AAC5D,SAASC,mBAAmB,QAAQ,yCAAwC;AAC5E,SAASC,UAAU,QAAQ,sBAAqB;AAChD,SAASC,0BAA0B,QAAQ,gCAA+B;AAC1E,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,UAAU,QAAQ,wBAAuB;AAClD,SAASC,gBAAgB,QAAQ,gBAAe;AAiBhD;;CAEC,GACD,SAASC,eAAeC,GAAW,EAAEC,OAAgB;IACnD,OAAOD,KAAKE,WAAW,UAAUF,MAAM,AAACC,CAAAA,SAASE,QAAQC,aAAa,EAAC,IAAKJ;AAC9E;AAEA,OAAO,MAAMK,gBAAgBZ,oBAI3B;IACAa,SAAS,OAAO,EAAEH,QAAQI,OAAO,EAAEC,MAAM,EAAEC,KAAK,EAAE;QAChD,IAAI,CAACA,OAAO;YACVA,QAAQ;gBAAEC,aAAa,CAAC;YAAE;QAC5B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AI/B,OAAO,CAACS,WAAW,CAACqB,MAAMM,WAAW;gCAE5D,IAAI,CAACzB,YAAY;oCACf,OAAOmB;gCACT;gCACA,mBAAmB;gCACnB,MAAME,KAAKF,MAAMG,OAAOD,MAAMF,MAAMG,MAAM,8BAA8B;;gCAExE,MAAMqC,gBACJ9D,OAAO+D,aAAaC,aAAahE,OAAO+D,WAAWhC,QAAQ/B,OAAO+D,WAAWhC;gCAE/E8B,mBAAmBI,IAAI,CACrBlF,SAAS;oCACPyC;oCACAG,gBAAgBxB,WAAWT,MAAM,CAACgB,IAAI;oCACtCmB;oCACAC,MAAMR;oCACNS,OAAO+B;oCACP9B;oCACAC,KAAK;oCACLC;oCACAX;oCACAY;gCACF;gCAGF,OAAOb;4BACT;yBACD;oBACH;oBACAA,MAAMlC;oBACN8E,aAAa;wBAAC7E,iBAAiBW;qBAAO;gBACxC;aACD;YACDmE,6BAA6BnE;QAC/B;IACF;IACAiC,KAAK;AACP,GAAE"}
|
|
1
|
+
{"version":3,"sources":["../../../src/features/upload/feature.server.ts"],"sourcesContent":["import type {\n CollectionSlug,\n Config,\n Field,\n FileData,\n FileSize,\n Payload,\n TypeWithID,\n} from 'payload'\n\nimport { sanitizeFields } from 'payload'\n\nimport type { UploadFeaturePropsClient } from './feature.client.js'\n\n// eslint-disable-next-line payload/no-imports-from-exports-dir\nimport { UploadFeatureClient } from '../../exports/client/index.js'\nimport { populate } from '../../populateGraphQL/populate.js'\nimport { createServerFeature } from '../../utilities/createServerFeature.js'\nimport { createNode } from '../typeUtilities.js'\nimport { uploadPopulationPromiseHOC } from './graphQLPopulationPromise.js'\nimport { i18n } from './i18n.js'\nimport { UploadNode } from './nodes/UploadNode.js'\nimport { uploadValidation } from './validate.js'\n\nexport type UploadFeatureProps = {\n collections?: {\n [collection: CollectionSlug]: {\n fields: Field[]\n }\n }\n /**\n * Sets a maximum population depth for this upload (not the fields for this upload), regardless of the remaining depth when the respective field is reached.\n * This behaves exactly like the maxDepth properties of relationship and upload fields.\n *\n * {@link https://payloadcms.com/docs/getting-started/concepts#field-level-max-depth}\n */\n maxDepth?: number\n}\n\n/**\n * Get the absolute URL for an upload URL by potentially prepending the serverURL\n */\nfunction getAbsoluteURL(url: string, payload: Payload): string {\n return url?.startsWith('http') ? url : (payload?.config?.serverURL || '') + url\n}\n\nexport const UploadFeature = createServerFeature<\n UploadFeatureProps,\n UploadFeatureProps,\n UploadFeaturePropsClient\n>({\n feature: async ({ config: _config, isRoot, props }) => {\n if (!props) {\n props = { collections: {} }\n }\n\n const clientProps: UploadFeaturePropsClient = {\n collections: {},\n }\n if (props.collections) {\n for (const collection in props.collections) {\n clientProps.collections[collection] = {\n hasExtraFields: props.collections[collection].fields.length >= 1,\n }\n }\n }\n\n const validRelationships = _config.collections.map((c) => c.slug) || []\n\n for (const collection in props.collections) {\n if (props.collections[collection].fields?.length) {\n props.collections[collection].fields = await sanitizeFields({\n config: _config as unknown as Config,\n fields: props.collections[collection].fields,\n requireFieldLevelRichTextEditor: isRoot,\n validRelationships,\n })\n }\n }\n\n return {\n ClientFeature: UploadFeatureClient,\n clientFeatureProps: clientProps,\n generateSchemaMap: ({ props }) => {\n if (!props?.collections) return null\n\n const schemaMap = new Map<string, Field[]>()\n\n for (const collection in props.collections) {\n if (props.collections[collection].fields?.length) {\n schemaMap.set(collection, props.collections[collection].fields)\n }\n }\n\n return schemaMap\n },\n i18n,\n nodes: [\n createNode({\n converters: {\n html: {\n converter: async ({ draft, node, overrideAccess, req, showHiddenFields }) => {\n // @ts-expect-error\n const id = node?.value?.id || node?.value // for backwards-compatibility\n\n if (req?.payload) {\n const uploadDocument: {\n value?: FileData & TypeWithID\n } = {}\n\n try {\n await populate({\n id,\n collectionSlug: node.relationTo,\n currentDepth: 0,\n data: uploadDocument,\n depth: 1,\n draft,\n key: 'value',\n overrideAccess,\n req,\n showHiddenFields,\n })\n } catch (ignored) {\n // eslint-disable-next-line no-console\n console.error(\n 'Lexical upload node HTML converter: error fetching upload file',\n ignored,\n 'Node:',\n node,\n )\n return `<img />`\n }\n\n const url = getAbsoluteURL(uploadDocument?.value?.url, req?.payload)\n\n /**\n * If the upload is not an image, return a link to the upload\n */\n if (!uploadDocument?.value?.mimeType?.startsWith('image')) {\n return `<a href=\"${url}\" rel=\"noopener noreferrer\">${uploadDocument.value?.filename}</a>`\n }\n\n /**\n * If the upload is a simple image with no different sizes, return a simple img tag\n */\n if (\n !uploadDocument?.value?.sizes ||\n !Object.keys(uploadDocument?.value?.sizes).length\n ) {\n return `<img src=\"${url}\" alt=\"${uploadDocument?.value?.filename}\" width=\"${uploadDocument?.value?.width}\" height=\"${uploadDocument?.value?.height}\"/>`\n }\n\n /**\n * If the upload is an image with different sizes, return a picture element\n */\n let pictureHTML = '<picture>'\n\n // Iterate through each size in the data.sizes object\n for (const size in uploadDocument.value?.sizes) {\n const imageSize: {\n url?: string\n } & FileSize = uploadDocument.value?.sizes[size]\n\n // Skip if any property of the size object is null\n if (\n !imageSize.width ||\n !imageSize.height ||\n !imageSize.mimeType ||\n !imageSize.filesize ||\n !imageSize.filename ||\n !imageSize.url\n ) {\n continue\n }\n const imageSizeURL = getAbsoluteURL(imageSize?.url, req?.payload)\n\n pictureHTML += `<source srcset=\"${imageSizeURL}\" media=\"(max-width: ${imageSize.width}px)\" type=\"${imageSize.mimeType}\">`\n }\n\n // Add the default img tag\n pictureHTML += `<img src=\"${url}\" alt=\"Image\" width=\"${uploadDocument.value?.width}\" height=\"${uploadDocument.value?.height}\">`\n pictureHTML += '</picture>'\n return pictureHTML\n } else {\n return `<img src=\"${id}\" />`\n }\n },\n nodeTypes: [UploadNode.getType()],\n },\n },\n getSubFields: ({ node, req }) => {\n const collection = req.payload.collections[node?.relationTo]\n\n if (collection) {\n const collectionFieldSchema = props?.collections?.[node?.relationTo]?.fields\n\n if (Array.isArray(collectionFieldSchema)) {\n if (!collectionFieldSchema?.length) {\n return null\n }\n return collectionFieldSchema\n }\n }\n return null\n },\n getSubFieldsData: ({ node }) => {\n return node?.fields\n },\n graphQLPopulationPromises: [uploadPopulationPromiseHOC(props)],\n hooks: {\n afterRead: [\n ({\n currentDepth,\n depth,\n draft,\n node,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n }) => {\n if (!node?.value) {\n return node\n }\n const collection = req.payload.collections[node?.relationTo]\n\n if (!collection) {\n return node\n }\n // @ts-expect-error\n const id = node?.value?.id || node?.value // for backwards-compatibility\n\n const populateDepth =\n props?.maxDepth !== undefined && props?.maxDepth < depth ? props?.maxDepth : depth\n\n populationPromises.push(\n populate({\n id,\n collectionSlug: collection.config.slug,\n currentDepth,\n data: node,\n depth: populateDepth,\n draft,\n key: 'value',\n overrideAccess,\n req,\n showHiddenFields,\n }),\n )\n\n return node\n },\n ],\n },\n node: UploadNode,\n validations: [uploadValidation(props)],\n }),\n ],\n sanitizedServerFeatureProps: props,\n }\n },\n key: 'upload',\n})\n"],"names":["sanitizeFields","UploadFeatureClient","populate","createServerFeature","createNode","uploadPopulationPromiseHOC","i18n","UploadNode","uploadValidation","getAbsoluteURL","url","payload","startsWith","config","serverURL","UploadFeature","feature","_config","isRoot","props","collections","clientProps","collection","hasExtraFields","fields","length","validRelationships","map","c","slug","requireFieldLevelRichTextEditor","ClientFeature","clientFeatureProps","generateSchemaMap","schemaMap","Map","set","nodes","converters","html","converter","draft","node","overrideAccess","req","showHiddenFields","id","value","uploadDocument","collectionSlug","relationTo","currentDepth","data","depth","key","ignored","console","error","mimeType","filename","sizes","Object","keys","width","height","pictureHTML","size","imageSize","filesize","imageSizeURL","nodeTypes","getType","getSubFields","collectionFieldSchema","Array","isArray","getSubFieldsData","graphQLPopulationPromises","hooks","afterRead","populationPromises","populateDepth","maxDepth","undefined","push","validations","sanitizedServerFeatureProps"],"mappings":"AAUA,SAASA,cAAc,QAAQ,UAAS;AAIxC,+DAA+D;AAC/D,SAASC,mBAAmB,QAAQ,gCAA+B;AACnE,SAASC,QAAQ,QAAQ,oCAAmC;AAC5D,SAASC,mBAAmB,QAAQ,y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,CAACsB,MAAMQ,WAAW,EAAE1B;4BAEtE,IAAIkD,MAAMC,OAAO,CAACF,wBAAwB;gCACxC,IAAI,CAACA,uBAAuBhD,QAAQ;oCAClC,OAAO;gCACT;gCACA,OAAOgD;4BACT;wBACF;wBACA,OAAO;oBACT;oBACAG,kBAAkB,CAAC,EAAElC,IAAI,EAAE;wBACzB,OAAOA,MAAMlB;oBACf;oBACAqD,2BAA2B;wBAACxE,2BAA2Bc;qBAAO;oBAC9D2D,OAAO;wBACLC,WAAW;4BACT,CAAC,EACC5B,YAAY,EACZE,KAAK,EACLZ,KAAK,EACLC,IAAI,EACJC,cAAc,EACdqC,kBAAkB,EAClBpC,GAAG,EACHC,gBAAgB,EACjB;gCACC,IAAI,CAACH,MAAMK,OAAO;oCAChB,OAAOL;gCACT;gCACA,MAAMpB,aAAasB,IAAIjC,OAAO,CAACS,WAAW,CAACsB,MAAMQ,WAAW;gCAE5D,IAAI,CAAC5B,YAAY;oCACf,OAAOoB;gCACT;gCACA,mBAAmB;gCACnB,MAAMI,KAAKJ,MAAMK,OAAOD,MAAMJ,MAAMK,MAAM,8BAA8B;;gCAExE,MAAMkC,gBACJ9D,OAAO+D,aAAaC,aAAahE,OAAO+D,WAAW7B,QAAQlC,OAAO+D,WAAW7B;gCAE/E2B,mBAAmBI,IAAI,CACrBlF,SAAS;oCACP4C;oCACAG,gBAAgB3B,WAAWT,MAAM,CAACgB,IAAI;oCACtCsB;oCACAC,MAAMV;oCACNW,OAAO4B;oCACPxC;oCACAa,KAAK;oCACLX;oCACAC;oCACAC;gCACF;gCAGF,OAAOH;4BACT;yBACD;oBACH;oBACAA,MAAMnC;oBACN8E,aAAa;wBAAC7E,iBAAiBW;qBAAO;gBACxC;aACD;YACDmE,6BAA6BnE;QAC/B;IACF;IACAmC,KAAK;AACP,GAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../src/features/upload/validate.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAEjE,eAAO,MAAM,gBAAgB,UACpB,kBAAkB,KACxB,cAAc,CAAC,oBAAoB,
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../src/features/upload/validate.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAEjE,eAAO,MAAM,gBAAgB,UACpB,kBAAkB,KACxB,cAAc,CAAC,oBAAoB,CA2DrC,CAAA"}
|
|
@@ -21,6 +21,7 @@ export const uploadValidation = (props)=>{
|
|
|
21
21
|
}
|
|
22
22
|
const result = await buildStateFromSchema({
|
|
23
23
|
id,
|
|
24
|
+
collectionSlug: node.relationTo,
|
|
24
25
|
data: node?.fields ?? {},
|
|
25
26
|
fieldSchema: collection.fields,
|
|
26
27
|
operation: operation === 'create' || operation === 'update' ? operation : 'update',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/features/upload/validate.ts"],"sourcesContent":["import { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema'\nimport { isValidID } from 'payload'\n\nimport type { NodeValidation } from '../typesServer.js'\nimport type { UploadFeatureProps } from './feature.server.js'\nimport type { SerializedUploadNode } from './nodes/UploadNode.js'\n\nexport const uploadValidation = (\n props: UploadFeatureProps,\n): NodeValidation<SerializedUploadNode> => {\n return async ({\n node,\n validation: {\n options: {\n id,\n operation,\n preferences,\n req,\n req: { payload, t },\n },\n },\n }) => {\n const idType = payload.collections[node.relationTo].customIDType || payload.db.defaultIDType\n // @ts-expect-error\n const nodeID = node?.value?.id || node?.value // for backwards-compatibility\n\n if (!isValidID(nodeID, idType)) {\n return t('validation:validUploadID')\n }\n\n if (!props?.collections) {\n return true\n }\n\n if (Object.keys(props?.collections).length === 0) {\n return true\n }\n\n const collection = props?.collections[node.relationTo]\n\n if (!collection?.fields?.length) {\n return true\n }\n\n const result = await buildStateFromSchema({\n id,\n data: node?.fields ?? {},\n fieldSchema: collection.fields,\n operation: operation === 'create' || operation === 'update' ? operation : 'update',\n preferences,\n req,\n siblingData: node?.fields ?? {},\n })\n\n let errorPaths = []\n for (const fieldKey in result) {\n if (result[fieldKey].errorPaths) {\n errorPaths = errorPaths.concat(result[fieldKey].errorPaths)\n }\n }\n\n if (errorPaths.length) {\n return 'The following fields are invalid: ' + errorPaths.join(', ')\n }\n\n return true\n }\n}\n"],"names":["buildStateFromSchema","isValidID","uploadValidation","props","node","validation","options","id","operation","preferences","req","payload","t","idType","collections","relationTo","customIDType","db","defaultIDType","nodeID","value","Object","keys","length","collection","fields","result","data","fieldSchema","siblingData","errorPaths","fieldKey","concat","join"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,4CAA2C;AAChF,SAASC,SAAS,QAAQ,UAAS;AAMnC,OAAO,MAAMC,mBAAmB,CAC9BC;IAEA,OAAO,OAAO,EACZC,IAAI,EACJC,YAAY,EACVC,SAAS,EACPC,EAAE,EACFC,SAAS,EACTC,WAAW,EACXC,GAAG,EACHA,KAAK,EAAEC,OAAO,EAAEC,CAAC,EAAE,EACpB,EACF,EACF;QACC,MAAMC,SAASF,QAAQG,WAAW,CAACV,KAAKW,UAAU,CAAC,CAACC,YAAY,IAAIL,QAAQM,EAAE,CAACC,aAAa;QAC5F,mBAAmB;QACnB,MAAMC,SAASf,MAAMgB,OAAOb,MAAMH,MAAMgB,MAAM,8BAA8B;;QAE5E,IAAI,CAACnB,UAAUkB,QAAQN,SAAS;YAC9B,OAAOD,EAAE;QACX;QAEA,IAAI,CAACT,OAAOW,aAAa;YACvB,OAAO;QACT;QAEA,IAAIO,OAAOC,IAAI,CAACnB,OAAOW,aAAaS,MAAM,KAAK,GAAG;YAChD,OAAO;QACT;QAEA,MAAMC,aAAarB,OAAOW,WAAW,CAACV,KAAKW,UAAU,CAAC;QAEtD,IAAI,CAACS,YAAYC,QAAQF,QAAQ;YAC/B,OAAO;QACT;QAEA,MAAMG,SAAS,MAAM1B,qBAAqB;YACxCO;YACAoB,
|
|
1
|
+
{"version":3,"sources":["../../../src/features/upload/validate.ts"],"sourcesContent":["import { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema'\nimport { isValidID } from 'payload'\n\nimport type { NodeValidation } from '../typesServer.js'\nimport type { UploadFeatureProps } from './feature.server.js'\nimport type { SerializedUploadNode } from './nodes/UploadNode.js'\n\nexport const uploadValidation = (\n props: UploadFeatureProps,\n): NodeValidation<SerializedUploadNode> => {\n return async ({\n node,\n validation: {\n options: {\n id,\n operation,\n preferences,\n req,\n req: { payload, t },\n },\n },\n }) => {\n const idType = payload.collections[node.relationTo].customIDType || payload.db.defaultIDType\n // @ts-expect-error\n const nodeID = node?.value?.id || node?.value // for backwards-compatibility\n\n if (!isValidID(nodeID, idType)) {\n return t('validation:validUploadID')\n }\n\n if (!props?.collections) {\n return true\n }\n\n if (Object.keys(props?.collections).length === 0) {\n return true\n }\n\n const collection = props?.collections[node.relationTo]\n\n if (!collection?.fields?.length) {\n return true\n }\n\n const result = await buildStateFromSchema({\n id,\n collectionSlug: node.relationTo,\n data: node?.fields ?? {},\n fieldSchema: collection.fields,\n operation: operation === 'create' || operation === 'update' ? operation : 'update',\n preferences,\n req,\n siblingData: node?.fields ?? {},\n })\n\n let errorPaths = []\n for (const fieldKey in result) {\n if (result[fieldKey].errorPaths) {\n errorPaths = errorPaths.concat(result[fieldKey].errorPaths)\n }\n }\n\n if (errorPaths.length) {\n return 'The following fields are invalid: ' + errorPaths.join(', ')\n }\n\n return true\n }\n}\n"],"names":["buildStateFromSchema","isValidID","uploadValidation","props","node","validation","options","id","operation","preferences","req","payload","t","idType","collections","relationTo","customIDType","db","defaultIDType","nodeID","value","Object","keys","length","collection","fields","result","collectionSlug","data","fieldSchema","siblingData","errorPaths","fieldKey","concat","join"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,4CAA2C;AAChF,SAASC,SAAS,QAAQ,UAAS;AAMnC,OAAO,MAAMC,mBAAmB,CAC9BC;IAEA,OAAO,OAAO,EACZC,IAAI,EACJC,YAAY,EACVC,SAAS,EACPC,EAAE,EACFC,SAAS,EACTC,WAAW,EACXC,GAAG,EACHA,KAAK,EAAEC,OAAO,EAAEC,CAAC,EAAE,EACpB,EACF,EACF;QACC,MAAMC,SAASF,QAAQG,WAAW,CAACV,KAAKW,UAAU,CAAC,CAACC,YAAY,IAAIL,QAAQM,EAAE,CAACC,aAAa;QAC5F,mBAAmB;QACnB,MAAMC,SAASf,MAAMgB,OAAOb,MAAMH,MAAMgB,MAAM,8BAA8B;;QAE5E,IAAI,CAACnB,UAAUkB,QAAQN,SAAS;YAC9B,OAAOD,EAAE;QACX;QAEA,IAAI,CAACT,OAAOW,aAAa;YACvB,OAAO;QACT;QAEA,IAAIO,OAAOC,IAAI,CAACnB,OAAOW,aAAaS,MAAM,KAAK,GAAG;YAChD,OAAO;QACT;QAEA,MAAMC,aAAarB,OAAOW,WAAW,CAACV,KAAKW,UAAU,CAAC;QAEtD,IAAI,CAACS,YAAYC,QAAQF,QAAQ;YAC/B,OAAO;QACT;QAEA,MAAMG,SAAS,MAAM1B,qBAAqB;YACxCO;YACAoB,gBAAgBvB,KAAKW,UAAU;YAC/Ba,MAAMxB,MAAMqB,UAAU,CAAC;YACvBI,aAAaL,WAAWC,MAAM;YAC9BjB,WAAWA,cAAc,YAAYA,cAAc,WAAWA,YAAY;YAC1EC;YACAC;YACAoB,aAAa1B,MAAMqB,UAAU,CAAC;QAChC;QAEA,IAAIM,aAAa,EAAE;QACnB,IAAK,MAAMC,YAAYN,OAAQ;YAC7B,IAAIA,MAAM,CAACM,SAAS,CAACD,UAAU,EAAE;gBAC/BA,aAAaA,WAAWE,MAAM,CAACP,MAAM,CAACM,SAAS,CAACD,UAAU;YAC5D;QACF;QAEA,IAAIA,WAAWR,MAAM,EAAE;YACrB,OAAO,uCAAuCQ,WAAWG,IAAI,CAAC;QAChE;QAEA,OAAO;IACT;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../src/field/Field.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAU5C,OAAO,KAAsB,MAAM,OAAO,CAAA;AAG1C,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAA;AAG7E,OAAO,eAAe,CAAA;AACtB,OAAO,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../src/field/Field.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAU5C,OAAO,KAAsB,MAAM,OAAO,CAAA;AAG1C,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAA;AAG7E,OAAO,eAAe,CAAA;AACtB,OAAO,cAAc,CAAA;AAsIrB,eAAO,MAAM,QAAQ;kBAhIH,2BAA2B;UACnC,MAAM;0BACU,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC;YAC1C,MAAM;kBA6HsC,CAAA"}
|
package/dist/field/Field.js
CHANGED
|
@@ -6,8 +6,8 @@ import { ErrorBoundary } from 'react-error-boundary';
|
|
|
6
6
|
import { LexicalProvider } from '../lexical/LexicalProvider.js';
|
|
7
7
|
import './bundled.css';
|
|
8
8
|
const baseClass = 'rich-text-lexical';
|
|
9
|
-
const
|
|
10
|
-
const { name, CustomDescription, CustomError, CustomLabel, className, descriptionProps, editorConfig, errorProps, label, labelProps, path: pathFromProps, readOnly, required, style, validate, width } = props;
|
|
9
|
+
const RichTextComponent = (props)=>{
|
|
10
|
+
const { name, CustomDescription, CustomError, CustomLabel, className, descriptionProps, editorConfig, errorProps, label, labelProps, path: pathFromProps, readOnly: readOnlyFromProps, required, style, validate, width } = props;
|
|
11
11
|
const memoizedValidate = useCallback((value, validationOptions)=>{
|
|
12
12
|
if (typeof validate === 'function') {
|
|
13
13
|
return validate(value, {
|
|
@@ -23,18 +23,19 @@ const _RichText = (props)=>{
|
|
|
23
23
|
validate,
|
|
24
24
|
required
|
|
25
25
|
]);
|
|
26
|
-
const { path: pathFromContext } = useFieldProps();
|
|
26
|
+
const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps();
|
|
27
27
|
const fieldType = useField({
|
|
28
28
|
path: pathFromContext ?? pathFromProps ?? name,
|
|
29
29
|
validate: memoizedValidate
|
|
30
30
|
});
|
|
31
|
-
const { errorMessage, initialValue, path, schemaPath, setValue, showError, value } = fieldType;
|
|
31
|
+
const { errorMessage, formInitializing, formProcessing, initialValue, path, schemaPath, setValue, showError, value } = fieldType;
|
|
32
|
+
const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing;
|
|
32
33
|
const classes = [
|
|
33
34
|
baseClass,
|
|
34
35
|
'field-type',
|
|
35
36
|
className,
|
|
36
37
|
showError && 'error',
|
|
37
|
-
|
|
38
|
+
disabled && `${baseClass}--read-only`,
|
|
38
39
|
editorConfig?.admin?.hideGutter !== true ? `${baseClass}--show-gutter` : null
|
|
39
40
|
].filter(Boolean).join(' ');
|
|
40
41
|
return /*#__PURE__*/ _jsxs("div", {
|
|
@@ -78,7 +79,7 @@ const _RichText = (props)=>{
|
|
|
78
79
|
setValue(serializedEditorState);
|
|
79
80
|
},
|
|
80
81
|
path: path,
|
|
81
|
-
readOnly:
|
|
82
|
+
readOnly: disabled,
|
|
82
83
|
value: value
|
|
83
84
|
}, JSON.stringify({
|
|
84
85
|
initialValue,
|
|
@@ -111,6 +112,6 @@ function fallbackRender({ error }) {
|
|
|
111
112
|
]
|
|
112
113
|
});
|
|
113
114
|
}
|
|
114
|
-
export const RichText = withCondition(
|
|
115
|
+
export const RichText = withCondition(RichTextComponent);
|
|
115
116
|
|
|
116
117
|
//# sourceMappingURL=Field.js.map
|
package/dist/field/Field.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/field/Field.tsx"],"sourcesContent":["'use client'\nimport type { SerializedEditorState } from 'lexical'\nimport type { FormFieldBase } from 'payload'\n\nimport {\n FieldDescription,\n FieldError,\n FieldLabel,\n useField,\n useFieldProps,\n withCondition,\n} 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 { LexicalProvider } from '../lexical/LexicalProvider.js'\nimport './bundled.css'\nimport './index.scss'\n\nconst baseClass = 'rich-text-lexical'\n\nconst
|
|
1
|
+
{"version":3,"sources":["../../src/field/Field.tsx"],"sourcesContent":["'use client'\nimport type { SerializedEditorState } from 'lexical'\nimport type { FormFieldBase } from 'payload'\n\nimport {\n FieldDescription,\n FieldError,\n FieldLabel,\n useField,\n useFieldProps,\n withCondition,\n} 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 { LexicalProvider } from '../lexical/LexicalProvider.js'\nimport './bundled.css'\nimport './index.scss'\n\nconst baseClass = 'rich-text-lexical'\n\nconst RichTextComponent: React.FC<\n {\n editorConfig: SanitizedClientEditorConfig // With rendered features n stuff\n name: string\n richTextComponentMap: Map<string, React.ReactNode>\n width?: string\n } & FormFieldBase\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: readOnlyFromProps,\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, readOnly: readOnlyFromContext } = useFieldProps()\n\n const fieldType = useField<SerializedEditorState>({\n path: pathFromContext ?? pathFromProps ?? name,\n validate: memoizedValidate,\n })\n\n const {\n errorMessage,\n formInitializing,\n formProcessing,\n initialValue,\n path,\n schemaPath,\n setValue,\n showError,\n value,\n } = fieldType\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n const classes = [\n baseClass,\n 'field-type',\n className,\n showError && 'error',\n disabled && `${baseClass}--read-only`,\n editorConfig?.admin?.hideGutter !== true ? `${baseClass}--show-gutter` : null,\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 <FieldError CustomError={CustomError} path={path} {...(errorProps || {})} alignCaret=\"left\" />\n <FieldLabel\n CustomLabel={CustomLabel}\n label={label}\n required={required}\n {...(labelProps || {})}\n />\n <div className={`${baseClass}__wrap`}>\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={disabled}\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(RichTextComponent)\n"],"names":["FieldDescription","FieldError","FieldLabel","useField","useFieldProps","withCondition","React","useCallback","ErrorBoundary","LexicalProvider","baseClass","RichTextComponent","props","name","CustomDescription","CustomError","CustomLabel","className","descriptionProps","editorConfig","errorProps","label","labelProps","path","pathFromProps","readOnly","readOnlyFromProps","required","style","validate","width","memoizedValidate","value","validationOptions","pathFromContext","readOnlyFromContext","fieldType","errorMessage","formInitializing","formProcessing","initialValue","schemaPath","setValue","showError","disabled","classes","admin","hideGutter","filter","Boolean","join","div","alignCaret","fallbackRender","onReset","fieldProps","onChange","editorState","serializedEditorState","toJSON","features","hooks","save","length","forEach","hook","incomingEditorState","JSON","stringify","undefined","error","role","p","pre","color","message","RichText"],"mappings":"AAAA;;AAIA,SACEA,gBAAgB,EAChBC,UAAU,EACVC,UAAU,EACVC,QAAQ,EACRC,aAAa,EACbC,aAAa,QACR,iBAAgB;AACvB,OAAOC,SAASC,WAAW,QAAQ,QAAO;AAC1C,SAASC,aAAa,QAAQ,uBAAsB;AAIpD,SAASC,eAAe,QAAQ,gCAA+B;AAC/D,OAAO,gBAAe;AAGtB,MAAMC,YAAY;AAElB,MAAMC,oBAOF,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,UAAUC,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