@kendew-agency/react-feedback-layer 0.3.2 → 0.4.0-rc.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/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as React from 'react';
3
3
  import { HTMLProps, ReactNode, ElementType, ButtonHTMLAttributes } from 'react';
4
- import { C as CommentType, a as CommentOverlayProps$1, b as CommentContext } from './comment.types-C0m3sQ_Q.cjs';
4
+ import { C as CommentType, a as CommentOverlayProps$1, b as CommentContext, I as InitialFeedbackSession, c as CreateSessionInput, F as FeedbackSession, S as SessionType, K as KnownError, A as ActiveFeedbackSession, d as SessionOperationState, U as User, e as SessionEvents, f as UserProviderProps } from './use-session-events-DFksOgVA.cjs';
5
5
 
6
6
  interface CommentOverlayProps extends HTMLProps<HTMLDivElement> {
7
7
  children: ReactNode;
@@ -15,9 +15,6 @@ type CommentRendererProps = {
15
15
  DraftComment: ElementType<{
16
16
  comment: CommentType;
17
17
  }>;
18
- ResolvingComment: ElementType<{
19
- comment: CommentType;
20
- }>;
21
18
  ResolvedComment: ElementType<{
22
19
  comment: CommentType;
23
20
  }>;
@@ -30,7 +27,6 @@ type CommentRendererProps = {
30
27
  *
31
28
  * @param Comment - Component for all open comments
32
29
  * @param DraftComment - Component for all draft comments
33
- * @param ResolvingComment - Component for all resolving comments
34
30
  * @param ResolvedComment - Component for all resolved comments
35
31
  * @returns mapped arrays of all comment types
36
32
  * @description This component is used to render all comments based on their type
@@ -39,19 +35,16 @@ type CommentRendererProps = {
39
35
  * <CommentRenderer
40
36
  * Comment={MyCommentComponent}
41
37
  * DraftComment={MyDraftCommentComponent}
42
- * ResolvingComment={MyResolvingCommentComponent}
43
38
  * ResolvedComment={MyResolvedCommentComponent}
44
39
  * />
45
40
  * ```
46
41
  */
47
- declare const CommentRenderer: ({ Comment, DraftComment, ResolvingComment, ResolvedComment, }: CommentRendererProps) => react_jsx_runtime.JSX.Element | null;
42
+ declare const CommentRenderer: ({ Comment, DraftComment, ResolvedComment, }: CommentRendererProps) => react_jsx_runtime.JSX.Element | null;
48
43
 
49
44
  interface CommentButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
50
45
  asChild?: boolean;
51
46
  }
52
47
  declare const ToggleOverlayButton: ({ asChild, ...rest }: CommentButtonProps) => react_jsx_runtime.JSX.Element;
53
- declare const ConfirmComments: ({ asChild, ...rest }: CommentButtonProps) => react_jsx_runtime.JSX.Element;
54
- declare const ResolveComments: ({ asChild, ...rest }: CommentButtonProps) => react_jsx_runtime.JSX.Element;
55
48
 
56
49
  interface CommentRootProps extends HTMLProps<HTMLDivElement> {
57
50
  comment: CommentType;
@@ -76,6 +69,9 @@ interface CommentDeleteProps extends ButtonHTMLAttributes<HTMLButtonElement> {
76
69
  interface CommentResolveProps extends ButtonHTMLAttributes<HTMLButtonElement> {
77
70
  asChild?: boolean;
78
71
  }
72
+ interface CommentReopenProps extends ButtonHTMLAttributes<HTMLButtonElement> {
73
+ asChild?: boolean;
74
+ }
79
75
  declare const Comment: {
80
76
  /**
81
77
  * The root component for a comment, must be used to wrap all other comment components.
@@ -120,12 +116,19 @@ declare const Comment: {
120
116
  */
121
117
  Delete: ({ asChild, ...rest }: CommentDeleteProps) => react_jsx_runtime.JSX.Element;
122
118
  /**
123
- * Toggles the resolving status of a comment
119
+ * Resolves a comment
124
120
  *
125
- * @description Toggles the comment's resolving status, which will show a different UI state
121
+ * @description Calls `resolveComment` for this comment. Renders nothing (and logs an error) for draft and resolved comments
126
122
  * @param asChild as whether to use the child as the base element instead of the default `<button>` tag. This allows for more flexibility
127
123
  */
128
124
  Resolve: ({ asChild, ...rest }: CommentResolveProps) => react_jsx_runtime.JSX.Element | null;
125
+ /**
126
+ * Reopens a resolved comment
127
+ *
128
+ * @description Calls `reopenComment` for this comment. Renders nothing (and logs an error) for draft and published comments
129
+ * @param asChild as whether to use the child as the base element instead of the default `<button>` tag. This allows for more flexibility
130
+ */
131
+ Reopen: ({ asChild, ...rest }: CommentReopenProps) => react_jsx_runtime.JSX.Element | null;
129
132
  };
130
133
 
131
134
  /**
@@ -133,7 +136,7 @@ declare const Comment: {
133
136
  *
134
137
  * @param initialComments as the initial comments from the document
135
138
  */
136
- declare const CommentContextProvider: ({ children, initialComments, initialOverlayState, onConfirm, onResolve, currentUser, subscription, config, projectId, onError, }: CommentOverlayProps$1) => react_jsx_runtime.JSX.Element;
139
+ declare const CommentContextProvider: ({ children, initialComments, initialOverlayState, currentUser: currentUserProp, subscription, config, projectId, onError, onAdd, onEdit, onDelete, onResolve, onReopen, }: CommentOverlayProps$1) => react_jsx_runtime.JSX.Element;
137
140
  declare const useComments: () => CommentContext;
138
141
 
139
142
  type CommentScope = {
@@ -145,4 +148,58 @@ type CommentScope = {
145
148
  declare const CommentScopeContext: React.Context<CommentScope | null>;
146
149
  declare function useCommentScope(): CommentScope;
147
150
 
148
- export { Comment, CommentContextProvider, CommentOverlay, CommentRenderer, CommentScopeContext, ConfirmComments, ResolveComments, ToggleOverlayButton, useCommentScope, useComments };
151
+ interface SessionButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
152
+ asChild?: boolean;
153
+ }
154
+ declare const CreateSession: ({ asChild, ...rest }: SessionButtonProps) => react_jsx_runtime.JSX.Element;
155
+ declare const ConfirmSession: ({ asChild, ...rest }: SessionButtonProps) => react_jsx_runtime.JSX.Element;
156
+ declare const StartResolving: ({ asChild, ...rest }: SessionButtonProps) => react_jsx_runtime.JSX.Element;
157
+ declare const ResolveSession: ({ asChild, ...rest }: SessionButtonProps) => react_jsx_runtime.JSX.Element;
158
+
159
+ type FeedbackSessionProviderProps = {
160
+ children: ReactNode;
161
+ /** Resume a session, for example after a reload */
162
+ initialSession?: InitialFeedbackSession;
163
+ /** Default project id sent to onCreateSession */
164
+ projectId?: string;
165
+ /**
166
+ * Whether the current user may start the resolution of a session, resolve a
167
+ * session, and resolve and reopen comments.
168
+ * @default false
169
+ */
170
+ canResolveSession?: boolean;
171
+ onCreateSession?: (input: CreateSessionInput) => Promise<FeedbackSession>;
172
+ onConfirmSession?: (sessionId: string, type: SessionType) => Promise<void>;
173
+ onStartResolving?: (sessionId: string) => Promise<void>;
174
+ onResolveSession?: (sessionId: string) => Promise<void>;
175
+ onError?: (error: KnownError) => void;
176
+ };
177
+ type ActionResult = {
178
+ error: KnownError | null;
179
+ };
180
+ type FeedbackSessionContextType = {
181
+ session: ActiveFeedbackSession | null;
182
+ sessionState: SessionOperationState;
183
+ /** Mirrors the canResolveSession prop */
184
+ canResolve: boolean;
185
+ createSession: (options?: {
186
+ type?: SessionType;
187
+ user?: User | null;
188
+ projectId?: string;
189
+ }) => Promise<ActionResult>;
190
+ confirmSession: () => Promise<ActionResult>;
191
+ startResolving: () => Promise<ActionResult>;
192
+ resolveSession: () => Promise<ActionResult>;
193
+ events: SessionEvents;
194
+ };
195
+ declare const FeedbackSessionProvider: ({ children, initialSession, projectId, canResolveSession, onCreateSession, onConfirmSession, onStartResolving, onResolveSession, onError, }: FeedbackSessionProviderProps) => react_jsx_runtime.JSX.Element;
196
+ declare const useFeedbackSession: () => FeedbackSessionContextType;
197
+
198
+ declare const UserProvider: ({ user, children }: UserProviderProps) => react_jsx_runtime.JSX.Element;
199
+ /**
200
+ * Returns the current user, or null when nobody is signed in.
201
+ * Throws when used outside <UserProvider />.
202
+ */
203
+ declare const useCurrentUser: () => User | null;
204
+
205
+ export { Comment, CommentContextProvider, CommentOverlay, CommentRenderer, CommentScopeContext, ConfirmSession, CreateSession, type FeedbackSessionContextType, FeedbackSessionProvider, type FeedbackSessionProviderProps, ResolveSession, StartResolving, ToggleOverlayButton, UserProvider, useCommentScope, useComments, useCurrentUser, useFeedbackSession };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as React from 'react';
3
3
  import { HTMLProps, ReactNode, ElementType, ButtonHTMLAttributes } from 'react';
4
- import { C as CommentType, a as CommentOverlayProps$1, b as CommentContext } from './comment.types-C0m3sQ_Q.js';
4
+ import { C as CommentType, a as CommentOverlayProps$1, b as CommentContext, I as InitialFeedbackSession, c as CreateSessionInput, F as FeedbackSession, S as SessionType, K as KnownError, A as ActiveFeedbackSession, d as SessionOperationState, U as User, e as SessionEvents, f as UserProviderProps } from './use-session-events-DFksOgVA.js';
5
5
 
6
6
  interface CommentOverlayProps extends HTMLProps<HTMLDivElement> {
7
7
  children: ReactNode;
@@ -15,9 +15,6 @@ type CommentRendererProps = {
15
15
  DraftComment: ElementType<{
16
16
  comment: CommentType;
17
17
  }>;
18
- ResolvingComment: ElementType<{
19
- comment: CommentType;
20
- }>;
21
18
  ResolvedComment: ElementType<{
22
19
  comment: CommentType;
23
20
  }>;
@@ -30,7 +27,6 @@ type CommentRendererProps = {
30
27
  *
31
28
  * @param Comment - Component for all open comments
32
29
  * @param DraftComment - Component for all draft comments
33
- * @param ResolvingComment - Component for all resolving comments
34
30
  * @param ResolvedComment - Component for all resolved comments
35
31
  * @returns mapped arrays of all comment types
36
32
  * @description This component is used to render all comments based on their type
@@ -39,19 +35,16 @@ type CommentRendererProps = {
39
35
  * <CommentRenderer
40
36
  * Comment={MyCommentComponent}
41
37
  * DraftComment={MyDraftCommentComponent}
42
- * ResolvingComment={MyResolvingCommentComponent}
43
38
  * ResolvedComment={MyResolvedCommentComponent}
44
39
  * />
45
40
  * ```
46
41
  */
47
- declare const CommentRenderer: ({ Comment, DraftComment, ResolvingComment, ResolvedComment, }: CommentRendererProps) => react_jsx_runtime.JSX.Element | null;
42
+ declare const CommentRenderer: ({ Comment, DraftComment, ResolvedComment, }: CommentRendererProps) => react_jsx_runtime.JSX.Element | null;
48
43
 
49
44
  interface CommentButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
50
45
  asChild?: boolean;
51
46
  }
52
47
  declare const ToggleOverlayButton: ({ asChild, ...rest }: CommentButtonProps) => react_jsx_runtime.JSX.Element;
53
- declare const ConfirmComments: ({ asChild, ...rest }: CommentButtonProps) => react_jsx_runtime.JSX.Element;
54
- declare const ResolveComments: ({ asChild, ...rest }: CommentButtonProps) => react_jsx_runtime.JSX.Element;
55
48
 
56
49
  interface CommentRootProps extends HTMLProps<HTMLDivElement> {
57
50
  comment: CommentType;
@@ -76,6 +69,9 @@ interface CommentDeleteProps extends ButtonHTMLAttributes<HTMLButtonElement> {
76
69
  interface CommentResolveProps extends ButtonHTMLAttributes<HTMLButtonElement> {
77
70
  asChild?: boolean;
78
71
  }
72
+ interface CommentReopenProps extends ButtonHTMLAttributes<HTMLButtonElement> {
73
+ asChild?: boolean;
74
+ }
79
75
  declare const Comment: {
80
76
  /**
81
77
  * The root component for a comment, must be used to wrap all other comment components.
@@ -120,12 +116,19 @@ declare const Comment: {
120
116
  */
121
117
  Delete: ({ asChild, ...rest }: CommentDeleteProps) => react_jsx_runtime.JSX.Element;
122
118
  /**
123
- * Toggles the resolving status of a comment
119
+ * Resolves a comment
124
120
  *
125
- * @description Toggles the comment's resolving status, which will show a different UI state
121
+ * @description Calls `resolveComment` for this comment. Renders nothing (and logs an error) for draft and resolved comments
126
122
  * @param asChild as whether to use the child as the base element instead of the default `<button>` tag. This allows for more flexibility
127
123
  */
128
124
  Resolve: ({ asChild, ...rest }: CommentResolveProps) => react_jsx_runtime.JSX.Element | null;
125
+ /**
126
+ * Reopens a resolved comment
127
+ *
128
+ * @description Calls `reopenComment` for this comment. Renders nothing (and logs an error) for draft and published comments
129
+ * @param asChild as whether to use the child as the base element instead of the default `<button>` tag. This allows for more flexibility
130
+ */
131
+ Reopen: ({ asChild, ...rest }: CommentReopenProps) => react_jsx_runtime.JSX.Element | null;
129
132
  };
130
133
 
131
134
  /**
@@ -133,7 +136,7 @@ declare const Comment: {
133
136
  *
134
137
  * @param initialComments as the initial comments from the document
135
138
  */
136
- declare const CommentContextProvider: ({ children, initialComments, initialOverlayState, onConfirm, onResolve, currentUser, subscription, config, projectId, onError, }: CommentOverlayProps$1) => react_jsx_runtime.JSX.Element;
139
+ declare const CommentContextProvider: ({ children, initialComments, initialOverlayState, currentUser: currentUserProp, subscription, config, projectId, onError, onAdd, onEdit, onDelete, onResolve, onReopen, }: CommentOverlayProps$1) => react_jsx_runtime.JSX.Element;
137
140
  declare const useComments: () => CommentContext;
138
141
 
139
142
  type CommentScope = {
@@ -145,4 +148,58 @@ type CommentScope = {
145
148
  declare const CommentScopeContext: React.Context<CommentScope | null>;
146
149
  declare function useCommentScope(): CommentScope;
147
150
 
148
- export { Comment, CommentContextProvider, CommentOverlay, CommentRenderer, CommentScopeContext, ConfirmComments, ResolveComments, ToggleOverlayButton, useCommentScope, useComments };
151
+ interface SessionButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
152
+ asChild?: boolean;
153
+ }
154
+ declare const CreateSession: ({ asChild, ...rest }: SessionButtonProps) => react_jsx_runtime.JSX.Element;
155
+ declare const ConfirmSession: ({ asChild, ...rest }: SessionButtonProps) => react_jsx_runtime.JSX.Element;
156
+ declare const StartResolving: ({ asChild, ...rest }: SessionButtonProps) => react_jsx_runtime.JSX.Element;
157
+ declare const ResolveSession: ({ asChild, ...rest }: SessionButtonProps) => react_jsx_runtime.JSX.Element;
158
+
159
+ type FeedbackSessionProviderProps = {
160
+ children: ReactNode;
161
+ /** Resume a session, for example after a reload */
162
+ initialSession?: InitialFeedbackSession;
163
+ /** Default project id sent to onCreateSession */
164
+ projectId?: string;
165
+ /**
166
+ * Whether the current user may start the resolution of a session, resolve a
167
+ * session, and resolve and reopen comments.
168
+ * @default false
169
+ */
170
+ canResolveSession?: boolean;
171
+ onCreateSession?: (input: CreateSessionInput) => Promise<FeedbackSession>;
172
+ onConfirmSession?: (sessionId: string, type: SessionType) => Promise<void>;
173
+ onStartResolving?: (sessionId: string) => Promise<void>;
174
+ onResolveSession?: (sessionId: string) => Promise<void>;
175
+ onError?: (error: KnownError) => void;
176
+ };
177
+ type ActionResult = {
178
+ error: KnownError | null;
179
+ };
180
+ type FeedbackSessionContextType = {
181
+ session: ActiveFeedbackSession | null;
182
+ sessionState: SessionOperationState;
183
+ /** Mirrors the canResolveSession prop */
184
+ canResolve: boolean;
185
+ createSession: (options?: {
186
+ type?: SessionType;
187
+ user?: User | null;
188
+ projectId?: string;
189
+ }) => Promise<ActionResult>;
190
+ confirmSession: () => Promise<ActionResult>;
191
+ startResolving: () => Promise<ActionResult>;
192
+ resolveSession: () => Promise<ActionResult>;
193
+ events: SessionEvents;
194
+ };
195
+ declare const FeedbackSessionProvider: ({ children, initialSession, projectId, canResolveSession, onCreateSession, onConfirmSession, onStartResolving, onResolveSession, onError, }: FeedbackSessionProviderProps) => react_jsx_runtime.JSX.Element;
196
+ declare const useFeedbackSession: () => FeedbackSessionContextType;
197
+
198
+ declare const UserProvider: ({ user, children }: UserProviderProps) => react_jsx_runtime.JSX.Element;
199
+ /**
200
+ * Returns the current user, or null when nobody is signed in.
201
+ * Throws when used outside <UserProvider />.
202
+ */
203
+ declare const useCurrentUser: () => User | null;
204
+
205
+ export { Comment, CommentContextProvider, CommentOverlay, CommentRenderer, CommentScopeContext, ConfirmSession, CreateSession, type FeedbackSessionContextType, FeedbackSessionProvider, type FeedbackSessionProviderProps, ResolveSession, StartResolving, ToggleOverlayButton, UserProvider, useCommentScope, useComments, useCurrentUser, useFeedbackSession };