@payloadcms/richtext-lexical 3.60.0-canary.0 → 3.60.0-canary.1

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 (51) hide show
  1. package/dist/exports/client/RelationshipComponent-JXQOFHXF.js +2 -0
  2. package/dist/exports/client/RelationshipComponent-JXQOFHXF.js.map +7 -0
  3. package/dist/exports/client/chunk-O6XRT2H3.js +2 -0
  4. package/dist/exports/client/{chunk-BQCXN3B4.js.map → chunk-O6XRT2H3.js.map} +4 -4
  5. package/dist/exports/client/component-WT25HAJA.js +2 -0
  6. package/dist/exports/client/component-WT25HAJA.js.map +7 -0
  7. package/dist/exports/client/index.js +22 -22
  8. package/dist/exports/client/index.js.map +4 -4
  9. package/dist/features/relationship/client/components/RelationshipComponent.d.ts +1 -1
  10. package/dist/features/relationship/client/components/RelationshipComponent.d.ts.map +1 -1
  11. package/dist/features/relationship/client/components/RelationshipComponent.js +1 -6
  12. package/dist/features/relationship/client/components/RelationshipComponent.js.map +1 -1
  13. package/dist/features/relationship/client/drawer/index.d.ts +3 -2
  14. package/dist/features/relationship/client/drawer/index.d.ts.map +1 -1
  15. package/dist/features/relationship/client/drawer/index.js +72 -59
  16. package/dist/features/relationship/client/drawer/index.js.map +1 -1
  17. package/dist/features/relationship/client/plugins/index.d.ts.map +1 -1
  18. package/dist/features/relationship/client/plugins/index.js +41 -49
  19. package/dist/features/relationship/client/plugins/index.js.map +1 -1
  20. package/dist/features/relationship/client/utils/useEnabledRelationships.d.ts +13 -0
  21. package/dist/features/relationship/client/utils/useEnabledRelationships.d.ts.map +1 -0
  22. package/dist/features/relationship/client/utils/useEnabledRelationships.js +64 -0
  23. package/dist/features/relationship/client/utils/useEnabledRelationships.js.map +1 -0
  24. package/dist/features/upload/client/component/index.d.ts +1 -1
  25. package/dist/features/upload/client/component/index.d.ts.map +1 -1
  26. package/dist/features/upload/client/component/index.js +1 -11
  27. package/dist/features/upload/client/component/index.js.map +1 -1
  28. package/dist/features/upload/client/drawer/index.d.ts +3 -2
  29. package/dist/features/upload/client/drawer/index.d.ts.map +1 -1
  30. package/dist/features/upload/client/drawer/index.js +8 -9
  31. package/dist/features/upload/client/drawer/index.js.map +1 -1
  32. package/dist/features/upload/client/index.d.ts +2 -1
  33. package/dist/features/upload/client/index.d.ts.map +1 -1
  34. package/dist/features/upload/client/index.js.map +1 -1
  35. package/dist/features/upload/client/plugin/index.d.ts.map +1 -1
  36. package/dist/features/upload/client/plugin/index.js +72 -75
  37. package/dist/features/upload/client/plugin/index.js.map +1 -1
  38. package/dist/features/upload/server/index.d.ts +18 -3
  39. package/dist/features/upload/server/index.d.ts.map +1 -1
  40. package/dist/features/upload/server/index.js +6 -0
  41. package/dist/features/upload/server/index.js.map +1 -1
  42. package/package.json +6 -6
  43. package/dist/exports/client/RelationshipComponent-TSIENULZ.js +0 -2
  44. package/dist/exports/client/RelationshipComponent-TSIENULZ.js.map +0 -7
  45. package/dist/exports/client/chunk-BQCXN3B4.js +0 -2
  46. package/dist/exports/client/component-CYFKY3IL.js +0 -2
  47. package/dist/exports/client/component-CYFKY3IL.js.map +0 -7
  48. package/dist/features/relationship/client/utils/EnabledRelationshipsCondition.d.ts +0 -7
  49. package/dist/features/relationship/client/utils/EnabledRelationshipsCondition.d.ts.map +0 -1
  50. package/dist/features/relationship/client/utils/EnabledRelationshipsCondition.js +0 -96
  51. package/dist/features/relationship/client/utils/EnabledRelationshipsCondition.js.map +0 -1
@@ -1,8 +1,23 @@
1
- import type { CollectionSlug, Field } from 'payload';
1
+ import type { Field, UploadCollectionSlug } from 'payload';
2
2
  import type { UploadFeaturePropsClient } from '../client/index.js';
3
+ export type ExclusiveUploadFeatureProps = {
4
+ /**
5
+ * The collections that should be disabled. Overrides the `enableRichTextRelationship` property in the collection config.
6
+ * When this property is set, `enabledCollections` will not be available.
7
+ **/
8
+ disabledCollections?: UploadCollectionSlug[];
9
+ enabledCollections?: never;
10
+ } | {
11
+ disabledCollections?: never;
12
+ /**
13
+ * The collections that should be enabled. Overrides the `enableRichTextRelationship` property in the collection config
14
+ * When this property is set, `disabledCollections` will not be available.
15
+ **/
16
+ enabledCollections?: UploadCollectionSlug[];
17
+ };
3
18
  export type UploadFeatureProps = {
4
19
  collections?: {
5
- [collection: CollectionSlug]: {
20
+ [collection: UploadCollectionSlug]: {
6
21
  fields: Field[];
7
22
  };
8
23
  };
@@ -13,6 +28,6 @@ export type UploadFeatureProps = {
13
28
  * {@link https://payloadcms.com/docs/getting-started/concepts#field-level-max-depth}
14
29
  */
15
30
  maxDepth?: number;
16
- };
31
+ } & ExclusiveUploadFeatureProps;
17
32
  export declare const UploadFeature: import("../../typesServer.js").FeatureProviderProviderServer<UploadFeatureProps, UploadFeatureProps, UploadFeaturePropsClient>;
18
33
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/features/upload/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,KAAK,EAMN,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAUlE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,WAAW,CAAC,EAAE;QACZ,CAAC,UAAU,EAAE,cAAc,GAAG;YAC5B,MAAM,EAAE,KAAK,EAAE,CAAA;SAChB,CAAA;KACF,CAAA;IACD;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AASD,eAAO,MAAM,aAAa,gIAiPxB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/features/upload/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,KAAK,EAML,oBAAoB,EACrB,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAUlE,MAAM,MAAM,2BAA2B,GACnC;IACE;;;QAGI;IACJ,mBAAmB,CAAC,EAAE,oBAAoB,EAAE,CAAA;IAG5C,kBAAkB,CAAC,EAAE,KAAK,CAAA;CAC3B,GACD;IAEE,mBAAmB,CAAC,EAAE,KAAK,CAAA;IAE3B;;;QAGI;IACJ,kBAAkB,CAAC,EAAE,oBAAoB,EAAE,CAAA;CAC5C,CAAA;AAEL,MAAM,MAAM,kBAAkB,GAAG;IAC/B,WAAW,CAAC,EAAE;QACZ,CAAC,UAAU,EAAE,oBAAoB,GAAG;YAClC,MAAM,EAAE,KAAK,EAAE,CAAA;SAChB,CAAA;KACF,CAAA;IACD;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,GAAG,2BAA2B,CAAA;AAS/B,eAAO,MAAM,aAAa,gIAwPxB,CAAA"}
@@ -27,6 +27,12 @@ export const UploadFeature = createServerFeature({
27
27
  const clientProps = {
28
28
  collections: {}
29
29
  };
30
+ if (props.disabledCollections) {
31
+ clientProps.disabledCollections = props.disabledCollections;
32
+ }
33
+ if (props.enabledCollections) {
34
+ clientProps.enabledCollections = props.enabledCollections;
35
+ }
30
36
  if (props.collections) {
31
37
  for (const collection in props.collections) {
32
38
  clientProps.collections[collection] = {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["sanitizeFields","populate","createServerFeature","createNode","uploadPopulationPromiseHOC","i18n","UploadServerNode","uploadValidation","getAbsoluteURL","url","payload","startsWith","config","serverURL","UploadFeature","feature","_config","isRoot","parentIsLocalized","props","collections","clientProps","collection","hasExtraFields","fields","length","validRelationships","map","c","slug","collectionKey","requireFieldLevelRichTextEditor","ClientFeature","clientFeatureProps","generateSchemaMap","schemaMap","Map","set","nodes","converters","html","converter","currentDepth","depth","draft","node","overrideAccess","req","showHiddenFields","id","value","uploadDocument","collectionSlug","relationTo","data","key","ignored","console","error","mimeType","filename","sizes","Object","keys","width","height","pictureHTML","size","imageSize","filesize","imageSizeURL","nodeTypes","getType","getSubFields","allSubFields","collectionFields","concat","collectionFieldSchema","Array","isArray","getSubFieldsData","graphQLPopulationPromises","hooks","afterRead","populateArg","populationPromises","populateDepth","maxDepth","undefined","push","select","defaultPopulate","validations","sanitizedServerFeatureProps"],"sources":["../../../../src/features/upload/server/index.ts"],"sourcesContent":["import type {\n CollectionSlug,\n Config,\n Field,\n FieldSchemaMap,\n FileData,\n FileSizeImproved,\n Payload,\n TypeWithID,\n} from 'payload'\n\nimport { sanitizeFields } from 'payload'\n\nimport type { UploadFeaturePropsClient } from '../client/index.js'\n\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 { UploadServerNode } 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, parentIsLocalized, 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 collectionKey in props.collections) {\n const collection = props.collections[collectionKey]!\n if (collection.fields?.length) {\n collection.fields = await sanitizeFields({\n config: _config as unknown as Config,\n fields: collection.fields,\n parentIsLocalized,\n requireFieldLevelRichTextEditor: isRoot,\n validRelationships,\n })\n }\n }\n\n return {\n ClientFeature: '@payloadcms/richtext-lexical/client#UploadFeatureClient',\n clientFeatureProps: clientProps,\n generateSchemaMap: ({ props }) => {\n if (!props?.collections) {\n return null\n }\n\n const schemaMap: FieldSchemaMap = new Map()\n\n for (const collectionKey in props.collections) {\n const collection = props.collections[collectionKey]!\n if (collection.fields?.length) {\n schemaMap.set(collectionKey, {\n fields: collection.fields,\n })\n }\n }\n\n return schemaMap\n },\n i18n,\n nodes: [\n createNode({\n converters: {\n html: {\n converter: async ({\n currentDepth,\n depth,\n draft,\n node,\n overrideAccess,\n req,\n showHiddenFields,\n }) => {\n // @ts-expect-error - for backwards-compatibility\n const id = node?.value?.id || node?.value\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,\n data: uploadDocument,\n depth,\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 = uploadDocument.value.sizes[size] as FileSizeImproved\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: [UploadServerNode.getType()],\n },\n },\n getSubFields: ({ node, req }) => {\n if (!node) {\n let allSubFields: Field[] = []\n for (const collection in props?.collections) {\n const collectionFields = props.collections[collection]!.fields\n allSubFields = allSubFields.concat(collectionFields)\n }\n return allSubFields\n }\n const collection = req ? req.payload.collections[node?.relationTo] : null\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 populateArg,\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 - Fix in Payload v4\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 select:\n populateArg?.[collection.config.slug] ?? collection.config.defaultPopulate,\n showHiddenFields,\n }),\n )\n\n return node\n },\n ],\n },\n node: UploadServerNode,\n validations: [uploadValidation(props)],\n }),\n ],\n sanitizedServerFeatureProps: props,\n }\n },\n key: 'upload',\n})\n"],"mappings":"AAWA,SAASA,cAAc,QAAQ;AAI/B,SAASC,QAAQ,QAAQ;AACzB,SAASC,mBAAmB,QAAQ;AACpC,SAASC,UAAU,QAAQ;AAC3B,SAASC,0BAA0B,QAAQ;AAC3C,SAASC,IAAI,QAAQ;AACrB,SAASC,gBAAgB,QAAQ;AACjC,SAASC,gBAAgB,QAAQ;AAiBjC;;;AAGA,SAASC,eAAeC,GAAW,EAAEC,OAAgB;EACnD,OAAOD,GAAA,EAAKE,UAAA,CAAW,UAAUF,GAAA,GAAM,CAACC,OAAA,EAASE,MAAA,EAAQC,SAAA,IAAa,EAAC,IAAKJ,GAAA;AAC9E;AAEA,OAAO,MAAMK,aAAA,GAAgBZ,mBAAA,CAI3B;EACAa,OAAA,EAAS,MAAAA,CAAO;IAAEH,MAAA,EAAQI,OAAO;IAAEC,MAAM;IAAEC,iBAAiB;IAAEC;EAAK,CAAE;IACnE,IAAI,CAACA,KAAA,EAAO;MACVA,KAAA,GAAQ;QAAEC,WAAA,EAAa,CAAC;MAAE;IAC5B;IAEA,MAAMC,WAAA,GAAwC;MAC5CD,WAAA,EAAa,CAAC;IAChB;IACA,IAAID,KAAA,CAAMC,WAAW,EAAE;MACrB,KAAK,MAAME,UAAA,IAAcH,KAAA,CAAMC,WAAW,EAAE;QAC1CC,WAAA,CAAYD,WAAW,CAACE,UAAA,CAAW,GAAG;UACpCC,cAAA,EAAgBJ,KAAA,CAAMC,WAAW,CAACE,UAAA,CAAW,CAAEE,M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YAAA;cACAY,IAAA,EAAMT,IAAA;cACNF,KAAA,EAAO2C,aAAA;cACP1C,KAAA;cACAW,GAAA,EAAK;cACLT,cAAA;cACAC,GAAA;cACA2C,MAAA,EACEN,WAAA,GAAc9D,UAAA,CAAWV,MAAM,CAACiB,IAAI,CAAC,IAAIP,UAAA,CAAWV,MAAM,CAAC+E,eAAe;cAC5E3C;YACF;YAGF,OAAOH,IAAA;UACT;QAEJ;QACAA,IAAA,EAAMvC,gBAAA;QACNsF,WAAA,EAAa,CAACrF,gBAAA,CAAiBY,KAAA;MACjC,GACD;MACD0E,2BAAA,EAA6B1E;IAC/B;EACF;EACAoC,GAAA,EAAK;AACP","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["sanitizeFields","populate","createServerFeature","createNode","uploadPopulationPromiseHOC","i18n","UploadServerNode","uploadValidation","getAbsoluteURL","url","payload","startsWith","config","serverURL","UploadFeature","feature","_config","isRoot","parentIsLocalized","props","collections","clientProps","disabledCollections","enabledCollections","collection","hasExtraFields","fields","length","validRelationships","map","c","slug","collectionKey","requireFieldLevelRichTextEditor","ClientFeature","clientFeatureProps","generateSchemaMap","schemaMap","Map","set","nodes","converters","html","converter","currentDepth","depth","draft","node","overrideAccess","req","showHiddenFields","id","value","uploadDocument","collectionSlug","relationTo","data","key","ignored","console","error","mimeType","filename","sizes","Object","keys","width","height","pictureHTML","size","imageSize","filesize","imageSizeURL","nodeTypes","getType","getSubFields","allSubFields","collectionFields","concat","collectionFieldSchema","Array","isArray","getSubFieldsData","graphQLPopulationPromises","hooks","afterRead","populateArg","populationPromises","populateDepth","maxDepth","undefined","push","select","defaultPopulate","validations","sanitizedServerFeatureProps"],"sources":["../../../../src/features/upload/server/index.ts"],"sourcesContent":["import type {\n Config,\n Field,\n FieldSchemaMap,\n FileData,\n FileSizeImproved,\n Payload,\n TypeWithID,\n UploadCollectionSlug,\n} from 'payload'\n\nimport { sanitizeFields } from 'payload'\n\nimport type { UploadFeaturePropsClient } from '../client/index.js'\n\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 { UploadServerNode } from './nodes/UploadNode.js'\nimport { uploadValidation } from './validate.js'\n\nexport type ExclusiveUploadFeatureProps =\n | {\n /**\n * The collections that should be disabled. Overrides the `enableRichTextRelationship` property in the collection config.\n * When this property is set, `enabledCollections` will not be available.\n **/\n disabledCollections?: UploadCollectionSlug[]\n\n // Ensures that enabledCollections is not available when disabledCollections is set\n enabledCollections?: never\n }\n | {\n // Ensures that disabledCollections is not available when enabledCollections is set\n disabledCollections?: never\n\n /**\n * The collections that should be enabled. Overrides the `enableRichTextRelationship` property in the collection config\n * When this property is set, `disabledCollections` will not be available.\n **/\n enabledCollections?: UploadCollectionSlug[]\n }\n\nexport type UploadFeatureProps = {\n collections?: {\n [collection: UploadCollectionSlug]: {\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} & ExclusiveUploadFeatureProps\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, parentIsLocalized, props }) => {\n if (!props) {\n props = { collections: {} }\n }\n\n const clientProps: UploadFeaturePropsClient = {\n collections: {},\n }\n if (props.disabledCollections) {\n clientProps.disabledCollections = props.disabledCollections\n }\n if (props.enabledCollections) {\n clientProps.enabledCollections = props.enabledCollections\n }\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 collectionKey in props.collections) {\n const collection = props.collections[collectionKey]!\n if (collection.fields?.length) {\n collection.fields = await sanitizeFields({\n config: _config as unknown as Config,\n fields: collection.fields,\n parentIsLocalized,\n requireFieldLevelRichTextEditor: isRoot,\n validRelationships,\n })\n }\n }\n\n return {\n ClientFeature: '@payloadcms/richtext-lexical/client#UploadFeatureClient',\n clientFeatureProps: clientProps,\n generateSchemaMap: ({ props }) => {\n if (!props?.collections) {\n return null\n }\n\n const schemaMap: FieldSchemaMap = new Map()\n\n for (const collectionKey in props.collections) {\n const collection = props.collections[collectionKey]!\n if (collection.fields?.length) {\n schemaMap.set(collectionKey, {\n fields: collection.fields,\n })\n }\n }\n\n return schemaMap\n },\n i18n,\n nodes: [\n createNode({\n converters: {\n html: {\n converter: async ({\n currentDepth,\n depth,\n draft,\n node,\n overrideAccess,\n req,\n showHiddenFields,\n }) => {\n // @ts-expect-error - for backwards-compatibility\n const id = node?.value?.id || node?.value\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,\n data: uploadDocument,\n depth,\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 = uploadDocument.value.sizes[size] as FileSizeImproved\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: [UploadServerNode.getType()],\n },\n },\n getSubFields: ({ node, req }) => {\n if (!node) {\n let allSubFields: Field[] = []\n for (const collection in props?.collections) {\n const collectionFields = props.collections[collection]!.fields\n allSubFields = allSubFields.concat(collectionFields)\n }\n return allSubFields\n }\n const collection = req ? req.payload.collections[node?.relationTo] : null\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 populateArg,\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 - Fix in Payload v4\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 select:\n populateArg?.[collection.config.slug] ?? collection.config.defaultPopulate,\n showHiddenFields,\n }),\n )\n\n return node\n },\n ],\n },\n node: UploadServerNode,\n validations: [uploadValidation(props)],\n }),\n ],\n sanitizedServerFeatureProps: props,\n }\n },\n key: 'upload',\n})\n"],"mappings":"AAWA,SAASA,cAAc,QAAQ;AAI/B,SAASC,QAAQ,QAAQ;AACzB,SAASC,mBAAmB,QAAQ;AACpC,SAASC,UAAU,QAAQ;AAC3B,SAASC,0BAA0B,QAAQ;AAC3C,SAASC,IAAI,QAAQ;AACrB,SAASC,gBAAgB,QAAQ;AACjC,SAASC,gBAAgB,QAAQ;AAuCjC;;;AAGA,SAASC,eAAeC,GAAW,EAAEC,OAAgB;EACnD,OAAOD,GAAA,EAAKE,UAAA,CAAW,UAAUF,GAAA,GAAM,CAACC,OAAA,EAASE,MAAA,EAAQC,SAAA,IAAa,EAAC,IAAKJ,GAAA;AAC9E;AAEA,OAAO,MAAMK,aAAA,GAAgBZ,mBAAA,CAI3B;EACAa,OAAA,EAAS,MAAAA,CAAO;IAAEH,MAAA,EAAQI,OAAO;IAAEC,MAAM;IAAEC,iBAAiB;IAAEC;EAAK,CAAE;IACnE,IAAI,CAACA,KAAA,EAAO;MACVA,KAAA,GAAQ;QAAEC,WAAA,EAAa,CAAC;MAAE;IAC5B;IAEA,MAAMC,WAAA,GAAwC;MAC5CD,WAAA,EAAa,CAAC;IAChB;IACA,IAAID,KAAA,CAAMG,mBAAmB,EAAE;MAC7BD,WAAA,CAAYC,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ACA;YACA,MAAMI,EAAA,GAAKJ,IAAA,EAAMK,KAAA,EAAOD,EAAA,IAAMJ,IAAA,EAAMK,KAAA,CAAM;YAAA;YAE1C,MAAMoC,aAAA,GACJrE,KAAA,EAAOsE,QAAA,KAAaC,SAAA,IAAavE,KAAA,EAAOsE,QAAA,GAAW5C,KAAA,GAAQ1B,KAAA,EAAOsE,QAAA,GAAW5C,KAAA;YAE/E0C,kBAAA,CAAmBI,IAAI,CACrB1F,QAAA,CAAS;cACPkD,EAAA;cACAG,cAAA,EAAgB9B,UAAA,CAAWZ,MAAM,CAACmB,IAAI;cACtCa,YAAA;cACAY,IAAA,EAAMT,IAAA;cACNF,KAAA,EAAO2C,aAAA;cACP1C,KAAA;cACAW,GAAA,EAAK;cACLT,cAAA;cACAC,GAAA;cACA2C,MAAA,EACEN,WAAA,GAAc9D,UAAA,CAAWZ,MAAM,CAACmB,IAAI,CAAC,IAAIP,UAAA,CAAWZ,MAAM,CAACiF,eAAe;cAC5E3C;YACF;YAGF,OAAOH,IAAA;UACT;QAEJ;QACAA,IAAA,EAAMzC,gBAAA;QACNwF,WAAA,EAAa,CAACvF,gBAAA,CAAiBY,KAAA;MACjC,GACD;MACD4E,2BAAA,EAA6B5E;IAC/B;EACF;EACAsC,GAAA,EAAK;AACP","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/richtext-lexical",
3
- "version": "3.60.0-canary.0",
3
+ "version": "3.60.0-canary.1",
4
4
  "description": "The officially supported Lexical richtext adapter for Payload",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -373,8 +373,8 @@
373
373
  "react-error-boundary": "4.1.2",
374
374
  "ts-essentials": "10.0.3",
375
375
  "uuid": "10.0.0",
376
- "@payloadcms/ui": "3.60.0-canary.0",
377
- "@payloadcms/translations": "3.60.0-canary.0"
376
+ "@payloadcms/translations": "3.60.0-canary.1",
377
+ "@payloadcms/ui": "3.60.0-canary.1"
378
378
  },
379
379
  "devDependencies": {
380
380
  "@babel/cli": "7.27.2",
@@ -394,15 +394,15 @@
394
394
  "esbuild-sass-plugin": "3.3.1",
395
395
  "swc-plugin-transform-remove-imports": "4.0.4",
396
396
  "@payloadcms/eslint-config": "3.28.0",
397
- "payload": "3.60.0-canary.0"
397
+ "payload": "3.60.0-canary.1"
398
398
  },
399
399
  "peerDependencies": {
400
400
  "@faceless-ui/modal": "3.0.0",
401
401
  "@faceless-ui/scroll-info": "2.0.0",
402
402
  "react": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
403
403
  "react-dom": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
404
- "@payloadcms/next": "3.60.0-canary.0",
405
- "payload": "3.60.0-canary.0"
404
+ "@payloadcms/next": "3.60.0-canary.1",
405
+ "payload": "3.60.0-canary.1"
406
406
  },
407
407
  "engines": {
408
408
  "node": "^18.20.2 || >=20.9.0"
@@ -1,2 +0,0 @@
1
- "use client";import{a as f}from"./chunk-DBWINSQN.js";import{a as b}from"./chunk-F26IQ5RE.js";import{jsx as t,jsxs as u}from"react/jsx-runtime";import{useLexicalComposerContext as S}from"@lexical/react/LexicalComposerContext.js";import{useLexicalEditable as j}from"@lexical/react/useLexicalEditable";import{getTranslation as B}from"@payloadcms/translations";import{Button as _,useConfig as L,usePayloadAPI as A,useTranslation as I}from"@payloadcms/ui";import{$getNodeByKey as P}from"lexical";import k,{useCallback as H,useReducer as K,useRef as M,useState as O}from"react";var e="lexical-relationship",g={depth:0},W=a=>{let{data:{relationTo:R,value:l},nodeKey:s}=a;if(typeof l=="object")throw new Error("Relationship value should be a string or number. The Lexical Relationship component should not receive the populated value object.");let C=M(null),[i]=S(),n=j(),{config:{routes:{api:v},serverURL:x},getEntityConfig:N}=L(),[o]=O(()=>N({collectionSlug:R})),{i18n:$,t:r}=I(),[m,w]=K(c=>c+1,0),[{data:d},{setParams:p}]=A(`${x}${v}/${o.slug}/${l}`,{initialParams:g}),{closeDocumentDrawer:h,DocumentDrawer:D,DocumentDrawerToggler:E}=b({id:l,collectionSlug:o.slug}),T=H(()=>{i.update(()=>{P(s)?.remove()})},[i,s]),y=k.useCallback(()=>{p({...g,cacheBust:m}),h(),w()},[m,p,h]);return u("div",{className:e,contentEditable:!1,ref:C,children:[u("div",{className:`${e}__wrap`,children:[t("p",{className:`${e}__label`,children:r("fields:labelRelationship",{label:o.labels?.singular?B(o.labels?.singular,$):o.slug})}),t(E,{className:`${e}__doc-drawer-toggler`,children:t("p",{className:`${e}__title`,children:d?d[o?.admin?.useAsTitle||"id"]:l})})]}),n&&u("div",{className:`${e}__actions`,children:[t(_,{buttonStyle:"icon-label",className:`${e}__swapButton`,disabled:!n,el:"button",icon:"swap",onClick:()=>{s&&i.dispatchCommand(f,{replace:{nodeKey:s}})},round:!0,tooltip:r("fields:swapRelationship")}),t(_,{buttonStyle:"icon-label",className:`${e}__removeButton`,disabled:!n,icon:"x",onClick:c=>{c.preventDefault(),T()},round:!0,tooltip:r("fields:removeRelationship")})]}),!!l&&t(D,{onSave:y})]})},Y=a=>t(W,{...a});export{Y as RelationshipComponent};
2
- //# sourceMappingURL=RelationshipComponent-TSIENULZ.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/features/relationship/client/components/RelationshipComponent.tsx"],
4
- "sourcesContent": ["'use client'\nimport type { ElementFormatType } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { useLexicalEditable } from '@lexical/react/useLexicalEditable'\nimport { getTranslation } from '@payloadcms/translations'\nimport { Button, useConfig, usePayloadAPI, useTranslation } from '@payloadcms/ui'\nimport { $getNodeByKey } from 'lexical'\nimport React, { useCallback, useReducer, useRef, useState } from 'react'\n\nimport type { RelationshipData } from '../../server/nodes/RelationshipNode.js'\n\nimport { useLexicalDocumentDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDocumentDrawer.js'\nimport './index.scss'\nimport { INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND } from '../drawer/commands.js'\n\nconst baseClass = 'lexical-relationship'\n\nconst initialParams = {\n depth: 0,\n}\n\ntype Props = {\n className?: string\n data: RelationshipData\n format?: ElementFormatType\n nodeKey?: string\n}\n\nconst Component: React.FC<Props> = (props) => {\n const {\n data: { relationTo, value },\n nodeKey,\n } = props\n\n if (typeof value === 'object') {\n throw new Error(\n 'Relationship value should be a string or number. The Lexical Relationship component should not receive the populated value object.',\n )\n }\n\n const relationshipElemRef = useRef<HTMLDivElement | null>(null)\n\n const [editor] = useLexicalComposerContext()\n const isEditable = useLexicalEditable()\n const {\n config: {\n routes: { api },\n serverURL,\n },\n getEntityConfig,\n } = useConfig()\n\n const [relatedCollection] = useState(() => getEntityConfig({ collectionSlug: relationTo }))\n\n const { i18n, t } = useTranslation()\n const [cacheBust, dispatchCacheBust] = useReducer((state) => state + 1, 0)\n const [{ data }, { setParams }] = usePayloadAPI(\n `${serverURL}${api}/${relatedCollection.slug}/${value}`,\n { initialParams },\n )\n\n const { closeDocumentDrawer, DocumentDrawer, DocumentDrawerToggler } = useLexicalDocumentDrawer({\n id: value,\n collectionSlug: relatedCollection.slug,\n })\n\n const removeRelationship = useCallback(() => {\n editor.update(() => {\n $getNodeByKey(nodeKey!)?.remove()\n })\n }, [editor, nodeKey])\n\n const updateRelationship = React.useCallback(() => {\n setParams({\n ...initialParams,\n cacheBust, // do this to get the usePayloadAPI to re-fetch the data even though the URL string hasn't changed\n })\n\n closeDocumentDrawer()\n dispatchCacheBust()\n }, [cacheBust, setParams, closeDocumentDrawer])\n\n return (\n <div className={baseClass} contentEditable={false} ref={relationshipElemRef}>\n <div className={`${baseClass}__wrap`}>\n <p className={`${baseClass}__label`}>\n {t('fields:labelRelationship', {\n label: relatedCollection.labels?.singular\n ? getTranslation(relatedCollection.labels?.singular, i18n)\n : relatedCollection.slug,\n })}\n </p>\n <DocumentDrawerToggler className={`${baseClass}__doc-drawer-toggler`}>\n <p className={`${baseClass}__title`}>\n {data ? data[relatedCollection?.admin?.useAsTitle || 'id'] : value}\n </p>\n </DocumentDrawerToggler>\n </div>\n {isEditable && (\n <div className={`${baseClass}__actions`}>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__swapButton`}\n disabled={!isEditable}\n el=\"button\"\n icon=\"swap\"\n onClick={() => {\n if (nodeKey) {\n editor.dispatchCommand(INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND, {\n replace: { nodeKey },\n })\n }\n }}\n round\n tooltip={t('fields:swapRelationship')}\n />\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={!isEditable}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeRelationship()\n }}\n round\n tooltip={t('fields:removeRelationship')}\n />\n </div>\n )}\n\n {!!value && <DocumentDrawer onSave={updateRelationship} />}\n </div>\n )\n}\n\nexport const RelationshipComponent = (props: Props): React.ReactNode => {\n return <Component {...props} />\n}\n"],
5
- "mappings": "+IAGA,OAASA,6BAAAA,MAAiC,2CAC1C,OAASC,sBAAAA,MAA0B,oCACnC,OAASC,kBAAAA,MAAsB,2BAC/B,OAASC,UAAAA,EAAQC,aAAAA,EAAWC,iBAAAA,EAAeC,kBAAAA,MAAsB,iBACjE,OAASC,iBAAAA,MAAqB,UAC9B,OAAOC,GAASC,eAAAA,EAAaC,cAAAA,EAAYC,UAAAA,EAAQC,YAAAA,MAAgB,QAQjE,IAAMC,EAAY,uBAEZC,EAAgB,CACpBC,MAAO,CACT,EASMC,EAA8BC,GAAA,CAClC,GAAM,CACJC,KAAM,CAAEC,WAAAA,EAAYC,MAAAA,CAAK,EACzBC,QAAAA,CAAO,EACLJ,EAEJ,GAAI,OAAOG,GAAU,SACnB,MAAM,IAAIE,MACR,oIAAA,EAIJ,IAAMC,EAAsBC,EAA8B,IAAA,EAEpD,CAACC,CAAA,EAAUC,EAAA,EACXC,EAAaC,EAAA,EACb,CACJC,OAAQ,CACNC,OAAQ,CAAEC,IAAAA,CAAG,EACbC,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,CAAEH,UAAW,GAAGhD,CAAA,mBACdK,EAAOA,EAAKiB,GAAmBkC,OAAOC,YAAc,IAAA,EAAQlD,SAIlEO,GACCiC,EAAC,MAAA,CAAIC,UAAW,GAAGhD,CAAA,sBACjBmD,EAACO,EAAA,CACCC,YAAY,aACZX,UAAW,GAAGhD,CAAA,eACd4D,SAAU,CAAC9C,EACX+C,GAAG,SACHC,KAAK,OACLC,QAASA,IAAA,CACHvD,GACFI,EAAOoD,gBAAgBC,EAAyC,CAC9DC,QAAS,CAAE1D,QAAAA,CAAQ,CACrB,CAAA,CAEJ,EACA2D,MAAK,GACLC,QAAS1C,EAAE,yBAAA,IAEbyB,EAACO,EAAA,CACCC,YAAY,aACZX,UAAW,GAAGhD,CAAA,iBACd4D,SAAU,CAAC9C,EACXgD,KAAK,IACLC,QAAUM,GAAA,CACRA,EAAEC,eAAc,EAChB9B,EAAA,CACF,EACA2B,MAAK,GACLC,QAAS1C,EAAE,2BAAA,OAKhB,CAAC,CAACnB,GAAS4C,EAACf,EAAA,CAAemC,OAAQ1B,MAG1C,EAEa2B,EAAyBpE,GAC7B+C,EAAChD,EAAA,CAAW,GAAGC",
6
- "names": ["useLexicalComposerContext", "useLexicalEditable", "getTranslation", "Button", "useConfig", "usePayloadAPI", "useTranslation", "$getNodeByKey", "React", "useCallback", "useReducer", "useRef", "useState", "baseClass", "initialParams", "depth", "Component", "props", "data", "relationTo", "value", "nodeKey", "Error", "relationshipElemRef", "useRef", "editor", "useLexicalComposerContext", "isEditable", "useLexicalEditable", "config", "routes", "api", "serverURL", "getEntityConfig", "useConfig", "relatedCollection", "useState", "collectionSlug", "i18n", "t", "useTranslation", "cacheBust", "dispatchCacheBust", "useReducer", "state", "setParams", "usePayloadAPI", "slug", "closeDocumentDrawer", "DocumentDrawer", "DocumentDrawerToggler", "useLexicalDocumentDrawer", "id", "removeRelationship", "useCallback", "update", "$getNodeByKey", "remove", "updateRelationship", "React", "_jsxs", "className", "contentEditable", "ref", "_jsx", "label", "labels", "singular", "getTranslation", "admin", "useAsTitle", "Button", "buttonStyle", "disabled", "el", "icon", "onClick", "dispatchCommand", "INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND", "replace", "round", "tooltip", "e", "preventDefault", "onSave", "RelationshipComponent"]
7
- }
@@ -1,2 +0,0 @@
1
- import{b as F}from"./chunk-BZZVLW4U.js";import{c as z}from"react/compiler-runtime";import{jsx as R}from"react/jsx-runtime";import{Drawer as G,EditDepthProvider as J,useModal as K}from"@payloadcms/ui";import"react";import{jsx as y,jsxs as M}from"react/jsx-runtime";import{useLexicalEditable as v}from"@lexical/react/useLexicalEditable";import{Form as T,FormSubmit as $,RenderFields as N,useDocumentForm as W,useDocumentInfo as k,useServerFunctions as B,useTranslation as L}from"@payloadcms/ui";import{abortAndIgnore as x}from"@payloadcms/ui/shared";import{deepCopyObjectSimpleWithoutReactComponents as O}from"payload/shared";import{useCallback as H,useEffect as I,useRef as U,useState as V}from"react";import{v4 as q}from"uuid";var j=({data:c,featureKey:e,fieldMapOverride:u,handleDrawerSubmit:m,schemaFieldsPathOverride:o,schemaPath:d,schemaPathSuffix:f})=>{let{t:p}=L(),{id:i,collectionSlug:a,getDocPreferences:l,globalSlug:s}=k(),{fields:t}=W(),n=v(),r=U(new AbortController),[h,w]=V(!1),{fieldProps:{featureClientSchemaMap:A}}=F(),{getFormState:b}=B(),S=o??`${d}.lexical_internal_feature.${e}${f?`.${f}`:""}`,g=u??A[e]?.[S];I(()=>{let C=new AbortController;return(async()=>{let{state:_}=await b({id:i,collectionSlug:a,data:c??{},docPermissions:{fields:!0},docPreferences:await l(),documentFormState:O(t),globalSlug:s,initialBlockData:c,operation:"update",readOnly:!n,renderAllFields:!0,schemaPath:S,signal:C.signal});w(_)})(),()=>{x(C)}},[S,i,c,b,a,n,s,l,t]);let E=H(async({formState:C})=>{x(r.current);let P=new AbortController;r.current=P;let{state:_}=await b({id:i,collectionSlug:a,docPermissions:{fields:!0},docPreferences:await l(),documentFormState:O(t),formState:C,globalSlug:s,initialBlockFormState:C,operation:"update",readOnly:!n,schemaPath:S,signal:P.signal});return _||C},[b,i,n,a,l,t,s,S]);return I(()=>()=>{x(r.current)},[]),h===!1?null:M(T,{beforeSubmit:[E],disableValidationOnSubmit:!0,fields:Array.isArray(g)?g:[],initialState:h,onChange:[E],onSubmit:m,uuid:q(),children:[y(N,{fields:Array.isArray(g)?g:[],forceRender:!0,parentIndexPath:"",parentPath:"",parentSchemaPath:S,permissions:!0,readOnly:!n}),y($,{children:p("fields:saveChanges")})]})};var _e=c=>{let e=z(15),{className:u,data:m,drawerSlug:o,drawerTitle:d,featureKey:f,fieldMapOverride:p,handleDrawerSubmit:i,schemaFieldsPathOverride:a,schemaPath:l,schemaPathSuffix:s}=c,{closeModal:t}=K(),n=d??"",r;e[0]!==t||e[1]!==o||e[2]!==i?(r=(w,A)=>{t(o),setTimeout(()=>{i(w,A)},1)},e[0]=t,e[1]=o,e[2]=i,e[3]=r):r=e[3];let h;return e[4]!==u||e[5]!==m||e[6]!==o||e[7]!==f||e[8]!==p||e[9]!==a||e[10]!==l||e[11]!==s||e[12]!==n||e[13]!==r?(h=R(J,{children:R(G,{className:u,slug:o,title:n,children:R(j,{data:m,featureKey:f,fieldMapOverride:p,handleDrawerSubmit:r,schemaFieldsPathOverride:a,schemaPath:l,schemaPathSuffix:s})})}),e[4]=u,e[5]=m,e[6]=o,e[7]=f,e[8]=p,e[9]=a,e[10]=l,e[11]=s,e[12]=n,e[13]=r,e[14]=h):h=e[14],h};import{c as Q}from"react/compiler-runtime";import{jsx as X}from"react/jsx-runtime";import{useAuth as Y,useConfig as Z,useEntityVisibility as ee}from"@payloadcms/ui";import*as D from"react";var te=(c,e)=>c.filter(({slug:u,admin:{enableRichTextRelationship:m},upload:o})=>e?.visibleEntities?.collections.includes(u)?e?.uploads?m&&!!o:o?!1:m:!1),xe=c=>{let e=Q(12),{children:u,FallbackComponent:m,uploads:o,...d}=c,f=o===void 0?!1:o,{config:p}=Z(),{collections:i}=p,{user:a}=Y(),{visibleEntities:l}=ee(),s;e[0]!==i||e[1]!==f||e[2]!==a||e[3]!==l?(s=()=>te(i,{uploads:f,user:a,visibleEntities:l}).map(re),e[0]=i,e[1]=f,e[2]=a,e[3]=l,e[4]=s):s=e[4];let[t]=D.useState(s);if(!t.length)return m?X(m,{...d}):null;let n;if(e[5]!==u||e[6]!==t||e[7]!==d){let r;e[9]!==t||e[10]!==d?(r={...d,enabledCollectionSlugs:t},e[9]=t,e[10]=d,e[11]=r):r=e[11],n=D.cloneElement(u,r),e[5]=u,e[6]=t,e[7]=d,e[8]=n}else n=e[8];return n};function re(c){let{slug:e}=c;return e}import{createCommand as oe}from"lexical";var Fe=oe("INSERT_UPLOAD_WITH_DRAWER_COMMAND");export{_e as a,xe as b,Fe as c};
2
- //# sourceMappingURL=chunk-BQCXN3B4.js.map
@@ -1,2 +0,0 @@
1
- "use client";import{a as S,b as y,c as R}from"./chunk-BQCXN3B4.js";import{a as x}from"./chunk-INBEEENE.js";import{a as N}from"./chunk-F26IQ5RE.js";import{b as p}from"./chunk-BZZVLW4U.js";import{jsx as t,jsxs as n}from"react/jsx-runtime";import{useLexicalComposerContext as Y}from"@lexical/react/LexicalComposerContext.js";import{useLexicalEditable as Z}from"@lexical/react/useLexicalEditable";import{getTranslation as E}from"@payloadcms/translations";import{Button as h,formatDrawerSlug as ee,Thumbnail as te,useConfig as oe,useEditDepth as ae,usePayloadAPI as le,useTranslation as ie}from"@payloadcms/ui";import{$getNodeByKey as L}from"lexical";import{isImage as re}from"payload/shared";import{useCallback as f,useId as se,useReducer as ne,useRef as de,useState as ce}from"react";var e="lexical-upload",P={depth:0},ue=d=>{let{data:{fields:T,relationTo:g,value:c},nodeKey:l}=d;if(typeof c=="object")throw new Error("Upload value should be a string or number. The Lexical Upload component should not receive the populated value object.");let{config:{routes:{api:U},serverURL:F},getEntityConfig:j}=oe(),I=de(null),{uuid:z}=p(),B=ae(),[i]=Y(),{editorConfig:k,fieldProps:{schemaPath:A}}=p(),u=Z(),{i18n:_,t:r}=ie(),[b,K]=ne(s=>s+1,0),[a]=ce(()=>j({collectionSlug:g})),M=se(),w=ee({slug:"lexical-upload-drawer-"+z+M,depth:B}),{toggleDrawer:O}=x(w,!0),{closeDocumentDrawer:D,DocumentDrawer:W,DocumentDrawerToggler:H}=N({id:c,collectionSlug:a.slug}),[{data:o},{setParams:v}]=le(`${F}${U}/${a.slug}/${c}`,{initialParams:P}),C=o?.thumbnailURL||o?.url,q=f(()=>{i.update(()=>{L(l)?.remove()})},[i,l]),G=f(s=>{v({...P,cacheBust:b}),K(),D()},[v,b,D]),$=k?.resolvedFeatureMap?.get("upload")?.sanitizedClientFeatureProps.collections?.[a.slug]?.hasExtraFields,J=f((s,V)=>{i.update(()=>{let m=L(l);if(m){let X={...m.getData(),fields:V};m.setData(X)}})},[i,l]),Q=C&&o?.width&&o?.height?o.width>o.height?"landscape":"portrait":"landscape";return n("div",{className:`${e} ${e}--${Q}`,"data-filename":o?.filename,ref:I,children:[n("div",{className:`${e}__card`,children:[n("div",{className:`${e}__media`,children:[t(te,{collectionSlug:g,fileSrc:re(o?.mimeType)?C:null,height:o?.height,size:"none",width:o?.width}),u&&t("div",{className:`${e}__overlay ${e}__floater`,children:n("div",{className:`${e}__actions`,role:"toolbar",children:[$?t(h,{buttonStyle:"icon-label",className:`${e}__upload-drawer-toggler`,disabled:!u,el:"button",icon:"edit",onClick:O,round:!0,size:"medium",tooltip:r("fields:editRelationship")}):null,t(h,{buttonStyle:"icon-label",className:`${e}__swap-drawer-toggler`,disabled:!u,el:"button",icon:"swap",onClick:()=>{i.dispatchCommand(R,{replace:{nodeKey:l}})},round:!0,size:"medium",tooltip:r("fields:swapUpload")}),t(h,{buttonStyle:"icon-label",className:`${e}__removeButton`,disabled:!u,icon:"x",onClick:s=>{s.preventDefault(),q()},round:!0,size:"medium",tooltip:r("fields:removeUpload")})]})})]}),n("div",{className:`${e}__metaOverlay ${e}__floater`,children:[t(H,{className:`${e}__doc-drawer-toggler`,children:t("strong",{className:`${e}__filename`,children:o?.filename||r("general:untitled")})}),t("div",{className:`${e}__collectionLabel`,children:E(a.labels.singular,_)})]})]}),c?t(W,{onSave:G}):null,$?t(S,{data:T,drawerSlug:w,drawerTitle:r("general:editLabel",{label:E(a.labels.singular,_)}),featureKey:"upload",handleDrawerSubmit:J,schemaPath:A,schemaPathSuffix:a.slug}):null]})},ye=d=>t(y,{...d,uploads:!0,children:t(ue,{...d})});export{ye as UploadComponent};
2
- //# sourceMappingURL=component-CYFKY3IL.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/features/upload/client/component/index.tsx"],
4
- "sourcesContent": ["'use client'\nimport type { ClientCollectionConfig, Data, FormState, JsonObject } from 'payload'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { useLexicalEditable } from '@lexical/react/useLexicalEditable'\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n Button,\n formatDrawerSlug,\n Thumbnail,\n useConfig,\n useEditDepth,\n usePayloadAPI,\n useTranslation,\n} from '@payloadcms/ui'\nimport { $getNodeByKey, type ElementFormatType } from 'lexical'\nimport { isImage } from 'payload/shared'\nimport React, { useCallback, useId, useReducer, useRef, useState } from 'react'\n\nimport type { BaseClientFeatureProps } from '../../../typesClient.js'\nimport type { UploadData } from '../../server/nodes/UploadNode.js'\nimport type { UploadFeaturePropsClient } from '../index.js'\nimport type { UploadNode } from '../nodes/UploadNode.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport { FieldsDrawer } from '../../../../utilities/fieldsDrawer/Drawer.js'\nimport { useLexicalDocumentDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDocumentDrawer.js'\nimport { useLexicalDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDrawer.js'\nimport { EnabledRelationshipsCondition } from '../../../relationship/client/utils/EnabledRelationshipsCondition.js'\nimport './index.scss'\nimport { INSERT_UPLOAD_WITH_DRAWER_COMMAND } from '../drawer/commands.js'\n\nconst baseClass = 'lexical-upload'\n\nconst initialParams = {\n depth: 0,\n}\n\nexport type ElementProps = {\n data: UploadData\n format?: ElementFormatType\n nodeKey: string\n}\n\nconst Component: React.FC<ElementProps> = (props) => {\n const {\n data: { fields, relationTo, value },\n nodeKey,\n } = props\n\n if (typeof value === 'object') {\n throw new Error(\n 'Upload value should be a string or number. The Lexical Upload component should not receive the populated value object.',\n )\n }\n\n const {\n config: {\n routes: { api },\n serverURL,\n },\n getEntityConfig,\n } = useConfig()\n const uploadRef = useRef<HTMLDivElement | null>(null)\n const { uuid } = useEditorConfigContext()\n const editDepth = useEditDepth()\n const [editor] = useLexicalComposerContext()\n\n const {\n editorConfig,\n fieldProps: { schemaPath },\n } = useEditorConfigContext()\n const isEditable = useLexicalEditable()\n const { i18n, t } = useTranslation()\n const [cacheBust, dispatchCacheBust] = useReducer((state) => state + 1, 0)\n const [relatedCollection] = useState<ClientCollectionConfig>(() =>\n getEntityConfig({ collectionSlug: relationTo }),\n )\n\n const componentID = useId()\n\n const extraFieldsDrawerSlug = formatDrawerSlug({\n slug: `lexical-upload-drawer-` + uuid + componentID, // There can be multiple upload components, each with their own drawer, in one single editor => separate them by componentID\n depth: editDepth,\n })\n\n // Need to use hook to initialize useEffect that restores cursor position\n const { toggleDrawer } = useLexicalDrawer(extraFieldsDrawerSlug, true)\n\n const { closeDocumentDrawer, DocumentDrawer, DocumentDrawerToggler } = useLexicalDocumentDrawer({\n id: value,\n collectionSlug: relatedCollection.slug,\n })\n\n // Get the referenced document\n const [{ data }, { setParams }] = usePayloadAPI(\n `${serverURL}${api}/${relatedCollection.slug}/${value}`,\n { initialParams },\n )\n\n const thumbnailSRC = data?.thumbnailURL || data?.url\n\n const removeUpload = useCallback(() => {\n editor.update(() => {\n $getNodeByKey(nodeKey)?.remove()\n })\n }, [editor, nodeKey])\n\n const updateUpload = useCallback(\n (data: Data) => {\n setParams({\n ...initialParams,\n cacheBust, // do this to get the usePayloadAPI to re-fetch the data even though the URL string hasn't changed\n })\n\n dispatchCacheBust()\n closeDocumentDrawer()\n },\n [setParams, cacheBust, closeDocumentDrawer],\n )\n\n const hasExtraFields = (\n editorConfig?.resolvedFeatureMap?.get('upload')\n ?.sanitizedClientFeatureProps as BaseClientFeatureProps<UploadFeaturePropsClient>\n ).collections?.[relatedCollection.slug]?.hasExtraFields\n\n const onExtraFieldsDrawerSubmit = useCallback(\n (_: FormState, data: JsonObject) => {\n // Update lexical node (with key nodeKey) with new data\n editor.update(() => {\n const uploadNode: null | UploadNode = $getNodeByKey(nodeKey)\n if (uploadNode) {\n const newData: UploadData = {\n ...uploadNode.getData(),\n fields: data,\n }\n uploadNode.setData(newData)\n }\n })\n },\n [editor, nodeKey],\n )\n\n const aspectRatio =\n thumbnailSRC && data?.width && data?.height\n ? data.width > data.height\n ? 'landscape'\n : 'portrait'\n : 'landscape'\n\n return (\n <div\n className={`${baseClass} ${baseClass}--${aspectRatio}`}\n data-filename={data?.filename}\n ref={uploadRef}\n >\n <div className={`${baseClass}__card`}>\n <div className={`${baseClass}__media`}>\n <Thumbnail\n collectionSlug={relationTo}\n fileSrc={isImage(data?.mimeType) ? thumbnailSRC : null}\n height={data?.height}\n size=\"none\"\n width={data?.width}\n />\n\n {isEditable && (\n <div className={`${baseClass}__overlay ${baseClass}__floater`}>\n <div className={`${baseClass}__actions`} role=\"toolbar\">\n {hasExtraFields ? (\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__upload-drawer-toggler`}\n disabled={!isEditable}\n el=\"button\"\n icon=\"edit\"\n onClick={toggleDrawer}\n round\n size=\"medium\"\n tooltip={t('fields:editRelationship')}\n />\n ) : null}\n\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__swap-drawer-toggler`}\n disabled={!isEditable}\n el=\"button\"\n icon=\"swap\"\n onClick={() => {\n editor.dispatchCommand(INSERT_UPLOAD_WITH_DRAWER_COMMAND, {\n replace: { nodeKey },\n })\n }}\n round\n size=\"medium\"\n tooltip={t('fields:swapUpload')}\n />\n\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={!isEditable}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeUpload()\n }}\n round\n size=\"medium\"\n tooltip={t('fields:removeUpload')}\n />\n </div>\n </div>\n )}\n </div>\n\n <div className={`${baseClass}__metaOverlay ${baseClass}__floater`}>\n <DocumentDrawerToggler className={`${baseClass}__doc-drawer-toggler`}>\n <strong className={`${baseClass}__filename`}>\n {data?.filename || t('general:untitled')}\n </strong>\n </DocumentDrawerToggler>\n <div className={`${baseClass}__collectionLabel`}>\n {getTranslation(relatedCollection.labels.singular, i18n)}\n </div>\n </div>\n </div>\n\n {value ? <DocumentDrawer onSave={updateUpload} /> : null}\n {hasExtraFields ? (\n <FieldsDrawer\n data={fields}\n drawerSlug={extraFieldsDrawerSlug}\n drawerTitle={t('general:editLabel', {\n label: getTranslation(relatedCollection.labels.singular, i18n),\n })}\n featureKey=\"upload\"\n handleDrawerSubmit={onExtraFieldsDrawerSubmit}\n schemaPath={schemaPath}\n schemaPathSuffix={relatedCollection.slug}\n />\n ) : null}\n </div>\n )\n}\n\nexport const UploadComponent = (props: ElementProps): React.ReactNode => {\n return (\n <EnabledRelationshipsCondition {...props} uploads>\n <Component {...props} />\n </EnabledRelationshipsCondition>\n )\n}\n"],
5
- "mappings": "6OAGA,OAASA,6BAAAA,MAAiC,2CAC1C,OAASC,sBAAAA,MAA0B,oCACnC,OAASC,kBAAAA,MAAsB,2BAC/B,OACEC,UAAAA,EACAC,oBAAAA,GACAC,aAAAA,GACAC,aAAAA,GACAC,gBAAAA,GACAC,iBAAAA,GACAC,kBAAAA,OACK,iBACP,OAASC,iBAAAA,MAA6C,UACtD,OAASC,WAAAA,OAAe,iBACxB,OAAgBC,eAAAA,EAAaC,SAAAA,GAAOC,cAAAA,GAAYC,UAAAA,GAAQC,YAAAA,OAAgB,QAexE,IAAMC,EAAY,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A+E,WAAW,SACXC,mBAAoB1C,EACpBzC,WAAYA,EACZoF,iBAAkB1E,EAAkBO,OAEpC,IAAA,GAGV,EAEaoE,GAAmB5G,GAE5B6E,EAACgC,EAAA,CAA+B,GAAG7G,EAAO8G,QAAO,YAC/CjC,EAAC9E,GAAA,CAAW,GAAGC",
6
- "names": ["useLexicalComposerContext", "useLexicalEditable", "getTranslation", "Button", "formatDrawerSlug", "Thumbnail", "useConfig", "useEditDepth", "usePayloadAPI", "useTranslation", "$getNodeByKey", "isImage", "useCallback", "useId", "useReducer", "useRef", "useState", "baseClass", "initialParams", "depth", "Component", "props", "data", "fields", "relationTo", "value", "nodeKey", "Error", "config", "routes", "api", "serverURL", "getEntityConfig", "useConfig", "uploadRef", "useRef", "uuid", "useEditorConfigContext", "editDepth", "useEditDepth", "editor", "useLexicalComposerContext", "editorConfig", "fieldProps", "schemaPath", "isEditable", "useLexicalEditable", "i18n", "t", "useTranslation", "cacheBust", "dispatchCacheBust", "useReducer", "state", "relatedCollection", "useState", "collectionSlug", "componentID", "useId", "extraFieldsDrawerSlug", "formatDrawerSlug", "slug", "toggleDrawer", "useLexicalDrawer", "closeDocumentDrawer", "DocumentDrawer", "DocumentDrawerToggler", "useLexicalDocumentDrawer", "id", "setParams", "usePayloadAPI", "thumbnailSRC", "thumbnailURL", "url", "removeUpload", "useCallback", "update", "$getNodeByKey", "remove", "updateUpload", "hasExtraFields", "resolvedFeatureMap", "get", "sanitizedClientFeatureProps", "collections", "onExtraFieldsDrawerSubmit", "_", "uploadNode", "newData", "getData", "setData", "aspectRatio", "width", "height", "_jsxs", "className", "filename", "ref", "_jsx", "Thumbnail", "fileSrc", "isImage", "mimeType", "size", "role", "Button", "buttonStyle", "disabled", "el", "icon", "onClick", "round", "tooltip", "dispatchCommand", "INSERT_UPLOAD_WITH_DRAWER_COMMAND", "replace", "e", "preventDefault", "getTranslation", "labels", "singular", "onSave", "FieldsDrawer", "drawerSlug", "drawerTitle", "label", "featureKey", "handleDrawerSubmit", "schemaPathSuffix", "UploadComponent", "EnabledRelationshipsCondition", "uploads"]
7
- }
@@ -1,7 +0,0 @@
1
- import * as React from 'react';
2
- export declare const EnabledRelationshipsCondition: React.FC<{
3
- children: any;
4
- FallbackComponent?: React.FC;
5
- uploads?: boolean;
6
- }>;
7
- //# sourceMappingURL=EnabledRelationshipsCondition.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EnabledRelationshipsCondition.d.ts","sourceRoot":"","sources":["../../../../../src/features/relationship/client/utils/EnabledRelationshipsCondition.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AA2B9B,eAAO,MAAM,6BAA6B,EAAE,KAAK,CAAC,EAAE,CAAC;IACnD,QAAQ,EAAE,GAAG,CAAA;IACb,iBAAiB,CAAC,EAAE,KAAK,CAAC,EAAE,CAAA;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAmBA,CAAA"}
@@ -1,96 +0,0 @@
1
- 'use client';
2
-
3
- import { c as _c } from "react/compiler-runtime";
4
- import { jsx as _jsx } from "react/jsx-runtime";
5
- import { useAuth, useConfig, useEntityVisibility } from '@payloadcms/ui';
6
- import * as React from 'react';
7
- const filterRichTextCollections = (collections, options) => {
8
- return collections.filter(({
9
- slug,
10
- admin: {
11
- enableRichTextRelationship
12
- },
13
- upload
14
- }) => {
15
- if (!options?.visibleEntities?.collections.includes(slug)) {
16
- return false;
17
- }
18
- if (options?.uploads) {
19
- return enableRichTextRelationship && Boolean(upload) === true;
20
- }
21
- return upload ? false : enableRichTextRelationship;
22
- });
23
- };
24
- export const EnabledRelationshipsCondition = props => {
25
- const $ = _c(12);
26
- const {
27
- children,
28
- FallbackComponent,
29
- uploads: t0,
30
- ...rest
31
- } = props;
32
- const uploads = t0 === undefined ? false : t0;
33
- const {
34
- config: t1
35
- } = useConfig();
36
- const {
37
- collections
38
- } = t1;
39
- const {
40
- user
41
- } = useAuth();
42
- const {
43
- visibleEntities
44
- } = useEntityVisibility();
45
- let t2;
46
- if ($[0] !== collections || $[1] !== uploads || $[2] !== user || $[3] !== visibleEntities) {
47
- t2 = () => filterRichTextCollections(collections, {
48
- uploads,
49
- user,
50
- visibleEntities
51
- }).map(_temp);
52
- $[0] = collections;
53
- $[1] = uploads;
54
- $[2] = user;
55
- $[3] = visibleEntities;
56
- $[4] = t2;
57
- } else {
58
- t2 = $[4];
59
- }
60
- const [enabledCollectionSlugs] = React.useState(t2);
61
- if (!enabledCollectionSlugs.length) {
62
- return FallbackComponent ? _jsx(FallbackComponent, {
63
- ...rest
64
- }) : null;
65
- }
66
- let t3;
67
- if ($[5] !== children || $[6] !== enabledCollectionSlugs || $[7] !== rest) {
68
- let t4;
69
- if ($[9] !== enabledCollectionSlugs || $[10] !== rest) {
70
- t4 = {
71
- ...rest,
72
- enabledCollectionSlugs
73
- };
74
- $[9] = enabledCollectionSlugs;
75
- $[10] = rest;
76
- $[11] = t4;
77
- } else {
78
- t4 = $[11];
79
- }
80
- t3 = React.cloneElement(children, t4);
81
- $[5] = children;
82
- $[6] = enabledCollectionSlugs;
83
- $[7] = rest;
84
- $[8] = t3;
85
- } else {
86
- t3 = $[8];
87
- }
88
- return t3;
89
- };
90
- function _temp(t0) {
91
- const {
92
- slug
93
- } = t0;
94
- return slug;
95
- }
96
- //# sourceMappingURL=EnabledRelationshipsCondition.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EnabledRelationshipsCondition.js","names":["c","_c","useAuth","useConfig","useEntityVisibility","React","filterRichTextCollections","collections","options","filter","slug","admin","enableRichTextRelationship","upload","visibleEntities","includes","uploads","Boolean","EnabledRelationshipsCondition","props","$","children","FallbackComponent","t0","rest","undefined","config","t1","user","t2","map","_temp","enabledCollectionSlugs","useState","length","_jsx","t3","t4","cloneElement"],"sources":["../../../../../src/features/relationship/client/utils/EnabledRelationshipsCondition.tsx"],"sourcesContent":["'use client'\nimport type { ClientCollectionConfig, ClientUser, VisibleEntities } from 'payload'\n\nimport { useAuth, useConfig, useEntityVisibility } from '@payloadcms/ui'\nimport * as React from 'react'\n\ntype Options = {\n uploads: boolean\n user: ClientUser\n visibleEntities?: VisibleEntities\n}\n\ntype FilteredCollectionsT = (\n collections: ClientCollectionConfig[],\n options?: Options,\n) => ClientCollectionConfig[]\n\nconst filterRichTextCollections: FilteredCollectionsT = (collections, options) => {\n return collections.filter(({ slug, admin: { enableRichTextRelationship }, upload }) => {\n if (!options?.visibleEntities?.collections.includes(slug)) {\n return false\n }\n\n if (options?.uploads) {\n return enableRichTextRelationship && Boolean(upload) === true\n }\n\n return upload ? false : enableRichTextRelationship\n })\n}\n\nexport const EnabledRelationshipsCondition: React.FC<{\n children: any\n FallbackComponent?: React.FC\n uploads?: boolean\n}> = (props) => {\n const { children, FallbackComponent, uploads = false, ...rest } = props\n const {\n config: { collections },\n } = useConfig()\n const { user } = useAuth()\n const { visibleEntities } = useEntityVisibility()\n\n const [enabledCollectionSlugs] = React.useState(() =>\n filterRichTextCollections(collections, { uploads, user: user!, visibleEntities }).map(\n ({ slug }) => slug,\n ),\n )\n\n if (!enabledCollectionSlugs.length) {\n return FallbackComponent ? <FallbackComponent {...rest} /> : null\n }\n\n return React.cloneElement(children, { ...rest, enabledCollectionSlugs })\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAGA,SAASC,OAAO,EAAEC,SAAS,EAAEC,mBAAmB,QAAQ;AACxD,YAAYC,KAAA,MAAW;AAavB,MAAMC,yBAAA,GAAkDA,CAACC,WAAA,EAAaC,OAAA;EACpE,OAAOD,WAAA,CAAYE,MAAM,CAAC,CAAC;IAAEC,IAAI;IAAEC,KAAA,EAAO;MAAEC;IAA0B,CAAE;IAAEC;EAAM,CAAE;IAChF,IAAI,CAACL,OAAA,EAASM,eAAA,EAAiBP,WAAA,CAAYQ,QAAA,CAASL,IAAA,GAAO;MACzD,OAAO;IACT;IAEA,IAAIF,OAAA,EAASQ,OAAA,EAAS;MACpB,OAAOJ,0BA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