@focus-reactive/payload-plugin-comments 1.1.1 → 1.2.0

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 (157) hide show
  1. package/dist/api/mutations/useAddCommentMutation.d.ts +18 -0
  2. package/dist/api/mutations/useAddCommentMutation.d.ts.map +1 -0
  3. package/dist/api/mutations/useAddCommentMutation.js +52 -0
  4. package/dist/api/mutations/useAddCommentMutation.js.map +1 -0
  5. package/dist/api/mutations/useDeleteCommentMutation.d.ts +11 -0
  6. package/dist/api/mutations/useDeleteCommentMutation.d.ts.map +1 -0
  7. package/dist/api/mutations/useDeleteCommentMutation.js +31 -0
  8. package/dist/api/mutations/useDeleteCommentMutation.js.map +1 -0
  9. package/dist/api/mutations/useResolveCommentMutation.d.ts +13 -0
  10. package/dist/api/mutations/useResolveCommentMutation.d.ts.map +1 -0
  11. package/dist/api/mutations/useResolveCommentMutation.js +41 -0
  12. package/dist/api/mutations/useResolveCommentMutation.js.map +1 -0
  13. package/dist/api/queries/useCommentsQuery.d.ts +3 -0
  14. package/dist/api/queries/useCommentsQuery.d.ts.map +1 -0
  15. package/dist/api/queries/useCommentsQuery.js +40 -0
  16. package/dist/api/queries/useCommentsQuery.js.map +1 -0
  17. package/dist/api/queries/useDocumentTitlesQuery.d.ts +3 -0
  18. package/dist/api/queries/useDocumentTitlesQuery.d.ts.map +1 -0
  19. package/dist/api/queries/useDocumentTitlesQuery.js +32 -0
  20. package/dist/api/queries/useDocumentTitlesQuery.js.map +1 -0
  21. package/dist/api/queries/useFieldLabelsQuery.d.ts +3 -0
  22. package/dist/api/queries/useFieldLabelsQuery.d.ts.map +1 -0
  23. package/dist/api/queries/useFieldLabelsQuery.js +23 -0
  24. package/dist/api/queries/useFieldLabelsQuery.js.map +1 -0
  25. package/dist/api/queries/useMentionableUsersQuery.d.ts +2 -0
  26. package/dist/api/queries/useMentionableUsersQuery.d.ts.map +1 -0
  27. package/dist/api/queries/useMentionableUsersQuery.js +25 -0
  28. package/dist/api/queries/useMentionableUsersQuery.js.map +1 -0
  29. package/dist/api/queryKeys.d.ts +23 -0
  30. package/dist/api/queryKeys.d.ts.map +1 -0
  31. package/dist/api/queryKeys.js +40 -0
  32. package/dist/api/queryKeys.js.map +1 -0
  33. package/dist/components/CommentEditor/index.d.ts.map +1 -1
  34. package/dist/components/CommentEditor/index.js +5 -3
  35. package/dist/components/CommentEditor/index.js.map +1 -1
  36. package/dist/components/CommentItem/StrikethoroughOverlay/clamp.d.ts +2 -0
  37. package/dist/components/CommentItem/StrikethoroughOverlay/clamp.d.ts.map +1 -0
  38. package/dist/components/CommentItem/StrikethoroughOverlay/clamp.js +7 -0
  39. package/dist/components/CommentItem/StrikethoroughOverlay/clamp.js.map +1 -0
  40. package/dist/components/CommentItem/StrikethoroughOverlay/index.d.ts +8 -0
  41. package/dist/components/CommentItem/StrikethoroughOverlay/index.d.ts.map +1 -0
  42. package/dist/components/CommentItem/StrikethoroughOverlay/index.js +24 -0
  43. package/dist/components/CommentItem/StrikethoroughOverlay/index.js.map +1 -0
  44. package/dist/components/CommentItem/StrikethoroughOverlay/measureLineRects.d.ts +3 -0
  45. package/dist/components/CommentItem/StrikethoroughOverlay/measureLineRects.d.ts.map +1 -0
  46. package/dist/components/CommentItem/StrikethoroughOverlay/measureLineRects.js +29 -0
  47. package/dist/components/CommentItem/StrikethoroughOverlay/measureLineRects.js.map +1 -0
  48. package/dist/components/CommentItem/StrikethoroughOverlay/useStrikethroughAnimation.d.ts +7 -0
  49. package/dist/components/CommentItem/StrikethoroughOverlay/useStrikethroughAnimation.d.ts.map +1 -0
  50. package/dist/components/CommentItem/StrikethoroughOverlay/useStrikethroughAnimation.js +114 -0
  51. package/dist/components/CommentItem/StrikethoroughOverlay/useStrikethroughAnimation.js.map +1 -0
  52. package/dist/components/CommentItem/index.d.ts.map +1 -1
  53. package/dist/components/CommentItem/index.js +37 -18
  54. package/dist/components/CommentItem/index.js.map +1 -1
  55. package/dist/components/CommentsDrawer/components/Header.d.ts.map +1 -1
  56. package/dist/components/CommentsDrawer/components/Header.js +4 -33
  57. package/dist/components/CommentsDrawer/components/Header.js.map +1 -1
  58. package/dist/components/CommentsHeaderButton/index.js +2 -2
  59. package/dist/components/CommentsHeaderButton/index.js.map +1 -1
  60. package/dist/components/CommentsPanel/components/CollapsibleGroup.d.ts +7 -2
  61. package/dist/components/CommentsPanel/components/CollapsibleGroup.d.ts.map +1 -1
  62. package/dist/components/CommentsPanel/components/CollapsibleGroup.js +7 -2
  63. package/dist/components/CommentsPanel/components/CollapsibleGroup.js.map +1 -1
  64. package/dist/components/CommentsPanel/components/DocumentView.d.ts.map +1 -1
  65. package/dist/components/CommentsPanel/components/DocumentView.js +11 -17
  66. package/dist/components/CommentsPanel/components/DocumentView.js.map +1 -1
  67. package/dist/components/CommentsPanel/components/FieldGroupSection.d.ts.map +1 -1
  68. package/dist/components/CommentsPanel/components/FieldGroupSection.js +44 -22
  69. package/dist/components/CommentsPanel/components/FieldGroupSection.js.map +1 -1
  70. package/dist/components/CommentsPanel/components/GlobalDocumentView.d.ts.map +1 -1
  71. package/dist/components/CommentsPanel/components/GlobalDocumentView.js +3 -9
  72. package/dist/components/CommentsPanel/components/GlobalDocumentView.js.map +1 -1
  73. package/dist/components/CommentsPanel/components/GlobalView.d.ts.map +1 -1
  74. package/dist/components/CommentsPanel/components/GlobalView.js +38 -41
  75. package/dist/components/CommentsPanel/components/GlobalView.js.map +1 -1
  76. package/dist/components/CommentsPanel/hooks/useCollapseState.d.ts +1 -1
  77. package/dist/components/CommentsPanel/hooks/useCollapseState.d.ts.map +1 -1
  78. package/dist/components/CommentsPanel/hooks/useCollapseState.js +4 -1
  79. package/dist/components/CommentsPanel/hooks/useCollapseState.js.map +1 -1
  80. package/dist/components/CommentsPanel/index.d.ts.map +1 -1
  81. package/dist/components/CommentsPanel/index.js +14 -11
  82. package/dist/components/CommentsPanel/index.js.map +1 -1
  83. package/dist/components/FieldCommentLabel/hooks/useFieldBreadcrumb.d.ts +2 -0
  84. package/dist/components/FieldCommentLabel/hooks/useFieldBreadcrumb.d.ts.map +1 -0
  85. package/dist/components/FieldCommentLabel/hooks/useFieldBreadcrumb.js +52 -0
  86. package/dist/components/FieldCommentLabel/hooks/useFieldBreadcrumb.js.map +1 -0
  87. package/dist/components/FieldCommentLabel/index.d.ts.map +1 -1
  88. package/dist/components/FieldCommentLabel/index.js +53 -41
  89. package/dist/components/FieldCommentLabel/index.js.map +1 -1
  90. package/dist/components/FieldCommentLabel/utils/exludeComments.js +2 -2
  91. package/dist/components/FieldCommentLabel/utils/exludeComments.js.map +1 -1
  92. package/dist/constants.d.ts +1 -0
  93. package/dist/constants.d.ts.map +1 -1
  94. package/dist/constants.js +3 -4
  95. package/dist/constants.js.map +1 -1
  96. package/dist/plugin.d.ts.map +1 -1
  97. package/dist/plugin.js +6 -2
  98. package/dist/plugin.js.map +1 -1
  99. package/dist/providers/CommentsDrawerProvider/index.d.ts +8 -0
  100. package/dist/providers/CommentsDrawerProvider/index.d.ts.map +1 -1
  101. package/dist/providers/CommentsDrawerProvider/index.js +22 -6
  102. package/dist/providers/CommentsDrawerProvider/index.js.map +1 -1
  103. package/dist/providers/CommentsProvider/index.d.ts +7 -17
  104. package/dist/providers/CommentsProvider/index.d.ts.map +1 -1
  105. package/dist/providers/CommentsProvider/index.js +105 -196
  106. package/dist/providers/CommentsProvider/index.js.map +1 -1
  107. package/dist/providers/CommentsProviderWrapper/index.d.ts +1 -1
  108. package/dist/providers/CommentsProviderWrapper/index.d.ts.map +1 -1
  109. package/dist/providers/CommentsProviderWrapper/index.js +11 -1
  110. package/dist/providers/CommentsProviderWrapper/index.js.map +1 -1
  111. package/dist/services/findAllComments.d.ts +4 -1
  112. package/dist/services/findAllComments.d.ts.map +1 -1
  113. package/dist/services/findAllComments.js +36 -10
  114. package/dist/services/findAllComments.js.map +1 -1
  115. package/dist/styles.css +1 -1
  116. package/dist/translations/en.d.ts.map +1 -1
  117. package/dist/translations/en.js +3 -7
  118. package/dist/translations/en.js.map +1 -1
  119. package/dist/translations/types.d.ts +2 -6
  120. package/dist/translations/types.d.ts.map +1 -1
  121. package/dist/types/general.d.ts +0 -2
  122. package/dist/types/general.d.ts.map +1 -1
  123. package/dist/types/index.d.ts +3 -2
  124. package/dist/types/index.d.ts.map +1 -1
  125. package/dist/types/query.d.ts +11 -0
  126. package/dist/types/query.d.ts.map +1 -0
  127. package/dist/types/query.js +1 -0
  128. package/dist/types/query.js.map +1 -0
  129. package/dist/utils/query/toQueryContext.d.ts +3 -0
  130. package/dist/utils/query/toQueryContext.d.ts.map +1 -0
  131. package/dist/utils/query/toQueryContext.js +20 -0
  132. package/dist/utils/query/toQueryContext.js.map +1 -0
  133. package/package.json +2 -5
  134. package/dist/components/CommentsPanel/constants.d.ts +0 -3
  135. package/dist/components/CommentsPanel/constants.d.ts.map +0 -1
  136. package/dist/components/CommentsPanel/constants.js +0 -9
  137. package/dist/components/CommentsPanel/constants.js.map +0 -1
  138. package/dist/components/CommentsPanel/utils/filterComments.d.ts +0 -9
  139. package/dist/components/CommentsPanel/utils/filterComments.d.ts.map +0 -1
  140. package/dist/components/CommentsPanel/utils/filterComments.js +0 -17
  141. package/dist/components/CommentsPanel/utils/filterComments.js.map +0 -1
  142. package/dist/components/FieldCommentLabel/AddCommentPopup.d.ts +0 -8
  143. package/dist/components/FieldCommentLabel/AddCommentPopup.d.ts.map +0 -1
  144. package/dist/components/FieldCommentLabel/AddCommentPopup.js +0 -50
  145. package/dist/components/FieldCommentLabel/AddCommentPopup.js.map +0 -1
  146. package/dist/providers/GlobalCommentsLoader/GlobalCommentsHydrator.d.ts +0 -13
  147. package/dist/providers/GlobalCommentsLoader/GlobalCommentsHydrator.d.ts.map +0 -1
  148. package/dist/providers/GlobalCommentsLoader/GlobalCommentsHydrator.js +0 -22
  149. package/dist/providers/GlobalCommentsLoader/GlobalCommentsHydrator.js.map +0 -1
  150. package/dist/providers/GlobalCommentsLoader/index.d.ts +0 -10
  151. package/dist/providers/GlobalCommentsLoader/index.d.ts.map +0 -1
  152. package/dist/providers/GlobalCommentsLoader/index.js +0 -31
  153. package/dist/providers/GlobalCommentsLoader/index.js.map +0 -1
  154. package/dist/services/syncAllCommentsData.d.ts +0 -12
  155. package/dist/services/syncAllCommentsData.d.ts.map +0 -1
  156. package/dist/services/syncAllCommentsData.js +0 -48
  157. package/dist/services/syncAllCommentsData.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/FieldCommentLabel/index.tsx"],"sourcesContent":["\"use client\";\n\nimport { useState } from \"react\";\nimport { useTranslation, useLocale } from \"@payloadcms/ui\";\nimport { MessageSquareIcon } from \"lucide-react\";\nimport { useComments } from \"../../providers/CommentsProvider\";\nimport type { FieldLabelClientProps } from \"payload\";\nimport type { Label } from \"./types\";\nimport { resolveLabel } from \"./utils/resolveLabel\";\nimport { excludeComments } from \"./utils/exludeComments\";\nimport { useStablePath } from \"./hooks/useStablePath\";\nimport { useCommentsDrawer } from \"../../providers/CommentsDrawerProvider\";\nimport { IconButton } from \"../IconButton\";\nimport { AddCommentPopup } from \"./AddCommentPopup\";\n\ninterface Props extends FieldLabelClientProps {\n field: FieldLabelClientProps[\"field\"] & {\n label?: Label;\n required?: boolean;\n };\n}\n\nexport function FieldCommentLabel({ field, htmlFor, path: fieldPath }: Props) {\n const { label, required } = field;\n\n const { t } = useTranslation();\n const { code: locale } = useLocale();\n const { open: openDrawer, setScrollTargetPath } = useCommentsDrawer();\n const { visibleComments, setFilter, mode } = useComments();\n\n const [isHovered, setIsHovered] = useState(false);\n const [isPopupOpen, setIsPopupOpen] = useState(false);\n\n const resolvedLabel = resolveLabel(label, locale);\n const stablePath = useStablePath(fieldPath ?? \"\");\n const fieldComments = excludeComments(visibleComments, stablePath || undefined, locale);\n const openCommentsCount = fieldComments.length;\n\n const handleOpenDrawer = () => {\n setFilter(\"open\");\n setScrollTargetPath(stablePath || null);\n openDrawer();\n };\n\n const handleToggle = (isOpen: boolean) => {\n setIsPopupOpen(isOpen);\n };\n\n if (!resolvedLabel) return null;\n\n return (\n <div\n className=\"flex items-center gap-1.5 pb-1.25\"\n onMouseEnter={() => setIsHovered(true)}\n onMouseLeave={() => setIsHovered(false)}>\n <label className=\"field-label p-0\" htmlFor={htmlFor}>\n {resolvedLabel}\n\n {required && <span className=\"required\">*</span>}\n </label>\n\n {fieldPath && (mode === \"document\" || mode === \"global-document\") && (\n <div className=\"relative flex items-center\">\n {openCommentsCount > 0 ?\n <IconButton\n className=\"w-auto px-1 gap-1 text-[12px] font-semibold leading-none\"\n size=\"sm\"\n title={t(\"comments:openComments\" as never, { count: openCommentsCount })}\n onClick={handleOpenDrawer}>\n <MessageSquareIcon size={14} />\n\n {openCommentsCount}\n </IconButton>\n : <AddCommentPopup fieldPath={stablePath} showTrigger={isHovered || isPopupOpen} onToggle={handleToggle} />}\n </div>\n )}\n </div>\n );\n}\n"],"mappings":";AAuDM,SAGe,KAHf;AArDN,SAAS,gBAAgB;AACzB,SAAS,gBAAgB,iBAAiB;AAC1C,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAG5B,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB;AAChC,SAAS,qBAAqB;AAC9B,SAAS,yBAAyB;AAClC,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AASzB,SAAS,kBAAkB,EAAE,OAAO,SAAS,MAAM,UAAU,GAAU;AAC5E,QAAM,EAAE,OAAO,SAAS,IAAI;AAE5B,QAAM,EAAE,EAAE,IAAI,eAAe;AAC7B,QAAM,EAAE,MAAM,OAAO,IAAI,UAAU;AACnC,QAAM,EAAE,MAAM,YAAY,oBAAoB,IAAI,kBAAkB;AACpE,QAAM,EAAE,iBAAiB,WAAW,KAAK,IAAI,YAAY;AAEzD,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAChD,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,KAAK;AAEpD,QAAM,gBAAgB,aAAa,OAAO,MAAM;AAChD,QAAM,aAAa,cAAc,aAAa,EAAE;AAChD,QAAM,gBAAgB,gBAAgB,iBAAiB,cAAc,QAAW,MAAM;AACtF,QAAM,oBAAoB,cAAc;AAExC,QAAM,mBAAmB,MAAM;AAC7B,cAAU,MAAM;AAChB,wBAAoB,cAAc,IAAI;AACtC,eAAW;AAAA,EACb;AAEA,QAAM,eAAe,CAAC,WAAoB;AACxC,mBAAe,MAAM;AAAA,EACvB;AAEA,MAAI,CAAC,cAAe,QAAO;AAE3B,SACE;AAAA,IAAC;AAAA;AAAA,MACC,WAAU;AAAA,MACV,cAAc,MAAM,aAAa,IAAI;AAAA,MACrC,cAAc,MAAM,aAAa,KAAK;AAAA,MACtC;AAAA,6BAAC,WAAM,WAAU,mBAAkB,SAChC;AAAA;AAAA,UAEA,YAAY,oBAAC,UAAK,WAAU,YAAW,eAAC;AAAA,WAC3C;AAAA,QAEC,cAAc,SAAS,cAAc,SAAS,sBAC7C,oBAAC,SAAI,WAAU,8BACZ,8BAAoB,IACnB;AAAA,UAAC;AAAA;AAAA,YACC,WAAU;AAAA,YACV,MAAK;AAAA,YACL,OAAO,EAAE,yBAAkC,EAAE,OAAO,kBAAkB,CAAC;AAAA,YACvE,SAAS;AAAA,YACT;AAAA,kCAAC,qBAAkB,MAAM,IAAI;AAAA,cAE5B;AAAA;AAAA;AAAA,QACH,IACA,oBAAC,mBAAgB,WAAW,YAAY,aAAa,aAAa,aAAa,UAAU,cAAc,GAC3G;AAAA;AAAA;AAAA,EAEJ;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/components/FieldCommentLabel/index.tsx"],"sourcesContent":["\"use client\";\n\nimport { useTranslation, useLocale } from \"@payloadcms/ui\";\nimport { MessageSquareIcon, MessageSquarePlus } from \"lucide-react\";\nimport { useComments } from \"../../providers/CommentsProvider\";\nimport type { FieldLabelClientProps } from \"payload\";\nimport type { Label } from \"./types\";\nimport { resolveLabel } from \"./utils/resolveLabel\";\nimport { excludeComments } from \"./utils/exludeComments\";\nimport { useStablePath } from \"./hooks/useStablePath\";\nimport { useFieldBreadcrumb } from \"./hooks/useFieldBreadcrumb\";\nimport { useCommentsDrawer } from \"../../providers/CommentsDrawerProvider\";\nimport { IconButton } from \"../IconButton\";\nimport { resolveFieldLabel } from \"../CommentsPanel/utils/resolveFieldLabel\";\nimport { useCommentsQuery } from \"../../api/queries/useCommentsQuery\";\nimport { useFieldLabelsQuery } from \"../../api/queries/useFieldLabelsQuery\";\nimport { filterCommentsByLocale } from \"../../utils/comment/filterCommentsByLocale\";\n\ninterface Props extends FieldLabelClientProps {\n field: FieldLabelClientProps[\"field\"] & {\n label?: Label;\n required?: boolean;\n };\n}\n\nexport function FieldCommentLabel({ field, htmlFor, path: fieldPath }: Props) {\n const { label, required } = field;\n\n const { t } = useTranslation();\n const { code: locale } = useLocale();\n\n const { openForField } = useCommentsDrawer();\n const { mode, queryContext, collectionSlug, documentId, globalSlug } = useComments();\n const { data: allComments = [] } = useCommentsQuery(queryContext);\n const { data: fieldLabelRegistry } = useFieldLabelsQuery(queryContext);\n\n const resolvedLabel = resolveLabel(label, locale);\n const stablePath = useStablePath(fieldPath ?? \"\");\n\n const localeFiltered = filterCommentsByLocale(allComments, locale);\n const fieldComments = excludeComments(localeFiltered, stablePath || undefined, locale);\n const openCommentsCount = fieldComments.length;\n\n const clientBreadcrumb = useFieldBreadcrumb(fieldPath, resolvedLabel, collectionSlug, globalSlug);\n\n const handleOpenDrawer = () => {\n if (!stablePath) return;\n\n const serverLabel = resolveFieldLabel({\n registry: fieldLabelRegistry ?? {},\n collectionSlug: collectionSlug ?? undefined,\n documentId: documentId ?? undefined,\n globalSlug: globalSlug ?? undefined,\n fieldPath: stablePath,\n });\n\n openForField(stablePath, serverLabel !== stablePath ? serverLabel : clientBreadcrumb);\n };\n\n if (!resolvedLabel) return null;\n\n return (\n <div className=\"flex items-center gap-1.5 pb-1.25 group\">\n <label className=\"field-label p-0\" htmlFor={htmlFor}>\n {resolvedLabel}\n\n {required && <span className=\"required\">*</span>}\n </label>\n\n {fieldPath && (mode === \"document\" || mode === \"global-document\") && (\n <div className=\"relative flex items-center\">\n {!!openCommentsCount && (\n <IconButton\n className=\"w-auto px-1 gap-1 text-[12px] font-semibold leading-none\"\n size=\"sm\"\n title={t(\"comments:openComments\" as never, { count: openCommentsCount })}\n onClick={handleOpenDrawer}>\n <MessageSquareIcon size={14} />\n\n {openCommentsCount}\n </IconButton>\n )}\n {!openCommentsCount && (\n <IconButton\n className={\"opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100 transition-opacity\"}\n size=\"sm\"\n title={t(\"comments:add\" as never)}\n onClick={handleOpenDrawer}>\n <MessageSquarePlus size={14} />\n </IconButton>\n )}\n </div>\n )}\n </div>\n );\n}\n"],"mappings":";AA+DM,SAGe,KAHf;AA7DN,SAAS,gBAAgB,iBAAiB;AAC1C,SAAS,mBAAmB,yBAAyB;AACrD,SAAS,mBAAmB;AAG5B,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB;AAChC,SAAS,qBAAqB;AAC9B,SAAS,0BAA0B;AACnC,SAAS,yBAAyB;AAClC,SAAS,kBAAkB;AAC3B,SAAS,yBAAyB;AAClC,SAAS,wBAAwB;AACjC,SAAS,2BAA2B;AACpC,SAAS,8BAA8B;AAShC,SAAS,kBAAkB,EAAE,OAAO,SAAS,MAAM,UAAU,GAAU;AAC5E,QAAM,EAAE,OAAO,SAAS,IAAI;AAE5B,QAAM,EAAE,EAAE,IAAI,eAAe;AAC7B,QAAM,EAAE,MAAM,OAAO,IAAI,UAAU;AAEnC,QAAM,EAAE,aAAa,IAAI,kBAAkB;AAC3C,QAAM,EAAE,MAAM,cAAc,gBAAgB,YAAY,WAAW,IAAI,YAAY;AACnF,QAAM,EAAE,MAAM,cAAc,CAAC,EAAE,IAAI,iBAAiB,YAAY;AAChE,QAAM,EAAE,MAAM,mBAAmB,IAAI,oBAAoB,YAAY;AAErE,QAAM,gBAAgB,aAAa,OAAO,MAAM;AAChD,QAAM,aAAa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) {
2
2
  if (!path) return [];
3
- return (comments ?? []).filter(({ fieldPath, isResolved, locale }) => {
4
- if (fieldPath !== path || isResolved) return false;
3
+ return (comments ?? []).filter(({ fieldPath, locale }) => {
4
+ if (fieldPath !== path) return false;
5
5
  if (locale && currentLocale && locale !== currentLocale) return false;
6
6
  return true;
7
7
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/FieldCommentLabel/utils/exludeComments.ts"],"sourcesContent":["import type { Comment } from \"../../../types\";\n\nexport function excludeComments(comments: Comment[] | null, path: string | undefined, currentLocale?: string | null) {\n if (!path) return [];\n\n return (comments ?? []).filter(({ fieldPath, isResolved, locale }) => {\n if (fieldPath !== path || isResolved) return false;\n\n if (locale && currentLocale && locale !== currentLocale) return false;\n\n return true;\n });\n}\n"],"mappings":"AAEO,SAAS,gBAAgB,UAA4B,MAA0B,eAA+B;AACnH,MAAI,CAAC,KAAM,QAAO,CAAC;AAEnB,UAAQ,YAAY,CAAC,GAAG,OAAO,CAAC,EAAE,WAAW,YAAY,OAAO,MAAM;AACpE,QAAI,cAAc,QAAQ,WAAY,QAAO;AAE7C,QAAI,UAAU,iBAAiB,WAAW,cAAe,QAAO;AAEhE,WAAO;AAAA,EACT,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../../src/components/FieldCommentLabel/utils/exludeComments.ts"],"sourcesContent":["import type { Comment } from \"../../../types\";\n\nexport function excludeComments(comments: Comment[] | null, path: string | undefined, currentLocale?: string | null) {\n if (!path) return [];\n\n return (comments ?? []).filter(({ fieldPath, locale }) => {\n if (fieldPath !== path) return false;\n\n if (locale && currentLocale && locale !== currentLocale) return false;\n\n return true;\n });\n}\n"],"mappings":"AAEO,SAAS,gBAAgB,UAA4B,MAA0B,eAA+B;AACnH,MAAI,CAAC,KAAM,QAAO,CAAC;AAEnB,UAAQ,YAAY,CAAC,GAAG,OAAO,CAAC,EAAE,WAAW,OAAO,MAAM;AACxD,QAAI,cAAc,KAAM,QAAO;AAE/B,QAAI,UAAU,iBAAiB,WAAW,cAAe,QAAO;AAEhE,WAAO;AAAA,EACT,CAAC;AACH;","names":[]}
@@ -6,4 +6,5 @@ export declare const USERNAME_DEFAULT_FIELD_PATH = "name";
6
6
  export declare const FALLBACK_USERNAME = "Unknown user";
7
7
  export declare const FALLBACK_DELETED_USERNAME = "Deleted user";
8
8
  export declare const EXCLUDED_ADMIN_ROUTES: string[];
9
+ export declare const REFETCH_INTERVAL = 15000;
9
10
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uBAAuB,aAAa,CAAC;AAClD,eAAO,MAAM,yBAAyB,mBAAmB,CAAC;AAE1D,eAAO,MAAM,WAAW,4BAA4B,CAAC;AACrD,eAAO,MAAM,YAAY,4CAA4C,CAAC;AAEtE,eAAO,MAAM,2BAA2B,SAAS,CAAC;AAClD,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAChD,eAAO,MAAM,yBAAyB,iBAAiB,CAAC;AAExD,eAAO,MAAM,qBAAqB,UAGjC,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uBAAuB,aAAa,CAAC;AAClD,eAAO,MAAM,yBAAyB,mBAAmB,CAAC;AAE1D,eAAO,MAAM,WAAW,4BAA4B,CAAC;AACrD,eAAO,MAAM,YAAY,4CAA4C,CAAC;AAEtE,eAAO,MAAM,2BAA2B,SAAS,CAAC;AAClD,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAChD,eAAO,MAAM,yBAAyB,iBAAiB,CAAC;AAExD,eAAO,MAAM,qBAAqB,UAAiD,CAAC;AAEpF,eAAO,MAAM,gBAAgB,QAAQ,CAAC"}
package/dist/constants.js CHANGED
@@ -5,10 +5,8 @@ const PACKAGE_NAME = "@focus-reactive/payload-plugin-comments";
5
5
  const USERNAME_DEFAULT_FIELD_PATH = "name";
6
6
  const FALLBACK_USERNAME = "Unknown user";
7
7
  const FALLBACK_DELETED_USERNAME = "Deleted user";
8
- const EXCLUDED_ADMIN_ROUTES = [
9
- "/admin/account",
10
- "/admin/create-first-user"
11
- ];
8
+ const EXCLUDED_ADMIN_ROUTES = ["/admin/account", "/admin/create-first-user"];
9
+ const REFETCH_INTERVAL = 15e3;
12
10
  export {
13
11
  COMMENTS_DRAWER_BASE_SLUG,
14
12
  DEFAULT_COLLECTION_SLUG,
@@ -17,6 +15,7 @@ export {
17
15
  FALLBACK_USERNAME,
18
16
  PACKAGE_NAME,
19
17
  PLUGIN_NAME,
18
+ REFETCH_INTERVAL,
20
19
  USERNAME_DEFAULT_FIELD_PATH
21
20
  };
22
21
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/constants.ts"],"sourcesContent":["export const DEFAULT_COLLECTION_SLUG = \"comments\";\nexport const COMMENTS_DRAWER_BASE_SLUG = \"comments-panel\";\n\nexport const PLUGIN_NAME = \"payload-plugin-comments\";\nexport const PACKAGE_NAME = \"@focus-reactive/payload-plugin-comments\";\n\nexport const USERNAME_DEFAULT_FIELD_PATH = \"name\";\nexport const FALLBACK_USERNAME = \"Unknown user\";\nexport const FALLBACK_DELETED_USERNAME = \"Deleted user\";\n\nexport const EXCLUDED_ADMIN_ROUTES = [\n '/admin/account',\n '/admin/create-first-user',\n]\n"],"mappings":"AAAO,MAAM,0BAA0B;AAChC,MAAM,4BAA4B;AAElC,MAAM,cAAc;AACpB,MAAM,eAAe;AAErB,MAAM,8BAA8B;AACpC,MAAM,oBAAoB;AAC1B,MAAM,4BAA4B;AAElC,MAAM,wBAAwB;AAAA,EACnC;AAAA,EACA;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/constants.ts"],"sourcesContent":["export const DEFAULT_COLLECTION_SLUG = \"comments\";\nexport const COMMENTS_DRAWER_BASE_SLUG = \"comments-panel\";\n\nexport const PLUGIN_NAME = \"payload-plugin-comments\";\nexport const PACKAGE_NAME = \"@focus-reactive/payload-plugin-comments\";\n\nexport const USERNAME_DEFAULT_FIELD_PATH = \"name\";\nexport const FALLBACK_USERNAME = \"Unknown user\";\nexport const FALLBACK_DELETED_USERNAME = \"Deleted user\";\n\nexport const EXCLUDED_ADMIN_ROUTES = [\"/admin/account\", \"/admin/create-first-user\"];\n\nexport const REFETCH_INTERVAL = 15000;\n"],"mappings":"AAAO,MAAM,0BAA0B;AAChC,MAAM,4BAA4B;AAElC,MAAM,cAAc;AACpB,MAAM,eAAe;AAErB,MAAM,8BAA8B;AACpC,MAAM,oBAAoB;AAC1B,MAAM,4BAA4B;AAElC,MAAM,wBAAwB,CAAC,kBAAkB,0BAA0B;AAE3E,MAAM,mBAAmB;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,SAAS,CAAC;AAE9C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAQpD,eAAO,MAAM,cAAc,YAChB,oBAAoB,KAAQ,MA2DpC,CAAC"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,SAAS,CAAC;AAE9C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AASpD,eAAO,MAAM,cAAc,YAChB,oBAAoB,KAAQ,MA+DpC,CAAC"}
package/dist/plugin.js CHANGED
@@ -5,6 +5,7 @@ import { normalizeCollections } from "./utils/config/normalizeCollections";
5
5
  import { mergeTranslations } from "./utils/config/mergeTranslations";
6
6
  import { overrideCollections } from "./utils/config/overrideCollections";
7
7
  import { overrideGlobals } from "./utils/config/overrideGlobals";
8
+ import { setPayloadConfig } from "./config";
8
9
  const commentsPlugin = (config = {}) => (incomingConfig) => {
9
10
  const { enabled = true, collections: collectionEntries, overrides, usernameFieldPath } = config;
10
11
  if (!enabled) {
@@ -31,8 +32,7 @@ const commentsPlugin = (config = {}) => (incomingConfig) => {
31
32
  ...incomingConfig.admin?.components,
32
33
  providers: [
33
34
  ...incomingConfig.admin?.components?.providers ?? [],
34
- getComponentPath("providers/CommentsProviderWrapper", "CommentsProviderWrapper"),
35
- getComponentPath("providers/GlobalCommentsLoader", "GlobalCommentsLoader")
35
+ getComponentPath("providers/CommentsProviderWrapper", "CommentsProviderWrapper")
36
36
  ],
37
37
  actions: [
38
38
  ...incomingConfig.admin?.components?.actions ?? [],
@@ -50,6 +50,10 @@ const commentsPlugin = (config = {}) => (incomingConfig) => {
50
50
  }
51
51
  }
52
52
  },
53
+ onInit: async (payload) => {
54
+ setPayloadConfig(payload.config);
55
+ await incomingConfig.onInit?.(payload);
56
+ },
53
57
  collections: [...overrideCollections(incomingConfig.collections), finalCollection],
54
58
  globals: overrideGlobals(incomingConfig.globals)
55
59
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["import type { Config, Plugin } from \"payload\";\nimport { baseCollection as getBaseCollection } from \"./collection\";\nimport type { CommentsPluginConfig } from \"./types\";\nimport { overrideCommentsCollection } from \"./utils/config/overrideCommentsCollection\";\nimport { getComponentPath } from \"./utils/path/getComponentPath\";\nimport { normalizeCollections } from \"./utils/config/normalizeCollections\";\nimport { mergeTranslations } from \"./utils/config/mergeTranslations\";\nimport { overrideCollections } from \"./utils/config/overrideCollections\";\nimport { overrideGlobals } from \"./utils/config/overrideGlobals\";\n\nexport const commentsPlugin =\n (config: CommentsPluginConfig = {}): Plugin =>\n (incomingConfig: Config): Config => {\n const { enabled = true, collections: collectionEntries, overrides, usernameFieldPath } = config;\n\n if (!enabled) {\n return incomingConfig;\n }\n\n const baseCollection = getBaseCollection(config.tenant);\n const finalCollection = overrideCommentsCollection(baseCollection, overrides);\n\n const allGlobalSlugs = (incomingConfig.globals ?? []).map((g) => g.slug);\n const allCollectionSlugs = (incomingConfig.collections ?? []).map((c) => c.slug);\n\n const normalizedCollections = normalizeCollections(collectionEntries);\n const documentTitleFields =\n normalizedCollections ?\n Object.fromEntries([...normalizedCollections.entries()].map(([k, v]) => [k, v.titleField]))\n : {};\n\n const userTranslations = config.translations ?? {};\n const incomingConfigTranslations = (incomingConfig.i18n?.translations as Record<string, object> | undefined) ?? {};\n\n const mergedTranslations = mergeTranslations(incomingConfigTranslations, userTranslations);\n\n return {\n ...incomingConfig,\n i18n: {\n ...incomingConfig.i18n,\n translations: mergedTranslations,\n },\n admin: {\n ...incomingConfig.admin,\n components: {\n ...incomingConfig.admin?.components,\n providers: [\n ...(incomingConfig.admin?.components?.providers ?? []),\n getComponentPath(\"providers/CommentsProviderWrapper\", \"CommentsProviderWrapper\"),\n getComponentPath(\"providers/GlobalCommentsLoader\", \"GlobalCommentsLoader\"),\n ],\n actions: [\n ...(incomingConfig.admin?.components?.actions ?? []),\n getComponentPath(\"components/CommentsHeaderButton\", \"CommentsHeaderButton\"),\n ],\n },\n custom: {\n ...incomingConfig.admin?.custom,\n commentsPlugin: {\n collections: allCollectionSlugs,\n documentTitleFields,\n globals: allGlobalSlugs,\n tenant: config.tenant,\n usernameFieldPath,\n },\n },\n },\n collections: [...overrideCollections(incomingConfig.collections), finalCollection],\n globals: overrideGlobals(incomingConfig.globals),\n };\n };\n"],"mappings":"AACA,SAAS,kBAAkB,yBAAyB;AAEpD,SAAS,kCAAkC;AAC3C,SAAS,wBAAwB;AACjC,SAAS,4BAA4B;AACrC,SAAS,yBAAyB;AAClC,SAAS,2BAA2B;AACpC,SAAS,uBAAuB;AAEzB,MAAM,iBACX,CAAC,SAA+B,CAAC,MACjC,CAAC,mBAAmC;AAClC,QAAM,EAAE,UAAU,MAAM,aAAa,mBAAmB,WAAW,kBAAkB,IAAI;AAEzF,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AAEA,QAAM,iBAAiB,kBA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Ae,WAAW,GAAG,eAAe;AAAA,IACjF,SAAS,gBAAgB,eAAe,OAAO;AAAA,EACjD;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["import type { Config, Plugin } from \"payload\";\nimport { baseCollection as getBaseCollection } from \"./collection\";\nimport type { CommentsPluginConfig } from \"./types\";\nimport { overrideCommentsCollection } from \"./utils/config/overrideCommentsCollection\";\nimport { getComponentPath } from \"./utils/path/getComponentPath\";\nimport { normalizeCollections } from \"./utils/config/normalizeCollections\";\nimport { mergeTranslations } from \"./utils/config/mergeTranslations\";\nimport { overrideCollections } from \"./utils/config/overrideCollections\";\nimport { overrideGlobals } from \"./utils/config/overrideGlobals\";\nimport { setPayloadConfig } from \"./config\";\n\nexport const commentsPlugin =\n (config: CommentsPluginConfig = {}): Plugin =>\n (incomingConfig: Config): Config => {\n const { enabled = true, collections: collectionEntries, overrides, usernameFieldPath } = config;\n\n if (!enabled) {\n return incomingConfig;\n }\n\n const baseCollection = getBaseCollection(config.tenant);\n const finalCollection = overrideCommentsCollection(baseCollection, overrides);\n\n const allGlobalSlugs = (incomingConfig.globals ?? []).map((g) => g.slug);\n const allCollectionSlugs = (incomingConfig.collections ?? []).map((c) => c.slug);\n\n const normalizedCollections = normalizeCollections(collectionEntries);\n const documentTitleFields =\n normalizedCollections ?\n Object.fromEntries([...normalizedCollections.entries()].map(([k, v]) => [k, v.titleField]))\n : {};\n\n const userTranslations = config.translations ?? {};\n const incomingConfigTranslations = (incomingConfig.i18n?.translations as Record<string, object> | undefined) ?? {};\n\n const mergedTranslations = mergeTranslations(incomingConfigTranslations, userTranslations);\n\n return {\n ...incomingConfig,\n i18n: {\n ...incomingConfig.i18n,\n translations: mergedTranslations,\n },\n admin: {\n ...incomingConfig.admin,\n components: {\n ...incomingConfig.admin?.components,\n providers: [\n ...(incomingConfig.admin?.components?.providers ?? []),\n getComponentPath(\"providers/CommentsProviderWrapper\", \"CommentsProviderWrapper\"),\n ],\n actions: [\n ...(incomingConfig.admin?.components?.actions ?? []),\n getComponentPath(\"components/CommentsHeaderButton\", \"CommentsHeaderButton\"),\n ],\n },\n custom: {\n ...incomingConfig.admin?.custom,\n commentsPlugin: {\n collections: allCollectionSlugs,\n documentTitleFields,\n globals: allGlobalSlugs,\n tenant: config.tenant,\n usernameFieldPath,\n },\n },\n },\n onInit: async (payload) => {\n setPayloadConfig(payload.config);\n\n await incomingConfig.onInit?.(payload);\n },\n collections: [...overrideCollections(incomingConfig.collections), finalCollection],\n globals: overrideGlobals(incomingConfig.globals),\n };\n };\n"],"mappings":"AACA,SAAS,kBAAkB,yBAAyB;AAEpD,SAAS,kCAAkC;AAC3C,SAAS,wBAAwB;AACjC,SAAS,4BAA4B;AACrC,SAAS,yBAAyB;AAClC,SAAS,2BAA2B;AACpC,SAAS,uBAAuB;AAChC,SAAS,wBAAwB;AAE1B,MAAM,iBACX,CAAC,SAA+B,CAAC,MACjC,CAAC,mBAAmC;AAClC,QAAM,EAAE,UAAU,MAAM,aAAa,mBAAmB,WAAW,kBAAkB,IAAI;AAEzF,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AAEA,QAAM,iBAAiB,kBAAkB,OAAO,MAAM;AACtD,QAAM,kBAAkB,2BAA2B,gBAAgB,SAAS;AAE5E,QAAM,kBAAkB,eAAe,WAAW,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI;AACvE,QAAM,sBAAsB,eAAe,eAAe,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI;AAE/E,QAAM,wBAAwB,qBAAqB,iBAAiB;AACpE,QAAM,sBACJ,wBACE,OAAO,YAAY,CAAC,GAAG,sBAAsB,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC,IAC1F,CAAC;AAEL,QAAM,mBAAmB,OAAO,gBAAgB,CAAC;AACjD,QAAM,6BAA8B,eAAe,MAAM,gBAAuD,CAAC;AAEjH,QAAM,qBAAqB,kBAAkB,4BAA4B,gBAAgB;AAEzF,SAAO;AAAA,IACL,GAAG;AAAA,IACH,MAAM;AAAA,MACJ,GAAG,eAAe;AAAA,MAClB,cAAc;AAAA,IAChB;AAAA,IACA,OAAO;AAAA,MACL,GAAG,eAAe;AAAA,MAClB,YAAY;AAAA,QACV,GAAG,eAAe,OAAO;AAAA,QACzB,WAAW;AAAA,UACT,GAAI,eAAe,OAAO,YAAY,aAAa,CAAC;AAAA,UACpD,iBAAiB,qCAAqC,yBAAyB;AAAA,QACjF;AAAA,QACA,SAAS;AAAA,UACP,GAAI,eAAe,OAAO,YAAY,WAAW,CAAC;AAAA,UAClD,iBAAiB,mCAAmC,sBAAsB;AAAA,QAC5E;AAAA,MACF;AAAA,MACA,QAAQ;AAAA,QACN,GAAG,eAAe,OAAO;AAAA,QACzB,gBAAgB;AAAA,UACd,aAAa;AAAA,UACb;AAAA,UACA,SAAS;AAAA,UACT,QAAQ,OAAO;AAAA,UACf;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA,QAAQ,OAAO,YAAY;AACzB,uBAAiB,QAAQ,MAAM;AAE/B,YAAM,eAAe,SAAS,OAAO;AAAA,IACvC;AAAA,IACA,aAAa,CAAC,GAAG,oBAAoB,eAAe,WAAW,GAAG,eAAe;AAAA,IACjF,SAAS,gBAAgB,eAAe,OAAO;AAAA,EACjD;AACF;","names":[]}
@@ -1,9 +1,17 @@
1
1
  import { type ReactNode } from "react";
2
+ interface PendingField {
3
+ path: string;
4
+ label: string;
5
+ }
2
6
  interface CommentsDrawerContextProps {
3
7
  slug: string;
8
+ isOpen: boolean;
4
9
  scrollTargetPath: string | null;
10
+ pendingField: PendingField | null;
5
11
  open: () => void;
6
12
  setScrollTargetPath: (path: string | null) => void;
13
+ openForField: (path: string, label: string) => void;
14
+ clearPendingField: () => void;
7
15
  }
8
16
  interface Props {
9
17
  children: ReactNode;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/CommentsDrawerProvider/index.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAiB,KAAK,SAAS,EAAwB,MAAM,OAAO,CAAC;AAI5E,UAAU,0BAA0B;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,mBAAmB,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;CACpD;AAID,UAAU,KAAK;IACb,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,wBAAgB,sBAAsB,CAAC,EAAE,QAAQ,EAAE,EAAE,KAAK,2CAiBzD;AAED,wBAAgB,iBAAiB,+BAMhC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/CommentsDrawerProvider/index.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAiB,KAAK,SAAS,EAAmC,MAAM,OAAO,CAAC;AAGvF,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,UAAU,0BAA0B;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;IAClC,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,mBAAmB,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IACnD,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACpD,iBAAiB,EAAE,MAAM,IAAI,CAAC;CAC/B;AAID,UAAU,KAAK;IACb,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,wBAAgB,sBAAsB,CAAC,EAAE,QAAQ,EAAE,EAAE,KAAK,2CAiCzD;AAED,wBAAgB,iBAAiB,+BAMhC"}
@@ -1,20 +1,36 @@
1
1
  "use client";
2
2
  import { jsx } from "react/jsx-runtime";
3
3
  import { useDrawerSlug, useModal } from "@payloadcms/ui";
4
- import { createContext, useContext, useState } from "react";
4
+ import { createContext, useContext, useEffect, useState } from "react";
5
5
  import { COMMENTS_DRAWER_BASE_SLUG } from "../../constants";
6
- import { useComments } from "../CommentsProvider";
7
6
  const CommentsDrawerContext = createContext(null);
8
7
  function CommentsDrawerProvider({ children }) {
9
8
  const [scrollTargetPath, setScrollTargetPath] = useState(null);
9
+ const [pendingField, setPendingField] = useState(null);
10
10
  const slug = useDrawerSlug(COMMENTS_DRAWER_BASE_SLUG);
11
- const { openModal } = useModal();
12
- const { syncComments } = useComments();
11
+ const { openModal, modalState } = useModal();
12
+ const isOpen = modalState[slug]?.isOpen ?? false;
13
13
  const open = () => {
14
14
  openModal(slug);
15
- void syncComments();
16
15
  };
17
- return /* @__PURE__ */ jsx(CommentsDrawerContext.Provider, { value: { slug, scrollTargetPath, open, setScrollTargetPath }, children });
16
+ const openForField = (path, label) => {
17
+ setScrollTargetPath(path);
18
+ setPendingField({ path, label });
19
+ openModal(slug);
20
+ };
21
+ const clearPendingField = () => setPendingField(null);
22
+ useEffect(() => {
23
+ if (!isOpen) {
24
+ setPendingField(null);
25
+ }
26
+ }, [isOpen]);
27
+ return /* @__PURE__ */ jsx(
28
+ CommentsDrawerContext.Provider,
29
+ {
30
+ value: { slug, isOpen, scrollTargetPath, pendingField, open, setScrollTargetPath, openForField, clearPendingField },
31
+ children
32
+ }
33
+ );
18
34
  }
19
35
  function useCommentsDrawer() {
20
36
  const context = useContext(CommentsDrawerContext);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/providers/CommentsDrawerProvider/index.tsx"],"sourcesContent":["\"use client\";\n\nimport { useDrawerSlug, useModal } from \"@payloadcms/ui\";\nimport { createContext, type ReactNode, useContext, useState } from \"react\";\nimport { COMMENTS_DRAWER_BASE_SLUG } from \"../../constants\";\nimport { useComments } from \"../CommentsProvider\";\n\ninterface CommentsDrawerContextProps {\n slug: string;\n scrollTargetPath: string | null;\n open: () => void;\n setScrollTargetPath: (path: string | null) => void;\n}\n\nconst CommentsDrawerContext = createContext<CommentsDrawerContextProps | null>(null);\n\ninterface Props {\n children: ReactNode;\n}\n\nexport function CommentsDrawerProvider({ children }: Props) {\n const [scrollTargetPath, setScrollTargetPath] = useState<string | null>(null);\n const slug = useDrawerSlug(COMMENTS_DRAWER_BASE_SLUG);\n const { openModal } = useModal();\n const { syncComments } = useComments();\n\n const open = () => {\n openModal(slug);\n\n void syncComments();\n };\n\n return (\n <CommentsDrawerContext.Provider value={{ slug, scrollTargetPath, open, setScrollTargetPath }}>\n {children}\n </CommentsDrawerContext.Provider>\n );\n}\n\nexport function useCommentsDrawer() {\n const context = useContext(CommentsDrawerContext);\n\n if (!context) throw new Error(\"useCommentsDrawer must be used within a CommentsProvider\");\n\n return context;\n}\n"],"mappings":";AAiCI;AA/BJ,SAAS,eAAe,gBAAgB;AACxC,SAAS,eAA+B,YAAY,gBAAgB;AACpE,SAAS,iCAAiC;AAC1C,SAAS,mBAAmB;AAS5B,MAAM,wBAAwB,cAAiD,IAAI;AAM5E,SAAS,uBAAuB,EAAE,SAAS,GAAU;AAC1D,QAAM,CAAC,kBAAkB,mBAAmB,IAAI,SAAwB,IAAI;AAC5E,QAAM,OAAO,cAAc,yBAAyB;AACpD,QAAM,EAAE,UAAU,IAAI,SAAS;AAC/B,QAAM,EAAE,aAAa,IAAI,YAAY;AAErC,QAAM,OAAO,MAAM;AACjB,cAAU,IAAI;AAEd,SAAK,aAAa;AAAA,EACpB;AAEA,SACE,oBAAC,sBAAsB,UAAtB,EAA+B,OAAO,EAAE,MAAM,kBAAkB,MAAM,oBAAoB,GACxF,UACH;AAEJ;AAEO,SAAS,oBAAoB;AAClC,QAAM,UAAU,WAAW,qBAAqB;AAEhD,MAAI,CAAC,QAAS,OAAM,IAAI,MAAM,0DAA0D;AAExF,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/providers/CommentsDrawerProvider/index.tsx"],"sourcesContent":["\"use client\";\n\nimport { useDrawerSlug, useModal } from \"@payloadcms/ui\";\nimport { createContext, type ReactNode, useContext, useEffect, useState } from \"react\";\nimport { COMMENTS_DRAWER_BASE_SLUG } from \"../../constants\";\n\ninterface PendingField {\n path: string;\n label: string;\n}\n\ninterface CommentsDrawerContextProps {\n slug: string;\n isOpen: boolean;\n scrollTargetPath: string | null;\n pendingField: PendingField | null;\n open: () => void;\n setScrollTargetPath: (path: string | null) => void;\n openForField: (path: string, label: string) => void;\n clearPendingField: () => void;\n}\n\nconst CommentsDrawerContext = createContext<CommentsDrawerContextProps | null>(null);\n\ninterface Props {\n children: ReactNode;\n}\n\nexport function CommentsDrawerProvider({ children }: Props) {\n const [scrollTargetPath, setScrollTargetPath] = useState<string | null>(null);\n const [pendingField, setPendingField] = useState<PendingField | null>(null);\n\n const slug = useDrawerSlug(COMMENTS_DRAWER_BASE_SLUG);\n const { openModal, modalState } = useModal();\n\n const isOpen = modalState[slug]?.isOpen ?? false;\n\n const open = () => {\n openModal(slug);\n };\n\n const openForField = (path: string, label: string) => {\n setScrollTargetPath(path);\n setPendingField({ path, label });\n openModal(slug);\n };\n\n const clearPendingField = () => setPendingField(null);\n\n useEffect(() => {\n if (!isOpen) {\n setPendingField(null);\n }\n }, [isOpen]);\n\n return (\n <CommentsDrawerContext.Provider\n value={{ slug, isOpen, scrollTargetPath, pendingField, open, setScrollTargetPath, openForField, clearPendingField }}>\n {children}\n </CommentsDrawerContext.Provider>\n );\n}\n\nexport function useCommentsDrawer() {\n const context = useContext(CommentsDrawerContext);\n\n if (!context) throw new Error(\"useCommentsDrawer must be used within a CommentsProvider\");\n\n return context;\n}\n"],"mappings":";AAwDI;AAtDJ,SAAS,eAAe,gBAAgB;AACxC,SAAS,eAA+B,YAAY,WAAW,gBAAgB;AAC/E,SAAS,iCAAiC;AAkB1C,MAAM,wBAAwB,cAAiD,IAAI;AAM5E,SAAS,uBAAuB,EAAE,SAAS,GAAU;AAC1D,QAAM,CAAC,kBAAkB,mBAAmB,IAAI,SAAwB,IAAI;AAC5E,QAAM,CAAC,cAAc,eAAe,IAAI,SAA8B,IAAI;AAE1E,QAAM,OAAO,cAAc,yBAAyB;AACpD,QAAM,EAAE,WAAW,WAAW,IAAI,SAAS;AAE3C,QAAM,SAAS,WAAW,IAAI,GAAG,UAAU;AAE3C,QAAM,OAAO,MAAM;AACjB,cAAU,IAAI;AAAA,EAChB;AAEA,QAAM,eAAe,CAAC,MAAc,UAAkB;AACpD,wBAAoB,IAAI;AACxB,oBAAgB,EAAE,MAAM,MAAM,CAAC;AAC/B,cAAU,IAAI;AAAA,EAChB;AAEA,QAAM,oBAAoB,MAAM,gBAAgB,IAAI;AAEpD,YAAU,MAAM;AACd,QAAI,CAAC,QAAQ;AACX,sBAAgB,IAAI;AAAA,IACtB;AAAA,EACF,GAAG,CAAC,MAAM,CAAC;AAEX,SACE;AAAA,IAAC,sBAAsB;AAAA,IAAtB;AAAA,MACC,OAAO,EAAE,MAAM,QAAQ,kBAAkB,cAAc,MAAM,qBAAqB,cAAc,kBAAkB;AAAA,MACjH;AAAA;AAAA,EACH;AAEJ;AAEO,SAAS,oBAAoB;AAClC,QAAM,UAAU,WAAW,qBAAqB;AAEhD,MAAI,CAAC,QAAS,OAAM,IAAI,MAAM,0DAA0D;AAExF,SAAO;AACT;","names":[]}
@@ -1,33 +1,23 @@
1
- import { type Dispatch, type ReactNode, type SetStateAction } from "react";
2
- import type { Comment, EntityLabelsMap, User } from "../../types";
3
- import type { FilterMode, GlobalFieldLabelRegistry, LoadingStatus, DocumentTitles, Mode } from "../../types";
1
+ import { type ReactNode } from "react";
2
+ import type { EntityLabelsMap } from "../../types";
3
+ import type { QueryContext } from "../../types";
4
+ import type { Mode } from "../../types";
4
5
  interface MutationResult {
5
6
  success: boolean;
6
7
  error?: string;
7
8
  }
8
9
  interface CommentsContextProps {
9
- allComments: Comment[];
10
- visibleComments: Comment[];
11
- documentTitles: DocumentTitles;
12
- collectionLabels: EntityLabelsMap;
13
- globalLabels: EntityLabelsMap;
14
10
  mode: Mode;
15
11
  collectionSlug: string | null | undefined;
16
12
  documentId: number | null | undefined;
17
13
  globalSlug: string | null;
18
- mentionUsers: User[];
19
- loadError: boolean;
20
- filter: FilterMode;
21
- fieldLabelRegistry: GlobalFieldLabelRegistry;
22
- syncCommentsStatus: LoadingStatus;
14
+ queryContext: QueryContext;
15
+ collectionLabels: EntityLabelsMap;
16
+ globalLabels: EntityLabelsMap;
23
17
  usernameFieldPath: string | undefined;
24
- setFilter: Dispatch<SetStateAction<FilterMode>>;
25
- hydrateComments: (incoming?: Comment[], incomingTitles?: DocumentTitles, incomingMentionUsers?: User[], fieldLabels?: GlobalFieldLabelRegistry, incomingCollectionLabels?: EntityLabelsMap, nextLoadError?: boolean, incomingGlobalLabels?: EntityLabelsMap) => void;
26
- syncComments: () => Promise<void>;
27
18
  addComment: (text: string, fieldPath?: string | null, documentId?: number, collectionSlug?: string, locale?: string | null, globalSlugOverride?: string) => Promise<MutationResult>;
28
19
  removeComment: (id: string | number) => Promise<MutationResult>;
29
20
  resolveComment: (id: string | number, resolved: boolean) => Promise<MutationResult>;
30
- updateDocumentTitle: (collectionSlug: string, documentId: string, value: string) => void;
31
21
  }
32
22
  interface Props {
33
23
  children: ReactNode;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/CommentsProvider/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,cAAc,EAKpB,MAAM,OAAO,CAAC;AAGf,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAKlE,OAAO,KAAK,EAAE,UAAU,EAAE,wBAAwB,EAAE,aAAa,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,aA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AY,EAAE,YAAY,CAAC;IAC3B,gBAAgB,EAAE,eAAe,CAAC;IAClC,YAAY,EAAE,eAAe,CAAC;IAC9B,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,UAAU,EAAE,CACV,IAAI,EAAE,MAAM,EACZ,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,EACzB,UAAU,CAAC,EAAE,MAAM,EACnB,cAAc,CAAC,EAAE,MAAM,EACvB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,EACtB,kBAAkB,CAAC,EAAE,MAAM,KACxB,OAAO,CAAC,cAAc,CAAC,CAAC;IAC7B,aAAa,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IAChE,cAAc,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,OAAO,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;CACrF;AAID,UAAU,KAAK;IACb,QAAQ,EAAE,SAAS,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,wBAAgB,gBAAgB,CAAC,EAAE,QAAQ,EAAE,iBAAiB,EAAE,EAAE,KAAK,2CA8ItE;AAED,wBAAgB,WAAW,yBAM1B"}
@@ -1,225 +1,134 @@
1
1
  "use client";
2
2
  import { jsx } from "react/jsx-runtime";
3
- import {
4
- createContext,
5
- useCallback,
6
- useContext,
7
- useOptimistic,
8
- useState
9
- } from "react";
10
- import { useAuth, useLocale } from "@payloadcms/ui";
3
+ import { createContext, useCallback, useContext } from "react";
4
+ import { useAuth, useConfig } from "@payloadcms/ui";
11
5
  import { usePathname } from "next/navigation";
12
- import { createComment } from "../../services/createComment";
13
- import { deleteComment } from "../../services/deleteComment";
14
- import { resolveComment as resolveCommentService } from "../../services/resolveComment";
15
- import { syncAllCommentsData } from "../../services/syncAllCommentsData";
16
- import { parseMentionIds } from "../../utils/mention/parseMentionIds";
6
+ import { toQueryContext } from "../../utils/query/toQueryContext";
17
7
  import { defineModeByPathname } from "../../utils/mode/defineModeByPathname";
18
- import { extractVisibleComments } from "../../utils/comment/extractVisibleComments";
19
- function optimisticReducer(state, action) {
20
- switch (action.type) {
21
- case "add":
22
- return [action.comment, ...state];
23
- case "remove":
24
- return state.filter(({ id }) => id !== action.id);
25
- case "update":
26
- return state.map((c) => c.id === action.comment.id ? action.comment : c);
27
- }
28
- }
8
+ import { getEntitiesLabels } from "../../services/getEntitiesLabels";
9
+ import { parseMentionIds } from "../../utils/mention/parseMentionIds";
10
+ import { getDefaultErrorMessage } from "../../utils/error/getDefaultErrorMessage";
11
+ import { useAddCommentMutation } from "../../api/mutations/useAddCommentMutation";
12
+ import { useDeleteCommentMutation } from "../../api/mutations/useDeleteCommentMutation";
13
+ import { useResolveCommentMutation } from "../../api/mutations/useResolveCommentMutation";
29
14
  const CommentsContext = createContext(null);
30
15
  function CommentsProvider({ children, usernameFieldPath }) {
31
16
  const { user } = useAuth();
32
17
  const pathname = usePathname();
33
- const { code: currentLocale } = useLocale();
34
- const [allComments, setAllComments] = useState([]);
35
- const [optimisticComments, applyOptimistic] = useOptimistic(
36
- allComments,
37
- optimisticReducer
38
- );
39
- const [documentTitles, setDocumentTitles] = useState({});
40
- const [collectionLabels, setCollectionLabels] = useState({});
41
- const [globalLabels, setGlobalLabels] = useState({});
42
- const [mentionUsers, setMentionUsers] = useState([]);
43
- const [fieldLabelRegistry, setFieldLabelRegistry] = useState({});
44
- const [filter, setFilter] = useState("open");
45
- const [loadError, setLoadError] = useState(false);
46
- const [syncCommentsStatus, setSyncCommentsStatus] = useState("idle");
18
+ const { config } = useConfig();
47
19
  const { mode, collectionSlug, documentId, globalSlug } = defineModeByPathname(pathname);
48
- const visibleComments = extractVisibleComments({
49
- comments: optimisticComments,
50
- mode,
51
- collectionSlug,
52
- documentId,
53
- globalSlug,
54
- currentLocale
55
- });
56
- const hydrateComments = useCallback(
57
- (incoming, incomingTitles, incomingMentionUsers, fieldLabels, incomingCollectionLabels, nextLoadError = false, incomingGlobalLabels) => {
58
- if (incoming !== void 0) {
59
- setAllComments(incoming);
60
- }
61
- if (incomingTitles) {
62
- setDocumentTitles(incomingTitles);
63
- }
64
- if (incomingMentionUsers) {
65
- setMentionUsers(incomingMentionUsers);
66
- }
67
- if (fieldLabels) {
68
- setFieldLabelRegistry(fieldLabels);
20
+ const queryContext = toQueryContext(mode, collectionSlug, documentId, globalSlug);
21
+ const pluginConfig = config.admin?.custom?.commentsPlugin;
22
+ const collectionLabels = getEntitiesLabels(
23
+ config.collections ?? [],
24
+ pluginConfig?.collections ?? []
25
+ );
26
+ const globalLabels = getEntitiesLabels(
27
+ config.globals ?? [],
28
+ pluginConfig?.globals ?? []
29
+ );
30
+ const addMutation = useAddCommentMutation();
31
+ const deleteMutation = useDeleteCommentMutation();
32
+ const resolveMutation = useResolveCommentMutation();
33
+ const addComment = useCallback(
34
+ async (text, fieldPath, documentIdOverride, collectionSlugOverride, locale, globalSlugOverride) => {
35
+ const resolvedGlobalSlug = globalSlugOverride ?? (mode === "global-document" ? globalSlug : null);
36
+ const resolvedDocId = documentIdOverride ?? documentId;
37
+ const resolvedSlug = collectionSlugOverride ?? collectionSlug;
38
+ if (!resolvedGlobalSlug && (!resolvedDocId || !resolvedSlug)) {
39
+ return {
40
+ success: false,
41
+ error: "No document registered"
42
+ };
69
43
  }
70
- if (incomingCollectionLabels) {
71
- setCollectionLabels(incomingCollectionLabels);
44
+ try {
45
+ const res = await addMutation.mutateAsync({
46
+ ctx: queryContext,
47
+ text,
48
+ fieldPath: fieldPath ?? null,
49
+ documentId: resolvedGlobalSlug ? null : resolvedDocId,
50
+ collectionSlug: resolvedGlobalSlug ? null : resolvedSlug,
51
+ globalSlug: resolvedGlobalSlug ?? null,
52
+ locale: locale ?? null,
53
+ mentionIds: parseMentionIds(text),
54
+ currentUser: user
55
+ });
56
+ if (!res.success)
57
+ return {
58
+ success: false,
59
+ error: res.error
60
+ };
61
+ return { success: true };
62
+ } catch (e) {
63
+ return {
64
+ success: false,
65
+ error: getDefaultErrorMessage(e)
66
+ };
72
67
  }
73
- if (incomingGlobalLabels) {
74
- setGlobalLabels(incomingGlobalLabels);
68
+ },
69
+ [addMutation, mode, globalSlug, documentId, collectionSlug, queryContext, user]
70
+ );
71
+ const removeComment = useCallback(
72
+ async (id) => {
73
+ try {
74
+ const res = await deleteMutation.mutateAsync({
75
+ ctx: queryContext,
76
+ commentId: id
77
+ });
78
+ if (!res.success)
79
+ return {
80
+ success: false,
81
+ error: res.error
82
+ };
83
+ return { success: true };
84
+ } catch (e) {
85
+ return {
86
+ success: false,
87
+ error: getDefaultErrorMessage(e)
88
+ };
75
89
  }
76
- setLoadError(nextLoadError);
77
90
  },
78
- []
91
+ [deleteMutation, queryContext]
79
92
  );
80
- const addComment = async (text, fieldPath, documentIdOverride, collectionSlugOverride, locale, globalSlugOverride) => {
81
- const resolvedGlobalSlug = globalSlugOverride ?? (mode === "global-document" ? globalSlug : null);
82
- const resolvedDocId = documentIdOverride ?? documentId;
83
- const resolvedSlug = collectionSlugOverride ?? collectionSlug;
84
- if (!resolvedGlobalSlug && (!resolvedDocId || !resolvedSlug)) {
85
- return {
86
- success: false,
87
- error: "No document registered"
88
- };
89
- }
90
- const tempId = -Date.now();
91
- const mentionIds = parseMentionIds(text);
92
- const selectedMentionUsers = mentionUsers.filter(({ id }) => mentionIds.includes(id));
93
- const mentions = selectedMentionUsers.map((user2) => ({ id: null, user: user2 }));
94
- const optimisticComment = {
95
- id: tempId,
96
- text,
97
- fieldPath,
98
- locale: locale ?? null,
99
- documentId: resolvedGlobalSlug ? null : resolvedDocId,
100
- collectionSlug: resolvedGlobalSlug ? null : resolvedSlug,
101
- globalSlug: resolvedGlobalSlug ?? null,
102
- isResolved: false,
103
- mentions,
104
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
105
- updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
106
- author: user
107
- };
108
- applyOptimistic({ type: "add", comment: optimisticComment });
109
- const result = await createComment({
110
- documentId: resolvedGlobalSlug ? null : resolvedDocId,
111
- collectionSlug: resolvedGlobalSlug ? null : resolvedSlug,
112
- globalSlug: resolvedGlobalSlug,
113
- text,
114
- fieldPath,
115
- mentionIds,
116
- locale
117
- });
118
- if (result.success) {
119
- applyOptimistic({ type: "remove", id: tempId });
120
- setAllComments((prev) => [result.data, ...prev.filter((c) => c.id !== tempId)]);
121
- return { success: true };
122
- }
123
- return {
124
- success: false,
125
- error: result.error
126
- };
127
- };
128
- const removeComment = async (id) => {
129
- applyOptimistic({ type: "remove", id });
130
- const result = await deleteComment(id);
131
- if (result.success) {
132
- setAllComments((prev) => prev.filter((c) => c.id !== id));
133
- return { success: true };
134
- }
135
- return {
136
- success: false,
137
- error: result.error
138
- };
139
- };
140
- const syncComments = async () => {
141
- setSyncCommentsStatus("loading");
142
- const allCommentsDataResult = await syncAllCommentsData({ locale: currentLocale });
143
- if (!allCommentsDataResult.success) {
144
- setSyncCommentsStatus("error");
145
- return;
146
- }
147
- const {
148
- comments,
149
- documentTitles: documentTitles2,
150
- mentionUsers: mentionUsers2,
151
- fieldLabels,
152
- collectionLabels: syncedLabels,
153
- globalLabels: syncedGlobalLabels
154
- } = allCommentsDataResult.data;
155
- setAllComments((prev) => {
156
- const serverIds = new Set(comments.map((c) => c.id));
157
- const localOnly = prev.filter((c) => c.id > 0 && !serverIds.has(c.id));
158
- return [...localOnly, ...comments];
159
- });
160
- setDocumentTitles(documentTitles2);
161
- setMentionUsers(mentionUsers2);
162
- setFieldLabelRegistry(fieldLabels);
163
- setCollectionLabels(syncedLabels);
164
- setGlobalLabels(syncedGlobalLabels);
165
- setSyncCommentsStatus("success");
166
- };
167
- const resolveComment = async (id, resolved) => {
168
- const existing = optimisticComments.find((c) => c.id === id);
169
- if (existing) {
170
- applyOptimistic({
171
- type: "update",
172
- comment: {
173
- ...existing,
174
- isResolved: resolved
175
- }
176
- });
177
- }
178
- const result = await resolveCommentService(id, resolved);
179
- if (result.success) {
180
- setAllComments((prev) => prev.map((c) => c.id === id ? result.data : c));
181
- return { success: true };
182
- }
183
- return {
184
- success: false,
185
- error: result.error
186
- };
187
- };
188
- const updateDocumentTitle = (collectionSlug2, documentId2, value) => {
189
- setDocumentTitles((prev) => ({
190
- ...prev,
191
- [collectionSlug2]: {
192
- ...prev[collectionSlug2],
193
- [documentId2]: value
93
+ const resolveComment = useCallback(
94
+ async (id, resolved) => {
95
+ try {
96
+ const res = await resolveMutation.mutateAsync({
97
+ ctx: queryContext,
98
+ commentId: id,
99
+ resolved,
100
+ currentUser: user
101
+ });
102
+ if (!res.success)
103
+ return {
104
+ success: false,
105
+ error: res.error
106
+ };
107
+ return { success: true };
108
+ } catch (e) {
109
+ return {
110
+ success: false,
111
+ error: getDefaultErrorMessage(e)
112
+ };
194
113
  }
195
- }));
196
- };
114
+ },
115
+ [resolveMutation, queryContext, user]
116
+ );
197
117
  return /* @__PURE__ */ jsx(
198
118
  CommentsContext.Provider,
199
119
  {
200
120
  value: {
201
- allComments: optimisticComments,
202
- visibleComments,
203
- documentTitles,
204
- collectionLabels,
205
- globalLabels,
206
121
  mode,
207
122
  collectionSlug,
208
123
  documentId,
209
124
  globalSlug,
210
- mentionUsers,
211
- loadError,
212
- filter,
213
- fieldLabelRegistry,
214
- syncCommentsStatus,
125
+ queryContext,
126
+ collectionLabels,
127
+ globalLabels,
215
128
  usernameFieldPath,
216
- setFilter,
217
- hydrateComments,
218
- syncComments,
219
129
  addComment,
220
130
  removeComment,
221
- resolveComment,
222
- updateDocumentTitle
131
+ resolveComment
223
132
  },
224
133
  children
225
134
  }