@payloadcms/richtext-lexical 3.59.1 → 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 (187) hide show
  1. package/dist/exports/client/Field-CJFETHA3.js +2 -0
  2. package/dist/exports/client/Field-CJFETHA3.js.map +7 -0
  3. package/dist/exports/client/RelationshipComponent-JXQOFHXF.js +2 -0
  4. package/dist/exports/client/RelationshipComponent-JXQOFHXF.js.map +7 -0
  5. package/dist/exports/client/bundled.css +1 -1
  6. package/dist/exports/client/chunk-O6XRT2H3.js +2 -0
  7. package/dist/exports/client/chunk-O6XRT2H3.js.map +7 -0
  8. package/dist/exports/client/{chunk-2Y72RT72.js → chunk-TLQLXR6Q.js} +2 -2
  9. package/dist/exports/client/chunk-XNERFY6G.js +2 -0
  10. package/dist/exports/client/chunk-XNERFY6G.js.map +7 -0
  11. package/dist/exports/client/component-WT25HAJA.js +2 -0
  12. package/dist/exports/client/component-WT25HAJA.js.map +7 -0
  13. package/dist/exports/client/componentInline-NGTRUSGB.js +2 -0
  14. package/dist/exports/client/index.d.ts +3 -0
  15. package/dist/exports/client/index.d.ts.map +1 -1
  16. package/dist/exports/client/index.js +35 -10
  17. package/dist/exports/client/index.js.map +4 -4
  18. package/dist/features/blocks/client/component/BlockContent.d.ts +52 -27
  19. package/dist/features/blocks/client/component/BlockContent.d.ts.map +1 -1
  20. package/dist/features/blocks/client/component/BlockContent.js +48 -51
  21. package/dist/features/blocks/client/component/BlockContent.js.map +1 -1
  22. package/dist/features/blocks/client/component/components/BlockCollapsible.d.ts +2 -9
  23. package/dist/features/blocks/client/component/components/BlockCollapsible.d.ts.map +1 -1
  24. package/dist/features/blocks/client/component/components/BlockCollapsible.js +7 -25
  25. package/dist/features/blocks/client/component/components/BlockCollapsible.js.map +1 -1
  26. package/dist/features/blocks/client/component/index.d.ts.map +1 -1
  27. package/dist/features/blocks/client/component/index.js +71 -56
  28. package/dist/features/blocks/client/component/index.js.map +1 -1
  29. package/dist/features/blocks/client/componentInline/index.d.ts.map +1 -1
  30. package/dist/features/blocks/client/componentInline/index.js +13 -11
  31. package/dist/features/blocks/client/componentInline/index.js.map +1 -1
  32. package/dist/features/blocks/client/index.d.ts.map +1 -1
  33. package/dist/features/blocks/client/index.js +5 -0
  34. package/dist/features/blocks/client/index.js.map +1 -1
  35. package/dist/features/blocks/client/markdown/getLexicalToMarkdown.d.ts +6 -0
  36. package/dist/features/blocks/client/markdown/getLexicalToMarkdown.d.ts.map +1 -0
  37. package/dist/features/blocks/client/markdown/getLexicalToMarkdown.js +24 -0
  38. package/dist/features/blocks/client/markdown/getLexicalToMarkdown.js.map +1 -0
  39. package/dist/features/blocks/client/markdown/getMarkdownToLexical.d.ts +6 -0
  40. package/dist/features/blocks/client/markdown/getMarkdownToLexical.d.ts.map +1 -0
  41. package/dist/features/blocks/client/markdown/getMarkdownToLexical.js +20 -0
  42. package/dist/features/blocks/client/markdown/getMarkdownToLexical.js.map +1 -0
  43. package/dist/features/blocks/client/markdown/markdownTransformer.d.ts +12 -0
  44. package/dist/features/blocks/client/markdown/markdownTransformer.d.ts.map +1 -0
  45. package/dist/features/blocks/client/markdown/markdownTransformer.js +348 -0
  46. package/dist/features/blocks/client/markdown/markdownTransformer.js.map +1 -0
  47. package/dist/features/blocks/premade/CodeBlock/Component/Block.d.ts +5 -0
  48. package/dist/features/blocks/premade/CodeBlock/Component/Block.d.ts.map +1 -0
  49. package/dist/features/blocks/premade/CodeBlock/Component/Block.js +114 -0
  50. package/dist/features/blocks/premade/CodeBlock/Component/Block.js.map +1 -0
  51. package/dist/features/blocks/premade/CodeBlock/Component/Code.d.ts +56 -0
  52. package/dist/features/blocks/premade/CodeBlock/Component/Code.d.ts.map +1 -0
  53. package/dist/features/blocks/premade/CodeBlock/Component/Code.js +96 -0
  54. package/dist/features/blocks/premade/CodeBlock/Component/Code.js.map +1 -0
  55. package/dist/features/blocks/premade/CodeBlock/Component/Collapse/index.d.ts +4 -0
  56. package/dist/features/blocks/premade/CodeBlock/Component/Collapse/index.d.ts.map +1 -0
  57. package/dist/features/blocks/premade/CodeBlock/Component/Collapse/index.js +17 -0
  58. package/dist/features/blocks/premade/CodeBlock/Component/Collapse/index.js.map +1 -0
  59. package/dist/features/blocks/premade/CodeBlock/Component/FloatingCollapse/index.d.ts +4 -0
  60. package/dist/features/blocks/premade/CodeBlock/Component/FloatingCollapse/index.d.ts.map +1 -0
  61. package/dist/features/blocks/premade/CodeBlock/Component/FloatingCollapse/index.js +26 -0
  62. package/dist/features/blocks/premade/CodeBlock/Component/FloatingCollapse/index.js.map +1 -0
  63. package/dist/features/blocks/premade/CodeBlock/Component/defaultLanguages.d.ts +5 -0
  64. package/dist/features/blocks/premade/CodeBlock/Component/defaultLanguages.d.ts.map +1 -0
  65. package/dist/features/blocks/premade/CodeBlock/Component/defaultLanguages.js +87 -0
  66. package/dist/features/blocks/premade/CodeBlock/Component/defaultLanguages.js.map +1 -0
  67. package/dist/features/blocks/premade/CodeBlock/converter.d.ts +7 -0
  68. package/dist/features/blocks/premade/CodeBlock/converter.d.ts.map +1 -0
  69. package/dist/features/blocks/premade/CodeBlock/converter.js +46 -0
  70. package/dist/features/blocks/premade/CodeBlock/converter.js.map +1 -0
  71. package/dist/features/blocks/premade/CodeBlock/converterClient.d.ts +2 -0
  72. package/dist/features/blocks/premade/CodeBlock/converterClient.d.ts.map +1 -0
  73. package/dist/features/blocks/premade/CodeBlock/converterClient.js +4 -0
  74. package/dist/features/blocks/premade/CodeBlock/converterClient.js.map +1 -0
  75. package/dist/features/blocks/premade/CodeBlock/index.d.ts +7 -0
  76. package/dist/features/blocks/premade/CodeBlock/index.d.ts.map +1 -0
  77. package/dist/features/blocks/premade/CodeBlock/index.js +50 -0
  78. package/dist/features/blocks/premade/CodeBlock/index.js.map +1 -0
  79. package/dist/features/blocks/server/index.js +1 -1
  80. package/dist/features/blocks/server/index.js.map +1 -1
  81. package/dist/features/blocks/server/markdown/linesFromMatchToContentAndPropsString.d.ts.map +1 -0
  82. package/dist/features/blocks/server/markdown/linesFromMatchToContentAndPropsString.js.map +1 -0
  83. package/dist/features/blocks/server/markdown/markdownTransformer.d.ts +15 -0
  84. package/dist/features/blocks/server/markdown/markdownTransformer.d.ts.map +1 -0
  85. package/dist/features/blocks/server/{markdownTransformer.js → markdown/markdownTransformer.js} +22 -53
  86. package/dist/features/blocks/server/markdown/markdownTransformer.js.map +1 -0
  87. package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.d.ts.map +1 -1
  88. package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js +5 -3
  89. package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js.map +1 -1
  90. package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.d.ts.map +1 -1
  91. package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js +3 -1
  92. package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js.map +1 -1
  93. package/dist/features/relationship/client/components/RelationshipComponent.d.ts +1 -1
  94. package/dist/features/relationship/client/components/RelationshipComponent.d.ts.map +1 -1
  95. package/dist/features/relationship/client/components/RelationshipComponent.js +6 -15
  96. package/dist/features/relationship/client/components/RelationshipComponent.js.map +1 -1
  97. package/dist/features/relationship/client/drawer/index.d.ts +3 -2
  98. package/dist/features/relationship/client/drawer/index.d.ts.map +1 -1
  99. package/dist/features/relationship/client/drawer/index.js +72 -59
  100. package/dist/features/relationship/client/drawer/index.js.map +1 -1
  101. package/dist/features/relationship/client/plugins/index.d.ts.map +1 -1
  102. package/dist/features/relationship/client/plugins/index.js +41 -49
  103. package/dist/features/relationship/client/plugins/index.js.map +1 -1
  104. package/dist/features/relationship/client/utils/useEnabledRelationships.d.ts +13 -0
  105. package/dist/features/relationship/client/utils/useEnabledRelationships.d.ts.map +1 -0
  106. package/dist/features/relationship/client/utils/useEnabledRelationships.js +64 -0
  107. package/dist/features/relationship/client/utils/useEnabledRelationships.js.map +1 -0
  108. package/dist/features/toolbars/fixed/client/Toolbar/index.d.ts.map +1 -1
  109. package/dist/features/toolbars/fixed/client/Toolbar/index.js +7 -1
  110. package/dist/features/toolbars/fixed/client/Toolbar/index.js.map +1 -1
  111. package/dist/features/toolbars/inline/client/Toolbar/index.d.ts.map +1 -1
  112. package/dist/features/toolbars/inline/client/Toolbar/index.js +3 -1
  113. package/dist/features/toolbars/inline/client/Toolbar/index.js.map +1 -1
  114. package/dist/features/upload/client/component/index.d.ts +1 -1
  115. package/dist/features/upload/client/component/index.d.ts.map +1 -1
  116. package/dist/features/upload/client/component/index.js +7 -16
  117. package/dist/features/upload/client/component/index.js.map +1 -1
  118. package/dist/features/upload/client/drawer/index.d.ts +3 -2
  119. package/dist/features/upload/client/drawer/index.d.ts.map +1 -1
  120. package/dist/features/upload/client/drawer/index.js +8 -9
  121. package/dist/features/upload/client/drawer/index.js.map +1 -1
  122. package/dist/features/upload/client/index.d.ts +2 -1
  123. package/dist/features/upload/client/index.d.ts.map +1 -1
  124. package/dist/features/upload/client/index.js.map +1 -1
  125. package/dist/features/upload/client/plugin/index.d.ts.map +1 -1
  126. package/dist/features/upload/client/plugin/index.js +72 -75
  127. package/dist/features/upload/client/plugin/index.js.map +1 -1
  128. package/dist/features/upload/server/index.d.ts +18 -3
  129. package/dist/features/upload/server/index.d.ts.map +1 -1
  130. package/dist/features/upload/server/index.js +6 -0
  131. package/dist/features/upload/server/index.js.map +1 -1
  132. package/dist/field/bundled.css +1 -1
  133. package/dist/field/rscEntry.d.ts.map +1 -1
  134. package/dist/field/rscEntry.js +2 -0
  135. package/dist/field/rscEntry.js.map +1 -1
  136. package/dist/index.d.ts +1 -0
  137. package/dist/index.d.ts.map +1 -1
  138. package/dist/index.js +1 -0
  139. package/dist/index.js.map +1 -1
  140. package/dist/lexical/LexicalEditor.d.ts.map +1 -1
  141. package/dist/lexical/LexicalEditor.js +20 -26
  142. package/dist/lexical/LexicalEditor.js.map +1 -1
  143. package/dist/lexical/ui/icons/CodeBlock/index.d.ts.map +1 -1
  144. package/dist/lexical/ui/icons/CodeBlock/index.js +10 -15
  145. package/dist/lexical/ui/icons/CodeBlock/index.js.map +1 -1
  146. package/dist/lexical/ui/icons/Collapse/index.d.ts +3 -0
  147. package/dist/lexical/ui/icons/Collapse/index.d.ts.map +1 -0
  148. package/dist/lexical/ui/icons/Collapse/index.js +18 -0
  149. package/dist/lexical/ui/icons/Collapse/index.js.map +1 -0
  150. package/dist/utilities/buildInitialState.d.ts +1 -0
  151. package/dist/utilities/buildInitialState.d.ts.map +1 -1
  152. package/dist/utilities/buildInitialState.js +1 -0
  153. package/dist/utilities/buildInitialState.js.map +1 -1
  154. package/dist/utilities/fieldsDrawer/DrawerContent.d.ts.map +1 -1
  155. package/dist/utilities/fieldsDrawer/DrawerContent.js +7 -3
  156. package/dist/utilities/fieldsDrawer/DrawerContent.js.map +1 -1
  157. package/dist/utilities/jsx/collectTopLevelJSXInLines.js +2 -2
  158. package/dist/utilities/jsx/collectTopLevelJSXInLines.js.map +1 -1
  159. package/package.json +7 -7
  160. package/dist/exports/client/Field-EHRBYNHO.js +0 -2
  161. package/dist/exports/client/Field-EHRBYNHO.js.map +0 -7
  162. package/dist/exports/client/RelationshipComponent-APF3CN47.js +0 -2
  163. package/dist/exports/client/RelationshipComponent-APF3CN47.js.map +0 -7
  164. package/dist/exports/client/chunk-3BY5IZJD.js +0 -2
  165. package/dist/exports/client/chunk-3BY5IZJD.js.map +0 -7
  166. package/dist/exports/client/chunk-CYLMY5ZJ.js +0 -2
  167. package/dist/exports/client/chunk-CYLMY5ZJ.js.map +0 -7
  168. package/dist/exports/client/component-VDJI45F2.js +0 -2
  169. package/dist/exports/client/component-VDJI45F2.js.map +0 -7
  170. package/dist/exports/client/componentInline-7TPI7ZBC.js +0 -2
  171. package/dist/features/blocks/client/markdownTransformer.d.ts +0 -17
  172. package/dist/features/blocks/client/markdownTransformer.d.ts.map +0 -1
  173. package/dist/features/blocks/client/markdownTransformer.js +0 -144
  174. package/dist/features/blocks/client/markdownTransformer.js.map +0 -1
  175. package/dist/features/blocks/server/linesFromMatchToContentAndPropsString.d.ts.map +0 -1
  176. package/dist/features/blocks/server/linesFromMatchToContentAndPropsString.js.map +0 -1
  177. package/dist/features/blocks/server/markdownTransformer.d.ts +0 -22
  178. package/dist/features/blocks/server/markdownTransformer.d.ts.map +0 -1
  179. package/dist/features/blocks/server/markdownTransformer.js.map +0 -1
  180. package/dist/features/relationship/client/utils/EnabledRelationshipsCondition.d.ts +0 -7
  181. package/dist/features/relationship/client/utils/EnabledRelationshipsCondition.d.ts.map +0 -1
  182. package/dist/features/relationship/client/utils/EnabledRelationshipsCondition.js +0 -96
  183. package/dist/features/relationship/client/utils/EnabledRelationshipsCondition.js.map +0 -1
  184. /package/dist/exports/client/{chunk-2Y72RT72.js.map → chunk-TLQLXR6Q.js.map} +0 -0
  185. /package/dist/exports/client/{componentInline-7TPI7ZBC.js.map → componentInline-NGTRUSGB.js.map} +0 -0
  186. /package/dist/features/blocks/server/{linesFromMatchToContentAndPropsString.d.ts → markdown/linesFromMatchToContentAndPropsString.d.ts} +0 -0
  187. /package/dist/features/blocks/server/{linesFromMatchToContentAndPropsString.js → markdown/linesFromMatchToContentAndPropsString.js} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"RelationshipComponent.js","names":["useLexicalComposerContext","getTranslation","Button","useConfig","usePayloadAPI","useTranslation","$getNodeByKey","React","useCallback","useReducer","useRef","useState","useEditorConfigContext","useLexicalDocumentDrawer","INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND","baseClass","initialParams","depth","Component","props","data","relationTo","value","nodeKey","Error","relationshipElemRef","editor","fieldProps","readOnly","config","routes","api","serverURL","getEntityConfig","relatedCollection","collectionSlug","i18n","t","cacheBust","dispatchCacheBust","state","setParams","slug","closeDocumentDrawer","DocumentDrawer","DocumentDrawerToggler","id","removeRelationship","update","remove","updateRelationship","_jsxs","className","contentEditable","ref","_jsx","label","labels","singular","admin","useAsTitle","isEditable","buttonStyle","disabled","el","icon","onClick","dispatchCommand","replace","round","tooltip","e","preventDefault","onSave","RelationshipComponent"],"sources":["../../../../../src/features/relationship/client/components/RelationshipComponent.tsx"],"sourcesContent":["'use client'\nimport type { ElementFormatType } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\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 { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport { useLexicalDocumentDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDocumentDrawer.js'\nimport { INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND } from '../drawer/commands.js'\nimport './index.scss'\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 {\n fieldProps: { readOnly },\n } = useEditorConfigContext()\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 {editor.isEditable() && (\n <div className={`${baseClass}__actions`}>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__swapButton`}\n disabled={readOnly}\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={readOnly}\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"],"mappings":"AAAA;;;AAGA,SAASA,yBAAyB,QAAQ;AAC1C,SAASC,cAAc,QAAQ;AAC/B,SAAS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MAAA,CAAOmC,UAAU,mBAChBV,KAAA,CAAC;MAAIC,SAAA,EAAW,GAAGrC,SAAA,WAAoB;8BACrCwC,IAAA,CAACrD,MAAA;QACC4D,WAAA,EAAY;QACZV,SAAA,EAAW,GAAGrC,SAAA,cAAuB;QACrCgD,QAAA,EAAUnC,QAAA;QACVoC,EAAA,EAAG;QACHC,IAAA,EAAK;QACLC,OAAA,EAASA,CAAA;UACP,IAAI3C,OAAA,EAAS;YACXG,MAAA,CAAOyC,eAAe,CAACrD,uCAAA,EAAyC;cAC9DsD,OAAA,EAAS;gBAAE7C;cAAQ;YACrB;UACF;QACF;QACA8C,KAAK;QACLC,OAAA,EAASjC,CAAA,CAAE;uBAEbkB,IAAA,CAACrD,MAAA;QACC4D,WAAA,EAAY;QACZV,SAAA,EAAW,GAAGrC,SAAA,gBAAyB;QACvCgD,QAAA,EAAUnC,QAAA;QACVqC,IAAA,EAAK;QACLC,OAAA,EAAUK,CAAA;UACRA,CAAA,CAAEC,cAAc;UAChBzB,kBAAA;QACF;QACAsB,KAAK;QACLC,OAAA,EAASjC,CAAA,CAAE;;QAKhB,CAAC,CAACf,KAAA,iBAASiC,IAAA,CAACX,cAAA;MAAe6B,MAAA,EAAQvB;;;AAG1C;AAEA,OAAO,MAAMwB,qBAAA,GAAyBvD,KAAA;EACpC,oBAAOoC,IAAA,CAACrC,SAAA;IAAW,GAAGC;;AACxB","ignoreList":[]}
1
+ {"version":3,"file":"RelationshipComponent.js","names":["useLexicalComposerContext","useLexicalEditable","getTranslation","Button","useConfig","usePayloadAPI","useTranslation","$getNodeByKey","React","useCallback","useReducer","useRef","useState","useLexicalDocumentDrawer","INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND","baseClass","initialParams","depth","RelationshipComponent","props","data","relationTo","value","nodeKey","Error","relationshipElemRef","editor","isEditable","config","routes","api","serverURL","getEntityConfig","relatedCollection","collectionSlug","i18n","t","cacheBust","dispatchCacheBust","state","setParams","slug","closeDocumentDrawer","DocumentDrawer","DocumentDrawerToggler","id","removeRelationship","update","remove","updateRelationship","_jsxs","className","contentEditable","ref","_jsx","label","labels","singular","admin","useAsTitle","buttonStyle","disabled","el","icon","onClick","dispatchCommand","replace","round","tooltip","e","preventDefault","onSave"],"sources":["../../../../../src/features/relationship/client/components/RelationshipComponent.tsx"],"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\nexport const RelationshipComponent: 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"],"mappings":"AAAA;;;AAGA,SAASA,yBAAyB,QAAQ;AAC1C,SAASC,kBAAkB,QAAQ;AACnC,SAASC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SAAA,EAAW,GAAGpC,SAAA,WAAoB;8BACrCuC,IAAA,CAACnD,MAAA;QACCyD,WAAA,EAAY;QACZT,SAAA,EAAW,GAAGpC,SAAA,cAAuB;QACrC8C,QAAA,EAAU,CAAClC,UAAA;QACXmC,EAAA,EAAG;QACHC,IAAA,EAAK;QACLC,OAAA,EAASA,CAAA;UACP,IAAIzC,OAAA,EAAS;YACXG,MAAA,CAAOuC,eAAe,CAACnD,uCAAA,EAAyC;cAC9DoD,OAAA,EAAS;gBAAE3C;cAAQ;YACrB;UACF;QACF;QACA4C,KAAK;QACLC,OAAA,EAAShC,CAAA,CAAE;uBAEbkB,IAAA,CAACnD,MAAA;QACCyD,WAAA,EAAY;QACZT,SAAA,EAAW,GAAGpC,SAAA,gBAAyB;QACvC8C,QAAA,EAAU,CAAClC,UAAA;QACXoC,IAAA,EAAK;QACLC,OAAA,EAAUK,CAAA;UACRA,CAAA,CAAEC,cAAc;UAChBxB,kBAAA;QACF;QACAqB,KAAK;QACLC,OAAA,EAAShC,CAAA,CAAE;;QAKhB,CAAC,CAACd,KAAA,iBAASgC,IAAA,CAACX,cAAA;MAAe4B,MAAA,EAAQtB;;;AAG1C","ignoreList":[]}
@@ -1,7 +1,8 @@
1
+ import type { CollectionSlug } from 'payload';
1
2
  import React from 'react';
2
3
  type Props = {
3
- enabledCollectionSlugs: null | string[];
4
+ enabledCollectionSlugs: CollectionSlug[];
4
5
  };
5
- export declare const RelationshipDrawer: (props: Props) => React.ReactNode;
6
+ export declare const RelationshipDrawer: ({ enabledCollectionSlugs }: Props) => React.ReactNode;
6
7
  export {};
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/relationship/client/drawer/index.tsx"],"names":[],"mappings":"AAMA,OAAO,KAA2C,MAAM,OAAO,CAAA;AAkC/D,KAAK,KAAK,GAAG;IACX,sBAAsB,EAAE,IAAI,GAAG,MAAM,EAAE,CAAA;CACxC,CAAA;AA4CD,eAAO,MAAM,kBAAkB,UAAW,KAAK,KAAG,KAAK,CAAC,SAQvD,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/relationship/client/drawer/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAK7C,OAAO,KAA2C,MAAM,OAAO,CAAA;AAiC/D,KAAK,KAAK,GAAG;IACX,sBAAsB,EAAE,cAAc,EAAE,CAAA;CACzC,CAAA;AA6DD,eAAO,MAAM,kBAAkB,+BAAgC,KAAK,KAAG,KAAK,CAAC,SAM5E,CAAA"}
@@ -3,12 +3,12 @@
3
3
  import { c as _c } from "react/compiler-runtime";
4
4
  import { jsx as _jsx } from "react/jsx-runtime";
5
5
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js';
6
+ import { toast } from '@payloadcms/ui';
6
7
  import { $getNodeByKey, COMMAND_PRIORITY_EDITOR } from 'lexical';
7
8
  import React, { useCallback, useEffect, useState } from 'react';
8
9
  import { useLexicalListDrawer } from '../../../../utilities/fieldsDrawer/useLexicalListDrawer.js';
9
10
  import { $createRelationshipNode } from '../nodes/RelationshipNode.js';
10
11
  import { INSERT_RELATIONSHIP_COMMAND } from '../plugins/index.js';
11
- import { EnabledRelationshipsCondition } from '../utils/EnabledRelationshipsCondition.js';
12
12
  import { INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND } from './commands.js';
13
13
  const insertRelationship = ({
14
14
  editor,
@@ -34,64 +34,55 @@ const insertRelationship = ({
34
34
  }
35
35
  };
36
36
  const RelationshipDrawerComponent = t0 => {
37
- const $ = _c(16);
37
+ const $ = _c(14);
38
38
  const {
39
39
  enabledCollectionSlugs
40
40
  } = t0;
41
41
  const [editor] = useLexicalComposerContext();
42
- let t1;
43
- if ($[0] !== enabledCollectionSlugs?.[0]) {
44
- t1 = () => enabledCollectionSlugs?.[0];
45
- $[0] = enabledCollectionSlugs?.[0];
46
- $[1] = t1;
47
- } else {
48
- t1 = $[1];
49
- }
50
- const [selectedCollectionSlug] = useState(t1);
51
42
  const [replaceNodeKey, setReplaceNodeKey] = useState(null);
52
- const t2 = enabledCollectionSlugs ? enabledCollectionSlugs : undefined;
53
- let t3;
54
- if ($[2] !== selectedCollectionSlug || $[3] !== t2) {
55
- t3 = {
56
- collectionSlugs: t2,
57
- selectedCollection: selectedCollectionSlug
43
+ const t1 = enabledCollectionSlugs?.[0];
44
+ let t2;
45
+ if ($[0] !== enabledCollectionSlugs || $[1] !== t1) {
46
+ t2 = {
47
+ collectionSlugs: enabledCollectionSlugs,
48
+ selectedCollection: t1
58
49
  };
59
- $[2] = selectedCollectionSlug;
60
- $[3] = t2;
61
- $[4] = t3;
50
+ $[0] = enabledCollectionSlugs;
51
+ $[1] = t1;
52
+ $[2] = t2;
62
53
  } else {
63
- t3 = $[4];
54
+ t2 = $[2];
64
55
  }
65
56
  const {
66
57
  closeListDrawer,
67
58
  ListDrawer,
68
59
  openListDrawer
69
- } = useLexicalListDrawer(t3);
60
+ } = useLexicalListDrawer(t2);
61
+ let t3;
70
62
  let t4;
71
- let t5;
72
- if ($[5] !== editor || $[6] !== openListDrawer) {
73
- t4 = () => editor.registerCommand(INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND, payload => {
63
+ if ($[3] !== editor || $[4] !== openListDrawer) {
64
+ t3 = () => editor.registerCommand(INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND, payload => {
74
65
  setReplaceNodeKey(payload?.replace ? payload?.replace.nodeKey : null);
75
66
  openListDrawer();
76
67
  return true;
77
68
  }, COMMAND_PRIORITY_EDITOR);
78
- t5 = [editor, openListDrawer];
79
- $[5] = editor;
80
- $[6] = openListDrawer;
81
- $[7] = t4;
82
- $[8] = t5;
69
+ t4 = [editor, openListDrawer];
70
+ $[3] = editor;
71
+ $[4] = openListDrawer;
72
+ $[5] = t3;
73
+ $[6] = t4;
83
74
  } else {
84
- t4 = $[7];
85
- t5 = $[8];
75
+ t3 = $[5];
76
+ t4 = $[6];
86
77
  }
87
- useEffect(t4, t5);
88
- let t6;
89
- if ($[9] !== closeListDrawer || $[10] !== editor || $[11] !== replaceNodeKey) {
90
- t6 = t7 => {
78
+ useEffect(t3, t4);
79
+ let t5;
80
+ if ($[7] !== closeListDrawer || $[8] !== editor || $[9] !== replaceNodeKey) {
81
+ t5 = t6 => {
91
82
  const {
92
83
  collectionSlug,
93
84
  doc
94
- } = t7;
85
+ } = t6;
95
86
  insertRelationship({
96
87
  editor,
97
88
  relationTo: collectionSlug,
@@ -100,35 +91,57 @@ const RelationshipDrawerComponent = t0 => {
100
91
  });
101
92
  closeListDrawer();
102
93
  };
103
- $[9] = closeListDrawer;
104
- $[10] = editor;
105
- $[11] = replaceNodeKey;
106
- $[12] = t6;
94
+ $[7] = closeListDrawer;
95
+ $[8] = editor;
96
+ $[9] = replaceNodeKey;
97
+ $[10] = t5;
107
98
  } else {
108
- t6 = $[12];
99
+ t5 = $[10];
109
100
  }
110
- const onSelect = t6;
111
- let t7;
112
- if ($[13] !== ListDrawer || $[14] !== onSelect) {
113
- t7 = _jsx(ListDrawer, {
101
+ const onSelect = t5;
102
+ let t6;
103
+ if ($[11] !== ListDrawer || $[12] !== onSelect) {
104
+ t6 = _jsx(ListDrawer, {
114
105
  onSelect
115
106
  });
116
- $[13] = ListDrawer;
117
- $[14] = onSelect;
118
- $[15] = t7;
107
+ $[11] = ListDrawer;
108
+ $[12] = onSelect;
109
+ $[13] = t6;
119
110
  } else {
120
- t7 = $[15];
111
+ t6 = $[13];
121
112
  }
122
- return t7;
113
+ return t6;
123
114
  };
124
- export const RelationshipDrawer = props => {
125
- return (props?.enabledCollectionSlugs?.length ?? -1) > 0 ? /*#__PURE__*/_jsx(RelationshipDrawerComponent, {
126
- ...props
127
- }) : /*#__PURE__*/_jsx(EnabledRelationshipsCondition, {
128
- ...props,
129
- children: /*#__PURE__*/_jsx(RelationshipDrawerComponent, {
130
- ...props
131
- })
115
+ const RelationshipDrawerComponentFallback = () => {
116
+ const $ = _c(3);
117
+ const [editor] = useLexicalComposerContext();
118
+ let t0;
119
+ let t1;
120
+ if ($[0] !== editor) {
121
+ t0 = () => editor.registerCommand(INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND, _temp, COMMAND_PRIORITY_EDITOR);
122
+ t1 = [editor];
123
+ $[0] = editor;
124
+ $[1] = t0;
125
+ $[2] = t1;
126
+ } else {
127
+ t0 = $[1];
128
+ t1 = $[2];
129
+ }
130
+ useEffect(t0, t1);
131
+ return null;
132
+ };
133
+ export const RelationshipDrawer = ({
134
+ enabledCollectionSlugs
135
+ }) => {
136
+ if (!enabledCollectionSlugs?.length) {
137
+ return /*#__PURE__*/_jsx(RelationshipDrawerComponentFallback, {});
138
+ }
139
+ return /*#__PURE__*/_jsx(RelationshipDrawerComponent, {
140
+ enabledCollectionSlugs: enabledCollectionSlugs
132
141
  });
133
142
  };
143
+ function _temp() {
144
+ toast.error("No relationship collections enabled");
145
+ return true;
146
+ }
134
147
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","$getNodeByKey","COMMAND_PRIORITY_EDITOR","React","useCallback","useEffect","useState","useLexicalListDrawer","$createRelationshipNode","INSERT_RELATIONSHIP_COMMAND","EnabledRelationshipsCondition","INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND","insertRelationship","editor","relationTo","replaceNodeKey","value","dispatchCommand","update","node","replace","RelationshipDrawerComponent","t0","$","enabledCollectionSlugs","t1","selectedCollectionSlug","setReplaceNodeKey","t2","undefined","t3","collectionSlugs","selectedCollection","closeListDrawer","ListDrawer","openListDrawer","t4","t5","registerCommand","payload","nodeKey","t6","t7","collectionSlug","doc","id","onSelect","_jsx","RelationshipDrawer","props","length"],"sources":["../../../../../src/features/relationship/client/drawer/index.tsx"],"sourcesContent":["'use client'\nimport type { ListDrawerProps } from '@payloadcms/ui'\nimport type { LexicalEditor } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { $getNodeByKey, COMMAND_PRIORITY_EDITOR } from 'lexical'\nimport React, { useCallback, useEffect, useState } from 'react'\n\nimport { useLexicalListDrawer } from '../../../../utilities/fieldsDrawer/useLexicalListDrawer.js'\nimport { $createRelationshipNode } from '../nodes/RelationshipNode.js'\nimport { INSERT_RELATIONSHIP_COMMAND } from '../plugins/index.js'\nimport { EnabledRelationshipsCondition } from '../utils/EnabledRelationshipsCondition.js'\nimport { INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND } from './commands.js'\n\nconst insertRelationship = ({\n editor,\n relationTo,\n replaceNodeKey,\n value,\n}: {\n editor: LexicalEditor\n relationTo: string\n replaceNodeKey: null | string\n value: number | string\n}) => {\n if (!replaceNodeKey) {\n editor.dispatchCommand(INSERT_RELATIONSHIP_COMMAND, {\n relationTo,\n value,\n })\n } else {\n editor.update(() => {\n const node = $getNodeByKey(replaceNodeKey)\n if (node) {\n node.replace($createRelationshipNode({ relationTo, value }))\n }\n })\n }\n}\n\ntype Props = {\n enabledCollectionSlugs: null | string[]\n}\n\nconst RelationshipDrawerComponent: React.FC<Props> = ({ enabledCollectionSlugs }) => {\n const [editor] = useLexicalComposerContext()\n const [selectedCollectionSlug, setSelectedCollectionSlug] = useState(\n () => enabledCollectionSlugs?.[0],\n )\n const [replaceNodeKey, setReplaceNodeKey] = useState<null | string>(null)\n\n const { closeListDrawer, isListDrawerOpen, ListDrawer, openListDrawer } = useLexicalListDrawer({\n collectionSlugs: enabledCollectionSlugs ? enabledCollectionSlugs : undefined,\n selectedCollection: selectedCollectionSlug,\n })\n\n useEffect(() => {\n return editor.registerCommand<{\n replace: { nodeKey: string } | false\n }>(\n INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND,\n (payload) => {\n setReplaceNodeKey(payload?.replace ? payload?.replace.nodeKey : null)\n openListDrawer()\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n )\n }, [editor, openListDrawer])\n\n const onSelect = useCallback<NonNullable<ListDrawerProps['onSelect']>>(\n ({ collectionSlug, doc }) => {\n insertRelationship({\n editor,\n relationTo: collectionSlug,\n replaceNodeKey,\n value: doc.id,\n })\n closeListDrawer()\n },\n [editor, closeListDrawer, replaceNodeKey],\n )\n\n return <ListDrawer onSelect={onSelect} />\n}\n\nexport const RelationshipDrawer = (props: Props): React.ReactNode => {\n return (props?.enabledCollectionSlugs?.length ?? -1) > 0 ? ( // If enabledCollectionSlugs it overrides what EnabledRelationshipsCondition is doing\n <RelationshipDrawerComponent {...props} />\n ) : (\n <EnabledRelationshipsCondition {...props}>\n <RelationshipDrawerComponent {...props} />\n </EnabledRelationshipsCondition>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAIA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,aAAa,EAAEC,uBAAuB,QAAQ;AACvD,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ;AAExD,SAASC,oBAAoB,QAAQ;AACrC,SAASC,uBAAuB,QAAQ;AACxC,SAASC,2BAA2B,QAAQ;AAC5C,SAASC,6BAA6B,QAAQ;AAC9C,SAASC,uCAAuC,QAAQ;AAExD,MAAMC,kBAAA,GAAqBA,CAAC;EAC1BC,MAAM;EACNC,UAAU;EACVC,cAAc;EACdC;AAAK,CAMN;EACC,IAAI,CAACD,cAAA,EAAgB;IACnBF,MAAA,CAAOI,eAAe,CAACR,2BAAA,EAA6B;MAClDK,UAAA;MACAE;IACF;EACF,OAAO;IACLH,MAAA,CAAOK,MAAM,CAAC;MACZ,MAAMC,IAAA,GAAOlB,aAAA,CAAcc,cAAA;MAC3B,IAAII,IAAA,EAAM;QACRA,IAAA,CAAKC,OAAO,CAACZ,uBAAA,CAAwB;UAAEM,UAAA;UAAYE;QAAM;MAC3D;IACF;EACF;AACF;AAMA,MAAMK,2BAAA,GAA+CC,EAAA;EAAA,MAAAC,CAAA,GAAAxB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EAAA;IAAAb,CAAA,MAAAc,EAAA;EAAA;IAAAD,EAAA,GAAAb,CAAA;IAAAc,EAAA,GAAAd,CAAA;EAAA;EAZ3BlB,SAAA,CAAU+B,EAYV,EAAGC,EAAwB;EAAA,IAAAI,EAAA;EAAA,IAAAlB,CAAA,QAAAU,eAAA,IAAAV,CAAA,SAAAV,MAAA,IAAAU,CAAA,SAAAR,cAAA;IAGzB0B,EAAA,GAAAC,EAAA;MAAC;QAAAC,cAAA;QAAAC;MAAA,IAAAF,EAAuB;MACtB9B,kBAAA;QAAAC,MAAA;QAAAC,UAAA,EAEc6B,cAAA;QAAA5B,cAAA;QAAAC,KAAA,EAEL4B,GAAA,CAAAC;MAAA,CACT;MACAZ,eAAA;IAAA;IACFV,CAAA,MAAAU,eAAA;IAAAV,CAAA,OAAAV,MAAA;IAAAU,CAAA,OAAAR,cAAA;IAAAQ,CAAA,OAAAkB,EAAA;EAAA;IAAAA,EAAA,GAAAlB,CAAA;EAAA;EATF,MAAAuB,QAAA,GAAiBL,EAU0B;EAAA,IAAAC,EAAA;EAAA,IAAAnB,CAAA,SAAAW,UAAA,IAAAX,CAAA,SAAAuB,QAAA;IAGpCJ,EAAA,GAAAK,IAAA,CAACb,UAAA;MAAAY;IAAA,C;;;;;;;SAADJ,E;CACT;AAEA,OAAO,MAAMM,kBAAA,GAAsBC,KAAA;EACjC,OAAO,CAACA,KAAA,EAAOzB,sBAAA,EAAwB0B,MAAA,IAAU,CAAC,KAAK,iBACrDH,IAAA,CAAC1B,2BAAA;IAA6B,GAAG4B;oBAEjCF,IAAA,CAACrC,6BAAA;IAA+B,GAAGuC,KAAK;cACtC,aAAAF,IAAA,CAAC1B,2BAAA;MAA6B,GAAG4B;;;AAGvC","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","toast","$getNodeByKey","COMMAND_PRIORITY_EDITOR","React","useCallback","useEffect","useState","useLexicalListDrawer","$createRelationshipNode","INSERT_RELATIONSHIP_COMMAND","INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND","insertRelationship","editor","relationTo","replaceNodeKey","value","dispatchCommand","update","node","replace","RelationshipDrawerComponent","t0","$","enabledCollectionSlugs","setReplaceNodeKey","t1","t2","collectionSlugs","selectedCollection","closeListDrawer","ListDrawer","openListDrawer","t3","t4","registerCommand","payload","nodeKey","t5","t6","collectionSlug","doc","id","onSelect","_jsx","RelationshipDrawerComponentFallback","_temp","RelationshipDrawer","length","error"],"sources":["../../../../../src/features/relationship/client/drawer/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalEditor } from 'lexical'\nimport type { CollectionSlug } from 'payload'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { type ListDrawerProps, toast } from '@payloadcms/ui'\nimport { $getNodeByKey, COMMAND_PRIORITY_EDITOR } from 'lexical'\nimport React, { useCallback, useEffect, useState } from 'react'\n\nimport { useLexicalListDrawer } from '../../../../utilities/fieldsDrawer/useLexicalListDrawer.js'\nimport { $createRelationshipNode } from '../nodes/RelationshipNode.js'\nimport { INSERT_RELATIONSHIP_COMMAND } from '../plugins/index.js'\nimport { INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND } from './commands.js'\n\nconst insertRelationship = ({\n editor,\n relationTo,\n replaceNodeKey,\n value,\n}: {\n editor: LexicalEditor\n relationTo: string\n replaceNodeKey: null | string\n value: number | string\n}) => {\n if (!replaceNodeKey) {\n editor.dispatchCommand(INSERT_RELATIONSHIP_COMMAND, {\n relationTo,\n value,\n })\n } else {\n editor.update(() => {\n const node = $getNodeByKey(replaceNodeKey)\n if (node) {\n node.replace($createRelationshipNode({ relationTo, value }))\n }\n })\n }\n}\n\ntype Props = {\n enabledCollectionSlugs: CollectionSlug[]\n}\n\nconst RelationshipDrawerComponent: React.FC<Props> = ({ enabledCollectionSlugs }) => {\n const [editor] = useLexicalComposerContext()\n\n const [replaceNodeKey, setReplaceNodeKey] = useState<null | string>(null)\n\n const { closeListDrawer, ListDrawer, openListDrawer } = useLexicalListDrawer({\n collectionSlugs: enabledCollectionSlugs,\n selectedCollection: enabledCollectionSlugs?.[0],\n })\n\n useEffect(() => {\n return editor.registerCommand<{\n replace: { nodeKey: string } | false\n }>(\n INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND,\n (payload) => {\n setReplaceNodeKey(payload?.replace ? payload?.replace.nodeKey : null)\n openListDrawer()\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n )\n }, [editor, openListDrawer])\n\n const onSelect = useCallback<NonNullable<ListDrawerProps['onSelect']>>(\n ({ collectionSlug, doc }) => {\n insertRelationship({\n editor,\n relationTo: collectionSlug,\n replaceNodeKey,\n value: doc.id,\n })\n closeListDrawer()\n },\n [editor, closeListDrawer, replaceNodeKey],\n )\n\n return <ListDrawer onSelect={onSelect} />\n}\n\nconst RelationshipDrawerComponentFallback: React.FC = () => {\n const [editor] = useLexicalComposerContext()\n\n useEffect(() => {\n return editor.registerCommand<{\n replace: { nodeKey: string } | false\n }>(\n INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND,\n () => {\n toast.error('No relationship collections enabled')\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n )\n }, [editor])\n\n return null\n}\n\nexport const RelationshipDrawer = ({ enabledCollectionSlugs }: Props): React.ReactNode => {\n if (!enabledCollectionSlugs?.length) {\n return <RelationshipDrawerComponentFallback />\n }\n\n return <RelationshipDrawerComponent enabledCollectionSlugs={enabledCollectionSlugs} />\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAIA,SAASC,yBAAyB,QAAQ;AAC1C,SAA+BC,KAAK,QAAQ;AAC5C,SAASC,aAAa,EAAEC,uBAAuB,QAAQ;AACvD,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ;AAExD,SAASC,oBAAoB,QAAQ;AACrC,SAASC,uBAAuB,QAAQ;AACxC,SAASC,2BAA2B,QAAQ;AAC5C,SAASC,uCAAuC,QAAQ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AAAmC,KAAA,EAAA3C,uBAQL;IAEDuB,EAAA,IAACb,MAAA;IAAOU,CAAA,MAAAV,MAAA;IAAAU,CAAA,MAAAD,EAAA;IAAAC,CAAA,MAAAG,EAAA;EAAA;IAAAJ,EAAA,GAAAC,CAAA;IAAAG,EAAA,GAAAH,CAAA;EAAA;EAXXjB,SAAA,CAAUgB,EAWV,EAAGI,EAAQ;EAAA;AAAA,CAGb;AAEA,OAAO,MAAMqB,kBAAA,GAAqBA,CAAC;EAAEvB;AAAsB,CAAS;EAClE,IAAI,CAACA,sBAAA,EAAwBwB,MAAA,EAAQ;IACnC,oBAAOJ,IAAA,CAACC,mCAAA;EACV;EAEA,oBAAOD,IAAA,CAACvB,2BAAA;IAA4BG,sBAAA,EAAwBA;;AAC9D;AAzBsD,SAAAsB,MAAA;EAS9C7C,KAAA,CAAAgD,KAAA,CAAY;EAAA;AAAA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/relationship/client/plugins/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAe7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAA;AAK9E,eAAO,MAAM,2BAA2B,EAAE,cAAc,CAAC,gBAAgB,CAExE,CAAA;AAED,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAAC,wBAAwB,CA+CxE,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/relationship/client/plugins/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAc7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAA;AAM9E,eAAO,MAAM,2BAA2B,EAAE,cAAc,CAAC,gBAAgB,CAExE,CAAA;AAED,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAAC,wBAAwB,CAuCxE,CAAA"}
@@ -4,74 +4,66 @@ import { c as _c } from "react/compiler-runtime";
4
4
  import { jsx as _jsx } from "react/jsx-runtime";
5
5
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js';
6
6
  import { $insertNodeToNearestRoot } from '@lexical/utils';
7
- import { useConfig } from '@payloadcms/ui';
8
7
  import { $getPreviousSelection, $getSelection, $isParagraphNode, $isRangeSelection, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
9
8
  import { useEffect } from 'react';
10
9
  import { RelationshipDrawer } from '../drawer/index.js';
11
10
  import { $createRelationshipNode, RelationshipNode } from '../nodes/RelationshipNode.js';
11
+ import { useEnabledRelationships } from '../utils/useEnabledRelationships.js';
12
12
  export const INSERT_RELATIONSHIP_COMMAND = createCommand('INSERT_RELATIONSHIP_COMMAND');
13
13
  export const RelationshipPlugin = t0 => {
14
- const $ = _c(5);
14
+ const $ = _c(8);
15
15
  const {
16
16
  clientProps
17
17
  } = t0;
18
18
  const [editor] = useLexicalComposerContext();
19
- const {
20
- config: t1
21
- } = useConfig();
22
- const {
23
- collections
24
- } = t1;
25
- let enabledRelations = null;
26
- if (clientProps?.enabledCollections) {
27
- enabledRelations = clientProps?.enabledCollections;
19
+ const t1 = clientProps?.disabledCollections;
20
+ const t2 = clientProps?.enabledCollections;
21
+ let t3;
22
+ if ($[0] !== t1 || $[1] !== t2) {
23
+ t3 = {
24
+ collectionSlugsBlacklist: t1,
25
+ collectionSlugsWhitelist: t2
26
+ };
27
+ $[0] = t1;
28
+ $[1] = t2;
29
+ $[2] = t3;
28
30
  } else {
29
- if (clientProps?.disabledCollections) {
30
- let t2;
31
- if ($[0] !== clientProps?.disabledCollections) {
32
- t2 = t3 => {
33
- const {
34
- slug
35
- } = t3;
36
- return !clientProps?.disabledCollections?.includes(slug);
37
- };
38
- $[0] = clientProps?.disabledCollections;
39
- $[1] = t2;
40
- } else {
41
- t2 = $[1];
42
- }
43
- enabledRelations = collections.filter(t2).map(_temp);
44
- }
31
+ t3 = $[2];
45
32
  }
46
- let t2;
47
- let t3;
48
- if ($[2] !== editor) {
49
- t2 = () => {
33
+ const {
34
+ enabledCollectionSlugs
35
+ } = useEnabledRelationships(t3);
36
+ let t4;
37
+ let t5;
38
+ if ($[3] !== editor) {
39
+ t4 = () => {
50
40
  if (!editor.hasNodes([RelationshipNode])) {
51
41
  throw new Error("RelationshipPlugin: RelationshipNode not registered on editor");
52
42
  }
53
- return editor.registerCommand(INSERT_RELATIONSHIP_COMMAND, _temp2, COMMAND_PRIORITY_EDITOR);
43
+ return editor.registerCommand(INSERT_RELATIONSHIP_COMMAND, _temp, COMMAND_PRIORITY_EDITOR);
54
44
  };
55
- t3 = [editor];
56
- $[2] = editor;
57
- $[3] = t2;
58
- $[4] = t3;
45
+ t5 = [editor];
46
+ $[3] = editor;
47
+ $[4] = t4;
48
+ $[5] = t5;
49
+ } else {
50
+ t4 = $[4];
51
+ t5 = $[5];
52
+ }
53
+ useEffect(t4, t5);
54
+ let t6;
55
+ if ($[6] !== enabledCollectionSlugs) {
56
+ t6 = _jsx(RelationshipDrawer, {
57
+ enabledCollectionSlugs
58
+ });
59
+ $[6] = enabledCollectionSlugs;
60
+ $[7] = t6;
59
61
  } else {
60
- t2 = $[3];
61
- t3 = $[4];
62
+ t6 = $[7];
62
63
  }
63
- useEffect(t2, t3);
64
- return _jsx(RelationshipDrawer, {
65
- enabledCollectionSlugs: enabledRelations
66
- });
64
+ return t6;
67
65
  };
68
- function _temp(t0) {
69
- const {
70
- slug: slug_0
71
- } = t0;
72
- return slug_0;
73
- }
74
- function _temp2(payload) {
66
+ function _temp(payload) {
75
67
  const selection = $getSelection() || $getPreviousSelection();
76
68
  if ($isRangeSelection(selection)) {
77
69
  const relationshipNode = $createRelationshipNode(payload);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","$insertNodeToNearestRoot","useConfig","$getPreviousSelection","$getSelection","$isParagraphNode","$isRangeSelection","COMMAND_PRIORITY_EDITOR","createCommand","useEffect","RelationshipDrawer","$createRelationshipNode","RelationshipNode","INSERT_RELATIONSHIP_COMMAND","RelationshipPlugin","t0","$","clientProps","editor","config","t1","collections","enabledRelations","enabledCollections","disabledCollections","t2","t3","slug","includes","filter","map","_temp","hasNodes","Error","registerCommand","_temp2","_jsx","enabledCollectionSlugs","slug_0","payload","selection","relationshipNode","focus","focusNode","getNode","__first","remove"],"sources":["../../../../../src/features/relationship/client/plugins/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalCommand } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { $insertNodeToNearestRoot } from '@lexical/utils'\nimport { useConfig } from '@payloadcms/ui'\nimport {\n $getPreviousSelection,\n $getSelection,\n $isParagraphNode,\n $isRangeSelection,\n COMMAND_PRIORITY_EDITOR,\n createCommand,\n} from 'lexical'\nimport { useEffect } from 'react'\n\nimport type { PluginComponent } from '../../../typesClient.js'\nimport type { RelationshipFeatureProps } from '../../server/index.js'\nimport type { RelationshipData } from '../../server/nodes/RelationshipNode.js'\n\nimport { RelationshipDrawer } from '../drawer/index.js'\nimport { $createRelationshipNode, RelationshipNode } from '../nodes/RelationshipNode.js'\n\nexport const INSERT_RELATIONSHIP_COMMAND: LexicalCommand<RelationshipData> = createCommand(\n 'INSERT_RELATIONSHIP_COMMAND',\n)\n\nexport const RelationshipPlugin: PluginComponent<RelationshipFeatureProps> = ({ clientProps }) => {\n const [editor] = useLexicalComposerContext()\n const {\n config: { collections },\n } = useConfig()\n\n let enabledRelations: null | string[] = null\n\n if (clientProps?.enabledCollections) {\n enabledRelations = clientProps?.enabledCollections\n } else if (clientProps?.disabledCollections) {\n enabledRelations = collections\n .filter(({ slug }) => !clientProps?.disabledCollections?.includes(slug))\n .map(({ slug }) => slug)\n }\n\n useEffect(() => {\n if (!editor.hasNodes([RelationshipNode])) {\n throw new Error('RelationshipPlugin: RelationshipNode not registered on editor')\n }\n\n return editor.registerCommand<RelationshipData>(\n INSERT_RELATIONSHIP_COMMAND,\n (payload) => {\n const selection = $getSelection() || $getPreviousSelection()\n\n if ($isRangeSelection(selection)) {\n const relationshipNode = $createRelationshipNode(payload)\n // we need to get the focus node before inserting the block node, as $insertNodeToNearestRoot can change the focus node\n const { focus } = selection\n const focusNode = focus.getNode()\n // Insert relationship node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(relationshipNode)\n\n // Delete the node it it's an empty paragraph\n if ($isParagraphNode(focusNode) && !focusNode.__first) {\n focusNode.remove()\n }\n }\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n )\n }, [editor])\n\n return <RelationshipDrawer enabledCollectionSlugs={enabledRelations} />\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAGA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,wBAAwB,QAAQ;AACzC,SAASC,SAAS,QAAQ;AAC1B,SACEC,qBAAqB,EACrBC,aAAa,EACbC,gBAAgB,EAChBC,iBAAiB,EACjBC,uBAAuB,EACvBC,aAAa,QACR;AACP,SAASC,SAAS,QAAQ;AAM1B,SAASC,kBAAkB,QAAQ;AACnC,SAASC,uBAAuB,EAAEC,gBAAgB,QAAQ;AAE1D,OAAO,MAAMC,2BAAA,GAAgEL,aAAA,CAC3E;AAGF,OAAO,MAAMM,kBAAA,GAAgEC,EAAA;EAAA,MAAAC,CAAA,GAAAjB,EAAA;EAAC;IAAAkB;EAAA,IAAAF,EAAe;EAC3F,OAAAG,MAAA,IAAiBlB,yBAAA;EACjB;IAAAmB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IAAA,EAAAW;EAAA,IAAAvB,EAAQ;EAAA,OAAKY,MAAA;AAAA;AAboD,SAAAQ,OAAAI,OAAA;EAwBrE,MAAAC,SAAA,GAAkBpC,aAAA,MAAmBD,qBAAA;EAAA,IAEjCG,iBAAA,CAAkBkC,SAAA;IACpB,MAAAC,gBAAA,GAAyB9B,uBAAA,CAAwB4B,OAAA;IAEjD;MAAAG;IAAA,IAAkBF,SAAA;IAClB,MAAAG,SAAA,GAAkBD,KAAA,CAAAE,OAAA,CAAa;IAE/B3C,wBAAA,CAAyBwC,gBAAA;IAAA,IAGrBpC,gBAAA,CAAiBsC,SAAA,MAAeA,SAAA,CAAAE,OAAiB;MACnDF,SAAA,CAAAG,MAAA,CAAgB;IAAA;EAAA;EAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","$insertNodeToNearestRoot","$getPreviousSelection","$getSelection","$isParagraphNode","$isRangeSelection","COMMAND_PRIORITY_EDITOR","createCommand","useEffect","RelationshipDrawer","$createRelationshipNode","RelationshipNode","useEnabledRelationships","INSERT_RELATIONSHIP_COMMAND","RelationshipPlugin","t0","$","clientProps","editor","t1","disabledCollections","t2","enabledCollections","t3","collectionSlugsBlacklist","collectionSlugsWhitelist","enabledCollectionSlugs","t4","t5","hasNodes","Error","registerCommand","_temp","t6","_jsx","payload","selection","relationshipNode","focus","focusNode","getNode","__first","remove"],"sources":["../../../../../src/features/relationship/client/plugins/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalCommand } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { $insertNodeToNearestRoot } from '@lexical/utils'\nimport {\n $getPreviousSelection,\n $getSelection,\n $isParagraphNode,\n $isRangeSelection,\n COMMAND_PRIORITY_EDITOR,\n createCommand,\n} from 'lexical'\nimport { useEffect } from 'react'\n\nimport type { PluginComponent } from '../../../typesClient.js'\nimport type { RelationshipFeatureProps } from '../../server/index.js'\nimport type { RelationshipData } from '../../server/nodes/RelationshipNode.js'\n\nimport { RelationshipDrawer } from '../drawer/index.js'\nimport { $createRelationshipNode, RelationshipNode } from '../nodes/RelationshipNode.js'\nimport { useEnabledRelationships } from '../utils/useEnabledRelationships.js'\n\nexport const INSERT_RELATIONSHIP_COMMAND: LexicalCommand<RelationshipData> = createCommand(\n 'INSERT_RELATIONSHIP_COMMAND',\n)\n\nexport const RelationshipPlugin: PluginComponent<RelationshipFeatureProps> = ({ clientProps }) => {\n const [editor] = useLexicalComposerContext()\n\n const { enabledCollectionSlugs } = useEnabledRelationships({\n collectionSlugsBlacklist: clientProps?.disabledCollections,\n collectionSlugsWhitelist: clientProps?.enabledCollections,\n })\n\n useEffect(() => {\n if (!editor.hasNodes([RelationshipNode])) {\n throw new Error('RelationshipPlugin: RelationshipNode not registered on editor')\n }\n\n return editor.registerCommand<RelationshipData>(\n INSERT_RELATIONSHIP_COMMAND,\n (payload) => {\n const selection = $getSelection() || $getPreviousSelection()\n\n if ($isRangeSelection(selection)) {\n const relationshipNode = $createRelationshipNode(payload)\n // we need to get the focus node before inserting the block node, as $insertNodeToNearestRoot can change the focus node\n const { focus } = selection\n const focusNode = focus.getNode()\n // Insert relationship node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(relationshipNode)\n\n // Delete the node it it's an empty paragraph\n if ($isParagraphNode(focusNode) && !focusNode.__first) {\n focusNode.remove()\n }\n }\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n )\n }, [editor])\n\n return <RelationshipDrawer enabledCollectionSlugs={enabledCollectionSlugs} />\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAGA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,wBAAwB,QAAQ;AACzC,SACEC,qBAAqB,EACrBC,aAAa,EACbC,gBAAgB,EAChBC,iBAAiB,EACjBC,uBAAuB,EACvBC,aAAa,QACR;AACP,SAASC,SAAS,Q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jB,CAAA,QAAAU,sBAAA;IAEJO,EAAA,GAAAC,IAAA,CAAAzB,kBAAA;MAAAiB;IAAA,C;;;;;;SAAAO,E;CACT;AAvC6E,SAAAD,MAAAG,OAAA;EAgBrE,MAAAC,SAAA,GAAkBjC,aAAA,MAAmBD,qBAAA;EAAA,IAEjCG,iBAAA,CAAkB+B,SAAA;IACpB,MAAAC,gBAAA,GAAyB3B,uBAAA,CAAwByB,OAAA;IAEjD;MAAAG;IAAA,IAAkBF,SAAA;IAClB,MAAAG,SAAA,GAAkBD,KAAA,CAAAE,OAAA,CAAa;IAE/BvC,wBAAA,CAAyBoC,gBAAA;IAAA,IAGrBjC,gBAAA,CAAiBmC,SAAA,MAAeA,SAAA,CAAAE,OAAiB;MACnDF,SAAA,CAAAG,MAAA,CAAgB;IAAA;EAAA;EAAA;AAAA","ignoreList":[]}
@@ -0,0 +1,13 @@
1
+ import type { ClientCollectionConfig, CollectionSlug } from 'payload';
2
+ type UseEnabledRelationshipsOptions = {
3
+ collectionSlugsBlacklist?: string[];
4
+ collectionSlugsWhitelist?: string[];
5
+ uploads?: boolean;
6
+ };
7
+ type UseEnabledRelationshipsResult = {
8
+ enabledCollections: ClientCollectionConfig[];
9
+ enabledCollectionSlugs: CollectionSlug[];
10
+ };
11
+ export declare const useEnabledRelationships: (options?: UseEnabledRelationshipsOptions) => UseEnabledRelationshipsResult;
12
+ export {};
13
+ //# sourceMappingURL=useEnabledRelationships.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEnabledRelationships.d.ts","sourceRoot":"","sources":["../../../../../src/features/relationship/client/utils/useEnabledRelationships.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAKrE,KAAK,8BAA8B,GAAG;IACpC,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAA;IACnC,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAA;IACnC,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,KAAK,6BAA6B,GAAG;IACnC,kBAAkB,EAAE,sBAAsB,EAAE,CAAA;IAC5C,sBAAsB,EAAE,cAAc,EAAE,CAAA;CACzC,CAAA;AAED,eAAO,MAAM,uBAAuB,aACxB,8BAA8B,KACvC,6BAsDF,CAAA"}
@@ -0,0 +1,64 @@
1
+ 'use client';
2
+
3
+ import { useConfig, useEntityVisibility } from '@payloadcms/ui';
4
+ import * as React from 'react';
5
+ export const useEnabledRelationships = options => {
6
+ const {
7
+ collectionSlugsBlacklist,
8
+ collectionSlugsWhitelist,
9
+ uploads = false
10
+ } = options || {};
11
+ const {
12
+ config: {
13
+ collections
14
+ }
15
+ } = useConfig();
16
+ const {
17
+ visibleEntities
18
+ } = useEntityVisibility();
19
+ const result = React.useMemo(() => {
20
+ const enabledCollectionSlugs = [];
21
+ const enabledCollections = [];
22
+ const whitelistSet = collectionSlugsWhitelist ? new Set(collectionSlugsWhitelist) : null;
23
+ const blacklistSet = collectionSlugsBlacklist ? new Set(collectionSlugsBlacklist) : null;
24
+ for (const collection of collections) {
25
+ const {
26
+ slug,
27
+ admin: {
28
+ enableRichTextRelationship
29
+ },
30
+ upload
31
+ } = collection;
32
+ // Check visibility
33
+ if (!visibleEntities?.collections.includes(slug)) {
34
+ continue;
35
+ }
36
+ // Check rich text relationship and upload settings
37
+ if (uploads) {
38
+ if (!enableRichTextRelationship || !upload) {
39
+ continue;
40
+ }
41
+ } else {
42
+ if (upload || !enableRichTextRelationship) {
43
+ continue;
44
+ }
45
+ }
46
+ // Check whitelist (if provided, only include slugs in the whitelist)
47
+ if (whitelistSet && !whitelistSet.has(slug)) {
48
+ continue;
49
+ }
50
+ // Check blacklist (if provided, exclude slugs in the blacklist)
51
+ if (blacklistSet && blacklistSet.has(slug)) {
52
+ continue;
53
+ }
54
+ enabledCollectionSlugs.push(slug);
55
+ enabledCollections.push(collection);
56
+ }
57
+ return {
58
+ enabledCollections,
59
+ enabledCollectionSlugs
60
+ };
61
+ }, [collections, visibleEntities, uploads, collectionSlugsWhitelist, collectionSlugsBlacklist]);
62
+ return result;
63
+ };
64
+ //# sourceMappingURL=useEnabledRelationships.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEnabledRelationships.js","names":["useConfig","useEntityVisibility","React","useEnabledRelationships","options","collectionSlugsBlacklist","collectionSlugsWhitelist","uploads","config","collections","visibleEntities","result","useMemo","enabledCollectionSlugs","enabledCollections","whitelistSet","Set","blacklistSet","collection","slug","admin","enableRichTextRelationship","upload","includes","has","push"],"sources":["../../../../../src/features/relationship/client/utils/useEnabledRelationships.tsx"],"sourcesContent":["'use client'\nimport type { ClientCollectionConfig, CollectionSlug } from 'payload'\n\nimport { useConfig, useEntityVisibility } from '@payloadcms/ui'\nimport * as React from 'react'\n\ntype UseEnabledRelationshipsOptions = {\n collectionSlugsBlacklist?: string[]\n collectionSlugsWhitelist?: string[]\n uploads?: boolean\n}\n\ntype UseEnabledRelationshipsResult = {\n enabledCollections: ClientCollectionConfig[]\n enabledCollectionSlugs: CollectionSlug[]\n}\n\nexport const useEnabledRelationships = (\n options?: UseEnabledRelationshipsOptions,\n): UseEnabledRelationshipsResult => {\n const { collectionSlugsBlacklist, collectionSlugsWhitelist, uploads = false } = options || {}\n const {\n config: { collections },\n } = useConfig()\n const { visibleEntities } = useEntityVisibility()\n\n const result = React.useMemo(() => {\n const enabledCollectionSlugs: string[] = []\n const enabledCollections: ClientCollectionConfig[] = []\n const whitelistSet = collectionSlugsWhitelist ? new Set(collectionSlugsWhitelist) : null\n const blacklistSet = collectionSlugsBlacklist ? new Set(collectionSlugsBlacklist) : null\n\n for (const collection of collections) {\n const {\n slug,\n admin: { enableRichTextRelationship },\n upload,\n } = collection\n\n // Check visibility\n if (!visibleEntities?.collections.includes(slug)) {\n continue\n }\n\n // Check rich text relationship and upload settings\n if (uploads) {\n if (!enableRichTextRelationship || !upload) {\n continue\n }\n } else {\n if (upload || !enableRichTextRelationship) {\n continue\n }\n }\n\n // Check whitelist (if provided, only include slugs in the whitelist)\n if (whitelistSet && !whitelistSet.has(slug)) {\n continue\n }\n\n // Check blacklist (if provided, exclude slugs in the blacklist)\n if (blacklistSet && blacklistSet.has(slug)) {\n continue\n }\n\n enabledCollectionSlugs.push(slug)\n enabledCollections.push(collection)\n }\n\n return { enabledCollections, enabledCollectionSlugs }\n }, [collections, visibleEntities, uploads, collectionSlugsWhitelist, collectionSlugsBlacklist])\n\n return result\n}\n"],"mappings":"AAAA;;AAGA,SAASA,SAAS,EAAEC,mBAAmB,QAAQ;AAC/C,YAAYC,KAAA,MAAW;AAavB,OAAO,MAAMC,uBAAA,GACXC,OAAA;EAEA,MAAM;IAAEC,wBAAwB;IAAEC,wBAAwB;IAAEC,OAAA,GAAU;EAAK,CAAE,GAAGH,OAAA,IAAW,CAAC;EAC5F,MAAM;IACJI,MAAA,EAAQ;MAAEC;IAAW;EAAE,CACxB,GAAGT,SAAA;EACJ,MAAM;IAAEU;EAAe,CAAE,GAAGT,mBAAA;EAE5B,MAAMU,MAAA,GAAST,KAAA,CAAMU,OAAO,CAAC;IAC3B,MAAMC,sBAAA,GAAmC,EAAE;IAC3C,MAAMC,kBAAA,GAA+C,EAAE;IACvD,MAAMC,YAAA,GAAeT,wBAAA,GAA2B,IAAIU,GAAA,CAAIV,wBAAA,IAA4B;IACpF,MAAMW,YAAA,GAAeZ,wBAAA,GAA2B,IAAIW,GAAA,CAAIX,wBAAA,IAA4B;IAEpF,KAAK,MAAMa,UAAA,IAAcT,WAAA,EAAa;MACpC,MAAM;QACJU,IAAI;QACJC,KAAA,EAAO;UAAEC;QAA0B,CAAE;QACrCC;MAAM,CACP,GAAGJ,UAAA;MAEJ;MACA,IAAI,CAACR,eAAA,EAAiBD,WAAA,CAAYc,QAAA,CAASJ,IAAA,GAAO;QAChD;MACF;MAEA;MACA,IAAIZ,OAAA,EAAS;QACX,IAAI,CAACc,0BAAA,IAA8B,CAACC,MAAA,EAAQ;UAC1C;QACF;MACF,OAAO;QACL,IAAIA,MAAA,IAAU,CAACD,0BAAA,EAA4B;UACzC;QACF;MACF;MAEA;MACA,IAAIN,YAAA,IAAgB,CAACA,YAAA,CAAaS,GAAG,CAACL,IAAA,GAAO;QAC3C;MACF;MAEA;MACA,IAAIF,YAAA,IAAgBA,YAAA,CAAaO,GAAG,CAACL,IAAA,GAAO;QAC1C;MACF;MAEAN,sBAAA,CAAuBY,IAAI,CAACN,IAAA;MAC5BL,kBAAA,CAAmBW,IAAI,CAACP,UAAA;IAC1B;IAEA,OAAO;MAAEJ,kBAAA;MAAoBD;IAAuB;EACtD,GAAG,CAACJ,WAAA,EAAaC,eAAA,EAAiBH,OAAA,EAASD,wBAAA,EAA0BD,wBAAA,CAAyB;EAE9F,OAAOM,MAAA;AACT","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/features/toolbars/fixed/client/Toolbar/index.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAEjE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AAKrE,OAAO,cAAc,CAAA;AAoQrB,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAAC,wBAAwB,CAkCxE,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/features/toolbars/fixed/client/Toolbar/index.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAEjE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AAIrE,OAAO,cAAc,CAAA;AAuQrB,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAAC,wBAAwB,CAsCxE,CAAA"}
@@ -3,6 +3,7 @@
3
3
  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.js';
6
+ import { useLexicalEditable } from '@lexical/react/useLexicalEditable';
6
7
  import { useScrollInfo, useThrottledEffect, useTranslation } from '@payloadcms/ui';
7
8
  import * as React from 'react';
8
9
  import { useMemo } from 'react';
@@ -183,6 +184,7 @@ function FixedToolbar({
183
184
  parentWithFixedToolbar
184
185
  }) {
185
186
  const currentToolbarRef = React.useRef(null);
187
+ const isEditable = useLexicalEditable();
186
188
  const {
187
189
  y
188
190
  } = useScrollInfo();
@@ -237,7 +239,7 @@ function FixedToolbar({
237
239
  event.stopPropagation();
238
240
  },
239
241
  ref: currentToolbarRef,
240
- children: editor.isEditable() && /*#__PURE__*/_jsx(React.Fragment, {
242
+ children: isEditable && /*#__PURE__*/_jsx(React.Fragment, {
241
243
  children: editorConfig?.features && editorConfig.features?.toolbarFixed?.groups.map((group, i) => {
242
244
  return /*#__PURE__*/_jsx(ToolbarGroupComponent, {
243
245
  anchorElem: anchorElem,
@@ -269,6 +271,10 @@ export const FixedToolbarPlugin = t0 => {
269
271
  } = t0;
270
272
  const [currentEditor] = useLexicalComposerContext();
271
273
  const editorConfigContext = useEditorConfigContext();
274
+ const isEditable = useLexicalEditable();
275
+ if (!isEditable) {
276
+ return null;
277
+ }
272
278
  const {
273
279
  editorConfig: currentEditorConfig
274
280
  } = editorConfigContext;