@payloadcms/richtext-lexical 4.0.0-internal.b6f3b9a → 4.0.0-internal.b8a92d2

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 (202) hide show
  1. package/dist/exports/client/Field-QKAL7KMC.js +2 -0
  2. package/dist/exports/client/Field-QKAL7KMC.js.map +7 -0
  3. package/dist/exports/client/bundled.css +1 -1
  4. package/dist/exports/client/chunk-LN6VX25I.js +2 -0
  5. package/dist/exports/client/{chunk-SSMQFWCQ.js.map → chunk-LN6VX25I.js.map} +4 -4
  6. package/dist/exports/client/index.js +26 -26
  7. package/dist/exports/client/index.js.map +4 -4
  8. package/dist/features/blocks/server/index.js +2 -2
  9. package/dist/features/blocks/server/index.js.map +1 -1
  10. package/dist/features/converters/lexicalToHtml/async/converters/heading.js +1 -1
  11. package/dist/features/converters/lexicalToHtml/async/converters/heading.js.map +1 -1
  12. package/dist/features/converters/lexicalToHtml/async/converters/list.d.ts.map +1 -1
  13. package/dist/features/converters/lexicalToHtml/async/converters/list.js +4 -3
  14. package/dist/features/converters/lexicalToHtml/async/converters/list.js.map +1 -1
  15. package/dist/features/converters/lexicalToHtml/shared/findConverterForNode.d.ts.map +1 -1
  16. package/dist/features/converters/lexicalToHtml/shared/findConverterForNode.js +3 -2
  17. package/dist/features/converters/lexicalToHtml/shared/findConverterForNode.js.map +1 -1
  18. package/dist/features/converters/lexicalToHtml/sync/converters/heading.js +1 -1
  19. package/dist/features/converters/lexicalToHtml/sync/converters/heading.js.map +1 -1
  20. package/dist/features/converters/lexicalToHtml/sync/converters/list.d.ts.map +1 -1
  21. package/dist/features/converters/lexicalToHtml/sync/converters/list.js +4 -3
  22. package/dist/features/converters/lexicalToHtml/sync/converters/list.js.map +1 -1
  23. package/dist/features/converters/lexicalToJSX/converter/converters/heading.d.ts.map +1 -1
  24. package/dist/features/converters/lexicalToJSX/converter/converters/heading.js +2 -1
  25. package/dist/features/converters/lexicalToJSX/converter/converters/heading.js.map +1 -1
  26. package/dist/features/converters/lexicalToJSX/converter/converters/list.d.ts.map +1 -1
  27. package/dist/features/converters/lexicalToJSX/converter/converters/list.js +2 -1
  28. package/dist/features/converters/lexicalToJSX/converter/converters/list.js.map +1 -1
  29. package/dist/features/heading/constants.d.ts +2 -0
  30. package/dist/features/heading/constants.d.ts.map +1 -0
  31. package/dist/features/heading/constants.js +2 -0
  32. package/dist/features/heading/constants.js.map +1 -0
  33. package/dist/features/heading/server/index.d.ts.map +1 -1
  34. package/dist/features/heading/server/index.js +5 -1
  35. package/dist/features/heading/server/index.js.map +1 -1
  36. package/dist/features/heading/server/validate.d.ts +6 -0
  37. package/dist/features/heading/server/validate.d.ts.map +1 -0
  38. package/dist/features/heading/server/validate.js +15 -0
  39. package/dist/features/heading/server/validate.js.map +1 -0
  40. package/dist/features/link/server/index.js +2 -2
  41. package/dist/features/link/server/index.js.map +1 -1
  42. package/dist/features/lists/checklist/server/index.d.ts.map +1 -1
  43. package/dist/features/lists/checklist/server/index.js +5 -2
  44. package/dist/features/lists/checklist/server/index.js.map +1 -1
  45. package/dist/features/lists/orderedList/server/index.d.ts.map +1 -1
  46. package/dist/features/lists/orderedList/server/index.js +5 -2
  47. package/dist/features/lists/orderedList/server/index.js.map +1 -1
  48. package/dist/features/lists/shared/constants.d.ts +2 -0
  49. package/dist/features/lists/shared/constants.d.ts.map +1 -0
  50. package/dist/features/lists/shared/constants.js +2 -0
  51. package/dist/features/lists/shared/constants.js.map +1 -0
  52. package/dist/features/lists/shared/validate.d.ts +5 -0
  53. package/dist/features/lists/shared/validate.d.ts.map +1 -0
  54. package/dist/features/lists/shared/validate.js +15 -0
  55. package/dist/features/lists/shared/validate.js.map +1 -0
  56. package/dist/features/lists/unorderedList/server/index.d.ts.map +1 -1
  57. package/dist/features/lists/unorderedList/server/index.js +5 -2
  58. package/dist/features/lists/unorderedList/server/index.js.map +1 -1
  59. package/dist/features/relationship/client/index.d.ts +2 -2
  60. package/dist/features/relationship/client/index.d.ts.map +1 -1
  61. package/dist/features/relationship/client/index.js.map +1 -1
  62. package/dist/features/relationship/client/plugins/index.d.ts +2 -2
  63. package/dist/features/relationship/client/plugins/index.d.ts.map +1 -1
  64. package/dist/features/relationship/client/plugins/index.js +27 -31
  65. package/dist/features/relationship/client/plugins/index.js.map +1 -1
  66. package/dist/features/relationship/client/utils/useEnabledRelationships.d.ts +2 -4
  67. package/dist/features/relationship/client/utils/useEnabledRelationships.d.ts.map +1 -1
  68. package/dist/features/relationship/client/utils/useEnabledRelationships.js +53 -20
  69. package/dist/features/relationship/client/utils/useEnabledRelationships.js.map +1 -1
  70. package/dist/features/relationship/server/graphQLPopulationPromise.d.ts +2 -2
  71. package/dist/features/relationship/server/graphQLPopulationPromise.d.ts.map +1 -1
  72. package/dist/features/relationship/server/graphQLPopulationPromise.js +2 -2
  73. package/dist/features/relationship/server/graphQLPopulationPromise.js.map +1 -1
  74. package/dist/features/relationship/server/index.d.ts +8 -1
  75. package/dist/features/relationship/server/index.d.ts.map +1 -1
  76. package/dist/features/relationship/server/index.js +28 -11
  77. package/dist/features/relationship/server/index.js.map +1 -1
  78. package/dist/features/relationship/server/schema.d.ts +2 -2
  79. package/dist/features/relationship/server/schema.d.ts.map +1 -1
  80. package/dist/features/relationship/server/schema.js +5 -10
  81. package/dist/features/relationship/server/schema.js.map +1 -1
  82. package/dist/features/relationship/shared/filterEnabledRelationshipCollections.d.ts +1 -6
  83. package/dist/features/relationship/shared/filterEnabledRelationshipCollections.d.ts.map +1 -1
  84. package/dist/features/relationship/shared/filterEnabledRelationshipCollections.js +1 -5
  85. package/dist/features/relationship/shared/filterEnabledRelationshipCollections.js.map +1 -1
  86. package/dist/features/table/client/plugins/TableActionMenuPlugin/computeSelectionCount.d.ts +8 -0
  87. package/dist/features/table/client/plugins/TableActionMenuPlugin/computeSelectionCount.d.ts.map +1 -0
  88. package/dist/features/table/client/plugins/TableActionMenuPlugin/computeSelectionCount.js +19 -0
  89. package/dist/features/table/client/plugins/TableActionMenuPlugin/computeSelectionCount.js.map +1 -0
  90. package/dist/features/table/client/plugins/TableActionMenuPlugin/index.d.ts.map +1 -1
  91. package/dist/features/table/client/plugins/TableActionMenuPlugin/index.js +16 -43
  92. package/dist/features/table/client/plugins/TableActionMenuPlugin/index.js.map +1 -1
  93. package/dist/features/table/server/index.js +2 -2
  94. package/dist/features/table/server/index.js.map +1 -1
  95. package/dist/features/toolbars/fixed/client/Toolbar/horizontalWheelScroll.d.ts +8 -0
  96. package/dist/features/toolbars/fixed/client/Toolbar/horizontalWheelScroll.d.ts.map +1 -0
  97. package/dist/features/toolbars/fixed/client/Toolbar/horizontalWheelScroll.js +80 -0
  98. package/dist/features/toolbars/fixed/client/Toolbar/horizontalWheelScroll.js.map +1 -0
  99. package/dist/features/toolbars/fixed/client/Toolbar/index.css +77 -3
  100. package/dist/features/toolbars/fixed/client/Toolbar/index.d.ts.map +1 -1
  101. package/dist/features/toolbars/fixed/client/Toolbar/index.js +4 -1
  102. package/dist/features/toolbars/fixed/client/Toolbar/index.js.map +1 -1
  103. package/dist/features/toolbars/shared/ToolbarDropdown/index.css +12 -11
  104. package/dist/features/typesServer.d.ts +1 -1
  105. package/dist/features/typesServer.d.ts.map +1 -1
  106. package/dist/features/typesServer.js.map +1 -1
  107. package/dist/features/upload/client/index.d.ts +3 -2
  108. package/dist/features/upload/client/index.d.ts.map +1 -1
  109. package/dist/features/upload/client/index.js.map +1 -1
  110. package/dist/features/upload/client/plugin/index.d.ts.map +1 -1
  111. package/dist/features/upload/client/plugin/index.js +47 -52
  112. package/dist/features/upload/client/plugin/index.js.map +1 -1
  113. package/dist/features/upload/server/graphQLPopulationPromise.d.ts +2 -2
  114. package/dist/features/upload/server/graphQLPopulationPromise.d.ts.map +1 -1
  115. package/dist/features/upload/server/graphQLPopulationPromise.js +1 -1
  116. package/dist/features/upload/server/graphQLPopulationPromise.js.map +1 -1
  117. package/dist/features/upload/server/index.d.ts +6 -2
  118. package/dist/features/upload/server/index.d.ts.map +1 -1
  119. package/dist/features/upload/server/index.js +20 -16
  120. package/dist/features/upload/server/index.js.map +1 -1
  121. package/dist/features/upload/server/schema.d.ts +2 -2
  122. package/dist/features/upload/server/schema.d.ts.map +1 -1
  123. package/dist/features/upload/server/schema.js +4 -8
  124. package/dist/features/upload/server/schema.js.map +1 -1
  125. package/dist/features/upload/server/validate.d.ts +2 -2
  126. package/dist/features/upload/server/validate.d.ts.map +1 -1
  127. package/dist/features/upload/server/validate.js +3 -0
  128. package/dist/features/upload/server/validate.js.map +1 -1
  129. package/dist/field/Diff/converters/listitem/index.d.ts.map +1 -1
  130. package/dist/field/Diff/converters/listitem/index.js +2 -1
  131. package/dist/field/Diff/converters/listitem/index.js.map +1 -1
  132. package/dist/field/Diff/index.d.ts.map +1 -1
  133. package/dist/field/Diff/index.js +1 -0
  134. package/dist/field/Diff/index.js.map +1 -1
  135. package/dist/field/RenderLexical/index.d.ts +3 -1
  136. package/dist/field/RenderLexical/index.d.ts.map +1 -1
  137. package/dist/field/RenderLexical/index.js +23 -23
  138. package/dist/field/RenderLexical/index.js.map +1 -1
  139. package/dist/field/bundled.css +1 -1
  140. package/dist/field/index.css +10 -10
  141. package/dist/i18n.d.ts.map +1 -1
  142. package/dist/i18n.js +68 -0
  143. package/dist/i18n.js.map +1 -1
  144. package/dist/index.d.ts +1 -1
  145. package/dist/index.js +4 -4
  146. package/dist/index.js.map +1 -1
  147. package/dist/lexical/LexicalEditor.js.map +1 -1
  148. package/dist/lexical/config/server/loader.d.ts +1 -1
  149. package/dist/lexical/config/server/loader.d.ts.map +1 -1
  150. package/dist/lexical/config/server/loader.js +2 -2
  151. package/dist/lexical/config/server/loader.js.map +1 -1
  152. package/dist/lexical/config/server/sanitize.d.ts +1 -1
  153. package/dist/lexical/config/server/sanitize.d.ts.map +1 -1
  154. package/dist/lexical/config/server/sanitize.js +2 -2
  155. package/dist/lexical/config/server/sanitize.js.map +1 -1
  156. package/dist/lexical/plugins/InsertParagraphAtEnd/index.css +16 -23
  157. package/dist/lexical/plugins/InsertParagraphAtEnd/index.d.ts.map +1 -1
  158. package/dist/lexical/plugins/InsertParagraphAtEnd/index.js +27 -14
  159. package/dist/lexical/plugins/InsertParagraphAtEnd/index.js.map +1 -1
  160. package/dist/lexical/ui/icons/H3/index.d.ts.map +1 -1
  161. package/dist/lexical/ui/icons/H3/index.js +13 -6
  162. package/dist/lexical/ui/icons/H3/index.js.map +1 -1
  163. package/dist/lexical/ui/icons/H4/index.d.ts.map +1 -1
  164. package/dist/lexical/ui/icons/H4/index.js +13 -6
  165. package/dist/lexical/ui/icons/H4/index.js.map +1 -1
  166. package/dist/lexical/ui/icons/H5/index.d.ts.map +1 -1
  167. package/dist/lexical/ui/icons/H5/index.js +13 -6
  168. package/dist/lexical/ui/icons/H5/index.js.map +1 -1
  169. package/dist/lexical/ui/icons/H6/index.d.ts.map +1 -1
  170. package/dist/lexical/ui/icons/H6/index.js +13 -6
  171. package/dist/lexical/ui/icons/H6/index.js.map +1 -1
  172. package/dist/types/index.d.ts +1 -1
  173. package/dist/types/index.d.ts.map +1 -1
  174. package/dist/types/index.js.map +1 -1
  175. package/dist/utilities/createServerFeature.d.ts +1 -1
  176. package/dist/utilities/createServerFeature.d.ts.map +1 -1
  177. package/dist/utilities/createServerFeature.js +2 -2
  178. package/dist/utilities/createServerFeature.js.map +1 -1
  179. package/dist/utilities/editorConfigFactory.d.ts +6 -6
  180. package/dist/utilities/editorConfigFactory.d.ts.map +1 -1
  181. package/dist/utilities/editorConfigFactory.js +9 -9
  182. package/dist/utilities/editorConfigFactory.js.map +1 -1
  183. package/dist/utilities/getDefaultSanitizedEditorConfig.d.ts +2 -2
  184. package/dist/utilities/getDefaultSanitizedEditorConfig.d.ts.map +1 -1
  185. package/dist/utilities/getDefaultSanitizedEditorConfig.js +6 -17
  186. package/dist/utilities/getDefaultSanitizedEditorConfig.js.map +1 -1
  187. package/package.json +22 -22
  188. package/dist/dependencyChecker.spec.js +0 -16
  189. package/dist/dependencyChecker.spec.js.map +0 -1
  190. package/dist/exports/client/Field-IZKDIUJY.js +0 -2
  191. package/dist/exports/client/Field-IZKDIUJY.js.map +0 -7
  192. package/dist/exports/client/chunk-SSMQFWCQ.js +0 -2
  193. package/dist/features/converters/lexicalToPlaintext/convertLexicalToPlaintext.spec.js +0 -180
  194. package/dist/features/converters/lexicalToPlaintext/convertLexicalToPlaintext.spec.js.map +0 -1
  195. package/dist/features/link/markdownTransformer.spec.js +0 -195
  196. package/dist/features/link/markdownTransformer.spec.js.map +0 -1
  197. package/dist/lexical/utils/markdown/convertFromMarkdownString.spec.js +0 -88
  198. package/dist/lexical/utils/markdown/convertFromMarkdownString.spec.js.map +0 -1
  199. package/dist/lexical/utils/url.spec.js +0 -114
  200. package/dist/lexical/utils/url.spec.js.map +0 -1
  201. package/dist/utilities/jsx/jsx.spec.js +0 -178
  202. package/dist/utilities/jsx/jsx.spec.js.map +0 -1
@@ -1,22 +1,30 @@
1
1
  import { populate } from '../../../populateGraphQL/populate.js';
2
2
  import { createServerFeature } from '../../../utilities/createServerFeature.js';
3
3
  import { createNode } from '../../typeUtilities.js';
4
+ import { filterEnabledRelationshipCollections } from '../shared/filterEnabledRelationshipCollections.js';
4
5
  import { relationshipPopulationPromiseHOC } from './graphQLPopulationPromise.js';
5
6
  import { i18n } from './i18n.js';
6
7
  import { RelationshipServerNode } from './nodes/RelationshipNode.js';
7
8
  import { createRelationshipNodeJSONSchema } from './schema.js';
8
9
  export const RelationshipFeature = createServerFeature({
9
10
  feature: ({
10
- props
11
+ config,
12
+ props: unsanitizedProps
11
13
  }) => {
12
- // we don't need to pass maxDepth to the client, it's only used on the server
13
- const {
14
- maxDepth,
15
- ...clientFeatureProps
16
- } = props ?? {};
14
+ const props = {
15
+ ...unsanitizedProps,
16
+ enabledCollectionSlugs: filterEnabledRelationshipCollections(config.collections, {
17
+ ...unsanitizedProps,
18
+ uploads: false
19
+ }).map(({
20
+ slug
21
+ }) => slug)
22
+ };
17
23
  return {
18
24
  ClientFeature: '@payloadcms/richtext-lexical/client#RelationshipFeatureClient',
19
- clientFeatureProps,
25
+ clientFeatureProps: {
26
+ enabledCollectionSlugs: props.enabledCollectionSlugs
27
+ },
20
28
  i18n,
21
29
  nodes: [createNode({
22
30
  graphQLPopulationPromises: [relationshipPopulationPromiseHOC(props)],
@@ -32,7 +40,7 @@ export const RelationshipFeature = createServerFeature({
32
40
  req,
33
41
  showHiddenFields
34
42
  }) => {
35
- if (!node?.value) {
43
+ if (!node?.value || !props.enabledCollectionSlugs.includes(node.relationTo)) {
36
44
  return node;
37
45
  }
38
46
  const collection = req.payload.collections[node?.relationTo];
@@ -42,7 +50,7 @@ export const RelationshipFeature = createServerFeature({
42
50
  // @ts-expect-error
43
51
  const id = node?.value?.id || node?.value // for backwards-compatibility
44
52
  ;
45
- const populateDepth = maxDepth !== undefined && maxDepth < depth ? maxDepth : depth;
53
+ const populateDepth = props.maxDepth !== undefined && props.maxDepth < depth ? props.maxDepth : depth;
46
54
  populationPromises.push(populate({
47
55
  id,
48
56
  collectionSlug: collection.config.slug,
@@ -60,8 +68,17 @@ export const RelationshipFeature = createServerFeature({
60
68
  }]
61
69
  },
62
70
  jsonSchema: createRelationshipNodeJSONSchema(props),
63
- node: RelationshipServerNode
64
- })]
71
+ node: RelationshipServerNode,
72
+ validations: [({
73
+ node,
74
+ validation: {
75
+ options: {
76
+ req
77
+ }
78
+ }
79
+ }) => props.enabledCollectionSlugs.includes(node.relationTo) ? true : req.t('validation:invalidSelection')]
80
+ })],
81
+ sanitizedServerFeatureProps: props
65
82
  };
66
83
  },
67
84
  key: 'relationship'
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["populate","createServerFeature","createNode","relationshipPopulationPromiseHOC","i18n","RelationshipServerNode","createRelationshipNodeJSONSchema","RelationshipFeature","feature","props","maxDepth","clientFeatureProps","ClientFeature","nodes","graphQLPopulationPromises","hooks","afterRead","currentDepth","depth","draft","node","overrideAccess","populateArg","populationPromises","req","showHiddenFields","value","collection","payload","collections","relationTo","id","populateDepth","undefined","push","collectionSlug","config","slug","data","key","select","defaultPopulate","jsonSchema"],"sources":["../../../../src/features/relationship/server/index.ts"],"sourcesContent":["import type { CollectionSlug } from 'payload'\n\nimport { populate } from '../../../populateGraphQL/populate.js'\nimport { createServerFeature } from '../../../utilities/createServerFeature.js'\nimport { createNode } from '../../typeUtilities.js'\nimport { relationshipPopulationPromiseHOC } from './graphQLPopulationPromise.js'\nimport { i18n } from './i18n.js'\nimport { RelationshipServerNode } from './nodes/RelationshipNode.js'\nimport { createRelationshipNodeJSONSchema } from './schema.js'\n\nexport type { RelationshipData, SerializedRelationshipNode } from './schema.js'\n\nexport type ExclusiveRelationshipFeatureProps =\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?: CollectionSlug[]\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?: CollectionSlug[]\n }\n\nexport type RelationshipFeatureProps = {\n /**\n * Sets a maximum population depth for this relationship, 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} & ExclusiveRelationshipFeatureProps\n\nexport const RelationshipFeature = createServerFeature<\n RelationshipFeatureProps,\n RelationshipFeatureProps,\n ExclusiveRelationshipFeatureProps\n>({\n feature: ({ props }) => {\n // we don't need to pass maxDepth to the client, it's only used on the server\n const { maxDepth, ...clientFeatureProps } = props ?? {}\n return {\n ClientFeature: '@payloadcms/richtext-lexical/client#RelationshipFeatureClient',\n clientFeatureProps,\n i18n,\n nodes: [\n createNode({\n graphQLPopulationPromises: [relationshipPopulationPromiseHOC(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\n const id = node?.value?.id || node?.value // for backwards-compatibility\n\n const populateDepth = maxDepth !== undefined && maxDepth < depth ? 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 jsonSchema: createRelationshipNodeJSONSchema(props),\n node: RelationshipServerNode,\n }),\n ],\n }\n },\n key: 'relationship',\n})\n"],"mappings":"AAEA,SAASA,QAAQ,QAAQ;AACzB,SAASC,mBAAmB,QAAQ;AACpC,SAASC,UAAU,QAAQ;AAC3B,SAASC,gCAAgC,QAAQ;AACjD,SAASC,IAAI,QAAQ;AACrB,SAASC,sBAAsB,QAAQ;AACvC,SAASC,gCAAgC,QAAQ;AAoCjD,OAAO,MAAMC,mBAAA,GAAsBN,mBAAA,CAIjC;EACAO,OAAA,EAASA,CAAC;IAAEC;EAAK,CAAE;IACjB;IACA,MAAM;MAAEC,QAAQ;MAAE,GAAGC;IAAA,CAAoB,GAAGF,KAAA,IAAS,CAAC;IACtD,OAAO;MACLG,aAAA,EAAe;MACfD,kBAAA;MACAP,IAAA;MACAS,KAAA,EAAO,CACLX,UAAA,CAAW;QACTY,yBAAA,EAA2B,CAACX,gCAAA,CAAiCM,KAAA,EAAO;QACpEM,KAAA,EAAO;UACLC,SAAA,EAAW,CACT,CAAC;YACCC,YAAY;YACZC,KAAK;YACLC,KAAK;YACLC,IAAI;YACJC,cAAc;YACdC,WAAW;YACXC,kBAAkB;YAClBC,GAAG;YACHC;UAAgB,CACjB;YACC,IAAI,CAACL,IAAA,EAAMM,KAAA,EAAO;cAChB,OAAON,IAAA;YACT;YACA,MAAMO,UAAA,GAAaH,GAAA,CAAII,OAAO,CAACC,WAAW,CAACT,IAAA,EAAMU,UAAA,CAAW;YAE5D,IAAI,CAACH,UAAA,EAAY;cACf,OAAOP,IAAA;YACT;YACA;YACA,MAAMW,EAAA,GAAKX,IAAA,EAAMM,KAAA,EAAOK,EAAA,IAAMX,IAAA,EAAMM,KAAA,CAAM;AAAA;YAE1C,MAAMM,aAAA,GAAgBtB,QAAA,KAAauB,SAAA,IAAavB,QAAA,GAAWQ,KAAA,GAAQR,QAAA,GAAWQ,KAAA;YAE9EK,kBAAA,CAAmBW,IAAI,CACrBlC,QAAA,CAAS;cACP+B,EAAA;cACAI,cAAA,EAAgBR,UAAA,CAAWS,MAAM,CAACC,IAAI;cACtCpB,YAAA;cACAqB,IAAA,EAAMlB,IAAA;cACNF,KAAA,EAAOc,aAAA;cACPb,KAAA;cACAoB,GAAA,EAAK;cACLlB,cAAA;cACAG,GAAA;cACAgB,MAAA,EACElB,WAAA,GAAcK,UAAA,CAAWS,MAAM,CAACC,IAAI,CAAC,IAAIV,UAAA,CAAWS,MAAM,CAACK,eAAe;cAC5EhB;YACF;YAGF,OAAOL,IAAA;UACT;QAEJ;QACAsB,UAAA,EAAYpC,gCAAA,CAAiCG,KAAA;QAC7CW,IAAA,EAAMf;MACR;IAEJ;EACF;EACAkC,GAAA,EAAK;AACP","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["populate","createServerFeature","createNode","filterEnabledRelationshipCollections","relationshipPopulationPromiseHOC","i18n","RelationshipServerNode","createRelationshipNodeJSONSchema","RelationshipFeature","feature","config","props","unsanitizedProps","enabledCollectionSlugs","collections","uploads","map","slug","ClientFeature","clientFeatureProps","nodes","graphQLPopulationPromises","hooks","afterRead","currentDepth","depth","draft","node","overrideAccess","populateArg","populationPromises","req","showHiddenFields","value","includes","relationTo","collection","payload","id","populateDepth","maxDepth","undefined","push","collectionSlug","data","key","select","defaultPopulate","jsonSchema","validations","validation","options","t","sanitizedServerFeatureProps"],"sources":["../../../../src/features/relationship/server/index.ts"],"sourcesContent":["import type { CollectionSlug } from 'payload'\n\nimport { populate } from '../../../populateGraphQL/populate.js'\nimport { createServerFeature } from '../../../utilities/createServerFeature.js'\nimport { createNode } from '../../typeUtilities.js'\nimport { filterEnabledRelationshipCollections } from '../shared/filterEnabledRelationshipCollections.js'\nimport { relationshipPopulationPromiseHOC } from './graphQLPopulationPromise.js'\nimport { i18n } from './i18n.js'\nimport { RelationshipServerNode } from './nodes/RelationshipNode.js'\nimport { createRelationshipNodeJSONSchema } from './schema.js'\n\nexport type { RelationshipData, SerializedRelationshipNode } from './schema.js'\n\nexport type ExclusiveRelationshipFeatureProps =\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?: CollectionSlug[]\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?: CollectionSlug[]\n }\n\nexport type RelationshipFeatureProps = {\n /**\n * Sets a maximum population depth for this relationship, 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} & ExclusiveRelationshipFeatureProps\n\nexport type RelationshipFeatureServerProps = {\n /** Collection policy resolved during feature initialization. */\n enabledCollectionSlugs: CollectionSlug[]\n} & RelationshipFeatureProps\n\nexport type RelationshipFeatureClientProps = {\n enabledCollectionSlugs: CollectionSlug[]\n}\n\nexport const RelationshipFeature = createServerFeature<\n RelationshipFeatureProps,\n RelationshipFeatureServerProps,\n RelationshipFeatureClientProps\n>({\n feature: ({ config, props: unsanitizedProps }) => {\n const props: RelationshipFeatureServerProps = {\n ...unsanitizedProps,\n enabledCollectionSlugs: filterEnabledRelationshipCollections(config.collections, {\n ...unsanitizedProps,\n uploads: false,\n }).map(({ slug }) => slug),\n }\n\n return {\n ClientFeature: '@payloadcms/richtext-lexical/client#RelationshipFeatureClient',\n clientFeatureProps: {\n enabledCollectionSlugs: props.enabledCollectionSlugs,\n },\n i18n,\n nodes: [\n createNode({\n graphQLPopulationPromises: [relationshipPopulationPromiseHOC(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 || !props.enabledCollectionSlugs.includes(node.relationTo)) {\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 select:\n populateArg?.[collection.config.slug] ?? collection.config.defaultPopulate,\n showHiddenFields,\n }),\n )\n\n return node\n },\n ],\n },\n jsonSchema: createRelationshipNodeJSONSchema(props),\n node: RelationshipServerNode,\n validations: [\n ({\n node,\n validation: {\n options: { req },\n },\n }) =>\n props.enabledCollectionSlugs.includes(node.relationTo)\n ? true\n : req.t('validation:invalidSelection'),\n ],\n }),\n ],\n sanitizedServerFeatureProps: props,\n }\n },\n key: 'relationship',\n})\n"],"mappings":"AAEA,SAASA,QAAQ,QAAQ;AACzB,SAASC,mBAAmB,QAAQ;AACpC,SAASC,UAAU,QAAQ;AAC3B,SAASC,oCAAoC,QAAQ;AACrD,SAASC,gCAAgC,QAAQ;AACjD,SAASC,IAAI,QAAQ;AACrB,SAASC,sBAAsB,QAAQ;AACvC,SAASC,gCAAgC,QAAQ;AA6CjD,OAAO,MAAMC,mBAAA,GAAsBP,mBAAA,CAIjC;EACAQ,OAAA,EAASA,CAAC;IAAEC,MAAM;IAAEC,KAAA,EAAOC;EAAgB,CAAE;IAC3C,MAAMD,KAAA,GAAwC;MAC5C,GAAGC,gBAAgB;MACnBC,sBAAA,EAAwBV,oCAAA,CAAqCO,MAAA,CAAOI,WAAW,EAAE;QAC/E,GAAGF,gBAAgB;QACnBG,OAAA,EAAS;MACX,GAAGC,GAAG,CAAC,CAAC;QAAEC;MAAI,CAAE,KAAKA,IAAA;IACvB;IAEA,OAAO;MACLC,aAAA,EAAe;MACfC,kBAAA,EAAoB;QAClBN,sBAAA,EAAwBF,KAAA,CAAME;MAChC;MACAR,IAAA;MACAe,KAAA,EAAO,CACLlB,UAAA,CAAW;QACTmB,yBAAA,EAA2B,CAACjB,gCAAA,CAAiCO,KAAA,EAAO;QACpEW,KAAA,EAAO;UACLC,SAAA,EAAW,CACT,CAAC;YACCC,YAAY;YACZC,KAAK;YACLC,KAAK;YACLC,IAAI;YACJC,cAAc;YACdC,WAAW;YACXC,kBAAkB;YAClBC,GAAG;YACHC;UAAgB,CACjB;YACC,IAAI,CAACL,IAAA,EAAMM,KAAA,IAAS,CAACtB,KAAA,CAAME,sBAAsB,CAACqB,QAAQ,CAACP,IAAA,CAAKQ,UAAU,GAAG;cAC3E,OAAOR,IAAA;YACT;YACA,MAAMS,UAAA,GAAaL,GAAA,CAAIM,OAAO,CAACvB,WAAW,CAACa,IAAA,EAAMQ,UAAA,CAAW;YAE5D,IAAI,CAACC,UAAA,EAAY;cACf,OAAOT,IAAA;YACT;YACA;YACA,MAAMW,EAAA,GAAKX,IAAA,EAAMM,KAAA,EAAOK,EAAA,IAAMX,IAAA,EAAMM,KAAA,CAAM;AAAA;YAE1C,MAAMM,aAAA,GACJ5B,KAAA,CAAM6B,QAAQ,KAAKC,SAAA,IAAa9B,KAAA,CAAM6B,QAAQ,GAAGf,KAAA,GAAQd,KAAA,CAAM6B,QAAQ,GAAGf,KAAA;YAE5EK,kBAAA,CAAmBY,IAAI,CACrB1C,QAAA,CAAS;cACPsC,EAAA;cACAK,cAAA,EAAgBP,UAAA,CAAW1B,MAAM,CAACO,IAAI;cACtCO,YAAA;cACAoB,IAAA,EAAMjB,IAAA;cACNF,KAAA,EAAOc,aAAA;cACPb,KAAA;cACAmB,GAAA,EAAK;cACLjB,cAAA;cACAG,GAAA;cACAe,MAAA,EACEjB,WAAA,GAAcO,UAAA,CAAW1B,MAAM,CAACO,IAAI,CAAC,IAAImB,UAAA,CAAW1B,MAAM,CAACqC,eAAe;cAC5Ef;YACF;YAGF,OAAOL,IAAA;UACT;QAEJ;QACAqB,UAAA,EAAYzC,gCAAA,CAAiCI,KAAA;QAC7CgB,IAAA,EAAMrB,sBAAA;QACN2C,WAAA,EAAa,CACX,CAAC;UACCtB,IAAI;UACJuB,UAAA,EAAY;YACVC,OAAA,EAAS;cAAEpB;YAAG;UAAE;QACjB,CACF,KACCpB,KAAA,CAAME,sBAAsB,CAACqB,QAAQ,CAACP,IAAA,CAAKQ,UAAU,IACjD,OACAJ,GAAA,CAAIqB,CAAC,CAAC;MAEhB,GACD;MACDC,2BAAA,EAA6B1C;IAC/B;EACF;EACAkC,GAAA,EAAK;AACP","ignoreList":[]}
@@ -1,7 +1,7 @@
1
1
  import type { CollectionSlug, DataFromCollectionSlug, IDTypeForCollectionSlug, UploadCollectionSlug } from 'payload';
2
2
  import type { LexicalElementFormat } from '../../../types/nodeTypes.js';
3
3
  import type { JSONSchemaFn } from '../../typesServer.js';
4
- import type { RelationshipFeatureProps } from './index.js';
4
+ import type { RelationshipFeatureServerProps } from './index.js';
5
5
  export type RelationshipData = {
6
6
  [TCollectionSlug in CollectionSlug]: {
7
7
  relationTo: TCollectionSlug;
@@ -24,5 +24,5 @@ export type SerializedRelationshipNode<TSlugs extends CollectionSlug = NonUpload
24
24
  type: 'relationship';
25
25
  version: number;
26
26
  };
27
- export declare const createRelationshipNodeJSONSchema: (props: RelationshipFeatureProps | undefined) => JSONSchemaFn;
27
+ export declare const createRelationshipNodeJSONSchema: (props: RelationshipFeatureServerProps) => JSONSchemaFn;
28
28
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/features/relationship/server/schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAK1D,MAAM,MAAM,gBAAgB,GAAG;KAC5B,eAAe,IAAI,cAAc,GAAG;QACnC,UAAU,EAAE,eAAe,CAAA;QAC3B,KAAK,EAAE,sBAAsB,CAAC,eAAe,CAAC,GAAG,uBAAuB,CAAC,eAAe,CAAC,CAAA;KAC1F;CACF,CAAC,cAAc,CAAC,CAAA;AAEjB;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,oBAAoB,CAAC,CAAC,SAAS;IAC5F,KAAK;CACN,GACG,cAAc,GACd,OAAO,CAAC,cAAc,EAAE,oBAAoB,CAAC,CAAA;AAEjD,MAAM,MAAM,0BAA0B,CAAC,MAAM,SAAS,cAAc,GAAG,uBAAuB,IAAI;KAC/F,KAAK,IAAI,MAAM,GAAG;QACjB,UAAU,EAAE,KAAK,CAAA;QACjB,KAAK,EAAE,sBAAsB,CAAC,KAAK,CAAC,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAA;KACtE;CACF,CAAC,MAAM,CAAC,GAAG;IACV,MAAM,EAAE,oBAAoB,CAAA;IAC5B,IAAI,EAAE,cAAc,CAAA;IACpB,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AA0BD,eAAO,MAAM,gCAAgC,UACnC,wBAAwB,GAAG,SAAS,KAAG,YAwD9C,CAAA"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/features/relationship/server/schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAA;AAIhE,MAAM,MAAM,gBAAgB,GAAG;KAC5B,eAAe,IAAI,cAAc,GAAG;QACnC,UAAU,EAAE,eAAe,CAAA;QAC3B,KAAK,EAAE,sBAAsB,CAAC,eAAe,CAAC,GAAG,uBAAuB,CAAC,eAAe,CAAC,CAAA;KAC1F;CACF,CAAC,cAAc,CAAC,CAAA;AAEjB;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,oBAAoB,CAAC,CAAC,SAAS;IAC5F,KAAK;CACN,GACG,cAAc,GACd,OAAO,CAAC,cAAc,EAAE,oBAAoB,CAAC,CAAA;AAEjD,MAAM,MAAM,0BAA0B,CAAC,MAAM,SAAS,cAAc,GAAG,uBAAuB,IAAI;KAC/F,KAAK,IAAI,MAAM,GAAG;QACjB,UAAU,EAAE,KAAK,CAAA;QACjB,KAAK,EAAE,sBAAsB,CAAC,KAAK,CAAC,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAA;KACtE;CACF,CAAC,MAAM,CAAC,GAAG;IACV,MAAM,EAAE,oBAAoB,CAAA;IAC5B,IAAI,EAAE,cAAc,CAAA;IACpB,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AA0BD,eAAO,MAAM,gCAAgC,UACnC,8BAA8B,KAAG,YAiDxC,CAAA"}
@@ -1,5 +1,4 @@
1
1
  import { formatSchema, versionSchema } from '../../../types/jsonSchemaHelpers.js';
2
- import { filterEnabledRelationshipCollections } from '../shared/filterEnabledRelationshipCollections.js';
3
2
  /** MUST stay byte-for-byte in sync with the runtime `SerializedRelationshipNode` declared above. */
4
3
  const SERIALIZED_RELATIONSHIP_NODE_TS = `export type SerializedRelationshipNode<TSlugs extends keyof Config['collections']> = {
5
4
  type: 'relationship';
@@ -24,19 +23,15 @@ const SERIALIZED_RELATIONSHIP_NODE_INPUT_TS = `export type SerializedRelationshi
24
23
  }[TSlugs];`;
25
24
  export const createRelationshipNodeJSONSchema = props => ({
26
25
  collectionIDFieldTypes,
27
- config,
28
26
  typeStringDefinitions,
29
27
  variant
30
28
  }) => {
31
29
  const isInput = variant === 'input';
32
30
  typeStringDefinitions.add(isInput ? SERIALIZED_RELATIONSHIP_NODE_INPUT_TS : SERIALIZED_RELATIONSHIP_NODE_TS);
33
- const enabledCollections = config?.collections ? filterEnabledRelationshipCollections(config.collections, {
34
- disabledCollections: props?.disabledCollections,
35
- enabledCollections: props?.enabledCollections,
36
- uploads: false
37
- }) : [];
38
- const variants = enabledCollections.map(collection => {
39
- const slug = collection.slug;
31
+ const {
32
+ enabledCollectionSlugs
33
+ } = props;
34
+ const variants = enabledCollectionSlugs.map(slug => {
40
35
  const idType = collectionIDFieldTypes[slug] ?? 'string';
41
36
  return {
42
37
  type: 'object',
@@ -82,7 +77,7 @@ export const createRelationshipNodeJSONSchema = props => ({
82
77
  required: ['type', 'version']
83
78
  };
84
79
  } else {
85
- const slugUnion = enabledCollections.map(c => `'${c.slug}'`).join(' | ');
80
+ const slugUnion = enabledCollectionSlugs.map(slug => `'${slug}'`).join(' | ');
86
81
  const baseSchema = variants.length === 1 ? variants[0] : {
87
82
  oneOf: variants
88
83
  };
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","names":["formatSchema","versionSchema","filterEnabledRelationshipCollections","SERIALIZED_RELATIONSHIP_NODE_TS","SERIALIZED_RELATIONSHIP_NODE_INPUT_TS","createRelationshipNodeJSONSchema","props","collectionIDFieldTypes","config","typeStringDefinitions","variant","isInput","add","enabledCollections","collections","disabledCollections","uploads","variants","map","collection","slug","idType","type","additionalProperties","properties","const","format","relationTo","value","description","oneOf","$ref","version","required","schema","length","slugUnion","c","join","baseSchema","tsName","tsType"],"sources":["../../../../src/features/relationship/server/schema.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\nimport type {\n CollectionSlug,\n DataFromCollectionSlug,\n IDTypeForCollectionSlug,\n UploadCollectionSlug,\n} from 'payload'\n\nimport type { LexicalElementFormat } from '../../../types/nodeTypes.js'\nimport type { JSONSchemaFn } from '../../typesServer.js'\nimport type { RelationshipFeatureProps } from './index.js'\n\nimport { formatSchema, versionSchema } from '../../../types/jsonSchemaHelpers.js'\nimport { filterEnabledRelationshipCollections } from '../shared/filterEnabledRelationshipCollections.js'\n\nexport type RelationshipData = {\n [TCollectionSlug in CollectionSlug]: {\n relationTo: TCollectionSlug\n value: DataFromCollectionSlug<TCollectionSlug> | IDTypeForCollectionSlug<TCollectionSlug>\n }\n}[CollectionSlug]\n\n/**\n * Exclude upload collection slugs. This matches runtime behavior, as well as the json schema.\n */\nexport type NonUploadCollectionSlug = [Exclude<CollectionSlug, UploadCollectionSlug>] extends [\n never,\n]\n ? CollectionSlug\n : Exclude<CollectionSlug, UploadCollectionSlug>\n\nexport type SerializedRelationshipNode<TSlugs extends CollectionSlug = NonUploadCollectionSlug> = {\n [TSlug in TSlugs]: {\n relationTo: TSlug\n value: DataFromCollectionSlug<TSlug> | IDTypeForCollectionSlug<TSlug>\n }\n}[TSlugs] & {\n format: LexicalElementFormat\n type: 'relationship'\n version: number\n}\n\n/** MUST stay byte-for-byte in sync with the runtime `SerializedRelationshipNode` declared above. */\nconst SERIALIZED_RELATIONSHIP_NODE_TS = `export type SerializedRelationshipNode<TSlugs extends keyof Config['collections']> = {\n type: 'relationship';\n format: LexicalElementFormat;\n version: number;\n} & {\n [TSlug in TSlugs]: {\n relationTo: TSlug;\n value: Config['collections'][TSlug]['id'] | Config['collections'][TSlug];\n };\n}[TSlugs];`\n\n/** Input variant of `SerializedRelationshipNode`: `value` is ID-only (you only ever write an ID). */\nconst SERIALIZED_RELATIONSHIP_NODE_INPUT_TS = `export type SerializedRelationshipNodeInput<TSlugs extends keyof Config['collections']> = {\n type: 'relationship';\n format: LexicalElementFormat;\n version: number;\n} & {\n [TSlug in TSlugs]: {\n relationTo: TSlug;\n value: Config['collections'][TSlug]['id'];\n };\n}[TSlugs];`\n\nexport const createRelationshipNodeJSONSchema =\n (props: RelationshipFeatureProps | undefined): JSONSchemaFn =>\n ({ collectionIDFieldTypes, config, typeStringDefinitions, variant }) => {\n const isInput = variant === 'input'\n typeStringDefinitions.add(\n isInput ? SERIALIZED_RELATIONSHIP_NODE_INPUT_TS : SERIALIZED_RELATIONSHIP_NODE_TS,\n )\n const enabledCollections = config?.collections\n ? filterEnabledRelationshipCollections(config.collections, {\n disabledCollections: props?.disabledCollections,\n enabledCollections: props?.enabledCollections,\n uploads: false,\n })\n : []\n\n const variants: JSONSchema4[] = enabledCollections.map((collection) => {\n const slug = collection.slug\n const idType: 'number' | 'string' = collectionIDFieldTypes[slug] ?? 'string'\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', const: 'relationship' },\n format: formatSchema,\n relationTo: { type: 'string', const: slug },\n value: isInput\n ? { type: idType, description: 'The related document ID.' }\n : {\n description:\n 'The related document by ID (string or number). Populated to the full document when read at depth > 0.',\n oneOf: [{ type: idType }, { $ref: `#/$defs/${slug}` }],\n },\n version: versionSchema,\n },\n required: ['format', 'relationTo', 'type', 'value', 'version'],\n }\n })\n\n let schema: JSONSchema4\n if (variants.length === 0) {\n schema = {\n type: 'object',\n additionalProperties: true,\n properties: {\n type: { type: 'string', const: 'relationship' },\n version: versionSchema,\n },\n required: ['type', 'version'],\n }\n } else {\n const slugUnion = enabledCollections.map((c) => `'${c.slug}'`).join(' | ')\n const baseSchema: JSONSchema4 = variants.length === 1 ? variants[0]! : { oneOf: variants }\n const tsName = isInput ? 'SerializedRelationshipNodeInput' : 'SerializedRelationshipNode'\n schema = { ...baseSchema, tsType: `${tsName}<${slugUnion}>` }\n }\n\n return schema\n }\n"],"mappings":"AAYA,SAASA,YAAY,EAAEC,aAAa,QAAQ;AAC5C,SAASC,oCAAoC,QAAQ;AA6BrD;AACA,MAAMC,+BAAA,GAAkC;;;;;;;;;WAS7B;AAEX;AACA,MAAMC,qCAAA,GAAwC;;;;;;;;;WASnC;AAEX,OAAO,MAAMC,gCAAA,GACVC,KAAA,IACD,CAAC;EAAEC,sBAAsB;EAAEC,MAAM;EAAEC,qBAAqB;EAAEC;AAAO,CAAE;EACjE,MAAMC,OAAA,GAAUD,OAAA,KAAY;EAC5BD,qBAAA,CAAsBG,GAAG,CACvBD,OAAA,GAAUP,qCAAA,GAAwCD,+BAAA;EAEpD,MAAMU,kBAAA,GAAqBL,MAAA,EAAQM,WAAA,GAC/BZ,oCAAA,CAAqCM,MAAA,CAAOM,WAAW,EAAE;IACvDC,mBAAA,EAAqBT,KAAA,EAAOS,mBAAA;IAC5BF,kBAAA,EAAoBP,KAAA,EAAOO,kBAAA;IAC3BG,OAAA,EAAS;EACX,KACA,EAAE;EAEN,MAAMC,QAAA,GAA0BJ,kBAAA,CAAmBK,GAAG,CAAEC,UAAA;IACtD,MAAMC,IAAA,GAAOD,UAAA,CAAWC,IAAI;IAC5B,MAAMC,MAAA,GAA8Bd,sBAAsB,CAACa,IAAA,CAAK,IAAI;IACpE,OAAO;MACLE,IAAA,EAAM;MACNC,oBAAA,EAAsB;MACtBC,UAAA,EAAY;QACVF,IAAA,EAAM;UAAEA,IAAA,EAAM;UAAUG,KAAA,EAAO;QAAe;QAC9CC,MAAA,EAAQ1B,YAAA;QACR2B,UAAA,EAAY;UAAEL,IAAA,EAAM;UAAUG,KAAA,EAAOL;QAAK;QAC1CQ,KAAA,EAAOjB,OAAA,GACH;UAAEW,IAAA,EAAMD,MAAA;UAAQQ,WAAA,EAAa;QAA2B,IACxD;UACEA,WAAA,EACE;UACFC,KAAA,EAAO,CAAC;YAAER,IAAA,EAAMD;UAAO,GAAG;YAAEU,IAAA,EAAM,WAAWX,IAAA;UAAO;QACtD;QACJY,OAAA,EAAS/B;MACX;MACAgC,QAAA,EAAU,CAAC,UAAU,cAAc,QAAQ,SAAS;IACtD;EACF;EAEA,IAAIC,MAAA;EACJ,IAAIjB,QAAA,CAASkB,MAAM,KAAK,GAAG;IACzBD,MAAA,GAAS;MACPZ,IAAA,EAAM;MACNC,oBAAA,EAAsB;MACtBC,UAAA,EAAY;QACVF,IAAA,EAAM;UAAEA,IAAA,EAAM;UAAUG,KAAA,EAAO;QAAe;QAC9CO,OAAA,EAAS/B;MACX;MACAgC,QAAA,EAAU,CAAC,QAAQ;IACrB;EACF,OAAO;IACL,MAAMG,SAAA,GAAYvB,kBAAA,CAAmBK,GAAG,CAAEmB,CAAA,IAAM,IAAIA,CAAA,CAAEjB,IAAI,GAAG,EAAEkB,IAAI,CAAC;IACpE,MAAMC,UAAA,GAA0BtB,QAAA,CAASkB,MAAM,KAAK,IAAIlB,QAAQ,CAAC,EAAE,GAAI;MAAEa,KAAA,EAAOb;IAAS;IACzF,MAAMuB,MAAA,GAAS7B,OAAA,GAAU,oCAAoC;IAC7DuB,MAAA,GAAS;MAAE,GAAGK,UAAU;MAAEE,MAAA,EAAQ,GAAGD,MAAA,IAAUJ,SAAA;IAAa;EAC9D;EAEA,OAAOF,MAAA;AACT","ignoreList":[]}
1
+ {"version":3,"file":"schema.js","names":["formatSchema","versionSchema","SERIALIZED_RELATIONSHIP_NODE_TS","SERIALIZED_RELATIONSHIP_NODE_INPUT_TS","createRelationshipNodeJSONSchema","props","collectionIDFieldTypes","typeStringDefinitions","variant","isInput","add","enabledCollectionSlugs","variants","map","slug","idType","type","additionalProperties","properties","const","format","relationTo","value","description","oneOf","$ref","version","required","schema","length","slugUnion","join","baseSchema","tsName","tsType"],"sources":["../../../../src/features/relationship/server/schema.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\nimport type {\n CollectionSlug,\n DataFromCollectionSlug,\n IDTypeForCollectionSlug,\n UploadCollectionSlug,\n} from 'payload'\n\nimport type { LexicalElementFormat } from '../../../types/nodeTypes.js'\nimport type { JSONSchemaFn } from '../../typesServer.js'\nimport type { RelationshipFeatureServerProps } from './index.js'\n\nimport { formatSchema, versionSchema } from '../../../types/jsonSchemaHelpers.js'\n\nexport type RelationshipData = {\n [TCollectionSlug in CollectionSlug]: {\n relationTo: TCollectionSlug\n value: DataFromCollectionSlug<TCollectionSlug> | IDTypeForCollectionSlug<TCollectionSlug>\n }\n}[CollectionSlug]\n\n/**\n * Exclude upload collection slugs. This matches runtime behavior, as well as the json schema.\n */\nexport type NonUploadCollectionSlug = [Exclude<CollectionSlug, UploadCollectionSlug>] extends [\n never,\n]\n ? CollectionSlug\n : Exclude<CollectionSlug, UploadCollectionSlug>\n\nexport type SerializedRelationshipNode<TSlugs extends CollectionSlug = NonUploadCollectionSlug> = {\n [TSlug in TSlugs]: {\n relationTo: TSlug\n value: DataFromCollectionSlug<TSlug> | IDTypeForCollectionSlug<TSlug>\n }\n}[TSlugs] & {\n format: LexicalElementFormat\n type: 'relationship'\n version: number\n}\n\n/** MUST stay byte-for-byte in sync with the runtime `SerializedRelationshipNode` declared above. */\nconst SERIALIZED_RELATIONSHIP_NODE_TS = `export type SerializedRelationshipNode<TSlugs extends keyof Config['collections']> = {\n type: 'relationship';\n format: LexicalElementFormat;\n version: number;\n} & {\n [TSlug in TSlugs]: {\n relationTo: TSlug;\n value: Config['collections'][TSlug]['id'] | Config['collections'][TSlug];\n };\n}[TSlugs];`\n\n/** Input variant of `SerializedRelationshipNode`: `value` is ID-only (you only ever write an ID). */\nconst SERIALIZED_RELATIONSHIP_NODE_INPUT_TS = `export type SerializedRelationshipNodeInput<TSlugs extends keyof Config['collections']> = {\n type: 'relationship';\n format: LexicalElementFormat;\n version: number;\n} & {\n [TSlug in TSlugs]: {\n relationTo: TSlug;\n value: Config['collections'][TSlug]['id'];\n };\n}[TSlugs];`\n\nexport const createRelationshipNodeJSONSchema =\n (props: RelationshipFeatureServerProps): JSONSchemaFn =>\n ({ collectionIDFieldTypes, typeStringDefinitions, variant }) => {\n const isInput = variant === 'input'\n typeStringDefinitions.add(\n isInput ? SERIALIZED_RELATIONSHIP_NODE_INPUT_TS : SERIALIZED_RELATIONSHIP_NODE_TS,\n )\n const { enabledCollectionSlugs } = props\n\n const variants: JSONSchema4[] = enabledCollectionSlugs.map((slug) => {\n const idType: 'number' | 'string' = collectionIDFieldTypes[slug] ?? 'string'\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', const: 'relationship' },\n format: formatSchema,\n relationTo: { type: 'string', const: slug },\n value: isInput\n ? { type: idType, description: 'The related document ID.' }\n : {\n description:\n 'The related document by ID (string or number). Populated to the full document when read at depth > 0.',\n oneOf: [{ type: idType }, { $ref: `#/$defs/${slug}` }],\n },\n version: versionSchema,\n },\n required: ['format', 'relationTo', 'type', 'value', 'version'],\n }\n })\n\n let schema: JSONSchema4\n if (variants.length === 0) {\n schema = {\n type: 'object',\n additionalProperties: true,\n properties: {\n type: { type: 'string', const: 'relationship' },\n version: versionSchema,\n },\n required: ['type', 'version'],\n }\n } else {\n const slugUnion = enabledCollectionSlugs.map((slug) => `'${slug}'`).join(' | ')\n const baseSchema: JSONSchema4 = variants.length === 1 ? variants[0]! : { oneOf: variants }\n const tsName = isInput ? 'SerializedRelationshipNodeInput' : 'SerializedRelationshipNode'\n schema = { ...baseSchema, tsType: `${tsName}<${slugUnion}>` }\n }\n\n return schema\n }\n"],"mappings":"AAYA,SAASA,YAAY,EAAEC,aAAa,QAAQ;AA6B5C;AACA,MAAMC,+BAAA,GAAkC;;;;;;;;;WAS7B;AAEX;AACA,MAAMC,qCAAA,GAAwC;;;;;;;;;WASnC;AAEX,OAAO,MAAMC,gCAAA,GACVC,KAAA,IACD,CAAC;EAAEC,sBAAsB;EAAEC,qBAAqB;EAAEC;AAAO,CAAE;EACzD,MAAMC,OAAA,GAAUD,OAAA,KAAY;EAC5BD,qBAAA,CAAsBG,GAAG,CACvBD,OAAA,GAAUN,qCAAA,GAAwCD,+BAAA;EAEpD,MAAM;IAAES;EAAsB,CAAE,GAAGN,KAAA;EAEnC,MAAMO,QAAA,GAA0BD,sBAAA,CAAuBE,GAAG,CAAEC,IAAA;IAC1D,MAAMC,MAAA,GAA8BT,sBAAsB,CAACQ,IAAA,CAAK,IAAI;IACpE,OAAO;MACLE,IAAA,EAAM;MACNC,oBAAA,EAAsB;MACtBC,UAAA,EAAY;QACVF,IAAA,EAAM;UAAEA,IAAA,EAAM;UAAUG,KAAA,EAAO;QAAe;QAC9CC,MAAA,EAAQpB,YAAA;QACRqB,UAAA,EAAY;UAAEL,IAAA,EAAM;UAAUG,KAAA,EAAOL;QAAK;QAC1CQ,KAAA,EAAOb,OAAA,GACH;UAAEO,IAAA,EAAMD,MAAA;UAAQQ,WAAA,EAAa;QAA2B,IACxD;UACEA,WAAA,EACE;UACFC,KAAA,EAAO,CAAC;YAAER,IAAA,EAAMD;UAAO,GAAG;YAAEU,IAAA,EAAM,WAAWX,IAAA;UAAO;QACtD;QACJY,OAAA,EAASzB;MACX;MACA0B,QAAA,EAAU,CAAC,UAAU,cAAc,QAAQ,SAAS;IACtD;EACF;EAEA,IAAIC,MAAA;EACJ,IAAIhB,QAAA,CAASiB,MAAM,KAAK,GAAG;IACzBD,MAAA,GAAS;MACPZ,IAAA,EAAM;MACNC,oBAAA,EAAsB;MACtBC,UAAA,EAAY;QACVF,IAAA,EAAM;UAAEA,IAAA,EAAM;UAAUG,KAAA,EAAO;QAAe;QAC9CO,OAAA,EAASzB;MACX;MACA0B,QAAA,EAAU,CAAC,QAAQ;IACrB;EACF,OAAO;IACL,MAAMG,SAAA,GAAYnB,sBAAA,CAAuBE,GAAG,CAAEC,IAAA,IAAS,IAAIA,IAAA,GAAO,EAAEiB,IAAI,CAAC;IACzE,MAAMC,UAAA,GAA0BpB,QAAA,CAASiB,MAAM,KAAK,IAAIjB,QAAQ,CAAC,EAAE,GAAI;MAAEY,KAAA,EAAOZ;IAAS;IACzF,MAAMqB,MAAA,GAASxB,OAAA,GAAU,oCAAoC;IAC7DmB,MAAA,GAAS;MAAE,GAAGI,UAAU;MAAEE,MAAA,EAAQ,GAAGD,MAAA,IAAUH,SAAA;IAAa;EAC9D;EAEA,OAAOF,MAAA;AACT","ignoreList":[]}
@@ -12,12 +12,7 @@ export type FilterEnabledRelationshipCollectionsOptions = {
12
12
  enabledCollections?: readonly string[];
13
13
  /** When `true`, only upload-enabled collections; when `false`, only non-upload ones. */
14
14
  uploads: boolean;
15
- /**
16
- * Slugs the current user can see, supplied by the client at runtime.
17
- * Server-side type generation passes `undefined` to skip the check.
18
- */
19
- visibleSlugs?: readonly string[];
20
15
  };
21
- export declare const filterEnabledRelationshipCollections: <TCollection extends CollectionLike>(collections: readonly TCollection[], { disabledCollections, enabledCollections, uploads, visibleSlugs, }: FilterEnabledRelationshipCollectionsOptions) => TCollection[];
16
+ export declare const filterEnabledRelationshipCollections: <TCollection extends CollectionLike>(collections: readonly TCollection[], { disabledCollections, enabledCollections, uploads }: FilterEnabledRelationshipCollectionsOptions) => TCollection[];
22
17
  export {};
23
18
  //# sourceMappingURL=filterEnabledRelationshipCollections.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"filterEnabledRelationshipCollections.d.ts","sourceRoot":"","sources":["../../../../src/features/relationship/shared/filterEnabledRelationshipCollections.ts"],"names":[],"mappings":"AAAA,KAAK,cAAc,GAAG;IACpB,KAAK,CAAC,EAAE;QACN,0BAA0B,CAAC,EAAE,OAAO,CAAA;KACrC,CAAA;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,2CAA2C,GAAG;IACxD,2DAA2D;IAC3D,mBAAmB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACvC,0DAA0D;IAC1D,kBAAkB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACtC,wFAAwF;IACxF,OAAO,EAAE,OAAO,CAAA;IAChB;;;OAGG;IACH,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CACjC,CAAA;AAED,eAAO,MAAM,oCAAoC,GAAI,WAAW,SAAS,cAAc,eACxE,SAAS,WAAW,EAAE,uEAMhC,2CAA2C,KAC7C,WAAW,EA4Bb,CAAA"}
1
+ {"version":3,"file":"filterEnabledRelationshipCollections.d.ts","sourceRoot":"","sources":["../../../../src/features/relationship/shared/filterEnabledRelationshipCollections.ts"],"names":[],"mappings":"AAAA,KAAK,cAAc,GAAG;IACpB,KAAK,CAAC,EAAE;QACN,0BAA0B,CAAC,EAAE,OAAO,CAAA;KACrC,CAAA;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,2CAA2C,GAAG;IACxD,2DAA2D;IAC3D,mBAAmB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACvC,0DAA0D;IAC1D,kBAAkB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACtC,wFAAwF;IACxF,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,oCAAoC,GAAI,WAAW,SAAS,cAAc,eACxE,SAAS,WAAW,EAAE,wDACmB,2CAA2C,KAChG,WAAW,EAwBb,CAAA"}
@@ -1,8 +1,7 @@
1
1
  export const filterEnabledRelationshipCollections = (collections, {
2
2
  disabledCollections,
3
3
  enabledCollections,
4
- uploads,
5
- visibleSlugs
4
+ uploads
6
5
  }) => {
7
6
  const whitelistSet = enabledCollections?.length ? new Set(enabledCollections) : null;
8
7
  const blacklistSet = disabledCollections?.length ? new Set(disabledCollections) : null;
@@ -12,9 +11,6 @@ export const filterEnabledRelationshipCollections = (collections, {
12
11
  admin,
13
12
  upload
14
13
  } = collection;
15
- if (visibleSlugs && !visibleSlugs.includes(slug)) {
16
- return false;
17
- }
18
14
  if (uploads) {
19
15
  if (!admin?.enableRichTextRelationship || !upload) {
20
16
  return false;
@@ -1 +1 @@
1
- {"version":3,"file":"filterEnabledRelationshipCollections.js","names":["filterEnabledRelationshipCollections","collections","disabledCollections","enabledCollections","uploads","visibleSlugs","whitelistSet","length","Set","blacklistSet","filter","collection","slug","admin","upload","includes","enableRichTextRelationship","has"],"sources":["../../../../src/features/relationship/shared/filterEnabledRelationshipCollections.ts"],"sourcesContent":["type CollectionLike = {\n admin?: {\n enableRichTextRelationship?: boolean\n }\n slug: string\n upload?: unknown\n}\n\nexport type FilterEnabledRelationshipCollectionsOptions = {\n /** `disabledCollections` feature prop — slug blacklist. */\n disabledCollections?: readonly string[]\n /** `enabledCollections` feature prop — slug whitelist. */\n enabledCollections?: readonly string[]\n /** When `true`, only upload-enabled collections; when `false`, only non-upload ones. */\n uploads: boolean\n /**\n * Slugs the current user can see, supplied by the client at runtime.\n * Server-side type generation passes `undefined` to skip the check.\n */\n visibleSlugs?: readonly string[]\n}\n\nexport const filterEnabledRelationshipCollections = <TCollection extends CollectionLike>(\n collections: readonly TCollection[],\n {\n disabledCollections,\n enabledCollections,\n uploads,\n visibleSlugs,\n }: FilterEnabledRelationshipCollectionsOptions,\n): TCollection[] => {\n const whitelistSet = enabledCollections?.length ? new Set(enabledCollections) : null\n const blacklistSet = disabledCollections?.length ? new Set(disabledCollections) : null\n\n return collections.filter((collection) => {\n const { slug, admin, upload } = collection\n\n if (visibleSlugs && !visibleSlugs.includes(slug)) {\n return false\n }\n\n if (uploads) {\n if (!admin?.enableRichTextRelationship || !upload) {\n return false\n }\n } else if (upload || !admin?.enableRichTextRelationship) {\n return false\n }\n\n if (whitelistSet && !whitelistSet.has(slug)) {\n return false\n }\n if (blacklistSet && blacklistSet.has(slug)) {\n return false\n }\n\n return true\n })\n}\n"],"mappings":"AAsBA,OAAO,MAAMA,oCAAA,GAAuCA,CAClDC,WAAA,EACA;EACEC,mBAAmB;EACnBC,kBAAkB;EAClBC,OAAO;EACPC;AAAY,CACgC;EAE9C,MAAMC,YAAA,GAAeH,kBAAA,EAAoBI,MAAA,GAAS,IAAIC,GAAA,CAAIL,kBAAA,IAAsB;EAChF,MAAMM,YAAA,GAAeP,mBAAA,EAAqBK,MAAA,GAAS,IAAIC,GAAA,CAAIN,mBAAA,IAAuB;EAElF,OAAOD,WAAA,CAAYS,MAAM,CAAEC,UAAA;IACzB,MAAM;MAAEC,IAAI;MAAEC,KAAK;MAAEC;IAAM,CAAE,GAAGH,UAAA;IAEhC,IAAIN,YAAA,IAAgB,CAACA,YAAA,CAAaU,QAAQ,CAACH,IAAA,GAAO;MAChD,OAAO;IACT;IAEA,IAAIR,OAAA,EAAS;MACX,IAAI,CAACS,KAAA,EAAOG,0BAAA,IAA8B,CAACF,MAAA,EAAQ;QACjD,OAAO;MACT;IACF,OAAO,IAAIA,MAAA,IAAU,CAACD,KAAA,EAAOG,0BAAA,EAA4B;MACvD,OAAO;IACT;IAEA,IAAIV,YAAA,IAAgB,CAACA,YAAA,CAAaW,GAAG,CAACL,IAAA,GAAO;MAC3C,OAAO;IACT;IACA,IAAIH,YAAA,IAAgBA,YAAA,CAAaQ,GAAG,CAACL,IAAA,GAAO;MAC1C,OAAO;IACT;IAEA,OAAO;EACT;AACF","ignoreList":[]}
1
+ {"version":3,"file":"filterEnabledRelationshipCollections.js","names":["filterEnabledRelationshipCollections","collections","disabledCollections","enabledCollections","uploads","whitelistSet","length","Set","blacklistSet","filter","collection","slug","admin","upload","enableRichTextRelationship","has"],"sources":["../../../../src/features/relationship/shared/filterEnabledRelationshipCollections.ts"],"sourcesContent":["type CollectionLike = {\n admin?: {\n enableRichTextRelationship?: boolean\n }\n slug: string\n upload?: unknown\n}\n\nexport type FilterEnabledRelationshipCollectionsOptions = {\n /** `disabledCollections` feature prop — slug blacklist. */\n disabledCollections?: readonly string[]\n /** `enabledCollections` feature prop — slug whitelist. */\n enabledCollections?: readonly string[]\n /** When `true`, only upload-enabled collections; when `false`, only non-upload ones. */\n uploads: boolean\n}\n\nexport const filterEnabledRelationshipCollections = <TCollection extends CollectionLike>(\n collections: readonly TCollection[],\n { disabledCollections, enabledCollections, uploads }: FilterEnabledRelationshipCollectionsOptions,\n): TCollection[] => {\n const whitelistSet = enabledCollections?.length ? new Set(enabledCollections) : null\n const blacklistSet = disabledCollections?.length ? new Set(disabledCollections) : null\n\n return collections.filter((collection) => {\n const { slug, admin, upload } = collection\n\n if (uploads) {\n if (!admin?.enableRichTextRelationship || !upload) {\n return false\n }\n } else if (upload || !admin?.enableRichTextRelationship) {\n return false\n }\n\n if (whitelistSet && !whitelistSet.has(slug)) {\n return false\n }\n if (blacklistSet && blacklistSet.has(slug)) {\n return false\n }\n\n return true\n })\n}\n"],"mappings":"AAiBA,OAAO,MAAMA,oCAAA,GAAuCA,CAClDC,WAAA,EACA;EAAEC,mBAAmB;EAAEC,kBAAkB;EAAEC;AAAO,CAA+C;EAEjG,MAAMC,YAAA,GAAeF,kBAAA,EAAoBG,MAAA,GAAS,IAAIC,GAAA,CAAIJ,kBAAA,IAAsB;EAChF,MAAMK,YAAA,GAAeN,mBAAA,EAAqBI,MAAA,GAAS,IAAIC,GAAA,CAAIL,mBAAA,IAAuB;EAElF,OAAOD,WAAA,CAAYQ,MAAM,CAAEC,UAAA;IACzB,MAAM;MAAEC,IAAI;MAAEC,KAAK;MAAEC;IAAM,CAAE,GAAGH,UAAA;IAEhC,IAAIN,OAAA,EAAS;MACX,IAAI,CAACQ,KAAA,EAAOE,0BAAA,IAA8B,CAACD,MAAA,EAAQ;QACjD,OAAO;MACT;IACF,OAAO,IAAIA,MAAA,IAAU,CAACD,KAAA,EAAOE,0BAAA,EAA4B;MACvD,OAAO;IACT;IAEA,IAAIT,YAAA,IAAgB,CAACA,YAAA,CAAaU,GAAG,CAACJ,IAAA,GAAO;MAC3C,OAAO;IACT;IACA,IAAIH,YAAA,IAAgBA,YAAA,CAAaO,GAAG,CAACJ,IAAA,GAAO;MAC1C,OAAO;IACT;IAEA,OAAO;EACT;AACF","ignoreList":[]}
@@ -0,0 +1,8 @@
1
+ import type { TableSelection } from '@lexical/table';
2
+ export declare function $computeSelectionCount({ selection }: {
3
+ selection: TableSelection;
4
+ }): {
5
+ columns: number;
6
+ rows: number;
7
+ };
8
+ //# sourceMappingURL=computeSelectionCount.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"computeSelectionCount.d.ts","sourceRoot":"","sources":["../../../../../../src/features/table/client/plugins/TableActionMenuPlugin/computeSelectionCount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAIpD,wBAAgB,sBAAsB,CAAC,EAAE,SAAS,EAAE,EAAE;IAAE,SAAS,EAAE,cAAc,CAAA;CAAE,GAAG;IACpF,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;CACb,CAUA"}
@@ -0,0 +1,19 @@
1
+ import { $computeTableCellRectBoundary, $computeTableMap, $getNodeTriplet } from '@lexical/table';
2
+ export function $computeSelectionCount({
3
+ selection
4
+ }) {
5
+ const [anchorCell,, table] = $getNodeTriplet(selection.anchor);
6
+ const [focusCell] = $getNodeTriplet(selection.focus);
7
+ const [map, anchor, focus] = $computeTableMap(table, anchorCell, focusCell);
8
+ const {
9
+ maxColumn,
10
+ maxRow,
11
+ minColumn,
12
+ minRow
13
+ } = $computeTableCellRectBoundary(map, anchor, focus);
14
+ return {
15
+ columns: maxColumn - minColumn + 1,
16
+ rows: maxRow - minRow + 1
17
+ };
18
+ }
19
+ //# sourceMappingURL=computeSelectionCount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"computeSelectionCount.js","names":["$computeTableCellRectBoundary","$computeTableMap","$getNodeTriplet","$computeSelectionCount","selection","anchorCell","table","anchor","focusCell","focus","map","maxColumn","maxRow","minColumn","minRow","columns","rows"],"sources":["../../../../../../src/features/table/client/plugins/TableActionMenuPlugin/computeSelectionCount.ts"],"sourcesContent":["import type { TableSelection } from '@lexical/table'\n\nimport { $computeTableCellRectBoundary, $computeTableMap, $getNodeTriplet } from '@lexical/table'\n\nexport function $computeSelectionCount({ selection }: { selection: TableSelection }): {\n columns: number\n rows: number\n} {\n const [anchorCell, , table] = $getNodeTriplet(selection.anchor)\n const [focusCell] = $getNodeTriplet(selection.focus)\n const [map, anchor, focus] = $computeTableMap(table, anchorCell, focusCell)\n const { maxColumn, maxRow, minColumn, minRow } = $computeTableCellRectBoundary(map, anchor, focus)\n\n return {\n columns: maxColumn - minColumn + 1,\n rows: maxRow - minRow + 1,\n }\n}\n"],"mappings":"AAEA,SAASA,6BAA6B,EAAEC,gBAAgB,EAAEC,eAAe,QAAQ;AAEjF,OAAO,SAASC,uBAAuB;EAAEC;AAAS,CAAiC;EAIjF,MAAM,CAACC,UAAA,GAAcC,KAAA,CAAM,GAAGJ,eAAA,CAAgBE,SAAA,CAAUG,MAAM;EAC9D,MAAM,CAACC,SAAA,CAAU,GAAGN,eAAA,CAAgBE,SAAA,CAAUK,KAAK;EACnD,MAAM,CAACC,GAAA,EAAKH,MAAA,EAAQE,KAAA,CAAM,GAAGR,gBAAA,CAAiBK,KAAA,EAAOD,UAAA,EAAYG,SAAA;EACjE,MAAM;IAAEG,SAAS;IAAEC,MAAM;IAAEC,SAAS;IAAEC;EAAM,CAAE,GAAGd,6BAAA,CAA8BU,GAAA,EAAKH,MAAA,EAAQE,KAAA;EAE5F,OAAO;IACLM,OAAA,EAASJ,SAAA,GAAYE,SAAA,GAAY;IACjCG,IAAA,EAAMJ,MAAA,GAASE,MAAA,GAAS;EAC1B;AACF","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/features/table/client/plugins/TableActionMenuPlugin/index.tsx"],"names":[],"mappings":"AA6CA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAA;AAE3E,OAAO,aAAa,CAAA;AA6oBpB,eAAO,MAAM,qBAAqB,EAAE,yBAQnC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/features/table/client/plugins/TableActionMenuPlugin/index.tsx"],"names":[],"mappings":"AA8CA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAA;AAE3E,OAAO,aAAa,CAAA;AAqmBpB,eAAO,MAAM,qBAAqB,EAAE,yBAQnC,CAAA"}
@@ -4,7 +4,7 @@ import { c as _c } from "react/compiler-runtime";
4
4
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
5
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
6
6
  import { useLexicalEditable } from '@lexical/react/useLexicalEditable';
7
- import { $computeTableMapSkipCellCheck, $deleteTableColumnAtSelection, $deleteTableRowAtSelection, $getNodeTriplet, $getTableCellNodeFromLexicalNode, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $insertTableColumnAtSelection, $insertTableRowAtSelection, $isTableCellNode, $isTableSelection, $mergeCells, $unmergeCell, getTableElement, getTableObserverFromTableElement, TableCellHeaderStates, TableCellNode } from '@lexical/table';
7
+ import { $computeTableMap, $deleteTableColumnAtSelection, $deleteTableRowAtSelection, $getNodeTriplet, $getTableCellNodeFromLexicalNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $insertTableColumnAtSelection, $insertTableRowAtSelection, $isTableCellNode, $isTableSelection, $mergeCells, $setTableColumnIsHeader, $setTableRowIsHeader, $unmergeCell, getTableElement, getTableObserverFromTableElement, TableCellHeaderStates, TableCellNode } from '@lexical/table';
8
8
  import { mergeRegister } from '@lexical/utils';
9
9
  import { useScrollInfo } from '@payloadcms/ui';
10
10
  import { $getSelection, $isElementNode, $isRangeSelection, $isTextNode, $setSelection, COMMAND_PRIORITY_CRITICAL, getDOMSelection, isDOMNode, SELECTION_CHANGE_COMMAND } from 'lexical';
@@ -13,13 +13,7 @@ import { useCallback, useEffect, useRef, useState } from 'react';
13
13
  import { createPortal } from 'react-dom';
14
14
  import './index.css';
15
15
  import { MeatballsIcon } from '../../../../../lexical/ui/icons/Meatballs/index.js';
16
- function computeSelectionCount(selection) {
17
- const selectionShape = selection.getShape();
18
- return {
19
- columns: selectionShape.toX - selectionShape.fromX + 1,
20
- rows: selectionShape.toY - selectionShape.fromY + 1
21
- };
22
- }
16
+ import { $computeSelectionCount } from './computeSelectionCount.js';
23
17
  function $canUnmerge() {
24
18
  const selection = $getSelection();
25
19
  if ($isRangeSelection(selection) && !selection.isCollapsed() || $isTableSelection(selection) && !selection.anchor.is(selection.focus) || !$isRangeSelection(selection) && !$isTableSelection(selection)) {
@@ -74,9 +68,12 @@ function TableActionMenu({
74
68
  const selection = $getSelection();
75
69
  // Merge cells
76
70
  if ($isTableSelection(selection)) {
77
- const currentSelectionCounts = computeSelectionCount(selection);
78
- updateSelectionCounts(computeSelectionCount(selection));
79
- setCanMergeCells(currentSelectionCounts.columns > 1 || currentSelectionCounts.rows > 1);
71
+ const currentSelectionCounts = $computeSelectionCount({
72
+ selection
73
+ });
74
+ updateSelectionCounts(currentSelectionCounts);
75
+ const isCollapsedTableSelection = selection.anchor.is(selection.focus);
76
+ setCanMergeCells(!isCollapsedTableSelection && (currentSelectionCounts.columns > 1 || currentSelectionCounts.rows > 1));
80
77
  }
81
78
  // Unmerge cell
82
79
  setCanUnmergeCell($canUnmerge());
@@ -152,6 +149,7 @@ function TableActionMenu({
152
149
  editor.update(() => {
153
150
  $unmergeCell();
154
151
  });
152
+ clearTableSelection();
155
153
  };
156
154
  const insertTableRowAtSelection = useCallback(shouldInsertAfter => {
157
155
  editor.update(() => {
@@ -192,22 +190,9 @@ function TableActionMenu({
192
190
  const toggleTableRowIsHeader = useCallback(() => {
193
191
  editor.update(() => {
194
192
  const tableNode_1 = $getTableNodeFromLexicalNodeOrThrow(tableCellNode);
195
- const tableRowIndex = $getTableRowIndexFromTableCellNode(tableCellNode);
196
- const [gridMap] = $computeTableMapSkipCellCheck(tableNode_1, null, null);
197
- const rowCells = new Set();
198
- const newStyle = tableCellNode.getHeaderStyles() ^ TableCellHeaderStates.ROW;
199
- if (gridMap[tableRowIndex]) {
200
- for (let col = 0; col < gridMap[tableRowIndex].length; col++) {
201
- const mapCell = gridMap[tableRowIndex][col];
202
- if (!mapCell?.cell) {
203
- continue;
204
- }
205
- if (!rowCells.has(mapCell.cell)) {
206
- rowCells.add(mapCell.cell);
207
- mapCell.cell.setHeaderStyles(newStyle, TableCellHeaderStates.ROW);
208
- }
209
- }
210
- }
193
+ const rowIndex = $getTableRowIndexFromTableCellNode(tableCellNode);
194
+ const isHeader = !tableCellNode.hasHeaderState(TableCellHeaderStates.ROW);
195
+ $setTableRowIsHeader(tableNode_1, rowIndex, isHeader);
211
196
  clearTableSelection();
212
197
  onClose();
213
198
  });
@@ -215,22 +200,10 @@ function TableActionMenu({
215
200
  const toggleTableColumnIsHeader = useCallback(() => {
216
201
  editor.update(() => {
217
202
  const tableNode_2 = $getTableNodeFromLexicalNodeOrThrow(tableCellNode);
218
- const tableColumnIndex = $getTableColumnIndexFromTableCellNode(tableCellNode);
219
- const [gridMap_0] = $computeTableMapSkipCellCheck(tableNode_2, null, null);
220
- const columnCells = new Set();
221
- const newStyle_0 = tableCellNode.getHeaderStyles() ^ TableCellHeaderStates.COLUMN;
222
- if (gridMap_0) {
223
- for (let row = 0; row < gridMap_0.length; row++) {
224
- const mapCell_0 = gridMap_0?.[row]?.[tableColumnIndex];
225
- if (!mapCell_0?.cell) {
226
- continue;
227
- }
228
- if (!columnCells.has(mapCell_0.cell)) {
229
- columnCells.add(mapCell_0.cell);
230
- mapCell_0.cell.setHeaderStyles(newStyle_0, TableCellHeaderStates.COLUMN);
231
- }
232
- }
233
- }
203
+ // Merged cells can make the grid column differ from the cell's index in its row.
204
+ const [, cellMap] = $computeTableMap(tableNode_2, tableCellNode, tableCellNode);
205
+ const isHeader_0 = !tableCellNode.hasHeaderState(TableCellHeaderStates.COLUMN);
206
+ $setTableColumnIsHeader(tableNode_2, cellMap.startColumn, isHeader_0);
234
207
  clearTableSelection();
235
208
  onClose();
236
209
  });