@kendew-agency/react-feedback-layer 0.1.1 → 0.1.2

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/README.md CHANGED
@@ -136,7 +136,7 @@ interface CommentOverlayProps {
136
136
  onResolve: (comments: ConfirmedComment[]) => Promise<void>;
137
137
 
138
138
  // Callback to handle errors (optional)
139
- onError?: (error: Error) => void;
139
+ onError?: (error: KnownError) => void;
140
140
 
141
141
  // Optional configuration for the comment layer
142
142
  config?: {
@@ -995,6 +995,21 @@ function SaveButton() {
995
995
  }
996
996
  ```
997
997
 
998
+ #### Error codes
999
+ To keep track of the origin of a comment an error code is provided. You can use this code to display a more accurate error message. For example:
1000
+ ```ts
1001
+ switch(e.code){
1002
+ case "RESOLVE_ERROR":
1003
+ alert('Failed to resolve your comments')
1004
+ break
1005
+ case "CONFIRM_ERROR":
1006
+ alert('Failed to submit your comments')
1007
+ break
1008
+ default:
1009
+ alert('An unknown error occured')
1010
+ }
1011
+ ```
1012
+
998
1013
  ### Filtering and Searching Comments
999
1014
 
1000
1015
  ```tsx
@@ -1,5 +1,20 @@
1
1
  import { ReactNode } from 'react';
2
2
 
3
+ declare class BaseError extends Error {
4
+ code: OverlayErrorCode;
5
+ status: number;
6
+ constructor(message: string, code?: OverlayErrorCode, status?: number);
7
+ }
8
+ declare class ResolveError extends BaseError {
9
+ constructor(message?: string);
10
+ }
11
+ declare class ConfirmError extends BaseError {
12
+ constructor(message?: string);
13
+ }
14
+
15
+ type OverlayErrorCode = "RESOLVE_ERROR" | "CONFIRM_ERROR" | "UNKNOWN_ERROR";
16
+ type KnownError = ConfirmError | ResolveError;
17
+
3
18
  type CommentState = {
4
19
  /**
5
20
  * All confirmed comments
@@ -36,7 +51,7 @@ type CommentState = {
36
51
  * The state of the comment overlay
37
52
  * @description This is used to track the state of the comment overlay
38
53
  */
39
- type CommentOverlayState = "idle" | "editing" | "saving" | "error" | "resolving" | "inactive";
54
+ type CommentOverlayState = "idle" | "editing" | "saving" | "resolving" | "inactive";
40
55
  type CommentVisibility = {
41
56
  /**
42
57
  * Hide comments that are marked as resolved
@@ -94,7 +109,7 @@ type CommentOverlayProps = {
94
109
  *
95
110
  * @param error as the error that occurred
96
111
  */
97
- onError?: (error: Error) => void;
112
+ onError?: (error: KnownError) => void;
98
113
  /**
99
114
  * Optional configuration for the comment layer
100
115
  */
@@ -237,4 +252,4 @@ type CommentWithStatus<T extends Status> = Omit<CommentType, "status"> & {
237
252
  status: T;
238
253
  };
239
254
 
240
- export type { CommentType as C, Indicator as I, Position as P, Status as S, User as U, CommentOverlayProps as a, CommentContext as b, CommentOverlayState as c, CommentVisibility as d, ConfirmedStatus as e, ConfirmedComment as f, CommentWithStatus as g, CommentState as h, Config as i };
255
+ export type { CommentType as C, Indicator as I, KnownError as K, OverlayErrorCode as O, Position as P, Status as S, User as U, CommentOverlayProps as a, CommentContext as b, CommentOverlayState as c, CommentVisibility as d, ConfirmedStatus as e, ConfirmedComment as f, CommentWithStatus as g, CommentState as h, Config as i };
@@ -1,5 +1,20 @@
1
1
  import { ReactNode } from 'react';
2
2
 
3
+ declare class BaseError extends Error {
4
+ code: OverlayErrorCode;
5
+ status: number;
6
+ constructor(message: string, code?: OverlayErrorCode, status?: number);
7
+ }
8
+ declare class ResolveError extends BaseError {
9
+ constructor(message?: string);
10
+ }
11
+ declare class ConfirmError extends BaseError {
12
+ constructor(message?: string);
13
+ }
14
+
15
+ type OverlayErrorCode = "RESOLVE_ERROR" | "CONFIRM_ERROR" | "UNKNOWN_ERROR";
16
+ type KnownError = ConfirmError | ResolveError;
17
+
3
18
  type CommentState = {
4
19
  /**
5
20
  * All confirmed comments
@@ -36,7 +51,7 @@ type CommentState = {
36
51
  * The state of the comment overlay
37
52
  * @description This is used to track the state of the comment overlay
38
53
  */
39
- type CommentOverlayState = "idle" | "editing" | "saving" | "error" | "resolving" | "inactive";
54
+ type CommentOverlayState = "idle" | "editing" | "saving" | "resolving" | "inactive";
40
55
  type CommentVisibility = {
41
56
  /**
42
57
  * Hide comments that are marked as resolved
@@ -94,7 +109,7 @@ type CommentOverlayProps = {
94
109
  *
95
110
  * @param error as the error that occurred
96
111
  */
97
- onError?: (error: Error) => void;
112
+ onError?: (error: KnownError) => void;
98
113
  /**
99
114
  * Optional configuration for the comment layer
100
115
  */
@@ -237,4 +252,4 @@ type CommentWithStatus<T extends Status> = Omit<CommentType, "status"> & {
237
252
  status: T;
238
253
  };
239
254
 
240
- export type { CommentType as C, Indicator as I, Position as P, Status as S, User as U, CommentOverlayProps as a, CommentContext as b, CommentOverlayState as c, CommentVisibility as d, ConfirmedStatus as e, ConfirmedComment as f, CommentWithStatus as g, CommentState as h, Config as i };
255
+ export type { CommentType as C, Indicator as I, KnownError as K, OverlayErrorCode as O, Position as P, Status as S, User as U, CommentOverlayProps as a, CommentContext as b, CommentOverlayState as c, CommentVisibility as d, ConfirmedStatus as e, ConfirmedComment as f, CommentWithStatus as g, CommentState as h, Config as i };
package/dist/index.cjs CHANGED
@@ -61,6 +61,26 @@ function hasStatus(status) {
61
61
  return (comment) => comment.status === status;
62
62
  }
63
63
 
64
+ // src/errors.ts
65
+ var BaseError = class extends Error {
66
+ constructor(message, code = "UNKNOWN_ERROR", status = 500) {
67
+ super(message);
68
+ this.name = this.constructor.name;
69
+ this.code = code;
70
+ this.status = status;
71
+ }
72
+ };
73
+ var ResolveError = class extends BaseError {
74
+ constructor(message = "An error occured while resolving your comments") {
75
+ super(message, "RESOLVE_ERROR", 500);
76
+ }
77
+ };
78
+ var ConfirmError = class extends BaseError {
79
+ constructor(message = "An error occured while confirming your comments") {
80
+ super(message, "CONFIRM_ERROR", 500);
81
+ }
82
+ };
83
+
64
84
  // src/contexts/comment-context.tsx
65
85
  var import_jsx_runtime = require("react/jsx-runtime");
66
86
  var CommentContext = (0, import_react.createContext)(null);
@@ -120,7 +140,7 @@ var commentReducer = (state, action) => {
120
140
  case "FOCUS":
121
141
  return {
122
142
  ...state,
123
- overlayState: "editing",
143
+ overlayState: action.id === null ? "idle" : "editing",
124
144
  focussedComment: action.id
125
145
  };
126
146
  case "TOGGLE_OVERLAY":
@@ -265,11 +285,10 @@ var CommentContextProvider = ({
265
285
  )
266
286
  );
267
287
  if (error) {
268
- dispatch({ type: "CHANGE_OVERLAYSTATE", to: "error" });
269
288
  if (onError) {
270
- onError(error);
289
+ onError(new ConfirmError(error.message));
271
290
  }
272
- return { error };
291
+ return { error: new ConfirmError(error.message) };
273
292
  }
274
293
  dispatch({ type: "CHANGE_OVERLAYSTATE", to: "idle" });
275
294
  dispatch({ type: "RESET_DRAFT_COMMENTS" });
@@ -287,11 +306,10 @@ var CommentContextProvider = ({
287
306
  )
288
307
  );
289
308
  if (error) {
290
- dispatch({ type: "CHANGE_OVERLAYSTATE", to: "error" });
291
309
  if (onError) {
292
- onError(error);
310
+ onError(new ResolveError(error.message));
293
311
  }
294
- return { error };
312
+ return { error: new ResolveError(error.message) };
295
313
  }
296
314
  dispatch({ type: "RESET_RESOLVING_COMMENTS" });
297
315
  dispatch({ type: "CHANGE_OVERLAYSTATE", to: "idle" });
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 { ReactNode, ElementType, ButtonHTMLAttributes, HTMLProps } from 'react';
4
- import { C as CommentType, a as CommentOverlayProps, b as CommentContext } from './comment.types-B7xO89Wt.cjs';
4
+ import { C as CommentType, a as CommentOverlayProps, b as CommentContext } from './comment.types-CfEOrU1d.cjs';
5
5
 
6
6
  declare const CommentOverlay: ({ children }: {
7
7
  children: ReactNode;
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 { ReactNode, ElementType, ButtonHTMLAttributes, HTMLProps } from 'react';
4
- import { C as CommentType, a as CommentOverlayProps, b as CommentContext } from './comment.types-B7xO89Wt.js';
4
+ import { C as CommentType, a as CommentOverlayProps, b as CommentContext } from './comment.types-CfEOrU1d.js';
5
5
 
6
6
  declare const CommentOverlay: ({ children }: {
7
7
  children: ReactNode;
package/dist/index.js CHANGED
@@ -16,6 +16,26 @@ function hasStatus(status) {
16
16
  return (comment) => comment.status === status;
17
17
  }
18
18
 
19
+ // src/errors.ts
20
+ var BaseError = class extends Error {
21
+ constructor(message, code = "UNKNOWN_ERROR", status = 500) {
22
+ super(message);
23
+ this.name = this.constructor.name;
24
+ this.code = code;
25
+ this.status = status;
26
+ }
27
+ };
28
+ var ResolveError = class extends BaseError {
29
+ constructor(message = "An error occured while resolving your comments") {
30
+ super(message, "RESOLVE_ERROR", 500);
31
+ }
32
+ };
33
+ var ConfirmError = class extends BaseError {
34
+ constructor(message = "An error occured while confirming your comments") {
35
+ super(message, "CONFIRM_ERROR", 500);
36
+ }
37
+ };
38
+
19
39
  // src/contexts/comment-context.tsx
20
40
  import { jsx } from "react/jsx-runtime";
21
41
  var CommentContext = createContext(null);
@@ -75,7 +95,7 @@ var commentReducer = (state, action) => {
75
95
  case "FOCUS":
76
96
  return {
77
97
  ...state,
78
- overlayState: "editing",
98
+ overlayState: action.id === null ? "idle" : "editing",
79
99
  focussedComment: action.id
80
100
  };
81
101
  case "TOGGLE_OVERLAY":
@@ -220,11 +240,10 @@ var CommentContextProvider = ({
220
240
  )
221
241
  );
222
242
  if (error) {
223
- dispatch({ type: "CHANGE_OVERLAYSTATE", to: "error" });
224
243
  if (onError) {
225
- onError(error);
244
+ onError(new ConfirmError(error.message));
226
245
  }
227
- return { error };
246
+ return { error: new ConfirmError(error.message) };
228
247
  }
229
248
  dispatch({ type: "CHANGE_OVERLAYSTATE", to: "idle" });
230
249
  dispatch({ type: "RESET_DRAFT_COMMENTS" });
@@ -242,11 +261,10 @@ var CommentContextProvider = ({
242
261
  )
243
262
  );
244
263
  if (error) {
245
- dispatch({ type: "CHANGE_OVERLAYSTATE", to: "error" });
246
264
  if (onError) {
247
- onError(error);
265
+ onError(new ResolveError(error.message));
248
266
  }
249
- return { error };
267
+ return { error: new ResolveError(error.message) };
250
268
  }
251
269
  dispatch({ type: "RESET_RESOLVING_COMMENTS" });
252
270
  dispatch({ type: "CHANGE_OVERLAYSTATE", to: "idle" });
package/dist/types.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as CommentType, P as Position, I as Indicator, c as CommentOverlayState, d as CommentVisibility } from './comment.types-B7xO89Wt.cjs';
2
- export { b as CommentContext, a as CommentOverlayProps, h as CommentState, g as CommentWithStatus, i as Config, f as ConfirmedComment, e as ConfirmedStatus, S as Status, U as User } from './comment.types-B7xO89Wt.cjs';
1
+ import { C as CommentType, P as Position, I as Indicator, c as CommentOverlayState, d as CommentVisibility } from './comment.types-CfEOrU1d.cjs';
2
+ export { b as CommentContext, a as CommentOverlayProps, h as CommentState, g as CommentWithStatus, i as Config, f as ConfirmedComment, e as ConfirmedStatus, K as KnownError, O as OverlayErrorCode, S as Status, U as User } from './comment.types-CfEOrU1d.cjs';
3
3
  import 'react';
4
4
 
5
5
  /**
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as CommentType, P as Position, I as Indicator, c as CommentOverlayState, d as CommentVisibility } from './comment.types-B7xO89Wt.js';
2
- export { b as CommentContext, a as CommentOverlayProps, h as CommentState, g as CommentWithStatus, i as Config, f as ConfirmedComment, e as ConfirmedStatus, S as Status, U as User } from './comment.types-B7xO89Wt.js';
1
+ import { C as CommentType, P as Position, I as Indicator, c as CommentOverlayState, d as CommentVisibility } from './comment.types-CfEOrU1d.js';
2
+ export { b as CommentContext, a as CommentOverlayProps, h as CommentState, g as CommentWithStatus, i as Config, f as ConfirmedComment, e as ConfirmedStatus, K as KnownError, O as OverlayErrorCode, S as Status, U as User } from './comment.types-CfEOrU1d.js';
3
3
  import 'react';
4
4
 
5
5
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kendew-agency/react-feedback-layer",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Drop-in React feedback layer for collecting contextual user feedback",
5
5
  "license": "MIT",
6
6
  "author": "Kendew Agency",