@kendew-agency/react-feedback-layer 0.1.1 → 0.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/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # @kendew-agency/react-feedback-layer
2
2
 
3
- A drop-in React feedback layer for collecting contextual user feedback through interactive comments and annotations. Perfect for design review tools, bug reporting systems, and collaborative annotation platforms.
3
+ A drop-in React feedback layer for collecting contextual user feedback through interactive comments and annotations. Perfect for design review tools, bug reporting systems, and collaborative annotation platforms.
4
+
5
+ Have a look at the [changelog](#changelog) when updating the package.
4
6
 
5
7
  ## Features
6
8
 
@@ -136,7 +138,7 @@ interface CommentOverlayProps {
136
138
  onResolve: (comments: ConfirmedComment[]) => Promise<void>;
137
139
 
138
140
  // Callback to handle errors (optional)
139
- onError?: (error: Error) => void;
141
+ onError?: (error: KnownError) => void;
140
142
 
141
143
  // Optional configuration for the comment layer
142
144
  config?: {
@@ -995,6 +997,21 @@ function SaveButton() {
995
997
  }
996
998
  ```
997
999
 
1000
+ #### Error codes
1001
+ 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:
1002
+ ```ts
1003
+ switch(e.code){
1004
+ case "RESOLVE_ERROR":
1005
+ alert('Failed to resolve your comments')
1006
+ break
1007
+ case "CONFIRM_ERROR":
1008
+ alert('Failed to submit your comments')
1009
+ break
1010
+ default:
1011
+ alert('An unknown error occured')
1012
+ }
1013
+ ```
1014
+
998
1015
  ### Filtering and Searching Comments
999
1016
 
1000
1017
  ```tsx
@@ -1154,3 +1171,12 @@ MIT © [Kendew Agency](https://github.com/Kendew-Agency)
1154
1171
  - [GitHub Repository](https://github.com/Kendew-Agency/react-feedback-layer)
1155
1172
  - [Issue Tracker](https://github.com/Kendew-Agency/react-feedback-layer/issues)
1156
1173
  - [NPM Package](https://www.npmjs.com/package/@kendew-agency/react-feedback-layer)
1174
+
1175
+ ## Changelog
1176
+
1177
+ A list if breaking changes that could impact the way you configured the package
1178
+
1179
+ ### 0.2.0
1180
+ - Reworked the subscription system. The system remains in beta and may change in the future. Configurations made with version 0.1.2 or older will need adjustment after updating.
1181
+ - `mode` was defined twice in props. It has been removed as a root prop and is now only part of the config.
1182
+
@@ -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
@@ -74,9 +89,10 @@ type CommentOverlayProps = {
74
89
  initialOverlayState?: CommentOverlayState;
75
90
  /**
76
91
  * Realtime subscription if supported by you DB
92
+ * @description You can use this feature with a realtime DB or a websocket
93
+ * @beta this featue is not yet fully tested and is subject to change
77
94
  */
78
- subscription?: Suscription;
79
- mode?: "onConfirm";
95
+ subscription?: RealtimeSubscription<CommentType>;
80
96
  /**
81
97
  * Callback with all newly confirmed comments
82
98
  *
@@ -94,16 +110,16 @@ type CommentOverlayProps = {
94
110
  *
95
111
  * @param error as the error that occurred
96
112
  */
97
- onError?: (error: Error) => void;
113
+ onError?: (error: KnownError) => void;
98
114
  /**
99
115
  * Optional configuration for the comment layer
100
116
  */
101
117
  config?: Config;
102
118
  };
103
- type Suscription = {
104
- subscribe: (update: unknown) => void;
105
- unsubscribe: () => void;
106
- };
119
+ interface RealtimeSubscription<T> {
120
+ subscribe(onUpdate: (data: T) => void): void;
121
+ unsubscribe(): void;
122
+ }
107
123
  type Config = {
108
124
  /**
109
125
  * A custom prefix for the comment ids
@@ -237,4 +253,4 @@ type CommentWithStatus<T extends Status> = Omit<CommentType, "status"> & {
237
253
  status: T;
238
254
  };
239
255
 
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 };
256
+ export type { CommentType as C, Indicator as I, KnownError as K, OverlayErrorCode as O, Position as P, RealtimeSubscription as R, 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
@@ -74,9 +89,10 @@ type CommentOverlayProps = {
74
89
  initialOverlayState?: CommentOverlayState;
75
90
  /**
76
91
  * Realtime subscription if supported by you DB
92
+ * @description You can use this feature with a realtime DB or a websocket
93
+ * @beta this featue is not yet fully tested and is subject to change
77
94
  */
78
- subscription?: Suscription;
79
- mode?: "onConfirm";
95
+ subscription?: RealtimeSubscription<CommentType>;
80
96
  /**
81
97
  * Callback with all newly confirmed comments
82
98
  *
@@ -94,16 +110,16 @@ type CommentOverlayProps = {
94
110
  *
95
111
  * @param error as the error that occurred
96
112
  */
97
- onError?: (error: Error) => void;
113
+ onError?: (error: KnownError) => void;
98
114
  /**
99
115
  * Optional configuration for the comment layer
100
116
  */
101
117
  config?: Config;
102
118
  };
103
- type Suscription = {
104
- subscribe: (update: unknown) => void;
105
- unsubscribe: () => void;
106
- };
119
+ interface RealtimeSubscription<T> {
120
+ subscribe(onUpdate: (data: T) => void): void;
121
+ unsubscribe(): void;
122
+ }
107
123
  type Config = {
108
124
  /**
109
125
  * A custom prefix for the comment ids
@@ -237,4 +253,4 @@ type CommentWithStatus<T extends Status> = Omit<CommentType, "status"> & {
237
253
  status: T;
238
254
  };
239
255
 
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 };
256
+ export type { CommentType as C, Indicator as I, KnownError as K, OverlayErrorCode as O, Position as P, RealtimeSubscription as R, 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);
@@ -98,6 +118,11 @@ var commentReducer = (state, action) => {
98
118
  comments: action.comments
99
119
  };
100
120
  }
121
+ case "APPEND_COMMENT":
122
+ return {
123
+ ...state,
124
+ comments: [...state.comments, action.comment]
125
+ };
101
126
  case "DELETE":
102
127
  return {
103
128
  ...state,
@@ -120,7 +145,7 @@ var commentReducer = (state, action) => {
120
145
  case "FOCUS":
121
146
  return {
122
147
  ...state,
123
- overlayState: "editing",
148
+ overlayState: action.id === null ? "idle" : "editing",
124
149
  focussedComment: action.id
125
150
  };
126
151
  case "TOGGLE_OVERLAY":
@@ -200,8 +225,8 @@ var CommentContextProvider = ({
200
225
  });
201
226
  (0, import_react.useEffect)(() => {
202
227
  if (!subscription) return;
203
- subscription.subscribe((update) => {
204
- dispatch({ type: "UPDATE_COMMENTS", comments: update });
228
+ subscription.subscribe((data) => {
229
+ dispatch({ type: "APPEND_COMMENT", comment: data });
205
230
  });
206
231
  return () => {
207
232
  subscription.unsubscribe();
@@ -265,11 +290,10 @@ var CommentContextProvider = ({
265
290
  )
266
291
  );
267
292
  if (error) {
268
- dispatch({ type: "CHANGE_OVERLAYSTATE", to: "error" });
269
293
  if (onError) {
270
- onError(error);
294
+ onError(new ConfirmError(error.message));
271
295
  }
272
- return { error };
296
+ return { error: new ConfirmError(error.message) };
273
297
  }
274
298
  dispatch({ type: "CHANGE_OVERLAYSTATE", to: "idle" });
275
299
  dispatch({ type: "RESET_DRAFT_COMMENTS" });
@@ -287,11 +311,10 @@ var CommentContextProvider = ({
287
311
  )
288
312
  );
289
313
  if (error) {
290
- dispatch({ type: "CHANGE_OVERLAYSTATE", to: "error" });
291
314
  if (onError) {
292
- onError(error);
315
+ onError(new ResolveError(error.message));
293
316
  }
294
- return { error };
317
+ return { error: new ResolveError(error.message) };
295
318
  }
296
319
  dispatch({ type: "RESET_RESOLVING_COMMENTS" });
297
320
  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-CSGuc1D_.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-CSGuc1D_.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);
@@ -53,6 +73,11 @@ var commentReducer = (state, action) => {
53
73
  comments: action.comments
54
74
  };
55
75
  }
76
+ case "APPEND_COMMENT":
77
+ return {
78
+ ...state,
79
+ comments: [...state.comments, action.comment]
80
+ };
56
81
  case "DELETE":
57
82
  return {
58
83
  ...state,
@@ -75,7 +100,7 @@ var commentReducer = (state, action) => {
75
100
  case "FOCUS":
76
101
  return {
77
102
  ...state,
78
- overlayState: "editing",
103
+ overlayState: action.id === null ? "idle" : "editing",
79
104
  focussedComment: action.id
80
105
  };
81
106
  case "TOGGLE_OVERLAY":
@@ -155,8 +180,8 @@ var CommentContextProvider = ({
155
180
  });
156
181
  useEffect(() => {
157
182
  if (!subscription) return;
158
- subscription.subscribe((update) => {
159
- dispatch({ type: "UPDATE_COMMENTS", comments: update });
183
+ subscription.subscribe((data) => {
184
+ dispatch({ type: "APPEND_COMMENT", comment: data });
160
185
  });
161
186
  return () => {
162
187
  subscription.unsubscribe();
@@ -220,11 +245,10 @@ var CommentContextProvider = ({
220
245
  )
221
246
  );
222
247
  if (error) {
223
- dispatch({ type: "CHANGE_OVERLAYSTATE", to: "error" });
224
248
  if (onError) {
225
- onError(error);
249
+ onError(new ConfirmError(error.message));
226
250
  }
227
- return { error };
251
+ return { error: new ConfirmError(error.message) };
228
252
  }
229
253
  dispatch({ type: "CHANGE_OVERLAYSTATE", to: "idle" });
230
254
  dispatch({ type: "RESET_DRAFT_COMMENTS" });
@@ -242,11 +266,10 @@ var CommentContextProvider = ({
242
266
  )
243
267
  );
244
268
  if (error) {
245
- dispatch({ type: "CHANGE_OVERLAYSTATE", to: "error" });
246
269
  if (onError) {
247
- onError(error);
270
+ onError(new ResolveError(error.message));
248
271
  }
249
- return { error };
272
+ return { error: new ResolveError(error.message) };
250
273
  }
251
274
  dispatch({ type: "RESET_RESOLVING_COMMENTS" });
252
275
  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-CSGuc1D_.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, R as RealtimeSubscription, S as Status, U as User } from './comment.types-CSGuc1D_.cjs';
3
3
  import 'react';
4
4
 
5
5
  /**
@@ -11,6 +11,9 @@ type CommentAction = {
11
11
  } | {
12
12
  type: "UPDATE_COMMENTS";
13
13
  comments: CommentType[];
14
+ } | {
15
+ type: "APPEND_COMMENT";
16
+ comment: CommentType;
14
17
  } | {
15
18
  type: "EDIT";
16
19
  id: string;
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-CSGuc1D_.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, R as RealtimeSubscription, S as Status, U as User } from './comment.types-CSGuc1D_.js';
3
3
  import 'react';
4
4
 
5
5
  /**
@@ -11,6 +11,9 @@ type CommentAction = {
11
11
  } | {
12
12
  type: "UPDATE_COMMENTS";
13
13
  comments: CommentType[];
14
+ } | {
15
+ type: "APPEND_COMMENT";
16
+ comment: CommentType;
14
17
  } | {
15
18
  type: "EDIT";
16
19
  id: string;
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.2.0",
4
4
  "description": "Drop-in React feedback layer for collecting contextual user feedback",
5
5
  "license": "MIT",
6
6
  "author": "Kendew Agency",