@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.
- package/dist/api/mutations/useAddCommentMutation.d.ts +18 -0
- package/dist/api/mutations/useAddCommentMutation.d.ts.map +1 -0
- package/dist/api/mutations/useAddCommentMutation.js +52 -0
- package/dist/api/mutations/useAddCommentMutation.js.map +1 -0
- package/dist/api/mutations/useDeleteCommentMutation.d.ts +11 -0
- package/dist/api/mutations/useDeleteCommentMutation.d.ts.map +1 -0
- package/dist/api/mutations/useDeleteCommentMutation.js +31 -0
- package/dist/api/mutations/useDeleteCommentMutation.js.map +1 -0
- package/dist/api/mutations/useResolveCommentMutation.d.ts +13 -0
- package/dist/api/mutations/useResolveCommentMutation.d.ts.map +1 -0
- package/dist/api/mutations/useResolveCommentMutation.js +41 -0
- package/dist/api/mutations/useResolveCommentMutation.js.map +1 -0
- package/dist/api/queries/useCommentsQuery.d.ts +3 -0
- package/dist/api/queries/useCommentsQuery.d.ts.map +1 -0
- package/dist/api/queries/useCommentsQuery.js +40 -0
- package/dist/api/queries/useCommentsQuery.js.map +1 -0
- package/dist/api/queries/useDocumentTitlesQuery.d.ts +3 -0
- package/dist/api/queries/useDocumentTitlesQuery.d.ts.map +1 -0
- package/dist/api/queries/useDocumentTitlesQuery.js +32 -0
- package/dist/api/queries/useDocumentTitlesQuery.js.map +1 -0
- package/dist/api/queries/useFieldLabelsQuery.d.ts +3 -0
- package/dist/api/queries/useFieldLabelsQuery.d.ts.map +1 -0
- package/dist/api/queries/useFieldLabelsQuery.js +23 -0
- package/dist/api/queries/useFieldLabelsQuery.js.map +1 -0
- package/dist/api/queries/useMentionableUsersQuery.d.ts +2 -0
- package/dist/api/queries/useMentionableUsersQuery.d.ts.map +1 -0
- package/dist/api/queries/useMentionableUsersQuery.js +25 -0
- package/dist/api/queries/useMentionableUsersQuery.js.map +1 -0
- package/dist/api/queryKeys.d.ts +23 -0
- package/dist/api/queryKeys.d.ts.map +1 -0
- package/dist/api/queryKeys.js +40 -0
- package/dist/api/queryKeys.js.map +1 -0
- package/dist/components/CommentEditor/index.d.ts.map +1 -1
- package/dist/components/CommentEditor/index.js +5 -3
- package/dist/components/CommentEditor/index.js.map +1 -1
- package/dist/components/CommentItem/StrikethoroughOverlay/clamp.d.ts +2 -0
- package/dist/components/CommentItem/StrikethoroughOverlay/clamp.d.ts.map +1 -0
- package/dist/components/CommentItem/StrikethoroughOverlay/clamp.js +7 -0
- package/dist/components/CommentItem/StrikethoroughOverlay/clamp.js.map +1 -0
- package/dist/components/CommentItem/StrikethoroughOverlay/index.d.ts +8 -0
- package/dist/components/CommentItem/StrikethoroughOverlay/index.d.ts.map +1 -0
- package/dist/components/CommentItem/StrikethoroughOverlay/index.js +24 -0
- package/dist/components/CommentItem/StrikethoroughOverlay/index.js.map +1 -0
- package/dist/components/CommentItem/StrikethoroughOverlay/measureLineRects.d.ts +3 -0
- package/dist/components/CommentItem/StrikethoroughOverlay/measureLineRects.d.ts.map +1 -0
- package/dist/components/CommentItem/StrikethoroughOverlay/measureLineRects.js +29 -0
- package/dist/components/CommentItem/StrikethoroughOverlay/measureLineRects.js.map +1 -0
- package/dist/components/CommentItem/StrikethoroughOverlay/useStrikethroughAnimation.d.ts +7 -0
- package/dist/components/CommentItem/StrikethoroughOverlay/useStrikethroughAnimation.d.ts.map +1 -0
- package/dist/components/CommentItem/StrikethoroughOverlay/useStrikethroughAnimation.js +114 -0
- package/dist/components/CommentItem/StrikethoroughOverlay/useStrikethroughAnimation.js.map +1 -0
- package/dist/components/CommentItem/index.d.ts.map +1 -1
- package/dist/components/CommentItem/index.js +37 -18
- package/dist/components/CommentItem/index.js.map +1 -1
- package/dist/components/CommentsDrawer/components/Header.d.ts.map +1 -1
- package/dist/components/CommentsDrawer/components/Header.js +4 -33
- package/dist/components/CommentsDrawer/components/Header.js.map +1 -1
- package/dist/components/CommentsHeaderButton/index.js +2 -2
- package/dist/components/CommentsHeaderButton/index.js.map +1 -1
- package/dist/components/CommentsPanel/components/CollapsibleGroup.d.ts +7 -2
- package/dist/components/CommentsPanel/components/CollapsibleGroup.d.ts.map +1 -1
- package/dist/components/CommentsPanel/components/CollapsibleGroup.js +7 -2
- package/dist/components/CommentsPanel/components/CollapsibleGroup.js.map +1 -1
- package/dist/components/CommentsPanel/components/DocumentView.d.ts.map +1 -1
- package/dist/components/CommentsPanel/components/DocumentView.js +11 -17
- package/dist/components/CommentsPanel/components/DocumentView.js.map +1 -1
- package/dist/components/CommentsPanel/components/FieldGroupSection.d.ts.map +1 -1
- package/dist/components/CommentsPanel/components/FieldGroupSection.js +44 -22
- package/dist/components/CommentsPanel/components/FieldGroupSection.js.map +1 -1
- package/dist/components/CommentsPanel/components/GlobalDocumentView.d.ts.map +1 -1
- package/dist/components/CommentsPanel/components/GlobalDocumentView.js +3 -9
- package/dist/components/CommentsPanel/components/GlobalDocumentView.js.map +1 -1
- package/dist/components/CommentsPanel/components/GlobalView.d.ts.map +1 -1
- package/dist/components/CommentsPanel/components/GlobalView.js +38 -41
- package/dist/components/CommentsPanel/components/GlobalView.js.map +1 -1
- package/dist/components/CommentsPanel/hooks/useCollapseState.d.ts +1 -1
- package/dist/components/CommentsPanel/hooks/useCollapseState.d.ts.map +1 -1
- package/dist/components/CommentsPanel/hooks/useCollapseState.js +4 -1
- package/dist/components/CommentsPanel/hooks/useCollapseState.js.map +1 -1
- package/dist/components/CommentsPanel/index.d.ts.map +1 -1
- package/dist/components/CommentsPanel/index.js +14 -11
- package/dist/components/CommentsPanel/index.js.map +1 -1
- package/dist/components/FieldCommentLabel/hooks/useFieldBreadcrumb.d.ts +2 -0
- package/dist/components/FieldCommentLabel/hooks/useFieldBreadcrumb.d.ts.map +1 -0
- package/dist/components/FieldCommentLabel/hooks/useFieldBreadcrumb.js +52 -0
- package/dist/components/FieldCommentLabel/hooks/useFieldBreadcrumb.js.map +1 -0
- package/dist/components/FieldCommentLabel/index.d.ts.map +1 -1
- package/dist/components/FieldCommentLabel/index.js +53 -41
- package/dist/components/FieldCommentLabel/index.js.map +1 -1
- package/dist/components/FieldCommentLabel/utils/exludeComments.js +2 -2
- package/dist/components/FieldCommentLabel/utils/exludeComments.js.map +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +3 -4
- package/dist/constants.js.map +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +6 -2
- package/dist/plugin.js.map +1 -1
- package/dist/providers/CommentsDrawerProvider/index.d.ts +8 -0
- package/dist/providers/CommentsDrawerProvider/index.d.ts.map +1 -1
- package/dist/providers/CommentsDrawerProvider/index.js +22 -6
- package/dist/providers/CommentsDrawerProvider/index.js.map +1 -1
- package/dist/providers/CommentsProvider/index.d.ts +7 -17
- package/dist/providers/CommentsProvider/index.d.ts.map +1 -1
- package/dist/providers/CommentsProvider/index.js +105 -196
- package/dist/providers/CommentsProvider/index.js.map +1 -1
- package/dist/providers/CommentsProviderWrapper/index.d.ts +1 -1
- package/dist/providers/CommentsProviderWrapper/index.d.ts.map +1 -1
- package/dist/providers/CommentsProviderWrapper/index.js +11 -1
- package/dist/providers/CommentsProviderWrapper/index.js.map +1 -1
- package/dist/services/findAllComments.d.ts +4 -1
- package/dist/services/findAllComments.d.ts.map +1 -1
- package/dist/services/findAllComments.js +36 -10
- package/dist/services/findAllComments.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/translations/en.d.ts.map +1 -1
- package/dist/translations/en.js +3 -7
- package/dist/translations/en.js.map +1 -1
- package/dist/translations/types.d.ts +2 -6
- package/dist/translations/types.d.ts.map +1 -1
- package/dist/types/general.d.ts +0 -2
- package/dist/types/general.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/query.d.ts +11 -0
- package/dist/types/query.d.ts.map +1 -0
- package/dist/types/query.js +1 -0
- package/dist/types/query.js.map +1 -0
- package/dist/utils/query/toQueryContext.d.ts +3 -0
- package/dist/utils/query/toQueryContext.d.ts.map +1 -0
- package/dist/utils/query/toQueryContext.js +20 -0
- package/dist/utils/query/toQueryContext.js.map +1 -0
- package/package.json +2 -5
- package/dist/components/CommentsPanel/constants.d.ts +0 -3
- package/dist/components/CommentsPanel/constants.d.ts.map +0 -1
- package/dist/components/CommentsPanel/constants.js +0 -9
- package/dist/components/CommentsPanel/constants.js.map +0 -1
- package/dist/components/CommentsPanel/utils/filterComments.d.ts +0 -9
- package/dist/components/CommentsPanel/utils/filterComments.d.ts.map +0 -1
- package/dist/components/CommentsPanel/utils/filterComments.js +0 -17
- package/dist/components/CommentsPanel/utils/filterComments.js.map +0 -1
- package/dist/components/FieldCommentLabel/AddCommentPopup.d.ts +0 -8
- package/dist/components/FieldCommentLabel/AddCommentPopup.d.ts.map +0 -1
- package/dist/components/FieldCommentLabel/AddCommentPopup.js +0 -50
- package/dist/components/FieldCommentLabel/AddCommentPopup.js.map +0 -1
- package/dist/providers/GlobalCommentsLoader/GlobalCommentsHydrator.d.ts +0 -13
- package/dist/providers/GlobalCommentsLoader/GlobalCommentsHydrator.d.ts.map +0 -1
- package/dist/providers/GlobalCommentsLoader/GlobalCommentsHydrator.js +0 -22
- package/dist/providers/GlobalCommentsLoader/GlobalCommentsHydrator.js.map +0 -1
- package/dist/providers/GlobalCommentsLoader/index.d.ts +0 -10
- package/dist/providers/GlobalCommentsLoader/index.d.ts.map +0 -1
- package/dist/providers/GlobalCommentsLoader/index.js +0 -31
- package/dist/providers/GlobalCommentsLoader/index.js.map +0 -1
- package/dist/services/syncAllCommentsData.d.ts +0 -12
- package/dist/services/syncAllCommentsData.d.ts.map +0 -1
- package/dist/services/syncAllCommentsData.js +0 -48
- package/dist/services/syncAllCommentsData.js.map +0 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Comment, QueryContext } from "../../types";
|
|
2
|
+
interface AddCommentVariables {
|
|
3
|
+
ctx: QueryContext;
|
|
4
|
+
text: string;
|
|
5
|
+
fieldPath?: string | null;
|
|
6
|
+
documentId?: number | null;
|
|
7
|
+
collectionSlug?: string | null;
|
|
8
|
+
globalSlug?: string | null;
|
|
9
|
+
locale?: string | null;
|
|
10
|
+
mentionIds: number[];
|
|
11
|
+
currentUser: Comment["author"];
|
|
12
|
+
}
|
|
13
|
+
export declare function useAddCommentMutation(): import("@tanstack/react-query").UseMutationResult<import("../../types").Response<Comment>, Error, AddCommentVariables, {
|
|
14
|
+
snapshot: Comment[] | undefined;
|
|
15
|
+
ctx: QueryContext;
|
|
16
|
+
}>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=useAddCommentMutation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAddCommentMutation.d.ts","sourceRoot":"","sources":["../../../src/api/mutations/useAddCommentMutation.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAQ,YAAY,EAAE,MAAM,aAAa,CAAC;AAE/D,UAAU,mBAAmB;IAC3B,GAAG,EAAE,YAAY,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;CAChC;AAED,wBAAgB,qBAAqB;;;GAqDpC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { getCommentsKey, getFieldLabelsKey, getDocumentTitlesKey, QUERY_KEYS } from "../queryKeys";
|
|
4
|
+
import { createComment } from "../../services/createComment";
|
|
5
|
+
function useAddCommentMutation() {
|
|
6
|
+
const queryClient = useQueryClient();
|
|
7
|
+
return useMutation({
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
9
|
+
mutationFn: ({ ctx: _ctx, currentUser: _user, ...data }) => createComment(data),
|
|
10
|
+
onMutate: async (variables) => {
|
|
11
|
+
const { ctx, text, fieldPath, documentId, collectionSlug, globalSlug, locale, mentionIds, currentUser } = variables;
|
|
12
|
+
const key = getCommentsKey(ctx);
|
|
13
|
+
await queryClient.cancelQueries({ queryKey: key });
|
|
14
|
+
const snapshot = queryClient.getQueryData(key);
|
|
15
|
+
const cachedUsers = queryClient.getQueryData(QUERY_KEYS.mentionableUsers()) ?? [];
|
|
16
|
+
const selectedUsers = cachedUsers.filter(({ id }) => mentionIds.includes(id));
|
|
17
|
+
const mentions = selectedUsers.map((user) => ({ id: null, user }));
|
|
18
|
+
const optimisticComment = {
|
|
19
|
+
id: -Date.now(),
|
|
20
|
+
text,
|
|
21
|
+
fieldPath: fieldPath ?? null,
|
|
22
|
+
locale,
|
|
23
|
+
documentId: documentId ?? null,
|
|
24
|
+
collectionSlug: collectionSlug ?? null,
|
|
25
|
+
globalSlug: globalSlug ?? null,
|
|
26
|
+
isResolved: false,
|
|
27
|
+
mentions,
|
|
28
|
+
author: currentUser,
|
|
29
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
30
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
31
|
+
};
|
|
32
|
+
queryClient.setQueryData(key, (prev = []) => [optimisticComment, ...prev]);
|
|
33
|
+
return { snapshot, ctx };
|
|
34
|
+
},
|
|
35
|
+
onError: (_err, _vars, context) => {
|
|
36
|
+
if (context?.snapshot !== void 0) {
|
|
37
|
+
queryClient.setQueryData(getCommentsKey(context.ctx), context.snapshot);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
onSettled: (_data, _err, _vars, context) => {
|
|
41
|
+
if (!context?.ctx) return;
|
|
42
|
+
const ctx = context.ctx;
|
|
43
|
+
queryClient.invalidateQueries({ queryKey: getCommentsKey(ctx) });
|
|
44
|
+
queryClient.invalidateQueries({ queryKey: getFieldLabelsKey(ctx) });
|
|
45
|
+
queryClient.invalidateQueries({ queryKey: getDocumentTitlesKey(ctx) });
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
useAddCommentMutation
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=useAddCommentMutation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/api/mutations/useAddCommentMutation.ts"],"sourcesContent":["\"use client\";\n\nimport { useMutation, useQueryClient } from \"@tanstack/react-query\";\nimport { getCommentsKey, getFieldLabelsKey, getDocumentTitlesKey, QUERY_KEYS } from \"../queryKeys\";\nimport { createComment } from \"../../services/createComment\";\nimport type { Comment, User, QueryContext } from \"../../types\";\n\ninterface AddCommentVariables {\n ctx: QueryContext;\n text: string;\n fieldPath?: string | null;\n documentId?: number | null;\n collectionSlug?: string | null;\n globalSlug?: string | null;\n locale?: string | null;\n mentionIds: number[];\n currentUser: Comment[\"author\"];\n}\n\nexport function useAddCommentMutation() {\n const queryClient = useQueryClient();\n\n return useMutation({\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n mutationFn: ({ ctx: _ctx, currentUser: _user, ...data }: AddCommentVariables) => createComment(data),\n onMutate: async (variables) => {\n const { ctx, text, fieldPath, documentId, collectionSlug, globalSlug, locale, mentionIds, currentUser } =\n variables;\n\n const key = getCommentsKey(ctx);\n\n await queryClient.cancelQueries({ queryKey: key });\n const snapshot = queryClient.getQueryData<Comment[]>(key);\n\n const cachedUsers = queryClient.getQueryData<User[]>(QUERY_KEYS.mentionableUsers()) ?? [];\n const selectedUsers = cachedUsers.filter(({ id }) => mentionIds.includes(id));\n const mentions = selectedUsers.map((user) => ({ id: null, user }));\n\n const optimisticComment: Comment = {\n id: -Date.now(),\n text,\n fieldPath: fieldPath ?? null,\n locale,\n documentId: documentId ?? null,\n collectionSlug: collectionSlug ?? null,\n globalSlug: globalSlug ?? null,\n isResolved: false,\n mentions,\n author: currentUser,\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n };\n\n queryClient.setQueryData<Comment[]>(key, (prev = []) => [optimisticComment, ...prev]);\n\n return { snapshot, ctx };\n },\n onError: (_err, _vars, context) => {\n if (context?.snapshot !== undefined) {\n queryClient.setQueryData(getCommentsKey(context.ctx), context.snapshot);\n }\n },\n onSettled: (_data, _err, _vars, context) => {\n if (!context?.ctx) return;\n\n const ctx = context.ctx;\n\n queryClient.invalidateQueries({ queryKey: getCommentsKey(ctx) });\n queryClient.invalidateQueries({ queryKey: getFieldLabelsKey(ctx) });\n queryClient.invalidateQueries({ queryKey: getDocumentTitlesKey(ctx) });\n },\n });\n}\n"],"mappings":";AAEA,SAAS,aAAa,sBAAsB;AAC5C,SAAS,gBAAgB,mBAAmB,sBAAsB,kBAAkB;AACpF,SAAS,qBAAqB;AAevB,SAAS,wBAAwB;AACtC,QAAM,cAAc,eAAe;AAEnC,SAAO,YAAY;AAAA;AAAA,IAEjB,YAAY,CAAC,EAAE,KAAK,MAAM,aAAa,OAAO,GAAG,KAAK,MAA2B,cAAc,IAAI;AAAA,IACnG,UAAU,OAAO,cAAc;AAC7B,YAAM,EAAE,KAAK,MAAM,WAAW,YAAY,gBAAgB,YAAY,QAAQ,YAAY,YAAY,IACpG;AAEF,YAAM,MAAM,eAAe,GAAG;AAE9B,YAAM,YAAY,cAAc,EAAE,UAAU,IAAI,CAAC;AACjD,YAAM,WAAW,YAAY,aAAwB,GAAG;AAExD,YAAM,cAAc,YAAY,aAAqB,WAAW,iBAAiB,CAAC,KAAK,CAAC;AACxF,YAAM,gBAAgB,YAAY,OAAO,CAAC,EAAE,GAAG,MAAM,WAAW,SAAS,EAAE,CAAC;AAC5E,YAAM,WAAW,cAAc,IAAI,CAAC,UAAU,EAAE,IAAI,MAAM,KAAK,EAAE;AAEjE,YAAM,oBAA6B;AAAA,QACjC,IAAI,CAAC,KAAK,IAAI;AAAA,QACd;AAAA,QACA,WAAW,aAAa;AAAA,QACxB;AAAA,QACA,YAAY,cAAc;AAAA,QAC1B,gBAAgB,kBAAkB;AAAA,QAClC,YAAY,cAAc;AAAA,QAC1B,YAAY;AAAA,QACZ;AAAA,QACA,QAAQ;AAAA,QACR,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,QAClC,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,MACpC;AAEA,kBAAY,aAAwB,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,mBAAmB,GAAG,IAAI,CAAC;AAEpF,aAAO,EAAE,UAAU,IAAI;AAAA,IACzB;AAAA,IACA,SAAS,CAAC,MAAM,OAAO,YAAY;AACjC,UAAI,SAAS,aAAa,QAAW;AACnC,oBAAY,aAAa,eAAe,QAAQ,GAAG,GAAG,QAAQ,QAAQ;AAAA,MACxE;AAAA,IACF;AAAA,IACA,WAAW,CAAC,OAAO,MAAM,OAAO,YAAY;AAC1C,UAAI,CAAC,SAAS,IAAK;AAEnB,YAAM,MAAM,QAAQ;AAEpB,kBAAY,kBAAkB,EAAE,UAAU,eAAe,GAAG,EAAE,CAAC;AAC/D,kBAAY,kBAAkB,EAAE,UAAU,kBAAkB,GAAG,EAAE,CAAC;AAClE,kBAAY,kBAAkB,EAAE,UAAU,qBAAqB,GAAG,EAAE,CAAC;AAAA,IACvE;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Comment, QueryContext } from "../../types";
|
|
2
|
+
interface DeleteCommentVariables {
|
|
3
|
+
ctx: QueryContext;
|
|
4
|
+
commentId: string | number;
|
|
5
|
+
}
|
|
6
|
+
export declare function useDeleteCommentMutation(): import("@tanstack/react-query").UseMutationResult<import("../../types").Response<Comment>, Error, DeleteCommentVariables, {
|
|
7
|
+
snapshot: Comment[] | undefined;
|
|
8
|
+
ctx: QueryContext;
|
|
9
|
+
}>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=useDeleteCommentMutation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDeleteCommentMutation.d.ts","sourceRoot":"","sources":["../../../src/api/mutations/useDeleteCommentMutation.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEzD,UAAU,sBAAsB;IAC9B,GAAG,EAAE,YAAY,CAAC;IAClB,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;CAC5B;AAED,wBAAgB,wBAAwB;;;GA2BvC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { getCommentsKey } from "../queryKeys";
|
|
4
|
+
import { deleteComment } from "../../services/deleteComment";
|
|
5
|
+
function useDeleteCommentMutation() {
|
|
6
|
+
const queryClient = useQueryClient();
|
|
7
|
+
return useMutation({
|
|
8
|
+
mutationFn: ({ commentId }) => deleteComment(commentId),
|
|
9
|
+
onMutate: async (variables) => {
|
|
10
|
+
const { ctx, commentId } = variables;
|
|
11
|
+
const key = getCommentsKey(ctx);
|
|
12
|
+
await queryClient.cancelQueries({ queryKey: key });
|
|
13
|
+
const snapshot = queryClient.getQueryData(key);
|
|
14
|
+
queryClient.setQueryData(key, (prev = []) => prev.filter((c) => c.id !== commentId));
|
|
15
|
+
return { snapshot, ctx };
|
|
16
|
+
},
|
|
17
|
+
onError: (_err, _vars, context) => {
|
|
18
|
+
if (context?.snapshot !== void 0) {
|
|
19
|
+
queryClient.setQueryData(getCommentsKey(context.ctx), context.snapshot);
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
onSettled: (_data, _err, _vars, context) => {
|
|
23
|
+
if (!context?.ctx) return;
|
|
24
|
+
queryClient.invalidateQueries({ queryKey: getCommentsKey(context.ctx) });
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
useDeleteCommentMutation
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=useDeleteCommentMutation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/api/mutations/useDeleteCommentMutation.ts"],"sourcesContent":["\"use client\";\n\nimport { useMutation, useQueryClient } from \"@tanstack/react-query\";\nimport { getCommentsKey } from \"../queryKeys\";\nimport { deleteComment } from \"../../services/deleteComment\";\nimport type { Comment, QueryContext } from \"../../types\";\n\ninterface DeleteCommentVariables {\n ctx: QueryContext;\n commentId: string | number;\n}\n\nexport function useDeleteCommentMutation() {\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: ({ commentId }: DeleteCommentVariables) => deleteComment(commentId),\n onMutate: async (variables) => {\n const { ctx, commentId } = variables;\n const key = getCommentsKey(ctx);\n\n await queryClient.cancelQueries({ queryKey: key });\n const snapshot = queryClient.getQueryData<Comment[]>(key);\n\n queryClient.setQueryData<Comment[]>(key, (prev = []) => prev.filter((c) => c.id !== commentId));\n\n return { snapshot, ctx };\n },\n onError: (_err, _vars, context) => {\n if (context?.snapshot !== undefined) {\n queryClient.setQueryData(getCommentsKey(context.ctx), context.snapshot);\n }\n },\n onSettled: (_data, _err, _vars, context) => {\n if (!context?.ctx) return;\n\n queryClient.invalidateQueries({ queryKey: getCommentsKey(context.ctx) });\n },\n });\n}\n"],"mappings":";AAEA,SAAS,aAAa,sBAAsB;AAC5C,SAAS,sBAAsB;AAC/B,SAAS,qBAAqB;AAQvB,SAAS,2BAA2B;AACzC,QAAM,cAAc,eAAe;AAEnC,SAAO,YAAY;AAAA,IACjB,YAAY,CAAC,EAAE,UAAU,MAA8B,cAAc,SAAS;AAAA,IAC9E,UAAU,OAAO,cAAc;AAC7B,YAAM,EAAE,KAAK,UAAU,IAAI;AAC3B,YAAM,MAAM,eAAe,GAAG;AAE9B,YAAM,YAAY,cAAc,EAAE,UAAU,IAAI,CAAC;AACjD,YAAM,WAAW,YAAY,aAAwB,GAAG;AAExD,kBAAY,aAAwB,KAAK,CAAC,OAAO,CAAC,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,OAAO,SAAS,CAAC;AAE9F,aAAO,EAAE,UAAU,IAAI;AAAA,IACzB;AAAA,IACA,SAAS,CAAC,MAAM,OAAO,YAAY;AACjC,UAAI,SAAS,aAAa,QAAW;AACnC,oBAAY,aAAa,eAAe,QAAQ,GAAG,GAAG,QAAQ,QAAQ;AAAA,MACxE;AAAA,IACF;AAAA,IACA,WAAW,CAAC,OAAO,MAAM,OAAO,YAAY;AAC1C,UAAI,CAAC,SAAS,IAAK;AAEnB,kBAAY,kBAAkB,EAAE,UAAU,eAAe,QAAQ,GAAG,EAAE,CAAC;AAAA,IACzE;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Comment, QueryContext } from "../../types";
|
|
2
|
+
interface ResolveCommentVariables {
|
|
3
|
+
ctx: QueryContext;
|
|
4
|
+
commentId: string | number;
|
|
5
|
+
resolved: boolean;
|
|
6
|
+
currentUser: Comment["author"];
|
|
7
|
+
}
|
|
8
|
+
export declare function useResolveCommentMutation(): import("@tanstack/react-query").UseMutationResult<import("../../types").Response<Comment>, Error, ResolveCommentVariables, {
|
|
9
|
+
snapshot: Comment[] | undefined;
|
|
10
|
+
ctx: QueryContext;
|
|
11
|
+
}>;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=useResolveCommentMutation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useResolveCommentMutation.d.ts","sourceRoot":"","sources":["../../../src/api/mutations/useResolveCommentMutation.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEzD,UAAU,uBAAuB;IAC/B,GAAG,EAAE,YAAY,CAAC;IAClB,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;CAChC;AAED,wBAAgB,yBAAyB;;;GAsCxC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { getCommentsKey } from "../queryKeys";
|
|
4
|
+
import { resolveComment } from "../../services/resolveComment";
|
|
5
|
+
function useResolveCommentMutation() {
|
|
6
|
+
const queryClient = useQueryClient();
|
|
7
|
+
return useMutation({
|
|
8
|
+
mutationFn: ({ commentId, resolved }) => resolveComment(commentId, resolved),
|
|
9
|
+
onMutate: async (variables) => {
|
|
10
|
+
const { ctx, commentId, resolved, currentUser } = variables;
|
|
11
|
+
const key = getCommentsKey(ctx);
|
|
12
|
+
await queryClient.cancelQueries({ queryKey: key });
|
|
13
|
+
const snapshot = queryClient.getQueryData(key);
|
|
14
|
+
queryClient.setQueryData(
|
|
15
|
+
key,
|
|
16
|
+
(prev = []) => prev.map(
|
|
17
|
+
(c) => c.id === commentId ? {
|
|
18
|
+
...c,
|
|
19
|
+
isResolved: resolved,
|
|
20
|
+
resolvedAt: resolved ? (/* @__PURE__ */ new Date()).toISOString() : null,
|
|
21
|
+
resolvedBy: resolved ? currentUser : null
|
|
22
|
+
} : c
|
|
23
|
+
)
|
|
24
|
+
);
|
|
25
|
+
return { snapshot, ctx };
|
|
26
|
+
},
|
|
27
|
+
onError: (_err, _vars, context) => {
|
|
28
|
+
if (context?.snapshot !== void 0) {
|
|
29
|
+
queryClient.setQueryData(getCommentsKey(context.ctx), context.snapshot);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
onSettled: (_data, _err, _vars, context) => {
|
|
33
|
+
if (!context?.ctx) return;
|
|
34
|
+
void queryClient.invalidateQueries({ queryKey: getCommentsKey(context.ctx) });
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
useResolveCommentMutation
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=useResolveCommentMutation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/api/mutations/useResolveCommentMutation.ts"],"sourcesContent":["\"use client\";\n\nimport { useMutation, useQueryClient } from \"@tanstack/react-query\";\nimport { getCommentsKey } from \"../queryKeys\";\nimport { resolveComment } from \"../../services/resolveComment\";\nimport type { Comment, QueryContext } from \"../../types\";\n\ninterface ResolveCommentVariables {\n ctx: QueryContext;\n commentId: string | number;\n resolved: boolean;\n currentUser: Comment[\"author\"];\n}\n\nexport function useResolveCommentMutation() {\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: ({ commentId, resolved }: ResolveCommentVariables) => resolveComment(commentId, resolved),\n onMutate: async (variables) => {\n const { ctx, commentId, resolved, currentUser } = variables;\n const key = getCommentsKey(ctx);\n\n await queryClient.cancelQueries({ queryKey: key });\n const snapshot = queryClient.getQueryData<Comment[]>(key);\n\n queryClient.setQueryData<Comment[]>(key, (prev = []) =>\n prev.map((c) =>\n c.id === commentId ?\n {\n ...c,\n isResolved: resolved,\n resolvedAt: resolved ? new Date().toISOString() : null,\n resolvedBy: resolved ? currentUser : null,\n }\n : c,\n ),\n );\n\n return { snapshot, ctx };\n },\n onError: (_err, _vars, context) => {\n if (context?.snapshot !== undefined) {\n queryClient.setQueryData(getCommentsKey(context.ctx), context.snapshot);\n }\n },\n onSettled: (_data, _err, _vars, context) => {\n if (!context?.ctx) return;\n\n void queryClient.invalidateQueries({ queryKey: getCommentsKey(context.ctx) });\n },\n });\n}\n"],"mappings":";AAEA,SAAS,aAAa,sBAAsB;AAC5C,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAUxB,SAAS,4BAA4B;AAC1C,QAAM,cAAc,eAAe;AAEnC,SAAO,YAAY;AAAA,IACjB,YAAY,CAAC,EAAE,WAAW,SAAS,MAA+B,eAAe,WAAW,QAAQ;AAAA,IACpG,UAAU,OAAO,cAAc;AAC7B,YAAM,EAAE,KAAK,WAAW,UAAU,YAAY,IAAI;AAClD,YAAM,MAAM,eAAe,GAAG;AAE9B,YAAM,YAAY,cAAc,EAAE,UAAU,IAAI,CAAC;AACjD,YAAM,WAAW,YAAY,aAAwB,GAAG;AAExD,kBAAY;AAAA,QAAwB;AAAA,QAAK,CAAC,OAAO,CAAC,MAChD,KAAK;AAAA,UAAI,CAAC,MACR,EAAE,OAAO,YACP;AAAA,YACE,GAAG;AAAA,YACH,YAAY;AAAA,YACZ,YAAY,YAAW,oBAAI,KAAK,GAAE,YAAY,IAAI;AAAA,YAClD,YAAY,WAAW,cAAc;AAAA,UACvC,IACA;AAAA,QACJ;AAAA,MACF;AAEA,aAAO,EAAE,UAAU,IAAI;AAAA,IACzB;AAAA,IACA,SAAS,CAAC,MAAM,OAAO,YAAY;AACjC,UAAI,SAAS,aAAa,QAAW;AACnC,oBAAY,aAAa,eAAe,QAAQ,GAAG,GAAG,QAAQ,QAAQ;AAAA,MACxE;AAAA,IACF;AAAA,IACA,WAAW,CAAC,OAAO,MAAM,OAAO,YAAY;AAC1C,UAAI,CAAC,SAAS,IAAK;AAEnB,WAAK,YAAY,kBAAkB,EAAE,UAAU,eAAe,QAAQ,GAAG,EAAE,CAAC;AAAA,IAC9E;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCommentsQuery.d.ts","sourceRoot":"","sources":["../../../src/api/queries/useCommentsQuery.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,0FAqCjD"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useQuery } from "@tanstack/react-query";
|
|
3
|
+
import { useConfig } from "@payloadcms/ui";
|
|
4
|
+
import { getCommentsKey } from "../queryKeys";
|
|
5
|
+
import { findAllComments } from "../../services/findAllComments";
|
|
6
|
+
import { useCommentsDrawer } from "../../providers/CommentsDrawerProvider";
|
|
7
|
+
import { REFETCH_INTERVAL } from "../../constants";
|
|
8
|
+
function useCommentsQuery(ctx) {
|
|
9
|
+
const { isOpen } = useCommentsDrawer();
|
|
10
|
+
const { config } = useConfig();
|
|
11
|
+
const pluginConfig = config.admin?.custom?.commentsPlugin;
|
|
12
|
+
return useQuery({
|
|
13
|
+
queryKey: getCommentsKey(ctx),
|
|
14
|
+
queryFn: async () => {
|
|
15
|
+
const params = ctx.mode === "doc" ? {
|
|
16
|
+
enabledCollections: pluginConfig?.collections,
|
|
17
|
+
enabledGlobals: pluginConfig?.globals,
|
|
18
|
+
docId: ctx.docId,
|
|
19
|
+
filterCollectionSlug: ctx.collectionSlug
|
|
20
|
+
} : ctx.mode === "global-doc" ? {
|
|
21
|
+
enabledCollections: pluginConfig?.collections,
|
|
22
|
+
enabledGlobals: pluginConfig?.globals,
|
|
23
|
+
filterGlobalSlug: ctx.globalSlug
|
|
24
|
+
} : {
|
|
25
|
+
enabledCollections: pluginConfig?.collections,
|
|
26
|
+
enabledGlobals: pluginConfig?.globals
|
|
27
|
+
};
|
|
28
|
+
const res = await findAllComments(params);
|
|
29
|
+
if (!res.success) throw new Error(res.error);
|
|
30
|
+
return res.data;
|
|
31
|
+
},
|
|
32
|
+
staleTime: 0,
|
|
33
|
+
refetchInterval: isOpen ? REFETCH_INTERVAL : false,
|
|
34
|
+
refetchIntervalInBackground: false
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
useCommentsQuery
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=useCommentsQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/api/queries/useCommentsQuery.ts"],"sourcesContent":["\"use client\";\n\nimport { useQuery } from \"@tanstack/react-query\";\nimport { useConfig } from \"@payloadcms/ui\";\nimport { getCommentsKey } from \"../queryKeys\";\nimport { findAllComments } from \"../../services/findAllComments\";\nimport { useCommentsDrawer } from \"../../providers/CommentsDrawerProvider\";\nimport type { QueryContext } from \"../../types\";\nimport type { CommentsPluginConfigStorage } from \"../../types\";\nimport { REFETCH_INTERVAL } from \"../../constants\";\n\nexport function useCommentsQuery(ctx: QueryContext) {\n const { isOpen } = useCommentsDrawer();\n const { config } = useConfig();\n const pluginConfig = config.admin?.custom?.commentsPlugin as CommentsPluginConfigStorage | undefined;\n\n return useQuery({\n queryKey: getCommentsKey(ctx),\n queryFn: async () => {\n const params =\n ctx.mode === \"doc\" ?\n {\n enabledCollections: pluginConfig?.collections,\n enabledGlobals: pluginConfig?.globals,\n docId: ctx.docId,\n filterCollectionSlug: ctx.collectionSlug,\n }\n : ctx.mode === \"global-doc\" ?\n {\n enabledCollections: pluginConfig?.collections,\n enabledGlobals: pluginConfig?.globals,\n filterGlobalSlug: ctx.globalSlug,\n }\n : {\n enabledCollections: pluginConfig?.collections,\n enabledGlobals: pluginConfig?.globals,\n };\n\n const res = await findAllComments(params);\n\n if (!res.success) throw new Error(res.error);\n \n return res.data;\n },\n staleTime: 0,\n refetchInterval: isOpen ? REFETCH_INTERVAL : false,\n refetchIntervalInBackground: false,\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAC1B,SAAS,sBAAsB;AAC/B,SAAS,uBAAuB;AAChC,SAAS,yBAAyB;AAGlC,SAAS,wBAAwB;AAE1B,SAAS,iBAAiB,KAAmB;AAClD,QAAM,EAAE,OAAO,IAAI,kBAAkB;AACrC,QAAM,EAAE,OAAO,IAAI,UAAU;AAC7B,QAAM,eAAe,OAAO,OAAO,QAAQ;AAE3C,SAAO,SAAS;AAAA,IACd,UAAU,eAAe,GAAG;AAAA,IAC5B,SAAS,YAAY;AACnB,YAAM,SACJ,IAAI,SAAS,QACX;AAAA,QACE,oBAAoB,cAAc;AAAA,QAClC,gBAAgB,cAAc;AAAA,QAC9B,OAAO,IAAI;AAAA,QACX,sBAAsB,IAAI;AAAA,MAC5B,IACA,IAAI,SAAS,eACb;AAAA,QACE,oBAAoB,cAAc;AAAA,QAClC,gBAAgB,cAAc;AAAA,QAC9B,kBAAkB,IAAI;AAAA,MACxB,IACA;AAAA,QACE,oBAAoB,cAAc;AAAA,QAClC,gBAAgB,cAAc;AAAA,MAChC;AAEJ,YAAM,MAAM,MAAM,gBAAgB,MAAM;AAExC,UAAI,CAAC,IAAI,QAAS,OAAM,IAAI,MAAM,IAAI,KAAK;AAE3C,aAAO,IAAI;AAAA,IACb;AAAA,IACA,WAAW;AAAA,IACX,iBAAiB,SAAS,mBAAmB;AAAA,IAC7C,6BAA6B;AAAA,EAC/B,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDocumentTitlesQuery.d.ts","sourceRoot":"","sources":["../../../src/api/queries/useDocumentTitlesQuery.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,YAAY,+FAsBvD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useQuery } from "@tanstack/react-query";
|
|
3
|
+
import { useConfig } from "@payloadcms/ui";
|
|
4
|
+
import { useLocale } from "@payloadcms/ui";
|
|
5
|
+
import { getDocumentTitlesKey } from "../queryKeys";
|
|
6
|
+
import { getDocumentTitles } from "../../services/getDocumentTitles";
|
|
7
|
+
import { useCommentsDrawer } from "../../providers/CommentsDrawerProvider";
|
|
8
|
+
import { useCommentsQuery } from "./useCommentsQuery";
|
|
9
|
+
import { REFETCH_INTERVAL } from "../../constants";
|
|
10
|
+
function useDocumentTitlesQuery(ctx) {
|
|
11
|
+
const { isOpen } = useCommentsDrawer();
|
|
12
|
+
const { data: comments } = useCommentsQuery(ctx);
|
|
13
|
+
const { code: locale } = useLocale();
|
|
14
|
+
const { config } = useConfig();
|
|
15
|
+
const pluginConfig = config.admin?.custom?.commentsPlugin;
|
|
16
|
+
return useQuery({
|
|
17
|
+
queryKey: getDocumentTitlesKey(ctx),
|
|
18
|
+
queryFn: async () => {
|
|
19
|
+
const res = await getDocumentTitles(comments ?? [], pluginConfig?.documentTitleFields ?? {}, { locale });
|
|
20
|
+
if (!res.success) throw new Error(res.error);
|
|
21
|
+
return res.data;
|
|
22
|
+
},
|
|
23
|
+
enabled: isOpen && !!comments,
|
|
24
|
+
staleTime: 0,
|
|
25
|
+
refetchInterval: isOpen ? REFETCH_INTERVAL : false,
|
|
26
|
+
refetchIntervalInBackground: false
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
useDocumentTitlesQuery
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=useDocumentTitlesQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/api/queries/useDocumentTitlesQuery.ts"],"sourcesContent":["\"use client\";\n\nimport { useQuery } from \"@tanstack/react-query\";\nimport { useConfig } from \"@payloadcms/ui\";\nimport { useLocale } from \"@payloadcms/ui\";\nimport { getDocumentTitlesKey } from \"../queryKeys\";\nimport { getDocumentTitles } from \"../../services/getDocumentTitles\";\nimport { useCommentsDrawer } from \"../../providers/CommentsDrawerProvider\";\nimport { useCommentsQuery } from \"./useCommentsQuery\";\nimport type { QueryContext } from \"../../types\";\nimport type { CommentsPluginConfigStorage } from \"../../types\";\nimport { REFETCH_INTERVAL } from \"../../constants\";\n\nexport function useDocumentTitlesQuery(ctx: QueryContext) {\n const { isOpen } = useCommentsDrawer();\n const { data: comments } = useCommentsQuery(ctx);\n const { code: locale } = useLocale();\n const { config } = useConfig();\n\n const pluginConfig = config.admin?.custom?.commentsPlugin as CommentsPluginConfigStorage | undefined;\n\n return useQuery({\n queryKey: getDocumentTitlesKey(ctx),\n queryFn: async () => {\n const res = await getDocumentTitles(comments ?? [], pluginConfig?.documentTitleFields ?? {}, { locale });\n\n if (!res.success) throw new Error(res.error);\n\n return res.data;\n },\n enabled: isOpen && !!comments,\n staleTime: 0,\n refetchInterval: isOpen ? REFETCH_INTERVAL : false,\n refetchIntervalInBackground: false,\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,4BAA4B;AACrC,SAAS,yBAAyB;AAClC,SAAS,yBAAyB;AAClC,SAAS,wBAAwB;AAGjC,SAAS,wBAAwB;AAE1B,SAAS,uBAAuB,KAAmB;AACxD,QAAM,EAAE,OAAO,IAAI,kBAAkB;AACrC,QAAM,EAAE,MAAM,SAAS,IAAI,iBAAiB,GAAG;AAC/C,QAAM,EAAE,MAAM,OAAO,IAAI,UAAU;AACnC,QAAM,EAAE,OAAO,IAAI,UAAU;AAE7B,QAAM,eAAe,OAAO,OAAO,QAAQ;AAE3C,SAAO,SAAS;AAAA,IACd,UAAU,qBAAqB,GAAG;AAAA,IAClC,SAAS,YAAY;AACnB,YAAM,MAAM,MAAM,kBAAkB,YAAY,CAAC,GAAG,cAAc,uBAAuB,CAAC,GAAG,EAAE,OAAO,CAAC;AAEvG,UAAI,CAAC,IAAI,QAAS,OAAM,IAAI,MAAM,IAAI,KAAK;AAE3C,aAAO,IAAI;AAAA,IACb;AAAA,IACA,SAAS,UAAU,CAAC,CAAC;AAAA,IACrB,WAAW;AAAA,IACX,iBAAiB,SAAS,mBAAmB;AAAA,IAC7C,6BAA6B;AAAA,EAC/B,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFieldLabelsQuery.d.ts","sourceRoot":"","sources":["../../../src/api/queries/useFieldLabelsQuery.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,YAAY,yGAYpD"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useQuery } from "@tanstack/react-query";
|
|
3
|
+
import { getFieldLabelsKey } from "../queryKeys";
|
|
4
|
+
import { fetchFieldLabels } from "../../services/fieldLabels/fetchFieldLabels";
|
|
5
|
+
import { useCommentsDrawer } from "../../providers/CommentsDrawerProvider";
|
|
6
|
+
import { useCommentsQuery } from "./useCommentsQuery";
|
|
7
|
+
import { REFETCH_INTERVAL } from "../../constants";
|
|
8
|
+
function useFieldLabelsQuery(ctx) {
|
|
9
|
+
const { isOpen } = useCommentsDrawer();
|
|
10
|
+
const { data: comments } = useCommentsQuery(ctx);
|
|
11
|
+
return useQuery({
|
|
12
|
+
queryKey: getFieldLabelsKey(ctx),
|
|
13
|
+
queryFn: () => fetchFieldLabels(comments ?? []),
|
|
14
|
+
enabled: isOpen && !!comments,
|
|
15
|
+
staleTime: 0,
|
|
16
|
+
refetchInterval: isOpen ? REFETCH_INTERVAL : false,
|
|
17
|
+
refetchIntervalInBackground: false
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
useFieldLabelsQuery
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=useFieldLabelsQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/api/queries/useFieldLabelsQuery.ts"],"sourcesContent":["\"use client\";\n\nimport { useQuery } from \"@tanstack/react-query\";\nimport { getFieldLabelsKey } from \"../queryKeys\";\nimport { fetchFieldLabels } from \"../../services/fieldLabels/fetchFieldLabels\";\nimport { useCommentsDrawer } from \"../../providers/CommentsDrawerProvider\";\nimport { useCommentsQuery } from \"./useCommentsQuery\";\nimport type { QueryContext } from \"../../types\";\nimport { REFETCH_INTERVAL } from \"../../constants\";\n\nexport function useFieldLabelsQuery(ctx: QueryContext) {\n const { isOpen } = useCommentsDrawer();\n const { data: comments } = useCommentsQuery(ctx);\n\n return useQuery({\n queryKey: getFieldLabelsKey(ctx),\n queryFn: () => fetchFieldLabels(comments ?? []),\n enabled: isOpen && !!comments,\n staleTime: 0,\n refetchInterval: isOpen ? REFETCH_INTERVAL : false,\n refetchIntervalInBackground: false,\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,yBAAyB;AAClC,SAAS,wBAAwB;AACjC,SAAS,yBAAyB;AAClC,SAAS,wBAAwB;AAEjC,SAAS,wBAAwB;AAE1B,SAAS,oBAAoB,KAAmB;AACrD,QAAM,EAAE,OAAO,IAAI,kBAAkB;AACrC,QAAM,EAAE,MAAM,SAAS,IAAI,iBAAiB,GAAG;AAE/C,SAAO,SAAS;AAAA,IACd,UAAU,kBAAkB,GAAG;AAAA,IAC/B,SAAS,MAAM,iBAAiB,YAAY,CAAC,CAAC;AAAA,IAC9C,SAAS,UAAU,CAAC,CAAC;AAAA,IACrB,WAAW;AAAA,IACX,iBAAiB,SAAS,mBAAmB;AAAA,IAC7C,6BAA6B;AAAA,EAC/B,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMentionableUsersQuery.d.ts","sourceRoot":"","sources":["../../../src/api/queries/useMentionableUsersQuery.ts"],"names":[],"mappings":"AAQA,wBAAgB,wBAAwB,wFAiBvC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useQuery } from "@tanstack/react-query";
|
|
3
|
+
import { QUERY_KEYS } from "../queryKeys";
|
|
4
|
+
import { fetchMentionableUsers } from "../../services/fetchMentionableUsers";
|
|
5
|
+
import { useCommentsDrawer } from "../../providers/CommentsDrawerProvider";
|
|
6
|
+
import { REFETCH_INTERVAL } from "../../constants";
|
|
7
|
+
function useMentionableUsersQuery() {
|
|
8
|
+
const { isOpen } = useCommentsDrawer();
|
|
9
|
+
return useQuery({
|
|
10
|
+
queryKey: QUERY_KEYS.mentionableUsers(),
|
|
11
|
+
queryFn: async () => {
|
|
12
|
+
const res = await fetchMentionableUsers();
|
|
13
|
+
if (!res.success) throw new Error(res.error);
|
|
14
|
+
return res.data;
|
|
15
|
+
},
|
|
16
|
+
enabled: isOpen,
|
|
17
|
+
staleTime: 0,
|
|
18
|
+
refetchInterval: isOpen ? REFETCH_INTERVAL : false,
|
|
19
|
+
refetchIntervalInBackground: false
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
useMentionableUsersQuery
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=useMentionableUsersQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/api/queries/useMentionableUsersQuery.ts"],"sourcesContent":["\"use client\";\n\nimport { useQuery } from \"@tanstack/react-query\";\nimport { QUERY_KEYS } from \"../queryKeys\";\nimport { fetchMentionableUsers } from \"../../services/fetchMentionableUsers\";\nimport { useCommentsDrawer } from \"../../providers/CommentsDrawerProvider\";\nimport { REFETCH_INTERVAL } from \"../../constants\";\n\nexport function useMentionableUsersQuery() {\n const { isOpen } = useCommentsDrawer();\n\n return useQuery({\n queryKey: QUERY_KEYS.mentionableUsers(),\n queryFn: async () => {\n const res = await fetchMentionableUsers();\n\n if (!res.success) throw new Error(res.error);\n\n return res.data;\n },\n enabled: isOpen,\n staleTime: 0,\n refetchInterval: isOpen ? REFETCH_INTERVAL : false,\n refetchIntervalInBackground: false,\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AACtC,SAAS,yBAAyB;AAClC,SAAS,wBAAwB;AAE1B,SAAS,2BAA2B;AACzC,QAAM,EAAE,OAAO,IAAI,kBAAkB;AAErC,SAAO,SAAS;AAAA,IACd,UAAU,WAAW,iBAAiB;AAAA,IACtC,SAAS,YAAY;AACnB,YAAM,MAAM,MAAM,sBAAsB;AAExC,UAAI,CAAC,IAAI,QAAS,OAAM,IAAI,MAAM,IAAI,KAAK;AAE3C,aAAO,IAAI;AAAA,IACb;AAAA,IACA,SAAS;AAAA,IACT,WAAW;AAAA,IACX,iBAAiB,SAAS,mBAAmB;AAAA,IAC7C,6BAA6B;AAAA,EAC/B,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { QueryContext } from "../types";
|
|
2
|
+
export declare const QUERY_KEYS: {
|
|
3
|
+
comments: {
|
|
4
|
+
doc: (collectionSlug: string, docId: string) => readonly ["comments", "doc", string, string];
|
|
5
|
+
globalDoc: (globalSlug: string) => readonly ["comments", "global-doc", string];
|
|
6
|
+
global: () => readonly ["comments", "global"];
|
|
7
|
+
};
|
|
8
|
+
fieldLabels: {
|
|
9
|
+
doc: (collectionSlug: string, docId: string) => readonly ["field-labels", "doc", string, string];
|
|
10
|
+
globalDoc: (globalSlug: string) => readonly ["field-labels", "global-doc", string];
|
|
11
|
+
global: () => readonly ["field-labels", "global"];
|
|
12
|
+
};
|
|
13
|
+
documentTitles: {
|
|
14
|
+
doc: (collectionSlug: string, docId: string) => readonly ["document-titles", "doc", string, string];
|
|
15
|
+
globalDoc: (globalSlug: string) => readonly ["document-titles", "global-doc", string];
|
|
16
|
+
global: () => readonly ["document-titles", "global"];
|
|
17
|
+
};
|
|
18
|
+
mentionableUsers: () => readonly ["mentionable-users"];
|
|
19
|
+
};
|
|
20
|
+
export declare function getCommentsKey(ctx: QueryContext): readonly ["comments", "doc", string, string] | readonly ["comments", "global-doc", string] | readonly ["comments", "global"];
|
|
21
|
+
export declare function getFieldLabelsKey(ctx: QueryContext): readonly ["field-labels", "doc", string, string] | readonly ["field-labels", "global-doc", string] | readonly ["field-labels", "global"];
|
|
22
|
+
export declare function getDocumentTitlesKey(ctx: QueryContext): readonly ["document-titles", "doc", string, string] | readonly ["document-titles", "global-doc", string] | readonly ["document-titles", "global"];
|
|
23
|
+
//# sourceMappingURL=queryKeys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryKeys.d.ts","sourceRoot":"","sources":["../../src/api/queryKeys.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,eAAO,MAAM,UAAU;;8BAEG,MAAM,SAAS,MAAM;gCACnB,MAAM;;;;8BAIR,MAAM,SAAS,MAAM;gCACnB,MAAM;;;;8BAIR,MAAM,SAAS,MAAM;gCACnB,MAAM;;;;CAIjC,CAAC;AAEF,wBAAgB,cAAc,CAAC,GAAG,EAAE,YAAY,gIAM/C;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,YAAY,4IAMlD;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,YAAY,qJAMrD"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const QUERY_KEYS = {
|
|
2
|
+
comments: {
|
|
3
|
+
doc: (collectionSlug, docId) => ["comments", "doc", collectionSlug, docId],
|
|
4
|
+
globalDoc: (globalSlug) => ["comments", "global-doc", globalSlug],
|
|
5
|
+
global: () => ["comments", "global"]
|
|
6
|
+
},
|
|
7
|
+
fieldLabels: {
|
|
8
|
+
doc: (collectionSlug, docId) => ["field-labels", "doc", collectionSlug, docId],
|
|
9
|
+
globalDoc: (globalSlug) => ["field-labels", "global-doc", globalSlug],
|
|
10
|
+
global: () => ["field-labels", "global"]
|
|
11
|
+
},
|
|
12
|
+
documentTitles: {
|
|
13
|
+
doc: (collectionSlug, docId) => ["document-titles", "doc", collectionSlug, docId],
|
|
14
|
+
globalDoc: (globalSlug) => ["document-titles", "global-doc", globalSlug],
|
|
15
|
+
global: () => ["document-titles", "global"]
|
|
16
|
+
},
|
|
17
|
+
mentionableUsers: () => ["mentionable-users"]
|
|
18
|
+
};
|
|
19
|
+
function getCommentsKey(ctx) {
|
|
20
|
+
if (ctx.mode === "doc") return QUERY_KEYS.comments.doc(ctx.collectionSlug, ctx.docId);
|
|
21
|
+
if (ctx.mode === "global-doc") return QUERY_KEYS.comments.globalDoc(ctx.globalSlug);
|
|
22
|
+
return QUERY_KEYS.comments.global();
|
|
23
|
+
}
|
|
24
|
+
function getFieldLabelsKey(ctx) {
|
|
25
|
+
if (ctx.mode === "doc") return QUERY_KEYS.fieldLabels.doc(ctx.collectionSlug, ctx.docId);
|
|
26
|
+
if (ctx.mode === "global-doc") return QUERY_KEYS.fieldLabels.globalDoc(ctx.globalSlug);
|
|
27
|
+
return QUERY_KEYS.fieldLabels.global();
|
|
28
|
+
}
|
|
29
|
+
function getDocumentTitlesKey(ctx) {
|
|
30
|
+
if (ctx.mode === "doc") return QUERY_KEYS.documentTitles.doc(ctx.collectionSlug, ctx.docId);
|
|
31
|
+
if (ctx.mode === "global-doc") return QUERY_KEYS.documentTitles.globalDoc(ctx.globalSlug);
|
|
32
|
+
return QUERY_KEYS.documentTitles.global();
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
QUERY_KEYS,
|
|
36
|
+
getCommentsKey,
|
|
37
|
+
getDocumentTitlesKey,
|
|
38
|
+
getFieldLabelsKey
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=queryKeys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/api/queryKeys.ts"],"sourcesContent":["import type { QueryContext } from \"../types\";\n\nexport const QUERY_KEYS = {\n comments: {\n doc: (collectionSlug: string, docId: string) => [\"comments\", \"doc\", collectionSlug, docId] as const,\n globalDoc: (globalSlug: string) => [\"comments\", \"global-doc\", globalSlug] as const,\n global: () => [\"comments\", \"global\"] as const,\n },\n fieldLabels: {\n doc: (collectionSlug: string, docId: string) => [\"field-labels\", \"doc\", collectionSlug, docId] as const,\n globalDoc: (globalSlug: string) => [\"field-labels\", \"global-doc\", globalSlug] as const,\n global: () => [\"field-labels\", \"global\"] as const,\n },\n documentTitles: {\n doc: (collectionSlug: string, docId: string) => [\"document-titles\", \"doc\", collectionSlug, docId] as const,\n globalDoc: (globalSlug: string) => [\"document-titles\", \"global-doc\", globalSlug] as const,\n global: () => [\"document-titles\", \"global\"] as const,\n },\n mentionableUsers: () => [\"mentionable-users\"] as const,\n};\n\nexport function getCommentsKey(ctx: QueryContext) {\n if (ctx.mode === \"doc\") return QUERY_KEYS.comments.doc(ctx.collectionSlug, ctx.docId);\n\n if (ctx.mode === \"global-doc\") return QUERY_KEYS.comments.globalDoc(ctx.globalSlug);\n\n return QUERY_KEYS.comments.global();\n}\n\nexport function getFieldLabelsKey(ctx: QueryContext) {\n if (ctx.mode === \"doc\") return QUERY_KEYS.fieldLabels.doc(ctx.collectionSlug, ctx.docId);\n\n if (ctx.mode === \"global-doc\") return QUERY_KEYS.fieldLabels.globalDoc(ctx.globalSlug);\n\n return QUERY_KEYS.fieldLabels.global();\n}\n\nexport function getDocumentTitlesKey(ctx: QueryContext) {\n if (ctx.mode === \"doc\") return QUERY_KEYS.documentTitles.doc(ctx.collectionSlug, ctx.docId);\n\n if (ctx.mode === \"global-doc\") return QUERY_KEYS.documentTitles.globalDoc(ctx.globalSlug);\n\n return QUERY_KEYS.documentTitles.global();\n}\n"],"mappings":"AAEO,MAAM,aAAa;AAAA,EACxB,UAAU;AAAA,IACR,KAAK,CAAC,gBAAwB,UAAkB,CAAC,YAAY,OAAO,gBAAgB,KAAK;AAAA,IACzF,WAAW,CAAC,eAAuB,CAAC,YAAY,cAAc,UAAU;AAAA,IACxE,QAAQ,MAAM,CAAC,YAAY,QAAQ;AAAA,EACrC;AAAA,EACA,aAAa;AAAA,IACX,KAAK,CAAC,gBAAwB,UAAkB,CAAC,gBAAgB,OAAO,gBAAgB,KAAK;AAAA,IAC7F,WAAW,CAAC,eAAuB,CAAC,gBAAgB,cAAc,UAAU;AAAA,IAC5E,QAAQ,MAAM,CAAC,gBAAgB,QAAQ;AAAA,EACzC;AAAA,EACA,gBAAgB;AAAA,IACd,KAAK,CAAC,gBAAwB,UAAkB,CAAC,mBAAmB,OAAO,gBAAgB,KAAK;AAAA,IAChG,WAAW,CAAC,eAAuB,CAAC,mBAAmB,cAAc,UAAU;AAAA,IAC/E,QAAQ,MAAM,CAAC,mBAAmB,QAAQ;AAAA,EAC5C;AAAA,EACA,kBAAkB,MAAM,CAAC,mBAAmB;AAC9C;AAEO,SAAS,eAAe,KAAmB;AAChD,MAAI,IAAI,SAAS,MAAO,QAAO,WAAW,SAAS,IAAI,IAAI,gBAAgB,IAAI,KAAK;AAEpF,MAAI,IAAI,SAAS,aAAc,QAAO,WAAW,SAAS,UAAU,IAAI,UAAU;AAElF,SAAO,WAAW,SAAS,OAAO;AACpC;AAEO,SAAS,kBAAkB,KAAmB;AACnD,MAAI,IAAI,SAAS,MAAO,QAAO,WAAW,YAAY,IAAI,IAAI,gBAAgB,IAAI,KAAK;AAEvF,MAAI,IAAI,SAAS,aAAc,QAAO,WAAW,YAAY,UAAU,IAAI,UAAU;AAErF,SAAO,WAAW,YAAY,OAAO;AACvC;AAEO,SAAS,qBAAqB,KAAmB;AACtD,MAAI,IAAI,SAAS,MAAO,QAAO,WAAW,eAAe,IAAI,IAAI,gBAAgB,IAAI,KAAK;AAE1F,MAAI,IAAI,SAAS,aAAc,QAAO,WAAW,eAAe,UAAU,IAAI,UAAU;AAExF,SAAO,WAAW,eAAe,OAAO;AAC1C;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/CommentEditor/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAyC,KAAK,SAAS,EAAmB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/CommentEditor/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAyC,KAAK,SAAS,EAAmB,MAAM,OAAO,CAAC;AAe/F,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,UAAU,kBAAkB;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,SAAS,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAAC;IAC5C,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mBAAmB,CAAC,EAAE,MAAM,IAAI,CAAC;IACjC,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;CAC5B;AAED,wBAAgB,aAAa,CAAC,EAC5B,QAAQ,EACR,SAAS,EACT,WAAW,EAAE,eAAe,EAC5B,GAAG,EACH,SAAS,EACT,UAAU,EACV,cAAc,EACd,UAAU,EACV,mBAAmB,EACnB,YAAY,EACZ,aAAa,GACd,EAAE,kBAAkB,2CAyRpB"}
|
|
@@ -3,6 +3,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { useState, useRef, useImperativeHandle, startTransition } from "react";
|
|
4
4
|
import { useAuth, useLocale, useTranslation } from "@payloadcms/ui";
|
|
5
5
|
import { useComments } from "../../providers/CommentsProvider";
|
|
6
|
+
import { useMentionableUsersQuery } from "../../api/queries/useMentionableUsersQuery";
|
|
6
7
|
import { MentionDropdown } from "../MentionDropdown";
|
|
7
8
|
import { MentionLabel } from "../MentionLabel";
|
|
8
9
|
import { serializeEditor } from "../../utils/comment/serializeEditor";
|
|
@@ -25,7 +26,8 @@ function CommentEditor({
|
|
|
25
26
|
onEnterPress,
|
|
26
27
|
onEscapePress
|
|
27
28
|
}) {
|
|
28
|
-
const {
|
|
29
|
+
const { addComment } = useComments();
|
|
30
|
+
const { data: users = [] } = useMentionableUsersQuery();
|
|
29
31
|
const { code: locale } = useLocale();
|
|
30
32
|
const { user } = useAuth();
|
|
31
33
|
const [mentionQuery, setMentionQuery] = useState(null);
|
|
@@ -210,13 +212,13 @@ function CommentEditor({
|
|
|
210
212
|
"div",
|
|
211
213
|
{
|
|
212
214
|
ref: editorWrapperRef,
|
|
213
|
-
className: "relative flex-1 group px-2.5 py-2 rounded-md border border-transparent focus-within:border-(--theme-elevation-150) bg-transparent
|
|
215
|
+
className: "relative flex-1 min-w-0 group px-2.5 py-2 rounded-md border border-transparent focus-within:border-(--theme-elevation-150) bg-transparent",
|
|
214
216
|
children: [
|
|
215
217
|
/* @__PURE__ */ jsx("div", { className: "relative", children: /* @__PURE__ */ jsx(
|
|
216
218
|
"div",
|
|
217
219
|
{
|
|
218
220
|
className: `
|
|
219
|
-
is-empty w-full min-h-5
|
|
221
|
+
is-empty w-full min-h-5 max-h-32 overflow-y-auto whitespace-pre-wrap wrap-break-word
|
|
220
222
|
text-(--theme-text) text-[13px] outline-none box-border
|
|
221
223
|
[&.is-empty]:before:content-[attr(data-placeholder)] [&.is-empty]:before:text-(--theme-elevation-450)
|
|
222
224
|
[&.is-empty]:before:pointer-events-none [&.is-empty]:before:absolute
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/CommentEditor/index.tsx"],"sourcesContent":["\"use client\";\n\nimport { useState, useRef, useImperativeHandle, type RefObject, startTransition } from \"react\";\nimport { useAuth, useLocale, useTranslation } from \"@payloadcms/ui\";\nimport { useComments } from \"../../providers/CommentsProvider\";\nimport { MentionDropdown } from \"../MentionDropdown\";\nimport { MentionLabel } from \"../MentionLabel\";\nimport { serializeEditor } from \"../../utils/comment/serializeEditor\";\nimport { isSelfMention } from \"../../utils/mention/isSelfMention\";\nimport { createRoot } from \"react-dom/client\";\nimport type { User } from \"../../types\";\nimport { FALLBACK_USERNAME } from \"../../constants\";\nimport { resolveUsername } from \"../../utils/user/resolveUsername\";\nimport { ActionPanel } from \"./ActionPanel\";\nimport { Avatar } from \"../Avatar\";\n\nexport interface CommentEditorHandle {\n getValue: () => string;\n clear: () => void;\n focus: () => void;\n insertAt: () => void;\n}\n\ninterface CommentEditorProps {\n disabled?: boolean;\n autoFocus?: boolean;\n placeholder?: string;\n ref?: RefObject<CommentEditorHandle | null>;\n fieldPath?: string | null;\n documentId?: number;\n collectionSlug?: string;\n globalSlug?: string;\n onSuccessAddComment?: () => void;\n onEnterPress?: () => void;\n onEscapePress?: () => void;\n}\n\nexport function CommentEditor({\n disabled,\n autoFocus,\n placeholder: placeholderProp,\n ref,\n fieldPath,\n documentId,\n collectionSlug,\n globalSlug,\n onSuccessAddComment,\n onEnterPress,\n onEscapePress,\n}: CommentEditorProps) {\n const { mentionUsers: users, addComment } = useComments();\n const { code: locale } = useLocale();\n const { user } = useAuth();\n\n const [mentionQuery, setMentionQuery] = useState<string | null>(null);\n const [triggerRange, setTriggerRange] = useState<Range | null>(null);\n const [filteredUsers, setFilteredUsers] = useState<User[]>([]);\n const [selectedIndex, setSelectedIndex] = useState(0);\n\n const { usernameFieldPath } = useComments();\n const { t } = useTranslation();\n\n const editorRef = useRef<HTMLDivElement>(null);\n const editorWrapperRef = useRef<HTMLDivElement>(null);\n\n const unknownLabel = t(\"comments:unknownAuthor\" as never) ?? FALLBACK_USERNAME;\n const currentUserId = user?.id;\n const placeholder = placeholderProp ?? t(\"comments:writeComment\" as never) ?? \"Add a comment\";\n\n // Methods\n const detectMention = () => {\n const sel = window.getSelection();\n\n if (!sel || !sel.rangeCount) {\n setMentionQuery(null);\n\n return;\n }\n\n const range = sel.getRangeAt(0);\n const node = range.startContainer;\n\n if (node.nodeType !== Node.TEXT_NODE) {\n setMentionQuery(null);\n\n return;\n }\n\n const text = node.textContent ?? \"\";\n const offset = range.startOffset;\n\n let i = offset - 1;\n while (i >= 0 && text[i] !== \" \" && text[i] !== \"\\n\") {\n if (text[i] === \"@\") {\n const query = text.slice(i + 1, offset);\n if (query.includes(\" \")) {\n setMentionQuery(null);\n return;\n }\n\n const atRange = document.createRange();\n atRange.setStart(node, i);\n atRange.setEnd(node, offset);\n setTriggerRange(atRange.cloneRange());\n setMentionQuery(query);\n setFilteredUsers(\n users.filter((u) =>\n resolveUsername(u, usernameFieldPath, unknownLabel).toLowerCase().includes(query.toLowerCase()),\n ),\n );\n setSelectedIndex(0);\n\n return;\n }\n\n i--;\n }\n\n setMentionQuery(null);\n };\n\n const insertMention = (user: User) => {\n if (!triggerRange || !editorRef.current) return;\n\n const sel = window.getSelection();\n if (!sel) return;\n\n sel.removeAllRanges();\n sel.addRange(triggerRange);\n sel.deleteFromDocument();\n\n const { id: userId } = user;\n\n const mentionLabelContainer = document.createElement(\"span\");\n const mentionLabelContainerRoot = createRoot(mentionLabelContainer);\n\n mentionLabelContainerRoot.render(\n <MentionLabel\n name={resolveUsername(user, usernameFieldPath, unknownLabel)}\n isSelf={isSelfMention(currentUserId, userId)}\n />,\n );\n\n mentionLabelContainer.contentEditable = \"false\";\n mentionLabelContainer.dataset.mentionId = String(userId);\n\n const range2 = sel.getRangeAt(0);\n range2.insertNode(mentionLabelContainer);\n\n const zws = document.createTextNode(\"\\u200b\");\n mentionLabelContainer.after(zws);\n\n const newRange = document.createRange();\n newRange.setStartAfter(zws);\n newRange.collapse(true);\n sel.removeAllRanges();\n sel.addRange(newRange);\n\n setMentionQuery(null);\n setTriggerRange(null);\n editorRef.current?.focus();\n };\n\n const insertAt = () => {\n const editor = editorRef.current;\n if (!editor) return;\n\n editor.focus();\n\n const sel = window.getSelection();\n if (!sel || !sel.rangeCount) {\n const range = document.createRange();\n range.selectNodeContents(editor);\n range.collapse(false);\n sel?.removeAllRanges();\n sel?.addRange(range);\n }\n\n document.execCommand(\"insertText\", false, \"@\");\n detectMention();\n };\n\n const updateEmptyClass = () => {\n const editor = editorRef.current;\n if (!editor) return;\n\n const isEmpty = editor.innerHTML === \"\" || editor.innerHTML === \"<br>\";\n\n editor.classList.toggle(\"is-empty\", isEmpty);\n };\n\n // Editor API\n const getEditorValue = () => {\n if (!editorRef.current) return \"\";\n\n return serializeEditor(editorRef.current).trim();\n };\n\n const clearEditor = () => {\n setMentionQuery(null);\n setTriggerRange(null);\n\n if (editorRef.current) {\n editorRef.current.innerHTML = \"\";\n editorRef.current.classList.add(\"is-empty\");\n }\n };\n\n const focusEditor = () => {\n editorRef.current?.focus();\n };\n\n useImperativeHandle(ref, () => ({\n getValue: getEditorValue,\n clear: clearEditor,\n focus: focusEditor,\n insertAt,\n }));\n\n // Handlers\n const handleAddComment = () => {\n const serialized = getEditorValue();\n if (!serialized) return;\n\n clearEditor();\n\n startTransition(async () => {\n const res = await addComment(serialized, fieldPath, documentId, collectionSlug, locale, globalSlug);\n\n if (res.success) {\n onSuccessAddComment?.();\n }\n });\n };\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n if (mentionQuery !== null) {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n e.stopPropagation();\n setSelectedIndex((prev) => (prev + 1) % filteredUsers.length);\n return;\n }\n if (e.key === \"ArrowUp\") {\n e.preventDefault();\n e.stopPropagation();\n setSelectedIndex((prev) => (prev - 1 + filteredUsers.length) % filteredUsers.length);\n return;\n }\n if (e.key === \"Enter\" && filteredUsers.length > 0) {\n e.preventDefault();\n const selectedUser = filteredUsers[selectedIndex];\n if (selectedUser) insertMention(selectedUser);\n return;\n }\n if (e.key === \"Escape\") {\n e.stopPropagation();\n setMentionQuery(null);\n setTriggerRange(null);\n return;\n }\n }\n\n if (e.key === \"Enter\" && !e.shiftKey) {\n e.preventDefault();\n\n handleAddComment();\n onEnterPress?.();\n } else if (e.key === \"Escape\") {\n onEscapePress?.();\n }\n };\n\n const handleInput = () => {\n detectMention();\n updateEmptyClass();\n };\n\n return (\n <div className=\"relative\">\n <div className=\"flex gap-2.5 items-start\">\n <Avatar className=\"shrink-0\" user={user} usernameFieldPath={usernameFieldPath} fallbackName={unknownLabel} />\n\n <div\n ref={editorWrapperRef}\n className=\"relative flex-1 group px-2.5 py-2 rounded-md border border-transparent focus-within:border-(--theme-elevation-150) bg-transparent transition-colors\">\n <div className=\"relative\">\n <div\n className={`\n is-empty w-full min-h-5 leading-5\n text-(--theme-text) text-[13px] outline-none box-border\n [&.is-empty]:before:content-[attr(data-placeholder)] [&.is-empty]:before:text-(--theme-elevation-450)\n [&.is-empty]:before:pointer-events-none [&.is-empty]:before:absolute\n `}\n ref={editorRef}\n contentEditable={!disabled}\n autoFocus={autoFocus}\n role=\"textbox\"\n aria-multiline=\"true\"\n aria-label={placeholder}\n data-placeholder={placeholder}\n onInput={handleInput}\n onKeyDown={handleKeyDown}\n />\n </div>\n\n {mentionQuery !== null && (\n <MentionDropdown\n users={filteredUsers}\n selectedIndex={selectedIndex}\n onSelect={insertMention}\n onClose={() => {\n setMentionQuery(null);\n setTriggerRange(null);\n editorRef.current?.focus();\n }}\n anchorRef={editorWrapperRef}\n />\n )}\n\n <ActionPanel\n className=\"hidden group-focus-within:flex\"\n onMention={() => insertAt()}\n onAddComment={handleAddComment}\n />\n </div>\n </div>\n </div>\n );\n}\n"],"mappings":";AAyIM,cAkJE,YAlJF;AAvIN,SAAS,UAAU,QAAQ,qBAAqC,uBAAuB;AACvF,SAAS,SAAS,WAAW,sBAAsB;AACnD,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB;AAChC,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAE3B,SAAS,yBAAyB;AAClC,SAAS,uBAAuB;AAChC,SAAS,mBAAmB;AAC5B,SAAS,cAAc;AAuBhB,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA;AAAA,EACA,aAAa;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAuB;AACrB,QAAM,E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AAY;AAAA,cACZ,oBAAkB;AAAA,cAClB,SAAS;AAAA,cACT,WAAW;AAAA;AAAA,UACb,GACF;AAAA,UAEC,iBAAiB,QAChB;AAAA,YAAC;AAAA;AAAA,cACC,OAAO;AAAA,cACP;AAAA,cACA,UAAU;AAAA,cACV,SAAS,MAAM;AACb,gCAAgB,IAAI;AACpB,gCAAgB,IAAI;AACpB,0BAAU,SAAS,MAAM;AAAA,cAC3B;AAAA,cACA,WAAW;AAAA;AAAA,UACb;AAAA,UAGF;AAAA,YAAC;AAAA;AAAA,cACC,WAAU;AAAA,cACV,WAAW,MAAM,SAAS;AAAA,cAC1B,cAAc;AAAA;AAAA,UAChB;AAAA;AAAA;AAAA,IACF;AAAA,KACF,GACF;AAEJ;","names":["user"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/CommentEditor/index.tsx"],"sourcesContent":["\"use client\";\n\nimport { useState, useRef, useImperativeHandle, type RefObject, startTransition } from \"react\";\nimport { useAuth, useLocale, useTranslation } from \"@payloadcms/ui\";\nimport { useComments } from \"../../providers/CommentsProvider\";\nimport { useMentionableUsersQuery } from \"../../api/queries/useMentionableUsersQuery\";\nimport { MentionDropdown } from \"../MentionDropdown\";\nimport { MentionLabel } from \"../MentionLabel\";\nimport { serializeEditor } from \"../../utils/comment/serializeEditor\";\nimport { isSelfMention } from \"../../utils/mention/isSelfMention\";\nimport { createRoot } from \"react-dom/client\";\nimport type { User } from \"../../types\";\nimport { FALLBACK_USERNAME } from \"../../constants\";\nimport { resolveUsername } from \"../../utils/user/resolveUsername\";\nimport { ActionPanel } from \"./ActionPanel\";\nimport { Avatar } from \"../Avatar\";\n\nexport interface CommentEditorHandle {\n getValue: () => string;\n clear: () => void;\n focus: () => void;\n insertAt: () => void;\n}\n\ninterface CommentEditorProps {\n disabled?: boolean;\n autoFocus?: boolean;\n placeholder?: string;\n ref?: RefObject<CommentEditorHandle | null>;\n fieldPath?: string | null;\n documentId?: number;\n collectionSlug?: string;\n globalSlug?: string;\n onSuccessAddComment?: () => void;\n onEnterPress?: () => void;\n onEscapePress?: () => void;\n}\n\nexport function CommentEditor({\n disabled,\n autoFocus,\n placeholder: placeholderProp,\n ref,\n fieldPath,\n documentId,\n collectionSlug,\n globalSlug,\n onSuccessAddComment,\n onEnterPress,\n onEscapePress,\n}: CommentEditorProps) {\n const { addComment } = useComments();\n const { data: users = [] } = useMentionableUsersQuery();\n const { code: locale } = useLocale();\n const { user } = useAuth();\n\n const [mentionQuery, setMentionQuery] = useState<string | null>(null);\n const [triggerRange, setTriggerRange] = useState<Range | null>(null);\n const [filteredUsers, setFilteredUsers] = useState<User[]>([]);\n const [selectedIndex, setSelectedIndex] = useState(0);\n\n const { usernameFieldPath } = useComments();\n const { t } = useTranslation();\n\n const editorRef = useRef<HTMLDivElement>(null);\n const editorWrapperRef = useRef<HTMLDivElement>(null);\n\n const unknownLabel = t(\"comments:unknownAuthor\" as never) ?? FALLBACK_USERNAME;\n const currentUserId = user?.id;\n const placeholder = placeholderProp ?? t(\"comments:writeComment\" as never) ?? \"Add a comment\";\n\n // Methods\n const detectMention = () => {\n const sel = window.getSelection();\n\n if (!sel || !sel.rangeCount) {\n setMentionQuery(null);\n\n return;\n }\n\n const range = sel.getRangeAt(0);\n const node = range.startContainer;\n\n if (node.nodeType !== Node.TEXT_NODE) {\n setMentionQuery(null);\n\n return;\n }\n\n const text = node.textContent ?? \"\";\n const offset = range.startOffset;\n\n let i = offset - 1;\n while (i >= 0 && text[i] !== \" \" && text[i] !== \"\\n\") {\n if (text[i] === \"@\") {\n const query = text.slice(i + 1, offset);\n if (query.includes(\" \")) {\n setMentionQuery(null);\n return;\n }\n\n const atRange = document.createRange();\n atRange.setStart(node, i);\n atRange.setEnd(node, offset);\n setTriggerRange(atRange.cloneRange());\n setMentionQuery(query);\n setFilteredUsers(\n users.filter((u) =>\n resolveUsername(u, usernameFieldPath, unknownLabel).toLowerCase().includes(query.toLowerCase()),\n ),\n );\n setSelectedIndex(0);\n\n return;\n }\n\n i--;\n }\n\n setMentionQuery(null);\n };\n\n const insertMention = (user: User) => {\n if (!triggerRange || !editorRef.current) return;\n\n const sel = window.getSelection();\n if (!sel) return;\n\n sel.removeAllRanges();\n sel.addRange(triggerRange);\n sel.deleteFromDocument();\n\n const { id: userId } = user;\n\n const mentionLabelContainer = document.createElement(\"span\");\n const mentionLabelContainerRoot = createRoot(mentionLabelContainer);\n\n mentionLabelContainerRoot.render(\n <MentionLabel\n name={resolveUsername(user, usernameFieldPath, unknownLabel)}\n isSelf={isSelfMention(currentUserId, userId)}\n />,\n );\n\n mentionLabelContainer.contentEditable = \"false\";\n mentionLabelContainer.dataset.mentionId = String(userId);\n\n const range2 = sel.getRangeAt(0);\n range2.insertNode(mentionLabelContainer);\n\n const zws = document.createTextNode(\"\\u200b\");\n mentionLabelContainer.after(zws);\n\n const newRange = document.createRange();\n newRange.setStartAfter(zws);\n newRange.collapse(true);\n sel.removeAllRanges();\n sel.addRange(newRange);\n\n setMentionQuery(null);\n setTriggerRange(null);\n editorRef.current?.focus();\n };\n\n const insertAt = () => {\n const editor = editorRef.current;\n if (!editor) return;\n\n editor.focus();\n\n const sel = window.getSelection();\n if (!sel || !sel.rangeCount) {\n const range = document.createRange();\n range.selectNodeContents(editor);\n range.collapse(false);\n sel?.removeAllRanges();\n sel?.addRange(range);\n }\n\n document.execCommand(\"insertText\", false, \"@\");\n detectMention();\n };\n\n const updateEmptyClass = () => {\n const editor = editorRef.current;\n if (!editor) return;\n\n const isEmpty = editor.innerHTML === \"\" || editor.innerHTML === \"<br>\";\n\n editor.classList.toggle(\"is-empty\", isEmpty);\n };\n\n // Editor API\n const getEditorValue = () => {\n if (!editorRef.current) return \"\";\n\n return serializeEditor(editorRef.current).trim();\n };\n\n const clearEditor = () => {\n setMentionQuery(null);\n setTriggerRange(null);\n\n if (editorRef.current) {\n editorRef.current.innerHTML = \"\";\n editorRef.current.classList.add(\"is-empty\");\n }\n };\n\n const focusEditor = () => {\n editorRef.current?.focus();\n };\n\n useImperativeHandle(ref, () => ({\n getValue: getEditorValue,\n clear: clearEditor,\n focus: focusEditor,\n insertAt,\n }));\n\n // Handlers\n const handleAddComment = () => {\n const serialized = getEditorValue();\n if (!serialized) return;\n\n clearEditor();\n\n startTransition(async () => {\n const res = await addComment(serialized, fieldPath, documentId, collectionSlug, locale, globalSlug);\n\n if (res.success) {\n onSuccessAddComment?.();\n }\n });\n };\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n if (mentionQuery !== null) {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n e.stopPropagation();\n setSelectedIndex((prev) => (prev + 1) % filteredUsers.length);\n return;\n }\n if (e.key === \"ArrowUp\") {\n e.preventDefault();\n e.stopPropagation();\n setSelectedIndex((prev) => (prev - 1 + filteredUsers.length) % filteredUsers.length);\n return;\n }\n if (e.key === \"Enter\" && filteredUsers.length > 0) {\n e.preventDefault();\n const selectedUser = filteredUsers[selectedIndex];\n if (selectedUser) insertMention(selectedUser);\n return;\n }\n if (e.key === \"Escape\") {\n e.stopPropagation();\n setMentionQuery(null);\n setTriggerRange(null);\n return;\n }\n }\n\n if (e.key === \"Enter\" && !e.shiftKey) {\n e.preventDefault();\n\n handleAddComment();\n onEnterPress?.();\n } else if (e.key === \"Escape\") {\n onEscapePress?.();\n }\n };\n\n const handleInput = () => {\n detectMention();\n updateEmptyClass();\n };\n\n return (\n <div className=\"relative\">\n <div className=\"flex gap-2.5 items-start\">\n <Avatar className=\"shrink-0\" user={user} usernameFieldPath={usernameFieldPath} fallbackName={unknownLabel} />\n\n <div\n ref={editorWrapperRef}\n className=\"relative flex-1 min-w-0 group px-2.5 py-2 rounded-md border border-transparent focus-within:border-(--theme-elevation-150) bg-transparent\">\n <div className=\"relative\">\n <div\n className={`\n is-empty w-full min-h-5 max-h-32 overflow-y-auto whitespace-pre-wrap wrap-break-word\n text-(--theme-text) text-[13px] outline-none box-border\n [&.is-empty]:before:content-[attr(data-placeholder)] [&.is-empty]:before:text-(--theme-elevation-450)\n [&.is-empty]:before:pointer-events-none [&.is-empty]:before:absolute\n `}\n ref={editorRef}\n contentEditable={!disabled}\n autoFocus={autoFocus}\n role=\"textbox\"\n aria-multiline=\"true\"\n aria-label={placeholder}\n data-placeholder={placeholder}\n onInput={handleInput}\n onKeyDown={handleKeyDown}\n />\n </div>\n\n {mentionQuery !== null && (\n <MentionDropdown\n users={filteredUsers}\n selectedIndex={selectedIndex}\n onSelect={insertMention}\n onClose={() => {\n setMentionQuery(null);\n setTriggerRange(null);\n editorRef.current?.focus();\n }}\n anchorRef={editorWrapperRef}\n />\n )}\n\n <ActionPanel\n className=\"hidden group-focus-within:flex\"\n onMention={() => insertAt()}\n onAddComment={handleAddComment}\n />\n </div>\n </div>\n </div>\n );\n}\n"],"mappings":";AA2IM,cAkJE,YAlJF;AAzIN,SAAS,UAAU,QAAQ,qBAAqC,uBAAuB;AACvF,SAAS,SAAS,WAAW,sBAAsB;AACnD,SAAS,mBAAmB;AAC5B,SAAS,gCAAgC;AACzC,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB;AAChC,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAE3B,SAAS,yBAAyB;AAClC,SAAS,uBAAuB;AAChC,SAAS,mBAAmB;AAC5B,SAAS,cAAc;AAuBhB,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA;AAAA,EACA,aAAa;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAuB;AACrB,QAAM,EAAE,WAAW,IAAI,YAAY;AACnC,QAAM,EAAE,MAAM,QAAQ,CAAC,EAAE,IAAI,yBAAyB;AACtD,QAAM,EAAE,MAAM,OAAO,IAAI,UAAU;AACnC,QAAM,EAAE,KAAK,IAAI,QAAQ;AAEzB,QAAM,CAAC,cAAc,eAAe,IAAI,SAAwB,IAAI;AACpE,QAAM,CAAC,cAAc,eAAe,IAAI,S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AgB,IAAI;AACpB,gCAAgB,IAAI;AACpB,0BAAU,SAAS,MAAM;AAAA,cAC3B;AAAA,cACA,WAAW;AAAA;AAAA,UACb;AAAA,UAGF;AAAA,YAAC;AAAA;AAAA,cACC,WAAU;AAAA,cACV,WAAW,MAAM,SAAS;AAAA,cAC1B,cAAc;AAAA;AAAA,UAChB;AAAA;AAAA;AAAA,IACF;AAAA,KACF,GACF;AAEJ;","names":["user"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clamp.d.ts","sourceRoot":"","sources":["../../../../src/components/CommentItem/StrikethoroughOverlay/clamp.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,UAE5D"}
|