@kendew-agency/react-feedback-layer 0.1.0 → 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
@@ -1,4 +1,4 @@
1
- # @kendew/react-feedback-layer
1
+ # @kendew-agency/react-feedback-layer
2
2
 
3
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
4
 
@@ -17,7 +17,7 @@ A drop-in React feedback layer for collecting contextual user feedback through i
17
17
  ## Installation
18
18
 
19
19
  ```bash
20
- npm install @kendew/react-feedback-layer
20
+ npm install @kendew-agency/react-feedback-layer
21
21
  ```
22
22
 
23
23
  ### Peer Dependencies
@@ -35,7 +35,7 @@ import {
35
35
  CommentContextProvider,
36
36
  CommentOverlay,
37
37
  CommentRenderer,
38
- } from '@kendew/react-feedback-layer';
38
+ } from '@kendew-agency/react-feedback-layer';
39
39
 
40
40
  function App() {
41
41
  const handleConfirm = async (comments) => {
@@ -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?: {
@@ -401,7 +401,7 @@ interface CommentButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
401
401
  **Example:**
402
402
 
403
403
  ```tsx
404
- import { ToggleOverlayButton } from '@kendew/react-feedback-layer';
404
+ import { ToggleOverlayButton } from '@kendew-agency/react-feedback-layer';
405
405
 
406
406
  <ToggleOverlayButton className="toggle-btn">
407
407
  Toggle Comments
@@ -415,7 +415,7 @@ Confirms all draft comments and triggers the `onConfirm` callback.
415
415
  **Example:**
416
416
 
417
417
  ```tsx
418
- import { ConfirmComments } from '@kendew/react-feedback-layer';
418
+ import { ConfirmComments } from '@kendew-agency/react-feedback-layer';
419
419
 
420
420
  <ConfirmComments className="btn-save">
421
421
  Save All Comments
@@ -429,7 +429,7 @@ Resolves all resolving comments and triggers the `onResolve` callback.
429
429
  **Example:**
430
430
 
431
431
  ```tsx
432
- import { ResolveComments } from '@kendew/react-feedback-layer';
432
+ import { ResolveComments } from '@kendew-agency/react-feedback-layer';
433
433
 
434
434
  <ResolveComments className="btn-resolve-all">
435
435
  Resolve All
@@ -476,7 +476,7 @@ interface CommentContext {
476
476
  **Example:**
477
477
 
478
478
  ```tsx
479
- import { useComments } from '@kendew/react-feedback-layer';
479
+ import { useComments } from '@kendew-agency/react-feedback-layer';
480
480
 
481
481
  function CommentToolbar() {
482
482
  const {
@@ -524,7 +524,7 @@ interface CommentScope {
524
524
  **Example:**
525
525
 
526
526
  ```tsx
527
- import { useCommentScope } from '@kendew/react-feedback-layer';
527
+ import { useCommentScope } from '@kendew-agency/react-feedback-layer';
528
528
 
529
529
  function CustomCommentContent() {
530
530
  const { comment, isActive, draft } = useCommentScope();
@@ -553,7 +553,7 @@ import type {
553
553
  CommentVisibility,
554
554
  CommentAction,
555
555
  Config
556
- } from '@kendew/react-feedback-layer/types';
556
+ } from '@kendew-agency/react-feedback-layer/types';
557
557
  ```
558
558
 
559
559
  #### `CommentType`
@@ -633,7 +633,7 @@ import {
633
633
  Comment,
634
634
  ToggleOverlayButton,
635
635
  ConfirmComments,
636
- } from '@kendew/react-feedback-layer';
636
+ } from '@kendew-agency/react-feedback-layer';
637
637
 
638
638
  function DraftComment({ comment }) {
639
639
  return (
@@ -757,7 +757,7 @@ function App() {
757
757
  ### Custom Toolbar with Visibility Controls
758
758
 
759
759
  ```tsx
760
- import { useComments } from '@kendew/react-feedback-layer';
760
+ import { useComments } from '@kendew-agency/react-feedback-layer';
761
761
 
762
762
  function CommentToolbar() {
763
763
  const {
@@ -824,7 +824,7 @@ function CommentToolbar() {
824
824
  The `asChild` prop (powered by Radix UI Slot) lets you render components as different elements:
825
825
 
826
826
  ```tsx
827
- import { Comment } from '@kendew/react-feedback-layer';
827
+ import { Comment } from '@kendew-agency/react-feedback-layer';
828
828
 
829
829
  function CustomComment({ comment }) {
830
830
  return (
@@ -920,7 +920,7 @@ function VisibilityControls() {
920
920
  ### Programmatic Comment Creation
921
921
 
922
922
  ```tsx
923
- import { useComments } from '@kendew/react-feedback-layer';
923
+ import { useComments } from '@kendew-agency/react-feedback-layer';
924
924
 
925
925
  function CustomTool() {
926
926
  const { registerComment } = useComments();
@@ -968,7 +968,7 @@ You can handle errors in two ways:
968
968
  **2. Handling errors from action results:**
969
969
 
970
970
  ```tsx
971
- import { useComments } from '@kendew/react-feedback-layer';
971
+ import { useComments } from '@kendew-agency/react-feedback-layer';
972
972
 
973
973
  function SaveButton() {
974
974
  const { confirmComments, overlayState } = useComments();
@@ -995,10 +995,25 @@ 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
1001
- import { useComments } from '@kendew/react-feedback-layer';
1016
+ import { useComments } from '@kendew-agency/react-feedback-layer';
1002
1017
  import { useState } from 'react';
1003
1018
 
1004
1019
  function CommentList() {
@@ -1095,7 +1110,7 @@ This library is completely unstyled (headless). Here's a basic CSS example to ge
1095
1110
  This library is written in TypeScript and includes full type definitions. No additional `@types` packages needed.
1096
1111
 
1097
1112
  ```tsx
1098
- import type { CommentType, User } from '@kendew/react-feedback-layer/types';
1113
+ import type { CommentType, User } from '@kendew-agency/react-feedback-layer/types';
1099
1114
 
1100
1115
  const user: User = {
1101
1116
  id: '123',
@@ -1153,4 +1168,4 @@ MIT © [Kendew Agency](https://github.com/Kendew-Agency)
1153
1168
 
1154
1169
  - [GitHub Repository](https://github.com/Kendew-Agency/react-feedback-layer)
1155
1170
  - [Issue Tracker](https://github.com/Kendew-Agency/react-feedback-layer/issues)
1156
- - [NPM Package](https://www.npmjs.com/package/@kendew/react-feedback-layer)
1171
+ - [NPM Package](https://www.npmjs.com/package/@kendew-agency/react-feedback-layer)
@@ -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.0",
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",