UNPKG

3.68 kBTypeScriptView Raw
1import type { Node, Text } from '@contentful/rich-text-types';
2import type { BasicMetaSysProps, DefaultElements, GetCommentParams, GetEntryParams, GetSpaceEnvironmentParams, Link, MakeRequest, SysLink, VersionedLink } from '../common-types';
3interface LinkWithReference<T extends string> extends Link<T> {
4 sys: Link<T>['sys'] & {
5 ref: string;
6 };
7}
8export type CommentSysProps = Pick<BasicMetaSysProps, 'id' | 'version' | 'createdAt' | 'createdBy' | 'updatedAt' | 'updatedBy'> & {
9 type: 'Comment';
10 space: SysLink;
11 environment: SysLink;
12 parentEntity: Link<'ContentType'> | LinkWithReference<'ContentType'> | Link<'Entry'> | LinkWithReference<'Entry'> | VersionedLink<'Workflow'>;
13 parent: Link<'Comment'> | null;
14};
15export type PlainTextBodyProperty = 'plain-text';
16export type RichTextBodyProperty = 'rich-text';
17export type RichTextBodyFormat = {
18 bodyFormat: RichTextBodyProperty;
19};
20export type PlainTextBodyFormat = {
21 bodyFormat?: PlainTextBodyProperty;
22};
23export type CommentStatus = 'active' | 'resolved';
24export type CommentProps = {
25 sys: CommentSysProps;
26 body: string;
27 status: CommentStatus;
28};
29export type CreateCommentProps = Omit<CommentProps, 'sys' | 'status'> & {
30 status?: CommentStatus;
31};
32export type UpdateCommentProps = Omit<CommentProps, 'sys'> & {
33 sys: Pick<CommentSysProps, 'version'>;
34};
35export declare enum CommentNode {
36 Document = "document",
37 Paragraph = "paragraph",
38 Mention = "mention"
39}
40export interface Mention {
41 nodeType: CommentNode.Mention;
42 data: {
43 target: Link<'User'> | Link<'Team'>;
44 };
45 content: Text[];
46}
47export interface RootParagraph extends Node {
48 nodeType: CommentNode.Paragraph;
49 content: (Text | Mention)[];
50}
51export interface RichTextCommentDocument extends Node {
52 nodeType: CommentNode.Document;
53 content: RootParagraph[];
54}
55export type RichTextCommentBodyPayload = {
56 body: RichTextCommentDocument;
57};
58export type RichTextCommentProps = Omit<CommentProps, 'body'> & RichTextCommentBodyPayload;
59export type GetCommentParentEntityParams = GetSpaceEnvironmentParams & ({
60 parentEntityType: 'ContentType';
61 parentEntityId: string;
62 parentEntityReference?: string;
63} | {
64 parentEntityType: 'Entry';
65 parentEntityId: string;
66 parentEntityReference?: string;
67} | {
68 parentEntityType: 'Workflow';
69 parentEntityId: string;
70 parentEntityVersion?: number;
71});
72export type GetManyCommentsParams = (GetEntryParams | GetCommentParentEntityParams) & {
73 status?: CommentStatus;
74};
75export type CreateCommentParams = (GetEntryParams | GetCommentParentEntityParams) & {
76 parentCommentId?: string;
77};
78export type UpdateCommentParams = GetCommentParams;
79export type DeleteCommentParams = GetCommentParams & {
80 version: number;
81};
82type CommentApi = {
83 update(): Promise<Comment | RichTextComment>;
84 delete(): Promise<void>;
85};
86export interface Comment extends CommentProps, DefaultElements<CommentProps>, CommentApi {
87}
88export interface RichTextComment extends Omit<CommentProps, 'body'>, RichTextCommentProps, DefaultElements<CommentProps>, CommentApi {
89}
90/**
91 * @private
92 */
93export default function createCommentApi(makeRequest: MakeRequest): CommentApi;
94/**
95 * @private
96 */
97export declare function wrapComment(makeRequest: MakeRequest, data: CommentProps | RichTextCommentProps): Comment | RichTextComment;
98/**
99 * @private
100 */
101export declare const wrapCommentCollection: (makeRequest: MakeRequest, data: import("../common-types").CollectionProp<CommentProps | RichTextCommentProps>) => import("../common-types").Collection<Comment | RichTextComment, CommentProps | RichTextCommentProps>;
102export {};